Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions cmd/arc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,18 +1052,20 @@ var updateCmd = &cobra.Command{
// Handle --take flag
take, _ := cmd.Flags().GetBool("take")
sessionID, _ := cmd.Flags().GetString("session-id")
sessionIDSet := cmd.Flags().Changed("session-id")

if sessionID != "" && !take {
if sessionIDSet && !take {
return errors.New("--session-id requires --take")
}

if take {
// Resolve session ID: explicit flag > env var > error
if sessionID == "" {
sessionID = os.Getenv("ARC_SESSION_ID")
sessionID, err = resolveSessionID(sessionID, sessionIDSet)
if err != nil {
return err
}
if sessionID == "" {
return errors.New("no session ID available — set ARC_SESSION_ID or pass --session-id")
return errors.New(
"no session ID available — set ARC_SESSION_ID or pass --session-id")
}
updates["ai_session_id"] = sessionID
// Set status to in_progress unless user explicitly passed --status
Expand Down Expand Up @@ -1131,8 +1133,8 @@ func init() {
updateCmd.Flags().StringP("description", "d", "", "New description")
updateCmd.Flags().Bool("stdin", false, "Read description from stdin")
updateCmd.Flags().Bool("take", false,
"Take this issue for the current AI session (sets ai_session_id + status=in_progress)")
updateCmd.Flags().String("session-id", "", "Explicit AI session ID (used with --take)")
"Take this issue (session: --session-id > ARC_SESSION_ID; status=in_progress)")
updateCmd.Flags().String("session-id", "", "Explicit AI session ID (requires --take; overrides ARC_SESSION_ID)")
updateCmd.Flags().StringSlice("label-add", nil, "Label to add (repeatable)")
updateCmd.Flags().StringSlice("label-remove", nil, "Label to remove (repeatable)")
}
Expand Down
53 changes: 36 additions & 17 deletions cmd/arc/prime.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,28 @@ Role detection (in priority order):

Workflow customization:
- Place a .arc/PRIME.md file to override the default output entirely.`,
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
explicitSessionID, _ := cmd.Flags().GetString("session-id")
explicitSessionIDSet := cmd.Flags().Changed("session-id")
if explicitSessionIDSet && explicitSessionID == "" {
return errEmptySessionID
}

// Read hook stdin and persist session ID if available
sessionID := readHookStdin()
if sessionID != "" {
persistSessionID(sessionID)
hookSessionID := readHookStdin()
if hookSessionID != "" {
persistSessionID(hookSessionID)
}

// Also check env var (may have been set by a previous SessionStart hook)
if sessionID == "" {
sessionID = os.Getenv("ARC_SESSION_ID")
sessionID, err := resolvePrimeSessionID(explicitSessionID, explicitSessionIDSet, hookSessionID)
if err != nil {
return err
}

// Check if this project has arc configured via workspace path resolution
cwd, err := os.Getwd()
if err != nil {
os.Exit(0)
return nil
}
normalizedCwd := project.NormalizePath(cwd)

Expand All @@ -77,15 +83,15 @@ Workflow customization:
// Fall back to legacy config check (works offline)
arcHome := project.DefaultArcHome()
if cfg, err := readLegacyConfig(arcHome, cwd); err != nil || cfg == nil {
os.Exit(0)
return nil
}
}

// Check for custom PRIME.md override
localPrimePath := ".arc/PRIME.md"
if content, err := os.ReadFile(localPrimePath); err == nil {
_, _ = os.Stdout.Write(content)
return
return nil
}

// Detect role from flag or env var
Expand All @@ -97,14 +103,14 @@ Workflow customization:
// Role-based output takes precedence over mode flags
if role == "lead" {
if err := outputTeamLeadContext(os.Stdout, sessionID); err != nil {
os.Exit(0)
return nil
}
return
return nil
} else if role != "" {
if err := outputTeammateContext(os.Stdout, role, sessionID); err != nil {
os.Exit(0)
return nil
}
return
return nil
}

// Determine output mode
Expand All @@ -115,8 +121,9 @@ Workflow customization:

// Output workflow context
if err := outputPrimeContext(os.Stdout, mcpMode, sessionID); err != nil {
os.Exit(0)
return nil
}
return nil
},
}

Expand Down Expand Up @@ -225,6 +232,7 @@ func init() {
primeCmd.Flags().BoolVar(&primeFullMode, "full", false, "Force full CLI output")
primeCmd.Flags().BoolVar(&primeMCPMode, "mcp", false, "Force MCP mode (minimal output)")
primeCmd.Flags().StringVar(&primeRole, "role", "", "Teammate role (lead, frontend, backend, etc.)")
primeCmd.Flags().String("session-id", "", "Explicit AI session ID (overrides hook input and ARC_SESSION_ID)")
rootCmd.AddCommand(primeCmd)
}

Expand Down Expand Up @@ -339,6 +347,16 @@ var tmplCLI = template.Must(template.New("cli").Parse(`# Arc Workflow Context
- Git workflow: commit and push at session end
- Session management: check ` + "`arc ready`" + ` for available work

### Session Identity
- The CLI accepts only ` + "`--session-id`" + ` and ` + "`ARC_SESSION_ID`" + `; harnesses pass their
current identity explicitly.
- Pass a harness's current binding as
` + "`arc update <id> --take --session-id <session-id>`" + ` or
` + "`arc prime --session-id <session-id>`" + `. Do not copy a parent session ID into a spawned worker.
- A supplied empty ` + "`--session-id`" + ` fails instead of falling back.
` + "`--session-id`" + ` on ` + "`update`" + ` requires ` + "`--take`" + `.
- ` + "`prime`" + ` and ` + "`--take`" + ` do not register sessions; harness setup owns registration.

## Essential Commands

### Finding Work
Expand Down Expand Up @@ -369,7 +387,8 @@ var tmplCLI = template.Must(template.New("cli").Parse(`# Arc Workflow Context
` + "`arc create \"Phase\" --type=milestone --parent=<release-id>`" + ` (auto-sequences
after the previous milestone; ` + "`--parallel`" + ` for an independent track,
` + "`--after=<id>`" + ` to sequence explicitly)
- ` + "`arc update <id> --take`" + ` - Take issue for current AI session (sets session ID + in_progress)
- ` + "`arc update <id> --take --session-id <session-id>`" + ` - Take issue for current AI session
(sets session ID + in_progress)
- ` + "`arc update <id> --title=\"new title\"`" + ` - Update fields
- ` + "`arc update <id> --stdin <<'EOF'`" + ` - Update description via stdin heredoc
- ` + "`arc close <id>`" + ` - Mark complete
Expand Down Expand Up @@ -404,7 +423,7 @@ var tmplCLI = template.Must(template.New("cli").Parse(`# Arc Workflow Context
` + "```bash" + `
arc ready # Find available work
arc show <id> # Review issue details
arc update <id> --take # Take it (sets session ID + in_progress)
arc update <id> --take --session-id <session-id> # Take it (sets session ID + in_progress)
` + "```" + `

**Completing work:**
Expand Down
13 changes: 13 additions & 0 deletions cmd/arc/prime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func TestPrime(t *testing.T) {
{"documents arc roadmap command", "arc roadmap"},
{"documents --under flag", "--under"},
{"documents --parallel flag", "--parallel"},
{"documents generic session identity", "ARC_SESSION_ID"},
{"documents explicit session identity", "--session-id"},
{"documents separate registration", "do not register sessions"},
}

for _, tt := range tests {
Expand All @@ -87,4 +90,14 @@ func TestPrime(t *testing.T) {
}
})
}
if strings.Contains(content, "$CURRENT_SESSION_ID") {
t.Error("prime output must not invent a session environment variable")
}
}

func TestPrimeSessionIDFlag(t *testing.T) {
flag := primeCmd.Flags().Lookup("session-id")
if flag == nil {
t.Fatal("prime must expose --session-id")
}
}
33 changes: 33 additions & 0 deletions cmd/arc/session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"errors"
"os"
)

var errEmptySessionID = errors.New("--session-id cannot be empty")

// resolveSessionID uses an explicitly supplied session ID or Arc's generic
// environment fallback. Harness integrations are responsible for passing their
// native identity through one of these provider-neutral boundaries.
func resolveSessionID(explicit string, explicitSet bool) (string, error) {
if explicitSet {
if explicit == "" {
return "", errEmptySessionID
}
return explicit, nil
}
return os.Getenv("ARC_SESSION_ID"), nil
}

// resolvePrimeSessionID gives a validated Claude hook identity precedence over
// ARC_SESSION_ID unless prime was given an explicit session ID.
func resolvePrimeSessionID(explicit string, explicitSet bool, hookID string) (string, error) {
if explicitSet {
return resolveSessionID(explicit, true)
}
if hookID != "" {
return hookID, nil
}
return resolveSessionID("", false)
}
Loading