pantheon-cli 0.2.32 → 0.2.34

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 -10
  2. package/package.json +1 -1
package/dist/pantheon.mjs CHANGED
@@ -22596,9 +22596,13 @@ function missingGeneratedFiles(turns, artifacts = []) {
22596
22596
  }
22597
22597
  var PACKET_TURNS = 14;
22598
22598
  var PACKET_TURN_CHARS = 400;
22599
- function sessionLine(session, current) {
22599
+ var PACKET_ARTIFACTS = 40;
22600
+ var PACKET_STORY = 4;
22601
+ var PACKET_STORY_CHARS = 2400;
22602
+ var PACKET_SESSIONS = 20;
22603
+ function sessionLine(session, current, mark = "\u2190 this packet") {
22600
22604
  const detail = [session.source, session.updatedAt && `updated ${session.updatedAt}`].filter(Boolean).join(", ");
22601
- return `- ${session.id} \u2014 ${session.turns} turns${detail ? ` (${detail})` : ""}${current ? " \u2190 this packet" : ""}`;
22605
+ return `- ${session.id} \u2014 ${session.turns} turns${detail ? ` (${detail})` : ""}${current ? ` ${mark}` : ""}`;
22602
22606
  }
22603
22607
  function fullHistory(slug, turns, sessionId, sessions) {
22604
22608
  const total = sessions.reduce((sum, session) => sum + session.turns, 0) || turns;
@@ -22622,6 +22626,56 @@ function fullHistory(slug, turns, sessionId, sessions) {
22622
22626
  );
22623
22627
  return lines;
22624
22628
  }
22629
+ function recentTurns(root, limit) {
22630
+ const picked = [];
22631
+ for (const session of sessionDirs(root)) {
22632
+ if (picked.length >= limit) break;
22633
+ const spoken = readSessionTurns(session.dir).filter((turn) => turn.text.trim());
22634
+ for (let i = spoken.length - 1; i >= 0 && picked.length < limit; i -= 1) {
22635
+ picked.push({ sessionId: session.id, spoken: spoken.length, turn: spoken[i] });
22636
+ }
22637
+ }
22638
+ return picked.reverse();
22639
+ }
22640
+ function turnLines(picked) {
22641
+ const lines = [];
22642
+ let session = "";
22643
+ for (const item of picked) {
22644
+ if (item.sessionId !== session) {
22645
+ session = item.sessionId;
22646
+ if (lines.length) lines.push("");
22647
+ lines.push(`From ${item.sessionId} (${item.spoken} spoken turns):`);
22648
+ }
22649
+ lines.push(
22650
+ `- [${item.turn.id}] ${item.turn.role}: ${item.turn.text.replace(/\s+/g, " ").slice(0, PACKET_TURN_CHARS)}`
22651
+ );
22652
+ }
22653
+ return lines;
22654
+ }
22655
+ function spaceArtifacts(root) {
22656
+ const groups = [];
22657
+ let total = 0;
22658
+ let listed = 0;
22659
+ let sessions = 0;
22660
+ for (const session of sessionDirs(root)) {
22661
+ const dir = join3(session.dir, "artifacts");
22662
+ if (!existsSync3(dir)) continue;
22663
+ const names = [];
22664
+ let held = 0;
22665
+ for (const name of readdirSync3(dir)) {
22666
+ if (name.startsWith(".")) continue;
22667
+ total += 1;
22668
+ held += 1;
22669
+ if (listed < PACKET_ARTIFACTS) {
22670
+ names.push(name);
22671
+ listed += 1;
22672
+ }
22673
+ }
22674
+ if (held) sessions += 1;
22675
+ if (names.length) groups.push({ sessionId: session.id, names });
22676
+ }
22677
+ return { groups, total, listed, sessions };
22678
+ }
22625
22679
  function distill(input) {
22626
22680
  const { space, source, turns, summary, artifacts, sessionId, sessions } = input;
22627
22681
  const spoken = turns.filter((turn) => turn.text.trim());
@@ -22650,6 +22704,65 @@ function distill(input) {
22650
22704
  return `${lines.filter((line) => line !== null).join("\n")}
22651
22705
  `;
22652
22706
  }
22707
+ function spaceDistill(input) {
22708
+ const { root, space, source, turns, summary, sessionId, sessions, earlier } = input;
22709
+ const slug = slugify(space);
22710
+ const total = sessions.reduce((sum, session) => sum + session.turns, 0) || turns.length;
22711
+ const toolCalls = turns.reduce((sum, turn) => sum + (turn.toolCalls?.length || 0), 0);
22712
+ const files2 = spaceArtifacts(root);
22713
+ const picked = recentTurns(root, PACKET_TURNS);
22714
+ const lines = [
22715
+ `# Handoff: ${space}`,
22716
+ `Space: ${total} turns across ${sessions.length} session${sessions.length === 1 ? "" : "s"} \xB7 ${files2.total} stored file${files2.total === 1 ? "" : "s"} \xB7 ${nowIso()}`,
22717
+ `Latest: ${source || "unknown"} \xB7 ${turns.length} turns \xB7 ${toolCalls} tool calls \xB7 ${sessionId}`,
22718
+ "",
22719
+ "## Packet",
22720
+ summary?.trim() || "Continue from the stored archive. This packet is a pointer, not the conversation \u2014 read the full transcript before assuming context."
22721
+ ];
22722
+ if (earlier.length) {
22723
+ lines.push("", "## Earlier packets");
22724
+ for (const item of [...earlier].reverse()) {
22725
+ lines.push("", `### ${item.at}`, item.packet);
22726
+ }
22727
+ }
22728
+ lines.push("", "## Artifacts");
22729
+ if (files2.total) {
22730
+ lines.push(
22731
+ `${files2.total} stored across ${files2.sessions} session${files2.sessions === 1 ? "" : "s"}. Fetch with pantheon_get_artifact (space, session_id, name).`
22732
+ );
22733
+ for (const group of files2.groups) {
22734
+ lines.push("", `From ${group.sessionId}:`, ...group.names.map((name) => `- ${name}`));
22735
+ }
22736
+ if (files2.total > files2.listed) {
22737
+ lines.push("", `\u2026and ${files2.total - files2.listed} more not listed here.`);
22738
+ }
22739
+ } else {
22740
+ lines.push("- (none stored in this space)");
22741
+ }
22742
+ lines.push(
22743
+ "",
22744
+ picked.length ? `## Last ${picked.length} spoken turns` : "## Last spoken turns",
22745
+ ...picked.length ? turnLines(picked) : ["- (nothing spoken yet)"],
22746
+ "",
22747
+ ...spaceHistory(slug, sessions, sessionId),
22748
+ ""
22749
+ );
22750
+ return `${lines.filter((line) => line !== null).join("\n")}
22751
+ `;
22752
+ }
22753
+ function spaceHistory(slug, sessions, latest) {
22754
+ const shown = sessions.slice(0, PACKET_SESSIONS);
22755
+ const hidden = sessions.length - shown.length;
22756
+ return [
22757
+ "## Full history",
22758
+ `Every session is archived verbatim, tool calls included, under spaces/${slug}/sessions/<id>/transcript.jsonl.`,
22759
+ ...shown.map((session) => sessionLine(session, session.id === latest, "\u2190 ended last")),
22760
+ ...hidden ? [`\u2026and ${hidden} older session${hidden === 1 ? "" : "s"}, listed in full by pantheon_resume.`] : [],
22761
+ "",
22762
+ `Search the whole space before deciding something is missing: pantheon_search (space: ${slug}, query: "<topic>") \u2014 it reads tool calls as well as messages.`,
22763
+ `Then pantheon_get_turns (space, session_id, from, to) for a range, or pantheon_get_session for one session end to end.`
22764
+ ];
22765
+ }
22653
22766
  function ensureSpace(home, name) {
22654
22767
  const slug = slugify(name);
22655
22768
  const root = spaceDir(home, slug);
@@ -22863,6 +22976,7 @@ function writeHandoff(home, input) {
22863
22976
  const source = input.source || captured?.session.source;
22864
22977
  const sessionId = captured ? captured.session.key : input.append ? latestSessionId(root) || void 0 : void 0;
22865
22978
  const session = writeSession(root, source, turns, artifacts, sessionId);
22979
+ const sessions = sessionSummaries(root);
22866
22980
  const packet = distill({
22867
22981
  space: input.space,
22868
22982
  source,
@@ -22870,10 +22984,24 @@ function writeHandoff(home, input) {
22870
22984
  summary: input.summary,
22871
22985
  artifacts: session.artifacts,
22872
22986
  sessionId: session.sessionId,
22873
- sessions: sessionSummaries(root)
22987
+ sessions
22874
22988
  });
22875
- writeFileSync2(join3(root, "handoff.md"), packet);
22876
22989
  writeFileSync2(join3(root, "handoffs", `${stamp()}.md`), packet);
22990
+ writeFileSync2(
22991
+ join3(root, "handoff.md"),
22992
+ spaceDistill({
22993
+ root,
22994
+ space: input.space,
22995
+ source,
22996
+ turns: session.turns,
22997
+ summary: input.summary,
22998
+ sessionId: session.sessionId,
22999
+ sessions,
23000
+ // Written after the stamped copy above so that copy is the one excluded
23001
+ // as "current" rather than the handoff before it.
23002
+ earlier: readStory(root, PACKET_STORY, PACKET_STORY_CHARS)
23003
+ })
23004
+ );
22877
23005
  if (input.facts?.length) {
22878
23006
  const extra = input.facts.map((fact) => `- ${fact.trim()}`).join("\n");
22879
23007
  appendFileSync(join3(root, "memory.md"), `${extra}
@@ -22999,13 +23127,13 @@ function packetBody(markdown) {
22999
23127
  function unstamp(name) {
23000
23128
  return name.replace(/T(\d{2})-(\d{2})-(\d{2})-(\d{3})Z$/, "T$1:$2:$3.$4Z");
23001
23129
  }
23002
- function readStory(root) {
23130
+ function readStory(root, packets = STORY_PACKETS, chars = STORY_CHARS) {
23003
23131
  const dir = join3(root, "handoffs");
23004
23132
  if (!existsSync3(dir)) return [];
23005
23133
  const files2 = readdirSync3(dir).filter((name) => name.endsWith(".md")).sort();
23006
- const prior = files2.slice(0, -1).slice(-STORY_PACKETS);
23134
+ const prior = files2.slice(0, -1).slice(-packets);
23007
23135
  const out = [];
23008
- let budget = STORY_CHARS;
23136
+ let budget = chars;
23009
23137
  for (const name of [...prior].reverse()) {
23010
23138
  if (budget <= 0) break;
23011
23139
  const packet = packetBody(readText(join3(dir, name)));
@@ -23140,7 +23268,7 @@ function resumeNote(sessions, turns, story, skills) {
23140
23268
  ];
23141
23269
  if (sessions.length > 1) {
23142
23270
  parts.push(
23143
- "The packet was written by whichever session ended last, so it does not describe the others. Every id in sessions works with pantheon_get_session and pantheon_get_turns."
23271
+ "The packet covers the space \u2014 its totals, its stored files, its most recent turns wherever they happened, and the summaries of earlier handoffs \u2014 but it is still a summary. Every id in sessions works with pantheon_get_session and pantheon_get_turns."
23144
23272
  );
23145
23273
  }
23146
23274
  if (story) {
@@ -23345,7 +23473,7 @@ Grounding \u2014 never break these:
23345
23473
  - /pantheon-spaces \u2192 call pantheon_list_spaces, then show only those slugs.
23346
23474
  - /pantheon-skills \u2192 call pantheon_skill_review. Never nominate a skill without it, never save one the human has not agreed to, and cite the turns any claim rests on. Proposing none is a normal, common outcome \u2014 say so plainly rather than finding something to fill the silence.
23347
23475
  - Files you generated (PDFs, letters, CVs, spreadsheets) must go in artifacts as base64. Handoff is rejected if the chat names a .pdf and you omit it.
23348
- - After resume, the packet is a summary of the session that ended last \u2014 not the space. Before you tell the human something was not carried over, call pantheon_search (it reads tool calls too) and pantheon_get_turns on any id from the sessions list.
23476
+ - After resume, the packet covers the whole space but is still a summary of it. Before you tell the human something was not carried over, call pantheon_search (it reads tool calls too) and pantheon_get_turns on any id from the sessions list.
23349
23477
  - Shared spaces belong to someone else and are read-only. Resume, search and the get_* tools work on them exactly as on your own. Handoff, park, remember and save_skill are refused \u2014 do not retry with a different spelling, tell the human it is read-only and offer to write to a space they own. A bare name is enough when only one space matches; write owner/space when two do.
23350
23478
  `;
23351
23479
  var GUIDE = `pantheon \u2014 agent conscience
@@ -23936,7 +24064,7 @@ ${GUIDE}` }]
23936
24064
  registerTool(
23937
24065
  server,
23938
24066
  "pantheon_resume",
23939
- "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.",
24067
+ "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 covers the whole space \u2014 totals, stored files, the most recent turns wherever they happened, and summaries of earlier handoffs \u2014 but it is a summary, not the conversation: 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.",
23940
24068
  { space: external_exports.string().optional() },
23941
24069
  async ({ space }) => safe(async () => {
23942
24070
  const sync2 = await vault.pull(home);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantheon-cli",
3
- "version": "0.2.32",
3
+ "version": "0.2.34",
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",