@mytegroupinc/myte-core 0.0.2 → 0.0.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/cli.js +39 -20
- package/package.json +1 -2
package/cli.js
CHANGED
|
@@ -211,6 +211,11 @@ function runGitDiff(repoPath, args, opts = {}) {
|
|
|
211
211
|
maxBuffer: 64 * 1024 * 1024,
|
|
212
212
|
...opts,
|
|
213
213
|
});
|
|
214
|
+
if (res.error && res.error.code === "ENOENT") {
|
|
215
|
+
const err = new Error("git executable not found in PATH. Install Git and ensure PATH includes git.");
|
|
216
|
+
err.code = "ENOENT";
|
|
217
|
+
throw err;
|
|
218
|
+
}
|
|
214
219
|
if (res.status !== 0 && res.status !== 1) {
|
|
215
220
|
const msg = res.stderr || res.error?.message || "unknown git error";
|
|
216
221
|
const err = new Error(`git ${args.join(" ")} failed (${res.status}): ${msg}`);
|
|
@@ -239,6 +244,14 @@ function runGitTry(repoPath, args) {
|
|
|
239
244
|
}
|
|
240
245
|
}
|
|
241
246
|
|
|
247
|
+
function runGitSafeDiff(repoPath, args, prefix) {
|
|
248
|
+
const patchText = runGitTry(repoPath, args);
|
|
249
|
+
if (!patchText) {
|
|
250
|
+
return "";
|
|
251
|
+
}
|
|
252
|
+
return patchPaths(patchText, prefix);
|
|
253
|
+
}
|
|
254
|
+
|
|
242
255
|
function patchPaths(diff, prefix = "") {
|
|
243
256
|
if (!diff) return "";
|
|
244
257
|
return diff
|
|
@@ -378,13 +391,15 @@ function collectGitDiff({ projectId, repoNames, maxChars, fetchRemote = true } =
|
|
|
378
391
|
const headBranch = runGitTry(abs, ["rev-parse", "--abbrev-ref", "HEAD"]) || "HEAD";
|
|
379
392
|
const baseRef = resolveBaseRef(abs);
|
|
380
393
|
|
|
381
|
-
const baseDiffRaw = baseRef
|
|
382
|
-
|
|
383
|
-
|
|
394
|
+
const baseDiffRaw = baseRef
|
|
395
|
+
? runGitSafeDiff(abs, ["diff", "--no-color", "-U2", `${baseRef}...HEAD`], prefix)
|
|
396
|
+
: "";
|
|
397
|
+
const stagedRaw = runGitSafeDiff(abs, ["diff", "--cached", "--no-color", "-U2"], prefix);
|
|
398
|
+
const unstagedRaw = runGitSafeDiff(abs, ["diff", "--no-color", "-U2"], prefix);
|
|
384
399
|
|
|
385
|
-
const baseDiff =
|
|
386
|
-
const staged =
|
|
387
|
-
const unstaged =
|
|
400
|
+
const baseDiff = filterDiff(baseDiffRaw);
|
|
401
|
+
const staged = filterDiff(stagedRaw);
|
|
402
|
+
const unstaged = filterDiff(unstagedRaw);
|
|
388
403
|
|
|
389
404
|
const untracked = runGitTry(abs, ["ls-files", "--others", "--exclude-standard"])
|
|
390
405
|
.split("\n")
|
|
@@ -395,7 +410,7 @@ function collectGitDiff({ projectId, repoNames, maxChars, fetchRemote = true } =
|
|
|
395
410
|
for (const file of untracked) {
|
|
396
411
|
const absFile = path.join(abs, file);
|
|
397
412
|
if (!fs.existsSync(absFile) || !fs.statSync(absFile).isFile()) continue;
|
|
398
|
-
const patch =
|
|
413
|
+
const patch = runGitTry(abs, ["diff", "--no-index", "--no-color", "/dev/null", file]);
|
|
399
414
|
if (patch) untrackedDiffs += patchPaths(patch, prefix) + "\n";
|
|
400
415
|
}
|
|
401
416
|
|
|
@@ -549,23 +564,28 @@ async function runQuery(args) {
|
|
|
549
564
|
|
|
550
565
|
let diffText = "";
|
|
551
566
|
if (includeDiff) {
|
|
552
|
-
let cfg;
|
|
567
|
+
let cfg = null;
|
|
553
568
|
try {
|
|
554
569
|
cfg = await fetchProjectConfig({ apiBase, key, timeoutMs });
|
|
555
570
|
} catch (err) {
|
|
556
|
-
console.
|
|
557
|
-
|
|
571
|
+
console.warn("Warning: project config unavailable for --with-diff. Continuing without diff context.");
|
|
572
|
+
console.warn(`Detail: ${err?.message || err}`);
|
|
573
|
+
cfg = null;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
if (cfg) {
|
|
577
|
+
const repoNames = Array.isArray(cfg.repo_names) ? cfg.repo_names : [];
|
|
578
|
+
diffText = collectGitDiff({
|
|
579
|
+
projectId: cfg.project_id,
|
|
580
|
+
repoNames,
|
|
581
|
+
maxChars: diffLimit,
|
|
582
|
+
fetchRemote,
|
|
583
|
+
});
|
|
584
|
+
} else {
|
|
585
|
+
diffText = "";
|
|
558
586
|
}
|
|
559
|
-
const repoNames = Array.isArray(cfg.repo_names) ? cfg.repo_names : [];
|
|
560
|
-
diffText = collectGitDiff({
|
|
561
|
-
projectId: cfg.project_id,
|
|
562
|
-
repoNames,
|
|
563
|
-
maxChars: diffLimit,
|
|
564
|
-
fetchRemote,
|
|
565
|
-
});
|
|
566
587
|
if (!diffText) {
|
|
567
|
-
console.error("
|
|
568
|
-
process.exit(1);
|
|
588
|
+
console.error("Warning: no diff context collected. Continuing without --with-diff context.");
|
|
569
589
|
}
|
|
570
590
|
}
|
|
571
591
|
|
|
@@ -650,4 +670,3 @@ main().catch((err) => {
|
|
|
650
670
|
console.error("Unexpected error:", err?.message || err);
|
|
651
671
|
process.exit(1);
|
|
652
672
|
});
|
|
653
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mytegroupinc/myte-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Myte CLI core implementation (Project Assistant + deterministic diffs).",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "cli.js",
|
|
@@ -17,4 +17,3 @@
|
|
|
17
17
|
"node-fetch": "^3.3.2"
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
|