Repository Public License
1// AgentRuntime — the browsing-agent engine of ORIX Navigator (see docs/AGENT.md and docs/AGENT_SECURITY.md).2//3// Layout of the module:4// JSONSchema.swift strict JSON Schema subset validator for tool arguments5// AgentTools.swift the typed tool catalogue (capability, risk, confirmation, data leaving the device)6// BrowserAgentHost.swift the only door to web pages; implemented by the UI layer over WebEngine7// AgentPolicy.swift limits, per-run permission policy, domain allow-list, strict URL parsing8// AgentClassifiers.swift sensitive actions, secret fields, CAPTCHA / sign-in walls, injection heuristic9// ExfiltrationGuard.swift outbound URL / text checks against what the agent has read10// DataEnvelope.swift per-run nonce envelopes, redaction and size limits of tool results11// Citations.swift source registry and deterministic answer verification12// TextDiff.swift line diff used by browser.compare13// AgentEvents.swift events, confirmation and hand-off types, the delegate protocol14// AgentSession.swift the orchestrator actor (loop, budget, cancellation, persistence)15// AgentSession+Tools.swift one function per tool16// AgentRunHistory.swift relaunch handling: unfinished runs become "interrupted", never resumed17// AssistantHelpers.swift tool-less helpers (summarise, explain, translate, compare, extract) with consent18//19// This module never imports WebKit, WebRuntime or SwiftUI.20import Foundation2122enum AgentText {23 /// Lowercased, diacritics removed, typographic apostrophes straightened, whitespace runs collapsed.24 static func fold(_ text: String) -> String {25 let folded = text.folding(options: [.diacriticInsensitive, .caseInsensitive, .widthInsensitive], locale: Locale(identifier: "en_US_POSIX"))26 .replacingOccurrences(of: "’", with: "'").replacingOccurrences(of: "‘", with: "'")27 return folded.split(whereSeparator: { $0.isWhitespace }).joined(separator: " ")28 }2930 /// At most `limit` characters; a marker says how much was cut.31 static func truncate(_ text: String, to limit: Int) -> String {32 guard limit >= 0, text.count > limit else { return text }33 return String(text.prefix(limit)) + " …[truncated \(text.count - limit) characters]"34 }3536 /// One line, no control characters: for text that is echoed in runtime-authored messages and step summaries.37 static func singleLine(_ text: String, limit: Int = 120) -> String {38 let scalars = text.unicodeScalars.map { scalar -> Character in39 (scalar.properties.generalCategory == .control || scalar == "\u{2028}" || scalar == "\u{2029}") ? " " : Character(scalar)40 }41 let line = String(scalars).split(whereSeparator: { $0.isWhitespace }).joined(separator: " ")42 return line.count > limit ? String(line.prefix(limit)) + "…" : line43 }44}45