@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,112 @@
1
+ # Session cache usage
2
+
3
+ [Documentation](../README.md) · [简体中文](../zh-CN/reference/session-cache.md)
4
+
5
+ Available in Forge 0.5.5. The nested-usage contract is experimental; producer integration is owned and released independently by optional tools. Forge tracks and summarizes read-only prompt-cache metrics for the active session branch. These metrics appear in the Web editor's **Current session** capabilities panel and are exposed in the capability runtime state.
6
+
7
+ ## Read-only architecture
8
+
9
+ Cache usage metrics are computed on demand from provider-reported usage that Pi has already persisted in messages along the active branch:
10
+
11
+ - **Zero side effects:** Forge never initiates model inference, appends session entries, edits prompt text, inserts `cache_control` breakpoints, or triggers prompt warming for usage tracking.
12
+ - **Reused polling:** The Web client receives cache metrics through its existing visibility-based polling (`GET /api/capability-state`); no extra network requests or timers are introduced.
13
+ - **Root-to-leaf branch traversal:** Metrics reflect the active branch from root to leaf.
14
+ - **Main session requests:** Counted from `assistant` messages carrying non-zero persisted usage (`input + output + cacheRead + cacheWrite > 0`). Requests with zero reported usage (such as aborted turns or failed calls without provider usage) are excluded.
15
+ - **Latest reported request:** The latest assistant message with non-zero usage; a later aborted or unreported request does not replace it.
16
+ - **Current turn:** Aggregates assistant requests appearing after the latest `user` message on the branch. Tool loops within the turn aggregate together.
17
+ - **Session scope:** Aggregates all qualifying requests on the active branch, including pre-compaction conversation history that remains on the branch.
18
+ - **Exclusions and persistence boundaries:**
19
+ - Excludes standalone Pi `usage` events, compaction entries, and `branch_summary` records.
20
+ - Pi can persist warming usage separately; these metrics intentionally count conversational requests, not warming or summarization overhead.
21
+ - Not equivalent to Pi's overall session billing or total bill statistics.
22
+
23
+ ## Hit rate formula and aggregation
24
+
25
+ ### Hit rate formula
26
+
27
+ Prompt cache hit rate measures prompt prefix reuse:
28
+
29
+ ```
30
+ cacheHitRate = cacheRead / (input + cacheRead + cacheWrite)
31
+ ```
32
+
33
+ - `input`: normalized uncached prompt tokens, following the `pi-ai` `Usage` convention.
34
+ - `cacheRead`: prompt tokens served from the provider prompt cache.
35
+ - `cacheWrite`: prompt tokens written to provider prompt cache checkpoints.
36
+ - `output`: model completion tokens are strictly excluded from the prompt cache hit rate denominator.
37
+ - **Undefined denominator:** When total prompt tokens (`input + cacheRead + cacheWrite`) equal zero, the hit rate is undefined and displayed as an em dash (`—`).
38
+
39
+ ### Aggregation semantics
40
+
41
+ - **Mixed models:** When multiple models run on the same branch or turn, rates are aggregated by summing raw token counts across requests (sum of cache reads / sum of prompt tokens), never as an arithmetic mean of percentages.
42
+ - **Provider reporting caveats:** Zero reported cache counts (`cacheRead: 0`, `cacheWrite: 0`) can indicate that the provider does not report cache metrics. They do not prove that prompt caching is unsupported or that no caching occurred.
43
+
44
+ ## Main session vs. nested tool separation
45
+
46
+ Usage is tracked in two distinct streams:
47
+ 1. **Main (`main`):** Direct assistant turns initiated by the primary session model.
48
+ 2. **Nested (`nested`):** Usage reported by tools that execute model requests internally (such as subagents). Nested usage is never merged into `main`.
49
+
50
+ In the Web UI:
51
+ - Main session and nested tools are displayed in separate visible rows (**Cache hit** and **Nested tools**).
52
+ - Tooltips display combined totals for **known** data only, with a permanent note that absent, invalid, or cache-unknown reports are excluded. The combined value is not a complete bill.
53
+
54
+ ## Experimental nested-usage contract (`toolResult.details.forgeNestedUsage`)
55
+
56
+ Tools that make inner model calls can report aggregate token and cache metrics by attaching an object to `toolResult.details.forgeNestedUsage` (`FORGE_NESTED_USAGE_KEY`).
57
+
58
+ ### Typed import
59
+
60
+ ```ts
61
+ import {
62
+ FORGE_NESTED_USAGE_KEY,
63
+ parseForgeNestedUsage,
64
+ type ForgeNestedUsage,
65
+ } from "@zihanw/pi-forge/subagent";
66
+ ```
67
+
68
+ ### JSON payload example
69
+
70
+ ```json
71
+ {
72
+ "role": "toolResult",
73
+ "toolCallId": "call_subagent_abc123",
74
+ "content": [{ "type": "text", "text": "Subagent task completed." }],
75
+ "details": {
76
+ "forgeNestedUsage": {
77
+ "schemaVersion": 1,
78
+ "requests": 2,
79
+ "input": 1500,
80
+ "output": 420,
81
+ "cacheRead": 3200,
82
+ "cacheWrite": 0
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ ### Contract specification
89
+
90
+ | Field | Type | Required | Notes |
91
+ |---|---|---|---|
92
+ | `schemaVersion` | `1` | Yes | Contract version. Must be literal `1`. |
93
+ | `requests` | `number` | Yes | Non-negative safe integer. Total model requests executed during the tool invocation. `0` is allowed **only** when all supplied token counts are zero. |
94
+ | `input` | `number` | Yes | Non-negative safe integer. Normalized uncached input tokens. |
95
+ | `output` | `number` | Yes | Non-negative safe integer. Generated completion tokens. |
96
+ | `cacheRead` | `number` | Optional | Non-negative safe integer. Prompt tokens read from cache. Must be paired with `cacheWrite`. |
97
+ | `cacheWrite` | `number` | Optional | Non-negative safe integer. Prompt tokens written to cache. Must be paired with `cacheRead`. |
98
+
99
+ - **Strict schema:** No extra keys are permitted.
100
+ - **Cache pair rule:** `cacheRead` and `cacheWrite` must either both be present or both omitted. Omit both when the producer cannot provide cache numbers.
101
+ - **Invocation aggregation:** A final tool result must supply exactly **one** aggregate per tool invocation covering all its internal model requests. Intermediate progress snapshots or repeated lifetime totals across calls are prohibited.
102
+ - **Rollup ownership:** The tool producer owns deduplication and recursive rollup across child agents. Nested totals must not include main session tokens.
103
+ - **Ingestion and error handling:**
104
+ - **Unknown cache metrics:** Valid records omitting `cacheRead`/`cacheWrite` are excluded from all request and token totals; the call is counted in `cacheUnknownCalls` (`N calls reported no cache data`).
105
+ - **Malformed records:** Payloads failing schema validation are ignored; the call is counted in `invalidCalls` (`N malformed reports ignored`).
106
+ - **Absent key:** When `forgeNestedUsage` is absent, the tool call is treated as having no nested usage. Forge does not mine legacy output or parse logs.
107
+
108
+ ### Attribution and Pi integration boundary
109
+
110
+ - **Forge attribution only:** `toolResult.details.forgeNestedUsage` is used solely for Forge UI attribution and cache tracking. It does **not** modify Pi's built-in session totals.
111
+ - **No duplicate counting:** Pi supports `toolResult.usage` natively. A future producer can emit the same underlying usage to `toolResult.usage` for Pi's session totals and to `toolResult.details.forgeNestedUsage` for Forge's cache display. Forge does not re-add top-level `toolResult.usage`, preventing duplication.
112
+ - **Ecosystem status:** Runtime and subagent producer integration is deferred. Existing subagent calls without this field display no data; no historical backfill is performed.
@@ -0,0 +1,243 @@
1
+ # Prompt-stack schema and policy
2
+
3
+ [Documentation](../README.md)
4
+
5
+ Use [the default Pi mirror](../../examples/default-prompt-stack.json) as the complete baseline. This page describes behavior-significant fields; `/preset validate` and the web editor are the final validators.
6
+
7
+ ## Top-level shape
8
+
9
+ A stack has a unique `id`, schema/type identity, optional display metadata and auto-activation, a system `mode`, ordered `items`, and optional defaults, parameters (schema v2) or legacy variables, context, resource policy, regex, and source metadata.
10
+
11
+ Unknown/advanced metadata is preserved by raw editing, but behavior-changing fields are shape-checked and invalid values are not silently normalized into active behavior.
12
+
13
+ ## Items
14
+
15
+ Block:
16
+
17
+ ```json
18
+ {
19
+ "kind": "block",
20
+ "id": "unique-id",
21
+ "name": "Readable label",
22
+ "enabled": true,
23
+ "role": "system",
24
+ "content": "Your text here. Use {{ parameters.role }} / {{ runtime.lastUserMessage }} for dynamic content."
25
+ }
26
+ ```
27
+
28
+ Valid roles are `system`, `user`, `assistant`, and `custom`. Custom-role content participates in compilation and reaches the provider as a `user` message: Pi converts `custom` messages to `user` when it builds the wire request, so the wire carries no distinct custom role. Custom-role items never merge with other items (see [Context options](#context-options)).
29
+
30
+ Slot:
31
+
32
+ ```json
33
+ {
34
+ "kind": "slot",
35
+ "id": "history",
36
+ "name": "Chat history",
37
+ "enabled": true,
38
+ "role": "user",
39
+ "slot": "chat-history",
40
+ "options": {
41
+ "includeLastUserMessage": false
42
+ }
43
+ }
44
+ ```
45
+
46
+ Item IDs must be unique. Unsupported slots and missing required custom registrations produce diagnostics. Multiple chat-history slots warn unless explicitly permitted.
47
+
48
+ Item position only matters within each channel: all `system` items join the system prompt in their relative order, and all non-system items become messages in their relative order. A `system` item placed after non-system items therefore has no effect on placement and produces a validation warning; roles are never silently converted. Use a `user` item for in-conversation injection.
49
+
50
+ ## Capabilities
51
+
52
+ - `replace` replaces Pi's base system prompt; empty output falls back to the base.
53
+ - `append` places stack system text after Pi's base.
54
+ - `prepend` places stack system text before Pi's base.
55
+
56
+ ## Context options
57
+
58
+ ```json
59
+ {
60
+ "context": {
61
+ "allowDuplicateChatHistory": false,
62
+ "mergeConsecutiveRoles": true,
63
+ "mergeSeparator": "\n\n"
64
+ }
65
+ }
66
+ ```
67
+
68
+ - `allowDuplicateChatHistory` permits multiple enabled chat-history slots; otherwise only the first expands.
69
+ - `mergeConsecutiveRoles` (default `false`) merges runs of consecutive stack items that share the same declared role into a single message, joined by `mergeSeparator` (default a blank line). Only stack-authored `user`/`assistant` items merge: chat-history output (including the implicit history tail) and `custom` items are hard boundaries, and merging runs after compiled-stage regex so regex semantics are unchanged. The web editor preview reflects the merged layout.
70
+ - `mergeSeparator` is inserted verbatim between merged texts and may be an empty string.
71
+
72
+ ## Chat-history options
73
+
74
+ ```json
75
+ {
76
+ "includeLastUserMessage": false,
77
+ "stripAssistantThinking": true,
78
+ "includeSummaries": true,
79
+ "toolCapability": "keep",
80
+ "roles": ["user", "assistant"],
81
+ "maxMessages": 40,
82
+ "maxChars": 20000
83
+ }
84
+ ```
85
+
86
+ - Set `includeLastUserMessage: false` when a later block reinserts `{{ runtime.lastUserMessage }}`.
87
+ - `stripAssistantThinking` removes prior thinking blocks but preserves visible assistant text, tool calls, and results. It does not change the live loop or stored transcript.
88
+ - `includeSummaries: false` excludes branch/compaction summaries.
89
+ - `roles` keeps only selected roles.
90
+ - `toolCapability: "drop"` removes prior tool traffic.
91
+ - `maxMessages` and `maxChars` keep recent history within limits.
92
+
93
+ When filtering would separate a tool call from its result, pi-forge removes dangling entries rather than sending inconsistent provider history.
94
+
95
+ ## Structured slots
96
+
97
+ `tools`, `tool-guidelines`, `skills`, and `project-context` support `"format": "plain"`; the default is XML-style structure. Date slots support `includeTime: true`.
98
+
99
+ See [macros and slots](macros-and-slots.md) for names and options.
100
+
101
+ ## Tool and skill policy
102
+
103
+ Patterns are exact by default and support `*` wildcards:
104
+
105
+ ```json
106
+ {
107
+ "tools": {
108
+ "allow": ["read", "grep", "find", "ls"],
109
+ "initial": ["read", "grep"]
110
+ },
111
+ "skills": {
112
+ "deny": ["browser-danger"]
113
+ }
114
+ }
115
+ ```
116
+
117
+ Each resource may have a non-empty `allow` list or `deny` list, never both. A selective tool `allow` list chooses matching tools from Pi's complete registered tool catalog, so it can activate a registered tool that was inactive when the stack was selected. A tool `deny` list removes matching tools from the active baseline. `allow: ["*"]` remains unrestricted and does not activate every registered tool. Unmatched allow patterns are surfaced during validation/preflight.
118
+
119
+ ### Initial active tools (`tools.initial`)
120
+
121
+ The `tools` policy optionally accepts an `initial` list:
122
+
123
+ - **Concrete names only:** `tools.initial` must be an array of valid, concrete tool name strings (up to 128 characters each). Wildcards (`*`, `?`) are rejected; duplicate names produce a warning and are deduplicated on parsing.
124
+ - **Omission vs. empty array:**
125
+ - When `initial` is omitted, pi-forge preserves legacy behavior: a selective allow chooses matching registered tools; unrestricted/deny policies retain or filter the restorable session baseline, not the entire catalog.
126
+ - When `initial: []` is set explicitly, zero tools are active initially.
127
+ - **Ceiling enforcement:** The `allow`/`deny` ceiling remains authoritative and exclusive. Initial tools must fall within permitted bounds: listing a tool that is blocked by allow/deny produces a validation error.
128
+ - **Extension and mod tools:** Dynamically registered extension tools are allowed by default if they satisfy the allow/deny policy, but when `initial` is specified, they remain registered and inactive until explicitly added by `initial`, by an active capability, or through runtime tooling.
129
+ - **Preset baseline behavior:** Configured initial tools serve as the active base for as long as the preset remains active—not a one-time reset per turn. Calling `/capability disable` or `/capability reset` returns the session to the preset defaults (plus any remaining active capabilities). Disabling restores the reconciled session baseline; switching recomputes under the new Preset and remaining unbound capabilities.
130
+ - **Compatibility:** Stacks declaring `tools.initial` require Forge 0.5.5 or newer. 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), so the field is not downgrade-compatible. 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](../guides/pi-1-compatibility.md)).
131
+
132
+ Tool policy changes Pi's active tool list, is reasserted before input/turns, and has a tool-call guard. It preserves external additions in the restorable baseline and restores that baseline when policy no longer applies or the extension shuts down.
133
+
134
+ Skill policy filters only pi-forge-rendered skill slots. It does not disable explicit invocation and is not a capability boundary. `append`/`prepend` may retain Pi's unfiltered base skill text, so validation warns.
135
+
136
+ ## Parameters and schema v2
137
+
138
+ Schema v2 stacks store immutable static values in `parameters` (JSON-compatible):
139
+
140
+ ```json
141
+ {
142
+ "schemaVersion": 2,
143
+ "parameters": {
144
+ "char": "Konata",
145
+ "user": "User",
146
+ "style": { "tone": "concise" }
147
+ }
148
+ }
149
+ ```
150
+
151
+ Parameters resolve through `{{ parameters.<name> }}` templates and are available
152
+ to trusted custom macros/slots. Unversioned and v1 stacks continue to read the
153
+ legacy `variables` field (string values) and support bare `{{name}}` fallback.
154
+ A stack must not mix `parameters` and `variables` across schema versions. See
155
+ [macro reference](macros-and-slots.md).
156
+
157
+ ## Regex transforms
158
+
159
+ Regex rules are ordered, deterministic JavaScript `RegExp` replacements. There is no embedded JavaScript, DOM, browser, CSS, or HTML-decoration runtime.
160
+
161
+ ```json
162
+ {
163
+ "regex": {
164
+ "schemaVersion": 1,
165
+ "rules": [
166
+ {
167
+ "id": "trim-ooc",
168
+ "enabled": true,
169
+ "stage": "history",
170
+ "effect": "outgoing",
171
+ "pattern": "\\(OOC:[^)]+\\)",
172
+ "flags": "gi",
173
+ "replace": "",
174
+ "roles": ["assistant"],
175
+ "maxMessages": 20
176
+ }
177
+ ]
178
+ }
179
+ }
180
+ ```
181
+
182
+ `stage: "history"` changes text inserted by `chat-history`. `stage: "compiled"` changes the final compiled system prompt and/or messages through optional `targets: ["system", "messages"]`.
183
+
184
+ Message rules may filter by `roles`, `maxMessages`, `maxChars`, `minDepth`, and `maxDepth` (depth 0 is latest). `trimStrings` removes literal strings from expanded matches/captures. Supported flags are `g`, `i`, `m`, `s`, and `u`. Replacements use JavaScript `$&`/`$1`; `$0` is accepted as a full-match alias and `$$` yields a literal dollar sign.
185
+
186
+ ### Frequency
187
+
188
+ Outgoing rules default to `"frequency": "turn"`: they run during the full compilation on the first provider request of each user turn. Tool-result follow-up requests receive Pi's natural context, so a turn-scoped rule never sees tool output until the next user turn.
189
+
190
+ Set `"frequency": "request"` to also run an outgoing message rule on every tool-result follow-up request, applied to Pi's full natural context:
191
+
192
+ ```json
193
+ {
194
+ "id": "redact-api-keys",
195
+ "stage": "history",
196
+ "effect": "outgoing",
197
+ "frequency": "request",
198
+ "pattern": "\\b(sk-[A-Za-z0-9_-]{12,})\\b",
199
+ "flags": "g",
200
+ "replace": "[REDACTED]"
201
+ }
202
+ ```
203
+
204
+ Each provider request is rebuilt from the stored transcript, so re-applying a rule to older messages is wire-consistent and never doubles. History-stage rules and compiled-stage rules with a `messages` target both participate; on follow-ups there is no stack layout rewrite, so both stages collapse onto the natural context (history-stage rules run first). `frequency` has no effect on `finalize` rules or system-only targets, and validation says so. It is wire-only scrubbing: the stored transcript keeps the original text.
205
+
206
+ Regex rules only cover the text targets and patterns you declare. They cannot recognize every credential format and do not scan system text, tool definitions, or arbitrary request metadata unless those targets are explicitly supported and selected. Treat them as deterministic text transforms, not as a security boundary.
207
+
208
+ To scrub the same recognized shapes from stored assistant/tool-result text, pair a request-frequency outgoing rule with a `finalize` rule:
209
+
210
+ ```json
211
+ {
212
+ "id": "redact-api-keys-finalize",
213
+ "stage": "compiled",
214
+ "effect": "finalize",
215
+ "targets": ["messages"],
216
+ "roles": ["assistant", "toolResult"],
217
+ "pattern": "\\b(sk-[A-Za-z0-9_-]{12,})\\b",
218
+ "flags": "g",
219
+ "replace": "[REDACTED]"
220
+ }
221
+ ```
222
+
223
+ Outgoing rules change future model input. To destructively change a completed assistant transcript message:
224
+
225
+ ```json
226
+ {
227
+ "id": "finalize-ooc",
228
+ "enabled": true,
229
+ "stage": "compiled",
230
+ "effect": "finalize",
231
+ "targets": ["messages"],
232
+ "roles": ["assistant"],
233
+ "pattern": "\\s*\\(OOC:[^)]+\\)",
234
+ "flags": "gi",
235
+ "replace": ""
236
+ }
237
+ ```
238
+
239
+ > `finalize` runs at `message_end`, after raw output may have streamed. It replaces the stored assistant message, so the original output is not preserved.
240
+
241
+ `effect: "outgoing"` and `"finalize"` are the only valid effects; `"display"` and `"both"` are rejected during validation. Runtime diagnostics report match and changed-segment counts.
242
+
243
+ `finalize` applies to assistant messages by default, and additionally to stored tool-result messages when a rule's `roles` explicitly includes `"toolResult"` — useful for scrubbing secrets out of stored tool output before the follow-up request replays it. Rules without `roles` keep assistant-only behavior, user messages are never finalized, and unsupported roles warn.
@@ -0,0 +1,57 @@
1
+ # Subagent host port contract
2
+
3
+ [Documentation](../README.md)
4
+
5
+ Status: experimental, versioned (`FORGE_HOST_PORT_VERSION = 1`). The `/subagent` entry point is the main package's only subagent surface: a transport-neutral host port over data-only messages. Subagent execution, approval, and configuration live in the optional [`@zihanw/pi-forge-subagents`](https://github.com/MacroSony/pi-forge-subagents) package, which consumes this port and never imports main-package internals.
6
+
7
+ ## Ownership boundary
8
+
9
+ - **Main package owns:** prompt-stack/agent-profile storage and validation (repositories + codecs), the immutable `ForgeWorkspace` snapshot, profile/stack resolution, host-owned prompt compilation, and tool filtering through stack policy.
10
+ - **Optional package owns:** delegation authorization (`subagents.json`), the execution contract (request, preflight, plan, response, validators), backend preflight and sealing via `@zihanw/pi-subagent-runtime`, approval UX, and execution.
11
+ - **Never crosses the port:** live contexts, internal registries, execution/runtime material (access workspace model, limits, `resultProjection`, `parent`, `remoteEgressConsent`, a base system prompt). The client sends only a profile selector, the task, prompt-compilation access facts (`level`/`network`/`allowProcess`), and backend facts (model, thinking level, tool catalog).
12
+
13
+ ## Transport and lifecycle
14
+
15
+ `ForgeHostTransport` is a minimal `{ emit(channel, data), on(channel, handler) }` interface; the production wiring is `pi.events`. Wire messages are plain JSON-compatible data validated recursively (exact nested fields, typed enums, plain objects only, unknown fields rejected) at both boundaries.
16
+
17
+ Mandatory lifecycle rules:
18
+
19
+ 1. Clients subscribe before announcing or discovering, and use bounded timeouts.
20
+ 2. A duplicate live host fails explicitly (`host.duplicate`).
21
+ 3. `request`/`reply` messages carry `hostId` + `generation`; stale-generation and wrong-host requests are rejected server-side, mismatched replies ignored client-side.
22
+ 4. Disposal sends `unavailable` and invalidates connections; all transient and persistent listeners are cleaned up.
23
+ 5. The host can only start after the first workspace snapshot exists, so an advertised host implies a loaded workspace. Reload honors project trust: untrusted workspaces expose global resources only.
24
+
25
+ ## Operations
26
+
27
+ ### Discovery
28
+
29
+ `ForgeHostClient.discover()` / `ForgeHostSession` in the optional package announce on `FORGE_HOST_CHANNEL` and wait for `available` with capabilities.
30
+
31
+ ### `listProfiles`
32
+
33
+ Request: `{}`. Response: `{ profiles: ForgeProfileSummary[] }` — each with `profileId`, `scope`, optional `name`/`description`/`autoActivate`, `model`, `thinkingLevel`, `promptStack`, `usable`, and load diagnostics. Read-only; no resolution side effects.
34
+
35
+ ### `resolveProfile`
36
+
37
+ Request: `{ profile: string }` — a scoped selector (`reviewer`, `project:reviewer`, `global:reviewer`). Response: `{ snapshot }` — the immutable host-owned profile snapshot artifact: resolved profile and prompt stack JSON, prompt dependency list, and `sha256:v1` content fingerprints (`profileFingerprint`, `promptStackFingerprint`) computed with Forge-owned canonical helpers byte-compatible with the runtime's canonical JSON. The optional package re-validates and re-fingerprints the snapshot before binding it into execution plans.
38
+
39
+ ### `prepare`
40
+
41
+ Request: `{ profile, task: { text }, access: ForgePromptAccessFacts, backend: ForgeBackendFacts }`. The workspace resolves the profile and stack from its snapshot, filters the client tool catalog through stack tool policy and the access facts, and compiles through the same compilation context as runtime and preview. Response: `{ profileId, model, thinkingLevel, systemPrompt, messages, effectiveToolIds, effectiveToolNames, diagnostics, profileSnapshot, preparedAt }`. `messages` ends with the protected delegated task (`protectedTask: true`, `source: "delegated-task"`); stack-compiled messages carry `source: "prompt-stack"`. The base system prompt is host-owned and intentionally empty for delegated subagents — the prompt stack composes the system prompt.
42
+
43
+ ## Tool-selection compatibility
44
+
45
+ For Presets containing `tools.initial`, both the host and the optional package must understand the field. The host filters the registered backend catalog to those concrete names (including an explicitly empty set), applies the existing allow/deny ceiling, then applies request access. The optional package independently recomputes this selection when validating the execution plan; `plan.tool-negotiation` must continue to reject disagreement. Omitting `initial` preserves legacy selection.
46
+
47
+ Forge 0.5.5 provides the host-side `tools.initial` support. Published `pi-forge-subagents` 0.5.3 is not compatible with `tools.initial`: it ignores the field during its independent negotiation. Use matching local optional-package checkouts until the optional package raises its Forge dependency floor to `^0.5.5` and completes its own release; the existing broad package dependency range is not a feature-compatibility guarantee.
48
+
49
+ This is an optional-package release gate, not a gate on the main Forge 0.5.5 release. The optional package must update its own manifests, runtime sequencing, backend/continuation coverage, lockfiles, and cross-package packed tests through its separately authorized process. No optional package or runtime publication is claimed here.
50
+
51
+ ## Fingerprints
52
+
53
+ `canonicalSubagentJson`, `subagentFingerprint`, `subagentSourceProfileFingerprint`, `subagentPromptStackFingerprint`, and `SUBAGENT_FINGERPRINT_PREFIX` are Forge-owned and vendored in the main package; golden vectors pin byte compatibility with the runtime's canonical serialization. Conversation and execution fingerprints are never host-computed — they are issued by `@zihanw/pi-subagent-runtime` during plan sealing in the optional package.
54
+
55
+ ## Errors
56
+
57
+ `ForgeHostPortError` carries `code: "timeout" | "duplicate" | "unavailable" | "protocol" | "invalid"`. Operation-level failures return `{ ok: false, error }` results rather than throwing across the bus.
@@ -0,0 +1,51 @@
1
+ # UI contribution port contract
2
+
3
+ [Documentation](../README.md)
4
+
5
+ Status: experimental, versioned (`UI_CONTRIBUTION_PORT_VERSION = 1`). The `@zihanw/pi-forge/ui-contribution` entry point is the generic cross-extension port that lets optional packages contribute schema-driven pages to the pi-forge web editor's top-level **Settings** surface. The forge side knows nothing about specific providers; the first consumer is [`@zihanw/pi-forge-subagents`](https://github.com/MacroSony/pi-forge-subagents), which contributes its Subagent Settings page when installed.
6
+
7
+ ## Ownership boundary
8
+
9
+ - **The contributing package owns** its tab's form schema, current values, server-side validation on write, and persistence (for example, the subagent package owns `subagents.json`). It implements the provider side of the port.
10
+ - **pi-forge owns** provider discovery over the bus, rendering contributed pages through the generic schema-form renderer, and proxying browser writes back over the bus through the web server routes. It never interprets or stores contributed configuration itself. Contributed pages are not stack tabs and never mount in the stack Preview dock.
11
+ - **Never crosses the port:** functions, components, live contexts, internal registries, or any non-JSON-compatible value. All payloads are plain recursively validated JSON. The port is not a trust boundary — providers must re-validate everything they receive and never trust the web client.
12
+
13
+ ## Transport and lifecycle
14
+
15
+ `UiContributionTransport` is a minimal `{ emit(channel, data), on(channel, handler) }` interface; the production wiring is `pi.events`. Messages travel on the dedicated `@zihanw/pi-forge/ui-contribution/v1` channel namespace with its own version counter, separate from the `/subagent` host port. Wire messages are plain JSON-compatible data validated recursively at both boundaries (exact field sets, typed enums, plain objects only, unknown fields rejected).
16
+
17
+ Channels: `discover`, `available`, `request`, `reply`, `unavailable`.
18
+
19
+ Lifecycle rules:
20
+
21
+ 1. Version negotiation: `discover` carries `protocolVersion` plus a supported `minVersion`/`maxVersion` range; a compatible provider answers `available` with its own `protocolVersion`, range, `capabilities`, `hostId`, and `generation`.
22
+ 2. A second compatible provider fails discovery explicitly (`duplicate`).
23
+ 3. `request`/`reply` messages carry `requestId` + `hostId` + `generation`; stale-generation and wrong-host requests are rejected server-side, mismatched replies ignored client-side.
24
+ 4. Provider disposal sends `unavailable`. The web editor clears that provider's contributed Settings pages and re-discovers when a provider reappears across sessions; late-surfacing providers are picked up without a page reload path change. The local HTTP listing also carries a forge-owned monotonic, opaque provider-session key so a fast restart refreshes a still-visible form even when browser polling never observes the empty interval. Browser PUT handling binds each response to the session that received it; a delayed success from an older session cannot mark or overwrite the newer session and the preserved draft is retried instead.
25
+ 5. Operation handlers may return a result or a promise of one and must never throw across the bus; rejected promises and thrown failures are converted to `{ ok: false, error }` results. Each invocation receives `{ signal, generation }`; stopping the provider aborts the signal. Handlers that await before persistence must check it before side effects. Replies from a stopped generation are discarded as a final transport guard.
26
+
27
+ The Settings host keeps the first descriptor for each `tabId`; later duplicates are ignored. Browser button IDs use a Settings-specific prefix and cannot collide with built-in stack tabs. Providers should still emit unique stable `tabId` values because `writeValues` routes by that identifier. In-progress drafts and save status are tracked per tab, so switching between contributed pages does not discard a pending edit or leak its status into another page.
28
+
29
+ ## Operations
30
+
31
+ ### Discovery
32
+
33
+ The web host acts as the client: `UiContributionClient.discover()` announces on the channel namespace and waits (bounded timeout) for an `available` announcement. Discovered tab descriptors are fetched at page load through `GET /api/contrib`.
34
+
35
+ ### `listContributions`
36
+
37
+ Request: `{}`. Response: `{ tabs: UiContributionTabDescriptor[] }` — each descriptor carries `tabId`, `title`, `icon`, a `FormSchema`, and the current `values`. Read-only; listing a tab contributes it to the editor but performs no other side effect. Every HTTP `GET /api/contrib` refreshes this operation, so providers may update plain-data option catalogs without restarting their session.
38
+
39
+ ### `writeValues`
40
+
41
+ Request: `{ tabId, patch }` — a partial values patch for one contributed tab. Omitted top-level fields preserve their stored values. A supplied `record` field is the complete keyed table produced by the form, so omitted rows represent deletion. The provider merges those semantics over its current values, re-validates server-side, and persists the result to its own storage. Response: `{ ok: true, values? }` with the canonical stored values, or `{ ok: false, errors }` with per-field error strings keyed by field key (dotted paths for record rows). The web server exposes this as `PUT /api/contrib/<tabId>` and rejects malformed or oversized request bodies with 400/413 before any bus call.
42
+
43
+ The browser serializes autosave requests. If the form changes while a PUT is in flight, the latest complete normalized snapshot is queued and written only after the current request settles. This ordering prevents older provider writes from landing after newer ones.
44
+
45
+ ## Form schema
46
+
47
+ v1 field types are deliberately restricted: `boolean`, `number`, `enum`, `string`, and `record` (a keyed table of entries — for example per-profile settings). Fields carry `key`, `label`, optional `description`/`required`/`default`, enum `options` (plain strings or `{ value, label }`), numeric `min`/`max`, string `maxLength`/`pattern`/`placeholder`, and record sub-fields (`recordFields`, `keyLabel`, `keyPlaceholder`). A record may also provide `keyOptions` (the same string-or-labelled-option shape as enum options); the generic renderer then uses a selector for row identity and prevents choosing a key already used by another row. Providers remain responsible for refreshing those plain-data options and validating them again on write.
48
+
49
+ ## Errors
50
+
51
+ `UiContributionPortError` carries `code: "timeout" | "duplicate" | "unavailable" | "protocol" | "invalid"`. Operation-level failures return `{ ok: false, error }` results rather than throwing across the bus.
@@ -0,0 +1,41 @@
1
+ # pi-forge 中文文档
2
+
3
+ [项目首页](../../README.zh-CN.md) · [English docs](../README.md)
4
+
5
+ ## 从这里开始
6
+
7
+ - [快速上手](getting-started.md):安装、创建预设、打开编辑器并保存 Profile。
8
+ - [预设与堆栈](concepts/prompt-stacks.md):完整预设及其有序 Block/Slot 编排。
9
+ - [Agent Profile](concepts/agent-profiles.md):一次性模型/思考等级/预设组合。
10
+
11
+ ## 指南
12
+
13
+ - [Web 编辑器](guides/web-editor.md)
14
+ - [迁移到 0.5](guides/migrating-to-0.5.md)
15
+ - [Pi 1.0 兼容指南](guides/pi-1-compatibility.md)
16
+ - [实验性前台 delegation](guides/delegation.md):启用前请先阅读安全边界。
17
+ - [预设使用场景(英文)](../guides/use-cases.md)
18
+
19
+ 自定义 macros/slots 和调试的完整说明目前以英文版为准:
20
+
21
+ - [Custom macros and slots](../guides/custom-macros-and-slots.md)
22
+ - [Prompt and payload debugging](../guides/debugging.md)
23
+
24
+ ## 参考
25
+
26
+ - [命令参考](reference/commands.md)
27
+ - [能力](reference/capabilities.md)
28
+ - [会话缓存用量](reference/session-cache.md):提示词缓存命中率与嵌套工具用量契约
29
+ - [各服务商对会话中更新的支持情况](reference/provider-support.md):Pi 0.87.1 快照
30
+ - [Stack schema 与策略(英文)](../reference/stack-schema.md)
31
+ - [Macros 与 slots(英文)](../reference/macros-and-slots.md)
32
+ - [配置(英文)](../reference/configuration.md)
33
+ - [Public API(英文)](../reference/public-api.md)
34
+ - [实验性 subagent host port(英文)](../reference/subagent-host-port.md)
35
+
36
+ ## 开发与设计
37
+
38
+ - [开发设置与兼容性(英文)](../development/setup.md)
39
+ - [Release 流程(英文)](../development/release.md)
40
+ - [Roadmap(英文)](../development/roadmap.md)
41
+ - [历史设计档案(英文)](../design/README.md)
@@ -0,0 +1,48 @@
1
+ # Agent profile
2
+
3
+ [中文文档](../README.md) · [English](../../concepts/agent-profiles.md)
4
+
5
+ Agent profile 是项目级或用户全局、带 schema version 的预设,只引用一个精确模型、思考等级和 prompt stack。项目 profile 位于 `.pi/forge/agent-profiles/`,全局 profile 位于 `~/.pi/forge/agent-profiles/`。命令接受 `reviewer`、`project:reviewer` 和 `global:reviewer`;未限定 ID 优先解析项目 profile,项目 profile 会遮蔽同 ID 全局 profile。
6
+
7
+ ```json
8
+ {
9
+ "schemaVersion": 1,
10
+ "type": "pi-forge.agent-profile",
11
+ "id": "reviewer",
12
+ "name": "Reviewer",
13
+ "description": "只审查代码,不做修改。",
14
+ "autoActivate": true,
15
+ "model": {
16
+ "provider": "provider-id",
17
+ "id": "model-id"
18
+ },
19
+ "thinkingLevel": "high",
20
+ "promptStack": "reviewer"
21
+ }
22
+ ```
23
+
24
+ `promptStack` 可以是 `null`。Profile v1 不保存生成参数、工具、skills、backend 或 runner policy;不支持字段会直接报错。工具/skill 策略只属于引用的 stack。
25
+
26
+ `promptStack` 引用相对 profile 自身 scope 解析:项目 profile 用裸 ID 引用项目 stack,也可用 `global:<id>` 显式引用全局 stack;全局 profile 只能引用全局 stack,`project:<id>` 会被拒绝。
27
+
28
+ ## 应用
29
+
30
+ ```text
31
+ /profile save reviewer
32
+ /profile preview reviewer
33
+ /profile use reviewer
34
+ ```
35
+
36
+ 保存不会包含 secrets、history、tools 或 provenance。应用前会完整检查 profile、模型、认证、思考等级、stack 和工具策略;失败时不会部分应用,运行中失败会尝试 rollback。
37
+
38
+ 成功应用后,后续手动修改会被保留。Profile 不是持续的 runtime owner。
39
+
40
+ ## Auto-activation 与 drift
41
+
42
+ 最多一个 profile 可以设置 `autoActivate: true`。它只在全新 session 中应用一次,并优先于独立 stack autoload;恢复的 branch 状态优先。无效或冲突的自动启用会 fail closed。
43
+
44
+ 自动 Profile 的设置及预设/工具选择可能在首轮提示词兼容性被观察之前生效。之后检测到缺少必要输入时,不会回滚这些设置、中止 provider 请求派发,或自动清除独立生效的工具策略。CLI 应用前会检查命令专用提示词 API;这不是通用启动检测,也不代表支持 OMP 等分支。详见[不受支持宿主的边界](../guides/pi-1-compatibility.md#不受支持宿主的边界)。
45
+
46
+ `/profile status` 会把 profile 源定义变化和当前模型/思考等级/stack drift 分开显示。Provenance 只用于 branch 状态报告;reload、resume、tree navigation 和 compaction 不会重新应用 profile。
47
+
48
+ 普通 profile 默认不能委派。Delegation 授权由可选包 `@zihanw/pi-forge-subagents` 通过专用文件持有,使用 `project:<id>` 或 `global:<id>` 完整 key,并可按 profile 覆盖 backend/timeout。裸授权 key 无论位于哪个文件都只是项目 profile 的兼容别名;同 ID 的全局和项目 profile 永不互相继承授权。主包不读取任何 subagent 配置,删除 profile 也不会改动 `subagents.json`。启用前见[前台 delegation](../guides/delegation.md)。
@@ -0,0 +1,48 @@
1
+ # 预设与堆栈
2
+
3
+ [中文文档](../README.md) · [English](../../concepts/prompt-stacks.md)
4
+
5
+ **Preset(预设)**是 Pi Forge 应用的完整声明式资源;其中由固定 **Block** 和动态 **Slot** 组成的有序 prompt 编排叫 **Stack(堆栈)**。同一份预设还会携带策略、Regex、参数和扩展引用。
6
+
7
+ > **0.5.3 兼容说明。** UI 使用“预设 → 堆栈”术语。这个补丁版本仍保留文件路径、JSON type、Profile 字段、API 路由和内部类型中的 `prompt-stack` / `promptStack` 拼写。
8
+
9
+ 预设当前放在兼容路径 `.pi/forge/prompt-stacks/` 或用户全局 `~/.pi/forge/prompt-stacks/`。命令接受 `reviewer`、`project:reviewer` 和 `global:reviewer`;未限定 ID 优先解析项目预设,项目预设会遮蔽同 ID 全局预设。重复 ID 只在同一 scope 内算错误。
10
+
11
+ ## 编译模型
12
+
13
+ 每个用户轮次开始时,pi-forge 会:
14
+
15
+ 1. 按 JSON 顺序排列启用的 block/slot。
16
+ 2. 构建 system 内容,并使用 `replace`、`append` 或 `prepend` 模式。
17
+ 3. 在可移动 `chat-history` 周围插入 user/assistant 消息。
18
+ 4. 用 forge-v1 编译 `runtime.*` / `parameters.*` / `extensions.*` 模板。
19
+ 5. 对 Pi 执行工具策略,并过滤 pi-forge 渲染的 skills。
20
+ 6. 应用 history/compiled outgoing regex。`frequency: "request"` 的 outgoing 消息规则还会在 tool 结果后续请求上对 Pi 的完整自然上下文再次运行;默认 `"turn"` 保持仅在每轮首次请求运行。
21
+ 7. 可选地在消息完成后应用破坏性的 finalize regex;`roles` 显式包含 `"toolResult"` 的 finalize 规则还会改写存储的 tool 结果消息。
22
+
23
+ ## 常用历史布局
24
+
25
+ 1. 长期 system 规则。
26
+ 2. 工具和项目上下文。
27
+ 3. `includeLastUserMessage: false` 的 `chat-history`。
28
+ 4. 包含 `{{ runtime.lastUserMessage }}` 的最终 user block。
29
+
30
+ 这样既保留旧上下文,又只在最后明确出现一次当前请求。History 还可以过滤 summary/role、去掉旧工具消息、移除 assistant thinking,并限制消息数或字符数。
31
+
32
+ 堆栈还可以通过 `context.mergeConsecutiveRoles`(及可选的 `context.mergeSeparator`)把连续的同角色条目合并成一条消息;chat-history 输出和 custom 角色条目永远不会被合并。详见英文 [Preset schema](../../reference/stack-schema.md#context-options)。
33
+
34
+ ## 策略边界
35
+
36
+ 工具 `allow`/`deny` 会修改 Pi active tools,并在 tool call 时再次检查。具体的 `allow` 列表会从 Pi 的完整已注册工具目录中选择,因此可以启用预设激活前处于 inactive 状态的工具;`deny` 只从原 active baseline 中移除工具,`allow: ["*"]` 仍表示不限制且不会启用全部工具。Skill policy 只过滤 pi-forge 渲染给模型的列表;它不能阻止明确调用,也不是安全边界。若必须控制模型可见 skill 列表,请使用 `replace`,因为 Pi 的基础 prompt 可能已经在 `append`/`prepend` 内容之前列出 skills。
37
+
38
+ ## Scope 与自动启用
39
+
40
+ - 只有显式设置 `"autoActivate": true` 的预设参与自动启用;文件名(包括 `default.json`)没有特殊作用。
41
+ - 项目预设优先于全局预设;项目 scope 存在候选时,即使项目候选无效或冲突也会 fail closed,不会回退到全局预设。
42
+ - 同 ID 项目预设会遮蔽全局预设,包括无效 shadow 或显式 opt-out。
43
+ - `/preset use none` 会记录 session branch 的 opt-out。
44
+ - Active Preset 选择会跟随 Pi session tree branch。
45
+ - 恢复的 branch 状态优先于新 session 自动启用。
46
+ - 自动启用的 Agent Profile 优先于独立预设 autoload。
47
+
48
+ 完整字段见英文 [stack schema](../../reference/stack-schema.md)(schema v2 使用 `parameters`),模板语法见[参考](../../reference/macros-and-slots.md)。