pantheon-cli 0.1.1 → 0.1.2
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 +108 -1
- package/package.json +1 -1
package/dist/pantheon.mjs
CHANGED
|
@@ -21764,6 +21764,110 @@ function collectDiskArtifacts(turns) {
|
|
|
21764
21764
|
}
|
|
21765
21765
|
return found;
|
|
21766
21766
|
}
|
|
21767
|
+
var WRITE_TOOL = /write|edit|patch|notebook|replace|create|save/i;
|
|
21768
|
+
var PATH_KEYS = [
|
|
21769
|
+
"path",
|
|
21770
|
+
"file_path",
|
|
21771
|
+
"filePath",
|
|
21772
|
+
"target_file",
|
|
21773
|
+
"target_notebook",
|
|
21774
|
+
"notebook_path",
|
|
21775
|
+
"absolute_path"
|
|
21776
|
+
];
|
|
21777
|
+
function pathsFromPatch(input) {
|
|
21778
|
+
const body = typeof input === "string" ? input : input && typeof input === "object" ? String(input.input ?? input.patch ?? "") : "";
|
|
21779
|
+
if (!body.includes("***")) return [];
|
|
21780
|
+
const found = [];
|
|
21781
|
+
for (const match of body.matchAll(/^\*\*\*\s+(?:Add|Update|Move to) File:\s*(.+)$/gm)) {
|
|
21782
|
+
const path = match[1].trim();
|
|
21783
|
+
if (path) found.push(path);
|
|
21784
|
+
}
|
|
21785
|
+
return found;
|
|
21786
|
+
}
|
|
21787
|
+
var SKIP_PATH = /(^|\/)(node_modules|\.git|\.next|dist|build|out|coverage|\.turbo)(\/|$)|\.(lock|log)$|lock\.(json|yaml)$/;
|
|
21788
|
+
var MAX_WRITTEN_FILE = 512 * 1024;
|
|
21789
|
+
var MAX_WRITTEN_TOTAL = 8 * 1024 * 1024;
|
|
21790
|
+
var MAX_WRITTEN_COUNT = 200;
|
|
21791
|
+
function pathFromInput(input) {
|
|
21792
|
+
if (!input || typeof input !== "object") return null;
|
|
21793
|
+
const record2 = input;
|
|
21794
|
+
for (const key of PATH_KEYS) {
|
|
21795
|
+
const value = record2[key];
|
|
21796
|
+
if (typeof value === "string" && value.trim()) return value.trim();
|
|
21797
|
+
}
|
|
21798
|
+
return null;
|
|
21799
|
+
}
|
|
21800
|
+
function flatName(path, base) {
|
|
21801
|
+
const relative = path.startsWith(base) ? path.slice(base.length) : path;
|
|
21802
|
+
return relative.replace(/^[./]+/, "").replace(/[^a-zA-Z0-9._/-]/g, "_").replace(/\//g, "_");
|
|
21803
|
+
}
|
|
21804
|
+
function readArtifactFile(path, base) {
|
|
21805
|
+
const stat = statSync2(path);
|
|
21806
|
+
if (!stat.isFile() || stat.size === 0 || stat.size > MAX_WRITTEN_FILE) return null;
|
|
21807
|
+
const buf = readFileSync2(path);
|
|
21808
|
+
const binary = buf.includes(0);
|
|
21809
|
+
return {
|
|
21810
|
+
name: flatName(path, base),
|
|
21811
|
+
content: binary ? buf.toString("base64") : buf.toString("utf8"),
|
|
21812
|
+
encoding: binary ? "base64" : "utf8",
|
|
21813
|
+
bytes: stat.size
|
|
21814
|
+
};
|
|
21815
|
+
}
|
|
21816
|
+
function collectWrittenArtifacts(turns, cwd = process.cwd()) {
|
|
21817
|
+
const base = cwd.endsWith("/") ? cwd : `${cwd}/`;
|
|
21818
|
+
const latest = /* @__PURE__ */ new Set();
|
|
21819
|
+
const add = (path) => {
|
|
21820
|
+
const full = path.startsWith("/") ? path : join2(base, path);
|
|
21821
|
+
if (!SKIP_PATH.test(full)) latest.add(full);
|
|
21822
|
+
};
|
|
21823
|
+
for (const turn of turns) {
|
|
21824
|
+
for (const call of turn.toolCalls ?? []) {
|
|
21825
|
+
if (!WRITE_TOOL.test(call.name || "")) continue;
|
|
21826
|
+
const path = pathFromInput(call.input);
|
|
21827
|
+
if (path) add(path);
|
|
21828
|
+
for (const patched of pathsFromPatch(call.input)) add(patched);
|
|
21829
|
+
}
|
|
21830
|
+
}
|
|
21831
|
+
const found = [];
|
|
21832
|
+
let total = 0;
|
|
21833
|
+
for (const path of latest) {
|
|
21834
|
+
if (found.length >= MAX_WRITTEN_COUNT || total >= MAX_WRITTEN_TOTAL) break;
|
|
21835
|
+
try {
|
|
21836
|
+
if (!existsSync2(path)) continue;
|
|
21837
|
+
const file = readArtifactFile(path, base);
|
|
21838
|
+
if (!file) continue;
|
|
21839
|
+
total += file.bytes;
|
|
21840
|
+
found.push({ name: file.name, content: file.content, encoding: file.encoding });
|
|
21841
|
+
} catch {
|
|
21842
|
+
}
|
|
21843
|
+
}
|
|
21844
|
+
return found;
|
|
21845
|
+
}
|
|
21846
|
+
function collectAttachedArtifacts(turns, cwd = process.cwd()) {
|
|
21847
|
+
const base = cwd.endsWith("/") ? cwd : `${cwd}/`;
|
|
21848
|
+
const paths = /* @__PURE__ */ new Set();
|
|
21849
|
+
for (const turn of turns) {
|
|
21850
|
+
if (turn.role !== "user") continue;
|
|
21851
|
+
for (const match of (turn.text || "").matchAll(/(?:^|[\s"'`(@])(\/[\w./@ -]*\/[\w.@-]+\.[a-zA-Z0-9]{1,16})/g)) {
|
|
21852
|
+
const path = match[1].trim();
|
|
21853
|
+
if (!SKIP_PATH.test(path)) paths.add(path);
|
|
21854
|
+
}
|
|
21855
|
+
}
|
|
21856
|
+
const found = [];
|
|
21857
|
+
let total = 0;
|
|
21858
|
+
for (const path of paths) {
|
|
21859
|
+
if (found.length >= 40 || total >= MAX_WRITTEN_TOTAL) break;
|
|
21860
|
+
try {
|
|
21861
|
+
if (!existsSync2(path)) continue;
|
|
21862
|
+
const file = readArtifactFile(path, base);
|
|
21863
|
+
if (!file) continue;
|
|
21864
|
+
total += file.bytes;
|
|
21865
|
+
found.push({ name: file.name, content: file.content, encoding: file.encoding });
|
|
21866
|
+
} catch {
|
|
21867
|
+
}
|
|
21868
|
+
}
|
|
21869
|
+
return found;
|
|
21870
|
+
}
|
|
21767
21871
|
function missingGeneratedFiles(turns, artifacts = []) {
|
|
21768
21872
|
const mentioned = mentionedDocuments(turns).map((doc) => doc.name);
|
|
21769
21873
|
if (!mentioned.length) return null;
|
|
@@ -21945,10 +22049,13 @@ function writeHandoff(home, input) {
|
|
|
21945
22049
|
const thin = transcriptLooksThin(turns);
|
|
21946
22050
|
if (thin) throw new Error(thin);
|
|
21947
22051
|
}
|
|
22052
|
+
const cwd = input.cwd || process.cwd();
|
|
21948
22053
|
const artifacts = mergeArtifacts(
|
|
21949
22054
|
input.artifacts,
|
|
21950
22055
|
extractFencedArtifacts(turns),
|
|
21951
|
-
collectDiskArtifacts(turns)
|
|
22056
|
+
collectDiskArtifacts(turns),
|
|
22057
|
+
captured ? collectWrittenArtifacts(turns, cwd) : void 0,
|
|
22058
|
+
captured ? collectAttachedArtifacts(turns, cwd) : void 0
|
|
21952
22059
|
);
|
|
21953
22060
|
if (!captured) {
|
|
21954
22061
|
const missing = missingGeneratedFiles(turns, artifacts);
|
package/package.json
CHANGED