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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Each release is a heading with its tag. The release workflow uses the words under it as the release's notes.

## v1.0.4

- Docs works with no shell (a Shepherd turn, or the spacesheep MCP alone). SKILL.md's first line sends such an agent to references/shepherd.md, which replaces the docs.js steps: the agent writes the page itself from page.html, keeping `<meta name="ss-edit" content="open">` and the `docs-ledger` meta, so the page opens in Edit and typing on it saves to the space.
- With no shell, Docs makes new pages only: a blank page or a first draft, in one write, on a new space or, in a Shepherd turn, on one whose page is empty. Through the spacesheep MCP it makes a new space with `create_space` and never calls `create_version`, which merges onto a space's newer edits. It never saves over a page that has anything on it; it proposes the change instead, or says an agent with a shell can make it. The ledger stays empty, so docs.js later counts every block on such a page as the person's and never rewrites one without a yes.
- A blank ask ("a blank doc I can write on", "an empty doc") is Docs too: the page gets its title and nothing else, open in Edit, with no outline. With a shell, `docs.js blank "<title>"` makes the same page, and refuses a space that holds anything. A title with `$&` or `$'` in it is written as typed.
- The skill's description names a blank document the person writes themselves.
- The folder's hash is `51887724c53f`.

## v1.0.3

- Docs pages open in Edit: the page carries `<meta name="ss-edit" content="open">`, so a person who may edit it can type on it straight away, even while Docs is still writing. Docs writes around what they type and never waits for them or undoes it.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ An agent with this skill writes a document on a space while the person watches:
| `docs/SKILL.md` | Part one: the first command, and the pace |
| `docs/references/outline.md` | Printed by `start`: the outline |
| `docs/references/writing.md` | Printed by `outline`: sections, comments, facts, length, done |
| `docs/references/shepherd.md` | For an agent with no shell (Shepherd, or the MCP alone): new pages only, a blank page or a first draft |
| `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 |
Expand Down
11 changes: 10 additions & 1 deletion docs/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
---
name: docs
description: Use when someone wants a document written on a page they and others will read, comment on and edit together, such as a proposal, a letter, a brief, a plan, a policy or a report. It writes the document live on a space, section by section, so the person watches it fill in, and it never changes words they typed without their yes.
description: Use when someone wants a document written on a page they and others will read, comment on and edit together, such as a proposal, a letter, a brief, a plan, a policy or a report, or a blank document they write on themselves ("a blank doc I can write on"). It writes the document live on a space, section by section, so the person watches it fill in, and it never changes words they typed without their yes.
license: MIT
---

# Docs

**With no shell (a Shepherd turn, or the spacesheep MCP alone), first read
references/shepherd.md (`use_skill`, or `get_skill` with `path`): it replaces the steps
below.**

**First, before you read on or decide anything:** run
`node <this skill's folder>/assets/docs.js -C <folder> start <link>`, with the space the
person gave you (`start --new "<title>"` with none), where `<folder>` is an empty folder
you work in. It puts a status on the page at once and says what the space holds. When
it's empty, it prints how to write the outline, the next command. When it holds a
document already, it lists its blocks and prints the rest of this skill.

**A blank ask** ("a blank doc I can write on", "an empty doc"): after `start`, run
`node <this skill's folder>/assets/docs.js -C <folder> blank "<title>"` in place of the
outline. The page gets the title and nothing else, open in Edit, and is the person's to
write on: send nothing more to it.

**The person watches the page fill in.** The status is your first command, ahead of all
thinking; the headings follow within 30 seconds, and a new section at least every 45.
Plan one section, write it, then plan the next: never plan the whole document before its
Expand Down
18 changes: 18 additions & 0 deletions docs/assets/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,24 @@ const COMMANDS = {
return 0;
},

// A blank page the person writes on themselves: the starter with its title as their first line, and nothing
// of the tool's, so no ledger. It opens in Edit; every line on it is theirs, the title too.
blank(ctx, args) {
const title = plain("title", args[0]);
if (!title) throw new Error('blank: give the title: blank "<title>"');
const r = ctx.io.read(), html = r.files["index.html"] || "";
if (!blank(html)) {
ctx.io.push({ status: "Stopped: this space holds a page already", stopped: true });
throw new Error("blank: this space holds a page already, and it's never written over. Nothing changed. For a blank page, start --new in a new folder");
}
// Replacer functions, so a "$&" or "$'" in the title is text and not a replacement pattern.
const page = fs.readFileSync(STARTER, "utf8").replace("<title>Document</title>", () => `<title>${esc(title)}</title>`).replace('<main data-ss-id="d-doc">\n', () => `<main data-ss-id="d-doc">\n<h1>${esc(title)}</h1>\n`);
ctx.io.push({ html: page });
ctx.io.save({ parent: r.version, label: "Blank page", files: [{ path: "index.html", content: page }] });
ctx.log("the blank page is on the space, open in Edit, and saved. Write nothing more on it: tell the person it's ready for them to type on");
return 0;
},

// The title and every heading, each section saying "Writing…", on open tabs and saved.
outline(ctx, args) {
let pages = null;
Expand Down
83 changes: 83 additions & 0 deletions docs/references/shepherd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Docs with no shell

Read this when you have no shell: a Spacesheep Shepherd turn, or an agent with only the
spacesheep MCP's tools. There is no docs.js, so you write the page yourself. This page
replaces SKILL.md's steps. Read this skill's files with `use_skill` (`file`, and `offset`
for the next part), or through the MCP with `get_skill` (`skill` `@spacesheep/docs`,
`path`).

## New pages only

docs.js is what keeps the person's words safe while it edits a page. Without it, you write
a page once and never save over it. Write only:

- on a new space, or
- in a Shepherd turn, on the space you're on when its page is empty: nothing in its body,
such as the app's empty sheet, this skill's page.html with nothing typed on it, or the
"working on it" page.

Through the MCP, write only new spaces. A page with anything on it is the person's, even
one word, and through the MCP so is any space that exists already. Don't save it. Propose
a change in your reply (through the MCP, as a comment on its block with `create_comment`),
or say an agent with a shell can make it with the Docs skill.

## The page

Read references/page.html and copy it whole, from `<!doctype html>` to `</html>`. Change
only the `<title>` and what goes inside `<main data-ss-id="d-doc">`. Keep its two marks
exactly as they are:

- `<meta name="ss-edit" content="open">`: the page opens in Edit, so the person can type
on it at once, and their typing saves to the space.
- `<meta name="docs-ledger" content="">`, empty. Only docs.js fills it. Empty means every
block counts as the person's, so docs.js never rewrites one without asking.

## A blank ask

"A blank doc I can write on", "an empty doc", "a page for my notes": the person writes it
themselves. The page holds the title and nothing else, with no outline and no placeholders.
The title is theirs, or "Untitled document" when they named none. It goes in `<title>` and
as the one line in `<main>`:

<main data-ss-id="d-doc">
<h1>Packing list</h1>
</main>

Save it (below), then reply in one line with its link: it's ready for them to type on.

## A document

Decide the title and three to seven headings, then write the whole document in one write,
in order: the title, the opening, then each section. It streams onto the page as you
write it, so the person watches it fill in. Read references/writing.md's "The text" and
"Facts and length" first: they hold here too.

<h1 data-ss-id="d-title">Sublet proposal</h1>
<section data-ss-id="d-s0">
<p data-ss-id="d-s0-1">What this is and what it asks, in one or two sentences.</p>
</section>
<section data-ss-id="d-s1">
<h2 data-ss-id="d-s1-h">What I'm asking</h2>
<p data-ss-id="d-s1-1">To sublet from <mark class="blank" tabindex="0">[start date]</mark>.</p>
<ul data-ss-id="d-s1-2"><li>One point</li><li>Another</li></ul>
</section>

Use only `p`, `h3`, `ul` or `ol` with `li`, `blockquote`, `strong`, `em`, `br` and
`<a href="https://…">`. Write `&` as `&amp;` and `<` as `&lt;`. A fact the person didn't
give is a blank: `<mark class="blank" tabindex="0">[landlord's name]</mark>`.

## Saving it

- **Shepherd, on the dashboard:** `create_space` with the title, 📄 and the page.
- **Shepherd, on a space whose page is empty:** the whole page as your `@page` block.
- **Through the MCP:** a new space only. `create_space` with the title, 📄, `files`
`[{"path": "index.html", "content": <the page>}]` and `label` "Document" (or "Blank
page"), then give its link in your reply. Never `create_version`: on a space that exists,
it merges your page with what's there, and the person's words with it. On a space they
have, propose the change instead, as "New pages only" says.

## After it's saved

The page is the person's now. Never save it again, even to fix your own words. When they
ask for a change, propose it as "New pages only" says. Then reply in two or three lines:
what the document holds, and the blanks for them to fill in.
104 changes: 104 additions & 0 deletions tests/noshell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// The no-shell path (references/shepherd.md): an agent with no docs.js writes new pages only, from page.html with
// its two marks, and the ledger left empty, so docs.js counts every block on them as the person's. Its examples
// are read from shepherd.md itself, so the words and the tool can't drift apart. Loaded by tests/run.js.
"use strict";
const assert = require("assert");
const path = require("path");
const fs = require("fs");
const os = require("os");
const { fakeSpace } = require("./fake");

module.exports = function ({ test, ROOT }) {
const D = require(path.join(ROOT, "docs/assets/docs.js"));
const read = (f) => fs.readFileSync(path.join(ROOT, "docs", f), "utf8");
const starter = read("references/page.html"), guide = read("references/shepherd.md");
const tmp = () => fs.mkdtempSync(path.join(os.tmpdir(), "docs-noshell-"));
const go = (s, dir, args) => { const lines = []; const code = D.run({ io: s.io, dir, log: (l) => lines.push(String(l)) }, args); return { code, out: lines.join("\n") }; };
// shepherd.md's indented examples, in order: the blank page's <main>, then the document's.
const examples = guide.split(/\n\n/).filter((b) => /^ {4}</.test(b)).map((b) => b.replace(/^ {4}/gm, ""));
const MARKS = ['<meta name="ss-edit" content="open">', '<meta name="docs-ledger" content="">'];
// The page as shepherd.md says to make it: page.html whole, its title and its <main> changed, nothing else.
const pageWith = (title, main) => starter.replace("<title>Document</title>", `<title>${title}</title>`).replace(/<main data-ss-id="d-doc">\n<\/main>/, main);
// docs.js on a page it didn't make: every command that writes refuses, and nothing is drawn or saved.
const untouched = (page) => {
const s = fakeSpace({ "index.html": page }), dir = tmp();
for (const args of [["start", s.id], ["outline", "T", "One"], ["blank", "T"]]) {
const r = go(s, dir, args);
assert.notStrictEqual(r.code, 0, `${args[0]}: refused`);
assert.match(r.out, /never written over/);
}
assert.strictEqual(s.files["index.html"], page);
assert.strictEqual(s.saves.length, 0);
assert.ok(!s.pushes.some((p) => p.html || p.edits), "nothing drawn on it");
};

test("shepherd.md keeps both of page.html's marks, and SKILL.md sends a no-shell agent to it first", () => {
for (const m of MARKS) { assert.ok(starter.includes(m), `page.html has ${m}`); assert.ok(guide.includes(m), `shepherd.md says to keep ${m}`); }
const body = read("SKILL.md").split(/^# Docs\n/m)[1].trim();
assert.match(body.split("\n\n")[0], /no shell[\s\S]*references\/shepherd\.md/, "the first paragraph");
assert.strictEqual(examples.length, 2, "the blank page's main, then the document's");
});

test("a blank ask: the page is page.html with the title and nothing else, as docs.js blank makes it, and the person's", () => {
const [main] = examples, title = /<h1>([^<]+)<\/h1>/.exec(main)[1];
const page = pageWith(title, main);
for (const m of MARKS) assert.ok(page.includes(m));
assert.ok(!/data-ss-id="d-(?!doc)/.test(page.slice(page.indexOf("<body>"))), "no block of the tool's");
const s = fakeSpace(), dir = tmp();
assert.strictEqual(go(s, dir, ["start", s.id]).code, 0);
assert.strictEqual(go(s, dir, ["blank", title]).code, 0);
assert.strictEqual(s.files["index.html"], page, "docs.js blank makes the same page");
assert.strictEqual(s.saves.length, 1);
assert.strictEqual(D.ledgerOf(page), null, "no ledger: every line on it is the person's");
untouched(page);
});

test("docs.js blank writes a title with $ patterns as text: one <title>, one <main>, the title escaped in both", () => {
const title = "R$&D $' $` $$ & <b>";
const s = fakeSpace(), dir = tmp();
assert.strictEqual(go(s, dir, ["start", s.id]).code, 0);
assert.strictEqual(go(s, dir, ["blank", title]).code, 0);
const page = s.files["index.html"], shown = D.esc(title);
assert.strictEqual(page.match(/<title>/g).length, 1, "one <title>");
assert.strictEqual(page.match(/<main\b/g).length, 1, "one <main>");
assert.ok(page.includes(`<title>${shown}</title>`), "the title, as typed");
assert.ok(page.includes(`<main data-ss-id="d-doc">\n<h1>${shown}</h1>\n</main>`), "the heading, as typed, and nothing else in <main>");
});

test("a first draft: page.html with the document, its ledger empty, so docs.js counts every block as the person's", () => {
const doc = examples[1], page = pageWith("Sublet proposal", `<main data-ss-id="d-doc">\n${doc}\n</main>`);
for (const m of MARKS) assert.ok(page.includes(m));
const tags = new Set([...doc.matchAll(/<([a-z][a-z0-9]*)/g)].map((m) => m[1]));
for (const t of tags) assert.ok(["h1", "h2", "section", "p", "h3", "ul", "ol", "li", "blockquote", "strong", "em", "br", "a", "mark"].includes(t), `the example uses only allowed tags: ${t}`);
assert.strictEqual(D.ledgerOf(page), null);
untouched(page);
});

test("a page a person has typed in is never saved over: docs.js blank refuses it, and shepherd.md says to save only new pages", () => {
const typed = starter.replace('<main data-ss-id="d-doc">\n', '<main data-ss-id="d-doc">\n<p>My own first line</p>\n');
const s = fakeSpace({ "index.html": typed }), dir = tmp();
assert.strictEqual(go(s, dir, ["start", s.id]).code, 0, "start reads it as blank but for their line");
const r = go(s, dir, ["blank", "Notes"]);
assert.notStrictEqual(r.code, 0);
assert.match(r.out, /never written over/);
assert.strictEqual(s.files["index.html"], typed);
assert.strictEqual(s.saves.length, 0);
assert.ok(!s.pushes.some((p) => p.html || p.edits));
// The person types on the blank page: it stays theirs.
untouched(pageWith("Packing list", '<main data-ss-id="d-doc">\n<h1>Packing list</h1>\n<p>Socks</p>\n</main>'));
assert.match(guide, /## New pages only/);
assert.match(guide, /Never save it again/);
});

test("the MCP save makes a new space with create_space, using only fields it takes, and never saves onto one", () => {
const mcp = /- \*\*Through the MCP:\*\*([\s\S]*?)(?=\n- |\n\n|$)/.exec(guide)[1];
assert.match(mcp, /`create_space`/);
// create_space's fields, from spacesheep's shared/doors.json: what the bullet passes must be among them.
const TAKES = ["title", "emoji", "description", "visibility", "files", "label"];
const named = [...mcp.matchAll(/`(\w+)`(?! *:)/g)].map((m) => m[1]).filter((n) => !/^create_|^get_/.test(n));
for (const n of named) assert.ok(TAKES.includes(n), `create_space takes ${n}`);
// create_version merges onto a space's newer edits: it's named only to forbid it.
assert.match(mcp, /Never `create_version`/);
for (const n of ["skill", "keep_others", "parent", "live_link"]) assert.ok(!mcp.includes("`" + n + "`"), `no ${n}`);
});
};
4 changes: 3 additions & 1 deletion tests/ownership.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = function ({ test, ROOT }) {
return close > open ? null : best;
};
// The commands every test below must cover: a new command fails this until it is in the walk.
const WALKED = ["start", "outline", "write", "blocks", "done", "edit", "comments", "reply", "propose", "apply"];
const WALKED = ["start", "blank", "outline", "write", "blocks", "done", "edit", "comments", "reply", "propose", "apply"];

test("every command the tool has is in the person's-block walk", () => {
assert.deepStrictEqual(Object.keys(D.COMMANDS).sort(), WALKED.slice().sort());
Expand Down Expand Up @@ -84,6 +84,7 @@ module.exports = function ({ test, ROOT }) {
["blocks", "2"],
["start", s.id],
["outline", "Another title", "Another heading"],
["blank", "A blank page"],
["done"],
];
// The person asks for changes in comments: on their own typed block, on the tool's block, on the whole page.
Expand Down Expand Up @@ -112,6 +113,7 @@ module.exports = function ({ test, ROOT }) {
const code = D.run({ io: s.io, dir, log: (l) => lines.push(String(l)), stdin: () => stdin }, [cmd, ...rest]);
if (cmd === "edit" && rest[0] !== "d-s0-1") assert.notStrictEqual(code, 0, `edit ${rest[0]}: refused, it's the person's`);
if (cmd === "apply") assert.notStrictEqual(code, 0, "apply with no yes: refused");
if (cmd === "blank") assert.notStrictEqual(code, 0, "blank on a document: refused");
if (cmd === "propose" && !proposal) { const m = /comment (\w{8})/.exec(lines.join("\n")); proposal = m && s.comments.find((c) => c.id.startsWith(m[1])).id; }
check(st.slice(0, 2).join(" "));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function test(name, fn) {
try { fn(); pass++; console.log(`ok ${name}`); }
catch (e) { fail++; console.log(`FAIL ${name}\n ${String(e && e.stack || e).split("\n").slice(0, 3).join("\n ")}`); }
}
for (const f of ["ownership", "commands", "comments", "property", "review", "typed", "edit"]) {
for (const f of ["ownership", "commands", "comments", "property", "review", "typed", "edit", "noshell"]) {
try { require(path.join(__dirname, f + ".js"))({ test, ROOT }); }
catch (e) { fail++; console.log(`FAIL ${f}.js didn't load: ${String(e.message).split("\n")[0]}`); }
}
Expand Down