@blackbelt-technology/pi-dashboard-extension 0.5.4 → 0.6.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 (254) hide show
  1. package/.pi/skills/browser/LICENSE +201 -0
  2. package/.pi/skills/browser/SKILL.md +105 -0
  3. package/.pi/skills/browser/UPSTREAM.md +46 -0
  4. package/.pi/skills/browser/references/electron.md +351 -0
  5. package/.pi/skills/browser/references/web.md +2789 -0
  6. package/.pi/skills/browser/scripts/detect-dashboard.sh +55 -0
  7. package/.pi/skills/doctor/AGENTS.md +27 -0
  8. package/.pi/skills/doctor/SKILL.md +89 -0
  9. package/.pi/skills/doctor/_lib/checks.ts +177 -0
  10. package/.pi/skills/doctor/_lib/derive-tokens.ts +43 -0
  11. package/.pi/skills/doctor/_lib/front-matter.ts +122 -0
  12. package/.pi/skills/doctor/_lib/index.ts +14 -0
  13. package/.pi/skills/doctor/_lib/knowledge-hash.ts +74 -0
  14. package/.pi/skills/doctor/_lib/provenance.ts +50 -0
  15. package/.pi/skills/doctor/_lib/regenerate.ts +100 -0
  16. package/.pi/skills/doctor/_lib/router.ts +155 -0
  17. package/.pi/skills/doctor/_lib/server-tier.ts +62 -0
  18. package/.pi/skills/doctor/modules/build-reload.knowledge.hash +1 -0
  19. package/.pi/skills/doctor/modules/build-reload.md +51 -0
  20. package/.pi/skills/doctor/modules/env-node.knowledge.hash +1 -0
  21. package/.pi/skills/doctor/modules/env-node.md +49 -0
  22. package/.pi/skills/doctor/modules/install-topology.knowledge.hash +1 -0
  23. package/.pi/skills/doctor/modules/install-topology.md +53 -0
  24. package/.pi/skills/doctor/modules/model-resolution.knowledge.hash +1 -0
  25. package/.pi/skills/doctor/modules/model-resolution.md +53 -0
  26. package/.pi/skills/doctor/modules/peers.knowledge.hash +1 -0
  27. package/.pi/skills/doctor/modules/peers.md +57 -0
  28. package/.pi/skills/doctor/modules/pi-resolution.knowledge.hash +1 -0
  29. package/.pi/skills/doctor/modules/pi-resolution.md +60 -0
  30. package/.pi/skills/doctor/modules/plugins-bridges.knowledge.hash +1 -0
  31. package/.pi/skills/doctor/modules/plugins-bridges.md +56 -0
  32. package/.pi/skills/pi-dashboard/SKILL.md +68 -0
  33. package/.pi/skills/pi-dashboard/commands/README.md +45 -0
  34. package/.pi/skills/pi-dashboard/commands/dashboard-flow-abort.md +10 -0
  35. package/.pi/skills/pi-dashboard/commands/dashboard-flow-auto.md +10 -0
  36. package/.pi/skills/pi-dashboard/commands/dashboard-git-branches.md +6 -0
  37. package/.pi/skills/pi-dashboard/commands/dashboard-git-init.md +8 -0
  38. package/.pi/skills/pi-dashboard/commands/dashboard-git-stash-pop.md +8 -0
  39. package/.pi/skills/pi-dashboard/commands/dashboard-list-models.md +10 -0
  40. package/.pi/skills/pi-dashboard/commands/dashboard-peer-list.md +6 -0
  41. package/.pi/skills/pi-dashboard/commands/dashboard-peer-scan.md +6 -0
  42. package/.pi/skills/pi-dashboard/commands/dashboard-pin-list.md +5 -0
  43. package/.pi/skills/pi-dashboard/commands/dashboard-proposal-archive.md +6 -0
  44. package/.pi/skills/pi-dashboard/commands/dashboard-proposal-attach.md +10 -0
  45. package/.pi/skills/pi-dashboard/commands/dashboard-proposal-detach.md +10 -0
  46. package/.pi/skills/pi-dashboard/commands/dashboard-server-config.md +5 -0
  47. package/.pi/skills/pi-dashboard/commands/dashboard-server-health.md +6 -0
  48. package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-off.md +6 -0
  49. package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-on.md +6 -0
  50. package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-status.md +6 -0
  51. package/.pi/skills/pi-dashboard/commands/dashboard-session-abort-all.md +14 -0
  52. package/.pi/skills/pi-dashboard/commands/dashboard-session-abort.md +10 -0
  53. package/.pi/skills/pi-dashboard/commands/dashboard-session-diff.md +11 -0
  54. package/.pi/skills/pi-dashboard/commands/dashboard-session-fork.md +10 -0
  55. package/.pi/skills/pi-dashboard/commands/dashboard-session-hide.md +10 -0
  56. package/.pi/skills/pi-dashboard/commands/dashboard-session-info.md +11 -0
  57. package/.pi/skills/pi-dashboard/commands/dashboard-session-kill.md +10 -0
  58. package/.pi/skills/pi-dashboard/commands/dashboard-session-list-active.md +8 -0
  59. package/.pi/skills/pi-dashboard/commands/dashboard-session-list-here.md +8 -0
  60. package/.pi/skills/pi-dashboard/commands/dashboard-session-list.md +6 -0
  61. package/.pi/skills/pi-dashboard/commands/dashboard-session-model.md +10 -0
  62. package/.pi/skills/pi-dashboard/commands/dashboard-session-rename.md +10 -0
  63. package/.pi/skills/pi-dashboard/commands/dashboard-session-resume.md +10 -0
  64. package/.pi/skills/pi-dashboard/commands/dashboard-session-spawn.md +10 -0
  65. package/.pi/skills/pi-dashboard/commands/dashboard-session-tell.md +10 -0
  66. package/.pi/skills/pi-dashboard/commands/dashboard-session-thinking.md +10 -0
  67. package/.pi/skills/pi-dashboard/commands/dashboard-session-unhide.md +10 -0
  68. package/.pi/skills/pi-dashboard/references/api-reference.md +30 -0
  69. package/.pi/skills/pi-dashboard/references/recipes.md +38 -0
  70. package/.pi/skills/pi-dashboard/references/slash-commands.md +71 -0
  71. package/.pi/skills/pi-dashboard/scripts/dashboard-api.sh +6 -0
  72. package/.pi/skills/pi-dashboard/scripts/dashboard-bus.ts +217 -0
  73. package/.pi/skills/project-init/SKILL.md +279 -0
  74. package/.pi/skills/project-init/dox-doctrine.md +104 -0
  75. package/.pi/skills/project-init/profiles/coding/AGENTS.md.tmpl +111 -0
  76. package/.pi/skills/project-init/profiles/coding/profile.json +5 -0
  77. package/.pi/skills/project-init/profiles/coding/prompts/plan-change.md +5 -0
  78. package/.pi/skills/project-init/profiles/coding/prompts/tdd-loop.md +6 -0
  79. package/.pi/skills/project-init/profiles/coding/settings.json.tmpl +9 -0
  80. package/.pi/skills/project-init/profiles/docs/AGENTS.md.tmpl +37 -0
  81. package/.pi/skills/project-init/profiles/docs/profile.json +4 -0
  82. package/.pi/skills/project-init/profiles/docs/prompts/draft-page.md +5 -0
  83. package/.pi/skills/project-init/profiles/docs/settings.json.tmpl +9 -0
  84. package/package.json +12 -4
  85. package/src/AGENTS.md +56 -0
  86. package/src/__tests__/abort-latch.test.ts +97 -0
  87. package/src/__tests__/agent-settled.test.ts +82 -0
  88. package/src/__tests__/artifact-roots.test.ts +83 -0
  89. package/src/__tests__/ask-user-attachments.test.ts +106 -0
  90. package/src/__tests__/ask-user-tool.test.ts +90 -27
  91. package/src/__tests__/auto-session-namer.test.ts +339 -0
  92. package/src/__tests__/bridge-default-model-apply.test.ts +242 -0
  93. package/src/__tests__/bridge-default-model-gate.test.ts +6 -3
  94. package/src/__tests__/bridge-followup-mutation.test.ts +217 -0
  95. package/src/__tests__/bridge-followup-queue-drain.test.ts +266 -0
  96. package/src/__tests__/bridge-hasui-flip.test.ts +109 -0
  97. package/src/__tests__/bridge-no-queue-mutation.test.ts +112 -0
  98. package/src/__tests__/bridge-plugin-emit-event.test.ts +44 -0
  99. package/src/__tests__/bridge-shutdown-reset.test.ts +57 -136
  100. package/src/__tests__/bridge-slash-command-routing.test.ts +7 -7
  101. package/src/__tests__/bridge-stop-after-turn.test.ts +72 -0
  102. package/src/__tests__/bridge-system-followup.test.ts +163 -0
  103. package/src/__tests__/bridge-thinking-level-select.test.ts +68 -0
  104. package/src/__tests__/browser-skill-registered.test.ts +84 -0
  105. package/src/__tests__/build-provider-catalogue.test.ts +35 -1
  106. package/src/__tests__/command-handler.test.ts +331 -35
  107. package/src/__tests__/commit-draft.test.ts +100 -0
  108. package/src/__tests__/connection-dropped-frames.test.ts +78 -0
  109. package/src/__tests__/custom-provider-apikey-roundtrip.test.ts +128 -0
  110. package/src/__tests__/cwd-missing-probe.test.ts +82 -0
  111. package/src/__tests__/dashboard-commands-shipped.test.ts +53 -0
  112. package/src/__tests__/dashboard-context-injector.test.ts +190 -0
  113. package/src/__tests__/doctor/checks.test.ts +121 -0
  114. package/src/__tests__/doctor/modules.test.ts +64 -0
  115. package/src/__tests__/doctor/provenance-hash.test.ts +94 -0
  116. package/src/__tests__/doctor/router.test.ts +143 -0
  117. package/src/__tests__/empty-actionable-guard-config.test.ts +32 -0
  118. package/src/__tests__/empty-actionable-guard.test.ts +73 -0
  119. package/src/__tests__/enrich-model-metadata.test.ts +21 -0
  120. package/src/__tests__/extension-slash-command-detection.test.ts +37 -1
  121. package/src/__tests__/filter-enabled-models.test.ts +151 -0
  122. package/src/__tests__/fixtures/turn-actionability-fixtures.ts +69 -0
  123. package/src/__tests__/git-info-status.test.ts +73 -0
  124. package/src/__tests__/git-poll.test.ts +69 -0
  125. package/src/__tests__/markdown-image-inliner.test.ts +37 -0
  126. package/src/__tests__/model-resolve.test.ts +379 -0
  127. package/src/__tests__/pi-version-tracker.test.ts +109 -0
  128. package/src/__tests__/process-scanner.test.ts +112 -22
  129. package/src/__tests__/project-init-detect-stack.test.ts +61 -0
  130. package/src/__tests__/project-init-dox-kb-config.test.ts +53 -0
  131. package/src/__tests__/project-init-profiles.test.ts +84 -0
  132. package/src/__tests__/project-init-scaffold.test.ts +139 -0
  133. package/src/__tests__/project-init-seed-doctrine.test.ts +100 -0
  134. package/src/__tests__/project-trust.test.ts +92 -0
  135. package/src/__tests__/prompt-expander.test.ts +191 -1
  136. package/src/__tests__/provider-register-reload.test.ts +36 -6
  137. package/src/__tests__/provider-register-thinking-levels.test.ts +51 -0
  138. package/src/__tests__/retry-tracker.test.ts +75 -70
  139. package/src/__tests__/role-manager.test.ts +585 -0
  140. package/src/__tests__/role-model-tools-registry-readiness.test.ts +114 -0
  141. package/src/__tests__/role-model-tools.test.ts +229 -0
  142. package/src/__tests__/search-files-completeness.test.ts +111 -0
  143. package/src/__tests__/search-files-ranking.test.ts +168 -0
  144. package/src/__tests__/server-auto-start.test.ts +121 -4
  145. package/src/__tests__/server-launcher-launch.test.ts +24 -6
  146. package/src/__tests__/server-launcher.test.ts +19 -2
  147. package/src/__tests__/session-sync.test.ts +36 -0
  148. package/src/__tests__/subagent-frame-buffer.test.ts +239 -0
  149. package/src/__tests__/tool-result-image-inliner.test.ts +206 -0
  150. package/src/__tests__/tui-prompt-adapter.test.ts +70 -64
  151. package/src/__tests__/turn-actionability.test.ts +86 -0
  152. package/src/__tests__/vcs-info.test.ts +145 -4
  153. package/src/__tests__/visibility-intent.test.ts +43 -0
  154. package/src/abort-latch.ts +55 -0
  155. package/src/abort-latch.ts.AGENTS.md +3 -0
  156. package/src/agent-settled.ts +72 -0
  157. package/src/agent-settled.ts.AGENTS.md +3 -0
  158. package/src/artifact-roots.ts +73 -0
  159. package/src/artifact-roots.ts.AGENTS.md +3 -0
  160. package/src/ask-user-attachments.ts +121 -0
  161. package/src/ask-user-attachments.ts.AGENTS.md +3 -0
  162. package/src/ask-user-tool.ts +56 -58
  163. package/src/ask-user-tool.ts.AGENTS.md +3 -0
  164. package/src/auto-session-namer.ts +334 -0
  165. package/src/auto-session-namer.ts.AGENTS.md +3 -0
  166. package/src/bridge-context.ts +86 -8
  167. package/src/bridge-context.ts.AGENTS.md +3 -0
  168. package/src/bridge-default-model-gate.ts +22 -6
  169. package/src/bridge-default-model-gate.ts.AGENTS.md +3 -0
  170. package/src/bridge.ts +1241 -360
  171. package/src/bridge.ts.AGENTS.md +3 -0
  172. package/src/canvas-tool.ts +107 -0
  173. package/src/command-handler.ts +490 -51
  174. package/src/command-handler.ts.AGENTS.md +3 -0
  175. package/src/commit-draft-agent.ts +114 -0
  176. package/src/commit-draft-agent.ts.AGENTS.md +3 -0
  177. package/src/commit-draft.ts +136 -0
  178. package/src/commit-draft.ts.AGENTS.md +3 -0
  179. package/src/connection.ts +32 -1
  180. package/src/connection.ts.AGENTS.md +3 -0
  181. package/src/dashboard-context-injector.ts +124 -0
  182. package/src/dashboard-context-injector.ts.AGENTS.md +3 -0
  183. package/src/dashboard-default-adapter.ts.AGENTS.md +3 -0
  184. package/src/dev-build.ts.AGENTS.md +3 -0
  185. package/src/empty-actionable-guard-config.ts +32 -0
  186. package/src/empty-actionable-guard-config.ts.AGENTS.md +3 -0
  187. package/src/empty-actionable-guard.ts +90 -0
  188. package/src/empty-actionable-guard.ts.AGENTS.md +3 -0
  189. package/src/event-forwarder.ts.AGENTS.md +3 -0
  190. package/src/flow-event-wiring.ts +4 -14
  191. package/src/flow-event-wiring.ts.AGENTS.md +3 -0
  192. package/src/git-link-builder.ts.AGENTS.md +3 -0
  193. package/src/git-poll.ts +38 -0
  194. package/src/git-poll.ts.AGENTS.md +3 -0
  195. package/src/hasui-flip.ts +56 -0
  196. package/src/hasui-flip.ts.AGENTS.md +3 -0
  197. package/src/markdown-image-inliner.ts +45 -2
  198. package/src/markdown-image-inliner.ts.AGENTS.md +3 -0
  199. package/src/model-tracker.ts +145 -19
  200. package/src/model-tracker.ts.AGENTS.md +3 -0
  201. package/src/multiselect-decode.ts.AGENTS.md +3 -0
  202. package/src/multiselect-list.ts.AGENTS.md +3 -0
  203. package/src/multiselect-polyfill.ts.AGENTS.md +3 -0
  204. package/src/process-metrics.ts.AGENTS.md +3 -0
  205. package/src/process-scanner.ts +114 -103
  206. package/src/process-scanner.ts.AGENTS.md +3 -0
  207. package/src/project-init/AGENTS.md +12 -0
  208. package/src/project-init/detect-stack.ts +146 -0
  209. package/src/project-init/dox-kb-config.ts +47 -0
  210. package/src/project-init/profiles.ts +135 -0
  211. package/src/project-init/scaffold.ts +192 -0
  212. package/src/project-init/seed-doctrine.ts +95 -0
  213. package/src/project-trust.ts +63 -0
  214. package/src/project-trust.ts.AGENTS.md +3 -0
  215. package/src/prompt-bus.ts +10 -1
  216. package/src/prompt-bus.ts.AGENTS.md +3 -0
  217. package/src/prompt-expander.ts +238 -37
  218. package/src/prompt-expander.ts.AGENTS.md +3 -0
  219. package/src/provider-register.ts +323 -54
  220. package/src/provider-register.ts.AGENTS.md +3 -0
  221. package/src/retry-tracker.ts +64 -39
  222. package/src/retry-tracker.ts.AGENTS.md +3 -0
  223. package/src/role-manager.ts +436 -0
  224. package/src/role-manager.ts.AGENTS.md +3 -0
  225. package/src/role-model-tools.ts +301 -0
  226. package/src/role-model-tools.ts.AGENTS.md +3 -0
  227. package/src/server-auto-start.ts +59 -23
  228. package/src/server-auto-start.ts.AGENTS.md +3 -0
  229. package/src/server-launcher.ts +56 -16
  230. package/src/server-launcher.ts.AGENTS.md +3 -0
  231. package/src/session-sync.ts +111 -15
  232. package/src/session-sync.ts.AGENTS.md +3 -0
  233. package/src/slash-dispatch.ts +13 -11
  234. package/src/slash-dispatch.ts.AGENTS.md +3 -0
  235. package/src/source-detector.ts.AGENTS.md +3 -0
  236. package/src/subagent-frame-buffer.ts +220 -0
  237. package/src/subagent-frame-buffer.ts.AGENTS.md +3 -0
  238. package/src/tool-result-image-inliner.ts +204 -0
  239. package/src/tool-result-image-inliner.ts.AGENTS.md +3 -0
  240. package/src/tui-prompt-adapter.ts +123 -0
  241. package/src/tui-prompt-adapter.ts.AGENTS.md +3 -0
  242. package/src/turn-actionability.ts +117 -0
  243. package/src/turn-actionability.ts.AGENTS.md +3 -0
  244. package/src/ui-modules.ts.AGENTS.md +3 -0
  245. package/src/vcs-info.ts +91 -129
  246. package/src/vcs-info.ts.AGENTS.md +3 -0
  247. package/src/visibility-intent.ts +34 -0
  248. package/src/visibility-intent.ts.AGENTS.md +3 -0
  249. package/src/__tests__/bridge-retry-ordering.test.ts +0 -148
  250. package/src/__tests__/bridge-shadow-queue-drain.test.ts +0 -221
  251. package/src/__tests__/fixtures/usage-limit-error-strings.ts +0 -127
  252. package/src/__tests__/usage-limit-orderer.test.ts +0 -117
  253. package/src/__tests__/vcs-info-jj.test.ts +0 -145
  254. package/src/usage-limit-orderer.ts +0 -93
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Pure git + name/model poll-tick body, extracted from bridge.ts so the
3
+ * session-start timer and the session-change timer share ONE implementation
4
+ * and can never drift. Previously the two `setInterval` loops were duplicated;
5
+ * the session-change copy dropped name/model polling, so session renames and
6
+ * model changes stopped propagating after any new/fork/resume.
7
+ * See change: fix-stale-ctx-cwd-crash.
8
+ *
9
+ * Contract:
10
+ * - Inactive tick (isActive() === false): no-op.
11
+ * - cwd present: run git + cwd-missing checks (these need a directory).
12
+ * - cwd absent (e.g. cachedCwd unset after a stale-ctx session swap): skip
13
+ * git/cwd checks, but STILL run name + model checks every active tick.
14
+ */
15
+ export interface GitPollDeps {
16
+ isActive: () => boolean;
17
+ /** Cached ctx.cwd. ctx.cwd is a throwing getter post session-swap, so the
18
+ * caller caches it and exposes the snapshot here. */
19
+ cachedCwd: () => string | undefined;
20
+ sendGitInfoIfChanged: (cwd: string) => void;
21
+ sendCwdMissingIfChanged: (cwd: string) => void;
22
+ sendSessionNameIfChanged: () => void;
23
+ sendModelUpdateIfChanged: () => void;
24
+ /** Re-read pi version; push pi_version_update only on change. */
25
+ sendPiVersionIfChanged: () => void;
26
+ }
27
+
28
+ export function runGitPollTick(deps: GitPollDeps): void {
29
+ if (!deps.isActive()) return;
30
+ const cwd = deps.cachedCwd();
31
+ if (cwd) {
32
+ deps.sendGitInfoIfChanged(cwd);
33
+ deps.sendCwdMissingIfChanged(cwd);
34
+ }
35
+ deps.sendSessionNameIfChanged();
36
+ deps.sendModelUpdateIfChanged();
37
+ deps.sendPiVersionIfChanged();
38
+ }
@@ -0,0 +1,3 @@
1
+ # git-poll.ts — index
2
+
3
+ Exports `runGitPollTick(deps)` + `GitPollDeps` interface. Pure git + name/model poll-tick body. Shared by bridge.ts session-start timer + session-change timer so they cannot drift. Inactive tick → no-op. cwd present → `sendGitInfoIfChanged` + `sendCwdMissingIfChanged`. cwd absent → skip git/cwd, still run `sendSessionNameIfChanged` + `sendModelUpdateIfChanged` every active tick. Dependency-injected `cachedCwd` thunk so each tick reads current cached cwd after session swap. See change: fix-stale-ctx-cwd-crash. `GitPollDeps.sendPiVersionIfChanged`; `runGitPollTick` invokes it each tick. See change: restore-pi-version-skew-surface.
@@ -0,0 +1,56 @@
1
+ /**
2
+ * `flipHasUI(ctx)` — flip `ctx.hasUI` to `true` on the live pi extension
3
+ * context after the bridge has installed PromptBus wrappers on `ctx.ui.*`.
4
+ *
5
+ * Rationale: extensions (`context-mode`, `pi-agent-browser`, …) branch on
6
+ * `ctx.hasUI` to decide whether to call `ctx.ui.notify`, render dialogs, or
7
+ * short-circuit interactive flows. The bridge already provides a working UI
8
+ * surface via PromptBus over the patched `ctx.ui.*` methods, so `ctx.hasUI`
9
+ * MUST reflect that reality.
10
+ *
11
+ * Contract:
12
+ * - Makes the live `ctx.hasUI` read `true`.
13
+ * - Caller MUST have captured the original `ctx.hasUI` into its own state
14
+ * BEFORE invoking this helper, since `source-detector.detectSessionSource`
15
+ * depends on the pi-supplied original value.
16
+ * - pi <0.80 exposed `hasUI` as a writable data property, so a direct
17
+ * assignment sufficed. pi >=0.80 exposes it as a getter-only own accessor
18
+ * (`get hasUI()` in the extension-runner context object), so assignment
19
+ * throws `TypeError: Cannot set property hasUI ... which has only a getter`.
20
+ * Since that accessor is `configurable`, we redefine the descriptor via
21
+ * `Object.defineProperty` instead. See change:
22
+ * fix-bridge-hasui-getter-redefine.
23
+ * - A truly non-configurable / frozen `ctx.hasUI` still degrades gracefully:
24
+ * a single `[dashboard] failed to flip ctx.hasUI` warning, no throw.
25
+ * - `null` / `undefined` ctx is a silent no-op (defensive).
26
+ *
27
+ * Spec: openspec/changes/fix-bridge-hasui-for-headless-rpc/
28
+ * specs/bridge-extension/spec.md
29
+ */
30
+ export function flipHasUI(ctx: { hasUI?: boolean } | null | undefined): void {
31
+ if (ctx == null) return;
32
+ const desc = Object.getOwnPropertyDescriptor(ctx, "hasUI");
33
+ // Fast path: absent or writable data property (pi <0.80) — plain assignment
34
+ // keeps the descriptor shape untouched.
35
+ if (!desc || desc.writable === true) {
36
+ try {
37
+ (ctx as { hasUI: boolean }).hasUI = true;
38
+ } catch (err) {
39
+ console.warn("[dashboard] failed to flip ctx.hasUI", err);
40
+ }
41
+ return;
42
+ }
43
+ // Getter-only accessor or read-only data property (pi >=0.80): assignment
44
+ // would throw, so replace the descriptor. Non-configurable / frozen props
45
+ // make defineProperty throw — caught below and degraded to a warning.
46
+ try {
47
+ Object.defineProperty(ctx, "hasUI", {
48
+ value: true,
49
+ writable: true,
50
+ configurable: true,
51
+ enumerable: desc.enumerable ?? true,
52
+ });
53
+ } catch (err) {
54
+ console.warn("[dashboard] failed to flip ctx.hasUI", err);
55
+ }
56
+ }
@@ -0,0 +1,3 @@
1
+ # hasui-flip.ts — index
2
+
3
+ Flip `ctx.hasUI` to `true` after bridge patches `ctx.ui.*`. Exports `flipHasUI`. Defensive try/catch for frozen/future non-writable ctx; null ctx no-op. Caller captures original value first (source-detector needs it).
@@ -128,8 +128,13 @@ export interface ReadFileResult {
128
128
  }
129
129
  export interface ReadFileError {
130
130
  ok: false;
131
- /** Use ENOENT/EACCES/EISDIR/EOTHER. EACCES is folded into ENOENT in placeholder text. */
132
- kind: "ENOENT" | "EACCES" | "EISDIR" | "EOTHER";
131
+ /**
132
+ * ENOENT/EACCES/EISDIR/EOTHER come from the `readFile` callback. EACCES is
133
+ * folded into ENOENT in placeholder text. NOT_IMAGE / TOO_LARGE are emitted
134
+ * by `inlineLocalImagePath` after a successful read (unsupported extension /
135
+ * over the per-image byte cap). See change: inline-agent-screenshot-artifacts.
136
+ */
137
+ kind: "ENOENT" | "EACCES" | "EISDIR" | "EOTHER" | "NOT_IMAGE" | "TOO_LARGE";
133
138
  }
134
139
  export type ReadFileOutcome = ReadFileResult | ReadFileError;
135
140
 
@@ -157,6 +162,44 @@ export interface AssetToEmit {
157
162
  data: string;
158
163
  }
159
164
 
165
+ /** Options for the single-path inliner. */
166
+ export interface InlineLocalImageOptions {
167
+ /** Synchronous file-read callback (same shape as `InlineOptions.readFile`). */
168
+ readFile: (absolutePath: string) => ReadFileOutcome;
169
+ /** Override the per-image cap. Default `MAX_PER_IMAGE_BYTES`. */
170
+ maxPerImageBytes?: number;
171
+ }
172
+
173
+ /**
174
+ * Inline a single local image path to an `AssetToEmit` (base64 + mime + hash).
175
+ * Pure: all I/O goes through `opts.readFile`. Returns a `ReadFileError` when
176
+ * the file is missing / unreadable (`ENOENT`/`EACCES`/`EISDIR`/`EOTHER` from
177
+ * the callback), is not a recognized image extension (`NOT_IMAGE`), or exceeds
178
+ * the per-image byte cap (`TOO_LARGE`). Discriminate the union on the `ok`
179
+ * field: a success has no `ok`, a failure has `ok: false`.
180
+ *
181
+ * Distinct from `inlineMessageText`: no `alreadyEmitted` dedup, no per-message
182
+ * budget, no placeholder rewriting — single path in, asset-or-error out. Used
183
+ * by the bridge to inline path-referenced image tool results at
184
+ * `tool_execution_end`. See change: inline-agent-screenshot-artifacts.
185
+ */
186
+ export function inlineLocalImagePath(
187
+ absPath: string,
188
+ opts: InlineLocalImageOptions,
189
+ ): AssetToEmit | ReadFileError {
190
+ const outcome = opts.readFile(absPath);
191
+ if (!outcome.ok) return outcome;
192
+ const mime = mimeFromExtension(absPath);
193
+ if (!mime) return { ok: false, kind: "NOT_IMAGE" };
194
+ const maxPerImage = opts.maxPerImageBytes ?? MAX_PER_IMAGE_BYTES;
195
+ if (outcome.bytes.length > maxPerImage) return { ok: false, kind: "TOO_LARGE" };
196
+ return {
197
+ hash: hashBytes(outcome.bytes),
198
+ mimeType: mime,
199
+ data: outcome.bytes.toString("base64"),
200
+ };
201
+ }
202
+
160
203
  export interface InlineResult {
161
204
  /** The rewritten text with every applicable token replaced. */
162
205
  rewritten: string;
@@ -0,0 +1,3 @@
1
+ # markdown-image-inliner.ts — index
2
+
3
+ Bridge helper rewriting assistant `![alt](path)` → `![alt](pi-asset:<hash>)` (SHA-256/16, MIME allowlist, 5 MB/img + 20 MB/msg caps). Adds `inlineLocalImagePath(absPath, opts)` single-path inliner returning `AssetToEmit` \| `ReadFileError` (kinds extended with `NOT_IMAGE` / `TOO_LARGE`). See change: inline-agent-screenshot-artifacts.
@@ -2,9 +2,12 @@
2
2
  * Model and thinking-level change detection.
3
3
  * Sends model_update only when values actually change.
4
4
  */
5
+ import { existsSync, readFileSync } from "node:fs";
6
+ import { dirname, join } from "node:path";
7
+ import { fileURLToPath } from "node:url";
5
8
  import type { BridgeContext } from "./bridge-context.js";
6
9
  import { getCurrentModelString } from "./bridge-context.js";
7
- import { gatherGitInfo, gatherJjInfo } from "./vcs-info.js";
10
+ import { gatherGitInfo, gatherGitStatus } from "./vcs-info.js";
8
11
 
9
12
  /**
10
13
  * Send model_update if model or thinking level has changed since last send.
@@ -40,51 +43,174 @@ export function sendSessionNameIfChanged(bc: BridgeContext): void {
40
43
  }
41
44
 
42
45
  /**
43
- * Send git_info_update if branch or PR has changed since last send.
46
+ * Send git_info_update if branch, PR, or worktree state has changed since last send.
44
47
  */
45
48
  export function sendGitInfoIfChanged(bc: BridgeContext, cwd: string): void {
46
49
  const info = gatherGitInfo(cwd);
47
50
  if (!info) return;
48
- if (info.gitBranch === bc.lastGitBranch && info.gitPrNumber === bc.lastGitPrNumber) return;
51
+ // Worktree state diff: serialise to a stable string. `"null"` marks an
52
+ // explicit "cwd is not a worktree" so a subsequent transition into a
53
+ // worktree still counts as a change.
54
+ const nextWorktreeJson = info.gitWorktree ? JSON.stringify(info.gitWorktree) : "null";
55
+ // Working-tree dirtiness + drift, gathered on the same tick (one extra
56
+ // `git status` — cheap; git is already running here). Serialised for a
57
+ // stable change-diff; `"null"` = inconclusive probe this tick.
58
+ // See change: add-session-uncommitted-indicator-and-commit.
59
+ const status = gatherGitStatus(cwd);
60
+ const nextStatusJson = status ? JSON.stringify(status) : "null";
61
+ if (
62
+ info.gitBranch === bc.lastGitBranch &&
63
+ info.gitPrNumber === bc.lastGitPrNumber &&
64
+ nextWorktreeJson === bc.lastGitWorktreeJson &&
65
+ nextStatusJson === bc.lastGitStatusJson
66
+ ) return;
49
67
  bc.lastGitBranch = info.gitBranch;
50
68
  bc.lastGitPrNumber = info.gitPrNumber;
69
+ bc.lastGitWorktreeJson = nextWorktreeJson;
70
+ bc.lastGitStatusJson = nextStatusJson;
51
71
  bc.connection.send({
52
72
  type: "git_info_update",
53
73
  sessionId: bc.sessionId,
54
74
  ...info,
75
+ // `info` present ⇒ branch resolved ⇒ cwd is a confirmed git repo.
76
+ // See change: gate-session-worktree-button-on-git.
77
+ isGitRepo: true,
78
+ // Use explicit `null` on the wire when worktree state went from
79
+ // present → absent, so the server can clear its cached value.
80
+ gitWorktree: info.gitWorktree ?? null,
81
+ // Omit when the probe was inconclusive so the server keeps the last
82
+ // known status rather than clearing it to a false all-clean.
83
+ ...(status ? { gitStatus: status } : {}),
55
84
  });
56
85
  }
57
86
 
87
+ /**
88
+ * Last pi version pushed via `pi_version_update`. Module-scoped: a single pi
89
+ * process has exactly one pi version, so this correctly survives bridge
90
+ * reconnect and suppresses redundant pushes. See change:
91
+ * restore-pi-version-skew-surface.
92
+ */
93
+ let lastPiVersion: string | undefined;
94
+
95
+ const PI_PKG = "@earendil-works/pi-coding-agent";
96
+
97
+ /**
98
+ * Read a package's `version` without resolving its `./package.json` subpath.
99
+ *
100
+ * Node gates subpath resolution on the package's `exports` map: a package that
101
+ * exports only `"."` makes resolving the `"<pkg>/package.json"` subpath throw
102
+ * `ERR_PACKAGE_PATH_NOT_EXPORTED` (pi 0.80.2 is such a package). So we resolve
103
+ * the always-present `"."` entry instead, then walk up to the nearest
104
+ * `package.json` whose `name` matches — the `name` check avoids grabbing an
105
+ * ancestor workspace manifest under hoisted/linked layouts. Returns `undefined`
106
+ * (not throw) when no matching manifest is found; a truly-uninstalled package
107
+ * still throws from `resolveEntry`, which the caller catches.
108
+ *
109
+ * `resolveEntry`/`readFile`/`fileExists` are injectable for tests.
110
+ */
111
+ export function readPkgVersionByWalkUp(
112
+ pkgName: string,
113
+ resolveEntry: (spec: string) => string,
114
+ readFile: (p: string) => string = (p) => readFileSync(p, "utf8"),
115
+ fileExists: (p: string) => boolean = existsSync,
116
+ ): string | undefined {
117
+ let dir = dirname(resolveEntry(pkgName));
118
+ for (let i = 0; i < 10; i++) {
119
+ const candidate = join(dir, "package.json");
120
+ if (fileExists(candidate)) {
121
+ const parsed = JSON.parse(readFile(candidate)) as { name?: string; version?: string };
122
+ if (parsed.name === pkgName) {
123
+ return typeof parsed.version === "string" ? parsed.version : undefined;
124
+ }
125
+ }
126
+ const parent = dirname(dir);
127
+ if (parent === dir) break;
128
+ dir = parent;
129
+ }
130
+ return undefined;
131
+ }
132
+
133
+ /**
134
+ * Default reader: pi-coding-agent version from inside the bridge's own tree.
135
+ *
136
+ * Uses `import.meta.resolve` (the ESM resolver, `import` condition) rather than
137
+ * `createRequire().resolve` (CJS, `require` condition): pi's `"."` export defines
138
+ * only `import`/`types`, so the CJS resolver would itself throw
139
+ * `ERR_PACKAGE_PATH_NOT_EXPORTED` ("No exports main defined"). `import.meta.resolve`
140
+ * returns a `file://` URL, converted to a path for the walk-up.
141
+ */
142
+ export function defaultReadPiVersion(): string | undefined {
143
+ return readPkgVersionByWalkUp(PI_PKG, (spec) => fileURLToPath(import.meta.resolve(spec)));
144
+ }
145
+
146
+ /**
147
+ * Send `pi_version_update` when the bridge's pi version differs from the last
148
+ * sent value (including the first read). The bridge runs inside pi's own tree,
149
+ * so `createRequire` resolution always succeeds. A read failure logs a warning
150
+ * and skips the send; the next poll tick retries. `readVersion` is injectable
151
+ * for tests.
152
+ */
153
+ export function sendPiVersionIfChanged(
154
+ bc: BridgeContext,
155
+ readVersion: () => string | undefined = defaultReadPiVersion,
156
+ ): void {
157
+ let version: string | undefined;
158
+ try {
159
+ version = readVersion();
160
+ } catch (e) {
161
+ console.warn("[dashboard] pi version read failed:", e);
162
+ return;
163
+ }
164
+ if (!version || version === lastPiVersion) return;
165
+ lastPiVersion = version;
166
+ bc.connection.send({
167
+ type: "pi_version_update",
168
+ sessionId: bc.sessionId,
169
+ version,
170
+ });
171
+ }
172
+
173
+ /** Test-only: clear the module-scoped pi-version cache. */
174
+ export function _resetPiVersionCache(): void {
175
+ lastPiVersion = undefined;
176
+ }
177
+
58
178
  /**
59
179
  * Reset the change-detection caches that aren't persisted on the server
60
180
  * side, so a server-restart-driven reconnect re-sends them. `gitBranch`
61
181
  * is already persisted to `.meta.json` so it's tolerable for a tick of
62
- * staleness; `jjState` is intentionally NOT persisted (live tool state)
63
- * and must be re-emitted on every reconnect.
64
- * See change: add-jj-workspace-plugin.
182
+ * staleness.
65
183
  */
66
184
  export function resetReconnectCaches(bc: BridgeContext): void {
67
- bc.lastJjStateJson = undefined;
68
- // Defensive: also reset git so a reconnect through a stale state cache
185
+ // Defensive: reset git so a reconnect through a stale state cache
69
186
  // doesn't surface stale branch info if .meta.json wasn't persisted yet.
70
187
  bc.lastGitBranch = undefined;
71
188
  bc.lastGitPrNumber = undefined;
189
+ bc.lastGitWorktreeJson = undefined;
190
+ bc.lastGitStatusJson = undefined;
72
191
  }
73
192
 
74
193
  /**
75
- * Send jj_state_update if the cwd's jj state has changed since last send.
76
- * Sends `null` to clear when the session leaves a jj repo (cwd switch).
77
- * No-op when there's nothing to clear and nothing to send.
78
- * See change: add-jj-workspace-plugin.
194
+ * Emit `cwd_missing` the first time `existsSync(cwd)` flips to false.
195
+ * Debounced via `bc.lastCwdMissing` — once we've reported missing, the
196
+ * tick is a no-op forever (we never reset to false on rediscovery; see
197
+ * the BridgeContext doc-comment for the rationale).
198
+ *
199
+ * Pure with respect to `bc` aside from caching the flag; the only side
200
+ * effect is `connection.send`. See change: add-worktree-lifecycle-actions.
79
201
  */
80
- export function sendJjStateIfChanged(bc: BridgeContext, cwd: string): void {
81
- const state = gatherJjInfo(cwd);
82
- const nextJson = state ? JSON.stringify(state) : "";
83
- if (nextJson === (bc.lastJjStateJson ?? "")) return;
84
- bc.lastJjStateJson = nextJson;
202
+ export function sendCwdMissingIfChanged(
203
+ bc: BridgeContext,
204
+ cwd: string,
205
+ exists: (p: string) => boolean = existsSync,
206
+ ): void {
207
+ if (bc.lastCwdMissing === true) return;
208
+ if (!cwd) return;
209
+ if (exists(cwd)) return;
210
+ bc.lastCwdMissing = true;
85
211
  bc.connection.send({
86
- type: "jj_state_update",
212
+ type: "cwd_missing",
87
213
  sessionId: bc.sessionId,
88
- jjState: state ?? null,
89
214
  });
90
215
  }
216
+
@@ -0,0 +1,3 @@
1
+ # model-tracker.ts — index
2
+
3
+ Diff-and-send trackers for model / session name / git info / pi version / cwd-missing. Exports `sendModelUpdateIfChanged`, `sendSessionNameIfChanged`, `sendGitInfoIfChanged`, `sendPiVersionIfChanged`, `sendCwdMissingIfChanged`, `resetReconnectCaches`. Suppressed redundant sends across reconnects. `sendGitInfoIfChanged` also gathers `gatherGitStatus` and includes `gitStatus` in `git_info_update` (dedup via `lastGitStatusJson`; omitted on inconclusive probe). See change: add-session-uncommitted-indicator-and-commit.
@@ -0,0 +1,3 @@
1
+ # multiselect-decode.ts — index
2
+
3
+ Pure helper decoding `PromptResponse` into `string[] | undefined`. Exports `decodeMultiselectAnswer`, `DecodableResponse`. Cancelled → undefined; empty answer → `[]`; unparseable JSON → `[]` (never throws). Separated from bridge for unit testing.
@@ -0,0 +1,3 @@
1
+ # multiselect-list.ts — index
2
+
3
+ TUI multi-select component implementing pi-tui `ComponentLike`. Exports `MultiSelectList`, `ComponentLike`. Keyboard: arrows/jk move, space toggle, enter confirm, esc cancel. Legacy fallback renderer for `polyfillMultiselect`.
@@ -0,0 +1,3 @@
1
+ # multiselect-polyfill.ts — index
2
+
3
+ Polyfill `ctx.ui.multiselect`. Exports `polyfillMultiselect`, `PolyfillCtx`. Primary path delegates to bridge-patched `ctx.ui.multiselect` (PromptBus → DashboardDefaultAdapter); legacy fallback renders `MultiSelectList` via `ctx.ui.custom`.
@@ -0,0 +1,3 @@
1
+ # process-metrics.ts — index
2
+
3
+ Lightweight process metrics collector for bridge heartbeats. Exports `startMetricsMonitor`, `stopMetricsMonitor`, `collectMetrics`. Returns `ProcessMetrics` (rss, heap, cpuPercent, eventLoopMaxMs, loadAvg1m) via Node built-ins; event-loop-delay monitor opt-in.