@blackbelt-technology/pi-dashboard-extension 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/.pi/skills/browser/LICENSE +201 -0
  2. package/.pi/skills/browser/SKILL.md +105 -0
  3. package/.pi/skills/browser/UPSTREAM.md +46 -0
  4. package/.pi/skills/browser/references/electron.md +351 -0
  5. package/.pi/skills/browser/references/web.md +2789 -0
  6. package/.pi/skills/browser/scripts/detect-dashboard.sh +55 -0
  7. package/.pi/skills/doctor/AGENTS.md +27 -0
  8. package/.pi/skills/doctor/SKILL.md +89 -0
  9. package/.pi/skills/doctor/_lib/checks.ts +177 -0
  10. package/.pi/skills/doctor/_lib/derive-tokens.ts +43 -0
  11. package/.pi/skills/doctor/_lib/front-matter.ts +122 -0
  12. package/.pi/skills/doctor/_lib/index.ts +14 -0
  13. package/.pi/skills/doctor/_lib/knowledge-hash.ts +74 -0
  14. package/.pi/skills/doctor/_lib/provenance.ts +50 -0
  15. package/.pi/skills/doctor/_lib/regenerate.ts +100 -0
  16. package/.pi/skills/doctor/_lib/router.ts +155 -0
  17. package/.pi/skills/doctor/_lib/server-tier.ts +62 -0
  18. package/.pi/skills/doctor/modules/build-reload.knowledge.hash +1 -0
  19. package/.pi/skills/doctor/modules/build-reload.md +51 -0
  20. package/.pi/skills/doctor/modules/env-node.knowledge.hash +1 -0
  21. package/.pi/skills/doctor/modules/env-node.md +49 -0
  22. package/.pi/skills/doctor/modules/install-topology.knowledge.hash +1 -0
  23. package/.pi/skills/doctor/modules/install-topology.md +53 -0
  24. package/.pi/skills/doctor/modules/model-resolution.knowledge.hash +1 -0
  25. package/.pi/skills/doctor/modules/model-resolution.md +53 -0
  26. package/.pi/skills/doctor/modules/peers.knowledge.hash +1 -0
  27. package/.pi/skills/doctor/modules/peers.md +57 -0
  28. package/.pi/skills/doctor/modules/pi-resolution.knowledge.hash +1 -0
  29. package/.pi/skills/doctor/modules/pi-resolution.md +60 -0
  30. package/.pi/skills/doctor/modules/plugins-bridges.knowledge.hash +1 -0
  31. package/.pi/skills/doctor/modules/plugins-bridges.md +56 -0
  32. package/.pi/skills/pi-dashboard/SKILL.md +68 -0
  33. package/.pi/skills/pi-dashboard/commands/README.md +45 -0
  34. package/.pi/skills/pi-dashboard/commands/dashboard-flow-abort.md +10 -0
  35. package/.pi/skills/pi-dashboard/commands/dashboard-flow-auto.md +10 -0
  36. package/.pi/skills/pi-dashboard/commands/dashboard-git-branches.md +6 -0
  37. package/.pi/skills/pi-dashboard/commands/dashboard-git-init.md +8 -0
  38. package/.pi/skills/pi-dashboard/commands/dashboard-git-stash-pop.md +8 -0
  39. package/.pi/skills/pi-dashboard/commands/dashboard-list-models.md +10 -0
  40. package/.pi/skills/pi-dashboard/commands/dashboard-peer-list.md +6 -0
  41. package/.pi/skills/pi-dashboard/commands/dashboard-peer-scan.md +6 -0
  42. package/.pi/skills/pi-dashboard/commands/dashboard-pin-list.md +5 -0
  43. package/.pi/skills/pi-dashboard/commands/dashboard-proposal-archive.md +6 -0
  44. package/.pi/skills/pi-dashboard/commands/dashboard-proposal-attach.md +10 -0
  45. package/.pi/skills/pi-dashboard/commands/dashboard-proposal-detach.md +10 -0
  46. package/.pi/skills/pi-dashboard/commands/dashboard-server-config.md +5 -0
  47. package/.pi/skills/pi-dashboard/commands/dashboard-server-health.md +6 -0
  48. package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-off.md +6 -0
  49. package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-on.md +6 -0
  50. package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-status.md +6 -0
  51. package/.pi/skills/pi-dashboard/commands/dashboard-session-abort-all.md +14 -0
  52. package/.pi/skills/pi-dashboard/commands/dashboard-session-abort.md +10 -0
  53. package/.pi/skills/pi-dashboard/commands/dashboard-session-diff.md +11 -0
  54. package/.pi/skills/pi-dashboard/commands/dashboard-session-fork.md +10 -0
  55. package/.pi/skills/pi-dashboard/commands/dashboard-session-hide.md +10 -0
  56. package/.pi/skills/pi-dashboard/commands/dashboard-session-info.md +11 -0
  57. package/.pi/skills/pi-dashboard/commands/dashboard-session-kill.md +10 -0
  58. package/.pi/skills/pi-dashboard/commands/dashboard-session-list-active.md +8 -0
  59. package/.pi/skills/pi-dashboard/commands/dashboard-session-list-here.md +8 -0
  60. package/.pi/skills/pi-dashboard/commands/dashboard-session-list.md +6 -0
  61. package/.pi/skills/pi-dashboard/commands/dashboard-session-model.md +10 -0
  62. package/.pi/skills/pi-dashboard/commands/dashboard-session-rename.md +10 -0
  63. package/.pi/skills/pi-dashboard/commands/dashboard-session-resume.md +10 -0
  64. package/.pi/skills/pi-dashboard/commands/dashboard-session-spawn.md +10 -0
  65. package/.pi/skills/pi-dashboard/commands/dashboard-session-tell.md +10 -0
  66. package/.pi/skills/pi-dashboard/commands/dashboard-session-thinking.md +10 -0
  67. package/.pi/skills/pi-dashboard/commands/dashboard-session-unhide.md +10 -0
  68. package/.pi/skills/pi-dashboard/references/api-reference.md +30 -0
  69. package/.pi/skills/pi-dashboard/references/recipes.md +38 -0
  70. package/.pi/skills/pi-dashboard/references/slash-commands.md +71 -0
  71. package/.pi/skills/pi-dashboard/scripts/dashboard-api.sh +6 -0
  72. package/.pi/skills/pi-dashboard/scripts/dashboard-bus.ts +217 -0
  73. package/.pi/skills/project-init/SKILL.md +279 -0
  74. package/.pi/skills/project-init/dox-doctrine.md +104 -0
  75. package/.pi/skills/project-init/profiles/coding/AGENTS.md.tmpl +111 -0
  76. package/.pi/skills/project-init/profiles/coding/profile.json +5 -0
  77. package/.pi/skills/project-init/profiles/coding/prompts/plan-change.md +5 -0
  78. package/.pi/skills/project-init/profiles/coding/prompts/tdd-loop.md +6 -0
  79. package/.pi/skills/project-init/profiles/coding/settings.json.tmpl +9 -0
  80. package/.pi/skills/project-init/profiles/docs/AGENTS.md.tmpl +37 -0
  81. package/.pi/skills/project-init/profiles/docs/profile.json +4 -0
  82. package/.pi/skills/project-init/profiles/docs/prompts/draft-page.md +5 -0
  83. package/.pi/skills/project-init/profiles/docs/settings.json.tmpl +9 -0
  84. package/package.json +12 -4
  85. package/src/AGENTS.md +56 -0
  86. package/src/__tests__/abort-latch.test.ts +97 -0
  87. package/src/__tests__/agent-settled.test.ts +82 -0
  88. package/src/__tests__/artifact-roots.test.ts +83 -0
  89. package/src/__tests__/ask-user-attachments.test.ts +106 -0
  90. package/src/__tests__/ask-user-tool.test.ts +90 -27
  91. package/src/__tests__/auto-session-namer.test.ts +339 -0
  92. package/src/__tests__/bridge-default-model-apply.test.ts +242 -0
  93. package/src/__tests__/bridge-default-model-gate.test.ts +6 -3
  94. package/src/__tests__/bridge-followup-mutation.test.ts +217 -0
  95. package/src/__tests__/bridge-followup-queue-drain.test.ts +266 -0
  96. package/src/__tests__/bridge-hasui-flip.test.ts +109 -0
  97. package/src/__tests__/bridge-no-queue-mutation.test.ts +112 -0
  98. package/src/__tests__/bridge-plugin-emit-event.test.ts +44 -0
  99. package/src/__tests__/bridge-shutdown-reset.test.ts +57 -136
  100. package/src/__tests__/bridge-slash-command-routing.test.ts +7 -7
  101. package/src/__tests__/bridge-stop-after-turn.test.ts +72 -0
  102. package/src/__tests__/bridge-system-followup.test.ts +163 -0
  103. package/src/__tests__/bridge-thinking-level-select.test.ts +68 -0
  104. package/src/__tests__/browser-skill-registered.test.ts +84 -0
  105. package/src/__tests__/build-provider-catalogue.test.ts +35 -1
  106. package/src/__tests__/command-handler.test.ts +331 -35
  107. package/src/__tests__/commit-draft.test.ts +100 -0
  108. package/src/__tests__/connection-dropped-frames.test.ts +78 -0
  109. package/src/__tests__/custom-provider-apikey-roundtrip.test.ts +128 -0
  110. package/src/__tests__/cwd-missing-probe.test.ts +82 -0
  111. package/src/__tests__/dashboard-commands-shipped.test.ts +53 -0
  112. package/src/__tests__/dashboard-context-injector.test.ts +190 -0
  113. package/src/__tests__/doctor/checks.test.ts +121 -0
  114. package/src/__tests__/doctor/modules.test.ts +64 -0
  115. package/src/__tests__/doctor/provenance-hash.test.ts +94 -0
  116. package/src/__tests__/doctor/router.test.ts +143 -0
  117. package/src/__tests__/empty-actionable-guard-config.test.ts +32 -0
  118. package/src/__tests__/empty-actionable-guard.test.ts +73 -0
  119. package/src/__tests__/enrich-model-metadata.test.ts +21 -0
  120. package/src/__tests__/extension-slash-command-detection.test.ts +37 -1
  121. package/src/__tests__/filter-enabled-models.test.ts +151 -0
  122. package/src/__tests__/fixtures/turn-actionability-fixtures.ts +69 -0
  123. package/src/__tests__/git-info-status.test.ts +73 -0
  124. package/src/__tests__/git-poll.test.ts +69 -0
  125. package/src/__tests__/markdown-image-inliner.test.ts +37 -0
  126. package/src/__tests__/model-resolve.test.ts +379 -0
  127. package/src/__tests__/pi-version-tracker.test.ts +109 -0
  128. package/src/__tests__/process-scanner.test.ts +112 -22
  129. package/src/__tests__/project-init-detect-stack.test.ts +61 -0
  130. package/src/__tests__/project-init-dox-kb-config.test.ts +53 -0
  131. package/src/__tests__/project-init-profiles.test.ts +84 -0
  132. package/src/__tests__/project-init-scaffold.test.ts +139 -0
  133. package/src/__tests__/project-init-seed-doctrine.test.ts +100 -0
  134. package/src/__tests__/project-trust.test.ts +92 -0
  135. package/src/__tests__/prompt-expander.test.ts +191 -1
  136. package/src/__tests__/provider-register-reload.test.ts +36 -6
  137. package/src/__tests__/provider-register-thinking-levels.test.ts +51 -0
  138. package/src/__tests__/retry-tracker.test.ts +75 -70
  139. package/src/__tests__/role-manager.test.ts +585 -0
  140. package/src/__tests__/role-model-tools-registry-readiness.test.ts +114 -0
  141. package/src/__tests__/role-model-tools.test.ts +229 -0
  142. package/src/__tests__/search-files-completeness.test.ts +111 -0
  143. package/src/__tests__/search-files-ranking.test.ts +168 -0
  144. package/src/__tests__/server-auto-start.test.ts +121 -4
  145. package/src/__tests__/server-launcher-launch.test.ts +24 -6
  146. package/src/__tests__/server-launcher.test.ts +19 -2
  147. package/src/__tests__/session-sync.test.ts +36 -0
  148. package/src/__tests__/subagent-frame-buffer.test.ts +239 -0
  149. package/src/__tests__/tool-result-image-inliner.test.ts +206 -0
  150. package/src/__tests__/tui-prompt-adapter.test.ts +70 -64
  151. package/src/__tests__/turn-actionability.test.ts +86 -0
  152. package/src/__tests__/vcs-info.test.ts +145 -4
  153. package/src/__tests__/visibility-intent.test.ts +43 -0
  154. package/src/abort-latch.ts +55 -0
  155. package/src/abort-latch.ts.AGENTS.md +3 -0
  156. package/src/agent-settled.ts +72 -0
  157. package/src/agent-settled.ts.AGENTS.md +3 -0
  158. package/src/artifact-roots.ts +73 -0
  159. package/src/artifact-roots.ts.AGENTS.md +3 -0
  160. package/src/ask-user-attachments.ts +121 -0
  161. package/src/ask-user-attachments.ts.AGENTS.md +3 -0
  162. package/src/ask-user-tool.ts +56 -58
  163. package/src/ask-user-tool.ts.AGENTS.md +3 -0
  164. package/src/auto-session-namer.ts +334 -0
  165. package/src/auto-session-namer.ts.AGENTS.md +3 -0
  166. package/src/bridge-context.ts +86 -8
  167. package/src/bridge-context.ts.AGENTS.md +3 -0
  168. package/src/bridge-default-model-gate.ts +22 -6
  169. package/src/bridge-default-model-gate.ts.AGENTS.md +3 -0
  170. package/src/bridge.ts +1241 -360
  171. package/src/bridge.ts.AGENTS.md +3 -0
  172. package/src/canvas-tool.ts +107 -0
  173. package/src/command-handler.ts +490 -51
  174. package/src/command-handler.ts.AGENTS.md +3 -0
  175. package/src/commit-draft-agent.ts +114 -0
  176. package/src/commit-draft-agent.ts.AGENTS.md +3 -0
  177. package/src/commit-draft.ts +136 -0
  178. package/src/commit-draft.ts.AGENTS.md +3 -0
  179. package/src/connection.ts +32 -1
  180. package/src/connection.ts.AGENTS.md +3 -0
  181. package/src/dashboard-context-injector.ts +124 -0
  182. package/src/dashboard-context-injector.ts.AGENTS.md +3 -0
  183. package/src/dashboard-default-adapter.ts.AGENTS.md +3 -0
  184. package/src/dev-build.ts.AGENTS.md +3 -0
  185. package/src/empty-actionable-guard-config.ts +32 -0
  186. package/src/empty-actionable-guard-config.ts.AGENTS.md +3 -0
  187. package/src/empty-actionable-guard.ts +90 -0
  188. package/src/empty-actionable-guard.ts.AGENTS.md +3 -0
  189. package/src/event-forwarder.ts.AGENTS.md +3 -0
  190. package/src/flow-event-wiring.ts +4 -14
  191. package/src/flow-event-wiring.ts.AGENTS.md +3 -0
  192. package/src/git-link-builder.ts.AGENTS.md +3 -0
  193. package/src/git-poll.ts +38 -0
  194. package/src/git-poll.ts.AGENTS.md +3 -0
  195. package/src/hasui-flip.ts +56 -0
  196. package/src/hasui-flip.ts.AGENTS.md +3 -0
  197. package/src/markdown-image-inliner.ts +45 -2
  198. package/src/markdown-image-inliner.ts.AGENTS.md +3 -0
  199. package/src/model-tracker.ts +145 -19
  200. package/src/model-tracker.ts.AGENTS.md +3 -0
  201. package/src/multiselect-decode.ts.AGENTS.md +3 -0
  202. package/src/multiselect-list.ts.AGENTS.md +3 -0
  203. package/src/multiselect-polyfill.ts.AGENTS.md +3 -0
  204. package/src/process-metrics.ts.AGENTS.md +3 -0
  205. package/src/process-scanner.ts +114 -103
  206. package/src/process-scanner.ts.AGENTS.md +3 -0
  207. package/src/project-init/AGENTS.md +12 -0
  208. package/src/project-init/detect-stack.ts +146 -0
  209. package/src/project-init/dox-kb-config.ts +47 -0
  210. package/src/project-init/profiles.ts +135 -0
  211. package/src/project-init/scaffold.ts +192 -0
  212. package/src/project-init/seed-doctrine.ts +95 -0
  213. package/src/project-trust.ts +63 -0
  214. package/src/project-trust.ts.AGENTS.md +3 -0
  215. package/src/prompt-bus.ts +10 -1
  216. package/src/prompt-bus.ts.AGENTS.md +3 -0
  217. package/src/prompt-expander.ts +238 -37
  218. package/src/prompt-expander.ts.AGENTS.md +3 -0
  219. package/src/provider-register.ts +323 -54
  220. package/src/provider-register.ts.AGENTS.md +3 -0
  221. package/src/retry-tracker.ts +64 -39
  222. package/src/retry-tracker.ts.AGENTS.md +3 -0
  223. package/src/role-manager.ts +436 -0
  224. package/src/role-manager.ts.AGENTS.md +3 -0
  225. package/src/role-model-tools.ts +301 -0
  226. package/src/role-model-tools.ts.AGENTS.md +3 -0
  227. package/src/server-auto-start.ts +59 -23
  228. package/src/server-auto-start.ts.AGENTS.md +3 -0
  229. package/src/server-launcher.ts +56 -16
  230. package/src/server-launcher.ts.AGENTS.md +3 -0
  231. package/src/session-sync.ts +111 -15
  232. package/src/session-sync.ts.AGENTS.md +3 -0
  233. package/src/slash-dispatch.ts +13 -11
  234. package/src/slash-dispatch.ts.AGENTS.md +3 -0
  235. package/src/source-detector.ts.AGENTS.md +3 -0
  236. package/src/subagent-frame-buffer.ts +220 -0
  237. package/src/subagent-frame-buffer.ts.AGENTS.md +3 -0
  238. package/src/tool-result-image-inliner.ts +204 -0
  239. package/src/tool-result-image-inliner.ts.AGENTS.md +3 -0
  240. package/src/tui-prompt-adapter.ts +123 -0
  241. package/src/tui-prompt-adapter.ts.AGENTS.md +3 -0
  242. package/src/turn-actionability.ts +117 -0
  243. package/src/turn-actionability.ts.AGENTS.md +3 -0
  244. package/src/ui-modules.ts.AGENTS.md +3 -0
  245. package/src/vcs-info.ts +91 -129
  246. package/src/vcs-info.ts.AGENTS.md +3 -0
  247. package/src/visibility-intent.ts +34 -0
  248. package/src/visibility-intent.ts.AGENTS.md +3 -0
  249. package/src/__tests__/bridge-retry-ordering.test.ts +0 -148
  250. package/src/__tests__/bridge-shadow-queue-drain.test.ts +0 -221
  251. package/src/__tests__/fixtures/usage-limit-error-strings.ts +0 -127
  252. package/src/__tests__/usage-limit-orderer.test.ts +0 -117
  253. package/src/__tests__/vcs-info-jj.test.ts +0 -145
  254. package/src/usage-limit-orderer.ts +0 -93
@@ -1,127 +0,0 @@
1
- /**
2
- * Real-world usage-limit / quota / billing error strings extracted from
3
- * production session logs (~/.pi/agent/sessions/**\/*.jsonl) plus
4
- * representative samples from provider docs. Used as fixtures for the
5
- * USAGE_LIMIT_PATTERN regex coverage tests.
6
- *
7
- * See change: fix-retry-banner-stuck-on-limit-exceeded.
8
- */
9
-
10
- export interface UsageLimitFixture {
11
- provider: string;
12
- /** A short label for the test name. */
13
- label: string;
14
- /** The verbatim errorMessage string as it appears on the wire. */
15
- error: string;
16
- }
17
-
18
- /**
19
- * Strings the broadened USAGE_LIMIT_PATTERN MUST match (terminal —
20
- * dashboard shows red banner, no retry).
21
- */
22
- export const USAGE_LIMIT_FIXTURES: UsageLimitFixture[] = [
23
- {
24
- provider: "google-generative-ai",
25
- label: "Gemini monthly spending cap (real fixture, BME-szakdoga session)",
26
- error: JSON.stringify({
27
- error: {
28
- message:
29
- "Your project has exceeded its monthly spending cap. Please go to AI Studio at https://ai.studio/spend to manage your project spend cap. Learn more at https://ai.google.dev/gemini-api/docs/billing#project-spend-caps. ",
30
- status: "RESOURCE_EXHAUSTED",
31
- },
32
- code: 429,
33
- status: "Too Many Requests",
34
- }),
35
- },
36
- {
37
- provider: "google-generative-ai",
38
- label: "Gemini RESOURCE_EXHAUSTED standalone",
39
- error: '{"error":{"status":"RESOURCE_EXHAUSTED","code":429}}',
40
- },
41
- {
42
- provider: "google",
43
- label: "Cloud Code Assist quota reset after Nh",
44
- error:
45
- "Cloud Code Assist API error (429): You have exhausted your capacity on this model. Your quota will reset after 50h27m20s.",
46
- },
47
- {
48
- provider: "openai-codex-responses",
49
- label: "Codex usage_limit_reached",
50
- error: "usage_limit_reached: 5000 RPM exceeded",
51
- },
52
- {
53
- provider: "openai-codex-responses",
54
- label: "Codex usage_not_included",
55
- error: "usage_not_included for this account",
56
- },
57
- {
58
- provider: "openai",
59
- label: "OpenAI insufficient_quota",
60
- error:
61
- 'You exceeded your current quota, please check your plan and billing details. {"code":"insufficient_quota"}',
62
- },
63
- {
64
- provider: "anthropic",
65
- label: "Anthropic credit balance too low",
66
- error:
67
- 'Your credit balance is too low to access the Anthropic API. Please go to https://console.anthropic.com/billing to add credits.',
68
- },
69
- {
70
- provider: "github-copilot",
71
- label: "Copilot daily limit",
72
- error: "You have reached the daily limit for free GitHub Copilot users",
73
- },
74
- {
75
- provider: "anthropic",
76
- label: "Anthropic quota_exceeded snake-case",
77
- error: "quota_exceeded: monthly token allotment used",
78
- },
79
- ];
80
-
81
- /**
82
- * Strings the broadened USAGE_LIMIT_PATTERN MUST NOT match (transient —
83
- * pi-coding-agent retries internally; dashboard shows yellow banner only).
84
- */
85
- export const NON_USAGE_LIMIT_FIXTURES: UsageLimitFixture[] = [
86
- {
87
- provider: "anthropic",
88
- label: "Anthropic transient overloaded",
89
- error: '{"type":"overloaded_error","message":"Anthropic is currently overloaded"}',
90
- },
91
- {
92
- provider: "google",
93
- label: "Gemini 503 transient high demand",
94
- error:
95
- '{"error":{"code":503,"message":"This model is currently experiencing high demand. Spikes in demand are usually temporary. Please try again later.","status":"UNAVAILABLE"}}',
96
- },
97
- {
98
- provider: "unknown",
99
- label: "Generic fetch failed",
100
- error: "fetch failed",
101
- },
102
- {
103
- provider: "unknown",
104
- label: "Generic timeout",
105
- error: "Request timed out.",
106
- },
107
- {
108
- provider: "unknown",
109
- label: "Generic connection error",
110
- error: "Connection error.",
111
- },
112
- {
113
- provider: "unknown",
114
- label: "Tool execution failed (not a provider error)",
115
- error: "tool execution failed",
116
- },
117
- {
118
- provider: "anthropic",
119
- label: "Anthropic 502 Bad Gateway",
120
- error: "502 Bad Gateway",
121
- },
122
- {
123
- provider: "unknown",
124
- label: "Empty error message",
125
- error: "",
126
- },
127
- ];
@@ -1,117 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { UsageLimitOrderer, USAGE_LIMIT_PATTERN } from "../usage-limit-orderer.js";
3
- import { USAGE_LIMIT_FIXTURES, NON_USAGE_LIMIT_FIXTURES } from "./fixtures/usage-limit-error-strings.js";
4
-
5
- describe("UsageLimitOrderer", () => {
6
- it("returns null when no retry was pending", () => {
7
- const o = new UsageLimitOrderer();
8
- const result = o.maybeSynthesize("s1", {
9
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached" }],
10
- });
11
- expect(result).toBeNull();
12
- });
13
-
14
- it("returns null when retry was pending but error is not a usage-limit", () => {
15
- const o = new UsageLimitOrderer();
16
- o.noteRetryStart("s1");
17
- const result = o.maybeSynthesize("s1", {
18
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "tool execution failed" }],
19
- });
20
- expect(result).toBeNull();
21
- });
22
-
23
- it("returns null on a non-error agent_end even with pending retry", () => {
24
- const o = new UsageLimitOrderer();
25
- o.noteRetryStart("s1");
26
- const result = o.maybeSynthesize("s1", {
27
- messages: [{ role: "assistant", stopReason: "end_turn" }],
28
- });
29
- expect(result).toBeNull();
30
- });
31
-
32
- it("synthesizes auto_retry_end on usage_limit_reached when retry was pending", () => {
33
- const o = new UsageLimitOrderer();
34
- o.noteRetryStart("s1");
35
- const result = o.maybeSynthesize("s1", {
36
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached: 5000 RPM" }],
37
- });
38
- expect(result).not.toBeNull();
39
- expect(result!.eventType).toBe("auto_retry_end");
40
- expect(result!.data).toEqual({ success: false, attempt: -1, finalError: "usage_limit_reached: 5000 RPM" });
41
- });
42
-
43
- it.each([
44
- "usage_limit_reached",
45
- "usage_not_included",
46
- "quota_exceeded",
47
- "monthly limit reached for free tier",
48
- "hourly limit hit",
49
- "Your quota will reset after 18h31m10s",
50
- ])("matches usage-limit variant: %s", (msg) => {
51
- expect(USAGE_LIMIT_PATTERN.test(msg)).toBe(true);
52
- });
53
-
54
- it.each([
55
- "rate limit exceeded",
56
- "overloaded_error",
57
- "tool execution failed",
58
- "fetch failed",
59
- "",
60
- ])("does not match non-usage-limit variant: %s", (msg) => {
61
- expect(USAGE_LIMIT_PATTERN.test(msg)).toBe(false);
62
- });
63
-
64
- // Real production-log fixtures — see change: fix-retry-banner-stuck-on-limit-exceeded.
65
- describe("USAGE_LIMIT_PATTERN broadened coverage (production fixtures)", () => {
66
- it.each(USAGE_LIMIT_FIXTURES)("matches terminal: [$provider] $label", ({ error }) => {
67
- expect(USAGE_LIMIT_PATTERN.test(error)).toBe(true);
68
- });
69
-
70
- it.each(NON_USAGE_LIMIT_FIXTURES)("does not match transient: [$provider] $label", ({ error }) => {
71
- expect(USAGE_LIMIT_PATTERN.test(error)).toBe(false);
72
- });
73
- });
74
-
75
- it("clears pending after agent_end (no double-synthesis on subsequent agent_end)", () => {
76
- const o = new UsageLimitOrderer();
77
- o.noteRetryStart("s1");
78
- const first = o.maybeSynthesize("s1", {
79
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached" }],
80
- });
81
- expect(first).not.toBeNull();
82
- // Same payload again — pending was cleared, so no synthesis.
83
- const second = o.maybeSynthesize("s1", {
84
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached" }],
85
- });
86
- expect(second).toBeNull();
87
- });
88
-
89
- it("noteRetryEnd clears pending so subsequent agent_end does not synthesize", () => {
90
- const o = new UsageLimitOrderer();
91
- o.noteRetryStart("s1");
92
- o.noteRetryEnd("s1");
93
- expect(o.hasPending("s1")).toBe(false);
94
- const result = o.maybeSynthesize("s1", {
95
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached" }],
96
- });
97
- expect(result).toBeNull();
98
- });
99
-
100
- it("scopes pending state per-session", () => {
101
- const o = new UsageLimitOrderer();
102
- o.noteRetryStart("s1");
103
- expect(o.hasPending("s2")).toBe(false);
104
- const result = o.maybeSynthesize("s2", {
105
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached" }],
106
- });
107
- expect(result).toBeNull();
108
- });
109
-
110
- it("returns null on missing or empty messages array", () => {
111
- const o = new UsageLimitOrderer();
112
- o.noteRetryStart("s1");
113
- expect(o.maybeSynthesize("s1", {})).toBeNull();
114
- o.noteRetryStart("s1");
115
- expect(o.maybeSynthesize("s1", { messages: [] })).toBeNull();
116
- });
117
- });
@@ -1,145 +0,0 @@
1
- /**
2
- * Tests for the jj half of vcs-info.ts. The file probes both git AND jj;
3
- * git-only assertions live in `vcs-info.test.ts` and jj-only assertions
4
- * live here so each suite can mock the relevant tool module independently.
5
- *
6
- * Per spec scenario "Non-jj cwd incurs no jj subprocess cost", the probe
7
- * MUST short-circuit on `.jj/`-absent BEFORE invoking any `jj` recipe.
8
- *
9
- * See change: add-jj-workspace-plugin.
10
- */
11
- import { describe, it, expect, vi, beforeEach } from "vitest";
12
- import os from "node:os";
13
- import path from "node:path";
14
- import fs from "node:fs";
15
-
16
- const { workspaceRoot, workspaceList } = vi.hoisted(() => ({
17
- workspaceRoot: vi.fn(),
18
- workspaceList: vi.fn(),
19
- }));
20
-
21
- vi.mock("@blackbelt-technology/pi-dashboard-shared/platform/jj.js", async () => {
22
- // Import the real module's pure parsers; only mock the I/O entry points.
23
- const real = await vi.importActual<
24
- typeof import("@blackbelt-technology/pi-dashboard-shared/platform/jj.js")
25
- >("@blackbelt-technology/pi-dashboard-shared/platform/jj.js");
26
- return {
27
- ...real,
28
- workspaceRoot,
29
- workspaceList,
30
- };
31
- });
32
-
33
- // Tool registry mock — make `jj` resolvable by default.
34
- vi.mock("@blackbelt-technology/pi-dashboard-shared/tool-registry/index.js", () => ({
35
- getDefaultRegistry: () => ({
36
- resolve: (_name: string) => ({ ok: true, path: "/usr/local/bin/jj", source: "system", tried: [] }),
37
- }),
38
- }));
39
-
40
- import { gatherJjInfo, _resetJjAvailableForTests } from "../vcs-info.js";
41
-
42
- describe("gatherJjInfo", () => {
43
- beforeEach(() => {
44
- workspaceRoot.mockReset();
45
- workspaceList.mockReset();
46
- _resetJjAvailableForTests();
47
- });
48
-
49
- it("returns undefined when .jj/ does not exist (no jj subprocess spawned)", () => {
50
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "vcs-info-jj-"));
51
- expect(gatherJjInfo(tmp)).toBeUndefined();
52
- // Crucial: NEITHER recipe was called.
53
- expect(workspaceRoot).not.toHaveBeenCalled();
54
- expect(workspaceList).not.toHaveBeenCalled();
55
- });
56
-
57
- it("returns isJjRepo=true with workspace name when .jj/ exists and jj responds", () => {
58
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "vcs-info-jj-"));
59
- fs.mkdirSync(path.join(tmp, ".jj"));
60
-
61
- workspaceRoot.mockReturnValue({ ok: true, value: tmp });
62
- workspaceList.mockReturnValue({
63
- ok: true,
64
- value: "default: aaaa 1111 (no description set)\n",
65
- });
66
-
67
- const state = gatherJjInfo(tmp);
68
- expect(state).toBeDefined();
69
- expect(state!.isJjRepo).toBe(true);
70
- expect(state!.workspaceRoot).toBe(tmp);
71
- expect(state!.workspaceName).toBe("default");
72
- expect(state!.isColocated).toBe(false);
73
- expect(state!.lastError).toBeUndefined();
74
- });
75
-
76
- it("flags isColocated=true when both .jj/ and .git/ exist", () => {
77
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "vcs-info-jj-"));
78
- fs.mkdirSync(path.join(tmp, ".jj"));
79
- fs.mkdirSync(path.join(tmp, ".git"));
80
-
81
- workspaceRoot.mockReturnValue({ ok: true, value: tmp });
82
- workspaceList.mockReturnValue({
83
- ok: true,
84
- value: "default: aaaa 1111 (no description set)\n",
85
- });
86
-
87
- expect(gatherJjInfo(tmp)?.isColocated).toBe(true);
88
- });
89
-
90
- it("picks `default` workspace when multiple are listed", () => {
91
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "vcs-info-jj-"));
92
- fs.mkdirSync(path.join(tmp, ".jj"));
93
-
94
- workspaceRoot.mockReturnValue({ ok: true, value: tmp });
95
- workspaceList.mockReturnValue({
96
- ok: true,
97
- value:
98
- "agent-1: tttt 2222 (empty) (no description set)\n" +
99
- "default: aaaa 1111 (no description set)\n",
100
- });
101
-
102
- expect(gatherJjInfo(tmp)?.workspaceName).toBe("default");
103
- });
104
-
105
- it("surfaces lastError when workspaceRoot fails non-trivially", () => {
106
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "vcs-info-jj-"));
107
- fs.mkdirSync(path.join(tmp, ".jj"));
108
-
109
- workspaceRoot.mockReturnValue({
110
- ok: false,
111
- error: { kind: "exit", code: 1, signal: null, stdout: "", stderr: "fatal: not in a workspace" },
112
- });
113
- workspaceList.mockReturnValue({ ok: true, value: "" });
114
-
115
- const state = gatherJjInfo(tmp);
116
- expect(state?.isJjRepo).toBe(true);
117
- expect(state?.lastError).toContain("fatal");
118
- });
119
- });
120
-
121
- describe("gatherJjInfo when jj is not on PATH", () => {
122
- beforeEach(() => {
123
- workspaceRoot.mockReset();
124
- workspaceList.mockReset();
125
- _resetJjAvailableForTests();
126
- });
127
-
128
- it("returns undefined and never reads .jj/ when registry says jj is unavailable", () => {
129
- // Re-mock the registry for this scope only.
130
- vi.doMock("@blackbelt-technology/pi-dashboard-shared/tool-registry/index.js", () => ({
131
- getDefaultRegistry: () => ({
132
- resolve: () => ({ ok: false, path: undefined, tried: [] }),
133
- }),
134
- }));
135
-
136
- // Since the test file already imported gatherJjInfo before the doMock,
137
- // we just rely on the cached `jjAvailable` flag; reset it and let the
138
- // real registry mock at the file level (which says ok:true) drive
139
- // behavior. This case is therefore covered structurally by the
140
- // first test in the previous describe (`.jj/` absent → no calls);
141
- // a fully-isolated "registry says no" test is deferred until we
142
- // refactor the registry probe to be injectable.
143
- expect(true).toBe(true);
144
- });
145
- });
@@ -1,93 +0,0 @@
1
- /**
2
- * Usage-limit event orderer.
3
- *
4
- * Tracks per-session whether an `auto_retry_start` was forwarded without a
5
- * matching `auto_retry_end`, and — when an `agent_end` arrives whose terminal
6
- * assistant message has a usage-limit / quota errorMessage — synthesizes an
7
- * `auto_retry_end { success: false }` to emit BEFORE the `agent_end`.
8
- *
9
- * Pure logic (no I/O). The bridge wires this into its forwarding pipeline.
10
- *
11
- * See change: fix-provider-retry-infinite-loop.
12
- */
13
-
14
- /**
15
- * Matches terminal billing/quota error categories observed in production
16
- * across providers. The orderer uses this to surface a synthesized
17
- * `auto_retry_end{success:false}` BEFORE the bridge forwards `agent_end`,
18
- * so the dashboard's `retryState` clears before `lastError` is set.
19
- *
20
- * Coverage (verified via fixture tests):
21
- * - Codex / Anthropic / generic: usage_limit_reached, usage_not_included,
22
- * quota_exceeded, credit_balance, insufficient_quota, monthly limit,
23
- * daily limit, hourly limit, "reset after Nh|Nm|Ns".
24
- * - Gemini / Google: "monthly spending cap", "spending cap",
25
- * RESOURCE_EXHAUSTED.
26
- * - Generic catch-all for "exceeded ... (quota|cap|spending)" within
27
- * ~40 chars (avoids a string with no terminal-meaning context).
28
- *
29
- * See change: fix-retry-banner-stuck-on-limit-exceeded.
30
- */
31
- export const USAGE_LIMIT_PATTERN =
32
- /usage[_ ]limit[_ ]reached|usage_not_included|insufficient_quota|credit[_ ]balance|quota[_ ]exceeded|resource[_ ]exhausted|monthly[_ ]limit|monthly[_ ]spending[_ ]cap|hourly[_ ]limit|daily[_ ]limit|spending[_ ]cap|exceeded[^"]{0,40}(quota|cap|spending)|reset after \d+[hms]/i;
33
-
34
- export interface SyntheticEventEnvelope {
35
- eventType: "auto_retry_end";
36
- data: { success: false; attempt: -1; finalError: string };
37
- }
38
-
39
- export class UsageLimitOrderer {
40
- /** sessionId → true while a retry is in flight (no auto_retry_end seen yet). */
41
- private pending = new Set<string>();
42
-
43
- /**
44
- * Notify the orderer of an outbound `auto_retry_start` for sessionId.
45
- */
46
- noteRetryStart(sessionId: string): void {
47
- this.pending.add(sessionId);
48
- }
49
-
50
- /**
51
- * Notify the orderer of an outbound `auto_retry_end` for sessionId.
52
- * Subsequent `agent_end` events will not synthesize unless a new retry
53
- * has been started.
54
- */
55
- noteRetryEnd(sessionId: string): void {
56
- this.pending.delete(sessionId);
57
- }
58
-
59
- /**
60
- * Inspect an `agent_end` payload. If the terminal message has a
61
- * usage-limit error AND we have an unmatched retry-start for this session,
62
- * return the synthetic event the bridge should forward BEFORE the agent_end.
63
- *
64
- * Returns null when no synthesis is needed. Always clears the pending flag
65
- * after a terminal agent_end (errored or not) so we don't double-synthesize.
66
- */
67
- maybeSynthesize(
68
- sessionId: string,
69
- agentEndData: Record<string, unknown> | undefined,
70
- ): SyntheticEventEnvelope | null {
71
- const wasPending = this.pending.has(sessionId);
72
- // Always clear on agent_end: a terminal turn ends any retry tracking.
73
- this.pending.delete(sessionId);
74
-
75
- if (!wasPending || !agentEndData) return null;
76
- const messages = agentEndData.messages;
77
- if (!Array.isArray(messages) || messages.length === 0) return null;
78
- const last = messages[messages.length - 1] as Record<string, unknown> | undefined;
79
- if (!last || last.stopReason !== "error") return null;
80
- const errorMessage = typeof last.errorMessage === "string" ? last.errorMessage : "";
81
- if (!errorMessage || !USAGE_LIMIT_PATTERN.test(errorMessage)) return null;
82
-
83
- return {
84
- eventType: "auto_retry_end",
85
- data: { success: false, attempt: -1, finalError: errorMessage },
86
- };
87
- }
88
-
89
- /** Test-only: inspect pending state. */
90
- hasPending(sessionId: string): boolean {
91
- return this.pending.has(sessionId);
92
- }
93
- }