@open-artifacts/bus 0.140.0 → 0.141.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 +150 -21
- package/assets/oa_bus/bus.py +79 -8
- package/assets/oa_bus/copy.py +43 -0
- package/assets/oa_bus/plugin.yaml +3 -0
- package/assets/oa_bus/roots.py +26 -0
- package/assets/oa_bus/tools.py +2 -16
- package/assets/openclaw/index.js +30786 -0
- package/assets/openclaw/openclaw.plugin.json +19 -0
- package/assets/openclaw/package.json +14 -0
- package/dist/index.js +2613 -1433
- 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.141.0";
|
|
15
15
|
|
|
16
16
|
type Frame = Json & { type: string; id: string };
|
|
17
17
|
type Ctx = {
|
|
@@ -414,10 +414,49 @@ const followingText = (
|
|
|
414
414
|
? follows.map((f) => `${f.url} (since ${f.followed_at})`).join("\n")
|
|
415
415
|
: "You are not following any artifacts.";
|
|
416
416
|
|
|
417
|
+
/** The bad_frame answers a current daemon gives a follow call itself (@oa/bus-ipc FOLLOW_DAEMON_BAD_FRAME). */
|
|
418
|
+
const FOLLOW_DAEMON_BAD_FRAME = [
|
|
419
|
+
"follow is not supported on this connection",
|
|
420
|
+
"the frame is not valid on the hub wire",
|
|
421
|
+
];
|
|
422
|
+
|
|
417
423
|
/** What an agent sees when its daemon is too old for the follow frames. */
|
|
418
424
|
const FOLLOW_OLD_DAEMON =
|
|
419
425
|
"This oa-bus daemon is too old to follow artifacts. Ask the user to update oa-bus.";
|
|
420
426
|
|
|
427
|
+
/** The `propose_reach` result (#1346). */
|
|
428
|
+
const reachProposedText = (
|
|
429
|
+
namespaces: readonly string[],
|
|
430
|
+
url: string,
|
|
431
|
+
expiresAt: string,
|
|
432
|
+
): string =>
|
|
433
|
+
`Proposed: let your role reach ${namespaces.join(", ")}. Nothing has changed. Give the person this link to confirm it in their browser, signed in (it works once and expires at ${expiresAt}): ${url}`;
|
|
434
|
+
|
|
435
|
+
/** What an agent sees when its daemon is too old for the reach frames. */
|
|
436
|
+
const REACH_OLD_DAEMON =
|
|
437
|
+
"This oa-bus daemon is too old to ask for reach. Ask the user to update oa-bus.";
|
|
438
|
+
|
|
439
|
+
/** The `propose_reach` namespaces: 1 to 10, each as list_agents shows it. @oa/bus-ipc reachNamespacesOf. */
|
|
440
|
+
const reachNamespacesOf = (
|
|
441
|
+
value: unknown,
|
|
442
|
+
): { namespaces: string[] } | { error: string } => {
|
|
443
|
+
const list = Array.isArray(value)
|
|
444
|
+
? value.map((v) => (typeof v === "string" ? v.trim() : ""))
|
|
445
|
+
: [];
|
|
446
|
+
if (list.length < 1 || list.length > 10)
|
|
447
|
+
return {
|
|
448
|
+
error: "oa-bus: namespaces: give 1 to 10 namespaces. Nothing was asked.",
|
|
449
|
+
};
|
|
450
|
+
const bad = list.find(
|
|
451
|
+
(n) => n.length < 1 || n.length > 128 || !/^[a-z0-9._~/-]+$/.test(n),
|
|
452
|
+
);
|
|
453
|
+
if (bad !== undefined)
|
|
454
|
+
return {
|
|
455
|
+
error: `oa-bus: namespaces: "${bad.slice(0, 40)}" is not a namespace. Use one as list_agents shows it. Nothing was asked.`,
|
|
456
|
+
};
|
|
457
|
+
return { namespaces: [...new Set(list)] };
|
|
458
|
+
};
|
|
459
|
+
|
|
421
460
|
/** @oa/bus-protocol BAD_NS_CHARS: control, bidi and zero-width characters. */
|
|
422
461
|
const BAD_LABEL_CHARS =
|
|
423
462
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: rejecting them is the point
|
|
@@ -504,6 +543,58 @@ function rosterLine(
|
|
|
504
543
|
return `- ${a.name} (${displayKind(a.kind)}, ${a.namespace}${typeof a.machine_label === "string" && a.machine_label ? `, ${a.machine_label}` : ""})${a.away !== undefined ? (a.away ? ` (away since ${awayTime(a.away)})` : " (away)") : a.queued ? " (queued)" : ""}${says ? ` ${says}` : ""}`;
|
|
505
544
|
}
|
|
506
545
|
|
|
546
|
+
/** @oa/bus-protocol isFallbackName: a name only the harness gave the session. */
|
|
547
|
+
const isFallbackName = (name: string, kind: string): boolean => {
|
|
548
|
+
const lname = name.toLowerCase();
|
|
549
|
+
return (
|
|
550
|
+
lname === kind ||
|
|
551
|
+
lname.startsWith(`${kind}-`) ||
|
|
552
|
+
lname === "agent" ||
|
|
553
|
+
/^claude-\d+$/.test(lname)
|
|
554
|
+
);
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
/** @oa/bus-ipc collapsedAwayLine: the count of away fallback-named rows. */
|
|
558
|
+
const collapsedAwayLine = (n: number, listed: boolean): string =>
|
|
559
|
+
`${n}${listed ? " more" : ""} away ${n === 1 ? "session" : "sessions"} with no chosen name (not listed, still reachable by name)`;
|
|
560
|
+
|
|
561
|
+
/** @oa/bus-ipc rosterText: the list_agents text from the hub's roster rows. */
|
|
562
|
+
function rosterText(
|
|
563
|
+
agents: readonly (StatusFields & {
|
|
564
|
+
name: string;
|
|
565
|
+
kind: string;
|
|
566
|
+
namespace: string;
|
|
567
|
+
machine_label?: unknown;
|
|
568
|
+
state?: unknown;
|
|
569
|
+
live?: unknown;
|
|
570
|
+
since?: unknown;
|
|
571
|
+
})[],
|
|
572
|
+
now = Date.now(),
|
|
573
|
+
): string {
|
|
574
|
+
if (!agents.length) return "No agents in your namespace and linked ones.";
|
|
575
|
+
const lines: string[] = [];
|
|
576
|
+
let collapsed = 0;
|
|
577
|
+
for (const a of agents) {
|
|
578
|
+
const away = a.state === "away";
|
|
579
|
+
if (away && isFallbackName(a.name, a.kind)) {
|
|
580
|
+
collapsed++;
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
lines.push(
|
|
584
|
+
rosterLine(
|
|
585
|
+
{
|
|
586
|
+
...a,
|
|
587
|
+
queued: (a.state ?? (a.live ? "live" : "queued")) === "queued",
|
|
588
|
+
away: away ? String(a.since ?? "") : undefined,
|
|
589
|
+
},
|
|
590
|
+
now,
|
|
591
|
+
),
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
if (collapsed > 0) lines.push(collapsedAwayLine(collapsed, lines.length > 0));
|
|
595
|
+
return lines.join("\n");
|
|
596
|
+
}
|
|
597
|
+
|
|
507
598
|
/** @oa/bus-ipc selfText: the agent entry, its status cleaned. */
|
|
508
599
|
function selfText(
|
|
509
600
|
agent: (StatusFields & Record<string, unknown>) | null,
|
|
@@ -539,9 +630,13 @@ export const copy = {
|
|
|
539
630
|
unfollowText,
|
|
540
631
|
followingText,
|
|
541
632
|
FOLLOW_OLD_DAEMON,
|
|
633
|
+
reachProposedText,
|
|
634
|
+
REACH_OLD_DAEMON,
|
|
635
|
+
reachNamespacesOf,
|
|
542
636
|
displayKind,
|
|
543
637
|
statusSaysText,
|
|
544
638
|
rosterLine,
|
|
639
|
+
rosterText,
|
|
545
640
|
selfText,
|
|
546
641
|
receiptText,
|
|
547
642
|
movedName,
|
|
@@ -657,6 +752,25 @@ const TOOLS = [
|
|
|
657
752
|
description: "List the artifacts you follow.",
|
|
658
753
|
parameters: none,
|
|
659
754
|
},
|
|
755
|
+
{
|
|
756
|
+
name: "oabus_propose_reach",
|
|
757
|
+
label: "Open Artifacts bus: ask for reach",
|
|
758
|
+
description:
|
|
759
|
+
"Ask that the role you hold be able to message agents in more namespaces. Name only other namespaces: your role already reaches its own. This only asks: nothing changes until the person confirms on the link you get back.",
|
|
760
|
+
parameters: {
|
|
761
|
+
type: "object",
|
|
762
|
+
properties: {
|
|
763
|
+
namespaces: {
|
|
764
|
+
type: "array",
|
|
765
|
+
items: { type: "string" },
|
|
766
|
+
minItems: 1,
|
|
767
|
+
maxItems: 10,
|
|
768
|
+
},
|
|
769
|
+
},
|
|
770
|
+
required: ["namespaces"],
|
|
771
|
+
additionalProperties: false,
|
|
772
|
+
},
|
|
773
|
+
},
|
|
660
774
|
] as const;
|
|
661
775
|
|
|
662
776
|
const STATES = ["working", "idle", "blocked", "waiting_on_owner"];
|
|
@@ -970,7 +1084,7 @@ function open(
|
|
|
970
1084
|
// #1295: this asset decodes away rows and the new refusals.
|
|
971
1085
|
// #1525: and a config file that is pending approval.
|
|
972
1086
|
// #1635: and may send a rename.
|
|
973
|
-
caps: ["mailbox", "pending", "rename", "follow"],
|
|
1087
|
+
caps: ["mailbox", "pending", "rename", "follow", "reach"],
|
|
974
1088
|
attest: start ? { proc_start: start } : {},
|
|
975
1089
|
}),
|
|
976
1090
|
);
|
|
@@ -1189,24 +1303,15 @@ export default function oaBus(pi: Pi): void {
|
|
|
1189
1303
|
if (r.type !== "roster") failed(r);
|
|
1190
1304
|
const agents = (r.agents ?? []) as Json[];
|
|
1191
1305
|
const now = Date.now();
|
|
1192
|
-
return
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
queued:
|
|
1202
|
-
(a.state ?? (a.live ? "live" : "queued")) === "queued",
|
|
1203
|
-
away: a.state === "away" ? String(a.since ?? "") : undefined,
|
|
1204
|
-
},
|
|
1205
|
-
now,
|
|
1206
|
-
),
|
|
1207
|
-
)
|
|
1208
|
-
.join("\n")
|
|
1209
|
-
: "No agents in your namespace and linked ones.";
|
|
1306
|
+
return rosterText(
|
|
1307
|
+
agents.map((a) => ({
|
|
1308
|
+
...a,
|
|
1309
|
+
name: String(a.name),
|
|
1310
|
+
kind: String(a.kind),
|
|
1311
|
+
namespace: String(a.namespace),
|
|
1312
|
+
})),
|
|
1313
|
+
now,
|
|
1314
|
+
);
|
|
1210
1315
|
}
|
|
1211
1316
|
if (name === "oabus_send_message") {
|
|
1212
1317
|
const to = String(args.to ?? "");
|
|
@@ -1257,6 +1362,7 @@ export default function oaBus(pi: Pi): void {
|
|
|
1257
1362
|
return stripTerminalControls(String(r.body));
|
|
1258
1363
|
}
|
|
1259
1364
|
if (name === "oabus_set_status") return statusTool(args, link);
|
|
1365
|
+
if (name === "oabus_propose_reach") return reachTool(args, link);
|
|
1260
1366
|
if (
|
|
1261
1367
|
name === "oabus_follow" ||
|
|
1262
1368
|
name === "oabus_unfollow" ||
|
|
@@ -1268,6 +1374,25 @@ export default function oaBus(pi: Pi): void {
|
|
|
1268
1374
|
return selfText((r.agent ?? null) as Json | null);
|
|
1269
1375
|
};
|
|
1270
1376
|
|
|
1377
|
+
/** propose_reach (#1346): the frame carries the namespaces only; the daemon knows the session. */
|
|
1378
|
+
const reachTool = async (args: Json, link: Link): Promise<string> => {
|
|
1379
|
+
const given = reachNamespacesOf(args.namespaces);
|
|
1380
|
+
if ("error" in given) throw new Error(given.error);
|
|
1381
|
+
const r = await link.request({
|
|
1382
|
+
type: "propose_reach",
|
|
1383
|
+
namespaces: given.namespaces,
|
|
1384
|
+
});
|
|
1385
|
+
if (r.type === "reach_proposed")
|
|
1386
|
+
return reachProposedText(
|
|
1387
|
+
given.namespaces,
|
|
1388
|
+
String(r.confirm_url),
|
|
1389
|
+
String(r.expires_at),
|
|
1390
|
+
);
|
|
1391
|
+
if (r.type === "error" && r.code === "bad_frame")
|
|
1392
|
+
throw new Error(REACH_OLD_DAEMON);
|
|
1393
|
+
return failed(r);
|
|
1394
|
+
};
|
|
1395
|
+
|
|
1271
1396
|
/** follow, unfollow and following (#1317). Refusals are the hub's or daemon's copy, as-is. */
|
|
1272
1397
|
const followTool = async (
|
|
1273
1398
|
name: string,
|
|
@@ -1288,7 +1413,11 @@ export default function oaBus(pi: Pi): void {
|
|
|
1288
1413
|
return followingText(
|
|
1289
1414
|
(r.follows ?? []) as { url: string; followed_at: string }[],
|
|
1290
1415
|
);
|
|
1291
|
-
if (
|
|
1416
|
+
if (
|
|
1417
|
+
r.type === "error" &&
|
|
1418
|
+
r.code === "bad_frame" &&
|
|
1419
|
+
!FOLLOW_DAEMON_BAD_FRAME.includes(String(r.message))
|
|
1420
|
+
)
|
|
1292
1421
|
throw new Error(FOLLOW_OLD_DAEMON);
|
|
1293
1422
|
return failed(r);
|
|
1294
1423
|
};
|
package/assets/oa_bus/bus.py
CHANGED
|
@@ -9,10 +9,11 @@ import os
|
|
|
9
9
|
import re
|
|
10
10
|
import sys
|
|
11
11
|
import threading
|
|
12
|
+
import unicodedata
|
|
12
13
|
|
|
13
14
|
from . import copy
|
|
14
15
|
from .link import Link, LinkError, retry_delay_s
|
|
15
|
-
from .roots import NotOnBus
|
|
16
|
+
from .roots import NotOnBus, hermes_session_title
|
|
16
17
|
from .sockpath import proc_start
|
|
17
18
|
from .wrap import wrap
|
|
18
19
|
|
|
@@ -22,14 +23,35 @@ SHOWN_MAX = 1000
|
|
|
22
23
|
SELF_TIMEOUT_S = 2.0
|
|
23
24
|
|
|
24
25
|
|
|
25
|
-
def
|
|
26
|
-
"""A
|
|
27
|
-
slug = re.sub(r"[^a-z0-9]+", "-", (
|
|
26
|
+
def slug_of(text, kind="hermes"):
|
|
27
|
+
"""A derived name (the directory) as a bus name: lowercase words joined by `-`; the kind when nothing is left."""
|
|
28
|
+
slug = re.sub(r"[^a-z0-9]+", "-", (text or "").lower())
|
|
28
29
|
slug = re.sub(r"^-+", "", slug)[:64]
|
|
29
30
|
slug = re.sub(r"-+$", "", slug)
|
|
30
31
|
return slug or kind
|
|
31
32
|
|
|
32
33
|
|
|
34
|
+
def name_of(title, kind="hermes"):
|
|
35
|
+
"""A session title as a bus name (#1704), as typed.
|
|
36
|
+
|
|
37
|
+
The same rules the pi adapter follows (#1703). Accents fold away. Letters,
|
|
38
|
+
digits, single spaces, `.` `_` `-` keep their place and case. A run of any
|
|
39
|
+
other character (controls included) becomes `-` only between two kept
|
|
40
|
+
non-space characters, and is dropped elsewhere. Starts with a letter or
|
|
41
|
+
digit, ends with a letter, digit, `_` or `-`, at most 64 characters (the
|
|
42
|
+
hub counts characters, and every kept one is ASCII); the kind when nothing
|
|
43
|
+
is left.
|
|
44
|
+
"""
|
|
45
|
+
t = unicodedata.normalize("NFKD", title or "")
|
|
46
|
+
t = "".join(c for c in t if not unicodedata.combining(c))
|
|
47
|
+
t = re.sub(r"([A-Za-z0-9._-])[^A-Za-z0-9 ._-]+(?=[A-Za-z0-9._-])", r"\1-", t)
|
|
48
|
+
t = re.sub(r"[^A-Za-z0-9 ._-]+", "", t)
|
|
49
|
+
t = re.sub(r" {2,}", " ", t)
|
|
50
|
+
t = re.sub(r"^[ ._-]+", "", t)[:64]
|
|
51
|
+
t = re.sub(r"[ .]+$", "", t)
|
|
52
|
+
return t or kind
|
|
53
|
+
|
|
54
|
+
|
|
33
55
|
def codex_app_server_active():
|
|
34
56
|
"""Whether Hermes hands turns to the codex app-server, which never carries plugin context.
|
|
35
57
|
|
|
@@ -66,13 +88,56 @@ def context_reaches_model(user_message, history):
|
|
|
66
88
|
return _is_gateway_wrapped(last["content"], user_message)
|
|
67
89
|
|
|
68
90
|
|
|
91
|
+
# gateway/run_turn_runner.py _prepare_turn_message prepends this, as an inline literal (Hermes
|
|
92
|
+
# has no constant for it), to the current message after an interrupted tool call.
|
|
93
|
+
_TOOL_TAIL_NOTE = (
|
|
94
|
+
"[System note: A new message has arrived. The conversation "
|
|
95
|
+
"history contains pending tool outputs from an interrupted turn. "
|
|
96
|
+
"IGNORE those pending results. Address the user's NEW message "
|
|
97
|
+
"below FIRST. Do NOT re-execute old tool calls from the history.]\n\n"
|
|
98
|
+
)
|
|
99
|
+
_NOTE_PROBE = "\0"
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _resume_note_prefixes():
|
|
103
|
+
"""Every exact prefix Hermes's own build_resume_recovery_note puts before a user message.
|
|
104
|
+
|
|
105
|
+
The note names the reason, so it is built for each phrase it has (restart, shutdown, and
|
|
106
|
+
the generic one) with a probe message and cut off at the probe. Empty when Hermes's
|
|
107
|
+
builder is missing or does not behave as expected, so nothing is recognised then.
|
|
108
|
+
"""
|
|
109
|
+
build = getattr(sys.modules.get("gateway.run"), "build_resume_recovery_note", None)
|
|
110
|
+
if not callable(build):
|
|
111
|
+
return []
|
|
112
|
+
prefixes = []
|
|
113
|
+
for reason in ("restart_timeout", "shutdown_timeout", None):
|
|
114
|
+
try:
|
|
115
|
+
full = build(reason, _NOTE_PROBE)
|
|
116
|
+
except Exception:
|
|
117
|
+
return []
|
|
118
|
+
tail = "\n\n" + _NOTE_PROBE
|
|
119
|
+
if not isinstance(full, str) or not full.startswith("[System note:") or not full.endswith(tail):
|
|
120
|
+
return []
|
|
121
|
+
prefixes.append(full[: -len(_NOTE_PROBE)])
|
|
122
|
+
return prefixes
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _strip_recovery_note(rest):
|
|
126
|
+
"""`rest` without one leading Hermes recovery note (resume or interrupted tool call), if it has one."""
|
|
127
|
+
for prefix in (*_resume_note_prefixes(), _TOOL_TAIL_NOTE):
|
|
128
|
+
if rest.startswith(prefix):
|
|
129
|
+
return rest[len(prefix) :]
|
|
130
|
+
return rest
|
|
131
|
+
|
|
132
|
+
|
|
69
133
|
def _is_gateway_wrapped(content, user_message):
|
|
70
134
|
"""Whether `content` is `user_message` as the Hermes gateway composes it.
|
|
71
135
|
|
|
72
136
|
The gateway may prepend a timestamp (gateway/message_timestamps.py, when
|
|
73
137
|
gateway.message_timestamps is on) and then, outside it, the Telegram observed group
|
|
74
|
-
context (gateway/run.py _wrap_current_message_with_observed_context)
|
|
75
|
-
|
|
138
|
+
context (gateway/run.py _wrap_current_message_with_observed_context), and between them
|
|
139
|
+
a recovery note after an interrupted turn (gateway/run_turn_runner.py). Only those exact
|
|
140
|
+
shapes count; any other prefix means the text is not the current turn's.
|
|
76
141
|
"""
|
|
77
142
|
if content == user_message:
|
|
78
143
|
return True
|
|
@@ -88,6 +153,9 @@ def _is_gateway_wrapped(content, user_message):
|
|
|
88
153
|
rest = rest[at + len(marker) :]
|
|
89
154
|
if rest == user_message:
|
|
90
155
|
return True
|
|
156
|
+
rest = _strip_recovery_note(rest)
|
|
157
|
+
if rest == user_message:
|
|
158
|
+
return True
|
|
91
159
|
if not user_message or not rest.endswith(user_message):
|
|
92
160
|
return False
|
|
93
161
|
prefix = rest[: -len(user_message)]
|
|
@@ -135,8 +203,10 @@ class Bus:
|
|
|
135
203
|
"""`inject` is ctx.inject_message; `connect` makes a Link (replaced in tests)."""
|
|
136
204
|
|
|
137
205
|
def __init__(self, roots, inject=None, connect=None, start=None, cwd=None, spawn=None,
|
|
138
|
-
current_session=None, codex_runtime=None, habits_marker=None):
|
|
206
|
+
current_session=None, codex_runtime=None, habits_marker=None, title_of=None):
|
|
139
207
|
self.roots = roots
|
|
208
|
+
# The user-set session title of a root, or None.
|
|
209
|
+
self._title_of = title_of or hermes_session_title
|
|
140
210
|
self._habits_marker = habits_marker or HABITS_MARKER
|
|
141
211
|
self._codex_runtime = codex_runtime or codex_app_server_active
|
|
142
212
|
self._inject = inject
|
|
@@ -164,7 +234,8 @@ class Bus:
|
|
|
164
234
|
return Link(
|
|
165
235
|
root.ref,
|
|
166
236
|
cwd,
|
|
167
|
-
|
|
237
|
+
# The user's own title as typed; else the directory, as before.
|
|
238
|
+
name_of(self._title_of(root.ref), slug_of(f"hermes-{base}" if base else None)),
|
|
168
239
|
self._start,
|
|
169
240
|
os.getpid(),
|
|
170
241
|
on_deliver,
|
package/assets/oa_bus/copy.py
CHANGED
|
@@ -357,6 +357,12 @@ def following_text(follows):
|
|
|
357
357
|
return "\n".join(f"{f['url']} (since {f['followed_at']})" for f in follows)
|
|
358
358
|
|
|
359
359
|
|
|
360
|
+
# The bad_frame answers a current daemon gives a follow call itself (@oa/bus-ipc FOLLOW_DAEMON_BAD_FRAME).
|
|
361
|
+
FOLLOW_DAEMON_BAD_FRAME = (
|
|
362
|
+
"follow is not supported on this connection",
|
|
363
|
+
"the frame is not valid on the hub wire",
|
|
364
|
+
)
|
|
365
|
+
|
|
360
366
|
FOLLOW_OLD_DAEMON = "This oa-bus daemon is too old to follow artifacts. Ask the user to update oa-bus."
|
|
361
367
|
|
|
362
368
|
|
|
@@ -477,6 +483,43 @@ def roster_line(a, now_ms):
|
|
|
477
483
|
return f"- {a['name']} ({display_kind(a['kind'])}, {a['namespace']}{where}){mark}{tail}"
|
|
478
484
|
|
|
479
485
|
|
|
486
|
+
def is_fallback_name(name, kind):
|
|
487
|
+
"""bus-protocol isFallbackName: a name only the harness gave the session."""
|
|
488
|
+
low = name.lower()
|
|
489
|
+
return low == kind or low.startswith(f"{kind}-") or low == "agent" or re.fullmatch(r"claude-\d+", low) is not None
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
def collapsed_away_line(n, listed):
|
|
493
|
+
more = " more" if listed else ""
|
|
494
|
+
return f"{n}{more} away {'session' if n == 1 else 'sessions'} with no chosen name (not listed, still reachable by name)"
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def roster_text(agents, now_ms):
|
|
498
|
+
"""bus-ipc rosterText: the list_agents text from the hub's roster rows."""
|
|
499
|
+
if not agents:
|
|
500
|
+
return "No agents in your namespace and linked ones."
|
|
501
|
+
lines = []
|
|
502
|
+
collapsed = 0
|
|
503
|
+
for a in agents:
|
|
504
|
+
away = a.get("state") == "away"
|
|
505
|
+
if away and is_fallback_name(a["name"], a["kind"]):
|
|
506
|
+
collapsed += 1
|
|
507
|
+
continue
|
|
508
|
+
lines.append(
|
|
509
|
+
roster_line(
|
|
510
|
+
{
|
|
511
|
+
**a,
|
|
512
|
+
"queued": (a.get("state") or ("live" if a.get("live") else "queued")) == "queued",
|
|
513
|
+
"away": str(a.get("since", "")) if away else None,
|
|
514
|
+
},
|
|
515
|
+
now_ms,
|
|
516
|
+
)
|
|
517
|
+
)
|
|
518
|
+
if collapsed:
|
|
519
|
+
lines.append(collapsed_away_line(collapsed, len(lines) > 0))
|
|
520
|
+
return "\n".join(lines)
|
|
521
|
+
|
|
522
|
+
|
|
480
523
|
def self_text(agent):
|
|
481
524
|
if not agent:
|
|
482
525
|
return "null"
|
package/assets/oa_bus/roots.py
CHANGED
|
@@ -53,6 +53,32 @@ def hermes_lineage_root(session_id):
|
|
|
53
53
|
return lineage[0] if lineage and session_id in lineage else None
|
|
54
54
|
|
|
55
55
|
|
|
56
|
+
def hermes_session_title(root_ref, db=None):
|
|
57
|
+
"""The title the user set on this conversation (/title), or None.
|
|
58
|
+
|
|
59
|
+
Hermes's public SessionDB.get_session_title and get_session_title_source,
|
|
60
|
+
on the same read-only handle as the lineage lookup. Automatic titles
|
|
61
|
+
(source "derived" or "llm") are not the user's and give None. Any failure
|
|
62
|
+
is None: the link then keeps the directory name.
|
|
63
|
+
"""
|
|
64
|
+
try:
|
|
65
|
+
if db is None:
|
|
66
|
+
from hermes_constants import get_hermes_home
|
|
67
|
+
from hermes_state import SessionDB
|
|
68
|
+
|
|
69
|
+
path = get_hermes_home() / "state.db"
|
|
70
|
+
if not path.exists():
|
|
71
|
+
return None
|
|
72
|
+
db = _dbs.get(path)
|
|
73
|
+
if db is None:
|
|
74
|
+
db = _dbs[path] = SessionDB(path, read_only=True)
|
|
75
|
+
if db.get_session_title_source(root_ref) != "user":
|
|
76
|
+
return None
|
|
77
|
+
return db.get_session_title(root_ref) or None
|
|
78
|
+
except Exception:
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
|
|
56
82
|
class Roots:
|
|
57
83
|
def __init__(self, lineage_root=hermes_lineage_root):
|
|
58
84
|
self._lineage_root = lineage_root
|
package/assets/oa_bus/tools.py
CHANGED
|
@@ -120,21 +120,7 @@ def run(name, args, link):
|
|
|
120
120
|
r = link.request({"type": "list"})
|
|
121
121
|
if r["type"] != "roster":
|
|
122
122
|
_failed(r)
|
|
123
|
-
|
|
124
|
-
if not agents:
|
|
125
|
-
return "No agents in your namespace and linked ones."
|
|
126
|
-
now = int(time.time() * 1000)
|
|
127
|
-
return "\n".join(
|
|
128
|
-
copy.roster_line(
|
|
129
|
-
{
|
|
130
|
-
**a,
|
|
131
|
-
"queued": (a.get("state") or ("live" if a.get("live") else "queued")) == "queued",
|
|
132
|
-
"away": str(a.get("since", "")) if a.get("state") == "away" else None,
|
|
133
|
-
},
|
|
134
|
-
now,
|
|
135
|
-
)
|
|
136
|
-
for a in agents
|
|
137
|
-
)
|
|
123
|
+
return copy.roster_text(r.get("agents", []), int(time.time() * 1000))
|
|
138
124
|
if name == "oabus_send_message":
|
|
139
125
|
to = str(args.get("to") or "")
|
|
140
126
|
body = str(args.get("text") or "")
|
|
@@ -200,7 +186,7 @@ def _follow(name, args, link):
|
|
|
200
186
|
return copy.unfollow_text(r["removed"] is True, artifact)
|
|
201
187
|
if r["type"] == "follows":
|
|
202
188
|
return copy.following_text(r["follows"])
|
|
203
|
-
if r["type"] == "error" and r.get("code") == "bad_frame":
|
|
189
|
+
if r["type"] == "error" and r.get("code") == "bad_frame" and r.get("message") not in copy.FOLLOW_DAEMON_BAD_FRAME:
|
|
204
190
|
raise ToolError(copy.FOLLOW_OLD_DAEMON)
|
|
205
191
|
_failed(r)
|
|
206
192
|
|