Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
55 changes: 55 additions & 0 deletions docs/assets/blank-starter-1.0.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light dark">
<title>Document</title>
<meta name="docs-ledger" content="">
<style>
:root {
--paper: #fdfcfa; --ink: #1d1c1a; --soft: #5e5a54; --rule: #e4e0d9; --link: #2453a6; --todo: #9a948b; --blank: #f1e8cf;
--body: "Iowan Old Style", "Charter", "Georgia", "Times New Roman", serif;
--head: ui-sans-serif, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
:root { --paper: #191816; --ink: #ece8e1; --soft: #aaa399; --rule: #34312c; --link: #8fb1ff; --todo: #77716a; --blank: #3b3626; }
}
* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 18px/1.6 var(--body); }
main { max-width: calc(65ch + 2.5rem); margin: 0 auto; padding: 3rem 1.25rem 5rem; }
h1, h2, h3 { font-family: var(--head); line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 2rem; margin: 0 0 1rem; }
h2 { font-size: 1.25rem; margin: 2.25rem 0 0.5rem; }
h3 { font-size: 1.05rem; margin: 1.5rem 0 0.25rem; }
p, ul, ol, blockquote { margin: 0 0 1rem; }
ul, ol { padding-left: 1.4rem; }
li { margin: 0.25rem 0; }
blockquote { border-left: 3px solid var(--rule); padding-left: 1rem; color: var(--soft); }
a { color: var(--link); }
section[data-ss-id="d-s0"] p { font-size: 1.1rem; }
mark.blank { background: var(--blank); color: inherit; border-radius: 3px; padding: 0 0.15em; }
mark.blank:focus { outline: 2px solid var(--link); outline-offset: 1px; }
.todo:empty::before { content: "Writing…"; color: var(--todo); font-style: italic; }
@media (max-width: 480px) { body { font-size: 17px; } main { padding-top: 2rem; } h1 { font-size: 1.6rem; } }
@page { size: A4; margin: 16mm 18mm; }
@media print {
html { background: #fff; color: #000; }
body { font-size: 11pt; line-height: 1.4; }
main { max-width: none; padding: 0; }
h1 { font-size: 17pt; margin: 0 0 8pt; }
h2 { font-size: 12.5pt; margin: 12pt 0 3pt; break-after: avoid; }
h3 { font-size: 11pt; margin: 8pt 0 2pt; break-after: avoid; }
p, ul, ol, blockquote { margin: 0 0 6pt; }
section[data-ss-id="d-s0"] p { font-size: 11.5pt; }
mark.blank { background: none; padding: 0; }
a { color: inherit; }
}
</style>
</head>
<body>
<main data-ss-id="d-doc">
</main>
</body>
</html>
91 changes: 78 additions & 13 deletions docs/assets/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -155,6 +156,67 @@ 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) => `<meta name="docs-ledger" content="${esc(JSON.stringify(L))}">`;
// The page opens in Edit: Spacesheep's frame reads <meta name="ss-edit" content="open"> 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 = '<meta name="ss-edit" content="open">';
// An element's attributes as the browser reads its start tag: names lower-cased (ASCII only), the first of a
// repeated name kept, values in either quote or none, separated by whitespace or "/". Values are as written;
// attrText decodes them.
const HTML_WS = "\t\n\f\r ";
function attrsOf(html, el) {
const s = html.slice(el.start + 1 + el.name.length, el.openEnd - 1), out = new Map(), ws = (c) => HTML_WS.includes(c);
let i = 0;
while (i < s.length) {
while (i < s.length && (ws(s[i]) || s[i] === "/")) i++;
if (i >= s.length) break;
let j = i + 1; // a name's first character can be "="
while (j < s.length && !ws(s[j]) && s[j] !== "/" && s[j] !== "=") j++;
const name = s.slice(i, j).replace(/[A-Z]/g, (c) => c.toLowerCase());
i = j;
while (i < s.length && ws(s[i])) i++;
let value = "";
if (s[i] === "=") {
i++;
while (i < s.length && ws(s[i])) i++;
if (s[i] === '"' || s[i] === "'") { const k = s.indexOf(s[i], i + 1), end = k < 0 ? s.length : k; value = s.slice(i + 1, end); i = end + 1; }
else { let k = i; while (k < s.length && !ws(s[k])) k++; value = s.slice(i, k); i = k; }
}
if (!out.has(name)) out.set(name, value);
}
return out;
}
// A value as the browser decodes it, as far as comparing it with a plain ASCII name needs: numeric references,
// with or without their ";", become their character (anything outside ASCII, or 0, as U+FFFD). No named reference
// stands for a letter, a digit or "-", so one is left as written: a value holding one equals no plain name, as in
// the browser.
const attrText = (v) => v.replace(/&#(?:[xX]([0-9a-fA-F]+)|([0-9]+));?/g, (m, h, d) => { const n = h ? parseInt(h, 16) : parseInt(d, 10); return n > 0 && n < 0x80 ? String.fromCharCode(n) : "\uFFFD"; });
// A meta named ss-edit as the browser sees it: an element whose tag name is exactly "meta", whose name attribute
// (the first one) decodes to ss-edit, compared ASCII case-insensitively as meta names are. One inside a <template>
// isn't in the page; one in a comment or in raw text (a script, a style) isn't an element.
function hasEditMeta(html) {
let found = false;
const look = (el) => { for (const c of el.children) {
if (c.name === "template") continue;
if (c.name === "meta" && HTML_WS.concat("/>").includes(html[c.start + 5])) {
const v = attrsOf(html, c).get("name");
if (v !== undefined && attrText(v).replace(/[A-Z]/g, (x) => x.toLowerCase()) === "ss-edit") found = true;
}
look(c);
} };
look(parse(html));
return found;
}
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) {
Expand Down Expand Up @@ -212,7 +274,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 };
}

Expand Down Expand Up @@ -244,7 +306,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 <main> holds
Expand All @@ -268,7 +330,7 @@ function buildPage(starter, title, headings, pages, theirTitle) {
});
const swaps = [
[/<title>[\s\S]*?<\/title>/, () => `<title>${esc(title)}</title>`],
[/<meta name="docs-ledger" content="[^"]*">/, () => ledgerTag(L)],
[/<meta name="docs-ledger" content="[^"]*">/, () => ledgerTag(L) + editAdd(starter)],
[/(<main data-ss-id="d-doc"[^>]*>)([\s\S]*?)(<\/main>)/, (m, a, kept, b) => `${a}${kept.replace(/\s+$/, "")}\n${parts.join("\n")}\n${b}`],
];
let page = starter;
Expand All @@ -285,7 +347,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.
Expand All @@ -305,13 +368,14 @@ function newSpaceSlots(html) {
return titles.length === 1 && /<title>[^<]*<\/title>/.test(html) ? html.replace(/<title>[^<]*<\/title>/, "<title>T</title>") : 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 <main>, or in <body> 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.
Expand Down Expand Up @@ -350,7 +414,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);
Expand Down Expand Up @@ -436,7 +500,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; }
}
Expand Down Expand Up @@ -578,7 +642,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(/<title>[\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" })) });
Expand Down Expand Up @@ -657,8 +721,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); }
Expand All @@ -683,7 +748,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." });
Expand Down
1 change: 1 addition & 0 deletions docs/references/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="color-scheme" content="light dark">
<title>Document</title>
<meta name="docs-ledger" content="">
<meta name="ss-edit" content="open">
<style>
:root {
--paper: #fdfcfa; --ink: #1d1c1a; --soft: #5e5a54; --rule: #e4e0d9; --link: #2453a6; --todo: #9a948b; --blank: #f1e8cf;
Expand Down
Loading
Loading