@senpi/runtime 3.0.180 → 3.0.181

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 (135) hide show
  1. package/dist/actions/llm-decision/openclaw-llm-decision.d.ts +8 -0
  2. package/dist/actions/llm-decision/openclaw-llm-decision.d.ts.map +1 -1
  3. package/dist/actions/llm-decision/openclaw-llm-decision.js +56 -1
  4. package/dist/actions/llm-decision/openclaw-llm-decision.js.map +1 -1
  5. package/dist/approvals/approval-store.d.ts +37 -7
  6. package/dist/approvals/approval-store.d.ts.map +1 -1
  7. package/dist/approvals/approval-store.js +127 -23
  8. package/dist/approvals/approval-store.js.map +1 -1
  9. package/dist/approvals/telemetry.d.ts +27 -3
  10. package/dist/approvals/telemetry.d.ts.map +1 -1
  11. package/dist/approvals/telemetry.js +8 -4
  12. package/dist/approvals/telemetry.js.map +1 -1
  13. package/dist/approvals/tool-approval-gate.d.ts +79 -0
  14. package/dist/approvals/tool-approval-gate.d.ts.map +1 -1
  15. package/dist/approvals/tool-approval-gate.js +184 -15
  16. package/dist/approvals/tool-approval-gate.js.map +1 -1
  17. package/dist/approvals/turn-context.d.ts +271 -0
  18. package/dist/approvals/turn-context.d.ts.map +1 -0
  19. package/dist/approvals/turn-context.js +551 -0
  20. package/dist/approvals/turn-context.js.map +1 -0
  21. package/dist/cli/guide-commands.d.ts.map +1 -1
  22. package/dist/cli/guide-commands.js +17 -3
  23. package/dist/cli/guide-commands.js.map +1 -1
  24. package/dist/cli/senpi-commands.d.ts.map +1 -1
  25. package/dist/cli/senpi-commands.js +71 -4
  26. package/dist/cli/senpi-commands.js.map +1 -1
  27. package/dist/deploy/job.d.ts +32 -0
  28. package/dist/deploy/job.d.ts.map +1 -1
  29. package/dist/deploy/job.js +72 -7
  30. package/dist/deploy/job.js.map +1 -1
  31. package/dist/deploy/register.d.ts +11 -0
  32. package/dist/deploy/register.d.ts.map +1 -1
  33. package/dist/deploy/register.js +84 -2
  34. package/dist/deploy/register.js.map +1 -1
  35. package/dist/host/openclaw-host.d.ts +138 -0
  36. package/dist/host/openclaw-host.d.ts.map +1 -0
  37. package/dist/host/openclaw-host.js +177 -0
  38. package/dist/host/openclaw-host.js.map +1 -0
  39. package/dist/index.d.ts +46 -2
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +220 -12
  42. package/dist/index.js.map +1 -1
  43. package/dist/runtime/auto-update/coordinator.d.ts +203 -0
  44. package/dist/runtime/auto-update/coordinator.d.ts.map +1 -1
  45. package/dist/runtime/auto-update/coordinator.js +621 -12
  46. package/dist/runtime/auto-update/coordinator.js.map +1 -1
  47. package/dist/runtime/auto-update/gateway-restart.d.ts +60 -1
  48. package/dist/runtime/auto-update/gateway-restart.d.ts.map +1 -1
  49. package/dist/runtime/auto-update/gateway-restart.js +95 -21
  50. package/dist/runtime/auto-update/gateway-restart.js.map +1 -1
  51. package/dist/runtime/auto-update/idle-gate.d.ts +139 -0
  52. package/dist/runtime/auto-update/idle-gate.d.ts.map +1 -0
  53. package/dist/runtime/auto-update/idle-gate.js +217 -0
  54. package/dist/runtime/auto-update/idle-gate.js.map +1 -0
  55. package/dist/runtime/auto-update/install-results.d.ts +130 -0
  56. package/dist/runtime/auto-update/install-results.d.ts.map +1 -0
  57. package/dist/runtime/auto-update/install-results.js +264 -0
  58. package/dist/runtime/auto-update/install-results.js.map +1 -0
  59. package/dist/runtime/auto-update/money-call-tracker.d.ts +36 -0
  60. package/dist/runtime/auto-update/money-call-tracker.d.ts.map +1 -0
  61. package/dist/runtime/auto-update/money-call-tracker.js +129 -0
  62. package/dist/runtime/auto-update/money-call-tracker.js.map +1 -0
  63. package/dist/runtime/auto-update/register-idle-gate.d.ts +70 -0
  64. package/dist/runtime/auto-update/register-idle-gate.d.ts.map +1 -0
  65. package/dist/runtime/auto-update/register-idle-gate.js +123 -0
  66. package/dist/runtime/auto-update/register-idle-gate.js.map +1 -0
  67. package/dist/runtime/auto-update/run-update-command.d.ts +13 -0
  68. package/dist/runtime/auto-update/run-update-command.d.ts.map +1 -1
  69. package/dist/runtime/auto-update/run-update-command.js +18 -0
  70. package/dist/runtime/auto-update/run-update-command.js.map +1 -1
  71. package/dist/runtime/auto-update/state-store.d.ts +14 -1
  72. package/dist/runtime/auto-update/state-store.d.ts.map +1 -1
  73. package/dist/runtime/auto-update/state-store.js +37 -3
  74. package/dist/runtime/auto-update/state-store.js.map +1 -1
  75. package/dist/runtime/auto-update/types.d.ts +51 -0
  76. package/dist/runtime/auto-update/types.d.ts.map +1 -1
  77. package/dist/runtime/auto-update/types.js.map +1 -1
  78. package/dist/runtime/auto-update/update-marker.d.ts +95 -0
  79. package/dist/runtime/auto-update/update-marker.d.ts.map +1 -0
  80. package/dist/runtime/auto-update/update-marker.js +185 -0
  81. package/dist/runtime/auto-update/update-marker.js.map +1 -0
  82. package/dist/runtime/auto-update/update-schedule.d.ts +57 -0
  83. package/dist/runtime/auto-update/update-schedule.d.ts.map +1 -0
  84. package/dist/runtime/auto-update/update-schedule.js +75 -0
  85. package/dist/runtime/auto-update/update-schedule.js.map +1 -0
  86. package/dist/runtime/decision-errors.d.ts +7 -0
  87. package/dist/runtime/decision-errors.d.ts.map +1 -1
  88. package/dist/runtime/decision-errors.js +15 -0
  89. package/dist/runtime/decision-errors.js.map +1 -1
  90. package/dist/senpi/client.d.ts +25 -0
  91. package/dist/senpi/client.d.ts.map +1 -1
  92. package/dist/senpi/client.js +56 -0
  93. package/dist/senpi/client.js.map +1 -1
  94. package/dist/telemetry/metrics.d.ts +14 -0
  95. package/dist/telemetry/metrics.d.ts.map +1 -1
  96. package/dist/telemetry/metrics.js +24 -0
  97. package/dist/telemetry/metrics.js.map +1 -1
  98. package/dist/telemetry/otel-sdk.d.ts +12 -0
  99. package/dist/telemetry/otel-sdk.d.ts.map +1 -1
  100. package/dist/telemetry/otel-sdk.js +47 -1
  101. package/dist/telemetry/otel-sdk.js.map +1 -1
  102. package/dist/telemetry/spans/span-hooks.d.ts +18 -1
  103. package/dist/telemetry/spans/span-hooks.d.ts.map +1 -1
  104. package/dist/telemetry/spans/span-hooks.js +306 -96
  105. package/dist/telemetry/spans/span-hooks.js.map +1 -1
  106. package/dist/telemetry/tool-plane.d.ts +2 -0
  107. package/dist/telemetry/tool-plane.d.ts.map +1 -1
  108. package/dist/telemetry/tool-plane.js +1 -0
  109. package/dist/telemetry/tool-plane.js.map +1 -1
  110. package/dist/tool-surface/crib-cache.d.ts +21 -0
  111. package/dist/tool-surface/crib-cache.d.ts.map +1 -0
  112. package/dist/tool-surface/crib-cache.js +54 -0
  113. package/dist/tool-surface/crib-cache.js.map +1 -0
  114. package/dist/tool-surface/crib-hook.d.ts +78 -0
  115. package/dist/tool-surface/crib-hook.d.ts.map +1 -0
  116. package/dist/tool-surface/crib-hook.js +217 -0
  117. package/dist/tool-surface/crib-hook.js.map +1 -0
  118. package/dist/tool-surface/crib-sheet.d.ts +56 -0
  119. package/dist/tool-surface/crib-sheet.d.ts.map +1 -0
  120. package/dist/tool-surface/crib-sheet.js +129 -0
  121. package/dist/tool-surface/crib-sheet.js.map +1 -0
  122. package/dist/tool-surface/mcp-tool-source.d.ts +64 -0
  123. package/dist/tool-surface/mcp-tool-source.d.ts.map +1 -0
  124. package/dist/tool-surface/mcp-tool-source.js +189 -0
  125. package/dist/tool-surface/mcp-tool-source.js.map +1 -0
  126. package/dist/utils/event-catalog.d.ts +117 -5
  127. package/dist/utils/event-catalog.d.ts.map +1 -1
  128. package/dist/utils/event-catalog.js +19 -0
  129. package/dist/utils/event-catalog.js.map +1 -1
  130. package/dist/widgets/tool.d.ts +9 -0
  131. package/dist/widgets/tool.d.ts.map +1 -1
  132. package/dist/widgets/tool.js +1 -0
  133. package/dist/widgets/tool.js.map +1 -1
  134. package/openclaw.plugin.json +11 -1
  135. package/package.json +5 -2
@@ -57,6 +57,15 @@ function str(value) {
57
57
  return String(value);
58
58
  return undefined;
59
59
  }
60
+ /** One `create_position` order as a sentence: "Open a LONG position on BTC · margin $50 · 5x". */
61
+ function describeOpen(asset, direction, margin, leverage) {
62
+ const parts = [`Open a ${direction ?? ""} position on ${asset ?? "?"}`.replace(/\s+/g, " ")];
63
+ if (margin)
64
+ parts.push(`margin $${margin}`);
65
+ if (leverage)
66
+ parts.push(`${leverage}x`);
67
+ return parts.join(" · ");
68
+ }
60
69
  /**
61
70
  * Human sentence for a senpi trade tool call, mirroring senpi-web's own
62
71
  * per-tool phrasing (its `getDescription` registry).
@@ -74,18 +83,23 @@ export function describeSenpiToolCall(tool, params) {
74
83
  const p = (params ?? {});
75
84
  const asset = str(p.asset) ?? str(p.coin) ?? str(p.symbol);
76
85
  const strategyId = str(p.strategyId) ?? str(p.strategy_id);
77
- const amount = str(p.amount) ?? str(p.usdAmount) ?? str(p.margin);
86
+ const amount = str(p.amount) ?? str(p.usdAmount) ?? str(p.margin) ?? str(p.marginAmount);
78
87
  const leverage = str(p.leverage);
79
88
  const direction = str(p.direction) ?? str(p.side);
80
89
  const parts = [];
81
90
  switch (tool) {
82
91
  case "create_position": {
83
- parts.push(`Open a ${direction ?? ""} position on ${asset ?? "?"}`.replace(/\s+/g, " "));
84
- if (amount)
85
- parts.push(`margin $${amount}`);
86
- if (leverage)
87
- parts.push(`${leverage}x`);
88
- break;
92
+ // The MCP's shape is `orders: [{ coin, direction, leverage, marginAmount }]`; top-level
93
+ // fields are the fallback for an older or hand-built call.
94
+ const orders = Array.isArray(p.orders)
95
+ ? p.orders.filter((o) => Boolean(o) && typeof o === "object")
96
+ : [];
97
+ if (orders.length > 0) {
98
+ return orders
99
+ .map((o) => describeOpen(str(o.coin) ?? str(o.asset) ?? asset, str(o.direction) ?? str(o.side) ?? direction, str(o.marginAmount) ?? str(o.margin) ?? amount, str(o.leverage) ?? leverage))
100
+ .join("; ");
101
+ }
102
+ return describeOpen(asset, direction, amount, leverage);
89
103
  }
90
104
  case "close_position":
91
105
  parts.push(`Close position ${str(p.positionId) ?? asset ?? ""}`.trim());
@@ -144,6 +158,93 @@ export function buildApprovalDescription(tool, params) {
144
158
  const base = hasArgs ? `${head} — ${args}` : head;
145
159
  return truncate(base, DESCRIPTION_MAX_LENGTH);
146
160
  }
161
+ /**
162
+ * Counts approval prompts the gate has asked for and not yet seen resolved
163
+ * (trade tools, and in `all` mode every gated Senpi tool).
164
+ *
165
+ * Read by the self-update idle gate (`runtime/auto-update/idle-gate.ts`): a
166
+ * restart while a user is looking at an approval prompt would cancel it. An
167
+ * entry ends on any `onResolution` decision (including `cancelled`), or
168
+ * expires `timeoutMs + slackMs` after it began, so a prompt the gateway never
169
+ * resolved cannot keep the box busy forever.
170
+ */
171
+ export class PendingApprovalTracker {
172
+ slackMs;
173
+ now;
174
+ open = new Map();
175
+ nextId = 1;
176
+ /**
177
+ * @param slackMs - Grace past the prompt's own timeout before an unresolved entry is dropped.
178
+ * @param now - Clock, for tests.
179
+ */
180
+ constructor(slackMs = 60_000, now = Date.now) {
181
+ this.slackMs = slackMs;
182
+ this.now = now;
183
+ }
184
+ /**
185
+ * Records a prompt that will time out after `timeoutMs`.
186
+ *
187
+ * @returns A handle for {@link end}.
188
+ */
189
+ begin(timeoutMs) {
190
+ const id = this.nextId++;
191
+ const ttl = Number.isFinite(timeoutMs) && timeoutMs > 0 ? timeoutMs : 0;
192
+ this.open.set(id, this.now() + ttl + this.slackMs);
193
+ return id;
194
+ }
195
+ /** Marks a prompt resolved. Unknown or repeated handles are ignored. */
196
+ end(id) {
197
+ this.open.delete(id);
198
+ }
199
+ /** Prompts still waiting for an answer. */
200
+ count() {
201
+ const now = this.now();
202
+ for (const [id, expiresAt] of this.open) {
203
+ if (now >= expiresAt)
204
+ this.open.delete(id);
205
+ }
206
+ return this.open.size;
207
+ }
208
+ }
209
+ /**
210
+ * The text the model reads when the gate stops a gated call in a scheduled
211
+ * turn (D13). On 10.10-beta.3 the host's own outcome for such an approval is
212
+ * a sentence the plugin cannot change and the model cannot act on: for a tool
213
+ * whose hook context carries the run trigger it cancels with "Plugin approval
214
+ * unavailable: cron runs have no approval-capable initiating surface."
215
+ * (`openclaw-worktrees/v2026.10.10-beta.3/src/agents/agent-tools.before-tool-call.approval.ts:161-189,310-320`);
216
+ * the `senpi__` MCP tools are wrapped without the trigger
217
+ * (`src/agents/embedded-agent-runner/run/attempt-tool-prepare.ts:468-485`), so
218
+ * the host asks the gateway instead, which fails with "Plugin approval
219
+ * unavailable (no approval route)" (`:371`) when no approval client is
220
+ * connected. The gate blocks first, in every scheduled turn. This text says
221
+ * what happened and the one step that works: the user asks in chat, where the
222
+ * approval prompt can be shown. It names no other route.
223
+ *
224
+ * D14 (ruled 2026-10-24): the block is outright. When an approval client is
225
+ * connected, 10.10 would route a `senpi__` approval from a scheduled run to
226
+ * it; scheduled runs still never get a prompt, even with the user online.
227
+ * D15: the same block covers every run not positively classified as a direct
228
+ * chat turn (`other`, `unknown`, a call with no run id), with the
229
+ * not-a-chat-turn wording. D16: a stored "Always allow" grant is checked
230
+ * first and wins in every run kind; this block only stops prompts.
231
+ */
232
+ export function scheduledTurnBlockReason(params) {
233
+ const what = params.isTrade ? "trade" : "action";
234
+ const What = params.isTrade ? "Trades" : "Actions";
235
+ const about = params.summary ? `what you were about to do (${params.summary})` : "what you were about to do";
236
+ const scheduled = params.kind === "cron" || params.kind === "heartbeat";
237
+ const why = scheduled
238
+ ? `this scheduled run (${params.kind}) has no way to ask for it`
239
+ : "only a direct chat turn can ask for it; this run is not one";
240
+ return (`The ${what} was not executed: ${params.wireName} needs the user's approval, and ${why}. ` +
241
+ (scheduled ? `${What} from scheduled runs need the user's approval in chat. ` : `${What} need the user's approval in chat. `) +
242
+ `Tell the user ${about} and that they can ask for it in chat, where they will be asked to approve it. ` +
243
+ // Not "do not call this tool again": that leaves every other route open
244
+ // (another trade tool, a raw MCP call from a skill script), and the agent
245
+ // takes the route a refusal leaves. The only path is the user, in chat.
246
+ "Do not try to do this another way from this run; only the user's approval in chat can make it happen.");
247
+ }
147
248
  /**
148
249
  * Register the `before_tool_call` approval gate. No-op in `off` mode.
149
250
  * Returns the store (for tests/introspection) when registered.
@@ -159,8 +260,13 @@ export function registerToolApprovalGate(options) {
159
260
  const tradeTools = new Set(manifest.tradeTools);
160
261
  const timeoutMs = manifest.defaults.timeoutMs;
161
262
  const store = new ToolApprovalStore(stateDir, logger);
263
+ const now = options.now ?? Date.now;
264
+ const resolutionContext = (turn) => ({
265
+ ...(turn.sessionKey ? { sessionKey: turn.sessionKey } : {}),
266
+ turnKind: turn.kind,
267
+ });
162
268
  logger?.info(`[senpi-tool-approvals] enabled | mode=${mode} tradeTools=${tradeTools.size} allowAlways=${store.size} timeoutMs=${timeoutMs}`);
163
- api.on("before_tool_call", (event) => {
269
+ api.on("before_tool_call", (event, ctx) => {
164
270
  // The registry name openclaw uses on the wire (e.g. `senpi__create_position`).
165
271
  // Telemetry keys on it for consistency with the span/tool.called stream,
166
272
  // which use the prefixed name too. Set inside the try so a hostile event
@@ -177,9 +283,62 @@ export function registerToolApprovalGate(options) {
177
283
  if (mode === "trades" && !isTrade) {
178
284
  return undefined;
179
285
  }
286
+ const c = ctx && typeof ctx === "object" ? ctx : undefined;
287
+ const runId = ev?.runId ?? c?.runId;
288
+ const turn = options.turnContext?.lookup({
289
+ runId,
290
+ sessionKey: c?.sessionKey,
291
+ }) ?? { ...(typeof c?.sessionKey === "string" && c.sessionKey ? { sessionKey: c.sessionKey } : {}), kind: "unknown" };
292
+ // D16: an "Always allow" grant wins in every run kind, scheduled and
293
+ // unknown included; the block below only stops prompts. Recorded with
294
+ // the run kind so grant-path calls from scheduled runs stay visible.
180
295
  if (store.isAllowedAlways(tool)) {
296
+ try {
297
+ telemetry.resolved(wireName ?? `senpi__${tool}`, "granted", isTrade, 0, resolutionContext(turn));
298
+ }
299
+ catch {
300
+ // Telemetry must never decide whether a tool runs.
301
+ }
181
302
  return undefined;
182
303
  }
304
+ // The block decision uses the call's own run only (a lookup with a run id
305
+ // reads that run). The session's-latest-run fallback, used when there is
306
+ // no run id, is for telemetry only: it could take a chat for a heartbeat
307
+ // on the shared main session. Both hosts always pass the run id.
308
+ // D15: only a run positively classified as a direct chat turn may ask;
309
+ // an unknown run or a call with no run id is not one (fail closed).
310
+ const runKind = typeof runId === "string" && runId.length > 0 ? turn.kind : "unknown";
311
+ if (options.turnClassification === true && runKind !== "chat") {
312
+ const scheduled = runKind === "cron" || runKind === "heartbeat";
313
+ const name = wireName ?? `senpi__${tool}`;
314
+ let summary;
315
+ try {
316
+ summary = describeSenpiToolCall(tool, ev?.params);
317
+ }
318
+ catch {
319
+ summary = undefined;
320
+ }
321
+ // Built before any telemetry, so an exporter failure can't reach the
322
+ // fail-open catch below and let a scheduled trade run unapproved.
323
+ const blocked = {
324
+ block: true,
325
+ blockReason: scheduledTurnBlockReason({ wireName: name, kind: runKind, isTrade, summary }),
326
+ };
327
+ try {
328
+ telemetry.resolved(name, "cancelled", isTrade, 0, {
329
+ ...resolutionContext(turn),
330
+ turnKind: runKind,
331
+ cancelReason: scheduled ? "scheduled_turn" : "not_chat_turn",
332
+ });
333
+ logger?.info(`[senpi-tool-approvals] gated call outside a chat turn blocked | tool=${tool} turn=${runKind}`);
334
+ }
335
+ catch {
336
+ // Telemetry must never decide whether a trade runs.
337
+ }
338
+ return blocked;
339
+ }
340
+ const pendingId = options.pendingApprovals?.begin(timeoutMs);
341
+ const askedAt = now();
183
342
  return {
184
343
  requireApproval: {
185
344
  title: truncate(`Senpi trade approval: ${tool}`, TITLE_MAX_LENGTH),
@@ -188,10 +347,17 @@ export function registerToolApprovalGate(options) {
188
347
  timeoutMs,
189
348
  timeoutBehavior: "deny",
190
349
  onResolution: (decision) => {
350
+ if (pendingId !== undefined)
351
+ options.pendingApprovals?.end(pendingId);
191
352
  const name = wireName ?? `senpi__${tool}`;
192
353
  if (decision === "allow-always") {
193
- store.rememberAllowAlways(tool);
194
- logger?.info(`[senpi-tool-approvals] allow-always persisted | tool=${tool}`);
354
+ if (store.rememberAllowAlways(tool)) {
355
+ logger?.info(`[senpi-tool-approvals] allow-always persisted | tool=${tool}`);
356
+ }
357
+ else {
358
+ logger?.info("[senpi-tool-approvals] allow-always kept in memory only (the state file could not be read or " +
359
+ `written; the store's warn names the cause and path, and a restart drops the grant) | tool=${tool}`);
360
+ }
195
361
  }
196
362
  else if (decision === "deny") {
197
363
  telemetry.denied(name, "user_denied");
@@ -201,14 +367,17 @@ export function registerToolApprovalGate(options) {
201
367
  // fails closed. A real product signal, and otherwise invisible.
202
368
  telemetry.denied(name, "approval_timeout");
203
369
  }
204
- // Audit every terminal decision — the only record of the approve
205
- // path (allow-once vs allow-always). `cancelled` (run aborted) is
206
- // not a user decision, so it's excluded.
370
+ // Audit every terminal decision: the only record of the approve
371
+ // path (allow-once vs allow-always), and of `cancelled` (a run
372
+ // abort, or on 10.x no route or surface to ask). A cancellation is
373
+ // not a deny: no tool.called{denied}, nothing persisted. The wait
374
+ // time tells a user abort from a no-route cancellation.
207
375
  if (decision === "allow-once" ||
208
376
  decision === "allow-always" ||
209
377
  decision === "deny" ||
210
- decision === "timeout") {
211
- telemetry.resolved(name, decision, isTrade);
378
+ decision === "timeout" ||
379
+ decision === "cancelled") {
380
+ telemetry.resolved(name, decision, isTrade, Math.max(0, now() - askedAt), resolutionContext(turn));
212
381
  }
213
382
  },
214
383
  },
@@ -1 +1 @@
1
- {"version":3,"file":"tool-approval-gate.js","sourceRoot":"","sources":["../../src/approvals/tool-approval-gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,yBAAyB,GAG1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAsB,MAAM,gBAAgB,CAAC;AA0C1E,yFAAyF;AACzF,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AAE7D,8EAA8E;AAC9E,6EAA6E;AAC7E,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,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YACpE,MAAM,EAAE,IAAI,CACV,2EAA2E,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC9H,CAAC;YACF,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YACnC,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Which kind of turn a tool call belongs to: a direct user chat, a cron run, a
3
+ * heartbeat, or another run (R6, D13, D15).
4
+ *
5
+ * The tool hooks' context carries no run trigger on any host
6
+ * (`PluginHookToolContext`, `openclaw-worktrees/v2026.10.10-beta.3/src/plugins/hook-types.ts:526-548`),
7
+ * but `before_prompt_build`'s agent context does (`trigger`, same field on
8
+ * 5.7, 5.12 and 10.x), and both carry the run id. The tracker records
9
+ * `runId → {sessionKey, trigger}` at prompt build and forgets the run at
10
+ * `agent_end`, so the approval gate can read the turn kind of the call it is
11
+ * gating.
12
+ *
13
+ * On 10.x `before_prompt_build` is a conversation hook: without
14
+ * `plugins.entries.runtime.hooks.allowConversationAccess` nothing is recorded
15
+ * and every lookup reads `unknown` ({@link turnClassificationAvailable} says so
16
+ * at boot).
17
+ */
18
+ /** Low-cardinality turn kind, as stamped on approval telemetry (`senpi.turn.kind`). */
19
+ export type TurnKind = "chat" | "cron" | "heartbeat" | "other" | "unknown";
20
+ /** What the gate learns about the turn of one tool call. */
21
+ export interface TurnContext {
22
+ /** The run's session key (the tool context's, when the run is unknown). */
23
+ sessionKey?: string;
24
+ kind: TurnKind;
25
+ }
26
+ /** The read side the approval gate takes. */
27
+ export interface TurnContextReader {
28
+ lookup(params: {
29
+ runId?: unknown;
30
+ sessionKey?: unknown;
31
+ }): TurnContext;
32
+ }
33
+ /**
34
+ * Maps a bare host run trigger to a {@link TurnKind}: `user` is a chat;
35
+ * `cron` and `heartbeat` are scheduled runs; any other trigger (`event`,
36
+ * `memory`, `manual`, `overflow`) is `other`; a missing one is `unknown`. The
37
+ * tracker uses it only after the run's provenance has been checked: a
38
+ * `user` trigger alone does not make a run a chat (see {@link TurnContextTracker}).
39
+ */
40
+ export declare function turnKindOf(trigger: unknown): TurnKind;
41
+ /**
42
+ * A session the host creates for a spawned child: `agent:<id>:subagent:<uuid>`
43
+ * (10.10 `src/agents/subagents/spawn-plan.ts:64-65`, `:subagent:incognito-…`
44
+ * at `subagent-spawn-child-plan.ts:95`; 5.12/5.7 `subagent-spawn.ts:829/821`)
45
+ * or an ACP child `agent:<id>:acp:<uuid>`.
46
+ */
47
+ export declare function isChildSession(sessionKey: string | undefined): boolean;
48
+ /**
49
+ * How long a `sessions_send` / `sessions_spawn` call stays matchable to the
50
+ * run it starts (the send's target run, the spawned child). That run normally
51
+ * starts within seconds; a target busy with another run queues the message,
52
+ * so the window is generous. Past it, the origin run is unidentified and the
53
+ * started run is not chat.
54
+ */
55
+ export declare const SESSIONS_SEND_MATCH_WINDOW_MS: number;
56
+ /**
57
+ * Recent runs by id, bounded, plus what each session's last run was and which
58
+ * kind each spawned child session inherited.
59
+ *
60
+ * Classification (D15: only a run positively identified as a direct chat turn
61
+ * is `chat`; anything not resolvable is not chat), from the
62
+ * `before_prompt_build` context (10.10 `attempt-prompt-build.ts:150-159`:
63
+ * `runId`, `jobId`, `sessionKey`, `trigger`, `inputProvenance`; 5.7/5.12 carry
64
+ * `runId`, `sessionKey`, `trigger` only, `attempt.ts:2563-2574` / `:2948-2959`):
65
+ *
66
+ * 1. `trigger` `cron` / `heartbeat` → that kind.
67
+ * 2. A `sessions_send` target (`inputProvenance` `inter_session` with
68
+ * `sourceTool: "sessions_send"`, 10.10 `sessions-send-tool.ts:477-483`) →
69
+ * the kind of the run that SENT it. The provenance names only the source
70
+ * session, not the sending run, so the sending run is identified from the
71
+ * `sessions_send` call itself: {@link onToolCall} records the calling run's
72
+ * kind with its source session and its named target at `before_tool_call`.
73
+ * A target run consumes the oldest pending send from `sourceSessionKey`
74
+ * whose target is the run's own session, inside
75
+ * {@link SESSIONS_SEND_MATCH_WINDOW_MS}. {@link onToolResult} drops a send
76
+ * whose result says no run was started for it (an error, a `steered` or
77
+ * unstarted `queued` delivery) or that it already finished, and gives a
78
+ * send addressed by `label` / `agentId` its resolved target. Until that
79
+ * result arrives (in wait mode the target run starts while the call is
80
+ * still open), such a send matches a run in any session of the named
81
+ * agent (any agent for a bare label), and only when no send with an exact
82
+ * target matches; candidates of different kinds still read `other`.
83
+ * The reply-back run is recognised too (10.10 `sessions-send-tool.a2a.ts:100,201-208`).
84
+ * It runs in the REQUESTER session, with the target as `sourceSessionKey`
85
+ * and `sourceTool: "sessions_send"`. It takes the kind of the send whose
86
+ * target run started (an open exchange, requester → target). It never
87
+ * takes the requester session's own pending sends.
88
+ * No match, an unclassified sender, or several candidates of different
89
+ * kinds (two runs sending at once; a forward send and a reply-back that
90
+ * could both explain the run) leave the origin unidentified → `other`. A
91
+ * later run on the source session (a chat starting after a heartbeat sent)
92
+ * never changes the answer.
93
+ * Other `inter_session` sources (subagent announce, exec-approval
94
+ * follow-up, `bash-tools.exec-approval-followup.ts:338-342`) → the kind of
95
+ * the `sourceSessionKey` session's last run; `other` when that is unknown.
96
+ * 3. A child session (`subagent:` / `acp:`) → the kind of the run that
97
+ * spawned it. `subagent_spawned` names only the requester session (10.10
98
+ * `subagent-spawn-lifecycle.ts:67-71`: ctx `requesterSessionKey`,
99
+ * `childSessionKey`), so the spawning run is identified the same way as a
100
+ * `sessions_send` sender: {@link onToolCall} records the run's kind at its
101
+ * `sessions_spawn` call (`sessions-spawn-tool.ts:355`), and
102
+ * `subagent_spawned` consumes the oldest pending spawn from the requester
103
+ * session, with the same window and ambiguity rules. Unmatched → `other`.
104
+ * 10.10 hard-codes `trigger: "user"` for these runs
105
+ * (`attempt-execution.ts:349`), and fires `subagent_spawned` after the
106
+ * gateway accepted the child (`subagent-spawn.ts:667`), so a child
107
+ * classified first reads `other` until its origin arrives.
108
+ * 4. `trigger` `event` or `inputProvenance.kind === "internal_system"` (a
109
+ * continuation after background work, `session-event-handoff.ts:509`;
110
+ * neither carries the originating run) → `other`.
111
+ * 5. A `jobId`, or a `cron:` session, with a non-cron trigger → `other`.
112
+ * 6. `trigger` `user` with no provenance or `external_user` provenance (a
113
+ * webchat `chat.send` turn: `reply-turn-kind.ts:18-22`,
114
+ * `chat-send-user-turn.ts:206`) → `chat`.
115
+ * 7. Any other trigger → `other`; none → `unknown`.
116
+ *
117
+ * Known limit: a gateway `agent` call with no provenance on a main session
118
+ * key (an operator `openclaw agent` run) reads as chat; nothing in the
119
+ * context tells it apart from a webchat turn.
120
+ */
121
+ export declare class TurnContextTracker implements TurnContextReader {
122
+ private readonly maxRuns;
123
+ private readonly now;
124
+ private readonly runs;
125
+ private readonly latestBySession;
126
+ /** The kind of each session's last classified run; kept past `agent_end`, for inheritance. */
127
+ private readonly lastKindBySession;
128
+ /** Child session key → the kind it inherited from its requester. */
129
+ private readonly childOrigins;
130
+ /** `sessions_send` / `sessions_spawn` calls waiting for the run they start, oldest first. */
131
+ private origins;
132
+ /** Sends whose target run started, waiting for their reply-back run, oldest first. */
133
+ private exchanges;
134
+ /**
135
+ * @param maxRuns - Runs kept at once; the oldest is dropped past it (a missed `agent_end`).
136
+ * @param now - Clock for the `sessions_send` match window.
137
+ */
138
+ constructor(maxRuns?: number, now?: () => number);
139
+ /**
140
+ * Records a `sessions_send` or `sessions_spawn` call from a `before_tool_call`
141
+ * event/context: the calling run's kind (`unknown` when that run was never
142
+ * classified), its session keys (the call's and the run's own), and for a
143
+ * send the target it names (`params.sessionKey`; a `label` or `agentId`
144
+ * marks it unresolved until the result names it). Any other tool, or
145
+ * malformed input, is ignored.
146
+ */
147
+ onToolCall(event: unknown, ctx: unknown): void;
148
+ /**
149
+ * Reads a `sessions_send` / `sessions_spawn` result from an `after_tool_call`
150
+ * event: drops the pending call when the result says it started no run to
151
+ * match (a failed spawn; for a send, {@link sendStartedNoRunToMatch}), and
152
+ * gives a send its resolved target session. Unknown calls, other tools and
153
+ * unreadable results are ignored.
154
+ */
155
+ onToolResult(event: unknown, ctx: unknown): void;
156
+ /**
157
+ * Records a run from a `before_prompt_build` agent context. Malformed input
158
+ * is ignored. A run is classified once: 10.x fires the hook again for each
159
+ * retry attempt of the same run (after compaction, a model or auth
160
+ * failover), and by then the origin call or exchange that classified it is
161
+ * consumed, so re-classifying would turn a chat-originated run into `other`.
162
+ * The first answer stands, whatever it was; a scheduled run stays scheduled.
163
+ */
164
+ onPromptBuild(ctx: unknown): void;
165
+ /**
166
+ * Records a spawned child's origin from a `subagent_spawned` context/event:
167
+ * the kind of the run whose `sessions_spawn` call is pending in the requester
168
+ * session (consumed), or `other` when none matches. Malformed input is ignored.
169
+ */
170
+ onSubagentSpawned(ctx: unknown, event?: unknown): void;
171
+ /** Forgets a run (its `agent_end`). */
172
+ onRunEnd(runId: unknown): void;
173
+ /**
174
+ * The turn of a tool call: by run id, else by the session's latest recorded
175
+ * run, else `unknown` with the given session key.
176
+ */
177
+ lookup(params: {
178
+ runId?: unknown;
179
+ sessionKey?: unknown;
180
+ }): TurnContext;
181
+ private classify;
182
+ /** Drops origin calls and exchanges older than the match window. */
183
+ private prune;
184
+ /** One kind from several candidates: theirs when all agree and it is known, else `other`. */
185
+ private static agreed;
186
+ /**
187
+ * The pending `tool` call from `source` (for a send: aimed at `target`)
188
+ * that started this run, consumed, with the kind the candidates agree on;
189
+ * `undefined` when none matches.
190
+ */
191
+ private takeOrigin;
192
+ /**
193
+ * The kind of a run whose provenance says `sessions_send` from `source`, in
194
+ * `sessionKey`: either a target run (a pending send from `source` aimed at
195
+ * this session) or a reply-back run (an open exchange from this session to
196
+ * `source`). Both possible with different kinds, or neither → `other`.
197
+ */
198
+ private sendOriginKind;
199
+ /** A session's last classified run kind, or `other` when it is unknown (not resolvable is not chat). */
200
+ private kindOfSession;
201
+ private forget;
202
+ }
203
+ /**
204
+ * Whether this host lets the runtime classify the run a gated call belongs to:
205
+ * one boot-time fact, never decided per run (D15). Both halves must hold.
206
+ *
207
+ * 1. **The host links a tool call to its run.** The gate reads the run id that
208
+ * `before_tool_call` carries. 5.12 and 5.7 add the bundle-MCP tools (every
209
+ * `senpi__` tool) unwrapped and split them with no hook context (5.12
210
+ * `pi-embedded-runner/run/attempt.ts:1228-1235,1275,1737`; 5.7
211
+ * `attempt.ts:1035,1081`), so `pi-tool-definition-adapter.ts:240-244` runs the
212
+ * hook with no ctx and the call arrives with no run id or session key
213
+ * (`pi-tools.before-tool-call.ts:525-534,594-600`). Every `senpi__` call would
214
+ * read `unknown`, so a 5.x host is never available, whatever its config.
215
+ * The first tag that links is 2026.6.1 (`splitSdkTools` passes
216
+ * `catalogToolHookContext`, which carries `runId`). Since 9.5 the bundle
217
+ * tools are also wrapped up front (`attempt-bundle-tools.ts:204` on 10.10).
218
+ * The runtime gates on the modern host (>= 2026.8.1), which includes that.
219
+ * 2. **The conversation hooks register.** The tracker is fed by
220
+ * `before_prompt_build`, a conversation hook on 10.x. A non-bundled plugin's
221
+ * registration is dropped with only a warn diagnostic unless
222
+ * `plugins.entries.<id>.hooks.allowConversationAccess` is `true` (10.10
223
+ * `registry-registrars-tools-hooks.ts:53-63,404-417`,
224
+ * `hook-policy-decisions.ts:10-16`). `allowPromptInjection: false` drops it
225
+ * too (5.12 `registry.ts:2288-2296`).
226
+ *
227
+ * @param config - The whole OpenClaw config the plugin was registered with (`api.config`).
228
+ * @returns `reason` for status surfaces. `configFix` only when a config change
229
+ * would make it available; a host-version limit has none.
230
+ */
231
+ export declare function turnClassificationAvailable(params: {
232
+ modernHost: boolean;
233
+ config: unknown;
234
+ pluginId: string;
235
+ }): {
236
+ available: boolean;
237
+ reason?: string;
238
+ configFix?: string;
239
+ };
240
+ /**
241
+ * The approval gate's host fact as status surfaces show it (`senpi.getHealthStatus` →
242
+ * `approvals`, `openclaw senpi status`). `unavailable` means every run is asked as before
243
+ * this release, scheduled runs included: a box config to fix, or (on 5.x) a host limit.
244
+ * `hostLimit` marks the 5.x case: nothing on the box can change it, so `senpi status`
245
+ * does not print it as a warning.
246
+ */
247
+ export type ApprovalsHostStatus = {
248
+ turnClassification: "available";
249
+ } | {
250
+ turnClassification: "unavailable";
251
+ reason?: string;
252
+ hostLimit?: true;
253
+ };
254
+ /**
255
+ * Feeds `tracker` from `before_prompt_build` (records; returns nothing, so the
256
+ * prompt is untouched), `subagent_spawned` (a child's origin; not a
257
+ * conversation hook on any host), `before_tool_call` / `after_tool_call`
258
+ * (observe `sessions_send` and `sessions_spawn` calls and their results only,
259
+ * to identify the run that started a target or a child; return nothing, so
260
+ * they decide nothing) and `agent_end` (forgets; refused without conversation access, then
261
+ * the tracker's bound applies). Handlers never throw.
262
+ */
263
+ export declare function registerTurnContextHooks(params: {
264
+ api: {
265
+ on(hookName: string, handler: (...args: unknown[]) => unknown, opts?: {
266
+ priority?: number;
267
+ }): void;
268
+ };
269
+ tracker: TurnContextTracker;
270
+ }): void;
271
+ //# sourceMappingURL=turn-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn-context.d.ts","sourceRoot":"","sources":["../../src/approvals/turn-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,uFAAuF;AACvF,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,GAAG,OAAO,GAAG,SAAS,CAAC;AAE3E,4DAA4D;AAC5D,MAAM,WAAW,WAAW;IAC1B,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,MAAM,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,WAAW,CAAC;CACxE;AAED;;;;;;GAMG;AACH,wB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