diff --git a/AGENTS.md b/AGENTS.md index 2eb7e40..dfb5fc2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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//.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` diff --git a/README.md b/README.md index ce6f12d..fdafb5c 100644 --- a/README.md +++ b/README.md @@ -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 `, 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 `, 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. diff --git a/docs/design/relay.md b/docs/design/relay.md index e5bc1f1..aaba27f 100644 --- a/docs/design/relay.md +++ b/docs/design/relay.md @@ -82,7 +82,7 @@ The running TUI queues and delivers while it's open; `ccs mcp` uses it when it's - The orchestrator (`ccs orchestrator`) adds no background process of ccs's own: it's an ordinary visible session whose role says to run `ccs watch` as its own background task, which ends with it. - ccs never posts on the user's behalf: it reports PR changes as events (`ccs watch`), and posting review requests is another tool's job (the two-slack plugin's consumer reads those events). - ccs sends sessions automatic notices in two cases. The first, option A's shape: `ccs watch` tells the live session that claimed a PR (`ccs claim`) about its failing checks, conflicts and new unanswered review threads, once per PR, head and reason. The envelope is its own (`from-name="ccs watch"`, a note saying it's an automatic status notice, not typed by the user and not from another session), never the user wrapper; the recipient must be live and its pid must still run the claiming session; there's no typing fallback, and each notice is an event the user can see. `--no-nudge` turns it off. -- The second automatic notice is the child-turn notice: Bharat chose a Claude Code Stop hook (`ccs hook stop`, added by `ccs hook install`) over a faster `ccs watch` tick or an event line alone, so it is immediate and needs no ccs process running. It goes only to the recorded parent (launch or adopt), only while that parent runs (by its id, else the one running session with its name; never a guess between two), in its own envelope (`from-name="ccs hook"`, marked automatic, never the user wrapper), over the socket with no typing fallback and nothing queued, and each one is a `child_turn` event the user can see. It isn't sent for a turn an automatic ccs notice started (no cascade up the tree), for a turn that ended with a SendMessage to the parent, or for a repeat in the same bucket within 30 seconds; an orchestrator can turn it off (`ccs hook child-notices off`, MCP `child_notices`). It carries the child's bucket, its last message cut to 300 characters and its open PRs, not history. `session_stalled` and `session_done` stay alongside it. +- The second automatic notice is the child-turn notice: Bharat chose a Claude Code Stop hook (`ccs hook stop`, added by `ccs hook install`) over a faster `ccs watch` tick or an event line alone, so it is immediate and needs no ccs process running. It goes only to the recorded parent (launch or adopt), only while that parent runs (by its id, else the one running session with its name; never a guess between two), in its own envelope (`from-name="ccs hook"`, marked automatic, never the user wrapper), over the socket with no typing fallback and nothing queued, and each one is a `child_turn` event the user can see. It isn't sent for a turn an automatic ccs notice started (no cascade up the tree), for a turn that sent the parent a SendMessage at any point, for a child now waiting_on_external (Bharat chose these two on 2026-11-20, after notice turns turned out to cost about a fifth of his spend, mostly acknowledgements of children waiting on CI), or for a repeat in the same bucket within 30 seconds; an orchestrator can turn it off (`ccs hook child-notices off`, MCP `child_notices`). It carries the child's bucket, its last message cut to 300 characters and its open PRs, not history. `session_stalled` and `session_done` stay alongside it. - Handoff carries a caller-written summary and explicit references, not automatic history. - A handover close (`ccs close --handover`, ^X W, `close_session` with `handover`) is the user asking a session to give its leftovers to its parent and be closed, so it stays inside these lines: it runs only when the user (or the orchestrator acting for them) asks, and ^X W asks first; it goes only to the recorded parent while that parent runs (by its id, else the one running session with its name), and is refused with nothing sent when there is none; the session writes the handover itself, the session-handoff skill's handback, and sends it with its own SendMessage, so ccs adds no history; ccs's notices to the child and then to the parent are in ccs close's envelope (marked automatic, never the user wrapper), over the socket with no typing fallback; what moves (PR claims, child sessions) and whether the handover was seen are logged and told to the parent. - `ccs reorg` (^X M) is the one place ccs starts and messages sessions in bulk on the user's behalf, so it stays inside these lines: it runs only when the user asks; the model's plan is checked by code (real orchestrators, the top one fixed, two levels, three topics each, clean topic text, a member's folder) and shown whole, and nothing launches or moves until the user accepts it (Enter once the end has been shown and past a short grace, or y/N in the CLI; `--yes` is the user's own choice for scripts); a plan whose sessions changed since is refused; the records are backed up (`ccs reorg --undo`) and saved before anything launches or is told; new orchestrators open in visible tabs through `ccs launch`; notices go only to live sessions, in ccs reorg's own envelope (marked automatic, never the user wrapper), over their socket with no typing fallback; closed sessions are only regrouped, never resumed or messaged; and each run is logged with its plan. The model call itself has no tools, MCP servers, settings files, hooks or commands, and is a visible session under the top orchestrator, not a hidden process. diff --git a/internal/mcp/childturn.go b/internal/mcp/childturn.go index 2b647a4..a829661 100644 --- a/internal/mcp/childturn.go +++ b/internal/mcp/childturn.go @@ -143,13 +143,12 @@ func SetChildNotices(parent string, on bool, now time.Time) error { } // turnTail is what the hook reads from the end of the transcript: the -// prompt that started the last turn, the turn's last tool call, and the +// prompt that started the last turn, who the turn sent messages to, and the // conversation as far as the tail goes. type turnTail struct { - Prompt string // the last prompt's text (typed, queued or a cross-session message) - LastTool string // the name of the last tool call after it - LastTo string // with SendMessage, its "to" - Conv transcript.Conversation + Prompt string // the last prompt's text (typed, queued or a cross-session message) + SentTo []string // the "to" of each SendMessage call after it + Conv transcript.Conversation } // readTurnTail reads the last childTurnTail bytes of path. @@ -202,11 +201,13 @@ func (t *turnTail) note(line []byte) { if json.Unmarshal(line, &l) != nil || l.IsSide { return } - prompt := func(s string) { t.Prompt, t.LastTool, t.LastTo = strings.TrimSpace(s), "", "" } + prompt := func(s string) { t.Prompt, t.SentTo = strings.TrimSpace(s), nil } switch l.Type { case "attachment": if l.Attachment.Type == "queued_command" { - prompt(l.Attachment.Prompt) + // Arrived mid-turn: the same turn goes on, so what it already + // sent still counts. + t.Prompt = strings.TrimSpace(l.Attachment.Prompt) } case "user": var s string @@ -241,8 +242,8 @@ func (t *turnTail) note(line []byte) { } json.Unmarshal(l.Message.Content, &blocks) for _, b := range blocks { - if b.Type == "tool_use" { - t.LastTool, t.LastTo = b.Name, b.Input.To + if b.Type == "tool_use" && b.Name == "SendMessage" { + t.SentTo = append(t.SentTo, b.Input.To) } } } @@ -465,13 +466,23 @@ func childTurn(req stopRequest, now time.Time) (ChildTurnEvent, bool) { if autoNotice.MatchString(tail.Prompt) { return ChildTurnEvent{}, false // a notice started it: telling the parent would cascade up the tree } - if tail.LastTool == "SendMessage" && ppid != 0 && toParent(tail.LastTo, rec.Parent, parentSocket(ppid)) { - return ChildTurnEvent{}, false // it just told the parent itself + if ppid != 0 { + socket := parentSocket(ppid) + for _, to := range tail.SentTo { + if toParent(to, rec.Parent, socket) { + return ChildTurnEvent{}, false // it told the parent itself during the turn + } + } } tail.Conv.Title = me.Stat.Name me.Stat.Status, me.Stat.Since = "idle", now // the turn has just ended, whatever the file says yet prs := ownedPRs(now)[ownerKey("claude", req.SessionID)] row := triageOf(tail.Conv, me, prs, now, DefaultStallAfter) + if row.Bucket == BucketWaitingOnExternal { + // Waiting on CI, a reviewer, its tasks or a wake-up: the parent can do + // nothing yet, and ccs watch nudges the child when a check fails. + return ChildTurnEvent{}, false + } e := ChildTurnEvent{At: now.UTC().Format(time.RFC3339), Event: "child_turn", Session: cmpOr(me.Stat.Name, rec.Child), SessionID: req.SessionID, Parent: rec.Parent, ParentID: cmpOr(pid, rec.ParentID), Bucket: row.Bucket, Reason: row.Reason, Last: row.LastSaid, PRs: row.OpenPRs} skip := false diff --git a/internal/mcp/childturn_test.go b/internal/mcp/childturn_test.go index 90e1a37..7f15541 100644 --- a/internal/mcp/childturn_test.go +++ b/internal/mcp/childturn_test.go @@ -329,3 +329,54 @@ func TestStopHookDeadline(t *testing.T) { close(release) <-finished } + +func TestChildTurnSkipsSentEarlierAndWaiting(t *testing.T) { + path, sent := childTurnFixture(t) + now := time.Now().UTC().Truncate(time.Second) + at := now.Add(-2 * time.Minute) + sendTo := func(to string) map[string]any { + return map[string]any{"type": "tool_use", "name": "SendMessage", "input": map[string]any{"to": to, "message": "HANDOVER x"}} + } + + // It told the parent earlier in the turn, then went on working: not told. + turn(t, path, at, "open the PR", say("Watching CI."), sendTo("boss"), bash("gh pr checks 12")) + if _, ok := childTurn(stop(path), now); ok { + t.Error("a SendMessage to the parent before the last tool call isn't told") + } + + // A message queued mid-turn doesn't end the turn: what it sent before still counts. + writeLines(t, path, + userLine(at, "open the PR", false), + assistantLine(at.Add(10*time.Second), sendTo("boss")), + map[string]any{"type": "attachment", "timestamp": at.Add(20 * time.Second).Format(time.RFC3339Nano), "attachment": map[string]any{"type": "queued_command", "prompt": "also bump the version"}}, + assistantLine(at.Add(30*time.Second), bash("make bump")), + assistantLine(at.Add(40*time.Second), say("Bumped."))) + if _, ok := childTurn(stop(path), now); ok { + t.Error("a SendMessage to the parent before a queued message isn't told") + } + + // It told the parent in an earlier turn only: told. + writeLines(t, path, + userLine(at, "open the PR", false), + assistantLine(at.Add(10*time.Second), sendTo("boss")), + assistantLine(at.Add(20*time.Second), say("Sent.")), + userLine(at.Add(time.Minute), "now fix the docs", false), + assistantLine(at.Add(70*time.Second), say("Should I also update the README?"))) + if _, ok := childTurn(stop(path), now); !ok { + t.Error("a SendMessage in an earlier turn doesn't stop this one being told") + } + + // Waiting on CI: not told. The same turn with a question in it: told. + stubOwned(map[string][]github.PRRow{ownerKey("claude", "k1"): {{PR: "https://github.com/o/r/pull/12", Group: "waiting", Status: "checks running"}}}) + turn(t, path, at, "push the fix", say("Pushed; waiting on CI.")) + if _, ok := childTurn(stop(path), now.Add(time.Hour)); ok { + t.Error("a child waiting_on_external isn't told") + } + turn(t, path, at, "push the fix", say("Pushed. Should I also bump the timeout?")) + if e, ok := childTurn(stop(path), now.Add(2*time.Hour)); !ok || e.Bucket != BucketWaitingOnUser { + t.Errorf("a question still gets through with CI running: %v %+v", ok, e) + } + if len(*sent) != 2 { + t.Errorf("two notices sent in all: %d", len(*sent)) + } +} diff --git a/internal/mcp/mcp.go b/internal/mcp/mcp.go index 355b3ea..2ab102f 100644 --- a/internal/mcp/mcp.go +++ b/internal/mcp/mcp.go @@ -276,7 +276,7 @@ var mcpTools = []map[string]any{ }, { "name": "child_notices", - "description": "Turn child-turn notices on or off for an orchestrator (as ccs hook child-notices on|off). With ccs's Stop hook installed (ccs hook install), each time a session you launched or adopted finishes a turn you get an automatic notice from \"ccs hook\": its name, its bucket now (waiting_on_user, waiting_on_external, done or idle), its last message cut to 300 characters and its open PRs, and a child_turn line goes to pr-events.jsonl. Turns started only by an automatic ccs notice, turns that ended with a SendMessage to you, and a repeat in the same bucket within 30 seconds aren't told. On by default.", + "description": "Turn child-turn notices on or off for an orchestrator (as ccs hook child-notices on|off). With ccs's Stop hook installed (ccs hook install), each time a session you launched or adopted finishes a turn you get an automatic notice from \"ccs hook\": its name, its bucket now (waiting_on_user, done or idle), its last message cut to 300 characters and its open PRs, and a child_turn line goes to pr-events.jsonl. Turns started only by an automatic ccs notice, turns that sent you a SendMessage, children now waiting_on_external (CI, reviews, tasks, wake-ups), and a repeat in the same bucket within 30 seconds aren't told. On by default.", "inputSchema": map[string]any{ "type": "object", "properties": map[string]any{