diff --git a/docs/spec/FILE_ATTACHMENTS.md b/docs/spec/FILE_ATTACHMENTS.md index c596772c2..11336961d 100644 --- a/docs/spec/FILE_ATTACHMENTS.md +++ b/docs/spec/FILE_ATTACHMENTS.md @@ -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//`, 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//` 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 diff --git a/docs/spec/SESSION_CONTRACT.md b/docs/spec/SESSION_CONTRACT.md index 1306f807c..30f4ea5c1 100644 --- a/docs/spec/SESSION_CONTRACT.md +++ b/docs/spec/SESSION_CONTRACT.md @@ -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:`; 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:`; 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 | diff --git a/src/chat/chat.css b/src/chat/chat.css index b7b60f4d2..f5a95b515 100644 --- a/src/chat/chat.css +++ b/src/chat/chat.css @@ -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//`. */ +.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); } diff --git a/src/chat/fake-host.ts b/src/chat/fake-host.ts index 28a4f510c..f75a2cb2f 100644 --- a/src/chat/fake-host.ts +++ b/src/chat/fake-host.ts @@ -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(); private filesRuleSeq = 0; @@ -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. @@ -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 ?? []; diff --git a/src/chat/files-panel.tsx b/src/chat/files-panel.tsx index ef7fee572..a5c1328e7 100644 --- a/src/chat/files-panel.tsx +++ b/src/chat/files-panel.tsx @@ -210,14 +210,16 @@ 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 ? :