@ai-agent-forge/agent-forge 0.87.0 → 0.88.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 +56 -0
- package/README.md +2 -2
- package/bundled-plugins/agent-loop-policy/agent-forge.json +19 -0
- package/bundled-plugins/agent-loop-policy/dist/entry.d.ts +28 -0
- package/bundled-plugins/agent-loop-policy/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/agent-loop-policy/dist/entry.js +69 -0
- package/bundled-plugins/agent-loop-policy/dist/entry.js.map +1 -0
- package/bundled-plugins/agent-loop-policy/dist/loop-guard.d.ts +199 -0
- package/bundled-plugins/agent-loop-policy/dist/loop-guard.d.ts.map +1 -0
- package/bundled-plugins/agent-loop-policy/dist/loop-guard.js +208 -0
- package/bundled-plugins/agent-loop-policy/dist/loop-guard.js.map +1 -0
- package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.d.ts +17 -0
- package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.d.ts.map +1 -0
- package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.js +18 -0
- package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.js.map +1 -0
- package/bundled-plugins/agent-loop-policy/plugin.json +7 -0
- package/bundled-plugins/coding-tools/agent-forge.json +19 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/bash.d.ts +5 -44
- package/bundled-plugins/coding-tools/dist/bash.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/bash.js +15 -119
- package/bundled-plugins/coding-tools/dist/bash.js.map +1 -0
- package/bundled-plugins/coding-tools/dist/capability.d.ts +25 -0
- package/bundled-plugins/coding-tools/dist/capability.d.ts.map +1 -0
- package/bundled-plugins/coding-tools/dist/capability.js +98 -0
- package/bundled-plugins/coding-tools/dist/capability.js.map +1 -0
- package/bundled-plugins/coding-tools/dist/config.d.ts +8 -0
- package/bundled-plugins/coding-tools/dist/config.d.ts.map +1 -0
- package/bundled-plugins/coding-tools/dist/config.js +8 -0
- package/bundled-plugins/coding-tools/dist/config.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/edit.d.ts +3 -3
- package/bundled-plugins/coding-tools/dist/edit.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/edit.js +12 -10
- package/bundled-plugins/coding-tools/dist/edit.js.map +1 -0
- package/bundled-plugins/coding-tools/dist/entry.d.ts +14 -0
- package/bundled-plugins/coding-tools/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/coding-tools/dist/entry.js +23 -0
- package/bundled-plugins/coding-tools/dist/entry.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/find.d.ts +4 -4
- package/bundled-plugins/coding-tools/dist/find.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/find.js +10 -8
- package/bundled-plugins/coding-tools/dist/find.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/grep.d.ts +3 -3
- package/bundled-plugins/coding-tools/dist/grep.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/grep.js +10 -8
- package/bundled-plugins/coding-tools/dist/grep.js.map +1 -0
- package/bundled-plugins/coding-tools/dist/index.d.ts +17 -0
- package/bundled-plugins/coding-tools/dist/index.d.ts.map +1 -0
- package/bundled-plugins/coding-tools/dist/index.js +17 -0
- package/bundled-plugins/coding-tools/dist/index.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.d.ts +3 -3
- package/bundled-plugins/coding-tools/dist/ls.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.js +8 -6
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.js.map +1 -1
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/powershell.d.ts +2 -1
- package/bundled-plugins/coding-tools/dist/powershell.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/powershell.js +6 -3
- package/bundled-plugins/coding-tools/dist/powershell.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/read.d.ts +3 -3
- package/bundled-plugins/coding-tools/dist/read.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/read.js +15 -13
- package/bundled-plugins/coding-tools/dist/read.js.map +1 -0
- package/bundled-plugins/coding-tools/dist/types.d.ts +74 -0
- package/bundled-plugins/coding-tools/dist/types.d.ts.map +1 -0
- package/bundled-plugins/coding-tools/dist/types.js +28 -0
- package/bundled-plugins/coding-tools/dist/types.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/write.d.ts +2 -2
- package/bundled-plugins/coding-tools/dist/write.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/write.js +11 -9
- package/bundled-plugins/coding-tools/dist/write.js.map +1 -0
- package/bundled-plugins/coding-tools/plugin.json +10 -0
- package/bundled-plugins/compaction-policy/agent-forge.json +19 -0
- package/bundled-plugins/compaction-policy/dist/branch-summary-policy.d.ts +6 -0
- package/bundled-plugins/compaction-policy/dist/branch-summary-policy.d.ts.map +1 -0
- package/bundled-plugins/compaction-policy/dist/branch-summary-policy.js +19 -0
- package/bundled-plugins/compaction-policy/dist/branch-summary-policy.js.map +1 -0
- package/bundled-plugins/compaction-policy/dist/compaction-policy.d.ts +6 -0
- package/bundled-plugins/compaction-policy/dist/compaction-policy.d.ts.map +1 -0
- package/bundled-plugins/compaction-policy/dist/compaction-policy.js +38 -0
- package/bundled-plugins/compaction-policy/dist/compaction-policy.js.map +1 -0
- package/bundled-plugins/compaction-policy/dist/entry.d.ts +13 -0
- package/bundled-plugins/compaction-policy/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/compaction-policy/dist/entry.js +23 -0
- package/bundled-plugins/compaction-policy/dist/entry.js.map +1 -0
- package/bundled-plugins/compaction-policy/plugin.json +10 -0
- package/bundled-plugins/mcp-http/dist/index.d.ts +8 -0
- package/bundled-plugins/mcp-http/dist/index.d.ts.map +1 -0
- package/bundled-plugins/mcp-http/dist/index.js +8 -0
- package/bundled-plugins/mcp-http/dist/index.js.map +1 -0
- package/bundled-plugins/mcp-http/dist/mcp-http.d.ts.map +1 -0
- package/{dist/plugins → bundled-plugins/mcp-http/dist}/mcp-http.js +1 -1
- package/bundled-plugins/mcp-http/dist/mcp-http.js.map +1 -0
- package/bundled-plugins/overflow-policy/agent-forge.json +19 -0
- package/bundled-plugins/overflow-policy/dist/entry.d.ts +16 -0
- package/bundled-plugins/overflow-policy/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/overflow-policy/dist/entry.js +35 -0
- package/bundled-plugins/overflow-policy/dist/entry.js.map +1 -0
- package/bundled-plugins/overflow-policy/plugin.json +10 -0
- package/bundled-plugins/provider-failover/agent-forge.json +19 -0
- package/bundled-plugins/provider-failover/dist/entry.d.ts +8 -0
- package/bundled-plugins/provider-failover/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/provider-failover/dist/entry.js +8 -0
- package/bundled-plugins/provider-failover/dist/entry.js.map +1 -0
- package/bundled-plugins/provider-failover/dist/provider-failover.d.ts +122 -0
- package/bundled-plugins/provider-failover/dist/provider-failover.d.ts.map +1 -0
- package/{dist/core/extensions → bundled-plugins/provider-failover/dist}/provider-failover.js +149 -61
- package/bundled-plugins/provider-failover/dist/provider-failover.js.map +1 -0
- package/bundled-plugins/provider-failover/plugin.json +7 -0
- package/bundled-plugins/retry-policy/agent-forge.json +19 -0
- package/bundled-plugins/retry-policy/dist/entry.d.ts +16 -0
- package/bundled-plugins/retry-policy/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/retry-policy/dist/entry.js +34 -0
- package/bundled-plugins/retry-policy/dist/entry.js.map +1 -0
- package/bundled-plugins/retry-policy/plugin.json +10 -0
- package/dist/bundle/.build-manifest.json +105 -183
- package/dist/bundle/chunks/{anthropic-messages-ALDZBUKI.js → anthropic-messages-PLAKXR73.js} +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-A2WJWZFB.js → azure-openai-responses-OUWQ2AZD.js} +1 -1
- package/dist/bundle/chunks/{chunk-CIX3FSBK.js → chunk-A3JYRWB6.js} +1 -1
- package/dist/bundle/chunks/{chunk-SQFG22WN.js → chunk-AC2FIS4G.js} +1 -1
- package/dist/bundle/chunks/chunk-AQLNTW2B.js +664 -0
- package/dist/bundle/chunks/chunk-D3ARGZFR.js +13 -0
- package/dist/bundle/chunks/{chunk-YJCQVXW5.js → chunk-HTEVUY7F.js} +1 -1
- package/dist/bundle/chunks/{chunk-Y7HXTASS.js → chunk-HV64ASMT.js} +1 -1
- package/dist/bundle/chunks/chunk-LZOEQITZ.js +855 -0
- package/dist/bundle/chunks/{chunk-7ZY7IXZD.js → chunk-TRDNDS6A.js} +1 -1
- package/dist/bundle/chunks/chunk-Z72JWUZ4.js +4 -0
- package/dist/bundle/chunks/{google-generative-ai-NIB4WONV.js → google-generative-ai-DLII6DAT.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-DCPYUEUO.js → google-vertex-G7BZL7GM.js} +1 -1
- package/dist/bundle/chunks/image-resize-worker.js +3 -3
- package/dist/bundle/chunks/{mistral-conversations-OC6LA5XL.js → mistral-conversations-JXUK24ID.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-IO2X4Y7L.js → openai-codex-responses-5GSGFIPG.js} +1 -1
- package/dist/bundle/chunks/{openai-completions-XYQQHETU.js → openai-completions-EI2I6DTG.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-DLIRN3CI.js → openai-responses-AUJQ3NWT.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-E6RRYBO7.js → pi-messages-PWU2VJMR.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-WF6WRHP7.js +5 -0
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/client.js +1 -1
- package/dist/bundle/index.js +3 -3
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/capabilities/builtin.d.ts +1 -1
- package/dist/capabilities/builtin.d.ts.map +1 -1
- package/dist/capabilities/builtin.js +5 -0
- package/dist/capabilities/builtin.js.map +1 -1
- package/dist/cli/auth-check.d.ts.map +1 -1
- package/dist/cli/auth-check.js +14 -2
- package/dist/cli/auth-check.js.map +1 -1
- package/dist/cli/auth-command.d.ts.map +1 -1
- package/dist/cli/auth-command.js +1 -1
- package/dist/cli/auth-command.js.map +1 -1
- package/dist/cli/plugin-command.d.ts.map +1 -1
- package/dist/cli/plugin-command.js +17 -1
- package/dist/cli/plugin-command.js.map +1 -1
- package/dist/config.d.ts +2 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -6
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts +1 -1
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +1 -1
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-compaction.d.ts +6 -10
- package/dist/core/agent-session-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-compaction.js +21 -112
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-internal.d.ts +1 -7
- package/dist/core/agent-session-internal.d.ts.map +1 -1
- package/dist/core/agent-session-internal.js.map +1 -1
- package/dist/core/agent-session-loop.d.ts +4 -3
- package/dist/core/agent-session-loop.d.ts.map +1 -1
- package/dist/core/agent-session-loop.js +9 -6
- package/dist/core/agent-session-loop.js.map +1 -1
- package/dist/core/agent-session-retry.d.ts +1 -1
- package/dist/core/agent-session-retry.d.ts.map +1 -1
- package/dist/core/agent-session-retry.js +32 -4
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +30 -9
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session-tools.d.ts.map +1 -1
- package/dist/core/agent-session-tools.js +5 -1
- package/dist/core/agent-session-tools.js.map +1 -1
- package/dist/core/agent-session.d.ts +12 -33
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +61 -67
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/extensions/bootstrap-agent-loop.d.ts +23 -151
- package/dist/core/extensions/bootstrap-agent-loop.d.ts.map +1 -1
- package/dist/core/extensions/bootstrap-agent-loop.js +28 -290
- package/dist/core/extensions/bootstrap-agent-loop.js.map +1 -1
- package/dist/core/extensions/capability-runtime-types.d.ts +5 -3
- package/dist/core/extensions/capability-runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/capability-runtime-types.js.map +1 -1
- package/dist/core/extensions/capability-runtime.d.ts.map +1 -1
- package/dist/core/extensions/capability-runtime.js +42 -6
- package/dist/core/extensions/capability-runtime.js.map +1 -1
- package/dist/core/extensions/index.d.ts +12 -5
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +12 -5
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +65 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/facade/coding-agent-facade.d.ts +1 -7
- package/dist/core/facade/coding-agent-facade.d.ts.map +1 -1
- package/dist/core/facade/coding-agent-facade.js +0 -3
- package/dist/core/facade/coding-agent-facade.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/cli.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/cli.js +3 -1
- package/dist/core/i18n/locales/zh-cn/cli.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-core.js +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-core.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-extensions.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js +2 -4
- package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-errors.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-errors.js +3 -1
- package/dist/core/i18n/locales/zh-cn/core-errors.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/interactive-mode.js +2 -0
- package/dist/core/i18n/locales/zh-cn/interactive-mode.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/tui-components-selectors.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js +0 -2
- package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js.map +1 -1
- package/dist/core/model-config.d.ts +0 -1
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +9 -1
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +3 -3
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/provider-composer.d.ts +2 -2
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +7 -8
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/sdk.d.ts +18 -3
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +267 -76
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +9 -20
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +20 -54
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/bash-operations.d.ts +41 -0
- package/dist/core/tools/bash-operations.d.ts.map +1 -0
- package/dist/core/tools/bash-operations.js +113 -0
- package/dist/core/tools/bash-operations.js.map +1 -0
- package/dist/core/tools/index.d.ts +12 -36
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -117
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/readme-path.d.ts +3 -0
- package/dist/core/tools/readme-path.d.ts.map +1 -0
- package/dist/core/tools/readme-path.js +15 -0
- package/dist/core/tools/readme-path.js.map +1 -0
- package/dist/index.d.ts +3 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -39
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +3 -2
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +0 -2
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +2 -7
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +2 -6
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +6 -28
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +0 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +9 -25
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +0 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +23 -36
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +0 -8
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +0 -12
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +0 -9
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +0 -19
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/plugins/ecosystem/cli.d.ts.map +1 -1
- package/dist/plugins/ecosystem/cli.js +14 -2
- package/dist/plugins/ecosystem/cli.js.map +1 -1
- package/dist/plugins/ecosystem/node-npm-registry-source.d.ts +7 -2
- package/dist/plugins/ecosystem/node-npm-registry-source.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-npm-registry-source.js +64 -9
- package/dist/plugins/ecosystem/node-npm-registry-source.js.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-acquisition-host.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-acquisition-host.js +6 -0
- package/dist/plugins/ecosystem/node-plugin-acquisition-host.js.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts +9 -2
- package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-bootstrap.js +23 -0
- package/dist/plugins/ecosystem/node-plugin-bootstrap.js.map +1 -1
- package/dist/plugins/ecosystem/plugin-bootstrap.d.ts +9 -1
- package/dist/plugins/ecosystem/plugin-bootstrap.d.ts.map +1 -1
- package/dist/plugins/ecosystem/plugin-bootstrap.js +5 -0
- package/dist/plugins/ecosystem/plugin-bootstrap.js.map +1 -1
- package/dist/profiles/builtin-suites.d.ts +5 -1
- package/dist/profiles/builtin-suites.d.ts.map +1 -1
- package/dist/profiles/builtin-suites.js +6 -1
- package/dist/profiles/builtin-suites.js.map +1 -1
- package/dist/utils/photon.d.ts +2 -2
- package/dist/utils/photon.d.ts.map +1 -1
- package/dist/utils/photon.js +2 -2
- package/dist/utils/photon.js.map +1 -1
- package/docs/compaction.md +1 -3
- package/docs/docs.json +4 -0
- package/docs/index.md +1 -0
- package/docs/mcp.md +103 -0
- package/docs/models.md +14 -22
- package/docs/providers.md +0 -1
- package/docs/rpc.md +1 -26
- package/docs/sdk.md +4 -6
- package/docs/settings.md +9 -12
- package/docs/skills.md +1 -9
- package/docs/usage.md +1 -1
- package/examples/extensions/bash-spawn-hook/index.ts +7 -2
- package/examples/extensions/built-in-tool-renderer/index.ts +4 -2
- package/examples/extensions/minimal-mode/index.ts +2 -2
- package/examples/extensions/truncated-tool/index.ts +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/extensions/with-deps/plugin.json +1 -1
- package/examples/sdk/10-settings.ts +2 -4
- package/examples/sdk/12-full-control.ts +1 -2
- package/package.json +3 -4
- package/dist/bundle/chunks/chunk-6ZKDNZHA.js +0 -145
- package/dist/bundle/chunks/chunk-BFC2BDVJ.js +0 -13
- package/dist/bundle/chunks/chunk-MOHOLL3F.js +0 -1456
- package/dist/bundle/chunks/virtual-modules-KZ5DRH7Q.js +0 -2
- package/dist/core/extensions/bootstrap-branch-summary-policy.d.ts +0 -7
- package/dist/core/extensions/bootstrap-branch-summary-policy.d.ts.map +0 -1
- package/dist/core/extensions/bootstrap-branch-summary-policy.js +0 -28
- package/dist/core/extensions/bootstrap-branch-summary-policy.js.map +0 -1
- package/dist/core/extensions/bootstrap-compaction-policy.d.ts +0 -7
- package/dist/core/extensions/bootstrap-compaction-policy.d.ts.map +0 -1
- package/dist/core/extensions/bootstrap-compaction-policy.js +0 -82
- package/dist/core/extensions/bootstrap-compaction-policy.js.map +0 -1
- package/dist/core/extensions/bootstrap-overflow-policy.d.ts +0 -7
- package/dist/core/extensions/bootstrap-overflow-policy.d.ts.map +0 -1
- package/dist/core/extensions/bootstrap-overflow-policy.js +0 -30
- package/dist/core/extensions/bootstrap-overflow-policy.js.map +0 -1
- package/dist/core/extensions/bootstrap-retry-policy.d.ts +0 -7
- package/dist/core/extensions/bootstrap-retry-policy.d.ts.map +0 -1
- package/dist/core/extensions/bootstrap-retry-policy.js +0 -29
- package/dist/core/extensions/bootstrap-retry-policy.js.map +0 -1
- package/dist/core/extensions/bootstrap-tools.d.ts +0 -20
- package/dist/core/extensions/bootstrap-tools.d.ts.map +0 -1
- package/dist/core/extensions/bootstrap-tools.js +0 -36
- package/dist/core/extensions/bootstrap-tools.js.map +0 -1
- package/dist/core/extensions/microcompact.d.ts +0 -80
- package/dist/core/extensions/microcompact.d.ts.map +0 -1
- package/dist/core/extensions/microcompact.js +0 -134
- package/dist/core/extensions/microcompact.js.map +0 -1
- package/dist/core/extensions/provider-failover.d.ts +0 -106
- package/dist/core/extensions/provider-failover.d.ts.map +0 -1
- package/dist/core/extensions/provider-failover.js.map +0 -1
- package/dist/core/tools/bash.d.ts.map +0 -1
- package/dist/core/tools/bash.js.map +0 -1
- package/dist/core/tools/edit.d.ts.map +0 -1
- package/dist/core/tools/edit.js.map +0 -1
- package/dist/core/tools/find.d.ts.map +0 -1
- package/dist/core/tools/find.js.map +0 -1
- package/dist/core/tools/grep.d.ts.map +0 -1
- package/dist/core/tools/grep.js.map +0 -1
- package/dist/core/tools/ls.d.ts.map +0 -1
- package/dist/core/tools/powershell.d.ts.map +0 -1
- package/dist/core/tools/powershell.js.map +0 -1
- package/dist/core/tools/read.d.ts.map +0 -1
- package/dist/core/tools/read.js.map +0 -1
- package/dist/core/tools/write.d.ts.map +0 -1
- package/dist/core/tools/write.js.map +0 -1
- package/dist/plugins/mcp-http.d.ts.map +0 -1
- package/dist/plugins/mcp-http.js.map +0 -1
- package/dist/profile/child-facade.d.ts +0 -44
- package/dist/profile/child-facade.d.ts.map +0 -1
- package/dist/profile/child-facade.js +0 -56
- package/dist/profile/child-facade.js.map +0 -1
- package/dist/profile/dependency-wiring.d.ts +0 -48
- package/dist/profile/dependency-wiring.d.ts.map +0 -1
- package/dist/profile/dependency-wiring.js +0 -56
- package/dist/profile/dependency-wiring.js.map +0 -1
- package/dist/profile/domain-recovery.d.ts +0 -60
- package/dist/profile/domain-recovery.d.ts.map +0 -1
- package/dist/profile/domain-recovery.js +0 -94
- package/dist/profile/domain-recovery.js.map +0 -1
- package/dist/profile/first-roles.d.ts +0 -30
- package/dist/profile/first-roles.d.ts.map +0 -1
- package/dist/profile/first-roles.js +0 -83
- package/dist/profile/first-roles.js.map +0 -1
- package/dist/profile/goal-plugin.d.ts +0 -38
- package/dist/profile/goal-plugin.d.ts.map +0 -1
- package/dist/profile/goal-plugin.js +0 -132
- package/dist/profile/goal-plugin.js.map +0 -1
- package/dist/profile/plan-plugin.d.ts +0 -44
- package/dist/profile/plan-plugin.d.ts.map +0 -1
- package/dist/profile/plan-plugin.js +0 -157
- package/dist/profile/plan-plugin.js.map +0 -1
- package/dist/profile/policy-manifest.d.ts +0 -53
- package/dist/profile/policy-manifest.d.ts.map +0 -1
- package/dist/profile/policy-manifest.js +0 -53
- package/dist/profile/policy-manifest.js.map +0 -1
- package/dist/profile/role-assembly.d.ts +0 -47
- package/dist/profile/role-assembly.d.ts.map +0 -1
- package/dist/profile/role-assembly.js +0 -31
- package/dist/profile/role-assembly.js.map +0 -1
- package/dist/profile/role-catalog.d.ts +0 -43
- package/dist/profile/role-catalog.d.ts.map +0 -1
- package/dist/profile/role-catalog.js +0 -132
- package/dist/profile/role-catalog.js.map +0 -1
- package/dist/profile/role-orchestrator.d.ts +0 -123
- package/dist/profile/role-orchestrator.d.ts.map +0 -1
- package/dist/profile/role-orchestrator.js +0 -195
- package/dist/profile/role-orchestrator.js.map +0 -1
- package/dist/profile/role-runner.d.ts +0 -99
- package/dist/profile/role-runner.d.ts.map +0 -1
- package/dist/profile/role-runner.js +0 -79
- package/dist/profile/role-runner.js.map +0 -1
- package/dist/profile/root-facade.d.ts +0 -36
- package/dist/profile/root-facade.d.ts.map +0 -1
- package/dist/profile/root-facade.js +0 -49
- package/dist/profile/root-facade.js.map +0 -1
- package/dist/profile/skill-discovery-wiring.d.ts +0 -58
- package/dist/profile/skill-discovery-wiring.d.ts.map +0 -1
- package/dist/profile/skill-discovery-wiring.js +0 -80
- package/dist/profile/skill-discovery-wiring.js.map +0 -1
- package/dist/profile/state-store.d.ts +0 -62
- package/dist/profile/state-store.d.ts.map +0 -1
- package/dist/profile/state-store.js +0 -144
- package/dist/profile/state-store.js.map +0 -1
- package/dist/profile/todo-plugin.d.ts +0 -37
- package/dist/profile/todo-plugin.d.ts.map +0 -1
- package/dist/profile/todo-plugin.js +0 -137
- package/dist/profile/todo-plugin.js.map +0 -1
- package/dist/server/create-harness.d.ts +0 -26
- package/dist/server/create-harness.d.ts.map +0 -1
- package/dist/server/create-harness.js +0 -106
- package/dist/server/create-harness.js.map +0 -1
- /package/{dist/plugins → bundled-plugins/mcp-http/dist}/mcp-http.d.ts +0 -0
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { t } from "../core/i18n/index.js";
|
|
2
|
-
function planPayloadOf(record) {
|
|
3
|
-
const payload = record.payload;
|
|
4
|
-
if (payload !== null && typeof payload === "object" && !Array.isArray(payload)) {
|
|
5
|
-
return payload;
|
|
6
|
-
}
|
|
7
|
-
return undefined;
|
|
8
|
-
}
|
|
9
|
-
export function createPlanPlugin(options) {
|
|
10
|
-
const transitions = options.transitions;
|
|
11
|
-
const planHistory = (planId, owner) => transitions.history(planId).filter((record) => record.domain === "plan" && record.owner === owner);
|
|
12
|
-
const current = (planId, owner) => {
|
|
13
|
-
const state = transitions.currentStatus("plan", planId);
|
|
14
|
-
if (state === undefined || planHistory(planId, owner).length === 0)
|
|
15
|
-
return undefined;
|
|
16
|
-
return { status: state.status, revisionNo: state.revision };
|
|
17
|
-
};
|
|
18
|
-
const planGet = (planId, owner) => {
|
|
19
|
-
const state = current(planId, owner);
|
|
20
|
-
if (!state)
|
|
21
|
-
return undefined;
|
|
22
|
-
const history = planHistory(planId, owner);
|
|
23
|
-
// v8 ignore next -- 因果校验保证每条 plan 历史都以 fromStatus=null 的创建记录开始
|
|
24
|
-
const createPayload = planPayloadOf(history.find((record) => record.fromStatus === null) ?? {});
|
|
25
|
-
const lastLinked = [...history]
|
|
26
|
-
.reverse()
|
|
27
|
-
.map((record) => planPayloadOf(record)?.linkedRevision)
|
|
28
|
-
.find((revision) => typeof revision === "number");
|
|
29
|
-
const lastEvidence = [...history].reverse().find((record) => record.evidence.length > 0)?.evidence ?? [];
|
|
30
|
-
return {
|
|
31
|
-
planId,
|
|
32
|
-
owner,
|
|
33
|
-
title: createPayload?.title ?? planId,
|
|
34
|
-
branch: createPayload?.branch ?? "",
|
|
35
|
-
steps: createPayload?.steps ?? [],
|
|
36
|
-
status: state.status,
|
|
37
|
-
...(lastLinked === undefined ? {} : { revision: lastLinked }),
|
|
38
|
-
evidence: lastEvidence,
|
|
39
|
-
revisionNo: state.revisionNo,
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
/** A retried transition with an already-applied operationId returns the existing state instead of conflicting. */
|
|
43
|
-
const replayedPlan = (planId, owner, toStatus, operationId) => {
|
|
44
|
-
if (!operationId)
|
|
45
|
-
return undefined;
|
|
46
|
-
const applied = planHistory(planId, owner).some((record) => record.toStatus === toStatus && record.operationId === operationId);
|
|
47
|
-
return applied ? planGet(planId, owner) : undefined;
|
|
48
|
-
};
|
|
49
|
-
const transitionPlan = (planId, owner, fromStatus, toStatus, planOptions) => {
|
|
50
|
-
transitions.transition({
|
|
51
|
-
domain: "plan",
|
|
52
|
-
entityId: planId,
|
|
53
|
-
owner,
|
|
54
|
-
fromStatus,
|
|
55
|
-
toStatus,
|
|
56
|
-
operationId: planOptions.operationId ?? `${toStatus}:${planId}`,
|
|
57
|
-
evidence: planOptions.evidence,
|
|
58
|
-
payload: planOptions.payload,
|
|
59
|
-
});
|
|
60
|
-
return planGet(planId, owner);
|
|
61
|
-
};
|
|
62
|
-
return {
|
|
63
|
-
createPlan({ planId, owner, title, branch, steps }) {
|
|
64
|
-
if (title.trim().length === 0)
|
|
65
|
-
throw new Error(t("Plan title must be a non-empty string"));
|
|
66
|
-
if (branch.trim().length === 0)
|
|
67
|
-
throw new Error(t("Plan branch must be a non-empty string"));
|
|
68
|
-
if (steps.length === 0)
|
|
69
|
-
throw new Error(t("Plan requires at least one step"));
|
|
70
|
-
const stepIds = new Set();
|
|
71
|
-
for (const step of steps) {
|
|
72
|
-
if (typeof step.stepId !== "string" || step.stepId.trim().length === 0) {
|
|
73
|
-
throw new Error(t("Plan stepId must be a non-empty string"));
|
|
74
|
-
}
|
|
75
|
-
if (typeof step.title !== "string" || step.title.trim().length === 0) {
|
|
76
|
-
throw new Error(t("Plan step title must be a non-empty string"));
|
|
77
|
-
}
|
|
78
|
-
if (stepIds.has(step.stepId))
|
|
79
|
-
throw new Error(t("Duplicate plan stepId: {stepId}", { stepId: step.stepId }));
|
|
80
|
-
stepIds.add(step.stepId);
|
|
81
|
-
}
|
|
82
|
-
return transitionPlan(planId, owner, null, "draft", {
|
|
83
|
-
payload: { title, branch, steps: [...steps] },
|
|
84
|
-
operationId: `create:${planId}`,
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
activate(planId, owner, activateOptions) {
|
|
88
|
-
const replayed = replayedPlan(planId, owner, "active", activateOptions?.operationId);
|
|
89
|
-
if (replayed)
|
|
90
|
-
return replayed;
|
|
91
|
-
const plan = planGet(planId, owner);
|
|
92
|
-
if (plan?.status !== "draft") {
|
|
93
|
-
throw new Error(t("Plan {planId} must be in draft status to activate (current: {status})", {
|
|
94
|
-
planId,
|
|
95
|
-
status: plan?.status ?? "missing",
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
return transitionPlan(planId, owner, "draft", "active", { operationId: activateOptions?.operationId });
|
|
99
|
-
},
|
|
100
|
-
linkRevision(planId, owner, revision, linkOptions) {
|
|
101
|
-
const replayed = replayedPlan(planId, owner, "active", linkOptions?.operationId);
|
|
102
|
-
if (replayed)
|
|
103
|
-
return replayed;
|
|
104
|
-
const plan = planGet(planId, owner);
|
|
105
|
-
if (plan?.status !== "active") {
|
|
106
|
-
throw new Error(t("Plan {planId} must be active to link a revision (current: {status})", {
|
|
107
|
-
planId,
|
|
108
|
-
status: plan?.status ?? "missing",
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
if (!Number.isSafeInteger(revision) || revision < 1) {
|
|
112
|
-
throw new Error(t("Plan revision must be a positive safe integer, got {revision}", { revision }));
|
|
113
|
-
}
|
|
114
|
-
return transitionPlan(planId, owner, "active", "active", {
|
|
115
|
-
payload: { title: plan.title, branch: plan.branch, steps: plan.steps, linkedRevision: revision },
|
|
116
|
-
operationId: linkOptions?.operationId ?? `link:${planId}:${revision}`,
|
|
117
|
-
});
|
|
118
|
-
},
|
|
119
|
-
complete(planId, owner, evidence, completeOptions) {
|
|
120
|
-
const replayed = replayedPlan(planId, owner, "completed", completeOptions?.operationId);
|
|
121
|
-
if (replayed)
|
|
122
|
-
return replayed;
|
|
123
|
-
const plan = planGet(planId, owner);
|
|
124
|
-
if (plan?.status !== "active") {
|
|
125
|
-
throw new Error(t("Plan {planId} must be active to complete (current: {status})", {
|
|
126
|
-
planId,
|
|
127
|
-
status: plan?.status ?? "missing",
|
|
128
|
-
}));
|
|
129
|
-
}
|
|
130
|
-
if (evidence.length === 0)
|
|
131
|
-
throw new Error(t("Completing a plan requires at least one evidence reference"));
|
|
132
|
-
const target = completeOptions?.atRevision ?? plan.revision;
|
|
133
|
-
if (typeof target !== "number") {
|
|
134
|
-
throw new Error(t("Plan {planId} requires atRevision or a linked revision to complete", { planId }));
|
|
135
|
-
}
|
|
136
|
-
return transitionPlan(planId, owner, "active", "completed", {
|
|
137
|
-
evidence,
|
|
138
|
-
payload: { title: plan.title, branch: plan.branch, steps: plan.steps, linkedRevision: target },
|
|
139
|
-
operationId: completeOptions?.operationId,
|
|
140
|
-
});
|
|
141
|
-
},
|
|
142
|
-
discard(planId, owner) {
|
|
143
|
-
const plan = planGet(planId, owner);
|
|
144
|
-
if (!plan || plan.status === "completed" || plan.status === "discarded") {
|
|
145
|
-
throw new Error(t("Plan {planId} cannot be discarded from status {status}", {
|
|
146
|
-
planId,
|
|
147
|
-
status: plan?.status ?? "missing",
|
|
148
|
-
}));
|
|
149
|
-
}
|
|
150
|
-
return transitionPlan(planId, owner, plan.status, "discarded", {});
|
|
151
|
-
},
|
|
152
|
-
get(planId, owner) {
|
|
153
|
-
return planGet(planId, owner);
|
|
154
|
-
},
|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O,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE;gBAC3D,QAAQ;gBACR,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE;gBAC9F,WAAW,EAAE,eAAe,EAAE,WAAW;aACzC,CAAC,CAAC;QAAA,CACH;QACD,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE;YACtB,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACpC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;gBACzE,MAAM,IAAI,KAAK,CACd,CAAC,CAAC,wDAAwD,EAAE;oBAC3D,MAAM;oBACN,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,SAAS;iBACjC,CAAC,CACF,CAAC;YACH,CAAC;YACD,OAAO,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;QAAA,CACnE;QACD,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE;YAClB,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAAA,CAC9B;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Plan plugin (2.3c) — Plan semantics bound to a branch/revision over the\n * 2.3a transition store.\n *\n * Status graph: null → draft → active → completed, and draft/active →\n * discarded. A plan is created with its step list and bound to a code branch;\n * while active, `linkRevision` records plan progress against concrete\n * revisions, and `complete` requires evidence plus the final revision. The\n * plugin holds NO shadow state: status, revision, steps, branch, and the\n * latest linked revision are all derived from the transition history, so\n * recovery is exactly a store replay.\n */\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { t } from \"../core/i18n/index.ts\";\nimport type { TransitionEvidenceRefV1, TransitionStoreV1 } from \"./state-store.ts\";\n\nexport type PlanStatusV1 = \"draft\" | \"active\" | \"completed\" | \"discarded\";\n\nexport interface PlanStepV1 {\n\treadonly stepId: string;\n\treadonly title: string;\n}\n\nexport interface PlanV1 {\n\treadonly planId: string;\n\treadonly owner: string;\n\treadonly title: string;\n\treadonly branch: string;\n\treadonly steps: readonly PlanStepV1[];\n\treadonly status: PlanStatusV1;\n\t/** The latest revision explicitly linked while active (undefined before the first link). */\n\treadonly revision?: number;\n\treadonly evidence: readonly TransitionEvidenceRefV1[];\n\treadonly revisionNo: number;\n}\n\nexport interface PlanPluginV1 {\n\tcreatePlan(input: {\n\t\treadonly planId: string;\n\t\treadonly owner: string;\n\t\treadonly title: string;\n\t\treadonly branch: string;\n\t\treadonly steps: readonly PlanStepV1[];\n\t}): PlanV1;\n\tactivate(planId: string, owner: string, options?: { readonly operationId?: string }): PlanV1;\n\t/** Records plan progress against a concrete revision of the bound branch. */\n\tlinkRevision(planId: string, owner: string, revision: number, options?: { readonly operationId?: string }): PlanV1;\n\tcomplete(\n\t\tplanId: string,\n\t\towner: string,\n\t\tevidence: readonly TransitionEvidenceRefV1[],\n\t\toptions?: { readonly atRevision?: number; readonly operationId?: string },\n\t): PlanV1;\n\tdiscard(planId: string, owner: string): PlanV1;\n\tget(planId: string, owner: string): PlanV1 | undefined;\n}\n\ninterface PlanPayloadV1 {\n\treadonly title: string;\n\treadonly branch: string;\n\treadonly steps: readonly PlanStepV1[];\n\treadonly linkedRevision?: number;\n}\n\nfunction planPayloadOf(record: { readonly payload?: unknown }): Partial<PlanPayloadV1> | undefined {\n\tconst payload = record.payload;\n\tif (payload !== null && typeof payload === \"object\" && !Array.isArray(payload)) {\n\t\treturn payload as Partial<PlanPayloadV1>;\n\t}\n\treturn undefined;\n}\n\nexport function createPlanPlugin(options: { readonly transitions: TransitionStoreV1 }): PlanPluginV1 {\n\tconst transitions = options.transitions;\n\n\tconst planHistory = (planId: string, owner: string) =>\n\t\ttransitions.history(planId).filter((record) => record.domain === \"plan\" && record.owner === owner);\n\n\tconst current = (planId: string, owner: string): { status: PlanStatusV1; revisionNo: number } | undefined => {\n\t\tconst state = transitions.currentStatus(\"plan\", planId);\n\t\tif (state === undefined || planHistory(planId, owner).length === 0) return undefined;\n\t\treturn { status: state.status as PlanStatusV1, revisionNo: state.revision };\n\t};\n\n\tconst planGet = (planId: string, owner: string): PlanV1 | undefined => {\n\t\tconst state = current(planId, owner);\n\t\tif (!state) return undefined;\n\t\tconst history = planHistory(planId, owner);\n\t\t// v8 ignore next -- 因果校验保证每条 plan 历史都以 fromStatus=null 的创建记录开始\n\t\tconst createPayload = planPayloadOf(history.find((record) => record.fromStatus === null) ?? {});\n\t\tconst lastLinked = [...history]\n\t\t\t.reverse()\n\t\t\t.map((record) => planPayloadOf(record)?.linkedRevision)\n\t\t\t.find((revision): revision is number => typeof revision === \"number\");\n\t\tconst lastEvidence = [...history].reverse().find((record) => record.evidence.length > 0)?.evidence ?? [];\n\t\treturn {\n\t\t\tplanId,\n\t\t\towner,\n\t\t\ttitle: createPayload?.title ?? planId,\n\t\t\tbranch: createPayload?.branch ?? \"\",\n\t\t\tsteps: createPayload?.steps ?? [],\n\t\t\tstatus: state.status,\n\t\t\t...(lastLinked === undefined ? {} : { revision: lastLinked }),\n\t\t\tevidence: lastEvidence,\n\t\t\trevisionNo: state.revisionNo,\n\t\t};\n\t};\n\n\t/** A retried transition with an already-applied operationId returns the existing state instead of conflicting. */\n\tconst replayedPlan = (\n\t\tplanId: string,\n\t\towner: string,\n\t\ttoStatus: PlanStatusV1,\n\t\toperationId?: string,\n\t): PlanV1 | undefined => {\n\t\tif (!operationId) return undefined;\n\t\tconst applied = planHistory(planId, owner).some(\n\t\t\t(record) => record.toStatus === toStatus && record.operationId === operationId,\n\t\t);\n\t\treturn applied ? planGet(planId, owner) : undefined;\n\t};\n\n\tconst transitionPlan = (\n\t\tplanId: string,\n\t\towner: string,\n\t\tfromStatus: PlanStatusV1 | null,\n\t\ttoStatus: PlanStatusV1,\n\t\tplanOptions: {\n\t\t\treadonly evidence?: readonly TransitionEvidenceRefV1[];\n\t\t\treadonly payload?: PlanPayloadV1;\n\t\t\treadonly operationId?: string;\n\t\t},\n\t): PlanV1 => {\n\t\ttransitions.transition({\n\t\t\tdomain: \"plan\",\n\t\t\tentityId: planId,\n\t\t\towner,\n\t\t\tfromStatus,\n\t\t\ttoStatus,\n\t\t\toperationId: planOptions.operationId ?? `${toStatus}:${planId}`,\n\t\t\tevidence: planOptions.evidence,\n\t\t\tpayload: planOptions.payload as JsonValue | undefined,\n\t\t});\n\t\treturn planGet(planId, owner)!;\n\t};\n\n\treturn {\n\t\tcreatePlan({ planId, owner, title, branch, steps }) {\n\t\t\tif (title.trim().length === 0) throw new Error(t(\"Plan title must be a non-empty string\"));\n\t\t\tif (branch.trim().length === 0) throw new Error(t(\"Plan branch must be a non-empty string\"));\n\t\t\tif (steps.length === 0) throw new Error(t(\"Plan requires at least one step\"));\n\t\t\tconst stepIds = new Set<string>();\n\t\t\tfor (const step of steps) {\n\t\t\t\tif (typeof step.stepId !== \"string\" || step.stepId.trim().length === 0) {\n\t\t\t\t\tthrow new Error(t(\"Plan stepId must be a non-empty string\"));\n\t\t\t\t}\n\t\t\t\tif (typeof step.title !== \"string\" || step.title.trim().length === 0) {\n\t\t\t\t\tthrow new Error(t(\"Plan step title must be a non-empty string\"));\n\t\t\t\t}\n\t\t\t\tif (stepIds.has(step.stepId))\n\t\t\t\t\tthrow new Error(t(\"Duplicate plan stepId: {stepId}\", { stepId: step.stepId }));\n\t\t\t\tstepIds.add(step.stepId);\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, null, \"draft\", {\n\t\t\t\tpayload: { title, branch, steps: [...steps] },\n\t\t\t\toperationId: `create:${planId}`,\n\t\t\t});\n\t\t},\n\t\tactivate(planId, owner, activateOptions) {\n\t\t\tconst replayed = replayedPlan(planId, owner, \"active\", activateOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (plan?.status !== \"draft\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} must be in draft status to activate (current: {status})\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, \"draft\", \"active\", { operationId: activateOptions?.operationId });\n\t\t},\n\t\tlinkRevision(planId, owner, revision, linkOptions) {\n\t\t\tconst replayed = replayedPlan(planId, owner, \"active\", linkOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (plan?.status !== \"active\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} must be active to link a revision (current: {status})\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!Number.isSafeInteger(revision) || revision < 1) {\n\t\t\t\tthrow new Error(t(\"Plan revision must be a positive safe integer, got {revision}\", { revision }));\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, \"active\", \"active\", {\n\t\t\t\tpayload: { title: plan.title, branch: plan.branch, steps: plan.steps, linkedRevision: revision },\n\t\t\t\toperationId: linkOptions?.operationId ?? `link:${planId}:${revision}`,\n\t\t\t});\n\t\t},\n\t\tcomplete(planId, owner, evidence, completeOptions) {\n\t\t\tconst replayed = replayedPlan(planId, owner, \"completed\", completeOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (plan?.status !== \"active\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} must be active to complete (current: {status})\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (evidence.length === 0) throw new Error(t(\"Completing a plan requires at least one evidence reference\"));\n\t\t\tconst target = completeOptions?.atRevision ?? plan.revision;\n\t\t\tif (typeof target !== \"number\") {\n\t\t\t\tthrow new Error(t(\"Plan {planId} requires atRevision or a linked revision to complete\", { planId }));\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, \"active\", \"completed\", {\n\t\t\t\tevidence,\n\t\t\t\tpayload: { title: plan.title, branch: plan.branch, steps: plan.steps, linkedRevision: target },\n\t\t\t\toperationId: completeOptions?.operationId,\n\t\t\t});\n\t\t},\n\t\tdiscard(planId, owner) {\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (!plan || plan.status === \"completed\" || plan.status === \"discarded\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} cannot be discarded from status {status}\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, plan.status, \"discarded\", {});\n\t\t},\n\t\tget(planId, owner) {\n\t\t\treturn planGet(planId, owner);\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default policy manifest (2.7e) — an explicit, declarative manifest of the
|
|
3
|
-
* confirmation / permission / dangerous-operation policies a profile wants,
|
|
4
|
-
* with an external selection path.
|
|
5
|
-
*
|
|
6
|
-
* The manifest is PURE DECLARATION: the kernel ships no policy enforcement —
|
|
7
|
-
* an enforcement plugin (or none at all) attaches externally. Every entry
|
|
8
|
-
* states its `enabled` flag explicitly; selecting an external policy
|
|
9
|
-
* replaces or nulls (disables) a declaration and produces a NEW frozen
|
|
10
|
-
* manifest plus a change record — the previous manifest stays untouched.
|
|
11
|
-
* Digests reuse the key-order-stable serialization so declarations are
|
|
12
|
-
* replayable.
|
|
13
|
-
*/
|
|
14
|
-
import type { JsonValue } from "@agent-forge/ai";
|
|
15
|
-
export type PolicyKindV1 = "confirmation" | "permission" | "dangerous_operation";
|
|
16
|
-
export interface PolicyDeclarationV1 {
|
|
17
|
-
readonly policyKind: PolicyKindV1;
|
|
18
|
-
readonly policyId: string;
|
|
19
|
-
readonly description: string;
|
|
20
|
-
/** Stated explicitly — a policy the profile does not want is `false`. */
|
|
21
|
-
readonly enabled: boolean;
|
|
22
|
-
readonly defaults?: JsonValue;
|
|
23
|
-
}
|
|
24
|
-
export interface PolicyManifestV1 {
|
|
25
|
-
readonly manifestVersion: 1;
|
|
26
|
-
readonly profileId: string;
|
|
27
|
-
readonly declarations: readonly PolicyDeclarationV1[];
|
|
28
|
-
readonly manifestDigest: string;
|
|
29
|
-
}
|
|
30
|
-
export interface PolicyChangeRecordV1 {
|
|
31
|
-
readonly policyKind: PolicyKindV1;
|
|
32
|
-
readonly policyId: string;
|
|
33
|
-
readonly action: "disabled" | "external_selected";
|
|
34
|
-
readonly reason: string;
|
|
35
|
-
}
|
|
36
|
-
export interface PolicyManifestBuilderV1 {
|
|
37
|
-
buildManifest(input: {
|
|
38
|
-
readonly profileId: string;
|
|
39
|
-
readonly declarations: readonly PolicyDeclarationV1[];
|
|
40
|
-
}): PolicyManifestV1;
|
|
41
|
-
/** The external selection path: swap in an external declaration or disable one (null). */
|
|
42
|
-
selectExternalPolicy(manifest: PolicyManifestV1, input: {
|
|
43
|
-
readonly policyKind: PolicyKindV1;
|
|
44
|
-
readonly policyId: string;
|
|
45
|
-
readonly external: PolicyDeclarationV1 | null;
|
|
46
|
-
readonly reason: string;
|
|
47
|
-
}): {
|
|
48
|
-
readonly manifest: PolicyManifestV1;
|
|
49
|
-
readonly change: PolicyChangeRecordV1;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
export declare function createPolicyManifestBuilder(): PolicyManifestBuilderV1;
|
|
53
|
-
//# sourceMappingURL=policy-manifest.d.ts.map
|
|
@@ -1 +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QACN,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC;QAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAAC;QAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACxB,GACC;QAAE,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAA;KAAE,CAAC;CAClF;AAgBD,wBAAgB,2BAA2B,IAAI,uBAAuB,CA6CrE","sourcesContent":["/**\n * Default policy manifest (2.7e) — an explicit, declarative manifest of the\n * confirmation / permission / dangerous-operation policies a profile wants,\n * with an external selection path.\n *\n * The manifest is PURE DECLARATION: the kernel ships no policy enforcement —\n * an enforcement plugin (or none at all) attaches externally. Every entry\n * states its `enabled` flag explicitly; selecting an external policy\n * replaces or nulls (disables) a declaration and produces a NEW frozen\n * manifest plus a change record — the previous manifest stays untouched.\n * Digests reuse the key-order-stable serialization so declarations are\n * replayable.\n */\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { t } from \"../core/i18n/index.ts\";\nimport { stableJsonDigest } from \"./identity.ts\";\n\nexport type PolicyKindV1 = \"confirmation\" | \"permission\" | \"dangerous_operation\";\n\nexport interface PolicyDeclarationV1 {\n\treadonly policyKind: PolicyKindV1;\n\treadonly policyId: string;\n\treadonly description: string;\n\t/** Stated explicitly — a policy the profile does not want is `false`. */\n\treadonly enabled: boolean;\n\treadonly defaults?: JsonValue;\n}\n\nexport interface PolicyManifestV1 {\n\treadonly manifestVersion: 1;\n\treadonly profileId: string;\n\treadonly declarations: readonly PolicyDeclarationV1[];\n\treadonly manifestDigest: string;\n}\n\nexport interface PolicyChangeRecordV1 {\n\treadonly policyKind: PolicyKindV1;\n\treadonly policyId: string;\n\treadonly action: \"disabled\" | \"external_selected\";\n\treadonly reason: string;\n}\n\nexport interface PolicyManifestBuilderV1 {\n\tbuildManifest(input: {\n\t\treadonly profileId: string;\n\t\treadonly declarations: readonly PolicyDeclarationV1[];\n\t}): PolicyManifestV1;\n\t/** The external selection path: swap in an external declaration or disable one (null). */\n\tselectExternalPolicy(\n\t\tmanifest: PolicyManifestV1,\n\t\tinput: {\n\t\t\treadonly policyKind: PolicyKindV1;\n\t\t\treadonly policyId: string;\n\t\t\treadonly external: PolicyDeclarationV1 | null;\n\t\t\treadonly reason: string;\n\t\t},\n\t): { readonly manifest: PolicyManifestV1; readonly change: PolicyChangeRecordV1 };\n}\n\nfunction assertDeclaration(value: PolicyDeclarationV1): void {\n\tif (![\"confirmation\", \"permission\", \"dangerous_operation\"].includes(value.policyKind)) {\n\t\tthrow new Error(\n\t\t\tt(\"Policy manifest policyKind is invalid: {policyKind}\", { policyKind: String(value.policyKind) }),\n\t\t);\n\t}\n\tif (typeof value.policyId !== \"string\" || value.policyId.trim().length === 0) {\n\t\tthrow new Error(t(\"Policy manifest policyId must be a non-empty string\"));\n\t}\n\tif (typeof value.enabled !== \"boolean\") {\n\t\tthrow new Error(t(\"Policy manifest {policyId}: enabled must be stated explicitly\", { policyId: value.policyId }));\n\t}\n}\n\nexport function createPolicyManifestBuilder(): PolicyManifestBuilderV1 {\n\tconst buildManifest = (input: {\n\t\treadonly profileId: string;\n\t\treadonly declarations: readonly PolicyDeclarationV1[];\n\t}): PolicyManifestV1 => {\n\t\tif (input.profileId.trim().length === 0)\n\t\t\tthrow new Error(t(\"Policy manifest profileId must be a non-empty string\"));\n\t\tfor (const declaration of input.declarations) assertDeclaration(declaration);\n\t\tconst declarations = Object.freeze(input.declarations.map((declaration) => Object.freeze({ ...declaration })));\n\t\treturn Object.freeze({\n\t\t\tmanifestVersion: 1 as const,\n\t\t\tprofileId: input.profileId,\n\t\t\tdeclarations,\n\t\t\tmanifestDigest: stableJsonDigest(declarations as unknown as JsonValue),\n\t\t});\n\t};\n\n\treturn {\n\t\tbuildManifest,\n\t\tselectExternalPolicy(manifest, input) {\n\t\t\tassertDeclaration(\n\t\t\t\tinput.external ?? {\n\t\t\t\t\tpolicyKind: input.policyKind,\n\t\t\t\t\tpolicyId: input.policyId,\n\t\t\t\t\tdescription: \"\",\n\t\t\t\t\tenabled: false,\n\t\t\t\t},\n\t\t\t);\n\t\t\tconst kept = manifest.declarations.filter(\n\t\t\t\t(declaration) => !(declaration.policyKind === input.policyKind && declaration.policyId === input.policyId),\n\t\t\t);\n\t\t\tconst existed = kept.length !== manifest.declarations.length;\n\t\t\tconst declarations = input.external === null ? kept : [...kept, input.external];\n\t\t\tconst next = buildManifest({ profileId: manifest.profileId, declarations });\n\t\t\treturn {\n\t\t\t\tmanifest: next,\n\t\t\t\tchange: {\n\t\t\t\t\tpolicyKind: input.policyKind,\n\t\t\t\t\tpolicyId: input.policyId,\n\t\t\t\t\taction: input.external === null ? \"disabled\" : existed ? \"external_selected\" : \"external_selected\",\n\t\t\t\t\treason: input.reason,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { t } from "../core/i18n/index.js";
|
|
2
|
-
import { stableJsonDigest } from "./identity.js";
|
|
3
|
-
function assertDeclaration(value) {
|
|
4
|
-
if (!["confirmation", "permission", "dangerous_operation"].includes(value.policyKind)) {
|
|
5
|
-
throw new Error(t("Policy manifest policyKind is invalid: {policyKind}", { policyKind: String(value.policyKind) }));
|
|
6
|
-
}
|
|
7
|
-
if (typeof value.policyId !== "string" || value.policyId.trim().length === 0) {
|
|
8
|
-
throw new Error(t("Policy manifest policyId must be a non-empty string"));
|
|
9
|
-
}
|
|
10
|
-
if (typeof value.enabled !== "boolean") {
|
|
11
|
-
throw new Error(t("Policy manifest {policyId}: enabled must be stated explicitly", { policyId: value.policyId }));
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export function createPolicyManifestBuilder() {
|
|
15
|
-
const buildManifest = (input) => {
|
|
16
|
-
if (input.profileId.trim().length === 0)
|
|
17
|
-
throw new Error(t("Policy manifest profileId must be a non-empty string"));
|
|
18
|
-
for (const declaration of input.declarations)
|
|
19
|
-
assertDeclaration(declaration);
|
|
20
|
-
const declarations = Object.freeze(input.declarations.map((declaration) => Object.freeze({ ...declaration })));
|
|
21
|
-
return Object.freeze({
|
|
22
|
-
manifestVersion: 1,
|
|
23
|
-
profileId: input.profileId,
|
|
24
|
-
declarations,
|
|
25
|
-
manifestDigest: stableJsonDigest(declarations),
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
return {
|
|
29
|
-
buildManifest,
|
|
30
|
-
selectExternalPolicy(manifest, input) {
|
|
31
|
-
assertDeclaration(input.external ?? {
|
|
32
|
-
policyKind: input.policyKind,
|
|
33
|
-
policyId: input.policyId,
|
|
34
|
-
description: "",
|
|
35
|
-
enabled: false,
|
|
36
|
-
});
|
|
37
|
-
const kept = manifest.declarations.filter((declaration) => !(declaration.policyKind === input.policyKind && declaration.policyId === input.policyId));
|
|
38
|
-
const existed = kept.length !== manifest.declarations.length;
|
|
39
|
-
const declarations = input.external === null ? kept : [...kept, input.external];
|
|
40
|
-
const next = buildManifest({ profileId: manifest.profileId, declarations });
|
|
41
|
-
return {
|
|
42
|
-
manifest: next,
|
|
43
|
-
change: {
|
|
44
|
-
policyKind: input.policyKind,
|
|
45
|
-
policyId: input.policyId,
|
|
46
|
-
action: input.external === null ? "disabled" : existed ? "external_selected" : "external_selected",
|
|
47
|
-
reason: input.reason,
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=policy-manifest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"policy-manifest.js","sourceRoot":"","sources":["../../src/profile/policy-manifest.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,CAAC,EAAE,MAAM,uBAAuB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AA4CjD,SAAS,iBAAiB,CAA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AC,CAAC,CAAC,mBAAmB;oBAClG,MAAM,EAAE,KAAK,CAAC,MAAM;iBACpB;aACD,CAAC;QAAA,CACF;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Default policy manifest (2.7e) — an explicit, declarative manifest of the\n * confirmation / permission / dangerous-operation policies a profile wants,\n * with an external selection path.\n *\n * The manifest is PURE DECLARATION: the kernel ships no policy enforcement —\n * an enforcement plugin (or none at all) attaches externally. Every entry\n * states its `enabled` flag explicitly; selecting an external policy\n * replaces or nulls (disables) a declaration and produces a NEW frozen\n * manifest plus a change record — the previous manifest stays untouched.\n * Digests reuse the key-order-stable serialization so declarations are\n * replayable.\n */\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { t } from \"../core/i18n/index.ts\";\nimport { stableJsonDigest } from \"./identity.ts\";\n\nexport type PolicyKindV1 = \"confirmation\" | \"permission\" | \"dangerous_operation\";\n\nexport interface PolicyDeclarationV1 {\n\treadonly policyKind: PolicyKindV1;\n\treadonly policyId: string;\n\treadonly description: string;\n\t/** Stated explicitly — a policy the profile does not want is `false`. */\n\treadonly enabled: boolean;\n\treadonly defaults?: JsonValue;\n}\n\nexport interface PolicyManifestV1 {\n\treadonly manifestVersion: 1;\n\treadonly profileId: string;\n\treadonly declarations: readonly PolicyDeclarationV1[];\n\treadonly manifestDigest: string;\n}\n\nexport interface PolicyChangeRecordV1 {\n\treadonly policyKind: PolicyKindV1;\n\treadonly policyId: string;\n\treadonly action: \"disabled\" | \"external_selected\";\n\treadonly reason: string;\n}\n\nexport interface PolicyManifestBuilderV1 {\n\tbuildManifest(input: {\n\t\treadonly profileId: string;\n\t\treadonly declarations: readonly PolicyDeclarationV1[];\n\t}): PolicyManifestV1;\n\t/** The external selection path: swap in an external declaration or disable one (null). */\n\tselectExternalPolicy(\n\t\tmanifest: PolicyManifestV1,\n\t\tinput: {\n\t\t\treadonly policyKind: PolicyKindV1;\n\t\t\treadonly policyId: string;\n\t\t\treadonly external: PolicyDeclarationV1 | null;\n\t\t\treadonly reason: string;\n\t\t},\n\t): { readonly manifest: PolicyManifestV1; readonly change: PolicyChangeRecordV1 };\n}\n\nfunction assertDeclaration(value: PolicyDeclarationV1): void {\n\tif (![\"confirmation\", \"permission\", \"dangerous_operation\"].includes(value.policyKind)) {\n\t\tthrow new Error(\n\t\t\tt(\"Policy manifest policyKind is invalid: {policyKind}\", { policyKind: String(value.policyKind) }),\n\t\t);\n\t}\n\tif (typeof value.policyId !== \"string\" || value.policyId.trim().length === 0) {\n\t\tthrow new Error(t(\"Policy manifest policyId must be a non-empty string\"));\n\t}\n\tif (typeof value.enabled !== \"boolean\") {\n\t\tthrow new Error(t(\"Policy manifest {policyId}: enabled must be stated explicitly\", { policyId: value.policyId }));\n\t}\n}\n\nexport function createPolicyManifestBuilder(): PolicyManifestBuilderV1 {\n\tconst buildManifest = (input: {\n\t\treadonly profileId: string;\n\t\treadonly declarations: readonly PolicyDeclarationV1[];\n\t}): PolicyManifestV1 => {\n\t\tif (input.profileId.trim().length === 0)\n\t\t\tthrow new Error(t(\"Policy manifest profileId must be a non-empty string\"));\n\t\tfor (const declaration of input.declarations) assertDeclaration(declaration);\n\t\tconst declarations = Object.freeze(input.declarations.map((declaration) => Object.freeze({ ...declaration })));\n\t\treturn Object.freeze({\n\t\t\tmanifestVersion: 1 as const,\n\t\t\tprofileId: input.profileId,\n\t\t\tdeclarations,\n\t\t\tmanifestDigest: stableJsonDigest(declarations as unknown as JsonValue),\n\t\t});\n\t};\n\n\treturn {\n\t\tbuildManifest,\n\t\tselectExternalPolicy(manifest, input) {\n\t\t\tassertDeclaration(\n\t\t\t\tinput.external ?? {\n\t\t\t\t\tpolicyKind: input.policyKind,\n\t\t\t\t\tpolicyId: input.policyId,\n\t\t\t\t\tdescription: \"\",\n\t\t\t\t\tenabled: false,\n\t\t\t\t},\n\t\t\t);\n\t\t\tconst kept = manifest.declarations.filter(\n\t\t\t\t(declaration) => !(declaration.policyKind === input.policyKind && declaration.policyId === input.policyId),\n\t\t\t);\n\t\t\tconst existed = kept.length !== manifest.declarations.length;\n\t\t\tconst declarations = input.external === null ? kept : [...kept, input.external];\n\t\t\tconst next = buildManifest({ profileId: manifest.profileId, declarations });\n\t\t\treturn {\n\t\t\t\tmanifest: next,\n\t\t\t\tchange: {\n\t\t\t\t\tpolicyKind: input.policyKind,\n\t\t\t\t\tpolicyId: input.policyId,\n\t\t\t\t\taction: input.external === null ? \"disabled\" : existed ? \"external_selected\" : \"external_selected\",\n\t\t\t\t\treason: input.reason,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Role assembly (2.2d) — builds a `RoleCatalogV1` plus a role-runner binding
|
|
3
|
-
* from registered role metadata, evaluates every role's REQUIRED capability
|
|
4
|
-
* dependencies against the available capability registry (2.5a structured
|
|
5
|
-
* `missing` diagnostics), and exposes the sorted roleId summary consumed by
|
|
6
|
-
* the code profile package assembly (2.7c). The same input always assembles
|
|
7
|
-
* identically; duplicate roleIds fail explicitly through the catalog.
|
|
8
|
-
*/
|
|
9
|
-
import type { AvailableCapabilityV1 } from "./dependency-wiring.ts";
|
|
10
|
-
import { type RoleCatalogV1, type RoleMetadataV1 } from "./role-catalog.ts";
|
|
11
|
-
import { type RoleMissingCapabilityV1, type RoleRunCallbackV1, type RoleRunnerV1 } from "./role-runner.ts";
|
|
12
|
-
/** One registered role: catalog metadata plus an optional per-role run binding. */
|
|
13
|
-
export interface RegisteredRoleMetaV1 {
|
|
14
|
-
readonly metadata: RoleMetadataV1;
|
|
15
|
-
/**
|
|
16
|
-
* Optional per-role run override. Run-binding precedence: per-role override
|
|
17
|
-
* → deterministic first-batch callback → explicit failure for roles
|
|
18
|
-
* without any first-batch callback.
|
|
19
|
-
*/
|
|
20
|
-
readonly run?: RoleRunCallbackV1;
|
|
21
|
-
}
|
|
22
|
-
/** Aggregated required-dependency diagnostics across all assembled roles. */
|
|
23
|
-
export interface RoleAssemblyDiagnosticsV1 {
|
|
24
|
-
readonly status: "satisfied" | "missing";
|
|
25
|
-
readonly missing: readonly RoleMissingCapabilityV1[];
|
|
26
|
-
}
|
|
27
|
-
/** Assembled role mount: catalog + runner binding + identity summary + diagnostics. */
|
|
28
|
-
export interface RoleAssemblyV1 {
|
|
29
|
-
readonly catalog: RoleCatalogV1;
|
|
30
|
-
readonly runner: RoleRunnerV1;
|
|
31
|
-
/** Sorted registered roleId summary (package identity/diagnostics surface). */
|
|
32
|
-
readonly roleIds: readonly string[];
|
|
33
|
-
readonly capabilityDiagnostics: RoleAssemblyDiagnosticsV1;
|
|
34
|
-
}
|
|
35
|
-
/** Data-only role mount summary carried by a ready code profile package. */
|
|
36
|
-
export interface MountedRoleSummaryV1 {
|
|
37
|
-
readonly roleIds: readonly string[];
|
|
38
|
-
readonly capabilityDiagnostics: RoleAssemblyDiagnosticsV1;
|
|
39
|
-
}
|
|
40
|
-
/** Assembles registered role metadata into a catalog + runner binding object. */
|
|
41
|
-
export declare function assembleRoles(input: {
|
|
42
|
-
readonly roles: readonly RegisteredRoleMetaV1[];
|
|
43
|
-
readonly availableCapabilities: readonly AvailableCapabilityV1[];
|
|
44
|
-
/** Owner stamped onto produced child definitions (see `createRoleRunner`). */
|
|
45
|
-
readonly owner?: string;
|
|
46
|
-
}): RoleAssemblyV1;
|
|
47
|
-
//# sourceMappingURL=role-assembly.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"role-assembly.d.ts","sourceRoot":"","sources":["../../src/profile/role-assembly.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAqB,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC/F,OAAO,EAEN,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAGjB,MAAM,kBAAkB,CAAC;AAE1B,mFAAmF;AACnF,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,iBAAiB,CAAC;CACjC;AAED,6EAA6E;AAC7E,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,SAAS,uBAAuB,EAAE,CAAC;CACrD;AAED,uFAAuF;AACvF,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,qBAAqB,EAAE,yBAAyB,CAAC;CAC1D;AAED,4EAA4E;AAC5E,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,qBAAqB,EAAE,yBAAyB,CAAC;CAC1D;AAED,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,KAAK,EAAE;IACpC,QAAQ,CAAC,KAAK,EAAE,SAAS,oBAAoB,EAAE,CAAC;IAChD,QAAQ,CAAC,qBAAqB,EAAE,SAAS,qBAAqB,EAAE,CAAC;IACjE,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,cAAc,CA4BjB","sourcesContent":["/**\n * Role assembly (2.2d) — builds a `RoleCatalogV1` plus a role-runner binding\n * from registered role metadata, evaluates every role's REQUIRED capability\n * dependencies against the available capability registry (2.5a structured\n * `missing` diagnostics), and exposes the sorted roleId summary consumed by\n * the code profile package assembly (2.7c). The same input always assembles\n * identically; duplicate roleIds fail explicitly through the catalog.\n */\nimport type { AvailableCapabilityV1 } from \"./dependency-wiring.ts\";\nimport { createRoleCatalog, type RoleCatalogV1, type RoleMetadataV1 } from \"./role-catalog.ts\";\nimport {\n\tcreateRoleRunner,\n\ttype RoleMissingCapabilityV1,\n\ttype RoleRunCallbackV1,\n\ttype RoleRunnerV1,\n\ttype RoleRunResolverV1,\n\trunFirstBatchRole,\n} from \"./role-runner.ts\";\n\n/** One registered role: catalog metadata plus an optional per-role run binding. */\nexport interface RegisteredRoleMetaV1 {\n\treadonly metadata: RoleMetadataV1;\n\t/**\n\t * Optional per-role run override. Run-binding precedence: per-role override\n\t * → deterministic first-batch callback → explicit failure for roles\n\t * without any first-batch callback.\n\t */\n\treadonly run?: RoleRunCallbackV1;\n}\n\n/** Aggregated required-dependency diagnostics across all assembled roles. */\nexport interface RoleAssemblyDiagnosticsV1 {\n\treadonly status: \"satisfied\" | \"missing\";\n\treadonly missing: readonly RoleMissingCapabilityV1[];\n}\n\n/** Assembled role mount: catalog + runner binding + identity summary + diagnostics. */\nexport interface RoleAssemblyV1 {\n\treadonly catalog: RoleCatalogV1;\n\treadonly runner: RoleRunnerV1;\n\t/** Sorted registered roleId summary (package identity/diagnostics surface). */\n\treadonly roleIds: readonly string[];\n\treadonly capabilityDiagnostics: RoleAssemblyDiagnosticsV1;\n}\n\n/** Data-only role mount summary carried by a ready code profile package. */\nexport interface MountedRoleSummaryV1 {\n\treadonly roleIds: readonly string[];\n\treadonly capabilityDiagnostics: RoleAssemblyDiagnosticsV1;\n}\n\n/** Assembles registered role metadata into a catalog + runner binding object. */\nexport function assembleRoles(input: {\n\treadonly roles: readonly RegisteredRoleMetaV1[];\n\treadonly availableCapabilities: readonly AvailableCapabilityV1[];\n\t/** Owner stamped onto produced child definitions (see `createRoleRunner`). */\n\treadonly owner?: string;\n}): RoleAssemblyV1 {\n\tconst catalog = createRoleCatalog(input.roles.map((role) => role.metadata));\n\tconst overrides = new Map<string, RoleRunCallbackV1>(\n\t\tinput.roles.flatMap((role) => (role.run ? [[role.metadata.roleId, role.run] as const] : [])),\n\t);\n\tconst runner = createRoleRunner({\n\t\tcatalog,\n\t\t...(input.owner === undefined ? {} : { owner: input.owner }),\n\t\t...(overrides.size > 0\n\t\t\t? {\n\t\t\t\t\trun: ((roleId, runInput, context) => {\n\t\t\t\t\t\tconst override = overrides.get(roleId);\n\t\t\t\t\t\treturn override ? override(runInput, context) : runFirstBatchRole(roleId, runInput, context);\n\t\t\t\t\t}) satisfies RoleRunResolverV1,\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n\tconst roleIds = catalog.list().map((role) => role.roleId);\n\tconst missing = roleIds.flatMap((roleId) => runner.checkCapabilities(roleId, input.availableCapabilities).missing);\n\treturn Object.freeze({\n\t\tcatalog,\n\t\trunner,\n\t\troleIds: Object.freeze([...roleIds]),\n\t\tcapabilityDiagnostics: Object.freeze({\n\t\t\tstatus: missing.length > 0 ? \"missing\" : \"satisfied\",\n\t\t\tmissing: Object.freeze(missing),\n\t\t}),\n\t});\n}\n"]}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createRoleCatalog } from "./role-catalog.js";
|
|
2
|
-
import { createRoleRunner, runFirstBatchRole, } from "./role-runner.js";
|
|
3
|
-
/** Assembles registered role metadata into a catalog + runner binding object. */
|
|
4
|
-
export function assembleRoles(input) {
|
|
5
|
-
const catalog = createRoleCatalog(input.roles.map((role) => role.metadata));
|
|
6
|
-
const overrides = new Map(input.roles.flatMap((role) => (role.run ? [[role.metadata.roleId, role.run]] : [])));
|
|
7
|
-
const runner = createRoleRunner({
|
|
8
|
-
catalog,
|
|
9
|
-
...(input.owner === undefined ? {} : { owner: input.owner }),
|
|
10
|
-
...(overrides.size > 0
|
|
11
|
-
? {
|
|
12
|
-
run: ((roleId, runInput, context) => {
|
|
13
|
-
const override = overrides.get(roleId);
|
|
14
|
-
return override ? override(runInput, context) : runFirstBatchRole(roleId, runInput, context);
|
|
15
|
-
}),
|
|
16
|
-
}
|
|
17
|
-
: {}),
|
|
18
|
-
});
|
|
19
|
-
const roleIds = catalog.list().map((role) => role.roleId);
|
|
20
|
-
const missing = roleIds.flatMap((roleId) => runner.checkCapabilities(roleId, input.availableCapabilities).missing);
|
|
21
|
-
return Object.freeze({
|
|
22
|
-
catalog,
|
|
23
|
-
runner,
|
|
24
|
-
roleIds: Object.freeze([...roleIds]),
|
|
25
|
-
capabilityDiagnostics: Object.freeze({
|
|
26
|
-
status: missing.length > 0 ? "missing" : "satisfied",
|
|
27
|
-
missing: Object.freeze(missing),
|
|
28
|
-
}),
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=role-assembly.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"role-assembly.js","sourceRoot":"","sources":["../../src/profile/role-assembly.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,iBAAiB,EAA2C,MAAM,mBAAmB,CAAC;AAC/F,OAAO,EACN,gBAAgB,EAKhB,iBAAiB,GACjB,MAAM,kBAAkB,CAAC;AAkC1B,iFAAiF;AACjF,MAAM,UAAU,aAAa,CAAC,KAK7B,EAAkB;IAClB,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5E,MAAM,SAAS,GAAG,IAAI,GAAG,CACxB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAC5F,CAAC;IACF,MAAM,MAAM,GAAG,gBAAgB,CAAC;QAC/B,OAAO;QACP,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;QAC5D,GAAG,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC;YACrB,CAAC,CAAC;gBACA,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC;oBACpC,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;oBACvC,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAAA,CAC7F,CAA6B;aAC9B;YACF,CAAC,CAAC,EAAE,CAAC;KACN,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC,CAAC;IACnH,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,OAAO;QACP,MAAM;QACN,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;QACpC,qBAAqB,EAAE,MAAM,CAAC,MAAM,CAAC;YACpC,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW;YACpD,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;SAC/B,CAAC;KACF,CAAC,CAAC;AAAA,CACH","sourcesContent":["/**\n * Role assembly (2.2d) — builds a `RoleCatalogV1` plus a role-runner binding\n * from registered role metadata, evaluates every role's REQUIRED capability\n * dependencies against the available capability registry (2.5a structured\n * `missing` diagnostics), and exposes the sorted roleId summary consumed by\n * the code profile package assembly (2.7c). The same input always assembles\n * identically; duplicate roleIds fail explicitly through the catalog.\n */\nimport type { AvailableCapabilityV1 } from \"./dependency-wiring.ts\";\nimport { createRoleCatalog, type RoleCatalogV1, type RoleMetadataV1 } from \"./role-catalog.ts\";\nimport {\n\tcreateRoleRunner,\n\ttype RoleMissingCapabilityV1,\n\ttype RoleRunCallbackV1,\n\ttype RoleRunnerV1,\n\ttype RoleRunResolverV1,\n\trunFirstBatchRole,\n} from \"./role-runner.ts\";\n\n/** One registered role: catalog metadata plus an optional per-role run binding. */\nexport interface RegisteredRoleMetaV1 {\n\treadonly metadata: RoleMetadataV1;\n\t/**\n\t * Optional per-role run override. Run-binding precedence: per-role override\n\t * → deterministic first-batch callback → explicit failure for roles\n\t * without any first-batch callback.\n\t */\n\treadonly run?: RoleRunCallbackV1;\n}\n\n/** Aggregated required-dependency diagnostics across all assembled roles. */\nexport interface RoleAssemblyDiagnosticsV1 {\n\treadonly status: \"satisfied\" | \"missing\";\n\treadonly missing: readonly RoleMissingCapabilityV1[];\n}\n\n/** Assembled role mount: catalog + runner binding + identity summary + diagnostics. */\nexport interface RoleAssemblyV1 {\n\treadonly catalog: RoleCatalogV1;\n\treadonly runner: RoleRunnerV1;\n\t/** Sorted registered roleId summary (package identity/diagnostics surface). */\n\treadonly roleIds: readonly string[];\n\treadonly capabilityDiagnostics: RoleAssemblyDiagnosticsV1;\n}\n\n/** Data-only role mount summary carried by a ready code profile package. */\nexport interface MountedRoleSummaryV1 {\n\treadonly roleIds: readonly string[];\n\treadonly capabilityDiagnostics: RoleAssemblyDiagnosticsV1;\n}\n\n/** Assembles registered role metadata into a catalog + runner binding object. */\nexport function assembleRoles(input: {\n\treadonly roles: readonly RegisteredRoleMetaV1[];\n\treadonly availableCapabilities: readonly AvailableCapabilityV1[];\n\t/** Owner stamped onto produced child definitions (see `createRoleRunner`). */\n\treadonly owner?: string;\n}): RoleAssemblyV1 {\n\tconst catalog = createRoleCatalog(input.roles.map((role) => role.metadata));\n\tconst overrides = new Map<string, RoleRunCallbackV1>(\n\t\tinput.roles.flatMap((role) => (role.run ? [[role.metadata.roleId, role.run] as const] : [])),\n\t);\n\tconst runner = createRoleRunner({\n\t\tcatalog,\n\t\t...(input.owner === undefined ? {} : { owner: input.owner }),\n\t\t...(overrides.size > 0\n\t\t\t? {\n\t\t\t\t\trun: ((roleId, runInput, context) => {\n\t\t\t\t\t\tconst override = overrides.get(roleId);\n\t\t\t\t\t\treturn override ? override(runInput, context) : runFirstBatchRole(roleId, runInput, context);\n\t\t\t\t\t}) satisfies RoleRunResolverV1,\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n\tconst roleIds = catalog.list().map((role) => role.roleId);\n\tconst missing = roleIds.flatMap((roleId) => runner.checkCapabilities(roleId, input.availableCapabilities).missing);\n\treturn Object.freeze({\n\t\tcatalog,\n\t\trunner,\n\t\troleIds: Object.freeze([...roleIds]),\n\t\tcapabilityDiagnostics: Object.freeze({\n\t\t\tstatus: missing.length > 0 ? \"missing\" : \"satisfied\",\n\t\t\tmissing: Object.freeze(missing),\n\t\t}),\n\t});\n}\n"]}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Role metadata catalog (2.2a).
|
|
3
|
-
*
|
|
4
|
-
* Role metadata is DISCOVERY data, not a security policy: roleId, input/output
|
|
5
|
-
* schema references, capability dependencies, writable memory scopes,
|
|
6
|
-
* concurrency, and completion criteria are all discoverable through the
|
|
7
|
-
* catalog. Registered roles are validated and served as detached, frozen
|
|
8
|
-
* snapshots.
|
|
9
|
-
*/
|
|
10
|
-
export type RoleWritableScopeV1 = "session" | "cycle" | "long-term";
|
|
11
|
-
export interface RoleCapabilityDependencyV1 {
|
|
12
|
-
readonly capabilityId: string;
|
|
13
|
-
readonly capabilityVersion: number;
|
|
14
|
-
/** Required dependencies fail role activation when missing. */
|
|
15
|
-
readonly required: boolean;
|
|
16
|
-
}
|
|
17
|
-
/** Versioned input/output schema reference (schema bodies live with the domain plugin). */
|
|
18
|
-
export interface RoleIOSchemaRefV1 {
|
|
19
|
-
readonly schemaId: string;
|
|
20
|
-
readonly schemaVersion: number;
|
|
21
|
-
}
|
|
22
|
-
export interface RoleMetadataV1 {
|
|
23
|
-
readonly roleId: string;
|
|
24
|
-
readonly title: string;
|
|
25
|
-
readonly input: RoleIOSchemaRefV1;
|
|
26
|
-
readonly output: RoleIOSchemaRefV1;
|
|
27
|
-
readonly capabilityDependencies: readonly RoleCapabilityDependencyV1[];
|
|
28
|
-
readonly writableScopes: readonly RoleWritableScopeV1[];
|
|
29
|
-
readonly concurrency: "single" | "parallel";
|
|
30
|
-
readonly completionCriteria: string;
|
|
31
|
-
}
|
|
32
|
-
export interface RoleCatalogV1 {
|
|
33
|
-
register(metadata: RoleMetadataV1): RoleMetadataV1;
|
|
34
|
-
get(roleId: string): RoleMetadataV1 | undefined;
|
|
35
|
-
list(): readonly RoleMetadataV1[];
|
|
36
|
-
/** Roles declaring the given capability as a dependency (required or optional). */
|
|
37
|
-
findByCapability(capabilityId: string): readonly RoleMetadataV1[];
|
|
38
|
-
}
|
|
39
|
-
/** Validates role metadata and returns a detached, frozen snapshot. */
|
|
40
|
-
export declare function validateRoleMetadataV1(value: unknown): RoleMetadataV1;
|
|
41
|
-
/** Discoverable role catalog: register, get, list (sorted), find by capability. */
|
|
42
|
-
export declare function createRoleCatalog(initial?: readonly RoleMetadataV1[]): RoleCatalogV1;
|
|
43
|
-
//# sourceMappingURL=role-catalog.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"role-catalog.d.ts","sourceRoot":"","sources":["../../src/profile/role-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,CAAC;AAEpE,MAAM,WAAW,0BAA0B;IAC1C,QAA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: roleId, input/output\n * schema references, capability dependencies, writable memory scopes,\n * concurrency, and completion criteria are all discoverable through the\n * catalog. Registered roles are validated and served as detached, frozen\n * snapshots.\n */\n\n/** Memory scopes a role may write to (aligned with the 1C.1b store scopes). */\nimport { t } from \"../core/i18n/index.ts\";\n\nexport type RoleWritableScopeV1 = \"session\" | \"cycle\" | \"long-term\";\n\nexport interface RoleCapabilityDependencyV1 {\n\treadonly capabilityId: string;\n\treadonly capabilityVersion: number;\n\t/** Required dependencies fail role activation when missing. */\n\treadonly required: boolean;\n}\n\n/** Versioned input/output schema reference (schema bodies live with the domain plugin). */\nexport interface RoleIOSchemaRefV1 {\n\treadonly schemaId: string;\n\treadonly schemaVersion: number;\n}\n\nexport interface RoleMetadataV1 {\n\treadonly roleId: string;\n\treadonly title: string;\n\treadonly input: RoleIOSchemaRefV1;\n\treadonly output: RoleIOSchemaRefV1;\n\treadonly capabilityDependencies: readonly RoleCapabilityDependencyV1[];\n\treadonly writableScopes: readonly RoleWritableScopeV1[];\n\treadonly concurrency: \"single\" | \"parallel\";\n\treadonly completionCriteria: string;\n}\n\nexport interface RoleCatalogV1 {\n\tregister(metadata: RoleMetadataV1): RoleMetadataV1;\n\tget(roleId: string): RoleMetadataV1 | undefined;\n\tlist(): readonly RoleMetadataV1[];\n\t/** Roles declaring the given capability as a dependency (required or optional). */\n\tfindByCapability(capabilityId: string): readonly RoleMetadataV1[];\n}\n\nconst WRITABLE_SCOPES: readonly RoleWritableScopeV1[] = [\"session\", \"cycle\", \"long-term\"];\n\nfunction assertNonEmptyString(value: unknown, label: string): asserts value is string {\n\tif (typeof value !== \"string\" || value.trim().length === 0)\n\t\tthrow new Error(t(\"{label} must be a non-empty string\", { label }));\n}\n\nfunction assertIOSchemaRef(value: unknown, label: string): RoleIOSchemaRefV1 {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(t(\"{label} must be a plain object\", { label }));\n\t}\n\tconst record = value as Record<string, unknown>;\n\tassertNonEmptyString(record.schemaId, `${label}.schemaId`);\n\tif (\n\t\ttypeof record.schemaVersion !== \"number\" ||\n\t\t!Number.isSafeInteger(record.schemaVersion) ||\n\t\trecord.schemaVersion < 1\n\t) {\n\t\tthrow new Error(t(\"{label}.schemaVersion must be a positive safe integer\", { label }));\n\t}\n\treturn Object.freeze({ schemaId: record.schemaId, schemaVersion: record.schemaVersion });\n}\n\n/** Validates role metadata and returns a detached, frozen snapshot. */\nexport function validateRoleMetadataV1(value: unknown): RoleMetadataV1 {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(t(\"Role metadata must be a plain object\"));\n\t}\n\tconst record = value as Record<string, unknown>;\n\tconst required = [\n\t\t\"roleId\",\n\t\t\"title\",\n\t\t\"input\",\n\t\t\"output\",\n\t\t\"capabilityDependencies\",\n\t\t\"writableScopes\",\n\t\t\"concurrency\",\n\t\t\"completionCriteria\",\n\t];\n\tfor (const key of required) {\n\t\tif (!(key in record)) throw new Error(t(\"Role metadata is missing required field: {key}\", { key }));\n\t}\n\tconst unsupported = Object.keys(record)\n\t\t.filter((key) => !required.includes(key))\n\t\t.sort();\n\tif (unsupported.length > 0)\n\t\tthrow new Error(t(\"Role metadata has unsupported fields: {fields}\", { fields: unsupported.join(\", \") }));\n\n\tassertNonEmptyString(record.roleId, \"Role metadata.roleId\");\n\tassertNonEmptyString(record.title, \"Role metadata.title\");\n\tconst input = assertIOSchemaRef(record.input, \"Role metadata.input\");\n\tconst output = assertIOSchemaRef(record.output, \"Role metadata.output\");\n\n\tif (!Array.isArray(record.capabilityDependencies)) {\n\t\tthrow new Error(t(\"Role metadata.capabilityDependencies must be an array\"));\n\t}\n\tconst capabilityDependencies = record.capabilityDependencies.map((item, index) => {\n\t\tconst depLabel = `Role metadata.capabilityDependencies[${index}]`;\n\t\tif (item === null || typeof item !== \"object\" || Array.isArray(item)) {\n\t\t\tthrow new Error(t(\"{label} must be a plain object\", { label: depLabel }));\n\t\t}\n\t\tconst dep = item as Record<string, unknown>;\n\t\tassertNonEmptyString(dep.capabilityId, `${depLabel}.capabilityId`);\n\t\tif (\n\t\t\ttypeof dep.capabilityVersion !== \"number\" ||\n\t\t\t!Number.isSafeInteger(dep.capabilityVersion) ||\n\t\t\tdep.capabilityVersion < 1\n\t\t) {\n\t\t\tthrow new Error(t(\"{label}.capabilityVersion must be a positive safe integer\", { label: depLabel }));\n\t\t}\n\t\tif (typeof dep.required !== \"boolean\")\n\t\t\tthrow new Error(t(\"{label}.required must be boolean\", { label: depLabel }));\n\t\treturn Object.freeze({\n\t\t\tcapabilityId: dep.capabilityId,\n\t\t\tcapabilityVersion: dep.capabilityVersion,\n\t\t\trequired: dep.required,\n\t\t});\n\t});\n\n\tif (!Array.isArray(record.writableScopes)) throw new Error(t(\"Role metadata.writableScopes must be an array\"));\n\tfor (const [index, scope] of record.writableScopes.entries()) {\n\t\tif (!WRITABLE_SCOPES.includes(scope as RoleWritableScopeV1)) {\n\t\t\tthrow new Error(t(\"Role metadata.writableScopes[{index}] is invalid\", { index }));\n\t\t}\n\t}\n\tassertNonEmptyString(record.completionCriteria, \"Role metadata.completionCriteria\");\n\tif (record.concurrency !== \"single\" && record.concurrency !== \"parallel\") {\n\t\tthrow new Error(t(\"Role metadata.concurrency is invalid\"));\n\t}\n\n\treturn Object.freeze({\n\t\troleId: record.roleId,\n\t\ttitle: record.title,\n\t\tinput,\n\t\toutput,\n\t\tcapabilityDependencies: Object.freeze(capabilityDependencies),\n\t\twritableScopes: Object.freeze([...(record.writableScopes as readonly RoleWritableScopeV1[])]),\n\t\tconcurrency: record.concurrency as RoleMetadataV1[\"concurrency\"],\n\t\tcompletionCriteria: record.completionCriteria,\n\t});\n}\n\n/** Discoverable role catalog: register, get, list (sorted), find by capability. */\nexport function createRoleCatalog(initial: readonly RoleMetadataV1[] = []): RoleCatalogV1 {\n\tconst roles = new Map<string, RoleMetadataV1>();\n\tfor (const metadata of initial) {\n\t\tconst validated = validateRoleMetadataV1(metadata);\n\t\tif (roles.has(validated.roleId))\n\t\t\tthrow new Error(t(\"Role already registered: {roleId}\", { roleId: validated.roleId }));\n\t\troles.set(validated.roleId, validated);\n\t}\n\treturn {\n\t\tregister(metadata) {\n\t\t\tconst validated = validateRoleMetadataV1(metadata);\n\t\t\tif (roles.has(validated.roleId))\n\t\t\t\tthrow new Error(t(\"Role already registered: {roleId}\", { roleId: validated.roleId }));\n\t\t\troles.set(validated.roleId, validated);\n\t\t\treturn validated;\n\t\t},\n\t\tget(roleId) {\n\t\t\treturn roles.get(roleId);\n\t\t},\n\t\tlist() {\n\t\t\treturn Object.freeze([...roles.values()].sort((left, right) => left.roleId.localeCompare(right.roleId)));\n\t\t},\n\t\tfindByCapability(capabilityId) {\n\t\t\treturn Object.freeze(\n\t\t\t\t[...roles.values()].filter((role) =>\n\t\t\t\t\trole.capabilityDependencies.some((dependency) => dependency.capabilityId === capabilityId),\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t};\n}\n"]}
|