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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Install the release locally: `brew update && brew upgrade ccs`.
- `ccs mcp` (`internal/mcp`, entry point `mcp.Main`): a stdio MCP server (hand-rolled newline-delimited JSON-RPC: initialize, ping, tools/list, tools/call) that answers one request at a time; `launch_session` and `close_session` (not graceful) hold their reply at most `sessionCallCap` (8s, `capped`), since clients give a tool call about 10s and a slow start would otherwise time the call out and hold up later ones: past the cap they answer "still starting" or "still closing" and the work carries on, its outcome to the activity log with `search_sessions`, `list_sessions`, `read_session`, `launch_session`, `close_session`, `restart_session` (these three need no transcripts, `mcp.mcpSessionCall`), and `list_prs`, `claim_pr` and `depends` (`mcp.prCall`: `github.RunPRs` (`--merged` with `merged`), `github.ClaimAs` (the calling session, or with `session` the one running session of that name, `github.LiveNamed`: a Codex one by `codexName`, as `ccs claim` inside Codex names it; stubbed in tests) and `github.RunDepends`, no transcripts either). `read_session` lists `mcp.readEntries`: the messages with each AskUserQuestion (`Conversation.Asks`, `transcript.Ask`, `asks.go`: `noteAsk` on the call, `noteAskResult` on its result, each question's answer and notes from the line's `toolUseResult`, read only for that result, else the result's text, as after a prune), each question placed by `At` as `Tools` are and each answer by `AnswerAt`, where its result arrived, one entry per question and per answer; they are not messages, so counts, times, unread and the list's search ignore them, and the query filter and offsets count them. Each call rescans through `transcript.GetConversations`, except a question only about the running sessions (session_triage, list_sessions live_only, and `ccs sessions` without --all), which parses only theirs (`LoadLive`, `transcript.GetConversationsFor`, turned on by `UseLiveLoads` from `Main` and the CLI, never in tests; parents not loaded keep their recorded name, `sessions.ParentNamesLoaded`); after each tools/call `AfterCall` (`transcript.DropParseCache`) drops every parsed transcript, so an idle server holds tens of MB, not the ~650 MB every parsed transcript takes (one server per Claude session: a burst of calls once froze the machine). A big scan (`GetConversations` with more than `scanSlotMin` transcripts not parsed yet in the process) takes one of `ScanSlots` (2) machine-wide slots first (`internal/transcript/scanslots.go`: a flock on `scan-N.lock` beside the settings, waiting up to `ScanWait`, else `ErrScanBusy`) and holds it while the parsed transcripts are held: until `DropParseCache` (ccs mcp, after each call), process exit (a CLI command), or `ReleaseScanSlot` straight after the first load in the list and `ccs serve`, which keep their cache and so never hold a slot for good; stdout is the protocol stream, so nothing else may print to it
- `ccs watch` (in `internal/github`): the PR watcher (`github.WatchPass`, `github.PRWatchState`, events in `github.PREventsPath`)
- `ccs hook session-start` (`internal/mcp/sessionstart.go`, `sessionStartHook`, `recordStartParent`, `startParent`, `launchedIn`): the SessionStart hook `ccs hook install` adds (`ourHooks`, `sessionStartTimeout`). On source "startup" only, it finds the new session in `hookSessions` (waiting `startFileWait` for its file), leaves a record whose `ChildID` is already this session (ccs launch, launch_session), and records (`ParentRec.Source` "start") the first running session among its process's ancestors (`proc.PsTree`, `startPPID`), else the running session whose transcript tail (`startTranscript`, `startTailBytes`) has, within `startEvidenceWindow`, a Bash command `transcript.LaunchNames` finds its name in (open-tab.sh, claude --name/-n, ccs launch --name) or a launch_session call with it. An env var can't do this: a tab opened through osascript or tmux starts a fresh login shell. Prints nothing (SessionStart output becomes context), never fails, and gives up after `sessionStartDeadline`. `ccs hook status` (`runHookStatus`, `HookStatus`, read-only) lists each of `ourHooks` installed or missing, exit 1 when any is; `HooksOutOfDate` is the missing ones when some are installed (none is a choice), which the TUI (`hooks.go`: `checkHooksCmd` with the scheduled minute refresh and on `tea.FocusMsg`, `hooksMissing`, `hooksNote`) shows as a dim static `hooks out of date: run ccs hook install` among the header's toggles and names in ? help. The TUI never writes Claude Code's settings. Codex has no such hook: `codexLauncher` in `nestFamilies` nests a named Codex session with no record under the listed session whose `Launches` holds its name, the newest that began before it
- `ccs hook stop` (`internal/mcp/childturn.go`, `stopHook`, `childTurn`): the Stop hook `ccs hook install` adds beside the PermissionRequest one (`ourHooks`, `hookCommandFor`, `isOurHookFor`, `withoutOursFor`; install and uninstall handle each, and add only what's missing). It finds the session's parent record (`sessions.LoadParents`: by child id, else by its name from `hookCallerName`, the session file of the hook's claude process or the one naming the id, so a session with no parent reads files only and never runs ps) and only then reads the session files (`hookSessions`: no ps, a signal-0 check per pid) for the parent: its recorded id, else the one running session with its name. `stopHook` gives up after `stopHookDeadline` (5s), below Claude Code's `stopHookTimeout` (15s). It reads the last `childTurnTail` (1 MB) of the transcript (`readTurnTail`: the turn's prompt, its last tool call and a `Conversation` for `triageOf`, the session's status forced idle) and skips a turn an automatic notice started (`autoNotice`), one whose last tool call was a SendMessage to the parent (`toParent`: name, name [ref] or its socket), a repeat in the same bucket within `childTurnDebounce` (30s), and parents turned off (`SetChildNotices`; `child-notices.json` beside the settings under a flock, `withChildNotices`; `ccs hook child-notices on|off [--orchestrator]`, MCP `child_notices`). It sends `childTurnText` through `sendChildTurn` (the parent's session file and socket, `SendEnvelope` with `childTurnSender` "ccs hook" and `ChildTurnNote`, no reply address, no typing) and writes a `child_turn` line (`ChildTurnEvent`) for every notice decided, delivered or not. It prints nothing and always exits 0. Tests stub `hookSessions`, `stopHookDeadline`, `sessions.ParentsPath`, `childNoticesPath`, `hookCallerName`, `sendChildTurn` and `parentSocket`
- `ccs hook stop` (`internal/mcp/childturn.go`, `stopHook`, `childTurn`): the Stop hook `ccs hook install` adds beside the PermissionRequest one (`ourHooks`, `hookCommandFor`, `isOurHookFor`, `withoutOursFor`; install and uninstall handle each, and add only what's missing). It finds the session's parent record (`sessions.LoadParents`: by child id, else by its name from `hookCallerName`, the session file of the hook's claude process or the one naming the id, so a session with no parent reads files only and never runs ps) and only then reads the session files (`hookSessions`: no ps, a signal-0 check per pid) for the parent: its recorded id, else the one running session with its name. `stopHook` gives up after `stopHookDeadline` (5s), below Claude Code's `stopHookTimeout` (15s). It reads the last `childTurnTail` (1 MB) of the transcript (`readTurnTail`: the turn's prompt, the `to` of every SendMessage since it (`SentTo`; a message queued mid-turn keeps them) and a `Conversation` for `triageOf`, the session's status forced idle) and skips a turn an automatic notice started (`autoNotice`), one that sent the parent a SendMessage at any point (`toParent`: name, name [ref] or its socket), one whose child is now `waiting_on_external`, a repeat in the same bucket within `childTurnDebounce` (30s), and parents turned off (`SetChildNotices`; `child-notices.json` beside the settings under a flock, `withChildNotices`; `ccs hook child-notices on|off [--orchestrator]`, MCP `child_notices`). It sends `childTurnText` through `sendChildTurn` (the parent's session file and socket, `SendEnvelope` with `childTurnSender` "ccs hook" and `ChildTurnNote`, no reply address, no typing) and writes a `child_turn` line (`ChildTurnEvent`) for every notice decided, delivered or not. It prints nothing and always exits 0. Tests stub `hookSessions`, `stopHookDeadline`, `sessions.ParentsPath`, `childNoticesPath`, `hookCallerName`, `sendChildTurn` and `parentSocket`
- `ccs orchestrator-report` and MCP `orchestrator_report` (`internal/mcp/report.go`, `RunReport`, `reportCall`): `BuildReport` scores each orchestrator (`orgTree`: the session in orchestrator.json, `reportTopID`, and every parent in `launch-parents.json` via `sessions.LoadParents`; the top one answers for every session and PR, the others for their `subtree`) from `pr-events.jsonl` (`readReportEvents`; a PR's owner is its `new` event's `opened_by`, else its first `claimed`) and its own transcript (`readOrchTranscript`: only lines stamped in the period plus `responseCap`, skipped before parsing; the user's own messages via `typedByUser`, including ones typed in ccs (`viaCCS`, meta once handed over) and queued mid-turn; its text and tool calls). `score` counts response (`needsResponse` events to the first mention of an `eventKeys` key, missed past `responseCap`), stalled minutes, done to close, `idleNudge` and `correction` matches (quoted in `Quotes`), `handsOn` calls (`handsOnBash`) and `ccsBash`, merges and ready to merged; live counts and span breaches (`maxSpan` 6 direct, `maxDepth` 2) only when the period ends now. `withPrevious` attaches the newest earlier day's file and saves this one (`reportDir`, `reports/<name>/<date>.json`); `formatScorecard` prints ▲/▼ by `trend`. Tests stub `sessions.ParentsPath`, `reportTopID`, `reportDir` and `transcript.GetProjectsDir`
- `ccs sessions --triage` and MCP `session_triage` (`internal/mcp/triage.go`): each live session in one bucket, tested in order by `classify` (waiting_on_user, working, waiting_on_external, done, stalled, idle; `bucketOrder` lists them), the reason quoting the deciding sentence of its last message (`matched`; `asksToRun`, `waitsOnYou`, `saysFinished`/`saysNotFinished`), open PRs from `ownedPRs` (`github.OpenPRsByOwner`: saved state and claims read only, never pruned, by `github.OwnerKey`; stubbed in tests). `WatchSessions` is `github.SessionTick` (set in `cli.go` before `ccs watch`): after every pass it triages, reading only the live transcripts, each pass only their new lines (`liveConversations`, `watchConvs`, `ParseAppended`), and writes `session_stalled` / `session_done` once per stretch of idleness (`sessionEvents`, keyed by `IdleSince`, kept in `session-events.json`, a session missed by a scan remembered for `sessionEventKeep`; `--no-session-events`, `--stall-after`), and `session_active` when one leaves a stall or finish (`sessionEventRec.State`, `StateAt`, `Since`), `session_started` for a session not seen before (none on the first scan ever, an empty record) and `session_ended` once it is missing from `endAfterMisses` (2) scans in a row (a record from before names were kept ends silently). Wake-ups come from `internal/transcript/schedules.go`: each `ScheduleWakeup` and `CronCreate` (`Schedule`, from the result line's `toolUseResult`: `scheduledFor`, `nextFireAt`, `recurring`, `durable`; else the input and the result text), ended by a stop, a later wakeup or `CronDelete`; `PendingSchedules` keeps those set by the current process (unless durable) still ahead
- Codex claims: `codexSession` is in `internal/github`, the rest in `internal/sessions` (`ccs claim` inside Codex, from `CODEX_THREAD_ID`, since Codex's sandbox runs no `ps`; named by `transcript.CodexLaunchName`, the launch folder among the transcript's `runtime_workspace_roots`, else `sessions.CodexThreadName` from `session_index.jsonl`), `sessions.CodexThreadFor` (a launch's thread), `sessions.CodexLive` (a launched thread's codex process is running, else its transcript written within `sessions.CodexIdle`), `sessions.CodexQueue` (`codex queue --thread`, how nudges reach Codex, `sessions.CodexNudgeNote` first). A `github.PRClaim` with `Kind` codex is keyed by `Thread`, with no pid. Tests point `transcript.CodexHome` at a temp folder and stub `sessions.CodexQueue`
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ PRs: app#12 checks running
```

- Claude Code runs `ccs hook stop` the moment a turn ends, so it works with the TUI and `ccs watch` closed. It reads only the parent records, the session files in `~/.claude/sessions` and the last 1 MB of the child's own transcript, never runs ps or loads other transcripts, and gives up after 5 seconds; it never prints anything, so it can't keep a turn going. Measured with 17 sessions running and 1,152 transcripts: about 10 ms and 17 MB peak for a session with no parent, about 35 ms and 22 MB for a child.
- The notice carries the child's name, its bucket now as `session_triage` would put it (`waiting_on_user`, `waiting_on_external`, `done` or `idle`) with why, its last message cut to 300 characters, and its open PRs. It goes over the parent's own socket in ccs's automatic-notice envelope, never the user's, and only to a running parent: by its recorded id, else the one running session with its name (two with that name get nothing). There is no typing fallback and nothing is queued for a closed parent.
- The notice carries the child's name, its bucket now as `session_triage` would put it (`waiting_on_user`, `done` or `idle`) with why, its last message cut to 300 characters, and its open PRs. It goes over the parent's own socket in ccs's automatic-notice envelope, never the user's, and only to a running parent: by its recorded id, else the one running session with its name (two with that name get nothing). There is no typing fallback and nothing is queued for a closed parent.
- Each notice is also a `child_turn` line in `pr-events.jsonl`: `{at, event, session, session_id, parent, parent_id, bucket, reason, last, prs, delivered, error}`; `error` says why it wasn't delivered (`parent not running`, or the send's error).
- Not told: a turn started only by an automatic ccs notice (a child-turn notice, a `ccs watch` nudge, `ccs reorg` or `ccs close`), so a turn doesn't cascade up the tree; a turn whose last tool call was a `SendMessage` to the parent; the same bucket again within 30 seconds of the last notice; and orchestrators that turned them off with `ccs hook child-notices off` (`--orchestrator <name>`, default the calling session) or MCP `child_notices` (`enabled`, `orchestrator`), kept in `child-notices.json` beside ccs's settings.
- Not told: a turn started only by an automatic ccs notice (a child-turn notice, a `ccs watch` nudge, `ccs reorg` or `ccs close`), so a turn doesn't cascade up the tree; a turn that sent the parent a `SendMessage` at any point, since it already told it; a child now `waiting_on_external` (CI, a reviewer, its tasks, subagents or a wake-up), since the parent can do nothing yet and `ccs watch` nudges the child when a check fails (a question still gets through: `waiting_on_user` comes first); the same bucket again within 30 seconds of the last notice; and orchestrators that turned them off with `ccs hook child-notices off` (`--orchestrator <name>`, default the calling session) or MCP `child_notices` (`enabled`, `orchestrator`), kept in `child-notices.json` beside ccs's settings.
- `session_stalled` and `session_done` still fire after the stall threshold: a child left idle after its notice is one nobody acted on.

Running sessions pick the hook up only after a restart.
Expand Down
Loading
Loading