osborn 0.5.2 → 0.5.5

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.
Files changed (37) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.claude/skills/markdown-to-pdf/SKILL.md +29 -0
  3. package/.claude/skills/pdf-to-markdown/SKILL.md +28 -0
  4. package/.claude/skills/playwright-browser/SKILL.md +75 -0
  5. package/.claude/skills/youtube-transcript/SKILL.md +24 -0
  6. package/dist/claude-llm.d.ts +29 -1
  7. package/dist/claude-llm.js +346 -79
  8. package/dist/config.d.ts +6 -2
  9. package/dist/config.js +6 -1
  10. package/dist/fast-brain.d.ts +124 -12
  11. package/dist/fast-brain.js +1361 -96
  12. package/dist/index-3-2-26-legacy.d.ts +1 -0
  13. package/dist/index-3-2-26-legacy.js +2233 -0
  14. package/dist/index.js +889 -394
  15. package/dist/jsonl-search.d.ts +66 -0
  16. package/dist/jsonl-search.js +274 -0
  17. package/dist/leagcyprompts2.d.ts +0 -0
  18. package/dist/leagcyprompts2.js +573 -0
  19. package/dist/pipeline-direct-llm.d.ts +77 -0
  20. package/dist/pipeline-direct-llm.js +216 -0
  21. package/dist/pipeline-fastbrain.d.ts +45 -0
  22. package/dist/pipeline-fastbrain.js +367 -0
  23. package/dist/prompts-2-25-26.d.ts +0 -0
  24. package/dist/prompts-2-25-26.js +518 -0
  25. package/dist/prompts-3-2-26.d.ts +78 -0
  26. package/dist/prompts-3-2-26.js +1319 -0
  27. package/dist/prompts.d.ts +83 -8
  28. package/dist/prompts.js +1990 -374
  29. package/dist/session-access.d.ts +60 -2
  30. package/dist/session-access.js +172 -2
  31. package/dist/summary-index.d.ts +87 -0
  32. package/dist/summary-index.js +570 -0
  33. package/dist/turn-detector-shim.d.ts +24 -0
  34. package/dist/turn-detector-shim.js +83 -0
  35. package/dist/voice-io.d.ts +9 -3
  36. package/dist/voice-io.js +39 -20
  37. package/package.json +18 -11
@@ -1,31 +1,40 @@
1
1
  /**
2
- * Fast Brain Agent Middle-tier intelligence for the Voice AI System
2
+ * Fast Brain — Central Orchestrator for the Voice AI System
3
3
  *
4
- * A fast intermediary between the realtime voice model and the Claude SDK agent.
5
- * Uses direct API calls for ~2 second responses.
4
+ * The sole intelligence layer between the user and all backend capabilities.
5
+ * The realtime voice model is a thin teleprompter — it speaks what this module returns.
6
6
  *
7
7
  * Capabilities:
8
8
  * - Read/write session files (spec.md + library/)
9
9
  * - Web search for quick factual lookups
10
10
  * - Record user decisions and preferences into spec.md
11
- * - Post-research: synthesize findings into spec.md
12
- * - Escalate to ask_agent when deeper research is needed
11
+ * - Trigger deep research (via callbacks to index.ts)
12
+ * - Generate teleprompter scripts for ALL voice output
13
+ * - Post-research: synthesize findings from JSONL into spec.md + voice scripts
14
+ * - Generate visual documents (comparison, diagram, analysis, summary)
13
15
  *
14
- * Key constraint: The fast brain NEVER calls ask_agent. The realtime model is always the router.
16
+ * Central function: askFastBrain() ALL user questions route here.
17
+ * It returns a FastBrainResponse with a teleprompter script the voice model reads verbatim.
15
18
  *
16
19
  * Auth chain (tried in order):
17
20
  * 1. ANTHROPIC_API_KEY env var → Anthropic SDK (Haiku)
18
21
  * 2. ANTHROPIC_AUTH_TOKEN env var → Anthropic SDK (Haiku)
19
22
  * 3. GOOGLE_API_KEY env var → Gemini Flash fallback
20
- *
21
- * Note: Claude Code OAuth (macOS Keychain) was tested but Anthropic's Messages API
22
- * rejects OAuth tokens with 401 "OAuth authentication is currently not supported."
23
23
  */
24
24
  /**
25
25
  * Extract useful content snippets from tool responses, truncated by tool type.
26
26
  * Returns null for tools with no useful content (Write confirmations, etc.)
27
27
  */
28
28
  export declare function extractToolContent(toolName: string, toolInput: any, toolResponse: any): string | null;
29
+ /** A single voice conversation turn from the realtime LLM's chatCtx */
30
+ export interface ConversationTurn {
31
+ role: 'user' | 'assistant';
32
+ text: string;
33
+ }
34
+ /** Clear fast brain session state — call on disconnect/reconnect/session switch */
35
+ export declare function clearFastBrainSession(): void;
36
+ /** @deprecated Use clearFastBrainSession() instead */
37
+ export declare function clearFastBrainHistory(): void;
29
38
  /**
30
39
  * Ask the fast brain a question with access to session files and web search.
31
40
  * Returns an answer or "NEEDS_DEEPER_RESEARCH: ..." for escalation.
@@ -35,17 +44,49 @@ export declare function extractToolContent(toolName: string, toolInput: any, too
35
44
  * @param researchContext - Optional snapshot of the live research log.
36
45
  * ~2 second response time for most queries.
37
46
  */
38
- export declare function askHaiku(workingDir: string, sessionId: string, question: string, researchContext?: string): Promise<string>;
47
+ export declare function askHaiku(workingDir: string, sessionId: string, question: string, researchContext?: string, chatHistory?: ConversationTurn[], sendToChat?: (text: string) => void, sessionBaseDir?: string): Promise<string>;
48
+ /** Callbacks for the fast brain to trigger side effects in index.ts */
49
+ export interface FastBrainCallbacks {
50
+ triggerResearch: (task: string) => void;
51
+ queueVoice: (script: string) => void;
52
+ sendToFrontend: (data: any) => void;
53
+ }
54
+ /** Structured response from the fast brain orchestrator */
55
+ export interface FastBrainResponse {
56
+ /** Teleprompter script for the voice model to speak */
57
+ script: string;
58
+ /** Response type for caller routing */
59
+ type: 'answer' | 'research_started' | 'recorded' | 'question';
60
+ }
61
+ /**
62
+ * Central orchestrator — ALL user questions from the realtime model come here.
63
+ * Routes to: direct answer, research triggering, decision recording, or document generation.
64
+ * Returns a teleprompter script the voice model reads verbatim.
65
+ */
66
+ export declare function askFastBrain(workingDir: string, sessionId: string, question: string, opts: {
67
+ chatHistory?: ConversationTurn[];
68
+ researchContext?: string;
69
+ callbacks: FastBrainCallbacks;
70
+ sessionBaseDir?: string;
71
+ }): Promise<FastBrainResponse>;
39
72
  /**
40
73
  * Process a batch of research content chunks through the fast brain.
41
74
  * Updates spec.md and library/ files incrementally during research.
42
75
  *
43
76
  * @param isRefinement - true for the final post-research consolidation pass (higher token budget)
44
77
  */
45
- export declare function processResearchChunk(workingDir: string, sessionId: string, task: string, contentChunks: string[], isRefinement?: boolean): Promise<{
78
+ export declare function processResearchChunk(workingDir: string, sessionId: string, task: string, contentChunks: string[], isRefinement?: boolean, sessionBaseDir?: string): Promise<{
46
79
  spec: string | null;
47
80
  libraryFiles: string[];
48
81
  } | null>;
82
+ /**
83
+ * Augment agent SDK research results with context from spec.md.
84
+ * Passes ALL specific details through verbatim — only ADDS context annotations.
85
+ * The voice model downstream handles summarization for speech.
86
+ *
87
+ * Falls back to returning the original result if the fast brain is unavailable.
88
+ */
89
+ export declare function augmentResearchResult(workingDir: string, sessionId: string, task: string, agentResult: string): Promise<string>;
49
90
  /**
50
91
  * Update spec.md and library/ files after research completes.
51
92
  * Reads FULL untruncated data directly from Claude Agent SDK JSONL files
@@ -58,7 +99,78 @@ export declare function processResearchChunk(workingDir: string, sessionId: stri
58
99
  *
59
100
  * Returns { spec, libraryFiles } or null if update failed.
60
101
  */
61
- export declare function updateSpecFromJSONL(workingDir: string, sessionId: string, task: string, researchLog: string[]): Promise<{
102
+ export declare function updateSpecFromJSONL(workingDir: string, sessionId: string, task: string, researchLog: string[], sessionBaseDir?: string): Promise<{
62
103
  spec: string | null;
63
104
  libraryFiles: string[];
64
105
  } | null>;
106
+ /**
107
+ * Fire-and-forget: Write a user question to spec.md Open Questions > From User
108
+ * before the agent starts researching. Ensures every escalated question is tracked.
109
+ *
110
+ * Uses a simple LLM call to fuzzy-match existing questions and avoid duplicates.
111
+ * Skips if spec.md doesn't exist yet or no provider is available.
112
+ */
113
+ export declare function writeQuestionToSpec(workingDir: string, sessionId: string, question: string): Promise<void>;
114
+ /**
115
+ * Fire-and-forget: Check if substantial agent output answers any open questions in spec.md.
116
+ * Debounced (3s) to prevent flooding during rapid tool_result sequences.
117
+ *
118
+ * When a question is answered, marks it with [x] and moves the answer to Findings.
119
+ */
120
+ export declare function checkOutputAgainstQuestions(workingDir: string, sessionId: string, output: string, outputType: 'tool_result' | 'assistant_text'): Promise<void>;
121
+ /**
122
+ * Generate a natural, contextualized voice update from raw research events.
123
+ * Called by scheduleResearchBatch() instead of injecting raw events directly.
124
+ *
125
+ * Returns a natural 1-2 sentence update, or null if nothing interesting to say.
126
+ * 3-second timeout — returns null if the LLM is too slow.
127
+ */
128
+ export declare function contextualizeResearchUpdate(workingDir: string, sessionId: string, task: string, batchEvents: string[], researchLog: string[], chatHistory?: ConversationTurn[], sessionBaseDir?: string): Promise<string | null>;
129
+ /**
130
+ * Generate a proactive conversational prompt to keep the user engaged during research.
131
+ * Called periodically (every 15s) during active research.
132
+ *
133
+ * Can ask open questions, discuss implications of findings, or give progress with depth.
134
+ * Returns null/NOTHING if nothing interesting to say.
135
+ * 3-second timeout.
136
+ */
137
+ export declare function generateProactivePrompt(workingDir: string, sessionId: string, task: string, researchLog: string[], previousPrompts: string[], sessionBaseDir?: string): Promise<string | null>;
138
+ /**
139
+ * Generate a structured visual document (comparison table, Mermaid diagram,
140
+ * analysis, or summary) from research findings.
141
+ *
142
+ * Reads spec.md, JSONL results, and library for context.
143
+ * Writes the result to library/ and returns the filename + content.
144
+ */
145
+ export declare function generateVisualDocument(workingDir: string, sessionId: string, request: string, documentType: 'comparison' | 'diagram' | 'analysis' | 'summary', sessionBaseDir?: string): Promise<{
146
+ fileName: string;
147
+ content: string;
148
+ } | null>;
149
+ /**
150
+ * Generate a complete teleprompter script from research results.
151
+ * Replaces augmentResearchResult + extractPriorityContent.
152
+ * Reads full JSONL and produces a spoken monologue.
153
+ */
154
+ export declare function processResearchCompletion(workingDir: string, sessionId: string, task: string, agentResult: string, chatHistory?: ConversationTurn[], sendToChat?: (text: string) => void, sessionBaseDir?: string): Promise<string>;
155
+ /**
156
+ * Process a batch of research events and decide whether to speak.
157
+ * Replaces contextualizeResearchUpdate — but usually returns null (silent).
158
+ * Only speaks when something genuinely critical is found.
159
+ */
160
+ export declare function handleResearchBatch(workingDir: string, sessionId: string, task: string, batchEvents: string[], researchLog: string[], chatHistory?: ConversationTurn[], sessionBaseDir?: string): Promise<string | null>;
161
+ /**
162
+ * Generate a brief spoken script for session resume or switch.
163
+ * Replaces buildContextBriefing + getSpecForVoiceModel.
164
+ */
165
+ export declare function prepareBriefingScript(workingDir: string, sessionId: string, conversationHistory?: {
166
+ role: string;
167
+ text: string;
168
+ }[], type?: 'resume' | 'switch' | 'default'): Promise<string>;
169
+ /**
170
+ * Generate a spoken script after Gemini auto-recovery.
171
+ * Replaces inline recovery logic in index.ts.
172
+ */
173
+ export declare function prepareRecoveryScript(conversationHistory?: {
174
+ role: string;
175
+ text: string;
176
+ }[]): Promise<string>;