@agimon-ai/doompi 0.0.1-alpha.113 → 0.0.1-alpha.115

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 (40) hide show
  1. package/dist/extensions/terminalChildSession.cjs +1 -0
  2. package/dist/extensions/terminalChildSession.cjs.map +1 -1
  3. package/dist/extensions/terminalChildSession.d.mts.map +1 -1
  4. package/dist/extensions/terminalChildSession.mjs +2 -1
  5. package/dist/extensions/terminalChildSession.mjs.map +1 -1
  6. package/dist/src/builders/hooks/index.cjs +95 -0
  7. package/dist/src/builders/hooks/index.cjs.map +1 -0
  8. package/dist/src/builders/hooks/index.mjs +89 -0
  9. package/dist/src/builders/hooks/index.mjs.map +1 -0
  10. package/dist/src/builders/server/runtime.cjs +3 -1
  11. package/dist/src/builders/server/runtime.cjs.map +1 -1
  12. package/dist/src/builders/server/runtime.mjs +4 -2
  13. package/dist/src/builders/server/runtime.mjs.map +1 -1
  14. package/dist/src/cli/commands/sync/index.cjs +13 -4
  15. package/dist/src/cli/commands/sync/index.cjs.map +1 -1
  16. package/dist/src/cli/commands/sync/index.d.mts.map +1 -1
  17. package/dist/src/cli/commands/sync/index.mjs +9 -0
  18. package/dist/src/cli/commands/sync/index.mjs.map +1 -1
  19. package/dist/src/cli/commands/sync/inspection.cjs +1 -0
  20. package/dist/src/cli/commands/sync/inspection.cjs.map +1 -1
  21. package/dist/src/cli/commands/sync/inspection.d.mts.map +1 -1
  22. package/dist/src/cli/commands/sync/inspection.mjs +1 -0
  23. package/dist/src/cli/commands/sync/inspection.mjs.map +1 -1
  24. package/dist/src/compiler/index.cjs +13 -0
  25. package/dist/src/compiler/index.cjs.map +1 -1
  26. package/dist/src/compiler/index.mjs +13 -0
  27. package/dist/src/compiler/index.mjs.map +1 -1
  28. package/dist/src/composition/harnessState/index.d.mts.map +1 -1
  29. package/dist/src/composition/syncDrift/index.cjs +27 -0
  30. package/dist/src/composition/syncDrift/index.cjs.map +1 -1
  31. package/dist/src/composition/syncDrift/index.d.mts.map +1 -1
  32. package/dist/src/composition/syncDrift/index.mjs +27 -1
  33. package/dist/src/composition/syncDrift/index.mjs.map +1 -1
  34. package/dist/src/composition/syncState/index.cjs +2 -1
  35. package/dist/src/composition/syncState/index.cjs.map +1 -1
  36. package/dist/src/composition/syncState/index.d.mts +1 -1
  37. package/dist/src/composition/syncState/index.d.mts.map +1 -1
  38. package/dist/src/composition/syncState/index.mjs +2 -1
  39. package/dist/src/composition/syncState/index.mjs.map +1 -1
  40. package/package.json +29 -29
@@ -125,6 +125,31 @@ function mcpBundleIsFresh(state, registration) {
125
125
  function mcpBundleIsRuntimeUsable(state, registration) {
126
126
  return mcpBundleIsUsable(state, registration, false);
127
127
  }
128
+ /** Validate hook artifacts and, for sync checks, their complete imported source graph. */
129
+ function hookModulesAreFresh(state, generationRoot, requireFreshSources = true) {
130
+ const reference = state.fileState.hookModules;
131
+ if (!reference) return true;
132
+ try {
133
+ const root = fs.realpathSync(generationRoot);
134
+ const inside = (target) => {
135
+ const relative = path.relative(root, fs.realpathSync(target));
136
+ return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
137
+ };
138
+ if (!inside(reference.file)) return false;
139
+ const descriptor = JSON.parse(fs.readFileSync(reference.file, "utf8"));
140
+ if (descriptor.version !== 1 || !Array.isArray(descriptor.modules)) return false;
141
+ for (const module of descriptor.modules) {
142
+ if (!inside(module.artifact) || module.receipt.output !== module.artifact) return false;
143
+ if (!artifactReceiptIsIntact(module.receipt, inside)) return false;
144
+ const inputs = Array.isArray(module.receipt.inputs) ? module.receipt.inputs.map(parseInputFingerprint) : [];
145
+ if (inputs.length === 0 || inputs.some((input) => input === void 0)) return false;
146
+ if (requireFreshSources && !inputsAreFresh(inputs)) return false;
147
+ }
148
+ return true;
149
+ } catch {
150
+ return false;
151
+ }
152
+ }
128
153
  /**
129
154
  * Whether this repository is synced for the composition it would launch.
130
155
  *
@@ -170,6 +195,7 @@ function readSyncDrift(options) {
170
195
  reasons.push("runtime-stale");
171
196
  }
172
197
  if (registration.webDirectory === null && options.requireWebBundle || registration.webDirectory !== null && (!fs.existsSync(path.join(registration.webDirectory, "index.html")) || !fs.existsSync(path.join(path.dirname(registration.webDirectory), "plugins", "composition.js")) || !fs.existsSync(path.join(path.dirname(registration.webDirectory), "plugins", "manifest.json")))) reasons.push("cockpit-bundle-missing");
198
+ if (!hookModulesAreFresh(state, registration.generationRoot, requireFreshSources)) reasons.push("runtime-stale");
173
199
  if (!fs.existsSync(registration.apiDirectory)) reasons.push("package-apis-missing");
174
200
  if (!(requireFreshSources ? serverBundleIsFresh(state, registration) : serverBundleIsRuntimeUsable(state, registration))) reasons.push("server-bundle-stale");
175
201
  if (!(requireFreshSources ? mcpBundleIsFresh(state, registration) : mcpBundleIsRuntimeUsable(state, registration))) reasons.push("mcp-bundle-stale");
@@ -196,6 +222,6 @@ function describeSyncDrift(drift) {
196
222
  return drift.reasons.map((reason) => detail[reason]).join(", ");
197
223
  }
198
224
  //#endregion
199
- export { describeSyncDrift, mcpBundleIsFresh, mcpBundleIsRuntimeUsable, readSyncDrift, serverBundleIsFresh, serverBundleIsRuntimeUsable };
225
+ export { describeSyncDrift, hookModulesAreFresh, mcpBundleIsFresh, mcpBundleIsRuntimeUsable, readSyncDrift, serverBundleIsFresh, serverBundleIsRuntimeUsable };
200
226
 
201
227
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/composition/syncDrift/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport { parseCompiledContracts } from '@agimon-ai/doompi-core/apiContracts';\nimport { parseDoomMcpBundle } from '@agimon-ai/doompi-core/mcpFacet';\nimport { parseDoomServerBundle } from '@agimon-ai/doompi-core/serverFacet';\nimport { readSyncRegistration, type SyncRegistration } from '@agimon-ai/doompi-core/syncRegistration';\n\nimport { readStartupBootstrapStatus, readBootstrapStatus } from '../../builders/cli/bootstrapLocator';\nimport { inputsAreFresh, parseInputFingerprint } from '../../compiler/inputs';\nimport { EXTENSION_COMPILER_VERSION } from '../../compiler/version';\nimport {\n computeInputsHash,\n computeMcpSourcesHash,\n computeServerSourcesHash,\n computeWebSourcesHash,\n readSyncState,\n type SyncState,\n} from '../syncState';\n\nexport type SyncDriftReason =\n | 'never-synced'\n | 'configuration-changed'\n | 'code-changed'\n | 'runtime-stale'\n | 'cockpit-bundle-missing'\n | 'package-apis-missing'\n | 'server-bundle-stale'\n | 'mcp-bundle-stale';\n\nexport interface SyncDrift {\n /** True when nothing needs syncing before a session starts. */\n fresh: boolean;\n reasons: SyncDriftReason[];\n /** The recorded inputs hash, for a caller that wants to log what moved. */\n recordedInputsHash?: string;\n currentInputsHash?: string;\n}\n\nexport interface ReadSyncDriftOptions {\n repoRoot: string;\n environment?: NodeJS.ProcessEnv;\n /** Launcher-owned Doom entry used to build this repository's generated bootstrap. */\n expectedBootstrapEntry?: string;\n homeDirectory?: string;\n /** Web hosts cannot reuse a CLI-only generation without plugin artifacts. */\n requireWebBundle?: boolean;\n /** Ignore producer source drift while retaining generation and artifact checks. */\n requireFreshSources?: boolean;\n}\n\nfunction artifactReceiptIsIntact(receipt: Record<string, unknown>, inside: (target: string) => boolean): boolean {\n if (\n receipt.version !== EXTENSION_COMPILER_VERSION ||\n typeof receipt.output !== 'string' ||\n !Array.isArray(receipt.artifacts) ||\n !Array.isArray(receipt.artifactInputs)\n ) {\n return false;\n }\n if (receipt.artifactInputs.length === 0 || receipt.artifacts.some((file) => typeof file !== 'string')) return false;\n const expected = new Set([receipt.output, ...(receipt.artifacts as string[])].map((file) => fs.realpathSync(file)));\n const seen = new Set<string>();\n for (const value of receipt.artifactInputs) {\n const input = parseInputFingerprint(value);\n if (!input || !/^[a-f0-9]{64}$/u.test(input.sha256) || !inside(input.path)) return false;\n const target = fs.realpathSync(input.path);\n if (!expected.has(target)) return false;\n const stat = fs.statSync(target);\n if (!stat.isFile() || stat.size !== input.size) return false;\n if (crypto.createHash('sha256').update(fs.readFileSync(target)).digest('hex') !== input.sha256) return false;\n seen.add(target);\n }\n return seen.size === expected.size;\n}\n\nfunction serverBundleIsUsable(\n state: Pick<SyncState, 'serverBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'serverBundle'>,\n requireFreshSources: boolean,\n): boolean {\n const bundle = state.serverBundle;\n if (!bundle || !registration.serverBundle) return false;\n try {\n if (requireFreshSources && bundle.sourcesHash !== computeServerSourcesHash(state.resolved)) return false;\n const descriptorPath = fs.realpathSync(bundle.descriptorPath);\n if (descriptorPath !== fs.realpathSync(registration.serverBundle.path)) return false;\n const descriptor = parseDoomServerBundle(JSON.parse(fs.readFileSync(descriptorPath, 'utf8')));\n if (descriptor.generation !== registration.generation || descriptor.fingerprint !== bundle.fingerprint)\n return false;\n\n const root = fs.realpathSync(registration.generationRoot);\n const inside = (target: string) => {\n const relative = path.relative(root, fs.realpathSync(target));\n return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));\n };\n if (!descriptor.contracts) return false;\n const contractFile = path.resolve(path.dirname(descriptorPath), descriptor.contracts.file);\n if (!inside(contractFile)) return false;\n const bytes = fs.readFileSync(contractFile);\n if (crypto.createHash('sha256').update(bytes).digest('hex') !== descriptor.contracts.sha256) return false;\n const contracts = parseCompiledContracts(JSON.parse(bytes.toString('utf8')));\n if (contracts.generation !== descriptor.generation || contracts.fingerprint !== descriptor.fingerprint)\n return false;\n const outputs = [\n ...descriptor.entries.map((entry) => ({ key: entry.packageName, module: entry.module })),\n ...contracts.packages.flatMap((entry) =>\n entry.module ? [{ key: `${entry.packageName}#contracts`, module: entry.module }] : [],\n ),\n ];\n if (Object.keys(bundle.compilerManifests).length !== outputs.length) return false;\n for (const entry of outputs) {\n const manifestPath = bundle.compilerManifests[entry.key];\n if (!manifestPath || !inside(manifestPath)) return false;\n const receipt = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as Record<string, unknown>;\n if (\n typeof receipt.output !== 'string' ||\n !inside(receipt.output) ||\n fs.realpathSync(receipt.output) !== fs.realpathSync(path.resolve(path.dirname(descriptorPath), entry.module)) ||\n !Array.isArray(receipt.artifacts) ||\n !receipt.artifacts.every((file) => typeof file === 'string' && inside(file))\n )\n return false;\n const inputs = Array.isArray(receipt.inputs) ? receipt.inputs.map(parseInputFingerprint) : [];\n if (inputs.length === 0 || inputs.some((input) => input === undefined)) return false;\n if (requireFreshSources && !inputsAreFresh(inputs as NonNullable<(typeof inputs)[number]>[])) return false;\n if (!artifactReceiptIsIntact(receipt, inside)) return false;\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/** Validate direct-module receipts without importing candidates or loading the compiler. */\nexport function serverBundleIsFresh(\n state: Pick<SyncState, 'serverBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'serverBundle'>,\n): boolean {\n return serverBundleIsUsable(state, registration, true);\n}\n\n/** Validate generated server artifacts while allowing the producer source to drift. */\nexport function serverBundleIsRuntimeUsable(\n state: Pick<SyncState, 'serverBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'serverBundle'>,\n): boolean {\n return serverBundleIsUsable(state, registration, false);\n}\n\nfunction mcpBundleIsUsable(\n state: Pick<SyncState, 'mcpBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'mcpBundle'>,\n requireFreshSources: boolean,\n): boolean {\n const bundle = state.mcpBundle;\n if (!bundle || !registration.mcpBundle) return false;\n try {\n if (requireFreshSources && bundle.sourcesHash !== computeMcpSourcesHash(state.resolved)) return false;\n const descriptorPath = fs.realpathSync(bundle.descriptorPath);\n if (descriptorPath !== fs.realpathSync(registration.mcpBundle.path)) return false;\n const descriptorBytes = fs.readFileSync(descriptorPath);\n if (crypto.createHash('sha256').update(descriptorBytes).digest('hex') !== registration.mcpBundle.sha256)\n return false;\n const descriptor = parseDoomMcpBundle(JSON.parse(descriptorBytes.toString('utf8')));\n if (\n descriptor.generation !== registration.generation ||\n descriptor.fingerprint !== bundle.fingerprint ||\n descriptor.fingerprint !== registration.mcpBundle.fingerprint\n )\n return false;\n\n const root = fs.realpathSync(registration.generationRoot);\n const inside = (target: string) => {\n const relative = path.relative(root, fs.realpathSync(target));\n return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));\n };\n if (descriptor.ui) {\n const uiFile = path.resolve(path.dirname(descriptorPath), descriptor.ui.file);\n if (\n !inside(uiFile) ||\n crypto.createHash('sha256').update(fs.readFileSync(uiFile)).digest('hex') !== descriptor.ui.sha256\n )\n return false;\n if (\n requireFreshSources &&\n descriptor.ui.inputs.some(\n (input) =>\n !fs.existsSync(input.path) ||\n crypto.createHash('sha256').update(fs.readFileSync(input.path)).digest('hex') !== input.sha256,\n )\n )\n return false;\n }\n if (Object.keys(bundle.compilerManifests).length !== descriptor.entries.length) return false;\n for (const entry of descriptor.entries) {\n const manifestPath = bundle.compilerManifests[entry.packageName];\n if (!manifestPath || !inside(manifestPath)) return false;\n const receipt = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as Record<string, unknown>;\n const modulePath = path.resolve(path.dirname(descriptorPath), entry.module);\n if (\n typeof receipt.output !== 'string' ||\n !inside(receipt.output) ||\n fs.realpathSync(receipt.output) !== fs.realpathSync(modulePath) ||\n crypto.createHash('sha256').update(fs.readFileSync(modulePath)).digest('hex') !== entry.sha256 ||\n !Array.isArray(receipt.artifacts) ||\n !receipt.artifacts.every((file) => typeof file === 'string' && inside(file))\n )\n return false;\n const inputs = Array.isArray(receipt.inputs) ? receipt.inputs.map(parseInputFingerprint) : [];\n if (inputs.length === 0 || inputs.some((input) => input === undefined)) return false;\n if (requireFreshSources && !inputsAreFresh(inputs as NonNullable<(typeof inputs)[number]>[])) return false;\n if (!artifactReceiptIsIntact(receipt, inside)) return false;\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/** Validate MCP source inputs, descriptor identity, and compiler artifact receipts. */\nexport function mcpBundleIsFresh(\n state: Pick<SyncState, 'mcpBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'mcpBundle'>,\n): boolean {\n return mcpBundleIsUsable(state, registration, true);\n}\n\n/** Validate admitted MCP artifacts while allowing producer sources to drift. */\nexport function mcpBundleIsRuntimeUsable(\n state: Pick<SyncState, 'mcpBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'mcpBundle'>,\n): boolean {\n return mcpBundleIsUsable(state, registration, false);\n}\n\n/**\n * Whether this repository is synced for the composition it would launch.\n *\n * Sync produces three things a session or the cockpit reads later: the\n * resolved composition, the plugin bundle the browser loads, and the package\n * API routes each host mounts. A session started against any of them stale\n * runs, but quietly wrong: the cockpit shows no plugin surfaces and package\n * APIs answer nothing, with nothing in the log to say why.\n *\n * The hash is the one sync already records. It covers every `.doom` document\n * in both the repository and the home directory, the MCP configuration, the\n * plugin catalogue, and each profile's persona files, so an edit to any of\n * them reads as drift without this having to know what changed.\n */\nexport function readSyncDrift(options: ReadSyncDriftOptions): SyncDrift {\n const homeDirectory = options.homeDirectory ?? os.homedir();\n const requireFreshSources = options.requireFreshSources ?? true;\n const reasons: SyncDriftReason[] = [];\n\n let state: SyncState | undefined;\n let registration: ReturnType<typeof readSyncRegistration>;\n try {\n registration = readSyncRegistration(options.repoRoot, homeDirectory);\n state = registration ? readSyncState(options.repoRoot, homeDirectory) : undefined;\n } catch {\n // Unreadable or invalid registration is indistinguishable from absent for\n // this purpose: the next session needs a sync before it can be trusted.\n state = undefined;\n registration = undefined;\n }\n if (!state || !registration) return { fresh: false, reasons: ['never-synced'] };\n\n let currentInputsHash: string | undefined;\n try {\n currentInputsHash = computeInputsHash(options.repoRoot, state.selection, homeDirectory, options.environment);\n } catch {\n // A malformed document cannot be hashed, and syncing is what reports it.\n reasons.push('configuration-changed');\n }\n if (currentInputsHash !== undefined && currentInputsHash !== state.inputsHash) {\n reasons.push('configuration-changed');\n }\n // Cockpit sources are compiled straight from each package's web/ folder, so a\n // rebuilt plugin surface is a real change that no configuration hash sees. A\n // state recorded before this was tracked has nothing to compare and is left\n // alone rather than being called stale on sight.\n if (\n requireFreshSources &&\n state.webSourcesHash !== undefined &&\n computeWebSourcesHash(state.resolved) !== state.webSourcesHash\n ) {\n reasons.push('code-changed');\n }\n // The same question the `--check` path asks, so the cockpit and the CLI\n // cannot disagree about whether one repository is synced.\n try {\n const bootstrapStatus = requireFreshSources\n ? readBootstrapStatus(options.repoRoot, options.expectedBootstrapEntry, homeDirectory)\n : readStartupBootstrapStatus(options.repoRoot, options.expectedBootstrapEntry, homeDirectory);\n if (!bootstrapStatus.fresh) reasons.push('runtime-stale');\n } catch {\n // An unreadable bootstrap record is exactly as unusable as a stale one, and\n // syncing is what reports the underlying cause.\n reasons.push('runtime-stale');\n }\n if (\n (registration.webDirectory === null && options.requireWebBundle) ||\n (registration.webDirectory !== null &&\n (!fs.existsSync(path.join(registration.webDirectory, 'index.html')) ||\n !fs.existsSync(path.join(path.dirname(registration.webDirectory), 'plugins', 'composition.js')) ||\n !fs.existsSync(path.join(path.dirname(registration.webDirectory), 'plugins', 'manifest.json'))))\n ) {\n reasons.push('cockpit-bundle-missing');\n }\n if (!fs.existsSync(registration.apiDirectory)) reasons.push('package-apis-missing');\n if (\n !(requireFreshSources ? serverBundleIsFresh(state, registration) : serverBundleIsRuntimeUsable(state, registration))\n )\n reasons.push('server-bundle-stale');\n if (!(requireFreshSources ? mcpBundleIsFresh(state, registration) : mcpBundleIsRuntimeUsable(state, registration)))\n reasons.push('mcp-bundle-stale');\n\n return {\n fresh: reasons.length === 0,\n reasons,\n recordedInputsHash: state.inputsHash,\n ...(currentInputsHash === undefined ? {} : { currentInputsHash }),\n };\n}\n\n/** A one-line account of what drifted, for a log the person running the hub reads. */\nexport function describeSyncDrift(drift: SyncDrift): string {\n if (drift.fresh) return 'the repository is synced';\n const detail: Record<SyncDriftReason, string> = {\n 'never-synced': 'it has never been synced',\n 'configuration-changed': 'its configuration changed since the last sync',\n 'code-changed': 'its cockpit sources changed since the last sync',\n 'runtime-stale': 'its precompiled runtime is out of date',\n 'cockpit-bundle-missing': 'the cockpit bundle is missing',\n 'package-apis-missing': 'the package API routes are missing',\n 'server-bundle-stale': 'its server bundle is missing or out of date',\n 'mcp-bundle-stale': 'its MCP bundle is missing or out of date',\n };\n return drift.reasons.map((reason) => detail[reason]).join(', ');\n}\n"],"mappings":";;;;;;;;;;;;AAqDA,SAAS,wBAAwB,SAAkC,QAA8C;CAC/G,IACE,QAAQ,YAAA,SACR,OAAO,QAAQ,WAAW,YAC1B,CAAC,MAAM,QAAQ,QAAQ,SAAS,KAChC,CAAC,MAAM,QAAQ,QAAQ,cAAc,GAErC,OAAO;CAET,IAAI,QAAQ,eAAe,WAAW,KAAK,QAAQ,UAAU,MAAM,SAAS,OAAO,SAAS,QAAQ,GAAG,OAAO;CAC9G,MAAM,WAAW,IAAI,IAAI,CAAC,QAAQ,QAAQ,GAAI,QAAQ,SAAsB,CAAC,CAAC,KAAK,SAAS,GAAG,aAAa,IAAI,CAAC,CAAC;CAClH,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,SAAS,QAAQ,gBAAgB;EAC1C,MAAM,QAAQ,sBAAsB,KAAK;EACzC,IAAI,CAAC,SAAS,CAAC,kBAAkB,KAAK,MAAM,MAAM,KAAK,CAAC,OAAO,MAAM,IAAI,GAAG,OAAO;EACnF,MAAM,SAAS,GAAG,aAAa,MAAM,IAAI;EACzC,IAAI,CAAC,SAAS,IAAI,MAAM,GAAG,OAAO;EAClC,MAAM,OAAO,GAAG,SAAS,MAAM;EAC/B,IAAI,CAAC,KAAK,OAAO,KAAK,KAAK,SAAS,MAAM,MAAM,OAAO;EACvD,IAAI,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,GAAG,aAAa,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK,MAAM,MAAM,QAAQ,OAAO;EACvG,KAAK,I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AAC,GAAG,WAAW,aAAa,YAAY,GAAG,QAAQ,KAAK,sBAAsB;CAClF,IACE,EAAE,sBAAsB,oBAAoB,OAAO,YAAY,IAAI,4BAA4B,OAAO,YAAY,IAElH,QAAQ,KAAK,qBAAqB;CACpC,IAAI,EAAE,sBAAsB,iBAAiB,OAAO,YAAY,IAAI,yBAAyB,OAAO,YAAY,IAC9G,QAAQ,KAAK,kBAAkB;CAEjC,OAAO;EACL,OAAO,QAAQ,WAAW;EAC1B;EACA,oBAAoB,MAAM;EAC1B,GAAI,sBAAsB,KAAA,IAAY,CAAC,IAAI,EAAE,kBAAkB;CACjE;AACF;;AAGA,SAAgB,kBAAkB,OAA0B;CAC1D,IAAI,MAAM,OAAO,OAAO;CACxB,MAAM,SAA0C;EAC9C,gBAAgB;EAChB,yBAAyB;EACzB,gBAAgB;EAChB,iBAAiB;EACjB,0BAA0B;EAC1B,wBAAwB;EACxB,uBAAuB;EACvB,oBAAoB;CACtB;CACA,OAAO,MAAM,QAAQ,KAAK,WAAW,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI;AAChE"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/composition/syncDrift/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport { parseCompiledContracts } from '@agimon-ai/doompi-core/apiContracts';\nimport { parseDoomMcpBundle } from '@agimon-ai/doompi-core/mcpFacet';\nimport { parseDoomServerBundle } from '@agimon-ai/doompi-core/serverFacet';\nimport { readSyncRegistration, type SyncRegistration } from '@agimon-ai/doompi-core/syncRegistration';\n\nimport { readStartupBootstrapStatus, readBootstrapStatus } from '../../builders/cli/bootstrapLocator';\nimport { inputsAreFresh, parseInputFingerprint } from '../../compiler/inputs';\nimport { EXTENSION_COMPILER_VERSION } from '../../compiler/version';\nimport {\n computeInputsHash,\n computeMcpSourcesHash,\n computeServerSourcesHash,\n computeWebSourcesHash,\n readSyncState,\n type SyncState,\n} from '../syncState';\n\nexport type SyncDriftReason =\n | 'never-synced'\n | 'configuration-changed'\n | 'code-changed'\n | 'runtime-stale'\n | 'cockpit-bundle-missing'\n | 'package-apis-missing'\n | 'server-bundle-stale'\n | 'mcp-bundle-stale';\n\nexport interface SyncDrift {\n /** True when nothing needs syncing before a session starts. */\n fresh: boolean;\n reasons: SyncDriftReason[];\n /** The recorded inputs hash, for a caller that wants to log what moved. */\n recordedInputsHash?: string;\n currentInputsHash?: string;\n}\n\nexport interface ReadSyncDriftOptions {\n repoRoot: string;\n environment?: NodeJS.ProcessEnv;\n /** Launcher-owned Doom entry used to build this repository's generated bootstrap. */\n expectedBootstrapEntry?: string;\n homeDirectory?: string;\n /** Web hosts cannot reuse a CLI-only generation without plugin artifacts. */\n requireWebBundle?: boolean;\n /** Ignore producer source drift while retaining generation and artifact checks. */\n requireFreshSources?: boolean;\n}\n\nfunction artifactReceiptIsIntact(receipt: Record<string, unknown>, inside: (target: string) => boolean): boolean {\n if (\n receipt.version !== EXTENSION_COMPILER_VERSION ||\n typeof receipt.output !== 'string' ||\n !Array.isArray(receipt.artifacts) ||\n !Array.isArray(receipt.artifactInputs)\n ) {\n return false;\n }\n if (receipt.artifactInputs.length === 0 || receipt.artifacts.some((file) => typeof file !== 'string')) return false;\n const expected = new Set([receipt.output, ...(receipt.artifacts as string[])].map((file) => fs.realpathSync(file)));\n const seen = new Set<string>();\n for (const value of receipt.artifactInputs) {\n const input = parseInputFingerprint(value);\n if (!input || !/^[a-f0-9]{64}$/u.test(input.sha256) || !inside(input.path)) return false;\n const target = fs.realpathSync(input.path);\n if (!expected.has(target)) return false;\n const stat = fs.statSync(target);\n if (!stat.isFile() || stat.size !== input.size) return false;\n if (crypto.createHash('sha256').update(fs.readFileSync(target)).digest('hex') !== input.sha256) return false;\n seen.add(target);\n }\n return seen.size === expected.size;\n}\n\nfunction serverBundleIsUsable(\n state: Pick<SyncState, 'serverBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'serverBundle'>,\n requireFreshSources: boolean,\n): boolean {\n const bundle = state.serverBundle;\n if (!bundle || !registration.serverBundle) return false;\n try {\n if (requireFreshSources && bundle.sourcesHash !== computeServerSourcesHash(state.resolved)) return false;\n const descriptorPath = fs.realpathSync(bundle.descriptorPath);\n if (descriptorPath !== fs.realpathSync(registration.serverBundle.path)) return false;\n const descriptor = parseDoomServerBundle(JSON.parse(fs.readFileSync(descriptorPath, 'utf8')));\n if (descriptor.generation !== registration.generation || descriptor.fingerprint !== bundle.fingerprint)\n return false;\n\n const root = fs.realpathSync(registration.generationRoot);\n const inside = (target: string) => {\n const relative = path.relative(root, fs.realpathSync(target));\n return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));\n };\n if (!descriptor.contracts) return false;\n const contractFile = path.resolve(path.dirname(descriptorPath), descriptor.contracts.file);\n if (!inside(contractFile)) return false;\n const bytes = fs.readFileSync(contractFile);\n if (crypto.createHash('sha256').update(bytes).digest('hex') !== descriptor.contracts.sha256) return false;\n const contracts = parseCompiledContracts(JSON.parse(bytes.toString('utf8')));\n if (contracts.generation !== descriptor.generation || contracts.fingerprint !== descriptor.fingerprint)\n return false;\n const outputs = [\n ...descriptor.entries.map((entry) => ({ key: entry.packageName, module: entry.module })),\n ...contracts.packages.flatMap((entry) =>\n entry.module ? [{ key: `${entry.packageName}#contracts`, module: entry.module }] : [],\n ),\n ];\n if (Object.keys(bundle.compilerManifests).length !== outputs.length) return false;\n for (const entry of outputs) {\n const manifestPath = bundle.compilerManifests[entry.key];\n if (!manifestPath || !inside(manifestPath)) return false;\n const receipt = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as Record<string, unknown>;\n if (\n typeof receipt.output !== 'string' ||\n !inside(receipt.output) ||\n fs.realpathSync(receipt.output) !== fs.realpathSync(path.resolve(path.dirname(descriptorPath), entry.module)) ||\n !Array.isArray(receipt.artifacts) ||\n !receipt.artifacts.every((file) => typeof file === 'string' && inside(file))\n )\n return false;\n const inputs = Array.isArray(receipt.inputs) ? receipt.inputs.map(parseInputFingerprint) : [];\n if (inputs.length === 0 || inputs.some((input) => input === undefined)) return false;\n if (requireFreshSources && !inputsAreFresh(inputs as NonNullable<(typeof inputs)[number]>[])) return false;\n if (!artifactReceiptIsIntact(receipt, inside)) return false;\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/** Validate direct-module receipts without importing candidates or loading the compiler. */\nexport function serverBundleIsFresh(\n state: Pick<SyncState, 'serverBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'serverBundle'>,\n): boolean {\n return serverBundleIsUsable(state, registration, true);\n}\n\n/** Validate generated server artifacts while allowing the producer source to drift. */\nexport function serverBundleIsRuntimeUsable(\n state: Pick<SyncState, 'serverBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'serverBundle'>,\n): boolean {\n return serverBundleIsUsable(state, registration, false);\n}\n\nfunction mcpBundleIsUsable(\n state: Pick<SyncState, 'mcpBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'mcpBundle'>,\n requireFreshSources: boolean,\n): boolean {\n const bundle = state.mcpBundle;\n if (!bundle || !registration.mcpBundle) return false;\n try {\n if (requireFreshSources && bundle.sourcesHash !== computeMcpSourcesHash(state.resolved)) return false;\n const descriptorPath = fs.realpathSync(bundle.descriptorPath);\n if (descriptorPath !== fs.realpathSync(registration.mcpBundle.path)) return false;\n const descriptorBytes = fs.readFileSync(descriptorPath);\n if (crypto.createHash('sha256').update(descriptorBytes).digest('hex') !== registration.mcpBundle.sha256)\n return false;\n const descriptor = parseDoomMcpBundle(JSON.parse(descriptorBytes.toString('utf8')));\n if (\n descriptor.generation !== registration.generation ||\n descriptor.fingerprint !== bundle.fingerprint ||\n descriptor.fingerprint !== registration.mcpBundle.fingerprint\n )\n return false;\n\n const root = fs.realpathSync(registration.generationRoot);\n const inside = (target: string) => {\n const relative = path.relative(root, fs.realpathSync(target));\n return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));\n };\n if (descriptor.ui) {\n const uiFile = path.resolve(path.dirname(descriptorPath), descriptor.ui.file);\n if (\n !inside(uiFile) ||\n crypto.createHash('sha256').update(fs.readFileSync(uiFile)).digest('hex') !== descriptor.ui.sha256\n )\n return false;\n if (\n requireFreshSources &&\n descriptor.ui.inputs.some(\n (input) =>\n !fs.existsSync(input.path) ||\n crypto.createHash('sha256').update(fs.readFileSync(input.path)).digest('hex') !== input.sha256,\n )\n )\n return false;\n }\n if (Object.keys(bundle.compilerManifests).length !== descriptor.entries.length) return false;\n for (const entry of descriptor.entries) {\n const manifestPath = bundle.compilerManifests[entry.packageName];\n if (!manifestPath || !inside(manifestPath)) return false;\n const receipt = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as Record<string, unknown>;\n const modulePath = path.resolve(path.dirname(descriptorPath), entry.module);\n if (\n typeof receipt.output !== 'string' ||\n !inside(receipt.output) ||\n fs.realpathSync(receipt.output) !== fs.realpathSync(modulePath) ||\n crypto.createHash('sha256').update(fs.readFileSync(modulePath)).digest('hex') !== entry.sha256 ||\n !Array.isArray(receipt.artifacts) ||\n !receipt.artifacts.every((file) => typeof file === 'string' && inside(file))\n )\n return false;\n const inputs = Array.isArray(receipt.inputs) ? receipt.inputs.map(parseInputFingerprint) : [];\n if (inputs.length === 0 || inputs.some((input) => input === undefined)) return false;\n if (requireFreshSources && !inputsAreFresh(inputs as NonNullable<(typeof inputs)[number]>[])) return false;\n if (!artifactReceiptIsIntact(receipt, inside)) return false;\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/** Validate MCP source inputs, descriptor identity, and compiler artifact receipts. */\nexport function mcpBundleIsFresh(\n state: Pick<SyncState, 'mcpBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'mcpBundle'>,\n): boolean {\n return mcpBundleIsUsable(state, registration, true);\n}\n\n/** Validate admitted MCP artifacts while allowing producer sources to drift. */\nexport function mcpBundleIsRuntimeUsable(\n state: Pick<SyncState, 'mcpBundle' | 'resolved'>,\n registration: Pick<SyncRegistration, 'generation' | 'generationRoot' | 'mcpBundle'>,\n): boolean {\n return mcpBundleIsUsable(state, registration, false);\n}\n\n/** Validate hook artifacts and, for sync checks, their complete imported source graph. */\nexport function hookModulesAreFresh(\n state: { fileState: Pick<SyncState['fileState'], 'hookModules'> },\n generationRoot: string,\n requireFreshSources = true,\n): boolean {\n const reference = state.fileState.hookModules;\n if (!reference) return true;\n try {\n const root = fs.realpathSync(generationRoot);\n const inside = (target: string): boolean => {\n const relative = path.relative(root, fs.realpathSync(target));\n return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));\n };\n if (!inside(reference.file)) return false;\n const descriptor = JSON.parse(fs.readFileSync(reference.file, 'utf8')) as {\n version: number;\n modules: Array<{ artifact: string; receipt: Record<string, unknown> }>;\n };\n if (descriptor.version !== 1 || !Array.isArray(descriptor.modules)) return false;\n for (const module of descriptor.modules) {\n if (!inside(module.artifact) || module.receipt.output !== module.artifact) return false;\n if (!artifactReceiptIsIntact(module.receipt, inside)) return false;\n const inputs = Array.isArray(module.receipt.inputs) ? module.receipt.inputs.map(parseInputFingerprint) : [];\n if (inputs.length === 0 || inputs.some((input) => input === undefined)) return false;\n if (requireFreshSources && !inputsAreFresh(inputs as NonNullable<(typeof inputs)[number]>[])) return false;\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Whether this repository is synced for the composition it would launch.\n *\n * Sync produces three things a session or the cockpit reads later: the\n * resolved composition, the plugin bundle the browser loads, and the package\n * API routes each host mounts. A session started against any of them stale\n * runs, but quietly wrong: the cockpit shows no plugin surfaces and package\n * APIs answer nothing, with nothing in the log to say why.\n *\n * The hash is the one sync already records. It covers every `.doom` document\n * in both the repository and the home directory, the MCP configuration, the\n * plugin catalogue, and each profile's persona files, so an edit to any of\n * them reads as drift without this having to know what changed.\n */\nexport function readSyncDrift(options: ReadSyncDriftOptions): SyncDrift {\n const homeDirectory = options.homeDirectory ?? os.homedir();\n const requireFreshSources = options.requireFreshSources ?? true;\n const reasons: SyncDriftReason[] = [];\n\n let state: SyncState | undefined;\n let registration: ReturnType<typeof readSyncRegistration>;\n try {\n registration = readSyncRegistration(options.repoRoot, homeDirectory);\n state = registration ? readSyncState(options.repoRoot, homeDirectory) : undefined;\n } catch {\n // Unreadable or invalid registration is indistinguishable from absent for\n // this purpose: the next session needs a sync before it can be trusted.\n state = undefined;\n registration = undefined;\n }\n if (!state || !registration) return { fresh: false, reasons: ['never-synced'] };\n\n let currentInputsHash: string | undefined;\n try {\n currentInputsHash = computeInputsHash(options.repoRoot, state.selection, homeDirectory, options.environment);\n } catch {\n // A malformed document cannot be hashed, and syncing is what reports it.\n reasons.push('configuration-changed');\n }\n if (currentInputsHash !== undefined && currentInputsHash !== state.inputsHash) {\n reasons.push('configuration-changed');\n }\n // Cockpit sources are compiled straight from each package's web/ folder, so a\n // rebuilt plugin surface is a real change that no configuration hash sees. A\n // state recorded before this was tracked has nothing to compare and is left\n // alone rather than being called stale on sight.\n if (\n requireFreshSources &&\n state.webSourcesHash !== undefined &&\n computeWebSourcesHash(state.resolved) !== state.webSourcesHash\n ) {\n reasons.push('code-changed');\n }\n // The same question the `--check` path asks, so the cockpit and the CLI\n // cannot disagree about whether one repository is synced.\n try {\n const bootstrapStatus = requireFreshSources\n ? readBootstrapStatus(options.repoRoot, options.expectedBootstrapEntry, homeDirectory)\n : readStartupBootstrapStatus(options.repoRoot, options.expectedBootstrapEntry, homeDirectory);\n if (!bootstrapStatus.fresh) reasons.push('runtime-stale');\n } catch {\n // An unreadable bootstrap record is exactly as unusable as a stale one, and\n // syncing is what reports the underlying cause.\n reasons.push('runtime-stale');\n }\n if (\n (registration.webDirectory === null && options.requireWebBundle) ||\n (registration.webDirectory !== null &&\n (!fs.existsSync(path.join(registration.webDirectory, 'index.html')) ||\n !fs.existsSync(path.join(path.dirname(registration.webDirectory), 'plugins', 'composition.js')) ||\n !fs.existsSync(path.join(path.dirname(registration.webDirectory), 'plugins', 'manifest.json'))))\n ) {\n reasons.push('cockpit-bundle-missing');\n }\n if (!hookModulesAreFresh(state, registration.generationRoot, requireFreshSources)) reasons.push('runtime-stale');\n if (!fs.existsSync(registration.apiDirectory)) reasons.push('package-apis-missing');\n if (\n !(requireFreshSources ? serverBundleIsFresh(state, registration) : serverBundleIsRuntimeUsable(state, registration))\n )\n reasons.push('server-bundle-stale');\n if (!(requireFreshSources ? mcpBundleIsFresh(state, registration) : mcpBundleIsRuntimeUsable(state, registration)))\n reasons.push('mcp-bundle-stale');\n\n return {\n fresh: reasons.length === 0,\n reasons,\n recordedInputsHash: state.inputsHash,\n ...(currentInputsHash === undefined ? {} : { currentInputsHash }),\n };\n}\n\n/** A one-line account of what drifted, for a log the person running the hub reads. */\nexport function describeSyncDrift(drift: SyncDrift): string {\n if (drift.fresh) return 'the repository is synced';\n const detail: Record<SyncDriftReason, string> = {\n 'never-synced': 'it has never been synced',\n 'configuration-changed': 'its configuration changed since the last sync',\n 'code-changed': 'its cockpit sources changed since the last sync',\n 'runtime-stale': 'its precompiled runtime is out of date',\n 'cockpit-bundle-missing': 'the cockpit bundle is missing',\n 'package-apis-missing': 'the package API routes are missing',\n 'server-bundle-stale': 'its server bundle is missing or out of date',\n 'mcp-bundle-stale': 'its MCP bundle is missing or out of date',\n };\n return drift.reasons.map((reason) => detail[reason]).join(', ');\n}\n"],"mappings":";;;;;;;;;;;;AAqDA,SAAS,wBAAwB,SAAkC,QAA8C;CAC/G,IACE,QAAQ,YAAA,SACR,OAAO,QAAQ,WAAW,YAC1B,CAAC,MAAM,QAAQ,QAAQ,SAAS,KAChC,CAAC,MAAM,QAAQ,QAAQ,cAAc,GAErC,OAAO;CAET,IAAI,QAAQ,eAAe,WAAW,KAAK,QAAQ,UAAU,MAAM,SAAS,OAAO,SAAS,QAAQ,GAAG,OAAO;CAC9G,MAAM,WAAW,IAAI,IAAI,CAAC,QAAQ,QAAQ,GAAI,QAAQ,SAAsB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aAAa,iBAAiB,QAAQ,QAAQ,oBAC9C,aAAa,iBAAiB,SAC5B,CAAC,GAAG,WAAW,KAAK,KAAK,aAAa,cAAc,YAAY,CAAC,KAChE,CAAC,GAAG,WAAW,KAAK,KAAK,KAAK,QAAQ,aAAa,YAAY,GAAG,WAAW,gBAAgB,CAAC,KAC9F,CAAC,GAAG,WAAW,KAAK,KAAK,KAAK,QAAQ,aAAa,YAAY,GAAG,WAAW,eAAe,CAAC,IAEjG,QAAQ,KAAK,wBAAwB;CAEvC,IAAI,CAAC,oBAAoB,OAAO,aAAa,gBAAgB,mBAAmB,GAAG,QAAQ,KAAK,eAAe;CAC/G,IAAI,CAAC,GAAG,WAAW,aAAa,YAAY,GAAG,QAAQ,KAAK,sBAAsB;CAClF,IACE,EAAE,sBAAsB,oBAAoB,OAAO,YAAY,IAAI,4BAA4B,OAAO,YAAY,IAElH,QAAQ,KAAK,qBAAqB;CACpC,IAAI,EAAE,sBAAsB,iBAAiB,OAAO,YAAY,IAAI,yBAAyB,OAAO,YAAY,IAC9G,QAAQ,KAAK,kBAAkB;CAEjC,OAAO;EACL,OAAO,QAAQ,WAAW;EAC1B;EACA,oBAAoB,MAAM;EAC1B,GAAI,sBAAsB,KAAA,IAAY,CAAC,IAAI,EAAE,kBAAkB;CACjE;AACF;;AAGA,SAAgB,kBAAkB,OAA0B;CAC1D,IAAI,MAAM,OAAO,OAAO;CACxB,MAAM,SAA0C;EAC9C,gBAAgB;EAChB,yBAAyB;EACzB,gBAAgB;EAChB,iBAAiB;EACjB,0BAA0B;EAC1B,wBAAwB;EACxB,uBAAuB;EACvB,oBAAoB;CACtB;CACA,OAAO,MAAM,QAAQ,KAAK,WAAW,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI;AAChE"}
@@ -372,7 +372,8 @@ function parseSyncState(source, statePath, options) {
372
372
  fileState: {
373
373
  profileEnvironment: (0, _agimon_ai_doompi_core_runtimeJson.isRecord)(fileState.profileEnvironment) ? fileState.profileEnvironment : {},
374
374
  pluginHooks: Array.isArray(fileState.pluginHooks) ? fileState.pluginHooks : [],
375
- mcpProjection: fileState.mcpProjection
375
+ mcpProjection: fileState.mcpProjection,
376
+ ...(0, _agimon_ai_doompi_core_runtimeJson.isRecord)(fileState.hookModules) && typeof fileState.hookModules.file === "string" ? { hookModules: { file: fileState.hookModules.file } } : {}
376
377
  },
377
378
  resolved: stringRecord(parsed.resolved, "resolved", statePath),
378
379
  compiled,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["os","resolveSyncLocation","readSyncRegistration","path","fs","crypto","isRecord","loadDomains","resolvePluginEntries","loadProfiles","PERSONA_FILES","PRECOMPILE_STATE_VERSION","SYNC_STATE_VERSION","isDoomMcpProjection","LAYER_RESOLVERS","PERSONA_ENTRY","OLLAMA_PRESET"],"sources":["../../../../src/composition/syncState/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport { loadDomains, resolvePluginEntries } from '@agimon-ai/doompi-config/domains';\nimport type { LayerResolvers, MajorModesConfig } from '@agimon-ai/doompi-config/majorModes';\nimport { loadProfiles, PERSONA_FILES } from '@agimon-ai/doompi-config/profiles';\nimport type { HarnessState } from '@agimon-ai/doompi-config/types';\nimport { isDoomMcpProjection, type DoomMcpProjection } from '@agimon-ai/doompi-core/mcpProjection';\nimport { isRecord } from '@agimon-ai/doompi-core/runtimeJson';\nimport type { JsonObject } from '@agimon-ai/doompi-core/runtimeJson';\nimport {\n assertSyncLocationSafe,\n resolveSyncLocation,\n type SyncIdentity,\n type SyncLocation,\n} from '@agimon-ai/doompi-core/syncLocation';\nimport {\n readSyncRegistration,\n validateSyncRegistration,\n type SyncRegistration,\n} from '@agimon-ai/doompi-core/syncRegistration';\nimport { PRECOMPILE_STATE_VERSION, SYNC_STATE_VERSION } from '@agimon-ai/doompi-core/syncStateContract';\n\nimport {\n assembleChildExtensions,\n assembleExtensions,\n type ExtensionLayerResolvers,\n LAYER_RESOLVERS,\n OLLAMA_PRESET,\n PERSONA_ENTRY,\n} from '../../builders/cli/extensionAssembler';\n\nexport { SYNC_STATE_VERSION } from '@agimon-ai/doompi-core/syncStateContract';\n\n/**\n * The file `doom-pi sync` writes and the doom-pi Pi extension reads back.\n *\n * This is the whole contract between the two halves of the synced path. Sync\n * runs in plain Node, where module resolution and the repository config are\n * available; the extension runs inside a Pi session, where neither can be\n * relied on. Everything the extension needs is therefore resolved once here,\n * and everything in this file has to survive JSON.\n */\n\nconst PI_DIRECTORY = '.pi';\n/** The `.doom` config directory name, under both the repo root and `~/.pi`. */\nconst DOOM_CONFIG_DIRECTORY = '.doom';\nconst RUN_DIRECTORY = 'run';\nconst DEFAULT_PRESET = 'default';\nconst PRIVATE_FILE_MODE = 0o600;\nconst PRIVATE_DIRECTORY_MODE = 0o700;\nconst OWN_PREFIX = 'own:';\nconst PACKAGE_PREFIX = 'pkg:';\nconst LOCAL_PREFIX = 'local:';\nconst LOCAL_PACKAGE_NAME_PREFIX = 'local-package-name:';\nconst ENTRY_INDEX_SEPARATOR = ':entry:';\nconst COMPOSITION_FINGERPRINT = /^[a-f0-9]{64}$/u;\nconst PLUGIN_MCP_CONFIG_FILES = ['.mcp.json', 'mcp.json'] as const;\nconst PACKAGE_MANIFEST_FILE = 'package.json';\n/** Folder the cockpit bundler compiles straight from each installed package. */\nconst WEB_PLUGIN_DIRECTORY = 'web';\n\n/** Config that feeds a sync, in the order the hash reads it. */\nconst HASHED_CONFIG_FILES = ['config.yaml', 'modes.yaml', 'domains.yaml', 'profiles.yaml', 'hooks.yaml'] as const;\n\nexport interface SyncSelection {\n majorMode: string;\n domains: string[];\n profile?: string;\n preset: string;\n}\n\n/** Paths to the resources sync staged, before any live switch replaces them. */\nexport interface SyncBaseline {\n mcpConfigPath?: string;\n personaFile?: string;\n themePath: string;\n themeName: string;\n}\n\nexport interface SyncPrecompileState {\n /** Version of the lightweight freshness contract used by package startup. */\n version: number;\n strategy: 'bundle';\n /** Package entry the generated bootstrap bundles. */\n bootstrapEntry: string;\n /** Compiler manifest whose output is the graph-bundled package bootstrap. */\n bootstrapManifest: string;\n /** Compiler manifest for each graph-bundled composition. */\n bundleManifests: Record<string, string>;\n}\n\nexport interface SyncServerBundleState {\n descriptorPath: string;\n fingerprint: string;\n compilerManifests: Record<string, string>;\n sourcesHash: string;\n}\n\nexport interface SyncMcpBundleState {\n descriptorPath: string;\n fingerprint: string;\n compilerManifests: Record<string, string>;\n sourcesHash: string;\n}\n\nexport interface SyncState {\n version: number;\n root: string;\n /** Canonical repository and worktree namespace that owns this state. */\n identity: SyncIdentity;\n /** Hash of the config that produced this state, for the staleness warning. */\n inputsHash: string;\n /**\n * Hash of the cockpit sources and package versions this state was built from.\n *\n * Absent in a state written before cockpit sources were tracked, which reads\n * as \"cannot be compared\" rather than as a change, so an old state does not\n * force a resync on sight.\n */\n webSourcesHash?: string;\n /** Canonical composition selected when this state was recorded. */\n compositionFingerprint: string;\n selection: SyncSelection;\n /** Harness environment the extension applies when the values are unset. */\n env: Record<string, string>;\n /**\n * State the environment does not carry, so it has to be recorded on its own.\n *\n * Plugin hooks, the profile's environment defaults, and the neutral MCP\n * projection live in the session state file rather than in variables.\n */\n fileState: Pick<HarnessState, 'profileEnvironment' | 'pluginHooks'> & {\n mcpProjection: DoomMcpProjection;\n };\n /** Entry name to absolute path, covering every layer, not just the selected mode's. */\n resolved: Record<string, string>;\n /**\n * The same entries after TypeScript ones were bundled to plain ESM.\n *\n * Kept apart from `resolved` so the staleness check still compares resolution\n * against resolution; a state written before this existed simply has none and\n * falls back to loading the source.\n */\n compiled?: Record<string, string>;\n /** Aggregate entry by canonical composition fingerprint. */\n bundles?: Record<string, string>;\n /** Graph-compiled synced bootstrap dynamically loaded by the package entry. */\n bootstrap?: string;\n /** Inputs used to validate generated artifacts without loading the compiler. */\n precompile?: SyncPrecompileState;\n /** Absent only in generations produced before the server descriptor cutover. */\n serverBundle?: SyncServerBundleState;\n /** Explicit remote-only session capabilities staged with this generation. */\n mcpBundle?: SyncMcpBundleState;\n baseline: SyncBaseline;\n}\n\nexport function syncDirectory(repoRoot: string, homeDirectory: string = os.homedir()): string {\n return resolveSyncLocation(repoRoot, homeDirectory).directory;\n}\n\nexport function syncStatePath(repoRoot: string, homeDirectory: string = os.homedir()): string {\n return (\n readSyncRegistration(repoRoot, homeDirectory)?.statePath ?? resolveSyncLocation(repoRoot, homeDirectory).statePath\n );\n}\n\nexport function legacySyncDirectory(repoRoot: string): string {\n return resolveSyncLocation(repoRoot).legacyDirectory;\n}\n\nexport function legacySyncStatePath(repoRoot: string): string {\n return resolveSyncLocation(repoRoot).legacyStatePath;\n}\n\nfunction canonicalPath(target: string): string {\n const absolute = path.resolve(target);\n try {\n return fs.realpathSync(absolute);\n } catch {\n const parent = path.dirname(absolute);\n if (parent === absolute) return absolute;\n return path.join(canonicalPath(parent), path.basename(absolute));\n }\n}\n\nfunction isInside(directory: string, target: string): boolean {\n const relative = path.relative(canonicalPath(directory), canonicalPath(target));\n return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));\n}\n\n/** Whether generated state belongs to the repository that is reading it. */\nexport function syncStateRootMatches(repoRoot: string, stateRoot: string): boolean {\n return canonicalPath(repoRoot) === canonicalPath(stateRoot);\n}\n\n/**\n * Per-process scratch directory for live `/domains` and `/profile` switches.\n *\n * Switching rewrites the MCP config and the persona prompt. Writing those back\n * into the synced directory would both mutate the pinned baseline and let two\n * Pi sessions in one repository overwrite each other, which the launcher avoids\n * by giving every run its own temporary directory.\n */\nexport function runDirectory(\n repoRoot: string,\n processId: number = process.pid,\n homeDirectory: string = os.homedir(),\n): string {\n return path.join(syncDirectory(repoRoot, homeDirectory), RUN_DIRECTORY, String(processId));\n}\n\n/**\n * How a Pi project settings file should refer to a generated path.\n *\n * Relative to `.pi` when the target lives in the repository, which keeps the\n * committed settings file identical on every machine. A doom-pi installed\n * outside the repository stays absolute: Pi accepts both, and a relative path\n * climbing out of the project would be neither portable nor readable.\n */\nexport function settingsRelativePath(repoRoot: string, target: string): string {\n const relative = path.relative(repoRoot, target);\n if (relative.startsWith('..') || path.isAbsolute(relative)) return target;\n return path.relative(path.join(repoRoot, PI_DIRECTORY), target).split(path.sep).join('/');\n}\n\nfunction readIfPresent(filePath: string): string {\n return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : '';\n}\n\nfunction updateFramedHash(hash: ReturnType<typeof crypto.createHash>, label: string, value: string | Buffer): void {\n const bytes = typeof value === 'string' ? Buffer.from(value) : value;\n hash.update(`${String(label.length)}:${label}:${String(bytes.byteLength)}:`);\n hash.update(bytes);\n}\n\n/** Hashes path, existence, and bytes without making absent and empty files aliases. */\nfunction updateFileInputHash(hash: ReturnType<typeof crypto.createHash>, filePath: string): void {\n const absolutePath = path.resolve(filePath);\n updateFramedHash(hash, 'path', absolutePath);\n if (!fs.existsSync(absolutePath)) {\n updateFramedHash(hash, 'state', 'missing');\n return;\n }\n updateFramedHash(hash, 'state', 'present');\n updateFramedHash(hash, 'contents', fs.readFileSync(absolutePath));\n}\n\n/** Package root owning a resolved entry, or undefined when it sits outside one. */\nfunction owningPackageRoot(entryPath: string): string | undefined {\n // The resolved map also carries package-name metadata. Relative metadata must\n // not become a filesystem path whose meaning changes with process.cwd().\n if (!path.isAbsolute(entryPath)) return undefined;\n let directory = path.dirname(entryPath);\n for (;;) {\n if (fs.existsSync(path.join(directory, PACKAGE_MANIFEST_FILE))) return directory;\n const parent = path.dirname(directory);\n if (parent === directory) return undefined;\n directory = parent;\n }\n}\n\n/** Every regular file under a directory, as absolute paths in a stable order. */\nfunction filesUnder(directory: string): string[] {\n if (!fs.existsSync(directory)) return [];\n const found: string[] = [];\n const walk = (current: string): void => {\n for (const entry of fs.readdirSync(current, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {\n const full = path.join(current, entry.name);\n if (entry.isDirectory()) walk(full);\n else if (entry.isFile()) found.push(full);\n }\n };\n walk(directory);\n return found;\n}\n\n/**\n * Hashes the cockpit sources and package versions a sync compiled.\n *\n * The cockpit bundle is built from each installed package's `web/` folder by\n * `syncWebBundle`, straight from source, with no compiler manifest recording\n * what went in. Nothing else in the drift check reads those files, so editing a\n * plugin surface and rebuilding left the hub serving the previously bundled\n * cockpit with nothing reporting a reason. Compiled entries are covered\n * elsewhere, by the content digests in their compiler manifests, so only the\n * entry identity and its package version are folded in here.\n *\n * Bounded on purpose: the web sources of a full composition are a few hundred\n * small files, which is cheap enough for the hub to poll.\n */\nexport function computeWebSourcesHash(resolved: Record<string, string>): string {\n const hash = crypto.createHash('sha256');\n const roots = [...new Set(Object.values(resolved).flatMap((entry) => owningPackageRoot(entry) ?? []))].sort();\n for (const root of roots) {\n updateFramedHash(hash, 'package', root);\n const manifestPath = path.join(root, PACKAGE_MANIFEST_FILE);\n let manifest: { name?: unknown; version?: unknown } = {};\n try {\n manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as { name?: unknown; version?: unknown };\n } catch {\n // An unreadable manifest still contributes its path above, so the package\n // is not silently dropped from the hash; the version simply reads empty\n // and any later repair shows up as a change.\n manifest = {};\n }\n updateFramedHash(hash, 'name', typeof manifest.name === 'string' ? manifest.name : '');\n updateFramedHash(hash, 'version', typeof manifest.version === 'string' ? manifest.version : '');\n for (const file of filesUnder(path.join(root, WEB_PLUGIN_DIRECTORY))) updateFileInputHash(hash, file);\n }\n for (const [name, entry] of Object.entries(resolved).sort(([left], [right]) => left.localeCompare(right))) {\n updateFramedHash(hash, 'entry', `${name}\u0000${entry}`);\n }\n return hash.digest('hex');\n}\n\n/** Include declaration changes even for packages that did not previously expose a server facet. */\nexport function computeServerSourcesHash(resolved: Record<string, string>): string {\n const hash = crypto.createHash('sha256');\n const roots = [...new Set(Object.values(resolved).flatMap((entry) => owningPackageRoot(entry) ?? []))].sort();\n for (const root of roots) {\n const manifestPath = path.join(root, PACKAGE_MANIFEST_FILE);\n updateFileInputHash(hash, manifestPath);\n const manifest: unknown = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n if (!isRecord(manifest) || !isRecord(manifest.doompiServer) || !isRecord(manifest.doompiServer.contracts)) continue;\n // Include missing declarations too: building or repairing a contract must invalidate an incomplete generation.\n for (const file of [manifest.doompiServer.contracts.entry, manifest.doompiServer.contracts.dist]) {\n if (typeof file !== 'string' || !file.startsWith('./') || file.split('/').includes('..') || /[\\\\%?#]/u.test(file))\n continue;\n updateFileInputHash(hash, path.join(root, file));\n }\n }\n for (const [name, entry] of Object.entries(resolved).sort(([left], [right]) => left.localeCompare(right))) {\n updateFramedHash(hash, 'entry', JSON.stringify([name, entry]));\n }\n return hash.digest('hex');\n}\n\n/** Include MCP declarations and their attributed source files in sync freshness. */\nexport function computeMcpSourcesHash(resolved: Record<string, string>): string {\n const hash = crypto.createHash('sha256');\n const roots = [...new Set(Object.values(resolved).flatMap((entry) => owningPackageRoot(entry) ?? []))].sort();\n for (const root of roots) {\n const manifestPath = path.join(root, PACKAGE_MANIFEST_FILE);\n updateFileInputHash(hash, manifestPath);\n const manifest: unknown = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n if (!isRecord(manifest) || !isRecord(manifest.doompiMcp)) continue;\n for (const file of [manifest.doompiMcp.entry, manifest.doompiMcp.dist]) {\n if (typeof file !== 'string' || !file.startsWith('./') || file.split('/').includes('..') || /[\\\\%?#]/u.test(file))\n continue;\n updateFileInputHash(hash, path.join(root, file));\n }\n }\n for (const [name, entry] of Object.entries(resolved).sort(([left], [right]) => left.localeCompare(right))) {\n updateFramedHash(hash, 'entry', JSON.stringify([name, entry]));\n }\n return hash.digest('hex');\n}\n\n/**\n * Hashes the configuration a sync consumed.\n *\n * Deliberately cheap: the extension recomputes this on every session start, so\n * it reads config, marketplace, local plugin manifests, and profile persona text\n * without downloading plugins or re-resolving packages. A dependency upgrade that\n * moves a package path therefore does not show up here; `doom-pi sync --check`\n * re-resolves and is the check that catches that.\n */\nexport function computeInputsHash(\n repoRoot: string,\n selection: SyncSelection,\n homeDirectory: string = os.homedir(),\n environment: NodeJS.ProcessEnv = process.env,\n): string {\n // Match sync publication, including callers that reach the repository through a symlink.\n repoRoot = resolveSyncLocation(repoRoot, homeDirectory).root;\n const hash = crypto.createHash('sha256');\n hash.update(JSON.stringify({ ...selection, domains: [...selection.domains].sort() }));\n if (environment.DOOMPI_DISTRIBUTION === 'desktop') {\n updateFramedHash(hash, 'distribution', 'desktop:computer-use-default-v1');\n }\n // Every .doom document layers the global copy under the repository one, so an\n // edit in either location is a real change.\n for (const directory of [\n path.join(homeDirectory, PI_DIRECTORY, DOOM_CONFIG_DIRECTORY),\n path.join(repoRoot, DOOM_CONFIG_DIRECTORY),\n ]) {\n for (const fileName of HASHED_CONFIG_FILES) hash.update(readIfPresent(path.join(directory, fileName)));\n }\n updateFileInputHash(hash, path.join(repoRoot, '.mcp.json'));\n\n const catalog = loadDomains(repoRoot, homeDirectory).plugins;\n for (const root of catalog.roots) hash.update(root);\n for (const diagnostic of catalog.diagnostics) hash.update(diagnostic);\n for (const marketplace of catalog.marketplaces) {\n hash.update(marketplace);\n hash.update(readIfPresent(marketplace));\n }\n for (const [name, plugin] of Object.entries(catalog.entries).sort(([left], [right]) => left.localeCompare(right))) {\n hash.update(name);\n hash.update(JSON.stringify(plugin.source));\n if (plugin.manifest) {\n hash.update(plugin.manifest.path);\n hash.update(readIfPresent(plugin.manifest.path));\n }\n }\n\n let selectedPluginDirectories: string[] = [];\n try {\n selectedPluginDirectories = [\n ...new Set(\n resolvePluginEntries(repoRoot, selection.domains, [], homeDirectory)\n .filter((plugin) => plugin.mcp !== false)\n .map((plugin) => path.resolve(plugin.directory)),\n ),\n ].sort();\n } catch {\n // The surrounding .doom inputs already make an invalid or removed domain\n // selection stale. Keep this lightweight check readable for old state\n // instead of turning that expected staleness into a startup exception.\n }\n for (const directory of selectedPluginDirectories) {\n for (const fileName of PLUGIN_MCP_CONFIG_FILES) {\n updateFileInputHash(hash, path.join(directory, fileName));\n }\n }\n\n for (const profile of loadProfiles(repoRoot, homeDirectory)) {\n hash.update(profile.name);\n hash.update(profile.personaRoot);\n hash.update(profile.persona);\n hash.update(JSON.stringify(profile.env));\n const personaDirectory = path.resolve(profile.personaRoot, profile.persona);\n for (const fileName of PERSONA_FILES) {\n const filePath = path.join(personaDirectory, fileName);\n hash.update(filePath);\n hash.update(readIfPresent(filePath));\n }\n }\n return hash.digest('hex');\n}\n\nfunction stringRecord(value: unknown, field: string, statePath: string): Record<string, string> {\n if (!isRecord(value)) throw new Error(`Doom sync state at ${statePath} requires ${field} to be an object`);\n return Object.fromEntries(\n Object.entries(value).filter((entry): entry is [string, string] => typeof entry[1] === 'string'),\n );\n}\n\nfunction parsePrecompileState(value: unknown, statePath: string): SyncPrecompileState {\n if (\n !isRecord(value) ||\n value.version !== PRECOMPILE_STATE_VERSION ||\n value.strategy !== 'bundle' ||\n typeof value.bootstrapEntry !== 'string' ||\n typeof value.bootstrapManifest !== 'string' ||\n !isRecord(value.bundleManifests) ||\n Object.entries(value.bundleManifests).some(\n ([fingerprint, manifest]) => !COMPOSITION_FINGERPRINT.test(fingerprint) || typeof manifest !== 'string',\n )\n ) {\n throw new Error(`Doom sync state at ${statePath} has an invalid precompile record`);\n }\n return {\n version: value.version,\n strategy: value.strategy,\n bootstrapEntry: value.bootstrapEntry,\n bootstrapManifest: value.bootstrapManifest,\n bundleManifests: value.bundleManifests as Record<string, string>,\n };\n}\n\nfunction precompileMatchesBundles(\n precompile: SyncPrecompileState,\n bundles: Record<string, string> | undefined,\n): boolean {\n const bundleFingerprints = Object.keys(bundles ?? {}).sort();\n const manifestFingerprints = Object.keys(precompile.bundleManifests).sort();\n return (\n bundleFingerprints.length === manifestFingerprints.length &&\n bundleFingerprints.every((fingerprint, index) => fingerprint === manifestFingerprints[index])\n );\n}\n\ninterface ParseSyncStateOptions {\n repoRoot: string;\n location: SyncLocation;\n legacy: boolean;\n}\n\nfunction identityMatches(left: SyncIdentity, right: SyncIdentity): boolean {\n return left.repositoryId === right.repositoryId && left.worktreeId === right.worktreeId;\n}\n\nfunction parseSyncIdentity(value: unknown, statePath: string): SyncIdentity {\n if (!isRecord(value) || typeof value.repositoryId !== 'string' || typeof value.worktreeId !== 'string') {\n throw new Error(`Doom sync state at ${statePath} requires repository and worktree identity`);\n }\n return { repositoryId: value.repositoryId, worktreeId: value.worktreeId };\n}\n\nfunction parseSyncState(source: string, statePath: string, options: ParseSyncStateOptions): SyncState {\n let parsed: unknown;\n try {\n parsed = JSON.parse(source);\n } catch (error) {\n throw new Error(`Doom sync state at ${statePath} is not valid JSON`, { cause: error });\n }\n if (!isRecord(parsed)) throw new Error(`Doom sync state at ${statePath} must be an object`);\n if (typeof parsed.version !== 'number' || parsed.version !== SYNC_STATE_VERSION) {\n throw new Error(\n `Doom sync state at ${statePath} has version ${String(parsed.version)}, expected ${SYNC_STATE_VERSION}. Run doompi sync.`,\n );\n }\n if (typeof parsed.root !== 'string' || typeof parsed.inputsHash !== 'string') {\n throw new Error(`Doom sync state at ${statePath} requires string root and inputsHash`);\n }\n if (\n typeof parsed.compositionFingerprint !== 'string' ||\n !COMPOSITION_FINGERPRINT.test(parsed.compositionFingerprint)\n ) {\n throw new Error(`Doom sync state at ${statePath} requires a canonical compositionFingerprint`);\n }\n if (parsed.nativeGraphs !== undefined) {\n throw new Error(`Doom sync state at ${statePath} contains removed native graph state. Run doompi sync.`);\n }\n if (!syncStateRootMatches(options.repoRoot, parsed.root)) {\n throw new Error(`Doom sync state at ${statePath} belongs to a different repository: ${parsed.root}`);\n }\n const identity = parseSyncIdentity(parsed.identity, statePath);\n if (!identityMatches(identity, options.location.identity)) {\n throw new Error(`Doom sync state at ${statePath} belongs to a different repository or worktree identity`);\n }\n if (!isRecord(parsed.selection) || typeof parsed.selection.majorMode !== 'string') {\n throw new Error(`Doom sync state at ${statePath} requires a selection with a majorMode`);\n }\n if (!isRecord(parsed.baseline) || typeof parsed.baseline.themePath !== 'string') {\n throw new Error(`Doom sync state at ${statePath} requires a baseline with a themePath`);\n }\n const { majorMode, domains, profile, preset } = parsed.selection;\n const fileState = isRecord(parsed.fileState) ? parsed.fileState : {};\n if (!isDoomMcpProjection(fileState.mcpProjection)) {\n throw new Error(`Doom sync state at ${statePath} requires a valid MCP projection. Run doompi sync.`);\n }\n if (!syncStateRootMatches(parsed.root, fileState.mcpProjection.repoRoot)) {\n throw new Error(`Doom sync state at ${statePath} contains an MCP projection for a different repository`);\n }\n const generatedDirectory = options.legacy ? options.location.legacyDirectory : options.location.directory;\n const compiled = parsed.compiled === undefined ? undefined : stringRecord(parsed.compiled, 'compiled', statePath);\n const bundles = parsed.bundles === undefined ? undefined : stringRecord(parsed.bundles, 'bundles', statePath);\n const precompile = parsed.precompile === undefined ? undefined : parsePrecompileState(parsed.precompile, statePath);\n if (precompile && !precompileMatchesBundles(precompile, bundles)) {\n throw new Error(`Doom sync state at ${statePath} has an invalid precompile record`);\n }\n let serverBundle: SyncServerBundleState | undefined;\n if (parsed.serverBundle !== undefined) {\n const value = parsed.serverBundle;\n if (\n !isRecord(value) ||\n typeof value.descriptorPath !== 'string' ||\n typeof value.fingerprint !== 'string' ||\n !COMPOSITION_FINGERPRINT.test(value.fingerprint) ||\n typeof value.sourcesHash !== 'string' ||\n !COMPOSITION_FINGERPRINT.test(value.sourcesHash)\n ) {\n throw new Error(`Doom sync state at ${statePath} has an invalid server bundle record`);\n }\n const compilerManifests = stringRecord(value.compilerManifests, 'server compiler manifests', statePath);\n if (\n [value.descriptorPath, ...Object.values(compilerManifests)].some((entry) => !isInside(generatedDirectory, entry))\n ) {\n throw new Error(`Doom sync state at ${statePath} references server material outside ${generatedDirectory}`);\n }\n serverBundle = {\n descriptorPath: value.descriptorPath,\n fingerprint: value.fingerprint,\n compilerManifests,\n sourcesHash: value.sourcesHash,\n };\n }\n let mcpBundle: SyncMcpBundleState | undefined;\n if (parsed.mcpBundle !== undefined) {\n const value = parsed.mcpBundle;\n if (\n !isRecord(value) ||\n typeof value.descriptorPath !== 'string' ||\n typeof value.fingerprint !== 'string' ||\n !COMPOSITION_FINGERPRINT.test(value.fingerprint) ||\n typeof value.sourcesHash !== 'string' ||\n !COMPOSITION_FINGERPRINT.test(value.sourcesHash)\n ) {\n throw new Error(`Doom sync state at ${statePath} has an invalid MCP bundle record`);\n }\n const compilerManifests = stringRecord(value.compilerManifests, 'MCP compiler manifests', statePath);\n if (\n [value.descriptorPath, ...Object.values(compilerManifests)].some((entry) => !isInside(generatedDirectory, entry))\n ) {\n throw new Error(`Doom sync state at ${statePath} references MCP material outside ${generatedDirectory}`);\n }\n mcpBundle = {\n descriptorPath: value.descriptorPath,\n fingerprint: value.fingerprint,\n compilerManifests,\n sourcesHash: value.sourcesHash,\n };\n }\n const bootstrap = typeof parsed.bootstrap === 'string' ? parsed.bootstrap : undefined;\n const generatedPaths = [bootstrap, ...Object.values(compiled ?? {}), ...Object.values(bundles ?? {})].filter(\n (entry): entry is string => entry !== undefined,\n );\n if (generatedPaths.some((entry) => !isInside(generatedDirectory, entry))) {\n throw new Error(`Doom sync state at ${statePath} references generated material outside ${generatedDirectory}`);\n }\n return {\n version: parsed.version,\n root: parsed.root,\n identity,\n inputsHash: parsed.inputsHash,\n webSourcesHash: typeof parsed.webSourcesHash === 'string' ? parsed.webSourcesHash : undefined,\n compositionFingerprint: parsed.compositionFingerprint,\n selection: {\n majorMode,\n domains: Array.isArray(domains) ? domains.filter((name): name is string => typeof name === 'string') : [],\n profile: typeof profile === 'string' ? profile : undefined,\n preset: typeof preset === 'string' ? preset : DEFAULT_PRESET,\n },\n env: stringRecord(parsed.env, 'env', statePath),\n fileState: {\n profileEnvironment: isRecord(fileState.profileEnvironment)\n ? (fileState.profileEnvironment as Record<string, string>)\n : {},\n pluginHooks: Array.isArray(fileState.pluginHooks) ? (fileState.pluginHooks as HarnessState['pluginHooks']) : [],\n mcpProjection: fileState.mcpProjection,\n },\n resolved: stringRecord(parsed.resolved, 'resolved', statePath),\n compiled,\n bundles,\n bootstrap,\n precompile,\n ...(serverBundle ? { serverBundle } : {}),\n ...(mcpBundle ? { mcpBundle } : {}),\n baseline: parsed.baseline as unknown as SyncBaseline,\n };\n}\n\nexport interface LocatedSyncState {\n state: SyncState;\n location: SyncLocation;\n layout: 'global';\n}\n\n/** Reads one exact admitted registration, even after the worktree's current registration moves on. */\nexport function readRegisteredSyncState(\n registration: SyncRegistration,\n homeDirectory: string = os.homedir(),\n): SyncState {\n const location = resolveSyncLocation(registration.root, homeDirectory);\n validateSyncRegistration(registration, location);\n return parseSyncState(fs.readFileSync(registration.statePath, 'utf8'), registration.statePath, {\n repoRoot: registration.root,\n location,\n legacy: false,\n });\n}\n\n/** Reads only state reached through this repository/worktree's validated registration. */\nexport function readLocatedSyncState(\n repoRoot: string,\n homeDirectory: string = os.homedir(),\n): LocatedSyncState | undefined {\n const location = resolveSyncLocation(repoRoot, homeDirectory);\n const registration = readSyncRegistration(repoRoot, homeDirectory);\n if (!registration) return undefined;\n return {\n state: readRegisteredSyncState(registration, homeDirectory),\n location,\n layout: 'global',\n };\n}\n\n/** Reads the synced state, or undefined when the repository was never synced. */\nexport function readSyncState(repoRoot: string, homeDirectory: string = os.homedir()): SyncState | undefined {\n return readLocatedSyncState(repoRoot, homeDirectory)?.state;\n}\n\nexport function serializeSyncState(state: SyncState): string {\n return `${JSON.stringify(state, null, 2)}\\n`;\n}\n\nexport async function writeSyncState(\n repoRoot: string,\n state: SyncState,\n homeDirectory: string = os.homedir(),\n targetPath?: string,\n): Promise<string> {\n const location = resolveSyncLocation(repoRoot, homeDirectory);\n const statePath = targetPath ?? location.statePath;\n if (state.version !== SYNC_STATE_VERSION) {\n throw new Error(`Doom sync state writes require version ${SYNC_STATE_VERSION}`);\n }\n if (!COMPOSITION_FINGERPRINT.test(state.compositionFingerprint)) {\n throw new Error('Doom sync state writes require a canonical composition fingerprint');\n }\n if (!isDoomMcpProjection(state.fileState.mcpProjection)) {\n throw new Error('Doom sync state writes require a valid MCP projection');\n }\n if (!syncStateRootMatches(state.root, state.fileState.mcpProjection.repoRoot)) {\n throw new Error('Refusing to write a Doom sync state whose MCP projection belongs to another repository');\n }\n if (!syncStateRootMatches(repoRoot, state.root) || !identityMatches(state.identity, location.identity)) {\n throw new Error('Refusing to write Doom sync state for a different repository or worktree');\n }\n if (state.precompile) {\n const precompile = parsePrecompileState(state.precompile, statePath);\n if (!precompileMatchesBundles(precompile, state.bundles)) {\n throw new Error(`Doom sync state at ${statePath} has an invalid precompile record`);\n }\n }\n if (!isInside(location.directory, statePath)) {\n throw new Error(`Refusing to write Doom sync state outside ${location.directory}`);\n }\n assertSyncLocationSafe(location);\n await fs.promises.mkdir(path.dirname(statePath), { mode: PRIVATE_DIRECTORY_MODE, recursive: true });\n const temporaryPath = `${statePath}.${process.pid}.${crypto.randomUUID()}.tmp`;\n try {\n await fs.promises.writeFile(temporaryPath, serializeSyncState(state), { mode: PRIVATE_FILE_MODE });\n await fs.promises.rename(temporaryPath, statePath);\n } catch (error) {\n await fs.promises.rm(temporaryPath, { force: true });\n throw error;\n }\n return statePath;\n}\n\nexport function ownKey(name: string): string {\n return `${OWN_PREFIX}${name}`;\n}\n\nexport function packageKey(specifier: string): string {\n return `${PACKAGE_PREFIX}${specifier}`;\n}\n\nexport function packageEntryKey(specifier: string, index: number): string {\n return index === 0 ? packageKey(specifier) : `${packageKey(specifier)}${ENTRY_INDEX_SEPARATOR}${index}`;\n}\n\n/**\n * Keyed by the absolute target, because the same relative specifier means\n * different files under the repository and the global config directory.\n */\nexport function localKey(specifier: string, baseDirectory: string): string {\n return `${LOCAL_PREFIX}${path.resolve(baseDirectory, specifier)}`;\n}\n\nexport function localEntryKey(specifier: string, baseDirectory: string, index: number): string {\n return index === 0\n ? localKey(specifier, baseDirectory)\n : `${localKey(specifier, baseDirectory)}${ENTRY_INDEX_SEPARATOR}${index}`;\n}\n\nexport function localPackageNameKey(specifier: string, baseDirectory: string): string {\n return `${LOCAL_PACKAGE_NAME_PREFIX}${path.resolve(baseDirectory, specifier)}`;\n}\n\nexport interface RecordingResolvers extends ExtensionLayerResolvers {\n /** Every name this resolver was asked for, keyed for the state file. */\n readonly resolved: Record<string, string>;\n packageEntries(name: string): string[];\n optionalPackageEntries(name: string): string[] | undefined;\n localEntries(specifier: string, baseDirectory: string): string[] | undefined;\n}\n\n/**\n * Resolvers that record what they resolve.\n *\n * Sync composes once with every layer selected and hands the recording to the\n * state file, so the extension never has to resolve a specifier itself.\n */\nexport function createRecordingResolvers(base: LayerResolvers = LAYER_RESOLVERS): RecordingResolvers {\n const resolved: Record<string, string> = {};\n const extensionBase = base as ExtensionLayerResolvers;\n const recordEntries = (entries: string[], keyFor: (index: number) => string): string[] => {\n entries.forEach((entry, index) => {\n resolved[keyFor(index)] = entry;\n });\n return entries;\n };\n return {\n resolved,\n ownEntry(name) {\n const entry = base.ownEntry(name);\n resolved[ownKey(name)] = entry;\n return entry;\n },\n packageEntry(name) {\n const entry = base.packageEntry(name);\n resolved[packageKey(name)] = entry;\n return entry;\n },\n optionalPackageEntry(name) {\n const entry = base.optionalPackageEntry(name);\n // A miss is recorded by omission, which is what later makes the extension\n // treat it as absent instead of failing the whole composition.\n if (entry) resolved[packageKey(name)] = entry;\n return entry;\n },\n packageEntries(name) {\n const entries = extensionBase.packageEntries?.(name) ?? [base.packageEntry(name)];\n return recordEntries(entries, (index) => packageEntryKey(name, index));\n },\n optionalPackageEntries(name) {\n let entries = extensionBase.optionalPackageEntries?.(name);\n if (entries === undefined) {\n const entry = base.optionalPackageEntry(name);\n entries = entry ? [entry] : undefined;\n }\n return entries ? recordEntries(entries, (index) => packageEntryKey(name, index)) : undefined;\n },\n localEntry(specifier, baseDirectory) {\n const entry = base.localEntry(specifier, baseDirectory);\n if (entry) resolved[localKey(specifier, baseDirectory)] = entry;\n return entry;\n },\n localEntries(specifier, baseDirectory) {\n let entries = extensionBase.localEntries?.(specifier, baseDirectory);\n if (entries === undefined) {\n const entry = base.localEntry(specifier, baseDirectory);\n entries = entry ? [entry] : undefined;\n }\n return entries ? recordEntries(entries, (index) => localEntryKey(specifier, baseDirectory, index)) : undefined;\n },\n localPackageName(specifier, baseDirectory) {\n const name = extensionBase.localPackageName?.(specifier, baseDirectory);\n if (name) resolved[localPackageNameKey(specifier, baseDirectory)] = name;\n return name;\n },\n };\n}\n\n/**\n * Resolves every entry any layer could contribute, in one pass.\n *\n * Composing with every layer selected and the widest options is what makes the\n * map complete: a later `/mode` switch inside a Pi session can then pick a\n * different set without resolving anything itself. The persona entry is asked\n * for separately because it remains a fixed host entry rather than a layer.\n */\nexport function recordResolvedEntries(\n majorModesConfig: MajorModesConfig,\n base: LayerResolvers = LAYER_RESOLVERS,\n): Record<string, string> {\n const recording = createRecordingResolvers(base);\n recording.packageEntry(PERSONA_ENTRY);\n assembleExtensions({\n agents: true,\n autoStop: true,\n mute: false,\n // The one preset that contributes an extension of its own.\n preset: OLLAMA_PRESET,\n layers: Object.keys(majorModesConfig.layers),\n majorModesConfig,\n resolvers: recording,\n });\n assembleChildExtensions({\n agents: false,\n autoStop: false,\n mute: true,\n preset: OLLAMA_PRESET,\n layers: Object.keys(majorModesConfig.layers),\n majorModesConfig,\n resolvers: recording,\n });\n return recording.resolved;\n}\n\n/** Resolvers backed by a synced map, for composing inside a Pi session. */\nexport function createMapResolvers(\n resolved: Record<string, string>,\n compiled: Record<string, string> = {},\n): ExtensionLayerResolvers {\n // The compiled bundle when this entry has one, the source otherwise.\n const entryFor = (key: string): string | undefined => compiled[key] ?? resolved[key];\n const lookup = (key: string, name: string): string => {\n const entry = entryFor(key);\n if (!entry) throw new Error(`${name} is missing from the doompi sync state. Run doompi sync.`);\n return entry;\n };\n const indexedEntries = (keyFor: (index: number) => string): string[] | undefined => {\n const first = entryFor(keyFor(0));\n if (!first) return undefined;\n const entries = [first];\n for (let index = 1; ; index += 1) {\n const entry = entryFor(keyFor(index));\n if (!entry) break;\n entries.push(entry);\n }\n return entries;\n };\n return {\n ownEntry: (name) => lookup(ownKey(name), name),\n packageEntry: (name) => lookup(packageKey(name), name),\n optionalPackageEntry: (name) => entryFor(packageKey(name)),\n packageEntries: (name) => {\n const entries = indexedEntries((index) => packageEntryKey(name, index));\n if (!entries) throw new Error(`${name} is missing from the doompi sync state. Run doompi sync.`);\n return entries;\n },\n optionalPackageEntries: (name) => indexedEntries((index) => packageEntryKey(name, index)),\n localEntry: (specifier, baseDirectory) => entryFor(localKey(specifier, baseDirectory)),\n localEntries: (specifier, baseDirectory) =>\n indexedEntries((index) => localEntryKey(specifier, baseDirectory, index)),\n localPackageName: (specifier, baseDirectory) => resolved[localPackageNameKey(specifier, baseDirectory)],\n };\n}\n\n/** Reads the resolved MCP servers back out of a generated config. */\nexport function readMcpServerNames(configPath: string): string[] {\n if (!fs.existsSync(configPath)) return [];\n const config = JSON.parse(fs.readFileSync(configPath, 'utf8')) as JsonObject;\n return isRecord(config.mcpServers) ? Object.keys(config.mcpServers) : [];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAM,eAAe;;AAErB,MAAM,wBAAwB;AAC9B,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;AACvB,MAAM,oBAAoB;AAC1B,MAAM,yBAAyB;AAC/B,MAAM,aAAa;AACnB,MAAM,iBAAiB;AACvB,MAAM,eAAe;AACrB,MAAM,4BAA4B;AAClC,MAAM,wBAAwB;AAC9B,MAAM,0BAA0B;AAChC,MAAM,0BAA0B,CAAC,aAAa,UAAU;AACxD,MAAM,wBAAwB;;AAE9B,MAAM,uBAAuB;;AAG7B,MAAM,sBAAsB;CAAC;CAAe;CAAc;CAAgB;CAAiB;AAAY;AA+FvG,SAAgB,cAAc,UAAkB,gBAAwBA,QAAAA,QAAG,QAAQ,GAAW;CAC5F,QAAA,GAAOC,oCAAAA,oBAAAA,CAAoB,UAAU,aAAa,CAAC,CAAC;AACtD;AAEA,SAAgB,cAAc,UAAkB,gBAAwBD,QAAAA,QAAG,QAAQ,GAAW;CAC5F,QAAA,GACEE,wCAAAA,qBAAAA,CAAqB,UAAU,aAAa,CAAC,EAAE,cAAA,GAAaD,oCA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AAmB,YAA8B;CAC/D,IAAI,CAACZ,QAAAA,QAAG,WAAW,UAAU,GAAG,OAAO,CAAC;CACxC,MAAM,SAAS,KAAK,MAAMA,QAAAA,QAAG,aAAa,YAAY,MAAM,CAAC;CAC7D,QAAA,GAAOE,mCAAAA,SAAAA,CAAS,OAAO,UAAU,IAAI,OAAO,KAAK,OAAO,UAAU,IAAI,CAAC;AACzE"}
1
+ {"version":3,"file":"index.cjs","names":["os","resolveSyncLocation","readSyncRegistration","path","fs","crypto","isRecord","loadDomains","resolvePluginEntries","loadProfiles","PERSONA_FILES","PRECOMPILE_STATE_VERSION","SYNC_STATE_VERSION","isDoomMcpProjection","LAYER_RESOLVERS","PERSONA_ENTRY","OLLAMA_PRESET"],"sources":["../../../../src/composition/syncState/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport { loadDomains, resolvePluginEntries } from '@agimon-ai/doompi-config/domains';\nimport type { LayerResolvers, MajorModesConfig } from '@agimon-ai/doompi-config/majorModes';\nimport { loadProfiles, PERSONA_FILES } from '@agimon-ai/doompi-config/profiles';\nimport type { HarnessState } from '@agimon-ai/doompi-config/types';\nimport { isDoomMcpProjection, type DoomMcpProjection } from '@agimon-ai/doompi-core/mcpProjection';\nimport { isRecord } from '@agimon-ai/doompi-core/runtimeJson';\nimport type { JsonObject } from '@agimon-ai/doompi-core/runtimeJson';\nimport {\n assertSyncLocationSafe,\n resolveSyncLocation,\n type SyncIdentity,\n type SyncLocation,\n} from '@agimon-ai/doompi-core/syncLocation';\nimport {\n readSyncRegistration,\n validateSyncRegistration,\n type SyncRegistration,\n} from '@agimon-ai/doompi-core/syncRegistration';\nimport { PRECOMPILE_STATE_VERSION, SYNC_STATE_VERSION } from '@agimon-ai/doompi-core/syncStateContract';\n\nimport {\n assembleChildExtensions,\n assembleExtensions,\n type ExtensionLayerResolvers,\n LAYER_RESOLVERS,\n OLLAMA_PRESET,\n PERSONA_ENTRY,\n} from '../../builders/cli/extensionAssembler';\n\nexport { SYNC_STATE_VERSION } from '@agimon-ai/doompi-core/syncStateContract';\n\n/**\n * The file `doom-pi sync` writes and the doom-pi Pi extension reads back.\n *\n * This is the whole contract between the two halves of the synced path. Sync\n * runs in plain Node, where module resolution and the repository config are\n * available; the extension runs inside a Pi session, where neither can be\n * relied on. Everything the extension needs is therefore resolved once here,\n * and everything in this file has to survive JSON.\n */\n\nconst PI_DIRECTORY = '.pi';\n/** The `.doom` config directory name, under both the repo root and `~/.pi`. */\nconst DOOM_CONFIG_DIRECTORY = '.doom';\nconst RUN_DIRECTORY = 'run';\nconst DEFAULT_PRESET = 'default';\nconst PRIVATE_FILE_MODE = 0o600;\nconst PRIVATE_DIRECTORY_MODE = 0o700;\nconst OWN_PREFIX = 'own:';\nconst PACKAGE_PREFIX = 'pkg:';\nconst LOCAL_PREFIX = 'local:';\nconst LOCAL_PACKAGE_NAME_PREFIX = 'local-package-name:';\nconst ENTRY_INDEX_SEPARATOR = ':entry:';\nconst COMPOSITION_FINGERPRINT = /^[a-f0-9]{64}$/u;\nconst PLUGIN_MCP_CONFIG_FILES = ['.mcp.json', 'mcp.json'] as const;\nconst PACKAGE_MANIFEST_FILE = 'package.json';\n/** Folder the cockpit bundler compiles straight from each installed package. */\nconst WEB_PLUGIN_DIRECTORY = 'web';\n\n/** Config that feeds a sync, in the order the hash reads it. */\nconst HASHED_CONFIG_FILES = ['config.yaml', 'modes.yaml', 'domains.yaml', 'profiles.yaml', 'hooks.yaml'] as const;\n\nexport interface SyncSelection {\n majorMode: string;\n domains: string[];\n profile?: string;\n preset: string;\n}\n\n/** Paths to the resources sync staged, before any live switch replaces them. */\nexport interface SyncBaseline {\n mcpConfigPath?: string;\n personaFile?: string;\n themePath: string;\n themeName: string;\n}\n\nexport interface SyncPrecompileState {\n /** Version of the lightweight freshness contract used by package startup. */\n version: number;\n strategy: 'bundle';\n /** Package entry the generated bootstrap bundles. */\n bootstrapEntry: string;\n /** Compiler manifest whose output is the graph-bundled package bootstrap. */\n bootstrapManifest: string;\n /** Compiler manifest for each graph-bundled composition. */\n bundleManifests: Record<string, string>;\n}\n\nexport interface SyncServerBundleState {\n descriptorPath: string;\n fingerprint: string;\n compilerManifests: Record<string, string>;\n sourcesHash: string;\n}\n\nexport interface SyncMcpBundleState {\n descriptorPath: string;\n fingerprint: string;\n compilerManifests: Record<string, string>;\n sourcesHash: string;\n}\n\nexport interface SyncState {\n version: number;\n root: string;\n /** Canonical repository and worktree namespace that owns this state. */\n identity: SyncIdentity;\n /** Hash of the config that produced this state, for the staleness warning. */\n inputsHash: string;\n /**\n * Hash of the cockpit sources and package versions this state was built from.\n *\n * Absent in a state written before cockpit sources were tracked, which reads\n * as \"cannot be compared\" rather than as a change, so an old state does not\n * force a resync on sight.\n */\n webSourcesHash?: string;\n /** Canonical composition selected when this state was recorded. */\n compositionFingerprint: string;\n selection: SyncSelection;\n /** Harness environment the extension applies when the values are unset. */\n env: Record<string, string>;\n /**\n * State the environment does not carry, so it has to be recorded on its own.\n *\n * Plugin hooks, the profile's environment defaults, and the neutral MCP\n * projection live in the session state file rather than in variables.\n */\n fileState: Pick<HarnessState, 'profileEnvironment' | 'pluginHooks' | 'hookModules'> & {\n mcpProjection: DoomMcpProjection;\n };\n /** Entry name to absolute path, covering every layer, not just the selected mode's. */\n resolved: Record<string, string>;\n /**\n * The same entries after TypeScript ones were bundled to plain ESM.\n *\n * Kept apart from `resolved` so the staleness check still compares resolution\n * against resolution; a state written before this existed simply has none and\n * falls back to loading the source.\n */\n compiled?: Record<string, string>;\n /** Aggregate entry by canonical composition fingerprint. */\n bundles?: Record<string, string>;\n /** Graph-compiled synced bootstrap dynamically loaded by the package entry. */\n bootstrap?: string;\n /** Inputs used to validate generated artifacts without loading the compiler. */\n precompile?: SyncPrecompileState;\n /** Absent only in generations produced before the server descriptor cutover. */\n serverBundle?: SyncServerBundleState;\n /** Explicit remote-only session capabilities staged with this generation. */\n mcpBundle?: SyncMcpBundleState;\n baseline: SyncBaseline;\n}\n\nexport function syncDirectory(repoRoot: string, homeDirectory: string = os.homedir()): string {\n return resolveSyncLocation(repoRoot, homeDirectory).directory;\n}\n\nexport function syncStatePath(repoRoot: string, homeDirectory: string = os.homedir()): string {\n return (\n readSyncRegistration(repoRoot, homeDirectory)?.statePath ?? resolveSyncLocation(repoRoot, homeDirectory).statePath\n );\n}\n\nexport function legacySyncDirectory(repoRoot: string): string {\n return resolveSyncLocation(repoRoot).legacyDirectory;\n}\n\nexport function legacySyncStatePath(repoRoot: string): string {\n return resolveSyncLocation(repoRoot).legacyStatePath;\n}\n\nfunction canonicalPath(target: string): string {\n const absolute = path.resolve(target);\n try {\n return fs.realpathSync(absolute);\n } catch {\n const parent = path.dirname(absolute);\n if (parent === absolute) return absolute;\n return path.join(canonicalPath(parent), path.basename(absolute));\n }\n}\n\nfunction isInside(directory: string, target: string): boolean {\n const relative = path.relative(canonicalPath(directory), canonicalPath(target));\n return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));\n}\n\n/** Whether generated state belongs to the repository that is reading it. */\nexport function syncStateRootMatches(repoRoot: string, stateRoot: string): boolean {\n return canonicalPath(repoRoot) === canonicalPath(stateRoot);\n}\n\n/**\n * Per-process scratch directory for live `/domains` and `/profile` switches.\n *\n * Switching rewrites the MCP config and the persona prompt. Writing those back\n * into the synced directory would both mutate the pinned baseline and let two\n * Pi sessions in one repository overwrite each other, which the launcher avoids\n * by giving every run its own temporary directory.\n */\nexport function runDirectory(\n repoRoot: string,\n processId: number = process.pid,\n homeDirectory: string = os.homedir(),\n): string {\n return path.join(syncDirectory(repoRoot, homeDirectory), RUN_DIRECTORY, String(processId));\n}\n\n/**\n * How a Pi project settings file should refer to a generated path.\n *\n * Relative to `.pi` when the target lives in the repository, which keeps the\n * committed settings file identical on every machine. A doom-pi installed\n * outside the repository stays absolute: Pi accepts both, and a relative path\n * climbing out of the project would be neither portable nor readable.\n */\nexport function settingsRelativePath(repoRoot: string, target: string): string {\n const relative = path.relative(repoRoot, target);\n if (relative.startsWith('..') || path.isAbsolute(relative)) return target;\n return path.relative(path.join(repoRoot, PI_DIRECTORY), target).split(path.sep).join('/');\n}\n\nfunction readIfPresent(filePath: string): string {\n return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : '';\n}\n\nfunction updateFramedHash(hash: ReturnType<typeof crypto.createHash>, label: string, value: string | Buffer): void {\n const bytes = typeof value === 'string' ? Buffer.from(value) : value;\n hash.update(`${String(label.length)}:${label}:${String(bytes.byteLength)}:`);\n hash.update(bytes);\n}\n\n/** Hashes path, existence, and bytes without making absent and empty files aliases. */\nfunction updateFileInputHash(hash: ReturnType<typeof crypto.createHash>, filePath: string): void {\n const absolutePath = path.resolve(filePath);\n updateFramedHash(hash, 'path', absolutePath);\n if (!fs.existsSync(absolutePath)) {\n updateFramedHash(hash, 'state', 'missing');\n return;\n }\n updateFramedHash(hash, 'state', 'present');\n updateFramedHash(hash, 'contents', fs.readFileSync(absolutePath));\n}\n\n/** Package root owning a resolved entry, or undefined when it sits outside one. */\nfunction owningPackageRoot(entryPath: string): string | undefined {\n // The resolved map also carries package-name metadata. Relative metadata must\n // not become a filesystem path whose meaning changes with process.cwd().\n if (!path.isAbsolute(entryPath)) return undefined;\n let directory = path.dirname(entryPath);\n for (;;) {\n if (fs.existsSync(path.join(directory, PACKAGE_MANIFEST_FILE))) return directory;\n const parent = path.dirname(directory);\n if (parent === directory) return undefined;\n directory = parent;\n }\n}\n\n/** Every regular file under a directory, as absolute paths in a stable order. */\nfunction filesUnder(directory: string): string[] {\n if (!fs.existsSync(directory)) return [];\n const found: string[] = [];\n const walk = (current: string): void => {\n for (const entry of fs.readdirSync(current, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {\n const full = path.join(current, entry.name);\n if (entry.isDirectory()) walk(full);\n else if (entry.isFile()) found.push(full);\n }\n };\n walk(directory);\n return found;\n}\n\n/**\n * Hashes the cockpit sources and package versions a sync compiled.\n *\n * The cockpit bundle is built from each installed package's `web/` folder by\n * `syncWebBundle`, straight from source, with no compiler manifest recording\n * what went in. Nothing else in the drift check reads those files, so editing a\n * plugin surface and rebuilding left the hub serving the previously bundled\n * cockpit with nothing reporting a reason. Compiled entries are covered\n * elsewhere, by the content digests in their compiler manifests, so only the\n * entry identity and its package version are folded in here.\n *\n * Bounded on purpose: the web sources of a full composition are a few hundred\n * small files, which is cheap enough for the hub to poll.\n */\nexport function computeWebSourcesHash(resolved: Record<string, string>): string {\n const hash = crypto.createHash('sha256');\n const roots = [...new Set(Object.values(resolved).flatMap((entry) => owningPackageRoot(entry) ?? []))].sort();\n for (const root of roots) {\n updateFramedHash(hash, 'package', root);\n const manifestPath = path.join(root, PACKAGE_MANIFEST_FILE);\n let manifest: { name?: unknown; version?: unknown } = {};\n try {\n manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as { name?: unknown; version?: unknown };\n } catch {\n // An unreadable manifest still contributes its path above, so the package\n // is not silently dropped from the hash; the version simply reads empty\n // and any later repair shows up as a change.\n manifest = {};\n }\n updateFramedHash(hash, 'name', typeof manifest.name === 'string' ? manifest.name : '');\n updateFramedHash(hash, 'version', typeof manifest.version === 'string' ? manifest.version : '');\n for (const file of filesUnder(path.join(root, WEB_PLUGIN_DIRECTORY))) updateFileInputHash(hash, file);\n }\n for (const [name, entry] of Object.entries(resolved).sort(([left], [right]) => left.localeCompare(right))) {\n updateFramedHash(hash, 'entry', `${name}\u0000${entry}`);\n }\n return hash.digest('hex');\n}\n\n/** Include declaration changes even for packages that did not previously expose a server facet. */\nexport function computeServerSourcesHash(resolved: Record<string, string>): string {\n const hash = crypto.createHash('sha256');\n const roots = [...new Set(Object.values(resolved).flatMap((entry) => owningPackageRoot(entry) ?? []))].sort();\n for (const root of roots) {\n const manifestPath = path.join(root, PACKAGE_MANIFEST_FILE);\n updateFileInputHash(hash, manifestPath);\n const manifest: unknown = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n if (!isRecord(manifest) || !isRecord(manifest.doompiServer) || !isRecord(manifest.doompiServer.contracts)) continue;\n // Include missing declarations too: building or repairing a contract must invalidate an incomplete generation.\n for (const file of [manifest.doompiServer.contracts.entry, manifest.doompiServer.contracts.dist]) {\n if (typeof file !== 'string' || !file.startsWith('./') || file.split('/').includes('..') || /[\\\\%?#]/u.test(file))\n continue;\n updateFileInputHash(hash, path.join(root, file));\n }\n }\n for (const [name, entry] of Object.entries(resolved).sort(([left], [right]) => left.localeCompare(right))) {\n updateFramedHash(hash, 'entry', JSON.stringify([name, entry]));\n }\n return hash.digest('hex');\n}\n\n/** Include MCP declarations and their attributed source files in sync freshness. */\nexport function computeMcpSourcesHash(resolved: Record<string, string>): string {\n const hash = crypto.createHash('sha256');\n const roots = [...new Set(Object.values(resolved).flatMap((entry) => owningPackageRoot(entry) ?? []))].sort();\n for (const root of roots) {\n const manifestPath = path.join(root, PACKAGE_MANIFEST_FILE);\n updateFileInputHash(hash, manifestPath);\n const manifest: unknown = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n if (!isRecord(manifest) || !isRecord(manifest.doompiMcp)) continue;\n for (const file of [manifest.doompiMcp.entry, manifest.doompiMcp.dist]) {\n if (typeof file !== 'string' || !file.startsWith('./') || file.split('/').includes('..') || /[\\\\%?#]/u.test(file))\n continue;\n updateFileInputHash(hash, path.join(root, file));\n }\n }\n for (const [name, entry] of Object.entries(resolved).sort(([left], [right]) => left.localeCompare(right))) {\n updateFramedHash(hash, 'entry', JSON.stringify([name, entry]));\n }\n return hash.digest('hex');\n}\n\n/**\n * Hashes the configuration a sync consumed.\n *\n * Deliberately cheap: the extension recomputes this on every session start, so\n * it reads config, marketplace, local plugin manifests, and profile persona text\n * without downloading plugins or re-resolving packages. A dependency upgrade that\n * moves a package path therefore does not show up here; `doom-pi sync --check`\n * re-resolves and is the check that catches that.\n */\nexport function computeInputsHash(\n repoRoot: string,\n selection: SyncSelection,\n homeDirectory: string = os.homedir(),\n environment: NodeJS.ProcessEnv = process.env,\n): string {\n // Match sync publication, including callers that reach the repository through a symlink.\n repoRoot = resolveSyncLocation(repoRoot, homeDirectory).root;\n const hash = crypto.createHash('sha256');\n hash.update(JSON.stringify({ ...selection, domains: [...selection.domains].sort() }));\n if (environment.DOOMPI_DISTRIBUTION === 'desktop') {\n updateFramedHash(hash, 'distribution', 'desktop:computer-use-default-v1');\n }\n // Every .doom document layers the global copy under the repository one, so an\n // edit in either location is a real change.\n for (const directory of [\n path.join(homeDirectory, PI_DIRECTORY, DOOM_CONFIG_DIRECTORY),\n path.join(repoRoot, DOOM_CONFIG_DIRECTORY),\n ]) {\n for (const fileName of HASHED_CONFIG_FILES) hash.update(readIfPresent(path.join(directory, fileName)));\n }\n updateFileInputHash(hash, path.join(repoRoot, '.mcp.json'));\n\n const catalog = loadDomains(repoRoot, homeDirectory).plugins;\n for (const root of catalog.roots) hash.update(root);\n for (const diagnostic of catalog.diagnostics) hash.update(diagnostic);\n for (const marketplace of catalog.marketplaces) {\n hash.update(marketplace);\n hash.update(readIfPresent(marketplace));\n }\n for (const [name, plugin] of Object.entries(catalog.entries).sort(([left], [right]) => left.localeCompare(right))) {\n hash.update(name);\n hash.update(JSON.stringify(plugin.source));\n if (plugin.manifest) {\n hash.update(plugin.manifest.path);\n hash.update(readIfPresent(plugin.manifest.path));\n }\n }\n\n let selectedPluginDirectories: string[] = [];\n try {\n selectedPluginDirectories = [\n ...new Set(\n resolvePluginEntries(repoRoot, selection.domains, [], homeDirectory)\n .filter((plugin) => plugin.mcp !== false)\n .map((plugin) => path.resolve(plugin.directory)),\n ),\n ].sort();\n } catch {\n // The surrounding .doom inputs already make an invalid or removed domain\n // selection stale. Keep this lightweight check readable for old state\n // instead of turning that expected staleness into a startup exception.\n }\n for (const directory of selectedPluginDirectories) {\n for (const fileName of PLUGIN_MCP_CONFIG_FILES) {\n updateFileInputHash(hash, path.join(directory, fileName));\n }\n }\n\n for (const profile of loadProfiles(repoRoot, homeDirectory)) {\n hash.update(profile.name);\n hash.update(profile.personaRoot);\n hash.update(profile.persona);\n hash.update(JSON.stringify(profile.env));\n const personaDirectory = path.resolve(profile.personaRoot, profile.persona);\n for (const fileName of PERSONA_FILES) {\n const filePath = path.join(personaDirectory, fileName);\n hash.update(filePath);\n hash.update(readIfPresent(filePath));\n }\n }\n return hash.digest('hex');\n}\n\nfunction stringRecord(value: unknown, field: string, statePath: string): Record<string, string> {\n if (!isRecord(value)) throw new Error(`Doom sync state at ${statePath} requires ${field} to be an object`);\n return Object.fromEntries(\n Object.entries(value).filter((entry): entry is [string, string] => typeof entry[1] === 'string'),\n );\n}\n\nfunction parsePrecompileState(value: unknown, statePath: string): SyncPrecompileState {\n if (\n !isRecord(value) ||\n value.version !== PRECOMPILE_STATE_VERSION ||\n value.strategy !== 'bundle' ||\n typeof value.bootstrapEntry !== 'string' ||\n typeof value.bootstrapManifest !== 'string' ||\n !isRecord(value.bundleManifests) ||\n Object.entries(value.bundleManifests).some(\n ([fingerprint, manifest]) => !COMPOSITION_FINGERPRINT.test(fingerprint) || typeof manifest !== 'string',\n )\n ) {\n throw new Error(`Doom sync state at ${statePath} has an invalid precompile record`);\n }\n return {\n version: value.version,\n strategy: value.strategy,\n bootstrapEntry: value.bootstrapEntry,\n bootstrapManifest: value.bootstrapManifest,\n bundleManifests: value.bundleManifests as Record<string, string>,\n };\n}\n\nfunction precompileMatchesBundles(\n precompile: SyncPrecompileState,\n bundles: Record<string, string> | undefined,\n): boolean {\n const bundleFingerprints = Object.keys(bundles ?? {}).sort();\n const manifestFingerprints = Object.keys(precompile.bundleManifests).sort();\n return (\n bundleFingerprints.length === manifestFingerprints.length &&\n bundleFingerprints.every((fingerprint, index) => fingerprint === manifestFingerprints[index])\n );\n}\n\ninterface ParseSyncStateOptions {\n repoRoot: string;\n location: SyncLocation;\n legacy: boolean;\n}\n\nfunction identityMatches(left: SyncIdentity, right: SyncIdentity): boolean {\n return left.repositoryId === right.repositoryId && left.worktreeId === right.worktreeId;\n}\n\nfunction parseSyncIdentity(value: unknown, statePath: string): SyncIdentity {\n if (!isRecord(value) || typeof value.repositoryId !== 'string' || typeof value.worktreeId !== 'string') {\n throw new Error(`Doom sync state at ${statePath} requires repository and worktree identity`);\n }\n return { repositoryId: value.repositoryId, worktreeId: value.worktreeId };\n}\n\nfunction parseSyncState(source: string, statePath: string, options: ParseSyncStateOptions): SyncState {\n let parsed: unknown;\n try {\n parsed = JSON.parse(source);\n } catch (error) {\n throw new Error(`Doom sync state at ${statePath} is not valid JSON`, { cause: error });\n }\n if (!isRecord(parsed)) throw new Error(`Doom sync state at ${statePath} must be an object`);\n if (typeof parsed.version !== 'number' || parsed.version !== SYNC_STATE_VERSION) {\n throw new Error(\n `Doom sync state at ${statePath} has version ${String(parsed.version)}, expected ${SYNC_STATE_VERSION}. Run doompi sync.`,\n );\n }\n if (typeof parsed.root !== 'string' || typeof parsed.inputsHash !== 'string') {\n throw new Error(`Doom sync state at ${statePath} requires string root and inputsHash`);\n }\n if (\n typeof parsed.compositionFingerprint !== 'string' ||\n !COMPOSITION_FINGERPRINT.test(parsed.compositionFingerprint)\n ) {\n throw new Error(`Doom sync state at ${statePath} requires a canonical compositionFingerprint`);\n }\n if (parsed.nativeGraphs !== undefined) {\n throw new Error(`Doom sync state at ${statePath} contains removed native graph state. Run doompi sync.`);\n }\n if (!syncStateRootMatches(options.repoRoot, parsed.root)) {\n throw new Error(`Doom sync state at ${statePath} belongs to a different repository: ${parsed.root}`);\n }\n const identity = parseSyncIdentity(parsed.identity, statePath);\n if (!identityMatches(identity, options.location.identity)) {\n throw new Error(`Doom sync state at ${statePath} belongs to a different repository or worktree identity`);\n }\n if (!isRecord(parsed.selection) || typeof parsed.selection.majorMode !== 'string') {\n throw new Error(`Doom sync state at ${statePath} requires a selection with a majorMode`);\n }\n if (!isRecord(parsed.baseline) || typeof parsed.baseline.themePath !== 'string') {\n throw new Error(`Doom sync state at ${statePath} requires a baseline with a themePath`);\n }\n const { majorMode, domains, profile, preset } = parsed.selection;\n const fileState = isRecord(parsed.fileState) ? parsed.fileState : {};\n if (!isDoomMcpProjection(fileState.mcpProjection)) {\n throw new Error(`Doom sync state at ${statePath} requires a valid MCP projection. Run doompi sync.`);\n }\n if (!syncStateRootMatches(parsed.root, fileState.mcpProjection.repoRoot)) {\n throw new Error(`Doom sync state at ${statePath} contains an MCP projection for a different repository`);\n }\n const generatedDirectory = options.legacy ? options.location.legacyDirectory : options.location.directory;\n const compiled = parsed.compiled === undefined ? undefined : stringRecord(parsed.compiled, 'compiled', statePath);\n const bundles = parsed.bundles === undefined ? undefined : stringRecord(parsed.bundles, 'bundles', statePath);\n const precompile = parsed.precompile === undefined ? undefined : parsePrecompileState(parsed.precompile, statePath);\n if (precompile && !precompileMatchesBundles(precompile, bundles)) {\n throw new Error(`Doom sync state at ${statePath} has an invalid precompile record`);\n }\n let serverBundle: SyncServerBundleState | undefined;\n if (parsed.serverBundle !== undefined) {\n const value = parsed.serverBundle;\n if (\n !isRecord(value) ||\n typeof value.descriptorPath !== 'string' ||\n typeof value.fingerprint !== 'string' ||\n !COMPOSITION_FINGERPRINT.test(value.fingerprint) ||\n typeof value.sourcesHash !== 'string' ||\n !COMPOSITION_FINGERPRINT.test(value.sourcesHash)\n ) {\n throw new Error(`Doom sync state at ${statePath} has an invalid server bundle record`);\n }\n const compilerManifests = stringRecord(value.compilerManifests, 'server compiler manifests', statePath);\n if (\n [value.descriptorPath, ...Object.values(compilerManifests)].some((entry) => !isInside(generatedDirectory, entry))\n ) {\n throw new Error(`Doom sync state at ${statePath} references server material outside ${generatedDirectory}`);\n }\n serverBundle = {\n descriptorPath: value.descriptorPath,\n fingerprint: value.fingerprint,\n compilerManifests,\n sourcesHash: value.sourcesHash,\n };\n }\n let mcpBundle: SyncMcpBundleState | undefined;\n if (parsed.mcpBundle !== undefined) {\n const value = parsed.mcpBundle;\n if (\n !isRecord(value) ||\n typeof value.descriptorPath !== 'string' ||\n typeof value.fingerprint !== 'string' ||\n !COMPOSITION_FINGERPRINT.test(value.fingerprint) ||\n typeof value.sourcesHash !== 'string' ||\n !COMPOSITION_FINGERPRINT.test(value.sourcesHash)\n ) {\n throw new Error(`Doom sync state at ${statePath} has an invalid MCP bundle record`);\n }\n const compilerManifests = stringRecord(value.compilerManifests, 'MCP compiler manifests', statePath);\n if (\n [value.descriptorPath, ...Object.values(compilerManifests)].some((entry) => !isInside(generatedDirectory, entry))\n ) {\n throw new Error(`Doom sync state at ${statePath} references MCP material outside ${generatedDirectory}`);\n }\n mcpBundle = {\n descriptorPath: value.descriptorPath,\n fingerprint: value.fingerprint,\n compilerManifests,\n sourcesHash: value.sourcesHash,\n };\n }\n const bootstrap = typeof parsed.bootstrap === 'string' ? parsed.bootstrap : undefined;\n const generatedPaths = [bootstrap, ...Object.values(compiled ?? {}), ...Object.values(bundles ?? {})].filter(\n (entry): entry is string => entry !== undefined,\n );\n if (generatedPaths.some((entry) => !isInside(generatedDirectory, entry))) {\n throw new Error(`Doom sync state at ${statePath} references generated material outside ${generatedDirectory}`);\n }\n return {\n version: parsed.version,\n root: parsed.root,\n identity,\n inputsHash: parsed.inputsHash,\n webSourcesHash: typeof parsed.webSourcesHash === 'string' ? parsed.webSourcesHash : undefined,\n compositionFingerprint: parsed.compositionFingerprint,\n selection: {\n majorMode,\n domains: Array.isArray(domains) ? domains.filter((name): name is string => typeof name === 'string') : [],\n profile: typeof profile === 'string' ? profile : undefined,\n preset: typeof preset === 'string' ? preset : DEFAULT_PRESET,\n },\n env: stringRecord(parsed.env, 'env', statePath),\n fileState: {\n profileEnvironment: isRecord(fileState.profileEnvironment)\n ? (fileState.profileEnvironment as Record<string, string>)\n : {},\n pluginHooks: Array.isArray(fileState.pluginHooks) ? (fileState.pluginHooks as HarnessState['pluginHooks']) : [],\n mcpProjection: fileState.mcpProjection,\n ...(isRecord(fileState.hookModules) && typeof fileState.hookModules.file === 'string'\n ? { hookModules: { file: fileState.hookModules.file } }\n : {}),\n },\n resolved: stringRecord(parsed.resolved, 'resolved', statePath),\n compiled,\n bundles,\n bootstrap,\n precompile,\n ...(serverBundle ? { serverBundle } : {}),\n ...(mcpBundle ? { mcpBundle } : {}),\n baseline: parsed.baseline as unknown as SyncBaseline,\n };\n}\n\nexport interface LocatedSyncState {\n state: SyncState;\n location: SyncLocation;\n layout: 'global';\n}\n\n/** Reads one exact admitted registration, even after the worktree's current registration moves on. */\nexport function readRegisteredSyncState(\n registration: SyncRegistration,\n homeDirectory: string = os.homedir(),\n): SyncState {\n const location = resolveSyncLocation(registration.root, homeDirectory);\n validateSyncRegistration(registration, location);\n return parseSyncState(fs.readFileSync(registration.statePath, 'utf8'), registration.statePath, {\n repoRoot: registration.root,\n location,\n legacy: false,\n });\n}\n\n/** Reads only state reached through this repository/worktree's validated registration. */\nexport function readLocatedSyncState(\n repoRoot: string,\n homeDirectory: string = os.homedir(),\n): LocatedSyncState | undefined {\n const location = resolveSyncLocation(repoRoot, homeDirectory);\n const registration = readSyncRegistration(repoRoot, homeDirectory);\n if (!registration) return undefined;\n return {\n state: readRegisteredSyncState(registration, homeDirectory),\n location,\n layout: 'global',\n };\n}\n\n/** Reads the synced state, or undefined when the repository was never synced. */\nexport function readSyncState(repoRoot: string, homeDirectory: string = os.homedir()): SyncState | undefined {\n return readLocatedSyncState(repoRoot, homeDirectory)?.state;\n}\n\nexport function serializeSyncState(state: SyncState): string {\n return `${JSON.stringify(state, null, 2)}\\n`;\n}\n\nexport async function writeSyncState(\n repoRoot: string,\n state: SyncState,\n homeDirectory: string = os.homedir(),\n targetPath?: string,\n): Promise<string> {\n const location = resolveSyncLocation(repoRoot, homeDirectory);\n const statePath = targetPath ?? location.statePath;\n if (state.version !== SYNC_STATE_VERSION) {\n throw new Error(`Doom sync state writes require version ${SYNC_STATE_VERSION}`);\n }\n if (!COMPOSITION_FINGERPRINT.test(state.compositionFingerprint)) {\n throw new Error('Doom sync state writes require a canonical composition fingerprint');\n }\n if (!isDoomMcpProjection(state.fileState.mcpProjection)) {\n throw new Error('Doom sync state writes require a valid MCP projection');\n }\n if (!syncStateRootMatches(state.root, state.fileState.mcpProjection.repoRoot)) {\n throw new Error('Refusing to write a Doom sync state whose MCP projection belongs to another repository');\n }\n if (!syncStateRootMatches(repoRoot, state.root) || !identityMatches(state.identity, location.identity)) {\n throw new Error('Refusing to write Doom sync state for a different repository or worktree');\n }\n if (state.precompile) {\n const precompile = parsePrecompileState(state.precompile, statePath);\n if (!precompileMatchesBundles(precompile, state.bundles)) {\n throw new Error(`Doom sync state at ${statePath} has an invalid precompile record`);\n }\n }\n if (!isInside(location.directory, statePath)) {\n throw new Error(`Refusing to write Doom sync state outside ${location.directory}`);\n }\n assertSyncLocationSafe(location);\n await fs.promises.mkdir(path.dirname(statePath), { mode: PRIVATE_DIRECTORY_MODE, recursive: true });\n const temporaryPath = `${statePath}.${process.pid}.${crypto.randomUUID()}.tmp`;\n try {\n await fs.promises.writeFile(temporaryPath, serializeSyncState(state), { mode: PRIVATE_FILE_MODE });\n await fs.promises.rename(temporaryPath, statePath);\n } catch (error) {\n await fs.promises.rm(temporaryPath, { force: true });\n throw error;\n }\n return statePath;\n}\n\nexport function ownKey(name: string): string {\n return `${OWN_PREFIX}${name}`;\n}\n\nexport function packageKey(specifier: string): string {\n return `${PACKAGE_PREFIX}${specifier}`;\n}\n\nexport function packageEntryKey(specifier: string, index: number): string {\n return index === 0 ? packageKey(specifier) : `${packageKey(specifier)}${ENTRY_INDEX_SEPARATOR}${index}`;\n}\n\n/**\n * Keyed by the absolute target, because the same relative specifier means\n * different files under the repository and the global config directory.\n */\nexport function localKey(specifier: string, baseDirectory: string): string {\n return `${LOCAL_PREFIX}${path.resolve(baseDirectory, specifier)}`;\n}\n\nexport function localEntryKey(specifier: string, baseDirectory: string, index: number): string {\n return index === 0\n ? localKey(specifier, baseDirectory)\n : `${localKey(specifier, baseDirectory)}${ENTRY_INDEX_SEPARATOR}${index}`;\n}\n\nexport function localPackageNameKey(specifier: string, baseDirectory: string): string {\n return `${LOCAL_PACKAGE_NAME_PREFIX}${path.resolve(baseDirectory, specifier)}`;\n}\n\nexport interface RecordingResolvers extends ExtensionLayerResolvers {\n /** Every name this resolver was asked for, keyed for the state file. */\n readonly resolved: Record<string, string>;\n packageEntries(name: string): string[];\n optionalPackageEntries(name: string): string[] | undefined;\n localEntries(specifier: string, baseDirectory: string): string[] | undefined;\n}\n\n/**\n * Resolvers that record what they resolve.\n *\n * Sync composes once with every layer selected and hands the recording to the\n * state file, so the extension never has to resolve a specifier itself.\n */\nexport function createRecordingResolvers(base: LayerResolvers = LAYER_RESOLVERS): RecordingResolvers {\n const resolved: Record<string, string> = {};\n const extensionBase = base as ExtensionLayerResolvers;\n const recordEntries = (entries: string[], keyFor: (index: number) => string): string[] => {\n entries.forEach((entry, index) => {\n resolved[keyFor(index)] = entry;\n });\n return entries;\n };\n return {\n resolved,\n ownEntry(name) {\n const entry = base.ownEntry(name);\n resolved[ownKey(name)] = entry;\n return entry;\n },\n packageEntry(name) {\n const entry = base.packageEntry(name);\n resolved[packageKey(name)] = entry;\n return entry;\n },\n optionalPackageEntry(name) {\n const entry = base.optionalPackageEntry(name);\n // A miss is recorded by omission, which is what later makes the extension\n // treat it as absent instead of failing the whole composition.\n if (entry) resolved[packageKey(name)] = entry;\n return entry;\n },\n packageEntries(name) {\n const entries = extensionBase.packageEntries?.(name) ?? [base.packageEntry(name)];\n return recordEntries(entries, (index) => packageEntryKey(name, index));\n },\n optionalPackageEntries(name) {\n let entries = extensionBase.optionalPackageEntries?.(name);\n if (entries === undefined) {\n const entry = base.optionalPackageEntry(name);\n entries = entry ? [entry] : undefined;\n }\n return entries ? recordEntries(entries, (index) => packageEntryKey(name, index)) : undefined;\n },\n localEntry(specifier, baseDirectory) {\n const entry = base.localEntry(specifier, baseDirectory);\n if (entry) resolved[localKey(specifier, baseDirectory)] = entry;\n return entry;\n },\n localEntries(specifier, baseDirectory) {\n let entries = extensionBase.localEntries?.(specifier, baseDirectory);\n if (entries === undefined) {\n const entry = base.localEntry(specifier, baseDirectory);\n entries = entry ? [entry] : undefined;\n }\n return entries ? recordEntries(entries, (index) => localEntryKey(specifier, baseDirectory, index)) : undefined;\n },\n localPackageName(specifier, baseDirectory) {\n const name = extensionBase.localPackageName?.(specifier, baseDirectory);\n if (name) resolved[localPackageNameKey(specifier, baseDirectory)] = name;\n return name;\n },\n };\n}\n\n/**\n * Resolves every entry any layer could contribute, in one pass.\n *\n * Composing with every layer selected and the widest options is what makes the\n * map complete: a later `/mode` switch inside a Pi session can then pick a\n * different set without resolving anything itself. The persona entry is asked\n * for separately because it remains a fixed host entry rather than a layer.\n */\nexport function recordResolvedEntries(\n majorModesConfig: MajorModesConfig,\n base: LayerResolvers = LAYER_RESOLVERS,\n): Record<string, string> {\n const recording = createRecordingResolvers(base);\n recording.packageEntry(PERSONA_ENTRY);\n assembleExtensions({\n agents: true,\n autoStop: true,\n mute: false,\n // The one preset that contributes an extension of its own.\n preset: OLLAMA_PRESET,\n layers: Object.keys(majorModesConfig.layers),\n majorModesConfig,\n resolvers: recording,\n });\n assembleChildExtensions({\n agents: false,\n autoStop: false,\n mute: true,\n preset: OLLAMA_PRESET,\n layers: Object.keys(majorModesConfig.layers),\n majorModesConfig,\n resolvers: recording,\n });\n return recording.resolved;\n}\n\n/** Resolvers backed by a synced map, for composing inside a Pi session. */\nexport function createMapResolvers(\n resolved: Record<string, string>,\n compiled: Record<string, string> = {},\n): ExtensionLayerResolvers {\n // The compiled bundle when this entry has one, the source otherwise.\n const entryFor = (key: string): string | undefined => compiled[key] ?? resolved[key];\n const lookup = (key: string, name: string): string => {\n const entry = entryFor(key);\n if (!entry) throw new Error(`${name} is missing from the doompi sync state. Run doompi sync.`);\n return entry;\n };\n const indexedEntries = (keyFor: (index: number) => string): string[] | undefined => {\n const first = entryFor(keyFor(0));\n if (!first) return undefined;\n const entries = [first];\n for (let index = 1; ; index += 1) {\n const entry = entryFor(keyFor(index));\n if (!entry) break;\n entries.push(entry);\n }\n return entries;\n };\n return {\n ownEntry: (name) => lookup(ownKey(name), name),\n packageEntry: (name) => lookup(packageKey(name), name),\n optionalPackageEntry: (name) => entryFor(packageKey(name)),\n packageEntries: (name) => {\n const entries = indexedEntries((index) => packageEntryKey(name, index));\n if (!entries) throw new Error(`${name} is missing from the doompi sync state. Run doompi sync.`);\n return entries;\n },\n optionalPackageEntries: (name) => indexedEntries((index) => packageEntryKey(name, index)),\n localEntry: (specifier, baseDirectory) => entryFor(localKey(specifier, baseDirectory)),\n localEntries: (specifier, baseDirectory) =>\n indexedEntries((index) => localEntryKey(specifier, baseDirectory, index)),\n localPackageName: (specifier, baseDirectory) => resolved[localPackageNameKey(specifier, baseDirectory)],\n };\n}\n\n/** Reads the resolved MCP servers back out of a generated config. */\nexport function readMcpServerNames(configPath: string): string[] {\n if (!fs.existsSync(configPath)) return [];\n const config = JSON.parse(fs.readFileSync(configPath, 'utf8')) as JsonObject;\n return isRecord(config.mcpServers) ? Object.keys(config.mcpServers) : [];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAM,eAAe;;AAErB,MAAM,wBAAwB;AAC9B,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;AACvB,MAAM,oBAAoB;AAC1B,MAAM,yBAAyB;AAC/B,MAAM,aAAa;AACnB,MAAM,iBAAiB;AACvB,MAAM,eAAe;AACrB,MAAM,4BAA4B;AAClC,MAAM,wBAAwB;AAC9B,MAAM,0BAA0B;AAChC,MAAM,0BAA0B,CAAC,aAAa,UAAU;AACxD,MAAM,wBAAwB;;AAE9B,MAAM,uBAAuB;;AAG7B,MAAM,sBAAsB;CAAC;CAAe;CAAc;CAAgB;CAAiB;AAAY;AA+FvG,SAAgB,cAAc,UAAkB,gBAAwBA,QAAAA,QAAG,QAAQ,GAAW;CAC5F,QAAA,GAAOC,oCAAAA,oBAAAA,CAAoB,UAAU,aAAa,CAAC,CAAC;AACtD;AAEA,SAAgB,cAAc,UAAkB,gBAAwBD,QAAAA,QAAG,QAAQ,GAAW;CAC5F,QAAA,GACEE,wCAAAA,qBA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,WAAW,kBAAkB,SAAS,SAAS,WAAW,aAAa,CAAC;EACrF,eAAe,WAAW,kBACxB,gBAAgB,UAAU,cAAc,WAAW,eAAe,KAAK,CAAC;EAC1E,mBAAmB,WAAW,kBAAkB,SAAS,oBAAoB,WAAW,aAAa;CACvG;AACF;;AAGA,SAAgB,mBAAmB,YAA8B;CAC/D,IAAI,CAACZ,QAAAA,QAAG,WAAW,UAAU,GAAG,OAAO,CAAC;CACxC,MAAM,SAAS,KAAK,MAAMA,QAAAA,QAAG,aAAa,YAAY,MAAM,CAAC;CAC7D,QAAA,GAAOE,mCAAAA,SAAAA,CAAS,OAAO,UAAU,IAAI,OAAO,KAAK,OAAO,UAAU,IAAI,CAAC;AACzE"}
@@ -68,7 +68,7 @@ export interface SyncState {
68
68
  * Plugin hooks, the profile's environment defaults, and the neutral MCP
69
69
  * projection live in the session state file rather than in variables.
70
70
  */
71
- fileState: Pick<HarnessState, 'profileEnvironment' | 'pluginHooks'> & {
71
+ fileState: Pick<HarnessState, 'profileEnvironment' | 'pluginHooks' | 'hookModules'> & {
72
72
  mcpProjection: DoomMcpProjection;
73
73
  };
74
74
  /** Entry name to absolute path, covering every layer, not just the selected mode's. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../src/composition/syncState/index.ts"],"mappings":";;;;;;;;iBAmEiB;EACf;EACA;EACA;EACA;;;iBAIe;EACf;EACA;EACA;EACA;;iBAGe;;EAEf;EACA;;EAEA;;EAEA;;EAEA,iBAAiB;;iBAGF;EACf;EACA;EACA,mBAAmB;EACnB;;iBAGe;EACf;EACA;EACA,mBAAmB;EACnB;;iBAGe;EACf;EACA;;EAEA,UAAU;;EAEV;;;;;;;;EAQA;;EAEA;EACA,WAAW;;EAEX,KAAK;;;;;;;EAOL,WAAW,KAAK;IACd,eAAe;;;EAGjB,UAAU;;;;;;;;EAQV,WAAW;;EAEX,UAAU;;EAEV;;EAEA,aAAa;;EAEb,eAAe;;EAEf,YAAY;EACZ,UAAU;;wBAGI,cAAc,kBAAkB;wBAIhC,cAAc,kBAAkB;wBAMhC,oBAAoB;wBAIpB,oBAAoB;;wBAqBpB,qBAAqB,kBAAkB;;;;;;;;;wBAYvC,aACd,kBACA,oBACA;;;;;;;;;wBAac,qBAAqB,kBAAkB;;;;;;;;;;;;;;;wBAuEvC,sBAAsB,UAAU;;wBA0BhC,yBAAyB,UAAU;;wBAsBnC,sBAAsB,UAAU;;;;;;;;;;wBA6BhC,kBACd,kBACA,WAAW,eACX,wBACA,cAAa,OAAO;iBAiRL;EACf,OAAO;EACP,UAAU;EACV;;;wBAIc,wBACd,cAAc,kBACd,yBACC;;wBAWa,qBACd,kBACA,yBACC;;wBAYa,cAAc,kBAAkB,yBAAuC;wBAIvE,mBAAmB,OAAO;wBAIpB,eACpB,kBACA,OAAO,WACP,wBACA,sBACC;wBAwCa,OAAO;wBAIP,WAAW;wBAIX,gBAAgB,mBAAmB;;;;;wBAQnC,SAAS,mBAAmB;wBAI5B,cAAc,mBAAmB,uBAAuB;wBAMxD,oBAAoB,mBAAmB;iBAItC,2BAA2B;;WAEjC,UAAU;EACnB,eAAe;EACf,uBAAuB;EACvB,aAAa,mBAAmB;;;;;;;;wBASlB,yBAAyB,OAAM,iBAAmC;;;;;;;;;wBAqElE,sBACd,kBAAkB,kBAClB,OAAM,iBACL;;wBA0Ba,mBACd,UAAU,wBACV,WAAU,yBACT;;wBAqCa,mBAAmB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../../src/composition/syncState/index.ts"],"mappings":";;;;;;;;iBAmEiB;EACf;EACA;EACA;EACA;;;iBAIe;EACf;EACA;EACA;EACA;;iBAGe;;EAEf;EACA;;EAEA;;EAEA;;EAEA,iBAAiB;;iBAGF;EACf;EACA;EACA,mBAAmB;EACnB;;iBAGe;EACf;EACA;EACA,mBAAmB;EACnB;;iBAGe;EACf;EACA;;EAEA,UAAU;;EAEV;;;;;;;;EAQA;;EAEA;EACA,WAAW;;EAEX,KAAK;;;;;;;EAOL,WAAW,KAAK;IACd,eAAe;;;EAGjB,UAAU;;;;;;;;EAQV,WAAW;;EAEX,UAAU;;EAEV;;EAEA,aAAa;;EAEb,eAAe;;EAEf,YAAY;EACZ,UAAU;;wBAGI,cAAc,kBAAkB;wBAIhC,cAAc,kBAAkB;wBAMhC,oBAAoB;wBAIpB,oBAAoB;;wBAqBpB,qBAAqB,kBAAkB;;;;;;;;;wBAYvC,aACd,kBACA,oBACA;;;;;;;;;wBAac,qBAAqB,kBAAkB;;;;;;;;;;;;;;;wBAuEvC,sBAAsB,UAAU;;wBA0BhC,yBAAyB,UAAU;;wBAsBnC,sBAAsB,UAAU;;;;;;;;;;wBA6BhC,kBACd,kBACA,WAAW,eACX,wBACA,cAAa,OAAO;iBAoRL;EACf,OAAO;EACP,UAAU;EACV;;;wBAIc,wBACd,cAAc,kBACd,yBACC;;wBAWa,qBACd,kBACA,yBACC;;wBAYa,cAAc,kBAAkB,yBAAuC;wBAIvE,mBAAmB,OAAO;wBAIpB,eACpB,kBACA,OAAO,WACP,wBACA,sBACC;wBAwCa,OAAO;wBAIP,WAAW;wBAIX,gBAAgB,mBAAmB;;;;;wBAQnC,SAAS,mBAAmB;wBAI5B,cAAc,mBAAmB,uBAAuB;wBAMxD,oBAAoB,mBAAmB;iBAItC,2BAA2B;;WAEjC,UAAU;EACnB,eAAe;EACf,uBAAuB;EACvB,aAAa,mBAAmB;;;;;;;;wBASlB,yBAAyB,OAAM,iBAAmC;;;;;;;;;wBAqElE,sBACd,kBAAkB,kBAClB,OAAM,iBACL;;wBA0Ba,mBACd,UAAU,wBACV,WAAU,yBACT;;wBAqCa,mBAAmB"}
@@ -367,7 +367,8 @@ function parseSyncState(source, statePath, options) {
367
367
  fileState: {
368
368
  profileEnvironment: isRecord(fileState.profileEnvironment) ? fileState.profileEnvironment : {},
369
369
  pluginHooks: Array.isArray(fileState.pluginHooks) ? fileState.pluginHooks : [],
370
- mcpProjection: fileState.mcpProjection
370
+ mcpProjection: fileState.mcpProjection,
371
+ ...isRecord(fileState.hookModules) && typeof fileState.hookModules.file === "string" ? { hookModules: { file: fileState.hookModules.file } } : {}
371
372
  },
372
373
  resolved: stringRecord(parsed.resolved, "resolved", statePath),
373
374
  compiled,