pantheon-cli 0.2.17 → 0.2.18

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 +117 -44
  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,8 +22892,7 @@ 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 } = 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);
@@ -22859,20 +22919,32 @@ function spaceTitle(root, slug) {
22859
22919
  const meta = readText(join3(root, "space.yaml"));
22860
22920
  return meta.match(/^title:\s*(.+)$/m)?.[1]?.trim() || slug;
22861
22921
  }
22922
+ function summarise(dir, slug, name, extra = {}) {
22923
+ const handoff = join3(dir, "handoff.md");
22924
+ const body = readText(handoff);
22925
+ return {
22926
+ slug,
22927
+ title: spaceTitle(dir, name),
22928
+ updatedAt: existsSync3(handoff) ? statSync2(handoff).mtime.toISOString() : void 0,
22929
+ preview: body ? packetPreview(body) : void 0,
22930
+ ...extra
22931
+ };
22932
+ }
22862
22933
  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 || ""));
22934
+ const own = dirsIn(join3(resolve(home), "spaces")).map(
22935
+ (entry) => summarise(entry.dir, entry.name, entry.name)
22936
+ );
22937
+ const shared = dirsIn(sharedHome(home)).flatMap(
22938
+ (owner) => dirsIn(owner.dir).map(
22939
+ (space) => summarise(space.dir, `${owner.name}/${space.name}`, space.name, {
22940
+ owner: owner.name,
22941
+ shared: true
22942
+ })
22943
+ )
22944
+ );
22945
+ return [...own, ...shared].sort(
22946
+ (a, b) => (b.updatedAt || "").localeCompare(a.updatedAt || "")
22947
+ );
22876
22948
  }
22877
22949
  var SEARCH_LIMIT = 20;
22878
22950
  var SEARCH_MAX = 50;
@@ -22916,7 +22988,7 @@ function matchTurn(turn, needle) {
22916
22988
  return null;
22917
22989
  }
22918
22990
  function searchSpace(home, space, query, options = {}) {
22919
- const { root } = ensureSpace(home, space);
22991
+ const { root } = resolveForRead(home, space);
22920
22992
  const needle = query.trim().toLowerCase();
22921
22993
  if (!needle) return [];
22922
22994
  const limit = Math.min(Math.max(options.limit ?? SEARCH_LIMIT, 1), SEARCH_MAX);
@@ -22947,16 +23019,14 @@ function getTurns(home, space, sessionId, from, to) {
22947
23019
  return session.turns.filter((turn) => turn.id >= from && turn.id <= to);
22948
23020
  }
22949
23021
  function getSession(home, space, sessionId) {
22950
- const { root } = ensureSpace(home, space);
23022
+ const { root } = resolveForRead(home, space);
22951
23023
  const file = join3(root, "sessions", sessionId, "transcript.jsonl");
22952
23024
  if (!existsSync3(file)) throw new Error(`Session not found: ${sessionId}`);
22953
23025
  const turns = readFileSync3(file, "utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line));
22954
23026
  return { sessionId, turns, artifacts: listArtifacts(home, space, sessionId) };
22955
23027
  }
22956
23028
  function forgetSession(home, space, sessionId) {
22957
- requireSpaceName(space);
22958
- const slug = slugify(space);
22959
- const root = spaceDir(home, slug);
23029
+ const { slug, root } = resolveForWrite(home, space);
22960
23030
  const id = basename2(sessionId.trim());
22961
23031
  if (!id || id.startsWith(".")) throw new Error(`Not a session id: "${sessionId}".`);
22962
23032
  const dir = join3(root, "sessions", id);
@@ -22983,13 +23053,13 @@ function forgetSession(home, space, sessionId) {
22983
23053
  };
22984
23054
  }
22985
23055
  function listArtifacts(home, space, sessionId) {
22986
- const { root } = ensureSpace(home, space);
23056
+ const { root } = resolveForRead(home, space);
22987
23057
  const dir = join3(root, "sessions", sessionId, "artifacts");
22988
23058
  if (!existsSync3(dir)) return [];
22989
23059
  return readdirSync3(dir);
22990
23060
  }
22991
23061
  function getArtifact(home, space, sessionId, name) {
22992
- const { root } = ensureSpace(home, space);
23062
+ const { root } = resolveForRead(home, space);
22993
23063
  const file = join3(root, "sessions", sessionId, "artifacts", basename2(name));
22994
23064
  if (!existsSync3(file)) throw new Error(`Artifact not found: ${name}`);
22995
23065
  const buf = readFileSync3(file);
@@ -23270,9 +23340,12 @@ async function syncVault(home, opts = {}) {
23270
23340
  }
23271
23341
 
23272
23342
  // ../mcp/src/index.ts
23273
- function spaceRoot(home, space) {
23343
+ function readRoot(home, space) {
23274
23344
  return resolveSpace(home, space).root;
23275
23345
  }
23346
+ function writeRoot(home, space) {
23347
+ return resolveForWrite(home, space).root;
23348
+ }
23276
23349
  function defaultHooks() {
23277
23350
  return {
23278
23351
  pull: (home) => syncVault(home, { push: false }),
@@ -23623,7 +23696,7 @@ ${GUIDE}` }]
23623
23696
  "pantheon_get_skill",
23624
23697
  "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
23698
  { space: external_exports.string(), name: external_exports.string() },
23626
- async ({ space, name }) => safe(() => readSkill(spaceRoot(home, space), name))
23699
+ async ({ space, name }) => safe(() => readSkill(readRoot(home, space), name))
23627
23700
  );
23628
23701
  registerTool(
23629
23702
  server,
@@ -23642,7 +23715,7 @@ ${GUIDE}` }]
23642
23715
  sessions: external_exports.number().optional().describe("How many conversations back this up.")
23643
23716
  },
23644
23717
  async ({ space, name, when, body, key, sessions }) => safe(async () => {
23645
- const saved = saveSkill(spaceRoot(home, space), { name, when, body, key, sessions }, "draft");
23718
+ const saved = saveSkill(writeRoot(home, space), { name, when, body, key, sessions }, "draft");
23646
23719
  const sync2 = await vault.push(home, `skill draft ${saved.name}`);
23647
23720
  return {
23648
23721
  ok: sync2.ok !== false,
@@ -23658,7 +23731,7 @@ ${GUIDE}` }]
23658
23731
  "Record that the human does not want a skill written for a candidate pantheon_handoff proposed. Stops it being offered again.",
23659
23732
  { space: external_exports.string(), key: external_exports.string() },
23660
23733
  async ({ space, key }) => safe(async () => {
23661
- const done = dismissCandidate(spaceRoot(home, space), key);
23734
+ const done = dismissCandidate(writeRoot(home, space), key);
23662
23735
  const sync2 = await vault.push(home, "dismiss skill candidate");
23663
23736
  return { ok: sync2.ok !== false, ...done, sync: sync2 };
23664
23737
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantheon-cli",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
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",