osborn 0.9.275 → 0.9.277

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.
@@ -115,7 +115,7 @@ Personal values are NOT stored in this skill. They live in a local secret file t
115
115
  | City / State / Zip | `$CANDIDATE_CITY` / `$CANDIDATE_STATE` / `$CANDIDATE_ZIP` |
116
116
 
117
117
  Jobs:
118
- 1. Meta API Consultant at Prehype / Audos — April 2024 to Present
118
+ 1. Senior Engineer at Acme Corp — April 2024 to Present
119
119
  2. Full Stack Developer, Freelance — January 2016 to Present
120
120
 
121
121
  Education:
@@ -121,7 +121,7 @@ card replaced the stream).
121
121
 
122
122
  **Drive the engine** (one Bash call, needs `OSBORN_ENGINE_TOKEN` env):
123
123
  ```bash
124
- curl -sS -X POST "https://osborn-voice-e2e.fly.dev:8781/act" \
124
+ curl -sS -X POST "https://osborn-voice-e2e-n.fly.dev:8781/act" \
125
125
  -H "x-engine-token: $OSBORN_ENGINE_TOKEN" -H 'Content-Type: application/json' \
126
126
  -d '{"instruction":"go to youtube.com"}'
127
127
  ```
@@ -59,6 +59,14 @@ export declare function hasFallbackModelKey(env?: NodeJS.ProcessEnv): boolean;
59
59
  * upgrade. OSBORN_FORCE_CLAUDE_LOGIN=1 restores the old blocking behaviour.
60
60
  */
61
61
  export declare function shouldSkipBlockingOAuth(env: NodeJS.ProcessEnv, authed: boolean): boolean;
62
+ /**
63
+ * Pure decision for ensureClaudeAuth()'s in-flight branch (#71): should a new
64
+ * join wait on an OAuth flow that is already running? Only when the user
65
+ * explicitly asked to sign in (force) or there is no fallback model to run on.
66
+ * A fallback-key machine re-entering /chat must not be blocked by the optional
67
+ * sign-in it opened earlier.
68
+ */
69
+ export declare function inFlightAuthBlocksJoin(env: NodeJS.ProcessEnv, force?: boolean): boolean;
62
70
  /**
63
71
  * Additive onboarding tier resolution. Runs AFTER ensureClaudeAuth() and BEFORE
64
72
  * session creation. Resolves which auth backend the agent will use, in order
@@ -230,6 +230,18 @@ export function shouldSkipBlockingOAuth(env, authed) {
230
230
  return false;
231
231
  return hasFallbackModelKey(env);
232
232
  }
233
+ /**
234
+ * Pure decision for ensureClaudeAuth()'s in-flight branch (#71): should a new
235
+ * join wait on an OAuth flow that is already running? Only when the user
236
+ * explicitly asked to sign in (force) or there is no fallback model to run on.
237
+ * A fallback-key machine re-entering /chat must not be blocked by the optional
238
+ * sign-in it opened earlier.
239
+ */
240
+ export function inFlightAuthBlocksJoin(env, force = false) {
241
+ if (force)
242
+ return true;
243
+ return !shouldSkipBlockingOAuth(env, false);
244
+ }
233
245
  /**
234
246
  * Additive onboarding tier resolution. Runs AFTER ensureClaudeAuth() and BEFORE
235
247
  * session creation. Resolves which auth backend the agent will use, in order
@@ -269,8 +281,10 @@ export function applyAuthFallback() {
269
281
  // pay-per-use). Cline/opencode-style: unauthenticated demo users ride the
270
282
  // house pass instead of raw API billing. The z.ai Anthropic-compatible
271
283
  // endpoint (api.z.ai/api/anthropic) speaks native Messages - verified live
272
- // 2026-10-24 (glm-4.7 returned a real response). Precedence: Z_AI_PERSONAL_API_KEY,
273
- // then ZAI_API_KEY.
284
+ // 2026-10-24 (glm-4.7 returned a real response). Defaults moved to glm-5.3 /
285
+ // glm-5.3-flash 2026-11-10: the GLM Coding Plan now only lists GLM-5.3 and
286
+ // GLM-5.3-Flash (docs.z.ai/devpack/overview; glm-4.7 is silently routed to
287
+ // 5.3-Flash). Precedence: Z_AI_PERSONAL_API_KEY, then ZAI_API_KEY.
274
288
  const zaiKey = cleanEnvKey(process.env.Z_AI_PERSONAL_API_KEY) || cleanEnvKey(process.env.ZAI_API_KEY);
275
289
  if (zaiKey !== '') {
276
290
  snapshotModelEnv();
@@ -278,18 +292,20 @@ export function applyAuthFallback() {
278
292
  process.env.ANTHROPIC_BASE_URL = process.env.OSBORN_DEMO_BASE_URL || 'https://api.z.ai/api/anthropic';
279
293
  process.env.ANTHROPIC_AUTH_TOKEN = zaiKey;
280
294
  process.env.ANTHROPIC_API_KEY = ''; // required - a set key bypasses AUTH_TOKEN
281
- const demoModel = process.env.OSBORN_DEMO_MODEL || 'glm-4.7';
295
+ const demoModel = process.env.OSBORN_DEMO_MODEL || 'glm-5.3';
296
+ const demoFastModel = process.env.OSBORN_DEMO_FAST_MODEL || 'glm-5.3-flash';
282
297
  process.env.ANTHROPIC_MODEL = demoModel;
283
- process.env.ANTHROPIC_SMALL_FAST_MODEL = demoModel;
298
+ process.env.ANTHROPIC_SMALL_FAST_MODEL = demoFastModel;
284
299
  process.env.CLAUDE_CODE_SUBAGENT_MODEL = demoModel;
285
300
  process.env.CLAUDE_CODE_SUBAGENT_MODEL_FORCE = demoModel;
286
- // GLM-4.7 exposes a 200K window; pins the CLI's context-cap handling.
287
- process.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS = process.env.OSBORN_DEMO_MAX_CONTEXT || '200000';
301
+ // GLM-5.3 and GLM-5.3-Flash expose a 1M-token window (docs.z.ai/guides/llm/glm-5.3,
302
+ // verified 2026-11-10); pins the CLI's context-cap handling.
303
+ process.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS = process.env.OSBORN_DEMO_MAX_CONTEXT || '1000000';
288
304
  // Signal for the fast brain (pipeline-fastbrain reads this per call) so the
289
305
  // WHOLE model layer - main agent AND fast brain - rides the same pass.
290
306
  process.env.OSBORN_DEMO_PASS = 'zai';
291
307
  fallbackTierActive = true;
292
- console.log(`[auth-fallback] using house demo pass (z.ai), model=${demoModel}`);
308
+ console.log(`[auth-fallback] using house demo pass (z.ai), model=${demoModel}, fast=${demoFastModel}`);
293
309
  return;
294
310
  }
295
311
  // Tier 4: central OpenRouter key (pay-per-use fallback of the fallback).
@@ -342,7 +358,7 @@ export function clearAuthFallbackIfActive() {
342
358
  delete process.env.ANTHROPIC_AUTH_TOKEN;
343
359
  // Model-slot overrides both tiers (z.ai + OpenRouter) set — restore the
344
360
  // pre-fallback values (or unset) so the real Claude session isn't pinned onto
345
- // glm-4.7 / FALLBACK_MODEL and the fallback's context cap.
361
+ // glm-5.3 / FALLBACK_MODEL and the fallback's context cap.
346
362
  restoreModelEnv();
347
363
  // Was forced to '' for the OpenRouter redirect; unset so the real OAuth
348
364
  // token path (CLAUDE_CODE_OAUTH_TOKEN) is used cleanly.
@@ -662,6 +678,24 @@ export function replayInFlightAuth(send) {
662
678
  * sees two different URLs / two different code_challenges racing.
663
679
  */
664
680
  export async function ensureClaudeAuth(sendToFrontend, opts = {}) {
681
+ // A flow is in flight but this machine already has a working model (a
682
+ // fallback key) and nobody explicitly asked to sign in: this is a re-entry
683
+ // (reload / back into /chat) while the optional on-demand sign-in is still
684
+ // open. Don't block the session on it or re-raise the blocking modal (#71) —
685
+ // run on the fallback and keep sign-in optional; the on-demand flow still
686
+ // owns the code paste (pendingAuthSubmitCode) and claude_auth_start replays it.
687
+ if (inFlightAuth && !inFlightAuthBlocksJoin(process.env, !!opts.force)) {
688
+ console.log('🔑 ensureClaudeAuth: OAuth in flight but a fallback model is available — not blocking this join');
689
+ try {
690
+ sendToFrontend('claude_auth_optional', {
691
+ message: 'Running on the fallback model. Sign in to Claude to upgrade.',
692
+ });
693
+ }
694
+ catch (err) {
695
+ console.warn('🔑 claude_auth_optional send failed:', err);
696
+ }
697
+ return {};
698
+ }
665
699
  // If an auth flow is already running, attach to it and replay any
666
700
  // state we've already captured (the URL, any waiting_code prompt).
667
701
  if (inFlightAuth) {
@@ -7,7 +7,7 @@
7
7
  * Flow: User speaks → STT → ClaudeLLM (Agent SDK) → TTS → User hears
8
8
  */
9
9
  import { llm, type APIConnectOptions } from '@livekit/agents';
10
- import { type Options, type McpServerConfig } from '@anthropic-ai/claude-agent-sdk';
10
+ import { query, type Options, type McpServerConfig } from '@anthropic-ai/claude-agent-sdk';
11
11
  import { EventEmitter } from 'events';
12
12
  export interface ClaudeLLMOptions {
13
13
  workingDirectory?: string;
@@ -43,6 +43,9 @@ export interface ClaudeLLMOptions {
43
43
  tools?: string[];
44
44
  model?: string;
45
45
  }>;
46
+ /** Test seam: replaces the SDK `query()` for the persistent session (cold start
47
+ * + primeResume). Production never sets it. */
48
+ queryFn?: typeof query;
46
49
  }
47
50
  export declare const NAMED_AGENTS: {
48
51
  researcher: {
@@ -215,6 +218,7 @@ export declare class ClaudeLLM extends llm.LLM {
215
218
  * Call this when resuming a session from a different project slug
216
219
  */
217
220
  setWorkingDirectory(path: string): void;
221
+ get workingDirectory(): string | undefined;
218
222
  /**
219
223
  * Reset state for mid-conversation session switch
220
224
  * Clears pending permissions and resets conversation tracking
@@ -323,6 +327,22 @@ export declare class ClaudeLLM extends llm.LLM {
323
327
  description?: string;
324
328
  status: string;
325
329
  }>;
330
+ /** `resume` id the live persistent query was spawned with (null = fresh / none). */
331
+ get spawnedResumeId(): string | null;
332
+ /**
333
+ * What the live session is doing right now (#74). A session switch is only
334
+ * executed when `idle`: a turn awaiting its result, SDK tasks (sub-agents
335
+ * outlive their turn), compaction, an in-flight interrupt or a permission
336
+ * prompt all mean closing the query would lose work.
337
+ */
338
+ busyState(): {
339
+ turnInFlight: boolean;
340
+ runningTasks: number;
341
+ compacting: boolean;
342
+ interruptPending: boolean;
343
+ permissionPending: boolean;
344
+ idle: boolean;
345
+ };
326
346
  /** Whether a persistent session is alive and consuming messages */
327
347
  hasSession(): boolean;
328
348
  /**
@@ -1234,6 +1234,11 @@ export class ClaudeLLM extends llm.LLM {
1234
1234
  // they drive the deferred restart (see requestAuthRestart()).
1235
1235
  #spawnAuthGen = authEnvGeneration;
1236
1236
  #turnsInFlight = 0;
1237
+ // `resume` id the live persistent query was spawned with (null = fresh, or no
1238
+ // query). Lets a session switch tell "query already runs the armed target"
1239
+ // from "armed target is a pending switch" (#74; see session-switch.ts).
1240
+ #spawnedResumeId = null;
1241
+ #queryFn = query;
1237
1242
  /** True when the live subprocess predates the latest auth-backend change. */
1238
1243
  get authRestartPending() {
1239
1244
  return !!this.#persistentQuery && this.#spawnAuthGen !== authEnvGeneration;
@@ -1288,6 +1293,8 @@ export class ClaudeLLM extends llm.LLM {
1288
1293
  onCompactionEvent: opts.onCompactionEvent,
1289
1294
  };
1290
1295
  this.#eventEmitter = opts.eventEmitter || new EventEmitter();
1296
+ if (opts.queryFn)
1297
+ this.#queryFn = opts.queryFn;
1291
1298
  console.log('🟠 ClaudeLLM initialized (Research Mode)');
1292
1299
  console.log(` 📁 Working dir (cwd): ${this.#opts.workingDirectory}`);
1293
1300
  if (this.#opts.sessionBaseDir !== this.#opts.workingDirectory) {
@@ -1480,6 +1487,9 @@ export class ClaudeLLM extends llm.LLM {
1480
1487
  setWorkingDirectory(path) {
1481
1488
  this.#opts.workingDirectory = path;
1482
1489
  }
1490
+ get workingDirectory() {
1491
+ return this.#opts.workingDirectory;
1492
+ }
1483
1493
  /**
1484
1494
  * Reset state for mid-conversation session switch
1485
1495
  * Clears pending permissions and resets conversation tracking
@@ -1632,6 +1642,16 @@ export class ClaudeLLM extends llm.LLM {
1632
1642
  });
1633
1643
  this.#pendingInterrupt = tracked;
1634
1644
  await p;
1645
+ // Turn-in-flight reset (#90 leak fix): the interrupt aborts the current
1646
+ // turn and returns the subprocess to idle, but closeSession() is
1647
+ // deliberately NOT called here (the subprocess stays alive) and the
1648
+ // aborted turn may never emit a terminal `result` to decrement
1649
+ // #turnsInFlight. Without this reset the counter leaks upward forever,
1650
+ // permanently wedging shouldRestartForAuth() so a later Claude sign-in
1651
+ // never swaps the live subprocess off the fallback backend. Reset to 0
1652
+ // (not decrement): an idle subprocess has no turn streaming. Safe — the
1653
+ // result handler clamps at > 0, so a late `result` can't drive it negative.
1654
+ this.#turnsInFlight = 0;
1635
1655
  console.log('🛑 Interrupted persistent session (Esc equivalent — subprocess stays alive)');
1636
1656
  return true;
1637
1657
  }
@@ -1859,6 +1879,27 @@ export class ClaudeLLM extends llm.LLM {
1859
1879
  // start; subsequent chat() calls push messages to the existing
1860
1880
  // subprocess via the MessageChannel — no JSONL replay.
1861
1881
  // ============================================================
1882
+ /** `resume` id the live persistent query was spawned with (null = fresh / none). */
1883
+ get spawnedResumeId() {
1884
+ return this.#spawnedResumeId;
1885
+ }
1886
+ /**
1887
+ * What the live session is doing right now (#74). A session switch is only
1888
+ * executed when `idle`: a turn awaiting its result, SDK tasks (sub-agents
1889
+ * outlive their turn), compaction, an in-flight interrupt or a permission
1890
+ * prompt all mean closing the query would lose work.
1891
+ */
1892
+ busyState() {
1893
+ const turnInFlight = this.#turnsInFlight > 0;
1894
+ const runningTasks = this.getRunningTasks().length;
1895
+ const compacting = !!this.compacting;
1896
+ const interruptPending = !!this.#pendingInterrupt;
1897
+ const permissionPending = this.hasPendingPermission();
1898
+ return {
1899
+ turnInFlight, runningTasks, compacting, interruptPending, permissionPending,
1900
+ idle: !turnInFlight && runningTasks === 0 && !compacting && !interruptPending && !permissionPending,
1901
+ };
1902
+ }
1862
1903
  /** Whether a persistent session is alive and consuming messages */
1863
1904
  hasSession() {
1864
1905
  return this.#persistentQuery !== null && !this.#messageChannel?.closed;
@@ -1892,6 +1933,7 @@ export class ClaudeLLM extends llm.LLM {
1892
1933
  }
1893
1934
  this.#persistentQuery = null;
1894
1935
  this.#messageChannel = null;
1936
+ this.#spawnedResumeId = null;
1895
1937
  this.#backgroundConsumerRunning = false;
1896
1938
  this.#dispatchedFor.clear();
1897
1939
  // Task registry is per-process (SDK task ids die with the subprocess).
@@ -1935,7 +1977,8 @@ export class ClaudeLLM extends llm.LLM {
1935
1977
  console.log('🔥 primeResume: eager cold-start — resume replay overlaps connect (no user message)');
1936
1978
  this.#spawnAuthGen = authEnvGeneration;
1937
1979
  this.#messageChannel = new MessageChannel();
1938
- this.#persistentQuery = query({ prompt: this.#messageChannel, options: sdkOptions });
1980
+ this.#spawnedResumeId = sdkOptions?.resume ?? null;
1981
+ this.#persistentQuery = this.#queryFn({ prompt: this.#messageChannel, options: sdkOptions });
1939
1982
  this.#activeQueries.add(this.#persistentQuery);
1940
1983
  this.#startBackgroundConsumer(callbacks);
1941
1984
  }
@@ -1981,6 +2024,29 @@ export class ClaudeLLM extends llm.LLM {
1981
2024
  console.log('🔑 Auth backend changed since spawn — restarting persistent session before this turn');
1982
2025
  this.closeSession();
1983
2026
  }
2027
+ // Session-switch backstop (#74): a resume target was armed for a DIFFERENT
2028
+ // session than the live query runs (not the id it was spawned for, not the
2029
+ // id init reported). Pushing would run this turn in the old session and
2030
+ // init would then report session_resume_failed {requested: armed, actual:
2031
+ // old} — the live bug. When idle, rebuild on the armed target (sdkOptions
2032
+ // already carries resume: armed, see run()). When busy, never abort the
2033
+ // old session's work: push as before and warn. A target the query was
2034
+ // already spawned for (a failed resume) is never retried — no loop.
2035
+ if (this.#persistentQuery && this.#messageChannel && !this.#messageChannel.closed) {
2036
+ const armed = this.#opts.resumeSessionId || null;
2037
+ if (armed && armed !== this.#spawnedResumeId && armed !== this.#sessionId) {
2038
+ const busy = this.busyState();
2039
+ if (busy.idle) {
2040
+ console.log(`🔀 Pending switch to ${armed.substring(0, 8)} — closing idle session ${this.#sessionId?.substring(0, 8) ?? '(new)'} and resuming the target`);
2041
+ this.closeSession();
2042
+ this.#sessionId = null;
2043
+ userMessage.session_id = '';
2044
+ }
2045
+ else {
2046
+ console.warn(`⚠️ Session switch to ${armed.substring(0, 8)} is pending but the live session is busy (${JSON.stringify(busy)}) — this turn still runs in ${this.#sessionId?.substring(0, 8) ?? 'the live session'}`);
2047
+ }
2048
+ }
2049
+ }
1984
2050
  this.#turnsInFlight++;
1985
2051
  if (this.#persistentQuery && this.#messageChannel && !this.#messageChannel.closed) {
1986
2052
  // Fast path — push to existing subprocess (no cold start).
@@ -2015,7 +2081,8 @@ export class ClaudeLLM extends llm.LLM {
2015
2081
  this.#spawnAuthGen = authEnvGeneration;
2016
2082
  this.#messageChannel = new MessageChannel();
2017
2083
  this.#messageChannel.push(userMessage);
2018
- this.#persistentQuery = query({ prompt: this.#messageChannel, options: sdkOptions });
2084
+ this.#spawnedResumeId = sdkOptions?.resume ?? null;
2085
+ this.#persistentQuery = this.#queryFn({ prompt: this.#messageChannel, options: sdkOptions });
2019
2086
  this.#activeQueries.add(this.#persistentQuery);
2020
2087
  this.#startBackgroundConsumer(callbacks);
2021
2088
  }
@@ -2201,6 +2268,13 @@ export class ClaudeLLM extends llm.LLM {
2201
2268
  this.#backgroundConsumerRunning = false;
2202
2269
  this.#persistentQuery = null;
2203
2270
  this.#messageChannel = null;
2271
+ // Turn-in-flight reset (#90 leak fix): this loop owned the subprocess and
2272
+ // it is now gone (iterator ended or errored), so no turn can still be
2273
+ // streaming on it. A turn that ended without a terminal `result` (an
2274
+ // interrupt or a mid-turn iterator error) never decremented #turnsInFlight;
2275
+ // leaving it > 0 would permanently block shouldRestartForAuth(). Strictly
2276
+ // safe — the subprocess is dead, so there is nothing in flight to miscount.
2277
+ this.#turnsInFlight = 0;
2204
2278
  }
2205
2279
  console.log('🔒 Persistent session background consumer exited');
2206
2280
  }
@@ -34,7 +34,7 @@ export interface ClientRedactor {
34
34
  export interface RedactorOptions {
35
35
  /**
36
36
  * PER-PIECE opt-in un-redaction: denylisted terms to leave visible for ONE
37
- * named draft/render (e.g. reveal: ["Audos"]). Never used by extraction —
37
+ * named draft/render (e.g. reveal: ["Acme"]). Never used by extraction —
38
38
  * the profile and samples are always stored fully redacted. A renderer that
39
39
  * reveals re-pulls the quote rows from session.db by row # and redacts them
40
40
  * with this option, in memory, for that piece only.
@@ -14,6 +14,7 @@
14
14
  * Gated (state-changing or leaks session/process ids):
15
15
  * user_text, claude_auth_code, permission_response, list_sessions,
16
16
  * resume_session, continue_session, switch_session, session_selected,
17
+ * cancel_session_switch,
17
18
  * mcp_toggle, set_agents, skill_add, skill_remove, noise_cancel,
18
19
  * gate_send_anyway, stop_dispatch, join_meeting, leave_meeting,
19
20
  * mute_participant, start_ide, stop_ide, spawn_background_session,
@@ -14,6 +14,7 @@
14
14
  * Gated (state-changing or leaks session/process ids):
15
15
  * user_text, claude_auth_code, permission_response, list_sessions,
16
16
  * resume_session, continue_session, switch_session, session_selected,
17
+ * cancel_session_switch,
17
18
  * mcp_toggle, set_agents, skill_add, skill_remove, noise_cancel,
18
19
  * gate_send_anyway, stop_dispatch, join_meeting, leave_meeting,
19
20
  * mute_participant, start_ide, stop_ide, spawn_background_session,
@@ -45,6 +46,8 @@ export const CONTROL_MESSAGE_TYPES = new Set([
45
46
  'resume_session',
46
47
  'continue_session',
47
48
  'switch_session',
49
+ // Cancels a deferred switch (#74) — state-changing, controller-only.
50
+ 'cancel_session_switch',
48
51
  'session_selected',
49
52
  'mcp_toggle',
50
53
  'set_agents',