@sema-agent/client-core 0.104.1 → 0.106.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 (175) hide show
  1. package/CHANGELOG.md +310 -0
  2. package/README.md +36 -14
  3. package/dist/adapt/arms.js +23 -6
  4. package/dist/adapter/activeRunSelfHeal.d.ts +14 -2
  5. package/dist/adapter/activeRunSelfHeal.js +90 -12
  6. package/dist/adapter/downstream/eventToSdkMessage.d.ts +0 -5
  7. package/dist/adapter/downstream/eventToSdkMessage.js +24 -23
  8. package/dist/adapter/downstream/terminalToSdkResult.js +2 -3
  9. package/dist/adapter/downstream/wiringManifestView.d.ts +7 -3
  10. package/dist/adapter/downstream/wiringManifestView.js +25 -1
  11. package/dist/adapter/runStream.js +8 -5
  12. package/dist/approvalReachWire.d.ts +1 -0
  13. package/dist/approvalReachWire.js +4 -1
  14. package/dist/approvalSeat.d.ts +21 -0
  15. package/dist/approvalSeat.js +73 -0
  16. package/dist/assistantInbox.d.ts +2 -0
  17. package/dist/assistantInbox.js +3 -0
  18. package/dist/checkpointRowVerdict.d.ts +23 -0
  19. package/dist/checkpointRowVerdict.js +89 -0
  20. package/dist/cloudConfigWireCaps.js +3 -0
  21. package/dist/compensations.js +6 -6
  22. package/dist/coreValuePorts.d.ts +14 -1
  23. package/dist/coreValuePorts.js +14 -0
  24. package/dist/decideFailureNote.js +3 -1
  25. package/dist/decideReceipt.d.ts +9 -0
  26. package/dist/decideReceipt.js +29 -1
  27. package/dist/declared/supportFloorDeclared.js +2 -2
  28. package/dist/deviceRebind.d.ts +7 -0
  29. package/dist/deviceRebind.js +39 -5
  30. package/dist/displayUntrusted.d.ts +4 -2
  31. package/dist/displayUntrusted.js +45 -22
  32. package/dist/engineAddress.d.ts +3 -0
  33. package/dist/engineAddress.js +25 -0
  34. package/dist/engineDirectory.js +9 -17
  35. package/dist/engineErrorCodes.d.ts +8 -0
  36. package/dist/engineErrorCodes.js +8 -0
  37. package/dist/engineGenerationPort.d.ts +11 -2
  38. package/dist/engineGenerationPort.js +63 -9
  39. package/dist/engineHealthFacts.d.ts +5 -0
  40. package/dist/engineHealthFacts.js +11 -0
  41. package/dist/engineNoticeCodes.d.ts +26 -3
  42. package/dist/engineNoticeCodes.js +52 -7
  43. package/dist/engineRowRef.js +1 -1
  44. package/dist/errorSupplementRoles.js +2 -0
  45. package/dist/eventLeg.d.ts +3 -3
  46. package/dist/eventLeg.js +25 -4
  47. package/dist/fleet/fleetProjection.js +26 -5
  48. package/dist/generated/engineFactTables.d.ts +3 -1
  49. package/dist/generated/engineFactTables.js +4 -1
  50. package/dist/generated/engineNoticeTables.js +19 -4
  51. package/dist/generated/sdkFactTables.d.ts +5 -0
  52. package/dist/generated/sdkFactTables.js +24 -0
  53. package/dist/generated/settingsSchemaFns.d.ts +11 -0
  54. package/dist/generated/settingsSchemaFns.js +2 -1
  55. package/dist/generated/settingsSchemaSafetyMergeSpec.js +1 -1
  56. package/dist/generated/settingsSchemaSettingsSources.d.ts +1 -1
  57. package/dist/generated/settingsSchemaSettingsSources.js +22 -2
  58. package/dist/headlessReconnectWire.js +31 -4
  59. package/dist/hitl/approvalLiveFace.d.ts +17 -0
  60. package/dist/hitl/approvalLiveFace.js +35 -0
  61. package/dist/hitl/approvalQueueRow.d.ts +21 -0
  62. package/dist/hitl/approvalQueueRow.js +69 -0
  63. package/dist/hitl/approvalsFeed.d.ts +5 -4
  64. package/dist/hitl/approvalsFeed.js +38 -6
  65. package/dist/hitl/askGateWire.js +26 -2
  66. package/dist/hitl/askParkRowRouting.d.ts +4 -3
  67. package/dist/hitl/askParkRowRouting.js +15 -3
  68. package/dist/hitl/automaticAnswerVerdict.js +13 -10
  69. package/dist/hitl/crashConverged.d.ts +5 -1
  70. package/dist/hitl/decisionConflict.js +2 -1
  71. package/dist/hitl/decisionRefusal.js +1 -1
  72. package/dist/hitl/decisionSend.d.ts +1 -0
  73. package/dist/hitl/decisionSend.js +14 -2
  74. package/dist/hitl/frameRouter.d.ts +4 -0
  75. package/dist/hitl/frameRouter.js +18 -5
  76. package/dist/hitl/gateIdentity.d.ts +1 -0
  77. package/dist/hitl/gateIdentity.js +3 -0
  78. package/dist/hitl/hitlBridge.d.ts +1 -1
  79. package/dist/hitl/hitlBridge.js +26 -5
  80. package/dist/hitl/livePendingAsk.d.ts +5 -0
  81. package/dist/hitl/livePendingAsk.js +6 -1
  82. package/dist/hitl/planReviewCard.d.ts +23 -0
  83. package/dist/hitl/planReviewCard.js +250 -0
  84. package/dist/hitl/planReviewWire.d.ts +39 -14
  85. package/dist/hitl/planReviewWire.js +450 -163
  86. package/dist/hitl/sessionAllowRoute.d.ts +2 -0
  87. package/dist/hitl/sessionAllowRoute.js +7 -0
  88. package/dist/hitl/sessionPolicyWire.d.ts +1 -7
  89. package/dist/hitl/sessionPolicyWire.js +3 -43
  90. package/dist/hitl/subagentSource.d.ts +1 -0
  91. package/dist/hitl/subagentSource.js +13 -0
  92. package/dist/hitl/toolApprovalWire.d.ts +3 -2
  93. package/dist/hitl/toolApprovalWire.js +79 -37
  94. package/dist/hostSettingsSource.d.ts +5 -2
  95. package/dist/hostSettingsSource.js +19 -10
  96. package/dist/hostTurnSettings.d.ts +5 -6
  97. package/dist/hostTurnSettings.js +106 -26
  98. package/dist/i18n/messages.en.d.ts +85 -12
  99. package/dist/i18n/messages.en.js +85 -12
  100. package/dist/i18n/messages.zh.js +88 -12
  101. package/dist/index.d.ts +35 -4
  102. package/dist/index.js +19 -2
  103. package/dist/liveInitToolFace.js +0 -1
  104. package/dist/liveModelCatalog.d.ts +15 -0
  105. package/dist/liveModelCatalog.js +40 -0
  106. package/dist/mcpTransportKindsCapability.d.ts +18 -0
  107. package/dist/mcpTransportKindsCapability.js +75 -0
  108. package/dist/mcpWireCaps.d.ts +4 -1
  109. package/dist/mcpWireCaps.js +25 -14
  110. package/dist/modelCapabilityProbe.js +66 -33
  111. package/dist/notifications.d.ts +9 -0
  112. package/dist/notifications.js +11 -2
  113. package/dist/ownKey.d.ts +4 -1
  114. package/dist/ownKey.js +8 -2
  115. package/dist/permissionModeWriteCapability.d.ts +13 -0
  116. package/dist/permissionModeWriteCapability.js +35 -0
  117. package/dist/permissionsAllowGrantCapability.d.ts +3 -0
  118. package/dist/permissionsAllowGrantCapability.js +26 -3
  119. package/dist/permissionsDeclaration.d.ts +25 -3
  120. package/dist/permissionsDeclaration.js +69 -41
  121. package/dist/planReviewCardFacts.d.ts +116 -0
  122. package/dist/planReviewCardFacts.js +469 -0
  123. package/dist/projectSeed.d.ts +39 -0
  124. package/dist/projectSeed.js +80 -0
  125. package/dist/promptDelivery.js +1 -1
  126. package/dist/reattachWindow.d.ts +8 -1
  127. package/dist/reattachWindow.js +44 -12
  128. package/dist/replayBody.d.ts +7 -6
  129. package/dist/replayBody.js +62 -7
  130. package/dist/request/taskRequest.js +3 -4
  131. package/dist/ruleCompileVerdict.d.ts +0 -2
  132. package/dist/ruleCompileVerdict.js +0 -31
  133. package/dist/ruleRefusalSentence.js +0 -3
  134. package/dist/runFollow.d.ts +30 -0
  135. package/dist/runFollow.js +117 -0
  136. package/dist/runLedgerSnapshot.d.ts +20 -0
  137. package/dist/runLedgerSnapshot.js +272 -0
  138. package/dist/runPermissionModeSwitch.d.ts +57 -0
  139. package/dist/runPermissionModeSwitch.js +135 -0
  140. package/dist/runReattachPolicy.d.ts +16 -5
  141. package/dist/runReattachPolicy.js +72 -24
  142. package/dist/runTerminal.js +30 -8
  143. package/dist/sandboxWire.d.ts +0 -3
  144. package/dist/sandboxWire.js +0 -9
  145. package/dist/seam.d.ts +17 -7
  146. package/dist/seam.js +13 -1
  147. package/dist/seatContract.d.ts +57 -7
  148. package/dist/seatContract.js +133 -3
  149. package/dist/serverSupportRange.d.ts +18 -0
  150. package/dist/serverSupportRange.js +25 -0
  151. package/dist/sessionEngine.d.ts +156 -0
  152. package/dist/sessionEngine.js +464 -0
  153. package/dist/sessionMap.d.ts +11 -1
  154. package/dist/sessionMap.js +35 -9
  155. package/dist/sessionMemoryErase.d.ts +1 -1
  156. package/dist/sessionMemoryErase.js +5 -0
  157. package/dist/sessionMemoryStatus.d.ts +27 -1
  158. package/dist/sessionMemoryStatus.js +117 -0
  159. package/dist/sessionMemorySync.d.ts +31 -0
  160. package/dist/sessionMemorySync.js +95 -0
  161. package/dist/sessionRowTag.d.ts +4 -0
  162. package/dist/sessionRowTag.js +18 -0
  163. package/dist/settingsLayerAdmission.d.ts +1 -0
  164. package/dist/settingsLayerAdmission.js +4 -1
  165. package/dist/sseIdleTriage.d.ts +3 -1
  166. package/dist/sseIdleTriage.js +19 -4
  167. package/dist/subagent/engineSubagentTail.js +2 -0
  168. package/dist/subagentContentStore.d.ts +3 -0
  169. package/dist/subagentContentStore.js +10 -1
  170. package/dist/toolResult.js +1 -1
  171. package/dist/turnFailurePresentation.d.ts +5 -2
  172. package/dist/turnFailurePresentation.js +12 -4
  173. package/dist/wireRefusalCopy.js +2 -6
  174. package/docs/INTEGRATION-CLIENTS.md +1507 -18
  175. package/package.json +5 -5
@@ -1,5 +1,6 @@
1
1
  import { usableClockMs } from './clockReading.js';
2
2
  import { readThrownSlot, THROWN_SLOT_UNREADABLE } from './wireFailureShape.js';
3
+ import { isReattachBreak, mintRunNotFollowed } from './runFollow.js';
3
4
  export const REATTACH_WINDOW_MS = 300_000;
4
5
  export const REATTACH_BACKOFF_START_MS = 1_000;
5
6
  export const REATTACH_BACKOFF_CAP_MS = 30_000;
@@ -25,15 +26,37 @@ export function reattachBackoffMs(attempt, tuning) {
25
26
  const raw = startMs * 2 ** (attempt - 1);
26
27
  return Number.isFinite(raw) ? Math.min(raw, capMs) : capMs;
27
28
  }
28
- export function reattachWindowOpen(nowMs, tuning) {
29
+ const isRunHandle = (v) => typeof v === 'string' && v !== '';
30
+ export function reattachWindowOpen(nowMs, tuning, runId) {
29
31
  const t = tuned(tuning);
30
32
  const start = usableClockMs(nowMs) ?? Number.NaN;
31
- return Object.freeze({ enteredAtMs: start, deadlineMs: start + t.windowMs, attempt: 0, consecutiveNotFound: 0, notFoundConfirmed: false, tuning: Object.freeze(t) });
33
+ return Object.freeze({
34
+ enteredAtMs: start,
35
+ deadlineMs: start + t.windowMs,
36
+ attempt: 0,
37
+ consecutiveNotFound: 0,
38
+ notFoundConfirmed: false,
39
+ tuning: Object.freeze(t),
40
+ ...(isRunHandle(runId) ? { runId } : {}),
41
+ });
32
42
  }
33
43
  const step = (state, decision) => Object.freeze({ state, decision });
34
- const exhausted = (state) => step(state, Object.freeze({ action: 'window-exhausted' }));
44
+ const runOf = (state) => {
45
+ const v = readThrownSlot(state, 'runId', 'data');
46
+ return isRunHandle(v) ? v : undefined;
47
+ };
48
+ const exhausted = (state) => {
49
+ const brk = readThrownSlot(state, 'lastBreak', 'data');
50
+ return step(state, Object.freeze({ action: 'window-exhausted', notFollowed: mintRunNotFollowed('reattach_exhausted', runOf(state), isReattachBreak(brk) ? brk : undefined) }));
51
+ };
52
+ const badInput = (state, runId) => step(state, Object.freeze({ action: 'window-exhausted', notFollowed: mintRunNotFollowed('bad_input', runId) }));
35
53
  const cont = (state, notFoundConfirmed = false) => step(state, Object.freeze({ action: 'continue', notFoundConfirmed }));
36
- const next = (state, patch) => Object.freeze({ ...state, ...patch });
54
+ const next = (state, patch, lastBreak) => {
55
+ if (lastBreak === undefined)
56
+ return Object.freeze({ ...state, ...patch });
57
+ const { lastBreak: _previous, ...rest } = state;
58
+ return Object.freeze(lastBreak.to === undefined ? { ...rest, ...patch } : { ...rest, ...patch, lastBreak: lastBreak.to });
59
+ };
37
60
  const isCount = (v) => typeof v === 'number' && Number.isSafeInteger(v) && v >= 0;
38
61
  function validState(s) {
39
62
  if (typeof s !== 'object' || s === null)
@@ -42,18 +65,20 @@ function validState(s) {
42
65
  return typeof o.enteredAtMs === 'number' && typeof o.deadlineMs === 'number' && isCount(o.attempt) && isCount(o.consecutiveNotFound) && typeof o.notFoundConfirmed === 'boolean' && typeof o.tuning === 'object' && o.tuning !== null;
43
66
  }
44
67
  export function reattachWindowStep(state, event, nowMs) {
68
+ let windowRun;
45
69
  try {
70
+ windowRun = runOf(state);
46
71
  if (!validState(state))
47
- return exhausted(reattachWindowOpen(Number.NaN));
72
+ return badInput(reattachWindowOpen(Number.NaN, undefined, windowRun), windowRun);
48
73
  if (typeof event !== 'object' || event === null)
49
74
  return cont(state);
50
75
  const type = event.type;
51
76
  const result = event.result;
52
77
  const serverRetryAfterMs = event.serverRetryAfterMs;
53
78
  if (type === 'new-segment')
54
- return cont(reattachWindowOpen(nowMs, state.tuning));
55
- if (usableClockMs(nowMs) === null || !Number.isFinite(state.deadlineMs))
56
- return exhausted(state);
79
+ return cont(reattachWindowOpen(nowMs, state.tuning, windowRun));
80
+ if (usableClockMs(nowMs) === null || usableClockMs(state.enteredAtMs) === null || !Number.isFinite(state.deadlineMs))
81
+ return badInput(state, windowRun);
57
82
  switch (type) {
58
83
  case 'attempt':
59
84
  return nowMs < state.deadlineMs ? cont(next(state, { attempt: state.attempt + 1 })) : exhausted(state);
@@ -70,18 +95,25 @@ export function reattachWindowStep(state, event, nowMs) {
70
95
  case 'tail-frame':
71
96
  return cont(next(state, { consecutiveNotFound: 0, notFoundConfirmed: false }));
72
97
  case 'tail-refused-404':
73
- return state.notFoundConfirmed ? step(state, Object.freeze({ action: 'run-unknown', confirmations: state.consecutiveNotFound })) : cont(state);
98
+ return state.notFoundConfirmed
99
+ ? step(state, Object.freeze({ action: 'run-unknown', confirmations: state.consecutiveNotFound, notFollowed: mintRunNotFollowed('run_unknown', windowRun) }))
100
+ : cont(state);
74
101
  case 'backoff': {
75
- const own = reattachBackoffMs(state.attempt, state.tuning);
102
+ const brkRead = readThrownSlot(event, 'break');
103
+ const brk = isReattachBreak(brkRead) ? brkRead : undefined;
104
+ const handoffRead = readThrownSlot(event, 'runId');
105
+ const handoff = isRunHandle(handoffRead) && handoffRead !== windowRun ? handoffRead : undefined;
106
+ const moved = next(state, handoff !== undefined ? { runId: handoff, consecutiveNotFound: 0, notFoundConfirmed: false } : {}, { to: brk });
107
+ const own = reattachBackoffMs(moved.attempt, moved.tuning);
76
108
  const delay = typeof serverRetryAfterMs === 'number' && Number.isFinite(serverRetryAfterMs) && serverRetryAfterMs > 0 ? Math.max(own, serverRetryAfterMs) : own;
77
- return nowMs + delay >= state.deadlineMs ? exhausted(state) : step(state, Object.freeze({ action: 'wait', afterMs: delay }));
109
+ return nowMs + delay >= moved.deadlineMs ? exhausted(moved) : step(moved, Object.freeze({ action: 'wait', afterMs: delay }));
78
110
  }
79
111
  default:
80
112
  return cont(state);
81
113
  }
82
114
  }
83
115
  catch {
84
- return exhausted(reattachWindowOpen(Number.NaN));
116
+ return badInput(reattachWindowOpen(Number.NaN, undefined, windowRun), windowRun);
85
117
  }
86
118
  }
87
119
  export function poisonFrameInitial() {
@@ -1,14 +1,15 @@
1
- export interface ReplayRowView {
2
- readonly status?: string;
3
- readonly errorCode?: string;
4
- readonly error?: string;
1
+ export interface RunReceiptView {
2
+ readonly taskId?: string;
5
3
  readonly sessionId?: string;
4
+ readonly status?: string;
6
5
  }
7
6
  export interface DoneResultView {
8
7
  readonly replay: boolean;
9
- readonly engine: unknown;
10
- readonly row?: ReplayRowView;
8
+ readonly receipt: boolean;
9
+ readonly body: unknown;
11
10
  }
11
+ export declare function terminalLayerOf<T>(carrier: T): T | object;
12
+ export declare function runRowSentenceOf<T>(carrier: T): string | undefined;
12
13
  export declare function doneResultView(result: unknown): DoneResultView;
13
14
  export declare function isReplayedTerminal(frame: object | null | undefined): boolean;
14
15
  export declare function isReplayMarked(message: object | null | undefined): boolean;
@@ -11,18 +11,73 @@ function guardedString(o, k) {
11
11
  const v = guarded(o, k);
12
12
  return typeof v === 'string' && v.length > 0 ? v : undefined;
13
13
  }
14
+ function guardedIn(o, k) {
15
+ try {
16
+ return k in o;
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
22
+ function carriesEngineResult(o) {
23
+ const stats = guardedIn(o, 'stats');
24
+ const terminal = guardedIn(o, 'terminal');
25
+ if (stats === true || terminal === true)
26
+ return true;
27
+ return stats === false && terminal === false ? false : undefined;
28
+ }
29
+ function engineResultLayerOf(carrier) {
30
+ try {
31
+ if (typeof carrier !== 'object' || carrier === null || Array.isArray(carrier))
32
+ return undefined;
33
+ const own = carriesEngineResult(carrier);
34
+ if (own !== false)
35
+ return own === true ? carrier : undefined;
36
+ const nested = guarded(carrier, 'result');
37
+ if (typeof nested !== 'object' || nested === null || Array.isArray(nested))
38
+ return undefined;
39
+ return carriesEngineResult(nested) === true ? nested : undefined;
40
+ }
41
+ catch {
42
+ return undefined;
43
+ }
44
+ }
45
+ function isRunReceiptShape(o) {
46
+ return guardedIn(o, 'activeTaskId') === false && guardedIn(o, 'taskId') === true;
47
+ }
48
+ export function terminalLayerOf(carrier) {
49
+ return engineResultLayerOf(carrier) ?? carrier;
50
+ }
51
+ export function runRowSentenceOf(carrier) {
52
+ try {
53
+ if (typeof carrier !== 'object' || carrier === null || Array.isArray(carrier))
54
+ return undefined;
55
+ if (engineResultLayerOf(carrier) !== undefined)
56
+ return undefined;
57
+ if (!isRunReceiptShape(carrier))
58
+ return undefined;
59
+ return guardedString(carrier, 'error');
60
+ }
61
+ catch {
62
+ return undefined;
63
+ }
64
+ }
14
65
  export function doneResultView(result) {
15
66
  if (typeof result !== 'object' || result === null || Array.isArray(result))
16
- return { replay: false, engine: result };
17
- if (guarded(result, 'replay') !== true)
18
- return { replay: false, engine: result };
19
- const row = {};
20
- for (const k of ['status', 'errorCode', 'error', 'sessionId']) {
67
+ return { replay: false, receipt: false, body: result };
68
+ const replay = guarded(result, 'replay') === true;
69
+ const engine = engineResultLayerOf(result);
70
+ if (engine !== undefined)
71
+ return { replay, receipt: false, body: engine };
72
+ if (!isRunReceiptShape(result))
73
+ return { replay, receipt: false, body: result };
74
+ const view = {};
75
+ for (const k of ['taskId', 'sessionId', 'status']) {
21
76
  const v = guardedString(result, k);
22
77
  if (v !== undefined)
23
- row[k] = v;
78
+ view[k] = v;
24
79
  }
25
- return { replay: true, engine: guarded(result, 'result'), row };
80
+ return { replay, receipt: true, body: Object.freeze(view) };
26
81
  }
27
82
  export function isReplayedTerminal(frame) {
28
83
  if (frame === null || typeof frame !== 'object' || Array.isArray(frame))
@@ -450,7 +450,7 @@ const resolvedSnapshotForWire = (resolved) => {
450
450
  export function hostTurnSettings(input) {
451
451
  return buildHostTurnSettings(input, { materialize: (snapshot) => resolvedSnapshotForWire(snapshot), memoryOffDeclared });
452
452
  }
453
- const fileRestoreRequested = (restoreFiles, rewindFilesTo, rewindFiles) => restoreFiles === true || (typeof rewindFilesTo === 'string' && rewindFilesTo.length > 0) || rewindFiles === true;
453
+ const fileRestoreRequested = (restoreFiles, rewindFilesTo) => restoreFiles === true || (typeof rewindFilesTo === 'string' && rewindFilesTo.length > 0);
454
454
  function tightenedRequestOf(request, intake, lane) {
455
455
  const readData = (key) => {
456
456
  try {
@@ -489,10 +489,9 @@ function tightenedRequestOf(request, intake, lane) {
489
489
  if (sent.value !== FILE_HISTORY_DISABLED) {
490
490
  const restoreFiles = readData('restoreFiles');
491
491
  const rewindFilesTo = readData('rewindFilesTo');
492
- const rewindFiles = readData('rewindFiles');
493
- if (!restoreFiles.ok || !rewindFilesTo.ok || !rewindFiles.ok)
492
+ if (!restoreFiles.ok || !rewindFilesTo.ok)
494
493
  return unjudged;
495
- if (fileRestoreRequested(restoreFiles.value, rewindFilesTo.value, rewindFiles.value))
494
+ if (fileRestoreRequested(restoreFiles.value, rewindFilesTo.value))
496
495
  return { kind: 'refuse', notice: hostFileHistoryRestoreNotice() };
497
496
  add.fileHistory = FILE_HISTORY_DISABLED;
498
497
  appendOwnElement(tightened, 'fileHistory');
@@ -25,5 +25,3 @@ export type DenyEntryReading = {
25
25
  readonly kind: 'unknown';
26
26
  };
27
27
  export declare function denyEntryReading(rule: string): DenyEntryReading;
28
- export declare const DOMAIN_TIGHTEN_HONORED_FROM = "7.135.0";
29
- export declare function tightenEntryNeverMatches(rule: string, serverVersion: string | undefined): boolean;
@@ -1,6 +1,5 @@
1
1
  import { readRuleEntry, validatePermissionRules } from './coreValuePorts.js';
2
2
  import { guardedRead, readOwnDataValue } from './ownKey.js';
3
- import { engineVersionTier } from './supportFloor.js';
4
3
  const RULE_COMPILE_ROOT = '/';
5
4
  function issueText(issue, key) {
6
5
  try {
@@ -73,33 +72,3 @@ export function denyEntryReading(rule) {
73
72
  return { kind: 'unknown' };
74
73
  }
75
74
  }
76
- function readsAsDomainSpelling(rule) {
77
- try {
78
- const reading = readRuleEntry(rule, 'allow');
79
- if (typeof reading !== 'object' || reading === null)
80
- return false;
81
- if (readOwnDataValue(reading, 'kind') !== 'row')
82
- return false;
83
- const compiled = readOwnDataValue(reading, 'compiled');
84
- if (typeof compiled !== 'object' || compiled === null)
85
- return false;
86
- return readOwnDataValue(compiled, 'kind') === 'domain';
87
- }
88
- catch {
89
- return false;
90
- }
91
- }
92
- export const DOMAIN_TIGHTEN_HONORED_FROM = '7.135.0';
93
- function targetLeavesDomainTightenInert(serverVersion) {
94
- return engineVersionTier(serverVersion) === 'engine' && engineVersionTier(serverVersion, DOMAIN_TIGHTEN_HONORED_FROM) === 'legacy';
95
- }
96
- export function tightenEntryNeverMatches(rule, serverVersion) {
97
- if (!targetLeavesDomainTightenInert(serverVersion))
98
- return false;
99
- const r = denyEntryReading(rule);
100
- if (r.kind !== 'inert' || r.reason !== 'content_unsupported')
101
- return false;
102
- if (!readsAsDomainSpelling(rule))
103
- return false;
104
- return ruleCompileVerdict(rule, 'deny').kind === 'compiles';
105
- }
@@ -10,7 +10,6 @@ const CLASS_OF_REASON = Object.freeze({
10
10
  home_relative_path: 'homePath',
11
11
  compile_refused: 'compile',
12
12
  paren_in_tool_name: 'compile',
13
- content_form_never_matches: 'neverMatches',
14
13
  });
15
14
  function reasonOf(row, lang) {
16
15
  const cls = typeof row.reason === 'string' && Object.hasOwn(CLASS_OF_REASON, row.reason) ? CLASS_OF_REASON[row.reason] : undefined;
@@ -18,8 +17,6 @@ function reasonOf(row, lang) {
18
17
  return renderMessage(msg('rules.refusal.reason.toolName'), lang);
19
18
  if (cls === 'homePath')
20
19
  return renderMessage(msg('rules.refusal.reason.homePath'), lang);
21
- if (cls === 'neverMatches')
22
- return renderMessage(msg('rules.refusal.reason.neverMatches'), lang);
23
20
  if (cls === 'compile')
24
21
  return permissionRuleIssueDetail(row.code, row.message, row.rule, lang);
25
22
  return undefined;
@@ -0,0 +1,30 @@
1
+ import type { UiLanguage } from './env/uiLanguage.js';
2
+ import { type MessageRef } from './i18n/translate.js';
3
+ import type { ReattachEvent } from './runReattachPolicy.js';
4
+ export type RunNotFollowedCause = 'reattach_exhausted' | 'no_run_id' | 'bad_input' | 'run_unknown' | 'target_unconfirmed' | 'cursor_unknown';
5
+ export type ReattachBreak = ReattachEvent['cause'];
6
+ export type RunNotFollowed<C extends RunNotFollowedCause = RunNotFollowedCause> = C extends 'reattach_exhausted' ? RunNotFollowedExhausted : RunNotFollowedFact<C>;
7
+ interface RunNotFollowedFact<C extends RunNotFollowedCause> {
8
+ readonly kind: 'not_followable';
9
+ readonly cause: C;
10
+ readonly taskId?: string;
11
+ }
12
+ interface RunNotFollowedExhausted extends RunNotFollowedFact<'reattach_exhausted'> {
13
+ readonly lastBreak?: ReattachBreak;
14
+ }
15
+ export declare const isReattachBreak: (v: {} | null | undefined) => v is ReattachBreak;
16
+ export declare function mintRunNotFollowed<C extends RunNotFollowedCause>(cause: C, taskId?: string, lastBreak?: ReattachBreak): RunNotFollowed<C>;
17
+ export declare function registerRunNotFollowed(thrown: object, fact: RunNotFollowed): void;
18
+ export declare function runNotFollowedOf(err: {} | null | undefined): RunNotFollowed | undefined;
19
+ interface NoticeParts {
20
+ readonly reason: MessageRef;
21
+ readonly ending: MessageRef | '';
22
+ readonly exit: MessageRef | '';
23
+ }
24
+ export declare function runNotFollowedHeadRef(taskId: string | undefined, parts: NoticeParts): MessageRef;
25
+ export declare function runNotFollowedReasonRef(cause: RunNotFollowedCause, lastBreak?: ReattachBreak): MessageRef;
26
+ export declare function runNotFollowedEndingUnknownRef(): MessageRef;
27
+ export declare function runNotFollowedExitRef(cause: RunNotFollowedCause): MessageRef | '';
28
+ export declare function runNotFollowedNoticeRef(fact: RunNotFollowed): MessageRef;
29
+ export declare function runNotFollowedNotice(fact: RunNotFollowed, lang?: UiLanguage): string;
30
+ export {};
@@ -0,0 +1,117 @@
1
+ import { msg, renderMessage } from './i18n/translate.js';
2
+ import { displayUntrusted } from './displayUntrusted.js';
3
+ import { guardedRead, readOwnDataValue } from './ownKey.js';
4
+ const RUN_NOT_FOLLOWED_CAUSES = Object.freeze(['reattach_exhausted', 'no_run_id', 'bad_input', 'run_unknown', 'target_unconfirmed', 'cursor_unknown']);
5
+ const _causesPin = true;
6
+ void _causesPin;
7
+ const REATTACH_BREAKS = Object.freeze(['connection_lost', 'stream_cap', 'stream_draining']);
8
+ const _breaksPin = true;
9
+ void _breaksPin;
10
+ const isCause = (v) => RUN_NOT_FOLLOWED_CAUSES.includes(v);
11
+ export const isReattachBreak = (v) => REATTACH_BREAKS.includes(v);
12
+ export function mintRunNotFollowed(cause, taskId, lastBreak) {
13
+ const c = isCause(cause) ? cause : 'bad_input';
14
+ const run = typeof taskId === 'string' && taskId !== '' ? { taskId } : {};
15
+ const fact = c === 'reattach_exhausted' ? { kind: 'not_followable', cause: c, ...run, ...(isReattachBreak(lastBreak) ? { lastBreak } : {}) } : { kind: 'not_followable', cause: c, ...run };
16
+ return Object.freeze(fact);
17
+ }
18
+ const notFollowedByThrown = new WeakMap();
19
+ export function registerRunNotFollowed(thrown, fact) {
20
+ try {
21
+ if ((typeof thrown === 'object' && thrown !== null) || typeof thrown === 'function')
22
+ notFollowedByThrown.set(thrown, fact);
23
+ }
24
+ catch {
25
+ }
26
+ }
27
+ export function runNotFollowedOf(err) {
28
+ try {
29
+ if (typeof err === 'object' && err !== null)
30
+ return notFollowedByThrown.get(err);
31
+ if (typeof err === 'function')
32
+ return notFollowedByThrown.get(err);
33
+ return undefined;
34
+ }
35
+ catch {
36
+ return undefined;
37
+ }
38
+ }
39
+ const TASK_ID_MAX = 64;
40
+ function readFact(fact) {
41
+ if (typeof fact !== 'object' || fact === null)
42
+ return undefined;
43
+ if (guardedRead(() => readOwnDataValue(fact, 'kind')) !== 'not_followable')
44
+ return undefined;
45
+ const cause = guardedRead(() => readOwnDataValue(fact, 'cause'));
46
+ if (!isCause(cause))
47
+ return undefined;
48
+ const rawTask = guardedRead(() => readOwnDataValue(fact, 'taskId'));
49
+ const shown = typeof rawTask === 'string' && rawTask !== '' ? guardedRead(() => displayUntrusted(rawTask, { max: TASK_ID_MAX, blanks: true })) : undefined;
50
+ const brk = cause === 'reattach_exhausted' ? guardedRead(() => readOwnDataValue(fact, 'lastBreak')) : undefined;
51
+ return { cause, ...(shown !== undefined && shown !== '' ? { taskId: shown } : {}), ...(isReattachBreak(brk) ? { lastBreak: brk } : {}) };
52
+ }
53
+ export function runNotFollowedHeadRef(taskId, parts) {
54
+ const tail = { reason: parts.reason, ending: parts.ending, exit: parts.exit };
55
+ return taskId !== undefined && taskId !== '' ? msg('follow.notFollowed.headRun', { taskId, ...tail }) : msg('follow.notFollowed.headTurn', tail);
56
+ }
57
+ const LAST_BREAK_REASON_KEYS = Object.freeze({
58
+ stream_draining: 'follow.notFollowed.reason.exhaustedDraining',
59
+ connection_lost: 'follow.notFollowed.reason.exhaustedConnectionLost',
60
+ stream_cap: 'follow.notFollowed.reason.exhaustedStreamCap',
61
+ });
62
+ export function runNotFollowedReasonRef(cause, lastBreak) {
63
+ switch (cause) {
64
+ case 'reattach_exhausted':
65
+ return msg(lastBreak !== undefined && isReattachBreak(lastBreak) ? LAST_BREAK_REASON_KEYS[lastBreak] : 'follow.notFollowed.reason.exhausted');
66
+ case 'bad_input':
67
+ return msg('follow.notFollowed.reason.badInput');
68
+ case 'no_run_id':
69
+ return msg('follow.notFollowed.reason.noRunId');
70
+ case 'run_unknown':
71
+ return msg('follow.notFollowed.reason.runUnknown');
72
+ default:
73
+ return msg('follow.notFollowed.reason.unspecified');
74
+ }
75
+ }
76
+ export function runNotFollowedEndingUnknownRef() {
77
+ return msg('follow.notFollowed.endingUnknown');
78
+ }
79
+ export function runNotFollowedExitRef(cause) {
80
+ switch (cause) {
81
+ case 'reattach_exhausted':
82
+ case 'bad_input':
83
+ return msg('follow.notFollowed.exit.reattach');
84
+ case 'no_run_id':
85
+ return msg('follow.notFollowed.exit.checkRuns');
86
+ case 'run_unknown':
87
+ return msg('follow.notFollowed.exit.runUnknown');
88
+ default:
89
+ return '';
90
+ }
91
+ }
92
+ function neutralNoticeRef() {
93
+ return runNotFollowedHeadRef(undefined, { reason: msg('follow.notFollowed.reason.unspecified'), ending: runNotFollowedEndingUnknownRef(), exit: '' });
94
+ }
95
+ export function runNotFollowedNoticeRef(fact) {
96
+ try {
97
+ const r = readFact(fact);
98
+ if (r === undefined)
99
+ return neutralNoticeRef();
100
+ return runNotFollowedHeadRef(r.taskId, {
101
+ reason: runNotFollowedReasonRef(r.cause, r.lastBreak),
102
+ ending: r.cause === 'run_unknown' ? '' : runNotFollowedEndingUnknownRef(),
103
+ exit: runNotFollowedExitRef(r.cause),
104
+ });
105
+ }
106
+ catch {
107
+ return neutralNoticeRef();
108
+ }
109
+ }
110
+ export function runNotFollowedNotice(fact, lang) {
111
+ try {
112
+ return renderMessage(runNotFollowedNoticeRef(fact), lang);
113
+ }
114
+ catch {
115
+ return renderMessage(neutralNoticeRef(), lang);
116
+ }
117
+ }
@@ -0,0 +1,20 @@
1
+ export interface RunLedgerSnapshot<F = never> {
2
+ readonly highWater: string;
3
+ readonly openToolStart?: object;
4
+ readonly folded?: F;
5
+ }
6
+ export interface RunLedgerFold<F> {
7
+ readonly init: () => F;
8
+ readonly step: (acc: F, ev: object) => F;
9
+ readonly strictOrder?: boolean;
10
+ readonly agree?: (a: F, b: F) => boolean;
11
+ readonly substantive?: (ev: object) => boolean;
12
+ }
13
+ export interface RunLedgerSnapshotDeps<F = never> {
14
+ readonly isParked: (taskId: string, signal: AbortSignal) => Promise<boolean>;
15
+ readonly frames: (taskId: string, signal: AbortSignal) => AsyncIterable<object>;
16
+ readonly budgetMs?: number;
17
+ readonly log?: (msg: string) => void;
18
+ readonly fold?: RunLedgerFold<F>;
19
+ }
20
+ export declare function readRunLedgerSnapshot<F = never>(taskId: string, callId: string | undefined, deps: RunLedgerSnapshotDeps<F>, signal?: AbortSignal): Promise<RunLedgerSnapshot<F> | null>;