@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
@@ -16,6 +16,11 @@
16
16
  *
17
17
  * Registered at runtime (session_start) like `ask_user` to avoid static
18
18
  * tool-name conflicts.
19
+ *
20
+ * Cwd-independence (change: update-pi-core-0-85-adopt-apis, task 5.1): the
21
+ * tool is intentionally cwd-independent — `execute` validates the raw shape
22
+ * only and resolves no filesystem path, so `ctx.cwd` is never consulted. The
23
+ * cwd-anchored normalization happens server-side.
19
24
  */
20
25
 
21
26
  import { validateCanvasDeclareShape } from "@blackbelt-technology/pi-dashboard-shared/canvas-declare.js";
@@ -4,6 +4,7 @@
4
4
  import { readdirSync, readFileSync } from "node:fs";
5
5
  import { homedir } from "node:os";
6
6
  import { join, relative } from "node:path";
7
+ import { resolveDashboardPorts } from "@blackbelt-technology/pi-dashboard-shared/config.js";
7
8
  import { imageBlockData, imageBlockMime } from "@blackbelt-technology/pi-dashboard-shared/image-block.js";
8
9
  import { diffOr } from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
9
10
  import type {
@@ -202,13 +203,39 @@ export function searchFiles(cwd: string, query: string, opts?: { regex?: boolean
202
203
  *
203
204
  * `ok: false` carries the operator-facing reason so the terminal
204
205
  * `command_feedback` says WHY nothing reloaded instead of claiming success.
205
- * See change: fix-out-of-band-reload.
206
+ * `handedOff` means the terminal feedback is owned by someone else — the
207
+ * bridge instance loaded by an in-process reload reports `completed` after it
208
+ * re-registers — so the requesting side must emit nothing.
209
+ *
210
+ * See change: fix-out-of-band-reload, fix-terminal-session-dashboard-reload.
206
211
  */
207
- export type ReloadOutcome = { ok: true } | { ok: false; reason: string };
212
+ export type ReloadOutcome =
213
+ | { ok: true; handedOff?: false }
214
+ | { ok: true; handedOff: true }
215
+ | { ok: false; reason: string };
216
+
217
+ /** Reason emitted when the bridge has no reload path for this session. */
218
+ const NO_RELOAD_PATH_REASON =
219
+ "No dashboard reload path for this session — run /reload in the pi TUI.";
220
+
221
+ /** A dashboard reload for this session is still in flight. */
222
+ export const RELOAD_IN_PROGRESS_REASON = "A reload is already in progress for this session.";
223
+
224
+ /** The self-dispatched reload command never reached its handler. */
225
+ export const RELOAD_DID_NOT_RUN_REASON =
226
+ "The reload command did not run — is the dashboard extension still loaded? See the pi terminal.";
208
227
 
209
- /** Reason emitted when the bridge has no reload path at all. */
210
- export const NO_RELOAD_PATH_REASON =
211
- "No reload path for this session — a terminal-hosted pi session must run /__dashboard_reload once in its TUI to enable dashboard reloads.";
228
+ /** `ctx.reload()` settled without pi re-running `session_start{reason:"reload"}`. */
229
+ export const PI_DID_NOT_RELOAD_REASON =
230
+ "pi did not reload — session busy or reload failed; see the pi terminal.";
231
+
232
+ /** The pending-reload slot vanished or was replaced before completion was proven. */
233
+ export const RELOAD_SUPERSEDED_REASON =
234
+ "The reload was superseded before completion could be confirmed — see the pi terminal.";
235
+
236
+ /** The reload did not finish within the bridge's bound. */
237
+ export const RELOAD_TIMEOUT_REASON =
238
+ "The reload did not finish within 60 s — see the pi terminal.";
212
239
 
213
240
  /** Parsed result from parseSendPrompt */
214
241
  export type ParsedPrompt =
@@ -233,6 +260,19 @@ const MANAGEMENT_COMMAND_EVENTS: Record<string, {
233
260
  dataFn: (args: string) => Record<string, unknown>;
234
261
  }> = {};
235
262
 
263
+ /**
264
+ * Team sessions (add-team-plugin D7): the guard extension confines TOOL calls, but a prompt the bridge
265
+ * turns into a host action (`!cmd` bash, `/slash` extension commands, reload, new, model, shutdown,
266
+ * management) never reaches `tool_call`. Such a session's owner could run unconfined bash by typing
267
+ * `!id`. The spawn projects `PI_EXT_TEAM_TOOLS` into the pi process, so the bridge refuses those routes
268
+ * there; plain prompts, `/compact` and the dashboard-internal retry stay available.
269
+ */
270
+ export function isTeamConfinedSession(env: NodeJS.ProcessEnv = process.env): boolean {
271
+ return typeof env.PI_EXT_TEAM_TOOLS === "string";
272
+ }
273
+
274
+ const TEAM_ALLOWED_PARSED: ReadonlySet<ParsedPrompt["type"]> = new Set(["passthrough", "compact", "retry"]);
275
+
236
276
  /** Parse input text to detect pi internal command prefixes */
237
277
  export function parseSendPrompt(text: string): ParsedPrompt {
238
278
  // 1. Check !! (must check before !)
@@ -370,19 +410,18 @@ export function createCommandHandler(
370
410
  /**
371
411
  * Trigger session reload (extensions, settings, skills, etc.).
372
412
  *
373
- * Returns whether a reload ACTUALLY ran. The bridge only has a reload
374
- * function when a human once typed `/__dashboard_reload` in pi's TUI
375
- * (`ExtensionContext` has no `reload`; only `ExtensionCommandContext`
376
- * does), and even a captured one is single-use per process — its runner
377
- * is invalidated by the first reload, so a second call throws
378
- * *synchronously*. "Present" therefore does not imply "usable", which is
379
- * why this reports an outcome instead of returning void and letting the
380
- * caller emit an unconditional `completed`.
413
+ * Returns whether a reload ACTUALLY ran, so the caller never emits an
414
+ * unconditional `completed`. The bridge self-dispatches its
415
+ * `/__dashboard_reload <token>` command in-process and
416
+ * resolves `{ok:true, handedOff:true}` on success: the RELOADED bridge
417
+ * instance reports `completed` after re-registering, because this
418
+ * instance's connection is torn down by the reload. On `handedOff` the
419
+ * handler emits nothing.
381
420
  *
382
- * ASYNC by contract: `ctx.reload()` returns a promise, and a rejection
383
- * that lands after we have already emitted `completed` is the same false
384
- * success this change exists to remove. The handler awaits it.
385
- * See change: fix-out-of-band-reload (design.md D5).
421
+ * ASYNC by contract: a rejection that lands after we have already
422
+ * emitted `completed` would be a false success. The handler awaits it.
423
+ * See change: fix-out-of-band-reload (design.md D5),
424
+ * fix-terminal-session-dashboard-reload (D4).
386
425
  */
387
426
  reload?: () => Promise<ReloadOutcome>;
388
427
  /** Spawn a new session in the same cwd */
@@ -520,6 +559,11 @@ export function createCommandHandler(
520
559
  case "send_prompt": {
521
560
  const parsed = parseSendPrompt(msg.text);
522
561
 
562
+ if (isTeamConfinedSession() && !TEAM_ALLOWED_PARSED.has(parsed.type)) {
563
+ options?.eventSink?.({ type: "prompt_received", sessionId, fresh: false });
564
+ return undefined;
565
+ }
566
+
523
567
  // Non-turn commands (bash/compact/shutdown/reload/new/model/mgmt)
524
568
  // return early below and never produce a user `message_start`, so an
525
569
  // optimistic idle `pendingPrompt` bubble would hang until the 30s
@@ -574,6 +618,9 @@ export function createCommandHandler(
574
618
  outcome = { ok: false, reason: `Reload failed: ${reason}` };
575
619
  }
576
620
  }
621
+ // The reloaded bridge owns the terminal feedback.
622
+ // See change: fix-terminal-session-dashboard-reload (D4).
623
+ if (outcome.ok && outcome.handedOff) return undefined;
577
624
  options?.eventSink?.({
578
625
  type: "event_forward",
579
626
  sessionId,
@@ -670,7 +717,6 @@ export function createCommandHandler(
670
717
  parsed.text,
671
718
  sessionId,
672
719
  options?.eventSink,
673
- undefined, // connection — absent in non-bridge path
674
720
  msg.delivery,
675
721
  );
676
722
  // Exec-mode slash template (executable: bash): run as bash, no LLM.
@@ -1129,26 +1175,26 @@ function sendUserMessageWithImages(
1129
1175
 
1130
1176
  /**
1131
1177
  * Resolve the dashboard HTTP port, in precedence order:
1132
- * 1. `PI_DASHBOARD_PORT` / `DASHBOARD_PORT` env — set by the dashboard server
1133
- * and inherited by spawned sessions (the only reliable source when the
1134
- * server runs on a non-default port, e.g. the Docker test harness, whose
1135
- * `config.json` carries no `port` field).
1178
+ * 1. `PI_DASHBOARD_PORT` / `DASHBOARD_PORT` env — set by the session's
1179
+ * RUNTIME environment (e.g. the docker harness compose env). The
1180
+ * dashboard server does NOT inject these into spawned sessions; it
1181
+ * pins them via `PI_DASHBOARD_URL` / `PI_DASHBOARD_SOCKET` instead.
1136
1182
  * 2. `~/.pi/dashboard/config.json` `port` — normal local installs write it.
1137
- * 3. 8000 (default).
1138
- * Note: `PI_DASHBOARD_URL` is the gateway (ws) port, NOT the HTTP port, so it is
1139
- * deliberately not consulted here. See change: add-dashboard-slash-commands.
1183
+ * 3. The shared default.
1184
+ * Delegates to the shared `resolveDashboardPorts` so this path and the
1185
+ * bridge's auto-start port resolution cannot drift.
1186
+ * Note: `PI_DASHBOARD_URL` is the gateway (ws) endpoint, NOT the HTTP port,
1187
+ * so it is deliberately not consulted here.
1188
+ * See change: add-dashboard-slash-commands, fix-bridge-autostart-port-resolution.
1140
1189
  */
1141
1190
  function resolveDashboardPort(): number {
1142
- for (const v of [process.env.PI_DASHBOARD_PORT, process.env.DASHBOARD_PORT]) {
1143
- const n = Number(v);
1144
- if (v && Number.isFinite(n) && n > 0) return n;
1145
- }
1191
+ let fileConfig: { port?: number } = {};
1146
1192
  try {
1147
1193
  const raw = readFileSync(join(homedir(), ".pi", "dashboard", "config.json"), "utf-8");
1148
1194
  const parsed = JSON.parse(raw);
1149
- if (typeof parsed?.port === "number" && Number.isFinite(parsed.port)) return parsed.port;
1195
+ if (typeof parsed?.port === "number") fileConfig = { port: parsed.port };
1150
1196
  } catch { /* missing / unparseable config */ }
1151
- return 8000;
1197
+ return resolveDashboardPorts(process.env, fileConfig).port;
1152
1198
  }
1153
1199
 
1154
1200
  /**