@blackbelt-technology/pi-dashboard-extension 0.7.0 → 0.8.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 (216) hide show
  1. package/.pi/skills/browser/SKILL.md +28 -14
  2. package/.pi/skills/browser/UPSTREAM.md +10 -1
  3. package/.pi/skills/browser/references/electron.agent.md +57 -0
  4. package/.pi/skills/browser/references/own-browser.md +299 -0
  5. package/.pi/skills/browser/references/web.agent.md +323 -0
  6. package/.pi/skills/browser/scripts/check-panerelay.sh +157 -0
  7. package/.pi/skills/doctor/SKILL.md +3 -9
  8. package/.pi/skills/doctor/_lib/checks.ts +14 -68
  9. package/.pi/skills/doctor/_lib/derive-tokens.ts +1 -0
  10. package/.pi/skills/doctor/modules/apple-tools.knowledge.hash +1 -0
  11. package/.pi/skills/doctor/modules/apple-tools.md +51 -0
  12. package/.pi/skills/doctor/modules/oauth-redirect-base.knowledge.hash +1 -0
  13. package/.pi/skills/doctor/modules/oauth-redirect-base.md +71 -0
  14. package/.pi/skills/doctor/modules/pi-resolution.knowledge.hash +1 -1
  15. package/.pi/skills/doctor/modules/pi-resolution.md +21 -1
  16. package/.pi/skills/pi-dashboard/references/api-reference.agent.md +69 -0
  17. package/.pi/skills/project-init/SKILL.md +1 -7
  18. package/.pi/skills/project-init/dox-doctrine.md +42 -0
  19. package/.pi/skills/project-init/profiles/docs/profile.json +1 -1
  20. package/README.md +19 -0
  21. package/agents/DoxTriage.md +80 -0
  22. package/package.json +22 -11
  23. package/src/agent-settled.ts +27 -9
  24. package/src/auto-session-namer.ts +486 -70
  25. package/src/autostart-guard.ts +99 -0
  26. package/src/autostart-lock.ts +258 -0
  27. package/src/bridge-context.ts +86 -5
  28. package/src/bridge-ticket-client.ts +105 -0
  29. package/src/bridge.ts +917 -213
  30. package/src/command-handler.ts +332 -57
  31. package/src/connect-target.ts +130 -0
  32. package/src/connection.ts +371 -7
  33. package/src/endpoint-resolution.ts +221 -0
  34. package/src/flow-event-wiring.ts +125 -3
  35. package/src/followup-buffer.ts +217 -0
  36. package/src/instance-verification.ts +125 -0
  37. package/src/local-token-header.ts +44 -0
  38. package/src/model-refresh.ts +95 -0
  39. package/src/notify-proxy.ts +33 -0
  40. package/src/pi-env.d.ts +4 -0
  41. package/src/pi-retry-settings.ts +91 -0
  42. package/src/provider-register.ts +86 -21
  43. package/src/remote-registration-gate.ts +102 -0
  44. package/src/retry-tracker.ts +265 -86
  45. package/src/role-manager.ts +20 -0
  46. package/src/role-model-tools.ts +38 -3
  47. package/src/server-auto-start.ts +144 -2
  48. package/src/server-pin-store.ts +92 -0
  49. package/src/session-move.ts +275 -0
  50. package/src/session-sync.ts +24 -5
  51. package/src/subagent-forward-sites.ts +69 -0
  52. package/src/subagent-frame-buffer.ts +24 -3
  53. package/src/subagent-frame-strip.ts +109 -0
  54. package/src/subagent-tick-throttle.ts +250 -0
  55. package/src/transcript-backfill.ts +151 -0
  56. package/src/transcript-request-guard.ts +76 -0
  57. package/src/transport-diagnostics.ts +76 -0
  58. package/src/turn-actionability.ts +20 -0
  59. package/src/ui-stale-guard.ts +58 -0
  60. package/.pi/skills/doctor/AGENTS.md +0 -27
  61. package/src/AGENTS.md +0 -57
  62. package/src/__tests__/abort-latch.test.ts +0 -97
  63. package/src/__tests__/agent-settled.test.ts +0 -82
  64. package/src/__tests__/artifact-roots.test.ts +0 -83
  65. package/src/__tests__/ask-user-attachments.test.ts +0 -106
  66. package/src/__tests__/ask-user-schema-discriminator.test.ts +0 -141
  67. package/src/__tests__/ask-user-tool.test.ts +0 -571
  68. package/src/__tests__/auto-session-namer.test.ts +0 -339
  69. package/src/__tests__/bridge-default-model-apply.test.ts +0 -242
  70. package/src/__tests__/bridge-default-model-gate.test.ts +0 -50
  71. package/src/__tests__/bridge-entry-id-pi-070.test.ts +0 -174
  72. package/src/__tests__/bridge-followup-chat-order.test.ts +0 -215
  73. package/src/__tests__/bridge-followup-multi-entry.test.ts +0 -202
  74. package/src/__tests__/bridge-followup-mutation.test.ts +0 -217
  75. package/src/__tests__/bridge-followup-queue-drain.test.ts +0 -266
  76. package/src/__tests__/bridge-hasui-flip.test.ts +0 -109
  77. package/src/__tests__/bridge-no-queue-mutation.test.ts +0 -112
  78. package/src/__tests__/bridge-plugin-emit-event.test.ts +0 -44
  79. package/src/__tests__/bridge-queue-update-forward.test.ts +0 -77
  80. package/src/__tests__/bridge-resume-disconnect.test.ts +0 -333
  81. package/src/__tests__/bridge-shadow-queue-gate.test.ts +0 -299
  82. package/src/__tests__/bridge-shutdown-reset.test.ts +0 -159
  83. package/src/__tests__/bridge-slash-command-routing.test.ts +0 -458
  84. package/src/__tests__/bridge-stop-after-turn.test.ts +0 -72
  85. package/src/__tests__/bridge-system-followup.test.ts +0 -163
  86. package/src/__tests__/bridge-thinking-level-select.test.ts +0 -68
  87. package/src/__tests__/browser-skill-registered.test.ts +0 -84
  88. package/src/__tests__/build-provider-catalogue.test.ts +0 -210
  89. package/src/__tests__/command-handler.test.ts +0 -1180
  90. package/src/__tests__/commit-draft.test.ts +0 -100
  91. package/src/__tests__/connection-dropped-frames.test.ts +0 -78
  92. package/src/__tests__/connection-suppress-auto-start.test.ts +0 -97
  93. package/src/__tests__/connection.test.ts +0 -344
  94. package/src/__tests__/credentials-updated.test.ts +0 -26
  95. package/src/__tests__/custom-provider-apikey-roundtrip.test.ts +0 -128
  96. package/src/__tests__/cwd-missing-probe.test.ts +0 -82
  97. package/src/__tests__/dashboard-commands-shipped.test.ts +0 -53
  98. package/src/__tests__/dashboard-context-injector.test.ts +0 -190
  99. package/src/__tests__/dashboard-default-adapter.test.ts +0 -77
  100. package/src/__tests__/dev-build.test.ts +0 -79
  101. package/src/__tests__/doctor/checks.test.ts +0 -121
  102. package/src/__tests__/doctor/modules.test.ts +0 -64
  103. package/src/__tests__/doctor/provenance-hash.test.ts +0 -94
  104. package/src/__tests__/doctor/router.test.ts +0 -143
  105. package/src/__tests__/empty-actionable-guard-config.test.ts +0 -32
  106. package/src/__tests__/empty-actionable-guard.test.ts +0 -73
  107. package/src/__tests__/enrich-model-metadata.test.ts +0 -222
  108. package/src/__tests__/event-forwarder.test.ts +0 -119
  109. package/src/__tests__/extension-slash-command-detection.test.ts +0 -143
  110. package/src/__tests__/filter-enabled-models.test.ts +0 -151
  111. package/src/__tests__/fixtures/turn-actionability-fixtures.ts +0 -69
  112. package/src/__tests__/fork-entryid-timing.test.ts +0 -88
  113. package/src/__tests__/git-info-status.test.ts +0 -73
  114. package/src/__tests__/git-link-builder.test.ts +0 -102
  115. package/src/__tests__/git-poll.test.ts +0 -69
  116. package/src/__tests__/markdown-image-inliner.test.ts +0 -392
  117. package/src/__tests__/model-resolve.test.ts +0 -379
  118. package/src/__tests__/multiselect-dashboard-routing.test.ts +0 -203
  119. package/src/__tests__/multiselect-list.test.ts +0 -137
  120. package/src/__tests__/multiselect-polyfill.test.ts +0 -92
  121. package/src/__tests__/no-session-replacement-calls.test.ts +0 -99
  122. package/src/__tests__/no-tui-multiselect-arm-regression.test.ts +0 -81
  123. package/src/__tests__/openspec-activity-detector.test.ts +0 -337
  124. package/src/__tests__/openspec-cli-shim.test.ts +0 -145
  125. package/src/__tests__/openspec-poller.test.ts +0 -124
  126. package/src/__tests__/pi-version-tracker.test.ts +0 -109
  127. package/src/__tests__/process-metrics.test.ts +0 -47
  128. package/src/__tests__/process-scanner-kill.test.ts +0 -61
  129. package/src/__tests__/process-scanner.test.ts +0 -292
  130. package/src/__tests__/project-init-detect-stack.test.ts +0 -61
  131. package/src/__tests__/project-init-dox-kb-config.test.ts +0 -53
  132. package/src/__tests__/project-init-profiles.test.ts +0 -84
  133. package/src/__tests__/project-init-scaffold.test.ts +0 -139
  134. package/src/__tests__/project-init-seed-doctrine.test.ts +0 -100
  135. package/src/__tests__/project-trust.test.ts +0 -92
  136. package/src/__tests__/prompt-bus-wiring.test.ts +0 -791
  137. package/src/__tests__/prompt-bus.test.ts +0 -513
  138. package/src/__tests__/prompt-expander.test.ts +0 -398
  139. package/src/__tests__/provider-register-native-models.test.ts +0 -182
  140. package/src/__tests__/provider-register-reload.test.ts +0 -498
  141. package/src/__tests__/provider-register-thinking-levels.test.ts +0 -104
  142. package/src/__tests__/retry-tracker.test.ts +0 -152
  143. package/src/__tests__/role-manager.test.ts +0 -585
  144. package/src/__tests__/role-model-tools-registry-readiness.test.ts +0 -114
  145. package/src/__tests__/role-model-tools.test.ts +0 -229
  146. package/src/__tests__/search-files-completeness.test.ts +0 -111
  147. package/src/__tests__/search-files-ranking.test.ts +0 -168
  148. package/src/__tests__/server-auto-start.test.ts +0 -375
  149. package/src/__tests__/server-launcher-launch.test.ts +0 -96
  150. package/src/__tests__/server-launcher.test.ts +0 -101
  151. package/src/__tests__/server-probe.test.ts +0 -25
  152. package/src/__tests__/session-switch.test.ts +0 -139
  153. package/src/__tests__/session-sync.test.ts +0 -243
  154. package/src/__tests__/single-derivation-guard.test.ts +0 -39
  155. package/src/__tests__/source-detector.test.ts +0 -88
  156. package/src/__tests__/stats-extractor.test.ts +0 -92
  157. package/src/__tests__/subagent-frame-buffer.test.ts +0 -239
  158. package/src/__tests__/tool-result-image-inliner.test.ts +0 -206
  159. package/src/__tests__/tui-prompt-adapter.test.ts +0 -213
  160. package/src/__tests__/turn-actionability.test.ts +0 -86
  161. package/src/__tests__/ui-decorators.test.ts +0 -309
  162. package/src/__tests__/ui-modules.test.ts +0 -293
  163. package/src/__tests__/vcs-info.test.ts +0 -265
  164. package/src/__tests__/visibility-intent.test.ts +0 -43
  165. package/src/__tests__/watchdog.test.ts +0 -161
  166. package/src/abort-latch.ts.AGENTS.md +0 -3
  167. package/src/agent-settled.ts.AGENTS.md +0 -3
  168. package/src/artifact-roots.ts.AGENTS.md +0 -3
  169. package/src/ask-user-attachments.ts.AGENTS.md +0 -3
  170. package/src/ask-user-tool.ts.AGENTS.md +0 -3
  171. package/src/auto-session-namer.ts.AGENTS.md +0 -3
  172. package/src/bridge-context.ts.AGENTS.md +0 -3
  173. package/src/bridge-default-model-gate.ts.AGENTS.md +0 -3
  174. package/src/bridge.ts.AGENTS.md +0 -3
  175. package/src/command-handler.ts.AGENTS.md +0 -3
  176. package/src/commit-draft-agent.ts.AGENTS.md +0 -3
  177. package/src/commit-draft.ts.AGENTS.md +0 -3
  178. package/src/connection.ts.AGENTS.md +0 -3
  179. package/src/dashboard-context-injector.ts.AGENTS.md +0 -3
  180. package/src/dashboard-default-adapter.ts.AGENTS.md +0 -3
  181. package/src/dev-build.ts.AGENTS.md +0 -3
  182. package/src/empty-actionable-guard-config.ts.AGENTS.md +0 -3
  183. package/src/empty-actionable-guard.ts.AGENTS.md +0 -3
  184. package/src/event-forwarder.ts.AGENTS.md +0 -3
  185. package/src/flow-event-wiring.ts.AGENTS.md +0 -3
  186. package/src/git-link-builder.ts.AGENTS.md +0 -3
  187. package/src/git-poll.ts.AGENTS.md +0 -3
  188. package/src/hasui-flip.ts.AGENTS.md +0 -3
  189. package/src/markdown-image-inliner.ts.AGENTS.md +0 -3
  190. package/src/model-tracker.ts.AGENTS.md +0 -3
  191. package/src/multiselect-decode.ts.AGENTS.md +0 -3
  192. package/src/multiselect-list.ts.AGENTS.md +0 -3
  193. package/src/multiselect-polyfill.ts.AGENTS.md +0 -3
  194. package/src/openspec-cli-shim.ts.AGENTS.md +0 -7
  195. package/src/process-metrics.ts.AGENTS.md +0 -3
  196. package/src/process-scanner.ts.AGENTS.md +0 -3
  197. package/src/project-init/AGENTS.md +0 -12
  198. package/src/project-trust.ts.AGENTS.md +0 -3
  199. package/src/prompt-bus.ts.AGENTS.md +0 -3
  200. package/src/prompt-expander.ts.AGENTS.md +0 -3
  201. package/src/provider-register.ts.AGENTS.md +0 -3
  202. package/src/retry-tracker.ts.AGENTS.md +0 -3
  203. package/src/role-manager.ts.AGENTS.md +0 -3
  204. package/src/role-model-tools.ts.AGENTS.md +0 -3
  205. package/src/server-auto-start.ts.AGENTS.md +0 -3
  206. package/src/server-launcher.ts.AGENTS.md +0 -3
  207. package/src/session-sync.ts.AGENTS.md +0 -3
  208. package/src/slash-dispatch.ts.AGENTS.md +0 -3
  209. package/src/source-detector.ts.AGENTS.md +0 -3
  210. package/src/subagent-frame-buffer.ts.AGENTS.md +0 -3
  211. package/src/tool-result-image-inliner.ts.AGENTS.md +0 -3
  212. package/src/tui-prompt-adapter.ts.AGENTS.md +0 -3
  213. package/src/turn-actionability.ts.AGENTS.md +0 -3
  214. package/src/ui-modules.ts.AGENTS.md +0 -3
  215. package/src/vcs-info.ts.AGENTS.md +0 -3
  216. package/src/visibility-intent.ts.AGENTS.md +0 -3
@@ -1,86 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { classifyTurnActionability } from "../turn-actionability.js";
3
- import {
4
- EMPTY_STOP,
5
- ERRORED_TURN,
6
- LENGTH_TRUNCATED,
7
- NORMAL_TEXT_STOP,
8
- THINKING_ONLY_STOP,
9
- TOOL_CALL_TURN,
10
- WHITESPACE_TEXT_STOP,
11
- } from "./fixtures/turn-actionability-fixtures.js";
12
-
13
- describe("classifyTurnActionability", () => {
14
- it("classifies a thinking-only stop as empty-actionable (captured defect)", () => {
15
- expect(classifyTurnActionability(THINKING_ONLY_STOP)).toBe("empty-actionable");
16
- });
17
-
18
- it("classifies a wholly-empty stop as empty-actionable", () => {
19
- expect(classifyTurnActionability(EMPTY_STOP)).toBe("empty-actionable");
20
- });
21
-
22
- it("classifies whitespace-only text as empty-actionable", () => {
23
- expect(classifyTurnActionability(WHITESPACE_TEXT_STOP)).toBe("empty-actionable");
24
- });
25
-
26
- it("classifies a turn with visible text as normal", () => {
27
- expect(classifyTurnActionability(NORMAL_TEXT_STOP)).toBe("normal");
28
- });
29
-
30
- it("classifies a turn with a tool call as normal", () => {
31
- expect(classifyTurnActionability(TOOL_CALL_TURN)).toBe("normal");
32
- });
33
-
34
- it("classifies a length-truncated turn as truncated (NOT empty-actionable)", () => {
35
- expect(classifyTurnActionability(LENGTH_TRUNCATED)).toBe("truncated");
36
- });
37
-
38
- it("classifies an errored turn as error", () => {
39
- expect(classifyTurnActionability(ERRORED_TURN)).toBe("error");
40
- });
41
-
42
- it("treats a non-empty error object as error even with stopReason stop", () => {
43
- expect(
44
- classifyTurnActionability({ role: "assistant", stopReason: "stop", content: [], error: { code: 500 } }),
45
- ).toBe("error");
46
- });
47
-
48
- it("treats an empty error object as no error", () => {
49
- expect(
50
- classifyTurnActionability({ role: "assistant", stopReason: "stop", content: [], error: {} }),
51
- ).toBe("empty-actionable");
52
- });
53
-
54
- it("classifies a bare non-empty string content as normal", () => {
55
- expect(classifyTurnActionability({ role: "assistant", stopReason: "stop", content: "hello" })).toBe(
56
- "normal",
57
- );
58
- });
59
-
60
- it("classifies a bare empty string content as empty-actionable", () => {
61
- expect(classifyTurnActionability({ role: "assistant", stopReason: "stop", content: "" })).toBe(
62
- "empty-actionable",
63
- );
64
- });
65
-
66
- it("does not depend on provider identity (max_tokens truncation)", () => {
67
- expect(
68
- classifyTurnActionability({ role: "assistant", stopReason: "max_tokens", content: [] }),
69
- ).toBe("truncated");
70
- });
71
-
72
- it("returns normal for a null/undefined turn (defensive)", () => {
73
- expect(classifyTurnActionability(undefined)).toBe("normal");
74
- expect(classifyTurnActionability(null)).toBe("normal");
75
- });
76
-
77
- it("keeps a tool call normal even when stopReason is a truncation", () => {
78
- expect(
79
- classifyTurnActionability({
80
- role: "assistant",
81
- stopReason: "length",
82
- content: [{ type: "toolCall", id: "t1", name: "read" }],
83
- }),
84
- ).toBe("normal");
85
- });
86
- });
@@ -1,309 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
- import { refreshUiModules, subscribeUiInvalidate, type UiModulesBridgeCtx } from "../ui-modules.js";
3
- import type { DecoratorDescriptor, ExtensionUiModule } from "@blackbelt-technology/pi-dashboard-shared/types.js";
4
-
5
- /**
6
- * Phase-2 (`add-extension-ui-decorations`) bridge contract:
7
- *
8
- * - `refreshUiModules` partitions probe.modules by `kind` — `management-modal`
9
- * keeps flowing through `ui_modules_list`; the five Phase-2 kinds each
10
- * forward as one `ext_ui_decorator` message.
11
- * - Decorators MUST carry a `namespace` matching `/^[a-z0-9-]+$/`; malformed
12
- * namespaces are dropped with a warning.
13
- * - `(kind, namespace, id)` collisions within one probe → warning + last-write-wins.
14
- * - `removed: true` is forwarded verbatim.
15
- * - `ui:invalidate` re-runs the partitioned probe.
16
- * - Per-session invalidate rate cap: ≤20 invalidations/second; excess
17
- * coalesced to a trailing-edge probe with one warning.
18
- */
19
-
20
- function createTestCtx(sessionId = "s1") {
21
- const listeners = new Map<string, Array<(...args: any[]) => any>>();
22
- const sent: any[] = [];
23
-
24
- const ctx: UiModulesBridgeCtx & { _sent: any[]; _listeners: typeof listeners } = {
25
- pi: {
26
- events: {
27
- on: vi.fn((event: string, fn: (...args: any[]) => any) => {
28
- if (!listeners.has(event)) listeners.set(event, []);
29
- listeners.get(event)!.push(fn);
30
- }) as any,
31
- emit: vi.fn((event: string, ...args: any[]) => {
32
- const handlers = listeners.get(event) ?? [];
33
- for (const h of handlers) h(...args);
34
- }) as any,
35
- },
36
- },
37
- connection: {
38
- send: vi.fn((msg: unknown) => {
39
- sent.push(msg);
40
- }) as any,
41
- },
42
- getSessionId: () => sessionId,
43
- _sent: sent,
44
- _listeners: listeners,
45
- };
46
- return ctx;
47
- }
48
-
49
- const sampleModule = (id: string, command: string): ExtensionUiModule => ({
50
- kind: "management-modal",
51
- id,
52
- command,
53
- title: id,
54
- view: { kind: "table", dataEvent: `${id}:rows`, fields: [{ key: "id", label: "ID", kind: "text" }] },
55
- });
56
-
57
- const footerSeg = (namespace: string, id: string, text: string): DecoratorDescriptor => ({
58
- kind: "footer-segment",
59
- namespace,
60
- id,
61
- payload: { text },
62
- });
63
-
64
- const gate = (namespace: string, id: string, flowId: string, available: boolean, reason?: string): DecoratorDescriptor => ({
65
- kind: "gate",
66
- namespace,
67
- id,
68
- payload: { flowId, available, reason },
69
- });
70
-
71
- const toast = (namespace: string, id: string, message: string): DecoratorDescriptor => ({
72
- kind: "toast",
73
- namespace,
74
- id,
75
- payload: { level: "info", message },
76
- });
77
-
78
- describe("refreshUiModules — Phase-2 partitioning", () => {
79
- it("partitions a mixed probe into one ui_modules_list (modal-only) plus one ext_ui_decorator per decorator", () => {
80
- const ctx = createTestCtx("S");
81
- ctx._listeners.set("ui:list-modules", [
82
- (probe: { modules: any[] }) => {
83
- probe.modules.push(sampleModule("judo-status", "/judo:status"));
84
- probe.modules.push(footerSeg("judo", "model-state", "3 mut"));
85
- probe.modules.push(gate("judo", "save", "judo:save", false, "Not in workspace"));
86
- probe.modules.push(toast("flows", "done", "Flow finished"));
87
- },
88
- ]);
89
-
90
- refreshUiModules(ctx);
91
-
92
- // Exactly one ui_modules_list, exactly three ext_ui_decorator.
93
- const moduleMsgs = ctx._sent.filter((m) => m.type === "ui_modules_list");
94
- const decoratorMsgs = ctx._sent.filter((m) => m.type === "ext_ui_decorator");
95
- expect(moduleMsgs).toHaveLength(1);
96
- expect(decoratorMsgs).toHaveLength(3);
97
-
98
- expect(moduleMsgs[0]).toMatchObject({
99
- type: "ui_modules_list",
100
- sessionId: "S",
101
- modules: [expect.objectContaining({ id: "judo-status", kind: "management-modal" })],
102
- });
103
-
104
- const kinds = decoratorMsgs.map((m) => m.descriptor.kind).sort();
105
- expect(kinds).toEqual(["footer-segment", "gate", "toast"]);
106
- for (const m of decoratorMsgs) {
107
- expect(m.sessionId).toBe("S");
108
- expect(m.removed).toBeUndefined();
109
- }
110
- });
111
-
112
- it("forwards no decorator messages when only modal modules are pushed", () => {
113
- const ctx = createTestCtx();
114
- ctx._listeners.set("ui:list-modules", [
115
- (probe: { modules: any[] }) => {
116
- probe.modules.push(sampleModule("a", "/a"));
117
- },
118
- ]);
119
- refreshUiModules(ctx);
120
- expect(ctx._sent.filter((m) => m.type === "ext_ui_decorator")).toHaveLength(0);
121
- expect(ctx._sent.filter((m) => m.type === "ui_modules_list")).toHaveLength(1);
122
- });
123
-
124
- it("forwards decorator-only probe with empty modules list", () => {
125
- const ctx = createTestCtx();
126
- ctx._listeners.set("ui:list-modules", [
127
- (probe: { modules: any[] }) => {
128
- probe.modules.push(footerSeg("judo", "f1", "x"));
129
- probe.modules.push(footerSeg("judo", "f2", "y"));
130
- },
131
- ]);
132
- refreshUiModules(ctx);
133
- const modulesMsg = ctx._sent.find((m) => m.type === "ui_modules_list");
134
- expect(modulesMsg).toBeDefined();
135
- expect(modulesMsg.modules).toEqual([]);
136
- expect(ctx._sent.filter((m) => m.type === "ext_ui_decorator")).toHaveLength(2);
137
- });
138
-
139
- it("rejects decorators with malformed namespace and warns", () => {
140
- const ctx = createTestCtx();
141
- const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
142
- try {
143
- ctx._listeners.set("ui:list-modules", [
144
- (probe: { modules: any[] }) => {
145
- probe.modules.push(footerSeg("", "id1", "bad-empty"));
146
- probe.modules.push(footerSeg("UPPER", "id2", "bad-case"));
147
- probe.modules.push(footerSeg("with space", "id3", "bad-space"));
148
- probe.modules.push(footerSeg("ok-ns", "id4", "good"));
149
- },
150
- ]);
151
- refreshUiModules(ctx);
152
-
153
- const decoratorMsgs = ctx._sent.filter((m) => m.type === "ext_ui_decorator");
154
- expect(decoratorMsgs).toHaveLength(1);
155
- expect(decoratorMsgs[0].descriptor.namespace).toBe("ok-ns");
156
- // Three bad descriptors → at least one warning each (or one combined).
157
- expect(warn).toHaveBeenCalled();
158
- const allWarnText = warn.mock.calls.map((c) => String(c[0])).join("\n");
159
- expect(allWarnText).toMatch(/namespace/i);
160
- } finally {
161
- warn.mockRestore();
162
- }
163
- });
164
-
165
- it("collisions on (kind, namespace, id) within one probe warn once and last-write-wins", () => {
166
- const ctx = createTestCtx();
167
- const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
168
- try {
169
- ctx._listeners.set("ui:list-modules", [
170
- (probe: { modules: any[] }) => {
171
- probe.modules.push(footerSeg("judo", "x", "first"));
172
- probe.modules.push(footerSeg("judo", "x", "second"));
173
- probe.modules.push(footerSeg("judo", "x", "third"));
174
- },
175
- ]);
176
- refreshUiModules(ctx);
177
-
178
- const decoratorMsgs = ctx._sent.filter((m) => m.type === "ext_ui_decorator");
179
- expect(decoratorMsgs).toHaveLength(1);
180
- expect((decoratorMsgs[0].descriptor.payload as any).text).toBe("third");
181
- // One warning per colliding key, regardless of how many duplicates.
182
- const collisionWarnings = warn.mock.calls.filter((c) => /footer-segment:judo:x/.test(String(c[0])));
183
- expect(collisionWarnings.length).toBe(1);
184
- } finally {
185
- warn.mockRestore();
186
- }
187
- });
188
-
189
- it("different namespaces with the same id are NOT a collision", () => {
190
- const ctx = createTestCtx();
191
- ctx._listeners.set("ui:list-modules", [
192
- (probe: { modules: any[] }) => {
193
- probe.modules.push(footerSeg("judo", "model-state", "judo-text"));
194
- probe.modules.push(footerSeg("flows", "model-state", "flows-text"));
195
- },
196
- ]);
197
- refreshUiModules(ctx);
198
- const decoratorMsgs = ctx._sent.filter((m) => m.type === "ext_ui_decorator");
199
- expect(decoratorMsgs).toHaveLength(2);
200
- const namespaces = decoratorMsgs.map((m) => m.descriptor.namespace).sort();
201
- expect(namespaces).toEqual(["flows", "judo"]);
202
- });
203
-
204
- it("forwards `removed: true` verbatim on decorator descriptors", () => {
205
- const ctx = createTestCtx();
206
- ctx._listeners.set("ui:list-modules", [
207
- (probe: { modules: any[] }) => {
208
- probe.modules.push({ ...gate("judo", "save", "judo:save", true), removed: true });
209
- },
210
- ]);
211
- refreshUiModules(ctx);
212
- const decoratorMsgs = ctx._sent.filter((m) => m.type === "ext_ui_decorator");
213
- expect(decoratorMsgs).toHaveLength(1);
214
- expect(decoratorMsgs[0].removed).toBe(true);
215
- expect(decoratorMsgs[0].descriptor.kind).toBe("gate");
216
- });
217
-
218
- it("does not regress Phase-1 module-only probes", () => {
219
- // Mirrors the Phase-1 test "emits ui:list-modules and forwards collected
220
- // modules as ui_modules_list" — Phase-2 partitioning MUST be a no-op when
221
- // no decorators are pushed.
222
- const ctx = createTestCtx("session-A");
223
- ctx._listeners.set("ui:list-modules", [
224
- (probe: { modules: ExtensionUiModule[] }) => {
225
- probe.modules.push(sampleModule("judo-status", "/judo:status"));
226
- probe.modules.push(sampleModule("ragger-workspaces", "/ragger:workspaces"));
227
- },
228
- ]);
229
- refreshUiModules(ctx);
230
- const moduleMsgs = ctx._sent.filter((m) => m.type === "ui_modules_list");
231
- expect(moduleMsgs).toHaveLength(1);
232
- expect(moduleMsgs[0].modules).toHaveLength(2);
233
- expect(ctx._sent.filter((m) => m.type === "ext_ui_decorator")).toHaveLength(0);
234
- });
235
- });
236
-
237
- describe("subscribeUiInvalidate — Phase-2 re-forwarding", () => {
238
- it("re-runs the partitioned probe on every ui:invalidate (leading + trailing under throttle)", () => {
239
- vi.useFakeTimers();
240
- try {
241
- const ctx = createTestCtx();
242
- let counter = 0;
243
- ctx._listeners.set("ui:list-modules", [
244
- (probe: { modules: any[] }) => {
245
- counter++;
246
- probe.modules.push(footerSeg("judo", "model-state", `count=${counter}`));
247
- },
248
- ]);
249
- subscribeUiInvalidate(ctx);
250
-
251
- // Leading-edge probe.
252
- ctx.pi.events!.emit("ui:invalidate", { id: "model-state" });
253
- // Coalesced into trailing-edge probe — flush by advancing timers past
254
- // the 50ms throttle window.
255
- ctx.pi.events!.emit("ui:invalidate", { id: "model-state" });
256
- vi.advanceTimersByTime(100);
257
-
258
- const decoratorMsgs = ctx._sent.filter((m) => m.type === "ext_ui_decorator");
259
- expect(decoratorMsgs).toHaveLength(2);
260
- expect((decoratorMsgs[0].descriptor.payload as any).text).toBe("count=1");
261
- expect((decoratorMsgs[1].descriptor.payload as any).text).toBe("count=2");
262
- } finally {
263
- vi.useRealTimers();
264
- }
265
- });
266
- });
267
-
268
- describe("Per-session ui:invalidate rate cap", () => {
269
- beforeEach(() => {
270
- vi.useFakeTimers();
271
- });
272
- afterEach(() => {
273
- vi.useRealTimers();
274
- });
275
-
276
- it("coalesces a 100-invalidation burst to a small bounded number of probes with exactly one warning", () => {
277
- const ctx = createTestCtx();
278
- const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
279
- try {
280
- let probeCount = 0;
281
- ctx._listeners.set("ui:list-modules", [
282
- (probe: { modules: any[] }) => {
283
- probeCount++;
284
- probe.modules.push(footerSeg("judo", "model-state", `p${probeCount}`));
285
- },
286
- ]);
287
-
288
- subscribeUiInvalidate(ctx);
289
-
290
- // Fire 100 invalidations within ~200ms (well over the 20/sec cap).
291
- for (let i = 0; i < 100; i++) {
292
- ctx.pi.events!.emit("ui:invalidate", { id: "x" });
293
- vi.advanceTimersByTime(2);
294
- }
295
- // Allow any trailing-edge timer to fire.
296
- vi.advanceTimersByTime(2000);
297
-
298
- // Probes are bounded — at minimum 1 (the first), at most a handful, NOT 100.
299
- expect(probeCount).toBeGreaterThanOrEqual(1);
300
- expect(probeCount).toBeLessThanOrEqual(10);
301
-
302
- // Exactly one rate-cap warning per offending burst.
303
- const rateWarnings = warn.mock.calls.filter((c) => /rate|invalidat/i.test(String(c[0])));
304
- expect(rateWarnings.length).toBe(1);
305
- } finally {
306
- warn.mockRestore();
307
- }
308
- });
309
- });
@@ -1,293 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import { refreshUiModules, subscribeUiInvalidate, handleUiManagement, type UiModulesBridgeCtx } from "../ui-modules.js";
3
- import type { ExtensionUiModule } from "@blackbelt-technology/pi-dashboard-shared/types.js";
4
-
5
- /**
6
- * Minimal bus + ctx harness. The real bridge wires this up via `pi.events`
7
- * (a real `EventEmitter`); the contract this module relies on is `on` /
8
- * `emit`, so a hand-rolled bus is sufficient for tests.
9
- */
10
- function createTestCtx(sessionId = "s1") {
11
- const listeners = new Map<string, Array<(...args: any[]) => any>>();
12
- const sent: any[] = [];
13
-
14
- const ctx: UiModulesBridgeCtx & { _sent: any[]; _listeners: typeof listeners } = {
15
- pi: {
16
- events: {
17
- on: vi.fn((event: string, fn: (...args: any[]) => any) => {
18
- if (!listeners.has(event)) listeners.set(event, []);
19
- listeners.get(event)!.push(fn);
20
- }) as any,
21
- emit: vi.fn((event: string, ...args: any[]) => {
22
- const handlers = listeners.get(event) ?? [];
23
- for (const h of handlers) h(...args);
24
- }) as any,
25
- },
26
- },
27
- connection: {
28
- send: vi.fn((msg: unknown) => {
29
- sent.push(msg);
30
- }) as any,
31
- },
32
- getSessionId: () => sessionId,
33
- _sent: sent,
34
- _listeners: listeners,
35
- };
36
- return ctx;
37
- }
38
-
39
- const sampleModule = (id: string, command: string): ExtensionUiModule => ({
40
- kind: "management-modal",
41
- id,
42
- command,
43
- title: id,
44
- view: { kind: "table", dataEvent: `${id}:rows`, fields: [{ key: "id", label: "ID", kind: "text" }] },
45
- });
46
-
47
- describe("refreshUiModules", () => {
48
- it("emits ui:list-modules and forwards collected modules as ui_modules_list", () => {
49
- const ctx = createTestCtx("session-A");
50
- ctx._listeners.set("ui:list-modules", [
51
- (probe: { modules: ExtensionUiModule[] }) => {
52
- probe.modules.push(sampleModule("judo-status", "/judo:status"));
53
- probe.modules.push(sampleModule("ragger-workspaces", "/ragger:workspaces"));
54
- },
55
- ]);
56
-
57
- refreshUiModules(ctx);
58
-
59
- expect(ctx.pi.events!.emit).toHaveBeenCalledWith("ui:list-modules", expect.any(Object));
60
- expect(ctx._sent).toHaveLength(1);
61
- expect(ctx._sent[0]).toMatchObject({
62
- type: "ui_modules_list",
63
- sessionId: "session-A",
64
- modules: [
65
- expect.objectContaining({ id: "judo-status", command: "/judo:status" }),
66
- expect.objectContaining({ id: "ragger-workspaces", command: "/ragger:workspaces" }),
67
- ],
68
- });
69
- });
70
-
71
- it("forwards an empty modules list when no listeners push", () => {
72
- const ctx = createTestCtx();
73
- refreshUiModules(ctx);
74
- expect(ctx._sent).toEqual([{ type: "ui_modules_list", sessionId: "s1", modules: [] }]);
75
- });
76
-
77
- it("last-write-wins on duplicate id and warns once per collision", () => {
78
- const ctx = createTestCtx();
79
- const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
80
- try {
81
- ctx._listeners.set("ui:list-modules", [
82
- (probe: { modules: ExtensionUiModule[] }) => {
83
- // First push wins on insertion order; second push for same id replaces it.
84
- const a: ExtensionUiModule = { ...sampleModule("dup", "/a"), title: "First" };
85
- const b: ExtensionUiModule = { ...sampleModule("dup", "/b"), title: "Second" };
86
- const c: ExtensionUiModule = { ...sampleModule("dup", "/c"), title: "Third" };
87
- probe.modules.push(a, b, c);
88
- },
89
- ]);
90
-
91
- refreshUiModules(ctx);
92
-
93
- const sent = ctx._sent[0] as { modules: ExtensionUiModule[] };
94
- expect(sent.modules).toHaveLength(1);
95
- expect(sent.modules[0]).toMatchObject({ id: "dup", title: "Third", command: "/c" });
96
- // Two collisions reported, but only one warning per id.
97
- expect(warn).toHaveBeenCalledTimes(1);
98
- expect(warn.mock.calls[0]?.[0]).toMatch(/duplicate module id "dup"/);
99
- } finally {
100
- warn.mockRestore();
101
- }
102
- });
103
-
104
- it("ignores modules with missing/empty id", () => {
105
- const ctx = createTestCtx();
106
- ctx._listeners.set("ui:list-modules", [
107
- (probe: { modules: any[] }) => {
108
- probe.modules.push({ kind: "management-modal", id: "", command: "/x", title: "x", view: { kind: "table" } });
109
- probe.modules.push({ kind: "management-modal", command: "/y", title: "y", view: { kind: "table" } });
110
- probe.modules.push(sampleModule("ok", "/ok"));
111
- },
112
- ]);
113
-
114
- refreshUiModules(ctx);
115
- const sent = ctx._sent[0] as { modules: ExtensionUiModule[] };
116
- expect(sent.modules.map((m) => m.id)).toEqual(["ok"]);
117
- });
118
-
119
- it("does not throw or send when pi.events is missing", () => {
120
- const ctx = createTestCtx();
121
- ctx.pi = { events: undefined as any };
122
- expect(() => refreshUiModules(ctx)).not.toThrow();
123
- expect(ctx._sent).toHaveLength(0);
124
- });
125
-
126
- it("absorbs handler errors without breaking the bridge", () => {
127
- const ctx = createTestCtx();
128
- const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
129
- try {
130
- ctx._listeners.set("ui:list-modules", [
131
- () => {
132
- throw new Error("listener exploded");
133
- },
134
- ]);
135
- expect(() => refreshUiModules(ctx)).not.toThrow();
136
- expect(errSpy).toHaveBeenCalled();
137
- expect(ctx._sent).toHaveLength(0);
138
- } finally {
139
- errSpy.mockRestore();
140
- }
141
- });
142
- });
143
-
144
- describe("subscribeUiInvalidate", () => {
145
- it("re-runs the probe whenever ui:invalidate fires (leading + trailing throttle, see Phase 2)", () => {
146
- vi.useFakeTimers();
147
- try {
148
- const ctx = createTestCtx();
149
- ctx._listeners.set("ui:list-modules", [
150
- (probe: { modules: ExtensionUiModule[] }) => {
151
- probe.modules.push(sampleModule("a", "/a"));
152
- },
153
- ]);
154
-
155
- subscribeUiInvalidate(ctx);
156
- // First emit triggers a leading-edge probe immediately.
157
- ctx.pi.events!.emit("ui:invalidate", { id: "a" });
158
- expect(ctx._sent).toHaveLength(1);
159
- expect((ctx._sent[0] as any).type).toBe("ui_modules_list");
160
-
161
- // Second emit within the throttle window coalesces into a trailing-edge
162
- // probe; advance timers past the 50ms window to flush it.
163
- ctx.pi.events!.emit("ui:invalidate", {});
164
- vi.advanceTimersByTime(100);
165
- expect(ctx._sent).toHaveLength(2);
166
- } finally {
167
- vi.useRealTimers();
168
- }
169
- });
170
-
171
- it("is a no-op when pi.events.on is missing", () => {
172
- const ctx = createTestCtx();
173
- ctx.pi = { events: { emit: vi.fn() as any } as any };
174
- expect(() => subscribeUiInvalidate(ctx)).not.toThrow();
175
- });
176
- });
177
-
178
- describe("handleUiManagement", () => {
179
- it("re-emits the event on pi.events with action and _reply injected, and forwards synchronous data.items", () => {
180
- const ctx = createTestCtx("S");
181
- ctx._listeners.set("judo:status-rows", [
182
- (data: { action: string; items?: unknown[] }) => {
183
- expect(data.action).toBe("list");
184
- data.items = [{ id: 1 }, { id: 2 }];
185
- },
186
- ]);
187
-
188
- handleUiManagement(ctx, {
189
- type: "ui_management",
190
- sessionId: "S",
191
- action: "list",
192
- event: "judo:status-rows",
193
- });
194
-
195
- expect(ctx.pi.events!.emit).toHaveBeenCalledWith("judo:status-rows", expect.any(Object));
196
- expect(ctx._sent).toEqual([
197
- { type: "ui_data_list", sessionId: "S", event: "judo:status-rows", items: [{ id: 1 }, { id: 2 }] },
198
- ]);
199
- });
200
-
201
- it("supports async _reply path (extension calls _reply asynchronously)", () => {
202
- const ctx = createTestCtx();
203
- ctx._listeners.set("judo:rows", [
204
- (data: { _reply: (items: unknown[]) => void }) => {
205
- // Simulate async: call _reply later in this tick.
206
- setTimeout(() => data._reply([{ id: 7 }]), 0);
207
- },
208
- ]);
209
-
210
- handleUiManagement(ctx, { type: "ui_management", sessionId: "s1", action: "list", event: "judo:rows" });
211
- // Synchronous fast-path didn't fire because data.items wasn't set.
212
- expect(ctx._sent).toHaveLength(0);
213
- return new Promise<void>((resolve) => {
214
- setTimeout(() => {
215
- expect(ctx._sent).toEqual([
216
- { type: "ui_data_list", sessionId: "s1", event: "judo:rows", items: [{ id: 7 }] },
217
- ]);
218
- resolve();
219
- }, 5);
220
- });
221
- });
222
-
223
- it("does not double-send if both data.items is set and _reply is called", () => {
224
- const ctx = createTestCtx();
225
- ctx._listeners.set("e", [
226
- (data: { _reply: (items: unknown[]) => void; items?: unknown[] }) => {
227
- data._reply([1, 2]);
228
- data.items = [3, 4];
229
- },
230
- ]);
231
- handleUiManagement(ctx, { type: "ui_management", sessionId: "s1", action: "list", event: "e" });
232
- // _reply ran synchronously inside the emit; data.items fast-path is gated by `replied`.
233
- expect(ctx._sent).toHaveLength(1);
234
- expect((ctx._sent[0] as any).items).toEqual([1, 2]);
235
- });
236
-
237
- it("does NOT send a ui_data_list for fire-and-forget actions (no items, no _reply)", () => {
238
- const ctx = createTestCtx();
239
- ctx._listeners.set("judo:delete-row", [() => { /* side-effect only */ }]);
240
- handleUiManagement(ctx, {
241
- type: "ui_management",
242
- sessionId: "s1",
243
- action: "delete",
244
- event: "judo:delete-row",
245
- params: { id: 42 },
246
- });
247
- expect(ctx._sent).toHaveLength(0);
248
- });
249
-
250
- it("forwards the action and params verbatim to listeners", () => {
251
- const ctx = createTestCtx();
252
- let captured: any = null;
253
- ctx._listeners.set("e", [(data: any) => { captured = { ...data }; }]);
254
- handleUiManagement(ctx, {
255
- type: "ui_management",
256
- sessionId: "s1",
257
- action: "delete",
258
- event: "e",
259
- params: { id: 42, force: true },
260
- });
261
- expect(captured).toMatchObject({ action: "delete", id: 42, force: true });
262
- expect(typeof captured._reply).toBe("function");
263
- });
264
-
265
- it("absorbs handler errors without sending data", () => {
266
- const ctx = createTestCtx();
267
- const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
268
- try {
269
- ctx._listeners.set("explode", [() => { throw new Error("boom"); }]);
270
- expect(() => handleUiManagement(ctx, { type: "ui_management", sessionId: "s1", action: "list", event: "explode" })).not.toThrow();
271
- expect(errSpy).toHaveBeenCalled();
272
- expect(ctx._sent).toHaveLength(0);
273
- } finally {
274
- errSpy.mockRestore();
275
- }
276
- });
277
- });
278
-
279
- describe("Bridge invariants", () => {
280
- it("ui-modules.ts does not import pi.newSession / ctx.fork / ctx.switchSession", async () => {
281
- // Mirrors the contract checked by `no-session-replacement-calls.test.ts`,
282
- // but localized to the new module so a regression is caught at unit-test
283
- // granularity in addition to the global lint test.
284
- const fs = await import("node:fs/promises");
285
- const url = await import("node:url");
286
- const path = await import("node:path");
287
- const here = path.dirname(url.fileURLToPath(import.meta.url));
288
- const src = await fs.readFile(path.join(here, "..", "ui-modules.ts"), "utf8");
289
- expect(src).not.toMatch(/pi\.newSession\s*\(/);
290
- expect(src).not.toMatch(/ctx\.fork\s*\(/);
291
- expect(src).not.toMatch(/ctx\.switchSession\s*\(/);
292
- });
293
- });