From 9fdabbb9e1fc85eba4898f79c2f7772df6a93623 Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:12:22 +0800 Subject: [PATCH] feat(cli): list saved sessions offline --- README.md | 14 ++++---- README_CN.md | 14 ++++---- article/00-index.md | 2 +- article/00-index_EN.md | 2 +- article/06-session-and-cli.md | 2 +- article/06-session-and-cli_EN.md | 2 +- corecoder/cli.py | 25 +++++++++---- pyproject.toml | 2 +- tests/check_installed_wheel.py | 19 +++++++++- tests/test_session_catalog_cli.py | 59 +++++++++++++++++++++++++++++++ 10 files changed, 116 insertions(+), 25 deletions(-) create mode 100644 tests/test_session_catalog_cli.py diff --git a/README.md b/README.md index cf24fb9de..971fac94e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # CoreCoder -**The nanoGPT of coding agents. A 1.5k-line engine inside 3,359 readable lines of pure Python: understand how a coding agent actually works, then fork your own.** +**The nanoGPT of coding agents. A 1.5k-line engine inside 3,370 readable lines of pure Python: understand how a coding agent actually works, then fork your own.** *learn from it · fork it · ship something better* @@ -25,7 +25,7 @@ | | CoreCoder | Claude Code | aider | nanoGPT | |---|---|---|---|---| -| Lines of code | ~1,515 engine / 3,359 total | hundreds of thousands (closed) | tens of thousands of Python | ~600 (two files) | +| Lines of code | ~1,528 engine / 3,370 total | hundreds of thousands (closed) | tens of thousands of Python | ~600 (two files) | | Time to read it all | one afternoon | can't (closed) | a few days of slogging | one afternoon | | Breakpoint, change, rerun? | yes, every line | no | yes, but there's a lot | yes | | What it's for | understand one, then fork your own | production coding assistant | terminal pair-programming | minimal GPT for teaching | @@ -36,9 +36,9 @@ The nanoGPT column is there as a reference point: minimal, readable, but it teac I've always felt coding agents get talked about as if they were arcane. Strip a tool like Claude Code or Cursor all the way down and the core is a `while` loop wrapped around a large model, plus seven or eight tools that let it actually do things. The hard part was never the loop; it's everything the loop has to cope with once it meets the real world. CoreCoder is the minimal version that writes that core out honestly. -The engine (loop, model interface, context, tools, sessions) is 1,515 lines once you drop blank lines and comments. Counting the outer CLI, config and packaging too, the whole package is 26 files: 3,359 physical lines, 2,775 net, every one short enough to read in a single sitting. The growth since the original 1,161-line snapshot went into visible features: plan mode, hooks and checkpoints, each documented below. +The engine (loop, model interface, context, tools, sessions) is 1,528 lines once you drop blank lines and comments. Counting the outer CLI, config and packaging too, the whole package is 26 files: 3,370 physical lines, 2,783 net, every one short enough to read in a single sitting. The growth since the original 1,161-line snapshot went into visible features: plan mode, hooks and checkpoints, each documented below. -And it really runs: reads and writes files, executes shell, spawns sub-agents, compacts context in three tiers, and tells you the tokens and dollars a run burned whenever you ask. Anything that would mutate your disk or run a command stops for your consent first. The suite has 363 offline tests and an opt-in live smoke test. But the point of it running isn't to become your daily driver. It runs so the walkthrough can't lie: a reference that shows how an agent works has to actually work. +And it really runs: reads and writes files, executes shell, spawns sub-agents, compacts context in three tiers, and tells you the tokens and dollars a run burned whenever you ask. Anything that would mutate your disk or run a command stops for your consent first. The suite has 368 offline tests and an opt-in live smoke test. But the point of it running isn't to become your daily driver. It runs so the walkthrough can't lie: a reference that shows how an agent works has to actually work. The code came out of a public teardown: open analyses have already exposed a lot of the load-bearing architecture inside production agents like Claude Code. I took the most essential layer and rewrote it honestly, in as little code as I could. So reading CoreCoder is roughly like reading a runnable, annotated take on how that kind of agent works, except it's only a minimal reimplementation, sitting right there on your machine for you to take apart and change. @@ -91,7 +91,7 @@ Laid out flat, the whole project is this big. Skim it before you clone and you'l corecoder/ ├── agent.py agent loop + parallel tool exec 240 lines ← start here ├── llm.py streaming client + retry + cost 364 lines -├── context.py three-tier context compaction 220 lines +├── context.py three-tier context compaction 251 lines ├── session.py save / resume + path-traversal guard 97 lines ├── permissions.py consent for mutating tools 81 lines ├── hooks.py Pre/PostToolUse shell hooks 87 lines @@ -99,7 +99,7 @@ corecoder/ ├── mcp.py MCP tools, text resources + stdio 313 lines ├── mcp_http.py remote Streamable HTTP transport 211 lines ├── prompt.py system prompt 41 lines -├── cli.py REPL + slash commands + one-shot 393 lines +├── cli.py REPL + slash commands + one-shot 404 lines ├── config.py env-var config 55 lines ├── checkpoints.py /undo snapshot and restore 125 lines ├── demo.py offline end-to-end demo 101 lines @@ -229,6 +229,8 @@ Inside the REPL, `/help` lists everything; these are the ones you'll reach for: quit / exit exit (Ctrl+C cancels the current round) ``` +Run `corecoder --list-sessions` from the terminal to find the ID of a saved conversation before you resume it with `corecoder -r ID`. It shows the same model, save time and short prompt preview as `/sessions`, without loading provider settings or requiring an API key. + Session IDs are sanitized to safe characters before they become filenames, every archive lands under `~/.corecoder/sessions`, and a malicious session name can't traverse out. Undo history persists the same way: checkpoints land in `~/.corecoder/checkpoints.json`, so `/undo` still reaches back after a restart. Each checkpoint also records the bytes the edit produced; if the file changed again by hand or through bash, `/undo` keeps the newer work and the checkpoint instead of overwriting it. The cost estimate behind `/tokens` reads a built-in price table, and `~/.corecoder/pricing.json` overrides any entry in it, so a new model or a moved price lands without waiting for a release. ## Permissions diff --git a/README_CN.md b/README_CN.md index 9c27173e0..6382089f8 100644 --- a/README_CN.md +++ b/README_CN.md @@ -2,7 +2,7 @@ # CoreCoder -**编程 agent 里的 nanoGPT。1.5k 行引擎、整包 3359 行纯 Python 全部一口气可读,读懂一个 coding agent 到底怎么运作,再 fork 出你自己的。** +**编程 agent 里的 nanoGPT。1.5k 行引擎、整包 3370 行纯 Python 全部一口气可读,读懂一个 coding agent 到底怎么运作,再 fork 出你自己的。** *learn from it · fork it · ship something better* @@ -25,7 +25,7 @@ | | CoreCoder | Claude Code | aider | nanoGPT | |---|---|---|---|---| -| 代码量 | 引擎约 1528 行 / 整包 3359 行 | 几十万行(闭源) | 数万行 Python | 约 600 行(两个文件) | +| 代码量 | 引擎约 1528 行 / 整包 3370 行 | 几十万行(闭源) | 数万行 Python | 约 600 行(两个文件) | | 读完要多久 | 一个下午 | 读不了(闭源) | 得啃几天 | 一个下午 | | 能不能下断点改了再跑 | 能,每一行 | 不能 | 能,但量大 | 能 | | 定位 | 读懂并 fork 出你自己的 agent | 生产级编程助手 | 终端结对编程 | 教学用最小 GPT | @@ -36,9 +36,9 @@ nanoGPT 那一列是拿来对照的:它最小、可读,但教的是训一个 我一直觉得 coding agent 被讲得太玄了。把 Claude Code、Cursor 这类工具扒到底,核心是一个 while 循环套着一个大模型,外加七八个让它能真正动手的工具。难的从来不是这个循环,而是循环跑进真实世界以后要兜的那些底。CoreCoder 就是把这个核心老老实实写出来的最小版本。 -引擎部分(循环、模型接口、上下文、工具、会话)去掉空行和注释是 1528 行。连最外层的 CLI、配置、打包一起算,整个包 26 个文件、物理 3359 行、净 2775 行,每个文件都短到能一口气读完。自 1161 行快照之后的增长都花在了看得见的功能上:plan mode、hooks、checkpoints,下文各有交代。 +引擎部分(循环、模型接口、上下文、工具、会话)去掉空行和注释是 1528 行。连最外层的 CLI、配置、打包一起算,整个包 26 个文件、物理 3370 行、净 2783 行,每个文件都短到能一口气读完。自 1161 行快照之后的增长都花在了看得见的功能上:plan mode、hooks、checkpoints,下文各有交代。 -它真能跑:读写文件、执行 shell、派子 agent、分三层压上下文,还能随时把这趟烧掉的 token 和美元数报给你。任何要动你磁盘、要跑命令的调用,都会先停下来等你点头。现在有 363 个离线测试,另有按需开启的真实 API 冒烟。但能跑不是为了劝你拿去日用,而是为了让这份「注释」不撒谎:一个解释 agent 怎么运作的范例,自己得真能运作。 +它真能跑:读写文件、执行 shell、派子 agent、分三层压上下文,还能随时把这趟烧掉的 token 和美元数报给你。任何要动你磁盘、要跑命令的调用,都会先停下来等你点头。现在有 368 个离线测试,另有按需开启的真实 API 冒烟。但能跑不是为了劝你拿去日用,而是为了让这份「注释」不撒谎:一个解释 agent 怎么运作的范例,自己得真能运作。 代码来自一次公开拆解。公开的源码分析里,Claude Code 这类生产级 agent 暴露出不少关键架构,我挑出最核心的一层,用尽量少的代码诚实地复写了一遍。所以读 CoreCoder,约等于读一份基于公开源码分析的「可运行注释版」:讲的是这类 agent 的核心思路,而它本身只是最小复写,就摆在你机器上,随你拆、随你改。 @@ -91,7 +91,7 @@ corecoder -p "给 parse_config() 加错误处理" # 一次性模式,干完 corecoder/ ├── agent.py agent 主循环 + 并行工具执行 240 行 ← 从这里开始读 ├── llm.py 流式客户端 + 重试 + 成本统计 364 行 -├── context.py 三层上下文压缩 220 行 +├── context.py 三层上下文压缩 251 行 ├── session.py 会话存盘 / 续聊 + 路径穿越防护 97 行 ├── permissions.py 改动类工具的用户授权 81 行 ├── hooks.py 工具调用前后的用户 shell 钩子 87 行 @@ -99,7 +99,7 @@ corecoder/ ├── mcp.py MCP 工具、文本资源和 stdio 313 行 ├── mcp_http.py 远程 Streamable HTTP 连接 211 行 ├── prompt.py 系统提示词 41 行 -├── cli.py REPL + 斜杠命令 + 一次性模式 393 行 +├── cli.py REPL + 斜杠命令 + 一次性模式 404 行 ├── config.py 环境变量配置 55 行 ├── checkpoints.py /undo 快照与回滚 125 行 ├── demo.py 离线端到端演示 101 行 @@ -229,6 +229,8 @@ README 只给方向,每条的代码细节第七篇接着讲。挑一个动手 quit / exit 退出(Ctrl+C 取消当前回合) ``` +想找回上次的对话,直接在终端运行 `corecoder --list-sessions`。它和 `/sessions` 一样显示模型、保存时间和第一条提问的简短预览。找到 ID 后用 `corecoder -r ID` 接着做。列清单不会读取模型配置,也不用配置 API key。 + 会话 ID 会先清洗成安全字符再拿去当文件名,存档统统落在 `~/.corecoder/sessions` 里,恶意会话名穿越不出去。undo 历史也一样落盘:快照写在 `~/.corecoder/checkpoints.json`,重启之后 `/undo` 照样能往回撤。每份快照还会记下这次编辑实际写出的字节;如果文件后来又被手工或 bash 改过,`/undo` 会保留后来的改动和快照,不会直接覆盖。`/tokens` 的费用估算读的是内置价目表,在 `~/.corecoder/pricing.json` 里写自己的价格就会盖掉对应条目,新模型、调价都不用等发版。 ## 权限 diff --git a/article/00-index.md b/article/00-index.md index 6d7dbf0e3..5c644f5dd 100644 --- a/article/00-index.md +++ b/article/00-index.md @@ -8,7 +8,7 @@ 因为 Claude Code 本体太大了。它的代码量在几十万行的量级,光一个负责跑 shell 命令的 BashTool 就上千行,真要逐行读完,多数人会在第三个文件就关掉编辑器。可 agent 的核心其实没那么复杂,复杂的是工程化之后那些为真实世界兜底的边角:模型半路被打断怎么办、上下文塞满了怎么办、十个工具调用同时回来怎么办、provider 偶尔抽风返回 500 又怎么办。这些东西摊在几十万行里,你很难一眼看到骨架。 -CoreCoder 做的事,是把这套骨架压到一千五百行出头的纯 Python。准确说,agent 引擎(循环、模型接口、上下文、工具、会话)去掉空行和注释是 1528 行;连最外层的 CLI 终端、配置和打包都算上,整个包去掉空行和注释 2775 行,物理代码 3359 行。每个文件都短到能一口气读完,跑起来又确实是个能改代码、能跑命令、能自己开子任务、能压缩上下文、能算钱的 agent。它不是玩具。它是把生产级 agent 的每个设计决策,拣出最核心的那版,用最少的代码诚实地写一遍。 +CoreCoder 做的事,是把这套骨架压到一千五百行出头的纯 Python。准确说,agent 引擎(循环、模型接口、上下文、工具、会话)去掉空行和注释是 1528 行;连最外层的 CLI 终端、配置和打包都算上,整个包去掉空行和注释 2783 行,物理代码 3370 行。每个文件都短到能一口气读完,跑起来又确实是个能改代码、能跑命令、能自己开子任务、能压缩上下文、能算钱的 agent。它不是玩具。它是把生产级 agent 的每个设计决策,拣出最核心的那版,用最少的代码诚实地写一遍。 读它,约等于读一份 Claude Code 的「可运行注释版」。区别在于,CoreCoder 的每一行你都能在自己机器上断点、改、跑、看它出什么效果。本系列里我引用的每一个行数、每一段代码,都是从仓库里现读现核的,不是凭印象。这点我后面会反复较真,因为编码 agent 这个领域,太多文章在凭感觉编数字。 diff --git a/article/00-index_EN.md b/article/00-index_EN.md index c537f553f..50eb5d3d9 100644 --- a/article/00-index_EN.md +++ b/article/00-index_EN.md @@ -8,7 +8,7 @@ First, use CoreCoder, an open source project whose core runs to just over fiftee Because Claude Code itself is too big. Its codebase runs into the hundreds of thousands of lines, and the BashTool alone, the part that runs shell commands, is over a thousand. Read it line by line and most people close the editor by the third file. Yet the core of an agent isn't really that complicated. What's complicated is everything engineered around it to survive the real world: what to do when the model gets interrupted mid-stream, when the context window fills up, when ten tool calls come back at once, when a provider hiccups and returns a 500. Spread across hundreds of thousands of lines, that skeleton is hard to see. -What CoreCoder does is squeeze the skeleton down to just over fifteen hundred lines of pure Python. To be precise, the agent engine (the loop, model interface, context, tools, session) is 1,528 lines once you drop blank lines and comments; add the outermost CLI terminal, config, and packaging and the whole package is 2,775 lines without blanks and comments, 3,359 physical. Every file is short enough to read in one sitting, and what runs is genuinely an agent: it edits code, runs commands, spins up its own subtasks, compresses context, tracks cost. It is not a toy. It takes every design decision a production agent makes, picks the most essential version of each, and writes it out honestly in the least code it can. +What CoreCoder does is squeeze the skeleton down to just over fifteen hundred lines of pure Python. To be precise, the agent engine (the loop, model interface, context, tools, session) is 1,528 lines once you drop blank lines and comments; add the outermost CLI terminal, config, and packaging and the whole package is 2,783 lines without blanks and comments, 3,370 physical. Every file is short enough to read in one sitting, and what runs is genuinely an agent: it edits code, runs commands, spins up its own subtasks, compresses context, tracks cost. It is not a toy. It takes every design decision a production agent makes, picks the most essential version of each, and writes it out honestly in the least code it can. Reading it is close to reading a runnable, annotated edition of Claude Code. The difference is that every line of CoreCoder is something you can breakpoint, change, run, and watch on your own machine. Every line count and every snippet I quote in this series is read straight out of the repository, not recalled from memory. I'll keep being pedantic about that, because in the coding-agent space far too many write-ups just make the numbers up. diff --git a/article/06-session-and-cli.md b/article/06-session-and-cli.md index d19fd2d22..85710b0d8 100644 --- a/article/06-session-and-cli.md +++ b/article/06-session-and-cli.md @@ -1,6 +1,6 @@ # 把它跑成一个真正的命令行工具 -前五篇拆的是 agent 的内脏:循环、工具、模型接口、上下文压缩、并发与子 agent。这些零件再漂亮,你也没法直接用,因为还缺一层皮,一个让人能坐下来跟它对话、能存盘、能续聊、能查状态的命令行界面。这一篇讲这层皮,对应 `cli.py`(393 行)和 `session.py`(97 行)。 +前五篇拆的是 agent 的内脏:循环、工具、模型接口、上下文压缩、并发与子 agent。这些零件再漂亮,你也没法直接用,因为还缺一层皮,一个让人能坐下来跟它对话、能存盘、能续聊、能查状态的命令行界面。这一篇讲这层皮,对应 `cli.py`(404 行)和 `session.py`(97 行)。 它不光是「锦上添花的 UI」。这层皮里藏着一个很值得讲的安全细节,我们留到后面压轴。 diff --git a/article/06-session-and-cli_EN.md b/article/06-session-and-cli_EN.md index 9dbc918db..052ef8bfb 100644 --- a/article/06-session-and-cli_EN.md +++ b/article/06-session-and-cli_EN.md @@ -1,6 +1,6 @@ # Turning it into a real command-line tool -The first five pieces dissected the agent's internals: the loop, the tools, the model interface, context compression, parallelism and sub-agents. As lovely as these parts are, you can't use them directly, because one more layer is missing, a skin, a command-line interface where someone can sit down and talk to it, save, resume, and check status. This piece covers that skin, corresponding to `cli.py` (393 lines) and `session.py` (97 lines). +The first five pieces dissected the agent's internals: the loop, the tools, the model interface, context compression, parallelism and sub-agents. As lovely as these parts are, you can't use them directly, because one more layer is missing, a skin, a command-line interface where someone can sit down and talk to it, save, resume, and check status. This piece covers that skin, corresponding to `cli.py` (404 lines) and `session.py` (97 lines). It's not just "a nice-to-have UI." Hidden in this skin is a security detail well worth discussing, which we save for the finale. diff --git a/corecoder/cli.py b/corecoder/cli.py index e0c4156f9..ca1e56e24 100644 --- a/corecoder/cli.py +++ b/corecoder/cli.py @@ -37,13 +37,29 @@ def _parse_args(): p.add_argument("--yes", action="store_true", help="Auto-approve every tool call (for scripts and CI)") p.add_argument("--demo", action="store_true", help="Run the offline scripted demo (no API key needed)") p.add_argument("-r", "--resume", metavar="ID", help="Resume a saved session") + p.add_argument("--list-sessions", action="store_true", help="List saved sessions offline") p.add_argument("-v", "--version", action="version", version=f"%(prog)s {__version__}") - return p.parse_args() + args = p.parse_args() + if args.list_sessions and (args.demo or args.prompt is not None or args.resume is not None): + p.error("--list-sessions cannot be combined with --demo, --prompt or --resume") + return args + + +def _show_sessions(): + sessions = list_sessions() + if not sessions: + console.print("[dim]No saved sessions.[/dim]") + for s in sessions: + console.print(f" {s['id']} ({s['model']}, {s['saved_at']}) {s['preview']}", markup=False) def main(): args = _parse_args() + if args.list_sessions: + _show_sessions() + return + if args.demo: from .demo import run_demo raise SystemExit(run_demo()) @@ -285,12 +301,7 @@ def _newline(event): console.print(f"[dim]{left} more checkpoint(s) on the stack.[/dim]") continue if user_input == "/sessions": - sessions = list_sessions() - if not sessions: - console.print("[dim]No saved sessions.[/dim]") - else: - for s in sessions: - console.print(f" [cyan]{s['id']}[/cyan] ({s['model']}, {s['saved_at']}) {s['preview']}") + _show_sessions() continue if user_input == "/mcp" or user_input.startswith("/mcp "): _mcp(user_input[4:].strip()) diff --git a/pyproject.toml b/pyproject.toml index dade571f9..9a732b0a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "corecoder" version = "0.13.1" -description = "Minimal AI coding agent (3,359 lines of Python) inspired by Claude Code. Works with any LLM. (formerly NanoCoder)" +description = "Minimal AI coding agent (3,370 lines of Python) inspired by Claude Code. Works with any LLM. (formerly NanoCoder)" readme = "README.md" license = "MIT" requires-python = ">=3.10" diff --git a/tests/check_installed_wheel.py b/tests/check_installed_wheel.py index c12873d4d..6f492689c 100644 --- a/tests/check_installed_wheel.py +++ b/tests/check_installed_wheel.py @@ -2,6 +2,7 @@ import hashlib import json +import os import shutil import subprocess import sys @@ -33,6 +34,21 @@ def main(): assert cli, "installed console entry point is missing" help_result = subprocess.run([cli, "--help"], cwd=work, capture_output=True, text=True, check=True) assert "corecoder" in help_result.stdout.lower() + env = os.environ.copy() + for key in ("OPENAI_API_KEY", "DEEPSEEK_API_KEY", "CORECODER_API_KEY", "PYTHONPATH"): + env.pop(key, None) + env.update(HOME=work, USERPROFILE=work) + sessions = Path(work) / ".corecoder" / "sessions" + sessions.mkdir(parents=True) + (sessions / "wheel-session.json").write_text(json.dumps({ + "id": "wheel-session", + "model": "fixture-model", + "saved_at": "2026-01-01 12:00:00", + "messages": [{"role": "user", "content": "saved before the restart"}], + }), encoding="utf-8") + catalog = subprocess.run([cli, "--list-sessions"], cwd=work, env=env, + capture_output=True, text=True, check=True) + assert "wheel-session" in catalog.stdout and "saved before the restart" in " ".join(catalog.stdout.split()) # The package is already imported from site-packages; this path is only for test fixtures. sys.path.insert(0, str(checkout)) import pytest @@ -46,7 +62,8 @@ def main(): assert all(path.is_relative_to(package) for path in loaded.values()), loaded print(json.dumps({"version": corecoder.__version__, "wheelSha256": hashlib.sha256(wheel.read_bytes()).hexdigest(), "packageRoot": str(package), "matchingPythonFiles": len(sources), - "consoleExit": help_result.returncode, "resourceTestsExit": result}, indent=2)) + "consoleExit": help_result.returncode, "sessionCatalogExit": catalog.returncode, + "resourceTestsExit": result}, indent=2)) raise SystemExit(result) diff --git a/tests/test_session_catalog_cli.py b/tests/test_session_catalog_cli.py new file mode 100644 index 000000000..3b7ffcd3e --- /dev/null +++ b/tests/test_session_catalog_cli.py @@ -0,0 +1,59 @@ +import sys + +import pytest + +from corecoder import cli, session + + +@pytest.fixture +def isolated_sessions(monkeypatch, tmp_path): + root = tmp_path / "sessions" + monkeypatch.setattr(session, "SESSIONS_DIR", root) + + def unexpected_config(): + pytest.fail("listing sessions must not load provider configuration") + + monkeypatch.setattr(cli.Config, "from_env", unexpected_config) + return root + + +def test_list_sessions_offline(isolated_sessions, monkeypatch, capsys): + sid = session.save_session([ + {"role": "user", "content": "[note] 看上次的结果"}, + {"role": "assistant", "content": "not shown in a preview"}, + ], "research-model") + path = isolated_sessions / f"{sid}.json" + before = path.read_bytes() + monkeypatch.setattr(sys, "argv", ["corecoder", "--list-sessions"]) + + cli.main() + + output = capsys.readouterr().out + assert sid in output + assert "research-model" in output + assert "[note] 看上次的结果" in " ".join(output.split()) + assert "not shown" not in output + assert path.read_bytes() == before + + +def test_list_sessions_empty_is_read_only(isolated_sessions, monkeypatch, capsys): + monkeypatch.setattr(sys, "argv", ["corecoder", "--list-sessions"]) + + cli.main() + + assert "No saved sessions." in capsys.readouterr().out + assert not isolated_sessions.exists() + + +@pytest.mark.parametrize("other", [["--resume", "old-id"], ["--prompt", "hello"], ["--demo"]]) +def test_list_sessions_cannot_start_another_mode(other, isolated_sessions, monkeypatch, capsys): + monkeypatch.setattr(sys, "argv", ["corecoder", "--list-sessions", *other]) + + with pytest.raises(SystemExit) as error: + cli.main() + + assert error.value.code == 2 + stderr = capsys.readouterr().err + assert "--list-sessions" in stderr + assert "not allowed with" in stderr or "cannot be combined" in stderr + assert not isolated_sessions.exists()