@kilnai/cli 1.0.7 → 2.1.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/README.md +34 -8
- package/dist/application/__tests__/session-report.test.d.ts +2 -0
- package/dist/application/__tests__/session-report.test.d.ts.map +1 -0
- package/dist/application/__tests__/session-report.test.js +100 -0
- package/dist/application/__tests__/session-report.test.js.map +1 -0
- package/dist/application/agent-loader.d.ts +30 -2
- package/dist/application/agent-loader.d.ts.map +1 -1
- package/dist/application/agent-loader.js +99 -3
- package/dist/application/agent-loader.js.map +1 -1
- package/dist/application/agent-loader.test.js +112 -18
- package/dist/application/agent-loader.test.js.map +1 -1
- package/dist/application/agent-skill-context.d.ts +12 -0
- package/dist/application/agent-skill-context.d.ts.map +1 -0
- package/dist/application/agent-skill-context.js +32 -0
- package/dist/application/agent-skill-context.js.map +1 -0
- package/dist/application/agent-skill-context.test.d.ts +2 -0
- package/dist/application/agent-skill-context.test.d.ts.map +1 -0
- package/dist/application/agent-skill-context.test.js +156 -0
- package/dist/application/agent-skill-context.test.js.map +1 -0
- package/dist/application/benchmark-session-executor.d.ts +14 -0
- package/dist/application/benchmark-session-executor.d.ts.map +1 -0
- package/dist/application/benchmark-session-executor.js +210 -0
- package/dist/application/benchmark-session-executor.js.map +1 -0
- package/dist/application/config-apply-tool.d.ts +30 -0
- package/dist/application/config-apply-tool.d.ts.map +1 -0
- package/dist/application/config-apply-tool.js +68 -0
- package/dist/application/config-apply-tool.js.map +1 -0
- package/dist/application/config-apply.d.ts +9 -0
- package/dist/application/config-apply.d.ts.map +1 -0
- package/dist/application/config-apply.js +146 -0
- package/dist/application/config-apply.js.map +1 -0
- package/dist/application/config-approval.d.ts +10 -0
- package/dist/application/config-approval.d.ts.map +1 -0
- package/dist/application/config-approval.js +30 -0
- package/dist/application/config-approval.js.map +1 -0
- package/dist/application/config-mutation-store.d.ts +25 -0
- package/dist/application/config-mutation-store.d.ts.map +1 -0
- package/dist/application/config-mutation-store.js +59 -0
- package/dist/application/config-mutation-store.js.map +1 -0
- package/dist/application/config-proposal.d.ts +22 -0
- package/dist/application/config-proposal.d.ts.map +1 -0
- package/dist/application/config-proposal.js +395 -0
- package/dist/application/config-proposal.js.map +1 -0
- package/dist/application/config-propose-tool.d.ts +30 -0
- package/dist/application/config-propose-tool.d.ts.map +1 -0
- package/dist/application/config-propose-tool.js +63 -0
- package/dist/application/config-propose-tool.js.map +1 -0
- package/dist/application/config-read-tool.d.ts +26 -0
- package/dist/application/config-read-tool.d.ts.map +1 -0
- package/dist/application/config-read-tool.js +51 -0
- package/dist/application/config-read-tool.js.map +1 -0
- package/dist/application/config-status.d.ts +9 -0
- package/dist/application/config-status.d.ts.map +1 -0
- package/dist/application/config-status.js +361 -0
- package/dist/application/config-status.js.map +1 -0
- package/dist/application/config-tools.d.ts +3 -0
- package/dist/application/config-tools.d.ts.map +1 -0
- package/dist/application/config-tools.js +11 -0
- package/dist/application/config-tools.js.map +1 -0
- package/dist/application/context-types.d.ts +4 -17
- package/dist/application/context-types.d.ts.map +1 -1
- package/dist/application/context-types.js.map +1 -1
- package/dist/application/first-party-agent-defaults.d.ts +3 -0
- package/dist/application/first-party-agent-defaults.d.ts.map +1 -0
- package/dist/application/first-party-agent-defaults.js +135 -0
- package/dist/application/first-party-agent-defaults.js.map +1 -0
- package/dist/application/instruction-profile-context.d.ts +15 -0
- package/dist/application/instruction-profile-context.d.ts.map +1 -0
- package/dist/application/instruction-profile-context.js +80 -0
- package/dist/application/instruction-profile-context.js.map +1 -0
- package/dist/application/instruction-profile-loader.d.ts +20 -0
- package/dist/application/instruction-profile-loader.d.ts.map +1 -0
- package/dist/application/instruction-profile-loader.js +132 -0
- package/dist/application/instruction-profile-loader.js.map +1 -0
- package/dist/application/instruction-profile-loader.test.d.ts +2 -0
- package/dist/application/instruction-profile-loader.test.d.ts.map +1 -0
- package/dist/application/instruction-profile-loader.test.js +100 -0
- package/dist/application/instruction-profile-loader.test.js.map +1 -0
- package/dist/application/operator-theme-preferences.d.ts +11 -0
- package/dist/application/operator-theme-preferences.d.ts.map +1 -0
- package/dist/application/operator-theme-preferences.js +49 -0
- package/dist/application/operator-theme-preferences.js.map +1 -0
- package/dist/application/project-context.d.ts +22 -0
- package/dist/application/project-context.d.ts.map +1 -0
- package/dist/application/project-context.js +139 -0
- package/dist/application/project-context.js.map +1 -0
- package/dist/application/project-root-resolver.d.ts +14 -0
- package/dist/application/project-root-resolver.d.ts.map +1 -0
- package/dist/application/project-root-resolver.js +71 -0
- package/dist/application/project-root-resolver.js.map +1 -0
- package/dist/application/repo-shim-projection.d.ts +48 -0
- package/dist/application/repo-shim-projection.d.ts.map +1 -0
- package/dist/application/repo-shim-projection.js +536 -0
- package/dist/application/repo-shim-projection.js.map +1 -0
- package/dist/application/resume-sidebar-info.d.ts +9 -0
- package/dist/application/resume-sidebar-info.d.ts.map +1 -0
- package/dist/application/resume-sidebar-info.js +40 -0
- package/dist/application/resume-sidebar-info.js.map +1 -0
- package/dist/application/resume-strategy-feedback.d.ts.map +1 -1
- package/dist/application/resume-strategy-feedback.js +2 -1
- package/dist/application/resume-strategy-feedback.js.map +1 -1
- package/dist/application/run-session.d.ts +15 -0
- package/dist/application/run-session.d.ts.map +1 -1
- package/dist/application/run-session.js +110 -19
- package/dist/application/run-session.js.map +1 -1
- package/dist/application/runtime-session-rehydration.d.ts +9 -0
- package/dist/application/runtime-session-rehydration.d.ts.map +1 -0
- package/dist/application/runtime-session-rehydration.js +115 -0
- package/dist/application/runtime-session-rehydration.js.map +1 -0
- package/dist/application/session-context-artifacts.d.ts +19 -0
- package/dist/application/session-context-artifacts.d.ts.map +1 -0
- package/dist/application/session-context-artifacts.js +60 -0
- package/dist/application/session-context-artifacts.js.map +1 -0
- package/dist/application/session-metadata.d.ts +35 -0
- package/dist/application/session-metadata.d.ts.map +1 -0
- package/dist/application/session-metadata.js +157 -0
- package/dist/application/session-metadata.js.map +1 -0
- package/dist/application/session-report.d.ts.map +1 -1
- package/dist/application/session-report.js +8 -0
- package/dist/application/session-report.js.map +1 -1
- package/dist/application/session-resume.d.ts +1 -1
- package/dist/application/session-resume.d.ts.map +1 -1
- package/dist/application/session-resume.js +4 -4
- package/dist/application/session-resume.js.map +1 -1
- package/dist/application/work-governance-context.d.ts +7 -0
- package/dist/application/work-governance-context.d.ts.map +1 -0
- package/dist/application/work-governance-context.js +64 -0
- package/dist/application/work-governance-context.js.map +1 -0
- package/dist/application/work-governance-context.test.d.ts +2 -0
- package/dist/application/work-governance-context.test.d.ts.map +1 -0
- package/dist/application/work-governance-context.test.js +55 -0
- package/dist/application/work-governance-context.test.js.map +1 -0
- package/dist/application/work-governance-policy.d.ts +15 -0
- package/dist/application/work-governance-policy.d.ts.map +1 -0
- package/dist/application/work-governance-policy.js +53 -0
- package/dist/application/work-governance-policy.js.map +1 -0
- package/dist/application/work-governance-tool.d.ts +421 -0
- package/dist/application/work-governance-tool.d.ts.map +1 -0
- package/dist/application/work-governance-tool.js +937 -0
- package/dist/application/work-governance-tool.js.map +1 -0
- package/dist/application/work-governance-tool.test.d.ts +2 -0
- package/dist/application/work-governance-tool.test.d.ts.map +1 -0
- package/dist/application/work-governance-tool.test.js +935 -0
- package/dist/application/work-governance-tool.test.js.map +1 -0
- package/dist/application/work-governance-workflows.d.ts +23 -0
- package/dist/application/work-governance-workflows.d.ts.map +1 -0
- package/dist/application/work-governance-workflows.js +177 -0
- package/dist/application/work-governance-workflows.js.map +1 -0
- package/dist/application/workflow-snapshot-export.d.ts +81 -0
- package/dist/application/workflow-snapshot-export.d.ts.map +1 -0
- package/dist/application/workflow-snapshot-export.js +141 -0
- package/dist/application/workflow-snapshot-export.js.map +1 -0
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +242 -24
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/benchmark.d.ts +8 -0
- package/dist/commands/benchmark.d.ts.map +1 -0
- package/dist/commands/benchmark.js +287 -0
- package/dist/commands/benchmark.js.map +1 -0
- package/dist/commands/config.d.ts +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +369 -39
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/config.test.d.ts +2 -0
- package/dist/commands/config.test.d.ts.map +1 -0
- package/dist/commands/config.test.js +86 -0
- package/dist/commands/config.test.js.map +1 -0
- package/dist/commands/goal.d.ts +12 -0
- package/dist/commands/goal.d.ts.map +1 -0
- package/dist/commands/goal.js +469 -0
- package/dist/commands/goal.js.map +1 -0
- package/dist/commands/goal.test.d.ts +2 -0
- package/dist/commands/goal.test.d.ts.map +1 -0
- package/dist/commands/goal.test.js +317 -0
- package/dist/commands/goal.test.js.map +1 -0
- package/dist/commands/gui-options.d.ts +5 -0
- package/dist/commands/gui-options.d.ts.map +1 -0
- package/dist/commands/gui-options.js +18 -0
- package/dist/commands/gui-options.js.map +1 -0
- package/dist/commands/gui-session-detail.d.ts +4 -0
- package/dist/commands/gui-session-detail.d.ts.map +1 -0
- package/dist/commands/gui-session-detail.js +32 -0
- package/dist/commands/gui-session-detail.js.map +1 -0
- package/dist/commands/gui-session-summaries.d.ts +5 -0
- package/dist/commands/gui-session-summaries.d.ts.map +1 -0
- package/dist/commands/gui-session-summaries.js +62 -0
- package/dist/commands/gui-session-summaries.js.map +1 -0
- package/dist/commands/gui-shutdown-monitor.d.ts +8 -0
- package/dist/commands/gui-shutdown-monitor.d.ts.map +1 -0
- package/dist/commands/gui-shutdown-monitor.js +50 -0
- package/dist/commands/gui-shutdown-monitor.js.map +1 -0
- package/dist/commands/gui-window.d.ts +42 -0
- package/dist/commands/gui-window.d.ts.map +1 -0
- package/dist/commands/gui-window.js +287 -0
- package/dist/commands/gui-window.js.map +1 -0
- package/dist/commands/gui-workspace.d.ts +3 -0
- package/dist/commands/gui-workspace.d.ts.map +1 -0
- package/dist/commands/gui-workspace.js +297 -0
- package/dist/commands/gui-workspace.js.map +1 -0
- package/dist/commands/gui.d.ts +14 -0
- package/dist/commands/gui.d.ts.map +1 -0
- package/dist/commands/gui.js +391 -0
- package/dist/commands/gui.js.map +1 -0
- package/dist/commands/import-native.d.ts +34 -0
- package/dist/commands/import-native.d.ts.map +1 -0
- package/dist/commands/import-native.js +302 -0
- package/dist/commands/import-native.js.map +1 -0
- package/dist/commands/init-templates.d.ts.map +1 -1
- package/dist/commands/init-templates.js +13 -12
- package/dist/commands/init-templates.js.map +1 -1
- package/dist/commands/init.js +1 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/mcp-config.d.ts.map +1 -1
- package/dist/commands/mcp-config.js +6 -3
- package/dist/commands/mcp-config.js.map +1 -1
- package/dist/commands/memory.d.ts +1 -1
- package/dist/commands/memory.d.ts.map +1 -1
- package/dist/commands/memory.js +188 -39
- package/dist/commands/memory.js.map +1 -1
- package/dist/commands/project.d.ts +3 -0
- package/dist/commands/project.d.ts.map +1 -0
- package/dist/commands/project.js +64 -0
- package/dist/commands/project.js.map +1 -0
- package/dist/commands/route.d.ts +3 -0
- package/dist/commands/route.d.ts.map +1 -0
- package/dist/commands/route.js +19 -0
- package/dist/commands/route.js.map +1 -0
- package/dist/commands/run.d.ts +23 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +416 -81
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/skill-capture.js +34 -14
- package/dist/commands/skill-capture.js.map +1 -1
- package/dist/commands/skill.d.ts.map +1 -1
- package/dist/commands/skill.js +10 -9
- package/dist/commands/skill.js.map +1 -1
- package/dist/commands/status.d.ts +5 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +134 -5
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/sync.d.ts +8 -6
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +173 -48
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/tools.d.ts +2 -0
- package/dist/commands/tools.d.ts.map +1 -1
- package/dist/commands/tools.js +34 -15
- package/dist/commands/tools.js.map +1 -1
- package/dist/commands/tui.d.ts +6 -4
- package/dist/commands/tui.d.ts.map +1 -1
- package/dist/commands/tui.js +594 -94
- package/dist/commands/tui.js.map +1 -1
- package/dist/commands/uninstall.d.ts +13 -0
- package/dist/commands/uninstall.d.ts.map +1 -0
- package/dist/commands/uninstall.js +111 -0
- package/dist/commands/uninstall.js.map +1 -0
- package/dist/config/builtin-tool-surface-config.d.ts +6 -0
- package/dist/config/builtin-tool-surface-config.d.ts.map +1 -0
- package/dist/config/builtin-tool-surface-config.js +27 -0
- package/dist/config/builtin-tool-surface-config.js.map +1 -0
- package/dist/config/config-merger.d.ts +1 -1
- package/dist/config/config-merger.d.ts.map +1 -1
- package/dist/config/config-merger.js +21 -4
- package/dist/config/config-merger.js.map +1 -1
- package/dist/config/config-merger.test.js +202 -7
- package/dist/config/config-merger.test.js.map +1 -1
- package/dist/config/global-config.d.ts +59 -13
- package/dist/config/global-config.d.ts.map +1 -1
- package/dist/config/global-config.js +580 -5
- package/dist/config/global-config.js.map +1 -1
- package/dist/config/global-config.test.js +481 -8
- package/dist/config/global-config.test.js.map +1 -1
- package/dist/config/harness-integration-capabilities.d.ts +27 -0
- package/dist/config/harness-integration-capabilities.d.ts.map +1 -0
- package/dist/config/harness-integration-capabilities.js +64 -0
- package/dist/config/harness-integration-capabilities.js.map +1 -0
- package/dist/config/interactive-use-config.d.ts +25 -0
- package/dist/config/interactive-use-config.d.ts.map +1 -0
- package/dist/config/interactive-use-config.js +210 -0
- package/dist/config/interactive-use-config.js.map +1 -0
- package/dist/config/json-comments.d.ts +2 -0
- package/dist/config/json-comments.d.ts.map +1 -0
- package/dist/config/json-comments.js +21 -0
- package/dist/config/json-comments.js.map +1 -0
- package/dist/config/managed-agent-direct-adapters.d.ts +15 -0
- package/dist/config/managed-agent-direct-adapters.d.ts.map +1 -0
- package/dist/config/managed-agent-direct-adapters.js +54 -0
- package/dist/config/managed-agent-direct-adapters.js.map +1 -0
- package/dist/config/managed-agent-provider-models.d.ts +3 -0
- package/dist/config/managed-agent-provider-models.d.ts.map +1 -0
- package/dist/config/managed-agent-provider-models.js +12 -0
- package/dist/config/managed-agent-provider-models.js.map +1 -0
- package/dist/config/managed-agent-routes.d.ts +49 -0
- package/dist/config/managed-agent-routes.d.ts.map +1 -0
- package/dist/config/managed-agent-routes.js +578 -0
- package/dist/config/managed-agent-routes.js.map +1 -0
- package/dist/config/managed-invocation-context-resolver.d.ts +10 -0
- package/dist/config/managed-invocation-context-resolver.d.ts.map +1 -0
- package/dist/config/managed-invocation-context-resolver.js +98 -0
- package/dist/config/managed-invocation-context-resolver.js.map +1 -0
- package/dist/config/managed-invocation-context-resolver.test.d.ts +2 -0
- package/dist/config/managed-invocation-context-resolver.test.d.ts.map +1 -0
- package/dist/config/managed-invocation-context-resolver.test.js +133 -0
- package/dist/config/managed-invocation-context-resolver.test.js.map +1 -0
- package/dist/config/model-task-suitability.d.ts +9 -0
- package/dist/config/model-task-suitability.d.ts.map +1 -0
- package/dist/config/model-task-suitability.js +40 -0
- package/dist/config/model-task-suitability.js.map +1 -0
- package/dist/config/native-agent-projection.d.ts +16 -0
- package/dist/config/native-agent-projection.d.ts.map +1 -0
- package/dist/config/native-agent-projection.js +242 -0
- package/dist/config/native-agent-projection.js.map +1 -0
- package/dist/config/native-hook-projection.d.ts +11 -0
- package/dist/config/native-hook-projection.d.ts.map +1 -0
- package/dist/config/native-hook-projection.js +180 -0
- package/dist/config/native-hook-projection.js.map +1 -0
- package/dist/config/native-permission-projection.d.ts +12 -0
- package/dist/config/native-permission-projection.d.ts.map +1 -0
- package/dist/config/native-permission-projection.js +162 -0
- package/dist/config/native-permission-projection.js.map +1 -0
- package/dist/config/native-projection-backup.d.ts +8 -0
- package/dist/config/native-projection-backup.d.ts.map +1 -0
- package/dist/config/native-projection-backup.js +19 -0
- package/dist/config/native-projection-backup.js.map +1 -0
- package/dist/config/native-projection-policy.d.ts +10 -0
- package/dist/config/native-projection-policy.d.ts.map +1 -0
- package/dist/config/native-projection-policy.js +9 -0
- package/dist/config/native-projection-policy.js.map +1 -0
- package/dist/config/native-projection-state.d.ts +57 -0
- package/dist/config/native-projection-state.d.ts.map +1 -0
- package/dist/config/native-projection-state.js +199 -0
- package/dist/config/native-projection-state.js.map +1 -0
- package/dist/config/native-skill-projection.d.ts +24 -0
- package/dist/config/native-skill-projection.d.ts.map +1 -0
- package/dist/config/native-skill-projection.js +170 -0
- package/dist/config/native-skill-projection.js.map +1 -0
- package/dist/config/operator-identity-context.d.ts +7 -0
- package/dist/config/operator-identity-context.d.ts.map +1 -0
- package/dist/config/operator-identity-context.js +46 -0
- package/dist/config/operator-identity-context.js.map +1 -0
- package/dist/config/operator-identity-context.test.d.ts +2 -0
- package/dist/config/operator-identity-context.test.d.ts.map +1 -0
- package/dist/config/operator-identity-context.test.js +61 -0
- package/dist/config/operator-identity-context.test.js.map +1 -0
- package/dist/config/operator-voice.d.ts +10 -0
- package/dist/config/operator-voice.d.ts.map +1 -0
- package/dist/config/operator-voice.js +29 -0
- package/dist/config/operator-voice.js.map +1 -0
- package/dist/config/provider-route-candidates.d.ts +20 -0
- package/dist/config/provider-route-candidates.d.ts.map +1 -0
- package/dist/config/provider-route-candidates.js +211 -0
- package/dist/config/provider-route-candidates.js.map +1 -0
- package/dist/config/provider-route-candidates.test.d.ts +2 -0
- package/dist/config/provider-route-candidates.test.d.ts.map +1 -0
- package/dist/config/provider-route-candidates.test.js +150 -0
- package/dist/config/provider-route-candidates.test.js.map +1 -0
- package/dist/config/skill-registry.d.ts +9 -0
- package/dist/config/skill-registry.d.ts.map +1 -0
- package/dist/config/skill-registry.js +13 -0
- package/dist/config/skill-registry.js.map +1 -0
- package/dist/config/skill-registry.test.d.ts +2 -0
- package/dist/config/skill-registry.test.d.ts.map +1 -0
- package/dist/config/skill-registry.test.js +64 -0
- package/dist/config/skill-registry.test.js.map +1 -0
- package/dist/config/task-skill-selection.d.ts +24 -0
- package/dist/config/task-skill-selection.d.ts.map +1 -0
- package/dist/config/task-skill-selection.js +79 -0
- package/dist/config/task-skill-selection.js.map +1 -0
- package/dist/config/translators/claude-translator.d.ts +7 -0
- package/dist/config/translators/claude-translator.d.ts.map +1 -0
- package/dist/config/translators/claude-translator.js +30 -0
- package/dist/config/translators/claude-translator.js.map +1 -0
- package/dist/config/translators/codex-translator.d.ts +7 -0
- package/dist/config/translators/codex-translator.d.ts.map +1 -0
- package/dist/config/translators/codex-translator.js +20 -0
- package/dist/config/translators/codex-translator.js.map +1 -0
- package/dist/config/translators/opencode-translator.d.ts +7 -0
- package/dist/config/translators/opencode-translator.d.ts.map +1 -0
- package/dist/config/translators/opencode-translator.js +19 -0
- package/dist/config/translators/opencode-translator.js.map +1 -0
- package/dist/config/translators/permission-projection.d.ts +26 -0
- package/dist/config/translators/permission-projection.d.ts.map +1 -0
- package/dist/config/translators/permission-projection.js +22 -0
- package/dist/config/translators/permission-projection.js.map +1 -0
- package/dist/config/web-tools-config.d.ts +45 -0
- package/dist/config/web-tools-config.d.ts.map +1 -0
- package/dist/config/web-tools-config.js +846 -0
- package/dist/config/web-tools-config.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/engines/engine-registry.d.ts +45 -0
- package/dist/engines/engine-registry.d.ts.map +1 -0
- package/dist/engines/engine-registry.js +125 -0
- package/dist/engines/engine-registry.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +141 -18
- package/dist/index.js.map +1 -1
- package/dist/kiln-yaml-types.d.ts +207 -1
- package/dist/kiln-yaml-types.d.ts.map +1 -1
- package/dist/kiln-yaml-types.js +29 -0
- package/dist/kiln-yaml-types.js.map +1 -1
- package/dist/kiln-yaml.d.ts +1 -1
- package/dist/kiln-yaml.d.ts.map +1 -1
- package/dist/kiln-yaml.js +93 -0
- package/dist/kiln-yaml.js.map +1 -1
- package/dist/mcp/config-generator.d.ts.map +1 -1
- package/dist/mcp/config-generator.js +8 -7
- package/dist/mcp/config-generator.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -25
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -103
- package/dist/mcp/index.js.map +1 -1
- package/dist/wrapper/__tests__/session-manager-context-governor.test.d.ts +2 -0
- package/dist/wrapper/__tests__/session-manager-context-governor.test.d.ts.map +1 -0
- package/dist/wrapper/__tests__/session-manager-context-governor.test.js +210 -0
- package/dist/wrapper/__tests__/session-manager-context-governor.test.js.map +1 -0
- package/dist/wrapper/claude-code-process.d.ts +1 -0
- package/dist/wrapper/claude-code-process.d.ts.map +1 -1
- package/dist/wrapper/claude-code-process.js +32 -19
- package/dist/wrapper/claude-code-process.js.map +1 -1
- package/dist/wrapper/cleanup-registry.d.ts.map +1 -1
- package/dist/wrapper/cleanup-registry.js +3 -1
- package/dist/wrapper/cleanup-registry.js.map +1 -1
- package/dist/wrapper/codex-session.d.ts +3 -0
- package/dist/wrapper/codex-session.d.ts.map +1 -1
- package/dist/wrapper/codex-session.js +193 -85
- package/dist/wrapper/codex-session.js.map +1 -1
- package/dist/wrapper/debug.d.ts.map +1 -1
- package/dist/wrapper/debug.js +2 -0
- package/dist/wrapper/debug.js.map +1 -1
- package/dist/wrapper/direct-provider-adapter-factory.d.ts +12 -0
- package/dist/wrapper/direct-provider-adapter-factory.d.ts.map +1 -0
- package/dist/wrapper/direct-provider-adapter-factory.js +99 -0
- package/dist/wrapper/direct-provider-adapter-factory.js.map +1 -0
- package/dist/wrapper/index.d.ts +0 -2
- package/dist/wrapper/index.d.ts.map +1 -1
- package/dist/wrapper/index.js +0 -1
- package/dist/wrapper/index.js.map +1 -1
- package/dist/wrapper/opencode-session.d.ts +4 -0
- package/dist/wrapper/opencode-session.d.ts.map +1 -1
- package/dist/wrapper/opencode-session.js +245 -38
- package/dist/wrapper/opencode-session.js.map +1 -1
- package/dist/wrapper/permission-evaluator.d.ts +2 -1
- package/dist/wrapper/permission-evaluator.d.ts.map +1 -1
- package/dist/wrapper/permission-evaluator.js +54 -0
- package/dist/wrapper/permission-evaluator.js.map +1 -1
- package/dist/wrapper/permission-normalizer.d.ts +5 -1
- package/dist/wrapper/permission-normalizer.d.ts.map +1 -1
- package/dist/wrapper/permission-normalizer.js +17 -0
- package/dist/wrapper/permission-normalizer.js.map +1 -1
- package/dist/wrapper/permission-policy-authorizer.d.ts +1 -1
- package/dist/wrapper/permission-policy-authorizer.js +1 -1
- package/dist/wrapper/pooled-harness-session.d.ts +24 -0
- package/dist/wrapper/pooled-harness-session.d.ts.map +1 -0
- package/dist/wrapper/pooled-harness-session.js +123 -0
- package/dist/wrapper/pooled-harness-session.js.map +1 -0
- package/dist/wrapper/preamble-builder.d.ts +4 -1
- package/dist/wrapper/preamble-builder.d.ts.map +1 -1
- package/dist/wrapper/preamble-builder.js +48 -20
- package/dist/wrapper/preamble-builder.js.map +1 -1
- package/dist/wrapper/provider-session.d.ts +25 -5
- package/dist/wrapper/provider-session.d.ts.map +1 -1
- package/dist/wrapper/provider-session.js +562 -138
- package/dist/wrapper/provider-session.js.map +1 -1
- package/dist/wrapper/session-manager.d.ts.map +1 -1
- package/dist/wrapper/session-manager.js +16 -5
- package/dist/wrapper/session-manager.js.map +1 -1
- package/dist/wrapper/session-registry.d.ts +11 -1
- package/dist/wrapper/session-registry.d.ts.map +1 -1
- package/dist/wrapper/session-registry.js +167 -259
- package/dist/wrapper/session-registry.js.map +1 -1
- package/dist/wrapper/session-store.d.ts +33 -10
- package/dist/wrapper/session-store.d.ts.map +1 -1
- package/dist/wrapper/session-store.js +327 -84
- package/dist/wrapper/session-store.js.map +1 -1
- package/dist/wrapper/session.d.ts +55 -2
- package/dist/wrapper/session.d.ts.map +1 -1
- package/dist/wrapper/session.js +11 -2
- package/dist/wrapper/session.js.map +1 -1
- package/package.json +8 -8
- package/dist/application/__tests__/plan-exit-tool.test.d.ts +0 -2
- package/dist/application/__tests__/plan-exit-tool.test.d.ts.map +0 -1
- package/dist/application/__tests__/plan-exit-tool.test.js +0 -12
- package/dist/application/__tests__/plan-exit-tool.test.js.map +0 -1
- package/dist/application/context-governor.d.ts +0 -26
- package/dist/application/context-governor.d.ts.map +0 -1
- package/dist/application/context-governor.js +0 -164
- package/dist/application/context-governor.js.map +0 -1
- package/dist/application/plan-exit-tool.d.ts +0 -19
- package/dist/application/plan-exit-tool.d.ts.map +0 -1
- package/dist/application/plan-exit-tool.js +0 -13
- package/dist/application/plan-exit-tool.js.map +0 -1
- package/dist/commands/serve.d.ts +0 -7
- package/dist/commands/serve.d.ts.map +0 -1
- package/dist/commands/serve.js +0 -24
- package/dist/commands/serve.js.map +0 -1
- package/dist/mcp/server.d.ts +0 -36
- package/dist/mcp/server.d.ts.map +0 -1
- package/dist/mcp/server.js +0 -156
- package/dist/mcp/server.js.map +0 -1
- package/dist/mcp/transports.d.ts +0 -28
- package/dist/mcp/transports.d.ts.map +0 -1
- package/dist/mcp/transports.js +0 -108
- package/dist/mcp/transports.js.map +0 -1
- package/dist/mcp-entry.d.ts +0 -3
- package/dist/mcp-entry.d.ts.map +0 -1
- package/dist/mcp-entry.js +0 -19
- package/dist/mcp-entry.js.map +0 -1
- package/dist/sync/agent-sync.d.ts +0 -13
- package/dist/sync/agent-sync.d.ts.map +0 -1
- package/dist/sync/agent-sync.js +0 -130
- package/dist/sync/agent-sync.js.map +0 -1
- package/dist/sync/agent-sync.test.d.ts +0 -2
- package/dist/sync/agent-sync.test.d.ts.map +0 -1
- package/dist/sync/agent-sync.test.js +0 -130
- package/dist/sync/agent-sync.test.js.map +0 -1
- package/dist/sync/agents-md-sync.d.ts +0 -7
- package/dist/sync/agents-md-sync.d.ts.map +0 -1
- package/dist/sync/agents-md-sync.js +0 -44
- package/dist/sync/agents-md-sync.js.map +0 -1
- package/dist/sync/agents-md-sync.test.d.ts +0 -2
- package/dist/sync/agents-md-sync.test.d.ts.map +0 -1
- package/dist/sync/agents-md-sync.test.js +0 -154
- package/dist/sync/agents-md-sync.test.js.map +0 -1
- package/dist/sync/hook-sync.d.ts +0 -8
- package/dist/sync/hook-sync.d.ts.map +0 -1
- package/dist/sync/hook-sync.js +0 -90
- package/dist/sync/hook-sync.js.map +0 -1
- package/dist/sync/security-sync.d.ts +0 -9
- package/dist/sync/security-sync.d.ts.map +0 -1
- package/dist/sync/security-sync.js +0 -161
- package/dist/sync/security-sync.js.map +0 -1
- package/dist/sync/skill-sync.d.ts +0 -10
- package/dist/sync/skill-sync.d.ts.map +0 -1
- package/dist/sync/skill-sync.js +0 -87
- package/dist/sync/skill-sync.js.map +0 -1
- package/dist/sync/skill-sync.test.d.ts +0 -2
- package/dist/sync/skill-sync.test.d.ts.map +0 -1
- package/dist/sync/skill-sync.test.js +0 -163
- package/dist/sync/skill-sync.test.js.map +0 -1
- package/dist/wrapper/executable-provider-session.d.ts +0 -26
- package/dist/wrapper/executable-provider-session.d.ts.map +0 -1
- package/dist/wrapper/executable-provider-session.js +0 -214
- package/dist/wrapper/executable-provider-session.js.map +0 -1
|
@@ -1,38 +1,174 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { AllCredentialsExhaustedError, EventBus, KilnError, appendExecutionIdentity, getDirectProviderExecutionProfile, resolveExecutionIdentity, textPart, resolveDirectProviderExecutionProfile, } from "@kilnai/core";
|
|
3
|
+
import { buildEffectiveTurnAuthorityPolicyInputs, createAttachedRuntimeBuiltinToolSurface, } from "@kilnai/runtime";
|
|
3
4
|
import { buildProviderSystemPrompt } from "./preamble-builder.js";
|
|
5
|
+
import { PermissionPolicyAuthorizer } from "./permission-policy-authorizer.js";
|
|
4
6
|
import { ProviderContextTracker } from "./provider-context.js";
|
|
7
|
+
import { createDirectProviderAdapter } from "./direct-provider-adapter-factory.js";
|
|
8
|
+
import { createCliOperatorThemeController } from "../application/operator-theme-preferences.js";
|
|
5
9
|
const PROVIDER_PRIORITY = {
|
|
10
|
+
"codex-oauth": 1,
|
|
11
|
+
"opencode-go": 2,
|
|
12
|
+
"opencode-zen": 3,
|
|
6
13
|
anthropic: 4,
|
|
7
14
|
openai: 5,
|
|
8
15
|
openrouter: 6,
|
|
9
16
|
deepseek: 7,
|
|
10
17
|
ollama: 8,
|
|
18
|
+
lmstudio: 9,
|
|
11
19
|
};
|
|
20
|
+
function getDefaultBillingMode(provider) {
|
|
21
|
+
const profile = getDirectProviderExecutionProfile(provider);
|
|
22
|
+
if (profile?.defaultBillingMode === "metered"
|
|
23
|
+
|| profile?.defaultBillingMode === "free"
|
|
24
|
+
|| profile?.defaultBillingMode === "subscription") {
|
|
25
|
+
return profile.defaultBillingMode;
|
|
26
|
+
}
|
|
27
|
+
return provider === "ollama" || provider === "lmstudio" ? "free" : "metered";
|
|
28
|
+
}
|
|
29
|
+
function filterCapabilityMap(capabilities, allowlist) {
|
|
30
|
+
const filtered = new Map();
|
|
31
|
+
for (const [name, capability] of capabilities.entries()) {
|
|
32
|
+
if (allowlist.has(name)) {
|
|
33
|
+
filtered.set(name, capability);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return filtered;
|
|
37
|
+
}
|
|
38
|
+
function authorityDescriptorFromCapability(toolName, capability) {
|
|
39
|
+
const annotations = capability?.annotations;
|
|
40
|
+
if (!annotations) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
if (annotations?.destructive) {
|
|
44
|
+
return {
|
|
45
|
+
level: 4,
|
|
46
|
+
allowed: false,
|
|
47
|
+
requiresApproval: true,
|
|
48
|
+
reason: `Destructive tool "${toolName}" requires approval`,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (annotations?.readOnly) {
|
|
52
|
+
return {
|
|
53
|
+
level: 1,
|
|
54
|
+
allowed: true,
|
|
55
|
+
requiresApproval: false,
|
|
56
|
+
reason: "Read-only tool, auto-execute",
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (annotations?.idempotent) {
|
|
60
|
+
return {
|
|
61
|
+
level: 2,
|
|
62
|
+
allowed: true,
|
|
63
|
+
requiresApproval: false,
|
|
64
|
+
reason: "Audited execution",
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
level: 2,
|
|
69
|
+
allowed: true,
|
|
70
|
+
requiresApproval: false,
|
|
71
|
+
reason: "Audited execution",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function resolveExecutionMode(config) {
|
|
75
|
+
const profile = resolveProfile(config);
|
|
76
|
+
return profile?.executionMode ?? "text-only";
|
|
77
|
+
}
|
|
78
|
+
function toSessionToolUseEvent(content) {
|
|
79
|
+
try {
|
|
80
|
+
const parsed = JSON.parse(content);
|
|
81
|
+
return {
|
|
82
|
+
type: "tool_use",
|
|
83
|
+
toolName: typeof parsed.name === "string" && parsed.name.length > 0 ? parsed.name : "provider_tool_call",
|
|
84
|
+
input: parsed.input ?? {},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return {
|
|
89
|
+
type: "tool_use",
|
|
90
|
+
toolName: "provider_tool_call",
|
|
91
|
+
input: {},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function resolveProfile(config) {
|
|
96
|
+
return config.executionProfile ?? resolveDirectProviderExecutionProfile({
|
|
97
|
+
provider: config.provider,
|
|
98
|
+
model: config.model,
|
|
99
|
+
requestedExecutionMode: config.executionMode,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function toolCalledToSessionEvent(event) {
|
|
103
|
+
return {
|
|
104
|
+
type: "tool_use",
|
|
105
|
+
toolName: event.toolName,
|
|
106
|
+
input: event.toolInput ?? {},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function toolResultToSessionEvent(event) {
|
|
110
|
+
const output = event.output ?? event.resultSummary ?? "";
|
|
111
|
+
return {
|
|
112
|
+
type: "tool_result",
|
|
113
|
+
toolName: event.toolName,
|
|
114
|
+
output,
|
|
115
|
+
...(event.resultSummary !== undefined && event.resultSummary !== output ? { outputSummary: event.resultSummary } : {}),
|
|
116
|
+
...(event.isError ? { isError: true } : {}),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function deriveCapabilities(config, builtinToolNames) {
|
|
120
|
+
const executionMode = resolveExecutionMode(config);
|
|
121
|
+
const supportedTools = executionMode === "kiln-executable"
|
|
122
|
+
? [...builtinToolNames]
|
|
123
|
+
: [];
|
|
124
|
+
return {
|
|
125
|
+
mcp: false,
|
|
126
|
+
streaming: true,
|
|
127
|
+
resumable: false,
|
|
128
|
+
resume: false,
|
|
129
|
+
costTrackingMode: "computed",
|
|
130
|
+
supportedTools,
|
|
131
|
+
maxContextTokens: null,
|
|
132
|
+
priority: PROVIDER_PRIORITY[config.provider],
|
|
133
|
+
fallbackTo: null,
|
|
134
|
+
permissionPolicy: config.permissionPolicy,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
12
137
|
export class ProviderSession {
|
|
13
138
|
config;
|
|
14
139
|
sessionId;
|
|
15
140
|
_capabilities;
|
|
141
|
+
executionProfile;
|
|
142
|
+
executionMode;
|
|
143
|
+
resolvedModel;
|
|
16
144
|
contextTracker;
|
|
145
|
+
builtinTools;
|
|
146
|
+
toolDefinitions;
|
|
147
|
+
capabilityMap;
|
|
148
|
+
eventBus;
|
|
17
149
|
constructor(config) {
|
|
18
150
|
this.config = config;
|
|
19
151
|
this.sessionId = randomUUID();
|
|
152
|
+
this.executionProfile = resolveProfile(config);
|
|
153
|
+
this.executionMode = this.executionProfile?.executionMode ?? "text-only";
|
|
154
|
+
this.resolvedModel = this.executionProfile?.model ?? config.model;
|
|
20
155
|
this.contextTracker = new ProviderContextTracker({
|
|
21
156
|
maxContextTokens: 128000,
|
|
22
157
|
compactionThreshold: 0.85,
|
|
23
158
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
streaming: true,
|
|
27
|
-
resumable: false,
|
|
28
|
-
resume: false,
|
|
29
|
-
costTrackingMode: "computed",
|
|
30
|
-
supportedTools: [],
|
|
31
|
-
maxContextTokens: null,
|
|
32
|
-
priority: PROVIDER_PRIORITY[config.provider],
|
|
33
|
-
fallbackTo: null,
|
|
34
|
-
permissionPolicy: config.permissionPolicy,
|
|
159
|
+
const operatorSurface = config.operatorSurface ?? {
|
|
160
|
+
theme: createCliOperatorThemeController(),
|
|
35
161
|
};
|
|
162
|
+
const builtinToolSurface = createAttachedRuntimeBuiltinToolSurface({
|
|
163
|
+
operatorSurface,
|
|
164
|
+
builtinToolOptions: config.builtinToolOptions,
|
|
165
|
+
managedInvocation: config.managedInvocation,
|
|
166
|
+
});
|
|
167
|
+
this.builtinTools = builtinToolSurface.callBuiltinTools;
|
|
168
|
+
this.toolDefinitions = builtinToolSurface.toolDefinitions;
|
|
169
|
+
this.capabilityMap = builtinToolSurface.capabilities;
|
|
170
|
+
this.eventBus = new EventBus(100);
|
|
171
|
+
this._capabilities = deriveCapabilities(config, builtinToolSurface.toolDefinitions.map((tool) => tool.name));
|
|
36
172
|
}
|
|
37
173
|
get capabilities() {
|
|
38
174
|
return this._capabilities;
|
|
@@ -42,7 +178,6 @@ export class ProviderSession {
|
|
|
42
178
|
}
|
|
43
179
|
async *run(options) {
|
|
44
180
|
const startedAt = Date.now();
|
|
45
|
-
let isError = false;
|
|
46
181
|
if (options.abortSignal?.aborted) {
|
|
47
182
|
yield {
|
|
48
183
|
type: "error",
|
|
@@ -60,149 +195,438 @@ export class ProviderSession {
|
|
|
60
195
|
return;
|
|
61
196
|
}
|
|
62
197
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
198
|
+
if (this.executionMode === "kiln-executable") {
|
|
199
|
+
yield* this.runKilnExecutable(options, startedAt);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
yield* this.runTextOnly(options, startedAt);
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
const code = this.executionMode === "kiln-executable"
|
|
206
|
+
? "EXECUTABLE_SESSION_ERROR"
|
|
207
|
+
: "PROVIDER_SESSION_ERROR";
|
|
208
|
+
const message = this.executionMode === "kiln-executable"
|
|
209
|
+
? formatExecutableSessionError(err)
|
|
210
|
+
: formatProviderSessionError(err);
|
|
211
|
+
yield { type: "error", code, message, isRetryable: false };
|
|
212
|
+
yield { type: "completed", totalUsd: 0, durationMs: Date.now() - startedAt, isError: true, isPreflightCrash: false };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async dispose() {
|
|
216
|
+
// Stateless direct-provider session; no process/socket lifecycle to tear down.
|
|
217
|
+
}
|
|
218
|
+
isStructuredPreamble(prompt) {
|
|
219
|
+
return prompt.trimStart().startsWith("<kiln-preamble>");
|
|
220
|
+
}
|
|
221
|
+
buildSystemAndPrompt(options) {
|
|
222
|
+
const hasStructuredPreamble = this.isStructuredPreamble(options.prompt);
|
|
223
|
+
const baseSystemPrompt = options.system ?? (hasStructuredPreamble ? options.prompt : (this.config.systemPrompt ?? ""));
|
|
224
|
+
const userPrompt = hasStructuredPreamble ? this.config.task : options.prompt;
|
|
225
|
+
const systemPrompt = appendExecutionIdentity(buildProviderSystemPrompt(baseSystemPrompt, this.config.constraintInstructions, { executionMode: this.executionMode }), resolveExecutionIdentity({
|
|
226
|
+
configuredProvider: this.config.provider,
|
|
227
|
+
configuredModel: this.resolvedModel,
|
|
228
|
+
configuredBillingMode: getDefaultBillingMode(this.config.provider),
|
|
229
|
+
}));
|
|
230
|
+
return { systemPrompt, userPrompt };
|
|
231
|
+
}
|
|
232
|
+
buildConversationMessages(userPrompt, messages) {
|
|
233
|
+
const hydrated = [];
|
|
234
|
+
if (messages && messages.length > 0) {
|
|
235
|
+
for (let i = 0; i < messages.length - 1; i++) {
|
|
236
|
+
const message = messages[i];
|
|
237
|
+
if (message) {
|
|
238
|
+
hydrated.push(message);
|
|
103
239
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
hydrated.push({ role: "user", parts: [textPart(userPrompt)] });
|
|
243
|
+
return hydrated;
|
|
244
|
+
}
|
|
245
|
+
hydrateConversation(session, messages) {
|
|
246
|
+
for (let i = 0; i < messages.length - 1; i++) {
|
|
247
|
+
const message = messages[i];
|
|
248
|
+
if (!message)
|
|
249
|
+
continue;
|
|
250
|
+
if (message.role === "user") {
|
|
251
|
+
session.addUserMessage(message.parts);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
session.addAssistantMessage(message.parts);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async *runTextOnly(options, startedAt) {
|
|
259
|
+
let isError = false;
|
|
260
|
+
const adapter = await createDirectProviderAdapter({
|
|
261
|
+
provider: this.config.provider,
|
|
262
|
+
model: this.resolvedModel,
|
|
263
|
+
configEnv: this.config.env,
|
|
264
|
+
runtimeEnv: options.env,
|
|
265
|
+
});
|
|
266
|
+
const { systemPrompt, userPrompt } = this.buildSystemAndPrompt(options);
|
|
267
|
+
const messages = this.buildConversationMessages(userPrompt, options.messages);
|
|
268
|
+
for await (const event of adapter.streamMessage({
|
|
269
|
+
system: systemPrompt,
|
|
270
|
+
messages,
|
|
271
|
+
reasoningEffort: options.reasoningEffort ?? this.config.reasoningEffort,
|
|
272
|
+
})) {
|
|
273
|
+
if (options.abortSignal?.aborted) {
|
|
274
|
+
isError = true;
|
|
275
|
+
yield { type: "error", code: "ABORTED", message: "Aborted during execution", isRetryable: false };
|
|
276
|
+
yield { type: "completed", totalUsd: 0, durationMs: Date.now() - startedAt, isError, isPreflightCrash: false };
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (event.type === "thinking") {
|
|
280
|
+
yield { type: "text_delta", content: event.content, isThinking: true };
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (event.type === "text") {
|
|
284
|
+
yield { type: "text_delta", content: event.content };
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (event.type === "tool_use") {
|
|
288
|
+
yield toSessionToolUseEvent(event.content);
|
|
289
|
+
yield {
|
|
290
|
+
type: "error",
|
|
291
|
+
code: "TOOL_UNSUPPORTED",
|
|
292
|
+
message: "Provider emitted a tool call in text-only execution mode.",
|
|
293
|
+
isRetryable: false,
|
|
294
|
+
};
|
|
295
|
+
isError = true;
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (event.type === "tool_result") {
|
|
299
|
+
yield { type: "tool_result", toolName: "provider_tool_result", output: event.content };
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
if (event.type === "done") {
|
|
303
|
+
const doneEvent = event;
|
|
304
|
+
const inputTokens = typeof doneEvent.inputTokens === "number" ? doneEvent.inputTokens : 0;
|
|
305
|
+
const outputTokens = typeof doneEvent.outputTokens === "number" ? doneEvent.outputTokens : 0;
|
|
306
|
+
this.contextTracker.update(inputTokens, outputTokens);
|
|
307
|
+
yield {
|
|
308
|
+
type: "cost_update",
|
|
309
|
+
usd: 0,
|
|
310
|
+
mode: "computed",
|
|
311
|
+
provider: this.config.provider,
|
|
312
|
+
model: this.resolvedModel,
|
|
313
|
+
canonicalModel: this.resolvedModel,
|
|
314
|
+
billingMode: getDefaultBillingMode(this.config.provider),
|
|
315
|
+
inputTokens,
|
|
316
|
+
outputTokens,
|
|
317
|
+
};
|
|
318
|
+
yield { type: "completed", totalUsd: 0, durationMs: Date.now() - startedAt, isError, isPreflightCrash: false };
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
yield {
|
|
323
|
+
type: "cost_update",
|
|
324
|
+
usd: 0,
|
|
325
|
+
mode: "computed",
|
|
326
|
+
provider: this.config.provider,
|
|
327
|
+
model: this.resolvedModel,
|
|
328
|
+
canonicalModel: this.resolvedModel,
|
|
329
|
+
billingMode: getDefaultBillingMode(this.config.provider),
|
|
330
|
+
};
|
|
331
|
+
yield { type: "completed", totalUsd: 0, durationMs: Date.now() - startedAt, isError, isPreflightCrash: false };
|
|
332
|
+
}
|
|
333
|
+
buildPerCallConfig(reasoningEffort, requestedAuthority) {
|
|
334
|
+
if (!requestedAuthority || requestedAuthority === "auto") {
|
|
335
|
+
return {
|
|
336
|
+
...(reasoningEffort ? { reasoningEffort } : {}),
|
|
337
|
+
...(requestedAuthority ? {
|
|
338
|
+
effectiveTurnAuthority: {
|
|
339
|
+
executionMode: "execute",
|
|
340
|
+
requestedAuthority,
|
|
341
|
+
admittedAuthority: "unknown",
|
|
342
|
+
sourcePolicy: "runtime_surface_projection",
|
|
343
|
+
reason: "cli direct-provider requested turn authority",
|
|
344
|
+
completeness: "partial",
|
|
345
|
+
toolCount: this.toolDefinitions.length,
|
|
346
|
+
deniedToolCount: 0,
|
|
347
|
+
policyInputs: buildEffectiveTurnAuthorityPolicyInputs({
|
|
348
|
+
executionMode: "execute",
|
|
349
|
+
requestedAuthority,
|
|
350
|
+
admittedAuthority: "unknown",
|
|
351
|
+
routeReason: "cli direct-provider requested turn authority",
|
|
352
|
+
}),
|
|
353
|
+
},
|
|
354
|
+
} : {}),
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
const admittedToolNames = new Set();
|
|
358
|
+
const toolAuthority = new Map();
|
|
359
|
+
for (const tool of this.toolDefinitions) {
|
|
360
|
+
const capability = this.capabilityMap.get(tool.name);
|
|
361
|
+
const authority = authorityDescriptorFromCapability(tool.name, capability);
|
|
362
|
+
if (!authority || !authority.allowed || authority.requiresApproval) {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
if (requestedAuthority === "read_only") {
|
|
366
|
+
if (capability?.annotations?.readOnly === true && authority.level <= 1) {
|
|
367
|
+
admittedToolNames.add(tool.name);
|
|
368
|
+
toolAuthority.set(tool.name, authority);
|
|
107
369
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (authority.level <= 2) {
|
|
373
|
+
admittedToolNames.add(tool.name);
|
|
374
|
+
toolAuthority.set(tool.name, authority);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
const admittedAuthority = admittedToolNames.size === 0 ? "fail_closed" : requestedAuthority;
|
|
378
|
+
return {
|
|
379
|
+
...(reasoningEffort ? { reasoningEffort } : {}),
|
|
380
|
+
toolAllowlist: admittedToolNames,
|
|
381
|
+
toolAuthority,
|
|
382
|
+
additionalTools: this.toolDefinitions.filter((tool) => admittedToolNames.has(tool.name)),
|
|
383
|
+
perCallCapabilities: filterCapabilityMap(this.capabilityMap, admittedToolNames),
|
|
384
|
+
effectiveTurnAuthority: {
|
|
385
|
+
executionMode: "execute",
|
|
386
|
+
requestedAuthority,
|
|
387
|
+
admittedAuthority,
|
|
388
|
+
sourcePolicy: "runtime_surface_projection",
|
|
389
|
+
reason: "cli direct-provider requested turn authority",
|
|
390
|
+
completeness: "authoritative",
|
|
391
|
+
toolCount: admittedToolNames.size,
|
|
392
|
+
deniedToolCount: Math.max(0, this.toolDefinitions.length - admittedToolNames.size),
|
|
393
|
+
policyInputs: buildEffectiveTurnAuthorityPolicyInputs({
|
|
394
|
+
executionMode: "execute",
|
|
395
|
+
requestedAuthority,
|
|
396
|
+
admittedAuthority,
|
|
397
|
+
routeReason: "cli direct-provider requested turn authority",
|
|
398
|
+
}),
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
async *runKilnExecutable(options, startedAt) {
|
|
403
|
+
const { RuntimeSessionOrchestrator, RuntimeSession } = await import("@kilnai/runtime");
|
|
404
|
+
const { systemPrompt, userPrompt } = this.buildSystemAndPrompt(options);
|
|
405
|
+
const adapter = await createDirectProviderAdapter({
|
|
406
|
+
provider: this.config.provider,
|
|
407
|
+
model: this.resolvedModel,
|
|
408
|
+
configEnv: this.config.env,
|
|
409
|
+
runtimeEnv: options.env,
|
|
410
|
+
});
|
|
411
|
+
const authorizer = new PermissionPolicyAuthorizer(this.config.permissionPolicy);
|
|
412
|
+
const cliSession = new RuntimeSession({
|
|
413
|
+
appName: "kiln-cli",
|
|
414
|
+
tenantId: "cli-session",
|
|
415
|
+
userId: this.sessionId,
|
|
416
|
+
systemPrompt,
|
|
417
|
+
idleTimeoutMs: 30 * 60 * 1000,
|
|
418
|
+
});
|
|
419
|
+
const orchestrator = new RuntimeSessionOrchestrator({
|
|
420
|
+
provider: adapter,
|
|
421
|
+
model: this.resolvedModel,
|
|
422
|
+
tools: this.toolDefinitions,
|
|
423
|
+
builtinTools: this.builtinTools,
|
|
424
|
+
eventBus: this.eventBus,
|
|
425
|
+
toolAuthorizer: authorizer,
|
|
426
|
+
capabilityMap: this.capabilityMap,
|
|
427
|
+
dangerousCommandDetector: undefined,
|
|
428
|
+
});
|
|
429
|
+
if (options.messages && options.messages.length > 0) {
|
|
430
|
+
this.hydrateConversation(cliSession, options.messages);
|
|
431
|
+
}
|
|
432
|
+
const promptParts = [textPart(userPrompt)];
|
|
433
|
+
const liveToolEvents = [];
|
|
434
|
+
let hasLiveToolEvents = false;
|
|
435
|
+
let wakeLiveToolDrain;
|
|
436
|
+
const enqueueLiveToolEvent = (event) => {
|
|
437
|
+
hasLiveToolEvents = true;
|
|
438
|
+
liveToolEvents.push(event);
|
|
439
|
+
wakeLiveToolDrain?.();
|
|
440
|
+
wakeLiveToolDrain = undefined;
|
|
441
|
+
};
|
|
442
|
+
const onToolCalled = (event) => {
|
|
443
|
+
if (event.sessionId !== cliSession.id)
|
|
444
|
+
return;
|
|
445
|
+
enqueueLiveToolEvent(toolCalledToSessionEvent(event));
|
|
446
|
+
};
|
|
447
|
+
const onToolResult = (event) => {
|
|
448
|
+
if (event.sessionId !== cliSession.id)
|
|
449
|
+
return;
|
|
450
|
+
enqueueLiveToolEvent(toolResultToSessionEvent(event));
|
|
451
|
+
};
|
|
452
|
+
this.eventBus.on("tool_called", onToolCalled);
|
|
453
|
+
this.eventBus.on("tool_result", onToolResult);
|
|
454
|
+
let result;
|
|
455
|
+
let processError;
|
|
456
|
+
let processSettled = false;
|
|
457
|
+
const requestedAuthority = options.requestedAuthority ?? this.config.requestedAuthority;
|
|
458
|
+
const processPromise = orchestrator.processMessage(cliSession, promptParts, undefined, undefined, this.buildPerCallConfig(options.reasoningEffort ?? this.config.reasoningEffort, requestedAuthority)).then((nextResult) => {
|
|
459
|
+
result = nextResult;
|
|
460
|
+
}).catch((err) => {
|
|
461
|
+
processError = err;
|
|
462
|
+
}).finally(() => {
|
|
463
|
+
processSettled = true;
|
|
464
|
+
wakeLiveToolDrain?.();
|
|
465
|
+
wakeLiveToolDrain = undefined;
|
|
466
|
+
});
|
|
467
|
+
try {
|
|
468
|
+
while (!processSettled || liveToolEvents.length > 0) {
|
|
469
|
+
while (liveToolEvents.length > 0) {
|
|
470
|
+
yield liveToolEvents.shift();
|
|
113
471
|
}
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
472
|
+
if (!processSettled) {
|
|
473
|
+
await new Promise((resolve) => {
|
|
474
|
+
wakeLiveToolDrain = resolve;
|
|
475
|
+
});
|
|
118
476
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
477
|
+
}
|
|
478
|
+
await processPromise;
|
|
479
|
+
}
|
|
480
|
+
finally {
|
|
481
|
+
this.eventBus.off("tool_called", onToolCalled);
|
|
482
|
+
this.eventBus.off("tool_result", onToolResult);
|
|
483
|
+
}
|
|
484
|
+
if (processError) {
|
|
485
|
+
throw processError;
|
|
486
|
+
}
|
|
487
|
+
if (!result) {
|
|
488
|
+
throw new Error("Runtime session orchestrator did not return a result.");
|
|
489
|
+
}
|
|
490
|
+
let isError = false;
|
|
491
|
+
for (const toolExec of result.toolExecutions ?? []) {
|
|
492
|
+
if (!hasLiveToolEvents) {
|
|
493
|
+
const output = toolExec.output ?? toolExec.resultSummary;
|
|
494
|
+
if (toolExec.toolCallId || toolExec.input) {
|
|
125
495
|
yield {
|
|
126
|
-
type: "
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
isPreflightCrash: false,
|
|
496
|
+
type: "tool_use",
|
|
497
|
+
toolName: toolExec.toolName,
|
|
498
|
+
input: toolExec.input ?? {},
|
|
499
|
+
...(toolExec.toolCallId ? { toolCallId: toolExec.toolCallId } : {}),
|
|
131
500
|
};
|
|
132
|
-
|
|
501
|
+
}
|
|
502
|
+
yield {
|
|
503
|
+
type: "tool_result",
|
|
504
|
+
toolName: toolExec.toolName,
|
|
505
|
+
output,
|
|
506
|
+
...(toolExec.resultSummary !== output ? { outputSummary: toolExec.resultSummary } : {}),
|
|
507
|
+
...(toolExec.toolCallId ? { toolCallId: toolExec.toolCallId } : {}),
|
|
508
|
+
...(!toolExec.success ? { isError: true } : {}),
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
if (toolExec.fileChanges && toolExec.fileChanges.length > 0) {
|
|
512
|
+
for (const fileChange of toolExec.fileChanges) {
|
|
513
|
+
yield { type: "file_changed", path: fileChange.path, changeType: fileChange.changeType };
|
|
133
514
|
}
|
|
134
515
|
}
|
|
135
|
-
yield { type: "cost_update", usd: 0, mode: "computed" };
|
|
136
|
-
yield {
|
|
137
|
-
type: "completed",
|
|
138
|
-
totalUsd: 0,
|
|
139
|
-
durationMs: Date.now() - startedAt,
|
|
140
|
-
isError,
|
|
141
|
-
isPreflightCrash: false,
|
|
142
|
-
};
|
|
143
516
|
}
|
|
144
|
-
|
|
517
|
+
for (const part of result.parts) {
|
|
518
|
+
if (part.type === "text") {
|
|
519
|
+
yield { type: "text_delta", content: part.text };
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (result.escalation) {
|
|
145
523
|
yield {
|
|
146
524
|
type: "error",
|
|
147
|
-
code: "
|
|
148
|
-
message:
|
|
525
|
+
code: "ESCALATION",
|
|
526
|
+
message: result.escalation.reason,
|
|
149
527
|
isRetryable: false,
|
|
150
528
|
};
|
|
151
|
-
|
|
152
|
-
type: "completed",
|
|
153
|
-
totalUsd: 0,
|
|
154
|
-
durationMs: Date.now() - startedAt,
|
|
155
|
-
isError: true,
|
|
156
|
-
isPreflightCrash: false,
|
|
157
|
-
};
|
|
529
|
+
isError = true;
|
|
158
530
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (provider === "anthropic") {
|
|
169
|
-
const apiKey = this.resolveRequiredApiKey("ANTHROPIC_API_KEY", runtimeEnv);
|
|
170
|
-
return new AnthropicAdapter({ apiKey, defaultModel: this.config.model });
|
|
171
|
-
}
|
|
172
|
-
if (provider === "openai") {
|
|
173
|
-
const apiKey = this.resolveRequiredApiKey("OPENAI_API_KEY", runtimeEnv);
|
|
174
|
-
return new OpenAIAdapter({ apiKey, defaultModel: this.config.model });
|
|
175
|
-
}
|
|
176
|
-
if (provider === "deepseek") {
|
|
177
|
-
const apiKey = this.resolveRequiredApiKey("DEEPSEEK_API_KEY", runtimeEnv);
|
|
178
|
-
return new DeepSeekAdapter({ apiKey, defaultModel: this.config.model });
|
|
179
|
-
}
|
|
180
|
-
if (provider === "openrouter") {
|
|
181
|
-
const apiKey = this.resolveRequiredApiKey("OPENROUTER_API_KEY", runtimeEnv);
|
|
182
|
-
const appUrl = this.resolveEnv("OPENROUTER_APP_URL", runtimeEnv);
|
|
183
|
-
const appName = this.resolveEnv("OPENROUTER_APP_NAME", runtimeEnv);
|
|
184
|
-
return new OpenRouterAdapter({
|
|
185
|
-
apiKey,
|
|
186
|
-
defaultModel: this.config.model,
|
|
187
|
-
appUrl,
|
|
188
|
-
appName,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
const baseUrl = this.resolveEnv("OLLAMA_BASE_URL", runtimeEnv);
|
|
192
|
-
return new OllamaAdapter({
|
|
193
|
-
baseUrl,
|
|
194
|
-
defaultModel: this.config.model,
|
|
531
|
+
this.contextTracker.update(result.inputTokens ?? 0, result.outputTokens ?? 0);
|
|
532
|
+
const executionIdentity = resolveExecutionIdentity({
|
|
533
|
+
configuredProvider: this.config.provider,
|
|
534
|
+
configuredModel: this.resolvedModel,
|
|
535
|
+
configuredBillingMode: getDefaultBillingMode(this.config.provider),
|
|
536
|
+
routedProvider: result.routingDecision?.provider,
|
|
537
|
+
routedModel: result.routingDecision?.model,
|
|
538
|
+
routedCanonicalModel: result.routingDecision?.canonicalModel,
|
|
539
|
+
routedBillingMode: result.routingDecision?.billingMode,
|
|
195
540
|
});
|
|
541
|
+
yield {
|
|
542
|
+
type: "cost_update",
|
|
543
|
+
usd: 0,
|
|
544
|
+
mode: "computed",
|
|
545
|
+
provider: executionIdentity?.provider,
|
|
546
|
+
model: executionIdentity?.model,
|
|
547
|
+
canonicalModel: executionIdentity?.canonicalModel,
|
|
548
|
+
billingMode: executionIdentity?.billingMode,
|
|
549
|
+
inputTokens: result.inputTokens,
|
|
550
|
+
outputTokens: result.outputTokens,
|
|
551
|
+
cacheReadTokens: result.cacheReadTokens,
|
|
552
|
+
};
|
|
553
|
+
yield { type: "completed", totalUsd: 0, durationMs: Date.now() - startedAt, isError, isPreflightCrash: false };
|
|
196
554
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
555
|
+
}
|
|
556
|
+
function formatExecutableSessionError(error) {
|
|
557
|
+
if (error instanceof AllCredentialsExhaustedError) {
|
|
558
|
+
return formatCredentialPoolExhaustion(error);
|
|
559
|
+
}
|
|
560
|
+
if (error instanceof KilnError) {
|
|
561
|
+
const status = typeof error.context.status === "number" ? error.context.status : undefined;
|
|
562
|
+
const responseBody = typeof error.context.responseBody === "string"
|
|
563
|
+
? error.context.responseBody.trim()
|
|
564
|
+
: "";
|
|
565
|
+
const toolReplaySummary = typeof error.context.toolReplaySummary === "string"
|
|
566
|
+
? error.context.toolReplaySummary.trim()
|
|
567
|
+
: "";
|
|
568
|
+
const suffixParts = [];
|
|
569
|
+
if (status !== undefined) {
|
|
570
|
+
suffixParts.push(`status ${status}`);
|
|
571
|
+
}
|
|
572
|
+
if (responseBody.length > 0) {
|
|
573
|
+
const compactBody = responseBody.replace(/\s+/g, " ").slice(0, 240);
|
|
574
|
+
suffixParts.push(compactBody);
|
|
201
575
|
}
|
|
202
|
-
|
|
576
|
+
if (toolReplaySummary.length > 0) {
|
|
577
|
+
suffixParts.push(toolReplaySummary);
|
|
578
|
+
}
|
|
579
|
+
if (suffixParts.length === 0) {
|
|
580
|
+
return error.message;
|
|
581
|
+
}
|
|
582
|
+
return `${error.message} (${suffixParts.join(": ")})`;
|
|
203
583
|
}
|
|
204
|
-
|
|
205
|
-
|
|
584
|
+
return formatProviderSessionError(error);
|
|
585
|
+
}
|
|
586
|
+
function formatProviderSessionError(error) {
|
|
587
|
+
if (error instanceof AllCredentialsExhaustedError) {
|
|
588
|
+
return formatCredentialPoolExhaustion(error);
|
|
589
|
+
}
|
|
590
|
+
return readErrorMessage(error);
|
|
591
|
+
}
|
|
592
|
+
function formatCredentialPoolExhaustion(error) {
|
|
593
|
+
const details = [
|
|
594
|
+
formatCredentialOutcome(error.lastOutcome),
|
|
595
|
+
formatCredentialCause(error.cause),
|
|
596
|
+
].filter((detail) => Boolean(detail));
|
|
597
|
+
if (details.length === 0) {
|
|
598
|
+
return error.message;
|
|
206
599
|
}
|
|
600
|
+
return `${error.message}: ${details.join("; ")}`;
|
|
601
|
+
}
|
|
602
|
+
function formatCredentialOutcome(outcome) {
|
|
603
|
+
if (!outcome) {
|
|
604
|
+
return undefined;
|
|
605
|
+
}
|
|
606
|
+
switch (outcome.type) {
|
|
607
|
+
case "rate-limited":
|
|
608
|
+
return outcome.resetAt
|
|
609
|
+
? `last outcome rate-limited until ${new Date(outcome.resetAt).toISOString()}`
|
|
610
|
+
: "last outcome rate-limited";
|
|
611
|
+
case "quota-exceeded":
|
|
612
|
+
return "last outcome quota-exceeded";
|
|
613
|
+
case "auth-failed":
|
|
614
|
+
return "last outcome auth-failed";
|
|
615
|
+
case "connection-failed":
|
|
616
|
+
return "last outcome connection-failed";
|
|
617
|
+
case "unknown-error":
|
|
618
|
+
return outcome.message ? `last outcome unknown-error: ${outcome.message}` : "last outcome unknown-error";
|
|
619
|
+
case "ok":
|
|
620
|
+
return "last outcome ok";
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function formatCredentialCause(cause) {
|
|
624
|
+
if (cause === null || cause === undefined) {
|
|
625
|
+
return undefined;
|
|
626
|
+
}
|
|
627
|
+
return `last error ${readErrorMessage(cause)}`;
|
|
628
|
+
}
|
|
629
|
+
function readErrorMessage(error) {
|
|
630
|
+
return error instanceof Error ? error.message : String(error);
|
|
207
631
|
}
|
|
208
632
|
//# sourceMappingURL=provider-session.js.map
|