|
| 1 | +import type { CanonicalEvent, ClassifierOutput, ScoreBundle } from "./types.js"; |
| 2 | + |
| 3 | +type FrontierDomainTag = "ai" | "wetware" | "transhuman" | "crypto" | "structural"; |
| 4 | + |
| 5 | +const STRUCTURED_FORM_PATTERNS: RegExp[] = [ |
| 6 | + /^\s*what(?:'s|\s+is|\s+are)\b/i, |
| 7 | + /^\s*what limits\b/i, |
| 8 | + /^\s*how do\b/i, |
| 9 | + /^\s*why does\b/i, |
| 10 | + /^\s*do you think\b/i, |
| 11 | + /^\s*should humans\b/i, |
| 12 | + /^\s*is\s+.+\s+viable\b/i, |
| 13 | + /^\s*will\s+.+\?\s*$/i, |
| 14 | +]; |
| 15 | + |
| 16 | +const FRONTIER_DOMAIN_PATTERNS: Array<[FrontierDomainTag, RegExp[]]> = [ |
| 17 | + [ |
| 18 | + "ai", |
| 19 | + [ |
| 20 | + /\bai\b/i, |
| 21 | + /\bagi\b/i, |
| 22 | + /\bllms?\b/i, |
| 23 | + /\bmodel(?:s)?\b/i, |
| 24 | + /\binference\b/i, |
| 25 | + /\b(?:current\s+)?llm(?:s)?\b/i, |
| 26 | + /\barchitectur(?:e|es)\b/i, |
| 27 | + ], |
| 28 | + ], |
| 29 | + [ |
| 30 | + "wetware", |
| 31 | + [ |
| 32 | + /\bwetware\b/i, |
| 33 | + /\borganoid(?:s)?\b/i, |
| 34 | + /\bbiocomput(?:er|ing|ation)?\b/i, |
| 35 | + /\bbiological\s+comput(?:ing|ation)\b/i, |
| 36 | + ], |
| 37 | + ], |
| 38 | + [ |
| 39 | + "transhuman", |
| 40 | + [ |
| 41 | + /\btranshuman(?:ism)?\b/i, |
| 42 | + /\bposthuman(?:ism)?\b/i, |
| 43 | + /\bdigital\s+migration\b/i, |
| 44 | + /\bmerge\s+with\s+machines\b/i, |
| 45 | + /\bbiological\s+bodies?\s+are\s+obsolete\b/i, |
| 46 | + ], |
| 47 | + ], |
| 48 | + [ |
| 49 | + "crypto", |
| 50 | + [ |
| 51 | + /\bcrypto\b/i, |
| 52 | + /\bsolana\b/i, |
| 53 | + /\btoken\b/i, |
| 54 | + /\bmarket\b/i, |
| 55 | + ], |
| 56 | + ], |
| 57 | + [ |
| 58 | + "structural", |
| 59 | + [ |
| 60 | + /\bconvergen(?:ce|t)\b/i, |
| 61 | + /\bstructural\b/i, |
| 62 | + /\bviable\b/i, |
| 63 | + /\barchitecture\b/i, |
| 64 | + /\blimit(?:s|ed)?\b/i, |
| 65 | + /\blong\s+term\b/i, |
| 66 | + ], |
| 67 | + ], |
| 68 | +]; |
| 69 | + |
| 70 | +const MARKET_CLUSTER_PATTERNS: RegExp[] = [ |
| 71 | + /\bprice(?:s)?\b/i, |
| 72 | + /\bchart(?:s|ing)?\b/i, |
| 73 | + /\btrade(?:s|d|ing)?\b/i, |
| 74 | + /\bliquidity\b/i, |
| 75 | + /\bliq\b/i, |
| 76 | + /\bvolume\b/i, |
| 77 | + /\border\s*book\b/i, |
| 78 | + /\bmarket\s*cap\b/i, |
| 79 | + /\bmcap\b/i, |
| 80 | + /\btvl\b/i, |
| 81 | + /\bslippage\b/i, |
| 82 | + /\bentry\b/i, |
| 83 | + /\bexit\b/i, |
| 84 | + /\bsupport\b/i, |
| 85 | + /\bresistance\b/i, |
| 86 | + /\bperps?\b/i, |
| 87 | + /\bspot\b/i, |
| 88 | + /\bprice\s+action\b/i, |
| 89 | +]; |
| 90 | + |
| 91 | +function normalizeText(text: string): string { |
| 92 | + return text.trim().toLowerCase(); |
| 93 | +} |
| 94 | + |
| 95 | +function stripInvocationPrefix(text: string): string { |
| 96 | + return text |
| 97 | + .replace(/^(?:@\w+\s*)+/i, "") |
| 98 | + .replace(/^\s*explicit\s+opt[- ]?in[:\-\s]*/i, "") |
| 99 | + .trim(); |
| 100 | +} |
| 101 | + |
| 102 | +function detectFrontierTags(text: string): Set<FrontierDomainTag> { |
| 103 | + const tags = new Set<FrontierDomainTag>(); |
| 104 | + for (const [tag, patterns] of FRONTIER_DOMAIN_PATTERNS) { |
| 105 | + if (patterns.some((pattern) => pattern.test(text))) { |
| 106 | + tags.add(tag); |
| 107 | + } |
| 108 | + } |
| 109 | + return tags; |
| 110 | +} |
| 111 | + |
| 112 | +function hasAnyStructuredForm(text: string): boolean { |
| 113 | + return STRUCTURED_FORM_PATTERNS.some((pattern) => pattern.test(text)); |
| 114 | +} |
| 115 | + |
| 116 | +function hasDirectMentionSignal(event: CanonicalEvent): boolean { |
| 117 | + return ( |
| 118 | + event.trigger_type === "mention" || |
| 119 | + event.trigger_type === "reply" || |
| 120 | + event.trigger_type === "quote" || |
| 121 | + /@\w+/i.test(event.text) |
| 122 | + ); |
| 123 | +} |
| 124 | + |
| 125 | +function hasExplicitOptInSignal(text: string): boolean { |
| 126 | + return /\bexplicit\s+opt[- ]?in\b/i.test(text) || /\bopt[- ]?in\b/i.test(text); |
| 127 | +} |
| 128 | + |
| 129 | +function hasCrossDomainSignal(tags: Set<FrontierDomainTag>): boolean { |
| 130 | + if (tags.has("ai") && tags.has("wetware")) return true; |
| 131 | + if (tags.has("ai") && tags.has("transhuman")) return true; |
| 132 | + if (tags.has("wetware") && tags.has("transhuman")) return true; |
| 133 | + if (tags.has("crypto") && (tags.has("ai") || tags.has("wetware") || tags.has("transhuman"))) return true; |
| 134 | + return tags.size >= 3; |
| 135 | +} |
| 136 | + |
| 137 | +export function hasFrontierDomainSignal(text: string): boolean { |
| 138 | + const tags = detectFrontierTags(text); |
| 139 | + if (tags.has("ai") || tags.has("wetware") || tags.has("transhuman")) { |
| 140 | + return true; |
| 141 | + } |
| 142 | + return hasCrossDomainSignal(tags); |
| 143 | +} |
| 144 | + |
| 145 | +export function hasEscalatorSignal(args: { event: CanonicalEvent; text: string }): boolean { |
| 146 | + const tags = detectFrontierTags(args.text); |
| 147 | + return ( |
| 148 | + hasDirectMentionSignal(args.event) || |
| 149 | + hasExplicitOptInSignal(args.text) || |
| 150 | + hasAnyStructuredForm(args.text) || |
| 151 | + hasCrossDomainSignal(tags) |
| 152 | + ); |
| 153 | +} |
| 154 | + |
| 155 | +export function hasMarketClusterSignal(text: string): boolean { |
| 156 | + const normalized = normalizeText(text); |
| 157 | + if (!normalized) return false; |
| 158 | + return MARKET_CLUSTER_PATTERNS.some((pattern) => pattern.test(normalized)); |
| 159 | +} |
| 160 | + |
| 161 | +export function isConceptualProbe(text: string, context?: { event?: CanonicalEvent }): boolean { |
| 162 | + const normalized = normalizeText(text); |
| 163 | + if (!normalized) return false; |
| 164 | + const event = context?.event; |
| 165 | + const coreText = stripInvocationPrefix(normalized); |
| 166 | + const tags = detectFrontierTags(coreText); |
| 167 | + |
| 168 | + if (!hasAnyStructuredForm(coreText)) return false; |
| 169 | + if (!hasFrontierDomainSignal(coreText)) return false; |
| 170 | + |
| 171 | + return hasEscalatorSignal({ |
| 172 | + event: |
| 173 | + event ?? { |
| 174 | + event_id: "conceptual_probe", |
| 175 | + platform: "twitter", |
| 176 | + trigger_type: "manual", |
| 177 | + author_handle: "@unknown", |
| 178 | + author_id: "unknown", |
| 179 | + text, |
| 180 | + parent_text: null, |
| 181 | + quoted_text: null, |
| 182 | + conversation_context: [], |
| 183 | + cashtags: [], |
| 184 | + hashtags: [], |
| 185 | + urls: [], |
| 186 | + timestamp: new Date().toISOString(), |
| 187 | + }, |
| 188 | + text: coreText, |
| 189 | + }) || hasCrossDomainSignal(tags); |
| 190 | +} |
| 191 | + |
| 192 | +export function isOrchestrationEligibleMinimal(args: { |
| 193 | + event: CanonicalEvent; |
| 194 | + cls: ClassifierOutput; |
| 195 | + scores: ScoreBundle; |
| 196 | +}): boolean { |
| 197 | + if (args.cls.intent !== "conceptual_probe") return false; |
| 198 | + if (args.cls.policy_blocked || args.cls.policy_severity === "hard") return false; |
| 199 | + if (args.scores.risk > 0.55) return false; |
| 200 | + return isConceptualProbe(args.event.text, { event: args.event }); |
| 201 | +} |
0 commit comments