Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

docs: the storage ledger, its route and its read-only rule

lmliheng7943cbb5e735
diff --git a/changelog/unreleased/2026-10-10-storage-ledger.md b/changelog/unreleased/2026-10-10-storage-ledger.md
new file mode 100644
index 00000000..0b9cb1ac
--- /dev/null
+++ b/changelog/unreleased/2026-10-10-storage-ledger.md
@@ -0,0 +1,21 @@
+# A storage ledger for the data root, and nothing that acts on it
+
+- **Date:** 2026-10-10
+- **Type:** feature
+- **Scope:** `core`, `server`, `cli`, `web`, `docs`
+
+[中文版](2026-10-10-storage-ledger.zh.md)
+
+Adelie can now say what its data root is made of. `penguin storage`, and a Storage page in the Web App's Settings, report one row per class of data — user data, temporary Workspaces, Session drafts, Traces, tool environments, the trash, the database, everything else — and then the entries a person could clean up, each with the rule it matched and what clearing it would cost.
+
+**Nothing in this release removes anything.** There is no timer, no threshold that acts on its own, and no route that could delete: the whole feature is one read-only walk and a report. It is the first step of the cleanup design recorded in the fork's issue #17, whose two fixed points are that the default is to keep every byte, and that any later removal must be reviewed by a person against a specific candidate list.
+
+## Details
+
+- **The vocabulary lives in core, as pure functions.** `state/storage.ts` walks a data root once and answers with a ledger: every byte lands in exactly one class, so the classes sum to the root's own size and an unclassified file cannot hide. `protected` is user data — Agent State, Project config, the Workspaces the user chose, vaults, plugins, benchmarks, snapshots — and is never a candidate; the derived classes are the ones that can be: temporary Workspaces (`empty`, `unreferenced`, `idle`), Session drafts (`orphan` when the Session no longer exists, `idle`, `budget`), Traces (`idle`, `budget`), tool environments (`idle`, guarded by a text search of `agent_state`), the trash, and the database.
+- **Liveness is an input, never a discovery.** `scanStorage(root, live)` takes the Session ids, real Workspace paths and last-activity stamps from its caller, and `emptyLiveSet()` is named rather than defaulted, because a scan that assumes nothing is referenced would call every temporary Workspace free. Only the server can answer that question, which is why the command and the page ask it rather than each walking the disk themselves.
+- **Every threshold defaults to off except the temporary-Workspace idle rule (30 days).** On the install this was written against — ten days old, 6.0G — an age-based rule reported zero bytes of anything older than thirty days, so age is a slow lever; the ledger's value is that it names the fast ones. The numbers are apparent sizes (`st_size`), so a tree of many small files weighs less here than `du` reports, and the volume's own `df` numbers ride along with the report rather than being inferred.
+- **`GET /api/admin/storage` is admin-only, GET-only and takes no parameter.** `StorageService` assembles the live set from `SessionIndex.listByProject` over `Projects.listAll` and maps the ledger onto the API DTO; a Session in the middle of being deleted counts as live, because that window is not reachable from a node and counting it live can only make an entry look referenced, never claim that something a deletion is about to take away is free.
+- **The CLI says what it is.** `penguin storage [--top <n>] [--json]` prints the classes, then the candidates with their rules, then environments that share a name or a shape — reported, never proposed for removal, since two look-alike environments may be at different versions — and closes by stating that nothing is removed without an approval and that nothing runs on a timer. `--top` folds the tail instead of hiding it.
+- **The Settings page carries the same sentence.** A Storage page joins the admin group and renders the class table, the candidates with a per-class note on what clearing them costs (older messages' attached images stop previewing; history replay and the Costs page lose their rebuild source; an environment is reinstalled the next time it is used), the duplicate-looking environments, and the paths the scan could not read, so the report is never more complete than it is.
+- **Docs.** `/docs/cli § penguin storage` and the server API reference describe the route and the read-only rule; both language files were updated.
diff --git a/changelog/unreleased/2026-10-10-storage-ledger.zh.md b/changelog/unreleased/2026-10-10-storage-ledger.zh.md
new file mode 100644
index 00000000..8220d6b0
--- /dev/null
+++ b/changelog/unreleased/2026-10-10-storage-ledger.zh.md
@@ -0,0 +1,21 @@
+# 数据根的存储分类账,以及对它什么都不会做的实现
+
+- **Date:** 2026-10-10
+- **Type:** feature
+- **Scope:** `core`, `server`, `cli`, `web`, `docs`
+
+[English](2026-10-10-storage-ledger.md)
+
+Adelie 现在能说清自己的数据根是由什么组成的。`penguin storage`,以及 Web App 设置里的「存储」页,会逐类给出一行——用户资产、临时工作区、会话草稿、轨迹、工具环境、回收站、数据库、其他——然后是可供人清理的条目,每一条都写明它命中的规则,以及清掉它的代价。
+
+**这一版里没有任何东西会删除任何东西。** 没有定时器,没有会自己动手的阈值,也没有能执行删除的接口:整个功能就是一次只读遍历加一份报告。它是记录在 issue #17 里的清理设计的第一步,那份设计的两个固定点是——默认保留每一个字节,以及此后任何删除都必须由人对着**一份具体候选清单**审核。
+
+## 细节
+
+- **词汇表在 core,以纯函数形式存在。** `state/storage.ts` 只遍历数据根一次,然后给出账本:每个字节都恰好落进一个类别,所以各类之和等于数据根本身的大小,未分类的文件无处藏身。`protected` 是用户资产——Agent State、Project 配置、用户自己指定的 Workspace、密钥库、插件、基准、快照——永远不是候选;可能成为候选的是派生数据:临时工作区(`empty`、`unreferenced`、`idle`)、会话草稿(会话已不存在时的 `orphan`、`idle`、`budget`)、轨迹(`idle`、`budget`)、工具环境(`idle`,另有一道 `agent_state` 文本检索作护栏)、回收站与数据库。
+- **活性是输入,不是扫描能自己发现的东西。** `scanStorage(root, live)` 从调用方取会话 id、Workspace 真实路径与最后活动时间;`emptyLiveSet()` 被起了名字而不是做成默认值,因为「假设什么都没被引用」的扫描会把每个临时工作区都说成可以回收。只有服务端回答得了这个问题,所以命令与页面都是去问它,而不是各自去走一遍磁盘。
+- **除临时工作区的静默规则(30 天)外,所有阈值默认关闭。** 在写下这份代码的那台机器上(数据根只有十天、6.0G),按年龄的规则报出的「超过三十天」的字节数是 0,所以年龄是慢杠杆;账本的价值在于它能把快杠杆点名。数字是**表观大小**(`st_size`),因此小文件多的目录树会显得比 `du` 报的轻,而卷自身的数字随报告一起给出,不靠推算。
+- **`GET /api/admin/storage` 仅限管理员、只接受 GET、不带任何参数。** `StorageService` 用 `Projects.listAll` 上的 `SessionIndex.listByProject` 组装活性集合,再把账本映射到 API DTO;正在被删除的会话仍按「活着」算,因为那个窗口从节点里够不到,而且按活着算只会让条目看起来仍被引用,绝不会把删除将要带走的东西说成空闲。
+- **CLI 明确说明自己是什么。** `penguin storage [--top <n>] [--json]` 先打印类别,再打印带规则的候选,然后是同名或同结构的工具环境——只报告、绝不提议删除,因为两个看起来一样的环境可能版本不同——最后一句写明:没有你的批准不会删除任何东西,也没有任何定时任务在跑。`--top` 折叠尾部而不是把它藏起来。
+- **设置页写着同一句话。** 「存储」页并入管理员分组,画出类别表、候选清单(附每类「清掉它的代价」:旧消息附件不再能预览;历史回放与成本页失去重建依据;环境下次用到要重新装)、疑似重复的环境,以及扫描读不到的路径——报告从不显得比自己更完整。
+- **文档。** `/docs/cli § penguin storage` 与服务端 API 参考描述了该路由与只读约定,中英两份都已更新。
diff --git a/packages/docs/content/cli.en.md b/packages/docs/content/cli.en.md
index 85eea2b6..6830489f 100644
--- a/packages/docs/content/cli.en.md
+++ b/packages/docs/content/cli.en.md
@@ -256,6 +256,33 @@ penguin cost --days 7 --by model
penguin cost --from 2026-08-01 --to 2026-08-25 --by agent
```
+## penguin storage
+
+Shows what occupies the data root (`ADELIE_HOME`, `~/.adelie/data` by default): one row per class of data, then the entries a person could clean up, then the environments that look like the same toolchain installed twice.
+
+```bash
+penguin storage [options]
+```
+
+| Option | Description | Default |
+| --- | --- | --- |
+| `--top <n>` | How many candidates to print; `0` prints every one. | 20 |
+| `--json` / `--server <url>` | See [Global conventions](#global-conventions). | — |
+
+**This command is read-only, and it has no flag that could change that**: it reports, it never moves or deletes a file, and nothing in Adelie runs a cleanup on a timer.
+
+The class column accounts for every byte under the root. User data — Agent State, Project config, the Workspaces you chose, vaults, plugins, benchmarks, snapshots — is listed but is never a cleanup candidate; the derived classes are the ones that can be: temporary Workspaces, Session drafts, Traces, tool environments, the trash, the database. The candidate list names the rule each row matched: `empty` or `unreferenced` (a temporary Workspace no Session points at), `session gone` (drafts of a deleted Session), `idle` (silent past a threshold), `over budget` (a size cap evicted it, oldest first). Every threshold defaults to off except the temporary-Workspace idle rule (30 days), so a fresh install reports an empty candidate list rather than a to-do list.
+
+`tool environments` that share a name or a shape are grouped and reported, never proposed for deletion: two look-alike environments may be at different versions, and merging them is a change a person triggers.
+
+`GET /api/admin/storage` is admin-only, so the command needs the server's own API token (the CLI's default when it attaches to a local server).
+
+```bash
+penguin storage
+penguin storage --top 50
+penguin storage --json
+```
+
## penguin schedule
Lists and manages the Project's scheduled tasks.
diff --git a/packages/docs/content/cli.zh.md b/packages/docs/content/cli.zh.md
index aa6b719f..8da270d8 100644
--- a/packages/docs/content/cli.zh.md
+++ b/packages/docs/content/cli.zh.md
@@ -256,6 +256,33 @@ penguin cost --days 7 --by model
penguin cost --from 2026-08-01 --to 2026-08-25 --by agent
```
+## penguin storage
+
+查看数据根(`ADELIE_HOME`,默认 `~/.adelie/data`)被什么占满:先是每一类数据一行,然后是可供人清理的条目,最后是看起来同一套工具链装了多份的环境。
+
+```bash
+penguin storage [选项]
+```
+
+| 选项 | 说明 | 默认 |
+| --- | --- | --- |
+| `--top <n>` | 打印多少条候选;`0` 表示全部。 | 20 |
+| `--json` / `--server <url>` | 见[全局约定](#全局约定)。 | — |
+
+**本命令只读,也没有任何能让它改变这一点的开关**:它只报告,从不移动或删除文件,Adelie 里也没有任何定时清理在跑。
+
+类别一列覆盖数据根下的每一个字节。用户资产——Agent State、Project 配置、你自己指定的 Workspace、密钥库、插件、基准、快照——会被列出,但永远不会成为清理候选;可能成为候选的是派生数据:临时工作区、会话草稿、轨迹、工具环境、回收站、数据库。候选清单会写明每一行命中的规则:`empty` 空目录、`unreferenced` 无引用(没有任何会话指向的临时工作区)、`session gone` 会话已删除(草稿所属的会话不存在了)、`idle` 静默超期、`over budget` 超出预算(按最旧优先被体积上限选出)。除了临时工作区的静默规则(30 天)之外,所有阈值默认关闭——因此刚装好的机器看到的是一份空清单,而不是一份待办。
+
+同名或同结构的「工具环境」只做分组报告,绝不提议删除:两个看起来一样的环境可能版本不同,是否合并由人点一次决定。
+
+`GET /api/admin/storage` 仅限管理员,因此需要服务器自己的 API token(CLI 连接本机服务器时的默认值)。
+
+```bash
+penguin storage
+penguin storage --top 50
+penguin storage --json
+```
+
## penguin schedule
列出并管理 Project 的定时任务。
diff --git a/packages/docs/content/server-api.en.md b/packages/docs/content/server-api.en.md
index 431ee4fd..04eeaf9f 100644
--- a/packages/docs/content/server-api.en.md
+++ b/packages/docs/content/server-api.en.md
@@ -173,6 +173,22 @@ The sandbox's entry also carries `backend`: `installed` says whether a sandbox b
On PUT, fields the request omits keep their value, `null` or `""` clears one, and a secret sent back as its mask keeps the stored value. A refused field returns `400` `plugin_config_invalid` naming it; a name no group answers to returns `404` `plugin_config_unknown`. The declaring module picks the change up itself, through its watch or at its next read, with no restart.
+## Storage Ledger (admin only)
+
+What the data root holds, class by class, and which entries a person could review.
+
+| Method | Path | Description |
+| --- | --- | --- |
+| GET | `/api/admin/storage` | The storage ledger: `{report: {root, scannedAt, totalBytes, classes, candidates, sharedEnvGroups, disk, unreadable}}` |
+
+**Nothing here cleans up.** The route reads the root and answers; it takes no query parameter, has no PUT or DELETE beside it, and no part of the server acts on a report by itself — every removal in this design is a decision a person takes, and a report is what they take it against. A stale report cannot cause one either: `referenced` is recomputed from live state when a cleanup would run, so an entry that came alive in between is not acted on.
+
+`root` is the real path that was walked and `scannedAt` is the instant it was observed (ISO), so the report describes that moment rather than the moment it is read. `totalBytes` is the sum of every class, so the classification accounts for the whole root; each class carries its byte, file and entry counts plus how many of its entries are candidates and how many bytes they hold. The classes are `protected` (user data: Agent State, Project configuration, a Workspace the user chose, user vaults, plugins, benchmarks, snapshots), `tmp_workspaces`, `session_drafts`, `traces`, `shared_env`, `trash`, `database` and `other`.
+
+`candidates` lists the reviewable entries, largest first and capped per class (the class totals above stay exact), each with the rules it matched: `empty` and `unreferenced` for a temporary Workspace no Session points at, `orphan` for the drafts of a Session that no longer exists, `idle` for anything judged by silence, `budget` for anything a size cap would evict. A candidate is a claim about provenance, never an action. `sharedEnvGroups` names the shared environments that look like the same toolchain installed more than once, by normalized name (`csu-mail` vs `csumail`) or by what they hold — report only, since two look-alike environments may be at different versions. `disk` carries the volume's free and total bytes (`null` where the platform cannot say), and `unreadable` lists the paths that could not be read (capped), so the report says what it could not see rather than counting it as empty.
+
+Every threshold is off by default except the temporary-Workspace idle rule: the ledger's value is that it names references, budgets and duplicate environments, not that it guesses at timestamps.
+
## Machines (admin only)
Installs this server's build on other hosts over ssh and manages the connections to them.
diff --git a/packages/docs/content/server-api.zh.md b/packages/docs/content/server-api.zh.md
index cce5dca7..6a4b42ab 100644
--- a/packages/docs/content/server-api.zh.md
+++ b/packages/docs/content/server-api.zh.md
@@ -173,6 +173,22 @@ PUT 按如下规则校验:
PUT 时,请求省略的字段保持原值,`null` 或 `""` 清除该字段,密钥按掩码原样送回即保持存储值。被拒的字段返回 `400` `plugin_config_invalid` 并点名该字段;没有分组叫这个名字时返回 `404` `plugin_config_unknown`。声明它的模块自己经 watch 或下次读取拿到改动,无需重启。
+## 存储台账(仅管理员)
+
+数据根目录里有什么,按类别列出,以及哪些条目值得人工过目。
+
+| 方法 | 路径 | 说明 |
+| --- | --- | --- |
+| GET | `/api/admin/storage` | 存储台账:`{report: {root, scannedAt, totalBytes, classes, candidates, sharedEnvGroups, disk, unreadable}}` |
+
+**这个接口不做任何清理。** 它只读取根目录并返回结果:不接受任何查询参数,旁边没有 PUT 也没有 DELETE,服务器也不会自行依据报告采取动作——这套设计里每一次删除都由人决定,报告只是决定的依据。过期的报告也不会导致删除:真正执行时 `referenced` 会按当时的活性状态重新计算,期间重新活跃起来的条目不会被处理。
+
+`root` 是实际遍历的真实路径,`scannedAt` 是观测发生的那一刻(ISO),因此报告描述的是那一刻而不是被读取的那一刻。`totalBytes` 是各类别之和,也就是说这套分类覆盖整个根目录;每个类别带有自己的字节数、文件数、条目数,以及其中有多少条目是候选、共占多少字节。类别有 `protected`(用户数据:Agent State、Project 配置、用户自选的 Workspace、用户密钥库、插件、Benchmark、快照)、`tmp_workspaces`、`session_drafts`、`traces`、`shared_env`、`trash`、`database` 和 `other`。
+
+`candidates` 列出可供人工审核的条目,按体积从大到小、每个类别有数量上限(上面的类别总计仍是精确值),每条带上命中的规则:没有任何 Session 指向的临时 Workspace 为 `empty` 与 `unreferenced`,Session 已不存在的草稿为 `orphan`,按静默时长判定的为 `idle`,被体积上限挤出的为 `budget`。候选只是对来源的声明,不是动作。`sharedEnvGroups` 列出看起来是同一套工具链装了多份的共享环境,按归一化名称(`csu-mail` 与 `csumail`)或按内容特征归并——只报告:两份相似环境可能版本不同。`disk` 是所在卷的空闲与总字节数(平台无法给出时为 `null`),`unreadable` 列出读不了、被记下来的路径(有上限),报告会说明自己没看到什么,而不是把它当成空的。
+
+除临时 Workspace 的静默规则外,所有阈值默认关闭:这份台账的价值在于点出引用、体积上限和重复环境,而不在于拿时间戳去猜。
+
## 机器(仅管理员)
通过 ssh 在其他主机上安装本服务器的构建,并管理与这些主机的连接。