osborn 0.9.252-swap.0 → 0.9.253
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/bridge-llm.d.ts +22 -0
- package/dist/bridge-llm.js +39 -0
- package/dist/claude-llm.d.ts +23 -4
- package/dist/claude-llm.js +188 -17
- 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/content/compaction-lens-worker.d.ts +7 -2
- package/dist/content/compaction-lens-worker.js +60 -7
- package/dist/content/compaction-lens.js +13 -2
- package/dist/content/content-brief.d.ts +90 -0
- package/dist/content/content-brief.js +165 -0
- package/dist/content/content-checks.d.ts +88 -0
- package/dist/content/content-checks.js +249 -0
- package/dist/content/content-ingest.d.ts +51 -0
- package/dist/content/content-ingest.js +107 -0
- package/dist/content/content-llm.d.ts +134 -0
- package/dist/content/content-llm.js +412 -0
- package/dist/content/content-manifest.d.ts +115 -0
- package/dist/content/content-manifest.js +59 -0
- package/dist/content/content-query-gate.d.ts +22 -0
- package/dist/content/content-query-gate.js +78 -0
- package/dist/content/content-redact.d.ts +22 -0
- package/dist/content/content-redact.js +49 -0
- package/dist/content/content-research.d.ts +90 -0
- package/dist/content/content-research.js +256 -0
- package/dist/content/content-run.d.ts +85 -0
- package/dist/content/content-run.js +321 -0
- package/dist/content/content-script-rules.d.ts +74 -0
- package/dist/content/content-script-rules.js +134 -0
- package/dist/content/content-script.d.ts +61 -0
- package/dist/content/content-script.js +107 -0
- package/dist/content/lens-ingest.d.ts +7 -0
- package/dist/content/lens-ingest.js +21 -4
- package/dist/content/transcript-sanitizer.js +6 -0
- 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 +99 -201
- package/dist/leagcyprompts2.d.ts +0 -0
- package/dist/leagcyprompts2.js +573 -0
- package/dist/pipeline-direct-llm.d.ts +2 -5
- package/dist/pipeline-direct-llm.js +13 -46
- package/dist/pipeline-fastbrain.d.ts +1 -1
- package/dist/pipeline-fastbrain.js +8 -4
- 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/summary-index.d.ts +90 -0
- package/dist/summary-index.js +585 -0
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge LLM Module - Creates LLM instances for pipelined voice sessions
|
|
3
|
+
*
|
|
4
|
+
* In pipelined mode, we use a separate LLM (Gemini or GPT-4o) as the
|
|
5
|
+
* "conversation manager" that handles voice I/O and routes to Claude Code.
|
|
6
|
+
*/
|
|
7
|
+
import * as google from '@livekit/agents-plugin-google';
|
|
8
|
+
import * as openai from '@livekit/agents-plugin-openai';
|
|
9
|
+
export interface BridgeLLMConfig {
|
|
10
|
+
provider: 'gemini-pro' | 'gemini-flash' | 'gpt-4o' | 'gpt-4o-mini';
|
|
11
|
+
model?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create Bridge LLM instance for pipelined voice sessions
|
|
15
|
+
*
|
|
16
|
+
* Options:
|
|
17
|
+
* - gemini-pro: Gemini 2.5 Pro (smart, good reasoning)
|
|
18
|
+
* - gemini-flash: Gemini 2.0 Flash (faster, cheaper)
|
|
19
|
+
* - gpt-4o: GPT-4o (alternative if OpenAI preferred)
|
|
20
|
+
* - gpt-4o-mini: GPT-4o Mini (faster, cheaper)
|
|
21
|
+
*/
|
|
22
|
+
export declare function createBridgeLLM(config: BridgeLLMConfig): google.LLM | openai.LLM;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge LLM Module - Creates LLM instances for pipelined voice sessions
|
|
3
|
+
*
|
|
4
|
+
* In pipelined mode, we use a separate LLM (Gemini or GPT-4o) as the
|
|
5
|
+
* "conversation manager" that handles voice I/O and routes to Claude Code.
|
|
6
|
+
*/
|
|
7
|
+
import * as google from '@livekit/agents-plugin-google';
|
|
8
|
+
import * as openai from '@livekit/agents-plugin-openai';
|
|
9
|
+
/**
|
|
10
|
+
* Create Bridge LLM instance for pipelined voice sessions
|
|
11
|
+
*
|
|
12
|
+
* Options:
|
|
13
|
+
* - gemini-pro: Gemini 2.5 Pro (smart, good reasoning)
|
|
14
|
+
* - gemini-flash: Gemini 2.0 Flash (faster, cheaper)
|
|
15
|
+
* - gpt-4o: GPT-4o (alternative if OpenAI preferred)
|
|
16
|
+
* - gpt-4o-mini: GPT-4o Mini (faster, cheaper)
|
|
17
|
+
*/
|
|
18
|
+
export function createBridgeLLM(config) {
|
|
19
|
+
switch (config.provider) {
|
|
20
|
+
case 'gemini-pro':
|
|
21
|
+
return new google.LLM({
|
|
22
|
+
model: config.model || 'gemini-2.5-pro',
|
|
23
|
+
});
|
|
24
|
+
case 'gemini-flash':
|
|
25
|
+
return new google.LLM({
|
|
26
|
+
model: config.model || 'gemini-2.0-flash',
|
|
27
|
+
});
|
|
28
|
+
case 'gpt-4o':
|
|
29
|
+
return new openai.LLM({
|
|
30
|
+
model: config.model || 'gpt-4o',
|
|
31
|
+
});
|
|
32
|
+
case 'gpt-4o-mini':
|
|
33
|
+
return new openai.LLM({
|
|
34
|
+
model: config.model || 'gpt-4o-mini',
|
|
35
|
+
});
|
|
36
|
+
default:
|
|
37
|
+
throw new Error(`Unknown Bridge LLM provider: ${config.provider}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/claude-llm.d.ts
CHANGED
|
@@ -268,11 +268,28 @@ export declare class ClaudeLLM extends llm.LLM {
|
|
|
268
268
|
/** Remove an active query (called from ClaudeLLMStream when query completes) */
|
|
269
269
|
removeActiveQuery(q: any): void;
|
|
270
270
|
/**
|
|
271
|
-
* Stop a single dispatch flow by agent_id.
|
|
272
|
-
*
|
|
273
|
-
*
|
|
271
|
+
* Stop a single dispatch flow by agent_id — REAL stop via query.stopTask().
|
|
272
|
+
* Resolves agent_id → tool_use_id (claimed at SubagentStart) → task_id
|
|
273
|
+
* (from the SDK's task_started message); falls back to the only running
|
|
274
|
+
* task of the same subagent_type when the chain has a gap. Returns true
|
|
275
|
+
* only when a stopTask was actually issued — the old #activeQueriesById
|
|
276
|
+
* path never populated, so this used to report "stopped" while nothing
|
|
277
|
+
* stopped. Does NOT affect other tasks (use abortQuery() to kill all).
|
|
274
278
|
*/
|
|
275
|
-
stopAgent(agentId: string): boolean
|
|
279
|
+
stopAgent(agentId: string): Promise<boolean>;
|
|
280
|
+
/** PreToolUse(Task) capture: remember the dispatching tool_use_id per type (FIFO). */
|
|
281
|
+
noteTaskDispatch(toolUseId: string | undefined, subagentType: string | undefined): void;
|
|
282
|
+
/** SubagentStart claim: pair this agent_id with the oldest unclaimed dispatch of its type. */
|
|
283
|
+
claimTaskDispatch(agentId: string | undefined, subagentType: string | undefined): void;
|
|
284
|
+
/** Background consumer feed: track SDK task lifecycle messages. */
|
|
285
|
+
trackTaskMessage(msg: any): void;
|
|
286
|
+
/** Live background tasks (for truthful status/UX). */
|
|
287
|
+
getRunningTasks(): Array<{
|
|
288
|
+
taskId: string;
|
|
289
|
+
subagentType?: string;
|
|
290
|
+
description?: string;
|
|
291
|
+
status: string;
|
|
292
|
+
}>;
|
|
276
293
|
/** Whether a persistent session is alive and consuming messages */
|
|
277
294
|
hasSession(): boolean;
|
|
278
295
|
/**
|
|
@@ -300,6 +317,8 @@ export declare class ClaudeLLM extends llm.LLM {
|
|
|
300
317
|
onSessionId: (id: string) => void;
|
|
301
318
|
onCheckpoint: (checkpointId: string) => void;
|
|
302
319
|
eventEmitter: EventEmitter;
|
|
320
|
+
}, pushOpts?: {
|
|
321
|
+
priority?: 'now' | 'next' | 'later';
|
|
303
322
|
}): void;
|
|
304
323
|
chat({ chatCtx, toolCtx, connOptions, abortController, }: {
|
|
305
324
|
chatCtx: llm.ChatContext;
|
package/dist/claude-llm.js
CHANGED
|
@@ -1095,6 +1095,23 @@ export class ClaudeLLM extends llm.LLM {
|
|
|
1095
1095
|
// Per-agent-id query map — allows targeted stop of a single dispatch flow.
|
|
1096
1096
|
// Strictly additive; abortQuery/interruptQuery still iterate #activeQueries (kill-all).
|
|
1097
1097
|
#activeQueriesById = new Map();
|
|
1098
|
+
// ── Background-task registry (real per-flow stop) ──────────────────────────
|
|
1099
|
+
// With perTaskStopAffordance declared, an interrupt spares background tasks,
|
|
1100
|
+
// so a spared runaway task MUST be stoppable via query.stopTask(taskId).
|
|
1101
|
+
// Task ids arrive on system/task_started messages; the frontend's stop
|
|
1102
|
+
// button sends an agent_id (from SubagentStart). Correlation chain:
|
|
1103
|
+
// PreToolUse(Task) records tool_use_id per subagent_type (FIFO) →
|
|
1104
|
+
// SubagentStart claims the oldest unclaimed tool_use_id of its type →
|
|
1105
|
+
// task_started maps tool_use_id → task_id.
|
|
1106
|
+
#tasksById = new Map();
|
|
1107
|
+
#taskIdByToolUse = new Map();
|
|
1108
|
+
#pendingToolUseByType = new Map();
|
|
1109
|
+
#toolUseByAgentId = new Map();
|
|
1110
|
+
#typeByAgentId = new Map();
|
|
1111
|
+
// In-flight interrupt — pushMessage defers its channel push until this
|
|
1112
|
+
// settles, so an enriched [INTERRUPTED] message can never land inside the
|
|
1113
|
+
// turn being aborted (a fold-in-flight message dies with that turn).
|
|
1114
|
+
#pendingInterrupt = null;
|
|
1098
1115
|
// Dedup guard — prevents double-firing reviewer/gate if SubagentStop fires
|
|
1099
1116
|
// more than once for the same agent_id (e.g. retry edge cases).
|
|
1100
1117
|
#dispatchedFor = new Set();
|
|
@@ -1431,7 +1448,16 @@ export class ClaudeLLM extends llm.LLM {
|
|
|
1431
1448
|
// Prefer persistent query's interrupt() — graceful Esc that keeps subprocess alive
|
|
1432
1449
|
if (this.#persistentQuery && typeof this.#persistentQuery.interrupt === 'function') {
|
|
1433
1450
|
try {
|
|
1434
|
-
|
|
1451
|
+
// Expose the in-flight interrupt so pushMessage can order itself AFTER
|
|
1452
|
+
// the abort (callers like the sync voice chat() path can't await us).
|
|
1453
|
+
const p = Promise.resolve(this.#persistentQuery.interrupt()).then(() => { });
|
|
1454
|
+
let tracked;
|
|
1455
|
+
tracked = p.catch(() => { }).finally(() => {
|
|
1456
|
+
if (this.#pendingInterrupt === tracked)
|
|
1457
|
+
this.#pendingInterrupt = null;
|
|
1458
|
+
});
|
|
1459
|
+
this.#pendingInterrupt = tracked;
|
|
1460
|
+
await p;
|
|
1435
1461
|
console.log('🛑 Interrupted persistent session (Esc equivalent — subprocess stays alive)');
|
|
1436
1462
|
return true;
|
|
1437
1463
|
}
|
|
@@ -1531,21 +1557,111 @@ export class ClaudeLLM extends llm.LLM {
|
|
|
1531
1557
|
this.#activeQueries.delete(q);
|
|
1532
1558
|
}
|
|
1533
1559
|
/**
|
|
1534
|
-
* Stop a single dispatch flow by agent_id.
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
1560
|
+
* Stop a single dispatch flow by agent_id — REAL stop via query.stopTask().
|
|
1561
|
+
* Resolves agent_id → tool_use_id (claimed at SubagentStart) → task_id
|
|
1562
|
+
* (from the SDK's task_started message); falls back to the only running
|
|
1563
|
+
* task of the same subagent_type when the chain has a gap. Returns true
|
|
1564
|
+
* only when a stopTask was actually issued — the old #activeQueriesById
|
|
1565
|
+
* path never populated, so this used to report "stopped" while nothing
|
|
1566
|
+
* stopped. Does NOT affect other tasks (use abortQuery() to kill all).
|
|
1537
1567
|
*/
|
|
1538
|
-
stopAgent(agentId) {
|
|
1539
|
-
const
|
|
1540
|
-
if (!
|
|
1568
|
+
async stopAgent(agentId) {
|
|
1569
|
+
const taskId = this.#resolveTaskId(agentId);
|
|
1570
|
+
if (!taskId || !this.#persistentQuery || typeof this.#persistentQuery.stopTask !== 'function') {
|
|
1571
|
+
console.log(`🛑 stopAgent(${agentId}): no task to stop (taskId=${taskId ?? 'none'})`);
|
|
1541
1572
|
return false;
|
|
1573
|
+
}
|
|
1542
1574
|
try {
|
|
1543
|
-
|
|
1575
|
+
await this.#persistentQuery.stopTask(taskId);
|
|
1576
|
+
const t = this.#tasksById.get(taskId);
|
|
1577
|
+
if (t)
|
|
1578
|
+
t.status = 'stopped';
|
|
1579
|
+
console.log(`🛑 stopAgent(${agentId}) → stopTask(${taskId}) issued (${t?.subagentType || '?'})`);
|
|
1580
|
+
return true;
|
|
1544
1581
|
}
|
|
1545
|
-
catch {
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1582
|
+
catch (err) {
|
|
1583
|
+
console.error(`⚠️ stopTask(${taskId}) failed:`, err?.message);
|
|
1584
|
+
return false;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
#resolveTaskId(agentId) {
|
|
1588
|
+
const toolUse = this.#toolUseByAgentId.get(agentId);
|
|
1589
|
+
if (toolUse) {
|
|
1590
|
+
const byToolUse = this.#taskIdByToolUse.get(toolUse);
|
|
1591
|
+
if (byToolUse)
|
|
1592
|
+
return byToolUse;
|
|
1593
|
+
// Pairing exists but its task already ended (terminal notification unmapped
|
|
1594
|
+
// it). This agent's work is DONE — do not fall through to the type fallback,
|
|
1595
|
+
// which would retarget the stop onto a DIFFERENT live agent of the same type.
|
|
1596
|
+
return null;
|
|
1597
|
+
}
|
|
1598
|
+
// Fallback: a single running task of the agent's subagent_type is unambiguous.
|
|
1599
|
+
const type = this.#typeByAgentId.get(agentId);
|
|
1600
|
+
if (type) {
|
|
1601
|
+
const candidates = [...this.#tasksById.entries()]
|
|
1602
|
+
.filter(([, t]) => t.subagentType === type && (t.status === 'running' || t.status === 'pending'));
|
|
1603
|
+
if (candidates.length === 1)
|
|
1604
|
+
return candidates[0][0];
|
|
1605
|
+
}
|
|
1606
|
+
return null;
|
|
1607
|
+
}
|
|
1608
|
+
/** PreToolUse(Task) capture: remember the dispatching tool_use_id per type (FIFO). */
|
|
1609
|
+
noteTaskDispatch(toolUseId, subagentType) {
|
|
1610
|
+
if (!toolUseId || !subagentType)
|
|
1611
|
+
return;
|
|
1612
|
+
const q = this.#pendingToolUseByType.get(subagentType) || [];
|
|
1613
|
+
q.push(toolUseId);
|
|
1614
|
+
this.#pendingToolUseByType.set(subagentType, q);
|
|
1615
|
+
}
|
|
1616
|
+
/** SubagentStart claim: pair this agent_id with the oldest unclaimed dispatch of its type. */
|
|
1617
|
+
claimTaskDispatch(agentId, subagentType) {
|
|
1618
|
+
if (!agentId || !subagentType)
|
|
1619
|
+
return;
|
|
1620
|
+
this.#typeByAgentId.set(agentId, subagentType);
|
|
1621
|
+
const q = this.#pendingToolUseByType.get(subagentType);
|
|
1622
|
+
if (q?.length) {
|
|
1623
|
+
// Prefer the oldest dispatch the registry has seen START (task_started
|
|
1624
|
+
// already mapped its tool_use_id): a denied/errored Task never starts,
|
|
1625
|
+
// and pairing with its stale id would skew every later pairing of this
|
|
1626
|
+
// type. Fall back to plain FIFO when no started id is known yet.
|
|
1627
|
+
const idx = q.findIndex(tu => this.#taskIdByToolUse.has(tu));
|
|
1628
|
+
const toolUse = idx >= 0 ? q.splice(idx, 1)[0] : q.shift();
|
|
1629
|
+
if (toolUse)
|
|
1630
|
+
this.#toolUseByAgentId.set(agentId, toolUse);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
/** Background consumer feed: track SDK task lifecycle messages. */
|
|
1634
|
+
trackTaskMessage(msg) {
|
|
1635
|
+
if (msg?.type !== 'system')
|
|
1636
|
+
return;
|
|
1637
|
+
if (msg.subtype === 'task_started') {
|
|
1638
|
+
this.#tasksById.set(msg.task_id, {
|
|
1639
|
+
toolUseId: msg.tool_use_id,
|
|
1640
|
+
subagentType: msg.subagent_type,
|
|
1641
|
+
description: msg.description,
|
|
1642
|
+
status: 'running',
|
|
1643
|
+
});
|
|
1644
|
+
if (msg.tool_use_id)
|
|
1645
|
+
this.#taskIdByToolUse.set(msg.tool_use_id, msg.task_id);
|
|
1646
|
+
}
|
|
1647
|
+
else if (msg.subtype === 'task_updated') {
|
|
1648
|
+
const t = this.#tasksById.get(msg.task_id);
|
|
1649
|
+
if (t && msg.patch?.status)
|
|
1650
|
+
t.status = msg.patch.status;
|
|
1651
|
+
}
|
|
1652
|
+
else if (msg.subtype === 'task_notification') {
|
|
1653
|
+
// Terminal: completed | failed | stopped — drop from the live registry.
|
|
1654
|
+
const t = this.#tasksById.get(msg.task_id);
|
|
1655
|
+
if (t?.toolUseId)
|
|
1656
|
+
this.#taskIdByToolUse.delete(t.toolUseId);
|
|
1657
|
+
this.#tasksById.delete(msg.task_id);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
/** Live background tasks (for truthful status/UX). */
|
|
1661
|
+
getRunningTasks() {
|
|
1662
|
+
return [...this.#tasksById.entries()]
|
|
1663
|
+
.filter(([, t]) => t.status === 'running' || t.status === 'pending')
|
|
1664
|
+
.map(([taskId, t]) => ({ taskId, subagentType: t.subagentType, description: t.description, status: t.status }));
|
|
1549
1665
|
}
|
|
1550
1666
|
// ============================================================
|
|
1551
1667
|
// PERSISTENT SESSION — V1 query() with AsyncIterable<SDKUserMessage>
|
|
@@ -1588,6 +1704,13 @@ export class ClaudeLLM extends llm.LLM {
|
|
|
1588
1704
|
this.#messageChannel = null;
|
|
1589
1705
|
this.#backgroundConsumerRunning = false;
|
|
1590
1706
|
this.#dispatchedFor.clear();
|
|
1707
|
+
// Task registry is per-process (SDK task ids die with the subprocess).
|
|
1708
|
+
this.#tasksById.clear();
|
|
1709
|
+
this.#taskIdByToolUse.clear();
|
|
1710
|
+
this.#pendingToolUseByType.clear();
|
|
1711
|
+
this.#toolUseByAgentId.clear();
|
|
1712
|
+
this.#typeByAgentId.clear();
|
|
1713
|
+
this.#pendingInterrupt = null;
|
|
1591
1714
|
console.log('🔒 Persistent session closed');
|
|
1592
1715
|
}
|
|
1593
1716
|
/**
|
|
@@ -1599,7 +1722,11 @@ export class ClaudeLLM extends llm.LLM {
|
|
|
1599
1722
|
* @param sdkOptions - Full V1 Options (only used on first call to create the query)
|
|
1600
1723
|
* @param callbacks - Event callbacks for the background consumer
|
|
1601
1724
|
*/
|
|
1602
|
-
pushMessage(userText, sdkOptions, callbacks
|
|
1725
|
+
pushMessage(userText, sdkOptions, callbacks,
|
|
1726
|
+
// Progressive-interrupt ladder: the SDK's own queue delivers mid-turn
|
|
1727
|
+
// messages at the next tool boundary (native fold) — default. 'now' =
|
|
1728
|
+
// native interrupt-and-redirect; 'later' = wait for the turn to finish.
|
|
1729
|
+
pushOpts) {
|
|
1603
1730
|
// (Compaction/1M env is set once at module load — see ENABLE_1M_CONTEXT /
|
|
1604
1731
|
// CLAUDE_AUTOCOMPACT_PCT_OVERRIDE near ensureCompactionSettings(). Setting it
|
|
1605
1732
|
// here per-message was too late for the persistent query.)
|
|
@@ -1608,11 +1735,31 @@ export class ClaudeLLM extends llm.LLM {
|
|
|
1608
1735
|
message: { role: 'user', content: [{ type: 'text', text: userText }] },
|
|
1609
1736
|
parent_tool_use_id: null,
|
|
1610
1737
|
session_id: this.#sessionId || '',
|
|
1738
|
+
...(pushOpts?.priority && { priority: pushOpts.priority }),
|
|
1611
1739
|
};
|
|
1612
1740
|
if (this.#persistentQuery && this.#messageChannel && !this.#messageChannel.closed) {
|
|
1613
|
-
// Fast path — push to existing subprocess (no cold start)
|
|
1614
|
-
|
|
1615
|
-
|
|
1741
|
+
// Fast path — push to existing subprocess (no cold start).
|
|
1742
|
+
// If an interrupt is in flight, order the push AFTER it settles: a message
|
|
1743
|
+
// that folds into the turn being aborted never runs as its own turn, so
|
|
1744
|
+
// pushing during the abort window can lose the user's message.
|
|
1745
|
+
const pending = this.#pendingInterrupt;
|
|
1746
|
+
if (pending) {
|
|
1747
|
+
console.log('⚡ Persistent session: interrupt in flight — deferring push until it settles');
|
|
1748
|
+
pending.then(() => {
|
|
1749
|
+
if (this.#messageChannel && !this.#messageChannel.closed) {
|
|
1750
|
+
console.log('⚡ Persistent session: pushing deferred message (post-interrupt)');
|
|
1751
|
+
this.#messageChannel.push(userMessage);
|
|
1752
|
+
}
|
|
1753
|
+
else {
|
|
1754
|
+
// Never drop a user message silently — make the loss loud in logs.
|
|
1755
|
+
console.warn(`⚠️ Deferred message NOT delivered (channel closed during interrupt): "${userText.slice(0, 80)}"`);
|
|
1756
|
+
}
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
else {
|
|
1760
|
+
console.log('⚡ Persistent session: pushing message (no JSONL replay)');
|
|
1761
|
+
this.#messageChannel.push(userMessage);
|
|
1762
|
+
}
|
|
1616
1763
|
return;
|
|
1617
1764
|
}
|
|
1618
1765
|
// Cold start — create channel, push first message, start query + background consumer
|
|
@@ -1636,6 +1783,10 @@ export class ClaudeLLM extends llm.LLM {
|
|
|
1636
1783
|
try {
|
|
1637
1784
|
for await (const message of pq) {
|
|
1638
1785
|
const msg = message;
|
|
1786
|
+
// Background-task lifecycle → registry (task_started/updated/notification).
|
|
1787
|
+
// This is what makes the per-flow stop button real: stopTask() needs the
|
|
1788
|
+
// task_id these messages carry.
|
|
1789
|
+
this.trackTaskMessage(msg);
|
|
1639
1790
|
// Session ID capture
|
|
1640
1791
|
if (msg.type === 'system' && msg.subtype === 'init') {
|
|
1641
1792
|
const mcpServers = msg.mcp_servers;
|
|
@@ -1880,6 +2031,13 @@ class ClaudeLLMStream extends llm.LLMStream {
|
|
|
1880
2031
|
// model: this.#llmRef.turbo ? FAST_MODEL : (this.#opts.model || 'claude-opus-4-8[1m]'), // prev
|
|
1881
2032
|
model: this.#llmRef.turbo ? FAST_MODEL : (this.#opts.model || 'claude-opus-5-5'), // Opus 5.5 default — 1M context built-in, no beta suffix needed
|
|
1882
2033
|
enableFileCheckpointing: true,
|
|
2034
|
+
// Declares a per-task stop control (stop_dispatch → query.stopTask), so an
|
|
2035
|
+
// interrupt on this open-input streaming session SPARES running background
|
|
2036
|
+
// agents/workflows — Stop aborts only the current turn. Without this the
|
|
2037
|
+
// CLI fails closed: every interrupt killed in-flight sub-agents (the
|
|
2038
|
+
// "stuck running writers" bug). Live-proven on d4f24f46: flag off = busy
|
|
2039
|
+
// sub-agent killed at interrupt; flag on = survived; stopTask stops it.
|
|
2040
|
+
perTaskStopAffordance: true,
|
|
1883
2041
|
settingSources: ['project', 'user'],
|
|
1884
2042
|
extraArgs: { 'replay-user-messages': null },
|
|
1885
2043
|
...(this.#abortController && { abortController: this.#abortController }),
|
|
@@ -2038,6 +2196,9 @@ class ClaudeLLMStream extends llm.LLMStream {
|
|
|
2038
2196
|
const d = String(toolInput?.description || toolInput?.prompt || '');
|
|
2039
2197
|
if (st && d)
|
|
2040
2198
|
this.#pendingTaskByType.set(st, d);
|
|
2199
|
+
// Per-flow stop correlation: remember the dispatching tool_use_id so
|
|
2200
|
+
// SubagentStart can pair agent_id → tool_use_id → task_id (stopTask).
|
|
2201
|
+
this.#llmRef.noteTaskDispatch(input?.tool_use_id, st || undefined);
|
|
2041
2202
|
}
|
|
2042
2203
|
this.#eventEmitter.emit('tool_use', { name: toolName, input: toolInput, agentRole: agentType || 'main', agentId: input?.agent_id });
|
|
2043
2204
|
return {};
|
|
@@ -2429,6 +2590,8 @@ class ClaudeLLMStream extends llm.LLMStream {
|
|
|
2429
2590
|
if (at0)
|
|
2430
2591
|
this.#pendingTaskByType.delete(String(at0));
|
|
2431
2592
|
const task = rawTask ? String(rawTask).replace(/\s+/g, ' ').trim().slice(0, 160) : undefined;
|
|
2593
|
+
// Pair this agent_id with its dispatching tool_use_id (per-flow stop chain).
|
|
2594
|
+
this.#llmRef.claimTaskDispatch(input?.agent_id, at0 ? String(at0) : undefined);
|
|
2432
2595
|
this.#eventEmitter.emit('agent_started', { agent_type: input?.agent_type, agent_id: input?.agent_id, task });
|
|
2433
2596
|
// Record the dispatch as LIVE so the frontend can reconcile orphaned
|
|
2434
2597
|
// "running" rows against statusManager.getActiveDispatchIds(). Without a
|
|
@@ -2531,11 +2694,19 @@ class ClaudeLLMStream extends llm.LLMStream {
|
|
|
2531
2694
|
// PERSISTENT SESSION: Push message to existing subprocess (no JSONL replay).
|
|
2532
2695
|
// First call creates the query (cold start). Subsequent calls are instant.
|
|
2533
2696
|
// The background consumer in ClaudeLLM handles all message routing (TTS, tools, etc.)
|
|
2697
|
+
// Progressive interrupt (locked design): every real user message carries
|
|
2698
|
+
// priority 'now' — the SDK natively aborts the current turn and answers
|
|
2699
|
+
// immediately, while perTaskStopAffordance spares background sub-agents,
|
|
2700
|
+
// so interrupting is free (work lives in interrupt-surviving tasks).
|
|
2701
|
+
// Meeting transcript chunks are ambient and must NOT interrupt (they
|
|
2702
|
+
// arrive continuously and would abort working turns nonstop).
|
|
2703
|
+
// Escape hatch: OSBORN_MSG_PRIORITY=off restores queue-and-fold.
|
|
2704
|
+
const steerNow = process.env.OSBORN_MSG_PRIORITY !== 'off' && !userText.startsWith('[MEETING');
|
|
2534
2705
|
this.#llmRef.pushMessage(userText, sdkOptions, {
|
|
2535
2706
|
onSessionId: this.#onSessionId,
|
|
2536
2707
|
onCheckpoint: this.#onCheckpoint,
|
|
2537
2708
|
eventEmitter: this.#eventEmitter,
|
|
2538
|
-
});
|
|
2709
|
+
}, steerNow ? { priority: 'now' } : undefined);
|
|
2539
2710
|
// Return immediately — queue closes, pipeline completes, say() handles play
|
|
2540
2711
|
console.log('🚀 Direct mode: Claude query running in background, pipeline released');
|
|
2541
2712
|
return;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
type SandboxMode = 'workspace-write' | 'danger-full-access';
|
|
3
|
+
type ApprovalPolicy = 'on-failure' | 'on-request' | 'never';
|
|
4
|
+
interface CodexHandlerOptions {
|
|
5
|
+
workingDirectory?: string;
|
|
6
|
+
skipGitRepoCheck?: boolean;
|
|
7
|
+
sandboxMode?: SandboxMode;
|
|
8
|
+
approvalPolicy?: ApprovalPolicy;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Codex Handler using the official OpenAI Codex SDK
|
|
12
|
+
*
|
|
13
|
+
* Features:
|
|
14
|
+
* - Thread persistence (reuses same thread for context)
|
|
15
|
+
* - Built-in coding tools (file operations, terminal commands)
|
|
16
|
+
* - Hooks for observability
|
|
17
|
+
*
|
|
18
|
+
* Requirements:
|
|
19
|
+
* - Codex CLI must be installed (npm install -g @openai/codex or use npx)
|
|
20
|
+
* - Must be authenticated via: codex login (ChatGPT) or OPENAI_API_KEY env var
|
|
21
|
+
*
|
|
22
|
+
* Sandbox/Approval modes are configured via:
|
|
23
|
+
* - ~/.codex/config.yaml for global settings
|
|
24
|
+
* - CLI flags: --sandbox, --approval-policy
|
|
25
|
+
*
|
|
26
|
+
* Note: The SDK spawns the CLI binary, so authentication must be done beforehand.
|
|
27
|
+
*/
|
|
28
|
+
export declare class CodexHandler extends EventEmitter {
|
|
29
|
+
private codex;
|
|
30
|
+
private thread;
|
|
31
|
+
private options;
|
|
32
|
+
constructor(options?: CodexHandlerOptions);
|
|
33
|
+
run(prompt: string): Promise<string>;
|
|
34
|
+
getThreadId(): string | null;
|
|
35
|
+
clearThread(): void;
|
|
36
|
+
}
|
|
37
|
+
export declare function askCodex(prompt: string, cwd?: string): Promise<string>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Codex } from '@openai/codex-sdk';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
/**
|
|
4
|
+
* Codex Handler using the official OpenAI Codex SDK
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - Thread persistence (reuses same thread for context)
|
|
8
|
+
* - Built-in coding tools (file operations, terminal commands)
|
|
9
|
+
* - Hooks for observability
|
|
10
|
+
*
|
|
11
|
+
* Requirements:
|
|
12
|
+
* - Codex CLI must be installed (npm install -g @openai/codex or use npx)
|
|
13
|
+
* - Must be authenticated via: codex login (ChatGPT) or OPENAI_API_KEY env var
|
|
14
|
+
*
|
|
15
|
+
* Sandbox/Approval modes are configured via:
|
|
16
|
+
* - ~/.codex/config.yaml for global settings
|
|
17
|
+
* - CLI flags: --sandbox, --approval-policy
|
|
18
|
+
*
|
|
19
|
+
* Note: The SDK spawns the CLI binary, so authentication must be done beforehand.
|
|
20
|
+
*/
|
|
21
|
+
export class CodexHandler extends EventEmitter {
|
|
22
|
+
codex;
|
|
23
|
+
thread = null;
|
|
24
|
+
options;
|
|
25
|
+
constructor(options = {}) {
|
|
26
|
+
super();
|
|
27
|
+
this.options = {
|
|
28
|
+
workingDirectory: options.workingDirectory || process.cwd(),
|
|
29
|
+
skipGitRepoCheck: options.skipGitRepoCheck ?? true,
|
|
30
|
+
};
|
|
31
|
+
// Initialize Codex (inherits process env by default)
|
|
32
|
+
this.codex = new Codex();
|
|
33
|
+
}
|
|
34
|
+
async run(prompt) {
|
|
35
|
+
try {
|
|
36
|
+
// Create or reuse thread
|
|
37
|
+
if (!this.thread) {
|
|
38
|
+
console.log('🆕 Starting new Codex thread');
|
|
39
|
+
this.thread = this.codex.startThread({
|
|
40
|
+
workingDirectory: this.options.workingDirectory,
|
|
41
|
+
skipGitRepoCheck: this.options.skipGitRepoCheck,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
console.log('🔄 Continuing Codex thread');
|
|
46
|
+
}
|
|
47
|
+
console.log(`📁 CWD: ${this.options.workingDirectory}`);
|
|
48
|
+
this.emit('thinking', prompt);
|
|
49
|
+
// Run the prompt and get the Turn result
|
|
50
|
+
const turn = await this.thread.run(prompt);
|
|
51
|
+
// Extract the final response text
|
|
52
|
+
const result = turn.finalResponse || '';
|
|
53
|
+
this.emit('result', result);
|
|
54
|
+
console.log(`✅ Codex done. Length: ${result.length}`);
|
|
55
|
+
// Log tool usage if any
|
|
56
|
+
if (turn.items && turn.items.length > 0) {
|
|
57
|
+
for (const item of turn.items) {
|
|
58
|
+
this.emit('tool_use', item);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result || 'Task completed.';
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error('❌ Codex SDK error:', error);
|
|
65
|
+
this.emit('error', error);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
getThreadId() {
|
|
70
|
+
// Codex threads have IDs but they may not be directly exposed
|
|
71
|
+
// Check the thread object for an id property
|
|
72
|
+
return this.thread?.id || null;
|
|
73
|
+
}
|
|
74
|
+
clearThread() {
|
|
75
|
+
this.thread = null;
|
|
76
|
+
console.log('🗑️ Codex thread cleared');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Quick utility for one-off queries
|
|
80
|
+
export async function askCodex(prompt, cwd) {
|
|
81
|
+
const handler = new CodexHandler({ workingDirectory: cwd });
|
|
82
|
+
return handler.run(prompt);
|
|
83
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex LLM Wrapper for LiveKit Agents
|
|
3
|
+
*
|
|
4
|
+
* Wraps the Codex Agent SDK (@openai/codex-sdk) to work
|
|
5
|
+
* with LiveKit's AgentSession as an LLM provider.
|
|
6
|
+
*
|
|
7
|
+
* Flow: User speaks → STT → CodexLLM (Agent SDK) → TTS → User hears
|
|
8
|
+
*/
|
|
9
|
+
import { llm, type APIConnectOptions } from '@livekit/agents';
|
|
10
|
+
import { Codex } from '@openai/codex-sdk';
|
|
11
|
+
import { EventEmitter } from 'events';
|
|
12
|
+
export interface CodexLLMOptions {
|
|
13
|
+
workingDirectory?: string;
|
|
14
|
+
skipGitRepoCheck?: boolean;
|
|
15
|
+
/** Event emitter for tool_use, progress updates */
|
|
16
|
+
eventEmitter?: EventEmitter;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Codex LLM - Wraps Codex Agent SDK for LiveKit
|
|
20
|
+
*/
|
|
21
|
+
export declare class CodexLLM extends llm.LLM {
|
|
22
|
+
#private;
|
|
23
|
+
constructor(opts?: CodexLLMOptions);
|
|
24
|
+
label(): string;
|
|
25
|
+
get model(): string;
|
|
26
|
+
get events(): EventEmitter;
|
|
27
|
+
get thread(): ReturnType<Codex['startThread']> | null;
|
|
28
|
+
chat({ chatCtx, toolCtx, connOptions, }: {
|
|
29
|
+
chatCtx: llm.ChatContext;
|
|
30
|
+
toolCtx?: llm.ToolContext;
|
|
31
|
+
connOptions?: APIConnectOptions;
|
|
32
|
+
parallelToolCalls?: boolean;
|
|
33
|
+
toolChoice?: llm.ToolChoice;
|
|
34
|
+
extraKwargs?: Record<string, unknown>;
|
|
35
|
+
}): llm.LLMStream;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a CodexLLM instance
|
|
39
|
+
*/
|
|
40
|
+
export declare function createCodexLLM(opts?: CodexLLMOptions): CodexLLM;
|