Skip to main content

Module parse

Module parse 

Source
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§

JsonlMeta 🔒
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 to MAX_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_dir when 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, or UNIX_EPOCH if it can’t be read (a vanished/permission-denied file sorts oldest — excluded first by scan_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 by watch_agent when the target directory doesn’t exist yet — notify::Watcher::watch fails 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 timestamp field, tolerant of BOTH shapes that occur in real transcripts.
parse_event_type 🔒
Parse a JSONL line into a SubagentEventType based on the type field.
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 / result records in a workflow journal from offset. 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 by subagent.GenerateName as the source text for the Haiku naming call. Deliberately bypasses the events cache/offset machinery read_jsonl_from_offset uses: naming only ever needs the first line, is called at most once per subagent (cached via display_name thereafter), and must work even for a subagent whose events haven’t been scanned into SubagentState yet.
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_tx broadcast and prune watcher’s per-block state on Event::BlockDeleted/TabDeleted/WorkspaceDeleted — the robust backstop described on SubagentWatcher::prune_block’s doc comment. Mirrors crates/cef/src/srv_ipc.rs’s cascaded-block-id extraction (same three-arm match, same rationale: TabDeleted/ WorkspaceDeleted never emit a per-block event of their own — see reducer/tab.rs::handle_delete_tab’s doc comment — so block_ids is the only signal for a block that cascaded out via its tab/workspace) and server/mux_obj_bridge.rs::run_mux_obj_bridge’s subscribe-loop plumbing (lag/close handling).
truncate_chars 🔒
Cut to max CHARS (never mid-codepoint), appending an ellipsis when it actually cut something.