{"version":3,"file":"relaunchHandoff.cjs","names":["Type","Check"],"sources":["../../src/schemas/relaunchHandoff.ts"],"sourcesContent":["import { type Static, Type } from 'typebox';\nimport { Check } from 'typebox/value';\n\n/**\n * The relaunch handoff between a DoomPi runtime and its process supervisor.\n *\n * A launcher-class session cannot recompose its extension closure in place, so\n * a relaunch-class transition normally stays pending until a human reruns the\n * launcher with the new selection. A supervisor that owns the agent process\n * (doompi-server) opts into performing that relaunch itself: it points this\n * environment variable at a file path, the runtime writes the target selection\n * there and exits, and the supervisor respawns the agent with the recorded\n * major mode under the same session id.\n */\nexport const DOOM_RELAUNCH_FILE_ENV = 'DOOMPI_RELAUNCH_FILE';\n\nconst MAX_IDENTIFIER_LENGTH = 256;\n\nexport const RelaunchHandoffSchema = Type.Object(\n  {\n    version: Type.Literal(1),\n    majorMode: Type.String({ minLength: 1, maxLength: MAX_IDENTIFIER_LENGTH }),\n    operationId: Type.String({ minLength: 1, maxLength: MAX_IDENTIFIER_LENGTH }),\n  },\n  { additionalProperties: false },\n);\nexport type RelaunchHandoff = Static<typeof RelaunchHandoffSchema>;\n\nexport function serializeRelaunchHandoff(handoff: RelaunchHandoff): string {\n  return JSON.stringify(handoff);\n}\n\n/** The handoff a supervisor read back, or undefined for anything malformed. */\nexport function parseRelaunchHandoff(text: string): RelaunchHandoff | undefined {\n  let candidate: unknown;\n  try {\n    candidate = JSON.parse(text);\n  } catch {\n    return undefined;\n  }\n  return Check(RelaunchHandoffSchema, candidate) ? candidate : undefined;\n}\n"],"mappings":"oDAcA,MAIa,EAAwBA,EAAAA,KAAK,OACxC,CACE,QAASA,EAAAA,KAAK,QAAQ,CAAC,EACvB,UAAWA,EAAAA,KAAK,OAAO,CAAE,UAAW,EAAG,UAAW,GAAsB,CAAC,EACzE,YAAaA,EAAAA,KAAK,OAAO,CAAE,UAAW,EAAG,UAAW,GAAsB,CAAC,CAC7E,EACA,CAAE,qBAAsB,EAAM,CAChC,EAGA,SAAgB,EAAyB,EAAkC,CACzE,OAAO,KAAK,UAAU,CAAO,CAC/B,CAGA,SAAgB,EAAqB,EAA2C,CAC9E,IAAI,EACJ,GAAI,CACF,EAAY,KAAK,MAAM,CAAI,CAC7B,MAAQ,CACN,MACF,CACA,OAAA,EAAOC,EAAAA,MAAAA,CAAM,EAAuB,CAAS,EAAI,EAAY,IAAA,EAC/D"}