@sema-agent/client-core 0.104.0 → 0.105.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 (92) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/README.md +13 -5
  3. package/dist/adapt/arms.js +14 -6
  4. package/dist/adapter/activeRunSelfHeal.d.ts +1 -0
  5. package/dist/adapter/activeRunSelfHeal.js +10 -5
  6. package/dist/adapter/downstream/eventToSdkMessage.js +4 -4
  7. package/dist/adapter/downstream/wiringManifestView.d.ts +6 -0
  8. package/dist/adapter/downstream/wiringManifestView.js +25 -0
  9. package/dist/adapter/runStream.js +5 -1
  10. package/dist/cloudConfigWireCaps.js +3 -0
  11. package/dist/compensations.js +6 -6
  12. package/dist/coreValuePorts.d.ts +3 -1
  13. package/dist/coreValuePorts.js +4 -0
  14. package/dist/displayUntrusted.d.ts +4 -2
  15. package/dist/displayUntrusted.js +45 -22
  16. package/dist/engineGenerationPort.d.ts +11 -2
  17. package/dist/engineGenerationPort.js +63 -9
  18. package/dist/engineHealthFacts.d.ts +5 -0
  19. package/dist/engineHealthFacts.js +11 -0
  20. package/dist/eventLeg.d.ts +1 -1
  21. package/dist/eventLeg.js +23 -3
  22. package/dist/generated/engineFactTables.d.ts +1 -0
  23. package/dist/generated/engineFactTables.js +1 -0
  24. package/dist/generated/sdkFactTables.d.ts +2 -0
  25. package/dist/generated/sdkFactTables.js +9 -0
  26. package/dist/headlessReconnectWire.js +31 -4
  27. package/dist/hitl/askGateWire.js +26 -2
  28. package/dist/hitl/frameRouter.d.ts +4 -0
  29. package/dist/hitl/frameRouter.js +14 -0
  30. package/dist/hitl/gateIdentity.d.ts +1 -0
  31. package/dist/hitl/gateIdentity.js +3 -0
  32. package/dist/hitl/livePendingAsk.d.ts +2 -1
  33. package/dist/hitl/livePendingAsk.js +7 -1
  34. package/dist/hitl/planReviewCard.d.ts +21 -0
  35. package/dist/hitl/planReviewCard.js +229 -0
  36. package/dist/hitl/planReviewWire.d.ts +38 -13
  37. package/dist/hitl/planReviewWire.js +355 -133
  38. package/dist/hitl/toolApprovalWire.d.ts +2 -2
  39. package/dist/hitl/toolApprovalWire.js +53 -32
  40. package/dist/hostSettingsSource.d.ts +1 -1
  41. package/dist/hostSettingsSource.js +8 -4
  42. package/dist/hostTurnSettings.d.ts +1 -1
  43. package/dist/hostTurnSettings.js +29 -10
  44. package/dist/i18n/messages.en.d.ts +50 -0
  45. package/dist/i18n/messages.en.js +50 -0
  46. package/dist/i18n/messages.zh.js +51 -0
  47. package/dist/index.d.ts +15 -3
  48. package/dist/index.js +9 -1
  49. package/dist/mcpTransportKindsCapability.d.ts +18 -0
  50. package/dist/mcpTransportKindsCapability.js +75 -0
  51. package/dist/mcpWireCaps.d.ts +4 -1
  52. package/dist/mcpWireCaps.js +24 -13
  53. package/dist/notifications.d.ts +9 -0
  54. package/dist/notifications.js +11 -2
  55. package/dist/ownKey.d.ts +4 -0
  56. package/dist/ownKey.js +8 -0
  57. package/dist/permissionModeWriteCapability.d.ts +13 -0
  58. package/dist/permissionModeWriteCapability.js +35 -0
  59. package/dist/permissionsAllowGrantCapability.d.ts +3 -0
  60. package/dist/permissionsAllowGrantCapability.js +26 -3
  61. package/dist/permissionsDeclaration.d.ts +23 -1
  62. package/dist/permissionsDeclaration.js +60 -30
  63. package/dist/planReviewCardFacts.d.ts +116 -0
  64. package/dist/planReviewCardFacts.js +469 -0
  65. package/dist/reattachWindow.d.ts +8 -1
  66. package/dist/reattachWindow.js +44 -12
  67. package/dist/runFollow.d.ts +30 -0
  68. package/dist/runFollow.js +117 -0
  69. package/dist/runLedgerSnapshot.d.ts +20 -0
  70. package/dist/runLedgerSnapshot.js +272 -0
  71. package/dist/runPermissionModeSwitch.d.ts +57 -0
  72. package/dist/runPermissionModeSwitch.js +135 -0
  73. package/dist/runReattachPolicy.d.ts +13 -5
  74. package/dist/runReattachPolicy.js +58 -23
  75. package/dist/seam.d.ts +3 -0
  76. package/dist/seam.js +1 -1
  77. package/dist/seatContract.js +1 -0
  78. package/dist/sessionMemoryErase.d.ts +1 -1
  79. package/dist/sessionMemoryErase.js +5 -0
  80. package/dist/sessionMemoryStatus.d.ts +27 -1
  81. package/dist/sessionMemoryStatus.js +117 -0
  82. package/dist/sseIdleTriage.d.ts +3 -1
  83. package/dist/sseIdleTriage.js +19 -4
  84. package/dist/steering.d.ts +1 -0
  85. package/dist/steering.js +34 -26
  86. package/dist/subagent/engineSubagentTail.js +2 -0
  87. package/dist/subagentContentStore.d.ts +3 -0
  88. package/dist/subagentContentStore.js +10 -1
  89. package/dist/turnFailurePresentation.d.ts +5 -2
  90. package/dist/turnFailurePresentation.js +12 -4
  91. package/docs/INTEGRATION-CLIENTS.md +587 -10
  92. package/package.json +2 -2
@@ -208,3 +208,28 @@ export function modRowsOf(records) {
208
208
  return undefined;
209
209
  }
210
210
  }
211
+ export function readPermissionModeReceiptSegment(holder, key) {
212
+ try {
213
+ const seg = ownSlot(holder, key);
214
+ if (seg.state !== 'value' || !isModRecordObject(seg.value))
215
+ return undefined;
216
+ const raw = seg.value;
217
+ const effective = nonEmpty(ownSlot(raw, 'effective'));
218
+ if (effective === undefined)
219
+ return undefined;
220
+ const requestedSlot = ownSlot(raw, 'requested');
221
+ const foldedBySlot = ownSlot(raw, 'foldedBy');
222
+ const requested = nonEmpty(requestedSlot);
223
+ const foldedBy = nonEmpty(foldedBySlot);
224
+ if ((requestedSlot.state !== 'absent' && requested === undefined) || (foldedBySlot.state !== 'absent' && foldedBy === undefined))
225
+ return undefined;
226
+ return Object.freeze({
227
+ ...(requested !== undefined ? { requested } : {}),
228
+ effective,
229
+ ...(foldedBy !== undefined ? { foldedBy } : {}),
230
+ });
231
+ }
232
+ catch {
233
+ return undefined;
234
+ }
235
+ }
@@ -20,6 +20,7 @@ import { MODEL_OUTPUT_ERROR_PREFIX, OUTCOME_UNKNOWN_ROW_PREFIX, RUN_BLOCKED_MESS
20
20
  export { MODEL_OUTPUT_ERROR_PREFIX, OUTCOME_UNKNOWN_ROW_PREFIX, RUN_BLOCKED_MESSAGE_PREFIX, RUN_STOPPED_MESSAGE_PREFIX };
21
21
  import { ccToolDenialKindForToolEnd, gateDeniedBy, gateOutcomeOf } from '../gateOutcome.js';
22
22
  import { resumeReopenContent, resumeReopenFromError, suspendedReopenOf } from '../hitl/suspendedReopen.js';
23
+ import { openPlanBodyClaimLeg, planReviewParkFacts, stepPlanBodyClaim } from '../planReviewCardFacts.js';
23
24
  import { isCcToolDenialKind, isCcToolDenialKindADenial, isGateDeniedByWord } from '../gateVocabulary.js';
24
25
  const ENGINE_TURN_USAGE_KEYS = Object.freeze(['inputTokens', 'totalInputTokens', 'outputTokens', 'cacheReadTokens', 'cacheWriteTokens', 'costMicroUsd']);
25
26
  const _engineTurnUsageKeysPin = true;
@@ -578,6 +579,7 @@ async function* runStreamInner(events, ctx, handle = {}) {
578
579
  return false;
579
580
  }
580
581
  };
582
+ const planLeg = openPlanBodyClaimLeg();
581
583
  for await (const rawEv of events) {
582
584
  const ev = withStringFailureFields(rawEv);
583
585
  const wireSubFlow = wireFrameIsSubFlow(ev);
@@ -591,6 +593,7 @@ async function* runStreamInner(events, ctx, handle = {}) {
591
593
  }
592
594
  seen.add(seq);
593
595
  }
596
+ stepPlanBodyClaim(planLeg, ev, wireSubFlow);
594
597
  if (ev.type === 'tool_start') {
595
598
  const callId = ev.toolCallId;
596
599
  if (typeof callId === 'string' && callId.length > 0 && !toolInputAmbiguous.has(callId)) {
@@ -853,9 +856,10 @@ async function* runStreamInner(events, ctx, handle = {}) {
853
856
  accepted: ev.type === 'done' && (doneTerminal?.kind === 'completed' || doneTerminal?.kind === 'paused'),
854
857
  }).acceptedSinceMismatch;
855
858
  }
859
+ const planReview = ev.type === 'done' ? planReviewParkFacts(planLeg, engineResultOf(ev.result)) : undefined;
856
860
  if (ev.type === 'done' && isReviewPark(doneTerminal) && ctx.emitChrome) {
857
861
  try {
858
- await ctx.emitChrome({ kind: 'plan_review_park', laneProof: mainLane(), result: ev.result });
862
+ await ctx.emitChrome({ kind: 'plan_review_park', laneProof: mainLane(), result: ev.result, ...(planReview !== undefined ? { planReview } : {}) });
859
863
  }
860
864
  catch { }
861
865
  }
@@ -149,11 +149,13 @@ export function cloudMcpToSpecs(servers, env) {
149
149
  let elicitationDeclared;
150
150
  let allowDeclared;
151
151
  let startupDeclared;
152
+ let sessionMetaKeyDeclared;
152
153
  try {
153
154
  axesDeclared = s.toolAxes;
154
155
  elicitationDeclared = s.elicitation;
155
156
  allowDeclared = s.allowTools;
156
157
  startupDeclared = s.startupTimeoutMs;
158
+ sessionMetaKeyDeclared = s.sessionMetaKey;
157
159
  }
158
160
  catch {
159
161
  recordDrop(name, 'entry-unreadable');
@@ -202,6 +204,7 @@ export function cloudMcpToSpecs(servers, env) {
202
204
  ...(facesShipped !== undefined ? { toolFaces: facesShipped } : {}),
203
205
  ...(axesShipped !== undefined ? { toolAxes: axesShipped } : {}),
204
206
  ...(startupDeclared !== undefined ? { startupTimeoutMs: startupDeclared } : {}),
207
+ ...(sessionMetaKeyDeclared !== undefined ? { sessionMetaKey: sessionMetaKeyDeclared } : {}),
205
208
  });
206
209
  }
207
210
  return { specs, missingEnv: [...new Set(missingEnv)], droppedServers, degradedServers };
@@ -77,12 +77,12 @@ export const MIGRATED_COMPENSATIONS = [
77
77
  },
78
78
  {
79
79
  id: 'T2',
80
- what: '去重键客户端重算(`[external:]taskId:status[:seq]`)—— wire 上没有「这次完成的唯一 id」',
80
+ what: '渲染去重的身份 —— 自算键(`[external:]taskId:status[:seq]`)恒在;终态、非 external 且带完成 id 的通知再加一把 `completion:<id>`;只有完成键见过的同一次完成不渲第二行,其余义务照做',
81
81
  disposition: 'in-library',
82
- libraryHalf: 'notifications.ts taskNotificationDedupKey + taskNotificationDedupKeyFromWire(裸 wire 入口)',
82
+ libraryHalf: 'notifications.ts taskNotificationRenderKeys(身份全集,适配器渲染去重读它)+ taskNotificationDedupKey / taskNotificationDedupKeyFromWire(自算键;裸 wire 入口)',
83
83
  chromeArm: null,
84
84
  hostHalf: null,
85
- retireOn: 'RL-36',
85
+ retireOn: null,
86
86
  },
87
87
  {
88
88
  id: 'T3',
@@ -103,16 +103,16 @@ export const MIGRATED_COMPENSATIONS = [
103
103
  libraryHalf: 'toolResult.ts 终态轮询卡臂的预 seed + notifications.markEngineWorkflowNotified',
104
104
  chromeArm: null,
105
105
  hostHalf: null,
106
- retireOn: 'RL-38',
106
+ retireOn: null,
107
107
  },
108
108
  {
109
109
  id: 'T53',
110
- what: '同一次完成四通道扇出 ⇒ 四道去重(设计稿列为最贵 #4)',
110
+ what: '同一次完成四通道扇出 ⇒ 四道去重(四通道扇出里最贵的一道;第四道是队列撤单,不是去重)',
111
111
  disposition: 'in-library',
112
112
  libraryHalf: 'adapt.ts task_notification / workflow_complete 两臂的四道门(逐道说明见本行上方注释)',
113
113
  chromeArm: null,
114
114
  hostHalf: null,
115
- retireOn: 'RL-39',
115
+ retireOn: null,
116
116
  },
117
117
  {
118
118
  id: 'T49',
@@ -150,8 +150,9 @@ export interface CoreValuePorts {
150
150
  ANTHROPIC_DEFAULT_BASE_URL: string;
151
151
  readToolFaces(declared: {} | null | undefined): McpToolFacesReadView;
152
152
  ruleNameCovers: (ruleName: string, toolName: string) => boolean;
153
+ IMPORTED_SETTINGS_LAYERS: readonly ['userSettings', 'projectSettings', 'localSettings'];
153
154
  }
154
- export declare const CORE_VALUE_PORT_NAMES: readonly ["resolveAutonomousLoopPrompt", "loosenReasons", "combinePolicies", "createAllowDenyPolicy", "MCP_NAMESPACE", "protocolOf", "ruleToolGrammarOf", "validatePermissionRules", "mintNamespacePrefix", "compileAllowList", "routeKeyOf", "joinRequestUrl", "resolveRouteCredential", "adjudicateModelRoute", "routePairingStatus", "judgeRuleToolName", "readRuleEntry", "readMcpToolAxes", "ANTHROPIC_DEFAULT_BASE_URL", "readToolFaces", "ruleNameCovers"];
155
+ export declare const CORE_VALUE_PORT_NAMES: readonly ["resolveAutonomousLoopPrompt", "loosenReasons", "combinePolicies", "createAllowDenyPolicy", "MCP_NAMESPACE", "protocolOf", "ruleToolGrammarOf", "validatePermissionRules", "mintNamespacePrefix", "compileAllowList", "routeKeyOf", "joinRequestUrl", "resolveRouteCredential", "adjudicateModelRoute", "routePairingStatus", "judgeRuleToolName", "readRuleEntry", "readMcpToolAxes", "ANTHROPIC_DEFAULT_BASE_URL", "readToolFaces", "ruleNameCovers", "IMPORTED_SETTINGS_LAYERS"];
155
156
  export type CoreValuePortName = (typeof CORE_VALUE_PORT_NAMES)[number];
156
157
  export declare function installCoreValuePorts(ports: Partial<CoreValuePorts> | null): () => void;
157
158
  export declare function hasCoreValuePorts(): boolean;
@@ -182,3 +183,4 @@ export declare function readMcpToolAxes(declared: {} | null | undefined): McpToo
182
183
  export declare function anthropicDefaultBaseUrl(): string | undefined;
183
184
  export declare function readToolFaces(declared: {} | null | undefined): McpToolFacesReadView | undefined;
184
185
  export declare function ruleNameCovers(ruleName: string, toolName: string): boolean | undefined;
186
+ export declare function importedSettingsLayers(): CoreValuePorts['IMPORTED_SETTINGS_LAYERS'] | undefined;
@@ -20,6 +20,7 @@ export const CORE_VALUE_PORT_NAMES = Object.freeze([
20
20
  'ANTHROPIC_DEFAULT_BASE_URL',
21
21
  'readToolFaces',
22
22
  'ruleNameCovers',
23
+ 'IMPORTED_SETTINGS_LAYERS',
23
24
  ]);
24
25
  let installed = null;
25
26
  export function installCoreValuePorts(ports) {
@@ -123,3 +124,6 @@ export function ruleNameCovers(ruleName, toolName) {
123
124
  const fn = port('ruleNameCovers');
124
125
  return fn === undefined ? undefined : fn(ruleName, toolName);
125
126
  }
127
+ export function importedSettingsLayers() {
128
+ return port('IMPORTED_SETTINGS_LAYERS');
129
+ }
@@ -14,6 +14,7 @@ export interface DisplayFace {
14
14
  readonly fold: boolean;
15
15
  readonly mark: DisplayMark;
16
16
  readonly keepBlanks?: boolean;
17
+ readonly keepCrlf?: boolean;
17
18
  }
18
19
  export declare function applyDisplayFace(text: string, face: DisplayFace): string;
19
20
  export interface DisplayUntrustedOptions {
@@ -22,11 +23,11 @@ export interface DisplayUntrustedOptions {
22
23
  readonly controls?: boolean;
23
24
  readonly bidi?: boolean;
24
25
  readonly foldLines?: boolean;
25
- readonly keepLayout?: boolean;
26
+ readonly keepLayout?: boolean | 'crlf';
26
27
  readonly mark?: DisplayMark;
27
28
  readonly max?: number;
28
29
  readonly escapeBackslashes?: boolean;
29
- readonly blanks?: boolean;
30
+ readonly blanks?: boolean | 'fillers';
30
31
  }
31
32
  export interface DisplayMarkSpan {
32
33
  readonly start: number;
@@ -37,6 +38,7 @@ export interface DisplayUntrustedMarked {
37
38
  readonly text: string;
38
39
  readonly marks: readonly DisplayMarkSpan[];
39
40
  }
41
+ export declare const DISPLAY_DECISION_BODY: Readonly<DisplayUntrustedOptions>;
40
42
  export declare const ESCAPE_FACE: DisplayFace;
41
43
  export declare const LABEL_FACE: DisplayFace;
42
44
  export declare const PEER_NAME_FACE: DisplayFace;
@@ -3618,6 +3618,8 @@ class SequenceReader {
3618
3618
  if (this.atomicBlanks === 'none')
3619
3619
  return false;
3620
3620
  const cp = nameBlankTokenAt(this.text, at);
3621
+ if (this.atomicBlanks === 'fillers')
3622
+ return cp !== -1 && !isFoldedBlank(cp);
3621
3623
  return this.atomicBlanks === 'all' ? cp !== -1 : isFoldedBlank(cp);
3622
3624
  }
3623
3625
  intermediateAt(at) {
@@ -3735,6 +3737,9 @@ function nameBlankTokenAt(text, at) {
3735
3737
  const cp = Number.parseInt(hit[1] ?? '', 16);
3736
3738
  return isNameBlank(cp) ? cp : -1;
3737
3739
  }
3740
+ function isMarkedNameBlank(net, c) {
3741
+ return net === 1 ? isNameBlank(c) : net === 2 ? isNameBlank(c) && !isRegexSpace(c) : false;
3742
+ }
3738
3743
  function buildScanView(text, o) {
3739
3744
  const chars = [];
3740
3745
  const starts = [];
@@ -3743,7 +3748,7 @@ function buildScanView(text, o) {
3743
3748
  const dropped = [];
3744
3749
  const spaceUnits = [];
3745
3750
  const contents = [];
3746
- const seq = new SequenceReader(text, o.blanks ? 'all' : 'none', o.blanks || o.fold, o.fold);
3751
+ const seq = new SequenceReader(text, o.blanks === 1 ? 'all' : o.blanks === 2 ? 'fillers' : 'none', o.blanks === 1 || o.fold, o.fold);
3747
3752
  const keep = (ch, s, e, unit = UNIT_NONE) => {
3748
3753
  chars.push(ch);
3749
3754
  starts.push(s);
@@ -3814,7 +3819,7 @@ function buildScanView(text, o) {
3814
3819
  continue;
3815
3820
  }
3816
3821
  }
3817
- if (o.blanks && isNameBlank(c)) {
3822
+ if (isMarkedNameBlank(o.blanks, c)) {
3818
3823
  drop(i, i + 1);
3819
3824
  i++;
3820
3825
  continue;
@@ -3984,7 +3989,7 @@ function screenSurfaces(text, o) {
3984
3989
  i = j;
3985
3990
  continue;
3986
3991
  }
3987
- else if (unsafe !== null && unsafe.test(ch) && !faceHitKept(ch, i, text)) {
3992
+ else if (unsafe !== null && unsafe.test(ch) && !faceHitKept(ch, i, text, face.keepCrlf === true)) {
3988
3993
  form = markOf(ch, face.mark);
3989
3994
  dotted = face.mark !== 'escape';
3990
3995
  }
@@ -4636,13 +4641,16 @@ function scanAndMask(text, o, trace, stats, phaseOut) {
4636
4641
  }
4637
4642
  return cur;
4638
4643
  }
4639
- const WASH_OPTIONS = Object.freeze({ urls: true, words: true, blanks: false, fold: false, face: null, escapeSpaces: null });
4644
+ const WASH_OPTIONS = Object.freeze({ urls: true, words: true, blanks: 0, fold: false, face: null, escapeSpaces: null });
4640
4645
  export function washCredentials(text) {
4641
4646
  if (typeof text !== 'string')
4642
4647
  return text;
4643
4648
  return scanAndMask(text, WASH_OPTIONS, false).text;
4644
4649
  }
4645
4650
  const NAME_BLANKS = NAME_BLANK_RANGES.map(([a, b]) => (a === b ? classEscape(a) : `${classEscape(a)}-${classEscape(b)}`)).join('');
4651
+ const NAME_FILLERS = NAME_BLANK_RANGES.filter(([a, b]) => !isRegexSpace(a) && !isRegexSpace(b))
4652
+ .map(([a, b]) => (a === b ? classEscape(a) : `${classEscape(a)}-${classEscape(b)}`))
4653
+ .join('');
4646
4654
  function classEscape(cp) {
4647
4655
  return `\\u${cp.toString(16).toUpperCase().padStart(4, '0')}`;
4648
4656
  }
@@ -4740,10 +4748,12 @@ function joinerKept(text, at, zwj) {
4740
4748
  function emojiPresented(cp, after) {
4741
4749
  return isPictograph(cp) && (isEmojiPresentation(cp) || after === 0xfe0f || (after !== -1 && isEmojiModifier(after)));
4742
4750
  }
4743
- function faceHitKept(ch, at, text) {
4751
+ function faceHitKept(ch, at, text, crlf = false) {
4744
4752
  if (ch.length > 2)
4745
4753
  return true;
4746
4754
  const c = ch.charCodeAt(0);
4755
+ if (crlf && c === 0x0d && ch.length === 1)
4756
+ return text.charCodeAt(at + 1) === 0x0a;
4747
4757
  return ch.length === 1 && (c === 0x200d || c === 0x200c) && joinerKept(text, at, c === 0x200d);
4748
4758
  }
4749
4759
  const RGI_TAG_FLAG = '\\u{1F3F4}\\u{E0067}\\u{E0062}(?:\\u{E0065}\\u{E006E}\\u{E0067}|\\u{E0073}\\u{E0063}\\u{E0074}|\\u{E0077}\\u{E006C}\\u{E0073})\\u{E007F}';
@@ -4771,7 +4781,7 @@ const FOLD_RUN_KEEPING_BLANKS = new RegExp(`[^\\S${NAME_BLANKS}]+`, 'g');
4771
4781
  const EDGE_SPACE = /^ | $/g;
4772
4782
  const foldWhitespace = (s, keepBlanks = false) => keepBlanks ? s.replace(FOLD_RUN_KEEPING_BLANKS, ' ').replace(EDGE_SPACE, '') : s.replace(FOLD_RUN, ' ').trim();
4773
4783
  export function applyDisplayFace(text, face) {
4774
- const markAll = (s) => face.unsafe === null ? s : s.replace(face.unsafe, (ch, at, whole) => (faceHitKept(ch, at, whole) ? ch : markOf(ch, face.mark)));
4784
+ const markAll = (s) => face.unsafe === null ? s : s.replace(face.unsafe, (ch, at, whole) => (faceHitKept(ch, at, whole, face.keepCrlf === true) ? ch : markOf(ch, face.mark)));
4775
4785
  const keepBlanks = face.keepBlanks === true;
4776
4786
  if (face.mark === 'space') {
4777
4787
  const marked = markAll(text);
@@ -4779,7 +4789,7 @@ export function applyDisplayFace(text, face) {
4779
4789
  }
4780
4790
  return markAll(face.fold ? foldWhitespace(text, keepBlanks) : text);
4781
4791
  }
4782
- function markTracked(t, re, mark, ledger) {
4792
+ function markTracked(t, re, mark, ledger, crlf = false) {
4783
4793
  const parts = [];
4784
4794
  const ids = [];
4785
4795
  const keep = (a, b) => {
@@ -4792,7 +4802,7 @@ function markTracked(t, re, mark, ledger) {
4792
4802
  const at = hit.index ?? 0;
4793
4803
  const ch = hit[0];
4794
4804
  keep(cursor, at);
4795
- if (faceHitKept(ch, at, t.text))
4805
+ if (faceHitKept(ch, at, t.text, crlf))
4796
4806
  keep(at, at + ch.length);
4797
4807
  else {
4798
4808
  const form = markOf(ch, mark);
@@ -4841,7 +4851,7 @@ function foldTracked(t, keepBlanks) {
4841
4851
  function faceTracked(t, face, ledger) {
4842
4852
  const keepBlanks = face.keepBlanks === true;
4843
4853
  const unsafe = face.unsafe;
4844
- const markAll = (x) => (unsafe === null ? x : markTracked(x, unsafe, face.mark, ledger));
4854
+ const markAll = (x) => (unsafe === null ? x : markTracked(x, unsafe, face.mark, ledger, face.keepCrlf === true));
4845
4855
  if (face.mark === 'space') {
4846
4856
  const marked = markAll(t);
4847
4857
  return face.fold ? foldTracked(marked, keepBlanks) : marked;
@@ -4920,20 +4930,33 @@ function collectMarks(t, ledger) {
4920
4930
  }
4921
4931
  return out;
4922
4932
  }
4923
- const PUBLIC_UNSAFE_BY_NETS = Object.freeze(Array.from({ length: 16 }, (_, i) => {
4924
- const controls = (i & 8) !== 0;
4925
- const bidi = (i & 4) !== 0;
4926
- const keep = (i & 2) !== 0;
4927
- const blanks = (i & 1) !== 0;
4928
- const members = `${controls ? `${keep ? C0_KEEP_LAYOUT : C0_ALL}${DEL_C1}${LONE_SURROGATE}` : ''}${bidi ? LINE_SEPARATORS : ''}${blanks ? NAME_BLANKS : ''}`;
4933
+ export const DISPLAY_DECISION_BODY = Object.freeze({
4934
+ foldLines: false,
4935
+ keepLayout: 'crlf',
4936
+ blanks: 'fillers',
4937
+ mark: 'escape',
4938
+ });
4939
+ const PUBLIC_UNSAFE_BY_NETS = Object.freeze(Array.from({ length: 24 }, (_, i) => {
4940
+ const net = i % 3;
4941
+ const rest = (i - net) / 3;
4942
+ const controls = (rest & 4) !== 0;
4943
+ const bidi = (rest & 2) !== 0;
4944
+ const keep = (rest & 1) !== 0;
4945
+ const blanks = net === 1 ? NAME_BLANKS : net === 2 ? NAME_FILLERS : '';
4946
+ const members = `${controls ? `${keep ? C0_KEEP_LAYOUT : C0_ALL}${DEL_C1}${LONE_SURROGATE}` : ''}${bidi ? LINE_SEPARATORS : ''}${blanks}`;
4929
4947
  return unsafeClass(members, bidi);
4930
4948
  }));
4949
+ function blankNetOf(opts) {
4950
+ return opts.blanks === true ? 1 : opts.blanks === 'fillers' ? 2 : 0;
4951
+ }
4952
+ const keepsLayout = (opts) => opts.keepLayout === true || opts.keepLayout === 'crlf';
4931
4953
  function publicFace(opts) {
4932
4954
  const fold = opts.foldLines !== false;
4933
- const keep = !fold && opts.keepLayout === true;
4934
- const blanks = opts.blanks === true;
4935
- const index = (opts.controls !== false ? 8 : 0) + (opts.bidi !== false ? 4 : 0) + (keep ? 2 : 0) + (blanks ? 1 : 0);
4936
- return { unsafe: PUBLIC_UNSAFE_BY_NETS[index] ?? null, fold, mark: opts.mark ?? 'escape', keepBlanks: blanks };
4955
+ const keep = !fold && keepsLayout(opts);
4956
+ const net = blankNetOf(opts);
4957
+ const index = ((opts.controls !== false ? 4 : 0) + (opts.bidi !== false ? 2 : 0) + (keep ? 1 : 0)) * 3 + net;
4958
+ const face = { unsafe: PUBLIC_UNSAFE_BY_NETS[index] ?? null, fold, mark: opts.mark ?? 'escape', keepBlanks: net === 1 };
4959
+ return keep && opts.keepLayout === 'crlf' && opts.controls !== false ? { ...face, keepCrlf: true } : face;
4937
4960
  }
4938
4961
  export const ESCAPE_FACE = Object.freeze({ ...publicFace({ foldLines: false }) });
4939
4962
  export const LABEL_FACE = Object.freeze({ ...publicFace({}) });
@@ -5007,7 +5030,7 @@ function escapeSpacesFor(o, face) {
5007
5030
  if (o.controls !== false) {
5008
5031
  for (const c of [0x09, 0x0a, 0x0b, 0x0c, 0x0d])
5009
5032
  set.add(c);
5010
- if (o.keepLayout === true) {
5033
+ if (keepsLayout(o)) {
5011
5034
  set.delete(0x09);
5012
5035
  set.delete(0x0a);
5013
5036
  }
@@ -5024,7 +5047,7 @@ function scanOptionsOf(o, face, queryByShape = false, wholeAddress = false) {
5024
5047
  queryByShape,
5025
5048
  wholeAddress,
5026
5049
  words: o.credentialWords !== false,
5027
- blanks: face.keepBlanks === true,
5050
+ blanks: blankNetOf(o),
5028
5051
  fold: face.fold,
5029
5052
  face,
5030
5053
  escapeSpaces: escapeSpacesFor(o, face),
@@ -5321,7 +5344,7 @@ function queryPartPhases(key, value, relax) {
5321
5344
  return hit;
5322
5345
  }
5323
5346
  const UPLOAD_PROBE_PREFIX = 'https://q.invalid/?';
5324
- const UPLOAD_SCAN_OPTIONS = Object.freeze({ urls: true, queryByShape: 'strict', wholeAddress: true, words: true, blanks: false, fold: false, face: null, escapeSpaces: null });
5347
+ const UPLOAD_SCAN_OPTIONS = Object.freeze({ urls: true, queryByShape: 'strict', wholeAddress: true, words: true, blanks: 0, fold: false, face: null, escapeSpaces: null });
5325
5348
  export function queryCarriesCredential(query) {
5326
5349
  if (typeof query !== 'string' || query.length === 0)
5327
5350
  return false;
@@ -19,7 +19,9 @@ export interface EngineGenerationPort {
19
19
  endedMaterials: () => Promise<EndedGenerationMaterials>;
20
20
  replacementInFlight?: () => boolean;
21
21
  awaitEngineInstalled?: (signal: AbortSignal, maxMs: number) => Promise<boolean>;
22
+ endedBy?: (generation: number) => EngineGenerationEndFact | undefined;
22
23
  }
24
+ export type EngineGenerationEndFact = 'own-supervision' | 'external-replacement';
23
25
  export type EngineGenerationReading = {
24
26
  readonly known: true;
25
27
  readonly generation: number;
@@ -42,11 +44,18 @@ export interface ApprovalFrameGenerationFacts {
42
44
  export declare function approvalFrameGenerationVerdict(facts: ApprovalFrameGenerationFacts): 'admit' | 'drop';
43
45
  export declare const REATTACH_AWAIT_NEXT_ENGINE_MS = 245000;
44
46
  export declare function unreachableForSettle(liveness: ReattachLivenessReading): boolean;
45
- export type EndedGenerationSettleStep = 'await-next-engine' | 'refresh-credentials' | 'credentials-rejected' | 'hand-over-terminal' | 'parked' | 'engine-stopped';
47
+ export type EndedGenerationSettleStep = 'await-next-engine' | 'refresh-credentials' | 'credentials-rejected' | 'hand-over-terminal' | 'parked' | 'engine-stopped' | 'window-exhausted';
48
+ export interface EndedGenerationWaitReading {
49
+ readonly replacing: boolean;
50
+ readonly installed: boolean;
51
+ readonly generationBefore?: EngineGenerationReading;
52
+ readonly generationAfter?: EngineGenerationReading;
53
+ readonly replacingAfter?: boolean;
54
+ }
46
55
  export interface EndedGenerationSettleFacts {
47
56
  readonly liveness: ReattachLivenessReading;
48
57
  readonly canAwaitNextEngine: boolean;
49
- readonly awaitedNextEngine: boolean;
58
+ readonly waits?: readonly EndedGenerationWaitReading[];
50
59
  readonly refreshedCredentials: boolean | null;
51
60
  readonly terminalReadable?: boolean;
52
61
  }
@@ -60,25 +60,79 @@ export function unreachableForSettle(liveness) {
60
60
  return false;
61
61
  }
62
62
  }
63
+ const SETTLE_WAIT_ROUNDS_MAX = 8;
64
+ function waitSnapshotsOf(raw) {
65
+ if (raw === undefined)
66
+ return [];
67
+ if (!Array.isArray(raw))
68
+ return null;
69
+ const out = [];
70
+ const n = raw.length;
71
+ for (let i = 0; i < n; i++) {
72
+ const item = raw[i];
73
+ if (typeof item !== 'object' || item === null)
74
+ return null;
75
+ const o = item;
76
+ const replacing = o.replacing;
77
+ const installed = o.installed;
78
+ const replacingAfter = o.replacingAfter;
79
+ if (typeof replacing !== 'boolean' || typeof installed !== 'boolean')
80
+ return null;
81
+ if (replacingAfter !== undefined && typeof replacingAfter !== 'boolean')
82
+ return null;
83
+ out.push({ replacing, installed, generationBefore: o.generationBefore, generationAfter: o.generationAfter, replacingAfter });
84
+ }
85
+ return out;
86
+ }
63
87
  export function endedGenerationSettleStep(facts) {
64
88
  try {
65
89
  const liveness = facts.liveness;
66
- if (typeof liveness !== 'object' || liveness === null || !REATTACH_RUN_STATES.includes(liveness.state))
67
- return 'engine-stopped';
68
- if (facts.canAwaitNextEngine === true && facts.awaitedNextEngine !== true && unreachableForSettle(liveness))
90
+ const canAwait = facts.canAwaitNextEngine;
91
+ const rawWaits = facts.waits;
92
+ const refreshed = facts.refreshedCredentials;
93
+ const terminalReadable = facts.terminalReadable;
94
+ if (typeof liveness !== 'object' || liveness === null)
95
+ return 'window-exhausted';
96
+ const state = liveness.state;
97
+ const notFound = liveness.notFound;
98
+ if (!REATTACH_RUN_STATES.includes(state))
99
+ return 'window-exhausted';
100
+ if (!(refreshed === null || typeof refreshed === 'boolean'))
101
+ return 'window-exhausted';
102
+ const waits = waitSnapshotsOf(rawWaits);
103
+ if (waits === null)
104
+ return 'window-exhausted';
105
+ const reading = notFound === true ? { state: state, notFound: true } : { state: state };
106
+ const unreachable = unreachableForSettle(reading);
107
+ const k = waits.length;
108
+ const w = k === 0 ? undefined : waits[k - 1];
109
+ const unstable = w !== undefined &&
110
+ w.installed &&
111
+ (engineGenerationEnded({ run: knownOrUnknown(w.generationBefore), current: knownOrUnknown(w.generationAfter) }) || w.replacingAfter === true);
112
+ if (refreshed === null && canAwait === true && (unreachable || state === 'unauthorized') && (k === 0 || (unstable && k < SETTLE_WAIT_ROUNDS_MAX)))
69
113
  return 'await-next-engine';
70
- if (liveness.state === 'unauthorized')
71
- return facts.refreshedCredentials === null ? 'refresh-credentials' : 'credentials-rejected';
72
- if (liveness.state === 'done')
73
- return facts.terminalReadable === false ? 'engine-stopped' : 'hand-over-terminal';
74
- if (liveness.state === 'parked')
114
+ const answered401 = refreshed !== null || state === 'unauthorized';
115
+ const outcomeUnknown = w !== undefined && answered401 && ((!w.installed && w.replacing) || (unstable && k >= SETTLE_WAIT_ROUNDS_MAX));
116
+ if (state === 'unauthorized') {
117
+ if (refreshed === null)
118
+ return 'refresh-credentials';
119
+ return outcomeUnknown ? 'window-exhausted' : 'credentials-rejected';
120
+ }
121
+ if (outcomeUnknown && unreachable)
122
+ return 'window-exhausted';
123
+ if (state === 'done')
124
+ return terminalReadable === false ? 'engine-stopped' : 'hand-over-terminal';
125
+ if (state === 'parked')
75
126
  return 'parked';
76
127
  return 'engine-stopped';
77
128
  }
78
129
  catch {
79
- return 'engine-stopped';
130
+ return 'window-exhausted';
80
131
  }
81
132
  }
133
+ function knownOrUnknown(reading) {
134
+ return typeof reading === 'object' && reading !== null ? reading : UNKNOWN;
135
+ }
82
136
  export const AWAIT_ENGINE_INSTALL_POLL_MS = 200;
83
137
  export function awaitNextEngineInstalled(signal, maxMs, deps) {
84
138
  const clock = typeof deps.now === 'function' ? deps.now : () => performance.now();
@@ -14,10 +14,15 @@ export interface EngineHealthDrainingFacts {
14
14
  readonly since: number;
15
15
  readonly deadlineAt: number;
16
16
  }
17
+ export interface EngineHealthLeaseFacts {
18
+ readonly lingerMs: number;
19
+ readonly tickMs: number;
20
+ }
17
21
  export interface EngineHealthFacts {
18
22
  readonly center?: EngineHealthCenterFacts;
19
23
  readonly auth?: EngineHealthAuthFacts;
20
24
  readonly operator?: 'present' | 'absent';
21
25
  readonly draining?: EngineHealthDrainingFacts;
26
+ readonly engineLease?: EngineHealthLeaseFacts;
22
27
  }
23
28
  export declare function readEngineHealthFacts(health: object | null | undefined): EngineHealthFacts;
@@ -67,6 +67,15 @@ function drainingOf(health) {
67
67
  return undefined;
68
68
  return Object.freeze({ actionId, since, deadlineAt });
69
69
  }
70
+ function leaseOf(raw) {
71
+ if (!isObject(raw))
72
+ return undefined;
73
+ const lingerMs = epochMs(readOwnDataValue(raw, 'lingerMs'));
74
+ const tickMs = epochMs(readOwnDataValue(raw, 'tickMs'));
75
+ if (lingerMs === undefined || tickMs === undefined)
76
+ return undefined;
77
+ return Object.freeze({ lingerMs, tickMs });
78
+ }
70
79
  function guarded(read) {
71
80
  try {
72
81
  return read();
@@ -83,10 +92,12 @@ export function readEngineHealthFacts(health) {
83
92
  const operatorRaw = guarded(() => readOwnDataValue(health, 'operator'));
84
93
  const operator = operatorRaw === 'present' || operatorRaw === 'absent' ? operatorRaw : undefined;
85
94
  const draining = guarded(() => drainingOf(health));
95
+ const engineLease = guarded(() => leaseOf(readOwnDataValue(health, 'engineLease')));
86
96
  return Object.freeze({
87
97
  ...(center !== undefined ? { center } : {}),
88
98
  ...(auth !== undefined ? { auth } : {}),
89
99
  ...(operator !== undefined ? { operator } : {}),
90
100
  ...(draining !== undefined ? { draining } : {}),
101
+ ...(engineLease !== undefined ? { engineLease } : {}),
91
102
  });
92
103
  }
@@ -81,7 +81,7 @@ export interface EventLegPorts {
81
81
  readonly signal?: AbortSignal;
82
82
  readonly taps?: readonly EventLegTap[];
83
83
  }
84
- export type EventLegPortName = 'run.headerRunId' | 'run.onBound' | 'run.onRefused' | 'run.onTerminal' | 'run.isCurrent' | 'hitl.question' | 'hitl.elicitation' | 'hitl.toolApproval' | 'askBridge.respondToolApproval' | 'taps';
84
+ export type EventLegPortName = 'run.headerRunId' | 'run.onBound' | 'run.onRefused' | 'run.onTerminal' | 'run.isCurrent' | 'hitl.question' | 'hitl.elicitation' | 'hitl.toolApproval' | 'askBridge.respondToolApproval' | 'askBridge.onBreak' | 'taps';
85
85
  export interface EventLegReport {
86
86
  readonly missingPorts: readonly EventLegPortName[];
87
87
  readonly portFaults: Readonly<Partial<Record<EventLegPortName, number>>>;
package/dist/eventLeg.js CHANGED
@@ -3,11 +3,12 @@ import { bridgeAskUserQuestionGates } from './hitl/askGateWire.js';
3
3
  import { diagnoseSseIdleTear } from './sseIdleTriage.js';
4
4
  import { recordSubagentOwnerFromProgress } from './subagentContentStore.js';
5
5
  import { activeRunBusySignal } from './adapter/runStream.js';
6
- import { invokeHostCallbackIsolated } from './hostCallbackGuard.js';
6
+ import { faultText, invokeHostCallbackIsolated } from './hostCallbackGuard.js';
7
7
  import { hostLog } from './host.js';
8
8
  import { guardedRead, readOwnDataNonEmptyString, readOwnDataValue } from './ownKey.js';
9
9
  import { settleEngineClosedApproval } from './hitl/approvalHolds.js';
10
10
  import { approvalCompleteParked } from './hitl/approvalCompleteParked.js';
11
+ import { setBridgeRunHandleFallback } from './hitl/frameRouter.js';
11
12
  export const EVENT_LEG_KINDS = Object.freeze(['live', 'durable', 'continuation']);
12
13
  export const EVENT_LEG_TABLE = Object.freeze({
13
14
  live: Object.freeze({ stages: Object.freeze(['bindRun', 'stampOwner', 'hitlFrames', 'askBridge', 'idleTriage']), windowIsCurrent: true }),
@@ -108,7 +109,7 @@ export function composeEventLeg(source, leg, ports) {
108
109
  return port.call(runPorts) === true;
109
110
  }
110
111
  catch (e) {
111
- fault('run.isCurrent', String(e));
112
+ fault('run.isCurrent', faultText(e));
112
113
  return false;
113
114
  }
114
115
  };
@@ -131,7 +132,7 @@ export function composeEventLeg(source, leg, ports) {
131
132
  return undefined;
132
133
  }
133
134
  catch (e) {
134
- fault('run.headerRunId', String(e));
135
+ fault('run.headerRunId', faultText(e));
135
136
  return undefined;
136
137
  }
137
138
  };
@@ -232,13 +233,32 @@ export function composeEventLeg(source, leg, ports) {
232
233
  windowOpen = false;
233
234
  return streamOf(hostBridge.runsEvents(taskId, opts), 'continuation', taskId);
234
235
  };
236
+ const onBreak = (event) => {
237
+ if (!isCurrentNow())
238
+ return;
239
+ let port;
240
+ try {
241
+ port = hostBridge.onBreak;
242
+ }
243
+ catch (e) {
244
+ fault('askBridge.onBreak', faultText(e));
245
+ port = undefined;
246
+ }
247
+ if (typeof port !== 'function')
248
+ return;
249
+ if (!isCurrentNow() || ports.signal?.aborted === true)
250
+ return;
251
+ callPort('askBridge.onBreak', () => port.call(hostBridge, event));
252
+ };
235
253
  const deps = hostView(hostBridge, {
236
254
  runsEvents: () => runsEvents,
237
255
  approvalLane: () => {
238
256
  const lane = hostBridge.approvalLane;
239
257
  return typeof lane === 'object' && lane !== null ? hostView(lane, { windowIsCurrent: () => windowOpen }) : Object.freeze({ windowIsCurrent: windowOpen });
240
258
  },
259
+ onBreak: () => onBreak,
241
260
  });
261
+ setBridgeRunHandleFallback(deps, () => lastBound?.taskId);
242
262
  inner = bridgeAskUserQuestionGates(inner, deps, { ...(ports.signal !== undefined ? { signal: ports.signal } : {}), ...(legRunId !== undefined ? { taskId: legRunId } : {}) });
243
263
  }
244
264
  const baseUrl = ports.idleTriage?.baseUrl;
@@ -71,3 +71,4 @@ export interface CoreUserAttachmentSeat {
71
71
  export declare const CORE_USER_ATTACHMENT_SEAT: CoreUserAttachmentSeat;
72
72
  export declare const CORE_USER_ATTACHMENTS_MAX: number;
73
73
  export declare const CORE_USER_ATTACHMENT_LABEL_MAX: number;
74
+ export declare const CORE_PRESENT_PLAN_TOOL_NAME: "ExitPlanMode";
@@ -463,3 +463,4 @@ export const CORE_USER_ATTACHMENT_SEAT = Object.freeze({
463
463
  });
464
464
  export const CORE_USER_ATTACHMENTS_MAX = 20;
465
465
  export const CORE_USER_ATTACHMENT_LABEL_MAX = 4096;
466
+ export const CORE_PRESENT_PLAN_TOOL_NAME = "ExitPlanMode";
@@ -5,3 +5,5 @@ export declare const SDK_ASK_ROW_ENDING_CAUSES: readonly ["routing_failure_fail_
5
5
  export declare const SDK_RUN_DEATH_VERDICT_CODES: readonly ["run.stalled", "run.orphaned", "approval.expired"];
6
6
  export declare const SDK_APPROVAL_DECIDE_GATE_KINDS: readonly ["human", "irreversible_ask"];
7
7
  export declare const SDK_PLAN_REVIEW_GATE_KINDS: readonly ["plan_review"];
8
+ export declare const SDK_PERMISSION_MODE_ADMISSION_FOLDS: readonly ["entry_floor", "disable_auto_mode"];
9
+ export declare const SDK_PERMISSION_MODE_PERSIST_MISSES: readonly ["claim_released", "context_absent", "store_failed"];
@@ -39,3 +39,12 @@ export const SDK_APPROVAL_DECIDE_GATE_KINDS = Object.freeze([
39
39
  export const SDK_PLAN_REVIEW_GATE_KINDS = Object.freeze([
40
40
  "plan_review",
41
41
  ]);
42
+ export const SDK_PERMISSION_MODE_ADMISSION_FOLDS = Object.freeze([
43
+ "entry_floor",
44
+ "disable_auto_mode",
45
+ ]);
46
+ export const SDK_PERMISSION_MODE_PERSIST_MISSES = Object.freeze([
47
+ "claim_released",
48
+ "context_absent",
49
+ "store_failed",
50
+ ]);