pantheon-cli 0.2.10 → 0.2.12

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 +123 -13
  2. package/package.json +1 -1
package/dist/pantheon.mjs CHANGED
@@ -21267,6 +21267,7 @@ import {
21267
21267
  mkdirSync as mkdirSync2,
21268
21268
  readFileSync as readFileSync3,
21269
21269
  readdirSync as readdirSync3,
21270
+ rmSync as rmSync2,
21270
21271
  statSync as statSync2,
21271
21272
  writeFileSync as writeFileSync2,
21272
21273
  appendFileSync
@@ -21278,6 +21279,22 @@ import { basename as basename2, isAbsolute, join as join3, relative, resolve } f
21278
21279
  import { closeSync, existsSync, openSync, readFileSync, readSync, readdirSync, statSync } from "node:fs";
21279
21280
  import { homedir } from "node:os";
21280
21281
  import { basename, join } from "node:path";
21282
+ var CLIENT_SOURCES = [
21283
+ // Before the bare claude test: Claude Code is readable, Claude Desktop is not.
21284
+ [/claude[-_ ]?code/i, "claude-code"],
21285
+ [/cursor/i, "cursor"],
21286
+ [/codex|chatgpt/i, "codex"]
21287
+ ];
21288
+ var UNREADABLE_CLIENTS = /claude[-_ ]?(ai|desktop)|windsurf|replit|continue|cline/i;
21289
+ function clientCapture(client) {
21290
+ const name = client?.trim();
21291
+ if (!name) return { readable: true, known: false };
21292
+ for (const [pattern, source] of CLIENT_SOURCES) {
21293
+ if (pattern.test(name)) return { source, readable: true, known: true };
21294
+ }
21295
+ if (UNREADABLE_CLIENTS.test(name)) return { readable: false, known: true };
21296
+ return { readable: true, known: false };
21297
+ }
21281
21298
  var MAX_SCAN = 60;
21282
21299
  function readLines(path) {
21283
21300
  try {
@@ -21964,23 +21981,41 @@ function ensureDir(path) {
21964
21981
  function readText(path) {
21965
21982
  return existsSync3(path) ? readFileSync3(path, "utf8") : "";
21966
21983
  }
21984
+ function jsonTurns(transcript) {
21985
+ const text2 = transcript.trim();
21986
+ if (!text2.startsWith("[") && !text2.startsWith("{")) return null;
21987
+ try {
21988
+ const parsed = JSON.parse(text2);
21989
+ const list = Array.isArray(parsed) ? parsed : Array.isArray(parsed.turns) ? parsed.turns : null;
21990
+ if (!list?.length) return null;
21991
+ const turns = list.filter(
21992
+ (item) => Boolean(item) && typeof item === "object" && typeof item.text === "string"
21993
+ );
21994
+ return turns.length ? turns : null;
21995
+ } catch {
21996
+ return null;
21997
+ }
21998
+ }
21967
21999
  function parseTurns(transcript) {
21968
- if (Array.isArray(transcript)) {
21969
- return transcript.map((turn, index) => ({
22000
+ const list = Array.isArray(transcript) ? transcript : jsonTurns(transcript);
22001
+ if (list) {
22002
+ const base2 = Date.now();
22003
+ return list.map((turn, index) => ({
21970
22004
  id: turn.id ?? index + 1,
21971
- role: turn.role,
22005
+ role: turn.role === "assistant" || turn.role === "system" ? turn.role : "user",
21972
22006
  text: turn.text,
21973
- ts: turn.ts || nowIso(),
22007
+ ts: turn.ts || new Date(base2 + index).toISOString(),
21974
22008
  toolCalls: turn.toolCalls
21975
22009
  }));
21976
22010
  }
22011
+ const base = Date.now();
21977
22012
  return transcript.split(/\n{2,}/).map((block2, index) => {
21978
22013
  const match = block2.match(/^(user|assistant|system)\s*:\s*([\s\S]+)/i);
21979
22014
  return {
21980
22015
  id: index + 1,
21981
22016
  role: match?.[1]?.toLowerCase() || "user",
21982
22017
  text: (match?.[2] || block2).trim(),
21983
- ts: nowIso()
22018
+ ts: new Date(base + index).toISOString()
21984
22019
  };
21985
22020
  }).filter((turn) => turn.text);
21986
22021
  }
@@ -22474,6 +22509,13 @@ function chooseSessionMessage(space, choices) {
22474
22509
  ...choices.map((choice) => choiceLine(choice, space))
22475
22510
  ].join("\n");
22476
22511
  }
22512
+ function unreadableClientMessage(client, space) {
22513
+ return [
22514
+ `This conversation is running in ${client || "an app"}, which keeps its chats somewhere Pantheon cannot read. Capture would archive an unrelated conversation from this machine into "${space}", so it is refused.`,
22515
+ "Send the transcript yourself: one object per message, role user = what the human typed, role assistant = what you replied, verbatim and never narrated. Pass it as an array, not a JSON string.",
22516
+ "If the human actually meant to archive a chat from a local editor, call pantheon_local_sessions and pass the chosen sessionKey."
22517
+ ].join(" ");
22518
+ }
22477
22519
  function resolveTranscript(input) {
22478
22520
  const supplied = input.transcript ? parseTurns(input.transcript) : [];
22479
22521
  if (supplied.length) return { turns: supplied, captured: null };
@@ -22482,11 +22524,19 @@ function resolveTranscript(input) {
22482
22524
  "Transcript is empty and capture is disabled. Send the real turns, or drop capture:false to archive this chat from local history."
22483
22525
  );
22484
22526
  }
22527
+ const client = clientCapture(input.client);
22485
22528
  if (!input.sessionKey) {
22486
- const choices = ambiguousCapture({ cwd: input.cwd, hint: input.space });
22529
+ if (!client.readable) throw new Error(unreadableClientMessage(input.client, input.space));
22530
+ const choices = ambiguousCapture({ cwd: input.cwd, source: client.source, hint: input.space });
22487
22531
  if (choices) throw new Error(chooseSessionMessage(input.space, choices));
22488
22532
  }
22489
- const captured = captureLocalTranscript({ cwd: input.cwd, sessionKey: input.sessionKey });
22533
+ const captured = captureLocalTranscript({
22534
+ cwd: input.cwd,
22535
+ // Scoped to the calling app's own log, so a handoff from one editor cannot
22536
+ // reach into another editor's chats.
22537
+ source: input.sessionKey ? void 0 : client.source,
22538
+ sessionKey: input.sessionKey
22539
+ });
22490
22540
  if (!captured?.turns.length) {
22491
22541
  throw new Error(
22492
22542
  "No local conversation history found for this workspace. Pass cwd for the project folder, or send the transcript explicitly with every user and assistant turn verbatim."
@@ -22843,6 +22893,35 @@ function getSession(home, space, sessionId) {
22843
22893
  const turns = readFileSync3(file, "utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line));
22844
22894
  return { sessionId, turns, artifacts: listArtifacts(home, space, sessionId) };
22845
22895
  }
22896
+ function forgetSession(home, space, sessionId) {
22897
+ requireSpaceName(space);
22898
+ const slug = slugify(space);
22899
+ const root = spaceDir(home, slug);
22900
+ const id = basename2(sessionId.trim());
22901
+ if (!id || id.startsWith(".")) throw new Error(`Not a session id: "${sessionId}".`);
22902
+ const dir = join3(root, "sessions", id);
22903
+ if (!existsSync3(dir)) {
22904
+ const known = sessionDirs(root).map((session) => session.id);
22905
+ throw new Error(
22906
+ known.length ? `No session "${id}" in "${slug}". Archived sessions: ${known.join(", ")}.` : `No session "${id}" in "${slug}". This space has no archived sessions.`
22907
+ );
22908
+ }
22909
+ const turns = countLines(join3(dir, "transcript.jsonl"));
22910
+ const artifacts = existsSync3(join3(dir, "artifacts")) ? readdirSync3(join3(dir, "artifacts")).length : 0;
22911
+ rmSync2(dir, { recursive: true, force: true });
22912
+ const remaining = sessionDirs(root);
22913
+ return {
22914
+ slug,
22915
+ sessionId: id,
22916
+ turns,
22917
+ artifacts,
22918
+ remainingSessions: remaining.length,
22919
+ remainingTurns: remaining.reduce(
22920
+ (sum, session) => sum + countLines(join3(session.dir, "transcript.jsonl")),
22921
+ 0
22922
+ )
22923
+ };
22924
+ }
22846
22925
  function listArtifacts(home, space, sessionId) {
22847
22926
  const { root } = ensureSpace(home, space);
22848
22927
  const dir = join3(root, "sessions", sessionId, "artifacts");
@@ -22936,6 +23015,8 @@ MCP tools \u2014 always the pantheon_ prefix
22936
23015
  pantheon_get_turns fetch a turn range
22937
23016
  pantheon_get_session fetch a stored transcript
22938
23017
  pantheon_get_artifact fetch a stored file
23018
+ pantheon_forget_session delete one archived chat, when capture read the
23019
+ wrong one. Not undoable \u2014 confirm the id first.
22939
23020
 
22940
23021
  Chat shortcuts (namespaced \u2014 use these, not /resume)
22941
23022
  /pantheon-handoff <space>
@@ -23310,11 +23391,13 @@ ${GUIDE}` }]
23310
23391
  registerTool(
23311
23392
  server,
23312
23393
  "pantheon_handoff",
23313
- `Archive this chat into a Pantheon space. Trigger: /pantheon-handoff <space>. If the human typed a slug, call this even when that slug is not in pantheon_list_spaces \u2014 first handoff creates the space. Do not ask them to create it first. LEAVE transcript EMPTY: Pantheon reads the complete conversation, including tool calls, straight from this app's own history on disk, so nothing is lost and you do not spend tokens retyping it. Pass cwd when the project folder is not the server's working directory. Only send transcript yourself when capture cannot see this chat (a hosted or web-only agent) \u2014 then it must be the real thread, one object per message, role user = what the human typed, role assistant = what you replied, verbatim and never narrated. Handing off the same chat again appends only the new turns to the same archive. artifacts is still required for files you generated or the human uploaded that do not live in this repo \u2014 pass { name, content: base64, encoding: "base64" }. REPORT THE RESULT as a two-column table and nothing else: space, session, captured from, turns added, already archived, total turns, artifact count (the number, never the names), skill candidates, and committed/pulled/pushed. Do not restate the summary you just wrote. Two things belong outside the table because they are not receipts: say plainly what broke if sync failed, and if skillCandidates is non-empty ask the human whether to write a skill for each one.`,
23394
+ `Archive this chat into a Pantheon space. Trigger: /pantheon-handoff <space>. If the human typed a slug, call this even when that slug is not in pantheon_list_spaces \u2014 first handoff creates the space. Do not ask them to create it first. LEAVE transcript EMPTY: Pantheon reads the complete conversation, including tool calls, straight from this app's own history on disk, so nothing is lost and you do not spend tokens retyping it. Pass cwd when the project folder is not the server's working directory. Capture only works in Cursor, Codex and Claude Code, which write their chats to disk. In any other app \u2014 Claude Desktop, Windsurf, a web chat \u2014 it is refused rather than allowed to archive an unrelated local conversation, and you must send transcript yourself: the real thread, one object per message, role user = what the human typed, role assistant = what you replied, verbatim and never narrated. Pass it as an array of objects, not as a JSON string. Handing off the same chat again appends only the new turns to the same archive. artifacts is still required for files you generated or the human uploaded that do not live in this repo \u2014 pass { name, content: base64, encoding: "base64" }. REPORT THE RESULT as a two-column table and nothing else: space, session, captured from, turns added, already archived, total turns, artifact count (the number, never the names), skill candidates, and committed/pulled/pushed. Do not restate the summary you just wrote. Two things belong outside the table because they are not receipts: say plainly what broke if sync failed, and if skillCandidates is non-empty ask the human whether to write a skill for each one.`,
23314
23395
  {
23315
23396
  space: external_exports.string(),
23316
23397
  source: external_exports.string().optional(),
23317
- transcript: external_exports.union([external_exports.array(turnSchema), external_exports.string()]).optional().describe("Omit this. Only needed when local capture cannot see the chat."),
23398
+ transcript: external_exports.union([external_exports.array(turnSchema), external_exports.string()]).optional().describe(
23399
+ "Omit this in Cursor, Codex and Claude Code. Required everywhere else. An array of turn objects \u2014 not a JSON string of one."
23400
+ ),
23318
23401
  summary: external_exports.string().optional().describe("Short orientation for the next agent. The full transcript is stored separately."),
23319
23402
  facts: external_exports.array(external_exports.string()).optional(),
23320
23403
  artifacts: external_exports.array(artifactSchema).optional(),
@@ -23328,7 +23411,11 @@ ${GUIDE}` }]
23328
23411
  const request = input;
23329
23412
  const written = writeHandoff(home, {
23330
23413
  ...request,
23331
- capture: allowCapture ? request.capture : false
23414
+ capture: allowCapture ? request.capture : false,
23415
+ // Which app is on the other end of this stdio pipe. Running locally
23416
+ // is not the same as keeping chats where Pantheon can read them, and
23417
+ // capture needs to tell those apart before it reads anything.
23418
+ client: server.server.getClientVersion()?.name
23332
23419
  });
23333
23420
  const sync2 = await vault.push(home, `handoff ${written.slug}`);
23334
23421
  return {
@@ -23450,6 +23537,25 @@ ${GUIDE}` }]
23450
23537
  },
23451
23538
  async ({ space, session_id, name }) => safe(() => getArtifact(home, space, session_id, name))
23452
23539
  );
23540
+ registerTool(
23541
+ server,
23542
+ "pantheon_forget_session",
23543
+ "Delete one archived conversation from a Pantheon space, with its stored files. Use when a handoff captured the wrong chat \u2014 a second window, or an app whose history is not on this machine \u2014 and the space now holds a conversation that does not belong to it. This is not undoable: confirm the session id with the human against pantheon_resume or pantheon_local_sessions before calling, and never guess which one they meant. The space, its memory and its other sessions are untouched.",
23544
+ {
23545
+ space: external_exports.string(),
23546
+ session_id: external_exports.string().describe("Exactly as listed in the resume packet.")
23547
+ },
23548
+ async ({ space, session_id }) => safe(async () => {
23549
+ const removed = forgetSession(home, space, session_id);
23550
+ const sync2 = await vault.push(home, `forget session ${removed.sessionId}`);
23551
+ return {
23552
+ ok: sync2.ok !== false,
23553
+ ...removed,
23554
+ sync: sync2,
23555
+ note: sync2.ok === false ? `Removed locally but the push failed: ${sync2.error || "unknown error"}. Tell the human it is still in GitHub.` : `Removed ${removed.turns} turns and ${removed.artifacts} files. "${removed.slug}" now holds ${removed.remainingSessions} sessions and ${removed.remainingTurns} turns.`
23556
+ };
23557
+ })
23558
+ );
23453
23559
  registerTool(
23454
23560
  server,
23455
23561
  "pantheon_get_skill",
@@ -23534,11 +23640,12 @@ async function startMcpServer(home = defaultHome()) {
23534
23640
  }
23535
23641
 
23536
23642
  // src/bootstrap.ts
23537
- import { hostname as hostname2 } from "node:os";
23643
+ import { hostname as hostname3 } from "node:os";
23538
23644
 
23539
23645
  // src/connect.ts
23540
23646
  import { execFileSync as execFileSync2 } from "node:child_process";
23541
23647
  import { existsSync as existsSync7, mkdirSync as mkdirSync6, renameSync } from "node:fs";
23648
+ import { hostname as hostname2 } from "node:os";
23542
23649
  import { join as join7 } from "node:path";
23543
23650
 
23544
23651
  // src/mcp-install.ts
@@ -23936,7 +24043,10 @@ async function connect(opts) {
23936
24043
  const res = await fetch(`${host}/api/cli/pair`, {
23937
24044
  method: "POST",
23938
24045
  headers: { "content-type": "application/json" },
23939
- body: JSON.stringify({ code })
24046
+ // The name is what the dashboard lists, and it is also the key the
24047
+ // server de-duplicates on: pairing this machine again replaces its own
24048
+ // row instead of adding another anonymous one.
24049
+ body: JSON.stringify({ code, name: hostname2() })
23940
24050
  });
23941
24051
  const payload = await res.json();
23942
24052
  if (res.ok) {
@@ -24071,7 +24181,7 @@ async function bootstrapFromToken(token, opts = {}) {
24071
24181
  "content-type": "application/json",
24072
24182
  authorization: `Bearer ${token}`
24073
24183
  },
24074
- body: JSON.stringify({ name: hostname2() })
24184
+ body: JSON.stringify({ name: hostname3() })
24075
24185
  });
24076
24186
  const payload = await res.json();
24077
24187
  if (res.ok) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantheon-cli",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
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",