2026-04-16 13:52:12 +09:00
|
|
|
import { extractTaskLink } from "../../features/tool-metadata-store"
|
2026-04-15 10:46:41 +09:00
|
|
|
import { stripInvisibleAgentCharacters } from "../../shared/agent-display-names"
|
2026-04-08 13:24:50 +09:00
|
|
|
import { ULTRAWORK_VERIFICATION_PROMISE } from "./constants"
|
|
|
|
|
|
|
|
|
|
export interface OracleVerificationEvidence {
|
|
|
|
|
agent: string
|
|
|
|
|
promise: string
|
|
|
|
|
sessionID?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const AGENT_LINE_PATTERN = /^Agent:[ \t]*(\S+)$/im
|
|
|
|
|
const PROMISE_TAG_PATTERN = /<promise>[ \t]*(\S+?)[ \t]*<\/promise>/is
|
|
|
|
|
|
|
|
|
|
export function parseOracleVerificationEvidence(text: string): OracleVerificationEvidence | undefined {
|
|
|
|
|
const trimmedText = text.trim()
|
|
|
|
|
if (!trimmedText) {
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const agentMatch = trimmedText.match(AGENT_LINE_PATTERN)
|
|
|
|
|
if (!agentMatch) {
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
const agent = agentMatch[1]?.trim()
|
|
|
|
|
if (!agent) {
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const promiseMatch = trimmedText.match(PROMISE_TAG_PATTERN)
|
|
|
|
|
if (!promiseMatch) {
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
const promise = promiseMatch[1]?.trim()
|
|
|
|
|
if (!promise) {
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-16 13:52:12 +09:00
|
|
|
const sessionID = extractTaskLink(undefined, trimmedText).sessionId
|
2026-04-08 13:24:50 +09:00
|
|
|
|
2026-04-16 13:52:12 +09:00
|
|
|
return { agent, promise, sessionID }
|
2026-04-08 13:24:50 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isOracleVerified(text: string): boolean {
|
|
|
|
|
const evidence = parseOracleVerificationEvidence(text)
|
|
|
|
|
if (!evidence) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 10:46:41 +09:00
|
|
|
const isOracleAgent = stripInvisibleAgentCharacters(evidence.agent).toLowerCase() === "oracle"
|
2026-04-08 13:24:50 +09:00
|
|
|
const isVerifiedPromise = evidence.promise === ULTRAWORK_VERIFICATION_PROMISE
|
|
|
|
|
|
|
|
|
|
return isOracleAgent && isVerifiedPromise
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function extractOracleSessionID(text: string): string | undefined {
|
|
|
|
|
const evidence = parseOracleVerificationEvidence(text)
|
2026-04-15 10:46:41 +09:00
|
|
|
if (!evidence || stripInvisibleAgentCharacters(evidence.agent).toLowerCase() !== "oracle") {
|
2026-04-08 13:24:50 +09:00
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return evidence.sessionID
|
|
|
|
|
}
|