@blackbelt-technology/pi-dashboard-extension 0.5.3 → 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 (258) 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 +50 -0
  94. package/src/__tests__/bridge-followup-chat-order.test.ts +215 -0
  95. package/src/__tests__/bridge-followup-multi-entry.test.ts +202 -0
  96. package/src/__tests__/bridge-followup-mutation.test.ts +217 -0
  97. package/src/__tests__/bridge-followup-queue-drain.test.ts +266 -0
  98. package/src/__tests__/bridge-hasui-flip.test.ts +109 -0
  99. package/src/__tests__/bridge-no-queue-mutation.test.ts +112 -0
  100. package/src/__tests__/bridge-plugin-emit-event.test.ts +44 -0
  101. package/src/__tests__/bridge-queue-update-forward.test.ts +77 -0
  102. package/src/__tests__/bridge-shadow-queue-gate.test.ts +299 -0
  103. package/src/__tests__/bridge-shutdown-reset.test.ts +159 -0
  104. package/src/__tests__/bridge-slash-command-routing.test.ts +127 -31
  105. package/src/__tests__/bridge-stop-after-turn.test.ts +72 -0
  106. package/src/__tests__/bridge-system-followup.test.ts +163 -0
  107. package/src/__tests__/bridge-thinking-level-select.test.ts +68 -0
  108. package/src/__tests__/browser-skill-registered.test.ts +84 -0
  109. package/src/__tests__/build-provider-catalogue.test.ts +35 -1
  110. package/src/__tests__/command-handler.test.ts +427 -29
  111. package/src/__tests__/commit-draft.test.ts +100 -0
  112. package/src/__tests__/connection-dropped-frames.test.ts +78 -0
  113. package/src/__tests__/custom-provider-apikey-roundtrip.test.ts +128 -0
  114. package/src/__tests__/cwd-missing-probe.test.ts +82 -0
  115. package/src/__tests__/dashboard-commands-shipped.test.ts +53 -0
  116. package/src/__tests__/dashboard-context-injector.test.ts +190 -0
  117. package/src/__tests__/doctor/checks.test.ts +121 -0
  118. package/src/__tests__/doctor/modules.test.ts +64 -0
  119. package/src/__tests__/doctor/provenance-hash.test.ts +94 -0
  120. package/src/__tests__/doctor/router.test.ts +143 -0
  121. package/src/__tests__/empty-actionable-guard-config.test.ts +32 -0
  122. package/src/__tests__/empty-actionable-guard.test.ts +73 -0
  123. package/src/__tests__/enrich-model-metadata.test.ts +21 -0
  124. package/src/__tests__/extension-slash-command-detection.test.ts +37 -1
  125. package/src/__tests__/filter-enabled-models.test.ts +151 -0
  126. package/src/__tests__/fixtures/turn-actionability-fixtures.ts +69 -0
  127. package/src/__tests__/git-info-status.test.ts +73 -0
  128. package/src/__tests__/git-poll.test.ts +69 -0
  129. package/src/__tests__/markdown-image-inliner.test.ts +37 -0
  130. package/src/__tests__/model-resolve.test.ts +379 -0
  131. package/src/__tests__/pi-version-tracker.test.ts +109 -0
  132. package/src/__tests__/process-scanner.test.ts +112 -22
  133. package/src/__tests__/project-init-detect-stack.test.ts +61 -0
  134. package/src/__tests__/project-init-dox-kb-config.test.ts +53 -0
  135. package/src/__tests__/project-init-profiles.test.ts +84 -0
  136. package/src/__tests__/project-init-scaffold.test.ts +139 -0
  137. package/src/__tests__/project-init-seed-doctrine.test.ts +100 -0
  138. package/src/__tests__/project-trust.test.ts +92 -0
  139. package/src/__tests__/prompt-expander.test.ts +191 -1
  140. package/src/__tests__/provider-register-reload.test.ts +36 -6
  141. package/src/__tests__/provider-register-thinking-levels.test.ts +51 -0
  142. package/src/__tests__/retry-tracker.test.ts +75 -70
  143. package/src/__tests__/role-manager.test.ts +585 -0
  144. package/src/__tests__/role-model-tools-registry-readiness.test.ts +114 -0
  145. package/src/__tests__/role-model-tools.test.ts +229 -0
  146. package/src/__tests__/search-files-completeness.test.ts +111 -0
  147. package/src/__tests__/search-files-ranking.test.ts +168 -0
  148. package/src/__tests__/server-auto-start.test.ts +121 -4
  149. package/src/__tests__/server-launcher-launch.test.ts +24 -6
  150. package/src/__tests__/server-launcher.test.ts +19 -2
  151. package/src/__tests__/session-sync.test.ts +36 -0
  152. package/src/__tests__/source-detector.test.ts +15 -0
  153. package/src/__tests__/subagent-frame-buffer.test.ts +239 -0
  154. package/src/__tests__/tool-result-image-inliner.test.ts +206 -0
  155. package/src/__tests__/tui-prompt-adapter.test.ts +70 -64
  156. package/src/__tests__/turn-actionability.test.ts +86 -0
  157. package/src/__tests__/vcs-info.test.ts +145 -4
  158. package/src/__tests__/visibility-intent.test.ts +43 -0
  159. package/src/abort-latch.ts +55 -0
  160. package/src/abort-latch.ts.AGENTS.md +3 -0
  161. package/src/agent-settled.ts +72 -0
  162. package/src/agent-settled.ts.AGENTS.md +3 -0
  163. package/src/artifact-roots.ts +73 -0
  164. package/src/artifact-roots.ts.AGENTS.md +3 -0
  165. package/src/ask-user-attachments.ts +121 -0
  166. package/src/ask-user-attachments.ts.AGENTS.md +3 -0
  167. package/src/ask-user-tool.ts +56 -58
  168. package/src/ask-user-tool.ts.AGENTS.md +3 -0
  169. package/src/auto-session-namer.ts +334 -0
  170. package/src/auto-session-namer.ts.AGENTS.md +3 -0
  171. package/src/bridge-context.ts +86 -8
  172. package/src/bridge-context.ts.AGENTS.md +3 -0
  173. package/src/bridge-default-model-gate.ts +48 -0
  174. package/src/bridge-default-model-gate.ts.AGENTS.md +3 -0
  175. package/src/bridge.ts +1373 -213
  176. package/src/bridge.ts.AGENTS.md +3 -0
  177. package/src/canvas-tool.ts +107 -0
  178. package/src/command-handler.ts +527 -42
  179. package/src/command-handler.ts.AGENTS.md +3 -0
  180. package/src/commit-draft-agent.ts +114 -0
  181. package/src/commit-draft-agent.ts.AGENTS.md +3 -0
  182. package/src/commit-draft.ts +136 -0
  183. package/src/commit-draft.ts.AGENTS.md +3 -0
  184. package/src/connection.ts +32 -1
  185. package/src/connection.ts.AGENTS.md +3 -0
  186. package/src/dashboard-context-injector.ts +124 -0
  187. package/src/dashboard-context-injector.ts.AGENTS.md +3 -0
  188. package/src/dashboard-default-adapter.ts +5 -0
  189. package/src/dashboard-default-adapter.ts.AGENTS.md +3 -0
  190. package/src/dev-build.ts.AGENTS.md +3 -0
  191. package/src/empty-actionable-guard-config.ts +32 -0
  192. package/src/empty-actionable-guard-config.ts.AGENTS.md +3 -0
  193. package/src/empty-actionable-guard.ts +90 -0
  194. package/src/empty-actionable-guard.ts.AGENTS.md +3 -0
  195. package/src/event-forwarder.ts.AGENTS.md +3 -0
  196. package/src/flow-event-wiring.ts +4 -14
  197. package/src/flow-event-wiring.ts.AGENTS.md +3 -0
  198. package/src/git-link-builder.ts.AGENTS.md +3 -0
  199. package/src/git-poll.ts +38 -0
  200. package/src/git-poll.ts.AGENTS.md +3 -0
  201. package/src/hasui-flip.ts +56 -0
  202. package/src/hasui-flip.ts.AGENTS.md +3 -0
  203. package/src/markdown-image-inliner.ts +45 -2
  204. package/src/markdown-image-inliner.ts.AGENTS.md +3 -0
  205. package/src/model-tracker.ts +145 -19
  206. package/src/model-tracker.ts.AGENTS.md +3 -0
  207. package/src/multiselect-decode.ts.AGENTS.md +3 -0
  208. package/src/multiselect-list.ts.AGENTS.md +3 -0
  209. package/src/multiselect-polyfill.ts.AGENTS.md +3 -0
  210. package/src/process-metrics.ts.AGENTS.md +3 -0
  211. package/src/process-scanner.ts +114 -103
  212. package/src/process-scanner.ts.AGENTS.md +3 -0
  213. package/src/project-init/AGENTS.md +12 -0
  214. package/src/project-init/detect-stack.ts +146 -0
  215. package/src/project-init/dox-kb-config.ts +47 -0
  216. package/src/project-init/profiles.ts +135 -0
  217. package/src/project-init/scaffold.ts +192 -0
  218. package/src/project-init/seed-doctrine.ts +95 -0
  219. package/src/project-trust.ts +63 -0
  220. package/src/project-trust.ts.AGENTS.md +3 -0
  221. package/src/prompt-bus.ts +25 -1
  222. package/src/prompt-bus.ts.AGENTS.md +3 -0
  223. package/src/prompt-expander.ts +238 -37
  224. package/src/prompt-expander.ts.AGENTS.md +3 -0
  225. package/src/provider-register.ts +323 -54
  226. package/src/provider-register.ts.AGENTS.md +3 -0
  227. package/src/retry-tracker.ts +64 -39
  228. package/src/retry-tracker.ts.AGENTS.md +3 -0
  229. package/src/role-manager.ts +436 -0
  230. package/src/role-manager.ts.AGENTS.md +3 -0
  231. package/src/role-model-tools.ts +301 -0
  232. package/src/role-model-tools.ts.AGENTS.md +3 -0
  233. package/src/server-auto-start.ts +59 -23
  234. package/src/server-auto-start.ts.AGENTS.md +3 -0
  235. package/src/server-launcher.ts +56 -16
  236. package/src/server-launcher.ts.AGENTS.md +3 -0
  237. package/src/session-sync.ts +111 -15
  238. package/src/session-sync.ts.AGENTS.md +3 -0
  239. package/src/slash-dispatch.ts +32 -15
  240. package/src/slash-dispatch.ts.AGENTS.md +3 -0
  241. package/src/source-detector.ts +13 -5
  242. package/src/source-detector.ts.AGENTS.md +3 -0
  243. package/src/subagent-frame-buffer.ts +220 -0
  244. package/src/subagent-frame-buffer.ts.AGENTS.md +3 -0
  245. package/src/tool-result-image-inliner.ts +204 -0
  246. package/src/tool-result-image-inliner.ts.AGENTS.md +3 -0
  247. package/src/tui-prompt-adapter.ts +123 -0
  248. package/src/tui-prompt-adapter.ts.AGENTS.md +3 -0
  249. package/src/turn-actionability.ts +117 -0
  250. package/src/turn-actionability.ts.AGENTS.md +3 -0
  251. package/src/ui-modules.ts.AGENTS.md +3 -0
  252. package/src/vcs-info.ts +91 -129
  253. package/src/vcs-info.ts.AGENTS.md +3 -0
  254. package/src/visibility-intent.ts +34 -0
  255. package/src/visibility-intent.ts.AGENTS.md +3 -0
  256. package/src/__tests__/usage-limit-orderer.test.ts +0 -105
  257. package/src/__tests__/vcs-info-jj.test.ts +0 -145
  258. package/src/usage-limit-orderer.ts +0 -76
package/src/vcs-info.ts CHANGED
@@ -1,20 +1,14 @@
1
1
  /**
2
- * VCS info gathering — detects git branch/remote/PR AND jj workspace state.
2
+ * VCS info gathering — detects git branch/remote/PR and worktree state.
3
3
  * Delegates to shared platform tool modules so there's no inline execSync
4
4
  * and every call benefits from the runner's safety defaults (windowsHide,
5
5
  * timeout, tolerated exit codes).
6
6
  *
7
- * jj probing is fast-path-gated: when `<cwd>/.jj/` doesn't exist, NO `jj`
8
- * subprocess is spawned. Only sessions inside a jj repo pay the probe cost.
9
- *
10
- * See changes: platform-command-executor, add-jj-workspace-plugin.
7
+ * See change: platform-command-executor.
11
8
  */
12
- import { existsSync } from "node:fs";
13
9
  import path from "node:path";
14
10
  import * as git from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
15
- import * as jj from "@blackbelt-technology/pi-dashboard-shared/platform/jj.js";
16
- import { getDefaultRegistry } from "@blackbelt-technology/pi-dashboard-shared/tool-registry/index.js";
17
- import type { JjState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
11
+ import type { GitStatus, GitWorktreeInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
18
12
  import { buildGitLinks, type GitLinks } from "./git-link-builder.js";
19
13
 
20
14
  export interface GitInfo {
@@ -22,6 +16,36 @@ export interface GitInfo {
22
16
  gitBranchUrl?: string;
23
17
  gitPrNumber?: number;
24
18
  gitPrUrl?: string;
19
+ /**
20
+ * Worktree identity (mainPath, name) when cwd is a git worktree.
21
+ * Undefined for the main checkout and for any cwd where the rev-parse
22
+ * pair fails. Never carries `base` — that field is post-create
23
+ * metadata supplied by the server.
24
+ */
25
+ gitWorktree?: GitWorktreeInfo;
26
+ }
27
+
28
+ /**
29
+ * Detect whether `cwd` is a git repository as a tri-state.
30
+ *
31
+ * Uses the `git.isGitRepo()` `Result` (NOT `isGitRepoOr`) to distinguish
32
+ * *confirmed non-git* from *unknown*:
33
+ * - `ok` → the boolean value (`git rev-parse --is-inside-work-tree`);
34
+ * - `error kind:"exit" code:128` → `false` (git ran and definitively
35
+ * reported "not a repository");
36
+ * - any other failure (missing binary, timeout, signal, other exit code)
37
+ * → `undefined` (unknown).
38
+ *
39
+ * Returns `undefined` — never `false` — on an inconclusive probe so a real
40
+ * git repo whose probe failed never loses its truthy signal (the client
41
+ * gate hides the `+Worktree` button only on a confirmed `false`).
42
+ * See change: gate-session-worktree-button-on-git.
43
+ */
44
+ export function detectIsGitRepo(cwd: string): boolean | undefined {
45
+ const res = git.isGitRepo({ cwd });
46
+ if (res.ok) return res.value;
47
+ if (res.error.kind === "exit" && res.error.code === 128) return false;
48
+ return undefined;
25
49
  }
26
50
 
27
51
  /** Detect the current git branch. Returns short SHA for detached HEAD. */
@@ -45,6 +69,62 @@ export function detectPrNumber(cwd: string): number | undefined {
45
69
  return git.prNumberOr({ cwd });
46
70
  }
47
71
 
72
+ /**
73
+ * Detect whether `cwd` is a git worktree (not the main checkout).
74
+ *
75
+ * Uses the canonical signal: `git rev-parse --git-common-dir` resolves
76
+ * to a path OUTSIDE `git rev-parse --show-toplevel` when the cwd is a
77
+ * worktree (because `--git-common-dir` points back at the main repo's
78
+ * `.git/`, while `--show-toplevel` is the worktree's own root).
79
+ *
80
+ * Returns `undefined` when:
81
+ * - either rev-parse invocation fails (not a repo, git missing,
82
+ * permission, etc.),
83
+ * - the cwd IS the main checkout (`commonDir` is inside `topLevel`).
84
+ *
85
+ * Resolution is path-prefix based with case-folding on Windows/macOS
86
+ * via the shared platform helpers; relative `commonDir` outputs (which
87
+ * happen on some git versions when cwd === main repo) are normalised
88
+ * to absolute via `path.resolve(cwd, commonDir)`.
89
+ */
90
+ export function detectWorktree(cwd: string): GitWorktreeInfo | undefined {
91
+ const commonDirRaw = git.commonDirOr({ cwd });
92
+ const topLevel = git.toplevelOr({ cwd });
93
+ if (!commonDirRaw || !topLevel) return undefined;
94
+
95
+ // Normalise commonDir: when it's relative (`.git`), resolve against cwd.
96
+ // When absolute, leave as-is.
97
+ const commonDirAbs = path.isAbsolute(commonDirRaw)
98
+ ? commonDirRaw
99
+ : path.resolve(cwd, commonDirRaw);
100
+
101
+ // Main checkout: commonDir == <toplevel>/.git (or anywhere inside toplevel).
102
+ // Worktree: commonDir == <main-repo>/.git, which is NOT inside the
103
+ // worktree's toplevel.
104
+ const topWithSep = topLevel.endsWith(path.sep) ? topLevel : topLevel + path.sep;
105
+ const insideToplevel =
106
+ commonDirAbs === topLevel || commonDirAbs.startsWith(topWithSep);
107
+ if (insideToplevel) return undefined;
108
+
109
+ // `commonDir` for a worktree is `<main-repo>/.git` — the parent dir is
110
+ // the main worktree root.
111
+ const mainPath = path.dirname(commonDirAbs);
112
+ const name = path.basename(cwd);
113
+ return { mainPath, name };
114
+ }
115
+
116
+ /**
117
+ * Gather working-tree dirtiness + upstream drift for `cwd` via one
118
+ * `git status --porcelain=v2 --branch` call. Returns `undefined` on an
119
+ * inconclusive probe (git missing, not a repo, timeout) so the broadcast
120
+ * omits the field rather than sending a false all-clean status.
121
+ * See change: add-session-uncommitted-indicator-and-commit.
122
+ */
123
+ export function gatherGitStatus(cwd: string): GitStatus | undefined {
124
+ const res = git.gitStatusV2({ cwd });
125
+ return res.ok ? res.value : undefined;
126
+ }
127
+
48
128
  /** Gather all git info for a directory. Returns undefined if not a git repo. */
49
129
  export function gatherGitInfo(cwd: string): GitInfo | undefined {
50
130
  const branch = detectBranch(cwd);
@@ -52,6 +132,7 @@ export function gatherGitInfo(cwd: string): GitInfo | undefined {
52
132
 
53
133
  const remoteUrl = detectRemoteUrl(cwd);
54
134
  const prNumber = detectPrNumber(cwd);
135
+ const gitWorktree = detectWorktree(cwd);
55
136
 
56
137
  const links: GitLinks = remoteUrl ? buildGitLinks(remoteUrl, branch, prNumber) : {};
57
138
 
@@ -60,125 +141,6 @@ export function gatherGitInfo(cwd: string): GitInfo | undefined {
60
141
  gitBranchUrl: links.branchUrl,
61
142
  gitPrNumber: prNumber,
62
143
  gitPrUrl: links.prUrl,
63
- };
64
- }
65
-
66
- // ── Jujutsu probing ────────────────────────────────────────────────────────
67
-
68
- /**
69
- * Module-level cache: result of resolving `jj` once per process. The tool
70
- * registry already memoizes resolutions, but reading it on every probe tick
71
- * adds noise to traces. Single read on first probe, sticky for the process.
72
- */
73
- let jjAvailable: boolean | undefined;
74
-
75
- function isJjResolvable(): boolean {
76
- if (jjAvailable !== undefined) return jjAvailable;
77
- try {
78
- const reg = getDefaultRegistry();
79
- const res = reg.resolve("jj");
80
- jjAvailable = res.ok;
81
- } catch {
82
- jjAvailable = false;
83
- }
84
- return jjAvailable;
85
- }
86
-
87
- /**
88
- * Test-only hook to reset the jj-availability cache.
89
- * Production code MUST NOT call this.
90
- */
91
- export function _resetJjAvailableForTests(): void {
92
- jjAvailable = undefined;
93
- }
94
-
95
- /**
96
- * Gather jj workspace state for a directory.
97
- * Returns `undefined` when:
98
- * - `jj` is not resolvable via the tool registry, OR
99
- * - `.jj/` does not exist in cwd (fast path, no subprocess spawn).
100
- *
101
- * Returns a populated `JjState` when both conditions are met. Errors during
102
- * `jj` invocation surface in `lastError` rather than throwing; the rest of
103
- * the fields fall back to undefined / empty.
104
- *
105
- * Per spec scenario "Non-jj cwd incurs no jj subprocess cost".
106
- */
107
- export function gatherJjInfo(cwd: string): JjState | undefined {
108
- if (!isJjResolvable()) return undefined;
109
- if (!existsSync(path.join(cwd, ".jj"))) return undefined;
110
-
111
- const isColocated = existsSync(path.join(cwd, ".git"));
112
-
113
- // Resolve workspace name + root. Errors are caught and surfaced via
114
- // lastError so callers always get *some* JjState rather than nothing.
115
- let workspaceName: string | undefined;
116
- let workspaceRoot: string | undefined;
117
- let lastError: string | undefined;
118
-
119
- const rootResult = jj.workspaceRoot({ cwd });
120
- if (rootResult.ok) {
121
- workspaceRoot = rootResult.value;
122
- } else if (rootResult.error.kind !== "not-found") {
123
- lastError = describeJjError(rootResult.error);
124
- }
125
-
126
- // Workspace name: parse `jj workspace list` and match by working-copy
127
- // path. The CLI does not include the path in list output, so we fall
128
- // back to identifying the workspace via the `<name>@` revset matching
129
- // the workspace root. For now: if there's only one workspace, use
130
- // its name; otherwise default to "default" if found, else first entry.
131
- // (Multi-workspace name disambiguation tracked as Phase 4 follow-up.)
132
- const listResult = jj.workspaceList({ cwd });
133
- if (listResult.ok) {
134
- const entries = jj.parseWorkspaceList(listResult.value);
135
- if (entries.length === 1) {
136
- workspaceName = entries[0]?.name;
137
- } else if (entries.length > 1) {
138
- workspaceName = entries.find((e) => e.name === "default")?.name
139
- ?? entries[0]?.name;
140
- }
141
- } else if (listResult.error.kind !== "not-found" && !lastError) {
142
- lastError = describeJjError(listResult.error);
143
- }
144
-
145
- return {
146
- isJjRepo: true,
147
- isColocated,
148
- workspaceName,
149
- workspaceRoot,
150
- lastError,
151
- };
152
- }
153
-
154
- function describeJjError(
155
- error: { kind: string; [k: string]: unknown },
156
- ): string {
157
- if (error.kind === "timeout") return "jj probe timed out";
158
- if (error.kind === "exit") {
159
- const stderr = typeof error.stderr === "string" ? error.stderr.trim() : "";
160
- return stderr.split("\n")[0] || `jj exited ${String(error.code)}`;
161
- }
162
- if (error.kind === "spawn-failure") {
163
- return typeof error.message === "string" ? error.message : "spawn failed";
164
- }
165
- return error.kind;
166
- }
167
-
168
- // ── Combined VCS gather ────────────────────────────────────────────────────
169
-
170
- export interface VcsInfo {
171
- git?: GitInfo;
172
- jj?: JjState;
173
- }
174
-
175
- /**
176
- * Convenience helper that gathers both git and jj info in one call.
177
- * Used by the bridge's per-session 30 s probe tick.
178
- */
179
- export function gatherVcsInfo(cwd: string): VcsInfo {
180
- return {
181
- git: gatherGitInfo(cwd),
182
- jj: gatherJjInfo(cwd),
144
+ gitWorktree,
183
145
  };
184
146
  }
@@ -0,0 +1,3 @@
1
+ # vcs-info.ts — index
2
+
3
+ Gathers git branch/remote/PR/worktree info via shared platform git helpers. Exports `GitInfo`, `detectBranch`, `detectRemoteUrl`, `detectPrNumber`, `detectWorktree`, `detectIsGitRepo`, `gatherGitInfo`. `detectWorktree` compares `--git-common-dir` vs `--show-toplevel`. `detectIsGitRepo` returns tri-state `boolean\|undefined` from `git.isGitRepo()` Result: ok→value, exit-128→false, else→undefined (never false on inconclusive probe); attached to `session_register` (session-sync.ts, bridge.ts). Builds links via `buildGitLinks`. Returns undefined if not a repo. Exports `gatherGitStatus(cwd)` → `GitStatus\|undefined` via shared `git.gitStatusV2` (`git status --porcelain=v2 --branch`). See changes: gate-session-worktree-button-on-git, add-session-uncommitted-indicator-and-commit.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Resolve the optional `session_register` visibility fields the bridge
3
+ * forwards to the server (fact-forwarding only; the server decides what to
4
+ * do with them). See change: auto-hide-headless-worker-sessions.
5
+ */
6
+
7
+ /**
8
+ * Map the bridge's environment to an explicit visibility override.
9
+ * `PI_DASHBOARD_VISIBLE` wins over `PI_DASHBOARD_HIDDEN` (explicit show beats
10
+ * hide). Absent ⇒ undefined (server falls back to its auto-hide heuristic).
11
+ */
12
+ export function resolveVisibilityIntent(
13
+ env: NodeJS.ProcessEnv,
14
+ ): "hidden" | "visible" | undefined {
15
+ if (env.PI_DASHBOARD_VISIBLE) return "visible";
16
+ if (env.PI_DASHBOARD_HIDDEN) return "hidden";
17
+ return undefined;
18
+ }
19
+
20
+ /**
21
+ * Build the optional `{ hasUI?, visibilityIntent? }` slice of a
22
+ * `session_register` payload. Fields are omitted (not set to undefined) when
23
+ * absent so legacy/back-compat behavior is preserved on the wire.
24
+ */
25
+ export function buildVisibilityRegisterFields(
26
+ hasUI: boolean | undefined,
27
+ env: NodeJS.ProcessEnv,
28
+ ): { hasUI?: boolean; visibilityIntent?: "hidden" | "visible" } {
29
+ const fields: { hasUI?: boolean; visibilityIntent?: "hidden" | "visible" } = {};
30
+ if (hasUI !== undefined) fields.hasUI = hasUI;
31
+ const intent = resolveVisibilityIntent(env);
32
+ if (intent) fields.visibilityIntent = intent;
33
+ return fields;
34
+ }
@@ -0,0 +1,3 @@
1
+ # visibility-intent.ts — index
2
+
3
+ Resolves `session_register` visibility fields. Exports `resolveVisibilityIntent`, `buildVisibilityRegisterFields`. `PI_DASHBOARD_VISIBLE` beats `PI_DASHBOARD_HIDDEN`; absent ⇒ undefined (server auto-hide heuristic). Emits `{ hasUI?, visibilityIntent? }` slice omitting absent fields. See change auto-hide-headless-worker-sessions.
@@ -1,105 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { UsageLimitOrderer, USAGE_LIMIT_PATTERN } from "../usage-limit-orderer.js";
3
-
4
- describe("UsageLimitOrderer", () => {
5
- it("returns null when no retry was pending", () => {
6
- const o = new UsageLimitOrderer();
7
- const result = o.maybeSynthesize("s1", {
8
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached" }],
9
- });
10
- expect(result).toBeNull();
11
- });
12
-
13
- it("returns null when retry was pending but error is not a usage-limit", () => {
14
- const o = new UsageLimitOrderer();
15
- o.noteRetryStart("s1");
16
- const result = o.maybeSynthesize("s1", {
17
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "tool execution failed" }],
18
- });
19
- expect(result).toBeNull();
20
- });
21
-
22
- it("returns null on a non-error agent_end even with pending retry", () => {
23
- const o = new UsageLimitOrderer();
24
- o.noteRetryStart("s1");
25
- const result = o.maybeSynthesize("s1", {
26
- messages: [{ role: "assistant", stopReason: "end_turn" }],
27
- });
28
- expect(result).toBeNull();
29
- });
30
-
31
- it("synthesizes auto_retry_end on usage_limit_reached when retry was pending", () => {
32
- const o = new UsageLimitOrderer();
33
- o.noteRetryStart("s1");
34
- const result = o.maybeSynthesize("s1", {
35
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached: 5000 RPM" }],
36
- });
37
- expect(result).not.toBeNull();
38
- expect(result!.eventType).toBe("auto_retry_end");
39
- expect(result!.data).toEqual({ success: false, attempt: -1, finalError: "usage_limit_reached: 5000 RPM" });
40
- });
41
-
42
- it.each([
43
- "usage_limit_reached",
44
- "usage_not_included",
45
- "quota_exceeded",
46
- "monthly limit reached for free tier",
47
- "hourly limit hit",
48
- "Your quota will reset after 18h31m10s",
49
- ])("matches usage-limit variant: %s", (msg) => {
50
- expect(USAGE_LIMIT_PATTERN.test(msg)).toBe(true);
51
- });
52
-
53
- it.each([
54
- "rate limit exceeded",
55
- "overloaded_error",
56
- "tool execution failed",
57
- "fetch failed",
58
- "",
59
- ])("does not match non-usage-limit variant: %s", (msg) => {
60
- expect(USAGE_LIMIT_PATTERN.test(msg)).toBe(false);
61
- });
62
-
63
- it("clears pending after agent_end (no double-synthesis on subsequent agent_end)", () => {
64
- const o = new UsageLimitOrderer();
65
- o.noteRetryStart("s1");
66
- const first = o.maybeSynthesize("s1", {
67
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached" }],
68
- });
69
- expect(first).not.toBeNull();
70
- // Same payload again — pending was cleared, so no synthesis.
71
- const second = o.maybeSynthesize("s1", {
72
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached" }],
73
- });
74
- expect(second).toBeNull();
75
- });
76
-
77
- it("noteRetryEnd clears pending so subsequent agent_end does not synthesize", () => {
78
- const o = new UsageLimitOrderer();
79
- o.noteRetryStart("s1");
80
- o.noteRetryEnd("s1");
81
- expect(o.hasPending("s1")).toBe(false);
82
- const result = o.maybeSynthesize("s1", {
83
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached" }],
84
- });
85
- expect(result).toBeNull();
86
- });
87
-
88
- it("scopes pending state per-session", () => {
89
- const o = new UsageLimitOrderer();
90
- o.noteRetryStart("s1");
91
- expect(o.hasPending("s2")).toBe(false);
92
- const result = o.maybeSynthesize("s2", {
93
- messages: [{ role: "assistant", stopReason: "error", errorMessage: "usage_limit_reached" }],
94
- });
95
- expect(result).toBeNull();
96
- });
97
-
98
- it("returns null on missing or empty messages array", () => {
99
- const o = new UsageLimitOrderer();
100
- o.noteRetryStart("s1");
101
- expect(o.maybeSynthesize("s1", {})).toBeNull();
102
- o.noteRetryStart("s1");
103
- expect(o.maybeSynthesize("s1", { messages: [] })).toBeNull();
104
- });
105
- });
@@ -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,76 +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
- export const USAGE_LIMIT_PATTERN =
15
- /usage[_ ]limit[_ ]reached|usage_not_included|quota[_ ]exceeded|monthly limit|hourly limit|reset after \d+[hms]/i;
16
-
17
- export interface SyntheticEventEnvelope {
18
- eventType: "auto_retry_end";
19
- data: { success: false; attempt: -1; finalError: string };
20
- }
21
-
22
- export class UsageLimitOrderer {
23
- /** sessionId → true while a retry is in flight (no auto_retry_end seen yet). */
24
- private pending = new Set<string>();
25
-
26
- /**
27
- * Notify the orderer of an outbound `auto_retry_start` for sessionId.
28
- */
29
- noteRetryStart(sessionId: string): void {
30
- this.pending.add(sessionId);
31
- }
32
-
33
- /**
34
- * Notify the orderer of an outbound `auto_retry_end` for sessionId.
35
- * Subsequent `agent_end` events will not synthesize unless a new retry
36
- * has been started.
37
- */
38
- noteRetryEnd(sessionId: string): void {
39
- this.pending.delete(sessionId);
40
- }
41
-
42
- /**
43
- * Inspect an `agent_end` payload. If the terminal message has a
44
- * usage-limit error AND we have an unmatched retry-start for this session,
45
- * return the synthetic event the bridge should forward BEFORE the agent_end.
46
- *
47
- * Returns null when no synthesis is needed. Always clears the pending flag
48
- * after a terminal agent_end (errored or not) so we don't double-synthesize.
49
- */
50
- maybeSynthesize(
51
- sessionId: string,
52
- agentEndData: Record<string, unknown> | undefined,
53
- ): SyntheticEventEnvelope | null {
54
- const wasPending = this.pending.has(sessionId);
55
- // Always clear on agent_end: a terminal turn ends any retry tracking.
56
- this.pending.delete(sessionId);
57
-
58
- if (!wasPending || !agentEndData) return null;
59
- const messages = agentEndData.messages;
60
- if (!Array.isArray(messages) || messages.length === 0) return null;
61
- const last = messages[messages.length - 1] as Record<string, unknown> | undefined;
62
- if (!last || last.stopReason !== "error") return null;
63
- const errorMessage = typeof last.errorMessage === "string" ? last.errorMessage : "";
64
- if (!errorMessage || !USAGE_LIMIT_PATTERN.test(errorMessage)) return null;
65
-
66
- return {
67
- eventType: "auto_retry_end",
68
- data: { success: false, attempt: -1, finalError: errorMessage },
69
- };
70
- }
71
-
72
- /** Test-only: inspect pending state. */
73
- hasPending(sessionId: string): boolean {
74
- return this.pending.has(sessionId);
75
- }
76
- }