Skip to content
Merged
13 changes: 13 additions & 0 deletions docs/spec/FILE_ATTACHMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,19 @@ RULED 2026-11-17 (Shane's idea, the details the coordinator's calls, in the coor
seen at the next listing, never replayed. A tree may be out of date between a change and its hint.
- **Open, for the slice's own spec:** the coalescing window, which roots are watched beyond the session's own
folder (the sync watches that folder only), and what a watch that overflows or dies reports.
9. **A handle folder of one file is drawn as that file** (the coordinator, 2026-11-29). Every attachment lives at
`attached/<handle>/<name>`, one file to a handle folder, so the tree drew a folder per attachment around a single
row. A listing of `attached/` gives such a folder's entry an `only`, the file's entry (SESSION_CONTRACT.md,
`files.list`), and the panel draws one row: the file's name, size, marks and menu, with the handle dim after the
name. It rides the hub gated as any entry, so a hub client sees the shown name it would see by opening the folder.
Code's listings never carry it: `ml.fs` and Python's mount still see `attached/<handle>/` as a folder, and errors
and `ml.dereference` still give the path through it ("Names under `/files`", rule 5). A folder with any other
content, or one the runtime does not mark, is drawn as a folder. So is one a rule hides on exactly its path (a hide
an older build's panel made on the folder): its menu still removes that rule, which the file's menu could not, since
a file's `show` releases the file and leaves the folder's rule standing. A listing of `attached/` reads each handle
folder through the same reader, but asks the worker for the secrets' forms once, not once per folder: the listing's
channel keeps the first answer until it is disposed at the end of the request, and code's channels still ask at
each call.

#### A `python_install` candidate worker

Expand Down
2 changes: 1 addition & 1 deletion docs/spec/SESSION_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ runtime answers a type or option it does not offer with `unsupported`.
| `page.highlight`: a selector, a canvas token, or clear | drive | `highlight` | `__mlHighlight` → `ML_HL_REMOTE` |
| `side.call`: a utility-model call about a session | drive | `sideCalls` | `FETCH_LLM` with `extend: "utility"` |
| `policy.files`: add a hiding rule for a session's files (`op: "add"`, `effect` `hide` or `show`, a path or glob `source`, `scope` `session` or `global`), or remove one by `id` (`op: "remove"`; removing a `hide` widens and answers `confirm` until sent with `confirm: true`); POLICIES.md, "Hiding files" | approve | | nothing |
| `files.list`: one page of one directory under a session's `/files/` (FILE_ATTACHMENTS.md, "The file browser shows the mounts, and its menu sends commands"): `{ path, cursor?, limit?, mount? }` answers `{ entries, next? }`, each entry `{ name, kind: "file" \| "dir", size, mtimeMs, hidden, readonly }` under its SHOWN name ("Names under `/files`"; two entries may share one, so a client keys rows by position). A `path` through a shown name two stored entries share is refused `invalid`, with a reason saying the name is shared, never resolved to the first, as the mount refuses it (rule 4); on-device `realName` is what lifts it. At most 500 entries (`limit` at most 500) and 256 KiB of JSON a page; `next` is an opaque cursor; a well-formed cursor the runtime did not give lists the entries after the name it holds, in the same session and path, nothing else. A directory that changes between pages may repeat or skip an entry, never a snapshot: the client lists again from the start on `files-changed`. The root (`path: ""`) also answers `count: { attached, agent? }`, and a client never presents `attached` alone as the total. A hidden entry is listed with its size from stored metadata; its bytes are never read. `mount` defaults to `files`, and any other is `unsupported`; a path outside the mount, a file's path ("not a directory") or a cursor not of the runtime's form is `invalid`, a path that does not resolve `not-found`. From the person's own clients only: no model tool, `ml.fs` member or page-started message reaches it. An entry also carries `realName`, the stored name, only where it differs from `name`; a hidden entry also carries `hiddenBy`, the id of the rule that decides it (a policy id, or a default's `default:<name>`; for a file under a hidden directory, that directory's rule), and `unhide`, `remove` when that rule is a session `hide` whose source is exactly this entry's stored path and `show` otherwise; and the page then carries `detail: true`. All four are set by the runtime from the command's sender alone, never from a field of the command: only to a sender that is this browser's own pages (`CommandFrom.via` is `this browser`), never to a hub sender, in `files-changed`, in an event or in an export, and absent, never `false`, otherwise. A client offers the hide and show menu only on a page with `detail` (FILE_ATTACHMENTS.md, "The file browser shows the mounts, and its menu sends commands") | view | `listFiles` | nothing |
| `files.list`: one page of one directory under a session's `/files/` (FILE_ATTACHMENTS.md, "The file browser shows the mounts, and its menu sends commands"): `{ path, cursor?, limit?, mount? }` answers `{ entries, next? }`, each entry `{ name, kind: "file" \| "dir", size, mtimeMs, hidden, readonly }` under its SHOWN name ("Names under `/files`"; two entries may share one, so a client keys rows by position). A `path` through a shown name two stored entries share is refused `invalid`, with a reason saying the name is shared, never resolved to the first, as the mount refuses it (rule 4); on-device `realName` is what lifts it. At most 500 entries (`limit` at most 500) and 256 KiB of JSON a page; `next` is an opaque cursor; a well-formed cursor the runtime did not give lists the entries after the name it holds, in the same session and path, nothing else. A directory that changes between pages may repeat or skip an entry, never a snapshot: the client lists again from the start on `files-changed`. The root (`path: ""`) also answers `count: { attached, agent? }`, and a client never presents `attached` alone as the total. A hidden entry is listed with its size from stored metadata; its bytes are never read. `mount` defaults to `files`, and any other is `unsupported`; a path outside the mount, a file's path ("not a directory") or a cursor not of the runtime's form is `invalid`, a path that does not resolve `not-found`. From the person's own clients only: no model tool, `ml.fs` member or page-started message reaches it. An entry also carries `realName`, the stored name, only where it differs from `name`; a hidden entry also carries `hiddenBy`, the id of the rule that decides it (a policy id, or a default's `default:<name>`; for a file under a hidden directory, that directory's rule), and `unhide`, `remove` when that rule is a session `hide` whose source is exactly this entry's stored path and `show` otherwise; and the page then carries `detail: true`. All four are set by the runtime from the command's sender alone, never from a field of the command: only to a sender that is this browser's own pages (`CommandFrom.via` is `this browser`), never to a hub sender, in `files-changed`, in an event or in an export, and absent, never `false`, otherwise. A client offers the hide and show menu only on a page with `detail` (FILE_ATTACHMENTS.md, "The file browser shows the mounts, and its menu sends commands"). On a page of `path: "attached"`, a `dir` entry (a handle folder) that holds exactly one entry, a file, on one page also carries `only`: that file's entry, gated as any entry (to a hub sender its shown `name` alone, never `realName`, `hiddenBy` or `unhide`), never with an `only` of its own. It is read from stored metadata, never bytes. A client draws the pair as ONE row, the file's, with the handle after its name; an entry without `only` (another count, a folder inside, a second page, a refused read, or a runtime that does not set it) is drawn as a folder. Only `files.list` sets it, never a listing code reads (`ml.fs`, Python's mount) | view | `listFiles` | nothing |
| `file.put`: one chunk of a file sent ahead of the message that names it (a PDF, or a text file that will not go whole, `sentWhole`), over the hub only: `{ runtime, sha256, index, count, bytes }`, the chunk's raw bytes after the JSON and a zero byte in the sealed body. Answers `{ held, complete }`; `complete` once every chunk is in and the bytes hash to `sha256`. At most 4 unanswered (FILE_ATTACHMENTS.md, "Over the hub") | drive | (the hub path; `unsupported` from a runtime that takes none, and the client sends inline) | nothing |
| `file.have`: which chunks of a file this runtime holds, `{ held, count, complete }`, so a client sends only the rest | drive | (as `file.put`) | nothing |
| `device.list` | admin | `devices` | nothing |
Expand Down
4 changes: 4 additions & 0 deletions src/chat/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,10 @@ html[data-calm] .tt-layer { --notice: var(--accent); --notice-fg: var(--accent-f
@media (prefers-reduced-motion: reduce) { .fp-row .tri { transition: none; } }
.fp-kind { color: var(--fg-faint); display: inline-flex; flex: 0 0 auto; }
.fp-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* A one-file handle folder drawn as its file: the folder's name sits right after the file's, dim, and the rest stays right. */
.fp-one .fp-name { flex: 0 1 auto; }
/* The handle folder's name after its one file's, dim: where the file lives, as `attached/<handle>/`. */
.fp-handle { flex: 0 1000 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; margin-right: auto; color: var(--fg-faint); font-size: .86em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fp-size, .fp-time { flex: 0 0 auto; color: var(--fg-faint); font-size: .86em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fp-size { min-width: 4.4em; text-align: right; }
.fp-notes { display: inline-flex; gap: 4px; flex: 0 0 auto; color: var(--fg-dim); }
Expand Down
11 changes: 9 additions & 2 deletions src/chat/fake-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export class FakeHost implements SessionHost {
filesListed = true;
/** does it list as for this browser's own pages (`detail`: stored names, deciding rules)? Off, as for a hub client */
filesDetail = true;
/** does a listing of `attached/` carry a one-file handle folder's file as `only`? Off, as a runtime from before it */
filesOnly = true;
/** each session's hiding rules, as `policy.files` made them: literal paths only, the fake's whole rule language */
private filesRules = new Map<SessionKey, { id: string; effect: "hide" | "show"; source: string }[]>();
private filesRuleSeq = 0;
Expand Down Expand Up @@ -329,8 +331,8 @@ export class FakeHost implements SessionHost {
if (c.cursor != null) { at = /^\d+$/.test(c.cursor) ? Number(c.cursor) : -1; if (at < 0 || at > level!.length) return bad("invalid", "not a cursor this runtime gave"); }
const n = Math.min(Math.max(1, c.limit ?? this.filesPageSize), this.filesPageSize, 500);
const detail = this.filesDetail;
const entries = level!.slice(at, at + n).map((f): FileListEntry => {
const stored = [...storedDir, f.realName ?? f.name].join("/");
const entryOf = (f: FakeFsNode, dir: string[]): FileListEntry => {
const stored = [...dir, f.realName ?? f.name].join("/");
const rule = this.ruleFor(key, stored);
const hidden = rule ? rule.effect === "hide" : !!f.hidden;
// A node hidden with no session rule stands for a default (`.env`): only a `show` releases it.
Expand All @@ -339,6 +341,11 @@ export class FakeHost implements SessionHost {
name: f.name, kind: f.children ? "dir" : "file", size: f.size ?? 0, mtimeMs: f.mtimeMs ?? DEMO_MTIME, hidden, readonly: !!f.readonly,
...(detail && f.realName ? { realName: f.realName } : {}), ...(detail ? why : {}),
};
};
const entries = level!.slice(at, at + n).map((f): FileListEntry => {
const e = entryOf(f, storedDir);
const one = f.children?.length === 1 && !f.children[0].children ? f.children[0] : null;
return this.filesOnly && c.path === "attached" && one ? { ...e, only: entryOf(one, [...storedDir, f.realName ?? f.name]) } : e;
});
const files = (ns: FakeFsNode[]): number => ns.reduce((t, f) => t + (f.children ? files(f.children) : 1), 0);
const shelf = (name: string) => tree.find((t) => t.name === name)?.children ?? [];
Expand Down
20 changes: 17 additions & 3 deletions src/chat/files-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,24 @@ export const rowLabel = (e: FileListEntry): string => (e.realName != null && e.r

const truncated = (el: Element) => el.scrollWidth > el.clientWidth;

/** One row of any file browser: the kind's icon (and a chevron for a folder), the name, the size, the time. */
function BaseRow({ entry, open, shared, onToggle, notes, parentReadonly, menu }: { entry: FileListEntry; open: boolean; shared: boolean; onToggle: () => void; notes: boolean; parentReadonly: boolean; menu?: ComponentChildren }) {
/** One row of any file browser: the kind's icon (and a chevron for a folder), the name, the size, the time. `handle`: the
* row is a one-file handle folder drawn as its file, and the folder's name follows the file's, dim. */
function BaseRow({ entry, open, shared, onToggle, notes, parentReadonly, menu, handle }: { entry: FileListEntry; open: boolean; shared: boolean; onToggle: () => void; notes: boolean; parentReadonly: boolean; menu?: ComponentChildren; handle?: string }) {
const dir = entry.kind === "dir";
const label = rowLabel(entry);
const body = <>
{dir ? <span class={`tri${open ? " open" : ""}`} aria-hidden="true"><IconChevron /></span> : <span class="tri-gap" aria-hidden="true" />}
<span class="fp-kind" aria-hidden="true">{dir ? <IconFolder /> : <IconFile />}</span>
<span class="fp-name" {...cursorTipOn(label, { delayMs: 500, onlyIf: truncated })}>{label}</span>
{handle != null ? <span class="fp-handle" {...cursorTipOn(`In attached/${handle}/`)}>{handle}</span> : null}
{notes ? <RowNotes entry={entry} parentReadonly={parentReadonly} /> : null}
<span class="fp-size">{dir ? "" : formatBytes(entry.size)}</span>
<span class="fp-time" {...cursorTipOn(entry.mtimeMs ? fullStamp(entry.mtimeMs) : "No time")}>{entry.mtimeMs ? shortStamp(entry.mtimeMs) : "—"}</span>
</>;
// A folder whose shown name two entries share cannot be opened: the runtime refuses the path rather than guess.
const row = dir && shared ? <div class="fp-row fp-dir fp-shared" aria-disabled="true" {...cursorTipOn("Two entries share this name")}>{body}</div>
: dir ? <button class="fp-row fp-dir" aria-expanded={open} onClick={onToggle}>{body}</button>
: <div class="fp-row fp-file">{body}</div>;
: <div class={`fp-row fp-file${handle != null ? " fp-one" : ""}`}>{body}</div>;
// The menu sits beside the row, never inside it: a folder's row is a button, and a button holds no other.
return menu ? <div class="fp-row-wrap">{row}{menu}</div> : row;
}
Expand All @@ -247,6 +249,17 @@ function Level({ dirs, path, onToggle, onMore, notes, readonly = false, menuFor
const open = e.kind === "dir" && dirs.has(p);
// The stored path only where the page carried the stored names: a shown name is not one.
const stored = d.detail && d.stored != null ? join(d.stored, rowLabel(e)) : null;
// A handle folder holding one file is drawn as that file: its row, notes and menu, on the file's path. One
// a rule hides on exactly its path (an older build's hide) stays a folder, so its menu still removes that rule.
if (e.kind === "dir" && e.only?.kind === "file" && !open && !(e.hidden && e.unhide === "remove")) {
const one = e.only;
return (
<li key={i} role="treeitem">
<BaseRow entry={one} open={false} shared={false} onToggle={() => {}} notes={notes} parentReadonly={readonly || e.readonly} handle={e.name}
menu={menuFor?.(one, stored != null ? join(stored, rowLabel(one)) : null, d.detail === true)} />
</li>
);
}
return (
<li key={i} role="treeitem" aria-expanded={e.kind === "dir" ? open : undefined}>
<BaseRow entry={e} open={open} shared={(names.get(e.name) ?? 0) > 1} onToggle={() => onToggle(p, stored)} notes={notes} parentReadonly={readonly}
Expand All @@ -270,6 +283,7 @@ function Level({ dirs, path, onToggle, onMore, notes, readonly = false, menuFor
* @group chat
* @gallery tree {"dirs": {"": {"entries": [{"name": "attached", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": true}, {"name": "agent", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": false}, {"name": "archive", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": true}]}, "attached": {"entries": [{"name": "3fa91c2", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": true}, {"name": "9b20e11", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": true}, {"name": "c41d7a0", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": true}], "next": "3"}, "attached/9b20e11": {"entries": [{"name": "upload-1.txt", "realName": "quarterly report.txt", "kind": "file", "size": 880, "mtimeMs": 1795100000000, "hidden": false, "readonly": true}]}, "agent": {"entries": [{"name": "out.json", "kind": "file", "size": 700, "mtimeMs": 1795100000000, "hidden": false, "readonly": false}, {"name": "data.csv", "kind": "file", "size": 2048, "mtimeMs": 1795100000000, "hidden": false, "readonly": false}, {"name": "data.csv", "kind": "file", "size": 4096, "mtimeMs": 1795100060000, "hidden": false, "readonly": false}, {"name": "plots", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": false}, {"name": "old", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": false}, {"name": "old", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": false}]}}}
* @gallery closed folders {"dirs": {"": {"entries": [{"name": "attached", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": true}, {"name": "agent", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": false}]}}}
* @gallery one-file handle folders {"dirs": {"": {"entries": [{"name": "attached", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": true}]}, "attached": {"entries": [{"name": "3fa91c2", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": true, "only": {"name": "report.pdf", "kind": "file", "size": 482113, "mtimeMs": 1795100000000, "hidden": false, "readonly": true}}, {"name": "9b20e11", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": true, "only": {"name": "upload-1.txt", "kind": "file", "size": 880, "mtimeMs": 1795100000000, "hidden": false, "readonly": true, "realName": "quarterly report.txt"}}, {"name": "c41d7a0", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": true, "only": {"name": "keys.env", "kind": "file", "size": 96, "mtimeMs": 1795100000000, "hidden": true, "readonly": true}}, {"name": "d02e5f1", "kind": "dir", "size": 0, "mtimeMs": 1795100000000, "hidden": false, "readonly": true}]}}}
* @gallery loading {"dirs": {"": {"entries": [], "loading": true}}}
* @gallery failed {"dirs": {"": {"entries": [], "error": "The runtime is unreachable"}}}
*/
Expand Down
Loading
Loading