pantheon-cli 0.2.10 → 0.2.14
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.
- package/dist/pantheon.mjs +162 -21
- 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 {
|
|
@@ -21620,9 +21637,11 @@ function describe(session, mentionsHint) {
|
|
|
21620
21637
|
mentionsHint
|
|
21621
21638
|
};
|
|
21622
21639
|
}
|
|
21640
|
+
var CLOSE_MS = 10 * 60 * 1e3;
|
|
21641
|
+
function gapMs(a, b) {
|
|
21642
|
+
return Math.abs(Date.parse(a.updatedAt) - Date.parse(b.updatedAt));
|
|
21643
|
+
}
|
|
21623
21644
|
function ambiguousCapture(opts = {}) {
|
|
21624
|
-
const needle = opts.hint?.trim().toLowerCase();
|
|
21625
|
-
if (!needle || needle.length < 3) return null;
|
|
21626
21645
|
const cwd = opts.cwd || process.cwd();
|
|
21627
21646
|
const scoped = discoverLocalSessions({ cwd, source: opts.source });
|
|
21628
21647
|
const candidates = (scoped.length ? scoped : discoverLocalSessions({ source: opts.source })).slice(
|
|
@@ -21631,10 +21650,29 @@ function ambiguousCapture(opts = {}) {
|
|
|
21631
21650
|
);
|
|
21632
21651
|
if (candidates.length < 2) return null;
|
|
21633
21652
|
const [newest, ...rest2] = candidates;
|
|
21634
|
-
|
|
21635
|
-
const
|
|
21636
|
-
|
|
21637
|
-
|
|
21653
|
+
const needle = opts.hint?.trim().toLowerCase();
|
|
21654
|
+
const usable = needle && needle.length >= 3 ? needle : null;
|
|
21655
|
+
const seen = /* @__PURE__ */ new Map();
|
|
21656
|
+
const mentions = (session) => {
|
|
21657
|
+
if (!usable) return false;
|
|
21658
|
+
const hit = seen.get(session.key);
|
|
21659
|
+
if (hit !== void 0) return hit;
|
|
21660
|
+
const found = tail(session.path).toLowerCase().includes(usable);
|
|
21661
|
+
seen.set(session.key, found);
|
|
21662
|
+
return found;
|
|
21663
|
+
};
|
|
21664
|
+
const close = rest2.filter((session) => gapMs(newest, session) <= CLOSE_MS);
|
|
21665
|
+
if (mentions(newest)) {
|
|
21666
|
+
const rivals = close.filter(mentions);
|
|
21667
|
+
if (!rivals.length) return null;
|
|
21668
|
+
return [newest, ...rivals.slice(0, 3)].map((session) => describe(session, true));
|
|
21669
|
+
}
|
|
21670
|
+
const named = rest2.filter(mentions);
|
|
21671
|
+
if (named.length) {
|
|
21672
|
+
return [...named.slice(0, 3).map((s) => describe(s, true)), describe(newest, false)];
|
|
21673
|
+
}
|
|
21674
|
+
if (!close.length) return null;
|
|
21675
|
+
return [newest, ...close.slice(0, 3)].map((session) => describe(session, false));
|
|
21638
21676
|
}
|
|
21639
21677
|
function captureLocalTranscript(opts = {}) {
|
|
21640
21678
|
const { sessionKey, minTurns = 2 } = opts;
|
|
@@ -21964,23 +22002,41 @@ function ensureDir(path) {
|
|
|
21964
22002
|
function readText(path) {
|
|
21965
22003
|
return existsSync3(path) ? readFileSync3(path, "utf8") : "";
|
|
21966
22004
|
}
|
|
22005
|
+
function jsonTurns(transcript) {
|
|
22006
|
+
const text2 = transcript.trim();
|
|
22007
|
+
if (!text2.startsWith("[") && !text2.startsWith("{")) return null;
|
|
22008
|
+
try {
|
|
22009
|
+
const parsed = JSON.parse(text2);
|
|
22010
|
+
const list = Array.isArray(parsed) ? parsed : Array.isArray(parsed.turns) ? parsed.turns : null;
|
|
22011
|
+
if (!list?.length) return null;
|
|
22012
|
+
const turns = list.filter(
|
|
22013
|
+
(item) => Boolean(item) && typeof item === "object" && typeof item.text === "string"
|
|
22014
|
+
);
|
|
22015
|
+
return turns.length ? turns : null;
|
|
22016
|
+
} catch {
|
|
22017
|
+
return null;
|
|
22018
|
+
}
|
|
22019
|
+
}
|
|
21967
22020
|
function parseTurns(transcript) {
|
|
21968
|
-
|
|
21969
|
-
|
|
22021
|
+
const list = Array.isArray(transcript) ? transcript : jsonTurns(transcript);
|
|
22022
|
+
if (list) {
|
|
22023
|
+
const base2 = Date.now();
|
|
22024
|
+
return list.map((turn, index) => ({
|
|
21970
22025
|
id: turn.id ?? index + 1,
|
|
21971
|
-
role: turn.role,
|
|
22026
|
+
role: turn.role === "assistant" || turn.role === "system" ? turn.role : "user",
|
|
21972
22027
|
text: turn.text,
|
|
21973
|
-
ts: turn.ts ||
|
|
22028
|
+
ts: turn.ts || new Date(base2 + index).toISOString(),
|
|
21974
22029
|
toolCalls: turn.toolCalls
|
|
21975
22030
|
}));
|
|
21976
22031
|
}
|
|
22032
|
+
const base = Date.now();
|
|
21977
22033
|
return transcript.split(/\n{2,}/).map((block2, index) => {
|
|
21978
22034
|
const match = block2.match(/^(user|assistant|system)\s*:\s*([\s\S]+)/i);
|
|
21979
22035
|
return {
|
|
21980
22036
|
id: index + 1,
|
|
21981
22037
|
role: match?.[1]?.toLowerCase() || "user",
|
|
21982
22038
|
text: (match?.[2] || block2).trim(),
|
|
21983
|
-
ts:
|
|
22039
|
+
ts: new Date(base + index).toISOString()
|
|
21984
22040
|
};
|
|
21985
22041
|
}).filter((turn) => turn.text);
|
|
21986
22042
|
}
|
|
@@ -22462,18 +22518,35 @@ function transcriptLooksThin(turns) {
|
|
|
22462
22518
|
}
|
|
22463
22519
|
return null;
|
|
22464
22520
|
}
|
|
22521
|
+
function agoLabel(when) {
|
|
22522
|
+
const ms = Date.now() - Date.parse(when);
|
|
22523
|
+
if (!Number.isFinite(ms) || ms < 6e4) return "seconds ago";
|
|
22524
|
+
const minutes = Math.round(ms / 6e4);
|
|
22525
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
22526
|
+
const hours = Math.round(minutes / 60);
|
|
22527
|
+
return hours < 24 ? `${hours}h ago` : `${Math.round(hours / 24)}d ago`;
|
|
22528
|
+
}
|
|
22465
22529
|
function choiceLine(choice, space) {
|
|
22466
|
-
const why = choice.mentionsHint ? `mentions "${space}"` :
|
|
22530
|
+
const why = choice.mentionsHint ? `mentions "${space}"` : `last written ${agoLabel(choice.updatedAt)}`;
|
|
22467
22531
|
const last = choice.lastMessage ? ` \xB7 last human message: "${choice.lastMessage}"` : "";
|
|
22468
22532
|
return `- sessionKey: ${choice.key} \u2014 ${choice.turns} turns, ${why}${last}`;
|
|
22469
22533
|
}
|
|
22470
22534
|
function chooseSessionMessage(space, choices) {
|
|
22535
|
+
const named = choices.some((choice) => choice.mentionsHint);
|
|
22536
|
+
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";
|
|
22471
22537
|
return [
|
|
22472
|
-
`More than one conversation in this workspace could be the one being handed off, and
|
|
22538
|
+
`More than one conversation in this workspace could be the one being handed off, and ${why}. Do not guess.`,
|
|
22473
22539
|
"Show the human this list, ask which conversation they are in, then call pantheon_handoff again with that sessionKey:",
|
|
22474
22540
|
...choices.map((choice) => choiceLine(choice, space))
|
|
22475
22541
|
].join("\n");
|
|
22476
22542
|
}
|
|
22543
|
+
function unreadableClientMessage(client, space) {
|
|
22544
|
+
return [
|
|
22545
|
+
`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.`,
|
|
22546
|
+
"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.",
|
|
22547
|
+
"If the human actually meant to archive a chat from a local editor, call pantheon_local_sessions and pass the chosen sessionKey."
|
|
22548
|
+
].join(" ");
|
|
22549
|
+
}
|
|
22477
22550
|
function resolveTranscript(input) {
|
|
22478
22551
|
const supplied = input.transcript ? parseTurns(input.transcript) : [];
|
|
22479
22552
|
if (supplied.length) return { turns: supplied, captured: null };
|
|
@@ -22482,11 +22555,19 @@ function resolveTranscript(input) {
|
|
|
22482
22555
|
"Transcript is empty and capture is disabled. Send the real turns, or drop capture:false to archive this chat from local history."
|
|
22483
22556
|
);
|
|
22484
22557
|
}
|
|
22558
|
+
const client = clientCapture(input.client);
|
|
22485
22559
|
if (!input.sessionKey) {
|
|
22486
|
-
|
|
22560
|
+
if (!client.readable) throw new Error(unreadableClientMessage(input.client, input.space));
|
|
22561
|
+
const choices = ambiguousCapture({ cwd: input.cwd, source: client.source, hint: input.space });
|
|
22487
22562
|
if (choices) throw new Error(chooseSessionMessage(input.space, choices));
|
|
22488
22563
|
}
|
|
22489
|
-
const captured = captureLocalTranscript({
|
|
22564
|
+
const captured = captureLocalTranscript({
|
|
22565
|
+
cwd: input.cwd,
|
|
22566
|
+
// Scoped to the calling app's own log, so a handoff from one editor cannot
|
|
22567
|
+
// reach into another editor's chats.
|
|
22568
|
+
source: input.sessionKey ? void 0 : client.source,
|
|
22569
|
+
sessionKey: input.sessionKey
|
|
22570
|
+
});
|
|
22490
22571
|
if (!captured?.turns.length) {
|
|
22491
22572
|
throw new Error(
|
|
22492
22573
|
"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 +22924,35 @@ function getSession(home, space, sessionId) {
|
|
|
22843
22924
|
const turns = readFileSync3(file, "utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line));
|
|
22844
22925
|
return { sessionId, turns, artifacts: listArtifacts(home, space, sessionId) };
|
|
22845
22926
|
}
|
|
22927
|
+
function forgetSession(home, space, sessionId) {
|
|
22928
|
+
requireSpaceName(space);
|
|
22929
|
+
const slug = slugify(space);
|
|
22930
|
+
const root = spaceDir(home, slug);
|
|
22931
|
+
const id = basename2(sessionId.trim());
|
|
22932
|
+
if (!id || id.startsWith(".")) throw new Error(`Not a session id: "${sessionId}".`);
|
|
22933
|
+
const dir = join3(root, "sessions", id);
|
|
22934
|
+
if (!existsSync3(dir)) {
|
|
22935
|
+
const known = sessionDirs(root).map((session) => session.id);
|
|
22936
|
+
throw new Error(
|
|
22937
|
+
known.length ? `No session "${id}" in "${slug}". Archived sessions: ${known.join(", ")}.` : `No session "${id}" in "${slug}". This space has no archived sessions.`
|
|
22938
|
+
);
|
|
22939
|
+
}
|
|
22940
|
+
const turns = countLines(join3(dir, "transcript.jsonl"));
|
|
22941
|
+
const artifacts = existsSync3(join3(dir, "artifacts")) ? readdirSync3(join3(dir, "artifacts")).length : 0;
|
|
22942
|
+
rmSync2(dir, { recursive: true, force: true });
|
|
22943
|
+
const remaining = sessionDirs(root);
|
|
22944
|
+
return {
|
|
22945
|
+
slug,
|
|
22946
|
+
sessionId: id,
|
|
22947
|
+
turns,
|
|
22948
|
+
artifacts,
|
|
22949
|
+
remainingSessions: remaining.length,
|
|
22950
|
+
remainingTurns: remaining.reduce(
|
|
22951
|
+
(sum, session) => sum + countLines(join3(session.dir, "transcript.jsonl")),
|
|
22952
|
+
0
|
|
22953
|
+
)
|
|
22954
|
+
};
|
|
22955
|
+
}
|
|
22846
22956
|
function listArtifacts(home, space, sessionId) {
|
|
22847
22957
|
const { root } = ensureSpace(home, space);
|
|
22848
22958
|
const dir = join3(root, "sessions", sessionId, "artifacts");
|
|
@@ -22936,6 +23046,8 @@ MCP tools \u2014 always the pantheon_ prefix
|
|
|
22936
23046
|
pantheon_get_turns fetch a turn range
|
|
22937
23047
|
pantheon_get_session fetch a stored transcript
|
|
22938
23048
|
pantheon_get_artifact fetch a stored file
|
|
23049
|
+
pantheon_forget_session delete one archived chat, when capture read the
|
|
23050
|
+
wrong one. Not undoable \u2014 confirm the id first.
|
|
22939
23051
|
|
|
22940
23052
|
Chat shortcuts (namespaced \u2014 use these, not /resume)
|
|
22941
23053
|
/pantheon-handoff <space>
|
|
@@ -23310,11 +23422,13 @@ ${GUIDE}` }]
|
|
|
23310
23422
|
registerTool(
|
|
23311
23423
|
server,
|
|
23312
23424
|
"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.
|
|
23425
|
+
`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
23426
|
{
|
|
23315
23427
|
space: external_exports.string(),
|
|
23316
23428
|
source: external_exports.string().optional(),
|
|
23317
|
-
transcript: external_exports.union([external_exports.array(turnSchema), external_exports.string()]).optional().describe(
|
|
23429
|
+
transcript: external_exports.union([external_exports.array(turnSchema), external_exports.string()]).optional().describe(
|
|
23430
|
+
"Omit this in Cursor, Codex and Claude Code. Required everywhere else. An array of turn objects \u2014 not a JSON string of one."
|
|
23431
|
+
),
|
|
23318
23432
|
summary: external_exports.string().optional().describe("Short orientation for the next agent. The full transcript is stored separately."),
|
|
23319
23433
|
facts: external_exports.array(external_exports.string()).optional(),
|
|
23320
23434
|
artifacts: external_exports.array(artifactSchema).optional(),
|
|
@@ -23328,7 +23442,11 @@ ${GUIDE}` }]
|
|
|
23328
23442
|
const request = input;
|
|
23329
23443
|
const written = writeHandoff(home, {
|
|
23330
23444
|
...request,
|
|
23331
|
-
capture: allowCapture ? request.capture : false
|
|
23445
|
+
capture: allowCapture ? request.capture : false,
|
|
23446
|
+
// Which app is on the other end of this stdio pipe. Running locally
|
|
23447
|
+
// is not the same as keeping chats where Pantheon can read them, and
|
|
23448
|
+
// capture needs to tell those apart before it reads anything.
|
|
23449
|
+
client: server.server.getClientVersion()?.name
|
|
23332
23450
|
});
|
|
23333
23451
|
const sync2 = await vault.push(home, `handoff ${written.slug}`);
|
|
23334
23452
|
return {
|
|
@@ -23450,6 +23568,25 @@ ${GUIDE}` }]
|
|
|
23450
23568
|
},
|
|
23451
23569
|
async ({ space, session_id, name }) => safe(() => getArtifact(home, space, session_id, name))
|
|
23452
23570
|
);
|
|
23571
|
+
registerTool(
|
|
23572
|
+
server,
|
|
23573
|
+
"pantheon_forget_session",
|
|
23574
|
+
"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.",
|
|
23575
|
+
{
|
|
23576
|
+
space: external_exports.string(),
|
|
23577
|
+
session_id: external_exports.string().describe("Exactly as listed in the resume packet.")
|
|
23578
|
+
},
|
|
23579
|
+
async ({ space, session_id }) => safe(async () => {
|
|
23580
|
+
const removed = forgetSession(home, space, session_id);
|
|
23581
|
+
const sync2 = await vault.push(home, `forget session ${removed.sessionId}`);
|
|
23582
|
+
return {
|
|
23583
|
+
ok: sync2.ok !== false,
|
|
23584
|
+
...removed,
|
|
23585
|
+
sync: sync2,
|
|
23586
|
+
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.`
|
|
23587
|
+
};
|
|
23588
|
+
})
|
|
23589
|
+
);
|
|
23453
23590
|
registerTool(
|
|
23454
23591
|
server,
|
|
23455
23592
|
"pantheon_get_skill",
|
|
@@ -23534,11 +23671,12 @@ async function startMcpServer(home = defaultHome()) {
|
|
|
23534
23671
|
}
|
|
23535
23672
|
|
|
23536
23673
|
// src/bootstrap.ts
|
|
23537
|
-
import { hostname as
|
|
23674
|
+
import { hostname as hostname3 } from "node:os";
|
|
23538
23675
|
|
|
23539
23676
|
// src/connect.ts
|
|
23540
23677
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
23541
23678
|
import { existsSync as existsSync7, mkdirSync as mkdirSync6, renameSync } from "node:fs";
|
|
23679
|
+
import { hostname as hostname2 } from "node:os";
|
|
23542
23680
|
import { join as join7 } from "node:path";
|
|
23543
23681
|
|
|
23544
23682
|
// src/mcp-install.ts
|
|
@@ -23936,7 +24074,10 @@ async function connect(opts) {
|
|
|
23936
24074
|
const res = await fetch(`${host}/api/cli/pair`, {
|
|
23937
24075
|
method: "POST",
|
|
23938
24076
|
headers: { "content-type": "application/json" },
|
|
23939
|
-
|
|
24077
|
+
// The name is what the dashboard lists, and it is also the key the
|
|
24078
|
+
// server de-duplicates on: pairing this machine again replaces its own
|
|
24079
|
+
// row instead of adding another anonymous one.
|
|
24080
|
+
body: JSON.stringify({ code, name: hostname2() })
|
|
23940
24081
|
});
|
|
23941
24082
|
const payload = await res.json();
|
|
23942
24083
|
if (res.ok) {
|
|
@@ -24071,7 +24212,7 @@ async function bootstrapFromToken(token, opts = {}) {
|
|
|
24071
24212
|
"content-type": "application/json",
|
|
24072
24213
|
authorization: `Bearer ${token}`
|
|
24073
24214
|
},
|
|
24074
|
-
body: JSON.stringify({ name:
|
|
24215
|
+
body: JSON.stringify({ name: hostname3() })
|
|
24075
24216
|
});
|
|
24076
24217
|
const payload = await res.json();
|
|
24077
24218
|
if (res.ok) {
|
package/package.json
CHANGED