osborn 0.9.281 → 0.9.283
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/agent-store.d.ts +5 -3
- package/dist/agent-store.js +11 -9
- package/dist/bridge-llm.d.ts +22 -0
- package/dist/bridge-llm.js +39 -0
- package/dist/claude-llm.js +10 -11
- package/dist/codex-handler.d.ts +38 -0
- package/dist/codex-handler.js +83 -0
- package/dist/codex-llm.d.ts +40 -0
- package/dist/codex-llm.js +144 -0
- package/dist/data-sender-auth.d.ts +1 -1
- package/dist/data-sender-auth.js +5 -1
- package/dist/fast-brain.d.ts +176 -0
- package/dist/fast-brain.js +1887 -0
- package/dist/index-3-2-26-legacy.d.ts +1 -0
- package/dist/index-3-2-26-legacy.js +2233 -0
- package/dist/index.js +175 -78
- package/dist/leagcyprompts2.d.ts +0 -0
- package/dist/leagcyprompts2.js +573 -0
- package/dist/pipeline-fastbrain.js +6 -47
- package/dist/prompts/pipeline-fast-brain.md +43 -0
- package/dist/prompts/steward.md +20 -6
- package/dist/prompts-2-25-26.d.ts +0 -0
- package/dist/prompts-2-25-26.js +518 -0
- package/dist/prompts-3-2-26.d.ts +78 -0
- package/dist/prompts-3-2-26.js +1319 -0
- package/dist/prompts.d.ts +2 -0
- package/dist/prompts.js +4 -0
- package/dist/pushover.d.ts +5 -0
- package/dist/pushover.js +41 -40
- package/dist/steward-verdict.js +1 -1
- package/dist/store-catalog.d.ts +5 -0
- package/dist/store-catalog.js +29 -9
- package/dist/store-name.js +5 -1
- package/dist/summary-index.d.ts +90 -0
- package/dist/summary-index.js +585 -0
- package/package.json +1 -1
- package/scripts/review.ts +6 -66
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ import { cleanupHousekeeping } from './housekeeping.js';
|
|
|
40
40
|
import { createSTT, createTTS } from './voice-io.js';
|
|
41
41
|
import { createClaudeLLM, NAMED_AGENTS, applyTurbo, requestAuthRestart } from './claude-llm.js';
|
|
42
42
|
import { SOURCES, loadCatalog, findEntry, installSkill, agentDraft, recommend, skillProvenance, installedIds } from './store-catalog.js';
|
|
43
|
-
import { parseUserAgents, mergeAgents, describeAgents, describeRoles, coreRole, storeWriteRefusal, storeWriteOriginAllowed, coreSkillNames, skillForkedFrom, forkSkill, removeUserSkill, addUserSkill, readUserSkill, parseFrontMatter, storeName } from './agent-store.js';
|
|
43
|
+
import { parseUserAgents, mergeAgents, describeAgents, describeRoles, coreRole, AGENT_LIMITS, storeWriteRefusal, storeWriteOriginAllowed, coreSkillNames, skillForkedFrom, forkSkill, removeUserSkill, addUserSkill, readUserSkill, parseFrontMatter, storeName } from './agent-store.js';
|
|
44
44
|
import { clearPipelineFastBrainSession, prewarmBM25Index } from './pipeline-fastbrain.js';
|
|
45
45
|
import { ensureClaudeAuth, applyAuthFallback, replayInFlightAuth, startClaudeAuthOnDemand, isOnDemandAuthInFlight, probeActiveProviderKey } from './claude-auth.js';
|
|
46
46
|
import { statusManager } from './status-manager.js';
|
|
@@ -58,7 +58,7 @@ import { getRecallClient } from './recall-client.js';
|
|
|
58
58
|
import { synthMeetingAudio, selectMeetingTtsProviders } from './meeting-tts.js';
|
|
59
59
|
import { MeetingTranscriptPoller } from './meeting-transcript-poller.js';
|
|
60
60
|
import { missingRequiredEnv } from './env-keys.js';
|
|
61
|
-
import { armPermissionPush, handleWatchAck, setWatchResultHandler, osbornFrontendUrl } from './pushover.js';
|
|
61
|
+
import { armPermissionPush, handleWatchAck, setWatchResultHandler, osbornFrontendUrl, notifyPhone, isWatchBridgeEnabled, phonePushPending } from './pushover.js';
|
|
62
62
|
import { startWatchGateway } from './watch-gateway.js';
|
|
63
63
|
import { noiseGate } from './noise-gate.js';
|
|
64
64
|
import { installDuck, DUCK_LEVEL } from './duck.js';
|
|
@@ -131,8 +131,10 @@ const STORE_REPLY_TYPES = {
|
|
|
131
131
|
skill_get: 'skill_content', skill_add: 'skill_add_result', skill_fork: 'skill_fork_result',
|
|
132
132
|
skill_remove: 'skill_remove_result', get_agent_prompt: 'agent_prompt',
|
|
133
133
|
};
|
|
134
|
-
//
|
|
134
|
+
// Store routes, guarded by storeRefused: writes change the machine's skills; reads carry the
|
|
135
|
+
// core prompts, the user's skills and the catalog. Neither answers every site's CORS.
|
|
135
136
|
const STORE_WRITE_PATHS = new Set(['/skills/fork', '/skills/remove', '/store/install']);
|
|
137
|
+
const STORE_PATHS = new Set([...STORE_WRITE_PATHS, '/skills', '/skills/content', '/store/catalog', '/store/entry', '/agents']);
|
|
136
138
|
// Skills shipped with the package (core: maintained by Voice Native).
|
|
137
139
|
const PKG_SKILLS_DIR = join(__dirname, '..', '.claude', 'skills');
|
|
138
140
|
const homeSkillsDir = () => join(homedir(), '.claude', 'skills');
|
|
@@ -605,9 +607,8 @@ function startApiServer(workingDir, port) {
|
|
|
605
607
|
// Authorization is required for /secrets (Bearer OSBORN_SYNC_TOKEN); without it in the
|
|
606
608
|
// allow-list the browser preflight fails and the dashboard can't read/manage keys.
|
|
607
609
|
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
608
|
-
// Store
|
|
609
|
-
|
|
610
|
-
if (STORE_WRITE_PATHS.has((req.url || '/').split('?')[0])) {
|
|
610
|
+
// Store routes (STORE_PATHS) echo only an allowed origin, never '*'.
|
|
611
|
+
if (STORE_PATHS.has((req.url || '/').split('?')[0])) {
|
|
611
612
|
const origin = req.headers.origin;
|
|
612
613
|
if (origin && storeWriteOriginAllowed(origin, osbornFrontendUrl())) {
|
|
613
614
|
res.setHeader('Access-Control-Allow-Origin', origin);
|
|
@@ -745,24 +746,13 @@ function startApiServer(workingDir, port) {
|
|
|
745
746
|
res.end(JSON.stringify(out));
|
|
746
747
|
return;
|
|
747
748
|
}
|
|
748
|
-
if (req.method === 'GET' && url.pathname === '/skills') {
|
|
749
|
-
// Installed skills — same list the chat's get_skills data-channel message
|
|
750
|
-
// returns, exposed over HTTP so the DASHBOARD (no LiveKit connection) can
|
|
751
|
-
// render the skills manager too. Reads ~/.claude/skills (homedir) — the SINGLE
|
|
752
|
-
// location the agent ingests from (loadAllSkills) and PostCompact writes to.
|
|
753
|
-
// Previously used process.cwd()/.claude/skills, which the agent never read —
|
|
754
|
-
// so UI-created skills were invisible to the agent (the "divergence").
|
|
755
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
756
|
-
res.end(JSON.stringify({ skills: loadSkillsList(homedir()) }));
|
|
757
|
-
return;
|
|
758
|
-
}
|
|
759
749
|
// Agent & skill store routes: the chat and Settings both use them (through the
|
|
760
750
|
// authenticated /api/agent proxy in the cloud). JSON in and out.
|
|
761
751
|
const reply = (status, body) => { res.writeHead(status, { 'Content-Type': 'application/json' }); res.end(JSON.stringify(body)); };
|
|
762
|
-
//
|
|
763
|
-
//
|
|
764
|
-
const
|
|
765
|
-
const refusal = storeWriteRefusal({
|
|
752
|
+
// Called past the token gate (unauthorized()); the rules for a machine with no sync token
|
|
753
|
+
// are agent-store.ts storeWriteRefusal (reads skip only the JSON check).
|
|
754
|
+
const storeRefused = (read = false) => {
|
|
755
|
+
const refusal = storeWriteRefusal({ read,
|
|
766
756
|
hasToken: !!syncToken,
|
|
767
757
|
publicDeploy: !!process.env.FLY_APP_NAME || !!process.env.OSBORN_PUBLIC_HOST,
|
|
768
758
|
forwarded: !!(req.headers['x-forwarded-for'] || req.headers['x-forwarded-host']),
|
|
@@ -773,17 +763,32 @@ function startApiServer(workingDir, port) {
|
|
|
773
763
|
reply(refusal.status, { error: refusal.error });
|
|
774
764
|
return !!refusal;
|
|
775
765
|
};
|
|
766
|
+
if (req.method === 'GET' && url.pathname === '/skills') {
|
|
767
|
+
if (unauthorized() || storeRefused(true))
|
|
768
|
+
return;
|
|
769
|
+
// Installed skills — same list the chat's get_skills data-channel message
|
|
770
|
+
// returns, exposed over HTTP so the DASHBOARD (no LiveKit connection) can
|
|
771
|
+
// render the skills manager too. Reads ~/.claude/skills (homedir) — the SINGLE
|
|
772
|
+
// location the agent ingests from (loadAllSkills) and PostCompact writes to.
|
|
773
|
+
// Previously used process.cwd()/.claude/skills, which the agent never read —
|
|
774
|
+
// so UI-created skills were invisible to the agent (the "divergence").
|
|
775
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
776
|
+
res.end(JSON.stringify({ skills: loadSkillsList(homedir()) }));
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
776
779
|
if (url.pathname === '/skills/content' || (url.pathname.startsWith('/skills/') && STORE_WRITE_PATHS.has(url.pathname))) {
|
|
777
780
|
if (unauthorized())
|
|
778
781
|
return;
|
|
779
782
|
const name = url.searchParams.get('name');
|
|
780
783
|
if (req.method === 'GET' && url.pathname === '/skills/content') {
|
|
784
|
+
if (storeRefused(true))
|
|
785
|
+
return;
|
|
781
786
|
const out = readUserSkill(homeSkillsDir(), name);
|
|
782
787
|
return reply('error' in out ? 404 : 200, out);
|
|
783
788
|
}
|
|
784
789
|
if (req.method !== 'POST' || url.pathname === '/skills/content')
|
|
785
790
|
return reply(405, { error: 'method not allowed' });
|
|
786
|
-
if (
|
|
791
|
+
if (storeRefused())
|
|
787
792
|
return;
|
|
788
793
|
const out = changeSkill(url.pathname === '/skills/fork' ? 'fork' : 'remove', name, url.searchParams.get('to'));
|
|
789
794
|
return reply('ok' in out ? 200 : 400, { ...out, skills: loadSkillsList(homedir()) });
|
|
@@ -795,6 +800,8 @@ function startApiServer(workingDir, port) {
|
|
|
795
800
|
if (unauthorized())
|
|
796
801
|
return;
|
|
797
802
|
try {
|
|
803
|
+
if (req.method === 'GET' && storeRefused(true))
|
|
804
|
+
return;
|
|
798
805
|
if (req.method === 'GET' && url.pathname === '/store/catalog') {
|
|
799
806
|
const src = url.searchParams.get('source');
|
|
800
807
|
const caches = await loadCatalog(src && src !== 'all' ? src.split(',') : null, { refresh: url.searchParams.get('refresh') === '1' });
|
|
@@ -810,7 +817,7 @@ function startApiServer(workingDir, port) {
|
|
|
810
817
|
return reply(200, {
|
|
811
818
|
sources: caches.map((c) => {
|
|
812
819
|
const s = SOURCES.find((x) => x.id === c.source);
|
|
813
|
-
return { id: c.source, label: s.label, repo: c.repo, trust: s.trust, sha: c.sha, fetchedAt: c.fetchedAt, count: c.entries.length, ...(c.error ? { error: c.error } : {}) };
|
|
820
|
+
return { id: c.source, label: s.label, repo: c.repo, trust: s.trust, sha: c.sha, fetchedAt: c.fetchedAt, count: c.entries.length, ...(c.error ? { error: c.error } : {}), ...(c.note ? { note: c.note } : {}) };
|
|
814
821
|
}),
|
|
815
822
|
entries,
|
|
816
823
|
installed: [...installed],
|
|
@@ -825,11 +832,18 @@ function startApiServer(workingDir, port) {
|
|
|
825
832
|
return reply(200, { entry: found.entry, content: found.body, ...(found.entry.kind === 'agent' ? { draft: agentDraft(found.entry, found.body) } : {}) });
|
|
826
833
|
}
|
|
827
834
|
if (req.method === 'POST' && url.pathname === '/store/install') {
|
|
828
|
-
if (
|
|
835
|
+
if (storeRefused())
|
|
829
836
|
return;
|
|
830
837
|
const found = await findEntry(url.searchParams.get('id') || '');
|
|
831
838
|
if (!found)
|
|
832
839
|
return reply(404, { error: 'not in the catalog' });
|
|
840
|
+
// Install what was reviewed: the card carries the entry's rev (its text and file list).
|
|
841
|
+
const reviewed = url.searchParams.get('rev');
|
|
842
|
+
if (reviewed && reviewed !== found.entry.rev)
|
|
843
|
+
return reply(409, { error: 'This entry changed upstream since you viewed it. Refresh and review it again.' });
|
|
844
|
+
// An agent whose prompt is over the limit is refused, never cut: what was reviewed is what installs.
|
|
845
|
+
if (found.entry.kind === 'agent' && found.body.length > AGENT_LIMITS.prompt)
|
|
846
|
+
return reply(400, { error: `this agent's prompt is ${found.body.length} characters; the limit is ${AGENT_LIMITS.prompt}` });
|
|
833
847
|
if (found.entry.kind === 'agent')
|
|
834
848
|
return reply(200, { draft: agentDraft(found.entry, found.body) });
|
|
835
849
|
const out = await installSkill(found.entry, homeSkillsDir(), coreSkillNames(PKG_SKILLS_DIR));
|
|
@@ -845,7 +859,7 @@ function startApiServer(workingDir, port) {
|
|
|
845
859
|
// Core sub-agents from claude-llm.ts NAMED_AGENTS (the same object the SDK
|
|
846
860
|
// query uses), with prompts so the store can show and fork them — so gated
|
|
847
861
|
// like the other store routes (the chat and Settings go through /api/agent).
|
|
848
|
-
if (unauthorized())
|
|
862
|
+
if (unauthorized() || storeRefused(true))
|
|
849
863
|
return;
|
|
850
864
|
return reply(200, { agents: describeAgents(NAMED_AGENTS, null, {}, true), ...describeRoles() });
|
|
851
865
|
}
|
|
@@ -2375,7 +2389,10 @@ async function main() {
|
|
|
2375
2389
|
// P1: room stays alive while the host anchor is active or any background slot
|
|
2376
2390
|
// is running. Teardown timers below early-return on this so a dashboard-started
|
|
2377
2391
|
// session + its background dispatches aren't killed by the empty-room grace.
|
|
2378
|
-
|
|
2392
|
+
// Work the user left running when they hung up (keep-working, below) holds the
|
|
2393
|
+
// machine the same way, until it finishes or hits its cap.
|
|
2394
|
+
let keepWorkingActive = false;
|
|
2395
|
+
const agentsActive = () => hostActive || slots.size > 0 || keepWorkingActive;
|
|
2379
2396
|
// Release the host anchor + hard-kill background slots at a genuine session-end
|
|
2380
2397
|
// boundary so the room can idle-exit (agentsActive → false). Idempotent. MUST be
|
|
2381
2398
|
// called before arming idle-exit on EVERY path where the session ends, or the
|
|
@@ -2498,7 +2515,8 @@ async function main() {
|
|
|
2498
2515
|
// fast-leave) — the parked brain does NOT hold the room (it's no longer
|
|
2499
2516
|
// `currentLLM` nor in `slots`, so agentsActive() is false);
|
|
2500
2517
|
// 2. a grace timer frees the parked brain if no reconnect arrives;
|
|
2501
|
-
// 3. an INDEPENDENT watchdog hard-kills it at a ceiling even if (2) is buggy
|
|
2518
|
+
// 3. an INDEPENDENT watchdog hard-kills it at a ceiling even if (2) is buggy
|
|
2519
|
+
// (while keep-working runs, its cap timer replaces (2) and (3).)
|
|
2502
2520
|
// One-owner invariant: the subprocess is owned by exactly one of
|
|
2503
2521
|
// {currentLLM, warmLLM}, or it's aborted — never two live, never orphaned.
|
|
2504
2522
|
// DEFAULT-ON (user, 2026-10-21): the three backstops above — not the flag —
|
|
@@ -2560,11 +2578,33 @@ async function main() {
|
|
|
2560
2578
|
'session_id', 'mcp_servers_changed', 'tool_use', 'tool_result',
|
|
2561
2579
|
'assistant_text', 'assistant_result', 'tts_chunks', 'permission_request',
|
|
2562
2580
|
'tts_say', 'session_resume_failed', 'checkpoint_captured',
|
|
2563
|
-
'dispatch_rejected', 'task_completed', 'agent_started', 'steward_verdict', 'steward_gate',
|
|
2581
|
+
'dispatch_rejected', 'task_completed', 'agent_started', 'steward_verdict', 'steward_gate', 'tool_blocked',
|
|
2564
2582
|
];
|
|
2565
|
-
//
|
|
2566
|
-
//
|
|
2567
|
-
|
|
2583
|
+
// ── KEEP WORKING AFTER HANG-UP ──
|
|
2584
|
+
// When the user ends the call while the agent is mid-task and chooses "Keep
|
|
2585
|
+
// working" (data message keep_working), the keep-warm park below drops its
|
|
2586
|
+
// short grace: the brain runs until its turn and tasks finish (then a phone
|
|
2587
|
+
// notice, and the normal re-attach grace), or until the machine's own idle
|
|
2588
|
+
// timeout (IDLE_EXIT_GRACE_MS, 15 min) has passed since the hang-up, when it
|
|
2589
|
+
// is stopped. keepWorkingActive holds the machine (idle-exit, recycle); the
|
|
2590
|
+
// room still tears down. A reconnect re-attaches through claimWarm.
|
|
2591
|
+
let keepWorkingRequested = false;
|
|
2592
|
+
let keepWorkingPoll = null;
|
|
2593
|
+
let keepWorkingCap = null;
|
|
2594
|
+
const stopKeepWorking = () => {
|
|
2595
|
+
if (keepWorkingPoll) {
|
|
2596
|
+
clearInterval(keepWorkingPoll);
|
|
2597
|
+
keepWorkingPoll = null;
|
|
2598
|
+
}
|
|
2599
|
+
if (keepWorkingCap) {
|
|
2600
|
+
clearTimeout(keepWorkingCap);
|
|
2601
|
+
keepWorkingCap = null;
|
|
2602
|
+
}
|
|
2603
|
+
keepWorkingActive = false;
|
|
2604
|
+
};
|
|
2605
|
+
// Every timer that can end or free the parked brain.
|
|
2606
|
+
const clearWarmTimers = () => {
|
|
2607
|
+
stopKeepWorking();
|
|
2568
2608
|
if (warmGraceTimer) {
|
|
2569
2609
|
clearTimeout(warmGraceTimer);
|
|
2570
2610
|
warmGraceTimer = null;
|
|
@@ -2573,6 +2613,49 @@ async function main() {
|
|
|
2573
2613
|
clearTimeout(warmWatchdog);
|
|
2574
2614
|
warmWatchdog = null;
|
|
2575
2615
|
}
|
|
2616
|
+
};
|
|
2617
|
+
// Called right after parkWarm, once the room teardown is armed.
|
|
2618
|
+
const keepWorkingAfterLeave = () => {
|
|
2619
|
+
if (!warmLLM)
|
|
2620
|
+
return;
|
|
2621
|
+
clearWarmTimers();
|
|
2622
|
+
const started = Date.now();
|
|
2623
|
+
warmExpiry = started + IDLE_EXIT_GRACE_MS; // a reconnect while it works re-attaches
|
|
2624
|
+
keepWorkingActive = true;
|
|
2625
|
+
console.log(`🏃 [KEEP-WORKING] user hung up mid-task — working on for up to ${IDLE_EXIT_GRACE_MS / 60000} min`);
|
|
2626
|
+
keepWorkingPoll = setInterval(() => {
|
|
2627
|
+
const busy = warmLLM?.busyState?.();
|
|
2628
|
+
if (busy?.permissionPending) {
|
|
2629
|
+
// Blocked on an approval. If a phone push is out, its answer reaches the
|
|
2630
|
+
// parked brain, so keep waiting (the cap still applies); otherwise nobody
|
|
2631
|
+
// can answer, so fall back to the grace.
|
|
2632
|
+
if (phonePushPending())
|
|
2633
|
+
return;
|
|
2634
|
+
stopKeepWorking();
|
|
2635
|
+
console.log('✋ [KEEP-WORKING] waiting on an approval no phone can answer — normal re-attach grace from here');
|
|
2636
|
+
warmExpiry = Date.now() + REATTACH_GRACE_MS;
|
|
2637
|
+
armWarmTimers();
|
|
2638
|
+
return;
|
|
2639
|
+
}
|
|
2640
|
+
if (!(busy?.idle ?? true))
|
|
2641
|
+
return;
|
|
2642
|
+
stopKeepWorking();
|
|
2643
|
+
const mins = Math.max(1, Math.round((Date.now() - started) / 60000));
|
|
2644
|
+
console.log(`🏁 [KEEP-WORKING] finished after ~${mins} min — normal re-attach grace from here`);
|
|
2645
|
+
void notifyPhone(`Osborn finished the work you left running (${mins} min). Open Voice Native to see the result.`);
|
|
2646
|
+
warmExpiry = Date.now() + REATTACH_GRACE_MS;
|
|
2647
|
+
armWarmTimers();
|
|
2648
|
+
}, 15_000);
|
|
2649
|
+
keepWorkingCap = setTimeout(() => {
|
|
2650
|
+
console.log(`⏱️ [KEEP-WORKING] cap reached (${IDLE_EXIT_GRACE_MS / 60000} min) — stopping`);
|
|
2651
|
+
freeWarm('keep_working_cap');
|
|
2652
|
+
void notifyPhone(`Osborn stopped the work you left running after ${IDLE_EXIT_GRACE_MS / 60000} minutes. Reconnect to continue it.`);
|
|
2653
|
+
}, IDLE_EXIT_GRACE_MS);
|
|
2654
|
+
};
|
|
2655
|
+
// Abort + clear the parked brain. Clears BOTH timers so grace/watchdog can't
|
|
2656
|
+
// double-fire. Used on grace expiry, watchdog, and session mismatch.
|
|
2657
|
+
const killWarm = (reason) => {
|
|
2658
|
+
clearWarmTimers();
|
|
2576
2659
|
if (warmLLM) {
|
|
2577
2660
|
try {
|
|
2578
2661
|
const llm = warmLLM;
|
|
@@ -2595,8 +2678,16 @@ async function main() {
|
|
|
2595
2678
|
warmExpiry = 0;
|
|
2596
2679
|
};
|
|
2597
2680
|
// Grace timer (free memory if no reconnect) + INDEPENDENT watchdog ceiling.
|
|
2598
|
-
// Both end in the SAME teardown: kill warm →
|
|
2599
|
-
// the
|
|
2681
|
+
// Both end in the SAME teardown (freeWarm, also keep-working's cap): kill warm →
|
|
2682
|
+
// releaseAgents → fast-leave (a room the kept slots held) → arm idle-exit, so the
|
|
2683
|
+
// machine always self-stops within WARM_HARD_CEILING_MS + idle-grace (keep-working:
|
|
2684
|
+
// its cap + the re-attach grace + idle-grace).
|
|
2685
|
+
const freeWarm = (reason) => {
|
|
2686
|
+
killWarm(reason);
|
|
2687
|
+
releaseAgents();
|
|
2688
|
+
armFastLeaveTimer();
|
|
2689
|
+
armIdleExitTimer(`warm-${reason}`);
|
|
2690
|
+
};
|
|
2600
2691
|
const armWarmTimers = () => {
|
|
2601
2692
|
if (warmGraceTimer)
|
|
2602
2693
|
clearTimeout(warmGraceTimer);
|
|
@@ -2606,17 +2697,13 @@ async function main() {
|
|
|
2606
2697
|
warmGraceTimer = null;
|
|
2607
2698
|
warmStats.wastedTimeouts++;
|
|
2608
2699
|
console.log('🧊 [KEEP-WARM] grace expired with no reconnect — freeing warm slot');
|
|
2609
|
-
|
|
2610
|
-
releaseAgents();
|
|
2611
|
-
armIdleExitTimer('warm-grace-expired');
|
|
2700
|
+
freeWarm('grace_expired');
|
|
2612
2701
|
}, REATTACH_GRACE_MS);
|
|
2613
2702
|
warmWatchdog = setTimeout(() => {
|
|
2614
2703
|
warmWatchdog = null;
|
|
2615
2704
|
warmStats.watchdogKills++;
|
|
2616
2705
|
console.warn('🧊 [KEEP-WARM] WATCHDOG ceiling hit — hard-freeing warm slot (backstop)');
|
|
2617
|
-
|
|
2618
|
-
releaseAgents();
|
|
2619
|
-
armIdleExitTimer('warm-watchdog');
|
|
2706
|
+
freeWarm('watchdog_ceiling');
|
|
2620
2707
|
}, WARM_HARD_CEILING_MS);
|
|
2621
2708
|
};
|
|
2622
2709
|
// Move currentLLM → warm slot WITHOUT aborting it (the park). If there's no
|
|
@@ -2650,14 +2737,7 @@ async function main() {
|
|
|
2650
2737
|
// Detach the parked brain for reuse WITHOUT aborting it, cancelling its timers.
|
|
2651
2738
|
// Caller takes ownership (becomes currentLLM via createDirectSession).
|
|
2652
2739
|
const claimWarm = () => {
|
|
2653
|
-
|
|
2654
|
-
clearTimeout(warmGraceTimer);
|
|
2655
|
-
warmGraceTimer = null;
|
|
2656
|
-
}
|
|
2657
|
-
if (warmWatchdog) {
|
|
2658
|
-
clearTimeout(warmWatchdog);
|
|
2659
|
-
warmWatchdog = null;
|
|
2660
|
-
}
|
|
2740
|
+
clearWarmTimers();
|
|
2661
2741
|
const llm = warmLLM;
|
|
2662
2742
|
warmLLM = null;
|
|
2663
2743
|
warmSessionId = null;
|
|
@@ -4128,15 +4208,13 @@ async function main() {
|
|
|
4128
4208
|
// 11. Tell the UI; it replaces the transcript with the target's history.
|
|
4129
4209
|
const summary = await getSessionSummary(target, cwd);
|
|
4130
4210
|
const conversationHistory = await getConversationHistory(target, cwd, 30);
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
conversationHistory,
|
|
4139
|
-
});
|
|
4211
|
+
const switched = { type: 'session_switched', sessionId: target, workingDirectory: cwd, success: true, forced: plan.reason === 'forced' };
|
|
4212
|
+
// The history is only the UI's fallback (it reads /session-messages first); when it pushes the
|
|
4213
|
+
// message past the size cap, send the switch without it so the rail and URL still move.
|
|
4214
|
+
const told = await sendToFrontend({ ...switched, summary, conversationHistory })
|
|
4215
|
+
|| await sendToFrontend(switched);
|
|
4216
|
+
if (!told)
|
|
4217
|
+
console.warn(`⚠️ Switch to ${target.slice(0, 8)}: the UI was not told (no room or publish failed)`);
|
|
4140
4218
|
const switchArtifacts = listWorkspaceArtifacts(cwd, target);
|
|
4141
4219
|
if (switchArtifacts.length > 0) {
|
|
4142
4220
|
await sendToFrontend({
|
|
@@ -4354,6 +4432,18 @@ async function main() {
|
|
|
4354
4432
|
console.error(`[COMPACT-AGENT-ERROR] ${err.message}`);
|
|
4355
4433
|
}
|
|
4356
4434
|
};
|
|
4435
|
+
// Pipeline fast brain → provisional chat answer. Both pipeline sessions (connect and recovery) use it.
|
|
4436
|
+
const onPipelineFastBrainResult = (r) => {
|
|
4437
|
+
console.log(`🧠⚡ [FAST_BRAIN ${r.type.toUpperCase()} +${r.elapsedMs}ms]: "${r.answer.substring(0, 60)}"`);
|
|
4438
|
+
// A hand-off to the main agent has nothing to say yet; its answer follows.
|
|
4439
|
+
if (r.type === 'research_needed')
|
|
4440
|
+
return;
|
|
4441
|
+
sendToFrontend({
|
|
4442
|
+
type: 'fast_brain_response', text: r.answer, responseType: r.type,
|
|
4443
|
+
elapsedMs: r.elapsedMs, question: r.question, toolsUsed: r.toolsUsed,
|
|
4444
|
+
agentRole: 'pipeline-fast-brain',
|
|
4445
|
+
});
|
|
4446
|
+
};
|
|
4357
4447
|
// Create DIRECT session (STT + Claude Agent SDK + TTS)
|
|
4358
4448
|
async function createDirectSession(resumeSessionId, llmOverride) {
|
|
4359
4449
|
console.log('🎯 Creating direct session...');
|
|
@@ -4380,8 +4470,9 @@ async function main() {
|
|
|
4380
4470
|
// permission is currently pending. Re-registered per session — harmless,
|
|
4381
4471
|
// the latest closure wins and they all resolve through currentLLM.
|
|
4382
4472
|
setWatchResultHandler((allow, toolName) => {
|
|
4383
|
-
|
|
4384
|
-
|
|
4473
|
+
const target = currentLLM?.hasPendingPermission?.() ? currentLLM : warmLLM?.hasPendingPermission?.() ? warmLLM : null;
|
|
4474
|
+
if (target) {
|
|
4475
|
+
target.respondToPermission(allow);
|
|
4385
4476
|
console.log(`⌚️ Watch bridge settled ${toolName}: ${allow ? 'approve' : 'deny'}`);
|
|
4386
4477
|
}
|
|
4387
4478
|
else {
|
|
@@ -4834,6 +4925,7 @@ async function main() {
|
|
|
4834
4925
|
// Steward verdict card + sign-off gate note (#221) → chat
|
|
4835
4926
|
directLLM.events.on('steward_verdict', (v) => sendToFrontend({ type: 'steward_verdict', ...v }));
|
|
4836
4927
|
directLLM.events.on('steward_gate', (d) => sendToFrontend({ type: 'steward_gate', decision: d.decision, message: d.message }));
|
|
4928
|
+
directLLM.events.on('tool_blocked', (d) => sendToFrontend({ type: 'tool_blocked', ...d }));
|
|
4837
4929
|
// Dispatcher v1 — sub-agent started → frontend stop-key signal (Feature A2)
|
|
4838
4930
|
directLLM.events.on('agent_started', (d) => sendToFrontend({
|
|
4839
4931
|
type: 'agent_started',
|
|
@@ -5166,6 +5258,7 @@ async function main() {
|
|
|
5166
5258
|
// connect callback, not via events).
|
|
5167
5259
|
participantConnectedHandler = async (participant) => {
|
|
5168
5260
|
console.log(`\n👤 User joined: ${participant.identity}`);
|
|
5261
|
+
keepWorkingRequested = false; // a request belongs to the hang-up it preceded
|
|
5169
5262
|
// The meeting canvas joining as a listener = browser-parity audio path is
|
|
5170
5263
|
// LIVE: the agent's normal session.say plays through the canvas into the
|
|
5171
5264
|
// meeting, so tts_say suppression/redirect must stand down.
|
|
@@ -5372,6 +5465,10 @@ async function main() {
|
|
|
5372
5465
|
session = result.session;
|
|
5373
5466
|
agent = result.agent;
|
|
5374
5467
|
reattached = true;
|
|
5468
|
+
const pending = reused?.getPendingPermission?.();
|
|
5469
|
+
// Its prompt went to the old room: re-show it through the wired listener (diff included).
|
|
5470
|
+
if (pending)
|
|
5471
|
+
reused.events?.emit('permission_request', pending);
|
|
5375
5472
|
}
|
|
5376
5473
|
else if (warmLLM) {
|
|
5377
5474
|
killWarm(warmSessionId && warmSessionId !== resumeSessionId ? 'reattach_session_mismatch' : 'reattach_expired');
|
|
@@ -5407,18 +5504,7 @@ async function main() {
|
|
|
5407
5504
|
},
|
|
5408
5505
|
getAndConsumeInterruptionContext,
|
|
5409
5506
|
getAndConsumeClientNotes,
|
|
5410
|
-
onFastBrainResult:
|
|
5411
|
-
console.log(`🧠⚡ [FAST_BRAIN ${result.type.toUpperCase()} +${result.elapsedMs}ms]: "${result.answer.substring(0, 60)}"`);
|
|
5412
|
-
sendToFrontend({
|
|
5413
|
-
type: 'fast_brain_response',
|
|
5414
|
-
text: result.answer,
|
|
5415
|
-
responseType: result.type,
|
|
5416
|
-
elapsedMs: result.elapsedMs,
|
|
5417
|
-
question: result.question,
|
|
5418
|
-
toolsUsed: result.toolsUsed,
|
|
5419
|
-
agentRole: 'pipeline-fast-brain',
|
|
5420
|
-
});
|
|
5421
|
-
},
|
|
5507
|
+
onFastBrainResult: onPipelineFastBrainResult,
|
|
5422
5508
|
});
|
|
5423
5509
|
// Pass pipelineLLM to createDirectSession so it uses it instead of creating a new ClaudeLLM
|
|
5424
5510
|
const result = await createDirectSession(resumeSessionId, pipelineLLM);
|
|
@@ -5907,14 +5993,7 @@ async function main() {
|
|
|
5907
5993
|
},
|
|
5908
5994
|
getAndConsumeInterruptionContext,
|
|
5909
5995
|
getAndConsumeClientNotes,
|
|
5910
|
-
onFastBrainResult:
|
|
5911
|
-
console.log(`🧠⚡ [FAST_BRAIN ${r.type.toUpperCase()} +${r.elapsedMs}ms]: "${r.answer.substring(0, 60)}"`);
|
|
5912
|
-
sendToFrontend({
|
|
5913
|
-
type: 'fast_brain_response', text: r.answer, responseType: r.type,
|
|
5914
|
-
elapsedMs: r.elapsedMs, question: r.question, toolsUsed: r.toolsUsed,
|
|
5915
|
-
agentRole: 'pipeline-fast-brain',
|
|
5916
|
-
});
|
|
5917
|
-
},
|
|
5996
|
+
onFastBrainResult: onPipelineFastBrainResult,
|
|
5918
5997
|
});
|
|
5919
5998
|
result = await createDirectSession(recoverySessionId, pipelineLLM);
|
|
5920
5999
|
}
|
|
@@ -6026,6 +6105,7 @@ async function main() {
|
|
|
6026
6105
|
skills: loadSkillsList(homedir()),
|
|
6027
6106
|
namedAgents: describeAgents(NAMED_AGENTS, userNamedAgents, userAgentRoles, false, userAgentOrigins),
|
|
6028
6107
|
...describeRoles(),
|
|
6108
|
+
keepWorking: true,
|
|
6029
6109
|
});
|
|
6030
6110
|
};
|
|
6031
6111
|
const readyInterval = setInterval(sendReady, 2000);
|
|
@@ -6258,6 +6338,11 @@ async function main() {
|
|
|
6258
6338
|
releaseAgents();
|
|
6259
6339
|
armMeetingLeaveGrace();
|
|
6260
6340
|
armFastLeaveTimer();
|
|
6341
|
+
// "Keep working" chosen at End: after the teardown is armed (it checks agentsActive()).
|
|
6342
|
+
if (keepWorkingRequested) {
|
|
6343
|
+
keepWorkingRequested = false;
|
|
6344
|
+
keepWorkingAfterLeave();
|
|
6345
|
+
}
|
|
6261
6346
|
}
|
|
6262
6347
|
else {
|
|
6263
6348
|
// Kill the Claude SDK subprocess BEFORE dropping the reference, otherwise the
|
|
@@ -6593,6 +6678,18 @@ async function main() {
|
|
|
6593
6678
|
const hint = typeof data.workingDirectory === 'string' ? data.workingDirectory : undefined;
|
|
6594
6679
|
await requestSessionSwitch(sessionId, hint, { force: !!data.force, origin: 'switch_session' });
|
|
6595
6680
|
}
|
|
6681
|
+
else if (data.type === 'get_busy') {
|
|
6682
|
+
// End asks before hanging up: a busy agent may keep working (keep_working).
|
|
6683
|
+
// Offered only when the hang-up will park the brain (the KEEP_WARM branch of
|
|
6684
|
+
// the disconnect handler) and it is working, not just waiting on an approval.
|
|
6685
|
+
const busy = currentLLM?.busyState?.();
|
|
6686
|
+
const parks = KEEP_WARM && !activeMeetingBotId && !!currentLLM?.sessionId;
|
|
6687
|
+
await sendToFrontend({ type: 'busy_state', idle: (busy?.idle ?? true) || !!busy?.permissionPending, capMin: parks ? IDLE_EXIT_GRACE_MS / 60000 : 0, phone: isWatchBridgeEnabled() }, participant?.identity);
|
|
6688
|
+
}
|
|
6689
|
+
else if (data.type === 'keep_working') {
|
|
6690
|
+
keepWorkingRequested = true;
|
|
6691
|
+
console.log('🏃 [KEEP-WORKING] requested — the next hang-up keeps the agent working');
|
|
6692
|
+
}
|
|
6596
6693
|
else if (data.type === 'cancel_session_switch') {
|
|
6597
6694
|
if (pendingSwitch)
|
|
6598
6695
|
cancelPendingSwitch('user_cancelled');
|
|
File without changes
|