@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,11 +1,9 @@
1
1
  import { join } from "node:path";
2
- import { guardedMemoryStore } from "../../core/memory.js";
3
2
  import { STORE_HOOK_KEYS, TtlSessionStore } from "../../core/session-store.js";
4
3
  import { BootLock, resolveDataRoot } from "./fs-atomic.js";
5
4
  import { assertAdoptionBootGate } from "./adoption/marker.js";
6
5
  import { FileCheckpointStore } from "./checkpoint-store.js";
7
6
  import { readLedgerTuning } from "./ledger-tuning.js";
8
- import { FileMemoryStore } from "./memory-store.js";
9
7
  import { FileSessionRepo } from "./session-store.js";
10
8
  import { FileToolResultStore } from "./tool-result-store.js";
11
9
  import { FileSessionPolicyStore } from "./session-policy-store.js";
@@ -23,7 +21,6 @@ function nestedOptions(value, member, keys) {
23
21
  return value === undefined ? undefined : receiveMembers(value, { subject: `FileStorageBackendOptions.${member}`, unit: "option", moment: "at new FileStorageBackend" }, keys);
24
22
  }
25
23
  export { FileCheckpointStore, CHECKPOINT_LEDGER_EVENT_KINDS, readCheckpointLedger, } from "./checkpoint-store.js";
26
- export { FileMemoryStore } from "./memory-store.js";
27
24
  export { FileSessionRepo } from "./session-store.js";
28
25
  export { FileToolResultStore } from "./tool-result-store.js";
29
26
  export { FileSessionPolicyStore } from "./session-policy-store.js";
@@ -37,7 +34,7 @@ export { atomicWriteFile, writeThenLink, ensureDir, readJsonlRecords, AppendLog
37
34
  export { processFingerprint, isProcessLive } from "./fs-atomic.js";
38
35
  export { AdoptionError, assertAdoptionBootGate, readRootAdoptionFile, writeRootAdoptionFile, ROOT_ADOPTION_FILE, } from "./adoption/marker.js";
39
36
  export { adoptLocalDataRoot, ackAdoptionConfig, witnessAdoptionConfig, listAdoptionQuarantine, readAdoptionStatus, } from "./adoption/adopt.js";
40
- const FILE_STORAGE_BACKEND_OPTION_KEYS = optionKeys()({ root: 0, utilityGate: 0, evict: 0, checkpoint: 0, retention: 0, fileHistory: 0, sessionPolicy: 0, embedder: 0, onCorruptRead: 0, sessions: 0 });
37
+ const FILE_STORAGE_BACKEND_OPTION_KEYS = optionKeys()({ root: 0, evict: 0, checkpoint: 0, retention: 0, fileHistory: 0, sessionPolicy: 0, onCorruptRead: 0, sessions: 0 });
41
38
  const NESTED_FILE_HISTORY_OPTION_KEYS = optionKeys()({ retention: 0 });
42
39
  const NESTED_SESSION_POLICY_OPTION_KEYS = optionKeys()({ mountedToolNames: 0 });
43
40
  const NESTED_CHECKPOINT_OPTION_KEYS = optionKeys()({ fsync: 0, compactEvery: 0, holderIsCurrent: 0 });
@@ -45,7 +42,6 @@ export class FileStorageBackend {
45
42
  root;
46
43
  sessionStore;
47
44
  checkpointStore;
48
- memoryStore;
49
45
  toolResultStore;
50
46
  sessionPolicyStore;
51
47
  workflowJournalStore;
@@ -58,7 +54,6 @@ export class FileStorageBackend {
58
54
  fileAgentRows;
59
55
  fileMailbox;
60
56
  fileCheckpoints;
61
- fileMemory;
62
57
  ttl;
63
58
  fileSessions;
64
59
  fileWorkflowJournal;
@@ -88,9 +83,6 @@ export class FileStorageBackend {
88
83
  this.fileCheckpoints = new FileCheckpointStore(this.root, { ...checkpointOptions, ...corruptRead, retention, ...(sessionHeadOf !== undefined ? { sessionHeadOf } : {}) });
89
84
  built.push(() => this.fileCheckpoints.close());
90
85
  this.checkpointStore = this.fileCheckpoints;
91
- this.fileMemory = new FileMemoryStore(this.root, opts.embedder ? { embedder: opts.embedder } : {});
92
- built.push(() => this.fileMemory.close());
93
- this.memoryStore = guardedMemoryStore(this.fileMemory, opts.utilityGate);
94
86
  this.toolResultStore = new FileToolResultStore(this.root, { ...corruptRead, retention });
95
87
  this.sessionPolicyStore = new FileSessionPolicyStore(this.root, { ...sessionPolicyOptions, ...corruptRead });
96
88
  this.fileWorkflowJournal = new FileWorkflowJournalStore(this.root, true, corruptRead);
@@ -138,12 +130,6 @@ export class FileStorageBackend {
138
130
  catch {
139
131
  }
140
132
  this.fileCheckpoints.close();
141
- try {
142
- await this.fileMemory.flushEmbeds();
143
- }
144
- catch {
145
- }
146
- this.fileMemory.close();
147
133
  this.fileWorkflowJournal.dispose();
148
134
  try {
149
135
  this.fileAgentRows.close();
@@ -264,13 +264,24 @@ export declare class FileDurableRulePartitionProvider implements DurableRulePart
264
264
  * dropped. A host reads `owners` through {@link forPrincipal} / {@link forLocalOwner} like any owner it knows; `unnamedBuckets > 0`
265
265
  * says its census of owners is incomplete by that many, not that they are empty.
266
266
  *
267
+ * A host may know owners the directory does not record (a File store beside this one derives some from its own import records):
268
+ * `opts.knownOwners` hands those principal names over, and each one whose bucket file is present here (the file the one digest,
269
+ * {@link principalRuleFileName}, names for it — the host never computes a bucket name) is listed in `owners`, after the ones the
270
+ * directory names, and is no longer counted in `unnamedBuckets`; so `unnamedBuckets` is then the count of buckets neither the
271
+ * directory nor the host can name (#3494). A name the host gives whose file is absent lists nothing and changes nothing, and a
272
+ * name given twice (or one the marker names too) is one owner. It is a plain object with that one member, and a list of
273
+ * principal names ({@link principalNameOf}: the one reading every face that takes a name judges by) — anything else refuses
274
+ * (`config.invalid_argument`), before the directory is looked at, rather than being read as "no known owners".
275
+ *
267
276
  * Reading takes no lock and writes nothing. A directory this engine refuses to use refuses with
268
277
  * {@link PERMISSION_RULES_DAMAGED_BUCKET_CODE}, as the read faces refuse it; a listing that failed to read refuses with
269
278
  * {@link PERMISSION_RULES_UNREADABLE_BUCKET_CODE} and the system error's name in `errno`; an adoption marker that does not read
270
279
  * refuses as {@link forPrincipal} refuses it (the marker is the truth of whose bucket is whose, so a listing never guesses
271
280
  * past it). An absent directory lists nothing.
272
281
  */
273
- listBucketOwners(): {
282
+ listBucketOwners(opts?: {
283
+ readonly knownOwners?: readonly string[];
284
+ }): {
274
285
  readonly owners: readonly RuleOwner[];
275
286
  readonly unnamedBuckets: number;
276
287
  };
@@ -4,14 +4,15 @@ import { createHash, randomBytes } from "node:crypto";
4
4
  import { isRuleBehavior } from "../../core/permission-rule-model.js";
5
5
  import { posixModeBitsMeaningful } from "../../core/posix-mode-face.js";
6
6
  import { readRuleOwner } from "../../core/rule-owner.js";
7
- import { principalNameOf, readPrincipal } from "../../core/principal-name.js";
7
+ import { principalNameFault, principalNameOf, readPrincipal } from "../../core/principal-name.js";
8
8
  import { PERMISSION_RULES_DAMAGED_BUCKET_CODE, PERMISSION_RULES_LATER_GRAMMAR_CODE, PERMISSION_RULES_UNREADABLE_BUCKET_CODE, PERMISSION_RULE_WRITER, applySyncJoin, applyTombstones, assertDeleteDeltaCarriesNoAdd, assertRedemptionNotQuarantined, assertWriteDeltaScopeDurable, foldDelta, unknownRuleWriteDeltaError, } from "../../core/permission-rule-store.js";
9
9
  import { sameOrgPolicyContent } from "../../core/permission-rule-org.js";
10
10
  import { SESSION_RULES_GRAMMAR, readRuleGrammarStamp } from "../../core/session-policy-store.js";
11
11
  import { canonicalize } from "../../core/canonical-json.js";
12
12
  import { BootLock, FileStoreLockError } from "./fs-atomic.js";
13
13
  import { assertAdoptionBootGate } from "./adoption/marker.js";
14
- import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
14
+ import { CONFIG_RECEIPT_MODE, optionKeys, receiptRefusal, receiveMembers, receiveOptions } from "../../core/own-property-receipt.js";
15
+ import { describeFault, receive } from "../../core/mods/kernel/receive.js";
15
16
  import { thrownText } from "../../core/thrown-value.js";
16
17
  function isRuleFile(v) {
17
18
  const p = v;
@@ -422,6 +423,31 @@ class FileDurableRulePartition {
422
423
  };
423
424
  }
424
425
  const FILE_DURABLE_RULE_PARTITION_PROVIDER_OPTION_KEYS = optionKeys()({ dataRoot: 0, platform: 0 });
426
+ const LIST_BUCKET_OWNERS_OPTION_KEYS = optionKeys()({ knownOwners: 0 });
427
+ function receiveKnownOwners(opts) {
428
+ if (opts === undefined)
429
+ return [];
430
+ const given = receiveMembers(opts, { subject: "listBucketOwners options", unit: "option", moment: "at listBucketOwners" }, LIST_BUCKET_OWNERS_OPTION_KEYS).knownOwners;
431
+ if (given === undefined)
432
+ return [];
433
+ const received = receive(given, CONFIG_RECEIPT_MODE);
434
+ if (!received.ok)
435
+ throw receiptRefusal(`listBucketOwners options.knownOwners could not be read — ${describeFault(received.fault)}; refused rather than read as "no known owners"`);
436
+ const list = received.value;
437
+ if (!Array.isArray(list) || list === given) {
438
+ throw receiptRefusal(`listBucketOwners options.knownOwners must be an array of principal names (got ${given === null ? "null" : Array.isArray(given) ? "an array the engine cannot copy" : typeof given}); refused rather than read as "no known owners"`);
439
+ }
440
+ const names = new Set();
441
+ for (let index = 0; index < list.length; index++) {
442
+ const element = Object.hasOwn(list, index) ? list[index] : undefined;
443
+ const name = principalNameOf(element);
444
+ if (name === undefined) {
445
+ throw receiptRefusal(`listBucketOwners options.knownOwners[${index}] is not a principal name (got ${principalNameFault(element)}); refused rather than skipped — a skipped name would be counted as a bucket nobody can name`);
446
+ }
447
+ names.add(name);
448
+ }
449
+ return [...names];
450
+ }
425
451
  export class FileDurableRulePartitionProvider {
426
452
  dir;
427
453
  onError;
@@ -505,7 +531,8 @@ export class FileDurableRulePartitionProvider {
505
531
  }
506
532
  return new FileDurableRulePartition(this.dir, join(this.dir, LOCAL_OWNER_FILE), this.acquireWriteLock, this.onError, this.vetting);
507
533
  }
508
- listBucketOwners() {
534
+ listBucketOwners(opts) {
535
+ const knownOwners = receiveKnownOwners(opts);
509
536
  const faulted = (err, what) => unreadableError(systemFaultRefusal(this.onError, err, `the permission-rule store directory could not be ${what} (${err?.code ?? err?.name ?? "unknown"})`, `${this.dir}: ${thrownText(err)}`));
510
537
  try {
511
538
  lstatSync(this.dir);
@@ -539,7 +566,7 @@ export class FileDurableRulePartitionProvider {
539
566
  owners.push({ kind: "local-owner" });
540
567
  const claimed = new Set();
541
568
  const named = new Set();
542
- for (const principal of [rec?.toPrincipal, rec?.from.kind === "principal" ? rec.from.principal : undefined]) {
569
+ for (const principal of [rec?.toPrincipal, rec?.from.kind === "principal" ? rec.from.principal : undefined, ...knownOwners]) {
543
570
  if (principal === undefined || named.has(principal))
544
571
  continue;
545
572
  named.add(principal);
@@ -55,7 +55,7 @@ class FileSessionStorage extends BaseSessionStorage {
55
55
  this.log.close();
56
56
  }
57
57
  isViewOf(row) {
58
- return this.log.isFileAtPath() && compareOccupants(this.occupant, row) !== "different";
58
+ return this.log.isFileAtPath() && compareOccupants(this.occupant, row) === "same";
59
59
  }
60
60
  persistSync(entry) {
61
61
  this.log.append({ kind: "entry", entry }, true);
@@ -17,7 +17,7 @@ import { resolveBashTimeoutCaps, bashTimeoutCapsSec, bashTimeoutArgRefusal, bash
17
17
  import { bashClassifyDefaultAllow, BASH_READONLY_DEFAULT_ALLOW, classifyBoundedReadonlyPollLoopDetailed, classifyCompoundReadonlyDetailed, parseLeadingCommandName } from "./bash-readonly-classifier.js";
18
18
  import { readOnlyShellVerdict } from "../../core/read-only-shell.js";
19
19
  import { toolFace } from "../../core/tool-catalog-entries.js";
20
- import { argvOf, compoundValueHidesRun, expansionHidesRun, expansionsInHeredocBody, lexShell } from "../../shell/lex.js";
20
+ import { argvOf, assignedWords, expansionHidesRun, expansionsInHeredocBody, lexShell, subscriptHidesRun } from "../../shell/lex.js";
21
21
  import { arithmeticAssignedNames } from "./shell-read-bindings.js";
22
22
  import { thrownText } from "../../core/thrown-value.js";
23
23
  import { patternKillRefusal } from "./pattern-kill-guard.js";
@@ -163,8 +163,8 @@ export function canAutoBackground(command, depth = 0) {
163
163
  return false;
164
164
  const segments = lexed.segments;
165
165
  const hidden = (e) => e !== undefined && e.kind !== "command" && e.kind !== "process" && e.kind !== "arithmetic" && expansionHidesRun(e);
166
- const words = segments.flatMap((s) => s.tokens.flatMap((t) => (t.kind === "word" ? [t] : t.kind === "redirect" && t.target !== undefined ? [t.target] : [])));
167
- if (words.some((w) => w.unresolved === "parameter_text" || compoundValueHidesRun(w) || w.expansions.some((p) => hidden(p.expansion))))
166
+ const words = segments.flatMap((s) => s.tokens.flatMap((t) => (t.kind === "word" ? assignedWords(t) : t.kind === "redirect" && t.target !== undefined ? [t.target] : [])));
167
+ if (words.some((w) => w.unresolved === "parameter_text" || w.assignment?.form === "compound" || subscriptHidesRun(w) || w.expansions.some((p) => hidden(p.expansion))))
168
168
  return false;
169
169
  const heredocs = segments.flatMap((s) => s.tokens.flatMap((t) => (t.kind === "heredoc" && !t.quoted ? [expansionsInHeredocBody(t.body)] : [])));
170
170
  if (heredocs.some((b) => b === undefined || b.some((x) => x.unresolved !== undefined || hidden(x.expansion))))
@@ -9,10 +9,16 @@ export type ShellRemovalCommand = (typeof SHELL_REMOVAL_COMMANDS)[number];
9
9
  /** What makes a removal target dangerous, in the order a card names it. */
10
10
  export type DangerousRemovalKind = "filesystem_root" | "home" | "workspace" | "top_level" | "mounted_drive";
11
11
  /** The protected locations a removal is judged against. `homes`: the environment's declared home and every other spelling
12
- * of it (its canonical one); `workspace`: the task root, the working directory, the additional working directories. */
12
+ * of it (its canonical one); `workspace`: the task root, the additional working directories — and, judged at one removal
13
+ * ({@link removalSeatAt}), the working directory; `startedIn`: the directory the command starts in, the removal's working
14
+ * directory wherever the plan does not prove the removal's shell left it (absent: `workspace` holds every one);
15
+ * `departures`: the plan's working-directory bases PROVEN to stand outside `startedIn` ({@link departuresOf}), by removal
16
+ * key (absent or empty: no base is). */
13
17
  export interface RemovalSeat {
14
18
  readonly homes: readonly string[];
15
19
  readonly workspace: readonly string[];
20
+ readonly startedIn?: string;
21
+ readonly departures?: ReadonlySet<string>;
16
22
  }
17
23
  /** One dangerous removal a command makes: the removal program, the operand as written, the target as established. */
18
24
  export interface DangerousRemoval {
@@ -87,7 +93,7 @@ export declare const KNOWN_SAFE_ROOTS: readonly string[];
87
93
  * ({@link runtimeScriptOf}), or one nobody read ({@link unreadPlan}, {@link programUnread}) — is an unreadable text of its
88
94
  * own. The read-face copy of an operand is not judged: it follows a link the removal does not follow.
89
95
  */
90
- export declare function removalFindingsOf(established: EstablishedPlan, seat: RemovalSeat, safeRoots?: readonly string[], enclosingRelocated?: boolean): RemovalFinding[];
96
+ export declare function removalFindingsOf(established: EstablishedPlan, seat: RemovalSeat, safeRoots?: readonly string[], enclosingRelocated?: boolean, apart?: boolean): RemovalFinding[];
91
97
  /** Does the removal program refuse this operand by its own first step — its last path component is `.` or `..`, trailing
92
98
  * separators stripped (POSIX `rm` step 1, which GNU, BSD and BusyBox `rm` keep; `rmdir(2)` fails on such a component
93
99
  * too)? It removes nothing there, wherever the name lands. The name is the one the program RECEIVES: a pattern's match
@@ -10,6 +10,30 @@ import { declaresOption, implementationsOf, programRow, rowRefusesArgv, runsShel
10
10
  import { inlineUntrusted } from "../../core/untrusted-text.js";
11
11
  export const SHELL_REMOVAL_COMMANDS = Object.freeze(["rm", "rmdir"]);
12
12
  const REMOVAL_COMMAND_SET = new Set(SHELL_REMOVAL_COMMANDS);
13
+ function removalSeatAt(seat, plan, segment, apart) {
14
+ const started = seat.startedIn;
15
+ const left = started !== undefined && !apart && segment.bases !== "unmodelled" && segment.bases.length > 0 && segment.bases.every((b) => seat.departures?.has(removalKey(b)) === true) && !plan.shape.backgrounded;
16
+ return { homes: seat.homes, workspace: [...seat.workspace, ...(left || started === undefined ? [] : [started])] };
17
+ }
18
+ function standsWithin(path, dir) {
19
+ const k = removalKey(path);
20
+ const d = removalKey(dir);
21
+ return k === d || k.startsWith(d.endsWith("/") ? d : `${d}/`);
22
+ }
23
+ async function departuresOf(plan, startedIn, env, signal) {
24
+ const start = await resolvedOrUndefined(env.canonicalPath(startedIn, signal), signal);
25
+ const out = new Set();
26
+ if (start === undefined || !start.ok)
27
+ return out;
28
+ for (const base of new Set(plan.segments.flatMap((s) => (s.bases === "unmodelled" ? [] : s.bases)))) {
29
+ if (standsWithin(base, startedIn) || standsWithin(base, start.value))
30
+ continue;
31
+ const canonical = await resolvedOrUndefined(env.canonicalPath(base, signal), signal);
32
+ if (canonical !== undefined && canonical.ok && !standsWithin(canonical.value, start.value))
33
+ out.add(removalKey(base));
34
+ }
35
+ return out;
36
+ }
13
37
  function removalKey(path) {
14
38
  let k = normalizeAbsPathLexically(path.normalize("NFC")).replace(/\\/g, "/").toLowerCase();
15
39
  k = k.replace(/(?:\/+\*+)+\/*$/, "");
@@ -89,7 +113,7 @@ function selectsOptions(row, args, shellChooses, ...wanted) {
89
113
  return wanted.every((has) => selected.some(has) || (shellChooses && declaresOption(view, has)));
90
114
  });
91
115
  }
92
- export function removalFindingsOf(established, seat, safeRoots = KNOWN_SAFE_ROOTS, enclosingRelocated = false) {
116
+ export function removalFindingsOf(established, seat, safeRoots = KNOWN_SAFE_ROOTS, enclosingRelocated = false, apart = false) {
93
117
  if (unreadPlan(established.plan))
94
118
  return [{ guard: "unverifiable_shell_text", program: "bash", text: established.plan.unreadable, source: "unread" }];
95
119
  const out = [];
@@ -114,7 +138,7 @@ export function removalFindingsOf(established, seat, safeRoots = KNOWN_SAFE_ROOT
114
138
  continue;
115
139
  if (refusedByRemoval(read))
116
140
  continue;
117
- const kind = removalKindOf(read, seat, rm);
141
+ const kind = removalKindOf(read, removalSeatAt(seat, established.plan, segment, apart), rm);
118
142
  if (kind !== undefined) {
119
143
  const untracked = read.candidate.bases === "unmodelled" ? established.plan.segments.find((s) => s.bases === "unmodelled")?.text.trim() : undefined;
120
144
  out.push({ guard: "dangerous_delete", kind, program: removal.program, operand: read.candidate.raw, target: read.target ?? read.candidate.floorSpelled ?? read.candidate.spelled, ...(untracked !== undefined ? { untrackedFrom: untracked } : {}) });
@@ -141,7 +165,7 @@ export function removalFindingsOf(established, seat, safeRoots = KNOWN_SAFE_ROOT
141
165
  }
142
166
  const sub = established.nested.get(nested);
143
167
  if (sub !== undefined)
144
- out.push(...removalFindingsOf(sub, seat, safeRoots, handedRelocated));
168
+ out.push(...removalFindingsOf(sub, seat, safeRoots, handedRelocated, true));
145
169
  }
146
170
  }
147
171
  return out;
@@ -238,9 +262,12 @@ export function removalReadingOf(command, req, seat, safeRoots = KNOWN_SAFE_ROOT
238
262
  async judge(signal) {
239
263
  const env = seat?.env;
240
264
  const resolved = env !== undefined && homeDir !== undefined ? await resolvedOrUndefined(env.canonicalPath(homeDir, signal), signal) : undefined;
265
+ const departures = env !== undefined && req.cwd !== undefined ? await departuresOf(plan, req.cwd, env, signal) : undefined;
241
266
  const removalSeat = {
242
267
  homes: [...(homeDir !== undefined ? [homeDir] : []), ...(resolved !== undefined && resolved.ok ? [resolved.value] : [])],
243
- workspace: [...(req.root !== undefined ? [req.root] : []), ...(req.cwd !== undefined ? [req.cwd] : []), ...(seat?.additionalRoots?.() ?? [])],
268
+ workspace: [...(req.root !== undefined ? [req.root] : []), ...(seat?.additionalRoots?.() ?? [])],
269
+ ...(req.cwd !== undefined ? { startedIn: req.cwd } : {}),
270
+ ...(departures !== undefined ? { departures } : {}),
244
271
  };
245
272
  const lexical = removalFindingsOf(establishShellReadsLexically(plan, boundary), removalSeat, safeRoots);
246
273
  if (lexical.some((f) => f.guard === "dangerous_delete") || env === undefined || roots.length === 0)
@@ -1,4 +1,4 @@
1
- import { literalTildeSpelling } from "../../shell/lex.js";
1
+ import { assignedWords, literalTildeSpelling } from "../../shell/lex.js";
2
2
  import { expandsOf, globMark, partPattern, readOfText, receivedWordOf, rewritten, spellingOf } from "./shell-read-word.js";
3
3
  import { arithmeticSubstitutions, bindsArrayElement, judgedSpellingOf, wordValues } from "./shell-read-bindings.js";
4
4
  import { argvProgramOf, attachedOptionPayloads, isPathShapedToken } from "./bash-readonly-classifier.js";
@@ -546,6 +546,12 @@ export function subscriptOnly(word) {
546
546
  return at < 0 ? "" : word.slice(at);
547
547
  }
548
548
  export function assignmentArithmetic(w, integer, ctx, asWritten = false) {
549
+ const stored = assignedWords(w);
550
+ if (stored[0] !== w) {
551
+ for (const e of stored)
552
+ assignmentArithmetic(e, integer, ctx, asWritten);
553
+ return;
554
+ }
549
555
  const a = w.assignment;
550
556
  if (a === undefined) {
551
557
  if (!asWritten)
@@ -29,6 +29,7 @@
29
29
  import { type LexedRedirect, type LexedSegment, type LexedToken, type LexedWord } from "../../shell/lex.js";
30
30
  import { readProgramPosition } from "./bash-program-position.js";
31
31
  import { type DeclaredAttribute } from "./program-read-model.js";
32
+ import { type StdinText } from "./shell-reentry-text.js";
32
33
  import { type BuiltinState } from "./shell-read-builtins.js";
33
34
  /** A value a name may hold — the text the program receives ({@link spelled}: what a shell re-parsing it reads), literal
34
35
  * throughout, or a PATTERN whose matches are the values (a `for` list word the shell globs before the loop binds it;
@@ -64,6 +65,9 @@ export interface FloorValue {
64
65
  readonly glob?: true;
65
66
  /** A pattern's spelling as a reader judges the names it matches, where it is not `spelled` ({@link judgedSpellingOf}). */
66
67
  readonly pattern?: string;
68
+ /** A value a binding that may not have run left an unknown name (#3536, {@link BindingTable.floorOf}): it yields to the
69
+ * floor reader's bound before any other ({@link wordFloorValues}). */
70
+ readonly held?: true;
67
71
  }
68
72
  /** A pattern value's names as a reader judges them, where that is not its spelling: its runs, a class the judge widens
69
73
  * as `?` (the lexer's `WordExpansion.pattern.judged`), a leading `~` the literal tilde it is. */
@@ -140,7 +144,8 @@ export declare function inheritedFunctionsOf(segments: readonly {
140
144
  export declare function inheritedExportedFunctions(names: ReadonlyMap<string, InheritedBody>): InheritedFunctions;
141
145
  /** One binding a segment makes: a name and what it now holds (`unknown` = made unknown). `prefix`: a binding that may or
142
146
  * may not take effect (a prefix assignment to a special builtin, which may or may not outlive its command; an `unset` of a
143
- * function, which a read-only function refuses). `loopVar`: a `for` loop's variable, held through its body. */
147
+ * function, which a read-only function refuses). `loopVar`: a `for` loop's variable — or the name a loop head's `read` binds
148
+ * from a literal input (#3401) — held through its body. */
144
149
  export interface Binding {
145
150
  readonly name: string;
146
151
  readonly state: NameState;
@@ -242,7 +247,7 @@ export declare function loopListHeadAt(argv: readonly LexedWord[]): number | und
242
247
  * more value its names may hold). `availability`: whether the builtin of a name runs by it where the segment stands
243
248
  * ({@link BuiltinState}) — `disabled`: the word finds no command and binds nothing, `maybe`: as a function that may stand.
244
249
  */
245
- export declare function bindingEffectOf(segment: LexedSegment, argv: readonly LexedWord[], shape: SegmentShape, readValue: ValueReader, shadow?: "named" | "maybe", availability?: (builtin: string) => BuiltinState): BindingEffect;
250
+ export declare function bindingEffectOf(segment: LexedSegment, argv: readonly LexedWord[], shape: SegmentShape, readValue: ValueReader, shadow?: "named" | "maybe", availability?: (builtin: string) => BuiltinState, fed?: readonly StdinText[], fedByLoop?: boolean): BindingEffect;
246
251
  /** Does this assignment store ARRAY ELEMENTS — a compound value `(…)`, or a subscripted name `a[k]=v`? Bash never exports
247
252
  * an array (an element assigned to an exported scalar makes it an array, gone from every child's environment): what it
248
253
  * stores reaches a program only through a word that reads an element — the element floor it leaves here ({@link
@@ -433,6 +438,12 @@ export declare class BindingThread {
433
438
  /** The names any of the text's function bodies binds — what a call to one of them may change — or `all` where a body
434
439
  * may bind any name. A name the body keeps `local` ({@link leavesBody}) stays in it. */
435
440
  functionBound(): ReadonlySet<string> | "all";
441
+ /** Of {@link functionBound}, the names a call MAY leave as they were: the body binds them where the binding may not have run
442
+ * — a `prefix` (a builtin that may not run as the builtin, a declaration behind a launcher) or a segment of SPLICED text
443
+ * (#3557: the sourced literal may never have run, so neither did the definition). A call kills these as one more value the
444
+ * name may hold (detached), never as a certainty — the value before the call stays the deny floor (#3536's law; #3566).
445
+ * A name the body ALSO binds certainly is not here: that binding makes the call's kill certain. */
446
+ functionMaybeBound(): ReadonlySet<string>;
436
447
  /** The function body a binding segment `at` makes belongs to, where the name can outlive it: the body it stands in — a
437
448
  * plain `local NAME` is the body's own and never leaves it (an optioned declaration, `declare -g` / `local -p`, reads no
438
449
  * scope, so it can). What a reader in ANOTHER body loses ({@link unreadableBy}); a call to the body changes it unless a
@@ -469,14 +480,15 @@ export declare class BindingThread {
469
480
  /** Does the block that holds a binding's words stay open (no closing word, no switch of branch) through `j`? */
470
481
  private heldThrough;
471
482
  /** Apply segment `at`'s effect. `andRun`: the segment was reached through `&&` / `||`. `loopEnd`: for a loop variable,
472
- * the index of the loop's end. */
473
- apply(at: number, effect: BindingEffect, andRun: boolean, loopEnd?: number): void;
483
+ * the index of the loop's end. `spliced`: the segment is a sourced literal's text standing in for its `source` (#3557):
484
+ * it may not have run, so every binding it makes is {@link Entry.detached} — one more value, never a certainty. */
485
+ apply(at: number, effect: BindingEffect, andRun: boolean, loopEnd?: number, spliced?: boolean): void;
474
486
  /** Does a reader at segment `j` lose the name `u` makes unreadable: past a name reference it may run after, or in a
475
487
  * function body other than the one that binds it? */
476
488
  private lostAt;
477
489
  /** Make these names unknown from segment `at` on (a loop body that binds them may have run before any of its beats; a
478
490
  * call runs a body that binds them). */
479
- kill(at: number, names: Iterable<string> | "all"): void;
491
+ kill(at: number, names: Iterable<string> | "all", spliced?: boolean): void;
480
492
  /** The table a reader at segment `j` sees; `andRunStart` = the first segment of `j`'s `&&` run; `where` = what the
481
493
  * working-directory thread says `PWD` / `OLDPWD` hold there (absent: it does not say — both unknown). */
482
494
  tableAt(j: number, andRunStart: number, where?: WorkingDirectoryState): BindingTable;
@@ -506,3 +518,7 @@ export declare function arithmeticSubstitutions(text: string, table: BindingTabl
506
518
  }): string[];
507
519
  /** The text of every `[…]` subscript in an arithmetic text (nested brackets balanced; an unclosed one runs to the end). */
508
520
  export declare function subscriptsOf(text: string): string[];
521
+ /** The substitution bodies a subscript's text carries, its quotes removed first (the evaluator sees the text without
522
+ * them; `keepQuotes` = the shell expands the text as it stands); a text the lexer refuses is returned whole (a body
523
+ * nothing could read is still re-entered). */
524
+ export declare function substitutionBodies(subscript: string, keepQuotes?: boolean): string[];