@open-artifacts/bus 0.133.0 → 0.135.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 +67 -9
- package/assets/oa_bus/bus.py +47 -3
- package/dist/index.js +1520 -808
- 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.135.0";
|
|
15
15
|
|
|
16
16
|
type Frame = Json & { type: string; id: string };
|
|
17
17
|
type Ctx = {
|
|
@@ -733,15 +733,27 @@ function procStart(): string | undefined {
|
|
|
733
733
|
}
|
|
734
734
|
}
|
|
735
735
|
|
|
736
|
-
/**
|
|
736
|
+
/**
|
|
737
|
+
* A session name as typed (#1635), made a valid bus name the way the hub
|
|
738
|
+
* (BusNameSchema) wants one. Accents fold away (NFKD, combining marks
|
|
739
|
+
* dropped). Letters, digits, single spaces, `.` `_` `-` keep their place and
|
|
740
|
+
* case. A run of any other character becomes `-` only between two kept
|
|
741
|
+
* non-space characters (`docs/readme` gives `docs-readme`); elsewhere it is
|
|
742
|
+
* dropped. Starts with a letter or digit, ends with a letter, digit, `_` or
|
|
743
|
+
* `-`, at most 64 characters; the kind when nothing is left. The hub would
|
|
744
|
+
* turn a name with any other character into `agent-N`.
|
|
745
|
+
*/
|
|
737
746
|
function nameOf(title: string | undefined, kind: string): string {
|
|
738
|
-
const
|
|
739
|
-
.
|
|
740
|
-
.replace(/[
|
|
741
|
-
.replace(
|
|
747
|
+
const cut = (title ?? "")
|
|
748
|
+
.normalize("NFKD")
|
|
749
|
+
.replace(/[\u0300-\u036f]/g, "")
|
|
750
|
+
.replace(/([A-Za-z0-9._-])[^A-Za-z0-9 ._-]+(?=[A-Za-z0-9._-])/g, "$1-")
|
|
751
|
+
.replace(/[^A-Za-z0-9 ._-]+/g, "")
|
|
752
|
+
.replace(/ {2,}/g, " ")
|
|
753
|
+
.replace(/^[ ._-]+/, "")
|
|
742
754
|
.slice(0, 64)
|
|
743
|
-
.replace(
|
|
744
|
-
return
|
|
755
|
+
.replace(/[ .]+$/, "");
|
|
756
|
+
return cut || kind;
|
|
745
757
|
}
|
|
746
758
|
|
|
747
759
|
type Identity = { ref: string; cwd: string; name: string; kind: "pi" | "omp" };
|
|
@@ -750,6 +762,8 @@ type Link = {
|
|
|
750
762
|
welcome: Frame;
|
|
751
763
|
request: (frame: Json, timeoutMs?: number) => Promise<Frame>;
|
|
752
764
|
ack: (msgId: string) => void;
|
|
765
|
+
/** #1635: tell the daemon the session's new name; false when this daemon does not take it. */
|
|
766
|
+
rename: (name: string) => boolean;
|
|
753
767
|
closed: () => boolean;
|
|
754
768
|
close: () => void;
|
|
755
769
|
};
|
|
@@ -809,6 +823,14 @@ function open(
|
|
|
809
823
|
}),
|
|
810
824
|
// Fire-and-forget: the daemon answers an ack with nothing.
|
|
811
825
|
ack: (msgId) => write({ type: "ack", id: `ack-${++seq}`, msg_id: msgId }),
|
|
826
|
+
// Only to a daemon whose welcome listed `rename`: an older one has no such frame.
|
|
827
|
+
rename: (name) => {
|
|
828
|
+
const caps = link.welcome.caps;
|
|
829
|
+
if (ended || !Array.isArray(caps) || !caps.includes("rename"))
|
|
830
|
+
return false;
|
|
831
|
+
write({ type: "rename", id: `rename-${++seq}`, name });
|
|
832
|
+
return true;
|
|
833
|
+
},
|
|
812
834
|
closed: () => ended,
|
|
813
835
|
close: () => {
|
|
814
836
|
ended = true;
|
|
@@ -892,7 +914,8 @@ function open(
|
|
|
892
914
|
proposed_name: id.name,
|
|
893
915
|
// #1295: this asset decodes away rows and the new refusals.
|
|
894
916
|
// #1525: and a config file that is pending approval.
|
|
895
|
-
|
|
917
|
+
// #1635: and may send a rename.
|
|
918
|
+
caps: ["mailbox", "pending", "rename"],
|
|
896
919
|
attest: start ? { proc_start: start } : {},
|
|
897
920
|
}),
|
|
898
921
|
);
|
|
@@ -1015,6 +1038,13 @@ export default function oaBus(pi: Pi): void {
|
|
|
1015
1038
|
}
|
|
1016
1039
|
current = l;
|
|
1017
1040
|
refusals = 0;
|
|
1041
|
+
// Renamed while this hello was in flight (#1635).
|
|
1042
|
+
if (
|
|
1043
|
+
identity.kind !== "omp" &&
|
|
1044
|
+
identity.name !== id.name &&
|
|
1045
|
+
identity.name !== identity.kind
|
|
1046
|
+
)
|
|
1047
|
+
l.rename(identity.name);
|
|
1018
1048
|
return l;
|
|
1019
1049
|
},
|
|
1020
1050
|
(e: unknown) => {
|
|
@@ -1043,6 +1073,34 @@ export default function oaBus(pi: Pi): void {
|
|
|
1043
1073
|
*/
|
|
1044
1074
|
const subagent = (ctx: Ctx | undefined) => ctx?.agent?.kind === "sub";
|
|
1045
1075
|
|
|
1076
|
+
/**
|
|
1077
|
+
* #1635: the session was renamed (/name, --name, setSessionName). One frame
|
|
1078
|
+
* per change; nothing for the fallback name. The identity carries the name,
|
|
1079
|
+
* so a reconnect's hello proposes the new one.
|
|
1080
|
+
*/
|
|
1081
|
+
const renamed = (ctx: Ctx) => {
|
|
1082
|
+
if (stopped || !identity) return;
|
|
1083
|
+
// omp titles a session itself ("auto") after its first message, and its
|
|
1084
|
+
// extension context does not say whether a name was typed by the user:
|
|
1085
|
+
// so omp never renames on the hub. (pi has no auto titles.)
|
|
1086
|
+
if (identity.kind === "omp") return;
|
|
1087
|
+
const id = identityOf(ctx);
|
|
1088
|
+
if (id.ref !== identity.ref || id.name === identity.name) return;
|
|
1089
|
+
identity = { ...identity, name: id.name };
|
|
1090
|
+
if (id.name === id.kind) return;
|
|
1091
|
+
// An open link tells the daemon now; a daemon without the cap, or no
|
|
1092
|
+
// link, learns it from the next hello.
|
|
1093
|
+
if (current && !current.closed() && current.ref === id.ref)
|
|
1094
|
+
current.rename(id.name);
|
|
1095
|
+
};
|
|
1096
|
+
pi.on("session_info_changed", (_event, ctx) => {
|
|
1097
|
+
if (!subagent(ctx)) renamed(ctx);
|
|
1098
|
+
});
|
|
1099
|
+
// A turn start checks too (cheap when unchanged); omp is skipped in renamed().
|
|
1100
|
+
pi.on("turn_start", (_event, ctx) => {
|
|
1101
|
+
if (!subagent(ctx)) renamed(ctx);
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1046
1104
|
pi.on("session_start", async (_event, ctx) => {
|
|
1047
1105
|
if (subagent(ctx)) return;
|
|
1048
1106
|
stopped = false;
|
package/assets/oa_bus/bus.py
CHANGED
|
@@ -7,6 +7,7 @@ queued.
|
|
|
7
7
|
|
|
8
8
|
import os
|
|
9
9
|
import re
|
|
10
|
+
import sys
|
|
10
11
|
import threading
|
|
11
12
|
|
|
12
13
|
from . import copy
|
|
@@ -37,9 +38,11 @@ def codex_app_server_active():
|
|
|
37
38
|
"""
|
|
38
39
|
try:
|
|
39
40
|
from hermes_cli.codex_runtime_switch import get_current_runtime
|
|
40
|
-
from hermes_cli
|
|
41
|
+
from hermes_cli import config
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
# Read-only callers skip the defensive deepcopy; older Hermes has only load_config.
|
|
44
|
+
load = getattr(config, "load_config_readonly", None) or config.load_config
|
|
45
|
+
return get_current_runtime(load()) == "codex_app_server"
|
|
43
46
|
except Exception:
|
|
44
47
|
return None
|
|
45
48
|
|
|
@@ -58,7 +61,48 @@ def context_reaches_model(user_message, history):
|
|
|
58
61
|
last = next((m for m in reversed(history) if isinstance(m, dict) and m.get("role") == "user"), None)
|
|
59
62
|
# Equal text: a voice turn's API-facing content differs from its clean text, and a
|
|
60
63
|
# message appended after the current one by compaction would differ too.
|
|
61
|
-
|
|
64
|
+
if last is None or not isinstance(last.get("content"), str):
|
|
65
|
+
return False
|
|
66
|
+
return _is_gateway_wrapped(last["content"], user_message)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _is_gateway_wrapped(content, user_message):
|
|
70
|
+
"""Whether `content` is `user_message` as the Hermes gateway composes it.
|
|
71
|
+
|
|
72
|
+
The gateway may prepend a timestamp (gateway/message_timestamps.py, when
|
|
73
|
+
gateway.message_timestamps is on) and then, outside it, the Telegram observed group
|
|
74
|
+
context (gateway/run.py _wrap_current_message_with_observed_context). Only those two
|
|
75
|
+
exact shapes count; any other prefix means the text is not the current turn's.
|
|
76
|
+
"""
|
|
77
|
+
if content == user_message:
|
|
78
|
+
return True
|
|
79
|
+
rest = content
|
|
80
|
+
run = sys.modules.get("gateway.run") # already loaded in a gateway process; never import it
|
|
81
|
+
obs = getattr(run, "_OBSERVED_GROUP_CONTEXT_HEADER", None)
|
|
82
|
+
cur = getattr(run, "_CURRENT_ADDRESSED_MESSAGE_HEADER", None)
|
|
83
|
+
if isinstance(obs, str) and isinstance(cur, str) and obs and cur and rest.startswith(obs + "\n"):
|
|
84
|
+
marker = "\n\n" + cur + "\n"
|
|
85
|
+
at = rest.find(marker, len(obs))
|
|
86
|
+
if at < 0:
|
|
87
|
+
return False
|
|
88
|
+
rest = rest[at + len(marker) :]
|
|
89
|
+
if rest == user_message:
|
|
90
|
+
return True
|
|
91
|
+
if not user_message or not rest.endswith(user_message):
|
|
92
|
+
return False
|
|
93
|
+
prefix = rest[: -len(user_message)]
|
|
94
|
+
if not prefix:
|
|
95
|
+
return True
|
|
96
|
+
# The gateway loads it for every text message before the turn runs; never import it here
|
|
97
|
+
# (this runs under the plugin's lock).
|
|
98
|
+
strip = getattr(sys.modules.get("gateway.message_timestamps"), "strip_leading_message_timestamps", None)
|
|
99
|
+
if not callable(strip):
|
|
100
|
+
return False
|
|
101
|
+
try:
|
|
102
|
+
# The prefix must be nothing but gateway timestamps.
|
|
103
|
+
return strip(prefix + "\0")[0] == "\0"
|
|
104
|
+
except Exception:
|
|
105
|
+
return False
|
|
62
106
|
|
|
63
107
|
|
|
64
108
|
# Hermes has no always-on instruction file for the bus, so these two lines ride in the turn's
|