maka-agent 0.2.0-dev.26.20260909 → 0.2.0-dev.28.20260911

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 (125) hide show
  1. package/LICENSE +106 -0
  2. package/dist/cli-core.js +28 -0
  3. package/dist/runtime-host-cli.js +43 -3
  4. package/dist/runtime-host-handoff-surface.js +10 -8
  5. package/dist/runtime-host-lifecycle-transaction.js +28 -3
  6. package/dist/runtime-host-local-source-retirement.js +1 -1
  7. package/dist/runtime-host-run-command.js +15 -7
  8. package/dist/runtime-host-setup-command.js +29 -6
  9. package/dist/runtime-host-update-command.js +49 -5
  10. package/dist/session-export-command.js +72 -0
  11. package/dist/session-import-command.js +69 -0
  12. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  13. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  14. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  15. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  16. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  17. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +9 -4
  18. package/node_modules/@maka/core/dist/diagnostic-log.js +18 -7
  19. package/node_modules/@maka/core/dist/text-sanitize.js +8 -2
  20. package/node_modules/@maka/core/dist/usage-stats/types.js +2 -0
  21. package/node_modules/@maka/core/dist/workhub-routing.js +126 -0
  22. package/node_modules/@maka/core/package.json +2 -1
  23. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +15 -11
  24. package/node_modules/@maka/runtime/dist/archive-read-tool.js +3 -1
  25. package/node_modules/@maka/runtime/dist/bots/bot-test.js +2 -1
  26. package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +24 -20
  27. package/node_modules/@maka/runtime/dist/bots/slack-bridge.js +5 -3
  28. package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +87 -29
  29. package/node_modules/@maka/runtime/dist/bots/wecom-bridge.js +40 -36
  30. package/node_modules/@maka/runtime/dist/builtin-tools.js +21 -2
  31. package/node_modules/@maka/runtime/dist/computer-use-tools.js +4 -1
  32. package/node_modules/@maka/runtime/dist/deep-research-tools.js +11 -5
  33. package/node_modules/@maka/runtime/dist/edit-replace.js +2 -2
  34. package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +5 -6
  35. package/node_modules/@maka/runtime/dist/memory-extraction-evidence.js +7 -1
  36. package/node_modules/@maka/runtime/dist/memory-extraction.js +12 -7
  37. package/node_modules/@maka/runtime/dist/openai-responses-websocket.js +2 -5
  38. package/node_modules/@maka/runtime/dist/plugin-agent-service.js +131 -0
  39. package/node_modules/@maka/runtime/dist/plugin-approval-service.js +33 -0
  40. package/node_modules/@maka/runtime/dist/plugin-attachment-service.js +53 -0
  41. package/node_modules/@maka/runtime/dist/plugin-command-service.js +100 -0
  42. package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +11 -2
  43. package/node_modules/@maka/runtime/dist/plugin-data-services.js +332 -0
  44. package/node_modules/@maka/runtime/dist/plugin-fs-service.js +62 -0
  45. package/node_modules/@maka/runtime/dist/plugin-goal-service.js +61 -0
  46. package/node_modules/@maka/runtime/dist/plugin-invocation-signal.js +24 -0
  47. package/node_modules/@maka/runtime/dist/plugin-llm-service.js +85 -0
  48. package/node_modules/@maka/runtime/dist/plugin-lsp-service.js +94 -0
  49. package/node_modules/@maka/runtime/dist/plugin-scope-registry.js +91 -0
  50. package/node_modules/@maka/runtime/dist/plugin-session-query-service.js +71 -0
  51. package/node_modules/@maka/runtime/dist/plugin-shell-env-service.js +87 -0
  52. package/node_modules/@maka/runtime/dist/plugin-shell-service.js +74 -0
  53. package/node_modules/@maka/runtime/dist/plugin-skill-service.js +93 -0
  54. package/node_modules/@maka/runtime/dist/plugin-system-prompt-service.js +346 -0
  55. package/node_modules/@maka/runtime/dist/plugin-tool-service.js +18 -52
  56. package/node_modules/@maka/runtime/dist/plugin-user-question-service.js +43 -0
  57. package/node_modules/@maka/runtime/dist/plugin-web-service.js +69 -0
  58. package/node_modules/@maka/runtime/dist/request-customization-fetch.js +14 -7
  59. package/node_modules/@maka/runtime/dist/session-export.js +178 -0
  60. package/node_modules/@maka/runtime/dist/session-import.js +100 -0
  61. package/node_modules/@maka/runtime/dist/session-manager.js +6 -1
  62. package/node_modules/@maka/runtime/dist/shell-run-manager.js +9 -6
  63. package/node_modules/@maka/runtime/dist/shell-run-tool-result.js +13 -6
  64. package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +43 -10
  65. package/node_modules/@maka/runtime/dist/stream-graph-handoff.js +6 -1
  66. package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +1 -4
  67. package/node_modules/@maka/runtime/dist/system-prompt/workspace-instructions.js +11 -6
  68. package/node_modules/@maka/runtime/dist/tavily-search.js +8 -2
  69. package/node_modules/@maka/runtime/dist/text-line-window.js +49 -0
  70. package/node_modules/@maka/runtime/dist/tool-output.js +35 -12
  71. package/node_modules/@maka/runtime/dist/unified-diff.js +40 -10
  72. package/node_modules/@maka/runtime/dist/web-fetch-tool.js +4 -2
  73. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +82 -33
  74. package/node_modules/@maka/runtime/dist/workspace-executor.js +2 -6
  75. package/node_modules/@maka/runtime/package.json +20 -1
  76. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +73 -24
  77. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +46 -12
  78. package/node_modules/@maka/runtime-host/dist/operator/setup-frame.js +31 -21
  79. package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +7 -4
  80. package/node_modules/@maka/runtime-host/dist/protocol/artifact.js +2 -2
  81. package/node_modules/@maka/runtime-host/dist/protocol/index.js +10 -1
  82. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +30 -5
  83. package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +3 -2
  84. package/node_modules/@maka/runtime-host/dist/protocol/skill-catalog.js +2 -1
  85. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +25 -23
  86. package/node_modules/@maka/runtime-host/dist/server/artifact-coordinator.js +2 -0
  87. package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +62 -4
  88. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +481 -11
  89. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +74 -0
  90. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +6 -1
  91. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +2 -2
  92. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +30 -0
  93. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +114 -20
  94. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +49 -12
  95. package/node_modules/@maka/runtime-host/dist/server/plugin-data-runtime.js +234 -0
  96. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
  97. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +12 -0
  98. package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +17 -8
  99. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +189 -92
  100. package/node_modules/@maka/runtime-host/dist/server/runtime-resource-projection.js +3 -9
  101. package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +20 -21
  102. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +24 -2
  103. package/node_modules/@maka/runtime-host/dist/server/skill-catalog-coordinator.js +18 -2
  104. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +44 -35
  105. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +92 -10
  106. package/node_modules/@maka/runtime-host/dist/transport/framed-byte-stream-transport.js +4 -1
  107. package/node_modules/@maka/runtime-host/dist/transport/local-ipc-framing.js +4 -2
  108. package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +9 -8
  109. package/node_modules/@maka/runtime-host/dist/transport/resumable-peer-stream.js +14 -9
  110. package/node_modules/@maka/storage/dist/agent-run-store.js +54 -10
  111. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +32 -10
  112. package/node_modules/@maka/storage/dist/context-value-mutation-gate.js +59 -0
  113. package/node_modules/@maka/storage/dist/execution-stores.js +1 -1
  114. package/node_modules/@maka/storage/dist/session-bundle-policy.js +909 -34
  115. package/node_modules/@maka/storage/dist/session-message-projection.js +8 -4
  116. package/node_modules/@maka/storage/dist/session-store.js +2 -2
  117. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +18 -4
  118. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +12 -5
  119. package/node_modules/@maka/storage/dist/stable-storage.js +2 -1
  120. package/node_modules/@maka/storage/package.json +2 -0
  121. package/node_modules/@modelcontextprotocol/client/dist/src-D_zzAWoS.mjs +22 -5
  122. package/node_modules/@modelcontextprotocol/client/dist/src-NAgB4Mp8.cjs +22 -5
  123. package/node_modules/zod/v4/core/memoizer.cjs +12 -16
  124. package/node_modules/zod/v4/core/memoizer.js +12 -16
  125. package/package.json +1 -1
@@ -0,0 +1,234 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'node:crypto';
20
+ import { chmod, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
21
+ import { dirname, join } from 'node:path';
22
+ const NAMESPACE_QUOTA_BYTES = 10 * 1024 * 1024;
23
+ /** Durable per-extension data authority. JSON writes are atomic; secrets are AES-GCM sealed at rest. */
24
+ export class HostPluginDataRuntime {
25
+ #root;
26
+ #tails = new Map();
27
+ #listeners = new Map();
28
+ #key;
29
+ constructor(controlDirectory) {
30
+ this.#root = join(controlDirectory, 'plugin-data');
31
+ }
32
+ async read(namespace, domain, key) {
33
+ return await this.#withNamespace(namespace, async () => {
34
+ const item = (await this.#readData(namespace, domain)).values[key];
35
+ return Object.freeze(item
36
+ ? { revision: item.revision, value: clone(item.value) }
37
+ : { revision: 0, value: undefined });
38
+ });
39
+ }
40
+ async list(namespace, domain, prefix = '') {
41
+ return await this.#withNamespace(namespace, async () => Object.freeze(Object.fromEntries(Object.entries((await this.#readData(namespace, domain)).values)
42
+ .filter(([key, item]) => key.startsWith(prefix) && item.value !== undefined)
43
+ .sort(([left], [right]) => left.localeCompare(right))
44
+ .map(([key, item]) => [
45
+ key,
46
+ Object.freeze({ revision: item.revision, value: clone(item.value) }),
47
+ ]))));
48
+ }
49
+ async mutate(namespace, domain, mutations) {
50
+ return await this.#withNamespace(namespace, async () => {
51
+ const document = await this.#readData(namespace, domain);
52
+ const changed = new Set();
53
+ for (const mutation of mutations) {
54
+ const current = document.values[mutation.key];
55
+ const revision = current?.revision ?? 0;
56
+ if (mutation.expectedRevision !== undefined && mutation.expectedRevision !== revision)
57
+ throw new Error(`Plugin data revision conflict for ${mutation.key}: expected ${mutation.expectedRevision}, current ${revision}`);
58
+ const nextRevision = revision + 1;
59
+ if (mutation.value === undefined)
60
+ document.values[mutation.key] = { revision: nextRevision };
61
+ else
62
+ document.values[mutation.key] = { revision: nextRevision, value: clone(mutation.value) };
63
+ document.revision += 1;
64
+ changed.add(mutation.key);
65
+ }
66
+ const encoded = `${JSON.stringify(document)}\n`;
67
+ if (Buffer.byteLength(encoded, 'utf8') > NAMESPACE_QUOTA_BYTES)
68
+ throw new Error('Plugin data namespace exceeds 10 MiB quota');
69
+ await atomicWrite(this.#dataPath(namespace, domain), encoded, 0o600);
70
+ const result = Object.freeze(Object.fromEntries([...changed].map((key) => {
71
+ const item = document.values[key];
72
+ return [key, Object.freeze({ revision: item.revision, value: clone(item.value) })];
73
+ })));
74
+ queueMicrotask(() => {
75
+ for (const listener of this.#listeners.get(this.#listenerKey(namespace, domain)) ?? [])
76
+ listener(Object.freeze([...changed].sort()));
77
+ });
78
+ return result;
79
+ });
80
+ }
81
+ subscribe(namespace, domain, listener) {
82
+ const key = this.#listenerKey(namespace, domain);
83
+ let listeners = this.#listeners.get(key);
84
+ if (!listeners) {
85
+ listeners = new Set();
86
+ this.#listeners.set(key, listeners);
87
+ }
88
+ listeners.add(listener);
89
+ return () => {
90
+ listeners.delete(listener);
91
+ if (listeners.size === 0)
92
+ this.#listeners.delete(key);
93
+ };
94
+ }
95
+ async hasCredential(namespace, slot) {
96
+ return await this.#withNamespace(namespace, async () => Boolean((await this.#readCredentials(namespace)).values[slot]));
97
+ }
98
+ async useCredential(namespace, slot, use) {
99
+ const secret = await this.#withNamespace(namespace, async () => {
100
+ const record = (await this.#readCredentials(namespace)).values[slot];
101
+ if (!record)
102
+ throw new Error(`Plugin credential is unavailable: ${slot}`);
103
+ const key = await this.#encryptionKey();
104
+ const decipher = createDecipheriv('aes-256-gcm', key, Buffer.from(record.iv, 'base64'));
105
+ decipher.setAuthTag(Buffer.from(record.tag, 'base64'));
106
+ return Buffer.concat([
107
+ decipher.update(Buffer.from(record.ciphertext, 'base64')),
108
+ decipher.final(),
109
+ ]).toString('utf8');
110
+ });
111
+ return await use(secret);
112
+ }
113
+ async commitCredential(namespace, slot, secret, metadata) {
114
+ await this.#withNamespace(namespace, async () => {
115
+ const document = await this.#readCredentials(namespace);
116
+ const key = await this.#encryptionKey();
117
+ const iv = randomBytes(12);
118
+ const cipher = createCipheriv('aes-256-gcm', key, iv);
119
+ const ciphertext = Buffer.concat([cipher.update(secret, 'utf8'), cipher.final()]);
120
+ document.values[slot] = {
121
+ ciphertext: ciphertext.toString('base64'),
122
+ iv: iv.toString('base64'),
123
+ tag: cipher.getAuthTag().toString('base64'),
124
+ ...(metadata ? { metadata: Object.freeze({ ...metadata }) } : {}),
125
+ };
126
+ document.revision += 1;
127
+ await atomicWrite(this.#credentialPath(namespace), `${JSON.stringify(document)}\n`, 0o600);
128
+ });
129
+ }
130
+ async removeCredential(namespace, slot) {
131
+ await this.#withNamespace(namespace, async () => {
132
+ const document = await this.#readCredentials(namespace);
133
+ if (!document.values[slot])
134
+ return;
135
+ delete document.values[slot];
136
+ document.revision += 1;
137
+ await atomicWrite(this.#credentialPath(namespace), `${JSON.stringify(document)}\n`, 0o600);
138
+ });
139
+ }
140
+ async #readData(namespace, domain) {
141
+ return await readJson(this.#dataPath(namespace, domain), () => ({
142
+ schemaVersion: 1,
143
+ revision: 0,
144
+ values: Object.create(null),
145
+ }));
146
+ }
147
+ async #readCredentials(namespace) {
148
+ return await readJson(this.#credentialPath(namespace), () => ({
149
+ schemaVersion: 1,
150
+ revision: 0,
151
+ values: Object.create(null),
152
+ }));
153
+ }
154
+ #dataPath(namespace, domain) {
155
+ return join(this.#root, digest(namespace), `${domain}.json`);
156
+ }
157
+ #credentialPath(namespace) {
158
+ return join(this.#root, digest(namespace), 'credentials.json');
159
+ }
160
+ #listenerKey(namespace, domain) {
161
+ return `${digest(namespace)}:${domain}`;
162
+ }
163
+ async #encryptionKey() {
164
+ this.#key ??= (async () => {
165
+ const path = join(this.#root, '.credential-key');
166
+ await mkdir(this.#root, { recursive: true, mode: 0o700 });
167
+ try {
168
+ const value = await readFile(path);
169
+ if (value.length !== 32)
170
+ throw new Error('Plugin credential key has invalid length');
171
+ return value;
172
+ }
173
+ catch (error) {
174
+ if (error.code !== 'ENOENT')
175
+ throw error;
176
+ const value = randomBytes(32);
177
+ await writeFile(path, value, { mode: 0o600, flag: 'wx' }).catch(async (writeError) => {
178
+ if (writeError.code !== 'EEXIST')
179
+ throw writeError;
180
+ });
181
+ await chmod(path, 0o600);
182
+ return await readFile(path);
183
+ }
184
+ })();
185
+ return await this.#key;
186
+ }
187
+ async #withNamespace(namespace, operation) {
188
+ validateNamespace(namespace);
189
+ const key = digest(namespace);
190
+ const previous = this.#tails.get(key) ?? Promise.resolve();
191
+ let release;
192
+ const gate = new Promise((resolve) => {
193
+ release = resolve;
194
+ });
195
+ const tail = previous.then(() => gate);
196
+ this.#tails.set(key, tail);
197
+ await previous;
198
+ try {
199
+ return await operation();
200
+ }
201
+ finally {
202
+ release();
203
+ if (this.#tails.get(key) === tail)
204
+ this.#tails.delete(key);
205
+ }
206
+ }
207
+ }
208
+ function validateNamespace(value) {
209
+ if (!value.extensionId || !value.scopeId || /[\0\r\n]/u.test(value.extensionId + value.scopeId))
210
+ throw new TypeError('Invalid Plugin data namespace');
211
+ }
212
+ function digest(value) {
213
+ return createHash('sha256').update(`${value.extensionId}\0${value.scopeId}`).digest('hex');
214
+ }
215
+ function clone(value) {
216
+ return value === undefined ? value : JSON.parse(JSON.stringify(value));
217
+ }
218
+ async function readJson(path, fallback) {
219
+ try {
220
+ return JSON.parse(await readFile(path, 'utf8'));
221
+ }
222
+ catch (error) {
223
+ if (error.code === 'ENOENT')
224
+ return fallback();
225
+ throw new Error(`Unable to read Plugin data: ${path}`, { cause: error });
226
+ }
227
+ }
228
+ async function atomicWrite(path, content, mode) {
229
+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });
230
+ const candidate = `${path}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`;
231
+ await writeFile(candidate, content, { mode, flag: 'wx' });
232
+ await rename(candidate, path);
233
+ await chmod(path, mode);
234
+ }
@@ -62,6 +62,12 @@ export class HostPluginPlatformCoordinator {
62
62
  result: boundedPage('tools', this.platform.inspectTools(input.rootId), input),
63
63
  };
64
64
  }
65
+ if (input.view === 'commands') {
66
+ return {
67
+ ok: true,
68
+ result: boundedPage('commands', this.platform.inspectCommands(input.rootId), input),
69
+ };
70
+ }
65
71
  if (input.view === 'failures') {
66
72
  return { ok: true, result: boundedPage('failures', failures, input) };
67
73
  }
@@ -43,6 +43,8 @@ export class HostPluginPlatform {
43
43
  #packageLoader;
44
44
  #store;
45
45
  #tools;
46
+ #systemPrompt;
47
+ #commands;
46
48
  #authority = emptyCompositionAuthority();
47
49
  #desired = emptyCompositionState();
48
50
  #mutation = Promise.resolve();
@@ -64,6 +66,8 @@ export class HostPluginPlatform {
64
66
  options.packageLoader ?? new TrustedPluginPackageLoader(controlDirectory, this.#packages);
65
67
  this.#store = options.store ?? new HostPluginCompositionStore(controlDirectory);
66
68
  this.#tools = options.tools;
69
+ this.#systemPrompt = options.systemPrompt;
70
+ this.#commands = options.commands;
67
71
  }
68
72
  async recover() {
69
73
  if (this.#recoveryStarted ||
@@ -344,6 +348,14 @@ export class HostPluginPlatform {
344
348
  this.#assertReadable();
345
349
  return this.#tools?.inspect(rootId) ?? Object.freeze([]);
346
350
  }
351
+ inspectSystemPrompt(rootId) {
352
+ this.#assertReadable();
353
+ return this.#systemPrompt?.inspect(rootId) ?? Object.freeze([]);
354
+ }
355
+ inspectCommands(rootId) {
356
+ this.#assertReadable();
357
+ return this.#commands?.inspect(rootId) ?? Object.freeze([]);
358
+ }
347
359
  async status() {
348
360
  this.#assertReadable();
349
361
  return Object.freeze({
@@ -17,7 +17,7 @@
17
17
  * under the License.
18
18
  */
19
19
  import { isDeepStrictEqual } from 'node:util';
20
- import { messageContentsEqual, normalizeMessageContent, } from '@maka/core/events';
20
+ import { messageContentDigest, normalizeMessageContent, } from '@maka/core/events';
21
21
  import { submittedTurnIntentsEqual } from '@maka/storage/execution-stores';
22
22
  export class RootAdmissionOwner {
23
23
  store;
@@ -44,7 +44,7 @@ export class RootAdmissionOwner {
44
44
  const snapshots = Object.freeze(admissions.map(snapshotAdmission));
45
45
  const byTurnId = new Map();
46
46
  for (const admission of snapshots)
47
- byTurnId.set(admission.turnId, admission);
47
+ byTurnId.set(admission.turnId, admissionIdentity(admission));
48
48
  this.#admissionsBySession.set(sessionId, byTurnId);
49
49
  const tip = snapshots.at(-1);
50
50
  if (tip)
@@ -67,7 +67,7 @@ export class RootAdmissionOwner {
67
67
  if (!known || !sameRootAdmission(known, admission)) {
68
68
  throw new Error('Durable Root Turn conflict is outside the owned chain');
69
69
  }
70
- return Object.freeze({ kind: 'conflict', admission: known });
70
+ return Object.freeze({ kind: 'conflict', admission: snapshotAdmission(admission) });
71
71
  }
72
72
  if (admission.sessionId !== input.sessionId ||
73
73
  admission.turnId !== input.turnId ||
@@ -80,7 +80,7 @@ export class RootAdmissionOwner {
80
80
  throw new Error('Root Turn admission identity changed within one Host Epoch');
81
81
  }
82
82
  const snapshot = snapshotAdmission(admission);
83
- byTurnId.set(admission.turnId, snapshot);
83
+ byTurnId.set(admission.turnId, admissionIdentity(snapshot));
84
84
  this.#admissionsBySession.set(input.sessionId, byTurnId);
85
85
  this.#tips.set(input.sessionId, snapshot);
86
86
  return Object.freeze({ ...result, admission: snapshot });
@@ -91,6 +91,16 @@ export class RootAdmissionOwner {
91
91
  }
92
92
  }
93
93
  }
94
+ // Historical admissions must remain verifiable throughout the Host Epoch, but
95
+ // only the current tip needs to own the full message bodies.
96
+ function admissionIdentity(admission) {
97
+ const { normalizedInput, sourceMessages, ...metadata } = admission;
98
+ return Object.freeze({
99
+ ...structuredClone(metadata),
100
+ normalizedInputDigest: normalizedInput === null ? null : messageContentDigest(normalizedInput),
101
+ sourceMessages: Object.freeze(sourceMessages.map(({ content, ...source }) => Object.freeze({ ...structuredClone(source), contentDigest: messageContentDigest(content) }))),
102
+ });
103
+ }
94
104
  function sameRootAdmission(left, right) {
95
105
  return (left.schemaVersion === right.schemaVersion &&
96
106
  left.sessionId === right.sessionId &&
@@ -102,9 +112,8 @@ function sameRootAdmission(left, right) {
102
112
  isDeepStrictEqual(left.skillInvocation, right.skillInvocation) &&
103
113
  isDeepStrictEqual(left.authorization, right.authorization) &&
104
114
  left.previousRootTurnId === right.previousRootTurnId &&
105
- (left.normalizedInput === null || right.normalizedInput === null
106
- ? left.normalizedInput === right.normalizedInput
107
- : messageContentsEqual(left.normalizedInput, right.normalizedInput)) &&
115
+ left.normalizedInputDigest ===
116
+ (right.normalizedInput === null ? null : messageContentDigest(right.normalizedInput)) &&
108
117
  left.sourceMessages.length === right.sourceMessages.length &&
109
118
  left.sourceMessages.every((source, index) => {
110
119
  const other = right.sourceMessages[index];
@@ -117,7 +126,7 @@ function sameRootAdmission(left, right) {
117
126
  (other.submittedPlacement ?? other.placement) &&
118
127
  submittedTurnIntentsEqual(source.submittedIntent, other.submittedIntent) &&
119
128
  isDeepStrictEqual(source.skillInvocation, other.skillInvocation) &&
120
- messageContentsEqual(source.content, other.content));
129
+ source.contentDigest === messageContentDigest(other.content));
121
130
  }) &&
122
131
  left.admittedAt === right.admittedAt);
123
132
  }