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AC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACzC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,GAAG,kBAAkB,CAwBrB;AAED,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,OAAO,GACZ;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,kBAAkB,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAyD9E","sourcesContent":["/**\n * Logical agent store — port + validation (3.0.0 foundation).\n *\n * A logical agent is a semantic execution context over the existing durable\n * identities (child session / mission / assignment / execution). This store is\n * a read/control model; it does not introduce a second agent identity and does\n * not replace the Mission state machine.\n */\n\nimport type { LogicalAgentRecord } from \"./types.js\";\n\nexport const LOGICAL_AGENT_SCHEMA_VERSION = 1 as const;\n\nexport type LogicalAgentLoadResult =\n\t| { status: \"ok\"; record: LogicalAgentRecord }\n\t| { status: \"missing\" }\n\t| { status: \"corrupt\"; logicalAgentId: string; diagnostic: string };\n\nexport type LogicalAgentSaveResult =\n\t| { status: \"saved\"; record: LogicalAgentRecord }\n\t| { status: \"stale\"; expectedRevision: number; actualRevision: number | undefined };\n\nexport interface LogicalAgentStore {\n\treadonly storeId: string;\n\tload(logicalAgentId: string): Promise<LogicalAgentLoadResult>;\n\t/** Optimistic-concurrency save: reject when on-disk revision differs. */\n\tsave(record: LogicalAgentRecord, options?: { expectedRevision?: number }): Promise<LogicalAgentSaveResult>;\n\tlist(): Promise<string[]>;\n}\n\nexport function isSafeLogicalAgentId(value: string): boolean {\n\treturn /^[A-Za-z0-9._-]+$/u.test(value) && value !== \".\" && value !== \"..\";\n}\n\nexport function createLogicalAgentRecord(input: {\n\tlogicalAgentId: string;\n\tparentAgentId?: string;\n\tmissionId?: string;\n\tassignmentId?: string;\n\tattemptId?: string;\n\texecutionId?: string;\n\tworkerId?: string;\n\texecutorId?: string;\n\tmodelPolicy?: { provider: string; model: string };\n\tsessionId: string;\n\tsessionDir?: string;\n\tevidenceRefs?: string[];\n\tactivity: LogicalAgentRecord[\"activity\"];\n\twaitingReason?: string;\n\tpendingInferenceRequestId?: string;\n\tpriority?: number;\n\tnow?: number;\n}): LogicalAgentRecord {\n\tconst now = input.now ?? Date.now();\n\treturn {\n\t\tschemaVersion: LOGICAL_AGENT_SCHEMA_VERSION,\n\t\tlogicalAgentId: input.logicalAgentId,\n\t\tparentAgentId: input.parentAgentId,\n\t\tmissionId: input.missionId,\n\t\tassignmentId: input.assignmentId,\n\t\tattemptId: input.attemptId,\n\t\texecutionId: input.executionId,\n\t\tworkerId: input.workerId,\n\t\texecutorId: input.executorId,\n\t\tmodelPolicy: input.modelPolicy ? { ...input.modelPolicy } : undefined,\n\t\tsessionId: input.sessionId,\n\t\tsessionDir: input.sessionDir,\n\t\tevidenceRefs: [...(input.evidenceRefs ?? [])],\n\t\tactivity: input.activity,\n\t\twaitingReason: input.waitingReason,\n\t\tpendingInferenceRequestId: input.pendingInferenceRequestId,\n\t\tpriority: input.priority ?? 0,\n\t\tcreatedAtMs: now,\n\t\tupdatedAtMs: now,\n\t\trevision: 1,\n\t};\n}\n\nexport function parseLogicalAgentRecord(\n\tvalue: unknown,\n): { ok: true; record: LogicalAgentRecord } | { ok: false; diagnostic: string } {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value))\n\t\treturn { ok: false, diagnostic: \"record must be an object\" };\n\tconst doc = value as Record<string, unknown>;\n\tif (doc.schemaVersion !== LOGICAL_AGENT_SCHEMA_VERSION)\n\t\treturn { ok: false, diagnostic: `unsupported schemaVersion: ${String(doc.schemaVersion)}` };\n\tif (typeof doc.logicalAgentId !== \"string\" || !isSafeLogicalAgentId(doc.logicalAgentId))\n\t\treturn { ok: false, diagnostic: \"logicalAgentId is missing or unsafe\" };\n\tif (typeof doc.sessionId !== \"string\" || doc.sessionId.length === 0)\n\t\treturn { ok: false, diagnostic: \"sessionId must be a non-empty string\" };\n\tif (!(typeof doc.activity === \"string\")) return { ok: false, diagnostic: \"activity must be a string\" };\n\tif (!Array.isArray(doc.evidenceRefs)) return { ok: false, diagnostic: \"evidenceRefs must be an array\" };\n\tif (typeof doc.priority !== \"number\" || !Number.isSafeInteger(doc.priority))\n\t\treturn { ok: false, diagnostic: \"priority must be a safe integer\" };\n\tif (\n\t\t!Number.isSafeInteger(doc.createdAtMs) ||\n\t\t!Number.isSafeInteger(doc.updatedAtMs) ||\n\t\t!Number.isSafeInteger(doc.revision)\n\t)\n\t\treturn { ok: false, diagnostic: \"timestamps/revision must be safe integers\" };\n\n\tlet modelPolicy: LogicalAgentRecord[\"modelPolicy\"];\n\tif (doc.modelPolicy !== undefined) {\n\t\tif (typeof doc.modelPolicy !== \"object\" || doc.modelPolicy === null || Array.isArray(doc.modelPolicy))\n\t\t\treturn { ok: false, diagnostic: \"modelPolicy must be an object\" };\n\t\tconst mp = doc.modelPolicy as Record<string, unknown>;\n\t\tif (typeof mp.provider !== \"string\" || typeof mp.model !== \"string\")\n\t\t\treturn { ok: false, diagnostic: \"modelPolicy.provider/model must be strings\" };\n\t\tmodelPolicy = { provider: mp.provider, model: mp.model };\n\t}\n\n\treturn {\n\t\tok: true,\n\t\trecord: {\n\t\t\tschemaVersion: LOGICAL_AGENT_SCHEMA_VERSION,\n\t\t\tlogicalAgentId: doc.logicalAgentId as string,\n\t\t\tparentAgentId: typeof doc.parentAgentId === \"string\" ? doc.parentAgentId : undefined,\n\t\t\tmissionId: typeof doc.missionId === \"string\" ? doc.missionId : undefined,\n\t\t\tassignmentId: typeof doc.assignmentId === \"string\" ? doc.assignmentId : undefined,\n\t\t\tattemptId: typeof doc.attemptId === \"string\" ? doc.attemptId : undefined,\n\t\t\texecutionId: typeof doc.executionId === \"string\" ? doc.executionId : undefined,\n\t\t\tworkerId: typeof doc.workerId === \"string\" ? doc.workerId : undefined,\n\t\t\texecutorId: typeof doc.executorId === \"string\" ? doc.executorId : undefined,\n\t\t\tmodelPolicy,\n\t\t\tsessionId: doc.sessionId as string,\n\t\t\tsessionDir: typeof doc.sessionDir === \"string\" ? doc.sessionDir : undefined,\n\t\t\tevidenceRefs: (doc.evidenceRefs as unknown[]).filter((e): e is string => typeof e === \"string\"),\n\t\t\tactivity: doc.activity as LogicalAgentRecord[\"activity\"],\n\t\t\twaitingReason: typeof doc.waitingReason === \"string\" ? doc.waitingReason : undefined,\n\t\t\tpendingInferenceRequestId:\n\t\t\t\ttypeof doc.pendingInferenceRequestId === \"string\" ? doc.pendingInferenceRequestId : undefined,\n\t\t\tpriority: doc.priority as number,\n\t\t\tcreatedAtMs: doc.createdAtMs as number,\n\t\t\tupdatedAtMs: doc.updatedAtMs as number,\n\t\t\trevision: doc.revision as number,\n\t\t},\n\t};\n}\n"]}