opencastle 0.8.1 → 0.9.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.
@@ -58,17 +58,11 @@ Load relevant skills before writing code.
58
58
 
59
59
  ### Actions
60
60
 
61
- 1. **Run the Pre-Response Quality Gate**This is the single exit gate. Verify ALL items from the checklist in `general.instructions.md` § Pre-Response Quality Gate:
62
- - [ ] Lessons read at session start
63
- - [ ] Lessons captured for any retries
64
- - [ ] Discovered issues tracked (not ignored)
65
- - [ ] Lint/type/test pass (no new errors)
66
- - [ ] Session logged to `sessions.ndjson` (ALWAYS)
67
- - [ ] Delegations logged (Team Lead only)
68
- - [ ] Reviews/panels/disputes logged (if applicable)
69
- 2. **Save checkpoint** (Team Lead only) — If work is incomplete, write `.github/customizations/SESSION-CHECKPOINT.md` with current state so the next session can resume. Load **session-checkpoints** skill for format.
70
- 3. **Memory merge check** — If `LESSONS-LEARNED.md` has grown significantly (5+ new entries this session), flag for memory merge consideration.
71
- 4. **Clean up** — Remove any temporary files created during the session (e.g., test fixtures, debug outputs).
61
+ 1. **Call Session Guard** (Team Lead only) Delegate to the **Session Guard** agent with a session summary (delegations, retries, discoveries, files changed). Execute any fix commands it returns. This replaces the manual Pre-Response Quality Gate checklist — the guard runs it automatically with a fresh context window.
62
+ 2. **For specialist agents** (not Team Lead) — Run the Pre-Response Quality Gate checklist from `general.instructions.md` manually. Specialist agents don't have access to the Session Guard.
63
+ 3. **Save checkpoint** (Team Lead only) — If work is incomplete, write `.github/customizations/SESSION-CHECKPOINT.md` with current state so the next session can resume. Load **session-checkpoints** skill for format.
64
+ 4. **Memory merge check** If `LESSONS-LEARNED.md` has grown significantly (5+ new entries this session), flag for memory merge consideration.
65
+ 5. **Clean up** Remove any temporary files created during the session (e.g., test fixtures, debug outputs).
72
66
 
73
67
  ### Template for Delegation Prompts
74
68
 
@@ -80,6 +74,8 @@ Load relevant skills before writing code.
80
74
  - Clean up temp files
81
75
  ```
82
76
 
77
+ > **Note for Team Lead:** You do NOT use this template yourself. Instead, call the **Session Guard** agent (step 10 in your role). This template is only for specialist agents you delegate to.
78
+
83
79
  ---
84
80
 
85
81
  ## Hook: on-pre-delegate
@@ -115,8 +111,12 @@ Pre-Delegate:
115
111
 
116
112
  ### Actions
117
113
 
118
- 0. **Fast review (mandatory)** — Run the `fast-review` skill against the agent's output. This is a **non-skippable gate**. See the fast-review skill for the full procedure (single reviewer sub-agent, automatic retry, escalation). Only after the fast review passes do you proceed to the remaining post-delegate actions below.
119
- 1. **Verify output** — Read changed files. Check that changes stay within the agent's file partition.
114
+ 0. **Log the delegation NOW** — Append a record to `.github/customizations/logs/delegations.ndjson` immediately. Do this BEFORE review or verification logging must not depend on review passing.
115
+ ```bash
116
+ echo '{"timestamp":"...","session_id":"<branch>","agent":"...","model":"...","tier":"...","mechanism":"sub-agent","outcome":"...","retries":0,"phase":N,"file_partition":["..."]}' >> .github/customizations/logs/delegations.ndjson
117
+ ```
118
+ 1. **Fast review (mandatory)** — Run the `fast-review` skill against the agent's output. This is a **non-skippable gate**. See the fast-review skill for the full procedure (single reviewer sub-agent, automatic retry, escalation). Only after the fast review passes do you proceed to the remaining post-delegate actions below.
119
+ 2. **Verify output** — Read changed files. Check that changes stay within the agent's file partition.
120
120
  2. **Run verification** — Execute appropriate checks: lint, type-check, tests, or visual inspection.
121
121
  3. **Check acceptance criteria** — Compare output against the tracker issue's acceptance criteria. Each criterion must be independently verified.
122
122
  4. **Discovered issues tracked** — Verify the agent followed the Discovered Issues Policy. If they found issues, check that they're in KNOWN-ISSUES.md or a new tracker ticket.
@@ -127,6 +127,7 @@ Pre-Delegate:
127
127
 
128
128
  ```
129
129
  Post-Delegate:
130
+ ☐ Delegation logged to delegations.ndjson (FIRST — before anything else)
130
131
  ☐ Changed files reviewed
131
132
  ☐ Files within partition
132
133
  ☐ Lint/test/build passes
@@ -0,0 +1,122 @@
1
+ ---
2
+ name: decomposition
3
+ description: "Task decomposition patterns for the Team Lead: dependency resolution, phase assignment, delegation spec templates, prompt quality examples, and orchestration patterns."
4
+ ---
5
+
6
+ # Task Decomposition
7
+
8
+ Detailed decomposition and delegation patterns for the Team Lead. **Load at:** Decompose & Partition phase (Step 2) or when writing delegation prompts (Step 3).
9
+
10
+ ## Dependency Resolution
11
+
12
+ Declare dependencies between subtasks using arrow notation: `TaskB → TaskA` means B depends on A (A must finish first).
13
+
14
+ **Topological sort rules:**
15
+ 1. Tasks with no dependencies go in Phase 1 (can run in parallel)
16
+ 2. Tasks depending only on Phase 1 tasks go in Phase 2
17
+ 3. Continue until all tasks are assigned to phases
18
+ 4. Tasks in the same phase with no mutual dependencies run in parallel
19
+
20
+ **Cycle detection:** If A → B → C → A, break the cycle by: (a) finding a task that can partially complete independently, (b) splitting that task into an independent part and a dependent part.
21
+
22
+ **Visual example:**
23
+
24
+ ```
25
+ Dependency Graph: Execution Plan:
26
+ E → C → A Phase 1: A, B (parallel)
27
+ D → B Phase 2: C, D (parallel, depend on Phase 1)
28
+ F → C, D Phase 3: E, F (parallel, depend on Phase 2)
29
+ ```
30
+
31
+ Always draw the dependency graph before assigning phases. Missed dependencies cause agents to block on missing inputs; redundant sequencing wastes time.
32
+
33
+ ## Delegation Spec Template
34
+
35
+ For complex tasks (score 5+), generate a structured spec rather than a free-form prompt:
36
+
37
+ ```
38
+ ## Delegation Spec: [Task Title]
39
+
40
+ **Tracker Issue:** TAS-XX — [Title]
41
+ **Complexity:** [score]/13 → [tier] tier
42
+ **Agent:** [Agent Name]
43
+
44
+ ### Objective
45
+ What to build/change and why. 1-3 sentences max.
46
+
47
+ ### Context
48
+ - Key files to read first: [list]
49
+ - Related patterns to follow: [file:line references]
50
+ - Relevant lessons: [LES-XXX references from LESSONS-LEARNED.md]
51
+
52
+ ### Constraints
53
+ - File partition: Only modify files under [paths]
54
+ - Do NOT modify: [explicit exclusions]
55
+ - Dependencies: Requires [TAS-XX] to be Done first
56
+
57
+ ### Acceptance Criteria
58
+ - [ ] Criterion 1 (copied from tracker issue)
59
+ - [ ] Criterion 2
60
+ - [ ] Criterion 3
61
+
62
+ ### Expected Output
63
+ Return a structured summary with:
64
+ - Files changed (path + one-line description)
65
+ - Verification results (lint/test/build pass/fail)
66
+ - Acceptance criteria status (each item ✅/❌)
67
+ - Discovered issues (if any)
68
+ - Lessons applied or added
69
+
70
+ **Note:** Follow the Structured Output Contract from the team-lead-reference skill. Include all standard fields plus agent-specific extensions.
71
+
72
+ ### Self-Improvement
73
+ Read `.github/customizations/LESSONS-LEARNED.md` before starting. If you retry any command/tool with a different approach that works, immediately add a lesson to that file.
74
+ ```
75
+
76
+ For simpler tasks (score 1-3), the existing prompt format (objective + files + criteria) is sufficient. Don't over-engineer delegation for trivial work.
77
+
78
+ **For sub-agents** — also specify what information to return in the result message.
79
+
80
+ **For background agents** — include full self-contained context since they cannot ask follow-up questions.
81
+
82
+ ## Prompt Quality Examples
83
+
84
+ **Strong prompt (simple task, score 2):**
85
+ > "**Tracker issue:** TAS-42 — [Auth] Fix token refresh logic
86
+ > Users report 'Invalid token' errors after 30 minutes. JWT tokens are configured with 1-hour expiration in `libs/auth/src/server.ts`. Investigate why tokens expire early and fix the refresh logic. Only modify files under `libs/auth/`. Run the auth library tests to verify."
87
+
88
+ **Strong prompt (complex task, score 8):**
89
+ > Use the Delegation Spec Template above. Fill in all sections for tasks scoring 5+.
90
+
91
+ **Weak prompt:**
92
+ > "Fix the authentication bug."
93
+
94
+ ## Delegation Mechanism Selection
95
+
96
+ ```
97
+ Need result immediately?
98
+ / \
99
+ YES NO
100
+ | |
101
+ Is it a dependency Expected duration
102
+ for the next step? > 5 minutes?
103
+ / \ / \
104
+ YES NO YES NO
105
+ | | | |
106
+ Sub-Agent Sub-Agent Background Sub-Agent
107
+ (inline) (if small enough, Agent (sequential)
108
+ else Background)
109
+ ```
110
+
111
+ ## Mixed Delegation Orchestration
112
+
113
+ Combine sub-agents and background agents for maximum efficiency:
114
+
115
+ ```
116
+ Phase 1 (sub-agent): Research — gather context, identify patterns, map files
117
+ Phase 2 (background): Foundation — DB migration + Component scaffolding (parallel)
118
+ Phase 3 (sub-agent): Integration — wire components to data (needs Phase 2 results)
119
+ Phase 4 (background): Validation — Security audit + Tests + Docs (parallel)
120
+ Phase 5 (sub-agent): QA gate — verify all phases, run builds, self-review
121
+ Phase 6 (sub-agent): Panel review — load panel-majority-vote skill for high-stakes validation
122
+ ```
@@ -0,0 +1,116 @@
1
+ ---
2
+ name: orchestration-protocols
3
+ description: "Runtime orchestration patterns for the Team Lead: parallel research spawning, agent health monitoring, active steering, background agent management, and escalation paths."
4
+ ---
5
+
6
+ # Orchestration Protocols
7
+
8
+ Runtime patterns for managing delegated agents. **Load at:** Execution phase (Step 4+), when monitoring active agents or spawning parallel work.
9
+
10
+ ## Active Steering
11
+
12
+ Monitor agent sessions during execution. Intervene early when you spot:
13
+
14
+ - **Failing tests/builds** — the agent can't resolve a dependency or breaks existing code
15
+ - **Unexpected file changes** — files outside the agent's partition appear in the diff
16
+ - **Scope creep** — the agent starts refactoring code you didn't ask about
17
+ - **Circular behavior** — the agent retries the same failing approach without adjusting
18
+ - **Intent misunderstanding** — session log shows the agent interpreted the prompt differently
19
+
20
+ **When redirecting, be specific.** Explain *why* you're redirecting and *how* to proceed:
21
+
22
+ > "Don't modify `libs/data/src/lib/product.ts` — that file is shared across features. Instead, add the new query in `libs/data/src/lib/reviews.ts`. This keeps the change isolated."
23
+
24
+ **Timing matters.** Catching a problem 5 minutes in can save an hour. Don't wait until the agent finishes.
25
+
26
+ **Background agent caveat:** The drift signals above apply only to **sub-agents** (inline) where you see results in real-time. Background agents run autonomously — you cannot inspect their intermediate state or redirect mid-execution. For background agents, steering is **post-hoc**: invest more effort in prompt specificity and file partition constraints upfront, then review thoroughly when the agent returns its output.
27
+
28
+ ## Background Agents
29
+
30
+ Background agents run autonomously in isolated Git worktrees. Use for well-scoped subtasks with clear acceptance criteria.
31
+
32
+ - **Spawn:** Delegate Session → Background → Select agent → Enter prompt
33
+ - **Auto-compaction:** At 95% token limit, context is automatically compressed
34
+ - **Resume:** Use `--resume` for previous sessions
35
+ - **Duration threshold:** Reserve for tasks expected to take >5 minutes
36
+ - **No real-time monitoring:** You cannot inspect intermediate state. Drift detection happens only at completion review. Mitigate with: (a) highly specific prompts, (b) strict file partition constraints, (c) acceptance criteria checklists in the prompt
37
+
38
+ ## Parallel Research Protocol
39
+
40
+ When a task requires broad exploration before implementation, spawn multiple research sub-agents in parallel to gather context efficiently.
41
+
42
+ ### When to Use
43
+
44
+ - 3+ independent research questions need answering before implementation can begin
45
+ - Broad codebase exploration across multiple libraries or domains
46
+ - Multi-area analysis (e.g., "How do we handle X in the frontend, backend, and CMS?")
47
+
48
+ ### Spawn Strategy
49
+
50
+ - **Divide by topic/area**, not by file count — each researcher should own a coherent domain
51
+ - **Max 3-5 parallel researchers** — more than 5 creates diminishing returns and token waste
52
+ - **Each researcher gets a focused scope** — explicit directories, file patterns, or questions
53
+ - **Use Economy/Standard tier** for research sub-agents to manage cost
54
+
55
+ ### Research Sub-Agent Prompt Template
56
+
57
+ ```
58
+ Research: [specific question]
59
+ Scope: [files/directories to search]
60
+ Return: A structured summary with:
61
+ - Key findings (bullet list)
62
+ - Relevant file paths (with line numbers)
63
+ - Patterns observed
64
+ - Unanswered questions
65
+ ```
66
+
67
+ ### Result Merge Protocol
68
+
69
+ After all research sub-agents return:
70
+
71
+ 1. **Collect** all sub-agent results into a single context
72
+ 2. **Deduplicate** findings — same file/pattern reported by multiple agents counts once
73
+ 3. **Resolve conflicts** — if agents report contradictory information, trust the one with more specific evidence (exact file paths + line numbers > general observations)
74
+ 4. **Synthesize** into a single context block for the next phase — distill the combined findings into a concise summary that can be included in implementation delegation prompts
75
+
76
+ ### When NOT to Use
77
+
78
+ - Single-file investigation — just read the file directly
79
+ - When the answer is in one known location — a single sub-agent or direct read is faster
80
+ - When results must be sequential (e.g., "find X, then based on X find Y")
81
+ - For fewer than 3 questions — overhead of parallel coordination exceeds time saved
82
+
83
+ ## Batch Reviews
84
+
85
+ When multiple background agents complete work simultaneously, batch similar reviews to save time:
86
+
87
+ - Group reviews by domain (e.g., all UI changes together, all data changes together)
88
+ - Run fast reviews in parallel for independent outputs
89
+ - If multiple outputs share the same file partition boundary, review them sequentially to catch integration issues
90
+ - For panel reviews, combine related artifacts into a single panel question when they share acceptance criteria
91
+
92
+ ## Agent Health-Check Protocol
93
+
94
+ Monitor delegated agents for failure signals. Intervene early rather than waiting for completion.
95
+
96
+ ### Health Signals
97
+
98
+ | Signal | Detection | Threshold | Recovery |
99
+ |--------|-----------|-----------|----------|
100
+ | **Stuck** | No new terminal output or file changes | Sub-agent: 5 min / Background: 15 min | Check terminal output. If idle, nudge with clarification. If frozen, abort and re-delegate with simpler scope. |
101
+ | **Looping** | Same error message repeated 3+ times | 3 consecutive identical failures | Abort immediately. Analyze the error, add context the agent is missing, re-delegate with explicit fix path. |
102
+ | **Scope creep** | Files outside assigned partition appear in diff | Any file outside partition | Redirect: "Only modify files in [partition]. Revert changes to [file]." |
103
+ | **Context exhaustion** | Responses become repetitive, confused, or lose earlier instructions | Visible confusion or instruction amnesia | Checkpoint immediately. End session. Resume in fresh context. |
104
+ | **Permission loop** | Agent repeatedly asks for confirmation or waits for input | 2+ consecutive prompts without progress | Auto-approve if safe, or abort and re-delegate with `--dangerously-skip-permissions` flag or equivalent. |
105
+
106
+ ### Health-Check Cadence
107
+
108
+ - **Sub-agents (inline):** Monitor continuously — you see output in real-time
109
+ - **Background agents:** Check terminal output after 10 minutes, then every 10 minutes
110
+ - **After completion:** Always review the full diff before accepting output
111
+
112
+ ### Escalation Path
113
+
114
+ 1. **First failure:** Re-delegate with more specific prompt + error context
115
+ 2. **Second failure:** Downscope the task (split into smaller pieces) and re-delegate
116
+ 3. **Third failure:** Log to Dead Letter Queue (`.github/customizations/AGENT-FAILURES.md`), escalate to Architect for root cause analysis. If the failure involves a panel 3x BLOCK or unresolvable agent/reviewer conflict, create a **dispute record** in `.github/customizations/DISPUTES.md` instead (see **team-lead-reference** skill § Dispute Protocol).