Repository navigation
Conversation
…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]>
|
| Filename | Overview |
|---|---|
| tokenjam/cli/cmd_onboard.py | Adds stable sentinel constants, _zshrc_otel_block, and _strip_zshrc_otel_blocks; replaces the old check-then-append-or-replace logic with a clean strip-then-write pattern. One minor edge case: the sentinel regex requires a trailing \n after _ZSHRC_OTEL_END, so a manually-truncated block at end-of-file would survive stripping. |
| tokenjam/cli/cmd_uninstall.py | Replaces inline regex with a shared _strip_zshrc_otel_blocks call; removes now-unused top-level import re. Clean refactor with no logic changes to the surrounding uninstall steps. |
| tests/unit/test_onboard_zshrc_otel.py | New unit test file covering the strip function against all legacy marker combinations, idempotency, and the full onboard/uninstall round-trip at the function level. Good coverage of the bug's exact shape. |
| tests/integration/test_cli.py | Adds two integration tests exercising the real CLI paths against a seeded zshrc with both legacy marker blocks; uses monkeypatch / patch isolation correctly. Minor: the onboard integration test relies on Path.home classmethod patching which works but couples to the module's import path. |
| CLAUDE.md | Adds rule 21 documenting the stable-sentinel requirement for future dotfile-managed blocks, grounding it in the concrete history of the ocw->tj marker drift. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["tj onboard --claude-code"] --> B["Read ~/.zshrc"]
B --> C["_strip_zshrc_otel_blocks(text)"]
C --> D["Remove current sentinel block"]
D --> E["Remove legacy 'tj harness observability' block"]
E --> F["Remove legacy 'ocw harness observability' block"]
F --> G{"stripped.strip() non-empty?"}
G -- Yes --> H["stripped.rstrip() + newline + new_block"]
G -- No --> I["new_block only"]
H --> J["zshrc.write_text(updated)"]
I --> J
K["tj uninstall"] --> L["Read ~/.zshrc"]
L --> M["_strip_zshrc_otel_blocks(text)"]
M --> N{"cleaned != text?"}
N -- Yes --> O["zshrc.write_text(cleaned)"]
N -- No --> P["No-op"]
style C fill:#d4edda
style M fill:#d4edda
%%{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 --claude-code"] --> B["Read ~/.zshrc"]
B --> C["_strip_zshrc_otel_blocks(text)"]
C --> D["Remove current sentinel block"]
D --> E["Remove legacy 'tj harness observability' block"]
E --> F["Remove legacy 'ocw harness observability' block"]
F --> G{"stripped.strip() non-empty?"}
G -- Yes --> H["stripped.rstrip() + newline + new_block"]
G -- No --> I["new_block only"]
H --> J["zshrc.write_text(updated)"]
I --> J
K["tj uninstall"] --> L["Read ~/.zshrc"]
L --> M["_strip_zshrc_otel_blocks(text)"]
M --> N{"cleaned != text?"}
N -- Yes --> O["zshrc.write_text(cleaned)"]
N -- No --> P["No-op"]
style C fill:#d4edda
style M fill:#d4edda
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:960-965
The sentinel-block regex requires `_ZSHRC_OTEL_END` to be followed by a literal `
`. If the block ever appears at the very end of a file without a trailing newline (e.g. a user's text editor stripped it), the pattern will fail to match and the block will survive `uninstall` or re-onboard. Adding `
?` makes the trailing newline optional without affecting any other case.
```suggestion
cleaned = _re.sub(
rf"{_re.escape(_ZSHRC_OTEL_START)}\n.*?{_re.escape(_ZSHRC_OTEL_END)}\n?",
"",
text,
flags=_re.DOTALL,
)
```
### Issue 2 of 2
tokenjam/cli/cmd_onboard.py:966-971
The legacy-marker regex uses `(?:export [^
]+
)*`, which requires each matched export line to end with `
`. If the legacy block's last line is also the last line of the file and lacks a trailing newline, the regex matches only the marker line itself and leaves the final export line (including the bearer token) in the file. Adding an optional trailing-newline alternative closes the gap.
```suggestion
for marker in _ZSHRC_OTEL_LEGACY_MARKERS:
cleaned = _re.sub(
rf"{_re.escape(marker)}\n(?:export [^\n]+\n)*(?:export [^\n]+)?",
"",
cleaned,
)
```
Reviews (1): Last reviewed commit: "docs: durable lesson — dotfile-managed b..." | Re-trigger Greptile
| cleaned = _re.sub( | ||
| rf"{_re.escape(_ZSHRC_OTEL_START)}\n.*?{_re.escape(_ZSHRC_OTEL_END)}\n", | ||
| "", | ||
| text, | ||
| flags=_re.DOTALL, | ||
| ) |
There was a problem hiding this comment.
The sentinel-block regex requires
_ZSHRC_OTEL_END to be followed by a literal . If the block ever appears at the very end of a file without a trailing newline (e.g. a user's text editor stripped it), the pattern will fail to match and the block will survive uninstall or re-onboard. Adding ? makes the trailing newline optional without affecting any other case.
| cleaned = _re.sub( | |
| rf"{_re.escape(_ZSHRC_OTEL_START)}\n.*?{_re.escape(_ZSHRC_OTEL_END)}\n", | |
| "", | |
| text, | |
| flags=_re.DOTALL, | |
| ) | |
| cleaned = _re.sub( | |
| rf"{_re.escape(_ZSHRC_OTEL_START)}\n.*?{_re.escape(_ZSHRC_OTEL_END)}\n?", | |
| "", | |
| text, | |
| flags=_re.DOTALL, | |
| ) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/cli/cmd_onboard.py
Line: 960-965
Comment:
The sentinel-block regex requires `_ZSHRC_OTEL_END` to be followed by a literal `
`. If the block ever appears at the very end of a file without a trailing newline (e.g. a user's text editor stripped it), the pattern will fail to match and the block will survive `uninstall` or re-onboard. Adding `
?` makes the trailing newline optional without affecting any other case.
```suggestion
cleaned = _re.sub(
rf"{_re.escape(_ZSHRC_OTEL_START)}\n.*?{_re.escape(_ZSHRC_OTEL_END)}\n?",
"",
text,
flags=_re.DOTALL,
)
```
How can I resolve this? If you propose a fix, please make it concise.| for marker in _ZSHRC_OTEL_LEGACY_MARKERS: | ||
| cleaned = _re.sub( | ||
| rf"{_re.escape(marker)}\n(?:export [^\n]+\n)*", | ||
| "", | ||
| cleaned, | ||
| ) |
There was a problem hiding this comment.
The legacy-marker regex uses
(?:export [^ ]+ )*, which requires each matched export line to end with . If the legacy block's last line is also the last line of the file and lacks a trailing newline, the regex matches only the marker line itself and leaves the final export line (including the bearer token) in the file. Adding an optional trailing-newline alternative closes the gap.
| for marker in _ZSHRC_OTEL_LEGACY_MARKERS: | |
| cleaned = _re.sub( | |
| rf"{_re.escape(marker)}\n(?:export [^\n]+\n)*", | |
| "", | |
| cleaned, | |
| ) | |
| for marker in _ZSHRC_OTEL_LEGACY_MARKERS: | |
| cleaned = _re.sub( | |
| rf"{_re.escape(marker)}\n(?:export [^\n]+\n)*(?:export [^\n]+)?", | |
| "", | |
| cleaned, | |
| ) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: tokenjam/cli/cmd_onboard.py
Line: 966-971
Comment:
The legacy-marker regex uses `(?:export [^
]+
)*`, which requires each matched export line to end with `
`. If the legacy block's last line is also the last line of the file and lacks a trailing newline, the regex matches only the marker line itself and leaves the final export line (including the bearer token) in the file. Adding an optional trailing-newline alternative closes the gap.
```suggestion
for marker in _ZSHRC_OTEL_LEGACY_MARKERS:
cleaned = _re.sub(
rf"{_re.escape(marker)}\n(?:export [^\n]+\n)*(?:export [^\n]+)?",
"",
cleaned,
)
```
How can I resolve this? If you propose a fix, please make it concise.
Summary
Fixes #118 — the
~/.zshrcOTEL export block written bytj onboard --claude-codewas keyed on a single-line comment marker that had itself already drifted once in this repo's history. That made re-onboard's "replace in place" andtj uninstall's removal blind to a block written under an older marker.Git-history finding (the drift is real, not hypothetical)
The zshrc OTEL block's marker literally changed once already, in this repo's own tracked history:
300861c("Add agents API endpoint, alert acknowledge REST+MCP, and full uninstall cleanup") as# ocw harness observability.281275f("Rename project: openclawwatch → Token Juice") to# tj harness observability— the ocw→tj rebrand.The rename commit updated the marker string used by future onboards but shipped no migration for users who had already onboarded under the old marker — exactly the shape reported in #118 (a real
~/.zshrcwith both an# ocw harness observabilityblock and a# tj harness observabilityblock, different bearer tokens). Because both onboard's replace and uninstall's removal only ever matched the current marker string, the old-marker block was invisible to both: re-onboard appended a second block instead of replacing the first (stale secrets accumulate), and uninstall left the old block behind.(Aside: the Codex
[otel]config has an analogous, already-fixed legacy-ocwpurge —_codex_purge_legacy_ocw— showing this class of drift bit that surface too, pre-#118.)Fix
# >>> tokenjam OTEL (managed) >>>/# <<< tokenjam OTEL <<<. This pair is not tied to the product name and won't drift on a future rename._strip_zshrc_otel_blocks()(new, shared by both commands incmd_onboard.py) removes the current sentinel block and every known legacy marker block (# tj harness observability,# ocw harness observability) in one pass.onboard --claude-codenow strips-then-appends: strip all managed blocks, then write exactly one fresh block. Running it twice (or against a zshrc with legacy blocks) leaves exactly one block, with the current secret.tj uninstallnow calls the same_strip_zshrc_otel_blocks()for removal, so it cleans up legacy-marker blocks too, not just the current one.Scope boundary
Did not touch the
claude()per-terminal wrapper block (# tj per-terminal naming) — that's owned by #117 (merges first).Merge order: CC install/remove cluster — merge #117 → #118 → #121; this is #118 (merge after #117).
Test plan
tests/unit/test_onboard_zshrc_otel.py— pure-function coverage of_strip_zshrc_otel_blocks/_zshrc_otel_block, including the exact dual-legacy-marker shape from README: add Lens and Reuse to the roadmap #118.tests/integration/test_cli.py—test_onboard_claude_code_replaces_legacy_zshrc_otel_markersandtest_uninstall_removes_legacy_and_current_zshrc_otel_blocks, seeding a~/.zshrcwith both legacy blocks, running the realonboard --claude-code/uninstallCLI commands, and asserting exactly one block after onboard / zero after uninstall.python -m pytest tests/unit/ -k "onboard or uninstall or otel or zshrc" -q→ 146 passedpython -m pytest tests/integration/test_cli.py -q→ 80 passedpython -m pytest tests/unit/ -q(full suite) → 1644 passed, 1 skipped (pre-existing, unrelated)ruff check tokenjam/cli/cmd_onboard.py tokenjam/cli/cmd_uninstall.py→ clean🤖 Generated with Claude Code