@matt82198/aesop 0.1.0-beta.3 → 0.1.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -94
- package/CLAUDE-TEMPLATE.md +115 -0
- package/README.md +89 -264
- package/aesop.config.example.json +27 -26
- package/bin/CLAUDE.md +39 -0
- package/bin/cli.js +368 -24
- package/daemons/CLAUDE.md +33 -0
- package/daemons/backup-fleet.sh +92 -21
- package/daemons/run-watchdog.sh +90 -10
- package/dash/CLAUDE.md +32 -0
- package/dash/dash-extra.mjs +194 -21
- package/dash/watchdog-gui.sh +23 -6
- package/docs/BEHAVIORAL-PR-REVIEW.md +86 -0
- package/docs/CHECKPOINTING.md +100 -0
- package/docs/DISPATCH-MODEL.md +11 -7
- package/docs/FORENSICS.md +204 -0
- package/docs/GOVERNANCE.md +4 -2
- package/docs/HOOK-INSTALL.md +307 -0
- package/docs/HOW-THE-LOOP-WORKS.md +175 -0
- package/docs/MEMORY-TEMPLATE.md +61 -0
- package/docs/README.md +44 -0
- package/docs/RELIABILITY.md +61 -0
- package/docs/RESTORE.md +397 -0
- package/docs/SCRIPTS-POLICY.md +97 -0
- package/docs/spikes/tiered-cognition/ACTIVATION.md +125 -0
- package/docs/spikes/tiered-cognition/DESIGN.md +287 -0
- package/docs/spikes/tiered-cognition/FINDINGS.md +113 -0
- package/docs/spikes/tiered-cognition/README.md +29 -0
- package/docs/spikes/tiered-cognition/aesop-cognition.example.md +32 -0
- package/docs/spikes/tiered-cognition/force-model-policy.merged.mjs +673 -0
- package/docs/spikes/tiered-cognition/strip-tools-hook.mjs +434 -0
- package/hooks/CLAUDE.md +38 -0
- package/hooks/claude/force-model-policy.mjs +159 -0
- package/hooks/pre-push-policy.sh +753 -0
- package/monitor/.signal-state.json +3 -0
- package/monitor/ACTIONS.log +1 -0
- package/monitor/BRIEF.md +24 -0
- package/monitor/CHARTER.md +29 -8
- package/monitor/CLAUDE.md +40 -0
- package/monitor/SIGNALS.json +54 -0
- package/monitor/collect-signals.mjs +529 -62
- package/package.json +12 -3
- package/skills/CLAUDE.md +3 -0
- package/skills/power/SKILL.md +161 -0
- package/tools/CLAUDE.md +191 -0
- package/tools/__pycache__/buildlog.cpython-314.pyc +0 -0
- package/tools/__pycache__/ci_merge_wait.cpython-314.pyc +0 -0
- package/tools/__pycache__/ensure_state.cpython-314.pyc +0 -0
- package/tools/__pycache__/eod_sweep.cpython-314.pyc +0 -0
- package/tools/__pycache__/fleet_ledger.cpython-314.pyc +0 -0
- package/tools/__pycache__/heartbeat.cpython-314.pyc +0 -0
- package/tools/__pycache__/inbox_drain.cpython-314.pyc +0 -0
- package/tools/__pycache__/launch_tui.cpython-314.pyc +0 -0
- package/tools/__pycache__/orchestrator_status.cpython-314.pyc +0 -0
- package/tools/__pycache__/power_selftest.cpython-314.pyc +0 -0
- package/tools/__pycache__/prepublish_scan.cpython-314.pyc +0 -0
- package/tools/__pycache__/rotate_logs.cpython-314.pyc +0 -0
- package/tools/__pycache__/scanner_selftest.cpython-314.pyc +0 -0
- package/tools/__pycache__/secret_scan.cpython-314.pyc +0 -0
- package/tools/__pycache__/stall_check.cpython-314.pyc +0 -0
- package/tools/__pycache__/verify_dash.cpython-314.pyc +0 -0
- package/tools/__pycache__/verify_submit_encoding.cpython-314.pyc +0 -0
- package/tools/agent-forensics.sh +186 -0
- package/tools/buildlog.py +182 -0
- package/tools/ci_merge_wait.py +204 -0
- package/tools/ensure_state.py +94 -0
- package/tools/eod_sweep.py +239 -0
- package/tools/fleet_ledger.py +272 -0
- package/tools/heartbeat.py +131 -0
- package/tools/inbox_drain.py +249 -0
- package/tools/launch_tui.py +51 -3
- package/tools/lock.mjs +211 -0
- package/tools/metrics_gate.py +205 -0
- package/tools/orchestrator_status.py +99 -0
- package/tools/power_selftest.py +386 -0
- package/tools/prepublish_scan.py +84 -0
- package/tools/proposals.mjs +248 -0
- package/tools/reconstitute.sh +467 -0
- package/tools/rotate_logs.py +228 -0
- package/tools/scanner_selftest.py +303 -0
- package/tools/secret_scan.py +131 -31
- package/tools/stall_check.py +172 -0
- package/tools/verify_dash.py +694 -0
- package/tools/verify_submit_encoding.py +194 -0
- package/ui/CLAUDE.md +109 -0
- package/ui/__pycache__/agents.cpython-314.pyc +0 -0
- package/ui/__pycache__/collectors.cpython-314.pyc +0 -0
- package/ui/__pycache__/config.cpython-314.pyc +0 -0
- package/ui/__pycache__/csrf.cpython-314.pyc +0 -0
- package/ui/__pycache__/handler.cpython-314.pyc +0 -0
- package/ui/__pycache__/render.cpython-314.pyc +0 -0
- package/ui/__pycache__/serve.cpython-314.pyc +0 -0
- package/ui/__pycache__/sse.cpython-314.pyc +0 -0
- package/ui/agents.py +179 -0
- package/ui/api/__init__.py +84 -0
- package/ui/api/__pycache__/__init__.cpython-314.pyc +0 -0
- package/ui/api/__pycache__/submit.cpython-314.pyc +0 -0
- package/ui/api/__pycache__/tracker.cpython-314.pyc +0 -0
- package/ui/api/submit.py +58 -0
- package/ui/api/tracker.py +116 -0
- package/ui/collectors.py +586 -0
- package/ui/config.py +114 -0
- package/ui/csrf.py +140 -0
- package/ui/handler.py +426 -0
- package/ui/render.py +29 -0
- package/ui/serve.py +68 -796
- package/ui/sse.py +168 -0
- package/ui/templates/dashboard.html +1202 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Durable Checkpointing & State Management
|
|
2
|
+
|
|
3
|
+
**TL;DR**: Maintain STATE.md (intent, phase, NEXT STEPS) + BUILDLOG.md (append-only progress log). On resume after context loss, read both, verify from disk, then proceed. Survives session wipes, enables rapid context handoff, and keeps orchestrator cheap (no re-reading full history).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## STATE.md: Authoritative intent & decisions
|
|
8
|
+
|
|
9
|
+
**Purpose**: Single source of truth for current intent, locked decisions, data model/contracts, key file paths, current phase, and explicit NEXT STEPS.
|
|
10
|
+
|
|
11
|
+
**Structure**:
|
|
12
|
+
- What we're trying to build (intent, not mechanism)
|
|
13
|
+
- Locked decisions (technology choices, data models, architecture trade-offs)
|
|
14
|
+
- Current phase (e.g., "Phase 2: API integration")
|
|
15
|
+
- Explicit NEXT STEPS (enumerated, actionable, owner assigned)
|
|
16
|
+
- Key paths (file locations, service boundaries, data contracts)
|
|
17
|
+
|
|
18
|
+
**Discipline**: Hand-update STATE.md at phase boundaries. Never leave it stale; always update BEFORE moving to the next phase. An out-of-date STATE.md is worse than no STATE.md (it's actively misleading).
|
|
19
|
+
|
|
20
|
+
**Recovery use case**: If context is lost or a session is interrupted, STATE.md is the first file to read. It answers "where were we?" and "what's next?" without re-reading logs or transcripts.
|
|
21
|
+
|
|
22
|
+
## BUILDLOG.md: Append-only progress snapshots
|
|
23
|
+
|
|
24
|
+
**Purpose**: Timestamped, immutable record of progress. Never overwrite or edit earlier entries (append-only discipline).
|
|
25
|
+
|
|
26
|
+
**Pattern**: Each entry contains:
|
|
27
|
+
- Timestamp (ISO 8601 or human-readable)
|
|
28
|
+
- Work completed (features, bugs, integrations, tests)
|
|
29
|
+
- Status (green / yellow / blocked / pending decision)
|
|
30
|
+
- Next step or blocker (for orchestrator reference)
|
|
31
|
+
|
|
32
|
+
**Example**:
|
|
33
|
+
```
|
|
34
|
+
[2026-07-11 13:00] Phase 1 complete: scaffolding + unit tests passing
|
|
35
|
+
[2026-07-11 14:30] API integration: 2 endpoints done, 1 blocked on schema review
|
|
36
|
+
[2026-07-11 15:45] BLOCKED: waiting for design review on request body format
|
|
37
|
+
[2026-07-11 16:20] Design approved; resume API endpoint 3 implementation
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Append-only rule**: Agents and loops append one line per work unit. The orchestrator never edits earlier entries. This prevents accidental data loss and keeps the log auditable.
|
|
41
|
+
|
|
42
|
+
## Recovery workflow: On context loss or resume
|
|
43
|
+
|
|
44
|
+
When you resume work (context wipe, new session, task restart), follow this protocol:
|
|
45
|
+
|
|
46
|
+
1. **Read STATE.md**: Understand intent, locked decisions, and current phase
|
|
47
|
+
2. **Skim BUILDLOG.md**: Review recent progress and current blockers
|
|
48
|
+
3. **Run git log**: Verify actual file state and recent commits vs. STATE.md
|
|
49
|
+
4. **Sync**: If STATE.md is stale, update it before proceeding; if reality diverged from STATE.md, note the delta and surface it
|
|
50
|
+
|
|
51
|
+
**Never invent state.** Verify everything from disk (git log, file timestamps, handoff files) before trusting in-memory recollection. Disk is the source of truth.
|
|
52
|
+
|
|
53
|
+
## Dated archive strategy: Log rotation
|
|
54
|
+
|
|
55
|
+
When BUILDLOG.md grows beyond **~200 lines or ~20 KB**:
|
|
56
|
+
|
|
57
|
+
1. Identify the cut point (e.g., last entry from yesterday or the last "green" state marker)
|
|
58
|
+
2. Move older entries to `BUILDLOG-YYYY-MM.md` (dated archive)
|
|
59
|
+
3. Keep only recent entries in the live `BUILDLOG.md`
|
|
60
|
+
4. Commit both files
|
|
61
|
+
5. Update any orchestrator references to point to the live file
|
|
62
|
+
|
|
63
|
+
**Why rotation?** The orchestrator reads the live BUILDLOG.md frequently; a 50-line log is faster and cheaper than 500 lines. Full history remains available in archives for auditing and debugging.
|
|
64
|
+
|
|
65
|
+
**Example**:
|
|
66
|
+
- Live file: `BUILDLOG.md` (entries from 2026-07-08 onward)
|
|
67
|
+
- Archive: `BUILDLOG-2026-07.md` (entries through 2026-07-07)
|
|
68
|
+
|
|
69
|
+
## Handoff metadata across team boundaries
|
|
70
|
+
|
|
71
|
+
When handing off work to another team member or agent:
|
|
72
|
+
|
|
73
|
+
- Include the git commit hash (anchors history)
|
|
74
|
+
- Snapshot key file paths and their state
|
|
75
|
+
- Document any external dependencies or waiting states
|
|
76
|
+
- List any environment assumptions (database schema versions, external service versions, etc.)
|
|
77
|
+
|
|
78
|
+
Example:
|
|
79
|
+
```
|
|
80
|
+
[2026-07-12 09:00] Handing off to feature-team: commit abc1234
|
|
81
|
+
- Database schema: v3.2 (see db/migrations/)
|
|
82
|
+
- API contracts frozen in openapi.yaml
|
|
83
|
+
- Waiting for design review on component layout
|
|
84
|
+
- Next: implement sign-up form based on design feedback
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Multi-session coordination
|
|
88
|
+
|
|
89
|
+
For work spanning multiple people or sessions:
|
|
90
|
+
|
|
91
|
+
1. **Orchestrator updates STATE.md** after each major decision or phase change
|
|
92
|
+
2. **Subagents append to BUILDLOG.md** after each work unit
|
|
93
|
+
3. **On session resume**, orchestrator syncs from disk and briefs the incoming worker
|
|
94
|
+
4. **Hand-updates to STATE.md** happen only at phase boundaries (not every commit)
|
|
95
|
+
|
|
96
|
+
This keeps overhead low (one STATE.md update per phase, one BUILDLOG line per work unit) while preserving a clear audit trail.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
**Why STATE.md + BUILDLOG.md?** They ensure work survives context loss, enables rapid resume without re-reading history, and provides an audit trail for debugging. Together with git history and the heartbeat protocol, they form the **checkpointing core** that makes orchestration systems reliable and recoverable.
|
package/docs/DISPATCH-MODEL.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Aesop Dispatch Model — Cost & Orchestration Patterns
|
|
2
2
|
|
|
3
|
+
**TL;DR**: Spawn 5–8 cheap Haiku subagents in parallel (not serial Opus). Result: **lower cost (Haiku ~1/3 Sonnet) plus a parallel speedup** via parallelism. Rule: subagents ALWAYS Haiku unless scoped work genuinely exceeds its capability (rare).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
3
7
|
## The fable conceit
|
|
4
8
|
|
|
5
9
|
In Aesop's Fables, Aesop (the narrator) directs the characters (tortoise, hare, fox, etc.) through moral tales. Here, **Aesop (the orchestrator)** directs a fleet of **Fables (the subagents)** toward reliable task completion.
|
|
@@ -21,7 +25,7 @@ The tortoise represents deliberate, resourceful thinking; the hare, quick speed.
|
|
|
21
25
|
1 orchestrator (Opus, 5 min thinking) = 5 × 60 = 300 tokens
|
|
22
26
|
5 subagents (Haiku, 2 min each) = 5 × 2 × 20 = 200 tokens
|
|
23
27
|
Total = 500 tokens/session
|
|
24
|
-
=
|
|
28
|
+
= a large saving vs all-Opus (Haiku is 1/5 the per-token cost of Opus)
|
|
25
29
|
```
|
|
26
30
|
|
|
27
31
|
### Scaling to 10 parallel domains
|
|
@@ -30,14 +34,14 @@ Total = 500 tokens/session
|
|
|
30
34
|
1 orchestrator (Opus, 8 min) = 480 tokens
|
|
31
35
|
10 subagents (Haiku, 3 min each) = 600 tokens
|
|
32
36
|
Total = 1,080 tokens
|
|
33
|
-
=
|
|
37
|
+
= a large saving vs all-Opus (most domains run on Haiku at 1/5 Opus cost)
|
|
34
38
|
```
|
|
35
39
|
|
|
36
40
|
## MAIN RULE: Subagents are ALWAYS the cheap tier
|
|
37
41
|
|
|
38
42
|
This is **the single most important cost lever** in the entire system. Every subagent spawned must default to Haiku, never Sonnet or Opus. This rule, more than any other, multiplies your savings at scale.
|
|
39
43
|
|
|
40
|
-
**Why**: Haiku is 1/3 the cost of Sonnet with sufficient capability for scoped domain work. Scaling from 1 subagent to 6–8 in parallel multiplies the per-domain savings —
|
|
44
|
+
**Why**: Haiku is 1/3 the cost of Sonnet with sufficient capability for scoped domain work. Scaling from 1 subagent to 6–8 in parallel multiplies the per-domain savings — most of the work runs on Haiku at 1/5 the per-token cost of Opus. Violating this rule (spawning Sonnet/Opus subagents) erases the economic advantage of the entire dispatch model.
|
|
41
45
|
|
|
42
46
|
**The exception**: Only use Sonnet/Opus for a subagent if:
|
|
43
47
|
1. The task genuinely exceeds Haiku capability (rare for scoped domains), **AND**
|
|
@@ -79,7 +83,7 @@ Orchestrator → Phase 1
|
|
|
79
83
|
└─ Haiku-4: Integration test
|
|
80
84
|
|
|
81
85
|
Orchestrator reassembles + QA
|
|
82
|
-
Total cost:
|
|
86
|
+
Total cost: 1 Opus orchestrator + 4 Haiku implementers — the four implementers run at 1/5 the per-token cost of Opus
|
|
83
87
|
```
|
|
84
88
|
|
|
85
89
|
### Pattern 3: Hierarchical (supervisor + workers)
|
|
@@ -96,7 +100,7 @@ Orchestrator
|
|
|
96
100
|
│ └─ Haiku-5: config module
|
|
97
101
|
└─ (Sonnet synthesizes reviews into final report)
|
|
98
102
|
|
|
99
|
-
Cost: 1 Opus + 1 Sonnet + 5 Haiku =
|
|
103
|
+
Cost: 1 Opus + 1 Sonnet + 5 Haiku = ~1/3 the cost of running every domain on Opus
|
|
100
104
|
```
|
|
101
105
|
|
|
102
106
|
## Decision flowchart
|
|
@@ -118,7 +122,7 @@ Is this task scoped to <5 min reasoning?
|
|
|
118
122
|
|
|
119
123
|
### ❌ All-Opus fleet
|
|
120
124
|
|
|
121
|
-
**Cost**:
|
|
125
|
+
**Cost**: higher — Sonnet/Opus per-token rates. **Why**: throws CPU power at problems that are scoped.
|
|
122
126
|
|
|
123
127
|
**Fix**: Decompose into Haiku-sized tasks.
|
|
124
128
|
|
|
@@ -204,4 +208,4 @@ Surfacing to the user after 3 retries ensures visibility and prevents silent cos
|
|
|
204
208
|
|
|
205
209
|
---
|
|
206
210
|
|
|
207
|
-
**Summary**: Aesop's dispatch model trades a small amount of orchestration complexity for **
|
|
211
|
+
**Summary**: Aesop's dispatch model trades a small amount of orchestration complexity for **lower cost** (Haiku ~1/3 Sonnet) and **parallel speedup** (via parallelism). It works by keeping subagents small, orchestrator lean, and feedback constant.
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# Forensics: Making Agent Failures Git-Bisectable
|
|
2
|
+
|
|
3
|
+
## The Pillar
|
|
4
|
+
|
|
5
|
+
Agent behavior is source code. When an agent misbehaves, you can reconstruct exactly what rules, memory, and policies were active at the time of failure — then bisect the codebase to find the commit that broke it. This turns vague "the agent was weird yesterday" into a reproducible root cause.
|
|
6
|
+
|
|
7
|
+
**Key principle**: Rules (CARDINAL-RULES.md, CLAUDE.md), checkpoints (STATE.md, BUILDLOG.md), and policies (hooks/, monitor/CHARTER.md) are the agent's executable spec. Versioning them in git means agent failures become debuggable like code regressions.
|
|
8
|
+
|
|
9
|
+
## Tools
|
|
10
|
+
|
|
11
|
+
### `tools/agent-forensics.sh`
|
|
12
|
+
|
|
13
|
+
Read-only incident-forensics tool. Reconstructs agent behavior from git history using only git plumbing (no checkout, no working-tree mutation).
|
|
14
|
+
|
|
15
|
+
**Usage:**
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Snapshot agent behavior at a commit
|
|
19
|
+
bash tools/agent-forensics.sh <commit>
|
|
20
|
+
|
|
21
|
+
# Show what behavior changed between two commits
|
|
22
|
+
bash tools/agent-forensics.sh --diff <commitA> <commitB>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Output:**
|
|
26
|
+
- Commit header (hash, date, subject)
|
|
27
|
+
- First ~40 lines of rules (docs/CARDINAL-RULES.md)
|
|
28
|
+
- CLAUDE.md snapshot (if present)
|
|
29
|
+
- STATE.md snapshot (if present)
|
|
30
|
+
- Last 30 lines of BUILDLOG.md (if tracked)
|
|
31
|
+
- For `--diff`: side-by-side changes in CLAUDE.md, STATE.md, docs/, hooks/, monitor/CHARTER.md
|
|
32
|
+
|
|
33
|
+
**Exit codes:**
|
|
34
|
+
- `0` on success
|
|
35
|
+
- `1` on error (unknown commit, I/O failure); clean error message printed to stderr, never raw stack traces
|
|
36
|
+
|
|
37
|
+
**Examples:**
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Forensics at HEAD
|
|
41
|
+
bash tools/agent-forensics.sh HEAD
|
|
42
|
+
|
|
43
|
+
# Forensics at a specific commit
|
|
44
|
+
bash tools/agent-forensics.sh 858ac08
|
|
45
|
+
|
|
46
|
+
# What changed in behavior between two releases?
|
|
47
|
+
bash tools/agent-forensics.sh --diff v0.1.0-beta.2 v0.1.0-beta.3
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Recipe: Bisect an Agent Regression
|
|
51
|
+
|
|
52
|
+
When an agent's behavior regressed (e.g., "rules started being ignored on July 10"):
|
|
53
|
+
|
|
54
|
+
1. **Identify the failure time window.** (e.g., "agent started proposing without filtering on 2026-07-10 18:00 UTC")
|
|
55
|
+
|
|
56
|
+
2. **Run forensics at the last known-good commit** and the first known-bad commit:
|
|
57
|
+
```bash
|
|
58
|
+
bash tools/agent-forensics.sh <good-commit>
|
|
59
|
+
bash tools/agent-forensics.sh <bad-commit>
|
|
60
|
+
```
|
|
61
|
+
Compare the output manually. Often you'll spot the culprit immediately (e.g., a rule was deleted, CLAUDE.md lost a policy).
|
|
62
|
+
|
|
63
|
+
3. **If manual inspection doesn't find it, bisect:**
|
|
64
|
+
```bash
|
|
65
|
+
git bisect start
|
|
66
|
+
git bisect bad <bad-commit>
|
|
67
|
+
git bisect good <good-commit>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
4. **Write a behavior predicate** (a test that reproduces the failure):
|
|
71
|
+
```bash
|
|
72
|
+
# Example: check that docs/CARDINAL-RULES.md mentions "Haiku" at this commit
|
|
73
|
+
git bisect run bash -c '
|
|
74
|
+
git show HEAD:docs/CARDINAL-RULES.md | grep -q "Haiku" && exit 0 || exit 1
|
|
75
|
+
'
|
|
76
|
+
```
|
|
77
|
+
Bisect will pin-point the exact commit that broke the behavior.
|
|
78
|
+
|
|
79
|
+
5. **Review the offending commit** using `--diff`:
|
|
80
|
+
```bash
|
|
81
|
+
bash tools/agent-forensics.sh --diff <parent-of-bad> <bad-commit>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
6. **Fix the issue** (restore the rule, reinstate the policy, etc.) in a new commit on a feature branch.
|
|
85
|
+
|
|
86
|
+
## What to Check When an Incident Happens
|
|
87
|
+
|
|
88
|
+
### Incident Discovery
|
|
89
|
+
1. Capture the **current behavior** (what went wrong, when, which agent):
|
|
90
|
+
- Run `bash tools/agent-forensics.sh HEAD` to see rules + state at time of report.
|
|
91
|
+
- Check logs in `state/FLEET-BACKUP.log`, `state/ACTIONS.log`, or agent transcript.
|
|
92
|
+
- Note the **exact timestamp** of the first wrong behavior.
|
|
93
|
+
|
|
94
|
+
2. **Cross-reference the timestamp** with `git log --since="<time>"` to find commits near that time.
|
|
95
|
+
|
|
96
|
+
### Root Cause Narrowing
|
|
97
|
+
3. **Did a rule change?**
|
|
98
|
+
```bash
|
|
99
|
+
git log -p --since="<before-incident>" -- docs/CARDINAL-RULES.md CLAUDE.md | head -100
|
|
100
|
+
```
|
|
101
|
+
Look for deletions, edits to retry logic, dispatch budgets, or policy changes.
|
|
102
|
+
|
|
103
|
+
4. **Did state get corrupted?**
|
|
104
|
+
```bash
|
|
105
|
+
bash tools/agent-forensics.sh <commit-before-incident>
|
|
106
|
+
bash tools/agent-forensics.sh <commit-at-incident>
|
|
107
|
+
# Compare STATE.md and BUILDLOG.md for anomalies (e.g., PHASE stuck, cost spike)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
5. **Did a hook fail silently?**
|
|
111
|
+
```bash
|
|
112
|
+
git log -p --since="<before-incident>" -- hooks/ monitor/CHARTER.md
|
|
113
|
+
cat state/SECURITY-AUDIT.log | tail -50
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Confirmation via Bisect
|
|
117
|
+
6. Once you have a suspect commit or time range, use the bisect recipe above to narrow it down.
|
|
118
|
+
|
|
119
|
+
7. **Write the fix** in a feature branch. Update CLAUDE.md if the rule itself was wrong; add an explanatory comment referencing the incident date.
|
|
120
|
+
|
|
121
|
+
8. **Add a regression test:** if the incident was "agent ignored retry cap," add a check in pre-push-policy.sh or a future test-harness to catch that rule drifting again.
|
|
122
|
+
|
|
123
|
+
## Durable Artifacts to Check
|
|
124
|
+
|
|
125
|
+
| File | Purpose | Checked via |
|
|
126
|
+
|------|---------|-------------|
|
|
127
|
+
| **docs/CARDINAL-RULES.md** | Dispatch, cost, retry, TDD policy | `bash tools/agent-forensics.sh <commit>` |
|
|
128
|
+
| **CLAUDE.md** | Project-level rules, branch discipline, commit gates | manual forensics; git log |
|
|
129
|
+
| **STATE.md** | Current phase, locked decisions, next steps | forensics snapshot |
|
|
130
|
+
| **BUILDLOG.md** | Append-only cycle log (cost, actions, phase changes) | forensics (last 5 entries) |
|
|
131
|
+
| **hooks/** | Pre-push policy, secret-scan gate, lint checks | git show or forensics --diff |
|
|
132
|
+
| **monitor/CHARTER.md** | Orchestration monitor config (AUTO/PROPOSE thresholds) | forensics --diff |
|
|
133
|
+
|
|
134
|
+
## Example: Debugging a Cost Spike
|
|
135
|
+
|
|
136
|
+
**Symptom**: Agent token spend jumped from 50k to 200k tokens on 2026-07-10.
|
|
137
|
+
|
|
138
|
+
1. Run forensics at the spike time:
|
|
139
|
+
```bash
|
|
140
|
+
bash tools/agent-forensics.sh <commit-on-2026-07-10>
|
|
141
|
+
```
|
|
142
|
+
Check STATE.md and BUILDLOG.md. Look for:
|
|
143
|
+
- Did `parallelism` increase? (more agents spawned → more tokens)
|
|
144
|
+
- Did `retries` increase? (retry cap lowered → more respawns)
|
|
145
|
+
- Did `model` change to Opus? (rule 1 violation)
|
|
146
|
+
|
|
147
|
+
2. Narrow the window:
|
|
148
|
+
```bash
|
|
149
|
+
git log --oneline --since="2026-07-09" --until="2026-07-11"
|
|
150
|
+
bash tools/agent-forensics.sh --diff <2026-07-09-commit> <2026-07-10-spike-commit>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
3. If a rule changed (e.g., retries bumped from 3 to 6), fix it:
|
|
154
|
+
```bash
|
|
155
|
+
git log -p --since="2026-07-09" -- docs/CARDINAL-RULES.md | grep -A5 -B5 retries
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
4. Restore or correct the rule, commit, and monitor spend in the next cycle.
|
|
159
|
+
|
|
160
|
+
## Integration with the Refinement Loop
|
|
161
|
+
|
|
162
|
+
Forensic replay strengthens the orchestration refinement cycle by enabling rapid root-cause analysis when the fleet exhibits unexpected behavior changes.
|
|
163
|
+
|
|
164
|
+
**When to invoke forensics in refinement:**
|
|
165
|
+
|
|
166
|
+
1. **Suspected behavior regression** — If PROPOSALS.md or monitoring signals suggest rules changed unexpectedly:
|
|
167
|
+
```bash
|
|
168
|
+
# Find the suspect commit range
|
|
169
|
+
git log --oneline --all | head -20
|
|
170
|
+
|
|
171
|
+
# Compare behavior-controlling files between two commits
|
|
172
|
+
bash tools/agent-forensics.sh --diff <last-known-good> <suspect-bad>
|
|
173
|
+
```
|
|
174
|
+
This immediately shows what changed in CLAUDE.md, STATE.md, docs/, hooks/, and monitor/CHARTER.md.
|
|
175
|
+
|
|
176
|
+
2. **Cost or performance spike** — If SIGNALS.json reports elevated token spend or cost anomalies:
|
|
177
|
+
```bash
|
|
178
|
+
# Snapshot state at the anomaly time
|
|
179
|
+
bash tools/agent-forensics.sh <commit-at-spike-time>
|
|
180
|
+
```
|
|
181
|
+
Check the BUILDLOG.md excerpt for cost-related entries, parallelism changes, or dispatch budget adjustments.
|
|
182
|
+
|
|
183
|
+
3. **After merging a PR** — Before rolling to production, verify no unintended behavior changes were introduced:
|
|
184
|
+
```bash
|
|
185
|
+
# Compare main...feature-branch
|
|
186
|
+
bash tools/agent-forensics.sh --diff main <feature-branch-head>
|
|
187
|
+
```
|
|
188
|
+
If behavior-controlling files show unexpected changes, halt the merge and investigate.
|
|
189
|
+
|
|
190
|
+
**Output interpretation:**
|
|
191
|
+
|
|
192
|
+
- **CLAUDE.md or STATE.md changed** → review what rules or phase-state was altered
|
|
193
|
+
- **docs/CARDINAL-RULES.md modified** → check if dispatch budgets, retry caps, or cost levers were adjusted
|
|
194
|
+
- **hooks/ or monitor/CHARTER.md changed** → verify policy enforcement or signal thresholds are intentional
|
|
195
|
+
- **No changes in behavior-controlling files** → regression is likely in agent logic (non-behavior files) or external state
|
|
196
|
+
|
|
197
|
+
**Integration point:** The monitor/collect-signals.mjs can emit a PROPOSAL when it detects rule drift or state anomalies, prompting operators to run forensics on the linked commits to verify the change was intentional.
|
|
198
|
+
|
|
199
|
+
## See Also
|
|
200
|
+
|
|
201
|
+
- **docs/CARDINAL-RULES.md** — The executable spec for agent behavior.
|
|
202
|
+
- **docs/DISPATCH-MODEL.md** — Cost levers, parallelism, watchdog stall detection.
|
|
203
|
+
- **docs/GOVERNANCE.md** — Memory/state single-writer guarantees, proposal flow.
|
|
204
|
+
- **README.md** — Quick start; includes examples of running forensics on a live incident.
|
package/docs/GOVERNANCE.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Governance & Control
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**TL;DR**: Keep the system coherent: one instance of each loop (heartbeat protocol), single writer per control file (MEMORY.md, STATE.md), append-only logs, secret-scan gate on every push, feature branches only (never direct-to-main). Prevents races, data loss, credential leaks, and makes work auditable.
|
|
4
|
+
|
|
5
|
+
---
|
|
4
6
|
|
|
5
7
|
## Single-instance loops
|
|
6
8
|
|
|
@@ -41,7 +43,7 @@ Some files must have exactly one writer to prevent race conditions and data loss
|
|
|
41
43
|
|
|
42
44
|
## Inbox pattern for coordination
|
|
43
45
|
|
|
44
|
-
Loops that need to request memory updates or signal decisions use an append-only inbox. The orchestrator reviews inbox entries on every `/power` cycle.
|
|
46
|
+
Loops that need to request memory updates or signal decisions use an append-only inbox. The orchestrator reviews inbox entries on every `/power` cycle. See [skills/power/SKILL.md](../skills/power/SKILL.md) for orchestrator priming details.
|
|
45
47
|
|
|
46
48
|
### Inbox format
|
|
47
49
|
|