@blackbelt-technology/pi-dashboard-extension 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/.pi/skills/browser/SKILL.md +69 -28
  2. package/.pi/skills/browser/UPSTREAM.md +6 -3
  3. package/.pi/skills/browser/references/challenge.md +183 -0
  4. package/.pi/skills/browser/references/dashboard-relay.md +150 -0
  5. package/.pi/skills/browser/references/own-browser.md +7 -1
  6. package/.pi/skills/doctor/SKILL.md +1 -0
  7. package/.pi/skills/doctor/_lib/checks.ts +133 -0
  8. package/.pi/skills/doctor/_lib/derive-tokens.ts +4 -0
  9. package/.pi/skills/doctor/modules/apple-tools.md +2 -1
  10. package/.pi/skills/doctor/modules/mcp-builtin.knowledge.hash +1 -0
  11. package/.pi/skills/doctor/modules/mcp-builtin.md +61 -0
  12. package/.pi/skills/doctor/modules/pi-resolution.knowledge.hash +1 -1
  13. package/.pi/skills/doctor/modules/plugins-bridges.md +14 -1
  14. package/.pi/skills/pi-dashboard/SKILL.md +10 -3
  15. package/.pi/skills/pi-dashboard/scripts/dashboard-bus.ts +4 -4
  16. package/.pi/skills/project-init/SKILL.md +40 -27
  17. package/.pi/skills/project-init/profiles/coding/AGENTS.md.tmpl +0 -23
  18. package/package.json +19 -16
  19. package/src/ask-user-tool.ts +4 -0
  20. package/src/bridge-activation.ts +26 -0
  21. package/src/bridge-context.ts +21 -19
  22. package/src/bridge-default-model-gate.ts +38 -0
  23. package/src/bridge-polling.ts +148 -0
  24. package/src/bridge.ts +954 -248
  25. package/src/canvas-tool.ts +5 -0
  26. package/src/command-handler.ts +77 -31
  27. package/src/connection.ts +481 -16
  28. package/src/custom-entry-forward.ts +92 -0
  29. package/src/endpoint-resolution.ts +32 -0
  30. package/src/event-forwarder.ts +42 -0
  31. package/src/extension-identity.ts +59 -0
  32. package/src/git-dir-watcher.ts +79 -0
  33. package/src/git-poll.ts +45 -12
  34. package/src/git-probe-scheduler.ts +119 -0
  35. package/src/git-tracker.ts +284 -0
  36. package/src/instance-verification.ts +31 -0
  37. package/src/mcp-token-delivery.ts +147 -0
  38. package/src/message-update-coalescer.ts +340 -0
  39. package/src/model-tracker.ts +118 -35
  40. package/src/notify-proxy.ts +3 -0
  41. package/src/path-gate/decide.ts +149 -0
  42. package/src/path-gate/grant-cache.ts +71 -0
  43. package/src/path-gate/grant-link.ts +108 -0
  44. package/src/path-gate/handler.ts +307 -0
  45. package/src/path-gate/index.ts +155 -0
  46. package/src/path-gate/resolve.ts +126 -0
  47. package/src/path-gate/roots.ts +137 -0
  48. package/src/path-gate/suppression.ts +27 -0
  49. package/src/pending-prompt-emitter.ts +59 -0
  50. package/src/pi-env.d.ts +2 -10
  51. package/src/plugin-request-client.ts +114 -0
  52. package/src/poll-cost.ts +40 -0
  53. package/src/pr-status.ts +338 -0
  54. package/src/process-metrics.ts +77 -1
  55. package/src/process-scan-scheduler.ts +137 -0
  56. package/src/process-scanner.ts +226 -247
  57. package/src/project-init/dox-kb-config.ts +3 -0
  58. package/src/project-init/scaffold.ts +1 -4
  59. package/src/project-init/seed-doctrine.ts +23 -60
  60. package/src/prompt-bus.ts +13 -0
  61. package/src/provider-register.ts +6 -0
  62. package/src/retry-tracker.ts +0 -7
  63. package/src/role-manager.ts +22 -95
  64. package/src/role-model-tools.ts +6 -0
  65. package/src/server-auto-start.ts +192 -23
  66. package/src/server-launcher.ts +70 -34
  67. package/src/session-move.ts +4 -4
  68. package/src/session-sync.ts +51 -15
  69. package/src/slash-dispatch.ts +66 -81
  70. package/src/subagent-fanout-admission.ts +234 -0
  71. package/src/subagent-saturation.ts +196 -0
  72. package/src/terminal-reload.ts +298 -0
  73. package/src/tui-prompt-adapter.ts +13 -1
  74. package/src/usage-drain.ts +167 -0
  75. package/src/vcs-info.ts +261 -63
  76. package/.pi/skills/project-init/dox-doctrine.md +0 -146
  77. package/src/agent-settled.ts +0 -90
  78. package/src/transcript-request-guard.ts +0 -76
@@ -8,7 +8,10 @@
8
8
  * See change: add-modular-doctor-skill (design.md D4/D8, spec: Derive-on-run).
9
9
  */
10
10
 
11
+ import { readFileSync } from "node:fs";
11
12
  import { createRequire } from "node:module";
13
+ import os from "node:os";
14
+ import path from "node:path";
12
15
  import {
13
16
  enumeratePiInstalls,
14
17
  type PiInstall,
@@ -121,3 +124,133 @@ export function detectNameSkew(
121
124
  return { resolvedName: null, staleNames: stale, tier: null, resolvedPath: null };
122
125
  }
123
126
 
127
+
128
+ // ── pi built-in MCP (change: migrate-mcp-to-pi-builtin) ─────────────────────
129
+
130
+ export interface McpBuiltinFinding {
131
+ id: "adapter-disables-builtin" | "operator-entry-shadows-registration" | "mcp-json-not-strict";
132
+ /** The file the finding is about. */
133
+ path: string;
134
+ message: string;
135
+ }
136
+
137
+ export interface McpBuiltinCheckOptions {
138
+ /** Defaults to `$PI_CODING_AGENT_DIR` or `~/.pi/agent`. */
139
+ agentDir?: string;
140
+ /** When set, `<cwd>/.pi/settings.json` and `<cwd>/.pi/mcp.json` are checked too. */
141
+ cwd?: string;
142
+ /** Test seam; defaults to `fs.readFileSync` (null when absent). */
143
+ readFile?: (path: string) => string | null;
144
+ }
145
+
146
+ const ADAPTER_SOURCE = "npm:pi-mcp-adapter";
147
+
148
+ function packageSourceOf(entry: unknown): string | null {
149
+ if (typeof entry === "string") return entry;
150
+ if (entry && typeof entry === "object" && typeof (entry as { source?: unknown }).source === "string") {
151
+ return (entry as { source: string }).source;
152
+ }
153
+ return null;
154
+ }
155
+
156
+ function isAdapterSource(source: string): boolean {
157
+ try {
158
+ if (sourcesMatch(source, ADAPTER_SOURCE)) return true;
159
+ } catch {
160
+ /* unparseable source → fall through to the path test */
161
+ }
162
+ return /(^|[\\/])pi-mcp-adapter[\\/]?$/.test(source);
163
+ }
164
+
165
+ /**
166
+ * Three read-only diagnostics for pi's built-in MCP, one finding each:
167
+ * - `pi-mcp-adapter` in a settings `packages[]` registers `/mcp` and so
168
+ * DISABLES the built-in MCP — and with it the dashboard's per-session
169
+ * `pi-dashboard` registration (the bridge cannot see this; pi reports it as
170
+ * an extension error, not a throw).
171
+ * - an operator-authored `pi-dashboard` entry in the global `mcp.json` takes
172
+ * precedence over the registration (the dashboard-provisioned shape is
173
+ * removed at server start and is NOT reported).
174
+ * - an `mcp.json` that is not strict JSON (comments, trailing commas) is
175
+ * skipped WHOLE by pi; the file path is named.
176
+ * Never writes, never throws.
177
+ */
178
+ export function checkMcpBuiltin(opts: McpBuiltinCheckOptions = {}): McpBuiltinFinding[] {
179
+ const agentDir =
180
+ opts.agentDir ?? (process.env.PI_CODING_AGENT_DIR || path.join(os.homedir(), ".pi", "agent"));
181
+ const read =
182
+ opts.readFile ??
183
+ ((p: string): string | null => {
184
+ try {
185
+ return readFileSync(p, "utf8");
186
+ } catch {
187
+ return null;
188
+ }
189
+ });
190
+ const findings: McpBuiltinFinding[] = [];
191
+
192
+ const settingsFiles = [path.join(agentDir, "settings.json")];
193
+ if (opts.cwd) settingsFiles.push(path.join(opts.cwd, ".pi", "settings.json"));
194
+ for (const file of settingsFiles) {
195
+ const raw = read(file);
196
+ if (raw === null) continue;
197
+ let packages: unknown;
198
+ try {
199
+ packages = (JSON.parse(raw) as { packages?: unknown }).packages;
200
+ } catch {
201
+ continue;
202
+ }
203
+ if (!Array.isArray(packages)) continue;
204
+ if (packages.some((e) => {
205
+ const s = packageSourceOf(e);
206
+ return s !== null && isAdapterSource(s);
207
+ })) {
208
+ findings.push({
209
+ id: "adapter-disables-builtin",
210
+ path: file,
211
+ message:
212
+ `pi-mcp-adapter is listed in ${file} packages[]: it takes over /mcp and DISABLES pi's built-in MCP, ` +
213
+ "so the dashboard's pi-dashboard MCP tools are unavailable in sessions. Fix: remove it from packages[] " +
214
+ "(convert adapter-only `disabled: true` entries to `enabled: false` in the MCP settings first).",
215
+ });
216
+ break;
217
+ }
218
+ }
219
+
220
+ const mcpFiles = [path.join(agentDir, "mcp.json")];
221
+ if (opts.cwd) mcpFiles.push(path.join(opts.cwd, ".pi", "mcp.json"));
222
+ for (const [i, file] of mcpFiles.entries()) {
223
+ const raw = read(file);
224
+ if (raw === null) continue;
225
+ let parsed: unknown;
226
+ try {
227
+ parsed = JSON.parse(raw);
228
+ } catch (e) {
229
+ findings.push({
230
+ id: "mcp-json-not-strict",
231
+ path: file,
232
+ message: `${file} is not strict JSON (${(e as Error).message}); pi skips the whole file. Remove comments and trailing commas.`,
233
+ });
234
+ continue;
235
+ }
236
+ if (i !== 0) continue; // the shadow check concerns the global file only
237
+ const entry = (parsed as { mcpServers?: Record<string, unknown> } | null)?.mcpServers?.["pi-dashboard"];
238
+ if (entry === undefined || entry === null || typeof entry !== "object") continue;
239
+ const rhc = (entry as { requestHeadersCommand?: { command?: unknown; args?: unknown } }).requestHeadersCommand;
240
+ const provisioned =
241
+ rhc?.command === "node" &&
242
+ Array.isArray(rhc.args) &&
243
+ typeof rhc.args[0] === "string" &&
244
+ /(^|[\\/])header-command\.mjs$/.test(rhc.args[0]);
245
+ if (!provisioned) {
246
+ findings.push({
247
+ id: "operator-entry-shadows-registration",
248
+ path: file,
249
+ message:
250
+ `${file} defines its own "pi-dashboard" MCP server; pi prefers it over the dashboard's per-session ` +
251
+ "registration. Remove or rename it unless you intend to override the dashboard endpoint.",
252
+ });
253
+ }
254
+ }
255
+ return findings;
256
+ }
@@ -26,6 +26,10 @@ export const MODULE_TOKEN_SOURCES: Record<string, string[]> = {
26
26
  "install-topology": ["packages/shared/src/dashboard-paths.ts"],
27
27
  "model-resolution": ["packages/extension/src/provider-register.ts"],
28
28
  "oauth-redirect-base": ["packages/server/src/auth/auth.ts", "packages/server/src/routes/system-routes.ts"],
29
+ "mcp-builtin": [
30
+ "packages/extension/src/mcp-token-delivery.ts",
31
+ "packages/mcp-server-plugin/src/server/legacy-entry-migration.ts",
32
+ ],
29
33
  };
30
34
 
31
35
  /**
@@ -16,7 +16,8 @@ derives-from:
16
16
 
17
17
  ## SCOPE
18
18
  Whether iMCP is provisioned for the `apple-tools` plugin on this host: platform,
19
- macOS version floor, `imcp-server` discovery, and the two config writes. macOS
19
+ macOS version floor, `imcp-server` discovery, and the `mcp.json` write (pi's
20
+ built-in MCP; `settings.json` is never written). macOS
20
21
  only — a non-macOS host is inert, never a fault.
21
22
 
22
23
  ## KNOWLEDGE
@@ -0,0 +1 @@
1
+ d48ae6dceec2cfc5
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: mcp-builtin
3
+ scope: pi's built-in MCP and the dashboard's per-session pi-dashboard registration.
4
+ symptoms:
5
+ - dashboard mcp tools missing
6
+ - pi-dashboard mcp server not connected
7
+ - mcp tools not found in session
8
+ - pi-mcp-adapter installed
9
+ - mcp.json ignored
10
+ - built-in mcp disabled
11
+ depends-on: [pi-resolution]
12
+ derives-from:
13
+ - packages/extension/.pi/skills/doctor/_lib/checks.ts (checkMcpBuiltin)
14
+ - packages/extension/src/mcp-token-delivery.ts (createMcpDashboardRegistrar)
15
+ - packages/mcp-server-plugin/src/server/legacy-entry-migration.ts (isProvisionedDashboardEntry)
16
+ ---
17
+
18
+ ## SCOPE
19
+ Whether a session can reach the dashboard's `/mcp` through pi's BUILT-IN MCP:
20
+ the bridge registers `pi-dashboard` per session with `pi.registerMcpServer()`
21
+ (`url` + `Authorization: Bearer <token>`, `exposure: "deferred"`). Three host
22
+ conditions silently break that; this module names each one.
23
+
24
+ ## KNOWLEDGE
25
+ - An installed `pi-mcp-adapter` registers `/mcp` and DISABLES pi's built-in
26
+ MCP. The registration is then reported by pi as an extension error, not
27
+ thrown, so the bridge cannot see it. The dashboard never removes the package
28
+ (operator's choice).
29
+ - An `mcp.json` entry named `pi-dashboard` takes PRECEDENCE over the bridge
30
+ registration. The dashboard-provisioned shape (`requestHeadersCommand.command
31
+ === "node"`, `args[0]` ending `header-command.mjs`) is removed at server start;
32
+ any other shape is the operator's and is only reported.
33
+ - pi parses `mcp.json` with strict `JSON.parse`; comments or trailing commas make
34
+ pi skip the WHOLE file (every server in it).
35
+ - The bridge's own guard (registration API missing/throwing, delivery without
36
+ `url`) is logged by the server as `mcp.dashboard_registration_unavailable
37
+ session=<id> reason=<reason>` in `~/.pi/dashboard/server.log`.
38
+
39
+ ## CHECKS
40
+ - `checkMcpBuiltin({ agentDir, cwd })` from `_lib/checks.ts` → one finding per
41
+ condition, file path named: `adapter-disables-builtin`,
42
+ `operator-entry-shadows-registration`, `mcp-json-not-strict`. Read-only.
43
+ - `grep mcp.dashboard_registration_unavailable ~/.pi/dashboard/server.log`.
44
+ - `pi mcp list --json` in the session cwd: `pi-dashboard` is NOT listed there
45
+ (registrations are per session); a listed `pi-dashboard` is a file entry.
46
+
47
+ ## FIX ROUTING
48
+ - `adapter-disables-builtin` → remove `pi-mcp-adapter` from `settings.json`
49
+ `packages[]` (convert adapter `disabled: true` entries to `enabled: false` in
50
+ Settings → MCP first, or they become active), then reload sessions.
51
+ - `operator-entry-shadows-registration` → delete/rename that entry unless the
52
+ override is intended.
53
+ - `mcp-json-not-strict` → remove comments / trailing commas from the named file.
54
+ - `registration_unavailable reason=no-url` → dashboard server older than the
55
+ bridge: update/restart the dashboard. `api-missing` → pi older than 1.0.0.
56
+
57
+ ## DERIVES-FROM
58
+ Source: `packages/extension/.pi/skills/doctor/_lib/checks.ts`,
59
+ `packages/extension/src/mcp-token-delivery.ts`,
60
+ `packages/mcp-server-plugin/src/server/legacy-entry-migration.ts`.
61
+ Hash sidecar: `mcp-builtin.knowledge.hash`.
@@ -1 +1 @@
1
- 7cf1f8402e98e7af
1
+ dc91e569d6caa71c
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: plugins-bridges
3
- scope: Surface bridge registration (packages[] vs dashboardPluginBridges) + activation.
3
+ scope: Surface bridge registration (packages[] vs dashboardPluginBridges) + activation, and kb-extension presence for DOX doctrine injection.
4
4
  symptoms:
5
5
  - flow wont show
6
6
  - bridge not registered
@@ -8,6 +8,9 @@ symptoms:
8
8
  - bridge misregistered
9
9
  - plugin not loading
10
10
  - bridge degraded
11
+ - doctrine not injected
12
+ - dox doctrine missing
13
+ - first-contact nudge keeps firing
11
14
  depends-on:
12
15
  - peers
13
16
  derives-from:
@@ -41,6 +44,13 @@ partial load. A disabled dashboard plugin auto-deregisters its bridge entirely.
41
44
  `packages[]`, not `dashboardPluginBridges`-only or missing.
42
45
  - Anthropic bridge not active → report status + the per-peer probe result from
43
46
  the `peers` module.
47
+ - **doctrine configured but kb extension not loaded**: when the project's
48
+ `.pi/dashboard/knowledge_base.json` supplies a `doctrine` key but
49
+ `pi-dashboard-kb-extension` is ABSENT from `settings.json#packages[]`, report
50
+ FAIL: "doctrine configured but kb extension not loaded" — the project recorded
51
+ a doctrine choice, yet nothing injects the text. A pointer-only `AGENTS.md`
52
+ (`<!-- dox-doctrine -->`, no `doctrine` key) is the supported opt-out — the
53
+ project may never install the extension — so it is NOT a finding.
44
54
 
45
55
  ## FIX ROUTING
46
56
  - misregistered (dashboardPluginBridges-only) → dashboard ≥ 0.5.4 writes both;
@@ -48,6 +58,9 @@ partial load. A disabled dashboard plugin auto-deregisters its bridge entirely.
48
58
  - `waiting_peers` → fix the failed peer (peers module), then respawn the session
49
59
  (bridges wire hooks once per process).
50
60
  - plugin disabled → enable it → the bridge auto-registers.
61
+ - doctrine configured but kb extension not loaded → add
62
+ `@blackbelt-technology/pi-dashboard-kb-extension` to `settings.json#packages[]`
63
+ (or `pi install` it), then reload the session.
51
64
 
52
65
  ## DERIVES-FROM
53
66
  Live: `settings.json` packages[]/dashboardPluginBridges. Server-enriched:
@@ -41,7 +41,7 @@ orchestration (spawn → prompt → until idle → read → plugin) using `conne
41
41
  ### Tier split
42
42
 
43
43
  - **COMMAND verbs → bus** (`dashboard-bus.ts`): abort, send_prompt, spawn,
44
- resume, flow_control, set_model, set_thinking_level, rename, hide/unhide,
44
+ resume, flow_control, set_model, set_thinking_level, rename, archive/unarchive,
45
45
  attach/detach_proposal, plugin goal.
46
46
  - **READ-ONLY + no-WS-twin → REST** (`dashboard-api.sh`): session / health /
47
47
  config reads, git ops, grep/browse, `plugin_config_write`, tunnel, peer scan,
@@ -101,8 +101,15 @@ curl -s -b "pi_dash_token=YOUR_JWT" "$BASE/api/sessions" | jq .
101
101
  | Abort | `curl -s -X POST "$BASE/api/session/ID/abort" -H 'Content-Type: application/json' -d '{}'` |
102
102
  | Shutdown session | `curl -s -X POST "$BASE/api/session/ID/shutdown" -H 'Content-Type: application/json' -d '{}'` |
103
103
  | Rename | `curl -s -X POST "$BASE/api/session/ID/rename" -H 'Content-Type: application/json' -d '{"name":"my-name"}'` |
104
- | Hide | `curl -s -X POST "$BASE/api/session/ID/hide" -H 'Content-Type: application/json' -d '{}'` |
105
- | Unhide | `curl -s -X POST "$BASE/api/session/ID/unhide" -H 'Content-Type: application/json' -d '{}'` |
104
+ | Archive | `curl -s -X POST "$BASE/api/session/ID/archive" -H 'Content-Type: application/json' -d '{}'` |
105
+ | Unarchive | `curl -s -X POST "$BASE/api/session/ID/unarchive" -H 'Content-Type: application/json' -d '{}'` |
106
+
107
+ > `GET /api/sessions` lists RESIDENT sessions only — archived sessions are excluded.
108
+ > Resolve an archived id with `GET /api/sessions/archived?q=<text>` (or
109
+ > `?cwd=<group-path>`), or read one row with `GET /api/sessions/archived/:id`.
110
+ > Archiving an alive-but-idle session terminates its pi process and completes on
111
+ > the ended transition; a running or interrupted (`live:true`) session is refused
112
+ > (WS error / REST 409).
106
113
  | Spawn new | `curl -s -X POST "$BASE/api/session/spawn" -H 'Content-Type: application/json' -d '{"cwd":"/path"}'` |
107
114
  | Resume/Fork | `curl -s -X POST "$BASE/api/session/ID/resume" -H 'Content-Type: application/json' -d '{"mode":"continue"}'` |
108
115
 
@@ -18,7 +18,7 @@
18
18
  * npx tsx ./scripts/dashboard-bus.ts model <id-prefix> <provider> <modelId>
19
19
  * npx tsx ./scripts/dashboard-bus.ts thinking <id-prefix> <level>
20
20
  * npx tsx ./scripts/dashboard-bus.ts rename <id-prefix> <name...>
21
- * npx tsx ./scripts/dashboard-bus.ts hide|unhide <id-prefix>
21
+ * npx tsx ./scripts/dashboard-bus.ts archive|unarchive <id-prefix>
22
22
  * npx tsx ./scripts/dashboard-bus.ts resume <id-prefix> [--fork]
23
23
  * npx tsx ./scripts/dashboard-bus.ts flow <id-prefix> <abort|toggle_autonomous|dismiss_summary>
24
24
  * npx tsx ./scripts/dashboard-bus.ts proposal-attach <id-prefix> <change>
@@ -149,10 +149,10 @@ async function main(): Promise<void> {
149
149
  console.log(`renamed ${id.slice(0, 8)} → ${name}`);
150
150
  break;
151
151
  }
152
- case "hide":
153
- case "unhide": {
152
+ case "archive":
153
+ case "unarchive": {
154
154
  const id = resolveId(pos[0] ?? die(`${cmd} needs <id-prefix>`));
155
- client.send({ type: cmd === "hide" ? "hide_session" : "unhide_session", sessionId: id });
155
+ client.send({ type: cmd === "archive" ? "archive_session" : "unarchive_session", sessionId: id });
156
156
  console.log(`${cmd} ${id.slice(0, 8)}`);
157
157
  break;
158
158
  }
@@ -121,8 +121,8 @@ confirm). The writes for profile `<p>` are:
121
121
 
122
122
  When `DOX_ENABLED` is true, ALSO name in the preview:
123
123
 
124
- - the DOX doctrine seed appended to `./AGENTS.md` (see Step 5)
125
- - the kb toolset flip written to `./.pi/dashboard/knowledge_base.json`
124
+ - the DOX pointer block appended to `./AGENTS.md` (see Step 5)
125
+ - the `doctrine` choice + kb toolset flip written to `./.pi/dashboard/knowledge_base.json`
126
126
 
127
127
  When `OPENSPEC_INIT` is true, ALSO disclose the side effect (see Step 6) — NOT a
128
128
  plain file write:
@@ -200,49 +200,62 @@ branch, never on the present/installed path (so a successfully-wired project
200
200
  never carries a false "not detected" line). The install is always user-global
201
201
  and never forced.
202
202
 
203
- ## Step 5 — DOX doctrine seed (only when `DOX_ENABLED` is true)
203
+ ## Step 5 — DOX pointer seed (only when `DOX_ENABLED` is true)
204
204
 
205
205
  > Gated on the user's Step 3a answer (`DOX_ENABLED`), NOT the raw `profile.json`
206
206
  > `dox` flag — the flag only supplied the default. Skip this step entirely when
207
207
  > the user declined DOX.
208
208
 
209
+ Do NOT copy any doctrine text. The per-turn DOX doctrine (READ + WRITE) is
210
+ injected by the `pi-dashboard-kb-extension`; the project's `AGENTS.md` carries
211
+ only a marker + pointer block. Tune it via `.pi/dashboard/knowledge_base.json`.
209
212
 
210
- The canonical doctrine ships once at `<skill>/dox-doctrine.md`. Do NOT copy the
211
- whole file. Seed a single block into `./AGENTS.md` **only when it does not
212
- already carry the marker** `<!-- dox-doctrine -->` (idempotent — if the marker
213
- is present, skip this step entirely).
213
+ **1. Seed the pointer block.** Append it to `./AGENTS.md` **only when it does
214
+ not already carry the marker** `<!-- dox-doctrine -->` (idempotent — if the
215
+ marker is present, skip this step entirely):
214
216
 
215
- Compose the seeded block as:
217
+ ```markdown
218
+ <!-- dox-doctrine -->
216
219
 
217
- 1. The marker line `<!-- dox-doctrine -->`
218
- 2. The WRITE discipline — the text between `<!-- dox:write:start -->` and
219
- `<!-- dox:write:end -->` in `dox-doctrine.md`.
220
- 3. ONE READ discipline variant — **skip this item entirely when the chosen
221
- profile's `AGENTS.md.tmpl` already embeds a `## Finding docs (READ
222
- discipline)` section** (the shipped `coding` profile does; seeding it again
223
- would duplicate the gate). Seed only the WRITE discipline in that case.
224
- Otherwise:
225
- - If the kb toolset is wired (this profile writes
226
- `knowledge_base.json` with `indexAgentsFiles`/`directoryLevelAgents`),
227
- use the text between `<!-- dox:read:kb:start -->` and
228
- `<!-- dox:read:kb:end -->` (references `kb agents` / `kb_search`).
229
- - Otherwise use the text between `<!-- dox:read:manual:start -->` and
230
- `<!-- dox:read:manual:end -->` (manual chain-walk; no kb references).
220
+ ## DOX doctrine
231
221
 
232
- Strip the delimiter comments from the seeded text. Append the block to
233
- `./AGENTS.md`.
222
+ Per-turn DOX doctrine — the kb-first READ discipline and the directory `AGENTS.md`
223
+ WRITE discipline — is injected by the `pi-dashboard-kb-extension`. Tune it in
224
+ `.pi/dashboard/knowledge_base.json` under the `doctrine` key (`inject`, `write`).
225
+ ```
226
+
227
+ **2. Record the doctrine choice.** Read-merge-write
228
+ `./.pi/dashboard/knowledge_base.json` — read the file if present, set ONLY the
229
+ `doctrine` key, preserve every other key, write valid JSON. Since `DOX_ENABLED`
230
+ is true here, write:
231
+
232
+ ```json
233
+ "doctrine": { "inject": "kb", "write": true }
234
+ ```
234
235
 
235
- Then write `./.pi/dashboard/knowledge_base.json` (when absent) enabling the
236
- directory-level AGENTS.md toolset:
236
+ When the file is absent, also enable the directory-level AGENTS.md toolset:
237
237
 
238
238
  ```json
239
239
  {
240
240
  "sources": [{ "kind": "filesystem", "ref": "." }],
241
241
  "indexAgentsFiles": true,
242
- "directoryLevelAgents": { "enabled": true }
242
+ "directoryLevelAgents": { "enabled": true },
243
+ "doctrine": { "inject": "kb", "write": true }
243
244
  }
244
245
  ```
245
246
 
247
+ **3. Scaffold the directory `AGENTS.md` tree** (path-only rows):
248
+
249
+ ```bash
250
+ kb dox init
251
+ ```
252
+
253
+ **4. Offer `dox-describe`.** After the tree is scaffolded, ask the user
254
+ (`ask_user` confirm): "Fill the empty Purpose cells now with `dox-describe`?
255
+ (one subagent per `AGENTS.md`, plan-then-confirm, ≤50 rows per run)". On yes,
256
+ invoke the `dox-describe` skill (ships with `packages/kb-extension`); on no,
257
+ tell the user they can run it later.
258
+
246
259
  ## Step 6 — Run OpenSpec init (only when `OPENSPEC_INIT` is true)
247
260
 
248
261
  Gated on the user's Step 3b answer (`OPENSPEC_INIT`); this only becomes true for
@@ -23,9 +23,6 @@ speed. For trivial tasks, use judgment.
23
23
  (`kb agents <path>` / `kb_search`) first, then read the specific file.
24
24
  - Before any major change, confirm the plan.
25
25
 
26
- See the **Finding docs (READ discipline)** section for the kb-first
27
- substitution table (which `kb_*` call replaces which raw-search reflex).
28
-
29
26
  ### 2. Simplicity First
30
27
 
31
28
  - Minimum code that solves the problem. Nothing speculative.
@@ -50,26 +47,6 @@ substitution table (which `kb_*` call replaces which raw-search reflex).
50
47
 
51
48
  - Give a high-level explanation of what changed — don't dump diffs without summary.
52
49
 
53
- ## Finding docs (READ discipline)
54
-
55
- `kb_*` tools return a one-line purpose + key exports per file, not raw bytes —
56
- faster and cheaper than raw search. **This fires on the ACTION, not the
57
- intent**: before you `grep`/`rg` for a symbol, `cat`/read a file to learn what
58
- it does, or chase an import, the doc lookup goes first — even mid-task when you
59
- already know the file. When your reflex is the left column, run the right:
60
-
61
- | You're about to… | Do this FIRST instead |
62
- |---|---|
63
- | `grep -rn "SymbolName" src/` — find where a fn / type / const lives | `kb_search --doc-type agents "SymbolName"` (or read the nearest directory `AGENTS.md` if kb is not wired) |
64
- | `grep -rn "feature\|topic" src/` — how does X work / where's X handled | `kb_search "feature topic"` (or walk the root→nearest `AGENTS.md` chain) |
65
- | `cat` / read a file just to learn its purpose before editing | `kb agents <path>` — one-line purpose + exports + change history |
66
- | chase imports / callers across files | `kb_neighbors <path\|heading>` |
67
- | read one doc section in full | `kb_get <path> <section>` |
68
-
69
- **Fall-through:** if the kb call (or the tree) returns nothing relevant, `rg` /
70
- source read is allowed — then add the missing directory `AGENTS.md` row per the
71
- Documentation Update Protocol. The doc lookup does NOT replace grep; it goes first.
72
-
73
50
  ## Commands
74
51
 
75
52
  <!-- Filled from the detected project stack; edit if your commands differ. -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blackbelt-technology/pi-dashboard-extension",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Pi bridge extension for pi-dashboard",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,6 +21,17 @@
21
21
  ".pi/skills/browser",
22
22
  ".pi/skills/project-init",
23
23
  ".pi/skills/doctor"
24
+ ],
25
+ "tools": [
26
+ {
27
+ "id": "agent-browser",
28
+ "probe": "resolve"
29
+ },
30
+ {
31
+ "id": "chromium",
32
+ "probe": "pw-browser",
33
+ "optional": true
34
+ }
24
35
  ]
25
36
  },
26
37
  "files": [
@@ -37,18 +48,16 @@
37
48
  "!**/*.test.tsx"
38
49
  ],
39
50
  "dependencies": {
40
- "@blackbelt-technology/pi-dashboard-bus-client": "^0.8.0",
41
- "@blackbelt-technology/pi-dashboard-shared": "^0.8.0",
42
- "@fission-ai/openspec": "^1.6.0",
51
+ "@blackbelt-technology/pi-dashboard-bus-client": "^0.9.0",
52
+ "@blackbelt-technology/pi-dashboard-shared": "^0.9.0",
53
+ "@fission-ai/openspec": "1.11.0",
43
54
  "minimatch": "^10.0.0",
44
55
  "ws": "^8.18.0"
45
56
  },
46
57
  "peerDependencies": {
47
- "@earendil-works/pi-ai": ">=0.75.5",
48
- "@earendil-works/pi-coding-agent": ">=0.80.10",
49
- "@earendil-works/pi-tui": ">=0.80.10",
50
- "@mariozechner/pi-coding-agent": ">=0.73.1",
51
- "@mariozechner/pi-tui": ">=0.73.1",
58
+ "@earendil-works/pi-ai": ">=1.0.0",
59
+ "@earendil-works/pi-coding-agent": ">=1.0.0",
60
+ "@earendil-works/pi-tui": ">=1.0.0",
52
61
  "typebox": ">=1.3.6"
53
62
  },
54
63
  "peerDependenciesMeta": {
@@ -58,18 +67,12 @@
58
67
  "@earendil-works/pi-tui": {
59
68
  "optional": true
60
69
  },
61
- "@mariozechner/pi-coding-agent": {
62
- "optional": true
63
- },
64
- "@mariozechner/pi-tui": {
65
- "optional": true
66
- },
67
70
  "@earendil-works/pi-ai": {
68
71
  "optional": true
69
72
  }
70
73
  },
71
74
  "devDependencies": {
72
- "@earendil-works/pi-tui": ">=0.80.10",
75
+ "@earendil-works/pi-tui": "^1.0.0",
73
76
  "@types/ws": "^8.18.1",
74
77
  "typebox": "^1.3.7"
75
78
  }
@@ -4,6 +4,10 @@
4
4
  * Called at runtime (session_start) rather than extension load time to avoid
5
5
  * static tool-name conflicts with other extensions (e.g. pi-flows) that also
6
6
  * register ask_user. Runtime registration bypasses detectExtensionConflicts.
7
+ *
8
+ * Cwd-independence (change: update-pi-core-0-85-adopt-apis, task 5.1): pure
9
+ * `ctx.ui` interaction — it renders the prompt and returns the answer, resolves
10
+ * no filesystem path and spawns no process, so `ctx.cwd` is never consulted.
7
11
  */
8
12
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
9
13
  import { Type } from "typebox";
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Bridge activation gate. Decides once per factory invocation, BEFORE any
3
+ * registration, whether the bridge runs in this pi process.
4
+ *
5
+ * Precedence: `PI_DASHBOARD_BRIDGE` env > `bridge.enabled` config > on.
6
+ * A recognised env value never touches the config file. Any failure while
7
+ * resolving fails OPEN (bridge activates) and emits no output — the opt-out
8
+ * must never be able to break the dashboard through an error.
9
+ *
10
+ * See change: add-bridge-env-opt-out.
11
+ */
12
+ import {
13
+ type BridgeActivationConfig,
14
+ bridgeEnvOverride,
15
+ } from "@blackbelt-technology/pi-dashboard-shared/config.js";
16
+
17
+ export function shouldActivateBridge(
18
+ env: Record<string, string | undefined>,
19
+ readConfig: () => BridgeActivationConfig,
20
+ ): boolean {
21
+ try {
22
+ return bridgeEnvOverride(env) ?? readConfig().enabled;
23
+ } catch {
24
+ return true;
25
+ }
26
+ }
@@ -3,8 +3,10 @@
3
3
  * Avoids passing 14+ closure variables to every extracted function.
4
4
  */
5
5
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
6
- import type { ConnectionManager } from "./connection.js";
7
6
  import { shouldSkipByPrefilter } from "./auto-session-namer.js";
7
+ import type { ConnectionManager } from "./connection.js";
8
+ import type { GitTracker } from "./git-tracker.js";
9
+ import type { PrStatusScheduler } from "./pr-status.js";
8
10
 
9
11
  export interface BridgeContext {
10
12
  pi: ExtensionAPI;
@@ -28,7 +30,24 @@ export interface BridgeContext {
28
30
  lastSessionDir: string | undefined;
29
31
  lastFirstMessage: string | undefined;
30
32
  lastGitBranch: string | undefined;
31
- lastGitPrNumber: number | undefined;
33
+ /**
34
+ * Last serialized PR tuple (`PrTuple`) sent via `git_info_update`, or
35
+ * `undefined` when nothing sent yet. Replaces `lastGitPrNumber`.
36
+ * See change: redesign-composer-session-strip (D5).
37
+ */
38
+ lastGitPrJson: string | undefined;
39
+ /**
40
+ * Per-bridge async PR-status scheduler (stable reference across
41
+ * `syncBc()` snapshots). Absent in unit-test contexts that don't need it.
42
+ * See change: redesign-composer-session-strip (D5).
43
+ */
44
+ prStatus?: PrStatusScheduler;
45
+ /**
46
+ * Per-bridge git tracker (facts cache, HEAD branch, async status probe).
47
+ * Stable reference across `syncBc()` snapshots. Absent in unit-test contexts.
48
+ * See change: optimize-polling-hot-paths.
49
+ */
50
+ gitTracker?: GitTracker;
32
51
  /**
33
52
  * Last serialized `GitWorktreeInfo` snapshot sent to the server, or
34
53
  * the literal string `"null"` when we explicitly cleared worktree
@@ -145,23 +164,6 @@ export function isExtensionSlashCommand(
145
164
  return commandList.some((c) => c?.name === cmdName && c?.source === "extension");
146
165
  }
147
166
 
148
- /**
149
- * Feature-detect upstream `pi.dispatchCommand(text, opts)` (pi 0.71+).
150
- * Returns true iff `dispatchCommand` resolves to a function on the supplied
151
- * object. Fast path uses a direct `typeof` access; when that is false an
152
- * `in`-operator fallback with a guarded `typeof` detects getter-backed /
153
- * Proxy-hidden properties. Returns false for null/undefined and non-functions.
154
- * See change: resolve-global-prompt-templates-from-dashboard.
155
- */
156
- export function hasDispatchCommand(pi: unknown): boolean {
157
- if (pi == null) return false;
158
- if (typeof (pi as any).dispatchCommand === "function") return true;
159
- if ("dispatchCommand" in (pi as object)) {
160
- return typeof (pi as any).dispatchCommand === "function";
161
- }
162
- return false;
163
- }
164
-
165
167
  /**
166
168
  * Pure predicate: is this bridge running inside a dashboard-spawned
167
169
  * headless `pi --mode rpc` session?