pantheon-cli 0.2.1 → 0.2.3
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 +733 -244
- package/package.json +3 -3
package/dist/pantheon.mjs
CHANGED
|
@@ -3640,7 +3640,7 @@ var require_fast_uri = __commonJS({
|
|
|
3640
3640
|
normalizeString(uri, options);
|
|
3641
3641
|
} else if (typeof uri === "object") {
|
|
3642
3642
|
uri = /** @type {T} */
|
|
3643
|
-
parse3(
|
|
3643
|
+
parse3(serialize2(uri, options), options);
|
|
3644
3644
|
}
|
|
3645
3645
|
return uri;
|
|
3646
3646
|
}
|
|
@@ -3653,51 +3653,51 @@ var require_fast_uri = __commonJS({
|
|
|
3653
3653
|
}
|
|
3654
3654
|
const resolved = resolveComponent(baseParsed, relativeParsed, schemelessOptions, true);
|
|
3655
3655
|
schemelessOptions.skipEscape = true;
|
|
3656
|
-
return
|
|
3656
|
+
return serialize2(resolved, schemelessOptions);
|
|
3657
3657
|
}
|
|
3658
|
-
function resolveComponent(base,
|
|
3658
|
+
function resolveComponent(base, relative2, options, skipNormalization) {
|
|
3659
3659
|
const target = {};
|
|
3660
3660
|
if (!skipNormalization) {
|
|
3661
|
-
base = parse3(
|
|
3662
|
-
|
|
3661
|
+
base = parse3(serialize2(base, options), options);
|
|
3662
|
+
relative2 = parse3(serialize2(relative2, options), options);
|
|
3663
3663
|
}
|
|
3664
3664
|
options = options || {};
|
|
3665
|
-
if (!options.tolerant &&
|
|
3666
|
-
target.scheme =
|
|
3667
|
-
target.userinfo =
|
|
3668
|
-
target.host =
|
|
3669
|
-
target.port =
|
|
3670
|
-
target.path = removeDotSegments(
|
|
3671
|
-
target.query =
|
|
3665
|
+
if (!options.tolerant && relative2.scheme) {
|
|
3666
|
+
target.scheme = relative2.scheme;
|
|
3667
|
+
target.userinfo = relative2.userinfo;
|
|
3668
|
+
target.host = relative2.host;
|
|
3669
|
+
target.port = relative2.port;
|
|
3670
|
+
target.path = removeDotSegments(relative2.path || "");
|
|
3671
|
+
target.query = relative2.query;
|
|
3672
3672
|
} else {
|
|
3673
|
-
if (
|
|
3674
|
-
target.userinfo =
|
|
3675
|
-
target.host =
|
|
3676
|
-
target.port =
|
|
3677
|
-
target.path = removeDotSegments(
|
|
3678
|
-
target.query =
|
|
3673
|
+
if (relative2.userinfo !== void 0 || relative2.host !== void 0 || relative2.port !== void 0) {
|
|
3674
|
+
target.userinfo = relative2.userinfo;
|
|
3675
|
+
target.host = relative2.host;
|
|
3676
|
+
target.port = relative2.port;
|
|
3677
|
+
target.path = removeDotSegments(relative2.path || "");
|
|
3678
|
+
target.query = relative2.query;
|
|
3679
3679
|
} else {
|
|
3680
|
-
if (!
|
|
3680
|
+
if (!relative2.path) {
|
|
3681
3681
|
target.path = base.path;
|
|
3682
|
-
if (
|
|
3683
|
-
target.query =
|
|
3682
|
+
if (relative2.query !== void 0) {
|
|
3683
|
+
target.query = relative2.query;
|
|
3684
3684
|
} else {
|
|
3685
3685
|
target.query = base.query;
|
|
3686
3686
|
}
|
|
3687
3687
|
} else {
|
|
3688
|
-
if (
|
|
3689
|
-
target.path = removeDotSegments(
|
|
3688
|
+
if (relative2.path[0] === "/") {
|
|
3689
|
+
target.path = removeDotSegments(relative2.path);
|
|
3690
3690
|
} else {
|
|
3691
3691
|
if ((base.userinfo !== void 0 || base.host !== void 0 || base.port !== void 0) && !base.path) {
|
|
3692
|
-
target.path = "/" +
|
|
3692
|
+
target.path = "/" + relative2.path;
|
|
3693
3693
|
} else if (!base.path) {
|
|
3694
|
-
target.path =
|
|
3694
|
+
target.path = relative2.path;
|
|
3695
3695
|
} else {
|
|
3696
|
-
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) +
|
|
3696
|
+
target.path = base.path.slice(0, base.path.lastIndexOf("/") + 1) + relative2.path;
|
|
3697
3697
|
}
|
|
3698
3698
|
target.path = removeDotSegments(target.path);
|
|
3699
3699
|
}
|
|
3700
|
-
target.query =
|
|
3700
|
+
target.query = relative2.query;
|
|
3701
3701
|
}
|
|
3702
3702
|
target.userinfo = base.userinfo;
|
|
3703
3703
|
target.host = base.host;
|
|
@@ -3705,7 +3705,7 @@ var require_fast_uri = __commonJS({
|
|
|
3705
3705
|
}
|
|
3706
3706
|
target.scheme = base.scheme;
|
|
3707
3707
|
}
|
|
3708
|
-
target.fragment =
|
|
3708
|
+
target.fragment = relative2.fragment;
|
|
3709
3709
|
return target;
|
|
3710
3710
|
}
|
|
3711
3711
|
function equal(uriA, uriB, options) {
|
|
@@ -3713,7 +3713,7 @@ var require_fast_uri = __commonJS({
|
|
|
3713
3713
|
const normalizedB = normalizeComparableURI(uriB, options);
|
|
3714
3714
|
return normalizedA !== void 0 && normalizedB !== void 0 && normalizedA.toLowerCase() === normalizedB.toLowerCase();
|
|
3715
3715
|
}
|
|
3716
|
-
function
|
|
3716
|
+
function serialize2(cmpts, opts) {
|
|
3717
3717
|
const component = {
|
|
3718
3718
|
host: cmpts.host,
|
|
3719
3719
|
scheme: cmpts.scheme,
|
|
@@ -3912,7 +3912,7 @@ var require_fast_uri = __commonJS({
|
|
|
3912
3912
|
function normalizeStringWithStatus(uri, opts) {
|
|
3913
3913
|
const { parsed, malformedAuthorityOrPort } = parseWithStatus(uri, opts);
|
|
3914
3914
|
return {
|
|
3915
|
-
normalized: malformedAuthorityOrPort ? uri :
|
|
3915
|
+
normalized: malformedAuthorityOrPort ? uri : serialize2(parsed, opts),
|
|
3916
3916
|
malformedAuthorityOrPort
|
|
3917
3917
|
};
|
|
3918
3918
|
}
|
|
@@ -3922,7 +3922,7 @@ var require_fast_uri = __commonJS({
|
|
|
3922
3922
|
return malformedAuthorityOrPort ? void 0 : normalized;
|
|
3923
3923
|
}
|
|
3924
3924
|
if (typeof uri === "object") {
|
|
3925
|
-
return
|
|
3925
|
+
return serialize2(uri, opts);
|
|
3926
3926
|
}
|
|
3927
3927
|
}
|
|
3928
3928
|
var fastUri = {
|
|
@@ -3931,7 +3931,7 @@ var require_fast_uri = __commonJS({
|
|
|
3931
3931
|
resolve: resolve2,
|
|
3932
3932
|
resolveComponent,
|
|
3933
3933
|
equal,
|
|
3934
|
-
serialize,
|
|
3934
|
+
serialize: serialize2,
|
|
3935
3935
|
parse: parse3
|
|
3936
3936
|
};
|
|
3937
3937
|
module.exports = fastUri;
|
|
@@ -21263,16 +21263,16 @@ var MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
|
|
|
21263
21263
|
|
|
21264
21264
|
// ../core/src/spaces.ts
|
|
21265
21265
|
import {
|
|
21266
|
-
existsSync as
|
|
21267
|
-
mkdirSync,
|
|
21268
|
-
readFileSync as
|
|
21269
|
-
readdirSync as
|
|
21266
|
+
existsSync as existsSync3,
|
|
21267
|
+
mkdirSync as mkdirSync2,
|
|
21268
|
+
readFileSync as readFileSync3,
|
|
21269
|
+
readdirSync as readdirSync3,
|
|
21270
21270
|
statSync as statSync2,
|
|
21271
|
-
writeFileSync,
|
|
21271
|
+
writeFileSync as writeFileSync2,
|
|
21272
21272
|
appendFileSync
|
|
21273
21273
|
} from "node:fs";
|
|
21274
21274
|
import { homedir as homedir2 } from "node:os";
|
|
21275
|
-
import { basename as basename2, join as
|
|
21275
|
+
import { basename as basename2, isAbsolute, join as join3, relative, resolve } from "node:path";
|
|
21276
21276
|
|
|
21277
21277
|
// ../core/src/transcripts.ts
|
|
21278
21278
|
import { closeSync, existsSync, openSync, readFileSync, readSync, readdirSync, statSync } from "node:fs";
|
|
@@ -21319,12 +21319,12 @@ function files(path) {
|
|
|
21319
21319
|
return [];
|
|
21320
21320
|
}
|
|
21321
21321
|
}
|
|
21322
|
-
function
|
|
21323
|
-
return
|
|
21322
|
+
function projectKey(value) {
|
|
21323
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
21324
21324
|
}
|
|
21325
21325
|
function sameWorkspace(a, b) {
|
|
21326
21326
|
if (!a || !b) return false;
|
|
21327
|
-
const norm = (value) => value.replace(/\/+$/, "").toLowerCase();
|
|
21327
|
+
const norm = (value) => value.replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase();
|
|
21328
21328
|
return norm(a) === norm(b);
|
|
21329
21329
|
}
|
|
21330
21330
|
function textOf(value) {
|
|
@@ -21345,8 +21345,8 @@ function cursorRoot() {
|
|
|
21345
21345
|
function cursorSessions(cwd) {
|
|
21346
21346
|
const root = cursorRoot();
|
|
21347
21347
|
if (!existsSync(root)) return [];
|
|
21348
|
-
const wanted = cwd ?
|
|
21349
|
-
const projects = dirs(root).filter((name) => wanted ? name === wanted : true);
|
|
21348
|
+
const wanted = cwd ? projectKey(cwd) : "";
|
|
21349
|
+
const projects = dirs(root).filter((name) => wanted ? projectKey(name) === wanted : true);
|
|
21350
21350
|
const found = [];
|
|
21351
21351
|
for (const project of projects) {
|
|
21352
21352
|
const base = join(root, project, "agent-transcripts");
|
|
@@ -21357,7 +21357,7 @@ function cursorSessions(cwd) {
|
|
|
21357
21357
|
source: "cursor",
|
|
21358
21358
|
key: `cursor-${id}`,
|
|
21359
21359
|
path,
|
|
21360
|
-
cwd: project === wanted ? cwd : void 0,
|
|
21360
|
+
cwd: wanted && projectKey(project) === wanted ? cwd : void 0,
|
|
21361
21361
|
updatedAt: iso(mtime(path))
|
|
21362
21362
|
});
|
|
21363
21363
|
}
|
|
@@ -21517,11 +21517,10 @@ function claudeRoot() {
|
|
|
21517
21517
|
function claudeSessions(cwd) {
|
|
21518
21518
|
const root = claudeRoot();
|
|
21519
21519
|
if (!existsSync(root)) return [];
|
|
21520
|
-
const wanted = cwd ?
|
|
21520
|
+
const wanted = cwd ? projectKey(cwd) : "";
|
|
21521
21521
|
const found = [];
|
|
21522
21522
|
for (const project of dirs(root)) {
|
|
21523
|
-
|
|
21524
|
-
if (wanted && normalized !== wanted) continue;
|
|
21523
|
+
if (wanted && projectKey(project) !== wanted) continue;
|
|
21525
21524
|
for (const name of files(join(root, project))) {
|
|
21526
21525
|
if (!name.endsWith(".jsonl")) continue;
|
|
21527
21526
|
const path = join(root, project, name);
|
|
@@ -21609,14 +21608,33 @@ function tail(path, bytes = HINT_TAIL_BYTES) {
|
|
|
21609
21608
|
return "";
|
|
21610
21609
|
}
|
|
21611
21610
|
}
|
|
21612
|
-
function
|
|
21613
|
-
const
|
|
21614
|
-
|
|
21615
|
-
|
|
21616
|
-
|
|
21611
|
+
function describe(session, mentionsHint) {
|
|
21612
|
+
const turns = readLocalSession(session);
|
|
21613
|
+
const spoken = [...turns].reverse().find((turn) => turn.role === "user" && turn.text.trim());
|
|
21614
|
+
return {
|
|
21615
|
+
key: session.key,
|
|
21616
|
+
source: session.source,
|
|
21617
|
+
turns: turns.length,
|
|
21618
|
+
updatedAt: session.updatedAt,
|
|
21619
|
+
lastMessage: spoken ? spoken.text.replace(/\s+/g, " ").trim().slice(0, 140) : null,
|
|
21620
|
+
mentionsHint
|
|
21621
|
+
};
|
|
21622
|
+
}
|
|
21623
|
+
function ambiguousCapture(opts = {}) {
|
|
21624
|
+
const needle = opts.hint?.trim().toLowerCase();
|
|
21625
|
+
if (!needle || needle.length < 3) return null;
|
|
21626
|
+
const cwd = opts.cwd || process.cwd();
|
|
21627
|
+
const scoped = discoverLocalSessions({ cwd, source: opts.source });
|
|
21628
|
+
const candidates = (scoped.length ? scoped : discoverLocalSessions({ source: opts.source })).slice(
|
|
21629
|
+
0,
|
|
21630
|
+
MAX_SCAN
|
|
21617
21631
|
);
|
|
21618
|
-
if (
|
|
21619
|
-
|
|
21632
|
+
if (candidates.length < 2) return null;
|
|
21633
|
+
const [newest, ...rest2] = candidates;
|
|
21634
|
+
if (tail(newest.path).toLowerCase().includes(needle)) return null;
|
|
21635
|
+
const named = rest2.filter((session) => tail(session.path).toLowerCase().includes(needle));
|
|
21636
|
+
if (!named.length) return null;
|
|
21637
|
+
return [...named.slice(0, 3).map((s) => describe(s, true)), describe(newest, false)];
|
|
21620
21638
|
}
|
|
21621
21639
|
function captureLocalTranscript(opts = {}) {
|
|
21622
21640
|
const { sessionKey, minTurns = 2 } = opts;
|
|
@@ -21624,10 +21642,7 @@ function captureLocalTranscript(opts = {}) {
|
|
|
21624
21642
|
const scoped = discoverLocalSessions({ cwd, source: opts.source });
|
|
21625
21643
|
const candidates = sessionKey ? discoverLocalSessions({ source: opts.source }).filter(
|
|
21626
21644
|
(item) => item.key === sessionKey || item.key.endsWith(sessionKey)
|
|
21627
|
-
) :
|
|
21628
|
-
scoped.length ? scoped : discoverLocalSessions({ source: opts.source }),
|
|
21629
|
-
opts.hint
|
|
21630
|
-
);
|
|
21645
|
+
) : scoped.length ? scoped : discoverLocalSessions({ source: opts.source });
|
|
21631
21646
|
for (const session of candidates.slice(0, MAX_SCAN)) {
|
|
21632
21647
|
const turns = readLocalSession(session);
|
|
21633
21648
|
if (turns.length >= minTurns) return { session, turns };
|
|
@@ -21635,9 +21650,282 @@ function captureLocalTranscript(opts = {}) {
|
|
|
21635
21650
|
return null;
|
|
21636
21651
|
}
|
|
21637
21652
|
|
|
21653
|
+
// ../core/src/skills.ts
|
|
21654
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, readdirSync as readdirSync2, rmSync, writeFileSync } from "node:fs";
|
|
21655
|
+
import { join as join2 } from "node:path";
|
|
21656
|
+
var SKILL_DIR = "skills";
|
|
21657
|
+
var DRAFT_DIR = "draft";
|
|
21658
|
+
var MAX_LIVE_SKILLS = 12;
|
|
21659
|
+
function skillsDir(root, status = "live") {
|
|
21660
|
+
return status === "live" ? join2(root, SKILL_DIR) : join2(root, SKILL_DIR, DRAFT_DIR);
|
|
21661
|
+
}
|
|
21662
|
+
function skillName(value) {
|
|
21663
|
+
const name = value.toLowerCase().trim().replace(/\.md$/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64);
|
|
21664
|
+
return name || "skill";
|
|
21665
|
+
}
|
|
21666
|
+
function parseFrontmatter(raw) {
|
|
21667
|
+
const match = raw.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
21668
|
+
if (!match) return { fields: {}, body: raw.trim() };
|
|
21669
|
+
const fields = {};
|
|
21670
|
+
for (const line of match[1].split("\n")) {
|
|
21671
|
+
const pair = line.match(/^([a-z_]+):\s*(.*)$/i);
|
|
21672
|
+
if (pair) fields[pair[1].toLowerCase()] = pair[2].trim();
|
|
21673
|
+
}
|
|
21674
|
+
return { fields, body: match[2].trim() };
|
|
21675
|
+
}
|
|
21676
|
+
function serialize(skill) {
|
|
21677
|
+
const head = [
|
|
21678
|
+
"---",
|
|
21679
|
+
`name: ${skill.name}`,
|
|
21680
|
+
`description: ${skill.when.replace(/\n/g, " ")}`,
|
|
21681
|
+
skill.key ? `key: ${skill.key}` : null,
|
|
21682
|
+
`sessions: ${skill.sessions}`,
|
|
21683
|
+
`updated_at: ${(/* @__PURE__ */ new Date()).toISOString()}`,
|
|
21684
|
+
"---",
|
|
21685
|
+
""
|
|
21686
|
+
].filter((line) => line !== null);
|
|
21687
|
+
return `${head.join("\n")}
|
|
21688
|
+
${skill.body.trim()}
|
|
21689
|
+
`;
|
|
21690
|
+
}
|
|
21691
|
+
function readSkillFile(dir, file, status) {
|
|
21692
|
+
const raw = (() => {
|
|
21693
|
+
try {
|
|
21694
|
+
return readFileSync2(join2(dir, file), "utf8");
|
|
21695
|
+
} catch {
|
|
21696
|
+
return "";
|
|
21697
|
+
}
|
|
21698
|
+
})();
|
|
21699
|
+
if (!raw.trim()) return null;
|
|
21700
|
+
const { fields, body } = parseFrontmatter(raw);
|
|
21701
|
+
const name = fields.name || file.replace(/\.md$/, "");
|
|
21702
|
+
return {
|
|
21703
|
+
name,
|
|
21704
|
+
when: fields.description || `Guidance recorded as ${name}.`,
|
|
21705
|
+
sessions: Number(fields.sessions) || 0,
|
|
21706
|
+
key: fields.key,
|
|
21707
|
+
updatedAt: fields.updated_at,
|
|
21708
|
+
status,
|
|
21709
|
+
body
|
|
21710
|
+
};
|
|
21711
|
+
}
|
|
21712
|
+
function listSkills(root, status = "live") {
|
|
21713
|
+
const dir = skillsDir(root, status);
|
|
21714
|
+
if (!existsSync2(dir)) return [];
|
|
21715
|
+
return readdirSync2(dir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".md")).map((entry) => readSkillFile(dir, entry.name, status)).filter((skill) => skill !== null).sort((a, b) => b.sessions - a.sessions || a.name.localeCompare(b.name));
|
|
21716
|
+
}
|
|
21717
|
+
function skillRefs(root) {
|
|
21718
|
+
return listSkills(root, "live").slice(0, MAX_LIVE_SKILLS).map((skill) => ({ name: skill.name, when: skill.when, sessions: skill.sessions }));
|
|
21719
|
+
}
|
|
21720
|
+
function readSkill(root, name) {
|
|
21721
|
+
const file = `${skillName(name)}.md`;
|
|
21722
|
+
for (const status of ["live", "draft"]) {
|
|
21723
|
+
const dir = skillsDir(root, status);
|
|
21724
|
+
if (!existsSync2(join2(dir, file))) continue;
|
|
21725
|
+
const skill = readSkillFile(dir, file, status);
|
|
21726
|
+
if (skill) return skill;
|
|
21727
|
+
}
|
|
21728
|
+
throw new Error(
|
|
21729
|
+
`No skill named "${name}" in this space. Resume lists the ones that exist; do not guess a name.`
|
|
21730
|
+
);
|
|
21731
|
+
}
|
|
21732
|
+
function saveSkill(root, input, status = "draft") {
|
|
21733
|
+
const name = skillName(input.name);
|
|
21734
|
+
if (!input.body.trim()) throw new Error("A skill needs a body. Write the guidance, not a title.");
|
|
21735
|
+
if (!input.when.trim()) {
|
|
21736
|
+
throw new Error(
|
|
21737
|
+
"A skill needs a description saying when to use it. That line is all an agent sees before deciding to open it."
|
|
21738
|
+
);
|
|
21739
|
+
}
|
|
21740
|
+
const dir = skillsDir(root, status);
|
|
21741
|
+
mkdirSync(dir, { recursive: true });
|
|
21742
|
+
writeFileSync(
|
|
21743
|
+
join2(dir, `${name}.md`),
|
|
21744
|
+
serialize({
|
|
21745
|
+
name,
|
|
21746
|
+
when: input.when.trim(),
|
|
21747
|
+
body: input.body,
|
|
21748
|
+
key: input.key,
|
|
21749
|
+
sessions: input.sessions ?? 0
|
|
21750
|
+
})
|
|
21751
|
+
);
|
|
21752
|
+
return { name, status };
|
|
21753
|
+
}
|
|
21754
|
+
var SHELL_TOOL = /(shell|bash|terminal|command|run_|exec)/i;
|
|
21755
|
+
var MULTIPLEXER = /* @__PURE__ */ new Set([
|
|
21756
|
+
"git",
|
|
21757
|
+
"npm",
|
|
21758
|
+
"pnpm",
|
|
21759
|
+
"yarn",
|
|
21760
|
+
"npx",
|
|
21761
|
+
"docker",
|
|
21762
|
+
"cargo",
|
|
21763
|
+
"gh",
|
|
21764
|
+
"supabase",
|
|
21765
|
+
"vercel",
|
|
21766
|
+
"python",
|
|
21767
|
+
"python3",
|
|
21768
|
+
"node",
|
|
21769
|
+
"go",
|
|
21770
|
+
"kubectl",
|
|
21771
|
+
"brew",
|
|
21772
|
+
"pip",
|
|
21773
|
+
"pip3"
|
|
21774
|
+
]);
|
|
21775
|
+
var NOISE = /* @__PURE__ */ new Set(["cd", "ls", "cat", "echo", "pwd", "which", "true", "false", "clear"]);
|
|
21776
|
+
var ERROR_LINE = /^.*?\b(?:error|fatal|failed|failure|cannot|could not|not found|denied|refused|unsupported|invalid|ERR_[A-Z_]+|Traceback|panic)\b.*$/im;
|
|
21777
|
+
function errorLine(output) {
|
|
21778
|
+
if (!output) return null;
|
|
21779
|
+
const text2 = output.slice(0, 4e3);
|
|
21780
|
+
if (/\b(0 errors|no errors|error: 0|warning)\b/i.test(text2) && !/\berror\b:/i.test(text2)) {
|
|
21781
|
+
return null;
|
|
21782
|
+
}
|
|
21783
|
+
const hit = text2.match(ERROR_LINE)?.[0];
|
|
21784
|
+
if (!hit) return null;
|
|
21785
|
+
const line = hit.replace(/\s+/g, " ").trim();
|
|
21786
|
+
return line.length > 6 ? line.slice(0, 200) : null;
|
|
21787
|
+
}
|
|
21788
|
+
function errorKey(line) {
|
|
21789
|
+
return line.toLowerCase().replace(/(?:[a-z]:)?[\\/][\w.\\/-]+/g, " ").replace(/0x[0-9a-f]+|\b\d+\b/g, " ").replace(/["'`].*?["'`]/g, " ").replace(/[^a-z_ ]+/g, " ").replace(/\s+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
|
|
21790
|
+
}
|
|
21791
|
+
function commandText(input) {
|
|
21792
|
+
if (typeof input === "string") return input;
|
|
21793
|
+
if (!input || typeof input !== "object") return "";
|
|
21794
|
+
const record2 = input;
|
|
21795
|
+
for (const key of ["command", "cmd", "script", "input", "text"]) {
|
|
21796
|
+
const value = record2[key];
|
|
21797
|
+
if (typeof value === "string" && value.trim()) return value;
|
|
21798
|
+
}
|
|
21799
|
+
return "";
|
|
21800
|
+
}
|
|
21801
|
+
function commandHead(command) {
|
|
21802
|
+
const words = command.replace(/^[\s(]*/, "").split(/\s+/).filter(Boolean);
|
|
21803
|
+
let index = 0;
|
|
21804
|
+
while (index < words.length && (/^[A-Z_][A-Z0-9_]*=/.test(words[index]) || words[index] === "sudo")) {
|
|
21805
|
+
index += 1;
|
|
21806
|
+
}
|
|
21807
|
+
const head = (words[index] || "").replace(/^.*[\\/]/, "").toLowerCase();
|
|
21808
|
+
if (!head || NOISE.has(head)) return null;
|
|
21809
|
+
if (!MULTIPLEXER.has(head)) return head;
|
|
21810
|
+
const sub = (words[index + 1] || "").toLowerCase();
|
|
21811
|
+
return /^[a-z][a-z0-9-]*$/.test(sub) ? `${head} ${sub}` : head;
|
|
21812
|
+
}
|
|
21813
|
+
var LOOKAHEAD = 8;
|
|
21814
|
+
var MAX_FRICTION = 24;
|
|
21815
|
+
function extractFrictions(turns) {
|
|
21816
|
+
const calls = [];
|
|
21817
|
+
for (const turn of turns) {
|
|
21818
|
+
for (const call of turn.toolCalls || []) {
|
|
21819
|
+
const command = SHELL_TOOL.test(call.name) ? commandText(call.input) : "";
|
|
21820
|
+
const head = command ? commandHead(command) : call.name.toLowerCase();
|
|
21821
|
+
if (!head) continue;
|
|
21822
|
+
calls.push({
|
|
21823
|
+
name: call.name,
|
|
21824
|
+
command: command.replace(/\s+/g, " ").trim().slice(0, 200) || call.name,
|
|
21825
|
+
head,
|
|
21826
|
+
output: call.output,
|
|
21827
|
+
turnId: turn.id
|
|
21828
|
+
});
|
|
21829
|
+
}
|
|
21830
|
+
}
|
|
21831
|
+
const out = [];
|
|
21832
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21833
|
+
for (let index = 0; index < calls.length && out.length < MAX_FRICTION; index += 1) {
|
|
21834
|
+
const call = calls[index];
|
|
21835
|
+
const error2 = errorLine(call.output);
|
|
21836
|
+
if (!error2) continue;
|
|
21837
|
+
const later = calls.slice(index + 1, index + 1 + LOOKAHEAD);
|
|
21838
|
+
const resolved = later.some((next) => next.head === call.head && !errorLine(next.output));
|
|
21839
|
+
if (!resolved) continue;
|
|
21840
|
+
const key = `${call.head}::${errorKey(error2)}`;
|
|
21841
|
+
if (!key.endsWith("::") && !seen.has(key)) {
|
|
21842
|
+
seen.add(key);
|
|
21843
|
+
out.push({ key, command: call.command, head: call.head, error: error2, turnId: call.turnId, resolved });
|
|
21844
|
+
}
|
|
21845
|
+
}
|
|
21846
|
+
return out;
|
|
21847
|
+
}
|
|
21848
|
+
var MIN_SESSIONS = 2;
|
|
21849
|
+
function titleFor(head, error2) {
|
|
21850
|
+
const subject = error2.replace(/^[^a-z]*/i, "").replace(/\s+/g, " ").trim().slice(0, 70);
|
|
21851
|
+
return `${head}: ${subject}`;
|
|
21852
|
+
}
|
|
21853
|
+
function documented(docs, error2) {
|
|
21854
|
+
if (!docs) return false;
|
|
21855
|
+
const haystack = docs.toLowerCase();
|
|
21856
|
+
const words = error2.toLowerCase().split(/[^a-z_]+/).filter((word) => word.length >= 7);
|
|
21857
|
+
if (!words.length) return false;
|
|
21858
|
+
const hits = words.filter((word) => haystack.includes(word)).length;
|
|
21859
|
+
return hits / words.length > 0.6;
|
|
21860
|
+
}
|
|
21861
|
+
function detectCandidates(sessions, options = {}) {
|
|
21862
|
+
const known = options.known ?? /* @__PURE__ */ new Set();
|
|
21863
|
+
const docs = options.docs ?? "";
|
|
21864
|
+
const groups = /* @__PURE__ */ new Map();
|
|
21865
|
+
for (const session of sessions) {
|
|
21866
|
+
for (const friction of extractFrictions(session.turns)) {
|
|
21867
|
+
if (known.has(friction.key)) continue;
|
|
21868
|
+
const group = groups.get(friction.key) ?? {
|
|
21869
|
+
evidence: [],
|
|
21870
|
+
sessions: /* @__PURE__ */ new Set(),
|
|
21871
|
+
head: friction.head,
|
|
21872
|
+
error: friction.error
|
|
21873
|
+
};
|
|
21874
|
+
group.sessions.add(session.id);
|
|
21875
|
+
group.evidence.push({
|
|
21876
|
+
sessionId: session.id,
|
|
21877
|
+
turnId: friction.turnId,
|
|
21878
|
+
command: friction.command,
|
|
21879
|
+
error: friction.error
|
|
21880
|
+
});
|
|
21881
|
+
groups.set(friction.key, group);
|
|
21882
|
+
}
|
|
21883
|
+
}
|
|
21884
|
+
const out = [];
|
|
21885
|
+
for (const [key, group] of groups) {
|
|
21886
|
+
if (group.sessions.size < MIN_SESSIONS) continue;
|
|
21887
|
+
if (documented(docs, group.error)) continue;
|
|
21888
|
+
const count = group.sessions.size;
|
|
21889
|
+
out.push({
|
|
21890
|
+
key,
|
|
21891
|
+
suggestedName: skillName(`${group.head}-${errorKey(group.error).split("-").slice(0, 3).join("-")}`),
|
|
21892
|
+
title: titleFor(group.head, group.error),
|
|
21893
|
+
why: `\`${group.head}\` failed this way in ${count} separate conversations and was worked through each time. Nothing in the repo's own docs covers it.`,
|
|
21894
|
+
sessions: [...group.sessions],
|
|
21895
|
+
evidence: group.evidence.slice(0, 6)
|
|
21896
|
+
});
|
|
21897
|
+
}
|
|
21898
|
+
return out.sort((a, b) => b.sessions.length - a.sessions.length || b.evidence.length - a.evidence.length).slice(0, options.limit ?? 3);
|
|
21899
|
+
}
|
|
21900
|
+
function knownSkillKeys(root) {
|
|
21901
|
+
const keys = /* @__PURE__ */ new Set();
|
|
21902
|
+
for (const status of ["live", "draft"]) {
|
|
21903
|
+
for (const skill of listSkills(root, status)) {
|
|
21904
|
+
if (skill.key) keys.add(skill.key);
|
|
21905
|
+
}
|
|
21906
|
+
}
|
|
21907
|
+
for (const key of readDismissed(root)) keys.add(key);
|
|
21908
|
+
return keys;
|
|
21909
|
+
}
|
|
21910
|
+
var DISMISSED = "dismissed.txt";
|
|
21911
|
+
function readDismissed(root) {
|
|
21912
|
+
const file = join2(skillsDir(root, "live"), DISMISSED);
|
|
21913
|
+
if (!existsSync2(file)) return [];
|
|
21914
|
+
return readFileSync2(file, "utf8").split("\n").map((line) => line.trim()).filter(Boolean);
|
|
21915
|
+
}
|
|
21916
|
+
function dismissCandidate(root, key) {
|
|
21917
|
+
const dir = skillsDir(root, "live");
|
|
21918
|
+
mkdirSync(dir, { recursive: true });
|
|
21919
|
+
const existing = new Set(readDismissed(root));
|
|
21920
|
+
existing.add(key.trim());
|
|
21921
|
+
writeFileSync(join2(dir, DISMISSED), `${[...existing].join("\n")}
|
|
21922
|
+
`);
|
|
21923
|
+
return { key };
|
|
21924
|
+
}
|
|
21925
|
+
|
|
21638
21926
|
// ../core/src/spaces.ts
|
|
21639
21927
|
function defaultHome() {
|
|
21640
|
-
return process.env.PANTHEON_HOME ||
|
|
21928
|
+
return process.env.PANTHEON_HOME || join3(homedir2(), "pantheon");
|
|
21641
21929
|
}
|
|
21642
21930
|
function missingSpaceName(value) {
|
|
21643
21931
|
const space = (value || "").trim();
|
|
@@ -21662,7 +21950,7 @@ function slugify(value) {
|
|
|
21662
21950
|
return slug || "space";
|
|
21663
21951
|
}
|
|
21664
21952
|
function spaceDir(home, slug) {
|
|
21665
|
-
return
|
|
21953
|
+
return join3(resolve(home), "spaces", slugify(slug));
|
|
21666
21954
|
}
|
|
21667
21955
|
function nowIso() {
|
|
21668
21956
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -21671,10 +21959,10 @@ function stamp() {
|
|
|
21671
21959
|
return nowIso().replace(/[:.]/g, "-");
|
|
21672
21960
|
}
|
|
21673
21961
|
function ensureDir(path) {
|
|
21674
|
-
|
|
21962
|
+
mkdirSync2(path, { recursive: true });
|
|
21675
21963
|
}
|
|
21676
21964
|
function readText(path) {
|
|
21677
|
-
return
|
|
21965
|
+
return existsSync3(path) ? readFileSync3(path, "utf8") : "";
|
|
21678
21966
|
}
|
|
21679
21967
|
function parseTurns(transcript) {
|
|
21680
21968
|
if (Array.isArray(transcript)) {
|
|
@@ -21763,9 +22051,9 @@ function mentionedDocuments(turns) {
|
|
|
21763
22051
|
}
|
|
21764
22052
|
function searchRoots() {
|
|
21765
22053
|
return [
|
|
21766
|
-
|
|
21767
|
-
|
|
21768
|
-
|
|
22054
|
+
join3(homedir2(), "Downloads"),
|
|
22055
|
+
join3(homedir2(), "Desktop"),
|
|
22056
|
+
join3(homedir2(), "Documents"),
|
|
21769
22057
|
"/mnt/user-data/outputs",
|
|
21770
22058
|
"/mnt/user-data/uploads",
|
|
21771
22059
|
process.cwd()
|
|
@@ -21774,17 +22062,17 @@ function searchRoots() {
|
|
|
21774
22062
|
function collectDiskArtifacts(turns) {
|
|
21775
22063
|
const found = [];
|
|
21776
22064
|
for (const doc of mentionedDocuments(turns)) {
|
|
21777
|
-
const candidates = [doc.path, ...searchRoots().map((root) =>
|
|
22065
|
+
const candidates = [doc.path, ...searchRoots().map((root) => join3(root, doc.name))].filter(
|
|
21778
22066
|
(path) => Boolean(path)
|
|
21779
22067
|
);
|
|
21780
22068
|
for (const path of candidates) {
|
|
21781
22069
|
try {
|
|
21782
|
-
if (!
|
|
22070
|
+
if (!existsSync3(path)) continue;
|
|
21783
22071
|
const stat = statSync2(path);
|
|
21784
22072
|
if (!stat.isFile() || stat.size === 0 || stat.size > MAX_DISK_ARTIFACT) continue;
|
|
21785
22073
|
found.push({
|
|
21786
22074
|
name: doc.name,
|
|
21787
|
-
content:
|
|
22075
|
+
content: readFileSync3(path).toString("base64"),
|
|
21788
22076
|
encoding: "base64"
|
|
21789
22077
|
});
|
|
21790
22078
|
break;
|
|
@@ -21814,10 +22102,54 @@ function pathsFromPatch(input) {
|
|
|
21814
22102
|
}
|
|
21815
22103
|
return found;
|
|
21816
22104
|
}
|
|
21817
|
-
var
|
|
21818
|
-
|
|
21819
|
-
|
|
22105
|
+
var slash = (path) => path.replace(/\\/g, "/");
|
|
22106
|
+
function toFull(path, from) {
|
|
22107
|
+
const expanded = /^~[\\/]/.test(path) ? join3(homedir2(), path.slice(2)) : path;
|
|
22108
|
+
return slash(isAbsolute(expanded) ? resolve(expanded) : resolve(from, expanded));
|
|
22109
|
+
}
|
|
22110
|
+
function inside(base, full) {
|
|
22111
|
+
const rel = relative(base, full);
|
|
22112
|
+
return Boolean(rel) && !rel.startsWith("..") && !isAbsolute(rel);
|
|
22113
|
+
}
|
|
22114
|
+
var SKIP_PATH = /(^|\/)(node_modules|\.git|\.next|coverage|\.turbo)(\/|$)|\.(lock|log|db|sqlite3?|map)$|lock\.(json|yaml)$/;
|
|
22115
|
+
var BUILD_DIR = /(^|\/)(dist|build|out)(\/|$)/;
|
|
22116
|
+
var DELIVERABLE = /\.(png|jpe?g|gif|webp|avif|svg|mp4|mov|webm|mp3|wav|pdf|csv|xlsx?|docx?|pptx?|zip)$/i;
|
|
22117
|
+
var SECRET_PATH = /(^|\/)(\.env(\.[\w-]+)*|\.npmrc|\.netrc|\.pgpass|id_(rsa|dsa|ecdsa|ed25519)|(credentials|secrets?)(\.[\w-]+)?)$|\.(pem|key|p12|pfx|keystore|jks)$/i;
|
|
22118
|
+
var MAX_WRITTEN_FILE = 8 * 1024 * 1024;
|
|
22119
|
+
var MAX_WRITTEN_TOTAL = 24 * 1024 * 1024;
|
|
21820
22120
|
var MAX_WRITTEN_COUNT = 200;
|
|
22121
|
+
var MAX_SKIP_REPORT = 12;
|
|
22122
|
+
function pathsFromText(text2) {
|
|
22123
|
+
const found = [];
|
|
22124
|
+
const cleaned = text2.replace(/\b[a-z][a-z0-9+.-]*:\/\/\S+/gi, " ");
|
|
22125
|
+
for (const raw of cleaned.split(/[\s'"`;|&$(){}[\],]+/)) {
|
|
22126
|
+
const token = raw.replace(/^[-=@]+/, "").replace(/[.,:;]+$/, "");
|
|
22127
|
+
if (!token || token.length > 200) continue;
|
|
22128
|
+
if (!/^([a-zA-Z]:)?[\w./\\@~+-]+$/.test(token)) continue;
|
|
22129
|
+
if (!/\.[a-zA-Z][a-zA-Z0-9]{0,7}$/.test(token)) continue;
|
|
22130
|
+
found.push(token);
|
|
22131
|
+
}
|
|
22132
|
+
return found;
|
|
22133
|
+
}
|
|
22134
|
+
function inputText(input) {
|
|
22135
|
+
if (typeof input === "string") return input;
|
|
22136
|
+
if (!input || typeof input !== "object") return "";
|
|
22137
|
+
try {
|
|
22138
|
+
return JSON.stringify(input);
|
|
22139
|
+
} catch {
|
|
22140
|
+
return "";
|
|
22141
|
+
}
|
|
22142
|
+
}
|
|
22143
|
+
var CWD_KEYS = ["working_directory", "workdir", "work_dir", "cwd", "directory"];
|
|
22144
|
+
function callBase(input, base) {
|
|
22145
|
+
const record2 = input && typeof input === "object" ? input : null;
|
|
22146
|
+
const declared = record2 ? CWD_KEYS.map((key) => record2[key]).find(
|
|
22147
|
+
(value) => typeof value === "string" && value.trim().length > 0
|
|
22148
|
+
) : void 0;
|
|
22149
|
+
const walked = inputText(input).match(/(?:^|[\s"'`;&|])cd\s+(([a-zA-Z]:)?[\w./\\@~-]+)\s*(?:&&|;)/);
|
|
22150
|
+
const dir = declared?.trim() || walked?.[1];
|
|
22151
|
+
return dir ? toFull(dir, base) : base;
|
|
22152
|
+
}
|
|
21821
22153
|
function pathFromInput(input) {
|
|
21822
22154
|
if (!input || typeof input !== "object") return null;
|
|
21823
22155
|
const record2 = input;
|
|
@@ -21828,13 +22160,13 @@ function pathFromInput(input) {
|
|
|
21828
22160
|
return null;
|
|
21829
22161
|
}
|
|
21830
22162
|
function flatName(path, base) {
|
|
21831
|
-
const
|
|
21832
|
-
return
|
|
22163
|
+
const rel = inside(base, path) ? relative(base, path) : path;
|
|
22164
|
+
return slash(rel).replace(/^[a-zA-Z]:/, "").replace(/^[./]+/, "").replace(/[^a-zA-Z0-9._/-]/g, "_").replace(/\//g, "_");
|
|
21833
22165
|
}
|
|
21834
22166
|
function readArtifactFile(path, base) {
|
|
21835
22167
|
const stat = statSync2(path);
|
|
21836
22168
|
if (!stat.isFile() || stat.size === 0 || stat.size > MAX_WRITTEN_FILE) return null;
|
|
21837
|
-
const buf =
|
|
22169
|
+
const buf = readFileSync3(path);
|
|
21838
22170
|
const binary = buf.includes(0);
|
|
21839
22171
|
return {
|
|
21840
22172
|
name: flatName(path, base),
|
|
@@ -21843,44 +22175,85 @@ function readArtifactFile(path, base) {
|
|
|
21843
22175
|
bytes: stat.size
|
|
21844
22176
|
};
|
|
21845
22177
|
}
|
|
21846
|
-
function collectWrittenArtifacts(turns, cwd = process.cwd()) {
|
|
21847
|
-
const base = cwd
|
|
21848
|
-
const
|
|
21849
|
-
const
|
|
21850
|
-
|
|
21851
|
-
|
|
22178
|
+
function collectWrittenArtifacts(turns, cwd = process.cwd(), opts = {}) {
|
|
22179
|
+
const base = slash(resolve(cwd));
|
|
22180
|
+
const since = opts.since ?? null;
|
|
22181
|
+
const vault = opts.home ? slash(resolve(opts.home)) : null;
|
|
22182
|
+
const written = /* @__PURE__ */ new Set();
|
|
22183
|
+
const touched = /* @__PURE__ */ new Set();
|
|
22184
|
+
const add = (into, path, from = base) => {
|
|
22185
|
+
const full = toFull(path, from);
|
|
22186
|
+
if (SKIP_PATH.test(full) || SECRET_PATH.test(full)) return;
|
|
22187
|
+
if (BUILD_DIR.test(full) && !DELIVERABLE.test(full)) return;
|
|
22188
|
+
if (vault && inside(vault, full)) return;
|
|
22189
|
+
if (into === touched && !inside(base, full)) return;
|
|
22190
|
+
into.add(full);
|
|
21852
22191
|
};
|
|
21853
22192
|
for (const turn of turns) {
|
|
21854
22193
|
for (const call of turn.toolCalls ?? []) {
|
|
21855
|
-
if (
|
|
21856
|
-
|
|
21857
|
-
|
|
21858
|
-
|
|
22194
|
+
if (WRITE_TOOL.test(call.name || "")) {
|
|
22195
|
+
const path = pathFromInput(call.input);
|
|
22196
|
+
if (path) add(written, path);
|
|
22197
|
+
for (const patched of pathsFromPatch(call.input)) add(written, patched);
|
|
22198
|
+
continue;
|
|
22199
|
+
}
|
|
22200
|
+
if (since === null) continue;
|
|
22201
|
+
const from = callBase(call.input, base);
|
|
22202
|
+
for (const named of pathsFromText(inputText(call.input))) add(touched, named, from);
|
|
21859
22203
|
}
|
|
21860
22204
|
}
|
|
21861
22205
|
const found = [];
|
|
22206
|
+
const skipped = [];
|
|
21862
22207
|
let total = 0;
|
|
21863
|
-
|
|
21864
|
-
if (
|
|
22208
|
+
const note = (path, reason) => {
|
|
22209
|
+
if (skipped.length < MAX_SKIP_REPORT) skipped.push({ name: flatName(path, base), reason });
|
|
22210
|
+
};
|
|
22211
|
+
const store = (path, gate) => {
|
|
22212
|
+
if (!existsSync3(path)) return;
|
|
22213
|
+
const stat = statSync2(path);
|
|
22214
|
+
if (!stat.isFile() || stat.size === 0) return;
|
|
22215
|
+
if (gate && since !== null && stat.mtimeMs < since) return;
|
|
22216
|
+
if (stat.size > MAX_WRITTEN_FILE) {
|
|
22217
|
+
note(
|
|
22218
|
+
path,
|
|
22219
|
+
`${Math.round(stat.size / 1024)}KB, over the ${MAX_WRITTEN_FILE / 1024 / 1024}MB per-file limit`
|
|
22220
|
+
);
|
|
22221
|
+
return;
|
|
22222
|
+
}
|
|
22223
|
+
if (found.length >= MAX_WRITTEN_COUNT || total + stat.size > MAX_WRITTEN_TOTAL) {
|
|
22224
|
+
note(path, "this handoff's artifact budget was full");
|
|
22225
|
+
return;
|
|
22226
|
+
}
|
|
22227
|
+
const file = readArtifactFile(path, base);
|
|
22228
|
+
if (!file) return;
|
|
22229
|
+
total += file.bytes;
|
|
22230
|
+
found.push({ name: file.name, content: file.content, encoding: file.encoding });
|
|
22231
|
+
};
|
|
22232
|
+
for (const path of written) {
|
|
21865
22233
|
try {
|
|
21866
|
-
|
|
21867
|
-
const file = readArtifactFile(path, base);
|
|
21868
|
-
if (!file) continue;
|
|
21869
|
-
total += file.bytes;
|
|
21870
|
-
found.push({ name: file.name, content: file.content, encoding: file.encoding });
|
|
22234
|
+
store(path, false);
|
|
21871
22235
|
} catch {
|
|
21872
22236
|
}
|
|
21873
22237
|
}
|
|
21874
|
-
|
|
22238
|
+
for (const path of touched) {
|
|
22239
|
+
if (written.has(path)) continue;
|
|
22240
|
+
try {
|
|
22241
|
+
store(path, true);
|
|
22242
|
+
} catch {
|
|
22243
|
+
}
|
|
22244
|
+
}
|
|
22245
|
+
return { artifacts: found, skipped };
|
|
21875
22246
|
}
|
|
21876
22247
|
function collectAttachedArtifacts(turns, cwd = process.cwd()) {
|
|
21877
|
-
const base = cwd
|
|
22248
|
+
const base = slash(resolve(cwd));
|
|
21878
22249
|
const paths = /* @__PURE__ */ new Set();
|
|
21879
22250
|
for (const turn of turns) {
|
|
21880
22251
|
if (turn.role !== "user") continue;
|
|
21881
|
-
for (const match of (turn.text || "").matchAll(
|
|
21882
|
-
|
|
21883
|
-
|
|
22252
|
+
for (const match of (turn.text || "").matchAll(
|
|
22253
|
+
/(?:^|[\s"'`(@])((?:[a-zA-Z]:[\\/]|\/)[\w.\\/@ -]*[\\/][\w.@-]+\.[a-zA-Z0-9]{1,16})/g
|
|
22254
|
+
)) {
|
|
22255
|
+
const full = slash(match[1].trim());
|
|
22256
|
+
if (!SKIP_PATH.test(full) && !SECRET_PATH.test(full)) paths.add(full);
|
|
21884
22257
|
}
|
|
21885
22258
|
}
|
|
21886
22259
|
const found = [];
|
|
@@ -21888,7 +22261,7 @@ function collectAttachedArtifacts(turns, cwd = process.cwd()) {
|
|
|
21888
22261
|
for (const path of paths) {
|
|
21889
22262
|
if (found.length >= 40 || total >= MAX_WRITTEN_TOTAL) break;
|
|
21890
22263
|
try {
|
|
21891
|
-
if (!
|
|
22264
|
+
if (!existsSync3(path)) continue;
|
|
21892
22265
|
const file = readArtifactFile(path, base);
|
|
21893
22266
|
if (!file) continue;
|
|
21894
22267
|
total += file.bytes;
|
|
@@ -21965,28 +22338,39 @@ function distill(input) {
|
|
|
21965
22338
|
function ensureSpace(home, name) {
|
|
21966
22339
|
const slug = slugify(name);
|
|
21967
22340
|
const root = spaceDir(home, slug);
|
|
21968
|
-
ensureDir(
|
|
21969
|
-
ensureDir(
|
|
21970
|
-
ensureDir(
|
|
21971
|
-
const metaPath =
|
|
21972
|
-
if (!
|
|
21973
|
-
|
|
22341
|
+
ensureDir(join3(root, "sessions"));
|
|
22342
|
+
ensureDir(join3(root, "handoffs"));
|
|
22343
|
+
ensureDir(join3(root, "artifacts"));
|
|
22344
|
+
const metaPath = join3(root, "space.yaml");
|
|
22345
|
+
if (!existsSync3(metaPath)) {
|
|
22346
|
+
writeFileSync2(
|
|
21974
22347
|
metaPath,
|
|
21975
22348
|
[`id: ${slug}`, `title: ${name}`, `created_at: ${nowIso()}`, ""].join("\n")
|
|
21976
22349
|
);
|
|
21977
22350
|
}
|
|
21978
|
-
if (!
|
|
21979
|
-
if (!
|
|
22351
|
+
if (!existsSync3(join3(root, "handoff.md"))) writeFileSync2(join3(root, "handoff.md"), "");
|
|
22352
|
+
if (!existsSync3(join3(root, "memory.md"))) writeFileSync2(join3(root, "memory.md"), "");
|
|
22353
|
+
return { slug, root };
|
|
22354
|
+
}
|
|
22355
|
+
function resolveSpace(home, name) {
|
|
22356
|
+
requireSpaceName(name);
|
|
22357
|
+
const slug = slugify(name);
|
|
22358
|
+
const root = spaceDir(home, slug);
|
|
22359
|
+
if (!existsSync3(root)) {
|
|
22360
|
+
throw new Error(
|
|
22361
|
+
`"${name}" is not a space in this vault. Call pantheon_list_spaces and use one of those names. Do not invent a substitute.`
|
|
22362
|
+
);
|
|
22363
|
+
}
|
|
21980
22364
|
return { slug, root };
|
|
21981
22365
|
}
|
|
21982
22366
|
function writeArtifacts(sessionDir, artifacts = []) {
|
|
21983
22367
|
const names = [];
|
|
21984
|
-
const dir =
|
|
22368
|
+
const dir = join3(sessionDir, "artifacts");
|
|
21985
22369
|
ensureDir(dir);
|
|
21986
22370
|
for (const artifact of artifacts) {
|
|
21987
22371
|
const safe2 = basename2(artifact.name).replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
21988
22372
|
const buf = artifact.encoding === "base64" ? Buffer.from(artifact.content, "base64") : Buffer.from(artifact.content, "utf8");
|
|
21989
|
-
|
|
22373
|
+
writeFileSync2(join3(dir, safe2), buf);
|
|
21990
22374
|
names.push(safe2);
|
|
21991
22375
|
}
|
|
21992
22376
|
return names;
|
|
@@ -21995,7 +22379,7 @@ function sanitizeSessionId(value) {
|
|
|
21995
22379
|
return value.replace(/[^a-zA-Z0-9._-]/g, "-").slice(0, 120) || "session";
|
|
21996
22380
|
}
|
|
21997
22381
|
function readSessionTurns(sessionDir) {
|
|
21998
|
-
const raw = readText(
|
|
22382
|
+
const raw = readText(join3(sessionDir, "transcript.jsonl"));
|
|
21999
22383
|
if (!raw.trim()) return [];
|
|
22000
22384
|
const turns = [];
|
|
22001
22385
|
for (const line of raw.split("\n")) {
|
|
@@ -22027,16 +22411,16 @@ function writeSession(root, source, turns, artifacts, sessionId) {
|
|
|
22027
22411
|
const id = sanitizeSessionId(
|
|
22028
22412
|
sessionId || `${(source || "session").replace(/[^a-z0-9-]/gi, "").toLowerCase() || "session"}-${stamp()}`
|
|
22029
22413
|
);
|
|
22030
|
-
const sessionDir =
|
|
22414
|
+
const sessionDir = join3(root, "sessions", id);
|
|
22031
22415
|
ensureDir(sessionDir);
|
|
22032
22416
|
const existing = readSessionTurns(sessionDir);
|
|
22033
22417
|
const { merged, added } = mergeTurns(existing, turns);
|
|
22034
22418
|
const lines = merged.map((turn) => JSON.stringify(turn));
|
|
22035
|
-
|
|
22419
|
+
writeFileSync2(join3(sessionDir, "transcript.jsonl"), `${lines.join("\n")}
|
|
22036
22420
|
`);
|
|
22037
|
-
const created = readText(
|
|
22038
|
-
|
|
22039
|
-
|
|
22421
|
+
const created = readText(join3(sessionDir, "meta.yaml")).match(/^created_at: (.+)$/m)?.[1];
|
|
22422
|
+
writeFileSync2(
|
|
22423
|
+
join3(sessionDir, "meta.yaml"),
|
|
22040
22424
|
[
|
|
22041
22425
|
`id: ${id}`,
|
|
22042
22426
|
`source: ${source || "unknown"}`,
|
|
@@ -22078,6 +22462,18 @@ function transcriptLooksThin(turns) {
|
|
|
22078
22462
|
}
|
|
22079
22463
|
return null;
|
|
22080
22464
|
}
|
|
22465
|
+
function choiceLine(choice, space) {
|
|
22466
|
+
const why = choice.mentionsHint ? `mentions "${space}"` : "most recently written";
|
|
22467
|
+
const last = choice.lastMessage ? ` \xB7 last human message: "${choice.lastMessage}"` : "";
|
|
22468
|
+
return `- sessionKey: ${choice.key} \u2014 ${choice.turns} turns, ${why}${last}`;
|
|
22469
|
+
}
|
|
22470
|
+
function chooseSessionMessage(space, choices) {
|
|
22471
|
+
return [
|
|
22472
|
+
`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.`,
|
|
22473
|
+
"Show the human this list, ask which conversation they are in, then call pantheon_handoff again with that sessionKey:",
|
|
22474
|
+
...choices.map((choice) => choiceLine(choice, space))
|
|
22475
|
+
].join("\n");
|
|
22476
|
+
}
|
|
22081
22477
|
function resolveTranscript(input) {
|
|
22082
22478
|
const supplied = input.transcript ? parseTurns(input.transcript) : [];
|
|
22083
22479
|
if (supplied.length) return { turns: supplied, captured: null };
|
|
@@ -22086,11 +22482,11 @@ function resolveTranscript(input) {
|
|
|
22086
22482
|
"Transcript is empty and capture is disabled. Send the real turns, or drop capture:false to archive this chat from local history."
|
|
22087
22483
|
);
|
|
22088
22484
|
}
|
|
22089
|
-
|
|
22090
|
-
cwd: input.cwd,
|
|
22091
|
-
|
|
22092
|
-
|
|
22093
|
-
});
|
|
22485
|
+
if (!input.sessionKey) {
|
|
22486
|
+
const choices = ambiguousCapture({ cwd: input.cwd, hint: input.space });
|
|
22487
|
+
if (choices) throw new Error(chooseSessionMessage(input.space, choices));
|
|
22488
|
+
}
|
|
22489
|
+
const captured = captureLocalTranscript({ cwd: input.cwd, sessionKey: input.sessionKey });
|
|
22094
22490
|
if (!captured?.turns.length) {
|
|
22095
22491
|
throw new Error(
|
|
22096
22492
|
"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."
|
|
@@ -22102,6 +22498,15 @@ function lastSpoken(turns) {
|
|
|
22102
22498
|
const last = [...turns].reverse().find((turn) => turn.role === "user" && turn.text.trim());
|
|
22103
22499
|
return last ? last.text.replace(/\s+/g, " ").trim().slice(0, 160) : null;
|
|
22104
22500
|
}
|
|
22501
|
+
function sessionStart(path) {
|
|
22502
|
+
try {
|
|
22503
|
+
const stat = statSync2(path);
|
|
22504
|
+
if (stat.birthtimeMs > 0 && stat.birthtimeMs <= stat.mtimeMs) return stat.birthtimeMs;
|
|
22505
|
+
return stat.mtimeMs - 24 * 60 * 60 * 1e3;
|
|
22506
|
+
} catch {
|
|
22507
|
+
return null;
|
|
22508
|
+
}
|
|
22509
|
+
}
|
|
22105
22510
|
function writeHandoff(home, input) {
|
|
22106
22511
|
requireSpaceName(input.space);
|
|
22107
22512
|
const { slug, root } = ensureSpace(home, input.space);
|
|
@@ -22111,11 +22516,12 @@ function writeHandoff(home, input) {
|
|
|
22111
22516
|
if (thin) throw new Error(thin);
|
|
22112
22517
|
}
|
|
22113
22518
|
const cwd = input.cwd || process.cwd();
|
|
22519
|
+
const sweep = captured ? collectWrittenArtifacts(turns, cwd, { since: sessionStart(captured.session.path), home }) : null;
|
|
22114
22520
|
const artifacts = mergeArtifacts(
|
|
22115
22521
|
input.artifacts,
|
|
22116
22522
|
extractFencedArtifacts(turns),
|
|
22117
22523
|
collectDiskArtifacts(turns),
|
|
22118
|
-
|
|
22524
|
+
sweep?.artifacts,
|
|
22119
22525
|
captured ? collectAttachedArtifacts(turns, cwd) : void 0
|
|
22120
22526
|
);
|
|
22121
22527
|
if (!captured) {
|
|
@@ -22134,11 +22540,11 @@ function writeHandoff(home, input) {
|
|
|
22134
22540
|
sessionId: session.sessionId,
|
|
22135
22541
|
sessions: sessionSummaries(root)
|
|
22136
22542
|
});
|
|
22137
|
-
|
|
22138
|
-
|
|
22543
|
+
writeFileSync2(join3(root, "handoff.md"), packet);
|
|
22544
|
+
writeFileSync2(join3(root, "handoffs", `${stamp()}.md`), packet);
|
|
22139
22545
|
if (input.facts?.length) {
|
|
22140
22546
|
const extra = input.facts.map((fact) => `- ${fact.trim()}`).join("\n");
|
|
22141
|
-
appendFileSync(
|
|
22547
|
+
appendFileSync(join3(root, "memory.md"), `${extra}
|
|
22142
22548
|
`);
|
|
22143
22549
|
}
|
|
22144
22550
|
return {
|
|
@@ -22151,6 +22557,12 @@ function writeHandoff(home, input) {
|
|
|
22151
22557
|
// So a human can tell at a glance that the right conversation was read.
|
|
22152
22558
|
lastMessage: lastSpoken(session.turns),
|
|
22153
22559
|
artifacts: session.artifacts,
|
|
22560
|
+
// Files this session made that the archive would not take. Silence here is
|
|
22561
|
+
// how a handoff comes to promise more than it holds.
|
|
22562
|
+
skipped: sweep?.skipped ?? [],
|
|
22563
|
+
// Usually empty. Only a failure that recurred across separate conversations
|
|
22564
|
+
// and is not already documented gets this far.
|
|
22565
|
+
skillCandidates: spaceSkillCandidates(root, cwd),
|
|
22154
22566
|
truncated: Boolean(input.truncated),
|
|
22155
22567
|
append: Boolean(input.append)
|
|
22156
22568
|
};
|
|
@@ -22172,9 +22584,9 @@ function writePark(home, input) {
|
|
|
22172
22584
|
const missing = missingGeneratedFiles(turns, artifacts);
|
|
22173
22585
|
if (missing) throw new Error(missing);
|
|
22174
22586
|
}
|
|
22175
|
-
const session = turns.length ? writeSession(root, input.source, turns, artifacts) : { sessionId: null, artifacts: writeArtifacts(
|
|
22587
|
+
const session = turns.length ? writeSession(root, input.source, turns, artifacts) : { sessionId: null, artifacts: writeArtifacts(join3(root, "sessions", "inbox"), artifacts) };
|
|
22176
22588
|
if (input.note) {
|
|
22177
|
-
appendFileSync(
|
|
22589
|
+
appendFileSync(join3(root, "memory.md"), `- park: ${input.note.trim()}
|
|
22178
22590
|
`);
|
|
22179
22591
|
}
|
|
22180
22592
|
return { slug, sessionId: session.sessionId, turns: turns.length, artifacts: session.artifacts };
|
|
@@ -22182,20 +22594,20 @@ function writePark(home, input) {
|
|
|
22182
22594
|
function writeRemember(home, space, fact) {
|
|
22183
22595
|
requireSpaceName(space);
|
|
22184
22596
|
const { slug, root } = ensureSpace(home, space);
|
|
22185
|
-
appendFileSync(
|
|
22597
|
+
appendFileSync(join3(root, "memory.md"), `- ${fact.trim()}
|
|
22186
22598
|
`);
|
|
22187
22599
|
return { slug };
|
|
22188
22600
|
}
|
|
22189
22601
|
function sessionDirs(root) {
|
|
22190
|
-
const sessions =
|
|
22191
|
-
if (!
|
|
22192
|
-
return
|
|
22193
|
-
const dir =
|
|
22194
|
-
const transcript =
|
|
22602
|
+
const sessions = join3(root, "sessions");
|
|
22603
|
+
if (!existsSync3(sessions)) return [];
|
|
22604
|
+
return readdirSync3(sessions, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== "inbox").map((entry) => {
|
|
22605
|
+
const dir = join3(sessions, entry.name);
|
|
22606
|
+
const transcript = join3(dir, "transcript.jsonl");
|
|
22195
22607
|
return {
|
|
22196
22608
|
id: entry.name,
|
|
22197
22609
|
dir,
|
|
22198
|
-
mtime:
|
|
22610
|
+
mtime: existsSync3(transcript) ? statSync2(transcript).mtimeMs : statSync2(dir).mtimeMs
|
|
22199
22611
|
};
|
|
22200
22612
|
}).sort((a, b) => b.mtime - a.mtime);
|
|
22201
22613
|
}
|
|
@@ -22208,19 +22620,31 @@ function countLines(path) {
|
|
|
22208
22620
|
}
|
|
22209
22621
|
function sessionSummaries(root) {
|
|
22210
22622
|
return sessionDirs(root).map((session) => {
|
|
22211
|
-
const meta = readText(
|
|
22623
|
+
const meta = readText(join3(session.dir, "meta.yaml"));
|
|
22212
22624
|
const source = metaField(meta, "source");
|
|
22213
22625
|
return {
|
|
22214
22626
|
id: session.id,
|
|
22215
22627
|
source: source && source !== "unknown" ? source : void 0,
|
|
22216
22628
|
// meta.yaml is rewritten on every handoff, but a half-written or
|
|
22217
22629
|
// hand-edited archive should still report an honest count.
|
|
22218
|
-
turns: Number(metaField(meta, "turns")) || countLines(
|
|
22630
|
+
turns: Number(metaField(meta, "turns")) || countLines(join3(session.dir, "transcript.jsonl")),
|
|
22219
22631
|
createdAt: metaField(meta, "created_at"),
|
|
22220
22632
|
updatedAt: metaField(meta, "updated_at")
|
|
22221
22633
|
};
|
|
22222
22634
|
});
|
|
22223
22635
|
}
|
|
22636
|
+
var SKILL_SCAN_SESSIONS = 20;
|
|
22637
|
+
function projectDocs(cwd) {
|
|
22638
|
+
return ["AGENTS.md", "README.md", "CONTRIBUTING.md"].map((name) => readText(join3(cwd, name))).join("\n").slice(0, 4e4);
|
|
22639
|
+
}
|
|
22640
|
+
function spaceSkillCandidates(root, cwd) {
|
|
22641
|
+
const sessions = sessionDirs(root).slice(0, SKILL_SCAN_SESSIONS).map((session) => ({ id: session.id, turns: readSessionTurns(session.dir) }));
|
|
22642
|
+
if (sessions.length < 2) return [];
|
|
22643
|
+
return detectCandidates(sessions, {
|
|
22644
|
+
known: knownSkillKeys(root),
|
|
22645
|
+
docs: cwd ? projectDocs(cwd) : ""
|
|
22646
|
+
});
|
|
22647
|
+
}
|
|
22224
22648
|
var STORY_PACKETS = 8;
|
|
22225
22649
|
var STORY_CHARS = 6e3;
|
|
22226
22650
|
function packetBody(markdown) {
|
|
@@ -22231,15 +22655,15 @@ function unstamp(name) {
|
|
|
22231
22655
|
return name.replace(/T(\d{2})-(\d{2})-(\d{2})-(\d{3})Z$/, "T$1:$2:$3.$4Z");
|
|
22232
22656
|
}
|
|
22233
22657
|
function readStory(root) {
|
|
22234
|
-
const dir =
|
|
22235
|
-
if (!
|
|
22236
|
-
const files2 =
|
|
22658
|
+
const dir = join3(root, "handoffs");
|
|
22659
|
+
if (!existsSync3(dir)) return [];
|
|
22660
|
+
const files2 = readdirSync3(dir).filter((name) => name.endsWith(".md")).sort();
|
|
22237
22661
|
const prior = files2.slice(0, -1).slice(-STORY_PACKETS);
|
|
22238
22662
|
const out = [];
|
|
22239
22663
|
let budget = STORY_CHARS;
|
|
22240
22664
|
for (const name of [...prior].reverse()) {
|
|
22241
22665
|
if (budget <= 0) break;
|
|
22242
|
-
const packet = packetBody(readText(
|
|
22666
|
+
const packet = packetBody(readText(join3(dir, name)));
|
|
22243
22667
|
if (!packet) continue;
|
|
22244
22668
|
out.push({ at: unstamp(name.replace(/\.md$/, "")), packet: packet.slice(0, budget) });
|
|
22245
22669
|
budget -= packet.length;
|
|
@@ -22249,9 +22673,9 @@ function readStory(root) {
|
|
|
22249
22673
|
function listSpaceArtifacts(root) {
|
|
22250
22674
|
const out = [];
|
|
22251
22675
|
for (const session of sessionDirs(root)) {
|
|
22252
|
-
const dir =
|
|
22253
|
-
if (!
|
|
22254
|
-
for (const name of
|
|
22676
|
+
const dir = join3(session.dir, "artifacts");
|
|
22677
|
+
if (!existsSync3(dir)) continue;
|
|
22678
|
+
for (const name of readdirSync3(dir)) {
|
|
22255
22679
|
if (name.startsWith(".")) continue;
|
|
22256
22680
|
out.push({ sessionId: session.id, name });
|
|
22257
22681
|
if (out.length >= 50) return out;
|
|
@@ -22259,7 +22683,7 @@ function listSpaceArtifacts(root) {
|
|
|
22259
22683
|
}
|
|
22260
22684
|
return out;
|
|
22261
22685
|
}
|
|
22262
|
-
function resumeNote(sessions, turns, story) {
|
|
22686
|
+
function resumeNote(sessions, turns, story, skills) {
|
|
22263
22687
|
if (!sessions.length) {
|
|
22264
22688
|
return "Nothing archived in this space yet. Ask the human what they were working on rather than guessing.";
|
|
22265
22689
|
}
|
|
@@ -22277,6 +22701,11 @@ function resumeNote(sessions, turns, story) {
|
|
|
22277
22701
|
parts.push(
|
|
22278
22702
|
'Before telling the human you lack context, run pantheon_search (query: "<topic>", context: 2) \u2014 it searches tool calls as well as messages, across every session.'
|
|
22279
22703
|
);
|
|
22704
|
+
if (skills.length) {
|
|
22705
|
+
parts.push(
|
|
22706
|
+
`This space has ${skills.length} skill${skills.length === 1 ? "" : "s"} \u2014 guidance written from failures that already happened here. Before working in an area one of them covers, read it with pantheon_get_skill. Following it is cheaper than rediscovering why it exists.`
|
|
22707
|
+
);
|
|
22708
|
+
}
|
|
22280
22709
|
return parts.join(" ");
|
|
22281
22710
|
}
|
|
22282
22711
|
function readResume(home, space) {
|
|
@@ -22285,16 +22714,19 @@ function readResume(home, space) {
|
|
|
22285
22714
|
const sessions = sessionSummaries(root);
|
|
22286
22715
|
const turns = sessions.reduce((sum, session) => sum + session.turns, 0);
|
|
22287
22716
|
const story = readStory(root);
|
|
22717
|
+
const skills = skillRefs(root);
|
|
22288
22718
|
return {
|
|
22289
22719
|
space: slug,
|
|
22290
|
-
handoff: readText(
|
|
22291
|
-
memory: readText(
|
|
22720
|
+
handoff: readText(join3(root, "handoff.md")).trim() || "(empty handoff)",
|
|
22721
|
+
memory: readText(join3(root, "memory.md")).trim() || "(no durable memory yet)",
|
|
22292
22722
|
sessionId: sessions[0]?.id ?? null,
|
|
22293
22723
|
sessions,
|
|
22294
22724
|
turns,
|
|
22295
22725
|
story,
|
|
22296
22726
|
artifacts: listSpaceArtifacts(root),
|
|
22297
|
-
|
|
22727
|
+
skills,
|
|
22728
|
+
pendingSkills: listSkills(root, "draft").length,
|
|
22729
|
+
note: resumeNote(sessions, turns, story.length, skills)
|
|
22298
22730
|
};
|
|
22299
22731
|
}
|
|
22300
22732
|
function packetPreview(markdown) {
|
|
@@ -22302,20 +22734,20 @@ function packetPreview(markdown) {
|
|
|
22302
22734
|
return packet.replace(/^#.+\n/gm, "").replace(/\s+/g, " ").trim().slice(0, 220);
|
|
22303
22735
|
}
|
|
22304
22736
|
function spaceTitle(root, slug) {
|
|
22305
|
-
const meta = readText(
|
|
22737
|
+
const meta = readText(join3(root, "space.yaml"));
|
|
22306
22738
|
return meta.match(/^title:\s*(.+)$/m)?.[1]?.trim() || slug;
|
|
22307
22739
|
}
|
|
22308
22740
|
function listSpaces(home) {
|
|
22309
|
-
const root =
|
|
22310
|
-
if (!
|
|
22311
|
-
return
|
|
22312
|
-
const dir =
|
|
22313
|
-
const handoff =
|
|
22741
|
+
const root = join3(resolve(home), "spaces");
|
|
22742
|
+
if (!existsSync3(root)) return [];
|
|
22743
|
+
return readdirSync3(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => {
|
|
22744
|
+
const dir = join3(root, entry.name);
|
|
22745
|
+
const handoff = join3(dir, "handoff.md");
|
|
22314
22746
|
const body = readText(handoff);
|
|
22315
22747
|
return {
|
|
22316
22748
|
slug: entry.name,
|
|
22317
22749
|
title: spaceTitle(dir, entry.name),
|
|
22318
|
-
updatedAt:
|
|
22750
|
+
updatedAt: existsSync3(handoff) ? statSync2(handoff).mtime.toISOString() : void 0,
|
|
22319
22751
|
preview: body ? packetPreview(body) : void 0
|
|
22320
22752
|
};
|
|
22321
22753
|
}).sort((a, b) => (b.updatedAt || "").localeCompare(a.updatedAt || ""));
|
|
@@ -22394,22 +22826,22 @@ function getTurns(home, space, sessionId, from, to) {
|
|
|
22394
22826
|
}
|
|
22395
22827
|
function getSession(home, space, sessionId) {
|
|
22396
22828
|
const { root } = ensureSpace(home, space);
|
|
22397
|
-
const file =
|
|
22398
|
-
if (!
|
|
22399
|
-
const turns =
|
|
22829
|
+
const file = join3(root, "sessions", sessionId, "transcript.jsonl");
|
|
22830
|
+
if (!existsSync3(file)) throw new Error(`Session not found: ${sessionId}`);
|
|
22831
|
+
const turns = readFileSync3(file, "utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line));
|
|
22400
22832
|
return { sessionId, turns, artifacts: listArtifacts(home, space, sessionId) };
|
|
22401
22833
|
}
|
|
22402
22834
|
function listArtifacts(home, space, sessionId) {
|
|
22403
22835
|
const { root } = ensureSpace(home, space);
|
|
22404
|
-
const dir =
|
|
22405
|
-
if (!
|
|
22406
|
-
return
|
|
22836
|
+
const dir = join3(root, "sessions", sessionId, "artifacts");
|
|
22837
|
+
if (!existsSync3(dir)) return [];
|
|
22838
|
+
return readdirSync3(dir);
|
|
22407
22839
|
}
|
|
22408
22840
|
function getArtifact(home, space, sessionId, name) {
|
|
22409
22841
|
const { root } = ensureSpace(home, space);
|
|
22410
|
-
const file =
|
|
22411
|
-
if (!
|
|
22412
|
-
const buf =
|
|
22842
|
+
const file = join3(root, "sessions", sessionId, "artifacts", basename2(name));
|
|
22843
|
+
if (!existsSync3(file)) throw new Error(`Artifact not found: ${name}`);
|
|
22844
|
+
const buf = readFileSync3(file);
|
|
22413
22845
|
const text2 = buf.toString("utf8");
|
|
22414
22846
|
const looksBinary = text2.includes("\0");
|
|
22415
22847
|
return looksBinary ? { name: basename2(name), encoding: "base64", content: buf.toString("base64") } : { name: basename2(name), encoding: "utf8", content: text2 };
|
|
@@ -22501,39 +22933,39 @@ Chat shortcuts (namespaced \u2014 use these, not /resume)
|
|
|
22501
22933
|
`;
|
|
22502
22934
|
|
|
22503
22935
|
// ../core/src/config.ts
|
|
22504
|
-
import { chmodSync, existsSync as
|
|
22936
|
+
import { chmodSync, existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
22505
22937
|
import { homedir as homedir3 } from "node:os";
|
|
22506
|
-
import { join as
|
|
22938
|
+
import { join as join4 } from "node:path";
|
|
22507
22939
|
function configDir() {
|
|
22508
|
-
return process.env.PANTHEON_CONFIG_DIR ||
|
|
22940
|
+
return process.env.PANTHEON_CONFIG_DIR || join4(homedir3(), ".config", "pantheon");
|
|
22509
22941
|
}
|
|
22510
22942
|
function loadMachineConfig() {
|
|
22511
22943
|
const dir = configDir();
|
|
22512
|
-
const configPath =
|
|
22513
|
-
const credPath =
|
|
22514
|
-
if (!
|
|
22944
|
+
const configPath = join4(dir, "config.json");
|
|
22945
|
+
const credPath = join4(dir, "credentials.json");
|
|
22946
|
+
if (!existsSync4(configPath) || !existsSync4(credPath)) return null;
|
|
22515
22947
|
return {
|
|
22516
|
-
config: JSON.parse(
|
|
22517
|
-
credentials: JSON.parse(
|
|
22948
|
+
config: JSON.parse(readFileSync4(configPath, "utf8")),
|
|
22949
|
+
credentials: JSON.parse(readFileSync4(credPath, "utf8"))
|
|
22518
22950
|
};
|
|
22519
22951
|
}
|
|
22520
22952
|
function saveMachineConfig(config2, credentials) {
|
|
22521
22953
|
const dir = configDir();
|
|
22522
|
-
|
|
22523
|
-
const configPath =
|
|
22524
|
-
const credPath =
|
|
22525
|
-
|
|
22954
|
+
mkdirSync3(dir, { recursive: true });
|
|
22955
|
+
const configPath = join4(dir, "config.json");
|
|
22956
|
+
const credPath = join4(dir, "credentials.json");
|
|
22957
|
+
writeFileSync3(configPath, `${JSON.stringify(config2, null, 2)}
|
|
22526
22958
|
`);
|
|
22527
|
-
|
|
22959
|
+
writeFileSync3(credPath, `${JSON.stringify(credentials, null, 2)}
|
|
22528
22960
|
`);
|
|
22529
22961
|
chmodSync(credPath, 384);
|
|
22530
22962
|
}
|
|
22531
22963
|
|
|
22532
22964
|
// ../core/src/vault.ts
|
|
22533
22965
|
import { execFileSync } from "node:child_process";
|
|
22534
|
-
import { existsSync as
|
|
22966
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync4, unlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
|
|
22535
22967
|
import { homedir as homedir4, tmpdir } from "node:os";
|
|
22536
|
-
import { dirname, join as
|
|
22968
|
+
import { dirname, join as join5 } from "node:path";
|
|
22537
22969
|
function gitEnv(extra = {}) {
|
|
22538
22970
|
return {
|
|
22539
22971
|
...process.env,
|
|
@@ -22541,7 +22973,7 @@ function gitEnv(extra = {}) {
|
|
|
22541
22973
|
PATH: [
|
|
22542
22974
|
extra.PATH,
|
|
22543
22975
|
process.env.PATH,
|
|
22544
|
-
|
|
22976
|
+
join5(homedir4(), ".local", "bin"),
|
|
22545
22977
|
"/opt/homebrew/bin",
|
|
22546
22978
|
"/usr/local/bin",
|
|
22547
22979
|
"/usr/bin",
|
|
@@ -22580,8 +23012,8 @@ async function mintToken() {
|
|
|
22580
23012
|
return body.token;
|
|
22581
23013
|
}
|
|
22582
23014
|
function withGitAuth(token, run) {
|
|
22583
|
-
const dest = process.platform === "win32" ?
|
|
22584
|
-
|
|
23015
|
+
const dest = process.platform === "win32" ? join5(tmpdir(), `pantheon-askpass-${process.pid}-${Date.now()}.cmd`) : join5(tmpdir(), `pantheon-askpass-${process.pid}-${Date.now()}`);
|
|
23016
|
+
writeFileSync4(
|
|
22585
23017
|
dest,
|
|
22586
23018
|
process.platform === "win32" ? `@echo off\r
|
|
22587
23019
|
echo(%~1| findstr /i "Username username" >nul\r
|
|
@@ -22611,7 +23043,7 @@ esac
|
|
|
22611
23043
|
}
|
|
22612
23044
|
function syncVaultWithToken(home, token, opts = {}) {
|
|
22613
23045
|
const result = { ok: false, committed: false, pulled: false, pushed: false };
|
|
22614
|
-
if (!
|
|
23046
|
+
if (!existsSync5(join5(home, ".git"))) {
|
|
22615
23047
|
result.error = "Vault is not a git repo.";
|
|
22616
23048
|
return result;
|
|
22617
23049
|
}
|
|
@@ -22650,11 +23082,11 @@ function syncVaultWithToken(home, token, opts = {}) {
|
|
|
22650
23082
|
}
|
|
22651
23083
|
}
|
|
22652
23084
|
function ensureVaultClone(home, cloneUrl, token) {
|
|
22653
|
-
if (
|
|
23085
|
+
if (existsSync5(join5(home, ".git"))) {
|
|
22654
23086
|
return syncVaultWithToken(home, token, { push: false });
|
|
22655
23087
|
}
|
|
22656
23088
|
try {
|
|
22657
|
-
|
|
23089
|
+
mkdirSync4(dirname(home), { recursive: true });
|
|
22658
23090
|
withGitAuth(token, (env) => {
|
|
22659
23091
|
execFileSync("git", ["clone", "--depth", "50", cloneUrl, home], {
|
|
22660
23092
|
encoding: "utf8",
|
|
@@ -22672,7 +23104,7 @@ function ensureVaultClone(home, cloneUrl, token) {
|
|
|
22672
23104
|
}
|
|
22673
23105
|
}
|
|
22674
23106
|
async function syncVault(home, opts = {}) {
|
|
22675
|
-
if (!
|
|
23107
|
+
if (!existsSync5(join5(home, ".git"))) {
|
|
22676
23108
|
return { ok: false, committed: false, pulled: false, pushed: false, error: "Vault is not a git repo. Run pantheon connect first." };
|
|
22677
23109
|
}
|
|
22678
23110
|
try {
|
|
@@ -22683,6 +23115,9 @@ async function syncVault(home, opts = {}) {
|
|
|
22683
23115
|
}
|
|
22684
23116
|
|
|
22685
23117
|
// ../mcp/src/index.ts
|
|
23118
|
+
function spaceRoot(home, space) {
|
|
23119
|
+
return resolveSpace(home, space).root;
|
|
23120
|
+
}
|
|
22686
23121
|
function defaultHooks() {
|
|
22687
23122
|
return {
|
|
22688
23123
|
pull: (home) => syncVault(home, { push: false }),
|
|
@@ -22733,6 +23168,9 @@ function fail(error2) {
|
|
|
22733
23168
|
}
|
|
22734
23169
|
function hint(message) {
|
|
22735
23170
|
const text2 = message.toLowerCase();
|
|
23171
|
+
if (text2.includes("more than one conversation")) {
|
|
23172
|
+
return "Do not retry blindly \u2014 the same chat would be picked again. Show the human the listed conversations, ask which one they are in, then call pantheon_handoff with that sessionKey.";
|
|
23173
|
+
}
|
|
22736
23174
|
if (text2.includes("not found") && text2.includes("session")) {
|
|
22737
23175
|
return "Call pantheon_search first and use the session_id from a hit.";
|
|
22738
23176
|
}
|
|
@@ -22888,7 +23326,13 @@ ${GUIDE}` }]
|
|
|
22888
23326
|
`Archived ${written.turns} turns${written.added !== written.turns ? ` (${written.added} new)` : ""} from ${written.capturedFrom || "the supplied transcript"}.`,
|
|
22889
23327
|
// Capture reads a chat off disk, so name what it read: if a
|
|
22890
23328
|
// second conversation was open, this is where that shows.
|
|
22891
|
-
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
|
|
23329
|
+
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,
|
|
23330
|
+
// A file the session made and the archive would not take is
|
|
23331
|
+
// the one thing the human cannot see for themselves.
|
|
23332
|
+
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,
|
|
23333
|
+
// Rare by design. Offer it, do not act on it: a skill nobody
|
|
23334
|
+
// asked for is context every future agent pays for.
|
|
23335
|
+
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
|
|
22892
23336
|
].filter(Boolean).join(" ")
|
|
22893
23337
|
};
|
|
22894
23338
|
})
|
|
@@ -22992,6 +23436,51 @@ ${GUIDE}` }]
|
|
|
22992
23436
|
},
|
|
22993
23437
|
async ({ space, session_id, name }) => safe(() => getArtifact(home, space, session_id, name))
|
|
22994
23438
|
);
|
|
23439
|
+
registerTool(
|
|
23440
|
+
server,
|
|
23441
|
+
"pantheon_get_skill",
|
|
23442
|
+
"Read one skill from a Pantheon space: guidance written from failures that already happened in this project. Resume lists the names and when to use each; call this for the body before doing work in an area a skill covers. Every claim cites the session and turn it came from, so pantheon_get_turns will show the original moment if the guidance does not fit your situation.",
|
|
23443
|
+
{ space: external_exports.string(), name: external_exports.string() },
|
|
23444
|
+
async ({ space, name }) => safe(() => readSkill(spaceRoot(home, space), name))
|
|
23445
|
+
);
|
|
23446
|
+
registerTool(
|
|
23447
|
+
server,
|
|
23448
|
+
"pantheon_save_skill",
|
|
23449
|
+
"Write a skill into a Pantheon space as a DRAFT for the human to review. Only call this when pantheon_handoff returned a skillCandidate and the human agreed, or when the human explicitly asks for a skill \u2014 never speculatively, because an unread skill costs every future agent context for nothing. Ground every instruction in the cited evidence: say what failed, what fixed it, and cite session and turn. Do not restate anything already in AGENTS.md or the README.",
|
|
23450
|
+
{
|
|
23451
|
+
space: external_exports.string(),
|
|
23452
|
+
name: external_exports.string().describe("Short slug, e.g. nextjs-og-images."),
|
|
23453
|
+
when: external_exports.string().describe(
|
|
23454
|
+
"One sentence starting 'Use when\u2026' describing the trigger. This is all a future agent sees before deciding to open it, so name the situation, not the topic."
|
|
23455
|
+
),
|
|
23456
|
+
body: external_exports.string().describe(
|
|
23457
|
+
"Markdown. Lead each section with the failure, then the fix. End with the session ids and turn numbers this came from."
|
|
23458
|
+
),
|
|
23459
|
+
key: external_exports.string().optional().describe("The candidate key from pantheon_handoff, so it is not proposed again."),
|
|
23460
|
+
sessions: external_exports.number().optional().describe("How many conversations back this up.")
|
|
23461
|
+
},
|
|
23462
|
+
async ({ space, name, when, body, key, sessions }) => safe(async () => {
|
|
23463
|
+
const saved = saveSkill(spaceRoot(home, space), { name, when, body, key, sessions }, "draft");
|
|
23464
|
+
const sync2 = await vault.push(home, `skill draft ${saved.name}`);
|
|
23465
|
+
return {
|
|
23466
|
+
ok: sync2.ok !== false,
|
|
23467
|
+
...saved,
|
|
23468
|
+
sync: sync2,
|
|
23469
|
+
note: sync2.ok === false ? `Draft saved locally but the push failed: ${sync2.error || "unknown error"}. Tell the human it is not yet in GitHub.` : `Saved as a draft. It is NOT active \u2014 no agent will be given it until the human promotes it from the space page. Tell them it is waiting for review.`
|
|
23470
|
+
};
|
|
23471
|
+
})
|
|
23472
|
+
);
|
|
23473
|
+
registerTool(
|
|
23474
|
+
server,
|
|
23475
|
+
"pantheon_dismiss_skill",
|
|
23476
|
+
"Record that the human does not want a skill written for a candidate pantheon_handoff proposed. Stops it being offered again.",
|
|
23477
|
+
{ space: external_exports.string(), key: external_exports.string() },
|
|
23478
|
+
async ({ space, key }) => safe(async () => {
|
|
23479
|
+
const done = dismissCandidate(spaceRoot(home, space), key);
|
|
23480
|
+
const sync2 = await vault.push(home, "dismiss skill candidate");
|
|
23481
|
+
return { ok: sync2.ok !== false, ...done, sync: sync2 };
|
|
23482
|
+
})
|
|
23483
|
+
);
|
|
22995
23484
|
server.registerPrompt(
|
|
22996
23485
|
"resume",
|
|
22997
23486
|
{
|
|
@@ -23035,18 +23524,18 @@ import { hostname as hostname2 } from "node:os";
|
|
|
23035
23524
|
|
|
23036
23525
|
// src/connect.ts
|
|
23037
23526
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
23038
|
-
import { existsSync as
|
|
23039
|
-
import { join as
|
|
23527
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync6, renameSync } from "node:fs";
|
|
23528
|
+
import { join as join7 } from "node:path";
|
|
23040
23529
|
|
|
23041
23530
|
// src/mcp-install.ts
|
|
23042
|
-
import { existsSync as
|
|
23531
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync5, readFileSync as readFileSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync5 } from "node:fs";
|
|
23043
23532
|
import { homedir as homedir5 } from "node:os";
|
|
23044
|
-
import { dirname as dirname2, join as
|
|
23533
|
+
import { dirname as dirname2, join as join6 } from "node:path";
|
|
23045
23534
|
import { fileURLToPath } from "node:url";
|
|
23046
23535
|
var here = dirname2(fileURLToPath(import.meta.url));
|
|
23047
23536
|
function pantheonBin() {
|
|
23048
23537
|
const self = fileURLToPath(import.meta.url);
|
|
23049
|
-
if (self.endsWith(".ts")) return
|
|
23538
|
+
if (self.endsWith(".ts")) return join6(here, "../bin/pantheon.mjs");
|
|
23050
23539
|
return self;
|
|
23051
23540
|
}
|
|
23052
23541
|
function launchEnv(home) {
|
|
@@ -23069,16 +23558,16 @@ function mcpServer(home, withType = false) {
|
|
|
23069
23558
|
return server;
|
|
23070
23559
|
}
|
|
23071
23560
|
function readJson(path) {
|
|
23072
|
-
if (!
|
|
23561
|
+
if (!existsSync6(path)) return {};
|
|
23073
23562
|
try {
|
|
23074
|
-
return JSON.parse(
|
|
23563
|
+
return JSON.parse(readFileSync5(path, "utf8"));
|
|
23075
23564
|
} catch {
|
|
23076
23565
|
throw new Error(`Could not parse ${path}. Fix the JSON, then retry.`);
|
|
23077
23566
|
}
|
|
23078
23567
|
}
|
|
23079
23568
|
function writeJson(path, data) {
|
|
23080
|
-
|
|
23081
|
-
|
|
23569
|
+
mkdirSync5(dirname2(path), { recursive: true });
|
|
23570
|
+
writeFileSync5(path, `${JSON.stringify(data, null, 2)}
|
|
23082
23571
|
`);
|
|
23083
23572
|
}
|
|
23084
23573
|
function mergeMcpJson(path, home, server, key = "mcpServers") {
|
|
@@ -23092,20 +23581,20 @@ function tomlString(value) {
|
|
|
23092
23581
|
}
|
|
23093
23582
|
function chatgptDesktopPath() {
|
|
23094
23583
|
if (process.platform !== "darwin") return null;
|
|
23095
|
-
return
|
|
23584
|
+
return join6(homedir5(), "Library", "Application Support", "ChatGPT", "chatgpt_mcp_config.json");
|
|
23096
23585
|
}
|
|
23097
23586
|
function claudeDesktopPath() {
|
|
23098
23587
|
if (process.platform === "darwin") {
|
|
23099
|
-
return
|
|
23588
|
+
return join6(homedir5(), "Library", "Application Support", "Claude", "claude_desktop_config.json");
|
|
23100
23589
|
}
|
|
23101
23590
|
if (process.platform === "win32") {
|
|
23102
|
-
return
|
|
23591
|
+
return join6(process.env.APPDATA || homedir5(), "Claude", "claude_desktop_config.json");
|
|
23103
23592
|
}
|
|
23104
|
-
return
|
|
23593
|
+
return join6(homedir5(), ".config", "Claude", "claude_desktop_config.json");
|
|
23105
23594
|
}
|
|
23106
23595
|
function upsertCodex(home) {
|
|
23107
|
-
const path =
|
|
23108
|
-
|
|
23596
|
+
const path = join6(homedir5(), ".codex", "config.toml");
|
|
23597
|
+
mkdirSync5(dirname2(path), { recursive: true });
|
|
23109
23598
|
const server = mcpServer(home);
|
|
23110
23599
|
const args = server.args.map(tomlString).join(", ");
|
|
23111
23600
|
const block2 = [
|
|
@@ -23118,21 +23607,21 @@ function upsertCodex(home) {
|
|
|
23118
23607
|
`PANTHEON_HOME = ${tomlString(home)}`,
|
|
23119
23608
|
""
|
|
23120
23609
|
].join("\n");
|
|
23121
|
-
if (!
|
|
23122
|
-
|
|
23610
|
+
if (!existsSync6(path)) {
|
|
23611
|
+
writeFileSync5(path, block2);
|
|
23123
23612
|
return;
|
|
23124
23613
|
}
|
|
23125
|
-
const existing =
|
|
23614
|
+
const existing = readFileSync5(path, "utf8");
|
|
23126
23615
|
if (existing.includes("[mcp_servers.pantheon]")) {
|
|
23127
23616
|
const next = existing.replace(
|
|
23128
23617
|
/\[mcp_servers\.pantheon\][\s\S]*?(?=\n\[(?!mcp_servers\.pantheon)|\s*$)/,
|
|
23129
23618
|
block2.trim()
|
|
23130
23619
|
);
|
|
23131
|
-
|
|
23620
|
+
writeFileSync5(path, next.endsWith("\n") ? next : `${next}
|
|
23132
23621
|
`);
|
|
23133
23622
|
return;
|
|
23134
23623
|
}
|
|
23135
|
-
|
|
23624
|
+
writeFileSync5(path, `${existing.trimEnd()}
|
|
23136
23625
|
|
|
23137
23626
|
${block2}`);
|
|
23138
23627
|
}
|
|
@@ -23178,7 +23667,7 @@ Parse the rest of the argument as the fact. Only then call pantheon_remember, ev
|
|
|
23178
23667
|
}
|
|
23179
23668
|
];
|
|
23180
23669
|
function writeCodexSkill() {
|
|
23181
|
-
const dirs2 = [
|
|
23670
|
+
const dirs2 = [join6(homedir5(), ".agents", "skills", "pantheon"), join6(homedir5(), ".codex", "skills", "pantheon")];
|
|
23182
23671
|
const skill = `---
|
|
23183
23672
|
name: pantheon
|
|
23184
23673
|
description: Use when the user types /pantheon-handoff, /pantheon-resume, /pantheon-park, /pantheon-remember, /pantheon-spaces, /pantheon-help, mentions Pantheon, conscience, spaces, or wants to hand off or resume an agent conversation. Always call pantheon_* MCP tools first. Never invent Pantheon space names from memory.
|
|
@@ -23202,17 +23691,17 @@ A **space** is the short name the human chose for a conscience. For handoff, par
|
|
|
23202
23691
|
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.
|
|
23203
23692
|
`;
|
|
23204
23693
|
for (const dir of dirs2) {
|
|
23205
|
-
|
|
23206
|
-
|
|
23694
|
+
mkdirSync5(dir, { recursive: true });
|
|
23695
|
+
writeFileSync5(join6(dir, "SKILL.md"), skill);
|
|
23207
23696
|
}
|
|
23208
23697
|
}
|
|
23209
23698
|
function writeSlashCommands() {
|
|
23210
|
-
const dirs2 = [
|
|
23699
|
+
const dirs2 = [join6(homedir5(), ".cursor", "commands"), join6(homedir5(), ".claude", "commands")];
|
|
23211
23700
|
for (const dir of dirs2) {
|
|
23212
|
-
|
|
23701
|
+
mkdirSync5(dir, { recursive: true });
|
|
23213
23702
|
for (const command of slashCommands) {
|
|
23214
|
-
|
|
23215
|
-
|
|
23703
|
+
writeFileSync5(
|
|
23704
|
+
join6(dir, `${command.name}.md`),
|
|
23216
23705
|
`---
|
|
23217
23706
|
description: ${command.description}
|
|
23218
23707
|
---
|
|
@@ -23235,33 +23724,33 @@ function installMcpClients(home) {
|
|
|
23235
23724
|
const written = [];
|
|
23236
23725
|
const skipped = [];
|
|
23237
23726
|
const server = mcpServer(home);
|
|
23238
|
-
const cursor =
|
|
23727
|
+
const cursor = join6(homedir5(), ".cursor", "mcp.json");
|
|
23239
23728
|
mergeMcpJson(cursor, home, server);
|
|
23240
23729
|
written.push({ name: "Cursor", detail: tilde(cursor) });
|
|
23241
|
-
const claudeCode =
|
|
23730
|
+
const claudeCode = join6(homedir5(), ".claude.json");
|
|
23242
23731
|
mergeMcpJson(claudeCode, home, mcpServer(home, true));
|
|
23243
23732
|
written.push({ name: "Claude Code", detail: tilde(claudeCode) });
|
|
23244
23733
|
const desktop = claudeDesktopPath();
|
|
23245
|
-
if (
|
|
23734
|
+
if (existsSync6(dirname2(desktop)) || process.platform === "darwin" || process.platform === "win32") {
|
|
23246
23735
|
mergeMcpJson(desktop, home, server);
|
|
23247
23736
|
written.push({ name: "Claude Desktop", detail: tilde(desktop) });
|
|
23248
23737
|
} else {
|
|
23249
23738
|
skipped.push({ name: "Claude Desktop", detail: "app not found" });
|
|
23250
23739
|
}
|
|
23251
23740
|
const chatgpt = chatgptDesktopPath();
|
|
23252
|
-
if (chatgpt &&
|
|
23741
|
+
if (chatgpt && existsSync6(dirname2(chatgpt))) {
|
|
23253
23742
|
mergeMcpJson(chatgpt, home, server);
|
|
23254
23743
|
written.push({ name: "ChatGPT.app", detail: tilde(chatgpt) });
|
|
23255
23744
|
}
|
|
23256
|
-
const codex =
|
|
23745
|
+
const codex = join6(homedir5(), ".codex", "config.toml");
|
|
23257
23746
|
try {
|
|
23258
23747
|
upsertCodex(home);
|
|
23259
23748
|
written.push({ name: "Codex", detail: tilde(codex) });
|
|
23260
23749
|
} catch {
|
|
23261
23750
|
skipped.push({ name: "Codex", detail: `could not write ${tilde(codex)}` });
|
|
23262
23751
|
}
|
|
23263
|
-
const windsurf =
|
|
23264
|
-
if (
|
|
23752
|
+
const windsurf = join6(homedir5(), ".codeium", "windsurf", "mcp_config.json");
|
|
23753
|
+
if (existsSync6(dirname2(windsurf))) {
|
|
23265
23754
|
mergeMcpJson(windsurf, home, server);
|
|
23266
23755
|
written.push({ name: "Windsurf", detail: tilde(windsurf) });
|
|
23267
23756
|
} else {
|
|
@@ -23279,7 +23768,7 @@ function installMcpClients(home) {
|
|
|
23279
23768
|
return { written, skipped };
|
|
23280
23769
|
}
|
|
23281
23770
|
function removeServerFromJson(path, key = "mcpServers") {
|
|
23282
|
-
if (!
|
|
23771
|
+
if (!existsSync6(path)) return false;
|
|
23283
23772
|
const current = readJson(path);
|
|
23284
23773
|
const servers = current[key] ?? {};
|
|
23285
23774
|
if (!servers.pantheon) return false;
|
|
@@ -23289,22 +23778,22 @@ function removeServerFromJson(path, key = "mcpServers") {
|
|
|
23289
23778
|
return true;
|
|
23290
23779
|
}
|
|
23291
23780
|
function removeCodex() {
|
|
23292
|
-
const path =
|
|
23293
|
-
if (!
|
|
23294
|
-
const existing =
|
|
23781
|
+
const path = join6(homedir5(), ".codex", "config.toml");
|
|
23782
|
+
if (!existsSync6(path)) return false;
|
|
23783
|
+
const existing = readFileSync5(path, "utf8");
|
|
23295
23784
|
if (!existing.includes("[mcp_servers.pantheon]")) return false;
|
|
23296
23785
|
const next = existing.replace(/\[mcp_servers\.pantheon\][\s\S]*?(?=\n\[(?!mcp_servers\.pantheon)|\s*$)/, "").replace(/\n{3,}/g, "\n\n").trimEnd();
|
|
23297
|
-
|
|
23786
|
+
writeFileSync5(path, next ? `${next}
|
|
23298
23787
|
` : "");
|
|
23299
23788
|
return true;
|
|
23300
23789
|
}
|
|
23301
23790
|
function removeSlashCommands() {
|
|
23302
|
-
const dirs2 = [
|
|
23791
|
+
const dirs2 = [join6(homedir5(), ".cursor", "commands"), join6(homedir5(), ".claude", "commands")];
|
|
23303
23792
|
let removed = 0;
|
|
23304
23793
|
for (const dir of dirs2) {
|
|
23305
23794
|
for (const command of slashCommands) {
|
|
23306
|
-
const file =
|
|
23307
|
-
if (!
|
|
23795
|
+
const file = join6(dir, `${command.name}.md`);
|
|
23796
|
+
if (!existsSync6(file)) continue;
|
|
23308
23797
|
unlinkSync2(file);
|
|
23309
23798
|
removed += 1;
|
|
23310
23799
|
}
|
|
@@ -23313,32 +23802,32 @@ function removeSlashCommands() {
|
|
|
23313
23802
|
}
|
|
23314
23803
|
function uninstallMcpClients() {
|
|
23315
23804
|
const removed = [];
|
|
23316
|
-
if (removeServerFromJson(
|
|
23317
|
-
if (removeServerFromJson(
|
|
23805
|
+
if (removeServerFromJson(join6(homedir5(), ".cursor", "mcp.json"))) removed.push("Cursor");
|
|
23806
|
+
if (removeServerFromJson(join6(homedir5(), ".claude.json"))) removed.push("Claude Code");
|
|
23318
23807
|
if (removeServerFromJson(claudeDesktopPath())) removed.push("Claude Desktop");
|
|
23319
23808
|
const chatgpt = chatgptDesktopPath();
|
|
23320
23809
|
if (chatgpt && removeServerFromJson(chatgpt)) removed.push("ChatGPT.app (shared MCP file)");
|
|
23321
23810
|
if (removeCodex()) removed.push("ChatGPT.app / Codex");
|
|
23322
|
-
if (removeServerFromJson(
|
|
23811
|
+
if (removeServerFromJson(join6(homedir5(), ".codeium", "windsurf", "mcp_config.json"))) {
|
|
23323
23812
|
removed.push("Windsurf");
|
|
23324
23813
|
}
|
|
23325
|
-
const
|
|
23326
|
-
if (
|
|
23814
|
+
const slash2 = removeSlashCommands();
|
|
23815
|
+
if (slash2) removed.push("/pantheon-* commands");
|
|
23327
23816
|
for (const dir of [
|
|
23328
|
-
|
|
23329
|
-
|
|
23817
|
+
join6(homedir5(), ".agents", "skills", "pantheon"),
|
|
23818
|
+
join6(homedir5(), ".codex", "skills", "pantheon")
|
|
23330
23819
|
]) {
|
|
23331
|
-
const file =
|
|
23332
|
-
if (!
|
|
23820
|
+
const file = join6(dir, "SKILL.md");
|
|
23821
|
+
if (!existsSync6(file)) continue;
|
|
23333
23822
|
unlinkSync2(file);
|
|
23334
23823
|
removed.push("ChatGPT / Codex skill");
|
|
23335
23824
|
break;
|
|
23336
23825
|
}
|
|
23337
23826
|
for (const launcher of [
|
|
23338
|
-
|
|
23339
|
-
|
|
23827
|
+
join6(homedir5(), ".local", "bin", "pantheon-mcp"),
|
|
23828
|
+
join6(homedir5(), ".local", "bin", "pantheon-mcp.cmd")
|
|
23340
23829
|
]) {
|
|
23341
|
-
if (!
|
|
23830
|
+
if (!existsSync6(launcher)) continue;
|
|
23342
23831
|
unlinkSync2(launcher);
|
|
23343
23832
|
removed.push("pantheon-mcp launcher");
|
|
23344
23833
|
}
|
|
@@ -23417,10 +23906,10 @@ async function connect(opts) {
|
|
|
23417
23906
|
},
|
|
23418
23907
|
{ machineSecret: body.machineSecret }
|
|
23419
23908
|
);
|
|
23420
|
-
|
|
23909
|
+
mkdirSync6(home, { recursive: true });
|
|
23421
23910
|
const helper = credentialHelperCommand();
|
|
23422
23911
|
const quiet = { stdio: ["ignore", "pipe", "pipe"] };
|
|
23423
|
-
const fresh = !
|
|
23912
|
+
const fresh = !existsSync7(join7(home, ".git"));
|
|
23424
23913
|
let archived = "";
|
|
23425
23914
|
if (fresh) {
|
|
23426
23915
|
process.stdout.write(" Cloning the vault\u2026\n");
|
|
@@ -23462,7 +23951,7 @@ function syncVault2(home, cloneUrl, helper, quiet) {
|
|
|
23462
23951
|
git2("pull", "--ff-only");
|
|
23463
23952
|
return "";
|
|
23464
23953
|
} catch (error2) {
|
|
23465
|
-
if (!
|
|
23954
|
+
if (!existsSync7(join7(home, ".git"))) throw error2;
|
|
23466
23955
|
}
|
|
23467
23956
|
if (sharesHistory(home)) {
|
|
23468
23957
|
process.stdout.write(" Merging work from another machine\u2026\n");
|
|
@@ -23651,7 +24140,7 @@ function printSpaces() {
|
|
|
23651
24140
|
}
|
|
23652
24141
|
|
|
23653
24142
|
// src/status.ts
|
|
23654
|
-
import { existsSync as
|
|
24143
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
23655
24144
|
function printStatus() {
|
|
23656
24145
|
const stored = loadMachineConfig();
|
|
23657
24146
|
if (!stored) {
|
|
@@ -23665,7 +24154,7 @@ function printStatus() {
|
|
|
23665
24154
|
field("GitHub", config2.account),
|
|
23666
24155
|
field("Install", String(config2.installationId)),
|
|
23667
24156
|
field("Repo", `${config2.repo} (private)`),
|
|
23668
|
-
field("Vault", `${config2.home}${
|
|
24157
|
+
field("Vault", `${config2.home}${existsSync8(config2.home) ? "" : " (missing)"}`),
|
|
23669
24158
|
field("API", config2.apiUrl),
|
|
23670
24159
|
field("Machine", config2.machineId)
|
|
23671
24160
|
].join("\n")
|
|
@@ -23744,10 +24233,10 @@ async function main() {
|
|
|
23744
24233
|
return;
|
|
23745
24234
|
}
|
|
23746
24235
|
if (AGENT_VERBS.has(cmd)) {
|
|
23747
|
-
const
|
|
24236
|
+
const slash2 = ["handoff", "park", "resume", "remember"].includes(cmd);
|
|
23748
24237
|
printError(
|
|
23749
24238
|
new Error(
|
|
23750
|
-
|
|
24239
|
+
slash2 ? `${cmd} is an MCP tool, not a CLI command. Call pantheon_${cmd.replace(/^pantheon_/, "")}, or type /pantheon-${cmd.replace(/^pantheon_/, "")} <space> in chat.` : `${cmd} is an MCP tool, not a CLI command. Call the pantheon_* tool, or type /pantheon-help.`
|
|
23751
24240
|
)
|
|
23752
24241
|
);
|
|
23753
24242
|
process.stdout.write(GUIDE);
|