@sema-agent/client-core 0.84.0 → 0.84.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +12 -5
  3. package/dist/abortableSleep.d.ts +10 -0
  4. package/dist/abortableSleep.js +37 -0
  5. package/dist/adapter/downstream/terminalToSdkResult.d.ts +1 -0
  6. package/dist/adapter/downstream/terminalToSdkResult.js +10 -5
  7. package/dist/agentsWireCaps.js +8 -0
  8. package/dist/decideFailureNote.d.ts +2 -1
  9. package/dist/decideFailureNote.js +5 -3
  10. package/dist/detachWire.d.ts +1 -0
  11. package/dist/detachWire.js +13 -5
  12. package/dist/displayUntrusted.js +114 -18
  13. package/dist/engineErrorCodes.d.ts +2 -0
  14. package/dist/engineErrorCodes.js +3 -0
  15. package/dist/engineNoticeCodes.d.ts +30 -4
  16. package/dist/engineNoticeCodes.js +73 -5
  17. package/dist/engineWireSdk.d.ts +2 -0
  18. package/dist/hitl/askGateWire.d.ts +1 -1
  19. package/dist/hitl/askGateWire.js +1 -1
  20. package/dist/hitl/hitlHostSurface.js +1 -1
  21. package/dist/hitl/parkResolver.d.ts +1 -0
  22. package/dist/hitl/parkResolver.js +9 -3
  23. package/dist/hitl/planReviewWire.d.ts +30 -3
  24. package/dist/hitl/planReviewWire.js +139 -32
  25. package/dist/hitl/sessionPolicyDeliverable.d.ts +2 -0
  26. package/dist/hitl/sessionPolicyDeliverable.js +14 -3
  27. package/dist/hitl/sessionPolicyWire.d.ts +40 -0
  28. package/dist/hitl/sessionPolicyWire.js +210 -0
  29. package/dist/hitl/toolApprovalWire.js +2 -2
  30. package/dist/index.d.ts +2 -1
  31. package/dist/index.js +2 -1
  32. package/dist/liveInitToolFace.js +28 -10
  33. package/dist/resumeRefusalCopy.d.ts +11 -0
  34. package/dist/resumeRefusalCopy.js +39 -1
  35. package/dist/systemReminderTag.d.ts +5 -0
  36. package/dist/systemReminderTag.js +20 -9
  37. package/docs/INTEGRATION-CLIENTS.md +461 -16
  38. package/package.json +1 -1
@@ -40,14 +40,15 @@ function joinableToolInput(args) {
40
40
  if (args === null || typeof args !== 'object' || Array.isArray(args))
41
41
  return undefined;
42
42
  let nodes = 0;
43
+ let transportRedacted = false;
43
44
  const stack = [{ v: args, depth: 0 }];
44
45
  while (stack.length > 0) {
45
46
  const { v, depth } = stack.pop();
46
47
  if (++nodes > TOOL_INPUT_SCAN_MAX_NODES || depth > TOOL_INPUT_SCAN_MAX_DEPTH)
47
48
  return undefined;
48
49
  if (typeof v === 'string') {
49
- if (v.includes(REDACTION_MARKER_PREFIX) || isTransportPlaceholderLeaf(v))
50
- return undefined;
50
+ if (!transportRedacted && (v.includes(REDACTION_MARKER_PREFIX) || isTransportPlaceholderLeaf(v)))
51
+ transportRedacted = true;
51
52
  continue;
52
53
  }
53
54
  if (v === null || typeof v !== 'object')
@@ -56,7 +57,7 @@ function joinableToolInput(args) {
56
57
  for (const c of children)
57
58
  stack.push({ v: c, depth: depth + 1 });
58
59
  }
59
- return args;
60
+ return { input: args, transportRedacted };
60
61
  }
61
62
  const GATE_DENIED_DECISIONS = new Set(['deny']);
62
63
  const GATE_NON_DENIAL_DECISIONS = new Set(['allow', 'approve', 'edit', 'reject']);
@@ -92,9 +93,10 @@ function permissionDenialParts(stats, observed) {
92
93
  const ledgerInput = rawInput !== null && typeof rawInput === 'object' && !Array.isArray(rawInput)
93
94
  ? rawInput
94
95
  : undefined;
95
- const joinedInput = ledgerInput === undefined && toolUseId !== undefined && toolInputByCallId?.has(toolUseId) === true
96
+ const joined = ledgerInput === undefined && toolUseId !== undefined && toolInputByCallId?.has(toolUseId) === true
96
97
  ? joinableToolInput(toolInputByCallId.get(toolUseId))
97
98
  : undefined;
99
+ const joinedInput = joined?.input;
98
100
  const toolInput = ledgerInput ?? joinedInput;
99
101
  const ledgerDeniedByRaw = row.deniedBy;
100
102
  const ledgerDeniedBy = typeof ledgerDeniedByRaw === 'string' && isGateDeniedByWord(ledgerDeniedByRaw)
@@ -116,6 +118,7 @@ function permissionDenialParts(stats, observed) {
116
118
  ...(toolUseId !== undefined ? { tool_use_id: toolUseId } : {}),
117
119
  ...(toolInput !== undefined ? { tool_input: toolInput } : {}),
118
120
  ...(joinedInput !== undefined ? { _sema_tool_input_source: 'tool_start' } : {}),
121
+ ...(joined?.transportRedacted === true ? { _sema_tool_input_redacted: true } : {}),
119
122
  ...(deniedBy !== undefined ? { deniedBy } : {}),
120
123
  ...(joinedDeniedBy !== undefined && ledgerDeniedBy === undefined
121
124
  ? { _sema_denied_by_source: 'tool_end' }
@@ -145,7 +148,8 @@ function permissionDenialParts(stats, observed) {
145
148
  continue;
146
149
  }
147
150
  const toolName = nonEmptyStr(toolNameRaw);
148
- const joinedInput = toolInputByCallId?.has(callId) === true ? joinableToolInput(toolInputByCallId.get(callId)) : undefined;
151
+ const joined = toolInputByCallId?.has(callId) === true ? joinableToolInput(toolInputByCallId.get(callId)) : undefined;
152
+ const joinedInput = joined?.input;
149
153
  const deniedByRaw = gateDeniedByByCallId?.has(callId) === true ? gateDeniedByByCallId.get(callId) : undefined;
150
154
  const deniedBy = typeof deniedByRaw === 'string' && isGateDeniedByWord(deniedByRaw) ? deniedByRaw : undefined;
151
155
  const toolDenialKind = isCcToolDenialKind(mergedKind) ? mergedKind : undefined;
@@ -153,6 +157,7 @@ function permissionDenialParts(stats, observed) {
153
157
  ...(toolName !== undefined ? { tool_name: toolName } : {}),
154
158
  tool_use_id: callId,
155
159
  ...(joinedInput !== undefined ? { tool_input: joinedInput, _sema_tool_input_source: 'tool_start' } : {}),
160
+ ...(joined?.transportRedacted === true ? { _sema_tool_input_redacted: true } : {}),
156
161
  ...(deniedBy !== undefined ? { deniedBy, _sema_denied_by_source: 'tool_end' } : {}),
157
162
  ...(toolDenialKind !== undefined ? { toolDenialKind } : {}),
158
163
  });
@@ -1,6 +1,7 @@
1
1
  import { hostEnv } from './hostEnv.js';
2
2
  import { makeEngineWireClient } from './engineWireSdk.js';
3
3
  import { frozenSet } from './frozenSet.js';
4
+ import { settleWithinDeadline } from './abortableSleep.js';
4
5
  export const MAX_TASK_AGENTS = 32;
5
6
  export const MAX_AGENT_NAME_CHARS = 64;
6
7
  export const MAX_AGENT_TEXT_CHARS = 4_096;
@@ -173,6 +174,13 @@ export function projectAgentsForWire(defs, deps) {
173
174
  return { agents: out.length > 0 ? out : undefined, warnings };
174
175
  }
175
176
  export async function engineSupportsTaskAgents(baseUrl, opts) {
177
+ if (opts?.client !== undefined) {
178
+ const injected = opts.client;
179
+ if (typeof injected?.capabilities !== 'function')
180
+ return undefined;
181
+ const got = await settleWithinDeadline(opts.timeoutMs ?? 3000, (signal) => injected.capabilities({ signal }));
182
+ return got.kind === 'value' ? got.value?.taskAgents === true : undefined;
183
+ }
176
184
  const client = makeEngineWireClient({
177
185
  baseUrl,
178
186
  ...(opts?.authToken ? { token: opts.authToken } : {}),
@@ -1 +1,2 @@
1
- export declare function decideFailureNote(err: unknown): string;
1
+ import { type ParkedResumeStartupDecision } from './resumeRefusalCopy.js';
2
+ export declare function decideFailureNote(err: unknown, decision?: ParkedResumeStartupDecision): string;
@@ -1,8 +1,10 @@
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
+ export function decideFailureNote(err, decision) {
4
4
  const where = corruptStoredRowWhere(err);
5
5
  const fold = resumePolicyBlockFromError(err);
6
+ const startup = parkedResumeStartupFromError(err, decision);
6
7
  return ((where === undefined ? '' : ` — ${corruptStoredRowContent(where)}`) +
7
- (fold === null ? '' : ` — ${resumePolicyBlockContent(fold)}`));
8
+ (fold === null ? '' : ` — ${resumePolicyBlockContent(fold)}`) +
9
+ (startup === null ? '' : ` — ${parkedResumeStartupContent(startup)}`));
8
10
  }
@@ -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
  }
@@ -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";
@@ -47,6 +48,7 @@ export declare const RESUME_ENV_FAILED = "resume.env_failed";
47
48
  export declare const RESUME_TOOL_UNAVAILABLE = "resume.tool_unavailable";
48
49
  export declare const RESUME_TOOL_CONTRACT_MISMATCH = "resume.tool_contract_mismatch";
49
50
  export declare const RESUME_REOPEN_CODES: readonly string[];
51
+ export declare const PARKED_RESUME_STARTUP_FAILED = "parked_resume.startup_failed";
50
52
  export declare const DECIDE_WORKFLOW_HOST_UNKNOWN = "decide.workflow_host_unknown";
51
53
  export declare const DECIDE_WORKFLOW_REMEMBER_UNSUPPORTED = "decide.workflow_remember_unsupported";
52
54
  export declare const DECIDE_WORKFLOW_LANE_CODES: readonly string[];
@@ -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';
@@ -92,6 +94,7 @@ export const RESUME_REOPEN_CODES = Object.freeze([
92
94
  RESUME_TOOL_UNAVAILABLE,
93
95
  RESUME_TOOL_CONTRACT_MISMATCH,
94
96
  ]);
97
+ export const PARKED_RESUME_STARTUP_FAILED = 'parked_resume.startup_failed';
95
98
  export const DECIDE_WORKFLOW_HOST_UNKNOWN = 'decide.workflow_host_unknown';
96
99
  export const DECIDE_WORKFLOW_REMEMBER_UNSUPPORTED = 'decide.workflow_remember_unsupported';
97
100
  export const DECIDE_WORKFLOW_LANE_CODES = Object.freeze([
@@ -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,32 @@ 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 declare const ENGINE_NOTICE_FACT_READERS: Readonly<{
77
+ readonly 'mcp.injection_dropped': typeof readMcpInjectionDrop;
78
+ readonly 'delegation.ask_unresolvable': typeof readAskUnresolvable;
79
+ readonly 'config.durable_gate_unavailable': typeof readDurableGateUnavailable;
80
+ readonly 'skills.listing_truncated': typeof readSkillsListingTruncated;
81
+ readonly 'mcp.server_redialed': typeof readMcpServerRedialed;
82
+ readonly 'instructions.source_changed': typeof readInstructionsSourceChanged;
83
+ readonly 'approval.read_root_granted': typeof readReadRootGrantNotice;
84
+ readonly 'approval.read_root_grant_rejected': typeof readReadRootGrantNotice;
85
+ }>;
86
+ type FactReaderTable = typeof ENGINE_NOTICE_FACT_READERS;
87
+ export type EngineNoticeFactsCode = keyof FactReaderTable;
88
+ export interface EngineNoticeFactsOf<K extends EngineNoticeFactsCode> {
89
+ code: K;
90
+ audience: NoticeAudience;
91
+ facts: Exclude<ReturnType<FactReaderTable[K]>, undefined>;
92
+ }
93
+ export type EngineNoticeFacts = {
94
+ [K in EngineNoticeFactsCode]: EngineNoticeFactsOf<K>;
95
+ }[EngineNoticeFactsCode];
96
+ export declare function readEngineNoticeFacts(notice: unknown): EngineNoticeFacts | undefined;
97
+ export {};
@@ -74,8 +74,15 @@ export const ENGINE_NOTICE_CODES = Object.freeze([
74
74
  'tool_result.offload_put_failed',
75
75
  ]);
76
76
  const CATALOG = new Set(ENGINE_NOTICE_CODES);
77
+ export const SERVER_NOTICE_AUDIENCE = Object.freeze({
78
+ 'instructions.source_changed': 'user',
79
+ 'memory.layer_locked_legacy': 'operator',
80
+ });
81
+ function audienceRow(table, code) {
82
+ return Object.hasOwn(table, code) ? table[code] : undefined;
83
+ }
77
84
  export function engineNoticeInCatalog(code) {
78
- return typeof code === 'string' && CATALOG.has(code);
85
+ return typeof code === 'string' && (CATALOG.has(code) || Object.hasOwn(SERVER_NOTICE_AUDIENCE, code));
79
86
  }
80
87
  export const ENGINE_NOTICE_AUDIENCE = Object.freeze({
81
88
  'config.autocompact_window_clamped': 'operator',
@@ -153,10 +160,9 @@ export const ENGINE_NOTICE_AUDIENCE = Object.freeze({
153
160
  'tool_result.offload_put_failed': 'operator',
154
161
  });
155
162
  export function noticeAudienceOf(code) {
156
- const row = typeof code === 'string' && Object.hasOwn(ENGINE_NOTICE_AUDIENCE, code)
157
- ? ENGINE_NOTICE_AUDIENCE[code]
158
- : undefined;
159
- return row ?? 'operator';
163
+ if (typeof code !== 'string')
164
+ return 'operator';
165
+ return audienceRow(ENGINE_NOTICE_AUDIENCE, code) ?? audienceRow(SERVER_NOTICE_AUDIENCE, code) ?? 'operator';
160
166
  }
161
167
  export const MCP_INJECTION_DROP_REASONS = Object.freeze([
162
168
  'malformed_entry',
@@ -348,3 +354,65 @@ function readRootGrantNoticeOf(notice) {
348
354
  const reason = str(o.reason);
349
355
  return { outcome: 'rejected', toolCallId, ...(reason !== undefined ? { reason } : {}), ...(sessionId !== undefined ? { sessionId } : {}) };
350
356
  }
357
+ function ownPathOrNull(o, key) {
358
+ if (!Object.hasOwn(o, key))
359
+ return undefined;
360
+ const v = o[key];
361
+ if (v === null)
362
+ return null;
363
+ return typeof v === 'string' && v.length > 0 ? v : undefined;
364
+ }
365
+ export function readInstructionsSourceChanged(notice) {
366
+ if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
367
+ return undefined;
368
+ try {
369
+ const n = notice;
370
+ if (n.code !== 'instructions.source_changed')
371
+ return undefined;
372
+ const d = n.detail;
373
+ if (typeof d !== 'object' || d === null || Array.isArray(d))
374
+ return undefined;
375
+ const o = d;
376
+ const previous = ownPathOrNull(o, 'previous');
377
+ const current = ownPathOrNull(o, 'current');
378
+ const sessionId = typeof o.sessionId === 'string' && o.sessionId.length > 0 ? o.sessionId : undefined;
379
+ if (previous === undefined || current === undefined || sessionId === undefined)
380
+ return undefined;
381
+ return { previous, current, sessionId };
382
+ }
383
+ catch {
384
+ return undefined;
385
+ }
386
+ }
387
+ export const ENGINE_NOTICE_FACT_READERS = Object.freeze({
388
+ 'mcp.injection_dropped': readMcpInjectionDrop,
389
+ 'delegation.ask_unresolvable': readAskUnresolvable,
390
+ 'config.durable_gate_unavailable': readDurableGateUnavailable,
391
+ 'skills.listing_truncated': readSkillsListingTruncated,
392
+ 'mcp.server_redialed': readMcpServerRedialed,
393
+ 'instructions.source_changed': readInstructionsSourceChanged,
394
+ 'approval.read_root_granted': readReadRootGrantNotice,
395
+ 'approval.read_root_grant_rejected': readReadRootGrantNotice,
396
+ });
397
+ const _factReaderTablePin = true;
398
+ void _factReaderTablePin;
399
+ export function readEngineNoticeFacts(notice) {
400
+ if (typeof notice !== 'object' || notice === null || Array.isArray(notice))
401
+ return undefined;
402
+ let code;
403
+ let detail;
404
+ try {
405
+ code = notice.code;
406
+ if (typeof code !== 'string' || !Object.hasOwn(ENGINE_NOTICE_FACT_READERS, code))
407
+ return undefined;
408
+ detail = notice.detail;
409
+ }
410
+ catch {
411
+ return undefined;
412
+ }
413
+ const k = code;
414
+ const facts = ENGINE_NOTICE_FACT_READERS[k]({ code: k, detail });
415
+ if (facts === undefined)
416
+ return undefined;
417
+ return { code: k, audience: noticeAudienceOf(k), facts };
418
+ }
@@ -6,11 +6,13 @@ export type WireAuthTokenSource = string | (() => string | undefined);
6
6
  export declare function isLoopbackWireUrl(url: string): boolean;
7
7
  export declare function resolveWireAuth(baseUrl: string | undefined, token?: string): WireAuthToken;
8
8
  export declare function wireAuthTokenFor(baseUrl: string, token?: string): WireAuthToken;
9
+ export type EngineProbeClient = Pick<AgentClient, 'capabilities' | 'scenarioCapabilities'>;
9
10
  export type EngineProbeOpts = {
10
11
  fetchImpl?: typeof fetch;
11
12
  timeoutMs?: number;
12
13
  authToken?: WireAuthTokenSource | undefined;
13
14
  principal?: string | undefined;
15
+ client?: EngineProbeClient;
14
16
  };
15
17
  export type EngineWireClientConfig = {
16
18
  baseUrl: string;
@@ -8,7 +8,7 @@ export type { AskAnsweredOutput } from './gateLedger.js';
8
8
  export { SEMA_COLLATERAL_ABORT_KEY } from './gateLedger.js';
9
9
  export { SEMA_DENIAL_KIND_KEY } from './gateLedger.js';
10
10
  export type { GateDenyAttribution } from './gateLedger.js';
11
- export { toAnsweredOutput, isAlreadyResolvedGateReason, isGateStandingErrorCode, GATE_FAILURE_CODES, nextHopBudget, MAX_GATE_HOPS, MAX_TOTAL_PARKS } from './parkResolver.js';
11
+ export { toAnsweredOutput, isAlreadyResolvedGateReason, isGateStandingErrorCode, isCodeClassifiedGateFailure, GATE_FAILURE_CODES, nextHopBudget, MAX_GATE_HOPS, MAX_TOTAL_PARKS } from './parkResolver.js';
12
12
  export type { HopBudget, HopRound } from './parkResolver.js';
13
13
  export type { GateOutcome, GateFailureCode } from './parkResolver.js';
14
14
  export declare function bridgeAskUserQuestionGates(source: AsyncGenerator<AgentEvent>, deps: AskGateWireDeps, opts?: {
@@ -6,7 +6,7 @@ export { HITL_INTERRUPT_MESSAGE_FOR_TOOL_USE } from './frameRouter.js';
6
6
  export { HITL_POLICY_DENY_MESSAGE } from './frameRouter.js';
7
7
  export { SEMA_COLLATERAL_ABORT_KEY } from './gateLedger.js';
8
8
  export { SEMA_DENIAL_KIND_KEY } from './gateLedger.js';
9
- export { toAnsweredOutput, isAlreadyResolvedGateReason, isGateStandingErrorCode, GATE_FAILURE_CODES, nextHopBudget, MAX_GATE_HOPS, MAX_TOTAL_PARKS } from './parkResolver.js';
9
+ export { toAnsweredOutput, isAlreadyResolvedGateReason, isGateStandingErrorCode, isCodeClassifiedGateFailure, GATE_FAILURE_CODES, nextHopBudget, MAX_GATE_HOPS, MAX_TOTAL_PARKS } from './parkResolver.js';
10
10
  export async function* bridgeAskUserQuestionGates(source, deps, opts) {
11
11
  const led = createGateLedger();
12
12
  const taskId = { current: opts?.taskId };
@@ -113,7 +113,7 @@ export function observeCancelByDeny(settle, taskId) {
113
113
  hostLog('debug', `[hitl-cancel-deny] cancel-by-deny no_pending for run ${taskId} (benign — already resolved)`);
114
114
  return;
115
115
  }
116
- const rowNote = decideFailureNote(e);
116
+ const rowNote = decideFailureNote(e, 'deny');
117
117
  hostLog('error', `[hitl-cancel-deny] cancel-by-deny FAILED for run ${taskId}: ${String(e)}${rowNote}`);
118
118
  surfaceCancelDenyWarn(`${CANCEL_DENY_WARN_TEXT}${rowNote}`);
119
119
  })
@@ -34,6 +34,7 @@ export type GateOutcome = {
34
34
  };
35
35
  export declare function isAlreadyResolvedGateReason(reason: unknown): boolean;
36
36
  export declare function isGateStandingErrorCode(code: string | null | undefined): boolean;
37
+ export declare function isCodeClassifiedGateFailure(code: string | null | undefined): boolean;
37
38
  export declare function toAnsweredOutput(questions: unknown[], answer: QuestionAnswer): AskAnsweredOutput;
38
39
  export type ParkResolution = {
39
40
  kind: 'reattach';