Repository navigation
feat(claude-code): symmetric onboard/uninstall + new tj reset (resolves #117, #118, #121) - #442
Conversation
#117) `tj onboard --claude-code` writes a `claude()` shell function into ~/.zshrc (and ~/.bashrc) via `_install_claude_wrapper()`, but `tj uninstall` had no counterpart removal path — leaving a `claude()` function that calls `tj` on every launch, which errors once the package is uninstalled. Add `_unwire_claude_wrapper()` (marker-delimited removal, mirroring the install path) and call it from `cmd_uninstall`. Also wire in the existing but never-called `_unwire_claude_output_cap_hook()` so an opted-in PostToolUse cap hook is cleaned up too. Co-Authored-By: Claude <[email protected]>
…t; document symmetric npx remove (#121) Extends `tj uninstall`'s existing --remove-package opt-in (#430) to make `npx tokenjam uninstall` a complete, symmetric counterpart to `npx tokenjam onboard`: detect uv-tool installs (not just pipx/pip) and auto-run the matching removal command, and detect ephemeral runners (uvx/pipx run) to make --purge a safe no-op with an explanation instead of guessing at a removal command that doesn't apply. --purge is added as an alias for --remove-package so existing scripts/tests keep working. Co-Authored-By: Claude <[email protected]>
…ip legacy markers (#118) The ~/.zshrc OTEL export block was keyed on a single-line comment marker that had itself already drifted once in this repo's history: the ocw->tj rebrand (commit 281275f) renamed "# ocw harness observability" to "# tj harness observability" but never migrated already-onboarded users' shell rc files. A block written under the older marker was invisible to both re-onboard's "replace in place" (which only matched the current marker) and `tj uninstall`'s removal — so re-onboarding APPENDED a second block with a fresh bearer token instead of replacing the stale one, and uninstall left old-marker blocks behind. Replace the marker with a stable, content-based sentinel pair (">>> tokenjam OTEL (managed) >>>" / "<<< tokenjam OTEL <<<") that will never be renamed. onboard now strips ALL managed blocks — the sentinel pair plus every known legacy marker — before appending exactly one fresh block; uninstall strips the same set. The removal routine (_strip_zshrc_otel_blocks) is shared between both commands. Co-Authored-By: Claude <[email protected]>
…ent marker (#118) Promotes the #118 root cause into Critical Rules so future onboard/uninstall dotfile-writing features (zshrc blocks, shell wrappers, etc.) use a stable sentinel + strip-all-legacy-markers pattern from the start, instead of re-discovering the same marker-drift bug. Co-Authored-By: Claude <[email protected]>
Applies four fixes found while combining #117/#118/#121 into one branch: - _is_ephemeral_runner() no longer misclassifies uv-managed Python runtimes (.../uv/python/...) as ephemeral — only uv's cache dirs (archive-/builds-/.cache/uv/) count, so `tj uninstall --purge` no longer silently no-ops for pip-into-uv-python installs (P1). - _strip_zshrc_otel_blocks() and _unwire_claude_wrapper() both required a trailing newline after their end marker, so a managed block that was the last line of a file with no final newline was left behind (leaking a bearer token). Trailing newline is now optional. - test_remove_package_flag_non_pipx_prints_command now mocks _installed_via_uv_tool/_is_ephemeral_runner so it no longer depends on the CI runner's own sys.executable. Co-Authored-By: Claude <[email protected]>
ruff F401 — all real usages go through uninstall_mod.subprocess (patching the module's own import), not the top-level `subprocess` name. Co-Authored-By: Claude <[email protected]>
|
| Filename | Overview |
|---|---|
| tokenjam/cli/cmd_onboard.py | Adds _zshrc_otel_block, _strip_zshrc_otel_blocks, and _unwire_claude_wrapper; refactors zshrc write to strip-then-write with stable sentinels; all three helpers carry correct optional-trailing-newline regexes. |
| tokenjam/cli/cmd_uninstall.py | Adds _installed_via_uv_tool, _is_ephemeral_runner, ephemeral-runner early-exit, and uv-tool branch in _remove_package; drops the now-unused re import; all hint helpers updated for the new install type. |
| tests/unit/test_onboard_zshrc_otel.py | New unit-test file; covers sentinel block, both legacy-marker variants, no-trailing-newline edge cases, and full onboard/uninstall round-trip semantics for _strip_zshrc_otel_blocks. |
| tests/unit/test_uninstall_runner_detect.py | New unit-test file; exhaustively covers all sys.executable path shapes (pipx, uv-tool, uvx cache, pipx run cache, plain pip, uv-managed Python runtime) and the uv-runtime non-ephemeral regression. |
| tests/unit/test_uninstall_wrapper.py | New unit-test file; covers _unwire_claude_wrapper (round-trip, idempotent, no-trailing-newline edge case, bashrc co-cleanup) and an end-to-end CLI test asserting no claude() / tj residue after tj uninstall. |
| tests/integration/test_cli_uninstall.py | Drops the subprocess import that's now unused; makes test_remove_package_flag_non_pipx_prints_command hermetic by also mocking _installed_via_uv_tool and _is_ephemeral_runner; adds uv-tool, ephemeral-runner, and prompt-suppression test cases. |
| tests/integration/test_cli.py | Adds MagicMock import and two integration tests for the zshrc OTEL sentinel/legacy-strip behaviour on both onboard and uninstall paths. |
| CLAUDE.md | Adds rule 21 documenting the sentinel-block invariant and the migration lesson from the ocw->tj rebrand for future managed-dotfile-block features. |
| docs/claude-code-integration.md | Rewrites the Uninstalling section to document the symmetric one-command pair, --purge detection logic, and ephemeral-runner behaviour. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant User
participant CLI
participant onboard as cmd_onboard
participant uninstall as cmd_uninstall
participant zshrc as ~/.zshrc / ~/.bashrc
participant settings as ~/.claude/settings.json
Note over User,settings: tj onboard --claude-code (install)
User->>CLI: tj onboard --claude-code
CLI->>onboard: _onboard_claude_code()
onboard->>zshrc: _strip_zshrc_otel_blocks (remove sentinel + legacy markers)
onboard->>zshrc: write one fresh sentinel-delimited OTEL block
onboard->>onboard: _install_claude_wrapper()
onboard->>zshrc: append claude() wrapper block
onboard->>settings: write OTEL env vars and hooks
Note over User,settings: tj uninstall (symmetric remove)
User->>CLI: tj uninstall --purge --yes
CLI->>uninstall: cmd_uninstall()
uninstall->>settings: remove OTEL env vars, resume-brief hook, output-cap hook
uninstall->>onboard: _strip_zshrc_otel_blocks (sentinel + all legacy blocks)
onboard->>zshrc: regex-remove managed OTEL block
uninstall->>onboard: _unwire_claude_wrapper()
onboard->>zshrc: regex-remove WRAPPER_MARKER block
uninstall->>uninstall: _is_ephemeral_runner()?
alt ephemeral runner uvx or pipx run
uninstall->>User: nothing persistent to remove, purge is no-op
else pipx or uv-tool install
uninstall->>User: auto-runs pipx or uv tool uninstall tokenjam
else plain pip install
uninstall->>User: prints pip uninstall tokenjam command
end
%%{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"}}}%%
sequenceDiagram
participant User
participant CLI
participant onboard as cmd_onboard
participant uninstall as cmd_uninstall
participant zshrc as ~/.zshrc / ~/.bashrc
participant settings as ~/.claude/settings.json
Note over User,settings: tj onboard --claude-code (install)
User->>CLI: tj onboard --claude-code
CLI->>onboard: _onboard_claude_code()
onboard->>zshrc: _strip_zshrc_otel_blocks (remove sentinel + legacy markers)
onboard->>zshrc: write one fresh sentinel-delimited OTEL block
onboard->>onboard: _install_claude_wrapper()
onboard->>zshrc: append claude() wrapper block
onboard->>settings: write OTEL env vars and hooks
Note over User,settings: tj uninstall (symmetric remove)
User->>CLI: tj uninstall --purge --yes
CLI->>uninstall: cmd_uninstall()
uninstall->>settings: remove OTEL env vars, resume-brief hook, output-cap hook
uninstall->>onboard: _strip_zshrc_otel_blocks (sentinel + all legacy blocks)
onboard->>zshrc: regex-remove managed OTEL block
uninstall->>onboard: _unwire_claude_wrapper()
onboard->>zshrc: regex-remove WRAPPER_MARKER block
uninstall->>uninstall: _is_ephemeral_runner()?
alt ephemeral runner uvx or pipx run
uninstall->>User: nothing persistent to remove, purge is no-op
else pipx or uv-tool install
uninstall->>User: auto-runs pipx or uv tool uninstall tokenjam
else plain pip install
uninstall->>User: prints pip uninstall tokenjam command
end
Reviews (2): Last reviewed commit: "Merge branch 'main' into cc-install-remo..." | Re-trigger Greptile
Summary
Combines three merged-ready fixes into one symmetric install/remove flow for the Claude Code integration, then redesigns the removal UX into two clearly-named commands:
tj uninstallnow removes theclaude()shell wrapper (and the opt-in output-cap PostToolUse hook) thattj onboard --claude-codeinstalls, so a subsequentclaudelaunch doesn't break after the tj package is gone.~/.zshrcOTEL export block now uses a stable sentinel delimiter and_strip_zshrc_otel_blocks()replaces/removes every managed block (current sentinel + any legacy marker), fixing re-onboard appending a second stale-secret block instead of replacing it.tj uninstalldetects how tokenjam was installed (pipx /uv tool/ plain pip) and either runs the right uninstall command or prints it, with a no-op-and-explain path for ephemeral runners (uvx/pipx run).Uninstall/reset redesign: two commands, no flag
Per product decision, replaced the
--purge/--remove-packageflag model with two clearly-named commands:tj uninstall→ full removal by default: the Layer-2 config/daemon/wiring teardown (MCP dereg,~/.zshrcOTEL block +claude()wrapper, per-project settings, daemon) plus Layer-1 package removal (what--purgeused to gate). This is now the single symmetric counterpart totj onboard. Installer-aware behavior is preserved: pipx/uv-tool installs auto-run their uninstall; a plain pip/venv install only gets the exact command printed (never guessed); an ephemeral runner (uvx/pipx run) is a safe no-op with an explanation.tj reset(new) → Layer-2 teardown only — package stays installed, ready totj onboardagain. Useful for reconfiguring or pausing without reinstalling the CLI._teardown_side_effects()incmd_uninstall.py(pure refactor) so both commands call the same code path.--purge,--remove-package, and the old second "also remove the package?" prompt are gone. The single top-level confirmation fortj uninstallnow states both consequences (config + package removal) up front.npx tokenjam uninstall/npx tokenjam resetboth work through the existing generic npm-wrapper passthrough — no wrapper changes needed.docs/claude-code-integration.md,docs/cli-reference.md) updated to the new model.Greptile fixes applied
_is_ephemeral_runner()incmd_uninstall.pyno longer misclassifies uv-managed Python runtimes (.../uv/python/cpython-.../bin/python3) as ephemeral — it now only matches uv's cache dirs (/uv/archive-,/uv/builds-,.cache/uv/), sotj uninstall's package-removal step no longer silently no-ops for apip install-into-uv-managed-Python setup._strip_zshrc_otel_blocks()incmd_onboard.py— both the sentinel-block and legacy-marker regexes required a trailing\nafter the end marker, so a managed block that was the last line of a file with no final newline was left behind (leaking a bearer token). Trailing newline is now optional._unwire_claude_wrapper()incmd_onboard.py— same class of bug on the wrapper's end marker; fixed the same way._installed_via_uv_tool/_is_ephemeral_runner(not just_installed_via_pipx) so they no longer depend on the CI runner's ownsys.executable.Supersedes #439, #441, #440 — those are the per-ticket branches now folded into this single PR.
Test plan
python -m pytest tests/unit/ tests/integration/ -q→ 2102 passed, 1 skipped, 2 warnings in 40.37sruff checkclean on all touched files<<<<<<</>>>>>>>/=======conflict markers across both the three-way feature merge and the latermainsync merge--purge/--remove-package/--keep-packagereferences anywhere intokenjam/,tests/,docs/(grep-confirmed)tj uninstall --help/tj reset --helpshow the new command surface with no stale flags🤖 Generated with Claude Code