agentschat-mcp 0.36.25 → 0.36.27

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.
Files changed (86) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +10 -10
  3. package/codex/README.md +4 -4
  4. package/codex/app-server.ts +101 -22
  5. package/codex/bots-config.ts +32 -11
  6. package/codex/bridge.ts +127 -28
  7. package/codex/config.ts +137 -21
  8. package/codex/gui-channel.ts +66 -9
  9. package/codex/inbox-sync.ts +77 -12
  10. package/codex/loop-grants.ts +49 -11
  11. package/codex/manager.ts +108 -27
  12. package/codex/owner.ts +106 -9
  13. package/codex/processes.ts +51 -7
  14. package/codex/run.ts +70 -17
  15. package/codex/runtime-home.ts +51 -11
  16. package/codex/thread-history.ts +87 -30
  17. package/codex/transport.ts +135 -22
  18. package/connector/README.md +1 -1
  19. package/connector/auth.ts +57 -5
  20. package/connector/backfill.ts +92 -10
  21. package/connector/descriptor.ts +27 -1
  22. package/connector/identities.ts +82 -14
  23. package/connector/ingest.ts +11 -2
  24. package/connector/normalize.ts +32 -12
  25. package/connector/run.ts +314 -67
  26. package/connector/server.ts +95 -26
  27. package/cordis.patch.yml +4 -2
  28. package/dist/codex-bots.js +437 -75
  29. package/dist/codex-bridge.js +2111 -582
  30. package/dist/connector.js +1300 -493
  31. package/dist/dsh.js +1789 -299
  32. package/dist/muse.js +967 -221
  33. package/dist/server.js +4410 -919
  34. package/dsh/README.md +1 -1
  35. package/dsh/client.js +7 -5
  36. package/dsh/identity-ui/client.js +7 -5
  37. package/dsh/identity-ui/index.js +43 -8
  38. package/dsh/inbound-bridge/index.js +677 -154
  39. package/dsh/src/cli.ts +430 -91
  40. package/dsh/src/patch.ts +295 -15
  41. package/dsh/tests/dsh-hardening-127.test.ts +207 -0
  42. package/dsh/tests/dsh.test.ts +1174 -3
  43. package/muse/scripts/ensure-muse-wakes.mjs +5 -3
  44. package/muse/scripts/muse-wake-receiver.mjs +4 -1
  45. package/muse/src/bridge.ts +54 -13
  46. package/muse/src/cli.ts +226 -41
  47. package/muse/src/client.ts +249 -34
  48. package/muse/src/config.ts +128 -12
  49. package/muse/src/policy.ts +28 -8
  50. package/muse/src/types.ts +1 -0
  51. package/muse/src/typing.ts +18 -1
  52. package/muse/src/wake.ts +237 -35
  53. package/muse/tests/bridge.test.mjs +131 -0
  54. package/muse/tests/client.test.mjs +327 -0
  55. package/muse/tests/config.test.mjs +78 -1
  56. package/muse/tests/hardening.test.mjs +199 -0
  57. package/muse/tests/hardening126.test.mjs +292 -0
  58. package/muse/tests/policy.test.mjs +83 -1
  59. package/muse/tests/wake.test.mjs +134 -6
  60. package/package.json +3 -3
  61. package/scripts/ensure-grok-wakes.mjs +93 -8
  62. package/scripts/example-url-wake-receiver.mjs +254 -61
  63. package/scripts/grok-bind-register.sh +38 -8
  64. package/skills/onboarding.md +15 -15
  65. package/src/argcheck.ts +113 -33
  66. package/src/cli.mjs +100 -16
  67. package/src/dedup.ts +57 -8
  68. package/src/grok-bind.ts +182 -33
  69. package/src/heartbeat.ts +39 -11
  70. package/src/identity-guard.ts +93 -20
  71. package/src/identity.ts +67 -11
  72. package/src/mentions.ts +26 -5
  73. package/src/onboarding-status.ts +134 -11
  74. package/src/profile-selection.ts +299 -18
  75. package/src/profile-store.ts +248 -30
  76. package/src/read-cursor.ts +280 -9
  77. package/src/reconnect.ts +98 -2
  78. package/src/redact.ts +34 -15
  79. package/src/rest-cli.ts +713 -159
  80. package/src/server.ts +286 -94
  81. package/src/session-bind.ts +777 -134
  82. package/src/session-route.ts +183 -12
  83. package/src/team-lead-skill.ts +3 -0
  84. package/src/timestamps.ts +56 -23
  85. package/src/tool-annotations.ts +10 -1
  86. package/src/wake.ts +510 -91
@@ -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 (frame.content !== "__typing__") {
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?.startsWith("dm-");
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
@@ -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
- const content = msg.content ?? "";
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 chatId = msg.channel_id ?? "";
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 = chatId.startsWith("dm-");
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: msg.channel_id ?? null,
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 || typeof msg.channel_id !== "string" || !msg.channel_id ||
104
- typeof msg.sender_id !== "string" || !msg.sender_id || msg.sender_type !== "agent" || msg.content_type !== "text" ||
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(row => row?.loop_id === tick.loop_id);
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 &&