@zihanw/pi-forge 0.4.0-beta.1 → 0.4.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 (186) hide show
  1. package/CHANGELOG.md +37 -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/forge-config.d.ts +80 -0
  7. package/dist/forge-config.d.ts.map +1 -1
  8. package/dist/forge-config.js +268 -18
  9. package/dist/forge-config.js.map +1 -1
  10. package/dist/index.d.ts +1 -4
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +29 -4
  13. package/dist/index.js.map +1 -1
  14. package/dist/lifecycle.js +1 -1
  15. package/dist/profile-service.d.ts +1 -1
  16. package/dist/profile-service.d.ts.map +1 -1
  17. package/dist/profile-service.js +10 -5
  18. package/dist/profile-service.js.map +1 -1
  19. package/dist/runtime/subagent-runtime.d.ts +23 -8
  20. package/dist/runtime/subagent-runtime.d.ts.map +1 -1
  21. package/dist/runtime/subagent-runtime.js +283 -62
  22. package/dist/runtime/subagent-runtime.js.map +1 -1
  23. package/dist/storage.d.ts +1 -0
  24. package/dist/storage.d.ts.map +1 -1
  25. package/dist/storage.js +15 -1
  26. package/dist/storage.js.map +1 -1
  27. package/dist/subagent/canonical.d.ts +19 -7
  28. package/dist/subagent/canonical.d.ts.map +1 -1
  29. package/dist/subagent/canonical.js +19 -47
  30. package/dist/subagent/canonical.js.map +1 -1
  31. package/dist/subagent/contract.d.ts +1 -2
  32. package/dist/subagent/contract.d.ts.map +1 -1
  33. package/dist/subagent/contract.js +1 -2
  34. package/dist/subagent/contract.js.map +1 -1
  35. package/dist/subagent/index.d.ts +4 -3
  36. package/dist/subagent/index.d.ts.map +1 -1
  37. package/dist/subagent/index.js +4 -3
  38. package/dist/subagent/index.js.map +1 -1
  39. package/dist/subagent/plan.d.ts +5 -1
  40. package/dist/subagent/plan.d.ts.map +1 -1
  41. package/dist/subagent/plan.js +28 -31
  42. package/dist/subagent/plan.js.map +1 -1
  43. package/dist/subagent/types.d.ts +62 -178
  44. package/dist/subagent/types.d.ts.map +1 -1
  45. package/dist/subagent/types.js +1 -1
  46. package/dist/subagent/types.js.map +1 -1
  47. package/dist/subagent/validation.d.ts +14 -14
  48. package/dist/subagent/validation.d.ts.map +1 -1
  49. package/dist/subagent/validation.js +52 -238
  50. package/dist/subagent/validation.js.map +1 -1
  51. package/dist/subagent-command.d.ts.map +1 -1
  52. package/dist/subagent-command.js +109 -16
  53. package/dist/subagent-command.js.map +1 -1
  54. package/dist/subagent-host.d.ts.map +1 -1
  55. package/dist/subagent-host.js +1 -0
  56. package/dist/subagent-host.js.map +1 -1
  57. package/dist/subagent-profile-tool.d.ts +25 -2
  58. package/dist/subagent-profile-tool.d.ts.map +1 -1
  59. package/dist/subagent-profile-tool.js +39 -8
  60. package/dist/subagent-profile-tool.js.map +1 -1
  61. package/dist/subagent-tool.d.ts +6 -3
  62. package/dist/subagent-tool.d.ts.map +1 -1
  63. package/dist/subagent-tool.js +85 -14
  64. package/dist/subagent-tool.js.map +1 -1
  65. package/dist/web-editor/client-script.generated.d.ts +1 -1
  66. package/dist/web-editor/client-script.generated.d.ts.map +1 -1
  67. package/dist/web-editor/client-script.generated.js +1 -1
  68. package/dist/web-editor/client-script.generated.js.map +1 -1
  69. package/dist/web-editor/client-styles.d.ts +2 -0
  70. package/dist/web-editor/client-styles.d.ts.map +1 -0
  71. package/dist/web-editor/client-styles.generated.d.ts +2 -0
  72. package/dist/web-editor/client-styles.generated.d.ts.map +1 -0
  73. package/dist/web-editor/client-styles.generated.js +3 -0
  74. package/dist/web-editor/client-styles.generated.js.map +1 -0
  75. package/dist/web-editor/client-styles.js +2 -0
  76. package/dist/web-editor/client-styles.js.map +1 -0
  77. package/dist/web-editor/page.d.ts +2 -0
  78. package/dist/web-editor/page.d.ts.map +1 -1
  79. package/dist/web-editor/page.js +11 -73
  80. package/dist/web-editor/page.js.map +1 -1
  81. package/dist/web-editor/server.d.ts.map +1 -1
  82. package/dist/web-editor/server.js +148 -0
  83. package/dist/web-editor/server.js.map +1 -1
  84. package/dist/web-editor/styles.d.ts.map +1 -1
  85. package/dist/web-editor/styles.js +60 -3
  86. package/dist/web-editor/styles.js.map +1 -1
  87. package/dist/web-editor/types.d.ts +79 -0
  88. package/dist/web-editor/types.d.ts.map +1 -1
  89. package/dist/web-host.d.ts +13 -2
  90. package/dist/web-host.d.ts.map +1 -1
  91. package/dist/web-host.js +301 -0
  92. package/dist/web-host.js.map +1 -1
  93. package/docs/README.md +41 -0
  94. package/docs/concepts/agent-profiles.md +60 -0
  95. package/docs/concepts/prompt-stacks.md +90 -0
  96. package/docs/design/README.md +17 -0
  97. package/docs/design/roadmap-0.4-archive.md +216 -0
  98. package/docs/design/subagents/design-review.md +220 -0
  99. package/docs/design/subagents/interface-design.md +274 -0
  100. package/docs/design/subagents/sdk-spike-findings.md +117 -0
  101. package/docs/development/complexity-review.md +86 -0
  102. package/docs/development/release.md +31 -0
  103. package/docs/development/roadmap.md +42 -0
  104. package/docs/development/setup.md +75 -0
  105. package/docs/getting-started.md +93 -0
  106. package/docs/guides/custom-macros-and-slots.md +68 -0
  107. package/docs/guides/debugging.md +39 -0
  108. package/docs/guides/delegation.md +99 -0
  109. package/docs/guides/sillytavern-import.md +47 -0
  110. package/docs/guides/use-cases.md +65 -0
  111. package/docs/guides/web-editor.md +75 -0
  112. package/docs/reference/commands.md +60 -0
  113. package/docs/reference/configuration.md +64 -0
  114. package/docs/reference/features.md +279 -0
  115. package/docs/reference/macros-and-slots.md +82 -0
  116. package/docs/reference/public-api.md +28 -0
  117. package/docs/reference/stack-schema.md +167 -0
  118. package/docs/reference/subagent-adapter.md +204 -0
  119. package/docs/zh-CN/README.md +37 -0
  120. package/docs/zh-CN/concepts/agent-profiles.md +44 -0
  121. package/docs/zh-CN/concepts/prompt-stacks.md +40 -0
  122. package/docs/zh-CN/getting-started.md +79 -0
  123. package/docs/zh-CN/guides/delegation.md +66 -0
  124. package/docs/zh-CN/guides/web-editor.md +45 -0
  125. package/docs/zh-CN/reference/commands.md +58 -0
  126. package/package.json +28 -14
  127. package/dist/subagent/backend-registry.d.ts +0 -75
  128. package/dist/subagent/backend-registry.d.ts.map +0 -1
  129. package/dist/subagent/backend-registry.js +0 -463
  130. package/dist/subagent/backend-registry.js.map +0 -1
  131. package/dist/subagent/diagnostics.d.ts +0 -3
  132. package/dist/subagent/diagnostics.d.ts.map +0 -1
  133. package/dist/subagent/diagnostics.js +0 -5
  134. package/dist/subagent/diagnostics.js.map +0 -1
  135. package/dist/subagent/pi-model-runtime.d.ts +0 -8
  136. package/dist/subagent/pi-model-runtime.d.ts.map +0 -1
  137. package/dist/subagent/pi-model-runtime.js +0 -22
  138. package/dist/subagent/pi-model-runtime.js.map +0 -1
  139. package/dist/subagent/pi-sdk-backend.d.ts +0 -23
  140. package/dist/subagent/pi-sdk-backend.d.ts.map +0 -1
  141. package/dist/subagent/pi-sdk-backend.js +0 -383
  142. package/dist/subagent/pi-sdk-backend.js.map +0 -1
  143. package/dist/subagent/pi-subprocess-backend.d.ts +0 -72
  144. package/dist/subagent/pi-subprocess-backend.d.ts.map +0 -1
  145. package/dist/subagent/pi-subprocess-backend.js +0 -756
  146. package/dist/subagent/pi-subprocess-backend.js.map +0 -1
  147. package/dist/subagent/subprocess-bridge.d.ts +0 -21
  148. package/dist/subagent/subprocess-bridge.d.ts.map +0 -1
  149. package/dist/subagent/subprocess-bridge.js +0 -87
  150. package/dist/subagent/subprocess-bridge.js.map +0 -1
  151. package/dist/subagent/subprocess-report.d.ts +0 -4
  152. package/dist/subagent/subprocess-report.d.ts.map +0 -1
  153. package/dist/subagent/subprocess-report.js +0 -55
  154. package/dist/subagent/subprocess-report.js.map +0 -1
  155. package/dist/subagent-contract.d.ts +0 -8
  156. package/dist/subagent-contract.d.ts.map +0 -1
  157. package/dist/subagent-contract.js +0 -8
  158. package/dist/subagent-contract.js.map +0 -1
  159. package/dist/web-editor/client/api.d.ts +0 -9
  160. package/dist/web-editor/client/api.d.ts.map +0 -1
  161. package/dist/web-editor/client/api.js +0 -26
  162. package/dist/web-editor/client/api.js.map +0 -1
  163. package/dist/web-editor/client/dom.d.ts +0 -13
  164. package/dist/web-editor/client/dom.d.ts.map +0 -1
  165. package/dist/web-editor/client/dom.js +0 -30
  166. package/dist/web-editor/client/dom.js.map +0 -1
  167. package/dist/web-editor/client/inspector.d.ts +0 -22
  168. package/dist/web-editor/client/inspector.d.ts.map +0 -1
  169. package/dist/web-editor/client/inspector.js +0 -226
  170. package/dist/web-editor/client/inspector.js.map +0 -1
  171. package/dist/web-editor/client/main.d.ts +0 -2
  172. package/dist/web-editor/client/main.d.ts.map +0 -1
  173. package/dist/web-editor/client/main.js +0 -1468
  174. package/dist/web-editor/client/main.js.map +0 -1
  175. package/dist/web-editor/client/policy-editor.d.ts +0 -16
  176. package/dist/web-editor/client/policy-editor.d.ts.map +0 -1
  177. package/dist/web-editor/client/policy-editor.js +0 -330
  178. package/dist/web-editor/client/policy-editor.js.map +0 -1
  179. package/dist/web-editor/client/regex-editor.d.ts +0 -19
  180. package/dist/web-editor/client/regex-editor.d.ts.map +0 -1
  181. package/dist/web-editor/client/regex-editor.js +0 -281
  182. package/dist/web-editor/client/regex-editor.js.map +0 -1
  183. package/dist/web-editor/client/types.d.ts +0 -60
  184. package/dist/web-editor/client/types.d.ts.map +0 -1
  185. package/dist/web-editor/client/types.js +0 -2
  186. package/dist/web-editor/client/types.js.map +0 -1
@@ -0,0 +1,93 @@
1
+ # Getting started
2
+
3
+ [Documentation](README.md) · [中文](zh-CN/getting-started.md)
4
+
5
+ ## Requirements and installation
6
+
7
+ pi-forge requires Node.js 22.19 or newer and runs as a Pi extension.
8
+
9
+ ```bash
10
+ pi install npm:@zihanw/pi-forge
11
+ ```
12
+
13
+ Restart Pi after installing or updating. The running Pi host supplies its SDK packages; see [Pi compatibility](development/setup.md#pi-compatibility) for the tested-version policy.
14
+
15
+ Project stacks, profiles, and configuration are loaded only after Pi trusts the project.
16
+
17
+ ## Create your first stack
18
+
19
+ Prompt stacks live in `.pi/forge/prompt-stacks/*.json`. The quickest baseline is [the default Pi mirror](../examples/default-prompt-stack.json), which preserves normal Pi behavior while splitting its prompt into movable sections.
20
+
21
+ In a repository clone:
22
+
23
+ ```bash
24
+ mkdir -p .pi/forge/prompt-stacks
25
+ cp examples/default-prompt-stack.json .pi/forge/prompt-stacks/default.json
26
+ ```
27
+
28
+ When installed from npm, open `/preset ui` and create a stack; new stacks start from the same mirror layout.
29
+
30
+ Reload and activate it:
31
+
32
+ ```text
33
+ /preset reload
34
+ /preset use default
35
+ ```
36
+
37
+ If no restored session selection or explicit opt-out takes precedence, `default.json` auto-activates. Set `"autoActivate": false` to prevent that behavior.
38
+
39
+ ## Edit and inspect
40
+
41
+ ```text
42
+ /preset ui
43
+ ```
44
+
45
+ The editor opens on a token-protected `127.0.0.1` URL. It supports structured and raw JSON editing, drag-and-drop ordering, validation, exact preview, policy selection, regex rules, import/export, fork, and profile management. See the [web-editor guide](guides/web-editor.md).
46
+
47
+ To inspect without opening a browser:
48
+
49
+ ```text
50
+ /preset validate default
51
+ /preset preview default
52
+ /preset diagnostics
53
+ ```
54
+
55
+ ## Create a profile
56
+
57
+ Select the model, thinking level, and prompt stack you want in Pi, then save them:
58
+
59
+ ```text
60
+ /profile save reviewer
61
+ /profile preview reviewer
62
+ /profile use reviewer
63
+ ```
64
+
65
+ Profiles live in `.pi/forge/agent-profiles/*.json`. Applying one is a preflighted, one-shot operation: later manual model/thinking changes remain until you apply the profile again. Read [agent-profile concepts](concepts/agent-profiles.md) for validation, auto-activation, and drift semantics.
66
+
67
+ ## Storage and migration
68
+
69
+ | Location | Purpose |
70
+ |---|---|
71
+ | `.pi/forge/prompt-stacks/` | Project prompt stacks |
72
+ | `.pi/forge/agent-profiles/` | Project agent profiles |
73
+ | `.pi/forge/config.json` | Trusted project configuration and delegation authorization |
74
+ | `.pi/forge/extensions/` | Trusted project macro/slot registration code |
75
+ | `~/.pi/forge/config.json` | User defaults |
76
+ | `~/.pi/forge/extensions/` | Trusted user macro/slot registration code |
77
+
78
+ Legacy `.pi/prompt-stacks/*.json` files remain readable. New stacks go to `.pi/forge/prompt-stacks`, and same-named new-location files shadow legacy ones. Migrate safely with:
79
+
80
+ ```text
81
+ /preset migrate-stacks --dry-run
82
+ /preset migrate-stacks
83
+ ```
84
+
85
+ Add `--overwrite` only when target replacement is intended. Add `--delete-legacy` only after checking the copied files.
86
+
87
+ ## Where to go next
88
+
89
+ - Learn the [prompt-stack model](concepts/prompt-stacks.md).
90
+ - Fork a [focused reviewer](../examples/reviewer-prompt-stack.json) or [DM writer](../examples/sillytavern-dm-writer-prompt-stack.json).
91
+ - Use the [SillyTavern importer](guides/sillytavern-import.md).
92
+ - Learn [macros and slots](reference/macros-and-slots.md).
93
+ - Inspect the [complete commands](reference/commands.md) and [stack schema](reference/stack-schema.md).
@@ -0,0 +1,68 @@
1
+ # Custom macros and slots
2
+
3
+ [Documentation](../README.md)
4
+
5
+ Custom macros and slots are registered by trusted extension code, never embedded as executable code in prompt-stack JSON.
6
+
7
+ Put small project registrations in `.pi/forge/extensions/` and machine-wide personal registrations in `~/.pi/forge/extensions/`. Global modules load first, then project modules, after trust and before stack validation. Both locations reload with `/preset reload`.
8
+
9
+ ## Registration module
10
+
11
+ Modules receive the pi-forge API directly, so they do not need to import the package:
12
+
13
+ ```ts
14
+ // .pi/forge/extensions/ticket-context.ts
15
+ export default function register(api) {
16
+ api.registerMacro({
17
+ name: "ticketId",
18
+ description: "Current ticket id from session variables.",
19
+ render: (ctx) => ctx.variables.toMacroText(ctx.variables.get("ticket.id")),
20
+ });
21
+
22
+ api.registerSlot({
23
+ name: "ticket-context",
24
+ description: "Render ticket context for the current task.",
25
+ options: {
26
+ heading: { type: "string", default: "Ticket context" },
27
+ },
28
+ render: (ctx) => [
29
+ String(ctx.options.heading ?? "Ticket context") + ":",
30
+ "- Ticket: " + ctx.variables.toMacroText(ctx.variables.get("ticket.id")),
31
+ "- Project: " + ctx.helpers.normalizePath(ctx.runtime.options.cwd),
32
+ ].join("\n"),
33
+ });
34
+ }
35
+ ```
36
+
37
+ Use the slot declaratively:
38
+
39
+ ```json
40
+ {
41
+ "kind": "slot",
42
+ "id": "ticket-context",
43
+ "enabled": true,
44
+ "role": "system",
45
+ "slot": "ticket-context",
46
+ "options": { "heading": "Current ticket" }
47
+ }
48
+ ```
49
+
50
+ ## Module rules
51
+
52
+ - Supported files are `.ts`, `.js`, `.mjs`, `.cjs`, and `index.*` inside a subdirectory.
53
+ - TypeScript should use syntax Node can strip at runtime; otherwise use JavaScript or precompile it.
54
+ - Export `default function register(api)` or named `register(api)`.
55
+ - Names must be unique across built-ins, global extensions, and project extensions.
56
+ - Duplicate names and load failures appear in diagnostics.
57
+ - Missing custom slots are validation warnings until their module is loaded.
58
+ - Registration ownership is disposed when the runtime shuts down.
59
+
60
+ The API provides `cwd`, `forgeDir`, `extensionPath`, helpers, registration functions, and `getRegisteredMacros()` / `getRegisteredSlots()`. Global `forgeDir` is `~/.pi/forge`; project `forgeDir` is `<project>/.pi/forge`.
61
+
62
+ Reusable Pi packages may import `registerMacro` and `registerSlot` from `@zihanw/pi-forge`. The directory loaders are intended for small trusted customizations without package boilerplate.
63
+
64
+ ## Security
65
+
66
+ Registration modules execute with the Pi process's user permissions. Load them only from code you trust. Stack JSON remains declarative and cannot register executable behavior by itself.
67
+
68
+ For a copyable example, see [custom-system-status-extension](../../examples/custom-system-status-extension/README.md). For built-ins, see [macros and slots](../reference/macros-and-slots.md).
@@ -0,0 +1,39 @@
1
+ # Prompt and payload debugging
2
+
3
+ [Documentation](../README.md)
4
+
5
+ ## Validate and preview
6
+
7
+ ```text
8
+ /preset validate [id]
9
+ /preset preview [id]
10
+ /preset status
11
+ /preset diagnostics
12
+ ```
13
+
14
+ Validation checks schema shape, item IDs, slots, policy, regex rules, custom dependencies, and activation conflicts. Preview compiles without sending a provider request. Diagnostics includes runtime policy, regex activity, extension modules, and load failures.
15
+
16
+ The web editor provides the same validation plus a full visual preview and source-aware resources.
17
+
18
+ ## Inspect the next provider payload
19
+
20
+ ```text
21
+ /payload next
22
+ /payload next save=.pi/forge/payloads/last.json
23
+ ```
24
+
25
+ Or open `/preset ui`, click **Arm payload**, then send the next Pi prompt. Credential-shaped token fields are redacted; normal request limits and accounting fields such as `max_tokens`, `input_tokens`, and `output_tokens` remain visible.
26
+
27
+ `/intercept` is the compact command for showing the next provider payload.
28
+
29
+ Saved payloads can contain prompt and conversation content. Keep them out of version control unless deliberately sanitized.
30
+
31
+ ## Common checks
32
+
33
+ - Unexpected duplicate task: set the `chat-history` slot's `includeLastUserMessage` to `false` when a later block uses `{{lastUserMessage}}`.
34
+ - Missing tool: inspect stack `allow`/`deny` policy and `/preset status`; the tool-call guard enforces the selected stack even if another extension modifies active tools.
35
+ - Skill still visible: use `replace` mode when Pi's base prompt must not include its own skill listing.
36
+ - Missing custom slot: trust the project, check `.pi/forge/extensions`, reload, and inspect diagnostics.
37
+ - Changed profile source: `/profile status` distinguishes source-definition changes from manual runtime drift.
38
+ - Delegation unavailable: use `/forge-agent backends`, `/profile preview`, and `forge_subagent_profiles` metadata before provider execution.
39
+ - Provider authentication works in the parent but not the child: restart after updating Pi or pi-forge and confirm the installed extension/runtime versions are not stale.
@@ -0,0 +1,99 @@
1
+ # Experimental foreground delegation
2
+
3
+ [Documentation](../README.md) · [中文](../zh-CN/guides/delegation.md)
4
+
5
+ > **Experimental:** This API and its backends may change independently of stable prompt-stack and profile behavior.
6
+
7
+ pi-forge can execute an explicitly authorized agent profile as a separate, clean, one-shot Pi process. It runs in the foreground and returns a bounded report to the parent conversation.
8
+
9
+ ## Enable a profile
10
+
11
+ Profiles are not delegatable by default. Enable each eligible ID in the trusted project's `.pi/forge/config.json`, or use the profile's delegation card in `/preset ui`:
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
+ "rpc-reviewer": {
24
+ "enabled": true,
25
+ "backend": "pi-rpc-readonly",
26
+ "timeoutMs": 180000
27
+ }
28
+ }
29
+ }
30
+ }
31
+ ```
32
+
33
+ Enablement and per-profile overrides are project-only because profiles are project-local. A global `~/.pi/forge/config.json` may define general `backend` and `timeoutMs` defaults; global `profiles` entries warn and are ignored. Disabled or unlisted IDs are hidden from discovery and rejected even if guessed.
34
+
35
+ ## Discover, plan, and run
36
+
37
+ Humans use:
38
+
39
+ ```text
40
+ /forge-agent backends
41
+ /forge-agent plan reviewer Review this API design for correctness.
42
+ /forge-agent run reviewer Review this API design for correctness.
43
+ /forge-agent run reviewer --backend pi-rpc-readonly Review this API design.
44
+ ```
45
+
46
+ `plan` resolves the profile and stack, compiles and validates the exact immutable provider-bound plan, displays it, and discards it without provider transport.
47
+
48
+ The parent model uses `forge_subagent_profiles` to discover enabled profiles and `forge_subagent` to invoke one. A restrictive parent stack must allow both tool names. Discovery is local/no-egress and reports metadata, resolution readiness, effective backend/timeout, approval mode, and whether parent tool policy permits invocation.
49
+
50
+ ## Backends and precedence
51
+
52
+ Two fresh-process backends are registered:
53
+
54
+ - `pi-subprocess-readonly` is the default and uses `pi --mode text --print`.
55
+ - `pi-rpc-readonly` uses `pi --mode rpc`.
56
+
57
+ Both execute the same sealed prompt and shared-user read-only policy; only their process protocol differs. There is no fallback if the selected backend is unavailable.
58
+
59
+ Interactive backend precedence is: per-run override, project profile override, project default, user default, built-in default. Unattended model invocation is pinned to the effective configured backend and rejects a per-call override. Timeout follows profile, project, user, then the 60-second built-in default; valid values are 1,000–3,600,000 ms. Host timeout is best effort.
60
+
61
+ ## Approval and unattended invocation
62
+
63
+ By default, the exact plan is prepared before an approval screen shows the task, profile/stack, provider/model, thinking level, tools, working directory, boundary, payload size, and fingerprint. **View full prompt** reveals the complete provider-bound system prompt and ordered messages. Editing that view cannot alter the sealed plan.
64
+
65
+ To authorize the parent model without per-run approval:
66
+
67
+ ```json
68
+ {
69
+ "subagents": {
70
+ "allowAgentInvocationWithoutApproval": true
71
+ }
72
+ }
73
+ ```
74
+
75
+ This affects only `forge_subagent`; `/forge-agent run` remains interactive. It is ignored in untrusted projects and malformed values fail closed. Treat this project config as an authorization file: do not enable or commit it unless every parent agent allowed to call `forge_subagent` may send the compiled prompt and readable file contents to the selected provider without asking again.
76
+
77
+ ## Child context and output
78
+
79
+ The child receives a clean conversation, the exact profile model/thinking/stack, and the delegated task as a protected final user message. It does not automatically receive parent history.
80
+
81
+ Candidate tools are `read`, `grep`, `find`, and `ls`, further restricted by stack tool policy. The child loads no write/edit/shell tools, skills, prompt templates, project context files, or third-party extensions.
82
+
83
+ The model-visible result is bounded. Expandable human details retain normalized status, a text transcript, tool events, diagnostics, usage, approval receipt, and execution report. Retained strings are bounded, base64-like text is redacted, and the transcript keeps a 512 KiB rolling tail. Inline image bytes are replaced by MIME/encoded-size metadata before retention in the parent session.
84
+
85
+ ## Security boundary
86
+
87
+ The current backends are **shared-user, not operating-system sandboxes**.
88
+
89
+ - “Read-only” is a model-tool policy. The process retains the invoking user's OS permissions.
90
+ - Absolute paths readable by that user may be read and sent to the selected provider.
91
+ - Text may be retained in parent tool-result details and Pi's on-disk session JSONL.
92
+ - Timeout and cancellation are best effort.
93
+ - `/tree` changes the active conversation branch; abandoned entries can remain on disk.
94
+ - `/tree` cannot undo provider requests, billing, or external effects.
95
+ - Removing sensitive retained text requires deleting the relevant Pi session data.
96
+
97
+ The default tools intentionally provide no mutation path. Do not add write, edit, or shell access to this shared-user design. OS isolation and separately approved staged writes remain future work.
98
+
99
+ For integration authors, see the [experimental adapter contract](../reference/subagent-adapter.md).
@@ -0,0 +1,47 @@
1
+ # Importing SillyTavern presets
2
+
3
+ [Documentation](../README.md)
4
+
5
+ Import through the command line:
6
+
7
+ ```text
8
+ /preset import-silly ~/SillyTavern/presets/my-preset.json
9
+ ```
10
+
11
+ Use `--dry-run` to preview, `--overwrite` to replace protected output, and an optional `character_id` when the preset contains multiple prompt orders. The web editor also accepts SillyTavern JSON and asks which character order to use when necessary.
12
+
13
+ Generated stacks go to `.pi/forge/prompt-stacks/<id>.json`; reports go to `.pi/forge/import-reports/<id>.md`. Always read the report before activating the stack.
14
+
15
+ ## Converted behavior
16
+
17
+ The importer:
18
+
19
+ - converts prompt order into ordered stack items;
20
+ - maps the chat-history marker to a movable `chat-history` slot;
21
+ - detects `{{lastUserMessage}}` and avoids duplicating the latest user turn;
22
+ - carries relevant identifiers in `source.sillytavern` metadata;
23
+ - maps deterministic `promptOnly` regex scripts to history-stage outgoing rules when their behavior is representable;
24
+ - converts full-match replacement syntax and preserves trim strings, depth limits, and supported user/assistant placement.
25
+
26
+ ## Report-only behavior
27
+
28
+ The following require manual review and are not executed:
29
+
30
+ - display-only or mixed prompt/display scripts;
31
+ - DOM, browser, CSS, HTML-decoration, or JavaScript behavior;
32
+ - unsupported placements or invalid regular expressions;
33
+ - markers with no pi-forge equivalent;
34
+ - SillyTavern features whose ordering or lifecycle cannot be represented safely.
35
+
36
+ pi-forge does not embed arbitrary executable preset code. Unsupported content stays visible in the migration report instead of being silently approximated.
37
+
38
+ ## Recommended workflow
39
+
40
+ 1. Run a dry import.
41
+ 2. Read every warning and omission in the report.
42
+ 3. Open the generated stack in `/preset ui`.
43
+ 4. Validate it and inspect the full preview.
44
+ 5. Compare the history placement and regex rules with the original preset.
45
+ 6. Activate it only after the preview matches your intent.
46
+
47
+ See [stack schema](../reference/stack-schema.md#regex-transforms) for the supported regex runtime.
@@ -0,0 +1,65 @@
1
+ # Prompt-stack patterns and examples
2
+
3
+ [Documentation](../README.md)
4
+
5
+ Use these as starting patterns rather than rigid templates. The [default Pi mirror](../../examples/default-prompt-stack.json) is the safest baseline to fork.
6
+
7
+ ## Roleplay and creative writing
8
+
9
+ Put long-lived character rules in a system block, runtime context in appropriate slots, and the current user action in an explicit final user block:
10
+
11
+ 1. System character/personality block.
12
+ 2. Tools, project context, variables, and other runtime slots.
13
+ 3. `chat-history` with `includeLastUserMessage: false`.
14
+ 4. Final user block containing `{{lastUserMessage}}`.
15
+
16
+ This keeps the latest request clear and avoids duplication. Static `{{char}}` / `{{user}}` variables work well for character constants; turn/session macros can track temporary scene state. Durable project memory belongs in project files, not prompt variables.
17
+
18
+ ## Focused code review
19
+
20
+ Start from [the reviewer example](../../examples/reviewer-prompt-stack.json). It denies writing tools, wraps prior history as background, omits the latest user message from history, then reinserts it as the explicit review target.
21
+
22
+ Use a rule such as “prioritize correctness, regressions, security, and missing tests.” Keep tools, project context, variables, and history when the reviewer must inspect the repository. Use `append` to retain Pi's normal coding prompt, or `replace` when the stack must fully control prompt and skill visibility.
23
+
24
+ ## Translation mode
25
+
26
+ Create a small stack with a system block for target language, register/tone, and terminology rules. Retain history and a final `{{lastUserMessage}}`. Separate literal translation, localization review, and bilingual editing into different stacks when their rules conflict.
27
+
28
+ ## Multi-mode switching
29
+
30
+ Keep independent project files:
31
+
32
+ ```text
33
+ .pi/forge/prompt-stacks/
34
+ coder.json
35
+ writer.json
36
+ translator.json
37
+ ```
38
+
39
+ Switch with `/preset use coder`, `/preset use writer`, or `/preset use translator`. Capture a profile when a mode also needs a specific model and thinking level.
40
+
41
+ ## Read-only scout
42
+
43
+ Allow only `read`, `grep`, `find`, and `ls`, omit editing tools, and cap chat history with `maxChars`. This is useful for exploration turns where the model should report findings without changing files.
44
+
45
+ Tool policy constrains model tool calls but is not an operating-system sandbox. A normal Pi agent may still have other non-tool ways to interact with its host; do not describe a prompt stack alone as process isolation.
46
+
47
+ ## Surgical patcher
48
+
49
+ Keep the Pi mirror, require the tools needed for the workflow, strip prior assistant thinking from inserted history, and move project context near the current user turn. This reduces distracting prompt material without removing relevant repository instructions.
50
+
51
+ ## SillyTavern DM writer
52
+
53
+ [The DM-writer example](../../examples/sillytavern-dm-writer-prompt-stack.json) defines a Dungeon Master through `{{char}}` / `{{user}}`, wraps prior adventure history, reinserts the current action, and uses deterministic regex cleanup for OOC notes, secret-roll markers, dice notation, and `Player:` prefixes.
54
+
55
+ ## Payload lab
56
+
57
+ Include `active-model`, `date-cwd`, and `variables`, then add compiled regex rules for deterministic redaction or formatting. Pair the stack with `/payload next` or the web editor's capture view to audit exactly what changed.
58
+
59
+ ## Pi-docs expert
60
+
61
+ Allow read/search tools, include the `pi-docs` and project-context slots, and keep a focused system instruction. This encourages answers grounded in installed Pi documentation rather than general model memory.
62
+
63
+ ## Trusted runtime status
64
+
65
+ The [custom system-status example](../../examples/custom-system-status-extension/README.md) registers `{{cpuLoad}}` and a `machine-status` slot from trusted project code. Use this pattern for deterministic host data that cannot be represented as static stack JSON.
@@ -0,0 +1,75 @@
1
+ # Web editor
2
+
3
+ [Documentation](../README.md)
4
+
5
+ Open the browser editor from a trusted Pi project:
6
+
7
+ ```text
8
+ /preset ui
9
+ ```
10
+
11
+ Use `/preset ui restart` to replace its server or `/preset ui stop` to close it.
12
+
13
+ ## Connection and trust
14
+
15
+ The editor binds to an available `127.0.0.1` port and uses a session token. Multiple Pi projects can run editors simultaneously. Lifecycle reinitialization reuses the existing editor URL for the same project when possible.
16
+
17
+ Reads, preview, resources, and payload inspection remain available as appropriate, but writes require Pi to trust the project. Files are constrained to pi-forge's stack/profile storage. Never expose or proxy the editor URL to an untrusted network.
18
+
19
+ Choose a preferred port in `.pi/forge/config.json`:
20
+
21
+ ```json
22
+ {
23
+ "webEditor": {
24
+ "port": 41738
25
+ }
26
+ }
27
+ ```
28
+
29
+ If that port is unavailable, pi-forge selects another and shows the actual URL.
30
+
31
+ ## Prompt-stack workspace
32
+
33
+ The stack workspace provides:
34
+
35
+ - creation from the default Pi-mirror layout;
36
+ - structured metadata, item, policy, variables, context, and regex editing;
37
+ - drag-and-drop item order and enable/disable controls;
38
+ - validation and a full compiled preview;
39
+ - registered-tool and loaded-skill search with exact-name chips and wildcard patterns;
40
+ - raw JSON recovery for advanced or unknown fields;
41
+ - native pi-forge and SillyTavern JSON import;
42
+ - export, fork, and deletion;
43
+ - payload arming and redacted captured-payload inspection;
44
+ - light and dark themes.
45
+
46
+ Existing IDs are immutable during edit. Use **Fork** to create a different ID without breaking profile references or the active selection. New stacks, imports, and forks write to `.pi/forge/prompt-stacks`; legacy stacks remain editable in place.
47
+
48
+ Saves, imports, forks, and deletes reload stack state into the current Pi session. When another surface changes a referenced stack, returning to profiles refreshes profile resolution without discarding unsaved delegation fields.
49
+
50
+ ## Agent-profile workspace
51
+
52
+ The profile list shows each profile's ID, display metadata, model, thinking level, stack, resolution state, auto-activation, last-applied provenance, and delegation status.
53
+
54
+ Trusted projects can create, edit, validate, save, apply once, and delete profiles. Model choices come from Pi's model registry, thinking choices reflect model support, and stack choices come from the shared repository. The editor rejects a second auto-activation profile.
55
+
56
+ The runtime/provenance card separates current runtime state, last-applied snapshot, source-definition changes, and field-level runtime drift.
57
+
58
+ ## Delegation card
59
+
60
+ The profile delegation card edits only project-level `subagents.profiles.<id>` values: enablement, backend override, and timeout override. General defaults and `allowAgentInvocationWithoutApproval` remain config-file-only because they affect broader authorization.
61
+
62
+ Unsaved delegation changes are guarded when selecting another profile, starting another profile operation, refreshing, deleting, or leaving/reloading the page. The card shows effective values and the source of each inherited or overridden setting.
63
+
64
+ Read [foreground delegation](delegation.md) before enabling a profile.
65
+
66
+ ## Migration
67
+
68
+ To copy legacy `.pi/prompt-stacks` into `.pi/forge/prompt-stacks`:
69
+
70
+ ```text
71
+ /preset migrate-stacks --dry-run
72
+ /preset migrate-stacks
73
+ ```
74
+
75
+ Review before adding `--overwrite` or `--delete-legacy`.
@@ -0,0 +1,60 @@
1
+ # Command reference
2
+
3
+ [Documentation](../README.md) · [中文](../zh-CN/reference/commands.md)
4
+
5
+ Arguments in brackets are optional. Commands that write project files require a trusted project.
6
+
7
+ ## Prompt stacks
8
+
9
+ | Command | Behavior |
10
+ |---|---|
11
+ | `/preset list` | List stacks and activation/validation state. |
12
+ | `/preset status` | Show the selected stack and diagnostics summary. |
13
+ | `/preset use <id>` | Validate and select a stack. |
14
+ | `/preset use none` | Disable prompt stacks for this session branch. `off` is accepted as an alias. |
15
+ | `/preset preview [id]` | Compile and display a stack without provider transport. Defaults to the selected stack. |
16
+ | `/preset validate [id]` | Validate one stack or all stacks when omitted. |
17
+ | `/preset diagnostics` | Show loader, runtime, policy, regex, and trusted-extension diagnostics. |
18
+ | `/preset reload` | Reload stacks and trusted macro/slot registrations. |
19
+ | `/preset ui [stop\|restart]` | Open, stop, or replace the local web editor. |
20
+
21
+ ## Storage migration and import
22
+
23
+ | Command | Behavior |
24
+ |---|---|
25
+ | `/preset migrate-stacks [--dry-run] [--overwrite] [--delete-legacy]` | Copy legacy `.pi/prompt-stacks` files into `.pi/forge/prompt-stacks`. |
26
+ | `/preset import-silly <path> [character_id] [--dry-run] [--overwrite]` | Convert a SillyTavern preset and write a migration report. |
27
+
28
+ Use migration/import dry runs before overwriting or deleting anything. See [SillyTavern import](../guides/sillytavern-import.md).
29
+
30
+ ## Agent profiles
31
+
32
+ | Command | Behavior |
33
+ |---|---|
34
+ | `/profile list` | List project profiles and resolution diagnostics. |
35
+ | `/profile use <id>` | Preflight and apply a profile once. |
36
+ | `/profile save <id> [--overwrite]` | Capture the current model, thinking level, and stack. |
37
+ | `/profile status` | Compare current runtime with last-applied branch provenance. |
38
+ | `/profile preview <id>` | Resolve model/auth/thinking/stack/tools without applying. |
39
+ | `/profile validate [id]` | Validate one profile or all profiles when omitted. |
40
+ | `/profile reload` | Reload definitions without applying them. |
41
+ | `/profile forget` | Remove last-applied provenance without changing runtime state. |
42
+
43
+ ## Experimental foreground delegation
44
+
45
+ | Command | Behavior |
46
+ |---|---|
47
+ | `/forge-agent backends` | List registered experimental backends, capabilities, and effective defaults. |
48
+ | `/forge-agent plan <profile> [--backend <id>] <task>` | Prepare, validate, display, and discard an exact plan without provider transport. |
49
+ | `/forge-agent run <profile> [--backend <id>] <task>` | Review and approve an exact foreground read-only run. |
50
+
51
+ Only project-authorized delegation profiles are accepted. The model-callable equivalents are `forge_subagent_profiles` (local discovery) and `forge_subagent` (execution). See the [delegation safety guide](../guides/delegation.md).
52
+
53
+ ## Payload inspection
54
+
55
+ | Command | Behavior |
56
+ |---|---|
57
+ | `/intercept` | Display the next redacted provider payload. |
58
+ | `/payload next [save=<path>]` | Display the next payload, optionally save it, and expose it to the web editor. |
59
+
60
+ Saved payloads may include prompt and conversation text even though credential-shaped fields are redacted. Handle them as potentially sensitive.
@@ -0,0 +1,64 @@
1
+ # Configuration reference
2
+
3
+ [Documentation](../README.md)
4
+
5
+ Project configuration lives in `.pi/forge/config.json` and is loaded only for a trusted project. User defaults live in `~/.pi/forge/config.json`.
6
+
7
+ ## Web editor
8
+
9
+ ```json
10
+ {
11
+ "webEditor": {
12
+ "port": 41738
13
+ }
14
+ }
15
+ ```
16
+
17
+ The port is preferred, not guaranteed. The editor binds only to `127.0.0.1` and chooses another available port when necessary.
18
+
19
+ ## Experimental subagents
20
+
21
+ User configuration may set general defaults:
22
+
23
+ ```json
24
+ {
25
+ "subagents": {
26
+ "backend": "pi-subprocess-readonly",
27
+ "timeoutMs": 60000
28
+ }
29
+ }
30
+ ```
31
+
32
+ Trusted project configuration may override defaults, authorize individual project profile IDs, and authorize unattended model invocation:
33
+
34
+ ```json
35
+ {
36
+ "subagents": {
37
+ "backend": "pi-subprocess-readonly",
38
+ "timeoutMs": 60000,
39
+ "allowAgentInvocationWithoutApproval": false,
40
+ "profiles": {
41
+ "reviewer": {
42
+ "enabled": true,
43
+ "backend": "pi-rpc-readonly",
44
+ "timeoutMs": 180000
45
+ }
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ Valid timeouts are 1,000–3,600,000 ms. Invalid fields warn and fall back to the preceding applicable default. General backend precedence is project then user then built-in; an interactive run and a project profile entry can further override it as described in [delegation](../guides/delegation.md#backends-and-precedence).
52
+
53
+ `profiles` in global configuration warns and is ignored. `allowAgentInvocationWithoutApproval` is project-only, requires trust, and fails closed when malformed. Deleting a profile also clears its effective delegation policy.
54
+
55
+ Treat project configuration as an authorization boundary. In particular, do not commit unattended delegation unless every permitted parent agent may transmit compiled prompt and readable project content without another human approval.
56
+
57
+ ## Trusted registration directories
58
+
59
+ These are code-loading locations rather than JSON fields:
60
+
61
+ - `~/.pi/forge/extensions/` loads trusted user macro/slot registrations.
62
+ - `.pi/forge/extensions/` loads trusted project registrations after project trust.
63
+
64
+ See [custom macros and slots](../guides/custom-macros-and-slots.md).