pantheon-cli 0.2.9 → 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.
- package/dist/pantheon.mjs +165 -14
- 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
|
-
|
|
21969
|
-
|
|
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 ||
|
|
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:
|
|
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
|
-
|
|
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({
|
|
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>
|
|
@@ -23275,7 +23356,7 @@ ${GUIDE}` }]
|
|
|
23275
23356
|
registerTool(
|
|
23276
23357
|
server,
|
|
23277
23358
|
"pantheon_resume",
|
|
23278
|
-
"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.",
|
|
23359
|
+
"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. 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.",
|
|
23279
23360
|
{ space: external_exports.string().optional() },
|
|
23280
23361
|
async ({ space }) => safe(async () => {
|
|
23281
23362
|
const sync2 = await vault.pull(home);
|
|
@@ -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.
|
|
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(
|
|
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
|
|
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
|
|
@@ -23703,6 +23810,47 @@ Grounding: the only space list is the \`pantheon_list_spaces\` tool result. Neve
|
|
|
23703
23810
|
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.
|
|
23704
23811
|
|
|
23705
23812
|
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 file you generated (PDFs, letters, CVs) as base64 artifacts \u2014 not just code fences. On resume, fetch listed artifacts with \`pantheon_get_artifact\`. Handoff commits and pushes; resume pulls. Do not run \`pantheon sync\` or \`pantheon handoff\` in a shell.
|
|
23813
|
+
|
|
23814
|
+
## Reporting a result
|
|
23815
|
+
|
|
23816
|
+
Report \`pantheon_handoff\` as this table and nothing else. No prose summary of
|
|
23817
|
+
what was archived, no list of artifact names, no restating the summary you just
|
|
23818
|
+
wrote. The tool result is long; the human wants the receipt.
|
|
23819
|
+
|
|
23820
|
+
| | |
|
|
23821
|
+
|---|---|
|
|
23822
|
+
| Space | the slug |
|
|
23823
|
+
| Session | the session id |
|
|
23824
|
+
| Captured from | source, e.g. cursor |
|
|
23825
|
+
| Turns added | added |
|
|
23826
|
+
| Already archived | alreadyArchived |
|
|
23827
|
+
| Total turns | turns |
|
|
23828
|
+
| Artifacts | count, not names |
|
|
23829
|
+
| Skill candidates | titles, or "none" |
|
|
23830
|
+
| Committed / Pulled / Pushed | yes/no each |
|
|
23831
|
+
|
|
23832
|
+
Two things go outside that table, because they are not receipts: if \`sync\`
|
|
23833
|
+
reports a failure, say what broke and what it means; and if \`skillCandidates\`
|
|
23834
|
+
is non-empty, ask whether to write a skill for each one, since that decision is
|
|
23835
|
+
the human's and the tool result alone will not prompt them.
|
|
23836
|
+
|
|
23837
|
+
Report \`pantheon_resume\` as this table, and then keep going.
|
|
23838
|
+
|
|
23839
|
+
| | |
|
|
23840
|
+
|---|---|
|
|
23841
|
+
| Space | the slug |
|
|
23842
|
+
| Sessions | count, with total turns |
|
|
23843
|
+
| Earlier handoffs | length of story |
|
|
23844
|
+
| Memory | fact count |
|
|
23845
|
+
| Artifacts | count |
|
|
23846
|
+
| Skills | N live, M awaiting review |
|
|
23847
|
+
| Pulled | yes/no |
|
|
23848
|
+
|
|
23849
|
+
After the table, in prose: where the work actually stood, in two or three
|
|
23850
|
+
sentences drawn from the packet; any open threads; and the available skills by
|
|
23851
|
+
name and trigger. The table only proves the load worked. It says nothing about
|
|
23852
|
+
where the work was, which is the part the human asked for, so never fold that
|
|
23853
|
+
into cells.
|
|
23706
23854
|
`;
|
|
23707
23855
|
for (const dir of dirs2) {
|
|
23708
23856
|
mkdirSync5(dir, { recursive: true });
|
|
@@ -23895,7 +24043,10 @@ async function connect(opts) {
|
|
|
23895
24043
|
const res = await fetch(`${host}/api/cli/pair`, {
|
|
23896
24044
|
method: "POST",
|
|
23897
24045
|
headers: { "content-type": "application/json" },
|
|
23898
|
-
|
|
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() })
|
|
23899
24050
|
});
|
|
23900
24051
|
const payload = await res.json();
|
|
23901
24052
|
if (res.ok) {
|
|
@@ -24030,7 +24181,7 @@ async function bootstrapFromToken(token, opts = {}) {
|
|
|
24030
24181
|
"content-type": "application/json",
|
|
24031
24182
|
authorization: `Bearer ${token}`
|
|
24032
24183
|
},
|
|
24033
|
-
body: JSON.stringify({ name:
|
|
24184
|
+
body: JSON.stringify({ name: hostname3() })
|
|
24034
24185
|
});
|
|
24035
24186
|
const payload = await res.json();
|
|
24036
24187
|
if (res.ok) {
|
package/package.json
CHANGED