osborn 0.9.282 → 0.9.284

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.
@@ -12,6 +12,7 @@
12
12
  * get_recent — latest N index entries + full content
13
13
  * emergency_stop — interrupt the main agent's turn and redirect it (background tasks survive)
14
14
  */
15
+ import { getPipelineFastBrainPrompt } from './prompts.js';
15
16
  // ============================================================
16
17
  // CONSTANTS
17
18
  // ============================================================
@@ -287,55 +288,11 @@ async function getRecentEntries(sessionId, workingDir, _, count) {
287
288
  //
288
289
  // PROMPT-CACHING NOTE (Fireworks/z.ai auto-cache long prefixes): the system
289
290
  // message is the START of the OpenAI prompt and those providers cache by
290
- // prefix. buildSystemPrompt() is therefore fully STATIC — the volatile
291
+ // prefix. The system prompt (prompts/pipeline-fast-brain.md) is therefore fully STATIC — the volatile
291
292
  // per-call inputs (chatHistory, researchContext) live in buildTurnContext()
292
293
  // and are prepended to the CURRENT user message instead, so the system +
293
294
  // persistent-messages prefix stays byte-identical across a session and every
294
295
  // turn after the first is a cache hit.
295
- function buildSystemPrompt() {
296
- const parts = [
297
- `You are a fast memory recall agent for a voice AI assistant called Osborn.`,
298
- `You search the user's conversation history — their questions, the assistant's answers,`,
299
- `tool calls, research findings, and decisions — stored as indexed session files.`,
300
- `Tools: search_session (keyword search) and get_recent (latest activity).`,
301
- ``,
302
- `== OBJECTIVE ==`,
303
- `Answer from session history. Search first for any recall question.`,
304
- `Greetings/thanks/confirmations: respond directly, no search.`,
305
- `Tasks needing live code analysis or new research: respond with [RESEARCH_NEEDED]`,
306
- ``,
307
- `== STYLE ==`,
308
- `1-3 sentences. Grounded in results. Never fabricate.`,
309
- `Answer in plain prose ONLY. NEVER include result header lines (the`,
310
- `"[source L… · msgType · matchedBy] timestamp" brackets), line numbers, or raw`,
311
- `timestamps in your reply — those are internal provenance the user must never see.`,
312
- `If not found after thorough searching: "I didn't find that in the session history."`,
313
- ``,
314
- `== AUDIENCE ==`,
315
- `A user having a conversation via voice. Questions may be casual, rambling,`,
316
- `or use vague references ("that thing", "the error"). Interpret intent, not just words.`,
317
- ``,
318
- `== RESULTS FORMAT ==`,
319
- `Each hit is a header line then its FULL untruncated text:`,
320
- ` [<source> L<lineNum> · <msgType>[:<tool>] · <matchedBy>] <timestamp>`,
321
- ` <full text of that message/tool result>`,
322
- ` source: "main" = conversation, "agent-XXXX" = sub-agent research.`,
323
- ` matchedBy: keyword | vector | both (how recall found it — vector/hybrid is preferred).`,
324
- ``,
325
- `== HOW TO SEARCH ==`,
326
- `Think about what words people ACTUALLY USED when this topic came up.`,
327
- `PHRASES: 1-4 words each, multiple phrases per call.`,
328
- ` Short precise terms beat long phrases. "error" finds more than "error we got".`,
329
- `RETRIES (4 rounds — use them before giving up):`,
330
- ` 1: Specific terms from the question.`,
331
- ` 2: Think about how the conversation would READ when this was discussed.`,
332
- ` 3: Related terms — names, tools, files that would appear near the topic.`,
333
- ` 4: Broad single words — cast a wide net.`,
334
- ` Only say "didn't find" after 3+ failed rounds.`,
335
- `⚠ Your own prior answers may have errors. Trust search results over your memory.`,
336
- ];
337
- return parts.join('\n');
338
- }
339
296
  /**
340
297
  * Volatile per-turn context (recent conversation, active research) that USED to be
341
298
  * interpolated into the system prompt. Moved into the first user message so the
@@ -388,6 +345,29 @@ async function callOpenRouter(messages, tools, apiKey) {
388
345
  // ============================================================
389
346
  // MAIN FUNCTION
390
347
  // ============================================================
348
+ // The fast brain stating its own limits is a hand-off (the main agent has those tools);
349
+ // recall that mentions a tool or an inability stays an answer (see the guard test).
350
+ const CAPABILITY_DENIAL = new RegExp([
351
+ /(?:\bI(?:'m| am)?|\bsorry,?)\s+(?:not able to|unable to|can't|cannot|can not|(?:don't|do not) have (?:the ability|a way|any way) to)\s+(?:actually\s+|directly\s+)?/.source +
352
+ /(?:browse|record (?:a |the )?(?:video|audio|screen|clip|page)|take (?:a )?screenshots?|edit|build|run|execute|open|visit|fetch|download|access)\b(?!\s+(?:through|over|down)\b)/.source,
353
+ /\bI(?:'m| am)?\s+(?:not able to|unable to|don't|do not|can't|cannot|can not|have no|lack)\b(?!\s+(?:find|see|locate|recall|spot|remember|know|tell|wait|record|details)\b)/.source +
354
+ /[^.!?\n]{0,60}?\b(?:browser|bash|shell|terminal|internet)\b(?!\s+(?:output|logs?|command|script|session|history)\b)/.source,
355
+ ].join('|'), 'i');
356
+ export const isHandOff = (text) => text.includes('[RESEARCH_NEEDED]') || CAPABILITY_DENIAL.test(text.replace(/[\u2018\u2019]/g, "'"));
357
+ /** Every exit that carries model text: sanitise, then answer or hand off. A hand-off
358
+ * carries no text (nothing for a consumer to post) and is not kept in the fast
359
+ * brain's own history, so a suppressed denial cannot prime the next turn. */
360
+ function finish(question, raw, toolsUsed) {
361
+ const text = sanitizeFastBrainAnswer((raw || '').trim());
362
+ persistentMessages.push({ role: 'user', content: question });
363
+ console.log(`🧠⚡ [pipeline-fb] ${toolsUsed.length} searches, answer: "${text.substring(0, 80)}"`);
364
+ if (isHandOff(text))
365
+ return { script: '', type: 'research_needed', toolsUsed };
366
+ if (!text)
367
+ return { script: "I didn't find that in the session history.", type: 'answer', toolsUsed };
368
+ persistentMessages.push({ role: 'assistant', content: text });
369
+ return { script: text, type: 'answer', toolsUsed };
370
+ }
391
371
  /**
392
372
  * Strip internal recall provenance the fast brain may echo into its answer so
393
373
  * the user never sees it: citation headers like
@@ -437,7 +417,7 @@ export async function askPipelineFastBrain(workingDir, sessionId, question, opts
437
417
  if (persistentMessages.length > 24) {
438
418
  persistentMessages = persistentMessages.slice(-24);
439
419
  }
440
- const systemPrompt = buildSystemPrompt();
420
+ const systemPrompt = getPipelineFastBrainPrompt();
441
421
  const turnContext = buildTurnContext(opts?.chatHistory, opts?.researchContext);
442
422
  const sessionBaseDir = opts?.sessionBaseDir || workingDir;
443
423
  const tools = buildTools(!!opts?.agentControl);
@@ -450,6 +430,7 @@ export async function askPipelineFastBrain(workingDir, sessionId, question, opts
450
430
  ...persistentMessages,
451
431
  { role: 'user', content: turnContext ? `${turnContext}${question}` : question },
452
432
  ];
433
+ const turnStart = messages.length; // this turn's replies only: never an earlier answer
453
434
  try {
454
435
  let rounds = 0;
455
436
  // Overall wall-clock cap. The per-request fetch timeout doesn't bound the whole
@@ -480,22 +461,7 @@ export async function askPipelineFastBrain(workingDir, sessionId, question, opts
480
461
  messages.push(msg);
481
462
  const calls = msg.tool_calls;
482
463
  if (!calls || calls.length === 0) {
483
- // Final text response. Strip any internal recall provenance the model
484
- // may have echoed (citation headers / line numbers / bare timestamps) —
485
- // those leak as ugly "[main L550 · tool_result · both] 2026-…" lines in
486
- // the chat bubble. Defense-in-depth alongside the system-prompt rule.
487
- const text = sanitizeFastBrainAnswer((msg.content || '').trim());
488
- // Update persistent history with this exchange
489
- persistentMessages.push({ role: 'user', content: question });
490
- if (text)
491
- persistentMessages.push({ role: 'assistant', content: text });
492
- console.log(`🧠⚡ [pipeline-fb] ${toolsUsed.length} searches, answer: "${text.substring(0, 80)}"`);
493
- if (!text)
494
- return { script: "I didn't find that in the session history.", type: 'answer', toolsUsed };
495
- if (text.includes('[RESEARCH_NEEDED]')) {
496
- return { script: text.replace('[RESEARCH_NEEDED]', '').trim() || 'This needs deeper research.', type: 'research_needed', toolsUsed };
497
- }
498
- return { script: text, type: 'answer', toolsUsed };
464
+ return finish(question, msg.content, toolsUsed);
499
465
  }
500
466
  // Execute tool calls
501
467
  for (const call of calls) {
@@ -515,13 +481,9 @@ export async function askPipelineFastBrain(workingDir, sessionId, question, opts
515
481
  });
516
482
  }
517
483
  }
518
- // Max rounds hit — extract whatever text we have
519
- const lastAssistant = [...messages].reverse().find(m => m.role === 'assistant' && m.content);
520
- const fallback = lastAssistant?.content?.trim() || "I didn't find that in the session history.";
521
- persistentMessages.push({ role: 'user', content: question });
522
- if (fallback)
523
- persistentMessages.push({ role: 'assistant', content: fallback });
524
- return { script: fallback, type: 'answer', toolsUsed };
484
+ // Max rounds or deadline hit — whatever text we have, classified the same way.
485
+ const lastAssistant = messages.slice(turnStart).reverse().find(m => m.role === 'assistant' && m.content);
486
+ return finish(question, lastAssistant?.content, toolsUsed);
525
487
  }
526
488
  catch (err) {
527
489
  if (err?.name === 'TimeoutError' || err?.message?.includes('timeout')) {
@@ -0,0 +1,43 @@
1
+ You are a fast memory recall agent for a voice AI assistant called Osborn.
2
+ You search the user's conversation history — their questions, the assistant's answers,
3
+ tool calls, research findings, and decisions — stored as indexed session files.
4
+ Tools: search_session (keyword search) and get_recent (latest activity).
5
+
6
+ == OBJECTIVE ==
7
+ Answer from session history. Search first for any recall question.
8
+ Greetings/thanks/confirmations: respond directly, no search.
9
+ Tasks needing live code analysis or new research: respond with [RESEARCH_NEEDED]
10
+ Never say Osborn cannot do something: the main agent has a real browser (screenshots and video
11
+ recordings), a shell, files and the web. Any request to open a site, take a screenshot, record,
12
+ run, edit or build is a task for it: respond with [RESEARCH_NEEDED], nothing else. Questions about
13
+ what was run, built or edited earlier are recall: search and answer them.
14
+
15
+ == STYLE ==
16
+ 1-3 sentences. Grounded in results. Never fabricate.
17
+ Answer in plain prose ONLY. NEVER include result header lines (the
18
+ "[source L… · msgType · matchedBy] timestamp" brackets), line numbers, or raw
19
+ timestamps in your reply — those are internal provenance the user must never see.
20
+ If not found after thorough searching: "I didn't find that in the session history."
21
+
22
+ == AUDIENCE ==
23
+ A user having a conversation via voice. Questions may be casual, rambling,
24
+ or use vague references ("that thing", "the error"). Interpret intent, not just words.
25
+
26
+ == RESULTS FORMAT ==
27
+ Each hit is a header line then its FULL untruncated text:
28
+ [<source> L<lineNum> · <msgType>[:<tool>] · <matchedBy>] <timestamp>
29
+ <full text of that message/tool result>
30
+ source: "main" = conversation, "agent-XXXX" = sub-agent research.
31
+ matchedBy: keyword | vector | both (how recall found it — vector/hybrid is preferred).
32
+
33
+ == HOW TO SEARCH ==
34
+ Think about what words people ACTUALLY USED when this topic came up.
35
+ PHRASES: 1-4 words each, multiple phrases per call.
36
+ Short precise terms beat long phrases. "error" finds more than "error we got".
37
+ RETRIES (4 rounds — use them before giving up):
38
+ 1: Specific terms from the question.
39
+ 2: Think about how the conversation would READ when this was discussed.
40
+ 3: Related terms — names, tools, files that would appear near the topic.
41
+ 4: Broad single words — cast a wide net.
42
+ Only say "didn't find" after 3+ failed rounds.
43
+ ⚠ Your own prior answers may have errors. Trust search results over your memory.
@@ -29,8 +29,9 @@ extend, or a one-line net-new reason. Do not edit files in plan mode.
29
29
  Git history, GitHub issues and PR descriptions are the project's memory and decision log; there is no separate
30
30
  ledger. Compute these for the touched files (in plan mode: the files the plan will touch); never assume which
31
31
  files are hotspots, they move over time. HISTORY says which checks ran and which could not.
32
- - Churn: `git log --no-merges --since=60.days --oneline -- <file>`. Count fixes by linked issues, reverts and
33
- re-touched lines, not by the word "fix" (commit prefixes differ by project and era).
32
+ - Churn: `git log --no-merges --since=60.days --oneline -- <file>`. Count fixes by linked issues, reverts
33
+ (`git log --grep='^Revert' -- <file>`) and re-touched lines, not by the word "fix" (commit prefixes differ by
34
+ project and era).
34
35
  - Re-touched lines: for each hunk of `git diff HEAD -M` with old side -a,b run `git log --since=60.days -L a,a+b-1:<file>`
35
36
  (b omitted means 1). For a pure insertion (b=0) use the enclosing function: `git log -L :<function>:<file>`.
36
37
  For a moved or renamed file, run this on the source path. Also `git log -S <changed symbol>` for fixes made
@@ -38,6 +39,9 @@ files are hotspots, they move over time. HISTORY says which checks ran and which
38
39
  - Coupling: `git log --no-merges --since=90.days --full-diff --name-only --format= -- <file> | sort | uniq -c | sort -rn`,
39
40
  ignoring the file itself and lock/version files. A partner in most of those commits but missing from the diff
40
41
  is a likely regression, especially across a client/server boundary; also `-S` the message or route names it shares.
42
+ - Fix chains: for the commits `-L` found, and the newest 5 per symbol from `-S`, run `git show --stat <sha>` and
43
+ read the message. A file such a fix changed together with this code and that is missing from the diff, or a
44
+ fix this diff undoes, is a likely regression.
41
45
  - Prior decisions: `git log -S <symbol>` / `--grep <topic>`; `gh issue list --state all --limit 30 --search "<topic>"`
42
46
  and `gh pr list --state all --limit 30 --search "<topic>"`, where topic = touched paths, changed symbols and
43
47
  linked issue numbers. If gh is missing or unauthenticated, HISTORY says so. Earlier PRs' "Why" sections are
@@ -49,9 +53,14 @@ files are hotspots, they move over time. HISTORY says which checks ran and which
49
53
  route, config or caller) or existing working code. The budget in step 8 applies per existing file; new files are
50
54
  judged by "does it exist?".
51
55
  1. Inventory and reuse: list EVERY definition the diff adds (each export, top-level const, type, interface,
52
- function, regex, route, data-channel message, component, prop, style string, SQL constraint), one INVENTORY row
53
- each. For each, search by name stem AND by its distinctive value or body (`git grep -n -F '<literal>'`, the
54
- regex source, the list items, the limit number), repo-wide and inside the diff itself. If anything already
56
+ function, regex, route, data-channel message, component, prop, style string, SQL constraint, environment
57
+ variable, config key, setting, flag, header, storage path, table, column, index, enum value, migration), one
58
+ INVENTORY row each. For each, search by name stem AND by its distinctive value or body (`git grep -n -F '<literal>'`, the
59
+ regex source, the list items, the limit number), repo-wide and inside the diff itself. For a variable, setting or
60
+ column, also search by meaning (same unit, default or purpose) in env reads, config loaders, schema files and
61
+ migrations: a second name for a meaning that already has one is a copy. A new migration must follow the
62
+ project's numbering and not repeat or contradict an earlier one; a new variable is declared where the project
63
+ declares its variables (example env files, setup docs, deployment manifests). If anything already
55
64
  does the same or nearly the same, EDIT the diff to reuse or extend it. Do not sample: on a large diff go file
56
65
  by file and say which files you covered. A missing row means the review is incomplete, and an incomplete
57
66
  review cannot be CLEAN.
@@ -101,6 +110,10 @@ files are hotspots, they move over time. HISTORY says which checks ran and which
101
110
  8. Budget: per existing file, aim for lines added ≤ lines removed (test files excluded); growth needs a NET-NEW
102
111
  reason in the return (no reason: REFACTORED to cut it, or BLOCK). Do not cut untouched code to meet it.
103
112
  9. New dependencies: a new package needs a reason and a check that no existing dependency already does it.
113
+ 10. Attack your own verdict: for each claim you are about to make (no duplicate, every caller still works,
114
+ behaviour kept, nothing coupled is missing, old data is safe), run at least one command that could prove it
115
+ wrong (grep, tsc, a test, git). A check that could not run is reported with its reason, as in TESTS and
116
+ HISTORY; only a claim you made no attempt to break blocks CLEAN.
104
117
 
105
118
  ## Tests before sign-off
106
119
  Run every test suite the repo has for the touched packages (in this repo: each `agent/tests/*.test.ts` and
@@ -126,6 +139,7 @@ REMOVED: <what you cut and why> (or none)
126
139
  IMPACT: <changed symbol> → <every usage found> → <updated / ok / broken + why>; SIBLINGS: <other copies of the logic> → <updated / out of scope>
127
140
  TESTS: <suite> → pass/fail/could not run (why), for every suite
128
141
  LINES: +<added> -<removed> before → after, excluding test files (*.test.*, *.spec.*, tests/), then tests separately
129
- HISTORY: churn, re-touched lines (hunks checked / found), missing coupled files, related issues/PRs, and any check that could not run
142
+ HISTORY: churn, re-touched lines (hunks checked / found), fix chains followed, missing coupled files, related issues/PRs, and any check that could not run
143
+ CHALLENGED: <claim> → <command run to break it> → held / broke (fixed) / could not run (why)
130
144
  ROOT CAUSE: for a fix, the cause, its evidence and the chain it ends; for a feature, "new feature, no earlier fault"
131
145
  For BLOCK, name the decision a human has to make.
File without changes