@zixt/host 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +121 -92
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,8 +12,8 @@ import { fstatSync } from "node:fs";
|
|
|
12
12
|
|
|
13
13
|
// src/supervisor.ts
|
|
14
14
|
import { spawn as spawn2 } from "node:child_process";
|
|
15
|
-
import { access as access2 } from "node:fs/promises";
|
|
16
|
-
import { join as join3 } from "node:path";
|
|
15
|
+
import { access as access2, readdir, rm } from "node:fs/promises";
|
|
16
|
+
import { join as join3, resolve as resolve2, sep } from "node:path";
|
|
17
17
|
import { homedir } from "node:os";
|
|
18
18
|
|
|
19
19
|
// src/client.ts
|
|
@@ -22,7 +22,7 @@ import WebSocket from "ws";
|
|
|
22
22
|
// package.json
|
|
23
23
|
var package_default = {
|
|
24
24
|
name: "@zixt/host",
|
|
25
|
-
version: "0.0.
|
|
25
|
+
version: "0.0.7",
|
|
26
26
|
type: "module",
|
|
27
27
|
exports: {
|
|
28
28
|
".": "./src/client.ts",
|
|
@@ -18489,7 +18489,7 @@ async function generateTaskTitle(instructions, runner) {
|
|
|
18489
18489
|
instructions.slice(0, INSTRUCTIONS_BUDGET),
|
|
18490
18490
|
"</task_request>"
|
|
18491
18491
|
].join("\n");
|
|
18492
|
-
return new Promise((
|
|
18492
|
+
return new Promise((resolve6) => {
|
|
18493
18493
|
const child = spawnCli(
|
|
18494
18494
|
command,
|
|
18495
18495
|
[
|
|
@@ -18512,7 +18512,7 @@ async function generateTaskTitle(instructions, runner) {
|
|
|
18512
18512
|
if (settled) return;
|
|
18513
18513
|
settled = true;
|
|
18514
18514
|
clearTimeout(timer);
|
|
18515
|
-
|
|
18515
|
+
resolve6(value);
|
|
18516
18516
|
};
|
|
18517
18517
|
const timer = setTimeout(() => {
|
|
18518
18518
|
child.kill();
|
|
@@ -18774,22 +18774,22 @@ var HostClient = class _HostClient {
|
|
|
18774
18774
|
const unwindingAssignments = [...this.activeAssignments.values()];
|
|
18775
18775
|
for (const cancel of this.cancels.values()) cancel(stopReason);
|
|
18776
18776
|
for (const entry of this.secretGrants.values()) {
|
|
18777
|
-
for (const
|
|
18777
|
+
for (const resolve6 of entry.resolvers) resolve6({});
|
|
18778
18778
|
entry.resolvers = [];
|
|
18779
18779
|
delete entry.value;
|
|
18780
18780
|
}
|
|
18781
18781
|
for (const entry of this.connectionGrants.values()) {
|
|
18782
|
-
for (const
|
|
18782
|
+
for (const resolve6 of entry.resolvers) resolve6([]);
|
|
18783
18783
|
entry.resolvers = [];
|
|
18784
18784
|
delete entry.value;
|
|
18785
18785
|
}
|
|
18786
18786
|
for (const entry of this.providerGrants.values()) {
|
|
18787
|
-
for (const
|
|
18787
|
+
for (const resolve6 of entry.resolvers) resolve6([]);
|
|
18788
18788
|
entry.resolvers = [];
|
|
18789
18789
|
delete entry.value;
|
|
18790
18790
|
}
|
|
18791
18791
|
for (const waiters of this.approvalWaiters.values()) {
|
|
18792
|
-
for (const
|
|
18792
|
+
for (const resolve6 of waiters.values()) resolve6({ approved: false, guidance: reason });
|
|
18793
18793
|
}
|
|
18794
18794
|
for (const waiters of this.agentOpWaiters.values()) {
|
|
18795
18795
|
for (const waiter of waiters.values()) {
|
|
@@ -19129,7 +19129,7 @@ var HostClient = class _HostClient {
|
|
|
19129
19129
|
const entry = this.secretGrants.get(key) ?? { resolvers: [] };
|
|
19130
19130
|
entry.value = message.secrets;
|
|
19131
19131
|
entry.expiresAt = expiresAt;
|
|
19132
|
-
for (const
|
|
19132
|
+
for (const resolve6 of entry.resolvers) resolve6(message.secrets);
|
|
19133
19133
|
entry.resolvers = [];
|
|
19134
19134
|
this.secretGrants.set(key, entry);
|
|
19135
19135
|
return;
|
|
@@ -19160,13 +19160,13 @@ var HostClient = class _HostClient {
|
|
|
19160
19160
|
const entry = this.connectionGrants.get(key) ?? { resolvers: [] };
|
|
19161
19161
|
entry.value = message.connections;
|
|
19162
19162
|
entry.expiresAt = expiresAt;
|
|
19163
|
-
for (const
|
|
19163
|
+
for (const resolve6 of entry.resolvers) resolve6(message.connections);
|
|
19164
19164
|
entry.resolvers = [];
|
|
19165
19165
|
this.connectionGrants.set(key, entry);
|
|
19166
19166
|
const providerEntry = this.providerGrants.get(key) ?? { resolvers: [] };
|
|
19167
19167
|
providerEntry.value = providers;
|
|
19168
19168
|
providerEntry.expiresAt = authorityExpiresAt;
|
|
19169
|
-
for (const
|
|
19169
|
+
for (const resolve6 of providerEntry.resolvers) resolve6(providers);
|
|
19170
19170
|
providerEntry.resolvers = [];
|
|
19171
19171
|
this.providerGrants.set(key, providerEntry);
|
|
19172
19172
|
return;
|
|
@@ -19245,8 +19245,8 @@ var HostClient = class _HostClient {
|
|
|
19245
19245
|
return redactCredentialText(text, sensitiveSnapshot()).slice(0, maxLength);
|
|
19246
19246
|
};
|
|
19247
19247
|
let resolveCancelled;
|
|
19248
|
-
const cancelledPromise = new Promise((
|
|
19249
|
-
resolveCancelled =
|
|
19248
|
+
const cancelledPromise = new Promise((resolve6) => {
|
|
19249
|
+
resolveCancelled = resolve6;
|
|
19250
19250
|
});
|
|
19251
19251
|
const endAuthority = (reason = "cloud_cancel") => {
|
|
19252
19252
|
if (stopReason) return;
|
|
@@ -19255,21 +19255,21 @@ var HostClient = class _HostClient {
|
|
|
19255
19255
|
authorityController.abort(reason);
|
|
19256
19256
|
const secretEntry = this.secretGrants.get(cancelKey);
|
|
19257
19257
|
if (secretEntry) {
|
|
19258
|
-
for (const
|
|
19258
|
+
for (const resolve6 of secretEntry.resolvers) resolve6({});
|
|
19259
19259
|
secretEntry.resolvers = [];
|
|
19260
19260
|
delete secretEntry.value;
|
|
19261
19261
|
}
|
|
19262
19262
|
this.secretGrants.delete(cancelKey);
|
|
19263
19263
|
const connectionEntry = this.connectionGrants.get(cancelKey);
|
|
19264
19264
|
if (connectionEntry) {
|
|
19265
|
-
for (const
|
|
19265
|
+
for (const resolve6 of connectionEntry.resolvers) resolve6([]);
|
|
19266
19266
|
connectionEntry.resolvers = [];
|
|
19267
19267
|
delete connectionEntry.value;
|
|
19268
19268
|
}
|
|
19269
19269
|
this.connectionGrants.delete(cancelKey);
|
|
19270
19270
|
const providerEntry = this.providerGrants.get(cancelKey);
|
|
19271
19271
|
if (providerEntry) {
|
|
19272
|
-
for (const
|
|
19272
|
+
for (const resolve6 of providerEntry.resolvers) resolve6([]);
|
|
19273
19273
|
providerEntry.resolvers = [];
|
|
19274
19274
|
delete providerEntry.value;
|
|
19275
19275
|
}
|
|
@@ -19277,8 +19277,8 @@ var HostClient = class _HostClient {
|
|
|
19277
19277
|
this.clearAuthorityExpiry(cancelKey);
|
|
19278
19278
|
const approvalWaiters = this.approvalWaiters.get(cancelKey);
|
|
19279
19279
|
if (approvalWaiters) {
|
|
19280
|
-
for (const
|
|
19281
|
-
|
|
19280
|
+
for (const resolve6 of approvalWaiters.values()) {
|
|
19281
|
+
resolve6({ approved: false, guidance: "task was cancelled" });
|
|
19282
19282
|
}
|
|
19283
19283
|
approvalWaiters.clear();
|
|
19284
19284
|
}
|
|
@@ -19341,9 +19341,9 @@ var HostClient = class _HostClient {
|
|
|
19341
19341
|
return value;
|
|
19342
19342
|
};
|
|
19343
19343
|
if (entry.value) return Promise.resolve(capture(entry.value));
|
|
19344
|
-
return new Promise((
|
|
19345
|
-
entry.resolvers.push((value) =>
|
|
19346
|
-
setTimeout(() =>
|
|
19344
|
+
return new Promise((resolve6) => {
|
|
19345
|
+
entry.resolvers.push((value) => resolve6(capture(value)));
|
|
19346
|
+
setTimeout(() => resolve6(capture(entry.value ?? {})), _HostClient.SECRETS_WAIT_MS);
|
|
19347
19347
|
});
|
|
19348
19348
|
};
|
|
19349
19349
|
const connections = () => {
|
|
@@ -19360,9 +19360,9 @@ var HostClient = class _HostClient {
|
|
|
19360
19360
|
return value;
|
|
19361
19361
|
};
|
|
19362
19362
|
if (entry.value) return Promise.resolve(capture(entry.value));
|
|
19363
|
-
return new Promise((
|
|
19364
|
-
entry.resolvers.push((value) =>
|
|
19365
|
-
setTimeout(() =>
|
|
19363
|
+
return new Promise((resolve6) => {
|
|
19364
|
+
entry.resolvers.push((value) => resolve6(capture(value)));
|
|
19365
|
+
setTimeout(() => resolve6(capture(entry.value ?? [])), _HostClient.SECRETS_WAIT_MS);
|
|
19366
19366
|
});
|
|
19367
19367
|
};
|
|
19368
19368
|
const providers = () => {
|
|
@@ -19379,9 +19379,9 @@ var HostClient = class _HostClient {
|
|
|
19379
19379
|
return value;
|
|
19380
19380
|
};
|
|
19381
19381
|
if (entry.value !== void 0) return Promise.resolve(capture(entry.value));
|
|
19382
|
-
return new Promise((
|
|
19383
|
-
entry.resolvers.push((value) =>
|
|
19384
|
-
setTimeout(() =>
|
|
19382
|
+
return new Promise((resolve6) => {
|
|
19383
|
+
entry.resolvers.push((value) => resolve6(capture(value)));
|
|
19384
|
+
setTimeout(() => resolve6(capture(entry.value ?? [])), _HostClient.SECRETS_WAIT_MS);
|
|
19385
19385
|
});
|
|
19386
19386
|
};
|
|
19387
19387
|
const linear = async () => {
|
|
@@ -19406,13 +19406,13 @@ var HostClient = class _HostClient {
|
|
|
19406
19406
|
summary: safe(summary, 500),
|
|
19407
19407
|
payload: safe(payload, 5e4)
|
|
19408
19408
|
});
|
|
19409
|
-
return new Promise((
|
|
19409
|
+
return new Promise((resolve6) => {
|
|
19410
19410
|
const waiters = this.approvalWaiters.get(cancelKey) ?? /* @__PURE__ */ new Map();
|
|
19411
19411
|
this.approvalWaiters.set(cancelKey, waiters);
|
|
19412
|
-
waiters.set(requestId,
|
|
19412
|
+
waiters.set(requestId, resolve6);
|
|
19413
19413
|
void cancelledPromise.then(() => {
|
|
19414
19414
|
if (waiters.delete(requestId)) {
|
|
19415
|
-
|
|
19415
|
+
resolve6({ approved: false, guidance: "task was cancelled" });
|
|
19416
19416
|
}
|
|
19417
19417
|
});
|
|
19418
19418
|
});
|
|
@@ -19450,11 +19450,11 @@ var HostClient = class _HostClient {
|
|
|
19450
19450
|
if (existing) message = existing;
|
|
19451
19451
|
else terminalMessages.set(requestId, message);
|
|
19452
19452
|
}
|
|
19453
|
-
return new Promise((
|
|
19453
|
+
return new Promise((resolve6) => {
|
|
19454
19454
|
const waiters = this.agentOpWaiters.get(cancelKey) ?? /* @__PURE__ */ new Map();
|
|
19455
19455
|
this.agentOpWaiters.set(cancelKey, waiters);
|
|
19456
19456
|
if (waiters.has(requestId)) {
|
|
19457
|
-
|
|
19457
|
+
resolve6({ ok: false, error: "provider settlement request is already in flight" });
|
|
19458
19458
|
return;
|
|
19459
19459
|
}
|
|
19460
19460
|
const timer = setTimeout(() => {
|
|
@@ -19465,7 +19465,7 @@ var HostClient = class _HostClient {
|
|
|
19465
19465
|
(pending) => !(pending.type === "agent.op" && pending.requestId === requestId)
|
|
19466
19466
|
);
|
|
19467
19467
|
}
|
|
19468
|
-
|
|
19468
|
+
resolve6({
|
|
19469
19469
|
ok: false,
|
|
19470
19470
|
error: terminal ? "The provider call completed, but Zixt could not record its outcome. Do not retry; wait for reconciliation." : "the platform did not answer in time; verify with a list_* tool before retrying a mutating call"
|
|
19471
19471
|
});
|
|
@@ -19473,7 +19473,7 @@ var HostClient = class _HostClient {
|
|
|
19473
19473
|
}, _HostClient.AGENT_OP_TIMEOUT_MS);
|
|
19474
19474
|
timer.unref?.();
|
|
19475
19475
|
waiters.set(requestId, {
|
|
19476
|
-
resolve:
|
|
19476
|
+
resolve: resolve6,
|
|
19477
19477
|
timer,
|
|
19478
19478
|
...terminal ? { terminalMessage: message } : {}
|
|
19479
19479
|
});
|
|
@@ -19517,12 +19517,12 @@ var HostClient = class _HostClient {
|
|
|
19517
19517
|
"No GitHub change was attempted; the authority grant request was invalid."
|
|
19518
19518
|
);
|
|
19519
19519
|
}
|
|
19520
|
-
const outcome = await new Promise((
|
|
19520
|
+
const outcome = await new Promise((resolve6) => {
|
|
19521
19521
|
const timer = setTimeout(() => {
|
|
19522
19522
|
const waiter = this.operationGrantWaiters.get(requestId);
|
|
19523
19523
|
if (!waiter) return;
|
|
19524
19524
|
this.operationGrantWaiters.delete(requestId);
|
|
19525
|
-
|
|
19525
|
+
resolve6({ grant: null, retryable: true, reason: "no_reply_from_zixt" });
|
|
19526
19526
|
}, this.operationGrantTimeoutMs);
|
|
19527
19527
|
timer.unref?.();
|
|
19528
19528
|
this.operationGrantWaiters.set(requestId, {
|
|
@@ -19535,16 +19535,16 @@ var HostClient = class _HostClient {
|
|
|
19535
19535
|
timer,
|
|
19536
19536
|
accept: (grant) => {
|
|
19537
19537
|
addSensitiveValues(providerGrantSensitiveValues(grant));
|
|
19538
|
-
|
|
19538
|
+
resolve6({ grant });
|
|
19539
19539
|
},
|
|
19540
|
-
deny: (retryable, reason, detail) =>
|
|
19540
|
+
deny: (retryable, reason, detail) => resolve6({ grant: null, retryable, reason, ...detail ? { detail } : {} })
|
|
19541
19541
|
});
|
|
19542
19542
|
try {
|
|
19543
19543
|
socket.send(JSON.stringify(parsed.data));
|
|
19544
19544
|
} catch {
|
|
19545
19545
|
clearTimeout(timer);
|
|
19546
19546
|
this.operationGrantWaiters.delete(requestId);
|
|
19547
|
-
|
|
19547
|
+
resolve6({ grant: null, retryable: false, reason: "connection_unavailable" });
|
|
19548
19548
|
}
|
|
19549
19549
|
});
|
|
19550
19550
|
if (outcome.grant) {
|
|
@@ -19585,7 +19585,7 @@ var HostClient = class _HostClient {
|
|
|
19585
19585
|
)
|
|
19586
19586
|
);
|
|
19587
19587
|
}
|
|
19588
|
-
return new Promise((
|
|
19588
|
+
return new Promise((resolve6, reject3) => {
|
|
19589
19589
|
const timer = setTimeout(() => {
|
|
19590
19590
|
if (this.browserCredentialWaiters.delete(requestId)) {
|
|
19591
19591
|
reject3(
|
|
@@ -19604,7 +19604,7 @@ var HostClient = class _HostClient {
|
|
|
19604
19604
|
timer,
|
|
19605
19605
|
accept: (credential) => {
|
|
19606
19606
|
addSensitiveValues(webLoginSensitiveValues(credential));
|
|
19607
|
-
|
|
19607
|
+
resolve6(credential);
|
|
19608
19608
|
},
|
|
19609
19609
|
deny: (reason) => reject3(new Error(reason))
|
|
19610
19610
|
});
|
|
@@ -19830,7 +19830,7 @@ function signalWorkerGroup(child, signal) {
|
|
|
19830
19830
|
}
|
|
19831
19831
|
}
|
|
19832
19832
|
function versionsRoot() {
|
|
19833
|
-
return join3(homedir(), ".zixt", "host-versions");
|
|
19833
|
+
return process.env.ZIXT_HOST_VERSIONS_DIR ?? join3(homedir(), ".zixt", "host-versions");
|
|
19834
19834
|
}
|
|
19835
19835
|
function npmCommand() {
|
|
19836
19836
|
return process.platform === "win32" ? "npm.cmd" : "npm";
|
|
@@ -19843,7 +19843,7 @@ async function installRelease(version2) {
|
|
|
19843
19843
|
() => false
|
|
19844
19844
|
);
|
|
19845
19845
|
if (await present()) return entry;
|
|
19846
|
-
const installed = await new Promise((
|
|
19846
|
+
const installed = await new Promise((resolve6) => {
|
|
19847
19847
|
const child = spawn2(
|
|
19848
19848
|
npmCommand(),
|
|
19849
19849
|
["install", "--prefix", prefix, "--no-audit", "--no-fund", `${PACKAGE_NAME}@${version2}`],
|
|
@@ -19851,21 +19851,44 @@ async function installRelease(version2) {
|
|
|
19851
19851
|
);
|
|
19852
19852
|
const timer = setTimeout(() => {
|
|
19853
19853
|
child.kill("SIGKILL");
|
|
19854
|
-
|
|
19854
|
+
resolve6(false);
|
|
19855
19855
|
}, INSTALL_TIMEOUT_MS);
|
|
19856
19856
|
timer.unref?.();
|
|
19857
19857
|
child.once("error", () => {
|
|
19858
19858
|
clearTimeout(timer);
|
|
19859
|
-
|
|
19859
|
+
resolve6(false);
|
|
19860
19860
|
});
|
|
19861
19861
|
child.once("exit", (code) => {
|
|
19862
19862
|
clearTimeout(timer);
|
|
19863
|
-
|
|
19863
|
+
resolve6(code === 0);
|
|
19864
19864
|
});
|
|
19865
19865
|
});
|
|
19866
19866
|
if (!installed) return null;
|
|
19867
19867
|
return await present() ? entry : null;
|
|
19868
19868
|
}
|
|
19869
|
+
var VERSION_DIR = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
19870
|
+
async function pruneInstalledVersions(keep, root = versionsRoot()) {
|
|
19871
|
+
const protectedDirs = new Set(keep);
|
|
19872
|
+
const running = process.argv[1] ? resolve2(process.argv[1]) : null;
|
|
19873
|
+
let entries;
|
|
19874
|
+
try {
|
|
19875
|
+
entries = await readdir(root);
|
|
19876
|
+
} catch {
|
|
19877
|
+
return [];
|
|
19878
|
+
}
|
|
19879
|
+
const removed = [];
|
|
19880
|
+
for (const name of entries) {
|
|
19881
|
+
if (protectedDirs.has(name) || !VERSION_DIR.test(name)) continue;
|
|
19882
|
+
const dir = join3(root, name);
|
|
19883
|
+
if (running && running.startsWith(`${dir}${sep}`)) continue;
|
|
19884
|
+
try {
|
|
19885
|
+
await rm(dir, { recursive: true, force: true });
|
|
19886
|
+
removed.push(name);
|
|
19887
|
+
} catch {
|
|
19888
|
+
}
|
|
19889
|
+
}
|
|
19890
|
+
return removed;
|
|
19891
|
+
}
|
|
19869
19892
|
function defaultSpawn(command, argv) {
|
|
19870
19893
|
return spawn2(process.execPath, [command.entry ?? process.argv[1] ?? "", ...argv], {
|
|
19871
19894
|
// stdin is a pipe this process owns: closing it is how the worker is
|
|
@@ -19886,9 +19909,10 @@ async function superviseHost(options = {}) {
|
|
|
19886
19909
|
const argv = options.argv ?? process.argv.slice(2);
|
|
19887
19910
|
const spawnWorker = options.spawnWorker ?? ((command2) => defaultSpawn(command2, argv));
|
|
19888
19911
|
const install = options.installVersion ?? installRelease;
|
|
19912
|
+
const prune = options.pruneVersions ?? ((keep) => pruneInstalledVersions(keep));
|
|
19889
19913
|
const published = options.publishedVersion ?? (() => fetchPublishedVersion(releaseSourceUrl()));
|
|
19890
19914
|
const now = options.now ?? Date.now;
|
|
19891
|
-
const delay2 = options.delay ?? ((ms) => new Promise((
|
|
19915
|
+
const delay2 = options.delay ?? ((ms) => new Promise((resolve6) => setTimeout(resolve6, ms)));
|
|
19892
19916
|
const log2 = options.log ?? ((message) => console.error(message));
|
|
19893
19917
|
const signalWorker = options.signalWorker ?? signalWorkerGroup;
|
|
19894
19918
|
let command = { entry: null, version: null };
|
|
@@ -19916,11 +19940,11 @@ async function superviseHost(options = {}) {
|
|
|
19916
19940
|
const startedAt = now();
|
|
19917
19941
|
child = spawnWorker(command);
|
|
19918
19942
|
const { code, signal } = await new Promise(
|
|
19919
|
-
(
|
|
19920
|
-
child.once("error", () =>
|
|
19943
|
+
(resolve6) => {
|
|
19944
|
+
child.once("error", () => resolve6({ code: 1, signal: null }));
|
|
19921
19945
|
child.once(
|
|
19922
19946
|
"exit",
|
|
19923
|
-
(exitCode, exitSignal) =>
|
|
19947
|
+
(exitCode, exitSignal) => resolve6({ code: exitCode, signal: exitSignal })
|
|
19924
19948
|
);
|
|
19925
19949
|
}
|
|
19926
19950
|
);
|
|
@@ -19941,6 +19965,11 @@ async function superviseHost(options = {}) {
|
|
|
19941
19965
|
const entry = await install(target);
|
|
19942
19966
|
if (entry) {
|
|
19943
19967
|
log2(`Zixt Host: updating to ${target}`);
|
|
19968
|
+
const keep = command.version === null ? [target] : [target, command.version];
|
|
19969
|
+
const removed = await prune(keep).catch(() => []);
|
|
19970
|
+
if (removed.length > 0) {
|
|
19971
|
+
log2(`Zixt Host: removed ${removed.length} old version(s): ${removed.join(", ")}`);
|
|
19972
|
+
}
|
|
19944
19973
|
command = { entry, version: target };
|
|
19945
19974
|
} else {
|
|
19946
19975
|
log2(`Zixt Host: could not install ${target}; staying on the current version`);
|
|
@@ -23566,7 +23595,7 @@ function createGithubPushOrchestrator(input) {
|
|
|
23566
23595
|
// src/tool-packs/github/git-bridge.ts
|
|
23567
23596
|
import { spawn as spawn4 } from "node:child_process";
|
|
23568
23597
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
23569
|
-
import { chmod as chmod2, lstat as lstat2, mkdir as mkdir2, realpath as realpath3, rm } from "node:fs/promises";
|
|
23598
|
+
import { chmod as chmod2, lstat as lstat2, mkdir as mkdir2, realpath as realpath3, rm as rm2 } from "node:fs/promises";
|
|
23570
23599
|
import { dirname, isAbsolute as isAbsolute4, join as join7, relative as relative2 } from "node:path";
|
|
23571
23600
|
|
|
23572
23601
|
// src/runners/process-tree.ts
|
|
@@ -23587,7 +23616,7 @@ var ProcessTreeTerminationError = class extends Error {
|
|
|
23587
23616
|
name = "ProcessTreeTerminationError";
|
|
23588
23617
|
};
|
|
23589
23618
|
function delay(ms) {
|
|
23590
|
-
return new Promise((
|
|
23619
|
+
return new Promise((resolve6) => setTimeout(resolve6, ms));
|
|
23591
23620
|
}
|
|
23592
23621
|
function processGroupAlive(pid) {
|
|
23593
23622
|
try {
|
|
@@ -23678,7 +23707,7 @@ async function snapshotWindowsDescendants(rootPid) {
|
|
|
23678
23707
|
"Windows process-tree observation could not start"
|
|
23679
23708
|
);
|
|
23680
23709
|
}
|
|
23681
|
-
return new Promise((
|
|
23710
|
+
return new Promise((resolve6, reject3) => {
|
|
23682
23711
|
let done = false;
|
|
23683
23712
|
const timeout = setTimeout(() => {
|
|
23684
23713
|
if (done) return;
|
|
@@ -23705,7 +23734,7 @@ async function snapshotWindowsDescendants(rootPid) {
|
|
|
23705
23734
|
return;
|
|
23706
23735
|
}
|
|
23707
23736
|
try {
|
|
23708
|
-
|
|
23737
|
+
resolve6(completeWindowsDescendantPids(rootPid, processes));
|
|
23709
23738
|
} catch (caught) {
|
|
23710
23739
|
reject3(caught);
|
|
23711
23740
|
}
|
|
@@ -23759,7 +23788,7 @@ async function waitForProcessesExit(pids, timeoutMs) {
|
|
|
23759
23788
|
}
|
|
23760
23789
|
async function runTaskkill(pid, command, timeoutMs = TASKKILL_TIMEOUT_MS, independentlyTrackedPids = []) {
|
|
23761
23790
|
const trustedCommand = command ?? defaultTaskkillCommand();
|
|
23762
|
-
const result = await new Promise((
|
|
23791
|
+
const result = await new Promise((resolve6, reject3) => {
|
|
23763
23792
|
const killer = spawn3(trustedCommand, ["/PID", String(pid), "/T", "/F"], {
|
|
23764
23793
|
stdio: ["ignore", "pipe", "pipe"],
|
|
23765
23794
|
windowsHide: true
|
|
@@ -23794,7 +23823,7 @@ async function runTaskkill(pid, command, timeoutMs = TASKKILL_TIMEOUT_MS, indepe
|
|
|
23794
23823
|
done = true;
|
|
23795
23824
|
clearTimeout(timeout);
|
|
23796
23825
|
if (error52) reject3(error52);
|
|
23797
|
-
else
|
|
23826
|
+
else resolve6({ code: killer.exitCode, output, outputTruncated });
|
|
23798
23827
|
};
|
|
23799
23828
|
killer.once(
|
|
23800
23829
|
"error",
|
|
@@ -24275,8 +24304,8 @@ async function runGit(input, args, env) {
|
|
|
24275
24304
|
let settled = false;
|
|
24276
24305
|
let stopping = false;
|
|
24277
24306
|
let resolveExited;
|
|
24278
|
-
const exited = new Promise((
|
|
24279
|
-
resolveExited =
|
|
24307
|
+
const exited = new Promise((resolve6) => {
|
|
24308
|
+
resolveExited = resolve6;
|
|
24280
24309
|
});
|
|
24281
24310
|
child.once("exit", resolveExited);
|
|
24282
24311
|
const cleanup = () => {
|
|
@@ -24472,7 +24501,7 @@ function createGithubGitBridge(input) {
|
|
|
24472
24501
|
const real = await requireRealDirectory(path, "git bridge");
|
|
24473
24502
|
assertBelow(current.bridges, real, "git bridge");
|
|
24474
24503
|
const hooks = join7(real, "hooks");
|
|
24475
|
-
await
|
|
24504
|
+
await rm2(hooks, { recursive: true, force: true });
|
|
24476
24505
|
await mkdir2(hooks, { mode: DIRECTORY_MODE });
|
|
24477
24506
|
await chmod2(hooks, DIRECTORY_MODE);
|
|
24478
24507
|
const config2 = join7(real, "config");
|
|
@@ -24480,7 +24509,7 @@ function createGithubGitBridge(input) {
|
|
|
24480
24509
|
active.add(real);
|
|
24481
24510
|
return real;
|
|
24482
24511
|
} catch (error52) {
|
|
24483
|
-
await
|
|
24512
|
+
await rm2(path, { recursive: true, force: true }).catch(() => {
|
|
24484
24513
|
});
|
|
24485
24514
|
throw error52;
|
|
24486
24515
|
}
|
|
@@ -24574,7 +24603,7 @@ function createGithubGitBridge(input) {
|
|
|
24574
24603
|
},
|
|
24575
24604
|
async destroyPrivateBridge(path) {
|
|
24576
24605
|
const bridge = await requireBridge(path);
|
|
24577
|
-
await
|
|
24606
|
+
await rm2(bridge, { recursive: true, force: true });
|
|
24578
24607
|
active.delete(bridge);
|
|
24579
24608
|
credentialed2.delete(bridge);
|
|
24580
24609
|
},
|
|
@@ -24582,7 +24611,7 @@ function createGithubGitBridge(input) {
|
|
|
24582
24611
|
if (closed) return;
|
|
24583
24612
|
closed = true;
|
|
24584
24613
|
const paths = [...active];
|
|
24585
|
-
await Promise.all(paths.map((path) =>
|
|
24614
|
+
await Promise.all(paths.map((path) => rm2(path, { recursive: true, force: true })));
|
|
24586
24615
|
active.clear();
|
|
24587
24616
|
credentialed2.clear();
|
|
24588
24617
|
}
|
|
@@ -24923,8 +24952,8 @@ function createRepositoryTools(runtime) {
|
|
|
24923
24952
|
|
|
24924
24953
|
// src/tool-packs/github/workspace.ts
|
|
24925
24954
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
24926
|
-
import { chmod as chmod3, lstat as lstat3, mkdir as mkdir3, readFile, realpath as realpath4, rename, rm as
|
|
24927
|
-
import { isAbsolute as isAbsolute5, join as join8, relative as relative3, resolve as
|
|
24955
|
+
import { chmod as chmod3, lstat as lstat3, mkdir as mkdir3, readFile, realpath as realpath4, rename, rm as rm3, writeFile as writeFile2 } from "node:fs/promises";
|
|
24956
|
+
import { isAbsolute as isAbsolute5, join as join8, relative as relative3, resolve as resolve3 } from "node:path";
|
|
24928
24957
|
var SAFE_LOCAL_ID = /^[A-Za-z0-9_-]{1,200}$/;
|
|
24929
24958
|
var FULL_NAME2 = /^[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100}$/;
|
|
24930
24959
|
var DIRECTORY_MODE2 = 448;
|
|
@@ -24947,7 +24976,7 @@ function assertBelow2(parent, child, label) {
|
|
|
24947
24976
|
}
|
|
24948
24977
|
}
|
|
24949
24978
|
function samePath(left, right) {
|
|
24950
|
-
return process.platform === "win32" ?
|
|
24979
|
+
return process.platform === "win32" ? resolve3(left).toLowerCase() === resolve3(right).toLowerCase() : resolve3(left) === resolve3(right);
|
|
24951
24980
|
}
|
|
24952
24981
|
async function requireRealDirectory2(path, label) {
|
|
24953
24982
|
const entry = await lstat3(path).catch(() => null);
|
|
@@ -25107,11 +25136,11 @@ async function createGithubWorkspaceService(input) {
|
|
|
25107
25136
|
try {
|
|
25108
25137
|
await rename(metadataTemporary, metadataPath);
|
|
25109
25138
|
} catch (error52) {
|
|
25110
|
-
await
|
|
25139
|
+
await rm3(destination, { recursive: true, force: true });
|
|
25111
25140
|
throw error52;
|
|
25112
25141
|
}
|
|
25113
25142
|
} finally {
|
|
25114
|
-
await
|
|
25143
|
+
await rm3(metadataTemporary, { force: true }).catch(() => {
|
|
25115
25144
|
});
|
|
25116
25145
|
}
|
|
25117
25146
|
const path = await requireRealDirectory2(destination, "GitHub repository");
|
|
@@ -25123,7 +25152,7 @@ async function createGithubWorkspaceService(input) {
|
|
|
25123
25152
|
headSha
|
|
25124
25153
|
};
|
|
25125
25154
|
} finally {
|
|
25126
|
-
await
|
|
25155
|
+
await rm3(temporary, { recursive: true, force: true }).catch(() => {
|
|
25127
25156
|
});
|
|
25128
25157
|
}
|
|
25129
25158
|
};
|
|
@@ -26764,8 +26793,8 @@ var linearToolPackFactory = {
|
|
|
26764
26793
|
async create(grant, context) {
|
|
26765
26794
|
let resolveCancelled;
|
|
26766
26795
|
let closed = false;
|
|
26767
|
-
const cancelled = new Promise((
|
|
26768
|
-
resolveCancelled =
|
|
26796
|
+
const cancelled = new Promise((resolve6) => {
|
|
26797
|
+
resolveCancelled = resolve6;
|
|
26769
26798
|
});
|
|
26770
26799
|
const cancel = () => {
|
|
26771
26800
|
if (closed) return;
|
|
@@ -27353,7 +27382,7 @@ function createAskUserServer() {
|
|
|
27353
27382
|
let server;
|
|
27354
27383
|
let listening;
|
|
27355
27384
|
function ensureListening() {
|
|
27356
|
-
listening ??= new Promise((
|
|
27385
|
+
listening ??= new Promise((resolve6, reject3) => {
|
|
27357
27386
|
server = createServer2((req, res) => {
|
|
27358
27387
|
res.on("error", () => {
|
|
27359
27388
|
});
|
|
@@ -27369,7 +27398,7 @@ function createAskUserServer() {
|
|
|
27369
27398
|
server.on("error", reject3);
|
|
27370
27399
|
server.listen(0, "127.0.0.1", () => {
|
|
27371
27400
|
const address = server.address();
|
|
27372
|
-
if (address && typeof address === "object")
|
|
27401
|
+
if (address && typeof address === "object") resolve6(address.port);
|
|
27373
27402
|
else reject3(new Error("ask_user server failed to bind"));
|
|
27374
27403
|
});
|
|
27375
27404
|
server.unref();
|
|
@@ -28282,9 +28311,9 @@ password=${credential.accessToken}
|
|
|
28282
28311
|
|
|
28283
28312
|
// src/runners/run-artifacts.ts
|
|
28284
28313
|
import { spawn as spawn5 } from "node:child_process";
|
|
28285
|
-
import { chmod as chmod5, lstat as lstat5, mkdir as mkdir6, readdir, readFile as readFile2, realpath as realpath6, rm as
|
|
28314
|
+
import { chmod as chmod5, lstat as lstat5, mkdir as mkdir6, readdir as readdir2, readFile as readFile2, realpath as realpath6, rm as rm4, writeFile as writeFile5 } from "node:fs/promises";
|
|
28286
28315
|
import { homedir as homedir3 } from "node:os";
|
|
28287
|
-
import { isAbsolute as isAbsolute8, join as join11, relative as relative5, resolve as
|
|
28316
|
+
import { isAbsolute as isAbsolute8, join as join11, relative as relative5, resolve as resolve4, win32 } from "node:path";
|
|
28288
28317
|
var SAFE_SEGMENT2 = /^[A-Za-z0-9_-]{1,200}$/;
|
|
28289
28318
|
var DIRECTORY_MODE4 = 448;
|
|
28290
28319
|
var FILE_MODE3 = 384;
|
|
@@ -28428,10 +28457,10 @@ async function rejectWindowsSymlinkAncestors(profile, target) {
|
|
|
28428
28457
|
}
|
|
28429
28458
|
}
|
|
28430
28459
|
async function prepareRoot(root) {
|
|
28431
|
-
const absolute =
|
|
28460
|
+
const absolute = resolve4(root);
|
|
28432
28461
|
let realProfile;
|
|
28433
28462
|
if (process.platform === "win32") {
|
|
28434
|
-
const profile =
|
|
28463
|
+
const profile = resolve4(homedir3());
|
|
28435
28464
|
assertWindowsProfileBoundary(profile, absolute);
|
|
28436
28465
|
await rejectWindowsSymlinkAncestors(profile, absolute);
|
|
28437
28466
|
realProfile = await realpath6(profile);
|
|
@@ -28542,7 +28571,7 @@ async function createRunArtifacts(input) {
|
|
|
28542
28571
|
requireSafeSegment(input.agentId, "agentId");
|
|
28543
28572
|
requireSafeSegment(input.runToken, "runToken");
|
|
28544
28573
|
const root = await prepareRoot(input.root);
|
|
28545
|
-
const removeTree = input.removeTree ?? ((path) =>
|
|
28574
|
+
const removeTree = input.removeTree ?? ((path) => rm4(path, { recursive: true, force: true }));
|
|
28546
28575
|
const cleanupRetryDelayMs = input.cleanupRetryDelayMs ?? CLEANUP_RETRY_DELAY_MS;
|
|
28547
28576
|
const agentRoot = await prepareAgentRoot(root, input.agentId);
|
|
28548
28577
|
await lockDownWindowsDirectories([root, agentRoot]);
|
|
@@ -28607,10 +28636,10 @@ async function removePrivateTreeWithRetries(path, removeTree, retryDelayMs) {
|
|
|
28607
28636
|
}
|
|
28608
28637
|
}
|
|
28609
28638
|
async function sweepOrphanedRunArtifacts(root) {
|
|
28610
|
-
const absolute =
|
|
28639
|
+
const absolute = resolve4(root);
|
|
28611
28640
|
let realProfile;
|
|
28612
28641
|
if (process.platform === "win32") {
|
|
28613
|
-
const profile =
|
|
28642
|
+
const profile = resolve4(homedir3());
|
|
28614
28643
|
assertWindowsProfileBoundary(profile, absolute);
|
|
28615
28644
|
await rejectWindowsSymlinkAncestors(profile, absolute);
|
|
28616
28645
|
realProfile = await realpath6(profile);
|
|
@@ -28625,17 +28654,17 @@ async function sweepOrphanedRunArtifacts(root) {
|
|
|
28625
28654
|
if (realProfile) assertWindowsProfileBoundary(realProfile, realRoot);
|
|
28626
28655
|
await chmod5(realRoot, DIRECTORY_MODE4);
|
|
28627
28656
|
await lockDownWindowsDirectories([realRoot]);
|
|
28628
|
-
const agents = await
|
|
28657
|
+
const agents = await readdir2(realRoot, { withFileTypes: true });
|
|
28629
28658
|
let removed = 0;
|
|
28630
28659
|
for (const agent of agents) {
|
|
28631
28660
|
if (!SAFE_SEGMENT2.test(agent.name) || !agent.isDirectory() || agent.isSymbolicLink()) continue;
|
|
28632
28661
|
const agentPath = join11(realRoot, agent.name);
|
|
28633
|
-
const runs = await
|
|
28662
|
+
const runs = await readdir2(agentPath, { withFileTypes: true });
|
|
28634
28663
|
for (const run2 of runs) {
|
|
28635
28664
|
if (!SAFE_SEGMENT2.test(run2.name) || !run2.isDirectory() || run2.isSymbolicLink()) continue;
|
|
28636
28665
|
const runPath = join11(agentPath, run2.name);
|
|
28637
28666
|
assertBelow3(agentPath, runPath);
|
|
28638
|
-
await
|
|
28667
|
+
await rm4(runPath, { recursive: true, force: true });
|
|
28639
28668
|
removed++;
|
|
28640
28669
|
}
|
|
28641
28670
|
}
|
|
@@ -28663,7 +28692,7 @@ async function forgetRunAssignment(runToken, registryRoot = defaultRunRegistryRo
|
|
|
28663
28692
|
if (retainingAssignments) return;
|
|
28664
28693
|
if (!SAFE_SEGMENT2.test(runToken)) return;
|
|
28665
28694
|
try {
|
|
28666
|
-
await
|
|
28695
|
+
await rm4(join11(registryRoot, `${runToken}.json`), { force: true });
|
|
28667
28696
|
} catch {
|
|
28668
28697
|
}
|
|
28669
28698
|
}
|
|
@@ -28687,7 +28716,7 @@ function parseAssignment(text) {
|
|
|
28687
28716
|
async function readRecordedRunAssignments(registryRoot = defaultRunRegistryRoot()) {
|
|
28688
28717
|
let entries;
|
|
28689
28718
|
try {
|
|
28690
|
-
entries = await
|
|
28719
|
+
entries = await readdir2(registryRoot, { withFileTypes: true });
|
|
28691
28720
|
} catch {
|
|
28692
28721
|
return [];
|
|
28693
28722
|
}
|
|
@@ -28708,7 +28737,7 @@ async function readRecordedRunAssignments(registryRoot = defaultRunRegistryRoot(
|
|
|
28708
28737
|
}
|
|
28709
28738
|
async function clearRecordedRunAssignments(registryRoot = defaultRunRegistryRoot()) {
|
|
28710
28739
|
try {
|
|
28711
|
-
await
|
|
28740
|
+
await rm4(registryRoot, { recursive: true, force: true });
|
|
28712
28741
|
} catch {
|
|
28713
28742
|
}
|
|
28714
28743
|
}
|
|
@@ -29240,7 +29269,7 @@ function runCliProcess(options) {
|
|
|
29240
29269
|
usage: { inputTokens: 0, outputTokens: 0 }
|
|
29241
29270
|
});
|
|
29242
29271
|
}
|
|
29243
|
-
return new Promise((
|
|
29272
|
+
return new Promise((resolve6) => {
|
|
29244
29273
|
const child = options.windowsWrapper ? spawn6(
|
|
29245
29274
|
options.windowsWrapper.nodeCommand,
|
|
29246
29275
|
[options.windowsWrapper.scriptPath, options.windowsWrapper.launchConfigPath],
|
|
@@ -29273,7 +29302,7 @@ function runCliProcess(options) {
|
|
|
29273
29302
|
if (settled) return;
|
|
29274
29303
|
settled = true;
|
|
29275
29304
|
clearInterval(timer);
|
|
29276
|
-
|
|
29305
|
+
resolve6(result);
|
|
29277
29306
|
};
|
|
29278
29307
|
const terminate = (result) => {
|
|
29279
29308
|
if (settled || forcedResult) return;
|
|
@@ -29876,7 +29905,7 @@ function improveCodexErrorMessage(error52) {
|
|
|
29876
29905
|
// src/runners/git-preflight.ts
|
|
29877
29906
|
import { spawn as spawn7 } from "node:child_process";
|
|
29878
29907
|
import { realpath as realpath8 } from "node:fs/promises";
|
|
29879
|
-
import { isAbsolute as isAbsolute9, resolve as
|
|
29908
|
+
import { isAbsolute as isAbsolute9, resolve as resolve5 } from "node:path";
|
|
29880
29909
|
var OUTPUT_LIMIT = 8192;
|
|
29881
29910
|
var DEFAULT_TIMEOUT_MS4 = 1e4;
|
|
29882
29911
|
var VERSION_PATTERN = /^git version [^\r\n]{1,108}$/;
|
|
@@ -29895,7 +29924,7 @@ async function preflightGit(options = {}) {
|
|
|
29895
29924
|
if (configured !== void 0 && !isAbsolute9(configured)) {
|
|
29896
29925
|
return unavailable("configured git command must be an absolute file", checkedAt);
|
|
29897
29926
|
}
|
|
29898
|
-
const trustedCwd = await realpath8(
|
|
29927
|
+
const trustedCwd = await realpath8(resolve5(options.trustedCwd ?? process.cwd())).catch(() => null);
|
|
29899
29928
|
if (!trustedCwd)
|
|
29900
29929
|
return unavailable("Host-owned git preflight directory is unavailable", checkedAt);
|
|
29901
29930
|
const executablePath = await resolveTrustedCliCommand(configured ?? "git", {
|
|
@@ -30117,7 +30146,7 @@ function parseAuth(result) {
|
|
|
30117
30146
|
return "unknown";
|
|
30118
30147
|
}
|
|
30119
30148
|
function run(command, args) {
|
|
30120
|
-
return new Promise((
|
|
30149
|
+
return new Promise((resolve6) => {
|
|
30121
30150
|
const child = spawnCli(command, args, {
|
|
30122
30151
|
stdio: ["ignore", "pipe", "pipe"],
|
|
30123
30152
|
windowsHide: true
|
|
@@ -30133,7 +30162,7 @@ function run(command, args) {
|
|
|
30133
30162
|
if (settled) return;
|
|
30134
30163
|
settled = true;
|
|
30135
30164
|
clearTimeout(timeout);
|
|
30136
|
-
|
|
30165
|
+
resolve6(result);
|
|
30137
30166
|
};
|
|
30138
30167
|
const timeout = setTimeout(() => {
|
|
30139
30168
|
child.kill();
|