From e6b8aa1175df5590c540aafc2e3cc2d7f69527fd Mon Sep 17 00:00:00 2001 From: sunheyi <50973219+sunheyi6@users.noreply.github.com> Date: Sat, 1 Aug 2026 08:03:41 +0800 Subject: [PATCH 1/3] fix(desktop): prevent startup white screen --- packages/core/src/index.ts | 14 ++++---------- .../src/__tests__/continuation-replay.test.ts | 4 ++-- .../runtime/src/__tests__/session-manager.test.ts | 3 +-- packages/runtime/src/continuation-replay.ts | 5 ++--- .../fixtures/sqlite-recovery-concurrency-child.ts | 3 +-- .../src/__tests__/sqlite-runtime-store.test.ts | 5 ++--- packages/storage/src/sqlite-runtime-store.ts | 12 +++++++----- 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index aade53f3a7..c471c7a493 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -325,16 +325,10 @@ export type { RuntimePrefixSegmentV1, RuntimeBoundaryDigest, } from './runtime-boundary.js'; -export { - buildImmutableRuntimePrefix, - createRuntimeBoundaryCursor, - decodeContinuationClaim, - decodeRuntimeBoundaryCursor, - decodeRuntimePrefixSegment, - digestRuntimeBoundaryManifest, - digestRuntimePrefix, - runtimePrefixSegment, -} from './runtime-boundary.js'; +// runtime-boundary.ts is intentionally type-only in this browser-consumed +// barrel: its digest implementation depends on node:crypto. Runtime code must +// import its values from `@maka/core/runtime-boundary` so renderer imports of +// `@maka/core` do not evaluate Node-only modules before React can mount. // session.ts export type { diff --git a/packages/runtime/src/__tests__/continuation-replay.test.ts b/packages/runtime/src/__tests__/continuation-replay.test.ts index fd38edf9c7..1625ffbd9c 100644 --- a/packages/runtime/src/__tests__/continuation-replay.test.ts +++ b/packages/runtime/src/__tests__/continuation-replay.test.ts @@ -1,10 +1,10 @@ import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; +import { type RuntimeEvent } from '@maka/core'; import { buildImmutableRuntimePrefix, - type RuntimeEvent, type RuntimePrefixIdentityV1, -} from '@maka/core'; +} from '@maka/core/runtime-boundary'; import { buildContinuationReplayPlan, buildContinuationReplaySegment, diff --git a/packages/runtime/src/__tests__/session-manager.test.ts b/packages/runtime/src/__tests__/session-manager.test.ts index c17abae357..313d33f40b 100644 --- a/packages/runtime/src/__tests__/session-manager.test.ts +++ b/packages/runtime/src/__tests__/session-manager.test.ts @@ -10,13 +10,12 @@ import { DEEP_RESEARCH_SESSION_LABEL, SIDE_CONVERSATION_SESSION_LABEL, RUNTIME_CONTINUATION_AUTHORITY_V1, - buildImmutableRuntimePrefix, - decodeContinuationClaim, deriveTurnRecords, isSandboxBoundaryRestartClosure, isSessionInlineRun, isTerminalRuntimeEvent, } from '@maka/core'; +import { buildImmutableRuntimePrefix, decodeContinuationClaim } from '@maka/core/runtime-boundary'; import type { CreateSandboxBoundaryRequest, SandboxBoundaryRequest, diff --git a/packages/runtime/src/continuation-replay.ts b/packages/runtime/src/continuation-replay.ts index 38e239eca4..92e08c2973 100644 --- a/packages/runtime/src/continuation-replay.ts +++ b/packages/runtime/src/continuation-replay.ts @@ -1,14 +1,13 @@ import { createHash } from 'node:crypto'; +import { stableJsonStringify, type RuntimeEvent } from '@maka/core'; import { createRuntimeBoundaryCursor, runtimePrefixSegment, - stableJsonStringify, type ImmutableRuntimePrefixV1, type RuntimeBoundaryCursorV1, type RuntimeBoundaryDigest, - type RuntimeEvent, type RuntimePrefixSegmentV1, -} from '@maka/core'; +} from '@maka/core/runtime-boundary'; import type { RuntimeEventModelReplayItem, RuntimeEventReplayDiagnostic } from './model-history.js'; import { buildRuntimeEventModelReplayPlan, diff --git a/packages/storage/src/__tests__/fixtures/sqlite-recovery-concurrency-child.ts b/packages/storage/src/__tests__/fixtures/sqlite-recovery-concurrency-child.ts index ddf6b2097b..59efdf98e2 100644 --- a/packages/storage/src/__tests__/fixtures/sqlite-recovery-concurrency-child.ts +++ b/packages/storage/src/__tests__/fixtures/sqlite-recovery-concurrency-child.ts @@ -1,12 +1,11 @@ import { existsSync, writeSync } from 'node:fs'; import { dirname } from 'node:path'; import { - createRuntimeBoundaryCursor, - runtimePrefixSegment, type RuntimeEvent, type ToolRecoveryFactEnvelope, type WorkspaceBaselineAuthorityInput, } from '@maka/core'; +import { createRuntimeBoundaryCursor, runtimePrefixSegment } from '@maka/core/runtime-boundary'; import { createSqliteRuntimeStore } from '../../sqlite-runtime-store.js'; import { acquireOperationalStateDatabase } from '../../operational-state-store.js'; import { diff --git a/packages/storage/src/__tests__/sqlite-runtime-store.test.ts b/packages/storage/src/__tests__/sqlite-runtime-store.test.ts index c24e1a38ae..7d31c0b3ef 100644 --- a/packages/storage/src/__tests__/sqlite-runtime-store.test.ts +++ b/packages/storage/src/__tests__/sqlite-runtime-store.test.ts @@ -4,17 +4,16 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { DatabaseSync } from 'node:sqlite'; import { describe, it } from 'node:test'; +import { canonicalToolArgsHash, type RuntimeEvent } from '@maka/core'; import { buildImmutableRuntimePrefix, - canonicalToolArgsHash, createRuntimeBoundaryCursor, runtimePrefixSegment, ToolLedgerCorruptionError, ToolLedgerRejectionError, type ContinuationClaimV1, type ImmutableRuntimePrefixV1, - type RuntimeEvent, -} from '@maka/core'; +} from '@maka/core/runtime-boundary'; import { SQLITE_RUNTIME_SCHEMA_VERSION, createSqliteRuntimeStore, diff --git a/packages/storage/src/sqlite-runtime-store.ts b/packages/storage/src/sqlite-runtime-store.ts index 5d0ca71d43..dae3c872dd 100644 --- a/packages/storage/src/sqlite-runtime-store.ts +++ b/packages/storage/src/sqlite-runtime-store.ts @@ -7,8 +7,6 @@ import { isDeepStrictEqual } from 'node:util'; import { canonicalToolArgsHash, buildWorkspaceBaselineAuthorityEvents, - buildImmutableRuntimePrefix, - decodeContinuationClaim, decodeRuntimeEvent, encodeCanonicalRuntimeEvent, isPartialRuntimeEvent, @@ -28,10 +26,7 @@ import { validateToolLedgerTransition, type ContinuationClaimResult, type ContinuationClaimStateV1, - type ContinuationClaimV1, type RuntimeEvent, - type ImmutableRuntimePrefixV1, - type RuntimeBoundaryDigest, type RuntimeContinuationAuthorityStore, type RuntimeRecoveryBundleCommit, type RuntimeRecoveryBundleStore, @@ -47,6 +42,13 @@ import { type WorkspaceProjectionRebuildResult, type WorkspaceVersionRecordV1, } from '@maka/core'; +import { + buildImmutableRuntimePrefix, + decodeContinuationClaim, + type ContinuationClaimV1, + type ImmutableRuntimePrefixV1, + type RuntimeBoundaryDigest, +} from '@maka/core/runtime-boundary'; import { assertToolRecoveryEventBundle, interpretScannedToolRecovery, From c8fa3aff12c85bb20852b286dcb913b3284a5445 Mon Sep 17 00:00:00 2001 From: sunheyi <50973219+sunheyi6@users.noreply.github.com> Date: Mon, 3 Aug 2026 20:58:51 +0800 Subject: [PATCH 2/3] fix(desktop): harden core barrel against node-only value exports Drop value exports for tool-ledger-scanner (node:util), tool-args-identity (node:crypto), canonical-runtime-event (node:util), and tool-recovery-bundle (node:crypto) from the browser-consumed @maka/core barrel; keep type exports and route value consumers to the explicit subpaths. Re-lands the renderer regression guard as an executable test against the built barrel. --- .../renderer-barrel-node-boundary-child.ts | 16 +++++ .../fixtures/throw-on-node-import-hook.ts | 15 +++++ ...renderer-core-barrel-node-boundary.test.ts | 66 +++++++++++++++++++ packages/core/src/index.ts | 45 ++++--------- .../client-capability-recovery.test.ts | 8 +-- .../src/__tests__/execution-host.test.ts | 3 +- .../src/__tests__/context-budget.test.ts | 2 +- .../src/__tests__/conversation-copy.test.ts | 7 +- .../recovery-authority-equivalence.test.ts | 3 +- .../src/__tests__/recovery-resolver.test.ts | 2 +- packages/runtime/src/continuation-replay.ts | 3 +- packages/runtime/src/runtime-commit-sink.ts | 7 +- .../recovery-persistence-authority.test.ts | 7 +- .../sqlite-recovery-concurrency.test.ts | 4 +- .../__tests__/sqlite-runtime-crash.test.ts | 7 +- .../__tests__/sqlite-runtime-store.test.ts | 3 +- ...pace-version-authority-persistence.test.ts | 2 +- packages/storage/src/agent-run-store.ts | 10 +-- packages/storage/src/sqlite-runtime-store.ts | 15 +++-- 19 files changed, 149 insertions(+), 76 deletions(-) create mode 100644 apps/desktop/src/main/__tests__/fixtures/renderer-barrel-node-boundary-child.ts create mode 100644 apps/desktop/src/main/__tests__/fixtures/throw-on-node-import-hook.ts create mode 100644 apps/desktop/src/main/__tests__/renderer-core-barrel-node-boundary.test.ts diff --git a/apps/desktop/src/main/__tests__/fixtures/renderer-barrel-node-boundary-child.ts b/apps/desktop/src/main/__tests__/fixtures/renderer-barrel-node-boundary-child.ts new file mode 100644 index 0000000000..bbf91f56f2 --- /dev/null +++ b/apps/desktop/src/main/__tests__/fixtures/renderer-barrel-node-boundary-child.ts @@ -0,0 +1,16 @@ +// Child process for renderer-core-barrel-node-boundary.test.ts. Registers the +// throwing loader hook, then imports the built @maka/core barrel. Prints +// `barrel-ok` and exits 0 only if the barrel evaluates without touching any +// `node:*` module. +import { register } from 'node:module'; + +register(new URL('./throw-on-node-import-hook.js', import.meta.url)); + +import('@maka/core') + .then(() => { + console.log('barrel-ok'); + }) + .catch((error: unknown) => { + console.error(error); + process.exitCode = 1; + }); diff --git a/apps/desktop/src/main/__tests__/fixtures/throw-on-node-import-hook.ts b/apps/desktop/src/main/__tests__/fixtures/throw-on-node-import-hook.ts new file mode 100644 index 0000000000..9e988b5220 --- /dev/null +++ b/apps/desktop/src/main/__tests__/fixtures/throw-on-node-import-hook.ts @@ -0,0 +1,15 @@ +// Loader hook used by renderer-core-barrel-node-boundary.test.ts. It mirrors +// the renderer: a `node:*` import cannot resolve in the browser (Vite +// externalizes it), so the moment the @maka/core barrel graph reaches +// Node-only code this hook throws and the child process fails. + +export async function resolve( + specifier: string, + context: unknown, + nextResolve: (specifier: string, context: unknown) => Promise<{ url: string }>, +): Promise<{ url: string }> { + if (specifier.startsWith('node:')) { + throw new Error(`renderer core barrel evaluated Node-only module: ${specifier}`); + } + return nextResolve(specifier, context); +} diff --git a/apps/desktop/src/main/__tests__/renderer-core-barrel-node-boundary.test.ts b/apps/desktop/src/main/__tests__/renderer-core-barrel-node-boundary.test.ts new file mode 100644 index 0000000000..b2569ae974 --- /dev/null +++ b/apps/desktop/src/main/__tests__/renderer-core-barrel-node-boundary.test.ts @@ -0,0 +1,66 @@ +/** + * Executable regression guard for the renderer-facing `@maka/core` barrel. + * + * The Electron renderer imports values from the `@maka/core` barrel in a + * browser-like environment where `node:*` modules cannot be evaluated (Vite + * externalizes them, so a browser import of `node:crypto` / `node:util` + * throws before `createRoot()` runs and leaves the preload skeleton on + * screen — see #1573). This test spawns a child Node process whose loader + * throws on every `node:*` import and then imports the built barrel; the + * child exits non-zero the moment the barrel graph evaluates Node-only code. + * + * This is the executable form of the source-regex contract that #1727 pruned + * (the previous form asserted on `packages/core/src/index.ts` text; this one + * asserts on the built artifact the renderer actually consumes). + */ + +import { strict as assert } from 'node:assert'; +import { spawn } from 'node:child_process'; +import { fileURLToPath } from 'node:url'; +import { describe, it } from 'node:test'; + +const DESKTOP_ROOT = fileURLToPath(new URL('../../../', import.meta.url)); +const FIXTURES_DIR = fileURLToPath(new URL('./fixtures/', import.meta.url)); + +function runChild( + args: string[], + timeoutMs = 30_000, +): Promise<{ code: number | null; stdout: string; stderr: string }> { + return new Promise((resolve, reject) => { + const child = spawn(process.execPath, args, { + cwd: DESKTOP_ROOT, + stdio: ['ignore', 'pipe', 'pipe'], + }); + let stdout = ''; + let stderr = ''; + child.stdout?.on('data', (chunk: Buffer) => { + stdout += chunk.toString(); + }); + child.stderr?.on('data', (chunk: Buffer) => { + stderr += chunk.toString(); + }); + const timer = setTimeout(() => { + child.kill('SIGKILL'); + reject(new Error(`child process timed out after ${timeoutMs}ms`)); + }, timeoutMs); + child.once('error', (error) => { + clearTimeout(timer); + reject(error); + }); + child.once('close', (code) => { + clearTimeout(timer); + resolve({ code, stdout, stderr }); + }); + }); +} + +describe('renderer core barrel node boundary contract', () => { + it('importing @maka/core evaluates no node:* module', async () => { + const childPath = fileURLToPath( + new URL('./fixtures/renderer-barrel-node-boundary-child.js', import.meta.url), + ); + const { code, stdout, stderr } = await runChild([childPath]); + assert.equal(code, 0, `child process failed:\n${stderr}`); + assert.match(stdout, /barrel-ok/); + }); +}); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index c471c7a493..b07f25cfd1 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -268,16 +268,8 @@ export type { ToolLedgerTransitionKind, ToolLedgerTransitionValidation, } from './tool-ledger-scanner.js'; -export { - ToolLedgerCorruptionError, - ToolLedgerRejectionError, - scanToolLedger, - validateGenericToolLedgerAppend, - validateToolLedgerEventLane, - validateToolLedgerTransition, -} from './tool-ledger-scanner.js'; -export type { - ToolReconcileObservation, + export type { + ToolReconcileObservation, ToolReconcileResultFact, ToolRecoveryCompletedDecisionFact, ToolRecoveryDecisionFact, @@ -300,23 +292,9 @@ export type { ToolRecoveryEventBundle, ToolRecoveryOperationIdentity, } from './tool-recovery-bundle.js'; -export { - ToolRecoveryBundleValidationError, - assertToolRecoveryEventBundle, - interpretScannedToolRecovery, - validateToolRecoveryEventBundle, -} from './tool-recovery-bundle.js'; -export { - canonicalToolArgsHash, - stableJsonStringify, - stripUndefinedDeep, -} from './tool-args-identity.js'; -export { - encodeCanonicalRuntimeEvent, - type CanonicalRuntimeEventEncoding, -} from './canonical-runtime-event.js'; -export type { - ContinuationClaimV1, +export type { CanonicalRuntimeEventEncoding } from './canonical-runtime-event.js'; + export type { + ContinuationClaimV1, ImmutableRuntimePrefixV1, RuntimeBoundaryCursorV1, RuntimePrefixIdentityV1, @@ -325,10 +303,15 @@ export type { RuntimePrefixSegmentV1, RuntimeBoundaryDigest, } from './runtime-boundary.js'; -// runtime-boundary.ts is intentionally type-only in this browser-consumed -// barrel: its digest implementation depends on node:crypto. Runtime code must -// import its values from `@maka/core/runtime-boundary` so renderer imports of -// `@maka/core` do not evaluate Node-only modules before React can mount. +// The following modules are intentionally type-only (or absent) in this +// browser-consumed barrel: their value implementations depend on node:* (e.g. +// runtime-boundary.ts and tool-args-identity.ts use node:crypto, tool- +// ledger-scanner.ts and canonical-runtime-event.ts use node:util), which the +// renderer cannot evaluate. Runtime code must import their values from the +// explicit subpaths (`@maka/core/runtime-boundary`, `@maka/core/tool-args- +// identity`, `@maka/core/tool-ledger-scanner`, `@maka/core/canonical-runtime- +// event`, `@maka/core/tool-recovery-bundle`) so renderer imports of `@maka/core` +// never evaluate Node-only modules before React can mount. // session.ts export type { diff --git a/packages/runtime-host/src/__tests__/client-capability-recovery.test.ts b/packages/runtime-host/src/__tests__/client-capability-recovery.test.ts index 455e1d0278..24c6953db4 100644 --- a/packages/runtime-host/src/__tests__/client-capability-recovery.test.ts +++ b/packages/runtime-host/src/__tests__/client-capability-recovery.test.ts @@ -1,11 +1,7 @@ import assert from 'node:assert/strict'; import { test } from 'node:test'; -import { - canonicalToolArgsHash, - TOOL_BOUNDARY_PROTOCOL_V1, - type RuntimeEvent, - type ToolRecoveryMode, -} from '@maka/core'; +import { TOOL_BOUNDARY_PROTOCOL_V1, type RuntimeEvent, type ToolRecoveryMode } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import { createSqliteRuntimeStore } from '@maka/storage'; import { recoverClientCapabilityOutcomes } from '../server/client-capability-recovery.js'; diff --git a/packages/runtime-host/src/__tests__/execution-host.test.ts b/packages/runtime-host/src/__tests__/execution-host.test.ts index 9e71f4eb69..1267e1cd5d 100644 --- a/packages/runtime-host/src/__tests__/execution-host.test.ts +++ b/packages/runtime-host/src/__tests__/execution-host.test.ts @@ -16,7 +16,8 @@ import { connect, type Socket } from 'node:net'; import { tmpdir } from 'node:os'; import { dirname, join } from 'node:path'; import { test } from 'node:test'; -import { canonicalToolArgsHash, TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core'; +import { TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import type { AgentRunHeader } from '@maka/core/agent-run'; import type { MessageContent } from '@maka/core/events'; import type { ConnectionCatalogEntry } from '@maka/core/runtime-policy'; diff --git a/packages/runtime/src/__tests__/context-budget.test.ts b/packages/runtime/src/__tests__/context-budget.test.ts index e1b6f44224..e85b1a09a9 100644 --- a/packages/runtime/src/__tests__/context-budget.test.ts +++ b/packages/runtime/src/__tests__/context-budget.test.ts @@ -2,7 +2,7 @@ import assert from 'node:assert/strict'; import { Buffer } from 'node:buffer'; import { createHash } from 'node:crypto'; import { describe, test } from 'node:test'; -import { encodeCanonicalRuntimeEvent } from '@maka/core'; +import { encodeCanonicalRuntimeEvent } from '@maka/core/canonical-runtime-event'; import type { RuntimeEvent } from '@maka/core/runtime-event'; import { ARCHIVED_TOOL_RESULT_PLACEHOLDER_KIND, diff --git a/packages/runtime/src/__tests__/conversation-copy.test.ts b/packages/runtime/src/__tests__/conversation-copy.test.ts index 2173a47c5d..aea569f219 100644 --- a/packages/runtime/src/__tests__/conversation-copy.test.ts +++ b/packages/runtime/src/__tests__/conversation-copy.test.ts @@ -11,11 +11,8 @@ import type { RuntimeEventStore, StoredMessage, } from '@maka/core'; -import { - canonicalToolArgsHash, - decodeCanonicalToolResultContent, - isSessionInlineRun, -} from '@maka/core'; +import { decodeCanonicalToolResultContent, isSessionInlineRun } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import { createSqliteAgentRunStore, createSqliteRuntimeStore, diff --git a/packages/runtime/src/__tests__/recovery-authority-equivalence.test.ts b/packages/runtime/src/__tests__/recovery-authority-equivalence.test.ts index 4f301428e4..1fa91cfec3 100644 --- a/packages/runtime/src/__tests__/recovery-authority-equivalence.test.ts +++ b/packages/runtime/src/__tests__/recovery-authority-equivalence.test.ts @@ -3,7 +3,8 @@ import { mkdtemp, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { describe, it } from 'node:test'; -import { canonicalToolArgsHash, type RuntimeEvent } from '@maka/core'; +import type { RuntimeEvent } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import { createSqliteRuntimeStore } from '@maka/storage'; import { resolveRuntimeRecovery } from '../recovery-resolver.js'; import { buildResumePlanFromRuntimeEvents } from '../runtime-resume.js'; diff --git a/packages/runtime/src/__tests__/recovery-resolver.test.ts b/packages/runtime/src/__tests__/recovery-resolver.test.ts index e44629a5f9..4a16863aa9 100644 --- a/packages/runtime/src/__tests__/recovery-resolver.test.ts +++ b/packages/runtime/src/__tests__/recovery-resolver.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; -import { canonicalToolArgsHash } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import type { RuntimeEvent } from '@maka/core/runtime-event'; import { buildInterruptedCodeModeOutcomeCommits, diff --git a/packages/runtime/src/continuation-replay.ts b/packages/runtime/src/continuation-replay.ts index 92e08c2973..dd7d35d1e0 100644 --- a/packages/runtime/src/continuation-replay.ts +++ b/packages/runtime/src/continuation-replay.ts @@ -1,5 +1,6 @@ import { createHash } from 'node:crypto'; -import { stableJsonStringify, type RuntimeEvent } from '@maka/core'; +import type { RuntimeEvent } from '@maka/core'; +import { stableJsonStringify } from '@maka/core/tool-args-identity'; import { createRuntimeBoundaryCursor, runtimePrefixSegment, diff --git a/packages/runtime/src/runtime-commit-sink.ts b/packages/runtime/src/runtime-commit-sink.ts index d5c0560b56..58ba945f56 100644 --- a/packages/runtime/src/runtime-commit-sink.ts +++ b/packages/runtime/src/runtime-commit-sink.ts @@ -1,9 +1,6 @@ import { createHash } from 'node:crypto'; -import { - canonicalToolArgsHash as canonicalToolArgsHashCore, - type RuntimeEvent, - type ToolRecoveryMode, -} from '@maka/core'; +import type { RuntimeEvent, ToolRecoveryMode } from '@maka/core'; +import { canonicalToolArgsHash as canonicalToolArgsHashCore } from '@maka/core/tool-args-identity'; export type { ToolRecoveryMode } from '@maka/core'; diff --git a/packages/storage/src/__tests__/recovery-persistence-authority.test.ts b/packages/storage/src/__tests__/recovery-persistence-authority.test.ts index 0c3db58d1f..50a4e95875 100644 --- a/packages/storage/src/__tests__/recovery-persistence-authority.test.ts +++ b/packages/storage/src/__tests__/recovery-persistence-authority.test.ts @@ -4,11 +4,8 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { DatabaseSync } from 'node:sqlite'; import { describe, it } from 'node:test'; -import { - TOOL_RECOVERY_BUNDLE_CAPABILITY_V1, - canonicalToolArgsHash, - type RuntimeEvent, -} from '@maka/core'; +import { TOOL_RECOVERY_BUNDLE_CAPABILITY_V1, type RuntimeEvent } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import { createSqliteRuntimeStore } from '../sqlite-runtime-store.js'; import type { SqliteRuntimeStoreFailpoint } from '../sqlite-runtime-store.js'; diff --git a/packages/storage/src/__tests__/sqlite-recovery-concurrency.test.ts b/packages/storage/src/__tests__/sqlite-recovery-concurrency.test.ts index 3474864f5c..028118d2b2 100644 --- a/packages/storage/src/__tests__/sqlite-recovery-concurrency.test.ts +++ b/packages/storage/src/__tests__/sqlite-recovery-concurrency.test.ts @@ -7,7 +7,9 @@ import { join } from 'node:path'; import { DatabaseSync } from 'node:sqlite'; import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; -import { canonicalToolArgsHash, scanToolLedger, type RuntimeEvent } from '@maka/core'; +import type { RuntimeEvent } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; +import { scanToolLedger } from '@maka/core/tool-ledger-scanner'; import { SQLITE_RUNTIME_SCHEMA_VERSION, createSqliteRuntimeStore, diff --git a/packages/storage/src/__tests__/sqlite-runtime-crash.test.ts b/packages/storage/src/__tests__/sqlite-runtime-crash.test.ts index 59a29c8ae9..487ce03214 100644 --- a/packages/storage/src/__tests__/sqlite-runtime-crash.test.ts +++ b/packages/storage/src/__tests__/sqlite-runtime-crash.test.ts @@ -6,11 +6,8 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { describe, it } from 'node:test'; import { fileURLToPath } from 'node:url'; -import { - canonicalToolArgsHash, - type RuntimeEvent, - type WorkspaceBaselineAuthorityInput, -} from '@maka/core'; +import { type RuntimeEvent, type WorkspaceBaselineAuthorityInput } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import { createSqliteRuntimeStore, type SqliteRuntimeStoreFailpoint, diff --git a/packages/storage/src/__tests__/sqlite-runtime-store.test.ts b/packages/storage/src/__tests__/sqlite-runtime-store.test.ts index 7d31c0b3ef..133ab14b00 100644 --- a/packages/storage/src/__tests__/sqlite-runtime-store.test.ts +++ b/packages/storage/src/__tests__/sqlite-runtime-store.test.ts @@ -4,7 +4,8 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { DatabaseSync } from 'node:sqlite'; import { describe, it } from 'node:test'; -import { canonicalToolArgsHash, type RuntimeEvent } from '@maka/core'; +import type { RuntimeEvent } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import { buildImmutableRuntimePrefix, createRuntimeBoundaryCursor, diff --git a/packages/storage/src/__tests__/workspace-version-authority-persistence.test.ts b/packages/storage/src/__tests__/workspace-version-authority-persistence.test.ts index ad3d32cc22..7436c2864e 100644 --- a/packages/storage/src/__tests__/workspace-version-authority-persistence.test.ts +++ b/packages/storage/src/__tests__/workspace-version-authority-persistence.test.ts @@ -7,11 +7,11 @@ import { describe, it } from 'node:test'; import { WORKSPACE_AUTHORITY_SESSION_ID, buildWorkspaceBaselineAuthorityEvents, - canonicalToolArgsHash, workspaceAuthorityIdentity, type RuntimeEvent, type WorkspaceBaselineAuthorityInput, } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import { createConversationOperationalStateStore } from '../conversation-operational-state.js'; import { createSqliteRuntimeStore, diff --git a/packages/storage/src/agent-run-store.ts b/packages/storage/src/agent-run-store.ts index ef8375d344..4b193580df 100644 --- a/packages/storage/src/agent-run-store.ts +++ b/packages/storage/src/agent-run-store.ts @@ -24,15 +24,11 @@ import { aggregateMessageContents, decodeAgentGraphIntentClaim, decodeMessageContent, - encodeCanonicalRuntimeEvent, isCanonicalAttachmentRef, isTerminalRuntimeEvent, MAX_ATTACHMENT_BYTES, MAX_ATTACHMENT_COUNT, messageContentsEqual, - scanToolLedger, - validateGenericToolLedgerAppend, - validateToolLedgerTransition, type AgentRunEvent, type AgentRunEventType, type AgentRunHeader, @@ -44,11 +40,17 @@ import { type RuntimeEvent, type RuntimeEventStore, } from '@maka/core'; +import { encodeCanonicalRuntimeEvent } from '@maka/core/canonical-runtime-event'; import { isOrchestrationMode, isTurnOrchestrationSource, type TurnOrchestration, } from '@maka/core/orchestration'; +import { + scanToolLedger, + validateGenericToolLedgerAppend, + validateToolLedgerTransition, +} from '@maka/core/tool-ledger-scanner'; const SAFE_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/; export const ROOT_TURN_ADMISSION_SCHEMA_VERSION = 1 as const; diff --git a/packages/storage/src/sqlite-runtime-store.ts b/packages/storage/src/sqlite-runtime-store.ts index dae3c872dd..c865e54c25 100644 --- a/packages/storage/src/sqlite-runtime-store.ts +++ b/packages/storage/src/sqlite-runtime-store.ts @@ -5,25 +5,18 @@ import { dirname } from 'node:path'; import type { DatabaseSync, SQLInputValue } from 'node:sqlite'; import { isDeepStrictEqual } from 'node:util'; import { - canonicalToolArgsHash, buildWorkspaceBaselineAuthorityEvents, decodeRuntimeEvent, - encodeCanonicalRuntimeEvent, isPartialRuntimeEvent, isTerminalRuntimeEvent, RUNTIME_CONTINUATION_AUTHORITY_V1, scanWorkspaceBaselineAuthority, - scanToolLedger, - stableJsonStringify, TOOL_BOUNDARY_PROTOCOL_V1, TOOL_RECOVERY_BUNDLE_CAPABILITY_V1, ToolLedgerCorruptionError, ToolLedgerRejectionError, WORKSPACE_AUTHORITY_SESSION_ID, WORKSPACE_VERSION_AUTHORITY_CAPABILITY_V1, - validateGenericToolLedgerAppend, - validateToolLedgerEventLane, - validateToolLedgerTransition, type ContinuationClaimResult, type ContinuationClaimStateV1, type RuntimeEvent, @@ -42,6 +35,14 @@ import { type WorkspaceProjectionRebuildResult, type WorkspaceVersionRecordV1, } from '@maka/core'; +import { canonicalToolArgsHash, stableJsonStringify } from '@maka/core/tool-args-identity'; +import { encodeCanonicalRuntimeEvent } from '@maka/core/canonical-runtime-event'; +import { + scanToolLedger, + validateGenericToolLedgerAppend, + validateToolLedgerEventLane, + validateToolLedgerTransition, +} from '@maka/core/tool-ledger-scanner'; import { buildImmutableRuntimePrefix, decodeContinuationClaim, From 03f8199e3de605eb74177b4b25a116e7c4ef4903 Mon Sep 17 00:00:00 2001 From: sunheyi <50973219+sunheyi6@users.noreply.github.com> Date: Sat, 8 Aug 2026 15:38:58 +0800 Subject: [PATCH 3/3] fix(desktop): rebase onto main, keep barrel browser-safe after #2258 - shell-run.ts gained a node:util dependency in #2258; replace the single isDeepStrictEqual use with a local structural comparison so the renderer-facing @maka/core barrel stays free of node:* evaluation - migrate main's new barrel consumers of node-only values to their existing subpaths (tool-args-identity, tool-ledger-scanner, canonical-runtime-event) - reword the barrel boundary test comments to describe the enforced structural invariant instead of a reproduced failure mechanism; drop the unused FIXTURES_DIR constant --- .../fixtures/throw-on-node-import-hook.ts | 8 ++-- ...renderer-core-barrel-node-boundary.test.ts | 17 ++++---- packages/core/src/index.ts | 8 ++-- packages/core/src/shell-run.ts | 40 +++++++++++++++++-- .../__tests__/execution-host-message.test.ts | 3 +- .../__tests__/execution-host-queue.test.ts | 3 +- .../__tests__/execution-host-recovery.test.ts | 3 +- .../fixtures/execution-host-suite.ts | 3 +- .../src/__tests__/ai-sdk-backend.test.ts | 2 +- .../pre-dispatch-refusal-ledger.test.ts | 2 +- .../src/__tests__/runtime-resume.test.ts | 2 +- .../session-manager-terminal-ledger.test.ts | 6 +-- .../src/__tests__/session-manager.test.ts | 2 +- .../__tests__/shell-run-tool-result.test.ts | 8 +--- packages/runtime/src/agent-run.ts | 8 +--- packages/runtime/src/ai-sdk-backend.ts | 2 +- .../__tests__/sqlite-runtime-store.test.ts | 6 ++- packages/storage/src/sqlite-runtime-store.ts | 4 +- 18 files changed, 79 insertions(+), 48 deletions(-) diff --git a/apps/desktop/src/main/__tests__/fixtures/throw-on-node-import-hook.ts b/apps/desktop/src/main/__tests__/fixtures/throw-on-node-import-hook.ts index 9e988b5220..98bde1acad 100644 --- a/apps/desktop/src/main/__tests__/fixtures/throw-on-node-import-hook.ts +++ b/apps/desktop/src/main/__tests__/fixtures/throw-on-node-import-hook.ts @@ -1,7 +1,7 @@ -// Loader hook used by renderer-core-barrel-node-boundary.test.ts. It mirrors -// the renderer: a `node:*` import cannot resolve in the browser (Vite -// externalizes it), so the moment the @maka/core barrel graph reaches -// Node-only code this hook throws and the child process fails. +// Loader hook used by renderer-core-barrel-node-boundary.test.ts. It enforces +// the structural invariant under test: a `node:*` import cannot resolve in the +// renderer's browser-like environment, so the moment the @maka/core barrel +// graph reaches Node-only code this hook throws and the child process fails. export async function resolve( specifier: string, diff --git a/apps/desktop/src/main/__tests__/renderer-core-barrel-node-boundary.test.ts b/apps/desktop/src/main/__tests__/renderer-core-barrel-node-boundary.test.ts index b2569ae974..eb04ddf216 100644 --- a/apps/desktop/src/main/__tests__/renderer-core-barrel-node-boundary.test.ts +++ b/apps/desktop/src/main/__tests__/renderer-core-barrel-node-boundary.test.ts @@ -1,13 +1,15 @@ /** * Executable regression guard for the renderer-facing `@maka/core` barrel. * - * The Electron renderer imports values from the `@maka/core` barrel in a - * browser-like environment where `node:*` modules cannot be evaluated (Vite - * externalizes them, so a browser import of `node:crypto` / `node:util` - * throws before `createRoot()` runs and leaves the preload skeleton on - * screen — see #1573). This test spawns a child Node process whose loader - * throws on every `node:*` import and then imports the built barrel; the - * child exits non-zero the moment the barrel graph evaluates Node-only code. + * This test intentionally enforces a stronger structural invariant than the + * current tree-shaking behavior: the renderer-facing root barrel must remain + * loadable without evaluating any Node built-ins. The Electron renderer runs + * in a browser-like environment where `node:*` modules cannot resolve (Vite + * externalizes them; today they happen to be tree-shaken out of the renderer + * graph, but nothing about that is guaranteed). This test spawns a child Node + * process whose loader throws on every `node:*` import and then imports the + * built barrel; the child exits non-zero the moment the barrel graph evaluates + * Node-only code. * * This is the executable form of the source-regex contract that #1727 pruned * (the previous form asserted on `packages/core/src/index.ts` text; this one @@ -20,7 +22,6 @@ import { fileURLToPath } from 'node:url'; import { describe, it } from 'node:test'; const DESKTOP_ROOT = fileURLToPath(new URL('../../../', import.meta.url)); -const FIXTURES_DIR = fileURLToPath(new URL('./fixtures/', import.meta.url)); function runChild( args: string[], diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index b07f25cfd1..5e46bdc2c3 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -268,8 +268,8 @@ export type { ToolLedgerTransitionKind, ToolLedgerTransitionValidation, } from './tool-ledger-scanner.js'; - export type { - ToolReconcileObservation, +export type { + ToolReconcileObservation, ToolReconcileResultFact, ToolRecoveryCompletedDecisionFact, ToolRecoveryDecisionFact, @@ -293,8 +293,8 @@ export type { ToolRecoveryOperationIdentity, } from './tool-recovery-bundle.js'; export type { CanonicalRuntimeEventEncoding } from './canonical-runtime-event.js'; - export type { - ContinuationClaimV1, +export type { + ContinuationClaimV1, ImmutableRuntimePrefixV1, RuntimeBoundaryCursorV1, RuntimePrefixIdentityV1, diff --git a/packages/core/src/shell-run.ts b/packages/core/src/shell-run.ts index 2eae201386..51e7c93698 100644 --- a/packages/core/src/shell-run.ts +++ b/packages/core/src/shell-run.ts @@ -1,5 +1,3 @@ -import * as nodeUtil from 'node:util'; - export const SHELL_RUN_STATUSES = [ 'starting', 'running', @@ -410,7 +408,7 @@ export function nextShellRunRecord(current: ShellRunRecord, patch: ShellRunPatch ) { throw new Error(`ShellRun terminal outcome is immutable: ${current.status}`); } - if (nodeUtil.isDeepStrictEqual(candidate, current)) return current; + if (shellRunRecordsEqual(candidate, current)) return current; return normalizeShellRunRecord( { ...candidate, revision: current.revision + 1 }, sessionId, @@ -418,6 +416,42 @@ export function nextShellRunRecord(current: ShellRunRecord, patch: ShellRunPatch ); } +/** + * Structural equality for normalized ShellRun records. Records are plain + * JSON-safe data (string/number/boolean/null/arrays/objects), so a small + * recursive comparison is sufficient and keeps this module free of node:* + * imports so the renderer-facing `@maka/core` barrel stays browser-safe. + */ +function shellRunRecordsEqual(left: unknown, right: unknown): boolean { + if (left === right) return true; + if (typeof left !== 'object' || typeof right !== 'object' || left === null || right === null) { + return false; + } + if (Array.isArray(left) !== Array.isArray(right)) return false; + if (Array.isArray(left)) { + if (left.length !== (right as unknown[]).length) return false; + for (let index = 0; index < left.length; index += 1) { + if (!shellRunRecordsEqual(left[index], (right as unknown[])[index])) return false; + } + return true; + } + const leftKeys = Object.keys(left as Record); + const rightKeys = Object.keys(right as Record); + if (leftKeys.length !== rightKeys.length) return false; + for (const key of leftKeys) { + if (!Object.prototype.hasOwnProperty.call(right, key)) return false; + if ( + !shellRunRecordsEqual( + (left as Record)[key], + (right as Record)[key], + ) + ) { + return false; + } + } + return true; +} + function isShellRunSandboxExecution(value: unknown): boolean { if (value === undefined) return true; if (!value || typeof value !== 'object' || Array.isArray(value)) return false; diff --git a/packages/runtime-host/src/__tests__/execution-host-message.test.ts b/packages/runtime-host/src/__tests__/execution-host-message.test.ts index f66cc5c296..66729c79d0 100644 --- a/packages/runtime-host/src/__tests__/execution-host-message.test.ts +++ b/packages/runtime-host/src/__tests__/execution-host-message.test.ts @@ -16,7 +16,8 @@ import { connect, type Socket } from 'node:net'; import { tmpdir } from 'node:os'; import { dirname, join } from 'node:path'; import { test } from 'node:test'; -import { canonicalToolArgsHash, TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core'; +import { TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import type { AgentRunHeader } from '@maka/core/agent-run'; import type { MessageContent } from '@maka/core/events'; import type { ConnectionCatalogEntry } from '@maka/core/runtime-policy'; diff --git a/packages/runtime-host/src/__tests__/execution-host-queue.test.ts b/packages/runtime-host/src/__tests__/execution-host-queue.test.ts index 28cfc2dc22..f491d04967 100644 --- a/packages/runtime-host/src/__tests__/execution-host-queue.test.ts +++ b/packages/runtime-host/src/__tests__/execution-host-queue.test.ts @@ -16,7 +16,8 @@ import { connect, type Socket } from 'node:net'; import { tmpdir } from 'node:os'; import { dirname, join } from 'node:path'; import { test } from 'node:test'; -import { canonicalToolArgsHash, TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core'; +import { TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import type { AgentRunHeader } from '@maka/core/agent-run'; import type { MessageContent } from '@maka/core/events'; import type { ConnectionCatalogEntry } from '@maka/core/runtime-policy'; diff --git a/packages/runtime-host/src/__tests__/execution-host-recovery.test.ts b/packages/runtime-host/src/__tests__/execution-host-recovery.test.ts index e52e989911..50cce19335 100644 --- a/packages/runtime-host/src/__tests__/execution-host-recovery.test.ts +++ b/packages/runtime-host/src/__tests__/execution-host-recovery.test.ts @@ -7,7 +7,8 @@ import { connect, type Socket } from 'node:net'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { test } from 'node:test'; -import { canonicalToolArgsHash, TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core'; +import { TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import type { AgentRunHeader } from '@maka/core/agent-run'; import type { MessageContent } from '@maka/core/events'; import type { ConnectionCatalogEntry } from '@maka/core/runtime-policy'; diff --git a/packages/runtime-host/src/__tests__/fixtures/execution-host-suite.ts b/packages/runtime-host/src/__tests__/fixtures/execution-host-suite.ts index 07d72c93e7..96d05b3bfc 100644 --- a/packages/runtime-host/src/__tests__/fixtures/execution-host-suite.ts +++ b/packages/runtime-host/src/__tests__/fixtures/execution-host-suite.ts @@ -16,7 +16,8 @@ import { connect, type Socket } from 'node:net'; import { tmpdir } from 'node:os'; import { dirname, join } from 'node:path'; import { test } from 'node:test'; -import { canonicalToolArgsHash, TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core'; +import { TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import type { AgentRunHeader } from '@maka/core/agent-run'; import { normalizeMessageContent, type MessageContent } from '@maka/core/events'; import type { ConnectionCatalogEntry } from '@maka/core/runtime-policy'; diff --git a/packages/runtime/src/__tests__/ai-sdk-backend.test.ts b/packages/runtime/src/__tests__/ai-sdk-backend.test.ts index 907949a02f..8b58e40ed2 100644 --- a/packages/runtime/src/__tests__/ai-sdk-backend.test.ts +++ b/packages/runtime/src/__tests__/ai-sdk-backend.test.ts @@ -13,7 +13,7 @@ import type { SessionHeader, StorageRef, } from '@maka/core'; -import { encodeCanonicalRuntimeEvent } from '@maka/core'; +import { encodeCanonicalRuntimeEvent } from '@maka/core/canonical-runtime-event'; import type { SessionEvent } from '@maka/core/events'; import type { RuntimeEvent } from '@maka/core/runtime-event'; import { createSessionEventMapMemory, mapSessionEventToRuntimeEvent } from '../ai-sdk-flow.js'; diff --git a/packages/runtime/src/__tests__/pre-dispatch-refusal-ledger.test.ts b/packages/runtime/src/__tests__/pre-dispatch-refusal-ledger.test.ts index 1ba5c647e6..498d25e5f2 100644 --- a/packages/runtime/src/__tests__/pre-dispatch-refusal-ledger.test.ts +++ b/packages/runtime/src/__tests__/pre-dispatch-refusal-ledger.test.ts @@ -2,12 +2,12 @@ import assert from 'node:assert/strict'; import { test } from 'node:test'; import { - scanToolLedger, type LlmConnection, type RuntimeEvent, type SessionEvent, type SessionHeader, } from '@maka/core'; +import { scanToolLedger } from '@maka/core/tool-ledger-scanner'; import { z } from 'zod'; import { createSessionEventMapMemory, mapSessionEventToRuntimeEvent } from '../ai-sdk-flow.js'; diff --git a/packages/runtime/src/__tests__/runtime-resume.test.ts b/packages/runtime/src/__tests__/runtime-resume.test.ts index a9a95597fb..c7b404ffc4 100644 --- a/packages/runtime/src/__tests__/runtime-resume.test.ts +++ b/packages/runtime/src/__tests__/runtime-resume.test.ts @@ -5,7 +5,7 @@ import { buildImmutableRuntimePrefix, type ImmutableRuntimePrefixV1, } from '@maka/core/runtime-boundary'; -import { canonicalToolArgsHash } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import type { RuntimeEvent } from '@maka/core/runtime-event'; import type { AgentRunHeader } from '@maka/core/agent-run'; diff --git a/packages/runtime/src/__tests__/session-manager-terminal-ledger.test.ts b/packages/runtime/src/__tests__/session-manager-terminal-ledger.test.ts index 79017dfe80..ae64087c4c 100644 --- a/packages/runtime/src/__tests__/session-manager-terminal-ledger.test.ts +++ b/packages/runtime/src/__tests__/session-manager-terminal-ledger.test.ts @@ -1,13 +1,11 @@ import { describe, test } from 'node:test'; import assert from 'node:assert/strict'; import { setTimeout as timerDelay } from 'node:timers/promises'; +import { deriveTurnRecords, DurableStoreWriteError, isTerminalRuntimeEvent } from '@maka/core'; import { - deriveTurnRecords, - DurableStoreWriteError, - isTerminalRuntimeEvent, ToolLedgerCorruptionError, ToolLedgerRejectionError, -} from '@maka/core'; +} from '@maka/core/tool-ledger-scanner'; import type { SandboxBoundaryResponse } from '@maka/core/sandbox-boundary'; import type { AgentRunEvent, diff --git a/packages/runtime/src/__tests__/session-manager.test.ts b/packages/runtime/src/__tests__/session-manager.test.ts index 313d33f40b..b6457dab5e 100644 --- a/packages/runtime/src/__tests__/session-manager.test.ts +++ b/packages/runtime/src/__tests__/session-manager.test.ts @@ -6,7 +6,6 @@ import { applySandboxBoundaryExpansion, createGenesisExecutionBoundary, createWorkspaceWritePermissionProfile, - canonicalToolArgsHash, DEEP_RESEARCH_SESSION_LABEL, SIDE_CONVERSATION_SESSION_LABEL, RUNTIME_CONTINUATION_AUTHORITY_V1, @@ -15,6 +14,7 @@ import { isSessionInlineRun, isTerminalRuntimeEvent, } from '@maka/core'; +import { canonicalToolArgsHash } from '@maka/core/tool-args-identity'; import { buildImmutableRuntimePrefix, decodeContinuationClaim } from '@maka/core/runtime-boundary'; import type { CreateSandboxBoundaryRequest, diff --git a/packages/runtime/src/__tests__/shell-run-tool-result.test.ts b/packages/runtime/src/__tests__/shell-run-tool-result.test.ts index 12b76fa8a9..78e2f55bd4 100644 --- a/packages/runtime/src/__tests__/shell-run-tool-result.test.ts +++ b/packages/runtime/src/__tests__/shell-run-tool-result.test.ts @@ -3,12 +3,8 @@ import { mkdtemp, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { describe, test } from 'node:test'; -import { - encodeCanonicalRuntimeEvent, - type PtyShellOutput, - type RuntimeEvent, - type ShellRunRecord, -} from '@maka/core'; +import { type PtyShellOutput, type RuntimeEvent, type ShellRunRecord } from '@maka/core'; +import { encodeCanonicalRuntimeEvent } from '@maka/core/canonical-runtime-event'; import { createSessionStore } from '@maka/storage'; import { diff --git a/packages/runtime/src/agent-run.ts b/packages/runtime/src/agent-run.ts index fb4a8a06ad..7d7f1ad966 100644 --- a/packages/runtime/src/agent-run.ts +++ b/packages/runtime/src/agent-run.ts @@ -7,12 +7,8 @@ import type { RuntimeEventStore, ToolBoundaryProtocol, } from '@maka/core'; -import { - DurableStoreWriteError, - ToolLedgerRejectionError, - isSessionInlineRun, - isTerminalRuntimeEvent, -} from '@maka/core'; +import { DurableStoreWriteError, isSessionInlineRun, isTerminalRuntimeEvent } from '@maka/core'; +import { ToolLedgerRejectionError } from '@maka/core/tool-ledger-scanner'; import { Buffer } from 'node:buffer'; import { isDeepStrictEqual } from 'node:util'; import { redactSecrets } from '@maka/core/redaction'; diff --git a/packages/runtime/src/ai-sdk-backend.ts b/packages/runtime/src/ai-sdk-backend.ts index 51d91bdd77..d502f5217e 100644 --- a/packages/runtime/src/ai-sdk-backend.ts +++ b/packages/runtime/src/ai-sdk-backend.ts @@ -80,8 +80,8 @@ import type { AttachmentByteReader } from '@maka/core/attachments'; import { MAX_PROVIDER_IMAGE_REQUEST_BYTES, PROVIDER_IMAGE_BUDGET_EXCEEDED_MESSAGE, - stripUndefinedDeep, } from '@maka/core'; +import { stripUndefinedDeep } from '@maka/core/tool-args-identity'; import type { LlmCallRecord, PricingConfig, diff --git a/packages/storage/src/__tests__/sqlite-runtime-store.test.ts b/packages/storage/src/__tests__/sqlite-runtime-store.test.ts index 133ab14b00..14b2a75008 100644 --- a/packages/storage/src/__tests__/sqlite-runtime-store.test.ts +++ b/packages/storage/src/__tests__/sqlite-runtime-store.test.ts @@ -10,11 +10,13 @@ import { buildImmutableRuntimePrefix, createRuntimeBoundaryCursor, runtimePrefixSegment, - ToolLedgerCorruptionError, - ToolLedgerRejectionError, type ContinuationClaimV1, type ImmutableRuntimePrefixV1, } from '@maka/core/runtime-boundary'; +import { + ToolLedgerCorruptionError, + ToolLedgerRejectionError, +} from '@maka/core/tool-ledger-scanner'; import { SQLITE_RUNTIME_SCHEMA_VERSION, createSqliteRuntimeStore, diff --git a/packages/storage/src/sqlite-runtime-store.ts b/packages/storage/src/sqlite-runtime-store.ts index c865e54c25..f1d5fbb116 100644 --- a/packages/storage/src/sqlite-runtime-store.ts +++ b/packages/storage/src/sqlite-runtime-store.ts @@ -13,8 +13,6 @@ import { scanWorkspaceBaselineAuthority, TOOL_BOUNDARY_PROTOCOL_V1, TOOL_RECOVERY_BUNDLE_CAPABILITY_V1, - ToolLedgerCorruptionError, - ToolLedgerRejectionError, WORKSPACE_AUTHORITY_SESSION_ID, WORKSPACE_VERSION_AUTHORITY_CAPABILITY_V1, type ContinuationClaimResult, @@ -39,6 +37,8 @@ import { canonicalToolArgsHash, stableJsonStringify } from '@maka/core/tool-args import { encodeCanonicalRuntimeEvent } from '@maka/core/canonical-runtime-event'; import { scanToolLedger, + ToolLedgerCorruptionError, + ToolLedgerRejectionError, validateGenericToolLedgerAppend, validateToolLedgerEventLane, validateToolLedgerTransition,