Skip to content

Add TODOS checklist and DELEGATE context-isolated subtask features#104

Merged
BillJr99 merged 1 commit into
masterfrom
claude/fervent-newton-yapx2q
Jul 6, 2026
Merged

Add TODOS checklist and DELEGATE context-isolated subtask features#104
BillJr99 merged 1 commit into
masterfrom
claude/fervent-newton-yapx2q

Conversation

@BillJr99

@BillJr99 BillJr99 commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

This PR introduces two new agent coordination primitives to the CLK orchestration framework:

  1. TODOS: A lightweight, mutable per-turn checklist that sits between the append-only progress log and heavyweight charter/plan. Agents maintain a short list of items (todo/doing/done) that overwrites on each emission (last-write-wins).

  2. DELEGATE: A context-isolation mechanism for bounded subtasks. An agent can hand off a self-contained task to a child agent that runs in a fresh session without access to the caller's blackboard, but may perform real work (file writes/commits). The child's distilled result returns as a single post.

Key Changes

TODOS Checklist System

  • New module clk_harness/orchestration/todos.py: Complete TODOS implementation with parsing, persistence, and rendering

    • parse_todos_blocks(): Extracts checklist items from agent responses (last complete block wins)
    • apply_todos_blocks(): Persists per-author checklists to .clk/state/todos.json (mutable, last-write-wins)
    • render_todos(): Formats checklist for prompt injection via $todos placeholder
    • Thread-safe per-author storage with metadata (timestamp, stage_id, workflow)
  • Integration points:

    • TranscriptMixin._apply_todos(): Parses and persists TODOS blocks from agent responses (skipped in meta phases)
    • PromptsMixin._collect_context(): Injects agent's current checklist into next prompt
    • runner.py: Added _todos_lock for thread-safe concurrent access
    • Template updates: Added _TODOS_PROTOCOL_BLOCK documentation to prompts
  • Tests: Comprehensive unit tests in tests/test_todos.py covering parsing, persistence, and rendering

DELEGATE Context-Isolation System

  • New parser parse_delegate_proposals() in casting/director.py: Extracts DELEGATE blocks with target, context, and task

  • Core implementation TranscriptMixin._apply_delegate():

    • Spawns context-isolated child agents with fresh session (no blackboard inheritance)
    • Enforces depth cap (max_delegate_depth, default 1) and per-turn limit (max_delegates_per_turn, default 2)
    • Guards against unknown targets, self-delegation, and cycles
    • Child's POST blocks suppressed; distilled result returned as single delegate_result post
    • Child may perform real work (ACTION blocks execute under child's name)
  • Configuration: New robustness settings in clk.config.json:

    • max_delegate_depth: Nesting limit (default 1)
    • max_delegates_per_turn: Per-turn dispatch cap (default 2)
    • delegate_result_max_chars: Result truncation cap (default 2000)
  • Tests: Integration tests in tests/test_robustness_integration.py and unit tests in tests/test_delegate_parser.py

PI Extension (TypeScript)

  • New tool clk_todos: Allows agents to update their checklist with status marks ([ ]/[~]/[x])
  • New tool clk_delegate: Dispatches bounded subtasks to context-isolated children
  • State management: setTodos() and getTodos() in state.ts for checklist persistence
  • Consensus module: runDelegate() function that constructs isolation preamble and distillation instructions
  • Tests: Unit tests for both tools and the delegate runner

Quality & Response Validation

  • response_quality.py: Added malformed TODOS block detection (balanced TODOS:/END_TODOS check)
  • Prompt templates: Added protocol documentation blocks for both TODOS and DELEGATE

Configuration & Documentation

  • Updated .env.example with new DELEGATE settings
  • Updated CONFIGURATION.md with robustness tuning guidance
  • Updated .gitignore to exclude scratch/ (context-offload working directory)

Implementation Details

https://claude.ai/code/session_01KUsgsFFA4ovessfnpsesTW

Three agent-workflow enhancements, implemented in both the Python harness
(clk_harness/) and the TypeScript pi-extension for parity.

1. TODOS checklist — a mutable per-turn checklist ([ ]/[~]/[x]) the agent
   re-emits each turn, filling the gap between append-only PROGRESS.md and
   the heavyweight charter/plan. Mirrors the POST: pipeline but with
   last-write-wins storage (.clk/state/todos.json, keyed by author).
   - Python: new orchestration/todos.py; _apply_todos hook in transcript.py
     wired into _dispatch_once; $todos injected per-author in prompts.py;
     _TODOS_PROTOCOL_BLOCK in _BASE_FOOTER; malformed_todos quality check.
   - pi: TodoItem type, setTodos (state.ts), clk_todos tool, primer note.

2. Context-offload discipline — a scratch/ convention plus guidance to park
   big blobs in files and read back only slices (grep/head/sed). No sandbox
   change needed; scratch/ is git-ignored so the per-run `git add -A`
   auto-commit can't sweep it in.
   - Python: prose in _BASE_FOOTER; scratch/ in .gitignore.
   - pi: prose in the operator manual; scratch/ in HARDENED_GITIGNORE and
     the extension .gitignore.

3. DELEGATE sub-agent — a context-isolated child that does a bounded
   subtask and returns a distilled result. Isolation withholds the caller's
   blackboard; the child's own posts are suppressed; it may do real work
   (commit files) and its result returns as one delegate_result post.
   Depth-capped (default 1) with cycle/self/unknown-target guards.
   - Python: DelegateProposal + parse_delegate_proposals (director.py);
     "delegate" in _META_PHASES; isolation branch in _collect_context;
     post-suppression in _apply_posts; _apply_delegate hook; max_delegate_depth
     config with .env.example/kickoff.py/docs parity; _DELEGATE_PROTOCOL_BLOCK.
   - pi: runDelegate (consensus.ts) + clk_delegate tool built on spawnSubagent
     (already context-isolated); quick-reference entry.

Tests: new tests/test_todos.py, tests/test_delegate_parser.py, TODOS+DELEGATE
integration tests, malformed_todos and scratch/ cases; pi tests/todos.test.ts,
tests/delegate.test.ts, extended prompts.test.ts. pi test:strict green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KUsgsFFA4ovessfnpsesTW
@BillJr99 BillJr99 merged commit 3b70442 into master Jul 6, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants