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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ Node.js is named, not half-installed (the bridge needs Node 20+).
and named.
- The tools come live from the server, so a new tool needs no reinstall. Re-run
`install` to refresh the skill.
- The **official skills** (`@spacesheep/design`, `@spacesheep/docs`,
`@spacesheep/sheets`) go beside `/sheep` in each harness, as the folders
`skills get <name> -o <dir>` writes (`~/.claude/skills/design`,
`~/.codex/skills/design`, …), at the store's current version. The harness's own
skill picker then finds them by their descriptions, with nothing to fetch first.
A folder is only replaced or removed when it holds install's
`.spacesheep-skill.json`, so a skill of your own by the same name is left alone.
A re-run replaces them when the store has a newer version, and once a day a
harness start does the same in the background (`spacesheep skills refresh`;
`SPACESHEEP_NO_SKILL_REFRESH=1` turns that off). `--skip design` leaves one out,
`--no-skill` all of them with `/sheep`.
- A run from `npx` copies the CLI (no dependencies) into `~/.config/spacesheep/cli`
for the harnesses to run, since npx clears its own cache, and running npx on
every harness start would wait on npm and fail offline.
Expand Down
17 changes: 15 additions & 2 deletions bin/spacesheep.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ if (process.argv[2] === "memory" && process.argv[3] === "sync") {
// protocol — nothing else may print there.
// `mcp headers` is Claude Code's headersHelper (lib/harnesses.js): it prints the
// header that signs a connection in, and nothing else, on every connect.
// Both start with each harness, so both bring the official skills up to date, once a
// day, in a process of their own that the harness doesn't wait for (lib/official.js).
const refreshSkills = () => require("../lib/official").startRefresh({ configDir: require("../lib/config").configDir(), script: __filename });
if (process.argv[2] === "mcp" && process.argv[3] === "headers") {
const k = require("../lib/config").resolveKey();
process.stdout.write(JSON.stringify(k ? { Authorization: `Bearer ${k.key}` } : {}) + "\n");
if (k) refreshSkills();
return;
}
if (process.argv[2] === "mcp" && (process.argv.length === 3 || process.argv[3] === "serve")) {
if (require("../lib/config").resolveKey()) refreshSkills();
// No process.exit: stdout to a pipe is async, and exiting would drop the answers still in it.
require("../lib/bridge").runBridge();
return;
Expand Down Expand Up @@ -63,7 +68,8 @@ const HELP = `
connect EVERY coding harness on this machine at once: signs the
machine in (once), points Claude Code, Codex, Gemini CLI,
Antigravity, Cursor, Windsurf, VS Code and opencode at
\`spacesheep mcp\`, and puts the /sheep skill where each reads skills.
\`spacesheep mcp\`, and puts the /sheep skill where each reads skills,
with the official skills (design, docs, sheets) beside it.
Takes --code ssc_… or --key ss_… to sign in with no browser.
--skip leaves some out: an agent (cursor) or one Claude home
by its folder (.claude-work, or just work)
Expand All @@ -83,6 +89,7 @@ const HELP = `
spacesheep delete <space> [--yes] delete one of your spaces and every version of it (can't be undone);
takes a uuid, a link or one of your slugs, and unpins this folder
spacesheep skills lint [folder] check a skill folder, or a repo holding one, for the format
spacesheep skills refresh bring the official skills install put here to the store's version
Spacesheep reads; no sign-in, and the folder never leaves
this machine. --json for CI
spacesheep tools [name] every tool the server has, or one tool's arguments
Expand Down Expand Up @@ -221,7 +228,7 @@ function parse(argv) {
* `label` on the new call. */
const spaceLine = (s) => `${(s.emoji || "·").padEnd(2)} ${(s.title || "(untitled)").slice(0, 40).padEnd(42)} ${(s.visibility || "").padEnd(10)} ${s.url || s.id}`;
const versionLine = (v) => `${(v.sha || v.id || "").slice(0, 12).padEnd(13)} ${(v.created_at || "").slice(0, 16).padEnd(17)} ${v.version_name || v.name || v.label || ""}`;
const FLAGS = new Set(["--camera", "--screen", "--test", "--beta", "--system", "--load-test", "--service", "--remove-service", "--new", "--replace", "--no-manifest", "--no-team", "--claude", "--codex", "--antigravity", "--no-memory", "--codex-chain", "--once", "--no-service", "--dry-run", "--no-skill", "--no-login"]);
const FLAGS = new Set(["--camera", "--screen", "--test", "--beta", "--system", "--load-test", "--service", "--remove-service", "--new", "--replace", "--no-manifest", "--no-team", "--claude", "--codex", "--antigravity", "--no-memory", "--codex-chain", "--once", "--no-service", "--dry-run", "--no-skill", "--no-login", "--quiet"]);
const camel = (s) => s.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
/** --scope as the server names it: stream(s) → "stream", session(s)/ingest → "ingest", full/none → undefined. */
function keyScope(v) {
Expand Down Expand Up @@ -525,6 +532,12 @@ const LOCAL = {
if (opts.help) return out(" spacesheep skills lint [folder] [--json]");
process.exitCode = require("../lib/skill-lint").run(opts._[2], { json: opts.json });
},
// The official skills `install` put here, brought to the store's version (what a harness
// start runs once a day). Local: it writes folders on this machine.
"skills refresh": async (opts) => {
if (opts.help) return out(" spacesheep skills refresh [--dry-run] [--json] bring the official skills install put here to the store's version");
return require("../lib/install").refresh(opts, log, out);
},
};
const HELD = new Set(["talk listen", "sessions export", "deploy", "read", "share", "delete"]);
// Held too, on the new call: `talk on|off` write this machine's opt-in, and `talk` and `talk
Expand Down
77 changes: 69 additions & 8 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const cfg = require("./config");
const { McpClient } = require("./mcp");
const H = require("./harnesses");
const S = require("./skills");
const O = require("./official");

const machineName = (opts) => String(opts.name || os.hostname().split(".")[0] || "machine").slice(0, 60);
const real = (p) => { try { return fs.realpathSync(p); } catch (_) { return p; } };
Expand Down Expand Up @@ -125,22 +126,43 @@ const atLeast = (v, min) => { const a = v.split(".").map(Number), b = min.split(
function chosen(all, opts = {}) {
const words = (v) => [].concat(v || []).flatMap((x) => String(x).split(",")).map((x) => x.trim().toLowerCase()).filter(Boolean);
const only = words(opts.only);
const skip = words(opts.skip);
const skip = words(opts.skip).filter((w) => !O.isOfficialWord(w)); // a skill's name, not a harness's
for (const [flag, list] of [["--only", only], ["--skip", skip]]) {
const unknown = list.filter((w) => !all.some((h) => H.matches(h, w)));
if (unknown.length) throw new Error(`${flag}: no harness called ${unknown.join(", ")} (known: ${[...new Set(all.filter((h) => h.present || !h.id.includes(":")).map((h) => h.id))].join(", ")})`);
if (unknown.length) throw new Error(`${flag}: no harness called ${unknown.join(", ")} (known: ${[...new Set(all.filter((h) => h.present || !h.id.includes(":")).map((h) => h.id))].join(", ")}${flag === "--skip" ? `; or a skill: ${O.OFFICIAL.map(O.slugOf).join(", ")}` : ""})`);
}
return all.filter((h) => (only.length ? only.some((w) => H.matches(h, w)) : h.present) && !skip.some((w) => H.matches(h, w)));
}
/** The skill targets for the same choice (a target has the id of its harness). */
function chosenSkills(targets, opts = {}) {
const words = (v) => [].concat(v || []).flatMap((x) => String(x).split(",")).map((x) => x.trim().toLowerCase()).filter(Boolean);
const only = words(opts.only);
const skip = words(opts.skip);
const skip = words(opts.skip).filter((w) => !O.isOfficialWord(w));
const asH = (t) => ({ id: t.id, label: t.harness });
return targets.filter((t) => (!only.length || only.some((w) => H.matches(asH(t), w))) && !skip.some((w) => H.matches(asH(t), w)));
}

/** The official skills, for the same choice of harnesses, `--skip design` taken out. */
async function officialSkills(opts, key, { dryRun, only = false } = {}) {
const skip = [].concat(opts.skip || []).flatMap((x) => String(x).split(",")).map((x) => x.trim().toLowerCase());
const names = O.namesAfterSkip(skip);
const targets = O.officialTargets(chosenSkills(S.skillTargets(), opts));
if (!names.length || !targets.length) return [];
const st = O.store({ origin: cfg.origin(), configDir: cfg.configDir(), key, version: require("../package.json").version, cache: !dryRun });
const go = () => O.installOfficial(targets, { st, names, dryRun, only, stageDir: path.join(cfg.configDir(), "skills-stage") });
if (dryRun) return go();
// One at a time on this machine: install waits for a refresh or an uninstall to end; a refresh
// (`only`) finds one running and leaves it, as the next harness start tries again.
const held = await O.withLock(cfg.configDir(), go, { wait: only ? 0 : 120000 });
if (held.busy) {
// A refresh leaves it for the next harness start, and says why (`--quiet` hides it, as all else).
if (only) { O.logRefreshSkip(cfg.configDir(), O.lockAdvice(held)); return [{ skill: "official skills", harness: "", action: "skipped", error: O.lockAdvice(held) }]; }
throw new Error(O.lockAdvice(held));
}
if (held.value.some((r) => !r.error)) O.markChecked(cfg.configDir());
return held.value;
}

const pad = (s, n) => (s + " ".repeat(n)).slice(0, Math.max(n, s.length));
const MARKS = { added: "✓", replaced: "✓", updated: "✓", unchanged: "·", removed: "✓", skipped: "!" };

Expand Down Expand Up @@ -171,8 +193,14 @@ async function run(opts, log, out) {
try { skillText = await S.fetchSkill(cfg.appOrigin()); skills = S.installSkills(skillText, chosenSkills(S.skillTargets(), opts), { dryRun }); }
catch (e) { skillError = e.message; }
}
// The official skills beside /sheep (official.js), so the harness's own picker finds them.
let official = [];
if (!opts.noSkill) {
try { official = await officialSkills(opts, k.key, { dryRun }); }
catch (e) { official = [{ skill: "official skills", harness: "", action: "skipped", error: e.message }]; }
}
const missing = opts.only ? [] : all.filter((h) => !h.present && !h.id.includes(":") && !/older config/.test(h.label));
if (opts.json) return out({ machine, username: who || null, tools, command: cmd.argv, copied: cmd.copied, dry_run: dryRun, harnesses: results, skills, skill_error: skillError, not_found: missing.map((h) => h.id) });
if (opts.json) return out({ machine, username: who || null, tools, command: cmd.argv, copied: cmd.copied, dry_run: dryRun, harnesses: results, skills, skill_error: skillError, official_skills: official, not_found: missing.map((h) => h.id) });

log(`\n ${dryRun ? "Would connect" : "Connected"} this machine${who ? ` (@${who}` : " ("}${machine ? ` on "${machine}"` : ""}) with ${k.how} — ${tools} tools.`);
log(` The agents below run: ${cmd.argv.map((a) => (/\s/.test(a) ? JSON.stringify(a) : a)).join(" ")}`);
Expand All @@ -186,6 +214,11 @@ async function run(opts, log, out) {
log(`\n /sheep skill ${S.versionOf(skillText) || ""}`.trimEnd());
for (const s of skills) log(` ${s.error ? "!" : s.note ? "·" : MARKS[s.action] || "·"} ${pad(s.harness, w)} ${pad(s.file || "", 34)} ${describe(s)}`);
}
if (official.length) {
log(`\n Official skills (the harness picks them by their description)`);
const sw = Math.max(...official.map((s) => s.skill.length));
for (const s of official) log(` ${s.error ? "!" : MARKS[s.action] || "·"} ${pad(s.skill, sw)} ${pad(s.harness, w)} ${pad(s.file || "", 30)} ${s.error || `${describe(s)} ${s.version || ""}`.trim()}`);
}
// The plugin's own copy of the server stands down for one with the same URL, in
// Claude Code 2.1.71 and newer; an older one would list every tool twice.
const plugin = H.claudeDirs(os.homedir(), process.env).some((d) => S.pluginEnabled(d));
Expand Down Expand Up @@ -257,7 +290,9 @@ async function status(opts, out, log) {
try { text = fs.readFileSync(t.file, "utf8"); } catch (_) {}
return { harness: t.harness, file: t.shown, version: text && text.includes(S.MARK) ? S.versionOf(text) : null };
});
if (opts.json) return out({ signed_in: !!k, key_prefix: k ? k.key.slice(0, 8) : null, harnesses: rows, skills });
const official = O.officialStatus(O.officialTargets(S.skillTargets()));
const lock = O.abandonedLock(cfg.configDir());
if (opts.json) return out({ signed_in: !!k, key_prefix: k ? k.key.slice(0, 8) : null, harnesses: rows, skills, official_skills: official, official_skills_lock: lock });
log(`\n This machine: ${k ? `signed in (${k.key.slice(0, 8)}…)` : "not signed in — run `npx -y spacesheep@latest install`"}\n`);
const w = Math.max(12, ...rows.map((r) => r.harness.length));
for (const r of rows) {
Expand All @@ -274,16 +309,42 @@ async function status(opts, out, log) {
log(`\n /sheep skill`);
for (const s of skills) log(` ${pad(s.harness, w)} ${pad(s.file || "", 34)} ${s.note || (s.version ? s.version : "not installed")}`);
}
if (official.length) {
log(`\n Official skills`);
for (const s of official) log(` ${pad(s.harness, w)} ${pad(s.file, 34)} ${s.version || "not installed"}`);
}
if (lock) log(`\n ! ${lock} Until then they aren't refreshed.`);
log("");
}

async function uninstall(opts, log, out) {
const dryRun = !!opts.dryRun;
const results = chosen(H.harnesses(), opts).map((h) => H.uninstall(h, { dryRun }));
const skills = opts.noSkill ? [] : S.uninstallSkills(chosenSkills(S.skillTargets(), opts), { dryRun });
if (opts.json) return out({ harnesses: results, skills });
for (const r of [...results, ...skills]) if (r.action !== "unchanged") log(` ${MARKS[r.action] || "·"} ${pad(r.harness, 14)} ${pad(r.file || "", 34)} ${r.error || r.action}`);
const skip = [].concat(opts.skip || []).flatMap((x) => String(x).split(",")).map((x) => x.trim().toLowerCase());
const take = () => O.uninstallOfficial(O.officialTargets(chosenSkills(S.skillTargets(), opts)), { names: O.namesAfterSkip(skip), dryRun });
let official = [];
if (!opts.noSkill && dryRun) official = take();
else if (!opts.noSkill) {
// Waits out an install or a refresh mid-fetch, so neither can put a folder back after this.
const held = await O.withLock(cfg.configDir(), take, { wait: 120000 });
official = held.busy ? [{ skill: "official skills", harness: "", action: "skipped", error: O.lockAdvice(held) }] : held.value;
}
if (opts.json) return out({ harnesses: results, skills, official_skills: official });
for (const r of [...results, ...skills, ...official]) if (r.action !== "unchanged") log(` ${MARKS[r.action] || "·"} ${pad(r.harness, 14)} ${pad(r.file || "", 34)} ${r.error || r.action}`);
log(`\n ${dryRun ? "Would remove" : "Removed"} the bridge from ${results.filter((r) => r.action === "removed").length} harness(es). This machine's key stays (\`spacesheep logout\` forgets it).\n`);
}

module.exports = { run, status, uninstall, stableCommand, chosen, chosenSkills, ensureKey };
/** `skills refresh`: the official skills this installed, brought to the store's current
* version; none added. What a harness start runs once a day (official.startRefresh). */
async function refresh(opts, log, out) {
const k = cfg.resolveKey();
if (!k) throw Object.assign(new Error("not signed in — run `spacesheep login` (or set SPACESHEEP_KEY)"), { code: "EAUTH" });
const results = await officialSkills({}, k.key, { dryRun: !!opts.dryRun, only: true });
if (opts.json) return out({ official_skills: results });
if (opts.quiet) return;
if (!results.length) return log(" No official skills installed here (`spacesheep install` puts them in).");
for (const s of results) log(` ${s.error ? "!" : MARKS[s.action] || "·"} ${pad(s.skill, 20)} ${pad(s.file || "", 30)} ${s.error || `${describe(s)} ${s.version || ""}`.trim()}`);
}

module.exports = { run, status, uninstall, refresh, officialSkills, stableCommand, chosen, chosenSkills, ensureKey };
Loading