@alan-ai-hq/agent-manager-darwin-arm64 0.1.146 → 0.1.147
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/alan-agent.cjs +657 -337
- package/alan-holder.cjs +662 -329
- package/package.json +1 -1
package/alan-agent.cjs
CHANGED
|
@@ -12529,7 +12529,7 @@ function compileValidator(schema, parser) {
|
|
|
12529
12529
|
function compile(schema, options) {
|
|
12530
12530
|
try {
|
|
12531
12531
|
const parser = compileFn(schema);
|
|
12532
|
-
const
|
|
12532
|
+
const clone3 = clone(schema);
|
|
12533
12533
|
const liveRun = schema._zod.run;
|
|
12534
12534
|
const originalRun = liveRun.__originalRun ?? liveRun;
|
|
12535
12535
|
const wrapped = (payload, ctx) => {
|
|
@@ -12549,12 +12549,12 @@ function compile(schema, options) {
|
|
|
12549
12549
|
return originalRun(payload, ctx);
|
|
12550
12550
|
};
|
|
12551
12551
|
wrapped.__originalRun = originalRun;
|
|
12552
|
-
|
|
12553
|
-
|
|
12554
|
-
|
|
12552
|
+
clone3._zod.bag.fallbackRun = originalRun;
|
|
12553
|
+
clone3._zod.bag.validator = compileValidator(schema, parser);
|
|
12554
|
+
clone3._zod.run = wrapped;
|
|
12555
12555
|
if (!liveRun.__originalRun)
|
|
12556
|
-
installCompiledUserMethods(
|
|
12557
|
-
return
|
|
12556
|
+
installCompiledUserMethods(clone3, schema, parser);
|
|
12557
|
+
return clone3;
|
|
12558
12558
|
} catch (err) {
|
|
12559
12559
|
if (options?.strict)
|
|
12560
12560
|
throw err;
|
|
@@ -20312,7 +20312,7 @@ var init_workspace = __esm({
|
|
|
20312
20312
|
});
|
|
20313
20313
|
|
|
20314
20314
|
// ../shared/dist/runtime-v2/desired-state.js
|
|
20315
|
-
var repoLocalPathSchema, runSpecSchema, desiredRunSchema, desiredStateSchema;
|
|
20315
|
+
var repoLocalPathSchema, requestedCheckoutSchema, runSpecSchema, desiredRunSchema, desiredStateSchema;
|
|
20316
20316
|
var init_desired_state = __esm({
|
|
20317
20317
|
"../shared/dist/runtime-v2/desired-state.js"() {
|
|
20318
20318
|
"use strict";
|
|
@@ -20327,6 +20327,11 @@ var init_desired_state = __esm({
|
|
|
20327
20327
|
localPath: external_exports.string().min(1),
|
|
20328
20328
|
branch: external_exports.string().min(1).optional()
|
|
20329
20329
|
});
|
|
20330
|
+
requestedCheckoutSchema = external_exports.object({
|
|
20331
|
+
path: machinePathSchema,
|
|
20332
|
+
repoUrl: gitRemoteUrlSchema,
|
|
20333
|
+
branch: gitBranchSchema
|
|
20334
|
+
});
|
|
20330
20335
|
runSpecSchema = external_exports.object({
|
|
20331
20336
|
runId: runIdSchema,
|
|
20332
20337
|
conversationId: conversationIdSchema,
|
|
@@ -20345,6 +20350,8 @@ var init_desired_state = __esm({
|
|
|
20345
20350
|
workspacePathPinned: external_exports.boolean().optional(),
|
|
20346
20351
|
approvedWorkspacePaths: external_exports.array(external_exports.string().min(1)).optional(),
|
|
20347
20352
|
repoLocalPaths: external_exports.array(repoLocalPathSchema).optional(),
|
|
20353
|
+
/** Applied once, at the conversation's first turn on a cloud sandbox; never moves local work. */
|
|
20354
|
+
requestedCheckouts: external_exports.array(requestedCheckoutSchema).max(64).optional(),
|
|
20348
20355
|
workflowId: external_exports.guid().optional(),
|
|
20349
20356
|
workflowExecutionId: external_exports.guid().optional(),
|
|
20350
20357
|
agentId: external_exports.string().min(1).optional(),
|
|
@@ -20973,13 +20980,20 @@ var init_problem = __esm({
|
|
|
20973
20980
|
});
|
|
20974
20981
|
|
|
20975
20982
|
// ../shared/dist/cli-usage.js
|
|
20976
|
-
var usagePercentSchema, usageTimestampSchema, cliUsageWindowPatchSchema, cliUsageWindowSchema, cliUsageBucketSchema, cliUsageSnapshotSchema;
|
|
20983
|
+
var usagePercentSchema, usageTimestampSchema, usageAmountSchema, usageObservationShape, cliUsageWindowPatchSchema, cliUsageWindowSchema, cliUsageSpendPatchSchema, cliUsageSpendSchema, cliUsageCreditsPatchSchema, cliUsageCreditsSchema, cliUsageBucketSchema, cliUsageSnapshotSchema;
|
|
20977
20984
|
var init_cli_usage = __esm({
|
|
20978
20985
|
"../shared/dist/cli-usage.js"() {
|
|
20979
20986
|
"use strict";
|
|
20980
20987
|
init_zod();
|
|
20981
20988
|
usagePercentSchema = external_exports.number().min(0).max(100);
|
|
20982
20989
|
usageTimestampSchema = external_exports.iso.datetime();
|
|
20990
|
+
usageAmountSchema = external_exports.string().min(1);
|
|
20991
|
+
usageObservationShape = {
|
|
20992
|
+
observedAt: usageTimestampSchema,
|
|
20993
|
+
receivedAt: usageTimestampSchema,
|
|
20994
|
+
sourceId: external_exports.string().min(1),
|
|
20995
|
+
sequence: external_exports.number().int().nonnegative()
|
|
20996
|
+
};
|
|
20983
20997
|
cliUsageWindowPatchSchema = external_exports.object({
|
|
20984
20998
|
usedPercent: usagePercentSchema.nullable().optional(),
|
|
20985
20999
|
windowMinutes: external_exports.number().positive().nullable().optional(),
|
|
@@ -20989,14 +21003,41 @@ var init_cli_usage = __esm({
|
|
|
20989
21003
|
usedPercent: usagePercentSchema.optional(),
|
|
20990
21004
|
windowMinutes: external_exports.number().positive().optional(),
|
|
20991
21005
|
resetsAt: usageTimestampSchema.optional(),
|
|
20992
|
-
|
|
20993
|
-
|
|
20994
|
-
|
|
20995
|
-
|
|
21006
|
+
...usageObservationShape
|
|
21007
|
+
});
|
|
21008
|
+
cliUsageSpendPatchSchema = external_exports.object({
|
|
21009
|
+
reached: external_exports.boolean(),
|
|
21010
|
+
limit: usageAmountSchema.nullable().optional(),
|
|
21011
|
+
used: usageAmountSchema.nullable().optional(),
|
|
21012
|
+
remaining: usageAmountSchema.nullable().optional(),
|
|
21013
|
+
usedPercent: usagePercentSchema.nullable().optional(),
|
|
21014
|
+
resetsAt: usageTimestampSchema.nullable().optional()
|
|
21015
|
+
});
|
|
21016
|
+
cliUsageSpendSchema = external_exports.object({
|
|
21017
|
+
reached: external_exports.boolean(),
|
|
21018
|
+
limit: usageAmountSchema.optional(),
|
|
21019
|
+
used: usageAmountSchema.optional(),
|
|
21020
|
+
remaining: usageAmountSchema.optional(),
|
|
21021
|
+
usedPercent: usagePercentSchema.optional(),
|
|
21022
|
+
resetsAt: usageTimestampSchema.optional(),
|
|
21023
|
+
...usageObservationShape
|
|
21024
|
+
});
|
|
21025
|
+
cliUsageCreditsPatchSchema = external_exports.object({
|
|
21026
|
+
hasCredits: external_exports.boolean(),
|
|
21027
|
+
unlimited: external_exports.boolean(),
|
|
21028
|
+
balance: usageAmountSchema.nullable().optional()
|
|
21029
|
+
});
|
|
21030
|
+
cliUsageCreditsSchema = external_exports.object({
|
|
21031
|
+
hasCredits: external_exports.boolean(),
|
|
21032
|
+
unlimited: external_exports.boolean(),
|
|
21033
|
+
balance: usageAmountSchema.optional(),
|
|
21034
|
+
...usageObservationShape
|
|
20996
21035
|
});
|
|
20997
21036
|
cliUsageBucketSchema = external_exports.object({
|
|
20998
21037
|
primary: cliUsageWindowSchema.optional(),
|
|
20999
21038
|
secondary: cliUsageWindowSchema.optional(),
|
|
21039
|
+
spend: cliUsageSpendSchema.optional(),
|
|
21040
|
+
credits: cliUsageCreditsSchema.optional(),
|
|
21000
21041
|
planType: external_exports.string().min(1).nullable().optional()
|
|
21001
21042
|
});
|
|
21002
21043
|
cliUsageSnapshotSchema = external_exports.object({
|
|
@@ -21038,6 +21079,8 @@ var init_run_log = __esm({
|
|
|
21038
21079
|
limitId: external_exports.string().min(1),
|
|
21039
21080
|
primary: cliUsageWindowPatchSchema.nullable().optional(),
|
|
21040
21081
|
secondary: cliUsageWindowPatchSchema.nullable().optional(),
|
|
21082
|
+
spend: cliUsageSpendPatchSchema.nullable().optional(),
|
|
21083
|
+
credits: cliUsageCreditsPatchSchema.nullable().optional(),
|
|
21041
21084
|
planType: external_exports.string().min(1).nullable().optional(),
|
|
21042
21085
|
observedAt: external_exports.iso.datetime(),
|
|
21043
21086
|
sourceId: external_exports.string().min(1),
|
|
@@ -22583,7 +22626,7 @@ function plan(command, args, options) {
|
|
|
22583
22626
|
function captureOutput(command, args, options) {
|
|
22584
22627
|
const launch = plan(command, args, options);
|
|
22585
22628
|
if (launch === void 0) return Promise.resolve(NEVER_STARTED);
|
|
22586
|
-
return new Promise((
|
|
22629
|
+
return new Promise((resolve14) => {
|
|
22587
22630
|
(0, import_child_process.execFile)(
|
|
22588
22631
|
launch.file,
|
|
22589
22632
|
[...launch.args],
|
|
@@ -22597,7 +22640,7 @@ function captureOutput(command, args, options) {
|
|
|
22597
22640
|
},
|
|
22598
22641
|
(error61, stdout, stderr) => {
|
|
22599
22642
|
const code = error61 && typeof error61.code === "number" ? error61.code : error61 ? void 0 : 0;
|
|
22600
|
-
|
|
22643
|
+
resolve14({ stdout, stderr, exitCode: code });
|
|
22601
22644
|
}
|
|
22602
22645
|
);
|
|
22603
22646
|
});
|
|
@@ -22647,10 +22690,10 @@ async function linuxStartTicks(pid) {
|
|
|
22647
22690
|
}
|
|
22648
22691
|
}
|
|
22649
22692
|
function psStartTime(pid) {
|
|
22650
|
-
return new Promise((
|
|
22693
|
+
return new Promise((resolve14) => {
|
|
22651
22694
|
(0, import_child_process2.execFile)("ps", ["-o", "lstart=", "-p", String(pid)], { timeout: 2e3 }, (error61, stdout) => {
|
|
22652
22695
|
const text3 = stdout.trim();
|
|
22653
|
-
|
|
22696
|
+
resolve14(error61 || !text3 ? void 0 : text3);
|
|
22654
22697
|
});
|
|
22655
22698
|
});
|
|
22656
22699
|
}
|
|
@@ -22679,12 +22722,12 @@ function parseProcessList(text3) {
|
|
|
22679
22722
|
}
|
|
22680
22723
|
function listProcesses(platform3 = process.platform) {
|
|
22681
22724
|
if (platform3 === "win32") return Promise.resolve([]);
|
|
22682
|
-
return new Promise((
|
|
22725
|
+
return new Promise((resolve14) => {
|
|
22683
22726
|
(0, import_child_process3.execFile)(
|
|
22684
22727
|
"ps",
|
|
22685
22728
|
["-A", "-o", "pid=,ppid=,pgid=,lstart="],
|
|
22686
22729
|
{ timeout: 5e3, maxBuffer: 8 * 1024 * 1024 },
|
|
22687
|
-
(error61, stdout) =>
|
|
22730
|
+
(error61, stdout) => resolve14(error61 ? [] : parseProcessList(stdout))
|
|
22688
22731
|
);
|
|
22689
22732
|
});
|
|
22690
22733
|
}
|
|
@@ -22724,11 +22767,11 @@ async function taskkill(pid, options) {
|
|
|
22724
22767
|
stdio: "ignore",
|
|
22725
22768
|
windowsHide: true
|
|
22726
22769
|
});
|
|
22727
|
-
const exited = new Promise((
|
|
22728
|
-
killer.once("error", (error210) =>
|
|
22770
|
+
const exited = new Promise((resolve14) => {
|
|
22771
|
+
killer.once("error", (error210) => resolve14(error210));
|
|
22729
22772
|
killer.once(
|
|
22730
22773
|
"exit",
|
|
22731
|
-
(code, signal) =>
|
|
22774
|
+
(code, signal) => resolve14(code === 0 ? void 0 : new Error(`taskkill failed: exit ${code}, signal ${signal}`))
|
|
22732
22775
|
);
|
|
22733
22776
|
});
|
|
22734
22777
|
const timedOut = clock.sleep(options.timeoutMs ?? DEFAULT_TASKKILL_TIMEOUT_MS, timeout.signal).then(() => new Error("taskkill timed out")).catch(() => void 0);
|
|
@@ -22984,10 +23027,10 @@ function spawnCli(options) {
|
|
|
22984
23027
|
function waitForSpawn(child, command) {
|
|
22985
23028
|
if (isWindowsJob(child)) return waitForWindowsJob(child, command);
|
|
22986
23029
|
if (child.pid !== void 0) return Promise.resolve();
|
|
22987
|
-
return new Promise((
|
|
23030
|
+
return new Promise((resolve14, reject) => {
|
|
22988
23031
|
const onSpawn = () => {
|
|
22989
23032
|
child.off("error", onError);
|
|
22990
|
-
|
|
23033
|
+
resolve14();
|
|
22991
23034
|
};
|
|
22992
23035
|
const onError = (error61) => {
|
|
22993
23036
|
child.off("spawn", onSpawn);
|
|
@@ -26585,8 +26628,8 @@ function createJsonRpcPeer(writer, handlers) {
|
|
|
26585
26628
|
},
|
|
26586
26629
|
request: (method, params = {}) => {
|
|
26587
26630
|
const id = counter.next++;
|
|
26588
|
-
return new Promise((
|
|
26589
|
-
pending.set(id, { method, resolve:
|
|
26631
|
+
return new Promise((resolve14, reject) => {
|
|
26632
|
+
pending.set(id, { method, resolve: resolve14, reject });
|
|
26590
26633
|
writer.write({ id, method, params }).catch((error61) => {
|
|
26591
26634
|
pending.delete(id);
|
|
26592
26635
|
reject(error61 instanceof Error ? error61 : new Error(String(error61)));
|
|
@@ -26699,7 +26742,7 @@ function createNdjsonWriter(stream) {
|
|
|
26699
26742
|
get writable() {
|
|
26700
26743
|
return stream.writable && !stream.destroyed && failure6.error === void 0;
|
|
26701
26744
|
},
|
|
26702
|
-
write: (value2) => new Promise((
|
|
26745
|
+
write: (value2) => new Promise((resolve14, reject) => {
|
|
26703
26746
|
if (failure6.error) {
|
|
26704
26747
|
reject(failure6.error);
|
|
26705
26748
|
return;
|
|
@@ -26711,7 +26754,7 @@ function createNdjsonWriter(stream) {
|
|
|
26711
26754
|
stream.write(`${JSON.stringify(value2)}
|
|
26712
26755
|
`, (error61) => {
|
|
26713
26756
|
if (error61) reject(error61);
|
|
26714
|
-
else
|
|
26757
|
+
else resolve14();
|
|
26715
26758
|
});
|
|
26716
26759
|
}),
|
|
26717
26760
|
end: () => {
|
|
@@ -26727,11 +26770,11 @@ function hostProcess(child, tree, options, handlers) {
|
|
|
26727
26770
|
const stderr = new LineSplitter((line) => handlers.onStderrLine(line));
|
|
26728
26771
|
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
26729
26772
|
child.stderr.once("end", () => stderr.flush());
|
|
26730
|
-
const processExit = new Promise((
|
|
26731
|
-
child.once("exit", (code, signal) =>
|
|
26773
|
+
const processExit = new Promise((resolve14) => {
|
|
26774
|
+
child.once("exit", (code, signal) => resolve14({ code, signal }));
|
|
26732
26775
|
});
|
|
26733
|
-
const outputEnded = new Promise((
|
|
26734
|
-
child.stdout.once("close", () =>
|
|
26776
|
+
const outputEnded = new Promise((resolve14) => {
|
|
26777
|
+
child.stdout.once("close", () => resolve14());
|
|
26735
26778
|
});
|
|
26736
26779
|
const watch = async () => {
|
|
26737
26780
|
const { clock, stdoutDrainMs, log, name } = options;
|
|
@@ -27021,13 +27064,13 @@ var init_chunk_4G77APXN = __esm({
|
|
|
27021
27064
|
const turnId = input2.turnId;
|
|
27022
27065
|
let finish = () => {
|
|
27023
27066
|
};
|
|
27024
|
-
const done = new Promise((
|
|
27067
|
+
const done = new Promise((resolve14) => {
|
|
27025
27068
|
finish = (outcome2) => {
|
|
27026
27069
|
if (this.#current?.id !== turnId) return;
|
|
27027
27070
|
this.#current = void 0;
|
|
27028
27071
|
if (this.#state === "busy") this.#state = "idle";
|
|
27029
27072
|
this.#emit({ type: "turn_ended", turnId, outcome: outcome2 });
|
|
27030
|
-
|
|
27073
|
+
resolve14({ turnId, outcome: outcome2, providerSessionId: this.#sessionId });
|
|
27031
27074
|
};
|
|
27032
27075
|
});
|
|
27033
27076
|
const pending = {
|
|
@@ -29620,8 +29663,8 @@ var init_claude = __esm({
|
|
|
29620
29663
|
}
|
|
29621
29664
|
async #awaitTaskStop(requestId, taskId) {
|
|
29622
29665
|
const timer = new AbortController();
|
|
29623
|
-
const answered = new Promise((
|
|
29624
|
-
this.#taskStops.set(requestId,
|
|
29666
|
+
const answered = new Promise((resolve14) => {
|
|
29667
|
+
this.#taskStops.set(requestId, resolve14);
|
|
29625
29668
|
});
|
|
29626
29669
|
const timeoutMs = this.#options.stopTaskTimeoutMs;
|
|
29627
29670
|
const timedOut = this.#options.clock.sleep(timeoutMs, timer.signal).then(
|
|
@@ -29694,17 +29737,17 @@ var init_claude = __esm({
|
|
|
29694
29737
|
};
|
|
29695
29738
|
let markStarted = () => {
|
|
29696
29739
|
};
|
|
29697
|
-
const whenStarted = new Promise((
|
|
29698
|
-
markStarted =
|
|
29740
|
+
const whenStarted = new Promise((resolve14) => {
|
|
29741
|
+
markStarted = resolve14;
|
|
29699
29742
|
});
|
|
29700
|
-
const done = new Promise((
|
|
29743
|
+
const done = new Promise((resolve14) => {
|
|
29701
29744
|
finish = (outcome2) => {
|
|
29702
29745
|
if (this.#current?.id !== id) return;
|
|
29703
29746
|
this.#current = void 0;
|
|
29704
29747
|
this.#lastTurn = turn;
|
|
29705
29748
|
if (this.#state === "busy") this.#state = "idle";
|
|
29706
29749
|
this.#emit({ type: "turn_ended", turnId: id, outcome: outcome2 });
|
|
29707
|
-
|
|
29750
|
+
resolve14({ turnId: id, outcome: outcome2, providerSessionId: this.#providerSessionId });
|
|
29708
29751
|
};
|
|
29709
29752
|
});
|
|
29710
29753
|
const active = {
|
|
@@ -29822,8 +29865,8 @@ var init_claude = __esm({
|
|
|
29822
29865
|
void removeLaunchFiles(this.#launchFiles).catch((error61) => {
|
|
29823
29866
|
this.#options.log.warn("claude.launch_files_cleanup_failed", { error: error61 });
|
|
29824
29867
|
});
|
|
29825
|
-
for (const
|
|
29826
|
-
|
|
29868
|
+
for (const resolve14 of this.#taskStops.values()) {
|
|
29869
|
+
resolve14({ ok: false, reason: "runtime_unavailable", message: "Claude Code exited." });
|
|
29827
29870
|
}
|
|
29828
29871
|
const active = this.#current;
|
|
29829
29872
|
if (active) {
|
|
@@ -30242,6 +30285,44 @@ function windowPatch(value2) {
|
|
|
30242
30285
|
}
|
|
30243
30286
|
return patch;
|
|
30244
30287
|
}
|
|
30288
|
+
function amount(value2) {
|
|
30289
|
+
const text3 = asString(value2).trim();
|
|
30290
|
+
return text3.length > 0 ? text3 : void 0;
|
|
30291
|
+
}
|
|
30292
|
+
function spendPatch(limit, reached) {
|
|
30293
|
+
const record2 = asRecord(limit);
|
|
30294
|
+
const reachedFlag = reached === true;
|
|
30295
|
+
if (!record2)
|
|
30296
|
+
return limit === null && !reachedFlag ? null : reachedFlag ? { reached: true } : void 0;
|
|
30297
|
+
const patch = { reached: reachedFlag };
|
|
30298
|
+
const limitAmount = amount(record2.limit);
|
|
30299
|
+
const usedAmount = amount(record2.used);
|
|
30300
|
+
if (limitAmount) patch.limit = limitAmount;
|
|
30301
|
+
if (usedAmount) patch.used = usedAmount;
|
|
30302
|
+
const remainingPercent = asFiniteNumber(record2.remainingPercent);
|
|
30303
|
+
if (remainingPercent !== void 0) {
|
|
30304
|
+
patch.usedPercent = Math.min(100, Math.max(0, 100 - remainingPercent));
|
|
30305
|
+
}
|
|
30306
|
+
const seconds = asFiniteNumber(record2.resetsAt);
|
|
30307
|
+
if (seconds !== void 0 && seconds >= 0) {
|
|
30308
|
+
const reset = new Date(seconds * 1e3);
|
|
30309
|
+
if (Number.isFinite(reset.getTime())) patch.resetsAt = reset.toISOString();
|
|
30310
|
+
}
|
|
30311
|
+
return patch;
|
|
30312
|
+
}
|
|
30313
|
+
function creditsPatch(value2) {
|
|
30314
|
+
if (value2 === null) return null;
|
|
30315
|
+
const record2 = asRecord(value2);
|
|
30316
|
+
if (!record2 || typeof record2.hasCredits !== "boolean" || typeof record2.unlimited !== "boolean") {
|
|
30317
|
+
return void 0;
|
|
30318
|
+
}
|
|
30319
|
+
const balance = amount(record2.balance);
|
|
30320
|
+
return {
|
|
30321
|
+
hasCredits: record2.hasCredits,
|
|
30322
|
+
unlimited: record2.unlimited,
|
|
30323
|
+
...balance ? { balance } : {}
|
|
30324
|
+
};
|
|
30325
|
+
}
|
|
30245
30326
|
function isApprovalRequest(method) {
|
|
30246
30327
|
return COMMAND_OR_FILE.has(method) || LEGACY.has(method);
|
|
30247
30328
|
}
|
|
@@ -31939,12 +32020,16 @@ var init_codex = __esm({
|
|
|
31939
32020
|
if (!snapshot2) return [];
|
|
31940
32021
|
const primary = windowPatch(snapshot2.primary);
|
|
31941
32022
|
const secondary = windowPatch(snapshot2.secondary);
|
|
32023
|
+
const spend = spendPatch(snapshot2.individualLimit, snapshot2.spendControlReached);
|
|
32024
|
+
const credits = creditsPatch(snapshot2.credits);
|
|
31942
32025
|
const planType = snapshot2.planType === null ? null : asString(snapshot2.planType) || void 0;
|
|
31943
32026
|
const parsed = runCodexRateLimitsUpdateSchema.safeParse({
|
|
31944
32027
|
sessionUpdate: "_alan/codex.rate_limits",
|
|
31945
32028
|
limitId: bucketId ?? (asString(snapshot2.limitId) || "codex"),
|
|
31946
32029
|
...primary === void 0 ? {} : { primary },
|
|
31947
32030
|
...secondary === void 0 ? {} : { secondary },
|
|
32031
|
+
...spend === void 0 ? {} : { spend },
|
|
32032
|
+
...credits === void 0 ? {} : { credits },
|
|
31948
32033
|
...planType === void 0 ? {} : { planType },
|
|
31949
32034
|
observedAt: new Date(this.#clock.now()).toISOString(),
|
|
31950
32035
|
sourceId: this.#sourceId,
|
|
@@ -32383,10 +32468,10 @@ var init_codex = __esm({
|
|
|
32383
32468
|
};
|
|
32384
32469
|
let identify = () => {
|
|
32385
32470
|
};
|
|
32386
|
-
const identified = new Promise((
|
|
32387
|
-
identify =
|
|
32471
|
+
const identified = new Promise((resolve14) => {
|
|
32472
|
+
identify = resolve14;
|
|
32388
32473
|
});
|
|
32389
|
-
const done = new Promise((
|
|
32474
|
+
const done = new Promise((resolve14) => {
|
|
32390
32475
|
finish = (outcome2) => {
|
|
32391
32476
|
if (this.#current?.id !== id) return;
|
|
32392
32477
|
this.#current = void 0;
|
|
@@ -32394,7 +32479,7 @@ var init_codex = __esm({
|
|
|
32394
32479
|
if (this.#state === "busy") this.#state = "idle";
|
|
32395
32480
|
this.#host.scanDescendants(true);
|
|
32396
32481
|
this.#emit({ type: "turn_ended", turnId: id, outcome: outcome2 });
|
|
32397
|
-
|
|
32482
|
+
resolve14({ turnId: id, outcome: outcome2, providerSessionId: this.#threadId });
|
|
32398
32483
|
};
|
|
32399
32484
|
});
|
|
32400
32485
|
const active = {
|
|
@@ -32949,7 +33034,7 @@ function alanCodeConfigContent(existing, input2) {
|
|
|
32949
33034
|
});
|
|
32950
33035
|
}
|
|
32951
33036
|
function readBody2(response) {
|
|
32952
|
-
return new Promise((
|
|
33037
|
+
return new Promise((resolve14, reject) => {
|
|
32953
33038
|
const chunks = [];
|
|
32954
33039
|
let size = 0;
|
|
32955
33040
|
response.on("data", (chunk) => {
|
|
@@ -32957,7 +33042,7 @@ function readBody2(response) {
|
|
|
32957
33042
|
if (size > MAX_CATALOG_BYTES) response.destroy(new Error("catalog too large"));
|
|
32958
33043
|
else chunks.push(chunk);
|
|
32959
33044
|
});
|
|
32960
|
-
response.on("end", () =>
|
|
33045
|
+
response.on("end", () => resolve14(Buffer.concat(chunks).toString("utf8")));
|
|
32961
33046
|
response.on("error", reject);
|
|
32962
33047
|
});
|
|
32963
33048
|
}
|
|
@@ -32973,13 +33058,13 @@ function parseResponseBody(text3, status) {
|
|
|
32973
33058
|
}
|
|
32974
33059
|
function getJson(url3, headers, timeout, signal) {
|
|
32975
33060
|
const request2 = url3.protocol === "https:" ? import_https.request : import_http9.request;
|
|
32976
|
-
return new Promise((
|
|
33061
|
+
return new Promise((resolve14, reject) => {
|
|
32977
33062
|
const outgoing = request2(url3, { method: "GET", headers, timeout, signal }, (response) => {
|
|
32978
33063
|
const status = response.statusCode ?? 0;
|
|
32979
33064
|
readBody2(response).then((text3) => {
|
|
32980
33065
|
const body = parseResponseBody(text3, status);
|
|
32981
33066
|
if (status < 200 || status >= 300) reject(new CatalogResponseError(status, body));
|
|
32982
|
-
else
|
|
33067
|
+
else resolve14(body);
|
|
32983
33068
|
}).catch(reject);
|
|
32984
33069
|
});
|
|
32985
33070
|
outgoing.on("timeout", () => outgoing.destroy(new Error("catalog timed out")));
|
|
@@ -41855,8 +41940,8 @@ var require_streamx = __commonJS({
|
|
|
41855
41940
|
return this;
|
|
41856
41941
|
},
|
|
41857
41942
|
next() {
|
|
41858
|
-
return new Promise(function(
|
|
41859
|
-
promiseResolve =
|
|
41943
|
+
return new Promise(function(resolve14, reject) {
|
|
41944
|
+
promiseResolve = resolve14;
|
|
41860
41945
|
promiseReject = reject;
|
|
41861
41946
|
const data = stream.read();
|
|
41862
41947
|
if (data !== null) ondata(data);
|
|
@@ -41889,11 +41974,11 @@ var require_streamx = __commonJS({
|
|
|
41889
41974
|
}
|
|
41890
41975
|
function destroy(err) {
|
|
41891
41976
|
stream.destroy(err);
|
|
41892
|
-
return new Promise((
|
|
41893
|
-
if (stream._duplexState & DESTROYED) return
|
|
41977
|
+
return new Promise((resolve14, reject) => {
|
|
41978
|
+
if (stream._duplexState & DESTROYED) return resolve14({ value: void 0, done: true });
|
|
41894
41979
|
stream.once("close", function() {
|
|
41895
41980
|
if (err) reject(err);
|
|
41896
|
-
else
|
|
41981
|
+
else resolve14({ value: void 0, done: true });
|
|
41897
41982
|
});
|
|
41898
41983
|
});
|
|
41899
41984
|
}
|
|
@@ -41937,8 +42022,8 @@ var require_streamx = __commonJS({
|
|
|
41937
42022
|
const writes = pending + (ws._duplexState & WRITE_WRITING ? 1 : 0);
|
|
41938
42023
|
if (writes === 0) return Promise.resolve(true);
|
|
41939
42024
|
if (state.drains === null) state.drains = [];
|
|
41940
|
-
return new Promise((
|
|
41941
|
-
state.drains.push({ writes, resolve:
|
|
42025
|
+
return new Promise((resolve14) => {
|
|
42026
|
+
state.drains.push({ writes, resolve: resolve14 });
|
|
41942
42027
|
});
|
|
41943
42028
|
}
|
|
41944
42029
|
write(data) {
|
|
@@ -42043,10 +42128,10 @@ var require_streamx = __commonJS({
|
|
|
42043
42128
|
cb(null);
|
|
42044
42129
|
}
|
|
42045
42130
|
function pipelinePromise(...streams) {
|
|
42046
|
-
return new Promise((
|
|
42131
|
+
return new Promise((resolve14, reject) => {
|
|
42047
42132
|
return pipeline(...streams, (err) => {
|
|
42048
42133
|
if (err) return reject(err);
|
|
42049
|
-
|
|
42134
|
+
resolve14();
|
|
42050
42135
|
});
|
|
42051
42136
|
});
|
|
42052
42137
|
}
|
|
@@ -42718,16 +42803,16 @@ var require_extract = __commonJS({
|
|
|
42718
42803
|
entryCallback = null;
|
|
42719
42804
|
cb(err);
|
|
42720
42805
|
}
|
|
42721
|
-
function onnext(
|
|
42806
|
+
function onnext(resolve14, reject) {
|
|
42722
42807
|
if (error61) {
|
|
42723
42808
|
return reject(error61);
|
|
42724
42809
|
}
|
|
42725
42810
|
if (entryStream) {
|
|
42726
|
-
|
|
42811
|
+
resolve14({ value: entryStream, done: false });
|
|
42727
42812
|
entryStream = null;
|
|
42728
42813
|
return;
|
|
42729
42814
|
}
|
|
42730
|
-
promiseResolve =
|
|
42815
|
+
promiseResolve = resolve14;
|
|
42731
42816
|
promiseReject = reject;
|
|
42732
42817
|
consumeCallback(null);
|
|
42733
42818
|
if (extract2._finished && promiseResolve) {
|
|
@@ -42755,11 +42840,11 @@ var require_extract = __commonJS({
|
|
|
42755
42840
|
function destroy(err) {
|
|
42756
42841
|
extract2.destroy(err);
|
|
42757
42842
|
consumeCallback(err);
|
|
42758
|
-
return new Promise((
|
|
42759
|
-
if (extract2.destroyed) return
|
|
42843
|
+
return new Promise((resolve14, reject) => {
|
|
42844
|
+
if (extract2.destroyed) return resolve14({ value: void 0, done: true });
|
|
42760
42845
|
extract2.once("close", function() {
|
|
42761
42846
|
if (err) reject(err);
|
|
42762
|
-
else
|
|
42847
|
+
else resolve14({ value: void 0, done: true });
|
|
42763
42848
|
});
|
|
42764
42849
|
});
|
|
42765
42850
|
}
|
|
@@ -44321,7 +44406,7 @@ var init_acp3 = __esm({
|
|
|
44321
44406
|
const turn = new AcpTurn(`acp-${this.#turns}-${id}`, this.#profile);
|
|
44322
44407
|
let finish = () => {
|
|
44323
44408
|
};
|
|
44324
|
-
const done = new Promise((
|
|
44409
|
+
const done = new Promise((resolve14) => {
|
|
44325
44410
|
finish = (outcome2) => {
|
|
44326
44411
|
if (this.#current?.id !== id) return;
|
|
44327
44412
|
this.#current = void 0;
|
|
@@ -44329,7 +44414,7 @@ var init_acp3 = __esm({
|
|
|
44329
44414
|
if (this.#state === "busy") this.#state = "idle";
|
|
44330
44415
|
this.#host.scanDescendants(true);
|
|
44331
44416
|
this.#emit({ type: "turn_ended", turnId: id, outcome: outcome2 });
|
|
44332
|
-
|
|
44417
|
+
resolve14({ turnId: id, outcome: outcome2, providerSessionId: this.#sessionId });
|
|
44333
44418
|
};
|
|
44334
44419
|
});
|
|
44335
44420
|
const active = { id, turn, done, finish, cancelRequested: false };
|
|
@@ -47005,8 +47090,8 @@ function createDroidPeer(writer, handlers) {
|
|
|
47005
47090
|
},
|
|
47006
47091
|
request: (method, params = {}) => {
|
|
47007
47092
|
const id = `alan-${counter.next++}`;
|
|
47008
|
-
return new Promise((
|
|
47009
|
-
pending.set(id, { method, resolve:
|
|
47093
|
+
return new Promise((resolve14, reject) => {
|
|
47094
|
+
pending.set(id, { method, resolve: resolve14, reject });
|
|
47010
47095
|
writer.write(envelope("request", { id, method, params })).catch((error61) => {
|
|
47011
47096
|
pending.delete(id);
|
|
47012
47097
|
reject(error61 instanceof Error ? error61 : new Error(String(error61)));
|
|
@@ -47631,14 +47716,14 @@ var init_droid = __esm({
|
|
|
47631
47716
|
const turn = new DroidTurn(sessionId, this.#memory);
|
|
47632
47717
|
let finish = () => {
|
|
47633
47718
|
};
|
|
47634
|
-
const done = new Promise((
|
|
47719
|
+
const done = new Promise((resolve14) => {
|
|
47635
47720
|
finish = (outcome2) => {
|
|
47636
47721
|
if (this.#current?.id !== id) return;
|
|
47637
47722
|
this.#current = void 0;
|
|
47638
47723
|
if (this.#state === "busy") this.#state = "idle";
|
|
47639
47724
|
this.#host.scanDescendants(true);
|
|
47640
47725
|
this.#emit({ type: "turn_ended", turnId: id, outcome: outcome2 });
|
|
47641
|
-
|
|
47726
|
+
resolve14({ turnId: id, outcome: outcome2, providerSessionId: this.#sessionId });
|
|
47642
47727
|
};
|
|
47643
47728
|
});
|
|
47644
47729
|
const active = { id, turn, done, finish, cancelRequested: false };
|
|
@@ -54564,7 +54649,7 @@ var require_websocket_server = __commonJS({
|
|
|
54564
54649
|
// package.json
|
|
54565
54650
|
var package_default = {
|
|
54566
54651
|
name: "@alan-ai-hq/agent-manager",
|
|
54567
|
-
version: "0.1.
|
|
54652
|
+
version: "0.1.147",
|
|
54568
54653
|
private: true,
|
|
54569
54654
|
type: "module",
|
|
54570
54655
|
description: "Alan machine runtime (alan-agent): identity, link, reconciler, session holders, run log, uploader, local API",
|
|
@@ -54614,7 +54699,7 @@ var package_default = {
|
|
|
54614
54699
|
|
|
54615
54700
|
// src/cli/commands/compat.ts
|
|
54616
54701
|
var import_node_crypto32 = require("crypto");
|
|
54617
|
-
var
|
|
54702
|
+
var import_promises69 = require("fs/promises");
|
|
54618
54703
|
init_runtime_v2();
|
|
54619
54704
|
init_zod();
|
|
54620
54705
|
|
|
@@ -54773,8 +54858,8 @@ async function writeJsonFileAtomic(path4, value2) {
|
|
|
54773
54858
|
var LIFECYCLE_DRAIN_MS = 5e3;
|
|
54774
54859
|
function createGate() {
|
|
54775
54860
|
const opened = {};
|
|
54776
|
-
const promise2 = new Promise((
|
|
54777
|
-
opened.resolve =
|
|
54861
|
+
const promise2 = new Promise((resolve14) => {
|
|
54862
|
+
opened.resolve = resolve14;
|
|
54778
54863
|
});
|
|
54779
54864
|
return { promise: promise2, open: () => opened.resolve?.() };
|
|
54780
54865
|
}
|
|
@@ -55001,7 +55086,7 @@ function transportFailure(request2, error61) {
|
|
|
55001
55086
|
});
|
|
55002
55087
|
}
|
|
55003
55088
|
function readBody(incoming, url3, maxBytes) {
|
|
55004
|
-
return new Promise((
|
|
55089
|
+
return new Promise((resolve14, reject) => {
|
|
55005
55090
|
const declared = Number(incoming.headers["content-length"] ?? "0");
|
|
55006
55091
|
if (maxBytes !== void 0 && declared > maxBytes) {
|
|
55007
55092
|
incoming.destroy();
|
|
@@ -55020,7 +55105,7 @@ function readBody(incoming, url3, maxBytes) {
|
|
|
55020
55105
|
chunks.push(chunk);
|
|
55021
55106
|
});
|
|
55022
55107
|
incoming.on("error", reject);
|
|
55023
|
-
incoming.on("end", () =>
|
|
55108
|
+
incoming.on("end", () => resolve14(Buffer.concat(chunks)));
|
|
55024
55109
|
});
|
|
55025
55110
|
}
|
|
55026
55111
|
function isConnectionReset(error61) {
|
|
@@ -55028,7 +55113,7 @@ function isConnectionReset(error61) {
|
|
|
55028
55113
|
}
|
|
55029
55114
|
function exchange(request2, agents, attempt2 = 0) {
|
|
55030
55115
|
const { signal, url: url3 } = request2;
|
|
55031
|
-
return new Promise((
|
|
55116
|
+
return new Promise((resolve14, reject) => {
|
|
55032
55117
|
if (signal.aborted) {
|
|
55033
55118
|
reject(signal.reason);
|
|
55034
55119
|
return;
|
|
@@ -55055,7 +55140,7 @@ function exchange(request2, agents, attempt2 = 0) {
|
|
|
55055
55140
|
const stale = outgoing.reusedSocket && !responded && isConnectionReset(error61);
|
|
55056
55141
|
if (stale && attempt2 < STALE_SOCKET_RETRIES && !signal.aborted) {
|
|
55057
55142
|
settle();
|
|
55058
|
-
|
|
55143
|
+
resolve14(exchange(request2, agents, attempt2 + 1));
|
|
55059
55144
|
return;
|
|
55060
55145
|
}
|
|
55061
55146
|
fail(error61);
|
|
@@ -55068,7 +55153,7 @@ function exchange(request2, agents, attempt2 = 0) {
|
|
|
55068
55153
|
readBody(incoming, url3, isRedirect(status) ? void 0 : request2.maxBodyBytes).then(
|
|
55069
55154
|
(body) => {
|
|
55070
55155
|
settle();
|
|
55071
|
-
|
|
55156
|
+
resolve14({ status, headers: incoming.headers, body });
|
|
55072
55157
|
},
|
|
55073
55158
|
fail
|
|
55074
55159
|
);
|
|
@@ -55313,8 +55398,8 @@ function isBodyless(method) {
|
|
|
55313
55398
|
return method === "GET" || method === "HEAD";
|
|
55314
55399
|
}
|
|
55315
55400
|
function exchange2(send2, options, input2) {
|
|
55316
|
-
return new Promise((
|
|
55317
|
-
const outgoing = send2({ ...options, method: input2.method, signal: input2.signal },
|
|
55401
|
+
return new Promise((resolve14, reject) => {
|
|
55402
|
+
const outgoing = send2({ ...options, method: input2.method, signal: input2.signal }, resolve14);
|
|
55318
55403
|
outgoing.on("error", reject);
|
|
55319
55404
|
if (isBodyless(input2.method)) {
|
|
55320
55405
|
input2.body.resume();
|
|
@@ -56800,7 +56885,7 @@ function createGitRunner(options) {
|
|
|
56800
56885
|
}
|
|
56801
56886
|
await killProcessTree(child.pid, { signal: "SIGKILL", child, platform: platform3 });
|
|
56802
56887
|
};
|
|
56803
|
-
return new Promise((
|
|
56888
|
+
return new Promise((resolve14, reject) => {
|
|
56804
56889
|
let ending = null;
|
|
56805
56890
|
const stop = (next) => {
|
|
56806
56891
|
if (ending !== null) return;
|
|
@@ -56825,7 +56910,7 @@ function createGitRunner(options) {
|
|
|
56825
56910
|
signal.removeEventListener("abort", onAbort);
|
|
56826
56911
|
const final = ending ?? last;
|
|
56827
56912
|
if (final.kind === "exited") {
|
|
56828
|
-
|
|
56913
|
+
resolve14({ exitCode: final.exitCode, stdout: stdout.text(), stderr: stderr.text() });
|
|
56829
56914
|
} else {
|
|
56830
56915
|
reject(faultFor(final, command));
|
|
56831
56916
|
}
|
|
@@ -57038,6 +57123,9 @@ async function checkSnapshotCheckouts(root, deps, signal) {
|
|
|
57038
57123
|
})
|
|
57039
57124
|
);
|
|
57040
57125
|
}
|
|
57126
|
+
async function recordCheckoutKept(dir, path4, reason) {
|
|
57127
|
+
await writeJsonFileAtomic(freshnessFile(dir, path4), { state: "kept", path: path4, reason });
|
|
57128
|
+
}
|
|
57041
57129
|
async function readCheckoutFreshness(dir, path4) {
|
|
57042
57130
|
for (let current = path4; ; current = (0, import_node_path7.dirname)(current)) {
|
|
57043
57131
|
const read = await readJsonFile(freshnessFile(dir, current), freshnessSchema);
|
|
@@ -58342,7 +58430,7 @@ function statusOf(error61) {
|
|
|
58342
58430
|
}
|
|
58343
58431
|
return 1;
|
|
58344
58432
|
}
|
|
58345
|
-
var systemExec = (request2) => new Promise((
|
|
58433
|
+
var systemExec = (request2) => new Promise((resolve14) => {
|
|
58346
58434
|
const child = (0, import_node_child_process6.execFile)(
|
|
58347
58435
|
request2.command,
|
|
58348
58436
|
[...request2.args],
|
|
@@ -58353,7 +58441,7 @@ var systemExec = (request2) => new Promise((resolve13) => {
|
|
|
58353
58441
|
windowsHide: true
|
|
58354
58442
|
},
|
|
58355
58443
|
(error61, stdout, stderr) => {
|
|
58356
|
-
|
|
58444
|
+
resolve14({ status: statusOf(error61), stdout, stderr });
|
|
58357
58445
|
}
|
|
58358
58446
|
);
|
|
58359
58447
|
child.stdin?.on("error", () => {
|
|
@@ -59543,11 +59631,11 @@ async function startGitCredentialServer(options) {
|
|
|
59543
59631
|
});
|
|
59544
59632
|
});
|
|
59545
59633
|
removeStaleEndpoint(options.endpoint);
|
|
59546
|
-
await new Promise((
|
|
59634
|
+
await new Promise((resolve14, reject) => {
|
|
59547
59635
|
server.once("error", reject);
|
|
59548
59636
|
server.listen(options.endpoint, () => {
|
|
59549
59637
|
server.off("error", reject);
|
|
59550
|
-
|
|
59638
|
+
resolve14();
|
|
59551
59639
|
});
|
|
59552
59640
|
});
|
|
59553
59641
|
options.log.info("git.credential_server_listening", { endpoint: options.endpoint });
|
|
@@ -59555,7 +59643,7 @@ async function startGitCredentialServer(options) {
|
|
|
59555
59643
|
endpoint: options.endpoint,
|
|
59556
59644
|
[Symbol.asyncDispose]: async () => {
|
|
59557
59645
|
closing.abort();
|
|
59558
|
-
await new Promise((
|
|
59646
|
+
await new Promise((resolve14) => server.close(() => resolve14()));
|
|
59559
59647
|
removeStaleEndpoint(options.endpoint);
|
|
59560
59648
|
}
|
|
59561
59649
|
};
|
|
@@ -59629,13 +59717,13 @@ authorityKeyIdentifier = keyid
|
|
|
59629
59717
|
`;
|
|
59630
59718
|
}
|
|
59631
59719
|
function openssl(args, cwd) {
|
|
59632
|
-
return new Promise((
|
|
59720
|
+
return new Promise((resolve14, reject) => {
|
|
59633
59721
|
(0, import_node_child_process9.execFile)(
|
|
59634
59722
|
"openssl",
|
|
59635
59723
|
[...args],
|
|
59636
59724
|
{ cwd, timeout: OPENSSL_TIMEOUT_MS },
|
|
59637
59725
|
(error61, _stdout, stderr) => {
|
|
59638
|
-
if (error61 === null)
|
|
59726
|
+
if (error61 === null) resolve14();
|
|
59639
59727
|
else
|
|
59640
59728
|
reject(new Error(`openssl ${args[0] ?? ""} failed: ${stderr.trim() || error61.message}`));
|
|
59641
59729
|
}
|
|
@@ -59812,21 +59900,21 @@ function relayTo(forward, log) {
|
|
|
59812
59900
|
};
|
|
59813
59901
|
}
|
|
59814
59902
|
function listen(server, target) {
|
|
59815
|
-
return new Promise((
|
|
59903
|
+
return new Promise((resolve14, reject) => {
|
|
59816
59904
|
server.once("error", reject);
|
|
59817
59905
|
const done = () => {
|
|
59818
59906
|
server.off("error", reject);
|
|
59819
|
-
|
|
59907
|
+
resolve14();
|
|
59820
59908
|
};
|
|
59821
59909
|
if (typeof target === "string") server.listen(target, done);
|
|
59822
59910
|
else server.listen(target.port, target.host, done);
|
|
59823
59911
|
});
|
|
59824
59912
|
}
|
|
59825
59913
|
function close(server, sockets = /* @__PURE__ */ new Set()) {
|
|
59826
|
-
return new Promise((
|
|
59914
|
+
return new Promise((resolve14) => {
|
|
59827
59915
|
for (const socket of sockets) socket.destroy();
|
|
59828
59916
|
server.closeAllConnections();
|
|
59829
|
-
server.close(() =>
|
|
59917
|
+
server.close(() => resolve14());
|
|
59830
59918
|
});
|
|
59831
59919
|
}
|
|
59832
59920
|
function portOf(server) {
|
|
@@ -62609,7 +62697,7 @@ async function startNativeIngest(deps) {
|
|
|
62609
62697
|
};
|
|
62610
62698
|
const settleIdle = () => {
|
|
62611
62699
|
if (workers.size > 0) return;
|
|
62612
|
-
for (const
|
|
62700
|
+
for (const resolve14 of idleWaiters) resolve14();
|
|
62613
62701
|
idleWaiters.clear();
|
|
62614
62702
|
};
|
|
62615
62703
|
const retryDelay = (worker) => {
|
|
@@ -62852,7 +62940,7 @@ async function startNativeIngest(deps) {
|
|
|
62852
62940
|
sweep: sweep2,
|
|
62853
62941
|
whenIdle: () => {
|
|
62854
62942
|
if (workers.size === 0) return Promise.resolve();
|
|
62855
|
-
return new Promise((
|
|
62943
|
+
return new Promise((resolve14) => idleWaiters.add(resolve14));
|
|
62856
62944
|
},
|
|
62857
62945
|
[Symbol.asyncDispose]: async () => {
|
|
62858
62946
|
shutdown.abort();
|
|
@@ -63000,7 +63088,7 @@ function captureProbe(command, args, options) {
|
|
|
63000
63088
|
const launch = directLaunch(command, args, options);
|
|
63001
63089
|
if (launch === void 0) return Promise.resolve({ stdout: "", stderr: "", exitCode: void 0 });
|
|
63002
63090
|
const env = platform3 === "win32" ? withWindowsHelper(canonicalWindowsEnvironment(options.env)) : options.env;
|
|
63003
|
-
return new Promise((
|
|
63091
|
+
return new Promise((resolve14) => {
|
|
63004
63092
|
const limit = options.maxBufferBytes ?? DEFAULT_MAX_BYTES;
|
|
63005
63093
|
const stdout = [];
|
|
63006
63094
|
const stderr = [];
|
|
@@ -63035,7 +63123,7 @@ function captureProbe(command, args, options) {
|
|
|
63035
63123
|
settled2 = true;
|
|
63036
63124
|
deadlineController.abort();
|
|
63037
63125
|
options.signal?.removeEventListener("abort", abort);
|
|
63038
|
-
|
|
63126
|
+
resolve14({
|
|
63039
63127
|
stdout: Buffer.concat(stdout).toString("utf8"),
|
|
63040
63128
|
stderr: Buffer.concat(stderr).toString("utf8"),
|
|
63041
63129
|
exitCode
|
|
@@ -63167,7 +63255,7 @@ function cursorAccountLabel(output2) {
|
|
|
63167
63255
|
function waitForAbort(signal) {
|
|
63168
63256
|
if (signal.aborted) return Promise.resolve();
|
|
63169
63257
|
return new Promise(
|
|
63170
|
-
(
|
|
63258
|
+
(resolve14) => signal.addEventListener("abort", () => resolve14(), { once: true })
|
|
63171
63259
|
);
|
|
63172
63260
|
}
|
|
63173
63261
|
function idlePrompt(signal) {
|
|
@@ -63245,14 +63333,14 @@ async function codexLabel(executable, env) {
|
|
|
63245
63333
|
windowsVerbatimArguments: launch.windowsVerbatimArguments
|
|
63246
63334
|
});
|
|
63247
63335
|
const timeout = AbortSignal.timeout(ACCOUNT_TIMEOUT_MS);
|
|
63248
|
-
return new Promise((
|
|
63336
|
+
return new Promise((resolve14) => {
|
|
63249
63337
|
let finished = false;
|
|
63250
63338
|
let buffer = "";
|
|
63251
63339
|
const finish = (label) => {
|
|
63252
63340
|
if (finished) return;
|
|
63253
63341
|
finished = true;
|
|
63254
63342
|
child.kill();
|
|
63255
|
-
|
|
63343
|
+
resolve14(label);
|
|
63256
63344
|
};
|
|
63257
63345
|
const send2 = (value2) => {
|
|
63258
63346
|
child.stdin.write(`${JSON.stringify(value2)}
|
|
@@ -63761,11 +63849,11 @@ async function resolveCliEnvironment(options) {
|
|
|
63761
63849
|
}
|
|
63762
63850
|
async function openCliEnvironment(options) {
|
|
63763
63851
|
const decorate = options.decorate ?? ((env) => env);
|
|
63764
|
-
const
|
|
63852
|
+
const resolve14 = async () => {
|
|
63765
63853
|
const resolved = await resolveCliEnvironmentDetailed(options);
|
|
63766
63854
|
return { env: decorate(resolved.env), source: resolved.source };
|
|
63767
63855
|
};
|
|
63768
|
-
let state = await
|
|
63856
|
+
let state = await resolve14();
|
|
63769
63857
|
let retryAt = options.clock.now() + DEGRADED_RETRY_MS;
|
|
63770
63858
|
return {
|
|
63771
63859
|
current: () => state.env,
|
|
@@ -63774,7 +63862,7 @@ async function openCliEnvironment(options) {
|
|
|
63774
63862
|
if (state.source === "login_shell" || options.platform === "win32") return false;
|
|
63775
63863
|
if (options.clock.now() < retryAt) return false;
|
|
63776
63864
|
retryAt = options.clock.now() + DEGRADED_RETRY_MS;
|
|
63777
|
-
const next = await
|
|
63865
|
+
const next = await resolve14();
|
|
63778
63866
|
const changed = envValue(next.env, "PATH") !== envValue(state.env, "PATH");
|
|
63779
63867
|
state = next;
|
|
63780
63868
|
return changed;
|
|
@@ -63851,11 +63939,11 @@ async function installVersion2(backendKind, requested, options, signal) {
|
|
|
63851
63939
|
}
|
|
63852
63940
|
return exact;
|
|
63853
63941
|
}
|
|
63854
|
-
const
|
|
63855
|
-
if (
|
|
63942
|
+
const resolve14 = options.resolveVersion;
|
|
63943
|
+
if (resolve14 === void 0) throw new Error("Latest version lookup is unavailable");
|
|
63856
63944
|
const packageName = packageFor(backendKind).name;
|
|
63857
63945
|
return checkedVersion(
|
|
63858
|
-
await
|
|
63946
|
+
await resolve14(backendKind === "opencode_serve" ? `${packageName}@1` : packageName, signal)
|
|
63859
63947
|
);
|
|
63860
63948
|
}
|
|
63861
63949
|
function selection(root, backendKind, version2) {
|
|
@@ -65422,8 +65510,8 @@ async function collectStream(stream) {
|
|
|
65422
65510
|
return import_node_buffer2.Buffer.concat(chunks);
|
|
65423
65511
|
}
|
|
65424
65512
|
function addArchiveEntry(archive, header, bytes) {
|
|
65425
|
-
return new Promise((
|
|
65426
|
-
archive.entry(header, bytes, (error61) => error61 ? reject(error61) :
|
|
65513
|
+
return new Promise((resolve14, reject) => {
|
|
65514
|
+
archive.entry(header, bytes, (error61) => error61 ? reject(error61) : resolve14());
|
|
65427
65515
|
});
|
|
65428
65516
|
}
|
|
65429
65517
|
async function decompressBounded(archiveBytes) {
|
|
@@ -65449,7 +65537,7 @@ async function extractTar(tarBytes, destination) {
|
|
|
65449
65537
|
const extractor = (0, import_tar_stream.extract)();
|
|
65450
65538
|
let fileCount = 0;
|
|
65451
65539
|
let totalBytes = 0;
|
|
65452
|
-
const completion = new Promise((
|
|
65540
|
+
const completion = new Promise((resolve14, reject) => {
|
|
65453
65541
|
extractor.on("entry", (header, stream, next) => {
|
|
65454
65542
|
void extractEntry(header, stream, destination, {
|
|
65455
65543
|
addFile(size) {
|
|
@@ -65464,7 +65552,7 @@ async function extractTar(tarBytes, destination) {
|
|
|
65464
65552
|
}
|
|
65465
65553
|
}).then(next, (error61) => extractor.destroy(error61 instanceof Error ? error61 : new Error(String(error61))));
|
|
65466
65554
|
});
|
|
65467
|
-
extractor.once("finish",
|
|
65555
|
+
extractor.once("finish", resolve14);
|
|
65468
65556
|
extractor.once("error", reject);
|
|
65469
65557
|
});
|
|
65470
65558
|
import_node_stream.Readable.from(tarBytes).pipe(extractor);
|
|
@@ -65947,9 +66035,9 @@ async function syncOnce(env, local, onRecorded, signal) {
|
|
|
65947
66035
|
return report2;
|
|
65948
66036
|
}
|
|
65949
66037
|
function aborted2(signal) {
|
|
65950
|
-
return new Promise((
|
|
65951
|
-
if (signal.aborted)
|
|
65952
|
-
else signal.addEventListener("abort", () =>
|
|
66038
|
+
return new Promise((resolve14) => {
|
|
66039
|
+
if (signal.aborted) resolve14(null);
|
|
66040
|
+
else signal.addEventListener("abort", () => resolve14(null), { once: true });
|
|
65953
66041
|
});
|
|
65954
66042
|
}
|
|
65955
66043
|
function openMachineSkills(options) {
|
|
@@ -66038,11 +66126,11 @@ function openMachineSkills(options) {
|
|
|
66038
66126
|
if ((await resolveSkillInvocations(layout, named, "exact")).kind === "resolved") return;
|
|
66039
66127
|
}
|
|
66040
66128
|
};
|
|
66041
|
-
const recordedUntilResolved = (named, until) => new Promise((
|
|
66129
|
+
const recordedUntilResolved = (named, until) => new Promise((resolve14) => {
|
|
66042
66130
|
const done = () => {
|
|
66043
66131
|
recordWatchers.delete(check3);
|
|
66044
66132
|
until.removeEventListener("abort", done);
|
|
66045
|
-
|
|
66133
|
+
resolve14();
|
|
66046
66134
|
};
|
|
66047
66135
|
const check3 = () => {
|
|
66048
66136
|
void resolveSkillInvocations(layout, named, "exact").then((resolution) => {
|
|
@@ -66050,7 +66138,7 @@ function openMachineSkills(options) {
|
|
|
66050
66138
|
});
|
|
66051
66139
|
};
|
|
66052
66140
|
if (until.aborted) {
|
|
66053
|
-
|
|
66141
|
+
resolve14();
|
|
66054
66142
|
return;
|
|
66055
66143
|
}
|
|
66056
66144
|
recordWatchers.add(check3);
|
|
@@ -66546,7 +66634,7 @@ async function openWorkspaces(options) {
|
|
|
66546
66634
|
|
|
66547
66635
|
// src/cli/config.ts
|
|
66548
66636
|
var import_node_os11 = require("os");
|
|
66549
|
-
var
|
|
66637
|
+
var import_node_path69 = require("path");
|
|
66550
66638
|
init_zod();
|
|
66551
66639
|
|
|
66552
66640
|
// src/client/contract.ts
|
|
@@ -66964,8 +67052,8 @@ function nextOffsetOf(response) {
|
|
|
66964
67052
|
async function pause(ms, signal) {
|
|
66965
67053
|
const either = AbortSignal.any([signal, AbortSignal.timeout(ms)]);
|
|
66966
67054
|
if (either.aborted) return;
|
|
66967
|
-
await new Promise((
|
|
66968
|
-
either.addEventListener("abort", () =>
|
|
67055
|
+
await new Promise((resolve14) => {
|
|
67056
|
+
either.addEventListener("abort", () => resolve14(), { once: true });
|
|
66969
67057
|
});
|
|
66970
67058
|
}
|
|
66971
67059
|
function jittered(backoff, failures) {
|
|
@@ -67274,9 +67362,9 @@ async function sendNativeHookSignal(discoveryPath, hookSignal, signal) {
|
|
|
67274
67362
|
|
|
67275
67363
|
// src/sessions/index.ts
|
|
67276
67364
|
var import_node_crypto31 = require("crypto");
|
|
67277
|
-
var
|
|
67365
|
+
var import_promises67 = require("fs/promises");
|
|
67278
67366
|
var import_node_os10 = require("os");
|
|
67279
|
-
var
|
|
67367
|
+
var import_node_path68 = require("path");
|
|
67280
67368
|
init_runtime_v2();
|
|
67281
67369
|
|
|
67282
67370
|
// src/holder/control-client.ts
|
|
@@ -67327,8 +67415,8 @@ function isReply(message2) {
|
|
|
67327
67415
|
async function connectHolder(endpoint, token, onEvent) {
|
|
67328
67416
|
const socket = (0, import_node_net2.connect)(endpoint);
|
|
67329
67417
|
const pending = /* @__PURE__ */ new Map();
|
|
67330
|
-
const closed = new Promise((
|
|
67331
|
-
const ready = new Promise((
|
|
67418
|
+
const closed = new Promise((resolve14) => socket.once("close", () => resolve14()));
|
|
67419
|
+
const ready = new Promise((resolve14, reject) => {
|
|
67332
67420
|
socket.once("error", reject);
|
|
67333
67421
|
socket.once(
|
|
67334
67422
|
"close",
|
|
@@ -67336,7 +67424,7 @@ async function connectHolder(endpoint, token, onEvent) {
|
|
|
67336
67424
|
);
|
|
67337
67425
|
readMessages(socket, holderMessageSchema, {
|
|
67338
67426
|
onMessage: (message2) => {
|
|
67339
|
-
if (message2.type === "ready")
|
|
67427
|
+
if (message2.type === "ready") resolve14(message2.pid);
|
|
67340
67428
|
else if (isReply(message2)) {
|
|
67341
67429
|
const id = message2.id;
|
|
67342
67430
|
if (id === null) return;
|
|
@@ -67351,13 +67439,13 @@ async function connectHolder(endpoint, token, onEvent) {
|
|
|
67351
67439
|
const pid = await ready;
|
|
67352
67440
|
const request2 = (body) => {
|
|
67353
67441
|
const id = (0, import_node_crypto26.randomUUID)();
|
|
67354
|
-
return new Promise((
|
|
67442
|
+
return new Promise((resolve14, reject) => {
|
|
67355
67443
|
const timer = AbortSignal.timeout(REQUEST_TIMEOUT_MS7);
|
|
67356
67444
|
timer.addEventListener("abort", () => {
|
|
67357
67445
|
pending.delete(id);
|
|
67358
67446
|
reject(new RuntimeFault("io_failed", "Holder did not answer"));
|
|
67359
67447
|
});
|
|
67360
|
-
pending.set(id,
|
|
67448
|
+
pending.set(id, resolve14);
|
|
67361
67449
|
writeMessage(socket, { ...body, id });
|
|
67362
67450
|
});
|
|
67363
67451
|
};
|
|
@@ -67694,14 +67782,14 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
|
|
|
67694
67782
|
var import_node_crypto30 = require("crypto");
|
|
67695
67783
|
var import_node_fs22 = require("fs");
|
|
67696
67784
|
var import_node_net3 = require("net");
|
|
67697
|
-
var
|
|
67785
|
+
var import_node_path67 = require("path");
|
|
67698
67786
|
init_runtime_v2();
|
|
67699
67787
|
|
|
67700
67788
|
// src/holder/admission.ts
|
|
67701
67789
|
var import_node_fs19 = require("fs");
|
|
67702
|
-
var
|
|
67790
|
+
var import_promises61 = require("fs/promises");
|
|
67703
67791
|
var import_node_os9 = require("os");
|
|
67704
|
-
var
|
|
67792
|
+
var import_node_path61 = require("path");
|
|
67705
67793
|
init_constants();
|
|
67706
67794
|
|
|
67707
67795
|
// ../shared/dist/node/local-workspace.js
|
|
@@ -67785,18 +67873,12 @@ async function discoverRelocatedWorkspace(search) {
|
|
|
67785
67873
|
}
|
|
67786
67874
|
|
|
67787
67875
|
// src/holder/checkout-refresh.ts
|
|
67876
|
+
var import_node_path59 = require("path");
|
|
67877
|
+
|
|
67878
|
+
// src/holder/claim-once.ts
|
|
67788
67879
|
var import_node_crypto28 = require("crypto");
|
|
67789
67880
|
var import_promises58 = require("fs/promises");
|
|
67790
67881
|
var import_node_path57 = require("path");
|
|
67791
|
-
function short(sha) {
|
|
67792
|
-
return sha.slice(0, 12);
|
|
67793
|
-
}
|
|
67794
|
-
function staleLine(path4, snapshot2, tip) {
|
|
67795
|
-
const checkout = snapshot2 === void 0 ? "is the environment snapshot's checkout" : `is the environment snapshot's checkout of ${snapshot2.branch} (commit ${short(snapshot2.head)})`;
|
|
67796
|
-
const base = snapshot2 === void 0 ? "its upstream" : `origin/${snapshot2.base}`;
|
|
67797
|
-
const remote = tip === void 0 ? "may be ahead" : `is ahead at ${short(tip)}`;
|
|
67798
|
-
return `Note: ${path4} ${checkout}; ${base} ${remote}. Run \`git pull --ff-only\` there before relying on its files.`;
|
|
67799
|
-
}
|
|
67800
67882
|
async function claimOnce(dir, name) {
|
|
67801
67883
|
try {
|
|
67802
67884
|
await (0, import_promises58.mkdir)(dir, { recursive: true, mode: 448 });
|
|
@@ -67806,6 +67888,199 @@ async function claimOnce(dir, name) {
|
|
|
67806
67888
|
return false;
|
|
67807
67889
|
}
|
|
67808
67890
|
}
|
|
67891
|
+
function claimFirstLease(freshnessDir, path4) {
|
|
67892
|
+
return claimOnce((0, import_node_path57.join)(freshnessDir, "leased"), (0, import_node_crypto28.createHash)("sha256").update(path4).digest("hex"));
|
|
67893
|
+
}
|
|
67894
|
+
|
|
67895
|
+
// src/holder/requested-checkout.ts
|
|
67896
|
+
var import_promises59 = require("fs/promises");
|
|
67897
|
+
var import_node_path58 = require("path");
|
|
67898
|
+
var REMOTE2 = "origin";
|
|
67899
|
+
var REASON_MAX_CHARS = 200;
|
|
67900
|
+
function firstLine3(text3) {
|
|
67901
|
+
return (text3.trim().split("\n")[0] ?? "").slice(0, REASON_MAX_CHARS);
|
|
67902
|
+
}
|
|
67903
|
+
function reasonOf(output2, command) {
|
|
67904
|
+
return firstLine3(output2.stderr) || `git ${command} exited ${output2.exitCode}`;
|
|
67905
|
+
}
|
|
67906
|
+
function noted(checkout, situation, reason, action) {
|
|
67907
|
+
return {
|
|
67908
|
+
kind: "noted",
|
|
67909
|
+
line: `Note: ${checkout.path} ${situation}: ${reason}. ${action} before relying on its files.`
|
|
67910
|
+
};
|
|
67911
|
+
}
|
|
67912
|
+
function notSwitched(checkout, current, reason) {
|
|
67913
|
+
const on2 = current ?? "a detached HEAD";
|
|
67914
|
+
return noted(
|
|
67915
|
+
checkout,
|
|
67916
|
+
`is on ${on2}, not ${checkout.branch}, the branch picked for this chat`,
|
|
67917
|
+
reason,
|
|
67918
|
+
`Switch it to ${checkout.branch}`
|
|
67919
|
+
);
|
|
67920
|
+
}
|
|
67921
|
+
async function clone2(checkout, deps, signal) {
|
|
67922
|
+
const parent = (0, import_node_path58.dirname)(checkout.path);
|
|
67923
|
+
await (0, import_promises59.mkdir)(parent, { recursive: true });
|
|
67924
|
+
await assertValidBranch(deps.git, parent, checkout.branch, signal);
|
|
67925
|
+
const output2 = await deps.git.run(
|
|
67926
|
+
{
|
|
67927
|
+
cwd: parent,
|
|
67928
|
+
args: [
|
|
67929
|
+
"clone",
|
|
67930
|
+
"--quiet",
|
|
67931
|
+
"--no-tags",
|
|
67932
|
+
"--depth=1",
|
|
67933
|
+
"--branch",
|
|
67934
|
+
checkout.branch,
|
|
67935
|
+
"--",
|
|
67936
|
+
checkout.repoUrl,
|
|
67937
|
+
checkout.path
|
|
67938
|
+
],
|
|
67939
|
+
network: true
|
|
67940
|
+
},
|
|
67941
|
+
signal
|
|
67942
|
+
);
|
|
67943
|
+
if (output2.exitCode === 0) return { kind: "moved", how: "cloned" };
|
|
67944
|
+
return noted(
|
|
67945
|
+
checkout,
|
|
67946
|
+
`is missing, and cloning it on ${checkout.branch}, the branch picked for this chat, failed`,
|
|
67947
|
+
reasonOf(output2, "clone"),
|
|
67948
|
+
`Clone ${checkout.repoUrl} there`
|
|
67949
|
+
);
|
|
67950
|
+
}
|
|
67951
|
+
var SWITCHED = { kind: "moved", how: "switched" };
|
|
67952
|
+
function coversBranch(fetchConfig, branch) {
|
|
67953
|
+
return fetchConfig.split("\n").some(
|
|
67954
|
+
(refspec) => refspec === `+refs/heads/*:refs/remotes/${REMOTE2}/*` || refspec === `+refs/heads/${branch}:refs/remotes/${REMOTE2}/${branch}`
|
|
67955
|
+
);
|
|
67956
|
+
}
|
|
67957
|
+
async function fetchBranch(checkout, git, shallow, current) {
|
|
67958
|
+
const { branch } = checkout;
|
|
67959
|
+
const tracking = `refs/remotes/${REMOTE2}/${branch}`;
|
|
67960
|
+
const fetchConfig = await git(["config", "--get-all", `remote.${REMOTE2}.fetch`], {
|
|
67961
|
+
readOnly: true
|
|
67962
|
+
});
|
|
67963
|
+
if (!coversBranch(fetchConfig.stdout, branch)) {
|
|
67964
|
+
const added = await git(["remote", "set-branches", "--add", REMOTE2, branch]);
|
|
67965
|
+
if (added.exitCode !== 0) return notSwitched(checkout, current, reasonOf(added, "remote"));
|
|
67966
|
+
}
|
|
67967
|
+
const depth = shallow ? ["--depth=1"] : [];
|
|
67968
|
+
const fetched = await git(
|
|
67969
|
+
["fetch", "--no-tags", "--quiet", ...depth, REMOTE2, `refs/heads/${branch}:${tracking}`],
|
|
67970
|
+
{ network: true }
|
|
67971
|
+
);
|
|
67972
|
+
if (fetched.exitCode !== 0) return notSwitched(checkout, current, reasonOf(fetched, "fetch"));
|
|
67973
|
+
const tip = await git(["rev-parse", "--verify", tracking], { readOnly: true });
|
|
67974
|
+
if (tip.exitCode !== 0) return notSwitched(checkout, current, reasonOf(tip, "rev-parse"));
|
|
67975
|
+
return { kind: "fetched", tip: tip.stdout.trim() };
|
|
67976
|
+
}
|
|
67977
|
+
async function moveOnto(checkout, git, tip, current) {
|
|
67978
|
+
const { branch } = checkout;
|
|
67979
|
+
const local = await git(["rev-parse", "--verify", "-q", `refs/heads/${branch}`], {
|
|
67980
|
+
readOnly: true
|
|
67981
|
+
});
|
|
67982
|
+
if (local.exitCode !== 0) {
|
|
67983
|
+
const created = await git([
|
|
67984
|
+
"switch",
|
|
67985
|
+
"--quiet",
|
|
67986
|
+
"-c",
|
|
67987
|
+
branch,
|
|
67988
|
+
"--track",
|
|
67989
|
+
`${REMOTE2}/${branch}`
|
|
67990
|
+
]);
|
|
67991
|
+
return created.exitCode === 0 ? SWITCHED : notSwitched(checkout, current, reasonOf(created, "switch"));
|
|
67992
|
+
}
|
|
67993
|
+
const localHead = local.stdout.trim();
|
|
67994
|
+
const ancestor = localHead === tip || (await git(["merge-base", "--is-ancestor", localHead, tip], { readOnly: true })).exitCode === 0;
|
|
67995
|
+
if (!ancestor) {
|
|
67996
|
+
return notSwitched(
|
|
67997
|
+
checkout,
|
|
67998
|
+
current,
|
|
67999
|
+
`its local ${branch} has diverged from ${REMOTE2}/${branch}`
|
|
68000
|
+
);
|
|
68001
|
+
}
|
|
68002
|
+
const switched = await git(["switch", "--quiet", branch]);
|
|
68003
|
+
if (switched.exitCode !== 0) return notSwitched(checkout, current, reasonOf(switched, "switch"));
|
|
68004
|
+
if (localHead === tip) return SWITCHED;
|
|
68005
|
+
const merged = await git(["merge", "--quiet", "--ff-only", tip]);
|
|
68006
|
+
return merged.exitCode === 0 ? SWITCHED : noted(
|
|
68007
|
+
checkout,
|
|
68008
|
+
`is on ${branch} but behind ${REMOTE2}/${branch}`,
|
|
68009
|
+
reasonOf(merged, "merge"),
|
|
68010
|
+
"Run `git pull --ff-only` there"
|
|
68011
|
+
);
|
|
68012
|
+
}
|
|
68013
|
+
async function switchTo(checkout, current, operationId, deps, signal) {
|
|
68014
|
+
var _stack = [];
|
|
68015
|
+
try {
|
|
68016
|
+
const cwd = checkout.path;
|
|
68017
|
+
const git = (args, invocation = {}) => deps.git.run({ cwd, args, ...invocation }, signal);
|
|
68018
|
+
await assertValidBranch(deps.git, cwd, checkout.branch, signal);
|
|
68019
|
+
const refs = await git(
|
|
68020
|
+
["rev-parse", "--path-format=absolute", "--git-common-dir", "--is-shallow-repository"],
|
|
68021
|
+
{ readOnly: true }
|
|
68022
|
+
);
|
|
68023
|
+
if (refs.exitCode !== 0) return notSwitched(checkout, current, reasonOf(refs, "rev-parse"));
|
|
68024
|
+
const [commonDir = "", shallow] = refs.stdout.trim().split("\n");
|
|
68025
|
+
const attempt2 = await deps.locks.tryExclusive(commonDir, operationId);
|
|
68026
|
+
if (attempt2.kind === "busy") {
|
|
68027
|
+
return notSwitched(checkout, current, "another git operation holds the checkout");
|
|
68028
|
+
}
|
|
68029
|
+
const _lock = __using(_stack, attempt2.lock, true);
|
|
68030
|
+
const now = await readCheckoutStatus(deps.git, cwd, signal);
|
|
68031
|
+
if (now === null || now.dirty) {
|
|
68032
|
+
return notSwitched(checkout, now?.branch ?? current, "it has uncommitted changes");
|
|
68033
|
+
}
|
|
68034
|
+
const fetched = await fetchBranch(checkout, git, shallow === "true", now.branch);
|
|
68035
|
+
if (fetched.kind !== "fetched") return fetched;
|
|
68036
|
+
const outcome2 = await moveOnto(checkout, git, fetched.tip, now.branch);
|
|
68037
|
+
const after = await readCheckoutStatus(deps.git, cwd, signal);
|
|
68038
|
+
if (after?.branch === checkout.branch) {
|
|
68039
|
+
await recordCheckoutKept(deps.dir, cwd, "requested_branch");
|
|
68040
|
+
}
|
|
68041
|
+
return outcome2;
|
|
68042
|
+
} catch (_) {
|
|
68043
|
+
var _error = _, _hasError = true;
|
|
68044
|
+
} finally {
|
|
68045
|
+
var _promise2 = __callDispose(_stack, _error, _hasError);
|
|
68046
|
+
_promise2 && await _promise2;
|
|
68047
|
+
}
|
|
68048
|
+
}
|
|
68049
|
+
async function applyRequestedCheckout(checkout, spec, deps, signal) {
|
|
68050
|
+
try {
|
|
68051
|
+
if (!await isCheckout(checkout.path)) return await clone2(checkout, deps, signal);
|
|
68052
|
+
const status = await readCheckoutStatus(deps.git, checkout.path, signal);
|
|
68053
|
+
if (status === null) return notSwitched(checkout, null, "git status failed");
|
|
68054
|
+
if (status.branch === checkout.branch) return { kind: "on_branch" };
|
|
68055
|
+
if (status.dirty) return notSwitched(checkout, status.branch, "it has uncommitted changes");
|
|
68056
|
+
if (!await claimFirstLease(deps.dir, checkout.path)) {
|
|
68057
|
+
return notSwitched(
|
|
68058
|
+
checkout,
|
|
68059
|
+
status.branch,
|
|
68060
|
+
"an earlier conversation on this machine already uses it"
|
|
68061
|
+
);
|
|
68062
|
+
}
|
|
68063
|
+
return await switchTo(checkout, status.branch, `checkout-${spec.runId}`, deps, signal);
|
|
68064
|
+
} catch (error61) {
|
|
68065
|
+
return noted(
|
|
68066
|
+
checkout,
|
|
68067
|
+
`could not be put on ${checkout.branch}, the branch picked for this chat`,
|
|
68068
|
+
firstLine3(error61 instanceof Error ? error61.message : String(error61)) || "unknown error",
|
|
68069
|
+
"Check it"
|
|
68070
|
+
);
|
|
68071
|
+
}
|
|
68072
|
+
}
|
|
68073
|
+
|
|
68074
|
+
// src/holder/checkout-refresh.ts
|
|
68075
|
+
function short(sha) {
|
|
68076
|
+
return sha.slice(0, 12);
|
|
68077
|
+
}
|
|
68078
|
+
function staleLine(path4, snapshot2, tip) {
|
|
68079
|
+
const checkout = snapshot2 === void 0 ? "is the environment snapshot's checkout" : `is the environment snapshot's checkout of ${snapshot2.branch} (commit ${short(snapshot2.head)})`;
|
|
68080
|
+
const base = snapshot2 === void 0 ? "its upstream" : `origin/${snapshot2.base}`;
|
|
68081
|
+
const remote = tip === void 0 ? "may be ahead" : `is ahead at ${short(tip)}`;
|
|
68082
|
+
return `Note: ${path4} ${checkout}; ${base} ${remote}. Run \`git pull --ff-only\` there before relying on its files.`;
|
|
68083
|
+
}
|
|
67809
68084
|
async function fastForward(freshness, operationId, deps, signal) {
|
|
67810
68085
|
var _stack = [];
|
|
67811
68086
|
try {
|
|
@@ -67830,10 +68105,7 @@ async function fastForward(freshness, operationId, deps, signal) {
|
|
|
67830
68105
|
}
|
|
67831
68106
|
}
|
|
67832
68107
|
async function atFirstLease(freshness, spec, deps, signal) {
|
|
67833
|
-
const first = await
|
|
67834
|
-
(0, import_node_path57.join)(deps.dir, "leased"),
|
|
67835
|
-
(0, import_node_crypto28.createHash)("sha256").update(freshness.path).digest("hex")
|
|
67836
|
-
);
|
|
68108
|
+
const first = await claimFirstLease(deps.dir, freshness.path);
|
|
67837
68109
|
switch (freshness.state) {
|
|
67838
68110
|
case "current":
|
|
67839
68111
|
case "kept":
|
|
@@ -67859,32 +68131,73 @@ async function checkoutsOf(spec, leaseTargets) {
|
|
|
67859
68131
|
if (leaseTargets.length > 0 || spec.projectPath === void 0) return [...leaseTargets];
|
|
67860
68132
|
return checkoutsUnder(spec.projectPath);
|
|
67861
68133
|
}
|
|
67862
|
-
function
|
|
67863
|
-
|
|
67864
|
-
|
|
67865
|
-
|
|
67866
|
-
|
|
67867
|
-
|
|
67868
|
-
const freshness = await readCheckoutFreshness(deps.dir, target);
|
|
67869
|
-
if (freshness === null) continue;
|
|
67870
|
-
const outcome2 = await atFirstLease(freshness, spec, deps, signal).catch(
|
|
67871
|
-
() => "noted"
|
|
67872
|
-
);
|
|
67873
|
-
if (outcome2 === "noted") lines2.push(lineFor(freshness));
|
|
67874
|
-
deps.log.info("workspace.refresh", {
|
|
68134
|
+
function requestedCheckoutsOf(spec, log) {
|
|
68135
|
+
const roots = spec.approvedWorkspacePaths ?? [];
|
|
68136
|
+
return (spec.requestedCheckouts ?? []).filter((checkout) => {
|
|
68137
|
+
const approved = roots.some((root) => isWithin(root, checkout.path, process.platform));
|
|
68138
|
+
if (!approved) {
|
|
68139
|
+
log.warn("workspace.requested_checkout_outside_workspace", {
|
|
67875
68140
|
runId: spec.runId,
|
|
67876
|
-
path:
|
|
67877
|
-
state: freshness.state,
|
|
67878
|
-
outcome: outcome2
|
|
68141
|
+
path: checkout.path
|
|
67879
68142
|
});
|
|
67880
68143
|
}
|
|
68144
|
+
return approved;
|
|
68145
|
+
});
|
|
68146
|
+
}
|
|
68147
|
+
async function applyRequestedCheckouts(spec, deps, signal) {
|
|
68148
|
+
const settled2 = /* @__PURE__ */ new Set();
|
|
68149
|
+
const lines2 = [];
|
|
68150
|
+
for (const checkout of requestedCheckoutsOf(spec, deps.log)) {
|
|
68151
|
+
const outcome2 = await applyRequestedCheckout(checkout, spec, deps, signal);
|
|
68152
|
+
deps.log.info("workspace.requested_checkout", {
|
|
68153
|
+
runId: spec.runId,
|
|
68154
|
+
path: checkout.path,
|
|
68155
|
+
branch: checkout.branch,
|
|
68156
|
+
outcome: outcome2.kind,
|
|
68157
|
+
...outcome2.kind === "moved" ? { how: outcome2.how } : {}
|
|
68158
|
+
});
|
|
68159
|
+
if (outcome2.kind === "on_branch") continue;
|
|
68160
|
+
settled2.add((0, import_node_path59.resolve)(checkout.path));
|
|
68161
|
+
if (outcome2.kind === "noted") lines2.push(outcome2.line);
|
|
68162
|
+
}
|
|
68163
|
+
return { settled: settled2, lines: lines2 };
|
|
68164
|
+
}
|
|
68165
|
+
async function refreshSnapshotCheckouts(spec, targets, settled2, deps, signal) {
|
|
68166
|
+
const lines2 = [];
|
|
68167
|
+
for (const target of targets) {
|
|
68168
|
+
if (settled2.has((0, import_node_path59.resolve)(target))) continue;
|
|
68169
|
+
const freshness = await readCheckoutFreshness(deps.dir, target);
|
|
68170
|
+
if (freshness === null) continue;
|
|
68171
|
+
const outcome2 = await atFirstLease(freshness, spec, deps, signal).catch(
|
|
68172
|
+
() => "noted"
|
|
68173
|
+
);
|
|
68174
|
+
if (outcome2 === "noted") lines2.push(lineFor(freshness));
|
|
68175
|
+
deps.log.info("workspace.refresh", {
|
|
68176
|
+
runId: spec.runId,
|
|
68177
|
+
path: freshness.path,
|
|
68178
|
+
state: freshness.state,
|
|
68179
|
+
outcome: outcome2
|
|
68180
|
+
});
|
|
68181
|
+
}
|
|
68182
|
+
return lines2;
|
|
68183
|
+
}
|
|
68184
|
+
function createCheckoutRefresh(deps) {
|
|
68185
|
+
return async (spec, leaseTargets, signal) => {
|
|
68186
|
+
if (spec.providerSessionId !== void 0) return void 0;
|
|
68187
|
+
if (!await claimOnce((0, import_node_path59.join)(deps.dir, "conversations"), spec.conversationId)) return void 0;
|
|
68188
|
+
const requested = await applyRequestedCheckouts(spec, deps, signal);
|
|
68189
|
+
const targets = await checkoutsOf(spec, leaseTargets);
|
|
68190
|
+
const lines2 = [
|
|
68191
|
+
...requested.lines,
|
|
68192
|
+
...await refreshSnapshotCheckouts(spec, targets, requested.settled, deps, signal)
|
|
68193
|
+
];
|
|
67881
68194
|
return lines2.length === 0 ? void 0 : lines2.join("\n");
|
|
67882
68195
|
};
|
|
67883
68196
|
}
|
|
67884
68197
|
|
|
67885
68198
|
// src/holder/lease.ts
|
|
67886
|
-
var
|
|
67887
|
-
var
|
|
68199
|
+
var import_promises60 = require("fs/promises");
|
|
68200
|
+
var import_node_path60 = require("path");
|
|
67888
68201
|
var LEASE_CHECK_EVERY_MS = 5e3;
|
|
67889
68202
|
var MAX_TRANSIENT_FAILURES = 3;
|
|
67890
68203
|
var BACKOFF_BASE_MS = 1e3;
|
|
@@ -67898,8 +68211,8 @@ function identityFailure(code, workspacePath) {
|
|
|
67898
68211
|
return { code, problemCode: "app.workspace.missing", message: MESSAGES[code], workspacePath };
|
|
67899
68212
|
}
|
|
67900
68213
|
async function fileIdentity(path4) {
|
|
67901
|
-
const canonical = await (0,
|
|
67902
|
-
const info = await (0,
|
|
68214
|
+
const canonical = await (0, import_promises60.realpath)(path4);
|
|
68215
|
+
const info = await (0, import_promises60.stat)(canonical, { bigint: true });
|
|
67903
68216
|
return `${canonical}:${info.dev}:${info.ino}`;
|
|
67904
68217
|
}
|
|
67905
68218
|
async function snapshot(git, path4, signal) {
|
|
@@ -67918,7 +68231,7 @@ async function snapshot(git, path4, signal) {
|
|
|
67918
68231
|
workspace: await fileIdentity(path4),
|
|
67919
68232
|
repository: await fileIdentity(commonDir),
|
|
67920
68233
|
worktree: await fileIdentity(gitDir),
|
|
67921
|
-
commonDir: await (0,
|
|
68234
|
+
commonDir: await (0, import_promises60.realpath)(commonDir)
|
|
67922
68235
|
};
|
|
67923
68236
|
} catch {
|
|
67924
68237
|
return null;
|
|
@@ -67931,7 +68244,7 @@ async function gitValue(git, path4, args, signal) {
|
|
|
67931
68244
|
}
|
|
67932
68245
|
async function pathExists(path4) {
|
|
67933
68246
|
try {
|
|
67934
|
-
await (0,
|
|
68247
|
+
await (0, import_promises60.stat)(path4);
|
|
67935
68248
|
return true;
|
|
67936
68249
|
} catch (error61) {
|
|
67937
68250
|
return errnoCode(error61) !== "ENOENT" && errnoCode(error61) !== "ENOTDIR";
|
|
@@ -67940,19 +68253,19 @@ async function pathExists(path4) {
|
|
|
67940
68253
|
async function hasGitMarker(path4) {
|
|
67941
68254
|
let directory;
|
|
67942
68255
|
try {
|
|
67943
|
-
directory = await (0,
|
|
68256
|
+
directory = await (0, import_promises60.realpath)(path4);
|
|
67944
68257
|
} catch {
|
|
67945
68258
|
return true;
|
|
67946
68259
|
}
|
|
67947
68260
|
for (; ; ) {
|
|
67948
68261
|
try {
|
|
67949
|
-
await (0,
|
|
68262
|
+
await (0, import_promises60.stat)((0, import_node_path60.join)(directory, ".git"));
|
|
67950
68263
|
return true;
|
|
67951
68264
|
} catch (error61) {
|
|
67952
68265
|
const code = errnoCode(error61);
|
|
67953
68266
|
if (code !== "ENOENT" && code !== "ENOTDIR") return true;
|
|
67954
68267
|
}
|
|
67955
|
-
const parent = (0,
|
|
68268
|
+
const parent = (0, import_node_path60.dirname)(directory);
|
|
67956
68269
|
if (parent === directory) return false;
|
|
67957
68270
|
directory = parent;
|
|
67958
68271
|
}
|
|
@@ -68116,7 +68429,7 @@ function volumeRoot(path4) {
|
|
|
68116
68429
|
}
|
|
68117
68430
|
async function exists4(path4) {
|
|
68118
68431
|
try {
|
|
68119
|
-
await (0,
|
|
68432
|
+
await (0, import_promises61.stat)(path4);
|
|
68120
68433
|
return true;
|
|
68121
68434
|
} catch {
|
|
68122
68435
|
return false;
|
|
@@ -68124,10 +68437,10 @@ async function exists4(path4) {
|
|
|
68124
68437
|
}
|
|
68125
68438
|
async function inspectReadiness(path4) {
|
|
68126
68439
|
try {
|
|
68127
|
-
if (!(await (0,
|
|
68440
|
+
if (!(await (0, import_promises61.stat)(path4)).isDirectory()) {
|
|
68128
68441
|
return { ready: false, missing: true, message: MESSAGES2.missing };
|
|
68129
68442
|
}
|
|
68130
|
-
await (0,
|
|
68443
|
+
await (0, import_promises61.access)(path4, import_node_fs19.constants.R_OK | import_node_fs19.constants.W_OK | import_node_fs19.constants.X_OK);
|
|
68131
68444
|
return { ready: true };
|
|
68132
68445
|
} catch (error61) {
|
|
68133
68446
|
const code = errnoCode(error61) ?? "";
|
|
@@ -68205,8 +68518,8 @@ async function admitDefaultWorkspace(spec, context, skills) {
|
|
|
68205
68518
|
const { env } = context;
|
|
68206
68519
|
const path4 = resolveAlanDefaultWorkspacePath(env.HOME || env.USERPROFILE || (0, import_node_os9.homedir)());
|
|
68207
68520
|
try {
|
|
68208
|
-
await (0,
|
|
68209
|
-
await (0,
|
|
68521
|
+
await (0, import_promises61.mkdir)(path4, { recursive: true, mode: 448 });
|
|
68522
|
+
await (0, import_promises61.access)(path4, import_node_fs19.constants.R_OK | import_node_fs19.constants.W_OK | import_node_fs19.constants.X_OK);
|
|
68210
68523
|
return {
|
|
68211
68524
|
kind: "admitted",
|
|
68212
68525
|
spec: { ...spec, projectPath: path4 },
|
|
@@ -68279,10 +68592,12 @@ async function admitRun(spec, context, signal) {
|
|
|
68279
68592
|
};
|
|
68280
68593
|
}
|
|
68281
68594
|
var PROBE_TIMEOUT_MS2 = 5e3;
|
|
68595
|
+
var CHECKOUT_LOCAL_TIMEOUT_MS = 6e4;
|
|
68596
|
+
var CHECKOUT_NETWORK_TIMEOUT_MS = 12e4;
|
|
68282
68597
|
function createHolderWorkspace(machine, clock, log) {
|
|
68283
68598
|
const platform3 = machine.platform ?? process.platform;
|
|
68284
68599
|
const git = createGitRunner({ env: machine.env, platform: platform3, localTimeoutMs: PROBE_TIMEOUT_MS2 });
|
|
68285
|
-
const locks = openRepositoryLocks({ dir: (0,
|
|
68600
|
+
const locks = openRepositoryLocks({ dir: (0, import_node_path61.join)(machine.stateDir, "locks"), clock, platform: platform3 });
|
|
68286
68601
|
return {
|
|
68287
68602
|
admission: {
|
|
68288
68603
|
env: machine.env,
|
|
@@ -68294,7 +68609,7 @@ function createHolderWorkspace(machine, clock, log) {
|
|
|
68294
68609
|
),
|
|
68295
68610
|
approvedRoots: async () => {
|
|
68296
68611
|
const approved = await openApprovedPaths({
|
|
68297
|
-
file: (0,
|
|
68612
|
+
file: (0, import_node_path61.join)(machine.stateDir, "workspaces.json"),
|
|
68298
68613
|
log,
|
|
68299
68614
|
platform: platform3
|
|
68300
68615
|
});
|
|
@@ -68304,10 +68619,15 @@ function createHolderWorkspace(machine, clock, log) {
|
|
|
68304
68619
|
lease: { git, locks, clock, log, platform: platform3 },
|
|
68305
68620
|
...machine.refreshesFirstCheckout === true ? {
|
|
68306
68621
|
refreshFirstCheckout: createCheckoutRefresh({
|
|
68307
|
-
git
|
|
68622
|
+
git: createGitRunner({
|
|
68623
|
+
env: machine.env,
|
|
68624
|
+
platform: platform3,
|
|
68625
|
+
localTimeoutMs: CHECKOUT_LOCAL_TIMEOUT_MS,
|
|
68626
|
+
networkTimeoutMs: CHECKOUT_NETWORK_TIMEOUT_MS
|
|
68627
|
+
}),
|
|
68308
68628
|
locks,
|
|
68309
68629
|
log,
|
|
68310
|
-
dir: (0,
|
|
68630
|
+
dir: (0, import_node_path61.join)(machine.stateDir, "checkout-freshness")
|
|
68311
68631
|
})
|
|
68312
68632
|
} : {}
|
|
68313
68633
|
};
|
|
@@ -68335,7 +68655,7 @@ async function respondToTurn(runningRunId, gate, driver, request2) {
|
|
|
68335
68655
|
}
|
|
68336
68656
|
|
|
68337
68657
|
// src/holder/session-facts.ts
|
|
68338
|
-
var
|
|
68658
|
+
var import_promises62 = require("fs/promises");
|
|
68339
68659
|
var CLI_RSS_CACHE_MS = 1e4;
|
|
68340
68660
|
var LOGIN_PROBLEM_PREFIX = "cli.auth.";
|
|
68341
68661
|
function isLoginFailure(result) {
|
|
@@ -68361,8 +68681,8 @@ function createSessionFacts(options) {
|
|
|
68361
68681
|
const path4 = await resolveCommandOnPath(command, env, platform3);
|
|
68362
68682
|
if (path4 === null) return null;
|
|
68363
68683
|
try {
|
|
68364
|
-
const real = await (0,
|
|
68365
|
-
const info = await (0,
|
|
68684
|
+
const real = await (0, import_promises62.realpath)(path4);
|
|
68685
|
+
const info = await (0, import_promises62.stat)(real);
|
|
68366
68686
|
return { command, key: `${real}:${info.ino}:${info.size}:${info.mtimeMs}` };
|
|
68367
68687
|
} catch {
|
|
68368
68688
|
return null;
|
|
@@ -68449,12 +68769,12 @@ function createSessionFacts(options) {
|
|
|
68449
68769
|
init_acp2();
|
|
68450
68770
|
|
|
68451
68771
|
// src/run-log/archive.ts
|
|
68452
|
-
var
|
|
68453
|
-
var
|
|
68772
|
+
var import_promises63 = require("fs/promises");
|
|
68773
|
+
var import_node_path62 = require("path");
|
|
68454
68774
|
init_runtime_v2();
|
|
68455
68775
|
async function openRunArchive(runsDir) {
|
|
68456
|
-
const path4 = (0,
|
|
68457
|
-
const text3 = await (0,
|
|
68776
|
+
const path4 = (0, import_node_path62.join)((0, import_node_path62.dirname)(runsDir), "archived-runs.txt");
|
|
68777
|
+
const text3 = await (0, import_promises63.readFile)(path4, "utf8").catch((error61) => {
|
|
68458
68778
|
if (errnoCode(error61) === "ENOENT") return "";
|
|
68459
68779
|
throw error61;
|
|
68460
68780
|
});
|
|
@@ -68468,7 +68788,7 @@ async function openRunArchive(runsDir) {
|
|
|
68468
68788
|
add: async (runIds) => {
|
|
68469
68789
|
const added = runIds.filter((runId) => !archived.has(runId));
|
|
68470
68790
|
if (added.length === 0) return;
|
|
68471
|
-
await (0,
|
|
68791
|
+
await (0, import_promises63.appendFile)(path4, `
|
|
68472
68792
|
${added.join("\n")}
|
|
68473
68793
|
`, { mode: 384 });
|
|
68474
68794
|
for (const runId of added) archived.add(runId);
|
|
@@ -68479,11 +68799,11 @@ ${added.join("\n")}
|
|
|
68479
68799
|
// src/run-log/complete.ts
|
|
68480
68800
|
var import_node_crypto29 = require("crypto");
|
|
68481
68801
|
var import_node_fs20 = require("fs");
|
|
68482
|
-
var
|
|
68802
|
+
var import_node_path64 = require("path");
|
|
68483
68803
|
|
|
68484
68804
|
// src/run-log/directory.ts
|
|
68485
|
-
var
|
|
68486
|
-
var
|
|
68805
|
+
var import_promises64 = require("fs/promises");
|
|
68806
|
+
var import_node_path63 = require("path");
|
|
68487
68807
|
init_runtime_v2();
|
|
68488
68808
|
init_zod();
|
|
68489
68809
|
var runMetaSchema = external_exports.object({
|
|
@@ -68509,17 +68829,17 @@ async function readRunMeta(path4) {
|
|
|
68509
68829
|
return read.kind === "ok" ? read.value : null;
|
|
68510
68830
|
}
|
|
68511
68831
|
function runDirectory(runsDir, runId) {
|
|
68512
|
-
const dir = (0,
|
|
68832
|
+
const dir = (0, import_node_path63.join)(runsDir, runId);
|
|
68513
68833
|
return {
|
|
68514
68834
|
dir,
|
|
68515
|
-
log: (0,
|
|
68516
|
-
upload: (0,
|
|
68517
|
-
meta: (0,
|
|
68835
|
+
log: (0, import_node_path63.join)(dir, "log.jsonl"),
|
|
68836
|
+
upload: (0, import_node_path63.join)(dir, "upload.json"),
|
|
68837
|
+
meta: (0, import_node_path63.join)(dir, "run.json")
|
|
68518
68838
|
};
|
|
68519
68839
|
}
|
|
68520
68840
|
async function isRunClaimed(runsDir, runId) {
|
|
68521
68841
|
try {
|
|
68522
|
-
return (await (0,
|
|
68842
|
+
return (await (0, import_promises64.stat)(runDirectory(runsDir, runId).log)).size > 0;
|
|
68523
68843
|
} catch (error61) {
|
|
68524
68844
|
if (errnoCode(error61) === "ENOENT") return false;
|
|
68525
68845
|
throw error61;
|
|
@@ -68528,7 +68848,7 @@ async function isRunClaimed(runsDir, runId) {
|
|
|
68528
68848
|
|
|
68529
68849
|
// src/run-log/complete.ts
|
|
68530
68850
|
function writeLogFile(path4, dir, text3) {
|
|
68531
|
-
const temp = (0,
|
|
68851
|
+
const temp = (0, import_node_path64.join)(dir, `.log.${(0, import_node_crypto29.randomUUID)()}.tmp`);
|
|
68532
68852
|
const fd = (0, import_node_fs20.openSync)(temp, "wx", 384);
|
|
68533
68853
|
try {
|
|
68534
68854
|
(0, import_node_fs20.writeSync)(fd, text3);
|
|
@@ -68557,8 +68877,8 @@ async function writeCompleteRunLog(runsDir, meta3, records) {
|
|
|
68557
68877
|
}
|
|
68558
68878
|
|
|
68559
68879
|
// src/run-log/conversation-index.ts
|
|
68560
|
-
var
|
|
68561
|
-
var
|
|
68880
|
+
var import_promises65 = require("fs/promises");
|
|
68881
|
+
var import_node_path65 = require("path");
|
|
68562
68882
|
init_runtime_v2();
|
|
68563
68883
|
init_zod();
|
|
68564
68884
|
var ORDINALS_PER_SHARD = 1e3;
|
|
@@ -68575,13 +68895,13 @@ var coverageSchema = external_exports.object({
|
|
|
68575
68895
|
nextExpectedOrdinal: external_exports.number().int().positive()
|
|
68576
68896
|
});
|
|
68577
68897
|
function conversationsDirectory(runsDir) {
|
|
68578
|
-
return (0,
|
|
68898
|
+
return (0, import_node_path65.join)((0, import_node_path65.dirname)(runsDir), "conversations");
|
|
68579
68899
|
}
|
|
68580
68900
|
function indexDirectory(runsDir, conversationId) {
|
|
68581
|
-
return (0,
|
|
68901
|
+
return (0, import_node_path65.join)(conversationsDirectory(runsDir), conversationId, "turn-index");
|
|
68582
68902
|
}
|
|
68583
68903
|
function shardPath(runsDir, conversationId, ordinal) {
|
|
68584
|
-
return (0,
|
|
68904
|
+
return (0, import_node_path65.join)(
|
|
68585
68905
|
indexDirectory(runsDir, conversationId),
|
|
68586
68906
|
`${Math.floor(ordinal / ORDINALS_PER_SHARD)}.jsonl`
|
|
68587
68907
|
);
|
|
@@ -68590,10 +68910,10 @@ async function indexConversationRun(runsDir, conversationId, ordinal, assistantO
|
|
|
68590
68910
|
const nextOrdinal = assistantOrdinal + 1;
|
|
68591
68911
|
if (nextOrdinal <= ordinal) throw new Error("Assistant order must follow the prompt");
|
|
68592
68912
|
const path4 = shardPath(runsDir, conversationId, ordinal);
|
|
68593
|
-
await (0,
|
|
68594
|
-
await (0,
|
|
68913
|
+
await (0, import_promises65.mkdir)((0, import_node_path65.dirname)(path4), { recursive: true, mode: 448 });
|
|
68914
|
+
await (0, import_promises65.appendFile)(path4, `${JSON.stringify({ ordinal, nextOrdinal, runId })}
|
|
68595
68915
|
`, { mode: 384 });
|
|
68596
|
-
const coveragePath = (0,
|
|
68916
|
+
const coveragePath = (0, import_node_path65.join)((0, import_node_path65.dirname)((0, import_node_path65.dirname)(path4)), "coverage.json");
|
|
68597
68917
|
const coverage = await readJsonFile(coveragePath, coverageSchema);
|
|
68598
68918
|
const current = coverage.kind === "ok" ? coverage.value : null;
|
|
68599
68919
|
const next = nextCoverage(current, ordinal, nextOrdinal);
|
|
@@ -68608,13 +68928,13 @@ function nextCoverage(current, ordinal, nextOrdinal) {
|
|
|
68608
68928
|
return null;
|
|
68609
68929
|
}
|
|
68610
68930
|
async function readConversationIndexCoverage(runsDir, conversationId) {
|
|
68611
|
-
const path4 = (0,
|
|
68931
|
+
const path4 = (0, import_node_path65.join)((0, import_node_path65.dirname)(indexDirectory(runsDir, conversationId)), "coverage.json");
|
|
68612
68932
|
const result = await readJsonFile(path4, coverageSchema);
|
|
68613
68933
|
return result.kind === "ok" ? result.value : null;
|
|
68614
68934
|
}
|
|
68615
68935
|
async function readConversationRunIndex(runsDir, conversationId, before, limit) {
|
|
68616
68936
|
const directory = indexDirectory(runsDir, conversationId);
|
|
68617
|
-
const names = await (0,
|
|
68937
|
+
const names = await (0, import_promises65.readdir)(directory).catch((error61) => {
|
|
68618
68938
|
if (error61.code === "ENOENT") return [];
|
|
68619
68939
|
throw error61;
|
|
68620
68940
|
});
|
|
@@ -68623,7 +68943,7 @@ async function readConversationRunIndex(runsDir, conversationId, before, limit)
|
|
|
68623
68943
|
).sort((left, right) => right - left);
|
|
68624
68944
|
const selected = [];
|
|
68625
68945
|
for (const shard of shards) {
|
|
68626
|
-
const text3 = await (0,
|
|
68946
|
+
const text3 = await (0, import_promises65.readFile)((0, import_node_path65.join)(directory, `${shard}.jsonl`), "utf8");
|
|
68627
68947
|
const records = text3.split("\n").flatMap((line) => {
|
|
68628
68948
|
if (!line) return [];
|
|
68629
68949
|
const parsed = indexRecordSchema.parse(JSON.parse(line));
|
|
@@ -68648,7 +68968,7 @@ async function readIndexableRun(runsDir, name) {
|
|
|
68648
68968
|
return { conversationId: meta3.conversationId, ordinal, assistantOrdinal, runId: runId.data };
|
|
68649
68969
|
}
|
|
68650
68970
|
async function readIndexableRuns(runsDir) {
|
|
68651
|
-
const names = await (0,
|
|
68971
|
+
const names = await (0, import_promises65.readdir)(runsDir).catch(() => []);
|
|
68652
68972
|
const byConversation = /* @__PURE__ */ new Map();
|
|
68653
68973
|
let next = 0;
|
|
68654
68974
|
const worker = async () => {
|
|
@@ -68678,21 +68998,21 @@ async function writeConversationIndex(directory, runs) {
|
|
|
68678
68998
|
else lines2.push(line);
|
|
68679
68999
|
coverage = nextCoverage(coverage, run2.ordinal, nextOrdinal) ?? coverage;
|
|
68680
69000
|
}
|
|
68681
|
-
await (0,
|
|
69001
|
+
await (0, import_promises65.mkdir)((0, import_node_path65.join)(directory, "turn-index"), { recursive: true, mode: 448 });
|
|
68682
69002
|
for (const [shard, lines2] of shards) {
|
|
68683
|
-
await (0,
|
|
69003
|
+
await (0, import_promises65.writeFile)((0, import_node_path65.join)(directory, "turn-index", `${shard}.jsonl`), `${lines2.join("\n")}
|
|
68684
69004
|
`, {
|
|
68685
69005
|
mode: 384
|
|
68686
69006
|
});
|
|
68687
69007
|
}
|
|
68688
|
-
await (0,
|
|
69008
|
+
await (0, import_promises65.writeFile)((0, import_node_path65.join)(directory, "coverage.json"), `${JSON.stringify(coverage)}
|
|
68689
69009
|
`, {
|
|
68690
69010
|
mode: 384
|
|
68691
69011
|
});
|
|
68692
69012
|
}
|
|
68693
69013
|
async function rebuildConversationIndexes(runsDir) {
|
|
68694
69014
|
const root = conversationsDirectory(runsDir);
|
|
68695
|
-
const exists6 = await (0,
|
|
69015
|
+
const exists6 = await (0, import_promises65.stat)(root).then(
|
|
68696
69016
|
() => true,
|
|
68697
69017
|
(error61) => {
|
|
68698
69018
|
if (errnoCode(error61) === "ENOENT") return false;
|
|
@@ -68701,18 +69021,18 @@ async function rebuildConversationIndexes(runsDir) {
|
|
|
68701
69021
|
);
|
|
68702
69022
|
if (exists6) return 0;
|
|
68703
69023
|
const building = `${root}.rebuilding`;
|
|
68704
|
-
await (0,
|
|
68705
|
-
await (0,
|
|
69024
|
+
await (0, import_promises65.rm)(building, { recursive: true, force: true });
|
|
69025
|
+
await (0, import_promises65.mkdir)(building, { recursive: true, mode: 448 });
|
|
68706
69026
|
const byConversation = await readIndexableRuns(runsDir);
|
|
68707
69027
|
for (const [conversationId, runs] of byConversation) {
|
|
68708
|
-
await writeConversationIndex((0,
|
|
69028
|
+
await writeConversationIndex((0, import_node_path65.join)(building, conversationId), runs);
|
|
68709
69029
|
}
|
|
68710
|
-
await (0,
|
|
69030
|
+
await (0, import_promises65.rename)(building, root);
|
|
68711
69031
|
return byConversation.size;
|
|
68712
69032
|
}
|
|
68713
69033
|
|
|
68714
69034
|
// src/run-log/reader.ts
|
|
68715
|
-
var
|
|
69035
|
+
var import_promises66 = require("fs/promises");
|
|
68716
69036
|
init_runtime_v2();
|
|
68717
69037
|
|
|
68718
69038
|
// src/run-log/tail.ts
|
|
@@ -68735,7 +69055,7 @@ function firstRecordLength(bytes) {
|
|
|
68735
69055
|
return bytes.indexOf(RUN_LOG_RECORD_SEPARATOR) + 1;
|
|
68736
69056
|
}
|
|
68737
69057
|
async function openRunLogReader(path4) {
|
|
68738
|
-
const handle = await (0,
|
|
69058
|
+
const handle = await (0, import_promises66.open)(path4, "r");
|
|
68739
69059
|
const readAt = async (position, length) => {
|
|
68740
69060
|
const buffer = Buffer.alloc(length);
|
|
68741
69061
|
const { bytesRead } = await handle.read(buffer, 0, length, position);
|
|
@@ -68769,7 +69089,7 @@ async function openRunLogReader(path4) {
|
|
|
68769
69089
|
};
|
|
68770
69090
|
}
|
|
68771
69091
|
async function readLastRecord(path4) {
|
|
68772
|
-
const handle = await (0,
|
|
69092
|
+
const handle = await (0, import_promises66.open)(path4, "r").catch(() => null);
|
|
68773
69093
|
if (handle === null) return null;
|
|
68774
69094
|
try {
|
|
68775
69095
|
const { size } = await handle.stat();
|
|
@@ -68803,7 +69123,7 @@ var decoder = new TextDecoder();
|
|
|
68803
69123
|
|
|
68804
69124
|
// src/run-log/writer.ts
|
|
68805
69125
|
var import_node_fs21 = require("fs");
|
|
68806
|
-
var
|
|
69126
|
+
var import_node_path66 = require("path");
|
|
68807
69127
|
init_runtime_v2();
|
|
68808
69128
|
function lastSeq(fd, size) {
|
|
68809
69129
|
for (const length of tailWindows(size)) {
|
|
@@ -68819,7 +69139,7 @@ function lastSeq(fd, size) {
|
|
|
68819
69139
|
throw new RuntimeFault("record_too_large", "Run log tail record is larger than any record");
|
|
68820
69140
|
}
|
|
68821
69141
|
function openRunLog(path4, clock) {
|
|
68822
|
-
(0, import_node_fs21.mkdirSync)((0,
|
|
69142
|
+
(0, import_node_fs21.mkdirSync)((0, import_node_path66.dirname)(path4), { recursive: true, mode: 448 });
|
|
68823
69143
|
const fd = (0, import_node_fs21.openSync)(path4, "a+", 384);
|
|
68824
69144
|
let size = (0, import_node_fs21.fstatSync)(fd).size;
|
|
68825
69145
|
let seq = lastSeq(fd, size);
|
|
@@ -69155,7 +69475,7 @@ async function runHolder({
|
|
|
69155
69475
|
try {
|
|
69156
69476
|
const identity = await readProcessIdentity(process.pid);
|
|
69157
69477
|
if (identity === null) throw new RuntimeFault("internal", "Cannot read own process identity");
|
|
69158
|
-
const _engines = __using(_stack, recordSpawnedEngines(engineRecordsPath((0,
|
|
69478
|
+
const _engines = __using(_stack, recordSpawnedEngines(engineRecordsPath((0, import_node_path67.dirname)(launch.statusPath)), clock, log));
|
|
69159
69479
|
const holder = {
|
|
69160
69480
|
state: "idle",
|
|
69161
69481
|
runId: null,
|
|
@@ -69351,16 +69671,16 @@ async function runHolder({
|
|
|
69351
69671
|
client.on("error", () => holder.clients.delete(client));
|
|
69352
69672
|
});
|
|
69353
69673
|
removeStaleEndpoint(launch.endpoint);
|
|
69354
|
-
await new Promise((
|
|
69674
|
+
await new Promise((resolve14, reject) => {
|
|
69355
69675
|
server.once("error", reject);
|
|
69356
|
-
server.listen(launch.endpoint, () =>
|
|
69676
|
+
server.listen(launch.endpoint, () => resolve14());
|
|
69357
69677
|
});
|
|
69358
69678
|
await writeStatus();
|
|
69359
69679
|
log.info("holder.ready", { conversationId: launch.conversationId, pid: identity.pid });
|
|
69360
|
-
await new Promise((
|
|
69680
|
+
await new Promise((resolve14) => exit.signal.addEventListener("abort", () => resolve14()));
|
|
69361
69681
|
await driver.suspend?.().catch((error61) => log.warn("holder.driver_suspend_failed", { error: error61 }));
|
|
69362
69682
|
for (const client of holder.clients) client.end();
|
|
69363
|
-
await new Promise((
|
|
69683
|
+
await new Promise((resolve14) => server.close(() => resolve14()));
|
|
69364
69684
|
(0, import_node_fs22.rmSync)(launch.statusPath, { force: true });
|
|
69365
69685
|
log.info("holder.suspended", { conversationId: launch.conversationId });
|
|
69366
69686
|
} catch (_) {
|
|
@@ -69449,7 +69769,7 @@ var DEFAULT_MAX_ACTIVE_RUNS = 32;
|
|
|
69449
69769
|
var HOLDER_BUSY = "busy";
|
|
69450
69770
|
async function listIds(dir, schema) {
|
|
69451
69771
|
const ids = [];
|
|
69452
|
-
for (const name of await (0,
|
|
69772
|
+
for (const name of await (0, import_promises67.readdir)(dir).catch(() => [])) {
|
|
69453
69773
|
const parsed = schema.safeParse(name);
|
|
69454
69774
|
if (parsed.success) ids.push(parsed.data);
|
|
69455
69775
|
}
|
|
@@ -69463,14 +69783,14 @@ function holderIdentity(status) {
|
|
|
69463
69783
|
return command === void 0 ? { pid, startedAt } : { pid, startedAt, command };
|
|
69464
69784
|
}
|
|
69465
69785
|
function sessionFiles(paths, conversationId) {
|
|
69466
|
-
const dir = (0,
|
|
69467
|
-
return { dir, launch: (0,
|
|
69786
|
+
const dir = (0, import_node_path68.join)(paths.sessions, conversationId);
|
|
69787
|
+
return { dir, launch: (0, import_node_path68.join)(dir, "launch.json"), status: (0, import_node_path68.join)(dir, "holder.json") };
|
|
69468
69788
|
}
|
|
69469
69789
|
async function removeHolderFiles(files) {
|
|
69470
69790
|
for (const path4 of [files.launch, files.status, engineRecordsPath(files.dir)]) {
|
|
69471
|
-
await (0,
|
|
69791
|
+
await (0, import_promises67.rm)(path4, { force: true });
|
|
69472
69792
|
}
|
|
69473
|
-
await (0,
|
|
69793
|
+
await (0, import_promises67.rmdir)(files.dir).catch((error61) => {
|
|
69474
69794
|
if (!["ENOENT", "ENOTEMPTY", "EEXIST"].includes(errnoCode(error61) ?? "")) throw error61;
|
|
69475
69795
|
});
|
|
69476
69796
|
}
|
|
@@ -69660,7 +69980,7 @@ async function openSessions(deps) {
|
|
|
69660
69980
|
const meta3 = await readRunMeta(dir.meta);
|
|
69661
69981
|
const last = await readLastRecord(dir.log);
|
|
69662
69982
|
if (meta3 === null || last === null) return null;
|
|
69663
|
-
const logged = await (0,
|
|
69983
|
+
const logged = await (0, import_promises67.stat)(dir.log).catch((error61) => {
|
|
69664
69984
|
if (errnoCode(error61) === "ENOENT") return null;
|
|
69665
69985
|
throw error61;
|
|
69666
69986
|
});
|
|
@@ -69972,7 +70292,7 @@ function loadRuntimeConfig(env = process.env, totalMemoryBytes = (0, import_node
|
|
|
69972
70292
|
providerProbes: ALAN_RUNTIME_PROVIDER_PROBES === "on",
|
|
69973
70293
|
providerToolchain: ALAN_RUNTIME_PROVIDER_NODE !== void 0 && ALAN_RUNTIME_PROVIDER_NPM_CLI !== void 0 ? { node: ALAN_RUNTIME_PROVIDER_NODE, npmCli: ALAN_RUNTIME_PROVIDER_NPM_CLI } : null,
|
|
69974
70294
|
home,
|
|
69975
|
-
configHome: XDG_CONFIG_HOME ?? (0,
|
|
70295
|
+
configHome: XDG_CONFIG_HOME ?? (0, import_node_path69.join)(home, ".config"),
|
|
69976
70296
|
codexHome: resolveCodexHome(CODEX_HOME, home),
|
|
69977
70297
|
...githubProxyConfig({ ALAN_RUNTIME_GITHUB_PROXY, XDG_CONFIG_HOME, GH_CONFIG_DIR }, home),
|
|
69978
70298
|
gitGatewayUrl: ALAN_RUNTIME_GIT_GATEWAY_URL ?? null,
|
|
@@ -69982,13 +70302,13 @@ function loadRuntimeConfig(env = process.env, totalMemoryBytes = (0, import_node
|
|
|
69982
70302
|
};
|
|
69983
70303
|
}
|
|
69984
70304
|
function resolveCodexHome(configuredHome, home) {
|
|
69985
|
-
return configuredHome ?? (0,
|
|
70305
|
+
return configuredHome ?? (0, import_node_path69.join)(home, ".codex");
|
|
69986
70306
|
}
|
|
69987
70307
|
function githubProxyConfig(env, home) {
|
|
69988
|
-
const configHome = env.XDG_CONFIG_HOME ?? (0,
|
|
70308
|
+
const configHome = env.XDG_CONFIG_HOME ?? (0, import_node_path69.join)(home, ".config");
|
|
69989
70309
|
return {
|
|
69990
70310
|
githubProxy: env.ALAN_RUNTIME_GITHUB_PROXY === "on",
|
|
69991
|
-
ghConfigDir: env.GH_CONFIG_DIR ?? (0,
|
|
70311
|
+
ghConfigDir: env.GH_CONFIG_DIR ?? (0, import_node_path69.join)(configHome, "gh")
|
|
69992
70312
|
};
|
|
69993
70313
|
}
|
|
69994
70314
|
function serviceEnvironment2(env, profile) {
|
|
@@ -70046,9 +70366,9 @@ function takeEnrollmentCodeFromEnv(env = process.env) {
|
|
|
70046
70366
|
}
|
|
70047
70367
|
|
|
70048
70368
|
// src/cli/context.ts
|
|
70049
|
-
var
|
|
70369
|
+
var import_promises68 = require("fs/promises");
|
|
70050
70370
|
var import_node_os12 = require("os");
|
|
70051
|
-
var
|
|
70371
|
+
var import_node_path70 = require("path");
|
|
70052
70372
|
var DESKTOP_BUNDLE_IDS = {
|
|
70053
70373
|
production: ["com.alan-ai.desktop"],
|
|
70054
70374
|
staging: ["com.alan-ai.desktop.staging"],
|
|
@@ -70088,7 +70408,7 @@ function serviceSpec({ config: config2, paths, self }) {
|
|
|
70088
70408
|
profile: config2.profile,
|
|
70089
70409
|
program: serviceCommand(config2.host, self, launcher),
|
|
70090
70410
|
environment: config2.serviceEnvironment,
|
|
70091
|
-
logPath: (0,
|
|
70411
|
+
logPath: (0, import_node_path70.join)(paths.logs, "service.log"),
|
|
70092
70412
|
associatedBundleIds: DESKTOP_BUNDLE_IDS[config2.profile]
|
|
70093
70413
|
};
|
|
70094
70414
|
}
|
|
@@ -70096,7 +70416,7 @@ async function installedServiceSpec(ctx) {
|
|
|
70096
70416
|
const spec = serviceSpec(ctx);
|
|
70097
70417
|
if (ctx.config.host === "app") return spec;
|
|
70098
70418
|
const layout = installLayout(ctx.config.installDir, ctx.config.profile);
|
|
70099
|
-
const installed = await (0,
|
|
70419
|
+
const installed = await (0, import_promises68.access)(layout.launcher).then(
|
|
70100
70420
|
() => true,
|
|
70101
70421
|
() => false
|
|
70102
70422
|
);
|
|
@@ -70224,7 +70544,7 @@ var manifestRevisionSchema = external_exports.object({ revision: external_export
|
|
|
70224
70544
|
async function manifestRevision(path4) {
|
|
70225
70545
|
let raw;
|
|
70226
70546
|
try {
|
|
70227
|
-
raw = JSON.parse(await (0,
|
|
70547
|
+
raw = JSON.parse(await (0, import_promises69.readFile)(path4, "utf8"));
|
|
70228
70548
|
} catch (error61) {
|
|
70229
70549
|
throw new RuntimeFault("invalid_file", `Cannot read the skill manifest at ${path4}`, {
|
|
70230
70550
|
cause: error61
|
|
@@ -70278,8 +70598,8 @@ async function runSkills(argv) {
|
|
|
70278
70598
|
}
|
|
70279
70599
|
|
|
70280
70600
|
// src/cli/commands/doctor.ts
|
|
70281
|
-
var
|
|
70282
|
-
var
|
|
70601
|
+
var import_promises72 = require("fs/promises");
|
|
70602
|
+
var import_node_path74 = require("path");
|
|
70283
70603
|
init_runtime_v2();
|
|
70284
70604
|
|
|
70285
70605
|
// src/identity/credential.ts
|
|
@@ -70456,18 +70776,18 @@ async function authorizeDevice(input2) {
|
|
|
70456
70776
|
}
|
|
70457
70777
|
|
|
70458
70778
|
// src/identity/enroll.ts
|
|
70459
|
-
var
|
|
70779
|
+
var import_promises70 = require("fs/promises");
|
|
70460
70780
|
init_runtime_v2();
|
|
70461
70781
|
|
|
70462
70782
|
// src/identity/installation.ts
|
|
70463
70783
|
var import_node_crypto33 = require("crypto");
|
|
70464
|
-
var
|
|
70784
|
+
var import_node_path71 = require("path");
|
|
70465
70785
|
init_zod();
|
|
70466
70786
|
var installationFileSchema = external_exports.object({
|
|
70467
70787
|
installationId: external_exports.uuid()
|
|
70468
70788
|
});
|
|
70469
70789
|
function installationPath(paths) {
|
|
70470
|
-
return (0,
|
|
70790
|
+
return (0, import_node_path71.join)(paths.stateDir, "installation.json");
|
|
70471
70791
|
}
|
|
70472
70792
|
async function ensureInstallationId(paths) {
|
|
70473
70793
|
const path4 = installationPath(paths);
|
|
@@ -70560,13 +70880,13 @@ async function enrollFromGrantFile(input2) {
|
|
|
70560
70880
|
clock: input2.clock,
|
|
70561
70881
|
access: input2.access
|
|
70562
70882
|
});
|
|
70563
|
-
await (0,
|
|
70883
|
+
await (0, import_promises70.rm)(input2.grantPath, { force: true });
|
|
70564
70884
|
return machine;
|
|
70565
70885
|
}
|
|
70566
70886
|
|
|
70567
70887
|
// src/identity/migrate-v1.ts
|
|
70568
|
-
var
|
|
70569
|
-
var
|
|
70888
|
+
var import_promises71 = require("fs/promises");
|
|
70889
|
+
var import_node_path72 = require("path");
|
|
70570
70890
|
init_runtime_v2();
|
|
70571
70891
|
init_zod();
|
|
70572
70892
|
var EXIT_POLL_MS = 200;
|
|
@@ -70587,11 +70907,11 @@ var ownerLeaseSchema = external_exports.looseObject({ pid: external_exports.numb
|
|
|
70587
70907
|
function legacyConfigPath(home, profile) {
|
|
70588
70908
|
switch (profile) {
|
|
70589
70909
|
case "production":
|
|
70590
|
-
return (0,
|
|
70910
|
+
return (0, import_node_path72.join)(home, ".alan", "agent", "config.json");
|
|
70591
70911
|
case "staging":
|
|
70592
|
-
return (0,
|
|
70912
|
+
return (0, import_node_path72.join)(home, ".alan-staging", "agent", "config.json");
|
|
70593
70913
|
default:
|
|
70594
|
-
return (0,
|
|
70914
|
+
return (0, import_node_path72.join)(home, ".alan-dev", "agent", "config.json");
|
|
70595
70915
|
}
|
|
70596
70916
|
}
|
|
70597
70917
|
async function findLegacyInstall(home, profile) {
|
|
@@ -70616,8 +70936,8 @@ async function scrubLegacyInstall(install2) {
|
|
|
70616
70936
|
const scrubbed = { ...install2.config, migratedToRuntimeV2: true };
|
|
70617
70937
|
for (const key of SCRUBBED_KEYS) delete scrubbed[key];
|
|
70618
70938
|
await writeJsonFileAtomic(`${install2.configPath}.migrated-v1`, scrubbed);
|
|
70619
|
-
await (0,
|
|
70620
|
-
await (0,
|
|
70939
|
+
await (0, import_promises71.rm)(install2.configPath, { force: true });
|
|
70940
|
+
await (0, import_promises71.rm)(install2.ownerLeasePath, { force: true });
|
|
70621
70941
|
}
|
|
70622
70942
|
async function exchangeCredential(deps) {
|
|
70623
70943
|
const { config: config2 } = deps.install;
|
|
@@ -70726,7 +71046,7 @@ async function loadIdentity(paths, options = {}) {
|
|
|
70726
71046
|
}
|
|
70727
71047
|
|
|
70728
71048
|
// src/cli/commands/status.ts
|
|
70729
|
-
var
|
|
71049
|
+
var import_node_path73 = require("path");
|
|
70730
71050
|
async function serviceStatus(ctx) {
|
|
70731
71051
|
try {
|
|
70732
71052
|
return await createServiceManager(ctx.host, ctx.config.profile).status();
|
|
@@ -70753,7 +71073,7 @@ async function runtimeState(ctx) {
|
|
|
70753
71073
|
const running = await readRunningRuntime(ctx.paths.lock);
|
|
70754
71074
|
if (running === null) return { state: "offline", pid: null, localApi: null };
|
|
70755
71075
|
const discovery = await readJsonFile(
|
|
70756
|
-
(0,
|
|
71076
|
+
(0, import_node_path73.join)(ctx.paths.stateDir, LOCAL_API_DISCOVERY_FILE),
|
|
70757
71077
|
localApiDiscoverySchema
|
|
70758
71078
|
);
|
|
70759
71079
|
const localApi = discovery.kind === "ok" && discovery.value.pid === running.pid ? {
|
|
@@ -70974,7 +71294,7 @@ async function runtimeCheck(ctx, status) {
|
|
|
70974
71294
|
return check2("runtime", "warn", "No runtime is running for this profile");
|
|
70975
71295
|
}
|
|
70976
71296
|
const client = createRuntimeClient({
|
|
70977
|
-
discoveryPath: (0,
|
|
71297
|
+
discoveryPath: (0, import_node_path74.join)(ctx.paths.stateDir, LOCAL_API_DISCOVERY_FILE)
|
|
70978
71298
|
});
|
|
70979
71299
|
try {
|
|
70980
71300
|
const live = await client.status(AbortSignal.timeout(LOCAL_TIMEOUT_MS));
|
|
@@ -71001,7 +71321,7 @@ async function runtimeCheck(ctx, status) {
|
|
|
71001
71321
|
}
|
|
71002
71322
|
}
|
|
71003
71323
|
async function probeHolder(dir, conversationId) {
|
|
71004
|
-
const launch = await readJsonFile((0,
|
|
71324
|
+
const launch = await readJsonFile((0, import_node_path74.join)(dir, "launch.json"), holderLaunchSchema);
|
|
71005
71325
|
if (launch.kind !== "ok") return null;
|
|
71006
71326
|
try {
|
|
71007
71327
|
const reply2 = await withTimeout(
|
|
@@ -71026,8 +71346,8 @@ async function probeHolder(dir, conversationId) {
|
|
|
71026
71346
|
}
|
|
71027
71347
|
}
|
|
71028
71348
|
async function holdersCheck(ctx) {
|
|
71029
|
-
const names = await (0,
|
|
71030
|
-
const holders = (await Promise.all(names.map((name) => probeHolder((0,
|
|
71349
|
+
const names = await (0, import_promises72.readdir)(ctx.paths.sessions).catch(() => []);
|
|
71350
|
+
const holders = (await Promise.all(names.map((name) => probeHolder((0, import_node_path74.join)(ctx.paths.sessions, name), name)))).filter((facts) => facts !== null);
|
|
71031
71351
|
const dead = holders.filter((holder) => !holder.alive).length;
|
|
71032
71352
|
return check2(
|
|
71033
71353
|
"holders",
|
|
@@ -71038,10 +71358,10 @@ async function holdersCheck(ctx) {
|
|
|
71038
71358
|
}
|
|
71039
71359
|
async function freeBytesAt(path4) {
|
|
71040
71360
|
try {
|
|
71041
|
-
const stats = await (0,
|
|
71361
|
+
const stats = await (0, import_promises72.statfs)(path4);
|
|
71042
71362
|
return { path: path4, freeBytes: stats.bavail * stats.bsize };
|
|
71043
71363
|
} catch (error61) {
|
|
71044
|
-
const parent = (0,
|
|
71364
|
+
const parent = (0, import_node_path74.dirname)(path4);
|
|
71045
71365
|
if (parent === path4) throw error61;
|
|
71046
71366
|
return freeBytesAt(parent);
|
|
71047
71367
|
}
|
|
@@ -71059,9 +71379,9 @@ async function diskCheck(ctx) {
|
|
|
71059
71379
|
}
|
|
71060
71380
|
}
|
|
71061
71381
|
var resolveFromLoginShell = (own2) => resolveCliEnvironment({ env: own2, platform: process.platform });
|
|
71062
|
-
async function cliDiscoveryCheck(
|
|
71382
|
+
async function cliDiscoveryCheck(resolve14) {
|
|
71063
71383
|
const own2 = readCliEnvironment();
|
|
71064
|
-
const env = await
|
|
71384
|
+
const env = await resolve14(own2);
|
|
71065
71385
|
const delimiter = process.platform === "win32" ? ";" : ":";
|
|
71066
71386
|
const ownDirs = new Set((own2.PATH ?? "").split(delimiter));
|
|
71067
71387
|
const added = (env.PATH ?? "").split(delimiter).filter((dir) => dir.length > 0 && !ownDirs.has(dir));
|
|
@@ -71177,7 +71497,7 @@ async function runDoctor(argv, context = cliContext) {
|
|
|
71177
71497
|
}
|
|
71178
71498
|
|
|
71179
71499
|
// src/cli/commands/git-credential.ts
|
|
71180
|
-
var
|
|
71500
|
+
var import_promises73 = require("fs/promises");
|
|
71181
71501
|
var import_node_net4 = require("net");
|
|
71182
71502
|
var MAX_RESPONSE_BYTES = 64 * 1024;
|
|
71183
71503
|
async function readAll(stream) {
|
|
@@ -71195,7 +71515,7 @@ function processIo() {
|
|
|
71195
71515
|
};
|
|
71196
71516
|
}
|
|
71197
71517
|
function askGitCredentialSocket(endpoint, request2, signal) {
|
|
71198
|
-
return new Promise((
|
|
71518
|
+
return new Promise((resolve14, reject) => {
|
|
71199
71519
|
const socket = (0, import_node_net4.createConnection)(endpoint);
|
|
71200
71520
|
let buffered = "";
|
|
71201
71521
|
const fail = (error61) => {
|
|
@@ -71222,7 +71542,7 @@ function askGitCredentialSocket(endpoint, request2, signal) {
|
|
|
71222
71542
|
signal.removeEventListener("abort", onAbort);
|
|
71223
71543
|
try {
|
|
71224
71544
|
const line = buffered.split("\n", 1)[0] ?? "";
|
|
71225
|
-
|
|
71545
|
+
resolve14(gitCredentialSocketResponseSchema.parse(JSON.parse(line)));
|
|
71226
71546
|
} catch (error61) {
|
|
71227
71547
|
reject(
|
|
71228
71548
|
new RuntimeFault("io_failed", "the Alan runtime sent an invalid reply", { cause: error61 })
|
|
@@ -71287,7 +71607,7 @@ async function configure(argv) {
|
|
|
71287
71607
|
}
|
|
71288
71608
|
async function configureGitGateway(config2, gatewayUrl, signal) {
|
|
71289
71609
|
const { launcher } = installLayout(config2.installDir, config2.profile);
|
|
71290
|
-
const installed = await (0,
|
|
71610
|
+
const installed = await (0, import_promises73.access)(launcher).then(
|
|
71291
71611
|
() => true,
|
|
71292
71612
|
() => false
|
|
71293
71613
|
);
|
|
@@ -71314,7 +71634,7 @@ async function runGitCredential(argv) {
|
|
|
71314
71634
|
}
|
|
71315
71635
|
|
|
71316
71636
|
// src/cli/commands/hold.ts
|
|
71317
|
-
var
|
|
71637
|
+
var import_node_path75 = require("path");
|
|
71318
71638
|
init_agent2();
|
|
71319
71639
|
init_runtime_v2();
|
|
71320
71640
|
async function machineAccess(paths, log, conversationId, transport) {
|
|
@@ -71372,7 +71692,7 @@ async function runHold(argv) {
|
|
|
71372
71692
|
const config2 = loadRuntimeConfig();
|
|
71373
71693
|
const paths = runtimePaths(config2.stateDir);
|
|
71374
71694
|
const log = __using(_stack, openFileLog(
|
|
71375
|
-
(0,
|
|
71695
|
+
(0, import_node_path75.join)(paths.logs, `holder-${launch.value.conversationId}.jsonl`),
|
|
71376
71696
|
config2.logLevel,
|
|
71377
71697
|
systemClock
|
|
71378
71698
|
));
|
|
@@ -71383,7 +71703,7 @@ async function runHold(argv) {
|
|
|
71383
71703
|
);
|
|
71384
71704
|
const transport = __using(_stack, createHttpTransport());
|
|
71385
71705
|
const access7 = await machineAccess(paths, log, launch.value.conversationId, transport);
|
|
71386
|
-
const credentialPath = (0,
|
|
71706
|
+
const credentialPath = (0, import_node_path75.join)(paths.tmp, "mcp", `${launch.value.conversationId}.json`);
|
|
71387
71707
|
const managedMcp = __using(_stack, access7.managedMcp === void 0 ? void 0 : createHelperMcpAccess({
|
|
71388
71708
|
managedMcp: access7.managedMcp,
|
|
71389
71709
|
conversationId: launch.value.conversationId,
|
|
@@ -71424,7 +71744,7 @@ async function runHold(argv) {
|
|
|
71424
71744
|
}
|
|
71425
71745
|
|
|
71426
71746
|
// src/cli/commands/hook.ts
|
|
71427
|
-
var
|
|
71747
|
+
var import_node_path76 = require("path");
|
|
71428
71748
|
var RUNTIME_ANSWER_MS = 2e3;
|
|
71429
71749
|
var DEBUG_VARIABLE = "ALAN_HOOK_DEBUG";
|
|
71430
71750
|
function flag(argv, name) {
|
|
@@ -71456,7 +71776,7 @@ async function forwardHook(argv, io) {
|
|
|
71456
71776
|
return "transcript outside provider root";
|
|
71457
71777
|
}
|
|
71458
71778
|
const verdict = await io.send(
|
|
71459
|
-
(0,
|
|
71779
|
+
(0, import_node_path76.join)(io.stateDir, LOCAL_API_DISCOVERY_FILE),
|
|
71460
71780
|
hookSignal,
|
|
71461
71781
|
AbortSignal.timeout(RUNTIME_ANSWER_MS)
|
|
71462
71782
|
);
|
|
@@ -71492,7 +71812,7 @@ async function runHook(argv, overrides = {}) {
|
|
|
71492
71812
|
}
|
|
71493
71813
|
|
|
71494
71814
|
// src/cli/commands/ingestion-hooks.ts
|
|
71495
|
-
var
|
|
71815
|
+
var import_promises74 = require("fs/promises");
|
|
71496
71816
|
var CODEX_TRUST_NOTE = "Codex runs new hooks only after you review them: open /hooks in Codex.";
|
|
71497
71817
|
function isAction(value2) {
|
|
71498
71818
|
return value2 === "enable" || value2 === "disable" || value2 === "status";
|
|
@@ -71515,7 +71835,7 @@ function errorMessage2(error61) {
|
|
|
71515
71835
|
return error61 instanceof Error ? error61.message : String(error61);
|
|
71516
71836
|
}
|
|
71517
71837
|
async function exists5(path4) {
|
|
71518
|
-
return (0,
|
|
71838
|
+
return (0, import_promises74.access)(path4).then(
|
|
71519
71839
|
() => true,
|
|
71520
71840
|
() => false
|
|
71521
71841
|
);
|
|
@@ -71618,10 +71938,10 @@ async function runIntegrationsCommand(argv) {
|
|
|
71618
71938
|
}
|
|
71619
71939
|
|
|
71620
71940
|
// src/cli/commands/legacy.ts
|
|
71621
|
-
var
|
|
71941
|
+
var import_node_path78 = require("path");
|
|
71622
71942
|
|
|
71623
71943
|
// src/cli/commands/setup.ts
|
|
71624
|
-
var
|
|
71944
|
+
var import_node_path77 = require("path");
|
|
71625
71945
|
init_zod();
|
|
71626
71946
|
|
|
71627
71947
|
// src/cli/legacy.ts
|
|
@@ -71703,7 +72023,7 @@ async function grantFileCredential(argv, grantPath, ctx, deps) {
|
|
|
71703
72023
|
return enrollFromGrantFile({
|
|
71704
72024
|
paths: ctx.paths,
|
|
71705
72025
|
storeKind: credentialStoreFlag(argv) ?? ctx.config.credentialStore,
|
|
71706
|
-
grantPath: (0,
|
|
72026
|
+
grantPath: (0, import_node_path77.resolve)(grantPath),
|
|
71707
72027
|
clock: deps.clock,
|
|
71708
72028
|
access: ctx.access
|
|
71709
72029
|
});
|
|
@@ -71779,7 +72099,7 @@ async function runSetup(argv, signal) {
|
|
|
71779
72099
|
var _stack = [];
|
|
71780
72100
|
try {
|
|
71781
72101
|
const ctx = cliContext();
|
|
71782
|
-
const log = __using(_stack, openFileLog((0,
|
|
72102
|
+
const log = __using(_stack, openFileLog((0, import_node_path77.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
|
|
71783
72103
|
const result = await setupMachine(argv, ctx, {
|
|
71784
72104
|
enrollment: (apiUrl) => createEnrollmentClient({ apiUrl }),
|
|
71785
72105
|
isProcessAlive,
|
|
@@ -71862,7 +72182,7 @@ async function runToken(argv, signal) {
|
|
|
71862
72182
|
);
|
|
71863
72183
|
}
|
|
71864
72184
|
const ctx = cliContext();
|
|
71865
|
-
const log = __using(_stack, openFileLog((0,
|
|
72185
|
+
const log = __using(_stack, openFileLog((0, import_node_path78.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
|
|
71866
72186
|
const result = await rotateMachineCredential(ctx, { clock: systemClock, log, signal });
|
|
71867
72187
|
process.stdout.write(`${rotationMessage(result)}
|
|
71868
72188
|
`);
|
|
@@ -71874,8 +72194,8 @@ async function runToken(argv, signal) {
|
|
|
71874
72194
|
}
|
|
71875
72195
|
|
|
71876
72196
|
// src/cli/commands/logout.ts
|
|
71877
|
-
var
|
|
71878
|
-
var
|
|
72197
|
+
var import_promises75 = require("fs/promises");
|
|
72198
|
+
var import_node_path79 = require("path");
|
|
71879
72199
|
init_runtime_v2();
|
|
71880
72200
|
var RUNTIME_EXIT_WAIT_MS = 35e3;
|
|
71881
72201
|
var TURN_END_WAIT_MS = 3e4;
|
|
@@ -71934,9 +72254,9 @@ async function stopHolder(launch, deps, outcome2) {
|
|
|
71934
72254
|
}
|
|
71935
72255
|
async function stopHeldRuns(ctx, deps, outcome2 = "aborted") {
|
|
71936
72256
|
const stopped = [];
|
|
71937
|
-
for (const name of await (0,
|
|
72257
|
+
for (const name of await (0, import_promises75.readdir)(ctx.paths.sessions).catch(() => [])) {
|
|
71938
72258
|
const launch = await readJsonFile(
|
|
71939
|
-
(0,
|
|
72259
|
+
(0, import_node_path79.join)(ctx.paths.sessions, name, "launch.json"),
|
|
71940
72260
|
holderLaunchSchema
|
|
71941
72261
|
);
|
|
71942
72262
|
if (launch.kind !== "ok") continue;
|
|
@@ -71973,13 +72293,13 @@ async function forgetMachineLocally(ctx) {
|
|
|
71973
72293
|
const machine = await readMachineFile(ctx.paths);
|
|
71974
72294
|
if (machine === null) return;
|
|
71975
72295
|
await credentialStoreFor(ctx.paths, machine.credentialStore, ctx.access).clear();
|
|
71976
|
-
await (0,
|
|
72296
|
+
await (0, import_promises75.rm)(ctx.paths.machine, { force: true });
|
|
71977
72297
|
}
|
|
71978
72298
|
async function runLogout(argv, signal) {
|
|
71979
72299
|
var _stack = [];
|
|
71980
72300
|
try {
|
|
71981
72301
|
const ctx = cliContext();
|
|
71982
|
-
const log = __using(_stack, openFileLog((0,
|
|
72302
|
+
const log = __using(_stack, openFileLog((0, import_node_path79.join)(ctx.paths.logs, "cli.jsonl"), ctx.config.logLevel, systemClock));
|
|
71983
72303
|
const result = await logoutMachine(argv, ctx, {
|
|
71984
72304
|
api: (apiUrl, accessToken) => createApiClient({ apiUrl, accessToken }),
|
|
71985
72305
|
stopHeldRuns,
|
|
@@ -71997,7 +72317,7 @@ async function runLogout(argv, signal) {
|
|
|
71997
72317
|
|
|
71998
72318
|
// src/cli/commands/run.ts
|
|
71999
72319
|
var import_node_fs24 = require("fs");
|
|
72000
|
-
var
|
|
72320
|
+
var import_node_path83 = require("path");
|
|
72001
72321
|
|
|
72002
72322
|
// src/local-api/app-attachments.ts
|
|
72003
72323
|
function createAppAttachments(clock) {
|
|
@@ -72037,7 +72357,7 @@ function createRunAppends() {
|
|
|
72037
72357
|
const pending = waiters.get(runId);
|
|
72038
72358
|
if (pending === void 0) return;
|
|
72039
72359
|
waiters.delete(runId);
|
|
72040
|
-
for (const
|
|
72360
|
+
for (const resolve14 of pending) resolve14();
|
|
72041
72361
|
};
|
|
72042
72362
|
return {
|
|
72043
72363
|
notify: wake,
|
|
@@ -72055,13 +72375,13 @@ function createRunAppends() {
|
|
|
72055
72375
|
},
|
|
72056
72376
|
nextAppend: (runId, signal) => {
|
|
72057
72377
|
if (signal.aborted) return Promise.resolve();
|
|
72058
|
-
return new Promise((
|
|
72378
|
+
return new Promise((resolve14) => {
|
|
72059
72379
|
const done = () => {
|
|
72060
72380
|
signal.removeEventListener("abort", done);
|
|
72061
72381
|
const pending2 = waiters.get(runId);
|
|
72062
72382
|
pending2?.delete(done);
|
|
72063
72383
|
if (pending2?.size === 0) waiters.delete(runId);
|
|
72064
|
-
|
|
72384
|
+
resolve14();
|
|
72065
72385
|
};
|
|
72066
72386
|
const pending = waiters.get(runId) ?? /* @__PURE__ */ new Set();
|
|
72067
72387
|
pending.add(done);
|
|
@@ -72074,9 +72394,9 @@ function createRunAppends() {
|
|
|
72074
72394
|
|
|
72075
72395
|
// src/local-api/server.ts
|
|
72076
72396
|
var import_node_crypto35 = require("crypto");
|
|
72077
|
-
var
|
|
72397
|
+
var import_promises76 = require("fs/promises");
|
|
72078
72398
|
var import_node_http4 = require("http");
|
|
72079
|
-
var
|
|
72399
|
+
var import_node_path80 = require("path");
|
|
72080
72400
|
|
|
72081
72401
|
// src/local-api/guard.ts
|
|
72082
72402
|
var import_node_crypto34 = require("crypto");
|
|
@@ -72153,11 +72473,11 @@ id: ${event.id}
|
|
|
72153
72473
|
${data}
|
|
72154
72474
|
`);
|
|
72155
72475
|
if (accepted || res.destroyed) return;
|
|
72156
|
-
await new Promise((
|
|
72476
|
+
await new Promise((resolve14) => {
|
|
72157
72477
|
const done = () => {
|
|
72158
72478
|
res.off("drain", done);
|
|
72159
72479
|
res.off("close", done);
|
|
72160
|
-
|
|
72480
|
+
resolve14();
|
|
72161
72481
|
};
|
|
72162
72482
|
res.once("drain", done);
|
|
72163
72483
|
res.once("close", done);
|
|
@@ -72385,9 +72705,9 @@ async function readChangedTurn(deps, conversationId, runId, slot) {
|
|
|
72385
72705
|
}
|
|
72386
72706
|
async function nextChangedRuns(bell, signal) {
|
|
72387
72707
|
if (bell.pending.size === 0) {
|
|
72388
|
-
await new Promise((
|
|
72389
|
-
bell.wake =
|
|
72390
|
-
if (signal.aborted || bell.pending.size > 0)
|
|
72708
|
+
await new Promise((resolve14) => {
|
|
72709
|
+
bell.wake = resolve14;
|
|
72710
|
+
if (signal.aborted || bell.pending.size > 0) resolve14();
|
|
72391
72711
|
});
|
|
72392
72712
|
bell.wake = void 0;
|
|
72393
72713
|
}
|
|
@@ -72704,9 +73024,9 @@ var streamStatus = async ({ feed, appAttachments }, { res, signal }) => {
|
|
|
72704
73024
|
latest = event;
|
|
72705
73025
|
writing = writing.then(flush);
|
|
72706
73026
|
}));
|
|
72707
|
-
await new Promise((
|
|
72708
|
-
if (signal.aborted)
|
|
72709
|
-
signal.addEventListener("abort", () =>
|
|
73027
|
+
await new Promise((resolve14) => {
|
|
73028
|
+
if (signal.aborted) resolve14();
|
|
73029
|
+
signal.addEventListener("abort", () => resolve14(), { once: true });
|
|
72710
73030
|
});
|
|
72711
73031
|
await writing;
|
|
72712
73032
|
} catch (_) {
|
|
@@ -73029,11 +73349,11 @@ function localRequestSignal(path4, closed) {
|
|
|
73029
73349
|
]);
|
|
73030
73350
|
}
|
|
73031
73351
|
async function listenOnLoopback(server) {
|
|
73032
|
-
await new Promise((
|
|
73352
|
+
await new Promise((resolve14, reject) => {
|
|
73033
73353
|
server.once("error", reject);
|
|
73034
73354
|
server.listen(0, "127.0.0.1", () => {
|
|
73035
73355
|
server.off("error", reject);
|
|
73036
|
-
|
|
73356
|
+
resolve14();
|
|
73037
73357
|
});
|
|
73038
73358
|
}).catch((error61) => {
|
|
73039
73359
|
throw new RuntimeFault("io_failed", "The local API could not listen on loopback", {
|
|
@@ -73048,7 +73368,7 @@ async function listenOnLoopback(server) {
|
|
|
73048
73368
|
}
|
|
73049
73369
|
async function closeServer(server) {
|
|
73050
73370
|
server.closeAllConnections();
|
|
73051
|
-
await new Promise((
|
|
73371
|
+
await new Promise((resolve14) => server.close(() => resolve14()));
|
|
73052
73372
|
}
|
|
73053
73373
|
async function serveLocalApi(deps) {
|
|
73054
73374
|
const limits = { ...DEFAULT_LIMITS, ...deps.limits };
|
|
@@ -73119,7 +73439,7 @@ async function serveLocalApi(deps) {
|
|
|
73119
73439
|
startedAtMs,
|
|
73120
73440
|
runtimeVersion: deps.runtimeVersion
|
|
73121
73441
|
};
|
|
73122
|
-
const discoveryPath = (0,
|
|
73442
|
+
const discoveryPath = (0, import_node_path80.join)(deps.stateDir, LOCAL_API_DISCOVERY_FILE);
|
|
73123
73443
|
await writeJsonFileAtomic(discoveryPath, discovery);
|
|
73124
73444
|
const followers = startMaintenance({
|
|
73125
73445
|
everyMs: limits.refreshEveryMs,
|
|
@@ -73153,7 +73473,7 @@ async function serveLocalApi(deps) {
|
|
|
73153
73473
|
await watchedStatus[Symbol.asyncDispose]();
|
|
73154
73474
|
const current = await readJsonFile(discoveryPath, localApiDiscoverySchema);
|
|
73155
73475
|
if (current.kind === "ok" && current.value.token === token) {
|
|
73156
|
-
await (0,
|
|
73476
|
+
await (0, import_promises76.rm)(discoveryPath, { force: true });
|
|
73157
73477
|
}
|
|
73158
73478
|
await closeServer(server);
|
|
73159
73479
|
log.info("local_api.closed", {});
|
|
@@ -73238,7 +73558,7 @@ function machineFeatureActions(deps) {
|
|
|
73238
73558
|
}
|
|
73239
73559
|
|
|
73240
73560
|
// src/cli/commands/machine-plane.ts
|
|
73241
|
-
var
|
|
73561
|
+
var import_node_path82 = require("path");
|
|
73242
73562
|
|
|
73243
73563
|
// src/link/index.ts
|
|
73244
73564
|
init_runtime_v2();
|
|
@@ -75805,9 +76125,9 @@ var Socket2 = class extends Emitter {
|
|
|
75805
76125
|
* @return a Promise that will be fulfilled when the server acknowledges the event
|
|
75806
76126
|
*/
|
|
75807
76127
|
emitWithAck(ev, ...args) {
|
|
75808
|
-
return new Promise((
|
|
76128
|
+
return new Promise((resolve14, reject) => {
|
|
75809
76129
|
const fn = (arg1, arg2) => {
|
|
75810
|
-
return arg1 ? reject(arg1) :
|
|
76130
|
+
return arg1 ? reject(arg1) : resolve14(arg2);
|
|
75811
76131
|
};
|
|
75812
76132
|
fn.withError = true;
|
|
75813
76133
|
args.push(fn);
|
|
@@ -76906,7 +77226,7 @@ function refusalFailure(refusal2) {
|
|
|
76906
77226
|
}
|
|
76907
77227
|
|
|
76908
77228
|
// src/link/probe.ts
|
|
76909
|
-
var
|
|
77229
|
+
var import_promises77 = require("dns/promises");
|
|
76910
77230
|
var import_node_net5 = require("net");
|
|
76911
77231
|
var import_node_tls2 = require("tls");
|
|
76912
77232
|
var PROBE_TIMEOUT_MS4 = 5e3;
|
|
@@ -76926,9 +77246,9 @@ async function connectOnce(url3, clock) {
|
|
|
76926
77246
|
const timer = new AbortController();
|
|
76927
77247
|
try {
|
|
76928
77248
|
return await Promise.race([
|
|
76929
|
-
new Promise((
|
|
76930
|
-
socket.once(ready, () =>
|
|
76931
|
-
socket.once("error", (error61) =>
|
|
77249
|
+
new Promise((resolve14) => {
|
|
77250
|
+
socket.once(ready, () => resolve14(null));
|
|
77251
|
+
socket.once("error", (error61) => resolve14(classifyTransportFailure(error61)));
|
|
76932
77252
|
}),
|
|
76933
77253
|
clock.sleep(PROBE_TIMEOUT_MS4, timer.signal).then(
|
|
76934
77254
|
() => "connection_timeout",
|
|
@@ -76942,7 +77262,7 @@ async function connectOnce(url3, clock) {
|
|
|
76942
77262
|
}
|
|
76943
77263
|
async function probeEndpoint(url3, clock) {
|
|
76944
77264
|
try {
|
|
76945
|
-
await (0,
|
|
77265
|
+
await (0, import_promises77.lookup)(url3.hostname);
|
|
76946
77266
|
} catch (error61) {
|
|
76947
77267
|
const reason = classifyTransportFailure(error61);
|
|
76948
77268
|
return reason === "other" ? "dns" : reason;
|
|
@@ -77391,7 +77711,7 @@ function createReconciler(host, lifecycle, log, signal) {
|
|
|
77391
77711
|
}
|
|
77392
77712
|
|
|
77393
77713
|
// src/uploader/index.ts
|
|
77394
|
-
var
|
|
77714
|
+
var import_promises78 = require("fs/promises");
|
|
77395
77715
|
init_runtime_v2();
|
|
77396
77716
|
init_zod();
|
|
77397
77717
|
var RETRY_DELAYS_MS = [250, 500, 1e3, 2e3, 5e3, 1e4, 3e4];
|
|
@@ -77539,7 +77859,7 @@ function startUploader({ api, runsDir, clock, log, archive }) {
|
|
|
77539
77859
|
};
|
|
77540
77860
|
const unsealedRunIds = async () => {
|
|
77541
77861
|
const runIds = [];
|
|
77542
|
-
for (const name of await (0,
|
|
77862
|
+
for (const name of await (0, import_promises78.readdir)(runsDir).catch(() => [])) {
|
|
77543
77863
|
const runId = runIdSchema.safeParse(name);
|
|
77544
77864
|
if (runId.success && !sealed.has(runId.data) && !archive?.has(runId.data))
|
|
77545
77865
|
runIds.push(runId.data);
|
|
@@ -77554,13 +77874,13 @@ function startUploader({ api, runsDir, clock, log, archive }) {
|
|
|
77554
77874
|
const dir = runDirectory(runsDir, runId);
|
|
77555
77875
|
const progress = await readJsonFile(dir.upload, uploadProgressSchema);
|
|
77556
77876
|
if (progress.kind !== "ok" || !progress.value.sealed) return false;
|
|
77557
|
-
const sealedAt = (await (0,
|
|
77877
|
+
const sealedAt = (await (0, import_promises78.stat)(dir.upload)).mtimeMs;
|
|
77558
77878
|
if (clock.now() - sealedAt < options.sealedForMs) return false;
|
|
77559
77879
|
return (await readLastRecord(dir.log))?.update.sessionUpdate === "_alan/run.ended";
|
|
77560
77880
|
};
|
|
77561
77881
|
const archivable = async (options) => {
|
|
77562
77882
|
const found = [];
|
|
77563
|
-
for (const name of await (0,
|
|
77883
|
+
for (const name of await (0, import_promises78.readdir)(runsDir).catch(() => [])) {
|
|
77564
77884
|
const runId = runIdSchema.safeParse(name);
|
|
77565
77885
|
if (!runId.success || archive?.has(runId.data)) continue;
|
|
77566
77886
|
try {
|
|
@@ -77761,12 +78081,12 @@ async function startMachineNativeIngest(deps) {
|
|
|
77761
78081
|
}
|
|
77762
78082
|
|
|
77763
78083
|
// src/cli/commands/run-updates.ts
|
|
77764
|
-
var
|
|
78084
|
+
var import_node_path81 = require("path");
|
|
77765
78085
|
init_runtime_v2();
|
|
77766
78086
|
var UPDATE_CHECK_EVERY_MS = 6 * 60 * 60 * 1e3;
|
|
77767
78087
|
var DEFERRED_RETRY_MS = 5 * 60 * 1e3;
|
|
77768
78088
|
function isInstalledBundle(layout, bundlePath) {
|
|
77769
|
-
return (0,
|
|
78089
|
+
return (0, import_node_path81.resolve)((0, import_node_path81.dirname)((0, import_node_path81.dirname)(bundlePath))) === (0, import_node_path81.resolve)(layout.versions);
|
|
77770
78090
|
}
|
|
77771
78091
|
async function settleUpgradeOnStart({
|
|
77772
78092
|
layout,
|
|
@@ -77873,7 +78193,7 @@ function startRuntimeUpdates(options) {
|
|
|
77873
78193
|
layout,
|
|
77874
78194
|
release: npmRelease,
|
|
77875
78195
|
tarball: await options.downloader.download(npmRelease.dist.tarball, signal),
|
|
77876
|
-
tmpDir: (0,
|
|
78196
|
+
tmpDir: (0, import_node_path81.join)(layout.root, ".downloads")
|
|
77877
78197
|
});
|
|
77878
78198
|
await lifecycle.exclusive("upgrade", async () => {
|
|
77879
78199
|
await recordPendingUpgrade(layout, currentVersion2, version2, clock.now());
|
|
@@ -78104,7 +78424,7 @@ async function startMachinePlane(deps) {
|
|
|
78104
78424
|
[ALAN_MANAGED_SESSION_ENV]: "1"
|
|
78105
78425
|
},
|
|
78106
78426
|
cwd: paths.stateDir,
|
|
78107
|
-
outputPath: (0,
|
|
78427
|
+
outputPath: (0, import_node_path82.join)(paths.logs, "holders.log")
|
|
78108
78428
|
},
|
|
78109
78429
|
deps.holderIsolation
|
|
78110
78430
|
);
|
|
@@ -78141,7 +78461,7 @@ async function startMachinePlane(deps) {
|
|
|
78141
78461
|
}),
|
|
78142
78462
|
local: { home: config2.home, machineId: identity.machineId },
|
|
78143
78463
|
// Only a cloud sandbox's runtime has a git gateway; a person's own ~/.codex is theirs.
|
|
78144
|
-
...config2.gitGatewayUrl === null ? {} : { codexSkillsDir: (0,
|
|
78464
|
+
...config2.gitGatewayUrl === null ? {} : { codexSkillsDir: (0, import_node_path82.join)(config2.codexHome, "skills") },
|
|
78145
78465
|
log
|
|
78146
78466
|
})
|
|
78147
78467
|
);
|
|
@@ -78339,7 +78659,7 @@ async function startMachinePlane(deps) {
|
|
|
78339
78659
|
git: createGitRunner({ env: cliEnvironment }),
|
|
78340
78660
|
clock,
|
|
78341
78661
|
log,
|
|
78342
|
-
dir: (0,
|
|
78662
|
+
dir: (0, import_node_path82.join)(paths.stateDir, "checkout-freshness")
|
|
78343
78663
|
},
|
|
78344
78664
|
stopped.signal
|
|
78345
78665
|
);
|
|
@@ -78601,11 +78921,11 @@ function createMachineSlot(deps) {
|
|
|
78601
78921
|
|
|
78602
78922
|
// src/cli/commands/run-exit.ts
|
|
78603
78923
|
function firstAborted(signals) {
|
|
78604
|
-
return new Promise((
|
|
78924
|
+
return new Promise((resolve14) => {
|
|
78605
78925
|
for (const reason of ["stop", "restart"]) {
|
|
78606
78926
|
const signal = signals[reason];
|
|
78607
|
-
if (signal.aborted)
|
|
78608
|
-
signal.addEventListener("abort", () =>
|
|
78927
|
+
if (signal.aborted) resolve14(reason);
|
|
78928
|
+
signal.addEventListener("abort", () => resolve14(reason), { once: true });
|
|
78609
78929
|
}
|
|
78610
78930
|
});
|
|
78611
78931
|
}
|
|
@@ -78633,7 +78953,7 @@ function lockWaitMs(argv) {
|
|
|
78633
78953
|
}
|
|
78634
78954
|
async function openManagedProviders(config2, paths) {
|
|
78635
78955
|
const providerEnv = readCliEnvironment();
|
|
78636
|
-
const bundledNpm = (0,
|
|
78956
|
+
const bundledNpm = (0, import_node_path83.join)((0, import_node_path83.dirname)(process.execPath), "npm", "bin", "npm-cli.js");
|
|
78637
78957
|
const providerToolchain = config2.providerToolchain ?? (process.platform === "win32" && (0, import_node_fs24.existsSync)(bundledNpm) ? { node: process.execPath, npmCli: bundledNpm } : null);
|
|
78638
78958
|
const npmPath = providerToolchain?.node ?? await resolveCommandOnPath("npm", providerEnv, process.platform);
|
|
78639
78959
|
const npmOptions = npmPath === null || process.platform === "win32" && providerToolchain === null ? null : {
|
|
@@ -78641,7 +78961,7 @@ async function openManagedProviders(config2, paths) {
|
|
|
78641
78961
|
...providerToolchain === null ? {} : { argsBeforeNpm: [providerToolchain.npmCli] },
|
|
78642
78962
|
env: providerEnv
|
|
78643
78963
|
};
|
|
78644
|
-
const providerNodeDir = providerToolchain?.node === void 0 ? void 0 : (0,
|
|
78964
|
+
const providerNodeDir = providerToolchain?.node === void 0 ? void 0 : (0, import_node_path83.dirname)(providerToolchain.node);
|
|
78645
78965
|
const probeEnv = providerNodeDir === void 0 ? providerEnv : {
|
|
78646
78966
|
...providerEnv,
|
|
78647
78967
|
PATH: `${providerNodeDir}${pathDelimiter(process.platform)}${envValue(providerEnv, "PATH")}`
|
|
@@ -78651,7 +78971,7 @@ async function openManagedProviders(config2, paths) {
|
|
|
78651
78971
|
throw new Error("Provider installer is unavailable on this computer");
|
|
78652
78972
|
};
|
|
78653
78973
|
const managed = createManagedProviderClis({
|
|
78654
|
-
root: (0,
|
|
78974
|
+
root: (0, import_node_path83.join)(paths.stateDir, "provider-clis"),
|
|
78655
78975
|
resolveVersion: npmOptions === null ? unavailable : createNpmVersionResolver(npmOptions),
|
|
78656
78976
|
installPackage: npmOptions === null ? unavailable : createNpmPackageInstaller(npmOptions),
|
|
78657
78977
|
probe: (executable, backendKind) => probeManagedProvider(executable, backendKind, canonicalProbeEnv)
|
|
@@ -78683,7 +79003,7 @@ async function runService(argv, stop, restart = new AbortController().signal) {
|
|
|
78683
79003
|
waitMs: lockWaitMs(argv),
|
|
78684
79004
|
signal: stop
|
|
78685
79005
|
}));
|
|
78686
|
-
const log = __using(_stack, openFileLog((0,
|
|
79006
|
+
const log = __using(_stack, openFileLog((0, import_node_path83.join)(paths.logs, "runtime.jsonl"), config2.logLevel, clock));
|
|
78687
79007
|
const lifecycle = createLifecycleQueue({ clock, log });
|
|
78688
79008
|
const install2 = installLayout(config2.installDir, config2.profile);
|
|
78689
79009
|
const bundlePath = process.argv[1] ?? "";
|
|
@@ -78717,7 +79037,7 @@ async function runService(argv, stop, restart = new AbortController().signal) {
|
|
|
78717
79037
|
openCliEnvironment({
|
|
78718
79038
|
env: readCliEnvironment(),
|
|
78719
79039
|
platform: process.platform,
|
|
78720
|
-
lastKnownGoodFile: (0,
|
|
79040
|
+
lastKnownGoodFile: (0, import_node_path83.join)(paths.stateDir, "login-path.json"),
|
|
78721
79041
|
clock,
|
|
78722
79042
|
decorate: (env) => withPackagedAlanCodeEngine(env, bundlePath, process.platform)
|
|
78723
79043
|
})
|
|
@@ -78894,17 +79214,17 @@ async function runServiceCommand(argv, ctx = cliContext()) {
|
|
|
78894
79214
|
}
|
|
78895
79215
|
|
|
78896
79216
|
// src/cli/commands/upgrade.ts
|
|
78897
|
-
var
|
|
78898
|
-
var
|
|
79217
|
+
var import_promises79 = require("fs/promises");
|
|
79218
|
+
var import_node_path84 = require("path");
|
|
78899
79219
|
function isNotNewer(version2, installed) {
|
|
78900
79220
|
return installed !== null && isReleaseVersion(version2) && isReleaseVersion(installed) && compareVersions(version2, installed) <= 0;
|
|
78901
79221
|
}
|
|
78902
79222
|
async function installFromSource(source) {
|
|
78903
79223
|
const { layout, from, ifNewer } = source;
|
|
78904
|
-
const isTarball = (await (0,
|
|
78905
|
-
const downloads = (0,
|
|
78906
|
-
if (isTarball) await (0,
|
|
78907
|
-
const scratch = isTarball ? await (0,
|
|
79224
|
+
const isTarball = (await (0, import_promises79.stat)(from)).isFile();
|
|
79225
|
+
const downloads = (0, import_node_path84.join)(layout.root, ".downloads");
|
|
79226
|
+
if (isTarball) await (0, import_promises79.mkdir)(downloads, { recursive: true, mode: 448 });
|
|
79227
|
+
const scratch = isTarball ? await (0, import_promises79.mkdtemp)((0, import_node_path84.join)(downloads, "upgrade-")) : null;
|
|
78908
79228
|
try {
|
|
78909
79229
|
const sourceDir = scratch === null ? from : await extractPackageTarball(from, scratch);
|
|
78910
79230
|
const version2 = await readPackageVersion(sourceDir);
|
|
@@ -78912,7 +79232,7 @@ async function installFromSource(source) {
|
|
|
78912
79232
|
if (ifNewer && isNotNewer(version2, installed)) return { kind: "skipped", version: version2, installed };
|
|
78913
79233
|
return { kind: "installed", ...await installVersion(layout, sourceDir) };
|
|
78914
79234
|
} finally {
|
|
78915
|
-
if (scratch !== null) await (0,
|
|
79235
|
+
if (scratch !== null) await (0, import_promises79.rm)(scratch, { recursive: true, force: true });
|
|
78916
79236
|
}
|
|
78917
79237
|
}
|
|
78918
79238
|
async function runUpgrade(argv) {
|
|
@@ -78924,7 +79244,7 @@ async function runUpgrade(argv) {
|
|
|
78924
79244
|
const layout = installLayout(config2.installDir, config2.profile);
|
|
78925
79245
|
const outcome2 = await installFromSource({
|
|
78926
79246
|
layout,
|
|
78927
|
-
from: (0,
|
|
79247
|
+
from: (0, import_node_path84.resolve)(from),
|
|
78928
79248
|
ifNewer: hasFlag(argv, "--if-newer")
|
|
78929
79249
|
});
|
|
78930
79250
|
if (outcome2.kind === "skipped") {
|