diff --git a/packages/plugin/src/codex/session-id.ts b/packages/plugin/src/codex/session-id.ts new file mode 100644 index 0000000..d26a0d9 --- /dev/null +++ b/packages/plugin/src/codex/session-id.ts @@ -0,0 +1,14 @@ +import { RpcError } from '../safe-error.js' + +/** Parse the public CodeX session identity without treating it as a Harness agent id. */ +export function parseCodexSessionId(value: unknown): { sessionId: string; threadId: string } | undefined { + if (typeof value !== 'string') return undefined + const match = /^codex:([A-Za-z0-9][A-Za-z0-9._-]{0,255})$/.exec(value) + return match === null ? undefined : { sessionId: value, threadId: match[1]! } +} + +export function requireCodexSessionId(value: unknown): { sessionId: string; threadId: string } { + const parsed = parseCodexSessionId(value) + if (parsed === undefined) throw new RpcError('CODEX_SESSION_INVALID', 'The CodeX session identifier is invalid.') + return parsed +}