@sema-agent/core 7.64.0 → 7.66.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 (192) hide show
  1. package/CHANGELOG.md +571 -0
  2. package/dist/agents/delegation-registry-seat.d.ts +15 -0
  3. package/dist/agents/delegation-registry-seat.js +13 -0
  4. package/dist/agents/org-delivery-gate.d.ts +8 -1
  5. package/dist/agents/org-delivery-gate.js +9 -3
  6. package/dist/agents/peer-held-queue.js +1 -1
  7. package/dist/agents/peer-idle.js +1 -1
  8. package/dist/agents/peer-session-drain.d.ts +51 -12
  9. package/dist/agents/peer-session-drain.js +47 -34
  10. package/dist/agents/read-inbox-tool.d.ts +6 -2
  11. package/dist/agents/read-inbox-tool.js +18 -5
  12. package/dist/agents/subagent.d.ts +3 -1
  13. package/dist/agents/subagent.js +84 -77
  14. package/dist/brain/reasoning.d.ts +2 -0
  15. package/dist/brain/reasoning.js +1 -0
  16. package/dist/core/allow-entry.d.ts +9 -0
  17. package/dist/core/allow-entry.js +7 -1
  18. package/dist/core/ask-origin.d.ts +23 -3
  19. package/dist/core/ask-origin.js +11 -1
  20. package/dist/core/auto-promote.d.ts +3 -2
  21. package/dist/core/background-agent-store.d.ts +7 -0
  22. package/dist/core/checkpoint-store.d.ts +2 -3
  23. package/dist/core/context-settings.d.ts +1 -2
  24. package/dist/core/context-settings.js +1 -1
  25. package/dist/core/engine-attestation.d.ts +2 -2
  26. package/dist/core/engine-notice.d.ts +13 -1
  27. package/dist/core/engine-notice.js +3 -1
  28. package/dist/core/file-history-store.d.ts +2 -2
  29. package/dist/core/file-history-store.js +0 -4
  30. package/dist/core/gate-fold.js +3 -1
  31. package/dist/core/governance-codes.d.ts +6 -4
  32. package/dist/core/governance-codes.js +5 -3
  33. package/dist/core/human-input-projection.d.ts +9 -0
  34. package/dist/core/human-input-projection.js +13 -0
  35. package/dist/core/input-author.d.ts +66 -6
  36. package/dist/core/input-author.js +21 -3
  37. package/dist/core/leg-identity.d.ts +18 -2
  38. package/dist/core/leg-identity.js +5 -7
  39. package/dist/core/mailbox-store.d.ts +1 -1
  40. package/dist/core/memory-engine/consolidation.d.ts +30 -10
  41. package/dist/core/memory-engine/consolidation.js +41 -6
  42. package/dist/core/memory-engine/control-objects.d.ts +36 -3
  43. package/dist/core/memory-engine/control-objects.js +134 -12
  44. package/dist/core/memory-engine/control-plane-adoption.d.ts +13 -9
  45. package/dist/core/memory-engine/control-plane-adoption.js +58 -31
  46. package/dist/core/memory-engine/delegation-settlement.d.ts +75 -52
  47. package/dist/core/memory-engine/delegation-settlement.js +211 -228
  48. package/dist/core/memory-engine/dual-root.d.ts +3 -2
  49. package/dist/core/memory-engine/dual-root.js +5 -1
  50. package/dist/core/memory-engine/engine.d.ts +33 -16
  51. package/dist/core/memory-engine/engine.js +213 -177
  52. package/dist/core/memory-engine/file-backend.d.ts +21 -12
  53. package/dist/core/memory-engine/file-backend.js +58 -104
  54. package/dist/core/memory-engine/index.d.ts +2 -2
  55. package/dist/core/memory-engine/index.js +2 -2
  56. package/dist/core/memory-engine/layout.d.ts +184 -83
  57. package/dist/core/memory-engine/layout.js +267 -172
  58. package/dist/core/memory-engine/memory-age.d.ts +12 -0
  59. package/dist/core/memory-engine/memory-age.js +17 -0
  60. package/dist/core/memory-engine/memory-backend-contract.js +12 -11
  61. package/dist/core/memory-engine/memory-deployment.d.ts +4 -3
  62. package/dist/core/memory-engine/memory-deployment.js +6 -3
  63. package/dist/core/memory-engine/origin-clearance.d.ts +43 -15
  64. package/dist/core/memory-engine/origin-clearance.js +142 -58
  65. package/dist/core/memory-engine/tools.d.ts +2 -2
  66. package/dist/core/memory-engine/tools.js +7 -7
  67. package/dist/core/memory-engine/types.d.ts +16 -10
  68. package/dist/core/memory-vector.d.ts +6 -14
  69. package/dist/core/memory.d.ts +0 -462
  70. package/dist/core/memory.js +0 -333
  71. package/dist/core/model-receipt.d.ts +2 -1
  72. package/dist/core/model-receipt.js +5 -0
  73. package/dist/core/mods/dollar.d.ts +12 -0
  74. package/dist/core/mods/kernel/dispatch.d.ts +3 -1
  75. package/dist/core/mods/kernel/dispatch.js +5 -2
  76. package/dist/core/mods/kernel/events.d.ts +3 -1
  77. package/dist/core/mods/kernel/events.js +2 -2
  78. package/dist/core/mods/prompt-submit.d.ts +4 -0
  79. package/dist/core/mods/prompt-submit.js +24 -0
  80. package/dist/core/mods/stations.d.ts +23 -4
  81. package/dist/core/mods/stations.js +14 -7
  82. package/dist/core/permission-rule-consent.d.ts +49 -18
  83. package/dist/core/permission-rule-consent.js +59 -38
  84. package/dist/core/permission-rule-store.d.ts +24 -14
  85. package/dist/core/retention.d.ts +2 -7
  86. package/dist/core/retention.js +0 -1
  87. package/dist/core/retired-host-table-account.d.ts +19 -0
  88. package/dist/core/retired-host-table-account.js +28 -0
  89. package/dist/core/retired-tool-name-account.d.ts +60 -0
  90. package/dist/core/retired-tool-name-account.js +32 -0
  91. package/dist/core/roles.d.ts +3 -1
  92. package/dist/core/roles.js +5 -2
  93. package/dist/core/runner/classifier-ladder.d.ts +3 -1
  94. package/dist/core/runner/classifier-ladder.js +2 -2
  95. package/dist/core/runner/compact-session.js +2 -1
  96. package/dist/core/runner/contracts.d.ts +9 -9
  97. package/dist/core/runner/delegation-owner.d.ts +0 -8
  98. package/dist/core/runner/delegation-owner.js +1 -3
  99. package/dist/core/runner/gate-exit.js +9 -2
  100. package/dist/core/runner/memory-consolidation-driver.js +2 -2
  101. package/dist/core/runner/prepare-config-doors.js +1 -1
  102. package/dist/core/runner/prepare-delegation-surface.d.ts +1 -1
  103. package/dist/core/runner/prepare-delegation-surface.js +5 -3
  104. package/dist/core/runner/prepare-gate-stations.d.ts +8 -5
  105. package/dist/core/runner/prepare-gate-stations.js +13 -5
  106. package/dist/core/runner/prepare-inherited-gate.js +2 -0
  107. package/dist/core/runner/prepare-memory-engine-session.js +1 -1
  108. package/dist/core/runner/prepare-memory.js +35 -14
  109. package/dist/core/runner/prepare-policy-chain.js +12 -3
  110. package/dist/core/runner/prepare-project-context.js +2 -2
  111. package/dist/core/runner/prepare-task.d.ts +9 -1
  112. package/dist/core/runner/prepare-task.js +6 -5
  113. package/dist/core/runner/prepare-wiring-manifest.js +5 -4
  114. package/dist/core/runner/prompt-suggestions.js +1 -1
  115. package/dist/core/runner/run-identity-wiring.js +2 -2
  116. package/dist/core/runner/run-leg.js +3 -3
  117. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  118. package/dist/core/runner/run-notification-lane.js +2 -2
  119. package/dist/core/runner/runtask.js +6 -3
  120. package/dist/core/runner/steer-admission.d.ts +11 -2
  121. package/dist/core/runner/stream-steer-verb.d.ts +5 -2
  122. package/dist/core/runner/stream-steer-verb.js +67 -14
  123. package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -8
  124. package/dist/core/runner/sub-agent-deny-lists.js +22 -8
  125. package/dist/core/runner-deps.d.ts +4 -4
  126. package/dist/core/secret-env.d.ts +2 -2
  127. package/dist/core/secret-env.js +6 -20
  128. package/dist/core/session-store.d.ts +6 -6
  129. package/dist/core/session-store.js +3 -3
  130. package/dist/core/shell-run-candidates.js +3 -3
  131. package/dist/core/side-query.js +1 -1
  132. package/dist/core/skill-grant.d.ts +7 -0
  133. package/dist/core/skill-grant.js +14 -5
  134. package/dist/core/store-contracts/background-agent-store-contract.js +13 -0
  135. package/dist/core/task-event.d.ts +14 -0
  136. package/dist/core/task-notification.d.ts +35 -8
  137. package/dist/core/task-notification.js +31 -13
  138. package/dist/core/task-registry-agent.js +1 -0
  139. package/dist/core/task-registry-shared.d.ts +4 -0
  140. package/dist/core/tool-errors.d.ts +3 -3
  141. package/dist/core/tool-policy.js +2 -3
  142. package/dist/core/tool-spec.d.ts +20 -10
  143. package/dist/core/user-attachment.d.ts +5 -1
  144. package/dist/core/user-attachment.js +11 -5
  145. package/dist/core/write-protect.d.ts +16 -0
  146. package/dist/core/write-protect.js +10 -0
  147. package/dist/engine/harness/agent-harness.d.ts +19 -11
  148. package/dist/engine/harness/agent-harness.js +7 -4
  149. package/dist/engine/llm/types.d.ts +22 -10
  150. package/dist/engine/session/repo-utils.d.ts +14 -4
  151. package/dist/engine/session/repo-utils.js +5 -4
  152. package/dist/index.d.ts +10 -8
  153. package/dist/index.js +9 -7
  154. package/dist/prompts/default.d.ts +1 -2
  155. package/dist/scenarios/full-body.d.ts +1 -1
  156. package/dist/shell/lex.d.ts +50 -15
  157. package/dist/shell/lex.js +43 -9
  158. package/dist/stores/file/adoption/adopt.d.ts +1 -1
  159. package/dist/stores/file/index.d.ts +1 -15
  160. package/dist/stores/file/index.js +1 -15
  161. package/dist/stores/file/permission-rule-store.d.ts +12 -1
  162. package/dist/stores/file/permission-rule-store.js +31 -4
  163. package/dist/stores/file/session-store.js +1 -1
  164. package/dist/tools/fs/fs-bash.js +3 -3
  165. package/dist/tools/fs/removal-targets.d.ts +8 -2
  166. package/dist/tools/fs/removal-targets.js +31 -4
  167. package/dist/tools/fs/shell-read-argv.js +7 -1
  168. package/dist/tools/fs/shell-read-bindings.d.ts +21 -5
  169. package/dist/tools/fs/shell-read-bindings.js +130 -44
  170. package/dist/tools/fs/shell-read-plan.js +95 -29
  171. package/dist/tools/fs/shell-read-sourced.d.ts +25 -0
  172. package/dist/tools/fs/shell-read-sourced.js +119 -0
  173. package/dist/tools/fs/shell-read-word.d.ts +2 -2
  174. package/dist/tools/fs/shell-read-word.js +4 -5
  175. package/dist/tools/fs/shell-read-workdir.d.ts +19 -3
  176. package/dist/tools/fs/shell-read-workdir.js +60 -15
  177. package/dist/tools/fs/shell-reentry-text.d.ts +10 -2
  178. package/dist/tools/fs/shell-reentry-text.js +11 -4
  179. package/package.json +2 -2
  180. package/test/export-surface.snapshot.json +21 -79
  181. package/wire-changes/core-stores-sql@7.65.0.json +30 -0
  182. package/wire-changes/core-stores-sql@7.66.0.json +30 -0
  183. package/wire-changes/core@7.65.0.json +1650 -0
  184. package/wire-changes/core@7.66.0.json +1218 -0
  185. package/wire-changes/mods-kernel@7.65.0.json +30 -0
  186. package/wire-changes/mods-kernel@7.66.0.json +65 -0
  187. package/wire-changes/primitives@7.65.0.json +337 -0
  188. package/wire-changes/primitives@7.66.0.json +30 -0
  189. package/dist/core/memory-recall.d.ts +0 -208
  190. package/dist/core/memory-recall.js +0 -136
  191. package/dist/stores/file/memory-store.d.ts +0 -124
  192. package/dist/stores/file/memory-store.js +0 -353
@@ -1,44 +1,7 @@
1
- import { uuidv7 } from "../internal/harness.js";
2
1
  import { parseScopeKey } from "./memory-engine/scope-contract.js";
3
- import { termSet } from "./memory-vector.js";
4
2
  import { attrEscape } from "./task-notification.js";
5
3
  import { sanitizeUntrustedText, ENGINE_AUTHORITY_ENVELOPE_TAGS } from "./untrusted-text.js";
6
- import { thrownText } from "./thrown-value.js";
7
4
  import { CREDENTIAL_VOCABULARY, scanSecrets } from "@sema-agent/primitives";
8
- export function supportsConsolidation(store) {
9
- return (typeof store.searchScored === "function" &&
10
- typeof store.update === "function" &&
11
- typeof store.delete === "function");
12
- }
13
- export function supportsPeriodicConsolidation(store) {
14
- return (typeof store.getConsolidationCursor === "function" &&
15
- typeof store.setConsolidationCursor === "function");
16
- }
17
- export const CALLER_AUTHORED_TYPES = new Set(["user", "feedback", "project", "reference"]);
18
- export const DEFAULT_CALLER_AUTHORED_TYPE = "project";
19
- export class MemoryGateError extends Error {
20
- code;
21
- constructor(code, detail) {
22
- super(detail ? `${code}: ${detail}` : code);
23
- this.name = "MemoryGateError";
24
- this.code = code;
25
- }
26
- }
27
- export class MemoryProjectionError extends Error {
28
- code = "memory.projection_failed";
29
- committed = true;
30
- path;
31
- constructor(path, cause) {
32
- const detail = thrownText(cause);
33
- super(`memory.projection_failed: the note IS durably committed — only the derived projection ${path} could not be rewritten: ${detail}. ` +
34
- `Do not retry the write (it would store the note twice); the projection is rebuilt by the next mutation of this scope.`, cause !== undefined ? { cause } : undefined);
35
- this.name = "MemoryProjectionError";
36
- this.path = path;
37
- }
38
- }
39
- function hasPromotableMarker(note) {
40
- return note.outcomeStats !== undefined;
41
- }
42
5
  const REFUSE_WRITE_POLICY = Object.freeze({
43
6
  grade: "strict",
44
7
  readings: Object.freeze([Object.freeze({ kind: "raw" })]),
@@ -58,308 +21,12 @@ export function detectSecret(text) {
58
21
  return refuseLabel(row.id);
59
22
  return null;
60
23
  }
61
- export function enforceSecretWriteGate(body) {
62
- const label = detectSecret(body);
63
- if (label !== null) {
64
- throw new MemoryGateError("memory.secret_detected", `memory write blocked: detected ${label}`);
65
- }
66
- }
67
- export function enforceStructuredNoteSecretGate(note) {
68
- enforceSecretWriteGate(note.body);
69
- if (note.name !== undefined)
70
- enforceSecretWriteGate(note.name);
71
- if (note.description !== undefined)
72
- enforceSecretWriteGate(note.description);
73
- if (note.type !== undefined)
74
- enforceSecretWriteGate(note.type);
75
- }
76
- export function classifyPromotable(note) {
77
- if (hasPromotableMarker(note))
78
- return "promotable";
79
- if (note.type !== undefined && !CALLER_AUTHORED_TYPES.has(note.type))
80
- return "promotable";
81
- return "caller_authored";
82
- }
83
- export function enforcePromotableWriteGate(note, utilityVerdict, utilityGate) {
84
- if (classifyPromotable(note) === "caller_authored")
85
- return;
86
- if (utilityVerdict === undefined) {
87
- throw new MemoryGateError("memory.promotable_ungated", "promotable memory write requires a utilityVerdict");
88
- }
89
- if (utilityGate === undefined) {
90
- throw new MemoryGateError("memory.promotable_ungated", "promotable memory write but profile utilityGate is unwired");
91
- }
92
- if (!utilityGate(note.outcomeStats)) {
93
- throw new MemoryGateError("memory.promotable_ungated", "promotable memory write failed the profile utilityGate");
94
- }
95
- }
96
- function stripConsolidationGenerated(note) {
97
- if (note.consolidationGenerated === undefined)
98
- return note;
99
- const { consolidationGenerated: _drop, ...rest } = note;
100
- return rest;
101
- }
102
- export function guardedMemoryStore(inner, utilityGate) {
103
- const guarded = {
104
- get vectorMode() {
105
- return inner.vectorMode;
106
- },
107
- read: (scope) => inner.read(scope),
108
- clear: (scope) => inner.clear(scope),
109
- append: (scope, note) => {
110
- enforceSecretWriteGate(note);
111
- return inner.append(scope, note);
112
- },
113
- appendStructured: inner.appendStructured
114
- ? (scope, note) => {
115
- enforceStructuredNoteSecretGate(note);
116
- enforcePromotableWriteGate(note, undefined, utilityGate);
117
- return inner.appendStructured(scope, stripConsolidationGenerated(note));
118
- }
119
- : undefined,
120
- appendConsolidationGenerated: inner.appendStructured
121
- ? (scope, note) => {
122
- enforceStructuredNoteSecretGate(note);
123
- enforcePromotableWriteGate(note, undefined, utilityGate);
124
- const withMarker = { ...note, consolidationGenerated: true };
125
- if (inner.appendConsolidationGenerated)
126
- return inner.appendConsolidationGenerated(scope, withMarker);
127
- return inner.appendStructured(scope, withMarker);
128
- }
129
- : undefined,
130
- appendPromotable: (scope, note, utilityVerdict) => {
131
- enforceStructuredNoteSecretGate(note);
132
- enforcePromotableWriteGate(note, utilityVerdict, utilityGate);
133
- if (inner.appendPromotable)
134
- return inner.appendPromotable(scope, note, utilityVerdict);
135
- if (inner.appendStructured)
136
- return inner.appendStructured(scope, note);
137
- return inner.append(scope, note.body);
138
- },
139
- };
140
- if (inner.search)
141
- guarded.search = (scope, query, limit) => inner.search(scope, query, limit);
142
- if (inner.searchScored)
143
- guarded.searchScored = (scope, query, limit) => inner.searchScored(scope, query, limit);
144
- if (inner.update)
145
- guarded.update = (scope, id, text) => {
146
- enforceSecretWriteGate(text);
147
- return inner.update(scope, id, text);
148
- };
149
- if (inner.delete)
150
- guarded.delete = (scope, id) => inner.delete(scope, id);
151
- if (inner.listStructuredNotes)
152
- guarded.listStructuredNotes = (scope) => inner.listStructuredNotes(scope);
153
- if (inner.getByIds)
154
- guarded.getByIds = (scope, ids) => inner.getByIds(scope, ids);
155
- if (inner.getConsolidationCursor)
156
- guarded.getConsolidationCursor = (scope) => inner.getConsolidationCursor(scope);
157
- if (inner.setConsolidationCursor)
158
- guarded.setConsolidationCursor = (scope, cursor) => inner.setConsolidationCursor(scope, cursor);
159
- return guarded;
160
- }
161
- function renderBullet(e) {
162
- return `- (${e.ts} UTC) ${e.text}`;
163
- }
164
- export class InMemoryMemoryStore {
165
- byScope = new Map();
166
- cursorByScope = new Map();
167
- vectorMode = "lexical";
168
- read(scope) {
169
- const entries = this.byScope.get(scope);
170
- if (!entries || entries.length === 0) {
171
- return null;
172
- }
173
- return entries.map(renderBullet).join("\n");
174
- }
175
- append(scope, note) {
176
- const text = note.trim().replace(/^#+\s*/, "");
177
- if (!text) {
178
- return;
179
- }
180
- const ts = new Date().toISOString().replace("T", " ").slice(0, 16);
181
- const entry = { id: uuidv7(), text, ts };
182
- const arr = this.byScope.get(scope) ?? [];
183
- arr.push(entry);
184
- this.byScope.set(scope, arr);
185
- return entry.id;
186
- }
187
- appendStructured(scope, note) {
188
- const body = note.body.trim().replace(/^#+\s*/, "");
189
- if (!body)
190
- return "";
191
- const ts = new Date().toISOString().replace("T", " ").slice(0, 16);
192
- const entry = {
193
- id: uuidv7(),
194
- text: body,
195
- ts,
196
- name: note.name,
197
- type: note.type ?? "project",
198
- description: note.description?.trim() || firstSentence(body),
199
- links: note.links,
200
- ...(note.consolidationGenerated ? { consolidationGenerated: true } : {}),
201
- };
202
- const arr = this.byScope.get(scope) ?? [];
203
- arr.push(entry);
204
- this.byScope.set(scope, arr);
205
- return entry.id;
206
- }
207
- clear(scope) {
208
- this.byScope.delete(scope);
209
- this.cursorByScope.delete(scope);
210
- }
211
- search(scope, query, limit = 10) {
212
- const entries = this.byScope.get(scope);
213
- if (!entries || entries.length === 0) {
214
- return [];
215
- }
216
- return entries
217
- .map(renderBullet)
218
- .filter((b) => lexicalSearchMatch(query, b))
219
- .slice(-limit);
220
- }
221
- searchScored(scope, query, limit = 20) {
222
- const entries = this.byScope.get(scope);
223
- if (!entries || entries.length === 0) {
224
- return [];
225
- }
226
- const q = termSet(query);
227
- if (q.size === 0) {
228
- return [];
229
- }
230
- const scored = [];
231
- for (const e of entries) {
232
- const t = termSet(e.text);
233
- let inter = 0;
234
- for (const term of q) {
235
- if (t.has(term))
236
- inter++;
237
- }
238
- const union = q.size + t.size - inter;
239
- const jaccard = union === 0 ? 0 : inter / union;
240
- if (jaccard === 0)
241
- continue;
242
- scored.push({ id: e.id, text: e.text, score: 1 - jaccard, ...(e.consolidationGenerated ? { consolidationGenerated: true } : {}) });
243
- }
244
- scored.sort((a, b) => a.score - b.score);
245
- return scored.slice(0, limit);
246
- }
247
- update(scope, id, text) {
248
- const clean = text.trim();
249
- if (!clean) {
250
- return;
251
- }
252
- const entry = this.byScope.get(scope)?.find((e) => e.id === id);
253
- if (!entry) {
254
- return;
255
- }
256
- const newBody = clean.replace(/^#+\s*/, "");
257
- if (entry.description !== undefined && entry.description === firstSentence(entry.text)) {
258
- entry.description = firstSentence(newBody);
259
- }
260
- entry.text = newBody;
261
- entry.ts = new Date().toISOString().replace("T", " ").slice(0, 16);
262
- }
263
- delete(scope, id) {
264
- const arr = this.byScope.get(scope);
265
- if (!arr) {
266
- return;
267
- }
268
- const i = arr.findIndex((e) => e.id === id);
269
- if (i !== -1) {
270
- arr.splice(i, 1);
271
- }
272
- }
273
- listStructuredNotes(scope) {
274
- const entries = this.byScope.get(scope) ?? [];
275
- return entries.map((e) => ({
276
- id: e.id,
277
- description: e.description ?? firstSentence(e.text),
278
- ...parseNoteTimestamp(e.ts),
279
- ...(e.name ? { name: e.name } : {}),
280
- ...(e.type ? { type: e.type } : {}),
281
- ...(e.consolidationGenerated ? { consolidationGenerated: true } : {}),
282
- }));
283
- }
284
- getConsolidationCursor(scope) {
285
- return this.cursorByScope.get(scope);
286
- }
287
- setConsolidationCursor(scope, cursor) {
288
- this.cursorByScope.set(scope, cursor);
289
- }
290
- getByIds(scope, ids) {
291
- const entries = this.byScope.get(scope);
292
- if (!entries)
293
- return [];
294
- const want = new Set(ids);
295
- return entries
296
- .filter((e) => want.has(e.id))
297
- .map((e) => ({
298
- id: e.id,
299
- text: e.text,
300
- description: e.description ?? firstSentence(e.text),
301
- ...parseNoteTimestamp(e.ts),
302
- ...(e.name ? { name: e.name } : {}),
303
- ...(e.type ? { type: e.type } : {}),
304
- ...(e.consolidationGenerated ? { consolidationGenerated: true } : {}),
305
- }));
306
- }
307
- }
308
- export function expandLexicalTerms(term) {
309
- const t = term.toLowerCase();
310
- const out = new Set([t]);
311
- const stem = lightStem(t);
312
- const stemOk = stem !== t && stem.length >= 3;
313
- if (stemOk)
314
- out.add(stem);
315
- for (const group of LEXICAL_SYNONYM_GROUPS) {
316
- if (group.has(t) || (stemOk && group.has(stem)))
317
- for (const w of group)
318
- out.add(w);
319
- }
320
- return [...out];
321
- }
322
- export function lexicalSearchMatch(query, text) {
323
- const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
324
- if (terms.length === 0)
325
- return false;
326
- const lower = text.toLowerCase();
327
- const tokens = termSet(text);
328
- return terms.every((t) => {
329
- const variants = expandLexicalTerms(t);
330
- return variants.some((v) => v === t ? lower.includes(v) : tokens.has(v));
331
- });
332
- }
333
- const LEXICAL_SYNONYM_GROUPS = [
334
- new Set(["auth", "authentication", "authorization", "credentials", "credential", "login", "signin"]),
335
- new Set(["token", "bearer", "apikey", "secret", "key"]),
336
- new Set(["password", "passwd", "passphrase", "pwd"]),
337
- new Set(["delete", "remove", "drop", "erase"]),
338
- new Set(["config", "configuration", "settings", "setting"]),
339
- new Set(["error", "failure", "exception", "fault"]),
340
- new Set(["db", "database"]),
341
- ];
342
- function lightStem(t) {
343
- if (t.length > 4 && t.endsWith("ies"))
344
- return `${t.slice(0, -3)}y`;
345
- if (t.length > 3 && t.endsWith("es"))
346
- return t.slice(0, -2);
347
- if (t.length > 3 && t.endsWith("s") && !t.endsWith("ss"))
348
- return t.slice(0, -1);
349
- return t;
350
- }
351
24
  export function firstSentence(text) {
352
25
  const t = text.trim().replace(/\s+/g, " ");
353
26
  const dot = t.search(/[.!?](\s|$)/);
354
27
  const cut = dot >= 0 && dot < 160 ? dot + 1 : Math.min(t.length, 120);
355
28
  return t.slice(0, cut).trim();
356
29
  }
357
- export function parseNoteTimestamp(ts) {
358
- if (typeof ts !== "string" || ts.trim() === "")
359
- return { mtimeMs: 0, timestampMissing: true };
360
- const ms = Date.parse(`${ts.replace(" ", "T")}:00Z`);
361
- return Number.isFinite(ms) ? { mtimeMs: ms } : { mtimeMs: 0, timestampMissing: true };
362
- }
363
30
  export const MEMORY_PROJECT_KEY_ABSENT_REASONS = Object.freeze(["not_git", "bare", "unreadable"]);
364
31
  export function normalizeMemorySpec(input) {
365
32
  if (!input)
@@ -34,6 +34,7 @@ export declare function modelOriginOf(model: Model): Model;
34
34
  * holds a member the receipt cannot copy (a getter that threw, a function, another prototype) — `config.unknown_role` /
35
35
  * `not_a_model_ref`; a retired member — `config.deps_retired_key` (its own sentence); a member outside the contract — `not_a_model_ref`
36
36
  * (a provider's own parameters belong in `Model.params`); an `id` that is not a non-empty string or an `api` that is not a string —
37
- * `not_a_model_ref`, naming the member.
37
+ * `not_a_model_ref`, naming the member; a `defaultThinking` that is present but not one of the seven tiers — `not_a_model_ref`, naming
38
+ * the member.
38
39
  */
39
40
  export declare function receiveModel(value: unknown, seat: string, what?: string, note?: string): Model;
@@ -1,4 +1,5 @@
1
1
  import { types } from "node:util";
2
+ import { isThinkingLevel, THINKING_LEVELS } from "../brain/reasoning.js";
2
3
  import { describeFault, receive } from "./mods/kernel/receive.js";
3
4
  import { DECLARATION_RECEIPT_MODE } from "./own-property-receipt.js";
4
5
  import { assertNoRetiredKeys, RETIRED_MODEL_KEYS } from "./retired-keys.js";
@@ -99,6 +100,10 @@ function judgeModelCopy(copy, seat, what, note) {
99
100
  throw modelBindingRefusal(seat, "not_a_model_ref", `${seat} is ${what} carrying ${bindingShown(key)}, which is not a member of Model — a provider's own parameters belong in \`Model.params\`.${note}`);
100
101
  }
101
102
  }
103
+ const defaultThinking = copy["defaultThinking"];
104
+ if (defaultThinking !== undefined && !isThinkingLevel(defaultThinking)) {
105
+ throw modelBindingRefusal(seat, "not_a_model_ref", `${seat} is ${what} whose \`defaultThinking\` is ${bindingShown(defaultThinking)} — a model's default thinking level is one of ${THINKING_LEVELS.join(", ")} ("off" spells thinking off), or absent for no default.${note}`);
106
+ }
102
107
  }
103
108
  function sameData(a, b, top = false, compared = new Map()) {
104
109
  if (Object.is(a, b))
@@ -147,6 +147,12 @@ export interface EngineDollar extends ModDollarBase {
147
147
  readonly instructions?: string;
148
148
  }): Promise<SessionCompactAnswer>;
149
149
  };
150
+ readonly prompt: {
151
+ /** `$.prompt.submit({ text })`: an extension's prompt entering this leg in the person's place (`prompt-submit.ts`). */
152
+ submit(args: {
153
+ readonly text: string;
154
+ }): Promise<PromptSubmitAnswer>;
155
+ };
150
156
  readonly clock: {
151
157
  now(): Promise<number>;
152
158
  sleep(args: {
@@ -207,6 +213,12 @@ export type SessionSendAnswer = {
207
213
  readonly isDelivered: false;
208
214
  readonly reason: string;
209
215
  };
216
+ /** What `$.prompt.submit` answers when the input is taken: the text that entered, or why it did not (returned, not thrown). */
217
+ export type PromptSubmitAnswer = {
218
+ readonly text: string;
219
+ } | {
220
+ readonly drop: string;
221
+ };
210
222
  /** What `$.session.compact` answers: the in-place pass's outcome (a call it refuses throws, its reason on the report sink too). */
211
223
  export interface SessionCompactAnswer {
212
224
  readonly outcome: CompactOutcome;
@@ -1,7 +1,8 @@
1
1
  import { type ModBusSide, type ModEventName, type ModSeat } from "./events.js";
2
2
  import { type ModAdmissionRecord, type ModDollarBase, type ModOrigin, type ModSeats } from "./registration.js";
3
3
  import { type ModAnswerCheck, type ModAnswerer, type ModAnswerRanks, type ModEventPayload, type ModFailureCause, type ModMatcher, type ModSkip, type ProxyProbe } from "./site-rules.js";
4
- /** A frame on the dispatch stack: a registration's own `$` call, or one of its handlers running. */
4
+ /** A frame on the dispatch stack: a registration's own `$` call, or one of its handlers running — on `event` (a handler may hang
5
+ * on several events; the frame says which one it is running on, every frame from its mint, {@link handlerFrame}). */
5
6
  export type ModFrame = {
6
7
  readonly kind: "dollar";
7
8
  readonly plugin: string;
@@ -9,6 +10,7 @@ export type ModFrame = {
9
10
  readonly kind: "handler";
10
11
  readonly plugin: string;
11
12
  readonly handler: number;
13
+ readonly event: ModEventName;
12
14
  };
13
15
  /** What a chain bottom (the core of an event) receives besides `e`. */
14
16
  export interface ModBottomContext {
@@ -2,6 +2,9 @@ import { CATCH_BUDGET_MS, createSelfBudget, POST_ABORT_GRACE_MS, RUNAWAY_AFTER_M
2
2
  import { expandOnSide, failureRefuses, isModEventName, MOD_SEATS, nextToRefusal, stationOn } from "./events.js";
3
3
  import { ENGINE_ORIGIN, modsInvalid, screenModSeats, } from "./registration.js";
4
4
  import { answerUpward, answerViolation, detachedCopy, engineObjectsOnce, handedOn, handOnViolation, matcherMatches, matcherViolation, methodAnswerViolation, NEXT_IN_FLIGHT, receiveAnswer, receiveEvent, receivePayload, sealedObjects, } from "./site-rules.js";
5
+ function handlerFrame(below, plugin, handler, event) {
6
+ return Object.freeze([...below, Object.freeze({ kind: "handler", plugin, handler, event })]);
7
+ }
5
8
  const TIER_RANK = { prepend: 0, user: 1, append: 2, builtin: 3, core: 4 };
6
9
  const bypassed = (floors, tier) => floors.some((f) => TIER_RANK[f.from] < TIER_RANK[tier] && TIER_RANK[tier] < TIER_RANK[f.to]);
7
10
  export async function admitMods(input) {
@@ -501,7 +504,7 @@ function createBus(side, mounted, bottoms, entries, report, records, describe, i
501
504
  live.add(ac);
502
505
  const budgetMs = ownMs(h.reg.budgetMs);
503
506
  const budget = createSelfBudget(budgetMs, () => ac.abort(new Error(`${name} ran past its ${budgetMs}ms budget`)));
504
- const myFrames = Object.freeze([...fr, Object.freeze({ kind: "handler", plugin: name, handler: h.index })]);
507
+ const myFrames = handlerFrame(fr, name, h.index, event);
505
508
  const state = {
506
509
  pending: 0,
507
510
  called: false,
@@ -672,7 +675,7 @@ function createBus(side, mounted, bottoms, entries, report, records, describe, i
672
675
  live.add(ac);
673
676
  const budgetMs = ownMs(h.reg.budgetMs);
674
677
  const budget = createSelfBudget(budgetMs, () => ac.abort(new Error(`${name} ran past its ${budgetMs}ms budget`)));
675
- const myFrames = Object.freeze([...fr, Object.freeze({ kind: "handler", plugin: name, handler: h.index })]);
678
+ const myFrames = handlerFrame(fr, name, h.index, event);
676
679
  const refuse = () => Promise.reject(new Error(`${name}: an observe handler is not in the chain; next() is unavailable`));
677
680
  const next = makeNext({ budget, signal: ac.signal, trace: () => Object.freeze([]) }, refuse, refuse);
678
681
  const verdict = (r) => {
@@ -38,8 +38,10 @@
38
38
  * `prompt.submit` (a person's input entering the leg — rewritable, droppable, refused on a failure), `classic.SessionStart` and
39
39
  * `classic.SessionEnd` have stations, the two classic ones raised in the bottoms of `session.start` and `session.end`; the
40
40
  * methods `session.turns`, `session.usage` and `session.version` have bottoms, and `session.messages` takes `{ agentId }`.
41
+ * 9: `prompt.submit` has a `call` column — a `$` call reaches the host's entry, an extension's input entering the leg under the
42
+ * author `extension` — and pins `author` and `extension`; a handler's frame names the event it runs on (`ModFrame.event`).
41
43
  */
42
- export declare const KERNEL_CONTRACT_VERSION = 8;
44
+ export declare const KERNEL_CONTRACT_VERSION = 9;
43
45
  /** The five tiers in run order (CC names). `builtin` and `core` are the engine's own. */
44
46
  export declare const MOD_TIERS: readonly ["prepend", "user", "append", "builtin", "core"];
45
47
  export type ModTier = (typeof MOD_TIERS)[number];
@@ -1,4 +1,4 @@
1
- export const KERNEL_CONTRACT_VERSION = 8;
1
+ export const KERNEL_CONTRACT_VERSION = 9;
2
2
  export const MOD_TIERS = Object.freeze(["prepend", "user", "append", "builtin", "core"]);
3
3
  export const MOD_SEATS = Object.freeze(["deployment", "task"]);
4
4
  export const MOD_EVENT_SIDES = Object.freeze(["engine", "surface", "both"]);
@@ -94,7 +94,7 @@ export const MOD_EVENT_TABLE = Object.freeze({
94
94
  "ui.focus": surface(station("skip", "grace", ["component", "requestId", "plugin", "origin", "element"], { call: true })),
95
95
  "agent.offer": engine(station("skip", "grace", ["agent", "provider"])),
96
96
  "agent.spawn": engine(station("refuse_until_run", "immediate", AGENT_SPAWN_PINNED, { call: true })),
97
- "prompt.submit": engine(station("refuse", "immediate", ["source", "inputId", "actor"])),
97
+ "prompt.submit": engine(station("refuse", "immediate", ["source", "inputId", "actor", "author", "extension"], { call: true })),
98
98
  "prompt.fill": surface(station("skip", "grace", ["origin", "mode"], { call: true })),
99
99
  "prompt.suggest": surface(station("skip", "grace", ["origin"], { call: true })),
100
100
  "prompt.edit": surface(station("skip", "grace", ["origin", "key"], { budgetMs: PROMPT_EDIT_BUDGET_MS })),
@@ -0,0 +1,4 @@
1
+ import type { PromptSubmitRef } from "../input-author.js";
2
+ import type { ModCallEntry } from "./kernel/index.js";
3
+ /** `$.prompt.submit`'s host entry over the stream's binding (read at call time: unfilled ⇒ the call is dropped). */
4
+ export declare function createPromptSubmitEntry(ref: PromptSubmitRef | undefined): ModCallEntry;
@@ -0,0 +1,24 @@
1
+ import { PROMPT_SCREEN_STATIONS } from "./stations.js";
2
+ import { extensionWords } from "../untrusted-egress.js";
3
+ const ARGUMENT = "text";
4
+ export function createPromptSubmitEntry(ref) {
5
+ return async (args, ctx) => {
6
+ const by = ctx.origin.plugin;
7
+ const refused = (why) => `${by}: $.prompt.submit: refused: ${why}`;
8
+ const extra = Object.keys(args).find((k) => k !== ARGUMENT);
9
+ if (extra !== undefined)
10
+ throw new TypeError(refused(`takes { text }; "${extensionWords(extra, 40)}" is not one`));
11
+ const text = args[ARGUMENT];
12
+ if (typeof text !== "string" || text.trim() === "")
13
+ throw new TypeError(refused("no { text } (a non-empty string)"));
14
+ const seat = ref?.seat;
15
+ const handlers = ctx.frames.filter((f) => f.kind === "handler");
16
+ const waitedOn = handlers.some((f) => PROMPT_SCREEN_STATIONS.includes(f.event)) || (handlers.length > 0 && seat?.inputWindow() === "before");
17
+ if (waitedOn)
18
+ throw new Error(refused("called from a handler the leg is waiting on before it can take this input; answer { text } instead, or submit from a later event (turn.start / turn.complete)"));
19
+ if (seat === undefined)
20
+ return Object.freeze({ drop: "no running leg takes a prompt here" });
21
+ const answer = await seat.relay("extension", text, { frames: ctx.frames, origin: ctx.origin, extension: by, priority: "later", signal: ctx.signal });
22
+ return "entered" in answer ? Object.freeze({ text: answer.entered }) : Object.freeze({ drop: answer.drop });
23
+ };
24
+ }
@@ -12,7 +12,9 @@ import type { TaskSpec } from "../task-spec.js";
12
12
  import { type ModAnswerCheck, type ModAnswerRanks, type ModBus, type ModCallEntry, type ModEventName, type ModMountedHandler, type ModDispatchOutcome, type ModEventPayload, type ModRegistration } from "./kernel/index.js";
13
13
  import { type SourcedOverlay } from "../../prompt-assembly/overlay.js";
14
14
  import type { BandId } from "../../prompt-assembly/catalog/schema.js";
15
- import type { ModParticipant } from "./kernel/dispatch.js";
15
+ import type { ModFrame, ModParticipant } from "./kernel/dispatch.js";
16
+ import type { ModOrigin } from "./kernel/index.js";
17
+ import type { InputAuthor } from "../input-author.js";
16
18
  import { type EngineDollar, type ModelCompleteRequest, type ModelCompleteResult, type ModSeatView, type SessionUsage, type SessionVersion } from "./dollar.js";
17
19
  import type { SkillSpec } from "../agent-definition.js";
18
20
  import { type SkillScopes } from "./spec-seats.js";
@@ -46,8 +48,8 @@ export interface LegEvents {
46
48
  * Both ends of a leg, from the delegation fact alone (a child resumed from its checkpoint keeps it): a delegated leg opens on
47
49
  * `classic.SubagentStart` and ends on `classic.SubagentStop`, any other opens on nothing and ends on `classic.Stop`. Not the leg
48
50
  * kind (a resumed leg's kind reads `"resume"` whoever it runs as), and not who wrote the objective: whether an input passes
49
- * `classic.UserPromptSubmit` is the input's own fact, its author (`countsAsOperator`, input-author.ts) — a delegator's words are
50
- * judged at the delegator's gate (`classic.PreToolUse` on the delegating call), an operator's resume of a child is screened.
51
+ * the prompt screen is the input's own fact, its author's row (`isScreened`, input-author.ts) — a delegator's words are judged
52
+ * at the delegator's gate (`classic.PreToolUse` on the delegating call), an operator's resume of a child is screened.
51
53
  */
52
54
  export declare function legEventsOf(identity: Pick<HookInvocationIdentity, "isDelegatedChild"> | undefined): LegEvents;
53
55
  /**
@@ -164,6 +166,11 @@ export declare function classicEventBase(identity: HookInvocationIdentity | unde
164
166
  * an observation must never change what it observes. The `e` is the event's own, as {@link ClassicEventMap} types it.
165
167
  */
166
168
  export declare function observeClassic<K extends ClassicEventName>(bus: LegModBus, event: K, e: ClassicEventMap[K]["e"], signal: AbortSignal | undefined): Promise<void>;
169
+ /** The frames and origin a raise runs under (an extension's `$` call's), so the caller's own handlers stay out of it. */
170
+ export interface RaisedUnder {
171
+ readonly frames: readonly ModFrame[];
172
+ readonly origin: ModOrigin;
173
+ }
167
174
  /**
168
175
  * Raise a classic event whose answer the station reads: `undefined` when no handler hangs on it (the station
169
176
  * runs as if the bus were not there), else the dispatch outcome. A rejection is an engine fault, never a
@@ -175,6 +182,7 @@ export declare function dispatchClassic<K extends ClassicEventName>(bus: LegModB
175
182
  readonly checkAnswer?: ModAnswerCheck;
176
183
  readonly ranks?: ModAnswerRanks;
177
184
  readonly participant?: (p: ModParticipant) => boolean;
185
+ readonly raisedUnder?: RaisedUnder;
178
186
  }): Promise<ModDispatchOutcome | undefined>;
179
187
  /** The answer form of a classic event whose answer is an object of optional string members (`block`, `additionalContext`, …). */
180
188
  export declare function stringMembersAnswer(event: string, members: readonly string[]): (answer: unknown) => string | undefined;
@@ -256,6 +264,12 @@ export declare function promptScreenDeclaredBy(registrations: readonly {
256
264
  readonly events: readonly string[];
257
265
  };
258
266
  }[]): boolean;
267
+ /** A screened input as the screen raises it: its author as judged, and for an extension's prompt the caller and its `$` call. */
268
+ export interface PromptScreenInput {
269
+ readonly author: InputAuthor;
270
+ readonly extension?: string;
271
+ readonly raisedUnder?: RaisedUnder;
272
+ }
259
273
  /**
260
274
  * A prompt's screen at one of the four entrances (objective, live steer, a wake's message before its claim, a parked steer
261
275
  * redelivered): `prompt.submit` over `e` with the prompt as `text`, its bottom raising `classic.UserPromptSubmit` on the text
@@ -263,8 +277,9 @@ export declare function promptScreenDeclaredBy(registrations: readonly {
263
277
  * handler that throws, runs past its budget or breaks the site's contract ends the screen `failed`, and every entrance fails
264
278
  * closed on it; a cancelled screen ends `aborted` at once; a dispatch the engine could not run is `failed` too. What the
265
279
  * classic screen refused (its block, failure or cancel) is final — a `prompt.submit` handler above it does not undo it.
280
+ * `input` ({@link PromptScreenInput}) rides `prompt.submit`'s `e` (both stations raised under its `$` call, when it has one).
266
281
  */
267
- export declare function screenUserPrompt(bus: LegModBus, e: UserPromptSubmitEvent, signal: AbortSignal | undefined): Promise<PromptScreen | undefined>;
282
+ export declare function screenUserPrompt(bus: LegModBus, e: UserPromptSubmitEvent, signal: AbortSignal | undefined, input?: PromptScreenInput): Promise<PromptScreen | undefined>;
268
283
  /**
269
284
  * Raise `classic.SubagentStart` as a delegated leg opens on its objective (undefined when no handler hangs on it): the
270
285
  * context the chain answers. It never keeps the child from starting — a handler that fails is skipped and reported by
@@ -363,6 +378,8 @@ export interface LegFacadeSeats {
363
378
  readonly sessionSend: ModCallEntry;
364
379
  /** `$.session.compact`'s host entry (`createSessionCompactEntry`, `session-compact.ts`). */
365
380
  readonly sessionCompact: ModCallEntry;
381
+ /** `$.prompt.submit`'s host entry (`createPromptSubmitEntry`, `prompt-submit.ts`). */
382
+ readonly promptSubmit: ModCallEntry;
366
383
  }
367
384
  /** The leg's admitted bus, its chain identity (the one its admission recorded, {@link chainOfBus}) and the binding of the
368
385
  * facade its `$` reaches. `bus` is the leg bus every station raises on ({@link legBusOf}: an extension's own call's
@@ -441,6 +458,8 @@ export interface LegFacadeInput {
441
458
  readonly sessionSend: ModCallEntry;
442
459
  /** `$.session.compact`'s host entry, over the leg's compaction station. */
443
460
  readonly sessionCompact: ModCallEntry;
461
+ /** `$.prompt.submit`'s host entry, over the leg's stream's steer relay. */
462
+ readonly promptSubmit: ModCallEntry;
444
463
  }
445
464
  /** The seat a leg reads its subagents' transcripts through: its task list, only the rows its own access reaches. Each row
446
465
  * carries the store its child's session lives in, so no store of the leg's own is read. */