@sema-agent/client-core 0.84.0 → 0.85.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 (101) hide show
  1. package/CHANGELOG.md +247 -0
  2. package/README.md +27 -13
  3. package/dist/abortableSleep.d.ts +10 -0
  4. package/dist/abortableSleep.js +37 -0
  5. package/dist/adapt/arms.js +1 -1
  6. package/dist/adapt.d.ts +1 -1
  7. package/dist/adapt.js +1 -1
  8. package/dist/adapter/downstream/terminalToSdkResult.d.ts +1 -0
  9. package/dist/adapter/downstream/terminalToSdkResult.js +19 -10
  10. package/dist/adapter/runStream.js +6 -2
  11. package/dist/agentSession/engineSessionBackgroundStop.d.ts +50 -0
  12. package/dist/agentSession/engineSessionBackgroundStop.js +291 -0
  13. package/dist/agentsWireCaps.d.ts +2 -1
  14. package/dist/agentsWireCaps.js +8 -0
  15. package/dist/cloudConfigWireCaps.js +2 -1
  16. package/dist/corruptSession.d.ts +3 -0
  17. package/dist/corruptSession.js +29 -0
  18. package/dist/corruptSessionCopy.d.ts +1 -0
  19. package/dist/corruptSessionCopy.js +4 -0
  20. package/dist/decideFailureNote.d.ts +2 -1
  21. package/dist/decideFailureNote.js +8 -3
  22. package/dist/decideReceipt.d.ts +6 -0
  23. package/dist/decideReceipt.js +30 -1
  24. package/dist/detachWire.d.ts +1 -0
  25. package/dist/detachWire.js +13 -5
  26. package/dist/displayUntrusted.js +114 -18
  27. package/dist/effortWire.d.ts +2 -1
  28. package/dist/effortWire.js +2 -4
  29. package/dist/engineErrorCodes.d.ts +11 -0
  30. package/dist/engineErrorCodes.js +32 -0
  31. package/dist/engineNoticeCodes.d.ts +39 -4
  32. package/dist/engineNoticeCodes.js +117 -161
  33. package/dist/engineWireFor.d.ts +43 -0
  34. package/dist/engineWireFor.js +399 -0
  35. package/dist/engineWireSdk.d.ts +6 -0
  36. package/dist/fileHistoryCaptureCapability.d.ts +4 -1
  37. package/dist/fileHistoryCaptureCapability.js +43 -9
  38. package/dist/gateVocabulary.d.ts +1 -2
  39. package/dist/gateVocabulary.js +1 -22
  40. package/dist/generated/engineNoticeTables.d.ts +3 -0
  41. package/dist/generated/engineNoticeTables.js +156 -0
  42. package/dist/generated/toolNameTables.d.ts +2 -0
  43. package/dist/generated/toolNameTables.js +43 -0
  44. package/dist/headlessPermissionModeWire.js +2 -4
  45. package/dist/hitl/askGateWire.d.ts +1 -1
  46. package/dist/hitl/askGateWire.js +1 -1
  47. package/dist/hitl/frameRouter.js +4 -2
  48. package/dist/hitl/hitlHostSurface.js +1 -1
  49. package/dist/hitl/parkResolver.d.ts +1 -0
  50. package/dist/hitl/parkResolver.js +11 -3
  51. package/dist/hitl/planReviewWire.d.ts +41 -3
  52. package/dist/hitl/planReviewWire.js +264 -49
  53. package/dist/hitl/rosterMountedNames.d.ts +2 -0
  54. package/dist/hitl/rosterMountedNames.js +38 -0
  55. package/dist/hitl/sessionPolicyDeliverable.d.ts +8 -2
  56. package/dist/hitl/sessionPolicyDeliverable.js +39 -48
  57. package/dist/hitl/sessionPolicyWire.d.ts +40 -0
  58. package/dist/hitl/sessionPolicyWire.js +173 -0
  59. package/dist/hitl/toolApprovalWire.d.ts +4 -2
  60. package/dist/hitl/toolApprovalWire.js +6 -4
  61. package/dist/index.d.ts +10 -3
  62. package/dist/index.js +7 -2
  63. package/dist/liveInitToolFace.js +28 -10
  64. package/dist/permissionWireCaps.d.ts +2 -1
  65. package/dist/permissionWireCaps.js +2 -7
  66. package/dist/request/taskRequest.d.ts +2 -0
  67. package/dist/request/taskRequest.js +18 -1
  68. package/dist/resumeRefusalCopy.d.ts +11 -0
  69. package/dist/resumeRefusalCopy.js +42 -2
  70. package/dist/runTerminal.js +4 -0
  71. package/dist/sandboxWire.js +1 -1
  72. package/dist/sealedKeyCapability.d.ts +17 -0
  73. package/dist/sealedKeyCapability.js +42 -0
  74. package/dist/seatContract.d.ts +2 -1
  75. package/dist/seatContract.js +5 -21
  76. package/dist/subagent/engineCompactWire.d.ts +13 -2
  77. package/dist/subagent/engineCompactWire.js +48 -37
  78. package/dist/subagent/engineDelegatedPrompt.d.ts +9 -1
  79. package/dist/subagent/engineDelegatedPrompt.js +16 -16
  80. package/dist/subagent/engineRowStopGate.d.ts +2 -2
  81. package/dist/subagent/engineRowStopGate.js +4 -4
  82. package/dist/subagent/engineSubagentOutput.d.ts +8 -0
  83. package/dist/subagent/engineSubagentOutput.js +37 -18
  84. package/dist/subagent/engineSubagentResume.d.ts +11 -2
  85. package/dist/subagent/engineSubagentResume.js +28 -14
  86. package/dist/subagent/engineSubagentSteer.d.ts +10 -1
  87. package/dist/subagent/engineSubagentSteer.js +16 -11
  88. package/dist/subagent/engineSubagentTail.d.ts +10 -1
  89. package/dist/subagent/engineSubagentTail.js +35 -17
  90. package/dist/subagent/engineTaskHandleWire.d.ts +13 -0
  91. package/dist/subagent/engineTaskHandleWire.js +41 -20
  92. package/dist/systemReminderTag.d.ts +5 -0
  93. package/dist/systemReminderTag.js +20 -9
  94. package/dist/taskRequestWords.d.ts +5 -0
  95. package/dist/taskRequestWords.js +4 -0
  96. package/dist/wireErrorTriage.d.ts +1 -0
  97. package/dist/wireErrorTriage.js +3 -1
  98. package/dist/wireRefusalCopy.d.ts +10 -0
  99. package/dist/wireRefusalCopy.js +62 -2
  100. package/docs/INTEGRATION-CLIENTS.md +1128 -22
  101. package/package.json +1 -1
@@ -1,8 +1,13 @@
1
1
  import { corruptStoredRowContent, corruptStoredRowWhere } from './wireErrorTriage.js';
2
- import { resumePolicyBlockContent, resumePolicyBlockFromError } from './resumeRefusalCopy.js';
3
- export function decideFailureNote(err) {
2
+ import { parkedResumeStartupContent, parkedResumeStartupFromError, resumePolicyBlockContent, resumePolicyBlockFromError, } from './resumeRefusalCopy.js';
3
+ import { decideParkMovedContent, decideParkMovedFromError } from './decideReceipt.js';
4
+ export function decideFailureNote(err, decision) {
4
5
  const where = corruptStoredRowWhere(err);
5
6
  const fold = resumePolicyBlockFromError(err);
7
+ const startup = parkedResumeStartupFromError(err, decision);
8
+ const moved = decideParkMovedFromError(err);
6
9
  return ((where === undefined ? '' : ` — ${corruptStoredRowContent(where)}`) +
7
- (fold === null ? '' : ` — ${resumePolicyBlockContent(fold)}`));
10
+ (fold === null ? '' : ` — ${resumePolicyBlockContent(fold)}`) +
11
+ (startup === null ? '' : ` — ${parkedResumeStartupContent(startup)}`) +
12
+ (moved === null ? '' : ` — ${decideParkMovedContent(moved)}`));
8
13
  }
@@ -21,3 +21,9 @@ export interface DecideRefusalDetail {
21
21
  resendable: boolean;
22
22
  }
23
23
  export declare function decideRefusalFromError(e: unknown): DecideRefusalDetail | null;
24
+ export interface DecideParkMovedDetail {
25
+ code: string;
26
+ taskId?: string;
27
+ }
28
+ export declare function decideParkMovedFromError(e: unknown): DecideParkMovedDetail | null;
29
+ export declare function decideParkMovedContent(detail: Pick<DecideParkMovedDetail, 'code'>): string;
@@ -1,6 +1,8 @@
1
1
  import { gateOutcomeOf } from './gateOutcome.js';
2
2
  import { resumeReopenFromError } from './resumeRefusalCopy.js';
3
- import { DECIDE_WORKFLOW_HOST_UNKNOWN, DECIDE_WORKFLOW_LANE_CODES, DECIDE_WORKFLOW_REMEMBER_UNSUPPORTED, } from './engineErrorCodes.js';
3
+ import { DECIDE_CLAIM_LOST, DECIDE_GATE_MOVED, DECIDE_NOT_PARKED, DECIDE_WORKFLOW_HOST_UNKNOWN, DECIDE_WORKFLOW_LANE_CODES, DECIDE_WORKFLOW_REMEMBER_UNSUPPORTED, isDecideParkMovedCode, } from './engineErrorCodes.js';
4
+ import { effectiveWireErrorCode } from './wireErrorTriage.js';
5
+ import { readErrorString } from './wireFailureShape.js';
4
6
  const STATUS_RESUMING = 'resuming';
5
7
  function str(v) {
6
8
  return typeof v === 'string' && v.length > 0 ? v : undefined;
@@ -77,3 +79,30 @@ export function decideRefusalFromError(e) {
77
79
  resendable: Object.hasOwn(DECIDE_RESENDABLE, code) ? DECIDE_RESENDABLE[code] === true : false,
78
80
  };
79
81
  }
82
+ export function decideParkMovedFromError(e) {
83
+ const code = effectiveWireErrorCode(e);
84
+ if (code === undefined || !isDecideParkMovedCode(code))
85
+ return null;
86
+ const taskId = readErrorString(e, 'taskId');
87
+ return { code, ...(taskId !== undefined && taskId.length > 0 ? { taskId } : {}) };
88
+ }
89
+ const DECIDE_PARK_MOVED_WHAT = Object.freeze({
90
+ [DECIDE_NOT_PARKED]: 'This approval was no longer waiting when the decision arrived (the agent was stopped, the approval was decided elsewhere, or the session it belongs to was deleted)',
91
+ [DECIDE_GATE_MOVED]: 'This approval moved while the decision was on its way (it was parked again, or settled elsewhere)',
92
+ [DECIDE_CLAIM_LOST]: 'Another decision on this approval got there first, or an earlier attempt is still holding it until the engine clears that hold on its own',
93
+ });
94
+ export function decideParkMovedContent(detail) {
95
+ let code;
96
+ try {
97
+ const raw = detail !== null && typeof detail === 'object' ? detail.code : undefined;
98
+ code = typeof raw === 'string' ? raw : undefined;
99
+ }
100
+ catch {
101
+ code = undefined;
102
+ }
103
+ const what = code !== undefined && Object.hasOwn(DECIDE_PARK_MOVED_WHAT, code)
104
+ ? DECIDE_PARK_MOVED_WHAT[code]
105
+ : 'This approval changed state while the decision was on its way';
106
+ const extra = code === DECIDE_CLAIM_LOST ? '; if this approval is still listed, wait a little before deciding it again' : '';
107
+ return `${what} · This decision was not applied — fetch the pending approvals again and decide from what is pending now${extra}`;
108
+ }
@@ -26,6 +26,7 @@ export declare function resolveHeadlessDetach(baseUrl: string, env?: EnvLike, op
26
26
  timeoutMs?: number;
27
27
  }): Promise<DetachResolution>;
28
28
  export declare const DETACH_DURABLE_OFF_400_ANCHOR = "x-detach-on-disconnect requires a durable run";
29
+ export declare function isDetachDurableOff400(err: unknown): boolean;
29
30
  export declare function detachDurableOffHint(err: unknown): string | null;
30
31
  export interface DetachCancelArm {
31
32
  baseUrl: string;
@@ -57,14 +57,22 @@ export async function resolveHeadlessDetach(baseUrl, env = hostEnv(), opts) {
57
57
  return { on: true, reason: 'default-on' };
58
58
  }
59
59
  export const DETACH_DURABLE_OFF_400_ANCHOR = 'x-detach-on-disconnect requires a durable run';
60
+ export function isDetachDurableOff400(err) {
61
+ try {
62
+ const e = err;
63
+ if (e?.status !== 400)
64
+ return false;
65
+ const msg = e?.message;
66
+ return typeof msg === 'string' && msg.includes(DETACH_DURABLE_OFF_400_ANCHOR);
67
+ }
68
+ catch {
69
+ return false;
70
+ }
71
+ }
60
72
  export function detachDurableOffHint(err) {
61
73
  if (!isDetachArmed())
62
74
  return null;
63
- const e = err;
64
- if (e?.status !== 400)
65
- return null;
66
- const msg = typeof e?.message === 'string' ? e.message : '';
67
- if (!msg.includes(DETACH_DURABLE_OFF_400_ANCHOR))
75
+ if (!isDetachDurableOff400(err))
68
76
  return null;
69
77
  return 'engine has durable runs disabled — detach-on-disconnect unavailable; interrupted turns will abort (SEMA_HEADLESS_DETACH=false to silence)';
70
78
  }
@@ -23,6 +23,10 @@ function pushEdit(edits, src, start, end, text) {
23
23
  return;
24
24
  edits.push({ start: a, end: b, text });
25
25
  }
26
+ const UNIT_NONE = 0;
27
+ const UNIT_SEQUENCE = 1;
28
+ const UNIT_SINGLE = 2;
29
+ const NO_UNITS = () => UNIT_NONE;
26
30
  function applyEdits(text, edits) {
27
31
  if (edits.length === 0)
28
32
  return text;
@@ -48,6 +52,9 @@ class PlainTarget {
48
52
  this.origin = editedOrigin(this.origin, this.text.length, edits);
49
53
  this.text = applyEdits(this.text, edits);
50
54
  }
55
+ unitAt() {
56
+ return UNIT_NONE;
57
+ }
51
58
  }
52
59
  const traced = (text, origin) => (origin === undefined ? { text } : { text, origin });
53
60
  function editedOrigin(prev, length, edits) {
@@ -87,13 +94,19 @@ class TrackedTarget {
87
94
  src;
88
95
  spans = [];
89
96
  viewLength;
90
- constructor(text, viewLength) {
97
+ units;
98
+ constructor(text, viewLength, units) {
91
99
  this.text = text;
92
100
  this.viewLength = viewLength;
101
+ this.units = units;
93
102
  this.src = new Int32Array(text.length);
94
103
  for (let k = 0; k < text.length; k++)
95
104
  this.src[k] = k;
96
105
  }
106
+ unitAt(k) {
107
+ const s = this.src[k] ?? -1;
108
+ return s >= 0 && this.units !== undefined ? (this.units[s] ?? UNIT_NONE) : UNIT_NONE;
109
+ }
97
110
  rangeStart(k) {
98
111
  const s = this.src[k] ?? 0;
99
112
  return s >= 0 ? s : (this.spans[2 * (-1 - s)] ?? 0);
@@ -344,17 +357,20 @@ function markerSpans(text) {
344
357
  spans.push(hit.index, hit.index + hit[0].length);
345
358
  return spans;
346
359
  }
347
- function schemelessUserinfoEdits(text) {
360
+ function schemelessUserinfoEdits(text, unitAt = NO_UNITS) {
348
361
  const edits = [];
349
362
  const markers = markerSpans(text);
350
363
  let m = 0;
351
364
  let floor = 0;
352
- for (let at = text.indexOf('@'); at !== -1; at = text.indexOf('@', at + 1)) {
353
- const hostEnd = schemelessHostEnd(text, at + 1);
365
+ for (let at = text.indexOf('@'), prevAt = -1; at !== -1; prevAt = at, at = text.indexOf('@', at + 1)) {
366
+ let hostEnd = schemelessHostEnd(text, at + 1);
367
+ const hidden = hostEnd === -1;
368
+ if (hidden)
369
+ hostEnd = hiddenHostEnd(text, at + 1, unitAt);
354
370
  if (hostEnd === -1)
355
371
  continue;
356
372
  let runStart = at;
357
- while (runStart > floor && !breaksUserinfo(text.charCodeAt(runStart - 1)))
373
+ while (runStart > floor && (!breaksUserinfo(text.charCodeAt(runStart - 1)) || (hidden && unitAt(runStart - 1) !== UNIT_NONE)))
358
374
  runStart--;
359
375
  if (text.charCodeAt(runStart) === 0x3a && runStart > floor && text[runStart - 1] === VIEW_SEPARATOR) {
360
376
  while (runStart > floor && text[runStart - 1] === VIEW_SEPARATOR)
@@ -391,16 +407,63 @@ function schemelessUserinfoEdits(text) {
391
407
  }
392
408
  if (found === -1)
393
409
  continue;
410
+ if (hidden && credentialWordAttached(text, prevAt + 1, found, at, unitAt))
411
+ continue;
394
412
  pushEdit(edits, text, found, at, REDACTED_USERINFO);
395
413
  floor = hostEnd;
396
414
  }
397
415
  return edits;
398
416
  }
417
+ function credentialWordAttached(text, lo, found, at, unitAt) {
418
+ if (credentialWordEndsFrom(text.slice(lo, at), found - lo))
419
+ return true;
420
+ const kept = [];
421
+ let joinedFound = -1;
422
+ for (let k = lo; k < at; k++) {
423
+ if (k === found)
424
+ joinedFound = kept.length;
425
+ if (unitAt(k) === UNIT_NONE)
426
+ kept.push(text.charAt(k));
427
+ }
428
+ return joinedFound !== -1 && credentialWordEndsFrom(kept.join(''), joinedFound);
429
+ }
430
+ function credentialWordEndsFrom(seg, from) {
431
+ for (const word of [SECRET_LABELLED_WORD, SECRET_SCHEME_WORD]) {
432
+ const re = new RegExp(word.source, 'gi');
433
+ for (let hit = re.exec(seg); hit !== null; hit = re.exec(seg)) {
434
+ if (hit.index + hit[0].length >= from)
435
+ return true;
436
+ if (hit[0].length === 0)
437
+ re.lastIndex++;
438
+ }
439
+ }
440
+ return false;
441
+ }
442
+ function unitRunEnd(text, from, unitAt) {
443
+ let k = from;
444
+ while (k < text.length && unitAt(k) !== UNIT_NONE)
445
+ k++;
446
+ return k > from ? k : -1;
447
+ }
448
+ function hiddenHostEnd(text, from, unitAt) {
449
+ let k = unitRunEnd(text, from, unitAt);
450
+ if (k === -1)
451
+ return -1;
452
+ if (text.charCodeAt(k) === 0x3a) {
453
+ let d = k + 1;
454
+ while (d < text.length && text.charCodeAt(d) >= 0x30 && text.charCodeAt(d) <= 0x39)
455
+ d++;
456
+ if (d > k + 1)
457
+ k = d;
458
+ }
459
+ const c = text.charCodeAt(k);
460
+ return endsSchemelessHost(c) || c === 0x40 ? k : -1;
461
+ }
399
462
  const MAX_URL_WASH_PASSES = 4;
400
463
  function washUrlNets(target) {
401
464
  for (let pass = 0; pass < MAX_URL_WASH_PASSES; pass++) {
402
465
  target.apply(urlTokenEdits(target.text));
403
- const handedOff = schemelessUserinfoEdits(target.text);
466
+ const handedOff = schemelessUserinfoEdits(target.text, (k) => target.unitAt(k));
404
467
  target.apply(handedOff);
405
468
  if (handedOff.length === 0)
406
469
  return;
@@ -735,6 +798,24 @@ function exemptAddressEdits(src, from, to, edits) {
735
798
  function isAddressShaped(value, raw = value) {
736
799
  return value.startsWith(`${REDACTED_USERINFO}@`) || ADDRESS_SCHEME_RE.test(raw);
737
800
  }
801
+ function gluedToSingleUnit(at, floor, unitAt) {
802
+ for (let k = at - 1; k >= floor; k--) {
803
+ const u = unitAt(k);
804
+ if (u === UNIT_SINGLE)
805
+ return true;
806
+ if (u === UNIT_NONE)
807
+ return false;
808
+ }
809
+ return false;
810
+ }
811
+ function userinfoHostHidden(text, at, unitAt) {
812
+ if (!text.startsWith(REDACTED_USERINFO, at))
813
+ return false;
814
+ let k = at + REDACTED_USERINFO.length;
815
+ while (text[k] === VIEW_SEPARATOR)
816
+ k++;
817
+ return text[k] === '@' && unitRunEnd(text, k + 1, unitAt) !== -1;
818
+ }
738
819
  function addressExtentEnd(text, from) {
739
820
  let end = from;
740
821
  while (end < text.length) {
@@ -800,7 +881,7 @@ function trailingLabelStart(text, from, end) {
800
881
  }
801
882
  const withoutSeparators = (s) => (s.includes(VIEW_SEPARATOR) ? s.split(VIEW_SEPARATOR).join('') : s);
802
883
  const isHorizontalSpace = (ch) => ch === ' ' || ch === '\t' || ch === '\u00a0' || ch === VIEW_SEPARATOR;
803
- function labelEdits(text, re, literalBlanks = false) {
884
+ function labelEdits(text, re, literalBlanks = false, unitAt = NO_UNITS) {
804
885
  const edits = [];
805
886
  const schemePass = re === SECRET_SCHEME_WORD;
806
887
  const idx = new InnerWordIndex(text);
@@ -864,6 +945,18 @@ function labelEdits(text, re, literalBlanks = false) {
864
945
  const trailing = trailingLabelStart(text, v.start, end);
865
946
  if (trailing !== -1)
866
947
  end = v.start + trailing;
948
+ if (gluedToSingleUnit(v.start, hit.index, unitAt) || userinfoHostHidden(text, v.start, unitAt)) {
949
+ const cut = trailing !== -1 ? end : Math.max(end, v.end);
950
+ const keep = ADDRESS_SCHEME_RE.exec(text.slice(v.start, v.start + 20))?.[0].length ?? 0;
951
+ const q = text.slice(v.start, cut).search(/[?#]/);
952
+ const bodyEnd = q === -1 ? cut : v.start + q;
953
+ if (withoutSeparators(text.slice(v.start + keep, bodyEnd)) !== '')
954
+ pushEdit(edits, text, v.start + keep, bodyEnd, REDACTED_SECRET);
955
+ if (q !== -1 && v.start + q + 1 < cut)
956
+ pushEdit(edits, text, v.start + q + 1, cut, text.charAt(v.start + q) === '#' ? REDACTED_FRAGMENT : REDACTED_QUERY);
957
+ re.lastIndex = cut;
958
+ continue;
959
+ }
867
960
  exemptAddressEdits(text, v.start, end, edits);
868
961
  re.lastIndex = end;
869
962
  continue;
@@ -1096,9 +1189,10 @@ function proseLiteralEdits(text) {
1096
1189
  return edits;
1097
1190
  }
1098
1191
  function washWordNets(target, literalBlanks = false) {
1192
+ const unitAt = (k) => target.unitAt(k);
1099
1193
  target.apply(pemEdits(target.text));
1100
- target.apply(labelEdits(target.text, SECRET_SCHEME_WORD, literalBlanks));
1101
- target.apply(labelEdits(target.text, SECRET_LABELLED_WORD, literalBlanks));
1194
+ target.apply(labelEdits(target.text, SECRET_SCHEME_WORD, literalBlanks, unitAt));
1195
+ target.apply(labelEdits(target.text, SECRET_LABELLED_WORD, literalBlanks, unitAt));
1102
1196
  target.apply(authParamEdits(target.text));
1103
1197
  target.apply(proseLiteralEdits(target.text));
1104
1198
  }
@@ -1264,35 +1358,37 @@ function buildCredentialView(text, separated, wordLetters = false, blankTokens =
1264
1358
  const chars = [];
1265
1359
  const starts = [];
1266
1360
  const ends = [];
1361
+ const units = [];
1267
1362
  let changed = false;
1268
1363
  let splitAny = false;
1269
1364
  const seq = new SequenceReader(text, blankTokens === 'blank' || blankTokens === 'fold' ? 'all' : blankTokens === 'foldlit' ? 'folded' : 'none', folding);
1270
- const keep = (ch, s, e) => {
1365
+ const keep = (ch, s, e, unit = UNIT_NONE) => {
1271
1366
  chars.push(ch);
1272
1367
  starts.push(s);
1273
1368
  ends.push(e);
1369
+ units.push(unit);
1274
1370
  };
1275
- const drop = (s, e, placeholder = VIEW_SEPARATOR) => {
1371
+ const drop = (s, e, placeholder = VIEW_SEPARATOR, unit = UNIT_SINGLE) => {
1276
1372
  changed = true;
1277
1373
  if (separated)
1278
- keep(placeholder, s, e);
1374
+ keep(placeholder, s, e, unit);
1279
1375
  };
1280
1376
  const dropUnit = (s, unit) => {
1281
1377
  const last = unit.end - 1;
1282
1378
  if ((blankTokens === 'literal' || blankTokens === 'foldlit') && last > s && text.charCodeAt(last) === 0x5c && nameBlankTokenAt(text, last) !== -1) {
1283
- drop(s, last);
1379
+ drop(s, last, VIEW_SEPARATOR, UNIT_SEQUENCE);
1284
1380
  keep(text.charAt(last + 1), last, last + 6);
1285
1381
  for (let u = 2; u < 6; u++)
1286
1382
  keep(text.charAt(last + u), last + 6, last + 6);
1287
1383
  return last + 6;
1288
1384
  }
1289
1385
  if (wordLetters && unit.content === undefined && last > s && (credentialWordBeginsWith(text, last) || finalIsStructural(text, last))) {
1290
- drop(s, last);
1386
+ drop(s, last, VIEW_SEPARATOR, UNIT_SEQUENCE);
1291
1387
  keep(text.charAt(last), last, unit.end);
1292
1388
  splitAny = true;
1293
1389
  return unit.end;
1294
1390
  }
1295
- drop(s, unit.end);
1391
+ drop(s, unit.end, VIEW_SEPARATOR, UNIT_SEQUENCE);
1296
1392
  return unit.end;
1297
1393
  };
1298
1394
  let i = 0;
@@ -1326,7 +1422,7 @@ function buildCredentialView(text, separated, wordLetters = false, blankTokens =
1326
1422
  i = dropUnit(i, unit);
1327
1423
  continue;
1328
1424
  }
1329
- drop(i, tok.end, ' ');
1425
+ drop(i, tok.end, ' ', isRegexSpace(tok.cp) && tok.cp !== 0xfeff ? UNIT_NONE : UNIT_SINGLE);
1330
1426
  i = tok.end;
1331
1427
  continue;
1332
1428
  }
@@ -1373,7 +1469,7 @@ function buildCredentialView(text, separated, wordLetters = false, blankTokens =
1373
1469
  }
1374
1470
  if (!changed || (wordLetters && !splitAny))
1375
1471
  return null;
1376
- return { view: chars.join(''), starts: Int32Array.from(starts), ends: Int32Array.from(ends) };
1472
+ return { view: chars.join(''), starts: Int32Array.from(starts), ends: Int32Array.from(ends), units: Uint8Array.from(units) };
1377
1473
  }
1378
1474
  function finalIsStructural(text, at) {
1379
1475
  if (text.charCodeAt(at) !== 0x5c)
@@ -1460,7 +1556,7 @@ function rebuildFromView(original, view, target, trace = false) {
1460
1556
  return origin === null ? { text: rebuilt } : { text: rebuilt, origin: Int32Array.from(origin) };
1461
1557
  }
1462
1558
  function washThroughView(original, view, urls, words, trace = false, literalBlanks = false) {
1463
- const target = new TrackedTarget(view.view, view.view.length);
1559
+ const target = new TrackedTarget(view.view, view.view.length, view.units);
1464
1560
  runCredentialNets(target, urls, words, literalBlanks);
1465
1561
  return target.text === view.view ? { text: original } : rebuildFromView(original, view, target, trace);
1466
1562
  }
@@ -1,2 +1,3 @@
1
- export type ReasoningEffort = 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
1
+ import { type TaskRequestReasoningEffort } from './taskRequestWords.js';
2
+ export type ReasoningEffort = TaskRequestReasoningEffort;
2
3
  export declare function effortToReasoningEffort(effort: unknown): ReasoningEffort | undefined;
@@ -1,7 +1,5 @@
1
- const REASONING_EFFORT_TUPLE = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
2
- const _effortPins = [true, true];
3
- void _effortPins;
4
- const REASONING_EFFORTS = new Set(REASONING_EFFORT_TUPLE);
1
+ import { REASONING_EFFORT_WORDS } from './taskRequestWords.js';
2
+ const REASONING_EFFORTS = new Set(REASONING_EFFORT_WORDS);
5
3
  export function effortToReasoningEffort(effort) {
6
4
  return typeof effort === 'string' && REASONING_EFFORTS.has(effort) ? effort : undefined;
7
5
  }
@@ -12,6 +12,7 @@ export declare const CONFIG_LIMIT_UNKNOWN_KEY = "config.limit_unknown_key";
12
12
  export declare const CONFIG_DELEGATION_ENTRY_CAPS = "config.delegation_entry_caps";
13
13
  export declare const CONFIG_MEMORY_PROJECT_KEY_SPELLING = "config.memory_project_key_spelling";
14
14
  export declare const CONFIG_MEMORY_WRITE_SCOPE_MISMATCH = "config.memory_write_scope_mismatch";
15
+ export declare const CONFIG_LEGACY_TOOL_NAME = "config.legacy_tool_name";
15
16
  export declare const CONFIG_REFUSAL_CODES: ReadonlySet<string>;
16
17
  export declare const DELEGATION_CONCURRENCY_CAP = "delegation.concurrency_cap";
17
18
  export declare const DELEGATION_SESSION_CAP = "delegation.session_cap";
@@ -27,6 +28,8 @@ export declare function isInterruptedToolEndCode(code: string | undefined): bool
27
28
  export declare const CAPABILITY_SELF_ORCHESTRATION_REQUIRED = "capability.self_orchestration_required";
28
29
  export declare const GATE_PARKED_ERROR_CODE = "gate.parked";
29
30
  export declare const ACTIVE_RUN_BUSY_ERROR_CODE = "conflict.session_active_run";
31
+ export declare const CORRUPT_SESSION_ERROR_CODE = "corrupt_session";
32
+ export declare function isCorruptSessionCode(code: string | null | undefined): boolean;
30
33
  export declare const STOP_PARK_ARBITER_UNREACHABLE = "stop.park_arbiter_unreachable";
31
34
  export declare const STOP_PARK_RESUME_WON = "stop.park_resume_won";
32
35
  export declare const STOP_NOT_LANDED = "stop.not_landed";
@@ -35,6 +38,8 @@ export declare const STOP_PARKED = "stop.parked";
35
38
  export declare const STOP_CONFLICT_CODES: readonly ["stop.park_arbiter_unreachable", "stop.park_resume_won", "stop.not_landed", "stop.not_local", "stop.parked"];
36
39
  export declare const OUTPUT_INVALID = "output.invalid";
37
40
  export declare const RESUME_POLICY_FOLD_CODE = "resume_blocked_by_policy";
41
+ export declare const STATUS_DERIVED_COARSE_CODES: readonly ["request.rejected", "auth.unauthorized", "auth.forbidden", "not_found.resource", "request.payload_too_large", "request.unprocessable", "limit.rate_exceeded", "capability.unavailable", "internal.error"];
42
+ export declare function isStatusDerivedCoarseCode(code: string | null | undefined): boolean;
38
43
  export declare const RESUME_AT_ERROR_CODE_PREFIX = "resume_at.";
39
44
  export declare const REWIND_ERROR_CODE_PREFIXES: readonly ["resume_at.", "rewind_snapshot."];
40
45
  export declare function isRewindFamilyCode(code: string | undefined): boolean;
@@ -47,9 +52,15 @@ export declare const RESUME_ENV_FAILED = "resume.env_failed";
47
52
  export declare const RESUME_TOOL_UNAVAILABLE = "resume.tool_unavailable";
48
53
  export declare const RESUME_TOOL_CONTRACT_MISMATCH = "resume.tool_contract_mismatch";
49
54
  export declare const RESUME_REOPEN_CODES: readonly string[];
55
+ export declare const PARKED_RESUME_STARTUP_FAILED = "parked_resume.startup_failed";
50
56
  export declare const DECIDE_WORKFLOW_HOST_UNKNOWN = "decide.workflow_host_unknown";
51
57
  export declare const DECIDE_WORKFLOW_REMEMBER_UNSUPPORTED = "decide.workflow_remember_unsupported";
52
58
  export declare const DECIDE_WORKFLOW_LANE_CODES: readonly string[];
59
+ export declare const DECIDE_NOT_PARKED = "decide.not_parked";
60
+ export declare const DECIDE_GATE_MOVED = "decide.gate_moved";
61
+ export declare const DECIDE_CLAIM_LOST = "decide.claim_lost";
62
+ export declare const DECIDE_PARK_MOVED_CODES: readonly string[];
63
+ export declare function isDecideParkMovedCode(code: string | null | undefined): boolean;
53
64
  export declare const WORKFLOW_PARK_REFUSAL_CODES: readonly string[];
54
65
  export declare function isWorkflowParkRefusalCode(code: unknown): boolean;
55
66
  export declare const DRAINING_ERROR_CODE = "draining";
@@ -16,6 +16,7 @@ export const CONFIG_LIMIT_UNKNOWN_KEY = 'config.limit_unknown_key';
16
16
  export const CONFIG_DELEGATION_ENTRY_CAPS = 'config.delegation_entry_caps';
17
17
  export const CONFIG_MEMORY_PROJECT_KEY_SPELLING = 'config.memory_project_key_spelling';
18
18
  export const CONFIG_MEMORY_WRITE_SCOPE_MISMATCH = 'config.memory_write_scope_mismatch';
19
+ export const CONFIG_LEGACY_TOOL_NAME = 'config.legacy_tool_name';
19
20
  export const CONFIG_REFUSAL_CODES = frozenSet([
20
21
  CONFIG_LIMIT_INVALID,
21
22
  CONFIG_STRATEGY_FIND_LIMIT_INVALID,
@@ -24,6 +25,7 @@ export const CONFIG_REFUSAL_CODES = frozenSet([
24
25
  CONFIG_DELEGATION_ENTRY_CAPS,
25
26
  CONFIG_MEMORY_PROJECT_KEY_SPELLING,
26
27
  CONFIG_MEMORY_WRITE_SCOPE_MISMATCH,
28
+ CONFIG_LEGACY_TOOL_NAME,
27
29
  ]);
28
30
  export const DELEGATION_CONCURRENCY_CAP = 'delegation.concurrency_cap';
29
31
  export const DELEGATION_SESSION_CAP = 'delegation.session_cap';
@@ -57,6 +59,10 @@ export function isInterruptedToolEndCode(code) {
57
59
  export const CAPABILITY_SELF_ORCHESTRATION_REQUIRED = 'capability.self_orchestration_required';
58
60
  export const GATE_PARKED_ERROR_CODE = 'gate.parked';
59
61
  export const ACTIVE_RUN_BUSY_ERROR_CODE = 'conflict.session_active_run';
62
+ export const CORRUPT_SESSION_ERROR_CODE = 'corrupt_session';
63
+ export function isCorruptSessionCode(code) {
64
+ return code === CORRUPT_SESSION_ERROR_CODE;
65
+ }
60
66
  export const STOP_PARK_ARBITER_UNREACHABLE = 'stop.park_arbiter_unreachable';
61
67
  export const STOP_PARK_RESUME_WON = 'stop.park_resume_won';
62
68
  export const STOP_NOT_LANDED = 'stop.not_landed';
@@ -71,6 +77,20 @@ export const STOP_CONFLICT_CODES = Object.freeze([
71
77
  ]);
72
78
  export const OUTPUT_INVALID = 'output.invalid';
73
79
  export const RESUME_POLICY_FOLD_CODE = 'resume_blocked_by_policy';
80
+ export const STATUS_DERIVED_COARSE_CODES = Object.freeze([
81
+ 'request.rejected',
82
+ 'auth.unauthorized',
83
+ 'auth.forbidden',
84
+ 'not_found.resource',
85
+ 'request.payload_too_large',
86
+ 'request.unprocessable',
87
+ 'limit.rate_exceeded',
88
+ 'capability.unavailable',
89
+ 'internal.error',
90
+ ]);
91
+ export function isStatusDerivedCoarseCode(code) {
92
+ return typeof code === 'string' && STATUS_DERIVED_COARSE_CODES.includes(code);
93
+ }
74
94
  export const RESUME_AT_ERROR_CODE_PREFIX = 'resume_at.';
75
95
  export const REWIND_ERROR_CODE_PREFIXES = Object.freeze([RESUME_AT_ERROR_CODE_PREFIX, 'rewind_snapshot.']);
76
96
  export function isRewindFamilyCode(code) {
@@ -92,12 +112,24 @@ export const RESUME_REOPEN_CODES = Object.freeze([
92
112
  RESUME_TOOL_UNAVAILABLE,
93
113
  RESUME_TOOL_CONTRACT_MISMATCH,
94
114
  ]);
115
+ export const PARKED_RESUME_STARTUP_FAILED = 'parked_resume.startup_failed';
95
116
  export const DECIDE_WORKFLOW_HOST_UNKNOWN = 'decide.workflow_host_unknown';
96
117
  export const DECIDE_WORKFLOW_REMEMBER_UNSUPPORTED = 'decide.workflow_remember_unsupported';
97
118
  export const DECIDE_WORKFLOW_LANE_CODES = Object.freeze([
98
119
  DECIDE_WORKFLOW_HOST_UNKNOWN,
99
120
  DECIDE_WORKFLOW_REMEMBER_UNSUPPORTED,
100
121
  ]);
122
+ export const DECIDE_NOT_PARKED = 'decide.not_parked';
123
+ export const DECIDE_GATE_MOVED = 'decide.gate_moved';
124
+ export const DECIDE_CLAIM_LOST = 'decide.claim_lost';
125
+ export const DECIDE_PARK_MOVED_CODES = Object.freeze([
126
+ DECIDE_NOT_PARKED,
127
+ DECIDE_GATE_MOVED,
128
+ DECIDE_CLAIM_LOST,
129
+ ]);
130
+ export function isDecideParkMovedCode(code) {
131
+ return typeof code === 'string' && DECIDE_PARK_MOVED_CODES.includes(code);
132
+ }
101
133
  const WORKFLOW_PARK_TRUTH_UNREADABLE = 'workflow.park_truth_unreadable';
102
134
  const WORKFLOW_PARK_NOT_PENDING = 'workflow.park_not_pending';
103
135
  const WORKFLOW_PARK_BINDING_BROKEN = 'workflow.park_binding_broken';
@@ -1,5 +1,6 @@
1
1
  export type NoticeAudience = 'user' | 'operator';
2
2
  export declare const ENGINE_NOTICE_CODES: readonly string[];
3
+ export declare const SERVER_NOTICE_AUDIENCE: Readonly<Record<string, NoticeAudience>>;
3
4
  export declare function engineNoticeInCatalog(code: unknown): boolean;
4
5
  export declare const ENGINE_NOTICE_AUDIENCE: Readonly<Record<string, NoticeAudience>>;
5
6
  export declare function noticeAudienceOf(code: unknown): NoticeAudience;
@@ -65,7 +66,41 @@ export type ReadRootGrantNoticeFactsView = {
65
66
  reason?: string;
66
67
  sessionId?: string;
67
68
  };
68
- export declare function readReadRootGrantNotice(notice: {
69
- readonly code?: string;
70
- readonly detail?: object | null;
71
- } | null | undefined): ReadRootGrantNoticeFactsView | undefined;
69
+ export declare function readReadRootGrantNotice(notice: unknown): ReadRootGrantNoticeFactsView | undefined;
70
+ export interface InstructionsSourceChangedFactsView {
71
+ previous: string | null;
72
+ current: string | null;
73
+ sessionId: string;
74
+ }
75
+ export declare function readInstructionsSourceChanged(notice: unknown): InstructionsSourceChangedFactsView | undefined;
76
+ export type NoticeCountReading = number | 'unknown';
77
+ export interface SessionRecordsSkippedFactsView {
78
+ dropped: NoticeCountReading;
79
+ entriesKept: NoticeCountReading;
80
+ sessionId: string;
81
+ }
82
+ export declare function readSessionRecordsSkipped(notice: unknown): SessionRecordsSkippedFactsView | undefined;
83
+ export declare function sessionRecordsSkippedNote(facts: Pick<SessionRecordsSkippedFactsView, 'entriesKept'>): string | undefined;
84
+ export declare const ENGINE_NOTICE_FACT_READERS: Readonly<{
85
+ readonly 'mcp.injection_dropped': typeof readMcpInjectionDrop;
86
+ readonly 'delegation.ask_unresolvable': typeof readAskUnresolvable;
87
+ readonly 'config.durable_gate_unavailable': typeof readDurableGateUnavailable;
88
+ readonly 'skills.listing_truncated': typeof readSkillsListingTruncated;
89
+ readonly 'mcp.server_redialed': typeof readMcpServerRedialed;
90
+ readonly 'instructions.source_changed': typeof readInstructionsSourceChanged;
91
+ readonly 'approval.read_root_granted': typeof readReadRootGrantNotice;
92
+ readonly 'approval.read_root_grant_rejected': typeof readReadRootGrantNotice;
93
+ readonly 'session.records_skipped': typeof readSessionRecordsSkipped;
94
+ }>;
95
+ type FactReaderTable = typeof ENGINE_NOTICE_FACT_READERS;
96
+ export type EngineNoticeFactsCode = keyof FactReaderTable;
97
+ export interface EngineNoticeFactsOf<K extends EngineNoticeFactsCode> {
98
+ code: K;
99
+ audience: NoticeAudience;
100
+ facts: Exclude<ReturnType<FactReaderTable[K]>, undefined>;
101
+ }
102
+ export type EngineNoticeFacts = {
103
+ [K in EngineNoticeFactsCode]: EngineNoticeFactsOf<K>;
104
+ }[EngineNoticeFactsCode];
105
+ export declare function readEngineNoticeFacts(notice: unknown): EngineNoticeFacts | undefined;
106
+ export {};