commit be263d6e77ad710c29318cdf0cd64e9441620e1c
parent dba087ceb758849623057f514a90ba404bcdac8e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 9 Nov 2026 21:40:51 -0500
umtool: ⌘K refuses an @file reference anywhere in a value; a CLI never quotes a file it could not parse (L8a re-review)
buildArgv refuses /(^|[:=,;])\s*['"]?@/ in every positional, list item and key=value (post-json:@…, a=@…, a,@…) -- the CLIs read @file from exactly those; allowAt exempts a cast @handle, a lexicon word and an avatar's handle, and a flag's words and free prose keep their @. timeline order takes entry ids only (no dot, no slash: never a file its CLI would read from its cwd). timeline's jsonArg (post, teaser, insert post-json:), timeline order, candidates add and posts set-item's @file refs now say a file is not JSON (or not an order) by its basename, never JSON.parse's message, which quotes the file's head.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
7 files changed, 91 insertions(+), 23 deletions(-)
diff --git a/umtool/lib/cli/argv.mjs b/umtool/lib/cli/argv.mjs
@@ -19,6 +19,10 @@ const NUMBER = /^-?(\d+\.?\d*|\.\d+)$/;
const BARE = /^[A-Za-z0-9_][\w.+-]*$/;
/** A `..` segment, a home or an absolute path inside a value: a page may not name a path outside the project. */
const ESCAPES = /(^|[\\/])\.\.([\\/]|$)|^~[\\/]|^[\\/]/;
+/** An `@file` reference anywhere in a value -- `@x`, `post-json:@x`, `a=@x`, `a,@x` (review, L8a): a CLI reads it. */
+const AT_REF = /(^|[:=,;])\s*['"]?@/;
+/** A timeline entry's id (`timeline order`: an id, never a file the CLI would read from its cwd). */
+const ENTRY_ID = /^[A-Za-z0-9_][\w:-]*$/;
/** A share URL or a <channel>/<id> (`new --from` from a page: never a file). */
const REF = /^(https?:\/\/\S+|[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9_-]+)$/;
@@ -49,15 +53,35 @@ class FormError extends Error {
}
/** One word of argv from a plain value: no NUL, bounded, and never read as a flag. */
-function word(a, raw, { what = a.name, max = STRING_MAX } = {}) {
+function word(a, raw, { what = a.name, max = STRING_MAX, strictAt = atStrict(a) } = {}) {
const s = String(raw);
if (s.includes("\0")) throw new FormError(`${what}: a NUL byte`, a.name);
if (s.length > max) throw new FormError(`${what}: longer than ${max} characters`, a.name);
// `-` alone is a value (`--after -`); a negative number is a value; anything else that starts with a
// dash would be read as a flag by umtool's parsers.
if (/^-./.test(s) && !NUMBER.test(s.trim())) throw new FormError(`${what}: a value may not start with "-" (it would be read as a flag)`, a.name);
- // `@file` reads a file wherever it is: a terminal's, never a form's (paste what the file holds).
- if (a.atFile && s.startsWith("@")) throw new FormError(`${what}: @file reads a file -- from a terminal only; paste what it holds`, a.name);
+ // `@file` reads a file wherever it is: a terminal's, never a form's (paste what the file holds) -- at the start,
+ // or inside a value a CLI splits (`post-json:@…`, `a=@…`, `a,@…`).
+ if (strictAt && !a.allowAt && AT_REF.test(s)) throw new FormError(`${what}: @file reads a file -- from a terminal only; paste what it holds`, a.name);
+ return s;
+}
+
+/**
+ * Whether an arg's values are checked for `@file` anywhere: a positional (the CLIs that read `@file` read it from
+ * a positional or a key=value), a list's items, a row's `atFile` arg. A flag's words and a positional's free prose
+ * (`text`, not atFile) are a person's words ("@grok said …"); `allowAt` is a handle (`@grok`) or a lexicon word.
+ */
+function atStrict(a) {
+ if (a.allowAt) return false;
+ if (a.atFile) return true;
+ if (a.type === "list" || a.type === "pairs") return true;
+ return !isFlag(a) && a.type !== "text";
+}
+
+/** A timeline entry's id: no dot, no slash -- never a file name. */
+function entryId(a, raw) {
+ const s = word(a, String(raw).trim());
+ if (!ENTRY_ID.test(s)) throw new FormError(`${a.name}: "${s}" is not an entry's id`, a.name);
return s;
}
@@ -71,7 +95,7 @@ function bare(a, raw, what = a.name) {
/** A key=value value from a page: never `@file`, never a path out of the project. */
function pairValue(a, value, what) {
const v = value.trim().replace(/^['"]/, "");
- if (v.startsWith("@")) throw new FormError(`${what}: @file reads a file -- from a terminal only; paste what it holds`, a.name);
+ if (AT_REF.test(v)) throw new FormError(`${what}: @file reads a file -- from a terminal only; paste what it holds`, a.name);
if (ESCAPES.test(v)) throw new FormError(`${what}: a path outside the project (.., ~ or /) -- from a terminal only`, a.name);
return value;
}
@@ -145,7 +169,7 @@ function wordsOf(a, v) {
const out = [];
for (const line of lines) {
if (a.type === "list") {
- const w = a.item === "name" ? bare(a, line) : a.item === "pair" ? pairWord(a, line) : a.item === "ref" ? refWord(a, line) : word(a, line);
+ const w = a.item === "id" ? entryId(a, line) : a.item === "name" ? bare(a, line) : a.item === "pair" ? pairWord(a, line) : a.item === "ref" ? refWord(a, line) : word(a, line);
out.push(...(isFlag(a) ? [a.name, w] : [w]));
continue;
}
diff --git a/umtool/lib/cli/verbs.mjs b/umtool/lib/cli/verbs.mjs
@@ -35,13 +35,15 @@
// pairs key=value lines, each one argv word (a positional run)
// flagpairs key=value lines, each `--key value`
// list several values: a positional run, or (`repeat`) the flag once per value
-// (`item: "name"` each a bare name; `item: "pair"` each key=value; `item: "ref"` each a ref)
+// (`item: "id"` each an entry id; `item: "name"` each a bare name; `item: "pair"` each key=value; `item: "ref"` each a ref)
// name a bare name: no directory, no `..`, no leading dot (`--out`, a take's id, a reel)
// path a file of the project, relative to its directory: POST /api/cli runs it only when
// its realpath is inside the project's, as that absolute path (`pass: "relative"`: as typed)
// ref a share URL or <channel>/<id>, never a file (`new --from`)
// literals values a name or path arg also takes as words ("none", "off")
-// atFile the CLI reads `@file` here: a form may not (the file could be anywhere)
+// atFile the CLI reads `@file` here: a form may not (the file could be anywhere). Every positional, list item
+// and key=value is refused an `@file` reference anywhere in it (`post-json:@x`, `a,@x`); `allowAt`
+// exempts a handle (`@grok`) or a lexicon word; a flag's words and free prose (`text`) are a person's.
// context "clip" | "post" | "take": filled from the page's selection (its URL: /clip/<id>,
// /post/<id>, /takes/<id>, ?clip=, ?take=)
//
@@ -109,11 +111,11 @@ export const VERBS = Object.freeze([
form("cast undo", "corpus", "the cast as it was before its last write", []),
form("cast project", "project", "the project's characters, their voices and drift", [project()]),
form("cast audition", "project", "one line read by 2-6 candidate voices, scored against the real voice", [
- arg("character", { help: "a character id or @handle" }), opt("--voices", { required: true, help: "engine:voice,engine:voice,…" }), project({ name: "--project", required: false }),
+ arg("character", { allowAt: true, help: "a character id or @handle" }), opt("--voices", { required: true, help: "engine:voice,engine:voice,…" }), project({ name: "--project", required: false }),
opt("--text", { type: "text" }), opt("--item"), num("--line"), bool("--stock"), bool("--no-score"), bool("--score-only"),
], Q),
- form("cast use", "draft", "the voice a character reads in, here or everywhere", [project(), arg("character"), arg("voice", { help: "engine:voice" }), bool("--everywhere", "the cast's voice, not this project's")], { shape: "cast use <project> <character> <voice>" }),
- form("cast reread", "project", "the items that say a character in another voice, read again", [project(), arg("character"), dry()], Q),
+ form("cast use", "draft", "the voice a character reads in, here or everywhere", [project(), arg("character", { allowAt: true }), arg("voice", { help: "engine:voice" }), bool("--everywhere", "the cast's voice, not this project's")], { shape: "cast use <project> <character> <voice>" }),
+ form("cast reread", "project", "the items that say a character in another voice, read again", [project(), arg("character", { allowAt: true }), dry()], Q),
form("speaker-check", "project", "which named voice each clip is (speaker-check.json)", [
project(), many("--clip", { repeat: true, help: "clip ids, one per line (none: every clip)" }), bool("--list", "list the named voices"),
@@ -373,7 +375,7 @@ function timeline() {
tl("section-set", "draft", "a section's label, colour or level", [marker(), opt("--label"), opt("--color"), pick("--level", ["1", "2"])]),
tl("split", "draft", "a clip in two at a source second", [id(), num("second", { required: true })]),
tl("flash-forward", "draft", "a tight copy of a span elsewhere, as a repeat", [id(), arg("span", { help: "<from>-<to>" }), opt("--after"), num("--to-section"), bool("--start"), bool("--move", "the span leaves the clip"), opt("--quote"), opt("--id")]),
- tl("order", "draft", "the cut's order in one write", [many("order", { required: true, item: "name", help: "entry ids in order, one per line" })]),
+ tl("order", "draft", "the cut's order in one write", [many("order", { required: true, item: "id", help: "entry ids in order, one per line" })]),
tl("threads", "draft", "the cut's conversations (and --write gathers them)", [bool("--write"), opt("--conversation")]),
tl("groups", "project", "the claim groups, by section", []),
tl("groups import", "draft", "a claim-groups file in one write", [file("file", { help: "a claim-groups file of the project" }), bool("--skip-missing"), bool("--drop-empty")]),
@@ -408,7 +410,7 @@ function posts() {
num("--limit"), bool("--force"), file("--recording", { help: "a person's recording (a file of the project) made the read" }), opt("--as"), dry(),
pairs({ required: false, help: "the mix: lead= tail= linger= rate= …, one per line" }), inTake(),
], Q),
- p("say", "draft", "the pronunciation lexicon", [pick("op", ["ls", "add", "remove", "try", "stale"], { required: true }), arg("word", { required: false, help: "the word or phrase (try: the text)" }), arg("spoken", { required: false }), bool("--case"), opt("--item"), opt("--note")], { shape: "posts say <project> <op>" }),
+ p("say", "draft", "the pronunciation lexicon", [pick("op", ["ls", "add", "remove", "try", "stale"], { required: true }), arg("word", { required: false, allowAt: true, help: "the word or phrase (try: the text)" }), arg("spoken", { required: false }), bool("--case"), opt("--item"), opt("--note")], { shape: "posts say <project> <op>" }),
p("voices", "draft", "the voice map a thread read uses", [pick("op", ["ls", "set", "remove"], { required: true }), arg("handle", { required: false, help: "a handle, or *" }), arg("voice", { required: false })], { shape: "posts voices <project> <op>" }),
p("fit", "draft", "narrated posts' videos cut to their best part", [items(), bool("--all"), num("--linger"), dry()], Q),
p("fx", "draft", "a post item's word zooms, captions, clock, slams", [
@@ -417,7 +419,7 @@ function posts() {
], { shape: "posts fx <project> <item> <op>" }),
p("clock", "draft", "the cut's clock default", [pick("mode", ["on", "off", "default"]), opt("--zone", { help: "an IANA zone" })]),
p("progress", "draft", "the cut's progress bar default", [pick("mode", ["auto", "on", "off", "default"])]),
- p("avatar", "draft", "an author's picture on the cards", [arg("handle", { required: false }), file("image", { required: false, literals: ["off"], help: "a picture file of the project, or off" })]),
+ p("avatar", "draft", "an author's picture on the cards", [arg("handle", { required: false, allowAt: true }), file("image", { required: false, literals: ["off"], help: "a picture file of the project, or off" })]),
p("avatars", "draft", "the authors' pictures from the archive", [dry()]),
p("redact", "draft", "words blanked from what is published", [pick("op", ["ls", "add", "remove"], { required: true }), arg("value", { required: false, help: "the term (add), its n (remove)" }), bool("--substring"), opt("--note")], { shape: "posts redact <project> <op>" }),
p("slurs", "draft", "the slur filter", [pick("op", ["ls", "on", "off", "level", "visual", "voice", "add", "except", "remove", "edges"], { required: true }), arg("value", { required: false }), bool("--off")], { shape: "posts slurs <project> <op>" }),
diff --git a/umtool/lib/cli/verbs.test.mjs b/umtool/lib/cli/verbs.test.mjs
@@ -245,7 +245,18 @@ test("names, paths, refs and @file: what a page may not send", () => {
no(verbRow("take"), { project: "p", "--id": "t", "--patch": "@/etc/passwd" }, /no @/);
no(verbRow("candidates add"), { project: "p", proposal: "@/etc/passwd" }, /terminal only/);
no(verbRow("timeline teaser"), { project: "p", id: "t1", patch: "@x.json" }, /terminal only/);
- no(verbRow("timeline order"), { project: "p", order: "/etc/passwd" }, /bare name/);
+ for (const o of ["/etc/passwd", "package.json", "@ids.txt", "../x"]) no(verbRow("timeline order"), { project: "p", order: o }, /not an entry's id|start with "-"|terminal only/);
+ assert.deepEqual(buildArgv(verbRow("timeline order"), { project: "p", order: "c01\nx-1987\nt:2" }).argv, ["timeline", "p", "order", "c01", "x-1987", "t:2"]);
+ // An @file reference anywhere a CLI splits a value (review): post-json:@…, a=@…, a,@….
+ for (const spec of ["post-json:@/etc/passwd", "post-json: @x.json", "@x", "post:@x"]) no(verbRow("timeline insert"), { project: "p", spec, "--after": "-" }, /terminal only/);
+ for (const settings of ["a=b,@/etc/passwd", "deck.markers=@m.json", "x=1;@y", "chat='@f'"]) no(verbRow("look"), { project: "p", settings }, /terminal only/);
+ no(verbRow("posts set-item"), { project: "p", item: "i1", settings: 'link.add= @/etc/passwd' }, /terminal only/);
+ no(verbRow("timeline set-video"), { project: "p", id: "v1", settings: "src=@x" }, /terminal only/);
+ // A person's words keep their @: a flag's value, free prose, a handle, a lexicon word, a pause at a take second.
+ assert.ok(buildArgv(verbRow("timeline insert"), { project: "p", spec: "yt/abc@1-5", "--quote": "@grok said, @x", "--title": "@sam" }).ok, "<channel>/<video>@<start>-<end> is not a file");
+ assert.ok(buildArgv(verbRow("notes reply"), { id: "n1", text: "@operator: done" }).ok);
+ assert.ok(buildArgv(verbRow("posts say"), { project: "p", op: "add", word: "@grok", spoken: "At grok" }).ok);
+ assert.ok(buildArgv(verbRow("posts reread"), { project: "p", item: "i1", "--pause": "@12.5=0.4" }).ok);
for (const v of ["@/etc/passwd", "/etc/passwd", "../../x", "~/x", "a/../../b", "'@x'"]) no(verbRow("posts set-item"), { project: "p", item: "i1", settings: `parent.0=${v}` }, /terminal only|outside the project/);
no(verbRow("take"), { project: "p", "--id": "t", "--set": "render.x=@f" }, /terminal only/);
no(verbRow("ledger add"), { project: "p", id: "r", more: "src=../../etc" }, /outside the project/);
diff --git a/umtool/lib/report/candidatesCli.mjs b/umtool/lib/report/candidatesCli.mjs
@@ -86,12 +86,14 @@ export async function candidatesCommand(args, { root = REPORTS_ROOT, out = (s) =
if (verb === "add") {
if (!arg) throw new CliError("add needs a JSON proposal (or @file)");
- const raw = arg.startsWith("@") ? await readFile(path.resolve(arg.slice(1)), "utf8") : arg;
+ const fromFile = arg.startsWith("@");
+ const raw = fromFile ? await readFile(path.resolve(arg.slice(1)), "utf8") : arg;
let v;
try {
v = JSON.parse(raw);
} catch (e) {
- throw new CliError(`add: not JSON (${e instanceof Error ? e.message : e})`);
+ // A file's words are never quoted back (JSON.parse's message carries its head): its name only.
+ throw new CliError(fromFile ? `add: ${path.basename(arg.slice(1))} is not JSON` : `add: not JSON (${e instanceof Error ? e.message : e})`);
}
const list = (Array.isArray(v) ? v : Array.isArray(v?.candidates) ? v.candidates : [v]).map((p) => normalizeProposal(p));
const res = await addCandidates(project.dir, list, { by });
diff --git a/umtool/lib/report/postsCli.mjs b/umtool/lib/report/postsCli.mjs
@@ -910,10 +910,12 @@ const REF_KEYS = ["id", "author", "handle", "badge", "date", "text", "url", "med
/** A context post given on the command line: JSON, or `@<file>.json`. Its `media` may name project files. */
const refArg = (raw, k) => {
let j;
+ const file = raw.trim().startsWith("@") ? raw.trim().slice(1) : null;
try {
- j = JSON.parse(raw.trim().startsWith("@") ? readFileSyncText(raw.trim().slice(1)) : raw);
+ j = JSON.parse(file ? readFileSyncText(file) : raw);
} catch (e) {
- throw new CliError(`${k}= takes a post as JSON ({"id","handle","author","date","text"}) or @<file>.json -- ${e.message}`);
+ // A file's words are never quoted back (JSON.parse's message carries its head): its name only.
+ throw new CliError(`${k}= takes a post as JSON ({"id","handle","author","date","text"}) or @<file>.json -- ${file ? `${path.basename(file)} is not JSON` : e.message}`);
}
if (!j || typeof j !== "object" || Array.isArray(j)) throw new CliError(`${k}= takes a post as a JSON object`);
const bad = Object.keys(j).filter((x) => !REF_KEYS.includes(x));
diff --git a/umtool/lib/report/timelineCli.mjs b/umtool/lib/report/timelineCli.mjs
@@ -238,11 +238,13 @@ async function handPostItem(project, manifest, raw, { id = null } = {}) {
async function jsonArg(raw, what) {
if (raw === undefined || raw === "") throw new CliError(`${what} needs a JSON value (or @file)`);
- const text = raw.startsWith("@") ? await readFile(path.resolve(raw.slice(1)), "utf8") : raw;
+ const fromFile = raw.startsWith("@");
+ const text = fromFile ? await readFile(path.resolve(raw.slice(1)), "utf8") : raw;
try {
return JSON.parse(text);
} catch (e) {
- throw new CliError(`${what}: not JSON (${e instanceof Error ? e.message : e})`);
+ // A file's words are never quoted back (JSON.parse's message carries its head): its name only.
+ throw new CliError(fromFile ? `${what}: ${path.basename(raw.slice(1))} is not JSON` : `${what}: not JSON (${e instanceof Error ? e.message : e})`);
}
}
@@ -776,20 +778,31 @@ export async function timelineCommand(args, { root = REPORTS_ROOT, out = (s) =>
case "order": {
if (!rest.length) throw new CliError("order needs the ids in their new order, or a file of them (@file)");
let text = rest.join(" ");
+ let fromFile = null;
if (rest.length === 1) {
const f = rest[0].startsWith("@") ? rest[0].slice(1) : rest[0];
const file = path.resolve(f);
const read = await readFile(file, "utf8").catch(() => null);
- if (read !== null) text = read;
+ if (read !== null) {
+ text = read;
+ fromFile = path.basename(file);
+ }
else if (rest[0].startsWith("@")) throw new CliError(`cannot read ${file}`);
}
let ids;
try {
ids = parseOrderText(text);
} catch (e) {
- throw new CliError(`order: ${e instanceof Error ? e.message : e}`);
+ // A file's words are never quoted back: its name only.
+ throw new CliError(fromFile ? `order: ${fromFile} is not an order (ids, a JSON list, {order} or a claim-groups file)` : `order: ${e instanceof Error ? e.message : e}`);
+ }
+ try {
+ ({ result, editNotes } = await write((token) => orderEntries(project.dir, ids, { token })));
+ } catch (e) {
+ // From a file, what it held is not echoed (it could be any file): its name and its count.
+ if (!fromFile) throw e;
+ throw new CliError(`order: ${fromFile} (${ids.length} id${ids.length === 1 ? "" : "s"}) is not an order of this cut's entries`);
}
- ({ result, editNotes } = await write((token) => orderEntries(project.dir, ids, { token })));
break;
}
case "groups": {
diff --git a/umtool/lib/report/timelineCli.test.mjs b/umtool/lib/report/timelineCli.test.mjs
@@ -213,3 +213,17 @@ test("teaser, post and post-remove (JSON or @file); a generated manifest gets it
const notes = JSON.parse(await readFile(path.join(dir, "notes.json"), "utf8"));
assert.ok(notes.notes.length > 0);
});
+
+test("a file read with @ that is not JSON (or an order file that is not an order) is named, never quoted (L8a review)", async () => {
+ await project("leak");
+ const secret = path.join(ROOT, "secret.txt");
+ await writeFile(secret, "root:x:0:0:THE-SECRET-HEAD\n");
+ for (const args of [["leak", "post", `@${secret}`], ["leak", "teaser", "t1", `@${secret}`], ["leak", "insert", "--after", "-", `post-json:@${secret}`], ["leak", "order", `@${secret}`], ["leak", "order", secret]]) {
+ const { lines, run } = runner();
+ const code = await run(...args);
+ assert.notEqual(code, 0, args.join(" "));
+ const said = lines.join("\n");
+ assert.ok(!said.includes("THE-SECRET") && !said.includes("root:x"), `${args.join(" ")} quoted the file: ${said}`);
+ assert.match(said, /secret\.txt/, args.join(" "));
+ }
+});