{"version":44,"agent":"speed","message":"status: skip reading files found unchanged before. A record in the folder's state dir (clean.json) keeps, per file, the size, time and inode of the file and its known copy, taken before reading; only status's unrecorded and line-ending checks use it, record always reads every file. Files changed too recently to trust are read; an unknown format or client version reads everything. The state dir is found once per walk. The mod-commit test no longer depends on how long it takes.","time":1791558026769,"timeIso":"2026-10-09T15:00:26.769Z","changes":10,"change":569,"files":["client/src/clean-files.ts","client/src/folder.ts","client/src/status-commands.ts","client/test/client.test.ts","client/test/install.test.ts"],"draft":null,"diff":[{"path":"client/src/clean-files.ts","added":134,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/clean-files.ts\n@@ -0,0 +1,134 @@\n+// Which files `abso status` found the same as their known copy last time, so the\n+// next status reads only the files that may have changed, as git's index does.\n+//\n+// An entry is kept per file: the size, modified time and inode of the file on\n+// disk and of its known copy, each taken before either was read, and whether\n+// the file held a CR. It's trusted only while both still match, and only when\n+// both were changed clearly before the entry was made: a file changed in the\n+// same moment can't be told apart from one changed just after, so it's read.\n+// Anything abso writes into the folder or the known copy changes one side's\n+// size, time or inode, so no writer has to remember to drop entries.\n+//\n+// Only status and the checks it prints use this. record reads every file: a\n+// line status misses is a nuisance, a change record misses is lost work.\n+\n+import { lstatSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from \"node:fs\";\n+import { join } from \"node:path\";\n+import { clientVersion } from \"./client-version.ts\";\n+import { stateDir } from \"./state-dir.ts\";\n+\n+const FILE = \"clean.json\";\n+const FORMAT = 1;\n+/** How much older than an entry a file's time must be to trust it. */\n+const RACY_MS = 2_000;\n+\n+/** A file's place in the record now, taken before it is read. */\n+export interface CleanKey {\n+\treadonly id: string;\n+\t/** The newer of the two modified times. */\n+\treadonly newest: number;\n+\t/** The file on disk's mode bits. */\n+\treadonly mode: number;\n+}\n+\n+interface Entry {\n+\treadonly id: string;\n+\treadonly at: number;\n+\treadonly cr: boolean;\n+}\n+\n+export class CleanFiles {\n+\treadonly #root: string;\n+\treadonly #entries: Map<string, Entry>;\n+\t/** When this run started looking; entries made in it carry this time. */\n+\treadonly #at = Date.now();\n+\treadonly #keys = new Map<string, CleanKey | undefined>();\n+\t#changed = false;\n+\n+\tprivate constructor(root: string, entries: Map<string, Entry>) {\n+\t\tthis.#root = root;\n+\t\tthis.#entries = entries;\n+\t}\n+\n+\t/** The folder's record, or an empty one when it's missing, unreadable, or from another format or client. */\n+\tstatic load(root: string): CleanFiles {\n+\t\tconst entries = new Map<string, Entry>();\n+\t\ttry {\n+\t\t\tconst file = JSON.parse(readFileSync(join(stateDir(root), FILE), \"utf8\")) as {\n+\t\t\t\tformat?: unknown;\n+\t\t\t\tclient?: unknown;\n+\t\t\t\tfiles?: Record<string, [string, number, boolean]>;\n+\t\t\t};\n+\t\t\tif (file.format === FORMAT && file.client === clientVersion() && typeof file.files === \"object\" && file.files)\n+\t\t\t\tfor (const [rel, [id, at, cr]] of Object.entries(file.files))\n+\t\t\t\t\tif (typeof id === \"string\" && typeof at === \"number\" && typeof cr === \"boolean\")\n+\t\t\t\t\t\tentries.set(rel, { id, at, cr });\n+\t\t} catch {}\n+\t\treturn new CleanFiles(root, entries);\n+\t}\n+\n+\t/**\n+\t * The key of a plain file on disk and its known copy; undefined for a link, or when either is missing.\n+\t * Taken once per run: a key taken before a later read is still safe to mark with, since any change\n+\t * after it was taken makes the next run's key differ.\n+\t */\n+\tkey(diskPath: string, knownPath: string): CleanKey | undefined {\n+\t\tif (this.#keys.has(diskPath)) return this.#keys.get(diskPath);\n+\t\tlet key: CleanKey | undefined;\n+\t\ttry {\n+\t\t\tconst disk = lstatSync(diskPath);\n+\t\t\tif (disk.isFile()) {\n+\t\t\t\tconst known = statSync(knownPath);\n+\t\t\t\tkey = {\n+\t\t\t\t\tid: `${disk.size}:${disk.mtimeMs}:${disk.ino}|${known.size}:${known.mtimeMs}:${known.ino}`,\n+\t\t\t\t\tnewest: Math.max(disk.mtimeMs, known.mtimeMs),\n+\t\t\t\t\tmode: disk.mode,\n+\t\t\t\t};\n+\t\t\t}\n+\t\t} catch {}\n+\t\tthis.#keys.set(diskPath, key);\n+\t\treturn key;\n+\t}\n+\n+\t/** Whether the file was the same as its known copy at this key, and if so whether it held a CR; undefined: read it. */\n+\tcheck(rel: string, key: CleanKey): { cr: boolean } | undefined {\n+\t\tconst entry = this.#entries.get(rel);\n+\t\tif (entry === undefined || entry.id !== key.id || key.newest >= entry.at - RACY_MS) return undefined;\n+\t\treturn { cr: entry.cr };\n+\t}\n+\n+\t/** The file, read after `key` was taken, is the same as its known copy. */\n+\tmark(rel: string, key: CleanKey, cr: boolean): void {\n+\t\tconst entry = this.#entries.get(rel);\n+\t\tif (key.newest >= this.#at - RACY_MS) {\n+\t\t\t// Too new to trust next time either; an old entry for it is no use now.\n+\t\t\tif (entry !== undefined) {\n+\t\t\t\tthis.#entries.delete(rel);\n+\t\t\t\tthis.#changed = true;\n+\t\t\t}\n+\t\t\treturn;\n+\t\t}\n+\t\tif (entry?.id === key.id && entry.cr === cr) return;\n+\t\tthis.#entries.set(rel, { id: key.id, at: this.#at, cr });\n+\t\tthis.#changed = true;\n+\t}\n+\n+\t/** The file differs from its known copy, or is gone. */\n+\tdrop(rel: string): void {\n+\t\tif (this.#entries.delete(rel)) this.#changed = true;\n+\t}\n+\n+\t/** Write the record, if anything changed. Best effort: a run that can't write it just reads more next time. */\n+\tsave(): void {\n+\t\tif (!this.#changed) return;\n+\t\ttry {\n+\t\t\tconst dir = stateDir(this.#root);\n+\t\t\tmkdirSync(dir, { recursive: true });\n+\t\t\tconst files = Object.fromEntries([...this.#entries].map(([rel, e]) => [rel, [e.id, e.at, e.cr]]));\n+\t\t\tconst next = join(dir, `${FILE}.${process.pid}.tmp`);\n+\t\t\twriteFileSync(next, JSON.stringify({ format: FORMAT, client: clientVersion(), files }));\n+\t\t\trenameSync(next, join(dir, FILE));\n+\t\t\tthis.#changed = false;\n+\t\t} catch {}\n+\t}\n+}"},{"path":"client/src/folder.ts","added":27,"removed":6,"diff":"--- a/client/src/folder.ts\n+++ b/client/src/folder.ts\n@@ -26,8 +26,9 @@\n import { homedir } from \"node:os\";\n import { dirname, join, relative, sep } from \"node:path\";\n import { blobOf, keptWholeAs, readKnownBlobs } from \"./blobs.ts\";\n+import type { CleanFiles } from \"./clean-files.ts\";\n import { type GitHome, gitIgnoreSetup, type Ignore, isLocalOnly, makeIgnore, normalize, readAllSync } from \"./core.ts\";\n-import { type Mode, modeChange, onDisk, PLAIN, readKnownModes } from \"./modes.ts\";\n+import { FILE_MODE, type Mode, modeChange, onDisk, PLAIN, readKnownModes } from \"./modes.ts\";\n import { stateDir } from \"./state-dir.ts\";\n \n export { type Ignore, isLocalOnly, normalize, withEndingsOf } from \"./core.ts\";\n@@ -279,12 +280,13 @@\n \n // --- the known copy ---\n \n-function knownPath(root: string, rel: string): string {\n-\treturn join(stateDir(root), KNOWN, ...insideParts(rel));\n+/** `state` is the folder's stateDir, for a caller that looks up many files: finding it checks the disk each time. */\n+export function knownPath(root: string, rel: string, state: string = stateDir(root)): string {\n+\treturn join(state, KNOWN, ...insideParts(rel));\n }\n \n-export function readKnown(root: string, rel: string): string | undefined {\n-\treturn readText(knownPath(root, rel));\n+export function readKnown(root: string, rel: string, state?: string): string | undefined {\n+\treturn readText(knownPath(root, rel, state));\n }\n \n export function writeKnown(root: string, rel: string, text: string): void {\n@@ -321,11 +323,15 @@\n  * server's form), known files that are gone (null), and the modes that differ\n  * from the known modes. An empty file is a file like any other (\"\"); a link's\n  * text is \"\".\n+ *\n+ * `clean` lets status skip reading the files it found unchanged last time\n+ * (clean-files.ts). record never passes it, so it always reads every file.\n  */\n export function unrecorded(\n \troot: string,\n \tall = false,\n \tmeantBinary: ReadonlySet<string> = new Set(),\n+\tclean?: CleanFiles,\n ): {\n \tfiles: Map<string, string | null>;\n \tblobs: Map<string, BlobToSend>;\n@@ -342,10 +348,23 @@\n \tconst turnedBinary: TurnedBinary[] = [];\n \t// Exact names: on a case-insensitive disk, known/a.ts would also answer for A.ts, hiding a rename that changes only case.\n \tconst knownPaths = new Set(listKnown(root));\n+\tconst state = stateDir(root);\n \tconst knownBlobs = readKnownBlobs(root);\n \tconst knownModes = readKnownModes(root);\n+\tconst trusted = all ? undefined : clean;\n \tfor (const rel of walk(root, ignore)) {\n \t\tconst was = knownModes.get(rel) ?? PLAIN;\n+\t\t// Taken before the file is read, so an edit during the read changes the key.\n+\t\tconst key =\n+\t\t\ttrusted && knownPaths.has(rel) && was.link === null\n+\t\t\t\t? trusted.key(absolute(root, rel), knownPath(root, rel, state))\n+\t\t\t\t: undefined;\n+\t\tif (key && trusted!.check(rel, key)) {\n+\t\t\tpresent.add(rel);\n+\t\t\tconst change = modeChange(was, { exec: FILE_MODE ? (key.mode & 0o111) !== 0 : was.exec, link: null });\n+\t\t\tif (change) modes[rel] = change;\n+\t\t\tcontinue;\n+\t\t}\n \t\tconst d = onDisk(absolute(root, rel), was);\n \t\tif (d === undefined) continue;\n \t\tif (d.text === undefined) {\n@@ -367,11 +386,13 @@\n \t\t\tif (all || knownBlobs.get(rel) !== b.sha) blobs.set(rel, { sha: b.sha, bytes: b.bytes });\n \t\t} else {\n \t\t\tconst text = normalize(d.text);\n-\t\t\tconst known = knownPaths.has(rel) ? readKnown(root, rel) : undefined;\n+\t\t\tconst known = knownPaths.has(rel) ? readKnown(root, rel, state) : undefined;\n \t\t\tpresent.add(rel);\n \t\t\t// A file the server keeps whole has no known copy, only its hash (#46).\n \t\t\tif (all || (known !== text && !(known === undefined && keptWholeAs(text, knownBlobs.get(rel)))))\n \t\t\t\tout.set(rel, text);\n+\t\t\tif (key && d.link === null && known === text) trusted!.mark(rel, key, d.text.includes(\"\\r\"));\n+\t\t\telse trusted?.drop(rel);\n \t\t}\n \t\t// --all sends every file's whole mode, as it sends every file's text.\n \t\tconst change = all ? { exec: d.exec, link: d.link } : modeChange(was, d);"},{"path":"client/src/status-commands.ts","added":20,"removed":4,"diff":"--- a/client/src/status-commands.ts\n+++ b/client/src/status-commands.ts\n@@ -8,6 +8,7 @@\n import { bool, type Parsed, UsageError } from \"./args.ts\";\n import { readKnownBlobs, writeKnownBlobs } from \"./blobs.ts\";\n import { ciText } from \"./ci.ts\";\n+import { CleanFiles } from \"./clean-files.ts\";\n import { newerCommitNote } from \"./client-version.ts\";\n import { type Env, heard, type Output, open, plural } from \"./command-env.ts\";\n import {\n@@ -26,6 +27,7 @@\n \tabsolute,\n \tforgetKnown,\n \tisLocalOnly,\n+\tknownPath,\n \tlistKnown,\n \tnewFileEndings,\n \tnormalize,\n@@ -68,13 +70,24 @@\n  * line endings (#37: Python's text mode on Windows writes CRLF).\n  * abso records them, and abso run sends them, with LF; a tool run here sees\n  * CRLF. Files git would check out with CRLF are left out of the list.\n+ * With `clean` (status), a file found unchanged before is answered without reading it.\n  */\n-export function crlfOnly(root: string): string[] {\n+export function crlfOnly(root: string, clean?: CleanFiles): string[] {\n \tconst out: string[] = [];\n+\tconst state = stateDir(root);\n \tfor (const rel of listKnown(root)) {\n+\t\tconst key = clean?.key(absolute(root, rel), knownPath(root, rel, state));\n+\t\tconst was = key && clean!.check(rel, key);\n+\t\tif (was) {\n+\t\t\tif (was.cr) out.push(rel);\n+\t\t\tcontinue;\n+\t\t}\n \t\tconst disk = readText(absolute(root, rel));\n \t\tif (disk === undefined || !disk.includes(\"\\r\")) continue;\n-\t\tif (normalize(disk) === readKnown(root, rel)) out.push(rel);\n+\t\tif (normalize(disk) === readKnown(root, rel, state)) {\n+\t\t\tout.push(rel);\n+\t\t\tif (key) clean!.mark(rel, key, true);\n+\t\t}\n \t}\n \tconst git = newFileEndings(root, out);\n \treturn out.filter((rel) => git.get(rel) !== \"crlf\").sort();\n@@ -269,9 +282,11 @@\n \tconst { root, config, api } = open(env);\n \tconst short = bool(args, \"short\");\n \tconst { files: view, ...status } = short ? { ...(await api.status()), files: undefined } : await api.statusAndFiles();\n-\tconst pending = unrecorded(root);\n+\tconst clean = CleanFiles.load(root);\n+\tconst pending = unrecorded(root, false, new Set(), clean);\n \tconst local = new Set([...pending.files.keys(), ...pending.blobs.keys(), ...Object.keys(pending.modes)]);\n \tif (short) {\n+\t\tclean.save();\n \t\t// One word to stamp a build with (#37): 214, coast@3, 214+unpublished.\n \t\tconst me = status.agents.find((a) => a.agent === config.agent);\n \t\tconst unpublished = local.size > 0 || (me?.draftChanges ?? 0) > 0;\n@@ -281,7 +296,8 @@\n \t}\n \tconst missing = view === undefined ? [] : missingHere(root, view.files, local);\n \tconst unwritten = readUnwritten(root);\n-\tconst crlf = crlfOnly(root);\n+\tconst crlf = crlfOnly(root, clean);\n+\tclean.save();\n \t// Files an earlier record added to the draft and that are gone again (#37: scratch files a run\n \t// recorded, deleted after): nothing reached shared, and the next record takes them out of the draft.\n \tconst deleted = [...pending.files].filter(([, text]) => text === null).map(([rel]) => rel);"},{"path":"client/test/client.test.ts","added":67,"removed":1,"diff":"--- a/client/test/client.test.ts\n+++ b/client/test/client.test.ts\n@@ -46,7 +46,7 @@\n \tuncomposedText,\n } from \"../src/core.ts\";\n import { unifiedDiff } from \"../src/diff.ts\";\n-import { absolute, writeFileAtomic } from \"../src/folder.ts\";\n+import { absolute, knownPath, unrecorded, writeFileAtomic } from \"../src/folder.ts\";\n import { runHook } from \"../src/hook.ts\";\n import { tryFolderLock } from \"../src/lock.ts\";\n import { boxServer, commandTable, main } from \"../src/main.ts\";\n@@ -3495,6 +3495,72 @@\n \t\tassert.deepEqual(after.json.unrecorded, []);\n \t});\n \n+\tit(\"status skips reading files it found unchanged before, never trusts one changed too recently, and record still reads every file\", async () => {\n+\t\tconst { folders } = await project({ \"a.txt\": \"a\\n\", \"b.txt\": \"b\\n\", \"c.txt\": \"c\\r\\n\" }, \"alice\", \"bob\");\n+\t\tconst root = folders.alice!;\n+\t\tconst record = join(stateDir(root), \"clean.json\");\n+\t\tconst old = new Date(Date.now() - 60_000);\n+\t\t// The file and its known copy a minute old, as after a quiet spell.\n+\t\tconst age = (...rels: string[]) => {\n+\t\t\tfor (const rel of rels) {\n+\t\t\t\tutimesSync(join(root, rel), old, old);\n+\t\t\t\tutimesSync(knownPath(root, rel), old, old);\n+\t\t\t}\n+\t\t};\n+\t\t// Changes a file without changing its size or time: only reading it can tell.\n+\t\tconst swap = (rel: string, text: string) => {\n+\t\t\tconst was = statSync(join(root, rel));\n+\t\t\twriteFileSync(join(root, rel), text);\n+\t\t\tutimesSync(join(root, rel), was.atime, was.mtime);\n+\t\t};\n+\t\twriteFileSync(join(root, \"c.txt\"), \"c\\r\\n\");\n+\n+\t\t// Files too new to trust are read, and not kept: a swap is still caught. A time a minute ahead stays\n+\t\t// too new however long the run takes.\n+\t\tconst soon = new Date(Date.now() + 60_000);\n+\t\tfor (const rel of [\"a.txt\", \"b.txt\", \"c.txt\"]) utimesSync(join(root, rel), soon, soon);\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, []);\n+\t\tswap(\"a.txt\", \"A\\n\");\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, [\"a.txt\"]);\n+\t\tswap(\"a.txt\", \"a\\n\");\n+\n+\t\t// Old files are kept after one status, and the next answers from the record without reading them.\n+\t\tage(\"a.txt\", \"b.txt\", \"c.txt\");\n+\t\tconst first = await avcs(root, \"status\");\n+\t\tassert.deepEqual(first.json.unrecorded, []);\n+\t\tassert.deepEqual(first.json.crlf, [\"c.txt\"]);\n+\t\tassert.deepEqual(Object.keys(JSON.parse(readFileSync(record, \"utf8\")).files).sort(), [\"a.txt\", \"b.txt\", \"c.txt\"]);\n+\t\tswap(\"b.txt\", \"B\\n\");\n+\t\tconst second = await avcs(root, \"status\");\n+\t\tassert.deepEqual(second.json.unrecorded, [], \"b.txt was answered from the record\");\n+\t\tassert.deepEqual(second.json.crlf, [\"c.txt\"]);\n+\t\t// What record sends is read from every file, whatever the record says.\n+\t\tassert.deepEqual([...unrecorded(root).files.keys()], [\"b.txt\"]);\n+\n+\t\t// A record of an unknown format, or one that doesn't parse, is not used.\n+\t\tconst kept = JSON.parse(readFileSync(record, \"utf8\"));\n+\t\twriteFileSync(record, JSON.stringify({ ...kept, format: 2 }));\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, [\"b.txt\"]);\n+\t\twriteFileSync(record, \"not json\");\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, [\"b.txt\"]);\n+\n+\t\t// An edit that changes the size or time is read at once.\n+\t\tswap(\"b.txt\", \"b\\n\");\n+\t\tage(\"b.txt\");\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, []);\n+\t\twriteFileSync(join(root, \"b.txt\"), \"bb\\n\");\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, [\"b.txt\"]);\n+\n+\t\t// A sync writes the file and its known copy, so what was kept for them no longer holds.\n+\t\twriteFileSync(join(root, \"b.txt\"), \"b\\n\");\n+\t\twrite(folders.bob!, { \"a.txt\": \"a2\\n\" });\n+\t\tassert.equal((await avcs(folders.bob!, \"publish\", \"-m\", \"a2\")).exit, 0);\n+\t\tassert.equal((await avcs(root, \"sync\")).exit, 0);\n+\t\tassert.equal(readFileSync(join(root, \"a.txt\"), \"utf8\"), \"a2\\n\");\n+\t\tswap(\"a.txt\", \"a3\\n\");\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, [\"a.txt\"]);\n+\t});\n+\n \tit(\"several files marked against one version get one settle --theirs hint\", () => {\n \t\tconst c = (file: string, version: number) => ({\n \t\t\tkind: \"lines\" as const,"},{"path":"client/test/install.test.ts","added":3,"removed":0,"diff":"--- a/client/test/install.test.ts\n+++ b/client/test/install.test.ts\n@@ -337,7 +337,10 @@\n \t\tassert.equal(keptModCommit(spec, home), \"fffffff\", \"a kept answer is used while nothing moved\");\n \n \t\t// A file changed in the same moment the answer was kept is never trusted, even when its size and time match.\n+\t\t// A time a minute ahead stays too new however long the run takes.\n \t\twrite(spec.from, \"src/core.ts\", \"export const core = 2\\n\");\n+\t\tconst soon = new Date(Date.now() + 60_000);\n+\t\tutimesSync(at(spec.from, \"src/core.ts\"), soon, soon);\n \t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`);\n \t\tplant();\n \t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`, \"too new to trust: git runs again\");"}],"ci":null}