@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.
- package/CHANGELOG.md +45 -1
- package/PUBLIC_API.md +3 -26
- package/README.md +90 -601
- package/README.zh-CN.md +86 -585
- package/SUBAGENT_ADAPTER_CONTRACT.md +3 -197
- package/dist/agent-profile.d.ts +24 -1
- package/dist/agent-profile.d.ts.map +1 -1
- package/dist/agent-profile.js +146 -36
- package/dist/agent-profile.js.map +1 -1
- package/dist/catalog.d.ts +27 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +59 -0
- package/dist/catalog.js.map +1 -0
- package/dist/forge-config.d.ts +106 -0
- package/dist/forge-config.d.ts.map +1 -1
- package/dist/forge-config.js +305 -18
- package/dist/forge-config.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -8
- package/dist/index.js.map +1 -1
- package/dist/lifecycle.d.ts +2 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +7 -4
- package/dist/lifecycle.js.map +1 -1
- package/dist/loader.d.ts +17 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +84 -25
- package/dist/loader.js.map +1 -1
- package/dist/preset-command.d.ts +1 -1
- package/dist/preset-command.d.ts.map +1 -1
- package/dist/preset-command.js +38 -10
- package/dist/preset-command.js.map +1 -1
- package/dist/profile-command.d.ts.map +1 -1
- package/dist/profile-command.js +46 -21
- package/dist/profile-command.js.map +1 -1
- package/dist/profile-service.d.ts +6 -3
- package/dist/profile-service.d.ts.map +1 -1
- package/dist/profile-service.js +55 -13
- package/dist/profile-service.js.map +1 -1
- package/dist/resource-identity.d.ts +33 -0
- package/dist/resource-identity.d.ts.map +1 -0
- package/dist/resource-identity.js +56 -0
- package/dist/resource-identity.js.map +1 -0
- package/dist/runtime/profile-runtime.d.ts.map +1 -1
- package/dist/runtime/profile-runtime.js +7 -2
- package/dist/runtime/profile-runtime.js.map +1 -1
- package/dist/runtime/prompt-stack-runtime.d.ts +1 -1
- package/dist/runtime/prompt-stack-runtime.d.ts.map +1 -1
- package/dist/runtime/prompt-stack-runtime.js +22 -12
- package/dist/runtime/prompt-stack-runtime.js.map +1 -1
- package/dist/runtime/subagent-runtime.d.ts +23 -8
- package/dist/runtime/subagent-runtime.d.ts.map +1 -1
- package/dist/runtime/subagent-runtime.js +296 -67
- package/dist/runtime/subagent-runtime.js.map +1 -1
- package/dist/storage.d.ts +11 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +51 -2
- package/dist/storage.js.map +1 -1
- package/dist/subagent/canonical.d.ts +19 -7
- package/dist/subagent/canonical.d.ts.map +1 -1
- package/dist/subagent/canonical.js +19 -47
- package/dist/subagent/canonical.js.map +1 -1
- package/dist/subagent/contract.d.ts +1 -2
- package/dist/subagent/contract.d.ts.map +1 -1
- package/dist/subagent/contract.js +1 -2
- package/dist/subagent/contract.js.map +1 -1
- package/dist/subagent/index.d.ts +4 -3
- package/dist/subagent/index.d.ts.map +1 -1
- package/dist/subagent/index.js +4 -3
- package/dist/subagent/index.js.map +1 -1
- package/dist/subagent/plan.d.ts +5 -1
- package/dist/subagent/plan.d.ts.map +1 -1
- package/dist/subagent/plan.js +29 -32
- package/dist/subagent/plan.js.map +1 -1
- package/dist/subagent/request.d.ts.map +1 -1
- package/dist/subagent/request.js +36 -4
- package/dist/subagent/request.js.map +1 -1
- package/dist/subagent/types.d.ts +66 -178
- package/dist/subagent/types.d.ts.map +1 -1
- package/dist/subagent/types.js +1 -1
- package/dist/subagent/types.js.map +1 -1
- package/dist/subagent/validation.d.ts +14 -14
- package/dist/subagent/validation.d.ts.map +1 -1
- package/dist/subagent/validation.js +52 -238
- package/dist/subagent/validation.js.map +1 -1
- package/dist/subagent-command.d.ts +2 -1
- package/dist/subagent-command.d.ts.map +1 -1
- package/dist/subagent-command.js +115 -19
- package/dist/subagent-command.js.map +1 -1
- package/dist/subagent-host.d.ts.map +1 -1
- package/dist/subagent-host.js +43 -16
- package/dist/subagent-host.js.map +1 -1
- package/dist/subagent-profile-tool.d.ts +25 -2
- package/dist/subagent-profile-tool.d.ts.map +1 -1
- package/dist/subagent-profile-tool.js +41 -9
- package/dist/subagent-profile-tool.js.map +1 -1
- package/dist/subagent-tool.d.ts +31 -4
- package/dist/subagent-tool.d.ts.map +1 -1
- package/dist/subagent-tool.js +311 -137
- package/dist/subagent-tool.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/web-editor/client-script.generated.d.ts +1 -1
- package/dist/web-editor/client-script.generated.d.ts.map +1 -1
- package/dist/web-editor/client-script.generated.js +1 -1
- package/dist/web-editor/client-script.generated.js.map +1 -1
- package/dist/web-editor/client-styles.d.ts +2 -0
- package/dist/web-editor/client-styles.d.ts.map +1 -0
- package/dist/web-editor/client-styles.generated.d.ts +2 -0
- package/dist/web-editor/client-styles.generated.d.ts.map +1 -0
- package/dist/web-editor/client-styles.generated.js +3 -0
- package/dist/web-editor/client-styles.generated.js.map +1 -0
- package/dist/web-editor/client-styles.js +2 -0
- package/dist/web-editor/client-styles.js.map +1 -0
- package/dist/web-editor/page.d.ts +2 -0
- package/dist/web-editor/page.d.ts.map +1 -1
- package/dist/web-editor/page.js +11 -73
- package/dist/web-editor/page.js.map +1 -1
- package/dist/web-editor/server.d.ts.map +1 -1
- package/dist/web-editor/server.js +176 -1
- package/dist/web-editor/server.js.map +1 -1
- package/dist/web-editor/styles.d.ts.map +1 -1
- package/dist/web-editor/styles.js +60 -3
- package/dist/web-editor/styles.js.map +1 -1
- package/dist/web-editor/types.d.ts +87 -0
- package/dist/web-editor/types.d.ts.map +1 -1
- package/dist/web-host.d.ts +13 -2
- package/dist/web-host.d.ts.map +1 -1
- package/dist/web-host.js +371 -27
- package/dist/web-host.js.map +1 -1
- package/docs/README.md +41 -0
- package/docs/concepts/agent-profiles.md +60 -0
- package/docs/concepts/prompt-stacks.md +95 -0
- package/docs/design/README.md +17 -0
- package/docs/design/roadmap-0.4-archive.md +216 -0
- package/docs/design/subagents/design-review.md +220 -0
- package/docs/design/subagents/interface-design.md +274 -0
- package/docs/design/subagents/sdk-spike-findings.md +117 -0
- package/docs/development/complexity-review.md +86 -0
- package/docs/development/release.md +31 -0
- package/docs/development/roadmap.md +36 -0
- package/docs/development/scoped-global-profiles-stacks.md +325 -0
- package/docs/development/setup.md +75 -0
- package/docs/getting-started.md +95 -0
- package/docs/guides/custom-macros-and-slots.md +68 -0
- package/docs/guides/debugging.md +39 -0
- package/docs/guides/delegation.md +107 -0
- package/docs/guides/sillytavern-import.md +47 -0
- package/docs/guides/use-cases.md +65 -0
- package/docs/guides/web-editor.md +75 -0
- package/docs/reference/commands.md +60 -0
- package/docs/reference/configuration.md +66 -0
- package/docs/reference/features.md +280 -0
- package/docs/reference/macros-and-slots.md +82 -0
- package/docs/reference/public-api.md +28 -0
- package/docs/reference/stack-schema.md +167 -0
- package/docs/reference/subagent-adapter.md +204 -0
- package/docs/zh-CN/README.md +37 -0
- package/docs/zh-CN/concepts/agent-profiles.md +46 -0
- package/docs/zh-CN/concepts/prompt-stacks.md +42 -0
- package/docs/zh-CN/getting-started.md +81 -0
- package/docs/zh-CN/guides/delegation.md +66 -0
- package/docs/zh-CN/guides/web-editor.md +45 -0
- package/docs/zh-CN/reference/commands.md +60 -0
- package/package.json +29 -15
- package/dist/subagent/backend-registry.d.ts +0 -75
- package/dist/subagent/backend-registry.d.ts.map +0 -1
- package/dist/subagent/backend-registry.js +0 -463
- package/dist/subagent/backend-registry.js.map +0 -1
- package/dist/subagent/diagnostics.d.ts +0 -3
- package/dist/subagent/diagnostics.d.ts.map +0 -1
- package/dist/subagent/diagnostics.js +0 -5
- package/dist/subagent/diagnostics.js.map +0 -1
- package/dist/subagent/pi-model-runtime.d.ts +0 -8
- package/dist/subagent/pi-model-runtime.d.ts.map +0 -1
- package/dist/subagent/pi-model-runtime.js +0 -22
- package/dist/subagent/pi-model-runtime.js.map +0 -1
- package/dist/subagent/pi-sdk-backend.d.ts +0 -23
- package/dist/subagent/pi-sdk-backend.d.ts.map +0 -1
- package/dist/subagent/pi-sdk-backend.js +0 -383
- package/dist/subagent/pi-sdk-backend.js.map +0 -1
- package/dist/subagent/pi-subprocess-backend.d.ts +0 -72
- package/dist/subagent/pi-subprocess-backend.d.ts.map +0 -1
- package/dist/subagent/pi-subprocess-backend.js +0 -756
- package/dist/subagent/pi-subprocess-backend.js.map +0 -1
- package/dist/subagent/subprocess-bridge.d.ts +0 -21
- package/dist/subagent/subprocess-bridge.d.ts.map +0 -1
- package/dist/subagent/subprocess-bridge.js +0 -87
- package/dist/subagent/subprocess-bridge.js.map +0 -1
- package/dist/subagent/subprocess-report.d.ts +0 -4
- package/dist/subagent/subprocess-report.d.ts.map +0 -1
- package/dist/subagent/subprocess-report.js +0 -55
- package/dist/subagent/subprocess-report.js.map +0 -1
- package/dist/subagent-contract.d.ts +0 -8
- package/dist/subagent-contract.d.ts.map +0 -1
- package/dist/subagent-contract.js +0 -8
- package/dist/subagent-contract.js.map +0 -1
- package/dist/web-editor/client/api.d.ts +0 -9
- package/dist/web-editor/client/api.d.ts.map +0 -1
- package/dist/web-editor/client/api.js +0 -26
- package/dist/web-editor/client/api.js.map +0 -1
- package/dist/web-editor/client/dom.d.ts +0 -13
- package/dist/web-editor/client/dom.d.ts.map +0 -1
- package/dist/web-editor/client/dom.js +0 -30
- package/dist/web-editor/client/dom.js.map +0 -1
- package/dist/web-editor/client/inspector.d.ts +0 -22
- package/dist/web-editor/client/inspector.d.ts.map +0 -1
- package/dist/web-editor/client/inspector.js +0 -226
- package/dist/web-editor/client/inspector.js.map +0 -1
- package/dist/web-editor/client/main.d.ts +0 -2
- package/dist/web-editor/client/main.d.ts.map +0 -1
- package/dist/web-editor/client/main.js +0 -1468
- package/dist/web-editor/client/main.js.map +0 -1
- package/dist/web-editor/client/policy-editor.d.ts +0 -16
- package/dist/web-editor/client/policy-editor.d.ts.map +0 -1
- package/dist/web-editor/client/policy-editor.js +0 -330
- package/dist/web-editor/client/policy-editor.js.map +0 -1
- package/dist/web-editor/client/regex-editor.d.ts +0 -19
- package/dist/web-editor/client/regex-editor.d.ts.map +0 -1
- package/dist/web-editor/client/regex-editor.js +0 -281
- package/dist/web-editor/client/regex-editor.js.map +0 -1
- package/dist/web-editor/client/types.d.ts +0 -60
- package/dist/web-editor/client/types.d.ts.map +0 -1
- package/dist/web-editor/client/types.js +0 -2
- package/dist/web-editor/client/types.js.map +0 -1
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# Implemented feature inventory
|
|
2
|
+
|
|
3
|
+
This file tracks the currently implemented feature surface for agent profiles, the prompt-stack runtime, template variables, web editor, SillyTavern importer, storage migration, payload inspector, and regex MVP.
|
|
4
|
+
|
|
5
|
+
## Package and Runtime
|
|
6
|
+
|
|
7
|
+
- Pi package manifest with compiled `dist/index.js` exposed through `package.json` `pi.extensions`.
|
|
8
|
+
- Public npm package configuration for `@zihanw/pi-forge`.
|
|
9
|
+
- Compiled npm runtime containing JavaScript, declarations, documentation, and examples without physical `src/` files; repository source remains available for clone-based development.
|
|
10
|
+
- Tarball verification rejects physical `src/` entries and requires the root and subagent compiled entry points.
|
|
11
|
+
- The web editor's HTML page shell and static styles are maintained separately from its browser behavior modules.
|
|
12
|
+
- Strict typed web-editor client modules bundled into one self-contained browser script at build time, with generated-client consistency verification.
|
|
13
|
+
- Supported Node.js baseline is 22.19+. Published Pi SDK dependencies are host-provided wildcard peers; exact repository versions are reproducible development/test fixtures rather than runtime constraints.
|
|
14
|
+
- Project trust check before loading prompt stacks.
|
|
15
|
+
- Footer status showing the active prompt stack.
|
|
16
|
+
|
|
17
|
+
## Agent Profiles
|
|
18
|
+
|
|
19
|
+
- Strict schema-versioned project profiles from `.pi/forge/agent-profiles/*.json`.
|
|
20
|
+
- Profile v1 stores an exact provider/model reference, thinking level, and prompt-stack ID or `null`, with optional name, description, and fresh-session auto-activation metadata.
|
|
21
|
+
- Unsupported fields are errors so unimplemented generation, tool, skill, or runner settings cannot become inert configuration.
|
|
22
|
+
- Tool policy and model-visible skill filtering remain owned by the referenced prompt stack rather than duplicated in profiles.
|
|
23
|
+
- Pure profile resolution checks model existence, configured authentication, thinking-level clamping, prompt-stack validity, and unmatched tool allow patterns before application.
|
|
24
|
+
- `/profile use <id>` applies model, thinking level, and prompt stack once after complete preflight; later manual runtime changes are preserved.
|
|
25
|
+
- At most one profile may set `autoActivate: true`; it applies once for a fresh session and takes precedence over standalone prompt-stack autoload, while restored branch state takes precedence over both.
|
|
26
|
+
- Invalid or ambiguous profile auto-activation fails closed without applying a fallback stack or a partial profile. With no auto-activation profile, existing prompt-stack autoload remains the compatibility fallback.
|
|
27
|
+
- Failed application performs best-effort rollback and never records successful provenance.
|
|
28
|
+
- `/profile save <id> [--overwrite]` captures current runtime fields without tools, secrets, history, or provenance, preserving existing name/description metadata.
|
|
29
|
+
- `/profile preview <id>` reports resolved changes, prompt-stack tool policy, effective tools, and diagnostics without mutation.
|
|
30
|
+
- `/profile status` compares the current runtime with the last-applied resolved snapshot and reports source-definition changes separately.
|
|
31
|
+
- Last-applied provenance is branch-scoped session metadata used only for drift reporting; reload, resume, tree navigation, and compaction never reapply a profile.
|
|
32
|
+
- `/profile reload` reloads definitions without applying them, and `/profile forget` clears provenance without changing runtime state.
|
|
33
|
+
- Project trust gates profile loading, application, and writes.
|
|
34
|
+
- Shared typed profile services own capture, protected write/update/delete, application/rollback, immutable preview data, provenance changes, and runtime-drift calculation so command, web-editor, and adapter consumers do not duplicate behavior.
|
|
35
|
+
|
|
36
|
+
## Subagent Adapter Contract
|
|
37
|
+
|
|
38
|
+
- Dedicated experimental `@zihanw/pi-forge/subagent` entry point, with the existing package-root exports retained for 0.4 compatibility.
|
|
39
|
+
- Subagent types, canonicalization, request/preflight validation, tool negotiation, context preparation, plan construction, response validation, and diagnostics live in focused modules behind a compatibility contract barrel.
|
|
40
|
+
- Exported pure v1 `AgentRequest`, profile snapshot, backend preflight, execution-plan, enforcement-receipt, and discriminated response types without registering or shipping a runner.
|
|
41
|
+
- Backend-independent host profile resolution produces path-free declarative snapshots and does not consult the parent model registry or authentication state.
|
|
42
|
+
- Host dependency scanning detects custom macro and slot references, records registration source identities, and fails resolution when required registrations are missing.
|
|
43
|
+
- Backend tool negotiation intersects prompt-stack name policy with declared filesystem/process/network effects and per-request access.
|
|
44
|
+
- Optional empty-by-default backend registry validates registration and preflight identity, requires the backend to supply a complete fingerprinted prompt runtime, binds the exact host preparation to execution, routes dry-plan discard, rejects unbound or refingerprinted substitute plans, arbitrates cancellation and host timeouts, normalizes failures, and protects opaque trace routing behind authorization-scoped handles.
|
|
45
|
+
- Experimental `pi-subprocess-readonly` backend reuses the host Pi runtime for authenticated preparation, then runs a clean foreground Pi subprocess with the exact profile model, thinking level, and compiled prompt. Its candidate model tools are limited to `read`, `grep`, `find`, and `ls`, further filtered by prompt-stack policy; it loads no write/shell tools, skills, prompt templates, context files, or third-party extensions. Host-coupled capability mismatches fail closed during preflight.
|
|
46
|
+
- Delegation is an explicit per-profile opt-in under the trusted project's `subagents.profiles`; ordinary profile loading/application remains independent. Global profile entries warn and are ignored so project-local profile IDs cannot silently authorize unrelated projects. Disabled and unlisted profiles are omitted from `forge_subagent_profiles` and rejected before preparation by the command, model-callable tool, and concrete runtime.
|
|
47
|
+
- The no-egress `forge_subagent_profiles` tool gives the main agent a live catalog of enabled profile IDs, names, descriptions, model/thinking/stack metadata, effective backend/timeout and sources, and ready/unavailable resolution status. It also reports whether the parent tool policy currently permits `forge_subagent`.
|
|
48
|
+
- `subagents.summaryInToolDescription` (default `false`) embeds a compact, bounded summary of enabled profiles directly in the `forge_subagent` tool description, so the main agent can pick a frequently used profile without a discovery call. Ready profiles sort first, unavailable enabled profiles include their first resolution error, and the summary is capped at 8 profiles and 1,000 characters. It refreshes whenever profiles, stacks, or configuration change and keeps `forge_subagent_profiles` as the authoritative full-detail surface.
|
|
49
|
+
- The model-callable `forge_subagent` tool and `/forge-agent run` prepare an immutable plan before provider transport. `/forge-agent run` and the default tool path require explicit human approval; a trusted-project `subagents.allowAgentInvocationWithoutApproval` option may authorize only the model-callable tool without a per-run prompt. The default review shows the task, profile/stack, provider/model/thinking level, effective tools, working directory, shared-user boundary, payload size, and fingerprint; the complete provider-bound prompt can be opened on demand.
|
|
50
|
+
- Backend selection is layered configuration rather than profile schema: `subagents.backend` supplies global/project defaults, the trusted project's `subagents.profiles.<id>.backend` supplies a per-profile override, and `/forge-agent plan|run --backend <id>` or the interactive `forge_subagent` `backend` parameter overrides one run. Both the `pi-subprocess-readonly` and `pi-rpc-readonly` backends are registered; there is no fallback when the selected backend is unavailable, and unattended tool invocation is pinned to the effective configured profile backend.
|
|
51
|
+
- Foreground timeout is layered host configuration rather than profile schema: `subagents.timeoutMs` supplies a 60,000-millisecond default and `subagents.profiles.<id>.timeoutMs` can override it per profile; values must be from 1,000 through 3,600,000 milliseconds. Invalid values warn and preserve the preceding valid/default value; discovery, planning, and approval surfaces show the effective best-effort timeout and source.
|
|
52
|
+
- Foreground progress and the bounded final report enter the normal tool-call result. A dedicated child report channel retains the normalized response, complete text transcript, tool calls/results, diagnostics, usage, approval receipt, and execution report without persisting the full prompt or inline image data; omitted images retain MIME and encoded-size metadata.
|
|
53
|
+
- The subprocess backend is explicitly shared-user rather than OS-sandboxed: read-only is a tool policy, host timeout/cancellation are best effort, and `/tree` reverts conversation state rather than provider egress, billing, or external side effects.
|
|
54
|
+
- `/forge-agent backends` and `/forge-agent plan <profile> <task>` expose backend discovery and provider-free exact dry planning to a human.
|
|
55
|
+
- Deterministic fake-backend conformance coverage exercises accepted/rejected preflight, tool effects, access/limit refusal, exact preparation, success/failure, cancellation races, timeout, media, artifacts, and traces. An offline faux-provider test additionally executes the concrete SDK backend through a real Pi `AgentSession` without network traffic.
|
|
56
|
+
- Selected parent context uses explicit provenance and deterministic exact UTF-8 budgeting; required items survive, optional items are selected newest-first, and the complete delegated text/media task remains the protected final user message.
|
|
57
|
+
- Granular validators cover request access/depth/media/limits, backend capabilities and enforcement, prompt-runtime fidelity, plan correlation, all response terminal statuses, usage units, artifact namespaces/paths, and authorized trace handles.
|
|
58
|
+
- Portable profile, prompt-stack, and complete execution fingerprints use canonical `sha256:v1` serialization without changing legacy branch-provenance fingerprints.
|
|
59
|
+
- The opt-in internal Pi SDK spike remains available for broader live diagnostics, including media and trusted custom registrations beyond the shipped text-only walking skeleton.
|
|
60
|
+
- Adapter responsibilities and unsupported runner behavior are documented in the [subagent adapter contract](subagent-adapter.md).
|
|
61
|
+
|
|
62
|
+
## Prompt Stack Loading and Storage
|
|
63
|
+
|
|
64
|
+
- File-backed prompt stacks from `.pi/forge/prompt-stacks/*.json`.
|
|
65
|
+
- Legacy `.pi/prompt-stacks/*.json` stacks remain readable and editable for compatibility.
|
|
66
|
+
- Same-named files in `.pi/forge/prompt-stacks` shadow legacy stack files.
|
|
67
|
+
- New stacks, imports, and forks write to `.pi/forge/prompt-stacks`.
|
|
68
|
+
- Trusted global and project-local macro/slot registration modules load from `~/.pi/forge/extensions` and `.pi/forge/extensions` before stack validation and reload on `/preset reload`.
|
|
69
|
+
- Trusted registration ownership is disposed during runtime shutdown, and supported ESM/CommonJS extension entry formats reload with fresh module code.
|
|
70
|
+
- `/preset migrate-stacks [--dry-run] [--overwrite] [--delete-legacy]` copies legacy stacks into the forge storage location.
|
|
71
|
+
- `default.json` auto-activation unless `autoActivate` is `false`.
|
|
72
|
+
- Branch-aware persisted active stack restore from session entries.
|
|
73
|
+
- Branch-aware macro session variable restore when navigating the session tree.
|
|
74
|
+
- Persisted `/preset use none` / `off` opt-out.
|
|
75
|
+
- Invalid stacks with error diagnostics are skipped by automatic selection.
|
|
76
|
+
- Raw stack fields are shape-checked before recovery normalization, including behavior-changing booleans/enums, defaults, context, variables, and item fields.
|
|
77
|
+
- Stack validation for duplicate item IDs, duplicate stack IDs, unsupported slots, missing chat-history slots, and ignored items.
|
|
78
|
+
- Stack validation for tool and skill policy shape.
|
|
79
|
+
|
|
80
|
+
## Prompt Compilation
|
|
81
|
+
|
|
82
|
+
- `replace`, `append`, and `prepend` system prompt modes.
|
|
83
|
+
- Empty replacement system prompt fallback to Pi's base system prompt.
|
|
84
|
+
- Enabled item ordering preserved during compilation.
|
|
85
|
+
- Movable `chat-history` slot in message layout.
|
|
86
|
+
- Optional omission of latest user message from chat history.
|
|
87
|
+
- Optional stripping of prior assistant thinking blocks from inserted chat history while preserving visible text, tool calls, and tool results.
|
|
88
|
+
- Chat history can filter summaries/roles, drop prior tool history, and cap recent history by message count or approximate characters with dangling tool calls/results repaired after filtering.
|
|
89
|
+
- Duplicate chat-history warning unless explicitly allowed.
|
|
90
|
+
- Synthetic `user`, `assistant`, and hidden `custom` messages.
|
|
91
|
+
- Context rewrite limited to the first provider request of each user-submitted turn.
|
|
92
|
+
- Tool policy filters Pi's active tool list while the stack is active and restores the previous active tools when the stack no longer applies.
|
|
93
|
+
- Tool policy restores its pre-policy baseline during extension shutdown so Pi reload/session replacement cannot carry a restricted built-in tool set into the replacement runtime.
|
|
94
|
+
- Startup tool enforcement waits until extension `session_start` configuration is complete, reasserts before user input and turns, and blocks disallowed model tool calls at execution time.
|
|
95
|
+
- Skill policy filters skills rendered by pi-forge `skills` slots.
|
|
96
|
+
- Outgoing regex transforms can run after `chat-history` insertion and after final prompt compilation.
|
|
97
|
+
- Finalize regex transforms can rewrite completed assistant messages at `message_end`.
|
|
98
|
+
|
|
99
|
+
## Regex Transforms
|
|
100
|
+
|
|
101
|
+
- Top-level `regex.schemaVersion` and ordered `regex.rules` stack config.
|
|
102
|
+
- Deterministic JavaScript `RegExp` replacements only; no embedded JavaScript, DOM access, browser automation, or CSS/HTML decoration runtime.
|
|
103
|
+
- `stage: "history"` transforms messages inserted by the `chat-history` slot.
|
|
104
|
+
- `stage: "compiled"` transforms the final compiled system prompt and/or message text before provider serialization.
|
|
105
|
+
- `effect: "outgoing"` is active for model-bound prompt text.
|
|
106
|
+
- `effect: "finalize"` is active for completed assistant messages at `stage: "compiled"` / `targets: ["messages"]`.
|
|
107
|
+
- `effect: "finalize"` is destructive: it replaces the finalized assistant message in Pi's stored transcript, so the original model output is not preserved.
|
|
108
|
+
- `effect: "display"` and `"both"` validate with warnings and are ignored until true display transforms are implemented.
|
|
109
|
+
- Streaming display is not transformed; raw text may be visible until the final message replacement happens.
|
|
110
|
+
- Message transforms support role filters, `maxMessages`, `maxChars`, `minDepth`, `maxDepth`, and `trimStrings`. `$0` is supported as a full-match alias for `$&` in replacements.
|
|
111
|
+
- Compiled-stage transforms support `targets: ["system"]`, `["messages"]`, or both.
|
|
112
|
+
- Supported regex flags are `g`, `i`, `m`, `s`, and `u`, with duplicate/unsupported flags rejected during validation.
|
|
113
|
+
- Runtime diagnostics report regex match counts and changed text segment counts.
|
|
114
|
+
|
|
115
|
+
## Runtime Slots
|
|
116
|
+
|
|
117
|
+
- `chat-history`
|
|
118
|
+
- `tools`
|
|
119
|
+
- `tool-guidelines`
|
|
120
|
+
- `skills`
|
|
121
|
+
- `project-context`
|
|
122
|
+
- `append-system-prompt`
|
|
123
|
+
- `date`
|
|
124
|
+
- `cwd`
|
|
125
|
+
- `date-cwd`
|
|
126
|
+
- `active-model`
|
|
127
|
+
- `pi-docs`
|
|
128
|
+
- `variables`
|
|
129
|
+
- `date` and `date-cwd` slots can include `Current time: HH:MM:SS` with `includeTime: true`.
|
|
130
|
+
- Runtime slots are registered through the same `registerSlot` definition interface used by trusted custom slots.
|
|
131
|
+
- Trusted `~/.pi/forge/extensions` / `.pi/forge/extensions` modules and reusable Pi packages can register additional runtime slots through `registerSlot`, with declarative option schemas and shared render helpers.
|
|
132
|
+
|
|
133
|
+
## Tool and Skill Policy
|
|
134
|
+
|
|
135
|
+
- Stack-level `tools.allow` / `tools.deny` policy.
|
|
136
|
+
- Stack-level `skills.allow` / `skills.deny` policy.
|
|
137
|
+
- Policy entries support exact names and `*` wildcards.
|
|
138
|
+
- Each resource uses either `allow` or `deny`; non-empty mixed lists are validation errors.
|
|
139
|
+
- Tool policy is enforced with `pi.setActiveTools()` and restored when prompt stacks are disabled or switched to an unrestricted stack.
|
|
140
|
+
- Tool policy preserves later extension tool additions in the restorable baseline while keeping them filtered from an active restrictive stack.
|
|
141
|
+
- A `tool_call` guard blocks tools outside the active stack policy even if another extension later changes Pi's active tool list.
|
|
142
|
+
- Rendered `tools` slots, tool macros such as `{{tools}}`, and `tool-guidelines` respect stack tool policy.
|
|
143
|
+
- Rendered `skills` slots respect stack skill policy and continue to hide skills marked `disableModelInvocation`.
|
|
144
|
+
- Skill policy controls model-visible skill listings rendered by pi-forge; it does not disable explicit skill invocation and is not a security boundary.
|
|
145
|
+
- Validation warns when skill policy is used with `append` or `prepend` mode because Pi's base prompt may already include unfiltered skills.
|
|
146
|
+
|
|
147
|
+
## Macros
|
|
148
|
+
|
|
149
|
+
- Built-in macros: `{{cwd}}`, `{{date}}`, `{{time}}`, `{{lastUserMessage}}`, `{{selectedTools}}`, `{{tools}}`, `{{activeModel}}`.
|
|
150
|
+
- Built-in macros are registered through the same `registerMacro` definition interface used by trusted custom macros.
|
|
151
|
+
- Parser-backed macro expansion supports nested `{{...}}` expressions and `::` argument splitting at the current macro depth.
|
|
152
|
+
- Filter macros: `{{trim::value}}`, `{{upper::value}}`, `{{lower::value}}`, `{{json::value}}`, and `{{xml::value}}`.
|
|
153
|
+
- Lazy conditional macros: `{{ifvar::name::then::else}}`, `{{ifeq::name::expected::then::else}}`, `{{iftools::tool::then::else}}`, and `{{ifslot::slot::then::else}}`. Only the selected branch is expanded.
|
|
154
|
+
- Trusted `~/.pi/forge/extensions` / `.pi/forge/extensions` modules and reusable Pi packages can register additional macros through `registerMacro`, with argument metadata and shared runtime/variable/helper access.
|
|
155
|
+
- `getRegisteredMacros()` and `getRegisteredSlots()` expose the active macro/slot definitions for implementation references and UI/resource inspection.
|
|
156
|
+
- Static stack variables from `stack.variables`.
|
|
157
|
+
- Turn/session/static lookup through `{{getvar::name}}`, `{{var::name}}`, and bare `{{name}}`.
|
|
158
|
+
- Turn variable mutation through `{{setvar::name::value}}`, `{{setturnvar::name::value}}`, and `{{clearvar::name}}`.
|
|
159
|
+
- Session variable mutation through `{{setsessionvar::name::value}}`, `{{setvar::session::name::value}}`, and `{{clearsessionvar::name}}`.
|
|
160
|
+
- Unknown macro diagnostics with configurable keep/warn/error policy.
|
|
161
|
+
- Non-string variable values stringify as JSON during macro substitution.
|
|
162
|
+
|
|
163
|
+
## Template Variables
|
|
164
|
+
|
|
165
|
+
- Static string variables from `stack.variables`.
|
|
166
|
+
- JSON-compatible session variable values: string, number, boolean, null, arrays, and objects.
|
|
167
|
+
- Session variable snapshots restore from the current session tree branch, so tree navigation rolls macro variables back/forward with history.
|
|
168
|
+
- Valid `<variables>` rendering from the `variables` slot.
|
|
169
|
+
- XML variable entries rendered as `<var name="...">...</var>`.
|
|
170
|
+
- Optional `format: "plain"` variables slot rendering.
|
|
171
|
+
- Scope toggles with `includeStatic`, `includeSession`, and `includeTurn`.
|
|
172
|
+
|
|
173
|
+
## Commands
|
|
174
|
+
|
|
175
|
+
- `/profile list`
|
|
176
|
+
- `/profile use <id>`
|
|
177
|
+
- `/profile save <id> [--overwrite]`
|
|
178
|
+
- `/profile status`
|
|
179
|
+
- `/profile preview <id>`
|
|
180
|
+
- `/profile validate [id]`
|
|
181
|
+
- `/profile reload`
|
|
182
|
+
- `/profile forget`
|
|
183
|
+
- `/forge-agent backends`
|
|
184
|
+
- `/forge-agent plan <profile> <task>`
|
|
185
|
+
- `/forge-agent run <profile> <task>`
|
|
186
|
+
- `/preset list`
|
|
187
|
+
- `/preset status`
|
|
188
|
+
- `/preset use <id|none>`
|
|
189
|
+
- `/preset preview [id]`
|
|
190
|
+
- `/preset validate [id]`
|
|
191
|
+
- `/preset diagnostics`
|
|
192
|
+
- `/preset reload`
|
|
193
|
+
- `/preset ui [stop|restart]`
|
|
194
|
+
- `/preset migrate-stacks [--dry-run] [--overwrite] [--delete-legacy]`
|
|
195
|
+
- `/preset import-silly <path> [character_id] [--dry-run] [--overwrite]`
|
|
196
|
+
- `/intercept`
|
|
197
|
+
- `/payload next [save=<path>]`
|
|
198
|
+
|
|
199
|
+
## SillyTavern Import
|
|
200
|
+
|
|
201
|
+
- Import SillyTavern preset JSON into `.pi/forge/prompt-stacks/<id>.json`.
|
|
202
|
+
- Generate import reports under `.pi/forge/import-reports/<id>.md`.
|
|
203
|
+
- Select a specific `character_id` when multiple prompt orders exist.
|
|
204
|
+
- Protect existing generated stack/report files from accidental overwrite, with confirmation or `--overwrite`.
|
|
205
|
+
- Preview generated output without writing files via `--dry-run`.
|
|
206
|
+
- Convert prompt order into prompt stack items.
|
|
207
|
+
- Preserve original SillyTavern identifiers in item source metadata.
|
|
208
|
+
- Convert `chatHistory` marker to a movable `chat-history` slot.
|
|
209
|
+
- Skip unsupported SillyTavern marker items and report omissions.
|
|
210
|
+
- Detect `{{lastUserMessage}}` and configure chat history accordingly.
|
|
211
|
+
- Strip SillyTavern comments and `{{trim}}` markers.
|
|
212
|
+
- Report macros that need manual migration, including normalized camelCase SillyTavern macro names.
|
|
213
|
+
- Report supported SillyTavern-style variable macros such as `setvar` and `getvar` as handled by pi-forge.
|
|
214
|
+
- Report SillyTavern `extensions.regex_scripts` counts, prompt/display classification, script names, and migration notes.
|
|
215
|
+
- Convert safe SillyTavern `promptOnly` regex scripts into pi-forge `regex.rules` with `stage: "history"`, `effect: "outgoing"`, JavaScript replacement syntax, trim strings, depth limits, clear placement role mappings, and preserved `source.sillytavern` metadata. History-stage depth is relative to the filtered chat history, matching SillyTavern's chat-relative depth.
|
|
216
|
+
- Leave SillyTavern display-only, mixed prompt/display, DOM/browser, CSS/HTML decoration, JavaScript, unsupported-placement, unsupported-flag, and invalid regex scripts as report-only migration notes.
|
|
217
|
+
|
|
218
|
+
## Debugging and Tests
|
|
219
|
+
|
|
220
|
+
- `/intercept` displays the next provider payload with redaction/truncation for secrets and large data.
|
|
221
|
+
- `/payload next save=<path>` displays and saves the next redacted/truncated provider payload with char/token-ish size estimates.
|
|
222
|
+
- Payload redaction preserves known token limits, accounting counters, budgets, and tokenizer names while retaining credential-shaped token redaction.
|
|
223
|
+
- The web editor can arm, poll, clear, and inspect the next redacted provider payload in a full-screen collapsible JSON inspector.
|
|
224
|
+
- Runtime compile diagnostics are visible through a footer status and `/preset diagnostics`.
|
|
225
|
+
- `/preset ui` starts a token-protected localhost web editor for stack management.
|
|
226
|
+
- Node built-in tests cover agent-profile resolution/application/provenance, compiler, loader, SillyTavern importer, and the command/event harness.
|
|
227
|
+
- Tests cover variable rendering, XML escaping, macro persistence, and typed macro stringification.
|
|
228
|
+
- Tests cover regex validation, history-stage transforms, compiled-stage transforms, finalize transforms, replacement syntax, trim strings, depth limits, role/message/char limits, and preservation of non-text message parts.
|
|
229
|
+
- Tests cover subagent host resolution, custom dependency detection, all access/required-limit/terminal-status matrices, effect-aware tool negotiation, context budgeting, protected media tasks, canonical fingerprint tamper detection, and malformed external contract values.
|
|
230
|
+
- A real headless-Chrome smoke test covers editor load, dirty state, metadata editing, policy and regex editing, validation, save, disk persistence, export, import, and browser-console errors.
|
|
231
|
+
- TypeScript strict typecheck passes.
|
|
232
|
+
- Package dry-run verifies published tarball contents.
|
|
233
|
+
|
|
234
|
+
## Web Stack Editor
|
|
235
|
+
|
|
236
|
+
- `/preset ui`, `/preset ui restart`, and `/preset ui stop`.
|
|
237
|
+
- Local editor server bound to an available `127.0.0.1` port by default with a random URL token.
|
|
238
|
+
- Preferred editor port can be configured through `.pi/forge/config.json` using `webEditor.port`; if it is unavailable, pi-forge falls back to an available port.
|
|
239
|
+
- Existing same-project editor servers are reclaimed after extension reinitialization from session navigation/new-session flows, so `/preset ui` reuses the current URL instead of opening a second port.
|
|
240
|
+
- Resource inventory and preview remain usable when a reclaimed editor host is refreshed from lifecycle contexts that do not expose command-only prompt APIs.
|
|
241
|
+
- Stack list with active/error/warning indicators.
|
|
242
|
+
- Collapsible prompt-stack sidebar.
|
|
243
|
+
- Collapsible stack metadata panel and main-area tabs for Items, Regex, Policy, and Stack JSON/context/variables work.
|
|
244
|
+
- Light/dark theme toggle, button icons, and tooltips for common actions.
|
|
245
|
+
- Unsaved-change badge in the top bar.
|
|
246
|
+
- Create a new prompt stack from the browser, including when no stack files exist yet; new stacks start from the default Pi prompt mirror layout.
|
|
247
|
+
- View immutable stack ID and edit name, mode, `autoActivate`, description, and existing stack file content; use Fork to create a new ID.
|
|
248
|
+
- Edit stack `context` options from a structured dialog.
|
|
249
|
+
- Edit stack static `variables` from a structured table.
|
|
250
|
+
- Edit stack `regex.rules`, including order, stage, effect, targets, roles, limits, depth, trim strings, pattern, flags, replacement, and runtime warnings.
|
|
251
|
+
- Policy editor lists registered tools and loaded skills, hides exact selected names from the available list, and supports removable selected-pattern chips plus filter/autocomplete input.
|
|
252
|
+
- Reorder items by drag-and-drop.
|
|
253
|
+
- Add block and slot stack items directly.
|
|
254
|
+
- Delete stack items.
|
|
255
|
+
- Toggle item enabled state from the item list.
|
|
256
|
+
- Inline item validation badges when diagnostics point at a specific item.
|
|
257
|
+
- Edit block content in a full-height text editor area.
|
|
258
|
+
- Edit slot kind, role, slot type, and common slot options through form controls.
|
|
259
|
+
- Fall back to raw JSON editing for advanced slot options.
|
|
260
|
+
- View, copy, and apply raw stack JSON as a recovery path for advanced stack-level fields.
|
|
261
|
+
- Validate and inspect edited stack JSON before saving.
|
|
262
|
+
- Full-screen structured preview inspector with collapsible system/message sections, char/token estimates, and copy controls.
|
|
263
|
+
- Arm and inspect the next provider payload from the web editor; captures triggered by `/payload next` are also available to the browser while the editor is open.
|
|
264
|
+
- Provider payload inspector shows top-level JSON sections, redacted full text, char/token estimates, and copy controls.
|
|
265
|
+
- Save existing stack JSON and immediately reload pi-forge stack data.
|
|
266
|
+
- Save rejects attempts to change an existing stack ID before writing or changing active selection.
|
|
267
|
+
- Keyboard shortcuts for new stack, save, validate, preview, and closing dialogs/inspectors.
|
|
268
|
+
- Import native stack JSON or SillyTavern preset JSON into `.pi/forge/prompt-stacks`; SillyTavern uploads are converted automatically.
|
|
269
|
+
- Show the SillyTavern import report in the web editor after import, with copy support.
|
|
270
|
+
- Export the current edited stack JSON from the browser, with clipboard fallback when download is unavailable.
|
|
271
|
+
- Fork the current stack into a new stack file, with optional activation.
|
|
272
|
+
- Delete stack files, disabling prompt-stack replacement if the deleted stack was active.
|
|
273
|
+
- Trust and path guardrails for save/import/fork/delete writes.
|
|
274
|
+
- Top-level navigation between prompt stacks and project agent profiles; stack drafts, selection, and active state survive surface switches.
|
|
275
|
+
- Profile list shows ID, name, model/thinking/stack targets, validation state, `autoActivate` and last-applied badges, and a `subagent` badge for delegation-enabled profiles.
|
|
276
|
+
- Profile create, edit, validate, save, one-shot apply, and delete reuse the shared resolver, transactional application service, and guarded repository; save rejects a second auto-activation profile and on-disk conflicts.
|
|
277
|
+
- Profile form populates provider/model choices from the model registry and stack choices from the shared stack repository, and shows resolution diagnostics for missing models, authentication, unsupported thinking levels, invalid stacks, and unmatched tool policy.
|
|
278
|
+
- A runtime/provenance card distinguishes current runtime, last-applied provenance, source-definition state, and per-field runtime drift after external model, thinking-level, or stack changes.
|
|
279
|
+
- Per-profile delegation card toggles the trusted project's `subagents.profiles.<id>` opt-in with backend and timeout overrides, writing `.pi/forge/config.json` while preserving unrelated keys and removing emptied entries; the card reports the effective backend/timeout and source, warns about unregistered backends, and keeps project defaults and the unattended-invocation setting read-only.
|
|
280
|
+
- Smoke tests cover editor server token checks, bundled page/script markers, save, payload arm/capture/clear, create/fork, SillyTavern JSON import conversion, collision handling, delete, and stop behavior.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Macros and runtime slots
|
|
2
|
+
|
|
3
|
+
[Documentation](../README.md)
|
|
4
|
+
|
|
5
|
+
## Value macros
|
|
6
|
+
|
|
7
|
+
| Macro | Value |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `{{lastUserMessage}}` | Latest user message |
|
|
10
|
+
| `{{date}}` | Current date as `YYYY-MM-DD` |
|
|
11
|
+
| `{{time}}` | Current time as `HH:MM:SS` |
|
|
12
|
+
| `{{cwd}}` | Current working directory |
|
|
13
|
+
| `{{tools}}` | Comma-separated selected tool names |
|
|
14
|
+
| `{{selectedTools}}` | Alias of `{{tools}}` |
|
|
15
|
+
| `{{activeModel}}` | Current `provider/model` |
|
|
16
|
+
| `{{name}}` | Turn, session, then static variable lookup |
|
|
17
|
+
| `{{var::name}}` / `{{getvar::name}}` | Explicit scoped-fallback variable lookup |
|
|
18
|
+
| `{{getturnvar::name}}` | Turn-only lookup |
|
|
19
|
+
| `{{getsessionvar::name}}` | Session-only lookup |
|
|
20
|
+
|
|
21
|
+
## Variable mutation
|
|
22
|
+
|
|
23
|
+
```text
|
|
24
|
+
{{setvar::name::value}} set a turn variable
|
|
25
|
+
{{setturnvar::name::value}} set a turn variable
|
|
26
|
+
{{setsessionvar::name::value}} set a session variable
|
|
27
|
+
{{setvar::session::name::value}} set a session variable
|
|
28
|
+
{{clearvar::name}} clear using normal scope behavior
|
|
29
|
+
{{clearturnvar::name}} clear a turn variable
|
|
30
|
+
{{clearsessionvar::name}} clear a session variable
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Turn variables reset for each message. Session variables follow Pi's active session-tree branch. Static variables come from top-level `stack.variables`. Non-string JSON-compatible values stringify as JSON during substitution.
|
|
34
|
+
|
|
35
|
+
## Filters and conditionals
|
|
36
|
+
|
|
37
|
+
Nested macros are supported. `::` separators are parsed only at the current macro depth.
|
|
38
|
+
|
|
39
|
+
| Macro | Result |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `{{trim::value}}` | Trim surrounding whitespace |
|
|
42
|
+
| `{{upper::value}}` | Uppercase value |
|
|
43
|
+
| `{{lower::value}}` | Lowercase value |
|
|
44
|
+
| `{{json::value}}` | JSON string literal |
|
|
45
|
+
| `{{xml::value}}` | XML-escaped value |
|
|
46
|
+
| `{{ifvar::name::then::else}}` | Select by variable existence |
|
|
47
|
+
| `{{ifeq::name::expected::then::else}}` | Select by equality |
|
|
48
|
+
| `{{iftools::tool::then::else}}` | Select by effective tool name |
|
|
49
|
+
| `{{ifslot::slot::then::else}}` | Select by enabled slot name |
|
|
50
|
+
|
|
51
|
+
The final `else` is optional. Branches are lazy: skipped branches are not expanded and cannot mutate variables.
|
|
52
|
+
|
|
53
|
+
Unknown macro behavior is controlled by stack `defaults.unknownMacro`: keep, warn, or error according to schema validation.
|
|
54
|
+
|
|
55
|
+
## Built-in slots
|
|
56
|
+
|
|
57
|
+
| Slot | Rendered content |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `chat-history` | Current conversation, with filtering and limits |
|
|
60
|
+
| `tools` | Effective tools and descriptions/snippets |
|
|
61
|
+
| `tool-guidelines` | Tool-use guidance |
|
|
62
|
+
| `skills` | Model-visible loaded Pi skills |
|
|
63
|
+
| `project-context` | Trusted project instructions/context |
|
|
64
|
+
| `append-system-prompt` | Pi's appended system prompt text |
|
|
65
|
+
| `variables` | Static/session/turn values |
|
|
66
|
+
| `date` | Current date, optionally time |
|
|
67
|
+
| `cwd` | Working directory |
|
|
68
|
+
| `date-cwd` | Date and working directory, optionally time |
|
|
69
|
+
| `active-model` | Selected provider/model |
|
|
70
|
+
| `pi-docs` | Pi documentation guidance |
|
|
71
|
+
|
|
72
|
+
Structured slots (`tools`, `tool-guidelines`, `skills`, `project-context`, `variables`) default to XML-style wrappers and support `"format": "plain"`.
|
|
73
|
+
|
|
74
|
+
Notable Pi-mirror options include `tools.onlyWithSnippets`, `tool-guidelines.heading`, `tool-guidelines.includePiDefaultGuidelines`, `tool-guidelines.piStyle`, and `skills.requireReadTool`. `date` and `date-cwd` support `includeTime: true`.
|
|
75
|
+
|
|
76
|
+
`variables` supports `includeStatic`, `includeSession`, `includeTurn`, and `format`.
|
|
77
|
+
|
|
78
|
+
The complete `chat-history` option set is documented in [stack schema](stack-schema.md#chat-history-options).
|
|
79
|
+
|
|
80
|
+
## Trusted custom definitions
|
|
81
|
+
|
|
82
|
+
Trusted global/project modules and reusable Pi packages can register additional macro and slot names. The runtime exposes the active definitions through `getRegisteredMacros()` and `getRegisteredSlots()`. See [custom macros and slots](../guides/custom-macros-and-slots.md).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Public API policy
|
|
2
|
+
|
|
3
|
+
pi-forge is pre-1.0. This document separates supported integration surfaces from experimental 0.4 work and compatibility paths that should not become permanent dependencies.
|
|
4
|
+
|
|
5
|
+
## Stable
|
|
6
|
+
|
|
7
|
+
- The package default export is the Pi extension entry point declared by `pi.extensions`.
|
|
8
|
+
- Package-root macro and slot registration APIs (`registerMacro`, `registerSlot`, their registry readers, render contexts, and declarative definition types) are supported for trusted reusable extensions.
|
|
9
|
+
- `ForgeExtensionApi` and related registration types are supported for trusted project-local forge extensions.
|
|
10
|
+
|
|
11
|
+
Stable means changes should preserve source compatibility within the documented supported release range unless a changelog entry explicitly announces a breaking release.
|
|
12
|
+
|
|
13
|
+
## Experimental
|
|
14
|
+
|
|
15
|
+
- Agent-profile repository, resolution, application, preview, provenance, and drift APIs are 0.4 experimental surfaces.
|
|
16
|
+
- The runner-neutral subagent contract and host-resolution helpers are 0.4 experimental surfaces. Backend registration, sealing, lifecycle, and the fresh-process backends moved to `@zihanw/pi-subagent-runtime`; Forge consumes them through its public runtime API.
|
|
17
|
+
- New subagent integrations should import from `@zihanw/pi-forge/subagent`. The package root continues to re-export the current subagent names through 0.4 for compatibility.
|
|
18
|
+
|
|
19
|
+
Experimental APIs are typed, tested, and documented, but may change in later releases as adapter and parent-integration experience exposes missing semantics. Changes should still be deliberate and recorded.
|
|
20
|
+
|
|
21
|
+
## Internal compatibility paths
|
|
22
|
+
|
|
23
|
+
- `@zihanw/pi-forge/src/*` subpath exports exist for compatibility with earlier source-shaped imports. They resolve to compiled `dist` modules and are not a promise that every implementation module is a permanent public API.
|
|
24
|
+
- Browser-only `@zihanw/pi-forge/src/web-editor/client/*` implementation paths are explicitly blocked. The editor is distributed only through its generated embedded assets; these authored modules have never been a runtime integration surface.
|
|
25
|
+
- The package root re-exports `@zihanw/pi-forge/subagent` contract names directly from the focused contract modules. The former `src/subagent-contract.ts` compatibility barrel and the `scripts/subagent-sdk-spike*` diagnostic harness were removed in the 0.4 cleanup.
|
|
26
|
+
- Physical `src/` files are not included in the npm tarball. Runtime installation and legacy `@zihanw/pi-forge/src/*` aliases use compiled `dist` modules; source inspection or modification requires a repository clone.
|
|
27
|
+
|
|
28
|
+
Before removing the compatibility subpaths, check known consumers, announce the change, and provide supported package entry points for legitimate integrations.
|
|
@@ -0,0 +1,167 @@
|
|
|
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, 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 {{macros}} for dynamic content."
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Valid roles are `system`, `user`, `assistant`, and `custom`. Custom-role content participates in compilation but does not produce a provider message directly.
|
|
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
|
+
## Modes
|
|
49
|
+
|
|
50
|
+
- `replace` replaces Pi's base system prompt; empty output falls back to the base.
|
|
51
|
+
- `append` places stack system text after Pi's base.
|
|
52
|
+
- `prepend` places stack system text before Pi's base.
|
|
53
|
+
|
|
54
|
+
## Chat-history options
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"includeLastUserMessage": false,
|
|
59
|
+
"stripAssistantThinking": true,
|
|
60
|
+
"includeSummaries": true,
|
|
61
|
+
"toolMode": "keep",
|
|
62
|
+
"roles": ["user", "assistant"],
|
|
63
|
+
"maxMessages": 40,
|
|
64
|
+
"maxChars": 20000
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- Set `includeLastUserMessage: false` when a later block reinserts `{{lastUserMessage}}`.
|
|
69
|
+
- `stripAssistantThinking` removes prior thinking blocks but preserves visible assistant text, tool calls, and results. It does not change the live loop or stored transcript.
|
|
70
|
+
- `includeSummaries: false` excludes branch/compaction summaries.
|
|
71
|
+
- `roles` keeps only selected roles.
|
|
72
|
+
- `toolMode: "drop"` removes prior tool traffic.
|
|
73
|
+
- `maxMessages` and `maxChars` keep recent history within limits.
|
|
74
|
+
|
|
75
|
+
When filtering would separate a tool call from its result, pi-forge removes dangling entries rather than sending inconsistent provider history.
|
|
76
|
+
|
|
77
|
+
## Structured slots
|
|
78
|
+
|
|
79
|
+
`tools`, `tool-guidelines`, `skills`, `project-context`, and `variables` support `"format": "plain"`; the default is XML-style structure. Date slots support `includeTime: true`.
|
|
80
|
+
|
|
81
|
+
See [macros and slots](macros-and-slots.md) for names and options.
|
|
82
|
+
|
|
83
|
+
## Tool and skill policy
|
|
84
|
+
|
|
85
|
+
Patterns are exact by default and support `*` wildcards:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"tools": {
|
|
90
|
+
"allow": ["read", "grep", "find", "ls"]
|
|
91
|
+
},
|
|
92
|
+
"skills": {
|
|
93
|
+
"deny": ["browser-danger"]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Each resource may have a non-empty `allow` list or `deny` list, never both. Tool allow keeps matching active tools; deny removes matching active tools. Unmatched allow patterns are surfaced during validation/preflight.
|
|
99
|
+
|
|
100
|
+
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.
|
|
101
|
+
|
|
102
|
+
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.
|
|
103
|
+
|
|
104
|
+
## Variables
|
|
105
|
+
|
|
106
|
+
Top-level static variables are JSON values:
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"variables": {
|
|
111
|
+
"char": "Konata",
|
|
112
|
+
"user": "User",
|
|
113
|
+
"style": { "tone": "concise" }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Turn and session values are changed through macros. See [macro reference](macros-and-slots.md).
|
|
119
|
+
|
|
120
|
+
## Regex transforms
|
|
121
|
+
|
|
122
|
+
Regex rules are ordered, deterministic JavaScript `RegExp` replacements. There is no embedded JavaScript, DOM, browser, CSS, or HTML-decoration runtime.
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"regex": {
|
|
127
|
+
"schemaVersion": 1,
|
|
128
|
+
"rules": [
|
|
129
|
+
{
|
|
130
|
+
"id": "trim-ooc",
|
|
131
|
+
"enabled": true,
|
|
132
|
+
"stage": "history",
|
|
133
|
+
"effect": "outgoing",
|
|
134
|
+
"pattern": "\\(OOC:[^)]+\\)",
|
|
135
|
+
"flags": "gi",
|
|
136
|
+
"replace": "",
|
|
137
|
+
"roles": ["assistant"],
|
|
138
|
+
"maxMessages": 20
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`stage: "history"` changes text inserted by `chat-history`. `stage: "compiled"` changes the final compiled system prompt and/or messages through optional `targets: ["system", "messages"]`.
|
|
146
|
+
|
|
147
|
+
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.
|
|
148
|
+
|
|
149
|
+
Outgoing rules change future model input. To destructively change a completed assistant transcript message:
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"id": "finalize-ooc",
|
|
154
|
+
"enabled": true,
|
|
155
|
+
"stage": "compiled",
|
|
156
|
+
"effect": "finalize",
|
|
157
|
+
"targets": ["messages"],
|
|
158
|
+
"roles": ["assistant"],
|
|
159
|
+
"pattern": "\\s*\\(OOC:[^)]+\\)",
|
|
160
|
+
"flags": "gi",
|
|
161
|
+
"replace": ""
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
> `finalize` runs at `message_end`, after raw output may have streamed. It replaces the stored assistant message, so the original output is not preserved.
|
|
166
|
+
|
|
167
|
+
`effect: "display"` and `"both"` validate with warnings but are ignored until true display transforms exist. Runtime diagnostics report match and changed-segment counts.
|