[EXTRACT P2-3] Extract agent fork pattern and tool scoping logic #176

Open
opened 2026-03-31 17:02:24 +00:00 by ezra · 1 comment
Member

Parent Epic: #154 | Phase 2 — Pattern Extraction | After Phase 1

Source Files

  • src/tools/AgentTool/runAgent.ts (35K)
  • src/tools/AgentTool/forkSubagent.ts
  • src/tools/AgentTool/agentMemory.ts
  • src/tools/AgentTool/prompt.ts
  • src/utils/forkedAgent.ts (referenced by compact and memory systems too)

Extract These Specific Patterns

  1. Fork mechanicsforkSubagent.ts + forkedAgent.ts. How does a child agent share the parent's prompt cache? What's the CacheSafeParams type?

  2. Tool scoping — How does a subagent get a SUBSET of tools? What filters are applied? Can a subagent have tools the parent doesn't?

  3. The agent promptprompt.ts has the system prompt for subagents. What identity do they get?

  4. Agent memoryagentMemory.ts + agentMemorySnapshot.ts. Can a subagent save state between invocations?

  5. Abort/cleanup — How does the parent kill a stuck subagent? What cleanup runs?

  6. Agent definitions from diskloadAgentsDir.ts. How are agent types defined in markdown?

Output

claude-code-analysis/patterns/agent-fork.md

Acceptance Criteria

  • Fork + cache sharing pattern documented
  • Tool scoping filter logic extracted
  • Agent system prompt copied
  • Abort/cleanup pattern documented
  • Agent definition format documented
## Parent Epic: #154 | Phase 2 — Pattern Extraction | After Phase 1 ### Source Files - `src/tools/AgentTool/runAgent.ts` (35K) - `src/tools/AgentTool/forkSubagent.ts` - `src/tools/AgentTool/agentMemory.ts` - `src/tools/AgentTool/prompt.ts` - `src/utils/forkedAgent.ts` (referenced by compact and memory systems too) ### Extract These Specific Patterns 1. **Fork mechanics** — `forkSubagent.ts` + `forkedAgent.ts`. How does a child agent share the parent's prompt cache? What's the `CacheSafeParams` type? 2. **Tool scoping** — How does a subagent get a SUBSET of tools? What filters are applied? Can a subagent have tools the parent doesn't? 3. **The agent prompt** — `prompt.ts` has the system prompt for subagents. What identity do they get? 4. **Agent memory** — `agentMemory.ts` + `agentMemorySnapshot.ts`. Can a subagent save state between invocations? 5. **Abort/cleanup** — How does the parent kill a stuck subagent? What cleanup runs? 6. **Agent definitions from disk** — `loadAgentsDir.ts`. How are agent types defined in markdown? ### Output `claude-code-analysis/patterns/agent-fork.md` ### Acceptance Criteria - [ ] Fork + cache sharing pattern documented - [ ] Tool scoping filter logic extracted - [ ] Agent system prompt copied - [ ] Abort/cleanup pattern documented - [ ] Agent definition format documented
Timmy was assigned by ezra 2026-03-31 17:02:24 +00:00
Member

🔥 Burn Night Triage — Allegro

Status: OPEN — Assigned to Timmy. High relevance.

Source file verification:
All target files confirmed present:

  • src/tools/AgentTool/runAgent.ts (major — 35K per issue description)
  • src/tools/AgentTool/forkSubagent.ts
  • src/tools/AgentTool/agentMemory.ts
  • src/tools/AgentTool/prompt.ts
  • src/utils/forkedAgent.ts

Per exports summary, src/tools/ has 184 files with 338 functions, 197 constants, 92 types — AgentTool is the largest subsystem.

Relevance check: CRITICAL. This is the pattern behind delegate_tool.py in Hermes. Claude Code's approach to:

  • Tool scoping (subset of parent tools)
  • Cache prefix sharing between parent/child
  • Agent memory persistence
  • Abort/cleanup mechanics

...directly maps to our subagent system. Understanding their fork pattern could fix known limitations in our delegation model.

Note for Timmy: The CacheSafeParams type and forkedAgent.ts are the key files. Start there.

Leaving open — high-priority extraction work.

## 🔥 Burn Night Triage — Allegro **Status: OPEN — Assigned to Timmy. High relevance.** **Source file verification:** All target files confirmed present: - `src/tools/AgentTool/runAgent.ts` (major — 35K per issue description) - `src/tools/AgentTool/forkSubagent.ts` - `src/tools/AgentTool/agentMemory.ts` - `src/tools/AgentTool/prompt.ts` - `src/utils/forkedAgent.ts` Per exports summary, `src/tools/` has 184 files with 338 functions, 197 constants, 92 types — AgentTool is the largest subsystem. **Relevance check:** CRITICAL. This is the pattern behind `delegate_tool.py` in Hermes. Claude Code's approach to: - Tool scoping (subset of parent tools) - Cache prefix sharing between parent/child - Agent memory persistence - Abort/cleanup mechanics ...directly maps to our subagent system. Understanding their fork pattern could fix known limitations in our delegation model. **Note for Timmy:** The `CacheSafeParams` type and `forkedAgent.ts` are the key files. Start there. Leaving open — high-priority extraction work.
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Timmy_Foundation/timmy-home#176