@@ -44,6 +44,7 @@ The application follows a command-line interface pattern using the Cobra library
4444 - ` jh git-credential ` : Git credential helper for seamless authentication
4545 - ` jh julia ` : Julia installation management
4646 - ` jh run ` : Julia execution with JuliaHub configuration
47+ - ` jh run setup ` : Setup Julia credentials without starting Julia
4748
48494 . ** Data Models** :
4950 - UUID strings for most entity IDs (projects, datasets, resources)
@@ -111,6 +112,27 @@ echo -e "protocol=https\nhost=juliahub.com\npath=git/projects/test/test\n" | go
111112git clone https://juliahub.com/git/projects/username/project.git
112113```
113114
115+ ### Test Julia integration
116+ ``` bash
117+ # Install Julia (if not already installed)
118+ go run . julia install
119+
120+ # Setup Julia credentials only
121+ go run . run setup
122+
123+ # Run Julia REPL with credentials setup
124+ go run . run
125+
126+ # Run Julia with credentials setup
127+ go run . run -- -e " println(\" Hello from JuliaHub!\" )"
128+
129+ # Run Julia script with project
130+ go run . run -- --project=. script.jl
131+
132+ # Run Julia with multiple flags
133+ go run . run -- --project=. --threads=4 -e " println(Threads.nthreads())"
134+ ```
135+
114136## Dependencies
115137
116138- ` github.com/spf13/cobra ` : CLI framework
@@ -196,10 +218,43 @@ git clone https://github.com/user/repo.git # Ignored by
196218## Julia Integration
197219
198220The CLI provides Julia installation and execution with JuliaHub configuration:
221+
222+ ### Julia Installation (` jh julia install ` )
199223- Cross-platform installation (Windows via winget, Unix via official installer)
200- - Authentication file creation (` ~/.julia/servers/<server>/auth.toml ` )
201- - Package server configuration (` JULIA_PKG_SERVER ` )
202- - Project activation (` --project=. ` )
224+ - Installs latest stable Julia version
225+
226+ ### Julia Credentials
227+ - ** Authentication file** : Automatically creates ` ~/.julia/servers/<server>/auth.toml `
228+ - ** Atomic writes** : Uses temporary file + rename for safe credential updates
229+ - ** Automatic updates** : Credentials are automatically refreshed when:
230+ - User runs ` jh auth login `
231+ - User runs ` jh auth refresh `
232+ - Token is refreshed via ` ensureValidToken() `
233+ - User runs ` jh run ` or ` jh run setup `
234+
235+ ### Julia Commands
236+
237+ #### ` jh run [-- julia-args...] ` - Run Julia with JuliaHub configuration
238+ ``` bash
239+ jh run # Start Julia REPL
240+ jh run -- script.jl # Run a script
241+ jh run -- -e " println(\" Hello\" )" # Execute code
242+ jh run -- --project=. --threads=4 script.jl # Run with flags
243+ ```
244+ - Sets up credentials, then starts Julia
245+ - Arguments after ` -- ` are passed directly to Julia without modification
246+ - User controls all Julia flags (including ` --project ` , ` --threads ` , etc.)
247+ - Environment variables set:
248+ - ` JULIA_PKG_SERVER ` : Points to your JuliaHub server
249+ - ` JULIA_PKG_USE_CLI_GIT ` : Set to ` true ` for Git integration
250+
251+ #### ` jh run setup ` - Setup credentials only (no Julia execution)
252+ ``` bash
253+ jh run setup
254+ ```
255+ - Creates/updates ` ~/.julia/servers/<server>/auth.toml ` with current credentials
256+ - Does not start Julia
257+ - Useful for explicitly updating credentials
203258
204259## Development Notes
205260
@@ -209,10 +264,58 @@ The CLI provides Julia installation and execution with JuliaHub configuration:
209264- Token refresh is automatic via ` ensureValidToken() `
210265- File uploads use multipart form data with proper content types
211266- Julia auth files use TOML format with ` preferred_username ` from JWT claims
267+ - Julia auth files use atomic writes (temp file + rename) to prevent corruption
268+ - Julia credentials are automatically updated after login and token refresh
212269- Git commands use ` http.extraHeader ` for authentication and pass through all arguments
213270- Git credential helper provides seamless authentication for standard Git commands
214271- Multi-server authentication handled automatically via credential helper
215272- Project filtering supports ` --user ` parameter for showing specific user's projects or own projects
216273- Clone command automatically resolves ` username/project ` format to project UUIDs
217274- Folder naming conflicts are resolved with automatic numbering (project-1, project-2, etc.)
218- - Credential helper follows Git protocol: responds only to JuliaHub URLs, ignores others
275+ - Credential helper follows Git protocol: responds only to JuliaHub URLs, ignores others
276+
277+ ## Implementation Details
278+
279+ ### Julia Credentials Management (` run.go ` )
280+
281+ The Julia credentials system consists of three main functions:
282+
283+ 1 . ** ` createJuliaAuthFile(server, token) ` ** :
284+ - Creates ` ~/.julia/servers/<server>/auth.toml ` with TOML-formatted credentials
285+ - Uses atomic writes: writes to temporary file, syncs, then renames
286+ - Includes all necessary fields: tokens, expiration, refresh URL, user info
287+ - Called by ` setupJuliaCredentials() ` and ` updateJuliaCredentialsIfNeeded() `
288+
289+ 2 . ** ` setupJuliaCredentials() ` ** :
290+ - Public function called by:
291+ - ` jh run ` command (before starting Julia)
292+ - ` jh run setup ` command
293+ - ` jh auth login ` command (after successful login)
294+ - ` jh auth refresh ` command (after successful refresh)
295+ - Ensures valid token via ` ensureValidToken() `
296+ - Creates/updates Julia auth file
297+ - Returns error if authentication fails
298+
299+ 3 . ** ` runJulia(args) ` ** :
300+ - Sets up credentials via ` setupJuliaCredentials() `
301+ - Configures environment variables (` JULIA_PKG_SERVER ` , ` JULIA_PKG_USE_CLI_GIT ` )
302+ - Executes Julia with user-provided arguments (no automatic flags)
303+ - Streams stdin/stdout/stderr to maintain interactive experience
304+
305+ ### Automatic Credential Updates (` auth.go ` )
306+
307+ The ` updateJuliaCredentialsIfNeeded(server, token) ` function:
308+ - Called automatically by ` ensureValidToken() ` after token refresh
309+ - Checks if ` ~/.julia/servers/<server>/auth.toml ` exists
310+ - If exists, updates it with refreshed token
311+ - If not exists, does nothing (user hasn't used Julia integration yet)
312+ - Errors are silently ignored to avoid breaking token operations
313+
314+ This ensures Julia credentials stay in sync with the main auth tokens without requiring manual intervention.
315+
316+ ### Command Structure
317+
318+ - ** ` jh run ` ** : Primary command - always starts Julia after setting up credentials
319+ - ** ` jh run setup ` ** : Subcommand - only sets up credentials without starting Julia
320+ - ** ` jh auth login ` ** : Automatically sets up Julia credentials after successful login
321+ - ** ` jh auth refresh ` ** : Automatically sets up Julia credentials after successful refresh
0 commit comments