@jadelclemens/pi-forge 0.0.0-stage → 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 (440) hide show
  1. package/CHANGELOG.md +486 -0
  2. package/LICENSE +21 -0
  3. package/PUBLIC_API.md +5 -0
  4. package/README.md +204 -2
  5. package/README.zh-CN.md +128 -0
  6. package/SUBAGENT_ADAPTER_CONTRACT.md +7 -0
  7. package/dist/active-state.d.ts +148 -0
  8. package/dist/active-state.d.ts.map +1 -0
  9. package/dist/active-state.js +374 -0
  10. package/dist/active-state.js.map +1 -0
  11. package/dist/agent-profile.d.ts +51 -0
  12. package/dist/agent-profile.d.ts.map +1 -0
  13. package/dist/agent-profile.js +197 -0
  14. package/dist/agent-profile.js.map +1 -0
  15. package/dist/capabilities.d.ts +39 -0
  16. package/dist/capabilities.d.ts.map +1 -0
  17. package/dist/capabilities.js +160 -0
  18. package/dist/capabilities.js.map +1 -0
  19. package/dist/capability-anchors.d.ts +45 -0
  20. package/dist/capability-anchors.d.ts.map +1 -0
  21. package/dist/capability-anchors.js +263 -0
  22. package/dist/capability-anchors.js.map +1 -0
  23. package/dist/capability-command.d.ts +4 -0
  24. package/dist/capability-command.d.ts.map +1 -0
  25. package/dist/capability-command.js +164 -0
  26. package/dist/capability-command.js.map +1 -0
  27. package/dist/capability-events.d.ts +79 -0
  28. package/dist/capability-events.d.ts.map +1 -0
  29. package/dist/capability-events.js +478 -0
  30. package/dist/capability-events.js.map +1 -0
  31. package/dist/capability-projection.d.ts +22 -0
  32. package/dist/capability-projection.d.ts.map +1 -0
  33. package/dist/capability-projection.js +273 -0
  34. package/dist/capability-projection.js.map +1 -0
  35. package/dist/capability-protocol.d.ts +21 -0
  36. package/dist/capability-protocol.d.ts.map +1 -0
  37. package/dist/capability-protocol.js +15 -0
  38. package/dist/capability-protocol.js.map +1 -0
  39. package/dist/capability-state.d.ts +74 -0
  40. package/dist/capability-state.d.ts.map +1 -0
  41. package/dist/capability-state.js +43 -0
  42. package/dist/capability-state.js.map +1 -0
  43. package/dist/capability-tool.d.ts +11 -0
  44. package/dist/capability-tool.d.ts.map +1 -0
  45. package/dist/capability-tool.js +25 -0
  46. package/dist/capability-tool.js.map +1 -0
  47. package/dist/capability-web-host.d.ts +11 -0
  48. package/dist/capability-web-host.d.ts.map +1 -0
  49. package/dist/capability-web-host.js +105 -0
  50. package/dist/capability-web-host.js.map +1 -0
  51. package/dist/catalog.d.ts +27 -0
  52. package/dist/catalog.d.ts.map +1 -0
  53. package/dist/catalog.js +59 -0
  54. package/dist/catalog.js.map +1 -0
  55. package/dist/codecs/agent-profile.d.ts +53 -0
  56. package/dist/codecs/agent-profile.d.ts.map +1 -0
  57. package/dist/codecs/agent-profile.js +176 -0
  58. package/dist/codecs/agent-profile.js.map +1 -0
  59. package/dist/codecs/capability.d.ts +71 -0
  60. package/dist/codecs/capability.d.ts.map +1 -0
  61. package/dist/codecs/capability.js +363 -0
  62. package/dist/codecs/capability.js.map +1 -0
  63. package/dist/codecs/index.d.ts +5 -0
  64. package/dist/codecs/index.d.ts.map +1 -0
  65. package/dist/codecs/index.js +3 -0
  66. package/dist/codecs/index.js.map +1 -0
  67. package/dist/codecs/prompt-stack.d.ts +18 -0
  68. package/dist/codecs/prompt-stack.d.ts.map +1 -0
  69. package/dist/codecs/prompt-stack.js +623 -0
  70. package/dist/codecs/prompt-stack.js.map +1 -0
  71. package/dist/command-contribution/index.d.ts +21 -0
  72. package/dist/command-contribution/index.d.ts.map +1 -0
  73. package/dist/command-contribution/index.js +14 -0
  74. package/dist/command-contribution/index.js.map +1 -0
  75. package/dist/compile-cycle.d.ts +26 -0
  76. package/dist/compile-cycle.d.ts.map +1 -0
  77. package/dist/compile-cycle.js +16 -0
  78. package/dist/compile-cycle.js.map +1 -0
  79. package/dist/compiler.d.ts +22 -0
  80. package/dist/compiler.d.ts.map +1 -0
  81. package/dist/compiler.js +737 -0
  82. package/dist/compiler.js.map +1 -0
  83. package/dist/context-diff-history.d.ts +69 -0
  84. package/dist/context-diff-history.d.ts.map +1 -0
  85. package/dist/context-diff-history.js +107 -0
  86. package/dist/context-diff-history.js.map +1 -0
  87. package/dist/context-diff-snapshot.d.ts +19 -0
  88. package/dist/context-diff-snapshot.d.ts.map +1 -0
  89. package/dist/context-diff-snapshot.js +146 -0
  90. package/dist/context-diff-snapshot.js.map +1 -0
  91. package/dist/context-diff.d.ts +70 -0
  92. package/dist/context-diff.d.ts.map +1 -0
  93. package/dist/context-diff.js +259 -0
  94. package/dist/context-diff.js.map +1 -0
  95. package/dist/extension-registry.d.ts +25 -0
  96. package/dist/extension-registry.d.ts.map +1 -0
  97. package/dist/extension-registry.js +9 -0
  98. package/dist/extension-registry.js.map +1 -0
  99. package/dist/forge-command.d.ts +10 -0
  100. package/dist/forge-command.d.ts.map +1 -0
  101. package/dist/forge-command.js +106 -0
  102. package/dist/forge-command.js.map +1 -0
  103. package/dist/forge-config.d.ts +9 -0
  104. package/dist/forge-config.d.ts.map +1 -0
  105. package/dist/forge-config.js +15 -0
  106. package/dist/forge-config.js.map +1 -0
  107. package/dist/forge-extensions.d.ts +28 -0
  108. package/dist/forge-extensions.d.ts.map +1 -0
  109. package/dist/forge-extensions.js +198 -0
  110. package/dist/forge-extensions.js.map +1 -0
  111. package/dist/forge-v1/analyzer.d.ts +3 -0
  112. package/dist/forge-v1/analyzer.d.ts.map +1 -0
  113. package/dist/forge-v1/analyzer.js +50 -0
  114. package/dist/forge-v1/analyzer.js.map +1 -0
  115. package/dist/forge-v1/index.d.ts +6 -0
  116. package/dist/forge-v1/index.d.ts.map +1 -0
  117. package/dist/forge-v1/index.js +13 -0
  118. package/dist/forge-v1/index.js.map +1 -0
  119. package/dist/forge-v1/parser.d.ts +3 -0
  120. package/dist/forge-v1/parser.d.ts.map +1 -0
  121. package/dist/forge-v1/parser.js +186 -0
  122. package/dist/forge-v1/parser.js.map +1 -0
  123. package/dist/forge-v1/renderer.d.ts +9 -0
  124. package/dist/forge-v1/renderer.d.ts.map +1 -0
  125. package/dist/forge-v1/renderer.js +181 -0
  126. package/dist/forge-v1/renderer.js.map +1 -0
  127. package/dist/forge-v1/types.d.ts +87 -0
  128. package/dist/forge-v1/types.d.ts.map +1 -0
  129. package/dist/forge-v1/types.js +4 -0
  130. package/dist/forge-v1/types.js.map +1 -0
  131. package/dist/host-compatibility.d.ts +13 -0
  132. package/dist/host-compatibility.d.ts.map +1 -0
  133. package/dist/host-compatibility.js +41 -0
  134. package/dist/host-compatibility.js.map +1 -0
  135. package/dist/index.d.ts +15 -0
  136. package/dist/index.d.ts.map +1 -0
  137. package/dist/index.js +183 -0
  138. package/dist/index.js.map +1 -0
  139. package/dist/json-fingerprint.d.ts +11 -0
  140. package/dist/json-fingerprint.d.ts.map +1 -0
  141. package/dist/json-fingerprint.js +66 -0
  142. package/dist/json-fingerprint.js.map +1 -0
  143. package/dist/lifecycle.d.ts +46 -0
  144. package/dist/lifecycle.d.ts.map +1 -0
  145. package/dist/lifecycle.js +330 -0
  146. package/dist/lifecycle.js.map +1 -0
  147. package/dist/loader.d.ts +21 -0
  148. package/dist/loader.d.ts.map +1 -0
  149. package/dist/loader.js +58 -0
  150. package/dist/loader.js.map +1 -0
  151. package/dist/macro-engine.d.ts +18 -0
  152. package/dist/macro-engine.d.ts.map +1 -0
  153. package/dist/macro-engine.js +29 -0
  154. package/dist/macro-engine.js.map +1 -0
  155. package/dist/payload-capture.d.ts +31 -0
  156. package/dist/payload-capture.d.ts.map +1 -0
  157. package/dist/payload-capture.js +253 -0
  158. package/dist/payload-capture.js.map +1 -0
  159. package/dist/payload-command.d.ts +12 -0
  160. package/dist/payload-command.d.ts.map +1 -0
  161. package/dist/payload-command.js +197 -0
  162. package/dist/payload-command.js.map +1 -0
  163. package/dist/payload-state.d.ts +20 -0
  164. package/dist/payload-state.d.ts.map +1 -0
  165. package/dist/payload-state.js +20 -0
  166. package/dist/payload-state.js.map +1 -0
  167. package/dist/policy.d.ts +7 -0
  168. package/dist/policy.d.ts.map +1 -0
  169. package/dist/policy.js +41 -0
  170. package/dist/policy.js.map +1 -0
  171. package/dist/preset-command.d.ts +19 -0
  172. package/dist/preset-command.d.ts.map +1 -0
  173. package/dist/preset-command.js +261 -0
  174. package/dist/preset-command.js.map +1 -0
  175. package/dist/preview-inspection.d.ts +68 -0
  176. package/dist/preview-inspection.d.ts.map +1 -0
  177. package/dist/preview-inspection.js +293 -0
  178. package/dist/preview-inspection.js.map +1 -0
  179. package/dist/preview-text.d.ts +5 -0
  180. package/dist/preview-text.d.ts.map +1 -0
  181. package/dist/preview-text.js +27 -0
  182. package/dist/preview-text.js.map +1 -0
  183. package/dist/preview.d.ts +32 -0
  184. package/dist/preview.d.ts.map +1 -0
  185. package/dist/preview.js +272 -0
  186. package/dist/preview.js.map +1 -0
  187. package/dist/profile-command.d.ts +17 -0
  188. package/dist/profile-command.d.ts.map +1 -0
  189. package/dist/profile-command.js +385 -0
  190. package/dist/profile-command.js.map +1 -0
  191. package/dist/profile-service.d.ts +107 -0
  192. package/dist/profile-service.d.ts.map +1 -0
  193. package/dist/profile-service.js +248 -0
  194. package/dist/profile-service.js.map +1 -0
  195. package/dist/prompt-analysis.d.ts +24 -0
  196. package/dist/prompt-analysis.d.ts.map +1 -0
  197. package/dist/prompt-analysis.js +84 -0
  198. package/dist/prompt-analysis.js.map +1 -0
  199. package/dist/prompt-cache-warning.d.ts +23 -0
  200. package/dist/prompt-cache-warning.d.ts.map +1 -0
  201. package/dist/prompt-cache-warning.js +74 -0
  202. package/dist/prompt-cache-warning.js.map +1 -0
  203. package/dist/prompt-runtime.d.ts +19 -0
  204. package/dist/prompt-runtime.d.ts.map +1 -0
  205. package/dist/prompt-runtime.js +34 -0
  206. package/dist/prompt-runtime.js.map +1 -0
  207. package/dist/regex.d.ts +19 -0
  208. package/dist/regex.d.ts.map +1 -0
  209. package/dist/regex.js +507 -0
  210. package/dist/regex.js.map +1 -0
  211. package/dist/render-helpers.d.ts +38 -0
  212. package/dist/render-helpers.d.ts.map +1 -0
  213. package/dist/render-helpers.js +85 -0
  214. package/dist/render-helpers.js.map +1 -0
  215. package/dist/repositories/agent-profile.d.ts +36 -0
  216. package/dist/repositories/agent-profile.d.ts.map +1 -0
  217. package/dist/repositories/agent-profile.js +153 -0
  218. package/dist/repositories/agent-profile.js.map +1 -0
  219. package/dist/repositories/capability.d.ts +53 -0
  220. package/dist/repositories/capability.d.ts.map +1 -0
  221. package/dist/repositories/capability.js +294 -0
  222. package/dist/repositories/capability.js.map +1 -0
  223. package/dist/repositories/index.d.ts +3 -0
  224. package/dist/repositories/index.d.ts.map +1 -0
  225. package/dist/repositories/index.js +3 -0
  226. package/dist/repositories/index.js.map +1 -0
  227. package/dist/repositories/prompt-stack.d.ts +57 -0
  228. package/dist/repositories/prompt-stack.d.ts.map +1 -0
  229. package/dist/repositories/prompt-stack.js +175 -0
  230. package/dist/repositories/prompt-stack.js.map +1 -0
  231. package/dist/resource-identity.d.ts +33 -0
  232. package/dist/resource-identity.d.ts.map +1 -0
  233. package/dist/resource-identity.js +56 -0
  234. package/dist/resource-identity.js.map +1 -0
  235. package/dist/runtime/capability-runtime.d.ts +95 -0
  236. package/dist/runtime/capability-runtime.d.ts.map +1 -0
  237. package/dist/runtime/capability-runtime.js +991 -0
  238. package/dist/runtime/capability-runtime.js.map +1 -0
  239. package/dist/runtime/profile-runtime.d.ts +14 -0
  240. package/dist/runtime/profile-runtime.d.ts.map +1 -0
  241. package/dist/runtime/profile-runtime.js +56 -0
  242. package/dist/runtime/profile-runtime.js.map +1 -0
  243. package/dist/runtime/prompt-stack-runtime.d.ts +27 -0
  244. package/dist/runtime/prompt-stack-runtime.d.ts.map +1 -0
  245. package/dist/runtime/prompt-stack-runtime.js +149 -0
  246. package/dist/runtime/prompt-stack-runtime.js.map +1 -0
  247. package/dist/runtime/tool-policy-runtime.d.ts +25 -0
  248. package/dist/runtime/tool-policy-runtime.d.ts.map +1 -0
  249. package/dist/runtime/tool-policy-runtime.js +386 -0
  250. package/dist/runtime/tool-policy-runtime.js.map +1 -0
  251. package/dist/runtime/web-editor-runtime.d.ts +11 -0
  252. package/dist/runtime/web-editor-runtime.d.ts.map +1 -0
  253. package/dist/runtime/web-editor-runtime.js +141 -0
  254. package/dist/runtime/web-editor-runtime.js.map +1 -0
  255. package/dist/session-adapter.d.ts +30 -0
  256. package/dist/session-adapter.d.ts.map +1 -0
  257. package/dist/session-adapter.js +167 -0
  258. package/dist/session-adapter.js.map +1 -0
  259. package/dist/session-state.d.ts +23 -0
  260. package/dist/session-state.d.ts.map +1 -0
  261. package/dist/session-state.js +44 -0
  262. package/dist/session-state.js.map +1 -0
  263. package/dist/session-usage.d.ts +65 -0
  264. package/dist/session-usage.d.ts.map +1 -0
  265. package/dist/session-usage.js +134 -0
  266. package/dist/session-usage.js.map +1 -0
  267. package/dist/slot-renderers.d.ts +38 -0
  268. package/dist/slot-renderers.d.ts.map +1 -0
  269. package/dist/slot-renderers.js +285 -0
  270. package/dist/slot-renderers.js.map +1 -0
  271. package/dist/stack-migration.d.ts +35 -0
  272. package/dist/stack-migration.d.ts.map +1 -0
  273. package/dist/stack-migration.js +123 -0
  274. package/dist/stack-migration.js.map +1 -0
  275. package/dist/status-text.d.ts +6 -0
  276. package/dist/status-text.d.ts.map +1 -0
  277. package/dist/status-text.js +11 -0
  278. package/dist/status-text.js.map +1 -0
  279. package/dist/storage.d.ts +24 -0
  280. package/dist/storage.d.ts.map +1 -0
  281. package/dist/storage.js +94 -0
  282. package/dist/storage.js.map +1 -0
  283. package/dist/subagent/fingerprints.d.ts +12 -0
  284. package/dist/subagent/fingerprints.d.ts.map +1 -0
  285. package/dist/subagent/fingerprints.js +17 -0
  286. package/dist/subagent/fingerprints.js.map +1 -0
  287. package/dist/subagent/host-port.d.ts +296 -0
  288. package/dist/subagent/host-port.d.ts.map +1 -0
  289. package/dist/subagent/host-port.js +560 -0
  290. package/dist/subagent/host-port.js.map +1 -0
  291. package/dist/subagent/index.d.ts +16 -0
  292. package/dist/subagent/index.d.ts.map +1 -0
  293. package/dist/subagent/index.js +15 -0
  294. package/dist/subagent/index.js.map +1 -0
  295. package/dist/subagent-host.d.ts +125 -0
  296. package/dist/subagent-host.d.ts.map +1 -0
  297. package/dist/subagent-host.js +327 -0
  298. package/dist/subagent-host.js.map +1 -0
  299. package/dist/template-render.d.ts +18 -0
  300. package/dist/template-render.d.ts.map +1 -0
  301. package/dist/template-render.js +232 -0
  302. package/dist/template-render.js.map +1 -0
  303. package/dist/types.d.ts +213 -0
  304. package/dist/types.d.ts.map +1 -0
  305. package/dist/types.js +2 -0
  306. package/dist/types.js.map +1 -0
  307. package/dist/ui-contribution/contrib-port.d.ts +170 -0
  308. package/dist/ui-contribution/contrib-port.d.ts.map +1 -0
  309. package/dist/ui-contribution/contrib-port.js +640 -0
  310. package/dist/ui-contribution/contrib-port.js.map +1 -0
  311. package/dist/ui-contribution/index.d.ts +3 -0
  312. package/dist/ui-contribution/index.d.ts.map +1 -0
  313. package/dist/ui-contribution/index.js +2 -0
  314. package/dist/ui-contribution/index.js.map +1 -0
  315. package/dist/web-editor/client-script.d.ts +2 -0
  316. package/dist/web-editor/client-script.d.ts.map +1 -0
  317. package/dist/web-editor/client-script.generated.d.ts +2 -0
  318. package/dist/web-editor/client-script.generated.d.ts.map +1 -0
  319. package/dist/web-editor/client-script.generated.js +3 -0
  320. package/dist/web-editor/client-script.generated.js.map +1 -0
  321. package/dist/web-editor/client-script.js +2 -0
  322. package/dist/web-editor/client-script.js.map +1 -0
  323. package/dist/web-editor/client-styles.d.ts +2 -0
  324. package/dist/web-editor/client-styles.d.ts.map +1 -0
  325. package/dist/web-editor/client-styles.generated.d.ts +2 -0
  326. package/dist/web-editor/client-styles.generated.d.ts.map +1 -0
  327. package/dist/web-editor/client-styles.generated.js +3 -0
  328. package/dist/web-editor/client-styles.generated.js.map +1 -0
  329. package/dist/web-editor/client-styles.js +2 -0
  330. package/dist/web-editor/client-styles.js.map +1 -0
  331. package/dist/web-editor/contrib-service.d.ts +41 -0
  332. package/dist/web-editor/contrib-service.d.ts.map +1 -0
  333. package/dist/web-editor/contrib-service.js +174 -0
  334. package/dist/web-editor/contrib-service.js.map +1 -0
  335. package/dist/web-editor/index.d.ts +3 -0
  336. package/dist/web-editor/index.d.ts.map +1 -0
  337. package/dist/web-editor/index.js +2 -0
  338. package/dist/web-editor/index.js.map +1 -0
  339. package/dist/web-editor/line-diff.d.ts +28 -0
  340. package/dist/web-editor/line-diff.d.ts.map +1 -0
  341. package/dist/web-editor/line-diff.js +216 -0
  342. package/dist/web-editor/line-diff.js.map +1 -0
  343. package/dist/web-editor/page.d.ts +4 -0
  344. package/dist/web-editor/page.d.ts.map +1 -0
  345. package/dist/web-editor/page.js +26 -0
  346. package/dist/web-editor/page.js.map +1 -0
  347. package/dist/web-editor/schema-form.d.ts +63 -0
  348. package/dist/web-editor/schema-form.d.ts.map +1 -0
  349. package/dist/web-editor/schema-form.js +213 -0
  350. package/dist/web-editor/schema-form.js.map +1 -0
  351. package/dist/web-editor/server.d.ts +4 -0
  352. package/dist/web-editor/server.d.ts.map +1 -0
  353. package/dist/web-editor/server.js +637 -0
  354. package/dist/web-editor/server.js.map +1 -0
  355. package/dist/web-editor/styles.d.ts +2 -0
  356. package/dist/web-editor/styles.d.ts.map +1 -0
  357. package/dist/web-editor/styles.js +1744 -0
  358. package/dist/web-editor/styles.js.map +1 -0
  359. package/dist/web-editor/types.d.ts +304 -0
  360. package/dist/web-editor/types.d.ts.map +1 -0
  361. package/dist/web-editor/types.js +2 -0
  362. package/dist/web-editor/types.js.map +1 -0
  363. package/dist/web-host.d.ts +56 -0
  364. package/dist/web-host.d.ts.map +1 -0
  365. package/dist/web-host.js +750 -0
  366. package/dist/web-host.js.map +1 -0
  367. package/dist/workspace.d.ts +85 -0
  368. package/dist/workspace.d.ts.map +1 -0
  369. package/dist/workspace.js +409 -0
  370. package/dist/workspace.js.map +1 -0
  371. package/docs/README.md +49 -0
  372. package/docs/concepts/agent-profiles.md +62 -0
  373. package/docs/concepts/prompt-stacks.md +99 -0
  374. package/docs/design/0.5.1-plan.md +237 -0
  375. package/docs/design/README.md +37 -0
  376. package/docs/design/architecture-0.5.md +254 -0
  377. package/docs/design/archive/0.5-full-proposal/0.5-consumer-audit.md +62 -0
  378. package/docs/design/archive/0.5-full-proposal/0.5-inventory.md +208 -0
  379. package/docs/design/archive/0.5-full-proposal/0.5-phase0-decision-drafts.md +237 -0
  380. package/docs/design/archive/0.5-full-proposal/README.md +12 -0
  381. package/docs/design/archive/0.5-full-proposal/architecture-0.5.md +423 -0
  382. package/docs/design/archive/0.5-full-proposal/host-discovery-spike.md +103 -0
  383. package/docs/design/archive/0.5-full-proposal/template-language-spike.md +156 -0
  384. package/docs/design/archive/2026-09-12-system-update-design.md +229 -0
  385. package/docs/design/context-diff-plan.md +78 -0
  386. package/docs/design/decision-template.md +33 -0
  387. package/docs/design/pi-forge-system-update-design-notes.md +157 -0
  388. package/docs/design/roadmap-0.4-archive.md +216 -0
  389. package/docs/design/subagents/design-review.md +220 -0
  390. package/docs/design/subagents/interface-design.md +274 -0
  391. package/docs/design/subagents/sdk-spike-findings.md +117 -0
  392. package/docs/development/architecture-rules.md +148 -0
  393. package/docs/development/complexity-review.md +86 -0
  394. package/docs/development/release.md +59 -0
  395. package/docs/development/roadmap.md +117 -0
  396. package/docs/development/scoped-global-profiles-stacks.md +325 -0
  397. package/docs/development/setup.md +99 -0
  398. package/docs/getting-started.md +96 -0
  399. package/docs/guides/custom-macros-and-slots.md +69 -0
  400. package/docs/guides/debugging.md +39 -0
  401. package/docs/guides/delegation.md +105 -0
  402. package/docs/guides/migrating-to-0.5.md +136 -0
  403. package/docs/guides/pi-1-compatibility.md +160 -0
  404. package/docs/guides/use-cases.md +67 -0
  405. package/docs/guides/web-editor.md +161 -0
  406. package/docs/reference/active-state.md +77 -0
  407. package/docs/reference/capabilities.md +288 -0
  408. package/docs/reference/commands.md +89 -0
  409. package/docs/reference/configuration.md +70 -0
  410. package/docs/reference/features.md +305 -0
  411. package/docs/reference/macros-and-slots.md +103 -0
  412. package/docs/reference/provider-support.md +67 -0
  413. package/docs/reference/public-api.md +133 -0
  414. package/docs/reference/session-cache.md +112 -0
  415. package/docs/reference/stack-schema.md +243 -0
  416. package/docs/reference/subagent-host-port.md +57 -0
  417. package/docs/reference/ui-contribution-port.md +51 -0
  418. package/docs/zh-CN/README.md +41 -0
  419. package/docs/zh-CN/concepts/agent-profiles.md +48 -0
  420. package/docs/zh-CN/concepts/prompt-stacks.md +48 -0
  421. package/docs/zh-CN/getting-started.md +82 -0
  422. package/docs/zh-CN/guides/delegation.md +76 -0
  423. package/docs/zh-CN/guides/migrating-to-0.5.md +121 -0
  424. package/docs/zh-CN/guides/pi-1-compatibility.md +158 -0
  425. package/docs/zh-CN/guides/web-editor.md +134 -0
  426. package/docs/zh-CN/reference/capabilities.md +288 -0
  427. package/docs/zh-CN/reference/commands.md +89 -0
  428. package/docs/zh-CN/reference/provider-support.md +67 -0
  429. package/docs/zh-CN/reference/session-cache.md +112 -0
  430. package/examples/capabilities/review.json +12 -0
  431. package/examples/capabilities/write-tools.json +15 -0
  432. package/examples/custom-system-status-extension/index.ts +144 -0
  433. package/examples/custom-system-status-extension/prompt-stack.json +40 -0
  434. package/examples/default-prompt-stack.json +125 -0
  435. package/examples/fake-assistant-direct-output-prompt-stack.json +48 -0
  436. package/examples/hack-prompt-stack.json +118 -0
  437. package/examples/minimal-prompt-stack.json +40 -0
  438. package/examples/read-first-worker-prompt-stack.json +49 -0
  439. package/examples/validation-issues-prompt-stack.json +38 -0
  440. package/package.json +114 -4
@@ -0,0 +1,67 @@
1
+ # Prompt-stack patterns and examples
2
+
3
+ [Documentation](../README.md)
4
+
5
+ Use these as starting patterns rather than rigid templates. The [default Pi mirror](../../examples/default-prompt-stack.json) is the safest baseline to fork.
6
+
7
+ ## Roleplay and creative writing
8
+
9
+ Put long-lived character rules in a system block, runtime context in appropriate slots, and the current user action in an explicit final user block:
10
+
11
+ 1. System character/personality block.
12
+ 2. Tools, project context, and other runtime slots.
13
+ 3. `chat-history` with `includeLastUserMessage: false`.
14
+ 4. Final user block containing `{{ runtime.lastUserMessage }}`.
15
+
16
+ This keeps the latest request clear and avoids duplication. Static `{{ parameters.char }}` / `{{ parameters.user }}` values work well for character constants. Durable project memory belongs in project files, not parameters.
17
+
18
+ ## Focused code review
19
+
20
+ Fork the default Pi mirror, deny writing tools, wrap prior history as background, omit the latest user message from history, then reinsert it as the explicit review target.
21
+
22
+ Use a rule such as “prioritize correctness, regressions, security, and missing tests.” Keep tools, project context, and history when the reviewer must inspect the repository. Use `append` to retain Pi's normal coding prompt, or `replace` when the stack must fully control prompt and skill visibility.
23
+
24
+ ## Translation mode
25
+
26
+ Create a small stack with a system block for target language, register/tone, and terminology rules. Retain history and a final `{{ runtime.lastUserMessage }}`. Separate literal translation, localization review, and bilingual editing into different stacks when their rules conflict.
27
+
28
+ ## Multi-mode switching
29
+
30
+ Keep independent project files:
31
+
32
+ ```text
33
+ .pi/forge/prompt-stacks/
34
+ coder.json
35
+ writer.json
36
+ translator.json
37
+ ```
38
+
39
+ Switch with `/preset use coder`, `/preset use writer`, or `/preset use translator`. Capture a profile when a capability also needs a specific model and thinking level.
40
+
41
+ ## Read-only scout
42
+
43
+ Allow only `read`, `grep`, `find`, and `ls`, omit editing tools, and cap chat history with `maxChars`. This is useful for exploration turns where the model should report findings without changing files.
44
+
45
+ Tool policy constrains model tool calls but is not an operating-system sandbox. A normal Pi agent may still have other non-tool ways to interact with its host; do not describe a prompt stack alone as process isolation.
46
+
47
+ ## Read first, enable command/edit tools on demand
48
+
49
+ The [Read-first Worker pair](../reference/capabilities.md#read-first-worker) keeps the minimal-worker shape: one role block and chat history. Defaults are `read` and `ls` plus `forge_capability`; one explicitly authorized binding adds `bash` and `edit`. Follow the paired-file setup and ownership/sandbox caveats before trying it.
50
+
51
+ ## Surgical patcher
52
+
53
+ Keep the Pi mirror, require the tools needed for the workflow, strip prior assistant thinking from inserted history, and move project context near the current user turn. This reduces distracting prompt material without removing relevant repository instructions.
54
+
55
+ ## Payload lab
56
+
57
+ Include `active-model` and `date-cwd`, then add compiled regex rules for deterministic redaction or formatting. Pair the stack with `/forge payload next` (or bare `/payload`) or the web editor's capture view to audit exactly what changed. Use `save="path with spaces.json"` when saving a capture; existing files require `--overwrite`.
58
+
59
+ Redaction is limited to the declared patterns and supported text targets. It is useful for known shapes but is not an exhaustive credential scanner or security boundary.
60
+
61
+ ## Pi-docs expert
62
+
63
+ Allow read/search tools, include the `pi-docs` and project-context slots, and keep a focused system instruction. This encourages answers grounded in installed Pi documentation rather than general model memory.
64
+
65
+ ## Trusted runtime status
66
+
67
+ The [custom system-status example](../../examples/custom-system-status-extension/README.md) samples host data when its trusted macro or slot renders during prompt compilation, then exposes that fresh snapshot through `{{ extensions.cpuLoad }}` and a `machine-status` slot. Use this pattern when a new user turn should see current machine state; it is compile-time telemetry, not a continuous background monitor.
@@ -0,0 +1,161 @@
1
+ # Web editor
2
+
3
+ [Documentation](../README.md)
4
+
5
+ Open the browser editor from a trusted Pi project:
6
+
7
+ ```text
8
+ /preset ui
9
+ ```
10
+
11
+ Use `/preset ui restart` to replace its server or `/preset ui stop` to close it.
12
+
13
+ ## Connection and trust
14
+
15
+ The editor binds to an available `127.0.0.1` port and uses a session token. Multiple Pi projects can run editors simultaneously. Lifecycle reinitialization reuses the existing editor URL for the same project when possible.
16
+
17
+ Reads, preview, resources, and payload inspection remain available as appropriate, but writes require Pi to trust the project. Built-in Web writes are constrained to Pi Forge's Preset/Profile, Capability, and trusted Forge configuration storage. Never expose or proxy the editor URL to an untrusted network.
18
+
19
+ Choose a preferred port in `.pi/forge/config.json`:
20
+
21
+ ```json
22
+ {
23
+ "webEditor": {
24
+ "port": 41738
25
+ }
26
+ }
27
+ ```
28
+
29
+ If that port is unavailable, pi-forge selects another and shows the actual URL.
30
+
31
+ ## Interface language
32
+
33
+ The editor interface is available in English and Chinese. Use the language selector in the top bar (Auto / English / 中文); the choice is written to `webEditor.locale` in the project config. `Auto` (the default) follows the browser language, and the initial page render also honors the browser's `Accept-Language` header. Interface chrome, built-in Preset/Profile surfaces, and the preview/diff dock are localized; compiler diagnostics, provider-contributed settings pages, and authored Preset content stay in their authored language.
34
+
35
+ ## Preset workspace
36
+
37
+ The Preset workspace provides:
38
+
39
+ - preset creation with template choices (Default Pi prompt, Empty, Minimal Worker);
40
+ - an ordered **Stack** tab for Block/Slot composition;
41
+ - a **Policy** tab for tool/skill allow/deny resource policy and custom default tools (`tools.initial`);
42
+ - a peer **Capability bindings** tab for associating capabilities (Preset metadata no longer contains bindings);
43
+ - structured metadata, parameters, context, and **Regex** editing;
44
+ - drag-and-drop item order and enable/disable controls;
45
+ - validation and a full compiled preview;
46
+ - registered-tool and loaded-skill search with exact-name chips and wildcard patterns;
47
+ - raw JSON recovery for advanced or unknown fields;
48
+ - native pi-forge JSON import;
49
+ - export, fork, and deletion;
50
+ - payload arming and redacted captured-payload inspection;
51
+ - light and dark themes.
52
+
53
+ ### Editing and inspecting
54
+
55
+ The resource header identifies the Preset being edited separately from whether it is active in the session. The global Session capabilities strip stays available when switching surfaces. Opening **Preset properties**, item properties, rule cards, or binding details does not modify the draft. Preset properties now opens from the resource header without pushing the editor down; its field edits remain in the same Preset draft until Save. Global Session capabilities retains a compact summary and opens the non-modal **Current session** workspace, separate from the edited resource. Effective tools, instruction excerpts, active capabilities and activation controls come first; full instruction bodies, session identity and transport details are expandable. Trust/stale/error and pending/prepared warnings remain visible. Preset status feedback sits in the footer; its Disable action still targets the active Preset, not the selected draft.
56
+
57
+ - **Stack:** Rows show a name/on-off control and one summary line, such as `user · report` or `slot · chat-history`. Full identity remains available in tooltips and **Properties**, including Copy ID. Role and slot selection sit beside Properties; content follows directly. Rows support Enter/Space selection and dragging. A quiet, direct delete button remains in the item header with confirmation. Slot option forms size to their contents rather than stretching their rows.
58
+ - **Row state and pane widths:** Disabled rows use a neutral background, muted text and gray side markers; a thin selection outline means editing, not enabling. Drag the right edge of the Presets or Stack items pane to resize it. Double-click or press Enter on the separator to restore its default; arrow keys adjust it, and Escape cancels an active drag. Width preferences stay in this browser origin, never in Preset JSON, and do not dirty or save a draft. Smaller windows temporarily constrain widths to leave editing room; narrow screens retain the stacked layout.
59
+ - **Regex:** Scan rule names, enable state, stage/effect, and pattern excerpts before expanding a rule. Pattern/replacement editing stays prominent; frequency, targets, roles, and limits are under the rule's advanced section. A dashed list-end entry adds and focuses a rule. Rule/binding removal is confirmed and remains a draft change; use the Preset's **Save** action to persist changes.
60
+ - **Policy:** Permission ceiling and default tools are separate cards. Literal/wildcard editing is advanced; skill-list visibility has its own section and is not an execution sandbox.
61
+ - **Preview / Draft diff / Run diff:** Preview is a separate workspace toggle: opening, closing, or changing editor tabs preserves the current editing page. The boundary chevron widens the sidebar; wide mode offers separate shrink and focus buttons. Leaving focus restores the previous nonfocused layout and keeps the inspection tab, without replacing the draft. Choosing another editing section while focused reveals that editor and retains the dock. The panel initially uses the sidebar. Switching Preview, Draft diff, or Run diff changes only its content and preserves the current width and focus state; focused reading is entered explicitly. Narrow windows stack work areas instead of squeezing four columns; focused reading hides the editor until you return or choose an editing section. Draft diff compares draft compilation with the saved definition; Run diff compares captured provider-turn snapshots. Inspection itself does not send a model request or establish cache hits.
62
+
63
+ Profile editing groups Provider/Model and Thinking/Preset together; immutable identity appears in the heading. Profile and Capability creation still explicitly choose ID and scope. The Advanced Preset tab places editable parameters before the collapsed extension reference catalog. Preview tool details are expandable; section statistics remain available under **Source**.
64
+
65
+ Contributed **Settings** pages auto-save and show pending/saving/saved/error feedback. Failed edits remain in the form. Presets, Capabilities, and Profiles retain their explicit save controls.
66
+
67
+ ### Reading Preview and tool results
68
+
69
+ Preview and Current session use readable excerpts with teal user / blue assistant roles. **Tools** groups start expanded; individual calls and results start as single lines. Fold a group to keep just its call/result counts and explicit failures. Groups cover only uninterrupted tools belonging to one assistant message; intervening messages or instructions stay visible. Missing, conflicting or ambiguous call IDs are not guessed. A uniquely matched file result can show the filename from its actual call arguments.
70
+
71
+ **Results → Original order** is the default. **Pair with calls** places uniquely associated returns beside their calls only within a safe continuous tool interval. Cross-message results and unassociated-result barriers remain in place. This is display pairing, not a timeline or claim about parallel execution; the position markers always refer to the original projection. These view controls do not modify the Preset, provider context or executable tools. Choices are local to the open inspector, not persisted resource settings.
72
+
73
+ Search examines complete message text, roles, source labels, tool names/call IDs, named System section keys and historical declaration JSON. Matching groups, text and declarations open temporarily; clearing search restores prior disclosure choices and reading positions. **Full text** expands the inspection text; **Source** exposes provenance and existing text estimates. Named System sections distinguish setting, setting empty, and removal; historical tool declarations remain separate from currently selected tools. The existing estimates still describe the compiler's text projection, not full tool schemas, structured arguments or media.
74
+
75
+ **Historical transcript tool declarations** keep each added tool collapsed to one line: name, an excerpt of its real description, and a count when the schema explicitly lists top-level properties. This is a declared-property count, not inferred arity through references/composites; an unknown schema does not mean zero arguments. Open a tool to inspect or copy its complete Preview declaration JSON (name, description and parameters when present). Removed declarations retain their names only; no missing schema is reconstructed. These historical records do not select executable tools.
76
+
77
+ Editing within the same Preset keeps inspection choices and unchanged tool reading positions. While the new draft compiles, the previous preview is explicitly marked pending and its inspection controls are paused. A real resource switch still resets local inspection state. On short narrow screens the Preset shell scrolls as needed so headers cannot squeeze the editor/inspection dock to zero height.
78
+
79
+ **Copy report** retains the compiler text report. Copy a tool row for its complete displayed parameters/output. Structured argument JSON is a representation of the compiled object, not raw provider-wire bytes; images and unsupported content parts have explicit placeholders. Text copying is not a complete multimodal export. Folding, pairing and excerpts do not reduce model context, token usage, or establish cache savings. Draft/Run diff and request invalidation retain their existing meanings.
80
+
81
+ ### Inspecting a Capability's context impact
82
+
83
+ The **Current session** workspace places capability controls and tools on the left, and the session projection on the right (stacked on narrow screens). It shows current effective tools and a short excerpt of each active instruction snapshot. A successful Enable/Disable/Reset in this browser also shows the observed tool additions/removals; this is not a persistent history. A Capability's configured tool adjustments are labeled separately: overlapping Capabilities can produce no net tool change.
84
+
85
+ **Locate in context** keeps the controls visible and highlights related projected update blocks, scrolling to the latest match. Normal updates do not steal the reading position. The workspace inspects the **active saved Preset + current session capabilities**, not whichever Preset is being edited. The Preset editor still supports simultaneous editing and **Preview / Draft diff / Run diff**; switching workspaces preserves its draft, selection, inspection tab and width/focus.
86
+
87
+ **After switching Presets:** if a turn ran under A and you then activate saved Preset B, this projection updates to B with the existing branch history and current capabilities, without sending a model request. Merely selecting/editing B leaves A active. Earlier A messages and historical declarations can still appear as history; that does not mean B failed to activate. This is a current composition preview, not the last sent request or an exact prediction of the next provider payload. Run diff retains captured requests; Payload shows the capture that was armed, not arbitrary past turns. Capture is at the provider hook and can precede later plugin shaping.
88
+
89
+ Background status checks are quiet and do not reload the capabilities catalog or disable otherwise usable controls on each poll. Catalog discovery occurs on workspace entry, explicit refresh and relevant mutation follow-up. Returning invalidates late reads from a previous visit without discarding in-flight mutation receipts. Projection reads follow semantic state changes, rather than a second polling loop. During same-branch refresh a labeled previous projection remains visible; stale/untrusted or changed session/branch data is invalidated.
90
+
91
+ Block numbers apply only to that preview. Native System sections and attributed user-fallback updates retain their actual roles; stopping a Capability does not erase its earlier updates. If no reliable match is visible, the inspector says so rather than guessing. This first iteration requires a trusted session and an active Preset; full event-history browsing is not included.
92
+
93
+ Inspection is a local read: it neither prepares/delivers a request nor changes tools or session history. It is not a captured provider payload or evidence of cache reuse; use Run diff/Payload and reported usage for those separate observations.
94
+
95
+ ### Tool selection and default tools editor
96
+
97
+ The **Policy** tab includes an opt-in default tools editor (`tools.initial?: string[]`):
98
+
99
+ - **Default tools picker:** A searchable, collapsible grouped tool picker organizes tools by SDK `sourceInfo` (Pi built-in tools, packages, and top-level entry points). Group checkboxes select/deselect the currently filtered group. **Enter tool names manually** preserves literal/offline-name entry, including in the Capability editor.
100
+ - **Exact names:** The picker saves concrete tool names. It does not persist package references or auto-install packages, and newly introduced package tools are not automatically added. Inactive registered tools are visible in the picker; unloaded tools are unavailable in the session, but manual saved references are preserved rather than discarded.
101
+ - **Omission vs. zero defaults:** Omitting custom defaults preserves legacy behavior (selective allow selects catalog matches; unrestricted/deny retains or filters the session baseline); setting an empty list (`[]`) sets zero active tools by default.
102
+ - **Authoritative ceiling:** The advanced literal and wildcard allow/deny policy is retained and acts as an authoritative ceiling; tools blocked by allow/deny cannot be selected as defaults.
103
+ - **Runtime behavior:** Configured defaults serve as the active base while the preset is active (not a one-time reset per turn). Disabling a capability recomputes defaults plus remaining active capabilities; disabling the preset restores the reconciled session baseline, while switching recomputes under the new Preset and remaining unbound capabilities.
104
+
105
+ ### Capability bindings tab
106
+
107
+ Capability bindings are managed in the peer **Capability bindings** tab:
108
+
109
+ - Each binding card shows one scoped capability reference and the model-activation authorization toggle. Binding ID belongs to its expandable details, not a permanently visible header field.
110
+ - **Advanced** reveals binding ID and overrides (content replace/append, tool add/remove). The live source-effective preview has its own disclosure.
111
+ - Tool overrides choose **Inherit** or **Custom override**, with integrated tool pickers matching the policy picker. A custom list may be empty: `[]` replaces that source add/remove list with zero entries, while inheritance omits the override. It does not clear every session tool or bypass other permission limits.
112
+ - Binding order is catalog order, not execution priority; the editor no longer offers up/down controls. Direct removal requires confirmation and stays in the Preset draft until Save. Expanded details follow their binding when another row is deleted.
113
+
114
+ ### Save behavior and execution impact
115
+
116
+ **Activate** uses the saved Preset. It is unavailable while the editor has unsaved changes; save explicitly first. Saving and activating are not a combined transaction.
117
+
118
+ - **Capabilities surface:** Saving a capability updates its library definition only and does not enable it in the current session.
119
+ - **Presets:** Saving an **inactive** Preset updates its configuration file without selecting or activating it. Crucially, saving the **currently active** Preset refreshes its policy immediately in the active session (synchronizing live tool and capability authorization policy), without replacing frozen active capability snapshots.
120
+
121
+ Existing IDs are immutable during edit. Use **More → Fork** to create a different ID without breaking Profile references or the active selection. The **New preset**, **Import**, and **Fork** dialogs collect name, ID, and target scope (default `Project`) before writing: `Global` targets the user-global `~/.pi/forge/prompt-stacks`, `Project` targets `.pi/forge/prompt-stacks`. Those paths keep their pre-0.5.3 names for compatibility.
122
+
123
+ The **New preset** dialog offers three initial templates:
124
+ - **Default Pi prompt:** Preserves Pi's built-in prompt layout with movable slots, tools, guidelines, docs, project context, skills, and chat history.
125
+ - **Empty:** Starts with no preset items or tool/skills policies (`items: []`). This does not mean zero context or tools; Pi automatically retains its base system prompt and history when no composed system prompt is provided.
126
+ - **Minimal Worker:** Mirrors the DeepSeek Harness minimal shape (`examples/minimal-prompt-stack.json`) with a single-line system persona ('You are a helpful software engineer assistant.'), chat history with summaries disabled, and restricted tools (`bash` and `edit` only).
127
+
128
+ Choosing a template automatically updates the suggested preset name as long as it has not been customized by the user. The **Import** and **Fork** dialogs continue to use the supplied or loaded source preset, not a creation template.
129
+
130
+ The dashed creation entry sits below the Preset list; **Add content / slot** below the item list lets you choose Block or Slot. Less-used capture, fork, import, export, and delete actions live under **More** so the Stack and Preview/Diff panes keep the available viewport. Preset rows show a `global` badge, and save/delete routes use `global:<id>` for exact global mutations. Legacy resources remain editable in place.
131
+
132
+ Saves, imports, forks, and deletes reload Preset state into the current Pi session. When another surface changes a referenced Preset, returning to Profiles refreshes Profile resolution.
133
+
134
+ ### Compatibility
135
+
136
+ Presets configured with `tools.initial` require updated Forge. Older Forge versions may ignore `tools.initial` and revert to legacy selection behavior (selective allow selects catalog matches; unrestricted/deny retains or filters the session baseline) (not downgrade-compatible). These changes require Forge 0.5.5; the minimum host requirement remains Pi 0.87.0 (published 0.5.7 peer range was `>=0.87.0 <0.88.0`; unreleased source compatibility supports `>=0.87.0 <0.88.0 || 0.99.0 || 0.99.1 || 0.99.2 || >=1.0.0 <1.1.0`; see [Pi 1.0 compatibility guide](pi-1-compatibility.md)).
137
+
138
+ ## Agent-profile workspace
139
+
140
+ The Profile list shows each Profile's ID, display metadata, model, thinking level, Preset, resolution state, auto-activation, last-applied provenance, and a `project`/`global` scope badge. Same-ID shadow pairs are marked `shadows global:<id>` or `shadowed by project:<id>`.
141
+
142
+ Profile and Capability libraries place their dashed creation entry below the resource list. Creation editors put name first and choose scope in one place; they keep their full model/content fields and do not write incomplete resources merely to create a list row.
143
+
144
+ Trusted projects can create Profiles in either scope: the scope field in the creation editor (default `project`) chooses whether to write the user-global `~/.pi/forge/agent-profiles` or the project `.pi/forge/agent-profiles`. Global Profiles can be edited, validated, saved, applied once, and deleted through explicit `global:<id>` routes; unqualified routes stay project-only. When editing a global Profile, the Preset dropdown offers only global Presets. Model choices come from Pi's model registry, thinking choices reflect model support, and Preset choices come from the shared repository. The editor rejects a second auto-activation Profile within the same scope.
145
+
146
+ The runtime/provenance card separates current runtime state, last-applied snapshot, source-definition changes, and field-level runtime drift.
147
+
148
+ ## Delegation
149
+
150
+ Delegation configuration is not part of the main editor. The optional `@zihanw/pi-forge-subagents` package owns the dedicated `.pi/forge/subagents.json` and `~/.pi/forge/subagents.json` files. Read [foreground delegation](delegation.md) before enabling a profile.
151
+
152
+ ## Migration
153
+
154
+ To copy legacy `.pi/prompt-stacks` into `.pi/forge/prompt-stacks`:
155
+
156
+ ```text
157
+ /preset migrate-stacks --dry-run
158
+ /preset migrate-stacks
159
+ ```
160
+
161
+ Review before adding `--overwrite` or `--delete-legacy`.
@@ -0,0 +1,77 @@
1
+ # Active-state bus contract
2
+
3
+ [Documentation](../README.md)
4
+
5
+ Status: neutral, versioned. This is an optional appearance/session metadata seam consumed over the Pi event bus. It is not a package import entry point and has no Pi Pet-specific dependency. Consumers attach to `pi.events` (or `ctx.events`) and must treat every failure cosmetically.
6
+
7
+ ## Channels
8
+
9
+ - Snapshot/change: `@zihanw/pi-forge/active-state/v1`
10
+ - Snapshot request: `@zihanw/pi-forge/active-state/request/v1`
11
+
12
+ The production publisher is the main pi-forge extension. It registers the request listener on attach and removes it on disposal/session switch. No unbounded retries or timers are used.
13
+
14
+ ## Request
15
+
16
+ ```json
17
+ { "schemaVersion": "1", "sessionId": "raw Pi session-manager id" }
18
+ ```
19
+
20
+ `sessionId` is optional. When present, the publisher answers only if it matches the currently bound session; when omitted, it answers the current snapshot. A late subscriber can therefore request the current state after missing an earlier publish. Malformed or oversized requests are ignored.
21
+
22
+ ## Event
23
+
24
+ ```json
25
+ {
26
+ "schemaVersion": "1",
27
+ "sessionId": "raw Pi session-manager id",
28
+ "instanceId": "uuid",
29
+ "revision": 1,
30
+ "stackKey": "global:slug",
31
+ "profileKey": null,
32
+ "projectKey": "64 lower hex sha256"
33
+ }
34
+ ```
35
+
36
+ | Field | Meaning |
37
+ | --- | --- |
38
+ | `schemaVersion` | Always `"1"`. Unknown versions are rejected. |
39
+ | `sessionId` | Raw Pi session-manager ID for the bound session. |
40
+ | `instanceId` | Fresh bounded publisher instance (`^[A-Za-z0-9_-]{1,128}$`, UUID-compatible) per attach/epoch. A new instance retires the old one. |
41
+ | `revision` | Monotonic safe integer within one instance. |
42
+ | `stackKey` | Effective scoped prompt-stack key, or `null` when disabled/off. |
43
+ | `profileKey` | Compatible applied-profile provenance key, or `null` (see below). |
44
+ | `projectKey` | Opaque SHA-256 project identity, or `null`. Never a raw path. |
45
+
46
+ No other fields cross the channel. Prompt text, file paths, tokens, credentials, model configuration, tool policy, and character data are never included.
47
+
48
+ ## Identity and scope rules
49
+
50
+ - Scoped keys use `^(global|project):[A-Za-z0-9][A-Za-z0-9._-]{0,127}$`. Invalid values become `null`; scoped IDs never cause filesystem access.
51
+ - `projectKey = sha256("pi-forge-project-v1\0" + hostname + "\0" + path.resolve(cwd))`, lower hex. Only the digest crosses the bus, so two working directories are isolated without revealing either path.
52
+ - Global resource bindings ignore `projectKey`.
53
+ - Project resource bindings **require** `projectKey`. A project-scoped `stackKey`/`profileKey` with a `null` project key fails closed. When the session `cwd` is empty or unresolvable, the publisher nulls project-scoped `stackKey`/`profileKey` rather than emit a snapshot its own validator rejects.
54
+ - `instanceId` uses the bounded UUID-compatible scalar grammar above; control characters, path separators, dots, and other punctuation are rejected. Real session IDs remain raw bounded strings (1..1024 chars).
55
+ - `profileKey` is derived from `lastAppliedProfile` only while its recorded `snapshot.promptStack` equals the current effective scoped stack (`null` equals disabled). It is cosmetic compatible-provenance identity, not a claim that the current model, thinking level, or tools still match the profile. Manual stack drift clears an unrelated profile binding.
56
+
57
+ ## Publishing lifecycle
58
+
59
+ The publisher emits on: initial session bind/restore, session start, tree navigation, compaction, explicit preset changes (`enable`, `none`/off), profile apply/update, web-editor updates, and disposal. Workspace changes publish without any provider/model call.
60
+
61
+ Rules:
62
+
63
+ 1. `instanceId` is per attach. Switching sessions emits a final cleared snapshot for the old session, then a new instance for the new session.
64
+ 2. `revision` is monotonic within an instance. At the `Number.MAX_SAFE_INTEGER` boundary the publisher rotates to a fresh instance epoch instead of wrapping the same instance back to `1`. A snapshot request repeats the current revision rather than advancing it.
65
+ 3. Disposal emits a cleared snapshot (`stackKey`/`profileKey`/`projectKey` as available, stack/profile `null`) and unregisters the request listener.
66
+ 4. Session start/tree/compact suspend publication and request replies across `restoreBranchScopedRuntime`, then bind and publish one latest coherent snapshot. A failed restore detaches/clears instead of leaving the old session bound to the new workspace.
67
+ 5. Optional listeners never alter Forge compilation, tool policy, or provider behavior; a throwing reader/listener/transport is isolated. The shutdown path attempts every teardown step even if an optional transport rejects `emit`/`on`/`unsubscribe`.
68
+ 6. The same live instance/epoch is retained across a same-session compaction; cosmetic state is not cleared/recreated needlessly.
69
+
70
+ ## Consumer expectations (normative)
71
+
72
+ - Accept only events whose `sessionId` matches the consumer's current Pi canonical session identity.
73
+ - Reject stale/duplicate revisions and snapshots from retired instances with bounded tracking; never retry unboundedly.
74
+ - Fail closed on malformed or oversized payloads, wrong schema versions, or project-scoped bindings without a `projectKey`.
75
+ - Clear context on an explicit cleared snapshot; do not treat bus traffic as an implicit identity/status/auth/Team change.
76
+
77
+ See [public API policy](public-api.md) for how this bus contract relates to the package import surfaces.