@alan-ai-hq/agent-manager 0.1.124 → 0.1.125
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.cjs +407 -230
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -34118,11 +34118,11 @@ function runOneShotCli(command, args, env, timeoutMs) {
|
|
|
34118
34118
|
return new Promise((resolve16) => {
|
|
34119
34119
|
const child = (0, import_node_child_process.spawn)(command, args, { env, stdio: ["ignore", "pipe", "ignore"] });
|
|
34120
34120
|
let stdout = "";
|
|
34121
|
-
let
|
|
34121
|
+
let settled2 = false;
|
|
34122
34122
|
const settle = (value2) => {
|
|
34123
|
-
if (
|
|
34123
|
+
if (settled2)
|
|
34124
34124
|
return;
|
|
34125
|
-
|
|
34125
|
+
settled2 = true;
|
|
34126
34126
|
clearTimeout(timer);
|
|
34127
34127
|
resolve16(value2);
|
|
34128
34128
|
};
|
|
@@ -34381,6 +34381,8 @@ function parseNpmRuntimeVerifiedVersion(stdout, packageName) {
|
|
|
34381
34381
|
var SANDBOX_AGENT_BROWSER_PACKAGE = "agent-browser";
|
|
34382
34382
|
var SANDBOX_AGENT_BROWSER_VERSION_POLICY = "0.37.1";
|
|
34383
34383
|
var SANDBOX_AGENT_BROWSER_NPM_SPEC = `${SANDBOX_AGENT_BROWSER_PACKAGE}@${SANDBOX_AGENT_BROWSER_VERSION_POLICY}`;
|
|
34384
|
+
var OPENCODE_ENGINE_PACKAGE = "opencode-ai";
|
|
34385
|
+
var OPENCODE_ENGINE_VERSION = "1.18.32";
|
|
34384
34386
|
var SANDBOX_DESKTOP_BROWSER_ENV = Object.freeze({
|
|
34385
34387
|
DISPLAY: ":0",
|
|
34386
34388
|
AGENT_BROWSER_HEADED: "true",
|
|
@@ -34562,8 +34564,8 @@ var definitions = [
|
|
|
34562
34564
|
envVars: ["ALAN_OPENCODE_PATH"],
|
|
34563
34565
|
installer: {
|
|
34564
34566
|
kind: "npm",
|
|
34565
|
-
packageName:
|
|
34566
|
-
versionPolicy:
|
|
34567
|
+
packageName: OPENCODE_ENGINE_PACKAGE,
|
|
34568
|
+
versionPolicy: OPENCODE_ENGINE_VERSION
|
|
34567
34569
|
},
|
|
34568
34570
|
bakeInto: ["e2b", "daytona", "freestyle"],
|
|
34569
34571
|
runtimeRepair: { kind: "all-hosts", timeoutMs: 12e4 },
|
|
@@ -35443,7 +35445,7 @@ function buildComputerReadiness(input2) {
|
|
|
35443
35445
|
}
|
|
35444
35446
|
|
|
35445
35447
|
// src/version.ts
|
|
35446
|
-
var AGENT_VERSION = "0.1.
|
|
35448
|
+
var AGENT_VERSION = "0.1.125";
|
|
35447
35449
|
|
|
35448
35450
|
// src/daemon/status.ts
|
|
35449
35451
|
var PENDING_RUN_START_TTL_MS = 10 * 6e4;
|
|
@@ -36767,7 +36769,7 @@ async function runHookCommand(args, overrides2 = {}) {
|
|
|
36767
36769
|
}
|
|
36768
36770
|
|
|
36769
36771
|
// src/cli/install.ts
|
|
36770
|
-
var
|
|
36772
|
+
var import_promises16 = require("timers/promises");
|
|
36771
36773
|
|
|
36772
36774
|
// src/sleep-inhibitor.ts
|
|
36773
36775
|
var import_node_child_process4 = require("child_process");
|
|
@@ -38152,6 +38154,7 @@ Team
|
|
|
38152
38154
|
\`\`\`
|
|
38153
38155
|
\`type\` is one of \`bar\`, \`line\`, \`area\`, \`pie\`, \`scatter\`. \`data\` is a non-empty array of flat objects \u2014 category field defaults to \`name\` (override with \`categoryKey\`), other numeric fields become series (or list explicitly via \`series: [...]\`). Pie needs a name+value field; scatter needs \`x\`/\`y\` (override via \`xKey\`/\`yKey\`). No JSX, no JS, no \`const\`/\`function\`, no unquoted keys or single-quoted strings, no code at all \u2014 it is rendered by a fixed component, not executed.
|
|
38154
38156
|
- This only covers plain chart data. There is currently no safe inline path for custom/bespoke visuals (node graphs, gauges, click-to-inspect panels, mini-apps) \u2014 an earlier version ran agent-authored JSX directly in the chat page with no sandbox, which is a real security risk (full page privileges: cookies, session storage, same-origin requests), so it was removed. If a request needs something \`\`\`chart's JSON shape can't express, say so plainly and offer the closest data-chart alternative, a Mermaid diagram, or a written summary \u2014 do not force custom visuals into the JSON shape, and do not silently fall back to scaffolding a project file with Write/Edit as a substitute for "inline."
|
|
38157
|
+
- Images you generate or edit appear in the chat automatically, the way ChatGPT shows them. Do not link, embed, or print the generated file's path afterwards, and do not announce "Generated:" or "Edited image:" \u2014 at most one short sentence about the result. Mention a path only when the user asked for the file to be saved into the project.
|
|
38155
38158
|
|
|
38156
38159
|
${ALAN_PLATFORM_TOOL_ROUTING_PROMPT}
|
|
38157
38160
|
|
|
@@ -40988,7 +40991,7 @@ function daemonExternalStopExitCode(reason) {
|
|
|
40988
40991
|
|
|
40989
40992
|
// src/cli/recover.ts
|
|
40990
40993
|
async function runLocalDaemonRecoveryLadder(input2) {
|
|
40991
|
-
const
|
|
40994
|
+
const settled2 = (status3) => status3.connected === true && !status3.recovering && !status3.restartRecommended || input2.stopWaiting?.(status3) === true;
|
|
40992
40995
|
const blocked = (status3) => input2.blockingRunCount(status3) > 0;
|
|
40993
40996
|
const busy = (status3) => {
|
|
40994
40997
|
const count2 = input2.blockingRunCount(status3);
|
|
@@ -41009,17 +41012,17 @@ async function runLocalDaemonRecoveryLadder(input2) {
|
|
|
41009
41012
|
const pollMs = input2.options?.pollMs ?? 500;
|
|
41010
41013
|
let status3 = await input2.getStatus();
|
|
41011
41014
|
while (Date.now() < deadline) {
|
|
41012
|
-
if (
|
|
41015
|
+
if (settled2(status3)) return status3;
|
|
41013
41016
|
await sleep(pollMs);
|
|
41014
41017
|
status3 = await input2.getStatus();
|
|
41015
41018
|
}
|
|
41016
41019
|
return status3;
|
|
41017
41020
|
};
|
|
41018
41021
|
let status2 = input2.initialStatus;
|
|
41019
|
-
if (
|
|
41022
|
+
if (settled2(status2)) return status2;
|
|
41020
41023
|
if (await input2.redial().catch(() => false)) {
|
|
41021
41024
|
status2 = await waitForRecovery();
|
|
41022
|
-
if (
|
|
41025
|
+
if (settled2(status2)) return status2;
|
|
41023
41026
|
if (status2.configured && status2.running !== false && !status2.restartRecommended) {
|
|
41024
41027
|
return { ...status2, recovering: true, recoveryCode: "connect_timeout" };
|
|
41025
41028
|
}
|
|
@@ -41033,10 +41036,10 @@ async function runLocalDaemonRecoveryLadder(input2) {
|
|
|
41033
41036
|
error61 instanceof Error ? error61.message : "Local daemon restart failed"
|
|
41034
41037
|
);
|
|
41035
41038
|
}
|
|
41036
|
-
if (
|
|
41039
|
+
if (settled2(status2)) return status2;
|
|
41037
41040
|
if (blocked(status2)) return busy(status2);
|
|
41038
41041
|
status2 = await waitForRecovery();
|
|
41039
|
-
if (
|
|
41042
|
+
if (settled2(status2)) return status2;
|
|
41040
41043
|
if (blocked(status2)) return busy(status2);
|
|
41041
41044
|
return exhausted(
|
|
41042
41045
|
status2,
|
|
@@ -43640,13 +43643,15 @@ var import_path8 = require("path");
|
|
|
43640
43643
|
var import_promises4 = require("fs/promises");
|
|
43641
43644
|
var import_path9 = require("path");
|
|
43642
43645
|
var import_crypto4 = require("crypto");
|
|
43646
|
+
var import_child_process6 = require("child_process");
|
|
43647
|
+
var import_util14 = require("util");
|
|
43643
43648
|
var import_crypto5 = require("crypto");
|
|
43644
43649
|
var import_fs9 = require("fs");
|
|
43645
43650
|
var import_os4 = require("os");
|
|
43646
43651
|
var import_path10 = require("path");
|
|
43647
43652
|
var import_url2 = require("url");
|
|
43648
|
-
var
|
|
43649
|
-
var
|
|
43653
|
+
var import_child_process7 = require("child_process");
|
|
43654
|
+
var import_util15 = require("util");
|
|
43650
43655
|
var import_os5 = require("os");
|
|
43651
43656
|
var import_path11 = require("path");
|
|
43652
43657
|
var import_url3 = require("url");
|
|
@@ -43667,30 +43672,33 @@ var import_crypto7 = require("crypto");
|
|
|
43667
43672
|
var import_fs13 = require("fs");
|
|
43668
43673
|
var import_os6 = require("os");
|
|
43669
43674
|
var import_path13 = require("path");
|
|
43670
|
-
var
|
|
43675
|
+
var import_promises5 = require("timers/promises");
|
|
43671
43676
|
var import_path14 = require("path");
|
|
43677
|
+
var import_fs14 = require("fs");
|
|
43678
|
+
var import_path15 = require("path");
|
|
43672
43679
|
var import_fs15 = require("fs");
|
|
43673
43680
|
var import_os7 = require("os");
|
|
43674
|
-
var
|
|
43681
|
+
var import_path16 = require("path");
|
|
43675
43682
|
var import_crypto8 = require("crypto");
|
|
43676
43683
|
var import_fs16 = require("fs");
|
|
43677
43684
|
var import_os8 = require("os");
|
|
43678
|
-
var
|
|
43685
|
+
var import_path17 = require("path");
|
|
43679
43686
|
var import_fs17 = require("fs");
|
|
43680
43687
|
var import_os9 = require("os");
|
|
43681
|
-
var
|
|
43688
|
+
var import_path18 = require("path");
|
|
43682
43689
|
var import_crypto9 = require("crypto");
|
|
43683
43690
|
var import_fs18 = require("fs");
|
|
43684
43691
|
var import_os10 = require("os");
|
|
43685
|
-
var
|
|
43686
|
-
var
|
|
43692
|
+
var import_path19 = require("path");
|
|
43693
|
+
var import_child_process8 = require("child_process");
|
|
43687
43694
|
var import_fs19 = require("fs");
|
|
43688
43695
|
var import_os11 = require("os");
|
|
43689
|
-
var
|
|
43696
|
+
var import_path20 = require("path");
|
|
43690
43697
|
function createGrammarState() {
|
|
43691
43698
|
return { seenToolCallIds: /* @__PURE__ */ new Set(), counter: 0, scratch: {} };
|
|
43692
43699
|
}
|
|
43693
43700
|
var PROVIDER_PAYLOAD_META = "alan.dev/providerPayload";
|
|
43701
|
+
var PROVIDER_WIRE_META = "alan.dev/providerWire";
|
|
43694
43702
|
var TOOL_RESULT_ONLY_META = "alan.dev/toolResultOnly";
|
|
43695
43703
|
var PARENT_TOOL_CALL_META = "alan.dev/parentToolCallId";
|
|
43696
43704
|
var SUBAGENT_LAUNCHER_META = "alan.dev/subagentLauncher";
|
|
@@ -44689,8 +44697,8 @@ function withBackgroundTaskMeta(update, state) {
|
|
|
44689
44697
|
if (!record4) return update;
|
|
44690
44698
|
const label = record4.meta.label ?? toolLabels.get(state)?.get(update.toolCallId);
|
|
44691
44699
|
if (!record4.meta.label && label) record4.meta = { ...record4.meta, label };
|
|
44692
|
-
const
|
|
44693
|
-
if (
|
|
44700
|
+
const settled2 = update.status === "completed" || update.status === "failed" || update.status === "cancelled";
|
|
44701
|
+
if (settled2 && record4.meta.kind === "agent" && isRunningBackgroundTask(record4)) {
|
|
44694
44702
|
setBackgroundTaskStatus(
|
|
44695
44703
|
record4,
|
|
44696
44704
|
terminalBackgroundTaskStatus(
|
|
@@ -45618,11 +45626,11 @@ async function killProcessTree(pid, options = {}) {
|
|
|
45618
45626
|
}
|
|
45619
45627
|
if (process.platform === "win32") {
|
|
45620
45628
|
return new Promise((resolve52) => {
|
|
45621
|
-
let
|
|
45629
|
+
let settled2 = false;
|
|
45622
45630
|
let timer;
|
|
45623
45631
|
const finish = (error61) => {
|
|
45624
|
-
if (
|
|
45625
|
-
|
|
45632
|
+
if (settled2) return;
|
|
45633
|
+
settled2 = true;
|
|
45626
45634
|
clearTimeout(timer);
|
|
45627
45635
|
if (error61) onError?.("taskkill", error61);
|
|
45628
45636
|
resolve52(!error61);
|
|
@@ -46370,8 +46378,8 @@ function mediaUpdatesFor(update, context) {
|
|
|
46370
46378
|
hints2.add(path2);
|
|
46371
46379
|
}
|
|
46372
46380
|
}
|
|
46373
|
-
const
|
|
46374
|
-
if (!
|
|
46381
|
+
const settled2 = update.status === "completed" || update.status === "failed";
|
|
46382
|
+
if (!settled2 || update.status === "failed") return [];
|
|
46375
46383
|
const call = tools.get(toolCallId);
|
|
46376
46384
|
if (!call) return [];
|
|
46377
46385
|
const hints = hintsFor(context);
|
|
@@ -46453,8 +46461,8 @@ function applyToolCall(update, context, state, effects, projection) {
|
|
|
46453
46461
|
if (taskId) registerBackgroundTaskRecord(state, { task_id: taskId, tool_use_id: id });
|
|
46454
46462
|
}
|
|
46455
46463
|
}
|
|
46456
|
-
const
|
|
46457
|
-
if (
|
|
46464
|
+
const settled2 = update.status === "completed" || update.status === "failed" || update.status === "cancelled";
|
|
46465
|
+
if (settled2 && isLauncher) clearBackgroundTaskIds(state, [id]);
|
|
46458
46466
|
}
|
|
46459
46467
|
function breakdownOf(update) {
|
|
46460
46468
|
const raw = metaOf(update)?.[USAGE_META];
|
|
@@ -47065,6 +47073,45 @@ async function connectOpenCodeSse(url3, signal) {
|
|
|
47065
47073
|
}
|
|
47066
47074
|
};
|
|
47067
47075
|
}
|
|
47076
|
+
var execFileAsync2 = (0, import_util14.promisify)(import_child_process6.execFile);
|
|
47077
|
+
var VERSION_PROBE_TIMEOUT_MS = 5e3;
|
|
47078
|
+
var SUPPORTED_OPENCODE_MAJOR = 1;
|
|
47079
|
+
var versionProbes = /* @__PURE__ */ new Map();
|
|
47080
|
+
function parseOpenCodeVersion(output2) {
|
|
47081
|
+
return /\bv?(\d+\.\d+\.\d+(?:-[\w.-]+)?)/.exec(output2)?.[1] ?? null;
|
|
47082
|
+
}
|
|
47083
|
+
function unsupportedOpenCodeVersionMessage(version2, command) {
|
|
47084
|
+
const major = Number.parseInt(version2, 10);
|
|
47085
|
+
if (!Number.isFinite(major) || major <= SUPPORTED_OPENCODE_MAJOR) return null;
|
|
47086
|
+
return `OpenCode ${version2} (${command}) is not supported yet. Alan runs the OpenCode ${SUPPORTED_OPENCODE_MAJOR}.x server API, which OpenCode 2 replaced. Install opencode-ai@${SUPPORTED_OPENCODE_MAJOR} or point ALAN_OPENCODE_PATH at an OpenCode ${SUPPORTED_OPENCODE_MAJOR}.x binary.`;
|
|
47087
|
+
}
|
|
47088
|
+
async function probeOpenCodeVersion(command, context) {
|
|
47089
|
+
try {
|
|
47090
|
+
const { stdout, stderr } = await execFileAsync2(command, ["--version"], {
|
|
47091
|
+
cwd: context.cwd,
|
|
47092
|
+
env: { ...process.env, ...context.env },
|
|
47093
|
+
encoding: "utf8",
|
|
47094
|
+
timeout: VERSION_PROBE_TIMEOUT_MS,
|
|
47095
|
+
maxBuffer: 64 * 1024,
|
|
47096
|
+
windowsHide: true
|
|
47097
|
+
});
|
|
47098
|
+
return parseOpenCodeVersion(`${stdout}
|
|
47099
|
+
${stderr}`);
|
|
47100
|
+
} catch {
|
|
47101
|
+
return null;
|
|
47102
|
+
}
|
|
47103
|
+
}
|
|
47104
|
+
async function assertSupportedOpenCodeEngine(command, context) {
|
|
47105
|
+
const cacheKey = `${command}\0${context.env.PATH ?? process.env.PATH ?? ""}`;
|
|
47106
|
+
let probe = versionProbes.get(cacheKey);
|
|
47107
|
+
if (!probe) {
|
|
47108
|
+
probe = probeOpenCodeVersion(command, context);
|
|
47109
|
+
versionProbes.set(cacheKey, probe);
|
|
47110
|
+
}
|
|
47111
|
+
const version2 = await probe;
|
|
47112
|
+
const message = version2 ? unsupportedOpenCodeVersionMessage(version2, command) : null;
|
|
47113
|
+
if (message) throw new Error(message);
|
|
47114
|
+
}
|
|
47068
47115
|
var HUNK_FIELDS = ["oldStart", "oldLines", "newStart", "newLines"];
|
|
47069
47116
|
function readPatchHunk(value2) {
|
|
47070
47117
|
const record4 = asRecord(value2);
|
|
@@ -47184,6 +47231,7 @@ function opencodeFileChangeContent(metadata, name = "", input2) {
|
|
|
47184
47231
|
];
|
|
47185
47232
|
}
|
|
47186
47233
|
var OPENCODE_GRAMMAR_NAME = "opencode";
|
|
47234
|
+
var OPENCODE_WIRE = "opencode-v1";
|
|
47187
47235
|
var SCRATCH = OPENCODE_GRAMMAR_NAME;
|
|
47188
47236
|
var TASK_TOOL_NAME = "task";
|
|
47189
47237
|
var TASK_RESULT_TAG = /<task_result>\n?([\s\S]*?)\n?<\/task_result>/;
|
|
@@ -47284,7 +47332,7 @@ function parseEvent(event, state) {
|
|
|
47284
47332
|
{
|
|
47285
47333
|
sessionUpdate: "_alan/unhandled",
|
|
47286
47334
|
kind: `opencode.part.${type || "unknown"}`,
|
|
47287
|
-
_meta: { [PROVIDER_PAYLOAD_META]: event }
|
|
47335
|
+
_meta: { [PROVIDER_PAYLOAD_META]: event, [PROVIDER_WIRE_META]: OPENCODE_WIRE }
|
|
47288
47336
|
}
|
|
47289
47337
|
];
|
|
47290
47338
|
}
|
|
@@ -47363,6 +47411,7 @@ function parseTool(part) {
|
|
|
47363
47411
|
// `task` spawns a subagent the runtime gates run completion on.
|
|
47364
47412
|
_meta: {
|
|
47365
47413
|
"alan.dev/providerEvent": part,
|
|
47414
|
+
[PROVIDER_WIRE_META]: OPENCODE_WIRE,
|
|
47366
47415
|
...isTask ? { [SUBAGENT_LAUNCHER_META]: true } : {},
|
|
47367
47416
|
...childSessionId ? { [SUBAGENT_TASK_ID_META]: childSessionId } : {},
|
|
47368
47417
|
...toolState?.metadata !== void 0 ? { [PROVIDER_PAYLOAD_META]: toolState.metadata } : {}
|
|
@@ -47851,10 +47900,10 @@ function startOpenCodeServer(command, context) {
|
|
|
47851
47900
|
env: withoutOpenCodeServerAuth(context.env)
|
|
47852
47901
|
});
|
|
47853
47902
|
const ready = new Promise((resolve52, reject2) => {
|
|
47854
|
-
let
|
|
47903
|
+
let settled2 = false;
|
|
47855
47904
|
const timeout = setTimeout(() => {
|
|
47856
|
-
if (
|
|
47857
|
-
|
|
47905
|
+
if (settled2) return;
|
|
47906
|
+
settled2 = true;
|
|
47858
47907
|
reject2(
|
|
47859
47908
|
new Error(`opencode serve did not report a listening URL within ${STARTUP_TIMEOUT_MS}ms`)
|
|
47860
47909
|
);
|
|
@@ -47862,10 +47911,10 @@ function startOpenCodeServer(command, context) {
|
|
|
47862
47911
|
let stdoutTail = "";
|
|
47863
47912
|
let stderrTail = "";
|
|
47864
47913
|
const checkLine = (line) => {
|
|
47865
|
-
if (
|
|
47914
|
+
if (settled2) return;
|
|
47866
47915
|
const match = line.match(SERVER_LISTENING_PATTERN);
|
|
47867
47916
|
if (!match) return;
|
|
47868
|
-
|
|
47917
|
+
settled2 = true;
|
|
47869
47918
|
clearTimeout(timeout);
|
|
47870
47919
|
child.stdout.off("data", onStdout);
|
|
47871
47920
|
child.stderr.off("data", onStderr);
|
|
@@ -47886,14 +47935,14 @@ function startOpenCodeServer(command, context) {
|
|
|
47886
47935
|
child.stdout.on("data", onStdout);
|
|
47887
47936
|
child.stderr.on("data", onStderr);
|
|
47888
47937
|
child.once("error", (error61) => {
|
|
47889
|
-
if (
|
|
47890
|
-
|
|
47938
|
+
if (settled2) return;
|
|
47939
|
+
settled2 = true;
|
|
47891
47940
|
clearTimeout(timeout);
|
|
47892
47941
|
reject2(error61);
|
|
47893
47942
|
});
|
|
47894
47943
|
child.once("exit", (code) => {
|
|
47895
|
-
if (
|
|
47896
|
-
|
|
47944
|
+
if (settled2) return;
|
|
47945
|
+
settled2 = true;
|
|
47897
47946
|
clearTimeout(timeout);
|
|
47898
47947
|
reject2(
|
|
47899
47948
|
new Error(
|
|
@@ -48314,6 +48363,7 @@ function createOpencodeServeBackend(command = "opencode", options = PLAIN_OPENCO
|
|
|
48314
48363
|
let context;
|
|
48315
48364
|
try {
|
|
48316
48365
|
context = await options.prepareContext(rawContext);
|
|
48366
|
+
await assertSupportedOpenCodeEngine(command, context);
|
|
48317
48367
|
} catch (error61) {
|
|
48318
48368
|
const message = error61 instanceof Error ? error61.message : String(error61);
|
|
48319
48369
|
const state2 = {
|
|
@@ -50043,7 +50093,7 @@ function handleSubagentResult(event, context, state) {
|
|
|
50043
50093
|
state.iterations = Math.max(state.iterations, 1);
|
|
50044
50094
|
const updates = [];
|
|
50045
50095
|
const launcherId = antigravityExplicitToolId(event);
|
|
50046
|
-
const
|
|
50096
|
+
const settled2 = settleBackgroundTerminalNotification(
|
|
50047
50097
|
KIND,
|
|
50048
50098
|
context,
|
|
50049
50099
|
state,
|
|
@@ -50056,9 +50106,9 @@ function handleSubagentResult(event, context, state) {
|
|
|
50056
50106
|
}
|
|
50057
50107
|
}
|
|
50058
50108
|
);
|
|
50059
|
-
if (
|
|
50060
|
-
state.antigravitySubagentTranscripts?.get(
|
|
50061
|
-
state.antigravitySubagentTranscripts?.delete(
|
|
50109
|
+
if (settled2) {
|
|
50110
|
+
state.antigravitySubagentTranscripts?.get(settled2)?.cursor?.close();
|
|
50111
|
+
state.antigravitySubagentTranscripts?.delete(settled2);
|
|
50062
50112
|
}
|
|
50063
50113
|
return updates;
|
|
50064
50114
|
}
|
|
@@ -50185,14 +50235,14 @@ var parseAntigravityStructuredLine = grammarAsStructuredLineParser(
|
|
|
50185
50235
|
antigravityEffects
|
|
50186
50236
|
);
|
|
50187
50237
|
var parseAntigravityTextLine = grammarAsStructuredLineParser(antigravityTextGrammar);
|
|
50188
|
-
var
|
|
50238
|
+
var execFileAsync3 = (0, import_util15.promisify)(import_child_process7.execFile);
|
|
50189
50239
|
var capabilityCache = /* @__PURE__ */ new Map();
|
|
50190
50240
|
function normalizeProbeOutput(output2) {
|
|
50191
50241
|
return output2.toLowerCase().replace(/\s+/g, " ");
|
|
50192
50242
|
}
|
|
50193
50243
|
async function readCliOutput(command, args, context) {
|
|
50194
50244
|
try {
|
|
50195
|
-
const { stdout, stderr } = await
|
|
50245
|
+
const { stdout, stderr } = await execFileAsync3(command, args, {
|
|
50196
50246
|
cwd: context.cwd,
|
|
50197
50247
|
env: { ...process.env, ...context.env },
|
|
50198
50248
|
encoding: "utf8",
|
|
@@ -51245,14 +51295,14 @@ function backgroundTaskProgress(event, state) {
|
|
|
51245
51295
|
return [
|
|
51246
51296
|
{ sessionUpdate: "tool_call_update", toolCallId, _meta: { [PROVIDER_PAYLOAD_META]: event } }
|
|
51247
51297
|
];
|
|
51248
|
-
const
|
|
51298
|
+
const settled2 = Boolean(
|
|
51249
51299
|
progress.status && TERMINAL_BACKGROUND_STATUSES.has(progress.status.toLowerCase())
|
|
51250
51300
|
);
|
|
51251
51301
|
return [
|
|
51252
51302
|
{
|
|
51253
51303
|
sessionUpdate: "tool_call_update",
|
|
51254
51304
|
toolCallId,
|
|
51255
|
-
...
|
|
51305
|
+
...settled2 ? {} : { status: "in_progress" },
|
|
51256
51306
|
_meta: { "alan.dev/taskProgress": progress, [PROVIDER_PAYLOAD_META]: event }
|
|
51257
51307
|
}
|
|
51258
51308
|
];
|
|
@@ -51394,11 +51444,11 @@ function handleSystem(event, context, state) {
|
|
|
51394
51444
|
}
|
|
51395
51445
|
clearBackgroundTaskIds(state, keys);
|
|
51396
51446
|
if (toolUseId && wasActive) {
|
|
51397
|
-
const
|
|
51447
|
+
const settled2 = settledSubagentResult(toolUseId, resultText2, failed, outputMeta(notification));
|
|
51398
51448
|
updates.push({
|
|
51399
|
-
...
|
|
51449
|
+
...settled2,
|
|
51400
51450
|
_meta: {
|
|
51401
|
-
...asRecord(
|
|
51451
|
+
...asRecord(settled2._meta),
|
|
51402
51452
|
[PROVIDER_PAYLOAD_META]: event,
|
|
51403
51453
|
...notification.summary ? {
|
|
51404
51454
|
"alan.dev/taskProgress": {
|
|
@@ -51676,21 +51726,109 @@ function recoverCodexFileChange(state, item) {
|
|
|
51676
51726
|
_meta: { ...asRecord(update._meta), [PROVIDER_PAYLOAD_META]: item }
|
|
51677
51727
|
}));
|
|
51678
51728
|
}
|
|
51729
|
+
var IMAGE_GEN_CALL = /\bimage_gen\w*\s*\(/;
|
|
51730
|
+
var PROMPT_LITERAL = /\bprompt\s*:\s*("(?:[^"\\]|\\.)*")/;
|
|
51731
|
+
function emptyImageGenerationFold() {
|
|
51732
|
+
return { pending: [], updates: [] };
|
|
51733
|
+
}
|
|
51734
|
+
function mentionsImageGeneration(line) {
|
|
51735
|
+
return line.includes("image_gen");
|
|
51736
|
+
}
|
|
51737
|
+
function promptOf(script) {
|
|
51738
|
+
const literal2 = PROMPT_LITERAL.exec(script)?.[1];
|
|
51739
|
+
if (!literal2) return void 0;
|
|
51740
|
+
try {
|
|
51741
|
+
const prompt = JSON.parse(literal2);
|
|
51742
|
+
return typeof prompt === "string" ? prompt : void 0;
|
|
51743
|
+
} catch {
|
|
51744
|
+
return void 0;
|
|
51745
|
+
}
|
|
51746
|
+
}
|
|
51747
|
+
function startedCall(payload) {
|
|
51748
|
+
const callId = typeof payload.call_id === "string" ? payload.call_id : "";
|
|
51749
|
+
if (!callId) return null;
|
|
51750
|
+
if (payload.type === "custom_tool_call" && payload.name === "exec") {
|
|
51751
|
+
const script = typeof payload.input === "string" ? payload.input : "";
|
|
51752
|
+
return IMAGE_GEN_CALL.test(script) ? { callId, prompt: promptOf(script) } : null;
|
|
51753
|
+
}
|
|
51754
|
+
if (payload.type === "function_call" && payload.name === "image_gen" && !payload.namespace) {
|
|
51755
|
+
return { callId };
|
|
51756
|
+
}
|
|
51757
|
+
return null;
|
|
51758
|
+
}
|
|
51759
|
+
function settled(toolCallId, status2) {
|
|
51760
|
+
return { sessionUpdate: "tool_call_update", toolCallId, status: status2 };
|
|
51761
|
+
}
|
|
51762
|
+
function foldImageGenerationLine(entryType, payload, fold) {
|
|
51763
|
+
if (entryType === "response_item") {
|
|
51764
|
+
const call = startedCall(payload);
|
|
51765
|
+
if (!call) return;
|
|
51766
|
+
fold.pending.push(call.callId);
|
|
51767
|
+
fold.updates.push({
|
|
51768
|
+
sessionUpdate: "tool_call_update",
|
|
51769
|
+
toolCallId: call.callId,
|
|
51770
|
+
name: "image_gen",
|
|
51771
|
+
title: "Generate image",
|
|
51772
|
+
kind: "other",
|
|
51773
|
+
status: "in_progress",
|
|
51774
|
+
rawInput: call.prompt ? { prompt: call.prompt } : {}
|
|
51775
|
+
});
|
|
51776
|
+
return;
|
|
51777
|
+
}
|
|
51778
|
+
if (entryType !== "event_msg") return;
|
|
51779
|
+
if (payload.type === "image_generation_end") {
|
|
51780
|
+
const toolCallId2 = fold.pending.shift();
|
|
51781
|
+
if (toolCallId2) fold.updates.push(settled(toolCallId2, "completed"));
|
|
51782
|
+
return;
|
|
51783
|
+
}
|
|
51784
|
+
const item = asRecord(payload.item);
|
|
51785
|
+
if (payload.type !== "item_completed") return;
|
|
51786
|
+
if (item?.type !== "Extension" || item.kind !== "image_gen.generation") return;
|
|
51787
|
+
const toolCallId = fold.pending.shift();
|
|
51788
|
+
const savedPath = typeof item.savedPath === "string" ? item.savedPath : void 0;
|
|
51789
|
+
const image = item.status === "completed" ? buildGeneratedImageFromInlinePayload(
|
|
51790
|
+
{
|
|
51791
|
+
id: item.id,
|
|
51792
|
+
call_id: toolCallId,
|
|
51793
|
+
result: item.result,
|
|
51794
|
+
filename: savedPath && (0, import_path14.basename)(savedPath)
|
|
51795
|
+
},
|
|
51796
|
+
{ dataFields: ["result"], toolIdFields: ["call_id"], idFields: ["id"] }
|
|
51797
|
+
) : null;
|
|
51798
|
+
if (image) {
|
|
51799
|
+
fold.updates.push({
|
|
51800
|
+
sessionUpdate: "_alan/generated_image",
|
|
51801
|
+
image: savedPath ? { ...image, sourcePath: savedPath } : image
|
|
51802
|
+
});
|
|
51803
|
+
}
|
|
51804
|
+
if (toolCallId) fold.updates.push(settled(toolCallId, image ? "completed" : "failed"));
|
|
51805
|
+
}
|
|
51806
|
+
function settlePendingImageGenerations(fold) {
|
|
51807
|
+
const updates = fold.pending.map((toolCallId) => settled(toolCallId, "failed"));
|
|
51808
|
+
fold.pending = [];
|
|
51809
|
+
return updates;
|
|
51810
|
+
}
|
|
51811
|
+
function takeImageGenerationUpdates(fold) {
|
|
51812
|
+
const isImage = (update) => update.sessionUpdate === "_alan/generated_image";
|
|
51813
|
+
const first = fold.updates.findIndex(isImage);
|
|
51814
|
+
const second = first === -1 ? -1 : fold.updates.findIndex((u, i) => i > first && isImage(u));
|
|
51815
|
+
return fold.updates.splice(0, second === -1 ? fold.updates.length : second);
|
|
51816
|
+
}
|
|
51679
51817
|
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
51680
51818
|
var MAX_HEADER_BYTES = 1024 * 1024;
|
|
51681
51819
|
function workerDirectories(rootLog) {
|
|
51682
|
-
const directory = (0,
|
|
51683
|
-
const monthDirectory = (0,
|
|
51684
|
-
const yearDirectory = (0,
|
|
51685
|
-
const date5 = `${(0,
|
|
51820
|
+
const directory = (0, import_path15.dirname)(rootLog);
|
|
51821
|
+
const monthDirectory = (0, import_path15.dirname)(directory);
|
|
51822
|
+
const yearDirectory = (0, import_path15.dirname)(monthDirectory);
|
|
51823
|
+
const date5 = `${(0, import_path15.basename)(yearDirectory)}-${(0, import_path15.basename)(monthDirectory)}-${(0, import_path15.basename)(directory)}`;
|
|
51686
51824
|
if (!/^\d{4}-\d{2}-\d{2}$/.test(date5)) return [directory];
|
|
51687
51825
|
const timestamp = Date.parse(`${date5}T00:00:00Z`);
|
|
51688
51826
|
if (!Number.isFinite(timestamp) || new Date(timestamp).toISOString().slice(0, 10) !== date5)
|
|
51689
51827
|
return [directory];
|
|
51690
|
-
const sessionsDirectory2 = (0,
|
|
51828
|
+
const sessionsDirectory2 = (0, import_path15.dirname)(yearDirectory);
|
|
51691
51829
|
return [0, 1, -1].map((offset2) => {
|
|
51692
51830
|
const day = new Date(timestamp + offset2 * DAY_MS).toISOString().slice(0, 10);
|
|
51693
|
-
return (0,
|
|
51831
|
+
return (0, import_path15.join)(sessionsDirectory2, ...day.split("-"));
|
|
51694
51832
|
});
|
|
51695
51833
|
}
|
|
51696
51834
|
function firstLine(path2) {
|
|
@@ -51727,7 +51865,7 @@ function findCodexWorkerLogs(rootLog, parentThreadId) {
|
|
|
51727
51865
|
}
|
|
51728
51866
|
for (const entry of entries) {
|
|
51729
51867
|
if (!entry.isFile() || !entry.name.endsWith(".jsonl")) continue;
|
|
51730
|
-
const path2 = (0,
|
|
51868
|
+
const path2 = (0, import_path15.join)(directory, entry.name);
|
|
51731
51869
|
if (path2 === rootLog) continue;
|
|
51732
51870
|
try {
|
|
51733
51871
|
const line = firstLine(path2);
|
|
@@ -51899,13 +52037,14 @@ function rolloutScanFor(state, path2) {
|
|
|
51899
52037
|
path: path2,
|
|
51900
52038
|
cursor: new TranscriptCursor(path2, promptOffset),
|
|
51901
52039
|
spawnByCallId: /* @__PURE__ */ new Map(),
|
|
51902
|
-
workersByThreadId: /* @__PURE__ */ new Map()
|
|
52040
|
+
workersByThreadId: /* @__PURE__ */ new Map(),
|
|
52041
|
+
imageGeneration: emptyImageGenerationFold()
|
|
51903
52042
|
};
|
|
51904
52043
|
rolloutScans.set(state, scan);
|
|
51905
52044
|
return scan;
|
|
51906
52045
|
}
|
|
51907
52046
|
function couldMatter(line, scan) {
|
|
51908
|
-
return line.includes('"role":"user"') || line.includes('"spawn_agent"') || line.includes('"sub_agent_activity"') || scan.spawnByCallId.size > 0 && line.includes('"function_call_output"');
|
|
52047
|
+
return line.includes('"role":"user"') || mentionsImageGeneration(line) || line.includes('"spawn_agent"') || line.includes('"sub_agent_activity"') || scan.spawnByCallId.size > 0 && line.includes('"function_call_output"');
|
|
51909
52048
|
}
|
|
51910
52049
|
function foldSpawnCall(payload, scan, timestamp) {
|
|
51911
52050
|
const namespace = typeof payload.namespace === "string" ? payload.namespace : "";
|
|
@@ -51962,6 +52101,7 @@ function foldRolloutLine(line, scan) {
|
|
|
51962
52101
|
scan.workersByThreadId.clear();
|
|
51963
52102
|
return;
|
|
51964
52103
|
}
|
|
52104
|
+
foldImageGenerationLine(entry.type, payload, scan.imageGeneration);
|
|
51965
52105
|
if (entry.type === "response_item" && payload.type === "function_call") {
|
|
51966
52106
|
if (payload.name === "spawn_agent") foldSpawnCall(payload, scan, entry.timestamp);
|
|
51967
52107
|
return;
|
|
@@ -51974,11 +52114,16 @@ function foldRolloutLine(line, scan) {
|
|
|
51974
52114
|
foldWorkerStarted(payload, scan);
|
|
51975
52115
|
}
|
|
51976
52116
|
}
|
|
51977
|
-
function
|
|
52117
|
+
function advanceRolloutScan(state, logPath) {
|
|
51978
52118
|
const scan = rolloutScanFor(state, logPath);
|
|
51979
|
-
if (!scan) return
|
|
52119
|
+
if (!scan) return null;
|
|
51980
52120
|
for (const line of scan.cursor.read()) foldRolloutLine(line.text, scan);
|
|
51981
52121
|
scan.cursor.close();
|
|
52122
|
+
return scan;
|
|
52123
|
+
}
|
|
52124
|
+
function collectCodexWorkerReplays(logPath, state) {
|
|
52125
|
+
const scan = advanceRolloutScan(state, logPath);
|
|
52126
|
+
if (!scan) return [];
|
|
51982
52127
|
const unresolved = [...scan.spawnByCallId.values()].filter(
|
|
51983
52128
|
(spawn42) => spawn42.agentPath && ![...scan.workersByThreadId.values()].some((worker) => worker.launcherId === spawn42.launcherId)
|
|
51984
52129
|
);
|
|
@@ -52207,6 +52352,30 @@ function replayCodexWorkerTranscript(context, worker, codexHome, state) {
|
|
|
52207
52352
|
rememberWorkerReplay(state, worker.threadId, lines.length, finalText);
|
|
52208
52353
|
return finalText;
|
|
52209
52354
|
}
|
|
52355
|
+
function imageGenerationFold(state) {
|
|
52356
|
+
const logPath = state.codexSessionLogPath;
|
|
52357
|
+
const scan = logPath ? advanceRolloutScan(state, logPath) : null;
|
|
52358
|
+
return scan?.imageGeneration ?? null;
|
|
52359
|
+
}
|
|
52360
|
+
function syncCodexImageGenerationFromSessionLog(context, state) {
|
|
52361
|
+
const fold = imageGenerationFold(state);
|
|
52362
|
+
const updates = fold ? takeImageGenerationUpdates(fold) : [];
|
|
52363
|
+
for (const update of updates) emitSessionUpdate(update, context, state);
|
|
52364
|
+
return updates.length;
|
|
52365
|
+
}
|
|
52366
|
+
var EXIT_IMAGE_SPACING_MS = 100;
|
|
52367
|
+
async function flushCodexImageGenerationOnExit(context, state) {
|
|
52368
|
+
const fold = imageGenerationFold(state);
|
|
52369
|
+
if (!fold) return;
|
|
52370
|
+
for (; ; ) {
|
|
52371
|
+
const updates = takeImageGenerationUpdates(fold);
|
|
52372
|
+
if (updates.length === 0) break;
|
|
52373
|
+
for (const update of updates) emitSessionUpdate(update, context, state);
|
|
52374
|
+
if (fold.updates.length > 0) await (0, import_promises5.setTimeout)(EXIT_IMAGE_SPACING_MS);
|
|
52375
|
+
}
|
|
52376
|
+
for (const update of settlePendingImageGenerations(fold))
|
|
52377
|
+
emitSessionUpdate(update, context, state);
|
|
52378
|
+
}
|
|
52210
52379
|
function syncCodexWorkerEventsFromSessionLog(context, state) {
|
|
52211
52380
|
const runtimeSessionId = state.runtimeSessionId;
|
|
52212
52381
|
if (!runtimeSessionId) return [];
|
|
@@ -52260,6 +52429,13 @@ function syncCodexWorkerEventsFromSessionLog(context, state) {
|
|
|
52260
52429
|
return workers;
|
|
52261
52430
|
}
|
|
52262
52431
|
async function replayCodexMcpToolEventsFromSessionLog(context, state) {
|
|
52432
|
+
try {
|
|
52433
|
+
replayRolloutAfterExit(context, state);
|
|
52434
|
+
} finally {
|
|
52435
|
+
await flushCodexImageGenerationOnExit(context, state);
|
|
52436
|
+
}
|
|
52437
|
+
}
|
|
52438
|
+
function replayRolloutAfterExit(context, state) {
|
|
52263
52439
|
const runtimeSessionId = state.runtimeSessionId;
|
|
52264
52440
|
if (!runtimeSessionId) return;
|
|
52265
52441
|
if (!state.iterations || state.iterations <= 0) return;
|
|
@@ -53007,7 +53183,8 @@ function ensureCodexWorkerEventPolling(context, state) {
|
|
|
53007
53183
|
drain: () => {
|
|
53008
53184
|
const before = replayProgress(state);
|
|
53009
53185
|
syncCodexWorkerEventsFromSessionLog(context, state);
|
|
53010
|
-
|
|
53186
|
+
const images2 = syncCodexImageGenerationFromSessionLog(context, state);
|
|
53187
|
+
if (replayProgress(state) > before || images2 > 0) state.onNewOutput?.();
|
|
53011
53188
|
}
|
|
53012
53189
|
});
|
|
53013
53190
|
state.providerTranscriptTail = tail;
|
|
@@ -54466,8 +54643,8 @@ function handleToolComplete(event, context, state) {
|
|
|
54466
54643
|
{
|
|
54467
54644
|
resultText: text2,
|
|
54468
54645
|
isError: success2 ? void 0 : true,
|
|
54469
|
-
emitToolResult: (launcherId,
|
|
54470
|
-
updates.push(settlementUpdate(launcherId,
|
|
54646
|
+
emitToolResult: (launcherId, settled2, isError) => {
|
|
54647
|
+
updates.push(settlementUpdate(launcherId, settled2, isError));
|
|
54471
54648
|
}
|
|
54472
54649
|
}
|
|
54473
54650
|
);
|
|
@@ -54484,8 +54661,8 @@ function activeTaskIdNamedIn(state, content) {
|
|
|
54484
54661
|
}
|
|
54485
54662
|
function writeCopilotMcpConfig(registration) {
|
|
54486
54663
|
if (!registration) return null;
|
|
54487
|
-
const dir = (0, import_fs15.mkdtempSync)((0,
|
|
54488
|
-
const path2 = (0,
|
|
54664
|
+
const dir = (0, import_fs15.mkdtempSync)((0, import_path16.join)((0, import_os7.tmpdir)(), "alan-copilot-mcp-"));
|
|
54665
|
+
const path2 = (0, import_path16.join)(dir, "mcp-config.json");
|
|
54489
54666
|
(0, import_fs15.writeFileSync)(
|
|
54490
54667
|
path2,
|
|
54491
54668
|
JSON.stringify({
|
|
@@ -54503,12 +54680,12 @@ function writeCopilotMcpConfig(registration) {
|
|
|
54503
54680
|
return { path: path2, cleanup: () => (0, import_fs15.rmSync)(dir, { recursive: true, force: true }) };
|
|
54504
54681
|
}
|
|
54505
54682
|
function resolveCopilotHome(env) {
|
|
54506
|
-
return env.COPILOT_HOME || (0,
|
|
54683
|
+
return env.COPILOT_HOME || (0, import_path17.join)(env.HOME || (0, import_os8.homedir)(), ".copilot");
|
|
54507
54684
|
}
|
|
54508
54685
|
function copilotSessionPresence(sessionId, home) {
|
|
54509
|
-
const stateRoot = (0,
|
|
54686
|
+
const stateRoot = (0, import_path17.join)(home, "session-state");
|
|
54510
54687
|
if (!(0, import_fs16.existsSync)(stateRoot)) return "unknown";
|
|
54511
|
-
return (0, import_fs16.existsSync)((0,
|
|
54688
|
+
return (0, import_fs16.existsSync)((0, import_path17.join)(stateRoot, sessionId, "events.jsonl")) ? "present" : "missing";
|
|
54512
54689
|
}
|
|
54513
54690
|
function freshSession(contextPrefix) {
|
|
54514
54691
|
const sessionId = (0, import_crypto8.randomUUID)();
|
|
@@ -55128,9 +55305,9 @@ function cursorSubagentConversationStepUpdates(steps, parentToolUseId2) {
|
|
|
55128
55305
|
if (!entry) return;
|
|
55129
55306
|
const args = cursorToolArgs(entry);
|
|
55130
55307
|
const toolCallId = asString(args.toolCallId) || asString(args.tool_call_id) || messageId;
|
|
55131
|
-
const
|
|
55132
|
-
const failed =
|
|
55133
|
-
const text2 =
|
|
55308
|
+
const settled2 = entry.payload.result !== void 0;
|
|
55309
|
+
const failed = settled2 && cursorResultVariant(entry.payload.result, "error") !== null;
|
|
55310
|
+
const text2 = settled2 ? buildCursorToolResultText(entry.payload.result) : "";
|
|
55134
55311
|
const name = formatCursorToolName(entry.rawName, entry.payload);
|
|
55135
55312
|
updates.push({
|
|
55136
55313
|
sessionUpdate: "tool_call_update",
|
|
@@ -55138,11 +55315,11 @@ function cursorSubagentConversationStepUpdates(steps, parentToolUseId2) {
|
|
|
55138
55315
|
name,
|
|
55139
55316
|
title: name,
|
|
55140
55317
|
kind: toolKindFor(name),
|
|
55141
|
-
status:
|
|
55318
|
+
status: settled2 ? failed ? "failed" : "completed" : "in_progress",
|
|
55142
55319
|
rawInput: args,
|
|
55143
55320
|
// `rawOutput` is what the provider said, `content` is what a reader renders;
|
|
55144
55321
|
// writing only the first left a replayed child tool showing no output.
|
|
55145
|
-
...
|
|
55322
|
+
...settled2 ? {
|
|
55146
55323
|
rawOutput: text2,
|
|
55147
55324
|
content: [
|
|
55148
55325
|
...failed ? [] : cursorFileChangeContent(entry.rawName, args, entry.payload.result),
|
|
@@ -55151,7 +55328,7 @@ function cursorSubagentConversationStepUpdates(steps, parentToolUseId2) {
|
|
|
55151
55328
|
} : {},
|
|
55152
55329
|
_meta: {
|
|
55153
55330
|
...childMeta(parentToolUseId2),
|
|
55154
|
-
...
|
|
55331
|
+
...settled2 ? { [PROVIDER_PAYLOAD_META]: entry.payload.result } : {}
|
|
55155
55332
|
}
|
|
55156
55333
|
});
|
|
55157
55334
|
});
|
|
@@ -55175,10 +55352,10 @@ function cursorConversationStepText(steps) {
|
|
|
55175
55352
|
function cursorTranscriptsRoot(context) {
|
|
55176
55353
|
const projectKey = context.cwd.replace(/^[/\\]+/, "").replace(/[/\\]+/g, "-");
|
|
55177
55354
|
const home = context.env.HOME || process.env.HOME || (0, import_os9.homedir)();
|
|
55178
|
-
return (0,
|
|
55355
|
+
return (0, import_path18.join)(home, ".cursor", "projects", projectKey, "agent-transcripts");
|
|
55179
55356
|
}
|
|
55180
55357
|
function cursorTranscriptPathForAgent(context, agentId) {
|
|
55181
|
-
return (0,
|
|
55358
|
+
return (0, import_path18.join)(cursorTranscriptsRoot(context), agentId, `${agentId}.jsonl`);
|
|
55182
55359
|
}
|
|
55183
55360
|
function resolveCursorSubagentTranscriptPath(success2, context) {
|
|
55184
55361
|
const explicit = success2?.transcriptPath ?? success2?.transcript_path;
|
|
@@ -55548,10 +55725,10 @@ function workspaceKeys(cwd) {
|
|
|
55548
55725
|
);
|
|
55549
55726
|
}
|
|
55550
55727
|
function cursorChatPresence(query) {
|
|
55551
|
-
const chatsRoot = (0,
|
|
55728
|
+
const chatsRoot = (0, import_path19.join)(query.home, ".cursor", "chats");
|
|
55552
55729
|
if (!(0, import_fs18.existsSync)(chatsRoot)) return "unknown";
|
|
55553
55730
|
const found = workspaceKeys(query.cwd).some(
|
|
55554
|
-
(key) => (0, import_fs18.existsSync)((0,
|
|
55731
|
+
(key) => (0, import_fs18.existsSync)((0, import_path19.join)(chatsRoot, key, query.chatId, "store.db"))
|
|
55555
55732
|
);
|
|
55556
55733
|
return found ? "present" : "missing";
|
|
55557
55734
|
}
|
|
@@ -56009,8 +56186,8 @@ function handleToolResult(event, context, state) {
|
|
|
56009
56186
|
const text2 = droidToolResultText(event.value);
|
|
56010
56187
|
const isError = event.isError === true;
|
|
56011
56188
|
const updates = [];
|
|
56012
|
-
const emitToolResult = (launcherId,
|
|
56013
|
-
updates.push(settlementUpdate2(launcherId,
|
|
56189
|
+
const emitToolResult = (launcherId, settled2, failed) => {
|
|
56190
|
+
updates.push(settlementUpdate2(launcherId, settled2, failed));
|
|
56014
56191
|
};
|
|
56015
56192
|
const polledTaskId = polledTaskIdByToolId.get(state)?.get(toolCallId);
|
|
56016
56193
|
if (polledTaskId) {
|
|
@@ -57520,7 +57697,7 @@ function kimiCliDialectFromHelp(help) {
|
|
|
57520
57697
|
}
|
|
57521
57698
|
function readHelp(command, context) {
|
|
57522
57699
|
return new Promise((resolve52) => {
|
|
57523
|
-
(0,
|
|
57700
|
+
(0, import_child_process8.execFile)(
|
|
57524
57701
|
command,
|
|
57525
57702
|
["--help"],
|
|
57526
57703
|
{
|
|
@@ -57564,8 +57741,8 @@ function createKimiCliBackend(command = "kimi", defaultArgs = []) {
|
|
|
57564
57741
|
async run(context) {
|
|
57565
57742
|
const dialect = await detectKimiCliDialect(command, context);
|
|
57566
57743
|
const registration = dialect === "kimi-cli" ? context.config.alanMcp : void 0;
|
|
57567
|
-
const mcpDirectory = registration ? (0, import_fs19.mkdtempSync)((0,
|
|
57568
|
-
const mcpConfigPath = mcpDirectory ? (0,
|
|
57744
|
+
const mcpDirectory = registration ? (0, import_fs19.mkdtempSync)((0, import_path20.join)((0, import_os11.tmpdir)(), "alan-kimi-mcp-")) : null;
|
|
57745
|
+
const mcpConfigPath = mcpDirectory ? (0, import_path20.join)(mcpDirectory, "mcp.json") : null;
|
|
57569
57746
|
if (registration && mcpConfigPath) {
|
|
57570
57747
|
(0, import_fs19.writeFileSync)(
|
|
57571
57748
|
mcpConfigPath,
|
|
@@ -59236,8 +59413,8 @@ function readNativeTranscriptTurns(provider, chunk, baseOffset, skipped = []) {
|
|
|
59236
59413
|
const records = draftLines.map((line) => line.record).filter(isRecordValue);
|
|
59237
59414
|
const closing = transcript.closingUpdates(records, state);
|
|
59238
59415
|
const error61 = turnError(draftLines, transcript);
|
|
59239
|
-
const
|
|
59240
|
-
if (!hasContent && !
|
|
59416
|
+
const settled2 = index < drafts.length - 1 || error61 !== null || endsIdle([...updates.map((entry) => entry.update), ...closing]);
|
|
59417
|
+
if (!hasContent && !settled2) {
|
|
59241
59418
|
if (index === drafts.length - 1) consumedEnd = draftLines[0].offset;
|
|
59242
59419
|
return;
|
|
59243
59420
|
}
|
|
@@ -59684,10 +59861,10 @@ var RuntimeRunHost = class extends BaseRunHost {
|
|
|
59684
59861
|
completion = Promise.reject(error61);
|
|
59685
59862
|
}
|
|
59686
59863
|
}
|
|
59687
|
-
const
|
|
59688
|
-
this.orderedDeliveryTail =
|
|
59689
|
-
void
|
|
59690
|
-
if (this.orderedDeliveryTail ===
|
|
59864
|
+
const settled2 = completion.catch(() => void 0);
|
|
59865
|
+
this.orderedDeliveryTail = settled2;
|
|
59866
|
+
void settled2.then(() => {
|
|
59867
|
+
if (this.orderedDeliveryTail === settled2) {
|
|
59691
59868
|
this.orderedDeliveryTail = void 0;
|
|
59692
59869
|
this.orderedDeliveryLeaseGate = void 0;
|
|
59693
59870
|
}
|
|
@@ -61518,11 +61695,11 @@ var SocketWithoutUpgrade = class _SocketWithoutUpgrade extends Emitter {
|
|
|
61518
61695
|
*/
|
|
61519
61696
|
_resetPingTimeout() {
|
|
61520
61697
|
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
61521
|
-
const
|
|
61522
|
-
this._pingTimeoutTime = Date.now() +
|
|
61698
|
+
const delay5 = this._pingInterval + this._pingTimeout;
|
|
61699
|
+
this._pingTimeoutTime = Date.now() + delay5;
|
|
61523
61700
|
this._pingTimeoutTimer = this.setTimeoutFn(() => {
|
|
61524
61701
|
this._onClose("ping timeout");
|
|
61525
|
-
},
|
|
61702
|
+
}, delay5);
|
|
61526
61703
|
if (this.opts.autoUnref) {
|
|
61527
61704
|
this._pingTimeoutTimer.unref();
|
|
61528
61705
|
}
|
|
@@ -61989,7 +62166,7 @@ function deconstructPacket(packet) {
|
|
|
61989
62166
|
pack2.attachments = buffers.length;
|
|
61990
62167
|
return { packet: pack2, buffers };
|
|
61991
62168
|
}
|
|
61992
|
-
function _deconstructPacket(data, buffers) {
|
|
62169
|
+
function _deconstructPacket(data, buffers, toJSON) {
|
|
61993
62170
|
if (!data)
|
|
61994
62171
|
return data;
|
|
61995
62172
|
if (isBinary(data)) {
|
|
@@ -62003,6 +62180,9 @@ function _deconstructPacket(data, buffers) {
|
|
|
62003
62180
|
}
|
|
62004
62181
|
return newData;
|
|
62005
62182
|
} else if (typeof data === "object" && !(data instanceof Date)) {
|
|
62183
|
+
if (data.toJSON && typeof data.toJSON === "function" && !toJSON) {
|
|
62184
|
+
return _deconstructPacket(data.toJSON(), buffers, true);
|
|
62185
|
+
}
|
|
62006
62186
|
const newData = {};
|
|
62007
62187
|
for (const key in data) {
|
|
62008
62188
|
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
@@ -62159,9 +62339,6 @@ var Decoder = class _Decoder extends Emitter {
|
|
|
62159
62339
|
if (isBinaryEvent || packet.type === PacketType.BINARY_ACK) {
|
|
62160
62340
|
packet.type = isBinaryEvent ? PacketType.EVENT : PacketType.ACK;
|
|
62161
62341
|
this.reconstructor = new BinaryReconstructor(packet);
|
|
62162
|
-
if (packet.attachments === 0) {
|
|
62163
|
-
super.emitReserved("decoded", packet);
|
|
62164
|
-
}
|
|
62165
62342
|
} else {
|
|
62166
62343
|
super.emitReserved("decoded", packet);
|
|
62167
62344
|
}
|
|
@@ -62202,7 +62379,7 @@ var Decoder = class _Decoder extends Emitter {
|
|
|
62202
62379
|
throw new Error("Illegal attachments");
|
|
62203
62380
|
}
|
|
62204
62381
|
const n = Number(buf);
|
|
62205
|
-
if (!isInteger(n) || n <
|
|
62382
|
+
if (!isInteger(n) || n < 1) {
|
|
62206
62383
|
throw new Error("Illegal attachments");
|
|
62207
62384
|
} else if (n > this.opts.maxAttachments) {
|
|
62208
62385
|
throw new Error("too many attachments");
|
|
@@ -63503,8 +63680,8 @@ var Manager = class extends Emitter {
|
|
|
63503
63680
|
this.emitReserved("reconnect_failed");
|
|
63504
63681
|
this._reconnecting = false;
|
|
63505
63682
|
} else {
|
|
63506
|
-
const
|
|
63507
|
-
debug10("will wait %dms before reconnect attempt",
|
|
63683
|
+
const delay5 = this.backoff.duration();
|
|
63684
|
+
debug10("will wait %dms before reconnect attempt", delay5);
|
|
63508
63685
|
this._reconnecting = true;
|
|
63509
63686
|
const timer = this.setTimeoutFn(() => {
|
|
63510
63687
|
if (self.skipReconnect)
|
|
@@ -63524,7 +63701,7 @@ var Manager = class extends Emitter {
|
|
|
63524
63701
|
self.onreconnect();
|
|
63525
63702
|
}
|
|
63526
63703
|
});
|
|
63527
|
-
},
|
|
63704
|
+
}, delay5);
|
|
63528
63705
|
if (this.opts.autoUnref) {
|
|
63529
63706
|
timer.unref();
|
|
63530
63707
|
}
|
|
@@ -63749,11 +63926,11 @@ function removeNativeHooks(homeDir = (0, import_node_os14.homedir)()) {
|
|
|
63749
63926
|
}
|
|
63750
63927
|
|
|
63751
63928
|
// src/events/runtime-command-reply.ts
|
|
63752
|
-
var
|
|
63929
|
+
var import_promises6 = require("timers/promises");
|
|
63753
63930
|
async function publishRuntimeCommandReply(path2, reply, credentials) {
|
|
63754
63931
|
const body = JSON.stringify(reply);
|
|
63755
63932
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
63756
|
-
if (attempt > 0) await (0,
|
|
63933
|
+
if (attempt > 0) await (0, import_promises6.setTimeout)(250, void 0, { signal: credentials.signal });
|
|
63757
63934
|
credentials.signal.throwIfAborted();
|
|
63758
63935
|
let response;
|
|
63759
63936
|
try {
|
|
@@ -63790,7 +63967,7 @@ var import_node_fs19 = require("fs");
|
|
|
63790
63967
|
// src/events/live.ts
|
|
63791
63968
|
var import_node_crypto9 = require("crypto");
|
|
63792
63969
|
var import_node_fs17 = require("fs");
|
|
63793
|
-
var
|
|
63970
|
+
var import_promises9 = require("fs/promises");
|
|
63794
63971
|
|
|
63795
63972
|
// src/events/http-retry.ts
|
|
63796
63973
|
var TranscriptRequestError = class extends Error {
|
|
@@ -63851,7 +64028,7 @@ function requestDeadline(timeoutMs, parent) {
|
|
|
63851
64028
|
// src/events/push.ts
|
|
63852
64029
|
var import_node_crypto8 = require("crypto");
|
|
63853
64030
|
var import_node_fs16 = require("fs");
|
|
63854
|
-
var
|
|
64031
|
+
var import_promises8 = require("fs/promises");
|
|
63855
64032
|
|
|
63856
64033
|
// src/events/session.ts
|
|
63857
64034
|
var import_node_fs15 = require("fs");
|
|
@@ -64060,7 +64237,7 @@ function writeRunTranscriptState(configPath, conversationId, runId, state) {
|
|
|
64060
64237
|
}
|
|
64061
64238
|
|
|
64062
64239
|
// src/events/transcript-buffer.ts
|
|
64063
|
-
var
|
|
64240
|
+
var import_promises7 = require("fs/promises");
|
|
64064
64241
|
var RETAINED_BYTES = 256 * 1024;
|
|
64065
64242
|
var MAX_PENDING_TRANSCRIPT_BYTES = 8 * 1024 * 1024;
|
|
64066
64243
|
var TranscriptBuffer = class {
|
|
@@ -64120,7 +64297,7 @@ function closeTranscriptBuffer(path2, buffer) {
|
|
|
64120
64297
|
async function retryTranscriptWrites(path2, runId) {
|
|
64121
64298
|
const buffer = active.get(path2);
|
|
64122
64299
|
if (!buffer || buffer.runId !== runId) return void 0;
|
|
64123
|
-
const file2 = await (0,
|
|
64300
|
+
const file2 = await (0, import_promises7.open)(path2, "r+");
|
|
64124
64301
|
try {
|
|
64125
64302
|
const stat4 = await file2.stat();
|
|
64126
64303
|
if (`${stat4.dev}.${stat4.ino}.${stat4.birthtimeMs}` !== buffer.generation)
|
|
@@ -64520,7 +64697,7 @@ function startTranscriptPush(target, onProblem) {
|
|
|
64520
64697
|
const current = state();
|
|
64521
64698
|
if (!current) throw new Error("Transcript run range disappeared");
|
|
64522
64699
|
const end = Math.min(boundary, admitted + adaptivePushBytes);
|
|
64523
|
-
const file2 = await (0,
|
|
64700
|
+
const file2 = await (0, import_promises8.open)(path2, "r");
|
|
64524
64701
|
let bytes;
|
|
64525
64702
|
try {
|
|
64526
64703
|
bytes = Buffer.alloc(end - admitted);
|
|
@@ -64597,9 +64774,9 @@ function startTranscriptPush(target, onProblem) {
|
|
|
64597
64774
|
});
|
|
64598
64775
|
return running;
|
|
64599
64776
|
};
|
|
64600
|
-
const schedule = (
|
|
64777
|
+
const schedule = (delay5) => {
|
|
64601
64778
|
if (stopped || target.signal?.aborted) return;
|
|
64602
|
-
const at = Math.max(Date.now() +
|
|
64779
|
+
const at = Math.max(Date.now() + delay5, retryNotBefore);
|
|
64603
64780
|
if (timer && scheduledAt <= at) return;
|
|
64604
64781
|
clearTimeout(timer);
|
|
64605
64782
|
scheduledAt = at;
|
|
@@ -64619,7 +64796,7 @@ function startTranscriptPush(target, onProblem) {
|
|
|
64619
64796
|
schedule(0);
|
|
64620
64797
|
return;
|
|
64621
64798
|
}
|
|
64622
|
-
let
|
|
64799
|
+
let delay5 = cached2 && (cached2.committedOffset < cached2.admittedOffset || cached2.finalOffset !== null && !cached2.finalized) ? Math.max(0, pollAt - Date.now()) : Number.POSITIVE_INFINITY;
|
|
64623
64800
|
try {
|
|
64624
64801
|
if (state()?.finalRequested && cached2?.finalOffset == null) {
|
|
64625
64802
|
schedule(0);
|
|
@@ -64627,13 +64804,13 @@ function startTranscriptPush(target, onProblem) {
|
|
|
64627
64804
|
}
|
|
64628
64805
|
const remaining = size() - (cached2?.admittedOffset ?? 0);
|
|
64629
64806
|
if (remaining > 0)
|
|
64630
|
-
|
|
64631
|
-
|
|
64807
|
+
delay5 = Math.min(
|
|
64808
|
+
delay5,
|
|
64632
64809
|
remaining >= MAX_PUSH_BYTES ? 0 : Math.max(0, checkpointAt - Date.now())
|
|
64633
64810
|
);
|
|
64634
64811
|
} catch {
|
|
64635
64812
|
}
|
|
64636
|
-
if (Number.isFinite(
|
|
64813
|
+
if (Number.isFinite(delay5)) schedule(delay5);
|
|
64637
64814
|
};
|
|
64638
64815
|
return {
|
|
64639
64816
|
notify() {
|
|
@@ -64763,7 +64940,7 @@ function startTranscriptLive(target, onProblem) {
|
|
|
64763
64940
|
if (active2 && from < active2.retainedFrom)
|
|
64764
64941
|
length = Math.min(length, active2.retainedFrom - from);
|
|
64765
64942
|
bytes = Buffer.alloc(length);
|
|
64766
|
-
const file2 = await (0,
|
|
64943
|
+
const file2 = await (0, import_promises9.open)(path2, "r");
|
|
64767
64944
|
try {
|
|
64768
64945
|
const read = await file2.read(bytes, 0, length, from);
|
|
64769
64946
|
if (read.bytesRead !== length) throw new Error("Live transcript changed during read");
|
|
@@ -64779,9 +64956,9 @@ function startTranscriptLive(target, onProblem) {
|
|
|
64779
64956
|
received = receipt.receivedOffset;
|
|
64780
64957
|
}
|
|
64781
64958
|
};
|
|
64782
|
-
const schedule = (
|
|
64959
|
+
const schedule = (delay5) => {
|
|
64783
64960
|
if (stopped || signal.aborted) return;
|
|
64784
|
-
const at = Math.max(Date.now() +
|
|
64961
|
+
const at = Math.max(Date.now() + delay5, retryNotBefore);
|
|
64785
64962
|
if (timer && scheduledAt <= at) return;
|
|
64786
64963
|
clearTimeout(timer);
|
|
64787
64964
|
scheduledAt = at;
|
|
@@ -65311,7 +65488,7 @@ function createTranscriptWatchRegistry() {
|
|
|
65311
65488
|
|
|
65312
65489
|
// src/native/ingest.ts
|
|
65313
65490
|
var import_node_fs21 = require("fs");
|
|
65314
|
-
var
|
|
65491
|
+
var import_promises11 = require("fs/promises");
|
|
65315
65492
|
|
|
65316
65493
|
// src/native/alan-runs.ts
|
|
65317
65494
|
function nativeProviderForBackend(backendKind) {
|
|
@@ -65650,7 +65827,7 @@ function reconcileTranscriptIdentity(entry, transcriptPath2, identity, size) {
|
|
|
65650
65827
|
|
|
65651
65828
|
// src/native/turns.ts
|
|
65652
65829
|
var import_node_crypto11 = require("crypto");
|
|
65653
|
-
var
|
|
65830
|
+
var import_promises10 = require("fs/promises");
|
|
65654
65831
|
var SCAN_BYTES = 1024 * 1024;
|
|
65655
65832
|
var MIN_READ_BYTES = 64 * 1024;
|
|
65656
65833
|
var SKIPPED_RECORD_LINE = Buffer.from("\n");
|
|
@@ -65697,7 +65874,7 @@ async function findRecordEnd(handle, from, size) {
|
|
|
65697
65874
|
return null;
|
|
65698
65875
|
}
|
|
65699
65876
|
async function readTranscriptWindow(path2, offset2, limits) {
|
|
65700
|
-
const handle = await (0,
|
|
65877
|
+
const handle = await (0, import_promises10.open)(path2, "r");
|
|
65701
65878
|
try {
|
|
65702
65879
|
const stats = await handle.stat({ bigint: true });
|
|
65703
65880
|
const size = Number(stats.size);
|
|
@@ -66145,9 +66322,9 @@ function createNativeIngestionSink(deps) {
|
|
|
66145
66322
|
eligible = [];
|
|
66146
66323
|
} else {
|
|
66147
66324
|
const index = lastMatchingTurnIndex(turns, target);
|
|
66148
|
-
const
|
|
66149
|
-
if (index < 0 &&
|
|
66150
|
-
await sleep2(
|
|
66325
|
+
const delay5 = lagDelays.shift();
|
|
66326
|
+
if (index < 0 && delay5 !== void 0) {
|
|
66327
|
+
await sleep2(delay5, shutdown.signal);
|
|
66151
66328
|
continue;
|
|
66152
66329
|
}
|
|
66153
66330
|
if (index < 0 && turns.length > 0)
|
|
@@ -66224,7 +66401,7 @@ function createNativeIngestionSink(deps) {
|
|
|
66224
66401
|
store.put(entry);
|
|
66225
66402
|
if (ending) log3("native-ingest-turn", worker, "closed");
|
|
66226
66403
|
}
|
|
66227
|
-
const current = await (0,
|
|
66404
|
+
const current = await (0, import_promises11.stat)(path2).catch(() => void 0);
|
|
66228
66405
|
return { grewDuringPass: current !== void 0 && current.size > lastSize };
|
|
66229
66406
|
};
|
|
66230
66407
|
const handleFailure = (worker, error61) => {
|
|
@@ -66711,12 +66888,12 @@ var RuntimeSkillCoordinator = class {
|
|
|
66711
66888
|
// src/skills/runtime-skill-manager.ts
|
|
66712
66889
|
var import_node_buffer5 = require("buffer");
|
|
66713
66890
|
var import_node_crypto14 = require("crypto");
|
|
66714
|
-
var
|
|
66891
|
+
var import_promises14 = require("fs/promises");
|
|
66715
66892
|
var import_node_path24 = require("path");
|
|
66716
66893
|
|
|
66717
66894
|
// src/skills/managed-skill-store.ts
|
|
66718
66895
|
var import_node_crypto12 = require("crypto");
|
|
66719
|
-
var
|
|
66896
|
+
var import_promises12 = require("fs/promises");
|
|
66720
66897
|
var import_node_path22 = require("path");
|
|
66721
66898
|
var EMPTY_STATE = {
|
|
66722
66899
|
version: 1,
|
|
@@ -66732,9 +66909,9 @@ var ManagedSkillStore = class _ManagedSkillStore {
|
|
|
66732
66909
|
state;
|
|
66733
66910
|
integrity;
|
|
66734
66911
|
static async open(baseDirectory) {
|
|
66735
|
-
await (0,
|
|
66912
|
+
await (0, import_promises12.mkdir)(baseDirectory, { recursive: true, mode: 448 });
|
|
66736
66913
|
try {
|
|
66737
|
-
const parsed = JSON.parse(await (0,
|
|
66914
|
+
const parsed = JSON.parse(await (0, import_promises12.readFile)((0, import_node_path22.join)(baseDirectory, "state.json"), "utf8"));
|
|
66738
66915
|
return new _ManagedSkillStore(baseDirectory, parseState(parsed), "verified");
|
|
66739
66916
|
} catch (error61) {
|
|
66740
66917
|
if (isMissingPath(error61)) {
|
|
@@ -66798,15 +66975,15 @@ var ManagedSkillStore = class _ManagedSkillStore {
|
|
|
66798
66975
|
`.state.json.pending-${process.pid}-${(0, import_node_crypto12.randomBytes)(6).toString("hex")}`
|
|
66799
66976
|
);
|
|
66800
66977
|
try {
|
|
66801
|
-
await (0,
|
|
66978
|
+
await (0, import_promises12.writeFile)(pendingPath, `${JSON.stringify(this.state, null, 2)}
|
|
66802
66979
|
`, {
|
|
66803
66980
|
encoding: "utf8",
|
|
66804
66981
|
flag: "wx",
|
|
66805
66982
|
mode: 384
|
|
66806
66983
|
});
|
|
66807
|
-
await (0,
|
|
66984
|
+
await (0, import_promises12.rename)(pendingPath, statePath);
|
|
66808
66985
|
} finally {
|
|
66809
|
-
await (0,
|
|
66986
|
+
await (0, import_promises12.rm)(pendingPath, { force: true });
|
|
66810
66987
|
}
|
|
66811
66988
|
}
|
|
66812
66989
|
};
|
|
@@ -66861,7 +67038,7 @@ function isMissingPath(error61) {
|
|
|
66861
67038
|
// ../shared/dist/node/skill-bundle.js
|
|
66862
67039
|
var import_node_buffer3 = require("buffer");
|
|
66863
67040
|
var import_node_crypto13 = require("crypto");
|
|
66864
|
-
var
|
|
67041
|
+
var import_promises13 = require("fs/promises");
|
|
66865
67042
|
var import_node_path23 = require("path");
|
|
66866
67043
|
var import_node_stream = require("stream");
|
|
66867
67044
|
var import_node_zlib = require("zlib");
|
|
@@ -66871,7 +67048,7 @@ async function createSkillBundle(packageRoot, options = {}) {
|
|
|
66871
67048
|
const archive = (0, import_tar_stream.pack)();
|
|
66872
67049
|
const tarPromise = collectStream(archive);
|
|
66873
67050
|
for (const file2 of before.files) {
|
|
66874
|
-
const bytes2 = await (0,
|
|
67051
|
+
const bytes2 = await (0, import_promises13.readFile)((0, import_node_path23.join)(packageRoot, ...file2.path.split("/")));
|
|
66875
67052
|
await addArchiveEntry(archive, {
|
|
66876
67053
|
name: file2.path,
|
|
66877
67054
|
type: "file",
|
|
@@ -66903,7 +67080,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
|
|
|
66903
67080
|
throw new Error("Skill archive hash does not match the expected immutable Version");
|
|
66904
67081
|
}
|
|
66905
67082
|
const tarBytes = await decompressBounded(archiveBytes);
|
|
66906
|
-
await (0,
|
|
67083
|
+
await (0, import_promises13.mkdir)(destination, { recursive: false, mode: 448 });
|
|
66907
67084
|
try {
|
|
66908
67085
|
await extractTar(tarBytes, destination);
|
|
66909
67086
|
const inspected = await inspectSkillPackage(destination, { expectedName: null });
|
|
@@ -66911,7 +67088,7 @@ async function extractSkillBundle(archiveBytes, destination, expected) {
|
|
|
66911
67088
|
throw new Error("Extracted Skill package hash does not match the expected immutable Version");
|
|
66912
67089
|
}
|
|
66913
67090
|
} catch (error61) {
|
|
66914
|
-
await (0,
|
|
67091
|
+
await (0, import_promises13.rm)(destination, { recursive: true, force: true });
|
|
66915
67092
|
throw error61;
|
|
66916
67093
|
}
|
|
66917
67094
|
}
|
|
@@ -66987,8 +67164,8 @@ async function extractEntry(header, stream, destination, limits) {
|
|
|
66987
67164
|
throw new Error(`Skill archive file size is invalid: ${path2}`);
|
|
66988
67165
|
}
|
|
66989
67166
|
const outputPath = (0, import_node_path23.join)(destination, ...path2.split("/"));
|
|
66990
|
-
await (0,
|
|
66991
|
-
await (0,
|
|
67167
|
+
await (0, import_promises13.mkdir)((0, import_node_path23.dirname)(outputPath), { recursive: true, mode: 448 });
|
|
67168
|
+
await (0, import_promises13.writeFile)(outputPath, bytes, { mode: (header.mode ?? 420) & 73 ? 493 : 420 });
|
|
66992
67169
|
}
|
|
66993
67170
|
function requireSafeArchivePath(value2) {
|
|
66994
67171
|
const normalized2 = value2.replaceAll("\\", "/").normalize("NFC");
|
|
@@ -67248,12 +67425,12 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67248
67425
|
}
|
|
67249
67426
|
async reconcileUnlocked(manifest) {
|
|
67250
67427
|
const desired = desiredSkillManifestSchema.parse(manifest);
|
|
67251
|
-
await (0,
|
|
67252
|
-
await (0,
|
|
67428
|
+
await (0, import_promises14.mkdir)(this.managedSkillsDirectory, { recursive: true, mode: 448 });
|
|
67429
|
+
await (0, import_promises14.mkdir)((0, import_node_path24.join)(this.skillsStateDirectory, "cache", "sha256"), {
|
|
67253
67430
|
recursive: true,
|
|
67254
67431
|
mode: 448
|
|
67255
67432
|
});
|
|
67256
|
-
await (0,
|
|
67433
|
+
await (0, import_promises14.mkdir)((0, import_node_path24.join)(this.skillsStateDirectory, "tmp"), { recursive: true, mode: 448 });
|
|
67257
67434
|
const results = [];
|
|
67258
67435
|
const nextProjections = {};
|
|
67259
67436
|
for (const entry of desired.skills) {
|
|
@@ -67376,52 +67553,52 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67376
67553
|
let sourceMoved = false;
|
|
67377
67554
|
let destinationInstalled = false;
|
|
67378
67555
|
try {
|
|
67379
|
-
await (0,
|
|
67556
|
+
await (0, import_promises14.rename)(source2, backup);
|
|
67380
67557
|
sourceMoved = true;
|
|
67381
|
-
await (0,
|
|
67558
|
+
await (0, import_promises14.cp)(backup, pending, { recursive: true, errorOnExist: true, force: false });
|
|
67382
67559
|
const skillMarkdown = (0, import_node_path24.join)(pending, "SKILL.md");
|
|
67383
|
-
await (0,
|
|
67560
|
+
await (0, import_promises14.writeFile)(
|
|
67384
67561
|
skillMarkdown,
|
|
67385
|
-
rewriteSkillMarkdownName(await (0,
|
|
67562
|
+
rewriteSkillMarkdownName(await (0, import_promises14.readFile)(skillMarkdown, "utf8"), name),
|
|
67386
67563
|
{
|
|
67387
67564
|
encoding: "utf8",
|
|
67388
67565
|
mode: 420
|
|
67389
67566
|
}
|
|
67390
67567
|
);
|
|
67391
67568
|
await inspectSkillPackage(pending, { expectedName: name });
|
|
67392
|
-
await (0,
|
|
67569
|
+
await (0, import_promises14.rename)(pending, destination);
|
|
67393
67570
|
destinationInstalled = true;
|
|
67394
|
-
await (0,
|
|
67571
|
+
await (0, import_promises14.rm)(backup, { recursive: true, force: true });
|
|
67395
67572
|
} catch (error61) {
|
|
67396
|
-
if (destinationInstalled) await (0,
|
|
67573
|
+
if (destinationInstalled) await (0, import_promises14.rm)(destination, { recursive: true, force: true });
|
|
67397
67574
|
if (sourceMoved && await pathExists2(backup) && !await pathExists2(source2)) {
|
|
67398
|
-
await (0,
|
|
67575
|
+
await (0, import_promises14.rename)(backup, source2);
|
|
67399
67576
|
}
|
|
67400
67577
|
throw error61;
|
|
67401
67578
|
} finally {
|
|
67402
|
-
await (0,
|
|
67579
|
+
await (0, import_promises14.rm)(pending, { recursive: true, force: true });
|
|
67403
67580
|
if (!sourceMoved || destinationInstalled) {
|
|
67404
|
-
await (0,
|
|
67581
|
+
await (0, import_promises14.rm)(backup, { recursive: true, force: true });
|
|
67405
67582
|
}
|
|
67406
67583
|
}
|
|
67407
67584
|
}
|
|
67408
67585
|
async overwriteLocalConflict(input2, entry, conflict, manifest) {
|
|
67409
67586
|
const source2 = this.conflictDirectory(entry.runtimeDirectory, conflict.kind);
|
|
67410
67587
|
const backup = `${source2}.overwrite-backup-${process.pid}-${(0, import_node_crypto14.randomBytes)(8).toString("hex")}`;
|
|
67411
|
-
await (0,
|
|
67588
|
+
await (0, import_promises14.rename)(source2, backup);
|
|
67412
67589
|
try {
|
|
67413
67590
|
const reconciled = await this.reconcileUnlocked(manifest);
|
|
67414
67591
|
const result = resolutionFromReconcile(input2, reconciled);
|
|
67415
67592
|
if (result.state !== "applied") {
|
|
67416
67593
|
await this.removeResolvedProjection(entry, conflict.kind);
|
|
67417
|
-
await (0,
|
|
67594
|
+
await (0, import_promises14.rename)(backup, source2);
|
|
67418
67595
|
return result;
|
|
67419
67596
|
}
|
|
67420
|
-
await (0,
|
|
67597
|
+
await (0, import_promises14.rm)(backup, { recursive: true, force: true });
|
|
67421
67598
|
return result;
|
|
67422
67599
|
} catch (error61) {
|
|
67423
67600
|
await this.removeResolvedProjection(entry, conflict.kind).catch(() => void 0);
|
|
67424
|
-
if (!await pathExists2(source2) && await pathExists2(backup)) await (0,
|
|
67601
|
+
if (!await pathExists2(source2) && await pathExists2(backup)) await (0, import_promises14.rename)(backup, source2);
|
|
67425
67602
|
throw error61;
|
|
67426
67603
|
}
|
|
67427
67604
|
}
|
|
@@ -67431,7 +67608,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67431
67608
|
if (conflictKind === "managed_destination") {
|
|
67432
67609
|
const marker = await readMarker(destination);
|
|
67433
67610
|
if (marker?.skillId === entry.skillId && marker.versionId === entry.versionId && marker.contentHash === entry.contentHash) {
|
|
67434
|
-
await (0,
|
|
67611
|
+
await (0, import_promises14.rm)(destination, { recursive: true, force: true });
|
|
67435
67612
|
}
|
|
67436
67613
|
return;
|
|
67437
67614
|
}
|
|
@@ -67463,16 +67640,16 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67463
67640
|
if (!await legacyFileMatches(source2, legacy.hash) || !await packageMatches(source2, entry.contentHash)) {
|
|
67464
67641
|
return;
|
|
67465
67642
|
}
|
|
67466
|
-
await (0,
|
|
67643
|
+
await (0, import_promises14.rename)(source2, destination);
|
|
67467
67644
|
try {
|
|
67468
|
-
await (0,
|
|
67645
|
+
await (0, import_promises14.writeFile)(
|
|
67469
67646
|
(0, import_node_path24.join)(destination, ".alan-managed.json"),
|
|
67470
67647
|
`${JSON.stringify(markerFor(entry), null, 2)}
|
|
67471
67648
|
`,
|
|
67472
67649
|
{ encoding: "utf8", flag: "wx", mode: 384 }
|
|
67473
67650
|
);
|
|
67474
67651
|
} catch (error61) {
|
|
67475
|
-
await (0,
|
|
67652
|
+
await (0, import_promises14.rename)(destination, source2).catch(() => void 0);
|
|
67476
67653
|
throw error61;
|
|
67477
67654
|
}
|
|
67478
67655
|
await removeExactLegacySkill((0, import_node_path24.join)(this.compatibilitySkillsDirectory, entry.slug), legacy.hash);
|
|
@@ -67485,7 +67662,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67485
67662
|
await removeExactLegacySkill((0, import_node_path24.join)(this.managedSkillsDirectory, command), entry.hash);
|
|
67486
67663
|
await removeExactLegacySkill((0, import_node_path24.join)(this.compatibilitySkillsDirectory, command), entry.hash);
|
|
67487
67664
|
}
|
|
67488
|
-
await (0,
|
|
67665
|
+
await (0, import_promises14.rm)(this.legacyManifestPath, { force: true });
|
|
67489
67666
|
}
|
|
67490
67667
|
async ensureCached(entry) {
|
|
67491
67668
|
const cacheDirectory = (0, import_node_path24.join)(
|
|
@@ -67495,7 +67672,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67495
67672
|
entry.contentHash.slice("sha256:".length)
|
|
67496
67673
|
);
|
|
67497
67674
|
if (await packageMatches(cacheDirectory, entry.contentHash)) return cacheDirectory;
|
|
67498
|
-
await (0,
|
|
67675
|
+
await (0, import_promises14.rm)(cacheDirectory, { recursive: true, force: true });
|
|
67499
67676
|
const bytes = await this.downloadBundle(entry);
|
|
67500
67677
|
if (bytes.byteLength !== entry.compressedBytes) {
|
|
67501
67678
|
throw new Error(
|
|
@@ -67513,12 +67690,12 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67513
67690
|
expectedContentHash: entry.contentHash
|
|
67514
67691
|
});
|
|
67515
67692
|
try {
|
|
67516
|
-
await (0,
|
|
67693
|
+
await (0, import_promises14.rename)(pendingDirectory, cacheDirectory);
|
|
67517
67694
|
} catch (error61) {
|
|
67518
67695
|
if (!await packageMatches(cacheDirectory, entry.contentHash)) throw error61;
|
|
67519
67696
|
}
|
|
67520
67697
|
} finally {
|
|
67521
|
-
await (0,
|
|
67698
|
+
await (0, import_promises14.rm)(pendingDirectory, { recursive: true, force: true });
|
|
67522
67699
|
}
|
|
67523
67700
|
return cacheDirectory;
|
|
67524
67701
|
}
|
|
@@ -67536,8 +67713,8 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67536
67713
|
let installedPending = false;
|
|
67537
67714
|
let completed = false;
|
|
67538
67715
|
try {
|
|
67539
|
-
await (0,
|
|
67540
|
-
await (0,
|
|
67716
|
+
await (0, import_promises14.cp)(cacheDirectory, pending, { recursive: true, errorOnExist: true, force: false });
|
|
67717
|
+
await (0, import_promises14.writeFile)(
|
|
67541
67718
|
(0, import_node_path24.join)(pending, ".alan-managed.json"),
|
|
67542
67719
|
`${JSON.stringify(markerFor(entry), null, 2)}
|
|
67543
67720
|
`,
|
|
@@ -67547,14 +67724,14 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67547
67724
|
throw new Error("Pending managed Skill projection failed content verification");
|
|
67548
67725
|
}
|
|
67549
67726
|
if (await pathExists2(destination)) {
|
|
67550
|
-
await (0,
|
|
67727
|
+
await (0, import_promises14.rename)(destination, backup);
|
|
67551
67728
|
movedExisting = true;
|
|
67552
67729
|
}
|
|
67553
67730
|
try {
|
|
67554
|
-
await (0,
|
|
67731
|
+
await (0, import_promises14.rename)(pending, destination);
|
|
67555
67732
|
installedPending = true;
|
|
67556
67733
|
} catch (error61) {
|
|
67557
|
-
if (movedExisting) await (0,
|
|
67734
|
+
if (movedExisting) await (0, import_promises14.rename)(backup, destination);
|
|
67558
67735
|
throw error61;
|
|
67559
67736
|
}
|
|
67560
67737
|
const inspected = await inspectSkillPackage(destination, { expectedName: null });
|
|
@@ -67563,18 +67740,18 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67563
67740
|
}
|
|
67564
67741
|
await this.ensureCompatibilityProjection(entry, destination);
|
|
67565
67742
|
completed = true;
|
|
67566
|
-
await (0,
|
|
67743
|
+
await (0, import_promises14.rm)(backup, { recursive: true, force: true });
|
|
67567
67744
|
return inspected.contentHash;
|
|
67568
67745
|
} catch (error61) {
|
|
67569
67746
|
if (!completed && installedPending) {
|
|
67570
|
-
await (0,
|
|
67571
|
-
if (movedExisting && await pathExists2(backup)) await (0,
|
|
67747
|
+
await (0, import_promises14.rm)(destination, { recursive: true, force: true });
|
|
67748
|
+
if (movedExisting && await pathExists2(backup)) await (0, import_promises14.rename)(backup, destination);
|
|
67572
67749
|
}
|
|
67573
67750
|
throw error61;
|
|
67574
67751
|
} finally {
|
|
67575
|
-
await (0,
|
|
67752
|
+
await (0, import_promises14.rm)(pending, { recursive: true, force: true });
|
|
67576
67753
|
if (completed || !movedExisting) {
|
|
67577
|
-
await (0,
|
|
67754
|
+
await (0, import_promises14.rm)(backup, { recursive: true, force: true });
|
|
67578
67755
|
}
|
|
67579
67756
|
}
|
|
67580
67757
|
}
|
|
@@ -67602,7 +67779,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67602
67779
|
const failures = [];
|
|
67603
67780
|
let entries;
|
|
67604
67781
|
try {
|
|
67605
|
-
entries = await (0,
|
|
67782
|
+
entries = await (0, import_promises14.readdir)(this.managedSkillsDirectory);
|
|
67606
67783
|
} catch (error61) {
|
|
67607
67784
|
if (isMissingPath2(error61)) return failures;
|
|
67608
67785
|
throw error61;
|
|
@@ -67639,12 +67816,12 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67639
67816
|
});
|
|
67640
67817
|
continue;
|
|
67641
67818
|
}
|
|
67642
|
-
await (0,
|
|
67819
|
+
await (0, import_promises14.rm)(destination, { recursive: true, force: true });
|
|
67643
67820
|
}
|
|
67644
67821
|
return failures;
|
|
67645
67822
|
}
|
|
67646
67823
|
async ensureCompatibilityProjection(entry, canonicalDirectory) {
|
|
67647
|
-
await (0,
|
|
67824
|
+
await (0, import_promises14.mkdir)(this.compatibilitySkillsDirectory, { recursive: true, mode: 448 });
|
|
67648
67825
|
const destination = (0, import_node_path24.join)(
|
|
67649
67826
|
this.compatibilitySkillsDirectory,
|
|
67650
67827
|
this.projectionDirectoryName(entry.runtimeDirectory)
|
|
@@ -67654,23 +67831,23 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67654
67831
|
throw unmanagedCompatibilityConflict(entry.runtimeDirectory);
|
|
67655
67832
|
}
|
|
67656
67833
|
try {
|
|
67657
|
-
await (0,
|
|
67834
|
+
await (0, import_promises14.symlink)(canonicalDirectory, destination, "dir");
|
|
67658
67835
|
return;
|
|
67659
67836
|
} catch (error61) {
|
|
67660
67837
|
if (!isSymlinkUnsupported(error61)) throw error61;
|
|
67661
67838
|
}
|
|
67662
67839
|
const pending = `${destination}.pending-${process.pid}-${(0, import_node_crypto14.randomBytes)(6).toString("hex")}`;
|
|
67663
67840
|
try {
|
|
67664
|
-
await (0,
|
|
67665
|
-
await (0,
|
|
67841
|
+
await (0, import_promises14.cp)(canonicalDirectory, pending, { recursive: true, errorOnExist: true, force: false });
|
|
67842
|
+
await (0, import_promises14.writeFile)(
|
|
67666
67843
|
(0, import_node_path24.join)(pending, ".alan-compatibility.json"),
|
|
67667
67844
|
`${JSON.stringify({ ...markerFor(entry), canonicalDirectory }, null, 2)}
|
|
67668
67845
|
`,
|
|
67669
67846
|
{ encoding: "utf8", flag: "wx", mode: 384 }
|
|
67670
67847
|
);
|
|
67671
|
-
await (0,
|
|
67848
|
+
await (0, import_promises14.rename)(pending, destination);
|
|
67672
67849
|
} finally {
|
|
67673
|
-
await (0,
|
|
67850
|
+
await (0, import_promises14.rm)(pending, { recursive: true, force: true });
|
|
67674
67851
|
}
|
|
67675
67852
|
}
|
|
67676
67853
|
async runExclusively(work) {
|
|
@@ -67694,29 +67871,29 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67694
67871
|
return this.storageNamespace ? `${runtimeDirectory}--alan-${this.storageNamespace}` : runtimeDirectory;
|
|
67695
67872
|
}
|
|
67696
67873
|
async withMachineLock(work) {
|
|
67697
|
-
await (0,
|
|
67874
|
+
await (0, import_promises14.mkdir)(this.skillsStateDirectory, { recursive: true, mode: 448 });
|
|
67698
67875
|
const lockDirectory = (0, import_node_path24.join)(this.skillsStateDirectory, "manager.lock");
|
|
67699
67876
|
const deadline = Date.now() + 3e4;
|
|
67700
67877
|
while (true) {
|
|
67701
67878
|
try {
|
|
67702
|
-
await (0,
|
|
67879
|
+
await (0, import_promises14.mkdir)(lockDirectory, { mode: 448 });
|
|
67703
67880
|
try {
|
|
67704
|
-
await (0,
|
|
67881
|
+
await (0, import_promises14.writeFile)(
|
|
67705
67882
|
(0, import_node_path24.join)(lockDirectory, "owner.json"),
|
|
67706
67883
|
`${JSON.stringify({ pid: process.pid, acquiredAt: (/* @__PURE__ */ new Date()).toISOString() })}
|
|
67707
67884
|
`,
|
|
67708
67885
|
{ encoding: "utf8", flag: "wx", mode: 384 }
|
|
67709
67886
|
);
|
|
67710
67887
|
} catch (error61) {
|
|
67711
|
-
await (0,
|
|
67888
|
+
await (0, import_promises14.rm)(lockDirectory, { recursive: true, force: true });
|
|
67712
67889
|
throw error61;
|
|
67713
67890
|
}
|
|
67714
67891
|
break;
|
|
67715
67892
|
} catch (error61) {
|
|
67716
67893
|
if (!isAlreadyPresent2(error61)) throw error61;
|
|
67717
|
-
const ageMs = await (0,
|
|
67894
|
+
const ageMs = await (0, import_promises14.stat)(lockDirectory).then((metadata) => Date.now() - metadata.mtimeMs).catch(() => 0);
|
|
67718
67895
|
if (ageMs > 15 * 6e4) {
|
|
67719
|
-
await (0,
|
|
67896
|
+
await (0, import_promises14.rm)(lockDirectory, { recursive: true, force: true });
|
|
67720
67897
|
continue;
|
|
67721
67898
|
}
|
|
67722
67899
|
if (Date.now() >= deadline) {
|
|
@@ -67730,7 +67907,7 @@ var RuntimeSkillManager = class _RuntimeSkillManager {
|
|
|
67730
67907
|
try {
|
|
67731
67908
|
return await work();
|
|
67732
67909
|
} finally {
|
|
67733
|
-
await (0,
|
|
67910
|
+
await (0, import_promises14.rm)(lockDirectory, { recursive: true, force: true });
|
|
67734
67911
|
}
|
|
67735
67912
|
}
|
|
67736
67913
|
};
|
|
@@ -67752,7 +67929,7 @@ async function packageMatches(directory, expectedHash) {
|
|
|
67752
67929
|
async function readMarker(directory) {
|
|
67753
67930
|
try {
|
|
67754
67931
|
const value2 = JSON.parse(
|
|
67755
|
-
await (0,
|
|
67932
|
+
await (0, import_promises14.readFile)((0, import_node_path24.join)(directory, ".alan-managed.json"), "utf8")
|
|
67756
67933
|
);
|
|
67757
67934
|
if (typeof value2 !== "object" || value2 === null || !("protocolVersion" in value2) || value2.protocolVersion !== SKILLS_PROTOCOL_VERSION || !("skillId" in value2) || typeof value2.skillId !== "string" || !("versionId" in value2) || typeof value2.versionId !== "string" || !("contentHash" in value2) || typeof value2.contentHash !== "string" || !/^sha256:[a-f0-9]{64}$/.test(value2.contentHash)) {
|
|
67758
67935
|
return null;
|
|
@@ -67763,9 +67940,9 @@ async function readMarker(directory) {
|
|
|
67763
67940
|
}
|
|
67764
67941
|
}
|
|
67765
67942
|
async function compatibilityProjectionMatches(destination, canonicalDirectory, entry) {
|
|
67766
|
-
const metadata = await (0,
|
|
67943
|
+
const metadata = await (0, import_promises14.lstat)(destination);
|
|
67767
67944
|
if (metadata.isSymbolicLink()) {
|
|
67768
|
-
const target = await (0,
|
|
67945
|
+
const target = await (0, import_promises14.readlink)(destination);
|
|
67769
67946
|
return (0, import_node_path24.resolve)((0, import_node_path24.dirname)(destination), target) === (0, import_node_path24.resolve)(canonicalDirectory);
|
|
67770
67947
|
}
|
|
67771
67948
|
if (!metadata.isDirectory()) return false;
|
|
@@ -67774,22 +67951,22 @@ async function compatibilityProjectionMatches(destination, canonicalDirectory, e
|
|
|
67774
67951
|
}
|
|
67775
67952
|
async function removeCompatibilityProjection(destination, canonicalDirectory, projection) {
|
|
67776
67953
|
if (!await pathExists2(destination)) return true;
|
|
67777
|
-
const metadata = await (0,
|
|
67954
|
+
const metadata = await (0, import_promises14.lstat)(destination);
|
|
67778
67955
|
if (metadata.isSymbolicLink()) {
|
|
67779
|
-
const target = await (0,
|
|
67956
|
+
const target = await (0, import_promises14.readlink)(destination);
|
|
67780
67957
|
if ((0, import_node_path24.resolve)((0, import_node_path24.dirname)(destination), target) !== (0, import_node_path24.resolve)(canonicalDirectory)) return false;
|
|
67781
|
-
await (0,
|
|
67958
|
+
await (0, import_promises14.rm)(destination, { force: true });
|
|
67782
67959
|
return true;
|
|
67783
67960
|
}
|
|
67784
67961
|
const marker = await readCompatibilityMarker(destination);
|
|
67785
67962
|
if (!marker || !markerMatchesProjection(marker, projection)) return false;
|
|
67786
|
-
await (0,
|
|
67963
|
+
await (0, import_promises14.rm)(destination, { recursive: true, force: true });
|
|
67787
67964
|
return true;
|
|
67788
67965
|
}
|
|
67789
67966
|
async function readCompatibilityMarker(directory) {
|
|
67790
67967
|
try {
|
|
67791
67968
|
const value2 = JSON.parse(
|
|
67792
|
-
await (0,
|
|
67969
|
+
await (0, import_promises14.readFile)((0, import_node_path24.join)(directory, ".alan-compatibility.json"), "utf8")
|
|
67793
67970
|
);
|
|
67794
67971
|
if (value2.protocolVersion !== SKILLS_PROTOCOL_VERSION || typeof value2.skillId !== "string" || typeof value2.versionId !== "string" || !/^sha256:[a-f0-9]{64}$/.test(value2.contentHash) || typeof value2.canonicalDirectory !== "string") {
|
|
67795
67972
|
return null;
|
|
@@ -67809,7 +67986,7 @@ function markerFor(entry) {
|
|
|
67809
67986
|
}
|
|
67810
67987
|
async function readLegacyManifest(path2) {
|
|
67811
67988
|
try {
|
|
67812
|
-
const value2 = JSON.parse(await (0,
|
|
67989
|
+
const value2 = JSON.parse(await (0, import_promises14.readFile)(path2, "utf8"));
|
|
67813
67990
|
if (!value2 || typeof value2 !== "object" || !("skills" in value2)) return null;
|
|
67814
67991
|
const skillsValue = value2.skills;
|
|
67815
67992
|
if (!skillsValue || typeof skillsValue !== "object" || Array.isArray(skillsValue)) return null;
|
|
@@ -67827,9 +68004,9 @@ async function readLegacyManifest(path2) {
|
|
|
67827
68004
|
}
|
|
67828
68005
|
async function legacyFileMatches(directory, expectedHash) {
|
|
67829
68006
|
try {
|
|
67830
|
-
const metadata = await (0,
|
|
68007
|
+
const metadata = await (0, import_promises14.lstat)(directory);
|
|
67831
68008
|
if (!metadata.isDirectory() || metadata.isSymbolicLink()) return false;
|
|
67832
|
-
const content = await (0,
|
|
68009
|
+
const content = await (0, import_promises14.readFile)((0, import_node_path24.join)(directory, "SKILL.md"));
|
|
67833
68010
|
return (0, import_node_crypto14.createHash)("sha256").update(content).digest("hex").slice(0, 16) === expectedHash;
|
|
67834
68011
|
} catch {
|
|
67835
68012
|
return false;
|
|
@@ -67837,9 +68014,9 @@ async function legacyFileMatches(directory, expectedHash) {
|
|
|
67837
68014
|
}
|
|
67838
68015
|
async function removeExactLegacySkill(directory, expectedHash) {
|
|
67839
68016
|
if (!await legacyFileMatches(directory, expectedHash)) return;
|
|
67840
|
-
await (0,
|
|
67841
|
-
const remaining = await (0,
|
|
67842
|
-
if (remaining.length === 0) await (0,
|
|
68017
|
+
await (0, import_promises14.rm)((0, import_node_path24.join)(directory, "SKILL.md"), { force: true });
|
|
68018
|
+
const remaining = await (0, import_promises14.readdir)(directory);
|
|
68019
|
+
if (remaining.length === 0) await (0, import_promises14.rm)(directory, { recursive: true, force: true });
|
|
67843
68020
|
}
|
|
67844
68021
|
function markerMatchesProjection(marker, projection) {
|
|
67845
68022
|
return marker.skillId === projection.skillId && marker.versionId === projection.versionId && marker.contentHash === projection.contentHash;
|
|
@@ -67941,7 +68118,7 @@ function localTextMediaType(path2) {
|
|
|
67941
68118
|
}
|
|
67942
68119
|
async function pathExists2(path2) {
|
|
67943
68120
|
try {
|
|
67944
|
-
await (0,
|
|
68121
|
+
await (0, import_promises14.lstat)(path2);
|
|
67945
68122
|
return true;
|
|
67946
68123
|
} catch (error61) {
|
|
67947
68124
|
if (isMissingPath2(error61)) return false;
|
|
@@ -68424,19 +68601,19 @@ ${input2.userRequest}
|
|
|
68424
68601
|
}
|
|
68425
68602
|
|
|
68426
68603
|
// src/workspace-run-lease.ts
|
|
68427
|
-
var
|
|
68604
|
+
var import_promises15 = require("fs/promises");
|
|
68428
68605
|
var import_node_path25 = require("path");
|
|
68429
68606
|
var WORKSPACE_LEASE_CHECK_INTERVAL_MS = 1e3;
|
|
68430
68607
|
async function hasGitWorkspaceMarker(workspacePath) {
|
|
68431
68608
|
let directory;
|
|
68432
68609
|
try {
|
|
68433
|
-
directory = await (0,
|
|
68610
|
+
directory = await (0, import_promises15.realpath)((0, import_node_path25.resolve)(workspacePath));
|
|
68434
68611
|
} catch {
|
|
68435
68612
|
return true;
|
|
68436
68613
|
}
|
|
68437
68614
|
while (true) {
|
|
68438
68615
|
try {
|
|
68439
|
-
await (0,
|
|
68616
|
+
await (0, import_promises15.stat)((0, import_node_path25.join)(directory, ".git"));
|
|
68440
68617
|
return true;
|
|
68441
68618
|
} catch (error61) {
|
|
68442
68619
|
const code = error61.code;
|
|
@@ -68448,8 +68625,8 @@ async function hasGitWorkspaceMarker(workspacePath) {
|
|
|
68448
68625
|
}
|
|
68449
68626
|
}
|
|
68450
68627
|
async function filesystemIdentity(path2) {
|
|
68451
|
-
const canonicalPath = await (0,
|
|
68452
|
-
const metadata = await (0,
|
|
68628
|
+
const canonicalPath = await (0, import_promises15.realpath)(path2);
|
|
68629
|
+
const metadata = await (0, import_promises15.stat)(canonicalPath);
|
|
68453
68630
|
return `${canonicalPath}:${metadata.dev}:${metadata.ino}`;
|
|
68454
68631
|
}
|
|
68455
68632
|
function resolveGitPath(workspacePath, value2) {
|
|
@@ -68461,7 +68638,7 @@ async function resolveGitIdentityPaths(canonicalWorkspacePath) {
|
|
|
68461
68638
|
const marker = (0, import_node_path25.join)(directory, ".git");
|
|
68462
68639
|
let markerStats;
|
|
68463
68640
|
try {
|
|
68464
|
-
markerStats = await (0,
|
|
68641
|
+
markerStats = await (0, import_promises15.stat)(marker);
|
|
68465
68642
|
} catch (error61) {
|
|
68466
68643
|
const code = error61.code;
|
|
68467
68644
|
if (code !== "ENOENT" && code !== "ENOTDIR") return null;
|
|
@@ -68475,7 +68652,7 @@ async function resolveGitIdentityPaths(canonicalWorkspacePath) {
|
|
|
68475
68652
|
}
|
|
68476
68653
|
let pointer;
|
|
68477
68654
|
try {
|
|
68478
|
-
pointer = await (0,
|
|
68655
|
+
pointer = await (0, import_promises15.readFile)(marker, "utf8");
|
|
68479
68656
|
} catch {
|
|
68480
68657
|
return null;
|
|
68481
68658
|
}
|
|
@@ -68484,7 +68661,7 @@ async function resolveGitIdentityPaths(canonicalWorkspacePath) {
|
|
|
68484
68661
|
const gitDirectory = resolveGitPath(directory, gitDirMatch[1].trim());
|
|
68485
68662
|
let commonDirectory = gitDirectory;
|
|
68486
68663
|
try {
|
|
68487
|
-
const commonRaw = (await (0,
|
|
68664
|
+
const commonRaw = (await (0, import_promises15.readFile)((0, import_node_path25.join)(gitDirectory, "commondir"), "utf8")).trim();
|
|
68488
68665
|
if (commonRaw) commonDirectory = (0, import_node_path25.resolve)(gitDirectory, commonRaw);
|
|
68489
68666
|
} catch (error61) {
|
|
68490
68667
|
const code = error61.code;
|
|
@@ -68530,7 +68707,7 @@ var DEFAULT_PROBE = {
|
|
|
68530
68707
|
snapshot: createWorkspaceRunLeaseSnapshotProbe(snapshotWorkspace),
|
|
68531
68708
|
pathExists: async (workspacePath) => {
|
|
68532
68709
|
try {
|
|
68533
|
-
await (0,
|
|
68710
|
+
await (0, import_promises15.access)((0, import_node_path25.resolve)(workspacePath));
|
|
68534
68711
|
return true;
|
|
68535
68712
|
} catch (error61) {
|
|
68536
68713
|
return error61.code !== "ENOENT";
|
|
@@ -68539,7 +68716,7 @@ var DEFAULT_PROBE = {
|
|
|
68539
68716
|
};
|
|
68540
68717
|
async function snapshotWorkspace(workspacePath) {
|
|
68541
68718
|
try {
|
|
68542
|
-
const canonicalWorkspacePath = await (0,
|
|
68719
|
+
const canonicalWorkspacePath = await (0, import_promises15.realpath)((0, import_node_path25.resolve)(workspacePath));
|
|
68543
68720
|
const gitPaths = await resolveGitIdentityPaths(canonicalWorkspacePath);
|
|
68544
68721
|
if (!gitPaths) return null;
|
|
68545
68722
|
return {
|
|
@@ -69097,7 +69274,7 @@ function admitWithToken(ctx, payload, tokenReady, heartbeatSeq, disconnectedSinc
|
|
|
69097
69274
|
const runtimeToken = ctx.getRuntimeToken();
|
|
69098
69275
|
const provider = resolveProvider(ctx, payload);
|
|
69099
69276
|
return provider instanceof Promise ? provider.then(
|
|
69100
|
-
(
|
|
69277
|
+
(settled2) => settleAdmission(ctx, payload, runtimeToken, settled2, heartbeatSeq, disconnectedSinceMs)
|
|
69101
69278
|
) : settleAdmission(ctx, payload, runtimeToken, provider, heartbeatSeq, disconnectedSinceMs);
|
|
69102
69279
|
}
|
|
69103
69280
|
function settleAdmission(ctx, payload, runtimeToken, provider, heartbeatSeq, disconnectedSinceMs) {
|
|
@@ -70892,7 +71069,7 @@ async function runNetworkGit(cwd, args, code) {
|
|
|
70892
71069
|
let stderr = "";
|
|
70893
71070
|
let outputExceeded = false;
|
|
70894
71071
|
let timedOut = false;
|
|
70895
|
-
let
|
|
71072
|
+
let settled2 = false;
|
|
70896
71073
|
const killTree = () => {
|
|
70897
71074
|
if (child.pid && process.platform !== "win32") {
|
|
70898
71075
|
try {
|
|
@@ -70923,14 +71100,14 @@ async function runNetworkGit(cwd, args, code) {
|
|
|
70923
71100
|
stderr = append(stderr, chunk);
|
|
70924
71101
|
});
|
|
70925
71102
|
child.once("error", (error61) => {
|
|
70926
|
-
if (
|
|
70927
|
-
|
|
71103
|
+
if (settled2) return;
|
|
71104
|
+
settled2 = true;
|
|
70928
71105
|
clearTimeout(timer);
|
|
70929
71106
|
rejectPromise(new BindingSwitchGitError(code, error61.message));
|
|
70930
71107
|
});
|
|
70931
71108
|
child.once("close", (exitCode) => {
|
|
70932
|
-
if (
|
|
70933
|
-
|
|
71109
|
+
if (settled2) return;
|
|
71110
|
+
settled2 = true;
|
|
70934
71111
|
clearTimeout(timer);
|
|
70935
71112
|
if (timedOut) {
|
|
70936
71113
|
rejectPromise(
|
|
@@ -75174,7 +75351,7 @@ async function setupWindowsRuntime(commandArgs) {
|
|
|
75174
75351
|
throw new Error("Windows runtime setup completed without a local readiness endpoint");
|
|
75175
75352
|
}
|
|
75176
75353
|
const probe = () => probeLocalDaemon(localApiPort, localApiToken, Math.min(250, remainingMs()));
|
|
75177
|
-
const poll = () => (0,
|
|
75354
|
+
const poll = () => (0, import_promises16.setTimeout)(Math.min(100, remainingMs()), void 0, { signal: controller.signal });
|
|
75178
75355
|
if (runtimeIdentityChanged) {
|
|
75179
75356
|
while (true) {
|
|
75180
75357
|
const status2 = await probe();
|
|
@@ -75491,14 +75668,14 @@ var AgentResourceSampler = class {
|
|
|
75491
75668
|
if (this.inFlight) return;
|
|
75492
75669
|
this.inFlight = true;
|
|
75493
75670
|
const generation = this.generation;
|
|
75494
|
-
const
|
|
75671
|
+
const delay5 = this.delay.count > 0 ? {
|
|
75495
75672
|
eventLoopDelayMaxMs: this.delay.max / 1e6,
|
|
75496
75673
|
eventLoopDelayP99Ms: this.delay.percentile(99) / 1e6
|
|
75497
75674
|
} : {};
|
|
75498
75675
|
this.delay.reset();
|
|
75499
75676
|
try {
|
|
75500
75677
|
const sample = await this.collect();
|
|
75501
|
-
if (generation === this.generation) this.sample = { ...sample, ...
|
|
75678
|
+
if (generation === this.generation) this.sample = { ...sample, ...delay5 };
|
|
75502
75679
|
} catch {
|
|
75503
75680
|
if (generation === this.generation) this.sample = void 0;
|
|
75504
75681
|
} finally {
|
|
@@ -76309,7 +76486,7 @@ var ExecutionLeaseClient = class {
|
|
|
76309
76486
|
const remaining = deadline - Date.now();
|
|
76310
76487
|
if (remaining <= 0) throw new Error("Sandbox provider protection timed out");
|
|
76311
76488
|
if (!this.inFlight) this.requestRenewal();
|
|
76312
|
-
await
|
|
76489
|
+
await delay4(Math.min(remaining, EXECUTION_PROTECTION_POLL_MS));
|
|
76313
76490
|
}
|
|
76314
76491
|
throw new Error("Execution authority was lost before provider protection");
|
|
76315
76492
|
}
|
|
@@ -76323,7 +76500,7 @@ var ExecutionLeaseClient = class {
|
|
|
76323
76500
|
const remaining = deadline - Date.now();
|
|
76324
76501
|
if (remaining <= 0) throw new Error("Execution protection capability timed out");
|
|
76325
76502
|
if (!this.inFlight) this.requestRenewal();
|
|
76326
|
-
await
|
|
76503
|
+
await delay4(Math.min(remaining, EXECUTION_PROTECTION_POLL_MS));
|
|
76327
76504
|
}
|
|
76328
76505
|
throw new Error("Execution authority was lost before protection capability resolved");
|
|
76329
76506
|
}
|
|
@@ -76550,7 +76727,7 @@ var ExecutionLeaseClient = class {
|
|
|
76550
76727
|
return;
|
|
76551
76728
|
}
|
|
76552
76729
|
}
|
|
76553
|
-
await
|
|
76730
|
+
await delay4(this.retryDelaysMs[attempt] ?? 0);
|
|
76554
76731
|
}
|
|
76555
76732
|
}
|
|
76556
76733
|
};
|
|
@@ -76588,7 +76765,7 @@ async function readErrorBody(response) {
|
|
|
76588
76765
|
return {};
|
|
76589
76766
|
}
|
|
76590
76767
|
}
|
|
76591
|
-
function
|
|
76768
|
+
function delay4(ms) {
|
|
76592
76769
|
return new Promise((resolve16) => setTimeout(resolve16, ms));
|
|
76593
76770
|
}
|
|
76594
76771
|
|
|
@@ -77122,7 +77299,7 @@ async function runSandbox(config4) {
|
|
|
77122
77299
|
}
|
|
77123
77300
|
|
|
77124
77301
|
// src/skills/skill-cli.ts
|
|
77125
|
-
var
|
|
77302
|
+
var import_promises17 = require("fs/promises");
|
|
77126
77303
|
var import_node_os22 = require("os");
|
|
77127
77304
|
var import_node_path40 = require("path");
|
|
77128
77305
|
async function runSkillsCommand(args) {
|
|
@@ -77169,7 +77346,7 @@ async function defaultScanInput(homeDirectory2) {
|
|
|
77169
77346
|
}
|
|
77170
77347
|
async function readProtectedJson(path2) {
|
|
77171
77348
|
const absolutePath = (0, import_node_path40.resolve)(path2);
|
|
77172
|
-
const stat4 = await (0,
|
|
77349
|
+
const stat4 = await (0, import_promises17.lstat)(absolutePath);
|
|
77173
77350
|
if (!stat4.isFile()) throw new Error(`Skill input is not a regular file: ${absolutePath}`);
|
|
77174
77351
|
if (process.platform !== "win32" && (stat4.mode & 63) !== 0) {
|
|
77175
77352
|
throw new Error(`Skill input must not be accessible by group or other users: ${absolutePath}`);
|
|
@@ -77178,7 +77355,7 @@ async function readProtectedJson(path2) {
|
|
|
77178
77355
|
throw new Error(`Skill input must be owned by the current user: ${absolutePath}`);
|
|
77179
77356
|
}
|
|
77180
77357
|
if (stat4.size > 2 * 1024 * 1024) throw new Error("Skill input exceeds 2 MiB");
|
|
77181
|
-
return JSON.parse(await (0,
|
|
77358
|
+
return JSON.parse(await (0, import_promises17.readFile)(absolutePath, "utf8"));
|
|
77182
77359
|
}
|
|
77183
77360
|
function option2(args, name) {
|
|
77184
77361
|
const index = args.indexOf(name);
|