opencastle 0.10.7 → 0.12.0

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.
Files changed (132) hide show
  1. package/README.md +4 -0
  2. package/bin/cli.mjs +4 -0
  3. package/dist/cli/convoy/events.d.ts +10 -0
  4. package/dist/cli/convoy/events.d.ts.map +1 -0
  5. package/dist/cli/convoy/events.js +27 -0
  6. package/dist/cli/convoy/events.js.map +1 -0
  7. package/dist/cli/convoy/events.test.d.ts +2 -0
  8. package/dist/cli/convoy/events.test.d.ts.map +1 -0
  9. package/dist/cli/convoy/events.test.js +94 -0
  10. package/dist/cli/convoy/events.test.js.map +1 -0
  11. package/dist/cli/convoy/store.d.ts +23 -0
  12. package/dist/cli/convoy/store.d.ts.map +1 -0
  13. package/dist/cli/convoy/store.js +210 -0
  14. package/dist/cli/convoy/store.js.map +1 -0
  15. package/dist/cli/convoy/store.test.d.ts +2 -0
  16. package/dist/cli/convoy/store.test.d.ts.map +1 -0
  17. package/dist/cli/convoy/store.test.js +387 -0
  18. package/dist/cli/convoy/store.test.js.map +1 -0
  19. package/dist/cli/convoy/types.d.ts +56 -0
  20. package/dist/cli/convoy/types.d.ts.map +1 -0
  21. package/dist/cli/convoy/types.js +2 -0
  22. package/dist/cli/convoy/types.js.map +1 -0
  23. package/dist/cli/dashboard.d.ts.map +1 -1
  24. package/dist/cli/dashboard.js +5 -1
  25. package/dist/cli/dashboard.js.map +1 -1
  26. package/dist/cli/init.test.js +1 -1
  27. package/dist/cli/init.test.js.map +1 -1
  28. package/dist/cli/lesson.d.ts +17 -0
  29. package/dist/cli/lesson.d.ts.map +1 -0
  30. package/dist/cli/lesson.js +294 -0
  31. package/dist/cli/lesson.js.map +1 -0
  32. package/dist/cli/log.d.ts +7 -0
  33. package/dist/cli/log.d.ts.map +1 -0
  34. package/dist/cli/log.js +131 -0
  35. package/dist/cli/log.js.map +1 -0
  36. package/dist/cli/run/executor.js.map +1 -1
  37. package/dist/cli/run/executor.test.js +1 -0
  38. package/dist/cli/run/executor.test.js.map +1 -1
  39. package/dist/cli/run/loop-executor.d.ts +3 -0
  40. package/dist/cli/run/loop-executor.d.ts.map +1 -0
  41. package/dist/cli/run/loop-executor.js +155 -0
  42. package/dist/cli/run/loop-executor.js.map +1 -0
  43. package/dist/cli/run/loop-reporter.d.ts +6 -0
  44. package/dist/cli/run/loop-reporter.d.ts.map +1 -0
  45. package/dist/cli/run/loop-reporter.js +112 -0
  46. package/dist/cli/run/loop-reporter.js.map +1 -0
  47. package/dist/cli/run/reporter.d.ts.map +1 -1
  48. package/dist/cli/run/reporter.js +28 -1
  49. package/dist/cli/run/reporter.js.map +1 -1
  50. package/dist/cli/run/schema.d.ts +4 -0
  51. package/dist/cli/run/schema.d.ts.map +1 -1
  52. package/dist/cli/run/schema.js +178 -50
  53. package/dist/cli/run/schema.js.map +1 -1
  54. package/dist/cli/run/schema.test.js +598 -1
  55. package/dist/cli/run/schema.test.js.map +1 -1
  56. package/dist/cli/run.d.ts.map +1 -1
  57. package/dist/cli/run.js +84 -3
  58. package/dist/cli/run.js.map +1 -1
  59. package/dist/cli/types.d.ts +78 -1
  60. package/dist/cli/types.d.ts.map +1 -1
  61. package/dist/cli/update.d.ts.map +1 -1
  62. package/dist/cli/update.js +54 -1
  63. package/dist/cli/update.js.map +1 -1
  64. package/package.json +3 -2
  65. package/src/cli/convoy/events.test.ts +118 -0
  66. package/src/cli/convoy/events.ts +41 -0
  67. package/src/cli/convoy/store.test.ts +446 -0
  68. package/src/cli/convoy/store.ts +308 -0
  69. package/src/cli/convoy/types.ts +68 -0
  70. package/src/cli/dashboard.ts +5 -1
  71. package/src/cli/init.test.ts +1 -1
  72. package/src/cli/lesson.ts +312 -0
  73. package/src/cli/log.ts +133 -0
  74. package/src/cli/run/executor.test.ts +1 -0
  75. package/src/cli/run/executor.ts +8 -8
  76. package/src/cli/run/loop-executor.ts +199 -0
  77. package/src/cli/run/loop-reporter.ts +125 -0
  78. package/src/cli/run/reporter.ts +30 -1
  79. package/src/cli/run/schema.test.ts +704 -3
  80. package/src/cli/run/schema.ts +206 -56
  81. package/src/cli/run.ts +82 -5
  82. package/src/cli/types.ts +87 -1
  83. package/src/cli/update.ts +62 -1
  84. package/src/dashboard/dist/index.html +14 -15
  85. package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
  86. package/src/dashboard/scripts/generate-seed-data.ts +23 -43
  87. package/src/dashboard/seed-data/events.ndjson +104 -0
  88. package/src/dashboard/src/pages/index.astro +14 -15
  89. package/src/orchestrator/agents/api-designer.agent.md +1 -1
  90. package/src/orchestrator/agents/architect.agent.md +1 -1
  91. package/src/orchestrator/agents/content-engineer.agent.md +1 -1
  92. package/src/orchestrator/agents/copywriter.agent.md +1 -1
  93. package/src/orchestrator/agents/data-expert.agent.md +1 -1
  94. package/src/orchestrator/agents/database-engineer.agent.md +1 -1
  95. package/src/orchestrator/agents/developer.agent.md +1 -1
  96. package/src/orchestrator/agents/devops-expert.agent.md +1 -1
  97. package/src/orchestrator/agents/documentation-writer.agent.md +1 -1
  98. package/src/orchestrator/agents/performance-expert.agent.md +1 -1
  99. package/src/orchestrator/agents/release-manager.agent.md +1 -1
  100. package/src/orchestrator/agents/security-expert.agent.md +1 -1
  101. package/src/orchestrator/agents/seo-specialist.agent.md +1 -1
  102. package/src/orchestrator/agents/session-guard.agent.md +9 -21
  103. package/src/orchestrator/agents/team-lead.agent.md +8 -34
  104. package/src/orchestrator/agents/testing-expert.agent.md +1 -1
  105. package/src/orchestrator/agents/ui-ux-expert.agent.md +1 -1
  106. package/src/orchestrator/customizations/AGENT-PERFORMANCE.md +11 -12
  107. package/src/orchestrator/customizations/DISPUTES.md +2 -2
  108. package/src/orchestrator/customizations/README.md +1 -3
  109. package/src/orchestrator/customizations/logs/README.md +66 -14
  110. package/src/orchestrator/instructions/ai-optimization.instructions.md +21 -132
  111. package/src/orchestrator/instructions/general.instructions.md +35 -181
  112. package/src/orchestrator/plugins/nx/SKILL.md +1 -1
  113. package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +4 -8
  114. package/src/orchestrator/prompts/bug-fix.prompt.md +4 -4
  115. package/src/orchestrator/prompts/implement-feature.prompt.md +3 -3
  116. package/src/orchestrator/prompts/quick-refinement.prompt.md +3 -3
  117. package/src/orchestrator/prompts/resolve-pr-comments.prompt.md +1 -1
  118. package/src/orchestrator/skills/agent-hooks/SKILL.md +11 -11
  119. package/src/orchestrator/skills/decomposition/SKILL.md +1 -1
  120. package/src/orchestrator/skills/fast-review/SKILL.md +4 -19
  121. package/src/orchestrator/skills/git-workflow/SKILL.md +72 -0
  122. package/src/orchestrator/skills/memory-merger/SKILL.md +1 -1
  123. package/src/orchestrator/skills/observability-logging/SKILL.md +129 -0
  124. package/src/orchestrator/skills/orchestration-protocols/SKILL.md +2 -2
  125. package/src/orchestrator/skills/panel-majority-vote/SKILL.md +4 -7
  126. package/src/orchestrator/skills/self-improvement/SKILL.md +13 -26
  127. package/src/orchestrator/skills/team-lead-reference/SKILL.md +2 -2
  128. package/src/orchestrator/customizations/logs/delegations.ndjson +0 -1
  129. package/src/orchestrator/customizations/logs/panels.ndjson +0 -1
  130. package/src/orchestrator/customizations/logs/reviews.ndjson +0 -0
  131. package/src/orchestrator/customizations/logs/sessions.ndjson +0 -1
  132. /package/src/orchestrator/customizations/logs/{disputes.ndjson → events.ndjson} +0 -0
@@ -30,27 +30,21 @@ Run ALL checks. Report each as ✅ or ❌.
30
30
 
31
31
  ### 1. Delegation Records
32
32
 
33
- For each delegation in the session summary, verify a matching record exists in `.github/customizations/logs/delegations.ndjson`.
33
+ For each delegation in the session summary, verify a matching record exists in `.github/customizations/logs/events.ndjson` (type=delegation).
34
34
 
35
- **How:** `tail -20 .github/customizations/logs/delegations.ndjson` and match agent + task against the summary.
35
+ **How:** `grep '"type":"delegation"' .github/customizations/logs/events.ndjson | tail -20` and match agent + task against the summary.
36
36
 
37
- **Fix command template:**
38
- ```bash
39
- (Fill in values from the session summary — see the Team Lead agent file for the canonical JSON schema)
40
- ```
37
+ **Fix:** Load the **observability-logging** skill and run the delegation record command (includes a verify step).
41
38
 
42
39
  Also verify each delegation record includes `session_id` (branch name). Records missing `session_id` should be flagged.
43
40
 
44
41
  ### 2. Session Record
45
42
 
46
- Verify a session record exists in `.github/customizations/logs/sessions.ndjson` for the current task.
43
+ Verify a session record exists in `.github/customizations/logs/events.ndjson` (type=session) for the current task.
47
44
 
48
- **How:** `tail -5 .github/customizations/logs/sessions.ndjson` and match task description.
45
+ **How:** `grep '"type":"session"' .github/customizations/logs/events.ndjson | tail -5` and match task description.
49
46
 
50
- **Fix command template:**
51
- ```bash
52
- echo '{"timestamp":"<ISO>","agent":"Team Lead","model":"<model>","task":"<description>","outcome":"success","duration_min":<N>,"files_changed":<N>,"retries":0,"lessons_added":[],"discoveries":[]}' >> .github/customizations/logs/sessions.ndjson
53
- ```
47
+ **Fix:** Load the **observability-logging** skill and run the session record command (includes a verify step).
54
48
 
55
49
  ### 3. Lessons Captured
56
50
 
@@ -66,17 +60,11 @@ If the session summary lists discovered issues, verify they appear in:
66
60
 
67
61
  ### 5. Review & Panel Records
68
62
 
69
- If the session summary mentions fast reviews or panel reviews, verify matching records exist in `.github/customizations/logs/reviews.ndjson` and/or `.github/customizations/logs/panels.ndjson`.
63
+ If the session summary mentions fast reviews or panel reviews, verify matching records exist in `.github/customizations/logs/events.ndjson` (type=review and/or type=panel).
70
64
 
71
- **How:** `tail -10 .github/customizations/logs/reviews.ndjson` and/or `tail -5 .github/customizations/logs/panels.ndjson`.
65
+ **How:** `grep '"type":"review"' .github/customizations/logs/events.ndjson | tail -10` and/or `grep '"type":"panel"' .github/customizations/logs/events.ndjson | tail -5`.
72
66
 
73
- **Fix command templates:**
74
- ```bash
75
- # Fast review
76
- echo '{"timestamp":"<ISO>","agent":"<reviewed-agent>","reviewer_model":"<model>","verdict":"<pass|fail>","attempt":1,"issues_critical":0,"issues_major":0,"issues_minor":0,"confidence":"high","escalated":false,"duration_sec":N}' >> .github/customizations/logs/reviews.ndjson
77
- # Panel review
78
- echo '{"timestamp":"<ISO>","panel_key":"<key>","verdict":"<pass|block>","pass_count":N,"block_count":N,"must_fix":0,"should_fix":0,"reviewer_model":"<model>","weighted":false,"attempt":1,"artifacts_count":N}' >> .github/customizations/logs/panels.ndjson
79
- ```
67
+ **Fix:** Load the **observability-logging** skill and run the review/panel record command as applicable (includes a verify step).
80
68
 
81
69
  ### 6. Uncommitted Changes
82
70
 
@@ -99,11 +99,7 @@ Synchronous — blocks until result. Use when:
99
99
 
100
100
  When calling `runSubagent`, always specify which custom agent to use by name: *"Use the **[Agent Name]** agent to [task]."* This routes the sub-agent to the named agent's model and tools instead of inheriting the Team Lead's Premium model. Include objective, file paths, acceptance criteria, and what to return in the result.
101
101
 
102
- **After each sub-agent returns**, log the delegation record before doing anything else (before review, before verification):
103
- ```bash
104
- echo '{"timestamp":"<ISO-NOW>","session_id":"<branch>","agent":"<name>","model":"<model>","tier":"<tier>","mechanism":"sub-agent","tracker_issue":"<issue-or-N/A>","outcome":"<success|partial|failed>","retries":0,"phase":<N>,"file_partition":["<paths>"]}' >> .github/customizations/logs/delegations.ndjson
105
- ```
106
- Verify: `tail -1 .github/customizations/logs/delegations.ndjson`
102
+ **After each sub-agent returns**, log the delegation record before doing anything else (before review, before verification). This is a **⛔ hard gate** — do NOT proceed to review or any other action until the delegation is logged. Use the **observability-logging** skill's delegation record command (`--mechanism sub-agent`).
107
103
 
108
104
  > **`model` and `tier` must come from the agent registry** — not the Team Lead's own model. Look up the agent in [agent-registry.md](../customizations/agents/agent-registry.md) and use their assigned model and tier. For example, delegating to Developer → `"model":"claude-sonnet-4-6","tier":"quality"`, not the Team Lead's `claude-opus-4-6`.
109
105
 
@@ -117,11 +113,7 @@ Async in isolated Git worktree. Use when:
117
113
 
118
114
  Spawn via: Delegate Session → Background → Select agent → Enter prompt with full self-contained context (they cannot ask follow-ups).
119
115
 
120
- **After spawning**, log the delegation record before spawning another agent or doing any other work:
121
- ```bash
122
- echo '{"timestamp":"<ISO-NOW>","session_id":"<branch>","agent":"<name>","model":"<model>","tier":"<tier>","mechanism":"background","tracker_issue":"<issue-or-N/A>","outcome":"pending","retries":0,"phase":<N>,"file_partition":["<paths>"]}' >> .github/customizations/logs/delegations.ndjson
123
- ```
124
- Verify: `tail -1 .github/customizations/logs/delegations.ndjson`
116
+ **After spawning**, log the delegation record before spawning another agent or doing any other work. This is a **⛔ hard gate** — do NOT spawn another agent or proceed until the delegation is logged. Use the **observability-logging** skill's delegation record command (`--mechanism background`, `--outcome pending`).
125
117
 
126
118
  > **`model` and `tier` must come from the agent registry** — see note in Sub-Agents section above.
127
119
 
@@ -133,20 +125,11 @@ Parallel agents must never touch the same files. Map file/directory ownership be
133
125
 
134
126
  ### Budget
135
127
 
136
- | Tier | Model | Est. Tokens | Est. Duration |
137
- |------|-------|-------------|---------------|
138
- | **Economy** | GPT-5 mini | ~5K–15K | 2–5 min |
139
- | **Fast** | GPT-5.3-Codex | ~10K–40K | 5–15 min |
140
- | **Standard** | Gemini 3.1 Pro | ~15K–50K | 8–20 min |
141
- | **Quality** | Claude Sonnet 4.6 | ~30K–80K | 10–25 min |
142
- | **Premium** | Claude Opus 4.6 | ~50K–150K | 15–30 min |
143
-
144
- **Quick reference:** Premium for orchestration, Quality for coding/UI/security/architecture, Standard for analysis/schemas/cost-sensitive, Fast for tests/data/terminal, Economy for docs.
128
+ See the **team-lead-reference** skill for model tiers, token estimates, duration estimates, and budget rules.
145
129
 
146
130
  - Target 5–7 delegations per session. At 8 → warn. At 9 → checkpoint. At 10+ → STOP and save state.
147
131
  - Max 3 delegation attempts per task. After 3 failures → Dead Letter Queue + Architect.
148
132
  - Max 3 panel attempts. After 3 BLOCKs → dispute record.
149
- - Full model routing details in **team-lead-reference** skill.
150
133
 
151
134
  ### Pre-Delegation Checks
152
135
 
@@ -191,7 +174,7 @@ Every delegation prompt must include:
191
174
  - **File paths** — exact files to read/modify (the agent's partition)
192
175
  - **Acceptance criteria** — from the tracker issue
193
176
  - **Patterns** — link to existing code examples
194
- - **Reminder:** *"Read `LESSONS-LEARNED.md` before starting. Add lessons for any retries. Follow the Discovered Issues Policy."*
177
+ - **Reminder:** *"Read `LESSONS-LEARNED.md` before starting. Use the **self-improvement** skill for any lessons. Follow the Discovered Issues Policy."*
195
178
 
196
179
  For complex tasks (score 5+), load the **decomposition** skill for the Delegation Spec Template.
197
180
 
@@ -205,7 +188,7 @@ For complex tasks (score 5+), load the **decomposition** skill for the Delegatio
205
188
  For each task:
206
189
  1. Move issue → In Progress
207
190
  2. Delegate to specialist agent by name (e.g., "Use the Developer agent to...")
208
- 3. Log delegation to delegations.ndjson (immediatelyverify with `tail -1`)
191
+ 3. Log delegation (⛔ hard gatedo NOT proceed until logged. See the **observability-logging** skill for the command and verify step.)
209
192
  4. Monitor for drift (load orchestration-protocols skill)
210
193
  5. Verify output:
211
194
  - Changed files within partition
@@ -216,7 +199,7 @@ For each task:
216
199
  - High-stakes: panel review (load panel-majority-vote skill)
217
200
  - Discovered issues tracked (not silently ignored)
218
201
  - Lessons captured (if agent retried anything)
219
- 6. PASS → log review, move issue → Done
202
+ 6. PASS → log review (⛔ hard gate — do NOT proceed until logged), move issue → Done
220
203
  FAIL → re-delegate with failure details (max 3 attempts)
221
204
  ```
222
205
 
@@ -248,16 +231,7 @@ See [shared-delivery-phase.md](../agent-workflows/shared-delivery-phase.md) for
248
231
 
249
232
  ## Observability
250
233
 
251
- > **⛔ HARD GATE — ALL observability logging is mandatory.** No record type is optional.
252
- > The Session Guard will flag missing records, but do not rely on it — log inline as you go.
253
-
254
- | Record | File | When to log | Timing |
255
- |--------|------|-------------|--------|
256
- | **Session** | `sessions.ndjson` | Every session — always | Before yielding to user |
257
- | **Delegation** | `delegations.ndjson` | After each `runSubagent` / background spawn | **Inline** — immediately after each delegation, before review |
258
- | **Fast review** | `reviews.ndjson` | After each fast review | After review completes |
259
- | **Panel** | `panels.ndjson` | After each panel majority vote | After panel completes |
260
- | **Dispute** | `disputes.ndjson` | After each dispute is created | When dispute is filed |
234
+ > **⛔ HARD GATE — ALL observability logging is mandatory.** Load the **observability-logging** skill for record schemas, logging commands, and the pre-response quality gate.
261
235
 
262
236
  **Self-check before calling Session Guard:** Count delegations, reviews, and panels performed → count records written → numbers must match for each type. If any count is off, fix it before calling the guard.
263
237
 
@@ -273,7 +247,7 @@ See [shared-delivery-phase.md](../agent-workflows/shared-delivery-phase.md) for
273
247
  8. Never proceed to dependent task until prerequisite is verified
274
248
  9. Sub-agents must not spawn other sub-agents (no recursive delegation)
275
249
  10. Never push to `main` — feature branch → PR → human merges
276
- 11. Log every delegation inline — immediately after each `runSubagent` or background spawn, not at session end
250
+ 11. Log every delegation and review inline — immediately after each `runSubagent` or background spawn, and after each fast review/panel. This is a hard gate — never proceed without logging first
277
251
  12. Steer early — don't wait until an agent finishes to redirect when you spot drift
278
252
  13. Never exceed session budget without checkpointing — context degrades after 8+ delegations
279
253
  14. Read `LESSONS-LEARNED.md` before delegating — include relevant lessons in prompts
@@ -76,4 +76,4 @@ When completing a task, return a structured summary:
76
76
  4. **Edge Cases Tested** — List edge cases covered and any known gaps
77
77
  5. **Regressions Checked** — Adjacent features/pages verified to still work
78
78
 
79
- See **Base Output Contract** in `general.instructions.md` for the standard closing items (Discovered Issues + Lessons Applied).
79
+ See **Base Output Contract** in the **observability-logging** skill for the standard closing items (Discovered Issues + Lessons Applied).
@@ -56,4 +56,4 @@ When completing a task, return a structured summary:
56
56
  3. **Responsive** — Breakpoints tested (per project testing config)
57
57
  4. **Visual Evidence** — Screenshots at each breakpoint
58
58
 
59
- See **Base Output Contract** in `general.instructions.md` for the standard closing items (Discovered Issues + Lessons Applied).
59
+ See **Base Output Contract** in the **observability-logging** skill for the standard closing items (Discovered Issues + Lessons Applied).
@@ -6,45 +6,44 @@ Tracks agent success rates across panel reviews and delegated tasks to inform mo
6
6
  ## Data Sources
7
7
 
8
8
  Performance data is collected automatically via NDJSON session logs:
9
- - **Session data:** `.github/customizations/logs/sessions.ndjson` — appended by every agent after each session
10
- - **Delegation data:** `.github/customizations/logs/delegations.ndjson` — appended by the Team Lead after each delegation
9
+ - **All events:** `.github/customizations/logs/events.ndjson` — unified log for all event types (sessions, delegations, reviews, panels, disputes), appended via `opencastle log`
11
10
  - **Dashboard:** Run `npx opencastle dashboard` to visualize agent performance
12
11
 
13
12
  ## Quick Queries
14
13
 
15
14
  ```bash
16
15
  # Sessions per agent
17
- jq -r '.agent' .github/customizations/logs/sessions.ndjson | sort | uniq -c | sort -rn
16
+ jq -r 'select(.type == "session") | .agent' .github/customizations/logs/events.ndjson | sort | uniq -c | sort -rn
18
17
 
19
18
  # Success rate by agent
20
- jq -r '[.agent, .outcome] | @tsv' .github/customizations/logs/sessions.ndjson | sort | uniq -c
19
+ jq -r 'select(.type == "session") | [.agent, .outcome] | @tsv' .github/customizations/logs/events.ndjson | sort | uniq -c
21
20
 
22
21
  # Delegation tier distribution
23
- jq -r '.tier' .github/customizations/logs/delegations.ndjson | sort | uniq -c
22
+ jq -r 'select(.type == "delegation") | .tier' .github/customizations/logs/events.ndjson | sort | uniq -c
24
23
 
25
24
  # Failed delegations
26
- jq 'select(.outcome == "failed")' .github/customizations/logs/delegations.ndjson
25
+ jq 'select(.type == "delegation" and .outcome == "failed")' .github/customizations/logs/events.ndjson
27
26
  ```
28
27
 
29
28
  ## Panel Review Performance
30
29
 
31
- Panel review data is collected automatically via `.github/customizations/logs/panels.ndjson` (appended by the panel runner after each review — see step 7 in the panel majority vote skill).
30
+ Panel review data is collected automatically in `.github/customizations/logs/events.ndjson` with `type: "panel"` (appended by the panel runner after each review — see step 7 in the panel majority vote skill).
32
31
 
33
32
  ```bash
34
33
  # Total panel reviews
35
- wc -l .github/customizations/logs/panels.ndjson
34
+ jq 'select(.type == "panel")' .github/customizations/logs/events.ndjson | wc -l
36
35
 
37
36
  # Pass vs block rate
38
- jq -r '.verdict' .github/customizations/logs/panels.ndjson | sort | uniq -c
37
+ jq -r 'select(.type == "panel") | .verdict' .github/customizations/logs/events.ndjson | sort | uniq -c
39
38
 
40
39
  # Reviews by panel key
41
- jq -r '.panel_key' .github/customizations/logs/panels.ndjson | sort | uniq -c | sort -rn
40
+ jq -r 'select(.type == "panel") | .panel_key' .github/customizations/logs/events.ndjson | sort | uniq -c | sort -rn
42
41
 
43
42
  # Reviews that required retries (attempt > 1)
44
- jq 'select(.attempt > 1)' .github/customizations/logs/panels.ndjson
43
+ jq 'select(.type == "panel" and .attempt > 1)' .github/customizations/logs/events.ndjson
45
44
 
46
45
  # Average SHOULD-FIX items per review
47
- jq -s 'if length > 0 then (map(.should_fix) | add) / length else 0 end' .github/customizations/logs/panels.ndjson
46
+ jq -s '[.[] | select(.type == "panel")] | if length > 0 then (map(.should_fix) | add) / length else 0 end' .github/customizations/logs/events.ndjson
48
47
  ```
49
48
 
50
49
  ## Usage
@@ -86,7 +86,7 @@ Which option the Team Lead recommends and why. Include specific next steps:
86
86
 
87
87
  Links to evidence for human review:
88
88
  - Panel report: `.github/customizations/logs/panel/[panel-key].md`
89
- - Review log entries: `.github/customizations/logs/reviews.ndjson` (filter by issue)
89
+ - Review log entries: `.github/customizations/logs/events.ndjson` (filter by `type: "review"` and issue)
90
90
  - Changed files: [list of files in the last attempt]
91
91
  - DLQ entry (if any): `DLQ-XXX`
92
92
  ```
@@ -112,7 +112,7 @@ Links to evidence for human review:
112
112
  ┌──────────────────────────────────────┐
113
113
  │ Team Lead creates dispute record │
114
114
  │ Status: pending │
115
- │ Logs to disputes.ndjson
115
+ │ Logs to events.ndjson
116
116
  │ Links to tracker issue │
117
117
  └──────────────┬───────────────────────┘
118
118
 
@@ -50,9 +50,7 @@ Structured machine-readable logs appended automatically by agents during session
50
50
  | File | Purpose |
51
51
  |------|---------|
52
52
  | `README.md` | Schema documentation for the NDJSON log files |
53
- | `sessions.ndjson` | Structured session log entries |
54
- | `delegations.ndjson` | Structured delegation log entries |
55
- | `panels.ndjson` | Structured panel review log entries |
53
+ | `events.ndjson` | All structured event log entries (sessions, delegations, reviews, panels, disputes) |
56
54
 
57
55
  ## When to update
58
56
 
@@ -1,21 +1,64 @@
1
1
  # Agent Session Logs
2
2
 
3
- Append-only NDJSON logs for agent activity tracking. Each file stores one JSON object per line.
3
+ Append-only NDJSON log for agent activity tracking. All events are stored in a single file with a `type` discriminator — one JSON object per line.
4
4
 
5
- ## Files
5
+ ## File
6
6
 
7
- | File | Appended by | Schema |
8
- |------|------------|--------|
9
- | `sessions.ndjson` | All agents (via self-improvement protocol) | Session record |
10
- | `delegations.ndjson` | Team Lead agent | Delegation record |
11
- | `reviews.ndjson` | Team Lead (via fast-review skill) | Fast review record |
12
- | `panels.ndjson` | Panel runner (via panel majority vote skill) | Panel record |
13
- | `disputes.ndjson` | Team Lead (via dispute protocol) | Dispute record |
7
+ | File | Description |
8
+ |------|-------------|
9
+ | `events.ndjson` | All agent events, sorted by timestamp |
14
10
 
15
- ## Session Record Schema
11
+ ## Type Discriminator
12
+
13
+ Each record includes a `type` field that identifies the event kind:
14
+
15
+ | `type` value | Appended by | Description |
16
+ |-------------|-------------|-------------|
17
+ | `session` | All agents (via self-improvement protocol) | Session record |
18
+ | `delegation` | Team Lead agent | Delegation record |
19
+ | `review` | Team Lead (via fast-review skill) | Fast review record |
20
+ | `panel` | Panel runner (via panel majority vote skill) | Panel record |
21
+ | `dispute` | Team Lead (via dispute protocol) | Dispute record |
22
+
23
+ ## CLI Usage
24
+
25
+ Use `opencastle log` to append events. Agents should call this instead of raw `echo` commands.
26
+
27
+ ```sh
28
+ # Session
29
+ opencastle log --type session --agent Developer --model claude-sonnet-4-6 \
30
+ --task "PRJ-57: Fix header component" --outcome success --duration_min 12 \
31
+ --files_changed 5 --retries 0
32
+
33
+ # Delegation
34
+ opencastle log --type delegation --session_id feat/prj-57 --agent Developer \
35
+ --model claude-opus-4-6 --tier fast --mechanism sub-agent \
36
+ --outcome success --phase 2 --file_partition "src/components/,src/pages/"
37
+
38
+ # Review
39
+ opencastle log --type review --tracker_issue PRJ-42 --agent Developer \
40
+ --reviewer_model gpt-5-mini --verdict pass --attempt 1 \
41
+ --issues_critical 0 --issues_major 0 --issues_minor 2 \
42
+ --confidence high --escalated false
43
+
44
+ # Panel
45
+ opencastle log --type panel --panel_key auth-review --verdict pass \
46
+ --pass_count 3 --block_count 0 --must_fix 0 --should_fix 5 \
47
+ --reviewer_model claude-opus-4-6 --weighted false --attempt 1
48
+
49
+ # Dispute
50
+ opencastle log --type dispute --dispute_id DSP-001 --tracker_issue PRJ-42 \
51
+ --priority high --trigger panel-3x-block --implementing_agent Developer \
52
+ --reviewing_agents "Reviewer,Panel (3x)" --total_attempts 6 --status pending
53
+ ```
54
+
55
+ Run `opencastle log --help` for full options.
56
+
57
+ ## Session Record (`type: "session"`)
16
58
 
17
59
  ```json
18
60
  {
61
+ "type": "session",
19
62
  "timestamp": "2026-02-25T14:30:00Z",
20
63
  "agent": "Developer",
21
64
  "model": "gpt-5.3-codex",
@@ -32,6 +75,7 @@ Append-only NDJSON logs for agent activity tracking. Each file stores one JSON o
32
75
 
33
76
  | Field | Type | Required | Description |
34
77
  |-------|------|----------|-------------|
78
+ | `type` | `string` | Yes | Always `"session"` |
35
79
  | `timestamp` | `string` | Yes | ISO 8601 datetime (YYYY-MM-DDTHH:MM:SSZ) |
36
80
  | `agent` | `string` | Yes | Agent name from the registry |
37
81
  | `model` | `string` | Yes | Model used (e.g., `claude-opus-4-6`, `gpt-5.3-codex`) |
@@ -44,10 +88,11 @@ Append-only NDJSON logs for agent activity tracking. Each file stores one JSON o
44
88
  | `lessons_added` | `string[]` | No | Lesson IDs added (e.g., `["LES-015"]`) |
45
89
  | `discoveries` | `string[]` | No | Issues discovered (issue IDs or KNOWN-ISSUES IDs) |
46
90
 
47
- ## Delegation Record Schema
91
+ ## Delegation Record (`type: "delegation"`)
48
92
 
49
93
  ```json
50
94
  {
95
+ "type": "delegation",
51
96
  "timestamp": "2026-02-25T14:30:00Z",
52
97
  "session_id": "feat/prj-57",
53
98
  "agent": "Developer",
@@ -64,6 +109,7 @@ Append-only NDJSON logs for agent activity tracking. Each file stores one JSON o
64
109
 
65
110
  | Field | Type | Required | Description |
66
111
  |-------|------|----------|-------------|
112
+ | `type` | `string` | Yes | Always `"delegation"` |
67
113
  | `timestamp` | `string` | Yes | ISO 8601 datetime (YYYY-MM-DDTHH:MM:SSZ) |
68
114
  | `session_id` | `string` | Yes | Branch name or feature identifier |
69
115
  | `agent` | `string` | Yes | Agent name delegated to |
@@ -76,10 +122,11 @@ Append-only NDJSON logs for agent activity tracking. Each file stores one JSON o
76
122
  | `phase` | `number` | No | Execution phase number |
77
123
  | `file_partition` | `string[]` | No | Directories/files assigned |
78
124
 
79
- ## Fast Review Record Schema
125
+ ## Fast Review Record (`type: "review"`)
80
126
 
81
127
  ```json
82
128
  {
129
+ "type": "review",
83
130
  "timestamp": "2026-02-28T14:30:00Z",
84
131
  "tracker_issue": "PRJ-42",
85
132
  "agent": "Developer",
@@ -97,6 +144,7 @@ Append-only NDJSON logs for agent activity tracking. Each file stores one JSON o
97
144
 
98
145
  | Field | Type | Required | Description |
99
146
  |-------|------|----------|-------------|
147
+ | `type` | `string` | Yes | Always `"review"` |
100
148
  | `timestamp` | `string` | Yes | ISO 8601 datetime (YYYY-MM-DDTHH:MM:SSZ) |
101
149
  | `tracker_issue` | `string` | No | Issue ID if applicable |
102
150
  | `agent` | `string` | Yes | Agent whose output was reviewed |
@@ -110,10 +158,11 @@ Append-only NDJSON logs for agent activity tracking. Each file stores one JSON o
110
158
  | `escalated` | `boolean` | Yes | Whether this review triggered escalation to panel |
111
159
  | `duration_sec` | `number` | No | Review duration in seconds |
112
160
 
113
- ## Panel Record Schema
161
+ ## Panel Record (`type: "panel"`)
114
162
 
115
163
  ```json
116
164
  {
165
+ "type": "panel",
117
166
  "timestamp": "2026-02-25T14:30:00Z",
118
167
  "panel_key": "instruction-refactoring",
119
168
  "verdict": "pass",
@@ -132,6 +181,7 @@ Append-only NDJSON logs for agent activity tracking. Each file stores one JSON o
132
181
 
133
182
  | Field | Type | Required | Description |
134
183
  |-------|------|----------|-------------|
184
+ | `type` | `string` | Yes | Always `"panel"` |
135
185
  | `timestamp` | `string` | Yes | ISO 8601 datetime (YYYY-MM-DDTHH:MM:SSZ) |
136
186
  | `panel_key` | `string` | Yes | Filesystem-safe panel identifier |
137
187
  | `verdict` | `string` | Yes | `pass` or `block` |
@@ -146,10 +196,11 @@ Append-only NDJSON logs for agent activity tracking. Each file stores one JSON o
146
196
  | `artifacts_count` | `number` | No | Number of artifacts reviewed |
147
197
  | `report_path` | `string` | No | Path to the full panel report |
148
198
 
149
- ## Dispute Record Schema
199
+ ## Dispute Record (`type: "dispute"`)
150
200
 
151
201
  ```json
152
202
  {
203
+ "type": "dispute",
153
204
  "timestamp": "2026-02-28T16:00:00Z",
154
205
  "dispute_id": "DSP-001",
155
206
  "tracker_issue": "PRJ-42",
@@ -167,6 +218,7 @@ Append-only NDJSON logs for agent activity tracking. Each file stores one JSON o
167
218
 
168
219
  | Field | Type | Required | Description |
169
220
  |-------|------|----------|-------------|
221
+ | `type` | `string` | Yes | Always `"dispute"` |
170
222
  | `timestamp` | `string` | Yes | ISO 8601 datetime when dispute was created |
171
223
  | `dispute_id` | `string` | Yes | Dispute ID (e.g., `DSP-001`) |
172
224
  | `tracker_issue` | `string` | No | Issue ID if applicable |
@@ -1,145 +1,34 @@
1
1
  ---
2
- description: 'AI assistant optimization techniques for efficient context usage and faster responses'
2
+ description: 'AI assistant optimization patterns for efficient context usage and tool calls'
3
3
  applyTo: '**'
4
4
  ---
5
5
 
6
6
  <!-- ⚠️ This file is managed by OpenCastle. Edits will be overwritten on update. Customize in the .github/customizations/ directory instead. -->
7
7
 
8
- # AI Assistant Optimization Instructions
8
+ # AI Optimization
9
9
 
10
- ## Batch Processing
10
+ Batch independent operations, gather context before acting, and avoid redundant tool calls.
11
11
 
12
- ### DO: Batch Independent Operations
12
+ ## Key Rules
13
13
 
14
- When gathering context, batch all read operations together in a single parallel call:
14
+ - **Batch independent reads** — parallelize file reads, searches, and error checks in a single call instead of sequentially
15
+ - **Don't batch dependent ops** — if step B needs step A's output, run them sequentially
16
+ - **Gather context first** — read and search before editing; don't act on assumptions
17
+ - **Read strategically** — prefer large ranges (500–2000 lines) over many micro-reads; use `grep_search` to locate, then read targeted ranges
18
+ - **Combine searches** — use regex alternation (`word1|word2|word3`) instead of separate searches
19
+ - **Don't re-read** — if a file or sub-agent result is already in context, use it directly
20
+ - **Verify once per phase** — run tests/lint/errors after a batch of edits, not after each individual change
21
+ - **Scale planning to complexity** — trivial (1–2 files) → act directly; large (10+ files) → full decomposition
22
+ - **Trust sub-agent results** — don't re-search or re-read what a sub-agent already returned
23
+ - **Include file paths in delegation prompts** — saves the sub-agent from wasting context on discovery
15
24
 
16
- ```
17
- Good: Read 3 files + search in parallel → 1 cache-friendly turn
18
- Bad: Read file 1 → Read file 2 → Read file 3 → 3 separate turns
19
- ```
25
+ ## Anti-Patterns
20
26
 
21
- When modifying multiple independent files, batch the edits:
22
-
23
- ```
24
- Good: Update 5 config files in parallel
25
- Bad: Update config 1 wait Update config 2 → wait...
26
- ```
27
-
28
- ### DON'T: Batch Dependent Operations
29
-
30
- Don't batch operations where one depends on the output of another:
31
-
32
- ```
33
- Bad: Read file + Edit file (need to read first)
34
- Good: Read file → Analyze → Edit file
35
- ```
36
-
37
- ## Context Gathering Workflow
38
-
39
- Gather all necessary context upfront before analysis/implementation:
40
-
41
- ```
42
- Phase 1 (parallel): Read files + search for patterns + check errors
43
- Phase 2: Analyze and plan
44
- Phase 3 (parallel if independent): Create/modify files
45
- Phase 4: Verify (tests, errors, lint)
46
- ```
47
-
48
- ## Token Reduction Techniques
49
-
50
- ### Strategic Tool Selection
51
-
52
- - Use `grep_search` with `includePattern` to scope searches to specific directories
53
- - Use `file_search` to find files by pattern before reading
54
- - Use `semantic_search` for exploring unfamiliar code instead of multiple grep searches
55
- - Read targeted line ranges when you know approximately where code is
56
-
57
- ### Avoid Redundant Operations
58
-
59
- - Don't re-read files already in context from the same conversation turn
60
- - Check errors once per phase, not after every single change
61
- - Don't search for what's already mentioned in context
62
- - Use regex with alternation (e.g., `word1|word2|word3`) to combine searches
63
-
64
- ### Read Strategically
65
-
66
- - Read larger sections (500-2000 lines) instead of many small reads
67
- - Use `grep_search` to locate code, then read targeted ranges around it
68
- - Deduplicate file paths before batching read operations
69
-
70
- ## Multi-Agent Optimization
71
-
72
- ### Sub-Agent Context Isolation
73
-
74
- Sub-agents run in isolated context windows. Use this to your advantage:
75
-
76
- - **Offload exploration** — fire a sub-agent to research a broad question; only the concise result comes back, keeping your primary context clean
77
- - **Parallel research** — launch multiple sub-agents simultaneously for independent research tasks (e.g., "find all CMS queries" + "list all components using X" at the same time)
78
- - **Detailed prompts save tokens** — a specific sub-agent prompt avoids the sub-agent doing its own exploratory searches, which would waste its context budget
79
-
80
- ### Trust Sub-Agent Results
81
-
82
- - Don't re-read files a sub-agent just analyzed — trust the returned summary
83
- - Don't re-search for patterns a sub-agent already identified
84
- - If a sub-agent returns file paths or code snippets, use them directly
85
-
86
- ### Background Agents for Long Work
87
-
88
- - Delegate tasks expected to take >5 minutes to background agents — they run in parallel without blocking
89
- - Include **all necessary context** in the delegation prompt (background agents can't ask follow-up questions)
90
- - Batch independent background delegations together (e.g., launch DB migration + UI components + docs simultaneously)
91
-
92
- ### Delegation Prompt Efficiency
93
-
94
- - Include exact file paths so the delegated agent doesn't waste time searching
95
- - Reference existing patterns ("follow the structure in `libs/ui-kit/src/lib/Button/`") instead of describing patterns from scratch
96
- - Set clear scope boundaries ("only modify files under `libs/queries/`") to prevent unnecessary exploration
97
-
98
- ## Response Optimization
99
-
100
- - Provide brief progress updates after batched operations
101
- - Describe changes concisely instead of repeating large code blocks
102
- - Plan what context is needed before making tool calls
103
- - Combine multiple related edits in planning before executing
104
-
105
- ## Planning Thresholds
106
-
107
- Scale planning effort to task complexity — don't over-plan simple work:
108
-
109
- | Complexity | Planning | Approach |
110
- |-----------|----------|----------|
111
- | Trivial (1-2 files, clear fix) | None | Act directly |
112
- | Small (3-5 files, single concern) | Mental plan | Brief reasoning, then act |
113
- | Medium (5-10 files, multiple concerns) | Todo list | Track steps, batch reads |
114
- | Large (10+ files, cross-cutting) | Full decomposition | Dependency graph, phased execution |
115
-
116
- **Stop-and-re-plan trigger:** See the Task Decomposition Protocol in `general.instructions.md` (step 5).
117
-
118
- ## Test & Build Output Efficiency
119
-
120
- - Capture full test/build output **once** per verification phase, not after each micro-change
121
- - Pipe verbose output through `tail -n 30` or `grep -E 'FAIL|ERROR|PASS'` to reduce noise
122
- - When tests fail, read the **relevant failure block** — don't re-run the entire suite repeatedly
123
-
124
- ## README Cascade Reading
125
-
126
- When entering an unfamiliar directory, check for a `README.md` before exploring files. READMEs provide architecture context that prevents wasted searches. Priority order:
127
- 1. Project root `README.md` (already covered by instruction files)
128
- 2. Library/app-level `README.md` (e.g., `libs/queries/README.md`)
129
- 3. Feature-level `README.md` (e.g., `libs/data-pipeline/src/lib/scrapers/README.md`)
130
-
131
- ## Anti-Patterns to Avoid
132
-
133
- 1. **Micro-reads** — Reading tiny file sections repeatedly
134
- 2. **Sequential searches** — Running searches one at a time when they're independent
135
- 3. **Premature actions** — Acting before gathering sufficient context
136
- 4. **Silent processing** — Batching without progress updates
137
- 5. **Exploratory tool calls** — Making tool calls without a clear plan
138
- 6. **Over-checking** — Validating after every tiny change instead of batching
139
- 7. **Re-gathering delegated context** — Re-reading files or re-searching after a sub-agent already returned the information
140
- 8. **Vague delegation prompts** — Forcing sub-agents to waste their context budget on discovery you already completed
141
- 9. **Sequential delegation** — Running independent sub-agents one-by-one when they could run in parallel
142
- 10. **Leaking secrets** — Printing tokens, keys, or passwords in terminal output or logs (violates Constitution #1)
143
- 11. **Over-planning** — Writing a full decomposition for a 2-file fix (see Planning Thresholds)
27
+ 1. **Micro-reads** reading tiny file sections repeatedly
28
+ 2. **Sequential searches** — running independent searches one at a time
29
+ 3. **Premature actions** — editing before gathering sufficient context
30
+ 4. **Over-checking** validating after every tiny change instead of batching
31
+ 5. **Re-gathering delegated context** re-reading files a sub-agent already analyzed
32
+ 6. **Over-planning** — full decomposition for a 2-file fix
144
33
 
145
34
  <!-- End of AI Optimization Instructions -->