@jaybeeuu/agent-cortex 1.37.1 → 1.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/.agents/skills/style-versioning/SKILL.md +9 -8
  2. package/.github/workflows/ci.yml +190 -8
  3. package/AGENTS.md +25 -6
  4. package/CHANGELOG.md +42 -0
  5. package/README.md +132 -33
  6. package/agents/README.md +47 -13
  7. package/agents/plan/agent.md +51 -0
  8. package/agents/plan/claude/frontmatter.json +6 -0
  9. package/agents/plan/copilot/frontmatter.json +6 -0
  10. package/agents/plan/pi/frontmatter.json +6 -0
  11. package/agents/plan.agent.md +3 -0
  12. package/agents/ralph/agent.md +262 -0
  13. package/agents/ralph/claude/frontmatter.json +6 -0
  14. package/agents/ralph/claude/polling.md +31 -0
  15. package/agents/ralph/copilot/frontmatter.json +6 -0
  16. package/agents/ralph/copilot/polling.md +62 -0
  17. package/agents/ralph/pi/frontmatter.json +6 -0
  18. package/agents/ralph/pi/polling.md +74 -0
  19. package/agents/ralph-plan/agent.md +114 -0
  20. package/agents/ralph-plan/claude/frontmatter.json +6 -0
  21. package/agents/ralph-plan/copilot/frontmatter.json +6 -0
  22. package/agents/ralph-plan/pi/frontmatter.json +6 -0
  23. package/agents/ralph-plan.agent.md +5 -2
  24. package/agents/ralph.agent.md +83 -57
  25. package/agents/strategy/agent.md +104 -0
  26. package/agents/strategy/claude/frontmatter.json +6 -0
  27. package/agents/strategy/copilot/frontmatter.json +6 -0
  28. package/agents/strategy/pi/frontmatter.json +6 -0
  29. package/agents/strategy.agent.md +3 -0
  30. package/bin/agent-cortex.mjs +68 -1
  31. package/bin/installers/claude.mjs +262 -0
  32. package/bin/installers/copilot.mjs +129 -0
  33. package/bin/installers/pi.mjs +197 -0
  34. package/claude/.claude-plugin/plugin.json +1 -1
  35. package/claude/agents/plan.md +3 -1
  36. package/claude/agents/ralph-plan.md +5 -3
  37. package/claude/agents/strategy.md +3 -1
  38. package/claude/hooks/scripts/notify.mjs +54 -0
  39. package/claude/hooks.json +15 -0
  40. package/docs/claude-hooks.md +115 -0
  41. package/docs/ideas/auto-model-selection.md +75 -0
  42. package/docs/ideas/improve-pi-system-prompt.md +34 -0
  43. package/docs/ideas/model-selector.md +40 -0
  44. package/docs/ideas/pi-task-memory.md +34 -0
  45. package/docs/ideas/qa-extension.md +43 -0
  46. package/docs/ideas/unified-ci-pipeline.md +28 -0
  47. package/docs/skills/skill-anatomy.md +9 -0
  48. package/extensions/agent-modes/README.md +54 -0
  49. package/extensions/agent-modes/discover.test.ts +241 -0
  50. package/extensions/agent-modes/discover.ts +458 -0
  51. package/extensions/agent-modes/index.ts +13 -224
  52. package/extensions/agent-modes/node_modules/.bin/pi +21 -0
  53. package/extensions/agent-modes/node_modules/.bin/tsc +21 -0
  54. package/extensions/agent-modes/node_modules/.bin/tsserver +21 -0
  55. package/extensions/agent-modes/node_modules/.bin/tsx +21 -0
  56. package/extensions/agent-modes/package.json +20 -0
  57. package/extensions/agent-modes/tsconfig.json +12 -0
  58. package/extensions/subagent/README.md +19 -0
  59. package/extensions/subagent/index.ts +131 -45
  60. package/extensions/subagent/node_modules/.bin/pi +21 -0
  61. package/extensions/subagent/node_modules/.bin/pi-ai +21 -0
  62. package/extensions/subagent/node_modules/.bin/tsc +21 -0
  63. package/extensions/subagent/node_modules/.bin/tsserver +21 -0
  64. package/extensions/subagent/node_modules/.bin/tsx +21 -0
  65. package/extensions/subagent/package.json +23 -0
  66. package/extensions/subagent/tsconfig.json +12 -0
  67. package/extensions/subagent/wait.test.ts +202 -0
  68. package/extensions/subagent/wait.ts +118 -0
  69. package/hooks/claude/hooks.json +38 -0
  70. package/hooks/claude/scripts/notify.mjs +54 -0
  71. package/lib/cli.mjs +62 -3
  72. package/package.json +6 -4
  73. package/plugin.json +1 -1
  74. package/scripts/build-copilot-agents.mjs +30 -0
  75. package/scripts/lib/compose-agent.mjs +241 -0
  76. package/skills/engineering/design-an-interface/SKILL.md +1 -1
  77. package/skills/engineering/improve-codebase-architecture/SKILL.md +1 -1
  78. package/skills/workflow/ralph/REFERENCE.md +2 -2
  79. package/skills/workflow/ralph/SKILL.md +6 -6
  80. package/skills/workflow/run-pipeline-stage/scripts/generate-progress.ts +4 -2
  81. package/skills/workflow/using-agent-skills/SKILL.md +122 -0
  82. package/test/cli.test.mjs +115 -2
  83. package/test/copilot-installer.test.mjs +298 -0
  84. package/test/installer.test.mjs +179 -0
  85. package/test/notify-hook.test.mjs +63 -0
  86. package/test/pi-installer.test.mjs +371 -0
  87. package/token-map.README.md +128 -0
  88. package/token-map.json +106 -0
  89. package/.github/workflows/ci.test.ts +0 -217
  90. package/.github/workflows/release.yml +0 -58
  91. package/scripts/build-claude-agents.mjs +0 -179
  92. package/scripts/publish-release.sh +0 -32
@@ -1,10 +1,12 @@
1
1
  ---
2
- # GENERATED from agents/plan.agent.md by scripts/build-claude-agents.mjs — DO NOT EDIT.
2
+ # GENERATED from agents/plan/ by bin/installers/claude.mjs — DO NOT EDIT.
3
3
  name: plan
4
4
  description: "Guide a feature from first discussion through PRD and task breakdown to classified beads ready for ralph execution. Full end-to-end planning workflow using the plan skill. Use when starting a new feature, scoping work to hand off to ralph, or saying 'plan this'."
5
5
  tools: Bash, Read, Edit, Write, Grep, Glob, AskUserQuestion, Task, Skill
6
6
  ---
7
7
 
8
+ # plan — end-to-end feature planning agent
9
+
8
10
  You are a planning agent. Your job is to guide a feature from first discussion through PRD and task breakdown to classified beads ready for ralph execution.
9
11
 
10
12
  You follow the **plan** skill workflow. The skill is defined in `skills/workflow/plan/SKILL.md`. Read it now to load the full instructions.
@@ -1,10 +1,12 @@
1
1
  ---
2
- # GENERATED from agents/ralph-plan.agent.md by scripts/build-claude-agents.mjs — DO NOT EDIT.
2
+ # GENERATED from agents/ralph-plan/ by bin/installers/claude.mjs — DO NOT EDIT.
3
3
  name: ralph-plan
4
4
  description: "Plans changes by exploring codebases and creating beads to track the work. Use when you want to scope a feature, bug fix, or refactor — the agent reads, reasons, grills the user, writes a high-level plan into the top-level bead, then files child beads ready for ralph."
5
5
  tools: Bash, Read, Edit, Write, Grep, Glob, AskUserQuestion
6
6
  ---
7
7
 
8
+ # ralph-plan — planning agent for ralph
9
+
8
10
  You are a planning agent. Your job is to understand a task, explore the codebase, grill the user until the design is clear, write a concise implementation plan, and file beads for ralph to implement. You **must not** modify any source code or tracked documentation — your writes are limited to `.agent-cortex/working-docs/` and bead fields.
9
11
 
10
12
  ## Permitted writes
@@ -32,7 +34,7 @@ Invoke the **beads** skill (set workspace root, run `bd prime`). Hold the output
32
34
  If the input looks like a PRD (product requirements document), invoke the **prd-to-tasks** skill first — it handles exploration, user quizzing, and creates epics and task beads directly. Then continue from step 7 (Agree with the user).
33
35
 
34
36
  ### 2. Understand the request
35
- If the request is ambiguous or incomplete, use `AskUserQuestion` to resolve blockers before exploring. One question at a time.
37
+ If the request is ambiguous or incomplete, use AskUserQuestion to resolve blockers before exploring. One question at a time.
36
38
 
37
39
  If the domain language is unclear or inconsistent, invoke the **grill-with-docs** skill to extract canonical terms. It updates `CONTEXT.md` inline and surfaces ambiguities.
38
40
 
@@ -116,4 +118,4 @@ Every explore sub-agent prompt must include:
116
118
  - Never assume — verify by reading actual code before creating a bead.
117
119
  - Never write outside `.agent-cortex/working-docs/` or bead fields.
118
120
  - Never make commits, open PRs, or run shell commands that modify the repo.
119
- - Use `Bash` only for read-only commands (`git log`, `find`, `cat`, etc.).
121
+ - Use Bash only for read-only commands (`git log`, `find`, `cat`, etc.).
@@ -1,10 +1,12 @@
1
1
  ---
2
- # GENERATED from agents/strategy.agent.md by scripts/build-claude-agents.mjs — DO NOT EDIT.
2
+ # GENERATED from agents/strategy/ by bin/installers/claude.mjs — DO NOT EDIT.
3
3
  name: strategy
4
4
  description: "Creates top-level design documents across strategy, PRD, and technical direction so delivery planning starts with clear intent and justified decisions. Use when defining product direction before implementation planning, shaping a feature PRD, or selecting technical direction before ralph-plan."
5
5
  tools: Bash, Read, Grep, Glob, AskUserQuestion, WebFetch, Skill, Edit, Write
6
6
  ---
7
7
 
8
+ # strategy — pre-delivery design agent
9
+
8
10
  You are a pre-delivery design agent. Your job is to produce high-quality design artifacts that set up `ralph-plan` for success.
9
11
 
10
12
  ## Scope
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ // Claude Code Notification hook — desktop notification on task completion/error.
3
+ //
4
+ // Reads the Notification hook JSON payload from stdin and prints a
5
+ // `{ "terminalSequence": "..." }` response for Claude Code to emit. Hooks run
6
+ // without a controlling terminal, so OSC sequences must go through Claude Code
7
+ // itself (it handles tmux/screen re-wrapping); writing /dev/tty directly fails.
8
+ //
9
+ // Mapped from the pi `notify` extension (extensions/notify/): pi notifies on
10
+ // agent_end for multi-turn or long tasks. Claude Code's Notification matcher is an
11
+ // exact-string list over `notification_type` values (there are no `success`/
12
+ // `error` types) — hooks.json selects `agent_completed|agent_needs_input|permission_prompt`
13
+ // to mirror "task completed / failed / needs approval". The payload already carries
14
+ // a message + title, so no summarization LLM call is needed here.
15
+ //
16
+ // Zero dependencies; runs on the Node that ships with Claude Code.
17
+
18
+ let raw = "";
19
+ for await (const chunk of process.stdin) {
20
+ raw += chunk;
21
+ }
22
+
23
+ let payload = {};
24
+ try {
25
+ payload = raw.trim() ? JSON.parse(raw) : {};
26
+ } catch {
27
+ process.exit(0); // never fail a session on an unparsable payload
28
+ }
29
+
30
+ const message = typeof payload.message === "string" ? payload.message.trim() : "";
31
+ if (!message) process.exit(0); // nothing worth notifying (e.g. autocompact events)
32
+
33
+ const title =
34
+ typeof payload.title === "string" && payload.title.trim() ? payload.title.trim() : "Claude Code";
35
+ const type = typeof payload.notification_type === "string" ? payload.notification_type : "";
36
+
37
+ process.stdout.write(JSON.stringify({ terminalSequence: pickSequence(title, message, type) }) + "\n");
38
+
39
+ /** Pick an OSC notification escape sequence for the detected terminal. */
40
+ function pickSequence(title, message, type) {
41
+ const body = message.replace(/\u001b/g, "").replace(/\n/g, " ").trim();
42
+ const label = type ? `${type}: ${title}` : title;
43
+
44
+ if (process.env.KITTY_WINDOW_ID) {
45
+ // Kitty: two-part persistent notification (title + body) — same form as the pi notify extension.
46
+ return `\u001b]99;i=1:d=1;${title}\u001b\\\u001b]99;i=1:p=body;${body}\u001b\\`;
47
+ }
48
+ if (process.env.TERM_PROGRAM === "iTerm.app" || process.env.ITERM_SESSION_ID) {
49
+ // iTerm2 / ConEmu / Windows Terminal / WezTerm: OSC 9.
50
+ return `\u001b]9;${label}: ${body}\u0007`;
51
+ }
52
+ // urxvt / Ghostty / Warp, and default fallback: OSC 777.
53
+ return `\u001b]777;notify;${label};${body}\u0007`;
54
+ }
package/claude/hooks.json CHANGED
@@ -12,12 +12,27 @@
12
12
  "type": "command",
13
13
  "command": "echo 'Style policy: this project ships style skills — prefer them over ad-hoc choices. Invoke style-code BEFORE writing or editing code (and when refactoring); style-tests BEFORE writing or changing tests; style-documentation BEFORE writing or updating docs; style-comms BEFORE composing commit messages, PR descriptions, tickets, or other written deliverables.'"
14
14
  },
15
+ {
16
+ "type": "command",
17
+ "command": "echo 'Skill policy: agent-cortex ships skills — prefer them over ad-hoc choices. using-agent-skills routes work to the right skill (check it first when unsure); bd-tool tracks beads tasks (run bd ready for available work); git-workflow enforces branch and PR discipline. Invoke skills via the Skill tool.'"
18
+ },
15
19
  {
16
20
  "type": "command",
17
21
  "command": "echo 'Be extremely concise. Sacrifice grammar for the sake of concision.'"
18
22
  }
19
23
  ]
20
24
  }
25
+ ],
26
+ "Notification": [
27
+ {
28
+ "matcher": "agent_completed|agent_needs_input|permission_prompt",
29
+ "hooks": [
30
+ {
31
+ "type": "command",
32
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/scripts/notify.mjs\""
33
+ }
34
+ ]
35
+ }
21
36
  ]
22
37
  }
23
38
  }
@@ -0,0 +1,115 @@
1
+ # Claude Code hooks — extension port audit
2
+
3
+ The pi extensions in `extensions/` were audited for Claude Code equivalents.
4
+ Implemented ports live in `hooks/claude/hooks.json` (copied verbatim into the
5
+ generated plugin as `claude/hooks.json`); support scripts live in
6
+ `hooks/claude/scripts/` and are bundled into `claude/hooks/scripts/` by
7
+ `bin/installers/claude.mjs` (referenced from hooks.json via `$CLAUDE_PLUGIN_ROOT`).
8
+
9
+ Claude Code's hook model differs from PI's: hooks are shell commands fed a JSON
10
+ payload on stdin, with events like `SessionStart`, `SessionEnd`, `Stop`,
11
+ `SubagentStop`, and `Notification` — there is no `before_agent_start` /
12
+ `agent_end` / `tool_call` extension API, no runtime tool registration, and no
13
+ UI surface. Each decision below is grounded in the Claude Code hooks reference.
14
+
15
+ | pi extension | Claude port | Decision |
16
+ |---|---|---|
17
+ | `session-start.ts` | `SessionStart` hook commands | **Port** (extended) |
18
+ | `auto-name.ts` | — | **Reject** — built-in |
19
+ | `notify/` | `Notification` hook + `scripts/notify.mjs` | **Port** |
20
+ | `skill-stats/` | — | **Reject** — no equivalent |
21
+ | `subagent/` | — | **Reject** — native |
22
+ | `agent-modes/` | — | **Reject** — no equivalent |
23
+
24
+ ## `session-start.ts` → SessionStart (port)
25
+
26
+ pi injects skill-availability hints + project context files (AGENTS.md,
27
+ `docs/user-preferences.md`) into every session. Claude Code already loads
28
+ `AGENTS.md` natively and the existing SessionStart hook nudge ("Load AGENTS.md
29
+ and active beads context…") plus the style-skill policy (PR #57) cover the
30
+ context side. This bead closes the remaining gap: a skill-policy command listing
31
+ the meta-skills (`using-agent-skills` for routing, `bd-tool` for beads context,
32
+ `git-workflow` for branch/PR discipline). SessionStart command-hook stdout is
33
+ added to Claude's context, so plain `echo` commands are the right shape —
34
+ keep them fast and dependency-free. Skipped from the pi original: the dynamic
35
+ file read of AGENTS.md/user-preferences.md, since Claude Code loads AGENTS.md
36
+ itself and user-preferences.md is a pi-harness document.
37
+
38
+ ## `auto-name.ts` → Reject (built-in)
39
+
40
+ pi names sessions via a tiny side-model call on the first prompt. Claude Code
41
+ already auto-generates descriptive session titles (visible in `claude --resume`;
42
+ a background model request in interactive and headless/SDK sessions) and supports
43
+ explicit naming via `--name` / `/rename`. A hook-based title generator would
44
+ duplicate platform behaviour with an extra LLM call — rejected. (SessionStart
45
+ hooks can also set `sessionTitle` in JSON output for the rare case where a
46
+ custom title is genuinely needed.)
47
+
48
+ ## `notify/` → Notification hook (port)
49
+
50
+ pi notifies on `agent_end` for multi-turn/long tasks with a desktop notification
51
+ + bell. Claude Code's native `Notification` event fires at the equivalent
52
+ completion points and already carries `message`, `title`, and `notification_type`
53
+ in the payload — and hooks emit desktop notifications by returning a
54
+ `terminalSequence` JSON field (hooks have no controlling terminal; Claude Code
55
+ emits the sequence itself, including inside tmux/screen).
56
+
57
+ Implemented as a `Notification` hook with matcher
58
+ `agent_completed|agent_needs_input|permission_prompt` invoking `scripts/notify.mjs`,
59
+ which reads the payload from stdin and prints the OSC sequence for the detected
60
+ terminal (Kitty OSC 99, iTerm2/Windows Terminal OSC 9, default urxvt/Ghostty/Warp
61
+ OSC 777 — same detection as the pi `notify` extension). The Notification matcher
62
+ is an **exact-string list** over the `notification_type` field; there are no
63
+ `success`/`error` types (an earlier draft used that matcher, which silently never
64
+ fired). The documented types are `permission_prompt`, `idle_prompt`, `auth_success`,
65
+ `elicitation_dialog`, `elicitation_url_dialog`, `elicitation_complete`,
66
+ `elicitation_response`, `agent_needs_input`, `agent_completed`,
67
+ `quota_auto_resume_fired`, `quota_auto_resume_stale`, `quota_auto_resume_disabled`
68
+ (the `agent_*` types require Claude Code v2.1.198+, the `quota_auto_resume_*`
69
+ types v2.1.234+). The selection maps to pi's "task completed / failed / needs
70
+ approval" semantics: `agent_completed` covers completion and failure ("finishes
71
+ or fails"), `agent_needs_input` covers a background session waiting on input, and
72
+ `permission_prompt` covers an awaited approval. Explicitly excluded as noise:
73
+ `idle_prompt` (fires ~60s after every turn you don't answer within a minute — a
74
+ desktop ping on every pause), `auth_success` and `quota_auto_resume_*` (not task
75
+ events), and `elicitation_*` (dialog trivia). Skipped from the pi original: the LLM
76
+ response summary (Claude's notification message is already the summary) and the tmux
77
+ session:window.pane title (unavailable to hooks; the plugin title suffices).
78
+
79
+ ## `skill-stats/` → Reject (no equivalent)
80
+
81
+ pi tracks skills loaded into the system prompt, `/skill:` invocations, SKILL.md
82
+ reads, and turns, exposing a `/skill-stats` query. Claude Code exposes none of
83
+ the required observability to hooks:
84
+
85
+ - **No "loaded" event** — nothing fires when a skill enters context, and hooks
86
+ never see system-prompt contents, so the primary "loaded" metric has no source.
87
+ - **Partial invocation/read observability only** — `PreToolUse` on the `Skill`
88
+ tool and `UserPromptExpansion` on slash commands would approximate
89
+ invocations, and `PostToolUse` on `Read` would approximate skill reads, but
90
+ the signals are fuzzy (Read covers any file; direct `/skill` typing bypasses
91
+ `PreToolUse`).
92
+ - **No query surface** — Claude Code plugin commands are markdown files, not
93
+ scripts, so there is no equivalent of the pi `/skill-stats` command, and
94
+ persistent state would live outside the plugin model.
95
+
96
+ A half-observable port would diverge from the pi semantics and add moving parts
97
+ for little signal. Rejected; Claude Code ships its own usage analytics
98
+ (`/usage`, sessions list, statsig) if insights are needed.
99
+
100
+ ## `subagent/` → Reject (native)
101
+
102
+ pi's `subagent` tool spawns isolated `pi --mode json` processes. Claude Code has
103
+ native subagents — the plugin already ships `claude/agents/*.md` (including
104
+ `ralph`, `plan`, `strategy`, `ralph-plan`) executed via the built-in Agent/Task
105
+ tools with per-session context isolation — so a hook-based workaround would be
106
+ strictly worse.
107
+
108
+ ## `agent-modes/` → Reject (no equivalent)
109
+
110
+ pi switches system prompts + tool restrictions at runtime with a TUI mode
111
+ selector. Claude Code exposes no hook or settings surface for dynamic
112
+ tool-restriction/prompt-switching of the main agent; the closest equivalents are
113
+ native (permission modes like plan mode configured via settings, and subagents
114
+ — already covered above). The `--agent <name>` start flag is covered by
115
+ `claude --agent` in newer versions. Rejected.
@@ -0,0 +1,75 @@
1
+ # Idea: Auto-Model Selection Plugin
2
+
3
+ ## Status
4
+ Backlog idea (not implementation-ready) — **direction: evaluate and adopt existing package**
5
+
6
+ ## Why it might be useful
7
+ PI has no intelligent model selection. Users must manually choose models, which means they either over-provision (expensive models for simple tasks) or under-provision (weak models for complex work). Rate limits hit without warning, forcing manual model switching mid-session. An auto-selection plugin would optimize cost/performance by matching model capability to task complexity, and provide seamless fallbacks when rate limits are hit.
8
+
9
+ ## How we might do it
10
+ **Evaluate and adopt an existing PI extension** rather than building from scratch. The ecosystem already has well-maintained packages that cover task-based routing and rate-limit fallbacks. The goal is to:
11
+
12
+ 1. **Evaluate the top candidates** (see "Packages to evaluate" below)
13
+ 2. **Pick the best fit** for agent-cortex's workflow (beads, pipeline stages, HITL/AFK classification)
14
+ 3. **Install and configure** it, possibly with light customisation if needed
15
+ 4. **Document** the chosen package and configuration in agent-cortex docs
16
+
17
+ ## Packages to evaluate (in priority order)
18
+ **Top candidates — cover both task-based routing AND fallbacks:**
19
+ 1. **`@kylebrodeur/pi-model-router`** — per-turn routing to high/medium/low tiers based on task intent, context size, budget, with automatic fallback chains and rate-limit recovery. Well-documented fork of yeliu84's original.
20
+ 2. **`pi-auto-router`** — multi-provider routing with same-request failover, budget-aware policies, and quota-aware fallback.
21
+ 3. **`pi-tiered-router`** — routes different *phases* (planner/validator/executor/tool-parser) to different models. Quality-first, not cost-saving.
22
+
23
+ **Fallback-only (simpler, if routing is overkill):**
24
+ - **`pi-auto-models`** — Claude→Codex quota switching with 429/529 recovery
25
+ - **`pi-provider-fallback`** — cross-provider fallback chain with TUI config
26
+
27
+ **Evaluation criteria:**
28
+ - Does it integrate cleanly with PI's existing provider/model system?
29
+ - Does it respect user's explicit model choice, or override it?
30
+ - How does it handle context window mismatches on fallback?
31
+ - Is it configurable per-project?
32
+ - Does it have fallback chains or just single fallback?
33
+ - Rate-limit detection and retry logic
34
+ - Documentation quality and maintenance status
35
+
36
+ ## When to think about it
37
+ - After current feature stabilisation (refactor-to-template epic, npm publishing, system prompt improvements)
38
+ - Not blocked, but benefits from stable extension infrastructure
39
+
40
+ ## Priority
41
+ Medium / backlog — valuable for cost optimisation and reliability, but not urgent. Current manual model selection works, just isn't optimal.
42
+
43
+ ## Open questions
44
+ - How to classify task complexity? Heuristics (file count, prompt length, keywords)? Or let user tag tasks?
45
+ - What defines a "model class"? Cost tier, context window size, reasoning capability, speed?
46
+ - Should the plugin override the user's explicit model choice, or only activate when no model is selected?
47
+ - How to handle context window mismatches when falling back (e.g., 200k → 128k)?
48
+ - Should this be configurable per-project (different policies for different repos)?
49
+
50
+ ## Existing packages in the ecosystem
51
+ Several published packages already address parts of this problem:
52
+
53
+ ### Fallback / rate-limit recovery
54
+ - **`pi-provider-fallback`** — cross-provider fallback with interactive TUI config
55
+ - **`pi-auto-models`** — primary/fallback switching on quota (Claude→Codex default), 429/529 recovery
56
+
57
+ ### Task-based / tier routing
58
+ - **`pi-model-router`** (yeliu84, forked by @kdejaeger and @kylebrodeur) — per-turn routing to high/medium/low tiers based on task intent, context size, budget, with automatic fallbacks
59
+ - **`pi-model-auto`** — routes by Low/Medium/High/Ultra capability modes per turn
60
+ - **`pi-tiered-router`** — routes different phases (planner/validator/executor/tool-parser) to different models
61
+
62
+ ### Full auto-router with failover
63
+ - **`pi-auto-router`** — multi-provider routing with same-request failover, budget-aware policies
64
+ - **`@ifi/pi-extension-adaptive-routing`** — adaptive routing with local telemetry persistence
65
+
66
+ ### Model selection (manual)
67
+ - **`pi-model-switch`** — direct model switching tool
68
+ - **`pi-model-select`** — `/select-model` with favourites and fuzzy search
69
+
70
+ ## Notes
71
+ - **The ecosystem is active** — this space is already well-served. Before building, evaluate whether an existing package (especially `pi-model-router` or `pi-auto-router`) already meets the need.
72
+ - **Gap analysis needed**: compare existing packages against the original requirements (task-based class selection + rate-limit fallbacks) to see if anything is genuinely missing.
73
+ - **Partial solutions exist in PI core**: OpenRouter's routing config supports fallbacks and provider ordering, but only within OpenRouter. Cross-provider fallback requires an extension.
74
+ - **Implementation approach** (if building): likely a PI extension that registers a "smart-router" provider, which internally delegates to real providers based on task classification and availability.
75
+ - **Research done**: reviewed PI docs on providers, models, and extensions. Searched npm and pi.dev for existing packages.
@@ -0,0 +1,34 @@
1
+ # Idea: Improve PI System Prompt
2
+
3
+ ## Status
4
+ Backlog idea (not implementation-ready)
5
+
6
+ ## Why it might be useful
7
+ PI's current system prompt is weak. Agents consistently get off track, spend excessive tokens spinning their wheels or going off on tangents, fail to check in when problems are hit, and generally behave like inexperienced code goblins. This wastes tokens, slows down task completion, and forces the user to constantly redirect the agent. A stronger system prompt would produce more focused, disciplined agents that know when to stop and ask.
8
+
9
+ ## How we might do it
10
+ Build improved behavioural instructions into agent-cortex — layered on top of or replacing PI's default system prompt. Key improvements:
11
+
12
+ 1. **Loop prevention / circuit-breakers** — hard limits on retry attempts (e.g. 2-attempt limit before stopping and asking), no repeated tool execution without rationale
13
+ 2. **Task-focus discipline** — stronger scoping instructions, no tangential refactoring, atomic changes
14
+ 3. **Check-in triggers** — explicit rules for when the agent must stop and present options to the user
15
+
16
+ A Gemini-generated execution protocol prompt exists as a possible starting point (see Notes), but will need significant customisation for agent-cortex.
17
+
18
+ ## When to think about it
19
+ - Land the current work first (refactor-to-template epic, bead workflow polish, CI/CD pipeline)
20
+ - **Next priority after current work** — this is urgent-ish
21
+
22
+ ## Priority
23
+ High — after current work lands. Directly impacts daily productivity and token efficiency.
24
+
25
+ ## Open questions
26
+ - Layer on top of PI's default prompt, or replace it entirely?
27
+ - Should PI's current system prompt be reviewed for nonsense that can be chopped out?
28
+ - Which guardrails from the Gemini starter are genuinely useful vs redundant with existing skills (e.g. `git-workflow` already covers destructive commands, `style-code` covers scope discipline)?
29
+ - How should circuit-breakers interact with skills like `run-pipeline-stage` that already have structured workflows?
30
+
31
+ ## Notes
32
+ - **Gemini starter prompt** exists (see conversation from 2026-08-05) covering loop prevention, action scope, context management, execution workflow order, and working state maintenance. Useful starting material but needs heavy customisation.
33
+ - **Incompatibility to fix**: the starter's "Working State Maintenance" section proposes `.pi/PLAN.md` files for complex tasks. This is incompatible with agent-cortex — we use **beads (bd)** for task tracking and pipeline stages, not flat markdown plan files. This section needs to be replaced with bead-aware equivalents (e.g. updating bead notes, using pipeline stage state).
34
+ - **Overlap with existing skills**: several guardrails already exist in agent-cortex skills (`git-workflow`, `style-code`, `run-pipeline-stage`). The biggest gaps are **loop prevention / circuit-breakers** and **check-in discipline** — these aren't enforced anywhere today.
@@ -0,0 +1,40 @@
1
+ # Idea: model-selector
2
+
3
+ ## Status
4
+ Backlog idea (not implementation-ready)
5
+
6
+ ## Created
7
+ 2026-07-12
8
+
9
+ ## Problem
10
+ Selecting the right model for a task is manual and brittle. When a model is unavailable (rate-limited, down, or lacking capability), there's no automatic fallback. You have to know which model IDs to type into `/model` and remember which providers offer which capabilities.
11
+
12
+ ## Who benefits
13
+ Anyone using PI who runs multiple models/providers. The extension makes model selection declarative: "I want to write code" → extension picks the best available model (and falls back if limits are hit).
14
+
15
+ ## Proposed outcome
16
+ A PI extension that defines an abstraction for selecting models based on task/use case. Users declare "use case → model(s) with fallbacks" in config, and the extension handles selection and failover automatically.
17
+
18
+ Key capabilities:
19
+ - **Use-case profiles**: e.g. `code`, `chat`, `review`, `architect` — each maps to a primary model + ordered fallbacks
20
+ - **Automatic fallback**: if the primary model returns a 429 or error, drop to the next in the chain
21
+ - **Task-based selection**: think "I want this model to write code" instead of choosing a specific model ID
22
+ - **Configurable**: profiles defined in settings.json or a dedicated config file
23
+
24
+ ## Validity check
25
+ - Evidence we already have: The existing `tiny-model.ts` lib in this repo already shows the pattern of configuring a model by provider/id string and looking it up via `modelRegistry.find()`. The PI extension API supports `before_provider_response` (for catching 429s) and `model_select` events.
26
+ - Riskiest assumption: That use-case profiles are a useful abstraction — users may prefer to just name a model family and let fallback be implicit.
27
+ - What would invalidate this idea: If PI adds built-in model routing/fallback, or if users find the abstraction adds confusion rather than removing it.
28
+
29
+ ## Constraints
30
+ - Must not add LLM calls internally (per extension conventions in AGENTS.md)
31
+ - Must work with the existing `modelRegistry` API — no monkey-patching
32
+ - Storage/config should go in settings.json or `~/.pi/agent-cortex/` (global, cross-project)
33
+
34
+ ## Next validation step
35
+ Sketch the config schema and test it against real usage patterns. Does the profile abstraction hold up for the models/providers you actually use?
36
+
37
+ ## Notes
38
+ - Initial conversation during planning session 2026-07-12. Idea recorded as backlog, to be fleshed out when time permits.
39
+ - Could draw on patterns from OpenRouter's routing and the existing `modelOverrides` in models.json.
40
+ - The `notify` extension already intercepts provider responses — similar pattern for catching rate limits.
@@ -0,0 +1,34 @@
1
+ # Idea: PI Task Memory Skill
2
+
3
+ ## Status
4
+ Backlog idea (not implementation-ready)
5
+
6
+ ## Why it might be useful
7
+ PI has no built-in task memory. Agents lose context between sessions — they can't track what a task has done, what decisions were made, or where they left off. A skill that persists task-scoped knowledge in structured markdown would let agents pick up work without re-discovering context from scratch, and give humans a readable audit trail they can review or promote into real documentation.
8
+
9
+ ## How we might do it
10
+ **Possibly build on top of `bd remember`** rather than creating a separate storage system. Worth exploring whether `bd remember`'s existing infrastructure (persistence, cross-session survival, auto-injection) could be extended with task-scoping and structure, vs building something standalone.
11
+ - **Task-linked** — memories keyed to specific bead/task IDs so they can be retrieved in context
12
+ - **Progressively discoverable** — the agent recalls relevant memories as it picks up work, not all at once
13
+ - **Structured** — consistent format that's easy to scan, edit, or promote
14
+ - **Promotable** — easy to elevate a memory into real repo documentation (e.g. `docs/`, `AGENTS.md`) once it's proven stable
15
+
16
+ If `bd remember` turns out to be the right foundation, the skill would add **task-scoping discipline, structure, and a promotion workflow** on top. But that's to be determined.
17
+
18
+ ## When to think about it
19
+ - After the current skill set stabilises (refactor-to-template work, bead workflow, CI/CD pipeline)
20
+ - Not blocked by anything, but benefits from a stable foundation
21
+
22
+ ## Priority
23
+ Low / backlog — useful but not urgent. Current memory surfaces (bd remember, context-mode) cover some of the gap already.
24
+
25
+ ## Open questions
26
+ - What triggers writing a memory? (Agent decides? Skill hook on task close? Specific prompts?)
27
+ - What does "progressively discoverable" mean in practice — agent reads task memories at session start, or on-demand when picking up a task?
28
+ - What does "elevate into docs" look like — export memory to markdown file, or just reference the memory in docs?
29
+ - How to structure memory keys for task-scoping? (e.g. `task-<bead-id>-<topic>`, or a naming convention?)
30
+
31
+ ## Notes
32
+ - **What bd remember already provides**: persistent cross-session memories, auto-injection at `bd prime`, searchable via `bd memories <keyword>`, stored in Dolt database.
33
+ - **Worth exploring**: could this skill layer task-scoping discipline (memories keyed to bead IDs), structured format, progressive discovery (not all memories at once), and a promotion workflow on top of `bd remember`? Or does it need its own system?
34
+ - Could be a **PI extension** (event hooks) rather than a skill (invoked on-demand) if memories should be written automatically during task work.
@@ -0,0 +1,43 @@
1
+ # Idea: qa-extension
2
+
3
+ ## Status
4
+ Backlog idea (not implementation-ready)
5
+
6
+ ## Created
7
+ 2026-07-12
8
+
9
+ ## Problem
10
+ When an agent needs clarification during a task (e.g. during a grilling session, resolving ambiguity, or making a recommendation), it has no structured way to ask the user a question and wait for an answer. The current workaround is unstructured prompting — the agent guesses, rambles, or proceeds with incomplete information. This makes grilling sessions less productive and wastes turns.
11
+
12
+ ## Who benefits
13
+ Anyone using PI agents for interactive work — especially during planning, grilling, and design sessions where the model needs to ask a series of questions one at a time and get focused answers.
14
+
15
+ ## Proposed outcome
16
+ A PI extension that registers a `qa` or `ask` tool that the LLM can call to ask the user a question. The tool:
17
+ - Presents the question (and optionally multiple-choice options or a recommendation)
18
+ - Pauses the agent and waits for the user's response
19
+ - Returns the user's answer to the model so it can continue
20
+ - Supports multi-turn Q&A sessions (series of questions)
21
+
22
+ This mirrors the built-in `ask_clarification` / `question` tools in Claude Code, GitHub Copilot Chat, and similar coding agents.
23
+
24
+ ## Validity check
25
+ - Evidence we already have: The PI extension API supports custom tools with user interaction via `ctx.ui` (input, confirm, select). The `subagent` extension already demonstrates complex async tool patterns. Claude Code and Copilot both ship this — it's a proven pattern.
26
+ - Riskiest assumption: That the tool execution model in PI can support a "pause and wait for user input" flow without blocking the agent loop awkwardly.
27
+ - What would invalidate this idea: If PI adds a built-in `ask_user` tool, or if the UX of blocking the agent loop for input feels worse than the current unstructured approach.
28
+
29
+ ## Constraints
30
+ - Must work in both TUI and RPC modes (graceful fallback in non-interactive modes)
31
+ - Should support at minimum: free-text input, confirm/deny, and multiple-choice selection
32
+ - Questions and answers should be visible in the session history so they survive compaction
33
+ - Must handle abort (Ctrl+C mid-question) gracefully
34
+
35
+ ## Next validation step
36
+ 1. **Investigate existing extensions first** — search PI's built-in tools, extension registry, and community repos for an existing `ask`/`qa`/`question` tool before building. May already be available.
37
+ 2. If no existing extension: check the PI tool execution model to see if a custom tool can return a partial result and then receive follow-up input from the user. Look at how `ctx.ui.input()` and `ctx.ui.confirm()` behave inside tool execution — can they block and return, or do they need a different pattern?
38
+
39
+ ## Notes
40
+ - **Needs investigation** — check for existing PI extensions/tools before building.
41
+ - Initial conversation 2026-07-12. Motivated by making grilling sessions more efficient — the grill-me skill asks one question at a time, and a structured Q&A tool would make that flow tighter.
42
+ - Related to `grill-me` skill (`skills/productivity/grill-me/SKILL.md`) — this extension could become the runtime that grill-me delegates its questioning to.
43
+ - Possible names: `/ask`, `qa`, `question` tool.
@@ -0,0 +1,28 @@
1
+ # Idea: Unified CI Pipeline with Parallel Checks
2
+
3
+ ## Status
4
+ Backlog idea (not implementation-ready)
5
+
6
+ ## Why it might be useful
7
+ The current CI setup has two problems:
8
+ 1. **Slow feedback** — checks run serially, making the pipeline slower than it needs to be.
9
+ 2. **Broken releases** — the release job (version branch creation) is a separate pipeline, so it can fire even when checks fail. A broken commit can reach the version branch.
10
+
11
+ Combining them gives faster feedback (parallel checks) and a safety gate (release step only runs if all checks pass).
12
+
13
+ ## How we might do it
14
+ - Merge the check pipeline and release pipeline into a single pipeline.
15
+ - Fan out all checks to run in parallel.
16
+ - Make the version branch creation a downstream job/step that depends on all checks passing.
17
+
18
+ ## When to think about it
19
+ When CI pipeline speed or release safety becomes a recurring friction — e.g. after the changesets/release workflow is fully set up and seeing real traffic.
20
+
21
+ ## Priority
22
+ P2 — infrastructure quality-of-life. Not blocking current work, but a clear improvement once the release flow stabilises.
23
+
24
+ ## Notes
25
+ - Setup job with artifact infrastructure added (2026-08): install + build now happen once in a `setup` job, artifacts are shared with downstream jobs via upload/download-artifact. This is the first step toward the unified pipeline vision.
26
+ - Depends on the changesets release workflow being in place (P1 beads `agnt-ctx-d1ht`, `agnt-ctx-5bcu`).
27
+ - Should be straightforward once the pipeline shape is settled.
28
+ - **Release pipeline fires on every push to main** — this wastes CI minutes. It should only run when there are changesets to process (e.g. when the version packages PR is merged, or when new changesets land on main). Add a path filter or a pre-check that skips the job when no `.changeset/*.md` files changed.
@@ -29,6 +29,14 @@ Optional fields:
29
29
  - Add one rationale sentence for non-obvious rules so behavior generalizes in novel cases.
30
30
  - Avoid ALL-CAPS emphasis.
31
31
 
32
+ ## Tool references
33
+
34
+ Reference agent tools by `{{TOOL:name}}` token (canonical copilot name), never a
35
+ hardcoded harness-specific name such as `bash`, `task`, or `read_agent` — installers
36
+ substitute the per-harness name from `token-map.json` at install time. Add any new tool
37
+ to the map's `tools` section in the same change; unknown tokens are hard errors. See
38
+ `token-map.README.md` for the full authoring rules.
39
+
32
40
  ## Required sections
33
41
 
34
42
  Every skill must include:
@@ -81,6 +89,7 @@ Provide completion gates that are testable and stage-scoped.
81
89
 
82
90
  A skill passes anatomy review when:
83
91
  - [ ] Front matter uses required fields and valid description format.
92
+ - [ ] Tool references use `{{TOOL:name}}` tokens, not hardcoded tool names.
84
93
  - [ ] Required sections exist and follow canonical ordering.
85
94
  - [ ] Optional sections (if present) include what/when/example guidance.
86
95
  - [ ] Verification checklist contains concrete, machine-checkable items.
@@ -0,0 +1,54 @@
1
+ # Agent Modes Extension
2
+
3
+ Makes the agent-cortex agents (ralph, ralph-plan, plan, strategy) available as
4
+ switchable PI modes. Each mode injects the agent's full system prompt into the
5
+ running context, restricts tools to the agent's declared tool set, and shows a
6
+ status indicator with the active agent name.
7
+
8
+ ## Usage
9
+
10
+ | Command | Description |
11
+ | --- | --- |
12
+ | `/agent` | Show the agent mode selector |
13
+ | `/agent <name>` | Switch to an agent mode directly (e.g. `/agent ralph`) |
14
+ | `/agent default` | Return to default mode (full tool access) |
15
+ | `Ctrl+Shift+A` | Cycle through agent modes |
16
+ | `--agent <name>` | Start PI in a specific agent mode |
17
+
18
+ ## How agents are discovered
19
+
20
+ Agents are read from the **composable source format** in the package's
21
+ `agents/` directory:
22
+
23
+ ```
24
+ agents/<name>/
25
+ ├── agent.md # Shared body (harness-agnostic)
26
+ └── pi/
27
+ ├── frontmatter.json # PI metadata: name, description, tools
28
+ └── <section>.md # Optional sections referenced by {{SECTION:name}}
29
+ ```
30
+
31
+ The PI system prompt is composed from `agent.md` per the token-map.json
32
+ contract:
33
+
34
+ 1. `{{SECTION:name}}` tokens are replaced with the agent's `pi/<name>.md`.
35
+ 2. `{{TOOL:key}}` / `{{PATH:key}}` tokens are substituted against the pi column
36
+ of `token-map.json`, with the plugin root resolved from the actual extension
37
+ location. Tools without a PI equivalent (`ask_user`, `skill`) are omitted
38
+ from the tool set.
39
+
40
+ Flat `agents/*.agent.md` files are parsed as a fallback when an agent has no
41
+ composable directory — they are generated output (scripts/build-copilot-agents.mjs)
42
+ but may exist for non-migrated agents. A composable directory always wins over its
43
+ flat counterpart for the same agent id.
44
+
45
+ ## Development
46
+
47
+ Discovery and prompt composition live in `discover.ts` (unit-tested against
48
+ fixture directories in `discover.test.ts`); `index.ts` only wires discovery
49
+ into the extension API.
50
+
51
+ ```bash
52
+ pnpm test # run discover.test.ts
53
+ pnpm typecheck # tsc --noEmit
54
+ ```