Expand description
Free-standing parsing/path utilities used by the rest of subagent_watcher
— none of these need &self. Covers: JSONL line parsing, journal-count
reading, workflow/session id derivation from a path, the block-delete
cascade subscriber, and Claude config dir resolution.
Structs§
- Jsonl
Meta 🔒 - Metadata extracted from the first JSONL line (the subagent init record).
Constants§
- MAX_
INPUT_ 🔒FIELD_ CHARS - Chars kept per top-level field of a tool call’s input. Every subagent call measured fits whole; an Edit’s file contents or an Agent prompt does not, and only needs to show its start.
- MAX_
RESULT_ 🔒PREVIEW_ CHARS - Chars of a tool result kept for the same feed. Larger than the input budget because a result is the thing a reader is usually scanning.
Functions§
- bounded_
tool_ 🔒input - A tool call’s
input, kept structured but bounded: each top-level string is cut toMAX_INPUT_FIELD_CHARS, and a nested array/object whose JSON is longer becomes that JSON, cut the same way. - derive_
claude_ config_ dir - Derive the Claude Code config directory for a host agent. Only matches
reality for an agent with an explicit per-account auth dir —
prefer
resolve_claude_config_dirwhen the block’s meta is available. - derive_
session_ 🔒id - Session id = the name of the directory containing
subagents/. Workflow member files are nested (subagents/workflows/<wf>/agent-*.jsonl), so walk ancestors instead of assuming a fixed depth. - file_
mtime 🔒 - Modification time of
path, orUNIX_EPOCHif it can’t be read (a vanished/permission-denied file sorts oldest — excluded first byscan_subagents_dir’s recency cap rather than crashing the scan). - nearest_
existing_ 🔒ancestor - Walk up
path’s ancestors (parent, grandparent, …) and return the first one that already exists on disk. Used bywatch_agentwhen the target directory doesn’t exist yet —notify::Watcher::watchfails outright on a nonexistent path, so this finds the closest directory that can actually be watched right now (a later-created descendant is still picked up, since the watch is recursive). - now_
millis 🔒 - Milliseconds since the Unix epoch, as
u64. - parse_
event_ 🔒timestamp - Epoch-millis for a subagent JSONL line’s
timestampfield, tolerant of BOTH shapes that occur in real transcripts. - parse_
event_ 🔒type - Parse a JSONL line into a SubagentEventType based on the
typefield. - parse_
workflow_ 🔒id - Extract the workflow id from a path under
.../subagents/workflows/<id>/.... Returns None for direct (non-workflow) subagent files. - read_
journal_ 🔒counts - Count new
started/resultrecords in a workflow journal fromoffset. Returns (started, results, new_offset). - read_
jsonl_ 🔒from_ offset - Read a JSONL file from a byte offset, parsing new subagent events. Returns (events, new_offset, optional_meta).
- read_
task_ 🔒prompt - Read just the subagent’s own initial task prompt from the first JSONL
line (a
"type":"user"init record) — used bysubagent.GenerateNameas the source text for the Haiku naming call. Deliberately bypasses the events cache/offset machineryread_jsonl_from_offsetuses: naming only ever needs the first line, is called at most once per subagent (cached viadisplay_namethereafter), and must work even for a subagent whose events haven’t been scanned intoSubagentStateyet. - resolve_
claude_ config_ dir - The authoritative Claude Code config directory for a block.
- result_
content_ 🔒text - A tool result’s text. A plain string is used as-is; anything else (the
common
[{"type":"text","text":…}]block array, or a bare object) falls back to compact JSON, same as before. - spawn_
block_ prune_ subscriber - Subscribe to the reducer’s
srv_events_txbroadcast and prunewatcher’s per-block state onEvent::BlockDeleted/TabDeleted/WorkspaceDeleted— the robust backstop described onSubagentWatcher::prune_block’s doc comment. Mirrorscrates/cef/src/srv_ipc.rs’s cascaded-block-id extraction (same three-arm match, same rationale:TabDeleted/WorkspaceDeletednever emit a per-block event of their own — seereducer/tab.rs::handle_delete_tab’s doc comment — soblock_idsis the only signal for a block that cascaded out via its tab/workspace) andserver/mux_obj_bridge.rs::run_mux_obj_bridge’s subscribe-loop plumbing (lag/close handling). - truncate_
chars 🔒 - Cut to
maxCHARS (never mid-codepoint), appending an ellipsis when it actually cut something.