@zixt/host 0.0.4 → 0.0.6
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 +129 -93
- 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.6",
|
|
26
26
|
type: "module",
|
|
27
27
|
exports: {
|
|
28
28
|
".": "./src/client.ts",
|
|
@@ -15053,6 +15053,7 @@ var ConnectionAccess = external_exports.discriminatedUnion("mode", [
|
|
|
15053
15053
|
connectionIds: external_exports.array(ConnectionId).max(MAX_CUSTOM_CONNECTION_IDS).refine((items) => new Set(items).size === items.length, "duplicate Integration")
|
|
15054
15054
|
}).strict()
|
|
15055
15055
|
]);
|
|
15056
|
+
var DEFAULT_HOST_GATEWAY_URL = "wss://api.zixt.ai/gateway";
|
|
15056
15057
|
var DEFAULT_CONNECTION_ACCESS = { mode: "all" };
|
|
15057
15058
|
var MAX_CUSTOM_MACHINE_IDS = 100;
|
|
15058
15059
|
var MachineAccess = external_exports.discriminatedUnion("mode", [
|
|
@@ -15439,7 +15440,13 @@ var HostProjection = external_exports.discriminatedUnion("telemetryRedacted", [
|
|
|
15439
15440
|
]);
|
|
15440
15441
|
var CreateHostResponse = external_exports.object({
|
|
15441
15442
|
host: AdminHostProjection,
|
|
15442
|
-
token: external_exports.string()
|
|
15443
|
+
token: external_exports.string(),
|
|
15444
|
+
/**
|
|
15445
|
+
* The gateway this deployment's Machines connect to, derived from its own
|
|
15446
|
+
* configuration. The client never guesses it from the browser's address:
|
|
15447
|
+
* the cloud that will accept the connection is the one that knows.
|
|
15448
|
+
*/
|
|
15449
|
+
gatewayUrl: external_exports.string().min(1)
|
|
15443
15450
|
});
|
|
15444
15451
|
var ListHostsResponse = external_exports.object({
|
|
15445
15452
|
hosts: external_exports.array(HostProjection)
|
|
@@ -18482,7 +18489,7 @@ async function generateTaskTitle(instructions, runner) {
|
|
|
18482
18489
|
instructions.slice(0, INSTRUCTIONS_BUDGET),
|
|
18483
18490
|
"</task_request>"
|
|
18484
18491
|
].join("\n");
|
|
18485
|
-
return new Promise((
|
|
18492
|
+
return new Promise((resolve6) => {
|
|
18486
18493
|
const child = spawnCli(
|
|
18487
18494
|
command,
|
|
18488
18495
|
[
|
|
@@ -18505,7 +18512,7 @@ async function generateTaskTitle(instructions, runner) {
|
|
|
18505
18512
|
if (settled) return;
|
|
18506
18513
|
settled = true;
|
|
18507
18514
|
clearTimeout(timer);
|
|
18508
|
-
|
|
18515
|
+
resolve6(value);
|
|
18509
18516
|
};
|
|
18510
18517
|
const timer = setTimeout(() => {
|
|
18511
18518
|
child.kill();
|
|
@@ -18767,22 +18774,22 @@ var HostClient = class _HostClient {
|
|
|
18767
18774
|
const unwindingAssignments = [...this.activeAssignments.values()];
|
|
18768
18775
|
for (const cancel of this.cancels.values()) cancel(stopReason);
|
|
18769
18776
|
for (const entry of this.secretGrants.values()) {
|
|
18770
|
-
for (const
|
|
18777
|
+
for (const resolve6 of entry.resolvers) resolve6({});
|
|
18771
18778
|
entry.resolvers = [];
|
|
18772
18779
|
delete entry.value;
|
|
18773
18780
|
}
|
|
18774
18781
|
for (const entry of this.connectionGrants.values()) {
|
|
18775
|
-
for (const
|
|
18782
|
+
for (const resolve6 of entry.resolvers) resolve6([]);
|
|
18776
18783
|
entry.resolvers = [];
|
|
18777
18784
|
delete entry.value;
|
|
18778
18785
|
}
|
|
18779
18786
|
for (const entry of this.providerGrants.values()) {
|
|
18780
|
-
for (const
|
|
18787
|
+
for (const resolve6 of entry.resolvers) resolve6([]);
|
|
18781
18788
|
entry.resolvers = [];
|
|
18782
18789
|
delete entry.value;
|
|
18783
18790
|
}
|
|
18784
18791
|
for (const waiters of this.approvalWaiters.values()) {
|
|
18785
|
-
for (const
|
|
18792
|
+
for (const resolve6 of waiters.values()) resolve6({ approved: false, guidance: reason });
|
|
18786
18793
|
}
|
|
18787
18794
|
for (const waiters of this.agentOpWaiters.values()) {
|
|
18788
18795
|
for (const waiter of waiters.values()) {
|
|
@@ -19122,7 +19129,7 @@ var HostClient = class _HostClient {
|
|
|
19122
19129
|
const entry = this.secretGrants.get(key) ?? { resolvers: [] };
|
|
19123
19130
|
entry.value = message.secrets;
|
|
19124
19131
|
entry.expiresAt = expiresAt;
|
|
19125
|
-
for (const
|
|
19132
|
+
for (const resolve6 of entry.resolvers) resolve6(message.secrets);
|
|
19126
19133
|
entry.resolvers = [];
|
|
19127
19134
|
this.secretGrants.set(key, entry);
|
|
19128
19135
|
return;
|
|
@@ -19153,13 +19160,13 @@ var HostClient = class _HostClient {
|
|
|
19153
19160
|
const entry = this.connectionGrants.get(key) ?? { resolvers: [] };
|
|
19154
19161
|
entry.value = message.connections;
|
|
19155
19162
|
entry.expiresAt = expiresAt;
|
|
19156
|
-
for (const
|
|
19163
|
+
for (const resolve6 of entry.resolvers) resolve6(message.connections);
|
|
19157
19164
|
entry.resolvers = [];
|
|
19158
19165
|
this.connectionGrants.set(key, entry);
|
|
19159
19166
|
const providerEntry = this.providerGrants.get(key) ?? { resolvers: [] };
|
|
19160
19167
|
providerEntry.value = providers;
|
|
19161
19168
|
providerEntry.expiresAt = authorityExpiresAt;
|
|
19162
|
-
for (const
|
|
19169
|
+
for (const resolve6 of providerEntry.resolvers) resolve6(providers);
|
|
19163
19170
|
providerEntry.resolvers = [];
|
|
19164
19171
|
this.providerGrants.set(key, providerEntry);
|
|
19165
19172
|
return;
|
|
@@ -19238,8 +19245,8 @@ var HostClient = class _HostClient {
|
|
|
19238
19245
|
return redactCredentialText(text, sensitiveSnapshot()).slice(0, maxLength);
|
|
19239
19246
|
};
|
|
19240
19247
|
let resolveCancelled;
|
|
19241
|
-
const cancelledPromise = new Promise((
|
|
19242
|
-
resolveCancelled =
|
|
19248
|
+
const cancelledPromise = new Promise((resolve6) => {
|
|
19249
|
+
resolveCancelled = resolve6;
|
|
19243
19250
|
});
|
|
19244
19251
|
const endAuthority = (reason = "cloud_cancel") => {
|
|
19245
19252
|
if (stopReason) return;
|
|
@@ -19248,21 +19255,21 @@ var HostClient = class _HostClient {
|
|
|
19248
19255
|
authorityController.abort(reason);
|
|
19249
19256
|
const secretEntry = this.secretGrants.get(cancelKey);
|
|
19250
19257
|
if (secretEntry) {
|
|
19251
|
-
for (const
|
|
19258
|
+
for (const resolve6 of secretEntry.resolvers) resolve6({});
|
|
19252
19259
|
secretEntry.resolvers = [];
|
|
19253
19260
|
delete secretEntry.value;
|
|
19254
19261
|
}
|
|
19255
19262
|
this.secretGrants.delete(cancelKey);
|
|
19256
19263
|
const connectionEntry = this.connectionGrants.get(cancelKey);
|
|
19257
19264
|
if (connectionEntry) {
|
|
19258
|
-
for (const
|
|
19265
|
+
for (const resolve6 of connectionEntry.resolvers) resolve6([]);
|
|
19259
19266
|
connectionEntry.resolvers = [];
|
|
19260
19267
|
delete connectionEntry.value;
|
|
19261
19268
|
}
|
|
19262
19269
|
this.connectionGrants.delete(cancelKey);
|
|
19263
19270
|
const providerEntry = this.providerGrants.get(cancelKey);
|
|
19264
19271
|
if (providerEntry) {
|
|
19265
|
-
for (const
|
|
19272
|
+
for (const resolve6 of providerEntry.resolvers) resolve6([]);
|
|
19266
19273
|
providerEntry.resolvers = [];
|
|
19267
19274
|
delete providerEntry.value;
|
|
19268
19275
|
}
|
|
@@ -19270,8 +19277,8 @@ var HostClient = class _HostClient {
|
|
|
19270
19277
|
this.clearAuthorityExpiry(cancelKey);
|
|
19271
19278
|
const approvalWaiters = this.approvalWaiters.get(cancelKey);
|
|
19272
19279
|
if (approvalWaiters) {
|
|
19273
|
-
for (const
|
|
19274
|
-
|
|
19280
|
+
for (const resolve6 of approvalWaiters.values()) {
|
|
19281
|
+
resolve6({ approved: false, guidance: "task was cancelled" });
|
|
19275
19282
|
}
|
|
19276
19283
|
approvalWaiters.clear();
|
|
19277
19284
|
}
|
|
@@ -19334,9 +19341,9 @@ var HostClient = class _HostClient {
|
|
|
19334
19341
|
return value;
|
|
19335
19342
|
};
|
|
19336
19343
|
if (entry.value) return Promise.resolve(capture(entry.value));
|
|
19337
|
-
return new Promise((
|
|
19338
|
-
entry.resolvers.push((value) =>
|
|
19339
|
-
setTimeout(() =>
|
|
19344
|
+
return new Promise((resolve6) => {
|
|
19345
|
+
entry.resolvers.push((value) => resolve6(capture(value)));
|
|
19346
|
+
setTimeout(() => resolve6(capture(entry.value ?? {})), _HostClient.SECRETS_WAIT_MS);
|
|
19340
19347
|
});
|
|
19341
19348
|
};
|
|
19342
19349
|
const connections = () => {
|
|
@@ -19353,9 +19360,9 @@ var HostClient = class _HostClient {
|
|
|
19353
19360
|
return value;
|
|
19354
19361
|
};
|
|
19355
19362
|
if (entry.value) return Promise.resolve(capture(entry.value));
|
|
19356
|
-
return new Promise((
|
|
19357
|
-
entry.resolvers.push((value) =>
|
|
19358
|
-
setTimeout(() =>
|
|
19363
|
+
return new Promise((resolve6) => {
|
|
19364
|
+
entry.resolvers.push((value) => resolve6(capture(value)));
|
|
19365
|
+
setTimeout(() => resolve6(capture(entry.value ?? [])), _HostClient.SECRETS_WAIT_MS);
|
|
19359
19366
|
});
|
|
19360
19367
|
};
|
|
19361
19368
|
const providers = () => {
|
|
@@ -19372,9 +19379,9 @@ var HostClient = class _HostClient {
|
|
|
19372
19379
|
return value;
|
|
19373
19380
|
};
|
|
19374
19381
|
if (entry.value !== void 0) return Promise.resolve(capture(entry.value));
|
|
19375
|
-
return new Promise((
|
|
19376
|
-
entry.resolvers.push((value) =>
|
|
19377
|
-
setTimeout(() =>
|
|
19382
|
+
return new Promise((resolve6) => {
|
|
19383
|
+
entry.resolvers.push((value) => resolve6(capture(value)));
|
|
19384
|
+
setTimeout(() => resolve6(capture(entry.value ?? [])), _HostClient.SECRETS_WAIT_MS);
|
|
19378
19385
|
});
|
|
19379
19386
|
};
|
|
19380
19387
|
const linear = async () => {
|
|
@@ -19399,13 +19406,13 @@ var HostClient = class _HostClient {
|
|
|
19399
19406
|
summary: safe(summary, 500),
|
|
19400
19407
|
payload: safe(payload, 5e4)
|
|
19401
19408
|
});
|
|
19402
|
-
return new Promise((
|
|
19409
|
+
return new Promise((resolve6) => {
|
|
19403
19410
|
const waiters = this.approvalWaiters.get(cancelKey) ?? /* @__PURE__ */ new Map();
|
|
19404
19411
|
this.approvalWaiters.set(cancelKey, waiters);
|
|
19405
|
-
waiters.set(requestId,
|
|
19412
|
+
waiters.set(requestId, resolve6);
|
|
19406
19413
|
void cancelledPromise.then(() => {
|
|
19407
19414
|
if (waiters.delete(requestId)) {
|
|
19408
|
-
|
|
19415
|
+
resolve6({ approved: false, guidance: "task was cancelled" });
|
|
19409
19416
|
}
|
|
19410
19417
|
});
|
|
19411
19418
|
});
|
|
@@ -19443,11 +19450,11 @@ var HostClient = class _HostClient {
|
|
|
19443
19450
|
if (existing) message = existing;
|
|
19444
19451
|
else terminalMessages.set(requestId, message);
|
|
19445
19452
|
}
|
|
19446
|
-
return new Promise((
|
|
19453
|
+
return new Promise((resolve6) => {
|
|
19447
19454
|
const waiters = this.agentOpWaiters.get(cancelKey) ?? /* @__PURE__ */ new Map();
|
|
19448
19455
|
this.agentOpWaiters.set(cancelKey, waiters);
|
|
19449
19456
|
if (waiters.has(requestId)) {
|
|
19450
|
-
|
|
19457
|
+
resolve6({ ok: false, error: "provider settlement request is already in flight" });
|
|
19451
19458
|
return;
|
|
19452
19459
|
}
|
|
19453
19460
|
const timer = setTimeout(() => {
|
|
@@ -19458,7 +19465,7 @@ var HostClient = class _HostClient {
|
|
|
19458
19465
|
(pending) => !(pending.type === "agent.op" && pending.requestId === requestId)
|
|
19459
19466
|
);
|
|
19460
19467
|
}
|
|
19461
|
-
|
|
19468
|
+
resolve6({
|
|
19462
19469
|
ok: false,
|
|
19463
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"
|
|
19464
19471
|
});
|
|
@@ -19466,7 +19473,7 @@ var HostClient = class _HostClient {
|
|
|
19466
19473
|
}, _HostClient.AGENT_OP_TIMEOUT_MS);
|
|
19467
19474
|
timer.unref?.();
|
|
19468
19475
|
waiters.set(requestId, {
|
|
19469
|
-
resolve:
|
|
19476
|
+
resolve: resolve6,
|
|
19470
19477
|
timer,
|
|
19471
19478
|
...terminal ? { terminalMessage: message } : {}
|
|
19472
19479
|
});
|
|
@@ -19510,12 +19517,12 @@ var HostClient = class _HostClient {
|
|
|
19510
19517
|
"No GitHub change was attempted; the authority grant request was invalid."
|
|
19511
19518
|
);
|
|
19512
19519
|
}
|
|
19513
|
-
const outcome = await new Promise((
|
|
19520
|
+
const outcome = await new Promise((resolve6) => {
|
|
19514
19521
|
const timer = setTimeout(() => {
|
|
19515
19522
|
const waiter = this.operationGrantWaiters.get(requestId);
|
|
19516
19523
|
if (!waiter) return;
|
|
19517
19524
|
this.operationGrantWaiters.delete(requestId);
|
|
19518
|
-
|
|
19525
|
+
resolve6({ grant: null, retryable: true, reason: "no_reply_from_zixt" });
|
|
19519
19526
|
}, this.operationGrantTimeoutMs);
|
|
19520
19527
|
timer.unref?.();
|
|
19521
19528
|
this.operationGrantWaiters.set(requestId, {
|
|
@@ -19528,16 +19535,16 @@ var HostClient = class _HostClient {
|
|
|
19528
19535
|
timer,
|
|
19529
19536
|
accept: (grant) => {
|
|
19530
19537
|
addSensitiveValues(providerGrantSensitiveValues(grant));
|
|
19531
|
-
|
|
19538
|
+
resolve6({ grant });
|
|
19532
19539
|
},
|
|
19533
|
-
deny: (retryable, reason, detail) =>
|
|
19540
|
+
deny: (retryable, reason, detail) => resolve6({ grant: null, retryable, reason, ...detail ? { detail } : {} })
|
|
19534
19541
|
});
|
|
19535
19542
|
try {
|
|
19536
19543
|
socket.send(JSON.stringify(parsed.data));
|
|
19537
19544
|
} catch {
|
|
19538
19545
|
clearTimeout(timer);
|
|
19539
19546
|
this.operationGrantWaiters.delete(requestId);
|
|
19540
|
-
|
|
19547
|
+
resolve6({ grant: null, retryable: false, reason: "connection_unavailable" });
|
|
19541
19548
|
}
|
|
19542
19549
|
});
|
|
19543
19550
|
if (outcome.grant) {
|
|
@@ -19578,7 +19585,7 @@ var HostClient = class _HostClient {
|
|
|
19578
19585
|
)
|
|
19579
19586
|
);
|
|
19580
19587
|
}
|
|
19581
|
-
return new Promise((
|
|
19588
|
+
return new Promise((resolve6, reject3) => {
|
|
19582
19589
|
const timer = setTimeout(() => {
|
|
19583
19590
|
if (this.browserCredentialWaiters.delete(requestId)) {
|
|
19584
19591
|
reject3(
|
|
@@ -19597,7 +19604,7 @@ var HostClient = class _HostClient {
|
|
|
19597
19604
|
timer,
|
|
19598
19605
|
accept: (credential) => {
|
|
19599
19606
|
addSensitiveValues(webLoginSensitiveValues(credential));
|
|
19600
|
-
|
|
19607
|
+
resolve6(credential);
|
|
19601
19608
|
},
|
|
19602
19609
|
deny: (reason) => reject3(new Error(reason))
|
|
19603
19610
|
});
|
|
@@ -19836,7 +19843,7 @@ async function installRelease(version2) {
|
|
|
19836
19843
|
() => false
|
|
19837
19844
|
);
|
|
19838
19845
|
if (await present()) return entry;
|
|
19839
|
-
const installed = await new Promise((
|
|
19846
|
+
const installed = await new Promise((resolve6) => {
|
|
19840
19847
|
const child = spawn2(
|
|
19841
19848
|
npmCommand(),
|
|
19842
19849
|
["install", "--prefix", prefix, "--no-audit", "--no-fund", `${PACKAGE_NAME}@${version2}`],
|
|
@@ -19844,21 +19851,44 @@ async function installRelease(version2) {
|
|
|
19844
19851
|
);
|
|
19845
19852
|
const timer = setTimeout(() => {
|
|
19846
19853
|
child.kill("SIGKILL");
|
|
19847
|
-
|
|
19854
|
+
resolve6(false);
|
|
19848
19855
|
}, INSTALL_TIMEOUT_MS);
|
|
19849
19856
|
timer.unref?.();
|
|
19850
19857
|
child.once("error", () => {
|
|
19851
19858
|
clearTimeout(timer);
|
|
19852
|
-
|
|
19859
|
+
resolve6(false);
|
|
19853
19860
|
});
|
|
19854
19861
|
child.once("exit", (code) => {
|
|
19855
19862
|
clearTimeout(timer);
|
|
19856
|
-
|
|
19863
|
+
resolve6(code === 0);
|
|
19857
19864
|
});
|
|
19858
19865
|
});
|
|
19859
19866
|
if (!installed) return null;
|
|
19860
19867
|
return await present() ? entry : null;
|
|
19861
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
|
+
}
|
|
19862
19892
|
function defaultSpawn(command, argv) {
|
|
19863
19893
|
return spawn2(process.execPath, [command.entry ?? process.argv[1] ?? "", ...argv], {
|
|
19864
19894
|
// stdin is a pipe this process owns: closing it is how the worker is
|
|
@@ -19879,9 +19909,10 @@ async function superviseHost(options = {}) {
|
|
|
19879
19909
|
const argv = options.argv ?? process.argv.slice(2);
|
|
19880
19910
|
const spawnWorker = options.spawnWorker ?? ((command2) => defaultSpawn(command2, argv));
|
|
19881
19911
|
const install = options.installVersion ?? installRelease;
|
|
19912
|
+
const prune = options.pruneVersions ?? ((keep) => pruneInstalledVersions(keep));
|
|
19882
19913
|
const published = options.publishedVersion ?? (() => fetchPublishedVersion(releaseSourceUrl()));
|
|
19883
19914
|
const now = options.now ?? Date.now;
|
|
19884
|
-
const delay2 = options.delay ?? ((ms) => new Promise((
|
|
19915
|
+
const delay2 = options.delay ?? ((ms) => new Promise((resolve6) => setTimeout(resolve6, ms)));
|
|
19885
19916
|
const log2 = options.log ?? ((message) => console.error(message));
|
|
19886
19917
|
const signalWorker = options.signalWorker ?? signalWorkerGroup;
|
|
19887
19918
|
let command = { entry: null, version: null };
|
|
@@ -19909,11 +19940,11 @@ async function superviseHost(options = {}) {
|
|
|
19909
19940
|
const startedAt = now();
|
|
19910
19941
|
child = spawnWorker(command);
|
|
19911
19942
|
const { code, signal } = await new Promise(
|
|
19912
|
-
(
|
|
19913
|
-
child.once("error", () =>
|
|
19943
|
+
(resolve6) => {
|
|
19944
|
+
child.once("error", () => resolve6({ code: 1, signal: null }));
|
|
19914
19945
|
child.once(
|
|
19915
19946
|
"exit",
|
|
19916
|
-
(exitCode, exitSignal) =>
|
|
19947
|
+
(exitCode, exitSignal) => resolve6({ code: exitCode, signal: exitSignal })
|
|
19917
19948
|
);
|
|
19918
19949
|
}
|
|
19919
19950
|
);
|
|
@@ -19934,6 +19965,11 @@ async function superviseHost(options = {}) {
|
|
|
19934
19965
|
const entry = await install(target);
|
|
19935
19966
|
if (entry) {
|
|
19936
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
|
+
}
|
|
19937
19973
|
command = { entry, version: target };
|
|
19938
19974
|
} else {
|
|
19939
19975
|
log2(`Zixt Host: could not install ${target}; staying on the current version`);
|
|
@@ -23559,7 +23595,7 @@ function createGithubPushOrchestrator(input) {
|
|
|
23559
23595
|
// src/tool-packs/github/git-bridge.ts
|
|
23560
23596
|
import { spawn as spawn4 } from "node:child_process";
|
|
23561
23597
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
23562
|
-
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";
|
|
23563
23599
|
import { dirname, isAbsolute as isAbsolute4, join as join7, relative as relative2 } from "node:path";
|
|
23564
23600
|
|
|
23565
23601
|
// src/runners/process-tree.ts
|
|
@@ -23580,7 +23616,7 @@ var ProcessTreeTerminationError = class extends Error {
|
|
|
23580
23616
|
name = "ProcessTreeTerminationError";
|
|
23581
23617
|
};
|
|
23582
23618
|
function delay(ms) {
|
|
23583
|
-
return new Promise((
|
|
23619
|
+
return new Promise((resolve6) => setTimeout(resolve6, ms));
|
|
23584
23620
|
}
|
|
23585
23621
|
function processGroupAlive(pid) {
|
|
23586
23622
|
try {
|
|
@@ -23671,7 +23707,7 @@ async function snapshotWindowsDescendants(rootPid) {
|
|
|
23671
23707
|
"Windows process-tree observation could not start"
|
|
23672
23708
|
);
|
|
23673
23709
|
}
|
|
23674
|
-
return new Promise((
|
|
23710
|
+
return new Promise((resolve6, reject3) => {
|
|
23675
23711
|
let done = false;
|
|
23676
23712
|
const timeout = setTimeout(() => {
|
|
23677
23713
|
if (done) return;
|
|
@@ -23698,7 +23734,7 @@ async function snapshotWindowsDescendants(rootPid) {
|
|
|
23698
23734
|
return;
|
|
23699
23735
|
}
|
|
23700
23736
|
try {
|
|
23701
|
-
|
|
23737
|
+
resolve6(completeWindowsDescendantPids(rootPid, processes));
|
|
23702
23738
|
} catch (caught) {
|
|
23703
23739
|
reject3(caught);
|
|
23704
23740
|
}
|
|
@@ -23752,7 +23788,7 @@ async function waitForProcessesExit(pids, timeoutMs) {
|
|
|
23752
23788
|
}
|
|
23753
23789
|
async function runTaskkill(pid, command, timeoutMs = TASKKILL_TIMEOUT_MS, independentlyTrackedPids = []) {
|
|
23754
23790
|
const trustedCommand = command ?? defaultTaskkillCommand();
|
|
23755
|
-
const result = await new Promise((
|
|
23791
|
+
const result = await new Promise((resolve6, reject3) => {
|
|
23756
23792
|
const killer = spawn3(trustedCommand, ["/PID", String(pid), "/T", "/F"], {
|
|
23757
23793
|
stdio: ["ignore", "pipe", "pipe"],
|
|
23758
23794
|
windowsHide: true
|
|
@@ -23787,7 +23823,7 @@ async function runTaskkill(pid, command, timeoutMs = TASKKILL_TIMEOUT_MS, indepe
|
|
|
23787
23823
|
done = true;
|
|
23788
23824
|
clearTimeout(timeout);
|
|
23789
23825
|
if (error52) reject3(error52);
|
|
23790
|
-
else
|
|
23826
|
+
else resolve6({ code: killer.exitCode, output, outputTruncated });
|
|
23791
23827
|
};
|
|
23792
23828
|
killer.once(
|
|
23793
23829
|
"error",
|
|
@@ -24268,8 +24304,8 @@ async function runGit(input, args, env) {
|
|
|
24268
24304
|
let settled = false;
|
|
24269
24305
|
let stopping = false;
|
|
24270
24306
|
let resolveExited;
|
|
24271
|
-
const exited = new Promise((
|
|
24272
|
-
resolveExited =
|
|
24307
|
+
const exited = new Promise((resolve6) => {
|
|
24308
|
+
resolveExited = resolve6;
|
|
24273
24309
|
});
|
|
24274
24310
|
child.once("exit", resolveExited);
|
|
24275
24311
|
const cleanup = () => {
|
|
@@ -24465,7 +24501,7 @@ function createGithubGitBridge(input) {
|
|
|
24465
24501
|
const real = await requireRealDirectory(path, "git bridge");
|
|
24466
24502
|
assertBelow(current.bridges, real, "git bridge");
|
|
24467
24503
|
const hooks = join7(real, "hooks");
|
|
24468
|
-
await
|
|
24504
|
+
await rm2(hooks, { recursive: true, force: true });
|
|
24469
24505
|
await mkdir2(hooks, { mode: DIRECTORY_MODE });
|
|
24470
24506
|
await chmod2(hooks, DIRECTORY_MODE);
|
|
24471
24507
|
const config2 = join7(real, "config");
|
|
@@ -24473,7 +24509,7 @@ function createGithubGitBridge(input) {
|
|
|
24473
24509
|
active.add(real);
|
|
24474
24510
|
return real;
|
|
24475
24511
|
} catch (error52) {
|
|
24476
|
-
await
|
|
24512
|
+
await rm2(path, { recursive: true, force: true }).catch(() => {
|
|
24477
24513
|
});
|
|
24478
24514
|
throw error52;
|
|
24479
24515
|
}
|
|
@@ -24567,7 +24603,7 @@ function createGithubGitBridge(input) {
|
|
|
24567
24603
|
},
|
|
24568
24604
|
async destroyPrivateBridge(path) {
|
|
24569
24605
|
const bridge = await requireBridge(path);
|
|
24570
|
-
await
|
|
24606
|
+
await rm2(bridge, { recursive: true, force: true });
|
|
24571
24607
|
active.delete(bridge);
|
|
24572
24608
|
credentialed2.delete(bridge);
|
|
24573
24609
|
},
|
|
@@ -24575,7 +24611,7 @@ function createGithubGitBridge(input) {
|
|
|
24575
24611
|
if (closed) return;
|
|
24576
24612
|
closed = true;
|
|
24577
24613
|
const paths = [...active];
|
|
24578
|
-
await Promise.all(paths.map((path) =>
|
|
24614
|
+
await Promise.all(paths.map((path) => rm2(path, { recursive: true, force: true })));
|
|
24579
24615
|
active.clear();
|
|
24580
24616
|
credentialed2.clear();
|
|
24581
24617
|
}
|
|
@@ -24916,8 +24952,8 @@ function createRepositoryTools(runtime) {
|
|
|
24916
24952
|
|
|
24917
24953
|
// src/tool-packs/github/workspace.ts
|
|
24918
24954
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
24919
|
-
import { chmod as chmod3, lstat as lstat3, mkdir as mkdir3, readFile, realpath as realpath4, rename, rm as
|
|
24920
|
-
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";
|
|
24921
24957
|
var SAFE_LOCAL_ID = /^[A-Za-z0-9_-]{1,200}$/;
|
|
24922
24958
|
var FULL_NAME2 = /^[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100}$/;
|
|
24923
24959
|
var DIRECTORY_MODE2 = 448;
|
|
@@ -24940,7 +24976,7 @@ function assertBelow2(parent, child, label) {
|
|
|
24940
24976
|
}
|
|
24941
24977
|
}
|
|
24942
24978
|
function samePath(left, right) {
|
|
24943
|
-
return process.platform === "win32" ?
|
|
24979
|
+
return process.platform === "win32" ? resolve3(left).toLowerCase() === resolve3(right).toLowerCase() : resolve3(left) === resolve3(right);
|
|
24944
24980
|
}
|
|
24945
24981
|
async function requireRealDirectory2(path, label) {
|
|
24946
24982
|
const entry = await lstat3(path).catch(() => null);
|
|
@@ -25100,11 +25136,11 @@ async function createGithubWorkspaceService(input) {
|
|
|
25100
25136
|
try {
|
|
25101
25137
|
await rename(metadataTemporary, metadataPath);
|
|
25102
25138
|
} catch (error52) {
|
|
25103
|
-
await
|
|
25139
|
+
await rm3(destination, { recursive: true, force: true });
|
|
25104
25140
|
throw error52;
|
|
25105
25141
|
}
|
|
25106
25142
|
} finally {
|
|
25107
|
-
await
|
|
25143
|
+
await rm3(metadataTemporary, { force: true }).catch(() => {
|
|
25108
25144
|
});
|
|
25109
25145
|
}
|
|
25110
25146
|
const path = await requireRealDirectory2(destination, "GitHub repository");
|
|
@@ -25116,7 +25152,7 @@ async function createGithubWorkspaceService(input) {
|
|
|
25116
25152
|
headSha
|
|
25117
25153
|
};
|
|
25118
25154
|
} finally {
|
|
25119
|
-
await
|
|
25155
|
+
await rm3(temporary, { recursive: true, force: true }).catch(() => {
|
|
25120
25156
|
});
|
|
25121
25157
|
}
|
|
25122
25158
|
};
|
|
@@ -26757,8 +26793,8 @@ var linearToolPackFactory = {
|
|
|
26757
26793
|
async create(grant, context) {
|
|
26758
26794
|
let resolveCancelled;
|
|
26759
26795
|
let closed = false;
|
|
26760
|
-
const cancelled = new Promise((
|
|
26761
|
-
resolveCancelled =
|
|
26796
|
+
const cancelled = new Promise((resolve6) => {
|
|
26797
|
+
resolveCancelled = resolve6;
|
|
26762
26798
|
});
|
|
26763
26799
|
const cancel = () => {
|
|
26764
26800
|
if (closed) return;
|
|
@@ -27346,7 +27382,7 @@ function createAskUserServer() {
|
|
|
27346
27382
|
let server;
|
|
27347
27383
|
let listening;
|
|
27348
27384
|
function ensureListening() {
|
|
27349
|
-
listening ??= new Promise((
|
|
27385
|
+
listening ??= new Promise((resolve6, reject3) => {
|
|
27350
27386
|
server = createServer2((req, res) => {
|
|
27351
27387
|
res.on("error", () => {
|
|
27352
27388
|
});
|
|
@@ -27362,7 +27398,7 @@ function createAskUserServer() {
|
|
|
27362
27398
|
server.on("error", reject3);
|
|
27363
27399
|
server.listen(0, "127.0.0.1", () => {
|
|
27364
27400
|
const address = server.address();
|
|
27365
|
-
if (address && typeof address === "object")
|
|
27401
|
+
if (address && typeof address === "object") resolve6(address.port);
|
|
27366
27402
|
else reject3(new Error("ask_user server failed to bind"));
|
|
27367
27403
|
});
|
|
27368
27404
|
server.unref();
|
|
@@ -28275,9 +28311,9 @@ password=${credential.accessToken}
|
|
|
28275
28311
|
|
|
28276
28312
|
// src/runners/run-artifacts.ts
|
|
28277
28313
|
import { spawn as spawn5 } from "node:child_process";
|
|
28278
|
-
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";
|
|
28279
28315
|
import { homedir as homedir3 } from "node:os";
|
|
28280
|
-
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";
|
|
28281
28317
|
var SAFE_SEGMENT2 = /^[A-Za-z0-9_-]{1,200}$/;
|
|
28282
28318
|
var DIRECTORY_MODE4 = 448;
|
|
28283
28319
|
var FILE_MODE3 = 384;
|
|
@@ -28421,10 +28457,10 @@ async function rejectWindowsSymlinkAncestors(profile, target) {
|
|
|
28421
28457
|
}
|
|
28422
28458
|
}
|
|
28423
28459
|
async function prepareRoot(root) {
|
|
28424
|
-
const absolute =
|
|
28460
|
+
const absolute = resolve4(root);
|
|
28425
28461
|
let realProfile;
|
|
28426
28462
|
if (process.platform === "win32") {
|
|
28427
|
-
const profile =
|
|
28463
|
+
const profile = resolve4(homedir3());
|
|
28428
28464
|
assertWindowsProfileBoundary(profile, absolute);
|
|
28429
28465
|
await rejectWindowsSymlinkAncestors(profile, absolute);
|
|
28430
28466
|
realProfile = await realpath6(profile);
|
|
@@ -28535,7 +28571,7 @@ async function createRunArtifacts(input) {
|
|
|
28535
28571
|
requireSafeSegment(input.agentId, "agentId");
|
|
28536
28572
|
requireSafeSegment(input.runToken, "runToken");
|
|
28537
28573
|
const root = await prepareRoot(input.root);
|
|
28538
|
-
const removeTree = input.removeTree ?? ((path) =>
|
|
28574
|
+
const removeTree = input.removeTree ?? ((path) => rm4(path, { recursive: true, force: true }));
|
|
28539
28575
|
const cleanupRetryDelayMs = input.cleanupRetryDelayMs ?? CLEANUP_RETRY_DELAY_MS;
|
|
28540
28576
|
const agentRoot = await prepareAgentRoot(root, input.agentId);
|
|
28541
28577
|
await lockDownWindowsDirectories([root, agentRoot]);
|
|
@@ -28600,10 +28636,10 @@ async function removePrivateTreeWithRetries(path, removeTree, retryDelayMs) {
|
|
|
28600
28636
|
}
|
|
28601
28637
|
}
|
|
28602
28638
|
async function sweepOrphanedRunArtifacts(root) {
|
|
28603
|
-
const absolute =
|
|
28639
|
+
const absolute = resolve4(root);
|
|
28604
28640
|
let realProfile;
|
|
28605
28641
|
if (process.platform === "win32") {
|
|
28606
|
-
const profile =
|
|
28642
|
+
const profile = resolve4(homedir3());
|
|
28607
28643
|
assertWindowsProfileBoundary(profile, absolute);
|
|
28608
28644
|
await rejectWindowsSymlinkAncestors(profile, absolute);
|
|
28609
28645
|
realProfile = await realpath6(profile);
|
|
@@ -28618,17 +28654,17 @@ async function sweepOrphanedRunArtifacts(root) {
|
|
|
28618
28654
|
if (realProfile) assertWindowsProfileBoundary(realProfile, realRoot);
|
|
28619
28655
|
await chmod5(realRoot, DIRECTORY_MODE4);
|
|
28620
28656
|
await lockDownWindowsDirectories([realRoot]);
|
|
28621
|
-
const agents = await
|
|
28657
|
+
const agents = await readdir2(realRoot, { withFileTypes: true });
|
|
28622
28658
|
let removed = 0;
|
|
28623
28659
|
for (const agent of agents) {
|
|
28624
28660
|
if (!SAFE_SEGMENT2.test(agent.name) || !agent.isDirectory() || agent.isSymbolicLink()) continue;
|
|
28625
28661
|
const agentPath = join11(realRoot, agent.name);
|
|
28626
|
-
const runs = await
|
|
28662
|
+
const runs = await readdir2(agentPath, { withFileTypes: true });
|
|
28627
28663
|
for (const run2 of runs) {
|
|
28628
28664
|
if (!SAFE_SEGMENT2.test(run2.name) || !run2.isDirectory() || run2.isSymbolicLink()) continue;
|
|
28629
28665
|
const runPath = join11(agentPath, run2.name);
|
|
28630
28666
|
assertBelow3(agentPath, runPath);
|
|
28631
|
-
await
|
|
28667
|
+
await rm4(runPath, { recursive: true, force: true });
|
|
28632
28668
|
removed++;
|
|
28633
28669
|
}
|
|
28634
28670
|
}
|
|
@@ -28656,7 +28692,7 @@ async function forgetRunAssignment(runToken, registryRoot = defaultRunRegistryRo
|
|
|
28656
28692
|
if (retainingAssignments) return;
|
|
28657
28693
|
if (!SAFE_SEGMENT2.test(runToken)) return;
|
|
28658
28694
|
try {
|
|
28659
|
-
await
|
|
28695
|
+
await rm4(join11(registryRoot, `${runToken}.json`), { force: true });
|
|
28660
28696
|
} catch {
|
|
28661
28697
|
}
|
|
28662
28698
|
}
|
|
@@ -28680,7 +28716,7 @@ function parseAssignment(text) {
|
|
|
28680
28716
|
async function readRecordedRunAssignments(registryRoot = defaultRunRegistryRoot()) {
|
|
28681
28717
|
let entries;
|
|
28682
28718
|
try {
|
|
28683
|
-
entries = await
|
|
28719
|
+
entries = await readdir2(registryRoot, { withFileTypes: true });
|
|
28684
28720
|
} catch {
|
|
28685
28721
|
return [];
|
|
28686
28722
|
}
|
|
@@ -28701,7 +28737,7 @@ async function readRecordedRunAssignments(registryRoot = defaultRunRegistryRoot(
|
|
|
28701
28737
|
}
|
|
28702
28738
|
async function clearRecordedRunAssignments(registryRoot = defaultRunRegistryRoot()) {
|
|
28703
28739
|
try {
|
|
28704
|
-
await
|
|
28740
|
+
await rm4(registryRoot, { recursive: true, force: true });
|
|
28705
28741
|
} catch {
|
|
28706
28742
|
}
|
|
28707
28743
|
}
|
|
@@ -29233,7 +29269,7 @@ function runCliProcess(options) {
|
|
|
29233
29269
|
usage: { inputTokens: 0, outputTokens: 0 }
|
|
29234
29270
|
});
|
|
29235
29271
|
}
|
|
29236
|
-
return new Promise((
|
|
29272
|
+
return new Promise((resolve6) => {
|
|
29237
29273
|
const child = options.windowsWrapper ? spawn6(
|
|
29238
29274
|
options.windowsWrapper.nodeCommand,
|
|
29239
29275
|
[options.windowsWrapper.scriptPath, options.windowsWrapper.launchConfigPath],
|
|
@@ -29266,7 +29302,7 @@ function runCliProcess(options) {
|
|
|
29266
29302
|
if (settled) return;
|
|
29267
29303
|
settled = true;
|
|
29268
29304
|
clearInterval(timer);
|
|
29269
|
-
|
|
29305
|
+
resolve6(result);
|
|
29270
29306
|
};
|
|
29271
29307
|
const terminate = (result) => {
|
|
29272
29308
|
if (settled || forcedResult) return;
|
|
@@ -29869,7 +29905,7 @@ function improveCodexErrorMessage(error52) {
|
|
|
29869
29905
|
// src/runners/git-preflight.ts
|
|
29870
29906
|
import { spawn as spawn7 } from "node:child_process";
|
|
29871
29907
|
import { realpath as realpath8 } from "node:fs/promises";
|
|
29872
|
-
import { isAbsolute as isAbsolute9, resolve as
|
|
29908
|
+
import { isAbsolute as isAbsolute9, resolve as resolve5 } from "node:path";
|
|
29873
29909
|
var OUTPUT_LIMIT = 8192;
|
|
29874
29910
|
var DEFAULT_TIMEOUT_MS4 = 1e4;
|
|
29875
29911
|
var VERSION_PATTERN = /^git version [^\r\n]{1,108}$/;
|
|
@@ -29888,7 +29924,7 @@ async function preflightGit(options = {}) {
|
|
|
29888
29924
|
if (configured !== void 0 && !isAbsolute9(configured)) {
|
|
29889
29925
|
return unavailable("configured git command must be an absolute file", checkedAt);
|
|
29890
29926
|
}
|
|
29891
|
-
const trustedCwd = await realpath8(
|
|
29927
|
+
const trustedCwd = await realpath8(resolve5(options.trustedCwd ?? process.cwd())).catch(() => null);
|
|
29892
29928
|
if (!trustedCwd)
|
|
29893
29929
|
return unavailable("Host-owned git preflight directory is unavailable", checkedAt);
|
|
29894
29930
|
const executablePath = await resolveTrustedCliCommand(configured ?? "git", {
|
|
@@ -30110,7 +30146,7 @@ function parseAuth(result) {
|
|
|
30110
30146
|
return "unknown";
|
|
30111
30147
|
}
|
|
30112
30148
|
function run(command, args) {
|
|
30113
|
-
return new Promise((
|
|
30149
|
+
return new Promise((resolve6) => {
|
|
30114
30150
|
const child = spawnCli(command, args, {
|
|
30115
30151
|
stdio: ["ignore", "pipe", "pipe"],
|
|
30116
30152
|
windowsHide: true
|
|
@@ -30126,7 +30162,7 @@ function run(command, args) {
|
|
|
30126
30162
|
if (settled) return;
|
|
30127
30163
|
settled = true;
|
|
30128
30164
|
clearTimeout(timeout);
|
|
30129
|
-
|
|
30165
|
+
resolve6(result);
|
|
30130
30166
|
};
|
|
30131
30167
|
const timeout = setTimeout(() => {
|
|
30132
30168
|
child.kill();
|
|
@@ -30383,7 +30419,7 @@ if (cliOptions.help) {
|
|
|
30383
30419
|
`);
|
|
30384
30420
|
process.exit(0);
|
|
30385
30421
|
}
|
|
30386
|
-
var url2 = process.env.ZIXT_CLOUD_URL ??
|
|
30422
|
+
var url2 = process.env.ZIXT_CLOUD_URL ?? DEFAULT_HOST_GATEWAY_URL;
|
|
30387
30423
|
var token = process.env.ZIXT_HOST_TOKEN;
|
|
30388
30424
|
var machine = hostname3();
|
|
30389
30425
|
if (!token) {
|