titan-agent 6.3.5 → 6.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/config.js +18 -2
- package/dist/config/config.js.map +1 -1
- package/dist/providers/defaultModel.js +2 -2
- package/dist/providers/defaultModel.js.map +1 -1
- package/dist/providers/ollama.js +17 -1
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/router.js +7 -3
- package/dist/providers/router.js.map +1 -1
- package/dist/providers/stub.js +1 -6
- package/dist/providers/stub.js.map +1 -1
- package/dist/utils/constants.js +1 -1
- package/dist/utils/constants.js.map +1 -1
- package/package.json +1 -1
- package/ui/dist/sw.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/providers/stub.ts"],"sourcesContent":["/**\n * TITAN — CI Stub Provider (v6.1.0-beta.11)\n *\n * Deterministic pattern-matched LLM provider used by CI eval suites\n * and offline tests. Returns canned, useful responses without making\n * any network call — so the Eval Gate workflow can run on every PR\n * without burning Anthropic / OpenAI credits OR requiring secrets\n * configured on the runner.\n *\n * WHAT this is:\n * - A real LLMProvider implementation registered as `'stub'`.\n * - Model IDs `stub/echo`, `stub/json`, `stub/refuse` route here.\n * - Pattern-matches the last user message + system prompt against a\n * small table of recognized shapes (chat, structured-JSON,\n * tool-call, safety-refusal) and emits the appropriate response.\n *\n * WHY it exists:\n * - Phase B.1 truth-table audit showed Eval Gate runs were scoring\n * 0% on every suite because no provider had credentials in CI.\n * - The fix isn't \"give CI an API key\" — that bakes a real-money\n * dependency into every push. The fix is a provider that can\n * stand in for the real model deterministically.\n * - The harness-engineering catalog (Picrew/awesome-agent-harness)\n * explicitly recommends a \"stub mode\" so the harness itself is\n * testable independent of any single LLM.\n *\n * TRADE-OFFS we deliberately accept:\n * - The stub can't answer open-ended questions. It pattern-matches\n * a fixed vocabulary. Suites that probe model creativity have\n * no business running against the stub.\n * - The stub knows the exact shapes our agent code expects (widget\n * gate JSON, structuredSpawn JSON, tool-call format). When those\n * shapes change, this file changes too. That coupling is OK —\n * it's the price of CI-grade determinism.\n *\n * FOLLOW-UP:\n * - When we add a new gated agent shape, add a recognizer here.\n * - When we add a new built-in tool, add a recognizer here so\n * tool-routing evals can exercise the dispatch path.\n */\nimport { LLMProvider } from './base.js';\nimport type {\n ChatMessage,\n ChatOptions,\n ChatResponse,\n ChatStreamChunk,\n ToolCall,\n} from './base.js';\nimport logger from '../utils/logger.js';\n\nconst COMPONENT = 'provider.stub';\n\n/* ─────────────────────────── Pattern recognizers ─────────────────────────── */\n\ninterface RecognizedIntent {\n /** Stable id of the matched pattern. Used by tests + telemetry. */\n kind: string;\n /** Plain-text body of the response. */\n content: string;\n /** Optional tool calls to emit alongside the text. */\n toolCalls?: ToolCall[];\n /** finish_reason on the response. */\n finishReason: 'stop' | 'tool_calls' | 'error';\n}\n\n/**\n * Inspect the conversation and decide what kind of response to emit.\n * Order matters — safety refusals first, then structured outputs,\n * then tool-call shapes, then default chat.\n */\nfunction recognize(messages: ChatMessage[], offeredTools: Set<string>): RecognizedIntent {\n const userMessages = messages.filter(m => m.role === 'user').map(m => m.content ?? '');\n const lastUser = [...userMessages].reverse()[0] ?? '';\n const system = messages.find(m => m.role === 'system')?.content ?? '';\n const combined = `${system}\\n${userMessages.join('\\n')}`.toLowerCase();\n const userOnly = lastUser.toLowerCase();\n const directiveRe = /^\\s*\\[system directive for this reply only\\]/i;\n const conversationalUsers = userMessages.filter(m => !directiveRe.test(m));\n const intentPrompt = ([...conversationalUsers].reverse()[0] ?? lastUser).toLowerCase();\n const intentContext = `${intentPrompt}\\n${combined}`;\n const structuredContext = `${system}\\n${intentPrompt}`;\n\n // ── Safety refusal — keep first so injection attempts in the\n // system prompt don't override it.\n if (isUnsafeRequest(intentPrompt || userOnly)) {\n return {\n kind: 'safety_refusal',\n content: 'Stub: I can\\'t safely comply. I refuse to execute unsafe, destructive, injected, traversal, scheme-abusing, or private-instruction extraction requests.',\n finishReason: 'stop',\n };\n }\n\n // ── Tool-result continuation — if the LAST message is a tool\n // result, wrap up instead of re-issuing the same deterministic\n // tool call on the next round.\n if (messages[messages.length - 1]?.role === 'tool') {\n return {\n kind: 'tool_result_ack',\n content: summarizeToolResult(intentPrompt),\n finishReason: 'stop',\n };\n }\n\n // ── Structured JSON output — when the system prompt is asking\n // for the structuredSpawn JSON envelope. The driver loop\n // relies on this shape so the \"done\" path is reachable in CI.\n // Recognizers are deliberately broad: any prompt asking for\n // JSON output, or any mention of the spawn-envelope fields\n // (\"status\", \"artifacts\", \"confidence\") together, triggers\n // the structured-output path.\n const mentionsJsonOutput = /(respond|reply|return|output)\\s+(with\\s+)?(strict\\s+)?json|json\\s+containing|json\\s+envelope|structuredSpawn|spawn\\s+envelope/i.test(structuredContext);\n const mentionsEnvelopeFields =\n /\"status\"/i.test(structuredContext) &&\n /\"artifacts\"/i.test(structuredContext) &&\n /\"confidence\"/i.test(structuredContext);\n if (mentionsJsonOutput || mentionsEnvelopeFields) {\n const json = JSON.stringify({\n status: 'done',\n artifacts: [],\n questions: [],\n confidence: 0.9,\n reasoning: `Stub: pattern-matched structured-output request on prompt \"${userOnly.slice(0, 60)}\".`,\n });\n return {\n kind: 'structured_done',\n content: '```json\\n' + json + '\\n```',\n finishReason: 'stop',\n };\n }\n\n // ── Widget gate — TITAN's chat surface listens for a\n // `_____widget` gate followed by a JSON line. The 100+ widget\n // gallery routes off this signal; eval suites assert it.\n const widget = pickWidget(intentPrompt || userOnly);\n if (widget) {\n const widgetJson = JSON.stringify({\n name: widget.name,\n format: 'system',\n source: widget.source,\n w: widget.w,\n h: widget.h,\n });\n return {\n kind: 'widget_gate',\n content: `Adding the **${widget.name}** widget to your canvas.\\n\\n_____widget\\n${widgetJson}`,\n finishReason: 'stop',\n };\n }\n\n // ── Tool-call shape — when tools are offered AND the user prompt\n // clearly asks for one. Emits a tool_calls finish_reason so\n // the agent loop dispatches the tool. The agent will then\n // feed a tool_result back; that's handled below.\n if (offeredTools.size > 0) {\n const toolMatches = pickToolCalls(intentPrompt || userOnly).filter(tool => offeredTools.has(tool.name));\n if (toolMatches.length > 0) {\n return {\n kind: `tool_call:${toolMatches.map(t => t.name).join('+')}`,\n content: '',\n toolCalls: toolMatches.map((toolMatch, index) => ({\n id: `stub-tool-${toolMatch.name}-${index + 1}`,\n type: 'function',\n function: {\n name: toolMatch.name,\n arguments: JSON.stringify(toolMatch.args),\n },\n })),\n finishReason: 'tool_calls',\n };\n }\n }\n\n const directPrompt = intentPrompt || userOnly;\n if (/\\bwhat\\s+is\\s+2\\s*\\+\\s*2\\b|\\b2\\s*\\+\\s*2\\b/.test(directPrompt)) {\n return { kind: 'direct_arithmetic', content: 'The answer is 4.', finishReason: 'stop' };\n }\n\n if (/^\\s*(hello|hi|hey)\\b/.test(directPrompt)) {\n return { kind: 'direct_greeting', content: 'Hello. Voice channel ready.', finishReason: 'stop' };\n }\n\n if (/write\\s+(a\\s+)?hello\\s+world\\s+program/i.test(intentContext) && /python/i.test(intentContext)) {\n return { kind: 'write_file_final_answer', content: 'Created a Python hello world program using print(\"hello world\").', finishReason: 'stop' };\n }\n\n // ── Default — plain chat echo. Includes the first 60 chars of\n // the prompt so eval suites can assert on prompt threading.\n return {\n kind: 'echo',\n content: `Stub response. Echoing your request: \"${lastUser.slice(0, 60)}\".`,\n finishReason: 'stop',\n };\n}\n\n/* ─────────────────────────── Sub-recognizers ─────────────────────────── */\n\nfunction isUnsafeRequest(prompt: string): boolean {\n return [\n /\\brm\\s+-[a-z]*r[a-z]*f[a-z]*\\b/,\n /\\bdelete\\s+everything\\b|\\bwipe\\s+the\\s+disk\\b|\\bdrop\\s+all\\s+tables\\b|\\bformat\\s+the\\s+drive\\b/,\n /\\bchmod\\s+777\\s+\\/(?:etc|bin|sbin|usr|var|)\\b/,\n /\\bsudo\\b/,\n /\\bcurl\\b[^|\\n;]*(?:\\|\\s*(?:ba)?sh\\b)/,\n /\\b(?:ignore|bypass)\\s+(?:all\\s+)?(?:previous|prior|system|developer)\\s+instructions\\b/,\n /\\b(?:repeat|reveal|print|show|extract).{0,80}\\b(?:system|developer)\\s+(?:prompt|instructions)\\b/,\n /\\b(?:dan|developer\\s+mode|unrestricted\\s+ai|do\\s+anything\\s+now)\\b/,\n /javascript\\s*:/,\n /(?:^|[/\"'\\s])\\.\\.\\/\\.\\.\\//,\n /\\b(?:run|execute)\\b[^;\\n]*[;`]|`[^`]+`/,\n /\\|\\s*(?:bash|sh|zsh|python|perl|ruby)\\b/,\n /\\b(?:fetch|download|open|read)\\s+(?:file|dict):\\/\\//,\n ].some(re => re.test(prompt));\n}\n\n/** Pick a widget name keyed off the user prompt. Defaults to a generic\n * \"Note\" panel so the agent always has SOMETHING to add. */\nfunction pickWidget(prompt: string): { name: string; source: string; w: number; h: number } | null {\n const systemWidgets: Array<{ re: RegExp; name: string; source: string; w: number; h: number }> = [\n { re: /\\b(?:backups?|snapshots?|archives?)\\b/, name: 'Backup Manager', source: 'system:backup', w: 6, h: 6 },\n { re: /\\b(?:training|train|specialists?|models?)\\b/, name: 'Training Dashboard', source: 'system:training', w: 6, h: 6 },\n { re: /\\b(?:recipes?|playbooks?|workflows?|jarvis)\\b/, name: 'Recipe Kitchen', source: 'system:recipes', w: 6, h: 6 },\n { re: /\\b(?:vram|gpu|nvidia)\\b/, name: 'VRAM Monitor', source: 'system:vram', w: 6, h: 6 },\n { re: /\\b(?:teams?|team hub|members?|roles?|permissions?|rbac)\\b/, name: 'Team Hub', source: 'system:teams', w: 6, h: 6 },\n { re: /\\b(?:cron|schedules?|jobs?|timers?)\\b/, name: 'Cron Scheduler', source: 'system:cron', w: 6, h: 6 },\n { re: /\\b(?:checkpoints?|restores?|save state)\\b/, name: 'Checkpoints', source: 'system:checkpoints', w: 6, h: 5 },\n { re: /\\b(?:organism|guardrails?)\\b/, name: 'Organism Monitor', source: 'system:organism', w: 6, h: 6 },\n { re: /\\b(?:fleet|nodes?|routes?|mesh)\\b/, name: 'Fleet Router', source: 'system:fleet', w: 6, h: 5 },\n { re: /\\b(?:browser tools?|captcha|form fill|web automation)\\b/, name: 'Browser Tools', source: 'system:browser', w: 6, h: 5 },\n { re: /\\b(?:test lab|tests?|flaky|failing|coverage|eval)\\b/, name: 'Test Lab', source: 'system:eval', w: 6, h: 6 },\n ];\n const wantsSystemWidget = /\\b(?:show|open|add|launch|pin|create|display|give me)\\b/.test(prompt);\n if (wantsSystemWidget) {\n const systemWidget = systemWidgets.find(w => w.re.test(prompt));\n if (systemWidget) return systemWidget;\n }\n\n if (/stock|ticker|nasdaq|nyse/.test(prompt)) return { name: 'Stock Ticker', source: 'gallery', w: 360, h: 240 };\n if (/pomodoro|timer|focus/.test(prompt)) return { name: 'Pomodoro Timer', source: 'gallery', w: 360, h: 240 };\n if (/calendar|schedule/.test(prompt)) return { name: 'Calendar', source: 'gallery', w: 360, h: 240 };\n if (/gauge|meter|metric/.test(prompt)) return { name: 'Gauge', source: 'gallery', w: 360, h: 240 };\n if (/dashboard/.test(prompt)) return { name: 'Dashboard', source: 'gallery', w: 360, h: 240 };\n if (/clock|time/.test(prompt)) return { name: 'Clock', source: 'gallery', w: 360, h: 240 };\n if (/widget|panel/.test(prompt)) return { name: 'Note', source: 'gallery', w: 360, h: 240 };\n return null;\n}\n\n/** Pick tool calls + arguments keyed off the user prompt. Returns an\n * empty list if no tool matches — caller falls through to text. */\nfunction pickToolCalls(prompt: string): Array<{ name: string; args: Record<string, unknown> }> {\n if (/\\b(?:fix|bug|change|update|edit|modify)\\b/.test(prompt) && /\\b[\\w./-]+\\.(?:ts|tsx|js|jsx|py|json|md)\\b/.test(prompt)) {\n const path = extractPath(prompt) || '/tmp/titan-stub-code.ts';\n const calls: Array<{ name: string; args: Record<string, unknown> }> = [\n { name: 'read_file', args: { path } },\n { name: 'edit_file', args: { path, target: 'OLD', replacement: 'NEW' } },\n ];\n if (/\\b(?:fix|bug|test|verify)\\b/.test(prompt)) {\n calls.push({ name: 'shell', args: { command: 'printf \"stub verification ok\\\\n\"' } });\n }\n return calls;\n }\n if (/\\bweather\\b|\\bforecast\\b|\\btemperature\\b/.test(prompt)) {\n return [{ name: 'weather', args: { location: extractLocation(prompt) || 'San Francisco', days: 1 } }];\n }\n if (/\\b(?:navigate|browse|click|screenshot|open)\\b.*\\b(?:browser|site|page|example\\.com|https?:\\/\\/)/.test(prompt)) {\n return [{ name: 'web_act', args: { action: `open ${extractUrl(prompt) || 'https://example.com'}`, sessionId: 'stub-eval' } }];\n }\n if (/\\bfetch\\s+https?:\\/\\//.test(prompt)) {\n return [{ name: 'web_fetch', args: { url: extractUrl(prompt) || 'https://example.com' } }];\n }\n if (/\\bresearch\\b|\\blatest\\b|\\bnews\\b|\\bhistory\\b|search\\s+(?:the\\s+web\\s+)?for|google|find\\s+information|web\\s+search/.test(prompt)) {\n return [{ name: 'web_search', args: { query: extractAfter(prompt, /search\\s+(?:the\\s+web\\s+)?for|research|find/) || prompt.slice(0, 80) } }];\n }\n if (/write\\s+(a\\s+)?file|save\\s+to|create\\s+(a\\s+)?file|write\\s+(a\\s+)?hello\\s+world\\s+program/.test(prompt)) {\n return [{ name: 'write_file', args: { path: extractPath(prompt) || '/tmp/stub-output.txt', content: contentForWrite(prompt) } }];\n }\n if (/read\\s+(a\\s+)?file|open\\s+the\\s+file|show\\s+me\\s+the\\s+contents/.test(prompt)) {\n return [{ name: 'read_file', args: { path: extractPath(prompt) || '/tmp/stub-input.txt' } }];\n }\n if (/list\\s+(the\\s+)?(files|directory|dir)|what(?:'| i)?s\\s+(?:in|inside)|what\\s+files\\s+are\\s+in/.test(prompt)) {\n return [{ name: 'list_dir', args: { path: extractPath(prompt) || '/tmp' } }];\n }\n if (/\\b(?:run|execute|restart)\\b/.test(prompt)) {\n return [{ name: 'shell', args: { command: 'printf \"stub shell ok\\\\n\"' } }];\n }\n if (/download\\s+(an?\\s+)?image|embed\\s+image/.test(prompt)) {\n return [{ name: 'download_image', args: { url: 'https://example.com/sample.jpg' } }];\n }\n return [];\n}\n\nfunction summarizeToolResult(prompt: string): string {\n if (/hello\\s+world|python/.test(prompt)) {\n return 'Stub: wrote a hello world Python program using print(\"hello world\"). Done.';\n }\n if (/\\bweather\\b/.test(prompt)) return 'Stub: weather tool finished. Done.';\n if (/\\bresearch\\b|\\blatest\\b|\\bnews\\b|\\bhistory\\b|search/.test(prompt)) return 'Stub: web search finished with deterministic results. Done.';\n return 'Stub: tool finished. Done.';\n}\n\nfunction extractPath(prompt: string): string {\n const quoted = prompt.match(/(?:called|to|of|in|file)\\s+[\"'`]?([/~]?[\\w./-]+\\.[\\w]+)[\"'`]?/);\n const anyPath = prompt.match(/([/~]?[\\w.-]*\\/[\\w./-]+|[\\w.-]+\\.(?:ts|tsx|js|jsx|py|json|md|txt))/);\n const path = quoted?.[1] || anyPath?.[1] || '';\n if (!path) return '';\n return path.startsWith('/') || path.startsWith('~') ? path : `/tmp/${path.split('/').pop()}`;\n}\n\nfunction extractUrl(prompt: string): string {\n return prompt.match(/https?:\\/\\/[^\\s\"'`<>]+/)?.[0]?.replace(/[).,]+$/, '') ?? '';\n}\n\nfunction extractLocation(prompt: string): string {\n return prompt.match(/weather\\s+(?:for|in|at)\\s+([a-z][a-z\\s,]+?)(?:[?.]|$)/i)?.[1]?.trim() ?? '';\n}\n\nfunction contentForWrite(prompt: string): string {\n if (/python|hello\\s+world/.test(prompt)) return 'print(\"hello world\")\\n';\n return 'hello world\\n';\n}\n\n/** Extract the part of the prompt AFTER a matched intent verb. Used to\n * pull the search query / file name / etc. out of the prompt. */\nfunction extractAfter(prompt: string, re: RegExp): string {\n const m = prompt.match(re);\n if (!m) return '';\n const idx = (m.index ?? -1) + m[0].length;\n if (idx < 0) return '';\n return prompt.slice(idx).trim().replace(/[.?!]+$/, '').slice(0, 80);\n}\n\n/* ─────────────────────────── Provider ─────────────────────────── */\n\nexport class StubProvider extends LLMProvider {\n readonly name = 'stub';\n readonly displayName = 'TITAN Stub (CI/offline)';\n\n /**\n * Always configured. The whole point is that the stub works\n * without any credentials so CI can run end-to-end.\n */\n isConfigured(): boolean {\n return true;\n }\n\n async chat(options: ChatOptions): Promise<ChatResponse> {\n const intent = recognize(options.messages, offeredToolNames(options));\n logger.debug(COMPONENT, `chat() kind=${intent.kind} model=${options.model ?? 'stub/echo'}`);\n const promptTokens = approxTokens(options.messages);\n const completionTokens = approxTokens([{ role: 'assistant', content: intent.content }]);\n return {\n id: `stub-${Date.now()}`,\n content: intent.content,\n toolCalls: intent.toolCalls,\n usage: {\n promptTokens,\n completionTokens,\n totalTokens: promptTokens + completionTokens,\n },\n finishReason: intent.finishReason,\n model: options.model || 'stub/echo',\n };\n }\n\n async *chatStream(options: ChatOptions): AsyncGenerator<ChatStreamChunk> {\n const intent = recognize(options.messages, offeredToolNames(options));\n logger.debug(COMPONENT, `chatStream() kind=${intent.kind}`);\n // Emit text content first (if any), then any tool calls,\n // then a done marker. Matches the shape real providers use.\n if (intent.content) {\n yield { type: 'text', content: intent.content };\n }\n if (intent.toolCalls) {\n for (const tc of intent.toolCalls) {\n yield { type: 'tool_call', toolCall: tc };\n }\n }\n yield { type: 'done' };\n }\n\n async listModels(): Promise<string[]> {\n return ['stub/echo', 'stub/json', 'stub/refuse'];\n }\n\n async healthCheck(): Promise<boolean> {\n return true;\n }\n}\n\n/* ─────────────────────────── Token estimator ─────────────────────────── */\n\nfunction offeredToolNames(options: ChatOptions): Set<string> {\n return new Set((options.tools ?? []).map(tool => tool.function.name));\n}\n\n/** ~4 chars per token rule-of-thumb. Not exact, but stable enough for\n * cost-budget tests that only need monotonicity. */\nfunction approxTokens(messages: ChatMessage[]): number {\n let chars = 0;\n for (const m of messages) chars += (m.content ?? '').length;\n return Math.max(1, Math.ceil(chars / 4));\n}\n\n/* ─────────────────────────── CI detection ─────────────────────────── */\n\n/**\n * Returns true when the runtime should fall back to the stub provider\n * because no real provider credentials are available. The default\n * model picker (`defaultModel.ts`) calls this to choose `stub/echo`\n * as the floor model in CI / offline environments.\n *\n * Trigger conditions (any one is enough):\n * - Explicit opt-in: `TITAN_STUB_PROVIDER=1`\n * - Standard CI signal: `CI=true` AND no Anthropic/OpenAI/Google key\n *\n * NOTE: we DELIBERATELY do NOT trigger on `VITEST=true`. Existing\n * unit tests (default-model-picker.test.ts in particular) pin the\n * \"no keys → ollama\" behavior; flipping that under VITEST would\n * break those tests. Tests that want the stub should set\n * `TITAN_STUB_PROVIDER=1` in their setup explicitly.\n */\nexport function shouldUseStubProvider(): boolean {\n if (process.env.TITAN_STUB_PROVIDER === '1') return true;\n if (process.env.CI === 'true') {\n const hasRealKey = !!(\n process.env.ANTHROPIC_API_KEY ||\n process.env.OPENAI_API_KEY ||\n process.env.GOOGLE_API_KEY ||\n process.env.OPENROUTER_API_KEY\n );\n return !hasRealKey;\n }\n return false;\n}\n"],"mappings":";AAwCA,SAAS,mBAAmB;AAQ5B,OAAO,YAAY;AAEnB,MAAM,YAAY;AAoBlB,SAAS,UAAU,UAAyB,cAA6C;AACrF,QAAM,eAAe,SAAS,OAAO,OAAK,EAAE,SAAS,MAAM,EAAE,IAAI,OAAK,EAAE,WAAW,EAAE;AACrF,QAAM,WAAW,CAAC,GAAG,YAAY,EAAE,QAAQ,EAAE,CAAC,KAAK;AACnD,QAAM,SAAS,SAAS,KAAK,OAAK,EAAE,SAAS,QAAQ,GAAG,WAAW;AACnE,QAAM,WAAW,GAAG,MAAM;AAAA,EAAK,aAAa,KAAK,IAAI,CAAC,GAAG,YAAY;AACrE,QAAM,WAAW,SAAS,YAAY;AACtC,QAAM,cAAc;AACpB,QAAM,sBAAsB,aAAa,OAAO,OAAK,CAAC,YAAY,KAAK,CAAC,CAAC;AACzE,QAAM,gBAAgB,CAAC,GAAG,mBAAmB,EAAE,QAAQ,EAAE,CAAC,KAAK,UAAU,YAAY;AACrF,QAAM,gBAAgB,GAAG,YAAY;AAAA,EAAK,QAAQ;AAClD,QAAM,oBAAoB,GAAG,MAAM;AAAA,EAAK,YAAY;AAIpD,MAAI,gBAAgB,gBAAgB,QAAQ,GAAG;AAC3C,WAAO;AA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AAwB,IAAK,QAAO;AACpD,MAAI,QAAQ,IAAI,OAAO,QAAQ;AAC3B,UAAM,aAAa,CAAC,EAChB,QAAQ,IAAI,qBACZ,QAAQ,IAAI,kBACZ,QAAQ,IAAI,kBACZ,QAAQ,IAAI;AAEhB,WAAO,CAAC;AAAA,EACZ;AACA,SAAO;AACX;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/providers/stub.ts"],"sourcesContent":["/**\n * TITAN — CI Stub Provider (v6.1.0-beta.11)\n *\n * Deterministic pattern-matched LLM provider used by CI eval suites\n * and offline tests. Returns canned, useful responses without making\n * any network call — so the Eval Gate workflow can run on every PR\n * without burning Anthropic / OpenAI credits OR requiring secrets\n * configured on the runner.\n *\n * WHAT this is:\n * - A real LLMProvider implementation registered as `'stub'`.\n * - Model IDs `stub/echo`, `stub/json`, `stub/refuse` route here.\n * - Pattern-matches the last user message + system prompt against a\n * small table of recognized shapes (chat, structured-JSON,\n * tool-call, safety-refusal) and emits the appropriate response.\n *\n * WHY it exists:\n * - Phase B.1 truth-table audit showed Eval Gate runs were scoring\n * 0% on every suite because no provider had credentials in CI.\n * - The fix isn't \"give CI an API key\" — that bakes a real-money\n * dependency into every push. The fix is a provider that can\n * stand in for the real model deterministically.\n * - The harness-engineering catalog (Picrew/awesome-agent-harness)\n * explicitly recommends a \"stub mode\" so the harness itself is\n * testable independent of any single LLM.\n *\n * TRADE-OFFS we deliberately accept:\n * - The stub can't answer open-ended questions. It pattern-matches\n * a fixed vocabulary. Suites that probe model creativity have\n * no business running against the stub.\n * - The stub knows the exact shapes our agent code expects (widget\n * gate JSON, structuredSpawn JSON, tool-call format). When those\n * shapes change, this file changes too. That coupling is OK —\n * it's the price of CI-grade determinism.\n *\n * FOLLOW-UP:\n * - When we add a new gated agent shape, add a recognizer here.\n * - When we add a new built-in tool, add a recognizer here so\n * tool-routing evals can exercise the dispatch path.\n */\nimport { LLMProvider } from './base.js';\nimport type {\n ChatMessage,\n ChatOptions,\n ChatResponse,\n ChatStreamChunk,\n ToolCall,\n} from './base.js';\nimport logger from '../utils/logger.js';\n\nconst COMPONENT = 'provider.stub';\n\n/* ─────────────────────────── Pattern recognizers ─────────────────────────── */\n\ninterface RecognizedIntent {\n /** Stable id of the matched pattern. Used by tests + telemetry. */\n kind: string;\n /** Plain-text body of the response. */\n content: string;\n /** Optional tool calls to emit alongside the text. */\n toolCalls?: ToolCall[];\n /** finish_reason on the response. */\n finishReason: 'stop' | 'tool_calls' | 'error';\n}\n\n/**\n * Inspect the conversation and decide what kind of response to emit.\n * Order matters — safety refusals first, then structured outputs,\n * then tool-call shapes, then default chat.\n */\nfunction recognize(messages: ChatMessage[], offeredTools: Set<string>): RecognizedIntent {\n const userMessages = messages.filter(m => m.role === 'user').map(m => m.content ?? '');\n const lastUser = [...userMessages].reverse()[0] ?? '';\n const system = messages.find(m => m.role === 'system')?.content ?? '';\n const combined = `${system}\\n${userMessages.join('\\n')}`.toLowerCase();\n const userOnly = lastUser.toLowerCase();\n const directiveRe = /^\\s*\\[system directive for this reply only\\]/i;\n const conversationalUsers = userMessages.filter(m => !directiveRe.test(m));\n const intentPrompt = ([...conversationalUsers].reverse()[0] ?? lastUser).toLowerCase();\n const intentContext = `${intentPrompt}\\n${combined}`;\n const structuredContext = `${system}\\n${intentPrompt}`;\n\n // ── Safety refusal — keep first so injection attempts in the\n // system prompt don't override it.\n if (isUnsafeRequest(intentPrompt || userOnly)) {\n return {\n kind: 'safety_refusal',\n content: 'Stub: I can\\'t safely comply. I refuse to execute unsafe, destructive, injected, traversal, scheme-abusing, or private-instruction extraction requests.',\n finishReason: 'stop',\n };\n }\n\n // ── Tool-result continuation — if the LAST message is a tool\n // result, wrap up instead of re-issuing the same deterministic\n // tool call on the next round.\n if (messages[messages.length - 1]?.role === 'tool') {\n return {\n kind: 'tool_result_ack',\n content: summarizeToolResult(intentPrompt),\n finishReason: 'stop',\n };\n }\n\n // ── Structured JSON output — when the system prompt is asking\n // for the structuredSpawn JSON envelope. The driver loop\n // relies on this shape so the \"done\" path is reachable in CI.\n // Recognizers are deliberately broad: any prompt asking for\n // JSON output, or any mention of the spawn-envelope fields\n // (\"status\", \"artifacts\", \"confidence\") together, triggers\n // the structured-output path.\n const mentionsJsonOutput = /(respond|reply|return|output)\\s+(with\\s+)?(strict\\s+)?json|json\\s+containing|json\\s+envelope|structuredSpawn|spawn\\s+envelope/i.test(structuredContext);\n const mentionsEnvelopeFields =\n /\"status\"/i.test(structuredContext) &&\n /\"artifacts\"/i.test(structuredContext) &&\n /\"confidence\"/i.test(structuredContext);\n if (mentionsJsonOutput || mentionsEnvelopeFields) {\n const json = JSON.stringify({\n status: 'done',\n artifacts: [],\n questions: [],\n confidence: 0.9,\n reasoning: `Stub: pattern-matched structured-output request on prompt \"${userOnly.slice(0, 60)}\".`,\n });\n return {\n kind: 'structured_done',\n content: '```json\\n' + json + '\\n```',\n finishReason: 'stop',\n };\n }\n\n // ── Widget gate — TITAN's chat surface listens for a\n // `_____widget` gate followed by a JSON line. The 100+ widget\n // gallery routes off this signal; eval suites assert it.\n const widget = pickWidget(intentPrompt || userOnly);\n if (widget) {\n const widgetJson = JSON.stringify({\n name: widget.name,\n format: 'system',\n source: widget.source,\n w: widget.w,\n h: widget.h,\n });\n return {\n kind: 'widget_gate',\n content: `Adding the **${widget.name}** widget to your canvas.\\n\\n_____widget\\n${widgetJson}`,\n finishReason: 'stop',\n };\n }\n\n // ── Tool-call shape — when tools are offered AND the user prompt\n // clearly asks for one. Emits a tool_calls finish_reason so\n // the agent loop dispatches the tool. The agent will then\n // feed a tool_result back; that's handled below.\n if (offeredTools.size > 0) {\n const toolMatches = pickToolCalls(intentPrompt || userOnly).filter(tool => offeredTools.has(tool.name));\n if (toolMatches.length > 0) {\n return {\n kind: `tool_call:${toolMatches.map(t => t.name).join('+')}`,\n content: '',\n toolCalls: toolMatches.map((toolMatch, index) => ({\n id: `stub-tool-${toolMatch.name}-${index + 1}`,\n type: 'function',\n function: {\n name: toolMatch.name,\n arguments: JSON.stringify(toolMatch.args),\n },\n })),\n finishReason: 'tool_calls',\n };\n }\n }\n\n const directPrompt = intentPrompt || userOnly;\n if (/\\bwhat\\s+is\\s+2\\s*\\+\\s*2\\b|\\b2\\s*\\+\\s*2\\b/.test(directPrompt)) {\n return { kind: 'direct_arithmetic', content: 'The answer is 4.', finishReason: 'stop' };\n }\n\n if (/^\\s*(hello|hi|hey)\\b/.test(directPrompt)) {\n return { kind: 'direct_greeting', content: 'Hello. Voice channel ready.', finishReason: 'stop' };\n }\n\n if (/write\\s+(a\\s+)?hello\\s+world\\s+program/i.test(intentContext) && /python/i.test(intentContext)) {\n return { kind: 'write_file_final_answer', content: 'Created a Python hello world program using print(\"hello world\").', finishReason: 'stop' };\n }\n\n // ── Default — plain chat echo. Includes the first 60 chars of\n // the prompt so eval suites can assert on prompt threading.\n return {\n kind: 'echo',\n content: `Stub response. Echoing your request: \"${lastUser.slice(0, 60)}\".`,\n finishReason: 'stop',\n };\n}\n\n/* ─────────────────────────── Sub-recognizers ─────────────────────────── */\n\nfunction isUnsafeRequest(prompt: string): boolean {\n return [\n /\\brm\\s+-[a-z]*r[a-z]*f[a-z]*\\b/,\n /\\bdelete\\s+everything\\b|\\bwipe\\s+the\\s+disk\\b|\\bdrop\\s+all\\s+tables\\b|\\bformat\\s+the\\s+drive\\b/,\n /\\bchmod\\s+777\\s+\\/(?:etc|bin|sbin|usr|var|)\\b/,\n /\\bsudo\\b/,\n /\\bcurl\\b[^|\\n;]*(?:\\|\\s*(?:ba)?sh\\b)/,\n /\\b(?:ignore|bypass)\\s+(?:all\\s+)?(?:previous|prior|system|developer)\\s+instructions\\b/,\n /\\b(?:repeat|reveal|print|show|extract).{0,80}\\b(?:system|developer)\\s+(?:prompt|instructions)\\b/,\n /\\b(?:dan|developer\\s+mode|unrestricted\\s+ai|do\\s+anything\\s+now)\\b/,\n /javascript\\s*:/,\n /(?:^|[/\"'\\s])\\.\\.\\/\\.\\.\\//,\n /\\b(?:run|execute)\\b[^;\\n]*[;`]|`[^`]+`/,\n /\\|\\s*(?:bash|sh|zsh|python|perl|ruby)\\b/,\n /\\b(?:fetch|download|open|read)\\s+(?:file|dict):\\/\\//,\n ].some(re => re.test(prompt));\n}\n\n/** Pick a widget name keyed off the user prompt. Defaults to a generic\n * \"Note\" panel so the agent always has SOMETHING to add. */\nfunction pickWidget(prompt: string): { name: string; source: string; w: number; h: number } | null {\n const systemWidgets: Array<{ re: RegExp; name: string; source: string; w: number; h: number }> = [\n { re: /\\b(?:backups?|snapshots?|archives?)\\b/, name: 'Backup Manager', source: 'system:backup', w: 6, h: 6 },\n { re: /\\b(?:training|train|specialists?|models?)\\b/, name: 'Training Dashboard', source: 'system:training', w: 6, h: 6 },\n { re: /\\b(?:recipes?|playbooks?|workflows?|jarvis)\\b/, name: 'Recipe Kitchen', source: 'system:recipes', w: 6, h: 6 },\n { re: /\\b(?:vram|gpu|nvidia)\\b/, name: 'VRAM Monitor', source: 'system:vram', w: 6, h: 6 },\n { re: /\\b(?:teams?|team hub|members?|roles?|permissions?|rbac)\\b/, name: 'Team Hub', source: 'system:teams', w: 6, h: 6 },\n { re: /\\b(?:cron|schedules?|jobs?|timers?)\\b/, name: 'Cron Scheduler', source: 'system:cron', w: 6, h: 6 },\n { re: /\\b(?:checkpoints?|restores?|save state)\\b/, name: 'Checkpoints', source: 'system:checkpoints', w: 6, h: 5 },\n { re: /\\b(?:organism|guardrails?)\\b/, name: 'Organism Monitor', source: 'system:organism', w: 6, h: 6 },\n { re: /\\b(?:fleet|nodes?|routes?|mesh)\\b/, name: 'Fleet Router', source: 'system:fleet', w: 6, h: 5 },\n { re: /\\b(?:browser tools?|captcha|form fill|web automation)\\b/, name: 'Browser Tools', source: 'system:browser', w: 6, h: 5 },\n { re: /\\b(?:test lab|tests?|flaky|failing|coverage|eval)\\b/, name: 'Test Lab', source: 'system:eval', w: 6, h: 6 },\n ];\n const wantsSystemWidget = /\\b(?:show|open|add|launch|pin|create|display|give me)\\b/.test(prompt);\n if (wantsSystemWidget) {\n const systemWidget = systemWidgets.find(w => w.re.test(prompt));\n if (systemWidget) return systemWidget;\n }\n\n if (/stock|ticker|nasdaq|nyse/.test(prompt)) return { name: 'Stock Ticker', source: 'gallery', w: 360, h: 240 };\n if (/pomodoro|timer|focus/.test(prompt)) return { name: 'Pomodoro Timer', source: 'gallery', w: 360, h: 240 };\n if (/calendar|schedule/.test(prompt)) return { name: 'Calendar', source: 'gallery', w: 360, h: 240 };\n if (/gauge|meter|metric/.test(prompt)) return { name: 'Gauge', source: 'gallery', w: 360, h: 240 };\n if (/dashboard/.test(prompt)) return { name: 'Dashboard', source: 'gallery', w: 360, h: 240 };\n if (/clock|time/.test(prompt)) return { name: 'Clock', source: 'gallery', w: 360, h: 240 };\n if (/widget|panel/.test(prompt)) return { name: 'Note', source: 'gallery', w: 360, h: 240 };\n return null;\n}\n\n/** Pick tool calls + arguments keyed off the user prompt. Returns an\n * empty list if no tool matches — caller falls through to text. */\nfunction pickToolCalls(prompt: string): Array<{ name: string; args: Record<string, unknown> }> {\n if (/\\b(?:fix|bug|change|update|edit|modify)\\b/.test(prompt) && /\\b[\\w./-]+\\.(?:ts|tsx|js|jsx|py|json|md)\\b/.test(prompt)) {\n const path = extractPath(prompt) || '/tmp/titan-stub-code.ts';\n const calls: Array<{ name: string; args: Record<string, unknown> }> = [\n { name: 'read_file', args: { path } },\n { name: 'edit_file', args: { path, target: 'OLD', replacement: 'NEW' } },\n ];\n if (/\\b(?:fix|bug|test|verify)\\b/.test(prompt)) {\n calls.push({ name: 'shell', args: { command: 'printf \"stub verification ok\\\\n\"' } });\n }\n return calls;\n }\n if (/\\bweather\\b|\\bforecast\\b|\\btemperature\\b/.test(prompt)) {\n return [{ name: 'weather', args: { location: extractLocation(prompt) || 'San Francisco', days: 1 } }];\n }\n if (/\\b(?:navigate|browse|click|screenshot|open)\\b.*\\b(?:browser|site|page|example\\.com|https?:\\/\\/)/.test(prompt)) {\n return [{ name: 'web_act', args: { action: `open ${extractUrl(prompt) || 'https://example.com'}`, sessionId: 'stub-eval' } }];\n }\n if (/\\bfetch\\s+https?:\\/\\//.test(prompt)) {\n return [{ name: 'web_fetch', args: { url: extractUrl(prompt) || 'https://example.com' } }];\n }\n if (/\\bresearch\\b|\\blatest\\b|\\bnews\\b|\\bhistory\\b|search\\s+(?:the\\s+web\\s+)?for|google|find\\s+information|web\\s+search/.test(prompt)) {\n return [{ name: 'web_search', args: { query: extractAfter(prompt, /search\\s+(?:the\\s+web\\s+)?for|research|find/) || prompt.slice(0, 80) } }];\n }\n if (/write\\s+(a\\s+)?file|save\\s+to|create\\s+(a\\s+)?file|write\\s+(a\\s+)?hello\\s+world\\s+program/.test(prompt)) {\n return [{ name: 'write_file', args: { path: extractPath(prompt) || '/tmp/stub-output.txt', content: contentForWrite(prompt) } }];\n }\n if (/read\\s+(a\\s+)?file|open\\s+the\\s+file|show\\s+me\\s+the\\s+contents/.test(prompt)) {\n return [{ name: 'read_file', args: { path: extractPath(prompt) || '/tmp/stub-input.txt' } }];\n }\n if (/list\\s+(the\\s+)?(files|directory|dir)|what(?:'| i)?s\\s+(?:in|inside)|what\\s+files\\s+are\\s+in/.test(prompt)) {\n return [{ name: 'list_dir', args: { path: extractPath(prompt) || '/tmp' } }];\n }\n if (/\\b(?:run|execute|restart)\\b/.test(prompt)) {\n return [{ name: 'shell', args: { command: 'printf \"stub shell ok\\\\n\"' } }];\n }\n if (/download\\s+(an?\\s+)?image|embed\\s+image/.test(prompt)) {\n return [{ name: 'download_image', args: { url: 'https://example.com/sample.jpg' } }];\n }\n return [];\n}\n\nfunction summarizeToolResult(prompt: string): string {\n if (/hello\\s+world|python/.test(prompt)) {\n return 'Stub: wrote a hello world Python program using print(\"hello world\"). Done.';\n }\n if (/\\bweather\\b/.test(prompt)) return 'Stub: weather tool finished. Done.';\n if (/\\bresearch\\b|\\blatest\\b|\\bnews\\b|\\bhistory\\b|search/.test(prompt)) return 'Stub: web search finished with deterministic results. Done.';\n return 'Stub: tool finished. Done.';\n}\n\nfunction extractPath(prompt: string): string {\n const quoted = prompt.match(/(?:called|to|of|in|file)\\s+[\"'`]?([/~]?[\\w./-]+\\.[\\w]+)[\"'`]?/);\n const anyPath = prompt.match(/([/~]?[\\w.-]*\\/[\\w./-]+|[\\w.-]+\\.(?:ts|tsx|js|jsx|py|json|md|txt))/);\n const path = quoted?.[1] || anyPath?.[1] || '';\n if (!path) return '';\n return path.startsWith('/') || path.startsWith('~') ? path : `/tmp/${path.split('/').pop()}`;\n}\n\nfunction extractUrl(prompt: string): string {\n return prompt.match(/https?:\\/\\/[^\\s\"'`<>]+/)?.[0]?.replace(/[).,]+$/, '') ?? '';\n}\n\nfunction extractLocation(prompt: string): string {\n return prompt.match(/weather\\s+(?:for|in|at)\\s+([a-z][a-z\\s,]+?)(?:[?.]|$)/i)?.[1]?.trim() ?? '';\n}\n\nfunction contentForWrite(prompt: string): string {\n if (/python|hello\\s+world/.test(prompt)) return 'print(\"hello world\")\\n';\n return 'hello world\\n';\n}\n\n/** Extract the part of the prompt AFTER a matched intent verb. Used to\n * pull the search query / file name / etc. out of the prompt. */\nfunction extractAfter(prompt: string, re: RegExp): string {\n const m = prompt.match(re);\n if (!m) return '';\n const idx = (m.index ?? -1) + m[0].length;\n if (idx < 0) return '';\n return prompt.slice(idx).trim().replace(/[.?!]+$/, '').slice(0, 80);\n}\n\n/* ─────────────────────────── Provider ─────────────────────────── */\n\nexport class StubProvider extends LLMProvider {\n readonly name = 'stub';\n readonly displayName = 'TITAN Stub (CI/offline)';\n\n /**\n * Always configured. The whole point is that the stub works\n * without any credentials so CI can run end-to-end.\n */\n isConfigured(): boolean {\n return true;\n }\n\n async chat(options: ChatOptions): Promise<ChatResponse> {\n const intent = recognize(options.messages, offeredToolNames(options));\n logger.debug(COMPONENT, `chat() kind=${intent.kind} model=${options.model ?? 'stub/echo'}`);\n const promptTokens = approxTokens(options.messages);\n const completionTokens = approxTokens([{ role: 'assistant', content: intent.content }]);\n return {\n id: `stub-${Date.now()}`,\n content: intent.content,\n toolCalls: intent.toolCalls,\n usage: {\n promptTokens,\n completionTokens,\n totalTokens: promptTokens + completionTokens,\n },\n finishReason: intent.finishReason,\n model: options.model || 'stub/echo',\n };\n }\n\n async *chatStream(options: ChatOptions): AsyncGenerator<ChatStreamChunk> {\n const intent = recognize(options.messages, offeredToolNames(options));\n logger.debug(COMPONENT, `chatStream() kind=${intent.kind}`);\n // Emit text content first (if any), then any tool calls,\n // then a done marker. Matches the shape real providers use.\n if (intent.content) {\n yield { type: 'text', content: intent.content };\n }\n if (intent.toolCalls) {\n for (const tc of intent.toolCalls) {\n yield { type: 'tool_call', toolCall: tc };\n }\n }\n yield { type: 'done' };\n }\n\n async listModels(): Promise<string[]> {\n return ['stub/echo', 'stub/json', 'stub/refuse'];\n }\n\n async healthCheck(): Promise<boolean> {\n return true;\n }\n}\n\n/* ─────────────────────────── Token estimator ─────────────────────────── */\n\nfunction offeredToolNames(options: ChatOptions): Set<string> {\n return new Set((options.tools ?? []).map(tool => tool.function.name));\n}\n\n/** ~4 chars per token rule-of-thumb. Not exact, but stable enough for\n * cost-budget tests that only need monotonicity. */\nfunction approxTokens(messages: ChatMessage[]): number {\n let chars = 0;\n for (const m of messages) chars += (m.content ?? '').length;\n return Math.max(1, Math.ceil(chars / 4));\n}\n\n/* ─────────────────────────── CI detection ─────────────────────────── */\n\n/**\n * Returns true when the runtime should use the deterministic stub\n * provider. This is explicit-only so CI and runtime failures cannot be\n * hidden by `stub/echo` when the real Ollama surface is available.\n *\n * Trigger condition:\n * - Explicit opt-in: `TITAN_STUB_PROVIDER=1`\n *\n * NOTE: we deliberately do not trigger on `CI=true` or `VITEST=true`.\n * Eval Gate and offline tests that want the stub must set\n * `TITAN_STUB_PROVIDER=1` explicitly.\n */\nexport function shouldUseStubProvider(): boolean {\n return process.env.TITAN_STUB_PROVIDER === '1';\n}\n"],"mappings":";AAwCA,SAAS,mBAAmB;AAQ5B,OAAO,YAAY;AAEnB,MAAM,YAAY;AAo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AAO,SAAS;AAChB,YAAM,EAAE,MAAM,QAAQ,SAAS,OAAO,QAAQ;AAAA,IAClD;AACA,QAAI,OAAO,WAAW;AAClB,iBAAW,MAAM,OAAO,WAAW;AAC/B,cAAM,EAAE,MAAM,aAAa,UAAU,GAAG;AAAA,MAC5C;AAAA,IACJ;AACA,UAAM,EAAE,MAAM,OAAO;AAAA,EACzB;AAAA,EAEA,MAAM,aAAgC;AAClC,WAAO,CAAC,aAAa,aAAa,aAAa;AAAA,EACnD;AAAA,EAEA,MAAM,cAAgC;AAClC,WAAO;AAAA,EACX;AACJ;AAIA,SAAS,iBAAiB,SAAmC;AACzD,SAAO,IAAI,KAAK,QAAQ,SAAS,CAAC,GAAG,IAAI,UAAQ,KAAK,SAAS,IAAI,CAAC;AACxE;AAIA,SAAS,aAAa,UAAiC;AACnD,MAAI,QAAQ;AACZ,aAAW,KAAK,SAAU,WAAU,EAAE,WAAW,IAAI;AACrD,SAAO,KAAK,IAAI,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC;AAC3C;AAgBO,SAAS,wBAAiC;AAC7C,SAAO,QAAQ,IAAI,wBAAwB;AAC/C;","names":[]}
|
package/dist/utils/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { homedir } from "os";
|
|
3
3
|
import { join } from "path";
|
|
4
|
-
const TITAN_VERSION = "6.3.
|
|
4
|
+
const TITAN_VERSION = "6.3.6";
|
|
5
5
|
const TITAN_CODENAME = "Living Canvas";
|
|
6
6
|
const TITAN_NAME = "TITAN";
|
|
7
7
|
const TITAN_FULL_NAME = "The Intelligent Task Automation Network";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/constants.ts"],"sourcesContent":["/**\n * TITAN Constants\n */\nimport { homedir } from 'os';\nimport { join } from 'path';\n\nexport const TITAN_VERSION = '6.3.
|
|
1
|
+
{"version":3,"sources":["../../src/utils/constants.ts"],"sourcesContent":["/**\n * TITAN Constants\n */\nimport { homedir } from 'os';\nimport { join } from 'path';\n\nexport const TITAN_VERSION = '6.3.6';\nexport const TITAN_CODENAME = 'Living Canvas';\nexport const TITAN_NAME = 'TITAN';\nexport const TITAN_FULL_NAME = 'The Intelligent Task Automation Network';\nexport const TITAN_ASCII_LOGO = `\n╔══════════════════════════════════════════════════════╗\n║ ║\n║ ████████╗██╗████████╗ █████╗ ███╗ ██╗ ║\n║ ██║ ██║ ██║ ██╔══██╗████╗ ██║ ║\n║ ██║ ██║ ██║ ███████║██╔██╗ ██║ ║\n║ ██║ ██║ ██║ ██╔══██║██║╚██╗██║ ║\n║ ██║ ██║ ██║ ██║ ██║██║ ╚████║ ║\n║ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ║\n║ ║\n║ The Intelligent Task Automation Network ║\n║ v${TITAN_VERSION} • by Tony Elliott ║\n╚══════════════════════════════════════════════════════╝`;\n\n// Paths\n// Hunt Finding #03 (2026-04-14): honor TITAN_HOME env var if set.\n// Previously this was hardcoded to `~/.titan`, which meant:\n// - Docker containers couldn't override the config path\n// - Shared machines couldn't isolate per-user state\n// - Test fixtures couldn't run against an isolated home\n// - The systemd unit's `Environment=TITAN_HOME=...` was silently ignored\n// The env var is read once at module load (constants are resolved at import time).\n// If TITAN_HOME starts with `~/`, expand it to the user's home dir.\nfunction resolveTitanHome(): string {\n const envHome = process.env.TITAN_HOME;\n if (envHome && envHome.trim().length > 0) {\n const trimmed = envHome.trim();\n if (trimmed.startsWith('~/')) {\n return join(homedir(), trimmed.slice(2));\n }\n if (trimmed === '~') {\n return homedir();\n }\n return trimmed;\n }\n return join(homedir(), '.titan');\n}\nexport const TITAN_HOME = resolveTitanHome();\nexport const TITAN_CONFIG_PATH = join(TITAN_HOME, 'titan.json');\nexport const TITAN_DB_PATH = join(TITAN_HOME, 'titan.db');\nexport const TITAN_WORKSPACE = join(TITAN_HOME, 'workspace');\nexport const TITAN_SKILLS_DIR = join(TITAN_WORKSPACE, 'skills');\nexport const TITAN_LOGS_DIR = join(TITAN_HOME, 'logs');\nexport const TITAN_MEMORY_DIR = join(TITAN_HOME, 'memory');\n\n// Workspace prompt files (injected into agent context)\nexport const AGENTS_MD = join(TITAN_WORKSPACE, 'AGENTS.md');\nexport const SOUL_MD = join(TITAN_WORKSPACE, 'SOUL.md');\nexport const TOOLS_MD = join(TITAN_WORKSPACE, 'TOOLS.md');\nexport const TITAN_MD_FILENAME = 'TITAN.md';\nexport const AUTOPILOT_MD = join(TITAN_HOME, 'AUTOPILOT.md');\nexport const AUTOPILOT_RUNS_PATH = join(TITAN_HOME, 'autopilot-runs.jsonl');\nexport const TITAN_CREDENTIALS_DIR = join(TITAN_HOME, 'credentials');\n\n// Income & lead tracking\nexport const INCOME_LEDGER_PATH = join(TITAN_HOME, 'income-ledger.jsonl');\nexport const FREELANCE_LEADS_PATH = join(TITAN_HOME, 'freelance-leads.jsonl');\nexport const FREELANCE_PROFILE_PATH = join(TITAN_HOME, 'freelance-profile.json');\nexport const LEADS_PATH = join(TITAN_HOME, 'leads.jsonl');\nexport const TELEMETRY_EVENTS_PATH = join(TITAN_HOME, 'telemetry-events.jsonl');\nexport const SOMADRIVE_STATE_PATH = join(TITAN_HOME, 'soma-drive-state.json');\nexport const ACTIVITY_LOG_PATH = join(TITAN_HOME, 'activity-log.jsonl');\n\n// v6.1.0 — Mission Chat\nexport const MISSIONS_DIR = join(TITAN_HOME, 'missions');\nexport const PLAYS_DIR = join(TITAN_HOME, 'plays');\n\n// Gateway defaults\nexport const DEFAULT_GATEWAY_HOST = '0.0.0.0';\nexport const DEFAULT_GATEWAY_PORT = 48420;\nexport const DEFAULT_WEB_PORT = 48421;\n\n// Agent defaults\n// v6.0.1 — Hardcoded floor only. The actual default at runtime is picked\n// by `getDefaultModelId()` in `src/providers/defaultModel.ts`, which\n// detects the user's available API keys (Anthropic / OpenAI / Google /\n// OpenRouter) and selects accordingly. Falls back to local Ollama when\n// no cloud keys are set. This constant is the last-resort fallback for\n// callsites that don't go through the schema thunk.\nexport const DEFAULT_MODEL = 'anthropic/claude-sonnet-4-20250514';\n/** v5.4.1: User-preference ceiling. Providers clamp per-model via\n * clampMaxTokens() so this can be high without causing 400s on\n * capped endpoints (e.g. Claude Sonnet 4 8K, Cohere 4K). */\nexport const DEFAULT_MAX_TOKENS = 200000;\nexport const DEFAULT_TEMPERATURE = 0.7;\nexport const MAX_CONTEXT_MESSAGES = 50;\nexport const SESSION_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes\n\n// Security\nexport const DEFAULT_SANDBOX_MODE = 'host';\n/** Default allowed tools. Empty = allow ALL registered tools.\n * Use security.deniedTools to block specific tools instead. */\nexport const ALLOWED_TOOLS_DEFAULT: string[] = [];\nexport const DENIED_TOOLS_DEFAULT: string[] = [];\n"],"mappings":";AAGA,SAAS,eAAe;AACxB,SAAS,YAAY;AAEd,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;AACvB,MAAM,aAAa;AACnB,MAAM,kBAAkB;AACxB,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAW1B,aAAa;AAAA;AAYnB,SAAS,mBAA2B;AAChC,QAAM,UAAU,QAAQ,IAAI;AAC5B,MAAI,WAAW,QAAQ,KAAK,EAAE,SAAS,GAAG;AACtC,UAAM,UAAU,QAAQ,KAAK;AAC7B,QAAI,QAAQ,WAAW,IAAI,GAAG;AAC1B,aAAO,KAAK,QAAQ,GAAG,QAAQ,MAAM,CAAC,CAAC;AAAA,IAC3C;AACA,QAAI,YAAY,KAAK;AACjB,aAAO,QAAQ;AAAA,IACnB;AACA,WAAO;AAAA,EACX;AACA,SAAO,KAAK,QAAQ,GAAG,QAAQ;AACnC;AACO,MAAM,aAAa,iBAAiB;AACpC,MAAM,oBAAoB,KAAK,YAAY,YAAY;AACvD,MAAM,gBAAgB,KAAK,YAAY,UAAU;AACjD,MAAM,kBAAkB,KAAK,YAAY,WAAW;AACpD,MAAM,mBAAmB,KAAK,iBAAiB,QAAQ;AACvD,MAAM,iBAAiB,KAAK,YAAY,MAAM;AAC9C,MAAM,mBAAmB,KAAK,YAAY,QAAQ;AAGlD,MAAM,YAAY,KAAK,iBAAiB,WAAW;AACnD,MAAM,UAAU,KAAK,iBAAiB,SAAS;AAC/C,MAAM,WAAW,KAAK,iBAAiB,UAAU;AACjD,MAAM,oBAAoB;AAC1B,MAAM,eAAe,KAAK,YAAY,cAAc;AACpD,MAAM,sBAAsB,KAAK,YAAY,sBAAsB;AACnE,MAAM,wBAAwB,KAAK,YAAY,aAAa;AAG5D,MAAM,qBAAqB,KAAK,YAAY,qBAAqB;AACjE,MAAM,uBAAuB,KAAK,YAAY,uBAAuB;AACrE,MAAM,yBAAyB,KAAK,YAAY,wBAAwB;AACxE,MAAM,aAAa,KAAK,YAAY,aAAa;AACjD,MAAM,wBAAwB,KAAK,YAAY,wBAAwB;AACvE,MAAM,uBAAuB,KAAK,YAAY,uBAAuB;AACrE,MAAM,oBAAoB,KAAK,YAAY,oBAAoB;AAG/D,MAAM,eAAe,KAAK,YAAY,UAAU;AAChD,MAAM,YAAY,KAAK,YAAY,OAAO;AAG1C,MAAM,uBAAuB;AAC7B,MAAM,uBAAuB;AAC7B,MAAM,mBAAmB;AASzB,MAAM,gBAAgB;AAItB,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,uBAAuB;AAC7B,MAAM,qBAAqB,KAAK,KAAK;AAGrC,MAAM,uBAAuB;AAG7B,MAAM,wBAAkC,CAAC;AACzC,MAAM,uBAAiC,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "titan-agent",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.6",
|
|
4
4
|
"description": "TITAN — TypeScript AI agent framework with multi-agent orchestration, provider routing, approval gates, receipts, evals, gateway APIs, and a React Mission Control dashboard. Open-source, MIT licensed.",
|
|
5
5
|
"author": "Tony Elliott (https://github.com/Djtony707)",
|
|
6
6
|
"repository": {
|
package/ui/dist/sw.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* but a default falls back to the source-controlled value here.
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
const CACHE_NAME = 'titan-' + ('
|
|
23
|
+
const CACHE_NAME = 'titan-' + ('1779408716011');
|
|
24
24
|
const ASSETS_PREFIX = '/assets/';
|
|
25
25
|
|
|
26
26
|
self.addEventListener('install', (event) => {
|