TypeScript
Add an interactive session with a unified slash interface
Claude82f010478561
diff --git a/NOTES.md b/NOTES.mdindex a001bc1..6cd2dbe 100644--- a/NOTES.md+++ b/NOTES.md@@ -2,6 +2,20 @@비전문 감시자용 기록. 용어 최소화, AS-IS → TO-BE.+## 2026-06-30 (3) — 인터랙티브 세션(통일된 슬래시 인터페이스)++**AS-IS**: 매번 긴 플래그를 외워 한 줄로 쳐야 했다. `theseus` 만 치면 "모델 미지정" 에러.++**TO-BE**: `theseus` 를 인자 없이 치면 **세션(REPL)** 이 열린다 — `claude`/`codex` 처럼.+- **목표 우선**: 자유 입력은 목표(goal)에 누적, `/goal` 로 명시 설정.+- **기능마다 슬래시 하나로 통일**: `/models` `/agents` `/harness` `/bench`(인자 없으면 목록·있으면 선택),+ `/runs` `/tasks` `/seed` `/runner` `/judge` `/score` `/lang`, 실행 `/run`, 시각화 `/view`,+ 점검 `/config` `/clear` `/help` `/exit`. 프롬프트에 현재 `[m×a×h]` 표시.+- `/run` → 결정지표 표(정확도·일관성·$/solved·시간) + 관점별 승자 + report 경로. `/view` → 갤러리 서버.+- 구현: 순수 `reduce()`(동기 명령) + readline 라인-큐 루프(TTY·파이프 모두 안정). `theseus session`(별칭+ `chat`/`repl`) 으로 명시 실행도. 비대화형(CI/파이프 무인자)은 기존 도움말로 폴백.+- 테스트 10개 추가(reduce 검증), 총 69 통과.+## 2026-06-30 (2) — 사용자 관점 지표(일관성·해결당 비용)**AS-IS**: 모든 지표를 동급으로 나열 — 서브에이전트·툴콜·토큰 같은 *진단* 지표가 헤드라인을 차지하고,diff --git a/README.ja.md b/README.ja.mdindex 5041138..fcaa1f9 100644--- a/README.ja.md+++ b/README.ja.md@@ -129,9 +129,35 @@ theseus --model opus4.8,gpt5.5 --agent cc,opencode,codex \非互換の組み合わせは **理由付きで除外** される(黙って捨てない)。+## インタラクティブセッション++引数なしで `theseus` を実行するとセッションが開く — `claude`/`codex` のように。目標を自由に入力し、+機能ごとに統一されたスラッシュコマンドで設定して `/run`:++```text+$ theseus+theseus [1m×1a×1h] ▸ cc と opencode をフレーキーなバグで比較+theseus [1m×1a×1h] ▸ /agents cc,opencode+theseus [2m×2a×1h] ▸ /models opus4.8,gpt5.5+theseus [2m×2a×1h] ▸ /run # → 決定テーブル + report.html+theseus [2m×2a×1h] ▸ /view # → 記録された全トレースを localhost で配信+theseus [2m×2a×1h] ▸ /exit+```++| コマンド | 説明 |+| --- | --- |+| 自由入力 · `/goal <text>` | 達成したい目標(自由入力は目標に蓄積) |+| `/models` `/agents` `/harness` `/bench` | L0×L1×L2 — 引数なしで一覧、引数ありで選択 |+| `/runs` `/tasks` `/seed` `/runner` `/judge` `/score` `/lang` | スイープのパラメータ |+| `/run` · `/view [open]` · `/config` `/clear` `/help` `/exit` | 実行 · 可視化 · 確認/リセット/ヘルプ/終了 |++明示的には `theseus session`(別名:`chat`, `repl`)。同じ操作はスクリプト用のワンショットフラグでも使える(下記)。+## コマンド```bash+theseus # インタラクティブセッション(スラッシュ)+theseus session | chat | repl # 同上(明示的)theseus [compare] --model … --agent … --harness … # 既定コマンドtheseus verify --model … --agent … --harness … # 組合せごとのサブエージェント呼び出し捕捉チェックtheseus results [--run <id>] # 記録済み run を表示diff --git a/README.ko.md b/README.ko.mdindex 48258a1..582f5e9 100644--- a/README.ko.md+++ b/README.ko.md@@ -128,9 +128,35 @@ theseus --model opus4.8,gpt5.5 --agent cc,opencode,codex \비호환 조합은 **사유와 함께 제외**된다(조용히 버리지 않음).+## 인터랙티브 세션++인자 없이 `theseus` 를 치면 세션이 열린다 — `claude`/`codex` 처럼. 목표를 자유롭게 입력하고,+기능마다 하나로 통일된 슬래시 명령으로 설정한 뒤 `/run`:++```text+$ theseus+theseus [1m×1a×1h] ▸ cc 와 opencode 를 플레이키 버그로 비교+theseus [1m×1a×1h] ▸ /agents cc,opencode+theseus [2m×2a×1h] ▸ /models opus4.8,gpt5.5+theseus [2m×2a×1h] ▸ /run # → 결정 표 + report.html+theseus [2m×2a×1h] ▸ /view # → 기록된 모든 트레이스를 localhost 에 서빙+theseus [2m×2a×1h] ▸ /exit+```++| 명령 | 설명 |+| --- | --- |+| 자유 입력 · `/goal <text>` | 달성하려는 목표(자유 입력은 목표에 누적) |+| `/models` `/agents` `/harness` `/bench` | L0×L1×L2 — 인자 없으면 목록, 있으면 선택 |+| `/runs` `/tasks` `/seed` `/runner` `/judge` `/score` `/lang` | 스윕 파라미터 |+| `/run` · `/view [open]` · `/config` `/clear` `/help` `/exit` | 실행 · 시각화 · 점검/리셋/도움말/종료 |++명시적으로는 `theseus session`(별칭: `chat`, `repl`). 같은 동작을 스크립트용 일회성 플래그로도 쓸 수 있다(아래).+## 명령어```bash+theseus # 인터랙티브 세션(슬래시 명령)+theseus session | chat | repl # 동일(명시적)theseus [compare] --model … --agent … --harness … # 기본 명령theseus verify --model … --agent … --harness … # 조합별 서브에이전트 콜 포착 점검theseus results [--run <id>] # 기록된 run 보기diff --git a/README.md b/README.mdindex ed00dcf..83efbbd 100644--- a/README.md+++ b/README.md@@ -130,9 +130,40 @@ omitted. (`cc` stays claude-only, `codex` gpt-only.)Incompatible combos are **excluded with a reason** (never silently dropped).+## Interactive session++Type `theseus` with no arguments and an interactive session opens — like `claude` or `codex`.+Describe your goal in plain text, then configure the run with one unified slash command per feature,+and `/run`:++```text+$ theseus+theseus [1m×1a×1h] ▸ compare cc vs opencode on a flaky bug+theseus [1m×1a×1h] ▸ /agents cc,opencode+theseus [2m×1a×1h] ▸ /models opus4.8,gpt5.5+theseus [2m×2a×1h] ▸ /runner mock+theseus [2m×2a×1h] ▸ /run # → decision table + report.html+theseus [2m×2a×1h] ▸ /view # → serve every recorded trace at localhost+theseus [2m×2a×1h] ▸ /exit+```++| command | what it does |+| --- | --- |+| plain text · `/goal <text>` | what you want to achieve (plain text accumulates into the goal) |+| `/models` `/agents` `/harness` `/bench` | the L0×L1×L2 matrix — bare command lists, with args selects |+| `/runs` `/tasks` `/seed` `/runner` `/judge` `/score` `/lang` | sweep parameters |+| `/run` | run the comparison with the current selection |+| `/view [open]` | serve every recorded trace at localhost |+| `/config` `/clear` `/help` `/exit` | inspect · reset · help · quit |++Start it explicitly with `theseus session` (aliases: `chat`, `repl`). The same actions are available as+one-shot flags for scripting — see below.+## Commands```bash+theseus # interactive session (slash commands)+theseus session | chat | repl # same, explicittheseus [compare] --model … --agent … --harness … # default commandtheseus verify --model … --agent … --harness … # per-combo subagent-call capture checktheseus results [--run <id>] # show a recorded rundiff --git a/README.zh.md b/README.zh.mdindex 2988e60..7f91297 100644--- a/README.zh.md+++ b/README.zh.md@@ -126,9 +126,35 @@ theseus --model opus4.8,gpt5.5 --agent cc,opencode,codex \不兼容的组合会 **附带理由被排除**(绝不静默丢弃)。+## 交互式会话++不带参数运行 `theseus` 即可打开会话 —— 就像 `claude`/`codex`。用自然语言描述目标,+再用每个功能统一的斜杠命令进行配置,然后 `/run`:++```text+$ theseus+theseus [1m×1a×1h] ▸ 在一个不稳定的 bug 上比较 cc 与 opencode+theseus [1m×1a×1h] ▸ /agents cc,opencode+theseus [2m×2a×1h] ▸ /models opus4.8,gpt5.5+theseus [2m×2a×1h] ▸ /run # → 决策表 + report.html+theseus [2m×2a×1h] ▸ /view # → 在 localhost 上服务所有已记录的轨迹+theseus [2m×2a×1h] ▸ /exit+```++| 命令 | 说明 |+| --- | --- |+| 自然语言 · `/goal <text>` | 你想达成的目标(自然语言会累加到目标) |+| `/models` `/agents` `/harness` `/bench` | L0×L1×L2 —— 无参数列出,有参数选择 |+| `/runs` `/tasks` `/seed` `/runner` `/judge` `/score` `/lang` | 扫描参数 |+| `/run` · `/view [open]` · `/config` `/clear` `/help` `/exit` | 运行 · 可视化 · 查看/重置/帮助/退出 |++也可显式使用 `theseus session`(别名:`chat`、`repl`)。同样的操作也有一次性命令行标志,便于脚本化(见下)。+## 命令```bash+theseus # 交互式会话(斜杠命令)+theseus session | chat | repl # 同上(显式)theseus [compare] --model … --agent … --harness … # 默认命令theseus verify --model … --agent … --harness … # 逐组合的子智能体调用捕获检查theseus results [--run <id>] # 查看已记录的运行diff --git a/src/cli.ts b/src/cli.tsindex bd4cc83..e227ac5 100644--- a/src/cli.ts+++ b/src/cli.ts@@ -20,6 +20,7 @@ import { analyze } from "./preflight";import { listRuns, loadMeta, loadResults } from "./recorder";import { getRunner } from "./runners/registry";import { commandExists } from "./runners/util";+import { runSession } from "./session";import { runTui } from "./tui";import { verifyCombos } from "./verify";import { openInBrowser, openUrl } from "./viz/open";@@ -229,6 +230,14 @@ function buildProgram(): Command {program.command("compare", { isDefault: true }).description("run an N-combo comparison"),).action(compareAction);+ program+ .command("session", { isDefault: false })+ .aliases(["chat", "repl"])+ .description("open an interactive session — slash commands to configure & run")+ .option("--out <dir>", "output dir", "runs")+ .option("-L, --language <lang>", "en|kr", "kr")+ .action((o) => runSession({ language: normalizeLang(o.language), outDir: o.out ?? "runs" }));+program.command("results").description("show recorded results")@@ -396,6 +405,11 @@ function buildProgram(): Command {}export async function main(argv = process.argv): Promise<void> {+ // 인자 없이 `theseus` → 인터랙티브 세션(claude/codex 처럼). 비대화형(파이프/CI)은 기존 도움말.+ if (argv.slice(2).length === 0 && process.stdin.isTTY) {+ await runSession({ language: "kr", outDir: "runs" });+ return;+ }await buildProgram().parseAsync(argv);}diff --git a/src/session.ts b/src/session.tsnew file mode 100644index 0000000..98235d8--- /dev/null+++ b/src/session.ts@@ -0,0 +1,458 @@+/**+ * 인터랙티브 세션 (REPL) — `theseus` 를 인자 없이 치면 열린다(claude/codex 처럼).+ *+ * 통일된 슬래시 인터페이스: 기능마다 `/<feature>` 하나.+ * /goal <text> 달성하려는 목표(자유 입력도 목표에 누적)+ * /models /agents /harness /bench 선택(L0×L1×L2) — 인자 없으면 목록, 있으면 설정+ * /runs /tasks /runner /seed /judge /score /lang 파라미터+ * /run 현재 선택으로 비교 실행 → 표 + report 경로+ * /view 기록된 모든 트레이스를 localhost 갤러리로+ * /config /help /clear /exit+ *+ * reduce() 는 순수 함수(동기 명령 = 상태 변경/출력). /run·/view·/results·/exit 은+ * 비동기 액션으로 분리해 루프에서 처리 → 테스트 가능.+ */+import * as readline from "node:readline";+import Table from "cli-table3";+import pc from "picocolors";+import { listLocalBenches } from "./benches/index";+import { logoBanner } from "./brand";+import { expand } from "./combos";+import { AGENTS, HARNESSES, MODELS, isKnownModel } from "./config";+import { type Translator, normalizeLang, translator } from "./i18n";+import { type aggregateAll, bestByPerspective, sortCombos } from "./metrics";+import type { Lang, RunOptions, ViewMode } from "./models";+import { execute } from "./orchestrator";+import { analyze } from "./preflight";+import { listRuns } from "./recorder";+import { openUrl } from "./viz/open";+import { serveRuns } from "./viz/serve";++export interface SessionState {+ goal: string;+ models: string[];+ agents: string[];+ harnesses: string[];+ bench: string;+ tasks: number;+ runs: number;+ seed: number;+ runner: string;+ judge: string;+ score: boolean;+ view: ViewMode;+ language: Lang;+ outDir: string;+ port: number;+}++export type Action =+ | { kind: "none" }+ | { kind: "run" }+ | { kind: "view"; open: boolean }+ | { kind: "results" }+ | { kind: "exit" };++export interface Reduced {+ state: SessionState;+ lines: string[];+ action: Action;+}++export function defaultState(language: Lang, outDir: string): SessionState {+ return {+ goal: "",+ models: ["opus4.8"],+ agents: ["cc"],+ harnesses: ["none"],+ bench: "subagent",+ tasks: 6,+ runs: 2,+ seed: 0,+ runner: "auto",+ judge: "none",+ score: false,+ view: "inline",+ language,+ outDir,+ port: 7777,+ };+}++const splitList = (s: string): string[] =>+ s+ .split(/[\s,]+/)+ .map((x) => x.trim())+ .filter(Boolean);++const knownModel = (m: string): boolean => isKnownModel(m) || m.includes("/");++/** L0 모델 목록(family 별), 현재 선택 ● 표시. */+function listModels(state: SessionState): string[] {+ const byFam: Record<string, string[]> = { claude: [], gpt: [], open: [] };+ for (const [alias, def] of Object.entries(MODELS)) byFam[def.family]?.push(alias);+ const sel = new Set(state.models);+ const out = ["available L0 models — /models <a,b,…> to select:"];+ for (const fam of ["claude", "gpt", "open"]) {+ const items = byFam[fam]!.map((a) => (sel.has(a) ? pc.green(`●${a}`) : pc.dim(`○${a}`))).join(+ " ",+ );+ out.push(` ${pc.bold(fam)}: ${items}`);+ }+ out.push(pc.dim(" (open = OpenRouter, multi-model agents only; ':free' = $0)"));+ return out;+}++function listOf(title: string, keys: string[], sel: string[], hint: string): string[] {+ const set = new Set(sel);+ const items = keys.map((k) => (set.has(k) ? pc.green(`●${k}`) : pc.dim(`○${k}`))).join(" ");+ return [`${title} — ${hint}:`, ` ${items}`];+}++/** 인자 없으면 목록, 있으면 검증 후 설정. 미지(unknown)는 경고하고 건너뜀. */+function setSelection(+ raw: string,+ current: string[],+ valid: (x: string) => boolean,+ label: string,+): { value: string[]; lines: string[] } {+ const items = splitList(raw);+ const ok = items.filter(valid);+ const bad = items.filter((x) => !valid(x));+ const lines: string[] = [];+ if (bad.length) lines.push(pc.yellow(` unknown ${label}: ${bad.join(", ")} (ignored)`));+ if (!ok.length) {+ lines.push(pc.red(` no valid ${label} given — keeping ${current.join(", ") || "—"}`));+ return { value: current, lines };+ }+ lines.push(` ${label}: ${pc.green(ok.join(", "))}`);+ return { value: ok, lines };+}++function configLines(state: SessionState): string[] {+ const { valid, excluded } = expand(state.models, state.agents, state.harnesses);+ const lines = [+ pc.bold("current plan"),+ ` goal : ${state.goal ? pc.cyan(state.goal) : pc.dim("(none — type it, or /goal <text>)")}`,+ ` models : ${state.models.join(", ")}`,+ ` agents : ${state.agents.join(", ")}`,+ ` harness : ${state.harnesses.join(", ")}`,+ ` bench : ${state.bench} tasks: ${state.tasks} runs: ${state.runs} seed: ${state.seed}`,+ ` runner : ${state.runner} judge: ${state.judge} score: ${state.score} lang: ${state.language}`,+ ` combos : ${pc.green(`${valid.length} valid`)}${+ excluded.length ? pc.yellow(` · ${excluded.length} excluded`) : ""+ }`,+ ];+ for (const c of valid) lines.push(pc.dim(` ✓ ${c.comboId}`));+ for (const c of excluded) lines.push(pc.dim(` ✗ ${c.comboId} — ${c.excludeReason}`));+ return lines;+}++const HELP = [+ pc.bold("commands") + pc.dim(" (each feature = one slash; bare command shows current)"),+ ` ${pc.cyan("/goal")} <text> what you want to achieve (plain text also appends)`,+ ` ${pc.cyan("/models")} <a,b,…> L0 — select models`,+ ` ${pc.cyan("/agents")} <a,b,…> L1 — cc,codex,opencode,openclaw,hermes`,+ ` ${pc.cyan("/harness")} <a,b,…> L2 — none,superpowers,omc,ecc,omx,lazycodex,omo,ponytail,mattpocock`,+ ` ${pc.cyan("/bench")} <name> ${listLocalBenches().join(",")} | terminal-bench-v2`,+ ` ${pc.cyan("/runs")} ${pc.cyan("/tasks")} ${pc.cyan("/seed")} <n> sweep size`,+ ` ${pc.cyan("/runner")} <name> auto|mock|cc|codex|opencode|openclaw|hermes|tb`,+ ` ${pc.cyan("/judge")} <name> ${pc.cyan("/score")} on|off ${pc.cyan("/lang")} en|kr`,+ ` ${pc.cyan("/run")} run the comparison → table + report.html`,+ ` ${pc.cyan("/view")} [open] serve every recorded trace at localhost`,+ ` ${pc.cyan("/config")} ${pc.cyan("/clear")} ${pc.cyan("/help")} ${pc.cyan("/exit")}`,+];++/** 순수 reducer — 한 줄 입력 → 새 상태 + 출력 + (비동기) 액션. */+export function reduce(prev: SessionState, raw: string): Reduced {+ const line = raw.trim();+ const state = { ...prev };+ const lines: string[] = [];+ const none = (): Reduced => ({ state, lines, action: { kind: "none" } });++ if (!line) return none();++ // 자유 입력 = 목표 누적+ if (!line.startsWith("/")) {+ state.goal = state.goal ? `${state.goal} ${line}` : line;+ lines.push(pc.dim(` goal ▸ ${state.goal}`));+ return none();+ }++ const [cmd, ...rest] = line.split(/\s+/);+ const arg = rest.join(" ").trim();++ switch (cmd) {+ case "/help":+ case "/?":+ lines.push(...HELP);+ return none();+ case "/config":+ case "/show":+ lines.push(...configLines(state));+ return none();+ case "/goal":+ if (!arg) lines.push(` goal: ${state.goal ? pc.cyan(state.goal) : pc.dim("(none)")}`);+ else if (arg === "clear") {+ state.goal = "";+ lines.push(pc.dim(" goal cleared"));+ } else {+ state.goal = arg;+ lines.push(` goal ▸ ${pc.cyan(state.goal)}`);+ }+ return none();+ case "/models": {+ if (!arg) {+ lines.push(...listModels(state));+ return none();+ }+ const r = setSelection(arg, state.models, knownModel, "models");+ state.models = r.value;+ lines.push(...r.lines);+ return none();+ }+ case "/agents": {+ if (!arg) {+ lines.push(...listOf("L1 agents", Object.keys(AGENTS), state.agents, "/agents <a,b,…>"));+ return none();+ }+ const r = setSelection(arg, state.agents, (x) => x in AGENTS, "agents");+ state.agents = r.value;+ lines.push(...r.lines);+ return none();+ }+ case "/harness": {+ if (!arg) {+ lines.push(+ ...listOf("L2 harnesses", Object.keys(HARNESSES), state.harnesses, "/harness <a,b,…>"),+ );+ return none();+ }+ const r = setSelection(arg, state.harnesses, (x) => x in HARNESSES, "harnesses");+ state.harnesses = r.value;+ lines.push(...r.lines);+ return none();+ }+ case "/bench":+ if (!arg) lines.push(` bench: ${state.bench} (${listLocalBenches().join(", ")})`);+ else {+ state.bench = arg;+ lines.push(` bench: ${pc.green(arg)}`);+ }+ return none();+ case "/runs":+ case "/tasks":+ case "/seed": {+ const key = cmd.slice(1) as "runs" | "tasks" | "seed";+ const n = Number.parseInt(arg, 10);+ if (Number.isFinite(n) && n >= 0) {+ state[key] = n;+ lines.push(` ${key}: ${pc.green(String(n))}`);+ } else lines.push(` ${key}: ${state[key]}`);+ return none();+ }+ case "/runner":+ if (arg) {+ state.runner = arg;+ lines.push(` runner: ${pc.green(arg)}`);+ } else lines.push(` runner: ${state.runner}`);+ return none();+ case "/judge":+ if (arg) {+ state.judge = arg;+ lines.push(` judge: ${pc.green(arg)}`);+ } else lines.push(` judge: ${state.judge}`);+ return none();+ case "/score":+ state.score = arg ? /^(on|true|yes|1)$/i.test(arg) : !state.score;+ lines.push(` score: ${pc.green(String(state.score))}`);+ return none();+ case "/lang":+ state.language = normalizeLang(arg || state.language);+ lines.push(` lang: ${pc.green(state.language)}`);+ return none();+ case "/clear": {+ const fresh = defaultState(state.language, state.outDir);+ lines.push(pc.dim(" selection reset to defaults"));+ return { state: fresh, lines, action: { kind: "none" } };+ }+ case "/run":+ case "/go":+ return { state, lines, action: { kind: "run" } };+ case "/view":+ case "/visualize":+ return { state, lines, action: { kind: "view", open: /open/i.test(arg) } };+ case "/results":+ return { state, lines, action: { kind: "results" } };+ case "/exit":+ case "/quit":+ case "/q":+ return { state, lines, action: { kind: "exit" } };+ default:+ lines.push(pc.yellow(` unknown command ${cmd} — /help`));+ return none();+ }+}++// ── 비동기 액션 ──────────────────────────────────────────+function toRunOptions(s: SessionState): RunOptions {+ return {+ models: s.models,+ agents: s.agents,+ harnesses: s.harnesses.length ? s.harnesses : ["none"],+ bench: s.bench,+ tasks: s.tasks,+ runs: s.runs,+ seed: s.seed,+ runner: s.runner,+ concurrency: 4,+ timeoutS: 600,+ outDir: s.outDir,+ judge: s.judge,+ score: s.score,+ balanced: false,+ language: s.language,+ view: "inline",+ port: s.port,+ };+}++function resultsTable(metrics: ReturnType<typeof aggregateAll>, lang: Lang, t: Translator): string {+ const table = new Table({+ head: [t("col_combo"), t("col_acc"), t("col_consistency"), t("col_effcost"), t("col_wall")],+ });+ for (const m of sortCombos(metrics)) {+ table.push([+ m.comboId,+ `${m.accuracy.toFixed(0)}%`,+ `${(m.consistency ?? 0).toFixed(0)}%`,+ m.effectiveCostUsd == null ? pc.dim("—") : `$${m.effectiveCostUsd.toFixed(4)}`,+ `${(m.wallTimeMs / 1000).toFixed(1)}s`,+ ]);+ }+ return table.toString();+}++async function doRun(state: SessionState): Promise<void> {+ const t = translator(state.language);+ if (!state.models.length || !state.agents.length) {+ console.log(pc.red(" set /models and /agents first"));+ return;+ }+ const { valid, excluded } = expand(state.models, state.agents, state.harnesses);+ if (!valid.length) {+ console.log(pc.red(" no valid combos — check /config"));+ return;+ }+ const pf = analyze(state.models, state.agents, state.harnesses, valid, excluded, {+ bench: state.bench,+ runner: state.runner,+ tasks: state.tasks,+ runs: state.runs,+ yes: false,+ });+ if (pf.gateBlocked) {+ console.log(pc.red(` ${t("gate_blocked")} — try /runner mock`));+ return;+ }+ if (state.goal) console.log(pc.dim(` goal ▸ ${state.goal}`));+ console.log(pc.dim(` running ${pf.scale} …`));+ const res = await execute(toRunOptions(state));+ if (res.mock) console.log(pc.yellow(` ${t("mock_banner")}`));+ console.log(resultsTable(res.metrics, state.language, t));+ for (const [label, combo] of Object.entries(bestByPerspective(res.metrics, state.language)))+ console.log(` ${pc.green("▸")} ${label}: ${combo}`);+ console.log(` ${t("report_path")}: ${pc.bold(res.reportPath)}`);+ console.log(pc.dim(" /view to open the gallery · /run again after tweaks"));+}++interface ServeRef {+ handle: { url: string; close: () => void } | null;+}++async function doView(state: SessionState, open: boolean, srv: ServeRef): Promise<void> {+ const runs = listRuns(state.outDir);+ if (!runs.length) {+ console.log(pc.yellow(` no runs yet in ${state.outDir}/ — /run first`));+ return;+ }+ if (!srv.handle) srv.handle = await serveRuns(state.outDir, state.port);+ console.log(+ ` ${pc.green("⛵ view")} — ${runs.length} run(s) at ${pc.bold(srv.handle.url)} ${pc.dim("(stays up; closes on /exit)")}`,+ );+ if (open) openUrl(srv.handle.url);+}++// ── REPL 루프 ────────────────────────────────────────────+export async function runSession(init: { language: Lang; outDir: string }): Promise<void> {+ let state = defaultState(init.language, init.outDir);+ const srv: ServeRef = { handle: null };++ console.log(logoBanner(state.language));+ console.log(+ pc.dim(" interactive session — describe your goal, then /run. /help for commands.\n"),+ );++ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });++ // 라인 큐 — TTY 와 파이프(다중 라인) 모두에서 안정적으로 한 줄씩 소비.+ const queue: string[] = [];+ let waiter: ((v: string | null) => void) | null = null;+ let closed = false;+ rl.on("line", (l) => {+ if (waiter) {+ const w = waiter;+ waiter = null;+ w(l);+ } else queue.push(l);+ });+ rl.on("close", () => {+ closed = true;+ if (waiter) {+ const w = waiter;+ waiter = null;+ w(null);+ }+ });+ const next = (): Promise<string | null> =>+ queue.length+ ? Promise.resolve(queue.shift()!)+ : closed+ ? Promise.resolve(null)+ : new Promise((res) => {+ waiter = res;+ });++ rl.on("SIGINT", () => {+ srv.handle?.close();+ console.log(pc.dim("\n bye ⛵"));+ process.exit(0);+ });++ const prompt = (): string =>+ `${pc.cyan("theseus")}${pc.dim(` [${state.models.length}m×${state.agents.length}a×${state.harnesses.length}h]`)} ▸ `;++ while (true) {+ rl.setPrompt(prompt());+ rl.prompt();+ const raw = await next();+ if (raw === null) break; // stream closed+ const r = reduce(state, raw);+ state = r.state;+ for (const l of r.lines) console.log(l);+ const a = r.action;+ if (a.kind === "exit") break;+ if (a.kind === "run") await doRun(state);+ else if (a.kind === "view") await doView(state, a.open, srv);+ else if (a.kind === "results") {+ const runs = listRuns(state.outDir);+ if (!runs.length) console.log(pc.yellow(` no runs in ${state.outDir}/`));+ // 최근 run 은 report 로 — 여기서는 안내만(상세 표는 /run 직후 출력)+ else console.log(pc.dim(` ${runs.length} run(s); use /view for the gallery`));+ }+ }++ srv.handle?.close();+ rl.close();+ console.log(pc.dim(" bye ⛵"));+}diff --git a/tests/session.test.ts b/tests/session.test.tsnew file mode 100644index 0000000..2b03a8d--- /dev/null+++ b/tests/session.test.ts@@ -0,0 +1,80 @@+/**+ * 인터랙티브 세션 reducer — 통일된 슬래시 인터페이스.+ * 순수 reduce(): 선택 변경 · 목표 누적 · 검증(미지 무시) · 액션 분기.+ */+import { describe, expect, it } from "vitest";+import { defaultState, reduce } from "../src/session";++const s0 = () => defaultState("en", "runs");++describe("session reduce — selection commands", () => {+ it("/models sets known models, ignores unknown", () => {+ const r = reduce(s0(), "/models opus4.8, gpt5.5, nope");+ expect(r.state.models).toEqual(["opus4.8", "gpt5.5"]);+ expect(r.lines.join("\n")).toMatch(/unknown models: nope/);+ });++ it("/models accepts raw openrouter ids (slash form)", () => {+ const r = reduce(s0(), "/models openrouter/qwen/qwen3-coder");+ expect(r.state.models).toEqual(["openrouter/qwen/qwen3-coder"]);+ });++ it("/agents and /harness validate against the registry", () => {+ const r1 = reduce(s0(), "/agents opencode,codex");+ expect(r1.state.agents).toEqual(["opencode", "codex"]);+ const r2 = reduce(r1.state, "/harness none,omc,bogus");+ expect(r2.state.harnesses).toEqual(["none", "omc"]);+ expect(r2.lines.join("\n")).toMatch(/unknown harnesses: bogus/);+ });++ it("rejects an all-invalid set and keeps the current selection", () => {+ const r = reduce(s0(), "/agents zzz");+ expect(r.state.agents).toEqual(["cc"]); // unchanged default+ });++ it("/runs /tasks /seed parse integers", () => {+ let st = reduce(s0(), "/runs 3").state;+ st = reduce(st, "/tasks 10").state;+ st = reduce(st, "/seed 42").state;+ expect([st.runs, st.tasks, st.seed]).toEqual([3, 10, 42]);+ });+});++describe("session reduce — goal", () => {+ it("plain text accumulates into the goal", () => {+ let st = reduce(s0(), "fix the flaky test").state;+ expect(st.goal).toBe("fix the flaky test");+ st = reduce(st, "without touching the API").state;+ expect(st.goal).toBe("fix the flaky test without touching the API");+ });++ it("/goal sets and clears", () => {+ let st = reduce(s0(), "/goal ship the dashboard").state;+ expect(st.goal).toBe("ship the dashboard");+ st = reduce(st, "/goal clear").state;+ expect(st.goal).toBe("");+ });+});++describe("session reduce — actions", () => {+ it("/run /view /exit yield actions; bare commands are read-only", () => {+ expect(reduce(s0(), "/run").action).toEqual({ kind: "run" });+ expect(reduce(s0(), "/view open").action).toEqual({ kind: "view", open: true });+ expect(reduce(s0(), "/view").action).toEqual({ kind: "view", open: false });+ expect(reduce(s0(), "/exit").action).toEqual({ kind: "exit" });+ expect(reduce(s0(), "/models").action).toEqual({ kind: "none" }); // list only+ });++ it("/clear resets to defaults", () => {+ const dirty = reduce(reduce(s0(), "/agents opencode").state, "/runs 9").state;+ const cleared = reduce(dirty, "/clear").state;+ expect(cleared.agents).toEqual(["cc"]);+ expect(cleared.runs).toBe(2);+ });++ it("unknown command is reported, not fatal", () => {+ const r = reduce(s0(), "/bogus");+ expect(r.action).toEqual({ kind: "none" });+ expect(r.lines.join("\n")).toMatch(/unknown command/);+ });+});