pantheon-cli 0.2.12 → 0.2.15

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 +99 -37
  2. package/package.json +1 -1
package/dist/pantheon.mjs CHANGED
@@ -21272,6 +21272,7 @@ import {
21272
21272
  writeFileSync as writeFileSync2,
21273
21273
  appendFileSync
21274
21274
  } from "node:fs";
21275
+ import { execFileSync } from "node:child_process";
21275
21276
  import { homedir as homedir2 } from "node:os";
21276
21277
  import { basename as basename2, isAbsolute, join as join3, relative, resolve } from "node:path";
21277
21278
 
@@ -21637,9 +21638,11 @@ function describe(session, mentionsHint) {
21637
21638
  mentionsHint
21638
21639
  };
21639
21640
  }
21641
+ var CLOSE_MS = 10 * 60 * 1e3;
21642
+ function gapMs(a, b) {
21643
+ return Math.abs(Date.parse(a.updatedAt) - Date.parse(b.updatedAt));
21644
+ }
21640
21645
  function ambiguousCapture(opts = {}) {
21641
- const needle = opts.hint?.trim().toLowerCase();
21642
- if (!needle || needle.length < 3) return null;
21643
21646
  const cwd = opts.cwd || process.cwd();
21644
21647
  const scoped = discoverLocalSessions({ cwd, source: opts.source });
21645
21648
  const candidates = (scoped.length ? scoped : discoverLocalSessions({ source: opts.source })).slice(
@@ -21648,10 +21651,29 @@ function ambiguousCapture(opts = {}) {
21648
21651
  );
21649
21652
  if (candidates.length < 2) return null;
21650
21653
  const [newest, ...rest2] = candidates;
21651
- if (tail(newest.path).toLowerCase().includes(needle)) return null;
21652
- const named = rest2.filter((session) => tail(session.path).toLowerCase().includes(needle));
21653
- if (!named.length) return null;
21654
- return [...named.slice(0, 3).map((s) => describe(s, true)), describe(newest, false)];
21654
+ const needle = opts.hint?.trim().toLowerCase();
21655
+ const usable = needle && needle.length >= 3 ? needle : null;
21656
+ const seen = /* @__PURE__ */ new Map();
21657
+ const mentions = (session) => {
21658
+ if (!usable) return false;
21659
+ const hit = seen.get(session.key);
21660
+ if (hit !== void 0) return hit;
21661
+ const found = tail(session.path).toLowerCase().includes(usable);
21662
+ seen.set(session.key, found);
21663
+ return found;
21664
+ };
21665
+ const close = rest2.filter((session) => gapMs(newest, session) <= CLOSE_MS);
21666
+ if (mentions(newest)) {
21667
+ const rivals = close.filter(mentions);
21668
+ if (!rivals.length) return null;
21669
+ return [newest, ...rivals.slice(0, 3)].map((session) => describe(session, true));
21670
+ }
21671
+ const named = rest2.filter(mentions);
21672
+ if (named.length) {
21673
+ return [...named.slice(0, 3).map((s) => describe(s, true)), describe(newest, false)];
21674
+ }
21675
+ if (!close.length) return null;
21676
+ return [newest, ...close.slice(0, 3)].map((session) => describe(session, false));
21655
21677
  }
21656
21678
  function captureLocalTranscript(opts = {}) {
21657
21679
  const { sessionKey, minTurns = 2 } = opts;
@@ -22210,6 +22232,23 @@ function readArtifactFile(path, base) {
22210
22232
  bytes: stat.size
22211
22233
  };
22212
22234
  }
22235
+ function trackedFiles(base) {
22236
+ try {
22237
+ const out = execFileSync("git", ["-C", base, "ls-files", "-z"], {
22238
+ encoding: "utf8",
22239
+ maxBuffer: 64 * 1024 * 1024,
22240
+ stdio: ["ignore", "pipe", "ignore"]
22241
+ });
22242
+ return new Set(
22243
+ out.split("\0").filter(Boolean).map((relative2) => slash(join3(base, relative2)))
22244
+ );
22245
+ } catch {
22246
+ return null;
22247
+ }
22248
+ }
22249
+ function budgetReason(tracked, limit) {
22250
+ return tracked ? `already tracked by git, so the ${limit} went to files that are not` : `over the ${limit}`;
22251
+ }
22213
22252
  function collectWrittenArtifacts(turns, cwd = process.cwd(), opts = {}) {
22214
22253
  const base = slash(resolve(cwd));
22215
22254
  const since = opts.since ?? null;
@@ -22239,11 +22278,13 @@ function collectWrittenArtifacts(turns, cwd = process.cwd(), opts = {}) {
22239
22278
  }
22240
22279
  const found = [];
22241
22280
  const skipped = [];
22281
+ let skippedTotal = 0;
22242
22282
  let total = 0;
22243
22283
  const note = (path, reason) => {
22284
+ skippedTotal += 1;
22244
22285
  if (skipped.length < MAX_SKIP_REPORT) skipped.push({ name: flatName(path, base), reason });
22245
22286
  };
22246
- const store = (path, gate) => {
22287
+ const store = (path, gate, tracked2) => {
22247
22288
  if (!existsSync3(path)) return;
22248
22289
  const stat = statSync2(path);
22249
22290
  if (!stat.isFile() || stat.size === 0) return;
@@ -22255,8 +22296,15 @@ function collectWrittenArtifacts(turns, cwd = process.cwd(), opts = {}) {
22255
22296
  );
22256
22297
  return;
22257
22298
  }
22258
- if (found.length >= MAX_WRITTEN_COUNT || total + stat.size > MAX_WRITTEN_TOTAL) {
22259
- note(path, "this handoff's artifact budget was full");
22299
+ if (found.length >= MAX_WRITTEN_COUNT) {
22300
+ note(path, budgetReason(tracked2, `${MAX_WRITTEN_COUNT}-file limit for one handoff`));
22301
+ return;
22302
+ }
22303
+ if (total + stat.size > MAX_WRITTEN_TOTAL) {
22304
+ note(
22305
+ path,
22306
+ budgetReason(tracked2, `${MAX_WRITTEN_TOTAL / 1024 / 1024}MB total limit for one handoff`)
22307
+ );
22260
22308
  return;
22261
22309
  }
22262
22310
  const file = readArtifactFile(path, base);
@@ -22264,20 +22312,19 @@ function collectWrittenArtifacts(turns, cwd = process.cwd(), opts = {}) {
22264
22312
  total += file.bytes;
22265
22313
  found.push({ name: file.name, content: file.content, encoding: file.encoding });
22266
22314
  };
22267
- for (const path of written) {
22268
- try {
22269
- store(path, false);
22270
- } catch {
22271
- }
22272
- }
22273
- for (const path of touched) {
22274
- if (written.has(path)) continue;
22315
+ const tracked = trackedFiles(base);
22316
+ const queue = [
22317
+ ...[...written].map((path) => ({ path, gate: false })),
22318
+ ...[...touched].filter((path) => !written.has(path)).map((path) => ({ path, gate: true }))
22319
+ ].map((item) => ({ ...item, tracked: tracked?.has(item.path) ?? false }));
22320
+ queue.sort((a, b) => Number(a.tracked) - Number(b.tracked));
22321
+ for (const item of queue) {
22275
22322
  try {
22276
- store(path, true);
22323
+ store(item.path, item.gate, item.tracked);
22277
22324
  } catch {
22278
22325
  }
22279
22326
  }
22280
- return { artifacts: found, skipped };
22327
+ return { artifacts: found, skipped, skippedTotal };
22281
22328
  }
22282
22329
  function collectAttachedArtifacts(turns, cwd = process.cwd()) {
22283
22330
  const base = slash(resolve(cwd));
@@ -22497,14 +22544,24 @@ function transcriptLooksThin(turns) {
22497
22544
  }
22498
22545
  return null;
22499
22546
  }
22547
+ function agoLabel(when) {
22548
+ const ms = Date.now() - Date.parse(when);
22549
+ if (!Number.isFinite(ms) || ms < 6e4) return "seconds ago";
22550
+ const minutes = Math.round(ms / 6e4);
22551
+ if (minutes < 60) return `${minutes}m ago`;
22552
+ const hours = Math.round(minutes / 60);
22553
+ return hours < 24 ? `${hours}h ago` : `${Math.round(hours / 24)}d ago`;
22554
+ }
22500
22555
  function choiceLine(choice, space) {
22501
- const why = choice.mentionsHint ? `mentions "${space}"` : "most recently written";
22556
+ const why = choice.mentionsHint ? `mentions "${space}"` : `last written ${agoLabel(choice.updatedAt)}`;
22502
22557
  const last = choice.lastMessage ? ` \xB7 last human message: "${choice.lastMessage}"` : "";
22503
22558
  return `- sessionKey: ${choice.key} \u2014 ${choice.turns} turns, ${why}${last}`;
22504
22559
  }
22505
22560
  function chooseSessionMessage(space, choices) {
22561
+ const named = choices.some((choice) => choice.mentionsHint);
22562
+ 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";
22506
22563
  return [
22507
- `More than one conversation in this workspace could be the one being handed off, and the most recently written is not the one that mentions "${space}". Do not guess.`,
22564
+ `More than one conversation in this workspace could be the one being handed off, and ${why}. Do not guess.`,
22508
22565
  "Show the human this list, ask which conversation they are in, then call pantheon_handoff again with that sessionKey:",
22509
22566
  ...choices.map((choice) => choiceLine(choice, space))
22510
22567
  ].join("\n");
@@ -22610,6 +22667,9 @@ function writeHandoff(home, input) {
22610
22667
  // Files this session made that the archive would not take. Silence here is
22611
22668
  // how a handoff comes to promise more than it holds.
22612
22669
  skipped: sweep?.skipped ?? [],
22670
+ // The list above is capped. Reporting its length as the total understates
22671
+ // the loss by however many it left out.
22672
+ skippedTotal: sweep?.skippedTotal ?? 0,
22613
22673
  // Usually empty. Only a failure that recurred across separate conversations
22614
22674
  // and is not already documented gets this far.
22615
22675
  skillCandidates: spaceSkillCandidates(root, cwd),
@@ -23057,7 +23117,7 @@ function saveMachineConfig(config2, credentials) {
23057
23117
  }
23058
23118
 
23059
23119
  // ../core/src/vault.ts
23060
- import { execFileSync } from "node:child_process";
23120
+ import { execFileSync as execFileSync2 } from "node:child_process";
23061
23121
  import { existsSync as existsSync5, mkdirSync as mkdirSync4, unlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
23062
23122
  import { homedir as homedir4, tmpdir } from "node:os";
23063
23123
  import { dirname, join as join5 } from "node:path";
@@ -23077,7 +23137,7 @@ function gitEnv(extra = {}) {
23077
23137
  };
23078
23138
  }
23079
23139
  function git(home, args, env) {
23080
- return execFileSync("git", ["-C", home, ...args], {
23140
+ return execFileSync2("git", ["-C", home, ...args], {
23081
23141
  encoding: "utf8",
23082
23142
  stdio: ["ignore", "pipe", "pipe"],
23083
23143
  env: gitEnv(env)
@@ -23183,7 +23243,7 @@ function ensureVaultClone(home, cloneUrl, token) {
23183
23243
  try {
23184
23244
  mkdirSync4(dirname(home), { recursive: true });
23185
23245
  withGitAuth(token, (env) => {
23186
- execFileSync("git", ["clone", "--depth", "50", cloneUrl, home], {
23246
+ execFileSync2("git", ["clone", "--depth", "50", cloneUrl, home], {
23187
23247
  encoding: "utf8",
23188
23248
  stdio: ["ignore", "pipe", "pipe"],
23189
23249
  env: gitEnv({
@@ -23429,8 +23489,10 @@ ${GUIDE}` }]
23429
23489
  // second conversation was open, this is where that shows.
23430
23490
  written.lastMessage ? `Last human message in the captured chat: "${written.lastMessage}" \u2014 if that is not this conversation, re-run with sessionKey from pantheon_local_sessions.` : null,
23431
23491
  // A file the session made and the archive would not take is
23432
- // the one thing the human cannot see for themselves.
23433
- written.skipped?.length ? `Not stored: ${written.skipped.map((file) => `${file.name} (${file.reason})`).join(", ")}. Tell the human, so they know the space does not hold these.` : null,
23492
+ // the one thing the human cannot see for themselves. Say how
23493
+ // many there were as well as which ones, because the list is
23494
+ // capped and reporting its length as the total is a lie.
23495
+ written.skipped?.length ? `Not stored: ${written.skippedTotal} file${written.skippedTotal === 1 ? "" : "s"}${written.skippedTotal > written.skipped.length ? `, of which these ${written.skipped.length}` : ""} \u2014 ${written.skipped.map((file) => `${file.name} (${file.reason})`).join(", ")}. Report the total, not just the named ones, so the human knows what the space does not hold.` : null,
23434
23496
  // Rare by design. Offer it, do not act on it: a skill nobody
23435
23497
  // asked for is context every future agent pays for.
23436
23498
  written.skillCandidates?.length ? `This space has hit the same problem in more than one conversation: ${written.skillCandidates.map((item) => `"${item.title}" (${item.sessions.length} sessions, key ${item.key})`).join("; ")}. Ask the human whether to write a skill for it. Only if they say yes, call pantheon_save_skill using the cited evidence \u2014 read the turns first with pantheon_get_turns rather than writing from memory. If they say no, call pantheon_dismiss_skill with that key so it stops being offered.` : null
@@ -23643,7 +23705,7 @@ async function startMcpServer(home = defaultHome()) {
23643
23705
  import { hostname as hostname3 } from "node:os";
23644
23706
 
23645
23707
  // src/connect.ts
23646
- import { execFileSync as execFileSync2 } from "node:child_process";
23708
+ import { execFileSync as execFileSync3 } from "node:child_process";
23647
23709
  import { existsSync as existsSync7, mkdirSync as mkdirSync6, renameSync } from "node:fs";
23648
23710
  import { hostname as hostname2 } from "node:os";
23649
23711
  import { join as join7 } from "node:path";
@@ -23746,7 +23808,7 @@ function upsertCodex(home) {
23746
23808
 
23747
23809
  ${block2}`);
23748
23810
  }
23749
- var spaceGate = 'A space is the short name the human chose for a conscience (preorders, auth-refactor). The argument is: $ARGUMENTS\n\nIf that value is missing, empty, still says $ARGUMENTS, contains spaces, or is not a single short name, do not call any tool. Ask: "What should this conscience be named?" and wait. Never invent a name.';
23811
+ var spaceGate = 'A space is the short name the human chose for a conscience (preorders, auth-refactor). The argument is: $ARGUMENTS\n\nIf that arrived blank, or as an unexpanded placeholder rather than a name, ask: "What should this conscience be named?" and wait. Never invent a name. Otherwise use it exactly as typed \u2014 any single short slug counts, including one that is not in the vault yet.';
23750
23812
  var slashCommands = [
23751
23813
  {
23752
23814
  name: "pantheon-handoff",
@@ -23760,7 +23822,7 @@ Only after you have a real space name, call pantheon_handoff even if that name i
23760
23822
  description: "Load a Pantheon conscience into this chat",
23761
23823
  body: `A space is the short name the human chose for a conscience. The argument is: $ARGUMENTS
23762
23824
 
23763
- Call pantheon_resume immediately. If $ARGUMENTS is missing, empty, still says $ARGUMENTS, or is not a single short name, call pantheon_resume without a space \u2014 it lists live consciences. Show that list and ask which one they meant. Do not invent a name. Once they pick a slug, call pantheon_resume with that slug. It pulls the vault first. If the packet lists artifacts, fetch the ones you need with pantheon_get_artifact. Do not use any other resume tool. Do not run pantheon sync.`
23825
+ Call pantheon_resume immediately, with that name exactly as typed. If it arrived blank or as an unexpanded placeholder, call pantheon_resume without a space \u2014 it lists live consciences. Show that list and ask which one they meant. Do not invent a name. Once they pick a slug, call pantheon_resume with that slug. It pulls the vault first. If the packet lists artifacts, fetch the ones you need with pantheon_get_artifact. Do not use any other resume tool. Do not run pantheon sync.`
23764
23826
  },
23765
23827
  {
23766
23828
  name: "pantheon-park",
@@ -24079,13 +24141,13 @@ async function connect(opts) {
24079
24141
  let archived = "";
24080
24142
  if (fresh) {
24081
24143
  process.stdout.write(" Cloning the vault\u2026\n");
24082
- execFileSync2("git", ["-c", `credential.helper=${helper}`, "clone", body.cloneUrl, home], quiet);
24144
+ execFileSync3("git", ["-c", `credential.helper=${helper}`, "clone", body.cloneUrl, home], quiet);
24083
24145
  } else {
24084
24146
  archived = syncVault2(home, body.cloneUrl, helper, quiet);
24085
24147
  }
24086
- execFileSync2("git", ["-C", home, "config", "credential.helper", helper], quiet);
24087
- execFileSync2("git", ["-C", home, "config", "user.name", "Pantheon"], quiet);
24088
- execFileSync2("git", ["-C", home, "config", "user.email", "pantheon@users.noreply.github.com"], quiet);
24148
+ execFileSync3("git", ["-C", home, "config", "credential.helper", helper], quiet);
24149
+ execFileSync3("git", ["-C", home, "config", "user.name", "Pantheon"], quiet);
24150
+ execFileSync3("git", ["-C", home, "config", "user.email", "pantheon@users.noreply.github.com"], quiet);
24089
24151
  let written = [];
24090
24152
  let skipped = [];
24091
24153
  let failure = "";
@@ -24112,7 +24174,7 @@ async function connect(opts) {
24112
24174
  );
24113
24175
  }
24114
24176
  function syncVault2(home, cloneUrl, helper, quiet) {
24115
- const git2 = (...args) => execFileSync2("git", ["-c", `credential.helper=${helper}`, "-C", home, ...args], quiet);
24177
+ const git2 = (...args) => execFileSync3("git", ["-c", `credential.helper=${helper}`, "-C", home, ...args], quiet);
24116
24178
  try {
24117
24179
  git2("pull", "--ff-only");
24118
24180
  return "";
@@ -24128,16 +24190,16 @@ function syncVault2(home, cloneUrl, helper, quiet) {
24128
24190
  const archive = `${home}-${stamp2}`;
24129
24191
  process.stdout.write(" Vault belongs to a deleted repo; setting it aside\u2026\n");
24130
24192
  renameSync(home, archive);
24131
- execFileSync2("git", ["-c", `credential.helper=${helper}`, "clone", cloneUrl, home], quiet);
24193
+ execFileSync3("git", ["-c", `credential.helper=${helper}`, "clone", cloneUrl, home], quiet);
24132
24194
  return archive;
24133
24195
  }
24134
24196
  function sharesHistory(home) {
24135
24197
  try {
24136
- const upstream = execFileSync2("git", ["-C", home, "rev-parse", "@{u}"], {
24198
+ const upstream = execFileSync3("git", ["-C", home, "rev-parse", "@{u}"], {
24137
24199
  stdio: ["ignore", "pipe", "pipe"],
24138
24200
  encoding: "utf8"
24139
24201
  }).trim();
24140
- execFileSync2("git", ["-C", home, "merge-base", "HEAD", upstream], {
24202
+ execFileSync3("git", ["-C", home, "merge-base", "HEAD", upstream], {
24141
24203
  stdio: ["ignore", "pipe", "pipe"]
24142
24204
  });
24143
24205
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantheon-cli",
3
- "version": "0.2.12",
3
+ "version": "0.2.15",
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",