@open-artifacts/bus 0.153.1 → 0.155.0
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/assets/oa-bus.ts +1 -1
- package/assets/openclaw/index.js +8 -1
- package/assets/openclaw/package.json +1 -1
- package/dist/index.js +1186 -428
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5097,7 +5097,7 @@ var init_az = __esm({
|
|
|
5097
5097
|
});
|
|
5098
5098
|
|
|
5099
5099
|
// ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/locales/be.js
|
|
5100
|
-
function getBelarusianPlural(count,
|
|
5100
|
+
function getBelarusianPlural(count, one3, few, many) {
|
|
5101
5101
|
const absCount = Math.abs(count);
|
|
5102
5102
|
const lastDigit = absCount % 10;
|
|
5103
5103
|
const lastTwoDigits = absCount % 100;
|
|
@@ -5105,7 +5105,7 @@ function getBelarusianPlural(count, one2, few, many) {
|
|
|
5105
5105
|
return many;
|
|
5106
5106
|
}
|
|
5107
5107
|
if (lastDigit === 1) {
|
|
5108
|
-
return
|
|
5108
|
+
return one3;
|
|
5109
5109
|
}
|
|
5110
5110
|
if (lastDigit >= 2 && lastDigit <= 4) {
|
|
5111
5111
|
return few;
|
|
@@ -7871,8 +7871,8 @@ var init_hu = __esm({
|
|
|
7871
7871
|
});
|
|
7872
7872
|
|
|
7873
7873
|
// ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/locales/hy.js
|
|
7874
|
-
function getArmenianPlural(count,
|
|
7875
|
-
return Math.abs(count) === 1 ?
|
|
7874
|
+
function getArmenianPlural(count, one3, many) {
|
|
7875
|
+
return Math.abs(count) === 1 ? one3 : many;
|
|
7876
7876
|
}
|
|
7877
7877
|
function withDefiniteArticle(word) {
|
|
7878
7878
|
if (!word)
|
|
@@ -10747,7 +10747,7 @@ var init_ro = __esm({
|
|
|
10747
10747
|
});
|
|
10748
10748
|
|
|
10749
10749
|
// ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/locales/ru.js
|
|
10750
|
-
function getRussianPlural(count,
|
|
10750
|
+
function getRussianPlural(count, one3, few, many) {
|
|
10751
10751
|
const absCount = Math.abs(count);
|
|
10752
10752
|
const lastDigit = absCount % 10;
|
|
10753
10753
|
const lastTwoDigits = absCount % 100;
|
|
@@ -10755,7 +10755,7 @@ function getRussianPlural(count, one2, few, many) {
|
|
|
10755
10755
|
return many;
|
|
10756
10756
|
}
|
|
10757
10757
|
if (lastDigit === 1) {
|
|
10758
|
-
return
|
|
10758
|
+
return one3;
|
|
10759
10759
|
}
|
|
10760
10760
|
if (lastDigit >= 2 && lastDigit <= 4) {
|
|
10761
10761
|
return few;
|
|
@@ -19926,7 +19926,7 @@ function visit(schema, fnOrHandlers) {
|
|
|
19926
19926
|
return h ? h(node2, rewritten) : node2;
|
|
19927
19927
|
};
|
|
19928
19928
|
const cache = /* @__PURE__ */ new Map();
|
|
19929
|
-
function
|
|
19929
|
+
function run5(s) {
|
|
19930
19930
|
const cached2 = cache.get(s);
|
|
19931
19931
|
if (cached2 === RESOLVING) {
|
|
19932
19932
|
return new $ZodLazy({
|
|
@@ -19952,21 +19952,21 @@ function visit(schema, fnOrHandlers) {
|
|
|
19952
19952
|
let changed = false;
|
|
19953
19953
|
const newShape = {};
|
|
19954
19954
|
for (const k of keys) {
|
|
19955
|
-
const mapped =
|
|
19955
|
+
const mapped = run5(oldShape[k]);
|
|
19956
19956
|
if (mapped !== oldShape[k])
|
|
19957
19957
|
changed = true;
|
|
19958
19958
|
newShape[k] = mapped;
|
|
19959
19959
|
}
|
|
19960
19960
|
let newCatchall = def.catchall;
|
|
19961
19961
|
if (def.catchall) {
|
|
19962
|
-
newCatchall =
|
|
19962
|
+
newCatchall = run5(def.catchall);
|
|
19963
19963
|
if (newCatchall !== def.catchall)
|
|
19964
19964
|
changed = true;
|
|
19965
19965
|
}
|
|
19966
19966
|
return changed ? clone(s, { ...def, shape: newShape, catchall: newCatchall }) : s;
|
|
19967
19967
|
}
|
|
19968
19968
|
case "array": {
|
|
19969
|
-
const mapped =
|
|
19969
|
+
const mapped = run5(def.element);
|
|
19970
19970
|
return mapped === def.element ? s : clone(s, { ...def, element: mapped });
|
|
19971
19971
|
}
|
|
19972
19972
|
case "tuple": {
|
|
@@ -19974,14 +19974,14 @@ function visit(schema, fnOrHandlers) {
|
|
|
19974
19974
|
let changed = false;
|
|
19975
19975
|
const newItems = [];
|
|
19976
19976
|
for (const item of oldItems) {
|
|
19977
|
-
const mapped =
|
|
19977
|
+
const mapped = run5(item);
|
|
19978
19978
|
if (mapped !== item)
|
|
19979
19979
|
changed = true;
|
|
19980
19980
|
newItems.push(mapped);
|
|
19981
19981
|
}
|
|
19982
19982
|
let newRest = def.rest;
|
|
19983
19983
|
if (def.rest) {
|
|
19984
|
-
newRest =
|
|
19984
|
+
newRest = run5(def.rest);
|
|
19985
19985
|
if (newRest !== def.rest)
|
|
19986
19986
|
changed = true;
|
|
19987
19987
|
}
|
|
@@ -19989,12 +19989,12 @@ function visit(schema, fnOrHandlers) {
|
|
|
19989
19989
|
}
|
|
19990
19990
|
case "record":
|
|
19991
19991
|
case "map": {
|
|
19992
|
-
const newKey =
|
|
19993
|
-
const newVal =
|
|
19992
|
+
const newKey = run5(def.keyType);
|
|
19993
|
+
const newVal = run5(def.valueType);
|
|
19994
19994
|
return newKey === def.keyType && newVal === def.valueType ? s : clone(s, { ...def, keyType: newKey, valueType: newVal });
|
|
19995
19995
|
}
|
|
19996
19996
|
case "set": {
|
|
19997
|
-
const newVal =
|
|
19997
|
+
const newVal = run5(def.valueType);
|
|
19998
19998
|
return newVal === def.valueType ? s : clone(s, { ...def, valueType: newVal });
|
|
19999
19999
|
}
|
|
20000
20000
|
case "union": {
|
|
@@ -20002,7 +20002,7 @@ function visit(schema, fnOrHandlers) {
|
|
|
20002
20002
|
let changed = false;
|
|
20003
20003
|
const newOptions = [];
|
|
20004
20004
|
for (const opt of oldOptions) {
|
|
20005
|
-
const mapped =
|
|
20005
|
+
const mapped = run5(opt);
|
|
20006
20006
|
if (mapped !== opt)
|
|
20007
20007
|
changed = true;
|
|
20008
20008
|
newOptions.push(mapped);
|
|
@@ -20010,8 +20010,8 @@ function visit(schema, fnOrHandlers) {
|
|
|
20010
20010
|
return changed ? clone(s, { ...def, options: newOptions }) : s;
|
|
20011
20011
|
}
|
|
20012
20012
|
case "intersection": {
|
|
20013
|
-
const newLeft =
|
|
20014
|
-
const newRight =
|
|
20013
|
+
const newLeft = run5(def.left);
|
|
20014
|
+
const newRight = run5(def.right);
|
|
20015
20015
|
return newLeft === def.left && newRight === def.right ? s : clone(s, { ...def, left: newLeft, right: newRight });
|
|
20016
20016
|
}
|
|
20017
20017
|
case "optional":
|
|
@@ -20023,23 +20023,23 @@ function visit(schema, fnOrHandlers) {
|
|
|
20023
20023
|
case "nonoptional":
|
|
20024
20024
|
case "promise":
|
|
20025
20025
|
case "success": {
|
|
20026
|
-
const newInner =
|
|
20026
|
+
const newInner = run5(def.innerType);
|
|
20027
20027
|
return newInner === def.innerType ? s : clone(s, { ...def, innerType: newInner });
|
|
20028
20028
|
}
|
|
20029
20029
|
case "pipe": {
|
|
20030
|
-
const newIn =
|
|
20031
|
-
const newOut =
|
|
20030
|
+
const newIn = run5(def.in);
|
|
20031
|
+
const newOut = run5(def.out);
|
|
20032
20032
|
return newIn === def.in && newOut === def.out ? s : clone(s, { ...def, in: newIn, out: newOut });
|
|
20033
20033
|
}
|
|
20034
20034
|
case "function": {
|
|
20035
|
-
const newInput =
|
|
20036
|
-
const newOutput =
|
|
20035
|
+
const newInput = run5(def.input);
|
|
20036
|
+
const newOutput = run5(def.output);
|
|
20037
20037
|
return newInput === def.input && newOutput === def.output ? s : clone(s, { ...def, input: newInput, output: newOutput });
|
|
20038
20038
|
}
|
|
20039
20039
|
case "lazy": {
|
|
20040
20040
|
const original = def.getter;
|
|
20041
20041
|
const { _cachedInner, ...rest } = def;
|
|
20042
|
-
return clone(s, { ...rest, getter: () =>
|
|
20042
|
+
return clone(s, { ...rest, getter: () => run5(original()) });
|
|
20043
20043
|
}
|
|
20044
20044
|
// A leaf by choice: `parts` are regex fragments, not data positions.
|
|
20045
20045
|
case "template_literal":
|
|
@@ -20070,7 +20070,7 @@ function visit(schema, fnOrHandlers) {
|
|
|
20070
20070
|
}
|
|
20071
20071
|
}
|
|
20072
20072
|
}
|
|
20073
|
-
return
|
|
20073
|
+
return run5(schema);
|
|
20074
20074
|
}
|
|
20075
20075
|
var RESOLVING;
|
|
20076
20076
|
var init_visit = __esm({
|
|
@@ -20536,6 +20536,13 @@ var init_caps = __esm({
|
|
|
20536
20536
|
* only when the hub listed both `link` and this.
|
|
20537
20537
|
*/
|
|
20538
20538
|
linkArg: "link_arg",
|
|
20539
|
+
/**
|
|
20540
|
+
* Waiting mail (#2029): the client decodes roster `waiting` on `away` rows.
|
|
20541
|
+
* The hub sends it only to a socket whose hello listed it (with `mailbox`),
|
|
20542
|
+
* and lists it in `hello_ok.caps`: a strict decoder without it would refuse
|
|
20543
|
+
* the whole roster.
|
|
20544
|
+
*/
|
|
20545
|
+
waiting: "waiting",
|
|
20539
20546
|
/**
|
|
20540
20547
|
* Notice acks (#1752): a daemon listing it sends the existing `ack` frame
|
|
20541
20548
|
* with a notice deliver frame's `msg_id` only once the harness took the
|
|
@@ -21385,8 +21392,8 @@ var init_protocol = __esm({
|
|
|
21385
21392
|
closed: external_exports.array(AgentRefSchema).max(LIMITS.maxRosterAgents)
|
|
21386
21393
|
}).refine((f) => {
|
|
21387
21394
|
if (!distinct(f.open) || !distinct(f.closed)) return false;
|
|
21388
|
-
const
|
|
21389
|
-
return !f.closed.some((r) =>
|
|
21395
|
+
const open3 = new Set(f.open);
|
|
21396
|
+
return !f.closed.some((r) => open3.has(r));
|
|
21390
21397
|
}, "duplicate or overlapping session refs");
|
|
21391
21398
|
Send = external_exports.strictObject({
|
|
21392
21399
|
...base,
|
|
@@ -21539,6 +21546,11 @@ var init_protocol = __esm({
|
|
|
21539
21546
|
* either refuses the row, and with it the whole roster.
|
|
21540
21547
|
*/
|
|
21541
21548
|
since: IsoTimeSchema.optional(),
|
|
21549
|
+
/**
|
|
21550
|
+
* #2029: mail pending to an `away` agent, counted up to 100. Only on away
|
|
21551
|
+
* rows, which only a `BUS_CAPS.mailbox` socket sees.
|
|
21552
|
+
*/
|
|
21553
|
+
waiting: external_exports.number().int().min(1).max(100).optional(),
|
|
21542
21554
|
/** The agent's machine label. */
|
|
21543
21555
|
machine_label: MachineLabelSchema.optional(),
|
|
21544
21556
|
/** Self-reported ("agent says"); cleared on close. */
|
|
@@ -21752,7 +21764,7 @@ var init_frames = __esm({
|
|
|
21752
21764
|
late = { late: external_exports.array(external_exports.string().min(1)).optional() };
|
|
21753
21765
|
isWellFormed2 = (s) => s.isWellFormed();
|
|
21754
21766
|
WELL_FORMED = { message: "text is not well-formed unicode" };
|
|
21755
|
-
CLIENT_VERSION = true ? "0.
|
|
21767
|
+
CLIENT_VERSION = true ? "0.155.0" : "0.0.0";
|
|
21756
21768
|
clientVersion = {
|
|
21757
21769
|
client_version: external_exports.string().min(1).max(64).optional()
|
|
21758
21770
|
};
|
|
@@ -21984,6 +21996,8 @@ var init_frames = __esm({
|
|
|
21984
21996
|
state: external_exports.enum(["live", "queued", "away"]).optional(),
|
|
21985
21997
|
/** When an `away` agent closed. */
|
|
21986
21998
|
since: IsoTimeSchema.optional(),
|
|
21999
|
+
/** #2029: mail pending to an `away` agent, capped at 100. */
|
|
22000
|
+
waiting: external_exports.number().int().min(1).max(100).optional(),
|
|
21987
22001
|
global: external_exports.boolean(),
|
|
21988
22002
|
/** The agent's machine (B13); absent when the hub is older. */
|
|
21989
22003
|
machine_label: MachineLabelSchema.optional(),
|
|
@@ -22499,10 +22513,10 @@ function receiptText(r, sentTo, namespaces, excerpt, movedTo2, linkedNs) {
|
|
|
22499
22513
|
case "delivered":
|
|
22500
22514
|
return fitLine((v) => `\u2713 Delivered to ${v}.`, to);
|
|
22501
22515
|
case "expired": {
|
|
22502
|
-
const
|
|
22516
|
+
const tail2 = (v) => r.reason === "recipient_closed" ? `was not delivered because ${v} closed first.` : `was not confirmed as delivered. Mail waits at most ${RETAIN}.`;
|
|
22503
22517
|
const head = (v) => `\xD7 Expired: your message to ${v}`;
|
|
22504
|
-
if (!quote2) return fitLine((v) => `${head(v)} ${
|
|
22505
|
-
return fitLine((v) => quoted(head(v), quote2,
|
|
22518
|
+
if (!quote2) return fitLine((v) => `${head(v)} ${tail2(v)}`, to);
|
|
22519
|
+
return fitLine((v) => quoted(head(v), quote2, tail2(v)), to);
|
|
22506
22520
|
}
|
|
22507
22521
|
case "refused": {
|
|
22508
22522
|
const copy2 = r.reason ? refusals[r.reason] : void 0;
|
|
@@ -22534,10 +22548,10 @@ function movedName(to, names2) {
|
|
|
22534
22548
|
for (const name of names2) {
|
|
22535
22549
|
const l = name.toLowerCase();
|
|
22536
22550
|
if (!l.startsWith(base3)) continue;
|
|
22537
|
-
const
|
|
22538
|
-
if (!/^[0-9]+$/.test(
|
|
22539
|
-
if (Number(
|
|
22540
|
-
bestN = Number(
|
|
22551
|
+
const tail2 = l.slice(base3.length);
|
|
22552
|
+
if (!/^[0-9]+$/.test(tail2)) continue;
|
|
22553
|
+
if (Number(tail2) < bestN) {
|
|
22554
|
+
bestN = Number(tail2);
|
|
22541
22555
|
best = name;
|
|
22542
22556
|
}
|
|
22543
22557
|
}
|
|
@@ -22554,22 +22568,22 @@ function linkedLiveNamespace(name, roster2) {
|
|
|
22554
22568
|
}
|
|
22555
22569
|
function unconfirmedText(to, excerpt) {
|
|
22556
22570
|
const head = (v) => `! Unconfirmed: your message to ${v}`;
|
|
22557
|
-
const
|
|
22571
|
+
const tail2 = "may not have been delivered.";
|
|
22558
22572
|
const fixed = "\n The connection to the hub dropped while it was being sent.\n Ask the recipient whether it arrived before sending it again.";
|
|
22559
|
-
if (!excerpt) return fitLine((v) => `${head(v)} ${
|
|
22560
|
-
return fitLine((v) => `${quoted(head(v), `"${excerpt}"`,
|
|
22573
|
+
if (!excerpt) return fitLine((v) => `${head(v)} ${tail2}${fixed}`, to);
|
|
22574
|
+
return fitLine((v) => `${quoted(head(v), `"${excerpt}"`, tail2)}${fixed}`, to);
|
|
22561
22575
|
}
|
|
22562
22576
|
function correctedDeliveredText(to, excerpt) {
|
|
22563
22577
|
const head = (v) => `\u2713 Delivered after all: your message to ${v}`;
|
|
22564
|
-
const
|
|
22565
|
-
if (!excerpt) return fitLine((v) => `${head(v)} ${
|
|
22566
|
-
return fitLine((v) => quoted(head(v), `"${excerpt}"`,
|
|
22578
|
+
const tail2 = "reached it. Ignore the earlier Expired notice.";
|
|
22579
|
+
if (!excerpt) return fitLine((v) => `${head(v)} ${tail2}`, to);
|
|
22580
|
+
return fitLine((v) => quoted(head(v), `"${excerpt}"`, tail2), to);
|
|
22567
22581
|
}
|
|
22568
22582
|
function lateDeliveredText(to, excerpt) {
|
|
22569
22583
|
const head = (v) => `\u2713 Delivered: your message to ${v}`;
|
|
22570
|
-
const
|
|
22571
|
-
if (!excerpt) return fitLine((v) => `${head(v)} ${
|
|
22572
|
-
return fitLine((v) => quoted(head(v), `"${excerpt}"`,
|
|
22584
|
+
const tail2 = "was delivered after all.";
|
|
22585
|
+
if (!excerpt) return fitLine((v) => `${head(v)} ${tail2}`, to);
|
|
22586
|
+
return fitLine((v) => quoted(head(v), `"${excerpt}"`, tail2), to);
|
|
22573
22587
|
}
|
|
22574
22588
|
function cutOff(seq2) {
|
|
22575
22589
|
const bel = seq2.endsWith("\x07");
|
|
@@ -22705,15 +22719,15 @@ var init_copy = __esm({
|
|
|
22705
22719
|
"Run the oa_bus list_agents tool and message the agent you mean by name."
|
|
22706
22720
|
]
|
|
22707
22721
|
};
|
|
22708
|
-
quoted = (head, quote2,
|
|
22709
|
-
const
|
|
22710
|
-
if (
|
|
22711
|
-
${
|
|
22712
|
-
const own2 = ` ${quote2}, ${
|
|
22722
|
+
quoted = (head, quote2, tail2) => {
|
|
22723
|
+
const one3 = `${head}, ${quote2},`;
|
|
22724
|
+
if (one3.length <= MAX_COLS) return `${one3}
|
|
22725
|
+
${tail2}`;
|
|
22726
|
+
const own2 = ` ${quote2}, ${tail2}`;
|
|
22713
22727
|
return own2.length <= MAX_COLS ? `${head},
|
|
22714
22728
|
${own2}` : `${head},
|
|
22715
22729
|
${quote2},
|
|
22716
|
-
${
|
|
22730
|
+
${tail2}`;
|
|
22717
22731
|
};
|
|
22718
22732
|
TERMINAL_CONTROLS = new RegExp(
|
|
22719
22733
|
[
|
|
@@ -23015,8 +23029,8 @@ function handle(sock, opts) {
|
|
|
23015
23029
|
sock.destroy();
|
|
23016
23030
|
return;
|
|
23017
23031
|
}
|
|
23018
|
-
const
|
|
23019
|
-
if (
|
|
23032
|
+
const one3 = opts.oneRequest?.(hello) ?? false;
|
|
23033
|
+
if (one3 && served) {
|
|
23020
23034
|
send({
|
|
23021
23035
|
type: "error",
|
|
23022
23036
|
id: frame.id,
|
|
@@ -23027,7 +23041,7 @@ function handle(sock, opts) {
|
|
|
23027
23041
|
return;
|
|
23028
23042
|
}
|
|
23029
23043
|
served = true;
|
|
23030
|
-
const reply =
|
|
23044
|
+
const reply = one3 ? (f) => {
|
|
23031
23045
|
const ok = push(f);
|
|
23032
23046
|
if (f.id === frame.id) sock.end();
|
|
23033
23047
|
return ok;
|
|
@@ -23036,7 +23050,7 @@ function handle(sock, opts) {
|
|
|
23036
23050
|
const replyNow = opts.onFrame(frame, hello, reply);
|
|
23037
23051
|
if (replyNow) {
|
|
23038
23052
|
send({ ...replyNow, id: frame.id });
|
|
23039
|
-
if (
|
|
23053
|
+
if (one3) sock.end();
|
|
23040
23054
|
}
|
|
23041
23055
|
} catch (e) {
|
|
23042
23056
|
fail2(frame.id, e instanceof Error ? e.message : String(e));
|
|
@@ -26518,11 +26532,11 @@ var require_codegen = __commonJS({
|
|
|
26518
26532
|
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
26519
26533
|
return `${varKind} ${this.name}${rhs};` + _n;
|
|
26520
26534
|
}
|
|
26521
|
-
optimizeNames(names2,
|
|
26535
|
+
optimizeNames(names2, constants6) {
|
|
26522
26536
|
if (!names2[this.name.str])
|
|
26523
26537
|
return;
|
|
26524
26538
|
if (this.rhs)
|
|
26525
|
-
this.rhs = optimizeExpr(this.rhs, names2,
|
|
26539
|
+
this.rhs = optimizeExpr(this.rhs, names2, constants6);
|
|
26526
26540
|
return this;
|
|
26527
26541
|
}
|
|
26528
26542
|
get names() {
|
|
@@ -26539,10 +26553,10 @@ var require_codegen = __commonJS({
|
|
|
26539
26553
|
render({ _n }) {
|
|
26540
26554
|
return `${this.lhs} = ${this.rhs};` + _n;
|
|
26541
26555
|
}
|
|
26542
|
-
optimizeNames(names2,
|
|
26556
|
+
optimizeNames(names2, constants6) {
|
|
26543
26557
|
if (this.lhs instanceof code_1.Name && !names2[this.lhs.str] && !this.sideEffects)
|
|
26544
26558
|
return;
|
|
26545
|
-
this.rhs = optimizeExpr(this.rhs, names2,
|
|
26559
|
+
this.rhs = optimizeExpr(this.rhs, names2, constants6);
|
|
26546
26560
|
return this;
|
|
26547
26561
|
}
|
|
26548
26562
|
get names() {
|
|
@@ -26603,8 +26617,8 @@ var require_codegen = __commonJS({
|
|
|
26603
26617
|
optimizeNodes() {
|
|
26604
26618
|
return `${this.code}` ? this : void 0;
|
|
26605
26619
|
}
|
|
26606
|
-
optimizeNames(names2,
|
|
26607
|
-
this.code = optimizeExpr(this.code, names2,
|
|
26620
|
+
optimizeNames(names2, constants6) {
|
|
26621
|
+
this.code = optimizeExpr(this.code, names2, constants6);
|
|
26608
26622
|
return this;
|
|
26609
26623
|
}
|
|
26610
26624
|
get names() {
|
|
@@ -26633,12 +26647,12 @@ var require_codegen = __commonJS({
|
|
|
26633
26647
|
}
|
|
26634
26648
|
return nodes.length > 0 ? this : void 0;
|
|
26635
26649
|
}
|
|
26636
|
-
optimizeNames(names2,
|
|
26650
|
+
optimizeNames(names2, constants6) {
|
|
26637
26651
|
const { nodes } = this;
|
|
26638
26652
|
let i = nodes.length;
|
|
26639
26653
|
while (i--) {
|
|
26640
26654
|
const n = nodes[i];
|
|
26641
|
-
if (n.optimizeNames(names2,
|
|
26655
|
+
if (n.optimizeNames(names2, constants6))
|
|
26642
26656
|
continue;
|
|
26643
26657
|
subtractNames(names2, n.names);
|
|
26644
26658
|
nodes.splice(i, 1);
|
|
@@ -26691,12 +26705,12 @@ var require_codegen = __commonJS({
|
|
|
26691
26705
|
return void 0;
|
|
26692
26706
|
return this;
|
|
26693
26707
|
}
|
|
26694
|
-
optimizeNames(names2,
|
|
26708
|
+
optimizeNames(names2, constants6) {
|
|
26695
26709
|
var _a3;
|
|
26696
|
-
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2,
|
|
26697
|
-
if (!(super.optimizeNames(names2,
|
|
26710
|
+
this.else = (_a3 = this.else) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2, constants6);
|
|
26711
|
+
if (!(super.optimizeNames(names2, constants6) || this.else))
|
|
26698
26712
|
return;
|
|
26699
|
-
this.condition = optimizeExpr(this.condition, names2,
|
|
26713
|
+
this.condition = optimizeExpr(this.condition, names2, constants6);
|
|
26700
26714
|
return this;
|
|
26701
26715
|
}
|
|
26702
26716
|
get names() {
|
|
@@ -26719,10 +26733,10 @@ var require_codegen = __commonJS({
|
|
|
26719
26733
|
render(opts) {
|
|
26720
26734
|
return `for(${this.iteration})` + super.render(opts);
|
|
26721
26735
|
}
|
|
26722
|
-
optimizeNames(names2,
|
|
26723
|
-
if (!super.optimizeNames(names2,
|
|
26736
|
+
optimizeNames(names2, constants6) {
|
|
26737
|
+
if (!super.optimizeNames(names2, constants6))
|
|
26724
26738
|
return;
|
|
26725
|
-
this.iteration = optimizeExpr(this.iteration, names2,
|
|
26739
|
+
this.iteration = optimizeExpr(this.iteration, names2, constants6);
|
|
26726
26740
|
return this;
|
|
26727
26741
|
}
|
|
26728
26742
|
get names() {
|
|
@@ -26758,10 +26772,10 @@ var require_codegen = __commonJS({
|
|
|
26758
26772
|
render(opts) {
|
|
26759
26773
|
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
26760
26774
|
}
|
|
26761
|
-
optimizeNames(names2,
|
|
26762
|
-
if (!super.optimizeNames(names2,
|
|
26775
|
+
optimizeNames(names2, constants6) {
|
|
26776
|
+
if (!super.optimizeNames(names2, constants6))
|
|
26763
26777
|
return;
|
|
26764
|
-
this.iterable = optimizeExpr(this.iterable, names2,
|
|
26778
|
+
this.iterable = optimizeExpr(this.iterable, names2, constants6);
|
|
26765
26779
|
return this;
|
|
26766
26780
|
}
|
|
26767
26781
|
get names() {
|
|
@@ -26803,11 +26817,11 @@ var require_codegen = __commonJS({
|
|
|
26803
26817
|
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
|
|
26804
26818
|
return this;
|
|
26805
26819
|
}
|
|
26806
|
-
optimizeNames(names2,
|
|
26820
|
+
optimizeNames(names2, constants6) {
|
|
26807
26821
|
var _a3, _b;
|
|
26808
|
-
super.optimizeNames(names2,
|
|
26809
|
-
(_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2,
|
|
26810
|
-
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names2,
|
|
26822
|
+
super.optimizeNames(names2, constants6);
|
|
26823
|
+
(_a3 = this.catch) === null || _a3 === void 0 ? void 0 : _a3.optimizeNames(names2, constants6);
|
|
26824
|
+
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names2, constants6);
|
|
26811
26825
|
return this;
|
|
26812
26826
|
}
|
|
26813
26827
|
get names() {
|
|
@@ -27108,7 +27122,7 @@ var require_codegen = __commonJS({
|
|
|
27108
27122
|
function addExprNames(names2, from) {
|
|
27109
27123
|
return from instanceof code_1._CodeOrName ? addNames(names2, from.names) : names2;
|
|
27110
27124
|
}
|
|
27111
|
-
function optimizeExpr(expr, names2,
|
|
27125
|
+
function optimizeExpr(expr, names2, constants6) {
|
|
27112
27126
|
if (expr instanceof code_1.Name)
|
|
27113
27127
|
return replaceName(expr);
|
|
27114
27128
|
if (!canOptimize(expr))
|
|
@@ -27123,14 +27137,14 @@ var require_codegen = __commonJS({
|
|
|
27123
27137
|
return items;
|
|
27124
27138
|
}, []));
|
|
27125
27139
|
function replaceName(n) {
|
|
27126
|
-
const c =
|
|
27140
|
+
const c = constants6[n.str];
|
|
27127
27141
|
if (c === void 0 || names2[n.str] !== 1)
|
|
27128
27142
|
return n;
|
|
27129
27143
|
delete names2[n.str];
|
|
27130
27144
|
return c;
|
|
27131
27145
|
}
|
|
27132
27146
|
function canOptimize(e) {
|
|
27133
|
-
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names2[c.str] === 1 &&
|
|
27147
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names2[c.str] === 1 && constants6[c.str] !== void 0);
|
|
27134
27148
|
}
|
|
27135
27149
|
}
|
|
27136
27150
|
function subtractNames(names2, from) {
|
|
@@ -29299,8 +29313,8 @@ var require_utils = __commonJS({
|
|
|
29299
29313
|
}
|
|
29300
29314
|
if (bestLength < 2) return hextets.join(":");
|
|
29301
29315
|
const head = hextets.slice(0, bestStart).join(":");
|
|
29302
|
-
const
|
|
29303
|
-
return head + "::" +
|
|
29316
|
+
const tail2 = hextets.slice(bestStart + bestLength).join(":");
|
|
29317
|
+
return head + "::" + tail2;
|
|
29304
29318
|
}
|
|
29305
29319
|
function normalizeIPv6Address(input2) {
|
|
29306
29320
|
const compression = input2.indexOf("::");
|
|
@@ -34655,7 +34669,7 @@ function parseAnswer(text3, sse) {
|
|
|
34655
34669
|
}
|
|
34656
34670
|
return void 0;
|
|
34657
34671
|
}
|
|
34658
|
-
async function within(ms,
|
|
34672
|
+
async function within(ms, open3) {
|
|
34659
34673
|
const st = {};
|
|
34660
34674
|
let timer;
|
|
34661
34675
|
const cap = new Promise((res) => {
|
|
@@ -34667,7 +34681,7 @@ async function within(ms, open2) {
|
|
|
34667
34681
|
timer.unref?.();
|
|
34668
34682
|
});
|
|
34669
34683
|
try {
|
|
34670
|
-
return await Promise.race([
|
|
34684
|
+
return await Promise.race([open3(st), cap]);
|
|
34671
34685
|
} finally {
|
|
34672
34686
|
clearTimeout(timer);
|
|
34673
34687
|
}
|
|
@@ -35339,9 +35353,9 @@ var require_permessage_deflate = __commonJS({
|
|
|
35339
35353
|
* @private
|
|
35340
35354
|
*/
|
|
35341
35355
|
_decompress(data, fin, callback) {
|
|
35342
|
-
const
|
|
35356
|
+
const endpoint2 = this._isServer ? "client" : "server";
|
|
35343
35357
|
if (!this._inflate) {
|
|
35344
|
-
const key2 = `${
|
|
35358
|
+
const key2 = `${endpoint2}_max_window_bits`;
|
|
35345
35359
|
const windowBits = typeof this.params[key2] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key2];
|
|
35346
35360
|
this._inflate = zlib.createInflateRaw({
|
|
35347
35361
|
...this._options.zlibInflateOptions,
|
|
@@ -35374,7 +35388,7 @@ var require_permessage_deflate = __commonJS({
|
|
|
35374
35388
|
} else {
|
|
35375
35389
|
this._inflate[kTotalLength] = 0;
|
|
35376
35390
|
this._inflate[kBuffers] = [];
|
|
35377
|
-
if (fin && this.params[`${
|
|
35391
|
+
if (fin && this.params[`${endpoint2}_no_context_takeover`]) {
|
|
35378
35392
|
this._inflate.reset();
|
|
35379
35393
|
}
|
|
35380
35394
|
}
|
|
@@ -35390,9 +35404,9 @@ var require_permessage_deflate = __commonJS({
|
|
|
35390
35404
|
* @private
|
|
35391
35405
|
*/
|
|
35392
35406
|
_compress(data, fin, callback) {
|
|
35393
|
-
const
|
|
35407
|
+
const endpoint2 = this._isServer ? "server" : "client";
|
|
35394
35408
|
if (!this._deflate) {
|
|
35395
|
-
const key2 = `${
|
|
35409
|
+
const key2 = `${endpoint2}_max_window_bits`;
|
|
35396
35410
|
const windowBits = typeof this.params[key2] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key2];
|
|
35397
35411
|
this._deflate = zlib.createDeflateRaw({
|
|
35398
35412
|
...this._options.zlibDeflateOptions,
|
|
@@ -35418,7 +35432,7 @@ var require_permessage_deflate = __commonJS({
|
|
|
35418
35432
|
this._deflate[kCallback] = null;
|
|
35419
35433
|
this._deflate[kTotalLength] = 0;
|
|
35420
35434
|
this._deflate[kBuffers] = [];
|
|
35421
|
-
if (fin && this.params[`${
|
|
35435
|
+
if (fin && this.params[`${endpoint2}_no_context_takeover`]) {
|
|
35422
35436
|
this._deflate.reset();
|
|
35423
35437
|
}
|
|
35424
35438
|
callback(null, data2);
|
|
@@ -38120,7 +38134,7 @@ var require_stream = __commonJS({
|
|
|
38120
38134
|
};
|
|
38121
38135
|
duplex._final = function(callback) {
|
|
38122
38136
|
if (ws.readyState === ws.CONNECTING) {
|
|
38123
|
-
ws.once("open", function
|
|
38137
|
+
ws.once("open", function open3() {
|
|
38124
38138
|
duplex._final(callback);
|
|
38125
38139
|
});
|
|
38126
38140
|
return;
|
|
@@ -38141,7 +38155,7 @@ var require_stream = __commonJS({
|
|
|
38141
38155
|
};
|
|
38142
38156
|
duplex._write = function(chunk, encoding, callback) {
|
|
38143
38157
|
if (ws.readyState === ws.CONNECTING) {
|
|
38144
|
-
ws.once("open", function
|
|
38158
|
+
ws.once("open", function open3() {
|
|
38145
38159
|
duplex._write(chunk, encoding, callback);
|
|
38146
38160
|
});
|
|
38147
38161
|
return;
|
|
@@ -38817,16 +38831,16 @@ async function rootSession(sessionId, deps2) {
|
|
|
38817
38831
|
cur = parent;
|
|
38818
38832
|
}
|
|
38819
38833
|
}
|
|
38820
|
-
var
|
|
38834
|
+
var run3, opencodeApi, MAX_DEPTH, ROOTS;
|
|
38821
38835
|
var init_session2 = __esm({
|
|
38822
38836
|
"../bus-adapter-opencode/src/session.ts"() {
|
|
38823
38837
|
"use strict";
|
|
38824
|
-
|
|
38838
|
+
run3 = promisify2(execFile4);
|
|
38825
38839
|
opencodeApi = async (op, params) => {
|
|
38826
38840
|
const args = ["api", op];
|
|
38827
38841
|
for (const [k, v] of Object.entries(params))
|
|
38828
38842
|
args.push("--param", `${k}=${v}`);
|
|
38829
|
-
const { stdout } = await
|
|
38843
|
+
const { stdout } = await run3("opencode", args, { timeout: 15e3 });
|
|
38830
38844
|
const data = JSON.parse(stdout).data;
|
|
38831
38845
|
return data && typeof data === "object" ? data : void 0;
|
|
38832
38846
|
};
|
|
@@ -39201,13 +39215,13 @@ __export(codex_proxy_main_exports, {
|
|
|
39201
39215
|
readTokenFile: () => readTokenFile,
|
|
39202
39216
|
startCodexProxy: () => startCodexProxy
|
|
39203
39217
|
});
|
|
39204
|
-
import { readFileSync as
|
|
39218
|
+
import { readFileSync as readFileSync31 } from "node:fs";
|
|
39205
39219
|
import { homedir as homedir4 } from "node:os";
|
|
39206
39220
|
function readTokenFile(path) {
|
|
39207
39221
|
if (!path) return void 0;
|
|
39208
39222
|
try {
|
|
39209
39223
|
const p = path.startsWith("~/") ? `${homedir4()}${path.slice(1)}` : path;
|
|
39210
|
-
return
|
|
39224
|
+
return readFileSync31(p, "utf8").trim() || void 0;
|
|
39211
39225
|
} catch {
|
|
39212
39226
|
return void 0;
|
|
39213
39227
|
}
|
|
@@ -39257,13 +39271,13 @@ __export(proxy_main_exports, {
|
|
|
39257
39271
|
readTokenFile: () => readTokenFile2,
|
|
39258
39272
|
startProxy: () => startProxy
|
|
39259
39273
|
});
|
|
39260
|
-
import { readFileSync as
|
|
39274
|
+
import { readFileSync as readFileSync32 } from "node:fs";
|
|
39261
39275
|
import { homedir as homedir5 } from "node:os";
|
|
39262
39276
|
function readTokenFile2(path) {
|
|
39263
39277
|
if (!path) return void 0;
|
|
39264
39278
|
try {
|
|
39265
39279
|
const p = path.startsWith("~/") ? `${homedir5()}${path.slice(1)}` : path;
|
|
39266
|
-
return
|
|
39280
|
+
return readFileSync32(p, "utf8").trim() || void 0;
|
|
39267
39281
|
} catch {
|
|
39268
39282
|
return void 0;
|
|
39269
39283
|
}
|
|
@@ -39464,8 +39478,8 @@ function cutMiddle(value, max, more = "\u2026") {
|
|
|
39464
39478
|
const slash = value.lastIndexOf("/");
|
|
39465
39479
|
const dot = value.lastIndexOf(".", value.lastIndexOf(".") - 1);
|
|
39466
39480
|
const end = slash >= 0 ? value.slice(slash) : dot >= 0 ? value.slice(dot) : "";
|
|
39467
|
-
const
|
|
39468
|
-
return chars.slice(0, keep -
|
|
39481
|
+
const tail2 = len(end) > 0 && len(end) <= keep / 2 ? len(end) : Math.ceil(keep / 2);
|
|
39482
|
+
return chars.slice(0, keep - tail2).join("") + more + chars.slice(chars.length - tail2).join("");
|
|
39469
39483
|
}
|
|
39470
39484
|
var graphemes = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
39471
39485
|
var WIDE = /[\u1100-\u115f\u2e80-\u303e\u3041-\u33ff\u3400-\u4dbf\u4e00-\u9fff\ua000-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6\u{20000}-\u{3fffd}]/u;
|
|
@@ -39552,8 +39566,8 @@ function copy(style, bus = BUS_CMD) {
|
|
|
39552
39566
|
*/
|
|
39553
39567
|
connected: (origin) => {
|
|
39554
39568
|
const page = `${origin}${BUS_ROUTES.page}`;
|
|
39555
|
-
const
|
|
39556
|
-
if (len(
|
|
39569
|
+
const one3 = `Connected to ${origin}. Manage machines: ${page}`;
|
|
39570
|
+
if (len(one3) + 3 <= WIDTH) return [done(one3)];
|
|
39557
39571
|
return [
|
|
39558
39572
|
done(`Connected to ${clip(origin, 17)}.`),
|
|
39559
39573
|
next(`Manage machines: ${clip(page, 20)}`)
|
|
@@ -39764,9 +39778,9 @@ function copy(style, bus = BUS_CMD) {
|
|
|
39764
39778
|
)
|
|
39765
39779
|
],
|
|
39766
39780
|
unreachableFinal: (host, attempts, error62) => {
|
|
39767
|
-
const
|
|
39781
|
+
const tail2 = `after ${attempts} attempts.`;
|
|
39768
39782
|
return [
|
|
39769
|
-
`${fail2(`Couldn't reach ${clip(host, 21 + len(
|
|
39783
|
+
`${fail2(`Couldn't reach ${clip(host, 21 + len(tail2) + len(error62))} ${tail2}`)} ${p("muted", error62)}`,
|
|
39770
39784
|
next("Check your network or the --instance URL, then try again.")
|
|
39771
39785
|
];
|
|
39772
39786
|
},
|
|
@@ -40429,7 +40443,7 @@ import { join as join20 } from "node:path";
|
|
|
40429
40443
|
// ../bus-daemon/src/index.ts
|
|
40430
40444
|
init_src3();
|
|
40431
40445
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
40432
|
-
import { lstatSync as lstatSync8, realpathSync as realpathSync7, writeFileSync as
|
|
40446
|
+
import { lstatSync as lstatSync8, realpathSync as realpathSync7, writeFileSync as writeFileSync8 } from "node:fs";
|
|
40433
40447
|
import { basename as basename5, isAbsolute as isAbsolute7, join as join16 } from "node:path";
|
|
40434
40448
|
|
|
40435
40449
|
// ../bus-adapter-opencode/src/version.ts
|
|
@@ -40503,7 +40517,7 @@ var AgentTable = class {
|
|
|
40503
40517
|
// ../bus-daemon/src/attest.ts
|
|
40504
40518
|
init_src3();
|
|
40505
40519
|
init_src2();
|
|
40506
|
-
import { execFileSync as
|
|
40520
|
+
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
40507
40521
|
import { basename as basename3, isAbsolute as isAbsolute2 } from "node:path";
|
|
40508
40522
|
|
|
40509
40523
|
// ../bus-daemon/src/codex-attest.ts
|
|
@@ -40719,7 +40733,9 @@ function openSessions(dir, deps2) {
|
|
|
40719
40733
|
const pid = data?.pid;
|
|
40720
40734
|
if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 1)
|
|
40721
40735
|
continue;
|
|
40722
|
-
if (!Array.isArray(data.sessionIDs)
|
|
40736
|
+
if (!Array.isArray(data.sessionIDs)) continue;
|
|
40737
|
+
if (!deps2.isRunning(pid)) continue;
|
|
40738
|
+
if (deps2.accept && deps2.accept(pid) !== true) continue;
|
|
40723
40739
|
const started = deps2.procStartEpoch(pid, String(mtime));
|
|
40724
40740
|
if (started !== null && started > mtime + START_TOLERANCE_SECONDS) continue;
|
|
40725
40741
|
for (const id of data.sessionIDs) if (typeof id === "string") out.add(id);
|
|
@@ -40731,18 +40747,57 @@ function lstartEpoch(lstart) {
|
|
|
40731
40747
|
const ms = Date.parse(`${lstart} UTC`);
|
|
40732
40748
|
return Number.isNaN(ms) ? null : ms / 1e3;
|
|
40733
40749
|
}
|
|
40750
|
+
function openState(dir, deps2, ref) {
|
|
40751
|
+
let names2;
|
|
40752
|
+
try {
|
|
40753
|
+
names2 = readdirSync(dir);
|
|
40754
|
+
} catch {
|
|
40755
|
+
return null;
|
|
40756
|
+
}
|
|
40757
|
+
let unknown2 = false;
|
|
40758
|
+
for (const fn of names2) {
|
|
40759
|
+
if (!/^\d+\.json$/.test(fn)) continue;
|
|
40760
|
+
let data;
|
|
40761
|
+
let mtime;
|
|
40762
|
+
try {
|
|
40763
|
+
mtime = statSync3(join5(dir, fn)).mtimeMs / 1e3;
|
|
40764
|
+
data = JSON.parse(readFileSync4(join5(dir, fn), "utf8"));
|
|
40765
|
+
} catch (e) {
|
|
40766
|
+
if (e.code !== "ENOENT") unknown2 = true;
|
|
40767
|
+
continue;
|
|
40768
|
+
}
|
|
40769
|
+
const pid = data?.pid;
|
|
40770
|
+
if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 1)
|
|
40771
|
+
continue;
|
|
40772
|
+
if (!Array.isArray(data.sessionIDs) || !data.sessionIDs.includes(ref))
|
|
40773
|
+
continue;
|
|
40774
|
+
if (!deps2.isRunning(pid)) continue;
|
|
40775
|
+
const ok = deps2.accept ? deps2.accept(pid) : true;
|
|
40776
|
+
if (ok === null) {
|
|
40777
|
+
unknown2 = true;
|
|
40778
|
+
continue;
|
|
40779
|
+
}
|
|
40780
|
+
if (!ok) continue;
|
|
40781
|
+
const started = deps2.procStartEpoch(pid, String(mtime));
|
|
40782
|
+
if (started !== null && started > mtime + START_TOLERANCE_SECONDS) continue;
|
|
40783
|
+
return true;
|
|
40784
|
+
}
|
|
40785
|
+
return unknown2 ? null : false;
|
|
40786
|
+
}
|
|
40734
40787
|
|
|
40735
40788
|
// ../bus-daemon/src/codex-attest.ts
|
|
40789
|
+
var CODEX_TOOL_NAMESPACE = "mcp__oa_bus";
|
|
40736
40790
|
var CODEX_REFUSALS = {
|
|
40737
40791
|
notCodex: "it is not running under Codex.",
|
|
40738
40792
|
restarted: "Codex restarted. Call the tool again.",
|
|
40739
40793
|
notLoaded: "Codex does not have this thread loaded.",
|
|
40740
40794
|
callNotFound: "this call is not an open Open Artifacts bus call in the thread. Call the tool again.",
|
|
40795
|
+
/** An open code-mode exec in this turn that did not name an Open Artifacts bus tool literally (a lookup such as `tools[name]`). */
|
|
40796
|
+
dynamicLookup: `Call the bus tool by its exact name, for example tools.${CODEX_TOOL_NAMESPACE}__self(), not through a dynamic lookup.`,
|
|
40741
40797
|
subagent: "only the main Codex thread can use Open Artifacts bus, not a subagent.",
|
|
40742
40798
|
/** DRAFT (C27), pending Design. */
|
|
40743
40799
|
oneExec: "this exec already made an Open Artifacts bus call. Make each Open Artifacts bus call in its own exec."
|
|
40744
40800
|
};
|
|
40745
|
-
var CODEX_TOOL_NAMESPACE = "mcp__oa_bus";
|
|
40746
40801
|
var CODEX_PROXY_ENTRY_FILE = "codex-mcp-entry.json";
|
|
40747
40802
|
function codexProxyNamespaces(busHome2) {
|
|
40748
40803
|
try {
|
|
@@ -40765,6 +40820,7 @@ var EXEC_CALL = /^exec-[0-9a-f-]{36}$/;
|
|
|
40765
40820
|
var seen = () => ({
|
|
40766
40821
|
open: /* @__PURE__ */ new Map(),
|
|
40767
40822
|
execs: /* @__PURE__ */ new Map(),
|
|
40823
|
+
lookups: /* @__PURE__ */ new Map(),
|
|
40768
40824
|
latest: void 0,
|
|
40769
40825
|
done: /* @__PURE__ */ new Set()
|
|
40770
40826
|
});
|
|
@@ -40875,6 +40931,14 @@ function codexAttestor(deps2 = {}) {
|
|
|
40875
40931
|
const e = sc2.execs.get(item);
|
|
40876
40932
|
return e !== void 0 && e.at >= since && e.turn === cx.turn_id && sc2.latest === e.turn && !sc2.done.has(cx.call_id);
|
|
40877
40933
|
};
|
|
40934
|
+
const lookupOpen = (sc2) => {
|
|
40935
|
+
if (!item || !cx.turn_id || !EXEC_CALL.test(cx.call_id)) return false;
|
|
40936
|
+
const e = sc2.lookups.get(item);
|
|
40937
|
+
return e !== void 0 && e.at >= since && e.turn === cx.turn_id && sc2.latest === e.turn && !sc2.done.has(cx.call_id);
|
|
40938
|
+
};
|
|
40939
|
+
const missing2 = (sc2) => no(
|
|
40940
|
+
lookupOpen(sc2) ? CODEX_REFUSALS.dynamicLookup : CODEX_REFUSALS.callNotFound
|
|
40941
|
+
);
|
|
40878
40942
|
const itemUsed = () => item !== void 0 && (usedItems.get(thread)?.has(item) ?? false);
|
|
40879
40943
|
const ok = { ok: true, cwd: proof.cwd, pid: p };
|
|
40880
40944
|
const okFor = (sc2) => sc2.open.get(cx.call_id)?.proxied ? { ...ok, linkOnly: true } : ok;
|
|
@@ -40891,14 +40955,14 @@ function codexAttestor(deps2 = {}) {
|
|
|
40891
40955
|
}
|
|
40892
40956
|
if (itemUsed()) return no(CODEX_REFUSALS.oneExec);
|
|
40893
40957
|
if (execOpen(scan2)) return admitExec();
|
|
40894
|
-
if (!retry || retryMs <= 0) return
|
|
40958
|
+
if (!retry || retryMs <= 0) return missing2(scan2);
|
|
40895
40959
|
spend(thread, cx.call_id);
|
|
40896
40960
|
const sc = scan2;
|
|
40897
40961
|
return sleep(retryMs).then(() => {
|
|
40898
40962
|
advance(sc, ns);
|
|
40899
40963
|
if (isOpen(sc)) return okFor(sc);
|
|
40900
40964
|
if (itemUsed()) return no(CODEX_REFUSALS.oneExec);
|
|
40901
|
-
return execOpen(sc) ? admitExec() :
|
|
40965
|
+
return execOpen(sc) ? admitExec() : missing2(sc);
|
|
40902
40966
|
});
|
|
40903
40967
|
};
|
|
40904
40968
|
const sweep = (live, relock) => {
|
|
@@ -40963,7 +41027,42 @@ function codexAttestor(deps2 = {}) {
|
|
|
40963
41027
|
pinned.delete(pid);
|
|
40964
41028
|
return void 0;
|
|
40965
41029
|
};
|
|
41030
|
+
const isUserThread = (home2, thread) => {
|
|
41031
|
+
const row = threadRow(home2, thread);
|
|
41032
|
+
const rollout = row?.rollout_path ?? globRollout(home2, thread);
|
|
41033
|
+
if (!rollout || !plainFile(rollout)) return false;
|
|
41034
|
+
const meta3 = metaOf2(rollout, thread);
|
|
41035
|
+
if (!meta3) return false;
|
|
41036
|
+
return !(isSubagent(row ? row.source : meta3.source) || isSubagent(meta3.source) || SPAWNED_SOURCES.has(String(meta3.thread_source)));
|
|
41037
|
+
};
|
|
41038
|
+
const holders = (threads) => {
|
|
41039
|
+
const home2 = deps2.home ?? codexHome();
|
|
41040
|
+
const files2 = threads.filter((t) => plainFile(lockOf(home2, t)));
|
|
41041
|
+
if (!files2.length) return /* @__PURE__ */ new Map();
|
|
41042
|
+
const held = (deps2.holdersOf ?? lsofHolders)(
|
|
41043
|
+
files2.map((t) => lockOf(home2, t))
|
|
41044
|
+
);
|
|
41045
|
+
if (!held) return void 0;
|
|
41046
|
+
const pids = /* @__PURE__ */ new Set();
|
|
41047
|
+
for (const t of files2)
|
|
41048
|
+
for (const p of held.get(lockOf(home2, t)) ?? []) pids.add(p);
|
|
41049
|
+
const rows = pids.size ? procs([...pids]) : /* @__PURE__ */ new Map();
|
|
41050
|
+
if (!rows) return void 0;
|
|
41051
|
+
const out = /* @__PURE__ */ new Map();
|
|
41052
|
+
for (const t of files2) {
|
|
41053
|
+
if (!isUserThread(home2, t)) continue;
|
|
41054
|
+
for (const pid of held.get(lockOf(home2, t)) ?? []) {
|
|
41055
|
+
const row = rows.get(pid);
|
|
41056
|
+
if (!row || basename2(row.comm) !== "codex") continue;
|
|
41057
|
+
if (proofs.has(`${pid}\0${row.start}\0${t}`)) continue;
|
|
41058
|
+
out.set(t, { pid, start: row.start });
|
|
41059
|
+
break;
|
|
41060
|
+
}
|
|
41061
|
+
}
|
|
41062
|
+
return out;
|
|
41063
|
+
};
|
|
40966
41064
|
return {
|
|
41065
|
+
holders,
|
|
40967
41066
|
attest: (hello) => check2(hello, true),
|
|
40968
41067
|
attestNow: (hello) => check2(hello, false),
|
|
40969
41068
|
sweep,
|
|
@@ -41042,7 +41141,7 @@ var TURN_ENDS = /* @__PURE__ */ new Set([
|
|
|
41042
41141
|
function visitLine(st, text3, namespaces = [CODEX_TOOL_NAMESPACE]) {
|
|
41043
41142
|
if (!/call|task_complete|turn_aborted|task_started|item_completed/.test(text3))
|
|
41044
41143
|
return;
|
|
41045
|
-
const { open:
|
|
41144
|
+
const { open: open3, execs, lookups } = st;
|
|
41046
41145
|
let line;
|
|
41047
41146
|
try {
|
|
41048
41147
|
line = record3(JSON.parse(text3));
|
|
@@ -41057,18 +41156,19 @@ function visitLine(st, text3, namespaces = [CODEX_TOOL_NAMESPACE]) {
|
|
|
41057
41156
|
}
|
|
41058
41157
|
if (line?.type === "event_msg" && TURN_ENDS.has(p.type)) {
|
|
41059
41158
|
const turn = typeof p.turn_id === "string" ? p.turn_id : void 0;
|
|
41060
|
-
for (const [id, c] of
|
|
41061
|
-
if (turn === void 0 || c.turn === void 0 || c.turn === turn)
|
|
41062
|
-
open2.delete(id);
|
|
41063
|
-
for (const [id, c] of execs)
|
|
41159
|
+
for (const [id, c] of open3)
|
|
41064
41160
|
if (turn === void 0 || c.turn === void 0 || c.turn === turn)
|
|
41065
|
-
|
|
41161
|
+
open3.delete(id);
|
|
41162
|
+
for (const m of [execs, lookups])
|
|
41163
|
+
for (const [id, c] of m)
|
|
41164
|
+
if (turn === void 0 || c.turn === void 0 || c.turn === turn)
|
|
41165
|
+
m.delete(id);
|
|
41066
41166
|
return;
|
|
41067
41167
|
}
|
|
41068
41168
|
if (p.type === "item_completed") {
|
|
41069
41169
|
const id = record3(p.item)?.id;
|
|
41070
41170
|
if (typeof id === "string") {
|
|
41071
|
-
|
|
41171
|
+
open3.delete(id);
|
|
41072
41172
|
if (EXEC_CALL.test(id)) {
|
|
41073
41173
|
st.done.add(id);
|
|
41074
41174
|
if (st.done.size > USED_CAP)
|
|
@@ -41080,12 +41180,16 @@ function visitLine(st, text3, namespaces = [CODEX_TOOL_NAMESPACE]) {
|
|
|
41080
41180
|
if (typeof p.call_id !== "string") return;
|
|
41081
41181
|
if (line?.type === "response_item" && p.type === "custom_tool_call") {
|
|
41082
41182
|
const turn = record3(p.internal_chat_message_metadata_passthrough)?.turn_id;
|
|
41083
|
-
if (p.name === "exec" && p.namespace === void 0 && typeof p.id === "string" && typeof p.input === "string"
|
|
41084
|
-
|
|
41183
|
+
if (p.name === "exec" && p.namespace === void 0 && typeof p.id === "string" && typeof p.input === "string") {
|
|
41184
|
+
const entry = {
|
|
41085
41185
|
call: p.call_id,
|
|
41086
41186
|
at: Date.parse(String(line.timestamp)),
|
|
41087
41187
|
turn: typeof turn === "string" ? turn : void 0
|
|
41088
|
-
}
|
|
41188
|
+
};
|
|
41189
|
+
if (p.input.includes(`${CODEX_TOOL_NAMESPACE}__`))
|
|
41190
|
+
execs.set(p.id, entry);
|
|
41191
|
+
else lookups.set(p.id, entry);
|
|
41192
|
+
}
|
|
41089
41193
|
return;
|
|
41090
41194
|
}
|
|
41091
41195
|
if (line?.type === "response_item" && p.type === "function_call") {
|
|
@@ -41094,7 +41198,7 @@ function visitLine(st, text3, namespaces = [CODEX_TOOL_NAMESPACE]) {
|
|
|
41094
41198
|
const ours2 = bus || proxied;
|
|
41095
41199
|
const turn = record3(p.internal_chat_message_metadata_passthrough)?.turn_id;
|
|
41096
41200
|
if (ours2)
|
|
41097
|
-
|
|
41201
|
+
open3.set(p.call_id, {
|
|
41098
41202
|
at: Date.parse(String(line.timestamp)),
|
|
41099
41203
|
turn: typeof turn === "string" ? turn : void 0,
|
|
41100
41204
|
...proxied ? { proxied: true } : {}
|
|
@@ -41102,8 +41206,9 @@ function visitLine(st, text3, namespaces = [CODEX_TOOL_NAMESPACE]) {
|
|
|
41102
41206
|
return;
|
|
41103
41207
|
}
|
|
41104
41208
|
if (p.type.endsWith("_output") || p.type.endsWith("_end")) {
|
|
41105
|
-
|
|
41106
|
-
for (const
|
|
41209
|
+
open3.delete(p.call_id);
|
|
41210
|
+
for (const m of [execs, lookups])
|
|
41211
|
+
for (const [id, e] of m) if (e.call === p.call_id) m.delete(id);
|
|
41107
41212
|
}
|
|
41108
41213
|
}
|
|
41109
41214
|
var record3 = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : void 0;
|
|
@@ -41266,6 +41371,37 @@ function holdingFiles(pairs) {
|
|
|
41266
41371
|
return r !== void 0 && (holders.get(r)?.has(pid2) ?? false);
|
|
41267
41372
|
});
|
|
41268
41373
|
}
|
|
41374
|
+
function lsofHolders(files2) {
|
|
41375
|
+
let out;
|
|
41376
|
+
try {
|
|
41377
|
+
out = execFileSync2(systemTool("lsof"), ["-F", "pn", ...files2], {
|
|
41378
|
+
encoding: "utf8",
|
|
41379
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
41380
|
+
timeout: 2e3
|
|
41381
|
+
});
|
|
41382
|
+
} catch (e) {
|
|
41383
|
+
if (!exitedOne(e)) return void 0;
|
|
41384
|
+
out = String(e.stdout ?? "");
|
|
41385
|
+
}
|
|
41386
|
+
const byReal = /* @__PURE__ */ new Map();
|
|
41387
|
+
let pid = 0;
|
|
41388
|
+
for (const l of out.split("\n")) {
|
|
41389
|
+
if (l.startsWith("p")) pid = Number(l.slice(1));
|
|
41390
|
+
else if (l.startsWith("n") && pid > 0) {
|
|
41391
|
+
const list = byReal.get(l.slice(1)) ?? [];
|
|
41392
|
+
list.push(pid);
|
|
41393
|
+
byReal.set(l.slice(1), list);
|
|
41394
|
+
}
|
|
41395
|
+
}
|
|
41396
|
+
const res = /* @__PURE__ */ new Map();
|
|
41397
|
+
for (const f of files2) {
|
|
41398
|
+
try {
|
|
41399
|
+
res.set(f, byReal.get(realpathSync2(f)) ?? []);
|
|
41400
|
+
} catch {
|
|
41401
|
+
}
|
|
41402
|
+
}
|
|
41403
|
+
return res;
|
|
41404
|
+
}
|
|
41269
41405
|
function devParts(dev) {
|
|
41270
41406
|
return {
|
|
41271
41407
|
major: dev >> 8n & 0xfffn | dev >> 32n & ~0xfffn,
|
|
@@ -41424,6 +41560,187 @@ function isRunning(pid) {
|
|
|
41424
41560
|
}
|
|
41425
41561
|
}
|
|
41426
41562
|
|
|
41563
|
+
// ../bus-daemon/src/presence/attached.ts
|
|
41564
|
+
init_src2();
|
|
41565
|
+
import { execFileSync as execFileSync3, spawnSync } from "node:child_process";
|
|
41566
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync7, readlinkSync as readlinkSync2 } from "node:fs";
|
|
41567
|
+
var READ_TIMEOUT_MS = 1500;
|
|
41568
|
+
var exePath = (exe) => exe === null ? null : exe.replace(/ \(deleted\)$/, "");
|
|
41569
|
+
function attachedTo(service, deps2) {
|
|
41570
|
+
let svcExe = null;
|
|
41571
|
+
let svcSockets = null;
|
|
41572
|
+
let parent = null;
|
|
41573
|
+
return (tui) => {
|
|
41574
|
+
svcExe ??= exePath(deps2.exeOf(service));
|
|
41575
|
+
const tuiExe = exePath(deps2.exeOf(tui));
|
|
41576
|
+
if (!svcExe || !tuiExe) return null;
|
|
41577
|
+
if (tuiExe !== svcExe) return false;
|
|
41578
|
+
parent ??= deps2.ppidOf(service);
|
|
41579
|
+
if (parent === tui) return true;
|
|
41580
|
+
svcSockets ??= deps2.established(service);
|
|
41581
|
+
const mine = deps2.established(tui);
|
|
41582
|
+
if (!svcSockets || !mine) return null;
|
|
41583
|
+
const found2 = mine.some(
|
|
41584
|
+
(t) => svcSockets?.some((x) => x.remote === t.local && x.local === t.remote)
|
|
41585
|
+
);
|
|
41586
|
+
if (found2) return true;
|
|
41587
|
+
return parent === null ? null : false;
|
|
41588
|
+
};
|
|
41589
|
+
}
|
|
41590
|
+
var ATTACH_TTL_MS = 2e3;
|
|
41591
|
+
function cachedAttach(deps2, now = Date.now, ttlMs = ATTACH_TTL_MS) {
|
|
41592
|
+
const entries = /* @__PURE__ */ new Map();
|
|
41593
|
+
return (service) => (tui) => {
|
|
41594
|
+
const t = now();
|
|
41595
|
+
for (const [k, e2] of entries) if (t - e2.at >= ttlMs) entries.delete(k);
|
|
41596
|
+
let e = entries.get(service);
|
|
41597
|
+
if (!e) {
|
|
41598
|
+
e = { at: t, pred: attachedTo(service, deps2), seen: /* @__PURE__ */ new Map() };
|
|
41599
|
+
entries.set(service, e);
|
|
41600
|
+
}
|
|
41601
|
+
const hit = e.seen.get(tui);
|
|
41602
|
+
if (hit !== void 0) return hit;
|
|
41603
|
+
const r = e.pred(tui);
|
|
41604
|
+
if (r !== null) e.seen.set(tui, r);
|
|
41605
|
+
return r;
|
|
41606
|
+
};
|
|
41607
|
+
}
|
|
41608
|
+
var hexWord = (w) => (w.match(/../g) ?? []).reverse().map((b) => Number.parseInt(b, 16)).join(".");
|
|
41609
|
+
function hexAddr(hex3) {
|
|
41610
|
+
if (/^[0-9A-F]{8}$/i.test(hex3)) return hexWord(hex3);
|
|
41611
|
+
if (!/^[0-9A-F]{32}$/i.test(hex3)) return null;
|
|
41612
|
+
const words = (hex3.match(/.{8}/g) ?? []).map(
|
|
41613
|
+
(w) => (w.match(/../g) ?? []).reverse().join("")
|
|
41614
|
+
);
|
|
41615
|
+
if (words[0] === "00000000" && words[1] === "00000000" && words[2]?.toUpperCase() === "0000FFFF")
|
|
41616
|
+
return hexWord((hex3.slice(24) ?? "").toUpperCase());
|
|
41617
|
+
const groups = words.flatMap((w) => [w.slice(0, 4), w.slice(4)]);
|
|
41618
|
+
return `[${groups.map((g) => g.toLowerCase().replace(/^0+(?=.)/, "")).join(":")}]`;
|
|
41619
|
+
}
|
|
41620
|
+
function endpoint(field) {
|
|
41621
|
+
const [addr, port] = field.split(":");
|
|
41622
|
+
if (!addr || !port) return null;
|
|
41623
|
+
const a = hexAddr(addr);
|
|
41624
|
+
return a === null ? null : `${a}:${Number.parseInt(port, 16)}`;
|
|
41625
|
+
}
|
|
41626
|
+
function parseProcNetTcp(text3) {
|
|
41627
|
+
const rows = [];
|
|
41628
|
+
for (const line of text3.split("\n").slice(1)) {
|
|
41629
|
+
const f = line.trim().split(/\s+/);
|
|
41630
|
+
if (f.length < 10 || !f[1] || !f[2] || !f[3] || !f[9]) continue;
|
|
41631
|
+
const local = endpoint(f[1]);
|
|
41632
|
+
const remote = endpoint(f[2]);
|
|
41633
|
+
if (local === null || remote === null) continue;
|
|
41634
|
+
rows.push({ state: f[3], local, remote, inode: f[9] });
|
|
41635
|
+
}
|
|
41636
|
+
return rows;
|
|
41637
|
+
}
|
|
41638
|
+
function socketInodes(pid) {
|
|
41639
|
+
try {
|
|
41640
|
+
const out = /* @__PURE__ */ new Set();
|
|
41641
|
+
for (const fd of readdirSync4(`/proc/${pid}/fd`)) {
|
|
41642
|
+
try {
|
|
41643
|
+
const m = /^socket:\[(\d+)\]$/.exec(
|
|
41644
|
+
readlinkSync2(`/proc/${pid}/fd/${fd}`)
|
|
41645
|
+
);
|
|
41646
|
+
if (m?.[1]) out.add(m[1]);
|
|
41647
|
+
} catch {
|
|
41648
|
+
}
|
|
41649
|
+
}
|
|
41650
|
+
return out;
|
|
41651
|
+
} catch {
|
|
41652
|
+
return null;
|
|
41653
|
+
}
|
|
41654
|
+
}
|
|
41655
|
+
function tcpRows() {
|
|
41656
|
+
try {
|
|
41657
|
+
return [
|
|
41658
|
+
...parseProcNetTcp(readFileSync7("/proc/net/tcp", "utf8")),
|
|
41659
|
+
...parseProcNetTcp(readFileSync7("/proc/net/tcp6", "utf8"))
|
|
41660
|
+
];
|
|
41661
|
+
} catch {
|
|
41662
|
+
return null;
|
|
41663
|
+
}
|
|
41664
|
+
}
|
|
41665
|
+
function linuxEstablished(pid) {
|
|
41666
|
+
const inodes = socketInodes(pid);
|
|
41667
|
+
const rows = tcpRows();
|
|
41668
|
+
if (!inodes || !rows) return null;
|
|
41669
|
+
return rows.filter((r) => r.state === "01" && inodes.has(r.inode)).map((r) => ({ local: r.local, remote: r.remote }));
|
|
41670
|
+
}
|
|
41671
|
+
function run2(cmd, args) {
|
|
41672
|
+
try {
|
|
41673
|
+
return execFileSync3(systemTool(cmd), args, {
|
|
41674
|
+
encoding: "utf8",
|
|
41675
|
+
timeout: READ_TIMEOUT_MS,
|
|
41676
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
41677
|
+
});
|
|
41678
|
+
} catch {
|
|
41679
|
+
return null;
|
|
41680
|
+
}
|
|
41681
|
+
}
|
|
41682
|
+
function parseLsofNames(text3) {
|
|
41683
|
+
return text3.split("\n").filter((l) => l.startsWith("n")).map((l) => l.slice(1));
|
|
41684
|
+
}
|
|
41685
|
+
function lsofResult(r, alive2) {
|
|
41686
|
+
if (r.failed) return null;
|
|
41687
|
+
if (r.status === 0) return lsofEstablished(r.stdout);
|
|
41688
|
+
if (r.status === 1 && alive2 && !r.stdout.trim() && !r.stderr.trim())
|
|
41689
|
+
return [];
|
|
41690
|
+
return null;
|
|
41691
|
+
}
|
|
41692
|
+
function lsofEndpoint(e) {
|
|
41693
|
+
const m = /^\[::ffff:(\d+\.\d+\.\d+\.\d+)\](:\d+)$/i.exec(e);
|
|
41694
|
+
return m ? `${m[1]}${m[2]}` : e.toLowerCase();
|
|
41695
|
+
}
|
|
41696
|
+
function lsofEstablished(text3) {
|
|
41697
|
+
const out = [];
|
|
41698
|
+
for (const n of parseLsofNames(text3)) {
|
|
41699
|
+
const [local, remote] = n.split("->");
|
|
41700
|
+
if (local && remote)
|
|
41701
|
+
out.push({ local: lsofEndpoint(local), remote: lsofEndpoint(remote) });
|
|
41702
|
+
}
|
|
41703
|
+
return out;
|
|
41704
|
+
}
|
|
41705
|
+
var defaultAttachDeps = {
|
|
41706
|
+
exeOf(pid) {
|
|
41707
|
+
if (process.platform === "linux") {
|
|
41708
|
+
try {
|
|
41709
|
+
return readlinkSync2(`/proc/${pid}/exe`);
|
|
41710
|
+
} catch {
|
|
41711
|
+
return null;
|
|
41712
|
+
}
|
|
41713
|
+
}
|
|
41714
|
+
const out = run2("ps", ["-o", "comm=", "-p", String(pid)])?.trim();
|
|
41715
|
+
return out?.startsWith("/") ? out : null;
|
|
41716
|
+
},
|
|
41717
|
+
ppidOf(pid) {
|
|
41718
|
+
const out = run2("ps", ["-o", "ppid=", "-p", String(pid)])?.trim();
|
|
41719
|
+
return out && /^\d+$/.test(out) ? Number(out) : null;
|
|
41720
|
+
},
|
|
41721
|
+
established(pid) {
|
|
41722
|
+
if (process.platform === "linux") return linuxEstablished(pid);
|
|
41723
|
+
const r = spawnSync(
|
|
41724
|
+
systemTool("lsof"),
|
|
41725
|
+
["-nP", "-a", "-p", String(pid), "-iTCP", "-sTCP:ESTABLISHED", "-Fn"],
|
|
41726
|
+
{
|
|
41727
|
+
encoding: "utf8",
|
|
41728
|
+
timeout: READ_TIMEOUT_MS,
|
|
41729
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
41730
|
+
}
|
|
41731
|
+
);
|
|
41732
|
+
return lsofResult(
|
|
41733
|
+
{
|
|
41734
|
+
status: r.status,
|
|
41735
|
+
stdout: r.stdout ?? "",
|
|
41736
|
+
stderr: r.stderr ?? "",
|
|
41737
|
+
failed: r.error !== void 0 || r.signal !== null
|
|
41738
|
+
},
|
|
41739
|
+
isRunning(pid)
|
|
41740
|
+
);
|
|
41741
|
+
}
|
|
41742
|
+
};
|
|
41743
|
+
|
|
41427
41744
|
// ../bus-daemon/src/attest.ts
|
|
41428
41745
|
var defaultCodex;
|
|
41429
41746
|
function attest(hello, deps2 = {}) {
|
|
@@ -41493,13 +41810,17 @@ function attestOpenCode(hello, deps2) {
|
|
|
41493
41810
|
);
|
|
41494
41811
|
if (service === void 0)
|
|
41495
41812
|
return { ok: false, reason: "not running under an OpenCode service" };
|
|
41496
|
-
|
|
41497
|
-
|
|
41813
|
+
const open3 = deps2.openSessions ?? ((s, ref) => defaultOpenSessions(s, ref, deps2.attach));
|
|
41814
|
+
if (!open3(service, hello.agent_ref).has(hello.agent_ref))
|
|
41815
|
+
return {
|
|
41816
|
+
ok: false,
|
|
41817
|
+
reason: "opencode session is not open in a TUI attached to this service"
|
|
41818
|
+
};
|
|
41498
41819
|
return { ok: true, pid: service };
|
|
41499
41820
|
}
|
|
41500
41821
|
function commOf(pid) {
|
|
41501
41822
|
try {
|
|
41502
|
-
return
|
|
41823
|
+
return execFileSync4(systemTool("ps"), ["-o", "comm=", "-p", String(pid)], {
|
|
41503
41824
|
encoding: "utf8",
|
|
41504
41825
|
// A timeout reads as null, which ocServiceGone treats as unknown, not gone.
|
|
41505
41826
|
timeout: 1500,
|
|
@@ -41509,11 +41830,17 @@ function commOf(pid) {
|
|
|
41509
41830
|
return null;
|
|
41510
41831
|
}
|
|
41511
41832
|
}
|
|
41512
|
-
function defaultOpenSessions() {
|
|
41513
|
-
|
|
41514
|
-
|
|
41515
|
-
|
|
41516
|
-
|
|
41833
|
+
function defaultOpenSessions(service, ref, attach) {
|
|
41834
|
+
const open3 = openState(
|
|
41835
|
+
opencodePresenceDir(),
|
|
41836
|
+
{
|
|
41837
|
+
accept: attachedTo(service, attach ?? defaultAttachDeps),
|
|
41838
|
+
isRunning,
|
|
41839
|
+
procStartEpoch: (pid) => lstartEpoch(procStartOf(pid))
|
|
41840
|
+
},
|
|
41841
|
+
ref
|
|
41842
|
+
);
|
|
41843
|
+
return open3 === true ? /* @__PURE__ */ new Set([ref]) : /* @__PURE__ */ new Set();
|
|
41517
41844
|
}
|
|
41518
41845
|
|
|
41519
41846
|
// ../bus-daemon/src/claude-links.ts
|
|
@@ -41526,10 +41853,10 @@ import {
|
|
|
41526
41853
|
constants as constants2,
|
|
41527
41854
|
fstatSync as fstatSync2,
|
|
41528
41855
|
openSync as openSync2,
|
|
41529
|
-
readFileSync as
|
|
41856
|
+
readFileSync as readFileSync8
|
|
41530
41857
|
} from "node:fs";
|
|
41531
41858
|
import { userInfo } from "node:os";
|
|
41532
|
-
function isPrivateGroup(gid, user, read = () =>
|
|
41859
|
+
function isPrivateGroup(gid, user, read = () => readFileSync8("/etc/group", "utf8"), readPasswd = () => readFileSync8("/etc/passwd", "utf8")) {
|
|
41533
41860
|
let text3;
|
|
41534
41861
|
let passwd;
|
|
41535
41862
|
try {
|
|
@@ -41597,13 +41924,13 @@ function readOwnFile(file2, uid = process.getuid?.(), opts = {}) {
|
|
|
41597
41924
|
}
|
|
41598
41925
|
return {
|
|
41599
41926
|
state: "ok",
|
|
41600
|
-
text:
|
|
41927
|
+
text: readFileSync8(fd, "utf8"),
|
|
41601
41928
|
...note ? { note } : {}
|
|
41602
41929
|
};
|
|
41603
41930
|
}
|
|
41604
41931
|
if (st.mode & 18)
|
|
41605
41932
|
return { state: "unsafe", why: "is writable by others" };
|
|
41606
|
-
return { state: "ok", text:
|
|
41933
|
+
return { state: "ok", text: readFileSync8(fd, "utf8") };
|
|
41607
41934
|
} catch (e) {
|
|
41608
41935
|
return {
|
|
41609
41936
|
state: "unsafe",
|
|
@@ -41639,11 +41966,11 @@ function readClaudeLinks(file2, uid = process.getuid?.(), log = () => {
|
|
|
41639
41966
|
const out = [];
|
|
41640
41967
|
for (const raw of top.data.links) {
|
|
41641
41968
|
if (out.length >= CLAUDE_LINKS_MAX) break;
|
|
41642
|
-
const
|
|
41643
|
-
if (
|
|
41969
|
+
const one3 = EntrySchema.safeParse(raw);
|
|
41970
|
+
if (one3.success)
|
|
41644
41971
|
out.push({
|
|
41645
|
-
...
|
|
41646
|
-
hashes:
|
|
41972
|
+
...one3.data,
|
|
41973
|
+
hashes: one3.data.hashes.slice(-LINK_HASHES_MAX)
|
|
41647
41974
|
});
|
|
41648
41975
|
}
|
|
41649
41976
|
return out;
|
|
@@ -41696,10 +42023,10 @@ function readCodexAgents(file2, uid = process.getuid?.()) {
|
|
|
41696
42023
|
const out = [];
|
|
41697
42024
|
for (const raw of top.data.agents) {
|
|
41698
42025
|
if (out.length >= LIMITS.maxAgentsPerMachine) break;
|
|
41699
|
-
const
|
|
41700
|
-
if (!
|
|
41701
|
-
seen2.add(
|
|
41702
|
-
out.push(
|
|
42026
|
+
const one3 = CodexAgentSchema.safeParse(raw);
|
|
42027
|
+
if (!one3.success || seen2.has(one3.data.ref)) continue;
|
|
42028
|
+
seen2.add(one3.data.ref);
|
|
42029
|
+
out.push(one3.data);
|
|
41703
42030
|
}
|
|
41704
42031
|
return out;
|
|
41705
42032
|
} catch {
|
|
@@ -41713,6 +42040,52 @@ function writeCodexAgents(file2, agents) {
|
|
|
41713
42040
|
renameSync4(tmp, file2);
|
|
41714
42041
|
}
|
|
41715
42042
|
|
|
42043
|
+
// ../bus-daemon/src/codex-away.ts
|
|
42044
|
+
init_src();
|
|
42045
|
+
init_zod();
|
|
42046
|
+
import { chmodSync as chmodSync5, renameSync as renameSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
42047
|
+
var AWAY_IDLE_MS = 24 * 36e5;
|
|
42048
|
+
var AWAY_MAX = 64;
|
|
42049
|
+
var CodexAwaySchema = external_exports.strictObject({
|
|
42050
|
+
ref: AgentRefSchema,
|
|
42051
|
+
name: external_exports.string().min(1).max(200),
|
|
42052
|
+
namespace: WireNamespaceSchema,
|
|
42053
|
+
/** When the thread was last live (ms), to the hour. */
|
|
42054
|
+
lastLive: external_exports.number().int().nonnegative()
|
|
42055
|
+
});
|
|
42056
|
+
var FileSchema3 = external_exports.strictObject({
|
|
42057
|
+
v: external_exports.literal(1),
|
|
42058
|
+
rows: external_exports.array(external_exports.unknown())
|
|
42059
|
+
});
|
|
42060
|
+
function trimAway(rows, now) {
|
|
42061
|
+
return rows.filter((r) => now - r.lastLive <= AWAY_IDLE_MS).sort((a, b) => b.lastLive - a.lastLive).slice(0, Math.min(AWAY_MAX, LIMITS.maxAgentsPerMachine));
|
|
42062
|
+
}
|
|
42063
|
+
function readCodexAway(file2, now, uid = process.getuid?.()) {
|
|
42064
|
+
try {
|
|
42065
|
+
const f = readOwnFile(file2, uid);
|
|
42066
|
+
if (f.state !== "ok") return [];
|
|
42067
|
+
const top = FileSchema3.safeParse(JSON.parse(f.text));
|
|
42068
|
+
if (!top.success) return [];
|
|
42069
|
+
const seen2 = /* @__PURE__ */ new Set();
|
|
42070
|
+
const out = [];
|
|
42071
|
+
for (const raw of top.data.rows) {
|
|
42072
|
+
const one3 = CodexAwaySchema.safeParse(raw);
|
|
42073
|
+
if (!one3.success || seen2.has(one3.data.ref)) continue;
|
|
42074
|
+
seen2.add(one3.data.ref);
|
|
42075
|
+
out.push(one3.data);
|
|
42076
|
+
}
|
|
42077
|
+
return trimAway(out, now);
|
|
42078
|
+
} catch {
|
|
42079
|
+
return [];
|
|
42080
|
+
}
|
|
42081
|
+
}
|
|
42082
|
+
function writeCodexAway(file2, rows) {
|
|
42083
|
+
const tmp = `${file2}.${process.pid}.tmp`;
|
|
42084
|
+
writeFileSync4(tmp, JSON.stringify({ v: 1, rows }), { mode: 384 });
|
|
42085
|
+
chmodSync5(tmp, 384);
|
|
42086
|
+
renameSync5(tmp, file2);
|
|
42087
|
+
}
|
|
42088
|
+
|
|
41716
42089
|
// ../bus-daemon/src/codex-names.ts
|
|
41717
42090
|
import { closeSync as closeSync3, constants as constants3, fstatSync as fstatSync3, openSync as openSync3, readSync as readSync2 } from "node:fs";
|
|
41718
42091
|
import { join as join8 } from "node:path";
|
|
@@ -41783,13 +42156,13 @@ import { dirname as dirname6, join as join12 } from "node:path";
|
|
|
41783
42156
|
// ../bus-daemon/src/global.ts
|
|
41784
42157
|
import { randomBytes } from "node:crypto";
|
|
41785
42158
|
import {
|
|
41786
|
-
chmodSync as
|
|
42159
|
+
chmodSync as chmodSync6,
|
|
41787
42160
|
closeSync as closeSync4,
|
|
41788
42161
|
lstatSync as lstatSync5,
|
|
41789
42162
|
mkdirSync as mkdirSync5,
|
|
41790
42163
|
openSync as openSync4,
|
|
41791
42164
|
realpathSync as realpathSync3,
|
|
41792
|
-
renameSync as
|
|
42165
|
+
renameSync as renameSync6,
|
|
41793
42166
|
statSync as statSync5,
|
|
41794
42167
|
unlinkSync,
|
|
41795
42168
|
writeSync
|
|
@@ -41862,7 +42235,7 @@ function sameDir(entry, dir) {
|
|
|
41862
42235
|
}
|
|
41863
42236
|
function writeGlobalDirs(dirs, h = home()) {
|
|
41864
42237
|
mkdirSync5(h, { recursive: true, mode: 448 });
|
|
41865
|
-
|
|
42238
|
+
chmodSync6(h, 448);
|
|
41866
42239
|
const tmp = join9(h, `.global.json.${randomBytes(8).toString("hex")}.tmp`);
|
|
41867
42240
|
const fd = openSync4(tmp, "wx", 384);
|
|
41868
42241
|
try {
|
|
@@ -41875,8 +42248,8 @@ function writeGlobalDirs(dirs, h = home()) {
|
|
|
41875
42248
|
}
|
|
41876
42249
|
closeSync4(fd);
|
|
41877
42250
|
try {
|
|
41878
|
-
|
|
41879
|
-
|
|
42251
|
+
chmodSync6(tmp, 384);
|
|
42252
|
+
renameSync6(tmp, globalFile(h));
|
|
41880
42253
|
} catch (e) {
|
|
41881
42254
|
unlinkSync(tmp);
|
|
41882
42255
|
throw e;
|
|
@@ -41885,7 +42258,7 @@ function writeGlobalDirs(dirs, h = home()) {
|
|
|
41885
42258
|
|
|
41886
42259
|
// ../bus-daemon/src/namespace.ts
|
|
41887
42260
|
init_src();
|
|
41888
|
-
import { execFileSync as
|
|
42261
|
+
import { execFileSync as execFileSync5 } from "node:child_process";
|
|
41889
42262
|
import { existsSync as existsSync3, realpathSync as realpathSync4 } from "node:fs";
|
|
41890
42263
|
import {
|
|
41891
42264
|
basename as basename4,
|
|
@@ -41900,11 +42273,11 @@ import {
|
|
|
41900
42273
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
41901
42274
|
import {
|
|
41902
42275
|
appendFileSync,
|
|
41903
|
-
chmodSync as
|
|
42276
|
+
chmodSync as chmodSync7,
|
|
41904
42277
|
closeSync as closeSync5,
|
|
41905
42278
|
mkdirSync as mkdirSync6,
|
|
41906
42279
|
openSync as openSync5,
|
|
41907
|
-
renameSync as
|
|
42280
|
+
renameSync as renameSync7,
|
|
41908
42281
|
unlinkSync as unlinkSync2,
|
|
41909
42282
|
writeSync as writeSync2
|
|
41910
42283
|
} from "node:fs";
|
|
@@ -41956,7 +42329,7 @@ function writeRemotes(entries, h = home()) {
|
|
|
41956
42329
|
}
|
|
41957
42330
|
function writePrivate(h, name, body) {
|
|
41958
42331
|
mkdirSync6(h, { recursive: true, mode: 448 });
|
|
41959
|
-
|
|
42332
|
+
chmodSync7(h, 448);
|
|
41960
42333
|
const tmp = join10(h, `.${name}.${randomBytes2(8).toString("hex")}.tmp`);
|
|
41961
42334
|
const fd = openSync5(tmp, "wx", 384);
|
|
41962
42335
|
try {
|
|
@@ -41969,8 +42342,8 @@ function writePrivate(h, name, body) {
|
|
|
41969
42342
|
}
|
|
41970
42343
|
closeSync5(fd);
|
|
41971
42344
|
try {
|
|
41972
|
-
|
|
41973
|
-
|
|
42345
|
+
chmodSync7(tmp, 384);
|
|
42346
|
+
renameSync7(tmp, join10(h, name));
|
|
41974
42347
|
} catch (e) {
|
|
41975
42348
|
unlinkSync2(tmp);
|
|
41976
42349
|
throw e;
|
|
@@ -41983,7 +42356,7 @@ function logApproval(entry, h = home(), now = /* @__PURE__ */ new Date()) {
|
|
|
41983
42356
|
const line = `${now.toISOString()} ${entry.action} dir=${JSON.stringify(entry.dir)} namespace=${JSON.stringify(entry.namespace)} tty=${entry.tty ? "yes" : "no"}
|
|
41984
42357
|
`;
|
|
41985
42358
|
appendFileSync(file2, line, { mode: 384 });
|
|
41986
|
-
|
|
42359
|
+
chmodSync7(file2, 384);
|
|
41987
42360
|
}
|
|
41988
42361
|
|
|
41989
42362
|
// ../bus-daemon/src/namespace.ts
|
|
@@ -42271,7 +42644,7 @@ function nearestConfig(dir, deps2 = {}) {
|
|
|
42271
42644
|
}
|
|
42272
42645
|
var git = (cwd, args) => {
|
|
42273
42646
|
try {
|
|
42274
|
-
return
|
|
42647
|
+
return execFileSync5("git", ["-C", cwd, ...args], {
|
|
42275
42648
|
encoding: "utf8",
|
|
42276
42649
|
stdio: ["ignore", "pipe", "ignore"]
|
|
42277
42650
|
}).trim() || null;
|
|
@@ -42776,6 +43149,14 @@ var FramePacer = class {
|
|
|
42776
43149
|
};
|
|
42777
43150
|
|
|
42778
43151
|
// ../bus-daemon/src/hub.ts
|
|
43152
|
+
var HUB_HELLO_CAPS = [
|
|
43153
|
+
BUS_CAPS.ids,
|
|
43154
|
+
BUS_CAPS.mailbox,
|
|
43155
|
+
BUS_CAPS.links,
|
|
43156
|
+
BUS_CAPS.follow,
|
|
43157
|
+
BUS_CAPS.link,
|
|
43158
|
+
BUS_CAPS.waiting
|
|
43159
|
+
];
|
|
42779
43160
|
var HubConnection = class {
|
|
42780
43161
|
constructor(opts) {
|
|
42781
43162
|
this.opts = opts;
|
|
@@ -42898,13 +43279,7 @@ var HubConnection = class {
|
|
|
42898
43279
|
// Reply ids: the hub then names each sender's agent (deliver.from_id).
|
|
42899
43280
|
// Mailboxes: the hub then sends queued/since, away rows and the new
|
|
42900
43281
|
// refusals, and honours agent_up.replaces (#1295).
|
|
42901
|
-
caps: [
|
|
42902
|
-
BUS_CAPS.ids,
|
|
42903
|
-
BUS_CAPS.mailbox,
|
|
42904
|
-
BUS_CAPS.links,
|
|
42905
|
-
BUS_CAPS.follow,
|
|
42906
|
-
BUS_CAPS.link
|
|
42907
|
-
]
|
|
43282
|
+
caps: [...HUB_HELLO_CAPS]
|
|
42908
43283
|
});
|
|
42909
43284
|
this.#guard("sessions", () => {
|
|
42910
43285
|
this.send({
|
|
@@ -43723,11 +44098,11 @@ function routeLocal(frame, hello, reply, ctx) {
|
|
|
43723
44098
|
init_src2();
|
|
43724
44099
|
init_src();
|
|
43725
44100
|
import {
|
|
43726
|
-
chmodSync as
|
|
43727
|
-
readFileSync as
|
|
43728
|
-
renameSync as
|
|
44101
|
+
chmodSync as chmodSync8,
|
|
44102
|
+
readFileSync as readFileSync9,
|
|
44103
|
+
renameSync as renameSync8,
|
|
43729
44104
|
rmSync as rmSync4,
|
|
43730
|
-
writeFileSync as
|
|
44105
|
+
writeFileSync as writeFileSync5
|
|
43731
44106
|
} from "node:fs";
|
|
43732
44107
|
var metaOf = ({
|
|
43733
44108
|
at: _,
|
|
@@ -43955,7 +44330,7 @@ var SentStore = class {
|
|
|
43955
44330
|
if (!this.file) return;
|
|
43956
44331
|
let raw;
|
|
43957
44332
|
try {
|
|
43958
|
-
raw = JSON.parse(
|
|
44333
|
+
raw = JSON.parse(readFileSync9(this.file, "utf8"));
|
|
43959
44334
|
} catch {
|
|
43960
44335
|
return;
|
|
43961
44336
|
}
|
|
@@ -44017,12 +44392,12 @@ var SentStore = class {
|
|
|
44017
44392
|
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
44018
44393
|
try {
|
|
44019
44394
|
rmSync4(tmp, { force: true });
|
|
44020
|
-
|
|
44395
|
+
writeFileSync5(tmp, JSON.stringify(Object.fromEntries(this.#all)), {
|
|
44021
44396
|
mode: 384,
|
|
44022
44397
|
flag: "wx"
|
|
44023
44398
|
});
|
|
44024
|
-
|
|
44025
|
-
|
|
44399
|
+
chmodSync8(tmp, 384);
|
|
44400
|
+
renameSync8(tmp, this.file);
|
|
44026
44401
|
} catch (e) {
|
|
44027
44402
|
this.#log?.(
|
|
44028
44403
|
`sent file write failed: ${e instanceof Error ? e.message : String(e)}`
|
|
@@ -44211,20 +44586,20 @@ init_src3();
|
|
|
44211
44586
|
init_src();
|
|
44212
44587
|
import { createHash as createHash4, randomUUID } from "node:crypto";
|
|
44213
44588
|
import {
|
|
44214
|
-
chmodSync as
|
|
44589
|
+
chmodSync as chmodSync10,
|
|
44215
44590
|
lstatSync as lstatSync6,
|
|
44216
44591
|
mkdirSync as mkdirSync7,
|
|
44217
|
-
readFileSync as
|
|
44218
|
-
renameSync as
|
|
44592
|
+
readFileSync as readFileSync11,
|
|
44593
|
+
renameSync as renameSync10,
|
|
44219
44594
|
rmSync as rmSync5,
|
|
44220
|
-
writeFileSync as
|
|
44595
|
+
writeFileSync as writeFileSync7
|
|
44221
44596
|
} from "node:fs";
|
|
44222
44597
|
import { createServer as createServer2 } from "node:net";
|
|
44223
44598
|
import { dirname as dirname7, join as join13 } from "node:path";
|
|
44224
44599
|
import { createInterface } from "node:readline";
|
|
44225
44600
|
|
|
44226
44601
|
// ../bus-daemon/src/transports/held.ts
|
|
44227
|
-
import { chmodSync as
|
|
44602
|
+
import { chmodSync as chmodSync9, readFileSync as readFileSync10, renameSync as renameSync9, writeFileSync as writeFileSync6 } from "node:fs";
|
|
44228
44603
|
var HeldStore = class {
|
|
44229
44604
|
constructor(file2, opts = {}) {
|
|
44230
44605
|
this.file = file2;
|
|
@@ -44237,6 +44612,10 @@ var HeldStore = class {
|
|
|
44237
44612
|
has(msgId) {
|
|
44238
44613
|
return msgId in this.#read();
|
|
44239
44614
|
}
|
|
44615
|
+
/** When `msgId` was added (ms), if it is held. */
|
|
44616
|
+
at(msgId) {
|
|
44617
|
+
return this.#read()[msgId];
|
|
44618
|
+
}
|
|
44240
44619
|
add(msgId) {
|
|
44241
44620
|
this.#write({ ...this.#read(), [msgId]: this.#now() });
|
|
44242
44621
|
}
|
|
@@ -44249,7 +44628,7 @@ var HeldStore = class {
|
|
|
44249
44628
|
#read() {
|
|
44250
44629
|
let raw;
|
|
44251
44630
|
try {
|
|
44252
|
-
raw = JSON.parse(
|
|
44631
|
+
raw = JSON.parse(readFileSync10(this.file, "utf8"));
|
|
44253
44632
|
} catch {
|
|
44254
44633
|
return {};
|
|
44255
44634
|
}
|
|
@@ -44262,9 +44641,9 @@ var HeldStore = class {
|
|
|
44262
44641
|
}
|
|
44263
44642
|
#write(all) {
|
|
44264
44643
|
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
44265
|
-
|
|
44266
|
-
|
|
44267
|
-
|
|
44644
|
+
writeFileSync6(tmp, JSON.stringify(all), { mode: 384 });
|
|
44645
|
+
chmodSync9(tmp, 384);
|
|
44646
|
+
renameSync9(tmp, this.file);
|
|
44268
44647
|
}
|
|
44269
44648
|
};
|
|
44270
44649
|
|
|
@@ -44310,7 +44689,7 @@ function returnKey(agentRef, namespace2, peerName, fromId) {
|
|
|
44310
44689
|
function readReturnIndex(file2) {
|
|
44311
44690
|
let raw;
|
|
44312
44691
|
try {
|
|
44313
|
-
raw = JSON.parse(
|
|
44692
|
+
raw = JSON.parse(readFileSync11(file2, "utf8"));
|
|
44314
44693
|
} catch {
|
|
44315
44694
|
return /* @__PURE__ */ Object.create(null);
|
|
44316
44695
|
}
|
|
@@ -44601,7 +44980,7 @@ var ClaudeTransport = class {
|
|
|
44601
44980
|
if (unsafe) throw new UnsafeDir(unsafe);
|
|
44602
44981
|
} else {
|
|
44603
44982
|
mkdirSync7(this.opts.socketsDir, { recursive: true, mode: 448 });
|
|
44604
|
-
|
|
44983
|
+
chmodSync10(this.opts.socketsDir, 448);
|
|
44605
44984
|
}
|
|
44606
44985
|
rmSync5(path, { force: true });
|
|
44607
44986
|
this.#paths.set(key2, path);
|
|
@@ -44633,7 +45012,7 @@ var ClaudeTransport = class {
|
|
|
44633
45012
|
sink.server.once("error", reject);
|
|
44634
45013
|
sink.server.listen(path, () => resolve16());
|
|
44635
45014
|
});
|
|
44636
|
-
|
|
45015
|
+
chmodSync10(path, 384);
|
|
44637
45016
|
return sink;
|
|
44638
45017
|
}
|
|
44639
45018
|
/** Paths of the sinks bound or binding now, by key. */
|
|
@@ -44673,9 +45052,9 @@ var ClaudeTransport = class {
|
|
|
44673
45052
|
const out = /* @__PURE__ */ Object.create(null);
|
|
44674
45053
|
for (const [k, v] of keep) out[k] = v;
|
|
44675
45054
|
const tmp = `${file2}.${process.pid}.tmp`;
|
|
44676
|
-
|
|
44677
|
-
|
|
44678
|
-
|
|
45055
|
+
writeFileSync7(tmp, JSON.stringify(out), { mode: 384 });
|
|
45056
|
+
chmodSync10(tmp, 384);
|
|
45057
|
+
renameSync10(tmp, file2);
|
|
44679
45058
|
return out;
|
|
44680
45059
|
} catch (e) {
|
|
44681
45060
|
this.opts.log?.(
|
|
@@ -44753,7 +45132,7 @@ async function shut(sink) {
|
|
|
44753
45132
|
// ../bus-daemon/src/transports/codex.ts
|
|
44754
45133
|
init_src2();
|
|
44755
45134
|
import { execFile } from "node:child_process";
|
|
44756
|
-
import { accessSync as accessSync2, constants as constants4, readFileSync as
|
|
45135
|
+
import { accessSync as accessSync2, constants as constants4, readFileSync as readFileSync12, statSync as statSync6 } from "node:fs";
|
|
44757
45136
|
import { readFile } from "node:fs/promises";
|
|
44758
45137
|
import { delimiter as delimiter2, isAbsolute as isAbsolute6, join as join14 } from "node:path";
|
|
44759
45138
|
var CODEX_QUEUE_TIMEOUT_MS = 1e4;
|
|
@@ -44774,7 +45153,7 @@ var executable2 = (p) => {
|
|
|
44774
45153
|
};
|
|
44775
45154
|
function codexAppBin(app) {
|
|
44776
45155
|
try {
|
|
44777
|
-
const plist =
|
|
45156
|
+
const plist = readFileSync12(join14(app, "Contents", "Info.plist"), "utf8");
|
|
44778
45157
|
const id = /<key>CFBundleIdentifier<\/key>\s*<string>([^<]*)<\/string>/.exec(
|
|
44779
45158
|
plist
|
|
44780
45159
|
)?.[1];
|
|
@@ -44786,7 +45165,7 @@ function codexAppBin(app) {
|
|
|
44786
45165
|
function resolveCodexBin(o) {
|
|
44787
45166
|
if (o.configFile)
|
|
44788
45167
|
try {
|
|
44789
|
-
const raw = JSON.parse(
|
|
45168
|
+
const raw = JSON.parse(readFileSync12(o.configFile, "utf8"));
|
|
44790
45169
|
if (typeof raw.bin === "string" && isAbsolute6(raw.bin) && executable2(raw.bin))
|
|
44791
45170
|
return { path: raw.bin, from: "config" };
|
|
44792
45171
|
} catch {
|
|
@@ -44933,16 +45312,34 @@ var CodexTransport = class {
|
|
|
44933
45312
|
}
|
|
44934
45313
|
async deliver(agent, mail) {
|
|
44935
45314
|
if (!await this.#wakes(agent)) return { ok: false, reason: "queued" };
|
|
44936
|
-
const r = await this.#queue(agent, mail.msg_id, codexText(agent, mail));
|
|
45315
|
+
const r = await this.#queue(agent.ref, mail.msg_id, codexText(agent, mail));
|
|
44937
45316
|
if (r.ok) return { ok: true };
|
|
44938
45317
|
return { ok: false, reason: r.taken === "no" ? "timeout" : "queued" };
|
|
44939
45318
|
}
|
|
44940
45319
|
/** An Open Artifacts bus notice about mail `msgId` (expired or refused); never a message from a peer. */
|
|
44941
45320
|
async notify(agent, text3, msgId) {
|
|
44942
45321
|
if (!await this.#wakes(agent)) return false;
|
|
44943
|
-
const r = await this.#queue(
|
|
45322
|
+
const r = await this.#queue(
|
|
45323
|
+
agent.ref,
|
|
45324
|
+
`notice:${msgId}`,
|
|
45325
|
+
`[oa-bus] ${text3}`
|
|
45326
|
+
);
|
|
44944
45327
|
return r.ok || r.taken === "maybe";
|
|
44945
45328
|
}
|
|
45329
|
+
/**
|
|
45330
|
+
* #2029: one fixed bus-written text into a thread that is not admitted, as
|
|
45331
|
+
* `id` (once per id, even after a failure). Only to a host that wakes on a
|
|
45332
|
+
* queued message (`pid` is that host); admission is not touched.
|
|
45333
|
+
*/
|
|
45334
|
+
canWake(pid) {
|
|
45335
|
+
return this.opts.wakes(pid);
|
|
45336
|
+
}
|
|
45337
|
+
async wake(ref, pid, id, text3) {
|
|
45338
|
+
if (!await this.opts.wakes(pid)) return "no_host";
|
|
45339
|
+
const r = await this.#queue(ref, id, text3);
|
|
45340
|
+
if (r.ok) return "sent";
|
|
45341
|
+
return r.taken === "maybe" ? "maybe" : "failed";
|
|
45342
|
+
}
|
|
44946
45343
|
#wakes(agent) {
|
|
44947
45344
|
return agent.live ? this.opts.wakes(agent.pid) : Promise.resolve(false);
|
|
44948
45345
|
}
|
|
@@ -44963,7 +45360,7 @@ var CodexTransport = class {
|
|
|
44963
45360
|
return false;
|
|
44964
45361
|
}
|
|
44965
45362
|
}
|
|
44966
|
-
async #queue(
|
|
45363
|
+
async #queue(ref, id, text3) {
|
|
44967
45364
|
if (this.#has(id)) return { ok: true };
|
|
44968
45365
|
if (this.#has(`maybe:${id}`)) return { ok: false, taken: "maybe" };
|
|
44969
45366
|
this.#bin ??= this.opts.resolve();
|
|
@@ -44977,7 +45374,7 @@ var CodexTransport = class {
|
|
|
44977
45374
|
return { ok: false, taken: "nobin" };
|
|
44978
45375
|
}
|
|
44979
45376
|
this.#missingLogged = false;
|
|
44980
|
-
const args = ["queue", `--thread=${
|
|
45377
|
+
const args = ["queue", `--thread=${ref}`, `--message=${text3}`];
|
|
44981
45378
|
let res;
|
|
44982
45379
|
try {
|
|
44983
45380
|
res = await this.opts.run(bin.path, args, {
|
|
@@ -44986,6 +45383,10 @@ var CodexTransport = class {
|
|
|
44986
45383
|
});
|
|
44987
45384
|
} catch (e) {
|
|
44988
45385
|
this.#bin = void 0;
|
|
45386
|
+
this.opts.event?.("codex_queue_failed", {
|
|
45387
|
+
thread: ref,
|
|
45388
|
+
reason: "start"
|
|
45389
|
+
});
|
|
44989
45390
|
this.opts.log?.(
|
|
44990
45391
|
`codex queue could not start (${bin.path}): ${e instanceof Error ? e.message : String(e)}`
|
|
44991
45392
|
);
|
|
@@ -44996,14 +45397,21 @@ var CodexTransport = class {
|
|
|
44996
45397
|
}
|
|
44997
45398
|
if (res.code === null) {
|
|
44998
45399
|
this.#keep(`maybe:${id}`);
|
|
44999
|
-
this.opts.
|
|
45000
|
-
|
|
45001
|
-
|
|
45400
|
+
this.opts.event?.("codex_queue_failed", {
|
|
45401
|
+
thread: ref,
|
|
45402
|
+
reason: "timeout"
|
|
45403
|
+
});
|
|
45404
|
+
this.opts.log?.(`codex queue for ${ref} timed out; not queued again`);
|
|
45002
45405
|
return { ok: false, taken: "maybe" };
|
|
45003
45406
|
}
|
|
45004
45407
|
this.#bin = void 0;
|
|
45408
|
+
this.opts.event?.("codex_queue_failed", {
|
|
45409
|
+
thread: ref,
|
|
45410
|
+
reason: "exit",
|
|
45411
|
+
code: res.code
|
|
45412
|
+
});
|
|
45005
45413
|
this.opts.log?.(
|
|
45006
|
-
`codex queue for ${
|
|
45414
|
+
`codex queue for ${ref} exited ${res.code}: ${stripTerminalControls(res.stderr.trim()).slice(0, 300)}`
|
|
45007
45415
|
);
|
|
45008
45416
|
return { ok: false, taken: "no" };
|
|
45009
45417
|
}
|
|
@@ -45012,6 +45420,7 @@ var codexHostWakes = async (pid) => {
|
|
|
45012
45420
|
const args = await processArgs(pid);
|
|
45013
45421
|
return args !== void 0 && hostWakes(args);
|
|
45014
45422
|
};
|
|
45423
|
+
var CODEX_WAKE_TEXT = `Open Artifacts bus: messages are waiting for this thread. Call the tool ${CODEX_TOOL_NAMESPACE}__self once, by that literal name (do not look it up from a tool list), to receive them.`;
|
|
45015
45424
|
|
|
45016
45425
|
// ../bus-daemon/src/transports/opencode.ts
|
|
45017
45426
|
init_src2();
|
|
@@ -45218,9 +45627,114 @@ var PiTransport = class {
|
|
|
45218
45627
|
}
|
|
45219
45628
|
};
|
|
45220
45629
|
|
|
45630
|
+
// ../bus-daemon/src/event-log.ts
|
|
45631
|
+
init_src2();
|
|
45632
|
+
import { constants as constants5 } from "node:fs";
|
|
45633
|
+
import { chmod, lstat, mkdir, open as open2, rename } from "node:fs/promises";
|
|
45634
|
+
import { dirname as dirname8 } from "node:path";
|
|
45635
|
+
var EVENT_LOG_MAX_BYTES = 1e6;
|
|
45636
|
+
var FIELDS = /* @__PURE__ */ new Set([
|
|
45637
|
+
"name",
|
|
45638
|
+
"ref",
|
|
45639
|
+
"thread",
|
|
45640
|
+
"agent",
|
|
45641
|
+
"ns",
|
|
45642
|
+
"kind",
|
|
45643
|
+
"pid",
|
|
45644
|
+
"reason",
|
|
45645
|
+
"code",
|
|
45646
|
+
"version",
|
|
45647
|
+
"state",
|
|
45648
|
+
"id"
|
|
45649
|
+
]);
|
|
45650
|
+
var MAX_VALUE = 120;
|
|
45651
|
+
var EVENT_LOG_MAX_PENDING = 1e3;
|
|
45652
|
+
var one = (v) => {
|
|
45653
|
+
const s = stripTerminalControls(String(v)).replace(/[\p{Cc}\p{Cf}\u2028\u2029]/gu, " ").replace(/ +/g, " ").slice(0, MAX_VALUE);
|
|
45654
|
+
return /^[\w.:/@+-]+$/.test(s) ? s : JSON.stringify(s);
|
|
45655
|
+
};
|
|
45656
|
+
function formatEvent(at, event, fields = {}) {
|
|
45657
|
+
const parts = [at.toISOString(), event.replace(/[^\w.-]/g, "_")];
|
|
45658
|
+
for (const [k, v] of Object.entries(fields))
|
|
45659
|
+
if (v !== void 0 && FIELDS.has(k)) parts.push(`${k}=${one(v)}`);
|
|
45660
|
+
return parts.join(" ");
|
|
45661
|
+
}
|
|
45662
|
+
function createEventLog(file2, opts = {}) {
|
|
45663
|
+
const max = opts.maxBytes ?? EVENT_LOG_MAX_BYTES;
|
|
45664
|
+
const now = opts.now ?? (() => /* @__PURE__ */ new Date());
|
|
45665
|
+
let chain = Promise.resolve();
|
|
45666
|
+
let size;
|
|
45667
|
+
const write = async (line) => {
|
|
45668
|
+
try {
|
|
45669
|
+
if (size === void 0) {
|
|
45670
|
+
const dir = dirname8(file2);
|
|
45671
|
+
await mkdir(dir, { recursive: true, mode: 448 });
|
|
45672
|
+
await chmod(dir, 448);
|
|
45673
|
+
size = 0;
|
|
45674
|
+
for (const f of [file2, `${file2}.1`]) {
|
|
45675
|
+
const st = await lstat(f).catch(() => void 0);
|
|
45676
|
+
if (!st) continue;
|
|
45677
|
+
if (st.isSymbolicLink()) throw new Error("symlink");
|
|
45678
|
+
await chmod(f, 384);
|
|
45679
|
+
if (f === file2) size = st.size;
|
|
45680
|
+
}
|
|
45681
|
+
}
|
|
45682
|
+
if (size > 0 && size + Buffer.byteLength(line) > max) {
|
|
45683
|
+
await rename(file2, `${file2}.1`);
|
|
45684
|
+
size = 0;
|
|
45685
|
+
}
|
|
45686
|
+
const fh = await open2(
|
|
45687
|
+
file2,
|
|
45688
|
+
constants5.O_WRONLY | constants5.O_APPEND | constants5.O_CREAT | constants5.O_NOFOLLOW,
|
|
45689
|
+
384
|
|
45690
|
+
);
|
|
45691
|
+
try {
|
|
45692
|
+
await fh.write(line);
|
|
45693
|
+
} finally {
|
|
45694
|
+
await fh.close();
|
|
45695
|
+
}
|
|
45696
|
+
size += Buffer.byteLength(line);
|
|
45697
|
+
} catch {
|
|
45698
|
+
size = void 0;
|
|
45699
|
+
}
|
|
45700
|
+
};
|
|
45701
|
+
const maxPending = opts.maxPending ?? EVENT_LOG_MAX_PENDING;
|
|
45702
|
+
let pending = 0;
|
|
45703
|
+
let dropped = 0;
|
|
45704
|
+
const enqueue = (line) => {
|
|
45705
|
+
pending++;
|
|
45706
|
+
chain = chain.then(() => write(line)).then(() => {
|
|
45707
|
+
pending--;
|
|
45708
|
+
if (pending === 0 && dropped > 0) {
|
|
45709
|
+
const n = dropped;
|
|
45710
|
+
dropped = 0;
|
|
45711
|
+
enqueue(`${formatEvent(now(), "events_dropped", {})} n=${n}
|
|
45712
|
+
`);
|
|
45713
|
+
}
|
|
45714
|
+
});
|
|
45715
|
+
};
|
|
45716
|
+
const log = ((event, fields) => {
|
|
45717
|
+
try {
|
|
45718
|
+
const line = `${formatEvent(now(), event, fields)}
|
|
45719
|
+
`;
|
|
45720
|
+
if (pending >= maxPending) dropped++;
|
|
45721
|
+
else enqueue(line);
|
|
45722
|
+
} catch {
|
|
45723
|
+
}
|
|
45724
|
+
});
|
|
45725
|
+
log.flush = async () => {
|
|
45726
|
+
let c;
|
|
45727
|
+
do {
|
|
45728
|
+
c = chain;
|
|
45729
|
+
await c;
|
|
45730
|
+
} while (c !== chain);
|
|
45731
|
+
};
|
|
45732
|
+
return log;
|
|
45733
|
+
}
|
|
45734
|
+
|
|
45221
45735
|
// ../bus-daemon/src/leads/templates.ts
|
|
45222
45736
|
init_src();
|
|
45223
|
-
import { lstatSync as lstatSync7, readdirSync as
|
|
45737
|
+
import { lstatSync as lstatSync7, readdirSync as readdirSync5, realpathSync as realpathSync6, statSync as statSync7 } from "node:fs";
|
|
45224
45738
|
import { join as join15 } from "node:path";
|
|
45225
45739
|
var leadsDir = (h = home()) => join15(h, "leads");
|
|
45226
45740
|
var leadTemplateFile = (name, h = home()) => join15(leadsDir(h), `${name}.json`);
|
|
@@ -45340,7 +45854,7 @@ function listLeadTemplateNames(h = home()) {
|
|
|
45340
45854
|
if (state !== void 0) return [];
|
|
45341
45855
|
let entries;
|
|
45342
45856
|
try {
|
|
45343
|
-
entries =
|
|
45857
|
+
entries = readdirSync5(dir);
|
|
45344
45858
|
} catch {
|
|
45345
45859
|
return [];
|
|
45346
45860
|
}
|
|
@@ -45360,10 +45874,25 @@ var PENDING_PROOF_MAX = 64;
|
|
|
45360
45874
|
var LATE_WINDOW_MS = 60 * 6e4;
|
|
45361
45875
|
var piLike = (kind4) => kind4 === "pi" || kind4 === "omp" || kind4 === "hermes" || kind4 === "openclaw";
|
|
45362
45876
|
var REF_BOUND = "agent_ref is bound to another live connection";
|
|
45877
|
+
var refusalKey = (reason2) => Object.entries(CODEX_REFUSALS).find(([, text3]) => text3 === reason2)?.[0] ?? "other";
|
|
45878
|
+
var agentFields = (a, reason2) => ({
|
|
45879
|
+
kind: a.kind,
|
|
45880
|
+
name: a.busName,
|
|
45881
|
+
ref: a.ref,
|
|
45882
|
+
ns: a.namespace,
|
|
45883
|
+
pid: a.pid,
|
|
45884
|
+
...reason2 !== void 0 ? { reason: reason2 } : {}
|
|
45885
|
+
});
|
|
45363
45886
|
async function runDaemon(deps2 = {}) {
|
|
45364
45887
|
const cfg = deps2.config ?? readConfig();
|
|
45365
45888
|
const log = deps2.log ?? ((msg) => console.error(`oa-bus: ${msg}`));
|
|
45366
45889
|
const debug = deps2.debug ?? process.env.OA_BUS_DEBUG === "1";
|
|
45890
|
+
const ev = (event, fields) => {
|
|
45891
|
+
try {
|
|
45892
|
+
deps2.events?.(event, fields);
|
|
45893
|
+
} catch {
|
|
45894
|
+
}
|
|
45895
|
+
};
|
|
45367
45896
|
const agents = new AgentTable();
|
|
45368
45897
|
const pending = new Pending(
|
|
45369
45898
|
deps2.pendingTimeoutMs,
|
|
@@ -45543,7 +46072,6 @@ async function runDaemon(deps2 = {}) {
|
|
|
45543
46072
|
ttlMs: cl.syncMs ?? 2e3,
|
|
45544
46073
|
jitter: 0
|
|
45545
46074
|
});
|
|
45546
|
-
const ocComm = oc.comm ?? commOf;
|
|
45547
46075
|
const cx = deps2.codex ?? {};
|
|
45548
46076
|
const linkOnly = /* @__PURE__ */ new WeakSet();
|
|
45549
46077
|
const codexCheck = codexAttestor({
|
|
@@ -45554,18 +46082,35 @@ async function runDaemon(deps2 = {}) {
|
|
|
45554
46082
|
const relockEvery = cx.relockEvery ?? 15;
|
|
45555
46083
|
let codexTicks = 0;
|
|
45556
46084
|
const ocServiceStart = /* @__PURE__ */ new Map();
|
|
46085
|
+
const ocComm = oc.comm ?? commOf;
|
|
45557
46086
|
const ocServiceGone = (ref, pid) => {
|
|
45558
46087
|
if (!ocRunning(pid)) return true;
|
|
45559
46088
|
const comm = ocComm(pid);
|
|
45560
46089
|
if (comm !== null && basename5(comm) !== "opencode") return true;
|
|
45561
46090
|
const start = ocServiceStart.get(ref);
|
|
45562
|
-
|
|
46091
|
+
if (start == null) return false;
|
|
46092
|
+
const now = ocStart(pid);
|
|
46093
|
+
return now !== null && now !== start;
|
|
45563
46094
|
};
|
|
45564
46095
|
const presenceDir = oc.presenceDir ?? opencodePresenceDir();
|
|
45565
46096
|
const openCodeSessions = oc.openSessions ?? (() => openSessions(presenceDir, {
|
|
45566
46097
|
isRunning: ocRunning,
|
|
45567
46098
|
procStartEpoch: (pid, stamp2) => lstartEpoch(ocStart(pid, stamp2))
|
|
45568
46099
|
}));
|
|
46100
|
+
const ocAttached = cachedAttach(
|
|
46101
|
+
oc.attach ?? defaultAttachDeps,
|
|
46102
|
+
deps2.bindingNow
|
|
46103
|
+
);
|
|
46104
|
+
const openCodeStateFor = (service, ref) => oc.openSessions ? oc.openSessions().has(ref) : openState(
|
|
46105
|
+
presenceDir,
|
|
46106
|
+
{
|
|
46107
|
+
isRunning: ocRunning,
|
|
46108
|
+
procStartEpoch: (pid, stamp2) => lstartEpoch(ocStart(pid, stamp2)),
|
|
46109
|
+
accept: ocAttached(service)
|
|
46110
|
+
},
|
|
46111
|
+
ref
|
|
46112
|
+
);
|
|
46113
|
+
const openCodeSessionsFor = (service, ref) => openCodeStateFor(service, ref) === true ? /* @__PURE__ */ new Set([ref]) : /* @__PURE__ */ new Set();
|
|
45569
46114
|
const ocSpawn = oc.spawn ?? execSpawn(2e4);
|
|
45570
46115
|
let promptIdSupported = false;
|
|
45571
46116
|
const opencode = new OpenCodeTransport({
|
|
@@ -45587,7 +46132,8 @@ async function runDaemon(deps2 = {}) {
|
|
|
45587
46132
|
home: codexIndexHome,
|
|
45588
46133
|
wakes: cx.wakes ?? codexHostWakes,
|
|
45589
46134
|
queued: new HeldStore(cx.queuedFile ?? join16(home(), "codex-queued.json")),
|
|
45590
|
-
log
|
|
46135
|
+
log,
|
|
46136
|
+
event: ev
|
|
45591
46137
|
});
|
|
45592
46138
|
const pi = new PiTransport({
|
|
45593
46139
|
push: (ref, frame) => {
|
|
@@ -45868,29 +46414,26 @@ async function runDaemon(deps2 = {}) {
|
|
|
45868
46414
|
seenAt.set(s.ref, ++seenSeq);
|
|
45869
46415
|
const old = prev ? void 0 : clearedFrom(s.ref, s.pid, s.procStart, liveRefs);
|
|
45870
46416
|
if (old) takenOver.add(old.ref);
|
|
45871
|
-
|
|
45872
|
-
|
|
45873
|
-
|
|
45874
|
-
|
|
45875
|
-
|
|
45876
|
-
|
|
45877
|
-
|
|
45878
|
-
|
|
45879
|
-
|
|
45880
|
-
|
|
45881
|
-
|
|
45882
|
-
|
|
45883
|
-
|
|
45884
|
-
|
|
45885
|
-
|
|
45886
|
-
|
|
45887
|
-
|
|
45888
|
-
|
|
45889
|
-
);
|
|
45890
|
-
|
|
45891
|
-
const rec = agents.byRef(s.ref);
|
|
45892
|
-
if (rec) seedLinks(rec);
|
|
45893
|
-
}
|
|
46417
|
+
const rec = agents.up({
|
|
46418
|
+
...old ? { replaces: handoverOf(old) } : {},
|
|
46419
|
+
ref: s.ref,
|
|
46420
|
+
kind: "claude-code",
|
|
46421
|
+
proposedName: old?.busName ?? s.name,
|
|
46422
|
+
busName: prev?.busName ?? old?.busName ?? s.name,
|
|
46423
|
+
namespace: ns.namespace,
|
|
46424
|
+
namespaceSource: ns.source,
|
|
46425
|
+
global: ns.global,
|
|
46426
|
+
pid: s.pid,
|
|
46427
|
+
procStart: s.procStart,
|
|
46428
|
+
// The same process keeps its proof across /clear; agent_ok rebinds it.
|
|
46429
|
+
...old?.linkHashes !== void 0 ? { linkHashes: old.linkHashes } : {},
|
|
46430
|
+
sessionName: s.name,
|
|
46431
|
+
cwd: s.cwd,
|
|
46432
|
+
live: true
|
|
46433
|
+
});
|
|
46434
|
+
ev("agent_join", { ...agentFields(rec), state: "synced" });
|
|
46435
|
+
announceUp(rec);
|
|
46436
|
+
seedLinks(rec);
|
|
45894
46437
|
void claude.revive(s.ref);
|
|
45895
46438
|
tellOwed(s.ref);
|
|
45896
46439
|
}
|
|
@@ -45900,6 +46443,7 @@ async function runDaemon(deps2 = {}) {
|
|
|
45900
46443
|
if (a.kind !== "claude-code" || !a.live || liveRefs.has(a.ref)) continue;
|
|
45901
46444
|
a.live = false;
|
|
45902
46445
|
closed = true;
|
|
46446
|
+
ev("agent_leave", agentFields(a, "session_gone"));
|
|
45903
46447
|
void claude.drop(a.ref);
|
|
45904
46448
|
}
|
|
45905
46449
|
persistLinks();
|
|
@@ -45907,20 +46451,21 @@ async function runDaemon(deps2 = {}) {
|
|
|
45907
46451
|
};
|
|
45908
46452
|
let openBefore = /* @__PURE__ */ new Set();
|
|
45909
46453
|
const syncOpenCode = () => {
|
|
45910
|
-
const
|
|
46454
|
+
const open3 = openCodeSessions();
|
|
45911
46455
|
let closed = false;
|
|
45912
46456
|
for (const a of agents.all()) {
|
|
45913
46457
|
if (a.kind !== "opencode") continue;
|
|
45914
|
-
if (a.live && !
|
|
46458
|
+
if (a.live && !open3.has(a.ref)) {
|
|
45915
46459
|
a.live = false;
|
|
45916
46460
|
closed = true;
|
|
45917
|
-
|
|
46461
|
+
ev("agent_leave", agentFields(a, "not_listed"));
|
|
46462
|
+
} else if (!a.live && open3.has(a.ref) && !openBefore.has(a.ref)) {
|
|
45918
46463
|
a.live = true;
|
|
45919
46464
|
announceUp(a);
|
|
45920
46465
|
tellOwed(a.ref);
|
|
45921
46466
|
}
|
|
45922
46467
|
}
|
|
45923
|
-
openBefore =
|
|
46468
|
+
openBefore = open3;
|
|
45924
46469
|
if (closed) announceSessions();
|
|
45925
46470
|
};
|
|
45926
46471
|
const delivery = createDeliver({
|
|
@@ -45936,7 +46481,10 @@ async function runDaemon(deps2 = {}) {
|
|
|
45936
46481
|
codex: (agent, mail) => codex.deliver(agent, mail),
|
|
45937
46482
|
...deps2.transports
|
|
45938
46483
|
},
|
|
45939
|
-
onClosed:
|
|
46484
|
+
onClosed: (a) => {
|
|
46485
|
+
ev("agent_leave", agentFields(a, "delivery_closed"));
|
|
46486
|
+
announceSessions();
|
|
46487
|
+
},
|
|
45940
46488
|
log
|
|
45941
46489
|
});
|
|
45942
46490
|
let hubEver = false;
|
|
@@ -45948,6 +46496,7 @@ async function runDaemon(deps2 = {}) {
|
|
|
45948
46496
|
let hubLinkArg = false;
|
|
45949
46497
|
let hubHelloed = false;
|
|
45950
46498
|
let hubVersion;
|
|
46499
|
+
let hubWaiting = false;
|
|
45951
46500
|
const hub = new HubConnection({
|
|
45952
46501
|
url: `${cfg.hub.replace(/^http/, "ws").replace(/\/+$/, "")}${BUS_ROUTES.connect}`,
|
|
45953
46502
|
token: cfg.machine_token,
|
|
@@ -46064,6 +46613,7 @@ async function runDaemon(deps2 = {}) {
|
|
|
46064
46613
|
hubIds = frame.caps?.includes(BUS_CAPS.ids) ?? false;
|
|
46065
46614
|
hubMailbox = frame.caps?.includes(BUS_CAPS.mailbox) ?? false;
|
|
46066
46615
|
hubFollow = frame.caps?.includes(BUS_CAPS.follow) ?? false;
|
|
46616
|
+
hubWaiting = frame.caps?.includes(BUS_CAPS.waiting) ?? false;
|
|
46067
46617
|
hubLink = frame.caps?.includes(BUS_CAPS.link) ?? false;
|
|
46068
46618
|
hubLinkArg = frame.caps?.includes(BUS_CAPS.linkArg) ?? false;
|
|
46069
46619
|
hubHelloed = true;
|
|
@@ -46092,7 +46642,7 @@ async function runDaemon(deps2 = {}) {
|
|
|
46092
46642
|
log(`this machine was revoked; run \`${BUS_CMD} install\``);
|
|
46093
46643
|
process.exitCode = 1;
|
|
46094
46644
|
try {
|
|
46095
|
-
|
|
46645
|
+
writeFileSync8(
|
|
46096
46646
|
deps2.revokedFile ?? join16(home(), "revoked"),
|
|
46097
46647
|
revokedMarker(cfg.machine_token),
|
|
46098
46648
|
{ mode: 384 }
|
|
@@ -46108,10 +46658,12 @@ async function runDaemon(deps2 = {}) {
|
|
|
46108
46658
|
onOpen: () => {
|
|
46109
46659
|
hubEver = true;
|
|
46110
46660
|
hubDroppedAt = void 0;
|
|
46661
|
+
ev("hub_connect");
|
|
46111
46662
|
for (const rec of agents.all()) if (rec.live) announceUp(rec);
|
|
46112
46663
|
},
|
|
46113
46664
|
onClose: () => {
|
|
46114
46665
|
if (hubEver) hubDroppedAt ??= Date.now();
|
|
46666
|
+
ev("hub_disconnect");
|
|
46115
46667
|
upIds.clear();
|
|
46116
46668
|
renameIds.clear();
|
|
46117
46669
|
hubVersion = void 0;
|
|
@@ -46312,13 +46864,20 @@ async function runDaemon(deps2 = {}) {
|
|
|
46312
46864
|
const checked3 = (deps2.attest ?? ((h) => h.kind === "codex" ? codexCheck.attest(h) : attest(h, {
|
|
46313
46865
|
// The dir liveness reads: a session is attested where it is seen.
|
|
46314
46866
|
sessionsDir: claudeSessions.dir,
|
|
46315
|
-
openSessions:
|
|
46867
|
+
openSessions: openCodeSessionsFor,
|
|
46316
46868
|
ancestors: oc.ancestors,
|
|
46317
46869
|
comm: oc.comm,
|
|
46318
46870
|
codex: codexCheck
|
|
46319
46871
|
})))(hello);
|
|
46320
46872
|
const admit = (check2) => {
|
|
46321
|
-
if (!check2.ok)
|
|
46873
|
+
if (!check2.ok) {
|
|
46874
|
+
ev(hello.kind === "codex" ? "codex_refused" : "agent_refused", {
|
|
46875
|
+
kind: hello.kind,
|
|
46876
|
+
ref: hello.agent_ref,
|
|
46877
|
+
reason: refusalKey(check2.reason)
|
|
46878
|
+
});
|
|
46879
|
+
return { error: check2.reason };
|
|
46880
|
+
}
|
|
46322
46881
|
const pid = check2.pid ?? hello.pid;
|
|
46323
46882
|
if (check2.linkOnly) linkOnly.add(hello);
|
|
46324
46883
|
let bindToken;
|
|
@@ -46348,7 +46907,7 @@ async function runDaemon(deps2 = {}) {
|
|
|
46348
46907
|
if (live.some((s) => s.pid === pid) && !live.some((s) => s.pid === prev.pid))
|
|
46349
46908
|
prev.pid = pid;
|
|
46350
46909
|
}
|
|
46351
|
-
if (prev?.live && prev.kind === "opencode" && hello.kind === "opencode" && prev.pid !== pid && ocServiceGone(prev.ref, prev.pid)) {
|
|
46910
|
+
if (prev?.live && prev.kind === "opencode" && hello.kind === "opencode" && prev.pid !== pid && (ocServiceGone(prev.ref, prev.pid) || openCodeStateFor(prev.pid, prev.ref) === false)) {
|
|
46352
46911
|
prev.pid = pid;
|
|
46353
46912
|
ocServiceStart.set(prev.ref, ocStart(pid));
|
|
46354
46913
|
}
|
|
@@ -46419,8 +46978,15 @@ async function runDaemon(deps2 = {}) {
|
|
|
46419
46978
|
cwd,
|
|
46420
46979
|
live: true
|
|
46421
46980
|
});
|
|
46981
|
+
ev(rec.kind === "codex" ? "codex_admitted" : "agent_join", {
|
|
46982
|
+
...agentFields(rec),
|
|
46983
|
+
...prev ? { state: "revived" } : {}
|
|
46984
|
+
});
|
|
46422
46985
|
if (rec.kind === "opencode") ocServiceStart.set(rec.ref, ocStart(pid));
|
|
46423
|
-
if (rec.kind === "codex")
|
|
46986
|
+
if (rec.kind === "codex") {
|
|
46987
|
+
persistCodex();
|
|
46988
|
+
trackAway();
|
|
46989
|
+
}
|
|
46424
46990
|
if (rec.kind === "claude-code") {
|
|
46425
46991
|
seedLinks(rec);
|
|
46426
46992
|
void claude.revive(rec.ref);
|
|
@@ -46552,6 +47118,7 @@ async function runDaemon(deps2 = {}) {
|
|
|
46552
47118
|
const rec = agents.byRef(hello.agent_ref);
|
|
46553
47119
|
if (!rec) return;
|
|
46554
47120
|
rec.live = false;
|
|
47121
|
+
ev("agent_leave", agentFields(rec, "link_closed"));
|
|
46555
47122
|
announceSessions();
|
|
46556
47123
|
}
|
|
46557
47124
|
}).catch(socketInUse);
|
|
@@ -46636,10 +47203,186 @@ async function runDaemon(deps2 = {}) {
|
|
|
46636
47203
|
if (debug) log(`restored codex thread ${r.ref.slice(0, 8)} pid ${r.pid}`);
|
|
46637
47204
|
}
|
|
46638
47205
|
};
|
|
47206
|
+
const awayFile = cx.awayFile ?? join16(home(), "codex-away.json");
|
|
47207
|
+
const awayNow = deps2.bindingNow ?? Date.now;
|
|
47208
|
+
const HOUR = 36e5;
|
|
47209
|
+
const awayRows = new Map(
|
|
47210
|
+
readCodexAway(awayFile, awayNow()).map((r) => [r.ref, r])
|
|
47211
|
+
);
|
|
47212
|
+
let awaySaved;
|
|
47213
|
+
const trackAway = () => {
|
|
47214
|
+
const now = awayNow();
|
|
47215
|
+
for (const a of agents.all()) {
|
|
47216
|
+
if (a.kind !== "codex") continue;
|
|
47217
|
+
const prev = awayRows.get(a.ref);
|
|
47218
|
+
const lastLive = a.live ? Math.floor(now / HOUR) * HOUR : prev?.lastLive ?? Math.floor(now / HOUR) * HOUR;
|
|
47219
|
+
if (!WireNamespaceSchema.safeParse(a.namespace).success || !AgentRefSchema.safeParse(a.ref).success)
|
|
47220
|
+
continue;
|
|
47221
|
+
awayRows.set(a.ref, {
|
|
47222
|
+
ref: a.ref,
|
|
47223
|
+
name: a.busName,
|
|
47224
|
+
namespace: a.namespace,
|
|
47225
|
+
lastLive
|
|
47226
|
+
});
|
|
47227
|
+
}
|
|
47228
|
+
const kept = trimAway([...awayRows.values()], now);
|
|
47229
|
+
awayRows.clear();
|
|
47230
|
+
for (const r of kept) awayRows.set(r.ref, r);
|
|
47231
|
+
const text3 = JSON.stringify(kept);
|
|
47232
|
+
if (awaySaved === void 0 ? kept.length === 0 : text3 === awaySaved)
|
|
47233
|
+
return;
|
|
47234
|
+
try {
|
|
47235
|
+
writeCodexAway(awayFile, kept);
|
|
47236
|
+
awaySaved = text3;
|
|
47237
|
+
} catch (e) {
|
|
47238
|
+
log(
|
|
47239
|
+
`could not save the Codex away threads: ${e instanceof Error ? e.message : String(e)}`
|
|
47240
|
+
);
|
|
47241
|
+
}
|
|
47242
|
+
};
|
|
47243
|
+
const woken = new HeldStore(
|
|
47244
|
+
cx.wokenFile ?? join16(home(), "codex-woken.json"),
|
|
47245
|
+
{ ttlMs: 7 * 24 * HOUR }
|
|
47246
|
+
);
|
|
47247
|
+
const wakeLogged = /* @__PURE__ */ new Set();
|
|
47248
|
+
const wakeAsked = /* @__PURE__ */ new Map();
|
|
47249
|
+
let waking = false;
|
|
47250
|
+
let wakeCheckedAt;
|
|
47251
|
+
const wakeSent = /* @__PURE__ */ new Map();
|
|
47252
|
+
const wakeWaiting = /* @__PURE__ */ new Map();
|
|
47253
|
+
const WAKES_MAX = 3;
|
|
47254
|
+
const wakeAway = async () => {
|
|
47255
|
+
if (waking) return;
|
|
47256
|
+
waking = true;
|
|
47257
|
+
try {
|
|
47258
|
+
const now = awayNow();
|
|
47259
|
+
for (const [k, w] of wakeSent) {
|
|
47260
|
+
if (agents.byRef(w.ref)?.live) wakeSent.delete(k);
|
|
47261
|
+
else if (!w.logged && now - w.at >= (cx.wakeAnswerMs ?? 3e5)) {
|
|
47262
|
+
w.logged = true;
|
|
47263
|
+
log(`codex wake ${w.ref.slice(0, 8)} wake_unanswered`);
|
|
47264
|
+
}
|
|
47265
|
+
}
|
|
47266
|
+
const rows = [...awayRows.values()].filter(
|
|
47267
|
+
(r) => now - r.lastLive <= AWAY_IDLE_MS && !agents.byRef(r.ref)?.live
|
|
47268
|
+
);
|
|
47269
|
+
const away = new Set(rows.map((r) => r.ref));
|
|
47270
|
+
for (const [k, w] of wakeSent) if (!away.has(w.ref)) wakeSent.delete(k);
|
|
47271
|
+
for (const m of [wakeAsked, wakeWaiting])
|
|
47272
|
+
for (const k of m.keys())
|
|
47273
|
+
if (!away.has(k.split(":")[1] ?? "")) m.delete(k);
|
|
47274
|
+
if (!rows.length) return;
|
|
47275
|
+
if (wakeCheckedAt !== void 0 && now - wakeCheckedAt < (cx.wakeCheckMs ?? 3e5))
|
|
47276
|
+
return;
|
|
47277
|
+
wakeCheckedAt = now;
|
|
47278
|
+
const held2 = codexCheck.holders(rows.map((r) => r.ref));
|
|
47279
|
+
if (!held2) return;
|
|
47280
|
+
const once2 = (key2, msg) => {
|
|
47281
|
+
if (wakeLogged.has(key2 + msg)) return;
|
|
47282
|
+
wakeLogged.add(key2 + msg);
|
|
47283
|
+
if (wakeLogged.size > 500) wakeLogged.clear();
|
|
47284
|
+
log(msg);
|
|
47285
|
+
};
|
|
47286
|
+
for (const r of rows) {
|
|
47287
|
+
const h = held2.get(r.ref);
|
|
47288
|
+
if (!h) continue;
|
|
47289
|
+
const key2 = `wake:${r.ref}:${h.pid}:${h.start.replace(/\s+/g, "_")}`;
|
|
47290
|
+
const who = `codex wake ${r.ref.slice(0, 8)} pid ${h.pid}`;
|
|
47291
|
+
let n = 1;
|
|
47292
|
+
while (n <= WAKES_MAX && woken.has(`${key2}#${n}`)) n++;
|
|
47293
|
+
if (n > WAKES_MAX) continue;
|
|
47294
|
+
const againAfter = n > 1 ? woken.at(`${key2}#${n - 1}`) ?? now : void 0;
|
|
47295
|
+
if (againAfter !== void 0) {
|
|
47296
|
+
if (now - againAfter < (cx.wakeAgainMs ?? 36e5) || !wakeWaiting.has(key2))
|
|
47297
|
+
continue;
|
|
47298
|
+
}
|
|
47299
|
+
const asker = agents.all().find((a) => a.live);
|
|
47300
|
+
if (!asker || !hub.open || hubVersion === void 0) {
|
|
47301
|
+
once2(key2, `${who} skipped: no live agent to ask the hub`);
|
|
47302
|
+
continue;
|
|
47303
|
+
}
|
|
47304
|
+
if (!hubWaiting) {
|
|
47305
|
+
once2(key2, `${who} skipped: the hub does not report waiting mail`);
|
|
47306
|
+
continue;
|
|
47307
|
+
}
|
|
47308
|
+
const last = wakeAsked.get(key2);
|
|
47309
|
+
if (last !== void 0 && now - last < (cx.wakeAskMs ?? 3e5))
|
|
47310
|
+
continue;
|
|
47311
|
+
wakeAsked.set(key2, now);
|
|
47312
|
+
const roster2 = await hubRoster(asker.ref);
|
|
47313
|
+
if (!roster2) {
|
|
47314
|
+
once2(key2 + now, `${who} skipped: the hub did not answer`);
|
|
47315
|
+
continue;
|
|
47316
|
+
}
|
|
47317
|
+
const row = roster2.find(
|
|
47318
|
+
(a) => a.state === "away" && a.name === r.name && a.namespace === r.namespace && (a.machine_label === void 0 || a.machine_label === cfg.label)
|
|
47319
|
+
);
|
|
47320
|
+
if (!row?.waiting) {
|
|
47321
|
+
once2(key2, `${who} skipped: no mail waiting`);
|
|
47322
|
+
continue;
|
|
47323
|
+
}
|
|
47324
|
+
if (n > 1 && row.waiting === wakeWaiting.get(key2) && row.waiting < 100) {
|
|
47325
|
+
once2(
|
|
47326
|
+
key2 + n,
|
|
47327
|
+
`${who} skipped: the mail count has not changed since the last wake`
|
|
47328
|
+
);
|
|
47329
|
+
continue;
|
|
47330
|
+
}
|
|
47331
|
+
if (!await codex.canWake(h.pid)) {
|
|
47332
|
+
once2(
|
|
47333
|
+
key2,
|
|
47334
|
+
`${who} skipped: the process does not wake on a queued message`
|
|
47335
|
+
);
|
|
47336
|
+
continue;
|
|
47337
|
+
}
|
|
47338
|
+
try {
|
|
47339
|
+
woken.add(`${key2}#${n}`);
|
|
47340
|
+
} catch (e) {
|
|
47341
|
+
once2(
|
|
47342
|
+
key2,
|
|
47343
|
+
`${who} skipped: could not record the wake (${e instanceof Error ? e.message : String(e)})`
|
|
47344
|
+
);
|
|
47345
|
+
continue;
|
|
47346
|
+
}
|
|
47347
|
+
const res = await codex.wake(
|
|
47348
|
+
r.ref,
|
|
47349
|
+
h.pid,
|
|
47350
|
+
`${key2}#${n}`,
|
|
47351
|
+
CODEX_WAKE_TEXT
|
|
47352
|
+
);
|
|
47353
|
+
wakeWaiting.set(key2, row.waiting);
|
|
47354
|
+
ev("codex_wake", { thread: r.ref, state: res });
|
|
47355
|
+
if (res === "failed" || res === "maybe")
|
|
47356
|
+
try {
|
|
47357
|
+
for (let m = n + 1; m <= WAKES_MAX; m++) woken.add(`${key2}#${m}`);
|
|
47358
|
+
} catch {
|
|
47359
|
+
}
|
|
47360
|
+
if (res === "sent")
|
|
47361
|
+
wakeSent.set(key2, { ref: r.ref, at: now, logged: false });
|
|
47362
|
+
log(
|
|
47363
|
+
res === "sent" ? `${who} sent` : res === "no_host" ? `${who} skipped: the process does not wake on a queued message` : `${who} failed: ${res}`
|
|
47364
|
+
);
|
|
47365
|
+
}
|
|
47366
|
+
} catch (e) {
|
|
47367
|
+
log(`codex wake failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
47368
|
+
} finally {
|
|
47369
|
+
waking = false;
|
|
47370
|
+
}
|
|
47371
|
+
};
|
|
46639
47372
|
const syncCodex = () => {
|
|
47373
|
+
try {
|
|
47374
|
+
syncCodexInner();
|
|
47375
|
+
} finally {
|
|
47376
|
+
trackAway();
|
|
47377
|
+
if (!deps2.attest && relockTickNow) void wakeAway();
|
|
47378
|
+
}
|
|
47379
|
+
};
|
|
47380
|
+
let relockTickNow = false;
|
|
47381
|
+
const syncCodexInner = () => {
|
|
46640
47382
|
renameCodexThreads();
|
|
46641
47383
|
codexTicks = (codexTicks + 1) % relockEvery;
|
|
46642
47384
|
const relockTick = codexTicks === 0;
|
|
47385
|
+
relockTickNow = relockTick;
|
|
46643
47386
|
const all = agents.all().filter((a) => a.kind === "codex" && (a.live || relockTick)).map((a) => ({ thread: a.ref, pid: a.pid, live: a.live }));
|
|
46644
47387
|
if (!all.length || deps2.attest) return persistCodex();
|
|
46645
47388
|
const still = codexCheck.sweep(all, relockTick);
|
|
@@ -46653,6 +47396,7 @@ async function runDaemon(deps2 = {}) {
|
|
|
46653
47396
|
announceUp(a);
|
|
46654
47397
|
tellOwed(a.ref);
|
|
46655
47398
|
} else changed = true;
|
|
47399
|
+
ev("codex_liveness", { thread, state: live ? "not_live" : "live" });
|
|
46656
47400
|
log(`codex thread ${thread} ${live ? "not live" : "live again"}`);
|
|
46657
47401
|
}
|
|
46658
47402
|
if (changed) announceSessions();
|
|
@@ -46690,11 +47434,13 @@ async function runDaemon(deps2 = {}) {
|
|
|
46690
47434
|
`OpenCode ${ocVersion ?? "(version unknown)"} is below ${MIN_PROMPT_ID_VERSION}: a timed-out prompt is never retried`
|
|
46691
47435
|
);
|
|
46692
47436
|
hub.start();
|
|
47437
|
+
ev("daemon_start", { version: deps2.version, pid: process.pid });
|
|
46693
47438
|
return {
|
|
46694
47439
|
hub,
|
|
46695
47440
|
agents,
|
|
46696
47441
|
bindings: { count: () => bindings.size, sweep: sweepBindings },
|
|
46697
47442
|
stop: async () => {
|
|
47443
|
+
ev("daemon_stop", { pid: process.pid });
|
|
46698
47444
|
clearInterval(socketWatch);
|
|
46699
47445
|
clearInterval(watcher);
|
|
46700
47446
|
clearInterval(retry);
|
|
@@ -46707,14 +47453,16 @@ async function runDaemon(deps2 = {}) {
|
|
|
46707
47453
|
pending.failAll("hub_unavailable", "the daemon is stopping");
|
|
46708
47454
|
sent.flush();
|
|
46709
47455
|
await Promise.all([server4.close(), claude.close()]);
|
|
47456
|
+
await deps2.events?.flush?.().catch(() => {
|
|
47457
|
+
});
|
|
46710
47458
|
}
|
|
46711
47459
|
};
|
|
46712
47460
|
}
|
|
46713
47461
|
|
|
46714
47462
|
// src/context.ts
|
|
46715
47463
|
init_src3();
|
|
46716
|
-
import { execFileSync as
|
|
46717
|
-
import { closeSync as closeSync6, openSync as openSync6, readFileSync as
|
|
47464
|
+
import { execFileSync as execFileSync6, spawn as spawn2 } from "node:child_process";
|
|
47465
|
+
import { closeSync as closeSync6, openSync as openSync6, readFileSync as readFileSync15 } from "node:fs";
|
|
46718
47466
|
import { homedir as homedir3, userInfo as userInfo2 } from "node:os";
|
|
46719
47467
|
import { createInterface as createInterface2 } from "node:readline";
|
|
46720
47468
|
init_src2();
|
|
@@ -46780,21 +47528,21 @@ var realDeps = {
|
|
|
46780
47528
|
init_src();
|
|
46781
47529
|
import { createHash as createHash5 } from "node:crypto";
|
|
46782
47530
|
import {
|
|
46783
|
-
chmodSync as
|
|
47531
|
+
chmodSync as chmodSync12,
|
|
46784
47532
|
cpSync,
|
|
46785
47533
|
existsSync as existsSync4,
|
|
46786
47534
|
lstatSync as lstatSync10,
|
|
46787
47535
|
mkdirSync as mkdirSync9,
|
|
46788
47536
|
realpathSync as realpathSync8,
|
|
46789
|
-
renameSync as
|
|
47537
|
+
renameSync as renameSync12,
|
|
46790
47538
|
rmSync as rmSync6,
|
|
46791
|
-
writeFileSync as
|
|
47539
|
+
writeFileSync as writeFileSync10
|
|
46792
47540
|
} from "node:fs";
|
|
46793
|
-
import { basename as basename6, dirname as
|
|
47541
|
+
import { basename as basename6, dirname as dirname10, isAbsolute as isAbsolute8, join as join18, resolve as resolve5 } from "node:path";
|
|
46794
47542
|
import { fileURLToPath } from "node:url";
|
|
46795
47543
|
|
|
46796
47544
|
// src/steps/codex.ts
|
|
46797
|
-
import { lstatSync as lstatSync9, readFileSync as
|
|
47545
|
+
import { lstatSync as lstatSync9, readFileSync as readFileSync13 } from "node:fs";
|
|
46798
47546
|
import { join as join17, resolve as resolve4 } from "node:path";
|
|
46799
47547
|
|
|
46800
47548
|
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/error.js
|
|
@@ -47576,7 +48324,7 @@ var findCodexBin = (o) => resolveCodexBin({ ...o, app: o.app ?? null })?.path;
|
|
|
47576
48324
|
function readToml(path) {
|
|
47577
48325
|
let text3;
|
|
47578
48326
|
try {
|
|
47579
|
-
text3 =
|
|
48327
|
+
text3 = readFileSync13(path, "utf8");
|
|
47580
48328
|
} catch (e) {
|
|
47581
48329
|
if (e.code === "ENOENT")
|
|
47582
48330
|
return { text: "", doc: {} };
|
|
@@ -47641,24 +48389,24 @@ function renderEntry(e) {
|
|
|
47641
48389
|
];
|
|
47642
48390
|
}
|
|
47643
48391
|
function scan(lines) {
|
|
47644
|
-
let
|
|
48392
|
+
let open3;
|
|
47645
48393
|
return lines.map((line) => {
|
|
47646
|
-
const startsInString =
|
|
48394
|
+
const startsInString = open3 !== void 0;
|
|
47647
48395
|
let i = 0;
|
|
47648
48396
|
let code2 = false;
|
|
47649
48397
|
while (i < line.length) {
|
|
47650
|
-
if (
|
|
47651
|
-
if (
|
|
48398
|
+
if (open3) {
|
|
48399
|
+
if (open3 === '"""' && line[i] === "\\") {
|
|
47652
48400
|
i += 2;
|
|
47653
48401
|
continue;
|
|
47654
48402
|
}
|
|
47655
|
-
if (!line.startsWith(
|
|
48403
|
+
if (!line.startsWith(open3, i)) {
|
|
47656
48404
|
i++;
|
|
47657
48405
|
continue;
|
|
47658
48406
|
}
|
|
47659
48407
|
i += 3;
|
|
47660
|
-
while (line[i] ===
|
|
47661
|
-
|
|
48408
|
+
while (line[i] === open3[0]) i++;
|
|
48409
|
+
open3 = void 0;
|
|
47662
48410
|
continue;
|
|
47663
48411
|
}
|
|
47664
48412
|
const c = line[i];
|
|
@@ -47667,7 +48415,7 @@ function scan(lines) {
|
|
|
47667
48415
|
code2 = true;
|
|
47668
48416
|
const triple = line.startsWith(c.repeat(3), i);
|
|
47669
48417
|
if (triple) {
|
|
47670
|
-
|
|
48418
|
+
open3 = c === '"' ? '"""' : "'''";
|
|
47671
48419
|
i += 3;
|
|
47672
48420
|
continue;
|
|
47673
48421
|
}
|
|
@@ -47842,16 +48590,16 @@ async function readCodexVersion(o) {
|
|
|
47842
48590
|
|
|
47843
48591
|
// src/steps/step.ts
|
|
47844
48592
|
import {
|
|
47845
|
-
chmodSync as
|
|
48593
|
+
chmodSync as chmodSync11,
|
|
47846
48594
|
mkdirSync as mkdirSync8,
|
|
47847
|
-
readFileSync as
|
|
47848
|
-
renameSync as
|
|
47849
|
-
writeFileSync as
|
|
48595
|
+
readFileSync as readFileSync14,
|
|
48596
|
+
renameSync as renameSync11,
|
|
48597
|
+
writeFileSync as writeFileSync9
|
|
47850
48598
|
} from "node:fs";
|
|
47851
|
-
import { dirname as
|
|
48599
|
+
import { dirname as dirname9 } from "node:path";
|
|
47852
48600
|
function readInstallFile(path) {
|
|
47853
48601
|
try {
|
|
47854
|
-
const v = JSON.parse(
|
|
48602
|
+
const v = JSON.parse(readFileSync14(path, "utf8"));
|
|
47855
48603
|
if (typeof v === "object" && v !== null && !Array.isArray(v))
|
|
47856
48604
|
return v;
|
|
47857
48605
|
} catch {
|
|
@@ -47860,12 +48608,12 @@ function readInstallFile(path) {
|
|
|
47860
48608
|
}
|
|
47861
48609
|
function updateInstallFile(path, patch) {
|
|
47862
48610
|
const next = { ...readInstallFile(path), ...patch };
|
|
47863
|
-
mkdirSync8(
|
|
48611
|
+
mkdirSync8(dirname9(path), { recursive: true, mode: 448 });
|
|
47864
48612
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
47865
|
-
|
|
48613
|
+
writeFileSync9(tmp, `${JSON.stringify(next, null, 2)}
|
|
47866
48614
|
`, { mode: 384 });
|
|
47867
|
-
|
|
47868
|
-
|
|
48615
|
+
chmodSync11(tmp, 384);
|
|
48616
|
+
renameSync11(tmp, path);
|
|
47869
48617
|
}
|
|
47870
48618
|
async function runSteps(steps, ctx, record7) {
|
|
47871
48619
|
for (const step2 of steps) {
|
|
@@ -47961,7 +48709,7 @@ function cliSource() {
|
|
|
47961
48709
|
jiti: import.meta.resolve("jiti")
|
|
47962
48710
|
} : { kind: "bundle", file: here };
|
|
47963
48711
|
}
|
|
47964
|
-
var entryName = (src) => src.kind === "bundle" ? join18(basename6(
|
|
48712
|
+
var entryName = (src) => src.kind === "bundle" ? join18(basename6(dirname10(src.file)), basename6(src.file)) : "oa-bus.js";
|
|
47965
48713
|
var shim = (src) => `// Written by oa-bus install: runs the sources it was installed from.
|
|
47966
48714
|
import { createJiti } from ${JSON.stringify(src.jiti)};
|
|
47967
48715
|
|
|
@@ -48021,24 +48769,24 @@ function installCli(home2, src, node2) {
|
|
|
48021
48769
|
const bin = join18(home2, "bin");
|
|
48022
48770
|
const tmp = `${bin}.${process.pid}.tmp`;
|
|
48023
48771
|
mkdirSync9(home2, { recursive: true, mode: 448 });
|
|
48024
|
-
|
|
48772
|
+
chmodSync12(home2, 448);
|
|
48025
48773
|
rmSync6(tmp, { recursive: true, force: true });
|
|
48026
48774
|
mkdirSync9(tmp);
|
|
48027
48775
|
if (src.kind === "bundle") {
|
|
48028
|
-
const pkg =
|
|
48776
|
+
const pkg = dirname10(dirname10(src.file));
|
|
48029
48777
|
for (const name of ["dist", "assets", "package.json"])
|
|
48030
48778
|
if (existsSync4(join18(pkg, name)))
|
|
48031
48779
|
cpSync(join18(pkg, name), join18(tmp, name), { recursive: true });
|
|
48032
|
-
} else
|
|
48033
|
-
|
|
48780
|
+
} else writeFileSync10(join18(tmp, entryName(src)), shim(src));
|
|
48781
|
+
chmodSync12(tmp, 448);
|
|
48034
48782
|
if (node2 !== void 0) {
|
|
48035
|
-
|
|
48036
|
-
|
|
48783
|
+
writeFileSync10(join18(tmp, "node"), launcherText(node2), { mode: 448 });
|
|
48784
|
+
chmodSync12(join18(tmp, "node"), 448);
|
|
48037
48785
|
}
|
|
48038
48786
|
if (!existsSync4(join18(tmp, "package.json")))
|
|
48039
|
-
|
|
48787
|
+
writeFileSync10(join18(tmp, "package.json"), '{ "type": "module" }\n');
|
|
48040
48788
|
rmSync6(bin, { recursive: true, force: true });
|
|
48041
|
-
|
|
48789
|
+
renameSync12(tmp, bin);
|
|
48042
48790
|
return join18(bin, entryName(src));
|
|
48043
48791
|
}
|
|
48044
48792
|
var present = (path) => {
|
|
@@ -48050,11 +48798,11 @@ var present = (path) => {
|
|
|
48050
48798
|
}
|
|
48051
48799
|
};
|
|
48052
48800
|
function writeReplacing(path, text3) {
|
|
48053
|
-
mkdirSync9(
|
|
48801
|
+
mkdirSync9(dirname10(path), { recursive: true });
|
|
48054
48802
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
48055
48803
|
try {
|
|
48056
|
-
|
|
48057
|
-
|
|
48804
|
+
writeFileSync10(tmp, text3, { mode: 420 });
|
|
48805
|
+
renameSync12(tmp, path);
|
|
48058
48806
|
} catch (e) {
|
|
48059
48807
|
rmSync6(tmp, { force: true });
|
|
48060
48808
|
throw e;
|
|
@@ -48065,7 +48813,7 @@ var real = (path) => {
|
|
|
48065
48813
|
try {
|
|
48066
48814
|
return realpathSync8(abs);
|
|
48067
48815
|
} catch {
|
|
48068
|
-
const parent =
|
|
48816
|
+
const parent = dirname10(abs);
|
|
48069
48817
|
return parent === abs ? abs : join18(real(parent), basename6(abs));
|
|
48070
48818
|
}
|
|
48071
48819
|
};
|
|
@@ -48302,23 +49050,23 @@ var noService = {
|
|
|
48302
49050
|
remove: async () => ({}),
|
|
48303
49051
|
cli: () => ["oa-bus"]
|
|
48304
49052
|
};
|
|
48305
|
-
var VERSION = true ? "0.
|
|
48306
|
-
|
|
49053
|
+
var VERSION = true ? "0.155.0" : JSON.parse(
|
|
49054
|
+
readFileSync15(new URL("../package.json", import.meta.url), "utf8")
|
|
48307
49055
|
).version;
|
|
48308
49056
|
var which = (cmd) => {
|
|
48309
49057
|
try {
|
|
48310
|
-
|
|
49058
|
+
execFileSync6("which", [cmd], { stdio: "ignore" });
|
|
48311
49059
|
return true;
|
|
48312
49060
|
} catch {
|
|
48313
49061
|
return false;
|
|
48314
49062
|
}
|
|
48315
49063
|
};
|
|
48316
49064
|
function processArgs2(pid, io = {
|
|
48317
|
-
ps: (pid2) =>
|
|
49065
|
+
ps: (pid2) => execFileSync6(systemTool("ps"), ["-o", "args=", "-p", String(pid2)], {
|
|
48318
49066
|
encoding: "utf8",
|
|
48319
49067
|
stdio: ["ignore", "pipe", "ignore"]
|
|
48320
49068
|
}),
|
|
48321
|
-
proc: (path) =>
|
|
49069
|
+
proc: (path) => readFileSync15(path, "utf8")
|
|
48322
49070
|
}) {
|
|
48323
49071
|
try {
|
|
48324
49072
|
return io.ps(pid).trim() || void 0;
|
|
@@ -48471,7 +49219,7 @@ var configFileLines = (ctx, files2) => files2.flatMap(
|
|
|
48471
49219
|
);
|
|
48472
49220
|
|
|
48473
49221
|
// src/machine.ts
|
|
48474
|
-
import { readFileSync as
|
|
49222
|
+
import { readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
|
|
48475
49223
|
import { join as join19 } from "node:path";
|
|
48476
49224
|
init_src();
|
|
48477
49225
|
function readMachine(home2) {
|
|
@@ -48480,7 +49228,7 @@ function readMachine(home2) {
|
|
|
48480
49228
|
let mode;
|
|
48481
49229
|
try {
|
|
48482
49230
|
mode = statSync8(file2).mode;
|
|
48483
|
-
text3 =
|
|
49231
|
+
text3 = readFileSync16(file2, "utf8");
|
|
48484
49232
|
} catch (e) {
|
|
48485
49233
|
return e.code === "ENOENT" ? { state: "missing" } : { state: "bad" };
|
|
48486
49234
|
}
|
|
@@ -48504,7 +49252,7 @@ function readMachine(home2) {
|
|
|
48504
49252
|
var lasting = (e) => [...START_ERROR_CODES, "EACCES", "EPERM"].includes(
|
|
48505
49253
|
e?.code
|
|
48506
49254
|
);
|
|
48507
|
-
async function daemon(ctx,
|
|
49255
|
+
async function daemon(ctx, run5 = runDaemon, signals = process) {
|
|
48508
49256
|
const m = readMachine(ctx.home);
|
|
48509
49257
|
if (existsSync5(join20(ctx.home, "revoked")) && (m.state !== "ok" || m.revoked)) {
|
|
48510
49258
|
sayErr(ctx, ctx.copy.revoked());
|
|
@@ -48523,8 +49271,10 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
|
|
|
48523
49271
|
const onSignal = () => end(0);
|
|
48524
49272
|
signals.once("SIGINT", onSignal);
|
|
48525
49273
|
signals.once("SIGTERM", onSignal);
|
|
48526
|
-
|
|
49274
|
+
run5({
|
|
48527
49275
|
version: ctx.version,
|
|
49276
|
+
// Always on: ~/.oa-bus/logs/events.log (the service owns daemon.log's fd); `oa-bus logs` shows both.
|
|
49277
|
+
events: createEventLog(join20(ctx.home, "logs", "events.log")),
|
|
48528
49278
|
// Only an older token was revoked: a restart picks up the new one.
|
|
48529
49279
|
onRevoked: (replaced) => end(replaced ? 1 : REVOKED_EXIT),
|
|
48530
49280
|
// Exit non-zero: the service restarts the daemon, which binds again.
|
|
@@ -48547,7 +49297,7 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
|
|
|
48547
49297
|
}
|
|
48548
49298
|
|
|
48549
49299
|
// src/commands/doctor.ts
|
|
48550
|
-
import { readFileSync as
|
|
49300
|
+
import { readFileSync as readFileSync27 } from "node:fs";
|
|
48551
49301
|
import { join as join32 } from "node:path";
|
|
48552
49302
|
|
|
48553
49303
|
// ../bus-adapter-opencode/src/index.ts
|
|
@@ -48562,18 +49312,18 @@ var OPENCODE_TUI_PLUGIN = fileURLToPath2(
|
|
|
48562
49312
|
// src/steps/adapters.ts
|
|
48563
49313
|
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
48564
49314
|
import {
|
|
48565
|
-
chmodSync as
|
|
49315
|
+
chmodSync as chmodSync14,
|
|
48566
49316
|
existsSync as existsSync12,
|
|
48567
49317
|
lstatSync as lstatSync15,
|
|
48568
49318
|
mkdirSync as mkdirSync12,
|
|
48569
|
-
readFileSync as
|
|
48570
|
-
readlinkSync as
|
|
48571
|
-
renameSync as
|
|
49319
|
+
readFileSync as readFileSync25,
|
|
49320
|
+
readlinkSync as readlinkSync5,
|
|
49321
|
+
renameSync as renameSync15,
|
|
48572
49322
|
rmSync as rmSync14,
|
|
48573
49323
|
statSync as statSync10,
|
|
48574
|
-
writeFileSync as
|
|
49324
|
+
writeFileSync as writeFileSync13
|
|
48575
49325
|
} from "node:fs";
|
|
48576
|
-
import { dirname as
|
|
49326
|
+
import { dirname as dirname14, join as join27, resolve as resolve11 } from "node:path";
|
|
48577
49327
|
import { isDeepStrictEqual } from "node:util";
|
|
48578
49328
|
|
|
48579
49329
|
// ../bus-adapter-hermes/src/index.ts
|
|
@@ -49661,10 +50411,10 @@ function removeAt(text3, path) {
|
|
|
49661
50411
|
const solid = (t) => !isSpace(t.kind) && !isComment(t.kind);
|
|
49662
50412
|
const p = toks.filter((t) => t.end <= s && solid(t)).at(-1);
|
|
49663
50413
|
const f = toks.find((t) => t.offset >= e && solid(t));
|
|
49664
|
-
const
|
|
50414
|
+
const open3 = parent.offset + 1;
|
|
49665
50415
|
const close = parent.offset + parent.length - 1;
|
|
49666
|
-
if (p?.offset === parent.offset && f?.offset === close && !comments(
|
|
49667
|
-
return splice(text3,
|
|
50416
|
+
if (p?.offset === parent.offset && f?.offset === close && !comments(open3, close))
|
|
50417
|
+
return splice(text3, open3, close);
|
|
49668
50418
|
const comma = (t) => t?.kind === SyntaxKind2.CommaToken;
|
|
49669
50419
|
if (p && comma(p) && !comments(p.end, s)) return splice(text3, p.offset, e);
|
|
49670
50420
|
let to = e;
|
|
@@ -49807,20 +50557,20 @@ var PI_EXTENSION = fileURLToPath4(
|
|
|
49807
50557
|
);
|
|
49808
50558
|
|
|
49809
50559
|
// src/steps/claude-proof.ts
|
|
49810
|
-
import { readFileSync as
|
|
50560
|
+
import { readFileSync as readFileSync17 } from "node:fs";
|
|
49811
50561
|
import { join as join21 } from "node:path";
|
|
49812
50562
|
var claudeConfigFile = (home2, env2) => join21(env2.CLAUDE_CONFIG_DIR ?? home2, ".claude.json");
|
|
49813
50563
|
var PROOF_COMMAND = "mcp-proof";
|
|
49814
50564
|
var TOKEN_HELPER = /^T=\$\(cat (.+)\) && printf '\{"Authorization":"Bearer %s"\}' "\$T"$/;
|
|
49815
50565
|
var quote = (s) => /^[A-Za-z0-9_./:@%+=,-]+$/.test(s) ? s : `'${s.replaceAll("'", `'\\''`)}'`;
|
|
49816
50566
|
function proofHelper(busBin, opts) {
|
|
49817
|
-
const
|
|
50567
|
+
const run5 = [
|
|
49818
50568
|
...opts.busHome ? [`OA_BUS_HOME=${quote(opts.busHome)}`] : [],
|
|
49819
50569
|
...busBin.map(quote),
|
|
49820
50570
|
PROOF_COMMAND,
|
|
49821
50571
|
...opts.tokenFile ? ["--token-file", opts.tokenFile] : []
|
|
49822
50572
|
].join(" ");
|
|
49823
|
-
return opts.tokenFile ? `T=$(cat ${opts.tokenFile}) && { ${
|
|
50573
|
+
return opts.tokenFile ? `T=$(cat ${opts.tokenFile}) && { ${run5} 2>/dev/null || printf '{"Authorization":"Bearer %s"}' "$T"; }` : run5;
|
|
49824
50574
|
}
|
|
49825
50575
|
var isProofHelper = (helper) => typeof helper === "string" && / mcp-proof( |$)/.test(helper);
|
|
49826
50576
|
var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -49841,7 +50591,7 @@ function findEntry(doc, origin) {
|
|
|
49841
50591
|
}
|
|
49842
50592
|
var readText = (path) => {
|
|
49843
50593
|
try {
|
|
49844
|
-
return
|
|
50594
|
+
return readFileSync17(path, "utf8");
|
|
49845
50595
|
} catch (e) {
|
|
49846
50596
|
if (e.code === "ENOENT") return "";
|
|
49847
50597
|
throw e;
|
|
@@ -49849,7 +50599,7 @@ var readText = (path) => {
|
|
|
49849
50599
|
};
|
|
49850
50600
|
function readRecord(path) {
|
|
49851
50601
|
try {
|
|
49852
|
-
const v = JSON.parse(
|
|
50602
|
+
const v = JSON.parse(readFileSync17(path, "utf8"));
|
|
49853
50603
|
if (isRecord3(v)) {
|
|
49854
50604
|
const { claudeProof: claudeProof2, ...rest } = v;
|
|
49855
50605
|
const p = claudeProof2;
|
|
@@ -49925,7 +50675,7 @@ function proofState(file2, origin) {
|
|
|
49925
50675
|
// src/steps/codex-proof.ts
|
|
49926
50676
|
init_src3();
|
|
49927
50677
|
init_src();
|
|
49928
|
-
import { existsSync as existsSync6, readFileSync as
|
|
50678
|
+
import { existsSync as existsSync6, readFileSync as readFileSync18, rmSync as rmSync7 } from "node:fs";
|
|
49929
50679
|
import { isAbsolute as isAbsolute10 } from "node:path";
|
|
49930
50680
|
var CODEX_MIN_VERSION = "0.123.0";
|
|
49931
50681
|
var PROXY_CMD = "mcp-proxy";
|
|
@@ -49948,7 +50698,7 @@ var BLOCKING = [
|
|
|
49948
50698
|
var isRecord4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
49949
50699
|
function readMoved(path) {
|
|
49950
50700
|
try {
|
|
49951
|
-
const v = JSON.parse(
|
|
50701
|
+
const v = JSON.parse(readFileSync18(path, "utf8"));
|
|
49952
50702
|
if (isRecord4(v) && typeof v.name === "string" && typeof v.origin === "string" && Array.isArray(v.lines) && v.lines.every((l) => typeof l === "string") && typeof v.original === "string" && typeof v.swapped === "string")
|
|
49953
50703
|
return v;
|
|
49954
50704
|
} catch {
|
|
@@ -50234,7 +50984,7 @@ init_src();
|
|
|
50234
50984
|
import {
|
|
50235
50985
|
existsSync as existsSync9,
|
|
50236
50986
|
lstatSync as lstatSync14,
|
|
50237
|
-
readFileSync as
|
|
50987
|
+
readFileSync as readFileSync22,
|
|
50238
50988
|
realpathSync as realpathSync12,
|
|
50239
50989
|
rmSync as rmSync11
|
|
50240
50990
|
} from "node:fs";
|
|
@@ -50246,18 +50996,18 @@ import {
|
|
|
50246
50996
|
cpSync as cpSync2,
|
|
50247
50997
|
lstatSync as lstatSync11,
|
|
50248
50998
|
mkdirSync as mkdirSync10,
|
|
50249
|
-
readdirSync as
|
|
50250
|
-
readFileSync as
|
|
50251
|
-
readlinkSync as
|
|
50999
|
+
readdirSync as readdirSync6,
|
|
51000
|
+
readFileSync as readFileSync19,
|
|
51001
|
+
readlinkSync as readlinkSync3,
|
|
50252
51002
|
realpathSync as realpathSync9,
|
|
50253
|
-
renameSync as
|
|
51003
|
+
renameSync as renameSync13,
|
|
50254
51004
|
rmdirSync,
|
|
50255
51005
|
rmSync as rmSync8,
|
|
50256
|
-
writeFileSync as
|
|
51006
|
+
writeFileSync as writeFileSync11
|
|
50257
51007
|
} from "node:fs";
|
|
50258
51008
|
import {
|
|
50259
51009
|
basename as basename7,
|
|
50260
|
-
dirname as
|
|
51010
|
+
dirname as dirname11,
|
|
50261
51011
|
isAbsolute as isAbsolute11,
|
|
50262
51012
|
join as join22,
|
|
50263
51013
|
relative as relative2,
|
|
@@ -50276,7 +51026,7 @@ var real2 = (p) => {
|
|
|
50276
51026
|
try {
|
|
50277
51027
|
return join22(realpathSync9(cur), ...rest.reverse());
|
|
50278
51028
|
} catch {
|
|
50279
|
-
const up =
|
|
51029
|
+
const up = dirname11(cur);
|
|
50280
51030
|
if (up === cur) return p;
|
|
50281
51031
|
rest.push(basename7(cur));
|
|
50282
51032
|
cur = up;
|
|
@@ -50298,7 +51048,7 @@ function sweepStaging(staging, own2, o = {}) {
|
|
|
50298
51048
|
const alive2 = o.alive ?? pidAlive;
|
|
50299
51049
|
let names2;
|
|
50300
51050
|
try {
|
|
50301
|
-
names2 =
|
|
51051
|
+
names2 = readdirSync6(staging);
|
|
50302
51052
|
} catch {
|
|
50303
51053
|
return;
|
|
50304
51054
|
}
|
|
@@ -50330,13 +51080,13 @@ function hermesHome(home2, env2, platform = process.platform) {
|
|
|
50330
51080
|
const native = nativeHome(home2, env2, platform);
|
|
50331
51081
|
const v = env2.HERMES_HOME?.trim();
|
|
50332
51082
|
const given = v ? tilded(home2, v) : void 0;
|
|
50333
|
-
if (given !== void 0 && basename7(
|
|
51083
|
+
if (given !== void 0 && basename7(dirname11(given)) === "profiles")
|
|
50334
51084
|
return given;
|
|
50335
51085
|
const base3 = given ?? native;
|
|
50336
51086
|
const root = hermesRoot(home2, env2, platform);
|
|
50337
51087
|
if (env2.HERMES_S6_SUPERVISED_CHILD) return base3;
|
|
50338
51088
|
try {
|
|
50339
|
-
const name =
|
|
51089
|
+
const name = readFileSync19(join22(root, "active_profile"), "utf8").trim().toLowerCase();
|
|
50340
51090
|
if (name && name !== "default" && /^[a-z0-9][a-z0-9_-]{0,63}$/.test(name)) {
|
|
50341
51091
|
const dir = join22(root, "profiles", name);
|
|
50342
51092
|
if (lstatSync11(dir).isDirectory()) return dir;
|
|
@@ -50350,7 +51100,7 @@ function hermesRoot(home2, env2, platform = process.platform) {
|
|
|
50350
51100
|
const v = env2.HERMES_HOME?.trim();
|
|
50351
51101
|
const given = v ? tilded(home2, v) : void 0;
|
|
50352
51102
|
if (given === void 0) return native;
|
|
50353
|
-
if (basename7(
|
|
51103
|
+
if (basename7(dirname11(given)) === "profiles") return dirname11(dirname11(given));
|
|
50354
51104
|
const rel = relative2(real2(native), real2(given));
|
|
50355
51105
|
if (rel === "" || !rel.startsWith("..") && !isAbsolute11(rel)) return native;
|
|
50356
51106
|
return given;
|
|
@@ -50367,14 +51117,14 @@ function hermesProfilesScan(home2, env2, platform = process.platform) {
|
|
|
50367
51117
|
return realpathSync9(path);
|
|
50368
51118
|
} catch {
|
|
50369
51119
|
try {
|
|
50370
|
-
return resolve6(
|
|
51120
|
+
return resolve6(dirname11(path), readlinkSync3(path));
|
|
50371
51121
|
} catch {
|
|
50372
51122
|
return "somewhere else";
|
|
50373
51123
|
}
|
|
50374
51124
|
}
|
|
50375
51125
|
};
|
|
50376
51126
|
try {
|
|
50377
|
-
const names2 =
|
|
51127
|
+
const names2 = readdirSync6(path).sort();
|
|
50378
51128
|
return {
|
|
50379
51129
|
names: names2,
|
|
50380
51130
|
incomplete: false,
|
|
@@ -50424,7 +51174,7 @@ var kind = (path) => {
|
|
|
50424
51174
|
};
|
|
50425
51175
|
function files(dir, rel = "") {
|
|
50426
51176
|
const out = [];
|
|
50427
|
-
for (const name of
|
|
51177
|
+
for (const name of readdirSync6(join22(dir, rel)).sort()) {
|
|
50428
51178
|
if (name === "__pycache__" || name.startsWith(".") || name.endsWith(".pyc") || rel === "" && name === HERMES_HABITS_MARKER)
|
|
50429
51179
|
continue;
|
|
50430
51180
|
const r = rel ? `${rel}/${name}` : name;
|
|
@@ -50437,7 +51187,7 @@ function pluginHash(dir) {
|
|
|
50437
51187
|
const h = createHash7("sha256");
|
|
50438
51188
|
for (const f of files(dir)) {
|
|
50439
51189
|
h.update(`${f}\0`);
|
|
50440
|
-
h.update(
|
|
51190
|
+
h.update(readFileSync19(join22(dir, f)));
|
|
50441
51191
|
h.update("\0");
|
|
50442
51192
|
}
|
|
50443
51193
|
return h.digest("hex").slice(0, 16);
|
|
@@ -50448,7 +51198,7 @@ function pluginState(dir, shipped) {
|
|
|
50448
51198
|
if (k !== "dir") return "foreign";
|
|
50449
51199
|
let marker;
|
|
50450
51200
|
try {
|
|
50451
|
-
marker =
|
|
51201
|
+
marker = readFileSync19(join22(dir, HERMES_MARKER), "utf8").trim();
|
|
50452
51202
|
} catch {
|
|
50453
51203
|
return "foreign";
|
|
50454
51204
|
}
|
|
@@ -50506,15 +51256,15 @@ async function installHermes(deps2) {
|
|
|
50506
51256
|
mkdirSync10(join22(tmp, f, ".."), { recursive: true });
|
|
50507
51257
|
cpSync2(join22(shipped, f), join22(tmp, f));
|
|
50508
51258
|
}
|
|
50509
|
-
|
|
51259
|
+
writeFileSync11(
|
|
50510
51260
|
join22(tmp, HERMES_MARKER),
|
|
50511
51261
|
`managed by the Open Artifacts bus installer: edits are replaced on reinstall. ${pluginHash(shipped)}
|
|
50512
51262
|
`
|
|
50513
51263
|
);
|
|
50514
51264
|
if (keepHabits)
|
|
50515
|
-
|
|
51265
|
+
writeFileSync11(join22(tmp, HERMES_HABITS_MARKER), HABITS_MARKER_TEXT);
|
|
50516
51266
|
if (state === "stale") rmSync8(dest, { recursive: true, force: true });
|
|
50517
|
-
|
|
51267
|
+
renameSync13(tmp, dest);
|
|
50518
51268
|
} catch (e) {
|
|
50519
51269
|
rmSync8(tmp, { recursive: true, force: true });
|
|
50520
51270
|
throw e;
|
|
@@ -50571,8 +51321,8 @@ async function hermesEnabled(deps2) {
|
|
|
50571
51321
|
import {
|
|
50572
51322
|
existsSync as existsSync8,
|
|
50573
51323
|
lstatSync as lstatSync13,
|
|
50574
|
-
readdirSync as
|
|
50575
|
-
readFileSync as
|
|
51324
|
+
readdirSync as readdirSync8,
|
|
51325
|
+
readFileSync as readFileSync21,
|
|
50576
51326
|
realpathSync as realpathSync11,
|
|
50577
51327
|
rmSync as rmSync10
|
|
50578
51328
|
} from "node:fs";
|
|
@@ -50581,21 +51331,21 @@ import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
|
50581
51331
|
|
|
50582
51332
|
// src/steps/skill.ts
|
|
50583
51333
|
import {
|
|
50584
|
-
chmodSync as
|
|
51334
|
+
chmodSync as chmodSync13,
|
|
50585
51335
|
existsSync as existsSync7,
|
|
50586
51336
|
lstatSync as lstatSync12,
|
|
50587
51337
|
mkdirSync as mkdirSync11,
|
|
50588
|
-
readdirSync as
|
|
50589
|
-
readFileSync as
|
|
50590
|
-
readlinkSync as
|
|
51338
|
+
readdirSync as readdirSync7,
|
|
51339
|
+
readFileSync as readFileSync20,
|
|
51340
|
+
readlinkSync as readlinkSync4,
|
|
50591
51341
|
realpathSync as realpathSync10,
|
|
50592
|
-
renameSync as
|
|
51342
|
+
renameSync as renameSync14,
|
|
50593
51343
|
rmdirSync as rmdirSync2,
|
|
50594
51344
|
rmSync as rmSync9,
|
|
50595
51345
|
statSync as statSync9,
|
|
50596
|
-
writeFileSync as
|
|
51346
|
+
writeFileSync as writeFileSync12
|
|
50597
51347
|
} from "node:fs";
|
|
50598
|
-
import { dirname as
|
|
51348
|
+
import { dirname as dirname12, join as join23, resolve as resolve7 } from "node:path";
|
|
50599
51349
|
var SKILL_MARKER = "<!-- managed by the Open Artifacts bus installer: edits are replaced on reinstall. -->";
|
|
50600
51350
|
var CODEX_BEGIN = "<!-- BEGIN Open Artifacts skill (managed): edits inside are replaced on reinstall. -->";
|
|
50601
51351
|
var CODEX_END = "<!-- END Open Artifacts skill -->";
|
|
@@ -50624,7 +51374,7 @@ var withoutCodexBlock = (text3) => {
|
|
|
50624
51374
|
};
|
|
50625
51375
|
var dropCodexBlock = (agentsPath, notes) => {
|
|
50626
51376
|
if (brokenLink(agentsPath) || !existsSync7(agentsPath)) return false;
|
|
50627
|
-
const text3 =
|
|
51377
|
+
const text3 = readFileSync20(agentsPath, "utf8");
|
|
50628
51378
|
if (codexBroken(text3)) {
|
|
50629
51379
|
notes.push(
|
|
50630
51380
|
`Left ${agentsPath} alone: its Open Artifacts block has no END marker. Fix or remove the block, then rerun the install.`
|
|
@@ -50745,7 +51495,7 @@ var targetOf = (path) => {
|
|
|
50745
51495
|
};
|
|
50746
51496
|
var seq = 0;
|
|
50747
51497
|
var writeAtomic = (path, text3) => {
|
|
50748
|
-
mkdirSync11(
|
|
51498
|
+
mkdirSync11(dirname12(path), { recursive: true });
|
|
50749
51499
|
const tmp = `${path}.oa-${process.pid}-${seq++}.tmp`;
|
|
50750
51500
|
try {
|
|
50751
51501
|
let mode;
|
|
@@ -50753,9 +51503,9 @@ var writeAtomic = (path, text3) => {
|
|
|
50753
51503
|
mode = statSync9(path).mode & 4095;
|
|
50754
51504
|
} catch {
|
|
50755
51505
|
}
|
|
50756
|
-
|
|
50757
|
-
if (mode !== void 0)
|
|
50758
|
-
|
|
51506
|
+
writeFileSync12(tmp, text3);
|
|
51507
|
+
if (mode !== void 0) chmodSync13(tmp, mode);
|
|
51508
|
+
renameSync14(tmp, path);
|
|
50759
51509
|
} catch (e) {
|
|
50760
51510
|
try {
|
|
50761
51511
|
rmSync9(tmp, { force: true });
|
|
@@ -50806,19 +51556,19 @@ var placesOf = (p) => {
|
|
|
50806
51556
|
const out = [realOrResolved(p)];
|
|
50807
51557
|
try {
|
|
50808
51558
|
if (lstatSync12(p).isSymbolicLink())
|
|
50809
|
-
out.push(realOrResolved(resolve7(
|
|
51559
|
+
out.push(realOrResolved(resolve7(dirname12(p), readlinkSync4(p))));
|
|
50810
51560
|
} catch {
|
|
50811
51561
|
}
|
|
50812
51562
|
return out;
|
|
50813
51563
|
};
|
|
50814
51564
|
var codexSkillsShared = (deps2) => {
|
|
50815
|
-
const mine = placesOf(
|
|
51565
|
+
const mine = placesOf(dirname12(dirname12(codexSkillFile(deps2, "x"))));
|
|
50816
51566
|
const theirs = placesOf(skillDir(deps2, "pi"));
|
|
50817
51567
|
return mine.some((m) => theirs.includes(m));
|
|
50818
51568
|
};
|
|
50819
51569
|
var ourSkillFile = (path, folder) => {
|
|
50820
51570
|
try {
|
|
50821
|
-
return isOurs(
|
|
51571
|
+
return isOurs(readFileSync20(path, "utf8"), folder);
|
|
50822
51572
|
} catch {
|
|
50823
51573
|
return false;
|
|
50824
51574
|
}
|
|
@@ -50828,7 +51578,7 @@ var installCodex = (deps2, folder, text3, written, notes) => {
|
|
|
50828
51578
|
const filePath = codexSkillFile(deps2, folder);
|
|
50829
51579
|
let before;
|
|
50830
51580
|
try {
|
|
50831
|
-
before = existsSync7(targetOf(agentsPath)) ?
|
|
51581
|
+
before = existsSync7(targetOf(agentsPath)) ? readFileSync20(targetOf(agentsPath), "utf8") : "";
|
|
50832
51582
|
} catch (e) {
|
|
50833
51583
|
notes.push(
|
|
50834
51584
|
`Left ${agentsPath} alone: could not read it (${e instanceof Error ? e.message : String(e)}).`
|
|
@@ -50898,7 +51648,7 @@ var installCodex = (deps2, folder, text3, written, notes) => {
|
|
|
50898
51648
|
try {
|
|
50899
51649
|
rmSync9(targetOf(filePath), { force: true });
|
|
50900
51650
|
try {
|
|
50901
|
-
rmdirSync2(
|
|
51651
|
+
rmdirSync2(dirname12(filePath));
|
|
50902
51652
|
} catch {
|
|
50903
51653
|
}
|
|
50904
51654
|
} catch (e) {
|
|
@@ -50980,7 +51730,7 @@ var uninstallSkill = (deps2, harnesses = [
|
|
|
50980
51730
|
let entries;
|
|
50981
51731
|
try {
|
|
50982
51732
|
if (!existsSync7(base3)) return;
|
|
50983
|
-
entries =
|
|
51733
|
+
entries = readdirSync7(base3);
|
|
50984
51734
|
} catch (e) {
|
|
50985
51735
|
fail2(base3, e);
|
|
50986
51736
|
return;
|
|
@@ -50996,7 +51746,7 @@ var uninstallSkill = (deps2, harnesses = [
|
|
|
50996
51746
|
continue;
|
|
50997
51747
|
}
|
|
50998
51748
|
if (!st.isDirectory() || !lstatOk(file2)) continue;
|
|
50999
|
-
if (!isOurs(
|
|
51749
|
+
if (!isOurs(readFileSync20(targetOf(file2), "utf8"), entry)) {
|
|
51000
51750
|
notes.push(
|
|
51001
51751
|
`Left ${file2} alone: it is not an Open Artifacts skill file.`
|
|
51002
51752
|
);
|
|
@@ -51023,7 +51773,7 @@ var uninstallSkill = (deps2, harnesses = [
|
|
|
51023
51773
|
} catch (e) {
|
|
51024
51774
|
fail2(base3, e);
|
|
51025
51775
|
}
|
|
51026
|
-
scan2(join23(
|
|
51776
|
+
scan2(join23(dirname12(base3), "skills"));
|
|
51027
51777
|
continue;
|
|
51028
51778
|
}
|
|
51029
51779
|
scan2(base3);
|
|
@@ -51035,8 +51785,8 @@ var codexSkillState = (deps2) => {
|
|
|
51035
51785
|
shared: codexSkillsShared(deps2)
|
|
51036
51786
|
};
|
|
51037
51787
|
try {
|
|
51038
|
-
const dir = join23(
|
|
51039
|
-
for (const entry of
|
|
51788
|
+
const dir = join23(dirname12(skillDir(deps2, "codex")), "skills");
|
|
51789
|
+
for (const entry of readdirSync7(dir)) {
|
|
51040
51790
|
const file2 = join23(dir, entry, "SKILL.md");
|
|
51041
51791
|
if (ourSkillFile(file2, entry)) {
|
|
51042
51792
|
out.file = file2;
|
|
@@ -51047,7 +51797,7 @@ var codexSkillState = (deps2) => {
|
|
|
51047
51797
|
}
|
|
51048
51798
|
try {
|
|
51049
51799
|
const agents = skillDir(deps2, "codex");
|
|
51050
|
-
if (withoutCodexBlock(
|
|
51800
|
+
if (withoutCodexBlock(readFileSync20(agents, "utf8")) !== void 0)
|
|
51051
51801
|
out.block = agents;
|
|
51052
51802
|
} catch {
|
|
51053
51803
|
}
|
|
@@ -51089,7 +51839,7 @@ function openclawPluginDirs(home2, env2) {
|
|
|
51089
51839
|
const h = openclawHome(home2, env2);
|
|
51090
51840
|
const states = [join24(h, ".openclaw"), join24(h, ".clawdbot")];
|
|
51091
51841
|
try {
|
|
51092
|
-
for (const name of
|
|
51842
|
+
for (const name of readdirSync8(h).sort())
|
|
51093
51843
|
if (name.startsWith(".openclaw-")) states.push(join24(h, name));
|
|
51094
51844
|
} catch {
|
|
51095
51845
|
}
|
|
@@ -51113,7 +51863,7 @@ var kind2 = (path) => {
|
|
|
51113
51863
|
var openclawManifestIsOurs = (dir) => {
|
|
51114
51864
|
try {
|
|
51115
51865
|
const m = JSON.parse(
|
|
51116
|
-
|
|
51866
|
+
readFileSync21(join24(dir, "openclaw.plugin.json"), "utf8")
|
|
51117
51867
|
);
|
|
51118
51868
|
return m?.id === OPENCLAW_PLUGIN_ID;
|
|
51119
51869
|
} catch {
|
|
@@ -51134,7 +51884,7 @@ function openclawPluginState(dir, shipped) {
|
|
|
51134
51884
|
if (k !== "dir") return "foreign";
|
|
51135
51885
|
let marker;
|
|
51136
51886
|
try {
|
|
51137
|
-
marker =
|
|
51887
|
+
marker = readFileSync21(join24(dir, OPENCLAW_MARKER), "utf8").trim();
|
|
51138
51888
|
} catch {
|
|
51139
51889
|
return sameAsShipped(dir, shipped) ? "stale" : "foreign";
|
|
51140
51890
|
}
|
|
@@ -51496,7 +52246,7 @@ function habitsFileState(deps2, h) {
|
|
|
51496
52246
|
try {
|
|
51497
52247
|
if (brokenLink(path)) return { state: "broken", path };
|
|
51498
52248
|
if (!existsSync9(path)) return { state: "absent", path };
|
|
51499
|
-
return { ...blockState(
|
|
52249
|
+
return { ...blockState(readFileSync22(targetOf(path), "utf8")), path };
|
|
51500
52250
|
} catch {
|
|
51501
52251
|
return { state: "broken", path };
|
|
51502
52252
|
}
|
|
@@ -51524,7 +52274,7 @@ function writeHabits(deps2, harnesses, opts = {}) {
|
|
|
51524
52274
|
const real3 = targetOf(path);
|
|
51525
52275
|
try {
|
|
51526
52276
|
const exists2 = existsSync9(real3);
|
|
51527
|
-
const before = exists2 ?
|
|
52277
|
+
const before = exists2 ? readFileSync22(real3, "utf8") : "";
|
|
51528
52278
|
const fresh = blockState(before).state === "absent";
|
|
51529
52279
|
const after = withHabits(before, habitsBlock());
|
|
51530
52280
|
if (after !== before) writeAtomic(real3, after);
|
|
@@ -51555,7 +52305,7 @@ function removeHabits(deps2, harnesses = HABITS_HARNESSES) {
|
|
|
51555
52305
|
try {
|
|
51556
52306
|
if (brokenLink(path) || !existsSync9(path)) continue;
|
|
51557
52307
|
const real3 = targetOf(path);
|
|
51558
|
-
const before =
|
|
52308
|
+
const before = readFileSync22(real3, "utf8");
|
|
51559
52309
|
if (blockState(before).state === "absent") continue;
|
|
51560
52310
|
const rec = kept[path];
|
|
51561
52311
|
const after = withHabits(before, null, rec?.added);
|
|
@@ -51593,7 +52343,7 @@ function habitsOn(deps2) {
|
|
|
51593
52343
|
seen2.add(path);
|
|
51594
52344
|
try {
|
|
51595
52345
|
if (brokenLink(path) || !existsSync9(path)) continue;
|
|
51596
|
-
const s = blockState(
|
|
52346
|
+
const s = blockState(readFileSync22(targetOf(path), "utf8")).state;
|
|
51597
52347
|
if (s === "current" || s === "changed") out.push(path);
|
|
51598
52348
|
} catch {
|
|
51599
52349
|
}
|
|
@@ -51800,8 +52550,8 @@ var habitsQuestionLines = (q) => [
|
|
|
51800
52550
|
];
|
|
51801
52551
|
|
|
51802
52552
|
// src/steps/opencode-proof.ts
|
|
51803
|
-
import { existsSync as existsSync10, readFileSync as
|
|
51804
|
-
import { dirname as
|
|
52553
|
+
import { existsSync as existsSync10, readFileSync as readFileSync23, rmSync as rmSync12 } from "node:fs";
|
|
52554
|
+
import { dirname as dirname13, isAbsolute as isAbsolute12, join as join26, resolve as resolve10 } from "node:path";
|
|
51805
52555
|
init_src();
|
|
51806
52556
|
var OPENCODE_ENTRY_FILE = "opencode-mcp-entry.json";
|
|
51807
52557
|
var isRecord5 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -51844,7 +52594,7 @@ var REMOTE_ONLY = /* @__PURE__ */ new Set(["type", "url", "headers", "oauth"]);
|
|
|
51844
52594
|
function resolveTokenFile(x, configFile, home2) {
|
|
51845
52595
|
if (x === "~") return home2;
|
|
51846
52596
|
if (x.startsWith("~/")) return join26(home2, x.slice(2));
|
|
51847
|
-
return isAbsolute12(x) ? x : resolve10(
|
|
52597
|
+
return isAbsolute12(x) ? x : resolve10(dirname13(configFile), x);
|
|
51848
52598
|
}
|
|
51849
52599
|
var proxyEntry = (io, origin, tokenFile, entry) => {
|
|
51850
52600
|
const kept = Object.fromEntries(
|
|
@@ -51883,7 +52633,7 @@ function ourEntry2(e, origin) {
|
|
|
51883
52633
|
}
|
|
51884
52634
|
function readMoved2(path) {
|
|
51885
52635
|
try {
|
|
51886
|
-
const v = JSON.parse(
|
|
52636
|
+
const v = JSON.parse(readFileSync23(path, "utf8"));
|
|
51887
52637
|
if (isRecord5(v) && typeof v.file === "string" && Array.isArray(v.path) && typeof v.origin === "string" && isRecord5(v.config))
|
|
51888
52638
|
return v;
|
|
51889
52639
|
} catch {
|
|
@@ -51992,7 +52742,7 @@ function proxyEntries(text3) {
|
|
|
51992
52742
|
}
|
|
51993
52743
|
|
|
51994
52744
|
// src/steps/pi-proof.ts
|
|
51995
|
-
import { existsSync as existsSync11, readFileSync as
|
|
52745
|
+
import { existsSync as existsSync11, readFileSync as readFileSync24, rmSync as rmSync13 } from "node:fs";
|
|
51996
52746
|
var PI_ENTRY_FILE = "pi-mcp-entry.json";
|
|
51997
52747
|
var OMP_ORIGIN_FILE = "omp-mcp-origin.json";
|
|
51998
52748
|
var PI_MIN_VERSION = "1.5.0";
|
|
@@ -52000,7 +52750,7 @@ var isRecord6 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
|
52000
52750
|
var BOM2 = "\uFEFF";
|
|
52001
52751
|
function readConfig2(file2) {
|
|
52002
52752
|
if (!existsSync11(file2)) return null;
|
|
52003
|
-
const raw =
|
|
52753
|
+
const raw = readFileSync24(file2, "utf8");
|
|
52004
52754
|
const bom = raw.startsWith(BOM2);
|
|
52005
52755
|
const text3 = bom ? raw.slice(1) : raw;
|
|
52006
52756
|
const parsed = JSON.parse(text3);
|
|
@@ -52034,7 +52784,7 @@ function findEntry2(servers4, origin) {
|
|
|
52034
52784
|
}
|
|
52035
52785
|
function readMoved3(path) {
|
|
52036
52786
|
try {
|
|
52037
|
-
const v = JSON.parse(
|
|
52787
|
+
const v = JSON.parse(readFileSync24(path, "utf8"));
|
|
52038
52788
|
if (isRecord6(v) && typeof v.name === "string" && typeof v.index === "number" && isRecord6(v.config))
|
|
52039
52789
|
return {
|
|
52040
52790
|
name: v.name,
|
|
@@ -52104,8 +52854,8 @@ var HARNESSES = [
|
|
|
52104
52854
|
"openclaw"
|
|
52105
52855
|
];
|
|
52106
52856
|
var readAssets = () => ({
|
|
52107
|
-
pi:
|
|
52108
|
-
opencodePlugin:
|
|
52857
|
+
pi: readFileSync25(PI_EXTENSION, "utf8"),
|
|
52858
|
+
opencodePlugin: readFileSync25(OPENCODE_TUI_PLUGIN, "utf8"),
|
|
52109
52859
|
// A folder, not text: the plugin is several Python files.
|
|
52110
52860
|
hermes: HERMES_PLUGIN,
|
|
52111
52861
|
// Built from packages/bus-adapter-openclaw (the CLI's bundle step does it).
|
|
@@ -52182,7 +52932,7 @@ var sharedFile = (deps2) => paths(deps2).omp === paths(deps2).pi;
|
|
|
52182
52932
|
function readDoc(path) {
|
|
52183
52933
|
let text3;
|
|
52184
52934
|
try {
|
|
52185
|
-
text3 =
|
|
52935
|
+
text3 = readFileSync25(path, "utf8");
|
|
52186
52936
|
} catch (e) {
|
|
52187
52937
|
if (e.code === "ENOENT") return {};
|
|
52188
52938
|
throw e;
|
|
@@ -52207,19 +52957,19 @@ function target(path) {
|
|
|
52207
52957
|
let p = path;
|
|
52208
52958
|
for (let hops = 0; hops < 40; hops++) {
|
|
52209
52959
|
if (!present2(p) || !lstatSync15(p).isSymbolicLink()) {
|
|
52210
|
-
if (p !== path && !existsSync12(
|
|
52960
|
+
if (p !== path && !existsSync12(dirname14(p)))
|
|
52211
52961
|
throw new Error(
|
|
52212
52962
|
`${path} is a dangling symlink to ${p}; left it untouched`
|
|
52213
52963
|
);
|
|
52214
52964
|
return p;
|
|
52215
52965
|
}
|
|
52216
|
-
p = resolve11(
|
|
52966
|
+
p = resolve11(dirname14(p), readlinkSync5(p));
|
|
52217
52967
|
}
|
|
52218
52968
|
throw new Error(`${path}: too many symlinks; left it untouched`);
|
|
52219
52969
|
}
|
|
52220
52970
|
function writeAtomic2(path, data, mode) {
|
|
52221
52971
|
const dest = target(path);
|
|
52222
|
-
mkdirSync12(
|
|
52972
|
+
mkdirSync12(dirname14(dest), { recursive: true });
|
|
52223
52973
|
let m = mode ?? 420;
|
|
52224
52974
|
if (mode === void 0)
|
|
52225
52975
|
try {
|
|
@@ -52228,9 +52978,9 @@ function writeAtomic2(path, data, mode) {
|
|
|
52228
52978
|
}
|
|
52229
52979
|
const tmp = `${dest}.${process.pid}.${randomBytes6(4).toString("hex")}.tmp`;
|
|
52230
52980
|
try {
|
|
52231
|
-
|
|
52232
|
-
|
|
52233
|
-
|
|
52981
|
+
writeFileSync13(tmp, data, { mode: m, flag: "wx" });
|
|
52982
|
+
chmodSync14(tmp, m);
|
|
52983
|
+
renameSync15(tmp, dest);
|
|
52234
52984
|
} catch (e) {
|
|
52235
52985
|
rmSync14(tmp, { force: true });
|
|
52236
52986
|
throw e;
|
|
@@ -52239,7 +52989,7 @@ function writeAtomic2(path, data, mode) {
|
|
|
52239
52989
|
function readJsonc(path) {
|
|
52240
52990
|
let text3;
|
|
52241
52991
|
try {
|
|
52242
|
-
text3 =
|
|
52992
|
+
text3 = readFileSync25(path, "utf8");
|
|
52243
52993
|
} catch (e) {
|
|
52244
52994
|
if (e.code === "ENOENT") return "";
|
|
52245
52995
|
throw e;
|
|
@@ -52256,7 +53006,7 @@ function saveText(path, before, next, ok) {
|
|
|
52256
53006
|
}
|
|
52257
53007
|
function readRecord2(path) {
|
|
52258
53008
|
try {
|
|
52259
|
-
const v = JSON.parse(
|
|
53009
|
+
const v = JSON.parse(readFileSync25(path, "utf8"));
|
|
52260
53010
|
const c = v?.created;
|
|
52261
53011
|
if (typeof c === "object" && c !== null) return c;
|
|
52262
53012
|
} catch {
|
|
@@ -52267,7 +53017,7 @@ function writeRecord2(path, before, created) {
|
|
|
52267
53017
|
if (isDeepStrictEqual(before, created)) return;
|
|
52268
53018
|
let rest = {};
|
|
52269
53019
|
try {
|
|
52270
|
-
const v = JSON.parse(
|
|
53020
|
+
const v = JSON.parse(readFileSync25(path, "utf8"));
|
|
52271
53021
|
if (typeof v === "object" && v !== null && !Array.isArray(v))
|
|
52272
53022
|
rest = v;
|
|
52273
53023
|
} catch {
|
|
@@ -52286,7 +53036,7 @@ function save(path, before, next) {
|
|
|
52286
53036
|
writeAtomic2(path, json2(next));
|
|
52287
53037
|
return true;
|
|
52288
53038
|
}
|
|
52289
|
-
async function
|
|
53039
|
+
async function run4(deps2, cmd, args) {
|
|
52290
53040
|
try {
|
|
52291
53041
|
return await deps2.exec(cmd, args);
|
|
52292
53042
|
} catch (e) {
|
|
@@ -52348,7 +53098,7 @@ async function codexEntryStep(deps2, notes) {
|
|
|
52348
53098
|
return;
|
|
52349
53099
|
}
|
|
52350
53100
|
const bin = findCodexBin({ path: deps2.env?.PATH, app: deps2.codexApp });
|
|
52351
|
-
const r = await
|
|
53101
|
+
const r = await run4(deps2, bin ?? "codex", ["--version"]);
|
|
52352
53102
|
const version2 = /(\d+\.\d+\.\d+\S*)/.exec(
|
|
52353
53103
|
r.code === 0 ? r.stdout : ""
|
|
52354
53104
|
)?.[1];
|
|
@@ -52388,7 +53138,7 @@ async function piEntry(deps2, notes) {
|
|
|
52388
53138
|
);
|
|
52389
53139
|
return;
|
|
52390
53140
|
}
|
|
52391
|
-
const r = await
|
|
53141
|
+
const r = await run4(deps2, "pi", ["--version"]);
|
|
52392
53142
|
const version2 = r.code === 0 ? r.stdout.trim().split(/\s+/)[0] : void 0;
|
|
52393
53143
|
if (version2 === void 0 || (compareVersions(version2, PI_MIN_VERSION) ?? -1) < 0) {
|
|
52394
53144
|
notes.push(
|
|
@@ -52433,16 +53183,16 @@ var codexHere = (deps2) => hasCodex({
|
|
|
52433
53183
|
app: deps2.codexApp
|
|
52434
53184
|
});
|
|
52435
53185
|
async function restartOpencode(deps2, notes) {
|
|
52436
|
-
const r = await
|
|
53186
|
+
const r = await run4(deps2, "opencode", ["service", "restart"]);
|
|
52437
53187
|
if (r.code !== 0) notes.push(`${RESTART_FAILED}: ${firstLine3(r.stderr)}`);
|
|
52438
53188
|
}
|
|
52439
53189
|
var install = {
|
|
52440
53190
|
// Claude rewrites ~/.claude.json while it runs, so its own CLI does the edit.
|
|
52441
53191
|
async claude(deps2, notes) {
|
|
52442
53192
|
if (!deps2.which("claude")) return "absent";
|
|
52443
|
-
await
|
|
53193
|
+
await run4(deps2, "claude", ["mcp", "remove", "--scope", "user", NAME2]);
|
|
52444
53194
|
const moved = movedHome(deps2);
|
|
52445
|
-
const add = await
|
|
53195
|
+
const add = await run4(deps2, "claude", [
|
|
52446
53196
|
"mcp",
|
|
52447
53197
|
"add",
|
|
52448
53198
|
"--scope",
|
|
@@ -52577,7 +53327,7 @@ var install = {
|
|
|
52577
53327
|
const pin = codexBinPin(bin);
|
|
52578
53328
|
let had = "";
|
|
52579
53329
|
try {
|
|
52580
|
-
had =
|
|
53330
|
+
had = readFileSync25(p.codexBin, "utf8");
|
|
52581
53331
|
} catch {
|
|
52582
53332
|
}
|
|
52583
53333
|
if (had !== pin) writeAtomic2(p.codexBin, pin, 384);
|
|
@@ -52607,7 +53357,7 @@ var uninstall = {
|
|
|
52607
53357
|
);
|
|
52608
53358
|
}
|
|
52609
53359
|
if (deps2.which("claude")) {
|
|
52610
|
-
const r = await
|
|
53360
|
+
const r = await run4(deps2, "claude", [
|
|
52611
53361
|
"mcp",
|
|
52612
53362
|
"remove",
|
|
52613
53363
|
"--scope",
|
|
@@ -52775,7 +53525,7 @@ function opencodeProxyProblem(deps2) {
|
|
|
52775
53525
|
const p = paths(deps2);
|
|
52776
53526
|
for (const f of p.opencodeConfigs.filter(present2))
|
|
52777
53527
|
try {
|
|
52778
|
-
for (const { name, entry } of proxyEntries(
|
|
53528
|
+
for (const { name, entry } of proxyEntries(readFileSync25(f, "utf8"))) {
|
|
52779
53529
|
const missing2 = proxyProgramMissing2(entry, void 0, deps2.which);
|
|
52780
53530
|
if (missing2 !== void 0) return { name, missing: missing2 };
|
|
52781
53531
|
}
|
|
@@ -52795,7 +53545,7 @@ function checkAdapters(deps2) {
|
|
|
52795
53545
|
const homeOf = (env2) => typeof env2 === "object" && env2 !== null ? env2.OA_BUS_HOME : void 0;
|
|
52796
53546
|
const homed = (file2) => {
|
|
52797
53547
|
if (!existsSync12(file2)) return false;
|
|
52798
|
-
const first =
|
|
53548
|
+
const first = readFileSync25(file2, "utf8").split("\n", 1)[0] ?? "";
|
|
52799
53549
|
const ob = movedHome(deps2);
|
|
52800
53550
|
return ob === void 0 ? !first.startsWith("process.env.OA_BUS_HOME ||=") : first === homeLine(ob);
|
|
52801
53551
|
};
|
|
@@ -52811,11 +53561,11 @@ function checkAdapters(deps2) {
|
|
|
52811
53561
|
opencode: state(
|
|
52812
53562
|
"opencode",
|
|
52813
53563
|
() => p.opencodeConfigs.filter(present2).some((f) => {
|
|
52814
|
-
const d = parseJsonc(
|
|
53564
|
+
const d = parseJsonc(readFileSync25(f, "utf8"), f);
|
|
52815
53565
|
const e = servers3(d)?.[NAME2] ?? d.mcp?.[NAME2];
|
|
52816
53566
|
return e !== void 0 && homeOf(e.environment) === movedHome(deps2);
|
|
52817
53567
|
}) && listed(
|
|
52818
|
-
parseJsonc(
|
|
53568
|
+
parseJsonc(readFileSync25(p.opencodeCli, "utf8"), p.opencodeCli),
|
|
52819
53569
|
p.opencodePlugin
|
|
52820
53570
|
) && homed(join27(p.opencodePlugin, "tui.js"))
|
|
52821
53571
|
),
|
|
@@ -52866,12 +53616,12 @@ function codexProxyProblem(deps2) {
|
|
|
52866
53616
|
import {
|
|
52867
53617
|
existsSync as existsSync13,
|
|
52868
53618
|
lstatSync as lstatSync16,
|
|
52869
|
-
readdirSync as
|
|
52870
|
-
readFileSync as
|
|
53619
|
+
readdirSync as readdirSync9,
|
|
53620
|
+
readFileSync as readFileSync26,
|
|
52871
53621
|
rmdirSync as rmdirSync3,
|
|
52872
53622
|
rmSync as rmSync15
|
|
52873
53623
|
} from "node:fs";
|
|
52874
|
-
import { dirname as
|
|
53624
|
+
import { dirname as dirname15, join as join28 } from "node:path";
|
|
52875
53625
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
52876
53626
|
var OUTPUT_STYLE_FILE = "artifacts-teammate.md";
|
|
52877
53627
|
var OUTPUT_STYLE_MARKER = "<!-- managed by the Open Artifacts bus installer: edits are replaced on reinstall. -->";
|
|
@@ -52891,7 +53641,7 @@ var outputStyleSource = () => {
|
|
|
52891
53641
|
"../../output-style/artifacts-teammate.md"
|
|
52892
53642
|
]) {
|
|
52893
53643
|
const path = fileURLToPath6(new URL(rel, import.meta.url));
|
|
52894
|
-
if (existsSync13(path)) return
|
|
53644
|
+
if (existsSync13(path)) return readFileSync26(path, "utf8");
|
|
52895
53645
|
}
|
|
52896
53646
|
throw new Error("the Artifacts Teammate output style is missing");
|
|
52897
53647
|
};
|
|
@@ -52925,7 +53675,7 @@ var readSettings = (path) => {
|
|
|
52925
53675
|
if (isLink2(path)) return { ok: false, why: "it is a symlink" };
|
|
52926
53676
|
if (!exists(path)) return { ok: true, text: void 0, style: void 0 };
|
|
52927
53677
|
try {
|
|
52928
|
-
const text3 =
|
|
53678
|
+
const text3 = readFileSync26(path, "utf8");
|
|
52929
53679
|
parseJsonc(text3, path);
|
|
52930
53680
|
return { ok: true, text: text3, style: jsoncValue(text3, ["outputStyle"]) };
|
|
52931
53681
|
} catch {
|
|
@@ -52987,7 +53737,7 @@ function installOutputStyle(deps2, harnesses) {
|
|
|
52987
53737
|
}
|
|
52988
53738
|
try {
|
|
52989
53739
|
const there = exists(path);
|
|
52990
|
-
if (there && !isOurs2(
|
|
53740
|
+
if (there && !isOurs2(readFileSync26(path, "utf8"))) {
|
|
52991
53741
|
out.notes.push(
|
|
52992
53742
|
`Left ${path} alone: it has no Open Artifacts marker, so it is not ours to replace.`
|
|
52993
53743
|
);
|
|
@@ -53039,7 +53789,7 @@ function uninstallOutputStyle(deps2) {
|
|
|
53039
53789
|
);
|
|
53040
53790
|
} else if (!exists(path)) {
|
|
53041
53791
|
gone = true;
|
|
53042
|
-
} else if (!isOurs2(
|
|
53792
|
+
} else if (!isOurs2(readFileSync26(path, "utf8"))) {
|
|
53043
53793
|
out.notes.push(
|
|
53044
53794
|
`Left ${path} alone: it has no Open Artifacts marker, so it is not ours to replace.`
|
|
53045
53795
|
);
|
|
@@ -53047,7 +53797,7 @@ function uninstallOutputStyle(deps2) {
|
|
|
53047
53797
|
rmSync15(path);
|
|
53048
53798
|
out.written.push(path);
|
|
53049
53799
|
gone = true;
|
|
53050
|
-
if (
|
|
53800
|
+
if (readdirSync9(dir).length === 0) rmdirSync3(dir);
|
|
53051
53801
|
}
|
|
53052
53802
|
} catch (e) {
|
|
53053
53803
|
out.notes.push(
|
|
@@ -53060,8 +53810,8 @@ function uninstallOutputStyle(deps2) {
|
|
|
53060
53810
|
var outputStyleState = (deps2) => {
|
|
53061
53811
|
const path = outputStyleFile(deps2);
|
|
53062
53812
|
try {
|
|
53063
|
-
if (isLink2(
|
|
53064
|
-
if (!isOurs2(
|
|
53813
|
+
if (isLink2(dirname15(path)) || isLink2(path)) return void 0;
|
|
53814
|
+
if (!isOurs2(readFileSync26(path, "utf8"))) return void 0;
|
|
53065
53815
|
const s = readSettings(claudeSettingsFile(deps2));
|
|
53066
53816
|
return { path, on: s.ok && s.style === OUTPUT_STYLE_NAME };
|
|
53067
53817
|
} catch {
|
|
@@ -53094,11 +53844,11 @@ function wired(ctx) {
|
|
|
53094
53844
|
};
|
|
53095
53845
|
}
|
|
53096
53846
|
var stamp = (ctx) => new Date(ctx.now()).toISOString();
|
|
53097
|
-
var
|
|
53847
|
+
var one2 = (ctx, f) => {
|
|
53098
53848
|
const link2 = linkInfo({ home: ctx.userHome }, f);
|
|
53099
53849
|
return link2 ? `${tilde(ctx, f)} (symlink to ${tilde(ctx, link2.target)}${link2.outside ? ", outside your home" : ""})` : tilde(ctx, f);
|
|
53100
53850
|
};
|
|
53101
|
-
var shown2 = (ctx, files2) => files2.map((f) =>
|
|
53851
|
+
var shown2 = (ctx, files2) => files2.map((f) => one2(ctx, f)).join(", ");
|
|
53102
53852
|
var pluginStateText = (ctx, p) => `${p.label} plugin: ${pluginHabitsState(deps(ctx), p)}`;
|
|
53103
53853
|
var show = (ctx) => {
|
|
53104
53854
|
say(
|
|
@@ -53155,7 +53905,7 @@ var pluginStates = (ctx) => Object.fromEntries(
|
|
|
53155
53905
|
PLUGIN_HARNESSES.map((p) => [p.name, pluginHabitsState(deps(ctx), p)])
|
|
53156
53906
|
);
|
|
53157
53907
|
function disclosure(ctx, pending) {
|
|
53158
|
-
const files2 = pending.map((p) => p.label ??
|
|
53908
|
+
const files2 = pending.map((p) => p.label ?? one2(ctx, p.path));
|
|
53159
53909
|
const changed = pending.filter((p) => p.s.state === "changed");
|
|
53160
53910
|
if (changed.length === 0)
|
|
53161
53911
|
return [
|
|
@@ -53204,7 +53954,7 @@ async function habitsAfterInstall(ctx, json3) {
|
|
|
53204
53954
|
const state = changed ? "changed" : "undecided";
|
|
53205
53955
|
const asked = pending.map((p) => p.path);
|
|
53206
53956
|
const question = habitsQuestion(
|
|
53207
|
-
pending.map((p) => p.label ??
|
|
53957
|
+
pending.map((p) => p.label ?? one2(ctx, p.path)),
|
|
53208
53958
|
// --json goes to an agent that may hand the commands to its user's own shell.
|
|
53209
53959
|
json3 ? BUS_CMD : ctx.busCmd
|
|
53210
53960
|
);
|
|
@@ -53286,12 +54036,12 @@ function habitsLine(ctx) {
|
|
|
53286
54036
|
(p) => plugins2.includes(p) || pluginHabitsState(deps(ctx), p) === "on"
|
|
53287
54037
|
);
|
|
53288
54038
|
const states = used.map((p) => pluginStateText(ctx, p));
|
|
53289
|
-
const
|
|
53290
|
-
if (on.length > 0) return `Habits: on in ${shown2(ctx, on)}${
|
|
54039
|
+
const tail2 = states.length > 0 ? `; ${states.join("; ")}` : "";
|
|
54040
|
+
if (on.length > 0) return `Habits: on in ${shown2(ctx, on)}${tail2}`;
|
|
53291
54041
|
if (used.some((p) => pluginHabitsState(deps(ctx), p) === "on"))
|
|
53292
54042
|
return `Habits: ${states.join("; ")}`;
|
|
53293
54043
|
if (targets.length > 0 || plugins2.length > 0)
|
|
53294
|
-
return `Habits: not decided (${ctx.busCmd} install --habits to add them)${
|
|
54044
|
+
return `Habits: not decided (${ctx.busCmd} install --habits to add them)${tail2}`;
|
|
53295
54045
|
return void 0;
|
|
53296
54046
|
}
|
|
53297
54047
|
|
|
@@ -53299,11 +54049,11 @@ function habitsLine(ctx) {
|
|
|
53299
54049
|
init_src();
|
|
53300
54050
|
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
53301
54051
|
import {
|
|
53302
|
-
chmodSync as
|
|
54052
|
+
chmodSync as chmodSync15,
|
|
53303
54053
|
closeSync as closeSync7,
|
|
53304
54054
|
mkdirSync as mkdirSync13,
|
|
53305
54055
|
openSync as openSync7,
|
|
53306
|
-
renameSync as
|
|
54056
|
+
renameSync as renameSync16,
|
|
53307
54057
|
rmSync as rmSync16,
|
|
53308
54058
|
unlinkSync as unlinkSync3,
|
|
53309
54059
|
writeSync as writeSync3
|
|
@@ -53355,7 +54105,7 @@ function checkVerificationUri(uri, hub) {
|
|
|
53355
54105
|
}
|
|
53356
54106
|
function writeMachineFile(home2, body) {
|
|
53357
54107
|
mkdirSync13(home2, { recursive: true, mode: 448 });
|
|
53358
|
-
|
|
54108
|
+
chmodSync15(home2, 448);
|
|
53359
54109
|
const tmp = join30(home2, `.machine.json.${randomBytes7(8).toString("hex")}.tmp`);
|
|
53360
54110
|
const fd = openSync7(tmp, "wx", 384);
|
|
53361
54111
|
try {
|
|
@@ -53367,8 +54117,8 @@ function writeMachineFile(home2, body) {
|
|
|
53367
54117
|
}
|
|
53368
54118
|
closeSync7(fd);
|
|
53369
54119
|
try {
|
|
53370
|
-
|
|
53371
|
-
|
|
54120
|
+
chmodSync15(tmp, 384);
|
|
54121
|
+
renameSync16(tmp, join30(home2, "machine.json"));
|
|
53372
54122
|
} catch (e) {
|
|
53373
54123
|
unlinkSync3(tmp);
|
|
53374
54124
|
throw e;
|
|
@@ -53519,7 +54269,7 @@ init_src();
|
|
|
53519
54269
|
|
|
53520
54270
|
// src/commands/install.ts
|
|
53521
54271
|
init_src3();
|
|
53522
|
-
import { dirname as
|
|
54272
|
+
import { dirname as dirname16, join as join31 } from "node:path";
|
|
53523
54273
|
init_src2();
|
|
53524
54274
|
|
|
53525
54275
|
// src/live.ts
|
|
@@ -53922,7 +54672,7 @@ function reportShim(ctx) {
|
|
|
53922
54672
|
if (r.kind === "installed") {
|
|
53923
54673
|
say(ctx, ctx.copy.shimInstalled(tilde(ctx, r.path)));
|
|
53924
54674
|
if (!r.onPath && r.hint)
|
|
53925
|
-
say(ctx, ctx.copy.shimNotOnPath(tilde(ctx,
|
|
54675
|
+
say(ctx, ctx.copy.shimNotOnPath(tilde(ctx, dirname16(r.path)), r.hint));
|
|
53926
54676
|
} else if (r.kind === "other-home")
|
|
53927
54677
|
say(ctx, ctx.copy.shimOtherHome(tilde(ctx, r.path), tilde(ctx, r.home)));
|
|
53928
54678
|
else if (r.kind === "foreign")
|
|
@@ -54139,7 +54889,7 @@ async function healthz(ctx, hub) {
|
|
|
54139
54889
|
function claudeIsolates(path) {
|
|
54140
54890
|
let text3;
|
|
54141
54891
|
try {
|
|
54142
|
-
text3 =
|
|
54892
|
+
text3 = readFileSync27(path, "utf8");
|
|
54143
54893
|
} catch {
|
|
54144
54894
|
return void 0;
|
|
54145
54895
|
}
|
|
@@ -54437,12 +55187,12 @@ async function global(opts, ctx) {
|
|
|
54437
55187
|
}
|
|
54438
55188
|
|
|
54439
55189
|
// src/commands/leads.ts
|
|
54440
|
-
import { readFileSync as
|
|
55190
|
+
import { readFileSync as readFileSync28 } from "node:fs";
|
|
54441
55191
|
import { join as join33 } from "node:path";
|
|
54442
55192
|
function hubOrigin(ctx) {
|
|
54443
55193
|
try {
|
|
54444
55194
|
const raw = JSON.parse(
|
|
54445
|
-
|
|
55195
|
+
readFileSync28(join33(ctx.home, "machine.json"), "utf8")
|
|
54446
55196
|
);
|
|
54447
55197
|
return typeof raw?.hub === "string" ? new URL(raw.hub).origin : void 0;
|
|
54448
55198
|
} catch {
|
|
@@ -54595,20 +55345,28 @@ async function link(opts, ctx) {
|
|
|
54595
55345
|
}
|
|
54596
55346
|
|
|
54597
55347
|
// src/commands/logs.ts
|
|
54598
|
-
import { readFileSync as
|
|
55348
|
+
import { readFileSync as readFileSync29 } from "node:fs";
|
|
54599
55349
|
import { join as join34 } from "node:path";
|
|
54600
55350
|
var TAIL = 50;
|
|
54601
|
-
|
|
54602
|
-
const path = join34(ctx.home, "logs", "daemon.log");
|
|
54603
|
-
let text3;
|
|
55351
|
+
var tail = (path) => {
|
|
54604
55352
|
try {
|
|
54605
|
-
|
|
55353
|
+
return readFileSync29(path, "utf8").replace(/\n$/, "").split("\n").slice(-TAIL);
|
|
54606
55354
|
} catch {
|
|
55355
|
+
return void 0;
|
|
55356
|
+
}
|
|
55357
|
+
};
|
|
55358
|
+
async function logs(ctx) {
|
|
55359
|
+
const path = join34(ctx.home, "logs", "daemon.log");
|
|
55360
|
+
const daemon2 = tail(path);
|
|
55361
|
+
const events = tail(join34(ctx.home, "logs", "events.log"));
|
|
55362
|
+
if (!daemon2 && !events) {
|
|
54607
55363
|
say(ctx, ctx.copy.noLog(tilde(ctx, path)));
|
|
54608
55364
|
return 1;
|
|
54609
55365
|
}
|
|
54610
|
-
|
|
54611
|
-
|
|
55366
|
+
say(
|
|
55367
|
+
ctx,
|
|
55368
|
+
daemon2 && events ? [...daemon2, "--- events.log ---", ...events] : daemon2 ?? events ?? []
|
|
55369
|
+
);
|
|
54612
55370
|
return 0;
|
|
54613
55371
|
}
|
|
54614
55372
|
|
|
@@ -54631,9 +55389,9 @@ async function mcp(harness, ctx, load = (h) => MCP_SERVER[h]()) {
|
|
|
54631
55389
|
init_src3();
|
|
54632
55390
|
init_src2();
|
|
54633
55391
|
init_src();
|
|
54634
|
-
import { execFileSync as
|
|
55392
|
+
import { execFileSync as execFileSync7 } from "node:child_process";
|
|
54635
55393
|
import { createHash as createHash8, randomBytes as randomBytes8 } from "node:crypto";
|
|
54636
|
-
import { readFileSync as
|
|
55394
|
+
import { readFileSync as readFileSync30, readlinkSync as readlinkSync6 } from "node:fs";
|
|
54637
55395
|
import { basename as basename8 } from "node:path";
|
|
54638
55396
|
var isClaude = (name) => name === "claude" || /\/claude\/versions\/[^/]+$/.test(name);
|
|
54639
55397
|
function parsePs(out) {
|
|
@@ -54644,19 +55402,19 @@ function parsePs(out) {
|
|
|
54644
55402
|
}
|
|
54645
55403
|
function readProc(pid) {
|
|
54646
55404
|
try {
|
|
54647
|
-
const stat =
|
|
55405
|
+
const stat = readFileSync30(`/proc/${pid}/stat`, "utf8");
|
|
54648
55406
|
const ppid = Number(stat.slice(stat.lastIndexOf(")") + 1).split(/\s+/)[2]);
|
|
54649
55407
|
let exe = "";
|
|
54650
55408
|
try {
|
|
54651
|
-
exe =
|
|
55409
|
+
exe = readlinkSync6(`/proc/${pid}/exe`);
|
|
54652
55410
|
} catch {
|
|
54653
55411
|
}
|
|
54654
|
-
const comm =
|
|
55412
|
+
const comm = readFileSync30(`/proc/${pid}/comm`, "utf8").trim();
|
|
54655
55413
|
return { ppid, name: isClaude(exe) ? exe : comm };
|
|
54656
55414
|
} catch {
|
|
54657
55415
|
}
|
|
54658
55416
|
try {
|
|
54659
|
-
const out =
|
|
55417
|
+
const out = execFileSync7(
|
|
54660
55418
|
systemTool("ps"),
|
|
54661
55419
|
["-o", "ppid=,comm=", "-p", String(pid)],
|
|
54662
55420
|
{ encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }
|
|
@@ -54679,7 +55437,7 @@ function findClaude(from, proc) {
|
|
|
54679
55437
|
function tokenOf(file2) {
|
|
54680
55438
|
if (!file2) return void 0;
|
|
54681
55439
|
try {
|
|
54682
|
-
return
|
|
55440
|
+
return readFileSync30(file2, "utf8").trim() || void 0;
|
|
54683
55441
|
} catch {
|
|
54684
55442
|
return void 0;
|
|
54685
55443
|
}
|
|
@@ -54840,7 +55598,7 @@ import { join as join37 } from "node:path";
|
|
|
54840
55598
|
|
|
54841
55599
|
// src/steps/purge.ts
|
|
54842
55600
|
init_src3();
|
|
54843
|
-
import { lstatSync as lstatSync17, readdirSync as
|
|
55601
|
+
import { lstatSync as lstatSync17, readdirSync as readdirSync10, rmdirSync as rmdirSync4, rmSync as rmSync17 } from "node:fs";
|
|
54844
55602
|
import { join as join36 } from "node:path";
|
|
54845
55603
|
var FILES = [
|
|
54846
55604
|
"machine.json",
|
|
@@ -54897,7 +55655,7 @@ function purgeShort(dir, removed) {
|
|
|
54897
55655
|
[dir, (n) => /^daemon\.sock(\.keep-\d+)?$/.test(n)]
|
|
54898
55656
|
]) {
|
|
54899
55657
|
if (kind3(d) !== "dir") continue;
|
|
54900
|
-
for (const name of
|
|
55658
|
+
for (const name of readdirSync10(d)) {
|
|
54901
55659
|
const path = join36(d, name);
|
|
54902
55660
|
const k = kind3(path);
|
|
54903
55661
|
if (k === void 0 || k === "dir" || !ours2(name, path)) continue;
|
|
@@ -54911,7 +55669,7 @@ function purgeShort(dir, removed) {
|
|
|
54911
55669
|
function purge(home2, opts) {
|
|
54912
55670
|
let entries;
|
|
54913
55671
|
try {
|
|
54914
|
-
entries =
|
|
55672
|
+
entries = readdirSync10(home2);
|
|
54915
55673
|
} catch {
|
|
54916
55674
|
return { removed: [], leftDir: false };
|
|
54917
55675
|
}
|
|
@@ -54932,7 +55690,7 @@ function purge(home2, opts) {
|
|
|
54932
55690
|
for (const folder of FOLDERS) {
|
|
54933
55691
|
const dir = join36(home2, folder.path);
|
|
54934
55692
|
if (kind3(dir) !== "dir") continue;
|
|
54935
|
-
for (const name of
|
|
55693
|
+
for (const name of readdirSync10(dir)) {
|
|
54936
55694
|
const path = join36(dir, name);
|
|
54937
55695
|
const k = kind3(path);
|
|
54938
55696
|
if (k === void 0 || !folder.ours(name, path)) continue;
|