From 183f0cce61ea84ac558c1f0b928300c3b7eed39c Mon Sep 17 00:00:00 2001 From: Shane B Date: Sun, 29 Nov 2026 16:52:42 +0100 Subject: [PATCH 1/4] feat(chat): a one-file handle folder under attached/ is listed with its file (only) and drawn as one row files.list of attached/ reads each handle folder through the same reader and, when it holds exactly one entry and that entry is a file, carries it as `only`: a FileListEntry gated as any other (over the hub its shown name alone; realName, hiddenBy and unhide only with detail), never with an `only` of its own. The worker rebuilds it by the same field rule and drops it off attached/, on a file, or when it is not a file. The panel draws the pair as the file's row with the handle dim after the name; its notes and menu are the file's, on the file's stored path. A listing code reads (ml.fs, Python's mount) never carries it. Co-Authored-By: Claude Opus 5.5 --- src/chat/chat.css | 4 ++ src/chat/fake-host.ts | 11 ++++- src/chat/files-panel.tsx | 19 +++++++-- src/session/files-list-serve.ts | 16 +++++++- src/session/session-host.ts | 4 ++ src/sw/sw-files-list.ts | 15 +++++-- tests/files-list-command.test.mjs | 23 +++++++++++ tests/files-list-serve.test.mjs | 63 +++++++++++++++++++++++++++++ tests/files-panel.test.mjs | 67 +++++++++++++++++++++++++++++-- 9 files changed, 209 insertions(+), 13 deletions(-) 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..3af8ba09f 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 ? :