@sema-agent/core 7.61.0 → 7.62.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 (176) hide show
  1. package/CHANGELOG.md +312 -0
  2. package/dist/agents/cascade.d.ts +11 -3
  3. package/dist/agents/cascade.js +1 -1
  4. package/dist/agents/peer-held-queue.d.ts +27 -4
  5. package/dist/agents/peer-held-queue.js +81 -36
  6. package/dist/agents/peer-session-drain.js +13 -3
  7. package/dist/agents/subagent.d.ts +6 -1
  8. package/dist/agents/subagent.js +66 -12
  9. package/dist/agents/suspend-guard.d.ts +38 -16
  10. package/dist/agents/suspend-guard.js +9 -4
  11. package/dist/agents/verify.js +4 -3
  12. package/dist/core/checkpoint-features.d.ts +722 -0
  13. package/dist/core/checkpoint-features.js +98 -0
  14. package/dist/core/checkpoint-requirements.d.ts +9 -2
  15. package/dist/core/checkpoint-requirements.js +9 -4
  16. package/dist/core/checkpoint-row-verdict.d.ts +99 -0
  17. package/dist/core/checkpoint-row-verdict.js +225 -0
  18. package/dist/core/checkpoint-store.d.ts +55 -745
  19. package/dist/core/checkpoint-store.js +39 -141
  20. package/dist/core/engine-notice.d.ts +19 -3
  21. package/dist/core/engine-notice.js +9 -2
  22. package/dist/core/gate-fold.js +2 -2
  23. package/dist/core/governance-codes.d.ts +3 -1
  24. package/dist/core/governance-codes.js +3 -0
  25. package/dist/core/hooks.d.ts +13 -0
  26. package/dist/core/human-input-projection.d.ts +1 -0
  27. package/dist/core/human-input-projection.js +3 -0
  28. package/dist/core/image-admission.d.ts +1 -1
  29. package/dist/core/locked-config.d.ts +2 -2
  30. package/dist/core/mcp-host-seat.js +6 -1
  31. package/dist/core/memory-engine/consolidation-driver.d.ts +1 -1
  32. package/dist/core/memory-vector.d.ts +1 -1
  33. package/dist/core/memory.d.ts +10 -10
  34. package/dist/core/mode-policy.js +1 -1
  35. package/dist/core/mods/classic-events.d.ts +9 -1
  36. package/dist/core/mods/dollar.d.ts +32 -1
  37. package/dist/core/mods/dollar.js +13 -1
  38. package/dist/core/mods/kernel/events.d.ts +11 -3
  39. package/dist/core/mods/kernel/events.js +13 -10
  40. package/dist/core/mods/lifecycle-stations.d.ts +36 -4
  41. package/dist/core/mods/lifecycle-stations.js +44 -9
  42. package/dist/core/mods/session-append.d.ts +4 -1
  43. package/dist/core/mods/session-append.js +7 -0
  44. package/dist/core/mods/session-receive.js +12 -15
  45. package/dist/core/mods/stations.d.ts +51 -6
  46. package/dist/core/mods/stations.js +124 -0
  47. package/dist/core/own-property-receipt.d.ts +7 -0
  48. package/dist/core/own-property-receipt.js +3 -0
  49. package/dist/core/read-root-candidate.js +1 -1
  50. package/dist/core/resume-startup-cause.d.ts +5 -4
  51. package/dist/core/runner/compact-session.js +5 -2
  52. package/dist/core/runner/contracts.d.ts +18 -8
  53. package/dist/core/runner/delegation-owner.d.ts +43 -0
  54. package/dist/core/runner/delegation-owner.js +59 -0
  55. package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
  56. package/dist/core/runner/lineage-reroot-view.js +108 -0
  57. package/dist/core/runner/permission-rule-lanes.d.ts +2 -1
  58. package/dist/core/runner/permission-rule-lanes.js +2 -2
  59. package/dist/core/runner/person-path-rows.d.ts +15 -0
  60. package/dist/core/runner/person-path-rows.js +26 -3
  61. package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
  62. package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
  63. package/dist/core/runner/prepare-caps-and-workflow.d.ts +1 -0
  64. package/dist/core/runner/prepare-caps-and-workflow.js +1 -1
  65. package/dist/core/runner/prepare-config-doors.d.ts +6 -6
  66. package/dist/core/runner/prepare-config-doors.js +3 -4
  67. package/dist/core/runner/prepare-hands-readface.d.ts +1 -1
  68. package/dist/core/runner/prepare-hands-readface.js +28 -7
  69. package/dist/core/runner/prepare-inherited-gate.d.ts +2 -0
  70. package/dist/core/runner/prepare-inherited-gate.js +7 -3
  71. package/dist/core/runner/prepare-task.js +10 -7
  72. package/dist/core/runner/resume-admission.d.ts +3 -3
  73. package/dist/core/runner/resume-admission.js +6 -3
  74. package/dist/core/runner/resume-apply.d.ts +4 -0
  75. package/dist/core/runner/resume-apply.js +11 -4
  76. package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
  77. package/dist/core/runner/resume-checkpoint-screen.js +4 -84
  78. package/dist/core/runner/run-git-lane.d.ts +2 -0
  79. package/dist/core/runner/run-git-lane.js +4 -1
  80. package/dist/core/runner/run-harness-handlers.d.ts +2 -0
  81. package/dist/core/runner/run-harness-handlers.js +3 -2
  82. package/dist/core/runner/run-leg.js +24 -7
  83. package/dist/core/runner/run-settle-and-teardown.js +3 -2
  84. package/dist/core/runner/run-stop-and-final-verify.js +2 -1
  85. package/dist/core/runner/run-turn-boundary.js +7 -4
  86. package/dist/core/runner/runtask.js +6 -6
  87. package/dist/core/runner/steering-preview.d.ts +9 -0
  88. package/dist/core/runner/steering-preview.js +5 -0
  89. package/dist/core/runner/stream-steer-verb.js +8 -0
  90. package/dist/core/runner/tool-face-overlay.js +2 -0
  91. package/dist/core/runner/turn-attachments.d.ts +5 -0
  92. package/dist/core/runner/turn-attachments.js +1 -1
  93. package/dist/core/runner-deps.d.ts +2 -2
  94. package/dist/core/secret-env.d.ts +8 -5
  95. package/dist/core/secret-env.js +37 -18
  96. package/dist/core/session-store.d.ts +1 -1
  97. package/dist/core/session-store.js +5 -1
  98. package/dist/core/session.d.ts +14 -4
  99. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +6 -0
  100. package/dist/core/store-contracts/checkpoint-store-contract.js +68 -0
  101. package/dist/core/store-contracts/session-store-contract.js +22 -8
  102. package/dist/core/task-event.d.ts +7 -1
  103. package/dist/core/task-notification.js +2 -1
  104. package/dist/core/task-registry-agent.d.ts +27 -7
  105. package/dist/core/task-registry-agent.js +12 -5
  106. package/dist/core/task-registry-shared.d.ts +7 -0
  107. package/dist/core/task-registry-workflow.js +4 -3
  108. package/dist/core/task-registry.d.ts +13 -2
  109. package/dist/core/task-registry.js +11 -4
  110. package/dist/core/task-result.d.ts +5 -5
  111. package/dist/core/task-spec.d.ts +1 -1
  112. package/dist/core/terminal-cause.d.ts +6 -6
  113. package/dist/core/tool-face.d.ts +6 -2
  114. package/dist/core/tool-face.js +1 -1
  115. package/dist/core/tool-policy.d.ts +2 -1
  116. package/dist/core/tool-roster.d.ts +4 -4
  117. package/dist/core/tool-spec.d.ts +4 -0
  118. package/dist/core/types.d.ts +1 -1
  119. package/dist/core/types.js +1 -1
  120. package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
  121. package/dist/engine/execution-env/node-execution-env.js +12 -5
  122. package/dist/engine/harness/types.d.ts +11 -0
  123. package/dist/engine/session/parent-chain-guard.d.ts +3 -3
  124. package/dist/engine/session/parent-chain-guard.js +1 -1
  125. package/dist/engine/session/path-to-root.d.ts +18 -3
  126. package/dist/engine/session/path-to-root.js +15 -1
  127. package/dist/engine/session/repo-utils.d.ts +12 -1
  128. package/dist/engine/session/repo-utils.js +41 -0
  129. package/dist/engine/session/session.js +1 -1
  130. package/dist/engine/session/storage-base.d.ts +20 -0
  131. package/dist/engine/session/storage-base.js +28 -9
  132. package/dist/index.d.ts +9 -8
  133. package/dist/index.js +4 -4
  134. package/dist/internal/harness.d.ts +4 -3
  135. package/dist/internal/harness.js +3 -2
  136. package/dist/orchestration/run-workflow-tool.d.ts +3 -0
  137. package/dist/orchestration/run-workflow-tool.js +27 -11
  138. package/dist/orchestration/workflow-governance.d.ts +1 -1
  139. package/dist/orchestration/workflow.d.ts +3 -0
  140. package/dist/orchestration/workflow.js +2 -7
  141. package/dist/stores/file/checkpoint-store.d.ts +2 -0
  142. package/dist/stores/file/checkpoint-store.js +7 -6
  143. package/dist/stores/file/fs-atomic.d.ts +0 -22
  144. package/dist/stores/file/fs-atomic.js +0 -17
  145. package/dist/stores/file/index.d.ts +2 -9
  146. package/dist/stores/file/index.js +2 -4
  147. package/dist/stores/file/session-store.d.ts +13 -7
  148. package/dist/stores/file/session-store.js +40 -17
  149. package/dist/tools/fs/bash-program-position.d.ts +3 -2
  150. package/dist/tools/fs/bash-program-position.js +7 -7
  151. package/dist/tools/fs/removal-targets.js +2 -2
  152. package/dist/tools/fs/shell-read-argv.d.ts +4 -2
  153. package/dist/tools/fs/shell-read-argv.js +14 -3
  154. package/dist/tools/fs/shell-read-bindings.d.ts +18 -2
  155. package/dist/tools/fs/shell-read-bindings.js +148 -68
  156. package/dist/tools/fs/shell-read-check.js +20 -4
  157. package/dist/tools/fs/shell-read-establish.js +22 -8
  158. package/dist/tools/fs/shell-read-functions.js +2 -2
  159. package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
  160. package/dist/tools/fs/shell-read-object-path.js +119 -0
  161. package/dist/tools/fs/shell-read-plan.d.ts +8 -0
  162. package/dist/tools/fs/shell-read-plan.js +47 -30
  163. package/dist/tools/fs/shell-read-start.d.ts +66 -13
  164. package/dist/tools/fs/shell-read-start.js +89 -17
  165. package/dist/tools/fs/shell-read-workdir.d.ts +29 -8
  166. package/dist/tools/fs/shell-read-workdir.js +31 -8
  167. package/package.json +2 -2
  168. package/test/export-surface.snapshot.json +21 -33
  169. package/wire-changes/core-stores-sql@7.62.0.json +30 -0
  170. package/wire-changes/core@7.62.0.json +2181 -0
  171. package/wire-changes/mods-kernel@7.62.0.json +42 -0
  172. package/wire-changes/primitives@7.62.0.json +30 -0
  173. package/dist/core/consolidate-scope.d.ts +0 -93
  174. package/dist/core/consolidate-scope.js +0 -98
  175. package/dist/core/runner/memory-consolidation.d.ts +0 -109
  176. package/dist/core/runner/memory-consolidation.js +0 -251
@@ -16,7 +16,7 @@ export interface ScoredMemory {
16
16
  /** design/84 Seam B (前置 BLOCKER): true when this note was CREATED by a consolidation ADD (not the
17
17
  * `remember` tool / a caller). Periodic/incremental consolidation EXCLUDES these from its candidate set so
18
18
  * it never re-consolidates its own output (infinite re-merge). Stores that don't track it leave it absent
19
- * (treated as not-generated — back-compat, RL-1654-memorystore: the inline task-end path already excludes this-task notes by id). */
19
+ * (treated as not-generated — back-compat, RL-1654-store-family: the inline task-end path already excludes this-task notes by id). */
20
20
  consolidationGenerated?: boolean;
21
21
  }
22
22
  /**
@@ -86,7 +86,7 @@ export interface MemoryStore {
86
86
  */
87
87
  searchScored?(scope: string, query: string, limit?: number): Promise<ScoredMemory[]> | ScoredMemory[];
88
88
  /** The vector-ranking rung this store achieves (design/81 Slice 5). Absent ⇒ treated as `"lexical"`
89
- * (back-compat, RL-1654-memorystore). A runtime observable — a deployment reads it to decide index/metrics, NOT to decide
89
+ * (back-compat, RL-1654-store-family). A runtime observable — a deployment reads it to decide index/metrics, NOT to decide
90
90
  * whether to inject an embedder (injection is config-driven; this is the RESULT). See {@link MemoryVectorMode}. */
91
91
  readonly vectorMode?: MemoryVectorMode;
92
92
  /** Optional: replace a note's text by id (consolidation UPDATE). The id stays stable. Must be safe
@@ -125,8 +125,8 @@ export interface MemoryStore {
125
125
  */
126
126
  appendPromotable?(scope: string, note: StructuredNoteInput, utilityVerdict: unknown): Promise<string> | string;
127
127
  /**
128
- * **INTERNAL consolidation-only door** for the design/84 Seam B marker. Memory consolidation (and ONLY
129
- * it — `runMemoryConsolidation`) calls this to materialize a merged "add" decision tagged
128
+ * **INTERNAL consolidation-only door** for the design/84 Seam B marker. A consolidation pass (and ONLY
129
+ * it; none ships in the package any more) calls this to materialize a merged "add" decision tagged
130
130
  * `consolidationGenerated:true`, so a later periodic/incremental pass EXCLUDES its own output from the
131
131
  * candidate set (no infinite re-merge). It is the COUNTERPART to the {@link guardedMemoryStore} boundary
132
132
  * defense: the public {@link appendStructured} STRIPS a caller-supplied `consolidationGenerated` (an
@@ -146,13 +146,13 @@ export interface MemoryStore {
146
146
  * reference stores it is a note **id** (uuidv7 — lexicographically time-sortable), so "after the cursor"
147
147
  * is a simple string `>` comparison. Returns `undefined` when no pass has run yet (⇒ the WHOLE scope is
148
148
  * pending — the first pass sweeps it all). PAIR with {@link setConsolidationCursor}: a store implements
149
- * BOTH or NEITHER ({@link supportsPeriodicConsolidation}); a store with neither makes {@link consolidateScope}
150
- * a safe NO-OP (it never silently degrades to a full re-consolidation).
149
+ * BOTH or NEITHER ({@link supportsPeriodicConsolidation}); the package no longer ships the pass that read it
150
+ * (the store family that keeps it is on RL-1654-store-family).
151
151
  */
152
152
  getConsolidationCursor?(scope: string): Promise<string | undefined> | string | undefined;
153
153
  /**
154
154
  * design/84 Seam B — persist the periodic/incremental consolidation cursor for `scope` (decision 3). Called
155
- * by {@link consolidateScope} ONLY after a pass succeeds in full, advancing the cursor to the max ordering
155
+ * by a consolidation pass ONLY after it succeeds in full, advancing the cursor to the max ordering
156
156
  * marker the pass observed (seen note ids ∪ added ids). Must be durable (a later pass reads it back). PAIR
157
157
  * with {@link getConsolidationCursor}.
158
158
  */
@@ -183,7 +183,7 @@ export interface StructuredNoteInput {
183
183
  outcomeStats?: unknown;
184
184
  /**
185
185
  * design/84 Seam B (前置 BLOCKER): mark a note as CREATED BY A CONSOLIDATION ADD. Set ONLY by
186
- * {@link import("./runner/memory-consolidation.js").runMemoryConsolidation} when it materializes a merged
186
+ * a consolidation pass (none ships in the package any more) when it materializes a merged
187
187
  * "add" decision — never by the `remember` tool or a normal caller. A store persists it (and surfaces it on
188
188
  * {@link ScoredMemory}/{@link MemoryNoteHeader}) so periodic/incremental consolidation can EXCLUDE these
189
189
  * notes from its candidate set and not re-consolidate its own output forever. It does NOT affect the
@@ -245,7 +245,7 @@ export type PeriodicConsolidationCapableStore = MemoryStore & Required<Pick<Memo
245
245
  /**
246
246
  * True when a store implements the design/84 Seam B cursor PAIR
247
247
  * ({@link MemoryStore.getConsolidationCursor}/{@link MemoryStore.setConsolidationCursor}). Periodic/incremental
248
- * consolidation ({@link import("./consolidate-scope.js").consolidateScope}) GATES on this: a store missing
248
+ * consolidation (a pass the package no longer ships) GATES on this: a store missing
249
249
  * either method makes a periodic pass a safe **NO-OP** (never a silent full re-consolidation of the whole
250
250
  * scope, which would re-merge already-consolidated notes forever). Both-or-neither — a store implementing
251
251
  * only one is treated as unsupported. Independent of {@link supportsConsolidation} (the id-addressable trio),
@@ -437,7 +437,7 @@ export declare function expandLexicalTerms(term: string): string[];
437
437
  * Matching rule: tokenize `text` on word boundaries, then for each whitespace-separated `query` term the
438
438
  * text must match AT LEAST ONE of that term's {@link expandLexicalTerms} variants (OR within a term), and
439
439
  * EVERY query term must match (AND across terms). The ORIGINAL query term keeps its pre-Slice-2b SUBSTRING
440
- * semantics (back-compat, RL-1654-memorystore); the EXPANDED synonym/stem variants are matched on WORD BOUNDARIES (set membership
440
+ * semantics (back-compat, RL-1654-store-family); the EXPANDED synonym/stem variants are matched on WORD BOUNDARIES (set membership
441
441
  * over the text's token set) so a short injected synonym like "key"/"db" cannot substring-match an unrelated
442
442
  * word ("keyboard"/"double"). An empty/whitespace-only query never matches.
443
443
  */
@@ -8,7 +8,7 @@ import { clampPermissionMode, isPermissionMode, PERMISSION_MODES } from "./ask-o
8
8
  import { argvOf, lexShellText } from "../shell/lex.js";
9
9
  import { COMMAND_RULE_TOOL } from "./permission-rule-model.js";
10
10
  import { createSafeNotifier } from "./safe-notify.js";
11
- import { CheckpointError, isCheckpointConfigRefusalCode } from "./checkpoint-store.js";
11
+ import { CheckpointError, isCheckpointConfigRefusalCode } from "./checkpoint-features.js";
12
12
  export const PERMISSION_MODE_FOLD_REASONS = Object.freeze(["operator_deny", "face_absent", "inherited_ceiling"]);
13
13
  export const ACCEPT_EDITS_FILE_COMMANDS = Object.freeze(["mkdir", "touch", "rm", "rmdir", "mv", "cp", "sed"]);
14
14
  const MODE_POLICY_TABLE = {
@@ -4,7 +4,7 @@
4
4
  * registration form types a handler by it. Its keys are the event table's `classic.*` rows that carry a station — the key
5
5
  * set is held to that table.
6
6
  */
7
- import type { PermissionDeniedPayload, PostCompactEvent, PostToolBatchEvent, PostToolBatchResult, PostToolUseEvent, PostToolUseFailureEvent, PostToolUseFailureResult, PostToolUseResult, PreCompactEvent, PreCompactResult, PreToolUseEvent, PreToolUseResult, StopEvent, StopFailureEvent, StopHookResult, SubagentStartEvent, SubagentStartResult, UserPromptSubmitEvent, UserPromptSubmitResult } from "../hooks.js";
7
+ import type { PermissionDeniedPayload, PostCompactEvent, PostToolBatchEvent, PostToolBatchResult, PostToolUseEvent, PostToolUseFailureEvent, PostToolUseFailureResult, PostToolUseResult, PreCompactEvent, PreCompactResult, PreToolUseEvent, PreToolUseResult, SessionEndEvent, SessionStartEvent, StopEvent, StopFailureEvent, StopHookResult, SubagentStartEvent, SubagentStartResult, UserPromptSubmitEvent, UserPromptSubmitResult } from "../hooks.js";
8
8
  import type { MappedOn, ModRegistration } from "./kernel/index.js";
9
9
  import type { EngineDollar } from "./dollar.js";
10
10
  /** The answer of an event whose station reads none (an observation event): a chain handler passes `next(e)`'s on. */
@@ -31,6 +31,14 @@ export type ClassicEventMap = {
31
31
  readonly e: UserPromptSubmitEvent;
32
32
  readonly answer: UserPromptSubmitResult;
33
33
  };
34
+ readonly "classic.SessionStart": {
35
+ readonly e: SessionStartEvent;
36
+ readonly answer: ObservedAnswer;
37
+ };
38
+ readonly "classic.SessionEnd": {
39
+ readonly e: SessionEndEvent;
40
+ readonly answer: ObservedAnswer;
41
+ };
34
42
  readonly "classic.SubagentStart": {
35
43
  readonly e: SubagentStartEvent;
36
44
  readonly answer: SubagentStartResult;
@@ -3,10 +3,11 @@
3
3
  * event over it. Every method's bottom is a seat the engine already has; each method's limits are part of
4
4
  * its contract and are checked here (a refused input is the caller's throw, "(host check)").
5
5
  */
6
- import type { ExecutionEnv } from "../../internal/harness-types.js";
6
+ import type { AgentMessage, ExecutionEnv } from "../../internal/harness-types.js";
7
7
  import type { Context, Message, Usage } from "../../internal/llm.js";
8
8
  import type { CompactOutcome } from "../task-event.js";
9
9
  import type { ModDollarBase, ModMethodBottoms } from "./kernel/index.js";
10
+ import type { ContextOccupancy } from "./lifecycle-stations.js";
10
11
  /** `$.process.run`'s default command timeout (CC). */
11
12
  export declare const PROCESS_RUN_DEFAULT_TIMEOUT_MS = 30000;
12
13
  /** `$.process.run`'s largest command timeout (CC). */
@@ -55,13 +56,30 @@ export interface ModSeatView {
55
56
  cwd(): string;
56
57
  root(): string;
57
58
  model(): string;
59
+ /** The leg's messages as the model last saw them. */
58
60
  messages(): readonly Message[];
61
+ /** A subagent's stored transcript rows, read through the leg's own task list row for it; rejects with the reason when the
62
+ * leg reaches no such row, the row has no session, or the session cannot be read. */
63
+ agentMessages(agentId: string): Promise<readonly AgentMessage[]>;
64
+ /** How many prompts the session's transcript holds from its people (`promptCountOf`, `session-append.ts`). */
65
+ turns(): Promise<number>;
66
+ usage(): SessionUsage;
67
+ version(): SessionVersion;
59
68
  };
60
69
  /** The deployment clock (`RunnerDeps.now`). */
61
70
  now(): number;
62
71
  tools(): readonly string[];
63
72
  agents(): readonly string[];
64
73
  }
74
+ /** `$.session.usage()`: the leg's latest turn-boundary measurement — the context occupancy the boundary's `context_usage`
75
+ * frame carries, absent before the leg's first boundary (a session-level pass measures none). */
76
+ export interface SessionUsage {
77
+ readonly context?: ContextOccupancy;
78
+ }
79
+ /** `$.session.version()`: the engine's package version. */
80
+ export interface SessionVersion {
81
+ readonly version: string;
82
+ }
65
83
  export interface ProcessRunResult {
66
84
  readonly stdout: string;
67
85
  readonly stderr: string;
@@ -91,7 +109,20 @@ export interface EngineDollar extends ModDollarBase {
91
109
  cwd(): Promise<string>;
92
110
  root(): Promise<string>;
93
111
  model(): Promise<string>;
112
+ /** The leg's messages as the model last saw them (the newest {@link SESSION_MESSAGES_MAX}, copies). */
94
113
  messages(): Promise<readonly Message[]>;
114
+ /** `$.session.messages({ agentId })`: a subagent's stored transcript rows (the newest {@link SESSION_MESSAGES_MAX}, copies),
115
+ * read through this leg's own task list row for that agent; rejects with the reason when this leg reaches no such row, the
116
+ * row has no session, or the session cannot be read. */
117
+ messages(args: {
118
+ readonly agentId: string;
119
+ }): Promise<readonly AgentMessage[]>;
120
+ /** `$.session.turns()`: how many prompts the session's transcript holds from its people (a steer is not one). */
121
+ turns(): Promise<number>;
122
+ /** `$.session.usage()`: the leg's latest turn-boundary measurement. */
123
+ usage(): Promise<SessionUsage>;
124
+ /** `$.session.version()`: the engine's package version. */
125
+ version(): Promise<SessionVersion>;
95
126
  /** `$.session.append({ message: { role: "user", content }, agentId? })`: an extension's own note, admitted at the
96
127
  * `session.append` station (`session-append.ts`). */
97
128
  append(args: {
@@ -132,6 +132,15 @@ function detachedMessage(m) {
132
132
  throw refuse("session.messages", "a session message could not be copied; the history is not handed out live");
133
133
  }
134
134
  }
135
+ function sessionMessages(view, args) {
136
+ only(args, "session.messages", ["agentId"]);
137
+ const agentId = args["agentId"];
138
+ if (agentId === undefined)
139
+ return Object.freeze(view.session.messages().slice(-SESSION_MESSAGES_MAX).map(detachedMessage));
140
+ if (typeof agentId !== "string" || agentId === "")
141
+ throw refuse("session.messages", `takes agentId, a non-empty string (got ${typeof agentId === "string" ? "an empty string" : typeof agentId})`);
142
+ return view.session.agentMessages(agentId).then((rows) => Object.freeze(rows.slice(-SESSION_MESSAGES_MAX).map(detachedMessage)));
143
+ }
135
144
  const read = (event, f) => (args) => {
136
145
  only(args, event, []);
137
146
  return f();
@@ -145,7 +154,10 @@ export function engineMethodBottoms(view) {
145
154
  "session.cwd": run(read("session.cwd", () => view.session.cwd())),
146
155
  "session.root": run(read("session.root", () => view.session.root())),
147
156
  "session.model": run(read("session.model", () => view.session.model())),
148
- "session.messages": run(read("session.messages", () => Object.freeze(view.session.messages().slice(-SESSION_MESSAGES_MAX).map(detachedMessage)))),
157
+ "session.messages": run((args) => sessionMessages(view, args)),
158
+ "session.turns": run(read("session.turns", () => view.session.turns())),
159
+ "session.usage": run(read("session.usage", () => view.session.usage())),
160
+ "session.version": run(read("session.version", () => view.session.version())),
149
161
  "clock.now": run(read("clock.now", () => view.now())),
150
162
  "clock.sleep": run((args, ctx) => sleep(args, ctx)),
151
163
  "tool.list": run(read("tool.list", () => Object.freeze([...view.tools()]))),
@@ -33,8 +33,13 @@
33
33
  * 7: `session.receive` (a frame arriving for the model), `session.append` (a row entering the conversation), `session.send` (a
34
34
  * message the leg sends) and `session.compact` (a compaction about to run) have stations; `agent.spawn` has a `call` column,
35
35
  * and so do `session.append`, `session.send` and `session.compact` — a `$` call of each reaches the host's entry.
36
+ * 8: the closed set is the reference's 145 names (`session.identity`, `ui.view`, `prompt.change` named, not raised);
37
+ * `session.start` (a leg opened), `session.measure` (the leg's context occupancy moved), `turn.start` (a model turn began),
38
+ * `prompt.submit` (a person's input entering the leg — rewritable, droppable, refused on a failure), `classic.SessionStart` and
39
+ * `classic.SessionEnd` have stations, the two classic ones raised in the bottoms of `session.start` and `session.end`; the
40
+ * methods `session.turns`, `session.usage` and `session.version` have bottoms, and `session.messages` takes `{ agentId }`.
36
41
  */
37
- export declare const KERNEL_CONTRACT_VERSION = 7;
42
+ export declare const KERNEL_CONTRACT_VERSION = 8;
38
43
  /** The five tiers in run order (CC names). `builtin` and `core` are the engine's own. */
39
44
  export declare const MOD_TIERS: readonly ["prepend", "user", "append", "builtin", "core"];
40
45
  export type ModTier = (typeof MOD_TIERS)[number];
@@ -111,8 +116,8 @@ export interface ModEventRow {
111
116
  readonly station?: ModStation;
112
117
  }
113
118
  /**
114
- * Every event the kernel knows: the reference's closed set of 142 names (CC 2.1.296 `J3e` (cli296.js:238573) — its 33 `classic.*` names,
115
- * its 46 engine events and its 63 `$` methods, in its own order). The shell's names (`ui.*`, `command.*`,
119
+ * Every event the kernel knows: the reference's closed set of 145 names (CC 2.1.309 `_De` (cli309.js:253322) — its 33 `classic.*` names,
120
+ * its 47 engine events and its 65 `$` methods, in its own order). The shell's names (`ui.*`, `command.*`,
116
121
  * `config.*`, `audio.*`, the prompt-box events and `prompt.read`) carry `side: "surface"`: one table serves both
117
122
  * buses, and the shell's stations are its rows here, raised by the shell where their chain bottoms are. A row with a
118
123
  * station is raised on its side in this version; a name with none is named, not raised, and a registration that
@@ -169,6 +174,7 @@ export declare const MOD_EVENT_TABLE: Readonly<{
169
174
  "prompt.fill": ModEventRow;
170
175
  "prompt.suggest": ModEventRow;
171
176
  "prompt.edit": ModEventRow;
177
+ "prompt.change": ModEventRow;
172
178
  "prompt.autocomplete": ModEventRow;
173
179
  "prompt.section": ModEventRow;
174
180
  "prompt.context": ModEventRow;
@@ -218,6 +224,7 @@ export declare const MOD_EVENT_TABLE: Readonly<{
218
224
  "session.surface": ModEventRow;
219
225
  "session.surfaces": ModEventRow;
220
226
  "session.authorize": ModEventRow;
227
+ "session.identity": ModEventRow;
221
228
  "session.usage": ModEventRow;
222
229
  "session.version": ModEventRow;
223
230
  "turn.abort": ModEventRow;
@@ -240,6 +247,7 @@ export declare const MOD_EVENT_TABLE: Readonly<{
240
247
  "ui.panes": ModEventRow;
241
248
  "ui.selection": ModEventRow;
242
249
  "ui.copy": ModEventRow;
250
+ "ui.view": ModEventRow;
243
251
  "ui.notify": ModEventRow;
244
252
  "ui.blit": ModEventRow;
245
253
  "fs.read": ModEventRow;
@@ -1,4 +1,4 @@
1
- export const KERNEL_CONTRACT_VERSION = 7;
1
+ export const KERNEL_CONTRACT_VERSION = 8;
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"]);
@@ -55,8 +55,8 @@ export const MOD_EVENT_TABLE = Object.freeze({
55
55
  "classic.Notification": engine(),
56
56
  "classic.UserPromptSubmit": engine(station("refuse", "immediate", ["source", "inputId", "actor", "prompt"])),
57
57
  "classic.UserPromptExpansion": engine(),
58
- "classic.SessionStart": engine(),
59
- "classic.SessionEnd": engine(),
58
+ "classic.SessionStart": engine(station("skip", "grace")),
59
+ "classic.SessionEnd": engine(station("skip", "grace")),
60
60
  "classic.Stop": engine(station("skip", "immediate")),
61
61
  "classic.StopFailure": engine(station("skip", "grace")),
62
62
  "classic.SubagentStart": engine(station("skip", "immediate", ["agentId", "agentType"])),
@@ -94,10 +94,11 @@ 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(),
97
+ "prompt.submit": engine(station("refuse", "immediate", ["source", "inputId", "actor"])),
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 })),
101
+ "prompt.change": surface(),
101
102
  "prompt.autocomplete": surface(),
102
103
  "prompt.section": engine(station("skip", "grace", ["name", "key", "mountedTools"])),
103
104
  "prompt.context": engine(),
@@ -113,17 +114,17 @@ export const MOD_EVENT_TABLE = Object.freeze({
113
114
  "telemetry.mark": engine(),
114
115
  "skill.prompt": engine(),
115
116
  "attribution.text": engine(),
116
- "session.start": engine(),
117
+ "session.start": engine(station("skip", "grace", ["cwd", "sessionId", "agentId"])),
117
118
  "session.receive": engine(station("refuse", "immediate", ["origin", "event", "agentId"])),
118
119
  "session.append": engine(station("skip", "grace", ["door", "origin", "agentId"], { call: true })),
119
120
  "session.send": engine(station("refuse_until_run", "immediate", ["origin", "agentId", "to", "text"], { call: true })),
120
121
  "session.compact": engine(station("refuse_until_run", "immediate", ["trigger", "agentId", "instructions"], { call: true })),
121
122
  "session.attach": engine(),
122
123
  "session.detach": engine(),
123
- "session.measure": engine(),
124
+ "session.measure": engine(station("skip", "grace", ["context", "changed", "agentId"])),
124
125
  "session.end": engine(station("skip", "grace", ["reason", "sessionId", "agentId"])),
125
126
  "plugin.register": Object.freeze({ side: "both", station: station("refuse", "immediate", ["name", "seat", "tier", "uses"]) }),
126
- "turn.start": engine(),
127
+ "turn.start": engine(station("skip", "grace", ["turn", "agentId"])),
127
128
  "turn.step": engine(),
128
129
  "turn.complete": engine(station("skip", "grace", ["answer", "agentId", "turn"])),
129
130
  "engine.create": engine(),
@@ -137,15 +138,16 @@ export const MOD_EVENT_TABLE = Object.freeze({
137
138
  "session.cwd": engine(method(true)),
138
139
  "session.root": engine(method(true)),
139
140
  "session.model": engine(method(true)),
140
- "session.turns": engine(),
141
+ "session.turns": engine(method(true)),
141
142
  "session.id": engine(method(true)),
142
143
  "session.messages": engine(method(true)),
143
144
  "session.repo": engine(),
144
145
  "session.surface": engine(),
145
146
  "session.surfaces": engine(),
146
147
  "session.authorize": engine(),
147
- "session.usage": engine(),
148
- "session.version": engine(),
148
+ "session.identity": engine(),
149
+ "session.usage": engine(method(true)),
150
+ "session.version": engine(method(true)),
149
151
  "turn.abort": engine(),
150
152
  "prompt.read": surface(method(true)),
151
153
  "flag.value": engine(),
@@ -166,6 +168,7 @@ export const MOD_EVENT_TABLE = Object.freeze({
166
168
  "ui.panes": surface(),
167
169
  "ui.selection": surface(method(true)),
168
170
  "ui.copy": surface(method(true)),
171
+ "ui.view": surface(),
169
172
  "ui.notify": surface(),
170
173
  "ui.blit": surface(),
171
174
  "fs.read": engine(),
@@ -1,13 +1,45 @@
1
1
  /**
2
- * A leg's two lifecycle stations over its bus, both observations (an answer changes nothing, a failure skips the handler).
2
+ * A leg's lifecycle stations over its bus, all observations (an answer changes nothing, a failure skips the handler). Each
3
+ * entry reads first, synchronously, whether its event (or the classic event raised in its bottom) is heard — none ⇒ nothing
4
+ * is raised and nothing is awaited.
5
+ * `session.start`: the leg opened (prepared, before its first model request); `e = { cwd, sessionId, agentId? }`; its bottom
6
+ * raises `classic.SessionStart` with the same `e` and comes up as `{ cwd }`.
7
+ * `turn.start`: a model turn began, before its first model request; `e = { turn, agentId? }` (`turn` = 1 for the leg's first);
8
+ * the bottom comes up as `{ turn }`.
3
9
  * `turn.complete`: the turn's end records it ({@link noteCompletedTurn}); the next await point raises it once
4
10
  * ({@link raiseCompletedTurn}) — the turn boundary after it, or the leg's settle for a turn whose boundary never ran.
5
11
  * `e = { answer, reason, turn, isAborted, agentId?, usage? }`; the bottom comes up as `{ text: answer, usage? }`.
6
- * `session.end`: a leg's terminal settled; `e = { reason, sessionId, agentId? }`, `reason` the terminal status word.
12
+ * `session.measure`: a turn boundary measured the leg's context occupancy and it moved since the last measurement
13
+ * ({@link measureSession} — the one write `$.session.usage` reads); `e = { context, changed, agentId? }`; the bottom comes up as
14
+ * `{ changed }`.
15
+ * `session.end`: a leg's terminal settled; `e = { reason, sessionId, agentId? }`, `reason` the terminal status word; its bottom
16
+ * raises `classic.SessionEnd` with the same `e` and comes up as `{ sessionId }`.
7
17
  */
8
18
  import type { AssistantMessage } from "../../internal/llm.js";
19
+ import type { maybeCompact } from "../auto-compaction.js";
9
20
  import type { HookInvocationIdentity } from "../hooks.js";
10
21
  import { type LegModBus } from "./stations.js";
22
+ /** Raise `session.start` as the leg opens; `undefined` (nothing raised, nothing to await) when neither it nor
23
+ * `classic.SessionStart` is heard. */
24
+ export declare function raiseSessionStart(bus: LegModBus, identity: HookInvocationIdentity | undefined, start: {
25
+ readonly cwd: string;
26
+ readonly sessionId: string;
27
+ }, signal: AbortSignal | undefined): Promise<void> | undefined;
28
+ /** Raise `turn.start` for the turn beginning (`turn` = its number); `undefined` when no handler hangs on it. */
29
+ export declare function raiseStartedTurn(bus: LegModBus, identity: HookInvocationIdentity | undefined, turn: number, signal: AbortSignal | undefined): Promise<void> | undefined;
30
+ /** A leg's context occupancy as a turn boundary measured it: the compaction pass's own `contextUsage` — the three numbers the
31
+ * boundary's `context_usage` frame carries. */
32
+ export type ContextOccupancy = Readonly<NonNullable<Awaited<ReturnType<typeof maybeCompact>>["contextUsage"]>>;
33
+ /** What `session.measure`'s `changed` names: the units that moved (the leg measures one). */
34
+ export declare const SESSION_MEASURE_UNITS: readonly ["context"];
35
+ export type SessionMeasureUnit = (typeof SESSION_MEASURE_UNITS)[number];
36
+ /** Where a leg keeps its latest measurement: written once per boundary by {@link measureSession}, read by `$.session.usage`. */
37
+ export interface SessionMeasureSeat {
38
+ context?: ContextOccupancy;
39
+ }
40
+ /** Record a boundary's measurement on the seat (always), then raise `session.measure` when the occupancy moved since the
41
+ * last one (the first measurement moved from none); `undefined` when nothing is raised. */
42
+ export declare function measureSession(bus: LegModBus, seat: SessionMeasureSeat, measured: ContextOccupancy, identity: HookInvocationIdentity | undefined, signal: AbortSignal | undefined): Promise<void> | undefined;
11
43
  /** Why a model turn ended. */
12
44
  export type CompletedTurnReason = "answer" | "aborted" | "error";
13
45
  /** A model turn that ended, as `turn.complete` names it (raised once, then gone). */
@@ -34,8 +66,8 @@ export declare function noteCompletedTurn(bus: LegModBus, seat: CompletedTurnSea
34
66
  /** Raise `turn.complete` for each turn the seat holds, in order, each once (the seat is emptied first). An engine-side
35
67
  * rejection is swallowed: an observation never changes what it observes. */
36
68
  export declare function raiseCompletedTurn(bus: LegModBus, seat: CompletedTurnSeat, identity: HookInvocationIdentity | undefined, signal: AbortSignal | undefined): Promise<void>;
37
- /** Raise `session.end` as the leg's terminal settles (nothing when no handler hangs on it). */
69
+ /** Raise `session.end` as the leg's terminal settles; `undefined` when neither it nor `classic.SessionEnd` is heard. */
38
70
  export declare function raiseSessionEnd(bus: LegModBus, identity: HookInvocationIdentity | undefined, end: {
39
71
  readonly reason: string;
40
72
  readonly sessionId: string;
41
- }): Promise<void>;
73
+ }): Promise<void> | undefined;
@@ -1,4 +1,40 @@
1
- import { classicEventBase } from "./stations.js";
1
+ import { classicEventBase, observeClassic } from "./stations.js";
2
+ const hearsEither = (bus, typed, classic) => bus.hasHandlers(typed) || bus.hasHandlers(classic);
3
+ export function raiseSessionStart(bus, identity, start, signal) {
4
+ if (!hearsEither(bus, "session.start", "classic.SessionStart"))
5
+ return undefined;
6
+ const e = { ...classicEventBase(identity), cwd: start.cwd, sessionId: start.sessionId };
7
+ const core = Object.freeze({ cwd: start.cwd });
8
+ return observeLifecycle(bus, "session.start", e, async () => {
9
+ await observeClassic(bus, "classic.SessionStart", e, signal);
10
+ return core;
11
+ }, signal);
12
+ }
13
+ export function raiseStartedTurn(bus, identity, turn, signal) {
14
+ if (!bus.hasHandlers("turn.start"))
15
+ return undefined;
16
+ const core = Object.freeze({ turn });
17
+ return observeLifecycle(bus, "turn.start", { ...classicEventBase(identity), turn }, () => core, signal);
18
+ }
19
+ export const SESSION_MEASURE_UNITS = Object.freeze(["context"]);
20
+ export function measureSession(bus, seat, measured, identity, signal) {
21
+ const before = seat.context;
22
+ const context = Object.freeze({ usedTokens: measured.usedTokens, windowTokens: measured.windowTokens, compactAtTokens: measured.compactAtTokens });
23
+ seat.context = context;
24
+ const moved = before === undefined || before.usedTokens !== context.usedTokens || before.windowTokens !== context.windowTokens || before.compactAtTokens !== context.compactAtTokens;
25
+ if (!moved || !bus.hasHandlers("session.measure"))
26
+ return undefined;
27
+ const changed = Object.freeze(["context"]);
28
+ const core = Object.freeze({ changed });
29
+ return observeLifecycle(bus, "session.measure", { ...classicEventBase(identity), context, changed }, () => core, signal);
30
+ }
31
+ async function observeLifecycle(bus, event, e, bottom, signal) {
32
+ try {
33
+ await bus.dispatch(event, e, { bottom, ...(signal !== undefined ? { signal } : {}) });
34
+ }
35
+ catch {
36
+ }
37
+ }
2
38
  const answerOf = (message) => (message?.content ?? []).flatMap((c) => (c.type === "text" ? [c.text] : [])).join("");
3
39
  export function noteCompletedTurn(bus, seat, message, turn, aborted, usage) {
4
40
  if (!bus.hasHandlers("turn.complete"))
@@ -22,14 +58,13 @@ export async function raiseCompletedTurn(bus, seat, identity, signal) {
22
58
  }
23
59
  }
24
60
  }
25
- export async function raiseSessionEnd(bus, identity, end) {
26
- if (!bus.hasHandlers("session.end"))
27
- return;
61
+ export function raiseSessionEnd(bus, identity, end) {
62
+ if (!hearsEither(bus, "session.end", "classic.SessionEnd"))
63
+ return undefined;
28
64
  const e = { ...classicEventBase(identity), reason: end.reason, sessionId: end.sessionId };
29
65
  const core = Object.freeze({ sessionId: end.sessionId });
30
- try {
31
- await bus.dispatch("session.end", e, { bottom: () => core });
32
- }
33
- catch {
34
- }
66
+ return observeLifecycle(bus, "session.end", e, async () => {
67
+ await observeClassic(bus, "classic.SessionEnd", e, undefined);
68
+ return core;
69
+ }, undefined);
35
70
  }
@@ -36,7 +36,7 @@
36
36
  * conversation the leg goes on with — stored by the port (`AgentHarness.appendMessage`), or carried by a durable park's row
37
37
  * (`heldRows`); once the park is taken, or may have been, the call throws `$.session.append: refused: …`.
38
38
  */
39
- import type { AgentMessage, RowAdmission, RowRaising } from "../../internal/harness-types.js";
39
+ import type { AgentMessage, RowAdmission, RowRaising, SessionTreeEntry } from "../../internal/harness-types.js";
40
40
  import type { AgentHarness } from "../../internal/harness.js";
41
41
  import { type FrameSettlement } from "../frame-settlement.js";
42
42
  import type { HookInvocationIdentity } from "../hooks.js";
@@ -67,6 +67,9 @@ export type SessionAppendOrigin = {
67
67
  * read is a `note` (a user-lane note, or a row of its own kind), a `delivery` (a frame with its delivery key) or an
68
68
  * `attachment`; the model's turn is a `response`, a tool's answer a `tool-result`. */
69
69
  export declare function doorOf(row: AgentMessage): SessionAppendDoor;
70
+ /** `$.session.turns()`: how many prompts a branch holds from its people — its message rows whose door ({@link doorOf}) is
71
+ * `prompt`. A steer is the engine's note on the person's behalf (`provenance: "engine-note"`), so it is not one. */
72
+ export declare function promptCountOf(branch: ReadonlyArray<SessionTreeEntry>): number;
70
73
  /** A row's maker, from its typed facts: the model, the tool that answered, the host (a prompt, an attachment the host
71
74
  * declared), else the engine. */
72
75
  export declare function originOf(row: AgentMessage): SessionAppendOrigin;
@@ -22,6 +22,13 @@ export function doorOf(row) {
22
22
  return "note";
23
23
  }
24
24
  }
25
+ export function promptCountOf(branch) {
26
+ let n = 0;
27
+ for (const entry of branch)
28
+ if (entry.type === "message" && doorOf(entry.message) === "prompt")
29
+ n += 1;
30
+ return n;
31
+ }
25
32
  const HOST = Object.freeze({ kind: "host" });
26
33
  const ENGINE = Object.freeze({ kind: "engine" });
27
34
  export function originOf(row) {
@@ -3,7 +3,7 @@ import { describeThrown } from "../tool-policy.js";
3
3
  import { extensionWords } from "../untrusted-egress.js";
4
4
  import { ENGINE_ORIGIN } from "./kernel/index.js";
5
5
  import { isPlainRecord } from "./kernel/receive.js";
6
- import { classicEventBase, failedHandlerClause, seatHears } from "./stations.js";
6
+ import { classicEventBase, failedHandlerClause, seatHears, textChanges } from "./stations.js";
7
7
  export const SESSION_RECEIVE_ORIGIN_KINDS = Object.freeze(["task", "agent", "peer", "host", "engine"]);
8
8
  const ENGINE = Object.freeze({ kind: "engine" });
9
9
  export function receiveOriginOf(p) {
@@ -47,18 +47,24 @@ export function createReceiveSeat() {
47
47
  const made = payload.received === undefined ? payload : (({ received: _r, ...rest }) => rest)(payload);
48
48
  const text = renderTaskNotificationXml(made);
49
49
  const e = { ...classicEventBase(binding.identity), origin: receiveOriginOf(made), event: eventOf(made), text };
50
- const handOns = [];
50
+ const changes = textChanges(text);
51
51
  const checkHandOn = (handed, by) => {
52
52
  const t = handed["text"];
53
53
  if (typeof t !== "string" || t.trim() === "")
54
54
  return "next() handed on a text that is not a non-blank string";
55
- handOns.push({ by: by.plugin, text: t });
55
+ changes.handedOn(by.plugin, t);
56
56
  return undefined;
57
57
  };
58
58
  const bottom = (handed) => Object.freeze({ text: handed["text"] });
59
- const checkAnswer = (a) => {
59
+ const checkAnswer = (a, handed, by, below) => {
60
60
  const read = readAnswer(a);
61
- return "why" in read ? read.why : undefined;
61
+ if ("why" in read)
62
+ return read.why;
63
+ if ("text" in read) {
64
+ const up = below.length > 0 ? readAnswer(below[below.length - 1]) : undefined;
65
+ changes.answered(by.plugin, read.text, handed["text"], up !== undefined && "text" in up ? up.text : undefined);
66
+ }
67
+ return undefined;
62
68
  };
63
69
  let outcome;
64
70
  try {
@@ -79,16 +85,7 @@ export function createReceiveSeat() {
79
85
  return consumed(binding, made, by, `extension "${extensionWords(by, 80)}" answered in a form session.receive does not take (${read.why}); the frame was not handed over (fail-closed)`);
80
86
  if (read.text === text)
81
87
  return Object.freeze({ kind: "arrived", payload: made });
82
- const rewrittenBy = [];
83
- let before = text;
84
- for (const h of handOns) {
85
- if (h.text !== before && !rewrittenBy.includes(h.by))
86
- rewrittenBy.push(h.by);
87
- before = h.text;
88
- }
89
- if (read.text !== before && !rewrittenBy.includes(by))
90
- rewrittenBy.push(by);
91
- return Object.freeze({ kind: "arrived", payload: { ...made, received: Object.freeze({ text: read.text, rewrittenBy: Object.freeze(rewrittenBy) }) } });
88
+ return Object.freeze({ kind: "arrived", payload: { ...made, received: Object.freeze({ text: read.text, rewrittenBy: changes.rewrittenBy() }) } });
92
89
  };
93
90
  return {
94
91
  listens: () => seatHears(bound, "session.receive"),