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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ npx -y spacesheep@latest skills lint --json # for CI: exits 1 when the fold
| `spacesheep mcp status \| uninstall` | Which harnesses go through it; take it out of them |
| `spacesheep logout` | Forget the stored key |
| `spacesheep whoami` | Who the current key belongs to |
| `spacesheep deploy [dir\|file]` | Publish. Options: `--space`, `--new`, `--title`, `--slug`, `--emoji`, `--description`, `--visibility`, `--team`, `--team-access`, `--no-team`, `--org`, `--base <sha>`, `--replace`, `-m <version name>`, `--json`. A folder's `.spacesheep.json` pins it to one space; if `index.html`'s `<title>` no longer matches the page the pin last published, deploy stops and asks for `--space` (update it anyway) or `--new` (a new space). Every deploy prints where the space lives (a team, or personal). Each update names the version its files are built on (`base_sha`: what this folder last published or read on this machine, or `--base`), so anything published since is merged in rather than overwritten. After a merge the folder keeps its base, so the next deploy merges the server's part in again. A clash is refused with the live version's sha and how to keep both (`read -o`, change, deploy); `--replace` publishes over it, erasing the changes made there. |
| `spacesheep deploy [dir\|file]` | Publish. Options: `--space`, `--new`, `--title`, `--slug`, `--emoji`, `--description`, `--visibility`, `--team`, `--team-access`, `--no-team`, `--org`, `--base <sha>`, `--replace`, `-m <version name>`, `--json`. A folder's `.spacesheep.json` pins it to one space; if `index.html`'s `<title>` no longer matches the page the pin last published, deploy stops and asks for `--space` (update it anyway) or `--new` (a new space). Every deploy prints where the space lives (a team, or personal). Each update names the version its files are built on (`base_sha`: what this folder last published or read on this machine, or `--base`), so anything published since is merged in rather than overwritten. After a merge the folder keeps its base, so the next deploy merges the server's part in again. A clash is refused with the live version's sha and how to keep both (`read -o`, change, deploy); `--replace` (or `--base latest`, the live version itself) publishes over it, erasing the changes made there. A folder's `.spacesheep.json` from the /sheep skill (`uuid`, `deployed_sha`) pins the space too, and its `deployed_sha` is the base when it is newer than this machine's. With no base at all, onto a space another session or person published last, deploy reads the live version before uploading anything: the same files are reported as already live (nothing deployed), different ones stop with who published it and the three ways on. No refusal is ever sent again by the CLI (`rate_limited` once, after a short `retry_after`); each prints the server's words and one line on what to do. Exit codes: 1 failed or refused, 2 wrong command line, 3 not signed in, 4 `stop_retrying` (the server refuses that call until something changes: don't run it again). |
| `spacesheep list` | Your spaces |
| `spacesheep read <space> [path] [-o dir]` | Print a space's files, or save them to a folder byte for byte. A whole space saved to a folder is the newest version, and a deploy from that folder builds on it. |
| `spacesheep versions <space>` | Version history |
Expand Down
40 changes: 33 additions & 7 deletions bin/spacesheep.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ const os = require("os");
const { deviceLogin, connectWithKey, redeemCode, agentClient } = require("../lib/login");
const { deploy } = require("../lib/deploy");
const { updateNotice, selfUpdate } = require("../lib/update");
const { refusalOf, EXIT_STOP_RETRYING } = require("../lib/refusals");
/** `call`'s refusal, from the tool's first text block. */
function callRefusal(result) {
const text = (result.content || []).filter((c) => c.type === "text").map((c) => c.text).join("\n");
let v = text;
try { v = JSON.parse(text); } catch {}
return refusalOf(v);
}

const HELP = `
spacesheep ${pkg.version} — publish web pages to spacesheep.dev from a terminal or CI
Expand Down Expand Up @@ -159,8 +167,16 @@ const HELP = `
-m, --message <text> version name shown in the space's history
--base <sha> the version your files are built on, or the start of its sha: anything
published since is merged in (default: what this folder last published
or read on this machine)
or read on this machine, or its .spacesheep.json's deployed_sha)
--base latest the live version itself: nothing is merged, your files replace it
(the same as --replace)
--replace publish over the live version on purpose, erasing changes made there
A folder with no base, onto a space someone else published last, stops
before uploading (or says the same files are already live).

Exit codes
0 done 1 failed or refused 2 wrong command line 3 not signed in
4 stop_retrying: the server refuses this call until something changes — don't run it again
--json print the server's JSON result

Auth
Expand Down Expand Up @@ -290,6 +306,12 @@ const commands = {
async deploy(opts) {
const r = await deploy(client(), opts._[0], { ...opts, via: process.env.GITHUB_ACTIONS ? "GitHub Actions" : "CLI" }, log);
if (opts.json) return out(r);
if (r.unchanged) {
log(`\n = Already live: these files are the live version of ${r.url || r.uuid} (${String(r.sha).slice(0, 12)}, published by ${r.who}). Nothing was deployed; this folder now builds on that version.`);
out(r.url || r.uuid);
if (process.env.GITHUB_OUTPUT) fs.appendFileSync(process.env.GITHUB_OUTPUT, `url=${r.url || ""}\nuuid=${r.uuid}\nsha=${r.sha}\n`);
return;
}
log(`\n ✓ ${r.is_update ? "Updated" : "Created"} ${r.url}`);
// Every push says who can read it because of where it lives, team or personal.
if (r.lives_in) log(` ⌂ Lives in ${r.lives_in}${r.team_from && !r.is_update ? ` (team from ${r.team_from === "--team" ? "--team" : path.relative(process.cwd(), r.team_from) || ".spacesheep.json"})` : ""}`);
Expand All @@ -300,7 +322,7 @@ const commands = {
const m = r.merged, merged = m.merged || [], kept = m.kept || [];
log(` ⇄ Merged with what was published since your version (${String(m.base_sha || "").slice(0, 12)} → ${String(m.server_sha || "").slice(0, 12)}): ${merged.length} file(s) merged${merged.length ? ` (${merged.slice(0, 5).join(", ")}${merged.length > 5 ? ", …" : ""})` : ""}, ${kept.length} kept as they are on the server. Read the page back before saying what it says. This folder doesn't have the server's part, so the next deploy from it merges that in again (spacesheep read ${r.uuid || "<space>"} -o <folder> brings it here).`);
}
if (r.replaced) log(` ! Replaced the live version ${String(r.replaced).slice(0, 12)} on purpose (--replace).`);
if (r.replaced) log(` ! Replaced the live version ${String(r.replaced).slice(0, 12)} on purpose (${r.base_latest ? "--base latest" : "--replace"}).`);
if (r.team_unchanged) log(` ! ${r.team_from === "--team" ? "--team names" : `${path.relative(process.cwd(), r.team_from || "") || ".spacesheep.json"} names`} a team this space isn't in. A deploy never moves a live space, so nothing moved: move it from the space's Share → Lives in, or check you are publishing the page you mean.`);
for (const w of r.warnings || []) log(` ! ${w}`);
if (r.metadata_warning) log(` ! ${r.metadata_warning.split(".")[0]}. Pass --emoji and --description.`);
Expand Down Expand Up @@ -379,9 +401,10 @@ const commands = {
catch (e) { if (/not found|unknown tool/i.test(e.message)) e.message += " — `spacesheep tools` lists the tools"; throw e; }
const shown = t.render(name, result, opts);
if (opts.json) out(shown.json);
else if (result.isError) { const e = new Error(shown.text || `${name} failed`); e.code = "ETOOL"; throw e; }
else if (shown.text) out(shown.text);
if (result.isError) process.exitCode = 1;
const refusal = result.isError ? callRefusal(result) : null;
if (opts.json) { if (result.isError) process.exitCode = refusal && refusal.code === "stop_retrying" ? EXIT_STOP_RETRYING : 1; return; }
if (result.isError) { const e = new Error(shown.text || `${name} failed`); e.code = "ETOOL"; if (refusal) e.refusal = refusal; throw e; }
if (shown.text) out(shown.text);
},
async feedback(opts) {
const args = require("../lib/inspection").feedbackArgs(opts);
Expand Down Expand Up @@ -616,7 +639,10 @@ async function door(argv) {
await commands[cmd](opts);
if (!opts.json && cmd !== "update") { const n = await updateNotice(); if (n) log(`\n${n}`); }
} catch (e) {
console.error(`\n ✗ ${e.message}\n`);
process.exit(e.code === "EAUTH" ? 3 : 1);
// A refusal is never run again here: its words, the one line on what to do, and an
// exit code of its own for stop_retrying (lib/refusals.js).
const { errorWords, exitCodeFor } = require("../lib/refusals");
console.error(`\n ✗ ${errorWords(e, { space: opts.space || (["read", "versions", "share", "delete"].includes(cmd) ? opts._[0] : undefined) })}\n`);
process.exit(exitCodeFor(e));
}
})();
9 changes: 8 additions & 1 deletion lib/bases.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ function savedBase(where) {
return hit && typeof hit.sha === "string" && hit.sha ? hit.sha : null;
}

/** When the saved base was saved (ISO time), or null: weighed against a .spacesheep.json's
* deployed_at, which the /sheep skill writes beside its deployed_sha. */
function savedAt(where) {
const hit = hitOf(where);
return hit && typeof hit.sha === "string" && hit.sha && typeof hit.at === "string" ? hit.at : null;
}

/** The merged version a deploy from `dir` made when no base for it was known, or null:
* the folder lacks part of what is live, and nothing says what it is built on. */
function heldBase(where) {
Expand Down Expand Up @@ -98,4 +105,4 @@ function write(where, rec) {
} catch {}
}

module.exports = { savedBase, saveBase, heldBase, holdBase, mergedInto, bareName };
module.exports = { savedBase, savedAt, saveBase, heldBase, holdBase, mergedInto, bareName };
Loading