@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
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { access, readdir, stat } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { basename, extname, join, resolve } from "node:path";
|
|
4
|
+
import { agentSessionKey, commandRegistryKey, keybindingRegistryKey, modeRegistryKey, } from "@di-code/builtins";
|
|
5
|
+
import { createCompositionLoader, ProjectTrustStore } from "@di-code/plugin-loader";
|
|
6
|
+
import { createRootContext, redactSensitiveText } from "@di-code/plugin-runtime";
|
|
7
|
+
import { ProcessTerminal } from "@di-code/tui";
|
|
8
|
+
import { createCliParser } from "./cli.js";
|
|
9
|
+
import { importCompositionModule, resolveCompositionEntries, resolveManagedCompositionEntries, } from "./compositions.js";
|
|
10
|
+
import { loadResources } from "./core/resources/loader.js";
|
|
11
|
+
import { SessionManager } from "./core/session/session-manager.js";
|
|
12
|
+
import { AgentSession } from "./core/session.js";
|
|
13
|
+
import { buildSystemPrompt } from "./core/system-prompt.js";
|
|
14
|
+
import { workspaceStorageKey } from "./core/user-data.js";
|
|
15
|
+
import { DEFAULT_LOCALE, translate } from "./i18n.js";
|
|
16
|
+
import { mcpClientServiceKey, mcpConfigServiceKey, mcpToolServiceKey } from "./mcp/entries.js";
|
|
17
|
+
import { runInteractiveMode } from "./modes/interactive-entry.js";
|
|
18
|
+
import { runProviderOnboarding, shouldStartProviderOnboarding } from "./provider-onboarding.js";
|
|
19
|
+
import { pluginInventoryKey } from "./runtime/plugin-inventory-service.js";
|
|
20
|
+
import { loadStartupConfiguration, resolveStartupRuntime } from "./startup.js";
|
|
21
|
+
function errorMessage(cause) {
|
|
22
|
+
return redactSensitiveText(cause instanceof Error ? cause.message : String(cause));
|
|
23
|
+
}
|
|
24
|
+
function isInteractiveRun(command) {
|
|
25
|
+
return command.kind === "run" && command.mode === "interactive";
|
|
26
|
+
}
|
|
27
|
+
async function exists(path) {
|
|
28
|
+
try {
|
|
29
|
+
await access(path);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
catch (cause) {
|
|
33
|
+
if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
|
|
34
|
+
return false;
|
|
35
|
+
throw cause;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function hasTrustedProjectContent(cwd) {
|
|
39
|
+
for (const path of [
|
|
40
|
+
join(cwd, ".di-code", "skills"),
|
|
41
|
+
join(cwd, ".agents", "skills"),
|
|
42
|
+
join(cwd, ".di-code", "mcp.local.json"),
|
|
43
|
+
join(cwd, ".mcp.json"),
|
|
44
|
+
]) {
|
|
45
|
+
if (await exists(path))
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
function sessionDirectory(agentDir, cwd) {
|
|
51
|
+
return join(agentDir, "sessions", workspaceStorageKey(cwd));
|
|
52
|
+
}
|
|
53
|
+
function newSessionPath(directory) {
|
|
54
|
+
return join(directory, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}.jsonl`);
|
|
55
|
+
}
|
|
56
|
+
async function openInteractiveSession(command, cwd, agentDir) {
|
|
57
|
+
const directory = sessionDirectory(agentDir, cwd);
|
|
58
|
+
if (command.sessionPath !== undefined)
|
|
59
|
+
return await SessionManager.open(resolve(cwd, command.sessionPath));
|
|
60
|
+
if (command.continueSession) {
|
|
61
|
+
try {
|
|
62
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
63
|
+
const candidates = await Promise.all(entries
|
|
64
|
+
.filter((entry) => entry.isFile() && extname(entry.name) === ".jsonl")
|
|
65
|
+
.map(async (entry) => ({
|
|
66
|
+
path: join(directory, entry.name),
|
|
67
|
+
modified: (await stat(join(directory, entry.name))).mtimeMs,
|
|
68
|
+
})));
|
|
69
|
+
const recent = candidates.sort((left, right) => right.modified - left.modified)[0];
|
|
70
|
+
if (recent)
|
|
71
|
+
return await SessionManager.open(recent.path);
|
|
72
|
+
}
|
|
73
|
+
catch (cause) {
|
|
74
|
+
if (!(cause instanceof Error && "code" in cause && cause.code === "ENOENT"))
|
|
75
|
+
throw cause;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return await SessionManager.create({ filePath: newSessionPath(directory), cwd, deferCreate: true });
|
|
79
|
+
}
|
|
80
|
+
function formatSessionLabel(manager) {
|
|
81
|
+
const fileName = basename(manager.filePath, extname(manager.filePath));
|
|
82
|
+
const firstUserEntry = manager.entries.find((entry) => entry.type === "message" && entry.message.role === "user");
|
|
83
|
+
if (firstUserEntry?.type !== "message" || firstUserEntry.message.role !== "user")
|
|
84
|
+
return fileName;
|
|
85
|
+
const question = firstUserEntry.message.content
|
|
86
|
+
.filter((content) => content.type === "text")
|
|
87
|
+
.map((content) => content.text)
|
|
88
|
+
.join(" ")
|
|
89
|
+
.replace(/\s+/g, " ")
|
|
90
|
+
.trim();
|
|
91
|
+
return question.length > 72 ? `${question.slice(0, 69)}...` : question || fileName;
|
|
92
|
+
}
|
|
93
|
+
async function interactiveSessionChoices(directory, currentFile, open) {
|
|
94
|
+
let entries = [];
|
|
95
|
+
try {
|
|
96
|
+
entries = (await readdir(directory, { withFileTypes: true }))
|
|
97
|
+
.filter((entry) => entry.isFile() && extname(entry.name) === ".jsonl")
|
|
98
|
+
.map((entry) => entry.name)
|
|
99
|
+
.sort();
|
|
100
|
+
}
|
|
101
|
+
catch (cause) {
|
|
102
|
+
if (!(cause instanceof Error && "code" in cause && cause.code === "ENOENT"))
|
|
103
|
+
throw cause;
|
|
104
|
+
}
|
|
105
|
+
return await Promise.all(entries
|
|
106
|
+
.filter((name) => resolve(directory, name) !== resolve(currentFile))
|
|
107
|
+
.map(async (name) => {
|
|
108
|
+
const filePath = join(directory, name);
|
|
109
|
+
let label = basename(name, extname(name));
|
|
110
|
+
try {
|
|
111
|
+
label = formatSessionLabel(await SessionManager.open(filePath));
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Retain corrupted files as choices so their detailed recovery diagnostic remains visible on open.
|
|
115
|
+
}
|
|
116
|
+
return { id: basename(name, extname(name)), label, description: filePath, open: () => open(filePath) };
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
/** Starts interactive TUI through the default composition without importing legacy plugin or extension hosts. */
|
|
120
|
+
export async function runInteractiveProfile(args, options) {
|
|
121
|
+
const parser = createCliParser();
|
|
122
|
+
let command;
|
|
123
|
+
try {
|
|
124
|
+
command = parser.parse(args);
|
|
125
|
+
}
|
|
126
|
+
catch (cause) {
|
|
127
|
+
options.stderr(`${errorMessage(cause)}\n`);
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
if (!isInteractiveRun(command)) {
|
|
131
|
+
options.stderr("Interactive profile requires --interactive or --mode interactive.\n");
|
|
132
|
+
return 1;
|
|
133
|
+
}
|
|
134
|
+
if (!options.isInteractiveTerminal) {
|
|
135
|
+
options.stderr("Interactive mode requires an interactive TTY.\n");
|
|
136
|
+
return 1;
|
|
137
|
+
}
|
|
138
|
+
const cwd = resolve(options.allowedRoot ?? process.cwd());
|
|
139
|
+
const agentDir = resolve(options.agentDir ?? join(homedir(), ".di-code"));
|
|
140
|
+
const trustStore = new ProjectTrustStore(join(agentDir, "trust.json"));
|
|
141
|
+
try {
|
|
142
|
+
if (command.projectTrust !== undefined)
|
|
143
|
+
await trustStore.set(cwd, command.projectTrust);
|
|
144
|
+
let projectTrusted = (await trustStore.get(cwd)) === true;
|
|
145
|
+
if (!projectTrusted &&
|
|
146
|
+
command.projectTrust === undefined &&
|
|
147
|
+
options.promptProjectTrust &&
|
|
148
|
+
(await hasTrustedProjectContent(cwd))) {
|
|
149
|
+
try {
|
|
150
|
+
projectTrusted = await options.promptProjectTrust(cwd);
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
projectTrusted = false;
|
|
154
|
+
}
|
|
155
|
+
await trustStore.set(cwd, projectTrusted);
|
|
156
|
+
}
|
|
157
|
+
const configuration = await loadStartupConfiguration(cwd, process.env, agentDir);
|
|
158
|
+
const runtime = shouldStartProviderOnboarding(command, true, configuration)
|
|
159
|
+
? await runProviderOnboarding({ configuration, terminal: new ProcessTerminal(), agentDir })
|
|
160
|
+
: resolveStartupRuntime(configuration.environment, configuration.providers, configuration.defaults);
|
|
161
|
+
if (!runtime)
|
|
162
|
+
return 0;
|
|
163
|
+
const context = createRootContext({
|
|
164
|
+
id: "interactive-profile",
|
|
165
|
+
mode: "interactive",
|
|
166
|
+
trustedProject: projectTrusted,
|
|
167
|
+
});
|
|
168
|
+
const compositionEntries = await resolveCompositionEntries(command.profile ?? command.mode, {
|
|
169
|
+
cwd,
|
|
170
|
+
agentDir,
|
|
171
|
+
...(command.compositionPath ? { compositionPath: command.compositionPath } : {}),
|
|
172
|
+
includeProjectComposition: projectTrusted && !command.noProjectPlugins,
|
|
173
|
+
allowedRoot: cwd,
|
|
174
|
+
});
|
|
175
|
+
const unsubscribe = context.events.subscribe((event) => options.onRuntimeEvent?.(event));
|
|
176
|
+
const loader = createCompositionLoader({
|
|
177
|
+
context,
|
|
178
|
+
entries: [...compositionEntries, ...(await resolveManagedCompositionEntries(agentDir))],
|
|
179
|
+
importModule: options.importModule ?? importCompositionModule,
|
|
180
|
+
projectTrusted,
|
|
181
|
+
});
|
|
182
|
+
let closed = false;
|
|
183
|
+
let closeMcp;
|
|
184
|
+
const close = async () => {
|
|
185
|
+
if (closed)
|
|
186
|
+
return;
|
|
187
|
+
closed = true;
|
|
188
|
+
try {
|
|
189
|
+
await closeMcp?.();
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
try {
|
|
193
|
+
await loader.dispose();
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
await context.dispose();
|
|
197
|
+
unsubscribe();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
try {
|
|
202
|
+
await loader.load();
|
|
203
|
+
context.require(pluginInventoryKey).set(loader.tree.snapshot());
|
|
204
|
+
const resources = await loadResources({
|
|
205
|
+
cwd,
|
|
206
|
+
agentDir,
|
|
207
|
+
projectTrusted,
|
|
208
|
+
noSkills: command.noSkills,
|
|
209
|
+
noContextFiles: command.noContextFiles,
|
|
210
|
+
skillPaths: command.skillPaths,
|
|
211
|
+
});
|
|
212
|
+
for (const diagnostic of resources.diagnostics)
|
|
213
|
+
options.stderr(`${errorMessage(diagnostic.message)}\n`);
|
|
214
|
+
const configurations = await context.require(mcpConfigServiceKey).load({ cwd, projectTrusted });
|
|
215
|
+
const mcp = await context.require(mcpClientServiceKey).connect(configurations);
|
|
216
|
+
closeMcp = async () => {
|
|
217
|
+
await mcp.manager.close();
|
|
218
|
+
};
|
|
219
|
+
const externalTools = context
|
|
220
|
+
.require(mcpToolServiceKey)
|
|
221
|
+
.create(mcp.servers, ["read", "write", "edit", "glob", "grep", "bash", "load_skill"]);
|
|
222
|
+
const manager = await openInteractiveSession(command, cwd, agentDir);
|
|
223
|
+
const systemPrompt = buildSystemPrompt({ cwd, ...resources });
|
|
224
|
+
const createSession = async (sessionManager) => {
|
|
225
|
+
const session = await context.require(agentSessionKey).create({
|
|
226
|
+
allowedRoot: cwd,
|
|
227
|
+
provider: runtime.provider,
|
|
228
|
+
model: runtime.model,
|
|
229
|
+
systemPrompt,
|
|
230
|
+
skills: resources.skills,
|
|
231
|
+
sessionManager,
|
|
232
|
+
externalTools,
|
|
233
|
+
});
|
|
234
|
+
if (!(session instanceof AgentSession))
|
|
235
|
+
throw new Error("SessionFactory returned an incompatible interactive session.");
|
|
236
|
+
return session;
|
|
237
|
+
};
|
|
238
|
+
const session = await createSession(manager);
|
|
239
|
+
const directory = sessionDirectory(agentDir, cwd);
|
|
240
|
+
const sessionChoices = [
|
|
241
|
+
{
|
|
242
|
+
id: "new-session",
|
|
243
|
+
label: translate(configuration.locale ?? DEFAULT_LOCALE, "newSession"),
|
|
244
|
+
description: translate(configuration.locale ?? DEFAULT_LOCALE, "newSessionDescription"),
|
|
245
|
+
open: async () => await createSession(await SessionManager.create({ filePath: newSessionPath(directory), cwd, deferCreate: true })),
|
|
246
|
+
},
|
|
247
|
+
...(await interactiveSessionChoices(directory, manager.filePath, async (filePath) => createSession(await SessionManager.open(filePath)))),
|
|
248
|
+
];
|
|
249
|
+
let mode;
|
|
250
|
+
let theme = "dark";
|
|
251
|
+
const interactiveContext = {
|
|
252
|
+
sessionChoices: () => sessionChoices,
|
|
253
|
+
cancel: () => mode?.cancelActivePrompt(),
|
|
254
|
+
retry: () => mode?.retryLastPrompt(),
|
|
255
|
+
theme: () => theme,
|
|
256
|
+
setTheme: (value) => {
|
|
257
|
+
theme = value;
|
|
258
|
+
},
|
|
259
|
+
keybindings: () => context.get(keybindingRegistryKey)?.snapshot(),
|
|
260
|
+
};
|
|
261
|
+
const code = await context.require(modeRegistryKey).execute("interactive", {
|
|
262
|
+
run: () => (options.startInteractiveMode ?? runInteractiveMode)({
|
|
263
|
+
session,
|
|
264
|
+
agentDir,
|
|
265
|
+
locale: configuration.locale ?? DEFAULT_LOCALE,
|
|
266
|
+
commandRegistry: context.require(commandRegistryKey),
|
|
267
|
+
context: interactiveContext,
|
|
268
|
+
initialPrompt: command.prompt,
|
|
269
|
+
onCreated: (created) => {
|
|
270
|
+
mode = created;
|
|
271
|
+
},
|
|
272
|
+
onExit: () => {
|
|
273
|
+
void close();
|
|
274
|
+
},
|
|
275
|
+
}),
|
|
276
|
+
}, context.signal);
|
|
277
|
+
return code;
|
|
278
|
+
}
|
|
279
|
+
catch (cause) {
|
|
280
|
+
await close();
|
|
281
|
+
options.stderr(`${errorMessage(cause)}\n`);
|
|
282
|
+
return 1;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
catch (cause) {
|
|
286
|
+
options.stderr(`${errorMessage(cause)}\n`);
|
|
287
|
+
return 1;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=interactive-profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive-profile.js","sourceRoot":"","sources":["../src/interactive-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EACN,eAAe,EACf,kB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homedir } from \"node:os\";\nimport { basename, extname, join, resolve } from \"node:path\";\nimport {\n\tagentSessionKey,\n\tcommandRegistryKey,\n\ttype InteractiveContextService,\n\tkeybindingRegistryKey,\n\tmodeRegistryKey,\n} from \"@di-code/builtins\";\nimport { createCompositionLoader, type PluginModule, ProjectTrustStore } from \"@di-code/plugin-loader\";\nimport { createRootContext, type RuntimeEvent, redactSensitiveText } from \"@di-code/plugin-runtime\";\nimport { ProcessTerminal } from \"@di-code/tui\";\nimport { type CliCommand, createCliParser } from \"./cli.ts\";\nimport {\n\timportCompositionModule,\n\tresolveCompositionEntries,\n\tresolveManagedCompositionEntries,\n} from \"./compositions.ts\";\nimport { loadResources } from \"./core/resources/loader.ts\";\nimport { SessionManager } from \"./core/session/session-manager.ts\";\nimport { AgentSession } from \"./core/session.ts\";\nimport { buildSystemPrompt } from \"./core/system-prompt.ts\";\nimport { workspaceStorageKey } from \"./core/user-data.ts\";\nimport { DEFAULT_LOCALE, translate } from \"./i18n.ts\";\nimport { mcpClientServiceKey, mcpConfigServiceKey, mcpToolServiceKey } from \"./mcp/entries.ts\";\nimport type { InteractiveSessionChoice } from \"./modes/interactive.ts\";\nimport { type InteractiveModeEntryOptions, runInteractiveMode } from \"./modes/interactive-entry.ts\";\nimport { runProviderOnboarding, shouldStartProviderOnboarding } from \"./provider-onboarding.ts\";\nimport { pluginInventoryKey } from \"./runtime/plugin-inventory-service.ts\";\nimport { loadStartupConfiguration, resolveStartupRuntime } from \"./startup.ts\";\n\nexport interface InteractiveProfileOptions {\n\treadonly stderr: (text: string) => void;\n\treadonly allowedRoot?: string;\n\treadonly agentDir?: string;\n\treadonly isInteractiveTerminal: boolean;\n\treadonly promptProjectTrust?: (cwd: string) => Promise<boolean>;\n\treadonly onRuntimeEvent?: (event: RuntimeEvent) => void;\n\t/** Test-only terminal boundary; production uses the composition-owned mode entry. */\n\treadonly startInteractiveMode?: (options: InteractiveModeEntryOptions) => number;\n\t/** Test-only module boundary; production uses the namespace composition importer. */\n\treadonly importModule?: (name: string) => Promise<PluginModule>;\n}\n\nfunction errorMessage(cause: unknown): string {\n\treturn redactSensitiveText(cause instanceof Error ? cause.message : String(cause));\n}\n\nfunction isInteractiveRun(\n\tcommand: CliCommand,\n): command is Extract<CliCommand, { kind: \"run\" }> & { readonly mode: \"interactive\" } {\n\treturn command.kind === \"run\" && command.mode === \"interactive\";\n}\n\nasync function exists(path: string): Promise<boolean> {\n\ttry {\n\t\tawait access(path);\n\t\treturn true;\n\t} catch (cause) {\n\t\tif (cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\") return false;\n\t\tthrow cause;\n\t}\n}\n\nasync function hasTrustedProjectContent(cwd: string): Promise<boolean> {\n\tfor (const path of [\n\t\tjoin(cwd, \".di-code\", \"skills\"),\n\t\tjoin(cwd, \".agents\", \"skills\"),\n\t\tjoin(cwd, \".di-code\", \"mcp.local.json\"),\n\t\tjoin(cwd, \".mcp.json\"),\n\t]) {\n\t\tif (await exists(path)) return true;\n\t}\n\treturn false;\n}\n\nfunction sessionDirectory(agentDir: string, cwd: string): string {\n\treturn join(agentDir, \"sessions\", workspaceStorageKey(cwd));\n}\n\nfunction newSessionPath(directory: string): string {\n\treturn join(directory, `${new Date().toISOString().replaceAll(/[:.]/g, \"-\")}.jsonl`);\n}\n\nasync function openInteractiveSession(\n\tcommand: Extract<CliCommand, { kind: \"run\" }>,\n\tcwd: string,\n\tagentDir: string,\n): Promise<SessionManager> {\n\tconst directory = sessionDirectory(agentDir, cwd);\n\tif (command.sessionPath !== undefined) return await SessionManager.open(resolve(cwd, command.sessionPath));\n\tif (command.continueSession) {\n\t\ttry {\n\t\t\tconst entries = await readdir(directory, { withFileTypes: true });\n\t\t\tconst candidates = await Promise.all(\n\t\t\t\tentries\n\t\t\t\t\t.filter((entry) => entry.isFile() && extname(entry.name) === \".jsonl\")\n\t\t\t\t\t.map(async (entry) => ({\n\t\t\t\t\t\tpath: join(directory, entry.name),\n\t\t\t\t\t\tmodified: (await stat(join(directory, entry.name))).mtimeMs,\n\t\t\t\t\t})),\n\t\t\t);\n\t\t\tconst recent = candidates.sort((left, right) => right.modified - left.modified)[0];\n\t\t\tif (recent) return await SessionManager.open(recent.path);\n\t\t} catch (cause) {\n\t\t\tif (!(cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\")) throw cause;\n\t\t}\n\t}\n\treturn await SessionManager.create({ filePath: newSessionPath(directory), cwd, deferCreate: true });\n}\n\nfunction formatSessionLabel(manager: SessionManager): string {\n\tconst fileName = basename(manager.filePath, extname(manager.filePath));\n\tconst firstUserEntry = manager.entries.find((entry) => entry.type === \"message\" && entry.message.role === \"user\");\n\tif (firstUserEntry?.type !== \"message\" || firstUserEntry.message.role !== \"user\") return fileName;\n\tconst question = firstUserEntry.message.content\n\t\t.filter((content) => content.type === \"text\")\n\t\t.map((content) => content.text)\n\t\t.join(\" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n\treturn question.length > 72 ? `${question.slice(0, 69)}...` : question || fileName;\n}\n\nasync function interactiveSessionChoices(\n\tdirectory: string,\n\tcurrentFile: string,\n\topen: (filePath: string) => Promise<AgentSession>,\n): Promise<readonly InteractiveSessionChoice[]> {\n\tlet entries: readonly string[] = [];\n\ttry {\n\t\tentries = (await readdir(directory, { withFileTypes: true }))\n\t\t\t.filter((entry) => entry.isFile() && extname(entry.name) === \".jsonl\")\n\t\t\t.map((entry) => entry.name)\n\t\t\t.sort();\n\t} catch (cause) {\n\t\tif (!(cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\")) throw cause;\n\t}\n\treturn await Promise.all(\n\t\tentries\n\t\t\t.filter((name) => resolve(directory, name) !== resolve(currentFile))\n\t\t\t.map(async (name) => {\n\t\t\t\tconst filePath = join(directory, name);\n\t\t\t\tlet label = basename(name, extname(name));\n\t\t\t\ttry {\n\t\t\t\t\tlabel = formatSessionLabel(await SessionManager.open(filePath));\n\t\t\t\t} catch {\n\t\t\t\t\t// Retain corrupted files as choices so their detailed recovery diagnostic remains visible on open.\n\t\t\t\t}\n\t\t\t\treturn { id: basename(name, extname(name)), label, description: filePath, open: () => open(filePath) };\n\t\t\t}),\n\t);\n}\n\n/** Starts interactive TUI through the default composition without importing legacy plugin or extension hosts. */\nexport async function runInteractiveProfile(\n\targs: readonly string[],\n\toptions: InteractiveProfileOptions,\n): Promise<number> {\n\tconst parser = createCliParser();\n\tlet command: CliCommand;\n\ttry {\n\t\tcommand = parser.parse(args);\n\t} catch (cause) {\n\t\toptions.stderr(`${errorMessage(cause)}\\n`);\n\t\treturn 1;\n\t}\n\tif (!isInteractiveRun(command)) {\n\t\toptions.stderr(\"Interactive profile requires --interactive or --mode interactive.\\n\");\n\t\treturn 1;\n\t}\n\tif (!options.isInteractiveTerminal) {\n\t\toptions.stderr(\"Interactive mode requires an interactive TTY.\\n\");\n\t\treturn 1;\n\t}\n\n\tconst cwd = resolve(options.allowedRoot ?? process.cwd());\n\tconst agentDir = resolve(options.agentDir ?? join(homedir(), \".di-code\"));\n\tconst trustStore = new ProjectTrustStore(join(agentDir, \"trust.json\"));\n\ttry {\n\t\tif (command.projectTrust !== undefined) await trustStore.set(cwd, command.projectTrust);\n\t\tlet projectTrusted = (await trustStore.get(cwd)) === true;\n\t\tif (\n\t\t\t!projectTrusted &&\n\t\t\tcommand.projectTrust === undefined &&\n\t\t\toptions.promptProjectTrust &&\n\t\t\t(await hasTrustedProjectContent(cwd))\n\t\t) {\n\t\t\ttry {\n\t\t\t\tprojectTrusted = await options.promptProjectTrust(cwd);\n\t\t\t} catch {\n\t\t\t\tprojectTrusted = false;\n\t\t\t}\n\t\t\tawait trustStore.set(cwd, projectTrusted);\n\t\t}\n\n\t\tconst configuration = await loadStartupConfiguration(cwd, process.env, agentDir);\n\t\tconst runtime = shouldStartProviderOnboarding(command, true, configuration)\n\t\t\t? await runProviderOnboarding({ configuration, terminal: new ProcessTerminal(), agentDir })\n\t\t\t: resolveStartupRuntime(configuration.environment, configuration.providers, configuration.defaults);\n\t\tif (!runtime) return 0;\n\n\t\tconst context = createRootContext({\n\t\t\tid: \"interactive-profile\",\n\t\t\tmode: \"interactive\",\n\t\t\ttrustedProject: projectTrusted,\n\t\t});\n\t\tconst compositionEntries = await resolveCompositionEntries(command.profile ?? command.mode, {\n\t\t\tcwd,\n\t\t\tagentDir,\n\t\t\t...(command.compositionPath ? { compositionPath: command.compositionPath } : {}),\n\t\t\tincludeProjectComposition: projectTrusted && !command.noProjectPlugins,\n\t\t\tallowedRoot: cwd,\n\t\t});\n\t\tconst unsubscribe = context.events.subscribe((event) => options.onRuntimeEvent?.(event));\n\t\tconst loader = createCompositionLoader({\n\t\t\tcontext,\n\t\t\tentries: [...compositionEntries, ...(await resolveManagedCompositionEntries(agentDir))],\n\t\t\timportModule: options.importModule ?? importCompositionModule,\n\t\t\tprojectTrusted,\n\t\t});\n\t\tlet closed = false;\n\t\tlet closeMcp: (() => Promise<void>) | undefined;\n\t\tconst close = async (): Promise<void> => {\n\t\t\tif (closed) return;\n\t\t\tclosed = true;\n\t\t\ttry {\n\t\t\t\tawait closeMcp?.();\n\t\t\t} finally {\n\t\t\t\ttry {\n\t\t\t\t\tawait loader.dispose();\n\t\t\t\t} finally {\n\t\t\t\t\tawait context.dispose();\n\t\t\t\t\tunsubscribe();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\ttry {\n\t\t\tawait loader.load();\n\t\t\tcontext.require(pluginInventoryKey).set(loader.tree.snapshot());\n\t\t\tconst resources = await loadResources({\n\t\t\t\tcwd,\n\t\t\t\tagentDir,\n\t\t\t\tprojectTrusted,\n\t\t\t\tnoSkills: command.noSkills,\n\t\t\t\tnoContextFiles: command.noContextFiles,\n\t\t\t\tskillPaths: command.skillPaths,\n\t\t\t});\n\t\t\tfor (const diagnostic of resources.diagnostics) options.stderr(`${errorMessage(diagnostic.message)}\\n`);\n\t\t\tconst configurations = await context.require(mcpConfigServiceKey).load({ cwd, projectTrusted });\n\t\t\tconst mcp = await context.require(mcpClientServiceKey).connect(configurations);\n\t\t\tcloseMcp = async () => {\n\t\t\t\tawait mcp.manager.close();\n\t\t\t};\n\t\t\tconst externalTools = context\n\t\t\t\t.require(mcpToolServiceKey)\n\t\t\t\t.create(mcp.servers, [\"read\", \"write\", \"edit\", \"glob\", \"grep\", \"bash\", \"load_skill\"]);\n\t\t\tconst manager = await openInteractiveSession(command, cwd, agentDir);\n\t\t\tconst systemPrompt = buildSystemPrompt({ cwd, ...resources });\n\t\t\tconst createSession = async (sessionManager: SessionManager): Promise<AgentSession> => {\n\t\t\t\tconst session = await context.require(agentSessionKey).create({\n\t\t\t\t\tallowedRoot: cwd,\n\t\t\t\t\tprovider: runtime.provider,\n\t\t\t\t\tmodel: runtime.model,\n\t\t\t\t\tsystemPrompt,\n\t\t\t\t\tskills: resources.skills,\n\t\t\t\t\tsessionManager,\n\t\t\t\t\texternalTools,\n\t\t\t\t});\n\t\t\t\tif (!(session instanceof AgentSession))\n\t\t\t\t\tthrow new Error(\"SessionFactory returned an incompatible interactive session.\");\n\t\t\t\treturn session;\n\t\t\t};\n\t\t\tconst session = await createSession(manager);\n\t\t\tconst directory = sessionDirectory(agentDir, cwd);\n\t\t\tconst sessionChoices: readonly InteractiveSessionChoice[] = [\n\t\t\t\t{\n\t\t\t\t\tid: \"new-session\",\n\t\t\t\t\tlabel: translate(configuration.locale ?? DEFAULT_LOCALE, \"newSession\"),\n\t\t\t\t\tdescription: translate(configuration.locale ?? DEFAULT_LOCALE, \"newSessionDescription\"),\n\t\t\t\t\topen: async () =>\n\t\t\t\t\t\tawait createSession(\n\t\t\t\t\t\t\tawait SessionManager.create({ filePath: newSessionPath(directory), cwd, deferCreate: true }),\n\t\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t...(await interactiveSessionChoices(directory, manager.filePath, async (filePath) =>\n\t\t\t\t\tcreateSession(await SessionManager.open(filePath)),\n\t\t\t\t)),\n\t\t\t];\n\t\t\tlet mode: import(\"./modes/interactive.ts\").InteractiveMode | undefined;\n\t\t\tlet theme = \"dark\";\n\t\t\tconst interactiveContext: InteractiveContextService = {\n\t\t\t\tsessionChoices: () => sessionChoices,\n\t\t\t\tcancel: () => mode?.cancelActivePrompt(),\n\t\t\t\tretry: () => mode?.retryLastPrompt(),\n\t\t\t\ttheme: () => theme,\n\t\t\t\tsetTheme: (value) => {\n\t\t\t\t\ttheme = value;\n\t\t\t\t},\n\t\t\t\tkeybindings: () => context.get(keybindingRegistryKey)?.snapshot(),\n\t\t\t};\n\t\t\tconst code = await context.require(modeRegistryKey).execute(\n\t\t\t\t\"interactive\",\n\t\t\t\t{\n\t\t\t\t\trun: () =>\n\t\t\t\t\t\t(options.startInteractiveMode ?? runInteractiveMode)({\n\t\t\t\t\t\t\tsession,\n\t\t\t\t\t\t\tagentDir,\n\t\t\t\t\t\t\tlocale: configuration.locale ?? DEFAULT_LOCALE,\n\t\t\t\t\t\t\tcommandRegistry: context.require(commandRegistryKey),\n\t\t\t\t\t\t\tcontext: interactiveContext,\n\t\t\t\t\t\t\tinitialPrompt: command.prompt,\n\t\t\t\t\t\t\tonCreated: (created) => {\n\t\t\t\t\t\t\t\tmode = created;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tonExit: () => {\n\t\t\t\t\t\t\t\tvoid close();\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t\tcontext.signal,\n\t\t\t);\n\t\t\treturn code;\n\t\t} catch (cause) {\n\t\t\tawait close();\n\t\t\toptions.stderr(`${errorMessage(cause)}\\n`);\n\t\t\treturn 1;\n\t\t}\n\t} catch (cause) {\n\t\toptions.stderr(`${errorMessage(cause)}\\n`);\n\t\treturn 1;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginDefinition } from "@di-code/plugin-runtime";
|
|
2
|
+
/** Provides resource discovery and the default prompt as replaceable registry contributions. */
|
|
3
|
+
export declare const apiVersion: 1;
|
|
4
|
+
export declare const name = "interactive-resources";
|
|
5
|
+
export declare const version = "0.1.7";
|
|
6
|
+
export declare const apply: PluginDefinition["apply"];
|
|
7
|
+
//# sourceMappingURL=interactive-resources-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive-resources-entry.d.ts","sourceRoot":"","sources":["../src/interactive-resources-entry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAuBhE,gGAAgG;AAChG,eAAO,MAAM,UAAU,EAAG,CAAU,CAAC;AACrC,eAAO,MAAM,IAAI,0BAA0B,CAAC;AAC5C,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAyB3C,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { promptRegistryKey, resourceRegistryKey } from "@di-code/builtins";
|
|
2
|
+
import { loadResources } from "./core/resources/loader.js";
|
|
3
|
+
import { buildSystemPrompt } from "./core/system-prompt.js";
|
|
4
|
+
import { interactiveResourceServiceKey } from "./runtime/interactive-resource-service.js";
|
|
5
|
+
function isPromptInput(value) {
|
|
6
|
+
return (typeof value === "object" &&
|
|
7
|
+
value !== null &&
|
|
8
|
+
"cwd" in value &&
|
|
9
|
+
typeof value.cwd === "string" &&
|
|
10
|
+
"contextFiles" in value &&
|
|
11
|
+
Array.isArray(value.contextFiles) &&
|
|
12
|
+
"skills" in value &&
|
|
13
|
+
Array.isArray(value.skills));
|
|
14
|
+
}
|
|
15
|
+
/** Provides resource discovery and the default prompt as replaceable registry contributions. */
|
|
16
|
+
export const apiVersion = 1;
|
|
17
|
+
export const name = "interactive-resources";
|
|
18
|
+
export const version = "0.1.7";
|
|
19
|
+
export const apply = (context, _config, fiber) => {
|
|
20
|
+
const prompts = context.require(promptRegistryKey);
|
|
21
|
+
const resources = context.require(resourceRegistryKey);
|
|
22
|
+
fiber.addDisposer(prompts.register("interactive-default", (input) => {
|
|
23
|
+
if (!isPromptInput(input))
|
|
24
|
+
throw new TypeError("Interactive prompt input is invalid");
|
|
25
|
+
return buildSystemPrompt(input);
|
|
26
|
+
}));
|
|
27
|
+
const service = {
|
|
28
|
+
load: async (options) => {
|
|
29
|
+
const snapshot = await loadResources(options);
|
|
30
|
+
const sections = await Promise.all(prompts.snapshot().map(async (entry) => await entry.get({ cwd: options.cwd, ...snapshot })));
|
|
31
|
+
return {
|
|
32
|
+
resources: snapshot,
|
|
33
|
+
systemPrompt: sections
|
|
34
|
+
.filter((section) => typeof section === "string" && section.length > 0)
|
|
35
|
+
.join("\n\n"),
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
context.set(interactiveResourceServiceKey, service);
|
|
40
|
+
fiber.addDisposer(resources.register("interactive-resources", service));
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=interactive-resources-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive-resources-entry.js","sourceRoot":"","sources":["../src/interactive-resources-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,2CAA2C,CAAC;AAM1F,SAAS,aAAa,CAAC,KAAc;IACpC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,KAAK,IAAI,KAAK;QACd,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ;QAC7B,cAAc,IAAI,KAAK;QACvB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC;QACjC,QAAQ,IAAI,KAAK;QACjB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAC3B,CAAC;AACH,CAAC;AAED,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,CAAC;aACd,CAAC;QACH,CAAC;KACD,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC;IACpD,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC,CAAC;AACzE,CAAC,CAAC","sourcesContent":["import { promptRegistryKey, resourceRegistryKey } from \"@di-code/builtins\";\nimport type { PluginDefinition } from \"@di-code/plugin-runtime\";\nimport { loadResources } from \"./core/resources/loader.ts\";\nimport type { ResourceSnapshot } from \"./core/resources/types.ts\";\nimport { buildSystemPrompt } from \"./core/system-prompt.ts\";\nimport { interactiveResourceServiceKey } from \"./runtime/interactive-resource-service.ts\";\n\ninterface PromptInput extends ResourceSnapshot {\n\treadonly cwd: string;\n}\n\nfunction isPromptInput(value: unknown): value is PromptInput {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"cwd\" in value &&\n\t\ttypeof value.cwd === \"string\" &&\n\t\t\"contextFiles\" in value &&\n\t\tArray.isArray(value.contextFiles) &&\n\t\t\"skills\" in value &&\n\t\tArray.isArray(value.skills)\n\t);\n}\n\n/** Provides resource discovery and the default prompt as replaceable registry contributions. */\nexport const apiVersion = 1 as const;\nexport const name = \"interactive-resources\";\nexport const version = \"0.1.7\";\nexport const apply: PluginDefinition[\"apply\"] = (context, _config, fiber) => {\n\tconst prompts = context.require(promptRegistryKey);\n\tconst resources = context.require(resourceRegistryKey);\n\tfiber.addDisposer(\n\t\tprompts.register(\"interactive-default\", (input) => {\n\t\t\tif (!isPromptInput(input)) throw new TypeError(\"Interactive prompt input is invalid\");\n\t\t\treturn buildSystemPrompt(input);\n\t\t}),\n\t);\n\tconst service = {\n\t\tload: async (options: Parameters<typeof loadResources>[0]) => {\n\t\t\tconst snapshot = await loadResources(options);\n\t\t\tconst sections = await Promise.all(\n\t\t\t\tprompts.snapshot().map(async (entry) => await entry.get({ cwd: options.cwd, ...snapshot })),\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tresources: snapshot,\n\t\t\t\tsystemPrompt: sections\n\t\t\t\t\t.filter((section): section is string => typeof section === \"string\" && section.length > 0)\n\t\t\t\t\t.join(\"\\n\\n\"),\n\t\t\t};\n\t\t},\n\t};\n\tcontext.set(interactiveResourceServiceKey, service);\n\tfiber.addDisposer(resources.register(\"interactive-resources\", service));\n};\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Model, Provider } from "@di-code/ai";
|
|
2
|
+
import { type CliCommand } from "./cli.ts";
|
|
3
|
+
import { SessionManager } from "./core/session/session-manager.ts";
|
|
4
|
+
import { type Locale } from "./i18n.ts";
|
|
5
|
+
import type { PrintIo } from "./modes/print.ts";
|
|
6
|
+
import type { StartupConfiguration } from "./startup.ts";
|
|
7
|
+
export interface MainRuntime {
|
|
8
|
+
readonly provider: Provider;
|
|
9
|
+
readonly model: Model;
|
|
10
|
+
}
|
|
11
|
+
export interface MainOptions extends PrintIo {
|
|
12
|
+
readonly version: string;
|
|
13
|
+
readonly createRuntime: (command: Extract<CliCommand, {
|
|
14
|
+
kind: "run";
|
|
15
|
+
}>) => MainRuntime | undefined | Promise<MainRuntime | undefined>;
|
|
16
|
+
readonly allowedRoot?: string;
|
|
17
|
+
readonly agentDir?: string;
|
|
18
|
+
readonly startupConfiguration?: StartupConfiguration;
|
|
19
|
+
/** Language for built-in human-facing CLI and terminal text. */
|
|
20
|
+
readonly locale?: Locale;
|
|
21
|
+
readonly now?: () => number;
|
|
22
|
+
/** Whether stdin and stdout are interactive terminals. */
|
|
23
|
+
readonly isInteractiveTerminal?: boolean;
|
|
24
|
+
/** Ask whether project-local Skills, plugins, and extensions may be loaded. */
|
|
25
|
+
readonly promptProjectTrust?: (cwd: string) => Promise<boolean>;
|
|
26
|
+
}
|
|
27
|
+
/** Renders startup states in place so terminal history retains only their final outcome. */
|
|
28
|
+
export declare class StartupStatusRenderer {
|
|
29
|
+
private readonly lines;
|
|
30
|
+
private readonly indexes;
|
|
31
|
+
private readonly write;
|
|
32
|
+
private readonly replaceInPlace;
|
|
33
|
+
private readonly width;
|
|
34
|
+
constructor(write: (text: string) => void, replaceInPlace: boolean, width?: number);
|
|
35
|
+
update(key: string, text: string): void;
|
|
36
|
+
}
|
|
37
|
+
export declare function formatSessionLabel(manager: SessionManager, timeZone?: string): string;
|
|
38
|
+
export declare function runMain(args: readonly string[], options: MainOptions): Promise<number>;
|
|
39
|
+
//# sourceMappingURL=legacy-main.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-main.d.ts","sourceRoot":"","sources":["../src/legacy-main.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAInD,OAAO,EAAE,KAAK,UAAU,EAAiD,MAAM,UAAU,CAAC;AAG1F,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAKnE,OAAO,EAAkB,KAAK,MAAM,EAAa,MAAM,WAAW,CAAC;AAKnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAIhD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGzD,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,WAAY,SAAQ,OAAO;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,CACvB,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE;QAAE,IAAI,EAAE,KAAK,CAAA;KAAE,CAAC,KACzC,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAChE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,C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