62c60ae9d8
- #3354: Coerce data.name to String in loadSkillFromPath/loadSkillFromPathAsync to prevent crash when YAML parses numeric skill names (e.g., name: 12306) - #3416: Add required run_in_background parameter to all task() examples in ultrawork prompts (default, gpt, gemini, planner) to match tool schema - #3379/#3417/#3418/#3337/#3335: Strip ZWSP (U+200B) before agent name comparisons in agent-tool-restrictions, sync-prompt-sender, tool-execute-after, tool-execute-before, oracle-verification-detector, call-omo-agent, recovery-prompt-config, and agent-variant to prevent ZWSP-prefixed display names from breaking exact-match lookups
72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
import { stripInvisibleAgentCharacters } from "../../shared/agent-display-names"
|
|
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
|
|
const TASK_METADATA_PATTERN = /<task_metadata>[ \t]*([\s\S]*?)[ \t]*<\/task_metadata>/is
|
|
const SESSION_ID_LINE_PATTERN = /^session_id:[ \t]*(\S+)$/im
|
|
|
|
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
|
|
}
|
|
|
|
const metadataMatch = trimmedText.match(TASK_METADATA_PATTERN)
|
|
let sessionID: string | undefined
|
|
if (metadataMatch) {
|
|
const metadataContent = metadataMatch[1]
|
|
const sessionIDMatch = metadataContent.match(SESSION_ID_LINE_PATTERN)
|
|
if (sessionIDMatch) {
|
|
sessionID = sessionIDMatch[1]?.trim()
|
|
}
|
|
}
|
|
|
|
return { agent, promise, sessionID }
|
|
}
|
|
|
|
export function isOracleVerified(text: string): boolean {
|
|
const evidence = parseOracleVerificationEvidence(text)
|
|
if (!evidence) {
|
|
return false
|
|
}
|
|
|
|
const isOracleAgent = stripInvisibleAgentCharacters(evidence.agent).toLowerCase() === "oracle"
|
|
const isVerifiedPromise = evidence.promise === ULTRAWORK_VERIFICATION_PROMISE
|
|
|
|
return isOracleAgent && isVerifiedPromise
|
|
}
|
|
|
|
export function extractOracleSessionID(text: string): string | undefined {
|
|
const evidence = parseOracleVerificationEvidence(text)
|
|
if (!evidence || stripInvisibleAgentCharacters(evidence.agent).toLowerCase() !== "oracle") {
|
|
return undefined
|
|
}
|
|
|
|
return evidence.sessionID
|
|
}
|