@blackbelt-technology/pi-dashboard-extension 0.7.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 (265) hide show
  1. package/.pi/skills/browser/SKILL.md +84 -29
  2. package/.pi/skills/browser/UPSTREAM.md +13 -1
  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/electron.agent.md +57 -0
  6. package/.pi/skills/browser/references/own-browser.md +305 -0
  7. package/.pi/skills/browser/references/web.agent.md +323 -0
  8. package/.pi/skills/browser/scripts/check-panerelay.sh +157 -0
  9. package/.pi/skills/doctor/SKILL.md +4 -9
  10. package/.pi/skills/doctor/_lib/checks.ts +133 -54
  11. package/.pi/skills/doctor/_lib/derive-tokens.ts +5 -0
  12. package/.pi/skills/doctor/modules/apple-tools.knowledge.hash +1 -0
  13. package/.pi/skills/doctor/modules/apple-tools.md +52 -0
  14. package/.pi/skills/doctor/modules/mcp-builtin.knowledge.hash +1 -0
  15. package/.pi/skills/doctor/modules/mcp-builtin.md +61 -0
  16. package/.pi/skills/doctor/modules/oauth-redirect-base.knowledge.hash +1 -0
  17. package/.pi/skills/doctor/modules/oauth-redirect-base.md +71 -0
  18. package/.pi/skills/doctor/modules/pi-resolution.knowledge.hash +1 -1
  19. package/.pi/skills/doctor/modules/pi-resolution.md +21 -1
  20. package/.pi/skills/doctor/modules/plugins-bridges.md +14 -1
  21. package/.pi/skills/pi-dashboard/SKILL.md +10 -3
  22. package/.pi/skills/pi-dashboard/references/api-reference.agent.md +69 -0
  23. package/.pi/skills/pi-dashboard/scripts/dashboard-bus.ts +4 -4
  24. package/.pi/skills/project-init/SKILL.md +41 -34
  25. package/.pi/skills/project-init/profiles/coding/AGENTS.md.tmpl +0 -23
  26. package/.pi/skills/project-init/profiles/docs/profile.json +1 -1
  27. package/README.md +19 -0
  28. package/agents/DoxTriage.md +80 -0
  29. package/package.json +30 -16
  30. package/src/ask-user-tool.ts +4 -0
  31. package/src/auto-session-namer.ts +486 -70
  32. package/src/autostart-guard.ts +99 -0
  33. package/src/autostart-lock.ts +258 -0
  34. package/src/bridge-activation.ts +26 -0
  35. package/src/bridge-context.ts +106 -23
  36. package/src/bridge-default-model-gate.ts +38 -0
  37. package/src/bridge-polling.ts +148 -0
  38. package/src/bridge-ticket-client.ts +105 -0
  39. package/src/bridge.ts +1760 -350
  40. package/src/canvas-tool.ts +5 -0
  41. package/src/command-handler.ts +392 -71
  42. package/src/connect-target.ts +130 -0
  43. package/src/connection.ts +846 -17
  44. package/src/custom-entry-forward.ts +92 -0
  45. package/src/endpoint-resolution.ts +253 -0
  46. package/src/event-forwarder.ts +42 -0
  47. package/src/extension-identity.ts +59 -0
  48. package/src/flow-event-wiring.ts +125 -3
  49. package/src/followup-buffer.ts +217 -0
  50. package/src/git-dir-watcher.ts +79 -0
  51. package/src/git-poll.ts +45 -12
  52. package/src/git-probe-scheduler.ts +119 -0
  53. package/src/git-tracker.ts +284 -0
  54. package/src/instance-verification.ts +156 -0
  55. package/src/local-token-header.ts +44 -0
  56. package/src/mcp-token-delivery.ts +147 -0
  57. package/src/message-update-coalescer.ts +340 -0
  58. package/src/model-refresh.ts +95 -0
  59. package/src/model-tracker.ts +118 -35
  60. package/src/notify-proxy.ts +36 -0
  61. package/src/path-gate/decide.ts +149 -0
  62. package/src/path-gate/grant-cache.ts +71 -0
  63. package/src/path-gate/grant-link.ts +108 -0
  64. package/src/path-gate/handler.ts +307 -0
  65. package/src/path-gate/index.ts +155 -0
  66. package/src/path-gate/resolve.ts +126 -0
  67. package/src/path-gate/roots.ts +137 -0
  68. package/src/path-gate/suppression.ts +27 -0
  69. package/src/pending-prompt-emitter.ts +59 -0
  70. package/src/pi-env.d.ts +6 -10
  71. package/src/pi-retry-settings.ts +91 -0
  72. package/src/plugin-request-client.ts +114 -0
  73. package/src/poll-cost.ts +40 -0
  74. package/src/pr-status.ts +338 -0
  75. package/src/process-metrics.ts +77 -1
  76. package/src/process-scan-scheduler.ts +137 -0
  77. package/src/process-scanner.ts +226 -247
  78. package/src/project-init/dox-kb-config.ts +3 -0
  79. package/src/project-init/scaffold.ts +1 -4
  80. package/src/project-init/seed-doctrine.ts +23 -60
  81. package/src/prompt-bus.ts +13 -0
  82. package/src/provider-register.ts +92 -21
  83. package/src/remote-registration-gate.ts +102 -0
  84. package/src/retry-tracker.ts +258 -86
  85. package/src/role-manager.ts +38 -91
  86. package/src/role-model-tools.ts +44 -3
  87. package/src/server-auto-start.ts +331 -20
  88. package/src/server-launcher.ts +70 -34
  89. package/src/server-pin-store.ts +92 -0
  90. package/src/session-move.ts +275 -0
  91. package/src/session-sync.ts +75 -20
  92. package/src/slash-dispatch.ts +66 -81
  93. package/src/subagent-fanout-admission.ts +234 -0
  94. package/src/subagent-forward-sites.ts +69 -0
  95. package/src/subagent-frame-buffer.ts +24 -3
  96. package/src/subagent-frame-strip.ts +109 -0
  97. package/src/subagent-saturation.ts +196 -0
  98. package/src/subagent-tick-throttle.ts +250 -0
  99. package/src/terminal-reload.ts +298 -0
  100. package/src/transcript-backfill.ts +151 -0
  101. package/src/transport-diagnostics.ts +76 -0
  102. package/src/tui-prompt-adapter.ts +13 -1
  103. package/src/turn-actionability.ts +20 -0
  104. package/src/ui-stale-guard.ts +58 -0
  105. package/src/usage-drain.ts +167 -0
  106. package/src/vcs-info.ts +261 -63
  107. package/.pi/skills/doctor/AGENTS.md +0 -27
  108. package/.pi/skills/project-init/dox-doctrine.md +0 -104
  109. package/src/AGENTS.md +0 -57
  110. package/src/__tests__/abort-latch.test.ts +0 -97
  111. package/src/__tests__/agent-settled.test.ts +0 -82
  112. package/src/__tests__/artifact-roots.test.ts +0 -83
  113. package/src/__tests__/ask-user-attachments.test.ts +0 -106
  114. package/src/__tests__/ask-user-schema-discriminator.test.ts +0 -141
  115. package/src/__tests__/ask-user-tool.test.ts +0 -571
  116. package/src/__tests__/auto-session-namer.test.ts +0 -339
  117. package/src/__tests__/bridge-default-model-apply.test.ts +0 -242
  118. package/src/__tests__/bridge-default-model-gate.test.ts +0 -50
  119. package/src/__tests__/bridge-entry-id-pi-070.test.ts +0 -174
  120. package/src/__tests__/bridge-followup-chat-order.test.ts +0 -215
  121. package/src/__tests__/bridge-followup-multi-entry.test.ts +0 -202
  122. package/src/__tests__/bridge-followup-mutation.test.ts +0 -217
  123. package/src/__tests__/bridge-followup-queue-drain.test.ts +0 -266
  124. package/src/__tests__/bridge-hasui-flip.test.ts +0 -109
  125. package/src/__tests__/bridge-no-queue-mutation.test.ts +0 -112
  126. package/src/__tests__/bridge-plugin-emit-event.test.ts +0 -44
  127. package/src/__tests__/bridge-queue-update-forward.test.ts +0 -77
  128. package/src/__tests__/bridge-resume-disconnect.test.ts +0 -333
  129. package/src/__tests__/bridge-shadow-queue-gate.test.ts +0 -299
  130. package/src/__tests__/bridge-shutdown-reset.test.ts +0 -159
  131. package/src/__tests__/bridge-slash-command-routing.test.ts +0 -458
  132. package/src/__tests__/bridge-stop-after-turn.test.ts +0 -72
  133. package/src/__tests__/bridge-system-followup.test.ts +0 -163
  134. package/src/__tests__/bridge-thinking-level-select.test.ts +0 -68
  135. package/src/__tests__/browser-skill-registered.test.ts +0 -84
  136. package/src/__tests__/build-provider-catalogue.test.ts +0 -210
  137. package/src/__tests__/command-handler.test.ts +0 -1180
  138. package/src/__tests__/commit-draft.test.ts +0 -100
  139. package/src/__tests__/connection-dropped-frames.test.ts +0 -78
  140. package/src/__tests__/connection-suppress-auto-start.test.ts +0 -97
  141. package/src/__tests__/connection.test.ts +0 -344
  142. package/src/__tests__/credentials-updated.test.ts +0 -26
  143. package/src/__tests__/custom-provider-apikey-roundtrip.test.ts +0 -128
  144. package/src/__tests__/cwd-missing-probe.test.ts +0 -82
  145. package/src/__tests__/dashboard-commands-shipped.test.ts +0 -53
  146. package/src/__tests__/dashboard-context-injector.test.ts +0 -190
  147. package/src/__tests__/dashboard-default-adapter.test.ts +0 -77
  148. package/src/__tests__/dev-build.test.ts +0 -79
  149. package/src/__tests__/doctor/checks.test.ts +0 -121
  150. package/src/__tests__/doctor/modules.test.ts +0 -64
  151. package/src/__tests__/doctor/provenance-hash.test.ts +0 -94
  152. package/src/__tests__/doctor/router.test.ts +0 -143
  153. package/src/__tests__/empty-actionable-guard-config.test.ts +0 -32
  154. package/src/__tests__/empty-actionable-guard.test.ts +0 -73
  155. package/src/__tests__/enrich-model-metadata.test.ts +0 -222
  156. package/src/__tests__/event-forwarder.test.ts +0 -119
  157. package/src/__tests__/extension-slash-command-detection.test.ts +0 -143
  158. package/src/__tests__/filter-enabled-models.test.ts +0 -151
  159. package/src/__tests__/fixtures/turn-actionability-fixtures.ts +0 -69
  160. package/src/__tests__/fork-entryid-timing.test.ts +0 -88
  161. package/src/__tests__/git-info-status.test.ts +0 -73
  162. package/src/__tests__/git-link-builder.test.ts +0 -102
  163. package/src/__tests__/git-poll.test.ts +0 -69
  164. package/src/__tests__/markdown-image-inliner.test.ts +0 -392
  165. package/src/__tests__/model-resolve.test.ts +0 -379
  166. package/src/__tests__/multiselect-dashboard-routing.test.ts +0 -203
  167. package/src/__tests__/multiselect-list.test.ts +0 -137
  168. package/src/__tests__/multiselect-polyfill.test.ts +0 -92
  169. package/src/__tests__/no-session-replacement-calls.test.ts +0 -99
  170. package/src/__tests__/no-tui-multiselect-arm-regression.test.ts +0 -81
  171. package/src/__tests__/openspec-activity-detector.test.ts +0 -337
  172. package/src/__tests__/openspec-cli-shim.test.ts +0 -145
  173. package/src/__tests__/openspec-poller.test.ts +0 -124
  174. package/src/__tests__/pi-version-tracker.test.ts +0 -109
  175. package/src/__tests__/process-metrics.test.ts +0 -47
  176. package/src/__tests__/process-scanner-kill.test.ts +0 -61
  177. package/src/__tests__/process-scanner.test.ts +0 -292
  178. package/src/__tests__/project-init-detect-stack.test.ts +0 -61
  179. package/src/__tests__/project-init-dox-kb-config.test.ts +0 -53
  180. package/src/__tests__/project-init-profiles.test.ts +0 -84
  181. package/src/__tests__/project-init-scaffold.test.ts +0 -139
  182. package/src/__tests__/project-init-seed-doctrine.test.ts +0 -100
  183. package/src/__tests__/project-trust.test.ts +0 -92
  184. package/src/__tests__/prompt-bus-wiring.test.ts +0 -791
  185. package/src/__tests__/prompt-bus.test.ts +0 -513
  186. package/src/__tests__/prompt-expander.test.ts +0 -398
  187. package/src/__tests__/provider-register-native-models.test.ts +0 -182
  188. package/src/__tests__/provider-register-reload.test.ts +0 -498
  189. package/src/__tests__/provider-register-thinking-levels.test.ts +0 -104
  190. package/src/__tests__/retry-tracker.test.ts +0 -152
  191. package/src/__tests__/role-manager.test.ts +0 -585
  192. package/src/__tests__/role-model-tools-registry-readiness.test.ts +0 -114
  193. package/src/__tests__/role-model-tools.test.ts +0 -229
  194. package/src/__tests__/search-files-completeness.test.ts +0 -111
  195. package/src/__tests__/search-files-ranking.test.ts +0 -168
  196. package/src/__tests__/server-auto-start.test.ts +0 -375
  197. package/src/__tests__/server-launcher-launch.test.ts +0 -96
  198. package/src/__tests__/server-launcher.test.ts +0 -101
  199. package/src/__tests__/server-probe.test.ts +0 -25
  200. package/src/__tests__/session-switch.test.ts +0 -139
  201. package/src/__tests__/session-sync.test.ts +0 -243
  202. package/src/__tests__/single-derivation-guard.test.ts +0 -39
  203. package/src/__tests__/source-detector.test.ts +0 -88
  204. package/src/__tests__/stats-extractor.test.ts +0 -92
  205. package/src/__tests__/subagent-frame-buffer.test.ts +0 -239
  206. package/src/__tests__/tool-result-image-inliner.test.ts +0 -206
  207. package/src/__tests__/tui-prompt-adapter.test.ts +0 -213
  208. package/src/__tests__/turn-actionability.test.ts +0 -86
  209. package/src/__tests__/ui-decorators.test.ts +0 -309
  210. package/src/__tests__/ui-modules.test.ts +0 -293
  211. package/src/__tests__/vcs-info.test.ts +0 -265
  212. package/src/__tests__/visibility-intent.test.ts +0 -43
  213. package/src/__tests__/watchdog.test.ts +0 -161
  214. package/src/abort-latch.ts.AGENTS.md +0 -3
  215. package/src/agent-settled.ts +0 -72
  216. package/src/agent-settled.ts.AGENTS.md +0 -3
  217. package/src/artifact-roots.ts.AGENTS.md +0 -3
  218. package/src/ask-user-attachments.ts.AGENTS.md +0 -3
  219. package/src/ask-user-tool.ts.AGENTS.md +0 -3
  220. package/src/auto-session-namer.ts.AGENTS.md +0 -3
  221. package/src/bridge-context.ts.AGENTS.md +0 -3
  222. package/src/bridge-default-model-gate.ts.AGENTS.md +0 -3
  223. package/src/bridge.ts.AGENTS.md +0 -3
  224. package/src/command-handler.ts.AGENTS.md +0 -3
  225. package/src/commit-draft-agent.ts.AGENTS.md +0 -3
  226. package/src/commit-draft.ts.AGENTS.md +0 -3
  227. package/src/connection.ts.AGENTS.md +0 -3
  228. package/src/dashboard-context-injector.ts.AGENTS.md +0 -3
  229. package/src/dashboard-default-adapter.ts.AGENTS.md +0 -3
  230. package/src/dev-build.ts.AGENTS.md +0 -3
  231. package/src/empty-actionable-guard-config.ts.AGENTS.md +0 -3
  232. package/src/empty-actionable-guard.ts.AGENTS.md +0 -3
  233. package/src/event-forwarder.ts.AGENTS.md +0 -3
  234. package/src/flow-event-wiring.ts.AGENTS.md +0 -3
  235. package/src/git-link-builder.ts.AGENTS.md +0 -3
  236. package/src/git-poll.ts.AGENTS.md +0 -3
  237. package/src/hasui-flip.ts.AGENTS.md +0 -3
  238. package/src/markdown-image-inliner.ts.AGENTS.md +0 -3
  239. package/src/model-tracker.ts.AGENTS.md +0 -3
  240. package/src/multiselect-decode.ts.AGENTS.md +0 -3
  241. package/src/multiselect-list.ts.AGENTS.md +0 -3
  242. package/src/multiselect-polyfill.ts.AGENTS.md +0 -3
  243. package/src/openspec-cli-shim.ts.AGENTS.md +0 -7
  244. package/src/process-metrics.ts.AGENTS.md +0 -3
  245. package/src/process-scanner.ts.AGENTS.md +0 -3
  246. package/src/project-init/AGENTS.md +0 -12
  247. package/src/project-trust.ts.AGENTS.md +0 -3
  248. package/src/prompt-bus.ts.AGENTS.md +0 -3
  249. package/src/prompt-expander.ts.AGENTS.md +0 -3
  250. package/src/provider-register.ts.AGENTS.md +0 -3
  251. package/src/retry-tracker.ts.AGENTS.md +0 -3
  252. package/src/role-manager.ts.AGENTS.md +0 -3
  253. package/src/role-model-tools.ts.AGENTS.md +0 -3
  254. package/src/server-auto-start.ts.AGENTS.md +0 -3
  255. package/src/server-launcher.ts.AGENTS.md +0 -3
  256. package/src/session-sync.ts.AGENTS.md +0 -3
  257. package/src/slash-dispatch.ts.AGENTS.md +0 -3
  258. package/src/source-detector.ts.AGENTS.md +0 -3
  259. package/src/subagent-frame-buffer.ts.AGENTS.md +0 -3
  260. package/src/tool-result-image-inliner.ts.AGENTS.md +0 -3
  261. package/src/tui-prompt-adapter.ts.AGENTS.md +0 -3
  262. package/src/turn-actionability.ts.AGENTS.md +0 -3
  263. package/src/ui-modules.ts.AGENTS.md +0 -3
  264. package/src/vcs-info.ts.AGENTS.md +0 -3
  265. package/src/visibility-intent.ts.AGENTS.md +0 -3
@@ -1,339 +0,0 @@
1
- /**
2
- * Automatic session topic-naming: pure helpers + the state-machine factory.
3
- *
4
- * Covers the eligibility gate, pre-filter skip cases, `@fast` resolution
5
- * (hard-error branch), the transcript-window bound, title parsing
6
- * (valid / NULL / empty / too-long), the in-process model call (fake registry
7
- * + fake streamSimple), the OAuth-only hard-error, and the provenance state
8
- * machine (auto → external change → user; one-shot error).
9
- *
10
- * See change: add-auto-session-naming.
11
- */
12
- import { describe, expect, it, vi } from "vitest";
13
- import {
14
- buildTranscriptWindow,
15
- classifyNameChange,
16
- createAutoNamer,
17
- generateTitle,
18
- isEligible,
19
- type NamerRegistry,
20
- parseTitle,
21
- sanitizeSessionName,
22
- type StreamSimpleFn,
23
- shouldSkipByPrefilter,
24
- } from "../auto-session-namer.js";
25
-
26
- describe("shouldSkipByPrefilter", () => {
27
- it.each([
28
- ["hi"],
29
- ["hello"],
30
- ["thanks"],
31
- ["ok"],
32
- ["test"],
33
- [" hey "],
34
- ["/commit"],
35
- ["/status"],
36
- ["short"], // < 15 chars
37
- ])("skips %j without a model call", (msg) => {
38
- expect(shouldSkipByPrefilter(msg)).toBe(true);
39
- });
40
-
41
- it("passes a substantive first message", () => {
42
- expect(shouldSkipByPrefilter("Refactor the auth middleware to support tokens")).toBe(false);
43
- });
44
-
45
- it("skips undefined / empty", () => {
46
- expect(shouldSkipByPrefilter(undefined)).toBe(true);
47
- expect(shouldSkipByPrefilter("")).toBe(true);
48
- });
49
- });
50
-
51
- describe("parseTitle", () => {
52
- it("accepts a valid title", () => {
53
- expect(parseTitle("Auth Token Refactor")).toEqual({ title: "Auth Token Refactor", wait: false });
54
- });
55
- it("trims surrounding whitespace", () => {
56
- expect(parseTitle(" Auth Token Refactor ")).toEqual({ title: "Auth Token Refactor", wait: false });
57
- });
58
- it("waits on the NULL sentinel (any case)", () => {
59
- expect(parseTitle("NULL").wait).toBe(true);
60
- expect(parseTitle("null").wait).toBe(true);
61
- });
62
- it("waits on empty", () => {
63
- expect(parseTitle("").wait).toBe(true);
64
- expect(parseTitle(" ").wait).toBe(true);
65
- expect(parseTitle(undefined).wait).toBe(true);
66
- });
67
- it("waits on an over-long title", () => {
68
- expect(parseTitle("This Title Is Far Too Long To Be A Reasonable Session Name Indeed").wait).toBe(true);
69
- });
70
- it("waits on too many words", () => {
71
- expect(parseTitle("One Two Three Four Five Six Seven").wait).toBe(true);
72
- });
73
- });
74
-
75
- describe("buildTranscriptWindow", () => {
76
- it("joins user + assistant", () => {
77
- expect(buildTranscriptWindow("do the thing", "sure, done")).toBe("do the thing\n\nsure, done");
78
- });
79
- it("omits the separator when there is no assistant reply", () => {
80
- expect(buildTranscriptWindow("do the thing", undefined)).toBe("do the thing");
81
- });
82
- it("bounds the window size", () => {
83
- const huge = "x".repeat(10_000);
84
- const out = buildTranscriptWindow(huge, huge);
85
- // each side capped at 2000 + the 2-char separator
86
- expect(out.length).toBeLessThanOrEqual(2000 + 2 + 2000);
87
- });
88
- });
89
-
90
- describe("isEligible", () => {
91
- it("true only when enabled, not user-named, and no auto-name yet", () => {
92
- expect(isEligible({ autoNameSessions: true, nameSource: undefined, hasAutoName: false })).toBe(true);
93
- });
94
- it("false when disabled", () => {
95
- expect(isEligible({ autoNameSessions: false, nameSource: undefined, hasAutoName: false })).toBe(false);
96
- });
97
- it("false when user-named", () => {
98
- expect(isEligible({ autoNameSessions: true, nameSource: "user", hasAutoName: false })).toBe(false);
99
- });
100
- it("false when already auto-named", () => {
101
- expect(isEligible({ autoNameSessions: true, nameSource: "auto", hasAutoName: true })).toBe(false);
102
- });
103
- });
104
-
105
- describe("classifyNameChange", () => {
106
- it("self when equal to the last self-applied title", () => {
107
- expect(classifyNameChange("Auth Refactor", "Auth Refactor")).toBe("self");
108
- });
109
- it("external when different or never self-applied", () => {
110
- expect(classifyNameChange("Hand Typed", "Auth Refactor")).toBe("external");
111
- expect(classifyNameChange("Hand Typed", undefined)).toBe("external");
112
- });
113
- // F5: a self-applied title with an internal newline still matches the
114
- // newline-collapsed name pi carries in session_info_changed.
115
- it("F5: self when a newline-bearing self-title matches the sanitized event name", () => {
116
- expect(classifyNameChange("Foo Bar", "Foo\nBar")).toBe("self");
117
- expect(classifyNameChange("Foo Bar", "Foo\r\nBar")).toBe("self");
118
- expect(classifyNameChange(" Foo Bar ", "Foo\nBar")).toBe("self");
119
- });
120
- // F4: a genuine external rename is still external.
121
- it("F4: external for a hand-typed rename that is not the self title", () => {
122
- expect(classifyNameChange("Bar", "Foo")).toBe("external");
123
- });
124
- });
125
-
126
- describe("sanitizeSessionName", () => {
127
- it("collapses internal newlines to single spaces and trims", () => {
128
- expect(sanitizeSessionName("Foo\nBar")).toBe("Foo Bar");
129
- expect(sanitizeSessionName("Foo\r\n\nBar")).toBe("Foo Bar");
130
- expect(sanitizeSessionName(" Foo Bar ")).toBe("Foo Bar");
131
- });
132
- });
133
-
134
- // ── generateTitle: in-process model call ─────────────────────────────────
135
- function fakeStream(events: any[]): StreamSimpleFn {
136
- return () => (async function* () {
137
- for (const e of events) yield e;
138
- })();
139
- }
140
-
141
- const okRegistry: NamerRegistry = {
142
- find: () => ({ provider: "anthropic", id: "claude-haiku" }),
143
- getApiKeyAndHeaders: async () => ({ apiKey: "sk-test", headers: {} }),
144
- };
145
-
146
- describe("generateTitle", () => {
147
- it("concatenates text_delta events", async () => {
148
- const res = await generateTitle({
149
- registry: okRegistry,
150
- streamSimple: fakeStream([
151
- { type: "text_delta", delta: "Auth " },
152
- { type: "text_delta", delta: "Refactor" },
153
- { type: "done", message: { content: [] } },
154
- ]),
155
- modelRef: "anthropic/claude-haiku",
156
- transcript: "refactor auth",
157
- });
158
- expect(res).toEqual({ ok: true, text: "Auth Refactor" });
159
- });
160
-
161
- it("falls back to the final message when no deltas arrive", async () => {
162
- const res = await generateTitle({
163
- registry: okRegistry,
164
- streamSimple: fakeStream([
165
- { type: "done", message: { content: [{ type: "text", text: "Cold Start" }] } },
166
- ]),
167
- modelRef: "anthropic/claude-haiku",
168
- transcript: "x",
169
- });
170
- expect(res).toEqual({ ok: true, text: "Cold Start" });
171
- });
172
-
173
- it("hard-errors on an unknown model (not a throw)", async () => {
174
- const res = await generateTitle({
175
- registry: { find: () => undefined, getApiKeyAndHeaders: async () => ({ apiKey: "k" }) },
176
- streamSimple: fakeStream([]),
177
- modelRef: "nope/missing",
178
- transcript: "x",
179
- });
180
- expect(res).toEqual({ ok: false, hardError: true, reason: expect.stringContaining("not found") });
181
- });
182
-
183
- it("hard-errors when credential resolution throws (OAuth-only, unauthable)", async () => {
184
- const res = await generateTitle({
185
- registry: {
186
- find: () => ({}),
187
- getApiKeyAndHeaders: async () => {
188
- throw new Error("oauth required");
189
- },
190
- },
191
- streamSimple: fakeStream([]),
192
- modelRef: "anthropic/claude-oauth",
193
- transcript: "x",
194
- });
195
- expect(res.ok).toBe(false);
196
- expect(res).toMatchObject({ hardError: true });
197
- });
198
-
199
- it("hard-errors when no usable credentials are returned", async () => {
200
- const res = await generateTitle({
201
- registry: { find: () => ({}), getApiKeyAndHeaders: async () => ({}) },
202
- streamSimple: fakeStream([]),
203
- modelRef: "anthropic/claude-oauth",
204
- transcript: "x",
205
- });
206
- expect(res).toMatchObject({ ok: false, hardError: true });
207
- });
208
-
209
- it("soft-errors (retry) on a stream error event", async () => {
210
- const res = await generateTitle({
211
- registry: okRegistry,
212
- streamSimple: fakeStream([{ type: "error", errorMessage: "rate limited" }]),
213
- modelRef: "anthropic/claude-haiku",
214
- transcript: "x",
215
- });
216
- expect(res).toMatchObject({ ok: false, hardError: false, reason: "rate limited" });
217
- });
218
-
219
- it("soft-errors (retry) when streamSimple throws", async () => {
220
- const res = await generateTitle({
221
- registry: okRegistry,
222
- streamSimple: () => {
223
- throw new Error("socket hang up");
224
- },
225
- modelRef: "anthropic/claude-haiku",
226
- transcript: "x",
227
- });
228
- expect(res).toMatchObject({ ok: false, hardError: false });
229
- });
230
- });
231
-
232
- // ── createAutoNamer: state machine ───────────────────────────────────────
233
- function makeHooks(overrides: Partial<Parameters<typeof createAutoNamer>[0]> = {}) {
234
- return {
235
- getAutoNameSessions: () => true,
236
- resolveFastModel: () => ({ literal: "anthropic/claude-haiku" }),
237
- getRegistry: () => okRegistry,
238
- loadStreamSimple: async () => fakeStream([{ type: "text_delta", delta: "Auth Refactor" }, { type: "done", message: { content: [] } }]),
239
- getTranscript: () => ({ firstUserMsg: "Refactor the auth middleware for tokens", firstAssistantReply: "on it" }),
240
- applyName: vi.fn(),
241
- reportUserRename: vi.fn(),
242
- emitError: vi.fn(),
243
- ...overrides,
244
- };
245
- }
246
-
247
- describe("createAutoNamer", () => {
248
- it("names an eligible session once, then stops", async () => {
249
- const hooks = makeHooks();
250
- const namer = createAutoNamer(hooks);
251
- await namer.maybeName();
252
- expect(hooks.applyName).toHaveBeenCalledWith("Auth Refactor");
253
- expect(namer._state()).toMatchObject({ hasAutoName: true, nameSource: "auto" });
254
-
255
- // A second terminal turn must NOT attempt again.
256
- (hooks.applyName as any).mockClear();
257
- await namer.maybeName();
258
- expect(hooks.applyName).not.toHaveBeenCalled();
259
- });
260
-
261
- it("does nothing when the feature is disabled", async () => {
262
- const hooks = makeHooks({ getAutoNameSessions: () => false });
263
- const namer = createAutoNamer(hooks);
264
- await namer.maybeName();
265
- expect(hooks.applyName).not.toHaveBeenCalled();
266
- });
267
-
268
- it("skips the model call on a greeting-only opener", async () => {
269
- const loadStreamSimple = vi.fn(async () => fakeStream([]));
270
- const hooks = makeHooks({ getTranscript: () => ({ firstUserMsg: "hi", firstAssistantReply: "hello" }), loadStreamSimple });
271
- const namer = createAutoNamer(hooks);
272
- await namer.maybeName();
273
- expect(loadStreamSimple).not.toHaveBeenCalled();
274
- expect(hooks.applyName).not.toHaveBeenCalled();
275
- });
276
-
277
- it("emits one auto_name_error and hard-stops when @fast is unconfigured", async () => {
278
- const hooks = makeHooks({ resolveFastModel: () => ({ reason: "role 'fast' not configured yet" }) });
279
- const namer = createAutoNamer(hooks);
280
- await namer.maybeName();
281
- await namer.maybeName(); // must not emit twice
282
- expect(hooks.emitError).toHaveBeenCalledTimes(1);
283
- expect(hooks.applyName).not.toHaveBeenCalled();
284
- expect(namer._state().hardStopped).toBe(true);
285
- });
286
-
287
- it("waits (no name) when the model returns NULL", async () => {
288
- const hooks = makeHooks({
289
- loadStreamSimple: async () => fakeStream([{ type: "text_delta", delta: "NULL" }, { type: "done", message: { content: [] } }]),
290
- });
291
- const namer = createAutoNamer(hooks);
292
- await namer.maybeName();
293
- expect(hooks.applyName).not.toHaveBeenCalled();
294
- expect(namer._state()).toMatchObject({ hasAutoName: false, hardStopped: false });
295
- });
296
-
297
- it("escalates auto → user on an external rename", async () => {
298
- const hooks = makeHooks();
299
- const namer = createAutoNamer(hooks);
300
- await namer.maybeName();
301
- expect(namer._state().nameSource).toBe("auto");
302
-
303
- // The bridge observing its OWN applied name is a no-op.
304
- namer.onObservedName("Auth Refactor");
305
- expect(hooks.reportUserRename).not.toHaveBeenCalled();
306
- expect(namer._state().nameSource).toBe("auto");
307
-
308
- // A different observed name = external rename → permanent user lockout.
309
- namer.onObservedName("Hand Typed Name");
310
- expect(hooks.reportUserRename).toHaveBeenCalledWith("Hand Typed Name");
311
- expect(namer._state()).toMatchObject({ nameSource: "user", hardStopped: true });
312
- });
313
-
314
- it("F5: a newline-bearing self-name echoing back (sanitized) does NOT lock out", async () => {
315
- // The bridge self-applies "Foo\nBar"; pi sanitizes + broadcasts "Foo Bar"
316
- // via session_info_changed. The self-filter must classify it self.
317
- const hooks = makeHooks({
318
- loadStreamSimple: async () =>
319
- fakeStream([{ type: "text_delta", delta: "Foo\nBar" }, { type: "done", message: { content: [] } }]),
320
- });
321
- const namer = createAutoNamer(hooks);
322
- await namer.maybeName();
323
- expect(hooks.applyName).toHaveBeenCalledWith("Foo\nBar");
324
- expect(namer._state().nameSource).toBe("auto");
325
-
326
- // The sanitized echo comes back through session_info_changed → self, no push.
327
- namer.onObservedName("Foo Bar");
328
- expect(hooks.reportUserRename).not.toHaveBeenCalled();
329
- expect(namer._state()).toMatchObject({ nameSource: "auto", hardStopped: false });
330
- });
331
-
332
- it("seeds a user lockout restored from meta", async () => {
333
- const hooks = makeHooks();
334
- const namer = createAutoNamer(hooks);
335
- namer.seed("user");
336
- await namer.maybeName();
337
- expect(hooks.applyName).not.toHaveBeenCalled();
338
- });
339
- });
@@ -1,242 +0,0 @@
1
- /**
2
- * Tests for the bridge's default-model application at session_start.
3
- *
4
- * Pure-model mirror of bridge.ts ~L1632-L1647. If production drifts from
5
- * this shape, this test drifts in lockstep.
6
- *
7
- * Covers the input-derivation expression (the bug surface fixed by this
8
- * change) PLUS the four spawn paths (new / resume / fork / reload) PLUS the
9
- * older-pi fallback (`buildSessionContext` undefined) PLUS the
10
- * default-not-configured no-op.
11
- *
12
- * Spec: openspec/specs/bridge-extension/spec.md — requirement
13
- * "Default model applied only to brand-new sessions".
14
- *
15
- * See changes: fix-resume-keeps-session-model (original gate),
16
- * fix-default-model-new-session-entry-count (signal correction).
17
- */
18
- import { describe, it, expect, vi } from "vitest";
19
- import { shouldApplyDefaultModel } from "../bridge-default-model-gate.js";
20
-
21
- interface BuildSessionContextResult {
22
- messages: unknown[];
23
- }
24
-
25
- interface FakeSessionManager {
26
- buildSessionContext?: () => BuildSessionContextResult;
27
- getEntries?: () => unknown[];
28
- }
29
-
30
- interface FakeCtx {
31
- sessionManager: FakeSessionManager;
32
- }
33
-
34
- interface FakePiEvent {
35
- reason?: string;
36
- }
37
-
38
- interface RunArgs {
39
- ctx: FakeCtx;
40
- event: FakePiEvent;
41
- hasModelRegistry: boolean;
42
- defaultModel: string; // "" === unset
43
- }
44
-
45
- /**
46
- * Pure-model mirror of bridge.ts session_start default-model branch.
47
- * Production reference (bridge.ts ~L1632-L1647):
48
- *
49
- * const entryCount = ctx.sessionManager.buildSessionContext?.()?.messages?.length ?? 0;
50
- * const freshConfig = loadConfig();
51
- * if (shouldApplyDefaultModel({
52
- * reason: _event?.reason,
53
- * entryCount,
54
- * hasModelRegistry: Boolean(cachedModelRegistry),
55
- * hasDefaultModel: Boolean(freshConfig.defaultModel),
56
- * })) {
57
- * pendingDefaultModel = applyDefaultModel();
58
- * }
59
- */
60
- function runSessionStartDefaultModelBranch(args: RunArgs): { applied: boolean } {
61
- const entryCount = args.ctx.sessionManager.buildSessionContext?.()?.messages?.length ?? 0;
62
- const apply = shouldApplyDefaultModel({
63
- reason: args.event.reason,
64
- entryCount,
65
- hasModelRegistry: args.hasModelRegistry,
66
- hasDefaultModel: Boolean(args.defaultModel),
67
- });
68
- return { applied: apply };
69
- }
70
-
71
- /**
72
- * Build a fake `ctx.sessionManager` whose `getEntries()` returns N entries
73
- * but whose `buildSessionContext().messages` returns M messages. Mirrors
74
- * pi's behaviour where setup entries (model_change + thinking_level_change)
75
- * inflate getEntries() but never appear in messages.
76
- */
77
- function makeCtx(opts: { entriesCount: number; messageCount: number }): FakeCtx {
78
- return {
79
- sessionManager: {
80
- getEntries: () => Array.from({ length: opts.entriesCount }, (_, i) => ({ idx: i })),
81
- buildSessionContext: () => ({
82
- messages: Array.from({ length: opts.messageCount }, (_, i) => ({ idx: i })),
83
- }),
84
- },
85
- };
86
- }
87
-
88
- describe("bridge default-model apply at session_start", () => {
89
- // ── New session ────────────────────────────────────────────────────────
90
- it("applies default model for a brand-new session with pre-emit setup entries", () => {
91
- // Brand-new session: pi auto-appended model_change + thinking_level_change
92
- // BEFORE emitting session_start, so getEntries() === 2 but messages === 0.
93
- // THIS is the regression case: the previous gate used getEntries().length
94
- // and silently skipped applying the default.
95
- const ctx = makeCtx({ entriesCount: 2, messageCount: 0 });
96
- const result = runSessionStartDefaultModelBranch({
97
- ctx,
98
- event: { reason: "startup" },
99
- hasModelRegistry: true,
100
- defaultModel: "anthropic/claude-sonnet-4-5",
101
- });
102
- expect(result.applied).toBe(true);
103
- });
104
-
105
- it("applies default model when getEntries returns 0 (synthetic minimal session)", () => {
106
- // Defensive: ensure the predicate is symmetric when both signals are 0.
107
- const ctx = makeCtx({ entriesCount: 0, messageCount: 0 });
108
- const result = runSessionStartDefaultModelBranch({
109
- ctx,
110
- event: { reason: "startup" },
111
- hasModelRegistry: true,
112
- defaultModel: "anthropic/claude-sonnet-4-5",
113
- });
114
- expect(result.applied).toBe(true);
115
- });
116
-
117
- // ── Resumed session ────────────────────────────────────────────────────
118
- it("does NOT apply default model for a resumed session (messages > 0)", () => {
119
- // Resume via --session: persisted entries loaded, including prior messages.
120
- const ctx = makeCtx({ entriesCount: 50, messageCount: 30 });
121
- const result = runSessionStartDefaultModelBranch({
122
- ctx,
123
- event: { reason: "startup" },
124
- hasModelRegistry: true,
125
- defaultModel: "anthropic/claude-sonnet-4-5",
126
- });
127
- expect(result.applied).toBe(false);
128
- });
129
-
130
- // ── Forked session ─────────────────────────────────────────────────────
131
- it("does NOT apply default model for a forked session (parent messages copied)", () => {
132
- // Fork via --fork: SessionManager.forkFrom copies parent entries including messages.
133
- const ctx = makeCtx({ entriesCount: 80, messageCount: 40 });
134
- const result = runSessionStartDefaultModelBranch({
135
- ctx,
136
- event: { reason: "startup" },
137
- hasModelRegistry: true,
138
- defaultModel: "anthropic/claude-sonnet-4-5",
139
- });
140
- expect(result.applied).toBe(false);
141
- });
142
-
143
- // ── Bridge reload of in-flight session ─────────────────────────────────
144
- it("does NOT apply default model on bridge reload of in-flight session", () => {
145
- // Reload: reason === "reload" (filtered by the reason gate AND messages > 0).
146
- const ctx = makeCtx({ entriesCount: 100, messageCount: 60 });
147
- const result = runSessionStartDefaultModelBranch({
148
- ctx,
149
- event: { reason: "reload" },
150
- hasModelRegistry: true,
151
- defaultModel: "anthropic/claude-sonnet-4-5",
152
- });
153
- expect(result.applied).toBe(false);
154
- });
155
-
156
- // ── Older pi without buildSessionContext ───────────────────────────────
157
- it("applies default model when older pi lacks buildSessionContext (fallback to 0)", () => {
158
- // Hypothetical older pi: only getEntries() exists. Optional-chained fallback
159
- // returns 0 → predicate returns true → default applied. Safer than silent skip.
160
- const ctx: FakeCtx = {
161
- sessionManager: {
162
- getEntries: () => [{}, {}],
163
- // buildSessionContext intentionally absent
164
- },
165
- };
166
- const result = runSessionStartDefaultModelBranch({
167
- ctx,
168
- event: { reason: "startup" },
169
- hasModelRegistry: true,
170
- defaultModel: "anthropic/claude-sonnet-4-5",
171
- });
172
- expect(result.applied).toBe(true);
173
- });
174
-
175
- it("applies default model when buildSessionContext returns object without messages array", () => {
176
- // Defensive: malformed result from buildSessionContext. Optional-chained
177
- // .messages?.length falls through to ?? 0.
178
- const ctx: FakeCtx = {
179
- sessionManager: {
180
- getEntries: () => [{}, {}],
181
- buildSessionContext: () => ({} as BuildSessionContextResult),
182
- },
183
- };
184
- const result = runSessionStartDefaultModelBranch({
185
- ctx,
186
- event: { reason: "startup" },
187
- hasModelRegistry: true,
188
- defaultModel: "anthropic/claude-sonnet-4-5",
189
- });
190
- expect(result.applied).toBe(true);
191
- });
192
-
193
- // ── Default not configured ─────────────────────────────────────────────
194
- it("does NOT apply default model when config.defaultModel is empty", () => {
195
- const ctx = makeCtx({ entriesCount: 2, messageCount: 0 });
196
- const result = runSessionStartDefaultModelBranch({
197
- ctx,
198
- event: { reason: "startup" },
199
- hasModelRegistry: true,
200
- defaultModel: "",
201
- });
202
- expect(result.applied).toBe(false);
203
- });
204
-
205
- it("does NOT apply default model when model registry not yet available", () => {
206
- const ctx = makeCtx({ entriesCount: 2, messageCount: 0 });
207
- const result = runSessionStartDefaultModelBranch({
208
- ctx,
209
- event: { reason: "startup" },
210
- hasModelRegistry: false,
211
- defaultModel: "anthropic/claude-sonnet-4-5",
212
- });
213
- expect(result.applied).toBe(false);
214
- });
215
-
216
- // ── Spec invariant: signal source ──────────────────────────────────────
217
- it("uses buildSessionContext().messages, NOT getEntries(), as the signal", () => {
218
- // This is the regression-locking test. If anyone reverts the bridge.ts
219
- // expression from `buildSessionContext().messages.length` back to
220
- // `getEntries().length`, this test must fail.
221
- //
222
- // Scenario: a session with 100 raw entries but ZERO messages (e.g. lots
223
- // of model_change / thinking_level_change / compaction-summary entries).
224
- // The correct signal says "brand-new, apply default"; the old (buggy)
225
- // signal would say "has history, skip".
226
- const buildSessionContext = vi.fn(() => ({ messages: [] }));
227
- const getEntries = vi.fn(() => Array.from({ length: 100 }, () => ({})));
228
- const ctx: FakeCtx = {
229
- sessionManager: { buildSessionContext, getEntries },
230
- };
231
- const result = runSessionStartDefaultModelBranch({
232
- ctx,
233
- event: { reason: "startup" },
234
- hasModelRegistry: true,
235
- defaultModel: "anthropic/claude-sonnet-4-5",
236
- });
237
- expect(result.applied).toBe(true);
238
- expect(buildSessionContext).toHaveBeenCalled();
239
- // getEntries() MAY or MAY NOT be called by the production branch; the
240
- // important contract is that buildSessionContext is the source of truth.
241
- });
242
- });
@@ -1,50 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { shouldApplyDefaultModel } from "../bridge-default-model-gate.js";
3
-
4
- // Note: `entryCount` is the message count from
5
- // `ctx.sessionManager.buildSessionContext().messages.length`, not the raw
6
- // `getEntries()` count. See change: fix-default-model-new-session-entry-count.
7
- describe("shouldApplyDefaultModel", () => {
8
- const base = { hasModelRegistry: true, hasDefaultModel: true };
9
-
10
- it("applies for a brand-new session (reason=startup, messages=0)", () => {
11
- expect(shouldApplyDefaultModel({ ...base, reason: "startup", entryCount: 0 })).toBe(true);
12
- });
13
-
14
- it("does NOT apply for resumed sessions (messages>0, reason=startup)", () => {
15
- expect(shouldApplyDefaultModel({ ...base, reason: "startup", entryCount: 5 })).toBe(false);
16
- });
17
-
18
- it("does NOT apply for in-process new (reason=new)", () => {
19
- // pi handles its own default for in-process /new — bridge stays out
20
- expect(shouldApplyDefaultModel({ ...base, reason: "new", entryCount: 0 })).toBe(false);
21
- });
22
-
23
- it("does NOT apply for in-process resume (reason=resume)", () => {
24
- expect(shouldApplyDefaultModel({ ...base, reason: "resume", entryCount: 5 })).toBe(false);
25
- });
26
-
27
- it("does NOT apply for in-process fork (reason=fork)", () => {
28
- expect(shouldApplyDefaultModel({ ...base, reason: "fork", entryCount: 5 })).toBe(false);
29
- });
30
-
31
- it("does NOT apply for reload of in-flight session (reason=reload, messages>0)", () => {
32
- expect(shouldApplyDefaultModel({ ...base, reason: "reload", entryCount: 5 })).toBe(false);
33
- });
34
-
35
- it("does NOT apply when defaultModel is not configured", () => {
36
- expect(
37
- shouldApplyDefaultModel({ ...base, hasDefaultModel: false, reason: "startup", entryCount: 0 }),
38
- ).toBe(false);
39
- });
40
-
41
- it("does NOT apply when model registry not yet available", () => {
42
- expect(
43
- shouldApplyDefaultModel({ ...base, hasModelRegistry: false, reason: "startup", entryCount: 0 }),
44
- ).toBe(false);
45
- });
46
-
47
- it("does NOT apply when reason is undefined", () => {
48
- expect(shouldApplyDefaultModel({ ...base, reason: undefined, entryCount: 0 })).toBe(false);
49
- });
50
- });