mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-03 22:19:42 +02:00
fix(session): learn the live Claude conversation from the CLI's own hook
Which conversation a pane is on was re-derived by correlating ~/.claude/history.jsonl against Session.lastSubmitAt — and lastSubmitAt is bumped only by input that flows through Codeman's own write path (Session.write / writeViaMux). A user who attaches to the pane's tmux session directly never set it, so resolveActiveClaudeSessionIdFromHistory() returned at its first line for that pane's whole life and the response viewer stayed pinned to the launch conversation, showing a pre-/clear transcript indefinitely. A UserPromptSubmit hook reports the live conversation id from inside the CLI process, delivered under the pane's own $CODEMAN_SESSION_ID. That binding is a fact rather than a correlation: it never consults workingDir, so it cannot be claimed by a sibling pane on the same folder, a closed tab, or a bare `claude` in the user's terminal. A pane holding such an id skips the correlation entirely, so the number of prompts eligible for cwd-based guessing goes DOWN, never up — the naive alternative (relax the guard, or synthesize an anchor from PTY activity) is the reverted bug the resolver's own comment describes. The hook also stamps lastSubmitAt, so it finally means "a prompt was submitted" rather than "typed into Codeman's web terminal". Conversations vouched for first-hand — and only those — extend a persisted claudeSessionChain, whose tail re-pins the conversation when a surviving tmux session is re-attached after a restart. ⚠️ start() resets the id at THREE points and the last one runs unconditionally after the mux branch, so the tail is applied there too; patching only the mux branch looks right and silently does nothing. ⚠️ The hook's stdout is discarded with curl's own -o /dev/null. Claude Code injects a UserPromptSubmit hook's stdout into the model's context ("Exit code 0 - stdout shown to Claude"), and a trailing >/dev/null does NOT work: curlCmd already ends `... 2>/dev/null || true`, and in `pipeline || true >/dev/null` the shell binds the redirection to `true`, which never runs on the success path. The discard is opt-in so the five SSE-fed events keep byte-identical command text and no workspace's settings file is rewritten for them. The staleness marker is quote-free for the matching reason: hooksJson is JSON.stringify'd, so a quoted needle never matches and the gate would rewrite every workspace on every spawn. Existing workspaces heal on their next Claude spawn through the staleness sweep.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
---
|
||||
"aicodeman": patch
|
||||
---
|
||||
|
||||
fix(session): learn the live Claude conversation from the CLI's own hook
|
||||
|
||||
Which conversation a pane is on was re-derived by correlating `~/.claude/history.jsonl`
|
||||
against `Session.lastSubmitAt` — and `lastSubmitAt` is bumped only by input that flows
|
||||
through Codeman's own write path. A user who attaches to the pane's tmux session directly
|
||||
never set it, so the resolver returned at its first line for that pane's whole life and the
|
||||
response viewer stayed pinned to the launch conversation, showing a pre-`/clear` transcript
|
||||
indefinitely. A new `UserPromptSubmit` hook reports the live conversation id from inside the
|
||||
CLI process, addressed by the pane's own `$CODEMAN_SESSION_ID`, so the id is a fact rather
|
||||
than a correlation: it never consults the working directory and cannot be claimed by a
|
||||
sibling pane on the same folder. A pane with such an id now skips the correlation entirely,
|
||||
which strictly reduces the number of prompts eligible for cwd-based guessing. The hook also
|
||||
stamps `lastSubmitAt`, so it finally means "a prompt was submitted" rather than "typed into
|
||||
Codeman's web terminal". Conversations vouched for this way are persisted as a chain, whose
|
||||
tail re-pins the conversation when a surviving tmux session is re-attached after a restart —
|
||||
`start()` otherwise resets the id back to the launch conversation. Existing workspaces heal
|
||||
on their next Claude spawn via the hooks staleness sweep. The hook's stdout is discarded with curl's own `-o /dev/null`:
|
||||
Claude Code injects `UserPromptSubmit` output into the model's context, so an undiscarded
|
||||
curl would paste the API envelope into the user's own prompt on every turn.
|
||||
Reference in New Issue
Block a user