@maestria/pi 0.3.0 → 0.3.2
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/README.md +18 -18
- package/dist/extension.mjs +4 -4
- package/dist/extension.mjs.map +1 -1
- package/package.json +1 -1
- package/prompts/adventurer.md +34 -34
- package/prompts/architect.md +35 -33
- package/prompts/builder.md +47 -46
- package/prompts/diagnose.md +30 -26
- package/prompts/orchestrator.md +51 -51
- package/prompts/planner.md +28 -28
- package/prompts/reviewer.md +30 -30
- package/prompts/writer.md +32 -32
- package/rules/AGENTS.md +24 -19
- package/skills/handoff/SKILL.md +6 -6
- package/skills/iteration-limits/SKILL.md +3 -3
package/README.md
CHANGED
|
@@ -4,13 +4,13 @@ A [Pi coding agent](https://pi.software/) extension that brings Maestria's struc
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **8 Specialist Prompts**
|
|
8
|
-
- **3 Workflow Modes**
|
|
9
|
-
- **Global Rules Injection**
|
|
10
|
-
- **Compaction Preservation**
|
|
11
|
-
- **Subagent Dispatch**
|
|
12
|
-
- **Maker/Checker Split**
|
|
13
|
-
- **2 Methodology Skills**
|
|
7
|
+
- **8 Specialist Prompts** - Orchestrator, Adventurer, Architect, Builder, Diagnose, Planner, Reviewer, Writer
|
|
8
|
+
- **3 Workflow Modes** - `fein` (full pipeline), `sonar` (research only), `blitz` (fast implementation)
|
|
9
|
+
- **Global Rules Injection** - Automatically injects orchestration rules via `before_agent_start`
|
|
10
|
+
- **Compaction Preservation** - Session state survives compaction with structured summaries
|
|
11
|
+
- **Subagent Dispatch** - Delegation via `@gotgenes/pi-subagents` with 6-field handoff validation
|
|
12
|
+
- **Maker/Checker Split** - Review mode blocks destructive tools. Dangerous bash patterns flagged.
|
|
13
|
+
- **2 Methodology Skills** - Handoff contract + iteration limits
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -20,17 +20,17 @@ pi install npm:@maestria/pi
|
|
|
20
20
|
|
|
21
21
|
## Commands
|
|
22
22
|
|
|
23
|
-
| Command
|
|
24
|
-
|
|
|
25
|
-
| `/fein <goal>`
|
|
26
|
-
| `/sonar <goal>`
|
|
27
|
-
| `/blitz <goal>`
|
|
28
|
-
| `/orchestrate <goal>`
|
|
29
|
-
| `/review <target>`
|
|
30
|
-
| `/restore-model`
|
|
31
|
-
| `/handoff <goal>`
|
|
32
|
-
| `/review-model <model-id>` | Set which model to use when entering review mode
|
|
33
|
-
| `/maestria-status`
|
|
23
|
+
| Command | Description |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `/fein <goal>` | Set workflow mode to full pipeline (recon → design → impl → review) |
|
|
26
|
+
| `/sonar <goal>` | Set workflow mode to research only (recon → design → stop) |
|
|
27
|
+
| `/blitz <goal>` | Set workflow mode to fast implementation (builder directly) |
|
|
28
|
+
| `/orchestrate <goal>` | Start a full pipeline by delegating to the orchestrator |
|
|
29
|
+
| `/review <target>` | Enter review mode - blocks destructive tools, sets read-only toolset |
|
|
30
|
+
| `/restore-model` | Restore the original model and tools active before review mode |
|
|
31
|
+
| `/handoff <goal>` | Generate a structured handoff prompt for a new task context |
|
|
32
|
+
| `/review-model <model-id>` | Set which model to use when entering review mode |
|
|
33
|
+
| `/maestria-status` | Show current maestria session state including handoff history |
|
|
34
34
|
|
|
35
35
|
## Development
|
|
36
36
|
|
package/dist/extension.mjs
CHANGED
|
@@ -4,13 +4,13 @@ import{Type as e}from"typebox";import{SUBAGENT_EVENTS as t}from"@gotgenes/pi-sub
|
|
|
4
4
|
`),sonar:[`## MODE: sonar (Research Only)`,``,`Execute research only: /adventurer (recon) →`,`/architect or /planner (design/plan) → STOP.`,`Do NOT implement anything. Return findings.`].join(`
|
|
5
5
|
`),blitz:[`## MODE: blitz (Fast Implementation)`,``,`Execute fast implementation via /builder directly.`,`Skip reconnaissance and design unless the codebase`,`is genuinely unknown. Skip review unless the result`,`needs validation.`].join(`
|
|
6
6
|
`)},f={fein:`[MODE: fein]`,sonar:`[MODE: sonar]`,blitz:`[MODE: blitz]`};function p(e){return`${f[e]}\n\n${d[e]}`}function m(e,t){for(let n of u)e.registerCommand(n,{description:`Set workflow mode to ${n}`,handler:async(r,i)=>{if(t.reviewMode&&await o(e,i,t),t.mode=n,s(e,t),r.trim()){let t=[p(n),``,`Run the maestria default pipeline on: ${r}`].join(`
|
|
7
|
-
`);e.sendUserMessage(t,{deliverAs:`steer`})}else i.ui.notify(`Mode set to ${n}. Describe what you'd like to work on.`)}})}function h(e){return(t,n)=>{let r=["<!-- Auto-generated from @maestria/core. Do not edit directly.\n Edit the canonical file at packages/core/agent-directives/ instead. -->\n\n# Global Agent Rules\n\n## Orchestration\n\n- **!!! Don't assume**
|
|
7
|
+
`);e.sendUserMessage(t,{deliverAs:`steer`})}else i.ui.notify(`Mode set to ${n}. Describe what you'd like to work on.`)}})}function h(e){return(t,n)=>{let r=["<!-- Auto-generated from @maestria/core. Do not edit directly.\n Edit the canonical file at packages/core/agent-directives/ instead. -->\n\n# Global Agent Rules\n\n## Orchestration\n\n- **!!! Don't assume** - verify against actual code and docs. Guesses lead to bugs.\n- **!!! Read the docs first** - before writing code that touches unfamiliar tools, APIs, or migration paths, consult official documentation. Don't guess at API changes. This rule is scar tissue from repeated failures; treat it seriously.\n- **!!! Don't anthropomorphize effort** - You operate at machine scale. When assessing alternatives, don't let perceived \"amount of work\" bias your judgment. What feels like a lot of work to a human is routine iteration for you. Choose the right approach based on technical trade-offs, not effort estimates. Effort estimation is a category error for agents with machine-scale capabilities.\n\n- **Don't reference internal project names in explanations** - avoid leaking context outside the workspace.\n- **Write for humans** - Your output (reasoning, commit messages, documentation, status updates, questions) is read by people. Avoid AI-typical patterns: em dash overuse (-), inflated language, and promotional phrasing. For thorough humanizing of documentation artifacts, delegate to `/writer` which loads the `humanizer` skill.\n- **Use `opensrc` for repos; `webfetch` for pages** - when analyzing a GitHub/GitLab/BitBucket repo or any multi-file code reference, run `opensrc path <owner/repo>` (e.g. `opensrc path facebook/react`). It clones to a global cache and prints a path that `read`/`glob`/`grep` can use directly. For a single file, a specific page, or a known URL, `webfetch` is fine. Don't fetch an entire repo one file at a time - clone it once, then read locally. Use `--cwd` to resolve versions from the current project.\n- **Webfetch may hang - don't block on it** - if a `webfetch` request hangs after you've issued it, **proceed without the result** and surface the skip in your next user-facing message. Don't wait for a hung fetch to complete.\n- **Workflow modes** - keywords `fein` (full pipeline), `sonar` (research only), `blitz` (fast impl) activate per-turn workflow overrides. See the orchestrator prompt for details.\n- **Project `.maestria/`** - `.maestria/workflow.md` and `.maestria/rules.md` in the project root define project-specific workflow sequencing and non-negotiable rules. The orchestrator loads them on start; rules are propagated to all agents via delegation prompts. See the orchestrator prompt for details.\n- **CLI references - use local tools first** - for CLI references, run `bash --help` or load the relevant `skill` instead of reaching for `webfetch`. Local tools are faster and more reliable than fetching docs.\n- **Local files - read directly** - use `read`, `glob`, or `grep` (or `lsp` when available) for any file you have path access to. Don't `webfetch` a local file or a file in a checked-out repo.\n- **Tool hierarchy for external information:**\n 1. `webfetch` - fetch a specific known URL (for docs, pages)\n 2. `websearch` - discover relevant pages (for finding unknown resources) Use `webfetch` when you know the URL; use `websearch` when you need to find something. `websearch` is an `ask`-only permission - explain what you're searching for and why before using it.\n\n## Principles\n\n- **Start from first principles** - before adopting an existing pattern or solution, verify it actually matches the fundamental problem. Prior art is a reference, not a constraint.\n- **Prefer existing solutions** - before building something yourself, verify no well-maintained open-source solution (package registries, GitHub, official libraries, plugins) already covers the need.\n\n## Delegation\n\nWhen delegating work via `maestria_subagent()`, use only the 7 specialists below. **Never delegate to `explore` or `general`** - they are built-in agents, not part of the pipeline.\n\n| Agent | Role | When to Delegate |\n| --- | --- | --- |\n| `/adventurer` | Codebase reconnaissance, deep code understanding | Understanding unfamiliar code, tracing dependencies, gathering context before implementation |\n| `/architect` | Architecture decisions, trade-off analysis, ADRs | Choosing between approaches, technology evaluation |\n| `/builder` | Focused implementation, single-task execution | Feature work, bug fixes, test writing, refactors |\n| `/diagnose` | Systematic bug tracing, root cause analysis | Debugging regressions, production incidents, cryptic errors |\n| `/planner` | Implementation plans with phased milestones | Complex features requiring structured execution |\n| `/reviewer` | Code review with quality gates | Pre-merge review, security audit, post-implementation QA |\n| `/writer` | Documentation following structured patterns | READMEs, API docs, changelogs, ADR transcription |\n\n## Context Management\n\n- **Progressive disclosure** - start high-level, get specific as needed.\n- **State checkpointing** - periodically summarize what's done, what's in progress, what's next.\n- **Context pruning** - remove irrelevant context when no longer needed.\n- **Completion promises** - define success criteria before starting work. \"This task is complete when [verifiable conditions].\"\n\n## Commit Policy\n\n- **Only the orchestrator authorizes commits.** Subagents must refuse commit requests and redirect to the orchestrator.\n- **Builders executing commits** must follow the orchestrator's exact instructions (message, files, validation commands `check`/`test`). Flag it if the orchestrator's instructions skip the commit protocol.\n- **Plans must not include implicit commit steps.** Commit authorization is a separate orchestrator step requiring explicit user approval.\n\n## Pipeline Patterns\n\nThe orchestrator prompt defines the canonical Role-Based Pipeline with thinker/worker/verifier roles and dynamic sequencing.\n",``,t.systemPrompt];return e.mode&&(r.push(``,p(e.mode)),r.push(``,`The user has set workflow mode to "${e.mode}". Honor this mode throughout the session until changed via /command.`)),{systemPrompt:r.join(`
|
|
8
8
|
`)}}}function g(e,t){e.on(`session_before_compact`,e=>({compaction:{summary:l(t),details:{...t},firstKeptEntryId:e.preparation.firstKeptEntryId,tokensBefore:e.preparation.tokensBefore}})),e.on(`session_before_tree`,e=>{if(e.preparation.userWantsSummary)return{summary:{summary:l(t)}}})}const _={REVIEW_ACTIVATED:`maestria:review:activated`,REVIEW_DEACTIVATED:`maestria:review:deactivated`,SUBAGENT_STARTED:`maestria:subagent:started`,SUBAGENT_COMPLETED:`maestria:subagent:completed`,SUBAGENT_FAILED:`maestria:subagent:failed`},v=[`adventurer`,`architect`,`builder`,`diagnose`,`planner`,`reviewer`,`writer`],y=new Set([`completed`,`steered`,`aborted`,`stopped`,`error`]);function b(n,r,a){if(n.registerTool({name:`maestria_subagent`,label:`Maestria Subagent`,description:`Dispatch a task to a @maestria specialist subagent`,promptSnippet:`Delegate tasks to @maestria specialist subagents (adventurer, architect, builder, planner, diagnose, reviewer, writer)`,promptGuidelines:[`Use maestria_subagent when a task MUST be delegated to a specialist subagent rather than handled directly. Each specialist has focused capabilities: adventurer (recon), architect (design), builder (impl), planner (planning), diagnose (bugs), reviewer (QA), writer (docs).`],prepareArguments(e){return e},parameters:e.Object({agent:e.Optional(e.String({description:`Specialist agent name`})),task:e.Optional(e.String({description:`Task description for the subagent`})),tasks:e.Optional(e.Array(e.Object({agent:e.String(),task:e.String()}),{description:`Array of task objects for parallel or chain dispatch`})),mode:e.Optional(e.Union([e.Literal(`parallel`),e.Literal(`chain`),e.Literal(`single`)]))}),async execute(e,t,a,o,s){if(r.reviewMode)return{content:[{type:`text`,text:`Subagent dispatch is not available during review mode. Use /restore-model to exit review mode first.`}]};let c=t.mode??`single`;if(c===`single`){if(!v.includes(t.agent))throw Error(`Unknown agent: "${t.agent}". Allowed: ${v.join(`, `)}`);if(!t.task||!t.task.trim())throw Error(`Task description is required`)}else if(c===`parallel`){if(!t.tasks||t.tasks.length<2)throw Error(`For parallel mode, tasks array is required with at least 2 items`);if(t.tasks.length>8)throw Error(`For parallel mode, tasks array may have at most 8 items (got ${t.tasks.length})`);for(let e of t.tasks){if(!v.includes(e.agent))throw Error(`Unknown agent: "${e.agent}". Allowed: ${v.join(`, `)}`);if(!e.task||!e.task.trim())throw Error(`Task description is required for all tasks`)}}else if(c===`chain`){if(!t.tasks||t.tasks.length<2)throw Error(`For chain mode, tasks array is required with at least 2 items`);for(let e of t.tasks){if(!v.includes(e.agent))throw Error(`Unknown agent: "${e.agent}". Allowed: ${v.join(`, `)}`);if(!e.task||!e.task.trim())throw Error(`Task description is required for all tasks`)}}try{let{getSubagentsService:e}=await import(`@gotgenes/pi-subagents`),s=e();if(typeof s.spawn!=`function`)throw Error(`Subagents service unavailable or incomplete`);async function l(e,t,n){let r=0,i=s.getRecord(e);for(;i&&!y.has(i.status)&&r<120;){if(a?.aborted)throw Error(`Maestria subagent call aborted`);await new Promise(e=>setTimeout(e,500)),i=s.getRecord(e),r++,n&&o?.({content:[{type:`text`,text:`${t} running... (${Math.round(r*500/1e3)}s)`}]})}if(i&&!y.has(i.status))throw Error(`Subagent ${e} timed out after 60000ms`);if(!i)throw Error(`Subagent ${e} was cleaned up before completion`);return i}if(c===`single`){let e=t.agent,a=t.task,o=s.spawn(e,a,{description:a.slice(0,80),foreground:!0,inheritContext:!0}),c=i(r,`orchestrator`,e,a);Object.assign(r,c),n.appendEntry(`maestria_state`,r);let u=await l(o,`Subagent ${e}`,!0);return{content:[{type:`text`,text:u.result??u.error??`No output.`}],details:{subagentId:o}}}if(c===`parallel`){let e=t.tasks;o?.({content:[{type:`text`,text:`Spawning ${e.length} parallel subagents...`}]});let a=[];for(let t of e){let e=s.spawn(t.agent,t.task,{description:t.task.slice(0,80),foreground:!0,inheritContext:!0});a.push(e);let n=i(r,`orchestrator`,t.agent,t.task);Object.assign(r,n)}n.appendEntry(`maestria_state`,r);let c=await Promise.all(a.map((t,n)=>l(t,`${e[n].agent} (${n+1}/${e.length})`,!1)));o?.({content:[{type:`text`,text:`All ${e.length} parallel subagents completed.`}]});let u=[`## Parallel Results (${e.length} tasks)\n`];for(let t=0;t<e.length;t++){let n=e[t],r=c[t],i=r.result??r.error??`No output.`;u.push(`### ${t+1}: ${n.agent}`),u.push(i)}return{content:[{type:`text`,text:u.join(`
|
|
9
9
|
|
|
10
10
|
`)}],details:{subagentIds:a}}}if(c===`chain`){let e=t.tasks,a=``;for(let t=0;t<e.length;t++){let c=e[t],u=c.task;t>0&&u.includes(`{previous}`)&&(u=u.replace(/\{previous\}/g,a));let d=s.spawn(c.agent,u,{description:u.slice(0,80),foreground:!0,inheritContext:!0}),f=i(r,`orchestrator`,c.agent,u);Object.assign(r,f),n.appendEntry(`maestria_state`,r),o?.({content:[{type:`text`,text:`Chain step ${t+1}/${e.length}: ${c.agent} running...`}]});let p=await l(d,`Chain step ${t+1}: ${c.agent}`,!0);a=p.result??p.error??`No output.`,t<e.length-1&&o?.({content:[{type:`text`,text:`Chain step ${t+1}/${e.length}: ${c.agent} completed. Moving to next step.`}]})}return{content:[{type:`text`,text:a}],details:{subagentId:`chain-completed`}}}throw Error(`Unknown dispatch mode`)}catch{let e=t.agent??t.tasks?.[0]?.agent??`unknown`,n=t.task??t.tasks?.map(e=>e.task).join(`; `)??`unknown`;return{content:[{type:`text`,text:[`## Subagent Handoff Required`,``,`**From:** orchestrator`,`**To:** ${e}`,`**Task:** ${n}`,``,`Subagent SDK not available. Please delegate this work manually.`].join(`
|
|
11
|
-
`)}]}}}}),n.events){let e=n.events.on(t.STARTED,e=>{let{id:t,type:i}=e;r.subagentStatus[t]={type:i,status:`running`,startedAt:Date.now()},s(n,r),n.events?.emit(_.SUBAGENT_STARTED,{id:t,type:i,timestamp:Date.now()})}),i=n.events.on(t.COMPLETED,e=>{let{id:t}=e,i=r.subagentStatus[t];i&&(i.status=`completed`,i.completedAt=Date.now()),s(n,r),n.events?.emit(_.SUBAGENT_COMPLETED,{id:t,type:i?.type,timestamp:Date.now()})}),o=n.events.on(t.FAILED,e=>{let{id:t,status:i}=e,a=r.subagentStatus[t];a&&(a.status=i??`error`,a.completedAt=Date.now()),s(n,r),n.events?.emit(_.SUBAGENT_FAILED,{id:t,type:a?.type,timestamp:Date.now()})}),c=n.events.on(t.STEERED,e=>{let{id:t}=e;r.subagentStatus[t]||(r.subagentStatus[t]={type:`unknown`,status:`running`,startedAt:Date.now()}),s(n,r)});a&&a.push(e,i,o,c)}}const x=[`read`,`grep`,`find`,`ls`,`glob`];function S(e,t){e.registerCommand(`orchestrate`,{description:`Start a full pipeline by delegating to the orchestrator`,handler:async(n,r)=>{if(!n.trim()){r.ui.notify(`Usage: /orchestrate <goal>
|
|
12
|
-
`),{deliverAs:`steer`})}}),e.registerCommand(`maestria-status`,{description:`Show current maestria session state including handoff history`,handler:async(e,n)=>{let r=l(t);if(!r){n.ui.notify(`No active maestria state to report.`);return}n.ui.setEditorText(r)}}),e.registerCommand(`review`,{description:`Enter review mode. Blocks destructive tools, sets read-only toolset.`,handler:async(n,r)=>{if(!n.trim()){r.ui.notify(`Usage: /review <target>
|
|
13
|
-
`),{deliverAs:`steer`})}}),e.registerCommand(`restore-model`,{description:`Restore the original model and tools that were active before review mode was entered.`,handler:async(n,r)=>{if(!t.reviewMode){r.ui.notify(`Not in review mode. Nothing to restore.`);return}let i=t.originalModel;await o(e,r,t),s(e,t),r.ui.notify(`Restored original model and tools.`),e.events?.emit(_.REVIEW_DEACTIVATED,{originalModel:i,timestamp:Date.now()})}}),e.registerCommand(`handoff`,{description:`Generate a structured handoff prompt for a new task context`,handler:async(n,r)=>{if(!n.trim()){r.ui.notify(`Usage: /handoff <goal>
|
|
11
|
+
`)}]}}}}),n.events){let e=n.events.on(t.STARTED,e=>{let{id:t,type:i}=e;r.subagentStatus[t]={type:i,status:`running`,startedAt:Date.now()},s(n,r),n.events?.emit(_.SUBAGENT_STARTED,{id:t,type:i,timestamp:Date.now()})}),i=n.events.on(t.COMPLETED,e=>{let{id:t}=e,i=r.subagentStatus[t];i&&(i.status=`completed`,i.completedAt=Date.now()),s(n,r),n.events?.emit(_.SUBAGENT_COMPLETED,{id:t,type:i?.type,timestamp:Date.now()})}),o=n.events.on(t.FAILED,e=>{let{id:t,status:i}=e,a=r.subagentStatus[t];a&&(a.status=i??`error`,a.completedAt=Date.now()),s(n,r),n.events?.emit(_.SUBAGENT_FAILED,{id:t,type:a?.type,timestamp:Date.now()})}),c=n.events.on(t.STEERED,e=>{let{id:t}=e;r.subagentStatus[t]||(r.subagentStatus[t]={type:`unknown`,status:`running`,startedAt:Date.now()}),s(n,r)});a&&a.push(e,i,o,c)}}const x=[`read`,`grep`,`find`,`ls`,`glob`];function S(e,t){e.registerCommand(`orchestrate`,{description:`Start a full pipeline by delegating to the orchestrator`,handler:async(n,r)=>{if(!n.trim()){r.ui.notify(`Usage: /orchestrate <goal> - describe what to accomplish`);return}if(t.reviewMode){let n=t.originalModel;await o(e,r,t),s(e,t),e.events?.emit(_.REVIEW_DEACTIVATED,{originalModel:n,source:`orchestrate`,timestamp:Date.now()})}e.sendUserMessage([`[ORCHESTRATE: ${n}]`,``,`Orchestrate the full maestria pipeline to: ${n}`,`Use the orchestrator prompt template for subagent delegation.`].join(`
|
|
12
|
+
`),{deliverAs:`steer`})}}),e.registerCommand(`maestria-status`,{description:`Show current maestria session state including handoff history`,handler:async(e,n)=>{let r=l(t);if(!r){n.ui.notify(`No active maestria state to report.`);return}n.ui.setEditorText(r)}}),e.registerCommand(`review`,{description:`Enter review mode. Blocks destructive tools, sets read-only toolset.`,handler:async(n,r)=>{if(!n.trim()){r.ui.notify(`Usage: /review <target> - describe what to review`);return}let i=r.model?.id??null,a=e.getActiveTools(),o={...t,reviewMode:!0,originalModel:i,originalTools:a};if(Object.assign(t,o),s(e,t),t.reviewModel){let n=await c(e,r,t);n&&(r.ui.notify(`Review mode: switched to ${n}`),e.events?.emit(_.REVIEW_ACTIVATED,{originalModel:t.originalModel,reviewModel:n,timestamp:Date.now()}))}e.setActiveTools(x),e.sendUserMessage([`[REVIEW: ${n}]`,``,`Review: ${n}. Use the reviewer prompt template.`,`Read only, no edits, report findings.`].join(`
|
|
13
|
+
`),{deliverAs:`steer`})}}),e.registerCommand(`restore-model`,{description:`Restore the original model and tools that were active before review mode was entered.`,handler:async(n,r)=>{if(!t.reviewMode){r.ui.notify(`Not in review mode. Nothing to restore.`);return}let i=t.originalModel;await o(e,r,t),s(e,t),r.ui.notify(`Restored original model and tools.`),e.events?.emit(_.REVIEW_DEACTIVATED,{originalModel:i,timestamp:Date.now()})}}),e.registerCommand(`handoff`,{description:`Generate a structured handoff prompt for a new task context`,handler:async(n,r)=>{if(!n.trim()){r.ui.notify(`Usage: /handoff <goal> - describe the task context for handoff`);return}let i=n.trim(),a=[`**Goal:** `+i,``,`**Context:**`,`- Mode: `+(t.mode??`none`),`- Active task: `+(t.activeTask||`none`),`- Specialists delegated: `+((t.specialistsDelegated?.length??0)>0?t.specialistsDelegated.join(`, `):`none`),`- Recent handoffs: `+(t.handoffHistory?.length??0)+` entries`,`- Files modified: `+((t.filesModified?.length??0)>0?t.filesModified.join(`, `):`none`),``,`**Requirements:**`,`(fill in specific requirements)`,``,`**Known problems:**`,(t.blockers?.length??0)>0?t.blockers.map(e=>`- `+e).join(`
|
|
14
14
|
`):`(no known problems documented)`,``,`**Success criteria:**`,`(fill in how to verify completion)`,``,`**Next step:**`,`(fill in what happens after this task)`,``,`---`,`Complete the fields above before sending.`].join(`
|
|
15
15
|
`);t.handoffHistory=[{from:`current`,to:`next`,task:i,timestamp:Date.now()},...t.handoffHistory??[]].slice(0,5),s(e,t),e.sendUserMessage(a,{deliverAs:`steer`})}}),e.registerCommand(`review-model`,{description:`Set which model to use when entering review mode`,handler:async(n,r)=>{if(!n.trim()){r.ui.notify(`Usage: /review-model <model-id>`);return}let i=n.trim(),a=r.modelRegistry.getAll();if(!a.find(e=>e.id===i)){r.ui.notify(`Unknown model: "${i}". Available: ${a.map(e=>e.id).join(`, `)}`);return}t.reviewModel=i,s(e,t),r.ui.notify(`Review model set to: ${i}`)}})}const C=[/rm\s+-rf\s+\//,/dd\s+if=/,/>\s*\/dev\/sd/,/chmod\s+-R\s+777\s+\//,/mkfs\.\w+/,/:(){ :\|:& };:/,/>\s*\/etc\/(passwd|shadow|sudoers)/,/\beval\b/,/wget\s+-O\s*-\s*\|\s*(bash|sh)/,/curl\s+.*\|\s*(bash|sh)/,/crontab\s+-r/];function w(e,t){e.on(`tool_call`,async(e,r)=>{if(!(!e||!e.toolName)){if(t.reviewMode&&(n(`edit`,e)||n(`write`,e)||n(`bash`,e)))return{block:!0,reason:`Review mode is active. Report findings, do not edit.`};if(n(`bash`,e)){let t=e.input.command;if(t){for(let e of C)if(e.test(t))return r.hasUI&&await r.ui.confirm(`Dangerous Pattern Detected`,`This command matches a dangerous pattern:\n${t}\nProceed?`)?void 0:{block:!0,reason:`Command matches dangerous pattern: ${e}`}}}}})}function T(e){let t=r(),n=[];m(e,t);let i=h(t);e.on(`before_agent_start`,(e,t)=>i(e,t)),e.on(`session_start`,(e,n)=>{if(!n.sessionManager?.getEntries)return;let r=n.sessionManager.getEntries();for(let e=r.length-1;e>=0;e--){let n=r[e];if(n.type===`custom`&&n.customType===`maestria_state`){let e=n.data;e&&typeof e==`object`&&Object.assign(t,e);break}}}),g(e,t),b(e,t,n),S(e,t),e.on(`session_shutdown`,()=>{for(let e of n)e();n.length=0}),w(e,t)}export{T as default};
|
|
16
16
|
//# sourceMappingURL=extension.mjs.map
|
package/dist/extension.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.mjs","names":[],"sources":["../src/state.ts","../src/modes.ts","../src/rules-content.ts","../src/rules.ts","../src/compaction.ts","../src/subagent.ts","../src/commands.ts","../src/tools.ts","../src/extension.ts"],"sourcesContent":["import type { ExtensionAPI, ExtensionCommandContext } from '@earendil-works/pi-coding-agent';\nimport type { ModeKeyword } from '@/modes.js';\n\nconst HANDOFF_HISTORY_CAP = 5;\nconst FILE_HISTORY_CAP = 10;\n\nexport interface HandoffEntry {\n from: string;\n to: string;\n task: string;\n timestamp: number;\n}\n\nexport interface SubagentStatusInfo {\n type: string;\n status: string;\n startedAt: number;\n completedAt?: number;\n}\n\nexport interface MaestriaState {\n mode: ModeKeyword | null;\n activeTask: string;\n completionPromise: string;\n specialistsDelegated: string[];\n blockers: string[];\n filesModified: string[];\n filesRead: string[];\n handoffHistory: HandoffEntry[];\n reviewMode: boolean;\n originalModel: string | null;\n originalTools: string[] | null;\n subagentStatus: Record<string, SubagentStatusInfo>;\n /** Model ID to use when entering review mode. Null = no preference. */\n reviewModel: string | null;\n}\n\nexport function createInitialState(): MaestriaState {\n return {\n mode: null,\n activeTask: '',\n completionPromise: '',\n specialistsDelegated: [],\n blockers: [],\n filesModified: [],\n filesRead: [],\n handoffHistory: [],\n reviewMode: false,\n originalModel: null,\n originalTools: null,\n subagentStatus: {},\n reviewModel: null,\n };\n}\n\nexport function recordHandoff(\n state: MaestriaState,\n from: string,\n to: string,\n task: string,\n): MaestriaState {\n const entry: HandoffEntry = { from, to, task, timestamp: Date.now() };\n const history = [entry, ...state.handoffHistory].slice(0, HANDOFF_HISTORY_CAP);\n return { ...state, handoffHistory: history };\n}\n\nfunction prependDeduped(files: string[], path: string, cap: number): string[] {\n const filtered = files.filter((f) => f !== path);\n return [path, ...filtered].slice(0, cap);\n}\n\nexport function recordFileModified(state: MaestriaState, path: string): MaestriaState {\n return { ...state, filesModified: prependDeduped(state.filesModified, path, FILE_HISTORY_CAP) };\n}\n\nexport function recordFileRead(state: MaestriaState, path: string): MaestriaState {\n return { ...state, filesRead: prependDeduped(state.filesRead, path, FILE_HISTORY_CAP) };\n}\n\nexport function recordSubagentStatus(\n state: MaestriaState,\n id: string,\n info: SubagentStatusInfo,\n): MaestriaState {\n return { ...state, subagentStatus: { ...state.subagentStatus, [id]: info } };\n}\n\nexport function setReviewMode(state: MaestriaState, active: boolean): MaestriaState {\n return {\n ...state,\n reviewMode: active,\n };\n}\n\n/**\n * Exit review mode and return the original model/tools for restoration.\n * Returns a new state (immutable) with review mode cleared and the\n * saved originals so the caller can pass them to pi.setModel/setActiveTools.\n */\nexport function exitReviewMode(state: MaestriaState): {\n state: MaestriaState;\n originalModel: string | null;\n originalTools: string[] | null;\n} {\n return {\n state: {\n ...state,\n reviewMode: false,\n originalModel: null,\n originalTools: null,\n },\n originalModel: state.originalModel,\n originalTools: state.originalTools,\n };\n}\n\n/**\n * Restore the original model and tools saved when review mode was entered.\n * Clears review mode from state and resets pi to the pre-review configuration.\n */\nexport async function restoreOriginalState(\n pi: ExtensionAPI,\n ctx: ExtensionCommandContext,\n state: MaestriaState,\n): Promise<void> {\n const { state: clearedState, originalModel, originalTools } = exitReviewMode(state);\n\n // Restore original tools first (makes full toolset available again)\n if (originalTools && originalTools.length > 0) {\n pi.setActiveTools(originalTools);\n }\n\n // Restore original model — best-effort, failures are non-fatal\n if (originalModel) {\n try {\n const models = ctx.modelRegistry.getAll();\n const model = models.find((m: { id: string }) => m.id === originalModel);\n if (model) {\n await pi.setModel(model);\n }\n } catch {\n // Best-effort: model restoration is non-critical\n }\n }\n\n // Clear review mode state\n Object.assign(state, clearedState);\n}\n\n/**\n * Persist the current state to the session by appending a custom entry.\n * Creates a shallow copy to ensure appendEntry sees the latest snapshot.\n */\nexport function persistState(pi: ExtensionAPI, state: MaestriaState): void {\n pi.appendEntry('maestria_state', { ...state });\n}\n\n/**\n * If a review model is configured, switch to it.\n * Returns the model ID switched to, or null if no switch occurred.\n */\nexport async function cycleToReviewModel(\n pi: ExtensionAPI,\n ctx: ExtensionCommandContext,\n state: MaestriaState,\n): Promise<string | null> {\n const reviewModel = state.reviewModel;\n if (!reviewModel) {\n return null;\n }\n try {\n const models = ctx.modelRegistry.getAll();\n const model = models.find((m) => m.id === reviewModel);\n if (model) {\n await pi.setModel(model);\n return reviewModel;\n } else {\n ctx.ui.notify(`Review model \"${reviewModel}\" not found in registry, staying on current.`);\n return null;\n }\n } catch {\n ctx.ui.notify(`Could not switch to review model \"${reviewModel}\", staying on current.`);\n return null;\n }\n}\n\nexport function renderMaestriaSummary(state: MaestriaState): string {\n const parts: string[] = [];\n\n if (state.mode) {\n parts.push(`**Mode:** ${state.mode.toUpperCase()}`);\n }\n\n if (state.reviewModel) {\n parts.push(`**Review Model:** ${state.reviewModel}`);\n }\n\n if (state.activeTask) {\n parts.push(`**Goal:** ${state.activeTask}`);\n }\n\n if (state.completionPromise) {\n parts.push(`**Completion Promise:** ${state.completionPromise}`);\n }\n\n if (state.specialistsDelegated.length > 0) {\n parts.push(`**Specialists Delegated:** ${state.specialistsDelegated.join(', ')}`);\n }\n\n if (state.blockers.length > 0) {\n parts.push('**Blockers:**');\n for (const blocker of state.blockers) {\n parts.push(`- ${blocker}`);\n }\n }\n\n const fileSubs: string[] = [];\n if (state.filesModified.length > 0) {\n fileSubs.push(`**Modified:** ${state.filesModified.join(', ')}`);\n }\n if (state.filesRead.length > 0) {\n fileSubs.push(`**Read:** ${state.filesRead.join(', ')}`);\n }\n if (fileSubs.length > 0) {\n parts.push(`**Files:** ${fileSubs.join('; ')}`);\n }\n\n if (state.handoffHistory.length > 0) {\n parts.push('**Recent Handoffs:**');\n for (const entry of state.handoffHistory) {\n parts.push(`- ${entry.from} → ${entry.to}: ${entry.task}`);\n }\n }\n\n return parts.join('\\n\\n');\n}\n\nexport { HANDOFF_HISTORY_CAP, FILE_HISTORY_CAP };\n","import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';\nimport type { MaestriaState } from '@/state.js';\nimport { persistState, restoreOriginalState } from '@/state.js';\n\nexport const MODE_KEYWORDS = ['fein', 'sonar', 'blitz'] as const;\nexport type ModeKeyword = (typeof MODE_KEYWORDS)[number];\n\nconst MODE_PROMPTS: Record<ModeKeyword, string> = {\n fein: [\n '## MODE: fein (Full Pipeline)',\n '',\n 'Execute the complete fein pipeline: mandatory reconnaissance',\n '(/adventurer) → design/plan (/architect or /planner) →',\n 'implementation (/builder) → review (/reviewer).',\n 'Do NOT skip any phase unless the user explicitly overrides',\n 'in the same turn.',\n ].join('\\n'),\n sonar: [\n '## MODE: sonar (Research Only)',\n '',\n 'Execute research only: /adventurer (recon) →',\n '/architect or /planner (design/plan) → STOP.',\n 'Do NOT implement anything. Return findings.',\n ].join('\\n'),\n blitz: [\n '## MODE: blitz (Fast Implementation)',\n '',\n 'Execute fast implementation via /builder directly.',\n 'Skip reconnaissance and design unless the codebase',\n 'is genuinely unknown. Skip review unless the result',\n 'needs validation.',\n ].join('\\n'),\n};\n\nconst MODE_MARKERS: Record<ModeKeyword, string> = {\n fein: '[MODE: fein]',\n sonar: '[MODE: sonar]',\n blitz: '[MODE: blitz]',\n};\n\nexport function getModePrompt(keyword: ModeKeyword): string {\n return `${MODE_MARKERS[keyword]}\\n\\n${MODE_PROMPTS[keyword]}`;\n}\n\nexport function installModeCommands(pi: ExtensionAPI, state: MaestriaState): void {\n for (const keyword of MODE_KEYWORDS) {\n pi.registerCommand(keyword, {\n description: `Set workflow mode to ${keyword}`,\n handler: async (args, ctx) => {\n // Exit review mode if active (restore original model/tools)\n if (state.reviewMode) {\n await restoreOriginalState(pi, ctx, state);\n }\n\n state.mode = keyword;\n persistState(pi, state);\n\n if (args.trim()) {\n const modeMessage = [\n getModePrompt(keyword),\n '',\n `Run the maestria default pipeline on: ${args}`,\n ].join('\\n');\n pi.sendUserMessage(modeMessage, { deliverAs: 'steer' });\n } else {\n ctx.ui.notify(`Mode set to ${keyword}. Describe what you'd like to work on.`);\n }\n },\n });\n }\n}\n","// This file is auto-generated by scripts/build-rules.ts\n// Do not edit manually — edit rules/AGENTS.md instead.\n\nexport const RULES_CONTENT: string = `<!-- Auto-generated from @maestria/core. Do not edit directly.\n Edit the canonical file at packages/core/agent-directives/ instead. -->\n\n# Global Agent Rules\n\n## Orchestration\n\n- **!!! Don't assume** — verify against actual code and docs. Guesses lead to bugs.\n- **!!! Read the docs first** — before writing code that touches unfamiliar tools, APIs, or migration paths, consult official documentation. Don't guess at API changes. This rule is scar tissue from repeated failures; treat it seriously.\n- **!!! Don't anthropomorphize effort** — You operate at machine scale. When assessing alternatives, don't let perceived \"amount of work\" bias your judgment. What feels like a lot of work to a human is routine iteration for you. Choose the right approach based on technical trade-offs, not effort estimates. Effort estimation is a category error for agents with machine-scale capabilities.\n\n- **Don't reference internal project names in explanations** — avoid leaking context outside the workspace.\n- **Write for humans** — Your output (reasoning, commit messages, documentation, status updates, questions) is read by people. Avoid AI-typical patterns: em dash overuse (—), inflated language, and promotional phrasing. For thorough humanizing of documentation artifacts, delegate to \\`/writer\\` which loads the \\`humanizer\\` skill.\n- **Use \\`opensrc\\` for repos; \\`webfetch\\` for pages** — when analyzing a GitHub/GitLab/BitBucket repo or any multi-file code reference, run \\`opensrc path <owner/repo>\\` (e.g. \\`opensrc path facebook/react\\`). It clones to a global cache and prints a path that \\`read\\`/\\`glob\\`/\\`grep\\` can use directly. For a single file, a specific page, or a known URL, \\`webfetch\\` is fine. Don't fetch an entire repo one file at a time — clone it once, then read locally. Use \\`--cwd\\` to resolve versions from the current project.\n- **Webfetch may hang — don't block on it** — if a \\`webfetch\\` request hangs after you've issued it, **proceed without the result** and surface the skip in your next user-facing message. Don't wait for a hung fetch to complete.\n- **Workflow modes** — keywords \\`fein\\` (full pipeline), \\`sonar\\` (research only), \\`blitz\\` (fast impl) activate per-turn workflow overrides. See the orchestrator prompt for details.\n- **Project \\`.maestria/\\`** — \\`.maestria/workflow.md\\` and \\`.maestria/rules.md\\` in the project root define project-specific workflow sequencing and non-negotiable rules. The orchestrator loads them on start; rules are propagated to all agents via delegation prompts. See the orchestrator prompt for details.\n- **CLI references — use local tools first** — for CLI references, run \\`bash --help\\` or load the relevant \\`skill\\` instead of reaching for \\`webfetch\\`. Local tools are faster and more reliable than fetching docs.\n- **Local files — read directly** — use \\`read\\`, \\`glob\\`, or \\`grep\\` (or \\`lsp\\` when available) for any file you have path access to. Don't \\`webfetch\\` a local file or a file in a checked-out repo.\n- **Tool hierarchy for external information:**\n 1. \\`webfetch\\` — fetch a specific known URL (for docs, pages)\n 2. \\`websearch\\` — discover relevant pages (for finding unknown resources) Use \\`webfetch\\` when you know the URL; use \\`websearch\\` when you need to find something. \\`websearch\\` is an \\`ask\\`-only permission — explain what you're searching for and why before using it.\n\n## Delegation\n\nWhen delegating work via \\`maestria_subagent()\\`, use only the 7 specialists below. **Never delegate to \\`explore\\` or \\`general\\`** — they are built-in agents, not part of the pipeline.\n\n| Agent | Role | When to Delegate |\n| --- | --- | --- |\n| \\`/adventurer\\` | Codebase reconnaissance, deep code understanding | Understanding unfamiliar code, tracing dependencies, gathering context before implementation |\n| \\`/architect\\` | Architecture decisions, trade-off analysis, ADRs | Choosing between approaches, technology evaluation |\n| \\`/builder\\` | Focused implementation, single-task execution | Feature work, bug fixes, test writing, refactors |\n| \\`/diagnose\\` | Systematic bug tracing, root cause analysis | Debugging regressions, production incidents, cryptic errors |\n| \\`/planner\\` | Implementation plans with phased milestones | Complex features requiring structured execution |\n| \\`/reviewer\\` | Code review with quality gates | Pre-merge review, security audit, post-implementation QA |\n| \\`/writer\\` | Documentation following structured patterns | READMEs, API docs, changelogs, ADR transcription |\n\n## Context Management\n\n- **Progressive disclosure** — start high-level, get specific as needed.\n- **State checkpointing** — periodically summarize what's done, what's in progress, what's next.\n- **Context pruning** — remove irrelevant context when no longer needed.\n- **Completion promises** — define success criteria before starting work. \"This task is complete when [verifiable conditions].\"\n\n## Commit Policy\n\n- **Only the orchestrator authorizes commits.** Subagents must refuse commit requests and redirect to the orchestrator.\n- **Builders executing commits** must follow the orchestrator's exact instructions (message, files, validation commands \\`check\\`/\\`test\\`). Flag it if the orchestrator's instructions skip the commit protocol.\n- **Plans must not include implicit commit steps.** Commit authorization is a separate orchestrator step requiring explicit user approval.\n\n## Pipeline Patterns\n\nThe orchestrator prompt defines the canonical Role-Based Pipeline with thinker/worker/verifier roles and dynamic sequencing.\n`;\n","import type {\n BeforeAgentStartEvent,\n BeforeAgentStartEventResult,\n ExtensionContext,\n} from '@earendil-works/pi-coding-agent';\nimport type { MaestriaState } from '@/state.js';\nimport { getModePrompt } from '@/modes.js';\nimport { RULES_CONTENT } from '@/rules-content.js';\n\nexport function createBeforeAgentStartHandler(state: MaestriaState) {\n return (\n event: BeforeAgentStartEvent,\n _ctx: ExtensionContext,\n ): BeforeAgentStartEventResult | void => {\n const parts: string[] = [RULES_CONTENT, '', event.systemPrompt];\n\n if (state.mode) {\n parts.push('', getModePrompt(state.mode));\n parts.push(\n '',\n `The user has set workflow mode to \"${state.mode}\". ` +\n 'Honor this mode throughout the session until changed via /command.',\n );\n }\n\n return { systemPrompt: parts.join('\\n') };\n };\n}\n","import type {\n ExtensionAPI,\n SessionBeforeCompactEvent,\n SessionBeforeTreeEvent,\n} from '@earendil-works/pi-coding-agent';\nimport type { MaestriaState } from '@/state.js';\nimport { renderMaestriaSummary } from '@/state.js';\n\nexport function installCompactionHandlers(pi: ExtensionAPI, state: MaestriaState): void {\n pi.on('session_before_compact', (event: SessionBeforeCompactEvent) => {\n return {\n compaction: {\n summary: renderMaestriaSummary(state),\n details: { ...state },\n firstKeptEntryId: event.preparation.firstKeptEntryId,\n tokensBefore: event.preparation.tokensBefore,\n },\n };\n });\n\n pi.on('session_before_tree', (event: SessionBeforeTreeEvent) => {\n if (event.preparation.userWantsSummary) {\n return {\n summary: {\n summary: renderMaestriaSummary(state),\n },\n };\n }\n return undefined;\n });\n}\n","import { Type } from 'typebox';\nimport type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { SUBAGENT_EVENTS } from '@gotgenes/pi-subagents';\nimport type { MaestriaState } from '@/state.js';\nimport { persistState, recordHandoff } from '@/state.js';\n\n/**\n * Maestria cross-extension event names.\n * Other Pi extensions can subscribe via `pi.events?.on(...)`.\n * Convention: `maestria:<domain>:<action>`\n */\nexport const MAESTRIA_EVENTS = {\n REVIEW_ACTIVATED: 'maestria:review:activated',\n REVIEW_DEACTIVATED: 'maestria:review:deactivated',\n SUBAGENT_STARTED: 'maestria:subagent:started',\n SUBAGENT_COMPLETED: 'maestria:subagent:completed',\n SUBAGENT_FAILED: 'maestria:subagent:failed',\n} as const;\n\nconst ALLOWED_AGENTS = [\n 'adventurer',\n 'architect',\n 'builder',\n 'diagnose',\n 'planner',\n 'reviewer',\n 'writer',\n] as const;\ntype AllowedAgent = (typeof ALLOWED_AGENTS)[number];\n\n// The 6-field handoff contract\nconst HANDOFF_FIELDS = [\n 'Goal',\n 'Context',\n 'Requirements',\n 'Known problems',\n 'Success criteria',\n 'Next step',\n] as const;\n\n/** Terminal subagent statuses — agent will produce no more updates. */\nconst TERMINAL_STATUSES = new Set(['completed', 'steered', 'aborted', 'stopped', 'error']);\n\n/** Maximum time to wait for a subagent to complete, in milliseconds. */\nexport const POLL_TIMEOUT_MS = 60_000;\n\n/** Interval between subagent status checks, in milliseconds. */\nexport const POLL_INTERVAL_MS = 500;\n\n/** Maximum number of tasks allowed in parallel dispatch. */\nexport const MAX_PARALLEL_TASKS = 8;\n\nexport function validateHandoff(handoff: string): { valid: boolean; errors: string[] } {\n const errors: string[] = [];\n for (const field of HANDOFF_FIELDS) {\n const regex = new RegExp(`\\\\*\\\\*${field}:\\\\*\\\\*[\\\\s\\\\S]*?\\\\S`, 'i');\n if (!regex.test(handoff)) {\n errors.push(`Missing or empty field: \"${field}\"`);\n }\n }\n return { valid: errors.length === 0, errors };\n}\n\nexport function installSubagentTool(\n pi: ExtensionAPI,\n state: MaestriaState,\n cleanups?: Array<() => void>,\n): void {\n pi.registerTool({\n name: 'maestria_subagent',\n label: 'Maestria Subagent',\n description: 'Dispatch a task to a @maestria specialist subagent',\n promptSnippet:\n 'Delegate tasks to @maestria specialist subagents (adventurer, architect, builder, planner, diagnose, reviewer, writer)',\n promptGuidelines: [\n 'Use maestria_subagent when a task MUST be delegated to a specialist subagent rather than handled directly. Each specialist has focused capabilities: adventurer (recon), architect (design), builder (impl), planner (planning), diagnose (bugs), reviewer (QA), writer (docs).',\n ],\n prepareArguments(args: unknown) {\n return args;\n },\n parameters: Type.Object({\n agent: Type.Optional(Type.String({ description: 'Specialist agent name' })),\n task: Type.Optional(Type.String({ description: 'Task description for the subagent' })),\n tasks: Type.Optional(\n Type.Array(\n Type.Object({\n agent: Type.String(),\n task: Type.String(),\n }),\n { description: 'Array of task objects for parallel or chain dispatch' },\n ),\n ),\n mode: Type.Optional(\n Type.Union([Type.Literal('parallel'), Type.Literal('chain'), Type.Literal('single')]),\n ),\n }),\n async execute(\n _toolCallId: string,\n params: {\n agent?: string;\n task?: string;\n tasks?: Array<{ agent: string; task: string }>;\n mode?: 'parallel' | 'chain' | 'single';\n },\n signal: AbortSignal | undefined,\n onUpdate: ((result: { content: Array<{ type: string; text: string }> }) => void) | undefined,\n _ctx: ExtensionContext,\n ) {\n // Block subagent dispatch when in review mode\n if (state.reviewMode) {\n return {\n content: [\n {\n type: 'text' as const,\n text: 'Subagent dispatch is not available during review mode. Use /restore-model to exit review mode first.',\n },\n ],\n };\n }\n\n // Determine dispatch mode (default to 'single' for backward compat)\n const mode = params.mode ?? 'single';\n\n // Validate parameters based on mode\n if (mode === 'single') {\n // Backward-compatible validation — must match original error messages exactly\n if (!ALLOWED_AGENTS.includes(params.agent as AllowedAgent)) {\n throw new Error(\n `Unknown agent: \"${params.agent}\". Allowed: ${ALLOWED_AGENTS.join(', ')}`,\n );\n }\n if (!params.task || !params.task.trim()) {\n throw new Error('Task description is required');\n }\n } else if (mode === 'parallel') {\n if (!params.tasks || params.tasks.length < 2) {\n throw new Error(`For parallel mode, tasks array is required with at least 2 items`);\n }\n if (params.tasks.length > MAX_PARALLEL_TASKS) {\n throw new Error(\n `For parallel mode, tasks array may have at most ${MAX_PARALLEL_TASKS} items (got ${params.tasks.length})`,\n );\n }\n for (const t of params.tasks) {\n if (!ALLOWED_AGENTS.includes(t.agent as AllowedAgent)) {\n throw new Error(`Unknown agent: \"${t.agent}\". Allowed: ${ALLOWED_AGENTS.join(', ')}`);\n }\n if (!t.task || !t.task.trim()) {\n throw new Error('Task description is required for all tasks');\n }\n }\n } else if (mode === 'chain') {\n if (!params.tasks || params.tasks.length < 2) {\n throw new Error('For chain mode, tasks array is required with at least 2 items');\n }\n for (const t of params.tasks) {\n if (!ALLOWED_AGENTS.includes(t.agent as AllowedAgent)) {\n throw new Error(`Unknown agent: \"${t.agent}\". Allowed: ${ALLOWED_AGENTS.join(', ')}`);\n }\n if (!t.task || !t.task.trim()) {\n throw new Error('Task description is required for all tasks');\n }\n }\n }\n\n // Attempt to dispatch via @gotgenes/pi-subagents; fallback gracefully\n try {\n const { getSubagentsService } = await import('@gotgenes/pi-subagents');\n const service = getSubagentsService()!;\n if (typeof service.spawn !== 'function') {\n throw new Error('Subagents service unavailable or incomplete');\n }\n\n // Helper: poll a single subagent until terminal or timeout\n async function pollSubagent(\n id: string,\n label: string,\n sendUpdates: boolean,\n ): Promise<{ status: string; result?: string; error?: string }> {\n const maxPolls = POLL_TIMEOUT_MS / POLL_INTERVAL_MS;\n let polls = 0;\n let record = service.getRecord(id);\n while (record && !TERMINAL_STATUSES.has(record.status) && polls < maxPolls) {\n if (signal?.aborted) throw new Error('Maestria subagent call aborted');\n await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));\n record = service.getRecord(id);\n polls++;\n if (sendUpdates) {\n onUpdate?.({\n content: [\n {\n type: 'text' as const,\n text: `${label} running... (${Math.round((polls * POLL_INTERVAL_MS) / 1000)}s)`,\n },\n ],\n });\n }\n }\n if (record && !TERMINAL_STATUSES.has(record.status)) {\n throw new Error(`Subagent ${id} timed out after ${POLL_TIMEOUT_MS}ms`);\n }\n if (!record) {\n throw new Error(`Subagent ${id} was cleaned up before completion`);\n }\n return record;\n }\n\n // --- SINGLE MODE ---\n if (mode === 'single') {\n const agent = params.agent!;\n const task = params.task!;\n\n // Spawn in foreground — returns subagent ID synchronously\n const id = service.spawn(agent, task, {\n description: task.slice(0, 80),\n foreground: true,\n inheritContext: true,\n });\n\n // Record handoff in state and persist (only after spawn succeeds)\n const updatedState = recordHandoff(state, 'orchestrator', agent, task);\n Object.assign(state, updatedState);\n pi.appendEntry('maestria_state', state);\n\n // Poll for completion\n const record = await pollSubagent(id, `Subagent ${agent}`, true);\n\n const resultText = record.result ?? record.error ?? 'No output.';\n\n return {\n content: [{ type: 'text' as const, text: resultText }],\n details: { subagentId: id },\n };\n }\n\n // --- PARALLEL MODE ---\n if (mode === 'parallel') {\n const taskList = params.tasks!;\n\n onUpdate?.({\n content: [\n { type: 'text' as const, text: `Spawning ${taskList.length} parallel subagents...` },\n ],\n });\n\n // Spawn all tasks\n const spawnedIds: string[] = [];\n for (const t of taskList) {\n const id = service.spawn(t.agent, t.task, {\n description: t.task.slice(0, 80),\n foreground: true,\n inheritContext: true,\n });\n spawnedIds.push(id);\n\n // Record each handoff\n const updatedState = recordHandoff(state, 'orchestrator', t.agent, t.task);\n Object.assign(state, updatedState);\n }\n pi.appendEntry('maestria_state', state);\n\n // Poll all concurrently\n const records = await Promise.all(\n spawnedIds.map((id, i) =>\n pollSubagent(id, `${taskList[i].agent} (${i + 1}/${taskList.length})`, false),\n ),\n );\n\n onUpdate?.({\n content: [\n {\n type: 'text' as const,\n text: `All ${taskList.length} parallel subagents completed.`,\n },\n ],\n });\n\n // Aggregate results\n const parts = [`## Parallel Results (${taskList.length} tasks)\\n`];\n for (let i = 0; i < taskList.length; i++) {\n const t = taskList[i];\n const rec = records[i];\n const resultText = rec.result ?? rec.error ?? 'No output.';\n parts.push(`### ${i + 1}: ${t.agent}`);\n parts.push(resultText);\n }\n\n return {\n content: [{ type: 'text' as const, text: parts.join('\\n\\n') }],\n details: { subagentIds: spawnedIds },\n };\n }\n\n // --- CHAIN MODE ---\n if (mode === 'chain') {\n const taskList = params.tasks!;\n let previousResult = '';\n\n for (let i = 0; i < taskList.length; i++) {\n const t = taskList[i];\n let taskText = t.task;\n\n // Substitute {previous} placeholder with previous result\n if (i > 0 && taskText.includes('{previous}')) {\n taskText = taskText.replace(/\\{previous\\}/g, previousResult);\n }\n\n const id = service.spawn(t.agent, taskText, {\n description: taskText.slice(0, 80),\n foreground: true,\n inheritContext: true,\n });\n\n // Record handoff\n const updatedState = recordHandoff(state, 'orchestrator', t.agent, taskText);\n Object.assign(state, updatedState);\n pi.appendEntry('maestria_state', state);\n\n onUpdate?.({\n content: [\n {\n type: 'text' as const,\n text: `Chain step ${i + 1}/${taskList.length}: ${t.agent} running...`,\n },\n ],\n });\n\n // Poll for completion\n const record = await pollSubagent(id, `Chain step ${i + 1}: ${t.agent}`, true);\n\n previousResult = record.result ?? record.error ?? 'No output.';\n\n if (i < taskList.length - 1) {\n onUpdate?.({\n content: [\n {\n type: 'text' as const,\n text: `Chain step ${i + 1}/${taskList.length}: ${t.agent} completed. Moving to next step.`,\n },\n ],\n });\n }\n }\n\n return {\n content: [{ type: 'text' as const, text: previousResult }],\n details: { subagentId: 'chain-completed' },\n };\n }\n\n // Should not reach here — all modes are handled above\n throw new Error('Unknown dispatch mode');\n } catch {\n // Return handoff payload as structured text when SDK unavailable\n const agentName = params.agent ?? params.tasks?.[0]?.agent ?? 'unknown';\n const taskDesc = params.task ?? params.tasks?.map((t) => t.task).join('; ') ?? 'unknown';\n const handoffInfo = [\n `## Subagent Handoff Required`,\n ``,\n `**From:** orchestrator`,\n `**To:** ${agentName}`,\n `**Task:** ${taskDesc}`,\n ``,\n `Subagent SDK not available. Please delegate this work manually.`,\n ].join('\\n');\n\n return {\n content: [{ type: 'text' as const, text: handoffInfo }],\n };\n }\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any); // TypeBox inferred types don't match ToolDefinition exactly\n\n // Subscribe to subagent lifecycle events for accurate state tracking.\n // These subscriptions are set up once at extension init, not on every tool call.\n // pi.events is the shared EventBus — distinct from pi.on() lifecycle hooks.\n if (pi.events) {\n const unsubStarted = pi.events.on(SUBAGENT_EVENTS.STARTED, (data: unknown) => {\n const { id, type } = data as { id: string; type: string };\n state.subagentStatus[id] = { type, status: 'running', startedAt: Date.now() };\n persistState(pi, state);\n pi.events?.emit(MAESTRIA_EVENTS.SUBAGENT_STARTED, {\n id,\n type,\n timestamp: Date.now(),\n });\n });\n\n const unsubCompleted = pi.events.on(SUBAGENT_EVENTS.COMPLETED, (data: unknown) => {\n const { id } = data as { id: string };\n const existing = state.subagentStatus[id];\n if (existing) {\n existing.status = 'completed';\n existing.completedAt = Date.now();\n }\n persistState(pi, state);\n pi.events?.emit(MAESTRIA_EVENTS.SUBAGENT_COMPLETED, {\n id,\n type: existing?.type,\n timestamp: Date.now(),\n });\n });\n\n const unsubFailed = pi.events.on(SUBAGENT_EVENTS.FAILED, (data: unknown) => {\n const { id, status } = data as { id: string; status: string };\n const existing = state.subagentStatus[id];\n if (existing) {\n existing.status = status ?? 'error';\n existing.completedAt = Date.now();\n }\n persistState(pi, state);\n pi.events?.emit(MAESTRIA_EVENTS.SUBAGENT_FAILED, {\n id,\n type: existing?.type,\n timestamp: Date.now(),\n });\n });\n\n const unsubSteered = pi.events.on(SUBAGENT_EVENTS.STEERED, (data: unknown) => {\n // Steering is informational — no status transition, but ensure\n // the agent is tracked as running if it wasn't already observed.\n const { id } = data as { id: string };\n if (!state.subagentStatus[id]) {\n state.subagentStatus[id] = { type: 'unknown', status: 'running', startedAt: Date.now() };\n }\n persistState(pi, state);\n });\n\n if (cleanups) {\n cleanups.push(unsubStarted, unsubCompleted, unsubFailed, unsubSteered);\n }\n }\n}\n","import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';\nimport type { MaestriaState } from '@/state.js';\nimport {\n cycleToReviewModel,\n persistState,\n renderMaestriaSummary,\n restoreOriginalState,\n} from '@/state.js';\nimport { MAESTRIA_EVENTS } from '@/subagent.js';\n\n/**\n * Read-only tools that let a reviewer inspect code without making changes.\n *\n * - `read`, `grep`, `find`, `ls`, `glob` — all non-destructive.\n * - Excluded: `bash`, `edit`, `write` — these can modify the filesystem.\n *\n * `glob` is included for file pattern matching even though it's not a\n * built-in Pi tool — extensions may register it, and including it is a no-op\n * if absent.\n */\nconst READ_ONLY_TOOLS = ['read', 'grep', 'find', 'ls', 'glob'];\n\nexport function installCommands(pi: ExtensionAPI, state: MaestriaState): void {\n pi.registerCommand('orchestrate', {\n description: 'Start a full pipeline by delegating to the orchestrator',\n handler: async (args: string, ctx) => {\n if (!args.trim()) {\n ctx.ui.notify('Usage: /orchestrate <goal> — describe what to accomplish');\n return;\n }\n\n // Exit review mode if active (restore original model/tools)\n if (state.reviewMode) {\n const prevOriginalModel = state.originalModel;\n await restoreOriginalState(pi, ctx, state);\n persistState(pi, state);\n pi.events?.emit(MAESTRIA_EVENTS.REVIEW_DEACTIVATED, {\n originalModel: prevOriginalModel,\n source: 'orchestrate',\n timestamp: Date.now(),\n });\n }\n\n pi.sendUserMessage(\n [\n `[ORCHESTRATE: ${args}]`,\n '',\n `Orchestrate the full maestria pipeline to: ${args}`,\n 'Use the orchestrator prompt template for subagent delegation.',\n ].join('\\n'),\n { deliverAs: 'steer' },\n );\n },\n });\n\n pi.registerCommand('maestria-status', {\n description: 'Show current maestria session state including handoff history',\n handler: async (_args: string, ctx) => {\n const summary = renderMaestriaSummary(state);\n if (!summary) {\n ctx.ui.notify('No active maestria state to report.');\n return;\n }\n ctx.ui.setEditorText(summary);\n },\n });\n\n pi.registerCommand('review', {\n description: 'Enter review mode. Blocks destructive tools, sets read-only toolset.',\n handler: async (args: string, ctx) => {\n if (!args.trim()) {\n ctx.ui.notify('Usage: /review <target> — describe what to review');\n return;\n }\n\n // 1. Save current model and tools for later restoration\n const currentModelId = ctx.model?.id ?? null;\n const currentTools = pi.getActiveTools();\n\n // 2. Update state: mark review mode, store originals\n const updatedState: MaestriaState = {\n ...state,\n reviewMode: true,\n originalModel: currentModelId,\n originalTools: currentTools,\n };\n Object.assign(state, updatedState);\n persistState(pi, state);\n\n // 3. Switch to review model if configured\n if (state.reviewModel) {\n const switched = await cycleToReviewModel(pi, ctx, state);\n if (switched) {\n ctx.ui.notify(`Review mode: switched to ${switched}`);\n pi.events?.emit(MAESTRIA_EVENTS.REVIEW_ACTIVATED, {\n originalModel: state.originalModel,\n reviewModel: switched,\n timestamp: Date.now(),\n });\n }\n }\n\n // 4. Restrict to read-only tools\n pi.setActiveTools(READ_ONLY_TOOLS);\n\n pi.sendUserMessage(\n [\n `[REVIEW: ${args}]`,\n '',\n `Review: ${args}. Use the reviewer prompt template.`,\n 'Read only, no edits, report findings.',\n ].join('\\n'),\n { deliverAs: 'steer' },\n );\n },\n });\n\n pi.registerCommand('restore-model', {\n description:\n 'Restore the original model and tools that were active before review mode was entered.',\n handler: async (_args: string, ctx) => {\n if (!state.reviewMode) {\n ctx.ui.notify('Not in review mode. Nothing to restore.');\n return;\n }\n const prevOriginalModel = state.originalModel;\n await restoreOriginalState(pi, ctx, state);\n persistState(pi, state);\n ctx.ui.notify('Restored original model and tools.');\n pi.events?.emit(MAESTRIA_EVENTS.REVIEW_DEACTIVATED, {\n originalModel: prevOriginalModel,\n timestamp: Date.now(),\n });\n },\n });\n\n pi.registerCommand('handoff', {\n description: 'Generate a structured handoff prompt for a new task context',\n handler: async (args: string, ctx) => {\n if (!args.trim()) {\n ctx.ui.notify('Usage: /handoff <goal> — describe the task context for handoff');\n return;\n }\n\n // Build a structured handoff document with 6 fields\n const goal = args.trim();\n const handoffPrompt = [\n '**Goal:** ' + goal,\n '',\n '**Context:**',\n '- Mode: ' + (state.mode ?? 'none'),\n '- Active task: ' + (state.activeTask || 'none'),\n '- Specialists delegated: ' +\n ((state.specialistsDelegated?.length ?? 0) > 0\n ? state.specialistsDelegated.join(', ')\n : 'none'),\n '- Recent handoffs: ' + (state.handoffHistory?.length ?? 0) + ' entries',\n '- Files modified: ' +\n ((state.filesModified?.length ?? 0) > 0 ? state.filesModified.join(', ') : 'none'),\n '',\n '**Requirements:**',\n '(fill in specific requirements)',\n '',\n '**Known problems:**',\n (state.blockers?.length ?? 0) > 0\n ? state.blockers.map((b: string) => '- ' + b).join('\\n')\n : '(no known problems documented)',\n '',\n '**Success criteria:**',\n '(fill in how to verify completion)',\n '',\n '**Next step:**',\n '(fill in what happens after this task)',\n '',\n '---',\n 'Complete the fields above before sending.',\n ].join('\\n');\n\n // Record in state\n state.handoffHistory = [\n { from: 'current', to: 'next', task: goal, timestamp: Date.now() },\n ...(state.handoffHistory ?? []),\n ].slice(0, 5);\n\n // Persist state\n persistState(pi, state);\n\n // Send as user message with steer delivery\n pi.sendUserMessage(handoffPrompt, { deliverAs: 'steer' });\n },\n });\n\n pi.registerCommand('review-model', {\n description: 'Set which model to use when entering review mode',\n handler: async (args: string, ctx) => {\n if (!args.trim()) {\n ctx.ui.notify('Usage: /review-model <model-id>');\n return;\n }\n const modelId = args.trim();\n const models = ctx.modelRegistry.getAll();\n const model = models.find((m) => m.id === modelId);\n if (!model) {\n ctx.ui.notify(\n `Unknown model: \"${modelId}\". Available: ${models.map((m) => m.id).join(', ')}`,\n );\n return;\n }\n state.reviewModel = modelId;\n persistState(pi, state);\n ctx.ui.notify(`Review model set to: ${modelId}`);\n },\n });\n}\n","import {\n isToolCallEventType,\n type ExtensionAPI,\n type ToolCallEvent,\n type ExtensionContext,\n} from '@earendil-works/pi-coding-agent';\nimport type { MaestriaState } from '@/state.js';\n\nconst DANGEROUS_PATTERNS = [\n /rm\\s+-rf\\s+\\//,\n /dd\\s+if=/,\n />\\s*\\/dev\\/sd/,\n /chmod\\s+-R\\s+777\\s+\\//,\n /mkfs\\.\\w+/,\n /:(){ :\\|:& };:/, // fork bomb\n />\\s*\\/etc\\/(passwd|shadow|sudoers)/,\n /\\beval\\b/,\n /wget\\s+-O\\s*-\\s*\\|\\s*(bash|sh)/,\n /curl\\s+.*\\|\\s*(bash|sh)/,\n /crontab\\s+-r/,\n];\n\nexport function installToolInterceptors(pi: ExtensionAPI, state: MaestriaState): void {\n pi.on('tool_call', async (event: ToolCallEvent, ctx: ExtensionContext) => {\n if (!event || !event.toolName) return;\n\n // Block destructive tools in review mode\n if (state.reviewMode) {\n if (\n isToolCallEventType('edit', event) ||\n isToolCallEventType('write', event) ||\n isToolCallEventType('bash', event)\n ) {\n return {\n block: true,\n reason: 'Review mode is active. Report findings, do not edit.',\n };\n }\n }\n\n // Block dangerous bash patterns regardless of mode\n if (isToolCallEventType('bash', event)) {\n const command = event.input.command;\n if (command) {\n for (const pattern of DANGEROUS_PATTERNS) {\n if (pattern.test(command)) {\n if (ctx.hasUI) {\n const confirmed = await ctx.ui.confirm(\n 'Dangerous Pattern Detected',\n `This command matches a dangerous pattern:\\n${command}\\nProceed?`,\n );\n if (confirmed) return undefined;\n }\n return {\n block: true,\n reason: `Command matches dangerous pattern: ${pattern}`,\n };\n }\n }\n }\n }\n\n return undefined; // allow\n });\n}\n","import type { ExtensionAPI, SessionStartEvent } from '@earendil-works/pi-coding-agent';\nimport { createInitialState } from '@/state.js';\nimport { installModeCommands } from '@/modes.js';\nimport { createBeforeAgentStartHandler } from '@/rules.js';\nimport { installCompactionHandlers } from '@/compaction.js';\nimport { installSubagentTool } from '@/subagent.js';\nimport { installCommands } from '@/commands.js';\nimport { installToolInterceptors } from '@/tools.js';\n\nexport default function (pi: ExtensionAPI): void {\n const state = createInitialState();\n const cleanups: Array<() => void> = [];\n\n // Install mode commands: /fein, /sonar, /blitz\n installModeCommands(pi, state);\n\n // Inject mode prompts when a mode is active\n const handleBeforeAgentStart = createBeforeAgentStartHandler(state);\n\n pi.on('before_agent_start', (event, ctx) => {\n return handleBeforeAgentStart(event, ctx);\n });\n\n // Restore persisted state on session start (reload/resume/fork)\n pi.on('session_start', (_event: SessionStartEvent, ctx) => {\n if (!ctx.sessionManager?.getEntries) return;\n const entries = ctx.sessionManager.getEntries();\n // Walk from newest to oldest, find the last persisted maestria_state entry\n for (let i = entries.length - 1; i >= 0; i--) {\n const entry = entries[i];\n if (entry.type === 'custom' && entry.customType === 'maestria_state') {\n const data = entry.data;\n if (data && typeof data === 'object') {\n Object.assign(state, data);\n }\n break;\n }\n }\n });\n\n // Install compaction preservation handlers\n installCompactionHandlers(pi, state);\n\n // Install orchestration hooks: subagent tool and commands\n installSubagentTool(pi, state, cleanups);\n installCommands(pi, state);\n\n // Cleanup subscriptions on shutdown\n pi.on('session_shutdown', () => {\n for (const cleanup of cleanups) cleanup();\n cleanups.length = 0;\n });\n\n // Install tool call interceptors for review mode and dangerous patterns\n installToolInterceptors(pi, state);\n}\n"],"mappings":"8JAqCA,SAAgB,GAAoC,CAClD,MAAO,CACL,KAAM,KACN,WAAY,GACZ,kBAAmB,GACnB,qBAAsB,CAAC,EACvB,SAAU,CAAC,EACX,cAAe,CAAC,EAChB,UAAW,CAAC,EACZ,eAAgB,CAAC,EACjB,WAAY,GACZ,cAAe,KACf,cAAe,KACf,eAAgB,CAAC,EACjB,YAAa,IACf,CACF,CAEA,SAAgB,EACd,EACA,EACA,EACA,EACe,CAEf,IAAM,EAAU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EAAM,aAAe,iBAAkB,CACpE,IAAM,EAAO,EAAM,KACf,GAAQ,OAAO,GAAS,UAC1B,OAAO,OAAO,EAAO,CAAI,EAE3B,KACF,CACF,CACF,CAAC,EAGD,EAA0B,EAAI,CAAK,EAGnC,EAAoB,EAAI,EAAO,CAAQ,EACvC,EAAgB,EAAI,CAAK,EAGzB,EAAG,GAAG,uBAA0B,CAC9B,IAAK,IAAM,KAAW,EAAU,EAAQ,EACxC,EAAS,OAAS,CACpB,CAAC,EAGD,EAAwB,EAAI,CAAK,CACnC"}
|
|
1
|
+
{"version":3,"file":"extension.mjs","names":[],"sources":["../src/state.ts","../src/modes.ts","../src/rules-content.ts","../src/rules.ts","../src/compaction.ts","../src/subagent.ts","../src/commands.ts","../src/tools.ts","../src/extension.ts"],"sourcesContent":["import type { ExtensionAPI, ExtensionCommandContext } from '@earendil-works/pi-coding-agent';\nimport type { ModeKeyword } from '@/modes.js';\n\nconst HANDOFF_HISTORY_CAP = 5;\nconst FILE_HISTORY_CAP = 10;\n\nexport interface HandoffEntry {\n from: string;\n to: string;\n task: string;\n timestamp: number;\n}\n\nexport interface SubagentStatusInfo {\n type: string;\n status: string;\n startedAt: number;\n completedAt?: number;\n}\n\nexport interface MaestriaState {\n mode: ModeKeyword | null;\n activeTask: string;\n completionPromise: string;\n specialistsDelegated: string[];\n blockers: string[];\n filesModified: string[];\n filesRead: string[];\n handoffHistory: HandoffEntry[];\n reviewMode: boolean;\n originalModel: string | null;\n originalTools: string[] | null;\n subagentStatus: Record<string, SubagentStatusInfo>;\n /** Model ID to use when entering review mode. Null = no preference. */\n reviewModel: string | null;\n}\n\nexport function createInitialState(): MaestriaState {\n return {\n mode: null,\n activeTask: '',\n completionPromise: '',\n specialistsDelegated: [],\n blockers: [],\n filesModified: [],\n filesRead: [],\n handoffHistory: [],\n reviewMode: false,\n originalModel: null,\n originalTools: null,\n subagentStatus: {},\n reviewModel: null,\n };\n}\n\nexport function recordHandoff(\n state: MaestriaState,\n from: string,\n to: string,\n task: string,\n): MaestriaState {\n const entry: HandoffEntry = { from, to, task, timestamp: Date.now() };\n const history = [entry, ...state.handoffHistory].slice(0, HANDOFF_HISTORY_CAP);\n return { ...state, handoffHistory: history };\n}\n\nfunction prependDeduped(files: string[], path: string, cap: number): string[] {\n const filtered = files.filter((f) => f !== path);\n return [path, ...filtered].slice(0, cap);\n}\n\nexport function recordFileModified(state: MaestriaState, path: string): MaestriaState {\n return { ...state, filesModified: prependDeduped(state.filesModified, path, FILE_HISTORY_CAP) };\n}\n\nexport function recordFileRead(state: MaestriaState, path: string): MaestriaState {\n return { ...state, filesRead: prependDeduped(state.filesRead, path, FILE_HISTORY_CAP) };\n}\n\nexport function recordSubagentStatus(\n state: MaestriaState,\n id: string,\n info: SubagentStatusInfo,\n): MaestriaState {\n return { ...state, subagentStatus: { ...state.subagentStatus, [id]: info } };\n}\n\nexport function setReviewMode(state: MaestriaState, active: boolean): MaestriaState {\n return {\n ...state,\n reviewMode: active,\n };\n}\n\n/**\n * Exit review mode and return the original model/tools for restoration.\n * Returns a new state (immutable) with review mode cleared and the\n * saved originals so the caller can pass them to pi.setModel/setActiveTools.\n */\nexport function exitReviewMode(state: MaestriaState): {\n state: MaestriaState;\n originalModel: string | null;\n originalTools: string[] | null;\n} {\n return {\n state: {\n ...state,\n reviewMode: false,\n originalModel: null,\n originalTools: null,\n },\n originalModel: state.originalModel,\n originalTools: state.originalTools,\n };\n}\n\n/**\n * Restore the original model and tools saved when review mode was entered.\n * Clears review mode from state and resets pi to the pre-review configuration.\n */\nexport async function restoreOriginalState(\n pi: ExtensionAPI,\n ctx: ExtensionCommandContext,\n state: MaestriaState,\n): Promise<void> {\n const { state: clearedState, originalModel, originalTools } = exitReviewMode(state);\n\n // Restore original tools first (makes full toolset available again)\n if (originalTools && originalTools.length > 0) {\n pi.setActiveTools(originalTools);\n }\n\n // Restore original model - best-effort, failures are non-fatal\n if (originalModel) {\n try {\n const models = ctx.modelRegistry.getAll();\n const model = models.find((m: { id: string }) => m.id === originalModel);\n if (model) {\n await pi.setModel(model);\n }\n } catch {\n // Best-effort: model restoration is non-critical\n }\n }\n\n // Clear review mode state\n Object.assign(state, clearedState);\n}\n\n/**\n * Persist the current state to the session by appending a custom entry.\n * Creates a shallow copy to ensure appendEntry sees the latest snapshot.\n */\nexport function persistState(pi: ExtensionAPI, state: MaestriaState): void {\n pi.appendEntry('maestria_state', { ...state });\n}\n\n/**\n * If a review model is configured, switch to it.\n * Returns the model ID switched to, or null if no switch occurred.\n */\nexport async function cycleToReviewModel(\n pi: ExtensionAPI,\n ctx: ExtensionCommandContext,\n state: MaestriaState,\n): Promise<string | null> {\n const reviewModel = state.reviewModel;\n if (!reviewModel) {\n return null;\n }\n try {\n const models = ctx.modelRegistry.getAll();\n const model = models.find((m) => m.id === reviewModel);\n if (model) {\n await pi.setModel(model);\n return reviewModel;\n } else {\n ctx.ui.notify(`Review model \"${reviewModel}\" not found in registry, staying on current.`);\n return null;\n }\n } catch {\n ctx.ui.notify(`Could not switch to review model \"${reviewModel}\", staying on current.`);\n return null;\n }\n}\n\nexport function renderMaestriaSummary(state: MaestriaState): string {\n const parts: string[] = [];\n\n if (state.mode) {\n parts.push(`**Mode:** ${state.mode.toUpperCase()}`);\n }\n\n if (state.reviewModel) {\n parts.push(`**Review Model:** ${state.reviewModel}`);\n }\n\n if (state.activeTask) {\n parts.push(`**Goal:** ${state.activeTask}`);\n }\n\n if (state.completionPromise) {\n parts.push(`**Completion Promise:** ${state.completionPromise}`);\n }\n\n if (state.specialistsDelegated.length > 0) {\n parts.push(`**Specialists Delegated:** ${state.specialistsDelegated.join(', ')}`);\n }\n\n if (state.blockers.length > 0) {\n parts.push('**Blockers:**');\n for (const blocker of state.blockers) {\n parts.push(`- ${blocker}`);\n }\n }\n\n const fileSubs: string[] = [];\n if (state.filesModified.length > 0) {\n fileSubs.push(`**Modified:** ${state.filesModified.join(', ')}`);\n }\n if (state.filesRead.length > 0) {\n fileSubs.push(`**Read:** ${state.filesRead.join(', ')}`);\n }\n if (fileSubs.length > 0) {\n parts.push(`**Files:** ${fileSubs.join('; ')}`);\n }\n\n if (state.handoffHistory.length > 0) {\n parts.push('**Recent Handoffs:**');\n for (const entry of state.handoffHistory) {\n parts.push(`- ${entry.from} → ${entry.to}: ${entry.task}`);\n }\n }\n\n return parts.join('\\n\\n');\n}\n\nexport { HANDOFF_HISTORY_CAP, FILE_HISTORY_CAP };\n","import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';\nimport type { MaestriaState } from '@/state.js';\nimport { persistState, restoreOriginalState } from '@/state.js';\n\nexport const MODE_KEYWORDS = ['fein', 'sonar', 'blitz'] as const;\nexport type ModeKeyword = (typeof MODE_KEYWORDS)[number];\n\nconst MODE_PROMPTS: Record<ModeKeyword, string> = {\n fein: [\n '## MODE: fein (Full Pipeline)',\n '',\n 'Execute the complete fein pipeline: mandatory reconnaissance',\n '(/adventurer) → design/plan (/architect or /planner) →',\n 'implementation (/builder) → review (/reviewer).',\n 'Do NOT skip any phase unless the user explicitly overrides',\n 'in the same turn.',\n ].join('\\n'),\n sonar: [\n '## MODE: sonar (Research Only)',\n '',\n 'Execute research only: /adventurer (recon) →',\n '/architect or /planner (design/plan) → STOP.',\n 'Do NOT implement anything. Return findings.',\n ].join('\\n'),\n blitz: [\n '## MODE: blitz (Fast Implementation)',\n '',\n 'Execute fast implementation via /builder directly.',\n 'Skip reconnaissance and design unless the codebase',\n 'is genuinely unknown. Skip review unless the result',\n 'needs validation.',\n ].join('\\n'),\n};\n\nconst MODE_MARKERS: Record<ModeKeyword, string> = {\n fein: '[MODE: fein]',\n sonar: '[MODE: sonar]',\n blitz: '[MODE: blitz]',\n};\n\nexport function getModePrompt(keyword: ModeKeyword): string {\n return `${MODE_MARKERS[keyword]}\\n\\n${MODE_PROMPTS[keyword]}`;\n}\n\nexport function installModeCommands(pi: ExtensionAPI, state: MaestriaState): void {\n for (const keyword of MODE_KEYWORDS) {\n pi.registerCommand(keyword, {\n description: `Set workflow mode to ${keyword}`,\n handler: async (args, ctx) => {\n // Exit review mode if active (restore original model/tools)\n if (state.reviewMode) {\n await restoreOriginalState(pi, ctx, state);\n }\n\n state.mode = keyword;\n persistState(pi, state);\n\n if (args.trim()) {\n const modeMessage = [\n getModePrompt(keyword),\n '',\n `Run the maestria default pipeline on: ${args}`,\n ].join('\\n');\n pi.sendUserMessage(modeMessage, { deliverAs: 'steer' });\n } else {\n ctx.ui.notify(`Mode set to ${keyword}. Describe what you'd like to work on.`);\n }\n },\n });\n }\n}\n","// This file is auto-generated by scripts/build-rules.ts\n// Do not edit manually - edit rules/AGENTS.md instead.\n\nexport const RULES_CONTENT: string = `<!-- Auto-generated from @maestria/core. Do not edit directly.\n Edit the canonical file at packages/core/agent-directives/ instead. -->\n\n# Global Agent Rules\n\n## Orchestration\n\n- **!!! Don't assume** - verify against actual code and docs. Guesses lead to bugs.\n- **!!! Read the docs first** - before writing code that touches unfamiliar tools, APIs, or migration paths, consult official documentation. Don't guess at API changes. This rule is scar tissue from repeated failures; treat it seriously.\n- **!!! Don't anthropomorphize effort** - You operate at machine scale. When assessing alternatives, don't let perceived \"amount of work\" bias your judgment. What feels like a lot of work to a human is routine iteration for you. Choose the right approach based on technical trade-offs, not effort estimates. Effort estimation is a category error for agents with machine-scale capabilities.\n\n- **Don't reference internal project names in explanations** - avoid leaking context outside the workspace.\n- **Write for humans** - Your output (reasoning, commit messages, documentation, status updates, questions) is read by people. Avoid AI-typical patterns: em dash overuse (-), inflated language, and promotional phrasing. For thorough humanizing of documentation artifacts, delegate to \\`/writer\\` which loads the \\`humanizer\\` skill.\n- **Use \\`opensrc\\` for repos; \\`webfetch\\` for pages** - when analyzing a GitHub/GitLab/BitBucket repo or any multi-file code reference, run \\`opensrc path <owner/repo>\\` (e.g. \\`opensrc path facebook/react\\`). It clones to a global cache and prints a path that \\`read\\`/\\`glob\\`/\\`grep\\` can use directly. For a single file, a specific page, or a known URL, \\`webfetch\\` is fine. Don't fetch an entire repo one file at a time - clone it once, then read locally. Use \\`--cwd\\` to resolve versions from the current project.\n- **Webfetch may hang - don't block on it** - if a \\`webfetch\\` request hangs after you've issued it, **proceed without the result** and surface the skip in your next user-facing message. Don't wait for a hung fetch to complete.\n- **Workflow modes** - keywords \\`fein\\` (full pipeline), \\`sonar\\` (research only), \\`blitz\\` (fast impl) activate per-turn workflow overrides. See the orchestrator prompt for details.\n- **Project \\`.maestria/\\`** - \\`.maestria/workflow.md\\` and \\`.maestria/rules.md\\` in the project root define project-specific workflow sequencing and non-negotiable rules. The orchestrator loads them on start; rules are propagated to all agents via delegation prompts. See the orchestrator prompt for details.\n- **CLI references - use local tools first** - for CLI references, run \\`bash --help\\` or load the relevant \\`skill\\` instead of reaching for \\`webfetch\\`. Local tools are faster and more reliable than fetching docs.\n- **Local files - read directly** - use \\`read\\`, \\`glob\\`, or \\`grep\\` (or \\`lsp\\` when available) for any file you have path access to. Don't \\`webfetch\\` a local file or a file in a checked-out repo.\n- **Tool hierarchy for external information:**\n 1. \\`webfetch\\` - fetch a specific known URL (for docs, pages)\n 2. \\`websearch\\` - discover relevant pages (for finding unknown resources) Use \\`webfetch\\` when you know the URL; use \\`websearch\\` when you need to find something. \\`websearch\\` is an \\`ask\\`-only permission - explain what you're searching for and why before using it.\n\n## Principles\n\n- **Start from first principles** - before adopting an existing pattern or solution, verify it actually matches the fundamental problem. Prior art is a reference, not a constraint.\n- **Prefer existing solutions** - before building something yourself, verify no well-maintained open-source solution (package registries, GitHub, official libraries, plugins) already covers the need.\n\n## Delegation\n\nWhen delegating work via \\`maestria_subagent()\\`, use only the 7 specialists below. **Never delegate to \\`explore\\` or \\`general\\`** - they are built-in agents, not part of the pipeline.\n\n| Agent | Role | When to Delegate |\n| --- | --- | --- |\n| \\`/adventurer\\` | Codebase reconnaissance, deep code understanding | Understanding unfamiliar code, tracing dependencies, gathering context before implementation |\n| \\`/architect\\` | Architecture decisions, trade-off analysis, ADRs | Choosing between approaches, technology evaluation |\n| \\`/builder\\` | Focused implementation, single-task execution | Feature work, bug fixes, test writing, refactors |\n| \\`/diagnose\\` | Systematic bug tracing, root cause analysis | Debugging regressions, production incidents, cryptic errors |\n| \\`/planner\\` | Implementation plans with phased milestones | Complex features requiring structured execution |\n| \\`/reviewer\\` | Code review with quality gates | Pre-merge review, security audit, post-implementation QA |\n| \\`/writer\\` | Documentation following structured patterns | READMEs, API docs, changelogs, ADR transcription |\n\n## Context Management\n\n- **Progressive disclosure** - start high-level, get specific as needed.\n- **State checkpointing** - periodically summarize what's done, what's in progress, what's next.\n- **Context pruning** - remove irrelevant context when no longer needed.\n- **Completion promises** - define success criteria before starting work. \"This task is complete when [verifiable conditions].\"\n\n## Commit Policy\n\n- **Only the orchestrator authorizes commits.** Subagents must refuse commit requests and redirect to the orchestrator.\n- **Builders executing commits** must follow the orchestrator's exact instructions (message, files, validation commands \\`check\\`/\\`test\\`). Flag it if the orchestrator's instructions skip the commit protocol.\n- **Plans must not include implicit commit steps.** Commit authorization is a separate orchestrator step requiring explicit user approval.\n\n## Pipeline Patterns\n\nThe orchestrator prompt defines the canonical Role-Based Pipeline with thinker/worker/verifier roles and dynamic sequencing.\n`;\n","import type {\n BeforeAgentStartEvent,\n BeforeAgentStartEventResult,\n ExtensionContext,\n} from '@earendil-works/pi-coding-agent';\nimport type { MaestriaState } from '@/state.js';\nimport { getModePrompt } from '@/modes.js';\nimport { RULES_CONTENT } from '@/rules-content.js';\n\nexport function createBeforeAgentStartHandler(state: MaestriaState) {\n return (\n event: BeforeAgentStartEvent,\n _ctx: ExtensionContext,\n ): BeforeAgentStartEventResult | void => {\n const parts: string[] = [RULES_CONTENT, '', event.systemPrompt];\n\n if (state.mode) {\n parts.push('', getModePrompt(state.mode));\n parts.push(\n '',\n `The user has set workflow mode to \"${state.mode}\". ` +\n 'Honor this mode throughout the session until changed via /command.',\n );\n }\n\n return { systemPrompt: parts.join('\\n') };\n };\n}\n","import type {\n ExtensionAPI,\n SessionBeforeCompactEvent,\n SessionBeforeTreeEvent,\n} from '@earendil-works/pi-coding-agent';\nimport type { MaestriaState } from '@/state.js';\nimport { renderMaestriaSummary } from '@/state.js';\n\nexport function installCompactionHandlers(pi: ExtensionAPI, state: MaestriaState): void {\n pi.on('session_before_compact', (event: SessionBeforeCompactEvent) => {\n return {\n compaction: {\n summary: renderMaestriaSummary(state),\n details: { ...state },\n firstKeptEntryId: event.preparation.firstKeptEntryId,\n tokensBefore: event.preparation.tokensBefore,\n },\n };\n });\n\n pi.on('session_before_tree', (event: SessionBeforeTreeEvent) => {\n if (event.preparation.userWantsSummary) {\n return {\n summary: {\n summary: renderMaestriaSummary(state),\n },\n };\n }\n return undefined;\n });\n}\n","import { Type } from 'typebox';\nimport type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\nimport { SUBAGENT_EVENTS } from '@gotgenes/pi-subagents';\nimport type { MaestriaState } from '@/state.js';\nimport { persistState, recordHandoff } from '@/state.js';\n\n/**\n * Maestria cross-extension event names.\n * Other Pi extensions can subscribe via `pi.events?.on(...)`.\n * Convention: `maestria:<domain>:<action>`\n */\nexport const MAESTRIA_EVENTS = {\n REVIEW_ACTIVATED: 'maestria:review:activated',\n REVIEW_DEACTIVATED: 'maestria:review:deactivated',\n SUBAGENT_STARTED: 'maestria:subagent:started',\n SUBAGENT_COMPLETED: 'maestria:subagent:completed',\n SUBAGENT_FAILED: 'maestria:subagent:failed',\n} as const;\n\nconst ALLOWED_AGENTS = [\n 'adventurer',\n 'architect',\n 'builder',\n 'diagnose',\n 'planner',\n 'reviewer',\n 'writer',\n] as const;\ntype AllowedAgent = (typeof ALLOWED_AGENTS)[number];\n\n// The 6-field handoff contract\nconst HANDOFF_FIELDS = [\n 'Goal',\n 'Context',\n 'Requirements',\n 'Known problems',\n 'Success criteria',\n 'Next step',\n] as const;\n\n/** Terminal subagent statuses - agent will produce no more updates. */\nconst TERMINAL_STATUSES = new Set(['completed', 'steered', 'aborted', 'stopped', 'error']);\n\n/** Maximum time to wait for a subagent to complete, in milliseconds. */\nexport const POLL_TIMEOUT_MS = 60_000;\n\n/** Interval between subagent status checks, in milliseconds. */\nexport const POLL_INTERVAL_MS = 500;\n\n/** Maximum number of tasks allowed in parallel dispatch. */\nexport const MAX_PARALLEL_TASKS = 8;\n\nexport function validateHandoff(handoff: string): { valid: boolean; errors: string[] } {\n const errors: string[] = [];\n for (const field of HANDOFF_FIELDS) {\n const regex = new RegExp(`\\\\*\\\\*${field}:\\\\*\\\\*[\\\\s\\\\S]*?\\\\S`, 'i');\n if (!regex.test(handoff)) {\n errors.push(`Missing or empty field: \"${field}\"`);\n }\n }\n return { valid: errors.length === 0, errors };\n}\n\nexport function installSubagentTool(\n pi: ExtensionAPI,\n state: MaestriaState,\n cleanups?: Array<() => void>,\n): void {\n pi.registerTool({\n name: 'maestria_subagent',\n label: 'Maestria Subagent',\n description: 'Dispatch a task to a @maestria specialist subagent',\n promptSnippet:\n 'Delegate tasks to @maestria specialist subagents (adventurer, architect, builder, planner, diagnose, reviewer, writer)',\n promptGuidelines: [\n 'Use maestria_subagent when a task MUST be delegated to a specialist subagent rather than handled directly. Each specialist has focused capabilities: adventurer (recon), architect (design), builder (impl), planner (planning), diagnose (bugs), reviewer (QA), writer (docs).',\n ],\n prepareArguments(args: unknown) {\n return args;\n },\n parameters: Type.Object({\n agent: Type.Optional(Type.String({ description: 'Specialist agent name' })),\n task: Type.Optional(Type.String({ description: 'Task description for the subagent' })),\n tasks: Type.Optional(\n Type.Array(\n Type.Object({\n agent: Type.String(),\n task: Type.String(),\n }),\n { description: 'Array of task objects for parallel or chain dispatch' },\n ),\n ),\n mode: Type.Optional(\n Type.Union([Type.Literal('parallel'), Type.Literal('chain'), Type.Literal('single')]),\n ),\n }),\n async execute(\n _toolCallId: string,\n params: {\n agent?: string;\n task?: string;\n tasks?: Array<{ agent: string; task: string }>;\n mode?: 'parallel' | 'chain' | 'single';\n },\n signal: AbortSignal | undefined,\n onUpdate: ((result: { content: Array<{ type: string; text: string }> }) => void) | undefined,\n _ctx: ExtensionContext,\n ) {\n // Block subagent dispatch when in review mode\n if (state.reviewMode) {\n return {\n content: [\n {\n type: 'text' as const,\n text: 'Subagent dispatch is not available during review mode. Use /restore-model to exit review mode first.',\n },\n ],\n };\n }\n\n // Determine dispatch mode (default to 'single' for backward compat)\n const mode = params.mode ?? 'single';\n\n // Validate parameters based on mode\n if (mode === 'single') {\n // Backward-compatible validation - must match original error messages exactly\n if (!ALLOWED_AGENTS.includes(params.agent as AllowedAgent)) {\n throw new Error(\n `Unknown agent: \"${params.agent}\". Allowed: ${ALLOWED_AGENTS.join(', ')}`,\n );\n }\n if (!params.task || !params.task.trim()) {\n throw new Error('Task description is required');\n }\n } else if (mode === 'parallel') {\n if (!params.tasks || params.tasks.length < 2) {\n throw new Error(`For parallel mode, tasks array is required with at least 2 items`);\n }\n if (params.tasks.length > MAX_PARALLEL_TASKS) {\n throw new Error(\n `For parallel mode, tasks array may have at most ${MAX_PARALLEL_TASKS} items (got ${params.tasks.length})`,\n );\n }\n for (const t of params.tasks) {\n if (!ALLOWED_AGENTS.includes(t.agent as AllowedAgent)) {\n throw new Error(`Unknown agent: \"${t.agent}\". Allowed: ${ALLOWED_AGENTS.join(', ')}`);\n }\n if (!t.task || !t.task.trim()) {\n throw new Error('Task description is required for all tasks');\n }\n }\n } else if (mode === 'chain') {\n if (!params.tasks || params.tasks.length < 2) {\n throw new Error('For chain mode, tasks array is required with at least 2 items');\n }\n for (const t of params.tasks) {\n if (!ALLOWED_AGENTS.includes(t.agent as AllowedAgent)) {\n throw new Error(`Unknown agent: \"${t.agent}\". Allowed: ${ALLOWED_AGENTS.join(', ')}`);\n }\n if (!t.task || !t.task.trim()) {\n throw new Error('Task description is required for all tasks');\n }\n }\n }\n\n // Attempt to dispatch via @gotgenes/pi-subagents; fallback gracefully\n try {\n const { getSubagentsService } = await import('@gotgenes/pi-subagents');\n const service = getSubagentsService()!;\n if (typeof service.spawn !== 'function') {\n throw new Error('Subagents service unavailable or incomplete');\n }\n\n // Helper: poll a single subagent until terminal or timeout\n async function pollSubagent(\n id: string,\n label: string,\n sendUpdates: boolean,\n ): Promise<{ status: string; result?: string; error?: string }> {\n const maxPolls = POLL_TIMEOUT_MS / POLL_INTERVAL_MS;\n let polls = 0;\n let record = service.getRecord(id);\n while (record && !TERMINAL_STATUSES.has(record.status) && polls < maxPolls) {\n if (signal?.aborted) throw new Error('Maestria subagent call aborted');\n await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));\n record = service.getRecord(id);\n polls++;\n if (sendUpdates) {\n onUpdate?.({\n content: [\n {\n type: 'text' as const,\n text: `${label} running... (${Math.round((polls * POLL_INTERVAL_MS) / 1000)}s)`,\n },\n ],\n });\n }\n }\n if (record && !TERMINAL_STATUSES.has(record.status)) {\n throw new Error(`Subagent ${id} timed out after ${POLL_TIMEOUT_MS}ms`);\n }\n if (!record) {\n throw new Error(`Subagent ${id} was cleaned up before completion`);\n }\n return record;\n }\n\n // --- SINGLE MODE ---\n if (mode === 'single') {\n const agent = params.agent!;\n const task = params.task!;\n\n // Spawn in foreground - returns subagent ID synchronously\n const id = service.spawn(agent, task, {\n description: task.slice(0, 80),\n foreground: true,\n inheritContext: true,\n });\n\n // Record handoff in state and persist (only after spawn succeeds)\n const updatedState = recordHandoff(state, 'orchestrator', agent, task);\n Object.assign(state, updatedState);\n pi.appendEntry('maestria_state', state);\n\n // Poll for completion\n const record = await pollSubagent(id, `Subagent ${agent}`, true);\n\n const resultText = record.result ?? record.error ?? 'No output.';\n\n return {\n content: [{ type: 'text' as const, text: resultText }],\n details: { subagentId: id },\n };\n }\n\n // --- PARALLEL MODE ---\n if (mode === 'parallel') {\n const taskList = params.tasks!;\n\n onUpdate?.({\n content: [\n { type: 'text' as const, text: `Spawning ${taskList.length} parallel subagents...` },\n ],\n });\n\n // Spawn all tasks\n const spawnedIds: string[] = [];\n for (const t of taskList) {\n const id = service.spawn(t.agent, t.task, {\n description: t.task.slice(0, 80),\n foreground: true,\n inheritContext: true,\n });\n spawnedIds.push(id);\n\n // Record each handoff\n const updatedState = recordHandoff(state, 'orchestrator', t.agent, t.task);\n Object.assign(state, updatedState);\n }\n pi.appendEntry('maestria_state', state);\n\n // Poll all concurrently\n const records = await Promise.all(\n spawnedIds.map((id, i) =>\n pollSubagent(id, `${taskList[i].agent} (${i + 1}/${taskList.length})`, false),\n ),\n );\n\n onUpdate?.({\n content: [\n {\n type: 'text' as const,\n text: `All ${taskList.length} parallel subagents completed.`,\n },\n ],\n });\n\n // Aggregate results\n const parts = [`## Parallel Results (${taskList.length} tasks)\\n`];\n for (let i = 0; i < taskList.length; i++) {\n const t = taskList[i];\n const rec = records[i];\n const resultText = rec.result ?? rec.error ?? 'No output.';\n parts.push(`### ${i + 1}: ${t.agent}`);\n parts.push(resultText);\n }\n\n return {\n content: [{ type: 'text' as const, text: parts.join('\\n\\n') }],\n details: { subagentIds: spawnedIds },\n };\n }\n\n // --- CHAIN MODE ---\n if (mode === 'chain') {\n const taskList = params.tasks!;\n let previousResult = '';\n\n for (let i = 0; i < taskList.length; i++) {\n const t = taskList[i];\n let taskText = t.task;\n\n // Substitute {previous} placeholder with previous result\n if (i > 0 && taskText.includes('{previous}')) {\n taskText = taskText.replace(/\\{previous\\}/g, previousResult);\n }\n\n const id = service.spawn(t.agent, taskText, {\n description: taskText.slice(0, 80),\n foreground: true,\n inheritContext: true,\n });\n\n // Record handoff\n const updatedState = recordHandoff(state, 'orchestrator', t.agent, taskText);\n Object.assign(state, updatedState);\n pi.appendEntry('maestria_state', state);\n\n onUpdate?.({\n content: [\n {\n type: 'text' as const,\n text: `Chain step ${i + 1}/${taskList.length}: ${t.agent} running...`,\n },\n ],\n });\n\n // Poll for completion\n const record = await pollSubagent(id, `Chain step ${i + 1}: ${t.agent}`, true);\n\n previousResult = record.result ?? record.error ?? 'No output.';\n\n if (i < taskList.length - 1) {\n onUpdate?.({\n content: [\n {\n type: 'text' as const,\n text: `Chain step ${i + 1}/${taskList.length}: ${t.agent} completed. Moving to next step.`,\n },\n ],\n });\n }\n }\n\n return {\n content: [{ type: 'text' as const, text: previousResult }],\n details: { subagentId: 'chain-completed' },\n };\n }\n\n // Should not reach here - all modes are handled above\n throw new Error('Unknown dispatch mode');\n } catch {\n // Return handoff payload as structured text when SDK unavailable\n const agentName = params.agent ?? params.tasks?.[0]?.agent ?? 'unknown';\n const taskDesc = params.task ?? params.tasks?.map((t) => t.task).join('; ') ?? 'unknown';\n const handoffInfo = [\n `## Subagent Handoff Required`,\n ``,\n `**From:** orchestrator`,\n `**To:** ${agentName}`,\n `**Task:** ${taskDesc}`,\n ``,\n `Subagent SDK not available. Please delegate this work manually.`,\n ].join('\\n');\n\n return {\n content: [{ type: 'text' as const, text: handoffInfo }],\n };\n }\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any); // TypeBox inferred types don't match ToolDefinition exactly\n\n // Subscribe to subagent lifecycle events for accurate state tracking.\n // These subscriptions are set up once at extension init, not on every tool call.\n // pi.events is the shared EventBus - distinct from pi.on() lifecycle hooks.\n if (pi.events) {\n const unsubStarted = pi.events.on(SUBAGENT_EVENTS.STARTED, (data: unknown) => {\n const { id, type } = data as { id: string; type: string };\n state.subagentStatus[id] = { type, status: 'running', startedAt: Date.now() };\n persistState(pi, state);\n pi.events?.emit(MAESTRIA_EVENTS.SUBAGENT_STARTED, {\n id,\n type,\n timestamp: Date.now(),\n });\n });\n\n const unsubCompleted = pi.events.on(SUBAGENT_EVENTS.COMPLETED, (data: unknown) => {\n const { id } = data as { id: string };\n const existing = state.subagentStatus[id];\n if (existing) {\n existing.status = 'completed';\n existing.completedAt = Date.now();\n }\n persistState(pi, state);\n pi.events?.emit(MAESTRIA_EVENTS.SUBAGENT_COMPLETED, {\n id,\n type: existing?.type,\n timestamp: Date.now(),\n });\n });\n\n const unsubFailed = pi.events.on(SUBAGENT_EVENTS.FAILED, (data: unknown) => {\n const { id, status } = data as { id: string; status: string };\n const existing = state.subagentStatus[id];\n if (existing) {\n existing.status = status ?? 'error';\n existing.completedAt = Date.now();\n }\n persistState(pi, state);\n pi.events?.emit(MAESTRIA_EVENTS.SUBAGENT_FAILED, {\n id,\n type: existing?.type,\n timestamp: Date.now(),\n });\n });\n\n const unsubSteered = pi.events.on(SUBAGENT_EVENTS.STEERED, (data: unknown) => {\n // Steering is informational - no status transition, but ensure\n // the agent is tracked as running if it wasn't already observed.\n const { id } = data as { id: string };\n if (!state.subagentStatus[id]) {\n state.subagentStatus[id] = { type: 'unknown', status: 'running', startedAt: Date.now() };\n }\n persistState(pi, state);\n });\n\n if (cleanups) {\n cleanups.push(unsubStarted, unsubCompleted, unsubFailed, unsubSteered);\n }\n }\n}\n","import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';\nimport type { MaestriaState } from '@/state.js';\nimport {\n cycleToReviewModel,\n persistState,\n renderMaestriaSummary,\n restoreOriginalState,\n} from '@/state.js';\nimport { MAESTRIA_EVENTS } from '@/subagent.js';\n\n/**\n * Read-only tools that let a reviewer inspect code without making changes.\n *\n * - `read`, `grep`, `find`, `ls`, `glob` - all non-destructive.\n * - Excluded: `bash`, `edit`, `write` - these can modify the filesystem.\n *\n * `glob` is included for file pattern matching even though it's not a\n * built-in Pi tool - extensions may register it, and including it is a no-op\n * if absent.\n */\nconst READ_ONLY_TOOLS = ['read', 'grep', 'find', 'ls', 'glob'];\n\nexport function installCommands(pi: ExtensionAPI, state: MaestriaState): void {\n pi.registerCommand('orchestrate', {\n description: 'Start a full pipeline by delegating to the orchestrator',\n handler: async (args: string, ctx) => {\n if (!args.trim()) {\n ctx.ui.notify('Usage: /orchestrate <goal> - describe what to accomplish');\n return;\n }\n\n // Exit review mode if active (restore original model/tools)\n if (state.reviewMode) {\n const prevOriginalModel = state.originalModel;\n await restoreOriginalState(pi, ctx, state);\n persistState(pi, state);\n pi.events?.emit(MAESTRIA_EVENTS.REVIEW_DEACTIVATED, {\n originalModel: prevOriginalModel,\n source: 'orchestrate',\n timestamp: Date.now(),\n });\n }\n\n pi.sendUserMessage(\n [\n `[ORCHESTRATE: ${args}]`,\n '',\n `Orchestrate the full maestria pipeline to: ${args}`,\n 'Use the orchestrator prompt template for subagent delegation.',\n ].join('\\n'),\n { deliverAs: 'steer' },\n );\n },\n });\n\n pi.registerCommand('maestria-status', {\n description: 'Show current maestria session state including handoff history',\n handler: async (_args: string, ctx) => {\n const summary = renderMaestriaSummary(state);\n if (!summary) {\n ctx.ui.notify('No active maestria state to report.');\n return;\n }\n ctx.ui.setEditorText(summary);\n },\n });\n\n pi.registerCommand('review', {\n description: 'Enter review mode. Blocks destructive tools, sets read-only toolset.',\n handler: async (args: string, ctx) => {\n if (!args.trim()) {\n ctx.ui.notify('Usage: /review <target> - describe what to review');\n return;\n }\n\n // 1. Save current model and tools for later restoration\n const currentModelId = ctx.model?.id ?? null;\n const currentTools = pi.getActiveTools();\n\n // 2. Update state: mark review mode, store originals\n const updatedState: MaestriaState = {\n ...state,\n reviewMode: true,\n originalModel: currentModelId,\n originalTools: currentTools,\n };\n Object.assign(state, updatedState);\n persistState(pi, state);\n\n // 3. Switch to review model if configured\n if (state.reviewModel) {\n const switched = await cycleToReviewModel(pi, ctx, state);\n if (switched) {\n ctx.ui.notify(`Review mode: switched to ${switched}`);\n pi.events?.emit(MAESTRIA_EVENTS.REVIEW_ACTIVATED, {\n originalModel: state.originalModel,\n reviewModel: switched,\n timestamp: Date.now(),\n });\n }\n }\n\n // 4. Restrict to read-only tools\n pi.setActiveTools(READ_ONLY_TOOLS);\n\n pi.sendUserMessage(\n [\n `[REVIEW: ${args}]`,\n '',\n `Review: ${args}. Use the reviewer prompt template.`,\n 'Read only, no edits, report findings.',\n ].join('\\n'),\n { deliverAs: 'steer' },\n );\n },\n });\n\n pi.registerCommand('restore-model', {\n description:\n 'Restore the original model and tools that were active before review mode was entered.',\n handler: async (_args: string, ctx) => {\n if (!state.reviewMode) {\n ctx.ui.notify('Not in review mode. Nothing to restore.');\n return;\n }\n const prevOriginalModel = state.originalModel;\n await restoreOriginalState(pi, ctx, state);\n persistState(pi, state);\n ctx.ui.notify('Restored original model and tools.');\n pi.events?.emit(MAESTRIA_EVENTS.REVIEW_DEACTIVATED, {\n originalModel: prevOriginalModel,\n timestamp: Date.now(),\n });\n },\n });\n\n pi.registerCommand('handoff', {\n description: 'Generate a structured handoff prompt for a new task context',\n handler: async (args: string, ctx) => {\n if (!args.trim()) {\n ctx.ui.notify('Usage: /handoff <goal> - describe the task context for handoff');\n return;\n }\n\n // Build a structured handoff document with 6 fields\n const goal = args.trim();\n const handoffPrompt = [\n '**Goal:** ' + goal,\n '',\n '**Context:**',\n '- Mode: ' + (state.mode ?? 'none'),\n '- Active task: ' + (state.activeTask || 'none'),\n '- Specialists delegated: ' +\n ((state.specialistsDelegated?.length ?? 0) > 0\n ? state.specialistsDelegated.join(', ')\n : 'none'),\n '- Recent handoffs: ' + (state.handoffHistory?.length ?? 0) + ' entries',\n '- Files modified: ' +\n ((state.filesModified?.length ?? 0) > 0 ? state.filesModified.join(', ') : 'none'),\n '',\n '**Requirements:**',\n '(fill in specific requirements)',\n '',\n '**Known problems:**',\n (state.blockers?.length ?? 0) > 0\n ? state.blockers.map((b: string) => '- ' + b).join('\\n')\n : '(no known problems documented)',\n '',\n '**Success criteria:**',\n '(fill in how to verify completion)',\n '',\n '**Next step:**',\n '(fill in what happens after this task)',\n '',\n '---',\n 'Complete the fields above before sending.',\n ].join('\\n');\n\n // Record in state\n state.handoffHistory = [\n { from: 'current', to: 'next', task: goal, timestamp: Date.now() },\n ...(state.handoffHistory ?? []),\n ].slice(0, 5);\n\n // Persist state\n persistState(pi, state);\n\n // Send as user message with steer delivery\n pi.sendUserMessage(handoffPrompt, { deliverAs: 'steer' });\n },\n });\n\n pi.registerCommand('review-model', {\n description: 'Set which model to use when entering review mode',\n handler: async (args: string, ctx) => {\n if (!args.trim()) {\n ctx.ui.notify('Usage: /review-model <model-id>');\n return;\n }\n const modelId = args.trim();\n const models = ctx.modelRegistry.getAll();\n const model = models.find((m) => m.id === modelId);\n if (!model) {\n ctx.ui.notify(\n `Unknown model: \"${modelId}\". Available: ${models.map((m) => m.id).join(', ')}`,\n );\n return;\n }\n state.reviewModel = modelId;\n persistState(pi, state);\n ctx.ui.notify(`Review model set to: ${modelId}`);\n },\n });\n}\n","import {\n isToolCallEventType,\n type ExtensionAPI,\n type ToolCallEvent,\n type ExtensionContext,\n} from '@earendil-works/pi-coding-agent';\nimport type { MaestriaState } from '@/state.js';\n\nconst DANGEROUS_PATTERNS = [\n /rm\\s+-rf\\s+\\//,\n /dd\\s+if=/,\n />\\s*\\/dev\\/sd/,\n /chmod\\s+-R\\s+777\\s+\\//,\n /mkfs\\.\\w+/,\n /:(){ :\\|:& };:/, // fork bomb\n />\\s*\\/etc\\/(passwd|shadow|sudoers)/,\n /\\beval\\b/,\n /wget\\s+-O\\s*-\\s*\\|\\s*(bash|sh)/,\n /curl\\s+.*\\|\\s*(bash|sh)/,\n /crontab\\s+-r/,\n];\n\nexport function installToolInterceptors(pi: ExtensionAPI, state: MaestriaState): void {\n pi.on('tool_call', async (event: ToolCallEvent, ctx: ExtensionContext) => {\n if (!event || !event.toolName) return;\n\n // Block destructive tools in review mode\n if (state.reviewMode) {\n if (\n isToolCallEventType('edit', event) ||\n isToolCallEventType('write', event) ||\n isToolCallEventType('bash', event)\n ) {\n return {\n block: true,\n reason: 'Review mode is active. Report findings, do not edit.',\n };\n }\n }\n\n // Block dangerous bash patterns regardless of mode\n if (isToolCallEventType('bash', event)) {\n const command = event.input.command;\n if (command) {\n for (const pattern of DANGEROUS_PATTERNS) {\n if (pattern.test(command)) {\n if (ctx.hasUI) {\n const confirmed = await ctx.ui.confirm(\n 'Dangerous Pattern Detected',\n `This command matches a dangerous pattern:\\n${command}\\nProceed?`,\n );\n if (confirmed) return undefined;\n }\n return {\n block: true,\n reason: `Command matches dangerous pattern: ${pattern}`,\n };\n }\n }\n }\n }\n\n return undefined; // allow\n });\n}\n","import type { ExtensionAPI, SessionStartEvent } from '@earendil-works/pi-coding-agent';\nimport { createInitialState } from '@/state.js';\nimport { installModeCommands } from '@/modes.js';\nimport { createBeforeAgentStartHandler } from '@/rules.js';\nimport { installCompactionHandlers } from '@/compaction.js';\nimport { installSubagentTool } from '@/subagent.js';\nimport { installCommands } from '@/commands.js';\nimport { installToolInterceptors } from '@/tools.js';\n\nexport default function (pi: ExtensionAPI): void {\n const state = createInitialState();\n const cleanups: Array<() => void> = [];\n\n // Install mode commands: /fein, /sonar, /blitz\n installModeCommands(pi, state);\n\n // Inject mode prompts when a mode is active\n const handleBeforeAgentStart = createBeforeAgentStartHandler(state);\n\n pi.on('before_agent_start', (event, ctx) => {\n return handleBeforeAgentStart(event, ctx);\n });\n\n // Restore persisted state on session start (reload/resume/fork)\n pi.on('session_start', (_event: SessionStartEvent, ctx) => {\n if (!ctx.sessionManager?.getEntries) return;\n const entries = ctx.sessionManager.getEntries();\n // Walk from newest to oldest, find the last persisted maestria_state entry\n for (let i = entries.length - 1; i >= 0; i--) {\n const entry = entries[i];\n if (entry.type === 'custom' && entry.customType === 'maestria_state') {\n const data = entry.data;\n if (data && typeof data === 'object') {\n Object.assign(state, data);\n }\n break;\n }\n }\n });\n\n // Install compaction preservation handlers\n installCompactionHandlers(pi, state);\n\n // Install orchestration hooks: subagent tool and commands\n installSubagentTool(pi, state, cleanups);\n installCommands(pi, state);\n\n // Cleanup subscriptions on shutdown\n pi.on('session_shutdown', () => {\n for (const cleanup of cleanups) cleanup();\n cleanups.length = 0;\n });\n\n // Install tool call interceptors for review mode and dangerous patterns\n installToolInterceptors(pi, state);\n}\n"],"mappings":"8JAqCA,SAAgB,GAAoC,CAClD,MAAO,CACL,KAAM,KACN,WAAY,GACZ,kBAAmB,GACnB,qBAAsB,CAAC,EACvB,SAAU,CAAC,EACX,cAAe,CAAC,EAChB,UAAW,CAAC,EACZ,eAAgB,CAAC,EACjB,WAAY,GACZ,cAAe,KACf,cAAe,KACf,eAAgB,CAAC,EACjB,YAAa,IACf,CACF,CAEA,SAAgB,EACd,EACA,EACA,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,GAAI,EAAM,OAAS,UAAY,EAAM,aAAe,iBAAkB,CACpE,IAAM,EAAO,EAAM,KACf,GAAQ,OAAO,GAAS,UAC1B,OAAO,OAAO,EAAO,CAAI,EAE3B,KACF,CACF,CACF,CAAC,EAGD,EAA0B,EAAI,CAAK,EAGnC,EAAoB,EAAI,EAAO,CAAQ,EACvC,EAAgB,EAAI,CAAK,EAGzB,EAAG,GAAG,uBAA0B,CAC9B,IAAK,IAAM,KAAW,EAAU,EAAQ,EACxC,EAAS,OAAS,CACpB,CAAC,EAGD,EAAwB,EAAI,CAAK,CACnC"}
|
package/package.json
CHANGED
package/prompts/adventurer.md
CHANGED
|
@@ -5,7 +5,7 @@ You are a codebase reconnaissance agent.
|
|
|
5
5
|
|
|
6
6
|
## Mission
|
|
7
7
|
|
|
8
|
-
Map unknown territory so downstream specialists (builder, architect, diagnose) can work with full context. You don't implement, design, or debug
|
|
8
|
+
Map unknown territory so downstream specialists (builder, architect, diagnose) can work with full context. You don't implement, design, or debug - you **understand and report**.
|
|
9
9
|
|
|
10
10
|
The pipeline starts with you:
|
|
11
11
|
|
|
@@ -17,19 +17,19 @@ Scan first, plan second, implement third. Your reconnaissance is the first step
|
|
|
17
17
|
|
|
18
18
|
## Process
|
|
19
19
|
|
|
20
|
-
1. **Scope**
|
|
21
|
-
2. **Explore**
|
|
22
|
-
3. **Document**
|
|
23
|
-
4. **Handoff**
|
|
20
|
+
1. **Scope** - Understand what the delegate needs to know
|
|
21
|
+
2. **Explore** - Trace code paths, find key files, map relationships
|
|
22
|
+
3. **Document** - Produce a structured reconnaissance report
|
|
23
|
+
4. **Handoff** - Pass the report cleanly to the next agent
|
|
24
24
|
|
|
25
25
|
## Exploration Techniques
|
|
26
26
|
|
|
27
|
-
- **Entry point analysis**
|
|
28
|
-
- **Call chain tracing**
|
|
29
|
-
- **Module mapping**
|
|
30
|
-
- **Pattern discovery**
|
|
31
|
-
- **Boundary identification**
|
|
32
|
-
- **Dependency tracing**
|
|
27
|
+
- **Entry point analysis** - Start from the user-facing API or entry point
|
|
28
|
+
- **Call chain tracing** - Follow function calls from invocation to implementation
|
|
29
|
+
- **Module mapping** - Document relationships between files and modules
|
|
30
|
+
- **Pattern discovery** - Identify conventions, idioms, repeated patterns
|
|
31
|
+
- **Boundary identification** - Find where data crosses module/API boundaries
|
|
32
|
+
- **Dependency tracing** - Map import chains and external dependencies
|
|
33
33
|
|
|
34
34
|
### Complexity Tiers
|
|
35
35
|
|
|
@@ -45,7 +45,7 @@ Adjust depth based on codebase size:
|
|
|
45
45
|
## Iteration Limits
|
|
46
46
|
|
|
47
47
|
- **Max 3 exploration approaches** before declaring "unable to find" and reporting what was tried.
|
|
48
|
-
- **Never loop silently**
|
|
48
|
+
- **Never loop silently** - if a search strategy doesn't work after 3 attempts, surface the loop with the discovery log.
|
|
49
49
|
- **Escalation format:** "Tried X, Y, Z. Blocked by [cause]. Need [input] to proceed."
|
|
50
50
|
|
|
51
51
|
## Output Format
|
|
@@ -56,7 +56,7 @@ Structure findings so the next agent can start work immediately:
|
|
|
56
56
|
# Reconnaissance Report: [Area]
|
|
57
57
|
|
|
58
58
|
## Key Files
|
|
59
|
-
- `path/to/file.ts`
|
|
59
|
+
- `path/to/file.ts` - Purpose, key exports, role in the system
|
|
60
60
|
|
|
61
61
|
## Call Chains
|
|
62
62
|
[Entry] → [Middleware] → [Implementation] → [Data Access]
|
|
@@ -75,20 +75,20 @@ Specific guidance for the downstream specialist.
|
|
|
75
75
|
|
|
76
76
|
## Rules
|
|
77
77
|
|
|
78
|
-
- **!!! Never edit files**
|
|
79
|
-
- **!!! Never implement solutions**
|
|
80
|
-
- **!!! Never make design decisions**
|
|
81
|
-
- **Use `opensrc` for investigating external dependencies**
|
|
82
|
-
- **External repos: `opensrc` for big repos, `webfetch` for single pages**
|
|
83
|
-
- **One role per session**
|
|
78
|
+
- **!!! Never edit files** - you are read-only reconnaissance
|
|
79
|
+
- **!!! Never implement solutions** - that's `/builder`'s job
|
|
80
|
+
- **!!! Never make design decisions** - that's `/architect`'s job
|
|
81
|
+
- **Use `opensrc` for investigating external dependencies** - when you need to understand how a library works internally, use the `opensrc` skill to clone and read its source instead of making API calls or web requests
|
|
82
|
+
- **External repos: `opensrc` for big repos, `webfetch` for single pages** - For GitHub/GitLab/BitBucket URLs, scoped queries (single file, single page) → `webfetch` is fine. Whole repos or "how is X implemented in library Y" → `opensrc path <owner/repo>` (clones to global cache, gives you a path for `read`/`glob`/`grep`). Don't webfetch a multi-file repo one file at a time - clone once, read locally.
|
|
83
|
+
- **One role per session** - don't mix exploration with building
|
|
84
84
|
- If you can't find something after reasonable effort, report what you tried
|
|
85
85
|
- Prefer `lsp` tool for code intelligence over grep when possible
|
|
86
86
|
- Document negative findings too ("no middleware layer found")
|
|
87
87
|
- Include specific file paths and line numbers in findings
|
|
88
88
|
- For large codebases, use grep-first strategy to avoid token waste
|
|
89
|
-
- **!!! Maker/checker split**
|
|
90
|
-
- **!!! Validate before handoff**
|
|
91
|
-
- **!!! If anything is unclear or ambiguous, flag it in your report**
|
|
89
|
+
- **!!! Maker/checker split** - your work is reviewed by `/reviewer` before it lands. The model that wrote the recon is too nice grading its own homework. Produce the report, do not QA it.
|
|
90
|
+
- **!!! Validate before handoff** - never present a report that hasn't been cross-checked against the source. Read your own report for completeness before reporting back.
|
|
91
|
+
- **!!! If anything is unclear or ambiguous, flag it in your report** - wrong assumptions waste more time than asking questions. State what is unclear and what you assumed instead.
|
|
92
92
|
- **Parallelization:** adventurer tasks on different modules/areas can run in parallel. Two adventurers mapping the same module produce overlapping reports. Read-only is safe; duplication is wasteful.
|
|
93
93
|
|
|
94
94
|
## Handoff
|
|
@@ -103,26 +103,26 @@ When done, your report should let the next agent start working immediately witho
|
|
|
103
103
|
|
|
104
104
|
## Related Agents
|
|
105
105
|
|
|
106
|
-
- `/builder`
|
|
107
|
-
- `/architect`
|
|
108
|
-
- `/diagnose`
|
|
109
|
-
- `/reviewer`
|
|
106
|
+
- `/builder` - Primary consumer of reconnaissance output; starts implementing based on your report
|
|
107
|
+
- `/architect` - Needs structural understanding before making decisions
|
|
108
|
+
- `/diagnose` - Needs call chain and dependency context for root cause analysis
|
|
109
|
+
- `/reviewer` - May request targeted exploration for validation
|
|
110
110
|
|
|
111
111
|
## Skill Prescription
|
|
112
112
|
|
|
113
113
|
### Always load
|
|
114
114
|
|
|
115
|
-
_(none
|
|
115
|
+
_(none - adventurer is read-only; skills load only on trigger)_
|
|
116
116
|
|
|
117
117
|
### Load on trigger
|
|
118
118
|
|
|
119
|
-
- `agent-browser` (`vercel-labs/agent-browser`)
|
|
120
|
-
- `c4-architecture` (`softaworks/agent-toolkit`)
|
|
121
|
-
- `domain-modeling` (`mattpocock/skills`)
|
|
122
|
-
- `mermaid-diagrams` (`softaworks/agent-toolkit`)
|
|
123
|
-
- `resolving-merge-conflicts` (`mattpocock/skills`)
|
|
124
|
-
- `opensrc` (`vercel-labs/opensrc`)
|
|
125
|
-
- `session-handoff` (`softaworks/agent-toolkit`)
|
|
119
|
+
- `agent-browser` (`vercel-labs/agent-browser`) - load when exploring a running web app, visual references/links provided, or Electron apps need inspection (skip if backend-only)
|
|
120
|
+
- `c4-architecture` (`softaworks/agent-toolkit`) - load when output requires a context/container diagram
|
|
121
|
+
- `domain-modeling` (`mattpocock/skills`) - load when mapping domain concepts, terminology, and ubiquitous language during reconnaissance
|
|
122
|
+
- `mermaid-diagrams` (`softaworks/agent-toolkit`) - load when a sequence/flow/ER diagram is requested
|
|
123
|
+
- `resolving-merge-conflicts` (`mattpocock/skills`) - load when investigating merge conflict history or understanding why a conflict occurred
|
|
124
|
+
- `opensrc` (`vercel-labs/opensrc`) - load when external library internals affect the answer
|
|
125
|
+
- `session-handoff` (`softaworks/agent-toolkit`) - load when creating a recon report or handoff document for another agent
|
|
126
126
|
|
|
127
127
|
### Defer to specialist
|
|
128
128
|
|