@m-cpy/pi-a2a-inbox 0.5.0 → 0.5.1

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 CHANGED
@@ -3,6 +3,19 @@
3
3
  All notable changes to `@m-cpy/pi-a2a-inbox` are documented here.
4
4
  The format follows [Keep a Changelog](https://keepachangelog.com/); versions match `package.json`.
5
5
 
6
+ ## [0.5.1] - 2026-12-04
7
+
8
+ ### Changed
9
+ - Busy-session reminders now use **steer** (mid-turn injection at the next tool boundary) instead of a fire-and-forget notice: visible within the current turn without interrupting it or spawning an extra empty turn.
10
+ - Busy-session reminder text is a generic trigger (`[a2a] 消息盒有新消息 → a2a_inbox_list`) carrying no peer/count snapshot, so it never goes stale while queued; idle wake reminders keep the sender/count form.
11
+
12
+ ### Fixed
13
+ - **Duplicate reminders**: the watchdog no longer escalates a reminder the host has reliably accepted (`hostQueued`) while it waits to drain — previously a long tool call (>60s) made the watchdog assume the reminder was lost and add a second follow-up. Failed wakes still retry; a genuinely stuck queue is surfaced by the STALLED alert (ops-facing), not by re-injecting into the session.
14
+ - `typecheck.sh` resolves a real `tsc` (local / require.resolve / host) and fails honestly when absent, instead of `npx` silently resolving a placeholder package and reporting a false pass.
15
+
16
+ ### Notes
17
+ - Reminder effect constraints (no drop when busy, no empty turn, no stale snapshot, no accumulation) are protocol §5; the delivery primitive (steer / follow-up / queued wake) is implementation-specific.
18
+
6
19
  ## [0.5.0] - 2026-12-03
7
20
 
8
21
  First public release.
package/README.md CHANGED
@@ -45,16 +45,22 @@ static URL peers (no discovery daemon)
45
45
 
46
46
  ## Install
47
47
 
48
- pi loads this as a **package**. From the public monorepo:
48
+ pi loads this as a **package**. From npm (published):
49
+
50
+ ```bash
51
+ pi install npm:@m-cpy/pi-a2a-inbox
52
+ ```
53
+
54
+ It also appears in the [Pi package gallery](https://pi.dev/packages). The package bundles the extension (`./extensions`) and a skill (`./skills/pi-a2a-inbox`). No native dependency, no mDNS daemon; host packages (`@earendil-works/pi-coding-agent`, `typebox`) are provided by pi.
55
+
56
+ Or install from the public monorepo source:
49
57
 
50
58
  ```bash
51
59
  git clone https://github.com/Mcpy/a2a-inbox
52
60
  pi install ./a2a-inbox/pi-a2a-inbox
53
61
  ```
54
62
 
55
- Or add the path to `~/.pi/agent/settings.json` `packages`. The package bundles the extension (`./extensions`) and a skill (`./skills/pi-a2a-inbox`). No native dependency, no mDNS daemon; host packages (`@earendil-works/pi-coding-agent`, `typebox`) are provided by pi.
56
-
57
- Once published to npm, a shorter form will be available: `pi install npm:@m-cpy/pi-a2a-inbox` (and it will appear in the [Pi package gallery](https://pi.dev/packages)).
63
+ (Or add the path to `~/.pi/agent/settings.json` `packages`.)
58
64
 
59
65
  ## Configure
60
66
 
@@ -98,6 +98,7 @@ interface NudgeState {
98
98
  batchCount: number; // 同批兜底唤醒次数(pending 归零重置)
99
99
  lastActivity: number;
100
100
  lastWakeAt: number; // 上次唤醒时刻(冷却去重,防 follow-up 堆积)
101
+ hostQueued: boolean; // 宿主已可靠接受入队(steer/followUp accepted)→ 等 drain,看门狗不升级防重复提醒(r51)
101
102
  }
102
103
 
103
104
  export class Inbox {
@@ -157,7 +158,7 @@ export class Inbox {
157
158
  for (const sid of Object.keys(this.nudges)) {
158
159
  const ns = this.nudges[sid];
159
160
  if ((ns.delivered || ns.queued) && this.pendingOf(sid).length > 0) {
160
- ns.delivered = false; ns.queued = false; ns.stallReported = false; changed = true;
161
+ ns.delivered = false; ns.queued = false; ns.stallReported = false; ns.hostQueued = false; changed = true;
161
162
  }
162
163
  }
163
164
  if (changed) this.save();
@@ -186,7 +187,7 @@ export class Inbox {
186
187
  }
187
188
 
188
189
  private nudge(sessionId: string): NudgeState {
189
- return (this.nudges[sessionId] ??= { queued: false, delivered: false, text: "", injectedAt: 0, firstQueuedAt: 0, stallReported: false, batchCount: 0, lastActivity: 0, lastWakeAt: 0 });
190
+ return (this.nudges[sessionId] ??= { queued: false, delivered: false, text: "", injectedAt: 0, firstQueuedAt: 0, stallReported: false, batchCount: 0, lastActivity: 0, lastWakeAt: 0, hostQueued: false });
190
191
  }
191
192
  private pendingOf(sessionId: string) {
192
193
  return this.messages.filter(m => m.direction === "in" && m.fromSessionId !== undefined && m.state === "pending" && this.boxOwner(m) === sessionId);
@@ -195,7 +196,7 @@ export class Inbox {
195
196
  return this.messages.filter(m => m.direction === "in" && m.state === "consuming" && this.boxOwner(m) === sessionId);
196
197
  }
197
198
  private markQueued(ns: NudgeState, now: number) { ns.queued = true; if (!ns.firstQueuedAt) ns.firstQueuedAt = now; } // 首次挂起时刻只记一次
198
- private resetBatch(ns: NudgeState) { ns.queued = false; ns.delivered = false; ns.batchCount = 0; ns.firstQueuedAt = 0; ns.stallReported = false; }
199
+ private resetBatch(ns: NudgeState) { ns.queued = false; ns.delivered = false; ns.batchCount = 0; ns.firstQueuedAt = 0; ns.stallReported = false; ns.hostQueued = false; }
199
200
  // 盒子按"我方会话"隔离:入站消息的盒子归属 = 投递目标会话(contextId),存于 boxSession
200
201
  private boxOwner(m: BoxMessage): string { return (m as any).boxSession ?? m.fromSessionId; }
201
202
 
@@ -263,11 +264,11 @@ export class Inbox {
263
264
  if (ns.queued) { ns.text = busy ? steerText : wakeText; return busy ? "nudge" : "nudge-wake"; } // 合并:更新内部记录不重复入队(已入队文本是快照,B 通用文本无 stale)
264
265
  if (busy) {
265
266
  const ok = await this.deps.light(target, steerText); // 轮间 steer 注入(当前轮内 drain,不跨轮)
266
- if (ok) { this.markQueued(ns, this.deps.now()); ns.injectedAt = this.deps.now(); ns.text = steerText; this.counters.wakeQueued++; return "nudge"; }
267
+ if (ok) { this.markQueued(ns, this.deps.now()); ns.hostQueued = true; ns.injectedAt = this.deps.now(); ns.text = steerText; this.counters.wakeQueued++; return "nudge"; }
267
268
  // 轮间提醒投不进(未加载)→ 降级唤醒
268
269
  }
269
270
  const ok = await this.deps.wake(target, wakeText);
270
- this.markQueued(ns, this.deps.now()); ns.text = wakeText;
271
+ this.markQueued(ns, this.deps.now()); ns.hostQueued = ok; ns.text = wakeText;
271
272
  if (ok) { ns.injectedAt = this.deps.now(); ns.lastWakeAt = this.deps.now(); this.counters.lastWakeOk = this.deps.now(); }
272
273
  else { const past = this.deps.now() - Math.max(WATCHDOG_MS, WAKE_COOLDOWN_MS); ns.injectedAt = past; ns.lastActivity = past; ns.lastWakeAt = past; this.counters.wakeFail++; } // 拒收→回拨计时,看门狗尽快升级
273
274
  return "nudge-wake";
@@ -277,7 +278,7 @@ export class Inbox {
277
278
  markDelivered(sessionId: string) {
278
279
  this.load();
279
280
  const ns = this.nudge(sessionId);
280
- if (ns.queued) { ns.queued = false; ns.delivered = true; ns.batchCount++; ns.firstQueuedAt = 0; ns.stallReported = false; this.save(); } // 预算只计真送达(qwenpaw 6a5335b ①:催过一次=delivered 非调用 wake);送达清挂起观测重新武装
281
+ if (ns.queued) { ns.queued = false; ns.delivered = true; ns.batchCount++; ns.firstQueuedAt = 0; ns.stallReported = false; ns.hostQueued = false; this.save(); } // 预算只计真送达(qwenpaw 6a5335b ①:催过一次=delivered 非调用 wake);送达清挂起观测重新武装
281
282
  }
282
283
 
283
284
  // ---------- 轮末收口(§4.5 + §5 兜底,进串行链) ----------
@@ -301,8 +302,8 @@ export class Inbox {
301
302
  if (!ns.queued && ns.batchCount < MAX_ATTEMPTS && this.deps.now() - Math.max(ns.lastWakeAt, ns.injectedAt) >= WAKE_COOLDOWN_MS) {
302
303
  const mustCount = pending.filter(m => m.mustReply).length;
303
304
  const text = `[a2a] 消息盒:${pending.length} 条待处理${mustCount ? `(${mustCount} 条需回复)` : ""} → a2a_inbox_fetch`;
304
- await this.deps.wake(sessionId, text);
305
- this.markQueued(ns, this.deps.now()); ns.injectedAt = this.deps.now(); ns.lastWakeAt = this.deps.now(); ns.text = text;
305
+ const wok = await this.deps.wake(sessionId, text);
306
+ this.markQueued(ns, this.deps.now()); ns.hostQueued = wok; ns.injectedAt = this.deps.now(); ns.lastWakeAt = this.deps.now(); ns.text = text;
306
307
  }
307
308
  this.save();
308
309
  });
@@ -346,6 +347,7 @@ export class Inbox {
346
347
  if (now - Math.max(ns.lastWakeAt, ns.injectedAt) < WAKE_COOLDOWN_MS) continue; // 冷却防堆积(含 light 提醒的 injectedAt)
347
348
  if (ns.queued && !ns.delivered) {
348
349
  // queued 提醒未投递:老化后升级(判忙误判场景,不查 isBusy)
350
+ if (ns.hostQueued) continue; // r51:宿主已可靠入队(steer/followUp accepted)→ 等当前轮工具边界 drain,不升级防重复提醒(长工具 >60s 时看门狗误判丢失会补一条 followUp,与 steer 叠成两条);真卡死由 STALLED 告警观测
349
351
  if (now - ns.injectedAt < WATCHDOG_MS) continue;
350
352
  if (now - ns.lastActivity < WATCHDOG_MS) continue; // 期间有活动则不升级
351
353
  } else {
@@ -358,8 +360,8 @@ export class Inbox {
358
360
  if (p.length === 0) return; // 有 consuming 无 pending:不催也不清账
359
361
  const mustCount = p.filter(m => m.mustReply).length;
360
362
  const text = `[a2a] 消息盒:${p.length} 条待处理${mustCount ? `(${mustCount} 条需回复)` : ""} → a2a_inbox_fetch`;
361
- await this.deps.wake(sessionId, text);
362
- this.markQueued(ns, now); ns.delivered = false; ns.injectedAt = now; ns.lastWakeAt = now; ns.text = text;
363
+ const wok = await this.deps.wake(sessionId, text);
364
+ this.markQueued(ns, now); ns.hostQueued = wok; ns.delivered = false; ns.injectedAt = now; ns.lastWakeAt = now; ns.text = text;
363
365
  this.save();
364
366
  });
365
367
  }
@@ -462,7 +464,7 @@ export class Inbox {
462
464
  }
463
465
  // 可观测性(qwenpaw 5bba8cb 同名):累计计数+since+最后动作时间戳,落盘重启不丢;日切从日志重算不进账本
464
466
  countersView(): Counters { this.load(); return { ...this.counters, susp: { ...this.counters.susp } }; }
465
- reminderState(sessionId: string) { this.load(); const ns = this.nudges[sessionId]; return ns ? { queued: ns.queued, delivered: ns.delivered, batchCount: ns.batchCount, firstQueuedAt: ns.firstQueuedAt, stallReported: ns.stallReported } : { queued: false, delivered: false, batchCount: 0, firstQueuedAt: 0, stallReported: false }; }
467
+ reminderState(sessionId: string) { this.load(); const ns = this.nudges[sessionId]; return ns ? { queued: ns.queued, delivered: ns.delivered, batchCount: ns.batchCount, firstQueuedAt: ns.firstQueuedAt, stallReported: ns.stallReported, hostQueued: ns.hostQueued } : { queued: false, delivered: false, batchCount: 0, firstQueuedAt: 0, stallReported: false, hostQueued: false }; }
466
468
  private suspCount(reason: string) { this.counters.susp[reason] = (this.counters.susp[reason] ?? 0) + 1; }
467
469
  // authReject 服务级计数(qwenpaw 同类):401 故意不每次同步写盘,只置脏标记(防端口扫描 I/O 放大),看门狗/下次 save flush
468
470
  noteReject(kind: "noToken" | "unknownToken" | "ambiguousToken") { this.load(); this.counters.rejects[kind]++; this.rejectDirty = true; }
@@ -33,7 +33,7 @@ interface Engine {
33
33
  }
34
34
  const ENGINE_KEY = Symbol.for("cpy.pi-a2a.engine.v3");
35
35
  // 引擎代码版本:inbox/envelope 改动须递增;reload 时若版本不符且空闲→重建引擎(避免旧类实例缺新方法)。
36
- const ENGINE_VERSION = "0.5.0-r50";
36
+ const ENGINE_VERSION = "0.5.1-r51";
37
37
  const engine: Engine = ((globalThis as any)[ENGINE_KEY] ??= {
38
38
  config: null, configPath: null, inbox: null, envelope: null,
39
39
  instances: new Map(), running: new Set(), watchdog: null, baseDir: process.cwd(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m-cpy/pi-a2a-inbox",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "A2A peer collaboration for pi — standard A2A v1.0 envelope + inbox extension, static URL peers, per-peer Bearer identity, session continuation",
5
5
  "keywords": [
6
6
  "pi-package",