@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
package/dist/commands/tui.js
CHANGED
|
@@ -1,17 +1,236 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { loadResumeSidebarInfo, } from "../application/resume-sidebar-info.js";
|
|
1
4
|
import { inferResumeStrategyFeedback } from "../application/resume-strategy-feedback.js";
|
|
2
5
|
import { collectResumeSignals, decideResumeStrategy } from "../application/resume-strategy-policy.js";
|
|
6
|
+
import { deriveSessionMetadata, shouldPromoteLatestPromptToSessionTitle, } from "../application/session-metadata.js";
|
|
3
7
|
import { buildCliPlanSummaryArtifactKeyFromShape, buildCliProjectSummaryArtifactKey, buildCliSessionSummaryArtifactKey, } from "../application/context-artifact-keys.js";
|
|
4
|
-
import { readGlobalConfig } from "../config/global-config.js";
|
|
8
|
+
import { readGlobalConfig, resolveGlobalDefaultModel, resolveGlobalDefaultProvider, resolveGlobalUiTheme, } from "../config/global-config.js";
|
|
9
|
+
import { withGlobalIdentityContext } from "../config/operator-identity-context.js";
|
|
10
|
+
import { withContextCandidates } from "../application/agent-skill-context.js";
|
|
11
|
+
import { resolveInstructionProfileContextCandidates } from "../application/instruction-profile-context.js";
|
|
12
|
+
import { withWorkGovernanceContext } from "../application/work-governance-context.js";
|
|
13
|
+
import { createTranscriptRuntimeSessionHydrator } from "../application/runtime-session-rehydration.js";
|
|
14
|
+
import { readConfigStatusSnapshot } from "../application/config-status.js";
|
|
15
|
+
import { readKilnYaml } from "../kiln-yaml.js";
|
|
16
|
+
import { loadKilnConfig } from "../config/config-merger.js";
|
|
5
17
|
import { resolveEffectiveProvider } from "../config/env-config.js";
|
|
6
|
-
import {
|
|
18
|
+
import { resolveOperatorVoiceRuntime } from "../config/operator-voice.js";
|
|
19
|
+
import { createManagedDirectProviderAdapterFactory } from "../config/managed-agent-direct-adapters.js";
|
|
20
|
+
import { createKilnConfigTools } from "../application/config-tools.js";
|
|
21
|
+
import { createWorkGovernanceTools } from "../application/work-governance-tool.js";
|
|
22
|
+
import { discoverManagedAgentProviderModels } from "../config/managed-agent-provider-models.js";
|
|
23
|
+
import { resolveManagedInvocationToolOptions } from "../config/managed-agent-routes.js";
|
|
24
|
+
import { loadConfiguredBuiltinToolSurfaceOptions } from "../config/builtin-tool-surface-config.js";
|
|
25
|
+
import { resolveEngineAvailabilityMap } from "../engines/engine-registry.js";
|
|
26
|
+
import { createDefaultRegistry, getProviderDisplayInfo, getRuntimeProviderAvailability, } from "../wrapper/session-registry.js";
|
|
7
27
|
import { SessionStore, TranscriptStore } from "../wrapper/session-store.js";
|
|
8
28
|
import { GatewaySession, waitForGateway, themes, kilnDark } from "@kilnai/tui";
|
|
29
|
+
import { GUI_PROVIDER_DISPLAY_ORDER, formatPresentationIntentAsText, getGuiProviderMetadata, isGuiProviderModeless, presentOperatorEventPayload, } from "@kilnai/gateway-contracts";
|
|
30
|
+
import { GoalRunStore, WorkItemStore, createSessionBuiltinToolOptions, extractText, } from "@kilnai/core";
|
|
9
31
|
import { getProjectContextArtifactCache } from "@kilnai/runtime";
|
|
32
|
+
import { createProviderCatalogService, projectGuiOperatorModels, providerRequiresSelectedModelMessage, resolveGuiOperatorDiscoveryResults, resolveGuiProviderSwitch, } from "@kilnai/runtime";
|
|
33
|
+
import { persistTuiThemePreference } from "../application/operator-theme-preferences.js";
|
|
34
|
+
function writeTuiBootstrapStatus(message) {
|
|
35
|
+
if (!process.stderr.isTTY) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
process.stderr.write(`${message}\n`);
|
|
39
|
+
}
|
|
40
|
+
function normalizeProviderModels(models) {
|
|
41
|
+
const unique = new Set();
|
|
42
|
+
for (const model of models ?? []) {
|
|
43
|
+
const trimmed = model.trim();
|
|
44
|
+
if (trimmed.length > 0) {
|
|
45
|
+
unique.add(trimmed);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [...unique];
|
|
49
|
+
}
|
|
50
|
+
function buildTuiStartupProviderDisplayInfo(input) {
|
|
51
|
+
const providerById = new Map();
|
|
52
|
+
for (const provider of input.providerDisplayInfo) {
|
|
53
|
+
providerById.set(provider.id, provider);
|
|
54
|
+
}
|
|
55
|
+
const orderedProviderIds = [];
|
|
56
|
+
const seen = new Set();
|
|
57
|
+
const addOrderedProviderId = (providerId) => {
|
|
58
|
+
if (seen.has(providerId) || !providerById.has(providerId)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
seen.add(providerId);
|
|
62
|
+
orderedProviderIds.push(providerId);
|
|
63
|
+
};
|
|
64
|
+
for (const provider of input.providerDisplayInfo) {
|
|
65
|
+
addOrderedProviderId(provider.id);
|
|
66
|
+
}
|
|
67
|
+
for (const providerId of GUI_PROVIDER_DISPLAY_ORDER) {
|
|
68
|
+
addOrderedProviderId(providerId);
|
|
69
|
+
}
|
|
70
|
+
return orderedProviderIds.flatMap((providerId) => {
|
|
71
|
+
const provider = providerById.get(providerId);
|
|
72
|
+
if (!provider) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
const runtimeModels = normalizeProviderModels(input.runtimeModels[providerId]);
|
|
76
|
+
const models = runtimeModels;
|
|
77
|
+
const runtimeCatalogContainsProvider = Object.prototype.hasOwnProperty.call(input.runtimeModels, providerId);
|
|
78
|
+
const discovery = input.runtimeDiscovery?.find((entry) => entry.provider === providerId);
|
|
79
|
+
const metadata = getGuiProviderMetadata(providerId);
|
|
80
|
+
const includeAuthProvider = Boolean(metadata?.authMethod
|
|
81
|
+
&& discovery
|
|
82
|
+
&& !discovery.available
|
|
83
|
+
&& (discovery.authState === "missing" || discovery.authState === "expired"));
|
|
84
|
+
if (models.length === 0) {
|
|
85
|
+
const includeModelessProvider = input.includeModelessProviders === true
|
|
86
|
+
&& runtimeCatalogContainsProvider
|
|
87
|
+
&& isGuiProviderModeless(providerId);
|
|
88
|
+
if (!includeModelessProvider && !includeAuthProvider && !input.includePendingProviders) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [{
|
|
93
|
+
...provider,
|
|
94
|
+
models,
|
|
95
|
+
available: discovery?.available,
|
|
96
|
+
reason: discovery?.reason,
|
|
97
|
+
}];
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function assertTuiProviderAvailableInStartupCatalog(provider, startupProviderDisplayInfo) {
|
|
101
|
+
const startupProvider = startupProviderDisplayInfo.find((entry) => entry.id === provider);
|
|
102
|
+
if (startupProvider && (startupProvider.models.length > 0 || isGuiProviderModeless(provider))) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const metadata = getGuiProviderMetadata(provider);
|
|
106
|
+
const startupAvailability = startupProvider;
|
|
107
|
+
if (metadata?.authMethod && startupAvailability?.available === false) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const runtimeProviderIds = startupProviderDisplayInfo
|
|
111
|
+
.filter((entry) => entry.models.length > 0 || isGuiProviderModeless(entry.id))
|
|
112
|
+
.map((entry) => entry.id);
|
|
113
|
+
const availableProviders = runtimeProviderIds.length > 0 ? runtimeProviderIds.join(", ") : "none";
|
|
114
|
+
throw new Error(`Provider '${provider}' is not available in the runtime TUI model catalog. Available providers: ${availableProviders}`);
|
|
115
|
+
}
|
|
116
|
+
function latestUserText(messages) {
|
|
117
|
+
if (!messages) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
121
|
+
const message = messages[index];
|
|
122
|
+
if (message?.role !== "user") {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const text = extractText(message.parts).trim();
|
|
126
|
+
return text.length > 0 ? text : undefined;
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
10
130
|
function parseProvider(p, providerIds) {
|
|
11
|
-
|
|
12
|
-
|
|
131
|
+
const requestedProvider = p?.trim() ?? "";
|
|
132
|
+
if (requestedProvider.length === 0) {
|
|
133
|
+
throw new Error("No provider configured. Set --provider, KILN_PROVIDER, or global provider.");
|
|
134
|
+
}
|
|
135
|
+
if (providerIds.includes(requestedProvider)) {
|
|
136
|
+
return requestedProvider;
|
|
13
137
|
}
|
|
14
|
-
|
|
138
|
+
throw new Error(`Unknown provider: ${requestedProvider}`);
|
|
139
|
+
}
|
|
140
|
+
function mapTranscriptTypeToKind(type) {
|
|
141
|
+
switch (type) {
|
|
142
|
+
case "user":
|
|
143
|
+
return "user_message";
|
|
144
|
+
case "text_delta":
|
|
145
|
+
return "assistant_delta";
|
|
146
|
+
case "tool_use":
|
|
147
|
+
return "tool_call_started";
|
|
148
|
+
case "tool_result":
|
|
149
|
+
return "tool_call_completed";
|
|
150
|
+
case "error":
|
|
151
|
+
return "error_recorded";
|
|
152
|
+
default:
|
|
153
|
+
return "assistant_message";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function mapTranscriptTypeToSource(type, surface) {
|
|
157
|
+
const component = surface === "gui" ? "gui-command" : "tui-command";
|
|
158
|
+
switch (type) {
|
|
159
|
+
case "user":
|
|
160
|
+
return { actor: "user", surface, component };
|
|
161
|
+
case "text_delta":
|
|
162
|
+
return { actor: "assistant", surface, component };
|
|
163
|
+
case "tool_use":
|
|
164
|
+
case "tool_result":
|
|
165
|
+
return { actor: "tool", surface, component };
|
|
166
|
+
case "error":
|
|
167
|
+
return { actor: "runtime", surface, component };
|
|
168
|
+
default:
|
|
169
|
+
return { actor: "system", surface, component };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function toPersistedTranscriptEvent(sessionId, sequence, type, payload, surface, turnId) {
|
|
173
|
+
return {
|
|
174
|
+
eventId: randomUUID(),
|
|
175
|
+
kilnSessionId: sessionId,
|
|
176
|
+
sequence,
|
|
177
|
+
timestamp: new Date().toISOString(),
|
|
178
|
+
kind: mapTranscriptTypeToKind(type),
|
|
179
|
+
source: mapTranscriptTypeToSource(type, surface),
|
|
180
|
+
...(turnId ? { turnId } : {}),
|
|
181
|
+
payload,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function persistedEvent(sessionId, sequence, kind, source, payload, turnId) {
|
|
185
|
+
return {
|
|
186
|
+
eventId: randomUUID(),
|
|
187
|
+
kilnSessionId: sessionId,
|
|
188
|
+
sequence,
|
|
189
|
+
timestamp: new Date().toISOString(),
|
|
190
|
+
kind,
|
|
191
|
+
source,
|
|
192
|
+
...(turnId ? { turnId } : {}),
|
|
193
|
+
payload,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function parseToolResultEnvelope(value) {
|
|
197
|
+
if (!value)
|
|
198
|
+
return { output: "" };
|
|
199
|
+
try {
|
|
200
|
+
const parsed = JSON.parse(value);
|
|
201
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
202
|
+
return { output: value };
|
|
203
|
+
}
|
|
204
|
+
const record = parsed;
|
|
205
|
+
const output = typeof record.output === "string" ? record.output : value;
|
|
206
|
+
const metadata = record.metadata && typeof record.metadata === "object" && !Array.isArray(record.metadata)
|
|
207
|
+
? record.metadata
|
|
208
|
+
: undefined;
|
|
209
|
+
return {
|
|
210
|
+
output,
|
|
211
|
+
...(typeof record.isError === "boolean" ? { isError: record.isError } : {}),
|
|
212
|
+
...(metadata ? { metadata } : {}),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
return { output: value };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function buildToolResultPayload(input) {
|
|
220
|
+
const full = parseToolResultEnvelope(input.output);
|
|
221
|
+
const summary = parseToolResultEnvelope(input.outputSummary);
|
|
222
|
+
const outputSummary = summary.output || full.output.slice(0, 200);
|
|
223
|
+
const isError = full.isError ?? input.isError ?? false;
|
|
224
|
+
return {
|
|
225
|
+
toolCallId: input.toolCallId,
|
|
226
|
+
toolName: input.toolName,
|
|
227
|
+
output: full.output,
|
|
228
|
+
outputSummary,
|
|
229
|
+
...(full.metadata ? { metadata: full.metadata } : {}),
|
|
230
|
+
status: {
|
|
231
|
+
state: isError ? "failed" : "succeeded",
|
|
232
|
+
},
|
|
233
|
+
};
|
|
15
234
|
}
|
|
16
235
|
function resolveTuiStartupTransport(_flags) {
|
|
17
236
|
if (process.env.KILN_TUI_TRANSPORT?.toLowerCase() === "direct") {
|
|
@@ -23,24 +242,14 @@ function resolveTuiStartupTransport(_flags) {
|
|
|
23
242
|
* Dynamic session factory that supports cross-provider session management.
|
|
24
243
|
* Each provider maintains independent session state, allowing seamless switching.
|
|
25
244
|
*/
|
|
26
|
-
export async function makeMultiProviderSessionFactory(initialProvider, providerIds, cwd, registry, sessionStore, transcriptStore, contextArtifactCache) {
|
|
245
|
+
export async function makeMultiProviderSessionFactory(initialProvider, providerIds, cwd, registry, sessionStore, transcriptStore, contextArtifactCache, builtinToolOptions, transcriptSurface = "tui", managedInvocation) {
|
|
27
246
|
const providers = providerIds;
|
|
28
247
|
// Per-provider session state
|
|
29
248
|
const providerState = new Map(providers.map((provider) => [provider, {}]));
|
|
249
|
+
const providerModelState = new Map(providers.map((provider) => [provider, ""]));
|
|
250
|
+
const sessionBuiltinToolOptions = createSessionBuiltinToolOptions(builtinToolOptions);
|
|
30
251
|
let currentProvider = initialProvider;
|
|
31
|
-
|
|
32
|
-
// Load last session for each provider
|
|
33
|
-
for (const p of providers) {
|
|
34
|
-
const lastRecord = await sessionStore.last(p);
|
|
35
|
-
if (lastRecord) {
|
|
36
|
-
const state = providerState.get(p);
|
|
37
|
-
if (!state)
|
|
38
|
-
continue;
|
|
39
|
-
state.resumeSessionId = lastRecord.sessionId;
|
|
40
|
-
state.providerSessionId = lastRecord.providerSessionId;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const policyAwareFactory = (systemPrompt, sessionCwd) => {
|
|
252
|
+
const policyAwareFactory = (systemPrompt, sessionCwd, context) => {
|
|
44
253
|
let activeSession = null;
|
|
45
254
|
return {
|
|
46
255
|
get capabilities() {
|
|
@@ -65,7 +274,10 @@ export async function makeMultiProviderSessionFactory(initialProvider, providerI
|
|
|
65
274
|
},
|
|
66
275
|
run: async function* (options) {
|
|
67
276
|
const providerForTurn = currentProvider;
|
|
68
|
-
|
|
277
|
+
if (!providerForTurn) {
|
|
278
|
+
throw new Error("No provider selected for this turn.");
|
|
279
|
+
}
|
|
280
|
+
const modelForTurn = providerModelState.get(providerForTurn) || undefined;
|
|
69
281
|
const state = providerState.get(providerForTurn) ?? {};
|
|
70
282
|
const resumedFrom = state.resumeSessionId;
|
|
71
283
|
const projectArtifactKey = buildCliProjectSummaryArtifactKey(cwd);
|
|
@@ -94,16 +306,47 @@ export async function makeMultiProviderSessionFactory(initialProvider, providerI
|
|
|
94
306
|
cwd: sessionCwd || cwd,
|
|
95
307
|
permissionPolicy: { approval: "never", sandbox: "workspace-write" },
|
|
96
308
|
resumeSessionId: decision.shouldUseProviderNativeResume ? resumedFrom : undefined,
|
|
309
|
+
sessionLedgerOwner: "host",
|
|
97
310
|
model: modelForTurn,
|
|
311
|
+
reasoningEffort: options.reasoningEffort,
|
|
312
|
+
...(context?.operatorSurface ? { operatorSurface: context.operatorSurface } : {}),
|
|
313
|
+
builtinToolOptions: sessionBuiltinToolOptions,
|
|
314
|
+
...(managedInvocation ? { managedInvocation } : {}),
|
|
98
315
|
});
|
|
99
316
|
activeSession = resumedSession;
|
|
100
|
-
const capturedId = resumedSession.sessionId;
|
|
317
|
+
const capturedId = options.kilnSessionId ?? context?.kilnSessionId ?? resumedFrom ?? resumedSession.sessionId;
|
|
318
|
+
const [existingRecord, existingMeta] = await Promise.all([
|
|
319
|
+
sessionStore.find(capturedId),
|
|
320
|
+
transcriptStore.readMeta(capturedId),
|
|
321
|
+
]);
|
|
322
|
+
const task = existingMeta?.task ?? existingRecord?.task ?? "interactive";
|
|
323
|
+
const shouldPromoteLatestPrompt = shouldPromoteLatestPromptToSessionTitle({
|
|
324
|
+
existingTitle: existingMeta?.canonicalTitle ?? existingRecord?.canonicalTitle ?? existingMeta?.title ?? existingRecord?.title,
|
|
325
|
+
latestPrompt: options.prompt,
|
|
326
|
+
});
|
|
327
|
+
const metadata = deriveSessionMetadata({
|
|
328
|
+
task,
|
|
329
|
+
prompt: options.prompt,
|
|
330
|
+
provider: providerForTurn,
|
|
331
|
+
model: modelForTurn,
|
|
332
|
+
canonicalTitle: shouldPromoteLatestPrompt ? undefined : existingMeta?.canonicalTitle ?? existingRecord?.canonicalTitle,
|
|
333
|
+
title: shouldPromoteLatestPrompt ? undefined : existingMeta?.title ?? existingRecord?.title,
|
|
334
|
+
summary: shouldPromoteLatestPrompt ? undefined : existingMeta?.summary ?? existingRecord?.summary,
|
|
335
|
+
tags: existingMeta?.tags ?? existingRecord?.tags,
|
|
336
|
+
providersUsed: existingMeta?.providersUsed ?? existingRecord?.providersUsed,
|
|
337
|
+
});
|
|
338
|
+
const startedAt = existingMeta?.startedAt ?? new Date().toISOString();
|
|
101
339
|
if (typeof transcriptStore.init === "function") {
|
|
102
340
|
await transcriptStore.init(capturedId, {
|
|
103
341
|
kilnSessionId: capturedId,
|
|
104
342
|
provider: providerForTurn,
|
|
105
|
-
|
|
106
|
-
|
|
343
|
+
canonicalTitle: metadata.canonicalTitle,
|
|
344
|
+
title: metadata.title,
|
|
345
|
+
summary: metadata.summary,
|
|
346
|
+
tags: metadata.tags,
|
|
347
|
+
providersUsed: metadata.providersUsed,
|
|
348
|
+
task,
|
|
349
|
+
startedAt,
|
|
107
350
|
resumeStrategy,
|
|
108
351
|
resumeFeedback,
|
|
109
352
|
sessionLedger: {
|
|
@@ -114,28 +357,138 @@ export async function makeMultiProviderSessionFactory(initialProvider, providerI
|
|
|
114
357
|
});
|
|
115
358
|
}
|
|
116
359
|
let turnCostUsd = 0;
|
|
360
|
+
let turnIsError = false;
|
|
361
|
+
let assistantContent = "";
|
|
362
|
+
let assistantDeltaIndex = 0;
|
|
363
|
+
const pendingToolCallIds = new Map();
|
|
364
|
+
let syntheticToolOrdinal = 0;
|
|
365
|
+
const priorTranscript = await transcriptStore.readTranscript(capturedId);
|
|
366
|
+
let transcriptSeq = priorTranscript.length;
|
|
367
|
+
const turnOrdinal = priorTranscript.filter((event) => event.kind === "turn_started").length + 1;
|
|
368
|
+
const turnId = `${capturedId}:turn:${turnOrdinal}`;
|
|
369
|
+
const assistantMessageId = `${turnId}:assistant`;
|
|
370
|
+
const source = (actor) => ({
|
|
371
|
+
actor,
|
|
372
|
+
surface: transcriptSurface,
|
|
373
|
+
component: transcriptSurface === "gui" ? "gui-command" : "tui-command",
|
|
374
|
+
});
|
|
375
|
+
await transcriptStore.append(capturedId, persistedEvent(capturedId, ++transcriptSeq, "turn_started", source("runtime"), {
|
|
376
|
+
turnId,
|
|
377
|
+
turnOrdinal,
|
|
378
|
+
trigger: "user_message",
|
|
379
|
+
}, turnId));
|
|
380
|
+
const userText = latestUserText(options.messages) ?? options.prompt.trim();
|
|
381
|
+
if (userText) {
|
|
382
|
+
await transcriptStore.append(capturedId, toPersistedTranscriptEvent(capturedId, ++transcriptSeq, "user", {
|
|
383
|
+
messageId: `${turnId}:user`,
|
|
384
|
+
content: userText,
|
|
385
|
+
}, transcriptSurface, turnId));
|
|
386
|
+
}
|
|
117
387
|
try {
|
|
118
388
|
for await (const event of resumedSession.run(options)) {
|
|
119
|
-
if (event
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
389
|
+
if (!event || typeof event !== "object" || !("type" in event)) {
|
|
390
|
+
yield event;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (event.type === "text_delta" && !event.isThinking) {
|
|
394
|
+
assistantContent += event.content;
|
|
395
|
+
await transcriptStore.append(capturedId, toPersistedTranscriptEvent(capturedId, ++transcriptSeq, "text_delta", {
|
|
396
|
+
messageId: assistantMessageId,
|
|
397
|
+
delta: event.content,
|
|
398
|
+
deltaIndex: assistantDeltaIndex++,
|
|
399
|
+
}, transcriptSurface, turnId));
|
|
400
|
+
}
|
|
401
|
+
else if (event.type === "tool_use") {
|
|
402
|
+
const toolCallId = event.toolCallId ?? `${turnId}:tool:${++syntheticToolOrdinal}`;
|
|
403
|
+
const pending = pendingToolCallIds.get(event.toolName) ?? [];
|
|
404
|
+
pending.push(toolCallId);
|
|
405
|
+
pendingToolCallIds.set(event.toolName, pending);
|
|
406
|
+
await transcriptStore.append(capturedId, toPersistedTranscriptEvent(capturedId, ++transcriptSeq, "tool_use", {
|
|
407
|
+
toolCallId,
|
|
408
|
+
toolName: event.toolName,
|
|
409
|
+
input: event.input,
|
|
410
|
+
}, transcriptSurface, turnId));
|
|
411
|
+
}
|
|
412
|
+
else if (event.type === "tool_result") {
|
|
413
|
+
const pending = pendingToolCallIds.get(event.toolName);
|
|
414
|
+
let toolCallId;
|
|
415
|
+
if (event.toolCallId) {
|
|
416
|
+
toolCallId = event.toolCallId;
|
|
417
|
+
const pendingIndex = pending?.indexOf(event.toolCallId) ?? -1;
|
|
418
|
+
if (pending && pendingIndex >= 0) {
|
|
419
|
+
pending.splice(pendingIndex, 1);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
toolCallId = pending?.shift();
|
|
424
|
+
}
|
|
425
|
+
if (pending && pending.length === 0) {
|
|
426
|
+
pendingToolCallIds.delete(event.toolName);
|
|
427
|
+
}
|
|
428
|
+
if (!toolCallId) {
|
|
429
|
+
toolCallId = `${turnId}:tool:${++syntheticToolOrdinal}`;
|
|
430
|
+
await transcriptStore.append(capturedId, toPersistedTranscriptEvent(capturedId, ++transcriptSeq, "tool_use", {
|
|
431
|
+
toolCallId,
|
|
432
|
+
toolName: event.toolName,
|
|
433
|
+
}, transcriptSurface, turnId));
|
|
434
|
+
}
|
|
435
|
+
await transcriptStore.append(capturedId, toPersistedTranscriptEvent(capturedId, ++transcriptSeq, "tool_result", buildToolResultPayload({
|
|
436
|
+
toolCallId,
|
|
437
|
+
toolName: event.toolName,
|
|
438
|
+
output: event.output,
|
|
439
|
+
...(event.outputSummary !== undefined ? { outputSummary: event.outputSummary } : {}),
|
|
440
|
+
...(event.isError !== undefined ? { isError: event.isError } : {}),
|
|
441
|
+
}), transcriptSurface, turnId));
|
|
442
|
+
}
|
|
443
|
+
else if (event.type === "error") {
|
|
444
|
+
turnIsError = true;
|
|
445
|
+
await transcriptStore.append(capturedId, toPersistedTranscriptEvent(capturedId, ++transcriptSeq, "error", {
|
|
446
|
+
message: event.message,
|
|
447
|
+
code: event.code,
|
|
448
|
+
retriable: event.isRetryable,
|
|
449
|
+
}, transcriptSurface, turnId));
|
|
450
|
+
}
|
|
451
|
+
if (event.type === "completed") {
|
|
123
452
|
turnCostUsd = event.totalUsd;
|
|
453
|
+
turnIsError = event.isError;
|
|
124
454
|
}
|
|
125
455
|
yield event;
|
|
126
456
|
}
|
|
127
457
|
}
|
|
128
458
|
finally {
|
|
459
|
+
if (assistantContent.trim().length > 0) {
|
|
460
|
+
await transcriptStore.append(capturedId, persistedEvent(capturedId, ++transcriptSeq, "assistant_message", source("assistant"), {
|
|
461
|
+
messageId: assistantMessageId,
|
|
462
|
+
content: assistantContent,
|
|
463
|
+
provider: {
|
|
464
|
+
provider: providerForTurn,
|
|
465
|
+
...(modelForTurn ? { model: modelForTurn } : { model: providerForTurn }),
|
|
466
|
+
},
|
|
467
|
+
}, turnId));
|
|
468
|
+
}
|
|
469
|
+
await transcriptStore.append(capturedId, persistedEvent(capturedId, ++transcriptSeq, "turn_completed", source("runtime"), {
|
|
470
|
+
turnId,
|
|
471
|
+
outcome: turnIsError ? "failed" : "completed",
|
|
472
|
+
...(assistantContent.trim().length > 0 ? { outputMessageId: assistantMessageId } : {}),
|
|
473
|
+
}, turnId));
|
|
129
474
|
await resumedSession.dispose();
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
475
|
+
for (const [providerId, providerRuntimeState] of providerState) {
|
|
476
|
+
providerRuntimeState.resumeSessionId = capturedId;
|
|
477
|
+
if (providerId === providerForTurn) {
|
|
478
|
+
providerRuntimeState.providerSessionId = resumedSession.providerSessionId;
|
|
479
|
+
}
|
|
134
480
|
}
|
|
135
481
|
if (typeof transcriptStore.finalize === "function") {
|
|
136
482
|
await transcriptStore.finalize(capturedId, {
|
|
137
483
|
completedAt: new Date().toISOString(),
|
|
138
|
-
|
|
484
|
+
canonicalTitle: metadata.canonicalTitle,
|
|
485
|
+
title: metadata.title,
|
|
486
|
+
summary: metadata.summary,
|
|
487
|
+
tags: metadata.tags,
|
|
488
|
+
providersUsed: metadata.providersUsed,
|
|
489
|
+
providerThread: resumedSession.providerSessionId
|
|
490
|
+
? { provider: providerForTurn, nativeSessionId: resumedSession.providerSessionId }
|
|
491
|
+
: undefined,
|
|
139
492
|
resumeStrategy,
|
|
140
493
|
resumeFeedback,
|
|
141
494
|
sessionLedger: {
|
|
@@ -149,11 +502,18 @@ export async function makeMultiProviderSessionFactory(initialProvider, providerI
|
|
|
149
502
|
await sessionStore.append({
|
|
150
503
|
sessionId: capturedId,
|
|
151
504
|
provider: providerForTurn,
|
|
152
|
-
task
|
|
505
|
+
task,
|
|
506
|
+
canonicalTitle: metadata.canonicalTitle,
|
|
507
|
+
title: metadata.title,
|
|
508
|
+
summary: metadata.summary,
|
|
509
|
+
tags: metadata.tags,
|
|
510
|
+
providersUsed: metadata.providersUsed,
|
|
153
511
|
completedAt: new Date().toISOString(),
|
|
154
512
|
cost: turnCostUsd,
|
|
155
513
|
projectPath: cwd,
|
|
156
|
-
|
|
514
|
+
providerThread: resumedSession.providerSessionId
|
|
515
|
+
? { provider: providerForTurn, nativeSessionId: resumedSession.providerSessionId }
|
|
516
|
+
: undefined,
|
|
157
517
|
resumeStrategy,
|
|
158
518
|
});
|
|
159
519
|
if (activeSession === resumedSession) {
|
|
@@ -171,86 +531,75 @@ export async function makeMultiProviderSessionFactory(initialProvider, providerI
|
|
|
171
531
|
};
|
|
172
532
|
return {
|
|
173
533
|
factory: policyAwareFactory,
|
|
174
|
-
getProvider: () => currentProvider,
|
|
534
|
+
getProvider: () => currentProvider ?? "",
|
|
175
535
|
setProvider: (newProvider) => {
|
|
176
536
|
if (providers.includes(newProvider)) {
|
|
177
537
|
currentProvider = newProvider;
|
|
178
538
|
}
|
|
179
539
|
},
|
|
180
|
-
getModel: () =>
|
|
540
|
+
getModel: () => currentProvider ? providerModelState.get(currentProvider) ?? "" : "",
|
|
181
541
|
setModel: (model) => {
|
|
182
|
-
|
|
542
|
+
if (currentProvider) {
|
|
543
|
+
providerModelState.set(currentProvider, model);
|
|
544
|
+
}
|
|
183
545
|
},
|
|
184
546
|
onClear: async (provider) => {
|
|
185
|
-
const
|
|
186
|
-
? provider
|
|
187
|
-
: currentProvider;
|
|
188
|
-
const state = providerState.get(p);
|
|
189
|
-
if (state) {
|
|
547
|
+
for (const state of providerState.values()) {
|
|
190
548
|
state.resumeSessionId = undefined;
|
|
191
549
|
state.providerSessionId = undefined;
|
|
192
550
|
}
|
|
193
|
-
await sessionStore.
|
|
551
|
+
await sessionStore.clearResumeTarget(provider);
|
|
194
552
|
},
|
|
195
553
|
setResumeSession: (sessionId, provider) => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
554
|
+
const targetProvider = provider && providers.includes(provider)
|
|
555
|
+
? provider
|
|
556
|
+
: currentProvider;
|
|
557
|
+
if (!targetProvider) {
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
const state = providerState.get(targetProvider);
|
|
561
|
+
if (state) {
|
|
562
|
+
currentProvider = targetProvider;
|
|
563
|
+
state.resumeSessionId = sessionId;
|
|
203
564
|
}
|
|
204
565
|
},
|
|
205
566
|
};
|
|
206
567
|
}
|
|
207
|
-
function formatResumeFeedback(feedback) {
|
|
208
|
-
if (!feedback) {
|
|
209
|
-
return undefined;
|
|
210
|
-
}
|
|
211
|
-
const source = feedback.influencedChoice ? "applied" : "observed";
|
|
212
|
-
const preferred = feedback.preferredStrategy ? ` ${feedback.preferredStrategy}` : "";
|
|
213
|
-
return `${source}${preferred} · ${feedback.sampleSize}`;
|
|
214
|
-
}
|
|
215
|
-
async function loadInitialResumeInfo(cwd, sessionStore, providerIds) {
|
|
216
|
-
const transcriptStore = new TranscriptStore(cwd);
|
|
217
|
-
const info = {};
|
|
218
|
-
for (const provider of providerIds) {
|
|
219
|
-
const lastRecord = await sessionStore.last(provider);
|
|
220
|
-
if (!lastRecord) {
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
const meta = await transcriptStore.readMeta(lastRecord.sessionId);
|
|
224
|
-
if (!meta?.resumeStrategy || meta.resumeStrategy === "none") {
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
info[provider] = {
|
|
228
|
-
strategy: meta.resumeStrategy,
|
|
229
|
-
feedbackLabel: formatResumeFeedback(meta.resumeFeedback),
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
return info;
|
|
233
|
-
}
|
|
234
568
|
async function bootstrapGatewaySession(options) {
|
|
235
569
|
const { startTuiGateway } = await import("@kilnai/runtime");
|
|
236
570
|
const { flags, sessionManager, contextArtifactCache, systemPrompt } = options;
|
|
571
|
+
writeTuiBootstrapStatus("Starting Kiln TUI runtime...");
|
|
237
572
|
const gateway = await startTuiGateway({
|
|
238
573
|
sessionManager,
|
|
239
574
|
port: flags.port,
|
|
240
575
|
systemPrompt,
|
|
241
576
|
onClear: sessionManager.onClear,
|
|
577
|
+
getProviderAvailability: () => getRuntimeProviderAvailability(options.registry),
|
|
242
578
|
contextArtifactCache,
|
|
243
|
-
|
|
579
|
+
artifactStore: options.builtinToolOptions?.artifactResources?.store,
|
|
580
|
+
voiceConfig: options.operatorVoice?.voiceConfig,
|
|
581
|
+
sttAdapter: options.operatorVoice?.sttAdapter,
|
|
582
|
+
ttsAdapter: options.operatorVoice?.ttsAdapter,
|
|
583
|
+
executionMode: flags.plan ? "plan" : "execute",
|
|
584
|
+
builtinToolOptions: options.builtinToolOptions,
|
|
585
|
+
managedInvocation: options.managedInvocation,
|
|
586
|
+
resumeSessionHydrator: options.resumeSessionHydrator,
|
|
244
587
|
});
|
|
588
|
+
writeTuiBootstrapStatus("Connecting to local gateway...");
|
|
245
589
|
await waitForGateway(`http://localhost:${gateway.port}/health`);
|
|
590
|
+
writeTuiBootstrapStatus("Loading provider and model discovery...");
|
|
246
591
|
const providerModelsRef = {
|
|
247
592
|
current: gateway.models,
|
|
248
593
|
};
|
|
594
|
+
const providerDiscoveryRef = {
|
|
595
|
+
current: gateway.providerDiscovery ?? [],
|
|
596
|
+
};
|
|
249
597
|
let session = null;
|
|
250
598
|
const createSession = async () => {
|
|
251
599
|
if (!session) {
|
|
252
|
-
session = new GatewaySession(gateway.url, (models) => {
|
|
600
|
+
session = new GatewaySession(gateway.url, (models, discovery) => {
|
|
253
601
|
providerModelsRef.current = models;
|
|
602
|
+
providerDiscoveryRef.current = discovery ?? [];
|
|
254
603
|
});
|
|
255
604
|
}
|
|
256
605
|
return session;
|
|
@@ -258,6 +607,7 @@ async function bootstrapGatewaySession(options) {
|
|
|
258
607
|
return {
|
|
259
608
|
createSession,
|
|
260
609
|
providerModelsRef,
|
|
610
|
+
providerDiscoveryRef,
|
|
261
611
|
shutdown: () => {
|
|
262
612
|
void session?.dispose();
|
|
263
613
|
gateway.shutdown();
|
|
@@ -266,11 +616,16 @@ async function bootstrapGatewaySession(options) {
|
|
|
266
616
|
}
|
|
267
617
|
function mapSessionEventToTui(event, route) {
|
|
268
618
|
const candidate = event;
|
|
619
|
+
const scoped = {
|
|
620
|
+
...(typeof candidate?.sessionId === "string" ? { sessionId: candidate.sessionId } : {}),
|
|
621
|
+
...(typeof candidate?.turnId === "string" ? { turnId: candidate.turnId } : {}),
|
|
622
|
+
};
|
|
269
623
|
switch (candidate?.type) {
|
|
270
624
|
case "text_delta":
|
|
271
625
|
return {
|
|
272
626
|
type: "text_delta",
|
|
273
627
|
content: String(candidate.content ?? ""),
|
|
628
|
+
...scoped,
|
|
274
629
|
};
|
|
275
630
|
case "file_changed":
|
|
276
631
|
return {
|
|
@@ -279,11 +634,13 @@ function mapSessionEventToTui(event, route) {
|
|
|
279
634
|
changeType: candidate.changeType ?? "modified",
|
|
280
635
|
linesAdded: typeof candidate.linesAdded === "number" ? candidate.linesAdded : undefined,
|
|
281
636
|
linesRemoved: typeof candidate.linesRemoved === "number" ? candidate.linesRemoved : undefined,
|
|
637
|
+
...scoped,
|
|
282
638
|
};
|
|
283
639
|
case "cost_update":
|
|
284
640
|
return {
|
|
285
641
|
type: "cost_update",
|
|
286
642
|
usd: typeof candidate.usd === "number" ? candidate.usd : 0,
|
|
643
|
+
...scoped,
|
|
287
644
|
};
|
|
288
645
|
case "completed":
|
|
289
646
|
return {
|
|
@@ -303,14 +660,32 @@ function mapSessionEventToTui(event, route) {
|
|
|
303
660
|
activity: "tool_use",
|
|
304
661
|
toolName: typeof candidate.toolName === "string" ? candidate.toolName : undefined,
|
|
305
662
|
input: candidate.input,
|
|
663
|
+
...scoped,
|
|
306
664
|
};
|
|
307
|
-
case "tool_result":
|
|
665
|
+
case "tool_result": {
|
|
666
|
+
const toolName = typeof candidate.toolName === "string" ? candidate.toolName : undefined;
|
|
667
|
+
const presentation = toolName && typeof candidate.output === "string"
|
|
668
|
+
? presentOperatorEventPayload("tool_call_completed", buildToolResultPayload({
|
|
669
|
+
toolCallId: typeof candidate.toolCallId === "string" ? candidate.toolCallId : "tool-result",
|
|
670
|
+
toolName,
|
|
671
|
+
output: candidate.output,
|
|
672
|
+
...(typeof candidate.outputSummary === "string" ? { outputSummary: candidate.outputSummary } : {}),
|
|
673
|
+
...(typeof candidate.isError === "boolean" ? { isError: candidate.isError } : {}),
|
|
674
|
+
}))
|
|
675
|
+
: undefined;
|
|
676
|
+
const output = presentation?.toolPresentation?.presentationIntent
|
|
677
|
+
? formatPresentationIntentAsText(presentation.toolPresentation.presentationIntent)
|
|
678
|
+
: typeof candidate.output === "string"
|
|
679
|
+
? parseToolResultEnvelope(candidate.output).output
|
|
680
|
+
: undefined;
|
|
308
681
|
return {
|
|
309
682
|
type: "activity",
|
|
310
683
|
activity: "tool_result",
|
|
311
|
-
toolName
|
|
312
|
-
output
|
|
684
|
+
toolName,
|
|
685
|
+
output,
|
|
686
|
+
...scoped,
|
|
313
687
|
};
|
|
688
|
+
}
|
|
314
689
|
default:
|
|
315
690
|
return {
|
|
316
691
|
type: "activity",
|
|
@@ -322,6 +697,21 @@ async function bootstrapDirectSession(options) {
|
|
|
322
697
|
const { flags, sessionManager, systemPrompt } = options;
|
|
323
698
|
const sessionCwd = flags.cwd ?? process.cwd();
|
|
324
699
|
let session = null;
|
|
700
|
+
const providerModelsRef = { current: {} };
|
|
701
|
+
const providerDiscoveryRef = { current: [] };
|
|
702
|
+
const providerCatalog = createProviderCatalogService(() => resolveGuiOperatorDiscoveryResults(getRuntimeProviderAvailability(options.registry)), []);
|
|
703
|
+
const applyProviderDiscovery = (discovery) => {
|
|
704
|
+
providerDiscoveryRef.current = discovery;
|
|
705
|
+
providerModelsRef.current = projectGuiOperatorModels(providerDiscoveryRef.current);
|
|
706
|
+
return providerModelsRef.current;
|
|
707
|
+
};
|
|
708
|
+
const refreshProviderModels = async (refreshOptions) => applyProviderDiscovery((await providerCatalog.refresh(refreshOptions)).discovery);
|
|
709
|
+
const ensureProviderModels = async () => applyProviderDiscovery((await providerCatalog.ensureReady()).discovery);
|
|
710
|
+
providerCatalog.subscribe((snapshot) => {
|
|
711
|
+
applyProviderDiscovery(snapshot.discovery);
|
|
712
|
+
});
|
|
713
|
+
writeTuiBootstrapStatus("Loading provider and model discovery...");
|
|
714
|
+
providerCatalog.startBackgroundRefresh({ force: true });
|
|
325
715
|
const createSession = async () => {
|
|
326
716
|
if (session) {
|
|
327
717
|
return session;
|
|
@@ -330,7 +720,36 @@ async function bootstrapDirectSession(options) {
|
|
|
330
720
|
session = {
|
|
331
721
|
async *run(opts) {
|
|
332
722
|
const providerForTurn = sessionManager.getProvider();
|
|
333
|
-
|
|
723
|
+
let modelForTurn = sessionManager.getModel();
|
|
724
|
+
const providerModels = await ensureProviderModels();
|
|
725
|
+
const advertisedModels = providerModels[providerForTurn];
|
|
726
|
+
if (!advertisedModels || (advertisedModels.length === 0 && !isGuiProviderModeless(providerForTurn))) {
|
|
727
|
+
yield {
|
|
728
|
+
type: "error",
|
|
729
|
+
message: `Provider '${providerForTurn}' is unavailable`,
|
|
730
|
+
};
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (advertisedModels.length === 0 && isGuiProviderModeless(providerForTurn)) {
|
|
734
|
+
if (modelForTurn.trim().length > 0) {
|
|
735
|
+
sessionManager.setModel("");
|
|
736
|
+
}
|
|
737
|
+
modelForTurn = "";
|
|
738
|
+
}
|
|
739
|
+
if (advertisedModels?.length && modelForTurn.trim().length === 0) {
|
|
740
|
+
yield {
|
|
741
|
+
type: "error",
|
|
742
|
+
message: providerRequiresSelectedModelMessage(providerForTurn),
|
|
743
|
+
};
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
if (advertisedModels?.length && !advertisedModels.includes(modelForTurn)) {
|
|
747
|
+
yield {
|
|
748
|
+
type: "error",
|
|
749
|
+
message: `Provider '${providerForTurn}' does not advertise model '${modelForTurn}'`,
|
|
750
|
+
};
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
334
753
|
for await (const event of inner.run(opts)) {
|
|
335
754
|
yield mapSessionEventToTui(event, {
|
|
336
755
|
provider: providerForTurn,
|
|
@@ -344,17 +763,31 @@ async function bootstrapDirectSession(options) {
|
|
|
344
763
|
async clear() {
|
|
345
764
|
await sessionManager.onClear(sessionManager.getProvider());
|
|
346
765
|
},
|
|
766
|
+
async refreshProviders() {
|
|
767
|
+
await refreshProviderModels({ force: true });
|
|
768
|
+
},
|
|
347
769
|
async switchProvider(providerName, modelName) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
770
|
+
const provider = providerName.trim();
|
|
771
|
+
const requestedModel = typeof modelName === "string" ? modelName.trim() : "";
|
|
772
|
+
const resolution = resolveGuiProviderSwitch({
|
|
773
|
+
provider,
|
|
774
|
+
model: requestedModel,
|
|
775
|
+
models: await ensureProviderModels(),
|
|
776
|
+
});
|
|
777
|
+
if (!resolution.ok) {
|
|
778
|
+
throw new Error(resolution.error);
|
|
779
|
+
}
|
|
780
|
+
sessionManager.setProvider(resolution.provider);
|
|
781
|
+
sessionManager.setModel(resolution.modelForSessionManager);
|
|
782
|
+
return resolution.provider;
|
|
351
783
|
},
|
|
352
784
|
};
|
|
353
785
|
return session;
|
|
354
786
|
};
|
|
355
787
|
return {
|
|
356
788
|
createSession,
|
|
357
|
-
providerModelsRef
|
|
789
|
+
providerModelsRef,
|
|
790
|
+
providerDiscoveryRef,
|
|
358
791
|
shutdown: () => { },
|
|
359
792
|
};
|
|
360
793
|
}
|
|
@@ -372,15 +805,60 @@ export async function tuiCommand(appConfig, flags = {}) {
|
|
|
372
805
|
const providerIds = providerDisplayInfo.map((entry) => entry.id);
|
|
373
806
|
const cwd = flags.cwd ?? process.cwd();
|
|
374
807
|
const globalConfig = readGlobalConfig();
|
|
375
|
-
const
|
|
808
|
+
const projectConfig = readKilnYaml(join(cwd, ".kiln"));
|
|
809
|
+
const resolvedKilnConfig = await loadKilnConfig(cwd);
|
|
810
|
+
const runtimeAppConfig = withContextCandidates(withWorkGovernanceContext(withGlobalIdentityContext(appConfig, globalConfig), resolvedKilnConfig?.workGovernance), resolveInstructionProfileContextCandidates({
|
|
811
|
+
projectPath: cwd,
|
|
812
|
+
globalConfig,
|
|
813
|
+
projectConfig,
|
|
814
|
+
}));
|
|
815
|
+
const startupTransport = resolveTuiStartupTransport(flags);
|
|
816
|
+
const provider = parseProvider(resolveEffectiveProvider(flags.provider, resolveGlobalDefaultProvider(globalConfig)), providerIds);
|
|
817
|
+
const startupModel = resolveGlobalDefaultModel(globalConfig);
|
|
818
|
+
const workItemStore = new WorkItemStore();
|
|
819
|
+
const goalRunStore = new GoalRunStore();
|
|
820
|
+
const startupProviderIds = providerIds;
|
|
376
821
|
const contextArtifactCache = await getProjectContextArtifactCache(cwd);
|
|
822
|
+
const configuredBuiltinToolOptions = await loadConfiguredBuiltinToolSurfaceOptions(runtimeAppConfig, cwd, {
|
|
823
|
+
memoryAuthority: {
|
|
824
|
+
modelFacingSession: true,
|
|
825
|
+
permissionAgent: "tui",
|
|
826
|
+
caller: { kind: "operator_surface", id: "tui" },
|
|
827
|
+
},
|
|
828
|
+
});
|
|
829
|
+
const builtinToolOptions = createSessionBuiltinToolOptions({
|
|
830
|
+
...configuredBuiltinToolOptions,
|
|
831
|
+
workItemStore,
|
|
832
|
+
goalRunStore,
|
|
833
|
+
additionalTools: [
|
|
834
|
+
...(configuredBuiltinToolOptions.additionalTools ?? []),
|
|
835
|
+
...createKilnConfigTools(cwd),
|
|
836
|
+
...createWorkGovernanceTools(resolvedKilnConfig?.workGovernance, { workItemStore, goalRunStore }),
|
|
837
|
+
],
|
|
838
|
+
});
|
|
839
|
+
const engineAvailability = resolveEngineAvailabilityMap(globalConfig);
|
|
840
|
+
const managedAgentProviderModels = await discoverManagedAgentProviderModels();
|
|
841
|
+
const managedInvocationResolution = await resolveManagedInvocationToolOptions(globalConfig, {
|
|
842
|
+
cwd,
|
|
843
|
+
registry,
|
|
844
|
+
surface: "tui",
|
|
845
|
+
isProviderAvailable: (providerId) => engineAvailability.get(providerId),
|
|
846
|
+
providerModels: managedAgentProviderModels,
|
|
847
|
+
directAdapterFactory: createManagedDirectProviderAdapterFactory({ builtinToolOptions }),
|
|
848
|
+
artifactStore: builtinToolOptions.artifactResources?.store,
|
|
849
|
+
});
|
|
850
|
+
const managedInvocation = appConfig.managedInvocation ?? managedInvocationResolution.managedInvocation;
|
|
851
|
+
const operatorVoice = await resolveOperatorVoiceRuntime(globalConfig);
|
|
852
|
+
for (const warning of operatorVoice.warnings) {
|
|
853
|
+
console.warn(warning);
|
|
854
|
+
}
|
|
377
855
|
// Resolve domain display name from app config if available
|
|
378
856
|
let domain = "kiln";
|
|
379
857
|
let systemPrompt = "You are a helpful assistant.";
|
|
380
858
|
try {
|
|
381
859
|
const { SessionManager } = await import("../wrapper/session-manager.js");
|
|
382
860
|
const wrapperConfig = { mode: "cli-wrapper", permissionPolicy: { approval: "never", sandbox: "workspace-write" } };
|
|
383
|
-
const manager = new SessionManager(wrapperConfig,
|
|
861
|
+
const manager = new SessionManager(wrapperConfig, runtimeAppConfig, contextArtifactCache);
|
|
384
862
|
const context = await manager.prepare("interactive", cwd, undefined, undefined, undefined);
|
|
385
863
|
domain = context.domain.displayName;
|
|
386
864
|
systemPrompt = context.systemPrompt;
|
|
@@ -391,14 +869,22 @@ export async function tuiCommand(appConfig, flags = {}) {
|
|
|
391
869
|
// Inject CLI session factory into the gateway (dependency inversion)
|
|
392
870
|
const sessionStore = new SessionStore(cwd);
|
|
393
871
|
const transcriptStore = new TranscriptStore(cwd);
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
const sessionManager = await makeMultiProviderSessionFactory(provider,
|
|
872
|
+
const resumeSessionHydrator = createTranscriptRuntimeSessionHydrator({ transcriptStore });
|
|
873
|
+
const initialResumeInfo = await loadResumeSidebarInfo(sessionStore, transcriptStore, startupProviderIds);
|
|
874
|
+
const sessionManager = await makeMultiProviderSessionFactory(provider, startupProviderIds, cwd, registry, sessionStore, transcriptStore, contextArtifactCache, builtinToolOptions, "tui", managedInvocation);
|
|
875
|
+
if (startupModel) {
|
|
876
|
+
sessionManager.setModel(startupModel);
|
|
877
|
+
}
|
|
397
878
|
const bootstrap = await bootstrapTuiSession({
|
|
398
879
|
flags,
|
|
399
880
|
sessionManager,
|
|
881
|
+
registry,
|
|
400
882
|
contextArtifactCache,
|
|
401
883
|
systemPrompt,
|
|
884
|
+
builtinToolOptions,
|
|
885
|
+
managedInvocation,
|
|
886
|
+
resumeSessionHydrator,
|
|
887
|
+
operatorVoice,
|
|
402
888
|
});
|
|
403
889
|
const shutdown = (code = 0, error) => {
|
|
404
890
|
bootstrap.shutdown();
|
|
@@ -420,7 +906,7 @@ export async function tuiCommand(appConfig, flags = {}) {
|
|
|
420
906
|
];
|
|
421
907
|
for (const [ev, handler] of handlers)
|
|
422
908
|
process.on(ev, handler);
|
|
423
|
-
const resolvedTheme = themes[flags.theme ?? globalConfig
|
|
909
|
+
const resolvedTheme = themes[flags.theme ?? resolveGlobalUiTheme(globalConfig) ?? "kiln-dark"] ?? kilnDark;
|
|
424
910
|
// Session list loader for sidebar browser
|
|
425
911
|
async function loadSessionList() {
|
|
426
912
|
try {
|
|
@@ -436,7 +922,21 @@ export async function tuiCommand(appConfig, flags = {}) {
|
|
|
436
922
|
sessionManager.setProvider(session.provider);
|
|
437
923
|
sessionManager.setResumeSession(session.sessionId, session.provider);
|
|
438
924
|
};
|
|
439
|
-
|
|
925
|
+
const startupProviderDisplayInfo = buildTuiStartupProviderDisplayInfo({
|
|
926
|
+
providerDisplayInfo,
|
|
927
|
+
runtimeModels: bootstrap.providerModelsRef.current,
|
|
928
|
+
runtimeDiscovery: bootstrap.providerDiscoveryRef.current,
|
|
929
|
+
includeModelessProviders: true,
|
|
930
|
+
includePendingProviders: bootstrap.providerDiscoveryRef.current.length === 0,
|
|
931
|
+
});
|
|
932
|
+
if (bootstrap.providerDiscoveryRef.current.length > 0) {
|
|
933
|
+
assertTuiProviderAvailableInStartupCatalog(provider, startupProviderDisplayInfo);
|
|
934
|
+
}
|
|
935
|
+
const startupProvider = startupProviderDisplayInfo.find((entry) => entry.id === provider);
|
|
936
|
+
if (startupProvider?.models[0] && sessionManager.getModel().trim().length === 0) {
|
|
937
|
+
sessionManager.setModel(startupProvider.models[0]);
|
|
938
|
+
}
|
|
939
|
+
await startTui(bootstrap.createSession, startupProviderDisplayInfo, provider, domain, resolvedTheme, startupTransport === "direct" ? initialResumeInfo : {}, () => loadResumeSidebarInfo(sessionStore, transcriptStore, startupProviderIds), bootstrap.providerModelsRef, bootstrap.providerDiscoveryRef, startupTransport === "direct" ? loadSessionList : undefined, startupTransport === "direct" ? handleResumeSession : undefined, () => bootstrap.createSession().then((session) => session.refreshProviders?.()), (themeName) => persistTuiThemePreference(themeName, globalConfig), async () => (await readConfigStatusSnapshot({ projectPath: cwd })).setup);
|
|
440
940
|
bootstrap.shutdown();
|
|
441
941
|
for (const [ev, handler] of handlers)
|
|
442
942
|
process.off(ev, handler);
|