pantheon-cli 0.2.17 → 0.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/pantheon.mjs +138 -50
  2. package/package.json +1 -1
package/dist/pantheon.mjs CHANGED
@@ -21970,6 +21970,12 @@ function missingSpaceName(value) {
21970
21970
  const space = (value || "").trim();
21971
21971
  return !space || space === "$ARGUMENTS" || space === "<space>" || /^space$/i.test(space);
21972
21972
  }
21973
+ function splitSpaceName(value) {
21974
+ const trimmed = (value || "").trim();
21975
+ const slash2 = trimmed.indexOf("/");
21976
+ if (slash2 < 0) return { owner: null, name: trimmed };
21977
+ return { owner: trimmed.slice(0, slash2).trim(), name: trimmed.slice(slash2 + 1).trim() };
21978
+ }
21973
21979
  function requireSpaceName(value) {
21974
21980
  const space = value.trim();
21975
21981
  if (missingSpaceName(space)) {
@@ -21977,10 +21983,14 @@ function requireSpaceName(value) {
21977
21983
  "No conscience name. Ask the human what to call this space \u2014 one short name like preorders \u2014 then retry. Do not invent a name."
21978
21984
  );
21979
21985
  }
21980
- if (/\s/.test(space) || space.length > 64 || !/^[a-zA-Z][a-zA-Z0-9._-]*$/.test(space)) {
21981
- throw new Error(
21982
- `"${space.slice(0, 80)}" is not a space name. Ask for one short name (letters, numbers, hyphens), then retry.`
21983
- );
21986
+ const { owner, name } = splitSpaceName(space);
21987
+ const parts = owner === null ? [name] : [owner, name];
21988
+ for (const part of parts) {
21989
+ if (/\s/.test(part) || part.length > 64 || !/^[a-zA-Z][a-zA-Z0-9._-]*$/.test(part)) {
21990
+ throw new Error(
21991
+ `"${space.slice(0, 80)}" is not a space name. Ask for one short name (letters, numbers, hyphens), then retry.`
21992
+ );
21993
+ }
21984
21994
  }
21985
21995
  return space;
21986
21996
  }
@@ -21991,6 +22001,67 @@ function slugify(value) {
21991
22001
  function spaceDir(home, slug) {
21992
22002
  return join3(resolve(home), "spaces", slugify(slug));
21993
22003
  }
22004
+ function sharedHome(home) {
22005
+ return `${resolve(home)}-shared`;
22006
+ }
22007
+ function sharedDir(home, owner, slug) {
22008
+ return join3(sharedHome(home), slugify(owner), slugify(slug));
22009
+ }
22010
+ function dirsIn(root) {
22011
+ if (!existsSync3(root)) return [];
22012
+ return readdirSync3(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => ({ name: entry.name, dir: join3(root, entry.name) }));
22013
+ }
22014
+ function sharedMatches(home, slug) {
22015
+ return dirsIn(sharedHome(home)).map((owner) => ({ owner: owner.name, root: join3(owner.dir, slug) })).filter((match) => existsSync3(match.root));
22016
+ }
22017
+ function sharedWriteRefusal(name) {
22018
+ return `"${name}" was shared with you read-only, so nothing can be written to it. Hand off to one of your own spaces instead \u2014 pantheon_list_spaces marks which are yours.`;
22019
+ }
22020
+ function resolveForRead(home, name, options = {}) {
22021
+ requireSpaceName(name);
22022
+ const { owner, name: bare } = splitSpaceName(name);
22023
+ const slug = slugify(bare);
22024
+ if (owner) {
22025
+ const root = sharedDir(home, owner, slug);
22026
+ if (!existsSync3(root)) {
22027
+ throw new Error(
22028
+ `"${owner}/${bare}" is not shared with this vault. Call pantheon_list_spaces to see what is.`
22029
+ );
22030
+ }
22031
+ return { slug: `${slugify(owner)}/${slug}`, root, shared: true, owner: slugify(owner) };
22032
+ }
22033
+ if (existsSync3(spaceDir(home, slug))) {
22034
+ return { slug, root: spaceDir(home, slug), shared: false };
22035
+ }
22036
+ const matches = sharedMatches(home, slug);
22037
+ if (matches.length === 1) {
22038
+ const [match] = matches;
22039
+ return { slug: `${match.owner}/${slug}`, root: match.root, shared: true, owner: match.owner };
22040
+ }
22041
+ if (matches.length > 1) {
22042
+ const names = matches.map((match) => `${match.owner}/${slug}`).join(", ");
22043
+ throw new Error(
22044
+ `"${bare}" has been shared by more than one person: ${names}. Use the full name to say which one.`
22045
+ );
22046
+ }
22047
+ if (options.create === false) {
22048
+ throw new Error(
22049
+ `"${name}" is not a space in this vault. Call pantheon_list_spaces and use one of those names. Do not invent a substitute.`
22050
+ );
22051
+ }
22052
+ return { slug, root: ensureSpace(home, bare).root, shared: false };
22053
+ }
22054
+ function resolveForWrite(home, name) {
22055
+ requireSpaceName(name);
22056
+ const { owner, name: bare } = splitSpaceName(name);
22057
+ if (owner) throw new Error(sharedWriteRefusal(`${owner}/${bare}`));
22058
+ const slug = slugify(bare);
22059
+ if (!existsSync3(spaceDir(home, slug))) {
22060
+ const [match] = sharedMatches(home, slug);
22061
+ if (match) throw new Error(sharedWriteRefusal(`${match.owner}/${slug}`));
22062
+ }
22063
+ return { slug, root: ensureSpace(home, bare).root, shared: false };
22064
+ }
21994
22065
  function nowIso() {
21995
22066
  return (/* @__PURE__ */ new Date()).toISOString();
21996
22067
  }
@@ -22435,14 +22506,7 @@ function ensureSpace(home, name) {
22435
22506
  return { slug, root };
22436
22507
  }
22437
22508
  function resolveSpace(home, name) {
22438
- requireSpaceName(name);
22439
- const slug = slugify(name);
22440
- const root = spaceDir(home, slug);
22441
- if (!existsSync3(root)) {
22442
- throw new Error(
22443
- `"${name}" is not a space in this vault. Call pantheon_list_spaces and use one of those names. Do not invent a substitute.`
22444
- );
22445
- }
22509
+ const { slug, root } = resolveForRead(home, name, { create: false });
22446
22510
  return { slug, root };
22447
22511
  }
22448
22512
  function writeArtifacts(sessionDir, artifacts = []) {
@@ -22615,8 +22679,7 @@ function sessionStart(path) {
22615
22679
  }
22616
22680
  }
22617
22681
  function writeHandoff(home, input) {
22618
- requireSpaceName(input.space);
22619
- const { slug, root } = ensureSpace(home, input.space);
22682
+ const { slug, root } = resolveForWrite(home, input.space);
22620
22683
  const { turns, captured } = resolveTranscript(input);
22621
22684
  if (!captured) {
22622
22685
  const thin = transcriptLooksThin(turns);
@@ -22678,8 +22741,7 @@ function writeHandoff(home, input) {
22678
22741
  };
22679
22742
  }
22680
22743
  function writePark(home, input) {
22681
- requireSpaceName(input.space);
22682
- const { slug, root } = ensureSpace(home, input.space);
22744
+ const { slug, root } = resolveForWrite(home, input.space);
22683
22745
  const turns = input.transcript ? parseTurns(input.transcript) : [];
22684
22746
  if (turns.length) {
22685
22747
  const thin = transcriptLooksThin(turns);
@@ -22702,8 +22764,7 @@ function writePark(home, input) {
22702
22764
  return { slug, sessionId: session.sessionId, turns: turns.length, artifacts: session.artifacts };
22703
22765
  }
22704
22766
  function writeRemember(home, space, fact) {
22705
- requireSpaceName(space);
22706
- const { slug, root } = ensureSpace(home, space);
22767
+ const { slug, root } = resolveForWrite(home, space);
22707
22768
  appendFileSync(join3(root, "memory.md"), `- ${fact.trim()}
22708
22769
  `);
22709
22770
  return { slug };
@@ -22831,14 +22892,15 @@ function resumeNote(sessions, turns, story, skills) {
22831
22892
  return parts.join(" ");
22832
22893
  }
22833
22894
  function readResume(home, space) {
22834
- requireSpaceName(space);
22835
- const { slug, root } = ensureSpace(home, space);
22895
+ const { slug, root, shared, owner } = resolveForRead(home, space);
22836
22896
  const sessions = sessionSummaries(root);
22837
22897
  const turns = sessions.reduce((sum, session) => sum + session.turns, 0);
22838
22898
  const story = readStory(root);
22839
22899
  const skills = skillRefs(root);
22900
+ const borrowed = shared ? `This conscience belongs to @${owner} and was shared with you to read. Nothing can be written to it \u2014 when this chat ends, hand off to one of your own spaces. ` : "";
22840
22901
  return {
22841
22902
  space: slug,
22903
+ ...shared ? { shared, owner } : {},
22842
22904
  handoff: readText(join3(root, "handoff.md")).trim() || "(empty handoff)",
22843
22905
  memory: readText(join3(root, "memory.md")).trim() || "(no durable memory yet)",
22844
22906
  sessionId: sessions[0]?.id ?? null,
@@ -22848,7 +22910,7 @@ function readResume(home, space) {
22848
22910
  artifacts: listSpaceArtifacts(root),
22849
22911
  skills,
22850
22912
  pendingSkills: listSkills(root, "draft").length,
22851
- note: resumeNote(sessions, turns, story.length, skills)
22913
+ note: borrowed + resumeNote(sessions, turns, story.length, skills)
22852
22914
  };
22853
22915
  }
22854
22916
  function packetPreview(markdown) {
@@ -22859,20 +22921,32 @@ function spaceTitle(root, slug) {
22859
22921
  const meta = readText(join3(root, "space.yaml"));
22860
22922
  return meta.match(/^title:\s*(.+)$/m)?.[1]?.trim() || slug;
22861
22923
  }
22924
+ function summarise(dir, slug, name, extra = {}) {
22925
+ const handoff = join3(dir, "handoff.md");
22926
+ const body = readText(handoff);
22927
+ return {
22928
+ slug,
22929
+ title: spaceTitle(dir, name),
22930
+ updatedAt: existsSync3(handoff) ? statSync2(handoff).mtime.toISOString() : void 0,
22931
+ preview: body ? packetPreview(body) : void 0,
22932
+ ...extra
22933
+ };
22934
+ }
22862
22935
  function listSpaces(home) {
22863
- const root = join3(resolve(home), "spaces");
22864
- if (!existsSync3(root)) return [];
22865
- return readdirSync3(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => {
22866
- const dir = join3(root, entry.name);
22867
- const handoff = join3(dir, "handoff.md");
22868
- const body = readText(handoff);
22869
- return {
22870
- slug: entry.name,
22871
- title: spaceTitle(dir, entry.name),
22872
- updatedAt: existsSync3(handoff) ? statSync2(handoff).mtime.toISOString() : void 0,
22873
- preview: body ? packetPreview(body) : void 0
22874
- };
22875
- }).sort((a, b) => (b.updatedAt || "").localeCompare(a.updatedAt || ""));
22936
+ const own = dirsIn(join3(resolve(home), "spaces")).map(
22937
+ (entry) => summarise(entry.dir, entry.name, entry.name)
22938
+ );
22939
+ const shared = dirsIn(sharedHome(home)).flatMap(
22940
+ (owner) => dirsIn(owner.dir).map(
22941
+ (space) => summarise(space.dir, `${owner.name}/${space.name}`, space.name, {
22942
+ owner: owner.name,
22943
+ shared: true
22944
+ })
22945
+ )
22946
+ );
22947
+ return [...own, ...shared].sort(
22948
+ (a, b) => (b.updatedAt || "").localeCompare(a.updatedAt || "")
22949
+ );
22876
22950
  }
22877
22951
  var SEARCH_LIMIT = 20;
22878
22952
  var SEARCH_MAX = 50;
@@ -22916,7 +22990,7 @@ function matchTurn(turn, needle) {
22916
22990
  return null;
22917
22991
  }
22918
22992
  function searchSpace(home, space, query, options = {}) {
22919
- const { root } = ensureSpace(home, space);
22993
+ const { root } = resolveForRead(home, space);
22920
22994
  const needle = query.trim().toLowerCase();
22921
22995
  if (!needle) return [];
22922
22996
  const limit = Math.min(Math.max(options.limit ?? SEARCH_LIMIT, 1), SEARCH_MAX);
@@ -22947,16 +23021,14 @@ function getTurns(home, space, sessionId, from, to) {
22947
23021
  return session.turns.filter((turn) => turn.id >= from && turn.id <= to);
22948
23022
  }
22949
23023
  function getSession(home, space, sessionId) {
22950
- const { root } = ensureSpace(home, space);
23024
+ const { root } = resolveForRead(home, space);
22951
23025
  const file = join3(root, "sessions", sessionId, "transcript.jsonl");
22952
23026
  if (!existsSync3(file)) throw new Error(`Session not found: ${sessionId}`);
22953
23027
  const turns = readFileSync3(file, "utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line));
22954
23028
  return { sessionId, turns, artifacts: listArtifacts(home, space, sessionId) };
22955
23029
  }
22956
23030
  function forgetSession(home, space, sessionId) {
22957
- requireSpaceName(space);
22958
- const slug = slugify(space);
22959
- const root = spaceDir(home, slug);
23031
+ const { slug, root } = resolveForWrite(home, space);
22960
23032
  const id = basename2(sessionId.trim());
22961
23033
  if (!id || id.startsWith(".")) throw new Error(`Not a session id: "${sessionId}".`);
22962
23034
  const dir = join3(root, "sessions", id);
@@ -22983,13 +23055,13 @@ function forgetSession(home, space, sessionId) {
22983
23055
  };
22984
23056
  }
22985
23057
  function listArtifacts(home, space, sessionId) {
22986
- const { root } = ensureSpace(home, space);
23058
+ const { root } = resolveForRead(home, space);
22987
23059
  const dir = join3(root, "sessions", sessionId, "artifacts");
22988
23060
  if (!existsSync3(dir)) return [];
22989
23061
  return readdirSync3(dir);
22990
23062
  }
22991
23063
  function getArtifact(home, space, sessionId, name) {
22992
- const { root } = ensureSpace(home, space);
23064
+ const { root } = resolveForRead(home, space);
22993
23065
  const file = join3(root, "sessions", sessionId, "artifacts", basename2(name));
22994
23066
  if (!existsSync3(file)) throw new Error(`Artifact not found: ${name}`);
22995
23067
  const buf = readFileSync3(file);
@@ -23270,9 +23342,12 @@ async function syncVault(home, opts = {}) {
23270
23342
  }
23271
23343
 
23272
23344
  // ../mcp/src/index.ts
23273
- function spaceRoot(home, space) {
23345
+ function readRoot(home, space) {
23274
23346
  return resolveSpace(home, space).root;
23275
23347
  }
23348
+ function writeRoot(home, space) {
23349
+ return resolveForWrite(home, space).root;
23350
+ }
23276
23351
  function defaultHooks() {
23277
23352
  return {
23278
23353
  pull: (home) => syncVault(home, { push: false }),
@@ -23400,7 +23475,7 @@ ${GUIDE}` }]
23400
23475
  registerTool(
23401
23476
  server,
23402
23477
  "pantheon_list_spaces",
23403
- "List existing Pantheon consciences from the private vault. Trigger: /pantheon-spaces. For listing only \u2014 never invent extra names. If the human already typed a new slug for handoff, do not block that handoff because it is missing here.",
23478
+ "List existing Pantheon consciences from the private vault. Trigger: /pantheon-spaces. For listing only \u2014 never invent extra names. If the human already typed a new slug for handoff, do not block that handoff because it is missing here. An entry with shared: true belongs to another person and is named owner/slug: it can be resumed and searched, but never handed off to, parked in, or remembered into. Say whose it is when you show the list.",
23404
23479
  {},
23405
23480
  async () => safe(async () => {
23406
23481
  const sync2 = await vault.pull(home);
@@ -23416,7 +23491,7 @@ ${GUIDE}` }]
23416
23491
  registerTool(
23417
23492
  server,
23418
23493
  "pantheon_resume",
23419
- "Pull the vault, then load a Pantheon conscience: the latest handoff packet, durable memory, packets from earlier handoffs (story), every archived session with its turn count (sessions), and stored artifact names. Trigger: /pantheon-resume <space>. If the space name is missing or empty, this tool lists live spaces \u2014 show that list and ask which conscience. The packet is a summary of the session that ended last, not the space: when the human asks about anything it does not cover, call pantheon_search before saying you lack context, and read detail with pantheon_get_turns or pantheon_get_session using any id from sessions. Fetch files with pantheon_get_artifact. Never call a generic resume tool for this. Do not run pantheon sync. REPORT THE RESULT as a two-column table \u2014 space, sessions (with total turns), earlier handoffs, memory facts, artifacts, skills (live and awaiting review), pulled \u2014 and then, outside the table, two or three sentences on where the work actually stood, any open threads, and the available skills by name and trigger. The table proves the load worked; it does not tell the human where the work was, so never collapse that prose into cells.",
23494
+ "Pull the vault, then load a Pantheon conscience: the latest handoff packet, durable memory, packets from earlier handoffs (story), every archived session with its turn count (sessions), and stored artifact names. Trigger: /pantheon-resume <space>. If the space name is missing or empty, this tool lists live spaces \u2014 show that list and ask which conscience. The packet is a summary of the session that ended last, not the space: when the human asks about anything it does not cover, call pantheon_search before saying you lack context, and read detail with pantheon_get_turns or pantheon_get_session using any id from sessions. Fetch files with pantheon_get_artifact. Never call a generic resume tool for this. Do not run pantheon sync. A space named owner/slug was shared with you by someone else: resume and search work, writing does not, so tell the human at the end that this chat has to be handed off to one of their own spaces. REPORT THE RESULT as a two-column table \u2014 space, sessions (with total turns), earlier handoffs, memory facts, artifacts, skills (live and awaiting review), pulled \u2014 and then, outside the table, two or three sentences on where the work actually stood, any open threads, and the available skills by name and trigger. The table proves the load worked; it does not tell the human where the work was, so never collapse that prose into cells.",
23420
23495
  { space: external_exports.string().optional() },
23421
23496
  async ({ space }) => safe(async () => {
23422
23497
  const sync2 = await vault.pull(home);
@@ -23432,9 +23507,22 @@ ${GUIDE}` }]
23432
23507
  sync: sync2
23433
23508
  };
23434
23509
  }
23435
- const match = spaces.find(
23436
- (item) => item.slug === raw || item.slug === raw.toLowerCase() || item.title === raw
23510
+ const lower = raw.toLowerCase();
23511
+ const exact = spaces.find(
23512
+ (item) => item.slug === raw || item.slug === lower || item.title === raw
23437
23513
  );
23514
+ const bare = exact ? [] : spaces.filter((item) => item.shared && item.slug.split("/")[1] === lower);
23515
+ if (bare.length > 1) {
23516
+ return {
23517
+ needSpace: true,
23518
+ home,
23519
+ spaces,
23520
+ source: "pantheon vault",
23521
+ note: `"${raw}" has been shared with you by more than one person: ${bare.map((item) => item.slug).join(", ")}. Ask which one they mean, then call pantheon_resume with the full name.`,
23522
+ sync: sync2
23523
+ };
23524
+ }
23525
+ const match = exact || bare[0];
23438
23526
  if (!match) {
23439
23527
  return {
23440
23528
  needSpace: true,
@@ -23623,7 +23711,7 @@ ${GUIDE}` }]
23623
23711
  "pantheon_get_skill",
23624
23712
  "Read one skill from a Pantheon space: guidance written from failures that already happened in this project. Resume lists the names and when to use each; call this for the body before doing work in an area a skill covers. Every claim cites the session and turn it came from, so pantheon_get_turns will show the original moment if the guidance does not fit your situation.",
23625
23713
  { space: external_exports.string(), name: external_exports.string() },
23626
- async ({ space, name }) => safe(() => readSkill(spaceRoot(home, space), name))
23714
+ async ({ space, name }) => safe(() => readSkill(readRoot(home, space), name))
23627
23715
  );
23628
23716
  registerTool(
23629
23717
  server,
@@ -23642,7 +23730,7 @@ ${GUIDE}` }]
23642
23730
  sessions: external_exports.number().optional().describe("How many conversations back this up.")
23643
23731
  },
23644
23732
  async ({ space, name, when, body, key, sessions }) => safe(async () => {
23645
- const saved = saveSkill(spaceRoot(home, space), { name, when, body, key, sessions }, "draft");
23733
+ const saved = saveSkill(writeRoot(home, space), { name, when, body, key, sessions }, "draft");
23646
23734
  const sync2 = await vault.push(home, `skill draft ${saved.name}`);
23647
23735
  return {
23648
23736
  ok: sync2.ok !== false,
@@ -23658,7 +23746,7 @@ ${GUIDE}` }]
23658
23746
  "Record that the human does not want a skill written for a candidate pantheon_handoff proposed. Stops it being offered again.",
23659
23747
  { space: external_exports.string(), key: external_exports.string() },
23660
23748
  async ({ space, key }) => safe(async () => {
23661
- const done = dismissCandidate(spaceRoot(home, space), key);
23749
+ const done = dismissCandidate(writeRoot(home, space), key);
23662
23750
  const sync2 = await vault.push(home, "dismiss skill candidate");
23663
23751
  return { ok: sync2.ok !== false, ...done, sync: sync2 };
23664
23752
  })
@@ -24081,7 +24169,7 @@ function detectApps() {
24081
24169
  }
24082
24170
  var AHEAD = "Written ahead \u2014 app not detected, ready if you install it";
24083
24171
  function nextSteps(found, apiUrl) {
24084
- if (found.length) return " Reload MCP in each app, then type /pantheon-handoff <space>";
24172
+ if (found.length) return "Reload MCP in each app, then type /pantheon-handoff <space>";
24085
24173
  return [
24086
24174
  " No desktop agent detected. The configs above are in place if you install one.",
24087
24175
  "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantheon-cli",
3
- "version": "0.2.17",
3
+ "version": "0.2.19",
4
4
  "description": "Carry agent conscience between AI coding agents. Hand off a conversation in one agent, resume it in another.",
5
5
  "license": "MIT",
6
6
  "type": "module",