@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,69 +0,0 @@
1
- /**
2
- * Shared assistant-turn fixtures for the empty-actionable-turn guard.
3
- *
4
- * `THINKING_ONLY_STOP` is derived from the captured live transcript
5
- * `…/2026-07-12T01-56-02…_019f5409….jsonl` (line 7): a `google-vertex/
6
- * gemini-2.5-pro` turn whose content is a single thinking block, `usage.output`
7
- * entirely reasoning, zero visible text, no tool call, `stopReason = "stop"`.
8
- *
9
- * See change: fix-gemini-subagent-silent-tool-schema-failure.
10
- */
11
-
12
- import type { ClassifiableTurn } from "../../turn-actionability.js";
13
-
14
- /** Captured defect: thinking-only completion, clean `stop`, no output. */
15
- export const THINKING_ONLY_STOP: ClassifiableTurn = {
16
- role: "assistant",
17
- stopReason: "stop",
18
- content: [{ type: "thinking", thinking: "**Exploring Doubtful Decisions**\nI'm processing…" }],
19
- error: {},
20
- };
21
-
22
- /** Wholly empty completion — no parts at all, clean `stop`. */
23
- export const EMPTY_STOP: ClassifiableTurn = {
24
- role: "assistant",
25
- stopReason: "stop",
26
- content: [],
27
- };
28
-
29
- /** Normal turn: thinking + a visible text part, `stop`. */
30
- export const NORMAL_TEXT_STOP: ClassifiableTurn = {
31
- role: "assistant",
32
- stopReason: "stop",
33
- content: [
34
- { type: "thinking", thinking: "**Analyzing…**" },
35
- { type: "text", text: "This skill is for stress-testing non-trivial decisions." },
36
- ],
37
- };
38
-
39
- /** Tool-call turn: thinking + a toolCall part, `toolUse`. */
40
- export const TOOL_CALL_TURN: ClassifiableTurn = {
41
- role: "assistant",
42
- stopReason: "toolUse",
43
- content: [
44
- { type: "thinking", thinking: "**Testing…**" },
45
- { type: "toolCall", id: "read_1", name: "read", arguments: { path: "/x" } },
46
- ],
47
- };
48
-
49
- /** Truncated turn: hit the token budget mid-reasoning, no visible output. */
50
- export const LENGTH_TRUNCATED: ClassifiableTurn = {
51
- role: "assistant",
52
- stopReason: "length",
53
- content: [{ type: "thinking", thinking: "**Long reasoning that ran out of budget…**" }],
54
- };
55
-
56
- /** Errored turn: terminal provider/adapter error. */
57
- export const ERRORED_TURN: ClassifiableTurn = {
58
- role: "assistant",
59
- stopReason: "error",
60
- content: [],
61
- errorMessage: "provider returned error: 503 service unavailable",
62
- };
63
-
64
- /** Whitespace-only text — treated as no visible text (empty-actionable). */
65
- export const WHITESPACE_TEXT_STOP: ClassifiableTurn = {
66
- role: "assistant",
67
- stopReason: "stop",
68
- content: [{ type: "text", text: " \n\t " }],
69
- };
@@ -1,88 +0,0 @@
1
- /**
2
- * Tests for bridge entryId stamping on message_end events.
3
- *
4
- * HISTORY: Originally this file modelled pi <0.69's synchronous emit pattern,
5
- * where the bridge's `queueMicrotask` deferral ran BEFORE
6
- * sessionManager.appendMessage. That design no longer reflects pi 0.70.x:
7
- * pi awaits extension handlers inside _emitExtensionEvent, so the microtask
8
- * resolves *inside* the awaited dispatcher, before persistence. The fix
9
- * (see change: fix-per-message-fork) is `setTimeout(0)` (a macrotask)
10
- * combined with reading `event.message.id` (which pi mutates in place
11
- * during appendMessage) or a WeakMap populated by the wrapped appendMessage.
12
- *
13
- * The previous test "message_start should still capture entryId immediately
14
- * (no deferral)" codified the off-by-one bug as expected behavior — it has
15
- * been REMOVED. The current test suite below models pi 0.70.x semantics
16
- * directly. Detailed pi-0.70-specific scenarios live in
17
- * `bridge-entry-id-pi-070.test.ts`.
18
- */
19
- import { describe, it, expect } from "vitest";
20
-
21
- describe("message_end entryId timing on pi 0.70.x", () => {
22
- it("setTimeout(0) deferral captures the post-persist entry ID", async () => {
23
- // Simulate pi 0.70.x: bridge handler runs awaited, THEN appendMessage runs.
24
- let leafId = "user-entry-100";
25
- const sessionManager = {
26
- getLeafId: () => leafId,
27
- appendMessage: (msg: any) => {
28
- msg.id = "assistant-entry-101";
29
- leafId = msg.id;
30
- return msg.id;
31
- },
32
- };
33
-
34
- const event = { type: "message_end", message: { role: "assistant" } as any };
35
- let captured: string | undefined;
36
- let sendDone!: () => void;
37
- const sentP = new Promise<void>((r) => { sendDone = r; });
38
-
39
- // Bridge handler: schedules a setTimeout(0) and returns synchronously.
40
- // The awaited dispatcher then unwinds, appendMessage runs, AND finally
41
- // the timeout fires.
42
- const bridgeHandler = (ev: any) => {
43
- setTimeout(() => {
44
- captured = ev.message.id ?? sessionManager.getLeafId();
45
- sendDone();
46
- }, 0);
47
- };
48
-
49
- // Simulate the dispatcher: await handler, then call appendMessage.
50
- await bridgeHandler(event);
51
- sessionManager.appendMessage(event.message);
52
- await sentP;
53
-
54
- expect(captured).toBe("assistant-entry-101");
55
- });
56
-
57
- it("queueMicrotask deferral would NOT work on pi 0.70.x (regression demonstration)", async () => {
58
- // Reproduces why we abandoned queueMicrotask: it resolves inside the
59
- // awaited dispatcher, before appendMessage runs.
60
- let leafId = "user-entry-100";
61
- let captured: string | undefined;
62
-
63
- const buggyBridge = async () => {
64
- await new Promise<void>((resolve) => queueMicrotask(resolve));
65
- captured = leafId;
66
- };
67
-
68
- // Pi 0.70.x: await the bridge, THEN persist. Mirroring the real ordering:
69
- const handlerP = buggyBridge();
70
- await handlerP;
71
- leafId = "assistant-entry-101"; // appendMessage runs after await
72
-
73
- expect(captured).toBe("user-entry-100");
74
- expect(captured).not.toBe("assistant-entry-101");
75
- });
76
-
77
- it("entry_persisted is the back-fill mechanism for user message_start (where event.message.id is unavailable)", () => {
78
- // Behavioural assertion (pure data shape): when the bridge sends a
79
- // user message_start, it stamps a nonce; later when pi persists the
80
- // user entry, the bridge sends entry_persisted { nonce, entryId }.
81
- // The reducer pairs them by nonce. See change: fix-per-message-fork.
82
- const start = { type: "message_start", message: { role: "user" }, nonce: "n-1" };
83
- const persisted = { type: "entry_persisted", entryId: "user-200", nonce: "n-1" };
84
-
85
- expect(start.nonce).toBe(persisted.nonce);
86
- expect(persisted.entryId).toBe("user-200");
87
- });
88
- });
@@ -1,73 +0,0 @@
1
- /**
2
- * Tests for `sendGitInfoIfChanged` gitStatus payload + dedup.
3
- * See change: add-session-uncommitted-indicator-and-commit.
4
- */
5
- import { describe, it, expect, vi, beforeEach } from "vitest";
6
-
7
- const { gatherGitInfo, gatherGitStatus } = vi.hoisted(() => ({
8
- gatherGitInfo: vi.fn(),
9
- gatherGitStatus: vi.fn(),
10
- }));
11
-
12
- vi.mock("../vcs-info.js", () => ({ gatherGitInfo, gatherGitStatus }));
13
-
14
- import { sendGitInfoIfChanged } from "../model-tracker.js";
15
- import type { BridgeContext } from "../bridge-context.js";
16
- import type { GitStatus } from "@blackbelt-technology/pi-dashboard-shared/types.js";
17
-
18
- function makeBc() {
19
- const send = vi.fn();
20
- const bc = {
21
- sessionId: "s1",
22
- connection: { send },
23
- lastGitBranch: undefined,
24
- lastGitPrNumber: undefined,
25
- lastGitWorktreeJson: undefined,
26
- lastGitStatusJson: undefined,
27
- } as unknown as BridgeContext;
28
- return { bc, send };
29
- }
30
-
31
- const CLEAN: GitStatus = { dirtyCount: 0, staged: 0, unstaged: 0, untracked: 0, ahead: 0, behind: 0 };
32
- const DIRTY: GitStatus = { dirtyCount: 3, staged: 1, unstaged: 2, untracked: 0, ahead: 0, behind: 0 };
33
-
34
- describe("sendGitInfoIfChanged — gitStatus", () => {
35
- beforeEach(() => {
36
- gatherGitInfo.mockReset();
37
- gatherGitStatus.mockReset();
38
- gatherGitInfo.mockReturnValue({ gitBranch: "main" });
39
- });
40
-
41
- it("includes gitStatus in the payload", () => {
42
- const { bc, send } = makeBc();
43
- gatherGitStatus.mockReturnValue(DIRTY);
44
- sendGitInfoIfChanged(bc, "/repo");
45
- expect(send).toHaveBeenCalledTimes(1);
46
- expect(send.mock.calls[0][0]).toMatchObject({ type: "git_info_update", gitStatus: DIRTY });
47
- });
48
-
49
- it("does not re-emit when branch + status unchanged", () => {
50
- const { bc, send } = makeBc();
51
- gatherGitStatus.mockReturnValue(DIRTY);
52
- sendGitInfoIfChanged(bc, "/repo");
53
- sendGitInfoIfChanged(bc, "/repo");
54
- expect(send).toHaveBeenCalledTimes(1);
55
- });
56
-
57
- it("re-emits when only the status changes (branch stable)", () => {
58
- const { bc, send } = makeBc();
59
- gatherGitStatus.mockReturnValueOnce(CLEAN).mockReturnValueOnce(DIRTY);
60
- sendGitInfoIfChanged(bc, "/repo");
61
- sendGitInfoIfChanged(bc, "/repo");
62
- expect(send).toHaveBeenCalledTimes(2);
63
- expect(send.mock.calls[1][0]).toMatchObject({ gitStatus: DIRTY });
64
- });
65
-
66
- it("omits gitStatus when the probe is inconclusive", () => {
67
- const { bc, send } = makeBc();
68
- gatherGitStatus.mockReturnValue(undefined);
69
- sendGitInfoIfChanged(bc, "/repo");
70
- expect(send).toHaveBeenCalledTimes(1);
71
- expect(send.mock.calls[0][0].gitStatus).toBeUndefined();
72
- });
73
- });
@@ -1,102 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { parseRemoteUrl, detectPlatform, buildGitLinks } from "../git-link-builder.js";
3
-
4
- describe("parseRemoteUrl", () => {
5
- it("parses SSH URL", () => {
6
- expect(parseRemoteUrl("git@github.com:user/repo.git")).toEqual({
7
- host: "github.com", user: "user", repo: "repo",
8
- });
9
- });
10
-
11
- it("parses SSH URL without .git suffix", () => {
12
- expect(parseRemoteUrl("git@github.com:user/repo")).toEqual({
13
- host: "github.com", user: "user", repo: "repo",
14
- });
15
- });
16
-
17
- it("parses HTTPS URL", () => {
18
- expect(parseRemoteUrl("https://github.com/user/repo.git")).toEqual({
19
- host: "github.com", user: "user", repo: "repo",
20
- });
21
- });
22
-
23
- it("parses HTTPS URL without .git suffix", () => {
24
- expect(parseRemoteUrl("https://gitlab.com/user/repo")).toEqual({
25
- host: "gitlab.com", user: "user", repo: "repo",
26
- });
27
- });
28
-
29
- it("parses nested group paths", () => {
30
- expect(parseRemoteUrl("git@gitlab.com:group/subgroup/repo.git")).toEqual({
31
- host: "gitlab.com", user: "group/subgroup", repo: "repo",
32
- });
33
- });
34
-
35
- it("returns undefined for invalid URL", () => {
36
- expect(parseRemoteUrl("not-a-url")).toBeUndefined();
37
- });
38
- });
39
-
40
- describe("detectPlatform", () => {
41
- it("detects GitHub", () => expect(detectPlatform("github.com")).toBe("github"));
42
- it("detects GitLab", () => expect(detectPlatform("gitlab.com")).toBe("gitlab"));
43
- it("detects Bitbucket", () => expect(detectPlatform("bitbucket.org")).toBe("bitbucket"));
44
- it("detects Gitea", () => expect(detectPlatform("gitea.com")).toBe("gitea"));
45
- it("detects Codeberg", () => expect(detectPlatform("codeberg.org")).toBe("codeberg"));
46
- it("detects SourceHut", () => expect(detectPlatform("sr.ht")).toBe("sourcehut"));
47
- it("returns undefined for unknown host", () => expect(detectPlatform("self-hosted.example.com")).toBeUndefined());
48
- });
49
-
50
- describe("buildGitLinks", () => {
51
- it("builds GitHub branch and PR links", () => {
52
- const links = buildGitLinks("git@github.com:user/repo.git", "main", 42);
53
- expect(links.branchUrl).toBe("https://github.com/user/repo/tree/main");
54
- expect(links.prUrl).toBe("https://github.com/user/repo/pull/42");
55
- });
56
-
57
- it("builds GitLab branch and MR links", () => {
58
- const links = buildGitLinks("https://gitlab.com/user/repo.git", "main", 10);
59
- expect(links.branchUrl).toBe("https://gitlab.com/user/repo/-/tree/main");
60
- expect(links.prUrl).toBe("https://gitlab.com/user/repo/-/merge_requests/10");
61
- });
62
-
63
- it("builds Bitbucket links", () => {
64
- const links = buildGitLinks("git@bitbucket.org:user/repo.git", "develop", 5);
65
- expect(links.branchUrl).toBe("https://bitbucket.org/user/repo/src/develop");
66
- expect(links.prUrl).toBe("https://bitbucket.org/user/repo/pull-requests/5");
67
- });
68
-
69
- it("builds Codeberg links", () => {
70
- const links = buildGitLinks("https://codeberg.org/user/repo.git", "main", 3);
71
- expect(links.branchUrl).toBe("https://codeberg.org/user/repo/src/branch/main");
72
- expect(links.prUrl).toBe("https://codeberg.org/user/repo/pulls/3");
73
- });
74
-
75
- it("builds SourceHut links", () => {
76
- const links = buildGitLinks("git@sr.ht:user/repo.git", "main", 1);
77
- expect(links.branchUrl).toBe("https://sr.ht/user/repo/tree/main");
78
- expect(links.prUrl).toBe("https://sr.ht/user/repo/patches/1");
79
- });
80
-
81
- it("URL-encodes branch names with slashes", () => {
82
- const links = buildGitLinks("git@github.com:user/repo.git", "feat/my-feature");
83
- expect(links.branchUrl).toBe("https://github.com/user/repo/tree/feat%2Fmy-feature");
84
- });
85
-
86
- it("returns empty for unknown host", () => {
87
- const links = buildGitLinks("git@self-hosted.example.com:user/repo.git", "main");
88
- expect(links.branchUrl).toBeUndefined();
89
- expect(links.prUrl).toBeUndefined();
90
- });
91
-
92
- it("does not generate branch URL for detached HEAD", () => {
93
- const links = buildGitLinks("git@github.com:user/repo.git", "HEAD");
94
- expect(links.branchUrl).toBeUndefined();
95
- });
96
-
97
- it("builds branch URL without PR", () => {
98
- const links = buildGitLinks("git@github.com:user/repo.git", "main");
99
- expect(links.branchUrl).toBe("https://github.com/user/repo/tree/main");
100
- expect(links.prUrl).toBeUndefined();
101
- });
102
- });
@@ -1,69 +0,0 @@
1
- /**
2
- * Tests for `runGitPollTick` — the shared git + name/model poll-tick body used
3
- * by both the session-start and session-change timers in bridge.ts.
4
- *
5
- * Regression guard for fix-stale-ctx-cwd-crash: the session-change timer used
6
- * to be a separate copy that dropped sendSessionNameIfChanged /
7
- * sendModelUpdateIfChanged, so renames + model changes stopped propagating
8
- * after a new/fork/resume. Both timers now route through this one function, so
9
- * asserting name/model fire here proves they fire after a session change too.
10
- */
11
- import { describe, it, expect, vi } from "vitest";
12
- import { runGitPollTick, type GitPollDeps } from "../git-poll.js";
13
-
14
- function makeDeps(overrides: Partial<GitPollDeps> = {}): GitPollDeps {
15
- return {
16
- isActive: () => true,
17
- cachedCwd: () => "/repo",
18
- sendGitInfoIfChanged: vi.fn(),
19
- sendCwdMissingIfChanged: vi.fn(),
20
- sendSessionNameIfChanged: vi.fn(),
21
- sendModelUpdateIfChanged: vi.fn(),
22
- sendPiVersionIfChanged: vi.fn(),
23
- ...overrides,
24
- };
25
- }
26
-
27
- describe("runGitPollTick", () => {
28
- it("active + cwd present: fires all four checks", () => {
29
- const deps = makeDeps();
30
- runGitPollTick(deps);
31
- expect(deps.sendGitInfoIfChanged).toHaveBeenCalledWith("/repo");
32
- expect(deps.sendCwdMissingIfChanged).toHaveBeenCalledWith("/repo");
33
- expect(deps.sendSessionNameIfChanged).toHaveBeenCalledTimes(1);
34
- expect(deps.sendModelUpdateIfChanged).toHaveBeenCalledTimes(1);
35
- expect(deps.sendPiVersionIfChanged).toHaveBeenCalledTimes(1);
36
- });
37
-
38
- it("name + model checks fire even when cwd is absent (stale-ctx swap)", () => {
39
- const deps = makeDeps({ cachedCwd: () => undefined });
40
- runGitPollTick(deps);
41
- // git/cwd skipped — they need a directory
42
- expect(deps.sendGitInfoIfChanged).not.toHaveBeenCalled();
43
- expect(deps.sendCwdMissingIfChanged).not.toHaveBeenCalled();
44
- // but name + model still propagate — the regression this guards
45
- expect(deps.sendSessionNameIfChanged).toHaveBeenCalledTimes(1);
46
- expect(deps.sendModelUpdateIfChanged).toHaveBeenCalledTimes(1);
47
- });
48
-
49
- it("inactive: no-op, nothing fires", () => {
50
- const deps = makeDeps({ isActive: () => false });
51
- runGitPollTick(deps);
52
- expect(deps.sendGitInfoIfChanged).not.toHaveBeenCalled();
53
- expect(deps.sendCwdMissingIfChanged).not.toHaveBeenCalled();
54
- expect(deps.sendSessionNameIfChanged).not.toHaveBeenCalled();
55
- expect(deps.sendModelUpdateIfChanged).not.toHaveBeenCalled();
56
- });
57
-
58
- it("reads cachedCwd fresh each tick (post-session-change cwd swap)", () => {
59
- let cwd: string | undefined = "/old";
60
- const deps = makeDeps({ cachedCwd: () => cwd });
61
- runGitPollTick(deps);
62
- cwd = "/new";
63
- runGitPollTick(deps);
64
- expect(deps.sendGitInfoIfChanged).toHaveBeenNthCalledWith(1, "/old");
65
- expect(deps.sendGitInfoIfChanged).toHaveBeenNthCalledWith(2, "/new");
66
- // name/model fired on both ticks regardless of the cwd swap
67
- expect(deps.sendModelUpdateIfChanged).toHaveBeenCalledTimes(2);
68
- });
69
- });