@zihanw/pi-forge 0.4.0-beta.1 → 0.4.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 (227) hide show
  1. package/CHANGELOG.md +45 -1
  2. package/PUBLIC_API.md +3 -26
  3. package/README.md +90 -601
  4. package/README.zh-CN.md +86 -585
  5. package/SUBAGENT_ADAPTER_CONTRACT.md +3 -197
  6. package/dist/agent-profile.d.ts +24 -1
  7. package/dist/agent-profile.d.ts.map +1 -1
  8. package/dist/agent-profile.js +146 -36
  9. package/dist/agent-profile.js.map +1 -1
  10. package/dist/catalog.d.ts +27 -0
  11. package/dist/catalog.d.ts.map +1 -0
  12. package/dist/catalog.js +59 -0
  13. package/dist/catalog.js.map +1 -0
  14. package/dist/forge-config.d.ts +106 -0
  15. package/dist/forge-config.d.ts.map +1 -1
  16. package/dist/forge-config.js +305 -18
  17. package/dist/forge-config.js.map +1 -1
  18. package/dist/index.d.ts +5 -5
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +55 -8
  21. package/dist/index.js.map +1 -1
  22. package/dist/lifecycle.d.ts +2 -1
  23. package/dist/lifecycle.d.ts.map +1 -1
  24. package/dist/lifecycle.js +7 -4
  25. package/dist/lifecycle.js.map +1 -1
  26. package/dist/loader.d.ts +17 -1
  27. package/dist/loader.d.ts.map +1 -1
  28. package/dist/loader.js +84 -25
  29. package/dist/loader.js.map +1 -1
  30. package/dist/preset-command.d.ts +1 -1
  31. package/dist/preset-command.d.ts.map +1 -1
  32. package/dist/preset-command.js +38 -10
  33. package/dist/preset-command.js.map +1 -1
  34. package/dist/profile-command.d.ts.map +1 -1
  35. package/dist/profile-command.js +46 -21
  36. package/dist/profile-command.js.map +1 -1
  37. package/dist/profile-service.d.ts +6 -3
  38. package/dist/profile-service.d.ts.map +1 -1
  39. package/dist/profile-service.js +55 -13
  40. package/dist/profile-service.js.map +1 -1
  41. package/dist/resource-identity.d.ts +33 -0
  42. package/dist/resource-identity.d.ts.map +1 -0
  43. package/dist/resource-identity.js +56 -0
  44. package/dist/resource-identity.js.map +1 -0
  45. package/dist/runtime/profile-runtime.d.ts.map +1 -1
  46. package/dist/runtime/profile-runtime.js +7 -2
  47. package/dist/runtime/profile-runtime.js.map +1 -1
  48. package/dist/runtime/prompt-stack-runtime.d.ts +1 -1
  49. package/dist/runtime/prompt-stack-runtime.d.ts.map +1 -1
  50. package/dist/runtime/prompt-stack-runtime.js +22 -12
  51. package/dist/runtime/prompt-stack-runtime.js.map +1 -1
  52. package/dist/runtime/subagent-runtime.d.ts +23 -8
  53. package/dist/runtime/subagent-runtime.d.ts.map +1 -1
  54. package/dist/runtime/subagent-runtime.js +296 -67
  55. package/dist/runtime/subagent-runtime.js.map +1 -1
  56. package/dist/storage.d.ts +11 -0
  57. package/dist/storage.d.ts.map +1 -1
  58. package/dist/storage.js +51 -2
  59. package/dist/storage.js.map +1 -1
  60. package/dist/subagent/canonical.d.ts +19 -7
  61. package/dist/subagent/canonical.d.ts.map +1 -1
  62. package/dist/subagent/canonical.js +19 -47
  63. package/dist/subagent/canonical.js.map +1 -1
  64. package/dist/subagent/contract.d.ts +1 -2
  65. package/dist/subagent/contract.d.ts.map +1 -1
  66. package/dist/subagent/contract.js +1 -2
  67. package/dist/subagent/contract.js.map +1 -1
  68. package/dist/subagent/index.d.ts +4 -3
  69. package/dist/subagent/index.d.ts.map +1 -1
  70. package/dist/subagent/index.js +4 -3
  71. package/dist/subagent/index.js.map +1 -1
  72. package/dist/subagent/plan.d.ts +5 -1
  73. package/dist/subagent/plan.d.ts.map +1 -1
  74. package/dist/subagent/plan.js +29 -32
  75. package/dist/subagent/plan.js.map +1 -1
  76. package/dist/subagent/request.d.ts.map +1 -1
  77. package/dist/subagent/request.js +36 -4
  78. package/dist/subagent/request.js.map +1 -1
  79. package/dist/subagent/types.d.ts +66 -178
  80. package/dist/subagent/types.d.ts.map +1 -1
  81. package/dist/subagent/types.js +1 -1
  82. package/dist/subagent/types.js.map +1 -1
  83. package/dist/subagent/validation.d.ts +14 -14
  84. package/dist/subagent/validation.d.ts.map +1 -1
  85. package/dist/subagent/validation.js +52 -238
  86. package/dist/subagent/validation.js.map +1 -1
  87. package/dist/subagent-command.d.ts +2 -1
  88. package/dist/subagent-command.d.ts.map +1 -1
  89. package/dist/subagent-command.js +115 -19
  90. package/dist/subagent-command.js.map +1 -1
  91. package/dist/subagent-host.d.ts.map +1 -1
  92. package/dist/subagent-host.js +43 -16
  93. package/dist/subagent-host.js.map +1 -1
  94. package/dist/subagent-profile-tool.d.ts +25 -2
  95. package/dist/subagent-profile-tool.d.ts.map +1 -1
  96. package/dist/subagent-profile-tool.js +41 -9
  97. package/dist/subagent-profile-tool.js.map +1 -1
  98. package/dist/subagent-tool.d.ts +31 -4
  99. package/dist/subagent-tool.d.ts.map +1 -1
  100. package/dist/subagent-tool.js +311 -137
  101. package/dist/subagent-tool.js.map +1 -1
  102. package/dist/types.d.ts +3 -0
  103. package/dist/types.d.ts.map +1 -1
  104. package/dist/types.js.map +1 -1
  105. package/dist/web-editor/client-script.generated.d.ts +1 -1
  106. package/dist/web-editor/client-script.generated.d.ts.map +1 -1
  107. package/dist/web-editor/client-script.generated.js +1 -1
  108. package/dist/web-editor/client-script.generated.js.map +1 -1
  109. package/dist/web-editor/client-styles.d.ts +2 -0
  110. package/dist/web-editor/client-styles.d.ts.map +1 -0
  111. package/dist/web-editor/client-styles.generated.d.ts +2 -0
  112. package/dist/web-editor/client-styles.generated.d.ts.map +1 -0
  113. package/dist/web-editor/client-styles.generated.js +3 -0
  114. package/dist/web-editor/client-styles.generated.js.map +1 -0
  115. package/dist/web-editor/client-styles.js +2 -0
  116. package/dist/web-editor/client-styles.js.map +1 -0
  117. package/dist/web-editor/page.d.ts +2 -0
  118. package/dist/web-editor/page.d.ts.map +1 -1
  119. package/dist/web-editor/page.js +11 -73
  120. package/dist/web-editor/page.js.map +1 -1
  121. package/dist/web-editor/server.d.ts.map +1 -1
  122. package/dist/web-editor/server.js +176 -1
  123. package/dist/web-editor/server.js.map +1 -1
  124. package/dist/web-editor/styles.d.ts.map +1 -1
  125. package/dist/web-editor/styles.js +60 -3
  126. package/dist/web-editor/styles.js.map +1 -1
  127. package/dist/web-editor/types.d.ts +87 -0
  128. package/dist/web-editor/types.d.ts.map +1 -1
  129. package/dist/web-host.d.ts +13 -2
  130. package/dist/web-host.d.ts.map +1 -1
  131. package/dist/web-host.js +371 -27
  132. package/dist/web-host.js.map +1 -1
  133. package/docs/README.md +41 -0
  134. package/docs/concepts/agent-profiles.md +60 -0
  135. package/docs/concepts/prompt-stacks.md +95 -0
  136. package/docs/design/README.md +17 -0
  137. package/docs/design/roadmap-0.4-archive.md +216 -0
  138. package/docs/design/subagents/design-review.md +220 -0
  139. package/docs/design/subagents/interface-design.md +274 -0
  140. package/docs/design/subagents/sdk-spike-findings.md +117 -0
  141. package/docs/development/complexity-review.md +86 -0
  142. package/docs/development/release.md +31 -0
  143. package/docs/development/roadmap.md +36 -0
  144. package/docs/development/scoped-global-profiles-stacks.md +325 -0
  145. package/docs/development/setup.md +75 -0
  146. package/docs/getting-started.md +95 -0
  147. package/docs/guides/custom-macros-and-slots.md +68 -0
  148. package/docs/guides/debugging.md +39 -0
  149. package/docs/guides/delegation.md +107 -0
  150. package/docs/guides/sillytavern-import.md +47 -0
  151. package/docs/guides/use-cases.md +65 -0
  152. package/docs/guides/web-editor.md +75 -0
  153. package/docs/reference/commands.md +60 -0
  154. package/docs/reference/configuration.md +66 -0
  155. package/docs/reference/features.md +280 -0
  156. package/docs/reference/macros-and-slots.md +82 -0
  157. package/docs/reference/public-api.md +28 -0
  158. package/docs/reference/stack-schema.md +167 -0
  159. package/docs/reference/subagent-adapter.md +204 -0
  160. package/docs/zh-CN/README.md +37 -0
  161. package/docs/zh-CN/concepts/agent-profiles.md +46 -0
  162. package/docs/zh-CN/concepts/prompt-stacks.md +42 -0
  163. package/docs/zh-CN/getting-started.md +81 -0
  164. package/docs/zh-CN/guides/delegation.md +66 -0
  165. package/docs/zh-CN/guides/web-editor.md +45 -0
  166. package/docs/zh-CN/reference/commands.md +60 -0
  167. package/package.json +29 -15
  168. package/dist/subagent/backend-registry.d.ts +0 -75
  169. package/dist/subagent/backend-registry.d.ts.map +0 -1
  170. package/dist/subagent/backend-registry.js +0 -463
  171. package/dist/subagent/backend-registry.js.map +0 -1
  172. package/dist/subagent/diagnostics.d.ts +0 -3
  173. package/dist/subagent/diagnostics.d.ts.map +0 -1
  174. package/dist/subagent/diagnostics.js +0 -5
  175. package/dist/subagent/diagnostics.js.map +0 -1
  176. package/dist/subagent/pi-model-runtime.d.ts +0 -8
  177. package/dist/subagent/pi-model-runtime.d.ts.map +0 -1
  178. package/dist/subagent/pi-model-runtime.js +0 -22
  179. package/dist/subagent/pi-model-runtime.js.map +0 -1
  180. package/dist/subagent/pi-sdk-backend.d.ts +0 -23
  181. package/dist/subagent/pi-sdk-backend.d.ts.map +0 -1
  182. package/dist/subagent/pi-sdk-backend.js +0 -383
  183. package/dist/subagent/pi-sdk-backend.js.map +0 -1
  184. package/dist/subagent/pi-subprocess-backend.d.ts +0 -72
  185. package/dist/subagent/pi-subprocess-backend.d.ts.map +0 -1
  186. package/dist/subagent/pi-subprocess-backend.js +0 -756
  187. package/dist/subagent/pi-subprocess-backend.js.map +0 -1
  188. package/dist/subagent/subprocess-bridge.d.ts +0 -21
  189. package/dist/subagent/subprocess-bridge.d.ts.map +0 -1
  190. package/dist/subagent/subprocess-bridge.js +0 -87
  191. package/dist/subagent/subprocess-bridge.js.map +0 -1
  192. package/dist/subagent/subprocess-report.d.ts +0 -4
  193. package/dist/subagent/subprocess-report.d.ts.map +0 -1
  194. package/dist/subagent/subprocess-report.js +0 -55
  195. package/dist/subagent/subprocess-report.js.map +0 -1
  196. package/dist/subagent-contract.d.ts +0 -8
  197. package/dist/subagent-contract.d.ts.map +0 -1
  198. package/dist/subagent-contract.js +0 -8
  199. package/dist/subagent-contract.js.map +0 -1
  200. package/dist/web-editor/client/api.d.ts +0 -9
  201. package/dist/web-editor/client/api.d.ts.map +0 -1
  202. package/dist/web-editor/client/api.js +0 -26
  203. package/dist/web-editor/client/api.js.map +0 -1
  204. package/dist/web-editor/client/dom.d.ts +0 -13
  205. package/dist/web-editor/client/dom.d.ts.map +0 -1
  206. package/dist/web-editor/client/dom.js +0 -30
  207. package/dist/web-editor/client/dom.js.map +0 -1
  208. package/dist/web-editor/client/inspector.d.ts +0 -22
  209. package/dist/web-editor/client/inspector.d.ts.map +0 -1
  210. package/dist/web-editor/client/inspector.js +0 -226
  211. package/dist/web-editor/client/inspector.js.map +0 -1
  212. package/dist/web-editor/client/main.d.ts +0 -2
  213. package/dist/web-editor/client/main.d.ts.map +0 -1
  214. package/dist/web-editor/client/main.js +0 -1468
  215. package/dist/web-editor/client/main.js.map +0 -1
  216. package/dist/web-editor/client/policy-editor.d.ts +0 -16
  217. package/dist/web-editor/client/policy-editor.d.ts.map +0 -1
  218. package/dist/web-editor/client/policy-editor.js +0 -330
  219. package/dist/web-editor/client/policy-editor.js.map +0 -1
  220. package/dist/web-editor/client/regex-editor.d.ts +0 -19
  221. package/dist/web-editor/client/regex-editor.d.ts.map +0 -1
  222. package/dist/web-editor/client/regex-editor.js +0 -281
  223. package/dist/web-editor/client/regex-editor.js.map +0 -1
  224. package/dist/web-editor/client/types.d.ts +0 -60
  225. package/dist/web-editor/client/types.d.ts.map +0 -1
  226. package/dist/web-editor/client/types.js +0 -2
  227. package/dist/web-editor/client/types.js.map +0 -1
@@ -0,0 +1,204 @@
1
+ # Subagent adapter contract
2
+
3
+ Status: experimental exported pure contract and host-preparation utilities for 0.4. This is a narrow one-shot delegation boundary, not a background orchestration runner or an OS sandbox.
4
+
5
+ > **Migration note (0.4):** execution ownership — backend registration, preflight binding, plan sealing, conversation/execution fingerprint issuance, lifecycle arbitration, and both fresh-process backends (`pi-subprocess-readonly`, `pi-rpc-readonly`) — lives in [`@zihanw/pi-subagent-runtime`](https://github.com/MacroSony/pi-subagent-runtime). Forge keeps the host surface described here (profiles, compilation, approval, plan/response product types) and consumes the runtime through its public API. The former in-package `SubagentBackendRegistry`, `PiSubprocessBackend`, and `PiSdkIsolatedBackend` exports no longer ship. Sections 8-9 below describe the superseded in-package design and remain as historical context.
6
+
7
+ ## Public Surface
8
+
9
+ New integrations should import this experimental 0.4 surface from `@zihanw/pi-forge/subagent`. The package root re-exports the same names through 0.4 for compatibility. Stability classifications and compatibility-path policy are recorded in the [public API policy](public-api.md).
10
+
11
+ The package root exports:
12
+
13
+ - `AgentRequest`, `AgentProfileSnapshot`, `BackendPreflightResult`, `AgentExecutionPlan`, and `AgentResponse`.
14
+ - Granular access, limit, tool, media, context, artifact, trace, usage, and diagnostic types.
15
+ - Host resolution through `resolveSubagentHostProfile()`.
16
+ - Tool negotiation through `negotiateSubagentTools()`.
17
+ - Deterministic context preparation through `budgetSubagentContext()`, `renderSubagentSelectedContext()`, and `prepareSubagentInitialMessages()`.
18
+ - Protected Pi-message helpers.
19
+ - Plan construction through `createAgentExecutionPlan()`.
20
+ - Pure request, snapshot, preflight, plan, response, artifact, and trace validators. Portable leaf validators (access, limits, prompt runtime, descriptors, enforcement) are re-exported from the runtime core so one implementation serves both packages.
21
+ - Canonical `sha256:v1` profile, stack, and prompt-runtime fingerprints.
22
+ - Host preparation through `prepareSubagentHostPlan()`.
23
+
24
+ The existing `agentProfileFingerprint()` remains unchanged. It is still the legacy JSON provenance value used for branch drift. Portable fingerprints use separately named functions and semantics.
25
+
26
+ Conversation and execution fingerprints are **not** host-computed: they are issued by `@zihanw/pi-subagent-runtime` when it seals a prepared plan and are passed into `createAgentExecutionPlan()` as required inputs. The host validates their shape and propagates them; substitution detection is the runtime's sealed-plan binding.
27
+
28
+ ## Required Flow
29
+
30
+ ```text
31
+ AgentRequest
32
+ -> resolveSubagentHostProfile
33
+ -> ExecutionRuntime.prepare (explicit backendId; backend preflight;
34
+ backend-assisted host compilation through the compile callback)
35
+ -> runtime sealing (conversation + execution fingerprints)
36
+ -> createAgentExecutionPlan (host plan carrying the sealed fingerprints)
37
+ -> host approval bound to the sealed fingerprints
38
+ -> ExecutionRuntime.execute
39
+ -> validateAgentResponse
40
+ ```
41
+
42
+ No stage may substitute parent-runtime model objects, credentials, source file paths, or raw session history for the portable artifacts.
43
+
44
+ ### 1. Request validation
45
+
46
+ `validateAgentRequest()` checks:
47
+
48
+ - Schema, IDs, task text/media references, and media digests.
49
+ - Explicit selected-context byte budgets and provenance.
50
+ - Delegation depth.
51
+ - Access-level/workspace/working-directory/network/process combinations.
52
+ - Required versus best-effort hard limits.
53
+ - Result-projection bounds and remote-egress consent.
54
+
55
+ Media references are opaque host resources with content digests. The contract does not place local absolute paths or media bytes in the portable request.
56
+
57
+ ### 2. Host resolution
58
+
59
+ `resolveSubagentHostProfile()` performs only backend-independent work:
60
+
61
+ - Validates the loaded profile and exact prompt-stack reference.
62
+ - Accepts null, default/replace, append, and prepend stack modes.
63
+ - Scans prompt-stack items for custom macro and slot dependencies.
64
+ - Requires those registrations to be loaded before final resolution.
65
+ - Produces a path-free immutable profile snapshot and portable fingerprints.
66
+
67
+ It deliberately does not inspect a model registry, authentication, backend tools, mounts, or limits. Parent `/profile use` resolution remains separate.
68
+
69
+ Unknown macro commands and custom slots are treated as missing subagent dependencies. Static stack variables and built-in macros/slots are excluded. Custom registrations without a `source` still resolve but produce a warning because their dependency identity is anonymous.
70
+
71
+ ### 3. Backend preflight
72
+
73
+ An accepted `BackendPreflightResult` must identify the exact model/thinking level, dynamic tool catalog, granular capabilities, effective access receipt, and accepted limit receipt.
74
+
75
+ `validateBackendPreflight()` enforces:
76
+
77
+ - Exact profile model and thinking-level agreement.
78
+ - Explicit consent for remote provider transport.
79
+ - Requested media MIME support.
80
+ - No missing, extra, upgraded, or mode-mismatched mounts.
81
+ - Working-directory containment through backend mount IDs.
82
+ - Read/write, symlink, process, and denied-network enforcement claims.
83
+ - Every required limit uses `backend-hard` enforcement.
84
+ - Best-effort limits are reported honestly, such as Pi SDK host-abort timeouts.
85
+ - Rejected preflight results contain at least one error diagnostic.
86
+
87
+ Prompt tool filtering is not accepted as an access receipt.
88
+
89
+ ### 4. Tool negotiation
90
+
91
+ Each backend tool declares a stable backend ID, policy-facing name, and effects:
92
+
93
+ - `filesystem-read`
94
+ - `filesystem-write`
95
+ - `process`
96
+ - `network`
97
+
98
+ `negotiateSubagentTools()` applies prompt-stack policy to names, then removes tools whose declared effects exceed request access. Effect-free tools may remain under filesystem access `none`; network and process are independently controlled. Unmatched allow patterns remain warnings.
99
+
100
+ Adapters must classify tool effects conservatively. A tool with undeclared effects invalidates the backend's enforcement claim even if name filtering succeeds.
101
+
102
+ ### 5. Context and exact preparation
103
+
104
+ `budgetSubagentContext()` measures the exact UTF-8 bytes of the rendered selected-context envelope. Required items are retained first. Optional items are considered newest-to-oldest without partial item truncation, and returned in original order. Required overflow fails preparation.
105
+
106
+ `prepareSubagentInitialMessages()` creates:
107
+
108
+ 1. One quoted selected-context message when the budget retains context.
109
+ 2. Host-prepared prompt-stack messages.
110
+ 3. The complete protected task/media message as the final user message.
111
+
112
+ Prompt-stack messages cannot claim reserved selected-context or delegated-task markers.
113
+
114
+ Backends such as Pi SDK may expose exact base-prompt runtime inputs only in a pre-provider hook. They may call the host preparer there, but provider transport must remain blocked until `createAgentExecutionPlan()` succeeds. A `partial` prompt-runtime preflight cannot produce an execution plan.
115
+
116
+ ### 6. Plan and fingerprints
117
+
118
+ `createAgentExecutionPlan()` revalidates the request, snapshot, preflight, deterministic context receipt, tool negotiation, runtime fidelity, and protected final task. It carries the runtime-issued conversation and execution fingerprints as required inputs; the host never computes either value.
119
+
120
+ The runtime's conversation fingerprint binds the exact sealed system prompt and ordered messages, so equivalent conversations on different backends compare equal. Its execution fingerprint additionally binds the accepted backend, preflight, effective tools, access and limit receipts, and runtime inputs, so the same conversation on different backends produces different execution fingerprints. Approval displays both values and execution accepts only the runtime-bound prepared handle.
121
+
122
+ Canonical serialization sorts object keys, omits undefined object fields, rejects cycles/non-finite numbers/non-JSON values, preserves array order, and normalizes negative zero.
123
+
124
+ ### 7. Response validation
125
+
126
+ `validateAgentResponse()` enforces the terminal status matrix:
127
+
128
+ | Status | Required terminal field | Output rule |
129
+ |---|---|---|
130
+ | `completed` | none | absent or `partial: false` |
131
+ | `failed` | structured `error` | absent or `partial: true` |
132
+ | `cancelled` | `reason` | absent or `partial: true` |
133
+ | `timed-out` | `reason`, `enforcedTimeoutMs` | absent or `partial: true` |
134
+ | `limit-reached` | `reachedLimit` | absent or `partial: true` |
135
+
136
+ It also validates request/run/backend correlation, model and fingerprints, effective backend tool IDs, backend-produced enforcement receipts, duration, token/cost units, artifact namespaces, relative paths, cleanup ownership, and authorized trace handles. Cost requires an ISO 4217 currency code.
137
+
138
+ ### 8. Optional backend registry
139
+
140
+ `SubagentBackendRegistry` starts empty and never installs a default backend. It:
141
+
142
+ - Validates backend descriptors and rejects duplicate identities.
143
+ - Binds accepted preflight IDs to the exact backend, request, and profile fingerprint used during discovery.
144
+ - Routes exact-preflight preparation directly to the host preparer and requires backend-assisted adapters to invoke the same host boundary.
145
+ - Binds the exact runtime fingerprint, compiled system/messages, effective tools, and context receipt returned by host preparation; recomputing an execution fingerprint cannot substitute a different plan.
146
+ - Routes dry-plan discard through the owning backend before forgetting the preflight binding.
147
+ - Rejects malformed, tampered, foreign, or unbound execution plans before transport.
148
+ - Arbitrates backend completion, explicit user cancellation, external abort signals, and declared host-abort timeouts through one terminal result.
149
+ - Discards prepared backend state without invoking execution when cancellation wins before backend dispatch.
150
+ - Normalizes thrown provider failures and malformed backend responses into contract-valid failed responses.
151
+ - Replaces backend-reported duration with host-observed duration.
152
+ - Keeps opaque backend trace IDs behind host-generated handles and enforces authorization scope, backend routing, expiry, and explicit forgetting during inspection.
153
+ - Refuses backend unregistration while an execution remains active or is draining after cancellation.
154
+
155
+ The registry validates receipts but does not manufacture filesystem, process, network, token, turn, or output isolation. Those remain adapter responsibilities.
156
+
157
+ Access receipts may explicitly declare `executionBoundary: "shared-user"`. This boundary means the subprocess retains the invoking user's operating-system permissions and its effective access is constrained only by the tools exposed to the model. A shared-user receipt cannot claim mount, symlink, process, or network isolation. Omitting the field preserves the legacy `isolated` interpretation.
158
+
159
+ ### 9. Experimental foreground subprocess and approval path
160
+
161
+ `PiSubprocessBackend` is the extension's deliberately narrow default adapter:
162
+
163
+ - It resolves the exact profile model through Pi's existing `ModelRegistry`, reuses the host Pi `ModelRuntime` so preparation sees the same authentication, and prepares the exact prompt inside an in-process Pi session held behind a provider gate. Required host capabilities are checked and fail closed before provider transport.
164
+ - After approval, it disposes the preparation session and launches a fresh foreground Pi subprocess with the approved model, thinking level, system prompt, messages, and tool IDs. Pi's ordinary text stdout is drained separately from a dedicated newline-delimited report channel.
165
+ - Its bridge preserves the exact prepared messages and rejects tools outside the approved allowlist. Candidate tools are limited to `read`, `grep`, `find`, and `ls`, then intersected with prompt-stack policy.
166
+ - It loads no write/edit/shell tools, skills, prompt templates, context files, themes, or third-party Pi extensions and writes no child session file.
167
+ - It accepts text-only, one-shot, sequential `read-only` requests rooted at the project working directory, with no process tool and optional host-abort timeout. It advertises no artifact retention or contract trace inspection.
168
+ - It records a bounded foreground execution report containing sanitized transcript events, tool calls/results, usage, stderr, status, and execution identity. Inline images remain available to the child model but cross the report boundary only as MIME/encoded-size metadata. Base64-like text is redacted, individual strings are capped, and retained messages form a 512 KiB rolling tail so large tool histories cannot make the parent TUI/session retain unbounded data. Temporary bridge inputs are mode `0600` and removed during cleanup.
169
+ - Retained textual tool results are ordinary parent-session tool details. `/tree` can move the active branch away from them but does not erase abandoned entries from Pi's on-disk session JSONL; callers handling sensitive files must treat session-data deletion as a separate operation.
170
+
171
+ This backend declares `executionBoundary: "shared-user"`. It does not create allowed-root mount containment, symlink-safe path containment, process isolation, or agent-network isolation. The subprocess retains the invoking user's OS permissions; `read-only` describes the tools exposed to the model, not a security sandbox. Network is therefore honestly recorded as allowed even though no dedicated network or shell tool is exposed.
172
+
173
+ The model-callable `forge_subagent_profiles` tool reads the already-loaded host profile catalog without preparing a prompt or contacting a provider, then filters it through explicit trusted-project `subagents.profiles.<id>.enabled` policy. Global config supplies only general backend/timeout defaults; global profile entries warn and are ignored because the loaded profile and stack catalog is project-local. The tool exposes only delegation-enabled IDs, names, descriptions, declared model/thinking/stack metadata, effective backend/timeout and sources, ready/unavailable resolution diagnostics, and whether parent policy currently exposes the invocation tool. Disabled and unlisted profiles remain usable through ordinary profile workflows but cannot be delegated. A restrictive parent stack must allow both `forge_subagent_profiles` and `forge_subagent` for discovery followed by delegation.
174
+
175
+ The model-callable `forge_subagent` tool and `/forge-agent run` use the same runtime path. Both reject profiles that are not explicitly enabled, resolve global/project general defaults plus trusted-project per-profile backend/timeout policy, and prepare an exact immutable plan while provider transport remains closed. `/forge-agent run` always shows a compact approval summary, allows inspection of the complete prompt, and requires interactive approval bound to the execution fingerprint. The tool does the same by default, but a trusted project may set `subagents.allowAgentInvocationWithoutApproval: true` in `.pi/forge/config.json`; this permits non-UI model invocation pinned to the effective configured profile backend and records `trusted-project-config` in the result receipt without weakening eligibility, preflight, or plan binding. Missing, malformed, and untrusted-project settings fail closed. The tool returns bounded content to the parent model and expandable execution details to the human. `/forge-agent plan` still prepares and discards without provider transport; `/forge-agent backends` shows capabilities and effective enabled-profile settings. Fresh-process backend registration, binding, lifecycle, and execution are provided by `@zihanw/pi-subagent-runtime`.
176
+
177
+ ## Adapter-Enforced Responsibilities
178
+
179
+ The exported validators cannot create isolation. Every adapter remains responsible for:
180
+
181
+ - Credential and model availability in its own runtime.
182
+ - Backend-side mount materialization and path canonicalization immediately before access.
183
+ - Symlink-race-safe containment.
184
+ - Process and agent-network isolation.
185
+ - Accurate tool effects and stable tool mappings.
186
+ - Required hard timeout, turn, token, and output limits.
187
+ - Cancellation settlement and cleanup.
188
+ - Media transport and remote-egress behavior.
189
+ - Artifact authorization, retention, and cleanup.
190
+ - Trace storage, authorization, redaction, pagination, and expiry.
191
+ - Returning actual enforcement receipts rather than echoing request fields.
192
+
193
+ An adapter must reject preflight when it cannot enforce a required field. Both shipped process adapters accept shared-user read-only access and network allow, and use best-effort host abort rather than a backend-hard timeout. Provider transport is always a separate, explicitly approved egress path.
194
+
195
+ ## Deliberately Not Included
196
+
197
+ - Filesystem writes, process/shell tools, media input, or background runs in the shipped path.
198
+ - OS-level filesystem, process, or network sandboxing for the shared-user subprocess.
199
+ - Automatic parent-history/context selection; the delegated task is explicit and starts a clean conversation.
200
+ - Session resume, retries, queues, chains, or pipelines.
201
+ - Artifact/trace storage implementations.
202
+ - Automatic provider or backend fallback.
203
+
204
+ Those belong to later iterations and cannot be inferred from these pure types alone.
@@ -0,0 +1,37 @@
1
+ # pi-forge 中文文档
2
+
3
+ [项目首页](../../README.zh-CN.md) · [English docs](../README.md)
4
+
5
+ ## 从这里开始
6
+
7
+ - [快速上手](getting-started.md):安装、创建 stack、打开编辑器并保存 profile。
8
+ - [Prompt stack](concepts/prompt-stacks.md):prompt 组合、历史布局和策略模型。
9
+ - [Agent profile](concepts/agent-profiles.md):一次性模型/思考等级/stack 预设。
10
+
11
+ ## 指南
12
+
13
+ - [Web 编辑器](guides/web-editor.md)
14
+ - [实验性前台 delegation](guides/delegation.md):启用前请先阅读安全边界。
15
+ - [Prompt stack 使用场景(英文)](../guides/use-cases.md)
16
+
17
+ SillyTavern 导入、自定义 macros/slots 和调试的完整说明目前以英文版为准:
18
+
19
+ - [SillyTavern import](../guides/sillytavern-import.md)
20
+ - [Custom macros and slots](../guides/custom-macros-and-slots.md)
21
+ - [Prompt and payload debugging](../guides/debugging.md)
22
+
23
+ ## 参考
24
+
25
+ - [命令参考](reference/commands.md)
26
+ - [Stack schema 与策略(英文)](../reference/stack-schema.md)
27
+ - [Macros 与 slots(英文)](../reference/macros-and-slots.md)
28
+ - [配置(英文)](../reference/configuration.md)
29
+ - [Public API(英文)](../reference/public-api.md)
30
+ - [实验性 subagent adapter(英文)](../reference/subagent-adapter.md)
31
+
32
+ ## 开发与设计
33
+
34
+ - [开发设置与兼容性(英文)](../development/setup.md)
35
+ - [Release 流程(英文)](../development/release.md)
36
+ - [Roadmap(英文)](../development/roadmap.md)
37
+ - [历史设计档案(英文)](../design/README.md)
@@ -0,0 +1,46 @@
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 status` 会把 profile 源定义变化和当前模型/思考等级/stack drift 分开显示。Provenance 只用于 branch 状态报告;reload、resume、tree navigation 和 compaction 不会重新应用 profile。
45
+
46
+ 普通 profile 默认不能委派。Delegation 授权跟随 profile scope:可信项目 `.pi/forge/config.json` 的 `subagents.profiles.<id>` 只授权 `project:<id>`,用户全局 `~/.pi/forge/config.json` 的 `subagents.profiles.<id>` 只授权 `global:<id>`;同 ID 的全局和项目 profile 永不互相继承授权。删除 profile 会清除同 scope 的授权,防止以后同 ID profile 继承权限。启用前见[前台 delegation](../guides/delegation.md)。
@@ -0,0 +1,42 @@
1
+ # Prompt stack
2
+
3
+ [中文文档](../README.md) · [English](../../concepts/prompt-stacks.md)
4
+
5
+ Prompt stack 是一份有序、声明式的 prompt 与策略描述,由固定 **block** 和动态 **slot** 组成。Stack 可以放在项目 `.pi/forge/prompt-stacks/`,也可以放在用户全局 `~/.pi/forge/prompt-stacks/`。命令接受 `reviewer`、`project:reviewer` 和 `global:reviewer`;未限定 ID 优先解析项目 stack,项目 stack 会遮蔽同 ID 全局 stack。重复 ID 只在同一 scope 内算错误。
6
+
7
+ ## 编译模型
8
+
9
+ 每个用户轮次开始时,pi-forge 会:
10
+
11
+ 1. 按 JSON 顺序排列启用的 block/slot。
12
+ 2. 构建 system 内容,并使用 `replace`、`append` 或 `prepend` 模式。
13
+ 3. 在可移动 `chat-history` 周围插入 user/assistant 消息。
14
+ 4. 展开内置、变量和可信自定义宏。
15
+ 5. 对 Pi 执行工具策略,并过滤 pi-forge 渲染的 skills。
16
+ 6. 应用 history/compiled outgoing regex。
17
+ 7. 可选地在消息完成后应用破坏性的 finalize regex。
18
+
19
+ ## 常用历史布局
20
+
21
+ 1. 长期 system 规则。
22
+ 2. 工具和项目上下文。
23
+ 3. `includeLastUserMessage: false` 的 `chat-history`。
24
+ 4. 包含 `{{lastUserMessage}}` 的最终 user block。
25
+
26
+ 这样既保留旧上下文,又只在最后明确出现一次当前请求。History 还可以过滤 summary/role、去掉旧工具消息、移除 assistant thinking,并限制消息数或字符数。
27
+
28
+ ## 策略边界
29
+
30
+ 工具 `allow`/`deny` 会修改 Pi active tools,并在 tool call 时再次检查。Skill policy 只过滤 pi-forge 渲染给模型的列表;它不能阻止明确调用,也不是安全边界。若必须控制模型可见 skill 列表,请使用 `replace`,因为 Pi 的基础 prompt 可能已经在 `append`/`prepend` 内容之前列出 skills。
31
+
32
+ ## Scope 与自动启用
33
+
34
+ - 只有显式设置 `"autoActivate": true` 的 stack 参与自动启用;文件名(包括 `default.json`)没有特殊作用。
35
+ - 项目 stack 优先于全局 stack;项目 scope 存在候选时,即使项目候选无效或冲突也会 fail closed,不会回退到全局 stack。
36
+ - 同 ID 项目 stack 会遮蔽全局 stack,包括无效 shadow 或显式 opt-out。
37
+ - `/preset use none` 会记录 session branch 的 opt-out。
38
+ - Active stack 和 session variables 会跟随 Pi session tree branch。
39
+ - 恢复的 branch 状态优先于新 session 自动启用。
40
+ - 自动启用的 agent profile 优先于独立 stack autoload。
41
+
42
+ 完整字段见英文 [stack schema](../../reference/stack-schema.md),macro/slot 见[参考](../../reference/macros-and-slots.md)。
@@ -0,0 +1,81 @@
1
+ # 快速上手
2
+
3
+ [中文文档](README.md) · [English](../getting-started.md)
4
+
5
+ ## 安装
6
+
7
+ pi-forge 需要 Node.js 22.19 或更高版本,并作为 Pi extension 运行:
8
+
9
+ ```bash
10
+ pi install npm:@zihanw/pi-forge
11
+ ```
12
+
13
+ 安装或更新后请重启 Pi。Pi host 会提供运行时 SDK;精确 package 版本只用于可复现的开发测试。用户全局 stack/profile 始终可以浏览;项目 stack、profile 和 config 只在 Pi 信任项目后加载和写入。
14
+
15
+ ## 第一个 stack
16
+
17
+ Prompt stack 保存在 `.pi/forge/prompt-stacks/*.json`。推荐从 [默认 Pi mirror](../../examples/default-prompt-stack.json) 开始:
18
+
19
+ ```bash
20
+ mkdir -p .pi/forge/prompt-stacks
21
+ cp examples/default-prompt-stack.json .pi/forge/prompt-stacks/default.json
22
+ ```
23
+
24
+ 如果不是在仓库 clone 中,可以打开 `/preset ui` 新建 stack;编辑器使用同样的默认布局。
25
+
26
+ ```text
27
+ /preset reload
28
+ /preset use default
29
+ ```
30
+
31
+ 示例中的 `default.json` 带 `"autoActivate": true`,因此没有恢复的 session 选择或明确 opt-out 时会自动启用。设置 `"autoActivate": false` 可以关闭此行为;文件名本身没有特殊作用。
32
+
33
+ ## 编辑和检查
34
+
35
+ ```text
36
+ /preset ui
37
+ ```
38
+
39
+ 编辑器运行在带 token 的本地 `127.0.0.1` URL,支持结构化/原始 JSON 编辑、排序、校验、完整预览、策略、regex、导入导出、fork 和 profile 管理。工具栏的 scope 下拉(默认 `project`)决定新建、fork 和导入 stack 写入项目 `.pi/forge/prompt-stacks` 还是用户全局 `~/.pi/forge/prompt-stacks`。
40
+
41
+ 命令行也可以检查:
42
+
43
+ ```text
44
+ /preset validate default
45
+ /preset preview default
46
+ /preset diagnostics
47
+ ```
48
+
49
+ ## 创建 profile
50
+
51
+ 先选择模型、思考等级和 stack,然后执行:
52
+
53
+ ```text
54
+ /profile save reviewer
55
+ /profile preview reviewer
56
+ /profile use reviewer
57
+ ```
58
+
59
+ Profile 默认保存在 `.pi/forge/agent-profiles/*.json`。`/profile save global:reviewer` 会写入用户全局 `~/.pi/forge/agent-profiles`。应用是经过 preflight 的一次性操作;之后的手动设置不会被自动覆盖。
60
+
61
+ ## 存储与迁移
62
+
63
+ | 路径 | 用途 |
64
+ |---|---|
65
+ | `.pi/forge/prompt-stacks/` | 项目 prompt stacks |
66
+ | `.pi/forge/agent-profiles/` | 项目 agent profiles |
67
+ | `.pi/forge/config.json` | 项目配置和 `project:<id>` delegation 授权 |
68
+ | `.pi/forge/extensions/` | 可信项目 macro/slot 代码 |
69
+ | `~/.pi/forge/prompt-stacks/` | 用户全局 prompt stacks |
70
+ | `~/.pi/forge/agent-profiles/` | 用户全局 agent profiles |
71
+ | `~/.pi/forge/config.json` | 用户默认配置和 `global:<id>` delegation 授权 |
72
+ | `~/.pi/forge/extensions/` | 可信用户 macro/slot 代码 |
73
+
74
+ 旧的 `.pi/prompt-stacks/*.json` 仍可读取;命令创建的 stack 会写到 `.pi/forge/prompt-stacks`,使用 Web 编辑器的 `global` scope 下拉可创建到用户全局 `~/.pi/forge/prompt-stacks`。安全迁移方式:
75
+
76
+ ```text
77
+ /preset migrate-stacks --dry-run
78
+ /preset migrate-stacks
79
+ ```
80
+
81
+ 确认复制结果后再考虑 `--overwrite` 或 `--delete-legacy`。
@@ -0,0 +1,66 @@
1
+ # 实验性前台 delegation
2
+
3
+ [中文文档](../README.md) · [English](../../guides/delegation.md)
4
+
5
+ > **实验性:** 此 API 和 backend 可能独立于稳定的 prompt stack/profile 功能发生变化。
6
+
7
+ pi-forge 可以把明确授权的 agent profile 作为独立、干净、一次性的 Pi 进程执行。它在前台运行,并向父对话返回有界报告。
8
+
9
+ ## 启用 profile
10
+
11
+ Profile 默认不能委派。请在可信项目的 `.pi/forge/config.json` 中逐个启用项目 profile,在用户全局 `~/.pi/forge/config.json` 中逐个启用全局 profile;也可以使用 `/preset ui` 的 delegation 卡片:
12
+
13
+ ```json
14
+ {
15
+ "subagents": {
16
+ "backend": "pi-subprocess-readonly",
17
+ "timeoutMs": 60000,
18
+ "profiles": {
19
+ "reviewer": {
20
+ "enabled": true,
21
+ "timeoutMs": 300000
22
+ }
23
+ }
24
+ }
25
+ }
26
+ ```
27
+
28
+ 授权跟随 profile scope:项目 config 的 `subagents.profiles.<id>` 只授权 `project:<id>`,全局 config 的 `subagents.profiles.<id>` 只授权 `global:<id>`。同 ID 的全局和项目 profile 不会互相继承 enable/backend/timeout。未启用或未列出的 ID 不会被 discovery 返回,即使猜中 ID 也会被拒绝。
29
+
30
+ ## Plan 与运行
31
+
32
+ ```text
33
+ /forge-agent backends
34
+ /forge-agent plan reviewer 检查这个 API 设计。
35
+ /forge-agent run reviewer 检查这个 API 设计。
36
+ ```
37
+
38
+ `plan` 会解析 profile/stack、编译并校验不可变的实际 provider-bound 计划,然后在不联系 provider 的情况下丢弃。Profile selector 在所有入口使用同一语法:`reviewer`(项目优先)、`project:reviewer` 或 `global:reviewer`。同 ID 冲突时,项目 profile 保持简写 selector,全局 profile 仍通过 `global:<id>` 调用。
39
+
40
+ 父模型使用无数据外发的 `forge_subagent_profiles` 做 discovery,再用 `forge_subagent` 执行。限制严格的父 stack 必须允许这两个工具名。
41
+
42
+ 当前有两个 fresh-process backend:默认 `pi-subprocess-readonly` 使用 text/print,`pi-rpc-readonly` 使用 RPC。两者执行同一密封 prompt 和 shared-user 只读策略。所选 backend 不可用时会 fail closed,不会自动 fallback。
43
+
44
+ ## 审批
45
+
46
+ 默认情况下,provider transport 前会显示与执行 fingerprint 绑定的计划,包括任务、profile/stack、provider/model、thinking、工具、cwd、安全边界和 payload 大小。可以选择 **View full prompt** 检查完整 system prompt 和消息。
47
+
48
+ 可信项目可以明确允许模型无需逐次审批:
49
+
50
+ ```json
51
+ {
52
+ "subagents": {
53
+ "allowAgentInvocationWithoutApproval": true
54
+ }
55
+ }
56
+ ```
57
+
58
+ 它只影响 `forge_subagent`;`/forge-agent run` 仍需要交互审批。格式错误或不可信项目会 fail closed。请把此 config 当作授权文件:除非所有可调用父 agent 都可以无需再次询问就把编译 prompt 和可读文件发给 provider,否则不要启用或提交此设置。
59
+
60
+ ## Child 边界
61
+
62
+ Child 从干净对话开始,不会自动继承父 history。候选工具只有 `read`、`grep`、`find`、`ls`,并继续受到 stack policy 限制。它不会加载 write/edit/shell、skills、prompt templates、context files 或第三方 extensions。
63
+
64
+ > **当前 backend 是 shared-user,不是操作系统沙箱。** “只读”只是模型工具策略,进程仍拥有启动用户的 OS 权限。该用户可读的绝对路径可能被读取并发送给 provider;文本可能保留在父 tool-result 和 Pi session JSONL。Timeout/取消仅为 best effort。`/tree` 不能撤销 provider 请求、计费或外部影响,也不保证删除磁盘上的 abandoned entry。
65
+
66
+ 不要给此 shared-user 设计添加 write/edit/shell。操作系统隔离和需要第二次审批的 staged write 属于未来工作。
@@ -0,0 +1,45 @@
1
+ # Web 编辑器
2
+
3
+ [中文文档](../README.md) · [English](../../guides/web-editor.md)
4
+
5
+ 在可信 Pi 项目中执行:
6
+
7
+ ```text
8
+ /preset ui
9
+ ```
10
+
11
+ `/preset ui restart` 会替换 server,`/preset ui stop` 会关闭它。
12
+
13
+ 编辑器绑定在带 session token 的可用 `127.0.0.1` 端口;多个项目可以同时运行。读取、预览和 payload 检查在合适范围内可用;写入要求 Pi 信任项目,并且文件被限制在 pi-forge 的 stack/profile 存储内。可以在 `.pi/forge/config.json` 中设置偏好端口:
14
+
15
+ ```json
16
+ {
17
+ "webEditor": { "port": 41738 }
18
+ }
19
+ ```
20
+
21
+ 端口被占用时会自动选择其他端口。请不要把带 token 的编辑器 URL 暴露或代理到不可信网络。写入操作要求项目已被 Pi 信任。
22
+
23
+ ## Prompt stack 工作区
24
+
25
+ 支持:
26
+
27
+ - 从默认 Pi mirror 新建 stack;
28
+ - 结构化和原始 JSON 编辑;
29
+ - 拖拽排序、启用/禁用、校验和完整编译预览;
30
+ - 工具/skill 搜索、精确名称 chips 和通配符策略;
31
+ - variables、context 和 regex 规则;
32
+ - 原生 pi-forge 与 SillyTavern JSON 导入;
33
+ - 导出、fork、删除和 payload 捕获。
34
+
35
+ 已有 ID 在编辑时不可修改;需要新 ID 时使用 **Fork**,避免破坏 profile 引用和当前选择。工具栏的 scope 下拉(默认 `project`)决定新建、导入和 fork 的写入位置:选择 `global` 写入用户全局 `~/.pi/forge/prompt-stacks`,选择 `project` 写入项目 `.pi/forge/prompt-stacks`。列表会为全局 stack 显示 `global` badge;保存和删除通过 `global:<id>` 路由精确作用于全局文件。保存、导入、fork 和删除后会重新加载当前 Pi session。
36
+
37
+ ## Agent profile 工作区
38
+
39
+ 列表显示 profile ID、名称、模型、思考等级、stack、校验状态、auto-activation、last-applied provenance 和 delegation 状态。每个 profile 都带 `project` / `global` scope badge;同 ID 的 shadow 对会显示 `shadows global:<id>` 或 `shadowed by project:<id>`。
40
+
41
+ 可信项目通过 **New profile** 旁的 scope 下拉(默认 `project`)选择目标 scope:选择 `global` 写入用户全局 `~/.pi/forge/agent-profiles`,选择 `project` 写入项目 `.pi/forge/agent-profiles`。全局 profile 可通过显式 `global:<id>` 路由编辑、校验、保存、一次性应用和删除;未限定路由始终只作用于项目资源。编辑全局 profile 时,stack 下拉只显示全局 stack。Model 选项来自 Pi registry,thinking 选项反映模型支持,stack 选项来自同一个 repository。编辑器会拒绝同 scope 内第二个 auto-activation profile。
42
+
43
+ Delegation 卡片按 profile 的 scope 修改 `subagents.profiles.<id>` 的 enable/backend/timeout:项目 profile 写入项目 config,全局 profile 写入用户全局 config。切换 profile、刷新、删除或离开页面时,未保存的 delegation 字段会得到保护。通用默认值和 `allowAgentInvocationWithoutApproval` 只能在 config 文件中设置。
44
+
45
+ 启用前请阅读[前台 delegation](delegation.md)。
@@ -0,0 +1,60 @@
1
+ # 命令参考
2
+
3
+ [中文文档](../README.md) · [English](../../reference/commands.md)
4
+
5
+ 方括号参数可选。写项目文件的命令要求项目已被信任。未限定的 `<id>` 使用项目优先的有效查找;需要精确选择时使用 `project:<id>` 或 `global:<id>`。
6
+
7
+ ## Prompt stack
8
+
9
+ | 命令 | 行为 |
10
+ |---|---|
11
+ | `/preset list` | 列出 stack 和状态 |
12
+ | `/preset status` | 显示当前 stack 和诊断摘要 |
13
+ | `/preset use <id>` | 校验并选择 stack |
14
+ | `/preset use none` | 在当前 session branch 禁用 stack |
15
+ | `/preset preview [id]` | 编译但不发送 provider 请求 |
16
+ | `/preset validate [id]` | 校验一个或全部 stack |
17
+ | `/preset diagnostics` | 显示 loader、runtime、policy、regex 和 extension 诊断 |
18
+ | `/preset reload` | 重新加载 stack 和可信 macro/slot registration |
19
+ | `/preset ui [stop\|restart]` | 打开或管理 Web 编辑器 |
20
+
21
+ ## 迁移与导入
22
+
23
+ | 命令 | 行为 |
24
+ |---|---|
25
+ | `/preset migrate-stacks [--dry-run] [--overwrite] [--delete-legacy]` | 把旧 stack 复制到 `.pi/forge/prompt-stacks` |
26
+ | `/preset import-silly <path> [character_id] [--dry-run] [--overwrite]` | 转换 SillyTavern preset 并生成报告 |
27
+
28
+ 覆盖或删除之前请先使用 `--dry-run`。
29
+
30
+ ## Agent profile
31
+
32
+ | 命令 | 行为 |
33
+ |---|---|
34
+ | `/profile list` | 列出 profile 和解析诊断 |
35
+ | `/profile use <id>` | preflight 并一次性应用 |
36
+ | `/profile save <id\|global:id> [--overwrite]` | 捕获当前模型、thinking 和 stack;`global:<id>` 写入用户全局目录 |
37
+ | `/profile status` | 比较当前 runtime 和 last-applied provenance |
38
+ | `/profile preview <id>` | 不应用地解析模型/auth/thinking/stack/tools |
39
+ | `/profile validate [id]` | 校验一个或全部 profile |
40
+ | `/profile reload` | 重新加载定义,但不应用 |
41
+ | `/profile forget` | 删除 provenance,不改变 runtime |
42
+
43
+ ## 实验性 delegation
44
+
45
+ | 命令 | 行为 |
46
+ |---|---|
47
+ | `/forge-agent backends` | 列出 backend、capabilities 和默认值 |
48
+ | `/forge-agent plan <profile> [--backend <id>] <task>` | 准备、显示并丢弃计划,不联系 provider |
49
+ | `/forge-agent run <profile> [--backend <id>] <task>` | 审批并执行前台只读任务 |
50
+
51
+ 只接受匹配 scope 明确授权的 profile:项目 config 授权 `project:<id>`,全局 config 授权 `global:<id>`。模型工具为 `forge_subagent_profiles` 和 `forge_subagent`。见[安全说明](../guides/delegation.md)。
52
+
53
+ ## Payload
54
+
55
+ | 命令 | 行为 |
56
+ |---|---|
57
+ | `/intercept` | 显示下一个脱敏 provider payload |
58
+ | `/payload next [save=<path>]` | 显示并可选保存 payload,同时提供给 Web 编辑器 |
59
+
60
+ 即使 credentials 字段被脱敏,保存的 payload 仍可能包含 prompt 和对话内容,请按敏感数据处理。