@jadelclemens/pi-forge 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +486 -0
- package/LICENSE +21 -0
- package/PUBLIC_API.md +5 -0
- package/README.md +204 -2
- package/README.zh-CN.md +128 -0
- package/SUBAGENT_ADAPTER_CONTRACT.md +7 -0
- package/dist/active-state.d.ts +148 -0
- package/dist/active-state.d.ts.map +1 -0
- package/dist/active-state.js +374 -0
- package/dist/active-state.js.map +1 -0
- package/dist/agent-profile.d.ts +51 -0
- package/dist/agent-profile.d.ts.map +1 -0
- package/dist/agent-profile.js +197 -0
- package/dist/agent-profile.js.map +1 -0
- package/dist/capabilities.d.ts +39 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +160 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/capability-anchors.d.ts +45 -0
- package/dist/capability-anchors.d.ts.map +1 -0
- package/dist/capability-anchors.js +263 -0
- package/dist/capability-anchors.js.map +1 -0
- package/dist/capability-command.d.ts +4 -0
- package/dist/capability-command.d.ts.map +1 -0
- package/dist/capability-command.js +164 -0
- package/dist/capability-command.js.map +1 -0
- package/dist/capability-events.d.ts +79 -0
- package/dist/capability-events.d.ts.map +1 -0
- package/dist/capability-events.js +478 -0
- package/dist/capability-events.js.map +1 -0
- package/dist/capability-projection.d.ts +22 -0
- package/dist/capability-projection.d.ts.map +1 -0
- package/dist/capability-projection.js +273 -0
- package/dist/capability-projection.js.map +1 -0
- package/dist/capability-protocol.d.ts +21 -0
- package/dist/capability-protocol.d.ts.map +1 -0
- package/dist/capability-protocol.js +15 -0
- package/dist/capability-protocol.js.map +1 -0
- package/dist/capability-state.d.ts +74 -0
- package/dist/capability-state.d.ts.map +1 -0
- package/dist/capability-state.js +43 -0
- package/dist/capability-state.js.map +1 -0
- package/dist/capability-tool.d.ts +11 -0
- package/dist/capability-tool.d.ts.map +1 -0
- package/dist/capability-tool.js +25 -0
- package/dist/capability-tool.js.map +1 -0
- package/dist/capability-web-host.d.ts +11 -0
- package/dist/capability-web-host.d.ts.map +1 -0
- package/dist/capability-web-host.js +105 -0
- package/dist/capability-web-host.js.map +1 -0
- 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/codecs/agent-profile.d.ts +53 -0
- package/dist/codecs/agent-profile.d.ts.map +1 -0
- package/dist/codecs/agent-profile.js +176 -0
- package/dist/codecs/agent-profile.js.map +1 -0
- package/dist/codecs/capability.d.ts +71 -0
- package/dist/codecs/capability.d.ts.map +1 -0
- package/dist/codecs/capability.js +363 -0
- package/dist/codecs/capability.js.map +1 -0
- package/dist/codecs/index.d.ts +5 -0
- package/dist/codecs/index.d.ts.map +1 -0
- package/dist/codecs/index.js +3 -0
- package/dist/codecs/index.js.map +1 -0
- package/dist/codecs/prompt-stack.d.ts +18 -0
- package/dist/codecs/prompt-stack.d.ts.map +1 -0
- package/dist/codecs/prompt-stack.js +623 -0
- package/dist/codecs/prompt-stack.js.map +1 -0
- package/dist/command-contribution/index.d.ts +21 -0
- package/dist/command-contribution/index.d.ts.map +1 -0
- package/dist/command-contribution/index.js +14 -0
- package/dist/command-contribution/index.js.map +1 -0
- package/dist/compile-cycle.d.ts +26 -0
- package/dist/compile-cycle.d.ts.map +1 -0
- package/dist/compile-cycle.js +16 -0
- package/dist/compile-cycle.js.map +1 -0
- package/dist/compiler.d.ts +22 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +737 -0
- package/dist/compiler.js.map +1 -0
- package/dist/context-diff-history.d.ts +69 -0
- package/dist/context-diff-history.d.ts.map +1 -0
- package/dist/context-diff-history.js +107 -0
- package/dist/context-diff-history.js.map +1 -0
- package/dist/context-diff-snapshot.d.ts +19 -0
- package/dist/context-diff-snapshot.d.ts.map +1 -0
- package/dist/context-diff-snapshot.js +146 -0
- package/dist/context-diff-snapshot.js.map +1 -0
- package/dist/context-diff.d.ts +70 -0
- package/dist/context-diff.d.ts.map +1 -0
- package/dist/context-diff.js +259 -0
- package/dist/context-diff.js.map +1 -0
- package/dist/extension-registry.d.ts +25 -0
- package/dist/extension-registry.d.ts.map +1 -0
- package/dist/extension-registry.js +9 -0
- package/dist/extension-registry.js.map +1 -0
- package/dist/forge-command.d.ts +10 -0
- package/dist/forge-command.d.ts.map +1 -0
- package/dist/forge-command.js +106 -0
- package/dist/forge-command.js.map +1 -0
- package/dist/forge-config.d.ts +9 -0
- package/dist/forge-config.d.ts.map +1 -0
- package/dist/forge-config.js +15 -0
- package/dist/forge-config.js.map +1 -0
- package/dist/forge-extensions.d.ts +28 -0
- package/dist/forge-extensions.d.ts.map +1 -0
- package/dist/forge-extensions.js +198 -0
- package/dist/forge-extensions.js.map +1 -0
- package/dist/forge-v1/analyzer.d.ts +3 -0
- package/dist/forge-v1/analyzer.d.ts.map +1 -0
- package/dist/forge-v1/analyzer.js +50 -0
- package/dist/forge-v1/analyzer.js.map +1 -0
- package/dist/forge-v1/index.d.ts +6 -0
- package/dist/forge-v1/index.d.ts.map +1 -0
- package/dist/forge-v1/index.js +13 -0
- package/dist/forge-v1/index.js.map +1 -0
- package/dist/forge-v1/parser.d.ts +3 -0
- package/dist/forge-v1/parser.d.ts.map +1 -0
- package/dist/forge-v1/parser.js +186 -0
- package/dist/forge-v1/parser.js.map +1 -0
- package/dist/forge-v1/renderer.d.ts +9 -0
- package/dist/forge-v1/renderer.d.ts.map +1 -0
- package/dist/forge-v1/renderer.js +181 -0
- package/dist/forge-v1/renderer.js.map +1 -0
- package/dist/forge-v1/types.d.ts +87 -0
- package/dist/forge-v1/types.d.ts.map +1 -0
- package/dist/forge-v1/types.js +4 -0
- package/dist/forge-v1/types.js.map +1 -0
- package/dist/host-compatibility.d.ts +13 -0
- package/dist/host-compatibility.d.ts.map +1 -0
- package/dist/host-compatibility.js +41 -0
- package/dist/host-compatibility.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +183 -0
- package/dist/index.js.map +1 -0
- package/dist/json-fingerprint.d.ts +11 -0
- package/dist/json-fingerprint.d.ts.map +1 -0
- package/dist/json-fingerprint.js +66 -0
- package/dist/json-fingerprint.js.map +1 -0
- package/dist/lifecycle.d.ts +46 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +330 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/loader.d.ts +21 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +58 -0
- package/dist/loader.js.map +1 -0
- package/dist/macro-engine.d.ts +18 -0
- package/dist/macro-engine.d.ts.map +1 -0
- package/dist/macro-engine.js +29 -0
- package/dist/macro-engine.js.map +1 -0
- package/dist/payload-capture.d.ts +31 -0
- package/dist/payload-capture.d.ts.map +1 -0
- package/dist/payload-capture.js +253 -0
- package/dist/payload-capture.js.map +1 -0
- package/dist/payload-command.d.ts +12 -0
- package/dist/payload-command.d.ts.map +1 -0
- package/dist/payload-command.js +197 -0
- package/dist/payload-command.js.map +1 -0
- package/dist/payload-state.d.ts +20 -0
- package/dist/payload-state.d.ts.map +1 -0
- package/dist/payload-state.js +20 -0
- package/dist/payload-state.js.map +1 -0
- package/dist/policy.d.ts +7 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +41 -0
- package/dist/policy.js.map +1 -0
- package/dist/preset-command.d.ts +19 -0
- package/dist/preset-command.d.ts.map +1 -0
- package/dist/preset-command.js +261 -0
- package/dist/preset-command.js.map +1 -0
- package/dist/preview-inspection.d.ts +68 -0
- package/dist/preview-inspection.d.ts.map +1 -0
- package/dist/preview-inspection.js +293 -0
- package/dist/preview-inspection.js.map +1 -0
- package/dist/preview-text.d.ts +5 -0
- package/dist/preview-text.d.ts.map +1 -0
- package/dist/preview-text.js +27 -0
- package/dist/preview-text.js.map +1 -0
- package/dist/preview.d.ts +32 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +272 -0
- package/dist/preview.js.map +1 -0
- package/dist/profile-command.d.ts +17 -0
- package/dist/profile-command.d.ts.map +1 -0
- package/dist/profile-command.js +385 -0
- package/dist/profile-command.js.map +1 -0
- package/dist/profile-service.d.ts +107 -0
- package/dist/profile-service.d.ts.map +1 -0
- package/dist/profile-service.js +248 -0
- package/dist/profile-service.js.map +1 -0
- package/dist/prompt-analysis.d.ts +24 -0
- package/dist/prompt-analysis.d.ts.map +1 -0
- package/dist/prompt-analysis.js +84 -0
- package/dist/prompt-analysis.js.map +1 -0
- package/dist/prompt-cache-warning.d.ts +23 -0
- package/dist/prompt-cache-warning.d.ts.map +1 -0
- package/dist/prompt-cache-warning.js +74 -0
- package/dist/prompt-cache-warning.js.map +1 -0
- package/dist/prompt-runtime.d.ts +19 -0
- package/dist/prompt-runtime.d.ts.map +1 -0
- package/dist/prompt-runtime.js +34 -0
- package/dist/prompt-runtime.js.map +1 -0
- package/dist/regex.d.ts +19 -0
- package/dist/regex.d.ts.map +1 -0
- package/dist/regex.js +507 -0
- package/dist/regex.js.map +1 -0
- package/dist/render-helpers.d.ts +38 -0
- package/dist/render-helpers.d.ts.map +1 -0
- package/dist/render-helpers.js +85 -0
- package/dist/render-helpers.js.map +1 -0
- package/dist/repositories/agent-profile.d.ts +36 -0
- package/dist/repositories/agent-profile.d.ts.map +1 -0
- package/dist/repositories/agent-profile.js +153 -0
- package/dist/repositories/agent-profile.js.map +1 -0
- package/dist/repositories/capability.d.ts +53 -0
- package/dist/repositories/capability.d.ts.map +1 -0
- package/dist/repositories/capability.js +294 -0
- package/dist/repositories/capability.js.map +1 -0
- package/dist/repositories/index.d.ts +3 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +3 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/repositories/prompt-stack.d.ts +57 -0
- package/dist/repositories/prompt-stack.d.ts.map +1 -0
- package/dist/repositories/prompt-stack.js +175 -0
- package/dist/repositories/prompt-stack.js.map +1 -0
- 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/capability-runtime.d.ts +95 -0
- package/dist/runtime/capability-runtime.d.ts.map +1 -0
- package/dist/runtime/capability-runtime.js +991 -0
- package/dist/runtime/capability-runtime.js.map +1 -0
- package/dist/runtime/profile-runtime.d.ts +14 -0
- package/dist/runtime/profile-runtime.d.ts.map +1 -0
- package/dist/runtime/profile-runtime.js +56 -0
- package/dist/runtime/profile-runtime.js.map +1 -0
- package/dist/runtime/prompt-stack-runtime.d.ts +27 -0
- package/dist/runtime/prompt-stack-runtime.d.ts.map +1 -0
- package/dist/runtime/prompt-stack-runtime.js +149 -0
- package/dist/runtime/prompt-stack-runtime.js.map +1 -0
- package/dist/runtime/tool-policy-runtime.d.ts +25 -0
- package/dist/runtime/tool-policy-runtime.d.ts.map +1 -0
- package/dist/runtime/tool-policy-runtime.js +386 -0
- package/dist/runtime/tool-policy-runtime.js.map +1 -0
- package/dist/runtime/web-editor-runtime.d.ts +11 -0
- package/dist/runtime/web-editor-runtime.d.ts.map +1 -0
- package/dist/runtime/web-editor-runtime.js +141 -0
- package/dist/runtime/web-editor-runtime.js.map +1 -0
- package/dist/session-adapter.d.ts +30 -0
- package/dist/session-adapter.d.ts.map +1 -0
- package/dist/session-adapter.js +167 -0
- package/dist/session-adapter.js.map +1 -0
- package/dist/session-state.d.ts +23 -0
- package/dist/session-state.d.ts.map +1 -0
- package/dist/session-state.js +44 -0
- package/dist/session-state.js.map +1 -0
- package/dist/session-usage.d.ts +65 -0
- package/dist/session-usage.d.ts.map +1 -0
- package/dist/session-usage.js +134 -0
- package/dist/session-usage.js.map +1 -0
- package/dist/slot-renderers.d.ts +38 -0
- package/dist/slot-renderers.d.ts.map +1 -0
- package/dist/slot-renderers.js +285 -0
- package/dist/slot-renderers.js.map +1 -0
- package/dist/stack-migration.d.ts +35 -0
- package/dist/stack-migration.d.ts.map +1 -0
- package/dist/stack-migration.js +123 -0
- package/dist/stack-migration.js.map +1 -0
- package/dist/status-text.d.ts +6 -0
- package/dist/status-text.d.ts.map +1 -0
- package/dist/status-text.js +11 -0
- package/dist/status-text.js.map +1 -0
- package/dist/storage.d.ts +24 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +94 -0
- package/dist/storage.js.map +1 -0
- package/dist/subagent/fingerprints.d.ts +12 -0
- package/dist/subagent/fingerprints.d.ts.map +1 -0
- package/dist/subagent/fingerprints.js +17 -0
- package/dist/subagent/fingerprints.js.map +1 -0
- package/dist/subagent/host-port.d.ts +296 -0
- package/dist/subagent/host-port.d.ts.map +1 -0
- package/dist/subagent/host-port.js +560 -0
- package/dist/subagent/host-port.js.map +1 -0
- package/dist/subagent/index.d.ts +16 -0
- package/dist/subagent/index.d.ts.map +1 -0
- package/dist/subagent/index.js +15 -0
- package/dist/subagent/index.js.map +1 -0
- package/dist/subagent-host.d.ts +125 -0
- package/dist/subagent-host.d.ts.map +1 -0
- package/dist/subagent-host.js +327 -0
- package/dist/subagent-host.js.map +1 -0
- package/dist/template-render.d.ts +18 -0
- package/dist/template-render.d.ts.map +1 -0
- package/dist/template-render.js +232 -0
- package/dist/template-render.js.map +1 -0
- package/dist/types.d.ts +213 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/ui-contribution/contrib-port.d.ts +170 -0
- package/dist/ui-contribution/contrib-port.d.ts.map +1 -0
- package/dist/ui-contribution/contrib-port.js +640 -0
- package/dist/ui-contribution/contrib-port.js.map +1 -0
- package/dist/ui-contribution/index.d.ts +3 -0
- package/dist/ui-contribution/index.d.ts.map +1 -0
- package/dist/ui-contribution/index.js +2 -0
- package/dist/ui-contribution/index.js.map +1 -0
- package/dist/web-editor/client-script.d.ts +2 -0
- package/dist/web-editor/client-script.d.ts.map +1 -0
- package/dist/web-editor/client-script.generated.d.ts +2 -0
- package/dist/web-editor/client-script.generated.d.ts.map +1 -0
- package/dist/web-editor/client-script.generated.js +3 -0
- package/dist/web-editor/client-script.generated.js.map +1 -0
- package/dist/web-editor/client-script.js +2 -0
- package/dist/web-editor/client-script.js.map +1 -0
- 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/contrib-service.d.ts +41 -0
- package/dist/web-editor/contrib-service.d.ts.map +1 -0
- package/dist/web-editor/contrib-service.js +174 -0
- package/dist/web-editor/contrib-service.js.map +1 -0
- package/dist/web-editor/index.d.ts +3 -0
- package/dist/web-editor/index.d.ts.map +1 -0
- package/dist/web-editor/index.js +2 -0
- package/dist/web-editor/index.js.map +1 -0
- package/dist/web-editor/line-diff.d.ts +28 -0
- package/dist/web-editor/line-diff.d.ts.map +1 -0
- package/dist/web-editor/line-diff.js +216 -0
- package/dist/web-editor/line-diff.js.map +1 -0
- package/dist/web-editor/page.d.ts +4 -0
- package/dist/web-editor/page.d.ts.map +1 -0
- package/dist/web-editor/page.js +26 -0
- package/dist/web-editor/page.js.map +1 -0
- package/dist/web-editor/schema-form.d.ts +63 -0
- package/dist/web-editor/schema-form.d.ts.map +1 -0
- package/dist/web-editor/schema-form.js +213 -0
- package/dist/web-editor/schema-form.js.map +1 -0
- package/dist/web-editor/server.d.ts +4 -0
- package/dist/web-editor/server.d.ts.map +1 -0
- package/dist/web-editor/server.js +637 -0
- package/dist/web-editor/server.js.map +1 -0
- package/dist/web-editor/styles.d.ts +2 -0
- package/dist/web-editor/styles.d.ts.map +1 -0
- package/dist/web-editor/styles.js +1744 -0
- package/dist/web-editor/styles.js.map +1 -0
- package/dist/web-editor/types.d.ts +304 -0
- package/dist/web-editor/types.d.ts.map +1 -0
- package/dist/web-editor/types.js +2 -0
- package/dist/web-editor/types.js.map +1 -0
- package/dist/web-host.d.ts +56 -0
- package/dist/web-host.d.ts.map +1 -0
- package/dist/web-host.js +750 -0
- package/dist/web-host.js.map +1 -0
- package/dist/workspace.d.ts +85 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +409 -0
- package/dist/workspace.js.map +1 -0
- package/docs/README.md +49 -0
- package/docs/concepts/agent-profiles.md +62 -0
- package/docs/concepts/prompt-stacks.md +99 -0
- package/docs/design/0.5.1-plan.md +237 -0
- package/docs/design/README.md +37 -0
- package/docs/design/architecture-0.5.md +254 -0
- package/docs/design/archive/0.5-full-proposal/0.5-consumer-audit.md +62 -0
- package/docs/design/archive/0.5-full-proposal/0.5-inventory.md +208 -0
- package/docs/design/archive/0.5-full-proposal/0.5-phase0-decision-drafts.md +237 -0
- package/docs/design/archive/0.5-full-proposal/README.md +12 -0
- package/docs/design/archive/0.5-full-proposal/architecture-0.5.md +423 -0
- package/docs/design/archive/0.5-full-proposal/host-discovery-spike.md +103 -0
- package/docs/design/archive/0.5-full-proposal/template-language-spike.md +156 -0
- package/docs/design/archive/2026-09-12-system-update-design.md +229 -0
- package/docs/design/context-diff-plan.md +78 -0
- package/docs/design/decision-template.md +33 -0
- package/docs/design/pi-forge-system-update-design-notes.md +157 -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/architecture-rules.md +148 -0
- package/docs/development/complexity-review.md +86 -0
- package/docs/development/release.md +59 -0
- package/docs/development/roadmap.md +117 -0
- package/docs/development/scoped-global-profiles-stacks.md +325 -0
- package/docs/development/setup.md +99 -0
- package/docs/getting-started.md +96 -0
- package/docs/guides/custom-macros-and-slots.md +69 -0
- package/docs/guides/debugging.md +39 -0
- package/docs/guides/delegation.md +105 -0
- package/docs/guides/migrating-to-0.5.md +136 -0
- package/docs/guides/pi-1-compatibility.md +160 -0
- package/docs/guides/use-cases.md +67 -0
- package/docs/guides/web-editor.md +161 -0
- package/docs/reference/active-state.md +77 -0
- package/docs/reference/capabilities.md +288 -0
- package/docs/reference/commands.md +89 -0
- package/docs/reference/configuration.md +70 -0
- package/docs/reference/features.md +305 -0
- package/docs/reference/macros-and-slots.md +103 -0
- package/docs/reference/provider-support.md +67 -0
- package/docs/reference/public-api.md +133 -0
- package/docs/reference/session-cache.md +112 -0
- package/docs/reference/stack-schema.md +243 -0
- package/docs/reference/subagent-host-port.md +57 -0
- package/docs/reference/ui-contribution-port.md +51 -0
- package/docs/zh-CN/README.md +41 -0
- package/docs/zh-CN/concepts/agent-profiles.md +48 -0
- package/docs/zh-CN/concepts/prompt-stacks.md +48 -0
- package/docs/zh-CN/getting-started.md +82 -0
- package/docs/zh-CN/guides/delegation.md +76 -0
- package/docs/zh-CN/guides/migrating-to-0.5.md +121 -0
- package/docs/zh-CN/guides/pi-1-compatibility.md +158 -0
- package/docs/zh-CN/guides/web-editor.md +134 -0
- package/docs/zh-CN/reference/capabilities.md +288 -0
- package/docs/zh-CN/reference/commands.md +89 -0
- package/docs/zh-CN/reference/provider-support.md +67 -0
- package/docs/zh-CN/reference/session-cache.md +112 -0
- package/examples/capabilities/review.json +12 -0
- package/examples/capabilities/write-tools.json +15 -0
- package/examples/custom-system-status-extension/index.ts +144 -0
- package/examples/custom-system-status-extension/prompt-stack.json +40 -0
- package/examples/default-prompt-stack.json +125 -0
- package/examples/fake-assistant-direct-output-prompt-stack.json +48 -0
- package/examples/hack-prompt-stack.json +118 -0
- package/examples/minimal-prompt-stack.json +40 -0
- package/examples/read-first-worker-prompt-stack.json +49 -0
- package/examples/validation-issues-prompt-stack.json +38 -0
- package/package.json +114 -4
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { MAX_CAPABILITY_BINDINGS } from "../capabilities.js";
|
|
3
|
+
import { applyResourcePolicy, hasResourcePolicy } from "../policy.js";
|
|
4
|
+
import { validateRegexConfig } from "../regex.js";
|
|
5
|
+
import { isValidToolName } from "./capability.js";
|
|
6
|
+
import { isValidResourceId, parseResourceSelector } from "../resource-identity.js";
|
|
7
|
+
import { SUPPORTED_SLOTS } from "../types.js";
|
|
8
|
+
import { validateCapabilityBinding } from "./capability.js";
|
|
9
|
+
const VALID_ROLES = new Set(["system", "user", "assistant", "custom"]);
|
|
10
|
+
const VALID_CHAT_HISTORY_TOOL_MODES = new Set(["keep", "drop"]);
|
|
11
|
+
/**
|
|
12
|
+
* Parse, normalize, and validate a preset from its serialized source.
|
|
13
|
+
* This is the single entry point for turning stack JSON text into a
|
|
14
|
+
* LoadedPromptStack; loaders only add file-system concerns on top.
|
|
15
|
+
*/
|
|
16
|
+
export function parsePromptStack(source, filePath, scope) {
|
|
17
|
+
const diagnostics = [];
|
|
18
|
+
let raw;
|
|
19
|
+
try {
|
|
20
|
+
raw = JSON.parse(source);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return createPromptStackFault(filePath, scope, `Failed to parse JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
24
|
+
}
|
|
25
|
+
diagnostics.push(...validateRawPromptStackShape(raw, scope));
|
|
26
|
+
const stack = normalizeStack(raw, filePath, diagnostics);
|
|
27
|
+
diagnostics.push(...validatePromptStack(stack, scope));
|
|
28
|
+
if (basename(filePath) === "default.json"
|
|
29
|
+
&& isPlainObject(raw)
|
|
30
|
+
&& !Object.prototype.hasOwnProperty.call(raw, "autoActivate")) {
|
|
31
|
+
diagnostics.push({
|
|
32
|
+
level: "warning",
|
|
33
|
+
message: 'default.json no longer auto-activates by filename; set "autoActivate": true to keep auto-activating this stack.',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// validateRawPromptStackShape runs over the raw input and validatePromptStack
|
|
37
|
+
// re-runs shape validation over the normalized stack; fields such as
|
|
38
|
+
// defaults.* and context.* pass through normalization unchanged, so collapse
|
|
39
|
+
// exact duplicates before surfacing diagnostics.
|
|
40
|
+
return { filePath, scope, key: { scope, id: stack.id }, stack, diagnostics: dedupeDiagnostics(diagnostics) };
|
|
41
|
+
}
|
|
42
|
+
function dedupeDiagnostics(diagnostics) {
|
|
43
|
+
const seen = new Set();
|
|
44
|
+
const result = [];
|
|
45
|
+
for (const diagnostic of diagnostics) {
|
|
46
|
+
const key = `${diagnostic.level}\0${diagnostic.message}\0${diagnostic.itemId ?? ""}`;
|
|
47
|
+
if (seen.has(key))
|
|
48
|
+
continue;
|
|
49
|
+
seen.add(key);
|
|
50
|
+
result.push(diagnostic);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
/** Build a fail-closed LoadedPromptStack when the source cannot be read or parsed. */
|
|
55
|
+
export function createPromptStackFault(filePath, scope, message) {
|
|
56
|
+
return {
|
|
57
|
+
filePath,
|
|
58
|
+
scope,
|
|
59
|
+
key: { scope, id: basename(filePath, ".json") },
|
|
60
|
+
stack: fallbackStack(filePath),
|
|
61
|
+
diagnostics: [{ level: "error", message }],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Single canonical serializer for presets. Every writer (web host,
|
|
66
|
+
* repository, migration tooling) must go through this function so serialized
|
|
67
|
+
* output stays identical across all write paths.
|
|
68
|
+
*/
|
|
69
|
+
export function serializePromptStack(stack) {
|
|
70
|
+
return `${JSON.stringify(stack, null, 2)}\n`;
|
|
71
|
+
}
|
|
72
|
+
function fallbackStack(filePath) {
|
|
73
|
+
return {
|
|
74
|
+
schemaVersion: 1,
|
|
75
|
+
type: "pi-forge.prompt-stack",
|
|
76
|
+
id: basename(filePath, ".json"),
|
|
77
|
+
name: basename(filePath),
|
|
78
|
+
items: [],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function normalizeStack(raw, filePath, diagnostics) {
|
|
82
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
83
|
+
diagnostics.push({ level: "error", message: "Preset root must be a JSON object." });
|
|
84
|
+
return fallbackStack(filePath);
|
|
85
|
+
}
|
|
86
|
+
const obj = raw;
|
|
87
|
+
const rawId = typeof obj.id === "string" && obj.id.trim() ? obj.id.trim() : undefined;
|
|
88
|
+
const id = rawId && isValidResourceId(rawId) ? rawId : basename(filePath, ".json");
|
|
89
|
+
if (rawId && !isValidResourceId(rawId)) {
|
|
90
|
+
diagnostics.push({
|
|
91
|
+
level: "error",
|
|
92
|
+
message: `Preset id ${rawId} must start with a letter or number and contain only letters, numbers, dots, underscores, and hyphens; falling back to ${id}.`,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
let schemaVersion = 1;
|
|
96
|
+
if (obj.schemaVersion === 2) {
|
|
97
|
+
schemaVersion = 2;
|
|
98
|
+
}
|
|
99
|
+
else if (obj.schemaVersion !== undefined && obj.schemaVersion !== 1) {
|
|
100
|
+
diagnostics.push({ level: "warning", message: `Unsupported schemaVersion; assuming 1.` });
|
|
101
|
+
}
|
|
102
|
+
const items = Array.isArray(obj.items) ? obj.items.map((item, index) => normalizeItem(item, index, diagnostics)) : [];
|
|
103
|
+
if (!Array.isArray(obj.items)) {
|
|
104
|
+
diagnostics.push({ level: "error", message: "Preset must contain an items array." });
|
|
105
|
+
}
|
|
106
|
+
if (isPlainObject(obj.state) && Object.keys(obj.state).length > 0) {
|
|
107
|
+
diagnostics.push({
|
|
108
|
+
level: "info",
|
|
109
|
+
message: "state is no longer supported and was ignored; use stack.variables and template interpolation instead.",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (obj.instructionModes !== undefined) {
|
|
113
|
+
diagnostics.push({ level: "error", message: "Preset instructionModes is no longer supported; rename it to capabilities." });
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
schemaVersion,
|
|
117
|
+
type: obj.type === "pi-forge.prompt-stack" ? "pi-forge.prompt-stack" : undefined,
|
|
118
|
+
id,
|
|
119
|
+
name: typeof obj.name === "string" ? obj.name : undefined,
|
|
120
|
+
description: typeof obj.description === "string" ? obj.description : undefined,
|
|
121
|
+
autoActivate: typeof obj.autoActivate === "boolean" ? obj.autoActivate : undefined,
|
|
122
|
+
mode: obj.mode === "append" || obj.mode === "prepend" || obj.mode === "replace" ? obj.mode : undefined,
|
|
123
|
+
defaults: isPlainObject(obj.defaults) ? obj.defaults : undefined,
|
|
124
|
+
context: isPlainObject(obj.context) ? obj.context : undefined,
|
|
125
|
+
tools: normalizeResourcePolicy(obj.tools, "tools", diagnostics, true),
|
|
126
|
+
skills: normalizeResourcePolicy(obj.skills, "skills", diagnostics),
|
|
127
|
+
variables: schemaVersion === 1 ? normalizeStringRecord(obj.variables) : undefined,
|
|
128
|
+
parameters: schemaVersion === 2 ? normalizeParameterRecord(obj.parameters, diagnostics) : undefined,
|
|
129
|
+
regex: normalizeRegexConfig(obj.regex, diagnostics),
|
|
130
|
+
capabilities: normalizeCapabilities(obj.capabilities),
|
|
131
|
+
items,
|
|
132
|
+
import: isPlainObject(obj.import) ? obj.import : undefined,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function normalizeCapabilities(value) {
|
|
136
|
+
if (value === undefined)
|
|
137
|
+
return undefined;
|
|
138
|
+
if (!Array.isArray(value))
|
|
139
|
+
return undefined;
|
|
140
|
+
return value.map((binding) => {
|
|
141
|
+
if (!isPlainObject(binding))
|
|
142
|
+
return binding;
|
|
143
|
+
const normalized = { ...binding };
|
|
144
|
+
if (isPlainObject(binding.overrides)) {
|
|
145
|
+
const overrides = { ...binding.overrides };
|
|
146
|
+
if (isPlainObject(binding.overrides.tools)) {
|
|
147
|
+
const tools = { ...binding.overrides.tools };
|
|
148
|
+
if (Array.isArray(binding.overrides.tools.add))
|
|
149
|
+
tools.add = [...binding.overrides.tools.add];
|
|
150
|
+
if (Array.isArray(binding.overrides.tools.remove))
|
|
151
|
+
tools.remove = [...binding.overrides.tools.remove];
|
|
152
|
+
overrides.tools = tools;
|
|
153
|
+
}
|
|
154
|
+
normalized.overrides = overrides;
|
|
155
|
+
}
|
|
156
|
+
return normalized;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function normalizeItem(raw, index, diagnostics) {
|
|
160
|
+
const fallbackId = `item-${index + 1}`;
|
|
161
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
162
|
+
diagnostics.push({ level: "error", message: `Item ${index + 1} must be an object.`, itemId: fallbackId });
|
|
163
|
+
return { kind: "block", id: fallbackId, enabled: false, content: "" };
|
|
164
|
+
}
|
|
165
|
+
const obj = raw;
|
|
166
|
+
const kind = obj.kind === "slot" ? "slot" : "block";
|
|
167
|
+
const id = normalizeId(obj.id, fallbackId);
|
|
168
|
+
const base = {
|
|
169
|
+
kind,
|
|
170
|
+
id,
|
|
171
|
+
name: typeof obj.name === "string" ? obj.name : undefined,
|
|
172
|
+
enabled: typeof obj.enabled === "boolean" ? obj.enabled : undefined,
|
|
173
|
+
role: VALID_ROLES.has(obj.role) ? obj.role : undefined,
|
|
174
|
+
tags: Array.isArray(obj.tags) ? obj.tags.filter((tag) => typeof tag === "string") : undefined,
|
|
175
|
+
source: isPlainObject(obj.source) ? obj.source : undefined,
|
|
176
|
+
};
|
|
177
|
+
if (kind === "slot") {
|
|
178
|
+
return {
|
|
179
|
+
...base,
|
|
180
|
+
kind: "slot",
|
|
181
|
+
slot: typeof obj.slot === "string" ? obj.slot : "",
|
|
182
|
+
options: isPlainObject(obj.options) ? obj.options : undefined,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
...base,
|
|
187
|
+
kind: "block",
|
|
188
|
+
content: typeof obj.content === "string" ? obj.content : "",
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export function validatePromptStack(stack, scope) {
|
|
192
|
+
const diagnostics = validateRawPromptStackShape(stack, scope);
|
|
193
|
+
const ids = new Set();
|
|
194
|
+
let chatHistoryCount = 0;
|
|
195
|
+
if (!stack.id.trim())
|
|
196
|
+
diagnostics.push({ level: "error", message: "Preset id must not be empty." });
|
|
197
|
+
let seenNonSystemItem = false;
|
|
198
|
+
for (const item of stack.items) {
|
|
199
|
+
if (ids.has(item.id))
|
|
200
|
+
diagnostics.push({ level: "error", message: `Duplicate item id: ${item.id}`, itemId: item.id });
|
|
201
|
+
ids.add(item.id);
|
|
202
|
+
if (item.role && !VALID_ROLES.has(item.role)) {
|
|
203
|
+
diagnostics.push({ level: "error", message: `Invalid role: ${item.role}`, itemId: item.id });
|
|
204
|
+
}
|
|
205
|
+
if (item.enabled !== false) {
|
|
206
|
+
if (item.role === "system") {
|
|
207
|
+
if (seenNonSystemItem) {
|
|
208
|
+
diagnostics.push({
|
|
209
|
+
level: "warning",
|
|
210
|
+
message: "System item appears after non-system items; item position across the system/message channels has no effect on compilation. Use a user-role item for in-conversation injection.",
|
|
211
|
+
itemId: item.id,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else if (item.role === "user" || item.role === "assistant" || item.role === "custom") {
|
|
216
|
+
seenNonSystemItem = true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (item.kind === "slot") {
|
|
220
|
+
if (!SUPPORTED_SLOTS.has(item.slot)) {
|
|
221
|
+
diagnostics.push({ level: "warning", message: `Unsupported slot: ${item.slot}`, itemId: item.id });
|
|
222
|
+
}
|
|
223
|
+
if (item.enabled !== false && item.slot === "chat-history")
|
|
224
|
+
chatHistoryCount++;
|
|
225
|
+
if (item.slot === "chat-history")
|
|
226
|
+
validateChatHistoryOptions(item, diagnostics);
|
|
227
|
+
}
|
|
228
|
+
if (item.kind === "block" && item.role !== "system" && item.enabled !== false && !item.role) {
|
|
229
|
+
diagnostics.push({ level: "warning", message: "Enabled block has no role and will be ignored.", itemId: item.id });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (chatHistoryCount === 0) {
|
|
233
|
+
diagnostics.push({
|
|
234
|
+
level: "warning",
|
|
235
|
+
message: "No enabled chat-history slot found; Pi chat context will be appended at the end.",
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
else if (chatHistoryCount > 1 && !stack.context?.allowDuplicateChatHistory) {
|
|
239
|
+
diagnostics.push({
|
|
240
|
+
level: "warning",
|
|
241
|
+
message: "Multiple enabled chat-history slots found; only the first will be expanded unless context.allowDuplicateChatHistory is true.",
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
diagnostics.push(...validateResourcePolicy(stack.tools, "tools"));
|
|
245
|
+
diagnostics.push(...validateToolInitialPolicy(stack.tools));
|
|
246
|
+
diagnostics.push(...validateResourcePolicy(stack.skills, "skills"));
|
|
247
|
+
const hasSkillPolicy = hasResourcePolicy(stack.skills);
|
|
248
|
+
if (hasSkillPolicy) {
|
|
249
|
+
diagnostics.push({
|
|
250
|
+
level: "info",
|
|
251
|
+
message: "skills policy only filters model-visible skills rendered by pi-forge skills slots; it does not disable explicit skill invocation and is not a security boundary.",
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if ((stack.mode === "append" || stack.mode === "prepend") && hasSkillPolicy) {
|
|
255
|
+
diagnostics.push({
|
|
256
|
+
level: "warning",
|
|
257
|
+
message: "skills policy only filters pi-forge skills slots. Use mode \"replace\" if you need the base Pi prompt to omit filtered skills.",
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
diagnostics.push(...validateRegexConfig(stack.regex));
|
|
261
|
+
return diagnostics;
|
|
262
|
+
}
|
|
263
|
+
function validateRawPromptStackShape(raw, scope) {
|
|
264
|
+
const diagnostics = [];
|
|
265
|
+
if (!isPlainObject(raw))
|
|
266
|
+
return diagnostics;
|
|
267
|
+
if (typeof raw.id !== "string" || !raw.id.trim()) {
|
|
268
|
+
diagnostics.push({ level: "error", message: "Preset id must be a non-empty string." });
|
|
269
|
+
}
|
|
270
|
+
if (raw.type !== undefined && raw.type !== "pi-forge.prompt-stack") {
|
|
271
|
+
diagnostics.push({ level: "error", message: 'Preset type must be "pi-forge.prompt-stack" when provided by the legacy schema.' });
|
|
272
|
+
}
|
|
273
|
+
validateOptionalString(raw, "name", "Preset name", diagnostics);
|
|
274
|
+
validateOptionalString(raw, "description", "Preset description", diagnostics);
|
|
275
|
+
validateOptionalBoolean(raw, "autoActivate", "Preset autoActivate", diagnostics);
|
|
276
|
+
if (raw.mode !== undefined && raw.mode !== "append" && raw.mode !== "prepend" && raw.mode !== "replace") {
|
|
277
|
+
diagnostics.push({ level: "error", message: 'Preset mode must be "append", "prepend", or "replace" when provided.' });
|
|
278
|
+
}
|
|
279
|
+
validateRawDefaults(raw.defaults, diagnostics);
|
|
280
|
+
validateRawContext(raw.context, diagnostics);
|
|
281
|
+
validateRawVariables(raw.variables, diagnostics);
|
|
282
|
+
validateRawParameters(raw, diagnostics);
|
|
283
|
+
if (raw.instructionModes !== undefined) {
|
|
284
|
+
diagnostics.push({ level: "error", message: "Preset instructionModes is no longer supported; rename it to capabilities." });
|
|
285
|
+
}
|
|
286
|
+
validateRawCapabilities(raw.capabilities, diagnostics, scope);
|
|
287
|
+
if (!Array.isArray(raw.items))
|
|
288
|
+
return diagnostics;
|
|
289
|
+
for (const [index, item] of raw.items.entries()) {
|
|
290
|
+
if (!isPlainObject(item))
|
|
291
|
+
continue;
|
|
292
|
+
const fallbackId = `item-${index + 1}`;
|
|
293
|
+
const itemId = typeof item.id === "string" && item.id.trim() ? item.id.trim() : fallbackId;
|
|
294
|
+
if (item.kind !== "block" && item.kind !== "slot") {
|
|
295
|
+
diagnostics.push({ level: "error", message: `Item ${index + 1} kind must be "block" or "slot".`, itemId });
|
|
296
|
+
}
|
|
297
|
+
if (typeof item.id !== "string" || !item.id.trim()) {
|
|
298
|
+
diagnostics.push({ level: "error", message: `Item ${index + 1} id must be a non-empty string.`, itemId });
|
|
299
|
+
}
|
|
300
|
+
if (item.name !== undefined && typeof item.name !== "string") {
|
|
301
|
+
diagnostics.push({ level: "error", message: "Item name must be a string when provided.", itemId });
|
|
302
|
+
}
|
|
303
|
+
if (item.enabled !== undefined && typeof item.enabled !== "boolean") {
|
|
304
|
+
diagnostics.push({ level: "error", message: "Item enabled must be a boolean when provided.", itemId });
|
|
305
|
+
}
|
|
306
|
+
if (item.role !== undefined && !VALID_ROLES.has(item.role)) {
|
|
307
|
+
diagnostics.push({ level: "error", message: `Invalid role: ${String(item.role)}`, itemId });
|
|
308
|
+
}
|
|
309
|
+
if (item.tags !== undefined && (!Array.isArray(item.tags) || item.tags.some((tag) => typeof tag !== "string"))) {
|
|
310
|
+
diagnostics.push({ level: "error", message: "Item tags must be an array of strings when provided.", itemId });
|
|
311
|
+
}
|
|
312
|
+
if (item.source !== undefined && !isPlainObject(item.source)) {
|
|
313
|
+
diagnostics.push({ level: "error", message: "Item source must be an object when provided.", itemId });
|
|
314
|
+
}
|
|
315
|
+
if (item.kind === "block" && typeof item.content !== "string") {
|
|
316
|
+
diagnostics.push({ level: "error", message: "Block content must be a string.", itemId });
|
|
317
|
+
}
|
|
318
|
+
if (item.kind === "slot") {
|
|
319
|
+
if (typeof item.slot !== "string" || !item.slot.trim()) {
|
|
320
|
+
diagnostics.push({ level: "error", message: "Slot name must be a non-empty string.", itemId });
|
|
321
|
+
}
|
|
322
|
+
if (item.options !== undefined && !isPlainObject(item.options)) {
|
|
323
|
+
diagnostics.push({ level: "error", message: "Slot options must be an object when provided.", itemId });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return diagnostics;
|
|
328
|
+
}
|
|
329
|
+
function validateRawCapabilities(value, diagnostics, scope) {
|
|
330
|
+
if (value === undefined)
|
|
331
|
+
return;
|
|
332
|
+
if (!Array.isArray(value)) {
|
|
333
|
+
diagnostics.push({ level: "error", message: "Preset capabilities must be an array when provided." });
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (value.length > MAX_CAPABILITY_BINDINGS) {
|
|
337
|
+
diagnostics.push({
|
|
338
|
+
level: "error",
|
|
339
|
+
message: `Preset capabilities cannot exceed ${MAX_CAPABILITY_BINDINGS} bindings (got ${value.length}).`,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
const ownerScope = scope ?? "project";
|
|
343
|
+
for (const item of value) {
|
|
344
|
+
const itemDiags = validateCapabilityBinding(item, ownerScope);
|
|
345
|
+
for (const diag of itemDiags) {
|
|
346
|
+
diagnostics.push({ level: diag.level, message: diag.message });
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const seenIds = new Set();
|
|
350
|
+
for (const item of value) {
|
|
351
|
+
if (!isPlainObject(item))
|
|
352
|
+
continue;
|
|
353
|
+
if (typeof item.ref !== "string" || !item.ref.trim())
|
|
354
|
+
continue;
|
|
355
|
+
const parsed = parseResourceSelector(item.ref);
|
|
356
|
+
const effectiveId = typeof item.id === "string" && item.id.trim()
|
|
357
|
+
? item.id.trim()
|
|
358
|
+
: (parsed.ok ? parsed.selector.id : "");
|
|
359
|
+
if (!effectiveId)
|
|
360
|
+
continue;
|
|
361
|
+
if (seenIds.has(effectiveId)) {
|
|
362
|
+
diagnostics.push({
|
|
363
|
+
level: "error",
|
|
364
|
+
message: `Duplicate capability binding id: ${effectiveId}`,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
seenIds.add(effectiveId);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
function validateRawDefaults(value, diagnostics) {
|
|
371
|
+
if (value === undefined)
|
|
372
|
+
return;
|
|
373
|
+
if (!isPlainObject(value)) {
|
|
374
|
+
diagnostics.push({ level: "error", message: "Preset defaults must be an object when provided." });
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
validateOptionalBoolean(value, "syntheticMessagesVisible", "defaults.syntheticMessagesVisible", diagnostics);
|
|
378
|
+
if (value.unresolvedMacroPolicy !== undefined && !["warn", "keep", "error"].includes(String(value.unresolvedMacroPolicy))) {
|
|
379
|
+
diagnostics.push({ level: "error", message: 'defaults.unresolvedMacroPolicy must be "warn", "keep", or "error" when provided.' });
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function validateRawContext(value, diagnostics) {
|
|
383
|
+
if (value === undefined)
|
|
384
|
+
return;
|
|
385
|
+
if (!isPlainObject(value)) {
|
|
386
|
+
diagnostics.push({ level: "error", message: "Preset context must be an object when provided." });
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
validateOptionalBoolean(value, "allowDuplicateChatHistory", "context.allowDuplicateChatHistory", diagnostics);
|
|
390
|
+
validateOptionalBoolean(value, "mergeConsecutiveRoles", "context.mergeConsecutiveRoles", diagnostics);
|
|
391
|
+
validateOptionalString(value, "mergeSeparator", "context.mergeSeparator", diagnostics);
|
|
392
|
+
}
|
|
393
|
+
function validateRawVariables(value, diagnostics) {
|
|
394
|
+
if (value === undefined)
|
|
395
|
+
return;
|
|
396
|
+
if (!isPlainObject(value)) {
|
|
397
|
+
diagnostics.push({ level: "error", message: "Preset variables must be an object when provided." });
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
for (const [name, variable] of Object.entries(value)) {
|
|
401
|
+
if (typeof variable !== "string") {
|
|
402
|
+
diagnostics.push({ level: "error", message: `Preset variable ${name} must be a string.` });
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function validateRawParameters(raw, diagnostics) {
|
|
407
|
+
const schemaVersion = raw.schemaVersion === 2 ? 2 : 1;
|
|
408
|
+
if (schemaVersion === 2 && raw.variables !== undefined) {
|
|
409
|
+
diagnostics.push({ level: "warning", message: "schemaVersion 2 presets use parameters; variables is ignored." });
|
|
410
|
+
}
|
|
411
|
+
if (schemaVersion === 1 && raw.parameters !== undefined) {
|
|
412
|
+
diagnostics.push({ level: "warning", message: "schemaVersion 1 presets use variables; parameters is ignored." });
|
|
413
|
+
}
|
|
414
|
+
if (raw.parameters === undefined)
|
|
415
|
+
return;
|
|
416
|
+
if (!isPlainObject(raw.parameters)) {
|
|
417
|
+
diagnostics.push({ level: "error", message: "Preset parameters must be an object when provided." });
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
for (const [name, value] of Object.entries(raw.parameters)) {
|
|
421
|
+
if (!isPromptVariableValue(value)) {
|
|
422
|
+
diagnostics.push({ level: "error", message: `Preset parameter ${name} must be a JSON-compatible value.` });
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function validateOptionalString(value, key, label, diagnostics) {
|
|
427
|
+
if (value[key] !== undefined && typeof value[key] !== "string") {
|
|
428
|
+
diagnostics.push({ level: "error", message: `${label} must be a string when provided.` });
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
function validateOptionalBoolean(value, key, label, diagnostics) {
|
|
432
|
+
if (value[key] !== undefined && typeof value[key] !== "boolean") {
|
|
433
|
+
diagnostics.push({ level: "error", message: `${label} must be a boolean when provided.` });
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
function validateChatHistoryOptions(item, diagnostics) {
|
|
437
|
+
const options = item.options;
|
|
438
|
+
if (!options)
|
|
439
|
+
return;
|
|
440
|
+
for (const key of ["includeLastUserMessage", "stripAssistantThinking", "includeSummaries"]) {
|
|
441
|
+
const value = options[key];
|
|
442
|
+
if (value !== undefined && typeof value !== "boolean") {
|
|
443
|
+
diagnostics.push({ level: "warning", message: `chat-history option ${key} should be a boolean.`, itemId: item.id });
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (options.roles !== undefined && !isStringArray(options.roles)) {
|
|
447
|
+
diagnostics.push({ level: "error", message: "chat-history option roles must be an array of strings.", itemId: item.id });
|
|
448
|
+
}
|
|
449
|
+
if (options.toolMode !== undefined && (typeof options.toolMode !== "string" || !VALID_CHAT_HISTORY_TOOL_MODES.has(options.toolMode))) {
|
|
450
|
+
diagnostics.push({ level: "error", message: 'chat-history option toolMode must be "keep" or "drop".', itemId: item.id });
|
|
451
|
+
}
|
|
452
|
+
for (const key of ["maxMessages", "maxChars"]) {
|
|
453
|
+
const value = options[key];
|
|
454
|
+
if (value !== undefined && !isPositiveInteger(value)) {
|
|
455
|
+
diagnostics.push({ level: "error", message: `chat-history option ${key} must be a positive integer.`, itemId: item.id });
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function normalizeId(value, fallback) {
|
|
460
|
+
if (typeof value === "string" && value.trim())
|
|
461
|
+
return value.trim();
|
|
462
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
463
|
+
return String(value);
|
|
464
|
+
return fallback;
|
|
465
|
+
}
|
|
466
|
+
function isStringArray(value) {
|
|
467
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
468
|
+
}
|
|
469
|
+
function isPositiveInteger(value) {
|
|
470
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
471
|
+
}
|
|
472
|
+
function isPlainObject(value) {
|
|
473
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
474
|
+
}
|
|
475
|
+
function normalizeParameterRecord(value, diagnostics) {
|
|
476
|
+
if (!isPlainObject(value))
|
|
477
|
+
return undefined;
|
|
478
|
+
const result = {};
|
|
479
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
480
|
+
if (isPromptVariableValue(raw))
|
|
481
|
+
result[key] = raw;
|
|
482
|
+
}
|
|
483
|
+
return result;
|
|
484
|
+
}
|
|
485
|
+
function isPromptVariableValue(value) {
|
|
486
|
+
if (value === null)
|
|
487
|
+
return true;
|
|
488
|
+
const type = typeof value;
|
|
489
|
+
if (type === "string" || type === "boolean")
|
|
490
|
+
return true;
|
|
491
|
+
if (type === "number")
|
|
492
|
+
return Number.isFinite(value);
|
|
493
|
+
if (Array.isArray(value))
|
|
494
|
+
return value.every(isPromptVariableValue);
|
|
495
|
+
if (!value || typeof value !== "object")
|
|
496
|
+
return false;
|
|
497
|
+
return Object.values(value).every(isPromptVariableValue);
|
|
498
|
+
}
|
|
499
|
+
function normalizeStringRecord(value) {
|
|
500
|
+
if (!isPlainObject(value))
|
|
501
|
+
return undefined;
|
|
502
|
+
const result = {};
|
|
503
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
504
|
+
if (typeof raw === "string")
|
|
505
|
+
result[key] = raw;
|
|
506
|
+
}
|
|
507
|
+
return result;
|
|
508
|
+
}
|
|
509
|
+
function normalizeResourcePolicy(value, label, diagnostics, includeInitial = false) {
|
|
510
|
+
if (value === undefined)
|
|
511
|
+
return undefined;
|
|
512
|
+
if (!isPlainObject(value)) {
|
|
513
|
+
diagnostics.push({ level: "error", message: `${label} policy must be an object when provided.` });
|
|
514
|
+
return undefined;
|
|
515
|
+
}
|
|
516
|
+
const allow = normalizePolicyPatterns(value.allow, `${label}.allow`, diagnostics);
|
|
517
|
+
const deny = normalizePolicyPatterns(value.deny, `${label}.deny`, diagnostics);
|
|
518
|
+
const initial = includeInitial ? normalizeInitialToolNames(value.initial, `${label}.initial`, diagnostics) : undefined;
|
|
519
|
+
const normalizedInitial = initial === undefined ? {} : { initial };
|
|
520
|
+
if (allow && deny) {
|
|
521
|
+
diagnostics.push({ level: "error", message: `${label} policy must use either allow or deny, not both.` });
|
|
522
|
+
return { allow, ...normalizedInitial };
|
|
523
|
+
}
|
|
524
|
+
if (allow)
|
|
525
|
+
return { allow, ...normalizedInitial };
|
|
526
|
+
if (deny)
|
|
527
|
+
return { deny, ...normalizedInitial };
|
|
528
|
+
return normalizedInitial;
|
|
529
|
+
}
|
|
530
|
+
function normalizeInitialToolNames(value, label, diagnostics) {
|
|
531
|
+
if (value === undefined)
|
|
532
|
+
return undefined;
|
|
533
|
+
if (!Array.isArray(value)) {
|
|
534
|
+
diagnostics.push({ level: "error", message: `${label} must be an array of concrete tool names when provided.` });
|
|
535
|
+
return undefined;
|
|
536
|
+
}
|
|
537
|
+
const names = [];
|
|
538
|
+
const seen = new Set();
|
|
539
|
+
for (const [index, item] of value.entries()) {
|
|
540
|
+
if (typeof item !== "string" || !isValidToolName(item.trim())) {
|
|
541
|
+
diagnostics.push({ level: "error", message: `${label}[${index}] must be a valid concrete tool name (wildcards are not allowed).` });
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
const name = item.trim();
|
|
545
|
+
if (seen.has(name)) {
|
|
546
|
+
diagnostics.push({ level: "warning", message: `Duplicate ${label} tool name: ${name}.` });
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
seen.add(name);
|
|
550
|
+
names.push(name);
|
|
551
|
+
}
|
|
552
|
+
return names;
|
|
553
|
+
}
|
|
554
|
+
function normalizePolicyPatterns(value, label, diagnostics) {
|
|
555
|
+
if (value === undefined)
|
|
556
|
+
return undefined;
|
|
557
|
+
if (!Array.isArray(value)) {
|
|
558
|
+
diagnostics.push({ level: "error", message: `${label} must be an array of strings when provided.` });
|
|
559
|
+
return undefined;
|
|
560
|
+
}
|
|
561
|
+
const patterns = [];
|
|
562
|
+
for (const [index, item] of value.entries()) {
|
|
563
|
+
if (typeof item !== "string" || !item.trim()) {
|
|
564
|
+
diagnostics.push({ level: "error", message: `${label}[${index}] must be a non-empty string.` });
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
patterns.push(item.trim());
|
|
568
|
+
}
|
|
569
|
+
return patterns.length > 0 ? patterns : undefined;
|
|
570
|
+
}
|
|
571
|
+
function validateResourcePolicy(policy, label) {
|
|
572
|
+
const diagnostics = [];
|
|
573
|
+
if ((policy?.allow?.length ?? 0) > 0 && (policy?.deny?.length ?? 0) > 0) {
|
|
574
|
+
diagnostics.push({ level: "error", message: `${label} policy must use either allow or deny, not both.` });
|
|
575
|
+
}
|
|
576
|
+
for (const key of ["allow", "deny"]) {
|
|
577
|
+
const values = policy?.[key];
|
|
578
|
+
if (!values)
|
|
579
|
+
continue;
|
|
580
|
+
const seen = new Set();
|
|
581
|
+
for (const value of values) {
|
|
582
|
+
if (seen.has(value)) {
|
|
583
|
+
diagnostics.push({ level: "warning", message: `Duplicate ${label}.${key} pattern: ${value}.` });
|
|
584
|
+
}
|
|
585
|
+
seen.add(value);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
return diagnostics;
|
|
589
|
+
}
|
|
590
|
+
function validateToolInitialPolicy(policy) {
|
|
591
|
+
const diagnostics = [];
|
|
592
|
+
if (policy?.initial === undefined)
|
|
593
|
+
return diagnostics;
|
|
594
|
+
if (!Array.isArray(policy.initial)) {
|
|
595
|
+
diagnostics.push({ level: "error", message: "tools.initial must be an array of concrete tool names when provided." });
|
|
596
|
+
return diagnostics;
|
|
597
|
+
}
|
|
598
|
+
const seen = new Set();
|
|
599
|
+
for (const [index, name] of policy.initial.entries()) {
|
|
600
|
+
if (typeof name !== "string" || !isValidToolName(name)) {
|
|
601
|
+
diagnostics.push({ level: "error", message: `tools.initial[${index}] must be a valid concrete tool name (wildcards are not allowed).` });
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
if (seen.has(name)) {
|
|
605
|
+
diagnostics.push({ level: "warning", message: `Duplicate tools.initial tool name: ${name}.` });
|
|
606
|
+
}
|
|
607
|
+
seen.add(name);
|
|
608
|
+
if (hasResourcePolicy(policy) && applyResourcePolicy([name], policy).length === 0) {
|
|
609
|
+
diagnostics.push({ level: "error", message: `tools.initial tool "${name}" is blocked by the allow/deny policy.` });
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
return diagnostics;
|
|
613
|
+
}
|
|
614
|
+
function normalizeRegexConfig(value, diagnostics) {
|
|
615
|
+
if (value === undefined)
|
|
616
|
+
return undefined;
|
|
617
|
+
if (!isPlainObject(value)) {
|
|
618
|
+
diagnostics.push({ level: "warning", message: "regex must be an object when provided." });
|
|
619
|
+
return undefined;
|
|
620
|
+
}
|
|
621
|
+
return value;
|
|
622
|
+
}
|
|
623
|
+
//# sourceMappingURL=prompt-stack.js.map
|