@armadra/agent 0.0.0-stage → 0.3.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 +37 -0
- package/LICENSE +21 -0
- package/README.md +470 -2
- package/dist/agent/agent.d.ts +56 -0
- package/dist/agent/agent.js +129 -0
- package/dist/agent/loop.d.ts +51 -0
- package/dist/agent/loop.js +158 -0
- package/dist/agent/queue.d.ts +25 -0
- package/dist/agent/queue.js +55 -0
- package/dist/agent/retry.d.ts +22 -0
- package/dist/agent/retry.js +92 -0
- package/dist/agent/schema.d.ts +27 -0
- package/dist/agent/schema.js +186 -0
- package/dist/agent/session-cache.d.ts +100 -0
- package/dist/agent/session-cache.js +514 -0
- package/dist/agent/session-compaction.d.ts +49 -0
- package/dist/agent/session-compaction.js +251 -0
- package/dist/agent/session-core.d.ts +103 -0
- package/dist/agent/session-core.js +7 -0
- package/dist/agent/session-run.d.ts +55 -0
- package/dist/agent/session-run.js +246 -0
- package/dist/agent/session-state.d.ts +39 -0
- package/dist/agent/session-state.js +119 -0
- package/dist/agent/session-subagent.d.ts +54 -0
- package/dist/agent/session-subagent.js +157 -0
- package/dist/agent/session-sync.d.ts +20 -0
- package/dist/agent/session-sync.js +111 -0
- package/dist/agent/session-tools.d.ts +24 -0
- package/dist/agent/session-tools.js +277 -0
- package/dist/agent/session.d.ts +117 -0
- package/dist/agent/session.js +485 -0
- package/dist/agent/system-prompt.d.ts +49 -0
- package/dist/agent/system-prompt.js +121 -0
- package/dist/agent/tool-runner.d.ts +64 -0
- package/dist/agent/tool-runner.js +309 -0
- package/dist/agent/transform.d.ts +26 -0
- package/dist/agent/transform.js +171 -0
- package/dist/agent/types.d.ts +378 -0
- package/dist/agent/types.js +21 -0
- package/dist/ai/apis/anthropic-messages.d.ts +26 -0
- package/dist/ai/apis/anthropic-messages.js +214 -0
- package/dist/ai/apis/anthropic-request.d.ts +42 -0
- package/dist/ai/apis/anthropic-request.js +282 -0
- package/dist/ai/apis/api.d.ts +28 -0
- package/dist/ai/apis/api.js +102 -0
- package/dist/ai/apis/cache-params.d.ts +48 -0
- package/dist/ai/apis/cache-params.js +163 -0
- package/dist/ai/apis/google-generative-ai.d.ts +32 -0
- package/dist/ai/apis/google-generative-ai.js +249 -0
- package/dist/ai/apis/google-request.d.ts +40 -0
- package/dist/ai/apis/google-request.js +255 -0
- package/dist/ai/apis/openai-compat.d.ts +35 -0
- package/dist/ai/apis/openai-compat.js +142 -0
- package/dist/ai/apis/openai-completions.d.ts +28 -0
- package/dist/ai/apis/openai-completions.js +246 -0
- package/dist/ai/apis/openai-request.d.ts +35 -0
- package/dist/ai/apis/openai-request.js +303 -0
- package/dist/ai/apis/openai-responses-request.d.ts +52 -0
- package/dist/ai/apis/openai-responses-request.js +266 -0
- package/dist/ai/apis/openai-responses.d.ts +28 -0
- package/dist/ai/apis/openai-responses.js +304 -0
- package/dist/ai/apis/shared.d.ts +56 -0
- package/dist/ai/apis/shared.js +179 -0
- package/dist/ai/cache/economics.d.ts +24 -0
- package/dist/ai/cache/economics.js +69 -0
- package/dist/ai/cache/fingerprint.d.ts +17 -0
- package/dist/ai/cache/fingerprint.js +39 -0
- package/dist/ai/cache/miss.d.ts +49 -0
- package/dist/ai/cache/miss.js +96 -0
- package/dist/ai/cache/reporting.d.ts +39 -0
- package/dist/ai/cache/reporting.js +103 -0
- package/dist/ai/cache/types.d.ts +94 -0
- package/dist/ai/cache/types.js +19 -0
- package/dist/ai/cache/warmer.d.ts +94 -0
- package/dist/ai/cache/warmer.js +224 -0
- package/dist/ai/context.d.ts +35 -0
- package/dist/ai/context.js +114 -0
- package/dist/ai/cost.d.ts +21 -0
- package/dist/ai/cost.js +60 -0
- package/dist/ai/event-stream.d.ts +33 -0
- package/dist/ai/event-stream.js +101 -0
- package/dist/ai/fake/fake-provider.d.ts +68 -0
- package/dist/ai/fake/fake-provider.js +278 -0
- package/dist/ai/fake/fake-script.d.ts +69 -0
- package/dist/ai/fake/fake-script.js +142 -0
- package/dist/ai/http.d.ts +54 -0
- package/dist/ai/http.js +212 -0
- package/dist/ai/json-partial.d.ts +17 -0
- package/dist/ai/json-partial.js +243 -0
- package/dist/ai/overflow.d.ts +22 -0
- package/dist/ai/overflow.js +61 -0
- package/dist/ai/providers/auth.d.ts +71 -0
- package/dist/ai/providers/auth.js +202 -0
- package/dist/ai/providers/builtin.d.ts +23 -0
- package/dist/ai/providers/builtin.js +148 -0
- package/dist/ai/providers/catalog-data.d.ts +5 -0
- package/dist/ai/providers/catalog-data.js +19 -0
- package/dist/ai/providers/catalog.d.ts +28 -0
- package/dist/ai/providers/catalog.js +166 -0
- package/dist/ai/providers/channels.d.ts +51 -0
- package/dist/ai/providers/channels.js +96 -0
- package/dist/ai/providers/enrich.d.ts +34 -0
- package/dist/ai/providers/enrich.js +86 -0
- package/dist/ai/providers/models-dev-cache.d.ts +53 -0
- package/dist/ai/providers/models-dev-cache.js +147 -0
- package/dist/ai/providers/models-dev.d.ts +99 -0
- package/dist/ai/providers/models-dev.js +315 -0
- package/dist/ai/providers/registry.d.ts +114 -0
- package/dist/ai/providers/registry.js +458 -0
- package/dist/ai/sse.d.ts +32 -0
- package/dist/ai/sse.js +140 -0
- package/dist/ai/thinking.d.ts +42 -0
- package/dist/ai/thinking.js +101 -0
- package/dist/ai/types.d.ts +448 -0
- package/dist/ai/types.js +19 -0
- package/dist/bundle/ama-sandbox.cjs +324 -0
- package/dist/bundle/ama.cjs +27837 -0
- package/dist/bundle.d.ts +9 -0
- package/dist/bundle.js +15 -0
- package/dist/cli/args.d.ts +85 -0
- package/dist/cli/args.js +408 -0
- package/dist/cli/bootstrap.d.ts +18 -0
- package/dist/cli/bootstrap.js +399 -0
- package/dist/cli/compose-providers.d.ts +37 -0
- package/dist/cli/compose-providers.js +107 -0
- package/dist/cli/compose-session.d.ts +72 -0
- package/dist/cli/compose-session.js +370 -0
- package/dist/cli/compose-store.d.ts +24 -0
- package/dist/cli/compose-store.js +125 -0
- package/dist/cli/compose.d.ts +108 -0
- package/dist/cli/compose.js +221 -0
- package/dist/cli/default-model.d.ts +16 -0
- package/dist/cli/default-model.js +24 -0
- package/dist/cli/deps.d.ts +207 -0
- package/dist/cli/deps.js +12 -0
- package/dist/cli/exit-codes.d.ts +29 -0
- package/dist/cli/exit-codes.js +40 -0
- package/dist/cli/main.d.ts +27 -0
- package/dist/cli/main.js +177 -0
- package/dist/cli/runtime.d.ts +90 -0
- package/dist/cli/runtime.js +8 -0
- package/dist/cli/startup-screen.d.ts +15 -0
- package/dist/cli/startup-screen.js +56 -0
- package/dist/cli/startup-steps.d.ts +35 -0
- package/dist/cli/startup-steps.js +202 -0
- package/dist/cli/subcommands/auth.d.ts +12 -0
- package/dist/cli/subcommands/auth.js +91 -0
- package/dist/cli/subcommands/config.d.ts +53 -0
- package/dist/cli/subcommands/config.js +277 -0
- package/dist/cli/subcommands/context.d.ts +21 -0
- package/dist/cli/subcommands/context.js +42 -0
- package/dist/cli/subcommands/doctor.d.ts +11 -0
- package/dist/cli/subcommands/doctor.js +246 -0
- package/dist/cli/subcommands/init.d.ts +6 -0
- package/dist/cli/subcommands/init.js +22 -0
- package/dist/cli/subcommands/model-meta.d.ts +16 -0
- package/dist/cli/subcommands/model-meta.js +54 -0
- package/dist/cli/subcommands/models-cache-probe.d.ts +34 -0
- package/dist/cli/subcommands/models-cache-probe.js +190 -0
- package/dist/cli/subcommands/models-discover.d.ts +46 -0
- package/dist/cli/subcommands/models-discover.js +232 -0
- package/dist/cli/subcommands/models.d.ts +40 -0
- package/dist/cli/subcommands/models.js +152 -0
- package/dist/cli/subcommands/providers-list.d.ts +8 -0
- package/dist/cli/subcommands/providers-list.js +97 -0
- package/dist/cli/subcommands/providers-plan.d.ts +79 -0
- package/dist/cli/subcommands/providers-plan.js +215 -0
- package/dist/cli/subcommands/providers.d.ts +27 -0
- package/dist/cli/subcommands/providers.js +433 -0
- package/dist/cli/subcommands/sessions.d.ts +11 -0
- package/dist/cli/subcommands/sessions.js +100 -0
- package/dist/codemode/capability.d.ts +37 -0
- package/dist/codemode/capability.js +55 -0
- package/dist/codemode/declarations.d.ts +44 -0
- package/dist/codemode/declarations.js +111 -0
- package/dist/codemode/host-side.d.ts +59 -0
- package/dist/codemode/host-side.js +253 -0
- package/dist/codemode/modes.d.ts +23 -0
- package/dist/codemode/modes.js +40 -0
- package/dist/codemode/protocol.d.ts +91 -0
- package/dist/codemode/protocol.js +114 -0
- package/dist/codemode/sandbox-entry.d.ts +25 -0
- package/dist/codemode/sandbox-entry.js +323 -0
- package/dist/codemode/store.d.ts +26 -0
- package/dist/codemode/store.js +53 -0
- package/dist/codemode/tool.d.ts +105 -0
- package/dist/codemode/tool.js +283 -0
- package/dist/compaction/branch-summary.d.ts +30 -0
- package/dist/compaction/branch-summary.js +79 -0
- package/dist/compaction/breaker.d.ts +32 -0
- package/dist/compaction/breaker.js +65 -0
- package/dist/compaction/cut-point.d.ts +23 -0
- package/dist/compaction/cut-point.js +70 -0
- package/dist/compaction/estimate.d.ts +30 -0
- package/dist/compaction/estimate.js +114 -0
- package/dist/compaction/prune-tier.d.ts +31 -0
- package/dist/compaction/prune-tier.js +83 -0
- package/dist/compaction/serialize.d.ts +20 -0
- package/dist/compaction/serialize.js +115 -0
- package/dist/compaction/summarize-tier.d.ts +111 -0
- package/dist/compaction/summarize-tier.js +305 -0
- package/dist/config/auth-file.d.ts +39 -0
- package/dist/config/auth-file.js +92 -0
- package/dist/config/context-files.d.ts +30 -0
- package/dist/config/context-files.js +77 -0
- package/dist/config/init.d.ts +30 -0
- package/dist/config/init.js +92 -0
- package/dist/config/json-schema.d.ts +14 -0
- package/dist/config/json-schema.js +182 -0
- package/dist/config/load.d.ts +45 -0
- package/dist/config/load.js +97 -0
- package/dist/config/merge.d.ts +73 -0
- package/dist/config/merge.js +248 -0
- package/dist/config/paths.d.ts +38 -0
- package/dist/config/paths.js +108 -0
- package/dist/config/profile.d.ts +27 -0
- package/dist/config/profile.js +65 -0
- package/dist/config/schema.d.ts +34 -0
- package/dist/config/schema.js +476 -0
- package/dist/config/trust.d.ts +42 -0
- package/dist/config/trust.js +122 -0
- package/dist/config/types.d.ts +190 -0
- package/dist/config/types.js +29 -0
- package/dist/config/write.d.ts +10 -0
- package/dist/config/write.js +25 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.js +30 -0
- package/dist/hooks/config.d.ts +49 -0
- package/dist/hooks/config.js +102 -0
- package/dist/hooks/dispatcher.d.ts +41 -0
- package/dist/hooks/dispatcher.js +104 -0
- package/dist/hooks/matcher.d.ts +22 -0
- package/dist/hooks/matcher.js +108 -0
- package/dist/hooks/protocol.d.ts +33 -0
- package/dist/hooks/protocol.js +240 -0
- package/dist/hooks/runner.d.ts +30 -0
- package/dist/hooks/runner.js +143 -0
- package/dist/hooks/types.d.ts +147 -0
- package/dist/hooks/types.js +20 -0
- package/dist/host/api-impl.d.ts +75 -0
- package/dist/host/api-impl.js +173 -0
- package/dist/host/loader.d.ts +31 -0
- package/dist/host/loader.js +147 -0
- package/dist/host/types.d.ts +169 -0
- package/dist/host/types.js +14 -0
- package/dist/host.d.ts +5 -0
- package/dist/host.js +4 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +28 -0
- package/dist/modes/commands-core.d.ts +44 -0
- package/dist/modes/commands-core.js +171 -0
- package/dist/modes/image-input.d.ts +27 -0
- package/dist/modes/image-input.js +78 -0
- package/dist/modes/interactive/approval-dialog.d.ts +48 -0
- package/dist/modes/interactive/approval-dialog.js +202 -0
- package/dist/modes/interactive/commands.d.ts +41 -0
- package/dist/modes/interactive/commands.js +201 -0
- package/dist/modes/interactive/completion.d.ts +53 -0
- package/dist/modes/interactive/completion.js +157 -0
- package/dist/modes/interactive/interactive-mode.d.ts +46 -0
- package/dist/modes/interactive/interactive-mode.js +491 -0
- package/dist/modes/interactive/key-dispatch.d.ts +29 -0
- package/dist/modes/interactive/key-dispatch.js +107 -0
- package/dist/modes/interactive/line/line-editor.d.ts +50 -0
- package/dist/modes/interactive/line/line-editor.js +232 -0
- package/dist/modes/interactive/line/line-mode.d.ts +20 -0
- package/dist/modes/interactive/line/line-mode.js +218 -0
- package/dist/modes/interactive/line/line-render.d.ts +35 -0
- package/dist/modes/interactive/line/line-render.js +171 -0
- package/dist/modes/interactive/line/paste-state.d.ts +26 -0
- package/dist/modes/interactive/line/paste-state.js +72 -0
- package/dist/modes/interactive/message-view.d.ts +77 -0
- package/dist/modes/interactive/message-view.js +269 -0
- package/dist/modes/interactive/pickers.d.ts +42 -0
- package/dist/modes/interactive/pickers.js +115 -0
- package/dist/modes/interactive/startup-ui.d.ts +33 -0
- package/dist/modes/interactive/startup-ui.js +268 -0
- package/dist/modes/interactive/status-bar.d.ts +48 -0
- package/dist/modes/interactive/status-bar.js +139 -0
- package/dist/modes/interactive/tool-view.d.ts +95 -0
- package/dist/modes/interactive/tool-view.js +344 -0
- package/dist/modes/print/json-event.d.ts +15 -0
- package/dist/modes/print/json-event.js +39 -0
- package/dist/modes/print/print-mode.d.ts +17 -0
- package/dist/modes/print/print-mode.js +107 -0
- package/dist/modes/rpc/commands.d.ts +40 -0
- package/dist/modes/rpc/commands.js +263 -0
- package/dist/modes/rpc/jsonl.d.ts +16 -0
- package/dist/modes/rpc/jsonl.js +55 -0
- package/dist/modes/rpc/rpc-mode.d.ts +22 -0
- package/dist/modes/rpc/rpc-mode.js +153 -0
- package/dist/modes/session-report.d.ts +55 -0
- package/dist/modes/session-report.js +278 -0
- package/dist/modes/shared.d.ts +13 -0
- package/dist/modes/shared.js +52 -0
- package/dist/modes/startup-ui-text.d.ts +16 -0
- package/dist/modes/startup-ui-text.js +103 -0
- package/dist/permissions/broker.d.ts +47 -0
- package/dist/permissions/broker.js +107 -0
- package/dist/permissions/dangerous.d.ts +47 -0
- package/dist/permissions/dangerous.js +370 -0
- package/dist/permissions/pipeline.d.ts +51 -0
- package/dist/permissions/pipeline.js +181 -0
- package/dist/permissions/preview.d.ts +43 -0
- package/dist/permissions/preview.js +463 -0
- package/dist/permissions/rules.d.ts +58 -0
- package/dist/permissions/rules.js +249 -0
- package/dist/permissions/types.d.ts +100 -0
- package/dist/permissions/types.js +18 -0
- package/dist/rpc.d.ts +173 -0
- package/dist/rpc.js +13 -0
- package/dist/sdk.d.ts +98 -0
- package/dist/sdk.js +195 -0
- package/dist/session/manager.d.ts +70 -0
- package/dist/session/manager.js +278 -0
- package/dist/session/migrate.d.ts +19 -0
- package/dist/session/migrate.js +53 -0
- package/dist/session/projection.d.ts +50 -0
- package/dist/session/projection.js +184 -0
- package/dist/session/store.d.ts +47 -0
- package/dist/session/store.js +210 -0
- package/dist/session/tree.d.ts +21 -0
- package/dist/session/tree.js +88 -0
- package/dist/session/types.d.ts +201 -0
- package/dist/session/types.js +18 -0
- package/dist/skills/discover.d.ts +60 -0
- package/dist/skills/discover.js +160 -0
- package/dist/skills/expand.d.ts +35 -0
- package/dist/skills/expand.js +46 -0
- package/dist/skills/frontmatter.d.ts +27 -0
- package/dist/skills/frontmatter.js +157 -0
- package/dist/skills/index-prompt.d.ts +13 -0
- package/dist/skills/index-prompt.js +42 -0
- package/dist/skills/templates.d.ts +52 -0
- package/dist/skills/templates.js +177 -0
- package/dist/tools/bash.d.ts +49 -0
- package/dist/tools/bash.js +222 -0
- package/dist/tools/edit-fuzzy.d.ts +36 -0
- package/dist/tools/edit-fuzzy.js +129 -0
- package/dist/tools/edit.d.ts +38 -0
- package/dist/tools/edit.js +241 -0
- package/dist/tools/file-mutex.d.ts +8 -0
- package/dist/tools/file-mutex.js +29 -0
- package/dist/tools/glob.d.ts +44 -0
- package/dist/tools/glob.js +217 -0
- package/dist/tools/grep.d.ts +39 -0
- package/dist/tools/grep.js +179 -0
- package/dist/tools/ignore.d.ts +40 -0
- package/dist/tools/ignore.js +174 -0
- package/dist/tools/image-file.d.ts +31 -0
- package/dist/tools/image-file.js +114 -0
- package/dist/tools/ls.d.ts +21 -0
- package/dist/tools/ls.js +96 -0
- package/dist/tools/output-accumulator.d.ts +48 -0
- package/dist/tools/output-accumulator.js +106 -0
- package/dist/tools/paths.d.ts +20 -0
- package/dist/tools/paths.js +58 -0
- package/dist/tools/presets.d.ts +71 -0
- package/dist/tools/presets.js +128 -0
- package/dist/tools/process-tree.d.ts +35 -0
- package/dist/tools/process-tree.js +125 -0
- package/dist/tools/read.d.ts +24 -0
- package/dist/tools/read.js +132 -0
- package/dist/tools/registry.d.ts +43 -0
- package/dist/tools/registry.js +106 -0
- package/dist/tools/shell.d.ts +38 -0
- package/dist/tools/shell.js +91 -0
- package/dist/tools/task.d.ts +29 -0
- package/dist/tools/task.js +107 -0
- package/dist/tools/todo.d.ts +28 -0
- package/dist/tools/todo.js +107 -0
- package/dist/tools/truncate.d.ts +44 -0
- package/dist/tools/truncate.js +175 -0
- package/dist/tools/types.d.ts +135 -0
- package/dist/tools/types.js +19 -0
- package/dist/tools/write.d.ts +20 -0
- package/dist/tools/write.js +84 -0
- package/dist/tui/ansi.d.ts +29 -0
- package/dist/tui/ansi.js +420 -0
- package/dist/tui/component.d.ts +38 -0
- package/dist/tui/component.js +13 -0
- package/dist/tui/components/box.d.ts +26 -0
- package/dist/tui/components/box.js +65 -0
- package/dist/tui/components/container.d.ts +14 -0
- package/dist/tui/components/container.js +39 -0
- package/dist/tui/components/editor-buffer.d.ts +67 -0
- package/dist/tui/components/editor-buffer.js +300 -0
- package/dist/tui/components/editor-paste.d.ts +29 -0
- package/dist/tui/components/editor-paste.js +64 -0
- package/dist/tui/components/editor.d.ts +114 -0
- package/dist/tui/components/editor.js +530 -0
- package/dist/tui/components/key-value.d.ts +29 -0
- package/dist/tui/components/key-value.js +48 -0
- package/dist/tui/components/loader.d.ts +35 -0
- package/dist/tui/components/loader.js +71 -0
- package/dist/tui/components/markdown.d.ts +90 -0
- package/dist/tui/components/markdown.js +462 -0
- package/dist/tui/components/meter.d.ts +29 -0
- package/dist/tui/components/meter.js +47 -0
- package/dist/tui/components/overlay.d.ts +24 -0
- package/dist/tui/components/overlay.js +52 -0
- package/dist/tui/components/select-list.d.ts +57 -0
- package/dist/tui/components/select-list.js +179 -0
- package/dist/tui/components/spacer.d.ts +11 -0
- package/dist/tui/components/spacer.js +16 -0
- package/dist/tui/components/text.d.ts +30 -0
- package/dist/tui/components/text.js +65 -0
- package/dist/tui/keybindings.d.ts +66 -0
- package/dist/tui/keybindings.js +120 -0
- package/dist/tui/keys.d.ts +38 -0
- package/dist/tui/keys.js +275 -0
- package/dist/tui/stdin-buffer.d.ts +41 -0
- package/dist/tui/stdin-buffer.js +206 -0
- package/dist/tui/terminal.d.ts +79 -0
- package/dist/tui/terminal.js +153 -0
- package/dist/tui/theme.d.ts +31 -0
- package/dist/tui/theme.js +199 -0
- package/dist/tui/tui.d.ts +103 -0
- package/dist/tui/tui.js +363 -0
- package/dist/tui/vt-screen.d.ts +46 -0
- package/dist/tui/vt-screen.js +251 -0
- package/dist/tui.d.ts +30 -0
- package/dist/tui.js +31 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.js +24 -0
- package/docs/codemode.md +102 -0
- package/docs/hooks.md +196 -0
- package/docs/host-api.md +161 -0
- package/docs/providers.md +531 -0
- package/docs/rpc.md +253 -0
- package/docs/session-format.md +119 -0
- package/docs/tui.md +170 -0
- package/package.json +101 -4
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema 子集校验(设计 §2、§5.1)。[B0] 所有。
|
|
3
|
+
*
|
|
4
|
+
* 子集:type(object / string / number / integer / boolean / array)、properties、required、
|
|
5
|
+
* additionalProperties(布尔)、items、enum(原始值)、description / title / default(只做注释)。
|
|
6
|
+
*
|
|
7
|
+
* - `validateSchema(schema, value)` 返回错误列表;空数组 = 通过。路径形如 `$.edits[0].oldText`,
|
|
8
|
+
* 非标识符键用 `$["a b"]`。
|
|
9
|
+
* - `checkSchemaSubset(schema)` 检查 schema 本身只用了子集关键字(工具注册时调用)。
|
|
10
|
+
* - 不做类型强转("1" 不会当作 1),不填 default。
|
|
11
|
+
*/
|
|
12
|
+
const SCHEMA_TYPES = [
|
|
13
|
+
"object",
|
|
14
|
+
"string",
|
|
15
|
+
"number",
|
|
16
|
+
"integer",
|
|
17
|
+
"boolean",
|
|
18
|
+
"array",
|
|
19
|
+
];
|
|
20
|
+
const SUPPORTED_KEYWORDS = new Set([
|
|
21
|
+
"type",
|
|
22
|
+
"title",
|
|
23
|
+
"description",
|
|
24
|
+
"properties",
|
|
25
|
+
"required",
|
|
26
|
+
"additionalProperties",
|
|
27
|
+
"items",
|
|
28
|
+
"enum",
|
|
29
|
+
"default",
|
|
30
|
+
]);
|
|
31
|
+
const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
32
|
+
export function joinPath(base, key) {
|
|
33
|
+
if (typeof key === "number")
|
|
34
|
+
return `${base}[${key}]`;
|
|
35
|
+
return IDENTIFIER.test(key) ? `${base}.${key}` : `${base}[${JSON.stringify(key)}]`;
|
|
36
|
+
}
|
|
37
|
+
function isPlainObject(value) {
|
|
38
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
39
|
+
}
|
|
40
|
+
function describeValue(value) {
|
|
41
|
+
if (value === null)
|
|
42
|
+
return "null";
|
|
43
|
+
if (Array.isArray(value))
|
|
44
|
+
return "array";
|
|
45
|
+
if (typeof value === "number") {
|
|
46
|
+
if (!Number.isFinite(value))
|
|
47
|
+
return "non-finite number";
|
|
48
|
+
return Number.isInteger(value) ? "integer" : "number";
|
|
49
|
+
}
|
|
50
|
+
return typeof value;
|
|
51
|
+
}
|
|
52
|
+
function matchesType(type, value) {
|
|
53
|
+
switch (type) {
|
|
54
|
+
case "object":
|
|
55
|
+
return isPlainObject(value);
|
|
56
|
+
case "array":
|
|
57
|
+
return Array.isArray(value);
|
|
58
|
+
case "string":
|
|
59
|
+
return typeof value === "string";
|
|
60
|
+
case "boolean":
|
|
61
|
+
return typeof value === "boolean";
|
|
62
|
+
case "number":
|
|
63
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
64
|
+
case "integer":
|
|
65
|
+
return typeof value === "number" && Number.isInteger(value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function formatEnum(values) {
|
|
69
|
+
return values.map((v) => JSON.stringify(v)).join(", ");
|
|
70
|
+
}
|
|
71
|
+
function validateAt(schema, value, path, out) {
|
|
72
|
+
if (schema.type !== undefined && !matchesType(schema.type, value)) {
|
|
73
|
+
out.push({
|
|
74
|
+
path,
|
|
75
|
+
keyword: "type",
|
|
76
|
+
message: `expected ${schema.type}, got ${describeValue(value)}`,
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (schema.enum !== undefined && !schema.enum.some((candidate) => candidate === value)) {
|
|
81
|
+
out.push({
|
|
82
|
+
path,
|
|
83
|
+
keyword: "enum",
|
|
84
|
+
message: `must be one of ${formatEnum(schema.enum)}`,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (isPlainObject(value) && (schema.type === "object" || schema.properties !== undefined)) {
|
|
88
|
+
const properties = schema.properties ?? {};
|
|
89
|
+
for (const key of schema.required ?? []) {
|
|
90
|
+
if (!Object.hasOwn(value, key) || value[key] === undefined) {
|
|
91
|
+
out.push({
|
|
92
|
+
path: joinPath(path, key),
|
|
93
|
+
keyword: "required",
|
|
94
|
+
message: "is required",
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (const [key, child] of Object.entries(value)) {
|
|
99
|
+
const childSchema = Object.hasOwn(properties, key) ? properties[key] : undefined;
|
|
100
|
+
if (childSchema !== undefined) {
|
|
101
|
+
if (child !== undefined)
|
|
102
|
+
validateAt(childSchema, child, joinPath(path, key), out);
|
|
103
|
+
}
|
|
104
|
+
else if (schema.additionalProperties === false) {
|
|
105
|
+
out.push({
|
|
106
|
+
path: joinPath(path, key),
|
|
107
|
+
keyword: "additionalProperties",
|
|
108
|
+
message: "is not allowed",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (Array.isArray(value) && schema.items !== undefined) {
|
|
114
|
+
const items = schema.items;
|
|
115
|
+
value.forEach((item, index) => validateAt(items, item, joinPath(path, index), out));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** 校验 value;返回全部错误(不在第一处停下)。 */
|
|
119
|
+
export function validateSchema(schema, value) {
|
|
120
|
+
const out = [];
|
|
121
|
+
validateAt(schema, value, "$", out);
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/** 把错误列表格式化成给模型看的多行文本。 */
|
|
125
|
+
export function formatSchemaErrors(errors) {
|
|
126
|
+
return errors.map((e) => `${e.path}: ${e.message}`).join("\n");
|
|
127
|
+
}
|
|
128
|
+
function checkSubsetAt(schema, path, out) {
|
|
129
|
+
if (!isPlainObject(schema)) {
|
|
130
|
+
out.push(`${path}: schema must be an object`);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
for (const key of Object.keys(schema)) {
|
|
134
|
+
if (!SUPPORTED_KEYWORDS.has(key))
|
|
135
|
+
out.push(`${path}: unsupported keyword "${key}"`);
|
|
136
|
+
}
|
|
137
|
+
const { type, properties, required, additionalProperties, items, enum: enumValues } = schema;
|
|
138
|
+
if (type !== undefined && !SCHEMA_TYPES.includes(type)) {
|
|
139
|
+
out.push(`${path}.type: unsupported type ${JSON.stringify(type)}`);
|
|
140
|
+
}
|
|
141
|
+
for (const key of ["title", "description"]) {
|
|
142
|
+
if (schema[key] !== undefined && typeof schema[key] !== "string") {
|
|
143
|
+
out.push(`${path}.${key}: must be a string`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (properties !== undefined) {
|
|
147
|
+
if (!isPlainObject(properties)) {
|
|
148
|
+
out.push(`${path}.properties: must be an object`);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
for (const [key, child] of Object.entries(properties)) {
|
|
152
|
+
checkSubsetAt(child, joinPath(`${path}.properties`, key), out);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (required !== undefined) {
|
|
157
|
+
if (!Array.isArray(required) || !required.every((r) => typeof r === "string")) {
|
|
158
|
+
out.push(`${path}.required: must be an array of strings`);
|
|
159
|
+
}
|
|
160
|
+
else if (isPlainObject(properties)) {
|
|
161
|
+
for (const name of required) {
|
|
162
|
+
if (!Object.hasOwn(properties, name)) {
|
|
163
|
+
out.push(`${path}.required: "${name}" is not declared in properties`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (additionalProperties !== undefined && typeof additionalProperties !== "boolean") {
|
|
169
|
+
out.push(`${path}.additionalProperties: only boolean is supported`);
|
|
170
|
+
}
|
|
171
|
+
if (items !== undefined)
|
|
172
|
+
checkSubsetAt(items, `${path}.items`, out);
|
|
173
|
+
if (enumValues !== undefined) {
|
|
174
|
+
const ok = Array.isArray(enumValues) &&
|
|
175
|
+
enumValues.length > 0 &&
|
|
176
|
+
enumValues.every((v) => v === null || ["string", "number", "boolean"].includes(typeof v));
|
|
177
|
+
if (!ok)
|
|
178
|
+
out.push(`${path}.enum: must be a non-empty array of primitives`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** 检查 schema 只用了子集关键字;返回问题列表,空数组 = 合规。 */
|
|
182
|
+
export function checkSchemaSubset(schema) {
|
|
183
|
+
const out = [];
|
|
184
|
+
checkSubsetAt(schema, "$", out);
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话层缓存控制器(第三波 §1.2、§1.5–§1.7、§1.9、§1.10)。[W3-C1b]
|
|
3
|
+
*
|
|
4
|
+
* `wrapStream()` 包住会话的流函数:每次真实请求记一条 `RequestRecord`(内存)、算前缀指纹、
|
|
5
|
+
* 更新三态、检测未命中(发 `cache_miss`)、跨 70% / 90% 发 `context_pressure`,turn 请求完成后
|
|
6
|
+
* 交给保温状态机。摘要请求自成一条链,不与主链比对;压缩 / 分支摘要 / 档一裁剪 / `/tree`
|
|
7
|
+
* 之后的首个请求是重置点。子会话(depth > 0)有自己的控制器,`warmSubagents` 为 false 时不保温。
|
|
8
|
+
* fork 出的会话沿用根会话 id 作 `prompt_cache_key`(只是路由提示);task 子会话不沿用。
|
|
9
|
+
*/
|
|
10
|
+
import { type CacheReportingTracker } from "../ai/cache/reporting.js";
|
|
11
|
+
import type { RequestRecord, WarmingDecisionHandler, WarmingMode } from "../ai/cache/types.js";
|
|
12
|
+
import { type WarmerTimers } from "../ai/cache/warmer.js";
|
|
13
|
+
import type { CacheRetention, Model } from "../ai/types.js";
|
|
14
|
+
import { type SummaryContinuation } from "../compaction/summarize-tier.js";
|
|
15
|
+
import type { SessionManager } from "../session/manager.js";
|
|
16
|
+
import type { StreamFn } from "./loop.js";
|
|
17
|
+
import type { SessionCore } from "./session-core.js";
|
|
18
|
+
import type { CacheSettings, SessionCacheStats } from "./types.js";
|
|
19
|
+
export declare const DEFAULT_CACHE_SETTINGS: Readonly<CacheSettings>;
|
|
20
|
+
export declare const PRESSURE_THRESHOLDS: readonly [70, 90];
|
|
21
|
+
export declare function resolveCacheSettings(partial?: Partial<CacheSettings>): CacheSettings;
|
|
22
|
+
export interface SessionCacheDeps {
|
|
23
|
+
now?(): number;
|
|
24
|
+
timers?: WarmerTimers;
|
|
25
|
+
/** 缺省进程内共享的 `sharedCacheReporting`。 */
|
|
26
|
+
tracker?: CacheReportingTracker;
|
|
27
|
+
/** 宿主 `cache.onWarmingDecision` 的处理器(每次刷新前现取)。 */
|
|
28
|
+
decider?(): WarmingDecisionHandler | undefined;
|
|
29
|
+
}
|
|
30
|
+
/** 目录 TTL(毫秒):long 保留且有 long 档时用 long;无承诺 → undefined。 */
|
|
31
|
+
export declare function cacheTtlMs(model: Model, retention?: CacheRetention): number | undefined;
|
|
32
|
+
/** fork 链上的根会话 id(task 子会话与非 fork 会话用自己的 id)。 */
|
|
33
|
+
export declare function cacheKeyOf(manager: SessionManager): string;
|
|
34
|
+
export declare class SessionCacheController {
|
|
35
|
+
private readonly core;
|
|
36
|
+
private settings;
|
|
37
|
+
private readonly now;
|
|
38
|
+
private readonly tracker;
|
|
39
|
+
private readonly decider;
|
|
40
|
+
private readonly warmer;
|
|
41
|
+
private readonly models;
|
|
42
|
+
private readonly snapshots;
|
|
43
|
+
private readonly replaced;
|
|
44
|
+
private inner;
|
|
45
|
+
private warmingOverride;
|
|
46
|
+
private cacheKey;
|
|
47
|
+
private prev;
|
|
48
|
+
private lastTurnRecord;
|
|
49
|
+
private resetPending;
|
|
50
|
+
private disposed;
|
|
51
|
+
private activeTasks;
|
|
52
|
+
private taskSince;
|
|
53
|
+
private taskMs;
|
|
54
|
+
private readonly sums;
|
|
55
|
+
private missCount;
|
|
56
|
+
private readonly byReason;
|
|
57
|
+
private reBilledTokens;
|
|
58
|
+
private reBilledUsd;
|
|
59
|
+
private readonly growth;
|
|
60
|
+
private lastPercent;
|
|
61
|
+
private readonly subagents;
|
|
62
|
+
constructor(core: SessionCore, settings: CacheSettings, deps?: SessionCacheDeps);
|
|
63
|
+
/** 生效的保温模式:子会话在 warmSubagents 为 false 时 off;`/cache warm` 会话内覆盖。 */
|
|
64
|
+
mode(): WarmingMode;
|
|
65
|
+
get cacheSettings(): Readonly<CacheSettings>;
|
|
66
|
+
setWarming(mode: WarmingMode): void;
|
|
67
|
+
/** 最后一条 turn 请求(摘要续写的前缀依据)。 */
|
|
68
|
+
get lastTurn(): RequestRecord | undefined;
|
|
69
|
+
wrapStream(inner: StreamFn): StreamFn;
|
|
70
|
+
/** 会话事件(AgentSessionImpl.emit 转交)。 */
|
|
71
|
+
onEvent(event: Parameters<SessionCore["emit"]>[0]): void;
|
|
72
|
+
onAgentSettled(): void;
|
|
73
|
+
/** 压缩 / context_edit / setModel / navigate 之后:下一条请求是重置点,保温作废。 */
|
|
74
|
+
onContextChanged(): void;
|
|
75
|
+
/** task 子会话结束时由父会话汇总(各自独立统计)。 */
|
|
76
|
+
addSubagent(tokens: {
|
|
77
|
+
cacheRead: number;
|
|
78
|
+
prompt: number;
|
|
79
|
+
}, reBilledTokens: number): void;
|
|
80
|
+
stats(context?: {
|
|
81
|
+
tokens?: number | undefined;
|
|
82
|
+
window?: number | undefined;
|
|
83
|
+
}): SessionCacheStats;
|
|
84
|
+
/**
|
|
85
|
+
* 摘要续写的前缀(第三波 §1.8):当前转录按回合同样的方式转换,且上一次 turn 请求的消息
|
|
86
|
+
* 逐条是它的前缀(缓存必然命中)、加上摘要输出放得进窗口;否则 undefined(走独立请求)。
|
|
87
|
+
*/
|
|
88
|
+
summaryContinuation(): SummaryContinuation | undefined;
|
|
89
|
+
dispose(): void;
|
|
90
|
+
private modelOf;
|
|
91
|
+
private toolsKey;
|
|
92
|
+
private takeTaskMs;
|
|
93
|
+
private turnsLeft;
|
|
94
|
+
private observe;
|
|
95
|
+
private checkPressure;
|
|
96
|
+
private scheduleWarm;
|
|
97
|
+
private isCurrent;
|
|
98
|
+
private replay;
|
|
99
|
+
private onWarmed;
|
|
100
|
+
}
|