agentschat-mcp 0.36.24 → 0.36.26
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/CHANGELOG.md +12 -0
- package/README.md +8 -0
- package/codex/README.md +1 -1
- package/codex/app-server.ts +79 -22
- package/codex/bots-config.ts +31 -11
- package/codex/bridge.ts +123 -25
- package/codex/config.ts +128 -21
- package/codex/gui-channel.ts +66 -9
- package/codex/inbox-sync.ts +65 -12
- package/codex/loop-grants.ts +41 -11
- package/codex/manager.ts +101 -25
- package/codex/owner.ts +81 -9
- package/codex/processes.ts +51 -7
- package/codex/run.ts +70 -17
- package/codex/runtime-home.ts +41 -11
- package/codex/thread-history.ts +77 -30
- package/codex/transport.ts +122 -19
- package/connector/auth.ts +57 -5
- package/connector/backfill.ts +92 -10
- package/connector/descriptor.ts +27 -1
- package/connector/identities.ts +82 -14
- package/connector/ingest.ts +11 -2
- package/connector/normalize.ts +32 -12
- package/connector/run.ts +314 -67
- package/connector/server.ts +95 -26
- package/dist/codex-bots.js +410 -73
- package/dist/codex-bridge.js +1996 -576
- package/dist/connector.js +1286 -493
- package/dist/dsh.js +1776 -299
- package/dist/muse.js +967 -221
- package/dist/server.js +7645 -1172
- package/dsh/client.js +7 -5
- package/dsh/identity-ui/client.js +7 -5
- package/dsh/identity-ui/index.js +43 -8
- package/dsh/inbound-bridge/index.js +595 -146
- package/dsh/src/cli.ts +430 -91
- package/dsh/src/patch.ts +295 -15
- package/dsh/tests/dsh-hardening-127.test.ts +207 -0
- package/dsh/tests/dsh.test.ts +990 -3
- package/muse/scripts/ensure-muse-wakes.mjs +5 -3
- package/muse/scripts/muse-wake-receiver.mjs +4 -1
- package/muse/src/bridge.ts +54 -13
- package/muse/src/cli.ts +226 -41
- package/muse/src/client.ts +249 -34
- package/muse/src/config.ts +128 -12
- package/muse/src/policy.ts +28 -8
- package/muse/src/types.ts +1 -0
- package/muse/src/typing.ts +18 -1
- package/muse/src/wake.ts +237 -35
- package/muse/tests/bridge.test.mjs +131 -0
- package/muse/tests/client.test.mjs +327 -0
- package/muse/tests/config.test.mjs +78 -1
- package/muse/tests/hardening.test.mjs +199 -0
- package/muse/tests/hardening126.test.mjs +292 -0
- package/muse/tests/policy.test.mjs +83 -1
- package/muse/tests/wake.test.mjs +134 -6
- package/package.json +3 -3
- package/scripts/ensure-grok-wakes.mjs +93 -8
- package/scripts/example-url-wake-receiver.mjs +254 -61
- package/scripts/grok-bind-register.sh +38 -8
- package/skills/agentschat-team-lead/SKILL.md +1 -1
- package/skills/onboarding.md +14 -10
- package/src/argcheck.ts +1890 -1
- package/src/cli.mjs +98 -14
- package/src/dedup.ts +57 -8
- package/src/grok-bind.ts +160 -33
- package/src/heartbeat.ts +39 -11
- package/src/identity-guard.ts +93 -20
- package/src/identity.ts +67 -11
- package/src/mentions.ts +26 -5
- package/src/onboarding-status.ts +134 -11
- package/src/profile-selection.ts +269 -18
- package/src/profile-store.ts +222 -28
- package/src/read-cursor.ts +256 -9
- package/src/reconnect.ts +98 -2
- package/src/redact.ts +34 -15
- package/src/rest-cli.ts +713 -159
- package/src/server.ts +2487 -342
- package/src/session-bind.ts +731 -132
- package/src/session-route.ts +183 -12
- package/src/team-lead-skill.ts +3 -0
- package/src/timestamps.ts +56 -23
- package/src/tool-annotations.ts +22 -1
- package/src/wake.ts +524 -90
package/connector/identities.ts
CHANGED
|
@@ -35,21 +35,83 @@ export interface Identity {
|
|
|
35
35
|
profile?: string;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const GATEWAY_PROTO_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
39
|
+
const IDENTITY_PROTO_KEYS = new Set([
|
|
40
|
+
"prototype",
|
|
41
|
+
...Object.getOwnPropertyNames(Object.prototype).map((k) => k.toLowerCase()),
|
|
42
|
+
]);
|
|
43
|
+
const IDENTITY_CTRL_RE = /[\x00-\x1f\x7f-\x9f\u2028\u2029]/;
|
|
44
|
+
|
|
45
|
+
export function validIdentityId(value: unknown): value is string {
|
|
46
|
+
return typeof value === "string" && value.length > 0 && value.length <= 128 && value !== "." && value !== ".." &&
|
|
47
|
+
!value.includes("..") && !/(?:%2f|%5c|%00|%2e%2e)/i.test(value) &&
|
|
48
|
+
!/[/\\\s\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(value) &&
|
|
49
|
+
!IDENTITY_PROTO_KEYS.has(value.toLowerCase());
|
|
50
|
+
}
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
function validOptionalProfile(profile: unknown): boolean {
|
|
53
|
+
if (profile === undefined) return true;
|
|
54
|
+
if (typeof profile !== "string" || IDENTITY_CTRL_RE.test(profile)) return false;
|
|
55
|
+
const trimmed = profile.trim();
|
|
56
|
+
return (
|
|
57
|
+
trimmed.length > 0 &&
|
|
58
|
+
trimmed.length <= 128 &&
|
|
59
|
+
trimmed !== "." &&
|
|
60
|
+
!trimmed.includes("..") &&
|
|
61
|
+
!/[/\\]/.test(trimmed) &&
|
|
62
|
+
!/(?:%2f|%5c|%00|%2e%2e)/i.test(trimmed) &&
|
|
63
|
+
!IDENTITY_PROTO_KEYS.has(trimmed.toLowerCase())
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Validate the whole candidate set before exposing any credentials or replacing state. */
|
|
68
|
+
function validateIdentities(identities: readonly Identity[], allowEmptyCredentials = false): void {
|
|
69
|
+
const bots = new Set<string>();
|
|
70
|
+
const agents = new Set<string>();
|
|
71
|
+
for (const id of identities) {
|
|
72
|
+
if (!id || !validIdentityId(id.botId) || !validIdentityId(id.agentId)) {
|
|
73
|
+
throw new Error("invalid identity botId or agentId");
|
|
74
|
+
}
|
|
75
|
+
if ([id.token, id.gatewayId, id.secret].some(value =>
|
|
76
|
+
typeof value !== "string" || (!value.trim() && !(allowEmptyCredentials && value === "")))) {
|
|
77
|
+
throw new Error("missing identity credentials");
|
|
78
|
+
}
|
|
79
|
+
if (!allowEmptyCredentials) {
|
|
80
|
+
if (
|
|
81
|
+
IDENTITY_CTRL_RE.test(id.gatewayId) ||
|
|
82
|
+
id.gatewayId.length > 256 ||
|
|
83
|
+
GATEWAY_PROTO_KEYS.has(id.gatewayId.trim().toLowerCase())
|
|
84
|
+
) {
|
|
85
|
+
throw new Error("invalid identity gatewayId");
|
|
86
|
+
}
|
|
87
|
+
if (IDENTITY_CTRL_RE.test(id.token) || IDENTITY_CTRL_RE.test(id.secret)) {
|
|
88
|
+
throw new Error("invalid identity credentials");
|
|
45
89
|
}
|
|
46
|
-
this.byBot.set(id.botId, id);
|
|
47
90
|
}
|
|
91
|
+
if (!validOptionalProfile(id.profile)) {
|
|
92
|
+
throw new Error("invalid identity profile");
|
|
93
|
+
}
|
|
94
|
+
if (bots.has(id.botId.trim()) || agents.has(id.agentId.trim())) {
|
|
95
|
+
throw new Error("duplicate identity botId or agentId — ambiguous routing");
|
|
96
|
+
}
|
|
97
|
+
bots.add(id.botId.trim());
|
|
98
|
+
agents.add(id.agentId.trim());
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export class IdentityTable {
|
|
103
|
+
private readonly byBot = new Map<string, Identity>();
|
|
104
|
+
|
|
105
|
+
constructor(identities: Identity[], opts?: { allowEmptyCredentials?: boolean }) {
|
|
106
|
+
// Legacy embedding uses an empty-credential placeholder only at construction.
|
|
107
|
+
// Replacements and platform credential lookups always retain strict validation.
|
|
108
|
+
validateIdentities(identities, opts?.allowEmptyCredentials === true);
|
|
109
|
+
this.install(identities);
|
|
48
110
|
}
|
|
49
111
|
|
|
50
112
|
/** The identity fronting `botId`, or null when unregistered (fail closed). */
|
|
51
113
|
forBot(botId: string): Identity | null {
|
|
52
|
-
return this.byBot.get(botId) ?? null;
|
|
114
|
+
return validIdentityId(botId) ? this.byBot.get(botId) ?? null : null;
|
|
53
115
|
}
|
|
54
116
|
|
|
55
117
|
isSingle(): boolean {
|
|
@@ -69,12 +131,17 @@ export class IdentityTable {
|
|
|
69
131
|
* duplicate botIds the same way the constructor does.
|
|
70
132
|
*/
|
|
71
133
|
replace(identities: Identity[]): void {
|
|
134
|
+
validateIdentities(identities);
|
|
135
|
+
this.install(identities);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private install(identities: Identity[]): void {
|
|
72
139
|
const next = new Map<string, Identity>();
|
|
73
140
|
for (const id of identities) {
|
|
74
141
|
if (next.has(id.botId)) {
|
|
75
142
|
throw new Error(`duplicate identity botId "${id.botId}" — ambiguous routing`);
|
|
76
143
|
}
|
|
77
|
-
next.set(id.botId, id);
|
|
144
|
+
next.set(id.botId, Object.freeze({ ...id }));
|
|
78
145
|
}
|
|
79
146
|
this.byBot.clear();
|
|
80
147
|
for (const [k, v] of next) this.byBot.set(k, v);
|
|
@@ -83,7 +150,8 @@ export class IdentityTable {
|
|
|
83
150
|
|
|
84
151
|
/** Platform hooks must never substitute another identity's credentials. */
|
|
85
152
|
export function requireIdentity(identities: readonly Identity[], botId: string): Identity {
|
|
86
|
-
|
|
153
|
+
validateIdentities(identities);
|
|
154
|
+
const id = validIdentityId(botId) ? identities.find(id => id.botId === botId) : undefined;
|
|
87
155
|
if (!id) throw new Error(`unknown identity: ${botId}`);
|
|
88
156
|
return id;
|
|
89
157
|
}
|
|
@@ -121,7 +189,7 @@ function matchesExactMention(content: string, id: string): boolean {
|
|
|
121
189
|
|
|
122
190
|
/** All exact addressed targets, once each, in identity-table order. */
|
|
123
191
|
export function routeInboundTargets(table: IdentityTable, ctx: InboundContext): Identity[] {
|
|
124
|
-
if (ctx.channel_id
|
|
192
|
+
if (/^dm[-:]/i.test(ctx.channel_id ?? "")) {
|
|
125
193
|
const owner = ctx.dmOwnerBotId ? table.forBot(ctx.dmOwnerBotId) : null;
|
|
126
194
|
return owner ? [owner] : [];
|
|
127
195
|
}
|
|
@@ -132,7 +200,7 @@ export function routeInboundTargets(table: IdentityTable, ctx: InboundContext):
|
|
|
132
200
|
|
|
133
201
|
export function routeInbound(table: IdentityTable, ctx: InboundContext): Identity | null {
|
|
134
202
|
// DM: route to the identity that owns the DM channel.
|
|
135
|
-
if (ctx.channel_id
|
|
203
|
+
if (/^dm[-:]/i.test(ctx.channel_id ?? "")) {
|
|
136
204
|
return ctx.dmOwnerBotId ? table.forBot(ctx.dmOwnerBotId) : null;
|
|
137
205
|
}
|
|
138
206
|
// Group/channel: an explicit mentioned_ids annotation wins when present.
|
|
@@ -179,7 +247,7 @@ export function resolveOutbound(table: IdentityTable, botId: string): Identity |
|
|
|
179
247
|
*/
|
|
180
248
|
export function hermesSourceProfile(id: Identity, frontedCount: number): string | undefined {
|
|
181
249
|
const named = typeof id.profile === "string" ? id.profile.trim() : "";
|
|
182
|
-
if (named) return named;
|
|
183
|
-
if (frontedCount > 1) return id.botId;
|
|
250
|
+
if (named && validOptionalProfile(id.profile)) return named;
|
|
251
|
+
if (frontedCount > 1 && validIdentityId(id.botId)) return id.botId;
|
|
184
252
|
return undefined;
|
|
185
253
|
}
|
package/connector/ingest.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MessageDedup, messageDedupKey } from "../src/dedup.ts";
|
|
2
|
+
import { canonicalCursorTimestamp } from "./backfill.ts";
|
|
2
3
|
import { serverLoopTick, type AgentsChatMessage } from "./normalize.ts";
|
|
3
4
|
|
|
4
5
|
export type IngestIdentity = { botId: string; agentId: string };
|
|
@@ -24,11 +25,19 @@ export function ingestAgentsChatFrame(
|
|
|
24
25
|
dedup: MessageDedup;
|
|
25
26
|
},
|
|
26
27
|
): boolean {
|
|
27
|
-
if (
|
|
28
|
+
if (
|
|
29
|
+
!frame ||
|
|
30
|
+
typeof frame !== "object" ||
|
|
31
|
+
Array.isArray(frame) ||
|
|
32
|
+
Object.prototype.hasOwnProperty.call(frame, "__proto__")
|
|
33
|
+
) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (frame.content !== "__typing__" && canonicalCursorTimestamp(frame.timestamp) !== null) {
|
|
28
37
|
deps.advanceCursor(id, frame.channel_id, frame.timestamp);
|
|
29
38
|
}
|
|
30
39
|
const key = messageDedupKey(frame as { id?: string; channel_id?: string });
|
|
31
|
-
const isDm = frame.channel_id
|
|
40
|
+
const isDm = typeof frame.channel_id === "string" && /^dm[-:]/i.test(frame.channel_id);
|
|
32
41
|
const scopedKey = key && (isDm ? JSON.stringify([id.botId, frame.channel_id, frame.id]) : key);
|
|
33
42
|
if (scopedKey && deps.dedup.recordOrSkip(scopedKey)) return false;
|
|
34
43
|
// Group fanout must filter self per TARGET, not per arrival socket: A can
|
package/connector/normalize.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface AgentsChatMessage {
|
|
|
24
24
|
content?: string;
|
|
25
25
|
timestamp?: string;
|
|
26
26
|
reply_to?: string;
|
|
27
|
+
parent_id?: string;
|
|
27
28
|
mentions?: string[];
|
|
28
29
|
sender_type?: string;
|
|
29
30
|
content_type?: string;
|
|
@@ -60,26 +61,29 @@ export interface WireEvent {
|
|
|
60
61
|
* not become an agent turn (typing placeholder, or no channel to key a session on).
|
|
61
62
|
*/
|
|
62
63
|
export function toWireEvent(msg: AgentsChatMessage, platform = "agentschat"): WireEvent | null {
|
|
63
|
-
|
|
64
|
+
if (!msg || typeof msg !== "object") return null;
|
|
65
|
+
const content = typeof msg.content === "string" ? msg.content : "";
|
|
64
66
|
if (content === "__typing__") return null;
|
|
65
67
|
|
|
66
|
-
const
|
|
68
|
+
const metadata = (value: string | undefined) =>
|
|
69
|
+
typeof value === "string" ? value.replace(/[\x00-\x1f\x7f-\x9f\u2028\u2029]/g, "") : undefined;
|
|
70
|
+
const chatId = metadata(msg.channel_id) ?? "";
|
|
67
71
|
if (!chatId) return null;
|
|
68
72
|
|
|
69
|
-
const isDm =
|
|
73
|
+
const isDm = /^dm[-:]/i.test(chatId);
|
|
70
74
|
|
|
71
75
|
return {
|
|
72
76
|
text: content,
|
|
73
77
|
message_type: "text",
|
|
74
|
-
message_id: msg.id,
|
|
75
|
-
reply_to_message_id: msg.reply_to,
|
|
78
|
+
message_id: metadata(msg.id),
|
|
79
|
+
reply_to_message_id: metadata(msg.reply_to ?? msg.parent_id),
|
|
76
80
|
source: {
|
|
77
81
|
platform,
|
|
78
82
|
chat_id: chatId,
|
|
79
83
|
chat_type: isDm ? "dm" : "group",
|
|
80
|
-
chat_name:
|
|
81
|
-
user_id: msg.sender_id,
|
|
82
|
-
user_name: msg.sender_name ?? msg.sender_id,
|
|
84
|
+
chat_name: chatId,
|
|
85
|
+
user_id: metadata(msg.sender_id),
|
|
86
|
+
user_name: metadata(msg.sender_name ?? msg.sender_id),
|
|
83
87
|
thread_id: null,
|
|
84
88
|
// scope_id intentionally omitted: agentschat has no guild/scope concept.
|
|
85
89
|
},
|
|
@@ -96,12 +100,25 @@ export interface ServerLoopTick {
|
|
|
96
100
|
expires_at: null;
|
|
97
101
|
}
|
|
98
102
|
|
|
103
|
+
const LOOP_TICK_CTRL_RE = /[\x00-\x1f\x7f-\x9f\u2028\u2029]/;
|
|
104
|
+
|
|
105
|
+
function hasOwnProto(value: unknown): boolean {
|
|
106
|
+
return Boolean(
|
|
107
|
+
value &&
|
|
108
|
+
typeof value === "object" &&
|
|
109
|
+
Object.prototype.hasOwnProperty.call(value, "__proto__"),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
99
113
|
/** Shape check only. Delivery must additionally verify the bot's live server record. */
|
|
100
114
|
export function serverLoopTick(msg: AgentsChatMessage): ServerLoopTick | null {
|
|
115
|
+
if (!msg || typeof msg !== "object" || hasOwnProto(msg)) return null;
|
|
101
116
|
const meta = msg.meta as Partial<ServerLoopTick> | undefined;
|
|
102
|
-
if (!meta || meta.kind !== "loop_tick" ||
|
|
103
|
-
typeof msg.id !== "string" || !msg.id ||
|
|
104
|
-
typeof msg.
|
|
117
|
+
if (!meta || typeof meta !== "object" || Array.isArray(meta) || hasOwnProto(meta) || meta.kind !== "loop_tick" ||
|
|
118
|
+
typeof msg.id !== "string" || !msg.id || LOOP_TICK_CTRL_RE.test(msg.id) ||
|
|
119
|
+
typeof msg.channel_id !== "string" || !msg.channel_id || LOOP_TICK_CTRL_RE.test(msg.channel_id) ||
|
|
120
|
+
typeof msg.sender_id !== "string" || !msg.sender_id || LOOP_TICK_CTRL_RE.test(msg.sender_id) ||
|
|
121
|
+
msg.sender_type !== "agent" || msg.content_type !== "text" ||
|
|
105
122
|
typeof msg.timestamp !== "string" || !Number.isFinite(Date.parse(msg.timestamp)) ||
|
|
106
123
|
typeof meta.loop_id !== "string" || !/^loop_[a-zA-Z0-9_-]+$/.test(meta.loop_id) ||
|
|
107
124
|
typeof meta.prompt !== "string" || !meta.prompt.trim() || meta.prompt.length > 4000 ||
|
|
@@ -115,9 +132,12 @@ export function serverLoopTick(msg: AgentsChatMessage): ServerLoopTick | null {
|
|
|
115
132
|
export function matchesLiveLoop(msg: AgentsChatMessage, agentId: string, response: unknown): boolean {
|
|
116
133
|
const tick = serverLoopTick(msg);
|
|
117
134
|
if (!tick || msg.sender_id !== agentId) return false;
|
|
135
|
+
if (!response || typeof response !== "object" || Array.isArray(response) || hasOwnProto(response)) return false;
|
|
118
136
|
const rows = (response as {loops?: any[]})?.loops;
|
|
119
137
|
if (!Array.isArray(rows)) return false;
|
|
120
|
-
const matches = rows.filter(
|
|
138
|
+
const matches = rows.filter(
|
|
139
|
+
row => row && typeof row === "object" && !Array.isArray(row) && !hasOwnProto(row) && row.loop_id === tick.loop_id,
|
|
140
|
+
);
|
|
121
141
|
if (matches.length !== 1) return false;
|
|
122
142
|
const row = matches[0];
|
|
123
143
|
return row.status === "active" && row.channel_id === msg.channel_id && row.prompt === tick.prompt &&
|