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