@open-artifacts/bus 0.127.0 → 0.128.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 +3 -2
- package/dist/index.js +812 -427
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4586,7 +4586,7 @@ function isRef(value) {
|
|
|
4586
4586
|
function cloneIssues(issues) {
|
|
4587
4587
|
return issues.map((iss) => iss.path ? { ...iss, path: iss.path.slice() } : { ...iss });
|
|
4588
4588
|
}
|
|
4589
|
-
function isRecursive(inst, stack,
|
|
4589
|
+
function isRecursive(inst, stack, resolve9) {
|
|
4590
4590
|
const cached2 = recursive.get(inst);
|
|
4591
4591
|
if (cached2 !== void 0)
|
|
4592
4592
|
return cached2 ? PROVEN : NONE;
|
|
@@ -4596,7 +4596,7 @@ function isRecursive(inst, stack, resolve8) {
|
|
|
4596
4596
|
let result = NONE;
|
|
4597
4597
|
const check2 = (child) => {
|
|
4598
4598
|
if (result !== PROVEN && child?._zod) {
|
|
4599
|
-
const answer = isRecursive(child, stack,
|
|
4599
|
+
const answer = isRecursive(child, stack, resolve9);
|
|
4600
4600
|
if (answer > result)
|
|
4601
4601
|
result = answer;
|
|
4602
4602
|
}
|
|
@@ -4607,7 +4607,7 @@ function isRecursive(inst, stack, resolve8) {
|
|
|
4607
4607
|
const desc = Object.getOwnPropertyDescriptor(sh, key2);
|
|
4608
4608
|
if (spread && !desc.enumerable)
|
|
4609
4609
|
continue;
|
|
4610
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
4610
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve9) : NONE;
|
|
4611
4611
|
if (child > answer)
|
|
4612
4612
|
answer = child;
|
|
4613
4613
|
}
|
|
@@ -4671,7 +4671,7 @@ function isRecursive(inst, stack, resolve8) {
|
|
|
4671
4671
|
break;
|
|
4672
4672
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
4673
4673
|
case "lazy": {
|
|
4674
|
-
const inner = def._cachedInner ?? (
|
|
4674
|
+
const inner = def._cachedInner ?? (resolve9 ? inst._zod.innerType : void 0);
|
|
4675
4675
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
4676
4676
|
break;
|
|
4677
4677
|
}
|
|
@@ -23038,7 +23038,7 @@ var init_protocol = __esm({
|
|
|
23038
23038
|
return;
|
|
23039
23039
|
}
|
|
23040
23040
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
23041
|
-
await new Promise((
|
|
23041
|
+
await new Promise((resolve9) => setTimeout(resolve9, pollInterval));
|
|
23042
23042
|
options?.signal?.throwIfAborted();
|
|
23043
23043
|
}
|
|
23044
23044
|
} catch (error62) {
|
|
@@ -23055,7 +23055,7 @@ var init_protocol = __esm({
|
|
|
23055
23055
|
*/
|
|
23056
23056
|
request(request, resultSchema, options) {
|
|
23057
23057
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
23058
|
-
return new Promise((
|
|
23058
|
+
return new Promise((resolve9, reject) => {
|
|
23059
23059
|
const earlyReject = (error62) => {
|
|
23060
23060
|
reject(error62);
|
|
23061
23061
|
};
|
|
@@ -23133,7 +23133,7 @@ var init_protocol = __esm({
|
|
|
23133
23133
|
if (!parseResult.success) {
|
|
23134
23134
|
reject(parseResult.error);
|
|
23135
23135
|
} else {
|
|
23136
|
-
|
|
23136
|
+
resolve9(parseResult.data);
|
|
23137
23137
|
}
|
|
23138
23138
|
} catch (error62) {
|
|
23139
23139
|
reject(error62);
|
|
@@ -23395,12 +23395,12 @@ var init_protocol = __esm({
|
|
|
23395
23395
|
}
|
|
23396
23396
|
} catch {
|
|
23397
23397
|
}
|
|
23398
|
-
return new Promise((
|
|
23398
|
+
return new Promise((resolve9, reject) => {
|
|
23399
23399
|
if (signal.aborted) {
|
|
23400
23400
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
23401
23401
|
return;
|
|
23402
23402
|
}
|
|
23403
|
-
const timeoutId = setTimeout(
|
|
23403
|
+
const timeoutId = setTimeout(resolve9, interval);
|
|
23404
23404
|
signal.addEventListener("abort", () => {
|
|
23405
23405
|
clearTimeout(timeoutId);
|
|
23406
23406
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -26427,7 +26427,7 @@ var require_compile = __commonJS({
|
|
|
26427
26427
|
const schOrFunc = root.refs[ref];
|
|
26428
26428
|
if (schOrFunc)
|
|
26429
26429
|
return schOrFunc;
|
|
26430
|
-
let _sch =
|
|
26430
|
+
let _sch = resolve9.call(this, root, ref);
|
|
26431
26431
|
if (_sch === void 0) {
|
|
26432
26432
|
const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
|
|
26433
26433
|
const { schemaId } = this.opts;
|
|
@@ -26454,7 +26454,7 @@ var require_compile = __commonJS({
|
|
|
26454
26454
|
function sameSchemaEnv(s1, s2) {
|
|
26455
26455
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
26456
26456
|
}
|
|
26457
|
-
function
|
|
26457
|
+
function resolve9(root, ref) {
|
|
26458
26458
|
let sch;
|
|
26459
26459
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
26460
26460
|
ref = sch;
|
|
@@ -27284,7 +27284,7 @@ var require_fast_uri = __commonJS({
|
|
|
27284
27284
|
}
|
|
27285
27285
|
return uri;
|
|
27286
27286
|
}
|
|
27287
|
-
function
|
|
27287
|
+
function resolve9(baseURI, relativeURI, options) {
|
|
27288
27288
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
27289
27289
|
const {
|
|
27290
27290
|
parsed: baseParsed,
|
|
@@ -27653,7 +27653,7 @@ var require_fast_uri = __commonJS({
|
|
|
27653
27653
|
var fastUri = {
|
|
27654
27654
|
SCHEMES,
|
|
27655
27655
|
normalize,
|
|
27656
|
-
resolve:
|
|
27656
|
+
resolve: resolve9,
|
|
27657
27657
|
resolveComponent,
|
|
27658
27658
|
equal,
|
|
27659
27659
|
serialize,
|
|
@@ -32409,11 +32409,20 @@ var init_frames = __esm({
|
|
|
32409
32409
|
late = { late: external_exports.array(external_exports.string().min(1)).optional() };
|
|
32410
32410
|
isWellFormed2 = (s) => s.isWellFormed();
|
|
32411
32411
|
WELL_FORMED = { message: "text is not well-formed unicode" };
|
|
32412
|
-
CLIENT_VERSION = true ? "0.
|
|
32412
|
+
CLIENT_VERSION = true ? "0.128.0" : "0.0.0";
|
|
32413
32413
|
clientVersion = {
|
|
32414
32414
|
client_version: external_exports.string().min(1).max(64).optional()
|
|
32415
32415
|
};
|
|
32416
|
-
ADAPTER_CAPS = {
|
|
32416
|
+
ADAPTER_CAPS = {
|
|
32417
|
+
mailbox: "mailbox",
|
|
32418
|
+
/**
|
|
32419
|
+
* `pending` (#1525): a `config_files` entry with `state: "pending"`, a
|
|
32420
|
+
* namespace waiting for the user's approval. An older strict decoder would
|
|
32421
|
+
* reject the whole frame on it, so the daemon sends it only to a client that
|
|
32422
|
+
* listed this.
|
|
32423
|
+
*/
|
|
32424
|
+
pending: "pending"
|
|
32425
|
+
};
|
|
32417
32426
|
Hello2 = external_exports.object({
|
|
32418
32427
|
...base2,
|
|
32419
32428
|
...clientVersion,
|
|
@@ -32514,7 +32523,9 @@ var init_frames = __esm({
|
|
|
32514
32523
|
...base2,
|
|
32515
32524
|
...clientVersion,
|
|
32516
32525
|
type: external_exports.literal("status"),
|
|
32517
|
-
cwd: external_exports.string().min(1).max(4096).optional()
|
|
32526
|
+
cwd: external_exports.string().min(1).max(4096).optional(),
|
|
32527
|
+
/** What this client can decode (ADAPTER_CAPS); absent means none. */
|
|
32528
|
+
caps: external_exports.array(external_exports.string().max(32)).max(16).optional()
|
|
32518
32529
|
});
|
|
32519
32530
|
AdapterFrame = external_exports.discriminatedUnion("type", [
|
|
32520
32531
|
Hello2,
|
|
@@ -32527,7 +32538,8 @@ var init_frames = __esm({
|
|
|
32527
32538
|
]);
|
|
32528
32539
|
ConfigFile = external_exports.object({
|
|
32529
32540
|
file: external_exports.string(),
|
|
32530
|
-
|
|
32541
|
+
/** `pending` (#1525) goes only to clients that listed ADAPTER_CAPS.pending. */
|
|
32542
|
+
state: external_exports.enum(["refused", "noted", "pending"]),
|
|
32531
32543
|
reason: external_exports.string(),
|
|
32532
32544
|
fix: external_exports.string()
|
|
32533
32545
|
});
|
|
@@ -32731,8 +32743,8 @@ var init_lines = __esm({
|
|
|
32731
32743
|
import { connect } from "node:net";
|
|
32732
32744
|
async function connectDaemon(opts) {
|
|
32733
32745
|
const sock = connect(opts.path);
|
|
32734
|
-
await new Promise((
|
|
32735
|
-
sock.once("connect",
|
|
32746
|
+
await new Promise((resolve9, reject) => {
|
|
32747
|
+
sock.once("connect", resolve9);
|
|
32736
32748
|
sock.once("error", reject);
|
|
32737
32749
|
});
|
|
32738
32750
|
const decoder = new LineDecoder();
|
|
@@ -32792,8 +32804,8 @@ async function connectDaemon(opts) {
|
|
|
32792
32804
|
sock.on("error", (e) => failAll(e));
|
|
32793
32805
|
sock.on("close", () => failAll(new Error("daemon connection closed")));
|
|
32794
32806
|
let timer;
|
|
32795
|
-
const welcomeRaw = await new Promise((
|
|
32796
|
-
waiters.push({ resolve:
|
|
32807
|
+
const welcomeRaw = await new Promise((resolve9, reject) => {
|
|
32808
|
+
waiters.push({ resolve: resolve9, reject });
|
|
32797
32809
|
timer = setTimeout(() => {
|
|
32798
32810
|
reject(new Error("daemon did not answer hello"));
|
|
32799
32811
|
sock.destroy();
|
|
@@ -32815,7 +32827,7 @@ async function connectDaemon(opts) {
|
|
|
32815
32827
|
if (state === "closed")
|
|
32816
32828
|
return Promise.reject(new Error("daemon connection closed"));
|
|
32817
32829
|
const id = partial2.id ?? String(++seq2);
|
|
32818
|
-
return new Promise((
|
|
32830
|
+
return new Promise((resolve9, reject) => {
|
|
32819
32831
|
const ms = opts.requestTimeoutMs ?? 2e4;
|
|
32820
32832
|
const timer2 = setTimeout(() => {
|
|
32821
32833
|
if (pending.delete(id))
|
|
@@ -32830,7 +32842,7 @@ async function connectDaemon(opts) {
|
|
|
32830
32842
|
clearTimeout(timer2);
|
|
32831
32843
|
f(...a);
|
|
32832
32844
|
};
|
|
32833
|
-
pending.set(id, { resolve: done(
|
|
32845
|
+
pending.set(id, { resolve: done(resolve9), reject: done(reject) });
|
|
32834
32846
|
sock.write(`${JSON.stringify({ v: 1, ...partial2, id })}
|
|
32835
32847
|
`);
|
|
32836
32848
|
});
|
|
@@ -32854,7 +32866,7 @@ async function connectDaemon(opts) {
|
|
|
32854
32866
|
};
|
|
32855
32867
|
}
|
|
32856
32868
|
function daemonStatus(opts) {
|
|
32857
|
-
return new Promise((
|
|
32869
|
+
return new Promise((resolve9, reject) => {
|
|
32858
32870
|
const sock = connect(opts.path);
|
|
32859
32871
|
const decoder = new LineDecoder();
|
|
32860
32872
|
const done = (f) => {
|
|
@@ -32883,7 +32895,7 @@ function daemonStatus(opts) {
|
|
|
32883
32895
|
sock.once(
|
|
32884
32896
|
"connect",
|
|
32885
32897
|
() => sock.write(
|
|
32886
|
-
`${JSON.stringify({ v: 1, id: "status", type: "status", client_version: CLIENT_VERSION, ...opts.cwd ? { cwd: opts.cwd } : {} })}
|
|
32898
|
+
`${JSON.stringify({ v: 1, id: "status", type: "status", client_version: CLIENT_VERSION, caps: [ADAPTER_CAPS.pending], ...opts.cwd ? { cwd: opts.cwd } : {} })}
|
|
32887
32899
|
`
|
|
32888
32900
|
)
|
|
32889
32901
|
);
|
|
@@ -32891,7 +32903,7 @@ function daemonStatus(opts) {
|
|
|
32891
32903
|
try {
|
|
32892
32904
|
for (const raw of decoder.push(chunk)) {
|
|
32893
32905
|
const f = DaemonFrame.parse(raw);
|
|
32894
|
-
if (f.type === "status") return done(() =>
|
|
32906
|
+
if (f.type === "status") return done(() => resolve9(f));
|
|
32895
32907
|
if (f.type === "error")
|
|
32896
32908
|
return done(
|
|
32897
32909
|
() => reject(
|
|
@@ -33056,13 +33068,13 @@ function selfText(agent) {
|
|
|
33056
33068
|
if (!agent) return JSON.stringify(agent, null, 2);
|
|
33057
33069
|
const { status: _s, status_label: _l, status_at: _a3, ...rest } = agent;
|
|
33058
33070
|
const label = typeof agent.status_label === "string" ? displayLabel(agent.status_label) : "";
|
|
33059
|
-
const
|
|
33071
|
+
const shown3 = {
|
|
33060
33072
|
...rest,
|
|
33061
33073
|
...typeof agent.status === "string" ? { status: displayKind(agent.status) } : {},
|
|
33062
33074
|
...label ? { status_label: label } : {},
|
|
33063
33075
|
...typeof agent.status_at === "string" && !Number.isNaN(Date.parse(agent.status_at)) ? { status_at: agent.status_at } : {}
|
|
33064
33076
|
};
|
|
33065
|
-
return JSON.stringify(
|
|
33077
|
+
return JSON.stringify(shown3, null, 2);
|
|
33066
33078
|
}
|
|
33067
33079
|
var MAX_COLS, RETAIN, MB, refusals, quoted, TERMINAL_CONTROLS, CUT_OFF, stripTerminalControls, KIND_CHARS, displayKind, neutralizeBody, deliveredText, oversizedText, INVISIBLES, EXCERPT_CHARS, STATUS_COPY, BAD_LABEL_CHARS2, cleanStatusLabel, statusLabelTooLong, statusSetText, earlierStatusText, STATUS_STALE_MS, agoText, displayLabel, awayTime, replyGoneText;
|
|
33068
33080
|
var init_copy = __esm({
|
|
@@ -33207,13 +33219,13 @@ async function clearStale(path) {
|
|
|
33207
33219
|
code: "ENOTSOCK"
|
|
33208
33220
|
});
|
|
33209
33221
|
}
|
|
33210
|
-
const live = await new Promise((
|
|
33222
|
+
const live = await new Promise((resolve9) => {
|
|
33211
33223
|
const probe = connect2(path);
|
|
33212
33224
|
probe.once("connect", () => {
|
|
33213
33225
|
probe.destroy();
|
|
33214
|
-
|
|
33226
|
+
resolve9(true);
|
|
33215
33227
|
});
|
|
33216
|
-
probe.once("error", () =>
|
|
33228
|
+
probe.once("error", () => resolve9(false));
|
|
33217
33229
|
});
|
|
33218
33230
|
if (live) {
|
|
33219
33231
|
throw Object.assign(new Error(`daemon already listening on ${path}`), {
|
|
@@ -33233,16 +33245,16 @@ async function serveDaemon(opts) {
|
|
|
33233
33245
|
sock.once("close", () => sockets.delete(sock));
|
|
33234
33246
|
handle(sock, opts);
|
|
33235
33247
|
});
|
|
33236
|
-
await new Promise((
|
|
33248
|
+
await new Promise((resolve9, reject) => {
|
|
33237
33249
|
server4.once("error", reject);
|
|
33238
|
-
server4.listen(opts.path, () =>
|
|
33250
|
+
server4.listen(opts.path, () => resolve9());
|
|
33239
33251
|
});
|
|
33240
33252
|
chmodSync(opts.path, 384);
|
|
33241
33253
|
const st = statSync(opts.path);
|
|
33242
33254
|
const mode = st.mode & 511;
|
|
33243
33255
|
return {
|
|
33244
33256
|
mode,
|
|
33245
|
-
close: () => new Promise((
|
|
33257
|
+
close: () => new Promise((resolve9) => {
|
|
33246
33258
|
for (const s of sockets) s.destroy();
|
|
33247
33259
|
let parked;
|
|
33248
33260
|
try {
|
|
@@ -33260,7 +33272,7 @@ async function serveDaemon(opts) {
|
|
|
33260
33272
|
} catch {
|
|
33261
33273
|
}
|
|
33262
33274
|
}
|
|
33263
|
-
|
|
33275
|
+
resolve9();
|
|
33264
33276
|
});
|
|
33265
33277
|
})
|
|
33266
33278
|
};
|
|
@@ -33537,17 +33549,17 @@ async function run(name, args, request) {
|
|
|
33537
33549
|
const to = String(args.to ?? "");
|
|
33538
33550
|
const body = String(args.text ?? "");
|
|
33539
33551
|
if (!to || !body) return text("oa-bus: to and text are required", true);
|
|
33540
|
-
const
|
|
33552
|
+
const namespace2 = typeof args.to_namespace === "string" && args.to_namespace ? args.to_namespace : void 0;
|
|
33541
33553
|
const r = await request({
|
|
33542
33554
|
type: "send",
|
|
33543
33555
|
to,
|
|
33544
33556
|
body,
|
|
33545
|
-
...
|
|
33557
|
+
...namespace2 ? { namespace: namespace2 } : {}
|
|
33546
33558
|
});
|
|
33547
33559
|
if (r.type !== "receipt") return failed(r);
|
|
33548
33560
|
if (r.text) return text(r.text, false);
|
|
33549
33561
|
const n = r.reason === "ambiguous" ? await namespacesOf(to, request) : void 0;
|
|
33550
|
-
const moved = r.reason === "revoked" ? await movedTo(to,
|
|
33562
|
+
const moved = r.reason === "revoked" ? await movedTo(to, namespace2, request) : void 0;
|
|
33551
33563
|
return text(
|
|
33552
33564
|
receiptText(r, to, n, excerptOf(body), moved),
|
|
33553
33565
|
r.state === "refused" || r.state === "expired"
|
|
@@ -33617,13 +33629,13 @@ async function namespacesOf(name, request) {
|
|
|
33617
33629
|
return void 0;
|
|
33618
33630
|
}
|
|
33619
33631
|
}
|
|
33620
|
-
async function movedTo(name,
|
|
33632
|
+
async function movedTo(name, namespace2, request) {
|
|
33621
33633
|
try {
|
|
33622
33634
|
const r = await request({ type: "list" });
|
|
33623
33635
|
if (r.type !== "roster") return void 0;
|
|
33624
33636
|
return movedName(
|
|
33625
33637
|
name,
|
|
33626
|
-
r.agents.filter((a) =>
|
|
33638
|
+
r.agents.filter((a) => namespace2 === void 0 || a.namespace === namespace2).map((a) => a.name)
|
|
33627
33639
|
);
|
|
33628
33640
|
} catch {
|
|
33629
33641
|
return void 0;
|
|
@@ -33758,7 +33770,7 @@ function codexHello(call, pid, ppid) {
|
|
|
33758
33770
|
pid,
|
|
33759
33771
|
...call.cwd ? { cwd: call.cwd } : {},
|
|
33760
33772
|
proposed_name: "codex",
|
|
33761
|
-
caps: [ADAPTER_CAPS.mailbox],
|
|
33773
|
+
caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
|
|
33762
33774
|
codex: {
|
|
33763
33775
|
thread_id: call.threadId,
|
|
33764
33776
|
call_id: call.callId,
|
|
@@ -33857,7 +33869,7 @@ ${neutralize(a.text)}
|
|
|
33857
33869
|
};
|
|
33858
33870
|
}
|
|
33859
33871
|
function inject(a) {
|
|
33860
|
-
return new Promise((
|
|
33872
|
+
return new Promise((resolve9, reject) => {
|
|
33861
33873
|
const sock = connect3(a.socketPath);
|
|
33862
33874
|
let connected = false;
|
|
33863
33875
|
const fail = (e) => {
|
|
@@ -33881,7 +33893,7 @@ function inject(a) {
|
|
|
33881
33893
|
sock.once("finish", () => {
|
|
33882
33894
|
clearTimeout(timer);
|
|
33883
33895
|
sock.destroy();
|
|
33884
|
-
|
|
33896
|
+
resolve9();
|
|
33885
33897
|
});
|
|
33886
33898
|
sock.end(`${JSON.stringify(frameOf(a))}
|
|
33887
33899
|
`);
|
|
@@ -34001,7 +34013,7 @@ function sessionHello(session, pid, cwd) {
|
|
|
34001
34013
|
pid,
|
|
34002
34014
|
cwd,
|
|
34003
34015
|
proposed_name: fitName(session.name, 64) || void 0,
|
|
34004
|
-
caps: [ADAPTER_CAPS.mailbox],
|
|
34016
|
+
caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
|
|
34005
34017
|
attest: {
|
|
34006
34018
|
session_id: session.sessionId,
|
|
34007
34019
|
socket_path: session.socketPath ?? void 0
|
|
@@ -36378,7 +36390,7 @@ var require_websocket = __commonJS({
|
|
|
36378
36390
|
var http = __require("http");
|
|
36379
36391
|
var net = __require("net");
|
|
36380
36392
|
var tls = __require("tls");
|
|
36381
|
-
var { randomBytes:
|
|
36393
|
+
var { randomBytes: randomBytes5, createHash: createHash6 } = __require("crypto");
|
|
36382
36394
|
var { Duplex, Readable } = __require("stream");
|
|
36383
36395
|
var { URL: URL2 } = __require("url");
|
|
36384
36396
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -36916,7 +36928,7 @@ var require_websocket = __commonJS({
|
|
|
36916
36928
|
}
|
|
36917
36929
|
}
|
|
36918
36930
|
const defaultPort = isSecure ? 443 : 80;
|
|
36919
|
-
const key2 =
|
|
36931
|
+
const key2 = randomBytes5(16).toString("base64");
|
|
36920
36932
|
const request = isSecure ? https.request : http.request;
|
|
36921
36933
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
36922
36934
|
let perMessageDeflate;
|
|
@@ -37811,12 +37823,12 @@ var require_websocket_server = __commonJS({
|
|
|
37811
37823
|
|
|
37812
37824
|
// ../bus-adapter-opencode/src/session.ts
|
|
37813
37825
|
import { execFile as execFile4 } from "node:child_process";
|
|
37814
|
-
import { isAbsolute as
|
|
37826
|
+
import { isAbsolute as isAbsolute8 } from "node:path";
|
|
37815
37827
|
import { promisify as promisify2 } from "node:util";
|
|
37816
37828
|
function directoryOf(s) {
|
|
37817
37829
|
const loc = s.location;
|
|
37818
37830
|
const dir = s.directory ?? loc?.directory;
|
|
37819
|
-
return typeof dir === "string" &&
|
|
37831
|
+
return typeof dir === "string" && isAbsolute8(dir) ? dir : null;
|
|
37820
37832
|
}
|
|
37821
37833
|
async function rootSession(sessionId, deps) {
|
|
37822
37834
|
const cache = deps.cache ?? ROOTS;
|
|
@@ -37894,7 +37906,7 @@ async function handleToolCall(input2) {
|
|
|
37894
37906
|
pid: process.pid,
|
|
37895
37907
|
cwd: session.directory,
|
|
37896
37908
|
proposed_name: nameOf(session.title),
|
|
37897
|
-
caps: [ADAPTER_CAPS.mailbox],
|
|
37909
|
+
caps: [ADAPTER_CAPS.mailbox, ADAPTER_CAPS.pending],
|
|
37898
37910
|
attest: { session_id: sessionId }
|
|
37899
37911
|
});
|
|
37900
37912
|
let client;
|
|
@@ -38034,12 +38046,12 @@ var init_stdio2 = __esm({
|
|
|
38034
38046
|
this.onclose?.();
|
|
38035
38047
|
}
|
|
38036
38048
|
send(message) {
|
|
38037
|
-
return new Promise((
|
|
38049
|
+
return new Promise((resolve9) => {
|
|
38038
38050
|
const json3 = serializeMessage(message);
|
|
38039
38051
|
if (this._stdout.write(json3)) {
|
|
38040
|
-
|
|
38052
|
+
resolve9();
|
|
38041
38053
|
} else {
|
|
38042
|
-
this._stdout.once("drain",
|
|
38054
|
+
this._stdout.once("drain", resolve9);
|
|
38043
38055
|
}
|
|
38044
38056
|
});
|
|
38045
38057
|
}
|
|
@@ -38208,16 +38220,16 @@ var harnessSkills = {
|
|
|
38208
38220
|
var harnessNames = Object.keys(harnessSkills);
|
|
38209
38221
|
|
|
38210
38222
|
// src/main.ts
|
|
38211
|
-
import { resolve as
|
|
38223
|
+
import { resolve as resolve8 } from "node:path";
|
|
38212
38224
|
|
|
38213
38225
|
// src/commands/daemon.ts
|
|
38214
38226
|
import { existsSync as existsSync4 } from "node:fs";
|
|
38215
|
-
import { join as
|
|
38227
|
+
import { join as join16 } from "node:path";
|
|
38216
38228
|
|
|
38217
38229
|
// ../bus-daemon/src/index.ts
|
|
38218
38230
|
init_src3();
|
|
38219
38231
|
import { lstatSync as lstatSync6, realpathSync as realpathSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
38220
|
-
import { basename as basename5, isAbsolute as
|
|
38232
|
+
import { basename as basename5, isAbsolute as isAbsolute6, join as join12 } from "node:path";
|
|
38221
38233
|
|
|
38222
38234
|
// ../bus-adapter-opencode/src/version.ts
|
|
38223
38235
|
var MIN_PROMPT_ID_VERSION = "2.0.0";
|
|
@@ -39202,8 +39214,8 @@ function defaultOpenSessions() {
|
|
|
39202
39214
|
|
|
39203
39215
|
// ../bus-daemon/src/config-issues.ts
|
|
39204
39216
|
init_src();
|
|
39205
|
-
import { realpathSync as
|
|
39206
|
-
import { dirname as
|
|
39217
|
+
import { realpathSync as realpathSync5 } from "node:fs";
|
|
39218
|
+
import { dirname as dirname5, join as join9 } from "node:path";
|
|
39207
39219
|
|
|
39208
39220
|
// ../bus-daemon/src/global.ts
|
|
39209
39221
|
import { randomBytes } from "node:crypto";
|
|
@@ -39402,6 +39414,227 @@ function writeGlobalDirs(dirs, h = home()) {
|
|
|
39402
39414
|
}
|
|
39403
39415
|
}
|
|
39404
39416
|
|
|
39417
|
+
// ../bus-daemon/src/namespace.ts
|
|
39418
|
+
init_src();
|
|
39419
|
+
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
39420
|
+
import { realpathSync as realpathSync4 } from "node:fs";
|
|
39421
|
+
import { basename as basename4, dirname as dirname4, resolve as resolve2 } from "node:path";
|
|
39422
|
+
|
|
39423
|
+
// ../bus-daemon/src/namespaces.ts
|
|
39424
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
39425
|
+
import {
|
|
39426
|
+
appendFileSync,
|
|
39427
|
+
chmodSync as chmodSync4,
|
|
39428
|
+
closeSync as closeSync4,
|
|
39429
|
+
mkdirSync as mkdirSync5,
|
|
39430
|
+
openSync as openSync4,
|
|
39431
|
+
renameSync as renameSync3,
|
|
39432
|
+
unlinkSync as unlinkSync2,
|
|
39433
|
+
writeSync as writeSync2
|
|
39434
|
+
} from "node:fs";
|
|
39435
|
+
import { isAbsolute as isAbsolute4, join as join8 } from "node:path";
|
|
39436
|
+
var namespacesFile = (h = home()) => join8(h, "namespaces.json");
|
|
39437
|
+
function readApprovals(file2 = namespacesFile()) {
|
|
39438
|
+
const own2 = readOwnFile(file2);
|
|
39439
|
+
if (own2.state === "none") return { entries: [] };
|
|
39440
|
+
if (own2.state === "unsafe") return { entries: [], error: own2.why };
|
|
39441
|
+
try {
|
|
39442
|
+
const raw = JSON.parse(own2.text);
|
|
39443
|
+
const list = raw?.approved;
|
|
39444
|
+
if (raw && !Array.isArray(raw) && Array.isArray(list) && list.every(
|
|
39445
|
+
(e) => e && typeof e === "object" && typeof e.dir === "string" && isAbsolute4(e.dir) && typeof e.namespace === "string" && e.namespace !== ""
|
|
39446
|
+
))
|
|
39447
|
+
return {
|
|
39448
|
+
entries: list.map((e) => ({ dir: e.dir, namespace: e.namespace }))
|
|
39449
|
+
};
|
|
39450
|
+
} catch {
|
|
39451
|
+
}
|
|
39452
|
+
return { entries: [], error: "is not valid JSON" };
|
|
39453
|
+
}
|
|
39454
|
+
function isApproved(dir, namespace2, entries) {
|
|
39455
|
+
return entries.some((e) => e.namespace === namespace2 && sameDir(e.dir, dir));
|
|
39456
|
+
}
|
|
39457
|
+
function writeApprovals(entries, h = home()) {
|
|
39458
|
+
mkdirSync5(h, { recursive: true, mode: 448 });
|
|
39459
|
+
chmodSync4(h, 448);
|
|
39460
|
+
const tmp = join8(h, `.namespaces.json.${randomBytes2(8).toString("hex")}.tmp`);
|
|
39461
|
+
const fd = openSync4(tmp, "wx", 384);
|
|
39462
|
+
try {
|
|
39463
|
+
writeSync2(fd, `${JSON.stringify({ approved: entries }, null, 2)}
|
|
39464
|
+
`);
|
|
39465
|
+
} catch (e) {
|
|
39466
|
+
closeSync4(fd);
|
|
39467
|
+
unlinkSync2(tmp);
|
|
39468
|
+
throw e;
|
|
39469
|
+
}
|
|
39470
|
+
closeSync4(fd);
|
|
39471
|
+
try {
|
|
39472
|
+
chmodSync4(tmp, 384);
|
|
39473
|
+
renameSync3(tmp, namespacesFile(h));
|
|
39474
|
+
} catch (e) {
|
|
39475
|
+
unlinkSync2(tmp);
|
|
39476
|
+
throw e;
|
|
39477
|
+
}
|
|
39478
|
+
}
|
|
39479
|
+
function logApproval(entry, h = home(), now = /* @__PURE__ */ new Date()) {
|
|
39480
|
+
const dir = join8(h, "logs");
|
|
39481
|
+
mkdirSync5(dir, { recursive: true, mode: 448 });
|
|
39482
|
+
const file2 = join8(dir, "approvals.log");
|
|
39483
|
+
const line = `${now.toISOString()} ${entry.action} dir=${JSON.stringify(entry.dir)} namespace=${JSON.stringify(entry.namespace)} tty=${entry.tty ? "yes" : "no"}
|
|
39484
|
+
`;
|
|
39485
|
+
appendFileSync(file2, line, { mode: 384 });
|
|
39486
|
+
chmodSync4(file2, 384);
|
|
39487
|
+
}
|
|
39488
|
+
|
|
39489
|
+
// ../bus-daemon/src/namespace.ts
|
|
39490
|
+
var warned = /* @__PURE__ */ new Set();
|
|
39491
|
+
var once = (deps, key2, msg) => {
|
|
39492
|
+
if (warned.has(key2)) return;
|
|
39493
|
+
warned.add(key2);
|
|
39494
|
+
deps.log?.(msg);
|
|
39495
|
+
};
|
|
39496
|
+
function resolveNamespace(start, deps = {}) {
|
|
39497
|
+
let cwd;
|
|
39498
|
+
let missing2 = false;
|
|
39499
|
+
try {
|
|
39500
|
+
cwd = realpathSync4(start);
|
|
39501
|
+
} catch (e) {
|
|
39502
|
+
if (!deps.allowMissing) throw e;
|
|
39503
|
+
cwd = resolve2(start);
|
|
39504
|
+
missing2 = true;
|
|
39505
|
+
if (!warned.has(cwd)) {
|
|
39506
|
+
warned.add(cwd);
|
|
39507
|
+
deps.log?.(`${cwd} does not resolve; using it as given`);
|
|
39508
|
+
}
|
|
39509
|
+
}
|
|
39510
|
+
const { cfg, asked, nsFile } = readConfigs(cwd, deps);
|
|
39511
|
+
const global2 = !missing2 && allowlisted(cwd, deps);
|
|
39512
|
+
if (!global2)
|
|
39513
|
+
for (const file2 of asked)
|
|
39514
|
+
once(
|
|
39515
|
+
deps,
|
|
39516
|
+
`global:${file2}`,
|
|
39517
|
+
`ignoring global in ${file2}: only \`${BUS_CMD} global add\` makes a directory global`
|
|
39518
|
+
);
|
|
39519
|
+
const remoteUrl = (deps.gitRemote ?? gitRemote)(cwd);
|
|
39520
|
+
const root = (deps.gitRoot ?? gitRoot)(cwd);
|
|
39521
|
+
const derived2 = namespaceFrom({
|
|
39522
|
+
remoteUrl,
|
|
39523
|
+
gitRootName: root ? basename4(root) : null,
|
|
39524
|
+
cwd
|
|
39525
|
+
});
|
|
39526
|
+
const source = remoteUrl && normalizeRemote(remoteUrl) ? "git" : root ? "dir" : "cwd";
|
|
39527
|
+
const fallback = { namespace: derived2, global: global2, source };
|
|
39528
|
+
if (!cfg.namespace || !nsFile) return fallback;
|
|
39529
|
+
if (cfg.namespace === derived2) {
|
|
39530
|
+
deps.issues?.setPending(nsFile, deps.uid ?? process.getuid?.(), void 0);
|
|
39531
|
+
return fallback;
|
|
39532
|
+
}
|
|
39533
|
+
if (approved(nsFile, cfg.namespace, deps))
|
|
39534
|
+
return { namespace: cfg.namespace, global: global2, source: "config" };
|
|
39535
|
+
const dir = dirname4(nsFile);
|
|
39536
|
+
deps.issues?.setPending(nsFile, deps.uid ?? process.getuid?.(), {
|
|
39537
|
+
file: nsFile,
|
|
39538
|
+
dir,
|
|
39539
|
+
namespace: cfg.namespace,
|
|
39540
|
+
approvals: deps.namespacesFile
|
|
39541
|
+
});
|
|
39542
|
+
once(
|
|
39543
|
+
deps,
|
|
39544
|
+
`ns:${nsFile}:${cfg.namespace}`,
|
|
39545
|
+
`ignoring namespace "${cfg.namespace}" in ${nsFile}: not approved; run: ${approveCommand(dir)}`
|
|
39546
|
+
);
|
|
39547
|
+
return fallback;
|
|
39548
|
+
}
|
|
39549
|
+
function approved(file2, namespace2, deps) {
|
|
39550
|
+
const path = deps.namespacesFile ?? namespacesFile();
|
|
39551
|
+
const list = readApprovals(path);
|
|
39552
|
+
if (list.error)
|
|
39553
|
+
once(
|
|
39554
|
+
deps,
|
|
39555
|
+
`approvals:${path}:${list.error}`,
|
|
39556
|
+
`${path} ${list.error}: no namespace is approved`
|
|
39557
|
+
);
|
|
39558
|
+
return isApproved(dirname4(file2), namespace2, list.entries);
|
|
39559
|
+
}
|
|
39560
|
+
function allowlisted(cwd, deps) {
|
|
39561
|
+
const file2 = deps.globalFile ?? globalFile();
|
|
39562
|
+
const list = readGlobalDirs(file2);
|
|
39563
|
+
if (list.error)
|
|
39564
|
+
once(
|
|
39565
|
+
deps,
|
|
39566
|
+
`allowlist:${file2}:${list.error}`,
|
|
39567
|
+
`${file2} ${list.error}: no directory is global`
|
|
39568
|
+
);
|
|
39569
|
+
if (list.dirs.length === 0) return false;
|
|
39570
|
+
try {
|
|
39571
|
+
return isGlobalDir(
|
|
39572
|
+
cwd,
|
|
39573
|
+
list.dirs,
|
|
39574
|
+
(entry) => once(
|
|
39575
|
+
deps,
|
|
39576
|
+
`stale:${file2}:${entry}`,
|
|
39577
|
+
`ignoring ${entry} in ${file2}: its path is no longer real (a symlink now stands in it)`
|
|
39578
|
+
)
|
|
39579
|
+
);
|
|
39580
|
+
} catch {
|
|
39581
|
+
return false;
|
|
39582
|
+
}
|
|
39583
|
+
}
|
|
39584
|
+
function readConfigs(cwd, deps) {
|
|
39585
|
+
const uid = deps.uid ?? process.getuid?.();
|
|
39586
|
+
const configs = [];
|
|
39587
|
+
const asked = [];
|
|
39588
|
+
let nsFile;
|
|
39589
|
+
for (const file2 of configPaths(cwd)) {
|
|
39590
|
+
const own2 = readOwnFile(file2, uid, {
|
|
39591
|
+
allowGroupWrite: true,
|
|
39592
|
+
...deps.group ? { group: deps.group } : {}
|
|
39593
|
+
});
|
|
39594
|
+
if (own2.state === "unsafe")
|
|
39595
|
+
once(deps, file2, `ignoring ${file2}: it ${own2.why}`);
|
|
39596
|
+
let valid2 = true;
|
|
39597
|
+
if (own2.state === "ok") {
|
|
39598
|
+
if (own2.note) once(deps, `note:${file2}`, `using ${file2}: it ${own2.note}`);
|
|
39599
|
+
let parsed;
|
|
39600
|
+
try {
|
|
39601
|
+
parsed = BusConfigSchema.safeParse(JSON.parse(own2.text));
|
|
39602
|
+
} catch {
|
|
39603
|
+
}
|
|
39604
|
+
if (parsed?.success) {
|
|
39605
|
+
configs.push(parsed.data);
|
|
39606
|
+
if (parsed.data.global === true) asked.push(file2);
|
|
39607
|
+
if (parsed.data.namespace !== void 0 && nsFile === void 0)
|
|
39608
|
+
nsFile = file2;
|
|
39609
|
+
} else {
|
|
39610
|
+
valid2 = false;
|
|
39611
|
+
deps.log?.(`ignoring invalid ${file2}`);
|
|
39612
|
+
}
|
|
39613
|
+
}
|
|
39614
|
+
deps.issues?.set(file2, uid, configIssue(file2, own2, valid2), deps.group);
|
|
39615
|
+
}
|
|
39616
|
+
return { cfg: mergeConfigs(configs), asked, nsFile };
|
|
39617
|
+
}
|
|
39618
|
+
function nearestConfig(dir, deps = {}) {
|
|
39619
|
+
try {
|
|
39620
|
+
return readConfigs(realpathSync4(dir), deps).cfg;
|
|
39621
|
+
} catch {
|
|
39622
|
+
return {};
|
|
39623
|
+
}
|
|
39624
|
+
}
|
|
39625
|
+
var git = (cwd, args) => {
|
|
39626
|
+
try {
|
|
39627
|
+
return execFileSync4("git", ["-C", cwd, ...args], {
|
|
39628
|
+
encoding: "utf8",
|
|
39629
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
39630
|
+
}).trim() || null;
|
|
39631
|
+
} catch {
|
|
39632
|
+
return null;
|
|
39633
|
+
}
|
|
39634
|
+
};
|
|
39635
|
+
var gitRemote = (cwd) => git(cwd, ["remote", "get-url", "origin"]);
|
|
39636
|
+
var gitRoot = (cwd) => git(cwd, ["rev-parse", "--show-toplevel"]);
|
|
39637
|
+
|
|
39405
39638
|
// ../bus-daemon/src/config-issues.ts
|
|
39406
39639
|
var shq = (s) => `'${s.replace(/'/g, "'\\''")}'`;
|
|
39407
39640
|
function fixFor(file2, why) {
|
|
@@ -39441,6 +39674,24 @@ function configIssue(file2, own2, valid2 = true) {
|
|
|
39441
39674
|
};
|
|
39442
39675
|
return void 0;
|
|
39443
39676
|
}
|
|
39677
|
+
var approveCommand = (dir) => `oa-bus namespace approve ${shq(dir)}`;
|
|
39678
|
+
var pendingIssue = (p) => ({
|
|
39679
|
+
file: p.file,
|
|
39680
|
+
state: "pending",
|
|
39681
|
+
reason: `sets namespace "${p.namespace}", which you have not approved`,
|
|
39682
|
+
fix: approveCommand(p.dir)
|
|
39683
|
+
});
|
|
39684
|
+
function stillPending(p, uid) {
|
|
39685
|
+
const own2 = readOwnFile(p.file, uid, { allowGroupWrite: true });
|
|
39686
|
+
if (own2.state !== "ok") return false;
|
|
39687
|
+
try {
|
|
39688
|
+
const parsed = BusConfigSchema.safeParse(JSON.parse(own2.text));
|
|
39689
|
+
if (!parsed.success || parsed.data.namespace !== p.namespace) return false;
|
|
39690
|
+
} catch {
|
|
39691
|
+
return false;
|
|
39692
|
+
}
|
|
39693
|
+
return !isApproved(p.dir, p.namespace, readApprovals(p.approvals).entries);
|
|
39694
|
+
}
|
|
39444
39695
|
function isValidConfig(text3) {
|
|
39445
39696
|
try {
|
|
39446
39697
|
return BusConfigSchema.safeParse(JSON.parse(text3)).success;
|
|
@@ -39465,6 +39716,16 @@ function inspectGlobal(file2 = globalFile()) {
|
|
|
39465
39716
|
fix: error62 === "is not valid JSON" ? `remove it (rm ${shq(file2)}), then run oa-bus global add <dir> again` : fixFor(file2, error62)
|
|
39466
39717
|
};
|
|
39467
39718
|
}
|
|
39719
|
+
function inspectApprovals(file2 = namespacesFile()) {
|
|
39720
|
+
const { error: error62 } = readApprovals(file2);
|
|
39721
|
+
if (error62 === void 0) return void 0;
|
|
39722
|
+
return {
|
|
39723
|
+
file: file2,
|
|
39724
|
+
state: "refused",
|
|
39725
|
+
reason: error62,
|
|
39726
|
+
fix: error62 === "is not valid JSON" ? `remove it (rm ${shq(file2)}), then run oa-bus namespace approve <dir> again` : fixFor(file2, error62)
|
|
39727
|
+
};
|
|
39728
|
+
}
|
|
39468
39729
|
var ConfigIssues = class {
|
|
39469
39730
|
#files = /* @__PURE__ */ new Map();
|
|
39470
39731
|
/** Records the result of reading `file` (undefined: it is fine now). */
|
|
@@ -39472,9 +39733,21 @@ var ConfigIssues = class {
|
|
|
39472
39733
|
if (issue2) this.#files.set(file2, { uid, group });
|
|
39473
39734
|
else this.#files.delete(file2);
|
|
39474
39735
|
}
|
|
39736
|
+
#pending = /* @__PURE__ */ new Map();
|
|
39737
|
+
/** Records a namespace waiting for approval, or clears it (undefined). */
|
|
39738
|
+
setPending(file2, uid, pending) {
|
|
39739
|
+
if (pending) this.#pending.set(file2, { p: pending, uid });
|
|
39740
|
+
else this.#pending.delete(file2);
|
|
39741
|
+
}
|
|
39475
39742
|
/** Every tracked file, re-read now; `within` keeps only those at these paths. */
|
|
39476
|
-
list(within) {
|
|
39743
|
+
list(within, opts = {}) {
|
|
39477
39744
|
const out = [];
|
|
39745
|
+
for (const [file2, { p, uid }] of [...this.#pending]) {
|
|
39746
|
+
if (within && !within.has(file2)) continue;
|
|
39747
|
+
if (stillPending(p, uid)) {
|
|
39748
|
+
if (opts.pending) out.push(pendingIssue(p));
|
|
39749
|
+
} else this.#pending.delete(file2);
|
|
39750
|
+
}
|
|
39478
39751
|
for (const [file2, { uid, group }] of [...this.#files]) {
|
|
39479
39752
|
if (within && !within.has(file2)) continue;
|
|
39480
39753
|
const issue2 = inspectConfig(file2, uid, group);
|
|
@@ -39489,22 +39762,40 @@ function scanConfigFiles(cwd, opts = {}) {
|
|
|
39489
39762
|
const out = [];
|
|
39490
39763
|
let real2 = cwd;
|
|
39491
39764
|
try {
|
|
39492
|
-
real2 =
|
|
39765
|
+
real2 = realpathSync5(cwd);
|
|
39493
39766
|
} catch {
|
|
39494
39767
|
}
|
|
39495
39768
|
for (const file2 of configPaths(real2)) {
|
|
39496
39769
|
const issue2 = inspectConfig(file2, uid, opts.group);
|
|
39497
39770
|
if (issue2) out.push(issue2);
|
|
39498
39771
|
}
|
|
39772
|
+
const seen2 = new ConfigIssues();
|
|
39773
|
+
try {
|
|
39774
|
+
resolveNamespace(real2, {
|
|
39775
|
+
issues: seen2,
|
|
39776
|
+
allowMissing: true,
|
|
39777
|
+
...opts.uid === void 0 ? {} : { uid: opts.uid },
|
|
39778
|
+
...opts.group ? { group: opts.group } : {},
|
|
39779
|
+
...opts.namespacesFile ? { namespacesFile: opts.namespacesFile } : {},
|
|
39780
|
+
...opts.gitRemote ? { gitRemote: opts.gitRemote } : {},
|
|
39781
|
+
...opts.gitRoot ? { gitRoot: opts.gitRoot } : {}
|
|
39782
|
+
});
|
|
39783
|
+
} catch {
|
|
39784
|
+
}
|
|
39785
|
+
out.push(
|
|
39786
|
+
...seen2.list(void 0, { pending: true }).filter((f) => f.state === "pending")
|
|
39787
|
+
);
|
|
39788
|
+
const a = inspectApprovals(opts.namespacesFile);
|
|
39789
|
+
if (a) out.push(a);
|
|
39499
39790
|
const g = inspectGlobal(opts.globalFile);
|
|
39500
39791
|
if (g) out.push(g);
|
|
39501
39792
|
return out;
|
|
39502
39793
|
}
|
|
39503
39794
|
function configPaths(cwd) {
|
|
39504
39795
|
const out = [];
|
|
39505
|
-
for (let dir = cwd; ; dir =
|
|
39506
|
-
out.push(
|
|
39507
|
-
if (
|
|
39796
|
+
for (let dir = cwd; ; dir = dirname5(dir)) {
|
|
39797
|
+
out.push(join9(dir, CONFIG_FILE));
|
|
39798
|
+
if (dirname5(dir) === dir) return out;
|
|
39508
39799
|
}
|
|
39509
39800
|
}
|
|
39510
39801
|
|
|
@@ -40018,127 +40309,6 @@ function defaultBackoff(attempt) {
|
|
|
40018
40309
|
return Math.round(base3 * (0.5 + Math.random() / 2));
|
|
40019
40310
|
}
|
|
40020
40311
|
|
|
40021
|
-
// ../bus-daemon/src/namespace.ts
|
|
40022
|
-
init_src();
|
|
40023
|
-
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
40024
|
-
import { realpathSync as realpathSync5 } from "node:fs";
|
|
40025
|
-
import { basename as basename4, resolve as resolve2 } from "node:path";
|
|
40026
|
-
var warned = /* @__PURE__ */ new Set();
|
|
40027
|
-
var once = (deps, key2, msg) => {
|
|
40028
|
-
if (warned.has(key2)) return;
|
|
40029
|
-
warned.add(key2);
|
|
40030
|
-
deps.log?.(msg);
|
|
40031
|
-
};
|
|
40032
|
-
function resolveNamespace(start, deps = {}) {
|
|
40033
|
-
let cwd;
|
|
40034
|
-
let missing2 = false;
|
|
40035
|
-
try {
|
|
40036
|
-
cwd = realpathSync5(start);
|
|
40037
|
-
} catch (e) {
|
|
40038
|
-
if (!deps.allowMissing) throw e;
|
|
40039
|
-
cwd = resolve2(start);
|
|
40040
|
-
missing2 = true;
|
|
40041
|
-
if (!warned.has(cwd)) {
|
|
40042
|
-
warned.add(cwd);
|
|
40043
|
-
deps.log?.(`${cwd} does not resolve; using it as given`);
|
|
40044
|
-
}
|
|
40045
|
-
}
|
|
40046
|
-
const { cfg, asked } = readConfigs(cwd, deps);
|
|
40047
|
-
const global2 = !missing2 && allowlisted(cwd, deps);
|
|
40048
|
-
if (!global2)
|
|
40049
|
-
for (const file2 of asked)
|
|
40050
|
-
once(
|
|
40051
|
-
deps,
|
|
40052
|
-
`global:${file2}`,
|
|
40053
|
-
`ignoring global in ${file2}: only \`${BUS_CMD} global add\` makes a directory global`
|
|
40054
|
-
);
|
|
40055
|
-
if (cfg.namespace)
|
|
40056
|
-
return { namespace: cfg.namespace, global: global2, source: "config" };
|
|
40057
|
-
const remoteUrl = (deps.gitRemote ?? gitRemote)(cwd);
|
|
40058
|
-
const root = (deps.gitRoot ?? gitRoot)(cwd);
|
|
40059
|
-
const namespace = namespaceFrom({
|
|
40060
|
-
remoteUrl,
|
|
40061
|
-
gitRootName: root ? basename4(root) : null,
|
|
40062
|
-
cwd
|
|
40063
|
-
});
|
|
40064
|
-
const source = remoteUrl && normalizeRemote(remoteUrl) ? "git" : root ? "dir" : "cwd";
|
|
40065
|
-
return { namespace, global: global2, source };
|
|
40066
|
-
}
|
|
40067
|
-
function allowlisted(cwd, deps) {
|
|
40068
|
-
const file2 = deps.globalFile ?? globalFile();
|
|
40069
|
-
const list = readGlobalDirs(file2);
|
|
40070
|
-
if (list.error)
|
|
40071
|
-
once(
|
|
40072
|
-
deps,
|
|
40073
|
-
`allowlist:${file2}:${list.error}`,
|
|
40074
|
-
`${file2} ${list.error}: no directory is global`
|
|
40075
|
-
);
|
|
40076
|
-
if (list.dirs.length === 0) return false;
|
|
40077
|
-
try {
|
|
40078
|
-
return isGlobalDir(
|
|
40079
|
-
cwd,
|
|
40080
|
-
list.dirs,
|
|
40081
|
-
(entry) => once(
|
|
40082
|
-
deps,
|
|
40083
|
-
`stale:${file2}:${entry}`,
|
|
40084
|
-
`ignoring ${entry} in ${file2}: its path is no longer real (a symlink now stands in it)`
|
|
40085
|
-
)
|
|
40086
|
-
);
|
|
40087
|
-
} catch {
|
|
40088
|
-
return false;
|
|
40089
|
-
}
|
|
40090
|
-
}
|
|
40091
|
-
function readConfigs(cwd, deps) {
|
|
40092
|
-
const uid = deps.uid ?? process.getuid?.();
|
|
40093
|
-
const configs = [];
|
|
40094
|
-
const asked = [];
|
|
40095
|
-
for (const file2 of configPaths(cwd)) {
|
|
40096
|
-
const own2 = readOwnFile(file2, uid, {
|
|
40097
|
-
allowGroupWrite: true,
|
|
40098
|
-
...deps.group ? { group: deps.group } : {}
|
|
40099
|
-
});
|
|
40100
|
-
if (own2.state === "unsafe")
|
|
40101
|
-
once(deps, file2, `ignoring ${file2}: it ${own2.why}`);
|
|
40102
|
-
let valid2 = true;
|
|
40103
|
-
if (own2.state === "ok") {
|
|
40104
|
-
if (own2.note) once(deps, `note:${file2}`, `using ${file2}: it ${own2.note}`);
|
|
40105
|
-
let parsed;
|
|
40106
|
-
try {
|
|
40107
|
-
parsed = BusConfigSchema.safeParse(JSON.parse(own2.text));
|
|
40108
|
-
} catch {
|
|
40109
|
-
}
|
|
40110
|
-
if (parsed?.success) {
|
|
40111
|
-
configs.push(parsed.data);
|
|
40112
|
-
if (parsed.data.global === true) asked.push(file2);
|
|
40113
|
-
} else {
|
|
40114
|
-
valid2 = false;
|
|
40115
|
-
deps.log?.(`ignoring invalid ${file2}`);
|
|
40116
|
-
}
|
|
40117
|
-
}
|
|
40118
|
-
deps.issues?.set(file2, uid, configIssue(file2, own2, valid2), deps.group);
|
|
40119
|
-
}
|
|
40120
|
-
return { cfg: mergeConfigs(configs), asked };
|
|
40121
|
-
}
|
|
40122
|
-
function nearestConfig(dir, deps = {}) {
|
|
40123
|
-
try {
|
|
40124
|
-
return readConfigs(realpathSync5(dir), deps).cfg;
|
|
40125
|
-
} catch {
|
|
40126
|
-
return {};
|
|
40127
|
-
}
|
|
40128
|
-
}
|
|
40129
|
-
var git = (cwd, args) => {
|
|
40130
|
-
try {
|
|
40131
|
-
return execFileSync4("git", ["-C", cwd, ...args], {
|
|
40132
|
-
encoding: "utf8",
|
|
40133
|
-
stdio: ["ignore", "pipe", "ignore"]
|
|
40134
|
-
}).trim() || null;
|
|
40135
|
-
} catch {
|
|
40136
|
-
return null;
|
|
40137
|
-
}
|
|
40138
|
-
};
|
|
40139
|
-
var gitRemote = (cwd) => git(cwd, ["remote", "get-url", "origin"]);
|
|
40140
|
-
var gitRoot = (cwd) => git(cwd, ["rev-parse", "--show-toplevel"]);
|
|
40141
|
-
|
|
40142
40312
|
// ../bus-daemon/src/outbox.ts
|
|
40143
40313
|
var Outbox = class {
|
|
40144
40314
|
constructor(opts) {
|
|
@@ -40595,7 +40765,10 @@ function routeLocal(frame, hello, reply, ctx) {
|
|
|
40595
40765
|
const ref = agent.ref;
|
|
40596
40766
|
switch (frame.type) {
|
|
40597
40767
|
case "self": {
|
|
40598
|
-
const files = frame.row ? ctx.configFiles?.(
|
|
40768
|
+
const files = frame.row ? ctx.configFiles?.(
|
|
40769
|
+
agent.cwd,
|
|
40770
|
+
hello.caps?.includes(ADAPTER_CAPS.pending)
|
|
40771
|
+
) ?? [] : [];
|
|
40599
40772
|
const self = {
|
|
40600
40773
|
type: "agent",
|
|
40601
40774
|
agent: {
|
|
@@ -40683,9 +40856,9 @@ function routeLocal(frame, hello, reply, ctx) {
|
|
|
40683
40856
|
init_src2();
|
|
40684
40857
|
init_src();
|
|
40685
40858
|
import {
|
|
40686
|
-
chmodSync as
|
|
40859
|
+
chmodSync as chmodSync5,
|
|
40687
40860
|
readFileSync as readFileSync7,
|
|
40688
|
-
renameSync as
|
|
40861
|
+
renameSync as renameSync4,
|
|
40689
40862
|
rmSync as rmSync2,
|
|
40690
40863
|
writeFileSync
|
|
40691
40864
|
} from "node:fs";
|
|
@@ -40863,20 +41036,20 @@ var SentStore = class {
|
|
|
40863
41036
|
from_ref,
|
|
40864
41037
|
from_name,
|
|
40865
41038
|
to_name,
|
|
40866
|
-
namespace,
|
|
41039
|
+
namespace: namespace2,
|
|
40867
41040
|
excerpt,
|
|
40868
41041
|
at,
|
|
40869
41042
|
outcome,
|
|
40870
41043
|
delivered,
|
|
40871
41044
|
late: late2,
|
|
40872
|
-
shown:
|
|
41045
|
+
shown: shown3,
|
|
40873
41046
|
native
|
|
40874
41047
|
} = e;
|
|
40875
41048
|
this.#all.set(id, {
|
|
40876
41049
|
from_ref,
|
|
40877
41050
|
...BusNameSchema.safeParse(from_name).success ? { from_name } : {},
|
|
40878
41051
|
to_name,
|
|
40879
|
-
...
|
|
41052
|
+
...namespace2 === void 0 ? {} : { namespace: namespace2 },
|
|
40880
41053
|
...validExcerpt(excerpt) ? { excerpt } : {},
|
|
40881
41054
|
at,
|
|
40882
41055
|
...outcome ? {
|
|
@@ -40887,7 +41060,7 @@ var SentStore = class {
|
|
|
40887
41060
|
} : {},
|
|
40888
41061
|
...delivered ? { delivered } : {},
|
|
40889
41062
|
...delivered && late2 ? { late: late2 } : {},
|
|
40890
|
-
...delivered && late2 &&
|
|
41063
|
+
...delivered && late2 && shown3 ? { shown: shown3 } : {},
|
|
40891
41064
|
...native ? { native } : {}
|
|
40892
41065
|
});
|
|
40893
41066
|
}
|
|
@@ -40913,8 +41086,8 @@ var SentStore = class {
|
|
|
40913
41086
|
mode: 384,
|
|
40914
41087
|
flag: "wx"
|
|
40915
41088
|
});
|
|
40916
|
-
|
|
40917
|
-
|
|
41089
|
+
chmodSync5(tmp, 384);
|
|
41090
|
+
renameSync4(tmp, this.file);
|
|
40918
41091
|
} catch (e) {
|
|
40919
41092
|
this.#log?.(
|
|
40920
41093
|
`sent file write failed: ${e instanceof Error ? e.message : String(e)}`
|
|
@@ -40949,7 +41122,7 @@ var Receipts = class {
|
|
|
40949
41122
|
#now;
|
|
40950
41123
|
#after;
|
|
40951
41124
|
/** `native`: no tool call waits for this receipt, so a refusal is a notice too. */
|
|
40952
|
-
sending(f,
|
|
41125
|
+
sending(f, namespace2, native, fromName) {
|
|
40953
41126
|
const excerpt = typeof f.body === "string" ? excerptOf(f.body) : void 0;
|
|
40954
41127
|
const cutoff = this.#now() - 15 * 6e4;
|
|
40955
41128
|
for (const [id, s] of this.#sending)
|
|
@@ -40959,7 +41132,7 @@ var Receipts = class {
|
|
|
40959
41132
|
from_ref: f.from_ref,
|
|
40960
41133
|
...fromName ? { from_name: fromName } : {},
|
|
40961
41134
|
to_name: f.to_name,
|
|
40962
|
-
...
|
|
41135
|
+
...namespace2 ? { namespace: namespace2 } : {},
|
|
40963
41136
|
...excerpt ? { excerpt } : {}
|
|
40964
41137
|
},
|
|
40965
41138
|
native,
|
|
@@ -41029,12 +41202,12 @@ var Receipts = class {
|
|
|
41029
41202
|
this.#waiting.delete(msgId);
|
|
41030
41203
|
return Promise.resolve(w.final);
|
|
41031
41204
|
}
|
|
41032
|
-
return new Promise((
|
|
41205
|
+
return new Promise((resolve9) => {
|
|
41033
41206
|
const cancel = this.#after(ms, () => w.done?.(void 0));
|
|
41034
41207
|
w.done = (f) => {
|
|
41035
41208
|
cancel();
|
|
41036
41209
|
this.#waiting.delete(msgId);
|
|
41037
|
-
|
|
41210
|
+
resolve9(f);
|
|
41038
41211
|
};
|
|
41039
41212
|
});
|
|
41040
41213
|
}
|
|
@@ -41090,20 +41263,20 @@ init_src3();
|
|
|
41090
41263
|
init_src();
|
|
41091
41264
|
import { createHash as createHash4, randomUUID } from "node:crypto";
|
|
41092
41265
|
import {
|
|
41093
|
-
chmodSync as
|
|
41266
|
+
chmodSync as chmodSync7,
|
|
41094
41267
|
lstatSync as lstatSync5,
|
|
41095
|
-
mkdirSync as
|
|
41268
|
+
mkdirSync as mkdirSync6,
|
|
41096
41269
|
readFileSync as readFileSync9,
|
|
41097
|
-
renameSync as
|
|
41270
|
+
renameSync as renameSync6,
|
|
41098
41271
|
rmSync as rmSync3,
|
|
41099
41272
|
writeFileSync as writeFileSync3
|
|
41100
41273
|
} from "node:fs";
|
|
41101
41274
|
import { createServer as createServer2 } from "node:net";
|
|
41102
|
-
import { dirname as
|
|
41275
|
+
import { dirname as dirname6, join as join10 } from "node:path";
|
|
41103
41276
|
import { createInterface } from "node:readline";
|
|
41104
41277
|
|
|
41105
41278
|
// ../bus-daemon/src/transports/held.ts
|
|
41106
|
-
import { chmodSync as
|
|
41279
|
+
import { chmodSync as chmodSync6, readFileSync as readFileSync8, renameSync as renameSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
41107
41280
|
var HeldStore = class {
|
|
41108
41281
|
constructor(file2, opts = {}) {
|
|
41109
41282
|
this.file = file2;
|
|
@@ -41142,8 +41315,8 @@ var HeldStore = class {
|
|
|
41142
41315
|
#write(all) {
|
|
41143
41316
|
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
41144
41317
|
writeFileSync2(tmp, JSON.stringify(all), { mode: 384 });
|
|
41145
|
-
|
|
41146
|
-
|
|
41318
|
+
chmodSync6(tmp, 384);
|
|
41319
|
+
renameSync5(tmp, this.file);
|
|
41147
41320
|
}
|
|
41148
41321
|
};
|
|
41149
41322
|
|
|
@@ -41169,7 +41342,7 @@ function unsafeClaudeSocket(path) {
|
|
|
41169
41342
|
try {
|
|
41170
41343
|
if (!sock.isSocket()) return `${path} is not a socket`;
|
|
41171
41344
|
if (sock.uid !== uid) return `${path} belongs to another user`;
|
|
41172
|
-
const dir =
|
|
41345
|
+
const dir = dirname6(path);
|
|
41173
41346
|
const st = lstatSync5(dir);
|
|
41174
41347
|
if (!st.isDirectory()) return `${dir} is not a folder`;
|
|
41175
41348
|
if (st.uid !== uid) return `${dir} belongs to another user`;
|
|
@@ -41183,8 +41356,8 @@ function unsafeClaudeSocket(path) {
|
|
|
41183
41356
|
var RETURN_INDEX_MAX = 500;
|
|
41184
41357
|
var RETURN_TTL_MS = LIMITS.mailTtlSec * 1e3;
|
|
41185
41358
|
var INDEX_REFRESH_MS = 6e4;
|
|
41186
|
-
function returnKey(agentRef,
|
|
41187
|
-
return `${agentRef}\0${
|
|
41359
|
+
function returnKey(agentRef, namespace2, peerName, fromId) {
|
|
41360
|
+
return `${agentRef}\0${namespace2}\0${peerName}\0${fromId ?? ""}`;
|
|
41188
41361
|
}
|
|
41189
41362
|
function readReturnIndex(file2) {
|
|
41190
41363
|
let raw;
|
|
@@ -41226,7 +41399,7 @@ var ClaudeTransport = class {
|
|
|
41226
41399
|
this.opts = opts;
|
|
41227
41400
|
this.#held = opts.heldFile ? new HeldStore(opts.heldFile) : void 0;
|
|
41228
41401
|
this.#injected = opts.heldFile ? new HeldStore(opts.heldFile.replace(/(\.json)?$/, ".injected.json")) : void 0;
|
|
41229
|
-
const sample =
|
|
41402
|
+
const sample = join10(opts.socketsDir, "00000000.sock");
|
|
41230
41403
|
if (Buffer.byteLength(sample) > MAX_SOCKET_PATH) {
|
|
41231
41404
|
this.#disabled = `claude delivery disabled: return socket paths are too long for a unix socket (${Buffer.byteLength(sample)} > ${MAX_SOCKET_PATH} bytes under ${opts.socketsDir}); use a shorter OA_BUS_HOME`;
|
|
41232
41405
|
opts.log?.(this.#disabled);
|
|
@@ -41343,22 +41516,22 @@ var ClaudeTransport = class {
|
|
|
41343
41516
|
return { ok: false, reason: "closed", cause: st };
|
|
41344
41517
|
}
|
|
41345
41518
|
#waitFor(msgId, ms) {
|
|
41346
|
-
return new Promise((
|
|
41519
|
+
return new Promise((resolve9) => {
|
|
41347
41520
|
const buffered = this.#buffered.get(msgId);
|
|
41348
41521
|
if (buffered !== void 0) {
|
|
41349
41522
|
this.#buffered.delete(msgId);
|
|
41350
|
-
|
|
41523
|
+
resolve9(buffered);
|
|
41351
41524
|
return;
|
|
41352
41525
|
}
|
|
41353
41526
|
const timer = setTimeout(() => {
|
|
41354
41527
|
this.#waiting.delete(msgId);
|
|
41355
|
-
|
|
41528
|
+
resolve9(void 0);
|
|
41356
41529
|
}, ms);
|
|
41357
41530
|
timer.unref();
|
|
41358
41531
|
this.#waiting.set(msgId, (s) => {
|
|
41359
41532
|
clearTimeout(timer);
|
|
41360
41533
|
this.#waiting.delete(msgId);
|
|
41361
|
-
|
|
41534
|
+
resolve9(s);
|
|
41362
41535
|
});
|
|
41363
41536
|
});
|
|
41364
41537
|
}
|
|
@@ -41439,14 +41612,14 @@ var ClaudeTransport = class {
|
|
|
41439
41612
|
return t ? `uds:${t.socketPath}` : "";
|
|
41440
41613
|
}
|
|
41441
41614
|
/** A global session hears from alice@ns1 and alice@ns2 on different sockets. */
|
|
41442
|
-
#sink(agentRef,
|
|
41443
|
-
const key2 = returnKey(agentRef,
|
|
41615
|
+
#sink(agentRef, namespace2, peerName, fromId, revived) {
|
|
41616
|
+
const key2 = returnKey(agentRef, namespace2, peerName, fromId);
|
|
41444
41617
|
let sink = this.#sinks.get(key2);
|
|
41445
41618
|
if (!sink) {
|
|
41446
41619
|
sink = this.#listen(
|
|
41447
41620
|
key2,
|
|
41448
41621
|
agentRef,
|
|
41449
|
-
|
|
41622
|
+
namespace2,
|
|
41450
41623
|
peerName,
|
|
41451
41624
|
false,
|
|
41452
41625
|
revived,
|
|
@@ -41460,8 +41633,8 @@ var ClaudeTransport = class {
|
|
|
41460
41633
|
}
|
|
41461
41634
|
return sink;
|
|
41462
41635
|
}
|
|
41463
|
-
async #listen(key2, agentRef,
|
|
41464
|
-
const path =
|
|
41636
|
+
async #listen(key2, agentRef, namespace2, peerName, notice = false, revived, fromId) {
|
|
41637
|
+
const path = join10(
|
|
41465
41638
|
this.opts.socketsDir,
|
|
41466
41639
|
`${notice ? randomUUID().slice(0, 8) : returnName(key2, this.#pathsInUse())}.sock`
|
|
41467
41640
|
);
|
|
@@ -41469,8 +41642,8 @@ var ClaudeTransport = class {
|
|
|
41469
41642
|
const unsafe = this.opts.prepareDir(this.opts.socketsDir);
|
|
41470
41643
|
if (unsafe) throw new UnsafeDir(unsafe);
|
|
41471
41644
|
} else {
|
|
41472
|
-
|
|
41473
|
-
|
|
41645
|
+
mkdirSync6(this.opts.socketsDir, { recursive: true, mode: 448 });
|
|
41646
|
+
chmodSync7(this.opts.socketsDir, 448);
|
|
41474
41647
|
}
|
|
41475
41648
|
rmSync3(path, { force: true });
|
|
41476
41649
|
this.#paths.set(key2, path);
|
|
@@ -41480,7 +41653,7 @@ var ClaudeTransport = class {
|
|
|
41480
41653
|
path,
|
|
41481
41654
|
conns,
|
|
41482
41655
|
agentRef,
|
|
41483
|
-
namespace,
|
|
41656
|
+
namespace: namespace2,
|
|
41484
41657
|
peerName,
|
|
41485
41658
|
claudeFrom: "",
|
|
41486
41659
|
notice,
|
|
@@ -41498,11 +41671,11 @@ var ClaudeTransport = class {
|
|
|
41498
41671
|
);
|
|
41499
41672
|
})
|
|
41500
41673
|
};
|
|
41501
|
-
await new Promise((
|
|
41674
|
+
await new Promise((resolve9, reject) => {
|
|
41502
41675
|
sink.server.once("error", reject);
|
|
41503
|
-
sink.server.listen(path, () =>
|
|
41676
|
+
sink.server.listen(path, () => resolve9());
|
|
41504
41677
|
});
|
|
41505
|
-
|
|
41678
|
+
chmodSync7(path, 384);
|
|
41506
41679
|
return sink;
|
|
41507
41680
|
}
|
|
41508
41681
|
/** Paths of the sinks bound or binding now, by key. */
|
|
@@ -41543,8 +41716,8 @@ var ClaudeTransport = class {
|
|
|
41543
41716
|
for (const [k, v] of keep) out[k] = v;
|
|
41544
41717
|
const tmp = `${file2}.${process.pid}.tmp`;
|
|
41545
41718
|
writeFileSync3(tmp, JSON.stringify(out), { mode: 384 });
|
|
41546
|
-
|
|
41547
|
-
|
|
41719
|
+
chmodSync7(tmp, 384);
|
|
41720
|
+
renameSync6(tmp, file2);
|
|
41548
41721
|
return out;
|
|
41549
41722
|
} catch (e) {
|
|
41550
41723
|
this.opts.log?.(
|
|
@@ -41624,10 +41797,10 @@ init_src2();
|
|
|
41624
41797
|
import { execFile } from "node:child_process";
|
|
41625
41798
|
import { accessSync, constants as constants2, readFileSync as readFileSync10, statSync as statSync7 } from "node:fs";
|
|
41626
41799
|
import { readFile } from "node:fs/promises";
|
|
41627
|
-
import { delimiter, isAbsolute as
|
|
41800
|
+
import { delimiter, isAbsolute as isAbsolute5, join as join11 } from "node:path";
|
|
41628
41801
|
var CODEX_QUEUE_TIMEOUT_MS = 1e4;
|
|
41629
41802
|
var CODEX_TEXT_CAP = 64 * 1024;
|
|
41630
|
-
var codexBinFile = (busHome2) =>
|
|
41803
|
+
var codexBinFile = (busHome2) => join11(busHome2, "codex.json");
|
|
41631
41804
|
var codexBinPin = (bin) => `${JSON.stringify({ bin }, null, 2)}
|
|
41632
41805
|
`;
|
|
41633
41806
|
var CODEX_APP = "/Applications/ChatGPT.app";
|
|
@@ -41643,11 +41816,11 @@ var executable = (p) => {
|
|
|
41643
41816
|
};
|
|
41644
41817
|
function codexAppBin(app) {
|
|
41645
41818
|
try {
|
|
41646
|
-
const plist = readFileSync10(
|
|
41819
|
+
const plist = readFileSync10(join11(app, "Contents", "Info.plist"), "utf8");
|
|
41647
41820
|
const id = /<key>CFBundleIdentifier<\/key>\s*<string>([^<]*)<\/string>/.exec(
|
|
41648
41821
|
plist
|
|
41649
41822
|
)?.[1];
|
|
41650
|
-
return id === CODEX_APP_ID ?
|
|
41823
|
+
return id === CODEX_APP_ID ? join11(app, "Contents", "Resources", "codex") : void 0;
|
|
41651
41824
|
} catch {
|
|
41652
41825
|
return void 0;
|
|
41653
41826
|
}
|
|
@@ -41656,13 +41829,13 @@ function resolveCodexBin(o) {
|
|
|
41656
41829
|
if (o.configFile)
|
|
41657
41830
|
try {
|
|
41658
41831
|
const raw = JSON.parse(readFileSync10(o.configFile, "utf8"));
|
|
41659
|
-
if (typeof raw.bin === "string" &&
|
|
41832
|
+
if (typeof raw.bin === "string" && isAbsolute5(raw.bin) && executable(raw.bin))
|
|
41660
41833
|
return { path: raw.bin, from: "config" };
|
|
41661
41834
|
} catch {
|
|
41662
41835
|
}
|
|
41663
41836
|
for (const dir of (o.path ?? "").split(delimiter)) {
|
|
41664
|
-
if (!
|
|
41665
|
-
const p =
|
|
41837
|
+
if (!isAbsolute5(dir)) continue;
|
|
41838
|
+
const p = join11(dir, "codex");
|
|
41666
41839
|
if (executable(p)) return { path: p, from: "path" };
|
|
41667
41840
|
}
|
|
41668
41841
|
const app = o.app === null ? void 0 : codexAppBin(o.app ?? CODEX_APP);
|
|
@@ -41712,14 +41885,14 @@ function splitArgv0(args) {
|
|
|
41712
41885
|
const real2 = ends.find((e) => {
|
|
41713
41886
|
const p = args.slice(0, e);
|
|
41714
41887
|
try {
|
|
41715
|
-
return
|
|
41888
|
+
return isAbsolute5(p) && statSync7(p).isFile();
|
|
41716
41889
|
} catch {
|
|
41717
41890
|
return false;
|
|
41718
41891
|
}
|
|
41719
41892
|
});
|
|
41720
41893
|
return words(args.slice(real2 ?? ends[0]));
|
|
41721
41894
|
}
|
|
41722
|
-
var execText = (cmd, args) => new Promise((
|
|
41895
|
+
var execText = (cmd, args) => new Promise((resolve9) => {
|
|
41723
41896
|
execFile(
|
|
41724
41897
|
cmd,
|
|
41725
41898
|
args,
|
|
@@ -41728,7 +41901,7 @@ var execText = (cmd, args) => new Promise((resolve8) => {
|
|
|
41728
41901
|
timeout: 2e3,
|
|
41729
41902
|
env: { ...process.env, LC_ALL: "C" }
|
|
41730
41903
|
},
|
|
41731
|
-
(err, stdout) =>
|
|
41904
|
+
(err, stdout) => resolve9(err ? void 0 : stdout)
|
|
41732
41905
|
);
|
|
41733
41906
|
});
|
|
41734
41907
|
async function processArgs(pid) {
|
|
@@ -41751,17 +41924,17 @@ async function processArgs(pid) {
|
|
|
41751
41924
|
return args ? splitArgv0(args) : void 0;
|
|
41752
41925
|
}
|
|
41753
41926
|
var START_ERRORS = /* @__PURE__ */ new Set(["ENOENT", "EACCES", "ENOEXEC"]);
|
|
41754
|
-
var execCodex = (timeoutMs = CODEX_QUEUE_TIMEOUT_MS) => (bin, args, env2) => new Promise((
|
|
41927
|
+
var execCodex = (timeoutMs = CODEX_QUEUE_TIMEOUT_MS) => (bin, args, env2) => new Promise((resolve9, reject) => {
|
|
41755
41928
|
execFile(
|
|
41756
41929
|
bin,
|
|
41757
41930
|
args,
|
|
41758
41931
|
{ timeout: timeoutMs, maxBuffer: 64 * 1024, env: env2 },
|
|
41759
41932
|
(err, _stdout, stderr) => {
|
|
41760
|
-
if (!err) return
|
|
41933
|
+
if (!err) return resolve9({ code: 0, stderr });
|
|
41761
41934
|
const e = err;
|
|
41762
41935
|
if (typeof e.code === "string" && START_ERRORS.has(e.code))
|
|
41763
41936
|
return reject(err);
|
|
41764
|
-
|
|
41937
|
+
resolve9({
|
|
41765
41938
|
// A maxBuffer kill is SIGTERM too, but carries its own string code.
|
|
41766
41939
|
code: e.killed && e.signal === "SIGTERM" && typeof e.code !== "string" ? null : typeof e.code === "number" ? e.code : -1,
|
|
41767
41940
|
stderr: String(stderr ?? "")
|
|
@@ -41886,17 +42059,17 @@ var codexHostWakes = async (pid) => {
|
|
|
41886
42059
|
init_src2();
|
|
41887
42060
|
import { execFile as execFile2 } from "node:child_process";
|
|
41888
42061
|
var START_ERRORS2 = /* @__PURE__ */ new Set(["ENOENT", "EACCES"]);
|
|
41889
|
-
var execSpawn = (timeoutMs, maxBuffer = 1024 * 1024) => (cmd, args) => new Promise((
|
|
42062
|
+
var execSpawn = (timeoutMs, maxBuffer = 1024 * 1024) => (cmd, args) => new Promise((resolve9, reject) => {
|
|
41890
42063
|
execFile2(
|
|
41891
42064
|
cmd,
|
|
41892
42065
|
args,
|
|
41893
42066
|
{ timeout: timeoutMs, maxBuffer },
|
|
41894
42067
|
(err, stdout, stderr) => {
|
|
41895
|
-
if (!err) return
|
|
42068
|
+
if (!err) return resolve9({ code: 0, stdout, stderr });
|
|
41896
42069
|
const e = err;
|
|
41897
42070
|
if (typeof e.code === "string" && START_ERRORS2.has(e.code))
|
|
41898
42071
|
return reject(err);
|
|
41899
|
-
|
|
42072
|
+
resolve9({
|
|
41900
42073
|
code: e.killed || typeof e.code !== "number" ? null : e.code,
|
|
41901
42074
|
stdout,
|
|
41902
42075
|
stderr
|
|
@@ -42011,18 +42184,18 @@ var PiTransport = class {
|
|
|
42011
42184
|
});
|
|
42012
42185
|
if (!pushed) return { ok: false, reason: "closed" };
|
|
42013
42186
|
this.#forget(mail.msg_id);
|
|
42014
|
-
return new Promise((
|
|
42187
|
+
return new Promise((resolve9) => {
|
|
42015
42188
|
const timer = setTimeout(() => {
|
|
42016
42189
|
this.#waiting.delete(mail.msg_id);
|
|
42017
42190
|
this.#remember(mail.msg_id, agent.ref);
|
|
42018
|
-
|
|
42191
|
+
resolve9({ ok: false, reason: "timeout" });
|
|
42019
42192
|
}, this.opts.ackTimeoutMs ?? 1e4);
|
|
42020
42193
|
timer.unref();
|
|
42021
42194
|
this.#waiting.set(mail.msg_id, {
|
|
42022
42195
|
ref: agent.ref,
|
|
42023
42196
|
done: (o) => {
|
|
42024
42197
|
clearTimeout(timer);
|
|
42025
|
-
|
|
42198
|
+
resolve9(o);
|
|
42026
42199
|
}
|
|
42027
42200
|
});
|
|
42028
42201
|
});
|
|
@@ -42145,8 +42318,9 @@ async function runDaemon(deps = {}) {
|
|
|
42145
42318
|
caps.delete(ref);
|
|
42146
42319
|
};
|
|
42147
42320
|
const configIssues = new ConfigIssues();
|
|
42148
|
-
const configFiles = (cwd) => {
|
|
42321
|
+
const configFiles = (cwd, pending2 = false) => {
|
|
42149
42322
|
const g = inspectGlobal();
|
|
42323
|
+
const a = inspectApprovals();
|
|
42150
42324
|
let within;
|
|
42151
42325
|
if (cwd !== void 0) {
|
|
42152
42326
|
try {
|
|
@@ -42155,7 +42329,11 @@ async function runDaemon(deps = {}) {
|
|
|
42155
42329
|
within = new Set(configPaths(cwd));
|
|
42156
42330
|
}
|
|
42157
42331
|
}
|
|
42158
|
-
return [
|
|
42332
|
+
return [
|
|
42333
|
+
...configIssues.list(within, { pending: pending2 }),
|
|
42334
|
+
...a ? [a] : [],
|
|
42335
|
+
...g ? [g] : []
|
|
42336
|
+
];
|
|
42159
42337
|
};
|
|
42160
42338
|
const resolveNs = (cwd, allowMissing) => (deps.resolveNamespace ?? ((dir) => resolveNamespace(dir, { log, allowMissing, issues: configIssues })))(cwd);
|
|
42161
42339
|
const cl = deps.claude ?? {};
|
|
@@ -42201,7 +42379,7 @@ async function runDaemon(deps = {}) {
|
|
|
42201
42379
|
log,
|
|
42202
42380
|
promptIdSupported: () => promptIdSupported,
|
|
42203
42381
|
uncertain: new HeldStore(
|
|
42204
|
-
oc.uncertainFile ??
|
|
42382
|
+
oc.uncertainFile ?? join12(home(), "opencode-uncertain.json")
|
|
42205
42383
|
)
|
|
42206
42384
|
});
|
|
42207
42385
|
const codex = new CodexTransport({
|
|
@@ -42212,7 +42390,7 @@ async function runDaemon(deps = {}) {
|
|
|
42212
42390
|
run: cx.run ?? execCodex(),
|
|
42213
42391
|
home: cx.home ?? codexHome(),
|
|
42214
42392
|
wakes: cx.wakes ?? codexHostWakes,
|
|
42215
|
-
queued: new HeldStore(cx.queuedFile ??
|
|
42393
|
+
queued: new HeldStore(cx.queuedFile ?? join12(home(), "codex-queued.json")),
|
|
42216
42394
|
log
|
|
42217
42395
|
});
|
|
42218
42396
|
const pi = new PiTransport({
|
|
@@ -42224,7 +42402,7 @@ async function runDaemon(deps = {}) {
|
|
|
42224
42402
|
},
|
|
42225
42403
|
ackTimeoutMs: deps.pi?.ackTimeoutMs
|
|
42226
42404
|
});
|
|
42227
|
-
const sent = new SentStore(deps.sentFile ??
|
|
42405
|
+
const sent = new SentStore(deps.sentFile ?? join12(home(), "sent.json"), {
|
|
42228
42406
|
log
|
|
42229
42407
|
});
|
|
42230
42408
|
const receipts = new Receipts(sent, { after: deps.deliveredTimer });
|
|
@@ -42317,15 +42495,15 @@ async function runDaemon(deps = {}) {
|
|
|
42317
42495
|
socketsDir: returnDir,
|
|
42318
42496
|
// A deps.socketsDir is the caller's (tests); ours is re-checked before each bind.
|
|
42319
42497
|
prepareDir: cl.socketsDir ? void 0 : (d) => prepareReturnDir(d),
|
|
42320
|
-
heldFile: cl.heldFile ??
|
|
42321
|
-
returnIndexFile: cl.returnIndexFile ?? (cl.heldFile ? cl.heldFile.replace(/(\.json)?$/, ".return.json") :
|
|
42498
|
+
heldFile: cl.heldFile ?? join12(home(), "claude-held.json"),
|
|
42499
|
+
returnIndexFile: cl.returnIndexFile ?? (cl.heldFile ? cl.heldFile.replace(/(\.json)?$/, ".return.json") : join12(home(), "claude-return.json")),
|
|
42322
42500
|
statusWindowMs: cl.statusWindowMs,
|
|
42323
42501
|
injectTimeoutMs: cl.injectTimeoutMs,
|
|
42324
42502
|
log,
|
|
42325
42503
|
target: (ref) => claudeTarget(ref, claudeSessions),
|
|
42326
42504
|
// A native reply is a message from the session: the sink names the sender, never the frame.
|
|
42327
42505
|
// Every reply names the peer's namespace (the deliver's), so a same-named local peer cannot get it.
|
|
42328
|
-
onReply: (agentRef, peerName, text3,
|
|
42506
|
+
onReply: (agentRef, peerName, text3, namespace2, peerId) => {
|
|
42329
42507
|
if (!isWellFormed2(text3))
|
|
42330
42508
|
log(
|
|
42331
42509
|
`a Claude reply to ${peerName} was not well-formed unicode; sent with U+FFFD`
|
|
@@ -42337,7 +42515,7 @@ async function runDaemon(deps = {}) {
|
|
|
42337
42515
|
type: "send",
|
|
42338
42516
|
from_ref: agentRef,
|
|
42339
42517
|
to_name: peerName,
|
|
42340
|
-
to_namespace:
|
|
42518
|
+
to_namespace: namespace2,
|
|
42341
42519
|
body
|
|
42342
42520
|
};
|
|
42343
42521
|
if (!ClientFrameSchema.safeParse(f).success) {
|
|
@@ -42378,7 +42556,7 @@ async function runDaemon(deps = {}) {
|
|
|
42378
42556
|
continue;
|
|
42379
42557
|
}
|
|
42380
42558
|
if (prev && prev.pid === s.pid) continue;
|
|
42381
|
-
if (!
|
|
42559
|
+
if (!isAbsolute6(s.cwd)) continue;
|
|
42382
42560
|
let ns;
|
|
42383
42561
|
try {
|
|
42384
42562
|
ns = resolveNs(s.cwd, true);
|
|
@@ -42564,7 +42742,7 @@ async function runDaemon(deps = {}) {
|
|
|
42564
42742
|
process.exitCode = 1;
|
|
42565
42743
|
try {
|
|
42566
42744
|
writeFileSync4(
|
|
42567
|
-
deps.revokedFile ??
|
|
42745
|
+
deps.revokedFile ?? join12(home(), "revoked"),
|
|
42568
42746
|
revokedMarker(cfg.machine_token),
|
|
42569
42747
|
{ mode: 384 }
|
|
42570
42748
|
);
|
|
@@ -42612,21 +42790,21 @@ async function runDaemon(deps = {}) {
|
|
|
42612
42790
|
statusEveryMs: deps.status?.statusEveryMs
|
|
42613
42791
|
});
|
|
42614
42792
|
const hubRoster = (ref) => new Promise(
|
|
42615
|
-
(
|
|
42793
|
+
(resolve9) => {
|
|
42616
42794
|
const id = pending.open(
|
|
42617
42795
|
"status",
|
|
42618
|
-
(f) =>
|
|
42796
|
+
(f) => resolve9(f.type === "roster" ? f.agents : void 0)
|
|
42619
42797
|
);
|
|
42620
42798
|
const timer = setTimeout(() => {
|
|
42621
42799
|
pending.cancel(id);
|
|
42622
42800
|
hub.cancel(id);
|
|
42623
|
-
|
|
42801
|
+
resolve9(void 0);
|
|
42624
42802
|
}, deps.statusRosterMs ?? 1500);
|
|
42625
42803
|
timer.unref();
|
|
42626
42804
|
if (!hub.send({ v: 1, id, type: "list", from_ref: ref })) {
|
|
42627
42805
|
clearTimeout(timer);
|
|
42628
42806
|
pending.cancel(id);
|
|
42629
|
-
|
|
42807
|
+
resolve9(void 0);
|
|
42630
42808
|
}
|
|
42631
42809
|
}
|
|
42632
42810
|
);
|
|
@@ -42650,7 +42828,7 @@ async function runDaemon(deps = {}) {
|
|
|
42650
42828
|
// this machine's open sessions are in (or only the cwd's).
|
|
42651
42829
|
onStatus: async (req) => {
|
|
42652
42830
|
let only;
|
|
42653
|
-
if (req.cwd &&
|
|
42831
|
+
if (req.cwd && isAbsolute6(req.cwd)) {
|
|
42654
42832
|
try {
|
|
42655
42833
|
only = resolveNs(req.cwd, true).namespace;
|
|
42656
42834
|
} catch {
|
|
@@ -42663,8 +42841,8 @@ async function runDaemon(deps = {}) {
|
|
|
42663
42841
|
)
|
|
42664
42842
|
];
|
|
42665
42843
|
const namespaces = await Promise.all(
|
|
42666
|
-
names2.map(async (
|
|
42667
|
-
const local = live.filter((a) => a.namespace ===
|
|
42844
|
+
names2.map(async (namespace2) => {
|
|
42845
|
+
const local = live.filter((a) => a.namespace === namespace2);
|
|
42668
42846
|
const mine = new Map(local.map((a) => [a.busName, a.kind]));
|
|
42669
42847
|
const roster2 = local[0] && hub.open ? await hubRoster(local[0].ref) : void 0;
|
|
42670
42848
|
const rows = roster2 ? roster2.filter((a) => a.state !== "away").map((a) => ({
|
|
@@ -42681,10 +42859,13 @@ async function runDaemon(deps = {}) {
|
|
|
42681
42859
|
machine: cfg.label,
|
|
42682
42860
|
state: "live"
|
|
42683
42861
|
}));
|
|
42684
|
-
return { namespace, agents: rows };
|
|
42862
|
+
return { namespace: namespace2, agents: rows };
|
|
42685
42863
|
})
|
|
42686
42864
|
);
|
|
42687
|
-
const config_files = configFiles(
|
|
42865
|
+
const config_files = configFiles(
|
|
42866
|
+
void 0,
|
|
42867
|
+
req.caps?.includes(ADAPTER_CAPS.pending)
|
|
42868
|
+
);
|
|
42688
42869
|
return {
|
|
42689
42870
|
pid: process.pid,
|
|
42690
42871
|
version: version2,
|
|
@@ -42759,7 +42940,7 @@ async function runDaemon(deps = {}) {
|
|
|
42759
42940
|
};
|
|
42760
42941
|
}
|
|
42761
42942
|
const cwd = check2.cwd ?? hello.cwd;
|
|
42762
|
-
if (!cwd || !
|
|
42943
|
+
if (!cwd || !isAbsolute6(cwd)) return { error: "cwd must be absolute" };
|
|
42763
42944
|
let ns;
|
|
42764
42945
|
try {
|
|
42765
42946
|
ns = resolveNs(cwd, check2.cwd !== void 0);
|
|
@@ -42973,8 +43154,9 @@ async function runDaemon(deps = {}) {
|
|
|
42973
43154
|
// src/context.ts
|
|
42974
43155
|
init_src3();
|
|
42975
43156
|
import { execFileSync as execFileSync5, spawn as spawn2 } from "node:child_process";
|
|
42976
|
-
import { closeSync as
|
|
43157
|
+
import { closeSync as closeSync5, openSync as openSync5, readFileSync as readFileSync13 } from "node:fs";
|
|
42977
43158
|
import { homedir as homedir3, userInfo as userInfo2 } from "node:os";
|
|
43159
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
42978
43160
|
init_src2();
|
|
42979
43161
|
|
|
42980
43162
|
// src/copy.ts
|
|
@@ -43279,11 +43461,11 @@ function copy(style) {
|
|
|
43279
43461
|
fail("The daemon did not start within 10 seconds."),
|
|
43280
43462
|
next(`Run ${BUS_CMD} doctor to see why.`)
|
|
43281
43463
|
],
|
|
43282
|
-
rosterHeader: (
|
|
43464
|
+
rosterHeader: (namespace2, live, queued2) => {
|
|
43283
43465
|
const n = live + queued2;
|
|
43284
43466
|
const meta3 = queued2 ? `${live} live ${g("sep")} ${queued2} queued` : `${live} live`;
|
|
43285
43467
|
const lead = `${n} agent${n === 1 ? "" : "s"} in namespace `;
|
|
43286
|
-
return `${lead}${p("accent", clip(
|
|
43468
|
+
return `${lead}${p("accent", clip(namespace2, len(lead) + 2 + len(meta3)))} ${p("muted", meta3)}`;
|
|
43287
43469
|
},
|
|
43288
43470
|
rosterRow: (a) => ` ${cell(a.name, 20, more)}${cell(kindLabel(a.kind), 13, more)}${cell(a.machine, 22, more)}${a.state === "live" ? p("success", `${g("live")} live`) : p("warning", `${g("queued")} queued`)}`,
|
|
43289
43471
|
/** The row's status, under it (AC5c): the agent's own report, cut to 80 columns. */
|
|
@@ -43300,10 +43482,10 @@ function copy(style) {
|
|
|
43300
43482
|
),
|
|
43301
43483
|
p("muted", "then the sender is told.")
|
|
43302
43484
|
],
|
|
43303
|
-
noAgents: (
|
|
43485
|
+
noAgents: (namespace2) => {
|
|
43304
43486
|
const lead = "No agents in namespace ";
|
|
43305
43487
|
return [
|
|
43306
|
-
`${lead}${p("accent", clip(
|
|
43488
|
+
`${lead}${p("accent", clip(namespace2, len(lead) + 5))} yet.`,
|
|
43307
43489
|
"Start Claude Code, OpenCode, Pi, oh-my-pi or Codex in this folder and it joins."
|
|
43308
43490
|
];
|
|
43309
43491
|
},
|
|
@@ -43382,8 +43564,8 @@ function copy(style) {
|
|
|
43382
43564
|
next(`Run ${BUS_CMD} --instance <your instance URL>,`),
|
|
43383
43565
|
next("or set OA_BUS_INSTANCE.")
|
|
43384
43566
|
],
|
|
43385
|
-
hubMismatch: (
|
|
43386
|
-
const a = clip(
|
|
43567
|
+
hubMismatch: (approved2, asked, askedUrl) => {
|
|
43568
|
+
const a = clip(approved2, 39 + Math.min(len(asked), 20));
|
|
43387
43569
|
const b2 = clip(asked, 39 + len(a));
|
|
43388
43570
|
return [
|
|
43389
43571
|
fail(`This machine is approved for ${a}, not ${b2}.`),
|
|
@@ -43488,7 +43670,7 @@ function copy(style) {
|
|
|
43488
43670
|
/** A refused or noted config file (#1527): the reason, then the exact fix. Paths arrive already shortened. */
|
|
43489
43671
|
configFile: (f) => [
|
|
43490
43672
|
warn(
|
|
43491
|
-
f.state === "refused" ? `${f.file} ${f.reason}, so it is ignored.` : `${f.file} ${f.reason}; it is still used.`
|
|
43673
|
+
f.state === "refused" ? `${f.file} ${f.reason}, so it is ignored.` : f.state === "pending" ? `${f.file} ${f.reason}, so its namespace is ignored.` : `${f.file} ${f.reason}; it is still used.`
|
|
43492
43674
|
),
|
|
43493
43675
|
next(`Fix: ${f.fix}`),
|
|
43494
43676
|
...f.restart ? [next("Restart the session to pick up a fix.")] : []
|
|
@@ -43622,6 +43804,60 @@ function copy(style) {
|
|
|
43622
43804
|
`${dirs.length} global ${dirs.length === 1 ? "directory" : "directories"}`,
|
|
43623
43805
|
...dirs.map((d) => ` ${clip(d, 2)}`)
|
|
43624
43806
|
],
|
|
43807
|
+
// 12. namespace approvals (#1525)
|
|
43808
|
+
nsUnusable: (path, why) => [
|
|
43809
|
+
warn(`${clip(path, 45)} can't be used, so no namespace is approved.`),
|
|
43810
|
+
next(p("muted", clip(`It ${why}.`, 3))),
|
|
43811
|
+
next(`Remove it, then run ${BUS_CMD} namespace approve <dir> again.`)
|
|
43812
|
+
],
|
|
43813
|
+
nsNoFile: (dir) => [
|
|
43814
|
+
fail(`${clip(dir, 40)} has no .oa-bus.json.`),
|
|
43815
|
+
next("Check the path: approval is for the namespace that file sets.")
|
|
43816
|
+
],
|
|
43817
|
+
nsFileUnusable: (file2, why) => [
|
|
43818
|
+
fail(`${clip(file2, 40)} can't be read: it ${why}.`)
|
|
43819
|
+
],
|
|
43820
|
+
nsNoNamespace: (file2) => warn(`${clip(file2, 40)} sets no namespace. Nothing to approve.`),
|
|
43821
|
+
nsNotDir: (dir) => [
|
|
43822
|
+
fail(`${clip(dir, 23)} is not a directory.`),
|
|
43823
|
+
next(`Check the path, then run ${BUS_CMD} namespace approve again.`)
|
|
43824
|
+
],
|
|
43825
|
+
nsAsk: (dir, namespace2) => [
|
|
43826
|
+
`${dir} sets its namespace to ${namespace2}.`,
|
|
43827
|
+
"Agents started there join it and can message everyone in it."
|
|
43828
|
+
],
|
|
43829
|
+
nsPrompt: () => "Approve it? [y/N] ",
|
|
43830
|
+
nsNeedTty: (command) => [
|
|
43831
|
+
fail("Approving a namespace needs your user."),
|
|
43832
|
+
next(`Ask them to run this in a terminal: ${command}`)
|
|
43833
|
+
],
|
|
43834
|
+
nsDeclined: () => warn("Not approved. Nothing changed."),
|
|
43835
|
+
nsAlready: (dir, namespace2) => done(`${clip(dir, 20)} is already approved for ${clip(namespace2, 40)}.`),
|
|
43836
|
+
nsApproved: (dir, namespace2) => [
|
|
43837
|
+
done(
|
|
43838
|
+
`${clip(dir, 20)} may now use the namespace ${clip(namespace2, 40)}.`
|
|
43839
|
+
),
|
|
43840
|
+
p(
|
|
43841
|
+
"muted",
|
|
43842
|
+
" Agents already running there keep their namespace until they restart."
|
|
43843
|
+
)
|
|
43844
|
+
],
|
|
43845
|
+
nsRevoked: (dir) => [
|
|
43846
|
+
done(`${clip(dir, 24)} is no longer approved.`),
|
|
43847
|
+
p(
|
|
43848
|
+
"muted",
|
|
43849
|
+
" Agents already running there keep their namespace until they restart."
|
|
43850
|
+
)
|
|
43851
|
+
],
|
|
43852
|
+
nsNotListed: (dir) => warn(`${clip(dir, 36)} was not approved. Nothing changed.`),
|
|
43853
|
+
nsNone: () => [
|
|
43854
|
+
"No approved namespaces.",
|
|
43855
|
+
p("muted", `Approve one with ${BUS_CMD} namespace approve <dir>.`)
|
|
43856
|
+
],
|
|
43857
|
+
nsList: (rows) => [
|
|
43858
|
+
`${rows.length} approved ${rows.length === 1 ? "namespace" : "namespaces"}`,
|
|
43859
|
+
...rows.map((r) => ` ${clip(r.dir, 2)} ${p("muted", r.namespace)}`)
|
|
43860
|
+
],
|
|
43625
43861
|
// logs, mcp (DRAFT)
|
|
43626
43862
|
noLog: (path) => [
|
|
43627
43863
|
warn(`No daemon log yet at ${clip(path, 24)}`),
|
|
@@ -43640,19 +43876,19 @@ init_src2();
|
|
|
43640
43876
|
import { execFile as execFile3, spawn } from "node:child_process";
|
|
43641
43877
|
import { promisify } from "node:util";
|
|
43642
43878
|
var browserCommand = (platform, url2) => platform === "darwin" ? { cmd: "open", args: [url2] } : platform === "win32" ? { cmd: "rundll32", args: ["url.dll,FileProtocolHandler", url2] } : { cmd: "xdg-open", args: [url2] };
|
|
43643
|
-
var openBrowser = (url2, launcher = browserCommand(process.platform, url2)) => new Promise((
|
|
43879
|
+
var openBrowser = (url2, launcher = browserCommand(process.platform, url2)) => new Promise((resolve9) => {
|
|
43644
43880
|
try {
|
|
43645
43881
|
const child = spawn(launcher.cmd, launcher.args, {
|
|
43646
43882
|
stdio: "ignore",
|
|
43647
43883
|
detached: true
|
|
43648
43884
|
});
|
|
43649
|
-
child.once("error", () =>
|
|
43885
|
+
child.once("error", () => resolve9(false));
|
|
43650
43886
|
child.once("spawn", () => {
|
|
43651
43887
|
child.unref();
|
|
43652
|
-
|
|
43888
|
+
resolve9(true);
|
|
43653
43889
|
});
|
|
43654
43890
|
} catch {
|
|
43655
|
-
|
|
43891
|
+
resolve9(false);
|
|
43656
43892
|
}
|
|
43657
43893
|
});
|
|
43658
43894
|
var EXEC_TIMEOUT_MS = 1e4;
|
|
@@ -43693,22 +43929,22 @@ var realDeps = {
|
|
|
43693
43929
|
// src/steps/service.ts
|
|
43694
43930
|
import { createHash as createHash5 } from "node:crypto";
|
|
43695
43931
|
import {
|
|
43696
|
-
chmodSync as
|
|
43932
|
+
chmodSync as chmodSync9,
|
|
43697
43933
|
cpSync,
|
|
43698
43934
|
existsSync as existsSync3,
|
|
43699
43935
|
lstatSync as lstatSync8,
|
|
43700
|
-
mkdirSync as
|
|
43936
|
+
mkdirSync as mkdirSync8,
|
|
43701
43937
|
realpathSync as realpathSync7,
|
|
43702
|
-
renameSync as
|
|
43938
|
+
renameSync as renameSync8,
|
|
43703
43939
|
rmSync as rmSync4,
|
|
43704
43940
|
writeFileSync as writeFileSync6
|
|
43705
43941
|
} from "node:fs";
|
|
43706
|
-
import { basename as basename6, dirname as
|
|
43942
|
+
import { basename as basename6, dirname as dirname8, isAbsolute as isAbsolute7, join as join14, resolve as resolve4 } from "node:path";
|
|
43707
43943
|
import { fileURLToPath } from "node:url";
|
|
43708
43944
|
|
|
43709
43945
|
// src/steps/codex.ts
|
|
43710
43946
|
import { lstatSync as lstatSync7, readFileSync as readFileSync11 } from "node:fs";
|
|
43711
|
-
import { join as
|
|
43947
|
+
import { join as join13, resolve as resolve3 } from "node:path";
|
|
43712
43948
|
|
|
43713
43949
|
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/error.js
|
|
43714
43950
|
function getLineColFromPtr(string4, ptr) {
|
|
@@ -44470,12 +44706,12 @@ var HAS_WELLFORMED = !!"".isWellFormed;
|
|
|
44470
44706
|
|
|
44471
44707
|
// src/steps/codex.ts
|
|
44472
44708
|
var CODEX_ENTRY = "oa_bus";
|
|
44473
|
-
var codexHome2 = (home2, env2) => env2.CODEX_HOME ? resolve3(env2.CODEX_HOME) :
|
|
44709
|
+
var codexHome2 = (home2, env2) => env2.CODEX_HOME ? resolve3(env2.CODEX_HOME) : join13(home2, ".codex");
|
|
44474
44710
|
function codexHomeEnv(home2, env2) {
|
|
44475
44711
|
const dir = codexHome2(home2, env2);
|
|
44476
|
-
return dir ===
|
|
44712
|
+
return dir === join13(home2, ".codex") ? {} : { CODEX_HOME: dir };
|
|
44477
44713
|
}
|
|
44478
|
-
var codexConfig = (home2, env2) =>
|
|
44714
|
+
var codexConfig = (home2, env2) => join13(codexHome2(home2, env2), "config.toml");
|
|
44479
44715
|
function hasCodex(o) {
|
|
44480
44716
|
if (o.which("codex")) return true;
|
|
44481
44717
|
try {
|
|
@@ -44509,7 +44745,7 @@ function codexEntry(busBin, home2, busHome2) {
|
|
|
44509
44745
|
return {
|
|
44510
44746
|
command: busBin[0],
|
|
44511
44747
|
args: [...busBin.slice(1), "mcp", "codex"],
|
|
44512
|
-
...ob ===
|
|
44748
|
+
...ob === join13(home2, ".oa-bus") ? {} : { env: { OA_BUS_HOME: ob } },
|
|
44513
44749
|
default_tools_approval_mode: "approve"
|
|
44514
44750
|
};
|
|
44515
44751
|
}
|
|
@@ -44535,7 +44771,7 @@ function sandboxRisk(doc, home2, codexDir) {
|
|
|
44535
44771
|
});
|
|
44536
44772
|
const covers = (root) => {
|
|
44537
44773
|
const r = resolve3(
|
|
44538
|
-
root === "~" ? home2 : root.startsWith("~/") ?
|
|
44774
|
+
root === "~" ? home2 : root.startsWith("~/") ? join13(home2, root.slice(2)) : root
|
|
44539
44775
|
);
|
|
44540
44776
|
return r === "/" || codexDir === r || codexDir.startsWith(`${r}/`) || r.startsWith(`${codexDir}/`);
|
|
44541
44777
|
};
|
|
@@ -44742,13 +44978,13 @@ function remove(path, text3, doc) {
|
|
|
44742
44978
|
|
|
44743
44979
|
// src/steps/step.ts
|
|
44744
44980
|
import {
|
|
44745
|
-
chmodSync as
|
|
44746
|
-
mkdirSync as
|
|
44981
|
+
chmodSync as chmodSync8,
|
|
44982
|
+
mkdirSync as mkdirSync7,
|
|
44747
44983
|
readFileSync as readFileSync12,
|
|
44748
|
-
renameSync as
|
|
44984
|
+
renameSync as renameSync7,
|
|
44749
44985
|
writeFileSync as writeFileSync5
|
|
44750
44986
|
} from "node:fs";
|
|
44751
|
-
import { dirname as
|
|
44987
|
+
import { dirname as dirname7 } from "node:path";
|
|
44752
44988
|
function readInstallFile(path) {
|
|
44753
44989
|
try {
|
|
44754
44990
|
const v = JSON.parse(readFileSync12(path, "utf8"));
|
|
@@ -44760,12 +44996,12 @@ function readInstallFile(path) {
|
|
|
44760
44996
|
}
|
|
44761
44997
|
function updateInstallFile(path, patch) {
|
|
44762
44998
|
const next = { ...readInstallFile(path), ...patch };
|
|
44763
|
-
|
|
44999
|
+
mkdirSync7(dirname7(path), { recursive: true, mode: 448 });
|
|
44764
45000
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
44765
45001
|
writeFileSync5(tmp, `${JSON.stringify(next, null, 2)}
|
|
44766
45002
|
`, { mode: 384 });
|
|
44767
|
-
|
|
44768
|
-
|
|
45003
|
+
chmodSync8(tmp, 384);
|
|
45004
|
+
renameSync7(tmp, path);
|
|
44769
45005
|
}
|
|
44770
45006
|
async function runSteps(steps, ctx, record6) {
|
|
44771
45007
|
for (const step2 of steps) {
|
|
@@ -44861,7 +45097,7 @@ function cliSource() {
|
|
|
44861
45097
|
jiti: import.meta.resolve("jiti")
|
|
44862
45098
|
} : { kind: "bundle", file: here };
|
|
44863
45099
|
}
|
|
44864
|
-
var entryName = (src) => src.kind === "bundle" ?
|
|
45100
|
+
var entryName = (src) => src.kind === "bundle" ? join14(basename6(dirname8(src.file)), basename6(src.file)) : "oa-bus.js";
|
|
44865
45101
|
var shim = (src) => `// Written by oa-bus install: runs the sources it was installed from.
|
|
44866
45102
|
import { createJiti } from ${JSON.stringify(src.jiti)};
|
|
44867
45103
|
|
|
@@ -44871,24 +45107,24 @@ const code = await main(process.argv.slice(2));
|
|
|
44871
45107
|
if (code !== undefined) process.exit(code);
|
|
44872
45108
|
`;
|
|
44873
45109
|
function installCli(home2, src) {
|
|
44874
|
-
const bin =
|
|
45110
|
+
const bin = join14(home2, "bin");
|
|
44875
45111
|
const tmp = `${bin}.${process.pid}.tmp`;
|
|
44876
|
-
|
|
44877
|
-
|
|
45112
|
+
mkdirSync8(home2, { recursive: true, mode: 448 });
|
|
45113
|
+
chmodSync9(home2, 448);
|
|
44878
45114
|
rmSync4(tmp, { recursive: true, force: true });
|
|
44879
|
-
|
|
45115
|
+
mkdirSync8(tmp);
|
|
44880
45116
|
if (src.kind === "bundle") {
|
|
44881
|
-
const pkg =
|
|
45117
|
+
const pkg = dirname8(dirname8(src.file));
|
|
44882
45118
|
for (const name of ["dist", "assets", "package.json"])
|
|
44883
|
-
if (existsSync3(
|
|
44884
|
-
cpSync(
|
|
44885
|
-
} else writeFileSync6(
|
|
44886
|
-
|
|
44887
|
-
if (!existsSync3(
|
|
44888
|
-
writeFileSync6(
|
|
45119
|
+
if (existsSync3(join14(pkg, name)))
|
|
45120
|
+
cpSync(join14(pkg, name), join14(tmp, name), { recursive: true });
|
|
45121
|
+
} else writeFileSync6(join14(tmp, entryName(src)), shim(src));
|
|
45122
|
+
chmodSync9(tmp, 448);
|
|
45123
|
+
if (!existsSync3(join14(tmp, "package.json")))
|
|
45124
|
+
writeFileSync6(join14(tmp, "package.json"), '{ "type": "module" }\n');
|
|
44889
45125
|
rmSync4(bin, { recursive: true, force: true });
|
|
44890
|
-
|
|
44891
|
-
return
|
|
45126
|
+
renameSync8(tmp, bin);
|
|
45127
|
+
return join14(bin, entryName(src));
|
|
44892
45128
|
}
|
|
44893
45129
|
var present = (path) => {
|
|
44894
45130
|
try {
|
|
@@ -44899,11 +45135,11 @@ var present = (path) => {
|
|
|
44899
45135
|
}
|
|
44900
45136
|
};
|
|
44901
45137
|
function writeReplacing(path, text3) {
|
|
44902
|
-
|
|
45138
|
+
mkdirSync8(dirname8(path), { recursive: true });
|
|
44903
45139
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
44904
45140
|
try {
|
|
44905
45141
|
writeFileSync6(tmp, text3, { mode: 420 });
|
|
44906
|
-
|
|
45142
|
+
renameSync8(tmp, path);
|
|
44907
45143
|
} catch (e) {
|
|
44908
45144
|
rmSync4(tmp, { force: true });
|
|
44909
45145
|
throw e;
|
|
@@ -44914,11 +45150,11 @@ var real = (path) => {
|
|
|
44914
45150
|
try {
|
|
44915
45151
|
return realpathSync7(abs);
|
|
44916
45152
|
} catch {
|
|
44917
|
-
const parent =
|
|
44918
|
-
return parent === abs ? abs :
|
|
45153
|
+
const parent = dirname8(abs);
|
|
45154
|
+
return parent === abs ? abs : join14(real(parent), basename6(abs));
|
|
44919
45155
|
}
|
|
44920
45156
|
};
|
|
44921
|
-
var isDefaultHome = (home2, userHome) => real(home2) === real(
|
|
45157
|
+
var isDefaultHome = (home2, userHome) => real(home2) === real(join14(userHome, ".oa-bus"));
|
|
44922
45158
|
function serviceNames(home2, userHome) {
|
|
44923
45159
|
const suffix = isDefaultHome(home2, userHome) ? "" : createHash5("sha256").update(real(home2)).digest("hex").slice(0, 8);
|
|
44924
45160
|
return {
|
|
@@ -44945,19 +45181,19 @@ function systemService(d) {
|
|
|
44945
45181
|
const manager = d.platform === "darwin" ? "launchd" : d.platform === "linux" ? "systemd" : void 0;
|
|
44946
45182
|
const home2 = () => resolve4(d.home());
|
|
44947
45183
|
const names2 = () => serviceNames(home2(), d.userHome);
|
|
44948
|
-
const entryOf = () =>
|
|
44949
|
-
const installFile = () =>
|
|
45184
|
+
const entryOf = () => join14(home2(), "bin", entryName(d.source()));
|
|
45185
|
+
const installFile = () => join14(home2(), "install.json");
|
|
44950
45186
|
const record6 = () => {
|
|
44951
45187
|
const r = readInstallFile(installFile()).service;
|
|
44952
45188
|
return typeof r === "object" && r !== null ? r : {};
|
|
44953
45189
|
};
|
|
44954
45190
|
const xdg = d.env.XDG_CONFIG_HOME;
|
|
44955
|
-
const configHome = xdg &&
|
|
45191
|
+
const configHome = xdg && isAbsolute7(xdg) ? xdg : join14(d.userHome, ".config");
|
|
44956
45192
|
const fileName = () => manager === "launchd" ? `${names2().label}.plist` : names2().unit;
|
|
44957
|
-
const fresh = () => manager === "launchd" ?
|
|
45193
|
+
const fresh = () => manager === "launchd" ? join14(d.userHome, "Library/LaunchAgents", fileName()) : join14(configHome, "systemd/user", fileName());
|
|
44958
45194
|
const recorded = () => {
|
|
44959
45195
|
const r = record6().unit;
|
|
44960
|
-
return typeof r === "string" &&
|
|
45196
|
+
return typeof r === "string" && isAbsolute7(r) && basename6(r) === fileName() ? r : void 0;
|
|
44961
45197
|
};
|
|
44962
45198
|
const file2 = () => {
|
|
44963
45199
|
const r = recorded();
|
|
@@ -45019,10 +45255,10 @@ function systemService(d) {
|
|
|
45019
45255
|
async ensure() {
|
|
45020
45256
|
const h = home2();
|
|
45021
45257
|
const src = d.source();
|
|
45022
|
-
const logs2 =
|
|
45258
|
+
const logs2 = join14(h, "logs");
|
|
45023
45259
|
const u = {
|
|
45024
45260
|
node: d.execPath,
|
|
45025
|
-
entry:
|
|
45261
|
+
entry: join14(h, "bin", entryName(src)),
|
|
45026
45262
|
env: {
|
|
45027
45263
|
PATH: d.env.PATH ?? DEFAULT_PATH,
|
|
45028
45264
|
...isDefaultHome(h, d.userHome) ? {} : { OA_BUS_HOME: h },
|
|
@@ -45030,8 +45266,8 @@ function systemService(d) {
|
|
|
45030
45266
|
...codexHomeEnv(d.userHome, d.env)
|
|
45031
45267
|
},
|
|
45032
45268
|
// One file: the daemon logs to stderr, and `oa-bus logs` tails it.
|
|
45033
|
-
out:
|
|
45034
|
-
err:
|
|
45269
|
+
out: join14(logs2, "daemon.log"),
|
|
45270
|
+
err: join14(logs2, "daemon.log")
|
|
45035
45271
|
};
|
|
45036
45272
|
const unit = { ...u, env: { ...u.env, OA_BUS_SERVICE: "1" } };
|
|
45037
45273
|
renderPlist(unit);
|
|
@@ -45042,7 +45278,7 @@ function systemService(d) {
|
|
|
45042
45278
|
const left = await stopDaemon();
|
|
45043
45279
|
if (left !== void 0) return { running: left };
|
|
45044
45280
|
installCli(h, src);
|
|
45045
|
-
|
|
45281
|
+
mkdirSync8(logs2, { recursive: true, mode: 448 });
|
|
45046
45282
|
const f = fresh();
|
|
45047
45283
|
const old = recorded();
|
|
45048
45284
|
if (old && old !== f) {
|
|
@@ -45132,7 +45368,7 @@ function systemService(d) {
|
|
|
45132
45368
|
const node2 = record6().node;
|
|
45133
45369
|
if (typeof node2 === "string" && !existsSync3(node2))
|
|
45134
45370
|
out.push({ kind: "node-missing", node: node2 });
|
|
45135
|
-
if (manager === "systemd" && !existsSync3(
|
|
45371
|
+
if (manager === "systemd" && !existsSync3(join14(d.lingerDir ?? "/var/lib/systemd/linger", d.user)))
|
|
45136
45372
|
out.push({ kind: "linger-off" });
|
|
45137
45373
|
return out;
|
|
45138
45374
|
}
|
|
@@ -45145,7 +45381,7 @@ var noService = {
|
|
|
45145
45381
|
remove: async () => ({}),
|
|
45146
45382
|
cli: () => ["oa-bus"]
|
|
45147
45383
|
};
|
|
45148
|
-
var VERSION = true ? "0.
|
|
45384
|
+
var VERSION = true ? "0.128.0" : JSON.parse(
|
|
45149
45385
|
readFileSync13(new URL("../package.json", import.meta.url), "utf8")
|
|
45150
45386
|
).version;
|
|
45151
45387
|
var which = (cmd) => {
|
|
@@ -45174,8 +45410,8 @@ function processArgs2(pid, io = {
|
|
|
45174
45410
|
}
|
|
45175
45411
|
}
|
|
45176
45412
|
var spawnDaemon = (cmd, args, opts) => {
|
|
45177
|
-
const out =
|
|
45178
|
-
const err =
|
|
45413
|
+
const out = openSync5(opts.out, "a", 384);
|
|
45414
|
+
const err = openSync5(opts.err, "a", 384);
|
|
45179
45415
|
try {
|
|
45180
45416
|
const child = spawn2(cmd, args, {
|
|
45181
45417
|
detached: true,
|
|
@@ -45185,8 +45421,8 @@ var spawnDaemon = (cmd, args, opts) => {
|
|
|
45185
45421
|
child.unref();
|
|
45186
45422
|
return child.pid;
|
|
45187
45423
|
} finally {
|
|
45188
|
-
|
|
45189
|
-
|
|
45424
|
+
closeSync5(out);
|
|
45425
|
+
closeSync5(err);
|
|
45190
45426
|
}
|
|
45191
45427
|
};
|
|
45192
45428
|
var userName = () => {
|
|
@@ -45218,7 +45454,21 @@ function realCtx(noColor) {
|
|
|
45218
45454
|
copy: copy(style),
|
|
45219
45455
|
platform: `${process.platform} ${process.arch}`,
|
|
45220
45456
|
nodeVersion: process.version,
|
|
45221
|
-
...process.platform === "darwin" ? { codexApp: CODEX_APP } : {}
|
|
45457
|
+
...process.platform === "darwin" ? { codexApp: CODEX_APP } : {},
|
|
45458
|
+
stdinIsTTY: Boolean(process.stdin.isTTY),
|
|
45459
|
+
readLine: async (question) => {
|
|
45460
|
+
const rl = createInterface2({
|
|
45461
|
+
input: process.stdin,
|
|
45462
|
+
output: process.stdout
|
|
45463
|
+
});
|
|
45464
|
+
try {
|
|
45465
|
+
return await new Promise(
|
|
45466
|
+
(resolve9) => rl.question(question, resolve9)
|
|
45467
|
+
);
|
|
45468
|
+
} finally {
|
|
45469
|
+
rl.close();
|
|
45470
|
+
}
|
|
45471
|
+
}
|
|
45222
45472
|
};
|
|
45223
45473
|
ctx.service = systemService({
|
|
45224
45474
|
platform: process.platform,
|
|
@@ -45300,10 +45550,10 @@ var configFileLines = (ctx, files) => files.flatMap(
|
|
|
45300
45550
|
|
|
45301
45551
|
// src/machine.ts
|
|
45302
45552
|
import { readFileSync as readFileSync14, statSync as statSync8 } from "node:fs";
|
|
45303
|
-
import { join as
|
|
45553
|
+
import { join as join15 } from "node:path";
|
|
45304
45554
|
init_src();
|
|
45305
45555
|
function readMachine(home2) {
|
|
45306
|
-
const file2 =
|
|
45556
|
+
const file2 = join15(home2, "machine.json");
|
|
45307
45557
|
let text3;
|
|
45308
45558
|
let mode;
|
|
45309
45559
|
try {
|
|
@@ -45334,11 +45584,11 @@ var lasting = (e) => [...START_ERROR_CODES, "EACCES", "EPERM"].includes(
|
|
|
45334
45584
|
);
|
|
45335
45585
|
async function daemon(ctx, run4 = runDaemon, signals = process) {
|
|
45336
45586
|
const m = readMachine(ctx.home);
|
|
45337
|
-
if (existsSync4(
|
|
45587
|
+
if (existsSync4(join16(ctx.home, "revoked")) && (m.state !== "ok" || m.revoked)) {
|
|
45338
45588
|
sayErr(ctx, ctx.copy.revoked());
|
|
45339
45589
|
return 0;
|
|
45340
45590
|
}
|
|
45341
|
-
return new Promise((
|
|
45591
|
+
return new Promise((resolve9) => {
|
|
45342
45592
|
let running;
|
|
45343
45593
|
let ended = false;
|
|
45344
45594
|
const end = (code2) => {
|
|
@@ -45346,7 +45596,7 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
|
|
|
45346
45596
|
ended = true;
|
|
45347
45597
|
signals.off("SIGINT", onSignal);
|
|
45348
45598
|
signals.off("SIGTERM", onSignal);
|
|
45349
|
-
void (running?.stop() ?? Promise.resolve()).finally(() =>
|
|
45599
|
+
void (running?.stop() ?? Promise.resolve()).finally(() => resolve9(code2));
|
|
45350
45600
|
};
|
|
45351
45601
|
const onSignal = () => end(0);
|
|
45352
45602
|
signals.once("SIGINT", onSignal);
|
|
@@ -45376,7 +45626,7 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
|
|
|
45376
45626
|
|
|
45377
45627
|
// src/commands/doctor.ts
|
|
45378
45628
|
import { readFileSync as readFileSync17 } from "node:fs";
|
|
45379
|
-
import { join as
|
|
45629
|
+
import { join as join21 } from "node:path";
|
|
45380
45630
|
|
|
45381
45631
|
// ../bus-adapter-opencode/src/index.ts
|
|
45382
45632
|
init_session2();
|
|
@@ -45387,20 +45637,20 @@ var OPENCODE_TUI_PLUGIN = fileURLToPath2(
|
|
|
45387
45637
|
);
|
|
45388
45638
|
|
|
45389
45639
|
// src/steps/adapters.ts
|
|
45390
|
-
import { randomBytes as
|
|
45640
|
+
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
45391
45641
|
import {
|
|
45392
|
-
chmodSync as
|
|
45642
|
+
chmodSync as chmodSync10,
|
|
45393
45643
|
existsSync as existsSync5,
|
|
45394
45644
|
lstatSync as lstatSync9,
|
|
45395
|
-
mkdirSync as
|
|
45645
|
+
mkdirSync as mkdirSync9,
|
|
45396
45646
|
readFileSync as readFileSync15,
|
|
45397
45647
|
readlinkSync,
|
|
45398
|
-
renameSync as
|
|
45648
|
+
renameSync as renameSync9,
|
|
45399
45649
|
rmSync as rmSync5,
|
|
45400
45650
|
statSync as statSync9,
|
|
45401
45651
|
writeFileSync as writeFileSync7
|
|
45402
45652
|
} from "node:fs";
|
|
45403
|
-
import { dirname as
|
|
45653
|
+
import { dirname as dirname9, join as join17, resolve as resolve5 } from "node:path";
|
|
45404
45654
|
import { isDeepStrictEqual } from "node:util";
|
|
45405
45655
|
|
|
45406
45656
|
// ../../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
@@ -46632,31 +46882,31 @@ var readAssets = () => ({
|
|
|
46632
46882
|
var movedHome = (deps) => {
|
|
46633
46883
|
if (deps.busHome === void 0) return void 0;
|
|
46634
46884
|
const ob = resolve5(deps.busHome);
|
|
46635
|
-
return ob ===
|
|
46885
|
+
return ob === join17(deps.home, ".oa-bus") ? void 0 : ob;
|
|
46636
46886
|
};
|
|
46637
46887
|
var homeLine = (ob) => `process.env.OA_BUS_HOME ||= ${JSON.stringify(ob)};`;
|
|
46638
46888
|
var withHome = (text3, ob) => ob === void 0 ? text3 : `${homeLine(ob)}
|
|
46639
46889
|
${text3}`;
|
|
46640
46890
|
var paths = (deps) => {
|
|
46641
46891
|
const env2 = deps.env ?? {};
|
|
46642
|
-
const opencode = env2.OPENCODE_CONFIG_DIR ??
|
|
46643
|
-
const busDir = deps.busHome ??
|
|
46892
|
+
const opencode = env2.OPENCODE_CONFIG_DIR ?? join17(env2.XDG_CONFIG_HOME ?? join17(deps.home, ".config"), "opencode");
|
|
46893
|
+
const busDir = deps.busHome ?? join17(deps.home, ".oa-bus");
|
|
46644
46894
|
return {
|
|
46645
|
-
claude:
|
|
46895
|
+
claude: join17(env2.CLAUDE_CONFIG_DIR ?? deps.home, ".claude.json"),
|
|
46646
46896
|
// OpenCode reads both; edit the one the user has, else create .json.
|
|
46647
46897
|
opencodeConfigs: [
|
|
46648
|
-
|
|
46649
|
-
|
|
46898
|
+
join17(opencode, "opencode.json"),
|
|
46899
|
+
join17(opencode, "opencode.jsonc")
|
|
46650
46900
|
],
|
|
46651
|
-
opencodeCli:
|
|
46652
|
-
record:
|
|
46901
|
+
opencodeCli: join17(opencode, "cli.json"),
|
|
46902
|
+
record: join17(busDir, "install.json"),
|
|
46653
46903
|
// OpenCode registers the folder that holds tui.js.
|
|
46654
|
-
opencodePlugin:
|
|
46655
|
-
pi:
|
|
46656
|
-
agentDirEnv(deps.home, env2) ??
|
|
46904
|
+
opencodePlugin: join17(busDir, "integrations/opencode", NAME),
|
|
46905
|
+
pi: join17(
|
|
46906
|
+
agentDirEnv(deps.home, env2) ?? join17(deps.home, ".pi/agent"),
|
|
46657
46907
|
"extensions/oa-bus.ts"
|
|
46658
46908
|
),
|
|
46659
|
-
omp:
|
|
46909
|
+
omp: join17(ompAgentDir(deps.home, env2), "extensions/oa-bus.ts"),
|
|
46660
46910
|
codex: codexConfig(deps.home, env2),
|
|
46661
46911
|
codexBin: codexBinFile(busDir),
|
|
46662
46912
|
busDir
|
|
@@ -46666,9 +46916,9 @@ function agentDirEnv(home2, env2) {
|
|
|
46666
46916
|
const dir = env2.PI_CODING_AGENT_DIR;
|
|
46667
46917
|
if (!dir) return void 0;
|
|
46668
46918
|
if (dir === "~") return home2;
|
|
46669
|
-
return resolve5(dir.startsWith("~/") ?
|
|
46919
|
+
return resolve5(dir.startsWith("~/") ? join17(home2, dir.slice(2)) : dir);
|
|
46670
46920
|
}
|
|
46671
|
-
var ompRoot = (home2, env2) =>
|
|
46921
|
+
var ompRoot = (home2, env2) => join17(home2, env2.PI_CONFIG_DIR || ".omp");
|
|
46672
46922
|
function ompProfile(env2) {
|
|
46673
46923
|
const name = (env2.OMP_PROFILE !== void 0 ? env2.OMP_PROFILE : env2.PI_PROFILE)?.trim();
|
|
46674
46924
|
if (!name || name === "default" || name.endsWith(".")) return void 0;
|
|
@@ -46677,14 +46927,14 @@ function ompProfile(env2) {
|
|
|
46677
46927
|
function ompAgentDir(home2, env2) {
|
|
46678
46928
|
const root = ompRoot(home2, env2);
|
|
46679
46929
|
const profile = ompProfile(env2);
|
|
46680
|
-
if (profile) return
|
|
46930
|
+
if (profile) return join17(root, "profiles", profile, "agent");
|
|
46681
46931
|
const piProfile = ompProfile({ PI_PROFILE: env2.PI_PROFILE });
|
|
46682
46932
|
const dir = agentDirEnv(home2, env2);
|
|
46683
|
-
if (dir && !(piProfile && dir ===
|
|
46933
|
+
if (dir && !(piProfile && dir === join17(root, "profiles", piProfile, "agent")))
|
|
46684
46934
|
return dir;
|
|
46685
|
-
return
|
|
46935
|
+
return join17(root, "agent");
|
|
46686
46936
|
}
|
|
46687
|
-
var hasOmp = (deps) => deps.which("omp") || present2(ompRoot(deps.home, deps.env ?? {})) || present2(
|
|
46937
|
+
var hasOmp = (deps) => deps.which("omp") || present2(ompRoot(deps.home, deps.env ?? {})) || present2(join17(deps.home, ".bun/bin/omp"));
|
|
46688
46938
|
var sharedFile = (deps) => paths(deps).omp === paths(deps).pi;
|
|
46689
46939
|
function readDoc(path) {
|
|
46690
46940
|
let text3;
|
|
@@ -46714,30 +46964,30 @@ function target(path) {
|
|
|
46714
46964
|
let p = path;
|
|
46715
46965
|
for (let hops = 0; hops < 40; hops++) {
|
|
46716
46966
|
if (!present2(p) || !lstatSync9(p).isSymbolicLink()) {
|
|
46717
|
-
if (p !== path && !existsSync5(
|
|
46967
|
+
if (p !== path && !existsSync5(dirname9(p)))
|
|
46718
46968
|
throw new Error(
|
|
46719
46969
|
`${path} is a dangling symlink to ${p}; left it untouched`
|
|
46720
46970
|
);
|
|
46721
46971
|
return p;
|
|
46722
46972
|
}
|
|
46723
|
-
p = resolve5(
|
|
46973
|
+
p = resolve5(dirname9(p), readlinkSync(p));
|
|
46724
46974
|
}
|
|
46725
46975
|
throw new Error(`${path}: too many symlinks; left it untouched`);
|
|
46726
46976
|
}
|
|
46727
46977
|
function writeAtomic(path, data, mode) {
|
|
46728
46978
|
const dest = target(path);
|
|
46729
|
-
|
|
46979
|
+
mkdirSync9(dirname9(dest), { recursive: true });
|
|
46730
46980
|
let m = mode ?? 420;
|
|
46731
46981
|
if (mode === void 0)
|
|
46732
46982
|
try {
|
|
46733
46983
|
m = statSync9(dest).mode & 511;
|
|
46734
46984
|
} catch {
|
|
46735
46985
|
}
|
|
46736
|
-
const tmp = `${dest}.${process.pid}.${
|
|
46986
|
+
const tmp = `${dest}.${process.pid}.${randomBytes3(4).toString("hex")}.tmp`;
|
|
46737
46987
|
try {
|
|
46738
46988
|
writeFileSync7(tmp, data, { mode: m, flag: "wx" });
|
|
46739
|
-
|
|
46740
|
-
|
|
46989
|
+
chmodSync10(tmp, m);
|
|
46990
|
+
renameSync9(tmp, dest);
|
|
46741
46991
|
} catch (e) {
|
|
46742
46992
|
rmSync5(tmp, { force: true });
|
|
46743
46993
|
throw e;
|
|
@@ -46892,7 +47142,7 @@ var install = {
|
|
|
46892
47142
|
created[p.opencodeCli] = add(p.opencodeCli, madeCli);
|
|
46893
47143
|
writeRecord(p.record, record6, created);
|
|
46894
47144
|
writeAtomic(
|
|
46895
|
-
|
|
47145
|
+
join17(p.opencodePlugin, "tui.js"),
|
|
46896
47146
|
withHome(deps.assets.opencodePlugin, movedHome(deps)),
|
|
46897
47147
|
420
|
|
46898
47148
|
);
|
|
@@ -47108,7 +47358,7 @@ function checkAdapters(deps) {
|
|
|
47108
47358
|
}) && listed(
|
|
47109
47359
|
parseJsonc(readFileSync15(p.opencodeCli, "utf8"), p.opencodeCli),
|
|
47110
47360
|
p.opencodePlugin
|
|
47111
|
-
) && homed(
|
|
47361
|
+
) && homed(join17(p.opencodePlugin, "tui.js"))
|
|
47112
47362
|
),
|
|
47113
47363
|
pi: state("pi", () => homed(p.pi)),
|
|
47114
47364
|
omp: state("omp", () => homed(p.omp)),
|
|
@@ -47130,18 +47380,18 @@ function checkAdapters(deps) {
|
|
|
47130
47380
|
|
|
47131
47381
|
// src/commands/login.ts
|
|
47132
47382
|
init_src();
|
|
47133
|
-
import { randomBytes as
|
|
47383
|
+
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
47134
47384
|
import {
|
|
47135
|
-
chmodSync as
|
|
47136
|
-
closeSync as
|
|
47137
|
-
mkdirSync as
|
|
47138
|
-
openSync as
|
|
47139
|
-
renameSync as
|
|
47385
|
+
chmodSync as chmodSync11,
|
|
47386
|
+
closeSync as closeSync6,
|
|
47387
|
+
mkdirSync as mkdirSync10,
|
|
47388
|
+
openSync as openSync6,
|
|
47389
|
+
renameSync as renameSync10,
|
|
47140
47390
|
rmSync as rmSync6,
|
|
47141
|
-
unlinkSync as
|
|
47142
|
-
writeSync as
|
|
47391
|
+
unlinkSync as unlinkSync3,
|
|
47392
|
+
writeSync as writeSync3
|
|
47143
47393
|
} from "node:fs";
|
|
47144
|
-
import { join as
|
|
47394
|
+
import { join as join18 } from "node:path";
|
|
47145
47395
|
|
|
47146
47396
|
// src/machine-label.ts
|
|
47147
47397
|
import { hostname as osHostname } from "node:os";
|
|
@@ -47187,23 +47437,23 @@ function checkVerificationUri(uri, hub) {
|
|
|
47187
47437
|
return uri;
|
|
47188
47438
|
}
|
|
47189
47439
|
function writeMachineFile(home2, body) {
|
|
47190
|
-
|
|
47191
|
-
|
|
47192
|
-
const tmp =
|
|
47193
|
-
const fd =
|
|
47440
|
+
mkdirSync10(home2, { recursive: true, mode: 448 });
|
|
47441
|
+
chmodSync11(home2, 448);
|
|
47442
|
+
const tmp = join18(home2, `.machine.json.${randomBytes4(8).toString("hex")}.tmp`);
|
|
47443
|
+
const fd = openSync6(tmp, "wx", 384);
|
|
47194
47444
|
try {
|
|
47195
|
-
|
|
47445
|
+
writeSync3(fd, body);
|
|
47196
47446
|
} catch (e) {
|
|
47197
|
-
|
|
47198
|
-
|
|
47447
|
+
closeSync6(fd);
|
|
47448
|
+
unlinkSync3(tmp);
|
|
47199
47449
|
throw e;
|
|
47200
47450
|
}
|
|
47201
|
-
|
|
47451
|
+
closeSync6(fd);
|
|
47202
47452
|
try {
|
|
47203
|
-
|
|
47204
|
-
|
|
47453
|
+
chmodSync11(tmp, 384);
|
|
47454
|
+
renameSync10(tmp, join18(home2, "machine.json"));
|
|
47205
47455
|
} catch (e) {
|
|
47206
|
-
|
|
47456
|
+
unlinkSync3(tmp);
|
|
47207
47457
|
throw e;
|
|
47208
47458
|
}
|
|
47209
47459
|
}
|
|
@@ -47328,7 +47578,7 @@ async function login(args) {
|
|
|
47328
47578
|
`${JSON.stringify({ hub, label, machine_token: poll.machine_token }, null, 2)}
|
|
47329
47579
|
`
|
|
47330
47580
|
);
|
|
47331
|
-
rmSync6(
|
|
47581
|
+
rmSync6(join18(args.home, "revoked"), { force: true });
|
|
47332
47582
|
if (!events?.code) print(`Approved this machine as ${label}.`);
|
|
47333
47583
|
return {
|
|
47334
47584
|
machineToken: poll.machine_token,
|
|
@@ -47352,7 +47602,7 @@ init_src();
|
|
|
47352
47602
|
|
|
47353
47603
|
// src/commands/install.ts
|
|
47354
47604
|
init_src3();
|
|
47355
|
-
import { join as
|
|
47605
|
+
import { join as join20 } from "node:path";
|
|
47356
47606
|
init_src2();
|
|
47357
47607
|
|
|
47358
47608
|
// src/live.ts
|
|
@@ -47405,16 +47655,16 @@ function spinner(ctx) {
|
|
|
47405
47655
|
import {
|
|
47406
47656
|
existsSync as existsSync6,
|
|
47407
47657
|
lstatSync as lstatSync10,
|
|
47408
|
-
mkdirSync as
|
|
47658
|
+
mkdirSync as mkdirSync11,
|
|
47409
47659
|
readdirSync as readdirSync4,
|
|
47410
47660
|
readFileSync as readFileSync16,
|
|
47411
47661
|
realpathSync as realpathSync8,
|
|
47412
|
-
renameSync as
|
|
47662
|
+
renameSync as renameSync11,
|
|
47413
47663
|
rmdirSync,
|
|
47414
47664
|
rmSync as rmSync7,
|
|
47415
47665
|
writeFileSync as writeFileSync8
|
|
47416
47666
|
} from "node:fs";
|
|
47417
|
-
import { dirname as
|
|
47667
|
+
import { dirname as dirname10, join as join19 } from "node:path";
|
|
47418
47668
|
var SKILL_MARKER = "<!-- managed by the Open Artifacts bus installer: edits are replaced on reinstall. -->";
|
|
47419
47669
|
var CODEX_BEGIN = "<!-- BEGIN Open Artifacts skill (managed): edits inside are replaced on reinstall. -->";
|
|
47420
47670
|
var CODEX_END = "<!-- END Open Artifacts skill -->";
|
|
@@ -47422,14 +47672,14 @@ var MAX_SKILL_BYTES = 256 * 1024;
|
|
|
47422
47672
|
var env = (deps) => deps.env ?? {};
|
|
47423
47673
|
var skillDir = (deps, h) => {
|
|
47424
47674
|
const e = env(deps);
|
|
47425
|
-
const opencode = e.OPENCODE_CONFIG_DIR ??
|
|
47426
|
-
const agents =
|
|
47675
|
+
const opencode = e.OPENCODE_CONFIG_DIR ?? join19(e.XDG_CONFIG_HOME ?? join19(deps.home, ".config"), "opencode");
|
|
47676
|
+
const agents = join19(deps.home, ".agents", "skills");
|
|
47427
47677
|
return {
|
|
47428
|
-
claude:
|
|
47429
|
-
opencode:
|
|
47678
|
+
claude: join19(e.CLAUDE_CONFIG_DIR ?? join19(deps.home, ".claude"), "skills"),
|
|
47679
|
+
opencode: join19(opencode, "skills"),
|
|
47430
47680
|
pi: agents,
|
|
47431
47681
|
omp: agents,
|
|
47432
|
-
codex:
|
|
47682
|
+
codex: join19(codexHome2(deps.home, e), "AGENTS.md")
|
|
47433
47683
|
}[h];
|
|
47434
47684
|
};
|
|
47435
47685
|
var skillFolder = (text3) => {
|
|
@@ -47525,11 +47775,11 @@ var targetOf = (path) => {
|
|
|
47525
47775
|
};
|
|
47526
47776
|
var seq = 0;
|
|
47527
47777
|
var writeAtomic2 = (path, text3) => {
|
|
47528
|
-
|
|
47778
|
+
mkdirSync11(dirname10(path), { recursive: true });
|
|
47529
47779
|
const tmp = `${path}.oa-${process.pid}-${seq++}.tmp`;
|
|
47530
47780
|
try {
|
|
47531
47781
|
writeFileSync8(tmp, text3);
|
|
47532
|
-
|
|
47782
|
+
renameSync11(tmp, path);
|
|
47533
47783
|
} catch (e) {
|
|
47534
47784
|
try {
|
|
47535
47785
|
rmSync7(tmp, { force: true });
|
|
@@ -47584,7 +47834,7 @@ async function installSkill(deps, origin, harnesses) {
|
|
|
47584
47834
|
failedUrl: url2
|
|
47585
47835
|
};
|
|
47586
47836
|
const base3 = skillDir(deps, h);
|
|
47587
|
-
const path = harnessSkills[h].agentsMd ? base3 :
|
|
47837
|
+
const path = harnessSkills[h].agentsMd ? base3 : join19(base3, folder, "SKILL.md");
|
|
47588
47838
|
if (brokenLink(path)) {
|
|
47589
47839
|
notes.push(`Left ${path} alone: it is a broken symlink.`);
|
|
47590
47840
|
continue;
|
|
@@ -47662,8 +47912,8 @@ var uninstallSkill = (deps, harnesses = ["claude", "opencode", "pi", "omp", "cod
|
|
|
47662
47912
|
continue;
|
|
47663
47913
|
}
|
|
47664
47914
|
for (const entry of entries) {
|
|
47665
|
-
const dir =
|
|
47666
|
-
const file2 =
|
|
47915
|
+
const dir = join19(base3, entry);
|
|
47916
|
+
const file2 = join19(dir, "SKILL.md");
|
|
47667
47917
|
try {
|
|
47668
47918
|
const st = lstatSync10(dir);
|
|
47669
47919
|
if (st.isSymbolicLink()) {
|
|
@@ -47772,7 +48022,7 @@ async function loginStep(ctx, opts) {
|
|
|
47772
48022
|
ctx,
|
|
47773
48023
|
c.approved(result.label),
|
|
47774
48024
|
c.tokenSaved(
|
|
47775
|
-
tilde(ctx,
|
|
48025
|
+
tilde(ctx, join20(ctx.home, "machine.json")),
|
|
47776
48026
|
result.machineToken
|
|
47777
48027
|
),
|
|
47778
48028
|
c.connected(originOf2(result.hub)),
|
|
@@ -47861,7 +48111,7 @@ function shownSocket(ctx) {
|
|
|
47861
48111
|
const real2 = `${canonicalHome(ctx.home)}/`;
|
|
47862
48112
|
return tilde(
|
|
47863
48113
|
ctx,
|
|
47864
|
-
path.startsWith(real2) ?
|
|
48114
|
+
path.startsWith(real2) ? join20(ctx.home, path.slice(real2.length)) : path
|
|
47865
48115
|
);
|
|
47866
48116
|
}
|
|
47867
48117
|
async function waitForDaemon(ctx) {
|
|
@@ -47912,12 +48162,12 @@ function rosterBlock(ctx, ns) {
|
|
|
47912
48162
|
(a, b) => Number(a.state === "queued") - Number(b.state === "queued") || a.name.localeCompare(b.name)
|
|
47913
48163
|
);
|
|
47914
48164
|
const queued2 = rows.filter((r) => r.state === "queued").length;
|
|
47915
|
-
const
|
|
48165
|
+
const shown3 = rows.slice(0, ROSTER_ROWS);
|
|
47916
48166
|
const now = ctx.now();
|
|
47917
48167
|
return {
|
|
47918
48168
|
lines: [
|
|
47919
48169
|
c.rosterHeader(ns.namespace, rows.length - queued2, queued2),
|
|
47920
|
-
...
|
|
48170
|
+
...shown3.flatMap((r) => {
|
|
47921
48171
|
const says = c.rosterSays(r, now);
|
|
47922
48172
|
return [c.rosterRow(r), ...says ? [says] : []];
|
|
47923
48173
|
}),
|
|
@@ -47997,7 +48247,7 @@ async function install2(opts, ctx) {
|
|
|
47997
48247
|
return results.every((r) => r.state === "done") ? 0 : 1;
|
|
47998
48248
|
}
|
|
47999
48249
|
const ok = await runSteps(steps, ctx, {
|
|
48000
|
-
path:
|
|
48250
|
+
path: join20(ctx.home, "install.json"),
|
|
48001
48251
|
now: ctx.now
|
|
48002
48252
|
});
|
|
48003
48253
|
const skillFailed = reportSkillFailure(ctx);
|
|
@@ -48213,7 +48463,7 @@ async function doctor(ctx) {
|
|
|
48213
48463
|
const node2 = ctx.nodeVersion.replace(/^v/, "");
|
|
48214
48464
|
if (Number(node2.split(".")[0]) >= MIN_NODE) pass(c.nodeOk(node2));
|
|
48215
48465
|
else fail(c.nodeOld(node2));
|
|
48216
|
-
const machineFile = tilde(ctx,
|
|
48466
|
+
const machineFile = tilde(ctx, join21(ctx.home, "machine.json"));
|
|
48217
48467
|
const m = readMachine(ctx.home);
|
|
48218
48468
|
if (m.state !== "ok") fail(c.noCredentials(machineFile));
|
|
48219
48469
|
else if (m.revoked) fail(c.revokedCheck());
|
|
@@ -48283,8 +48533,8 @@ async function doctor(ctx) {
|
|
|
48283
48533
|
if (wiring[h] === "configured") pass(c.wired(h, version2));
|
|
48284
48534
|
else fail(c.notWired(h));
|
|
48285
48535
|
if (h === "claude") {
|
|
48286
|
-
const settings =
|
|
48287
|
-
ctx.env.CLAUDE_CONFIG_DIR ??
|
|
48536
|
+
const settings = join21(
|
|
48537
|
+
ctx.env.CLAUDE_CONFIG_DIR ?? join21(ctx.userHome, ".claude"),
|
|
48288
48538
|
"settings.json"
|
|
48289
48539
|
);
|
|
48290
48540
|
const isolates = claudeIsolates(settings);
|
|
@@ -48296,9 +48546,10 @@ async function doctor(ctx) {
|
|
|
48296
48546
|
const allow = globalFile(ctx.home);
|
|
48297
48547
|
const list = readGlobalDirs(allow);
|
|
48298
48548
|
if (list.error) warn(c.globalUnusable(tilde(ctx, allow), list.error));
|
|
48299
|
-
const files = scanConfigFiles(ctx.cwd, {
|
|
48300
|
-
|
|
48301
|
-
|
|
48549
|
+
const files = scanConfigFiles(ctx.cwd, {
|
|
48550
|
+
globalFile: allow,
|
|
48551
|
+
namespacesFile: namespacesFile(ctx.home)
|
|
48552
|
+
}).filter((f) => f.file !== allow);
|
|
48302
48553
|
if (files.length > 0) {
|
|
48303
48554
|
n.warnings += files.length;
|
|
48304
48555
|
say(ctx, configFileLines(ctx, files));
|
|
@@ -48369,10 +48620,10 @@ async function global(opts, ctx) {
|
|
|
48369
48620
|
|
|
48370
48621
|
// src/commands/logs.ts
|
|
48371
48622
|
import { readFileSync as readFileSync18 } from "node:fs";
|
|
48372
|
-
import { join as
|
|
48623
|
+
import { join as join22 } from "node:path";
|
|
48373
48624
|
var TAIL = 50;
|
|
48374
48625
|
async function logs(ctx) {
|
|
48375
|
-
const path =
|
|
48626
|
+
const path = join22(ctx.home, "logs", "daemon.log");
|
|
48376
48627
|
let text3;
|
|
48377
48628
|
try {
|
|
48378
48629
|
text3 = readFileSync18(path, "utf8");
|
|
@@ -48400,13 +48651,125 @@ async function mcp(harness, ctx, load = (h) => MCP_SERVER[h]()) {
|
|
|
48400
48651
|
return void 0;
|
|
48401
48652
|
}
|
|
48402
48653
|
|
|
48654
|
+
// src/commands/namespace.ts
|
|
48655
|
+
import { realpathSync as realpathSync10, statSync as statSync11 } from "node:fs";
|
|
48656
|
+
import { join as join23, resolve as resolve7 } from "node:path";
|
|
48657
|
+
init_src();
|
|
48658
|
+
function shown2(ctx, path) {
|
|
48659
|
+
const t = tilde(ctx, path);
|
|
48660
|
+
if (t !== path) return t;
|
|
48661
|
+
try {
|
|
48662
|
+
return tilde({ userHome: realpathSync10(ctx.userHome) }, path);
|
|
48663
|
+
} catch {
|
|
48664
|
+
return path;
|
|
48665
|
+
}
|
|
48666
|
+
}
|
|
48667
|
+
async function namespace(opts, ctx) {
|
|
48668
|
+
const c = ctx.copy;
|
|
48669
|
+
say(ctx, c.header(ctx.version), "");
|
|
48670
|
+
const file2 = namespacesFile(ctx.home);
|
|
48671
|
+
const { entries, error: error62 } = readApprovals(file2);
|
|
48672
|
+
if (error62) {
|
|
48673
|
+
sayErr(ctx, c.nsUnusable(tilde(ctx, file2), error62));
|
|
48674
|
+
return 1;
|
|
48675
|
+
}
|
|
48676
|
+
if (opts.sub === "list") {
|
|
48677
|
+
say(
|
|
48678
|
+
ctx,
|
|
48679
|
+
entries.length ? c.nsList(entries.map((e) => ({ ...e, dir: shown2(ctx, e.dir) }))) : c.nsNone()
|
|
48680
|
+
);
|
|
48681
|
+
return 0;
|
|
48682
|
+
}
|
|
48683
|
+
const given = resolve7(ctx.cwd, opts.dir);
|
|
48684
|
+
let real2;
|
|
48685
|
+
try {
|
|
48686
|
+
real2 = canonicalPath(given);
|
|
48687
|
+
} catch {
|
|
48688
|
+
}
|
|
48689
|
+
if (opts.sub === "revoke") {
|
|
48690
|
+
const keep = entries.filter(
|
|
48691
|
+
(e) => e.dir !== given && e.dir !== real2 && !(real2 && sameDir(e.dir, real2))
|
|
48692
|
+
);
|
|
48693
|
+
if (keep.length === entries.length) {
|
|
48694
|
+
say(ctx, c.nsNotListed(shown2(ctx, real2 ?? given)));
|
|
48695
|
+
return 0;
|
|
48696
|
+
}
|
|
48697
|
+
writeApprovals(keep, ctx.home);
|
|
48698
|
+
for (const e of entries.filter((x) => !keep.includes(x)))
|
|
48699
|
+
logApproval(
|
|
48700
|
+
{ action: "revoke", ...e, tty: Boolean(ctx.stdinIsTTY) },
|
|
48701
|
+
ctx.home
|
|
48702
|
+
);
|
|
48703
|
+
say(ctx, c.nsRevoked(shown2(ctx, real2 ?? given)));
|
|
48704
|
+
return 0;
|
|
48705
|
+
}
|
|
48706
|
+
if (!real2 || !statSync11(real2).isDirectory()) {
|
|
48707
|
+
sayErr(ctx, c.nsNotDir(shown2(ctx, real2 ?? given)));
|
|
48708
|
+
return 1;
|
|
48709
|
+
}
|
|
48710
|
+
const cfgFile = join23(real2, CONFIG_FILE);
|
|
48711
|
+
const own2 = readOwnFile(cfgFile, process.getuid?.(), {
|
|
48712
|
+
allowGroupWrite: true
|
|
48713
|
+
});
|
|
48714
|
+
if (own2.state === "none") {
|
|
48715
|
+
sayErr(ctx, c.nsNoFile(shown2(ctx, real2)));
|
|
48716
|
+
return 1;
|
|
48717
|
+
}
|
|
48718
|
+
if (own2.state === "unsafe") {
|
|
48719
|
+
sayErr(ctx, c.nsFileUnusable(shown2(ctx, cfgFile), own2.why));
|
|
48720
|
+
return 1;
|
|
48721
|
+
}
|
|
48722
|
+
let ns;
|
|
48723
|
+
try {
|
|
48724
|
+
const parsed = BusConfigSchema.safeParse(JSON.parse(own2.text));
|
|
48725
|
+
if (parsed.success) ns = parsed.data.namespace;
|
|
48726
|
+
} catch {
|
|
48727
|
+
}
|
|
48728
|
+
if (!ns) {
|
|
48729
|
+
say(ctx, c.nsNoNamespace(shown2(ctx, cfgFile)));
|
|
48730
|
+
return 1;
|
|
48731
|
+
}
|
|
48732
|
+
if (isApproved(real2, ns, entries)) {
|
|
48733
|
+
say(ctx, c.nsAlready(shown2(ctx, real2), plain2(ns)));
|
|
48734
|
+
return 0;
|
|
48735
|
+
}
|
|
48736
|
+
if (!opts.yes) {
|
|
48737
|
+
if (!ctx.stdinIsTTY || !ctx.readLine) {
|
|
48738
|
+
sayErr(ctx, c.nsNeedTty(approveCommand(real2)));
|
|
48739
|
+
return 1;
|
|
48740
|
+
}
|
|
48741
|
+
say(ctx, c.nsAsk(shown2(ctx, real2), plain2(ns)));
|
|
48742
|
+
const answer = (await ctx.readLine(c.nsPrompt())).trim().toLowerCase();
|
|
48743
|
+
if (answer !== "y" && answer !== "yes") {
|
|
48744
|
+
say(ctx, c.nsDeclined());
|
|
48745
|
+
return 1;
|
|
48746
|
+
}
|
|
48747
|
+
}
|
|
48748
|
+
const next = [
|
|
48749
|
+
...entries.filter((e) => !sameDir(e.dir, real2)),
|
|
48750
|
+
{ dir: real2, namespace: ns }
|
|
48751
|
+
];
|
|
48752
|
+
writeApprovals(next, ctx.home);
|
|
48753
|
+
logApproval(
|
|
48754
|
+
{
|
|
48755
|
+
action: "approve",
|
|
48756
|
+
dir: real2,
|
|
48757
|
+
namespace: ns,
|
|
48758
|
+
tty: Boolean(ctx.stdinIsTTY)
|
|
48759
|
+
},
|
|
48760
|
+
ctx.home
|
|
48761
|
+
);
|
|
48762
|
+
say(ctx, c.nsApproved(shown2(ctx, real2), plain2(ns)));
|
|
48763
|
+
return 0;
|
|
48764
|
+
}
|
|
48765
|
+
|
|
48403
48766
|
// src/commands/uninstall.ts
|
|
48404
|
-
import { join as
|
|
48767
|
+
import { join as join25 } from "node:path";
|
|
48405
48768
|
|
|
48406
48769
|
// src/steps/purge.ts
|
|
48407
48770
|
init_src3();
|
|
48408
48771
|
import { lstatSync as lstatSync11, readdirSync as readdirSync5, rmdirSync as rmdirSync2, rmSync as rmSync8 } from "node:fs";
|
|
48409
|
-
import { join as
|
|
48772
|
+
import { join as join24 } from "node:path";
|
|
48410
48773
|
var FILES = [
|
|
48411
48774
|
"machine.json",
|
|
48412
48775
|
"install.json",
|
|
@@ -48455,14 +48818,14 @@ var rmdirIfEmpty = (path) => {
|
|
|
48455
48818
|
};
|
|
48456
48819
|
function purgeShort(dir, removed) {
|
|
48457
48820
|
if (kind(dir) !== "dir" || unsafeSocketDir(dir)) return;
|
|
48458
|
-
const ret =
|
|
48821
|
+
const ret = join24(dir, "claude-return");
|
|
48459
48822
|
for (const [d, ours2] of [
|
|
48460
48823
|
[ret, (_n, p) => kind(p) === "socket"],
|
|
48461
48824
|
[dir, (n) => /^daemon\.sock(\.keep-\d+)?$/.test(n)]
|
|
48462
48825
|
]) {
|
|
48463
48826
|
if (kind(d) !== "dir") continue;
|
|
48464
48827
|
for (const name of readdirSync5(d)) {
|
|
48465
|
-
const path =
|
|
48828
|
+
const path = join24(d, name);
|
|
48466
48829
|
const k = kind(path);
|
|
48467
48830
|
if (k === void 0 || k === "dir" || !ours2(name, path)) continue;
|
|
48468
48831
|
remove2(path, k);
|
|
@@ -48487,21 +48850,21 @@ function purge(home2, opts) {
|
|
|
48487
48850
|
...FILES,
|
|
48488
48851
|
...entries.filter((n) => TEMP.some((re) => re.test(n)))
|
|
48489
48852
|
]) {
|
|
48490
|
-
const path =
|
|
48853
|
+
const path = join24(home2, name);
|
|
48491
48854
|
const k = kind(path);
|
|
48492
48855
|
if (k === void 0 || k === "dir") continue;
|
|
48493
48856
|
remove2(path, k);
|
|
48494
48857
|
removed.push(name);
|
|
48495
48858
|
}
|
|
48496
48859
|
for (const folder of FOLDERS) {
|
|
48497
|
-
const dir =
|
|
48860
|
+
const dir = join24(home2, folder.path);
|
|
48498
48861
|
if (kind(dir) !== "dir") continue;
|
|
48499
48862
|
for (const name of readdirSync5(dir)) {
|
|
48500
|
-
const path =
|
|
48863
|
+
const path = join24(dir, name);
|
|
48501
48864
|
const k = kind(path);
|
|
48502
48865
|
if (k === void 0 || !folder.ours(name, path)) continue;
|
|
48503
48866
|
remove2(path, k);
|
|
48504
|
-
removed.push(
|
|
48867
|
+
removed.push(join24(folder.path, name));
|
|
48505
48868
|
}
|
|
48506
48869
|
if (rmdirIfEmpty(dir)) removed.push(folder.path);
|
|
48507
48870
|
}
|
|
@@ -48553,7 +48916,7 @@ async function uninstall2(opts, ctx) {
|
|
|
48553
48916
|
r.opencodeRestarted ? c.restartedUnload() : c.opencodeNotRunningUnload()
|
|
48554
48917
|
);
|
|
48555
48918
|
if (!opts.purge) {
|
|
48556
|
-
say(ctx, "", c.kept(tilde(ctx,
|
|
48919
|
+
say(ctx, "", c.kept(tilde(ctx, join25(ctx.home, "machine.json"))));
|
|
48557
48920
|
return 0;
|
|
48558
48921
|
}
|
|
48559
48922
|
const home2 = tilde(ctx, ctx.home);
|
|
@@ -48564,7 +48927,7 @@ async function uninstall2(opts, ctx) {
|
|
|
48564
48927
|
} catch {
|
|
48565
48928
|
}
|
|
48566
48929
|
const out = purge(ctx.home, {
|
|
48567
|
-
isDefault: ctx.home ===
|
|
48930
|
+
isDefault: ctx.home === join25(ctx.userHome, ".oa-bus")
|
|
48568
48931
|
});
|
|
48569
48932
|
if ("refused" in out) {
|
|
48570
48933
|
sayErr(ctx, c.purgeRefused(home2));
|
|
@@ -48589,16 +48952,19 @@ var COMMANDS = /* @__PURE__ */ new Set([
|
|
|
48589
48952
|
"doctor",
|
|
48590
48953
|
"uninstall",
|
|
48591
48954
|
"global",
|
|
48955
|
+
"namespace",
|
|
48592
48956
|
"version"
|
|
48593
48957
|
]);
|
|
48594
48958
|
var HARNESSES2 = ["claude", "opencode", "codex", "pi"];
|
|
48595
48959
|
var GLOBAL_USAGE = `usage: ${BUS_CMD} global <add|rm> <dir>, or global list`;
|
|
48960
|
+
var NAMESPACE_USAGE = `usage: ${BUS_CMD} namespace approve [dir], namespace revoke <dir>, or namespace list`;
|
|
48596
48961
|
var COMMON = /* @__PURE__ */ new Set(["no-color", "version", "home"]);
|
|
48597
48962
|
var FLAGS = {
|
|
48598
48963
|
install: ["instance", "no-open", "yes", "check", "no-service"],
|
|
48599
48964
|
login: ["instance", "no-open"],
|
|
48600
48965
|
daemon: ["instance"],
|
|
48601
|
-
uninstall: ["purge"]
|
|
48966
|
+
uninstall: ["purge"],
|
|
48967
|
+
namespace: ["yes"]
|
|
48602
48968
|
};
|
|
48603
48969
|
function parse7(argv) {
|
|
48604
48970
|
const { values, positionals, tokens: tokens2 } = parseArgs({
|
|
@@ -48624,7 +48990,16 @@ function parse7(argv) {
|
|
|
48624
48990
|
if (cmd === "mcp" && rest.length === 0)
|
|
48625
48991
|
throw new Error(`usage: ${BUS_CMD} mcp <claude|opencode|codex|pi>`);
|
|
48626
48992
|
if (cmd === "global" && rest.length < takes) throw new Error(GLOBAL_USAGE);
|
|
48627
|
-
|
|
48993
|
+
if (cmd === "namespace") {
|
|
48994
|
+
const sub = rest[0];
|
|
48995
|
+
const max = sub === "list" ? 1 : sub === "approve" ? 2 : 2;
|
|
48996
|
+
const min = sub === "revoke" ? 2 : 1;
|
|
48997
|
+
if (!["approve", "revoke", "list"].includes(sub ?? "") || rest.length < min)
|
|
48998
|
+
throw new Error(NAMESPACE_USAGE);
|
|
48999
|
+
if (rest[max] !== void 0)
|
|
49000
|
+
throw new Error(`unexpected argument: ${rest[max]}`);
|
|
49001
|
+
}
|
|
49002
|
+
const extra = cmd === "namespace" ? void 0 : rest[takes];
|
|
48628
49003
|
if (extra !== void 0) throw new Error(`unexpected argument: ${extra}`);
|
|
48629
49004
|
for (const name of ["home", "instance"])
|
|
48630
49005
|
if (values[name] === "") throw new Error(`--${name} needs a value`);
|
|
@@ -48660,6 +49035,14 @@ function route(cmd, values, positionals) {
|
|
|
48660
49035
|
if ((sub === "add" || sub === "rm") && dir) return { cmd, sub, dir };
|
|
48661
49036
|
throw new Error(GLOBAL_USAGE);
|
|
48662
49037
|
}
|
|
49038
|
+
case "namespace": {
|
|
49039
|
+
const [sub, dir] = positionals;
|
|
49040
|
+
if (sub === "list") return { cmd, sub };
|
|
49041
|
+
if (sub === "revoke" && dir) return { cmd, sub, dir };
|
|
49042
|
+
if (sub === "approve")
|
|
49043
|
+
return { cmd, sub, dir: dir ?? ".", yes: values.yes };
|
|
49044
|
+
throw new Error(NAMESPACE_USAGE);
|
|
49045
|
+
}
|
|
48663
49046
|
case "install":
|
|
48664
49047
|
return {
|
|
48665
49048
|
cmd,
|
|
@@ -48690,7 +49073,7 @@ async function main(argv, makeCtx = realCtx) {
|
|
|
48690
49073
|
return 2;
|
|
48691
49074
|
}
|
|
48692
49075
|
const ctx = makeCtx(cmd.noColor);
|
|
48693
|
-
if (cmd.home) ctx.home =
|
|
49076
|
+
if (cmd.home) ctx.home = resolve8(cmd.home);
|
|
48694
49077
|
try {
|
|
48695
49078
|
return await dispatch(cmd, ctx);
|
|
48696
49079
|
} catch (e) {
|
|
@@ -48742,6 +49125,8 @@ async function dispatch(cmd, ctx) {
|
|
|
48742
49125
|
return uninstall2({ purge: cmd.purge }, ctx);
|
|
48743
49126
|
case "global":
|
|
48744
49127
|
return global(cmd, ctx);
|
|
49128
|
+
case "namespace":
|
|
49129
|
+
return namespace(cmd, ctx);
|
|
48745
49130
|
case "version":
|
|
48746
49131
|
say(ctx, ctx.copy.header(ctx.version));
|
|
48747
49132
|
return 0;
|