@di-code/coding-agent 0.1.6 → 0.1.8
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 +112 -68
- package/compositions/base.yml +54 -0
- package/compositions/interactive.yml +14 -0
- package/compositions/json.yml +6 -0
- package/compositions/print.yml +5 -0
- package/compositions/rpc.yml +12 -0
- package/compositions/webui.yml +9 -0
- package/dist/cli.d.ts +22 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +97 -3
- package/dist/cli.js.map +1 -1
- package/dist/composition-loader-entry.d.ts +11 -0
- package/dist/composition-loader-entry.d.ts.map +1 -0
- package/dist/composition-loader-entry.js +12 -0
- package/dist/composition-loader-entry.js.map +1 -0
- package/dist/compositions.d.ts +32 -0
- package/dist/compositions.d.ts.map +1 -0
- package/dist/compositions.js +173 -0
- package/dist/compositions.js.map +1 -0
- package/dist/core/session/session-manager.d.ts +9 -2
- package/dist/core/session/session-manager.d.ts.map +1 -1
- package/dist/core/session/session-manager.js +28 -0
- package/dist/core/session/session-manager.js.map +1 -1
- package/dist/core/session/session-storage.d.ts.map +1 -1
- package/dist/core/session/session-storage.js +20 -3
- package/dist/core/session/session-storage.js.map +1 -1
- package/dist/core/session/types.d.ts +11 -2
- package/dist/core/session/types.d.ts.map +1 -1
- package/dist/core/session/types.js.map +1 -1
- package/dist/core/session-tools.d.ts +5 -0
- package/dist/core/session-tools.d.ts.map +1 -0
- package/dist/core/session-tools.js +17 -0
- package/dist/core/session-tools.js.map +1 -0
- package/dist/core/session.d.ts +21 -7
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +77 -41
- package/dist/core/session.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -38
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +1 -207
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +1 -24
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +1 -135
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +1 -26
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +1 -140
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +1 -23
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/file-search.d.ts +1 -13
- package/dist/core/tools/file-search.d.ts.map +1 -1
- package/dist/core/tools/file-search.js +1 -98
- package/dist/core/tools/file-search.js.map +1 -1
- package/dist/core/tools/glob.d.ts +1 -10
- package/dist/core/tools/glob.d.ts.map +1 -1
- package/dist/core/tools/glob.js +1 -43
- package/dist/core/tools/glob.js.map +1 -1
- package/dist/core/tools/grep.d.ts +1 -12
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +1 -66
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/load-skill.d.ts +1 -9
- package/dist/core/tools/load-skill.d.ts.map +1 -1
- package/dist/core/tools/load-skill.js +1 -21
- package/dist/core/tools/load-skill.js.map +1 -1
- package/dist/core/tools/path-boundary.d.ts +1 -4
- package/dist/core/tools/path-boundary.d.ts.map +1 -1
- package/dist/core/tools/path-boundary.js +1 -65
- package/dist/core/tools/path-boundary.js.map +1 -1
- package/dist/core/tools/read.d.ts +1 -16
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -131
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts +1 -16
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +1 -44
- package/dist/core/tools/write.js.map +1 -1
- package/dist/entry.js +30 -28
- package/dist/entry.js.map +1 -1
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +2 -0
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/interactive/builtin.d.ts +17 -0
- package/dist/interactive/builtin.d.ts.map +1 -0
- package/dist/interactive/builtin.js +47 -0
- package/dist/interactive/builtin.js.map +1 -0
- package/dist/interactive/controller.d.ts +85 -0
- package/dist/interactive/controller.d.ts.map +1 -0
- package/dist/interactive/controller.js +211 -0
- package/dist/interactive/controller.js.map +1 -0
- package/dist/interactive/index.d.ts +3 -0
- package/dist/interactive/index.d.ts.map +1 -0
- package/dist/interactive/index.js +3 -0
- package/dist/interactive/index.js.map +1 -0
- package/dist/interactive-host-entry.d.ts +7 -0
- package/dist/interactive-host-entry.d.ts.map +1 -0
- package/dist/interactive-host-entry.js +123 -0
- package/dist/interactive-host-entry.js.map +1 -0
- package/dist/interactive-profile.d.ts +18 -0
- package/dist/interactive-profile.d.ts.map +1 -0
- package/dist/interactive-profile.js +290 -0
- package/dist/interactive-profile.js.map +1 -0
- package/dist/interactive-resources-entry.d.ts +7 -0
- package/dist/interactive-resources-entry.d.ts.map +1 -0
- package/dist/interactive-resources-entry.js +42 -0
- package/dist/interactive-resources-entry.js.map +1 -0
- package/dist/legacy-main.d.ts +39 -0
- package/dist/legacy-main.d.ts.map +1 -0
- package/dist/legacy-main.js +611 -0
- package/dist/legacy-main.js.map +1 -0
- package/dist/main.d.ts +15 -34
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +130 -513
- package/dist/main.js.map +1 -1
- package/dist/mcp/entries.d.ts +42 -0
- package/dist/mcp/entries.d.ts.map +1 -0
- package/dist/mcp/entries.js +98 -0
- package/dist/mcp/entries.js.map +1 -0
- package/dist/mcp-client-entry.d.ts +5 -0
- package/dist/mcp-client-entry.d.ts.map +1 -0
- package/dist/mcp-client-entry.js +6 -0
- package/dist/mcp-client-entry.js.map +1 -0
- package/dist/mcp-config-entry.d.ts +5 -0
- package/dist/mcp-config-entry.d.ts.map +1 -0
- package/dist/mcp-config-entry.js +6 -0
- package/dist/mcp-config-entry.js.map +1 -0
- package/dist/mcp-tools-entry.d.ts +5 -0
- package/dist/mcp-tools-entry.d.ts.map +1 -0
- package/dist/mcp-tools-entry.js +6 -0
- package/dist/mcp-tools-entry.js.map +1 -0
- package/dist/mcp-transport-entry.d.ts +5 -0
- package/dist/mcp-transport-entry.d.ts.map +1 -0
- package/dist/mcp-transport-entry.js +6 -0
- package/dist/mcp-transport-entry.js.map +1 -0
- package/dist/modes/interactive-entry.d.ts +18 -0
- package/dist/modes/interactive-entry.d.ts.map +1 -0
- package/dist/modes/interactive-entry.js +21 -0
- package/dist/modes/interactive-entry.js.map +1 -0
- package/dist/modes/interactive-state.js +1 -1
- package/dist/modes/interactive-state.js.map +1 -1
- package/dist/modes/interactive.d.ts +16 -6
- package/dist/modes/interactive.d.ts.map +1 -1
- package/dist/modes/interactive.js +99 -33
- package/dist/modes/interactive.js.map +1 -1
- package/dist/modes/json-entry.d.ts +13 -0
- package/dist/modes/json-entry.d.ts.map +1 -0
- package/dist/modes/json-entry.js +14 -0
- package/dist/modes/json-entry.js.map +1 -0
- package/dist/modes/json.d.ts +4 -1
- package/dist/modes/json.d.ts.map +1 -1
- package/dist/modes/json.js +3 -3
- package/dist/modes/json.js.map +1 -1
- package/dist/modes/print-entry.d.ts +10 -0
- package/dist/modes/print-entry.d.ts.map +1 -0
- package/dist/modes/print-entry.js +11 -0
- package/dist/modes/print-entry.js.map +1 -0
- package/dist/modes/tree-selector.d.ts.map +1 -1
- package/dist/modes/tree-selector.js +4 -0
- package/dist/modes/tree-selector.js.map +1 -1
- package/dist/plugin-dump-composition.d.ts +6 -0
- package/dist/plugin-dump-composition.d.ts.map +1 -0
- package/dist/plugin-dump-composition.js +7 -0
- package/dist/plugin-dump-composition.js.map +1 -0
- package/dist/plugin-inventory.d.ts +7 -0
- package/dist/plugin-inventory.d.ts.map +1 -0
- package/dist/plugin-inventory.js +8 -0
- package/dist/plugin-inventory.js.map +1 -0
- package/dist/plugin-manager.d.ts +6 -0
- package/dist/plugin-manager.d.ts.map +1 -0
- package/dist/plugin-manager.js +7 -0
- package/dist/plugin-manager.js.map +1 -0
- package/dist/plugin-trace.d.ts +6 -0
- package/dist/plugin-trace.d.ts.map +1 -0
- package/dist/plugin-trace.js +7 -0
- package/dist/plugin-trace.js.map +1 -0
- package/dist/plugins/dynamic-broker.d.ts +76 -0
- package/dist/plugins/dynamic-broker.d.ts.map +1 -0
- package/dist/plugins/dynamic-broker.js +852 -0
- package/dist/plugins/dynamic-broker.js.map +1 -0
- package/dist/plugins/profile.d.ts +15 -0
- package/dist/plugins/profile.d.ts.map +1 -0
- package/dist/plugins/profile.js +34 -0
- package/dist/plugins/profile.js.map +1 -0
- package/dist/plugins/runtime-host.d.ts +37 -0
- package/dist/plugins/runtime-host.d.ts.map +1 -0
- package/dist/plugins/runtime-host.js +95 -0
- package/dist/plugins/runtime-host.js.map +1 -0
- package/dist/plugins/trust.d.ts +8 -0
- package/dist/plugins/trust.d.ts.map +1 -0
- package/dist/plugins/trust.js +59 -0
- package/dist/plugins/trust.js.map +1 -0
- package/dist/project-trust-entry.d.ts +15 -0
- package/dist/project-trust-entry.d.ts.map +1 -0
- package/dist/project-trust-entry.js +15 -0
- package/dist/project-trust-entry.js.map +1 -0
- package/dist/rpc/client.d.ts +78 -6
- package/dist/rpc/client.d.ts.map +1 -1
- package/dist/rpc/client.js +172 -4
- package/dist/rpc/client.js.map +1 -1
- package/dist/rpc/dispatcher.d.ts +121 -0
- package/dist/rpc/dispatcher.d.ts.map +1 -0
- package/dist/rpc/dispatcher.js +994 -0
- package/dist/rpc/dispatcher.js.map +1 -0
- package/dist/rpc/index.d.ts +2 -0
- package/dist/rpc/index.d.ts.map +1 -1
- package/dist/rpc/index.js +2 -0
- package/dist/rpc/index.js.map +1 -1
- package/dist/rpc/lifecycle.d.ts +6 -0
- package/dist/rpc/lifecycle.d.ts.map +1 -0
- package/dist/rpc/lifecycle.js +24 -0
- package/dist/rpc/lifecycle.js.map +1 -0
- package/dist/rpc/protocol.d.ts +112 -31
- package/dist/rpc/protocol.d.ts.map +1 -1
- package/dist/rpc/protocol.js +569 -117
- package/dist/rpc/protocol.js.map +1 -1
- package/dist/rpc/server-service.d.ts +7 -0
- package/dist/rpc/server-service.d.ts.map +1 -0
- package/dist/rpc/server-service.js +3 -0
- package/dist/rpc/server-service.js.map +1 -0
- package/dist/rpc/server.d.ts +16 -19
- package/dist/rpc/server.d.ts.map +1 -1
- package/dist/rpc/server.js +59 -115
- package/dist/rpc/server.js.map +1 -1
- package/dist/rpc-client-sdk-entry.d.ts +12 -0
- package/dist/rpc-client-sdk-entry.d.ts.map +1 -0
- package/dist/rpc-client-sdk-entry.js +11 -0
- package/dist/rpc-client-sdk-entry.js.map +1 -0
- package/dist/rpc-entry.js +50 -18
- package/dist/rpc-entry.js.map +1 -1
- package/dist/rpc-server-entry.d.ts +8 -0
- package/dist/rpc-server-entry.d.ts.map +1 -0
- package/dist/rpc-server-entry.js +67 -0
- package/dist/rpc-server-entry.js.map +1 -0
- package/dist/runtime/attachment-store.d.ts +13 -0
- package/dist/runtime/attachment-store.d.ts.map +1 -0
- package/dist/runtime/attachment-store.js +93 -0
- package/dist/runtime/attachment-store.js.map +1 -0
- package/dist/runtime/bootstrap.d.ts +14 -0
- package/dist/runtime/bootstrap.d.ts.map +1 -0
- package/dist/runtime/bootstrap.js +29 -0
- package/dist/runtime/bootstrap.js.map +1 -0
- package/dist/runtime/interactive-host-service.d.ts +22 -0
- package/dist/runtime/interactive-host-service.d.ts.map +1 -0
- package/dist/runtime/interactive-host-service.js +2 -0
- package/dist/runtime/interactive-host-service.js.map +1 -0
- package/dist/runtime/interactive-resource-service.d.ts +11 -0
- package/dist/runtime/interactive-resource-service.d.ts.map +1 -0
- package/dist/runtime/interactive-resource-service.js +3 -0
- package/dist/runtime/interactive-resource-service.js.map +1 -0
- package/dist/runtime/plugin-inventory-entry.d.ts +5 -0
- package/dist/runtime/plugin-inventory-entry.d.ts.map +1 -0
- package/dist/runtime/plugin-inventory-entry.js +18 -0
- package/dist/runtime/plugin-inventory-entry.js.map +1 -0
- package/dist/runtime/plugin-inventory-service.d.ts +8 -0
- package/dist/runtime/plugin-inventory-service.d.ts.map +1 -0
- package/dist/runtime/plugin-inventory-service.js +3 -0
- package/dist/runtime/plugin-inventory-service.js.map +1 -0
- package/dist/runtime/plugin-manager-entry.d.ts +20 -0
- package/dist/runtime/plugin-manager-entry.d.ts.map +1 -0
- package/dist/runtime/plugin-manager-entry.js +96 -0
- package/dist/runtime/plugin-manager-entry.js.map +1 -0
- package/dist/runtime/plugin-observability-entry.d.ts +12 -0
- package/dist/runtime/plugin-observability-entry.d.ts.map +1 -0
- package/dist/runtime/plugin-observability-entry.js +73 -0
- package/dist/runtime/plugin-observability-entry.js.map +1 -0
- package/dist/runtime/product-host.d.ts +91 -0
- package/dist/runtime/product-host.d.ts.map +1 -0
- package/dist/runtime/product-host.js +529 -0
- package/dist/runtime/product-host.js.map +1 -0
- package/dist/runtime/session-factory.d.ts +17 -0
- package/dist/runtime/session-factory.d.ts.map +1 -0
- package/dist/runtime/session-factory.js +75 -0
- package/dist/runtime/session-factory.js.map +1 -0
- package/dist/runtime/session-host.d.ts +152 -0
- package/dist/runtime/session-host.d.ts.map +1 -0
- package/dist/runtime/session-host.js +895 -0
- package/dist/runtime/session-host.js.map +1 -0
- package/dist/runtime-core-entry.d.ts +11 -0
- package/dist/runtime-core-entry.d.ts.map +1 -0
- package/dist/runtime-core-entry.js +9 -0
- package/dist/runtime-core-entry.js.map +1 -0
- package/dist/session-factory-entry.d.ts +7 -0
- package/dist/session-factory-entry.d.ts.map +1 -0
- package/dist/session-factory-entry.js +9 -0
- package/dist/session-factory-entry.js.map +1 -0
- package/dist/session-store-jsonl-entry.d.ts +7 -0
- package/dist/session-store-jsonl-entry.d.ts.map +1 -0
- package/dist/session-store-jsonl-entry.js +33 -0
- package/dist/session-store-jsonl-entry.js.map +1 -0
- package/dist/startup.d.ts +21 -1
- package/dist/startup.d.ts.map +1 -1
- package/dist/startup.js +179 -10
- package/dist/startup.js.map +1 -1
- package/dist/subagents/index.d.ts +2 -0
- package/dist/subagents/index.d.ts.map +1 -0
- package/dist/subagents/index.js +2 -0
- package/dist/subagents/index.js.map +1 -0
- package/dist/subagents/service.d.ts +50 -0
- package/dist/subagents/service.d.ts.map +1 -0
- package/dist/subagents/service.js +521 -0
- package/dist/subagents/service.js.map +1 -0
- package/dist/ui-host.d.ts +125 -0
- package/dist/ui-host.d.ts.map +1 -0
- package/dist/ui-host.js +275 -0
- package/dist/ui-host.js.map +1 -0
- package/dist/web/assets/index-BwfuGMvv.css +1 -0
- package/dist/web/assets/index-DPUaJqFJ.js +41 -0
- package/dist/web/assets/index-DPUaJqFJ.js.map +1 -0
- package/dist/web/index.html +14 -0
- package/dist/web-command.d.ts +11 -0
- package/dist/web-command.d.ts.map +1 -0
- package/dist/web-command.js +114 -0
- package/dist/web-command.js.map +1 -0
- package/dist/web-frontend.d.ts +73 -0
- package/dist/web-frontend.d.ts.map +1 -0
- package/dist/web-frontend.js +249 -0
- package/dist/web-frontend.js.map +1 -0
- package/dist/web.d.ts +254 -0
- package/dist/web.d.ts.map +1 -0
- package/dist/web.js +740 -0
- package/dist/web.js.map +1 -0
- package/dist/webui-entry.d.ts +3 -0
- package/dist/webui-entry.d.ts.map +1 -0
- package/dist/webui-entry.js +73 -0
- package/dist/webui-entry.js.map +1 -0
- package/dist/webui.d.ts +91 -0
- package/dist/webui.d.ts.map +1 -0
- package/dist/webui.js +882 -0
- package/dist/webui.js.map +1 -0
- package/package.json +89 -8
package/dist/main.js
CHANGED
|
@@ -1,542 +1,159 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { access, readdir, stat } from "node:fs/promises";
|
|
1
|
+
import { access } from "node:fs/promises";
|
|
3
2
|
import { homedir } from "node:os";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
function defaultSessionDirectory(agentDir, cwd) {
|
|
24
|
-
return join(agentDir, "sessions", workspaceStorageKey(cwd));
|
|
25
|
-
}
|
|
26
|
-
const STARTUP_STATUS_COLORS = {
|
|
27
|
-
error: "\x1b[31m",
|
|
28
|
-
success: "\x1b[32m",
|
|
29
|
-
warning: "\x1b[33m",
|
|
30
|
-
reset: "\x1b[0m",
|
|
31
|
-
};
|
|
32
|
-
function formatMcpStatus(status) {
|
|
33
|
-
switch (status.state) {
|
|
34
|
-
case "connecting":
|
|
35
|
-
return `${STARTUP_STATUS_COLORS.warning}MCP [loading]${STARTUP_STATUS_COLORS.reset} ${status.serverId}`;
|
|
36
|
-
case "connected":
|
|
37
|
-
return `${STARTUP_STATUS_COLORS.success}MCP [ok]${STARTUP_STATUS_COLORS.reset} ${status.serverId} (${status.tools} tools, ${status.resources} resources, ${status.prompts} prompts)`;
|
|
38
|
-
case "failed":
|
|
39
|
-
return `${STARTUP_STATUS_COLORS.error}MCP [error]${STARTUP_STATUS_COLORS.reset} ${status.serverId} (${status.stage}): ${status.message}`;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function formatMcpDiagnostic(serverId, stage, message) {
|
|
43
|
-
return `${STARTUP_STATUS_COLORS.error}MCP [error]${STARTUP_STATUS_COLORS.reset} ${serverId ?? "configuration"} (${stage}): ${message}\n`;
|
|
44
|
-
}
|
|
45
|
-
function formatPluginStatus(status) {
|
|
46
|
-
switch (status.state) {
|
|
47
|
-
case "loading":
|
|
48
|
-
return `${STARTUP_STATUS_COLORS.warning}Plugin [loading]${STARTUP_STATUS_COLORS.reset} ${status.pluginId}`;
|
|
49
|
-
case "loaded":
|
|
50
|
-
return `${STARTUP_STATUS_COLORS.success}Plugin [ok]${STARTUP_STATUS_COLORS.reset} ${status.pluginId} (${status.tools} tools, ${status.commands} commands)`;
|
|
51
|
-
case "failed":
|
|
52
|
-
return `${STARTUP_STATUS_COLORS.error}Plugin [error]${STARTUP_STATUS_COLORS.reset} ${status.pluginId ?? "plugin"} (${status.stage}): ${status.message}`;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function formatPluginDiagnostic(pluginId, stage, message) {
|
|
56
|
-
return `${STARTUP_STATUS_COLORS.error}Plugin [error]${STARTUP_STATUS_COLORS.reset} ${pluginId ?? "plugin"} (${stage}): ${message}\n`;
|
|
57
|
-
}
|
|
58
|
-
function pluginStatusKey(status) {
|
|
59
|
-
if (status.state === "failed" && status.pluginId === undefined)
|
|
60
|
-
return `plugin:${status.sourcePath}`;
|
|
61
|
-
return `plugin:${status.pluginId}`;
|
|
62
|
-
}
|
|
63
|
-
/** Renders startup states in place so terminal history retains only their final outcome. */
|
|
64
|
-
export class StartupStatusRenderer {
|
|
65
|
-
lines = [];
|
|
66
|
-
indexes = new Map();
|
|
67
|
-
write;
|
|
68
|
-
replaceInPlace;
|
|
69
|
-
width;
|
|
70
|
-
constructor(write, replaceInPlace, width = 80) {
|
|
71
|
-
this.write = write;
|
|
72
|
-
this.replaceInPlace = replaceInPlace;
|
|
73
|
-
this.width = width;
|
|
74
|
-
}
|
|
75
|
-
update(key, text) {
|
|
76
|
-
const line = truncateToWidth(text.replace(/[\r\n]+/g, " "), Math.max(1, this.width), "...");
|
|
77
|
-
const index = this.indexes.get(key);
|
|
78
|
-
if (index === undefined || !this.replaceInPlace) {
|
|
79
|
-
this.indexes.set(key, this.lines.length);
|
|
80
|
-
this.lines.push(line);
|
|
81
|
-
this.write(`${line}\n`);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
this.lines[index] = line;
|
|
85
|
-
const offset = this.lines.length - index;
|
|
86
|
-
this.write(`\x1b[${offset}A\r\x1b[2K${line}\x1b[${offset}B\r`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function startupStatusRenderer(write, interactive) {
|
|
90
|
-
const width = typeof process.stderr.columns === "number" && process.stderr.columns > 0 ? process.stderr.columns : 80;
|
|
91
|
-
return new StartupStatusRenderer(write, interactive && process.stderr.isTTY === true, width);
|
|
92
|
-
}
|
|
93
|
-
async function openOrCreateSession(filePath, cwd, now) {
|
|
94
|
-
try {
|
|
95
|
-
await access(filePath);
|
|
96
|
-
return await SessionManager.open(filePath, { now });
|
|
97
|
-
}
|
|
98
|
-
catch (cause) {
|
|
99
|
-
if (!(cause instanceof Error && "code" in cause && cause.code === "ENOENT"))
|
|
100
|
-
throw cause;
|
|
101
|
-
return SessionManager.create({ filePath, cwd, now, deferCreate: true });
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function newSessionPath(sessionDirectory, now) {
|
|
105
|
-
return join(sessionDirectory, `session-${now()}-${randomUUID().slice(0, 8)}.jsonl`);
|
|
106
|
-
}
|
|
107
|
-
async function mostRecentSessionPath(sessionDirectory) {
|
|
108
|
-
let names;
|
|
109
|
-
try {
|
|
110
|
-
names = (await readdir(sessionDirectory, { withFileTypes: true }))
|
|
111
|
-
.filter((entry) => entry.isFile() && extname(entry.name) === ".jsonl")
|
|
112
|
-
.map((entry) => entry.name);
|
|
113
|
-
}
|
|
114
|
-
catch (cause) {
|
|
115
|
-
if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
|
|
116
|
-
return undefined;
|
|
117
|
-
throw cause;
|
|
118
|
-
}
|
|
119
|
-
const candidates = await Promise.all(names.map(async (name) => {
|
|
120
|
-
const filePath = join(sessionDirectory, name);
|
|
121
|
-
try {
|
|
122
|
-
return { filePath, modifiedAt: (await stat(filePath)).mtimeMs };
|
|
123
|
-
}
|
|
124
|
-
catch (cause) {
|
|
125
|
-
if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
|
|
126
|
-
return undefined;
|
|
127
|
-
throw cause;
|
|
128
|
-
}
|
|
129
|
-
}));
|
|
130
|
-
return candidates
|
|
131
|
-
.filter((candidate) => candidate !== undefined)
|
|
132
|
-
.sort((left, right) => right.modifiedAt - left.modifiedAt || right.filePath.localeCompare(left.filePath))[0]
|
|
133
|
-
?.filePath;
|
|
134
|
-
}
|
|
135
|
-
async function hasProjectLocalCapabilities(cwd) {
|
|
136
|
-
const directories = [
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { hostCommandRegistryKey, processExitKey, sessionStoreKey } from "@di-code/builtins";
|
|
5
|
+
import { createCompositionLoader } from "@di-code/plugin-loader";
|
|
6
|
+
import { createRootContext, redactSensitiveText } from "@di-code/plugin-runtime";
|
|
7
|
+
import { createCliParser } from "./cli.js";
|
|
8
|
+
import { importCompositionModule, resolveCompositionEntries, resolveManagedCompositionEntries, } from "./compositions.js";
|
|
9
|
+
import { createProjectTrustStore } from "./project-trust-entry.js";
|
|
10
|
+
import { pluginInventoryKey } from "./runtime/plugin-inventory-service.js";
|
|
11
|
+
function errorMessage(cause) {
|
|
12
|
+
return redactSensitiveText(cause instanceof Error ? cause.message : String(cause));
|
|
13
|
+
}
|
|
14
|
+
function isRun(command) {
|
|
15
|
+
return command.kind === "run";
|
|
16
|
+
}
|
|
17
|
+
function isMinimalCommand(command) {
|
|
18
|
+
return command.kind === "run" || command.kind === "plugin" || command.kind === "observe";
|
|
19
|
+
}
|
|
20
|
+
async function hasTrustedProjectContent(cwd) {
|
|
21
|
+
for (const path of [
|
|
137
22
|
join(cwd, ".di-code", "skills"),
|
|
138
23
|
join(cwd, ".agents", "skills"),
|
|
139
|
-
join(cwd, ".di-code", "extensions"),
|
|
140
|
-
join(cwd, ".di-code", "plugins"),
|
|
141
24
|
join(cwd, ".di-code", "mcp.local.json"),
|
|
142
25
|
join(cwd, ".mcp.json"),
|
|
143
|
-
]
|
|
144
|
-
const results = await Promise.all(directories.map(async (directory) => {
|
|
26
|
+
]) {
|
|
145
27
|
try {
|
|
146
|
-
|
|
147
|
-
return
|
|
28
|
+
await access(path);
|
|
29
|
+
return true;
|
|
148
30
|
}
|
|
149
31
|
catch (cause) {
|
|
150
|
-
if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
|
|
151
|
-
|
|
152
|
-
return false;
|
|
32
|
+
if (!(cause instanceof Error && "code" in cause && cause.code === "ENOENT"))
|
|
33
|
+
throw cause;
|
|
153
34
|
}
|
|
154
|
-
}));
|
|
155
|
-
return results.some(Boolean);
|
|
156
|
-
}
|
|
157
|
-
async function selectStartupSession(command, allowedRoot, agentDir, now) {
|
|
158
|
-
const sessionDirectory = defaultSessionDirectory(agentDir, allowedRoot);
|
|
159
|
-
if (command.sessionPath !== undefined) {
|
|
160
|
-
return openOrCreateSession(resolve(allowedRoot, command.sessionPath), allowedRoot, now);
|
|
161
|
-
}
|
|
162
|
-
if (command.continueSession) {
|
|
163
|
-
const recentPath = await mostRecentSessionPath(sessionDirectory);
|
|
164
|
-
if (recentPath !== undefined)
|
|
165
|
-
return SessionManager.open(recentPath, { now });
|
|
166
35
|
}
|
|
167
|
-
return
|
|
168
|
-
filePath: newSessionPath(sessionDirectory, now),
|
|
169
|
-
cwd: allowedRoot,
|
|
170
|
-
now,
|
|
171
|
-
deferCreate: true,
|
|
172
|
-
});
|
|
36
|
+
return false;
|
|
173
37
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
38
|
+
/** Starts a composition profile and executes its registered host command. */
|
|
39
|
+
export async function runMinimalProfile(args, options) {
|
|
40
|
+
const parser = createCliParser();
|
|
41
|
+
let command;
|
|
178
42
|
try {
|
|
179
|
-
|
|
180
|
-
timeZone: timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
181
|
-
year: "numeric",
|
|
182
|
-
month: "2-digit",
|
|
183
|
-
day: "2-digit",
|
|
184
|
-
hour: "2-digit",
|
|
185
|
-
minute: "2-digit",
|
|
186
|
-
hourCycle: "h23",
|
|
187
|
-
})
|
|
188
|
-
.formatToParts(date)
|
|
189
|
-
.filter((part) => part.type !== "literal")
|
|
190
|
-
.map((part) => [part.type, part.value]));
|
|
191
|
-
const year = parts.get("year");
|
|
192
|
-
const month = parts.get("month");
|
|
193
|
-
const day = parts.get("day");
|
|
194
|
-
const hour = parts.get("hour");
|
|
195
|
-
const minute = parts.get("minute");
|
|
196
|
-
if (!year || !month || !day || !hour || !minute)
|
|
197
|
-
return fallback;
|
|
198
|
-
return `${year}-${month}-${day} ${hour}:${minute}`;
|
|
43
|
+
command = parser.parse(args);
|
|
199
44
|
}
|
|
200
|
-
catch {
|
|
201
|
-
|
|
45
|
+
catch (cause) {
|
|
46
|
+
options.stderr(`${errorMessage(cause)}\n`);
|
|
47
|
+
return 1;
|
|
202
48
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const fileName = basename(manager.filePath, extname(manager.filePath));
|
|
207
|
-
if (firstUserEntry?.type !== "message" || firstUserEntry.message.role !== "user") {
|
|
208
|
-
return `${fileName} (${formatSessionTimestamp(Date.parse(manager.header.timestamp), manager.header.timestamp, timeZone)})`;
|
|
49
|
+
if (command.kind === "help") {
|
|
50
|
+
options.stdout(`${parser.help("en")}\n`);
|
|
51
|
+
return 0;
|
|
209
52
|
}
|
|
210
|
-
|
|
211
|
-
.
|
|
212
|
-
|
|
213
|
-
.join(" ")
|
|
214
|
-
.replace(/\s+/g, " ")
|
|
215
|
-
.trim();
|
|
216
|
-
const label = question.length > MAX_SESSION_QUESTION_LENGTH
|
|
217
|
-
? `${question.slice(0, MAX_SESSION_QUESTION_LENGTH - 3)}...`
|
|
218
|
-
: question || fileName;
|
|
219
|
-
const timestamp = formatSessionTimestamp(firstUserEntry.message.timestamp, firstUserEntry.timestamp, timeZone);
|
|
220
|
-
return `${label} (${timestamp})`;
|
|
221
|
-
}
|
|
222
|
-
async function sessionChoices(sessionDirectory, currentFile, open) {
|
|
223
|
-
let names = [];
|
|
224
|
-
try {
|
|
225
|
-
names = (await readdir(sessionDirectory, { withFileTypes: true }))
|
|
226
|
-
.filter((entry) => entry.isFile() && extname(entry.name) === ".jsonl")
|
|
227
|
-
.map((entry) => entry.name)
|
|
228
|
-
.sort();
|
|
53
|
+
if (command.kind === "version") {
|
|
54
|
+
options.stdout(`${options.version}\n`);
|
|
55
|
+
return 0;
|
|
229
56
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
57
|
+
if (!isMinimalCommand(command)) {
|
|
58
|
+
options.stderr("MCP commands are unavailable in the minimal profile.\n");
|
|
59
|
+
return 1;
|
|
233
60
|
}
|
|
234
|
-
|
|
235
|
-
.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
61
|
+
if (isRun(command) && command.mode === "interactive" && !options.interactive?.isInteractiveTerminal) {
|
|
62
|
+
options.stderr("Interactive mode requires an interactive TTY.\n");
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
const mode = isRun(command) ? command.mode : "print";
|
|
66
|
+
const observability = command.kind === "observe";
|
|
67
|
+
const allowedRoot = resolve(options.allowedRoot ?? process.cwd());
|
|
68
|
+
const agentDir = resolve(options.agentDir ?? join(homedir(), ".di-code"));
|
|
69
|
+
const trustStore = createProjectTrustStore(join(agentDir, "trust.json"));
|
|
70
|
+
if (isRun(command) && command.projectTrust !== undefined)
|
|
71
|
+
await trustStore.set(allowedRoot, command.projectTrust);
|
|
72
|
+
let projectTrusted = isRun(command) && !command.noProjectPlugins && (await trustStore.get(allowedRoot)) === true;
|
|
73
|
+
if (isRun(command) &&
|
|
74
|
+
command.mode === "interactive" &&
|
|
75
|
+
!projectTrusted &&
|
|
76
|
+
command.projectTrust === undefined &&
|
|
77
|
+
options.interactive?.promptProjectTrust &&
|
|
78
|
+
(await hasTrustedProjectContent(allowedRoot))) {
|
|
79
|
+
projectTrusted = await options.interactive.promptProjectTrust(allowedRoot);
|
|
80
|
+
await trustStore.set(allowedRoot, projectTrusted);
|
|
81
|
+
}
|
|
82
|
+
const managedEntries = await resolveManagedCompositionEntries(agentDir);
|
|
83
|
+
const compositionEntries = await resolveCompositionEntries(isRun(command) ? (command.profile ?? command.mode) : "base", {
|
|
84
|
+
cwd: allowedRoot,
|
|
85
|
+
agentDir,
|
|
86
|
+
...(isRun(command) && command.compositionPath ? { compositionPath: command.compositionPath } : {}),
|
|
87
|
+
includeProjectComposition: projectTrusted,
|
|
88
|
+
observability,
|
|
89
|
+
allowedRoot,
|
|
90
|
+
});
|
|
91
|
+
const context = createRootContext({ id: "minimal-profile", mode, trustedProject: projectTrusted });
|
|
92
|
+
const unsubscribe = context.events.subscribe((event) => options.onRuntimeEvent?.(event));
|
|
93
|
+
const loader = createCompositionLoader({
|
|
94
|
+
context,
|
|
95
|
+
entries: [...compositionEntries, ...managedEntries],
|
|
96
|
+
importModule: options.importModule ?? importCompositionModule,
|
|
97
|
+
projectTrusted,
|
|
98
|
+
});
|
|
99
|
+
try {
|
|
100
|
+
await loader.load();
|
|
101
|
+
context.require(pluginInventoryKey).set(loader.tree.snapshot());
|
|
102
|
+
const host = context.require(hostCommandRegistryKey);
|
|
103
|
+
let name;
|
|
104
|
+
let input;
|
|
105
|
+
if (command.kind === "observe") {
|
|
106
|
+
name = command.action === "trace" ? "trace-plugins" : "dump-composition";
|
|
107
|
+
input = { stdout: options.stdout };
|
|
242
108
|
}
|
|
243
|
-
|
|
244
|
-
|
|
109
|
+
else if (command.kind === "plugin") {
|
|
110
|
+
name = "plugin";
|
|
111
|
+
input = { ...command, stdout: options.stdout, stderr: options.stderr };
|
|
245
112
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
open: () => open(filePath),
|
|
251
|
-
};
|
|
252
|
-
}));
|
|
253
|
-
}
|
|
254
|
-
export async function runMain(args, options) {
|
|
255
|
-
const dependencies = {
|
|
256
|
-
stdout: options.stdout,
|
|
257
|
-
stderr: options.stderr,
|
|
258
|
-
version: options.version,
|
|
259
|
-
locale: options.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE,
|
|
260
|
-
plugin: async (command) => {
|
|
261
|
-
const agentDir = resolve(options.agentDir ?? join(homedir(), ".di-code"));
|
|
262
|
-
const manager = new PluginManager({ agentDir });
|
|
263
|
-
try {
|
|
264
|
-
switch (command.action) {
|
|
265
|
-
case "list":
|
|
266
|
-
for (const plugin of await manager.list())
|
|
267
|
-
options.stdout(`${plugin.id}\t${plugin.enabled ? "enabled" : "disabled"}\t${plugin.manifest.version}\n`);
|
|
268
|
-
return 0;
|
|
269
|
-
case "install": {
|
|
270
|
-
const plugin = await manager.install(command.argument);
|
|
271
|
-
options.stdout(`Installed ${plugin.id}\n`);
|
|
272
|
-
return 0;
|
|
273
|
-
}
|
|
274
|
-
case "enable":
|
|
275
|
-
await manager.enable(command.argument);
|
|
276
|
-
return 0;
|
|
277
|
-
case "disable":
|
|
278
|
-
await manager.disable(command.argument);
|
|
279
|
-
return 0;
|
|
280
|
-
case "update":
|
|
281
|
-
await manager.update(command.argument);
|
|
282
|
-
return 0;
|
|
283
|
-
case "remove":
|
|
284
|
-
await manager.remove(command.argument);
|
|
285
|
-
return 0;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
catch (cause) {
|
|
289
|
-
options.stderr(`${cause instanceof Error ? cause.message : String(cause)}\n`);
|
|
290
|
-
return 1;
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
mcp: async (command) => {
|
|
294
|
-
const cwd = resolve(options.allowedRoot ?? process.cwd());
|
|
295
|
-
const scope = command.scope;
|
|
296
|
-
const trustManager = new ProjectTrustManager(join(options.agentDir ?? join(homedir(), ".di-code"), "trust.json"));
|
|
297
|
-
const requireProjectTrust = async (selected) => {
|
|
298
|
-
if ((selected === "local" || selected === "project") && (await trustManager.get(cwd)) !== true)
|
|
299
|
-
throw new Error(`Project trust is required to modify the ${selected} MCP scope.`);
|
|
300
|
-
};
|
|
301
|
-
try {
|
|
302
|
-
switch (command.action) {
|
|
303
|
-
case "add": {
|
|
304
|
-
const selected = scope ?? "local";
|
|
305
|
-
await requireProjectTrust(selected);
|
|
306
|
-
const config = command.transport === "stdio"
|
|
307
|
-
? {
|
|
308
|
-
command: command.command,
|
|
309
|
-
...(command.args && command.args.length > 0 ? { args: command.args } : {}),
|
|
310
|
-
}
|
|
311
|
-
: { type: "http", url: command.url };
|
|
312
|
-
await addMcpConfig(cwd, selected, command.serverId, config);
|
|
313
|
-
options.stdout(`Added MCP server "${command.serverId}" to ${selected} scope.\n`);
|
|
314
|
-
return 0;
|
|
315
|
-
}
|
|
316
|
-
case "list": {
|
|
317
|
-
const scopes = scope ? [scope] : ["local", "project", "user"];
|
|
318
|
-
for (const selected of scopes) {
|
|
319
|
-
for (const entry of await listMcpConfig(cwd, selected))
|
|
320
|
-
options.stdout(`${entry.id}\t${entry.scope}\t${JSON.stringify(entry.config)}\n`);
|
|
321
|
-
}
|
|
322
|
-
return 0;
|
|
323
|
-
}
|
|
324
|
-
case "get": {
|
|
325
|
-
const entry = await getMcpConfig(cwd, command.serverId, scope);
|
|
326
|
-
if (!entry)
|
|
327
|
-
throw new Error(`MCP server "${command.serverId}" was not found.`);
|
|
328
|
-
options.stdout(`${JSON.stringify({ id: entry.id, scope: entry.scope, config: entry.config })}\n`);
|
|
329
|
-
return 0;
|
|
330
|
-
}
|
|
331
|
-
case "remove": {
|
|
332
|
-
const selected = scope ?? "local";
|
|
333
|
-
await requireProjectTrust(selected);
|
|
334
|
-
await removeMcpConfig(cwd, selected, command.serverId);
|
|
335
|
-
options.stdout(`Removed MCP server "${command.serverId}" from ${selected} scope.\n`);
|
|
336
|
-
return 0;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
catch (cause) {
|
|
341
|
-
options.stderr(`${cause instanceof Error ? cause.message : String(cause)}\n`);
|
|
342
|
-
return 1;
|
|
343
|
-
}
|
|
344
|
-
},
|
|
345
|
-
run: async (command) => {
|
|
346
|
-
const allowedRoot = resolve(options.allowedRoot ?? process.cwd());
|
|
347
|
-
const now = options.now ?? Date.now;
|
|
348
|
-
const agentDir = resolve(options.agentDir ?? join(homedir(), ".di-code"));
|
|
349
|
-
const trustManager = new ProjectTrustManager(join(agentDir, "trust.json"));
|
|
350
|
-
if (command.projectTrust !== undefined)
|
|
351
|
-
await trustManager.set(allowedRoot, command.projectTrust);
|
|
352
|
-
let persistedTrust = await trustManager.get(allowedRoot);
|
|
353
|
-
const shouldPromptForTrust = command.mode === "interactive" &&
|
|
354
|
-
options.isInteractiveTerminal === true &&
|
|
355
|
-
command.projectTrust === undefined &&
|
|
356
|
-
persistedTrust === null &&
|
|
357
|
-
options.promptProjectTrust !== undefined &&
|
|
358
|
-
(await hasProjectLocalCapabilities(allowedRoot));
|
|
359
|
-
if (shouldPromptForTrust) {
|
|
360
|
-
let decision = false;
|
|
361
|
-
try {
|
|
362
|
-
decision = await options.promptProjectTrust(allowedRoot);
|
|
363
|
-
}
|
|
364
|
-
catch {
|
|
365
|
-
// Fail closed when the prompt is interrupted or unavailable.
|
|
366
|
-
}
|
|
367
|
-
await trustManager.set(allowedRoot, decision);
|
|
368
|
-
persistedTrust = decision;
|
|
369
|
-
}
|
|
370
|
-
const runtime = await options.createRuntime(command);
|
|
371
|
-
if (runtime === undefined)
|
|
372
|
-
return 0;
|
|
373
|
-
const resources = await loadResources({
|
|
374
|
-
cwd: allowedRoot,
|
|
375
|
-
agentDir,
|
|
376
|
-
projectTrusted: persistedTrust === true,
|
|
377
|
-
noSkills: command.noSkills,
|
|
378
|
-
noContextFiles: command.noContextFiles,
|
|
379
|
-
skillPaths: command.skillPaths,
|
|
380
|
-
});
|
|
381
|
-
for (const diagnostic of resources.diagnostics) {
|
|
382
|
-
if (diagnostic.kind !== "skill")
|
|
383
|
-
continue;
|
|
384
|
-
options.stderr(`${JSON.stringify({ type: "skill_diagnostic", path: diagnostic.path, stage: diagnostic.stage, severity: diagnostic.severity, message: diagnostic.message })}\n`);
|
|
385
|
-
}
|
|
386
|
-
const interactivePluginStatus = command.mode === "interactive";
|
|
387
|
-
const startupStatus = startupStatusRenderer(options.stderr, interactivePluginStatus);
|
|
388
|
-
const pluginStatusFailures = new Set();
|
|
389
|
-
const extensions = await loadPlugins({
|
|
113
|
+
else if (command.mode === "interactive") {
|
|
114
|
+
name = "interactive";
|
|
115
|
+
input = {
|
|
116
|
+
command,
|
|
390
117
|
cwd: allowedRoot,
|
|
391
118
|
agentDir,
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
...(
|
|
395
|
-
? {
|
|
396
|
-
onPluginLoadStatus: (status) => {
|
|
397
|
-
if (status.state === "failed")
|
|
398
|
-
pluginStatusFailures.add(status.sourcePath);
|
|
399
|
-
startupStatus.update(pluginStatusKey(status), formatPluginStatus(status));
|
|
400
|
-
},
|
|
401
|
-
}
|
|
402
|
-
: {}),
|
|
403
|
-
});
|
|
404
|
-
for (const diagnostic of extensions.diagnostics) {
|
|
405
|
-
if (interactivePluginStatus) {
|
|
406
|
-
if (pluginStatusFailures.has(diagnostic.sourcePath))
|
|
407
|
-
continue;
|
|
408
|
-
options.stderr(formatPluginDiagnostic(diagnostic.pluginId, diagnostic.stage, diagnostic.message));
|
|
409
|
-
continue;
|
|
410
|
-
}
|
|
411
|
-
options.stderr(`${JSON.stringify({ type: "plugin_diagnostic", pluginId: diagnostic.pluginId, stage: diagnostic.stage, sourcePath: diagnostic.sourcePath, severity: diagnostic.severity, message: diagnostic.message })}\n`);
|
|
412
|
-
}
|
|
413
|
-
const interactiveMcpStatus = command.mode === "interactive";
|
|
414
|
-
const mcp = await loadProjectMcp({
|
|
415
|
-
cwd: allowedRoot,
|
|
416
|
-
projectTrusted: persistedTrust === true,
|
|
417
|
-
homeDirectory: homedir(),
|
|
418
|
-
reservedToolNames: [
|
|
419
|
-
"read",
|
|
420
|
-
"write",
|
|
421
|
-
"edit",
|
|
422
|
-
"bash",
|
|
423
|
-
"load_skill",
|
|
424
|
-
...extensions.host.listTools().map((tool) => tool.name),
|
|
425
|
-
],
|
|
426
|
-
...(interactiveMcpStatus
|
|
427
|
-
? {
|
|
428
|
-
onServerConnectionStatus: (status) => startupStatus.update(`mcp:${status.serverId}`, formatMcpStatus(status)),
|
|
429
|
-
}
|
|
119
|
+
projectTrusted,
|
|
120
|
+
stderr: options.stderr,
|
|
121
|
+
...(options.interactive?.startInteractiveMode
|
|
122
|
+
? { startInteractiveMode: options.interactive.startInteractiveMode }
|
|
430
123
|
: {}),
|
|
431
|
-
});
|
|
432
|
-
for (const diagnostic of mcp.diagnostics) {
|
|
433
|
-
if (interactiveMcpStatus) {
|
|
434
|
-
if (diagnostic.serverId && (diagnostic.stage === "connect" || diagnostic.stage === "list_tools"))
|
|
435
|
-
continue;
|
|
436
|
-
options.stderr(formatMcpDiagnostic(diagnostic.serverId, diagnostic.stage, diagnostic.message));
|
|
437
|
-
continue;
|
|
438
|
-
}
|
|
439
|
-
options.stderr(`${JSON.stringify({ type: "mcp_diagnostic", serverId: diagnostic.serverId, stage: diagnostic.stage, message: diagnostic.message })}\n`);
|
|
440
|
-
}
|
|
441
|
-
const systemPrompt = buildSystemPrompt({ cwd: allowedRoot, ...resources });
|
|
442
|
-
const manager = await selectStartupSession(command, allowedRoot, agentDir, now);
|
|
443
|
-
const sessionFile = manager.filePath;
|
|
444
|
-
const session = new AgentSession({
|
|
445
|
-
allowedRoot,
|
|
446
|
-
provider: runtime.provider,
|
|
447
|
-
model: runtime.model,
|
|
448
|
-
systemPrompt,
|
|
449
|
-
skills: resources.skills,
|
|
450
|
-
now: options.now,
|
|
451
|
-
sessionManager: manager,
|
|
452
|
-
extensionHost: extensions.host,
|
|
453
|
-
externalTools: mcp.tools,
|
|
454
|
-
});
|
|
455
|
-
const imagePaths = command.imagePaths ?? [];
|
|
456
|
-
const promptRunner = {
|
|
457
|
-
prompt: async (text) => session.promptWithImages(text, await loadImageInputs(imagePaths, allowedRoot)),
|
|
458
|
-
subscribe: session.subscribe.bind(session),
|
|
459
124
|
};
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
locale: options.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE,
|
|
478
|
-
onExit: () => {
|
|
479
|
-
void mcp.manager.close();
|
|
480
|
-
},
|
|
481
|
-
extensionHost: extensions.host,
|
|
482
|
-
...(options.startupConfiguration
|
|
483
|
-
? { providerOnboarding: { configuration: options.startupConfiguration, agentDir } }
|
|
484
|
-
: {}),
|
|
485
|
-
sessions: [
|
|
486
|
-
{
|
|
487
|
-
id: "new-session",
|
|
488
|
-
label: translate(options.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE, "newSession"),
|
|
489
|
-
description: translate(options.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE, "newSessionDescription"),
|
|
490
|
-
open: async () => {
|
|
491
|
-
const filePath = newSessionPath(dirname(sessionFile), now);
|
|
492
|
-
const nextManager = await SessionManager.create({
|
|
493
|
-
filePath,
|
|
494
|
-
cwd: allowedRoot,
|
|
495
|
-
now,
|
|
496
|
-
deferCreate: true,
|
|
497
|
-
});
|
|
498
|
-
return new AgentSession({
|
|
499
|
-
allowedRoot,
|
|
500
|
-
provider: runtime.provider,
|
|
501
|
-
model: runtime.model,
|
|
502
|
-
systemPrompt,
|
|
503
|
-
skills: resources.skills,
|
|
504
|
-
now: options.now,
|
|
505
|
-
sessionManager: nextManager,
|
|
506
|
-
extensionHost: extensions.host,
|
|
507
|
-
externalTools: mcp.tools,
|
|
508
|
-
});
|
|
509
|
-
},
|
|
510
|
-
},
|
|
511
|
-
...(await sessionChoices(dirname(sessionFile), sessionFile, async (filePath) => {
|
|
512
|
-
const nextManager = await SessionManager.open(filePath, { now });
|
|
513
|
-
return new AgentSession({
|
|
514
|
-
allowedRoot,
|
|
515
|
-
provider: runtime.provider,
|
|
516
|
-
model: runtime.model,
|
|
517
|
-
systemPrompt,
|
|
518
|
-
skills: resources.skills,
|
|
519
|
-
now: options.now,
|
|
520
|
-
sessionManager: nextManager,
|
|
521
|
-
extensionHost: extensions.host,
|
|
522
|
-
externalTools: mcp.tools,
|
|
523
|
-
});
|
|
524
|
-
})),
|
|
525
|
-
],
|
|
526
|
-
});
|
|
527
|
-
mode.start(command.prompt);
|
|
528
|
-
return 0;
|
|
529
|
-
}
|
|
530
|
-
await extensions.host.emit({ type: "session_start", cwd: allowedRoot });
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
name = command.mode;
|
|
128
|
+
input = { prompt: command.prompt, stdout: options.stdout };
|
|
129
|
+
}
|
|
130
|
+
const code = await host.execute(name, input, context.signal);
|
|
131
|
+
const processExit = context.require(processExitKey);
|
|
132
|
+
processExit.setCode(code);
|
|
133
|
+
return processExit.code();
|
|
134
|
+
}
|
|
135
|
+
catch (cause) {
|
|
136
|
+
options.stderr(`${errorMessage(cause).replace(/^Required entry agent-loop failed: /, "")}\n`);
|
|
137
|
+
return 1;
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
const memory = context.get(sessionStoreKey);
|
|
141
|
+
try {
|
|
531
142
|
try {
|
|
532
|
-
|
|
143
|
+
await loader.dispose();
|
|
533
144
|
}
|
|
534
145
|
finally {
|
|
535
|
-
await
|
|
536
|
-
await mcp.manager.close();
|
|
146
|
+
await context.dispose();
|
|
537
147
|
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
unsubscribe();
|
|
151
|
+
if (memory) {
|
|
152
|
+
memory.dispose();
|
|
153
|
+
if (memory.disposed())
|
|
154
|
+
options.onSessionDisposed?.();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
541
158
|
}
|
|
542
159
|
//# sourceMappingURL=main.js.map
|