@deftai/directive 0.128.0 → 0.129.1
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/bin.js +234 -113
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -427,15 +427,98 @@ Recovery: ${RECOVERY_GUIDANCE}
|
|
|
427
427
|
import { mkdirSync } from "node:fs";
|
|
428
428
|
|
|
429
429
|
// packages/cli/src/bookends.ts
|
|
430
|
-
import { existsSync as
|
|
431
|
-
import { join as
|
|
430
|
+
import { existsSync as existsSync8, readFileSync as readFileSync6 } from "node:fs";
|
|
431
|
+
import { join as join7 } from "node:path";
|
|
432
|
+
|
|
433
|
+
// packages/cli/src/age-exclude.ts
|
|
434
|
+
import { existsSync as existsSync4, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
435
|
+
import { join as join3 } from "node:path";
|
|
436
|
+
var RUNTIME_AGE_EXCLUDE_PACKAGE = "@deftai/directive-runtime";
|
|
437
|
+
var PNPM_WORKSPACE_FILE = "pnpm-workspace.yaml";
|
|
438
|
+
var KEY_RE = /^(\s*)minimumReleaseAgeExclude:\s*(#.*)?$/;
|
|
439
|
+
var ITEM_RE = /^(\s*)-\s+(.*)$/;
|
|
440
|
+
var EXACT_VERSION_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
441
|
+
function indentOf(line) {
|
|
442
|
+
return line.length - line.trimStart().length;
|
|
443
|
+
}
|
|
444
|
+
function itemValue(raw) {
|
|
445
|
+
let v = raw.trim();
|
|
446
|
+
if (v.startsWith("'") || v.startsWith('"')) {
|
|
447
|
+
const q = v[0];
|
|
448
|
+
const end = v.indexOf(q, 1);
|
|
449
|
+
return end > 0 ? v.slice(1, end) : v;
|
|
450
|
+
}
|
|
451
|
+
const hash = v.search(/\s#/);
|
|
452
|
+
if (hash >= 0) v = v.slice(0, hash);
|
|
453
|
+
return v.trim();
|
|
454
|
+
}
|
|
455
|
+
function isRuntimeExact(value) {
|
|
456
|
+
const prefix = `${RUNTIME_AGE_EXCLUDE_PACKAGE}@`;
|
|
457
|
+
return value.startsWith(prefix) && EXACT_VERSION_RE.test(value.slice(prefix.length));
|
|
458
|
+
}
|
|
459
|
+
function upsertRuntimeAgeExcludeText(text, targetVersion) {
|
|
460
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
461
|
+
const lines = text.split(eol);
|
|
462
|
+
const keyIdx = lines.findIndex((l) => KEY_RE.test(l));
|
|
463
|
+
if (keyIdx < 0) return { changed: false, text, priorRuntimeItems: [] };
|
|
464
|
+
const keyIndent = indentOf(lines[keyIdx]);
|
|
465
|
+
const runtimeIdx = [];
|
|
466
|
+
const prior = [];
|
|
467
|
+
for (let i = keyIdx + 1; i < lines.length; i++) {
|
|
468
|
+
const line = lines[i];
|
|
469
|
+
const trimmed = line.trim();
|
|
470
|
+
if (trimmed === "" || trimmed.startsWith("#")) continue;
|
|
471
|
+
const m = ITEM_RE.exec(line);
|
|
472
|
+
if (m === null || indentOf(line) < keyIndent) break;
|
|
473
|
+
const value = itemValue(m[2]);
|
|
474
|
+
if (isRuntimeExact(value)) {
|
|
475
|
+
runtimeIdx.push(i);
|
|
476
|
+
prior.push(value);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (runtimeIdx.length === 0) return { changed: false, text, priorRuntimeItems: [] };
|
|
480
|
+
const first = runtimeIdx[0];
|
|
481
|
+
const itemIndent = ITEM_RE.exec(lines[first])?.[1] ?? "";
|
|
482
|
+
const replacement = `${itemIndent}- '${RUNTIME_AGE_EXCLUDE_PACKAGE}@${targetVersion}'`;
|
|
483
|
+
const drop = new Set(runtimeIdx.slice(1));
|
|
484
|
+
const out = [];
|
|
485
|
+
for (let i = 0; i < lines.length; i++) {
|
|
486
|
+
if (drop.has(i)) continue;
|
|
487
|
+
out.push(i === first ? replacement : lines[i]);
|
|
488
|
+
}
|
|
489
|
+
const next = out.join(eol);
|
|
490
|
+
return { changed: next !== text, text: next, priorRuntimeItems: prior };
|
|
491
|
+
}
|
|
492
|
+
function previewRuntimeAgeExcludeHeal(projectRoot, targetVersion) {
|
|
493
|
+
const abs = join3(projectRoot, PNPM_WORKSPACE_FILE);
|
|
494
|
+
if (!existsSync4(abs)) return null;
|
|
495
|
+
const r = upsertRuntimeAgeExcludeText(readFileSync2(abs, "utf8"), targetVersion);
|
|
496
|
+
return r.changed ? r : null;
|
|
497
|
+
}
|
|
498
|
+
function healRuntimeAgeExclude(projectRoot, targetVersion) {
|
|
499
|
+
const r = previewRuntimeAgeExcludeHeal(projectRoot, targetVersion);
|
|
500
|
+
if (r === null) return false;
|
|
501
|
+
writeFileSync(join3(projectRoot, PNPM_WORKSPACE_FILE), r.text, "utf8");
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
function formatAgeExcludeHealLine(r, targetVersion) {
|
|
505
|
+
return `pnpm-workspace.yaml: replace minimumReleaseAgeExclude ${r.priorRuntimeItems.join(", ")} with one '${RUNTIME_AGE_EXCLUDE_PACKAGE}@${targetVersion}' entry (#5854)
|
|
506
|
+
`;
|
|
507
|
+
}
|
|
508
|
+
function addWithRuntimeAgeExcludeHeal(projectRoot, pm, targetVersion, add) {
|
|
509
|
+
if (pm !== "pnpm") return add();
|
|
510
|
+
healRuntimeAgeExclude(projectRoot, targetVersion);
|
|
511
|
+
const result = add();
|
|
512
|
+
if (result.ok) healRuntimeAgeExclude(projectRoot, targetVersion);
|
|
513
|
+
return result;
|
|
514
|
+
}
|
|
432
515
|
|
|
433
516
|
// packages/cli/src/contract-invoke.ts
|
|
434
517
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
435
|
-
import { existsSync as
|
|
518
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
436
519
|
function invokeRuntime(options) {
|
|
437
520
|
const { projectRoot, launcherVersion, runtime, argv } = options;
|
|
438
|
-
if (!
|
|
521
|
+
if (!existsSync5(runtime.entryPath)) {
|
|
439
522
|
return {
|
|
440
523
|
exitCode: EXIT_CODES.FAILURE,
|
|
441
524
|
stdout: "",
|
|
@@ -552,8 +635,8 @@ function readInteractiveLine(options) {
|
|
|
552
635
|
|
|
553
636
|
// packages/cli/src/legacy-shapes/detect.ts
|
|
554
637
|
import { execFileSync } from "node:child_process";
|
|
555
|
-
import { readFileSync as
|
|
556
|
-
import { join as
|
|
638
|
+
import { readFileSync as readFileSync3, statSync as statSync3 } from "node:fs";
|
|
639
|
+
import { join as join4 } from "node:path";
|
|
557
640
|
|
|
558
641
|
// packages/cli/src/legacy-shapes/registry.ts
|
|
559
642
|
var DECISION_BY_SHAPE_ID = {
|
|
@@ -586,16 +669,16 @@ function isDir(path) {
|
|
|
586
669
|
}
|
|
587
670
|
function readText(path) {
|
|
588
671
|
try {
|
|
589
|
-
return
|
|
672
|
+
return readFileSync3(path, "utf8");
|
|
590
673
|
} catch {
|
|
591
674
|
return null;
|
|
592
675
|
}
|
|
593
676
|
}
|
|
594
677
|
var LEGACY_DEFT_DIR = "deft";
|
|
595
678
|
function isFrameworkDeftDir(projectRoot) {
|
|
596
|
-
const deftDir =
|
|
679
|
+
const deftDir = join4(projectRoot, LEGACY_DEFT_DIR);
|
|
597
680
|
if (!isDir(deftDir)) return false;
|
|
598
|
-
return isFile(
|
|
681
|
+
return isFile(join4(deftDir, "VERSION")) || isFile(join4(deftDir, "main.md")) || isFile(join4(deftDir, "Taskfile.yml")) || isDir(join4(deftDir, "skills"));
|
|
599
682
|
}
|
|
600
683
|
function gitmodulesReferencesFramework(text) {
|
|
601
684
|
const normalized = text.replace(/\r\n/g, "\n").toLowerCase();
|
|
@@ -643,12 +726,12 @@ function resolveInstallShape(projectRoot) {
|
|
|
643
726
|
if (hasCore) {
|
|
644
727
|
return resolution("vendored-core-go", [".deft/core (copied-core evidence, no exact pin)"]);
|
|
645
728
|
}
|
|
646
|
-
if (isFile(
|
|
729
|
+
if (isFile(join4(projectRoot, ".deft", "VERSION")) && !isDir(join4(projectRoot, ".deft", "core"))) {
|
|
647
730
|
return resolution("orphan-deft-version", [".deft/VERSION"]);
|
|
648
731
|
}
|
|
649
|
-
const deftDir =
|
|
732
|
+
const deftDir = join4(projectRoot, LEGACY_DEFT_DIR);
|
|
650
733
|
if (frameworkDeft) {
|
|
651
|
-
const submoduleGit = isFile(
|
|
734
|
+
const submoduleGit = isFile(join4(deftDir, ".git")) || isDir(join4(deftDir, ".git"));
|
|
652
735
|
if (submoduleGit) {
|
|
653
736
|
if (isUnsafeSubmoduleGitlink(projectRoot)) {
|
|
654
737
|
return resolution(
|
|
@@ -661,7 +744,7 @@ function resolveInstallShape(projectRoot) {
|
|
|
661
744
|
}
|
|
662
745
|
return resolution("go-tarball-deft-root", ["deft/"]);
|
|
663
746
|
}
|
|
664
|
-
const gitmodulesPath =
|
|
747
|
+
const gitmodulesPath = join4(projectRoot, ".gitmodules");
|
|
665
748
|
if (isFile(gitmodulesPath)) {
|
|
666
749
|
const text = readText(gitmodulesPath);
|
|
667
750
|
if (text !== null && gitmodulesReferencesFramework(text)) {
|
|
@@ -699,8 +782,8 @@ function isL2RefusalDecision(decision) {
|
|
|
699
782
|
// packages/cli/src/pm.ts
|
|
700
783
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
701
784
|
import { createHash } from "node:crypto";
|
|
702
|
-
import { existsSync as
|
|
703
|
-
import { join as
|
|
785
|
+
import { existsSync as existsSync6, readFileSync as readFileSync4, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
786
|
+
import { join as join5 } from "node:path";
|
|
704
787
|
var PARTIAL_CHANGES_MAY_REMAIN = "Partial changes may remain.";
|
|
705
788
|
var INSTALL_SCRIPT_POLICY_PLAN_LINE = "install-script policy: PM exact-add uses --ignore-scripts (pin/wiring do not require package lifecycle scripts); project registry, authentication, proxy, and lockfile settings are honoured";
|
|
706
789
|
var EXACT_SEMVER_RE = /^\d+\.\d+\.\d+([-+][0-9A-Za-z.-]+)?$/;
|
|
@@ -714,7 +797,7 @@ function isPrereleaseVersion(version) {
|
|
|
714
797
|
}
|
|
715
798
|
function readJsonObject2(path) {
|
|
716
799
|
try {
|
|
717
|
-
const raw =
|
|
800
|
+
const raw = readFileSync4(path, "utf8");
|
|
718
801
|
const parsed = JSON.parse(raw);
|
|
719
802
|
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
720
803
|
return parsed;
|
|
@@ -733,14 +816,14 @@ function parsePmNameToken(raw) {
|
|
|
733
816
|
return { kind: "unsupported", name };
|
|
734
817
|
}
|
|
735
818
|
function readPackageManagerField(projectRoot) {
|
|
736
|
-
const pkg = readJsonObject2(
|
|
819
|
+
const pkg = readJsonObject2(join5(projectRoot, "package.json"));
|
|
737
820
|
if (pkg === null) return { kind: "absent" };
|
|
738
821
|
const raw = pkg.packageManager;
|
|
739
822
|
if (typeof raw !== "string" || raw.trim() === "") return { kind: "absent" };
|
|
740
823
|
return parsePmNameToken(raw);
|
|
741
824
|
}
|
|
742
825
|
function readDevEnginesPackageManager(projectRoot) {
|
|
743
|
-
const pkg = readJsonObject2(
|
|
826
|
+
const pkg = readJsonObject2(join5(projectRoot, "package.json"));
|
|
744
827
|
if (pkg === null) return { kind: "absent" };
|
|
745
828
|
const devEngines = pkg.devEngines;
|
|
746
829
|
if (devEngines === null || typeof devEngines !== "object" || Array.isArray(devEngines)) {
|
|
@@ -790,8 +873,8 @@ function readDeclaredPackageManagerSlot(projectRoot) {
|
|
|
790
873
|
return { kind: "absent" };
|
|
791
874
|
}
|
|
792
875
|
function detectPackageManager(projectRoot, flag) {
|
|
793
|
-
const hasYarn =
|
|
794
|
-
const hasBun =
|
|
876
|
+
const hasYarn = existsSync6(join5(projectRoot, "yarn.lock"));
|
|
877
|
+
const hasBun = existsSync6(join5(projectRoot, "bun.lock")) || existsSync6(join5(projectRoot, "bun.lockb"));
|
|
795
878
|
if (hasYarn) {
|
|
796
879
|
return {
|
|
797
880
|
ok: false,
|
|
@@ -822,8 +905,8 @@ function detectPackageManager(projectRoot, flag) {
|
|
|
822
905
|
};
|
|
823
906
|
}
|
|
824
907
|
}
|
|
825
|
-
const hasPnpmLock =
|
|
826
|
-
const hasNpmLock =
|
|
908
|
+
const hasPnpmLock = existsSync6(join5(projectRoot, "pnpm-lock.yaml"));
|
|
909
|
+
const hasNpmLock = existsSync6(join5(projectRoot, "package-lock.json"));
|
|
827
910
|
const fieldPm = declared.kind === "supported" ? declared.pm : null;
|
|
828
911
|
const fieldEvidence = declared.kind === "supported" ? declared.evidence : null;
|
|
829
912
|
if (hasPnpmLock && hasNpmLock) {
|
|
@@ -915,16 +998,16 @@ function npmRootRequest(packages) {
|
|
|
915
998
|
}
|
|
916
999
|
function lockfileRecordsExactPin(projectRoot, exactVersion, pm) {
|
|
917
1000
|
if (pm === "pnpm") {
|
|
918
|
-
const pnpmLock =
|
|
919
|
-
if (!
|
|
1001
|
+
const pnpmLock = join5(projectRoot, "pnpm-lock.yaml");
|
|
1002
|
+
if (!existsSync6(pnpmLock)) return false;
|
|
920
1003
|
try {
|
|
921
|
-
return pnpmRootRecordsExactPin(
|
|
1004
|
+
return pnpmRootRecordsExactPin(readFileSync4(pnpmLock, "utf8"), exactVersion);
|
|
922
1005
|
} catch {
|
|
923
1006
|
return false;
|
|
924
1007
|
}
|
|
925
1008
|
}
|
|
926
|
-
const npmLock =
|
|
927
|
-
if (!
|
|
1009
|
+
const npmLock = join5(projectRoot, "package-lock.json");
|
|
1010
|
+
if (!existsSync6(npmLock)) return false;
|
|
928
1011
|
const lock = readJsonObject2(npmLock);
|
|
929
1012
|
if (lock === null) return false;
|
|
930
1013
|
const packages = lock.packages;
|
|
@@ -941,17 +1024,17 @@ function lockfileRecordsExactPin(projectRoot, exactVersion, pm) {
|
|
|
941
1024
|
return false;
|
|
942
1025
|
}
|
|
943
1026
|
function ensurePackageJson(projectRoot) {
|
|
944
|
-
const path =
|
|
945
|
-
if (
|
|
1027
|
+
const path = join5(projectRoot, "package.json");
|
|
1028
|
+
if (existsSync6(path)) {
|
|
946
1029
|
const existing = readJsonObject2(path);
|
|
947
1030
|
if (existing !== null && Object.keys(existing).length === 0) {
|
|
948
|
-
|
|
1031
|
+
writeFileSync2(path, `${JSON.stringify({ private: true }, null, 2)}
|
|
949
1032
|
`);
|
|
950
1033
|
return { created: true, path };
|
|
951
1034
|
}
|
|
952
1035
|
return { created: false, path };
|
|
953
1036
|
}
|
|
954
|
-
|
|
1037
|
+
writeFileSync2(path, `${JSON.stringify({ private: true }, null, 2)}
|
|
955
1038
|
`);
|
|
956
1039
|
return { created: true, path };
|
|
957
1040
|
}
|
|
@@ -962,7 +1045,7 @@ function versionFromPmToken(raw) {
|
|
|
962
1045
|
return ver.length > 0 ? ver : null;
|
|
963
1046
|
}
|
|
964
1047
|
function readDeclaredPackageManagerVersion(projectRoot) {
|
|
965
|
-
const pkg = readJsonObject2(
|
|
1048
|
+
const pkg = readJsonObject2(join5(projectRoot, "package.json"));
|
|
966
1049
|
if (pkg === null) return null;
|
|
967
1050
|
if (typeof pkg.packageManager === "string" && pkg.packageManager.trim() !== "") {
|
|
968
1051
|
const fromField = versionFromPmToken(pkg.packageManager.trim());
|
|
@@ -995,6 +1078,16 @@ To make ${pm} available:
|
|
|
995
1078
|
- Or install ${pm} yourself and ensure its directory is on PATH
|
|
996
1079
|
Directive does not install, upgrade, or switch package managers.`;
|
|
997
1080
|
}
|
|
1081
|
+
function isPnpmIgnoredBuildsFailure(text) {
|
|
1082
|
+
return /ERR_PNPM_IGNORED_BUILDS/i.test(text);
|
|
1083
|
+
}
|
|
1084
|
+
function formatPnpmIgnoredBuildsRecovery() {
|
|
1085
|
+
return `pnpm refused dependency builds (ERR_PNPM_IGNORED_BUILDS).
|
|
1086
|
+
Recover with pnpm's own policy tools \u2014 Directive does not write allowBuilds:
|
|
1087
|
+
- Run: pnpm approve-builds
|
|
1088
|
+
- Or set a real true/false under allowBuilds in pnpm-workspace.yaml
|
|
1089
|
+
Do not commit pnpm's interactive placeholder text.`;
|
|
1090
|
+
}
|
|
998
1091
|
function ensurePackageManagerAvailable(pm, env = process.env, declaredVersion = null, projectRoot) {
|
|
999
1092
|
const result = spawnSync4(pm, ["--version"], {
|
|
1000
1093
|
...projectRoot !== void 0 ? { cwd: projectRoot } : {},
|
|
@@ -1021,9 +1114,9 @@ function ensurePackageManagerAvailable(pm, env = process.env, declaredVersion =
|
|
|
1021
1114
|
return { ok: true };
|
|
1022
1115
|
}
|
|
1023
1116
|
function fileDigest(absPath) {
|
|
1024
|
-
if (!
|
|
1117
|
+
if (!existsSync6(absPath)) return null;
|
|
1025
1118
|
try {
|
|
1026
|
-
return createHash("sha256").update(
|
|
1119
|
+
return createHash("sha256").update(readFileSync4(absPath)).digest("hex");
|
|
1027
1120
|
} catch {
|
|
1028
1121
|
return null;
|
|
1029
1122
|
}
|
|
@@ -1042,7 +1135,7 @@ function planCriticalRelPaths(_pm) {
|
|
|
1042
1135
|
function fingerprintPlanCriticalFiles(projectRoot, pm) {
|
|
1043
1136
|
const entries = planCriticalRelPaths(pm).map((relPath) => ({
|
|
1044
1137
|
relPath,
|
|
1045
|
-
digest: fileDigest(
|
|
1138
|
+
digest: fileDigest(join5(projectRoot, relPath))
|
|
1046
1139
|
}));
|
|
1047
1140
|
return { entries };
|
|
1048
1141
|
}
|
|
@@ -1092,7 +1185,7 @@ function interpretPmSpawnResult(pm, args, result) {
|
|
|
1092
1185
|
return { ok: true };
|
|
1093
1186
|
}
|
|
1094
1187
|
function isPnpmWorkspaceRoot(projectRoot) {
|
|
1095
|
-
return
|
|
1188
|
+
return existsSync6(join5(projectRoot, "pnpm-workspace.yaml"));
|
|
1096
1189
|
}
|
|
1097
1190
|
function buildPmExactAddArgs(pm, version, projectRoot) {
|
|
1098
1191
|
const spec = `${RUNTIME_PACKAGE_NAME}@${version}`;
|
|
@@ -1116,7 +1209,7 @@ var RETIRED_DIRECTIVE_PACKAGE_NAMES = [
|
|
|
1116
1209
|
"@deftai/directive-types"
|
|
1117
1210
|
];
|
|
1118
1211
|
function removeLegacyDirectivePackages(projectRoot) {
|
|
1119
|
-
const path =
|
|
1212
|
+
const path = join5(projectRoot, "package.json");
|
|
1120
1213
|
const pkg = readJsonObject2(path);
|
|
1121
1214
|
if (pkg === null) return false;
|
|
1122
1215
|
let removed = false;
|
|
@@ -1134,7 +1227,7 @@ function removeLegacyDirectivePackages(projectRoot) {
|
|
|
1134
1227
|
}
|
|
1135
1228
|
}
|
|
1136
1229
|
if (!removed) return false;
|
|
1137
|
-
|
|
1230
|
+
writeFileSync2(path, `${JSON.stringify(pkg, null, 2)}
|
|
1138
1231
|
`);
|
|
1139
1232
|
return true;
|
|
1140
1233
|
}
|
|
@@ -1156,11 +1249,11 @@ function lockfileReferencesRetiredDirective(contents) {
|
|
|
1156
1249
|
function purgeRetiredDirectiveLockfiles(projectRoot) {
|
|
1157
1250
|
const purged = [];
|
|
1158
1251
|
for (const rel of LOCKFILE_CANDIDATES) {
|
|
1159
|
-
const abs =
|
|
1160
|
-
if (!
|
|
1252
|
+
const abs = join5(projectRoot, rel);
|
|
1253
|
+
if (!existsSync6(abs)) continue;
|
|
1161
1254
|
let contents;
|
|
1162
1255
|
try {
|
|
1163
|
-
contents =
|
|
1256
|
+
contents = readFileSync4(abs, "utf8");
|
|
1164
1257
|
} catch {
|
|
1165
1258
|
continue;
|
|
1166
1259
|
}
|
|
@@ -2198,14 +2291,14 @@ function resolvePublishedContract(version, env = process.env, projectRoot) {
|
|
|
2198
2291
|
// packages/cli/src/uninstall-map.ts
|
|
2199
2292
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
2200
2293
|
import {
|
|
2201
|
-
existsSync as
|
|
2294
|
+
existsSync as existsSync7,
|
|
2202
2295
|
readdirSync,
|
|
2203
|
-
readFileSync as
|
|
2296
|
+
readFileSync as readFileSync5,
|
|
2204
2297
|
realpathSync as realpathSync2,
|
|
2205
2298
|
rmSync,
|
|
2206
|
-
writeFileSync as
|
|
2299
|
+
writeFileSync as writeFileSync3
|
|
2207
2300
|
} from "node:fs";
|
|
2208
|
-
import { dirname, isAbsolute as isAbsolute2, join as
|
|
2301
|
+
import { dirname, isAbsolute as isAbsolute2, join as join6, normalize, relative, resolve as resolve2, sep } from "node:path";
|
|
2209
2302
|
var MANAGED_OPEN = "<!-- deft:managed-section";
|
|
2210
2303
|
var MANAGED_CLOSE = "<!-- /deft:managed-section -->";
|
|
2211
2304
|
var RUNTIME_PREFIX = "node_modules/@deftai/directive-runtime/";
|
|
@@ -2237,14 +2330,14 @@ var HOST_HOOK_RELS = [
|
|
|
2237
2330
|
];
|
|
2238
2331
|
function readText2(path) {
|
|
2239
2332
|
try {
|
|
2240
|
-
return
|
|
2333
|
+
return readFileSync5(path, "utf8");
|
|
2241
2334
|
} catch {
|
|
2242
2335
|
return null;
|
|
2243
2336
|
}
|
|
2244
2337
|
}
|
|
2245
2338
|
function readJsonObject3(path) {
|
|
2246
2339
|
try {
|
|
2247
|
-
const raw =
|
|
2340
|
+
const raw = readFileSync5(path, "utf8");
|
|
2248
2341
|
const parsed = JSON.parse(raw);
|
|
2249
2342
|
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
2250
2343
|
return parsed;
|
|
@@ -2253,7 +2346,7 @@ function readJsonObject3(path) {
|
|
|
2253
2346
|
}
|
|
2254
2347
|
}
|
|
2255
2348
|
function pkgHasDep(projectRoot, name) {
|
|
2256
|
-
const pkg = readJsonObject3(
|
|
2349
|
+
const pkg = readJsonObject3(join6(projectRoot, "package.json"));
|
|
2257
2350
|
if (pkg === null) return false;
|
|
2258
2351
|
for (const key of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
2259
2352
|
const block = pkg[key];
|
|
@@ -2305,18 +2398,18 @@ function safeWriteText(projectRoot, rel, body) {
|
|
|
2305
2398
|
const abs = resolve2(projectRoot, rel);
|
|
2306
2399
|
if (!isPathInsideProjectRoot(projectRoot, abs)) return false;
|
|
2307
2400
|
try {
|
|
2308
|
-
|
|
2401
|
+
writeFileSync3(abs, body);
|
|
2309
2402
|
return true;
|
|
2310
2403
|
} catch {
|
|
2311
2404
|
return false;
|
|
2312
2405
|
}
|
|
2313
2406
|
}
|
|
2314
2407
|
function parseOwnershipArtifacts(projectRoot) {
|
|
2315
|
-
const path =
|
|
2316
|
-
if (!
|
|
2408
|
+
const path = join6(projectRoot, ".deft", "GENERATION.json");
|
|
2409
|
+
if (!existsSync7(path)) return { inspection: "absent", artifacts: [], rejected: [] };
|
|
2317
2410
|
let parsed;
|
|
2318
2411
|
try {
|
|
2319
|
-
parsed = JSON.parse(
|
|
2412
|
+
parsed = JSON.parse(readFileSync5(path, "utf8"));
|
|
2320
2413
|
} catch {
|
|
2321
2414
|
return { inspection: "unreadable", artifacts: [], rejected: [] };
|
|
2322
2415
|
}
|
|
@@ -2373,8 +2466,8 @@ function isOurGitHook(rel, body) {
|
|
|
2373
2466
|
return body.includes("_directive-run.sh") || body.includes("_deft-run.sh") || body.includes(RUNTIME_PREFIX) || /\brun_deft\s+(verify:|preflight)/.test(body);
|
|
2374
2467
|
}
|
|
2375
2468
|
function listWiringReady(projectRoot) {
|
|
2376
|
-
const dir =
|
|
2377
|
-
if (!
|
|
2469
|
+
const dir = join6(projectRoot, ".deft", "directive");
|
|
2470
|
+
if (!existsSync7(dir)) return [];
|
|
2378
2471
|
try {
|
|
2379
2472
|
return readdirSync(dir).filter((n) => n.startsWith("wiring-ready.") && n.endsWith(".json")).map((n) => `.deft/directive/${n}`);
|
|
2380
2473
|
} catch {
|
|
@@ -2388,35 +2481,35 @@ function discoverKnownArtifacts(projectRoot) {
|
|
|
2388
2481
|
out.push(art);
|
|
2389
2482
|
}
|
|
2390
2483
|
};
|
|
2391
|
-
if (
|
|
2484
|
+
if (existsSync7(join6(projectRoot, ".deft", "GENERATION.json"))) {
|
|
2392
2485
|
push({ path: ".deft/GENERATION.json", kind: "whole-file", source: "known-map" });
|
|
2393
2486
|
}
|
|
2394
2487
|
for (const rel of listWiringReady(projectRoot)) {
|
|
2395
2488
|
push({ path: rel, kind: "whole-file", source: "known-map" });
|
|
2396
2489
|
}
|
|
2397
|
-
if (
|
|
2490
|
+
if (existsSync7(join6(projectRoot, ".deft", "directive", "data-schema.json"))) {
|
|
2398
2491
|
push({
|
|
2399
2492
|
path: ".deft/directive/data-schema.json",
|
|
2400
2493
|
kind: "whole-file",
|
|
2401
2494
|
source: "known-map"
|
|
2402
2495
|
});
|
|
2403
2496
|
}
|
|
2404
|
-
if (
|
|
2497
|
+
if (existsSync7(join6(projectRoot, ".deft", "core"))) {
|
|
2405
2498
|
push({ path: ".deft/core", kind: "whole-file", source: "known-map" });
|
|
2406
2499
|
}
|
|
2407
2500
|
for (const rel of GITHOOK_RELS) {
|
|
2408
|
-
const body = readText2(
|
|
2501
|
+
const body = readText2(join6(projectRoot, rel));
|
|
2409
2502
|
if (body !== null && isOurGitHook(rel, body)) {
|
|
2410
2503
|
push({ path: rel, kind: "whole-file", source: "known-map" });
|
|
2411
2504
|
}
|
|
2412
2505
|
}
|
|
2413
2506
|
for (const rel of skillPointerRels()) {
|
|
2414
|
-
const body = readText2(
|
|
2507
|
+
const body = readText2(join6(projectRoot, rel));
|
|
2415
2508
|
if (body !== null && isOurSkillPointer(body)) {
|
|
2416
2509
|
push({ path: rel, kind: "whole-file", source: "known-map" });
|
|
2417
2510
|
}
|
|
2418
2511
|
}
|
|
2419
|
-
const agents = readText2(
|
|
2512
|
+
const agents = readText2(join6(projectRoot, "AGENTS.md"));
|
|
2420
2513
|
if (agents !== null && agents.includes(MANAGED_OPEN)) {
|
|
2421
2514
|
push({
|
|
2422
2515
|
path: "AGENTS.md",
|
|
@@ -2426,7 +2519,7 @@ function discoverKnownArtifacts(projectRoot) {
|
|
|
2426
2519
|
});
|
|
2427
2520
|
}
|
|
2428
2521
|
for (const rel of HOST_HOOK_RELS) {
|
|
2429
|
-
if (
|
|
2522
|
+
if (existsSync7(join6(projectRoot, rel))) {
|
|
2430
2523
|
push({
|
|
2431
2524
|
path: rel,
|
|
2432
2525
|
kind: "structured-entry",
|
|
@@ -2435,7 +2528,7 @@ function discoverKnownArtifacts(projectRoot) {
|
|
|
2435
2528
|
});
|
|
2436
2529
|
}
|
|
2437
2530
|
}
|
|
2438
|
-
const taskfile = readText2(
|
|
2531
|
+
const taskfile = readText2(join6(projectRoot, "Taskfile.yml"));
|
|
2439
2532
|
if (taskfile !== null && (taskfile.includes(`${RUNTIME_PREFIX}Taskfile.yml`) || taskfile.includes(".deft/core/Taskfile.yml") || /(^|\n)[ \t]*deft:\s*(\n|$)/.test(taskfile))) {
|
|
2440
2533
|
push({
|
|
2441
2534
|
path: "Taskfile.yml",
|
|
@@ -2444,10 +2537,10 @@ function discoverKnownArtifacts(projectRoot) {
|
|
|
2444
2537
|
source: "known-map"
|
|
2445
2538
|
});
|
|
2446
2539
|
}
|
|
2447
|
-
if (
|
|
2540
|
+
if (existsSync7(join6(projectRoot, "xbrief"))) {
|
|
2448
2541
|
push({ path: "xbrief", kind: "retained", source: "known-map" });
|
|
2449
2542
|
}
|
|
2450
|
-
if (
|
|
2543
|
+
if (existsSync7(join6(projectRoot, ".deft", "settings.json"))) {
|
|
2451
2544
|
push({ path: ".deft/settings.json", kind: "retained", source: "known-map" });
|
|
2452
2545
|
}
|
|
2453
2546
|
return out;
|
|
@@ -2471,9 +2564,9 @@ function discoverUninstallFootprint(projectRoot) {
|
|
|
2471
2564
|
const artifacts = mergeArtifacts(fromRecord, fromKnown);
|
|
2472
2565
|
const hasRuntimePin = pkgHasDep(projectRoot, RUNTIME_PACKAGE_NAME);
|
|
2473
2566
|
const hasLegacyLauncherPin = pkgHasDep(projectRoot, LAUNCHER_PACKAGE_NAME);
|
|
2474
|
-
const hasLegacyCore =
|
|
2567
|
+
const hasLegacyCore = existsSync7(join6(projectRoot, ".deft", "core"));
|
|
2475
2568
|
const removable = artifacts.some((a) => a.kind !== "retained");
|
|
2476
|
-
const hasFootprint = removable || hasRuntimePin || hasLegacyLauncherPin || hasLegacyCore ||
|
|
2569
|
+
const hasFootprint = removable || hasRuntimePin || hasLegacyLauncherPin || hasLegacyCore || existsSync7(join6(projectRoot, ".deft", "GENERATION.json"));
|
|
2477
2570
|
return {
|
|
2478
2571
|
artifacts,
|
|
2479
2572
|
ownershipInspection: inspection,
|
|
@@ -2549,7 +2642,7 @@ function safeUnlink(projectRoot, rel) {
|
|
|
2549
2642
|
if (!isSafeOwnershipRelPath(rel)) return false;
|
|
2550
2643
|
const abs = resolve2(projectRoot, rel);
|
|
2551
2644
|
if (!isPathInsideProjectRoot(projectRoot, abs)) return false;
|
|
2552
|
-
if (!
|
|
2645
|
+
if (!existsSync7(abs)) return false;
|
|
2553
2646
|
try {
|
|
2554
2647
|
if (!isPathInsideProjectRoot(projectRoot, abs)) return false;
|
|
2555
2648
|
rmSync(abs, { recursive: true, force: true });
|
|
@@ -2562,8 +2655,8 @@ function maybeRemoveEmptyParents(projectRoot, relFile) {
|
|
|
2562
2655
|
const removed = [];
|
|
2563
2656
|
let dir = dirname(relFile);
|
|
2564
2657
|
while (dir && dir !== "." && dir !== "/") {
|
|
2565
|
-
const abs =
|
|
2566
|
-
if (!
|
|
2658
|
+
const abs = join6(projectRoot, dir);
|
|
2659
|
+
if (!existsSync7(abs)) break;
|
|
2567
2660
|
try {
|
|
2568
2661
|
const entries = readdirSync(abs);
|
|
2569
2662
|
if (entries.length > 0) break;
|
|
@@ -2598,7 +2691,7 @@ function applyLauncherCleanup(projectRoot, discovery) {
|
|
|
2598
2691
|
});
|
|
2599
2692
|
for (const art of ordered) {
|
|
2600
2693
|
if (art.kind === "retained") {
|
|
2601
|
-
if (
|
|
2694
|
+
if (existsSync7(join6(projectRoot, art.path))) preserved.push(art.path);
|
|
2602
2695
|
continue;
|
|
2603
2696
|
}
|
|
2604
2697
|
if (art.kind === "marked-section") {
|
|
@@ -2631,8 +2724,8 @@ function applyLauncherCleanup(projectRoot, discovery) {
|
|
|
2631
2724
|
}
|
|
2632
2725
|
if (art.kind === "structured-entry") {
|
|
2633
2726
|
const abs = resolve2(projectRoot, art.path);
|
|
2634
|
-
if (!isPathInsideProjectRoot(projectRoot, abs) || !
|
|
2635
|
-
if (
|
|
2727
|
+
if (!isPathInsideProjectRoot(projectRoot, abs) || !existsSync7(abs)) {
|
|
2728
|
+
if (existsSync7(abs)) {
|
|
2636
2729
|
uncertainty.push(`skipped structured-entry outside project: ${art.path}`);
|
|
2637
2730
|
}
|
|
2638
2731
|
continue;
|
|
@@ -2671,7 +2764,7 @@ function applyLauncherCleanup(projectRoot, discovery) {
|
|
|
2671
2764
|
continue;
|
|
2672
2765
|
}
|
|
2673
2766
|
if (art.path === "Taskfile.yml") {
|
|
2674
|
-
const body = readText2(
|
|
2767
|
+
const body = readText2(join6(projectRoot, art.path));
|
|
2675
2768
|
if (body !== null) {
|
|
2676
2769
|
const { next, removed: did } = stripTaskfileDeftInclude(body);
|
|
2677
2770
|
if (did) {
|
|
@@ -2719,7 +2812,7 @@ function applyLauncherCleanup(projectRoot, discovery) {
|
|
|
2719
2812
|
}
|
|
2720
2813
|
for (const rel of [...GITHOOK_RELS, ...skillPointerRels(), ...listWiringReady(projectRoot)]) {
|
|
2721
2814
|
if (removed.includes(rel)) continue;
|
|
2722
|
-
const body = rel.includes("SKILL.md") ? readText2(
|
|
2815
|
+
const body = rel.includes("SKILL.md") ? readText2(join6(projectRoot, rel)) : rel.startsWith(".githooks/") ? readText2(join6(projectRoot, rel)) : existsSync7(join6(projectRoot, rel)) ? "yes" : null;
|
|
2723
2816
|
if (body === null) continue;
|
|
2724
2817
|
if (rel.includes("SKILL.md") && !isOurSkillPointer(body)) continue;
|
|
2725
2818
|
if (rel.startsWith(".githooks/") && !isOurGitHook(rel, body)) continue;
|
|
@@ -2728,17 +2821,17 @@ function applyLauncherCleanup(projectRoot, discovery) {
|
|
|
2728
2821
|
removed.push(...maybeRemoveEmptyParents(projectRoot, rel));
|
|
2729
2822
|
}
|
|
2730
2823
|
}
|
|
2731
|
-
if (
|
|
2824
|
+
if (existsSync7(join6(projectRoot, ".deft", "core"))) {
|
|
2732
2825
|
if (safeUnlink(projectRoot, ".deft/core")) removed.push(".deft/core");
|
|
2733
2826
|
else leftovers.push(".deft/core");
|
|
2734
2827
|
}
|
|
2735
|
-
if (
|
|
2828
|
+
if (existsSync7(join6(projectRoot, ".deft", "directive", "data-schema.json"))) {
|
|
2736
2829
|
if (safeUnlink(projectRoot, ".deft/directive/data-schema.json")) {
|
|
2737
2830
|
removed.push(".deft/directive/data-schema.json");
|
|
2738
2831
|
}
|
|
2739
2832
|
}
|
|
2740
|
-
const directiveDir =
|
|
2741
|
-
if (
|
|
2833
|
+
const directiveDir = join6(projectRoot, ".deft", "directive");
|
|
2834
|
+
if (existsSync7(directiveDir)) {
|
|
2742
2835
|
try {
|
|
2743
2836
|
const left = readdirSync(directiveDir);
|
|
2744
2837
|
if (left.length === 0) {
|
|
@@ -2750,13 +2843,13 @@ function applyLauncherCleanup(projectRoot, discovery) {
|
|
|
2750
2843
|
} catch {
|
|
2751
2844
|
}
|
|
2752
2845
|
}
|
|
2753
|
-
if (
|
|
2846
|
+
if (existsSync7(join6(projectRoot, ".deft", "GENERATION.json"))) {
|
|
2754
2847
|
if (safeUnlink(projectRoot, ".deft/GENERATION.json")) removed.push(".deft/GENERATION.json");
|
|
2755
2848
|
}
|
|
2756
|
-
if (
|
|
2849
|
+
if (existsSync7(join6(projectRoot, "xbrief")) && !preserved.includes("xbrief")) {
|
|
2757
2850
|
preserved.push("xbrief");
|
|
2758
2851
|
}
|
|
2759
|
-
if (
|
|
2852
|
+
if (existsSync7(join6(projectRoot, ".deft", "settings.json")) && !preserved.includes(".deft/settings.json")) {
|
|
2760
2853
|
preserved.push(".deft/settings.json");
|
|
2761
2854
|
}
|
|
2762
2855
|
return {
|
|
@@ -2783,11 +2876,11 @@ function listLinkedWorktreePaths(projectRoot) {
|
|
|
2783
2876
|
}
|
|
2784
2877
|
}
|
|
2785
2878
|
function siblingNeedsHooksPath(projectRoot) {
|
|
2786
|
-
const rootResolved =
|
|
2879
|
+
const rootResolved = join6(projectRoot);
|
|
2787
2880
|
for (const wt of listLinkedWorktreePaths(projectRoot)) {
|
|
2788
|
-
if (
|
|
2789
|
-
if (
|
|
2790
|
-
if (
|
|
2881
|
+
if (join6(wt) === rootResolved) continue;
|
|
2882
|
+
if (existsSync7(join6(wt, ".githooks", "_directive-run.sh"))) return true;
|
|
2883
|
+
if (existsSync7(join6(wt, ".deft", "GENERATION.json"))) return true;
|
|
2791
2884
|
}
|
|
2792
2885
|
return false;
|
|
2793
2886
|
}
|
|
@@ -2818,17 +2911,17 @@ function cleanupHooksPath(projectRoot) {
|
|
|
2818
2911
|
}
|
|
2819
2912
|
function verifyUninstallComplete(projectRoot) {
|
|
2820
2913
|
const leftovers = [];
|
|
2821
|
-
if (
|
|
2914
|
+
if (existsSync7(join6(projectRoot, ".deft", "GENERATION.json"))) {
|
|
2822
2915
|
leftovers.push(".deft/GENERATION.json");
|
|
2823
2916
|
}
|
|
2824
|
-
if (
|
|
2917
|
+
if (existsSync7(join6(projectRoot, ".deft", "core"))) {
|
|
2825
2918
|
leftovers.push(".deft/core");
|
|
2826
2919
|
}
|
|
2827
2920
|
for (const rel of GITHOOK_RELS) {
|
|
2828
|
-
const body = readText2(
|
|
2921
|
+
const body = readText2(join6(projectRoot, rel));
|
|
2829
2922
|
if (body !== null && isOurGitHook(rel, body)) leftovers.push(rel);
|
|
2830
2923
|
}
|
|
2831
|
-
const agents = readText2(
|
|
2924
|
+
const agents = readText2(join6(projectRoot, "AGENTS.md"));
|
|
2832
2925
|
if (agents !== null && agents.includes(MANAGED_OPEN)) {
|
|
2833
2926
|
leftovers.push("AGENTS.md#marked-section");
|
|
2834
2927
|
}
|
|
@@ -2940,6 +3033,12 @@ function reportPmFailure(io, add) {
|
|
|
2940
3033
|
`);
|
|
2941
3034
|
if (add.stderr) io.writeErr(`${add.stderr}
|
|
2942
3035
|
`);
|
|
3036
|
+
const blob = `${add.message}
|
|
3037
|
+
${add.stderr ?? ""}`;
|
|
3038
|
+
if (isPnpmIgnoredBuildsFailure(blob)) {
|
|
3039
|
+
io.writeErr(`${formatPnpmIgnoredBuildsRecovery()}
|
|
3040
|
+
`);
|
|
3041
|
+
}
|
|
2943
3042
|
if (add.interrupted) {
|
|
2944
3043
|
if (!/partial changes may remain/i.test(add.message)) {
|
|
2945
3044
|
io.writeErr(`${PARTIAL_CHANGES_MAY_REMAIN}
|
|
@@ -2958,7 +3057,7 @@ function resolveLineReader(deps) {
|
|
|
2958
3057
|
}
|
|
2959
3058
|
function shouldDefaultToRepair(projectRoot, state) {
|
|
2960
3059
|
if (state.installed === null) return true;
|
|
2961
|
-
return !
|
|
3060
|
+
return !existsSync8(join7(projectRoot, ".deft", "GENERATION.json"));
|
|
2962
3061
|
}
|
|
2963
3062
|
function printConfiguredMenu(io, opts) {
|
|
2964
3063
|
const repairMarker = opts.defaultChoice === "repair" ? ">" : " ";
|
|
@@ -3149,7 +3248,7 @@ function runFirstInstall(projectRoot, state, flags, launcherVersion, io, deps, e
|
|
|
3149
3248
|
}
|
|
3150
3249
|
targetVersion = resolved.version;
|
|
3151
3250
|
}
|
|
3152
|
-
const willCreatePkg = !
|
|
3251
|
+
const willCreatePkg = !existsSync8(join7(projectRoot, "package.json"));
|
|
3153
3252
|
const pmCmd = formatPmExactAddCommand(pmDetect.pm, targetVersion, projectRoot);
|
|
3154
3253
|
presentFirstInstallPlan(io, {
|
|
3155
3254
|
projectRoot,
|
|
@@ -3158,10 +3257,12 @@ function runFirstInstall(projectRoot, state, flags, launcherVersion, io, deps, e
|
|
|
3158
3257
|
version: targetVersion,
|
|
3159
3258
|
pmCommand: pmCmd,
|
|
3160
3259
|
willCreatePkg,
|
|
3161
|
-
gitHooksInactive: !
|
|
3260
|
+
gitHooksInactive: !existsSync8(join7(projectRoot, ".git")),
|
|
3162
3261
|
nodeWarning: checkNodeVersion(deps.nodeVersion).warning ?? null,
|
|
3163
3262
|
verbosity: flags.verbosity
|
|
3164
3263
|
});
|
|
3264
|
+
const ageExcludeHeal = pmDetect.pm === "pnpm" ? previewRuntimeAgeExcludeHeal(projectRoot, targetVersion) : null;
|
|
3265
|
+
if (ageExcludeHeal !== null) io.writeOut(formatAgeExcludeHealLine(ageExcludeHeal, targetVersion));
|
|
3165
3266
|
const planFp = fingerprintPlanCriticalFiles(projectRoot, pmDetect.pm);
|
|
3166
3267
|
if (flags.dryRun) {
|
|
3167
3268
|
io.writeOut("[dry-run] no changes made.\n");
|
|
@@ -3175,7 +3276,12 @@ function runFirstInstall(projectRoot, state, flags, launcherVersion, io, deps, e
|
|
|
3175
3276
|
ensurePackageJson(projectRoot);
|
|
3176
3277
|
io.writeOut('Created package.json { "private": true }\n');
|
|
3177
3278
|
}
|
|
3178
|
-
const add =
|
|
3279
|
+
const add = addWithRuntimeAgeExcludeHeal(
|
|
3280
|
+
projectRoot,
|
|
3281
|
+
pmDetect.pm,
|
|
3282
|
+
targetVersion,
|
|
3283
|
+
() => deps.runPmAdd?.({ projectRoot, pm: pmDetect.pm, version: targetVersion }) ?? runPmExactAdd({ projectRoot, pm: pmDetect.pm, version: targetVersion, env })
|
|
3284
|
+
);
|
|
3179
3285
|
if (!add.ok) {
|
|
3180
3286
|
return reportPmFailure(io, add);
|
|
3181
3287
|
}
|
|
@@ -3248,10 +3354,12 @@ function runRepair(projectRoot, state, flags, launcherVersion, io, deps, env) {
|
|
|
3248
3354
|
needsPmRestore,
|
|
3249
3355
|
pmCommand: needsPmRestore ? pmCmd : null,
|
|
3250
3356
|
restoreReason: needsPmRestore ? restoreReason : null,
|
|
3251
|
-
gitHooksInactive: !
|
|
3357
|
+
gitHooksInactive: !existsSync8(join7(projectRoot, ".git")),
|
|
3252
3358
|
nodeWarning: checkNodeVersion(deps.nodeVersion).warning ?? null,
|
|
3253
3359
|
verbosity: flags.verbosity
|
|
3254
3360
|
});
|
|
3361
|
+
const ageExcludeHeal = pmDetect.pm === "pnpm" ? previewRuntimeAgeExcludeHeal(projectRoot, pinVersion) : null;
|
|
3362
|
+
if (ageExcludeHeal !== null) io.writeOut(formatAgeExcludeHealLine(ageExcludeHeal, pinVersion));
|
|
3255
3363
|
const planFp = fingerprintPlanCriticalFiles(projectRoot, pmDetect.pm);
|
|
3256
3364
|
if (flags.dryRun) {
|
|
3257
3365
|
io.writeOut("[dry-run] no changes made.\n");
|
|
@@ -3266,8 +3374,14 @@ function runRepair(projectRoot, state, flags, launcherVersion, io, deps, env) {
|
|
|
3266
3374
|
if (approval !== null) return approval;
|
|
3267
3375
|
const stale = assertPlanStillValid(projectRoot, pmDetect.pm, planFp, io);
|
|
3268
3376
|
if (stale !== null) return stale;
|
|
3377
|
+
if (pmDetect.pm === "pnpm") healRuntimeAgeExclude(projectRoot, pinVersion);
|
|
3269
3378
|
if (needsPmRestore) {
|
|
3270
|
-
const add =
|
|
3379
|
+
const add = addWithRuntimeAgeExcludeHeal(
|
|
3380
|
+
projectRoot,
|
|
3381
|
+
pmDetect.pm,
|
|
3382
|
+
pinVersion,
|
|
3383
|
+
() => deps.runPmAdd?.({ projectRoot, pm: pmDetect.pm, version: pinVersion }) ?? runPmExactAdd({ projectRoot, pm: pmDetect.pm, version: pinVersion, env })
|
|
3384
|
+
);
|
|
3271
3385
|
if (!add.ok) {
|
|
3272
3386
|
return reportPmFailure(io, add);
|
|
3273
3387
|
}
|
|
@@ -3396,14 +3510,14 @@ function handOffMigrate(opts) {
|
|
|
3396
3510
|
}
|
|
3397
3511
|
function isWiringCurrentForVersion(projectRoot, version) {
|
|
3398
3512
|
try {
|
|
3399
|
-
const genPath =
|
|
3400
|
-
if (!
|
|
3401
|
-
const genRaw = JSON.parse(
|
|
3513
|
+
const genPath = join7(projectRoot, ".deft", "GENERATION.json");
|
|
3514
|
+
if (!existsSync8(genPath)) return false;
|
|
3515
|
+
const genRaw = JSON.parse(readFileSync6(genPath, "utf8"));
|
|
3402
3516
|
if (genRaw === null || typeof genRaw !== "object" || Array.isArray(genRaw)) return false;
|
|
3403
3517
|
if (genRaw.runtimeVersion !== version) return false;
|
|
3404
|
-
const ready =
|
|
3405
|
-
if (!
|
|
3406
|
-
const bodyRaw = JSON.parse(
|
|
3518
|
+
const ready = join7(projectRoot, ".deft", "directive", `wiring-ready.${version}.json`);
|
|
3519
|
+
if (!existsSync8(ready)) return false;
|
|
3520
|
+
const bodyRaw = JSON.parse(readFileSync6(ready, "utf8"));
|
|
3407
3521
|
if (bodyRaw === null || typeof bodyRaw !== "object" || Array.isArray(bodyRaw)) return false;
|
|
3408
3522
|
const bodyVersion = bodyRaw.runtimeVersion;
|
|
3409
3523
|
if (bodyVersion !== void 0 && bodyVersion !== version) return false;
|
|
@@ -3596,10 +3710,12 @@ function runUpgrade(projectRoot, state, argv, launcherVersion, io = defaultIo(),
|
|
|
3596
3710
|
needMigrate,
|
|
3597
3711
|
oldStyle: state.oldStyle,
|
|
3598
3712
|
convertShapeId: convertViaRemovals ? upgradeShape?.shapeId : null,
|
|
3599
|
-
gitHooksInactive: !
|
|
3713
|
+
gitHooksInactive: !existsSync8(join7(projectRoot, ".git")),
|
|
3600
3714
|
nodeWarning: checkNodeVersion(deps.nodeVersion).warning ?? null,
|
|
3601
3715
|
verbosity: flags.verbosity
|
|
3602
3716
|
});
|
|
3717
|
+
const ageExcludeHeal = pmDetect.pm === "pnpm" && versionChange ? previewRuntimeAgeExcludeHeal(projectRoot, targetVersion) : null;
|
|
3718
|
+
if (ageExcludeHeal !== null) io.writeOut(formatAgeExcludeHealLine(ageExcludeHeal, targetVersion));
|
|
3603
3719
|
const planFp = fingerprintPlanCriticalFiles(projectRoot, pmDetect.pm);
|
|
3604
3720
|
if (flags.dryRun) {
|
|
3605
3721
|
io.writeOut("[dry-run] no changes made.\n");
|
|
@@ -3616,7 +3732,7 @@ function runUpgrade(projectRoot, state, argv, launcherVersion, io = defaultIo(),
|
|
|
3616
3732
|
if (stale !== null) return stale;
|
|
3617
3733
|
if (versionChange) {
|
|
3618
3734
|
if (state.oldStyle || convertViaRemovals) {
|
|
3619
|
-
if (convertViaRemovals && !
|
|
3735
|
+
if (convertViaRemovals && !existsSync8(join7(projectRoot, "package.json"))) {
|
|
3620
3736
|
ensurePackageJson(projectRoot);
|
|
3621
3737
|
}
|
|
3622
3738
|
for (const packageName of RETIRED_DIRECTIVE_PACKAGE_NAMES) {
|
|
@@ -3634,10 +3750,15 @@ function runUpgrade(projectRoot, state, argv, launcherVersion, io = defaultIo(),
|
|
|
3634
3750
|
);
|
|
3635
3751
|
}
|
|
3636
3752
|
}
|
|
3637
|
-
if (convertViaRemovals && !
|
|
3753
|
+
if (convertViaRemovals && !existsSync8(join7(projectRoot, "package.json"))) {
|
|
3638
3754
|
ensurePackageJson(projectRoot);
|
|
3639
3755
|
}
|
|
3640
|
-
const add =
|
|
3756
|
+
const add = addWithRuntimeAgeExcludeHeal(
|
|
3757
|
+
projectRoot,
|
|
3758
|
+
pmDetect.pm,
|
|
3759
|
+
targetVersion,
|
|
3760
|
+
() => deps.runPmAdd?.({ projectRoot, pm: pmDetect.pm, version: targetVersion }) ?? runPmExactAdd({ projectRoot, pm: pmDetect.pm, version: targetVersion, env })
|
|
3761
|
+
);
|
|
3641
3762
|
if (!add.ok) {
|
|
3642
3763
|
return reportPmFailure(io, add);
|
|
3643
3764
|
}
|
|
@@ -3678,8 +3799,8 @@ function runUpgrade(projectRoot, state, argv, launcherVersion, io = defaultIo(),
|
|
|
3678
3799
|
return setupResult.exitCode;
|
|
3679
3800
|
}
|
|
3680
3801
|
if (convertViaRemovals) {
|
|
3681
|
-
const pkgPath =
|
|
3682
|
-
if (!
|
|
3802
|
+
const pkgPath = join7(projectRoot, "package.json");
|
|
3803
|
+
if (!existsSync8(pkgPath)) {
|
|
3683
3804
|
io.writeErr(
|
|
3684
3805
|
`Convert upgrade lost package.json after setup (shape ${upgradeShape?.shapeId}). Expected exact ${RUNTIME_PACKAGE_NAME}@${targetVersion}. Fix the cause, then run: directive upgrade --yes.
|
|
3685
3806
|
`
|
|
@@ -3796,10 +3917,10 @@ function runUninstall(projectRoot, state, argv, launcherVersion, io = defaultIo(
|
|
|
3796
3917
|
(a) => a.kind === "whole-file" ? a.path : a.kind === "marked-section" ? `${a.path} (marked section)` : `${a.path} (${a.entryKey ?? "structured entry"})`
|
|
3797
3918
|
);
|
|
3798
3919
|
const keepPaths = discovery.artifacts.filter((a) => a.kind === "retained").map((a) => a.path);
|
|
3799
|
-
if (!keepPaths.includes("xbrief") &&
|
|
3920
|
+
if (!keepPaths.includes("xbrief") && existsSync8(join7(projectRoot, "xbrief"))) {
|
|
3800
3921
|
keepPaths.push("xbrief");
|
|
3801
3922
|
}
|
|
3802
|
-
if (!keepPaths.includes(".deft/settings.json") &&
|
|
3923
|
+
if (!keepPaths.includes(".deft/settings.json") && existsSync8(join7(projectRoot, ".deft", "settings.json"))) {
|
|
3803
3924
|
keepPaths.push(".deft/settings.json");
|
|
3804
3925
|
}
|
|
3805
3926
|
keepPaths.push("user content in AGENTS.md / host configs", "global launcher");
|
|
@@ -4029,14 +4150,14 @@ Recovery: ${RECOVERY_GUIDANCE}
|
|
|
4029
4150
|
var runDoctorStub = runDoctor;
|
|
4030
4151
|
|
|
4031
4152
|
// packages/cli/src/version.ts
|
|
4032
|
-
import { readFileSync as
|
|
4033
|
-
import { dirname as dirname2, join as
|
|
4153
|
+
import { readFileSync as readFileSync7 } from "node:fs";
|
|
4154
|
+
import { dirname as dirname2, join as join8 } from "node:path";
|
|
4034
4155
|
import { fileURLToPath } from "node:url";
|
|
4035
4156
|
var FALLBACK = "0.0.0";
|
|
4036
4157
|
function readLauncherVersion() {
|
|
4037
4158
|
try {
|
|
4038
|
-
const pkgPath =
|
|
4039
|
-
const parsed = JSON.parse(
|
|
4159
|
+
const pkgPath = join8(dirname2(fileURLToPath(import.meta.url)), "..", "package.json");
|
|
4160
|
+
const parsed = JSON.parse(readFileSync7(pkgPath, "utf8"));
|
|
4040
4161
|
if (parsed !== null && typeof parsed === "object") {
|
|
4041
4162
|
const version = parsed.version;
|
|
4042
4163
|
if (typeof version === "string" && version.length > 0) return version;
|
package/package.json
CHANGED