{"version":3,"file":"harnessStore-CEGS2XsW.cjs","names":["path","HARNESS_STATE_KEYS","fs","readHarnessState","readPoSessionEnvironment","os","createSerialRunner","readTextIfExists","nodeHost","readHarnessState","writePrivateAtomicJsonAsync","path","removePath","HARNESS_STATE_KEYS"],"sources":["../src/models/harnessCache.ts","../src/services/harnessStore/core.ts","../src/services/harnessStore/sync.ts","../src/services/harnessStore/index.ts"],"sourcesContent":["import type { HarnessState } from '../types/config';\n\nexport interface LoadedHarnessState {\n  /** Undefined when this process is running off the environment fallback. */\n  filePath?: string;\n  owned: boolean;\n  state: HarnessState;\n}\n\nexport interface CachedHarnessState extends LoadedHarnessState {\n  /** The file's mtime when it was read, so a rewrite by another copy is noticed. */\n  mtimeMs?: number;\n}\n\nexport const harnessCache: { loaded: CachedHarnessState | undefined } = { loaded: undefined };\n","import path from 'node:path';\n\nimport { harnessCache, type LoadedHarnessState } from '../../models/harnessCache';\nimport type { HarnessState } from '../../types/config';\nimport { HARNESS_STATE_KEYS } from '../harnessState';\n\n/** Points at the state file. The one variable that is not derived. */\nexport const HARNESS_STATE_POINTER = 'PO_STATE';\n\nconst STATE_FILE_VERSION = 1;\nconst STATE_FILE_NAME = 'harness-state.json';\nconst ADOPTED_DIRECTORY = 'po-harness';\n/**\n * Written for a process that does not exist yet, so the first one to read it\n * owns it. A spawner cannot know its child's pid, and a child that inherited\n * its parent's file would lose it the moment the parent cleaned up.\n */\nexport const UNCLAIMED_OWNER = 0;\n\nexport interface HarnessStateFile {\n  version: number;\n  owner: { pid: number; startedAt: string };\n  state: HarnessState;\n}\n\nexport interface HarnessStateTransactionSnapshot {\n  readonly filePath?: string;\n  readonly owned: boolean;\n  readonly state: HarnessState;\n  readonly environment: Readonly<Record<string, string | undefined>>;\n}\n\n/** Drops the cached state. For tests, and for a process changing identity. */\nexport function resetHarnessStore(): void {\n  harnessCache.loaded = undefined;\n}\n\nexport function parseStateFile(source: string, filePath: string): HarnessStateFile {\n  const parsed = JSON.parse(source) as Partial<HarnessStateFile>;\n  if (parsed.version !== STATE_FILE_VERSION) {\n    throw new Error(\n      `Harness state at ${filePath} has version ${String(parsed.version)}, expected ${STATE_FILE_VERSION}`,\n    );\n  }\n  if (typeof parsed.state !== 'object' || parsed.state === null) {\n    throw new Error(`Harness state at ${filePath} has no state object`);\n  }\n  return {\n    version: STATE_FILE_VERSION,\n    owner: { pid: parsed.owner?.pid ?? -1, startedAt: parsed.owner?.startedAt ?? '' },\n    state: parsed.state as HarnessState,\n  };\n}\n\n/** Whether a process may write the file in place rather than copying it first. */\nexport function ownsStateFile(file: HarnessStateFile, processId: number): boolean {\n  return file.owner.pid === processId || file.owner.pid === UNCLAIMED_OWNER;\n}\n\nexport function stateFileDocument(state: HarnessState, ownerPid: number): HarnessStateFile {\n  return { version: STATE_FILE_VERSION, owner: { pid: ownerPid, startedAt: new Date().toISOString() }, state };\n}\n\nexport function stateFilePath(directory: string): string {\n  return path.join(directory, STATE_FILE_NAME);\n}\n\n/** Where a process writes state when it was not given a file of its own. */\nexport function adoptedStateFilePath(temporaryDirectory: string, processId: number): string {\n  return path.join(temporaryDirectory, ADOPTED_DIRECTORY, `${String(processId)}.json`);\n}\n\n/** Captures a loaded state together with the pointer and every projected harness variable. */\nexport function snapshotFrom(\n  loaded: LoadedHarnessState,\n  environment: NodeJS.ProcessEnv,\n): HarnessStateTransactionSnapshot {\n  const environmentSnapshot: Record<string, string | undefined> = {\n    [HARNESS_STATE_POINTER]: environment[HARNESS_STATE_POINTER],\n  };\n  for (const key of Object.values(HARNESS_STATE_KEYS)) environmentSnapshot[key] = environment[key];\n  return {\n    filePath: loaded.filePath,\n    owned: loaded.owned,\n    state: structuredClone(loaded.state),\n    environment: environmentSnapshot,\n  };\n}\n","// sync: Preserve exported Node-only harness state signatures until their consumers migrate in phase 2.\nimport fs from 'node:fs';\nimport os from 'node:os';\n\nimport { readPoSessionEnvironment } from '@agimon-ai/po-core/cordisHost';\n\nimport { harnessCache, type CachedHarnessState, type LoadedHarnessState } from '../../models/harnessCache';\nimport type { HarnessState } from '../../types/config';\nimport { writePrivateAtomicJson } from '../atomicJson';\nimport { projectHarnessEnvironment, readHarnessState, type HarnessStateParseReporter } from '../harnessState';\nimport {\n  HARNESS_STATE_POINTER,\n  UNCLAIMED_OWNER,\n  adoptedStateFilePath,\n  ownsStateFile,\n  parseStateFile,\n  resetHarnessStore,\n  snapshotFrom,\n  stateFileDocument,\n  stateFilePath,\n  type HarnessStateTransactionSnapshot,\n} from './core';\n\nfunction fileMtime(filePath: string): number | undefined {\n  try {\n    return fs.statSync(filePath).mtimeMs;\n  } catch {\n    return undefined;\n  }\n}\n\n/**\n * Whether the cache still describes what the process points at.\n *\n * A session can load more than one copy of this package (a layer package\n * installed under .pi/npm brings its own), and each copy caches on its own.\n * The pointer and the file are shared, so a switch persisted through one copy\n * moves the pointer or rewrites the file, and every other copy must notice\n * rather than answer from memory.\n */\nfunction cacheCurrent(cache: CachedHarnessState, environment: NodeJS.ProcessEnv): boolean {\n  const pointer = environment[HARNESS_STATE_POINTER];\n  if (cache.filePath !== pointer) return false;\n  if (!cache.filePath) return true;\n  try {\n    return fs.statSync(cache.filePath).mtimeMs === cache.mtimeMs;\n  } catch {\n    return false;\n  }\n}\n\n/**\n * Reads the state for this process, once.\n *\n * A missing pointer means nobody wrote a file for this process, so the\n * environment is all there is: a nested run, a third-party spawn, or a caller\n * older than the store. A pointer that cannot be read is reported and then\n * treated the same way, because a session that starts degraded beats a session\n * that does not start at all.\n *\n * @deprecated Node-only sync shim; use loadHarnessStateAsync. Removed in M2.\n */\nexport function loadHarnessState(\n  environment: NodeJS.ProcessEnv = process.env,\n  report?: HarnessStateParseReporter,\n): LoadedHarnessState {\n  // The cache describes this process. Asking about another environment is a\n  // question about another process, so it reads through rather than answering\n  // from what this one happens to hold.\n  const cacheable = environment === process.env;\n  if (cacheable && harnessCache.loaded && cacheCurrent(harnessCache.loaded, environment)) return harnessCache.loaded;\n\n  const filePath = environment[HARNESS_STATE_POINTER];\n  let result: CachedHarnessState | undefined;\n  if (filePath && fs.existsSync(filePath)) {\n    try {\n      const file = parseStateFile(fs.readFileSync(filePath, 'utf8'), filePath);\n      result = { filePath, owned: ownsStateFile(file, process.pid), state: file.state, mtimeMs: fileMtime(filePath) };\n    } catch (error) {\n      report?.(HARNESS_STATE_POINTER, error);\n    }\n  }\n  result ??= { owned: false, state: readHarnessState(environment, report) };\n  if (cacheable) harnessCache.loaded = result;\n  return result;\n}\n\n/**\n * Captures the owned state pointer and every projected harness variable.\n *\n * @deprecated Node-only sync shim; use snapshotHarnessStateAsync. Removed in M2.\n */\nexport function snapshotHarnessState(environment: NodeJS.ProcessEnv = process.env): HarnessStateTransactionSnapshot {\n  return snapshotFrom(loadHarnessState(environment), environment);\n}\n\n/**\n * Restores a snapshot only while the current process still owns its state pointer.\n *\n * @deprecated Node-only sync shim. Removed in M2.\n */\nexport function restoreHarnessStateSnapshot(\n  snapshot: HarnessStateTransactionSnapshot,\n  environment: NodeJS.ProcessEnv = process.env,\n): void {\n  const current = loadHarnessState(environment);\n  if (snapshot.filePath && snapshot.owned) {\n    if (!current.owned || current.filePath !== snapshot.filePath) {\n      throw new Error('Harness state ownership changed; refusing to restore an older snapshot.');\n    }\n    persist(snapshot.filePath, snapshot.state);\n  } else if (!snapshot.filePath) {\n    if (current.filePath && !current.owned) {\n      throw new Error('Harness state is no longer owned by this process; refusing to restore an older snapshot.');\n    }\n    if (current.filePath && current.owned) fs.rmSync(current.filePath, { force: true });\n    resetHarnessStore();\n  } else if (current.filePath !== snapshot.filePath) {\n    throw new Error('Harness state pointer changed; refusing to restore an older snapshot.');\n  }\n  for (const [key, value] of Object.entries(snapshot.environment)) {\n    if (value === undefined) delete environment[key];\n    else environment[key] = value;\n  }\n  if (environment === process.env) {\n    harnessCache.loaded = snapshot.filePath\n      ? {\n          filePath: snapshot.filePath,\n          owned: snapshot.owned,\n          state: snapshot.state,\n          mtimeMs: fileMtime(snapshot.filePath),\n        }\n      : undefined;\n  }\n}\n\n/** @deprecated Node-only sync shim; use loadHarnessStateAsync. Removed in M2. */\nexport function getHarnessState(report?: HarnessStateParseReporter): HarnessState {\n  return loadHarnessState(process.env, report).state;\n}\n\n/**\n * The harness state of one session, by id.\n *\n * A server runs many sessions' extensions in one process, each with its own state file, so\n * a session-scoped reader asks by session id. A terminal session owns its process, and the\n * answer is the same as `getHarnessState`.\n *\n * @deprecated Node-only sync shim; use loadHarnessStateAsync with readPoSessionEnvironment. Removed in M2.\n */\nexport function getSessionHarnessState(\n  sessionId: string | undefined,\n  report?: HarnessStateParseReporter,\n): HarnessState {\n  return loadHarnessState(readPoSessionEnvironment(sessionId), report).state;\n}\n\nfunction persist(filePath: string, state: HarnessState, ownerPid = process.pid): void {\n  writePrivateAtomicJson(filePath, stateFileDocument(state, ownerPid));\n}\n\n/**\n * Starts a session: writes the file and publishes the derived environment.\n *\n * The environment is a parameter because the caller is usually describing a\n * process other than itself. The launcher builds the environment for the Pi it\n * is about to spawn, and Po Team builds the snapshot for a detached child, so\n * neither should touch its own `process.env` to do it.\n *\n * @deprecated Node-only sync shim; use createHarnessSessionAsync. Removed in M2.\n */\nexport function createHarnessSession(\n  state: HarnessState,\n  options: {\n    directory: string;\n    environment: NodeJS.ProcessEnv;\n    /**\n     * Leave the file for a process that does not exist yet to claim.\n     *\n     * What a spawner wants: the child owns its state from its first read, in a\n     * directory the spawner manages, so the parent cleaning up its own session\n     * cannot pull the file out from under a detached run.\n     */\n    unclaimed?: boolean;\n  },\n): string {\n  const filePath = stateFilePath(options.directory);\n  persist(filePath, state, options.unclaimed ? UNCLAIMED_OWNER : process.pid);\n  options.environment[HARNESS_STATE_POINTER] = filePath;\n  projectHarnessEnvironment(state, options.environment);\n  // Only prime the cache when this process is the one being described.\n  if (!options.unclaimed && options.environment === process.env)\n    harnessCache.loaded = { filePath, owned: true, state, mtimeMs: fileMtime(filePath) };\n  return filePath;\n}\n\n/**\n * Applies a patch to this process's state.\n *\n * Copy on write: a process holding a file it does not own writes its own copy\n * and repoints itself at it, so a child can never rewrite its parent's session.\n *\n * @deprecated Node-only sync shim; use updateHarnessStateAsync. Removed in M2.\n */\nexport function updateHarnessState(\n  patch: Partial<HarnessState>,\n  environment: NodeJS.ProcessEnv = process.env,\n): HarnessState {\n  const current = loadHarnessState(environment);\n  const state = { ...current.state, ...patch };\n  const filePath =\n    current.owned && current.filePath ? current.filePath : adoptedStateFilePath(os.tmpdir(), process.pid);\n  persist(filePath, state);\n  environment[HARNESS_STATE_POINTER] = filePath;\n  if (environment === process.env) harnessCache.loaded = { filePath, owned: true, state, mtimeMs: fileMtime(filePath) };\n  projectHarnessEnvironment(patch, environment);\n  return state;\n}\n\n/**\n * Removes this process's own state file. Safe when there is none.\n *\n * @deprecated Node-only sync shim; use disposeHarnessStateAsync. Removed in M2.\n */\nexport function disposeHarnessState(environment: NodeJS.ProcessEnv = process.env): void {\n  const current = harnessCache.loaded;\n  resetHarnessStore();\n  if (!current?.owned || !current.filePath) return;\n  fs.rmSync(current.filePath, { force: true });\n  delete environment[HARNESS_STATE_POINTER];\n}\n","import path from 'node:path';\n\nimport {\n  createSerialRunner,\n  nodeHost,\n  readTextIfExists,\n  removePath,\n  type FileSystem,\n} from '@agimon-ai/po-core/platform';\n\nimport type { LoadedHarnessState } from '../../models/harnessCache';\nimport type { HarnessState } from '../../types/config';\nimport { writePrivateAtomicJsonAsync } from '../atomicJson';\nimport {\n  HARNESS_STATE_KEYS,\n  projectHarnessEnvironment,\n  readHarnessState,\n  type HarnessStateParseReporter,\n} from '../harnessState';\nimport {\n  HARNESS_STATE_POINTER,\n  UNCLAIMED_OWNER,\n  adoptedStateFilePath,\n  ownsStateFile,\n  parseStateFile,\n  snapshotFrom,\n  stateFileDocument,\n  stateFilePath,\n  type HarnessStateTransactionSnapshot,\n} from './core';\nimport { getHarnessState } from './sync';\n\n/**\n * Who owns the harness state, and where it lives.\n *\n * The state used to be the environment: twenty variables that every reader\n * re-parsed and every writer mutated globally. The file is the authority now,\n * and the environment is a projection published for the readers that can only\n * see an environment, which are bash hooks, the shell launchers, packages that\n * do not depend on this one, and any process spawned by any of them.\n *\n * OWNERSHIP IS PER PROCESS, AND THAT IS THE WHOLE DESIGN:\n * Po Team subagents run detached, in their own process group, from an\n * environment snapshot taken at spawn. A child can outlive its parent. If it\n * shared the parent's file it would corrupt a session it does not own, and if\n * that file sat in the parent's run directory the parent's shutdown sweep would\n * delete it from under a live run. So every process writes a file it owns:\n * `owner.pid` records who, and a process that finds someone else's file copies\n * it before its first write.\n *\n * The async functions below read and write over an injected FileSystem and\n * never touch the in-process cache, so a session loads its snapshot once at\n * start and an isolate shared by several sessions cannot answer one from\n * another's memory. The Node shims in `./sync` keep the cache.\n *\n * AVOID:\n * - Treating the file as shared mutable state between processes. Atomic writes\n *   prevent torn reads, not lost updates\n * - Reading the environment directly for anything this exposes\n */\n\ntype IoContext = Parameters<FileSystem['readTextFile']>[1];\n\n/** Read-modify-write of one state file, queued per path within this process. */\nconst stateWrites = createSerialRunner();\n\n/** Reads the state an environment points at, uncached. Same fallbacks as `loadHarnessState`. */\nexport async function loadHarnessStateAsync(\n  fs: FileSystem,\n  environment: NodeJS.ProcessEnv,\n  context: IoContext,\n  report?: HarnessStateParseReporter,\n): Promise<LoadedHarnessState> {\n  const filePath = environment[HARNESS_STATE_POINTER];\n  if (filePath) {\n    try {\n      const source = await readTextIfExists(fs, filePath, context);\n      if (source !== undefined) {\n        const file = parseStateFile(source, filePath);\n        return { filePath, owned: ownsStateFile(file, nodeHost.processId()), state: file.state };\n      }\n    } catch (error) {\n      report?.(HARNESS_STATE_POINTER, error);\n    }\n  }\n  return { owned: false, state: readHarnessState(environment, report) };\n}\n\n/** Captures the state pointer, the state, and every projected harness variable. */\nexport async function snapshotHarnessStateAsync(\n  fs: FileSystem,\n  environment: NodeJS.ProcessEnv,\n  context: IoContext,\n): Promise<HarnessStateTransactionSnapshot> {\n  return snapshotFrom(await loadHarnessStateAsync(fs, environment, context), environment);\n}\n\nasync function persistAsync(\n  fs: FileSystem,\n  filePath: string,\n  state: HarnessState,\n  ownerPid: number,\n  context: IoContext,\n): Promise<void> {\n  await writePrivateAtomicJsonAsync(fs, filePath, stateFileDocument(state, ownerPid), context);\n}\n\n/** Starts a session over a FileSystem: writes the file and publishes the derived environment. */\nexport async function createHarnessSessionAsync(\n  fs: FileSystem,\n  state: HarnessState,\n  options: { directory: string; environment: NodeJS.ProcessEnv; unclaimed?: boolean },\n  context: IoContext,\n): Promise<string> {\n  const filePath = stateFilePath(options.directory);\n  await stateWrites.forKey(path.resolve(filePath))(() =>\n    persistAsync(fs, filePath, state, options.unclaimed ? UNCLAIMED_OWNER : nodeHost.processId(), context),\n  );\n  options.environment[HARNESS_STATE_POINTER] = filePath;\n  projectHarnessEnvironment(state, options.environment);\n  return filePath;\n}\n\nconst REPOINTED = Symbol('repointed');\n\n/**\n * Applies a patch to the state an environment points at, copy on write as\n * `updateHarnessState`. Concurrent patches to one file are queued, so each\n * reads what the previous one wrote and none is lost.\n */\nexport async function updateHarnessStateAsync(\n  fs: FileSystem,\n  patch: Partial<HarnessState>,\n  environment: NodeJS.ProcessEnv,\n  context: IoContext,\n): Promise<HarnessState> {\n  const adoptedPath = adoptedStateFilePath(nodeHost.temporaryDirectory(), nodeHost.processId());\n  const key = environment[HARNESS_STATE_POINTER] ?? adoptedPath;\n  const result = await stateWrites.forKey(path.resolve(key))(async () => {\n    // An earlier patch in the queue adopted a copy and moved the pointer; queue behind that file instead.\n    if ((environment[HARNESS_STATE_POINTER] ?? adoptedPath) !== key) return REPOINTED;\n    const current = await loadHarnessStateAsync(fs, environment, context);\n    const state = { ...current.state, ...patch };\n    const filePath = current.owned && current.filePath ? current.filePath : adoptedPath;\n    await persistAsync(fs, filePath, state, nodeHost.processId(), context);\n    environment[HARNESS_STATE_POINTER] = filePath;\n    projectHarnessEnvironment(patch, environment);\n    return state;\n  });\n  return result === REPOINTED ? updateHarnessStateAsync(fs, patch, environment, context) : result;\n}\n\n/** Removes the state file this process owns, if the environment points at one. Safe when there is none. */\nexport async function disposeHarnessStateAsync(\n  fs: FileSystem,\n  environment: NodeJS.ProcessEnv,\n  context: IoContext,\n): Promise<void> {\n  const current = await loadHarnessStateAsync(fs, environment, context);\n  if (!current.owned || !current.filePath) return;\n  const filePath = current.filePath;\n  await stateWrites.forKey(path.resolve(filePath))(() => removePath(fs, filePath, context));\n  delete environment[HARNESS_STATE_POINTER];\n}\n\nexport function harnessRoot(state: Pick<HarnessState, 'root'> = getHarnessState()): string {\n  return state.root ?? process.cwd();\n}\n\n/**\n * The repository root, or a hard error.\n *\n * Separate from `requireHarnessPaths` because most callers only need the root,\n * and separate from `harnessRoot` because falling back to `process.cwd()` would\n * quietly operate on whatever directory the session happens to sit in. A caller\n * that asks for the root wants the session's repository or nothing.\n */\nexport function requireHarnessRoot(state: Pick<HarnessState, 'root'> = getHarnessState()): string {\n  if (!state.root) throw new Error(`${HARNESS_STATE_KEYS.root} is not set`);\n  return state.root;\n}\n\n/** The root and the run's scratch directory, for callers that write to disk. */\nexport function requireHarnessPaths(state: Pick<HarnessState, 'root' | 'temporaryDirectory'> = getHarnessState()): {\n  root: string;\n  temporaryDirectory: string;\n} {\n  const root = requireHarnessRoot(state);\n  if (!state.temporaryDirectory) throw new Error(`${HARNESS_STATE_KEYS.temporaryDirectory} is not set`);\n  return { root, temporaryDirectory: state.temporaryDirectory };\n}\n\nexport { HARNESS_STATE_POINTER, resetHarnessStore } from './core';\nexport type { HarnessStateFile, HarnessStateTransactionSnapshot } from './core';\nexport {\n  createHarnessSession,\n  disposeHarnessState,\n  getHarnessState,\n  getSessionHarnessState,\n  loadHarnessState,\n  restoreHarnessStateSnapshot,\n  snapshotHarnessState,\n  updateHarnessState,\n} from './sync';\n"],"mappings":";;;;;;;;;;;;;AAcA,MAAa,eAA2D,EAAE,QAAQ,KAAA,EAAU;;;;ACP5F,MAAa,wBAAwB;AAErC,MAAM,qBAAqB;AAC3B,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;;AAsB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