pantheon-cli 0.2.44 → 0.2.47

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 +33 -99
  2. package/package.json +1 -1
package/dist/pantheon.mjs CHANGED
@@ -14816,10 +14816,10 @@ var require_fixed_queue = __commonJS({
14816
14816
  this.head.push(data);
14817
14817
  }
14818
14818
  shift() {
14819
- const tail2 = this.tail;
14820
- const next = tail2.shift();
14821
- if (tail2.isEmpty() && tail2.next !== null) {
14822
- this.tail = tail2.next;
14819
+ const tail = this.tail;
14820
+ const next = tail.shift();
14821
+ if (tail.isEmpty() && tail.next !== null) {
14822
+ this.tail = tail.next;
14823
14823
  }
14824
14824
  return next;
14825
14825
  }
@@ -23974,7 +23974,7 @@ var require_permessage_deflate = __commonJS({
23974
23974
  var { createInflateRaw, Z_DEFAULT_WINDOWBITS } = __require("node:zlib");
23975
23975
  var { isValidClientWindowBits } = require_util8();
23976
23976
  var { MessageSizeExceededError } = require_errors2();
23977
- var tail2 = Buffer.from([0, 0, 255, 255]);
23977
+ var tail = Buffer.from([0, 0, 255, 255]);
23978
23978
  var kBuffer = /* @__PURE__ */ Symbol("kBuffer");
23979
23979
  var kLength = /* @__PURE__ */ Symbol("kLength");
23980
23980
  var PerMessageDeflate = class {
@@ -24031,7 +24031,7 @@ var require_permessage_deflate = __commonJS({
24031
24031
  }
24032
24032
  this.#inflate.write(chunk);
24033
24033
  if (fin) {
24034
- this.#inflate.write(tail2);
24034
+ this.#inflate.write(tail);
24035
24035
  }
24036
24036
  this.#inflate.flush(() => {
24037
24037
  if (!this.#inflate) {
@@ -40201,84 +40201,41 @@ function readLocalSession(session) {
40201
40201
  return readers[session.source](session.path);
40202
40202
  }
40203
40203
  var HINT_TAIL_BYTES = 256 * 1024;
40204
- function tail(path, bytes = HINT_TAIL_BYTES) {
40205
- try {
40206
- const size = statSync(path).size;
40207
- const length = Math.min(size, bytes);
40208
- if (!length) return "";
40209
- const fd = openSync(path, "r");
40210
- try {
40211
- const buf = Buffer.alloc(length);
40212
- readSync(fd, buf, 0, length, size - length);
40213
- return buf.toString("utf8");
40214
- } finally {
40215
- closeSync(fd);
40216
- }
40217
- } catch {
40218
- return "";
40219
- }
40220
- }
40221
- function describe(session, mentionsHint) {
40222
- const turns = readLocalSession(session);
40223
- const spoken = [...turns].reverse().find((turn) => turn.role === "user" && turn.text.trim());
40224
- return {
40225
- key: session.key,
40226
- source: session.source,
40227
- turns: turns.length,
40228
- updatedAt: session.updatedAt,
40229
- lastMessage: spoken ? spoken.text.replace(/\s+/g, " ").trim().slice(0, 140) : null,
40230
- mentionsHint
40231
- };
40232
- }
40233
40204
  var CLOSE_MS = 10 * 60 * 1e3;
40234
- function gapMs(a, b) {
40235
- return Math.abs(Date.parse(a.updatedAt) - Date.parse(b.updatedAt));
40205
+ function escapeRegExp(value) {
40206
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
40236
40207
  }
40237
- function ambiguousCapture(opts = {}) {
40238
- const cwd = opts.cwd || process.cwd();
40239
- const scoped = discoverLocalSessions({ cwd, source: opts.source });
40240
- const candidates = (scoped.length ? scoped : discoverLocalSessions({ source: opts.source })).slice(
40241
- 0,
40242
- MAX_SCAN
40243
- );
40244
- if (candidates.length < 2) return null;
40245
- const [newest, ...rest2] = candidates;
40246
- const needle = opts.hint?.trim().toLowerCase();
40247
- const usable = needle && needle.length >= 3 ? needle : null;
40248
- const seen = /* @__PURE__ */ new Map();
40249
- const mentions = (session) => {
40250
- if (!usable) return false;
40251
- const hit = seen.get(session.key);
40252
- if (hit !== void 0) return hit;
40253
- const found = tail(session.path).toLowerCase().includes(usable);
40254
- seen.set(session.key, found);
40255
- return found;
40256
- };
40257
- const close = rest2.filter((session) => gapMs(newest, session) <= CLOSE_MS);
40258
- if (mentions(newest)) {
40259
- const rivals = close.filter(mentions);
40260
- if (!rivals.length) return null;
40261
- return [newest, ...rivals.slice(0, 3)].map((session) => describe(session, true));
40262
- }
40263
- const named = rest2.filter(mentions);
40264
- if (named.length) {
40265
- return [...named.slice(0, 3).map((s) => describe(s, true)), describe(newest, false)];
40208
+ function targetsHandoff(turns, space) {
40209
+ const target = space.trim();
40210
+ if (!target) return false;
40211
+ const last = [...turns].reverse().find((turn) => turn.role === "user" && turn.text.trim());
40212
+ if (!last) return false;
40213
+ return new RegExp(
40214
+ `(?:/pantheon-handoff|\\bpantheon_handoff)\\s+${escapeRegExp(target)}(?=\\s|$|[<"'\\\`])`,
40215
+ "i"
40216
+ ).test(last.text);
40217
+ }
40218
+ function selectCapturedTranscript(candidates, hint3) {
40219
+ if (!candidates.length) return null;
40220
+ if (hint3) {
40221
+ const current = candidates.find((candidate) => targetsHandoff(candidate.turns, hint3));
40222
+ if (current) return current;
40266
40223
  }
40267
- if (!close.length) return null;
40268
- return [newest, ...close.slice(0, 3)].map((session) => describe(session, false));
40224
+ return candidates[0] ?? null;
40269
40225
  }
40270
40226
  function captureLocalTranscript(opts = {}) {
40271
- const { sessionKey, minTurns = 2 } = opts;
40227
+ const { sessionKey, minTurns = 2, hint: hint3 } = opts;
40272
40228
  const cwd = opts.cwd || process.cwd();
40273
40229
  const scoped = discoverLocalSessions({ cwd, source: opts.source });
40274
40230
  const candidates = sessionKey ? discoverLocalSessions({ source: opts.source }).filter(
40275
40231
  (item) => item.key === sessionKey || item.key.endsWith(sessionKey)
40276
40232
  ) : scoped.length ? scoped : discoverLocalSessions({ source: opts.source });
40233
+ const readable = [];
40277
40234
  for (const session of candidates.slice(0, MAX_SCAN)) {
40278
40235
  const turns = readLocalSession(session);
40279
- if (turns.length >= minTurns) return { session, turns };
40236
+ if (turns.length >= minTurns) readable.push({ session, turns });
40280
40237
  }
40281
- return null;
40238
+ return selectCapturedTranscript(readable, sessionKey ? void 0 : hint3);
40282
40239
  }
40283
40240
 
40284
40241
  // ../core/src/skills.ts
@@ -41757,28 +41714,6 @@ function transcriptLooksThin(turns) {
41757
41714
  }
41758
41715
  return null;
41759
41716
  }
41760
- function agoLabel(when) {
41761
- const ms = Date.now() - Date.parse(when);
41762
- if (!Number.isFinite(ms) || ms < 6e4) return "seconds ago";
41763
- const minutes = Math.round(ms / 6e4);
41764
- if (minutes < 60) return `${minutes}m ago`;
41765
- const hours = Math.round(minutes / 60);
41766
- return hours < 24 ? `${hours}h ago` : `${Math.round(hours / 24)}d ago`;
41767
- }
41768
- function choiceLine(choice, space) {
41769
- const why = choice.mentionsHint ? `mentions "${space}"` : `last written ${agoLabel(choice.updatedAt)}`;
41770
- const last = choice.lastMessage ? ` \xB7 last human message: "${choice.lastMessage}"` : "";
41771
- return `- sessionKey: ${choice.key} \u2014 ${choice.turns} turns, ${why}${last}`;
41772
- }
41773
- function chooseSessionMessage(space, choices) {
41774
- const named = choices.some((choice) => choice.mentionsHint);
41775
- const why = named ? `the most recently written is not the one that mentions "${space}"` : "they were written minutes apart, and a chat is usually the last to flush its own turns to disk \u2014 so the newest file is not reliably the one asking";
41776
- return [
41777
- `More than one conversation in this workspace could be the one being handed off, and ${why}. Do not guess.`,
41778
- "Show the human this list, ask which conversation they are in, then call pantheon_handoff again with that sessionKey:",
41779
- ...choices.map((choice) => choiceLine(choice, space))
41780
- ].join("\n");
41781
- }
41782
41717
  function unreadableClientMessage(client, space) {
41783
41718
  return [
41784
41719
  `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.`,
@@ -41797,15 +41732,14 @@ function resolveTranscript(input) {
41797
41732
  const client = clientCapture(input.client);
41798
41733
  if (!input.sessionKey) {
41799
41734
  if (!client.readable) throw new Error(unreadableClientMessage(input.client, input.space));
41800
- const choices = ambiguousCapture({ cwd: input.cwd, source: client.source, hint: input.space });
41801
- if (choices) throw new Error(chooseSessionMessage(input.space, choices));
41802
41735
  }
41803
41736
  const captured = captureLocalTranscript({
41804
41737
  cwd: input.cwd,
41805
41738
  // Scoped to the calling app's own log, so a handoff from one editor cannot
41806
41739
  // reach into another editor's chats.
41807
41740
  source: input.sessionKey ? void 0 : client.source,
41808
- sessionKey: input.sessionKey
41741
+ sessionKey: input.sessionKey,
41742
+ hint: input.space
41809
41743
  });
41810
41744
  if (!captured?.turns.length) {
41811
41745
  throw new Error(
@@ -43428,7 +43362,7 @@ ${GUIDE}` }]
43428
43362
  registerTool(
43429
43363
  server,
43430
43364
  "pantheon_handoff",
43431
- "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. Attach every existing generated or uploaded file that is not already captured from the workspace. Prefer { name, path } with local desktop MCP, use { name, url } for a downloadable HTTPS file, and use inline base64 only as a fallback. Never generate or rewrite a file merely for handoff. When a successful handoff adds turns, it returns a post-handoff skill review for you to process. Read cited turns and submit up to five justified drafts together with pantheon_save_skill_drafts without asking the human; drafts are inert until approved in the UI. REPORT THE FINAL RESULT after that follow-up 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 drafts saved, and committed/pulled/pushed. Do not restate the summary. Only a sync or tool failure belongs outside the table.",
43365
+ "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 and do not ask which local conversation to use: in Cursor, Codex and Claude Code, Pantheon selects the session whose latest human turn invokes this handoff, falling back to the most recently recorded session, then reads its complete history including tool calls. Pass cwd when the project folder is not the server's working directory. In any other app \u2014 Claude Desktop, Windsurf, a web chat \u2014 local capture is refused rather than allowed to archive an unrelated 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, not a JSON string. Handing off the same chat again appends only the new turns to the same archive. Attach every existing generated or uploaded file that is not already captured from the workspace. Prefer { name, path } with local desktop MCP, use { name, url } for a downloadable HTTPS file, and use inline base64 only as a fallback. Never generate or rewrite a file merely for handoff. When a successful handoff adds turns, it returns a post-handoff skill review for you to process. Read cited turns and submit up to five justified drafts together with pantheon_save_skill_drafts without asking the human; drafts are inert until approved in the UI. REPORT THE FINAL RESULT after that follow-up 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 drafts saved, and committed/pulled/pushed. Do not restate the summary. Only a sync or tool failure belongs outside the table.",
43432
43366
  {
43433
43367
  space: external_exports.string(),
43434
43368
  source: external_exports.string().optional(),
@@ -43996,7 +43930,7 @@ var slashCommands = [
43996
43930
  description: "Leave a Pantheon conscience for the next agent",
43997
43931
  body: `${spaceGate}
43998
43932
 
43999
- Only after you have a real space name, call pantheon_handoff even if that name is not in pantheon_list_spaces. First handoff creates the space. Do not refuse. Do not tell the human to create it first. transcript is the real thread, not a recap. Each human message is { role: "user", text: "<what they typed>" }. Each of your replies is { role: "assistant", text: "<what you said>" }. Copy the words. Do not write "User asked\u2026" or "Assistant wrote\u2026". Do not mark your replies as user. Same timestamp on every turn will be rejected. Attach every EXISTING file you generated \u2014 PDFs, letters, CVs, spreadsheets \u2014 and every file the human uploaded. Prefer { name, path } when local desktop MCP can read it. Use { name, url } for an existing downloadable HTTPS file. Use { name, content: "<base64>", encoding: "base64" } only when neither is available. Never create, regenerate, convert, or rewrite a file merely to complete the handoff. Claude may expose existing files under /mnt/user-data/outputs or as a download URL. A chat that names a .pdf without attaching it is rejected. Named code fences are stored automatically. If the thread is too long, send the oldest visible chunk with truncated:true, then call again with append:true. The tool commits and pushes \u2014 do not run pantheon sync.
43933
+ Only after you have a real space name, call pantheon_handoff even if that name is not in pantheon_list_spaces. First handoff creates the space. Do not refuse. Do not tell the human to create it first. In Cursor, Codex and Claude Code, OMIT transcript and do not ask which conversation to use: Pantheon selects the session whose latest human turn invokes this handoff and reads its complete history from disk, including tool calls. Only send transcript when the tool explicitly says this client cannot be captured; then send the real thread, role user = what the human typed and role assistant = what you replied, never a recap. Attach every EXISTING file you generated \u2014 PDFs, letters, CVs, spreadsheets \u2014 and every file the human uploaded. Prefer { name, path } when local desktop MCP can read it. Use { name, url } for an existing downloadable HTTPS file. Use { name, content: "<base64>", encoding: "base64" } only when neither is available. Never create, regenerate, convert, or rewrite a file merely to complete the handoff. Claude may expose existing files under /mnt/user-data/outputs or as a download URL. A chat that names a .pdf without attaching it is rejected. Named code fences are stored automatically. The tool commits and pushes \u2014 do not run pantheon sync.
44000
43934
 
44001
43935
  ${autoSkillReview}
44002
43936
 
@@ -44084,7 +44018,7 @@ Grounding: the only space list is the \`pantheon_list_spaces\` tool result. Neve
44084
44018
 
44085
44019
  A **space** is the short name the human chose for a conscience. For handoff, park, or remember: if they did not give one, ask: "What should this conscience be named?" Do not invent a name. If they typed a new slug for handoff, call \`pantheon_handoff\` \u2014 that creates the space. For resume with no name, call \`pantheon_resume\` anyway \u2014 it lists live spaces. Show that list and ask which one.
44086
44020
 
44087
- For handoff, send the real thread: role user = what the human typed, role assistant = what you replied. Copy the words. Never write a third-person recap. Never label your replies as user. Attach every existing generated or uploaded file \u2014 not just code fences. Prefer \`{ name, path }\` for local files, use \`{ name, url }\` for downloadable HTTPS files, and use inline base64 only as a fallback. Never create or rewrite an artifact merely for handoff. On resume, fetch only needed files with \`pantheon_get_artifact\`; use \`save_to\` to restore the actual file into a local workspace. Handoff commits and pushes; resume pulls. Do not run \`pantheon sync\` or \`pantheon handoff\` in a shell.
44021
+ For handoff in Cursor, Codex or Claude Code, omit transcript and do not ask which conversation to use: Pantheon identifies the current handoff command and reads the complete local session. Only send transcript when the tool explicitly says the client cannot be captured; then send the real thread, role user = what the human typed and role assistant = what you replied, never a recap. Attach every existing generated or uploaded file \u2014 not just code fences. Prefer \`{ name, path }\` for local files, use \`{ name, url }\` for downloadable HTTPS files, and use inline base64 only as a fallback. Never create or rewrite an artifact merely for handoff. On resume, fetch only needed files with \`pantheon_get_artifact\`; use \`save_to\` to restore the actual file into a local workspace. Handoff commits and pushes; resume pulls. Do not run \`pantheon sync\` or \`pantheon handoff\` in a shell.
44088
44022
 
44089
44023
  ${autoSkillReview}
44090
44024
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantheon-cli",
3
- "version": "0.2.44",
3
+ "version": "0.2.47",
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",