From b6f72ffdcdfb2cf8db42bf99bd0aa0df5dc7e085 Mon Sep 17 00:00:00 2001 From: James Briggs <35938317+jamescalam@users.noreply.github.com> Date: Mon, 16 Nov 2026 14:12:26 +0800 Subject: [PATCH 1/2] Docs: pages open in Edit: the starter carries , and a page made before gets it with its next save The app opens a page with that meta in Edit for a person who may edit it, read in the frame when the page loads. The starter now carries it, right after the ledger. A page the skill made before (1.0.0 to 1.0.2) gets it in the ledger change its next save makes (write, edit, propose, apply, done's Checked save, outline on a typed page), once, and only when the ledger is in and the page has no meta of that name already, with any value. start only reads, so it never adds it. The 1.0 starter is frozen as assets/blank-starter-1.0.html and still counts as blank, and as the base for typed lines. SKILL.md says the person may be typing while the agent writes. Co-authored-by: Pointman Co-authored-by: Claude --- docs/SKILL.md | 4 + docs/assets/blank-starter-1.0.html | 55 +++++++++++ docs/assets/docs.js | 49 +++++++--- docs/references/page.html | 1 + tests/edit.js | 145 +++++++++++++++++++++++++++++ tests/run.js | 2 +- 6 files changed, 242 insertions(+), 14 deletions(-) create mode 100644 docs/assets/blank-starter-1.0.html create mode 100644 tests/edit.js diff --git a/docs/SKILL.md b/docs/SKILL.md index c274ec1..c84b049 100644 --- a/docs/SKILL.md +++ b/docs/SKILL.md @@ -18,5 +18,9 @@ thinking; the headings follow within 30 seconds, and a new section at least ever Plan one section, write it, then plan the next: never plan the whole document before its first section goes in. +**The person may be typing on the page while you write.** Docs pages open in Edit for +them. What they type is theirs: `docs.js` writes around it and never changes it, and +`blocks` shows it. Don't wait for them to stop, and don't repeat or undo what they wrote. + You write text, never the page: `docs.js` turns it into the page, shows it on every open tab and saves it. Never deploy, push or edit the page any other way. diff --git a/docs/assets/blank-starter-1.0.html b/docs/assets/blank-starter-1.0.html new file mode 100644 index 0000000..a906224 --- /dev/null +++ b/docs/assets/blank-starter-1.0.html @@ -0,0 +1,55 @@ + + + + + + +Document + + + + +
+
+ + diff --git a/docs/assets/docs.js b/docs/assets/docs.js index d6d5f20..5c3a2db 100644 --- a/docs/assets/docs.js +++ b/docs/assets/docs.js @@ -35,6 +35,7 @@ const WRITING = path.join(__dirname, "..", "references", "writing.md"); const OUTLINE = path.join(__dirname, "..", "references", "outline.md"); const BLANK_LIVE_LINK = path.join(__dirname, "blank-live-link.html"), BLANK_LIVE_LINK_NODESC = path.join(__dirname, "blank-live-link-nodesc.html"); const BLANK_NEW_SPACE = path.join(__dirname, "blank-new-space.html"); +const BLANK_STARTER_1 = path.join(__dirname, "blank-starter-1.0.html"); const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; const PLACEHOLDER = "Writing…"; const WORDS_FAR = 600; // words no A4 page of the starter holds @@ -155,6 +156,25 @@ function ledgerMeta(html) { const LEDGER = { exec: (html) => { const t = ledgerMeta(html); return t ? [t] : null; } }; function ledgerOf(html) { const t = ledgerMeta(html), m = t && /content="([^"]*)"/.exec(t); if (!m) return null; try { return JSON.parse(decode(m[1])); } catch { return null; } } const ledgerTag = (L) => ``; +// The page opens in Edit: Spacesheep's frame reads when the page loads, and +// opens it in Edit for a person who may edit it (16 Nov 2026). The starter carries it. A page of this skill made +// before then gets it with its next save, as part of the ledger change every save makes, right after the ledger +// in its head; it takes effect the next time the page is opened. A page with a meta of that name already, with +// any value, keeps it as it is. start only reads, so it never adds it. +const EDIT_META = ''; +function hasEditMeta(html) { + let n = 0; + walk(parse(html), (e) => { if (e.name === "meta" && /\sname\s*=\s*(["']?)ss-edit\1(?=[\s\/>])/i.test(html.slice(e.start, e.openEnd))) n++; }); + return n > 0; +} +function editAdd(html) { + const t = ledgerMeta(html); + if (!t || hasEditMeta(html)) return ""; + let inHead = false; + walk(parse(html), (e) => { if (e.name === "meta" && outer(html, e) === t && e.parent.name === "head") inHead = true; }); + return inHead ? "\n" + EDIT_META : ""; +} +const ledgerSwap = (html, NL) => ({ old_string: LEDGER.exec(html)[0], new_string: ledgerTag(NL) + editAdd(html) }); // Whose each block of a section is, and where the section is. function sectionView(html, root, L, n) { @@ -212,7 +232,7 @@ function planWrite(html, n, text) { for (const [a, b, h] of splices.sort((x, y) => y[0] - x[0])) secNew = secNew.slice(0, a - v.sec.start) + h + secNew.slice(b - v.sec.start); const replacements = []; if (secNew !== secOld) replacements.push({ old_string: secOld, new_string: secNew }); - replacements.push({ old_string: LEDGER.exec(html)[0], new_string: ledgerTag(NL) }); + replacements.push(ledgerSwap(html, NL)); return { edits, replacements, kept, changed: edits.length, ledger: NL }; } @@ -244,7 +264,7 @@ function planBlock(html, id, text, { mine, sigWas }) { if (rest.length) edits.push({ anchor: id, op: "insert_after", html: rest.join("\n") }); } const secOld = outer(html, sec), secNew = secOld.slice(0, rep[0] - sec.start) + rep[2] + secOld.slice(rep[1] - sec.start); - return { edits, replacements: [{ old_string: secOld, new_string: secNew }, { old_string: LEDGER.exec(html)[0], new_string: ledgerTag(NL) }], kept: [], ledger: NL }; + return { edits, replacements: [{ old_string: secOld, new_string: secNew }, ledgerSwap(html, NL)], kept: [], ledger: NL }; } // The starter with this document's title and headings, each with a placeholder, after whatever its
holds @@ -268,7 +288,7 @@ function buildPage(starter, title, headings, pages, theirTitle) { }); const swaps = [ [/[\s\S]*?<\/title>/, () => `<title>${esc(title)}`], - [//, () => ledgerTag(L)], + [//, () => ledgerTag(L) + editAdd(starter)], [/(
]*>)([\s\S]*?)(<\/main>)/, (m, a, kept, b) => `${a}${kept.replace(/\s+$/, "")}\n${parts.join("\n")}\n${b}`], ]; let page = starter; @@ -285,7 +305,8 @@ const spaceOf = (ctx) => { try { return fs.readFileSync(spaceFile(ctx.dir), "utf // Blank is a short closed list of whole pages, compared after dropping whitespace: an empty file, this skill's // starter before any outline, staging's "working on it" page (live_link, saved 14 Nov 2026) in its two forms, // with a description line and without, whose title and description are plain-text slots, and the app's empty -// sheet a space starts as from New space or Start from blank (saved 15 Nov 2026), whose title is a plain-text slot. Everything else is the person's page, however empty it looks: a wrong "not +// sheet a space starts as from New space or Start from blank (saved 15 Nov 2026), whose title is a plain-text slot, +// and the starter as Docs 1.0.0 to 1.0.2 made it, before it opened in Edit. Everything else is the person's page, however empty it looks: a wrong "not // blank" costs one question; a wrong "blank" deletes someone's work. const flat = (t) => String(t).replace(/\s+/g, ""); // Each slot is text only and stays where it is, in its exact tag; nothing is taken out before the comparison. @@ -305,13 +326,14 @@ function newSpaceSlots(html) { return titles.length === 1 && /[^<]*<\/title>/.test(html) ? html.replace(/<title>[^<]*<\/title>/, "<title>T") : null; } let BLANKS = null; -const blanks = () => BLANKS || (BLANKS = [STARTER, BLANK_LIVE_LINK, BLANK_LIVE_LINK_NODESC, BLANK_NEW_SPACE].map((f) => flat(fs.readFileSync(f, "utf8")))); +const blanks = () => BLANKS || (BLANKS = [STARTER, BLANK_LIVE_LINK, BLANK_LIVE_LINK_NODESC, BLANK_NEW_SPACE, BLANK_STARTER_1].map((f) => flat(fs.readFileSync(f, "utf8")))); +const isStarter = (f) => f === blanks()[0] || f === blanks()[4]; function blank(html) { const B = blanks(), h = flat(html), slotted = liveLinkSlots(String(html)), sf = slotted === null ? null : flat(slotted); const ns = newSpaceSlots(String(html)), nf = ns === null ? null : flat(ns); - return h === "" || h === B[0] || sf === B[1] || sf === B[2] || nf === B[3]; + return h === "" || isStarter(h) || sf === B[1] || sf === B[2] || nf === B[3]; } -// Docs' starter with lines the person typed on it, and nothing else: the app saves the first line inside the +// Docs' starter (either form) with lines the person typed on it, and nothing else: the app saves the first line inside the // starter's
, or in above it (before 16 Nov 2026). The lines are the person's: each stays where it // is, as it is, and the document goes after them. Text blocks only, so a picture, a frame, a script, a form, a // handler or an id of the tool's makes the page theirs. Answers the lines with their words, or null. @@ -350,7 +372,7 @@ function typedLines(html) { if (!lines.length || !lines.every((el) => typedOk(html, el, true))) return null; let rest = html; for (const el of lines.slice().sort((a, b) => b.start - a.start)) rest = rest.slice(0, el.start) + rest.slice(el.end); - if (flat(rest) !== blanks()[0]) return null; + if (!isStarter(flat(rest))) return null; return lines.map((el) => ({ inMain: el.parent === main, text: words(inner(html, el)) })); } const foreign = (html) => !ledgerOf(html) && !blank(html) && !typedLines(html); @@ -436,7 +458,7 @@ function closeRun(ctx, r, html, L) { const NL = Object.assign({}, L, { checked: true }); const live = noopPatch(html, parse(html), L); try { - ctx.io.save(Object.assign({ parent: r.version, label: "Checked", replacements: [{ old_string: span, new_string: ledgerTag(NL) + span.slice(tag.length) }] }, live ? { live_patch: [live] } : {})); + ctx.io.save(Object.assign({ parent: r.version, label: "Checked", replacements: [{ old_string: span, new_string: ledgerTag(NL) + editAdd(html) + span.slice(tag.length) }] }, live ? { live_patch: [live] } : {})); return true; } catch (e) { if (!isConflict(e)) throw e; return false; } } @@ -578,7 +600,7 @@ const COMMANDS = { const edit = { anchor: "d-doc", op: "append_into", html: page.slice(at, m1.closeStart).trim() }; const swap = (re) => ({ old_string: re.exec(html)[0], new_string: re.exec(page)[0] }); a = ctx.io.push({ edits: [edit] }); - try { ctx.io.save({ parent: r.version, label: "Outline", replacements: [swap(/[\s\S]*?<\/title>/), swap(LEDGER), { old_string: outer(html, m0), new_string: outer(page, m1) }], live_patch: [edit] }); } + try { ctx.io.save({ parent: r.version, label: "Outline", replacements: [swap(/<title>[\s\S]*?<\/title>/), { old_string: LEDGER.exec(html)[0], new_string: LEDGER.exec(page)[0] + editAdd(html) }, { old_string: outer(html, m0), new_string: outer(page, m1) }], live_patch: [edit] }); } catch (e) { if (!isConflict(e)) throw e; ctx.io.push({ edits: [...(theirs ? [] : ["d-title"]), ...["", ...headings].map((_, k) => `d-s${k}`)].map((id) => ({ anchor: id, op: "remove" })) }); @@ -657,8 +679,9 @@ const COMMANDS = { NL.proposals = NL.proposals || {}; NL.proposals[cid] = { changes: [{ block: id, sig: sig(html, el), text: String(text) }] }; try { - ctx.io.save({ parent: r.version, label: `Proposal on ${id}`, replacements: [{ old_string: LEDGER.exec(html)[0], new_string: ledgerTag(NL) }] }); - afterSave(ctx, html.replace(LEDGER.exec(html)[0], () => ledgerTag(NL)), null); + const swap = ledgerSwap(html, NL); + ctx.io.save({ parent: r.version, label: `Proposal on ${id}`, replacements: [swap] }); + afterSave(ctx, html.replace(swap.old_string, () => swap.new_string), null); ctx.log(`proposed on ${id}: comment ${cid.slice(0, 8)}. Nothing changes until the person answers yes there; then apply ${cid.slice(0, 8)}`); return 0; } catch (e) { if (!isConflict(e)) throw e; ctx.io.resolve(cid); } @@ -683,7 +706,7 @@ const COMMANDS = { }); P.changes.forEach((ch, i) => commit(ctx, `${ch.block}, as proposed`, null, (html) => { const p = planBlock(html, ch.block, ch.text, { sigWas: ch.sig }); - if (i === P.changes.length - 1) { delete p.ledger.proposals[c.id]; p.replacements[p.replacements.length - 1] = { old_string: LEDGER.exec(html)[0], new_string: ledgerTag(p.ledger) }; } + if (i === P.changes.length - 1) { delete p.ledger.proposals[c.id]; p.replacements[p.replacements.length - 1] = ledgerSwap(html, p.ledger); } return p; })); ctx.io.comment({ reply_to: c.id, body: AGENT + "Changed, as you said yes to." }); diff --git a/docs/references/page.html b/docs/references/page.html index a906224..f74770d 100644 --- a/docs/references/page.html +++ b/docs/references/page.html @@ -6,6 +6,7 @@ <meta name="color-scheme" content="light dark"> <title>Document +