@agent-marshal/marshal-pi 0.51.0 → 0.53.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@myko/core": "^4.24.4"
3
+ "@myko/core": "^6.5.13"
4
4
  },
5
5
  "description": "pi extension that connects a pi coding-agent session to the marshal coordination daemon — roster registration, send_message/broadcast/join_room/leave_room/set_status tools, and real-time + per-turn delivery of sibling-agent messages. The pi-native counterpart of the Claude Code marshal-shim, built on pi's extension API instead of a shim binary.",
6
6
  "devDependencies": {
@@ -51,5 +51,5 @@
51
51
  "gen": "cargo run -p marshal-entities --no-default-features --features codegen --bin typegen -- src/generated"
52
52
  },
53
53
  "type": "module",
54
- "version": "0.51.0"
54
+ "version": "0.53.0"
55
55
  }
package/src/daemon.ts CHANGED
@@ -44,6 +44,10 @@ import type { Identity } from "./identity.ts";
44
44
 
45
45
  const LIVENESS_INTERVAL_MS = 5_000;
46
46
  const INBOX_PULL_LIMIT = 20;
47
+ // Marshal context enriches a turn but must never gate the harness itself. A
48
+ // disconnected Myko client keeps sendCommand pending while it reconnects, so
49
+ // bound the optional per-turn inbox read and fail open.
50
+ const INBOX_COMMAND_TIMEOUT_MS = 1_500;
47
51
  const SOURCE_ID = "marshal-pi";
48
52
 
49
53
  /** myko's CellServer serves its WebSocket at the `/myko` path. */
@@ -251,6 +255,7 @@ export class MarshalDaemon {
251
255
  }
252
256
 
253
257
  drainInbox(sessionId: string): Promise<string | null> {
258
+ if (!this.connected) return Promise.resolve(null);
254
259
  const prev = this.draining.get(sessionId) ?? Promise.resolve<string | null>(null);
255
260
  const next = prev.catch(() => null).then(() => this.drainInboxInner(sessionId));
256
261
  this.draining.set(sessionId, next);
@@ -274,7 +279,7 @@ export class MarshalDaemon {
274
279
  let result: ReadMessagesResult | undefined;
275
280
  for (let attempt = 0; attempt < 3; attempt++) {
276
281
  try {
277
- result = await this.send(readMessages({
282
+ result = await this.sendForInbox(readMessages({
278
283
  asSession: sessionId,
279
284
  toSession: sessionId,
280
285
  inbox: false,
@@ -292,7 +297,7 @@ export class MarshalDaemon {
292
297
 
293
298
  const block = this.renderInbox(result.messages);
294
299
  try {
295
- await this.send(ackMessages(sessionId, result.messages.map((m) => m.messageId)));
300
+ await this.sendForInbox(ackMessages(sessionId, result.messages.map((m) => m.messageId)));
296
301
  } catch { this.log("inbox ack failed"); }
297
302
  return block;
298
303
  }
@@ -352,6 +357,38 @@ export class MarshalDaemon {
352
357
  return this.client.sendCommand(command as never) as Promise<R>;
353
358
  }
354
359
 
360
+ /** Bounded send for the optional inbox path: reject immediately if the WS is
361
+ * down, and otherwise time out rather than block a turn while the client
362
+ * reconnects. Interactive tools use the connection guard in index.ts. */
363
+ private sendForInbox<R>(command: MarshalCommand<R>): Promise<R> {
364
+ if (!this.connected) return Promise.reject(new Error("marshal is disconnected"));
365
+
366
+ return new Promise<R>((resolve, reject) => {
367
+ let settled = false;
368
+ const timer = setTimeout(() => {
369
+ if (settled) return;
370
+ settled = true;
371
+ reject(new Error(`marshal inbox command timed out after ${INBOX_COMMAND_TIMEOUT_MS}ms`));
372
+ }, INBOX_COMMAND_TIMEOUT_MS);
373
+ if (typeof (timer as any).unref === "function") (timer as any).unref();
374
+
375
+ void this.send(command).then(
376
+ (value) => {
377
+ if (settled) return;
378
+ settled = true;
379
+ clearTimeout(timer);
380
+ resolve(value);
381
+ },
382
+ (error: unknown) => {
383
+ if (settled) return;
384
+ settled = true;
385
+ clearTimeout(timer);
386
+ reject(error);
387
+ },
388
+ );
389
+ });
390
+ }
391
+
355
392
  private watch<I>(query: MarshalQuery<I>) {
356
393
  return this.client.watchQuery(query as never) as unknown as import("rxjs").Observable<I[]>;
357
394
  }
package/src/index.ts CHANGED
@@ -366,7 +366,8 @@ async function init(pi: ExtensionAPI) {
366
366
  promptSnippet: "List live peer sessions on the marshal roster",
367
367
  parameters: Type.Object({}),
368
368
  async execute(): Promise<MarshalToolResult> {
369
- if (!daemon || !sessionId) return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
369
+ if (!daemon || !sessionId || !daemon.isConnected())
370
+ return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
370
371
  daemon.registerSession(sessionId);
371
372
  const sessions = await daemon.roster_snapshot();
372
373
  if (sessions.length === 0) return { content: [{ type: "text", text: "no live sessions on the marshal roster" }], details: {} };
@@ -395,7 +396,8 @@ async function init(pi: ExtensionAPI) {
395
396
  _toolCallId: string,
396
397
  params: { to: string; body: string },
397
398
  ): Promise<MarshalToolResult> {
398
- if (!daemon || !sessionId) return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
399
+ if (!daemon || !sessionId || !daemon.isConnected())
400
+ return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
399
401
  daemon.registerSession(sessionId);
400
402
  try {
401
403
  const r = await daemon.sendMessage(sessionId, params.to, params.body);
@@ -424,7 +426,8 @@ async function init(pi: ExtensionAPI) {
424
426
  _toolCallId: string,
425
427
  params: { room: string; body: string },
426
428
  ): Promise<MarshalToolResult> {
427
- if (!daemon || !sessionId) return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
429
+ if (!daemon || !sessionId || !daemon.isConnected())
430
+ return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
428
431
  daemon.registerSession(sessionId);
429
432
  try {
430
433
  const r = await daemon.broadcast(sessionId, params.room, params.body);
@@ -451,7 +454,8 @@ async function init(pi: ExtensionAPI) {
451
454
  _toolCallId: string,
452
455
  params: { name: string; description?: string },
453
456
  ): Promise<MarshalToolResult> {
454
- if (!daemon || !sessionId) return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
457
+ if (!daemon || !sessionId || !daemon.isConnected())
458
+ return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
455
459
  daemon.registerSession(sessionId);
456
460
  try {
457
461
  const r = await daemon.joinRoom(sessionId, params.name, params.description);
@@ -477,7 +481,8 @@ async function init(pi: ExtensionAPI) {
477
481
  _toolCallId: string,
478
482
  params: { room: string },
479
483
  ): Promise<MarshalToolResult> {
480
- if (!daemon || !sessionId) return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
484
+ if (!daemon || !sessionId || !daemon.isConnected())
485
+ return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
481
486
  daemon.registerSession(sessionId);
482
487
  try {
483
488
  const r = await daemon.leaveRoom(sessionId, params.room);
@@ -503,7 +508,8 @@ async function init(pi: ExtensionAPI) {
503
508
  _toolCallId: string,
504
509
  params: { text: string },
505
510
  ): Promise<MarshalToolResult> {
506
- if (!daemon || !sessionId) return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
511
+ if (!daemon || !sessionId || !daemon.isConnected())
512
+ return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
507
513
  daemon.registerSession(sessionId);
508
514
  try {
509
515
  await daemon.setStatus(sessionId, params.text);
@@ -534,7 +540,8 @@ async function init(pi: ExtensionAPI) {
534
540
  _toolCallId: string,
535
541
  params: { room?: string; since?: number; limit?: number },
536
542
  ): Promise<MarshalToolResult> {
537
- if (!daemon || !sessionId) return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
543
+ if (!daemon || !sessionId || !daemon.isConnected())
544
+ return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
538
545
  daemon.registerSession(sessionId);
539
546
  try {
540
547
  const msgs = await daemon.readHistory(sessionId, {
@@ -563,7 +570,8 @@ async function init(pi: ExtensionAPI) {
563
570
  _toolCallId: string,
564
571
  params: { message_ids: string[] },
565
572
  ): Promise<MarshalToolResult> {
566
- if (!daemon || !sessionId) return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
573
+ if (!daemon || !sessionId || !daemon.isConnected())
574
+ return { content: [{ type: "text", text: "marshal: not connected" }], details: {} };
567
575
  daemon.registerSession(sessionId);
568
576
  try {
569
577
  const n = await daemon.ackMessages(sessionId, params.message_ids);