@open-artifacts/bus 0.129.0 → 0.131.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 +62 -5
- package/dist/index.js +291 -98
- package/package.json +1 -1
package/assets/oa-bus.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { StringDecoder } from "node:string_decoder";
|
|
|
11
11
|
type Json = Record<string, unknown>;
|
|
12
12
|
|
|
13
13
|
/** The IPC marker (CONTRACT.md): the package version, stamped by the CLI's bundler. */
|
|
14
|
-
const CLIENT_VERSION = "0.
|
|
14
|
+
const CLIENT_VERSION = "0.131.0";
|
|
15
15
|
|
|
16
16
|
type Frame = Json & { type: string; id: string };
|
|
17
17
|
type Ctx = {
|
|
@@ -178,6 +178,7 @@ function receiptText(
|
|
|
178
178
|
namespaces?: number,
|
|
179
179
|
excerpt?: string,
|
|
180
180
|
movedTo?: string,
|
|
181
|
+
linkedNs?: string,
|
|
181
182
|
): string {
|
|
182
183
|
const quote = excerpt ? `"${excerpt}"` : undefined;
|
|
183
184
|
const to = sentTo;
|
|
@@ -223,12 +224,42 @@ function receiptText(
|
|
|
223
224
|
: `× ${label}: your message to ${v} was not delivered.`,
|
|
224
225
|
...(said(v) ? [` ${said(v)}`] : []),
|
|
225
226
|
...(hint ? [` ${hint}`] : []),
|
|
227
|
+
...(linkedNs !== undefined &&
|
|
228
|
+
(r.reason === "closed" || r.reason === "revoked")
|
|
229
|
+
? [
|
|
230
|
+
" A linked project has a live agent with that name:",
|
|
231
|
+
` pass to_namespace ${linkedNs} to reach the live one.`,
|
|
232
|
+
]
|
|
233
|
+
: []),
|
|
226
234
|
].join("\n");
|
|
227
235
|
return fitLine(lines, to);
|
|
228
236
|
}
|
|
229
237
|
}
|
|
230
238
|
}
|
|
231
239
|
|
|
240
|
+
/** @oa/bus-ipc linkedLiveNamespace (#1567): the one namespace with a live agent called `name`. */
|
|
241
|
+
function linkedLiveNamespace(
|
|
242
|
+
name: string,
|
|
243
|
+
roster: readonly {
|
|
244
|
+
name: string;
|
|
245
|
+
namespace: string;
|
|
246
|
+
live?: boolean;
|
|
247
|
+
state?: string;
|
|
248
|
+
}[],
|
|
249
|
+
): string | undefined {
|
|
250
|
+
const l = name.toLowerCase();
|
|
251
|
+
const seen = new Set(
|
|
252
|
+
roster
|
|
253
|
+
.filter(
|
|
254
|
+
(a) =>
|
|
255
|
+
a.name.toLowerCase() === l &&
|
|
256
|
+
(a.state ?? (a.live ? "live" : "queued")) === "live",
|
|
257
|
+
)
|
|
258
|
+
.map((a) => a.namespace),
|
|
259
|
+
);
|
|
260
|
+
return seen.size === 1 ? [...seen][0] : undefined;
|
|
261
|
+
}
|
|
262
|
+
|
|
232
263
|
/**
|
|
233
264
|
* #1448: for a send refused `revoked`, the live name `to` most likely moved
|
|
234
265
|
* to: `<to>-N` among `names` (the sender's roster), the lowest N, ignoring
|
|
@@ -488,6 +519,7 @@ export const copy = {
|
|
|
488
519
|
selfText,
|
|
489
520
|
receiptText,
|
|
490
521
|
movedName,
|
|
522
|
+
linkedLiveNamespace,
|
|
491
523
|
excerptOf,
|
|
492
524
|
stripTerminalControls,
|
|
493
525
|
neutralizeBody,
|
|
@@ -508,7 +540,7 @@ const TOOLS = [
|
|
|
508
540
|
name: "oabus_list_agents",
|
|
509
541
|
label: "Open Artifacts bus: list agents",
|
|
510
542
|
description:
|
|
511
|
-
"List the agents you can message, in your Open Artifacts bus namespace.",
|
|
543
|
+
"List the agents you can message, in your Open Artifacts bus namespace and linked ones.",
|
|
512
544
|
parameters: none,
|
|
513
545
|
},
|
|
514
546
|
{
|
|
@@ -523,7 +555,7 @@ const TOOLS = [
|
|
|
523
555
|
to_namespace: {
|
|
524
556
|
type: "string",
|
|
525
557
|
description:
|
|
526
|
-
"The recipient's namespace, when a global agent's
|
|
558
|
+
"The recipient's namespace, when the target name exists in several: a global agent's, or a linked project's.",
|
|
527
559
|
},
|
|
528
560
|
},
|
|
529
561
|
required: ["to", "text"],
|
|
@@ -1061,7 +1093,7 @@ export default function oaBus(pi: Pi): void {
|
|
|
1061
1093
|
),
|
|
1062
1094
|
)
|
|
1063
1095
|
.join("\n")
|
|
1064
|
-
: "No agents in your namespace.";
|
|
1096
|
+
: "No agents in your namespace and linked ones.";
|
|
1065
1097
|
}
|
|
1066
1098
|
if (name === "oabus_send_message") {
|
|
1067
1099
|
const to = String(args.to ?? "");
|
|
@@ -1092,7 +1124,12 @@ export default function oaBus(pi: Pi): void {
|
|
|
1092
1124
|
receipt.reason === "revoked"
|
|
1093
1125
|
? await movedTo(to, namespace, link)
|
|
1094
1126
|
: undefined;
|
|
1095
|
-
const
|
|
1127
|
+
const linked =
|
|
1128
|
+
(receipt.reason === "closed" || receipt.reason === "revoked") &&
|
|
1129
|
+
!namespace
|
|
1130
|
+
? await linkedLive(to, link)
|
|
1131
|
+
: undefined;
|
|
1132
|
+
const out = receiptText(receipt, to, n, excerptOf(body), moved, linked);
|
|
1096
1133
|
if (receipt.state === "refused" || receipt.state === "expired")
|
|
1097
1134
|
throw new Error(out);
|
|
1098
1135
|
return out;
|
|
@@ -1210,6 +1247,26 @@ async function movedTo(
|
|
|
1210
1247
|
}
|
|
1211
1248
|
}
|
|
1212
1249
|
|
|
1250
|
+
/** #1567: the linked namespace with a live agent called `name`; undefined when none or the roster is unavailable. */
|
|
1251
|
+
async function linkedLive(
|
|
1252
|
+
name: string,
|
|
1253
|
+
link: Link,
|
|
1254
|
+
): Promise<string | undefined> {
|
|
1255
|
+
try {
|
|
1256
|
+
const r = await link.request({ type: "list" });
|
|
1257
|
+
if (r.type !== "roster") return undefined;
|
|
1258
|
+
const agents = ((r.agents ?? []) as Json[]).map((a) => ({
|
|
1259
|
+
name: String(a.name),
|
|
1260
|
+
namespace: String(a.namespace),
|
|
1261
|
+
...(typeof a.live === "boolean" ? { live: a.live } : {}),
|
|
1262
|
+
...(typeof a.state === "string" ? { state: a.state } : {}),
|
|
1263
|
+
}));
|
|
1264
|
+
return linkedLiveNamespace(name, agents);
|
|
1265
|
+
} catch {
|
|
1266
|
+
return undefined;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1213
1270
|
/** How many namespaces hold `name`; undefined when the roster is unavailable. */
|
|
1214
1271
|
async function namespacesOf(
|
|
1215
1272
|
name: string,
|
package/dist/index.js
CHANGED
|
@@ -2540,7 +2540,7 @@ function handleIntersectionResults(result, left, right) {
|
|
|
2540
2540
|
const unrecKeys = /* @__PURE__ */ new Map();
|
|
2541
2541
|
let unrecIssue;
|
|
2542
2542
|
const keyIssues = /* @__PURE__ */ new Map();
|
|
2543
|
-
const collect = (iss,
|
|
2543
|
+
const collect = (iss, side2) => {
|
|
2544
2544
|
let keys;
|
|
2545
2545
|
if (iss.code === "unrecognized_keys" && !iss.path?.length) {
|
|
2546
2546
|
unrecIssue ?? (unrecIssue = iss);
|
|
@@ -2556,7 +2556,7 @@ function handleIntersectionResults(result, left, right) {
|
|
|
2556
2556
|
for (const k of keys) {
|
|
2557
2557
|
if (!unrecKeys.has(k))
|
|
2558
2558
|
unrecKeys.set(k, {});
|
|
2559
|
-
unrecKeys.get(k)[
|
|
2559
|
+
unrecKeys.get(k)[side2] = true;
|
|
2560
2560
|
}
|
|
2561
2561
|
return true;
|
|
2562
2562
|
};
|
|
@@ -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, resolve10) {
|
|
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, resolve9) {
|
|
|
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, resolve10);
|
|
4600
4600
|
if (answer > result)
|
|
4601
4601
|
result = answer;
|
|
4602
4602
|
}
|
|
@@ -4607,7 +4607,7 @@ function isRecursive(inst, stack, resolve9) {
|
|
|
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, resolve10) : NONE;
|
|
4611
4611
|
if (child > answer)
|
|
4612
4612
|
answer = child;
|
|
4613
4613
|
}
|
|
@@ -4671,7 +4671,7 @@ function isRecursive(inst, stack, resolve9) {
|
|
|
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 ?? (resolve10 ? inst._zod.innerType : void 0);
|
|
4675
4675
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
4676
4676
|
break;
|
|
4677
4677
|
}
|
|
@@ -20219,11 +20219,11 @@ var init_deep_partial = __esm({
|
|
|
20219
20219
|
});
|
|
20220
20220
|
|
|
20221
20221
|
// ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/classic/in-out.js
|
|
20222
|
-
function withChecks(
|
|
20222
|
+
function withChecks(side2, checks) {
|
|
20223
20223
|
if (!checks?.length)
|
|
20224
|
-
return
|
|
20225
|
-
const def =
|
|
20226
|
-
return clone(
|
|
20224
|
+
return side2;
|
|
20225
|
+
const def = side2._zod.def;
|
|
20226
|
+
return clone(side2, mergeDefs(def, { checks: [...def.checks ?? [], ...checks] }), { parent: true });
|
|
20227
20227
|
}
|
|
20228
20228
|
function outSide(def) {
|
|
20229
20229
|
return withChecks(def.out, def.checks);
|
|
@@ -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((resolve10) => setTimeout(resolve10, 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((resolve10, 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
|
+
resolve10(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((resolve10, 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(resolve10, 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 = resolve10.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 resolve10(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 resolve10(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: resolve10,
|
|
27657
27657
|
resolveComponent,
|
|
27658
27658
|
equal,
|
|
27659
27659
|
serialize,
|
|
@@ -31714,7 +31714,15 @@ var init_device = __esm({
|
|
|
31714
31714
|
*/
|
|
31715
31715
|
approve: "/bus/approve",
|
|
31716
31716
|
/** `GET` WebSocket upgrade, `Authorization: Bearer oa_machine_...`. */
|
|
31717
|
-
connect: "/bus/connect"
|
|
31717
|
+
connect: "/bus/connect",
|
|
31718
|
+
/**
|
|
31719
|
+
* `POST`, `Authorization: Bearer oa_machine_...` (#1567): `oa-bus link` and
|
|
31720
|
+
* `unlink` record a proposal `{ action: "link" | "unlink", a, b }` and get
|
|
31721
|
+
* back `{ confirmUrl, expiresAt }`. It links nothing: the member opens
|
|
31722
|
+
* `confirmUrl` in a browser to confirm. 409 `details.reason`:
|
|
31723
|
+
* `rate_limited`, `proposal_limit`, `no_bus`.
|
|
31724
|
+
*/
|
|
31725
|
+
linkProposals: "/api/v1/bus/links/proposals"
|
|
31718
31726
|
};
|
|
31719
31727
|
DeviceCodeRequestSchema = external_exports.strictObject({
|
|
31720
31728
|
machine_label: MachineLabelSchema.optional()
|
|
@@ -32418,7 +32426,7 @@ var init_frames = __esm({
|
|
|
32418
32426
|
late = { late: external_exports.array(external_exports.string().min(1)).optional() };
|
|
32419
32427
|
isWellFormed2 = (s) => s.isWellFormed();
|
|
32420
32428
|
WELL_FORMED = { message: "text is not well-formed unicode" };
|
|
32421
|
-
CLIENT_VERSION = true ? "0.
|
|
32429
|
+
CLIENT_VERSION = true ? "0.131.0" : "0.0.0";
|
|
32422
32430
|
clientVersion = {
|
|
32423
32431
|
client_version: external_exports.string().min(1).max(64).optional()
|
|
32424
32432
|
};
|
|
@@ -32752,8 +32760,8 @@ var init_lines = __esm({
|
|
|
32752
32760
|
import { connect } from "node:net";
|
|
32753
32761
|
async function connectDaemon(opts) {
|
|
32754
32762
|
const sock = connect(opts.path);
|
|
32755
|
-
await new Promise((
|
|
32756
|
-
sock.once("connect",
|
|
32763
|
+
await new Promise((resolve10, reject) => {
|
|
32764
|
+
sock.once("connect", resolve10);
|
|
32757
32765
|
sock.once("error", reject);
|
|
32758
32766
|
});
|
|
32759
32767
|
const decoder = new LineDecoder();
|
|
@@ -32813,8 +32821,8 @@ async function connectDaemon(opts) {
|
|
|
32813
32821
|
sock.on("error", (e) => failAll(e));
|
|
32814
32822
|
sock.on("close", () => failAll(new Error("daemon connection closed")));
|
|
32815
32823
|
let timer;
|
|
32816
|
-
const welcomeRaw = await new Promise((
|
|
32817
|
-
waiters.push({ resolve:
|
|
32824
|
+
const welcomeRaw = await new Promise((resolve10, reject) => {
|
|
32825
|
+
waiters.push({ resolve: resolve10, reject });
|
|
32818
32826
|
timer = setTimeout(() => {
|
|
32819
32827
|
reject(new Error("daemon did not answer hello"));
|
|
32820
32828
|
sock.destroy();
|
|
@@ -32836,7 +32844,7 @@ async function connectDaemon(opts) {
|
|
|
32836
32844
|
if (state === "closed")
|
|
32837
32845
|
return Promise.reject(new Error("daemon connection closed"));
|
|
32838
32846
|
const id = partial2.id ?? String(++seq2);
|
|
32839
|
-
return new Promise((
|
|
32847
|
+
return new Promise((resolve10, reject) => {
|
|
32840
32848
|
const ms = opts.requestTimeoutMs ?? 2e4;
|
|
32841
32849
|
const timer2 = setTimeout(() => {
|
|
32842
32850
|
if (pending.delete(id))
|
|
@@ -32851,7 +32859,7 @@ async function connectDaemon(opts) {
|
|
|
32851
32859
|
clearTimeout(timer2);
|
|
32852
32860
|
f(...a);
|
|
32853
32861
|
};
|
|
32854
|
-
pending.set(id, { resolve: done(
|
|
32862
|
+
pending.set(id, { resolve: done(resolve10), reject: done(reject) });
|
|
32855
32863
|
sock.write(`${JSON.stringify({ v: 1, ...partial2, id })}
|
|
32856
32864
|
`);
|
|
32857
32865
|
});
|
|
@@ -32875,7 +32883,7 @@ async function connectDaemon(opts) {
|
|
|
32875
32883
|
};
|
|
32876
32884
|
}
|
|
32877
32885
|
function daemonStatus(opts) {
|
|
32878
|
-
return new Promise((
|
|
32886
|
+
return new Promise((resolve10, reject) => {
|
|
32879
32887
|
const sock = connect(opts.path);
|
|
32880
32888
|
const decoder = new LineDecoder();
|
|
32881
32889
|
const done = (f) => {
|
|
@@ -32912,7 +32920,7 @@ function daemonStatus(opts) {
|
|
|
32912
32920
|
try {
|
|
32913
32921
|
for (const raw of decoder.push(chunk)) {
|
|
32914
32922
|
const f = DaemonFrame.parse(raw);
|
|
32915
|
-
if (f.type === "status") return done(() =>
|
|
32923
|
+
if (f.type === "status") return done(() => resolve10(f));
|
|
32916
32924
|
if (f.type === "error")
|
|
32917
32925
|
return done(
|
|
32918
32926
|
() => reject(
|
|
@@ -32970,7 +32978,7 @@ function fitLine(text3, value) {
|
|
|
32970
32978
|
`${value.slice(0, head)}\u2026${value.slice(value.length - (keep - head))}`
|
|
32971
32979
|
);
|
|
32972
32980
|
}
|
|
32973
|
-
function receiptText(r, sentTo, namespaces, excerpt, movedTo2) {
|
|
32981
|
+
function receiptText(r, sentTo, namespaces, excerpt, movedTo2, linkedNs) {
|
|
32974
32982
|
const quote = excerpt ? `"${excerpt}"` : void 0;
|
|
32975
32983
|
const to = sentTo;
|
|
32976
32984
|
switch (r.state) {
|
|
@@ -33000,7 +33008,11 @@ function receiptText(r, sentTo, namespaces, excerpt, movedTo2) {
|
|
|
33000
33008
|
"was not delivered."
|
|
33001
33009
|
) : `\xD7 ${label}: your message to ${v} was not delivered.`,
|
|
33002
33010
|
...said(v) ? [` ${said(v)}`] : [],
|
|
33003
|
-
...hint ? [` ${hint}`] : []
|
|
33011
|
+
...hint ? [` ${hint}`] : [],
|
|
33012
|
+
...linkedNs !== void 0 && (r.reason === "closed" || r.reason === "revoked") ? [
|
|
33013
|
+
" A linked project has a live agent with that name:",
|
|
33014
|
+
` pass to_namespace ${linkedNs} to reach the live one.`
|
|
33015
|
+
] : []
|
|
33004
33016
|
].join("\n");
|
|
33005
33017
|
return fitLine(lines, to);
|
|
33006
33018
|
}
|
|
@@ -33022,6 +33034,15 @@ function movedName(to, names2) {
|
|
|
33022
33034
|
}
|
|
33023
33035
|
return best;
|
|
33024
33036
|
}
|
|
33037
|
+
function linkedLiveNamespace(name, roster2) {
|
|
33038
|
+
const l = name.toLowerCase();
|
|
33039
|
+
const seen2 = new Set(
|
|
33040
|
+
roster2.filter(
|
|
33041
|
+
(a) => a.name.toLowerCase() === l && (a.state ?? (a.live ? "live" : "queued")) === "live"
|
|
33042
|
+
).map((a) => a.namespace)
|
|
33043
|
+
);
|
|
33044
|
+
return seen2.size === 1 ? [...seen2][0] : void 0;
|
|
33045
|
+
}
|
|
33025
33046
|
function unconfirmedText(to, excerpt) {
|
|
33026
33047
|
const head = (v) => `! Unconfirmed: your message to ${v}`;
|
|
33027
33048
|
const tail = "may not have been delivered.";
|
|
@@ -33228,13 +33249,13 @@ async function clearStale(path) {
|
|
|
33228
33249
|
code: "ENOTSOCK"
|
|
33229
33250
|
});
|
|
33230
33251
|
}
|
|
33231
|
-
const live = await new Promise((
|
|
33252
|
+
const live = await new Promise((resolve10) => {
|
|
33232
33253
|
const probe = connect2(path);
|
|
33233
33254
|
probe.once("connect", () => {
|
|
33234
33255
|
probe.destroy();
|
|
33235
|
-
|
|
33256
|
+
resolve10(true);
|
|
33236
33257
|
});
|
|
33237
|
-
probe.once("error", () =>
|
|
33258
|
+
probe.once("error", () => resolve10(false));
|
|
33238
33259
|
});
|
|
33239
33260
|
if (live) {
|
|
33240
33261
|
throw Object.assign(new Error(`daemon already listening on ${path}`), {
|
|
@@ -33254,16 +33275,16 @@ async function serveDaemon(opts) {
|
|
|
33254
33275
|
sock.once("close", () => sockets.delete(sock));
|
|
33255
33276
|
handle(sock, opts);
|
|
33256
33277
|
});
|
|
33257
|
-
await new Promise((
|
|
33278
|
+
await new Promise((resolve10, reject) => {
|
|
33258
33279
|
server4.once("error", reject);
|
|
33259
|
-
server4.listen(opts.path, () =>
|
|
33280
|
+
server4.listen(opts.path, () => resolve10());
|
|
33260
33281
|
});
|
|
33261
33282
|
chmodSync(opts.path, 384);
|
|
33262
33283
|
const st = statSync(opts.path);
|
|
33263
33284
|
const mode = st.mode & 511;
|
|
33264
33285
|
return {
|
|
33265
33286
|
mode,
|
|
33266
|
-
close: () => new Promise((
|
|
33287
|
+
close: () => new Promise((resolve10) => {
|
|
33267
33288
|
for (const s of sockets) s.destroy();
|
|
33268
33289
|
let parked;
|
|
33269
33290
|
try {
|
|
@@ -33281,7 +33302,7 @@ async function serveDaemon(opts) {
|
|
|
33281
33302
|
} catch {
|
|
33282
33303
|
}
|
|
33283
33304
|
}
|
|
33284
|
-
|
|
33305
|
+
resolve10();
|
|
33285
33306
|
});
|
|
33286
33307
|
})
|
|
33287
33308
|
};
|
|
@@ -33551,7 +33572,7 @@ async function run(name, args, request) {
|
|
|
33551
33572
|
},
|
|
33552
33573
|
now
|
|
33553
33574
|
)
|
|
33554
|
-
).join("\n") : "No agents in your namespace."
|
|
33575
|
+
).join("\n") : "No agents in your namespace and linked ones."
|
|
33555
33576
|
);
|
|
33556
33577
|
}
|
|
33557
33578
|
if (name === "send_message") {
|
|
@@ -33569,8 +33590,9 @@ async function run(name, args, request) {
|
|
|
33569
33590
|
if (r.text) return text(r.text, false);
|
|
33570
33591
|
const n = r.reason === "ambiguous" ? await namespacesOf(to, request) : void 0;
|
|
33571
33592
|
const moved = r.reason === "revoked" ? await movedTo(to, namespace2, request) : void 0;
|
|
33593
|
+
const linked = (r.reason === "closed" || r.reason === "revoked") && !namespace2 ? await linkedLive(to, request) : void 0;
|
|
33572
33594
|
return text(
|
|
33573
|
-
receiptText(r, to, n, excerptOf(body), moved),
|
|
33595
|
+
receiptText(r, to, n, excerptOf(body), moved, linked),
|
|
33574
33596
|
r.state === "refused" || r.state === "expired"
|
|
33575
33597
|
);
|
|
33576
33598
|
}
|
|
@@ -33650,6 +33672,15 @@ async function movedTo(name, namespace2, request) {
|
|
|
33650
33672
|
return void 0;
|
|
33651
33673
|
}
|
|
33652
33674
|
}
|
|
33675
|
+
async function linkedLive(name, request) {
|
|
33676
|
+
try {
|
|
33677
|
+
const r = await request({ type: "list" });
|
|
33678
|
+
if (r.type !== "roster") return void 0;
|
|
33679
|
+
return linkedLiveNamespace(name, r.agents);
|
|
33680
|
+
} catch {
|
|
33681
|
+
return void 0;
|
|
33682
|
+
}
|
|
33683
|
+
}
|
|
33653
33684
|
function failed(r) {
|
|
33654
33685
|
return text(`oa-bus: ${r.type === "error" ? r.message : r.type}`, true);
|
|
33655
33686
|
}
|
|
@@ -33667,7 +33698,7 @@ var init_tools = __esm({
|
|
|
33667
33698
|
TOOLS = [
|
|
33668
33699
|
{
|
|
33669
33700
|
name: "list_agents",
|
|
33670
|
-
description: "List the agents you can message, in your Open Artifacts bus namespace.",
|
|
33701
|
+
description: "List the agents you can message, in your Open Artifacts bus namespace and linked ones.",
|
|
33671
33702
|
inputSchema: none
|
|
33672
33703
|
},
|
|
33673
33704
|
{
|
|
@@ -33680,7 +33711,7 @@ var init_tools = __esm({
|
|
|
33680
33711
|
text: { type: "string" },
|
|
33681
33712
|
to_namespace: {
|
|
33682
33713
|
type: "string",
|
|
33683
|
-
description: "The recipient's namespace, when a global agent's
|
|
33714
|
+
description: "The recipient's namespace, when the target name exists in several: a global agent's, or a linked project's."
|
|
33684
33715
|
}
|
|
33685
33716
|
},
|
|
33686
33717
|
required: ["to", "text"],
|
|
@@ -33878,7 +33909,7 @@ ${neutralize(a.text)}
|
|
|
33878
33909
|
};
|
|
33879
33910
|
}
|
|
33880
33911
|
function inject(a) {
|
|
33881
|
-
return new Promise((
|
|
33912
|
+
return new Promise((resolve10, reject) => {
|
|
33882
33913
|
const sock = connect3(a.socketPath);
|
|
33883
33914
|
let connected = false;
|
|
33884
33915
|
const fail = (e) => {
|
|
@@ -33902,7 +33933,7 @@ function inject(a) {
|
|
|
33902
33933
|
sock.once("finish", () => {
|
|
33903
33934
|
clearTimeout(timer);
|
|
33904
33935
|
sock.destroy();
|
|
33905
|
-
|
|
33936
|
+
resolve10();
|
|
33906
33937
|
});
|
|
33907
33938
|
sock.end(`${JSON.stringify(frameOf(a))}
|
|
33908
33939
|
`);
|
|
@@ -38055,12 +38086,12 @@ var init_stdio2 = __esm({
|
|
|
38055
38086
|
this.onclose?.();
|
|
38056
38087
|
}
|
|
38057
38088
|
send(message) {
|
|
38058
|
-
return new Promise((
|
|
38089
|
+
return new Promise((resolve10) => {
|
|
38059
38090
|
const json3 = serializeMessage(message);
|
|
38060
38091
|
if (this._stdout.write(json3)) {
|
|
38061
|
-
|
|
38092
|
+
resolve10();
|
|
38062
38093
|
} else {
|
|
38063
|
-
this._stdout.once("drain",
|
|
38094
|
+
this._stdout.once("drain", resolve10);
|
|
38064
38095
|
}
|
|
38065
38096
|
});
|
|
38066
38097
|
}
|
|
@@ -38229,7 +38260,7 @@ var harnessSkills = {
|
|
|
38229
38260
|
var harnessNames = Object.keys(harnessSkills);
|
|
38230
38261
|
|
|
38231
38262
|
// src/main.ts
|
|
38232
|
-
import { resolve as
|
|
38263
|
+
import { resolve as resolve9 } from "node:path";
|
|
38233
38264
|
|
|
38234
38265
|
// src/commands/daemon.ts
|
|
38235
38266
|
import { existsSync as existsSync4 } from "node:fs";
|
|
@@ -40239,7 +40270,7 @@ var HubConnection = class {
|
|
|
40239
40270
|
// Reply ids: the hub then names each sender's agent (deliver.from_id).
|
|
40240
40271
|
// Mailboxes: the hub then sends queued/since, away rows and the new
|
|
40241
40272
|
// refusals, and honours agent_up.replaces (#1295).
|
|
40242
|
-
caps: [BUS_CAPS.ids, BUS_CAPS.mailbox]
|
|
40273
|
+
caps: [BUS_CAPS.ids, BUS_CAPS.mailbox, BUS_CAPS.links]
|
|
40243
40274
|
});
|
|
40244
40275
|
this.#guard("sessions", () => {
|
|
40245
40276
|
this.send({
|
|
@@ -40491,22 +40522,22 @@ var Resends = class {
|
|
|
40491
40522
|
#send(e) {
|
|
40492
40523
|
e.stopRetry?.();
|
|
40493
40524
|
e.stopRetry = void 0;
|
|
40494
|
-
const
|
|
40495
|
-
e.link =
|
|
40525
|
+
const link2 = this.#link;
|
|
40526
|
+
e.link = link2;
|
|
40496
40527
|
const unsent = () => {
|
|
40497
|
-
if (this.#all.get(e.frame.id) !== e || e.link !==
|
|
40528
|
+
if (this.#all.get(e.frame.id) !== e || e.link !== link2) return;
|
|
40498
40529
|
e.link = -1;
|
|
40499
|
-
if (
|
|
40530
|
+
if (link2 === this.#link) this.#later(e);
|
|
40500
40531
|
};
|
|
40501
40532
|
if (!this.opts.send(e.frame, unsent)) unsent();
|
|
40502
40533
|
}
|
|
40503
40534
|
/** Sends `e` again after a backoff, on this link only; a dropped link resends on the next agent_ok. */
|
|
40504
40535
|
#later(e) {
|
|
40505
|
-
const
|
|
40536
|
+
const link2 = this.#link;
|
|
40506
40537
|
e.stopRetry?.();
|
|
40507
40538
|
e.stopRetry = this.#after(RETRY_BASE_MS * 2 ** e.retries++, () => {
|
|
40508
40539
|
e.stopRetry = void 0;
|
|
40509
|
-
if (
|
|
40540
|
+
if (link2 === this.#link) this.#send(e);
|
|
40510
40541
|
});
|
|
40511
40542
|
}
|
|
40512
40543
|
/** Sends never dropped and unanswered past the window: given up, never resent. */
|
|
@@ -41211,12 +41242,12 @@ var Receipts = class {
|
|
|
41211
41242
|
this.#waiting.delete(msgId);
|
|
41212
41243
|
return Promise.resolve(w.final);
|
|
41213
41244
|
}
|
|
41214
|
-
return new Promise((
|
|
41245
|
+
return new Promise((resolve10) => {
|
|
41215
41246
|
const cancel = this.#after(ms, () => w.done?.(void 0));
|
|
41216
41247
|
w.done = (f) => {
|
|
41217
41248
|
cancel();
|
|
41218
41249
|
this.#waiting.delete(msgId);
|
|
41219
|
-
|
|
41250
|
+
resolve10(f);
|
|
41220
41251
|
};
|
|
41221
41252
|
});
|
|
41222
41253
|
}
|
|
@@ -41525,22 +41556,22 @@ var ClaudeTransport = class {
|
|
|
41525
41556
|
return { ok: false, reason: "closed", cause: st };
|
|
41526
41557
|
}
|
|
41527
41558
|
#waitFor(msgId, ms) {
|
|
41528
|
-
return new Promise((
|
|
41559
|
+
return new Promise((resolve10) => {
|
|
41529
41560
|
const buffered = this.#buffered.get(msgId);
|
|
41530
41561
|
if (buffered !== void 0) {
|
|
41531
41562
|
this.#buffered.delete(msgId);
|
|
41532
|
-
|
|
41563
|
+
resolve10(buffered);
|
|
41533
41564
|
return;
|
|
41534
41565
|
}
|
|
41535
41566
|
const timer = setTimeout(() => {
|
|
41536
41567
|
this.#waiting.delete(msgId);
|
|
41537
|
-
|
|
41568
|
+
resolve10(void 0);
|
|
41538
41569
|
}, ms);
|
|
41539
41570
|
timer.unref();
|
|
41540
41571
|
this.#waiting.set(msgId, (s) => {
|
|
41541
41572
|
clearTimeout(timer);
|
|
41542
41573
|
this.#waiting.delete(msgId);
|
|
41543
|
-
|
|
41574
|
+
resolve10(s);
|
|
41544
41575
|
});
|
|
41545
41576
|
});
|
|
41546
41577
|
}
|
|
@@ -41680,9 +41711,9 @@ var ClaudeTransport = class {
|
|
|
41680
41711
|
);
|
|
41681
41712
|
})
|
|
41682
41713
|
};
|
|
41683
|
-
await new Promise((
|
|
41714
|
+
await new Promise((resolve10, reject) => {
|
|
41684
41715
|
sink.server.once("error", reject);
|
|
41685
|
-
sink.server.listen(path, () =>
|
|
41716
|
+
sink.server.listen(path, () => resolve10());
|
|
41686
41717
|
});
|
|
41687
41718
|
chmodSync7(path, 384);
|
|
41688
41719
|
return sink;
|
|
@@ -41901,7 +41932,7 @@ function splitArgv0(args) {
|
|
|
41901
41932
|
});
|
|
41902
41933
|
return words(args.slice(real2 ?? ends[0]));
|
|
41903
41934
|
}
|
|
41904
|
-
var execText = (cmd, args) => new Promise((
|
|
41935
|
+
var execText = (cmd, args) => new Promise((resolve10) => {
|
|
41905
41936
|
execFile(
|
|
41906
41937
|
cmd,
|
|
41907
41938
|
args,
|
|
@@ -41910,7 +41941,7 @@ var execText = (cmd, args) => new Promise((resolve9) => {
|
|
|
41910
41941
|
timeout: 2e3,
|
|
41911
41942
|
env: { ...process.env, LC_ALL: "C" }
|
|
41912
41943
|
},
|
|
41913
|
-
(err, stdout) =>
|
|
41944
|
+
(err, stdout) => resolve10(err ? void 0 : stdout)
|
|
41914
41945
|
);
|
|
41915
41946
|
});
|
|
41916
41947
|
async function processArgs(pid) {
|
|
@@ -41933,17 +41964,17 @@ async function processArgs(pid) {
|
|
|
41933
41964
|
return args ? splitArgv0(args) : void 0;
|
|
41934
41965
|
}
|
|
41935
41966
|
var START_ERRORS = /* @__PURE__ */ new Set(["ENOENT", "EACCES", "ENOEXEC"]);
|
|
41936
|
-
var execCodex = (timeoutMs = CODEX_QUEUE_TIMEOUT_MS) => (bin, args, env2) => new Promise((
|
|
41967
|
+
var execCodex = (timeoutMs = CODEX_QUEUE_TIMEOUT_MS) => (bin, args, env2) => new Promise((resolve10, reject) => {
|
|
41937
41968
|
execFile(
|
|
41938
41969
|
bin,
|
|
41939
41970
|
args,
|
|
41940
41971
|
{ timeout: timeoutMs, maxBuffer: 64 * 1024, env: env2 },
|
|
41941
41972
|
(err, _stdout, stderr) => {
|
|
41942
|
-
if (!err) return
|
|
41973
|
+
if (!err) return resolve10({ code: 0, stderr });
|
|
41943
41974
|
const e = err;
|
|
41944
41975
|
if (typeof e.code === "string" && START_ERRORS.has(e.code))
|
|
41945
41976
|
return reject(err);
|
|
41946
|
-
|
|
41977
|
+
resolve10({
|
|
41947
41978
|
// A maxBuffer kill is SIGTERM too, but carries its own string code.
|
|
41948
41979
|
code: e.killed && e.signal === "SIGTERM" && typeof e.code !== "string" ? null : typeof e.code === "number" ? e.code : -1,
|
|
41949
41980
|
stderr: String(stderr ?? "")
|
|
@@ -42068,17 +42099,17 @@ var codexHostWakes = async (pid) => {
|
|
|
42068
42099
|
init_src2();
|
|
42069
42100
|
import { execFile as execFile2 } from "node:child_process";
|
|
42070
42101
|
var START_ERRORS2 = /* @__PURE__ */ new Set(["ENOENT", "EACCES"]);
|
|
42071
|
-
var execSpawn = (timeoutMs, maxBuffer = 1024 * 1024) => (cmd, args) => new Promise((
|
|
42102
|
+
var execSpawn = (timeoutMs, maxBuffer = 1024 * 1024) => (cmd, args) => new Promise((resolve10, reject) => {
|
|
42072
42103
|
execFile2(
|
|
42073
42104
|
cmd,
|
|
42074
42105
|
args,
|
|
42075
42106
|
{ timeout: timeoutMs, maxBuffer },
|
|
42076
42107
|
(err, stdout, stderr) => {
|
|
42077
|
-
if (!err) return
|
|
42108
|
+
if (!err) return resolve10({ code: 0, stdout, stderr });
|
|
42078
42109
|
const e = err;
|
|
42079
42110
|
if (typeof e.code === "string" && START_ERRORS2.has(e.code))
|
|
42080
42111
|
return reject(err);
|
|
42081
|
-
|
|
42112
|
+
resolve10({
|
|
42082
42113
|
code: e.killed || typeof e.code !== "number" ? null : e.code,
|
|
42083
42114
|
stdout,
|
|
42084
42115
|
stderr
|
|
@@ -42193,18 +42224,18 @@ var PiTransport = class {
|
|
|
42193
42224
|
});
|
|
42194
42225
|
if (!pushed) return { ok: false, reason: "closed" };
|
|
42195
42226
|
this.#forget(mail.msg_id);
|
|
42196
|
-
return new Promise((
|
|
42227
|
+
return new Promise((resolve10) => {
|
|
42197
42228
|
const timer = setTimeout(() => {
|
|
42198
42229
|
this.#waiting.delete(mail.msg_id);
|
|
42199
42230
|
this.#remember(mail.msg_id, agent.ref);
|
|
42200
|
-
|
|
42231
|
+
resolve10({ ok: false, reason: "timeout" });
|
|
42201
42232
|
}, this.opts.ackTimeoutMs ?? 1e4);
|
|
42202
42233
|
timer.unref();
|
|
42203
42234
|
this.#waiting.set(mail.msg_id, {
|
|
42204
42235
|
ref: agent.ref,
|
|
42205
42236
|
done: (o) => {
|
|
42206
42237
|
clearTimeout(timer);
|
|
42207
|
-
|
|
42238
|
+
resolve10(o);
|
|
42208
42239
|
}
|
|
42209
42240
|
});
|
|
42210
42241
|
});
|
|
@@ -42799,21 +42830,21 @@ async function runDaemon(deps = {}) {
|
|
|
42799
42830
|
statusEveryMs: deps.status?.statusEveryMs
|
|
42800
42831
|
});
|
|
42801
42832
|
const hubRoster = (ref) => new Promise(
|
|
42802
|
-
(
|
|
42833
|
+
(resolve10) => {
|
|
42803
42834
|
const id = pending.open(
|
|
42804
42835
|
"status",
|
|
42805
|
-
(f) =>
|
|
42836
|
+
(f) => resolve10(f.type === "roster" ? f.agents : void 0)
|
|
42806
42837
|
);
|
|
42807
42838
|
const timer = setTimeout(() => {
|
|
42808
42839
|
pending.cancel(id);
|
|
42809
42840
|
hub.cancel(id);
|
|
42810
|
-
|
|
42841
|
+
resolve10(void 0);
|
|
42811
42842
|
}, deps.statusRosterMs ?? 1500);
|
|
42812
42843
|
timer.unref();
|
|
42813
42844
|
if (!hub.send({ v: 1, id, type: "list", from_ref: ref })) {
|
|
42814
42845
|
clearTimeout(timer);
|
|
42815
42846
|
pending.cancel(id);
|
|
42816
|
-
|
|
42847
|
+
resolve10(void 0);
|
|
42817
42848
|
}
|
|
42818
42849
|
}
|
|
42819
42850
|
);
|
|
@@ -43613,12 +43644,12 @@ function copy(style) {
|
|
|
43613
43644
|
next(`If it keeps running, run ${BUS_CMD} doctor to see why.`)
|
|
43614
43645
|
],
|
|
43615
43646
|
// 7. status
|
|
43616
|
-
hubRow: (host,
|
|
43617
|
-
if (!
|
|
43618
|
-
const word = `${
|
|
43619
|
-
const tone =
|
|
43620
|
-
const dur =
|
|
43621
|
-
return `Hub ${clip(host, 9 + 2 + len(word) + (
|
|
43647
|
+
hubRow: (host, link2) => {
|
|
43648
|
+
if (!link2) return `Hub ${clip(host, 9)}`;
|
|
43649
|
+
const word = `${link2.state === "connected" ? g("live") : g("queued")} ${link2.state}`;
|
|
43650
|
+
const tone = link2.state === "connected" ? "success" : "warning";
|
|
43651
|
+
const dur = link2.for ? ` ${p("muted", link2.for)}` : "";
|
|
43652
|
+
return `Hub ${clip(host, 9 + 2 + len(word) + (link2.for ? 2 + len(link2.for) : 0))} ${p(tone, word)}${dur}`;
|
|
43622
43653
|
},
|
|
43623
43654
|
machineRow: (label) => `Machine ${clip(label, 9)}`,
|
|
43624
43655
|
statusDaemonDown: () => [
|
|
@@ -43867,6 +43898,52 @@ function copy(style) {
|
|
|
43867
43898
|
`${rows.length} approved ${rows.length === 1 ? "namespace" : "namespaces"}`,
|
|
43868
43899
|
...rows.map((r) => ` ${clip(r.dir, 2)} ${p("muted", r.namespace)}`)
|
|
43869
43900
|
],
|
|
43901
|
+
// link, unlink (#1567)
|
|
43902
|
+
linkNotDir: (dir) => fail(`${clip(dir, 20)} is not a directory.`),
|
|
43903
|
+
linkSame: (a, b2, namespace2) => [
|
|
43904
|
+
fail(`${clip(a, 20)} and ${clip(b2, 20)} are in the same namespace.`),
|
|
43905
|
+
next(
|
|
43906
|
+
`Both are ${clip(namespace2, 12)}. A link joins two different namespaces.`
|
|
43907
|
+
)
|
|
43908
|
+
],
|
|
43909
|
+
linkNeedLogin: () => [
|
|
43910
|
+
fail("This machine is not signed in to a hub."),
|
|
43911
|
+
next(`Run ${BUS_CMD} login, then try again.`)
|
|
43912
|
+
],
|
|
43913
|
+
linkUnauthorized: () => [
|
|
43914
|
+
fail("The hub did not accept this machine's token."),
|
|
43915
|
+
next(`Run ${BUS_CMD} login, then try again.`)
|
|
43916
|
+
],
|
|
43917
|
+
linkRefused: (reason) => reason === "rate_limited" ? [
|
|
43918
|
+
fail("This machine asked for too many link changes."),
|
|
43919
|
+
next("Try again in an hour.")
|
|
43920
|
+
] : reason === "proposal_limit" ? [
|
|
43921
|
+
fail("Too many link changes are waiting for you."),
|
|
43922
|
+
next("Confirm or let them expire, then try again.")
|
|
43923
|
+
] : reason === "no_bus" ? [
|
|
43924
|
+
fail("The hub has no connected machine for you yet."),
|
|
43925
|
+
next(`Start the daemon with ${BUS_CMD}, then try again.`)
|
|
43926
|
+
] : [fail("The hub refused the request.")],
|
|
43927
|
+
linkBadReply: () => [
|
|
43928
|
+
fail("The hub's answer was not a confirm link for this instance."),
|
|
43929
|
+
next("Nothing was changed.")
|
|
43930
|
+
],
|
|
43931
|
+
linkProposed: (action, a, b2, url2) => [
|
|
43932
|
+
step2(`${action === "link" ? "Link" : "Unlink"} these two namespaces`),
|
|
43933
|
+
next(`${clip(a.namespace, 8)} ${p("muted", clip(a.dir, 12))}`),
|
|
43934
|
+
next(`${clip(b2.namespace, 8)} ${p("muted", clip(b2.dir, 12))}`),
|
|
43935
|
+
"",
|
|
43936
|
+
next(p("accent", url2)),
|
|
43937
|
+
next("Open this in your browser to confirm."),
|
|
43938
|
+
p(
|
|
43939
|
+
"muted",
|
|
43940
|
+
" Nothing changes until you confirm. The link works once, for an hour."
|
|
43941
|
+
)
|
|
43942
|
+
],
|
|
43943
|
+
linkList: (busUrl) => [
|
|
43944
|
+
"Links are managed on your bus page.",
|
|
43945
|
+
next(p("accent", busUrl))
|
|
43946
|
+
],
|
|
43870
43947
|
// logs, mcp (DRAFT)
|
|
43871
43948
|
noLog: (path) => [
|
|
43872
43949
|
warn(`No daemon log yet at ${clip(path, 24)}`),
|
|
@@ -43885,19 +43962,19 @@ init_src2();
|
|
|
43885
43962
|
import { execFile as execFile3, spawn } from "node:child_process";
|
|
43886
43963
|
import { promisify } from "node:util";
|
|
43887
43964
|
var browserCommand = (platform, url2) => platform === "darwin" ? { cmd: "open", args: [url2] } : platform === "win32" ? { cmd: "rundll32", args: ["url.dll,FileProtocolHandler", url2] } : { cmd: "xdg-open", args: [url2] };
|
|
43888
|
-
var openBrowser = (url2, launcher = browserCommand(process.platform, url2)) => new Promise((
|
|
43965
|
+
var openBrowser = (url2, launcher = browserCommand(process.platform, url2)) => new Promise((resolve10) => {
|
|
43889
43966
|
try {
|
|
43890
43967
|
const child = spawn(launcher.cmd, launcher.args, {
|
|
43891
43968
|
stdio: "ignore",
|
|
43892
43969
|
detached: true
|
|
43893
43970
|
});
|
|
43894
|
-
child.once("error", () =>
|
|
43971
|
+
child.once("error", () => resolve10(false));
|
|
43895
43972
|
child.once("spawn", () => {
|
|
43896
43973
|
child.unref();
|
|
43897
|
-
|
|
43974
|
+
resolve10(true);
|
|
43898
43975
|
});
|
|
43899
43976
|
} catch {
|
|
43900
|
-
|
|
43977
|
+
resolve10(false);
|
|
43901
43978
|
}
|
|
43902
43979
|
});
|
|
43903
43980
|
var EXEC_TIMEOUT_MS = 1e4;
|
|
@@ -45390,7 +45467,7 @@ var noService = {
|
|
|
45390
45467
|
remove: async () => ({}),
|
|
45391
45468
|
cli: () => ["oa-bus"]
|
|
45392
45469
|
};
|
|
45393
|
-
var VERSION = true ? "0.
|
|
45470
|
+
var VERSION = true ? "0.131.0" : JSON.parse(
|
|
45394
45471
|
readFileSync13(new URL("../package.json", import.meta.url), "utf8")
|
|
45395
45472
|
).version;
|
|
45396
45473
|
var which = (cmd) => {
|
|
@@ -45472,7 +45549,7 @@ function realCtx(noColor) {
|
|
|
45472
45549
|
});
|
|
45473
45550
|
try {
|
|
45474
45551
|
return await new Promise(
|
|
45475
|
-
(
|
|
45552
|
+
(resolve10) => rl.question(question, resolve10)
|
|
45476
45553
|
);
|
|
45477
45554
|
} finally {
|
|
45478
45555
|
rl.close();
|
|
@@ -45597,7 +45674,7 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
|
|
|
45597
45674
|
sayErr(ctx, ctx.copy.revoked());
|
|
45598
45675
|
return 0;
|
|
45599
45676
|
}
|
|
45600
|
-
return new Promise((
|
|
45677
|
+
return new Promise((resolve10) => {
|
|
45601
45678
|
let running;
|
|
45602
45679
|
let ended = false;
|
|
45603
45680
|
const end = (code2) => {
|
|
@@ -45605,7 +45682,7 @@ async function daemon(ctx, run4 = runDaemon, signals = process) {
|
|
|
45605
45682
|
ended = true;
|
|
45606
45683
|
signals.off("SIGINT", onSignal);
|
|
45607
45684
|
signals.off("SIGTERM", onSignal);
|
|
45608
|
-
void (running?.stop() ?? Promise.resolve()).finally(() =>
|
|
45685
|
+
void (running?.stop() ?? Promise.resolve()).finally(() => resolve10(code2));
|
|
45609
45686
|
};
|
|
45610
45687
|
const onSignal = () => end(0);
|
|
45611
45688
|
signals.once("SIGINT", onSignal);
|
|
@@ -48627,6 +48704,99 @@ async function global(opts, ctx) {
|
|
|
48627
48704
|
return 0;
|
|
48628
48705
|
}
|
|
48629
48706
|
|
|
48707
|
+
// src/commands/link.ts
|
|
48708
|
+
import { statSync as statSync11 } from "node:fs";
|
|
48709
|
+
import { resolve as resolve7 } from "node:path";
|
|
48710
|
+
init_src();
|
|
48711
|
+
function side(ctx, dir) {
|
|
48712
|
+
const given = resolve7(ctx.cwd, dir);
|
|
48713
|
+
try {
|
|
48714
|
+
const real2 = canonicalPath(given);
|
|
48715
|
+
if (!statSync11(real2).isDirectory()) return void 0;
|
|
48716
|
+
const ns = resolveNamespace(real2, {
|
|
48717
|
+
globalFile: globalFile(ctx.home),
|
|
48718
|
+
namespacesFile: namespacesFile(ctx.home)
|
|
48719
|
+
});
|
|
48720
|
+
return { dir: real2, namespace: ns.namespace };
|
|
48721
|
+
} catch {
|
|
48722
|
+
return void 0;
|
|
48723
|
+
}
|
|
48724
|
+
}
|
|
48725
|
+
async function link(opts, ctx) {
|
|
48726
|
+
const c = ctx.copy;
|
|
48727
|
+
say(ctx, c.header(ctx.version), "");
|
|
48728
|
+
const m = readMachine(ctx.home);
|
|
48729
|
+
if (m.state !== "ok") {
|
|
48730
|
+
sayErr(ctx, c.linkNeedLogin());
|
|
48731
|
+
return 1;
|
|
48732
|
+
}
|
|
48733
|
+
if (opts.sub === "list") {
|
|
48734
|
+
say(ctx, c.linkList(new URL(BUS_ROUTES.page, m.hub).href));
|
|
48735
|
+
return 0;
|
|
48736
|
+
}
|
|
48737
|
+
const sides = [];
|
|
48738
|
+
for (const d of opts.dirs) {
|
|
48739
|
+
const s = side(ctx, d);
|
|
48740
|
+
if (!s) {
|
|
48741
|
+
sayErr(ctx, c.linkNotDir(shq(resolve7(ctx.cwd, d))));
|
|
48742
|
+
return 1;
|
|
48743
|
+
}
|
|
48744
|
+
sides.push(s);
|
|
48745
|
+
}
|
|
48746
|
+
const [a, b] = sides;
|
|
48747
|
+
if (a.namespace === b.namespace) {
|
|
48748
|
+
sayErr(ctx, c.linkSame(shq(a.dir), shq(b.dir), plain2(a.namespace)));
|
|
48749
|
+
return 1;
|
|
48750
|
+
}
|
|
48751
|
+
const action = opts.sub === "add" ? "link" : "unlink";
|
|
48752
|
+
const res = await ctx.fetch(new URL(BUS_ROUTES.linkProposals, m.hub), {
|
|
48753
|
+
method: "POST",
|
|
48754
|
+
headers: {
|
|
48755
|
+
authorization: `Bearer ${m.token}`,
|
|
48756
|
+
"content-type": "application/json"
|
|
48757
|
+
},
|
|
48758
|
+
body: JSON.stringify({ action, a: a.namespace, b: b.namespace })
|
|
48759
|
+
});
|
|
48760
|
+
if (res.status === 401) {
|
|
48761
|
+
sayErr(ctx, c.linkUnauthorized());
|
|
48762
|
+
return 1;
|
|
48763
|
+
}
|
|
48764
|
+
if (!res.ok) {
|
|
48765
|
+
let reason;
|
|
48766
|
+
try {
|
|
48767
|
+
const j = await res.json();
|
|
48768
|
+
if (typeof j.details?.reason === "string") reason = j.details.reason;
|
|
48769
|
+
} catch {
|
|
48770
|
+
}
|
|
48771
|
+
sayErr(ctx, c.linkRefused(reason));
|
|
48772
|
+
return 1;
|
|
48773
|
+
}
|
|
48774
|
+
let url2;
|
|
48775
|
+
try {
|
|
48776
|
+
const j = await res.json();
|
|
48777
|
+
if (typeof j.confirmUrl === "string") {
|
|
48778
|
+
const u = new URL(j.confirmUrl);
|
|
48779
|
+
if (u.origin === new URL(m.hub).origin && /^\/bus\/links\/confirm\/[A-Za-z0-9_-]{43}$/.test(u.pathname) && !u.search && !u.hash)
|
|
48780
|
+
url2 = u.href;
|
|
48781
|
+
}
|
|
48782
|
+
} catch {
|
|
48783
|
+
}
|
|
48784
|
+
if (!url2) {
|
|
48785
|
+
sayErr(ctx, c.linkBadReply());
|
|
48786
|
+
return 1;
|
|
48787
|
+
}
|
|
48788
|
+
say(
|
|
48789
|
+
ctx,
|
|
48790
|
+
c.linkProposed(
|
|
48791
|
+
action,
|
|
48792
|
+
{ dir: shq(a.dir), namespace: plain2(a.namespace) },
|
|
48793
|
+
{ dir: shq(b.dir), namespace: plain2(b.namespace) },
|
|
48794
|
+
url2
|
|
48795
|
+
)
|
|
48796
|
+
);
|
|
48797
|
+
return 0;
|
|
48798
|
+
}
|
|
48799
|
+
|
|
48630
48800
|
// src/commands/logs.ts
|
|
48631
48801
|
import { readFileSync as readFileSync18 } from "node:fs";
|
|
48632
48802
|
import { join as join22 } from "node:path";
|
|
@@ -48661,8 +48831,8 @@ async function mcp(harness, ctx, load = (h) => MCP_SERVER[h]()) {
|
|
|
48661
48831
|
}
|
|
48662
48832
|
|
|
48663
48833
|
// src/commands/namespace.ts
|
|
48664
|
-
import { realpathSync as realpathSync10, statSync as
|
|
48665
|
-
import { join as join23, resolve as
|
|
48834
|
+
import { realpathSync as realpathSync10, statSync as statSync12 } from "node:fs";
|
|
48835
|
+
import { join as join23, resolve as resolve8 } from "node:path";
|
|
48666
48836
|
init_src();
|
|
48667
48837
|
function shown2(ctx, path) {
|
|
48668
48838
|
const t = tilde(ctx, path);
|
|
@@ -48689,7 +48859,7 @@ async function namespace(opts, ctx) {
|
|
|
48689
48859
|
);
|
|
48690
48860
|
return 0;
|
|
48691
48861
|
}
|
|
48692
|
-
const given =
|
|
48862
|
+
const given = resolve8(ctx.cwd, opts.dir);
|
|
48693
48863
|
let real2;
|
|
48694
48864
|
try {
|
|
48695
48865
|
real2 = canonicalPath(given);
|
|
@@ -48712,7 +48882,7 @@ async function namespace(opts, ctx) {
|
|
|
48712
48882
|
say(ctx, c.nsRevoked(shown2(ctx, real2 ?? given)));
|
|
48713
48883
|
return 0;
|
|
48714
48884
|
}
|
|
48715
|
-
if (!real2 || !
|
|
48885
|
+
if (!real2 || !statSync12(real2).isDirectory()) {
|
|
48716
48886
|
sayErr(ctx, c.nsNotDir(shown2(ctx, real2 ?? given)));
|
|
48717
48887
|
return 1;
|
|
48718
48888
|
}
|
|
@@ -48962,10 +49132,13 @@ var COMMANDS = /* @__PURE__ */ new Set([
|
|
|
48962
49132
|
"uninstall",
|
|
48963
49133
|
"global",
|
|
48964
49134
|
"namespace",
|
|
49135
|
+
"link",
|
|
49136
|
+
"unlink",
|
|
48965
49137
|
"version"
|
|
48966
49138
|
]);
|
|
48967
49139
|
var HARNESSES2 = ["claude", "opencode", "codex", "pi"];
|
|
48968
49140
|
var GLOBAL_USAGE = `usage: ${BUS_CMD} global <add|rm> <dir>, or global list`;
|
|
49141
|
+
var LINK_USAGE = `usage: ${BUS_CMD} link <dir> <dir>, ${BUS_CMD} unlink <dir> <dir>, or link list`;
|
|
48969
49142
|
var NAMESPACE_USAGE = `usage: ${BUS_CMD} namespace approve [dir], namespace revoke <dir>, or namespace list`;
|
|
48970
49143
|
var COMMON = /* @__PURE__ */ new Set(["no-color", "version", "home"]);
|
|
48971
49144
|
var FLAGS = {
|
|
@@ -49008,7 +49181,13 @@ function parse7(argv) {
|
|
|
49008
49181
|
if (rest[max] !== void 0)
|
|
49009
49182
|
throw new Error(`unexpected argument: ${rest[max]}`);
|
|
49010
49183
|
}
|
|
49011
|
-
|
|
49184
|
+
if (cmd === "link" || cmd === "unlink") {
|
|
49185
|
+
const n = cmd === "link" && rest[0] === "list" ? 1 : 2;
|
|
49186
|
+
if (rest.length < n) throw new Error(LINK_USAGE);
|
|
49187
|
+
if (rest[n] !== void 0)
|
|
49188
|
+
throw new Error(`unexpected argument: ${rest[n]}`);
|
|
49189
|
+
}
|
|
49190
|
+
const extra = cmd === "namespace" || cmd === "link" || cmd === "unlink" ? void 0 : rest[takes];
|
|
49012
49191
|
if (extra !== void 0) throw new Error(`unexpected argument: ${extra}`);
|
|
49013
49192
|
for (const name of ["home", "instance"])
|
|
49014
49193
|
if (values[name] === "") throw new Error(`--${name} needs a value`);
|
|
@@ -49052,6 +49231,18 @@ function route(cmd, values, positionals) {
|
|
|
49052
49231
|
return { cmd, sub, dir: dir ?? ".", yes: values.yes };
|
|
49053
49232
|
throw new Error(NAMESPACE_USAGE);
|
|
49054
49233
|
}
|
|
49234
|
+
case "link":
|
|
49235
|
+
case "unlink": {
|
|
49236
|
+
if (cmd === "link" && positionals[0] === "list")
|
|
49237
|
+
return { cmd: "link", sub: "list" };
|
|
49238
|
+
const [a, b] = positionals;
|
|
49239
|
+
if (!a || !b) throw new Error(LINK_USAGE);
|
|
49240
|
+
return {
|
|
49241
|
+
cmd: "link",
|
|
49242
|
+
sub: cmd === "link" ? "add" : "rm",
|
|
49243
|
+
dirs: [a, b]
|
|
49244
|
+
};
|
|
49245
|
+
}
|
|
49055
49246
|
case "install":
|
|
49056
49247
|
return {
|
|
49057
49248
|
cmd,
|
|
@@ -49082,7 +49273,7 @@ async function main(argv, makeCtx = realCtx) {
|
|
|
49082
49273
|
return 2;
|
|
49083
49274
|
}
|
|
49084
49275
|
const ctx = makeCtx(cmd.noColor);
|
|
49085
|
-
if (cmd.home) ctx.home =
|
|
49276
|
+
if (cmd.home) ctx.home = resolve9(cmd.home);
|
|
49086
49277
|
try {
|
|
49087
49278
|
return await dispatch(cmd, ctx);
|
|
49088
49279
|
} catch (e) {
|
|
@@ -49136,6 +49327,8 @@ async function dispatch(cmd, ctx) {
|
|
|
49136
49327
|
return global(cmd, ctx);
|
|
49137
49328
|
case "namespace":
|
|
49138
49329
|
return namespace(cmd, ctx);
|
|
49330
|
+
case "link":
|
|
49331
|
+
return link(cmd, ctx);
|
|
49139
49332
|
case "version":
|
|
49140
49333
|
say(ctx, ctx.copy.header(ctx.version));
|
|
49141
49334
|
return 0;
|