@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
@@ -0,0 +1,104 @@
1
+ # DOX Doctrine
2
+
3
+ Canonical per-directory `AGENTS.md` documentation doctrine. Shipped once with
4
+ the `project-init` skill. Adapted from agent0ai/dox, extended with a kb-backed
5
+ READ discipline. Retrievable via `kb_search "dox doctrine"`.
6
+
7
+ The scaffold seeds ONE block into a project's root `AGENTS.md` when that file
8
+ lacks the `<!-- dox-doctrine -->` marker: the WRITE discipline plus one READ
9
+ variant (kb-wired or manual). The sections below are delimited so the seeder
10
+ can compose the right block.
11
+
12
+ <!-- dox:write:start -->
13
+ ## Documentation Update Protocol (WRITE discipline)
14
+
15
+ Per-directory `AGENTS.md` files form a tree. Each directory `AGENTS.md` is the
16
+ per-file record for the files in that directory. The ROOT `AGENTS.md` holds
17
+ doctrine + architecture pointers only — never a per-file index.
18
+
19
+ **Keep the root lean.** The root `AGENTS.md` loads into every agent turn — every
20
+ byte costs tokens on every turn. A verbose root file buries the rules the model
21
+ must follow (signal dilution) and measurably degrades adherence; a lean file
22
+ keeps doctrine salient. Default assumption: your update does NOT belong in the
23
+ root — route it by the table below.
24
+
25
+ **Route every doc update by kind:**
26
+
27
+ | Kind of update | Goes in |
28
+ |---|---|
29
+ | New file in a directory, or its per-file detail / change history | Nearest directory `AGENTS.md`. Add a `` \| `<basename>` \| <purpose> \| `` row, path-alphabetical. |
30
+ | Data flow, protocol, architecture rationale | `docs/architecture.md` or a `docs/<topic>.md` |
31
+ | End-user / developer setup | `README.md` |
32
+ | Cross-cutting rule every agent needs every turn (rare) | ROOT `AGENTS.md` |
33
+
34
+ **Read before editing (chain walk).** Before editing a file, read the nearest
35
+ `AGENTS.md` chain root→leaf so you know the file's recorded purpose, contracts,
36
+ and change history. Do not edit blind.
37
+
38
+ **Update after editing (closeout pass).** After changing a file, update its row
39
+ in the nearest directory `AGENTS.md`: find the file's row, update its purpose in
40
+ place; if absent, add it in path-alphabetical order. New directory → scaffold
41
+ its `AGENTS.md`. One row per file. The purpose carries a one-line summary, key
42
+ exported symbols, contracts/invariants, and `See change: <id>` history.
43
+
44
+ **Row style (caveman).** Short declarative fragments. Drop articles. Subject →
45
+ verb → object, present tense. One fact per row. Prefer concrete tokens (paths,
46
+ symbols, env vars) over prose. Keep identifiers verbatim.
47
+
48
+ **Size rule — split an over-large directory `AGENTS.md` file-based.** pi
49
+ auto-injects a directory `AGENTS.md` on every turn when cwd sits at/below it, so
50
+ an over-large directory `AGENTS.md` (past a byte cap — typically a flat
51
+ directory holding many files) is not supported. Split it file-based: a row
52
+ exceeding the length threshold promotes to a per-file `<File>.AGENTS.md`
53
+ sidecar carrying that file's full detail (including every `See change:`). The
54
+ sidecar is pull-only — its name is not `AGENTS.md`, so pi never auto-injects it
55
+ — yet it stays search-indexed (`agents` doc_type). The directory `AGENTS.md`
56
+ keeps a one-line summary plus a `→ see \`<File>.AGENTS.md\`` pointer. Rows within
57
+ the threshold stay verbatim (lossless).
58
+ <!-- dox:write:end -->
59
+
60
+ <!-- dox:read:kb:start -->
61
+ ## Finding docs (READ discipline)
62
+
63
+ `kb_*` tools are faster and cheaper than raw search — they return a one-line
64
+ purpose + key exports per file, not raw bytes. **This fires on the ACTION, not
65
+ the intent** — before you `grep`/`rg` for a symbol, `cat`/read a file to learn
66
+ what it does, or chase an import, the kb call goes first. It fires **even
67
+ mid-task when you already know the file**; knowing the file does not exempt you.
68
+ When your reflex is the left column, run the right column instead:
69
+
70
+ | You're about to… | Do this FIRST instead |
71
+ |---|---|
72
+ | `grep -rn "SymbolName" src/` — find where a fn / type / const lives | `kb_search --doc-type agents "SymbolName"` — tree indexes key exports per file |
73
+ | `grep -rn "feature\|topic" src/` — how does X work / where's X handled | `kb_search "feature topic"` |
74
+ | `cat` / read a file just to learn its purpose before editing | `kb agents <path>` — one-line purpose + exports + change history |
75
+ | chase imports / callers across files | `kb_neighbors <path\|heading>` |
76
+ | read one doc section in full | `kb_get <path> <section>` |
77
+
78
+ **Fall-through (explicit):** if the kb call returns nothing relevant, `rg` /
79
+ source read is allowed — then add the missing directory `AGENTS.md` row per the
80
+ WRITE discipline. kb does NOT replace grep; it goes first.
81
+ <!-- dox:read:kb:end -->
82
+
83
+ <!-- dox:read:manual:start -->
84
+ ## Finding docs (READ discipline)
85
+
86
+ The directory `AGENTS.md` tree is faster and cheaper than raw search — each row
87
+ carries a one-line purpose + key exports per file. **This fires on the ACTION,
88
+ not the intent** — before you `grep`/`rg` for a symbol, `cat`/read a file to
89
+ learn what it does, or chase an import, consult the tree first. It fires **even
90
+ mid-task when you already know the file**; knowing the file does not exempt you.
91
+ When your reflex is the left column, do the right column instead:
92
+
93
+ | You're about to… | Do this FIRST instead |
94
+ |---|---|
95
+ | `grep -rn "SymbolName" src/` — find where a fn / type / const lives | read the nearest directory `AGENTS.md`; scan rows for the symbol |
96
+ | `grep -rn "feature\|topic" src/` — how does X work / where's X handled | walk the root→nearest `AGENTS.md` chain toward the file's directory |
97
+ | `cat` a file just to learn its purpose before editing | read that file's row in its directory `AGENTS.md` (purpose + exports + change history) |
98
+ | chase imports / callers across files | follow the `See change:` / pointer references in the nearest `AGENTS.md` |
99
+ | read one doc section in full | open the specific `docs/<topic>.md` section |
100
+
101
+ **Fall-through (explicit):** if the tree misses, `rg` / source read is allowed —
102
+ then add the missing directory `AGENTS.md` row per the WRITE discipline. The tree
103
+ goes first.
104
+ <!-- dox:read:manual:end -->
@@ -0,0 +1,111 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ ## Project Overview
4
+
5
+ <!-- One-paragraph description of what this project is. -->
6
+
7
+ > Keep this root file lean. It loads into every agent turn — verbose doctrine
8
+ > buries the rules the model must follow (signal dilution). Route per-file and
9
+ > task-specific detail into the directory `AGENTS.md` tree and `docs/`; keep
10
+ > only always-on doctrine here.
11
+
12
+ ## Code Instructions
13
+
14
+ Behavioral guidelines to reduce common coding mistakes. Bias toward caution over
15
+ speed. For trivial tasks, use judgment.
16
+
17
+ ### 1. Think Before Coding
18
+
19
+ - State assumptions explicitly. If uncertain, ask.
20
+ - If multiple interpretations exist, present them — don't pick silently.
21
+ - If a simpler approach exists, say so. Push back when warranted.
22
+ - Never speculate about code you have not opened. Consult the doc tree
23
+ (`kb agents <path>` / `kb_search`) first, then read the specific file.
24
+ - Before any major change, confirm the plan.
25
+
26
+ See the **Finding docs (READ discipline)** section for the kb-first
27
+ substitution table (which `kb_*` call replaces which raw-search reflex).
28
+
29
+ ### 2. Simplicity First
30
+
31
+ - Minimum code that solves the problem. Nothing speculative.
32
+ - No features beyond what was asked; no abstractions for single-use code.
33
+ - No error handling for impossible scenarios.
34
+ - DRY: extract a shared helper when a pattern repeats; don't pre-extract for one call site.
35
+
36
+ ### 3. Surgical Changes
37
+
38
+ - Touch only what you must. Match existing style.
39
+ - Don't refactor things that aren't broken.
40
+ - Remove imports/variables your changes made unused; leave pre-existing dead code (mention it).
41
+ - Every changed line traces directly to the request.
42
+
43
+ ### 4. Goal-Driven Execution (TDD)
44
+
45
+ - Turn tasks into verifiable goals with explicit success criteria.
46
+ - Write or update tests first, verify they fail, then write the minimal implementation to pass.
47
+ - For multi-step tasks, state a brief plan with a verify step each.
48
+
49
+ ### 5. Communication
50
+
51
+ - Give a high-level explanation of what changed — don't dump diffs without summary.
52
+
53
+ ## Finding docs (READ discipline)
54
+
55
+ `kb_*` tools return a one-line purpose + key exports per file, not raw bytes —
56
+ faster and cheaper than raw search. **This fires on the ACTION, not the
57
+ intent**: before you `grep`/`rg` for a symbol, `cat`/read a file to learn what
58
+ it does, or chase an import, the doc lookup goes first — even mid-task when you
59
+ already know the file. When your reflex is the left column, run the right:
60
+
61
+ | You're about to… | Do this FIRST instead |
62
+ |---|---|
63
+ | `grep -rn "SymbolName" src/` — find where a fn / type / const lives | `kb_search --doc-type agents "SymbolName"` (or read the nearest directory `AGENTS.md` if kb is not wired) |
64
+ | `grep -rn "feature\|topic" src/` — how does X work / where's X handled | `kb_search "feature topic"` (or walk the root→nearest `AGENTS.md` chain) |
65
+ | `cat` / read a file just to learn its purpose before editing | `kb agents <path>` — one-line purpose + exports + change history |
66
+ | chase imports / callers across files | `kb_neighbors <path\|heading>` |
67
+ | read one doc section in full | `kb_get <path> <section>` |
68
+
69
+ **Fall-through:** if the kb call (or the tree) returns nothing relevant, `rg` /
70
+ source read is allowed — then add the missing directory `AGENTS.md` row per the
71
+ Documentation Update Protocol. The doc lookup does NOT replace grep; it goes first.
72
+
73
+ ## Commands
74
+
75
+ <!-- Filled from the detected project stack; edit if your commands differ. -->
76
+
77
+ ```bash
78
+ {{INSTALL_CMD}} # install dependencies
79
+ {{TEST_CMD}} # run tests
80
+ {{BUILD_CMD}} # build
81
+ ```
82
+
83
+ ## OpenSpec
84
+
85
+ This project uses OpenSpec for spec-driven changes. Place change artifacts at
86
+ `openspec/changes/<name>/`. Prefer `openspec change new <name>` to scaffold.
87
+
88
+ When authoring a proposal, add a `## Discipline Skills` line to `proposal.md`
89
+ naming the `eng-disciplines` skills its tasks will trigger (mapped via the
90
+ checkpoint table below); omit only when none apply. This needs no edit to any
91
+ openspec skill — the implement loop reads the proposal artifact unchanged, so
92
+ the named skills enter its context and get invoked.
93
+
94
+ ## Discipline Skills
95
+
96
+ During implementation, invoke the matching `eng-disciplines` skill when a task
97
+ signal appears. Skills auto-trigger on natural language, but the implement loop
98
+ may never utter the phrase — this table makes the mapping explicit (signals are
99
+ observable in the diff / `tasks.md`, not vague intent):
100
+
101
+ | Task signal (in diff / tasks.md) | Skill |
102
+ |---|---|
103
+ | touches auth, untrusted input, secrets, webhooks, PII | `security-hardening` |
104
+ | spec has a latency/throughput budget, or a large-data / high-traffic path | `performance-optimization` |
105
+ | new endpoint, job, external call, or "can't tell what happened in prod" | `observability-instrumentation` |
106
+ | non-trivial/irreversible step (migration, public API, cross-boundary) BEFORE it stands | `doubt-driven-review` |
107
+ | a bug surfaces mid-implementation | `systematic-debugging` |
108
+ | runtime state opaque, `console.log` insufficient | `node-inspect-debugger` |
109
+ | feature works + tests pass but the implementation feels heavy | `code-simplification` |
110
+
111
+ The end gates (`code-review`, `code-quality`) remain unchanged and run at completion before commit.
@@ -0,0 +1,5 @@
1
+ {
2
+ "description": "Coding repo — TDD, simplicity, surgical changes. OpenSpec enabled; stack-detected worktree-init (npm/pnpm/yarn/bun/cargo/go/pip/poetry/maven/gradle).",
3
+ "stackAware": true,
4
+ "dox": true
5
+ }
@@ -0,0 +1,5 @@
1
+ Draft a focused implementation plan for the requested change.
2
+
3
+ State assumptions, list the files you expect to touch, and define a verify step
4
+ for each task (test to write, command to run). Keep the plan minimal — surgical
5
+ changes only. Confirm the plan before implementing.
@@ -0,0 +1,6 @@
1
+ Implement the current task test-first.
2
+
3
+ 1. Write or update a test that defines the expected behaviour.
4
+ 2. Run it and confirm it fails for the right reason.
5
+ 3. Write the minimal implementation to make it pass.
6
+ 4. Re-run until green. Refactor only with tests green.
@@ -0,0 +1,9 @@
1
+ {
2
+ "worktreeInit": {
3
+ "gate": "{{INIT_GATE}}",
4
+ "run": {
5
+ "type": "script",
6
+ "command": "{{INIT_COMMAND}}"
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,37 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ ## Project Overview
4
+
5
+ <!-- One-paragraph description of what this documentation set covers. -->
6
+
7
+ ## Writing Instructions
8
+
9
+ Guidelines for clear, consistent documentation.
10
+
11
+ ### 1. Structure First
12
+
13
+ - Lead with the answer, then the detail. Don't bury the point.
14
+ - One idea per section. Use descriptive headings a reader can scan.
15
+ - Prefer short paragraphs and lists over walls of prose.
16
+
17
+ ### 2. Style
18
+
19
+ - Plain, direct language. Present tense. Active voice.
20
+ - Define a term once, on first use. Keep terminology consistent.
21
+ - Show, don't tell: concrete examples, commands, and paths over abstraction.
22
+ - Keep code samples runnable and minimal.
23
+
24
+ ### 3. Surgical Edits
25
+
26
+ - Change only what the request needs. Match the existing voice and structure.
27
+ - Don't restructure a document that isn't broken.
28
+ - Fix the specific error; note adjacent issues, don't silently rewrite them.
29
+
30
+ ### 4. Review
31
+
32
+ - Read the edited section end-to-end. Does it stand alone and answer the question?
33
+ - Check every link, path, and command you touched.
34
+
35
+ ## Diagrams
36
+
37
+ Use Mermaid (```mermaid blocks) for diagrams, not ASCII art.
@@ -0,0 +1,4 @@
1
+ {
2
+ "description": "Documentation repo — writing structure + style. OpenSpec disabled; no build step.",
3
+ "dox": false
4
+ }
@@ -0,0 +1,5 @@
1
+ Draft or revise the requested documentation page.
2
+
3
+ Lead with the answer, then the detail. One idea per section with a scannable
4
+ heading. Plain, direct language, present tense, active voice. Include concrete
5
+ examples, commands, and paths. Keep edits surgical — match the existing voice.
@@ -0,0 +1,9 @@
1
+ {
2
+ "worktreeInit": {
3
+ "gate": "false",
4
+ "run": {
5
+ "type": "script",
6
+ "command": "echo 'docs project — no worktree-init step needed'"
7
+ }
8
+ }
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blackbelt-technology/pi-dashboard-extension",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "description": "Pi bridge extension for pi-dashboard",
5
5
  "type": "module",
6
6
  "repository": {
@@ -16,15 +16,23 @@
16
16
  "src/bridge.ts"
17
17
  ],
18
18
  "skills": [
19
- ".pi/skills/pi-dashboard"
19
+ ".pi/skills/pi-dashboard",
20
+ ".pi/skills/browser",
21
+ ".pi/skills/project-init",
22
+ ".pi/skills/doctor"
20
23
  ]
21
24
  },
22
25
  "files": [
23
26
  "src/",
24
- ".pi/skills/pi-dashboard/"
27
+ ".pi/skills/pi-dashboard/",
28
+ ".pi/skills/browser/",
29
+ ".pi/skills/project-init/",
30
+ ".pi/skills/doctor/"
25
31
  ],
26
32
  "dependencies": {
27
- "@blackbelt-technology/pi-dashboard-shared": "^0.5.3",
33
+ "@blackbelt-technology/pi-dashboard-bus-client": "^0.6.0",
34
+ "@blackbelt-technology/pi-dashboard-shared": "^0.6.0",
35
+ "minimatch": "^10.0.0",
28
36
  "ws": "^8.18.0"
29
37
  },
30
38
  "peerDependencies": {
package/src/AGENTS.md ADDED
@@ -0,0 +1,56 @@
1
+ # DOX — packages/extension/src
2
+
3
+ Files in this directory. One row per source file.
4
+
5
+ | File | Purpose |
6
+ |------|---------|
7
+ | `abort-latch.ts` | Pure class `AbortLatch`. Keeps user abort latched so provider backoff (5–60s) outliving 2s persistent-abort… → see `abort-latch.ts.AGENTS.md` |
8
+ | `agent-settled.ts` | Bridge `agent_settled` normalization (pure). `nativeAgentSettledSupported(piVersion)` → pi ≥ 0.80.4 emits… → see `agent-settled.ts.AGENTS.md` |
9
+ | `artifact-roots.ts` | Artifact-root allowlist for Fix B bridge image inlining. `resolveArtifactRoots({homedir,env,realpathSync})` →… → see `artifact-roots.ts.AGENTS.md` |
10
+ | `ask-user-attachments.ts` | Persist image attachments for ask_user input responses. Exports `attachmentDirForSession`,… → see `ask-user-attachments.ts.AGENTS.md` |
11
+ | `ask-user-tool.ts` | Register `ask_user` pi tool at `session_start` (avoids static-name conflict). Exports `registerAskUserTool`. → see `ask-user-tool.ts.AGENTS.md` |
12
+ | `auto-session-namer.ts` | Automatic session topic-naming (bridge-side). Pure helpers `shouldSkipByPrefilter`, `parseTitle`,… → see `auto-session-namer.ts.AGENTS.md` |
13
+ | `bridge-context.ts` | Shared mutable bridge state + pure predicates. Exports `BridgeContext`, `DASHBOARD_NATIVE_COMMANDS`,… → see `bridge-context.ts.AGENTS.md` |
14
+ | `bridge-default-model-gate.ts` | Pure predicate `shouldApplyDefaultModel({reason, entryCount, hasModelRegistry, hasDefaultModel})`. → see `bridge-default-model-gate.ts.AGENTS.md` |
15
+ | `bridge.ts` | Main bridge extension entry (default export). Connects to dashboard server, forwards pi events via… → see `bridge.ts.AGENTS.md` |
16
+ | `command-handler.ts` | Command routing: `!`/`!!` bash, `/compact`, slash commands. → see `command-handler.ts.AGENTS.md` |
17
+ | `connection.ts` | WebSocket connection manager with exponential backoff reconnect, message buffering while disconnected,… → see `connection.ts.AGENTS.md` |
18
+ | `dashboard-context-injector.ts` | Registers `before_agent_start` handler. Splice-replaces trailing `Current working directory:` line of system… → see `dashboard-context-injector.ts.AGENTS.md` |
19
+ | `dashboard-default-adapter.ts` | Built-in last-resort `PromptAdapter` (priority `9999`). Exports `DashboardDefaultAdapter`. → see `dashboard-default-adapter.ts.AGENTS.md` |
20
+ | `dev-build.ts` | Dev build-on-reload helper. Exports `runDevBuild`, `DevBuildOptions`. → see `dev-build.ts.AGENTS.md` |
21
+ | `empty-actionable-guard-config.ts` | Resolve empty-actionable guard config from env. Exports `resolveGuardConfig(env)` → `{mode,retryCap}`. → see `empty-actionable-guard-config.ts.AGENTS.md` |
22
+ | `empty-actionable-guard.ts` | Bounded continue-or-surface decision for empty-actionable turns. → see `empty-actionable-guard.ts.AGENTS.md` |
23
+ | `event-forwarder.ts` | Map pi event objects to `event_forward` protocol messages. Exports `mapEventToProtocol`. → see `event-forwarder.ts.AGENTS.md` |
24
+ | `flow-event-wiring.ts` | Register pi-flows + pi-subagents event listeners on `pi.events`. → see `flow-event-wiring.ts.AGENTS.md` |
25
+ | `git-link-builder.ts` | Parse SSH/HTTPS remote URLs into branch + PR links. Exports `parseRemoteUrl`, `detectPlatform`,… → see `git-link-builder.ts.AGENTS.md` |
26
+ | `commit-draft.ts` | Pure AI-draft fallback ladder (no pi-SDK coupling). Exports `draftCommitMessage(deps)` → `{message, source}`,… → see `commit-draft.ts.AGENTS.md` |
27
+ | `commit-draft-agent.ts` | pi-SDK-coupled half of AI-draft. Exports `buildSessionContextText(ctx, maxChars)` (compacts… → see `commit-draft-agent.ts.AGENTS.md` |
28
+ | `git-poll.ts` | Exports `runGitPollTick(deps)` + `GitPollDeps` interface. Pure git + name/model poll-tick body. → see `git-poll.ts.AGENTS.md` |
29
+ | `hasui-flip.ts` | Flip `ctx.hasUI` to `true` after bridge patches `ctx.ui.*`. Exports `flipHasUI`. → see `hasui-flip.ts.AGENTS.md` |
30
+ | `markdown-image-inliner.ts` | Bridge helper rewriting assistant `![alt](path)` → `![alt](pi-asset:<hash>)` (SHA-256/16, MIME allowlist, 5… → see `markdown-image-inliner.ts.AGENTS.md` |
31
+ | `model-tracker.ts` | Diff-and-send trackers for model / session name / git info / pi version / cwd-missing. → see `model-tracker.ts.AGENTS.md` |
32
+ | `multiselect-decode.ts` | Pure helper decoding `PromptResponse` into `string[] | undefined`. → see `multiselect-decode.ts.AGENTS.md` |
33
+ | `multiselect-list.ts` | TUI multi-select component implementing pi-tui `ComponentLike`. Exports `MultiSelectList`, `ComponentLike`. → see `multiselect-list.ts.AGENTS.md` |
34
+ | `multiselect-polyfill.ts` | Polyfill `ctx.ui.multiselect`. Exports `polyfillMultiselect`, `PolyfillCtx`. → see `multiselect-polyfill.ts.AGENTS.md` |
35
+ | `process-metrics.ts` | Lightweight process metrics collector for bridge heartbeats. → see `process-metrics.ts.AGENTS.md` |
36
+ | `process-scanner.ts` | Detect child processes of a pi session. Exports `getOwnPgid`, `captureChildPgids`, `scanTrackedProcesses`,… → see `process-scanner.ts.AGENTS.md` |
37
+ | `project-trust.ts` | `project_trust` auto-decision (pure gate + defensive cwd read). → see `project-trust.ts.AGENTS.md` |
38
+ | `prompt-bus.ts` | Prompt dispatch bus — first-response-wins adapter routing + cross-adapter dismissal. → see `prompt-bus.ts.AGENTS.md` |
39
+ | `prompt-expander.ts` | Expand prompt templates from disk for dashboard slash commands (`pi.sendUserMessage` skips expansion). → see `prompt-expander.ts.AGENTS.md` |
40
+ | `provider-register.ts` | Register custom LLM providers + auto-discovered models from `~/.pi/agent/providers.json`. → see `provider-register.ts.AGENTS.md` |
41
+ | `subagent-frame-buffer.ts` | Pure class `SubagentFrameBuffer` + `SUBAGENT_CHANNELS` set. Makes running-subagent timeline reconcilable. → see `subagent-frame-buffer.ts.AGENTS.md` |
42
+ | `retry-tracker.ts` | Pure helper class `RetryTracker` synthesizes `auto_retry_start` / `auto_retry_end` by OBSERVING pi's own… → see `retry-tracker.ts.AGENTS.md` |
43
+ | `role-manager.ts` | Manages session model roles. Registers six `roles:*` handlers… → see `role-manager.ts.AGENTS.md` |
44
+ | `role-model-tools.ts` | Agent-facing tools registered via `pi.registerTool` (capability agent-role-model-tools). → see `role-model-tools.ts.AGENTS.md` |
45
+ | `server-auto-start.ts` | Auto-start orchestration: discover dashboard via mDNS → health-check fallback → spawn server process. → see `server-auto-start.ts.AGENTS.md` |
46
+ | `server-launcher.ts` | Spawns dashboard server as detached process via shared `launchDashboardServer`. → see `server-launcher.ts.AGENTS.md` |
47
+ | `server-probe.ts` | TCP port probe. Exports `isPortOpen(port)` — 1s timeout localhost connect, resolves `true` on connect else `false`. Detects running dashboard server. |
48
+ | `session-sync.ts` | Session register/replay/switch lifecycle. Exports `sendStateSync`, `replaySessionEntries`,… → see `session-sync.ts.AGENTS.md` |
49
+ | `slash-dispatch.ts` | Extension slash-command dispatch (routing-step 9). Exports `tryDispatchExtensionCommand`, `FeedbackSink`,… → see `slash-dispatch.ts.AGENTS.md` |
50
+ | `source-detector.ts` | Detects session source env. Exports `detectSessionSource(hasUI?, sessionFile?)` → `SessionSource`. → see `source-detector.ts.AGENTS.md` |
51
+ | `tool-result-image-inliner.ts` | Bridge Fix B tool-result image inliner. On `tool_execution_end` scans result text for absolute image paths… → see `tool-result-image-inliner.ts.AGENTS.md` |
52
+ | `tui-prompt-adapter.ts` | Production PromptBus adapter for Pi's TUI. Exports `createTuiPromptAdapter`, `TuiPromptUi`. Presents select/input/confirm/editor via captured unpatched UI; forwards confirm `metadata.message`; no multiselect arm. → see `tui-prompt-adapter.ts.AGENTS.md` |
53
+ | `turn-actionability.ts` | Pure provider-agnostic classifier. Exports `classifyTurnActionability(turn)` →… → see `turn-actionability.ts.AGENTS.md` |
54
+ | `ui-modules.ts` | Extension UI system bridge side. Exports `refreshUiModules`, `subscribeUiInvalidate`, `handleUiManagement`,… → see `ui-modules.ts.AGENTS.md` |
55
+ | `vcs-info.ts` | Gathers git branch/remote/PR/worktree info via shared platform git helpers. → see `vcs-info.ts.AGENTS.md` |
56
+ | `visibility-intent.ts` | Resolves `session_register` visibility fields. Exports `resolveVisibilityIntent`,… → see `visibility-intent.ts.AGENTS.md` |
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Bridge abort-latch behaviour: a user abort must stop pi's in-flight retry
3
+ * even across a provider backoff that outlives the 2 s persistent-abort
4
+ * scheduler. The latch is abort-on-sight, cleared by a new user prompt or
5
+ * turn settle.
6
+ *
7
+ * `LatchSim` mirrors the bridge wiring (see bridge.ts): abort sets the latch
8
+ * and records the wrapper-abort; any observed resumption (assistant
9
+ * message_start / agent_start) while latched issues a fresh cachedCtx.abort();
10
+ * a new user prompt or agent_end clears the latch.
11
+ *
12
+ * See change: unify-error-retry-lifecycle.
13
+ */
14
+ import { describe, it, expect } from "vitest";
15
+ import { AbortLatch } from "../abort-latch.js";
16
+
17
+ class LatchSim {
18
+ /** Ordered log of cachedCtx.abort() invocations: "wrapper" (initial) | "latch" (re-abort). */
19
+ readonly aborts: string[] = [];
20
+ private latch = new AbortLatch();
21
+
22
+ /** User pressed Stop/Dismiss → wrapper-abort once + latch on. */
23
+ userAbort(sessionId: string): void {
24
+ this.aborts.push("wrapper");
25
+ this.latch.request(sessionId);
26
+ }
27
+
28
+ /** Bridge observes the aborted turn resuming (retry attempt). */
29
+ resume(sessionId: string): void {
30
+ if (this.latch.shouldAbort(sessionId)) this.aborts.push("latch");
31
+ }
32
+
33
+ /** A new user prompt is dispatched (deliberate new turn). */
34
+ userPrompt(sessionId: string): void {
35
+ this.latch.clear(sessionId);
36
+ }
37
+
38
+ /** The aborted turn settled (agent_end / idle). */
39
+ settle(sessionId: string): void {
40
+ this.latch.clear(sessionId);
41
+ }
42
+
43
+ isLatched(sessionId: string): boolean {
44
+ return this.latch.isActive(sessionId);
45
+ }
46
+ }
47
+
48
+ describe("AbortLatch", () => {
49
+ it("re-aborts a retry that wakes after the 2 s scheduler window", () => {
50
+ const sim = new LatchSim();
51
+ sim.userAbort("s1");
52
+ // ...30 s backoff elapses; the persistent-abort scheduler already stopped
53
+ // after 2 s. pi wakes and attempts to continue the same aborted turn.
54
+ sim.resume("s1");
55
+ expect(sim.aborts).toEqual(["wrapper", "latch"]);
56
+ expect(sim.isLatched("s1")).toBe(true); // still latched until settle / new prompt
57
+ });
58
+
59
+ it("re-aborts repeatedly across multiple resumption attempts", () => {
60
+ const sim = new LatchSim();
61
+ sim.userAbort("s1");
62
+ sim.resume("s1");
63
+ sim.resume("s1");
64
+ expect(sim.aborts).toEqual(["wrapper", "latch", "latch"]);
65
+ });
66
+
67
+ it("clears on a new user prompt and does NOT kill the new turn", () => {
68
+ const sim = new LatchSim();
69
+ sim.userAbort("s1");
70
+ sim.userPrompt("s1"); // deliberate new turn → clears latch
71
+ sim.resume("s1"); // the new turn's first assistant message_start
72
+ expect(sim.aborts).toEqual(["wrapper"]); // no latch re-abort
73
+ expect(sim.isLatched("s1")).toBe(false);
74
+ });
75
+
76
+ it("clears on settle (agent_end / idle)", () => {
77
+ const sim = new LatchSim();
78
+ sim.userAbort("s1");
79
+ sim.settle("s1");
80
+ sim.resume("s1"); // a later, unrelated turn
81
+ expect(sim.aborts).toEqual(["wrapper"]);
82
+ expect(sim.isLatched("s1")).toBe(false);
83
+ });
84
+
85
+ it("latch is per-session — aborting s1 never re-aborts s2", () => {
86
+ const sim = new LatchSim();
87
+ sim.userAbort("s1");
88
+ sim.resume("s2");
89
+ expect(sim.aborts).toEqual(["wrapper"]);
90
+ });
91
+
92
+ it("does not re-abort when no abort was requested", () => {
93
+ const sim = new LatchSim();
94
+ sim.resume("s1");
95
+ expect(sim.aborts).toEqual([]);
96
+ });
97
+ });
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Bridge `agent_settled` normalization — pure decision logic.
3
+ *
4
+ * The bridge guarantees exactly ONE terminal `agent_settled` per run on every
5
+ * supported pi: native (≥ 0.80.4) is forwarded as-is with no synth; floor pi
6
+ * (< 0.80.4) gets a synthetic settle synchronously after each `agent_end`.
7
+ *
8
+ * See change: adopt-pi-074-080-features (A.1 — E1, E2, F8, X2).
9
+ */
10
+ import { describe, expect, it } from "vitest";
11
+ import {
12
+ NATIVE_AGENT_SETTLED_FLOOR,
13
+ nativeAgentSettledSupported,
14
+ settleFollowUp,
15
+ synthesizeAgentSettledEvent,
16
+ } from "../agent-settled.js";
17
+
18
+ describe("nativeAgentSettledSupported", () => {
19
+ it("E1: 0.80.4 (boundary floor) supports native settle", () => {
20
+ expect(nativeAgentSettledSupported("0.80.4")).toBe(true);
21
+ expect(NATIVE_AGENT_SETTLED_FLOOR).toBe("0.80.4");
22
+ });
23
+
24
+ it("E2: 0.80.3 (just below floor) does NOT support native settle", () => {
25
+ expect(nativeAgentSettledSupported("0.80.3")).toBe(false);
26
+ });
27
+
28
+ it("F8: a modern pi (0.80.10) supports native settle", () => {
29
+ expect(nativeAgentSettledSupported("0.80.10")).toBe(true);
30
+ });
31
+
32
+ it("older majors/minors defer to synth", () => {
33
+ expect(nativeAgentSettledSupported("0.78.0")).toBe(false);
34
+ expect(nativeAgentSettledSupported("0.79.10")).toBe(false);
35
+ });
36
+
37
+ it("newer versions support native settle", () => {
38
+ expect(nativeAgentSettledSupported("0.81.0")).toBe(true);
39
+ expect(nativeAgentSettledSupported("1.0.0")).toBe(true);
40
+ });
41
+
42
+ it("ignores pre-release / build suffixes", () => {
43
+ expect(nativeAgentSettledSupported("0.80.4-rc.1")).toBe(true);
44
+ expect(nativeAgentSettledSupported("0.80.3-beta")).toBe(false);
45
+ });
46
+
47
+ it("unknown / unparseable version is treated as floor (synthesize)", () => {
48
+ expect(nativeAgentSettledSupported(undefined)).toBe(false);
49
+ expect(nativeAgentSettledSupported("")).toBe(false);
50
+ });
51
+ });
52
+
53
+ describe("settleFollowUp", () => {
54
+ it("E1/F8: native pi never synthesizes after agent_end", () => {
55
+ expect(settleFollowUp("agent_end", true, 100)).toBeNull();
56
+ });
57
+
58
+ it("E2: floor pi synthesizes exactly one settle after agent_end", () => {
59
+ const synth = settleFollowUp("agent_end", false, 100);
60
+ expect(synth).toEqual({ eventType: "agent_settled", timestamp: 100, data: {} });
61
+ });
62
+
63
+ it("F8/X2: a real agent_settled never produces a follow-up synth", () => {
64
+ expect(settleFollowUp("agent_settled", true, 100)).toBeNull();
65
+ expect(settleFollowUp("agent_settled", false, 100)).toBeNull();
66
+ });
67
+
68
+ it("other events never synthesize", () => {
69
+ expect(settleFollowUp("agent_start", false, 100)).toBeNull();
70
+ expect(settleFollowUp("turn_end", false, 100)).toBeNull();
71
+ });
72
+ });
73
+
74
+ describe("synthesizeAgentSettledEvent", () => {
75
+ it("carries no payload (agent_settled has no data)", () => {
76
+ expect(synthesizeAgentSettledEvent(42)).toEqual({
77
+ eventType: "agent_settled",
78
+ timestamp: 42,
79
+ data: {},
80
+ });
81
+ });
82
+ });