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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ An agent with this skill writes a document on a space while the person watches:
| `docs/references/page.html` | The starter page: no script, light and dark, A4 print |
| `docs/assets/docs.js` | Every command the agent runs, so a person allows one script |
| `docs/assets/blank-live-link*.html` | Spacesheep's working-on-it page, with and without its description: a space showing it counts as blank |
| `docs/assets/blank-new-space.html` | The empty sheet a space starts as from New space or Start from blank: a space showing it counts as blank |
| `docs/spacesheep.yaml` | The skill's title, emoji and tags on Spacesheep |
| `tests/` | The repo's tests: `node tests/run.js`, no dependencies |

Expand Down
17 changes: 17 additions & 0 deletions docs/assets/blank-new-space.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en" data-ss-id="root">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>T</title>
<style>
html{background:#fff}
body{margin:0;min-height:100vh;box-sizing:border-box;padding:48px clamp(20px,7vw,96px) 40vh;background:#fff;color:#1a1a1f;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;font-size:18px;line-height:1.6}
body:not(:has(> :not(script,style,link,template,[class^="ss-"]))){background-image:radial-gradient(circle,#dcdfe5 1px,transparent 1.3px);background-size:22px 22px}
h1{font-size:2rem;line-height:1.2;margin:0 0 .5em}
h2{font-size:1.4rem;margin:1.2em 0 .4em}
p,li{max-width:40em;margin:0 0 .7em}
</style>
</head>
<body data-ss-id="body"></body>
</html>
21 changes: 15 additions & 6 deletions docs/assets/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const STARTER = path.join(__dirname, "..", "references", "page.html");
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 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 @@ -278,8 +279,9 @@ const spaceOf = (ctx) => { try { return fs.readFileSync(spaceFile(ctx.dir), "utf
// A page that isn't a document from this skill: no ledger, and anything at all in its body. A short note, an image,
// a table, an embed: each is the person's. Only an empty body is blank.
// Blank is a short closed list of whole pages, compared after dropping whitespace: an empty file, this skill's
// starter before any outline, and 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. Everything else is the person's page, however empty it looks: a wrong "not
// 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
// 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 @@ -292,11 +294,18 @@ function liveLinkSlots(html) {
html = html.replace(/(<p class="ll-desc" data-ss-id="desc" data-ss-react="off">)[^<]*(<\/p>)/, (m, a, b) => a + "D" + b);
return n === 3 ? html : null;
}
// The new space's sheet has one slot, its title: the one <title>, text only. Its body is empty, so a block anyone
// adds, typed or pasted, makes the page the person's.
function newSpaceSlots(html) {
const titles = html.match(/<title\b/g) || [];
return titles.length === 1 && /<title>[^<]*<\/title>/.test(html) ? html.replace(/<title>[^<]*<\/title>/, "<title>T</title>") : null;
}
let BLANKS = null;
function blank(html) {
BLANKS = BLANKS || [STARTER, BLANK_LIVE_LINK, BLANK_LIVE_LINK_NODESC].map((f) => flat(fs.readFileSync(f, "utf8")));
BLANKS = BLANKS || [STARTER, BLANK_LIVE_LINK, BLANK_LIVE_LINK_NODESC, BLANK_NEW_SPACE].map((f) => flat(fs.readFileSync(f, "utf8")));
const h = flat(html), slotted = liveLinkSlots(String(html)), sf = slotted === null ? null : flat(slotted);
return h === "" || h === BLANKS[0] || sf === BLANKS[1] || sf === BLANKS[2];
const ns = newSpaceSlots(String(html)), nf = ns === null ? null : flat(ns);
return h === "" || h === BLANKS[0] || sf === BLANKS[1] || sf === BLANKS[2] || nf === BLANKS[3];
}
const foreign = (html) => !ledgerOf(html) && !blank(html);
const isConflict = (e) => e && (e.code === "conflict" || /conflict/i.test(String(e.message)));
Expand Down Expand Up @@ -487,7 +496,7 @@ const COMMANDS = {
}
if (foreign(html)) {
ctx.io.push({ status: "Stopped: this space holds another page", stopped: true });
throw new Error("start: this space holds a page someone made, and it's never written over. Nothing changed. Ask the person: use a new page (start --new, in a new folder), or tell you what to do with theirs");
throw new Error("start: this space holds a page someone made, and it's never written over. Nothing changed. Ask the person whether to write it on a new page (start --new, in a new folder). If they say to write on this page anyway, tell them you can't replace a page that has content yet, and write it on a new page all the same. Never save over their page any other way");
}
ctx.log("\n" + fs.readFileSync(OUTLINE, "utf8"));
return 0;
Expand All @@ -502,7 +511,7 @@ const COMMANDS = {
if (!title || !headings.length) throw new Error("outline: give the title, then every heading");
const r = ctx.io.read(), html = r.files["index.html"] || "";
if (ledgerOf(html)) throw new Error("outline: this space has its outline already. Write its sections; for another document, start --new in a new folder");
if (foreign(html)) throw new Error("outline: this space holds a page someone made, and it's never written over. Nothing changed. Ask the person: use a new page (start --new, in a new folder), or tell you what to do with theirs");
if (foreign(html)) throw new Error("outline: this space holds a page someone made, and it's never written over. Nothing changed. Ask the person whether to write it on a new page (start --new, in a new folder). If they say to write on this page anyway, tell them you can't replace a page that has content yet, and write it on a new page all the same. Never save over their page any other way");
const page = buildPage(fs.readFileSync(STARTER, "utf8"), title, headings, pages);
const a = ctx.io.push({ html: page });
ctx.io.save({ parent: r.version, label: "Outline", files: [{ path: "index.html", content: page }] });
Expand Down
17 changes: 17 additions & 0 deletions tests/fixtures/staging-new-space.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en" data-ss-id="root">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled</title>
<style>
html{background:#fff}
body{margin:0;min-height:100vh;box-sizing:border-box;padding:48px clamp(20px,7vw,96px) 40vh;background:#fff;color:#1a1a1f;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;font-size:18px;line-height:1.6}
body:not(:has(> :not(script,style,link,template,[class^="ss-"]))){background-image:radial-gradient(circle,#dcdfe5 1px,transparent 1.3px);background-size:22px 22px}
h1{font-size:2rem;line-height:1.2;margin:0 0 .5em}
h2{font-size:1.4rem;margin:1.2em 0 .4em}
p,li{max-width:40em;margin:0 0 .7em}
</style>
</head>
<body data-ss-id="body"></body>
</html>
8 changes: 6 additions & 2 deletions tests/ownership.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ module.exports = function ({ test, ROOT }) {
const s = fakeSpace({ "index.html": `<!doctype html><html><head><title>x</title></head><body><h1>Mine</h1>${words}</body></html>` });
const before = page(s);
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "docs-test-"));
assert.notStrictEqual(run(s, ["start", s.id], { dir }).code, 0);
assert.notStrictEqual(run(s, ["outline", "Title", "One"], { dir }).code, 0);
const refusals = [run(s, ["start", s.id], { dir }), run(s, ["outline", "Title", "One"], { dir })];
for (const r of refusals) {
assert.notStrictEqual(r.code, 0);
// The refusal says what to do with the answer, so a yes to "this page" never sends the agent around the skill.
assert.match(r.out, /If they say to write on this page anyway, tell them you can't replace a page that has content yet, and write it on a new page all the same\. Never save over their page any other way/);
}
assert.strictEqual(page(s), before);
assert.strictEqual(s.pushes.filter((p) => p.html || p.edits).length, 0, "nothing drawn over it");
assert.strictEqual(s.saves.length, 0);
Expand Down
32 changes: 32 additions & 0 deletions tests/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,38 @@ module.exports = function ({ test, ROOT }) {
}
});

test("a space made with New space or Start from blank is blank, whatever its title; one typed line makes it the person's", () => {
const sheet = fs.readFileSync(path.join(__dirname, "fixtures", "staging-new-space.html"), "utf8");
const titled = (t) => sheet.replace("<title>Untitled</title>", `<title>${t}</title>`);
const tryStart = (page) => { const s = fakeSpace({ "index.html": page }), dir = fs.mkdtempSync(path.join(os.tmpdir(), "docs-review-")); return { s, start: go(s, dir, ["start", s.id]), outline: go(s, dir, ["outline", "Letter", "Opening"]).code }; };
// The app's sheet, as staging saved it, with any plain-text title: written on at once, with no question.
for (const page of [sheet, titled("Untitled document"), titled("Letter to Ms Patel &amp; co"), titled("租房申请 🏠"), titled(""), sheet.replace(/\n/g, "\n ")]) {
const r = tryStart(page);
assert.strictEqual(r.start.code, 0, `blank: ${/<title>[^<]*/.exec(page)[0]}`);
assert.ok(!/never written over/.test(r.start.out));
assert.strictEqual(r.outline, 0);
assert.ok(r.s.files["index.html"].includes("Letter"), "the outline is on the page");
}
// Anything a person added, and any other change to the sheet: the page is theirs, refused, and left as it was.
const off = [
sheet.replace('<body data-ss-id="body"></body>', '<body data-ss-id="body"><p>One typed line.</p></body>'),
sheet.replace('<body data-ss-id="body"></body>', '<body data-ss-id="body"><h1>Untitled</h1></body>'),
sheet.replace('<body data-ss-id="body"></body>', '<body data-ss-id="body"><img src="plan.png"></body>'),
sheet.replace("</body>", "</body><p>After the body.</p>"),
sheet.replace("</head>", "<script>draw()</script></head>"),
sheet.replace("html{background:#fff}", "html{background:#000}"),
sheet.replace("<title>Untitled</title>", "<title>Untitled</title><title>Two</title>"),
sheet.replace('data-ss-id="body"', 'data-ss-id="body" class="mine"'),
];
for (const page of off) {
const r = tryStart(page);
assert.notStrictEqual(r.start.code, 0, `not blank: ${page.slice(-120)}`);
assert.notStrictEqual(r.outline, 0);
assert.strictEqual(r.s.files["index.html"], page);
assert.strictEqual(r.s.saves.length, 0, "no save");
}
});

test("review 5.2: blanks, bold and italics mark only text, never a link's address", () => {
const cases = [
["[policy](https://[2001:db8::1]/health)", '<a href="https://[2001:db8::1]/health">policy</a>'],
Expand Down
Loading