@jadelclemens/pi-forge 0.0.0-stage → 0.6.1

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,103 @@
1
+ # Pi cross-extension host-discovery spike
2
+
3
+ [Design index](../../README.md) · [0.5 architecture plan](../../architecture-0.5.md) · [0.5 migration inventory](0.5-inventory.md)
4
+
5
+ Status: completed Phase 0 spike; architecture decision pending
6
+
7
+ Date: 2026-08-17
8
+
9
+ ## Question
10
+
11
+ Can a separately installed `pi-forge-subagents` Pi extension reliably discover
12
+ and use the active main `pi-forge` extension without importing its internal
13
+ runtime state or relying on a process-global registry?
14
+
15
+ ## Environment and method
16
+
17
+ - Tested against the repository's installed
18
+ `@earendil-works/pi-coding-agent` 0.83.0 fixture.
19
+ - Used Pi's exported `createEventBus`, `createExtensionRuntime`, and actual
20
+ `loadExtensionFromFactory` loader. The factories used only `pi.events`.
21
+ - This was an in-memory Phase-0 harness, not a shipped extension or production
22
+ host-port implementation.
23
+
24
+ The harness covered both extension load orders, compatible and incompatible
25
+ versions, and unregistering a host listener. All cases passed:
26
+
27
+ | Case | Result |
28
+ |---|---|
29
+ | Host factory loads before client factory | Client discovery receives one compatible host reply |
30
+ | Client factory loads before host factory | Client's availability listener receives the later host announcement |
31
+ | Client requires an unsupported version | No host is accepted |
32
+ | Host unregisters its listener | A subsequent discovery request receives no reply |
33
+
34
+ ## Observations
35
+
36
+ 1. `ExtensionAPI.events` is a shared event bus across extension factories
37
+ loaded into the same Pi runtime.
38
+ 2. The bus exposes only `emit(channel, data)` and `on(channel, handler)`, with
39
+ an unsubscribe function. It does not expose a service registry, request
40
+ return values, sender identity, serialization, timeout, version negotiation,
41
+ duplicate-host handling, or lifecycle ownership.
42
+ 3. Pi wraps each event handler in an asynchronous error boundary. `emit()` is
43
+ therefore fire-and-forget; callers must not depend on handler order or a
44
+ synchronous reply, even though a handler with no initial `await` may appear
45
+ to reply synchronously in a simple test.
46
+ 4. The bus is in-process. It can coordinate packages loaded into one Pi
47
+ invocation, but it is not a cross-process, remote, or security boundary.
48
+ 5. A direct import of a module-level workspace singleton remains unsuitable:
49
+ Pi package installation can produce independent package instances, and that
50
+ mechanism provides no duplicate-host or reload semantics.
51
+
52
+ ## Recommended decision candidate
53
+
54
+ Use Pi's event bus as the transport for a **versioned, session-scoped Forge host
55
+ RPC protocol**. Do not use a process registry or a direct reference to
56
+ `ForgeWorkspace`.
57
+
58
+ The port must use plain, validated data messages rather than function callbacks
59
+ or the return value of `emit()`. A minimal protocol has these message families:
60
+
61
+ | Channel family | Direction | Required behavior |
62
+ |---|---|---|
63
+ | `@jadelclemens/pi-forge/host/v1/discover` | Client → host | Carries request ID, client identity/version, and supported protocol range |
64
+ | `@jadelclemens/pi-forge/host/v1/available` | Host → clients | Announces host ID, protocol version, capability set, and lifecycle generation after discovery listener registration |
65
+ | `@jadelclemens/pi-forge/host/v1/reply` | Host → client | Correlates discovery or operation result with request ID; carries typed success/failure data |
66
+ | `@jadelclemens/pi-forge/host/v1/request` | Client → host | Invokes only documented operations using validated request data |
67
+ | `@jadelclemens/pi-forge/host/v1/update` | Host → client | Optional bounded progress/resource-change events correlated to subscription or run IDs |
68
+ | `@jadelclemens/pi-forge/host/v1/unavailable` | Host → clients | Invalidates host ID/generation during disposal or replacement |
69
+
70
+ The final operation catalogue is still open, but must expose results and
71
+ snapshots—not Pi contexts, `ForgeWorkspace`, loaded resource objects, web-editor
72
+ state, callbacks, or internal registries. Cancellation must be a request by
73
+ run ID; it must not transfer `AbortSignal` objects through the port.
74
+
75
+ ## Required protocol rules before implementation
76
+
77
+ - Clients subscribe to reply, availability, update, and unavailable events
78
+ before announcing/discovering; they use a bounded timeout and clean up all
79
+ listeners.
80
+ - A host registers discovery/request listeners before sending `available`.
81
+ - Host and client validate every message and ignore unknown protocol versions,
82
+ malformed payloads, stale generations, and unrelated request IDs.
83
+ - More than one live compatible host is an explicit `host.duplicate` failure;
84
+ the client must not silently choose a host by load order. Incompatible hosts
85
+ are reported distinctly.
86
+ - `ForgeWorkspace` owns host registration, generation, and disposal. On Pi
87
+ session shutdown/reload it sends `unavailable`, unregisters listeners, and
88
+ rejects new work; clients invalidate outstanding handles and report a clear
89
+ unavailable diagnostic.
90
+ - The port is an integration contract, not a trust boundary. Pi extensions
91
+ already execute in the same trusted process; the host must not transmit raw
92
+ credentials, arbitrary live contexts, or undeclared project data.
93
+ - The optional package must remain usable as an ordinary Pi extension only when
94
+ the main host is present and protocol-compatible. Its absence must leave the
95
+ main pi-forge extension fully functional.
96
+
97
+ ## Limits and follow-up
98
+
99
+ This validates the event-bus transport in Pi 0.83.0 only. The Phase-0 Pi
100
+ compatibility gate still needs a documented range and packed-install matrix that
101
+ includes the release-time Pi version. The protocol, public operations, package
102
+ versioning, configuration ownership, and migration remain architecture decisions
103
+ to be accepted before Phase 5 implementation.
@@ -0,0 +1,156 @@
1
+ # Template-language and compiler spike
2
+
3
+ [Design index](README.md) · [0.5 architecture plan](architecture-0.5.md) · [0.5 migration inventory](0.5-inventory.md)
4
+
5
+ Status: completed Phase 0 spike; architecture decision pending
6
+
7
+ Date: 2026-08-17
8
+
9
+ ## Question
10
+
11
+ Which template language can replace 0.4 macros while keeping prompt compilation
12
+ deterministic over immutable inputs, statically analyzable, migrationable, and
13
+ free of arbitrary evaluation or template loading?
14
+
15
+ ## Characterized 0.4 surface
16
+
17
+ The current macro language mixes four separate concerns:
18
+
19
+ | Concern | 0.4 behavior | 0.5 direction |
20
+ |---|---|---|
21
+ | Immutable runtime values | Latest user message, date/time, cwd, selected tools, active model | Keep as explicit values in `PromptEnvironment` |
22
+ | Static reusable values | `stack.variables`, referenced as `{{name}}` | Keep as JSON-compatible immutable `parameters` |
23
+ | Text transforms | `trim`, `upper`, `lower`, `json`, `xml`, including nesting | Retain only as a finite, pure filter set if accepted |
24
+ | Control flow | `ifvar`, `ifeq`, `iftools`, `ifslot`, with lazy branches | Replace only with a parsed, side-effect-free conditional form if accepted |
25
+ | Mutable state | Turn/session variables plus set/get/clear macros and `variables` slot | Remove; emit migration diagnostics |
26
+ | Executable extension code | Trusted custom macro and slot renderers receive live runtime objects | Replace only through a separately accepted, immutable template/slot port |
27
+
28
+ The current examples demonstrate simple parameter and runtime interpolation;
29
+ the image-reader and SillyTavern examples also depend on nested filters,
30
+ conditionals, and mutable variables. SillyTavern is already removed from 0.5
31
+ scope. Any remaining non-mechanical construct must be diagnosed by migration,
32
+ not silently approximated.
33
+
34
+ ## Requirements
35
+
36
+ The v2 engine must provide one `parse → analyze → render` contract and meet all
37
+ of the following:
38
+
39
+ - parsing has no filesystem, network, process, clock, environment, or Pi access;
40
+ - rendering receives only a frozen normalized environment and parsed template;
41
+ - undefined paths, invalid filters, invalid conditions, parse errors, recursion,
42
+ and output-limit breaches are typed errors, never silent mutation or ambient
43
+ fallback;
44
+ - analysis returns source-spanned dependencies on environment paths, filters,
45
+ control predicates, and registered template/slot capabilities;
46
+ - no includes, extends, imports, macros, function calls, loops, arbitrary
47
+ property traversal, or general expression evaluation;
48
+ - whitespace is preserved unless a deliberately documented syntax construct
49
+ changes it; rendering has a bounded output size;
50
+ - preview, parent runtime, and subagent preparation invoke the same engine and
51
+ receive recorded environment/provenance values.
52
+
53
+ ## Candidate comparison
54
+
55
+ | Candidate | Parse/analyze/render fit | Restriction and determinism | Migration fit | Result |
56
+ |---|---|---|---|---|
57
+ | General Jinja-like engine (Nunjucks) | Has parsing/rendering and strict-undefined option | Fails the trust requirement: its own documentation says it does not sandbox user-defined templates; it supports loaders, includes, extensions, async behavior, and a rich expression language | Familiar delimiters, but an unsafe/surplus language would need a fragile denylist | Reject |
58
+ | Restricted LiquidJS wrapper | Provides parsed templates and documented static analysis | Better parser option, but its Liquid tags, includes, filters, and plugin model would still require a security-sensitive allowlist/wrapper; syntax is not Jinja-compatible | Requires a new Liquid migration plus wrapper-specific dependency semantics | Do not adopt for 0.5 |
59
+ | Small Forge AST grammar | Contract is designed exactly for parse/analyze/render and the allowed syntax is closed | No ambient capabilities or loaders by construction; all values and filters are explicit | Breaking but small, predictable, and mechanically migrates common interpolation | Recommended candidate |
60
+
61
+ Nunjucks documents both its lack of sandboxing and its extensible loaders,
62
+ includes, custom tags, and asynchronous behavior. [Nunjucks API](https://mozilla.github.io/nunjucks/api.html)
63
+ LiquidJS documents parsed-template reuse and static analysis, but is a broader
64
+ Liquid language with tags and plugins rather than the deliberately closed v2
65
+ language. [LiquidJS static analysis](https://liquidjs.com/tutorials/static-analysis.html)
66
+
67
+ ## Recommended decision candidate: `forge-v1`
68
+
69
+ Adopt a small parsed Forge template grammar. It resembles Jinja only at the
70
+ delimiter level; it must not claim Jinja compatibility.
71
+
72
+ ### Closed grammar
73
+
74
+ ```text
75
+ text := any text outside delimiters
76
+ output := "{{" path filters? "}}"
77
+ filters := ("|" filterName)*
78
+ if-block := "{% if" predicate "%}" template
79
+ ("{% else %}" template)? "{% endif %}"
80
+ path := identifier ("." identifier)*
81
+ predicate := path | path "==" json-string | path "!=" json-string
82
+ ```
83
+
84
+ The only initially proposed paths are `parameters.*` and documented
85
+ `runtime.*` fields. No bracket access, method invocation, object construction,
86
+ numeric arithmetic, loops, user-defined functions, imports, includes, extends,
87
+ macro definitions, or arbitrary expressions are in the grammar.
88
+
89
+ The initially proposed filters are `trim`, `upper`, `lower`, `json`, and `xml`.
90
+ They are pure, unary, versioned built-ins; unknown filters are errors. Tool and
91
+ slot conditions, if retained, must be represented as documented boolean values
92
+ in the environment rather than callable helpers. The exact v2 environment field
93
+ names remain part of the architecture decision.
94
+
95
+ ### Engine contract
96
+
97
+ ```ts
98
+ interface TemplateEngine {
99
+ readonly id: "forge-v1";
100
+ readonly version: 1;
101
+ parse(source: string): TemplateParseResult;
102
+ analyze(ast: TemplateAst): readonly TemplateDependency[];
103
+ render(ast: TemplateAst, environment: PromptEnvironment): TemplateRenderResult;
104
+ }
105
+ ```
106
+
107
+ `PromptEnvironment` is a frozen, JSON-compatible snapshot. It must carry an
108
+ explicit timestamp and timezone/formatting policy, cwd, model identity, selected
109
+ tool facts, latest-user-message data, static parameters, and the Pi-derived
110
+ inputs required by slots as separate structured values. The compiler—not the
111
+ engine—owns history placement, structured slots, tool/skill policy, base-system
112
+ prompt handling, message assembly, and regex stages.
113
+
114
+ The render receipt must identify engine ID/version, template dependencies,
115
+ environment/provenance fingerprint, diagnostics, and output size. Dependencies
116
+ are authoritative for preview and subagent preparation; no consumer may
117
+ re-parse syntax independently.
118
+
119
+ ### Extension boundary implication
120
+
121
+ The current `registerMacro()` API cannot cross this boundary unchanged because
122
+ it receives live runtime objects and can mutate or observe ambient state. The
123
+ template decision does not yet authorize a replacement API. If custom template
124
+ values, filters, or slots remain in 0.5, a separate accepted port must give them
125
+ only frozen input, declared dependency/capability metadata, bounded output, and
126
+ a pure-rendering contract. Trusted extension code is not a security boundary;
127
+ the core engine nevertheless must remain deterministic when no such extension
128
+ port participates.
129
+
130
+ ## Migration disposition
131
+
132
+ | 0.4 construct | Candidate v2 migration | Result when not mechanical |
133
+ |---|---|---|
134
+ | `{{name}}` for a known static value | `{{ parameters.name }}` | Warn when name could be a custom macro or ambiguous |
135
+ | `{{lastUserMessage}}`, date/time, cwd, model, selected tools | Corresponding documented `runtime.*` path | Mechanical only after field names are accepted |
136
+ | Nested value filters | Equivalent output plus pipeline where semantics match | Diagnose when nested arguments or behavior differ |
137
+ | `ifvar` / `ifeq` | Parsed `if` predicate where semantics match | Diagnose `iftools`/`ifslot` until boolean environment fields are accepted |
138
+ | Custom macros and slots | New port only after its decision | Diagnose; no compatibility execution shim |
139
+ | Set/get/clear variable macros and `variables` slot | None | Error-level migration diagnostic; removed behavior |
140
+ | Unknown macros / unresolved-policy behavior | None | Error-level diagnostic in v2; no keep/warn rendering policy |
141
+
142
+ The migration tool must preserve the original source, produce a field/item-level
143
+ report, and refuse a partly transformed file unless the user explicitly accepts
144
+ diagnostics. It must not rewrite SillyTavern inputs in 0.5.
145
+
146
+ ## Required acceptance and implementation evidence
147
+
148
+ Before Phase 3 implementation, accept the grammar, exact environment schema,
149
+ filter/condition set, undefined/error semantics, output limits, engine ID in
150
+ stack schema v2, extension-port disposition, and migration behavior.
151
+
152
+ Implementation then needs characterization and conformance coverage for parser
153
+ errors, source spans, strict undefined values, filters, nested/else conditionals,
154
+ whitespace, output limits, deterministic repeated render, dependency receipts,
155
+ preview/runtime identity, and migration diagnostics for every removed mutable or
156
+ custom-macro construct.
@@ -0,0 +1,229 @@
1
+ # @jadelclemens/pi-forge `system_update` Design Notes
2
+
3
+ **Status:** Current plan (revised 2026-09-12). Supersedes the 2026-09-10
4
+ exploration draft, which assumed pi-forge would implement the full
5
+ persistence/projection/transport stack itself. Upstream Pi has since started
6
+ building the primitive natively, so pi-forge's scope shrinks to the
7
+ workflow layer.
8
+
9
+ **Target:** 0.5.5+, blocked on an upstream Pi redo (see §2).
10
+
11
+ ---
12
+
13
+ ## 1. TL;DR — Current Plan
14
+
15
+ `system_update` is a **session-timeline event**, not a mutation of the
16
+ top-level system prompt. That core decision from the original draft survives.
17
+ What changed is who builds what:
18
+
19
+ - **Upstream Pi is building the primitive**: a first-class `SystemMessage`
20
+ (`role: "system"`) appended to the transcript, rendered natively on models
21
+ that support mid-conversation system messages and as a tagged user turn
22
+ elsewhere. Persistence, resume, compaction, and provider rendering are all
23
+ owned by the harness.
24
+ - **pi-forge builds only the workflow layer**: an append-only event log, a
25
+ reducer over it, the `/system-update` command family, preset-declared
26
+ dormant instruction blocks, and a permission-gated agent tool.
27
+ - **Integration is declarative**: pi-forge renders its active update set into
28
+ `systemPromptOptions.sections` and lets the harness diff engine emit the
29
+ deltas. pi-forge no longer returns a fully-compiled replacement string for
30
+ this path.
31
+
32
+ Discarded from the original draft: the custom-entry + self-written projector
33
+ design, the `custom_message` transport, the provider transport matrix, and
34
+ the six-phase rollout. See §5 for why.
35
+
36
+ ---
37
+
38
+ ## 2. Upstream Landscape (snapshot 2026-09-12)
39
+
40
+ ### 2.1 The PRs
41
+
42
+ - **PR #9116** (`system-role` branch, pi-ai layer): adds `SystemMessage` to
43
+ the `Message` union. Appended to the transcript, never folded into
44
+ `Context.systemPrompt`. Persisted as ordinary message entries; compaction
45
+ cut points and summaries understand them (rendered as `[System]:` in
46
+ summaries); interactive mode hides them.
47
+ - **PR #9117** (`system-tool-deltas` branch, stacked, coding-agent layer):
48
+ the first rendered prompt of a session becomes a stored **baseline**;
49
+ anything that changes afterwards is appended as a provider-neutral system
50
+ message delta. On resume/tree navigation the stored baseline is reinstated
51
+ so a resumed session sends byte-identical cached prefixes. After
52
+ compaction, the effective prompt folds into a fresh baseline at no extra
53
+ cost.
54
+
55
+ **Both PRs were closed by the author on 2026-09-11 with "I will redo this."**
56
+ Direction is alive; implementation is being redone; timeline unknown.
57
+ Community testing (13-scenario harness, all green) flagged two design
58
+ issues likely motivating the redo: ~10 KB per-prompt-entry session bloat
59
+ from storing rendered baselines, and silent tool disappearance on
60
+ non-supporting models across resume.
61
+
62
+ ### 2.2 Verified behavior of the PR branch (local clone: `~/programming/pi-pr9117`)
63
+
64
+ Measured against the actual `system-tool-deltas` build:
65
+
66
+ - `sections: Record<string, string>` on `systemPromptOptions` renders as
67
+ XML-wrapped blocks (`<name>\n...\n</name>`), diff-keyed as `section:name`.
68
+ - `diffSystemPrompts` behavior matrix:
69
+ - identical pieces → `unchanged` (no cost)
70
+ - section added → update delta: "The following `<name>` system guidance
71
+ now applies: ..."
72
+ - section removed → retraction: "The previous `<name>` system guidance no
73
+ longer applies."
74
+ - section content changed → "The `<name>` system guidance has changed. The
75
+ following supersedes..."
76
+ - literals changed or `forceSystemPrompt` changed → `replace`
77
+ (deliberate full cache miss)
78
+ - **`forceSystemPrompt` short-circuits everything**: when set, pieces are
79
+ only the forced prompt; sections are not rendered at all. Any extension
80
+ returning a full replacement string from `before_agent_start` gets this
81
+ path, and every content change is a full prefix miss.
82
+ - **`customPrompt` is a value piece** (keyed `customPrompt`, diff-friendly)
83
+ and does NOT short-circuit sections. This is pi-forge's integration point
84
+ for `mode = replace` stacks.
85
+ - Mid-run timing: the diff runs before every LLM request
86
+ (`agent-loop.ts`), including mid-tool-loop, so an agent tool that mutates
87
+ sections gets its delta delivered after the tool batch and before the next
88
+ inference. The tool-call adjacency problem from the original draft is
89
+ handled by the harness.
90
+ - Fallback rendering for unsupported providers:
91
+ `<system_update>\n{text}\n</system_update>` as a user-role message
92
+ (`pi-ai/utils/system-messages.ts`); Gemini confirmed user-role.
93
+ - Native support matrix (upstream compat flags): Anthropic Opus 4.8/5,
94
+ Fable 5/5.1, Mythos 5/5.1 get real system messages (Anthropic requires a
95
+ system message to directly precede an assistant turn; pending messages are
96
+ held). OpenAI transports get `developer`/`system` items. Everything else
97
+ gets the tagged user turn.
98
+ - `BeforeAgentStartEventResult.message` only accepts `CustomMessage`
99
+ (customType/content/display/details) — there is **no imperative
100
+ append-SystemMessage extension API** in the PR as written. The declarative
101
+ sections path is the intended extension surface.
102
+ - The PR branch itself had two TypeScript errors (`openrouter.ts`,
103
+ `xai.ts`) when we built it; dist artifacts were still produced.
104
+
105
+ ### 2.3 Trigger to resume this work
106
+
107
+ When the redone PR appears: verify the sections/diff semantics survived the
108
+ redo (re-run the §2.2 matrix), then wire pi-forge's workflow layer to it.
109
+ If the redo removes the declarative sections surface, reassess; the escape
110
+ hatch is splicing `SystemMessage` in the context hook (see §5).
111
+
112
+ ---
113
+
114
+ ## 3. pi-forge Design (workflow layer)
115
+
116
+ These decisions survive from the original draft and remain the plan.
117
+
118
+ ### 3.1 Event model
119
+
120
+ - Updates are **append-only custom session entries**
121
+ (`pi-forge-system-update`, schemaVersion 1), written via the existing
122
+ `session-adapter.ts` pattern (`pi.appendEntry` / `getCurrentBranchEntries`).
123
+ Branch semantics come for free.
124
+ - Entry payload: `{ updateId, op: "apply" | "revoke" | "reset", source,
125
+ presetId?, contentSnapshot, createdAt }`.
126
+ - **Snapshot content, not file paths**: file-backed presets are rendered at
127
+ activation time and the rendered text is persisted. Editing a preset file
128
+ tomorrow must not alter yesterday's session.
129
+ - Logical state is a **reducer view** over the branch's events, never
130
+ canonical mutable state. Powers `/system-update status`, badges, and
131
+ section rendering.
132
+ - Revoke/reset are new events, never history rewrites. In practice the
133
+ harness retraction wording ("no longer applies") is generated for us once
134
+ the section disappears; the event log only records intent.
135
+
136
+ ### 3.2 Rendering (the declarative bridge)
137
+
138
+ - The reducer's active set is rendered into
139
+ `systemPromptOptions.sections["pi-forge-update-<id>"]` during
140
+ `before_agent_start` (and picked up mid-run by the harness's per-request
141
+ diff).
142
+ - pi-forge's stack compilation moves off the legacy "return one big string"
143
+ path: `mode = replace` stacks go into `systemPromptOptions.customPrompt`,
144
+ additive content into keyed `sections`. This is a prerequisite refactor,
145
+ and it upgrades cache behavior for the whole stack system, not just
146
+ updates.
147
+ - Transport is not pi-forge's concern: native vs fallback rendering is the
148
+ harness's compatibility layer.
149
+
150
+ ### 3.3 Commands
151
+
152
+ - `/system-update <text>` — apply a freeform update (auto-id `update-N`).
153
+ - `/system-update status` — reducer view of active updates.
154
+ - `/system-update reset` — deactivate all (new event, append-only).
155
+ - 0.5.5+ with presets: `/system-update list|use <id>|off <id>`.
156
+ - No command deletes history. None of these trigger an agent turn.
157
+
158
+ ### 3.4 Presets and the agent tool
159
+
160
+ - Presets declare dormant runtime blocks:
161
+ `{ "systemUpdates": [{ "id", "name", "description", "modelCallable",
162
+ "content" | "file" }] }`.
163
+ - The base system prompt carries only a compact inventory; full blocks load
164
+ on activation (lazy privileged prompt loading).
165
+ - Agent-facing tool `forge_system_update({action, id})` references declared
166
+ preset IDs only. **No arbitrary file elevation, no arbitrary agent-provided
167
+ privileged text.** Repository content is untrusted; elevation requires an
168
+ explicit preset declaration.
169
+ - Source-aware deactivation: the agent may only deactivate agent-activated
170
+ modes; the user may deactivate anything.
171
+ - Mid-turn activation rides the harness's per-request diff — no
172
+ pending-commit machinery on our side.
173
+
174
+ ### 3.5 Compaction, resume, branching
175
+
176
+ All owned by the harness under the new architecture: update sections are part
177
+ of the effective prompt, folded into the post-compaction baseline; stored
178
+ baseline is reinstated on resume; events live on the branch. pi-forge's only
179
+ job is to re-derive the active set from the branch's event log on session
180
+ start/branch switch (same restore pattern as the active-stack state today).
181
+
182
+ ---
183
+
184
+ ## 4. Version Plan
185
+
186
+ - **0.5.4 (done, pushed):** web editor fixes and visual work; prompt-cache
187
+ features — cache-impact warning on `/preset use` / `/profile use`
188
+ (common-prefix estimate + last-request cacheRead), and compile-time
189
+ diagnostics for cache-sensitive content (`{{time}}`, date slots with
190
+ `includeTime`, `{{date}}` info).
191
+ - **0.5.5:** system update workflow layer per §3, gated on the upstream redo
192
+ landing in a released Pi. Build the upstream-touching code behind a small
193
+ isolated module so a redo API change rewrites one file, not the feature.
194
+
195
+ ---
196
+
197
+ ## 5. Discarded Designs (recorded so we don't re-litigate)
198
+
199
+ - **Custom entry + self-written projector** (original draft's main design):
200
+ required replicating Pi's session-entry→context translation rules
201
+ (compaction truncation, deferred-message filtering) to compute splice
202
+ positions, plus a compaction checkpoint synthesizer. Real maintenance
203
+ coupling to Pi internals. Killed by the upstream `SystemMessage`.
204
+ - **`pi.sendMessage` custom_message transport**: zero projection code, but
205
+ `custom_message` entries evaporate at compaction (the compaction path
206
+ doesn't recognize them) and render only as user-role. Viable fallback if
207
+ the upstream redo dies entirely; otherwise obsolete.
208
+ - **Provider transport matrix / native lowering in pi-forge**: the wire role
209
+ is the harness's compatibility layer. pi-forge stores semantics
210
+ (`op`, `presetId`) so a future transport change needs no data migration.
211
+ - **Context-hook SystemMessage splicing**: possible once upstream keeps
212
+ `role: "system"` messages, but brings back per-request projection, position
213
+ mapping, and Anthropic placement-rule handling. Escape hatch only.
214
+
215
+ ---
216
+
217
+ ## 6. Open Questions for the Redo
218
+
219
+ 1. Did sections survive the redo, and did their diff semantics change?
220
+ 2. Is there an imperative append path for extensions after all, or is
221
+ declarative sections still the only surface?
222
+ 3. How does the redo store baselines (the session-bloat feedback)?
223
+ 4. Does `customPrompt` remain a non-short-circuiting value piece?
224
+ 5. Timing: which Pi release carries it, and what's our minimum-version
225
+ dependency story for the feature?
226
+
227
+ Community posture: when the redo PR opens, comment as a downstream consumer
228
+ with the runtime-instruction-modes use case (do not file a new issue;
229
+ feature-request issues get auto-closed while a PR is in flight).
@@ -0,0 +1,78 @@
1
+ # Context Diff — design plan (post-0.5.0)
2
+
3
+ Status: folded into `docs/design/0.5.1-plan.md` as Lane 2 — that file is now the owner of truth. Kept for discussion history.
4
+
5
+ Implemented follow-up: the dock now provides git-style line diffs and correlates
6
+ captured requests with Pi's assistant usage. The structural cache-prefix figure
7
+ remains a chars/4 estimate; provider-reported cache hit rate is shown separately
8
+ and is unavailable until cache reporting is observed for that provider/model.
9
+
10
+ Original status: planned. Target release: 0.5.1 (first feature release after 0.5.0).
11
+
12
+ ## Goal
13
+
14
+ Per-turn observability for prompt changes so users can optimize KV-cache reuse:
15
+
16
+ - Mark which blocks of the prompt changed after each turn.
17
+ - Show how many tokens were added/removed/modified (delta vs the previous turn).
18
+ - Mark where the KV-cache prefix survives ("cache boundary").
19
+
20
+ Secondary goal: merge with live preview — while editing a stack, debounce-compile and diff against the previous compile, so edits show their prompt/token impact immediately.
21
+
22
+ ## Existing building blocks
23
+
24
+ - `src/payload-capture.ts` — captures the real provider request payload (secret-redacted), with `approxTokens` (chars/4) estimation. `SAFE_TOKEN_METADATA_KEYS` already whitelists `cached_tokens` etc., so real cache-hit numbers can be surfaced if response usage ever becomes available.
25
+ - `src/preview.ts` — edit-time compile output split into sections (system + per-message), each with chars/approxTokens.
26
+ - Legacy editor already polls payload state every 2s.
27
+
28
+ ## Two data sources
29
+
30
+ | Scenario | Source | Question answered |
31
+ |---|---|---|
32
+ | Edit time (live preview merge point) | debounced compile vs previous compile | "what does this edit change, how many tokens" |
33
+ | Run time (KV-cache truth) | diff of consecutive real payloads | "where did the cache break, how many extra tokens this turn" |
34
+
35
+ ## Core engine: `src/context-diff.ts` (host-neutral pure functions)
36
+
37
+ ```
38
+ TurnSnapshot { turnId, capturedAt, stackId, blocks: Block[] }
39
+ Block { key, role, text, chars, approxTokens, hash }
40
+ TurnDiff { blocks: DiffBlock[], prefixTokens, prefixRatio, deltaTokens, summary }
41
+ DiffBlock { status: same|added|removed|modified, before?, after?, tokenDelta }
42
+ ```
43
+
44
+ Cache-boundary algorithm: KV-cache hits depend on the longest common prefix of the serialized request. Walk the block arrays in order while hashes match; at the first mismatch, trim a char-level common prefix inside that block and convert to tokens. Render a boundary marker: "cache valid up to ~18,204 tokens (63% of prompt)". No Myers diff needed — prefix + block classification suffices.
45
+
46
+ Honesty note: tokens are chars/4 estimates. Relative deltas are accurate; absolute boundary claims must be labeled "approx" in UI and in promo material.
47
+
48
+ ## UI
49
+
50
+ Promote the Preview modal into a dockable right-side panel with two tabs:
51
+
52
+ - **Compiled** — current preview content, auto-refresh with 500ms debounce while editing (this is the live preview).
53
+ - **Diff** — top summary strip (`Turn N · +412 tokens vs previous · cache boundary ~63% · 2 blocks changed`), block list with green/red/yellow gutters and per-block token chips, scissor-line boundary marker.
54
+
55
+ Run-time mode: payload poll captures a new payload → store in rolling history (last 20 turns) → auto-compute diff.
56
+ Edit mode: diff current edited compile vs the active on-disk version.
57
+
58
+ Implementation constraint: write the panel as a self-contained Vue component bridged in via the vue-host mechanism. Do NOT add more imperative code to `legacy-editor.ts`. Do NOT refactor the legacy editor in the same lane.
59
+
60
+ ## Phases / estimate
61
+
62
+ | Phase | Content | Effort |
63
+ |---|---|---|
64
+ | 0 | Design freeze + golden fixtures (turn payload sets) | 0.5d |
65
+ | 1 | `context-diff.ts` engine + unit tests (prefix/add/remove/modify/token rollups) | 1d |
66
+ | 2 | Server endpoint + rolling snapshot state on the web host | 0.5d |
67
+ | 3 | Web UI: preview dock + Diff view (self-contained Vue, bridged) | 1.5d |
68
+ | 4 | Browser tests + docs + changelog | 0.5–1d |
69
+
70
+ Total ~4–5 working days; ~1 calendar week with review. Descope option (~3d): run-time diff only, live preview reduced to plain auto-refresh without edit-time diffing.
71
+
72
+ ## Release narrative
73
+
74
+ Do not fold into 0.5.0 — 0.5.0 ships as the architecture-split release; context diff headlines 0.5.1 as "observability". The promo video leads with this feature (money shot: edit one system-prompt line, watch the cache-boundary marker jump to the top).
75
+
76
+ ## Promo video pipeline (reference: AIGC/VIDEO_PRODUCTION ep02)
77
+
78
+ Reuse the ep02 pipeline: `PLAN.md` → script draft → `narration.json` (production source of truth) → roughcut → review. Terminology follows the ep02 rule: say it in plain words first, name the formal term once ("KV cache" on first mention, then "prefix cache / cache reuse region").
@@ -0,0 +1,33 @@
1
+ # Architecture decision: title
2
+
3
+ [Design index](README.md)
4
+
5
+ Status: proposed
6
+
7
+ Date: YYYY-MM-DD
8
+
9
+ Owners: maintainer names or roles
10
+
11
+ ## Context
12
+
13
+ Describe the concrete problem, current constraints, and evidence that a decision is needed.
14
+
15
+ ## Decision
16
+
17
+ State the chosen behavior and ownership boundary precisely. Include a small interface or diagram when it makes the boundary easier to verify.
18
+
19
+ ## Consequences
20
+
21
+ Describe what becomes easier, what becomes harder or impossible, and which compatibility or operational costs are accepted.
22
+
23
+ ## Migration
24
+
25
+ List the implementation order, compatibility period if any, user migration, and removal condition for temporary shims.
26
+
27
+ ## Alternatives considered
28
+
29
+ Record the serious alternatives and why they were rejected. Do not use this section to restate obviously inferior options.
30
+
31
+ ## Verification
32
+
33
+ Define the tests, dependency checks, documentation, and release evidence that prove the decision was implemented.