Repository navigation
[feature] Path-branched tj onboard first run - #432
Conversation
The bare `tj onboard` (no flag) assumed an SDK/API user: it prompted for the Claude plan, showed a `@watch`/`patch_anthropic` snippet, and verified by polling for a live span. For a Claude Code user — the most common case — that left an empty, useless tool and a verify that could never succeed (no live span is ever emitted; their data lives in on-disk logs). Redesign the bare path to open with a path question that routes to the flow matching how the user actually runs agents, so backfill happens AFTER the choice, per path: - Claude Code → the existing --claude-code flow (plan prompt, auto-backfill of ~/.claude/projects, statusline wiring); success = "N sessions backfilled", not a live-span wait. - Codex → the existing --codex OTel wiring, THEN a defensive Codex backfill (`tokenjam.core.ingest_adapters.codex.ingest_codex`, resolved via a guarded import since that adapter is a separate workstream and may not have landed); forward-only framing when unavailable. - Your own agents (SDK/API) → the existing generic path: plan/provider prompt, the `@watch`/`patch_anthropic` snippet, live-span verify via `tj ping`. - A combination → ask which surfaces they use, run the necessary backfills, report what was done, then show the SDK instrument snippet — one sequence. Every path now ends on the shared branded home screen + tailored next-best-actions (reusing `cli/home.print_home`), prefixed with an honest "N sessions backfilled" note only when a backfill actually ingested data. `--claude-code` / `--codex` remain shortcuts that skip the question. The path question is only asked interactively — a non-tty bare invocation (scripts, CI) falls through to the historical generic SDK path unchanged. Copy keeps the honesty discipline (Critical Rule 14): no promised savings, no backfill claim when nothing was ingested, forward-only framing when the Codex adapter is absent. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015e3DZGhb1R5sXX2x52Y2Ar
…ible); omit spend when 0
|
| Filename | Overview |
|---|---|
| tokenjam/cli/cmd_onboard.py | Adds path-branched interactive routing, per-path closing banners, and defensive Codex backfill; two bugs: (1) _onboard_combination calls _try_backfill_codex a second time even though _onboard_codex already calls it internally, and (2) each sub-onboarder prints its own _print_setup_complete_home(), so the combination flow prints "You're set up." up to three times. |
| tests/unit/test_onboard_path_branch.py | 15 new unit tests covering routing, tty detection, defensive Codex backfill, and the closing banner; no end-to-end test for the combination path with multiple surfaces selected, so the double-backfill and duplicate-banner bugs are not caught. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[tj onboard] --> B{Flag provided?}
B -->|--claude-code| CC[_onboard_claude_code]
B -->|--codex| CX[_onboard_codex]
B -->|bare| C{_is_interactive?}
C -->|No TTY| SDK[Generic SDK path]
C -->|Yes| D[_prompt_usage_path]
D -->|claude_code| CC
D -->|codex| CX
D -->|sdk| SDK
D -->|combination| COMB[_onboard_combination]
CC --> CC2[_print_setup_complete_home]
CX --> CX1[_try_backfill_codex first call]
CX --> CX2[_print_setup_complete_home]
COMB --> Q1{uses_cc?}
Q1 -->|Yes| CC
CC2 --> Q2{uses_codex?}
Q1 -->|No| Q2
Q2 -->|Yes| CX
CX2 --> DUP[_try_backfill_codex DUPLICATE second call]
DUP --> Q3{uses_sdk?}
Q2 -->|No| Q3
Q3 -->|Yes| SNIP[Show SDK snippet]
SNIP --> FINAL[_print_setup_complete_home third call]
Q3 -->|No| FINAL
SDK --> SDKFIN[_print_setup_complete_home]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[tj onboard] --> B{Flag provided?}
B -->|--claude-code| CC[_onboard_claude_code]
B -->|--codex| CX[_onboard_codex]
B -->|bare| C{_is_interactive?}
C -->|No TTY| SDK[Generic SDK path]
C -->|Yes| D[_prompt_usage_path]
D -->|claude_code| CC
D -->|codex| CX
D -->|sdk| SDK
D -->|combination| COMB[_onboard_combination]
CC --> CC2[_print_setup_complete_home]
CX --> CX1[_try_backfill_codex first call]
CX --> CX2[_print_setup_complete_home]
COMB --> Q1{uses_cc?}
Q1 -->|Yes| CC
CC2 --> Q2{uses_codex?}
Q1 -->|No| Q2
Q2 -->|Yes| CX
CX2 --> DUP[_try_backfill_codex DUPLICATE second call]
DUP --> Q3{uses_sdk?}
Q2 -->|No| Q3
Q3 -->|Yes| SNIP[Show SDK snippet]
SNIP --> FINAL[_print_setup_complete_home third call]
Q3 -->|No| FINAL
SDK --> SDKFIN[_print_setup_complete_home]
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
tokenjam/cli/cmd_onboard.py:1717-1736
**Double Codex backfill in combination path**
`_onboard_codex` now calls `_try_backfill_codex` internally (added in this PR, line ~1584), and `_onboard_combination` then calls it a second time in the explicit try/except block immediately after. On the combination path with Codex selected, the adapter runs twice against the same on-disk logs, producing a duplicate console line and double-counting sessions. The stale comment ("The per-Codex onboarder is forward-only (no backfill of its own)") reflects the pre-PR state and is now incorrect. The second `_try_backfill_codex` call should be removed; the count surfaced by `_onboard_codex` is already reported inline.
### Issue 2 of 2
tokenjam/cli/cmd_onboard.py:1706-1757
**"You're set up." printed up to three times in combination flow**
`_onboard_claude_code` and `_onboard_codex` each end with their own `_print_setup_complete_home()` call (added in this PR). When `_onboard_combination` calls both sub-onboarders and then calls `_print_setup_complete_home()` itself on line 1757, a user who selects Claude Code + Codex + SDK will see the "You're set up." banner three times in a single run. The sub-onboarders should skip the closing banner when invoked as part of a combination flow (e.g. via an `is_subflow=False` guard), or `_onboard_combination` should call them in a way that suppresses the banner and renders it exactly once at the end.
Reviews (1): Last reviewed commit: "Merge branch 'main' into feat/onboard-pa..." | Re-trigger Greptile
| # --- Codex (full flow: OTel wiring) then a defensive backfill --- | ||
| if uses_codex: | ||
| console.print() | ||
| console.print("[bold]Setting up Codex…[/bold]") | ||
| _onboard_codex( | ||
| ctx, budget, no_daemon, force, reconfigure=False, | ||
| plan_override=plan_override, verify=False, | ||
| ) | ||
| # The per-Codex onboarder is forward-only (no backfill of its own); try | ||
| # the on-disk Codex backfill defensively so combination reports it too. | ||
| try: | ||
| from tokenjam.core.config import load_config as _lc | ||
| global_path = Path.home() / ".config" / "tj" / "config.toml" | ||
| if global_path.exists(): | ||
| codex_cfg = _lc(str(global_path)) | ||
| cx_msg, _cx_has, _cx_n = _try_backfill_codex(codex_cfg) | ||
| if cx_msg: | ||
| console.print(f" Codex backfilled: {cx_msg}") | ||
| except Exception: | ||
| pass |
There was a problem hiding this comment.
Double Codex backfill in combination path
_onboard_codex now calls _try_backfill_codex internally (added in this PR, line ~1584), and _onboard_combination then calls it a second time in the explicit try/except block immediately after. On the combination path with Codex selected, the adapter runs twice against the same on-disk logs, producing a duplicate console line and double-counting sessions. The stale comment ("The per-Codex onboarder is forward-only (no backfill of its own)") reflects the pre-PR state and is now incorrect. The second _try_backfill_codex call should be removed; the count surfaced by _onboard_codex is already reported inline.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/cli/cmd_onboard.py
Line: 1717-1736
Comment:
**Double Codex backfill in combination path**
`_onboard_codex` now calls `_try_backfill_codex` internally (added in this PR, line ~1584), and `_onboard_combination` then calls it a second time in the explicit try/except block immediately after. On the combination path with Codex selected, the adapter runs twice against the same on-disk logs, producing a duplicate console line and double-counting sessions. The stale comment ("The per-Codex onboarder is forward-only (no backfill of its own)") reflects the pre-PR state and is now incorrect. The second `_try_backfill_codex` call should be removed; the count surfaced by `_onboard_codex` is already reported inline.
How can I resolve this? If you propose a fix, please make it concise.| # --- Claude Code (full flow: config + statusline + auto-backfill) --- | ||
| if uses_cc: | ||
| console.print() | ||
| console.print("[bold]Setting up Claude Code…[/bold]") | ||
| _onboard_claude_code( | ||
| ctx, budget, no_daemon, force, reconfigure=False, | ||
| plan_override=plan_override, project_override=project_override, | ||
| verify=False, | ||
| ) | ||
| done.append("Claude Code") | ||
|
|
||
| # --- Codex (full flow: OTel wiring) then a defensive backfill --- | ||
| if uses_codex: | ||
| console.print() | ||
| console.print("[bold]Setting up Codex…[/bold]") | ||
| _onboard_codex( | ||
| ctx, budget, no_daemon, force, reconfigure=False, | ||
| plan_override=plan_override, verify=False, | ||
| ) | ||
| # The per-Codex onboarder is forward-only (no backfill of its own); try | ||
| # the on-disk Codex backfill defensively so combination reports it too. | ||
| try: | ||
| from tokenjam.core.config import load_config as _lc | ||
| global_path = Path.home() / ".config" / "tj" / "config.toml" | ||
| if global_path.exists(): | ||
| codex_cfg = _lc(str(global_path)) | ||
| cx_msg, _cx_has, _cx_n = _try_backfill_codex(codex_cfg) | ||
| if cx_msg: | ||
| console.print(f" Codex backfilled: {cx_msg}") | ||
| except Exception: | ||
| pass | ||
| done.append("Codex") | ||
|
|
||
| # --- Custom SDK / API agents: show the instrument snippet --- | ||
| if uses_sdk: | ||
| console.print() | ||
| console.print("[bold]Instrument your own agents:[/bold]") | ||
| console.print() | ||
| _print_instrument_agent_snippet() | ||
| console.print() | ||
| console.print( | ||
| " Then run your agent and verify a live span is flowing with " | ||
| "[bold]tj ping[/bold] (in another terminal)." | ||
| ) | ||
| done.append("SDK/API") | ||
|
|
||
| console.print() | ||
| console.print( | ||
| f"[bold green]Combination setup complete[/bold green] " | ||
| f"[dim]({', '.join(done)})[/dim]" | ||
| ) | ||
| _print_setup_complete_home() |
There was a problem hiding this comment.
"You're set up." printed up to three times in combination flow
_onboard_claude_code and _onboard_codex each end with their own _print_setup_complete_home() call (added in this PR). When _onboard_combination calls both sub-onboarders and then calls _print_setup_complete_home() itself on line 1757, a user who selects Claude Code + Codex + SDK will see the "You're set up." banner three times in a single run. The sub-onboarders should skip the closing banner when invoked as part of a combination flow (e.g. via an is_subflow=False guard), or _onboard_combination should call them in a way that suppresses the banner and renders it exactly once at the end.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/cli/cmd_onboard.py
Line: 1706-1757
Comment:
**"You're set up." printed up to three times in combination flow**
`_onboard_claude_code` and `_onboard_codex` each end with their own `_print_setup_complete_home()` call (added in this PR). When `_onboard_combination` calls both sub-onboarders and then calls `_print_setup_complete_home()` itself on line 1757, a user who selects Claude Code + Codex + SDK will see the "You're set up." banner three times in a single run. The sub-onboarders should skip the closing banner when invoked as part of a combination flow (e.g. via an `is_subflow=False` guard), or `_onboard_combination` should call them in a way that suppresses the banner and renders it exactly once at the end.
How can I resolve this? If you propose a fix, please make it concise.… (#434) Five review findings from the just-merged onboarding batch, addressed together because they cluster around the same onboard/uninstall UX and the SDK exporter/backfill idempotency touched in that batch. #432 (P1): the combination path double-ran the Codex backfill and printed the closing home banner up to three times. `_onboard_codex` ran its own backfill AND printed the banner, `_onboard_claude_code` printed the banner too, and `_onboard_combination` did both again. Fix: give both per-path sub-onboarders a `standalone: bool = True` parameter. The combination flow passes `standalone=False`, which suppresses each sub-onboarder's own Codex backfill and closing banner — so the backfill runs exactly once (in the combination leg) and the banner prints exactly once (at the very end). Single-path flows keep `standalone=True` and are unchanged. #430 (P1): after a successful `pipx uninstall tokenjam`, the venv is gone, so the printed reinstall hint `pipx upgrade tokenjam` would fail ("not installed"). Added `_package_fresh_install_hint()` (bare `pipx install` / `pip install`) and use it only on the successful-removal path. The upgrade/--force hint stays where it belongs — when the package REMAINS (a plain install would no-op there). #430 (P2): `--remove-package` help text overstated ("runs pipx/pip uninstall") — for non-pipx installs it only PRINTS the command. Reworded the help + option text and the interactive confirm prompt so they say "runs" for pipx and "prints … for you to run" for pip/venv. #431 (P2): a whitespace-only ingest secret was truthy, so `TjHttpExporter` built `Authorization: Bearer ` — the same illegal header value the empty case already guards against. Now guard on `.strip()` so a blank secret omits the header entirely. #433 (P2): `ingest_codex` issued one `SELECT 1 FROM spans WHERE span_id=$1` per span. Aligned it with the Claude Code path's bulk idempotency by reusing `core.backfill._existing_span_ids` — one chunked `WHERE span_id IN (...)` per session partitions new-vs-existing spans, replacing the per-span existence SELECT. Backends without a `conn` (InMemoryBackend) fall back to plain inserts and let the PRIMARY KEY conflict skip duplicates. Tests: combination path backfills each source ONCE and prints the banner ONCE (TestCombinationPathNoDoubleRun); after-removal reinstall hint is `pipx install` not upgrade; prompt wording matches install type; whitespace-only secret omits the Authorization header; a DuckDB-backed idempotency test exercises the new bulk `_existing_span_ids` path. Claude-Session: https://claude.ai/code/session_015e3DZGhb1R5sXX2x52Y2Ar Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
tj onboard(no flag) assumed an SDK/API user: it prompted for the Claude plan, showed a@watch/patch_anthropicsnippet, and verified by polling for a live span. For a Claude Code user — the most common case — that left an empty tool and a verify that can never succeed (Claude Code emits no live span into an SDK pipeline; its data is on-disk logs). This redesigns the bare path to ask how the user actually runs agents, then backfill/wire per path.Summary
tj onboardopens with "How do you use AI agents?" → (1) Claude Code (2) Codex (3) Your own agents (Python/TS SDK or API) (4) A combination.--claude-code/--codexstay as shortcuts that skip the question.Per-path flow
--claude-codeflow — Anthropic plan prompt → auto-backfill~/.claude/projectsviaingest_claude_code→ statusline wiring → success reported as "N sessions backfilled" (not a live-span wait). No@watchstep.--codex[otel]wiring → then a defensive Codex backfill. The Codex on-disk adapter (tokenjam.core.ingest_adapters.codex.ingest_codex) is a separate workstream and may not have landed, so it's resolved via a guarded import (_try_backfill_codex): reports the count when present, forward-only framing ("Wired — data flows as you use Codex") when absent — never crashes, never over-claims.@watch/patch_anthropicsnippet → live-span verify (personasdkalready referencestj ping).Design decisions
tj onboardskips the question and runs the historical generic SDK path, so existing automation is unchanged. Gated behind a new_is_interactive()seam (CliRunner swapssys.stdin, so this is the testable hook).cmd_backfill.py/ the ingest adapters are owned by another agent._try_backfill_codexnever imports the adapter at module load — only inside the function, inside try/except — so this PR works whether or nottj backfill codexhas shipped._print_setup_complete_home()reusescli/home.print_home()for the next-best-actions block and prefixes an honest "N sessions backfilled" line only when a backfill actually ingested data.Tests / Verification
tests/unit/test_onboard_path_branch.py(15 tests): the path prompt lists all four paths and returns the right key; bare onboard routes to the selected path; SDK choice falls through to generic; non-tty skips the question;--claude-code/--codexshortcuts skip it;_try_backfill_codexis forward-only when the adapter is missing and reports counts when present; the closing banner reports counts only with data.ruff check tokenjam/clean;mypy tokenjam/cli/cmd_onboard.pyclean.tests/unit/test_onboard*.py(128) +tests/integration/test_cli.py(78) green.What's NOT in this PR
cmd_backfill.pyor the ingest adapters — the Codex backfill adapter is another agent's workstream; this PR calls it defensively.cmd_ping.py—tj pingis another agent's fix; the SDK-path verify text references it, nothing more.🤖 Generated with Claude Code