@sema-agent/client-core 0.87.0 → 0.89.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +177 -0
  2. package/README.md +20 -15
  3. package/dist/adapter/activeRunSelfHeal.js +4 -2
  4. package/dist/adapter/downstream/eventToSdkMessage.js +17 -2
  5. package/dist/adapter/downstream/wiringManifestView.d.ts +11 -0
  6. package/dist/adapter/downstream/wiringManifestView.js +28 -0
  7. package/dist/controlRouter.d.ts +7 -1
  8. package/dist/controlRouter.js +43 -1
  9. package/dist/disableSkillsWire.d.ts +17 -0
  10. package/dist/disableSkillsWire.js +52 -0
  11. package/dist/displayUntrusted.d.ts +4 -0
  12. package/dist/displayUntrusted.js +1742 -591
  13. package/dist/engineErrorCodes.d.ts +2 -0
  14. package/dist/engineErrorCodes.js +1 -0
  15. package/dist/engineNoticeCodes.d.ts +44 -1
  16. package/dist/engineNoticeCodes.js +211 -39
  17. package/dist/engineWireFor.d.ts +1 -0
  18. package/dist/engineWireFor.js +1 -1
  19. package/dist/gateOutcome.d.ts +4 -0
  20. package/dist/gateOutcome.js +5 -0
  21. package/dist/generated/engineFactTables.d.ts +1 -0
  22. package/dist/generated/engineFactTables.js +3 -0
  23. package/dist/generated/engineNoticeTables.d.ts +3 -0
  24. package/dist/generated/engineNoticeTables.js +110 -0
  25. package/dist/hitl/crashConverged.d.ts +1 -1
  26. package/dist/hitl/crashConverged.js +6 -1
  27. package/dist/hitl/planReviewWire.js +30 -10
  28. package/dist/hitl/toolApprovalWire.d.ts +6 -2
  29. package/dist/hitl/toolApprovalWire.js +30 -0
  30. package/dist/hooksWireCaps.js +80 -12
  31. package/dist/index.d.ts +12 -3
  32. package/dist/index.js +8 -3
  33. package/dist/pluginHooksWire.d.ts +46 -4
  34. package/dist/pluginHooksWire.js +277 -24
  35. package/dist/promptDelivery.d.ts +20 -0
  36. package/dist/promptDelivery.js +153 -0
  37. package/dist/providerRejection.d.ts +6 -0
  38. package/dist/providerRejection.js +52 -0
  39. package/dist/registryConflict.d.ts +3 -0
  40. package/dist/registryConflict.js +44 -0
  41. package/dist/request/taskRequest.d.ts +3 -0
  42. package/dist/request/taskRequest.js +64 -8
  43. package/dist/resumeRefusalCopy.d.ts +7 -0
  44. package/dist/resumeRefusalCopy.js +45 -1
  45. package/dist/runTerminal.d.ts +6 -0
  46. package/dist/runTerminal.js +23 -0
  47. package/dist/seam.d.ts +4 -0
  48. package/dist/seatContract.d.ts +9 -1
  49. package/dist/seatContract.js +10 -0
  50. package/dist/sessionMemoryErase.d.ts +76 -0
  51. package/dist/sessionMemoryErase.js +432 -0
  52. package/dist/subagent/engineSubagentResume.js +2 -1
  53. package/dist/subagent/engineSubagentSteer.d.ts +8 -1
  54. package/dist/subagent/engineSubagentSteer.js +26 -3
  55. package/docs/INTEGRATION-CLIENTS.md +767 -14
  56. package/package.json +3 -3
@@ -48,6 +48,8 @@ export declare const REWIND_ERROR_CODE_PREFIXES: readonly ["resume_at.", "rewind
48
48
  export declare function isRewindFamilyCode(code: string | undefined): boolean;
49
49
  export declare const RESUME_USAGE_WINDOW_EXHAUSTED = "resume.usage_window_exhausted";
50
50
  export declare const RESUME_PREFLIGHT_REJECTED = "resume.preflight_rejected";
51
+ export declare const RESUME_SESSION_NOT_FOUND = "resume.session_not_found";
52
+ export type StatusDerivedCoarseCode = (typeof STATUS_DERIVED_COARSE_CODES)[number];
51
53
  export declare const RESUME_PLACEMENT_MISMATCH = "resume.placement_mismatch";
52
54
  export declare const RESUME_CONTEXT_UNAVAILABLE = "conflict.resume_context_unavailable";
53
55
  export declare const RESUME_RETRY_LATER_CODES: readonly string[];
@@ -106,6 +106,7 @@ export function isRewindFamilyCode(code) {
106
106
  }
107
107
  export const RESUME_USAGE_WINDOW_EXHAUSTED = 'resume.usage_window_exhausted';
108
108
  export const RESUME_PREFLIGHT_REJECTED = 'resume.preflight_rejected';
109
+ export const RESUME_SESSION_NOT_FOUND = 'resume.session_not_found';
109
110
  export const RESUME_PLACEMENT_MISMATCH = 'resume.placement_mismatch';
110
111
  export const RESUME_CONTEXT_UNAVAILABLE = 'conflict.resume_context_unavailable';
111
112
  export const RESUME_RETRY_LATER_CODES = Object.freeze([
@@ -1,6 +1,6 @@
1
+ import { CORE_TOOL_TURN_INCOMPLETE_CAUSES, CORE_USER_STEER_UNDRAINED_CAUSES } from './generated/engineNoticeTables.js';
1
2
  export type NoticeAudience = 'user' | 'operator';
2
3
  export declare const ENGINE_NOTICE_CODES: readonly string[];
3
- export declare const SERVER_NOTICE_AUDIENCE: Readonly<Record<string, NoticeAudience>>;
4
4
  export declare function engineNoticeInCatalog(code: unknown): boolean;
5
5
  export declare const ENGINE_NOTICE_AUDIENCE: Readonly<Record<string, NoticeAudience>>;
6
6
  export declare function noticeAudienceOf(code: unknown): NoticeAudience;
@@ -137,6 +137,44 @@ export interface LegacyModeSeedMigratedFactsView {
137
137
  runId: string;
138
138
  }
139
139
  export declare function readLegacyModeSeedMigrated(notice: unknown): LegacyModeSeedMigratedFactsView | undefined;
140
+ export interface ToolTurnRepairView {
141
+ form: string;
142
+ toolCallIds: readonly string[];
143
+ }
144
+ export interface ToolTurnRepairedFactsView {
145
+ repairs: readonly ToolTurnRepairView[];
146
+ sessionId: string;
147
+ runId: string;
148
+ }
149
+ export declare function readToolTurnRepaired(notice: unknown): ToolTurnRepairedFactsView | undefined;
150
+ export interface ModelUnreachableFactsView {
151
+ code: string;
152
+ targetHost: string;
153
+ proxyInUse?: string;
154
+ remedy: string;
155
+ sessionId: string;
156
+ }
157
+ export declare function readModelUnreachable(notice: unknown): ModelUnreachableFactsView | undefined;
158
+ export type ToolTurnIncompleteCause = (typeof CORE_TOOL_TURN_INCOMPLETE_CAUSES)[number];
159
+ export interface ToolTurnIncompleteFactsView {
160
+ cause: string;
161
+ count: number;
162
+ toolCallIds?: readonly string[];
163
+ sessionId: string;
164
+ runId: string;
165
+ }
166
+ export declare function readToolTurnIncomplete(notice: unknown): ToolTurnIncompleteFactsView | undefined;
167
+ export type UserSteerUndrainedCause = (typeof CORE_USER_STEER_UNDRAINED_CAUSES)[number];
168
+ export interface UserInputUndrainedFactsView {
169
+ kind: 'steer' | 'followUp';
170
+ count: number;
171
+ cause?: string;
172
+ taskId?: string;
173
+ sessionId?: string;
174
+ runId?: string;
175
+ }
176
+ export declare function readUserInputUndrained(notice: unknown): UserInputUndrainedFactsView | undefined;
177
+ export declare function userInputUndrainedNotice(facts: Pick<UserInputUndrainedFactsView, 'kind' | 'count' | 'cause'>): string | undefined;
140
178
  export declare const ENGINE_NOTICE_FACT_READERS: Readonly<{
141
179
  readonly 'mcp.injection_dropped': typeof readMcpInjectionDrop;
142
180
  readonly 'delegation.ask_unresolvable': typeof readAskUnresolvable;
@@ -153,6 +191,11 @@ export declare const ENGINE_NOTICE_FACT_READERS: Readonly<{
153
191
  readonly 'permission.ask_released_by_mode': typeof readAskReleasedByMode;
154
192
  readonly 'permission.read_deny_unapplied': typeof readReadDenyUnapplied;
155
193
  readonly 'resume.legacy_mode_seed_migrated': typeof readLegacyModeSeedMigrated;
194
+ readonly 'context.tool_turn_repaired': typeof readToolTurnRepaired;
195
+ readonly 'server.model_unreachable': typeof readModelUnreachable;
196
+ readonly 'task.tool_turn_incomplete': typeof readToolTurnIncomplete;
197
+ readonly 'task.user_steer_undrained': typeof readUserInputUndrained;
198
+ readonly 'task.user_followup_undrained': typeof readUserInputUndrained;
156
199
  }>;
157
200
  type FactReaderTable = typeof ENGINE_NOTICE_FACT_READERS;
158
201
  export type EngineNoticeFactsCode = keyof FactReaderTable;
@@ -1,24 +1,19 @@
1
1
  import { AUTO_MODE_UNAVAILABLE_CAUSES } from './autoModeUnavailable.js';
2
- import { CORE_ENGINE_NOTICE_CODES, CORE_MCP_INJECTION_DROP_REASONS, CORE_NOTICE_AUDIENCE } from './generated/engineNoticeTables.js';
2
+ import { CORE_ENGINE_NOTICE_CODES, CORE_MCP_INJECTION_DROP_REASONS, CORE_NOTICE_AUDIENCE, } from './generated/engineNoticeTables.js';
3
3
  import { CORE_ASK_UNRESOLVABLE_CAUSES, CORE_DURABLE_MANDATE_SOURCES, CORE_PERMISSION_MODE_FOLD_REASONS, } from './generated/engineFactTables.js';
4
4
  export const ENGINE_NOTICE_CODES = CORE_ENGINE_NOTICE_CODES;
5
5
  const CATALOG = new Set(ENGINE_NOTICE_CODES);
6
- export const SERVER_NOTICE_AUDIENCE = Object.freeze({
7
- 'instructions.source_changed': 'user',
8
- 'memory.layer_locked_legacy': 'operator',
9
- 'session.records_skipped': 'user',
10
- });
11
6
  function audienceRow(table, code) {
12
7
  return Object.hasOwn(table, code) ? table[code] : undefined;
13
8
  }
14
9
  export function engineNoticeInCatalog(code) {
15
- return typeof code === 'string' && (CATALOG.has(code) || Object.hasOwn(SERVER_NOTICE_AUDIENCE, code));
10
+ return typeof code === 'string' && CATALOG.has(code);
16
11
  }
17
12
  export const ENGINE_NOTICE_AUDIENCE = CORE_NOTICE_AUDIENCE;
18
13
  export function noticeAudienceOf(code) {
19
14
  if (typeof code !== 'string')
20
15
  return 'operator';
21
- return audienceRow(ENGINE_NOTICE_AUDIENCE, code) ?? audienceRow(SERVER_NOTICE_AUDIENCE, code) ?? 'operator';
16
+ return audienceRow(ENGINE_NOTICE_AUDIENCE, code) ?? 'operator';
22
17
  }
23
18
  export const MCP_INJECTION_DROP_REASONS = CORE_MCP_INJECTION_DROP_REASONS;
24
19
  const DROP_REASONS = new Set(MCP_INJECTION_DROP_REASONS);
@@ -26,9 +21,9 @@ export function readMcpInjectionDrop(notice) {
26
21
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
27
22
  return undefined;
28
23
  const n = notice;
29
- if (n.code !== 'mcp.injection_dropped')
24
+ if (ownSeat(n, 'code') !== 'mcp.injection_dropped')
30
25
  return undefined;
31
- const d = n.detail;
26
+ const d = ownSeat(n, 'detail');
32
27
  if (typeof d !== 'object' || d === null || Array.isArray(d))
33
28
  return undefined;
34
29
  const o = d;
@@ -58,9 +53,9 @@ export function readAskUnresolvable(notice) {
58
53
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
59
54
  return undefined;
60
55
  const n = notice;
61
- if (n.code !== 'delegation.ask_unresolvable')
56
+ if (ownSeat(n, 'code') !== 'delegation.ask_unresolvable')
62
57
  return undefined;
63
- const d = n.detail;
58
+ const d = ownSeat(n, 'detail');
64
59
  if (typeof d !== 'object' || d === null || Array.isArray(d))
65
60
  return undefined;
66
61
  const o = d;
@@ -92,9 +87,9 @@ export function readDurableGateUnavailable(notice) {
92
87
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
93
88
  return undefined;
94
89
  const n = notice;
95
- if (n.code !== 'config.durable_gate_unavailable')
90
+ if (ownSeat(n, 'code') !== 'config.durable_gate_unavailable')
96
91
  return undefined;
97
- const d = n.detail;
92
+ const d = ownSeat(n, 'detail');
98
93
  if (typeof d !== 'object' || d === null || Array.isArray(d))
99
94
  return undefined;
100
95
  const o = d;
@@ -137,9 +132,9 @@ export function readSkillsListingTruncated(notice) {
137
132
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
138
133
  return undefined;
139
134
  const n = notice;
140
- if (n.code !== 'skills.listing_truncated')
135
+ if (ownSeat(n, 'code') !== 'skills.listing_truncated')
141
136
  return undefined;
142
- const d = n.detail;
137
+ const d = ownSeat(n, 'detail');
143
138
  if (typeof d !== 'object' || d === null || Array.isArray(d))
144
139
  return undefined;
145
140
  const o = d;
@@ -169,9 +164,9 @@ export function readMcpServerRedialed(notice) {
169
164
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
170
165
  return undefined;
171
166
  const n = notice;
172
- if (n.code !== 'mcp.server_redialed')
167
+ if (ownSeat(n, 'code') !== 'mcp.server_redialed')
173
168
  return undefined;
174
- const d = n.detail;
169
+ const d = ownSeat(n, 'detail');
175
170
  if (typeof d !== 'object' || d === null || Array.isArray(d))
176
171
  return undefined;
177
172
  const o = d;
@@ -204,9 +199,10 @@ function readRootGrantNoticeOf(notice) {
204
199
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
205
200
  return undefined;
206
201
  const n = notice;
207
- if (n.code !== 'approval.read_root_granted' && n.code !== 'approval.read_root_grant_rejected')
202
+ const code = ownSeat(n, 'code');
203
+ if (code !== 'approval.read_root_granted' && code !== 'approval.read_root_grant_rejected')
208
204
  return undefined;
209
- const d = n.detail;
205
+ const d = ownSeat(n, 'detail');
210
206
  if (typeof d !== 'object' || d === null || Array.isArray(d))
211
207
  return undefined;
212
208
  const o = d;
@@ -215,7 +211,7 @@ function readRootGrantNoticeOf(notice) {
215
211
  if (toolCallId === undefined)
216
212
  return undefined;
217
213
  const sessionId = str(o.sessionId);
218
- if (n.code === 'approval.read_root_granted') {
214
+ if (code === 'approval.read_root_granted') {
219
215
  const dir = str(o.dir);
220
216
  const root = str(o.root);
221
217
  if (dir === undefined || root === undefined)
@@ -247,9 +243,9 @@ export function readInstructionsSourceChanged(notice) {
247
243
  return undefined;
248
244
  try {
249
245
  const n = notice;
250
- if (n.code !== 'instructions.source_changed')
246
+ if (ownSeat(n, 'code') !== 'instructions.source_changed')
251
247
  return undefined;
252
- const d = n.detail;
248
+ const d = ownSeat(n, 'detail');
253
249
  if (typeof d !== 'object' || d === null || Array.isArray(d))
254
250
  return undefined;
255
251
  const o = d;
@@ -273,9 +269,9 @@ export function readSessionRecordsSkipped(notice) {
273
269
  return undefined;
274
270
  try {
275
271
  const n = notice;
276
- if (n.code !== 'session.records_skipped')
272
+ if (ownSeat(n, 'code') !== 'session.records_skipped')
277
273
  return undefined;
278
- const d = n.detail;
274
+ const d = ownSeat(n, 'detail');
279
275
  if (typeof d !== 'object' || d === null || Array.isArray(d))
280
276
  return undefined;
281
277
  const o = d;
@@ -319,9 +315,9 @@ function readRuleStoreUnavailableOf(notice) {
319
315
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
320
316
  return undefined;
321
317
  const n = notice;
322
- if (n.code !== 'permission.rule_store_unavailable')
318
+ if (ownSeat(n, 'code') !== 'permission.rule_store_unavailable')
323
319
  return undefined;
324
- const d = n.detail;
320
+ const d = ownSeat(n, 'detail');
325
321
  if (typeof d !== 'object' || d === null || Array.isArray(d))
326
322
  return undefined;
327
323
  const o = d;
@@ -343,9 +339,9 @@ function readClassifierUnavailableOf(notice) {
343
339
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
344
340
  return undefined;
345
341
  const n = notice;
346
- if (n.code !== 'classifier.unavailable')
342
+ if (ownSeat(n, 'code') !== 'classifier.unavailable')
347
343
  return undefined;
348
- const d = n.detail;
344
+ const d = ownSeat(n, 'detail');
349
345
  if (typeof d !== 'object' || d === null || Array.isArray(d))
350
346
  return undefined;
351
347
  const o = d;
@@ -379,9 +375,9 @@ function readPermissionModeUnavailableOf(notice) {
379
375
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
380
376
  return undefined;
381
377
  const n = notice;
382
- if (n.code !== 'config.permission_mode_unavailable')
378
+ if (ownSeat(n, 'code') !== 'config.permission_mode_unavailable')
383
379
  return undefined;
384
- const d = n.detail;
380
+ const d = ownSeat(n, 'detail');
385
381
  if (typeof d !== 'object' || d === null || Array.isArray(d))
386
382
  return undefined;
387
383
  const o = d;
@@ -404,9 +400,9 @@ function readAskReleasedByModeOf(notice) {
404
400
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
405
401
  return undefined;
406
402
  const n = notice;
407
- if (n.code !== 'permission.ask_released_by_mode')
403
+ if (ownSeat(n, 'code') !== 'permission.ask_released_by_mode')
408
404
  return undefined;
409
- const d = n.detail;
405
+ const d = ownSeat(n, 'detail');
410
406
  if (typeof d !== 'object' || d === null || Array.isArray(d))
411
407
  return undefined;
412
408
  const o = d;
@@ -439,9 +435,9 @@ function readReadDenyUnappliedOf(notice) {
439
435
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
440
436
  return undefined;
441
437
  const n = notice;
442
- if (n.code !== 'permission.read_deny_unapplied')
438
+ if (ownSeat(n, 'code') !== 'permission.read_deny_unapplied')
443
439
  return undefined;
444
- const d = n.detail;
440
+ const d = ownSeat(n, 'detail');
445
441
  if (typeof d !== 'object' || d === null || Array.isArray(d))
446
442
  return undefined;
447
443
  const o = d;
@@ -465,9 +461,9 @@ function readLegacyModeSeedMigratedOf(notice) {
465
461
  if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
466
462
  return undefined;
467
463
  const n = notice;
468
- if (n.code !== 'resume.legacy_mode_seed_migrated')
464
+ if (ownSeat(n, 'code') !== 'resume.legacy_mode_seed_migrated')
469
465
  return undefined;
470
- const d = n.detail;
466
+ const d = ownSeat(n, 'detail');
471
467
  if (typeof d !== 'object' || d === null || Array.isArray(d))
472
468
  return undefined;
473
469
  const o = d;
@@ -483,6 +479,177 @@ function readLegacyModeSeedMigratedOf(notice) {
483
479
  const permissionMode = nonEmpty(optionalSeat(mo, 'permissionMode'));
484
480
  return { ...(permissionMode !== undefined ? { permissionMode } : {}), droppedKeys, sessionId, runId };
485
481
  }
482
+ export function readToolTurnRepaired(notice) {
483
+ return guardedRead(notice, readToolTurnRepairedOf);
484
+ }
485
+ function ownSeat(o, key) {
486
+ return Object.hasOwn(o, key) ? o[key] : undefined;
487
+ }
488
+ function optionalOwnSeat(o, key) {
489
+ try {
490
+ return ownSeat(o, key);
491
+ }
492
+ catch {
493
+ return undefined;
494
+ }
495
+ }
496
+ function readToolTurnRepairedOf(notice) {
497
+ if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
498
+ return undefined;
499
+ const n = notice;
500
+ if (ownSeat(n, 'code') !== 'context.tool_turn_repaired')
501
+ return undefined;
502
+ const d = ownSeat(n, 'detail');
503
+ if (typeof d !== 'object' || d === null || Array.isArray(d))
504
+ return undefined;
505
+ const o = d;
506
+ const rawRepairs = ownSeat(o, 'repairs');
507
+ if (!Array.isArray(rawRepairs) || rawRepairs.length === 0)
508
+ return undefined;
509
+ const count = rawRepairs.length;
510
+ const repairs = [];
511
+ for (let i = 0; i < count; i++) {
512
+ const item = rawRepairs[i];
513
+ if (typeof item !== 'object' || item === null || Array.isArray(item))
514
+ return undefined;
515
+ const it = item;
516
+ const form = nonEmpty(ownSeat(it, 'form'));
517
+ const toolCallIds = nameList(ownSeat(it, 'toolCallIds'));
518
+ if (form === undefined || toolCallIds === undefined || toolCallIds.length === 0)
519
+ return undefined;
520
+ repairs.push(Object.freeze({ form, toolCallIds }));
521
+ }
522
+ const sessionId = nonEmpty(ownSeat(o, 'sessionId'));
523
+ const runId = nonEmpty(ownSeat(o, 'runId'));
524
+ if (sessionId === undefined || runId === undefined)
525
+ return undefined;
526
+ return { repairs: Object.freeze(repairs), sessionId, runId };
527
+ }
528
+ export function readModelUnreachable(notice) {
529
+ return guardedRead(notice, readModelUnreachableOf);
530
+ }
531
+ function readModelUnreachableOf(notice) {
532
+ if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
533
+ return undefined;
534
+ const n = notice;
535
+ if (ownSeat(n, 'code') !== 'server.model_unreachable')
536
+ return undefined;
537
+ const d = ownSeat(n, 'detail');
538
+ if (typeof d !== 'object' || d === null || Array.isArray(d))
539
+ return undefined;
540
+ const o = d;
541
+ const code = nonEmpty(ownSeat(o, 'code'));
542
+ const targetHost = nonEmpty(ownSeat(o, 'targetHost'));
543
+ const remedy = nonEmpty(ownSeat(o, 'remedy'));
544
+ const sessionId = nonEmpty(ownSeat(o, 'sessionId'));
545
+ if (code === undefined || targetHost === undefined || remedy === undefined || sessionId === undefined)
546
+ return undefined;
547
+ const proxyInUse = nonEmpty(optionalOwnSeat(o, 'proxyInUse'));
548
+ return { code, targetHost, ...(proxyInUse !== undefined ? { proxyInUse } : {}), remedy, sessionId };
549
+ }
550
+ const positiveInt = (v) => (typeof v === 'number' && Number.isInteger(v) && v > 0 ? v : undefined);
551
+ export function readToolTurnIncomplete(notice) {
552
+ return guardedRead(notice, readToolTurnIncompleteOf);
553
+ }
554
+ function optionalNameList(o, key) {
555
+ try {
556
+ const ids = nameList(ownSeat(o, key));
557
+ return ids !== undefined && ids.length > 0 ? ids : undefined;
558
+ }
559
+ catch {
560
+ return undefined;
561
+ }
562
+ }
563
+ function readToolTurnIncompleteOf(notice) {
564
+ if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
565
+ return undefined;
566
+ const n = notice;
567
+ if (ownSeat(n, 'code') !== 'task.tool_turn_incomplete')
568
+ return undefined;
569
+ const d = ownSeat(n, 'detail');
570
+ if (typeof d !== 'object' || d === null || Array.isArray(d))
571
+ return undefined;
572
+ const o = d;
573
+ const cause = nonEmpty(ownSeat(o, 'cause'));
574
+ const count = positiveInt(ownSeat(o, 'count'));
575
+ const toolCallIds = optionalNameList(o, 'toolCallIds');
576
+ const sessionId = nonEmpty(ownSeat(o, 'sessionId'));
577
+ const runId = nonEmpty(ownSeat(o, 'runId'));
578
+ if (cause === undefined || count === undefined || sessionId === undefined || runId === undefined)
579
+ return undefined;
580
+ return { cause, count, ...(toolCallIds !== undefined ? { toolCallIds } : {}), sessionId, runId };
581
+ }
582
+ export function readUserInputUndrained(notice) {
583
+ return guardedRead(notice, readUserInputUndrainedOf);
584
+ }
585
+ function readUserInputUndrainedOf(notice) {
586
+ if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
587
+ return undefined;
588
+ const n = notice;
589
+ const code = ownSeat(n, 'code');
590
+ const kind = code === 'task.user_steer_undrained' ? 'steer' : code === 'task.user_followup_undrained' ? 'followUp' : undefined;
591
+ if (kind === undefined)
592
+ return undefined;
593
+ const d = ownSeat(n, 'detail');
594
+ if (typeof d !== 'object' || d === null || Array.isArray(d))
595
+ return undefined;
596
+ const o = d;
597
+ const count = positiveInt(ownSeat(o, kind));
598
+ if (count === undefined)
599
+ return undefined;
600
+ const cause = nonEmpty(optionalOwnSeat(o, 'cause'));
601
+ const taskId = nonEmpty(optionalOwnSeat(o, 'taskId'));
602
+ const sessionId = nonEmpty(optionalOwnSeat(o, 'sessionId'));
603
+ const runId = nonEmpty(optionalOwnSeat(o, 'runId'));
604
+ return {
605
+ kind,
606
+ count,
607
+ ...(cause !== undefined ? { cause } : {}),
608
+ ...(taskId !== undefined ? { taskId } : {}),
609
+ ...(sessionId !== undefined ? { sessionId } : {}),
610
+ ...(runId !== undefined ? { runId } : {}),
611
+ };
612
+ }
613
+ const messagesPhrase = (n, noun) => `${n} ${noun}${n === 1 ? '' : 's'}`;
614
+ const verbBe = (n) => (n === 1 ? 'was' : 'were');
615
+ const itThem = (n) => (n === 1 ? 'it' : 'them');
616
+ const STEER_UNDRAINED_SENTENCE = Object.freeze({
617
+ leg_end: (n) => `${messagesPhrase(n, 'message')} you sent while the run was in progress ${verbBe(n)} not used before the run ended and will not be delivered. ` +
618
+ `Send ${itThem(n)} again if you still need ${itThem(n)}.`,
619
+ crashed: (n) => `${messagesPhrase(n, 'message')} you sent to an earlier run ${verbBe(n)} accepted, but the server stopped before that run finished, ` +
620
+ `so whether the run used ${itThem(n)} is not known. Check that run's transcript and results before sending ${itThem(n)} again.`,
621
+ });
622
+ const _steerSentencePin = true;
623
+ void _steerSentencePin;
624
+ const followUpUndrainedSentence = (n) => `${messagesPhrase(n, 'follow-up message')} you queued ${verbBe(n)} not used before the run ended and will not be delivered. ` +
625
+ `Send ${itThem(n)} again if you still need ${itThem(n)}.`;
626
+ const unrecognizedUndrainedSentence = (n, kind) => `${kind === 'followUp' ? `${messagesPhrase(n, 'follow-up message')} you queued` : `${messagesPhrase(n, 'message')} you sent during a run`} may not have been used, ` +
627
+ `and the reason was not reported in a form this version recognizes. Check the run's transcript before sending ${itThem(n)} again.`;
628
+ export function userInputUndrainedNotice(facts) {
629
+ let kind;
630
+ let count;
631
+ let cause;
632
+ try {
633
+ if (facts === null || typeof facts !== 'object' || Array.isArray(facts))
634
+ return undefined;
635
+ kind = Object.hasOwn(facts, 'kind') ? facts.kind : undefined;
636
+ count = Object.hasOwn(facts, 'count') ? facts.count : undefined;
637
+ cause = Object.hasOwn(facts, 'cause') ? facts.cause : undefined;
638
+ }
639
+ catch {
640
+ return undefined;
641
+ }
642
+ const n = positiveInt(count);
643
+ if (n === undefined || (kind !== 'steer' && kind !== 'followUp'))
644
+ return undefined;
645
+ if (kind === 'followUp') {
646
+ return cause === undefined || cause === 'leg_end' ? followUpUndrainedSentence(n) : unrecognizedUndrainedSentence(n, kind);
647
+ }
648
+ if (typeof cause === 'string' && Object.hasOwn(STEER_UNDRAINED_SENTENCE, cause)) {
649
+ return STEER_UNDRAINED_SENTENCE[cause](n);
650
+ }
651
+ return unrecognizedUndrainedSentence(n, kind);
652
+ }
486
653
  export const ENGINE_NOTICE_FACT_READERS = Object.freeze({
487
654
  'mcp.injection_dropped': readMcpInjectionDrop,
488
655
  'delegation.ask_unresolvable': readAskUnresolvable,
@@ -499,6 +666,11 @@ export const ENGINE_NOTICE_FACT_READERS = Object.freeze({
499
666
  'permission.ask_released_by_mode': readAskReleasedByMode,
500
667
  'permission.read_deny_unapplied': readReadDenyUnapplied,
501
668
  'resume.legacy_mode_seed_migrated': readLegacyModeSeedMigrated,
669
+ 'context.tool_turn_repaired': readToolTurnRepaired,
670
+ 'server.model_unreachable': readModelUnreachable,
671
+ 'task.tool_turn_incomplete': readToolTurnIncomplete,
672
+ 'task.user_steer_undrained': readUserInputUndrained,
673
+ 'task.user_followup_undrained': readUserInputUndrained,
502
674
  });
503
675
  const _factReaderTablePin = true;
504
676
  void _factReaderTablePin;
@@ -508,10 +680,10 @@ export function readEngineNoticeFacts(notice) {
508
680
  let code;
509
681
  let detail;
510
682
  try {
511
- code = notice.code;
683
+ code = ownSeat(notice, 'code');
512
684
  if (typeof code !== 'string' || !Object.hasOwn(ENGINE_NOTICE_FACT_READERS, code))
513
685
  return undefined;
514
- detail = notice.detail;
686
+ detail = ownSeat(notice, 'detail');
515
687
  }
516
688
  catch {
517
689
  return undefined;
@@ -40,4 +40,5 @@ export type EngineWireNoAnswerKind = 'deadline' | 'time-limit' | 'connection-los
40
40
  export declare function noAnswerKindOf(e: object | null | undefined): EngineWireNoAnswerKind | null;
41
41
  export declare function noAnswerDetailFrom(e: object | null | undefined): string | null;
42
42
  export declare function sendOnce<T>(signal: AbortSignal | null | undefined, run: () => Promise<T>): Promise<T>;
43
+ export declare function provablyNotSent(e: object | null | undefined): boolean;
43
44
  export declare function settleInjected<T>(ms: number, signal: AbortSignal | null | undefined, run: (signal: AbortSignal) => Promise<T>): Promise<T>;
@@ -331,7 +331,7 @@ export async function sendOnce(signal, run) {
331
331
  throw error;
332
332
  }
333
333
  }
334
- function provablyNotSent(e) {
334
+ export function provablyNotSent(e) {
335
335
  try {
336
336
  return e !== null && typeof e === 'object' && (markedNotSent(e) || failedBeforeSend(e));
337
337
  }
@@ -1,5 +1,6 @@
1
1
  import type { DeniedBy, Settlement } from '@sema-agent/sdk';
2
2
  import { type CcToolDenialKind } from './gateVocabulary.js';
3
+ import { CORE_MODE_RELEASE_REASONS } from './generated/engineFactTables.js';
3
4
  export type GateDispositionView = {
4
5
  kind: 'allowed';
5
6
  classifier?: GateClassifierRoundView;
@@ -31,6 +32,9 @@ export interface GateModeReleaseView {
31
32
  mandate?: string;
32
33
  reason?: string;
33
34
  }
35
+ export declare const GATE_MODE_RELEASE_REASON_WORDS: readonly ["rule_unreadable"];
36
+ export type GateModeReleaseReasonWord = (typeof CORE_MODE_RELEASE_REASONS)[number];
37
+ export declare function isGateModeReleaseReasonWord(v: unknown): v is GateModeReleaseReasonWord;
34
38
  export interface SettlementWhoView {
35
39
  party: string;
36
40
  approver?: string;
@@ -1,8 +1,13 @@
1
1
  import { ccToolDenialKindForSettledBy, isCcToolDenialKind, isGateDeniedByWord } from './gateVocabulary.js';
2
2
  import { GATE_PARKED_ERROR_CODE } from './engineErrorCodes.js';
3
+ import { CORE_MODE_RELEASE_REASONS } from './generated/engineFactTables.js';
3
4
  function str(v) {
4
5
  return typeof v === 'string' && v.length > 0 ? v : undefined;
5
6
  }
7
+ export const GATE_MODE_RELEASE_REASON_WORDS = CORE_MODE_RELEASE_REASONS;
8
+ export function isGateModeReleaseReasonWord(v) {
9
+ return typeof v === 'string' && CORE_MODE_RELEASE_REASONS.includes(v);
10
+ }
6
11
  export const SETTLEMENT_KIND_WORDS = Object.freeze([
7
12
  'human_allowed',
8
13
  'human_refused',
@@ -8,3 +8,4 @@ export declare const CORE_DENIED_BY_VALUES: readonly ["policy", "hook", "org", "
8
8
  export declare const CORE_PERMISSION_MODE_FOLD_REASONS: readonly string[];
9
9
  export declare const CORE_ENGINE_CARD_TYPES: readonly string[];
10
10
  export declare const CORE_TOOL_DECLARATION_CODES: readonly string[];
11
+ export declare const CORE_MODE_RELEASE_REASONS: readonly ["rule_unreadable"];
@@ -111,3 +111,6 @@ export const CORE_TOOL_DECLARATION_CODES = Object.freeze([
111
111
  "config.egress_requires_write_effect",
112
112
  "config.reserved_tool_name",
113
113
  ]);
114
+ export const CORE_MODE_RELEASE_REASONS = Object.freeze([
115
+ "rule_unreadable",
116
+ ]);
@@ -1,3 +1,6 @@
1
1
  export declare const CORE_ENGINE_NOTICE_CODES: readonly string[];
2
2
  export declare const CORE_NOTICE_AUDIENCE: Readonly<Record<string, 'user' | 'operator'>>;
3
3
  export declare const CORE_MCP_INJECTION_DROP_REASONS: readonly string[];
4
+ export declare const CORE_NOTICE_MINTER: Readonly<Record<string, 'engine' | 'server'>>;
5
+ export declare const CORE_USER_STEER_UNDRAINED_CAUSES: readonly ["leg_end", "crashed"];
6
+ export declare const CORE_TOOL_TURN_INCOMPLETE_CAUSES: readonly ["truncated", "unnamed", "bad_frame", "missing_result_synthesized"];