@ycodium-ai/agent-dsh 0.2.5029 → 0.2.5100
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/dist/index.js +1002 -666
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -7371,17 +7371,62 @@ var require_dist = __commonJS({
|
|
|
7371
7371
|
import { definePlugin } from "@ycodium-ai/plugin-api";
|
|
7372
7372
|
|
|
7373
7373
|
// ../../packages/plugin-api/src/version.ts
|
|
7374
|
-
var PLUGIN_API_VERSION =
|
|
7374
|
+
var PLUGIN_API_VERSION = 148;
|
|
7375
7375
|
|
|
7376
7376
|
// src/index.ts
|
|
7377
|
-
import * as
|
|
7378
|
-
import * as
|
|
7377
|
+
import * as NodeOS8 from "node:os";
|
|
7378
|
+
import * as NodePath8 from "node:path";
|
|
7379
7379
|
import {
|
|
7380
7380
|
EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
|
|
7381
7381
|
executorHomeEffectiveValue,
|
|
7382
7382
|
readExecutorEffectiveRequest
|
|
7383
7383
|
} from "@ycodium-ai/plugin-api/executor";
|
|
7384
7384
|
|
|
7385
|
+
// ../../packages/ycodium-instance-config/src/homePath.ts
|
|
7386
|
+
import * as NodeOS from "node:os";
|
|
7387
|
+
import * as NodePath from "node:path";
|
|
7388
|
+
import { mergeLaunchEnv } from "@ycodium-ai/plugin-api/executor";
|
|
7389
|
+
function expandHomePath(value) {
|
|
7390
|
+
if (value === "~") return NodeOS.homedir();
|
|
7391
|
+
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
7392
|
+
return NodePath.join(NodeOS.homedir(), value.slice(2));
|
|
7393
|
+
}
|
|
7394
|
+
return value;
|
|
7395
|
+
}
|
|
7396
|
+
|
|
7397
|
+
// ../../packages/ycodium-instance-config/src/programHomeSchema.ts
|
|
7398
|
+
function programAndHomeConfigSchema(binaryPath) {
|
|
7399
|
+
const binaryForm = {
|
|
7400
|
+
titleKey: "form.binaryPath.title",
|
|
7401
|
+
descriptionKey: "form.binaryPath.description",
|
|
7402
|
+
placeholderKey: "form.binaryPath.placeholder",
|
|
7403
|
+
control: binaryPath.control
|
|
7404
|
+
};
|
|
7405
|
+
if (binaryPath.machineLocal === true) binaryForm["machineLocal"] = true;
|
|
7406
|
+
return {
|
|
7407
|
+
type: "object",
|
|
7408
|
+
"x-ycodium-form-order": ["binaryPath", "homePath"],
|
|
7409
|
+
properties: {
|
|
7410
|
+
binaryPath: { type: "string", "x-ycodium-form": binaryForm },
|
|
7411
|
+
homePath: {
|
|
7412
|
+
type: "string",
|
|
7413
|
+
"x-ycodium-form": {
|
|
7414
|
+
titleKey: "form.homePath.title",
|
|
7415
|
+
machineLocal: true,
|
|
7416
|
+
descriptionKey: "form.homePath.description",
|
|
7417
|
+
placeholderKey: "form.homePath.placeholder"
|
|
7418
|
+
}
|
|
7419
|
+
},
|
|
7420
|
+
enabled: { type: "boolean" },
|
|
7421
|
+
customModels: { type: "array" },
|
|
7422
|
+
driver: { type: "string" },
|
|
7423
|
+
config: { type: "object" },
|
|
7424
|
+
environment: { type: "array" }
|
|
7425
|
+
},
|
|
7426
|
+
additionalProperties: true
|
|
7427
|
+
};
|
|
7428
|
+
}
|
|
7429
|
+
|
|
7385
7430
|
// src/card.ts
|
|
7386
7431
|
var DSH_DRIVER_KIND = "dsh";
|
|
7387
7432
|
var DSH_CLIENT_INFO = { name: "ycodium-agent-dsh", version: "0.1.0" };
|
|
@@ -7447,38 +7492,7 @@ var DSH_CARD = {
|
|
|
7447
7492
|
// 凭据由 CLI 自己保管在它 home 里,宿主不读 token。
|
|
7448
7493
|
credentialSources: [],
|
|
7449
7494
|
diagnostics: [],
|
|
7450
|
-
|
|
7451
|
-
// 顺序看 x-ycodium-form-order;文案键在本插件 locales/<locale>.json 里解析,宿主不兜底。
|
|
7452
|
-
configSchema: {
|
|
7453
|
-
type: "object",
|
|
7454
|
-
"x-ycodium-form-order": ["binaryPath", "homePath"],
|
|
7455
|
-
properties: {
|
|
7456
|
-
binaryPath: {
|
|
7457
|
-
type: "string",
|
|
7458
|
-
"x-ycodium-form": {
|
|
7459
|
-
titleKey: "form.binaryPath.title",
|
|
7460
|
-
descriptionKey: "form.binaryPath.description",
|
|
7461
|
-
placeholderKey: "form.binaryPath.placeholder",
|
|
7462
|
-
control: "executable-path"
|
|
7463
|
-
}
|
|
7464
|
-
},
|
|
7465
|
-
homePath: {
|
|
7466
|
-
type: "string",
|
|
7467
|
-
"x-ycodium-form": {
|
|
7468
|
-
titleKey: "form.homePath.title",
|
|
7469
|
-
machineLocal: true,
|
|
7470
|
-
descriptionKey: "form.homePath.description",
|
|
7471
|
-
placeholderKey: "form.homePath.placeholder"
|
|
7472
|
-
}
|
|
7473
|
-
},
|
|
7474
|
-
enabled: { type: "boolean" },
|
|
7475
|
-
customModels: { type: "array" },
|
|
7476
|
-
driver: { type: "string" },
|
|
7477
|
-
config: { type: "object" },
|
|
7478
|
-
environment: { type: "array" }
|
|
7479
|
-
},
|
|
7480
|
-
additionalProperties: true
|
|
7481
|
-
},
|
|
7495
|
+
configSchema: programAndHomeConfigSchema({ control: "executable-path" }),
|
|
7482
7496
|
modelConnectivity: {
|
|
7483
7497
|
dialects: ["openai-chat-completions"],
|
|
7484
7498
|
acceptsExternalEndpoints: true,
|
|
@@ -7498,7 +7512,7 @@ var DSH_CARD = {
|
|
|
7498
7512
|
|
|
7499
7513
|
// src/dshInstance.ts
|
|
7500
7514
|
import * as NodeCrypto4 from "node:crypto";
|
|
7501
|
-
import { modelSelectionStringOption, raceAbort as raceAbort2 } from "@ycodium-ai/plugin-api/executor";
|
|
7515
|
+
import { modelSelectionStringOption as modelSelectionStringOption3, raceAbort as raceAbort2 } from "@ycodium-ai/plugin-api/executor";
|
|
7502
7516
|
import { nodeStreamsFromHandle as nodeStreamsFromHandle2 } from "@ycodium-ai/plugin-api/process-stdin";
|
|
7503
7517
|
|
|
7504
7518
|
// ../../packages/ycodium-acp-executor/src/executor.ts
|
|
@@ -7561,6 +7575,24 @@ function approvalOutcomeForDecision(decision, optionId) {
|
|
|
7561
7575
|
return decision !== "cancel" && optionId !== void 0 ? { outcome: "selected", optionId } : { outcome: "cancelled" };
|
|
7562
7576
|
}
|
|
7563
7577
|
|
|
7578
|
+
// ../../packages/ycodium-executor-common/src/stderrTail.ts
|
|
7579
|
+
var REDACTION_MARKERS = ["[redacted]", "[pairing-url]"];
|
|
7580
|
+
function lastStderrTail(text, maxChars) {
|
|
7581
|
+
if (text.length <= maxChars) return text;
|
|
7582
|
+
let start = text.length - maxChars;
|
|
7583
|
+
if (text[start - 1] !== "\n") {
|
|
7584
|
+
const lineEnd = text.indexOf("\n", start);
|
|
7585
|
+
if (lineEnd !== -1 && lineEnd < text.length - 1) return text.slice(lineEnd + 1);
|
|
7586
|
+
const code = text.charCodeAt(start);
|
|
7587
|
+
if (code >= 56320 && code <= 57343) start += 1;
|
|
7588
|
+
for (const marker of REDACTION_MARKERS) {
|
|
7589
|
+
const at = text.lastIndexOf(marker, start);
|
|
7590
|
+
if (at !== -1 && at < start && start < at + marker.length) start = at + marker.length;
|
|
7591
|
+
}
|
|
7592
|
+
}
|
|
7593
|
+
return text.slice(start);
|
|
7594
|
+
}
|
|
7595
|
+
|
|
7564
7596
|
// ../../packages/ycodium-acp-executor/src/errors.ts
|
|
7565
7597
|
var AcpExecutorError = class extends Error {
|
|
7566
7598
|
code;
|
|
@@ -7665,30 +7697,14 @@ var AcpAgentExitedError = class extends AcpConnectionClosedError {
|
|
|
7665
7697
|
this.exitCode = exitCode;
|
|
7666
7698
|
}
|
|
7667
7699
|
};
|
|
7668
|
-
var REDACTION_MARKERS = ["[redacted]", "[pairing-url]"];
|
|
7669
|
-
var lastLines = (text, maxChars) => {
|
|
7670
|
-
if (text.length <= maxChars) return text;
|
|
7671
|
-
let start = text.length - maxChars;
|
|
7672
|
-
if (text[start - 1] !== "\n") {
|
|
7673
|
-
const lineEnd = text.indexOf("\n", start);
|
|
7674
|
-
if (lineEnd !== -1 && lineEnd < text.length - 1) return text.slice(lineEnd + 1);
|
|
7675
|
-
const code = text.charCodeAt(start);
|
|
7676
|
-
if (code >= 56320 && code <= 57343) start += 1;
|
|
7677
|
-
for (const marker of REDACTION_MARKERS) {
|
|
7678
|
-
const at = text.lastIndexOf(marker, start);
|
|
7679
|
-
if (at !== -1 && at < start && start < at + marker.length) start = at + marker.length;
|
|
7680
|
-
}
|
|
7681
|
-
}
|
|
7682
|
-
return text.slice(start);
|
|
7683
|
-
};
|
|
7684
7700
|
var settledExitCode = async (exited) => {
|
|
7685
7701
|
if (exited === void 0) return void 0;
|
|
7686
7702
|
let timer;
|
|
7687
7703
|
try {
|
|
7688
7704
|
return await Promise.race([
|
|
7689
7705
|
exited.catch(() => void 0),
|
|
7690
|
-
new Promise((
|
|
7691
|
-
timer = setTimeout(() =>
|
|
7706
|
+
new Promise((resolve5) => {
|
|
7707
|
+
timer = setTimeout(() => resolve5(void 0), AGENT_EXIT_SETTLE_MS);
|
|
7692
7708
|
})
|
|
7693
7709
|
]);
|
|
7694
7710
|
} finally {
|
|
@@ -7701,7 +7717,7 @@ async function describeAgentExit(input2) {
|
|
|
7701
7717
|
input2.stderrTail === void 0 ? "" : Promise.resolve().then(input2.stderrTail).catch(() => "")
|
|
7702
7718
|
]);
|
|
7703
7719
|
const head = exitCode === void 0 ? "The agent closed its connection." : exitCode === null ? "The agent process exited without an exit code." : `The agent process exited with code ${exitCode}.`;
|
|
7704
|
-
const excerpt =
|
|
7720
|
+
const excerpt = lastStderrTail(tail.trim(), AGENT_EXIT_STDERR_MAX_CHARS);
|
|
7705
7721
|
return new AcpAgentExitedError(
|
|
7706
7722
|
excerpt.length === 0 ? head : `${head}
|
|
7707
7723
|
Agent stderr (last lines):
|
|
@@ -7766,8 +7782,8 @@ var UnboundedEventStream = class {
|
|
|
7766
7782
|
iterators.subscribers.delete(subscriber);
|
|
7767
7783
|
return { value: void 0, done: true };
|
|
7768
7784
|
}
|
|
7769
|
-
await new Promise((
|
|
7770
|
-
subscriber.wake =
|
|
7785
|
+
await new Promise((resolve5) => {
|
|
7786
|
+
subscriber.wake = resolve5;
|
|
7771
7787
|
});
|
|
7772
7788
|
}
|
|
7773
7789
|
},
|
|
@@ -7910,9 +7926,17 @@ var selectPromptTurnId = (input2, activeTurnId, freshTurnId) => {
|
|
|
7910
7926
|
return target;
|
|
7911
7927
|
};
|
|
7912
7928
|
|
|
7913
|
-
// ../../packages/ycodium-
|
|
7929
|
+
// ../../packages/ycodium-executor-common/src/toolPresentation.ts
|
|
7930
|
+
function isRecord3(value) {
|
|
7931
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7932
|
+
}
|
|
7933
|
+
function asTrimmedString2(value) {
|
|
7934
|
+
if (typeof value !== "string") return void 0;
|
|
7935
|
+
const trimmed = value.trim();
|
|
7936
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
7937
|
+
}
|
|
7914
7938
|
function normalizeCommandValue(value) {
|
|
7915
|
-
const direct =
|
|
7939
|
+
const direct = asTrimmedString2(value);
|
|
7916
7940
|
if (direct) {
|
|
7917
7941
|
return direct;
|
|
7918
7942
|
}
|
|
@@ -7921,7 +7945,7 @@ function normalizeCommandValue(value) {
|
|
|
7921
7945
|
}
|
|
7922
7946
|
const parts = [];
|
|
7923
7947
|
for (const entry of value) {
|
|
7924
|
-
const part =
|
|
7948
|
+
const part = asTrimmedString2(entry);
|
|
7925
7949
|
if (part !== void 0) {
|
|
7926
7950
|
parts.push(part);
|
|
7927
7951
|
}
|
|
@@ -7945,11 +7969,11 @@ function extractCommandFromTitle(title) {
|
|
|
7945
7969
|
return backtickMatch?.[1]?.trim() || void 0;
|
|
7946
7970
|
}
|
|
7947
7971
|
function extractToolCommand(data, title) {
|
|
7948
|
-
const item =
|
|
7949
|
-
const itemInput = item &&
|
|
7950
|
-
const itemResult = item &&
|
|
7951
|
-
const rawInput =
|
|
7952
|
-
const dataInput =
|
|
7972
|
+
const item = isRecord3(data?.["item"]) ? data["item"] : void 0;
|
|
7973
|
+
const itemInput = item && isRecord3(item["input"]) ? item["input"] : void 0;
|
|
7974
|
+
const itemResult = item && isRecord3(item["result"]) ? item["result"] : void 0;
|
|
7975
|
+
const rawInput = isRecord3(data?.["rawInput"]) ? data["rawInput"] : void 0;
|
|
7976
|
+
const dataInput = isRecord3(data?.["input"]) ? data["input"] : void 0;
|
|
7953
7977
|
const candidates = [
|
|
7954
7978
|
normalizeCommandValue(item?.["command"]),
|
|
7955
7979
|
normalizeCommandValue(itemInput?.["command"]),
|
|
@@ -7962,7 +7986,7 @@ function extractToolCommand(data, title) {
|
|
|
7962
7986
|
if (direct) {
|
|
7963
7987
|
return direct;
|
|
7964
7988
|
}
|
|
7965
|
-
const executable =
|
|
7989
|
+
const executable = asTrimmedString2(rawInput?.["executable"]);
|
|
7966
7990
|
const args = normalizeCommandValue(rawInput?.["args"]);
|
|
7967
7991
|
if (executable && args) {
|
|
7968
7992
|
return `${executable} ${args}`;
|
|
@@ -7994,11 +8018,11 @@ function collectPaths(value, paths, seen, depth) {
|
|
|
7994
8018
|
}
|
|
7995
8019
|
return;
|
|
7996
8020
|
}
|
|
7997
|
-
if (!
|
|
8021
|
+
if (!isRecord3(value)) {
|
|
7998
8022
|
return;
|
|
7999
8023
|
}
|
|
8000
8024
|
for (const key of ["path", "filePath", "relativePath", "filename", "newPath", "oldPath"]) {
|
|
8001
|
-
const candidate = maybePathLike(
|
|
8025
|
+
const candidate = maybePathLike(asTrimmedString2(value[key]));
|
|
8002
8026
|
if (!candidate || seen.has(candidate)) {
|
|
8003
8027
|
continue;
|
|
8004
8028
|
}
|
|
@@ -8024,7 +8048,7 @@ function extractPrimaryPath(data) {
|
|
|
8024
8048
|
return paths[0];
|
|
8025
8049
|
}
|
|
8026
8050
|
function normalizeEquivalentValue(value) {
|
|
8027
|
-
const trimmed =
|
|
8051
|
+
const trimmed = asTrimmedString2(value);
|
|
8028
8052
|
if (!trimmed) {
|
|
8029
8053
|
return void 0;
|
|
8030
8054
|
}
|
|
@@ -8037,8 +8061,8 @@ function isEquivalent(left, right) {
|
|
|
8037
8061
|
}
|
|
8038
8062
|
function classifyToolAction(input2) {
|
|
8039
8063
|
const itemType = input2.itemType ?? void 0;
|
|
8040
|
-
const kind =
|
|
8041
|
-
const title =
|
|
8064
|
+
const kind = asTrimmedString2(input2.data?.["kind"])?.toLowerCase();
|
|
8065
|
+
const title = asTrimmedString2(input2.title)?.toLowerCase();
|
|
8042
8066
|
if (itemType === "command_execution" || kind === "execute" || title === "terminal") {
|
|
8043
8067
|
return "command";
|
|
8044
8068
|
}
|
|
@@ -8053,26 +8077,11 @@ function classifyToolAction(input2) {
|
|
|
8053
8077
|
}
|
|
8054
8078
|
return "other";
|
|
8055
8079
|
}
|
|
8056
|
-
function canonicalItemTypeFromAcpToolKind(kind) {
|
|
8057
|
-
switch (kind) {
|
|
8058
|
-
case "execute":
|
|
8059
|
-
return "command_execution";
|
|
8060
|
-
case "edit":
|
|
8061
|
-
case "delete":
|
|
8062
|
-
case "move":
|
|
8063
|
-
return "file_change";
|
|
8064
|
-
case "search":
|
|
8065
|
-
case "fetch":
|
|
8066
|
-
return "web_search";
|
|
8067
|
-
default:
|
|
8068
|
-
return "dynamic_tool_call";
|
|
8069
|
-
}
|
|
8070
|
-
}
|
|
8071
8080
|
function deriveToolActivityPresentation(input2) {
|
|
8072
|
-
const title =
|
|
8073
|
-
const detail = stripTrailingExitCode(
|
|
8074
|
-
const fallbackSummary =
|
|
8075
|
-
const data =
|
|
8081
|
+
const title = asTrimmedString2(input2.title);
|
|
8082
|
+
const detail = stripTrailingExitCode(asTrimmedString2(input2.detail));
|
|
8083
|
+
const fallbackSummary = asTrimmedString2(input2.fallbackSummary) ?? "Tool";
|
|
8084
|
+
const data = isRecord3(input2.data) ? input2.data : void 0;
|
|
8076
8085
|
const command = extractToolCommand(data, title);
|
|
8077
8086
|
const primaryPath = extractPrimaryPath(data);
|
|
8078
8087
|
const action = classifyToolAction({
|
|
@@ -8104,8 +8113,8 @@ function deriveToolActivityPresentation(input2) {
|
|
|
8104
8113
|
};
|
|
8105
8114
|
}
|
|
8106
8115
|
if (action === "search") {
|
|
8107
|
-
const rawInput =
|
|
8108
|
-
const query =
|
|
8116
|
+
const rawInput = isRecord3(data?.["rawInput"]) ? data["rawInput"] : void 0;
|
|
8117
|
+
const query = asTrimmedString2(rawInput?.["query"]) ?? asTrimmedString2(rawInput?.["pattern"]) ?? asTrimmedString2(rawInput?.["searchTerm"]);
|
|
8109
8118
|
return {
|
|
8110
8119
|
summary: "Searched files",
|
|
8111
8120
|
...query ? { detail: query } : {}
|
|
@@ -8122,6 +8131,23 @@ function deriveToolActivityPresentation(input2) {
|
|
|
8122
8131
|
};
|
|
8123
8132
|
}
|
|
8124
8133
|
|
|
8134
|
+
// ../../packages/ycodium-acp-executor/src/tool-presentation.ts
|
|
8135
|
+
function canonicalItemTypeFromAcpToolKind(kind) {
|
|
8136
|
+
switch (kind) {
|
|
8137
|
+
case "execute":
|
|
8138
|
+
return "command_execution";
|
|
8139
|
+
case "edit":
|
|
8140
|
+
case "delete":
|
|
8141
|
+
case "move":
|
|
8142
|
+
return "file_change";
|
|
8143
|
+
case "search":
|
|
8144
|
+
case "fetch":
|
|
8145
|
+
return "web_search";
|
|
8146
|
+
default:
|
|
8147
|
+
return "dynamic_tool_call";
|
|
8148
|
+
}
|
|
8149
|
+
}
|
|
8150
|
+
|
|
8125
8151
|
// ../../packages/ycodium-acp-executor/src/tool-call-state.ts
|
|
8126
8152
|
function normalizeToolCallStatus(raw, fallback) {
|
|
8127
8153
|
switch (raw) {
|
|
@@ -8350,6 +8376,30 @@ function decideToolCallUpdateEmission(input2) {
|
|
|
8350
8376
|
return { emit: false, skippedSinceEmit: skippedSinceEmit + 1 };
|
|
8351
8377
|
}
|
|
8352
8378
|
|
|
8379
|
+
// ../../packages/ycodium-executor-common/src/catalogModel.ts
|
|
8380
|
+
function catalogModelLastSegment(value) {
|
|
8381
|
+
if (value.startsWith("[")) {
|
|
8382
|
+
let parsed;
|
|
8383
|
+
try {
|
|
8384
|
+
parsed = JSON.parse(value);
|
|
8385
|
+
} catch {
|
|
8386
|
+
return void 0;
|
|
8387
|
+
}
|
|
8388
|
+
if (!Array.isArray(parsed) || parsed.length < 2) return void 0;
|
|
8389
|
+
const last = parsed[parsed.length - 1];
|
|
8390
|
+
return typeof last === "string" ? last : void 0;
|
|
8391
|
+
}
|
|
8392
|
+
const separator = value.indexOf("/");
|
|
8393
|
+
return separator > 0 && separator < value.length - 1 ? value.slice(separator + 1) : void 0;
|
|
8394
|
+
}
|
|
8395
|
+
function matchCatalogModel(requested, catalog) {
|
|
8396
|
+
const wanted = requested?.trim();
|
|
8397
|
+
if (!wanted) return void 0;
|
|
8398
|
+
if (catalog.includes(wanted)) return wanted;
|
|
8399
|
+
const byLastSegment = catalog.filter((value) => catalogModelLastSegment(value) === wanted);
|
|
8400
|
+
return byLastSegment.length === 1 ? byLastSegment[0] : void 0;
|
|
8401
|
+
}
|
|
8402
|
+
|
|
8353
8403
|
// ../../packages/ycodium-acp-executor/src/runtime-model.ts
|
|
8354
8404
|
function normalizePlanStepStatus(raw) {
|
|
8355
8405
|
switch (raw) {
|
|
@@ -8391,30 +8441,6 @@ function collectSessionModelIds(models) {
|
|
|
8391
8441
|
(model) => isRecord2(model) && typeof model["modelId"] === "string" ? [model["modelId"]] : []
|
|
8392
8442
|
);
|
|
8393
8443
|
}
|
|
8394
|
-
function catalogModelLastSegment(value) {
|
|
8395
|
-
if (value.startsWith("[")) {
|
|
8396
|
-
let parsed;
|
|
8397
|
-
try {
|
|
8398
|
-
parsed = JSON.parse(value);
|
|
8399
|
-
} catch {
|
|
8400
|
-
return void 0;
|
|
8401
|
-
}
|
|
8402
|
-
if (!Array.isArray(parsed) || parsed.length < 2) return void 0;
|
|
8403
|
-
const last = parsed[parsed.length - 1];
|
|
8404
|
-
return typeof last === "string" ? last : void 0;
|
|
8405
|
-
}
|
|
8406
|
-
const separator = value.indexOf("/");
|
|
8407
|
-
return separator > 0 && separator < value.length - 1 ? value.slice(separator + 1) : void 0;
|
|
8408
|
-
}
|
|
8409
|
-
function matchAdvertisedModelValue(requestedModelId, advertisedValues) {
|
|
8410
|
-
const wanted = requestedModelId.trim();
|
|
8411
|
-
if (!wanted) return void 0;
|
|
8412
|
-
if (advertisedValues.includes(wanted)) return wanted;
|
|
8413
|
-
const byLastSegment = advertisedValues.filter(
|
|
8414
|
-
(value) => catalogModelLastSegment(value) === wanted
|
|
8415
|
-
);
|
|
8416
|
-
return byLastSegment.length === 1 ? byLastSegment[0] : void 0;
|
|
8417
|
-
}
|
|
8418
8444
|
function parseSessionModeState(sessionResponse) {
|
|
8419
8445
|
const modes = sessionResponse.modes;
|
|
8420
8446
|
if (!modes) return void 0;
|
|
@@ -13995,7 +14021,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
13995
14021
|
var NONE = 0;
|
|
13996
14022
|
var ASSUMED = 1;
|
|
13997
14023
|
var PROVEN = 2;
|
|
13998
|
-
function isRecursive(inst, stack,
|
|
14024
|
+
function isRecursive(inst, stack, resolve5) {
|
|
13999
14025
|
const cached2 = recursive.get(inst);
|
|
14000
14026
|
if (cached2 !== void 0)
|
|
14001
14027
|
return cached2 ? PROVEN : NONE;
|
|
@@ -14005,7 +14031,7 @@ function isRecursive(inst, stack, resolve4) {
|
|
|
14005
14031
|
let result = NONE;
|
|
14006
14032
|
const check2 = (child) => {
|
|
14007
14033
|
if (result !== PROVEN && child?._zod) {
|
|
14008
|
-
const answer = isRecursive(child, stack,
|
|
14034
|
+
const answer = isRecursive(child, stack, resolve5);
|
|
14009
14035
|
if (answer > result)
|
|
14010
14036
|
result = answer;
|
|
14011
14037
|
}
|
|
@@ -14016,7 +14042,7 @@ function isRecursive(inst, stack, resolve4) {
|
|
|
14016
14042
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
14017
14043
|
if (spread && !desc.enumerable)
|
|
14018
14044
|
continue;
|
|
14019
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
14045
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve5) : NONE;
|
|
14020
14046
|
if (child > answer)
|
|
14021
14047
|
answer = child;
|
|
14022
14048
|
}
|
|
@@ -14080,7 +14106,7 @@ function isRecursive(inst, stack, resolve4) {
|
|
|
14080
14106
|
break;
|
|
14081
14107
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
14082
14108
|
case "lazy": {
|
|
14083
|
-
const inner = def._cachedInner ?? (
|
|
14109
|
+
const inner = def._cachedInner ?? (resolve5 ? inst._zod.innerType : void 0);
|
|
14084
14110
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
14085
14111
|
break;
|
|
14086
14112
|
}
|
|
@@ -30330,17 +30356,17 @@ function isResponseMessage(value) {
|
|
|
30330
30356
|
function isNotificationMessage(value) {
|
|
30331
30357
|
return isJsonRpcEnvelope(value) && !("id" in value) && typeof value["method"] === "string";
|
|
30332
30358
|
}
|
|
30333
|
-
function
|
|
30359
|
+
function isRecord4(value) {
|
|
30334
30360
|
return typeof value === "object" && value !== null;
|
|
30335
30361
|
}
|
|
30336
30362
|
function isJsonRpcEnvelope(value) {
|
|
30337
|
-
return
|
|
30363
|
+
return isRecord4(value) && value["jsonrpc"] === "2.0";
|
|
30338
30364
|
}
|
|
30339
30365
|
function isJsonRpcId(value) {
|
|
30340
30366
|
return value === null || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
30341
30367
|
}
|
|
30342
30368
|
function isResponseShapedMessage(value) {
|
|
30343
|
-
return
|
|
30369
|
+
return isRecord4(value) && !("method" in value) && ("id" in value || "result" in value || "error" in value);
|
|
30344
30370
|
}
|
|
30345
30371
|
function isResponseBatch(batch) {
|
|
30346
30372
|
let hasValidCall = false;
|
|
@@ -30350,7 +30376,7 @@ function isResponseBatch(batch) {
|
|
|
30350
30376
|
for (const entry of batch) {
|
|
30351
30377
|
hasValidCall ||= isRequestMessage(entry) || isNotificationMessage(entry);
|
|
30352
30378
|
hasValidResponse ||= isResponseMessage(entry);
|
|
30353
|
-
if (!
|
|
30379
|
+
if (!isRecord4(entry)) {
|
|
30354
30380
|
continue;
|
|
30355
30381
|
}
|
|
30356
30382
|
hasCallShape ||= "method" in entry;
|
|
@@ -30365,13 +30391,13 @@ function isResponseBatch(batch) {
|
|
|
30365
30391
|
return hasResponseShape && !hasCallShape;
|
|
30366
30392
|
}
|
|
30367
30393
|
function cancelRequestId(params) {
|
|
30368
|
-
if (!
|
|
30394
|
+
if (!isRecord4(params) || !isJsonRpcId(params["requestId"])) {
|
|
30369
30395
|
return void 0;
|
|
30370
30396
|
}
|
|
30371
30397
|
return params["requestId"];
|
|
30372
30398
|
}
|
|
30373
30399
|
function isErrorResponse(value) {
|
|
30374
|
-
return
|
|
30400
|
+
return isRecord4(value) && typeof value["code"] === "number" && Number.isInteger(value["code"]) && typeof value["message"] === "string";
|
|
30375
30401
|
}
|
|
30376
30402
|
var Handled = {
|
|
30377
30403
|
/**
|
|
@@ -30744,11 +30770,11 @@ var Connection = class {
|
|
|
30744
30770
|
const id = this.nextRequestId++;
|
|
30745
30771
|
let cancel = () => {
|
|
30746
30772
|
};
|
|
30747
|
-
const response = new Promise((
|
|
30773
|
+
const response = new Promise((resolve5, reject) => {
|
|
30748
30774
|
const pendingResponse = {
|
|
30749
30775
|
resolve: (value) => {
|
|
30750
30776
|
try {
|
|
30751
|
-
|
|
30777
|
+
resolve5(mapResponse ? mapResponse(value) : value);
|
|
30752
30778
|
} catch (error62) {
|
|
30753
30779
|
reject(error62);
|
|
30754
30780
|
}
|
|
@@ -30805,8 +30831,8 @@ var Connection = class {
|
|
|
30805
30831
|
this.stream = stream;
|
|
30806
30832
|
this.staticHandlers = handlers;
|
|
30807
30833
|
this.allowBatches = options?.allowBatches ?? true;
|
|
30808
|
-
this.closedPromise = new Promise((
|
|
30809
|
-
this.abortController.signal.addEventListener("abort", () =>
|
|
30834
|
+
this.closedPromise = new Promise((resolve5) => {
|
|
30835
|
+
this.abortController.signal.addEventListener("abort", () => resolve5());
|
|
30810
30836
|
});
|
|
30811
30837
|
void this.receive();
|
|
30812
30838
|
}
|
|
@@ -30916,7 +30942,7 @@ var Connection = class {
|
|
|
30916
30942
|
if (this.abortController.signal.aborted) {
|
|
30917
30943
|
return Promise.resolve();
|
|
30918
30944
|
}
|
|
30919
|
-
if (!
|
|
30945
|
+
if (!isRecord4(message)) {
|
|
30920
30946
|
console.error("Invalid message", { message });
|
|
30921
30947
|
return Promise.resolve();
|
|
30922
30948
|
}
|
|
@@ -31319,7 +31345,7 @@ function ndJsonStream(output2, input2) {
|
|
|
31319
31345
|
await writeJson(protocolErrorResponse(RequestError.parseError()));
|
|
31320
31346
|
return;
|
|
31321
31347
|
}
|
|
31322
|
-
if (
|
|
31348
|
+
if (isRecord4(message) || Array.isArray(message)) {
|
|
31323
31349
|
controller.enqueue(message);
|
|
31324
31350
|
} else {
|
|
31325
31351
|
await writeJson(protocolErrorResponse(RequestError.invalidRequest(message)));
|
|
@@ -31700,8 +31726,8 @@ var AsyncQueue = class {
|
|
|
31700
31726
|
if (this.failed) {
|
|
31701
31727
|
return Promise.reject(this.failure);
|
|
31702
31728
|
}
|
|
31703
|
-
return new Promise((
|
|
31704
|
-
this.waiters.push({ resolve:
|
|
31729
|
+
return new Promise((resolve5, reject) => {
|
|
31730
|
+
this.waiters.push({ resolve: resolve5, reject });
|
|
31705
31731
|
});
|
|
31706
31732
|
}
|
|
31707
31733
|
};
|
|
@@ -32306,14 +32332,14 @@ var legacyClientNotificationMethods = /* @__PURE__ */ new Set([
|
|
|
32306
32332
|
import * as NodeStream from "node:stream";
|
|
32307
32333
|
|
|
32308
32334
|
// ../../packages/ycodium-acp-executor/src/jsonrpc.ts
|
|
32309
|
-
function
|
|
32335
|
+
function isRecord5(value) {
|
|
32310
32336
|
return typeof value === "object" && value !== null;
|
|
32311
32337
|
}
|
|
32312
32338
|
function isJsonRpcId2(value) {
|
|
32313
32339
|
return typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
32314
32340
|
}
|
|
32315
32341
|
function isJsonRpcEnvelope2(value) {
|
|
32316
|
-
return
|
|
32342
|
+
return isRecord5(value) && value["jsonrpc"] === "2.0";
|
|
32317
32343
|
}
|
|
32318
32344
|
function isRequestMessage2(value) {
|
|
32319
32345
|
return isJsonRpcEnvelope2(value) && "id" in value && typeof value["method"] === "string" && isJsonRpcId2(value["id"]);
|
|
@@ -32333,7 +32359,7 @@ function isNotificationMessage2(value) {
|
|
|
32333
32359
|
return isJsonRpcEnvelope2(value) && !("id" in value) && typeof value["method"] === "string";
|
|
32334
32360
|
}
|
|
32335
32361
|
function readJsonRpcError(value) {
|
|
32336
|
-
if (!
|
|
32362
|
+
if (!isRecord5(value) || typeof value["code"] !== "number" || typeof value["message"] !== "string") {
|
|
32337
32363
|
return void 0;
|
|
32338
32364
|
}
|
|
32339
32365
|
return {
|
|
@@ -32406,11 +32432,11 @@ var KNOWN_SESSION_UPDATES = /* @__PURE__ */ new Set([
|
|
|
32406
32432
|
"compaction_summary_chunk"
|
|
32407
32433
|
]);
|
|
32408
32434
|
function isSessionUpdateEnvelope(payload) {
|
|
32409
|
-
if (!
|
|
32435
|
+
if (!isRecord5(payload) || typeof payload["sessionId"] !== "string") {
|
|
32410
32436
|
return false;
|
|
32411
32437
|
}
|
|
32412
32438
|
const update = payload["update"];
|
|
32413
|
-
return
|
|
32439
|
+
return isRecord5(update) && typeof update["sessionUpdate"] === "string";
|
|
32414
32440
|
}
|
|
32415
32441
|
function hasKnownVariantShape(update) {
|
|
32416
32442
|
const kind = update["sessionUpdate"];
|
|
@@ -32418,7 +32444,7 @@ function hasKnownVariantShape(update) {
|
|
|
32418
32444
|
return false;
|
|
32419
32445
|
}
|
|
32420
32446
|
if (kind === "user_message_chunk" || kind === "agent_message_chunk" || kind === "agent_thought_chunk") {
|
|
32421
|
-
return
|
|
32447
|
+
return isRecord5(update["content"]);
|
|
32422
32448
|
}
|
|
32423
32449
|
return true;
|
|
32424
32450
|
}
|
|
@@ -32748,12 +32774,12 @@ function createAcpConnection(options) {
|
|
|
32748
32774
|
failIfClosed();
|
|
32749
32775
|
const id = nextRequestId;
|
|
32750
32776
|
nextRequestId += 1;
|
|
32751
|
-
const { promise: promise2, resolve:
|
|
32777
|
+
const { promise: promise2, resolve: resolve5, reject } = Promise.withResolvers();
|
|
32752
32778
|
pending.set(String(id), {
|
|
32753
32779
|
method,
|
|
32754
32780
|
...promptId === void 0 ? {} : { promptId },
|
|
32755
32781
|
...onArrival === void 0 ? {} : { onArrival },
|
|
32756
|
-
resolve:
|
|
32782
|
+
resolve: resolve5,
|
|
32757
32783
|
reject
|
|
32758
32784
|
});
|
|
32759
32785
|
const message = params === void 0 ? { jsonrpc: "2.0", id, method } : { jsonrpc: "2.0", id, method, params };
|
|
@@ -32782,8 +32808,8 @@ function createAcpConnection(options) {
|
|
|
32782
32808
|
if (inboundBatches === 0) {
|
|
32783
32809
|
return;
|
|
32784
32810
|
}
|
|
32785
|
-
await new Promise((
|
|
32786
|
-
idleWaiters.push(
|
|
32811
|
+
await new Promise((resolve5) => {
|
|
32812
|
+
idleWaiters.push(resolve5);
|
|
32787
32813
|
if (inboundBatches === 0) {
|
|
32788
32814
|
releaseIdleWaiters();
|
|
32789
32815
|
}
|
|
@@ -32869,8 +32895,8 @@ var Mutex = class {
|
|
|
32869
32895
|
this.locked = true;
|
|
32870
32896
|
return Promise.resolve();
|
|
32871
32897
|
}
|
|
32872
|
-
return new Promise((
|
|
32873
|
-
this.waiters.push(
|
|
32898
|
+
return new Promise((resolve5) => {
|
|
32899
|
+
this.waiters.push(resolve5);
|
|
32874
32900
|
});
|
|
32875
32901
|
}
|
|
32876
32902
|
tryAcquire() {
|
|
@@ -33070,9 +33096,9 @@ function createExecutorLifecycle({
|
|
|
33070
33096
|
let timer;
|
|
33071
33097
|
await Promise.race([
|
|
33072
33098
|
connection.closed.catch(() => void 0),
|
|
33073
|
-
new Promise((
|
|
33099
|
+
new Promise((resolve5) => {
|
|
33074
33100
|
timer = setTimeout(
|
|
33075
|
-
|
|
33101
|
+
resolve5,
|
|
33076
33102
|
options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
|
|
33077
33103
|
);
|
|
33078
33104
|
})
|
|
@@ -33186,7 +33212,7 @@ var alignRequestedEffort = async (input2) => {
|
|
|
33186
33212
|
return { configOptions, unsupportedEffort, ...confirmed ? { appliedEffort: fallback } : {} };
|
|
33187
33213
|
};
|
|
33188
33214
|
|
|
33189
|
-
// ../../packages/ycodium-
|
|
33215
|
+
// ../../packages/ycodium-executor-common/src/reasoningLevelFallback.ts
|
|
33190
33216
|
var REASONING_LEVEL_FALLBACK_CODE = "reasoning-level-fallback";
|
|
33191
33217
|
function reasoningLevelFallbackWarning(input2) {
|
|
33192
33218
|
const model = input2.model ?? "This model";
|
|
@@ -33938,12 +33964,12 @@ function createPromptResults({
|
|
|
33938
33964
|
}) {
|
|
33939
33965
|
const prompts = /* @__PURE__ */ new Map();
|
|
33940
33966
|
const add = (identity, finish) => {
|
|
33941
|
-
const { promise: done, resolve:
|
|
33967
|
+
const { promise: done, resolve: resolve5 } = Promise.withResolvers();
|
|
33942
33968
|
const record2 = {
|
|
33943
33969
|
...identity,
|
|
33944
33970
|
finish,
|
|
33945
33971
|
done,
|
|
33946
|
-
resolve:
|
|
33972
|
+
resolve: resolve5,
|
|
33947
33973
|
rejected: false,
|
|
33948
33974
|
interrupted: false,
|
|
33949
33975
|
finished: false
|
|
@@ -33991,9 +34017,9 @@ function createPromptResults({
|
|
|
33991
34017
|
try {
|
|
33992
34018
|
const drained = await Promise.race([
|
|
33993
34019
|
Promise.all(claimed.map((record2) => record2.done)).then(() => true),
|
|
33994
|
-
new Promise((
|
|
34020
|
+
new Promise((resolve5) => {
|
|
33995
34021
|
timer = setTimeout(
|
|
33996
|
-
() =>
|
|
34022
|
+
() => resolve5(false),
|
|
33997
34023
|
options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
|
|
33998
34024
|
);
|
|
33999
34025
|
})
|
|
@@ -34192,14 +34218,14 @@ function createExecutorRequests({
|
|
|
34192
34218
|
const statement = hooks.permissionStatement?.(permissionContext) ?? defaultPermissionStatement(permissionRequest);
|
|
34193
34219
|
const fileChanges = hooks.permissionFileChanges?.(permissionContext) ?? fileChangesFromAcpPermission(permissionRequest);
|
|
34194
34220
|
const requestId = randomId();
|
|
34195
|
-
const outcome = await new Promise((
|
|
34221
|
+
const outcome = await new Promise((resolve5) => {
|
|
34196
34222
|
const pending = {
|
|
34197
34223
|
requestId,
|
|
34198
34224
|
request: params,
|
|
34199
34225
|
permissionRequest,
|
|
34200
34226
|
turnId: shared.activeTurnId,
|
|
34201
34227
|
settled: false,
|
|
34202
|
-
resolve:
|
|
34228
|
+
resolve: resolve5
|
|
34203
34229
|
};
|
|
34204
34230
|
approvals.add(pending);
|
|
34205
34231
|
emit(
|
|
@@ -34282,7 +34308,7 @@ function createExecutorRequests({
|
|
|
34282
34308
|
}
|
|
34283
34309
|
|
|
34284
34310
|
// ../../packages/ycodium-acp-executor/src/artifacts.ts
|
|
34285
|
-
import * as
|
|
34311
|
+
import * as NodePath2 from "node:path";
|
|
34286
34312
|
import * as NodeURL from "node:url";
|
|
34287
34313
|
function resourceLinkArtifacts(content) {
|
|
34288
34314
|
if (content["type"] !== "resource_link" || typeof content["uri"] !== "string") return [];
|
|
@@ -34293,7 +34319,7 @@ function resourceLinkArtifacts(content) {
|
|
|
34293
34319
|
} catch {
|
|
34294
34320
|
return [];
|
|
34295
34321
|
}
|
|
34296
|
-
if (!
|
|
34322
|
+
if (!NodePath2.isAbsolute(path)) return [];
|
|
34297
34323
|
const name = typeof content["name"] === "string" ? content["name"].trim() : "";
|
|
34298
34324
|
const mimeType = typeof content["mimeType"] === "string" ? content["mimeType"].trim() : "";
|
|
34299
34325
|
return [
|
|
@@ -34338,7 +34364,7 @@ function makeArtifactEmitter(input2) {
|
|
|
34338
34364
|
// ../../packages/ycodium-acp-executor/src/executor/runtime.ts
|
|
34339
34365
|
function createExecutorRuntime({
|
|
34340
34366
|
randomId,
|
|
34341
|
-
nowIso:
|
|
34367
|
+
nowIso: nowIso4,
|
|
34342
34368
|
eventStream,
|
|
34343
34369
|
options,
|
|
34344
34370
|
assistantItemRuntimeId,
|
|
@@ -34347,7 +34373,7 @@ function createExecutorRuntime({
|
|
|
34347
34373
|
}) {
|
|
34348
34374
|
const stamp = () => ({
|
|
34349
34375
|
eventId: randomId(),
|
|
34350
|
-
createdAt:
|
|
34376
|
+
createdAt: nowIso4()
|
|
34351
34377
|
});
|
|
34352
34378
|
const isLive = (expectedGeneration) => !shared.disposed && shared.generation === expectedGeneration;
|
|
34353
34379
|
const publish = (event) => {
|
|
@@ -34416,14 +34442,14 @@ function createExecutorRuntime({
|
|
|
34416
34442
|
if (!promptMutex.isLocked) {
|
|
34417
34443
|
return true;
|
|
34418
34444
|
}
|
|
34419
|
-
return await new Promise((
|
|
34445
|
+
return await new Promise((resolve5) => {
|
|
34420
34446
|
const timer = setTimeout(() => {
|
|
34421
34447
|
shared.promptWaiters = shared.promptWaiters.filter((waiter) => waiter !== onSettle);
|
|
34422
|
-
|
|
34448
|
+
resolve5(false);
|
|
34423
34449
|
}, timeoutMs);
|
|
34424
34450
|
const onSettle = () => {
|
|
34425
34451
|
clearTimeout(timer);
|
|
34426
|
-
|
|
34452
|
+
resolve5(true);
|
|
34427
34453
|
};
|
|
34428
34454
|
shared.promptWaiters.push(onSettle);
|
|
34429
34455
|
});
|
|
@@ -34525,7 +34551,7 @@ function judgeRequestedModel(input2) {
|
|
|
34525
34551
|
const hasCurrent = current !== void 0;
|
|
34526
34552
|
if (!hasCatalog && !hasCurrent && input2.state.modelUnconfirmed !== true) return { kind: "keep" };
|
|
34527
34553
|
const canSwitch = canSwitchModel(input2.state);
|
|
34528
|
-
const value = hasCatalog ?
|
|
34554
|
+
const value = hasCatalog ? matchCatalogModel(requested, input2.state.advertisedModelValues) : void 0;
|
|
34529
34555
|
if (value !== void 0 && value === current) return { kind: "keep" };
|
|
34530
34556
|
if (value !== void 0 && canSwitch) return { kind: "switch", value };
|
|
34531
34557
|
return { kind: "refresh" };
|
|
@@ -34565,18 +34591,18 @@ function modelRefreshFailedError(requestedModelId, error62) {
|
|
|
34565
34591
|
}
|
|
34566
34592
|
|
|
34567
34593
|
// ../../packages/ycodium-acp-executor/src/runtime-mode.ts
|
|
34568
|
-
function
|
|
34594
|
+
function isRecord6(value) {
|
|
34569
34595
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34570
34596
|
}
|
|
34571
34597
|
function asString2(value) {
|
|
34572
34598
|
return typeof value === "string" ? value : void 0;
|
|
34573
34599
|
}
|
|
34574
34600
|
function acpModeConfigId(setup) {
|
|
34575
|
-
if (!
|
|
34601
|
+
if (!isRecord6(setup)) return void 0;
|
|
34576
34602
|
const configOptions = setup["configOptions"];
|
|
34577
34603
|
if (!Array.isArray(configOptions)) return void 0;
|
|
34578
34604
|
for (const option of configOptions) {
|
|
34579
|
-
if (!
|
|
34605
|
+
if (!isRecord6(option)) continue;
|
|
34580
34606
|
if (asString2(option["category"])?.trim().toLowerCase() !== "mode") continue;
|
|
34581
34607
|
const id = asString2(option["id"])?.trim();
|
|
34582
34608
|
if (id) return id;
|
|
@@ -35489,8 +35515,8 @@ function readOpenToolCalls(toolCalls, turnId) {
|
|
|
35489
35515
|
|
|
35490
35516
|
// ../../packages/ycodium-acp-executor/src/protocol-log.ts
|
|
35491
35517
|
import * as NodeFS from "node:fs";
|
|
35492
|
-
import * as
|
|
35493
|
-
import * as
|
|
35518
|
+
import * as NodeOS2 from "node:os";
|
|
35519
|
+
import * as NodePath3 from "node:path";
|
|
35494
35520
|
var DEFAULT_MAX_BYTES = 8 * 1024 * 1024;
|
|
35495
35521
|
var UNSAFE_FILE_CHARS = /[^A-Za-z0-9._-]+/gu;
|
|
35496
35522
|
function safeFileName(value) {
|
|
@@ -35499,7 +35525,7 @@ function safeFileName(value) {
|
|
|
35499
35525
|
function createAcpProtocolLogFile(input2) {
|
|
35500
35526
|
const maxBytes = input2.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
35501
35527
|
NodeFS.mkdirSync(input2.directory, { recursive: true });
|
|
35502
|
-
const filePath =
|
|
35528
|
+
const filePath = NodePath3.join(
|
|
35503
35529
|
input2.directory,
|
|
35504
35530
|
`${safeFileName(input2.provider)}-${safeFileName(input2.threadId)}-${Date.now().toString(36)}.ndjson`
|
|
35505
35531
|
);
|
|
@@ -35555,7 +35581,7 @@ function createAcpProtocolLogFromEnv(input2) {
|
|
|
35555
35581
|
const flag = process.env.YCODIUM_ACP_PROTOCOL_LOG;
|
|
35556
35582
|
if (flag !== "1" && flag?.toLowerCase() !== "true") return void 0;
|
|
35557
35583
|
const configured = process.env.YCODIUM_ACP_PROTOCOL_LOG_DIR?.trim();
|
|
35558
|
-
const directory = configured && configured.length > 0 ? configured :
|
|
35584
|
+
const directory = configured && configured.length > 0 ? configured : NodePath3.join(NodeOS2.tmpdir(), "ycodium-acp-protocol");
|
|
35559
35585
|
try {
|
|
35560
35586
|
const sink = createAcpProtocolLogFile({
|
|
35561
35587
|
directory,
|
|
@@ -35584,7 +35610,7 @@ function defaultRandomId() {
|
|
|
35584
35610
|
function createAcpExecutor(options) {
|
|
35585
35611
|
const hooks = { ...defaultVendorHooks, ...options.hooks };
|
|
35586
35612
|
const cancelGraceMs = options.cancelGraceMs ?? DEFAULT_CANCEL_GRACE_MS;
|
|
35587
|
-
const
|
|
35613
|
+
const nowIso4 = options.nowIso ?? defaultNowIso;
|
|
35588
35614
|
const randomId = options.randomId ?? defaultRandomId;
|
|
35589
35615
|
const eventStream = new UnboundedEventStream();
|
|
35590
35616
|
const threadMutex = new Mutex();
|
|
@@ -35645,7 +35671,7 @@ function createAcpExecutor(options) {
|
|
|
35645
35671
|
waitForPromptIdle
|
|
35646
35672
|
} = createExecutorRuntime({
|
|
35647
35673
|
randomId,
|
|
35648
|
-
nowIso:
|
|
35674
|
+
nowIso: nowIso4,
|
|
35649
35675
|
eventStream,
|
|
35650
35676
|
options,
|
|
35651
35677
|
assistantItemRuntimeId,
|
|
@@ -35889,7 +35915,7 @@ function createAcpExecutor(options) {
|
|
|
35889
35915
|
}
|
|
35890
35916
|
|
|
35891
35917
|
// ../../packages/ycodium-acp-executor/src/session-registry.ts
|
|
35892
|
-
function createAcpSessionRegistry(threads,
|
|
35918
|
+
function createAcpSessionRegistry(threads, stopBooked, log) {
|
|
35893
35919
|
const exits = /* @__PURE__ */ new WeakMap();
|
|
35894
35920
|
const requireThread = (threadId) => {
|
|
35895
35921
|
const booked = threads.get(threadId);
|
|
@@ -35900,7 +35926,7 @@ function createAcpSessionRegistry(threads, stopBooked2, log) {
|
|
|
35900
35926
|
const stopSession = (threadId, booked = threads.get(threadId)) => {
|
|
35901
35927
|
if (!booked) return Promise.resolve();
|
|
35902
35928
|
const close = { exitCode: exits.get(booked), hasExited: () => exits.has(booked) };
|
|
35903
|
-
booked.closing ??= Promise.resolve().then(() =>
|
|
35929
|
+
booked.closing ??= Promise.resolve().then(() => stopBooked(booked, close)).then(() => {
|
|
35904
35930
|
if (threads.get(threadId) === booked) threads.delete(threadId);
|
|
35905
35931
|
}).catch((cause) => {
|
|
35906
35932
|
if (threads.get(threadId) === booked) delete booked.closing;
|
|
@@ -35983,13 +36009,13 @@ function createRetryableClose(run) {
|
|
|
35983
36009
|
|
|
35984
36010
|
// ../../packages/ycodium-acp-executor/src/prompt-dispatch.ts
|
|
35985
36011
|
var dispatchAcpPrompt = (executor, input2) => {
|
|
35986
|
-
const { promise: dispatched, resolve:
|
|
36012
|
+
const { promise: dispatched, resolve: resolve5 } = Promise.withResolvers();
|
|
35987
36013
|
let written = false;
|
|
35988
36014
|
const finished = executor.prompt({
|
|
35989
36015
|
...input2,
|
|
35990
36016
|
onDispatched: (turnId) => {
|
|
35991
36017
|
written = true;
|
|
35992
|
-
|
|
36018
|
+
resolve5(turnId);
|
|
35993
36019
|
}
|
|
35994
36020
|
});
|
|
35995
36021
|
return Promise.race([
|
|
@@ -36003,29 +36029,215 @@ var dispatchAcpPrompt = (executor, input2) => {
|
|
|
36003
36029
|
]);
|
|
36004
36030
|
};
|
|
36005
36031
|
|
|
36006
|
-
// ../../packages/ycodium-acp-executor/src/
|
|
36007
|
-
|
|
36008
|
-
|
|
36009
|
-
}
|
|
36010
|
-
|
|
36011
|
-
|
|
36012
|
-
|
|
36013
|
-
|
|
36014
|
-
|
|
36015
|
-
|
|
36016
|
-
|
|
36017
|
-
|
|
36018
|
-
|
|
36019
|
-
|
|
36020
|
-
|
|
36021
|
-
|
|
36032
|
+
// ../../packages/ycodium-acp-executor/src/thread-operations.ts
|
|
36033
|
+
var yieldTick = () => new Promise((resolve5) => {
|
|
36034
|
+
setImmediate(resolve5);
|
|
36035
|
+
});
|
|
36036
|
+
var nowIso = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
36037
|
+
function createAcpThreadOperations(options) {
|
|
36038
|
+
const { threads, requireThread } = options;
|
|
36039
|
+
return {
|
|
36040
|
+
sendTurn: async (input2, signal) => {
|
|
36041
|
+
if (options.isDisposed()) throw new Error("instance disposed");
|
|
36042
|
+
const booked = requireThread(input2.threadId);
|
|
36043
|
+
if (signal?.aborted) throw new Error("aborted");
|
|
36044
|
+
options.beforeSendTurn?.(booked);
|
|
36045
|
+
const onAbort = () => {
|
|
36046
|
+
void booked.executor.cancel(input2.expectedTurnId).catch(() => void 0);
|
|
36047
|
+
};
|
|
36048
|
+
signal?.addEventListener("abort", onAbort);
|
|
36049
|
+
try {
|
|
36050
|
+
const { requestedModelId, requestedEffort } = options.turnSelection?.(input2.modelSelection) ?? {};
|
|
36051
|
+
const turn = await dispatchAcpPrompt(booked.executor, {
|
|
36052
|
+
text: input2.input ?? "",
|
|
36053
|
+
expectedActiveTurnId: input2.expectedTurnId,
|
|
36054
|
+
...requestedModelId === void 0 ? {} : { requestedModelId },
|
|
36055
|
+
...requestedEffort === void 0 ? {} : { requestedEffort }
|
|
36056
|
+
});
|
|
36057
|
+
booked.turns.push({ id: turn.turnId, items: [] });
|
|
36058
|
+
return {
|
|
36059
|
+
threadId: input2.threadId,
|
|
36060
|
+
turnId: turn.turnId,
|
|
36061
|
+
...booked.session.resumeCursor === void 0 ? {} : { resumeCursor: booked.session.resumeCursor }
|
|
36062
|
+
};
|
|
36063
|
+
} finally {
|
|
36064
|
+
signal?.removeEventListener("abort", onAbort);
|
|
36065
|
+
}
|
|
36066
|
+
},
|
|
36067
|
+
interruptTurn: async (threadId, turnId) => {
|
|
36068
|
+
const booked = threads.get(threadId);
|
|
36069
|
+
if (booked === void 0 || booked.closing) return;
|
|
36070
|
+
options.log.info("interrupt turn", { threadId, turnId });
|
|
36071
|
+
await booked.executor.cancel(turnId);
|
|
36072
|
+
await yieldTick();
|
|
36073
|
+
},
|
|
36074
|
+
respondToRequest: async (threadId, requestId, decision, reason) => {
|
|
36075
|
+
const booked = requireThread(threadId);
|
|
36076
|
+
await booked.executor.respondToRequest(
|
|
36077
|
+
requestId,
|
|
36078
|
+
decision === "allow" ? "accept" : "decline",
|
|
36079
|
+
reason
|
|
36080
|
+
);
|
|
36081
|
+
},
|
|
36082
|
+
respondToUserInput: async (threadId, requestId, answers) => {
|
|
36083
|
+
const booked = requireThread(threadId);
|
|
36084
|
+
await booked.executor.respondToUserInput(requestId, answers);
|
|
36085
|
+
},
|
|
36086
|
+
/**
|
|
36087
|
+
* 切这只手自报的审批档。`nativeModeId` 是它自己报的 id(探测时原样上报的那些),
|
|
36088
|
+
* 一路不翻译成宿主四档。
|
|
36089
|
+
*
|
|
36090
|
+
* 这是 `setRuntimeMode` 做不到的那一半:那个只改插件自己的会话记录,CLI 收不到
|
|
36091
|
+
* (`runtime-mode-never-reaches-cli` 记的那族缺陷)。
|
|
36092
|
+
*/
|
|
36093
|
+
setNativeMode: async (threadId, nativeModeId) => {
|
|
36094
|
+
const booked = requireThread(threadId);
|
|
36095
|
+
await booked.executor.setNativeMode(nativeModeId);
|
|
36096
|
+
booked.session = { ...booked.session, nativeModeId, updatedAt: nowIso() };
|
|
36097
|
+
},
|
|
36098
|
+
setRuntimeMode: async (threadId, runtimeMode) => {
|
|
36099
|
+
const booked = requireThread(threadId);
|
|
36100
|
+
booked.session = { ...booked.session, runtimeMode, updatedAt: nowIso() };
|
|
36101
|
+
},
|
|
36102
|
+
readThread: async (threadId) => {
|
|
36103
|
+
const booked = requireThread(threadId);
|
|
36104
|
+
return { threadId, turns: booked.turns };
|
|
36105
|
+
}
|
|
36106
|
+
};
|
|
36022
36107
|
}
|
|
36023
36108
|
|
|
36024
|
-
// ../../packages/ycodium-
|
|
36025
|
-
|
|
36026
|
-
|
|
36027
|
-
|
|
36028
|
-
|
|
36109
|
+
// ../../packages/ycodium-executor-common/src/nodeStreams.ts
|
|
36110
|
+
import * as NodeOS3 from "node:os";
|
|
36111
|
+
import * as NodeStream2 from "node:stream";
|
|
36112
|
+
var PEER_CLOSED_STDIN_CODES = /* @__PURE__ */ new Set([
|
|
36113
|
+
"EPIPE",
|
|
36114
|
+
"ECONNRESET",
|
|
36115
|
+
"EOF",
|
|
36116
|
+
"ERR_STREAM_DESTROYED",
|
|
36117
|
+
"ERR_STREAM_WRITE_AFTER_END",
|
|
36118
|
+
"ERR_STREAM_ALREADY_FINISHED"
|
|
36119
|
+
]);
|
|
36120
|
+
function errorCode(value) {
|
|
36121
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
36122
|
+
const code = value.code;
|
|
36123
|
+
return typeof code === "string" ? code : void 0;
|
|
36124
|
+
}
|
|
36125
|
+
function asError(value) {
|
|
36126
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
36127
|
+
}
|
|
36128
|
+
function isPeerClosedStdinError(error62) {
|
|
36129
|
+
const code = errorCode(error62);
|
|
36130
|
+
return code !== void 0 && PEER_CLOSED_STDIN_CODES.has(code);
|
|
36131
|
+
}
|
|
36132
|
+
var PeerClosedStdinError = class extends Error {
|
|
36133
|
+
name = "PeerClosedStdinError";
|
|
36134
|
+
code;
|
|
36135
|
+
constructor(operation, cause) {
|
|
36136
|
+
super(
|
|
36137
|
+
`Child process stdin is closed; the ${operation} did not reach the peer.`,
|
|
36138
|
+
cause === void 0 ? void 0 : { cause }
|
|
36139
|
+
);
|
|
36140
|
+
this.code = errorCode(cause) ?? "ERR_STREAM_DESTROYED";
|
|
36141
|
+
}
|
|
36142
|
+
};
|
|
36143
|
+
var ownErrors = {
|
|
36144
|
+
isPeerClosed: isPeerClosedStdinError,
|
|
36145
|
+
peerClosed: (operation, cause) => new PeerClosedStdinError(operation, cause)
|
|
36146
|
+
};
|
|
36147
|
+
function toStreamError(errors, operation, error62) {
|
|
36148
|
+
if (errors.isPeerClosed(error62)) return errors.peerClosed(operation, error62);
|
|
36149
|
+
return asError(error62);
|
|
36150
|
+
}
|
|
36151
|
+
function nodeWritableFromHandle(handle, errors = ownErrors) {
|
|
36152
|
+
return new NodeStream2.Writable({
|
|
36153
|
+
write(chunk, _encoding, callback) {
|
|
36154
|
+
const bytes = typeof chunk === "string" ? new TextEncoder().encode(chunk) : chunk;
|
|
36155
|
+
handle.writeStdin(bytes).then(
|
|
36156
|
+
() => callback(),
|
|
36157
|
+
(error62) => callback(toStreamError(errors, "write", error62))
|
|
36158
|
+
);
|
|
36159
|
+
},
|
|
36160
|
+
final(callback) {
|
|
36161
|
+
handle.closeStdin().then(
|
|
36162
|
+
() => callback(),
|
|
36163
|
+
// 关一条对端已经没了的流是正常收尾,不是失败;真异常照旧交出去。
|
|
36164
|
+
(error62) => callback(errors.isPeerClosed(error62) ? void 0 : toStreamError(errors, "close", error62))
|
|
36165
|
+
);
|
|
36166
|
+
}
|
|
36167
|
+
});
|
|
36168
|
+
}
|
|
36169
|
+
var STDERR_TAIL_MAX_CHARS = 4096;
|
|
36170
|
+
var STDERR_SETTLE_MS = 500;
|
|
36171
|
+
var PAIRING_URL_PATTERN = /https?:\/\/[^\s]*\/pair#[^\s]*/gi;
|
|
36172
|
+
var BEARER_TOKEN_PATTERN = /\bBearer\s+[A-Za-z0-9._\-+=/]+/gi;
|
|
36173
|
+
var BASIC_AUTH_PATTERN = /\bAuthorization:\s*Basic\s+\S+/gi;
|
|
36174
|
+
var API_KEY_HEADER_PATTERN = /\bx-api-key:\s*\S+/gi;
|
|
36175
|
+
var SECRET_TOKEN_PATTERN = /\b(?:sk-[A-Za-z0-9][A-Za-z0-9-]{7,}|ghp_[A-Za-z0-9]+|xox[a-zA-Z]-[A-Za-z0-9-]+)\b/g;
|
|
36176
|
+
function redactStderrExcerpt(text, environment = process.env) {
|
|
36177
|
+
let result = text.replaceAll("\0", "");
|
|
36178
|
+
const homes = [environment["HOME"], environment["USERPROFILE"], NodeOS3.homedir()].filter(
|
|
36179
|
+
(value) => typeof value === "string" && value.length > 1
|
|
36180
|
+
);
|
|
36181
|
+
for (const home of new Set(homes)) {
|
|
36182
|
+
result = result.split(home).join("~");
|
|
36183
|
+
}
|
|
36184
|
+
return result.replace(PAIRING_URL_PATTERN, "[pairing-url]").replace(BEARER_TOKEN_PATTERN, "Bearer [redacted]").replace(BASIC_AUTH_PATTERN, "Authorization: Basic [redacted]").replace(API_KEY_HEADER_PATTERN, "x-api-key: [redacted]").replace(SECRET_TOKEN_PATTERN, "[redacted]").trim();
|
|
36185
|
+
}
|
|
36186
|
+
function drainStderrTail(stderr) {
|
|
36187
|
+
let tail = "";
|
|
36188
|
+
const decoder = new TextDecoder();
|
|
36189
|
+
const drained = (async () => {
|
|
36190
|
+
for await (const chunk of stderr) {
|
|
36191
|
+
const next = tail + decoder.decode(chunk, { stream: true });
|
|
36192
|
+
tail = next.length <= STDERR_TAIL_MAX_CHARS ? next : next.slice(-STDERR_TAIL_MAX_CHARS);
|
|
36193
|
+
}
|
|
36194
|
+
})().catch(() => void 0);
|
|
36195
|
+
return async () => {
|
|
36196
|
+
let timer;
|
|
36197
|
+
await Promise.race([
|
|
36198
|
+
drained,
|
|
36199
|
+
new Promise((resolve5) => {
|
|
36200
|
+
timer = setTimeout(resolve5, STDERR_SETTLE_MS);
|
|
36201
|
+
})
|
|
36202
|
+
]);
|
|
36203
|
+
clearTimeout(timer);
|
|
36204
|
+
return redactStderrExcerpt(tail);
|
|
36205
|
+
};
|
|
36206
|
+
}
|
|
36207
|
+
function nodeStreamsFromHandle(handle, errors = ownErrors) {
|
|
36208
|
+
const readable = new NodeStream2.PassThrough();
|
|
36209
|
+
void (async () => {
|
|
36210
|
+
try {
|
|
36211
|
+
for await (const chunk of handle.stdout) {
|
|
36212
|
+
if (!readable.writable) return;
|
|
36213
|
+
if (!readable.write(chunk)) {
|
|
36214
|
+
await new Promise((resolve5) => {
|
|
36215
|
+
const onDone = () => {
|
|
36216
|
+
readable.off("drain", onDone);
|
|
36217
|
+
readable.off("close", onDone);
|
|
36218
|
+
resolve5();
|
|
36219
|
+
};
|
|
36220
|
+
readable.once("drain", onDone);
|
|
36221
|
+
readable.once("close", onDone);
|
|
36222
|
+
});
|
|
36223
|
+
}
|
|
36224
|
+
}
|
|
36225
|
+
} catch (error62) {
|
|
36226
|
+
readable.destroy(asError(error62));
|
|
36227
|
+
return;
|
|
36228
|
+
}
|
|
36229
|
+
if (readable.writable) readable.end();
|
|
36230
|
+
})();
|
|
36231
|
+
const settledStderrTail = drainStderrTail(handle.stderr);
|
|
36232
|
+
const writable = nodeWritableFromHandle(handle, errors);
|
|
36233
|
+
return { readable, writable, stderrTail: settledStderrTail };
|
|
36234
|
+
}
|
|
36235
|
+
|
|
36236
|
+
// ../../packages/ycodium-acp-executor/src/mcp-servers.ts
|
|
36237
|
+
function toAcpMcpServers(entries) {
|
|
36238
|
+
return (entries ?? []).map(
|
|
36239
|
+
(entry) => entry.transport.type === "stdio" ? {
|
|
36240
|
+
name: entry.name,
|
|
36029
36241
|
command: entry.transport.command,
|
|
36030
36242
|
args: [...entry.transport.args ?? []],
|
|
36031
36243
|
env: Object.entries(entry.transport.env ?? {}).map(([name, value]) => ({ name, value }))
|
|
@@ -36041,10 +36253,186 @@ function toAcpMcpServers(entries) {
|
|
|
36041
36253
|
);
|
|
36042
36254
|
}
|
|
36043
36255
|
|
|
36256
|
+
// ../../packages/ycodium-acp-executor/src/start-abort.ts
|
|
36257
|
+
function throwIfStartAborted(signal) {
|
|
36258
|
+
if (signal?.aborted) throw new Error("aborted");
|
|
36259
|
+
}
|
|
36260
|
+
async function raceStartAbort(promise2, signal) {
|
|
36261
|
+
void promise2.catch(() => void 0);
|
|
36262
|
+
throwIfStartAborted(signal);
|
|
36263
|
+
if (signal === void 0) return promise2;
|
|
36264
|
+
const aborted2 = Promise.withResolvers();
|
|
36265
|
+
const onAbort = () => aborted2.reject(new Error("aborted"));
|
|
36266
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
36267
|
+
try {
|
|
36268
|
+
return await Promise.race([promise2, aborted2.promise]);
|
|
36269
|
+
} finally {
|
|
36270
|
+
signal.removeEventListener("abort", onAbort);
|
|
36271
|
+
}
|
|
36272
|
+
}
|
|
36273
|
+
|
|
36274
|
+
// ../../packages/ycodium-acp-executor/src/instance-kit.ts
|
|
36275
|
+
var yieldTick2 = () => new Promise((resolve5) => {
|
|
36276
|
+
setImmediate(resolve5);
|
|
36277
|
+
});
|
|
36278
|
+
var nowIso2 = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
36279
|
+
function createAcpThreadTable(log, beforeStopAll) {
|
|
36280
|
+
const threads = /* @__PURE__ */ new Map();
|
|
36281
|
+
const registry2 = createAcpSessionRegistry(
|
|
36282
|
+
threads,
|
|
36283
|
+
(booked, processExit) => cleanupAcpSession({
|
|
36284
|
+
executor: booked.executor,
|
|
36285
|
+
stopProcess: () => booked.handle.kill("SIGTERM"),
|
|
36286
|
+
forwarding: booked.forwarding,
|
|
36287
|
+
processExit
|
|
36288
|
+
}),
|
|
36289
|
+
log
|
|
36290
|
+
);
|
|
36291
|
+
const disposeOnce = createRetryableClose(async () => {
|
|
36292
|
+
await beforeStopAll?.();
|
|
36293
|
+
await registry2.stopAll();
|
|
36294
|
+
});
|
|
36295
|
+
return { threads, ...registry2, disposeOnce };
|
|
36296
|
+
}
|
|
36297
|
+
async function stopExistingAcpThread(table, threadId, isDisposed, signal) {
|
|
36298
|
+
const existing = table.threads.get(threadId);
|
|
36299
|
+
if (existing === void 0) return;
|
|
36300
|
+
await table.stopSession(threadId, existing);
|
|
36301
|
+
if (isDisposed()) throw new Error("instance disposed");
|
|
36302
|
+
throwIfStartAborted(signal);
|
|
36303
|
+
}
|
|
36304
|
+
function acpResumeFrom(input2, schemaVersion) {
|
|
36305
|
+
return input2.discardResumeCursor === true ? void 0 : parseAcpResumeCursor(input2.resumeCursor, schemaVersion);
|
|
36306
|
+
}
|
|
36307
|
+
function acpStartedSession(input2, started) {
|
|
36308
|
+
const createdAt = nowIso2();
|
|
36309
|
+
return {
|
|
36310
|
+
provider: input2.provider,
|
|
36311
|
+
providerInstanceId: input2.providerInstanceId,
|
|
36312
|
+
status: "idle",
|
|
36313
|
+
runtimeMode: input2.runtimeMode,
|
|
36314
|
+
...input2.nativeModeId === void 0 ? {} : { nativeModeId: input2.nativeModeId },
|
|
36315
|
+
cwd: input2.cwd,
|
|
36316
|
+
threadId: input2.threadId,
|
|
36317
|
+
createdAt,
|
|
36318
|
+
updatedAt: createdAt,
|
|
36319
|
+
resumeCursor: { schemaVersion: input2.resumeSchemaVersion, sessionId: started.sessionId },
|
|
36320
|
+
...started.modelId === void 0 ? {} : {
|
|
36321
|
+
model: started.modelId,
|
|
36322
|
+
// agent 在握手里报的才是读回的;切型号走 session/set_model 时回包不带型号,那只是请求值。
|
|
36323
|
+
modelSource: started.modelReported ? "reported" : "echo"
|
|
36324
|
+
},
|
|
36325
|
+
...input2.bindingGeneration === void 0 ? {} : { bindingGeneration: input2.bindingGeneration }
|
|
36326
|
+
};
|
|
36327
|
+
}
|
|
36328
|
+
async function openAcpThread(input2) {
|
|
36329
|
+
const { executor, handle, signal, threadId } = input2;
|
|
36330
|
+
const forwarding = (async () => {
|
|
36331
|
+
for await (const event of executor.events) {
|
|
36332
|
+
const forwarded = input2.forward(event);
|
|
36333
|
+
if (forwarded !== void 0) await forwarded;
|
|
36334
|
+
}
|
|
36335
|
+
})();
|
|
36336
|
+
try {
|
|
36337
|
+
throwIfStartAborted(signal);
|
|
36338
|
+
const started = await raceStartAbort(executor.start(), signal);
|
|
36339
|
+
const after = input2.afterStart?.(started);
|
|
36340
|
+
if (after !== void 0) await after;
|
|
36341
|
+
await yieldTick2();
|
|
36342
|
+
throwIfStartAborted(signal);
|
|
36343
|
+
const session = input2.session(started);
|
|
36344
|
+
input2.registerSession(
|
|
36345
|
+
threadId,
|
|
36346
|
+
input2.booked({ session, turns: [], executor, handle, forwarding })
|
|
36347
|
+
);
|
|
36348
|
+
input2.log.info("session started", { threadId, sessionId: started.sessionId });
|
|
36349
|
+
input2.afterRegister?.();
|
|
36350
|
+
return session;
|
|
36351
|
+
} catch (error62) {
|
|
36352
|
+
await cleanupAcpStartup({
|
|
36353
|
+
executor,
|
|
36354
|
+
stopProcess: () => handle.kill("SIGTERM"),
|
|
36355
|
+
forwarding,
|
|
36356
|
+
log: input2.log,
|
|
36357
|
+
threadId
|
|
36358
|
+
});
|
|
36359
|
+
throw error62;
|
|
36360
|
+
}
|
|
36361
|
+
}
|
|
36362
|
+
function acpLaunchMcpFields(input2) {
|
|
36363
|
+
const omit2 = input2.omitWhenEmpty === true && (input2.mcpServers === void 0 || input2.mcpServers.length === 0);
|
|
36364
|
+
return {
|
|
36365
|
+
...omit2 ? {} : { mcpServers: toAcpMcpServers(input2.mcpServers) },
|
|
36366
|
+
...input2.resumeSessionId === void 0 ? {} : { resumeSessionId: input2.resumeSessionId }
|
|
36367
|
+
};
|
|
36368
|
+
}
|
|
36369
|
+
function openAcpThreadSession(input2) {
|
|
36370
|
+
return openAcpThread({
|
|
36371
|
+
registerSession: input2.registerSession,
|
|
36372
|
+
threadId: input2.threadId,
|
|
36373
|
+
executor: input2.executor,
|
|
36374
|
+
handle: input2.handle,
|
|
36375
|
+
...input2.signal === void 0 ? {} : { signal: input2.signal },
|
|
36376
|
+
log: input2.log,
|
|
36377
|
+
forward: input2.emit,
|
|
36378
|
+
...input2.afterStart === void 0 ? {} : { afterStart: input2.afterStart },
|
|
36379
|
+
session: (started) => {
|
|
36380
|
+
input2.beforeSession?.(started);
|
|
36381
|
+
return acpStartedSession({ ...input2.session, threadId: input2.threadId }, started);
|
|
36382
|
+
},
|
|
36383
|
+
booked: input2.booked,
|
|
36384
|
+
...input2.afterRegister === void 0 ? {} : { afterRegister: input2.afterRegister }
|
|
36385
|
+
});
|
|
36386
|
+
}
|
|
36387
|
+
|
|
36388
|
+
// ../../packages/ycodium-acp-executor/src/probe-session.ts
|
|
36389
|
+
var acpProbeFailureDetail = (error62) => (error62 instanceof Error ? error62.message : String(error62)).trim() || void 0;
|
|
36390
|
+
function findAcpProbeSessionId(listed, probeCwd) {
|
|
36391
|
+
if (!isRecord2(listed) || !Array.isArray(listed["sessions"])) return void 0;
|
|
36392
|
+
for (const entry of listed["sessions"]) {
|
|
36393
|
+
if (!isRecord2(entry)) continue;
|
|
36394
|
+
if (entry["cwd"] !== probeCwd) continue;
|
|
36395
|
+
const sessionId = entry["sessionId"];
|
|
36396
|
+
if (typeof sessionId === "string" && sessionId.length > 0) return sessionId;
|
|
36397
|
+
}
|
|
36398
|
+
return void 0;
|
|
36399
|
+
}
|
|
36400
|
+
async function reuseAcpProbeSession(handshake, probeCwd) {
|
|
36401
|
+
const listed = await handshake.request("session/list", {}).catch(() => void 0);
|
|
36402
|
+
const reusable = findAcpProbeSessionId(listed, probeCwd);
|
|
36403
|
+
if (reusable !== void 0) {
|
|
36404
|
+
const resumed = await handshake.request("session/resume", { sessionId: reusable, cwd: probeCwd, mcpServers: [] }).catch(() => void 0);
|
|
36405
|
+
if (resumed !== void 0) return resumed;
|
|
36406
|
+
}
|
|
36407
|
+
return handshake.request("session/new", { cwd: probeCwd, mcpServers: [] });
|
|
36408
|
+
}
|
|
36409
|
+
function acpEffortCapabilities(configOptions, descriptor) {
|
|
36410
|
+
const state = acpEffortConfigState(configOptions);
|
|
36411
|
+
if (state === "unknown") return "unknown";
|
|
36412
|
+
if (state === "none") return { optionDescriptors: [] };
|
|
36413
|
+
const effort = findAcpEffortConfig(configOptions);
|
|
36414
|
+
if (effort === void 0) return "unknown";
|
|
36415
|
+
return {
|
|
36416
|
+
optionDescriptors: [
|
|
36417
|
+
{
|
|
36418
|
+
id: descriptor.id,
|
|
36419
|
+
label: effort.label || descriptor.fallbackLabel,
|
|
36420
|
+
type: "select",
|
|
36421
|
+
options: effort.choices.map((choice) => ({
|
|
36422
|
+
id: choice.value,
|
|
36423
|
+
label: choice.label,
|
|
36424
|
+
...choice.description === void 0 ? {} : { description: choice.description },
|
|
36425
|
+
...choice.isDefault === true ? { isDefault: true } : {}
|
|
36426
|
+
}))
|
|
36427
|
+
}
|
|
36428
|
+
]
|
|
36429
|
+
};
|
|
36430
|
+
}
|
|
36431
|
+
|
|
36044
36432
|
// ../../packages/ycodium-acp-executor/src/probe.ts
|
|
36045
36433
|
function withProbeTimeout(promise2, timeoutMs, what, signal) {
|
|
36046
36434
|
signal?.throwIfAborted();
|
|
36047
|
-
return new Promise((
|
|
36435
|
+
return new Promise((resolve5, reject) => {
|
|
36048
36436
|
const onAbort = () => {
|
|
36049
36437
|
clearTimeout(timer);
|
|
36050
36438
|
reject(signal?.reason ?? new Error("aborted"));
|
|
@@ -36059,7 +36447,7 @@ function withProbeTimeout(promise2, timeoutMs, what, signal) {
|
|
|
36059
36447
|
(value) => {
|
|
36060
36448
|
clearTimeout(timer);
|
|
36061
36449
|
signal?.removeEventListener("abort", onAbort);
|
|
36062
|
-
|
|
36450
|
+
resolve5(value);
|
|
36063
36451
|
},
|
|
36064
36452
|
(error62) => {
|
|
36065
36453
|
clearTimeout(timer);
|
|
@@ -36163,30 +36551,238 @@ async function collectProbeProcess(child, input2) {
|
|
|
36163
36551
|
}
|
|
36164
36552
|
var MAX_VERSION_OUTPUT_BYTES = 64 * 1024;
|
|
36165
36553
|
|
|
36554
|
+
// ../../packages/ycodium-acp-executor/src/probe-process.ts
|
|
36555
|
+
import * as NodeFS2 from "node:fs";
|
|
36556
|
+
|
|
36557
|
+
// ../../packages/ycodium-executor-common/src/raceAbort.ts
|
|
36558
|
+
async function raceAbort(pending, signal) {
|
|
36559
|
+
if (signal === void 0) return pending;
|
|
36560
|
+
void pending.catch(() => void 0);
|
|
36561
|
+
if (signal.aborted) throw new Error("aborted");
|
|
36562
|
+
let onAbort;
|
|
36563
|
+
const aborted2 = new Promise((_resolve, reject) => {
|
|
36564
|
+
onAbort = () => reject(new Error("aborted"));
|
|
36565
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
36566
|
+
});
|
|
36567
|
+
try {
|
|
36568
|
+
return await Promise.race([pending, aborted2]);
|
|
36569
|
+
} finally {
|
|
36570
|
+
signal.removeEventListener("abort", onAbort);
|
|
36571
|
+
}
|
|
36572
|
+
}
|
|
36573
|
+
|
|
36574
|
+
// ../../packages/ycodium-acp-executor/src/probe-process.ts
|
|
36575
|
+
async function withAcpProbeProcess(input2) {
|
|
36576
|
+
try {
|
|
36577
|
+
NodeFS2.mkdirSync(input2.cwd, { recursive: true });
|
|
36578
|
+
} catch (error62) {
|
|
36579
|
+
return { kind: "mkdir-failed", detail: acpProbeFailureDetail(error62) };
|
|
36580
|
+
}
|
|
36581
|
+
const spawned = await input2.spawn(input2.cwd);
|
|
36582
|
+
if (spawned.kind !== "spawned") return spawned;
|
|
36583
|
+
const handle = spawned.handle;
|
|
36584
|
+
let handshake;
|
|
36585
|
+
try {
|
|
36586
|
+
const streams = nodeStreamsFromHandle(handle);
|
|
36587
|
+
handshake = await raceAbort(
|
|
36588
|
+
openAcpProbeHandshake({
|
|
36589
|
+
readable: streams.readable,
|
|
36590
|
+
writable: streams.writable,
|
|
36591
|
+
clientInfo: input2.clientInfo,
|
|
36592
|
+
requestTimeoutMs: input2.requestTimeoutMs,
|
|
36593
|
+
...input2.subagentSessions === void 0 ? {} : { subagentSessions: input2.subagentSessions }
|
|
36594
|
+
}),
|
|
36595
|
+
input2.signal
|
|
36596
|
+
);
|
|
36597
|
+
return { kind: "ok", value: await input2.run(handshake) };
|
|
36598
|
+
} catch (error62) {
|
|
36599
|
+
return {
|
|
36600
|
+
kind: "threw",
|
|
36601
|
+
error: error62,
|
|
36602
|
+
handshakeOpened: handshake !== void 0,
|
|
36603
|
+
initializeResult: handshake?.initializeResult
|
|
36604
|
+
};
|
|
36605
|
+
} finally {
|
|
36606
|
+
await handshake?.close().catch(() => void 0);
|
|
36607
|
+
await handle.kill("SIGTERM").catch(() => void 0);
|
|
36608
|
+
}
|
|
36609
|
+
}
|
|
36610
|
+
|
|
36611
|
+
// ../../packages/ycodium-instance-config/src/launchArgs.ts
|
|
36612
|
+
function tokenizeShellWords(value) {
|
|
36613
|
+
const input2 = value.trim();
|
|
36614
|
+
if (!input2) return [];
|
|
36615
|
+
const tokens = [];
|
|
36616
|
+
let current = "";
|
|
36617
|
+
let quote;
|
|
36618
|
+
let quoted = false;
|
|
36619
|
+
for (let index = 0; index < input2.length; index++) {
|
|
36620
|
+
const char = input2[index];
|
|
36621
|
+
if (char === void 0) continue;
|
|
36622
|
+
if (quote) {
|
|
36623
|
+
if (char === quote) {
|
|
36624
|
+
quote = void 0;
|
|
36625
|
+
quoted = true;
|
|
36626
|
+
} else if (char === "\\" && quote === '"') {
|
|
36627
|
+
const next = input2[index + 1];
|
|
36628
|
+
if (next !== void 0 && ['"', "\\", "$", "`"].includes(next)) {
|
|
36629
|
+
current += next;
|
|
36630
|
+
index++;
|
|
36631
|
+
} else {
|
|
36632
|
+
current += char;
|
|
36633
|
+
}
|
|
36634
|
+
} else {
|
|
36635
|
+
current += char;
|
|
36636
|
+
}
|
|
36637
|
+
continue;
|
|
36638
|
+
}
|
|
36639
|
+
if (char === "'" || char === '"') {
|
|
36640
|
+
quote = char;
|
|
36641
|
+
quoted = true;
|
|
36642
|
+
} else if (/\s/.test(char)) {
|
|
36643
|
+
if (current || quoted) {
|
|
36644
|
+
tokens.push(current);
|
|
36645
|
+
current = "";
|
|
36646
|
+
quoted = false;
|
|
36647
|
+
}
|
|
36648
|
+
} else if (char === "\\") {
|
|
36649
|
+
const next = input2[index + 1];
|
|
36650
|
+
if (next !== void 0 && /\s/.test(next)) {
|
|
36651
|
+
current += next;
|
|
36652
|
+
index++;
|
|
36653
|
+
} else {
|
|
36654
|
+
current += char;
|
|
36655
|
+
}
|
|
36656
|
+
} else {
|
|
36657
|
+
current += char;
|
|
36658
|
+
}
|
|
36659
|
+
}
|
|
36660
|
+
if (current || quoted) tokens.push(current);
|
|
36661
|
+
return tokens;
|
|
36662
|
+
}
|
|
36663
|
+
|
|
36664
|
+
// ../../packages/ycodium-instance-config/src/instanceConfig.ts
|
|
36665
|
+
import { modelSelectionStringOption as modelSelectionStringOption2 } from "@ycodium-ai/plugin-api/executor";
|
|
36666
|
+
function isRecord7(value) {
|
|
36667
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36668
|
+
}
|
|
36669
|
+
function readString(value) {
|
|
36670
|
+
return typeof value === "string" ? value : "";
|
|
36671
|
+
}
|
|
36672
|
+
function readTrimmed(value) {
|
|
36673
|
+
return readString(value).trim();
|
|
36674
|
+
}
|
|
36675
|
+
function modelIdFromSelection(selection) {
|
|
36676
|
+
if (!isRecord7(selection)) return void 0;
|
|
36677
|
+
const model = selection["model"];
|
|
36678
|
+
return typeof model === "string" ? model.trim() || void 0 : void 0;
|
|
36679
|
+
}
|
|
36680
|
+
function readTurnSelection(selection, effortOptionId) {
|
|
36681
|
+
const requestedModelId = modelIdFromSelection(selection);
|
|
36682
|
+
const requestedEffort = modelSelectionStringOption2(selection, effortOptionId);
|
|
36683
|
+
return {
|
|
36684
|
+
...requestedModelId === void 0 ? {} : { requestedModelId },
|
|
36685
|
+
...requestedEffort === void 0 ? {} : { requestedEffort }
|
|
36686
|
+
};
|
|
36687
|
+
}
|
|
36688
|
+
function readEnvironment(value) {
|
|
36689
|
+
if (!Array.isArray(value)) return {};
|
|
36690
|
+
const env = {};
|
|
36691
|
+
for (const entry of value) {
|
|
36692
|
+
if (!isRecord7(entry)) continue;
|
|
36693
|
+
const name = readTrimmed(entry["name"]);
|
|
36694
|
+
if (name.length === 0) continue;
|
|
36695
|
+
env[name] = readString(entry["value"]);
|
|
36696
|
+
}
|
|
36697
|
+
return env;
|
|
36698
|
+
}
|
|
36699
|
+
function instanceSettings(config2) {
|
|
36700
|
+
if (!isRecord7(config2)) return {};
|
|
36701
|
+
return isRecord7(config2["config"]) ? config2["config"] : config2;
|
|
36702
|
+
}
|
|
36703
|
+
function readInstanceEnvelope(config2) {
|
|
36704
|
+
const envelope = isRecord7(config2) ? config2 : {};
|
|
36705
|
+
const settings = instanceSettings(config2);
|
|
36706
|
+
return {
|
|
36707
|
+
settings,
|
|
36708
|
+
settingOrEnvelope: (key) => readTrimmed(settings[key]) || readTrimmed(envelope[key]),
|
|
36709
|
+
environment: readEnvironment(envelope["environment"]),
|
|
36710
|
+
envelopeDriver: readTrimmed(envelope["driver"]) || void 0
|
|
36711
|
+
};
|
|
36712
|
+
}
|
|
36713
|
+
function readLaunchInstanceRecipe(config2, defaultLaunchArgs = "") {
|
|
36714
|
+
const envelope = readInstanceEnvelope(config2);
|
|
36715
|
+
return {
|
|
36716
|
+
binaryPath: readTrimmed(envelope.settings["binaryPath"]),
|
|
36717
|
+
launchArgs: readString(envelope.settings["launchArgs"]) || defaultLaunchArgs,
|
|
36718
|
+
homePath: envelope.settingOrEnvelope("homePath"),
|
|
36719
|
+
homeEnvVar: envelope.settingOrEnvelope("homeEnvVar"),
|
|
36720
|
+
environment: envelope.environment,
|
|
36721
|
+
envelopeDriver: envelope.envelopeDriver
|
|
36722
|
+
};
|
|
36723
|
+
}
|
|
36724
|
+
|
|
36166
36725
|
// src/dshBalance.ts
|
|
36167
36726
|
import * as NodeCrypto2 from "node:crypto";
|
|
36168
|
-
import * as
|
|
36169
|
-
import * as
|
|
36170
|
-
import * as
|
|
36171
|
-
import
|
|
36172
|
-
|
|
36173
|
-
|
|
36727
|
+
import * as NodeFS3 from "node:fs";
|
|
36728
|
+
import * as NodeOS4 from "node:os";
|
|
36729
|
+
import * as NodePath4 from "node:path";
|
|
36730
|
+
import "@ycodium-ai/plugin-api/usage";
|
|
36731
|
+
|
|
36732
|
+
// ../../packages/ycodium-credential-account/src/quotaRequest.ts
|
|
36733
|
+
import { parseRetryAfterMs } from "@ycodium-ai/plugin-api/usage";
|
|
36734
|
+
|
|
36735
|
+
// ../../packages/ycodium-credential-account/src/credentialAccount.ts
|
|
36736
|
+
var isRecord8 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36737
|
+
|
|
36738
|
+
// ../../packages/ycodium-credential-account/src/quotaRequest.ts
|
|
36739
|
+
async function requestQuotaJson(input2) {
|
|
36740
|
+
let response;
|
|
36741
|
+
try {
|
|
36742
|
+
response = await input2.fetch(input2.url, {
|
|
36743
|
+
headers: input2.headers,
|
|
36744
|
+
signal: AbortSignal.any([
|
|
36745
|
+
...input2.signal === void 0 ? [] : [input2.signal],
|
|
36746
|
+
AbortSignal.timeout(input2.timeoutMs)
|
|
36747
|
+
])
|
|
36748
|
+
});
|
|
36749
|
+
} catch {
|
|
36750
|
+
return { status: "unavailable", reason: "unreachable" };
|
|
36751
|
+
}
|
|
36752
|
+
if (response.status === 401 || response.status === 403) {
|
|
36753
|
+
return { status: "unavailable", reason: "authRejected" };
|
|
36754
|
+
}
|
|
36755
|
+
if (response.status === 429) {
|
|
36756
|
+
const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"), input2.now());
|
|
36757
|
+
return {
|
|
36758
|
+
status: "unavailable",
|
|
36759
|
+
reason: "rateLimited",
|
|
36760
|
+
...retryAfterMs === null ? {} : { retryAfterMs }
|
|
36761
|
+
};
|
|
36762
|
+
}
|
|
36763
|
+
if (!response.ok) return { status: "unavailable", reason: "unreachable" };
|
|
36764
|
+
let body;
|
|
36765
|
+
try {
|
|
36766
|
+
body = JSON.parse(await response.text());
|
|
36767
|
+
} catch {
|
|
36768
|
+
return { status: "unavailable", reason: "unreachable" };
|
|
36769
|
+
}
|
|
36770
|
+
if (!isRecord8(body)) return { status: "unavailable", reason: "unreachable" };
|
|
36771
|
+
return { body };
|
|
36772
|
+
}
|
|
36773
|
+
|
|
36774
|
+
// ../../packages/ycodium-credential-account/src/quotaJson.ts
|
|
36775
|
+
var asObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
36776
|
+
|
|
36777
|
+
// src/dshBalance.ts
|
|
36174
36778
|
var BALANCE_URL = "https://api.deepseek.com/user/balance";
|
|
36175
36779
|
var OFFICIAL_HOSTS = /* @__PURE__ */ new Set(["api.deepseek.com"]);
|
|
36176
36780
|
var API_KEY_NAME = "DEEPSEEK_API_KEY";
|
|
36177
36781
|
var BASE_URL_NAME = "DEEPSEEK_BASE_URL";
|
|
36178
36782
|
var TIMEOUT_MS = 1e4;
|
|
36179
|
-
var asObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
36180
|
-
var parseJson = (raw) => {
|
|
36181
|
-
try {
|
|
36182
|
-
return JSON.parse(raw);
|
|
36183
|
-
} catch {
|
|
36184
|
-
return null;
|
|
36185
|
-
}
|
|
36186
|
-
};
|
|
36187
36783
|
var readFile = (path) => {
|
|
36188
36784
|
try {
|
|
36189
|
-
return
|
|
36785
|
+
return NodeFS3.readFileSync(path, "utf8");
|
|
36190
36786
|
} catch {
|
|
36191
36787
|
return null;
|
|
36192
36788
|
}
|
|
@@ -36256,15 +36852,15 @@ var createDshUsage = (input2) => {
|
|
|
36256
36852
|
const now = input2.now ?? Date.now;
|
|
36257
36853
|
const processEnv = input2.processEnv ?? process.env;
|
|
36258
36854
|
const envValue = (name) => nonEmpty(input2.environment[name]) ?? nonEmpty(processEnv[name]);
|
|
36259
|
-
const dshHome = () => nonEmpty(input2.environment[input2.homeEnvVar]) ?? nonEmpty(input2.homePath) ?? nonEmpty(processEnv[input2.homeEnvVar]) ??
|
|
36855
|
+
const dshHome = () => nonEmpty(input2.environment[input2.homeEnvVar]) ?? nonEmpty(input2.homePath) ?? nonEmpty(processEnv[input2.homeEnvVar]) ?? NodePath4.join(NodeOS4.homedir(), ".dsh");
|
|
36260
36856
|
const resolveKey = () => {
|
|
36261
36857
|
const fromEnvironment = envValue(API_KEY_NAME);
|
|
36262
36858
|
if (fromEnvironment !== null) return fromEnvironment;
|
|
36263
36859
|
const home = dshHome();
|
|
36264
|
-
const yaml = readFile(
|
|
36860
|
+
const yaml = readFile(NodePath4.join(home, ".credentials.yaml"));
|
|
36265
36861
|
const fromYaml = yaml === null ? null : readCredentialsYamlRef(yaml, API_KEY_NAME);
|
|
36266
36862
|
if (fromYaml !== null) return fromYaml;
|
|
36267
|
-
const dotenv = readFile(
|
|
36863
|
+
const dotenv = readFile(NodePath4.join(home, ".env"));
|
|
36268
36864
|
return dotenv === null ? null : readDotenvValue(dotenv, API_KEY_NAME);
|
|
36269
36865
|
};
|
|
36270
36866
|
const readQuota = async (request) => {
|
|
@@ -36277,37 +36873,17 @@ var createDshUsage = (input2) => {
|
|
|
36277
36873
|
}
|
|
36278
36874
|
const key = resolveKey();
|
|
36279
36875
|
if (key === null) return { status: "unavailable", reason: "missingCredentials" };
|
|
36280
|
-
|
|
36281
|
-
|
|
36282
|
-
|
|
36283
|
-
|
|
36284
|
-
|
|
36285
|
-
|
|
36286
|
-
|
|
36287
|
-
|
|
36288
|
-
|
|
36289
|
-
}
|
|
36290
|
-
|
|
36291
|
-
}
|
|
36292
|
-
if (response.status === 401 || response.status === 403) {
|
|
36293
|
-
return { status: "unavailable", reason: "authRejected" };
|
|
36294
|
-
}
|
|
36295
|
-
if (response.status === 429) {
|
|
36296
|
-
const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"), now());
|
|
36297
|
-
return {
|
|
36298
|
-
status: "unavailable",
|
|
36299
|
-
reason: "rateLimited",
|
|
36300
|
-
...retryAfterMs === null ? {} : { retryAfterMs }
|
|
36301
|
-
};
|
|
36302
|
-
}
|
|
36303
|
-
if (!response.ok) return { status: "unavailable", reason: "unreachable" };
|
|
36304
|
-
let body;
|
|
36305
|
-
try {
|
|
36306
|
-
body = parseJson(await response.text());
|
|
36307
|
-
} catch {
|
|
36308
|
-
return { status: "unavailable", reason: "unreachable" };
|
|
36309
|
-
}
|
|
36310
|
-
if (asObject(body) === null || !Array.isArray(asObject(body)?.["balance_infos"])) {
|
|
36876
|
+
const answer = await requestQuotaJson({
|
|
36877
|
+
fetch: input2.fetch,
|
|
36878
|
+
url: BALANCE_URL,
|
|
36879
|
+
headers: { Authorization: `Bearer ${key}`, Accept: "application/json" },
|
|
36880
|
+
...request.signal === void 0 ? {} : { signal: request.signal },
|
|
36881
|
+
timeoutMs: TIMEOUT_MS,
|
|
36882
|
+
now
|
|
36883
|
+
});
|
|
36884
|
+
if (!("body" in answer)) return answer;
|
|
36885
|
+
const { body } = answer;
|
|
36886
|
+
if (!Array.isArray(body["balance_infos"])) {
|
|
36311
36887
|
return { status: "unavailable", reason: "unreachable" };
|
|
36312
36888
|
}
|
|
36313
36889
|
return {
|
|
@@ -36324,8 +36900,8 @@ var createDshUsage = (input2) => {
|
|
|
36324
36900
|
// src/dshOverlay.ts
|
|
36325
36901
|
import * as NodeCrypto3 from "node:crypto";
|
|
36326
36902
|
import * as NodeFSP from "node:fs/promises";
|
|
36327
|
-
import * as
|
|
36328
|
-
import * as
|
|
36903
|
+
import * as NodeOS5 from "node:os";
|
|
36904
|
+
import * as NodePath5 from "node:path";
|
|
36329
36905
|
import * as NodeURL2 from "node:url";
|
|
36330
36906
|
var import_yaml = __toESM(require_dist(), 1);
|
|
36331
36907
|
var OVERLAY_DIR = "ycodium-dsh-patches";
|
|
@@ -36335,8 +36911,8 @@ var SKILL_FILESYSTEM_ID = "skill-filesystem";
|
|
|
36335
36911
|
var PERMISSION_SYNC_ID = "ycodium-permission-sync";
|
|
36336
36912
|
var posixPath = (path) => path.replaceAll("\\", "/");
|
|
36337
36913
|
function permissionSyncModulePath() {
|
|
36338
|
-
const here =
|
|
36339
|
-
return
|
|
36914
|
+
const here = NodePath5.dirname(NodeURL2.fileURLToPath(import.meta.url));
|
|
36915
|
+
return NodePath5.resolve(here, "..", "assets", "permission-sync.mjs");
|
|
36340
36916
|
}
|
|
36341
36917
|
function dshOverlay(input2) {
|
|
36342
36918
|
const lines = [];
|
|
@@ -36360,8 +36936,8 @@ function dshOverlay(input2) {
|
|
|
36360
36936
|
}
|
|
36361
36937
|
async function ensureTempFile(tempRoot, extension, contents) {
|
|
36362
36938
|
const hash2 = NodeCrypto3.createHash("sha256").update(contents).digest("hex").slice(0, 16);
|
|
36363
|
-
const directory =
|
|
36364
|
-
const file2 =
|
|
36939
|
+
const directory = NodePath5.join(tempRoot, OVERLAY_DIR);
|
|
36940
|
+
const file2 = NodePath5.join(directory, `${hash2}${extension}`);
|
|
36365
36941
|
const present = await NodeFSP.readFile(file2, "utf8").then(
|
|
36366
36942
|
(existing) => existing === contents,
|
|
36367
36943
|
() => false
|
|
@@ -36377,10 +36953,10 @@ async function ensureTempFile(tempRoot, extension, contents) {
|
|
|
36377
36953
|
});
|
|
36378
36954
|
return file2;
|
|
36379
36955
|
}
|
|
36380
|
-
async function ensureDshOverlay(input2, tempRoot =
|
|
36956
|
+
async function ensureDshOverlay(input2, tempRoot = NodeOS5.tmpdir()) {
|
|
36381
36957
|
return ensureTempFile(tempRoot, ".yml", dshOverlay(input2));
|
|
36382
36958
|
}
|
|
36383
|
-
async function ensurePermissionSyncCopy(tempRoot =
|
|
36959
|
+
async function ensurePermissionSyncCopy(tempRoot = NodeOS5.tmpdir()) {
|
|
36384
36960
|
const source = await NodeFSP.readFile(permissionSyncModulePath(), "utf8").catch(() => void 0);
|
|
36385
36961
|
return source === void 0 ? void 0 : ensureTempFile(tempRoot, ".mjs", source);
|
|
36386
36962
|
}
|
|
@@ -36452,158 +37028,105 @@ async function dshOverlayPatchArgs(input2) {
|
|
|
36452
37028
|
if (skillsDir === void 0 && !expectPermissionSync) return [];
|
|
36453
37029
|
const overlay = await ensureDshOverlay(
|
|
36454
37030
|
{
|
|
36455
|
-
...skillsDir === void 0 ? {} : { skillsDir },
|
|
36456
|
-
...expectPermissionSync ? { permissionSyncModule: modulePath } : {}
|
|
36457
|
-
},
|
|
36458
|
-
input2.tempRoot
|
|
36459
|
-
);
|
|
36460
|
-
if (skillsDir === void 0) return ["--patch", overlay];
|
|
36461
|
-
const key = `${launch.cwd}\0${overlay}\0${expectPermissionSync ? "sync" : "no-sync"}`;
|
|
36462
|
-
try {
|
|
36463
|
-
let check2 = input2.verified.get(key);
|
|
36464
|
-
if (check2 === void 0) {
|
|
36465
|
-
check2 = overlayTakesEffect({ host, launch, overlay, skillsDir, expectPermissionSync });
|
|
36466
|
-
input2.verified.set(key, check2);
|
|
36467
|
-
}
|
|
36468
|
-
if (await check2) return ["--patch", overlay];
|
|
36469
|
-
host.log.warn("dsh did not take the session skills overlay; using dsh's own skills");
|
|
36470
|
-
} catch (error62) {
|
|
36471
|
-
input2.verified.delete(key);
|
|
36472
|
-
host.log.warn("dsh session skills verification failed; using dsh's own skills", {
|
|
36473
|
-
error: error62 instanceof Error ? error62.message : String(error62)
|
|
36474
|
-
});
|
|
36475
|
-
}
|
|
36476
|
-
return modulePath === void 0 ? [] : ["--patch", await ensureDshOverlay({ permissionSyncModule: modulePath }, input2.tempRoot)];
|
|
36477
|
-
} catch (error62) {
|
|
36478
|
-
input2.onPermissionSyncUnavailable?.();
|
|
36479
|
-
input2.verified.clear();
|
|
36480
|
-
host.log.warn(
|
|
36481
|
-
"dsh session overlay failed; skills and permission switching stay on dsh's own defaults",
|
|
36482
|
-
{
|
|
36483
|
-
error: error62 instanceof Error ? error62.message : String(error62)
|
|
36484
|
-
}
|
|
36485
|
-
);
|
|
36486
|
-
}
|
|
36487
|
-
return [];
|
|
36488
|
-
}
|
|
36489
|
-
|
|
36490
|
-
// src/config.ts
|
|
36491
|
-
var DSH_DEFAULT_LAUNCH_ARGS = "--profile acp";
|
|
36492
|
-
function isRecord6(value) {
|
|
36493
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36494
|
-
}
|
|
36495
|
-
function readString(value) {
|
|
36496
|
-
return typeof value === "string" ? value : "";
|
|
36497
|
-
}
|
|
36498
|
-
function readTrimmed(value) {
|
|
36499
|
-
return readString(value).trim();
|
|
36500
|
-
}
|
|
36501
|
-
function readEnvironment(value) {
|
|
36502
|
-
if (!Array.isArray(value)) return {};
|
|
36503
|
-
const env = {};
|
|
36504
|
-
for (const entry of value) {
|
|
36505
|
-
if (!isRecord6(entry)) continue;
|
|
36506
|
-
const name = readTrimmed(entry["name"]);
|
|
36507
|
-
if (name.length === 0) continue;
|
|
36508
|
-
env[name] = readString(entry["value"]);
|
|
36509
|
-
}
|
|
36510
|
-
return env;
|
|
36511
|
-
}
|
|
36512
|
-
function parseDshInstanceConfig(config2) {
|
|
36513
|
-
if (!isRecord6(config2)) {
|
|
36514
|
-
return {
|
|
36515
|
-
binaryPath: "",
|
|
36516
|
-
launchArgs: DSH_DEFAULT_LAUNCH_ARGS,
|
|
36517
|
-
homePath: "",
|
|
36518
|
-
homeEnvVar: "",
|
|
36519
|
-
environment: {},
|
|
36520
|
-
envelopeDriver: void 0
|
|
36521
|
-
};
|
|
36522
|
-
}
|
|
36523
|
-
const nested = isRecord6(config2["config"]) ? config2["config"] : void 0;
|
|
36524
|
-
const settings = nested ?? config2;
|
|
36525
|
-
return {
|
|
36526
|
-
binaryPath: readTrimmed(settings["binaryPath"]),
|
|
36527
|
-
launchArgs: readString(settings["launchArgs"]) || DSH_DEFAULT_LAUNCH_ARGS,
|
|
36528
|
-
homePath: readTrimmed(settings["homePath"]) || readTrimmed(config2["homePath"]),
|
|
36529
|
-
homeEnvVar: readTrimmed(settings["homeEnvVar"]) || readTrimmed(config2["homeEnvVar"]),
|
|
36530
|
-
environment: readEnvironment(config2["environment"]),
|
|
36531
|
-
envelopeDriver: readTrimmed(config2["driver"]) || void 0
|
|
36532
|
-
};
|
|
36533
|
-
}
|
|
36534
|
-
function tokenizeLaunchArgs(value) {
|
|
36535
|
-
const input2 = value.trim();
|
|
36536
|
-
if (!input2) return [];
|
|
36537
|
-
const tokens = [];
|
|
36538
|
-
let current = "";
|
|
36539
|
-
let quote;
|
|
36540
|
-
let quoted = false;
|
|
36541
|
-
for (let index = 0; index < input2.length; index++) {
|
|
36542
|
-
const char = input2[index];
|
|
36543
|
-
if (char === void 0) continue;
|
|
36544
|
-
if (quote) {
|
|
36545
|
-
if (char === quote) {
|
|
36546
|
-
quote = void 0;
|
|
36547
|
-
quoted = true;
|
|
36548
|
-
} else if (char === "\\" && quote === '"') {
|
|
36549
|
-
const next = input2[index + 1];
|
|
36550
|
-
if (next !== void 0 && ['"', "\\", "$", "`"].includes(next)) {
|
|
36551
|
-
current += next;
|
|
36552
|
-
index++;
|
|
36553
|
-
} else {
|
|
36554
|
-
current += char;
|
|
36555
|
-
}
|
|
36556
|
-
} else {
|
|
36557
|
-
current += char;
|
|
37031
|
+
...skillsDir === void 0 ? {} : { skillsDir },
|
|
37032
|
+
...expectPermissionSync ? { permissionSyncModule: modulePath } : {}
|
|
37033
|
+
},
|
|
37034
|
+
input2.tempRoot
|
|
37035
|
+
);
|
|
37036
|
+
if (skillsDir === void 0) return ["--patch", overlay];
|
|
37037
|
+
const key = `${launch.cwd}\0${overlay}\0${expectPermissionSync ? "sync" : "no-sync"}`;
|
|
37038
|
+
try {
|
|
37039
|
+
let check2 = input2.verified.get(key);
|
|
37040
|
+
if (check2 === void 0) {
|
|
37041
|
+
check2 = overlayTakesEffect({ host, launch, overlay, skillsDir, expectPermissionSync });
|
|
37042
|
+
input2.verified.set(key, check2);
|
|
36558
37043
|
}
|
|
36559
|
-
|
|
37044
|
+
if (await check2) return ["--patch", overlay];
|
|
37045
|
+
host.log.warn("dsh did not take the session skills overlay; using dsh's own skills");
|
|
37046
|
+
} catch (error62) {
|
|
37047
|
+
input2.verified.delete(key);
|
|
37048
|
+
host.log.warn("dsh session skills verification failed; using dsh's own skills", {
|
|
37049
|
+
error: error62 instanceof Error ? error62.message : String(error62)
|
|
37050
|
+
});
|
|
36560
37051
|
}
|
|
36561
|
-
|
|
36562
|
-
|
|
36563
|
-
|
|
36564
|
-
|
|
36565
|
-
|
|
36566
|
-
|
|
36567
|
-
|
|
36568
|
-
|
|
36569
|
-
}
|
|
36570
|
-
} else if (char === "\\") {
|
|
36571
|
-
const next = input2[index + 1];
|
|
36572
|
-
if (next !== void 0 && /\s/.test(next)) {
|
|
36573
|
-
current += next;
|
|
36574
|
-
index++;
|
|
36575
|
-
} else {
|
|
36576
|
-
current += char;
|
|
37052
|
+
return modulePath === void 0 ? [] : ["--patch", await ensureDshOverlay({ permissionSyncModule: modulePath }, input2.tempRoot)];
|
|
37053
|
+
} catch (error62) {
|
|
37054
|
+
input2.onPermissionSyncUnavailable?.();
|
|
37055
|
+
input2.verified.clear();
|
|
37056
|
+
host.log.warn(
|
|
37057
|
+
"dsh session overlay failed; skills and permission switching stay on dsh's own defaults",
|
|
37058
|
+
{
|
|
37059
|
+
error: error62 instanceof Error ? error62.message : String(error62)
|
|
36577
37060
|
}
|
|
36578
|
-
|
|
36579
|
-
current += char;
|
|
36580
|
-
}
|
|
37061
|
+
);
|
|
36581
37062
|
}
|
|
36582
|
-
|
|
36583
|
-
|
|
37063
|
+
return [];
|
|
37064
|
+
}
|
|
37065
|
+
|
|
37066
|
+
// src/config.ts
|
|
37067
|
+
var DSH_DEFAULT_LAUNCH_ARGS = "--profile acp";
|
|
37068
|
+
function parseDshInstanceConfig(config2) {
|
|
37069
|
+
return readLaunchInstanceRecipe(config2, DSH_DEFAULT_LAUNCH_ARGS);
|
|
36584
37070
|
}
|
|
36585
37071
|
|
|
36586
37072
|
// src/probeModels.ts
|
|
37073
|
+
import * as NodeOS7 from "node:os";
|
|
37074
|
+
import * as NodePath7 from "node:path";
|
|
36587
37075
|
import {
|
|
36588
|
-
|
|
36589
|
-
|
|
36590
|
-
|
|
36591
|
-
|
|
36592
|
-
import * as NodeOS5 from "node:os";
|
|
36593
|
-
import * as NodePath6 from "node:path";
|
|
37076
|
+
REASONING_OPTION_LABEL
|
|
37077
|
+
} from "@ycodium-ai/plugin-api/executor";
|
|
37078
|
+
|
|
37079
|
+
// ../../packages/ycodium-instance-config/src/probeProcess.ts
|
|
36594
37080
|
import {
|
|
36595
37081
|
describeExecutorSpawnFailure,
|
|
36596
37082
|
ExecutorSpawnAbortedError,
|
|
36597
|
-
ExecutorSpawnRefusedError
|
|
36598
|
-
raceAbort,
|
|
36599
|
-
REASONING_OPTION_LABEL
|
|
37083
|
+
ExecutorSpawnRefusedError
|
|
36600
37084
|
} from "@ycodium-ai/plugin-api/executor";
|
|
36601
|
-
import {
|
|
37085
|
+
import {
|
|
37086
|
+
OperationCleanupError,
|
|
37087
|
+
runProcessOperation
|
|
37088
|
+
} from "@ycodium-ai/plugin-api/process-operation";
|
|
37089
|
+
async function spawnProbeProcess(host, launch) {
|
|
37090
|
+
try {
|
|
37091
|
+
const handle = await host.process.spawn({
|
|
37092
|
+
program: launch.program,
|
|
37093
|
+
args: launch.args,
|
|
37094
|
+
cwd: launch.cwd,
|
|
37095
|
+
owner: { bindingId: host.bindingId },
|
|
37096
|
+
...Object.keys(launch.env).length > 0 ? { env: launch.env } : {},
|
|
37097
|
+
...launch.signal === void 0 ? {} : { signal: launch.signal }
|
|
37098
|
+
});
|
|
37099
|
+
return { kind: "spawned", handle };
|
|
37100
|
+
} catch (error62) {
|
|
37101
|
+
if (error62 instanceof ExecutorSpawnRefusedError || error62 instanceof ExecutorSpawnAbortedError) {
|
|
37102
|
+
throw error62;
|
|
37103
|
+
}
|
|
37104
|
+
return { kind: "not-started", ...describeExecutorSpawnFailure(error62) };
|
|
37105
|
+
}
|
|
37106
|
+
}
|
|
37107
|
+
async function readCliVersionCommand(host, input2) {
|
|
37108
|
+
try {
|
|
37109
|
+
const run = await runProcessOperation(host, {
|
|
37110
|
+
program: input2.program,
|
|
37111
|
+
args: ["--version"],
|
|
37112
|
+
owner: { bindingId: host.bindingId },
|
|
37113
|
+
...Object.keys(input2.env).length > 0 ? { env: input2.env } : {},
|
|
37114
|
+
signal: input2.signal,
|
|
37115
|
+
timeoutMs: input2.timeoutMs,
|
|
37116
|
+
maxOutputBytes: 64 * 1024
|
|
37117
|
+
});
|
|
37118
|
+
if (run.exitCode !== 0) return null;
|
|
37119
|
+
return input2.parse(run.stdout) ?? input2.parse(run.stderr);
|
|
37120
|
+
} catch (error62) {
|
|
37121
|
+
if (error62 instanceof OperationCleanupError || input2.signal?.aborted) throw error62;
|
|
37122
|
+
return null;
|
|
37123
|
+
}
|
|
37124
|
+
}
|
|
36602
37125
|
|
|
36603
37126
|
// src/spawnEnv.ts
|
|
36604
|
-
import * as
|
|
36605
|
-
import * as
|
|
36606
|
-
import { mergeLaunchEnv } from "@ycodium-ai/plugin-api/executor";
|
|
37127
|
+
import * as NodeOS6 from "node:os";
|
|
37128
|
+
import * as NodePath6 from "node:path";
|
|
37129
|
+
import { mergeLaunchEnv as mergeLaunchEnv2 } from "@ycodium-ai/plugin-api/executor";
|
|
36607
37130
|
|
|
36608
37131
|
// src/permission.ts
|
|
36609
37132
|
var DSH_NATIVE_MODES = [
|
|
@@ -36644,26 +37167,19 @@ function dshPermissionEnv(nativeModeId) {
|
|
|
36644
37167
|
}
|
|
36645
37168
|
|
|
36646
37169
|
// src/spawnEnv.ts
|
|
36647
|
-
function expandHomePath(value) {
|
|
36648
|
-
if (value === "~") return NodeOS4.homedir();
|
|
36649
|
-
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
36650
|
-
return NodePath5.join(NodeOS4.homedir(), value.slice(2));
|
|
36651
|
-
}
|
|
36652
|
-
return value;
|
|
36653
|
-
}
|
|
36654
37170
|
function resolveHomePath(value) {
|
|
36655
37171
|
const trimmed = value.trim();
|
|
36656
37172
|
if (trimmed.length === 0) return "";
|
|
36657
|
-
return
|
|
37173
|
+
return NodePath6.resolve(expandHomePath(trimmed));
|
|
36658
37174
|
}
|
|
36659
37175
|
function dshContinuationKey(homePath) {
|
|
36660
37176
|
const resolved = resolveHomePath(homePath);
|
|
36661
|
-
return `dsh:home:${resolved.length > 0 ? resolved :
|
|
37177
|
+
return `dsh:home:${resolved.length > 0 ? resolved : NodePath6.join(NodeOS6.homedir(), ".dsh")}`;
|
|
36662
37178
|
}
|
|
36663
37179
|
function buildSpawnEnv(recipe, resolvedHomePath, nativeModeId) {
|
|
36664
37180
|
const homeEnvVar = recipe.homeEnvVar.trim() || DSH_CARD.homeEnvVar;
|
|
36665
37181
|
const homeInjection = resolvedHomePath.length > 0 && homeEnvVar.length > 0 ? { [homeEnvVar]: resolvedHomePath } : {};
|
|
36666
|
-
return
|
|
37182
|
+
return mergeLaunchEnv2({
|
|
36667
37183
|
accountHome: homeInjection,
|
|
36668
37184
|
instanceTable: recipe.environment,
|
|
36669
37185
|
// 用户挑的档压过实例表:实例表里那一栏是这台机器的默认,输入区那一下是这一轮的
|
|
@@ -36676,16 +37192,13 @@ function buildSpawnEnv(recipe, resolvedHomePath, nativeModeId) {
|
|
|
36676
37192
|
var PROBE_REQUEST_TIMEOUT_MS = 15e3;
|
|
36677
37193
|
function dshProbeSessionCwd(instanceId) {
|
|
36678
37194
|
const safe = instanceId.trim().replace(/[^A-Za-z0-9._-]/g, "-") || "instance";
|
|
36679
|
-
return
|
|
37195
|
+
return NodePath7.join(NodeOS7.tmpdir(), `ycodium-dsh-probe-${safe}`);
|
|
36680
37196
|
}
|
|
36681
|
-
function
|
|
37197
|
+
function isRecord9(value) {
|
|
36682
37198
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36683
37199
|
}
|
|
36684
|
-
function asString3(value) {
|
|
36685
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
36686
|
-
}
|
|
36687
37200
|
function dshProbeModels(setup) {
|
|
36688
|
-
if (!
|
|
37201
|
+
if (!isRecord9(setup)) return void 0;
|
|
36689
37202
|
const rawOptions = setup["configOptions"];
|
|
36690
37203
|
const choices = acpModelChoicesFromConfigOptions(rawOptions);
|
|
36691
37204
|
if (choices === void 0) return void 0;
|
|
@@ -36694,118 +37207,48 @@ function dshProbeModels(setup) {
|
|
|
36694
37207
|
...choice.name === void 0 ? {} : { name: choice.name },
|
|
36695
37208
|
...choice.isDefault === true ? { isDefault: true } : {}
|
|
36696
37209
|
}));
|
|
36697
|
-
const
|
|
36698
|
-
|
|
36699
|
-
|
|
36700
|
-
|
|
36701
|
-
}
|
|
36702
|
-
const effort = findAcpEffortConfig(rawOptions);
|
|
36703
|
-
if (effort === void 0) return models;
|
|
36704
|
-
const capabilities = {
|
|
36705
|
-
optionDescriptors: [
|
|
36706
|
-
{
|
|
36707
|
-
id: DSH_EFFORT_OPTION_ID,
|
|
36708
|
-
label: effort.label || REASONING_OPTION_LABEL,
|
|
36709
|
-
type: "select",
|
|
36710
|
-
options: effort.choices.map((choice) => ({
|
|
36711
|
-
id: choice.value,
|
|
36712
|
-
label: choice.label,
|
|
36713
|
-
...choice.description === void 0 ? {} : { description: choice.description },
|
|
36714
|
-
...choice.isDefault === true ? { isDefault: true } : {}
|
|
36715
|
-
}))
|
|
36716
|
-
}
|
|
36717
|
-
]
|
|
36718
|
-
};
|
|
36719
|
-
return models.map((model) => ({ ...model, capabilities }));
|
|
37210
|
+
const capabilities = acpEffortCapabilities(rawOptions, {
|
|
37211
|
+
id: DSH_EFFORT_OPTION_ID,
|
|
37212
|
+
fallbackLabel: REASONING_OPTION_LABEL
|
|
37213
|
+
});
|
|
37214
|
+
return capabilities === "unknown" ? models : models.map((model) => ({ ...model, capabilities }));
|
|
36720
37215
|
}
|
|
36721
37216
|
var DSH_EFFORT_OPTION_ID = "reasoning";
|
|
36722
|
-
function findProbeSessionId(listed, probeCwd) {
|
|
36723
|
-
if (!isRecord7(listed) || !Array.isArray(listed["sessions"])) return void 0;
|
|
36724
|
-
for (const entry of listed["sessions"]) {
|
|
36725
|
-
if (!isRecord7(entry)) continue;
|
|
36726
|
-
if (asString3(entry["cwd"]) !== probeCwd) continue;
|
|
36727
|
-
const sessionId = asString3(entry["sessionId"]);
|
|
36728
|
-
if (sessionId !== void 0) return sessionId;
|
|
36729
|
-
}
|
|
36730
|
-
return void 0;
|
|
36731
|
-
}
|
|
36732
|
-
async function probeSessionSetup(handshake, probeCwd) {
|
|
36733
|
-
const listed = await handshake.request("session/list", {}).catch(() => void 0);
|
|
36734
|
-
const reusable = findProbeSessionId(listed, probeCwd);
|
|
36735
|
-
if (reusable !== void 0) {
|
|
36736
|
-
const resumed = await handshake.request("session/resume", { sessionId: reusable, cwd: probeCwd, mcpServers: [] }).catch(() => void 0);
|
|
36737
|
-
if (resumed !== void 0) return resumed;
|
|
36738
|
-
}
|
|
36739
|
-
return handshake.request("session/new", { cwd: probeCwd, mcpServers: [] });
|
|
36740
|
-
}
|
|
36741
|
-
var failureDetail = (error62) => (error62 instanceof Error ? error62.message : String(error62)).trim() || void 0;
|
|
36742
37217
|
async function probeDshModels(input2) {
|
|
36743
37218
|
const { recipe, host } = input2;
|
|
36744
37219
|
const probeCwd = dshProbeSessionCwd(host.instanceId);
|
|
36745
|
-
try {
|
|
36746
|
-
NodeFS3.mkdirSync(probeCwd, { recursive: true });
|
|
36747
|
-
} catch (error62) {
|
|
36748
|
-
return { kind: "failed", detail: failureDetail(error62) };
|
|
36749
|
-
}
|
|
36750
37220
|
const env = buildSpawnEnv(recipe, resolveHomePath(recipe.homePath));
|
|
36751
|
-
|
|
36752
|
-
|
|
36753
|
-
|
|
37221
|
+
const attempt = await withAcpProbeProcess({
|
|
37222
|
+
cwd: probeCwd,
|
|
37223
|
+
signal: input2.signal,
|
|
37224
|
+
clientInfo: DSH_CLIENT_INFO,
|
|
37225
|
+
requestTimeoutMs: PROBE_REQUEST_TIMEOUT_MS,
|
|
37226
|
+
spawn: (cwd) => spawnProbeProcess(host, {
|
|
36754
37227
|
program: recipe.binaryPath,
|
|
36755
|
-
args:
|
|
36756
|
-
cwd
|
|
36757
|
-
|
|
36758
|
-
...Object.keys(env).length > 0 ? { env } : {},
|
|
37228
|
+
args: tokenizeShellWords(recipe.launchArgs),
|
|
37229
|
+
cwd,
|
|
37230
|
+
env,
|
|
36759
37231
|
...input2.signal === void 0 ? {} : { signal: input2.signal }
|
|
36760
|
-
})
|
|
36761
|
-
|
|
36762
|
-
|
|
36763
|
-
|
|
36764
|
-
|
|
36765
|
-
|
|
36766
|
-
|
|
36767
|
-
|
|
36768
|
-
|
|
36769
|
-
const { readable, writable } = nodeStreamsFromHandle(handle);
|
|
36770
|
-
handshake = await raceAbort(
|
|
36771
|
-
openAcpProbeHandshake({
|
|
36772
|
-
readable,
|
|
36773
|
-
writable,
|
|
36774
|
-
clientInfo: DSH_CLIENT_INFO,
|
|
36775
|
-
requestTimeoutMs: PROBE_REQUEST_TIMEOUT_MS
|
|
36776
|
-
}),
|
|
36777
|
-
input2.signal
|
|
36778
|
-
);
|
|
36779
|
-
return {
|
|
36780
|
-
kind: "answered",
|
|
36781
|
-
models: dshProbeModels(await probeSessionSetup(handshake, probeCwd))
|
|
36782
|
-
};
|
|
36783
|
-
} catch (error62) {
|
|
36784
|
-
return { kind: "failed", detail: failureDetail(error62) };
|
|
36785
|
-
} finally {
|
|
36786
|
-
await handshake?.close().catch(() => void 0);
|
|
36787
|
-
await handle.kill("SIGTERM").catch(() => void 0);
|
|
36788
|
-
}
|
|
37232
|
+
}),
|
|
37233
|
+
run: (handshake) => reuseAcpProbeSession(handshake, probeCwd).then(dshProbeModels)
|
|
37234
|
+
});
|
|
37235
|
+
if (attempt.kind === "not-started") return attempt;
|
|
37236
|
+
if (attempt.kind === "ok") return { kind: "answered", models: attempt.value };
|
|
37237
|
+
return {
|
|
37238
|
+
kind: "failed",
|
|
37239
|
+
detail: attempt.kind === "mkdir-failed" ? attempt.detail : acpProbeFailureDetail(attempt.error)
|
|
37240
|
+
};
|
|
36789
37241
|
}
|
|
36790
37242
|
async function probeDshVersion(input2) {
|
|
36791
37243
|
const { recipe, host, signal } = input2;
|
|
36792
37244
|
const env = buildSpawnEnv(recipe, resolveHomePath(recipe.homePath));
|
|
36793
|
-
|
|
36794
|
-
|
|
36795
|
-
|
|
36796
|
-
|
|
36797
|
-
|
|
36798
|
-
|
|
36799
|
-
|
|
36800
|
-
timeoutMs: PROBE_REQUEST_TIMEOUT_MS,
|
|
36801
|
-
maxOutputBytes: 64 * 1024
|
|
36802
|
-
});
|
|
36803
|
-
if (run.exitCode !== 0) return null;
|
|
36804
|
-
return parseCliVersion(run.stdout) ?? parseCliVersion(run.stderr);
|
|
36805
|
-
} catch (error62) {
|
|
36806
|
-
if (error62 instanceof OperationCleanupError || signal?.aborted) throw error62;
|
|
36807
|
-
return null;
|
|
36808
|
-
}
|
|
37245
|
+
return readCliVersionCommand(host, {
|
|
37246
|
+
program: recipe.binaryPath,
|
|
37247
|
+
env,
|
|
37248
|
+
signal,
|
|
37249
|
+
timeoutMs: PROBE_REQUEST_TIMEOUT_MS,
|
|
37250
|
+
parse: parseCliVersion
|
|
37251
|
+
});
|
|
36809
37252
|
}
|
|
36810
37253
|
|
|
36811
37254
|
// src/openCommands.ts
|
|
@@ -36971,9 +37414,9 @@ var TURN_ENDED_DESCRIPTION = "Turn ended. Individual agent status is unavailable
|
|
|
36971
37414
|
var TURN_INTERRUPTED_DESCRIPTION = "Turn interrupted. The subagent may still be running in the background. Individual agent status is unavailable.";
|
|
36972
37415
|
var FIELD_LIMIT = 200;
|
|
36973
37416
|
var SUBAGENT_TITLES = /* @__PURE__ */ new Set(["subagent", "subagent_fork"]);
|
|
36974
|
-
var
|
|
37417
|
+
var isRecord10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36975
37418
|
function field(rawInput, key) {
|
|
36976
|
-
if (!
|
|
37419
|
+
if (!isRecord10(rawInput)) return void 0;
|
|
36977
37420
|
const value = rawInput[key];
|
|
36978
37421
|
if (typeof value !== "string") return void 0;
|
|
36979
37422
|
const text = value.trim();
|
|
@@ -37098,39 +37541,22 @@ function createPermissionSyncHealth(input2) {
|
|
|
37098
37541
|
|
|
37099
37542
|
// src/dshInstance.ts
|
|
37100
37543
|
var RESUME_SCHEMA_VERSION = 1;
|
|
37101
|
-
|
|
37102
|
-
setImmediate(resolve4);
|
|
37103
|
-
});
|
|
37104
|
-
function modelIdFromSelection(selection) {
|
|
37105
|
-
if (typeof selection !== "object" || selection === null || Array.isArray(selection)) {
|
|
37106
|
-
return void 0;
|
|
37107
|
-
}
|
|
37108
|
-
const model = selection["model"];
|
|
37109
|
-
return typeof model === "string" ? model.trim() || void 0 : void 0;
|
|
37110
|
-
}
|
|
37111
|
-
function nowIso() {
|
|
37544
|
+
function nowIso3() {
|
|
37112
37545
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
37113
37546
|
}
|
|
37114
|
-
async function stopBooked(booked, processExit) {
|
|
37115
|
-
await cleanupAcpSession({
|
|
37116
|
-
executor: booked.executor,
|
|
37117
|
-
stopProcess: () => booked.handle.kill("SIGTERM"),
|
|
37118
|
-
forwarding: booked.forwarding,
|
|
37119
|
-
processExit
|
|
37120
|
-
});
|
|
37121
|
-
}
|
|
37122
37547
|
var createDshInstance = (config2, host) => {
|
|
37123
37548
|
const recipe = parseDshInstanceConfig(config2);
|
|
37124
|
-
const threads = /* @__PURE__ */ new Map();
|
|
37125
37549
|
const overlayChecks = /* @__PURE__ */ new Map();
|
|
37126
37550
|
let disposed = false;
|
|
37127
|
-
const
|
|
37551
|
+
const table = createAcpThreadTable(host.log);
|
|
37552
|
+
const { threads, requireThread, registerSession, stopSession, disposeOnce } = table;
|
|
37553
|
+
const threadOps = createAcpThreadOperations({
|
|
37128
37554
|
threads,
|
|
37129
|
-
|
|
37130
|
-
|
|
37131
|
-
|
|
37132
|
-
|
|
37133
|
-
|
|
37555
|
+
requireThread,
|
|
37556
|
+
isDisposed: () => disposed,
|
|
37557
|
+
turnSelection: (selection) => readTurnSelection(selection, DSH_EFFORT_OPTION_ID),
|
|
37558
|
+
log: host.log,
|
|
37559
|
+
beforeSendTurn: (booked) => booked.permissionSync.beforeSendTurn()
|
|
37134
37560
|
});
|
|
37135
37561
|
const instance = {
|
|
37136
37562
|
probe: async (signal) => {
|
|
@@ -37184,13 +37610,8 @@ var createDshInstance = (config2, host) => {
|
|
|
37184
37610
|
}
|
|
37185
37611
|
const cwd = input2.cwd ?? host.workspacePath(input2.threadId);
|
|
37186
37612
|
if (cwd.trim() === "") throw new Error("workspace path missing");
|
|
37187
|
-
|
|
37188
|
-
|
|
37189
|
-
await stopSession(input2.threadId, existing);
|
|
37190
|
-
if (disposed) throw new Error("instance disposed");
|
|
37191
|
-
throwIfStartAborted(signal);
|
|
37192
|
-
}
|
|
37193
|
-
const resume = input2.discardResumeCursor === true ? void 0 : parseAcpResumeCursor(input2.resumeCursor, RESUME_SCHEMA_VERSION);
|
|
37613
|
+
await stopExistingAcpThread(table, input2.threadId, () => disposed, signal);
|
|
37614
|
+
const resume = acpResumeFrom(input2, RESUME_SCHEMA_VERSION);
|
|
37194
37615
|
const env = buildSpawnEnv(recipe, resolveHomePath(recipe.homePath), input2.nativeModeId);
|
|
37195
37616
|
const permissionSync = createPermissionSyncHealth({
|
|
37196
37617
|
sessionId: resume?.sessionId,
|
|
@@ -37203,7 +37624,7 @@ var createDshInstance = (config2, host) => {
|
|
|
37203
37624
|
provider: DSH_DRIVER_KIND,
|
|
37204
37625
|
providerInstanceId: host.instanceId,
|
|
37205
37626
|
threadId: input2.threadId,
|
|
37206
|
-
createdAt:
|
|
37627
|
+
createdAt: nowIso3(),
|
|
37207
37628
|
payload: {
|
|
37208
37629
|
code: "permission-mode-not-applied",
|
|
37209
37630
|
message: "The access mode change did not apply to this thread. It will keep its previous access mode. Start a new thread to use the new access mode."
|
|
@@ -37213,7 +37634,7 @@ var createDshInstance = (config2, host) => {
|
|
|
37213
37634
|
});
|
|
37214
37635
|
const launch = {
|
|
37215
37636
|
program: recipe.binaryPath,
|
|
37216
|
-
args:
|
|
37637
|
+
args: tokenizeShellWords(recipe.launchArgs),
|
|
37217
37638
|
cwd,
|
|
37218
37639
|
env
|
|
37219
37640
|
};
|
|
@@ -37233,7 +37654,7 @@ var createDshInstance = (config2, host) => {
|
|
|
37233
37654
|
closeStdin: () => handle.closeStdin()
|
|
37234
37655
|
});
|
|
37235
37656
|
const requestedModelId = modelIdFromSelection(input2.modelSelection);
|
|
37236
|
-
const requestedEffort =
|
|
37657
|
+
const requestedEffort = modelSelectionStringOption3(
|
|
37237
37658
|
input2.modelSelection,
|
|
37238
37659
|
DSH_EFFORT_OPTION_ID
|
|
37239
37660
|
);
|
|
@@ -37265,107 +37686,42 @@ var createDshInstance = (config2, host) => {
|
|
|
37265
37686
|
},
|
|
37266
37687
|
...requestedModelId === void 0 ? {} : { requestedModelId },
|
|
37267
37688
|
...requestedEffort === void 0 ? {} : { requestedEffort },
|
|
37268
|
-
//
|
|
37269
|
-
//
|
|
37270
|
-
|
|
37271
|
-
|
|
37272
|
-
|
|
37689
|
+
// 内置编排在前、插件中心配的在后(缺了就没有 `mcp__ycodium__*`);http / sse 由执行器按握手再筛。
|
|
37690
|
+
// 空数组也传。
|
|
37691
|
+
...acpLaunchMcpFields({
|
|
37692
|
+
mcpServers: input2.mcpServers,
|
|
37693
|
+
resumeSessionId: resume?.sessionId
|
|
37694
|
+
})
|
|
37273
37695
|
});
|
|
37274
|
-
|
|
37275
|
-
|
|
37276
|
-
|
|
37277
|
-
|
|
37278
|
-
|
|
37279
|
-
|
|
37280
|
-
|
|
37281
|
-
|
|
37282
|
-
|
|
37283
|
-
|
|
37284
|
-
|
|
37285
|
-
|
|
37286
|
-
sessionId: started.sessionId
|
|
37287
|
-
};
|
|
37288
|
-
const session = {
|
|
37696
|
+
return openAcpThreadSession({
|
|
37697
|
+
registerSession,
|
|
37698
|
+
threadId: input2.threadId,
|
|
37699
|
+
executor,
|
|
37700
|
+
handle,
|
|
37701
|
+
signal,
|
|
37702
|
+
log: host.log,
|
|
37703
|
+
emit: (event) => input2.events.emit(event),
|
|
37704
|
+
beforeSession: () => {
|
|
37705
|
+
if (resume !== void 0) permissionSync.sessionReady();
|
|
37706
|
+
},
|
|
37707
|
+
session: {
|
|
37289
37708
|
provider: DSH_DRIVER_KIND,
|
|
37290
37709
|
providerInstanceId: host.instanceId,
|
|
37291
|
-
status: "idle",
|
|
37292
37710
|
runtimeMode: input2.runtimeMode,
|
|
37293
|
-
|
|
37711
|
+
nativeModeId: input2.nativeModeId !== void 0 && isDshNativeModeId(input2.nativeModeId) ? input2.nativeModeId : void 0,
|
|
37294
37712
|
cwd,
|
|
37295
|
-
|
|
37296
|
-
|
|
37297
|
-
|
|
37298
|
-
|
|
37299
|
-
|
|
37300
|
-
model: started.modelId,
|
|
37301
|
-
// agent 在握手里报的才是读回的;切型号走 session/set_model 时回包不带型号,那只是请求值。
|
|
37302
|
-
modelSource: started.modelReported ? "reported" : "echo"
|
|
37303
|
-
},
|
|
37304
|
-
...input2.bindingGeneration === void 0 ? {} : { bindingGeneration: input2.bindingGeneration }
|
|
37305
|
-
};
|
|
37306
|
-
registerSession(input2.threadId, {
|
|
37307
|
-
session,
|
|
37308
|
-
turns: [],
|
|
37309
|
-
executor,
|
|
37310
|
-
handle,
|
|
37311
|
-
forwarding,
|
|
37312
|
-
permissionSync,
|
|
37313
|
-
spawned
|
|
37314
|
-
});
|
|
37315
|
-
host.log.info("session started", {
|
|
37316
|
-
threadId: input2.threadId,
|
|
37317
|
-
sessionId: started.sessionId
|
|
37318
|
-
});
|
|
37319
|
-
return session;
|
|
37320
|
-
} catch (error62) {
|
|
37321
|
-
await cleanupAcpStartup({
|
|
37322
|
-
executor,
|
|
37323
|
-
stopProcess: () => handle.kill("SIGTERM"),
|
|
37324
|
-
forwarding,
|
|
37325
|
-
log: host.log,
|
|
37326
|
-
threadId: input2.threadId
|
|
37327
|
-
});
|
|
37328
|
-
throw error62;
|
|
37329
|
-
}
|
|
37330
|
-
},
|
|
37331
|
-
sendTurn: async (input2, signal) => {
|
|
37332
|
-
if (disposed) throw new Error("instance disposed");
|
|
37333
|
-
const booked = requireThread(input2.threadId);
|
|
37334
|
-
if (signal?.aborted) throw new Error("aborted");
|
|
37335
|
-
booked.permissionSync.beforeSendTurn();
|
|
37336
|
-
const onAbort = () => {
|
|
37337
|
-
void booked.executor.cancel(input2.expectedTurnId).catch(() => void 0);
|
|
37338
|
-
};
|
|
37339
|
-
signal?.addEventListener("abort", onAbort);
|
|
37340
|
-
try {
|
|
37341
|
-
const requestedModelId = modelIdFromSelection(input2.modelSelection);
|
|
37342
|
-
const requestedEffort = modelSelectionStringOption(
|
|
37343
|
-
input2.modelSelection,
|
|
37344
|
-
DSH_EFFORT_OPTION_ID
|
|
37345
|
-
);
|
|
37346
|
-
const turn = await dispatchAcpPrompt(booked.executor, {
|
|
37347
|
-
text: input2.input ?? "",
|
|
37348
|
-
expectedActiveTurnId: input2.expectedTurnId,
|
|
37349
|
-
...requestedModelId === void 0 ? {} : { requestedModelId },
|
|
37350
|
-
...requestedEffort === void 0 ? {} : { requestedEffort }
|
|
37351
|
-
});
|
|
37352
|
-
booked.turns.push({ id: turn.turnId, items: [] });
|
|
37353
|
-
return {
|
|
37354
|
-
threadId: input2.threadId,
|
|
37355
|
-
turnId: turn.turnId,
|
|
37356
|
-
...booked.session.resumeCursor === void 0 ? {} : { resumeCursor: booked.session.resumeCursor }
|
|
37357
|
-
};
|
|
37358
|
-
} finally {
|
|
37359
|
-
signal?.removeEventListener("abort", onAbort);
|
|
37360
|
-
}
|
|
37713
|
+
bindingGeneration: input2.bindingGeneration,
|
|
37714
|
+
resumeSchemaVersion: RESUME_SCHEMA_VERSION
|
|
37715
|
+
},
|
|
37716
|
+
booked: (base) => ({ ...base, permissionSync, spawned })
|
|
37717
|
+
});
|
|
37361
37718
|
},
|
|
37719
|
+
sendTurn: threadOps.sendTurn,
|
|
37362
37720
|
interruptTurn: async (threadId, turnId) => {
|
|
37363
37721
|
const booked = threads.get(threadId);
|
|
37364
|
-
|
|
37365
|
-
|
|
37366
|
-
|
|
37367
|
-
await yieldTick();
|
|
37368
|
-
if (booked.executor.toolSubagentsMayRun()) {
|
|
37722
|
+
const active2 = booked !== void 0 && !booked.closing ? booked : void 0;
|
|
37723
|
+
await threadOps.interruptTurn(threadId, turnId);
|
|
37724
|
+
if (active2?.executor.toolSubagentsMayRun()) {
|
|
37369
37725
|
host.log.info("stop session to stop its subagents", { threadId });
|
|
37370
37726
|
await stopSession(threadId);
|
|
37371
37727
|
}
|
|
@@ -37379,31 +37735,11 @@ var createDshInstance = (config2, host) => {
|
|
|
37379
37735
|
openToolCalls: booked.executor.openToolCalls()
|
|
37380
37736
|
});
|
|
37381
37737
|
},
|
|
37382
|
-
respondToRequest:
|
|
37383
|
-
|
|
37384
|
-
|
|
37385
|
-
requestId,
|
|
37386
|
-
decision === "allow" ? "accept" : "decline",
|
|
37387
|
-
reason
|
|
37388
|
-
);
|
|
37389
|
-
},
|
|
37390
|
-
respondToUserInput: async (threadId, requestId, answers) => {
|
|
37391
|
-
const booked = requireThread(threadId);
|
|
37392
|
-
await booked.executor.respondToUserInput(requestId, answers);
|
|
37393
|
-
},
|
|
37394
|
-
setRuntimeMode: async (threadId, runtimeMode) => {
|
|
37395
|
-
const booked = requireThread(threadId);
|
|
37396
|
-
booked.session = {
|
|
37397
|
-
...booked.session,
|
|
37398
|
-
runtimeMode,
|
|
37399
|
-
updatedAt: nowIso()
|
|
37400
|
-
};
|
|
37401
|
-
},
|
|
37738
|
+
respondToRequest: threadOps.respondToRequest,
|
|
37739
|
+
respondToUserInput: threadOps.respondToUserInput,
|
|
37740
|
+
setRuntimeMode: threadOps.setRuntimeMode,
|
|
37402
37741
|
stopSession: (threadId) => stopSession(threadId),
|
|
37403
|
-
readThread:
|
|
37404
|
-
const booked = requireThread(threadId);
|
|
37405
|
-
return { threadId, turns: booked.turns };
|
|
37406
|
-
},
|
|
37742
|
+
readThread: threadOps.readThread,
|
|
37407
37743
|
// 额度是 DeepSeek 账户的剩余金额(API key,没有订阅窗口);token 暂无来源,见 dshBalance.ts 与 README。
|
|
37408
37744
|
usage: createDshUsage({
|
|
37409
37745
|
environment: recipe.environment,
|
|
@@ -37448,7 +37784,7 @@ var index_default = definePlugin({
|
|
|
37448
37784
|
"DSH_HOME",
|
|
37449
37785
|
request,
|
|
37450
37786
|
process.env,
|
|
37451
|
-
(value) => value === void 0 ?
|
|
37787
|
+
(value) => value === void 0 ? NodePath8.join(NodeOS8.homedir(), ".dsh") : NodePath8.resolve(expandHomePath(value))
|
|
37452
37788
|
)
|
|
37453
37789
|
};
|
|
37454
37790
|
}
|