jeo-code 0.7.46 → 0.7.47
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/CHANGELOG.md +13 -0
- package/README.ja.md +1 -1
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/package.json +1 -1
- package/src/agent/config-schema.ts +18 -0
- package/src/agent/prompt-router.ts +273 -0
- package/src/agent/state.ts +11 -0
- package/src/commands/launch/route-slash.ts +88 -0
- package/src/commands/launch.ts +39 -6
- package/src/tui/components/slash.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
The README mirrors the latest 5 entries — regenerate with `bun run changelog:sync`.
|
|
8
8
|
|
|
9
|
+
## [0.7.47] - 2026-07-06
|
|
10
|
+
_PromptRouter (gjc-inspired, jeo-native design — NOT a port of katanemo/plano, whose always-on proxy-orchestrator architecture doesn't fit an interactive CLI's per-turn latency budget): jeo already had static, role-based model mapping (`resolveSubagentModel`/`resolveRoleModel`) but zero logic that varied the model by what THIS turn's prompt actually asks for. Adds an opt-in (default OFF), heuristic-first, fail-open per-turn router: a bilingual regex classifier scores a prompt into trivial/standard/complex, escalating to one cheap LLM call ONLY when the heuristic is genuinely ambiguous (confidence below a configurable threshold — most turns never escalate), and an explicit `/model` pin always wins over routing. No new plumbing: reuses `resolveRoleModel`, `callLlm`, `jsonMode`, `catalogMetadata`, `tryExtractJsonObject`, and the existing `onNotice` transparency pattern._
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **`src/agent/prompt-router.ts`** — `classifyPromptHeuristically` (pure, sync, zero-I/O): bilingual (EN/KR) signal detection for short factual questions, causal/debugging questions ("why"/"how"/"왜"/"어떻게" — deliberately NEVER classified as trivial despite being short-and-question-shaped), code fences, file-path mentions (single vs. multi-file), and deep-work keywords (design/architecture/refactor/debug/설계/아키텍처/리팩터/디버그); conflicting or weak signals resolve to `standard` at low confidence so escalation decides. `routePrompt` escalates to a real LLM classification only below `routing.confidenceThreshold` (default 0.6) AND only when `roles.smol` is configured (otherwise "escalate to a cheap model" would paradoxically call the expensive `defaultModel` — skipped with a one-time `warnOnce` notice instead); the escalation response is parsed via `tryExtractJsonObject` (never bare `JSON.parse`, since not every provider has native JSON mode) and the returned tier is strictly validated against the 3 literal values before being trusted. Tier→model resolution reuses `config.roles.smol`/`config.roles.slow` when `routing.tiers.*.model` isn't explicitly set — zero new config required to get working routing if role tiers are already configured. An image-bearing prompt whose resolved tier model lacks image support (`catalogMetadata(...)?.images === false`) fails open, returning `null` so the caller keeps its own multimodal-capable model. The entire function is wrapped in try/catch and returns `null` on any unexpected failure — routing can never break a turn.
|
|
14
|
+
- **`LaunchTui`/`runTurn` wiring** (`src/commands/launch.ts`) — the `activeModel`/`activeThinking` computation now calls `routePrompt` when routing is enabled (session override via `/route on|off`, else `config.routing.enabled`) AND the user has NOT manually pinned a session model via `/model` (explicit choice always wins, verified by a real end-to-end test through `runLaunchCommand` — routing never engages when `sessionModel` is set even with `routing.enabled: true`). A `[route] tier → model (...)` notice surfaces only when something actually changed (an LLM escalation occurred, or the tier isn't `standard`) — a routine unescalated turn stays silent.
|
|
15
|
+
- **`/route [status|on|off|why]`** (`src/commands/launch/route-slash.ts`, registered in `src/tui/components/slash.ts`) — session-local toggle (never persisted to `~/.jeo/config.json`, mirroring `/thinking`) plus a `why` subcommand that explains the last routing decision's tier, resolved model, confidence, source (heuristic/llm), and every fired signal.
|
|
16
|
+
- **`routing` config field** (`ConfigSchema` in `config-schema.ts`, `Config` in `state.ts`) — `{enabled?, confidenceThreshold?, tiers?: {trivial|standard|complex: {model?, thinking?}}}`, all optional, default OFF.
|
|
17
|
+
|
|
18
|
+
### Verified
|
|
19
|
+
- `bun run typecheck` clean; `bun test` 2479 pass / 0 fail (48 new: `test/prompt-router.test.ts` — 32 tests covering the full bilingual signal corpus incl. the causal-question and numeric-fraction-path false-positive fixes found during design, escalation fail-open on `callLlm` throwing/aborting/returning malformed or invalid-tier JSON, the image-capability gate, and the "no config at all resolves to defaultModel" safe-no-op case; `test/route-slash.test.ts` — 12 tests for every `/route` subcommand; `test/launch-prompt-routing.test.ts` — 4 real end-to-end tests through the actual `runLaunchCommand` entrypoint, mocking only `node:readline` input and `runAgentLoop`'s network boundary, proving the explicit-`/model`-always-wins guarantee and `roles.smol`/`routing.tiers.*.thinking` resolution against the REAL wiring, not a synthetic stub).
|
|
20
|
+
- Two independent subagent passes (config-schema + core router module in parallel, then launch.ts/slash wiring), every line independently re-read and cross-checked against a frozen, pre-verified implementation contract by the orchestrating session before merge — including two real bugs caught in the contract itself before implementation (a TDZ reference to `tui` before its declaration, and invalid `??`/`||` operator mixing) that both subagents correctly fixed as mechanical corrections.
|
|
21
|
+
|
|
9
22
|
## [0.7.46] - 2026-07-06
|
|
10
23
|
_Registry-only correction: `npm publish` packs the working-tree filesystem, not the git commit — a concurrent, unrelated, uncommitted feature-in-progress from another session sharing this checkout (`src/agent/prompt-router.ts`, `src/commands/launch/route-slash.ts`, and edits to `config-schema.ts`/`state.ts`/`launch.ts`/`slash.ts`) was physically present on disk during the 0.7.45 `npm publish` and got bundled into that tarball even though it was never committed to git and is absent from the `0.7.45` git tag/branch. Unpublished `jeo-code@0.7.45` from the registry within minutes (npm then permanently blocks republishing that exact version number, hence the bump to 0.7.46) and republished from a verified-clean working tree (`git stash` of the foreign files, `npm pack --dry-run` confirmed their absence, then restored the stash afterward so the other session's in-progress work was never touched or lost). No functional change versus the intended 0.7.45 content — see that entry below._
|
|
11
24
|
|
package/README.ja.md
CHANGED
|
@@ -259,11 +259,11 @@ CI は `.github/workflows/npm-publish.yml` で公開します — GitHub リリ
|
|
|
259
259
|
## 変更履歴 (Changelog)
|
|
260
260
|
|
|
261
261
|
<!-- CHANGELOG:START (auto-generated from CHANGELOG.md — run `bun run changelog:sync`) -->
|
|
262
|
+
- **[0.7.47]** (2026-07-06) — PromptRouter (gjc-inspired, jeo-native design — NOT a port of katanemo/plano, whose always-on proxy-orchestrator architecture doesn't fit an interactive CLI's per-turn latency budget): jeo already had static, role-based model mapping (`resolveSubagentModel`/`resolveRoleModel`) but zero logic that varied the model by what THIS turn's prompt actually asks for. Adds an opt-in (default OFF), heuristic-first, fail-open per-turn router: a bilingual regex classifier scores a prompt into trivial/standard/complex, escalating to one cheap LLM call ONLY when the heuristic is genuinely ambiguous (confidence below a configurable threshold — most turns never escalate), and an explicit `/model` pin always wins over routing. No new plumbing: reuses `resolveRoleModel`, `callLlm`, `jsonMode`, `catalogMetadata`, `tryExtractJsonObject`, and the existing `onNotice` transparency pattern.
|
|
262
263
|
- **[0.7.46]** (2026-07-06) — Registry-only correction: `npm publish` packs the working-tree filesystem, not the git commit — a concurrent, unrelated, uncommitted feature-in-progress from another session sharing this checkout (`src/agent/prompt-router.ts`, `src/commands/launch/route-slash.ts`, and edits to `config-schema.ts`/`state.ts`/`launch.ts`/`slash.ts`) was physically present on disk during the 0.7.45 `npm publish` and got bundled into that tarball even though it was never committed to git and is absent from the `0.7.45` git tag/branch. Unpublished `jeo-code@0.7.45` from the registry within minutes (npm then permanently blocks republishing that exact version number, hence the bump to 0.7.46) and republished from a verified-clean working tree (`git stash` of the foreign files, `npm pack --dry-run` confirmed their absence, then restored the stash afterward so the other session's in-progress work was never touched or lost). No functional change versus the intended 0.7.45 content — see that entry below.
|
|
263
264
|
- **[0.7.45]** (2026-07-06) — gjc parity: jeo's subagent `task {tasks:[...]}` fan-out batches now visibly run as PARALLEL processes the way gjc's own task tool does, instead of quietly forcing the mutating executor role to serialize. Two compounding bugs made a batch of independent subagent tasks look and behave sequential even though the read-only roles were already technically concurrent: (1) the executor role's fan-out was hard-coded to concurrency 1 regardless of batch size, and (2) the TUI's live status line tracked ONE shared string clobbered by whichever worker's event landed last — worse, ANY single worker reaching "done" cleared the whole `(sub)` marker even while its siblings were still actively running.
|
|
264
265
|
- **[0.7.44]** (2026-07-06) — Root-caused a real production hang reported from `jeo`'s OpenAI Codex OAuth subagent path: after roughly 20-30 minutes of active streamed traffic, `chatgpt.com`'s backend severs the live SSE connection mid-response (an infra connection-duration cap, not a broken network) and Bun's fetch/undici surfaces it as `Error: The socket connection was closed unexpectedly …`. `retryableStream` (model-manager.ts) only auto-retries losing the FIRST streamed chunk — once any chunk had reached the caller it deliberately stopped retrying (a full re-call would replay already-emitted content) — so this class of drop propagated straight out of the engine as a raw, unretried turn-ending error every time, even though nothing had been committed to history yet and a plain resend is exactly as safe as a fresh call.
|
|
265
266
|
- **[0.7.43]** (2026-07-06) — TUI inline image DISPLAY (gjc TUI-image parity): jeo could already ATTACH an image to a turn (clipboard paste, drag-drop, `@path`) but never rendered it back — the transcript only ever showed a `⧉ N image(s) attached` count. On a terminal that speaks the kitty graphics protocol (kitty/ghostty/wezterm) or iTerm2's OSC 1337 inline-image protocol, a submitted image now renders as an actual picture directly under the `user` card; every other terminal (Terminal.app, plain xterm, CI/non-TTY) keeps today's text-only behavior unchanged. No native/binary dependency added — Sixel was deliberately left out because producing a sixel stream from arbitrary PNG/JPEG bytes needs a pixel quantizer jeo doesn't have; both implemented protocols decode compressed image bytes themselves.
|
|
266
|
-
- **[0.7.42]** (2026-07-06) — Fixes a genuine infinite hang on "thinking"/"executing" (reported under `jeo --tmux`, but the two root causes are tmux-agnostic): the interactive streaming model call had no absolute wall-clock, and the ~30-minute turn stall budget was a passive check that could never interrupt a blocked await in the first place. A third, lower-confidence but plausible tmux-specific trigger (synchronous TUI frame writes blocking on a backpressured tmux pane) gets a defensive, generic fix too.
|
|
267
267
|
|
|
268
268
|
See [CHANGELOG.md](CHANGELOG.md) for the full history.
|
|
269
269
|
<!-- CHANGELOG:END -->
|
package/README.ko.md
CHANGED
|
@@ -259,11 +259,11 @@ CI는 `.github/workflows/npm-publish.yml`로 배포합니다 — GitHub 릴리
|
|
|
259
259
|
## 변경 이력 (Changelog)
|
|
260
260
|
|
|
261
261
|
<!-- CHANGELOG:START (auto-generated from CHANGELOG.md — run `bun run changelog:sync`) -->
|
|
262
|
+
- **[0.7.47]** (2026-07-06) — PromptRouter (gjc-inspired, jeo-native design — NOT a port of katanemo/plano, whose always-on proxy-orchestrator architecture doesn't fit an interactive CLI's per-turn latency budget): jeo already had static, role-based model mapping (`resolveSubagentModel`/`resolveRoleModel`) but zero logic that varied the model by what THIS turn's prompt actually asks for. Adds an opt-in (default OFF), heuristic-first, fail-open per-turn router: a bilingual regex classifier scores a prompt into trivial/standard/complex, escalating to one cheap LLM call ONLY when the heuristic is genuinely ambiguous (confidence below a configurable threshold — most turns never escalate), and an explicit `/model` pin always wins over routing. No new plumbing: reuses `resolveRoleModel`, `callLlm`, `jsonMode`, `catalogMetadata`, `tryExtractJsonObject`, and the existing `onNotice` transparency pattern.
|
|
262
263
|
- **[0.7.46]** (2026-07-06) — Registry-only correction: `npm publish` packs the working-tree filesystem, not the git commit — a concurrent, unrelated, uncommitted feature-in-progress from another session sharing this checkout (`src/agent/prompt-router.ts`, `src/commands/launch/route-slash.ts`, and edits to `config-schema.ts`/`state.ts`/`launch.ts`/`slash.ts`) was physically present on disk during the 0.7.45 `npm publish` and got bundled into that tarball even though it was never committed to git and is absent from the `0.7.45` git tag/branch. Unpublished `jeo-code@0.7.45` from the registry within minutes (npm then permanently blocks republishing that exact version number, hence the bump to 0.7.46) and republished from a verified-clean working tree (`git stash` of the foreign files, `npm pack --dry-run` confirmed their absence, then restored the stash afterward so the other session's in-progress work was never touched or lost). No functional change versus the intended 0.7.45 content — see that entry below.
|
|
263
264
|
- **[0.7.45]** (2026-07-06) — gjc parity: jeo's subagent `task {tasks:[...]}` fan-out batches now visibly run as PARALLEL processes the way gjc's own task tool does, instead of quietly forcing the mutating executor role to serialize. Two compounding bugs made a batch of independent subagent tasks look and behave sequential even though the read-only roles were already technically concurrent: (1) the executor role's fan-out was hard-coded to concurrency 1 regardless of batch size, and (2) the TUI's live status line tracked ONE shared string clobbered by whichever worker's event landed last — worse, ANY single worker reaching "done" cleared the whole `(sub)` marker even while its siblings were still actively running.
|
|
264
265
|
- **[0.7.44]** (2026-07-06) — Root-caused a real production hang reported from `jeo`'s OpenAI Codex OAuth subagent path: after roughly 20-30 minutes of active streamed traffic, `chatgpt.com`'s backend severs the live SSE connection mid-response (an infra connection-duration cap, not a broken network) and Bun's fetch/undici surfaces it as `Error: The socket connection was closed unexpectedly …`. `retryableStream` (model-manager.ts) only auto-retries losing the FIRST streamed chunk — once any chunk had reached the caller it deliberately stopped retrying (a full re-call would replay already-emitted content) — so this class of drop propagated straight out of the engine as a raw, unretried turn-ending error every time, even though nothing had been committed to history yet and a plain resend is exactly as safe as a fresh call.
|
|
265
266
|
- **[0.7.43]** (2026-07-06) — TUI inline image DISPLAY (gjc TUI-image parity): jeo could already ATTACH an image to a turn (clipboard paste, drag-drop, `@path`) but never rendered it back — the transcript only ever showed a `⧉ N image(s) attached` count. On a terminal that speaks the kitty graphics protocol (kitty/ghostty/wezterm) or iTerm2's OSC 1337 inline-image protocol, a submitted image now renders as an actual picture directly under the `user` card; every other terminal (Terminal.app, plain xterm, CI/non-TTY) keeps today's text-only behavior unchanged. No native/binary dependency added — Sixel was deliberately left out because producing a sixel stream from arbitrary PNG/JPEG bytes needs a pixel quantizer jeo doesn't have; both implemented protocols decode compressed image bytes themselves.
|
|
266
|
-
- **[0.7.42]** (2026-07-06) — Fixes a genuine infinite hang on "thinking"/"executing" (reported under `jeo --tmux`, but the two root causes are tmux-agnostic): the interactive streaming model call had no absolute wall-clock, and the ~30-minute turn stall budget was a passive check that could never interrupt a blocked await in the first place. A third, lower-confidence but plausible tmux-specific trigger (synchronous TUI frame writes blocking on a backpressured tmux pane) gets a defensive, generic fix too.
|
|
267
267
|
|
|
268
268
|
See [CHANGELOG.md](CHANGELOG.md) for the full history.
|
|
269
269
|
<!-- CHANGELOG:END -->
|
package/README.md
CHANGED
|
@@ -261,11 +261,11 @@ Huge thanks to [gajae-code](https://github.com/Yeachan-Heo/gajae-code) for the i
|
|
|
261
261
|
## Changelog
|
|
262
262
|
|
|
263
263
|
<!-- CHANGELOG:START (auto-generated from CHANGELOG.md — run `bun run changelog:sync`) -->
|
|
264
|
+
- **[0.7.47]** (2026-07-06) — PromptRouter (gjc-inspired, jeo-native design — NOT a port of katanemo/plano, whose always-on proxy-orchestrator architecture doesn't fit an interactive CLI's per-turn latency budget): jeo already had static, role-based model mapping (`resolveSubagentModel`/`resolveRoleModel`) but zero logic that varied the model by what THIS turn's prompt actually asks for. Adds an opt-in (default OFF), heuristic-first, fail-open per-turn router: a bilingual regex classifier scores a prompt into trivial/standard/complex, escalating to one cheap LLM call ONLY when the heuristic is genuinely ambiguous (confidence below a configurable threshold — most turns never escalate), and an explicit `/model` pin always wins over routing. No new plumbing: reuses `resolveRoleModel`, `callLlm`, `jsonMode`, `catalogMetadata`, `tryExtractJsonObject`, and the existing `onNotice` transparency pattern.
|
|
264
265
|
- **[0.7.46]** (2026-07-06) — Registry-only correction: `npm publish` packs the working-tree filesystem, not the git commit — a concurrent, unrelated, uncommitted feature-in-progress from another session sharing this checkout (`src/agent/prompt-router.ts`, `src/commands/launch/route-slash.ts`, and edits to `config-schema.ts`/`state.ts`/`launch.ts`/`slash.ts`) was physically present on disk during the 0.7.45 `npm publish` and got bundled into that tarball even though it was never committed to git and is absent from the `0.7.45` git tag/branch. Unpublished `jeo-code@0.7.45` from the registry within minutes (npm then permanently blocks republishing that exact version number, hence the bump to 0.7.46) and republished from a verified-clean working tree (`git stash` of the foreign files, `npm pack --dry-run` confirmed their absence, then restored the stash afterward so the other session's in-progress work was never touched or lost). No functional change versus the intended 0.7.45 content — see that entry below.
|
|
265
266
|
- **[0.7.45]** (2026-07-06) — gjc parity: jeo's subagent `task {tasks:[...]}` fan-out batches now visibly run as PARALLEL processes the way gjc's own task tool does, instead of quietly forcing the mutating executor role to serialize. Two compounding bugs made a batch of independent subagent tasks look and behave sequential even though the read-only roles were already technically concurrent: (1) the executor role's fan-out was hard-coded to concurrency 1 regardless of batch size, and (2) the TUI's live status line tracked ONE shared string clobbered by whichever worker's event landed last — worse, ANY single worker reaching "done" cleared the whole `(sub)` marker even while its siblings were still actively running.
|
|
266
267
|
- **[0.7.44]** (2026-07-06) — Root-caused a real production hang reported from `jeo`'s OpenAI Codex OAuth subagent path: after roughly 20-30 minutes of active streamed traffic, `chatgpt.com`'s backend severs the live SSE connection mid-response (an infra connection-duration cap, not a broken network) and Bun's fetch/undici surfaces it as `Error: The socket connection was closed unexpectedly …`. `retryableStream` (model-manager.ts) only auto-retries losing the FIRST streamed chunk — once any chunk had reached the caller it deliberately stopped retrying (a full re-call would replay already-emitted content) — so this class of drop propagated straight out of the engine as a raw, unretried turn-ending error every time, even though nothing had been committed to history yet and a plain resend is exactly as safe as a fresh call.
|
|
267
268
|
- **[0.7.43]** (2026-07-06) — TUI inline image DISPLAY (gjc TUI-image parity): jeo could already ATTACH an image to a turn (clipboard paste, drag-drop, `@path`) but never rendered it back — the transcript only ever showed a `⧉ N image(s) attached` count. On a terminal that speaks the kitty graphics protocol (kitty/ghostty/wezterm) or iTerm2's OSC 1337 inline-image protocol, a submitted image now renders as an actual picture directly under the `user` card; every other terminal (Terminal.app, plain xterm, CI/non-TTY) keeps today's text-only behavior unchanged. No native/binary dependency added — Sixel was deliberately left out because producing a sixel stream from arbitrary PNG/JPEG bytes needs a pixel quantizer jeo doesn't have; both implemented protocols decode compressed image bytes themselves.
|
|
268
|
-
- **[0.7.42]** (2026-07-06) — Fixes a genuine infinite hang on "thinking"/"executing" (reported under `jeo --tmux`, but the two root causes are tmux-agnostic): the interactive streaming model call had no absolute wall-clock, and the ~30-minute turn stall budget was a passive check that could never interrupt a blocked await in the first place. A third, lower-confidence but plausible tmux-specific trigger (synchronous TUI frame writes blocking on a backpressured tmux pane) gets a defensive, generic fix too.
|
|
269
269
|
|
|
270
270
|
See [CHANGELOG.md](CHANGELOG.md) for the full history.
|
|
271
271
|
<!-- CHANGELOG:END -->
|
package/README.zh.md
CHANGED
|
@@ -259,11 +259,11 @@ CI 通过 `.github/workflows/npm-publish.yml` 发布 — GitHub 发布 release
|
|
|
259
259
|
## 更新日志 (Changelog)
|
|
260
260
|
|
|
261
261
|
<!-- CHANGELOG:START (auto-generated from CHANGELOG.md — run `bun run changelog:sync`) -->
|
|
262
|
+
- **[0.7.47]** (2026-07-06) — PromptRouter (gjc-inspired, jeo-native design — NOT a port of katanemo/plano, whose always-on proxy-orchestrator architecture doesn't fit an interactive CLI's per-turn latency budget): jeo already had static, role-based model mapping (`resolveSubagentModel`/`resolveRoleModel`) but zero logic that varied the model by what THIS turn's prompt actually asks for. Adds an opt-in (default OFF), heuristic-first, fail-open per-turn router: a bilingual regex classifier scores a prompt into trivial/standard/complex, escalating to one cheap LLM call ONLY when the heuristic is genuinely ambiguous (confidence below a configurable threshold — most turns never escalate), and an explicit `/model` pin always wins over routing. No new plumbing: reuses `resolveRoleModel`, `callLlm`, `jsonMode`, `catalogMetadata`, `tryExtractJsonObject`, and the existing `onNotice` transparency pattern.
|
|
262
263
|
- **[0.7.46]** (2026-07-06) — Registry-only correction: `npm publish` packs the working-tree filesystem, not the git commit — a concurrent, unrelated, uncommitted feature-in-progress from another session sharing this checkout (`src/agent/prompt-router.ts`, `src/commands/launch/route-slash.ts`, and edits to `config-schema.ts`/`state.ts`/`launch.ts`/`slash.ts`) was physically present on disk during the 0.7.45 `npm publish` and got bundled into that tarball even though it was never committed to git and is absent from the `0.7.45` git tag/branch. Unpublished `jeo-code@0.7.45` from the registry within minutes (npm then permanently blocks republishing that exact version number, hence the bump to 0.7.46) and republished from a verified-clean working tree (`git stash` of the foreign files, `npm pack --dry-run` confirmed their absence, then restored the stash afterward so the other session's in-progress work was never touched or lost). No functional change versus the intended 0.7.45 content — see that entry below.
|
|
263
264
|
- **[0.7.45]** (2026-07-06) — gjc parity: jeo's subagent `task {tasks:[...]}` fan-out batches now visibly run as PARALLEL processes the way gjc's own task tool does, instead of quietly forcing the mutating executor role to serialize. Two compounding bugs made a batch of independent subagent tasks look and behave sequential even though the read-only roles were already technically concurrent: (1) the executor role's fan-out was hard-coded to concurrency 1 regardless of batch size, and (2) the TUI's live status line tracked ONE shared string clobbered by whichever worker's event landed last — worse, ANY single worker reaching "done" cleared the whole `(sub)` marker even while its siblings were still actively running.
|
|
264
265
|
- **[0.7.44]** (2026-07-06) — Root-caused a real production hang reported from `jeo`'s OpenAI Codex OAuth subagent path: after roughly 20-30 minutes of active streamed traffic, `chatgpt.com`'s backend severs the live SSE connection mid-response (an infra connection-duration cap, not a broken network) and Bun's fetch/undici surfaces it as `Error: The socket connection was closed unexpectedly …`. `retryableStream` (model-manager.ts) only auto-retries losing the FIRST streamed chunk — once any chunk had reached the caller it deliberately stopped retrying (a full re-call would replay already-emitted content) — so this class of drop propagated straight out of the engine as a raw, unretried turn-ending error every time, even though nothing had been committed to history yet and a plain resend is exactly as safe as a fresh call.
|
|
265
266
|
- **[0.7.43]** (2026-07-06) — TUI inline image DISPLAY (gjc TUI-image parity): jeo could already ATTACH an image to a turn (clipboard paste, drag-drop, `@path`) but never rendered it back — the transcript only ever showed a `⧉ N image(s) attached` count. On a terminal that speaks the kitty graphics protocol (kitty/ghostty/wezterm) or iTerm2's OSC 1337 inline-image protocol, a submitted image now renders as an actual picture directly under the `user` card; every other terminal (Terminal.app, plain xterm, CI/non-TTY) keeps today's text-only behavior unchanged. No native/binary dependency added — Sixel was deliberately left out because producing a sixel stream from arbitrary PNG/JPEG bytes needs a pixel quantizer jeo doesn't have; both implemented protocols decode compressed image bytes themselves.
|
|
266
|
-
- **[0.7.42]** (2026-07-06) — Fixes a genuine infinite hang on "thinking"/"executing" (reported under `jeo --tmux`, but the two root causes are tmux-agnostic): the interactive streaming model call had no absolute wall-clock, and the ~30-minute turn stall budget was a passive check that could never interrupt a blocked await in the first place. A third, lower-confidence but plausible tmux-specific trigger (synchronous TUI frame writes blocking on a backpressured tmux pane) gets a defensive, generic fix too.
|
|
267
267
|
|
|
268
268
|
See [CHANGELOG.md](CHANGELOG.md) for the full history.
|
|
269
269
|
<!-- CHANGELOG:END -->
|
package/package.json
CHANGED
|
@@ -161,6 +161,24 @@ export const ConfigSchema = z
|
|
|
161
161
|
plan: z.string().optional(),
|
|
162
162
|
})
|
|
163
163
|
.optional(),
|
|
164
|
+
/** Prompt-content-based per-turn model routing (PromptRouter). Opt-in — off unless
|
|
165
|
+
* `enabled: true`. Applies ONLY to the main interactive turn loop (never to
|
|
166
|
+
* subagents/`task`, which keep their own `subagents.*`/role-tier resolution
|
|
167
|
+
* untouched), and ONLY when the user has not manually pinned a session model
|
|
168
|
+
* via `/model` (explicit user choice always wins). */
|
|
169
|
+
routing: z
|
|
170
|
+
.object({
|
|
171
|
+
enabled: z.boolean().optional(),
|
|
172
|
+
confidenceThreshold: z.number().min(0).max(1).optional(),
|
|
173
|
+
tiers: z
|
|
174
|
+
.object({
|
|
175
|
+
trivial: z.object({ model: z.string().optional(), thinking: z.enum(["minimal", "low", "medium", "high", "xhigh"]).optional() }).optional(),
|
|
176
|
+
standard: z.object({ model: z.string().optional(), thinking: z.enum(["minimal", "low", "medium", "high", "xhigh"]).optional() }).optional(),
|
|
177
|
+
complex: z.object({ model: z.string().optional(), thinking: z.enum(["minimal", "low", "medium", "high", "xhigh"]).optional() }).optional(),
|
|
178
|
+
})
|
|
179
|
+
.optional(),
|
|
180
|
+
})
|
|
181
|
+
.optional(),
|
|
164
182
|
gitAutoCommit: z.boolean().optional(),
|
|
165
183
|
hooks: HookConfigSchema.optional(),
|
|
166
184
|
computer: z
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PromptRouter: per-turn, prompt-content-based model routing (heuristic-first,
|
|
3
|
+
* LLM-escalation-only-when-ambiguous, always fail-open).
|
|
4
|
+
*
|
|
5
|
+
* Why heuristic-first instead of always asking a model to classify: a classifier
|
|
6
|
+
* call on every turn would burn latency+cost on the common case (most turns are
|
|
7
|
+
* unambiguously trivial or unambiguously routine). The regex heuristic below
|
|
8
|
+
* resolves the vast majority of turns with zero I/O; only genuinely ambiguous
|
|
9
|
+
* prompts (conflicting or absent signals) pay for a cheap escalation call.
|
|
10
|
+
*
|
|
11
|
+
* Why fail-open everywhere: this module runs on EVERY qualifying turn (see
|
|
12
|
+
* launch.ts's `runTurn`). A routing bug or a flaky classifier call must never
|
|
13
|
+
* be able to break a real user turn — every internal step swallows its own
|
|
14
|
+
* failures and falls back to a safe default, and the top-level export wraps
|
|
15
|
+
* everything again as a final backstop.
|
|
16
|
+
*
|
|
17
|
+
* Why no static tier→model map: `resolveTierModel` computes inline off
|
|
18
|
+
* `config.roles`/`config.routing.tiers` so a user who already configured
|
|
19
|
+
* `roles.smol`/`roles.slow` (for `--smol`/`--slow` role-tier resolution
|
|
20
|
+
* elsewhere) gets working routing with zero additional config, and an
|
|
21
|
+
* unconfigured role falls through to `defaultModel` exactly like every other
|
|
22
|
+
* role-tier consumer in this codebase (see `resolveRoleModel`).
|
|
23
|
+
*/
|
|
24
|
+
import { callLlm } from "./loop";
|
|
25
|
+
import { resolveRoleModel } from "../ai/model-manager";
|
|
26
|
+
import { catalogMetadata } from "../ai/model-catalog";
|
|
27
|
+
import { tryExtractJsonObject } from "./json";
|
|
28
|
+
import type { Config } from "./state";
|
|
29
|
+
import type { ThinkLevel } from "../ai/model-catalog";
|
|
30
|
+
|
|
31
|
+
export type PromptTier = "trivial" | "standard" | "complex";
|
|
32
|
+
|
|
33
|
+
export interface HeuristicResult {
|
|
34
|
+
tier: PromptTier;
|
|
35
|
+
confidence: number; // 0..1
|
|
36
|
+
signals: string[]; // fired signal names, e.g. ["short-question","no-code-no-path"]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface RouteDecision {
|
|
40
|
+
model: string;
|
|
41
|
+
thinking?: ThinkLevel; // undefined = do not override the session/global thinking level
|
|
42
|
+
tier: PromptTier;
|
|
43
|
+
confidence: number;
|
|
44
|
+
source: "heuristic" | "llm";
|
|
45
|
+
signals: string[];
|
|
46
|
+
/** Present only on the "smol role not configured" first-occurrence case — see warnOnce below. */
|
|
47
|
+
warning?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface RoutePromptOptions {
|
|
51
|
+
hasImages?: boolean;
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// --- Frozen, bilingual-validated classification signals (do not re-derive). ---
|
|
56
|
+
|
|
57
|
+
const RE_CAUSAL = /\b(why|how|root cause|how come)\b/i;
|
|
58
|
+
const RE_CAUSAL_KR = /(왜\s|근본\s*원인|이유가|어떻게)/;
|
|
59
|
+
const RE_TRIVIAL_QUESTION_WORD = /\b(what|who|when|where|which)\b/i;
|
|
60
|
+
const RE_TRIVIAL_QUESTION_WORD_KR = /(뭐|뭔가요|무엇|언제|어디|누구|몇\s|인가요|있나요)/;
|
|
61
|
+
const RE_CODE_FENCE = /```/;
|
|
62
|
+
const RE_PATH_TOKEN = /(?:^|[\s"'`(])@?(?:\.{0,2}[\w-]*\/)+[\w-]+(?:\.[\w-]+)*\.[A-Za-z]\w{0,7}\b/g;
|
|
63
|
+
const RE_DEEP_KEYWORDS_EN = /\b(design|architecture|refactor|debug|deep\s*dive|investigate|diagnose|redesign)\b/i;
|
|
64
|
+
const RE_DEEP_KEYWORDS_KR = /(설계|아키텍처|리팩터|디버그|딥\s*다이브|딥다이브|진단)/;
|
|
65
|
+
const RE_SENTENCE_BOUNDARY = /[.!?][ \n]|[.!?]$/g;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Pure, synchronous, zero-I/O prompt classification. Every branch and threshold
|
|
69
|
+
* here is frozen per the PromptRouter contract (validated against a 17+-case
|
|
70
|
+
* bilingual corpus) — in particular: a causal ("why"/"how"/"왜"/"어떻게") question
|
|
71
|
+
* is NEVER treated as trivial just because it's short and question-shaped (a
|
|
72
|
+
* debugging question is the opposite of trivial), and the path-token regex is
|
|
73
|
+
* anchored so numeric fractions like "3/4.5" or "10/10" never false-positive as
|
|
74
|
+
* a file path (the trailing segment must end in a letter-led extension).
|
|
75
|
+
*/
|
|
76
|
+
export function classifyPromptHeuristically(prompt: string): HeuristicResult {
|
|
77
|
+
const trimmed = prompt.trim();
|
|
78
|
+
const signals: string[] = [];
|
|
79
|
+
let trivialScore = 0;
|
|
80
|
+
let complexScore = 0;
|
|
81
|
+
|
|
82
|
+
const isCausal = RE_CAUSAL.test(trimmed) || RE_CAUSAL_KR.test(trimmed);
|
|
83
|
+
|
|
84
|
+
// trivial signal 1: short AND a factual-lookup-shaped question (never for a causal question).
|
|
85
|
+
const isShort = trimmed.length < 40;
|
|
86
|
+
const looksLikeFactualQuestion =
|
|
87
|
+
!isCausal &&
|
|
88
|
+
(trimmed.includes("?") || RE_TRIVIAL_QUESTION_WORD.test(trimmed) || RE_TRIVIAL_QUESTION_WORD_KR.test(trimmed));
|
|
89
|
+
if (isShort && looksLikeFactualQuestion) {
|
|
90
|
+
trivialScore++;
|
|
91
|
+
signals.push("short-question");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// trivial signal 2: no code fence AND no file path mention.
|
|
95
|
+
const hasCodeFence = RE_CODE_FENCE.test(trimmed);
|
|
96
|
+
const pathMatches = [...trimmed.matchAll(RE_PATH_TOKEN)];
|
|
97
|
+
if (!hasCodeFence && pathMatches.length === 0) {
|
|
98
|
+
trivialScore++;
|
|
99
|
+
signals.push("no-code-no-path");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// complex signal 1: deep-work keyword.
|
|
103
|
+
if (RE_DEEP_KEYWORDS_EN.test(trimmed) || RE_DEEP_KEYWORDS_KR.test(trimmed)) {
|
|
104
|
+
complexScore++;
|
|
105
|
+
signals.push("deep-work-keyword");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// complex signal 1b: causal/debugging question.
|
|
109
|
+
if (isCausal) {
|
|
110
|
+
complexScore++;
|
|
111
|
+
signals.push("causal-question");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// complex signal 2: long or multi-sentence.
|
|
115
|
+
const questionMarkCount = (trimmed.match(/\?/g) ?? []).length;
|
|
116
|
+
const sentenceCount = (trimmed.match(RE_SENTENCE_BOUNDARY) ?? []).length;
|
|
117
|
+
if (trimmed.length >= 200 || questionMarkCount >= 2 || sentenceCount >= 3) {
|
|
118
|
+
complexScore++;
|
|
119
|
+
signals.push("long-or-multi-sentence");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// complex signal 3: multiple distinct file mentions.
|
|
123
|
+
const distinctPaths = new Set(pathMatches.map(m => m[0].trim()));
|
|
124
|
+
if (distinctPaths.size >= 2) {
|
|
125
|
+
complexScore++;
|
|
126
|
+
signals.push("multi-file");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Tier + confidence resolution (frozen thresholds).
|
|
130
|
+
if (trivialScore > 0 && complexScore > 0) {
|
|
131
|
+
return { tier: "standard", confidence: 0.35, signals }; // conflicting signals -> let escalation decide
|
|
132
|
+
}
|
|
133
|
+
if (complexScore >= 2) return { tier: "complex", confidence: 0.85, signals };
|
|
134
|
+
if (complexScore === 1) return { tier: "complex", confidence: 0.65, signals };
|
|
135
|
+
if (trivialScore >= 2) return { tier: "trivial", confidence: 0.85, signals };
|
|
136
|
+
if (trivialScore === 1) return { tier: "trivial", confidence: 0.65, signals };
|
|
137
|
+
return { tier: "standard", confidence: 0.9, signals }; // no signals at all -> common case, high confidence
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// --- warnOnce: module-level one-time warning surface (no existing helper for this). ---
|
|
141
|
+
|
|
142
|
+
const warnedKeys = new Set<string>();
|
|
143
|
+
|
|
144
|
+
/** Returns `message` the first time `key` is seen in this process, `undefined` every
|
|
145
|
+
* time after — lets a fail-open path surface a diagnostic exactly once instead of
|
|
146
|
+
* spamming it on every qualifying turn. */
|
|
147
|
+
export function warnOnce(key: string, message: string): string | undefined {
|
|
148
|
+
if (warnedKeys.has(key)) return undefined;
|
|
149
|
+
warnedKeys.add(key);
|
|
150
|
+
return message;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Test-only: clear warned-once state between test cases (mirrors
|
|
154
|
+
* src/tui/components/color.ts's resetAppearanceCache pattern). */
|
|
155
|
+
export function resetPromptRouterWarnings(): void {
|
|
156
|
+
warnedKeys.clear();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// --- Tier -> model/thinking resolution (inline off config.roles/config.routing.tiers; no static map). ---
|
|
160
|
+
|
|
161
|
+
function resolveTierModel(tier: PromptTier, config: Pick<Config, "defaultModel" | "roles" | "routing">): string {
|
|
162
|
+
const configured = config.routing?.tiers?.[tier]?.model;
|
|
163
|
+
if (configured) return configured;
|
|
164
|
+
if (tier === "trivial") return config.roles?.smol || config.defaultModel;
|
|
165
|
+
if (tier === "complex") return config.roles?.slow || config.defaultModel;
|
|
166
|
+
return config.defaultModel; // "standard" always falls through to defaultModel unless explicitly configured
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function resolveTierThinking(tier: PromptTier, config: Pick<Config, "defaultModel" | "roles" | "routing">): ThinkLevel | undefined {
|
|
170
|
+
return config.routing?.tiers?.[tier]?.thinking; // undefined = no override, caller keeps session/global level
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const VALID_TIERS: readonly PromptTier[] = ["trivial", "standard", "complex"];
|
|
174
|
+
function isPromptTier(value: unknown): value is PromptTier {
|
|
175
|
+
return typeof value === "string" && (VALID_TIERS as readonly string[]).includes(value);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Hard cap on how much of the prompt is embedded in the escalation classifier call —
|
|
179
|
+
* never send megabytes of user text to a cheap classifier model. */
|
|
180
|
+
const ESCALATION_PROMPT_CHAR_CAP = 2000;
|
|
181
|
+
|
|
182
|
+
function buildClassifierPrompt(prompt: string): string {
|
|
183
|
+
const capped = prompt.length > ESCALATION_PROMPT_CHAR_CAP ? prompt.slice(0, ESCALATION_PROMPT_CHAR_CAP) : prompt;
|
|
184
|
+
return (
|
|
185
|
+
`Classify the complexity of the following user request for a coding assistant into exactly one ` +
|
|
186
|
+
`tier: "trivial" (a quick factual lookup, no repo work), "standard" (routine coding/editing work), ` +
|
|
187
|
+
`or "complex" (multi-file, architectural, or root-cause debugging work). ` +
|
|
188
|
+
`Respond with ONLY a JSON object of the shape {"tier":"trivial"|"standard"|"complex"}.\n\n` +
|
|
189
|
+
`Request:\n${capped}`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Attempt LLM-based re-classification for an ambiguous heuristic result. Fail-open:
|
|
194
|
+
* ANY failure (throw, abort/timeout, malformed JSON, invalid tier value) resolves to
|
|
195
|
+
* `undefined` so the caller falls back to the heuristic tier silently. */
|
|
196
|
+
async function escalateToLlm(prompt: string, smolModel: string, signal: AbortSignal | undefined): Promise<PromptTier | undefined> {
|
|
197
|
+
try {
|
|
198
|
+
const raw = await callLlm([{ role: "user", content: buildClassifierPrompt(prompt) }], {
|
|
199
|
+
model: smolModel,
|
|
200
|
+
jsonMode: true,
|
|
201
|
+
maxTokens: 200,
|
|
202
|
+
signal,
|
|
203
|
+
});
|
|
204
|
+
const parsed = tryExtractJsonObject<{ tier?: unknown }>(raw);
|
|
205
|
+
if (parsed && isPromptTier(parsed.tier)) return parsed.tier;
|
|
206
|
+
return undefined;
|
|
207
|
+
} catch {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Stable key for the one-time "escalation skipped, roles.smol unconfigured" notice. */
|
|
213
|
+
const SMOL_UNCONFIGURED_WARNING_KEY = "prompt-router:smol-unconfigured";
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Route a single turn's prompt to a tier-appropriate model. Heuristic-first: only
|
|
217
|
+
* escalates to a real LLM call when the heuristic's confidence is below
|
|
218
|
+
* `config.routing?.confidenceThreshold` (default 0.6). Returns `null` (never
|
|
219
|
+
* throws) when routing should not override the caller's own already-computed
|
|
220
|
+
* model — either because of an unexpected internal failure (defensive backstop;
|
|
221
|
+
* every internal step already fails open on its own) or because the resolved
|
|
222
|
+
* tier's model lacks image support for an image-bearing turn (the caller must
|
|
223
|
+
* keep whatever multimodal-capable model it already had).
|
|
224
|
+
*/
|
|
225
|
+
export async function routePrompt(
|
|
226
|
+
prompt: string,
|
|
227
|
+
config: Pick<Config, "defaultModel" | "roles" | "routing">,
|
|
228
|
+
opts: RoutePromptOptions = {},
|
|
229
|
+
): Promise<RouteDecision | null> {
|
|
230
|
+
try {
|
|
231
|
+
const heuristic = classifyPromptHeuristically(prompt);
|
|
232
|
+
const threshold = config.routing?.confidenceThreshold ?? 0.6;
|
|
233
|
+
|
|
234
|
+
let tier = heuristic.tier;
|
|
235
|
+
let source: "heuristic" | "llm" = "heuristic";
|
|
236
|
+
let warning: string | undefined;
|
|
237
|
+
|
|
238
|
+
if (heuristic.confidence < threshold) {
|
|
239
|
+
const smolModel = resolveRoleModel("smol", config);
|
|
240
|
+
if (smolModel === config.defaultModel) {
|
|
241
|
+
// roles.smol not configured -> "escalate to a cheap model" would actually call
|
|
242
|
+
// defaultModel (expensive) — the exact paradox the design doc identifies. Skip
|
|
243
|
+
// escalation, keep the heuristic result, and surface a one-time warning.
|
|
244
|
+
warning = warnOnce(
|
|
245
|
+
SMOL_UNCONFIGURED_WARNING_KEY,
|
|
246
|
+
"[route] confidence below threshold but roles.smol is not configured — skipping LLM escalation, using heuristic tier (set roles.smol to enable escalation)",
|
|
247
|
+
);
|
|
248
|
+
} else {
|
|
249
|
+
const escalated = await escalateToLlm(prompt, smolModel, opts.signal);
|
|
250
|
+
if (escalated) {
|
|
251
|
+
tier = escalated;
|
|
252
|
+
source = "llm";
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const model = resolveTierModel(tier, config);
|
|
258
|
+
if (opts.hasImages && catalogMetadata(model)?.images === false) return null;
|
|
259
|
+
|
|
260
|
+
const decision: RouteDecision = {
|
|
261
|
+
model,
|
|
262
|
+
thinking: resolveTierThinking(tier, config),
|
|
263
|
+
tier,
|
|
264
|
+
confidence: heuristic.confidence,
|
|
265
|
+
source,
|
|
266
|
+
signals: heuristic.signals,
|
|
267
|
+
};
|
|
268
|
+
if (warning) decision.warning = warning;
|
|
269
|
+
return decision;
|
|
270
|
+
} catch {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
}
|
package/src/agent/state.ts
CHANGED
|
@@ -122,6 +122,17 @@ export interface Config {
|
|
|
122
122
|
* `defaultModel`. Env `JEO_SMOL_MODEL`/`JEO_SLOW_MODEL`/`JEO_PLAN_MODEL` fill gaps.
|
|
123
123
|
*/
|
|
124
124
|
roles?: { smol?: string; slow?: string; plan?: string };
|
|
125
|
+
/** Prompt-content-based per-turn model routing (PromptRouter) — see prompt-router.ts.
|
|
126
|
+
* Opt-in (undefined/false = off). Never affects subagent/role-tier model resolution. */
|
|
127
|
+
routing?: {
|
|
128
|
+
enabled?: boolean;
|
|
129
|
+
confidenceThreshold?: number;
|
|
130
|
+
tiers?: {
|
|
131
|
+
trivial?: { model?: string; thinking?: "minimal" | "low" | "medium" | "high" | "xhigh" };
|
|
132
|
+
standard?: { model?: string; thinking?: "minimal" | "low" | "medium" | "high" | "xhigh" };
|
|
133
|
+
complex?: { model?: string; thinking?: "minimal" | "low" | "medium" | "high" | "xhigh" };
|
|
134
|
+
};
|
|
135
|
+
};
|
|
125
136
|
gitAutoCommit?: boolean;
|
|
126
137
|
hooks?: HookConfig;
|
|
127
138
|
computer?: {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/route` slash-command handler extracted from launch.ts.
|
|
3
|
+
*
|
|
4
|
+
* Handles `/route [status|on|off|why]` (default/`status`: report the effective
|
|
5
|
+
* session routing state + the last decision, if any; `on`/`off`: toggle a
|
|
6
|
+
* SESSION-LOCAL override of `config.routing.enabled`; `why`: explain the last
|
|
7
|
+
* routing decision in detail). This block shares mutable REPL state
|
|
8
|
+
* (`sessionRouteOverride`, `lastRouteDecision`) with `runTurn`'s own routing
|
|
9
|
+
* insertion, so the caller passes the current values in via an explicit
|
|
10
|
+
* context object and reads back a result object instead of this function
|
|
11
|
+
* closing over REPL state directly.
|
|
12
|
+
*
|
|
13
|
+
* Session-level toggle only — `sessionRouteOverride` is never persisted to
|
|
14
|
+
* `~/.jeo/config.json` (mirrors `/thinking` being session-only vs. `/model
|
|
15
|
+
* save` being the explicit opt-in for persistence). `/route` has no `save`
|
|
16
|
+
* subcommand in v1.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { RouteDecision } from "../../agent/prompt-router";
|
|
20
|
+
|
|
21
|
+
export interface RouteSlashCtx {
|
|
22
|
+
sessionRouteOverride: boolean | undefined;
|
|
23
|
+
/** `turnConfig.routing?.enabled ?? false`, read fresh by the caller. */
|
|
24
|
+
routingConfigEnabled: boolean;
|
|
25
|
+
lastRouteDecision: RouteDecision | { note: string } | null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface RouteSlashResult {
|
|
29
|
+
/** Present only when changed by "on"/"off". */
|
|
30
|
+
sessionRouteOverride?: boolean | undefined;
|
|
31
|
+
/** Lines to print. */
|
|
32
|
+
lines: string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const USAGE = "Usage: /route [status|on|off|why]";
|
|
36
|
+
|
|
37
|
+
function isRealDecision(decision: RouteDecision | { note: string } | null): decision is RouteDecision {
|
|
38
|
+
return !!decision && "model" in decision;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function explainDecision(decision: RouteDecision | { note: string } | null): string[] {
|
|
42
|
+
if (!isRealDecision(decision)) {
|
|
43
|
+
return [decision?.note ?? "No routing decision has been made yet this session."];
|
|
44
|
+
}
|
|
45
|
+
const lines = [
|
|
46
|
+
`tier: ${decision.tier}`,
|
|
47
|
+
`model: ${decision.model}`,
|
|
48
|
+
`source: ${decision.source}`,
|
|
49
|
+
`confidence: ${decision.confidence.toFixed(2)}`,
|
|
50
|
+
`signals: ${decision.signals.join(", ") || "none"}`,
|
|
51
|
+
];
|
|
52
|
+
if (decision.thinking) lines.push(`thinking: ${decision.thinking}`);
|
|
53
|
+
if (decision.warning) lines.push(`warning: ${decision.warning}`);
|
|
54
|
+
return lines;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Handle `/route [status|on|off|why]`. Extracted for the same reason as
|
|
59
|
+
* `/model`: shares REPL-local routing state with `runTurn` via an explicit
|
|
60
|
+
* ctx/result object rather than closing over it.
|
|
61
|
+
*/
|
|
62
|
+
export function runRouteSlash(input: string, ctx: RouteSlashCtx): RouteSlashResult {
|
|
63
|
+
const rest = input.slice("/route".length).trim();
|
|
64
|
+
const [sub] = rest.split(/\s+/).filter(Boolean);
|
|
65
|
+
const effective = ctx.sessionRouteOverride ?? ctx.routingConfigEnabled;
|
|
66
|
+
|
|
67
|
+
if (!sub || sub === "status") {
|
|
68
|
+
const lines = [`routing: ${effective ? "on" : "off"} (this session)`];
|
|
69
|
+
if (isRealDecision(ctx.lastRouteDecision)) {
|
|
70
|
+
lines.push(`last decision: ${ctx.lastRouteDecision.tier} → ${ctx.lastRouteDecision.model} (${ctx.lastRouteDecision.source}: ${ctx.lastRouteDecision.signals.join(", ") || "none"}, confidence ${ctx.lastRouteDecision.confidence.toFixed(2)})`);
|
|
71
|
+
}
|
|
72
|
+
return { lines };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (sub === "on") {
|
|
76
|
+
return { sessionRouteOverride: true, lines: ["routing: on (this session)"] };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (sub === "off") {
|
|
80
|
+
return { sessionRouteOverride: false, lines: ["routing: off (this session)"] };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (sub === "why") {
|
|
84
|
+
return { lines: explainDecision(ctx.lastRouteDecision) };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return { lines: [`Unknown /route subcommand: ${sub}`, USAGE] };
|
|
88
|
+
}
|
package/src/commands/launch.ts
CHANGED
|
@@ -47,6 +47,7 @@ import { rememberModelPatch, recentModelsForDisplay } from "../agent/model-recen
|
|
|
47
47
|
import { describeModel, describeAllProviders, thinkingMaxTokens, resolveMaxOutputTokens, thinkingToReasoningEffort, discoverModels, flattenModels, resolveSelection, catalogMetadata, catalogByProvider, resolveRoleModel, CODEX_MODELS, qualifyModelId } from "../ai";
|
|
48
48
|
import type { ProviderModelsResult, PickEntry, ProviderName, ModelRole, ThinkLevel } from "../ai";
|
|
49
49
|
import { readGoalState, writeGoalState, clearGoalState, verifyGoal } from "../agent/goal-verifier";
|
|
50
|
+
import { routePrompt, type RouteDecision } from "../agent/prompt-router";
|
|
50
51
|
|
|
51
52
|
import { listAliases } from "../ai/model-registry";
|
|
52
53
|
import { openaiCompatDef, SUBSCRIPTION_PROVIDER_NAMES } from "../ai/providers/openai-compatible-catalog";
|
|
@@ -204,6 +205,7 @@ import {
|
|
|
204
205
|
import { handleUndoSlash } from "./launch/git-slash";
|
|
205
206
|
import { runSessionSlash } from "./launch/session-slash";
|
|
206
207
|
import { runModelSlash } from "./launch/model-slash";
|
|
208
|
+
import { runRouteSlash } from "./launch/route-slash";
|
|
207
209
|
import { runAgentsSlash, runRolesSlash, runFastSlash, runThinkingSlash } from "./launch/agents-slash";
|
|
208
210
|
import { wikiRootPromptLine, decideWikiSlash } from "./launch/wiki-slash";
|
|
209
211
|
import { decideThemeSlash, buildConfigPanelLines, runEvolveSimulation } from "./launch/system-slash";
|
|
@@ -642,6 +644,10 @@ export async function runLaunchCommand(args: string[]): Promise<void> {
|
|
|
642
644
|
let sessionModel: string | undefined = initialSessionModel;
|
|
643
645
|
// Session thinking-level override (`/thinking`); falls back to the config level.
|
|
644
646
|
let sessionThinking: "minimal" | "low" | "medium" | "high" | "xhigh" | undefined = flags.thinking ?? cfg.thinkingLevel;
|
|
647
|
+
// PromptRouter session override: undefined = follow config.routing.enabled, true/false = /route on|off wins this session.
|
|
648
|
+
let sessionRouteOverride: boolean | undefined;
|
|
649
|
+
// Last routing decision (or the reason none applied) — /route why reads this.
|
|
650
|
+
let lastRouteDecision: RouteDecision | { note: string } | null = null;
|
|
645
651
|
// Cache of live, credential-validated models per provider (refreshed by live pickers).
|
|
646
652
|
let liveModelsCache: ProviderModelsResult[] | null = null;
|
|
647
653
|
const getLiveModels = async (force = false): Promise<ProviderModelsResult[]> => {
|
|
@@ -844,7 +850,14 @@ export async function runLaunchCommand(args: string[]): Promise<void> {
|
|
|
844
850
|
// global default (rememberModelPatch), so re-reading turnConfig.defaultModel here let
|
|
845
851
|
// that write silently switch THIS running session's model mid-run. Per-session model
|
|
846
852
|
// selection must stay session-local: running sessions never influence each other.
|
|
847
|
-
const
|
|
853
|
+
const routingEnabled = sessionRouteOverride ?? !!turnConfig.routing?.enabled;
|
|
854
|
+
const routed = routingEnabled && !sessionModel
|
|
855
|
+
? await routePrompt(userInput, turnConfig, { hasImages: !!images?.length }).catch(() => null)
|
|
856
|
+
: null;
|
|
857
|
+
lastRouteDecision = routed ?? (routingEnabled && !sessionModel ? { note: "routing produced no decision (fail-open)" } : { note: "routing not active this turn" });
|
|
858
|
+
// Explicit /model always wins: `routed` is only ever computed when `!sessionModel`.
|
|
859
|
+
const activeModel = routed?.model ?? (sessionModel || defaultModel);
|
|
860
|
+
const activeThinking = routed?.thinking ?? sessionThinking;
|
|
848
861
|
const contextTokens = catalogMetadata(activeModel)?.contextTokens;
|
|
849
862
|
|
|
850
863
|
// Resolve provider + dirty count up front — both are cheap and feed the live
|
|
@@ -852,7 +865,16 @@ export async function runLaunchCommand(args: string[]): Promise<void> {
|
|
|
852
865
|
// config file. (gjc parity P1.B5: dirty count per-turn, not per-render.)
|
|
853
866
|
const { provider: activeProvider } = await describeModel(activeModel, turnConfig);
|
|
854
867
|
const turnDirtyCount = branch ? gitDirtyCount(cwd) : undefined;
|
|
855
|
-
const tui = useTui ? new LaunchTui({ model: activeModel, provider: activeProvider, sessionId, maxSteps: initialStepLimit, cwd, branch, dirtyCount: turnDirtyCount, thinking:
|
|
868
|
+
const tui = useTui ? new LaunchTui({ model: activeModel, provider: activeProvider, sessionId, maxSteps: initialStepLimit, cwd, branch, dirtyCount: turnDirtyCount, thinking: activeThinking }) : null;
|
|
869
|
+
if (routed?.warning) {
|
|
870
|
+
if (tui) tui.events().onNotice?.(routed.warning);
|
|
871
|
+
else console.log(routed.warning);
|
|
872
|
+
}
|
|
873
|
+
if (routed && (routed.source === "llm" || routed.tier !== "standard")) {
|
|
874
|
+
const routeNotice = `[route] ${routed.tier} → ${routed.model} (${routed.source}: ${routed.signals.join(", ") || "none"}, confidence ${routed.confidence.toFixed(2)})`;
|
|
875
|
+
if (tui) tui.events().onNotice?.(routeNotice);
|
|
876
|
+
else console.log(routeNotice);
|
|
877
|
+
}
|
|
856
878
|
tui?.setTurnTitle(userInput); // gjc-parity turn title → HUD + tmux pane title (no LLM call)
|
|
857
879
|
// `beforeLen` marks where this turn's appended messages start; it is re-read
|
|
858
880
|
// AFTER compaction (which mutates history) and consumed by the post-turn
|
|
@@ -1134,8 +1156,8 @@ export async function runLaunchCommand(args: string[]): Promise<void> {
|
|
|
1134
1156
|
tools,
|
|
1135
1157
|
maxSteps: flags.maxSteps,
|
|
1136
1158
|
model: activeModel,
|
|
1137
|
-
maxTokens: resolveMaxOutputTokens(activeModel,
|
|
1138
|
-
reasoningEffort:
|
|
1159
|
+
maxTokens: resolveMaxOutputTokens(activeModel, activeThinking),
|
|
1160
|
+
reasoningEffort: activeThinking ? thinkingToReasoningEffort(activeThinking) : undefined,
|
|
1139
1161
|
signal: ac.signal,
|
|
1140
1162
|
sessionKey: sessionId,
|
|
1141
1163
|
steer: drainSteer,
|
|
@@ -1154,8 +1176,8 @@ export async function runLaunchCommand(args: string[]): Promise<void> {
|
|
|
1154
1176
|
maxSteps: Math.min(6, flags.maxSteps > 0 ? flags.maxSteps : 6),
|
|
1155
1177
|
budget: { maxExtensions: 0 },
|
|
1156
1178
|
model: activeModel,
|
|
1157
|
-
maxTokens: resolveMaxOutputTokens(activeModel,
|
|
1158
|
-
reasoningEffort:
|
|
1179
|
+
maxTokens: resolveMaxOutputTokens(activeModel, activeThinking),
|
|
1180
|
+
reasoningEffort: activeThinking ? thinkingToReasoningEffort(activeThinking) : undefined,
|
|
1159
1181
|
signal: ac.signal,
|
|
1160
1182
|
sessionKey: sessionId,
|
|
1161
1183
|
steer: drainSteer,
|
|
@@ -3964,6 +3986,17 @@ export async function runLaunchCommand(args: string[]): Promise<void> {
|
|
|
3964
3986
|
if (modelResult.lastPickIndex !== undefined) lastPickIndex = modelResult.lastPickIndex;
|
|
3965
3987
|
continue;
|
|
3966
3988
|
}
|
|
3989
|
+
if (input.startsWith("/route") && (input === "/route" || input[6] === " ")) {
|
|
3990
|
+
const cfgNow = await readGlobalConfig();
|
|
3991
|
+
const routeResult = runRouteSlash(input, {
|
|
3992
|
+
sessionRouteOverride,
|
|
3993
|
+
routingConfigEnabled: !!cfgNow.routing?.enabled,
|
|
3994
|
+
lastRouteDecision,
|
|
3995
|
+
});
|
|
3996
|
+
if (routeResult.sessionRouteOverride !== undefined) sessionRouteOverride = routeResult.sessionRouteOverride;
|
|
3997
|
+
for (const line of routeResult.lines) console.log(line);
|
|
3998
|
+
continue;
|
|
3999
|
+
}
|
|
3967
4000
|
if (input.startsWith("/view") && (input === "/view" || input[5] === " ")) {
|
|
3968
4001
|
for (const line of await handleViewSlash(input, cwd)) console.log(line);
|
|
3969
4002
|
continue;
|
|
@@ -43,6 +43,7 @@ export const SLASH_COMMAND_DETAILS: readonly SlashCommandInfo[] = [
|
|
|
43
43
|
{ command: "/logout", usage: "/logout <anthropic|openai|gemini|antigravity>", description: "Remove the stored OAuth token for a provider", group: "models" },
|
|
44
44
|
{ command: "/roles", usage: "/roles [tier model]", description: "Show or set model role tiers (smol/slow/plan)", group: "models" },
|
|
45
45
|
{ command: "/thinking", usage: "/thinking [level]", description: "Show or set thinking budget (minimal/low/medium/high/xhigh)", group: "models" },
|
|
46
|
+
{ command: "/route", usage: "/route [on|off|why]", description: "Show/toggle prompt-based model routing for this session, or explain the last routing decision", group: "models" },
|
|
46
47
|
{ command: "/agents", usage: "/agents [edit|role] [model|#N|thinking L|maxSteps N|reset]", description: "List subagent roles; use /agents edit for the interactive picker or pin role model/settings", group: "subagents" },
|
|
47
48
|
{ command: "/subagent", usage: "/subagent [role]", description: "Show the current subagent composition (per-role model · thinking · steps); alias of /agents", group: "subagents" },
|
|
48
49
|
{ command: "/view", usage: "/view <file> [a-b]", description: "Render a file with line numbers + light highlight", group: "code" },
|