claude-nomad 0.45.0 → 0.46.0
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/CHANGELOG.md +23 -0
- package/dist/nomad.mjs +1651 -1573
- package/package.json +1 -1
package/dist/nomad.mjs
CHANGED
|
@@ -1400,8 +1400,8 @@ function cmdEject(opts = {}, roots = defaultEjectRoots()) {
|
|
|
1400
1400
|
}
|
|
1401
1401
|
|
|
1402
1402
|
// src/commands.doctor.ts
|
|
1403
|
-
import { existsSync as
|
|
1404
|
-
import { join as
|
|
1403
|
+
import { existsSync as existsSync27 } from "node:fs";
|
|
1404
|
+
import { join as join33 } from "node:path";
|
|
1405
1405
|
|
|
1406
1406
|
// src/commands.doctor.checks.repo.ts
|
|
1407
1407
|
init_color();
|
|
@@ -2931,420 +2931,144 @@ function reportNodeEngineCheck(section2) {
|
|
|
2931
2931
|
addItem(section2, `${green(okGlyph)} node: ${process.version} (satisfies >=${min})`);
|
|
2932
2932
|
}
|
|
2933
2933
|
|
|
2934
|
-
// src/
|
|
2934
|
+
// src/spinner.ts
|
|
2935
2935
|
init_color();
|
|
2936
|
-
import {
|
|
2937
|
-
import {
|
|
2938
|
-
import {
|
|
2936
|
+
import { existsSync as existsSync25 } from "node:fs";
|
|
2937
|
+
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
2938
|
+
import { Worker } from "node:worker_threads";
|
|
2939
|
+
|
|
2940
|
+
// src/commands.push.recovery.ts
|
|
2939
2941
|
init_config();
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
const m = SEMVER_MAJOR_MINOR.exec(value);
|
|
2944
|
-
return m === null ? null : [m[1], m[2]];
|
|
2945
|
-
}
|
|
2946
|
-
function readGitleaksVersion(run, tomlExists) {
|
|
2947
|
-
const tomlPath = join26(repoHome(), ".gitleaks.toml");
|
|
2948
|
-
const args = ["version"];
|
|
2949
|
-
if (tomlExists(tomlPath)) args.push("--config", tomlPath);
|
|
2950
|
-
try {
|
|
2951
|
-
return run("gitleaks", args, {
|
|
2952
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
2953
|
-
timeout: GITLEAKS_TIMEOUT_MS
|
|
2954
|
-
}).toString().trim();
|
|
2955
|
-
} catch {
|
|
2956
|
-
return null;
|
|
2957
|
-
}
|
|
2958
|
-
}
|
|
2959
|
-
function reportGitleaksVersionCheck(section2, run = execFileSync7, tomlExists = existsSync22) {
|
|
2960
|
-
const raw = readGitleaksVersion(run, tomlExists);
|
|
2961
|
-
if (raw === null) return;
|
|
2962
|
-
const local = majorMinorOf(raw);
|
|
2963
|
-
if (local === null) return;
|
|
2964
|
-
const pin = majorMinorOf(GITLEAKS_PINNED_VERSION);
|
|
2965
|
-
if (pin === null) return;
|
|
2966
|
-
const sameMajorMinor = local[0] === pin[0] && local[1] === pin[1];
|
|
2967
|
-
if (sameMajorMinor) {
|
|
2968
|
-
addItem(section2, `${green(okGlyph)} gitleaks: ${raw} (matches pinned ${pin[0]}.${pin[1]})`);
|
|
2969
|
-
return;
|
|
2970
|
-
}
|
|
2971
|
-
addItem(
|
|
2972
|
-
section2,
|
|
2973
|
-
`${yellow(warnGlyph)} gitleaks: ${raw} -> ${GITLEAKS_PINNED_VERSION} (CI pins this; local drift may change scan results)`
|
|
2974
|
-
);
|
|
2975
|
-
}
|
|
2942
|
+
import { readFileSync as readFileSync13, rmSync as rmSync9, writeFileSync as writeFileSync5 } from "node:fs";
|
|
2943
|
+
import { join as join31 } from "node:path";
|
|
2944
|
+
import { createInterface } from "node:readline/promises";
|
|
2976
2945
|
|
|
2977
|
-
// src/commands.
|
|
2978
|
-
|
|
2979
|
-
import {
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
}
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2946
|
+
// src/commands.push.recovery.actions.ts
|
|
2947
|
+
init_config();
|
|
2948
|
+
import { readFileSync as readFileSync12 } from "node:fs";
|
|
2949
|
+
import { isAbsolute, resolve as resolve3, sep as sep4 } from "node:path";
|
|
2950
|
+
|
|
2951
|
+
// src/commands.push.recovery.redact.ts
|
|
2952
|
+
init_config();
|
|
2953
|
+
init_config_sharedDirs_guard();
|
|
2954
|
+
import { cpSync as cpSync5, existsSync as existsSync24, mkdirSync as mkdirSync6, statSync as statSync7 } from "node:fs";
|
|
2955
|
+
import { dirname as dirname6, join as join29, sep as sep3 } from "node:path";
|
|
2956
|
+
|
|
2957
|
+
// src/commands.redact.ts
|
|
2958
|
+
init_config();
|
|
2959
|
+
import { existsSync as existsSync23, statSync as statSync6 } from "node:fs";
|
|
2960
|
+
import { dirname as dirname5, join as join28 } from "node:path";
|
|
2961
|
+
|
|
2962
|
+
// src/commands.redact.subtree.ts
|
|
2963
|
+
import { existsSync as existsSync22, lstatSync as lstatSync7, readFileSync as readFileSync10, readdirSync as readdirSync9, statSync as statSync5, writeFileSync as writeFileSync3 } from "node:fs";
|
|
2964
|
+
import { join as join26 } from "node:path";
|
|
2965
|
+
init_utils_fs();
|
|
2966
|
+
function collectFiles(dir, out) {
|
|
2967
|
+
if (!existsSync22(dir)) return;
|
|
2968
|
+
const st = lstatSync7(dir);
|
|
2969
|
+
if (!st.isDirectory()) return;
|
|
2970
|
+
for (const entry of readdirSync9(dir)) {
|
|
2971
|
+
const abs = join26(dir, entry);
|
|
2972
|
+
const lst = lstatSync7(abs);
|
|
2973
|
+
if (lst.isSymbolicLink()) continue;
|
|
2974
|
+
if (lst.isDirectory()) {
|
|
2975
|
+
collectFiles(abs, out);
|
|
2976
|
+
continue;
|
|
2998
2977
|
}
|
|
2999
|
-
|
|
2978
|
+
if (lst.isFile()) out.push(abs);
|
|
3000
2979
|
}
|
|
3001
2980
|
}
|
|
3002
|
-
function
|
|
3003
|
-
const
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
`${yellow(warnGlyph)} ${FETCHER_BASE} (curl or wget): not installed (optional; needed for release-version staleness check + nomad doctor --check-schema)`
|
|
3013
|
-
);
|
|
2981
|
+
function listSubtreeFiles(sessionDir) {
|
|
2982
|
+
const out = [];
|
|
2983
|
+
collectFiles(sessionDir, out);
|
|
2984
|
+
return out.sort((a, b) => a.localeCompare(b));
|
|
2985
|
+
}
|
|
2986
|
+
function newestSubtreeMtimeMs(mainPath, subtreeFiles, statMtime = (p) => statSync5(p).mtimeMs) {
|
|
2987
|
+
let newest = statMtime(mainPath);
|
|
2988
|
+
for (const filePath of subtreeFiles) {
|
|
2989
|
+
const t = statMtime(filePath);
|
|
2990
|
+
if (t > newest) newest = t;
|
|
3014
2991
|
}
|
|
2992
|
+
return newest;
|
|
3015
2993
|
}
|
|
3016
|
-
function
|
|
3017
|
-
const
|
|
3018
|
-
if (
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
);
|
|
2994
|
+
function applySubtreeRedactions(mainPath, mainFindings, subtreeFiles, rule, ts, scan, dryRun) {
|
|
2995
|
+
const dirty = [];
|
|
2996
|
+
if (mainFindings.length > 0) dirty.push({ path: mainPath, findings: mainFindings });
|
|
2997
|
+
for (const filePath of subtreeFiles) {
|
|
2998
|
+
const raw = scan(filePath);
|
|
2999
|
+
if (raw === null || raw.length === 0) continue;
|
|
3000
|
+
const filtered = rule === void 0 ? raw : raw.filter((f) => f.RuleID === rule);
|
|
3001
|
+
if (filtered.length === 0) continue;
|
|
3002
|
+
dirty.push({ path: filePath, findings: filtered });
|
|
3025
3003
|
}
|
|
3026
|
-
|
|
3004
|
+
const total = dirty.reduce((n, e) => n + e.findings.length, 0);
|
|
3005
|
+
if (!dryRun && total > 0) {
|
|
3006
|
+
for (const { path: filePath, findings } of dirty) {
|
|
3007
|
+
backupBeforeWrite(filePath, ts);
|
|
3008
|
+
writeFileSync3(filePath, applyRedactions(readFileSync10(filePath, "utf8"), findings), "utf8");
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
return { total, dirty };
|
|
3027
3012
|
}
|
|
3028
3013
|
|
|
3029
|
-
// src/commands.
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3014
|
+
// src/commands.redact.ts
|
|
3015
|
+
init_push_gitleaks_scan();
|
|
3016
|
+
init_utils_fs();
|
|
3017
|
+
init_utils_json();
|
|
3018
|
+
init_utils();
|
|
3033
3019
|
|
|
3034
|
-
// src/
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
return { owner: m[1], repo: m[2] };
|
|
3020
|
+
// src/utils.lockfile.ts
|
|
3021
|
+
init_config();
|
|
3022
|
+
init_utils();
|
|
3023
|
+
import { closeSync as closeSync3, mkdirSync as mkdirSync5, openSync as openSync3, readFileSync as readFileSync11, unlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
|
|
3024
|
+
import { dirname as dirname4, join as join27 } from "node:path";
|
|
3025
|
+
function lockFilePath() {
|
|
3026
|
+
return join27(home(), ".cache", "claude-nomad", "nomad.lock");
|
|
3042
3027
|
}
|
|
3043
|
-
function
|
|
3028
|
+
function acquireLock(verb) {
|
|
3029
|
+
const lp = lockFilePath();
|
|
3030
|
+
mkdirSync5(dirname4(lp), { recursive: true });
|
|
3044
3031
|
try {
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
})
|
|
3049
|
-
|
|
3032
|
+
const fd = openSync3(lp, "wx");
|
|
3033
|
+
try {
|
|
3034
|
+
writeFileSync4(fd, String(process.pid));
|
|
3035
|
+
} catch (writeErr) {
|
|
3036
|
+
try {
|
|
3037
|
+
closeSync3(fd);
|
|
3038
|
+
} catch {
|
|
3039
|
+
}
|
|
3040
|
+
try {
|
|
3041
|
+
unlinkSync(lp);
|
|
3042
|
+
} catch {
|
|
3043
|
+
}
|
|
3044
|
+
throw writeErr;
|
|
3045
|
+
}
|
|
3046
|
+
return { fd, path: lp };
|
|
3050
3047
|
} catch (err) {
|
|
3051
|
-
const
|
|
3052
|
-
if (
|
|
3053
|
-
|
|
3054
|
-
return "gh-probe-error";
|
|
3048
|
+
const code = err.code;
|
|
3049
|
+
if (code !== "EEXIST") throw err;
|
|
3050
|
+
return checkStaleAndRetry(verb, lp);
|
|
3055
3051
|
}
|
|
3056
3052
|
}
|
|
3057
|
-
function
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
timeout: GH_TIMEOUT_MS
|
|
3061
|
-
}).toString();
|
|
3062
|
-
const parsed = JSON.parse(out);
|
|
3063
|
-
return parsed.isPrivate === true;
|
|
3064
|
-
}
|
|
3065
|
-
function isActionsEnabled(ref, run = execFileSync9) {
|
|
3066
|
-
const out = run(
|
|
3067
|
-
"gh",
|
|
3068
|
-
["api", `repos/${ref.owner}/${ref.repo}/actions/permissions`, "--jq", ".enabled"],
|
|
3069
|
-
{ stdio: ["ignore", "pipe", "ignore"], timeout: GH_TIMEOUT_MS }
|
|
3070
|
-
).toString().trim();
|
|
3071
|
-
return out === "true";
|
|
3072
|
-
}
|
|
3073
|
-
function disableActions(ref, run = execFileSync9) {
|
|
3074
|
-
run(
|
|
3075
|
-
"gh",
|
|
3076
|
-
[
|
|
3077
|
-
"api",
|
|
3078
|
-
"-X",
|
|
3079
|
-
"PUT",
|
|
3080
|
-
`repos/${ref.owner}/${ref.repo}/actions/permissions`,
|
|
3081
|
-
"-F",
|
|
3082
|
-
"enabled=false"
|
|
3083
|
-
],
|
|
3084
|
-
{ stdio: ["ignore", "ignore", "pipe"], timeout: GH_TIMEOUT_MS }
|
|
3085
|
-
);
|
|
3086
|
-
}
|
|
3087
|
-
function readOriginRemote(cwd, run = execFileSync9) {
|
|
3088
|
-
return run("git", ["remote", "get-url", "origin"], {
|
|
3089
|
-
cwd,
|
|
3090
|
-
stdio: ["ignore", "pipe", "ignore"]
|
|
3091
|
-
}).toString().trim();
|
|
3092
|
-
}
|
|
3093
|
-
|
|
3094
|
-
// src/commands.doctor.actions-drift.ts
|
|
3095
|
-
function reportActionsDrift(section2, run = execFileSync10) {
|
|
3096
|
-
let remote;
|
|
3053
|
+
function releaseLock(handle) {
|
|
3054
|
+
if (handle === null) return;
|
|
3055
|
+
const lp = handle.path;
|
|
3097
3056
|
try {
|
|
3098
|
-
|
|
3057
|
+
closeSync3(handle.fd);
|
|
3099
3058
|
} catch {
|
|
3100
|
-
return;
|
|
3101
3059
|
}
|
|
3102
|
-
const ref = parseGitHubRemote(remote);
|
|
3103
|
-
if (ref === null) return;
|
|
3104
|
-
const auth = ghAuthStatus(run);
|
|
3105
|
-
if (auth === "gh-not-installed" || auth === "gh-not-authed") return;
|
|
3106
|
-
let isPrivate;
|
|
3107
3060
|
try {
|
|
3108
|
-
|
|
3109
|
-
} catch {
|
|
3110
|
-
|
|
3061
|
+
unlinkSync(lp);
|
|
3062
|
+
} catch (err) {
|
|
3063
|
+
if (err.code !== "ENOENT") throw err;
|
|
3111
3064
|
}
|
|
3112
|
-
|
|
3113
|
-
|
|
3065
|
+
}
|
|
3066
|
+
function unlinkIfSamePid(expectedPidStr, lp) {
|
|
3067
|
+
let current;
|
|
3114
3068
|
try {
|
|
3115
|
-
|
|
3069
|
+
current = readFileSync11(lp, "utf8").trim();
|
|
3116
3070
|
} catch {
|
|
3117
|
-
return;
|
|
3118
|
-
}
|
|
3119
|
-
if (!enabled2) return;
|
|
3120
|
-
addItem(
|
|
3121
|
-
section2,
|
|
3122
|
-
`${yellow(warnGlyph)} Actions: enabled on private repo ${ref.owner}/${ref.repo} (re-disable with 'gh api -X PUT repos/${ref.owner}/${ref.repo}/actions/permissions -F enabled=false')`
|
|
3123
|
-
);
|
|
3124
|
-
}
|
|
3125
|
-
|
|
3126
|
-
// src/commands.doctor.verdict.ts
|
|
3127
|
-
init_color();
|
|
3128
|
-
function isFailLine(item2) {
|
|
3129
|
-
return item2.includes(failGlyph);
|
|
3130
|
-
}
|
|
3131
|
-
function isWarnLine(item2) {
|
|
3132
|
-
return !isFailLine(item2) && item2.includes(warnGlyph);
|
|
3133
|
-
}
|
|
3134
|
-
function buildVerdictSection(sections) {
|
|
3135
|
-
const summary = section("Summary");
|
|
3136
|
-
const lines = sections.flatMap((s) => s.items).map((item2) => item2.replace(/^\t/, ""));
|
|
3137
|
-
const failures = lines.filter(isFailLine);
|
|
3138
|
-
const warnings = lines.filter(isWarnLine);
|
|
3139
|
-
for (const line of [...failures, ...warnings]) addItem(summary, line);
|
|
3140
|
-
if (failures.length > 0) {
|
|
3141
|
-
addItem(
|
|
3142
|
-
summary,
|
|
3143
|
-
`${red(failGlyph)} ${failures.length} failure(s), ${warnings.length} warning(s)`
|
|
3144
|
-
);
|
|
3145
|
-
} else if (warnings.length > 0) {
|
|
3146
|
-
addItem(summary, `${yellow(warnGlyph)} ${warnings.length} warning(s)`);
|
|
3147
|
-
} else {
|
|
3148
|
-
addItem(summary, `${green(okGlyph)} healthy`);
|
|
3149
|
-
}
|
|
3150
|
-
return summary;
|
|
3151
|
-
}
|
|
3152
|
-
|
|
3153
|
-
// src/commands.doctor.ts
|
|
3154
|
-
function cmdDoctor(opts = {}) {
|
|
3155
|
-
const host = section("Environment");
|
|
3156
|
-
reportHostAndPaths(host);
|
|
3157
|
-
reportRepoState(host);
|
|
3158
|
-
const links = section("Shared links");
|
|
3159
|
-
const mapPath = join27(repoHome(), "path-map.json");
|
|
3160
|
-
const rawMap = existsSync23(mapPath) ? readJsonSafe(mapPath, mapPath, links) : null;
|
|
3161
|
-
const map = rawMap ?? { projects: {} };
|
|
3162
|
-
reportSharedLinks(links, map);
|
|
3163
|
-
const hooksScan = section("Hook targets");
|
|
3164
|
-
reportHooksTargetCheck(hooksScan);
|
|
3165
|
-
reportHookScopeCheck(hooksScan);
|
|
3166
|
-
reportPreserveSymlinksCheck(hooksScan);
|
|
3167
|
-
const settings = section("Settings");
|
|
3168
|
-
const base = loadBaseSettings(settings);
|
|
3169
|
-
const parsedSettings = loadAndReportSettings(settings);
|
|
3170
|
-
reportHostOverrides(settings, base, parsedSettings);
|
|
3171
|
-
reportSettingsDriftCheck(settings);
|
|
3172
|
-
const pathMap = section("Path map");
|
|
3173
|
-
reportPathMap(pathMap);
|
|
3174
|
-
const neverSync = section("Never-sync");
|
|
3175
|
-
reportNeverSync(neverSync);
|
|
3176
|
-
const repository = section("Repository");
|
|
3177
|
-
const gitleaksReady = reportGitleaksProbe(repository);
|
|
3178
|
-
reportGitlinks(repository);
|
|
3179
|
-
reportRemote(repository);
|
|
3180
|
-
reportRebaseClean(repository);
|
|
3181
|
-
reportRebaseState(repository);
|
|
3182
|
-
reportActionsDrift(repository);
|
|
3183
|
-
const nomadVersion = section("Nomad Version");
|
|
3184
|
-
reportVersionCheck(nomadVersion);
|
|
3185
|
-
const housekeeping = section("Housekeeping");
|
|
3186
|
-
reportBackupsCheck(housekeeping);
|
|
3187
|
-
const depVersions = section("Dependency Versions");
|
|
3188
|
-
reportNodeEngineCheck(depVersions);
|
|
3189
|
-
reportGitleaksVersionCheck(depVersions);
|
|
3190
|
-
reportOptionalDeps(depVersions);
|
|
3191
|
-
const sharedScan = section("Shared scan");
|
|
3192
|
-
if (opts.checkShared === true) reportCheckShared(sharedScan, gitleaksReady);
|
|
3193
|
-
const schemaScan = section("Schema scan");
|
|
3194
|
-
if (opts.checkSchema === true) reportCheckSchema(schemaScan);
|
|
3195
|
-
const body = [
|
|
3196
|
-
nomadVersion,
|
|
3197
|
-
depVersions,
|
|
3198
|
-
host,
|
|
3199
|
-
links,
|
|
3200
|
-
hooksScan,
|
|
3201
|
-
settings,
|
|
3202
|
-
pathMap,
|
|
3203
|
-
neverSync,
|
|
3204
|
-
repository,
|
|
3205
|
-
housekeeping,
|
|
3206
|
-
sharedScan,
|
|
3207
|
-
schemaScan
|
|
3208
|
-
];
|
|
3209
|
-
renderDoctor([...body, buildVerdictSection(body)]);
|
|
3210
|
-
}
|
|
3211
|
-
|
|
3212
|
-
// src/commands.drop-session.ts
|
|
3213
|
-
init_config();
|
|
3214
|
-
import { execFileSync as execFileSync12 } from "node:child_process";
|
|
3215
|
-
import { existsSync as existsSync25, readdirSync as readdirSync9, statSync as statSync5 } from "node:fs";
|
|
3216
|
-
import { join as join30, relative as relative4 } from "node:path";
|
|
3217
|
-
|
|
3218
|
-
// src/commands.drop-session.git.ts
|
|
3219
|
-
import { execFileSync as execFileSync11 } from "node:child_process";
|
|
3220
|
-
function expandStagedDir(dirRel, repo) {
|
|
3221
|
-
try {
|
|
3222
|
-
const out = execFileSync11("git", ["ls-files", "-z", "--", dirRel], {
|
|
3223
|
-
cwd: repo,
|
|
3224
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
3225
|
-
});
|
|
3226
|
-
return out.toString().split("\0").filter((p) => p !== "");
|
|
3227
|
-
} catch {
|
|
3228
|
-
return [];
|
|
3229
|
-
}
|
|
3230
|
-
}
|
|
3231
|
-
function isTrackedInHead(rel, repo) {
|
|
3232
|
-
try {
|
|
3233
|
-
execFileSync11("git", ["cat-file", "-e", `HEAD:${rel}`], {
|
|
3234
|
-
cwd: repo,
|
|
3235
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
3236
|
-
});
|
|
3237
|
-
return true;
|
|
3238
|
-
} catch {
|
|
3239
|
-
return false;
|
|
3240
|
-
}
|
|
3241
|
-
}
|
|
3242
|
-
function isInIndex(rel, repo) {
|
|
3243
|
-
try {
|
|
3244
|
-
const out = execFileSync11("git", ["ls-files", "--", rel], {
|
|
3245
|
-
cwd: repo,
|
|
3246
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
3247
|
-
});
|
|
3248
|
-
return out.toString().trim() !== "";
|
|
3249
|
-
} catch {
|
|
3250
|
-
return false;
|
|
3251
|
-
}
|
|
3252
|
-
}
|
|
3253
|
-
|
|
3254
|
-
// src/commands.drop-session.scrub-hint.ts
|
|
3255
|
-
init_config();
|
|
3256
|
-
init_utils();
|
|
3257
|
-
init_utils_json();
|
|
3258
|
-
import { existsSync as existsSync24 } from "node:fs";
|
|
3259
|
-
import { join as join28 } from "node:path";
|
|
3260
|
-
var SHARED_PROJECT_LOGICAL = /^shared\/projects\/([^/]+)\//;
|
|
3261
|
-
function reportScrubHint(id, matches) {
|
|
3262
|
-
const live = resolveLiveTranscript(id, matches);
|
|
3263
|
-
const target = live ?? `~/.claude/projects/<encoded>/${id}.jsonl`;
|
|
3264
|
-
log(
|
|
3265
|
-
`note: this only un-stages the session from the next push.
|
|
3266
|
-
The local source still contains the secret, so nomad push re-stages it
|
|
3267
|
-
on the next run and nomad doctor --check-shared keeps reporting it.
|
|
3268
|
-
To fully remediate: rotate the credential, then run:
|
|
3269
|
-
nomad redact ${id}
|
|
3270
|
-
(or scrub ${target} manually)`
|
|
3271
|
-
);
|
|
3272
|
-
}
|
|
3273
|
-
function resolveLiveTranscript(id, matches) {
|
|
3274
|
-
try {
|
|
3275
|
-
const mapPath = join28(repoHome(), "path-map.json");
|
|
3276
|
-
if (!existsSync24(mapPath)) return null;
|
|
3277
|
-
const projects = readJson(mapPath).projects;
|
|
3278
|
-
const claude = claudeHome();
|
|
3279
|
-
for (const rel of matches) {
|
|
3280
|
-
const logical = SHARED_PROJECT_LOGICAL.exec(rel)?.[1];
|
|
3281
|
-
if (logical === void 0) continue;
|
|
3282
|
-
const abs = projects[logical]?.[HOST];
|
|
3283
|
-
if (abs === void 0) continue;
|
|
3284
|
-
const live = join28(claude, "projects", encodePath(abs), `${id}.jsonl`);
|
|
3285
|
-
if (existsSync24(live)) return live;
|
|
3286
|
-
}
|
|
3287
|
-
return null;
|
|
3288
|
-
} catch {
|
|
3289
|
-
return null;
|
|
3290
|
-
}
|
|
3291
|
-
}
|
|
3292
|
-
|
|
3293
|
-
// src/commands.drop-session.ts
|
|
3294
|
-
init_utils();
|
|
3295
|
-
|
|
3296
|
-
// src/utils.lockfile.ts
|
|
3297
|
-
init_config();
|
|
3298
|
-
init_utils();
|
|
3299
|
-
import { closeSync as closeSync3, mkdirSync as mkdirSync5, openSync as openSync3, readFileSync as readFileSync10, unlinkSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
3300
|
-
import { dirname as dirname4, join as join29 } from "node:path";
|
|
3301
|
-
function lockFilePath() {
|
|
3302
|
-
return join29(home(), ".cache", "claude-nomad", "nomad.lock");
|
|
3303
|
-
}
|
|
3304
|
-
function acquireLock(verb) {
|
|
3305
|
-
const lp = lockFilePath();
|
|
3306
|
-
mkdirSync5(dirname4(lp), { recursive: true });
|
|
3307
|
-
try {
|
|
3308
|
-
const fd = openSync3(lp, "wx");
|
|
3309
|
-
try {
|
|
3310
|
-
writeFileSync3(fd, String(process.pid));
|
|
3311
|
-
} catch (writeErr) {
|
|
3312
|
-
try {
|
|
3313
|
-
closeSync3(fd);
|
|
3314
|
-
} catch {
|
|
3315
|
-
}
|
|
3316
|
-
try {
|
|
3317
|
-
unlinkSync(lp);
|
|
3318
|
-
} catch {
|
|
3319
|
-
}
|
|
3320
|
-
throw writeErr;
|
|
3321
|
-
}
|
|
3322
|
-
return { fd, path: lp };
|
|
3323
|
-
} catch (err) {
|
|
3324
|
-
const code = err.code;
|
|
3325
|
-
if (code !== "EEXIST") throw err;
|
|
3326
|
-
return checkStaleAndRetry(verb, lp);
|
|
3327
|
-
}
|
|
3328
|
-
}
|
|
3329
|
-
function releaseLock(handle) {
|
|
3330
|
-
if (handle === null) return;
|
|
3331
|
-
const lp = handle.path;
|
|
3332
|
-
try {
|
|
3333
|
-
closeSync3(handle.fd);
|
|
3334
|
-
} catch {
|
|
3335
|
-
}
|
|
3336
|
-
try {
|
|
3337
|
-
unlinkSync(lp);
|
|
3338
|
-
} catch (err) {
|
|
3339
|
-
if (err.code !== "ENOENT") throw err;
|
|
3340
|
-
}
|
|
3341
|
-
}
|
|
3342
|
-
function unlinkIfSamePid(expectedPidStr, lp) {
|
|
3343
|
-
let current;
|
|
3344
|
-
try {
|
|
3345
|
-
current = readFileSync10(lp, "utf8").trim();
|
|
3346
|
-
} catch {
|
|
3347
|
-
return false;
|
|
3071
|
+
return false;
|
|
3348
3072
|
}
|
|
3349
3073
|
if (current !== expectedPidStr) return false;
|
|
3350
3074
|
try {
|
|
@@ -3357,7 +3081,7 @@ function unlinkIfSamePid(expectedPidStr, lp) {
|
|
|
3357
3081
|
function checkStaleAndRetry(verb, lp) {
|
|
3358
3082
|
let pidStr;
|
|
3359
3083
|
try {
|
|
3360
|
-
pidStr =
|
|
3084
|
+
pidStr = readFileSync11(lp, "utf8").trim();
|
|
3361
3085
|
} catch {
|
|
3362
3086
|
pidStr = "";
|
|
3363
3087
|
}
|
|
@@ -3386,7 +3110,7 @@ function retryOnce(verb, lp) {
|
|
|
3386
3110
|
try {
|
|
3387
3111
|
const fd = openSync3(lp, "wx");
|
|
3388
3112
|
try {
|
|
3389
|
-
|
|
3113
|
+
writeFileSync4(fd, String(process.pid));
|
|
3390
3114
|
} catch {
|
|
3391
3115
|
try {
|
|
3392
3116
|
closeSync3(fd);
|
|
@@ -3406,193 +3130,59 @@ function retryOnce(verb, lp) {
|
|
|
3406
3130
|
}
|
|
3407
3131
|
}
|
|
3408
3132
|
|
|
3409
|
-
// src/commands.
|
|
3410
|
-
function
|
|
3133
|
+
// src/commands.redact.ts
|
|
3134
|
+
function resolveLiveTranscript(id) {
|
|
3135
|
+
try {
|
|
3136
|
+
const mapPath = join28(repoHome(), "path-map.json");
|
|
3137
|
+
if (!existsSync23(mapPath)) return null;
|
|
3138
|
+
const projects = readJson(mapPath).projects;
|
|
3139
|
+
const claude = claudeHome();
|
|
3140
|
+
for (const hostMap of Object.values(projects)) {
|
|
3141
|
+
const abs = hostMap[HOST];
|
|
3142
|
+
if (abs === void 0) continue;
|
|
3143
|
+
const live = join28(claude, "projects", encodePath(abs), `${id}.jsonl`);
|
|
3144
|
+
if (existsSync23(live)) return live;
|
|
3145
|
+
}
|
|
3146
|
+
return null;
|
|
3147
|
+
} catch {
|
|
3148
|
+
return null;
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
function resolveRedactFindings(localPath, rawFindings, rule, scan) {
|
|
3152
|
+
const source = rawFindings ?? scan(localPath);
|
|
3153
|
+
if (source === null) return null;
|
|
3154
|
+
return source.filter((f) => rule === void 0 || f.RuleID === rule);
|
|
3155
|
+
}
|
|
3156
|
+
function cmdRedact(opts, nowMs = Date.now, scan = scanFile) {
|
|
3157
|
+
const { id, rule, dryRun = false, findings: rawFindings } = opts;
|
|
3411
3158
|
if (id.length === 0 || id.length > 128 || !/^[A-Za-z0-9_-]+$/.test(id)) {
|
|
3412
3159
|
fail(`invalid session id: ${id}`);
|
|
3413
3160
|
process.exit(1);
|
|
3414
3161
|
}
|
|
3415
3162
|
const repo = repoHome();
|
|
3416
|
-
|
|
3417
|
-
|
|
3163
|
+
const backup = backupBase();
|
|
3164
|
+
if (!existsSync23(repo)) die(`repo not cloned at ${repo}`);
|
|
3165
|
+
const handle = acquireLock("redact");
|
|
3418
3166
|
if (handle === null) process.exit(0);
|
|
3419
3167
|
try {
|
|
3420
|
-
const
|
|
3421
|
-
if (!
|
|
3422
|
-
|
|
3168
|
+
const localPath = resolveLiveTranscript(id);
|
|
3169
|
+
if (localPath === null || !existsSync23(localPath)) {
|
|
3170
|
+
fail(`could not resolve local transcript for session ${id} on this host`);
|
|
3171
|
+
process.exitCode = 1;
|
|
3172
|
+
return;
|
|
3423
3173
|
}
|
|
3424
|
-
const
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
} finally {
|
|
3437
|
-
releaseLock(handle);
|
|
3438
|
-
}
|
|
3439
|
-
}
|
|
3440
|
-
function collectMatches(repoProjects, id, repo) {
|
|
3441
|
-
const matches = [];
|
|
3442
|
-
for (const logical of readdirSync9(repoProjects)) {
|
|
3443
|
-
const candidate = join30(repoProjects, logical, `${id}.jsonl`);
|
|
3444
|
-
if (existsSync25(candidate)) {
|
|
3445
|
-
matches.push(relative4(repo, candidate));
|
|
3446
|
-
}
|
|
3447
|
-
const dir = join30(repoProjects, logical, id);
|
|
3448
|
-
if (existsSync25(dir) && statSync5(dir).isDirectory()) {
|
|
3449
|
-
const dirRel = relative4(repo, dir);
|
|
3450
|
-
const staged = expandStagedDir(dirRel, repo);
|
|
3451
|
-
if (staged.length > 0) matches.push(...staged);
|
|
3452
|
-
else matches.push(dirRel);
|
|
3453
|
-
}
|
|
3454
|
-
}
|
|
3455
|
-
return matches;
|
|
3456
|
-
}
|
|
3457
|
-
function unstageOne(rel, repo) {
|
|
3458
|
-
if (!isInIndex(rel, repo)) {
|
|
3459
|
-
item(`dropped ${rel} (already absent from index)`);
|
|
3460
|
-
return;
|
|
3461
|
-
}
|
|
3462
|
-
try {
|
|
3463
|
-
if (isTrackedInHead(rel, repo)) {
|
|
3464
|
-
execFileSync12("git", ["restore", "--staged", "--worktree", "--", rel], {
|
|
3465
|
-
cwd: repo,
|
|
3466
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
3467
|
-
});
|
|
3468
|
-
} else {
|
|
3469
|
-
execFileSync12("git", ["rm", "--cached", "-f", "--", rel], {
|
|
3470
|
-
cwd: repo,
|
|
3471
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
3472
|
-
});
|
|
3473
|
-
}
|
|
3474
|
-
} catch (err) {
|
|
3475
|
-
const e = err;
|
|
3476
|
-
const detail = e.stderr?.toString().trim() ?? e.message;
|
|
3477
|
-
throw new NomadFatal(`git failed to unstage ${rel}: ${detail}`);
|
|
3478
|
-
}
|
|
3479
|
-
item(`dropped ${rel}`);
|
|
3480
|
-
}
|
|
3481
|
-
|
|
3482
|
-
// src/commands.redact.ts
|
|
3483
|
-
init_config();
|
|
3484
|
-
import { existsSync as existsSync27, statSync as statSync7 } from "node:fs";
|
|
3485
|
-
import { dirname as dirname5, join as join32 } from "node:path";
|
|
3486
|
-
|
|
3487
|
-
// src/commands.redact.subtree.ts
|
|
3488
|
-
import { existsSync as existsSync26, lstatSync as lstatSync7, readFileSync as readFileSync11, readdirSync as readdirSync10, statSync as statSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
3489
|
-
import { join as join31 } from "node:path";
|
|
3490
|
-
init_utils_fs();
|
|
3491
|
-
function collectFiles(dir, out) {
|
|
3492
|
-
if (!existsSync26(dir)) return;
|
|
3493
|
-
const st = lstatSync7(dir);
|
|
3494
|
-
if (!st.isDirectory()) return;
|
|
3495
|
-
for (const entry of readdirSync10(dir)) {
|
|
3496
|
-
const abs = join31(dir, entry);
|
|
3497
|
-
const lst = lstatSync7(abs);
|
|
3498
|
-
if (lst.isSymbolicLink()) continue;
|
|
3499
|
-
if (lst.isDirectory()) {
|
|
3500
|
-
collectFiles(abs, out);
|
|
3501
|
-
continue;
|
|
3502
|
-
}
|
|
3503
|
-
if (lst.isFile()) out.push(abs);
|
|
3504
|
-
}
|
|
3505
|
-
}
|
|
3506
|
-
function listSubtreeFiles(sessionDir) {
|
|
3507
|
-
const out = [];
|
|
3508
|
-
collectFiles(sessionDir, out);
|
|
3509
|
-
return out.sort((a, b) => a.localeCompare(b));
|
|
3510
|
-
}
|
|
3511
|
-
function newestSubtreeMtimeMs(mainPath, subtreeFiles, statMtime = (p) => statSync6(p).mtimeMs) {
|
|
3512
|
-
let newest = statMtime(mainPath);
|
|
3513
|
-
for (const filePath of subtreeFiles) {
|
|
3514
|
-
const t = statMtime(filePath);
|
|
3515
|
-
if (t > newest) newest = t;
|
|
3516
|
-
}
|
|
3517
|
-
return newest;
|
|
3518
|
-
}
|
|
3519
|
-
function applySubtreeRedactions(mainPath, mainFindings, subtreeFiles, rule, ts, scan, dryRun) {
|
|
3520
|
-
const dirty = [];
|
|
3521
|
-
if (mainFindings.length > 0) dirty.push({ path: mainPath, findings: mainFindings });
|
|
3522
|
-
for (const filePath of subtreeFiles) {
|
|
3523
|
-
const raw = scan(filePath);
|
|
3524
|
-
if (raw === null || raw.length === 0) continue;
|
|
3525
|
-
const filtered = rule === void 0 ? raw : raw.filter((f) => f.RuleID === rule);
|
|
3526
|
-
if (filtered.length === 0) continue;
|
|
3527
|
-
dirty.push({ path: filePath, findings: filtered });
|
|
3528
|
-
}
|
|
3529
|
-
const total = dirty.reduce((n, e) => n + e.findings.length, 0);
|
|
3530
|
-
if (!dryRun && total > 0) {
|
|
3531
|
-
for (const { path: filePath, findings } of dirty) {
|
|
3532
|
-
backupBeforeWrite(filePath, ts);
|
|
3533
|
-
writeFileSync4(filePath, applyRedactions(readFileSync11(filePath, "utf8"), findings), "utf8");
|
|
3534
|
-
}
|
|
3535
|
-
}
|
|
3536
|
-
return { total, dirty };
|
|
3537
|
-
}
|
|
3538
|
-
|
|
3539
|
-
// src/commands.redact.ts
|
|
3540
|
-
init_push_gitleaks_scan();
|
|
3541
|
-
init_utils_fs();
|
|
3542
|
-
init_utils_json();
|
|
3543
|
-
init_utils();
|
|
3544
|
-
function resolveLiveTranscript2(id) {
|
|
3545
|
-
try {
|
|
3546
|
-
const mapPath = join32(repoHome(), "path-map.json");
|
|
3547
|
-
if (!existsSync27(mapPath)) return null;
|
|
3548
|
-
const projects = readJson(mapPath).projects;
|
|
3549
|
-
const claude = claudeHome();
|
|
3550
|
-
for (const hostMap of Object.values(projects)) {
|
|
3551
|
-
const abs = hostMap[HOST];
|
|
3552
|
-
if (abs === void 0) continue;
|
|
3553
|
-
const live = join32(claude, "projects", encodePath(abs), `${id}.jsonl`);
|
|
3554
|
-
if (existsSync27(live)) return live;
|
|
3555
|
-
}
|
|
3556
|
-
return null;
|
|
3557
|
-
} catch {
|
|
3558
|
-
return null;
|
|
3559
|
-
}
|
|
3560
|
-
}
|
|
3561
|
-
function resolveRedactFindings(localPath, rawFindings, rule, scan) {
|
|
3562
|
-
const source = rawFindings ?? scan(localPath);
|
|
3563
|
-
if (source === null) return null;
|
|
3564
|
-
return source.filter((f) => rule === void 0 || f.RuleID === rule);
|
|
3565
|
-
}
|
|
3566
|
-
function cmdRedact(opts, nowMs = Date.now, scan = scanFile) {
|
|
3567
|
-
const { id, rule, dryRun = false, findings: rawFindings } = opts;
|
|
3568
|
-
if (id.length === 0 || id.length > 128 || !/^[A-Za-z0-9_-]+$/.test(id)) {
|
|
3569
|
-
fail(`invalid session id: ${id}`);
|
|
3570
|
-
process.exit(1);
|
|
3571
|
-
}
|
|
3572
|
-
const repo = repoHome();
|
|
3573
|
-
const backup = backupBase();
|
|
3574
|
-
if (!existsSync27(repo)) die(`repo not cloned at ${repo}`);
|
|
3575
|
-
const handle = acquireLock("redact");
|
|
3576
|
-
if (handle === null) process.exit(0);
|
|
3577
|
-
try {
|
|
3578
|
-
const localPath = resolveLiveTranscript2(id);
|
|
3579
|
-
if (localPath === null || !existsSync27(localPath)) {
|
|
3580
|
-
fail(`could not resolve local transcript for session ${id} on this host`);
|
|
3581
|
-
process.exitCode = 1;
|
|
3582
|
-
return;
|
|
3583
|
-
}
|
|
3584
|
-
const sessionDir = join32(dirname5(localPath), id);
|
|
3585
|
-
const subtreeFiles = listSubtreeFiles(sessionDir);
|
|
3586
|
-
const subtreeMtime = newestSubtreeMtimeMs(localPath, subtreeFiles, (p) => statSync7(p).mtimeMs);
|
|
3587
|
-
if (isRecentlyModified(subtreeMtime, nowMs())) {
|
|
3588
|
-
log(
|
|
3589
|
-
`session ${id} was modified recently and may be active.
|
|
3590
|
-
Refusing to rewrite a potentially live transcript.
|
|
3591
|
-
To proceed: wait for the session to end, then re-run nomad redact.
|
|
3592
|
-
Or drop from the staged tree: nomad drop-session ${id}
|
|
3593
|
-
Or skip this finding during nomad push.`
|
|
3594
|
-
);
|
|
3595
|
-
return;
|
|
3174
|
+
const sessionDir = join28(dirname5(localPath), id);
|
|
3175
|
+
const subtreeFiles = listSubtreeFiles(sessionDir);
|
|
3176
|
+
const subtreeMtime = newestSubtreeMtimeMs(localPath, subtreeFiles, (p) => statSync6(p).mtimeMs);
|
|
3177
|
+
if (isRecentlyModified(subtreeMtime, nowMs())) {
|
|
3178
|
+
log(
|
|
3179
|
+
`session ${id} was modified recently and may be active.
|
|
3180
|
+
Refusing to rewrite a potentially live transcript.
|
|
3181
|
+
To proceed: wait for the session to end, then re-run nomad redact.
|
|
3182
|
+
Or drop from the staged tree: nomad drop-session ${id}
|
|
3183
|
+
Or skip this finding during nomad push.`
|
|
3184
|
+
);
|
|
3185
|
+
return;
|
|
3596
3186
|
}
|
|
3597
3187
|
const mainFindings = resolveRedactFindings(localPath, rawFindings, rule, scan);
|
|
3598
3188
|
if (mainFindings === null) {
|
|
@@ -3633,1142 +3223,1630 @@ ${lines}`);
|
|
|
3633
3223
|
}
|
|
3634
3224
|
}
|
|
3635
3225
|
|
|
3636
|
-
// src/commands.
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
// src/commands.push.sections.ts
|
|
3641
|
-
init_color();
|
|
3642
|
-
|
|
3643
|
-
// src/summary.ts
|
|
3644
|
-
init_color();
|
|
3226
|
+
// src/commands.push.recovery.redact.ts
|
|
3227
|
+
init_push_gitleaks_scan();
|
|
3228
|
+
init_utils_json();
|
|
3645
3229
|
init_utils();
|
|
3646
|
-
function summaryText(verb, unmapped, collisions = 0, extrasSkipped = 0) {
|
|
3647
|
-
const extras = extrasSkipped > 0 ? `, ${extrasSkipped} extras skipped` : "";
|
|
3648
|
-
if (verb === "push") {
|
|
3649
|
-
if (unmapped === 0 && collisions === 0 && extrasSkipped === 0) {
|
|
3650
|
-
return { text: "summary: clean", clean: true };
|
|
3651
|
-
}
|
|
3652
|
-
const base = `summary: ${unmapped} unmapped on push, ${collisions} collisions`;
|
|
3653
|
-
return { text: `${base}${extras} (run nomad doctor to list)`, clean: false };
|
|
3654
|
-
}
|
|
3655
|
-
if (unmapped === 0 && extrasSkipped === 0) {
|
|
3656
|
-
return { text: "summary: clean", clean: true };
|
|
3657
|
-
}
|
|
3658
|
-
return {
|
|
3659
|
-
text: `summary: ${unmapped} unmapped on ${verb}${extras} (run nomad doctor to list)`,
|
|
3660
|
-
clean: false
|
|
3661
|
-
};
|
|
3662
|
-
}
|
|
3663
|
-
function summaryRow(verb, unmapped, collisions = 0, extrasSkipped = 0) {
|
|
3664
|
-
const { text, clean } = summaryText(verb, unmapped, collisions, extrasSkipped);
|
|
3665
|
-
return clean ? `${green(okGlyph)} ${text}` : `${yellow(warnGlyph)} ${text}`;
|
|
3666
|
-
}
|
|
3667
3230
|
|
|
3668
|
-
// src/commands.push.
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
return s;
|
|
3677
|
-
}
|
|
3678
|
-
function buildSessionsSection(items, unmapped) {
|
|
3679
|
-
const s = section("Sessions");
|
|
3680
|
-
for (const logical of items) addItem(s, `${green(okGlyph)} ${logical}`);
|
|
3681
|
-
const skip = collapsedSkipRow(unmapped, "not in path-map (run nomad doctor to list)");
|
|
3682
|
-
if (skip !== null) addItem(s, skip);
|
|
3683
|
-
return s;
|
|
3684
|
-
}
|
|
3685
|
-
function buildExtrasSection(items, extrasSkipped) {
|
|
3686
|
-
const s = section("Extras");
|
|
3687
|
-
for (const entry of items) addItem(s, `${green(okGlyph)} ${entry}`);
|
|
3688
|
-
const skip = collapsedSkipRow(extrasSkipped, "extras skipped");
|
|
3689
|
-
if (skip !== null) addItem(s, skip);
|
|
3690
|
-
return s;
|
|
3691
|
-
}
|
|
3692
|
-
function syncedSections(st) {
|
|
3693
|
-
const sessions = st.dryRun ? st.remap.wouldPush : st.remap.pushed;
|
|
3694
|
-
const extras = st.dryRun ? st.extras.wouldPush : st.extras.pushed;
|
|
3695
|
-
return [
|
|
3696
|
-
buildSessionsSection(sessions, st.remap.unmapped),
|
|
3697
|
-
buildExtrasSection(extras, st.extras.skipped)
|
|
3698
|
-
];
|
|
3231
|
+
// src/commands.push.recovery.seams.ts
|
|
3232
|
+
init_push_gitleaks();
|
|
3233
|
+
var MASK_LEAD = 4;
|
|
3234
|
+
var MASK_BODY = "************";
|
|
3235
|
+
var CONTEXT_WINDOW = 40;
|
|
3236
|
+
var CONTROL_CHARS = /[\x00-\x1f\x7f]/g;
|
|
3237
|
+
function findingKey(f) {
|
|
3238
|
+
return `${f.File}:${f.StartLine}:${f.StartColumn}:${f.RuleID}`;
|
|
3699
3239
|
}
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
const
|
|
3703
|
-
|
|
3704
|
-
|
|
3240
|
+
var VALID_SID = /^[A-Za-z0-9_-]+$/;
|
|
3241
|
+
function sessionIdFromFinding(f) {
|
|
3242
|
+
const m = SESSION_PATH.exec(f.File) ?? /^shared\/projects\/[^/]+\/([^/]+)\//.exec(f.File);
|
|
3243
|
+
if (m === null) return null;
|
|
3244
|
+
const sid = m[1];
|
|
3245
|
+
return VALID_SID.test(sid) ? sid : null;
|
|
3705
3246
|
}
|
|
3706
|
-
function
|
|
3707
|
-
const
|
|
3708
|
-
|
|
3709
|
-
|
|
3247
|
+
function parseAction(raw) {
|
|
3248
|
+
const t = raw.trim().toLowerCase();
|
|
3249
|
+
if (t === "r" || t === "redact") return "redact";
|
|
3250
|
+
if (t === "a" || t === "allow") return "allow";
|
|
3251
|
+
if (t === "d" || t === "drop") return "drop";
|
|
3252
|
+
return "skip";
|
|
3710
3253
|
}
|
|
3711
|
-
function
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3254
|
+
function maskSecret(secret) {
|
|
3255
|
+
return secret.slice(0, MASK_LEAD) + MASK_BODY;
|
|
3256
|
+
}
|
|
3257
|
+
function buildFindingContext(finding, readLine) {
|
|
3258
|
+
const raw = readLine(finding.File, finding.StartLine);
|
|
3259
|
+
if (raw !== null) {
|
|
3260
|
+
const len = raw.length;
|
|
3261
|
+
const startCol = Math.max(1, Math.min(finding.StartColumn, len + 1));
|
|
3262
|
+
const endCol = Math.max(startCol, Math.min(finding.EndColumn, len));
|
|
3263
|
+
const spanStart = startCol - 1;
|
|
3264
|
+
const spanEnd = endCol;
|
|
3265
|
+
const secret = raw.slice(spanStart, spanEnd);
|
|
3266
|
+
const masked = maskSecret(secret);
|
|
3267
|
+
const fullPrefix = raw.slice(0, spanStart);
|
|
3268
|
+
const fullSuffix = raw.slice(spanEnd);
|
|
3269
|
+
const prefixTruncated = fullPrefix.length > CONTEXT_WINDOW;
|
|
3270
|
+
const suffixTruncated = fullSuffix.length > CONTEXT_WINDOW;
|
|
3271
|
+
const prefix = prefixTruncated ? fullPrefix.slice(fullPrefix.length - CONTEXT_WINDOW) : fullPrefix;
|
|
3272
|
+
const suffix = suffixTruncated ? fullSuffix.slice(0, CONTEXT_WINDOW) : fullSuffix;
|
|
3273
|
+
const excerpt = (prefixTruncated ? "..." : "") + prefix + masked + suffix + (suffixTruncated ? "..." : "");
|
|
3274
|
+
const stripped = excerpt.replace(CONTROL_CHARS, "");
|
|
3275
|
+
if (stripped.trim().length > 0) return stripped;
|
|
3276
|
+
}
|
|
3277
|
+
if (finding.Match.length > 0) {
|
|
3278
|
+
return maskSecret(finding.Match).replace(CONTROL_CHARS, "");
|
|
3717
3279
|
}
|
|
3718
|
-
|
|
3280
|
+
return null;
|
|
3719
3281
|
}
|
|
3720
3282
|
|
|
3721
|
-
// src/commands.
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
// src/extras-sync.diff.ts
|
|
3730
|
-
init_utils();
|
|
3731
|
-
import { execFileSync as execFileSync13 } from "node:child_process";
|
|
3732
|
-
function labelDiffLine(line) {
|
|
3733
|
-
const tab = line.indexOf(" ");
|
|
3734
|
-
if (tab === -1) return line;
|
|
3735
|
-
const status = line.slice(0, tab);
|
|
3736
|
-
const path = line.slice(tab + 1);
|
|
3737
|
-
if (status === "D") return `${path} (local only)`;
|
|
3738
|
-
if (status === "A") return `${path} (repo only)`;
|
|
3739
|
-
return path;
|
|
3740
|
-
}
|
|
3741
|
-
function parseDiffOutput(stdout) {
|
|
3742
|
-
return stdout.split("\n").filter((line) => line.length > 0).map(labelDiffLine);
|
|
3743
|
-
}
|
|
3744
|
-
function listDivergingFiles(a, b) {
|
|
3745
|
-
try {
|
|
3746
|
-
const stdout = execFileSync13("git", ["diff", "--no-index", "--name-status", a, b], {
|
|
3747
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
3748
|
-
}).toString();
|
|
3749
|
-
return parseDiffOutput(stdout);
|
|
3750
|
-
} catch (err) {
|
|
3751
|
-
const e = err;
|
|
3752
|
-
if (e.status === 1 && e.stdout !== void 0) {
|
|
3753
|
-
return parseDiffOutput(e.stdout.toString());
|
|
3754
|
-
}
|
|
3755
|
-
if (e.code === "ENOENT") {
|
|
3756
|
-
warn(`git not on PATH; divergence check skipped for ${a}`);
|
|
3757
|
-
return [];
|
|
3283
|
+
// src/commands.push.recovery.redact.ts
|
|
3284
|
+
function resolveStagedDir(localPath, map, claude, repo) {
|
|
3285
|
+
for (const [logical, hostMap] of Object.entries(map.projects)) {
|
|
3286
|
+
assertSafeLogical(logical);
|
|
3287
|
+
const abs = hostMap[HOST];
|
|
3288
|
+
if (abs === void 0) continue;
|
|
3289
|
+
if (localPath.startsWith(join29(claude, "projects", encodePath(abs)) + sep3)) {
|
|
3290
|
+
return join29(repo, "shared", "projects", logical);
|
|
3758
3291
|
}
|
|
3759
|
-
warn(`divergence check failed for ${a}: ${e.message ?? String(err)}`);
|
|
3760
|
-
return [];
|
|
3761
3292
|
}
|
|
3293
|
+
return null;
|
|
3762
3294
|
}
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
if (!isAbsolute(localRoot)) {
|
|
3775
|
-
throw new NomadFatal(
|
|
3776
|
-
`invalid localRoot for ${logical} in path-map.json: ${JSON.stringify(localRoot)} (must be absolute)`
|
|
3295
|
+
function applyRedact(f, ts, map, nowMs, scan = scanFile) {
|
|
3296
|
+
const refuse = (msg) => {
|
|
3297
|
+
log(msg);
|
|
3298
|
+
return false;
|
|
3299
|
+
};
|
|
3300
|
+
const claude = claudeHome();
|
|
3301
|
+
const repo = repoHome();
|
|
3302
|
+
const sid = sessionIdFromFinding(f);
|
|
3303
|
+
if (sid === null) {
|
|
3304
|
+
return refuse(
|
|
3305
|
+
`could not locate the local transcript for this finding; choose Skip or Drop session.`
|
|
3777
3306
|
);
|
|
3778
3307
|
}
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3308
|
+
const localPath = resolveLiveTranscript(sid);
|
|
3309
|
+
if (localPath === null) {
|
|
3310
|
+
return refuse(
|
|
3311
|
+
`could not locate the local transcript for session ${sid}; choose Skip or Drop session.`
|
|
3782
3312
|
);
|
|
3783
3313
|
}
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
const repoExtras = join33(repo, "shared", "extras");
|
|
3793
|
-
if (!existsSync28(mapPath) || opts.requireRepoExtras === true && !existsSync28(repoExtras)) {
|
|
3794
|
-
if (opts.missingMsg !== void 0) log(opts.missingMsg);
|
|
3795
|
-
return null;
|
|
3796
|
-
}
|
|
3797
|
-
const map = readPathMap(mapPath);
|
|
3798
|
-
const extrasMap = map.extras ?? {};
|
|
3799
|
-
if (Object.keys(extrasMap).length === 0) return null;
|
|
3800
|
-
for (const logical of Object.keys(extrasMap)) {
|
|
3801
|
-
assertSafeLogical(logical);
|
|
3802
|
-
const localRoot = map.projects[logical]?.[HOST];
|
|
3803
|
-
if (localRoot && localRoot !== "TBD") assertSafeLocalRoot(localRoot, logical);
|
|
3314
|
+
const sessionDir = join29(dirname6(localPath), sid);
|
|
3315
|
+
const subtreeFiles = listSubtreeFiles(sessionDir);
|
|
3316
|
+
const subtreeMtime = newestSubtreeMtimeMs(localPath, subtreeFiles, (p) => statSync7(p).mtimeMs);
|
|
3317
|
+
if (isRecentlyModified(subtreeMtime, nowMs())) {
|
|
3318
|
+
return refuse(
|
|
3319
|
+
`session ${sid} looks active (modified within the last 5 minutes); refusing to redact, no changes made.
|
|
3320
|
+
End the session and choose Redact again, or choose Drop session (holds this session back from the push, local copy kept) or Skip.`
|
|
3321
|
+
);
|
|
3804
3322
|
}
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
const localRoot = v.map.projects[logical]?.[HOST];
|
|
3811
|
-
if (!localRoot || localRoot === "TBD") {
|
|
3812
|
-
counts.unmapped++;
|
|
3813
|
-
continue;
|
|
3814
|
-
}
|
|
3815
|
-
for (const dirname7 of dirnames) {
|
|
3816
|
-
if (!whitelist.includes(dirname7)) {
|
|
3817
|
-
counts.skipped++;
|
|
3818
|
-
continue;
|
|
3819
|
-
}
|
|
3820
|
-
yield { logical, localRoot, dirname: dirname7 };
|
|
3821
|
-
}
|
|
3323
|
+
const stagedProjectDir = resolveStagedDir(localPath, map, claude, repo);
|
|
3324
|
+
if (stagedProjectDir === null) {
|
|
3325
|
+
return refuse(
|
|
3326
|
+
`could not map the local transcript for session ${sid} to a staged copy; choose Drop session or Skip.`
|
|
3327
|
+
);
|
|
3822
3328
|
}
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
cpSync5(src, dst, { recursive: true, force: true, verbatimSymlinks: true });
|
|
3827
|
-
}
|
|
3828
|
-
|
|
3829
|
-
// src/extras-sync.ts
|
|
3830
|
-
init_utils();
|
|
3831
|
-
init_utils_json();
|
|
3832
|
-
|
|
3833
|
-
// src/extras-sync.remap.ts
|
|
3834
|
-
init_config();
|
|
3835
|
-
import { existsSync as existsSync29, mkdirSync as mkdirSync6 } from "node:fs";
|
|
3836
|
-
import { join as join34 } from "node:path";
|
|
3837
|
-
init_utils_fs();
|
|
3838
|
-
function runExtrasOp(v, dryRun, paths, backup) {
|
|
3839
|
-
const counts = { unmapped: 0, skipped: 0 };
|
|
3840
|
-
const done = [];
|
|
3841
|
-
const would = [];
|
|
3842
|
-
for (const t of eachExtrasTarget(v, counts)) {
|
|
3843
|
-
const { src, dst } = paths(t);
|
|
3844
|
-
if (!existsSync29(src)) continue;
|
|
3845
|
-
const item2 = `${t.logical}/${t.dirname}`;
|
|
3846
|
-
if (dryRun) {
|
|
3847
|
-
would.push(item2);
|
|
3848
|
-
continue;
|
|
3849
|
-
}
|
|
3850
|
-
backup(dst, t.localRoot);
|
|
3851
|
-
copyExtras(src, dst);
|
|
3852
|
-
done.push(item2);
|
|
3329
|
+
const mainFindings = scan(localPath);
|
|
3330
|
+
if (mainFindings === null) {
|
|
3331
|
+
return refuse(`re-scan of the transcript failed; choose Skip or Drop session.`);
|
|
3853
3332
|
}
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
if (!dryRun) mkdirSync6(repoExtras, { recursive: true });
|
|
3863
|
-
const { unmapped, skipped, done, would } = runExtrasOp(
|
|
3864
|
-
v,
|
|
3865
|
-
dryRun,
|
|
3866
|
-
({ localRoot, logical, dirname: dirname7 }) => ({
|
|
3867
|
-
src: join34(localRoot, dirname7),
|
|
3868
|
-
dst: join34(repoExtras, logical, dirname7)
|
|
3869
|
-
}),
|
|
3870
|
-
(dst) => backupRepoWrite(dst, ts, repo)
|
|
3871
|
-
);
|
|
3872
|
-
return { unmapped, skipped, pushed: done, wouldPush: would };
|
|
3873
|
-
}
|
|
3874
|
-
function remapExtrasPull(ts, opts = {}) {
|
|
3875
|
-
const dryRun = opts.dryRun === true;
|
|
3876
|
-
const v = loadValidatedExtras({
|
|
3877
|
-
requireRepoExtras: true,
|
|
3878
|
-
missingMsg: "no path-map or repo extras dir; skipping extras remap"
|
|
3879
|
-
});
|
|
3880
|
-
if (v === null) return { unmapped: 0, skipped: 0, pulled: [], wouldPull: [] };
|
|
3881
|
-
const repoExtras = join34(repoHome(), "shared", "extras");
|
|
3882
|
-
const { unmapped, skipped, done, would } = runExtrasOp(
|
|
3883
|
-
v,
|
|
3884
|
-
dryRun,
|
|
3885
|
-
({ localRoot, logical, dirname: dirname7 }) => ({
|
|
3886
|
-
src: join34(repoExtras, logical, dirname7),
|
|
3887
|
-
dst: join34(localRoot, dirname7)
|
|
3888
|
-
}),
|
|
3889
|
-
// Snapshot the host-side dst BEFORE copyExtras clobbers it. Anchor on
|
|
3890
|
-
// localRoot so the backup tree mirrors the project layout.
|
|
3891
|
-
(dst, localRoot) => backupExtrasWrite(dst, ts, localRoot)
|
|
3333
|
+
const { total: anyTotal } = applySubtreeRedactions(
|
|
3334
|
+
localPath,
|
|
3335
|
+
mainFindings,
|
|
3336
|
+
subtreeFiles,
|
|
3337
|
+
void 0,
|
|
3338
|
+
ts,
|
|
3339
|
+
scan,
|
|
3340
|
+
false
|
|
3892
3341
|
);
|
|
3893
|
-
|
|
3342
|
+
if (anyTotal === 0) {
|
|
3343
|
+
return refuse(
|
|
3344
|
+
`nothing to redact in the local transcript for session ${sid}; choose Skip or Drop session.`
|
|
3345
|
+
);
|
|
3346
|
+
}
|
|
3347
|
+
mkdirSync6(stagedProjectDir, { recursive: true });
|
|
3348
|
+
cpSync5(localPath, join29(stagedProjectDir, `${sid}.jsonl`), { force: true });
|
|
3349
|
+
if (existsSync24(sessionDir)) {
|
|
3350
|
+
cpSync5(sessionDir, join29(stagedProjectDir, sid), { force: true, recursive: true });
|
|
3351
|
+
}
|
|
3352
|
+
return true;
|
|
3894
3353
|
}
|
|
3895
3354
|
|
|
3896
|
-
// src/
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
const
|
|
3355
|
+
// src/commands.push.recovery.drop.ts
|
|
3356
|
+
init_config();
|
|
3357
|
+
import { rmSync as rmSync8 } from "node:fs";
|
|
3358
|
+
import { join as join30 } from "node:path";
|
|
3359
|
+
function dropSessionFromStaged(sid, map) {
|
|
3360
|
+
const logicals = Object.keys(map.projects);
|
|
3361
|
+
if (logicals.length === 0) return false;
|
|
3902
3362
|
const repo = repoHome();
|
|
3903
|
-
for (const
|
|
3904
|
-
const
|
|
3905
|
-
const
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
if (diff.length === 0) continue;
|
|
3909
|
-
const projectBackupRoot = join35(backupRoot, encodePath(localRoot));
|
|
3910
|
-
warn(
|
|
3911
|
-
`local ${dirname7} for ${logical} diverges from origin in ${diff.length} file(s); next remapExtrasPull will overwrite them (backups at ${projectBackupRoot}/)`
|
|
3912
|
-
);
|
|
3913
|
-
for (const f of diff) warn(` ${f}`);
|
|
3363
|
+
for (const logical of logicals) {
|
|
3364
|
+
const jsonl = join30(repo, "shared", "projects", logical, `${sid}.jsonl`);
|
|
3365
|
+
const dir = join30(repo, "shared", "projects", logical, sid);
|
|
3366
|
+
rmSync8(jsonl, { force: true });
|
|
3367
|
+
rmSync8(dir, { recursive: true, force: true });
|
|
3914
3368
|
}
|
|
3369
|
+
return true;
|
|
3915
3370
|
}
|
|
3916
3371
|
|
|
3917
|
-
// src/
|
|
3918
|
-
|
|
3372
|
+
// src/commands.push.recovery.actions.ts
|
|
3373
|
+
init_push_gitleaks_scan();
|
|
3919
3374
|
init_utils();
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
import { existsSync as existsSync31, lstatSync as lstatSync8, rmSync as rmSync9 } from "node:fs";
|
|
3923
|
-
import { join as join36 } from "node:path";
|
|
3924
|
-
function emitAutoMove(onPreview, linkPath, ts, name) {
|
|
3925
|
-
if (onPreview) {
|
|
3926
|
-
onPreview({ kind: "auto-move", from: linkPath, to: `backup/${ts}/${name}` });
|
|
3927
|
-
} else {
|
|
3928
|
-
log(`would auto-move non-symlink: ${linkPath} -> backup/${ts}/${name}`);
|
|
3929
|
-
}
|
|
3375
|
+
function applyAllow(f, repo) {
|
|
3376
|
+
appendGitleaksIgnore(f.Fingerprint, repo);
|
|
3930
3377
|
}
|
|
3931
|
-
function
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
} else {
|
|
3935
|
-
log(`would create symlink: ${from} -> ${to}`);
|
|
3378
|
+
function allowAllFindings(findings, repo) {
|
|
3379
|
+
for (const f of findings) {
|
|
3380
|
+
appendGitleaksIgnore(f.Fingerprint, repo);
|
|
3936
3381
|
}
|
|
3937
3382
|
}
|
|
3938
|
-
function
|
|
3939
|
-
|
|
3940
|
-
const
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
const linkPath = join36(claude, name);
|
|
3945
|
-
const target = join36(repo, "shared", name);
|
|
3946
|
-
if (!existsSync31(linkPath)) continue;
|
|
3947
|
-
if (lstatSync8(linkPath).isSymbolicLink()) continue;
|
|
3948
|
-
if (!existsSync31(target)) continue;
|
|
3949
|
-
if (dryRun) {
|
|
3950
|
-
emitAutoMove(opts.onPreview, linkPath, ts, name);
|
|
3951
|
-
continue;
|
|
3383
|
+
function allowFindingsByRule(findings, ruleId, repo) {
|
|
3384
|
+
let count = 0;
|
|
3385
|
+
for (const f of findings) {
|
|
3386
|
+
if (f.RuleID === ruleId) {
|
|
3387
|
+
appendGitleaksIgnore(f.Fingerprint, repo);
|
|
3388
|
+
count++;
|
|
3952
3389
|
}
|
|
3953
|
-
backupBeforeWrite(linkPath, ts);
|
|
3954
|
-
rmSync9(linkPath, { recursive: true, force: true });
|
|
3955
3390
|
}
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3391
|
+
return count;
|
|
3392
|
+
}
|
|
3393
|
+
function makeDefaultReadLine(repo) {
|
|
3394
|
+
return (file, line) => {
|
|
3395
|
+
try {
|
|
3396
|
+
const repoRoot = resolve3(repo);
|
|
3397
|
+
const target = resolve3(repoRoot, file);
|
|
3398
|
+
if (isAbsolute(file) || target !== repoRoot && !target.startsWith(repoRoot + sep4)) {
|
|
3399
|
+
return null;
|
|
3400
|
+
}
|
|
3401
|
+
const content = readFileSync12(target, "utf8");
|
|
3402
|
+
const lines = content.split(/\r?\n/);
|
|
3403
|
+
const idx = line - 1;
|
|
3404
|
+
if (idx < 0 || idx >= lines.length) return null;
|
|
3405
|
+
return lines[idx] ?? null;
|
|
3406
|
+
} catch {
|
|
3407
|
+
return null;
|
|
3962
3408
|
}
|
|
3963
|
-
|
|
3964
|
-
}
|
|
3409
|
+
};
|
|
3965
3410
|
}
|
|
3966
|
-
function
|
|
3967
|
-
const
|
|
3968
|
-
const
|
|
3969
|
-
const
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3411
|
+
async function collectActions(findings, prompt, readLine) {
|
|
3412
|
+
const reader = readLine ?? makeDefaultReadLine(repoHome());
|
|
3413
|
+
const actions = /* @__PURE__ */ new Map();
|
|
3414
|
+
for (const f of findings) {
|
|
3415
|
+
const sid = sessionIdFromFinding(f);
|
|
3416
|
+
const ctx = buildFindingContext(f, reader);
|
|
3417
|
+
const header = `
|
|
3418
|
+
Finding: ${f.RuleID} in ${f.File} line ${f.StartLine}` + (sid === null ? "" : ` (session: ${sid})`) + (ctx === null ? "" : `
|
|
3419
|
+
context: ${ctx}`) + "\n [R]edact [A]llow [D]rop session [S]kip (default)\n";
|
|
3420
|
+
actions.set(findingKey(f), parseAction(await prompt(header + "> ")));
|
|
3974
3421
|
}
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
const
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3422
|
+
return actions;
|
|
3423
|
+
}
|
|
3424
|
+
function dispatchOne(f, ctx) {
|
|
3425
|
+
const action = ctx.actions.get(findingKey(f)) ?? "skip";
|
|
3426
|
+
if (action === "skip") return;
|
|
3427
|
+
const sid = sessionIdFromFinding(f);
|
|
3428
|
+
if (sid !== null && ctx.droppedSids.has(sid)) return;
|
|
3429
|
+
if (action === "allow") {
|
|
3430
|
+
applyAllow(f, ctx.repo);
|
|
3431
|
+
return;
|
|
3432
|
+
}
|
|
3433
|
+
if (sid === null) return;
|
|
3434
|
+
if (action === "drop") {
|
|
3435
|
+
ctx.droppedSids.add(sid);
|
|
3436
|
+
if (ctx.drop(sid, ctx.map)) {
|
|
3437
|
+
log(
|
|
3438
|
+
`dropped session ${sid} from this push (local transcript kept; the secret remains in your local copy)`
|
|
3439
|
+
);
|
|
3992
3440
|
}
|
|
3441
|
+
return;
|
|
3993
3442
|
}
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
log(`would write settings.json (base + ${overrideLabel})`);
|
|
3997
|
-
return { label: overrideLabel };
|
|
3443
|
+
if (action === "redact" && !ctx.redactedSids.has(sid)) {
|
|
3444
|
+
if (applyRedact(f, ctx.ts, ctx.map, ctx.nowMs, ctx.scan)) ctx.redactedSids.add(sid);
|
|
3998
3445
|
}
|
|
3999
|
-
backupBeforeWrite(settingsPath, ts);
|
|
4000
|
-
writeJsonAtomic(settingsPath, merged);
|
|
4001
|
-
return { label: overrideLabel };
|
|
4002
3446
|
}
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
}
|
|
4019
|
-
const oldString = this.castInput(oldStr, options);
|
|
4020
|
-
const newString = this.castInput(newStr, options);
|
|
4021
|
-
const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
|
|
4022
|
-
const newTokens = this.removeEmpty(this.tokenize(newString, options));
|
|
4023
|
-
return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
|
|
3447
|
+
function dispatchActions(findings, actions, opts) {
|
|
3448
|
+
const { ts, map, nowMs, repo, scan = scanFile, drop = dropSessionFromStaged } = opts;
|
|
3449
|
+
const ctx = {
|
|
3450
|
+
actions,
|
|
3451
|
+
ts,
|
|
3452
|
+
map,
|
|
3453
|
+
nowMs,
|
|
3454
|
+
repo,
|
|
3455
|
+
scan,
|
|
3456
|
+
drop,
|
|
3457
|
+
redactedSids: /* @__PURE__ */ new Set(),
|
|
3458
|
+
droppedSids: /* @__PURE__ */ new Set()
|
|
3459
|
+
};
|
|
3460
|
+
for (const f of findings) {
|
|
3461
|
+
dispatchOne(f, ctx);
|
|
4024
3462
|
}
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
}, 0);
|
|
4033
|
-
return void 0;
|
|
4034
|
-
} else {
|
|
4035
|
-
return value;
|
|
4036
|
-
}
|
|
4037
|
-
};
|
|
4038
|
-
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
4039
|
-
let editLength = 1;
|
|
4040
|
-
let maxEditLength = newLen + oldLen;
|
|
4041
|
-
if (options.maxEditLength != null) {
|
|
4042
|
-
maxEditLength = Math.min(maxEditLength, options.maxEditLength);
|
|
4043
|
-
}
|
|
4044
|
-
const maxExecutionTime = (_a = options.timeout) !== null && _a !== void 0 ? _a : Infinity;
|
|
4045
|
-
const abortAfterTimestamp = Date.now() + maxExecutionTime;
|
|
4046
|
-
const bestPath = [{ oldPos: -1, lastComponent: void 0 }];
|
|
4047
|
-
let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
|
|
4048
|
-
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
4049
|
-
return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
|
|
4050
|
-
}
|
|
4051
|
-
let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
|
|
4052
|
-
const execEditLength = () => {
|
|
4053
|
-
for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
|
|
4054
|
-
let basePath;
|
|
4055
|
-
const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
|
|
4056
|
-
if (removePath) {
|
|
4057
|
-
bestPath[diagonalPath - 1] = void 0;
|
|
4058
|
-
}
|
|
4059
|
-
let canAdd = false;
|
|
4060
|
-
if (addPath) {
|
|
4061
|
-
const addPathNewPos = addPath.oldPos - diagonalPath;
|
|
4062
|
-
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
|
|
4063
|
-
}
|
|
4064
|
-
const canRemove = removePath && removePath.oldPos + 1 < oldLen;
|
|
4065
|
-
if (!canAdd && !canRemove) {
|
|
4066
|
-
bestPath[diagonalPath] = void 0;
|
|
4067
|
-
continue;
|
|
4068
|
-
}
|
|
4069
|
-
if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
|
|
4070
|
-
basePath = this.addToPath(addPath, true, false, 0, options);
|
|
4071
|
-
} else {
|
|
4072
|
-
basePath = this.addToPath(removePath, false, true, 1, options);
|
|
4073
|
-
}
|
|
4074
|
-
newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
|
|
4075
|
-
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
4076
|
-
return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
|
|
4077
|
-
} else {
|
|
4078
|
-
bestPath[diagonalPath] = basePath;
|
|
4079
|
-
if (basePath.oldPos + 1 >= oldLen) {
|
|
4080
|
-
maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
|
|
4081
|
-
}
|
|
4082
|
-
if (newPos + 1 >= newLen) {
|
|
4083
|
-
minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
|
|
4084
|
-
}
|
|
4085
|
-
}
|
|
4086
|
-
}
|
|
4087
|
-
editLength++;
|
|
4088
|
-
};
|
|
4089
|
-
if (callback) {
|
|
4090
|
-
(function exec() {
|
|
4091
|
-
setTimeout(function() {
|
|
4092
|
-
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
|
|
4093
|
-
return callback(void 0);
|
|
4094
|
-
}
|
|
4095
|
-
if (!execEditLength()) {
|
|
4096
|
-
exec();
|
|
4097
|
-
}
|
|
4098
|
-
}, 0);
|
|
4099
|
-
})();
|
|
4100
|
-
} else {
|
|
4101
|
-
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
4102
|
-
const ret = execEditLength();
|
|
4103
|
-
if (ret) {
|
|
4104
|
-
return ret;
|
|
4105
|
-
}
|
|
4106
|
-
}
|
|
4107
|
-
}
|
|
3463
|
+
}
|
|
3464
|
+
function redactAllFindings(findings, ts, map, nowMs, scan = scanFile) {
|
|
3465
|
+
const redactedSids = /* @__PURE__ */ new Set();
|
|
3466
|
+
for (const f of findings) {
|
|
3467
|
+
const sid = sessionIdFromFinding(f);
|
|
3468
|
+
if (sid === null || redactedSids.has(sid)) continue;
|
|
3469
|
+
if (applyRedact(f, ts, map, nowMs, scan)) redactedSids.add(sid);
|
|
4108
3470
|
}
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
}
|
|
3471
|
+
}
|
|
3472
|
+
|
|
3473
|
+
// src/commands.push.recovery.ts
|
|
3474
|
+
init_push_gitleaks_scan();
|
|
3475
|
+
init_push_gitleaks();
|
|
3476
|
+
init_utils();
|
|
3477
|
+
function isTTY(stdin = process.stdin, stdout = process.stdout) {
|
|
3478
|
+
return stdin.isTTY === true && stdout.isTTY === true;
|
|
3479
|
+
}
|
|
3480
|
+
function hasUnresolved(actions) {
|
|
3481
|
+
for (const action of actions.values()) {
|
|
3482
|
+
if (action === "skip") return true;
|
|
4122
3483
|
}
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
3484
|
+
return false;
|
|
3485
|
+
}
|
|
3486
|
+
function printRecoveryLegend(print = console.log) {
|
|
3487
|
+
print("");
|
|
3488
|
+
print("Recovery actions:");
|
|
3489
|
+
print(" Redact - scrub the secret from the local transcript, push the cleaned copy");
|
|
3490
|
+
print(" Allow - mark as false positive (adds a .gitleaksignore fingerprint), push as-is");
|
|
3491
|
+
print(" Drop session - exclude this session from this push (local transcript kept, running");
|
|
3492
|
+
print(" session is not stopped)");
|
|
3493
|
+
print(" Skip - leave unresolved (the push aborts)");
|
|
3494
|
+
print("");
|
|
3495
|
+
}
|
|
3496
|
+
function applyThenRescan(scanVerdict, repoHome2) {
|
|
3497
|
+
gitOrFatal(["add", "-A"], "git add", repoHome2);
|
|
3498
|
+
const next = scanVerdict(repoHome2);
|
|
3499
|
+
if (next.leak) {
|
|
3500
|
+
const { bySession, other } = partitionFindings(next.findings);
|
|
3501
|
+
throw new NomadFatal(buildSessionAwareFatal(bySession, other));
|
|
4139
3502
|
}
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
3503
|
+
return next;
|
|
3504
|
+
}
|
|
3505
|
+
function allowThenRescan(append, scanVerdict, repoHome2) {
|
|
3506
|
+
const ignPath = join31(repoHome2, ".gitleaksignore");
|
|
3507
|
+
let before;
|
|
3508
|
+
try {
|
|
3509
|
+
before = readFileSync13(ignPath, "utf8");
|
|
3510
|
+
} catch {
|
|
3511
|
+
before = null;
|
|
4146
3512
|
}
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
return ret;
|
|
3513
|
+
append();
|
|
3514
|
+
try {
|
|
3515
|
+
return applyThenRescan(scanVerdict, repoHome2);
|
|
3516
|
+
} catch (err) {
|
|
3517
|
+
if (before === null) rmSync9(ignPath, { force: true });
|
|
3518
|
+
else writeFileSync5(ignPath, before, "utf8");
|
|
3519
|
+
throw err;
|
|
4155
3520
|
}
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
3521
|
+
}
|
|
3522
|
+
function makeRealPrompt() {
|
|
3523
|
+
return async (prompt) => {
|
|
3524
|
+
const rl = createInterface({
|
|
3525
|
+
input: process.stdin,
|
|
3526
|
+
output: process.stdout,
|
|
3527
|
+
terminal: true
|
|
3528
|
+
});
|
|
3529
|
+
try {
|
|
3530
|
+
return await rl.question(prompt);
|
|
3531
|
+
} finally {
|
|
3532
|
+
rl.close();
|
|
3533
|
+
}
|
|
3534
|
+
};
|
|
3535
|
+
}
|
|
3536
|
+
async function resolveLeakFindings(verdict, ts, map, deps = {}) {
|
|
3537
|
+
const {
|
|
3538
|
+
isTTYCheck = isTTY,
|
|
3539
|
+
nowMs = Date.now,
|
|
3540
|
+
redactAll = false,
|
|
3541
|
+
allowAll = false,
|
|
3542
|
+
allowRule,
|
|
3543
|
+
makePrompt: makePromptFn = makeRealPrompt,
|
|
3544
|
+
scan = scanFile,
|
|
3545
|
+
printLegend = printRecoveryLegend
|
|
3546
|
+
} = deps;
|
|
3547
|
+
const scanVerdict = deps.scanVerdict ?? (await Promise.resolve().then(() => (init_push_leak_verdict(), push_leak_verdict_exports))).scanPushVerdict;
|
|
3548
|
+
const repo = repoHome();
|
|
3549
|
+
let current = verdict;
|
|
3550
|
+
if (redactAll) {
|
|
3551
|
+
redactAllFindings(current.findings, ts, map, nowMs, scan);
|
|
3552
|
+
return applyThenRescan(scanVerdict, repo);
|
|
3553
|
+
}
|
|
3554
|
+
if (allowAll) {
|
|
3555
|
+
return allowThenRescan(() => allowAllFindings(current.findings, repo), scanVerdict, repo);
|
|
3556
|
+
}
|
|
3557
|
+
if (allowRule !== void 0) {
|
|
3558
|
+
return allowThenRescan(
|
|
3559
|
+
() => {
|
|
3560
|
+
const matched = allowFindingsByRule(current.findings, allowRule, repo);
|
|
3561
|
+
if (matched === 0) log(`no findings matched rule ${allowRule}; re-scanning`);
|
|
3562
|
+
},
|
|
3563
|
+
scanVerdict,
|
|
3564
|
+
repo
|
|
3565
|
+
);
|
|
3566
|
+
}
|
|
3567
|
+
if (!isTTYCheck()) {
|
|
3568
|
+
throw new NomadFatal(current.recovery ?? "gitleaks detected secrets");
|
|
3569
|
+
}
|
|
3570
|
+
const prompt = makePromptFn();
|
|
3571
|
+
printLegend();
|
|
3572
|
+
while (current.leak && current.findings.length > 0) {
|
|
3573
|
+
const actions = await collectActions(current.findings, prompt);
|
|
3574
|
+
if (hasUnresolved(actions)) {
|
|
3575
|
+
const unresolved = current.findings.filter((f) => actions.get(findingKey(f)) === "skip");
|
|
3576
|
+
const { bySession, other } = partitionFindings(unresolved);
|
|
3577
|
+
throw new NomadFatal(buildSessionAwareFatal(bySession, other));
|
|
3578
|
+
}
|
|
3579
|
+
dispatchActions(current.findings, actions, { ts, map, nowMs, repo, scan });
|
|
3580
|
+
gitOrFatal(["add", "-A"], "git add", repo);
|
|
3581
|
+
current = scanVerdict(repo);
|
|
3582
|
+
}
|
|
3583
|
+
return current;
|
|
3584
|
+
}
|
|
3585
|
+
|
|
3586
|
+
// src/spinner.ts
|
|
3587
|
+
function formatElapsed(ms) {
|
|
3588
|
+
return `${(ms / 1e3).toFixed(1)}s`;
|
|
3589
|
+
}
|
|
3590
|
+
function writePlainStart(out, label) {
|
|
3591
|
+
out.write(`${label}...
|
|
3592
|
+
`);
|
|
3593
|
+
}
|
|
3594
|
+
function writePlainDone(out, label, ms) {
|
|
3595
|
+
out.write(`${label} done (${formatElapsed(ms)})
|
|
3596
|
+
`);
|
|
3597
|
+
}
|
|
3598
|
+
function writeAnimatedDone(out, label, ms, useTTY) {
|
|
3599
|
+
out.write("\r\x1B[K");
|
|
3600
|
+
const glyph = useTTY ? green(okGlyph) : okGlyph;
|
|
3601
|
+
out.write(`${glyph} ${label} (${formatElapsed(ms)})
|
|
3602
|
+
`);
|
|
3603
|
+
}
|
|
3604
|
+
function resolveWorkerPath(deps = {}) {
|
|
3605
|
+
const check = deps.existsSyncFn ?? existsSync25;
|
|
3606
|
+
const base = deps.baseUrl ?? import.meta.url;
|
|
3607
|
+
const mjs = fileURLToPath4(new URL("./nomad.worker.mjs", base));
|
|
3608
|
+
if (check(mjs)) return mjs;
|
|
3609
|
+
return fileURLToPath4(new URL("./spinner.worker.ts", base));
|
|
3610
|
+
}
|
|
3611
|
+
function makeRealWorker() {
|
|
3612
|
+
return new Worker(resolveWorkerPath());
|
|
3613
|
+
}
|
|
3614
|
+
function startSpinner(label, deps = {}) {
|
|
3615
|
+
const ttyCheck = deps.isTTYCheck ?? (() => isTTY());
|
|
3616
|
+
const env = deps.env ?? process.env;
|
|
3617
|
+
const out = deps.out ?? process.stderr;
|
|
3618
|
+
const now = deps.now ?? Date.now;
|
|
3619
|
+
const startMs = now();
|
|
3620
|
+
const animate = ttyCheck() && !env.CI;
|
|
3621
|
+
let worker = null;
|
|
3622
|
+
let degraded = false;
|
|
3623
|
+
let finalized = false;
|
|
3624
|
+
if (animate) {
|
|
3625
|
+
const factory = deps.makeWorker ?? makeRealWorker;
|
|
3626
|
+
try {
|
|
3627
|
+
worker = factory();
|
|
3628
|
+
worker.unref?.();
|
|
3629
|
+
worker.postMessage({ type: "start", label });
|
|
3630
|
+
} catch {
|
|
3631
|
+
degraded = true;
|
|
3632
|
+
worker = null;
|
|
3633
|
+
writePlainStart(out, label);
|
|
3634
|
+
}
|
|
3635
|
+
} else {
|
|
3636
|
+
writePlainStart(out, label);
|
|
3637
|
+
}
|
|
3638
|
+
function finalize(success, doneLabel) {
|
|
3639
|
+
if (finalized) return;
|
|
3640
|
+
finalized = true;
|
|
3641
|
+
const dl = doneLabel ?? label;
|
|
3642
|
+
const elapsed = now() - startMs;
|
|
3643
|
+
if (animate && !degraded && worker !== null) {
|
|
3644
|
+
worker.postMessage({ type: "pause" });
|
|
3645
|
+
worker.terminate();
|
|
3646
|
+
worker = null;
|
|
3647
|
+
if (success) writeAnimatedDone(out, dl, elapsed, ttyCheck());
|
|
3648
|
+
else out.write("\r\x1B[K");
|
|
3649
|
+
} else if (success) {
|
|
3650
|
+
writePlainDone(out, dl, elapsed);
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
return {
|
|
3654
|
+
succeed: (doneLabel) => finalize(true, doneLabel),
|
|
3655
|
+
stop: () => finalize(false)
|
|
3656
|
+
};
|
|
3657
|
+
}
|
|
3658
|
+
function withSpinner(label, fn, deps) {
|
|
3659
|
+
const sp = startSpinner(label, deps);
|
|
3660
|
+
try {
|
|
3661
|
+
const result = fn();
|
|
3662
|
+
sp.succeed();
|
|
3663
|
+
return result;
|
|
3664
|
+
} finally {
|
|
3665
|
+
sp.stop();
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
|
|
3669
|
+
// src/commands.doctor.gitleaks-version.ts
|
|
3670
|
+
init_color();
|
|
3671
|
+
import { execFileSync as execFileSync7 } from "node:child_process";
|
|
3672
|
+
import { existsSync as existsSync26 } from "node:fs";
|
|
3673
|
+
import { join as join32 } from "node:path";
|
|
3674
|
+
init_config();
|
|
3675
|
+
var SEMVER_MAJOR_MINOR = /^(\d+)\.(\d+)\.\d+$/;
|
|
3676
|
+
var GITLEAKS_TIMEOUT_MS = 5e3;
|
|
3677
|
+
function majorMinorOf(value) {
|
|
3678
|
+
const m = SEMVER_MAJOR_MINOR.exec(value);
|
|
3679
|
+
return m === null ? null : [m[1], m[2]];
|
|
3680
|
+
}
|
|
3681
|
+
function readGitleaksVersion(run, tomlExists) {
|
|
3682
|
+
const tomlPath = join32(repoHome(), ".gitleaks.toml");
|
|
3683
|
+
const args = ["version"];
|
|
3684
|
+
if (tomlExists(tomlPath)) args.push("--config", tomlPath);
|
|
3685
|
+
try {
|
|
3686
|
+
return run("gitleaks", args, {
|
|
3687
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
3688
|
+
timeout: GITLEAKS_TIMEOUT_MS
|
|
3689
|
+
}).toString().trim();
|
|
3690
|
+
} catch {
|
|
3691
|
+
return null;
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
function reportGitleaksVersionCheck(section2, run = execFileSync7, tomlExists = existsSync26) {
|
|
3695
|
+
const raw = readGitleaksVersion(run, tomlExists);
|
|
3696
|
+
if (raw === null) return;
|
|
3697
|
+
const local = majorMinorOf(raw);
|
|
3698
|
+
if (local === null) return;
|
|
3699
|
+
const pin = majorMinorOf(GITLEAKS_PINNED_VERSION);
|
|
3700
|
+
if (pin === null) return;
|
|
3701
|
+
const sameMajorMinor = local[0] === pin[0] && local[1] === pin[1];
|
|
3702
|
+
if (sameMajorMinor) {
|
|
3703
|
+
addItem(section2, `${green(okGlyph)} gitleaks: ${raw} (matches pinned ${pin[0]}.${pin[1]})`);
|
|
3704
|
+
return;
|
|
3705
|
+
}
|
|
3706
|
+
addItem(
|
|
3707
|
+
section2,
|
|
3708
|
+
`${yellow(warnGlyph)} gitleaks: ${raw} -> ${GITLEAKS_PINNED_VERSION} (CI pins this; local drift may change scan results)`
|
|
3709
|
+
);
|
|
3710
|
+
}
|
|
3711
|
+
|
|
3712
|
+
// src/commands.doctor.checks.deps.ts
|
|
3713
|
+
init_color();
|
|
3714
|
+
import { execFileSync as execFileSync8 } from "node:child_process";
|
|
3715
|
+
var VERSION_TOKEN = /(\d{1,9}\.\d{1,9}\.\d{1,9})/;
|
|
3716
|
+
var PROBE_TIMEOUT_MS = 3e3;
|
|
3717
|
+
var FETCHER_BASE = "HTTP fetcher";
|
|
3718
|
+
function parseFirstVersion(line) {
|
|
3719
|
+
const m = VERSION_TOKEN.exec(line);
|
|
3720
|
+
return m ? m[1] : null;
|
|
3721
|
+
}
|
|
3722
|
+
function probeOptionalDep(bin, run) {
|
|
3723
|
+
try {
|
|
3724
|
+
const firstLine = run(bin, ["--version"], {
|
|
3725
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
3726
|
+
timeout: PROBE_TIMEOUT_MS
|
|
3727
|
+
}).toString().split("\n")[0].trim();
|
|
3728
|
+
const version = parseFirstVersion(firstLine);
|
|
3729
|
+
return { status: "present", version };
|
|
3730
|
+
} catch (err) {
|
|
3731
|
+
if (err.code === "ENOENT") {
|
|
3732
|
+
return { status: "not-installed" };
|
|
3733
|
+
}
|
|
3734
|
+
return { status: "present", version: null };
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
function reportFetcherRow(section2, run) {
|
|
3738
|
+
const curl = probeOptionalDep("curl", run);
|
|
3739
|
+
const wget = probeOptionalDep("wget", run);
|
|
3740
|
+
if (curl.status === "present") {
|
|
3741
|
+
addItem(section2, `${green(okGlyph)} ${FETCHER_BASE}: curl ${curl.version ?? "(present)"}`);
|
|
3742
|
+
} else if (wget.status === "present") {
|
|
3743
|
+
addItem(section2, `${green(okGlyph)} ${FETCHER_BASE}: wget ${wget.version ?? "(present)"}`);
|
|
3744
|
+
} else {
|
|
3745
|
+
addItem(
|
|
3746
|
+
section2,
|
|
3747
|
+
`${yellow(warnGlyph)} ${FETCHER_BASE} (curl or wget): not installed (optional; needed for release-version staleness check + nomad doctor --check-schema)`
|
|
3748
|
+
);
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
function reportOptionalDeps(section2, run = execFileSync8) {
|
|
3752
|
+
const gh = probeOptionalDep("gh", run);
|
|
3753
|
+
if (gh.status === "present") {
|
|
3754
|
+
addItem(section2, `${green(okGlyph)} gh: ${gh.version ?? "present"}`);
|
|
3755
|
+
} else {
|
|
3756
|
+
addItem(
|
|
3757
|
+
section2,
|
|
3758
|
+
`${yellow(warnGlyph)} gh: not installed (optional; needed for nomad init Actions auto-disable + the Actions-drift check)`
|
|
3759
|
+
);
|
|
3760
|
+
}
|
|
3761
|
+
reportFetcherRow(section2, run);
|
|
3762
|
+
}
|
|
3763
|
+
|
|
3764
|
+
// src/commands.doctor.actions-drift.ts
|
|
3765
|
+
init_color();
|
|
3766
|
+
import { execFileSync as execFileSync10 } from "node:child_process";
|
|
3767
|
+
init_config();
|
|
3768
|
+
|
|
3769
|
+
// src/gh-actions.ts
|
|
3770
|
+
import { execFileSync as execFileSync9 } from "node:child_process";
|
|
3771
|
+
var GH_TIMEOUT_MS = 5e3;
|
|
3772
|
+
function parseGitHubRemote(remoteUrl) {
|
|
3773
|
+
const normalized = remoteUrl.trim().replace(/\/$/, "");
|
|
3774
|
+
const m = /github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?$/.exec(normalized);
|
|
3775
|
+
if (m === null) return null;
|
|
3776
|
+
return { owner: m[1], repo: m[2] };
|
|
3777
|
+
}
|
|
3778
|
+
function ghAuthStatus(run = execFileSync9) {
|
|
3779
|
+
try {
|
|
3780
|
+
run("gh", ["auth", "status"], {
|
|
3781
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
3782
|
+
timeout: GH_TIMEOUT_MS
|
|
3783
|
+
});
|
|
3784
|
+
return null;
|
|
3785
|
+
} catch (err) {
|
|
3786
|
+
const e = err;
|
|
3787
|
+
if (e.code === "ENOENT") return "gh-not-installed";
|
|
3788
|
+
if (typeof e.status === "number") return "gh-not-authed";
|
|
3789
|
+
return "gh-probe-error";
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3792
|
+
function isRepoPrivate(ref, run = execFileSync9) {
|
|
3793
|
+
const out = run("gh", ["repo", "view", `${ref.owner}/${ref.repo}`, "--json", "isPrivate"], {
|
|
3794
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
3795
|
+
timeout: GH_TIMEOUT_MS
|
|
3796
|
+
}).toString();
|
|
3797
|
+
const parsed = JSON.parse(out);
|
|
3798
|
+
return parsed.isPrivate === true;
|
|
3799
|
+
}
|
|
3800
|
+
function isActionsEnabled(ref, run = execFileSync9) {
|
|
3801
|
+
const out = run(
|
|
3802
|
+
"gh",
|
|
3803
|
+
["api", `repos/${ref.owner}/${ref.repo}/actions/permissions`, "--jq", ".enabled"],
|
|
3804
|
+
{ stdio: ["ignore", "pipe", "ignore"], timeout: GH_TIMEOUT_MS }
|
|
3805
|
+
).toString().trim();
|
|
3806
|
+
return out === "true";
|
|
3807
|
+
}
|
|
3808
|
+
function disableActions(ref, run = execFileSync9) {
|
|
3809
|
+
run(
|
|
3810
|
+
"gh",
|
|
3811
|
+
[
|
|
3812
|
+
"api",
|
|
3813
|
+
"-X",
|
|
3814
|
+
"PUT",
|
|
3815
|
+
`repos/${ref.owner}/${ref.repo}/actions/permissions`,
|
|
3816
|
+
"-F",
|
|
3817
|
+
"enabled=false"
|
|
3818
|
+
],
|
|
3819
|
+
{ stdio: ["ignore", "ignore", "pipe"], timeout: GH_TIMEOUT_MS }
|
|
3820
|
+
);
|
|
3821
|
+
}
|
|
3822
|
+
function readOriginRemote(cwd, run = execFileSync9) {
|
|
3823
|
+
return run("git", ["remote", "get-url", "origin"], {
|
|
3824
|
+
cwd,
|
|
3825
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
3826
|
+
}).toString().trim();
|
|
3827
|
+
}
|
|
3828
|
+
|
|
3829
|
+
// src/commands.doctor.actions-drift.ts
|
|
3830
|
+
function reportActionsDrift(section2, run = execFileSync10) {
|
|
3831
|
+
let remote;
|
|
3832
|
+
try {
|
|
3833
|
+
remote = readOriginRemote(repoHome(), run);
|
|
3834
|
+
} catch {
|
|
3835
|
+
return;
|
|
3836
|
+
}
|
|
3837
|
+
const ref = parseGitHubRemote(remote);
|
|
3838
|
+
if (ref === null) return;
|
|
3839
|
+
const auth = ghAuthStatus(run);
|
|
3840
|
+
if (auth === "gh-not-installed" || auth === "gh-not-authed") return;
|
|
3841
|
+
let isPrivate;
|
|
3842
|
+
try {
|
|
3843
|
+
isPrivate = isRepoPrivate(ref, run);
|
|
3844
|
+
} catch {
|
|
3845
|
+
return;
|
|
3846
|
+
}
|
|
3847
|
+
if (!isPrivate) return;
|
|
3848
|
+
let enabled2;
|
|
3849
|
+
try {
|
|
3850
|
+
enabled2 = isActionsEnabled(ref, run);
|
|
3851
|
+
} catch {
|
|
3852
|
+
return;
|
|
3853
|
+
}
|
|
3854
|
+
if (!enabled2) return;
|
|
3855
|
+
addItem(
|
|
3856
|
+
section2,
|
|
3857
|
+
`${yellow(warnGlyph)} Actions: enabled on private repo ${ref.owner}/${ref.repo} (re-disable with 'gh api -X PUT repos/${ref.owner}/${ref.repo}/actions/permissions -F enabled=false')`
|
|
3858
|
+
);
|
|
3859
|
+
}
|
|
3860
|
+
|
|
3861
|
+
// src/commands.doctor.verdict.ts
|
|
3862
|
+
init_color();
|
|
3863
|
+
function isFailLine(item2) {
|
|
3864
|
+
return item2.includes(failGlyph);
|
|
3865
|
+
}
|
|
3866
|
+
function isWarnLine(item2) {
|
|
3867
|
+
return !isFailLine(item2) && item2.includes(warnGlyph);
|
|
3868
|
+
}
|
|
3869
|
+
function buildVerdictSection(sections) {
|
|
3870
|
+
const summary = section("Summary");
|
|
3871
|
+
const lines = sections.flatMap((s) => s.items).map((item2) => item2.replace(/^\t/, ""));
|
|
3872
|
+
const failures = lines.filter(isFailLine);
|
|
3873
|
+
const warnings = lines.filter(isWarnLine);
|
|
3874
|
+
for (const line of [...failures, ...warnings]) addItem(summary, line);
|
|
3875
|
+
if (failures.length > 0) {
|
|
3876
|
+
addItem(
|
|
3877
|
+
summary,
|
|
3878
|
+
`${red(failGlyph)} ${failures.length} failure(s), ${warnings.length} warning(s)`
|
|
3879
|
+
);
|
|
3880
|
+
} else if (warnings.length > 0) {
|
|
3881
|
+
addItem(summary, `${yellow(warnGlyph)} ${warnings.length} warning(s)`);
|
|
3882
|
+
} else {
|
|
3883
|
+
addItem(summary, `${green(okGlyph)} healthy`);
|
|
4159
3884
|
}
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
3885
|
+
return summary;
|
|
3886
|
+
}
|
|
3887
|
+
|
|
3888
|
+
// src/commands.doctor.ts
|
|
3889
|
+
function gatherDoctorSections(opts) {
|
|
3890
|
+
const host = section("Environment");
|
|
3891
|
+
reportHostAndPaths(host);
|
|
3892
|
+
reportRepoState(host);
|
|
3893
|
+
const links = section("Shared links");
|
|
3894
|
+
const mapPath = join33(repoHome(), "path-map.json");
|
|
3895
|
+
const rawMap = existsSync27(mapPath) ? readJsonSafe(mapPath, mapPath, links) : null;
|
|
3896
|
+
const map = rawMap ?? { projects: {} };
|
|
3897
|
+
reportSharedLinks(links, map);
|
|
3898
|
+
const hooksScan = section("Hook targets");
|
|
3899
|
+
reportHooksTargetCheck(hooksScan);
|
|
3900
|
+
reportHookScopeCheck(hooksScan);
|
|
3901
|
+
reportPreserveSymlinksCheck(hooksScan);
|
|
3902
|
+
const settings = section("Settings");
|
|
3903
|
+
const base = loadBaseSettings(settings);
|
|
3904
|
+
const parsedSettings = loadAndReportSettings(settings);
|
|
3905
|
+
reportHostOverrides(settings, base, parsedSettings);
|
|
3906
|
+
reportSettingsDriftCheck(settings);
|
|
3907
|
+
const pathMap = section("Path map");
|
|
3908
|
+
reportPathMap(pathMap);
|
|
3909
|
+
const neverSync = section("Never-sync");
|
|
3910
|
+
reportNeverSync(neverSync);
|
|
3911
|
+
const repository = section("Repository");
|
|
3912
|
+
const gitleaksReady = reportGitleaksProbe(repository);
|
|
3913
|
+
reportGitlinks(repository);
|
|
3914
|
+
reportRemote(repository);
|
|
3915
|
+
reportRebaseClean(repository);
|
|
3916
|
+
reportRebaseState(repository);
|
|
3917
|
+
reportActionsDrift(repository);
|
|
3918
|
+
const nomadVersion = section("Nomad Version");
|
|
3919
|
+
reportVersionCheck(nomadVersion);
|
|
3920
|
+
const housekeeping = section("Housekeeping");
|
|
3921
|
+
reportBackupsCheck(housekeeping);
|
|
3922
|
+
const depVersions = section("Dependency Versions");
|
|
3923
|
+
reportNodeEngineCheck(depVersions);
|
|
3924
|
+
reportGitleaksVersionCheck(depVersions);
|
|
3925
|
+
reportOptionalDeps(depVersions);
|
|
3926
|
+
const sharedScan = section("Shared scan");
|
|
3927
|
+
if (opts.checkShared === true) reportCheckShared(sharedScan, gitleaksReady);
|
|
3928
|
+
const schemaScan = section("Schema scan");
|
|
3929
|
+
if (opts.checkSchema === true) reportCheckSchema(schemaScan);
|
|
3930
|
+
const body = [
|
|
3931
|
+
nomadVersion,
|
|
3932
|
+
depVersions,
|
|
3933
|
+
host,
|
|
3934
|
+
links,
|
|
3935
|
+
hooksScan,
|
|
3936
|
+
settings,
|
|
3937
|
+
pathMap,
|
|
3938
|
+
neverSync,
|
|
3939
|
+
repository,
|
|
3940
|
+
housekeeping,
|
|
3941
|
+
sharedScan,
|
|
3942
|
+
schemaScan
|
|
3943
|
+
];
|
|
3944
|
+
return [...body, buildVerdictSection(body)];
|
|
3945
|
+
}
|
|
3946
|
+
function cmdDoctor(opts = {}) {
|
|
3947
|
+
const makeSpinner = opts.startSpinner ?? startSpinner;
|
|
3948
|
+
const sp = makeSpinner("Running checks");
|
|
3949
|
+
let report;
|
|
3950
|
+
try {
|
|
3951
|
+
report = gatherDoctorSections(opts);
|
|
3952
|
+
} finally {
|
|
3953
|
+
sp.stop();
|
|
4163
3954
|
}
|
|
4164
|
-
|
|
4165
|
-
|
|
3955
|
+
renderDoctor(report);
|
|
3956
|
+
}
|
|
3957
|
+
|
|
3958
|
+
// src/commands.drop-session.ts
|
|
3959
|
+
init_config();
|
|
3960
|
+
import { execFileSync as execFileSync12 } from "node:child_process";
|
|
3961
|
+
import { existsSync as existsSync29, readdirSync as readdirSync10, statSync as statSync8 } from "node:fs";
|
|
3962
|
+
import { join as join35, relative as relative4 } from "node:path";
|
|
3963
|
+
|
|
3964
|
+
// src/commands.drop-session.git.ts
|
|
3965
|
+
import { execFileSync as execFileSync11 } from "node:child_process";
|
|
3966
|
+
function expandStagedDir(dirRel, repo) {
|
|
3967
|
+
try {
|
|
3968
|
+
const out = execFileSync11("git", ["ls-files", "-z", "--", dirRel], {
|
|
3969
|
+
cwd: repo,
|
|
3970
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
3971
|
+
});
|
|
3972
|
+
return out.toString().split("\0").filter((p) => p !== "");
|
|
3973
|
+
} catch {
|
|
3974
|
+
return [];
|
|
4166
3975
|
}
|
|
4167
|
-
|
|
4168
|
-
|
|
3976
|
+
}
|
|
3977
|
+
function isTrackedInHead(rel, repo) {
|
|
3978
|
+
try {
|
|
3979
|
+
execFileSync11("git", ["cat-file", "-e", `HEAD:${rel}`], {
|
|
3980
|
+
cwd: repo,
|
|
3981
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
3982
|
+
});
|
|
3983
|
+
return true;
|
|
3984
|
+
} catch {
|
|
3985
|
+
return false;
|
|
4169
3986
|
}
|
|
4170
|
-
|
|
3987
|
+
}
|
|
3988
|
+
function isInIndex(rel, repo) {
|
|
3989
|
+
try {
|
|
3990
|
+
const out = execFileSync11("git", ["ls-files", "--", rel], {
|
|
3991
|
+
cwd: repo,
|
|
3992
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
3993
|
+
});
|
|
3994
|
+
return out.toString().trim() !== "";
|
|
3995
|
+
} catch {
|
|
4171
3996
|
return false;
|
|
4172
3997
|
}
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
}
|
|
3998
|
+
}
|
|
3999
|
+
|
|
4000
|
+
// src/commands.drop-session.scrub-hint.ts
|
|
4001
|
+
init_config();
|
|
4002
|
+
init_utils();
|
|
4003
|
+
init_utils_json();
|
|
4004
|
+
import { existsSync as existsSync28 } from "node:fs";
|
|
4005
|
+
import { join as join34 } from "node:path";
|
|
4006
|
+
var SHARED_PROJECT_LOGICAL = /^shared\/projects\/([^/]+)\//;
|
|
4007
|
+
function reportScrubHint(id, matches) {
|
|
4008
|
+
const live = resolveLiveTranscript2(id, matches);
|
|
4009
|
+
const target = live ?? `~/.claude/projects/<encoded>/${id}.jsonl`;
|
|
4010
|
+
log(
|
|
4011
|
+
`note: this only un-stages the session from the next push.
|
|
4012
|
+
The local source still contains the secret, so nomad push re-stages it
|
|
4013
|
+
on the next run and nomad doctor --check-shared keeps reporting it.
|
|
4014
|
+
To fully remediate: rotate the credential, then run:
|
|
4015
|
+
nomad redact ${id}
|
|
4016
|
+
(or scrub ${target} manually)`
|
|
4017
|
+
);
|
|
4018
|
+
}
|
|
4019
|
+
function resolveLiveTranscript2(id, matches) {
|
|
4020
|
+
try {
|
|
4021
|
+
const mapPath = join34(repoHome(), "path-map.json");
|
|
4022
|
+
if (!existsSync28(mapPath)) return null;
|
|
4023
|
+
const projects = readJson(mapPath).projects;
|
|
4024
|
+
const claude = claudeHome();
|
|
4025
|
+
for (const rel of matches) {
|
|
4026
|
+
const logical = SHARED_PROJECT_LOGICAL.exec(rel)?.[1];
|
|
4027
|
+
if (logical === void 0) continue;
|
|
4028
|
+
const abs = projects[logical]?.[HOST];
|
|
4029
|
+
if (abs === void 0) continue;
|
|
4030
|
+
const live = join34(claude, "projects", encodePath(abs), `${id}.jsonl`);
|
|
4031
|
+
if (existsSync28(live)) return live;
|
|
4206
4032
|
}
|
|
4207
|
-
return
|
|
4033
|
+
return null;
|
|
4034
|
+
} catch {
|
|
4035
|
+
return null;
|
|
4208
4036
|
}
|
|
4209
|
-
}
|
|
4037
|
+
}
|
|
4210
4038
|
|
|
4211
|
-
//
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4039
|
+
// src/commands.drop-session.ts
|
|
4040
|
+
init_utils();
|
|
4041
|
+
function cmdDropSession(id) {
|
|
4042
|
+
if (id.length === 0 || id.length > 128 || !/^[A-Za-z0-9_-]+$/.test(id)) {
|
|
4043
|
+
fail(`invalid session id: ${id}`);
|
|
4044
|
+
process.exit(1);
|
|
4216
4045
|
}
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
}
|
|
4225
|
-
} else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
|
|
4226
|
-
if (left.endsWith("\n")) {
|
|
4227
|
-
left = left.slice(0, -1);
|
|
4228
|
-
}
|
|
4229
|
-
if (right.endsWith("\n")) {
|
|
4230
|
-
right = right.slice(0, -1);
|
|
4231
|
-
}
|
|
4046
|
+
const repo = repoHome();
|
|
4047
|
+
if (!existsSync29(repo)) die(`repo not cloned at ${repo}`);
|
|
4048
|
+
const handle = acquireLock("drop-session");
|
|
4049
|
+
if (handle === null) process.exit(0);
|
|
4050
|
+
try {
|
|
4051
|
+
const repoProjects = join35(repo, "shared", "projects");
|
|
4052
|
+
if (!existsSync29(repoProjects)) {
|
|
4053
|
+
throw new NomadFatal(`no staged session matches ${id}`);
|
|
4232
4054
|
}
|
|
4233
|
-
|
|
4055
|
+
const matches = collectMatches(repoProjects, id, repo);
|
|
4056
|
+
if (matches.length === 0) {
|
|
4057
|
+
throw new NomadFatal(`no staged session matches ${id}`);
|
|
4058
|
+
}
|
|
4059
|
+
for (const rel of matches) unstageOne(rel, repo);
|
|
4060
|
+
reportScrubHint(id, matches);
|
|
4061
|
+
} catch (err) {
|
|
4062
|
+
if (!(err instanceof NomadFatal)) {
|
|
4063
|
+
throw err;
|
|
4064
|
+
}
|
|
4065
|
+
fail(err.message);
|
|
4066
|
+
process.exitCode = 1;
|
|
4067
|
+
} finally {
|
|
4068
|
+
releaseLock(handle);
|
|
4234
4069
|
}
|
|
4235
|
-
};
|
|
4236
|
-
var lineDiff = new LineDiff();
|
|
4237
|
-
function diffLines(oldStr, newStr, options) {
|
|
4238
|
-
return lineDiff.diff(oldStr, newStr, options);
|
|
4239
4070
|
}
|
|
4240
|
-
function
|
|
4241
|
-
|
|
4242
|
-
|
|
4071
|
+
function collectMatches(repoProjects, id, repo) {
|
|
4072
|
+
const matches = [];
|
|
4073
|
+
for (const logical of readdirSync10(repoProjects)) {
|
|
4074
|
+
const candidate = join35(repoProjects, logical, `${id}.jsonl`);
|
|
4075
|
+
if (existsSync29(candidate)) {
|
|
4076
|
+
matches.push(relative4(repo, candidate));
|
|
4077
|
+
}
|
|
4078
|
+
const dir = join35(repoProjects, logical, id);
|
|
4079
|
+
if (existsSync29(dir) && statSync8(dir).isDirectory()) {
|
|
4080
|
+
const dirRel = relative4(repo, dir);
|
|
4081
|
+
const staged = expandStagedDir(dirRel, repo);
|
|
4082
|
+
if (staged.length > 0) matches.push(...staged);
|
|
4083
|
+
else matches.push(dirRel);
|
|
4084
|
+
}
|
|
4243
4085
|
}
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4086
|
+
return matches;
|
|
4087
|
+
}
|
|
4088
|
+
function unstageOne(rel, repo) {
|
|
4089
|
+
if (!isInIndex(rel, repo)) {
|
|
4090
|
+
item(`dropped ${rel} (already absent from index)`);
|
|
4091
|
+
return;
|
|
4247
4092
|
}
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4093
|
+
try {
|
|
4094
|
+
if (isTrackedInHead(rel, repo)) {
|
|
4095
|
+
execFileSync12("git", ["restore", "--staged", "--worktree", "--", rel], {
|
|
4096
|
+
cwd: repo,
|
|
4097
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4098
|
+
});
|
|
4252
4099
|
} else {
|
|
4253
|
-
|
|
4100
|
+
execFileSync12("git", ["rm", "--cached", "-f", "--", rel], {
|
|
4101
|
+
cwd: repo,
|
|
4102
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4103
|
+
});
|
|
4254
4104
|
}
|
|
4105
|
+
} catch (err) {
|
|
4106
|
+
const e = err;
|
|
4107
|
+
const detail = e.stderr?.toString().trim() ?? e.message;
|
|
4108
|
+
throw new NomadFatal(`git failed to unstage ${rel}: ${detail}`);
|
|
4255
4109
|
}
|
|
4256
|
-
|
|
4110
|
+
item(`dropped ${rel}`);
|
|
4257
4111
|
}
|
|
4258
4112
|
|
|
4259
|
-
// src/
|
|
4113
|
+
// src/commands.pull.ts
|
|
4114
|
+
import { existsSync as existsSync35, mkdirSync as mkdirSync8 } from "node:fs";
|
|
4115
|
+
import { join as join41 } from "node:path";
|
|
4116
|
+
|
|
4117
|
+
// src/commands.push.sections.ts
|
|
4260
4118
|
init_color();
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
let prefix;
|
|
4270
|
-
if (part.removed) prefix = (line) => red(`-${line}`);
|
|
4271
|
-
else if (part.added) prefix = (line) => green(`+${line}`);
|
|
4272
|
-
else prefix = (line) => ` ${line}`;
|
|
4273
|
-
for (const line of partLines) {
|
|
4274
|
-
lines.push(prefix(line));
|
|
4119
|
+
|
|
4120
|
+
// src/summary.ts
|
|
4121
|
+
init_utils();
|
|
4122
|
+
function summaryText(verb, unmapped, collisions = 0, extrasSkipped = 0) {
|
|
4123
|
+
const extras = extrasSkipped > 0 ? `, ${extrasSkipped} extras skipped` : "";
|
|
4124
|
+
if (verb === "push") {
|
|
4125
|
+
if (unmapped === 0 && collisions === 0 && extrasSkipped === 0) {
|
|
4126
|
+
return { text: "summary: clean", clean: true };
|
|
4275
4127
|
}
|
|
4128
|
+
const base = `summary: ${unmapped} unmapped on push, ${collisions} collisions`;
|
|
4129
|
+
return { text: `${base}${extras} (run nomad doctor to list)`, clean: false };
|
|
4276
4130
|
}
|
|
4277
|
-
|
|
4131
|
+
if (unmapped === 0 && extrasSkipped === 0) {
|
|
4132
|
+
return { text: "summary: clean", clean: true };
|
|
4133
|
+
}
|
|
4134
|
+
return {
|
|
4135
|
+
text: `summary: ${unmapped} unmapped on ${verb}${extras} (run nomad doctor to list)`,
|
|
4136
|
+
clean: false
|
|
4137
|
+
};
|
|
4138
|
+
}
|
|
4139
|
+
function summaryRow(verb, unmapped, collisions = 0, extrasSkipped = 0) {
|
|
4140
|
+
const { text } = summaryText(verb, unmapped, collisions, extrasSkipped);
|
|
4141
|
+
return text.replace(/^summary: /, "");
|
|
4278
4142
|
}
|
|
4279
4143
|
|
|
4280
|
-
// src/
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4144
|
+
// src/commands.push.sections.ts
|
|
4145
|
+
function collapsedSkipRow(n, noun) {
|
|
4146
|
+
if (n <= 0) return null;
|
|
4147
|
+
return `${dim(infoGlyph)} ${n} ${noun}`;
|
|
4148
|
+
}
|
|
4149
|
+
function buildSettingsSection(label) {
|
|
4150
|
+
const s = section("Settings");
|
|
4151
|
+
addItem(s, `${green(okGlyph)} settings.json (base + ${label})`);
|
|
4152
|
+
return s;
|
|
4153
|
+
}
|
|
4154
|
+
function buildSessionsSection(items, unmapped) {
|
|
4155
|
+
const s = section("Sessions");
|
|
4156
|
+
for (const logical of items) addItem(s, `${green(okGlyph)} ${logical}`);
|
|
4157
|
+
const skip = collapsedSkipRow(unmapped, "not in path-map (run nomad doctor to list)");
|
|
4158
|
+
if (skip !== null) addItem(s, skip);
|
|
4159
|
+
return s;
|
|
4160
|
+
}
|
|
4161
|
+
function buildExtrasSection(items, extrasSkipped) {
|
|
4162
|
+
const s = section("Extras");
|
|
4163
|
+
for (const entry of items) addItem(s, `${green(okGlyph)} ${entry}`);
|
|
4164
|
+
const skip = collapsedSkipRow(extrasSkipped, "extras skipped");
|
|
4165
|
+
if (skip !== null) addItem(s, skip);
|
|
4166
|
+
return s;
|
|
4167
|
+
}
|
|
4168
|
+
function syncedSections(st) {
|
|
4169
|
+
const sessions = st.dryRun ? st.remap.wouldPush : st.remap.pushed;
|
|
4170
|
+
const extras = st.dryRun ? st.extras.wouldPush : st.extras.pushed;
|
|
4171
|
+
return [
|
|
4172
|
+
buildSessionsSection(sessions, st.remap.unmapped),
|
|
4173
|
+
buildExtrasSection(extras, st.extras.skipped)
|
|
4289
4174
|
];
|
|
4290
|
-
return lines.join("\n");
|
|
4291
4175
|
}
|
|
4292
|
-
function
|
|
4293
|
-
|
|
4176
|
+
function summarySection(st) {
|
|
4177
|
+
const s = section("Summary");
|
|
4178
|
+
const unmapped = st.remap.unmapped + st.extras.unmapped;
|
|
4179
|
+
addItem(s, summaryRow("push", unmapped, st.remap.collisions, st.extras.skipped));
|
|
4180
|
+
return s;
|
|
4181
|
+
}
|
|
4182
|
+
function renderPushTree(st, verdict) {
|
|
4183
|
+
const leakScan = section("Leak scan");
|
|
4184
|
+
addItem(leakScan, verdict.verdictRow);
|
|
4185
|
+
renderTree([...syncedSections(st), leakScan, summarySection(st)]);
|
|
4186
|
+
}
|
|
4187
|
+
function renderNoScanTree(st, opts = {}) {
|
|
4188
|
+
const sections = [];
|
|
4189
|
+
if (opts.noMapHint === true) {
|
|
4190
|
+
const pathMap = section("Path map");
|
|
4191
|
+
addItem(pathMap, `${dim(infoGlyph)} no path-map.json (nothing to preview)`);
|
|
4192
|
+
sections.push(pathMap);
|
|
4193
|
+
}
|
|
4194
|
+
renderTree([...sections, ...syncedSections(st), summarySection(st)]);
|
|
4195
|
+
}
|
|
4196
|
+
|
|
4197
|
+
// src/commands.pull.ts
|
|
4198
|
+
init_config();
|
|
4199
|
+
|
|
4200
|
+
// src/extras-sync.ts
|
|
4201
|
+
init_config();
|
|
4202
|
+
import { existsSync as existsSync32 } from "node:fs";
|
|
4203
|
+
import { join as join38 } from "node:path";
|
|
4204
|
+
|
|
4205
|
+
// src/extras-sync.diff.ts
|
|
4206
|
+
init_utils();
|
|
4207
|
+
import { execFileSync as execFileSync13 } from "node:child_process";
|
|
4208
|
+
function labelDiffLine(line) {
|
|
4209
|
+
const tab = line.indexOf(" ");
|
|
4210
|
+
if (tab === -1) return line;
|
|
4211
|
+
const status = line.slice(0, tab);
|
|
4212
|
+
const path = line.slice(tab + 1);
|
|
4213
|
+
if (status === "D") return `${path} (local only)`;
|
|
4214
|
+
if (status === "A") return `${path} (repo only)`;
|
|
4215
|
+
return path;
|
|
4216
|
+
}
|
|
4217
|
+
function parseDiffOutput(stdout) {
|
|
4218
|
+
return stdout.split("\n").filter((line) => line.length > 0).map(labelDiffLine);
|
|
4219
|
+
}
|
|
4220
|
+
function listDivergingFiles(a, b) {
|
|
4294
4221
|
try {
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4222
|
+
const stdout = execFileSync13("git", ["diff", "--no-index", "--name-status", a, b], {
|
|
4223
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4224
|
+
}).toString();
|
|
4225
|
+
return parseDiffOutput(stdout);
|
|
4226
|
+
} catch (err) {
|
|
4227
|
+
const e = err;
|
|
4228
|
+
if (e.status === 1 && e.stdout !== void 0) {
|
|
4229
|
+
return parseDiffOutput(e.stdout.toString());
|
|
4230
|
+
}
|
|
4231
|
+
if (e.code === "ENOENT") {
|
|
4232
|
+
warn(`git not on PATH; divergence check skipped for ${a}`);
|
|
4233
|
+
return [];
|
|
4234
|
+
}
|
|
4235
|
+
warn(`divergence check failed for ${a}: ${e.message ?? String(err)}`);
|
|
4236
|
+
return [];
|
|
4298
4237
|
}
|
|
4299
4238
|
}
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4239
|
+
|
|
4240
|
+
// src/extras-sync.core.ts
|
|
4241
|
+
init_config();
|
|
4242
|
+
import { cpSync as cpSync6, existsSync as existsSync30, rmSync as rmSync10 } from "node:fs";
|
|
4243
|
+
import { join as join36 } from "node:path";
|
|
4244
|
+
|
|
4245
|
+
// src/extras-sync.guards.ts
|
|
4246
|
+
init_utils();
|
|
4247
|
+
init_config_sharedDirs_guard();
|
|
4248
|
+
import { isAbsolute as isAbsolute2, normalize } from "node:path";
|
|
4249
|
+
function assertSafeLocalRoot(localRoot, logical) {
|
|
4250
|
+
if (!isAbsolute2(localRoot)) {
|
|
4251
|
+
throw new NomadFatal(
|
|
4252
|
+
`invalid localRoot for ${logical} in path-map.json: ${JSON.stringify(localRoot)} (must be absolute)`
|
|
4253
|
+
);
|
|
4304
4254
|
}
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4255
|
+
if (localRoot !== normalize(localRoot)) {
|
|
4256
|
+
throw new NomadFatal(
|
|
4257
|
+
`invalid localRoot for ${logical} in path-map.json: ${JSON.stringify(localRoot)} (must be already-normalized; no '..' or redundant segments)`
|
|
4258
|
+
);
|
|
4309
4259
|
}
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4260
|
+
}
|
|
4261
|
+
|
|
4262
|
+
// src/extras-sync.core.ts
|
|
4263
|
+
init_utils();
|
|
4264
|
+
init_utils_json();
|
|
4265
|
+
function loadValidatedExtras(opts) {
|
|
4266
|
+
const repo = repoHome();
|
|
4267
|
+
const mapPath = join36(repo, "path-map.json");
|
|
4268
|
+
const repoExtras = join36(repo, "shared", "extras");
|
|
4269
|
+
if (!existsSync30(mapPath) || opts.requireRepoExtras === true && !existsSync30(repoExtras)) {
|
|
4270
|
+
if (opts.missingMsg !== void 0) log(opts.missingMsg);
|
|
4271
|
+
return null;
|
|
4314
4272
|
}
|
|
4315
|
-
const
|
|
4316
|
-
const
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4273
|
+
const map = readPathMap(mapPath);
|
|
4274
|
+
const extrasMap = map.extras ?? {};
|
|
4275
|
+
if (Object.keys(extrasMap).length === 0) return null;
|
|
4276
|
+
for (const logical of Object.keys(extrasMap)) {
|
|
4277
|
+
assertSafeLogical(logical);
|
|
4278
|
+
const localRoot = map.projects[logical]?.[HOST];
|
|
4279
|
+
if (localRoot && localRoot !== "TBD") assertSafeLocalRoot(localRoot, logical);
|
|
4280
|
+
}
|
|
4281
|
+
return { map, extrasMap };
|
|
4322
4282
|
}
|
|
4323
|
-
function
|
|
4324
|
-
|
|
4283
|
+
function* eachExtrasTarget(v, counts) {
|
|
4284
|
+
const whitelist = SUPPORTED_EXTRAS;
|
|
4285
|
+
for (const [logical, dirnames] of Object.entries(v.extrasMap)) {
|
|
4286
|
+
const localRoot = v.map.projects[logical]?.[HOST];
|
|
4287
|
+
if (!localRoot || localRoot === "TBD") {
|
|
4288
|
+
counts.unmapped++;
|
|
4289
|
+
continue;
|
|
4290
|
+
}
|
|
4291
|
+
for (const dirname7 of dirnames) {
|
|
4292
|
+
if (!whitelist.includes(dirname7)) {
|
|
4293
|
+
counts.skipped++;
|
|
4294
|
+
continue;
|
|
4295
|
+
}
|
|
4296
|
+
yield { logical, localRoot, dirname: dirname7 };
|
|
4297
|
+
}
|
|
4298
|
+
}
|
|
4325
4299
|
}
|
|
4326
|
-
function
|
|
4327
|
-
|
|
4300
|
+
function copyExtras(src, dst) {
|
|
4301
|
+
rmSync10(dst, { recursive: true, force: true });
|
|
4302
|
+
cpSync6(src, dst, { recursive: true, force: true, verbatimSymlinks: true });
|
|
4328
4303
|
}
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4304
|
+
|
|
4305
|
+
// src/extras-sync.ts
|
|
4306
|
+
init_utils();
|
|
4307
|
+
init_utils_json();
|
|
4308
|
+
|
|
4309
|
+
// src/extras-sync.remap.ts
|
|
4310
|
+
init_config();
|
|
4311
|
+
import { existsSync as existsSync31, mkdirSync as mkdirSync7 } from "node:fs";
|
|
4312
|
+
import { join as join37 } from "node:path";
|
|
4313
|
+
init_utils_fs();
|
|
4314
|
+
function runExtrasOp(v, dryRun, paths, backup) {
|
|
4315
|
+
const counts = { unmapped: 0, skipped: 0 };
|
|
4316
|
+
const done = [];
|
|
4317
|
+
const would = [];
|
|
4318
|
+
for (const t of eachExtrasTarget(v, counts)) {
|
|
4319
|
+
const { src, dst } = paths(t);
|
|
4320
|
+
if (!existsSync31(src)) continue;
|
|
4321
|
+
const item2 = `${t.logical}/${t.dirname}`;
|
|
4322
|
+
if (dryRun) {
|
|
4323
|
+
would.push(item2);
|
|
4324
|
+
continue;
|
|
4334
4325
|
}
|
|
4326
|
+
backup(dst, t.localRoot);
|
|
4327
|
+
copyExtras(src, dst);
|
|
4328
|
+
done.push(item2);
|
|
4335
4329
|
}
|
|
4336
|
-
|
|
4337
|
-
addItem(s, `note: ${note}`);
|
|
4338
|
-
}
|
|
4339
|
-
return s;
|
|
4330
|
+
return { ...counts, done, would };
|
|
4340
4331
|
}
|
|
4341
|
-
function
|
|
4332
|
+
function remapExtrasPush(ts, opts = {}) {
|
|
4333
|
+
const dryRun = opts.dryRun === true;
|
|
4334
|
+
const v = loadValidatedExtras({ missingMsg: "no path-map.json; skipping extras push" });
|
|
4335
|
+
if (v === null) return { unmapped: 0, skipped: 0, pushed: [], wouldPush: [] };
|
|
4342
4336
|
const repo = repoHome();
|
|
4343
|
-
const
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
join37(repo, "hosts", `${HOST}.json`),
|
|
4354
|
-
join37(claude, "settings.json")
|
|
4337
|
+
const repoExtras = join37(repo, "shared", "extras");
|
|
4338
|
+
if (!dryRun) mkdirSync7(repoExtras, { recursive: true });
|
|
4339
|
+
const { unmapped, skipped, done, would } = runExtrasOp(
|
|
4340
|
+
v,
|
|
4341
|
+
dryRun,
|
|
4342
|
+
({ localRoot, logical, dirname: dirname7 }) => ({
|
|
4343
|
+
src: join37(localRoot, dirname7),
|
|
4344
|
+
dst: join37(repoExtras, logical, dirname7)
|
|
4345
|
+
}),
|
|
4346
|
+
(dst) => backupRepoWrite(dst, ts, repo)
|
|
4355
4347
|
);
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4348
|
+
return { unmapped, skipped, pushed: done, wouldPush: would };
|
|
4349
|
+
}
|
|
4350
|
+
function remapExtrasPull(ts, opts = {}) {
|
|
4351
|
+
const dryRun = opts.dryRun === true;
|
|
4352
|
+
const v = loadValidatedExtras({
|
|
4353
|
+
requireRepoExtras: true,
|
|
4354
|
+
missingMsg: "no path-map or repo extras dir; skipping extras remap"
|
|
4361
4355
|
});
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4356
|
+
if (v === null) return { unmapped: 0, skipped: 0, pulled: [], wouldPull: [] };
|
|
4357
|
+
const repoExtras = join37(repoHome(), "shared", "extras");
|
|
4358
|
+
const { unmapped, skipped, done, would } = runExtrasOp(
|
|
4359
|
+
v,
|
|
4360
|
+
dryRun,
|
|
4361
|
+
({ localRoot, logical, dirname: dirname7 }) => ({
|
|
4362
|
+
src: join37(repoExtras, logical, dirname7),
|
|
4363
|
+
dst: join37(localRoot, dirname7)
|
|
4364
|
+
}),
|
|
4365
|
+
// Snapshot the host-side dst BEFORE copyExtras clobbers it. Anchor on
|
|
4366
|
+
// localRoot so the backup tree mirrors the project layout.
|
|
4367
|
+
(dst, localRoot) => backupExtrasWrite(dst, ts, localRoot)
|
|
4368
|
+
);
|
|
4369
|
+
return { unmapped, skipped, pulled: done, wouldPull: would };
|
|
4366
4370
|
}
|
|
4367
4371
|
|
|
4368
|
-
// src/
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4372
|
+
// src/extras-sync.ts
|
|
4373
|
+
function divergenceCheckExtras(ts) {
|
|
4374
|
+
const v = loadValidatedExtras({});
|
|
4375
|
+
if (v === null) return;
|
|
4376
|
+
const counts = { unmapped: 0, skipped: 0 };
|
|
4377
|
+
const backupRoot = join38(backupBase(), ts, "extras");
|
|
4378
|
+
const repo = repoHome();
|
|
4379
|
+
for (const { logical, localRoot, dirname: dirname7 } of eachExtrasTarget(v, counts)) {
|
|
4380
|
+
const local = join38(localRoot, dirname7);
|
|
4381
|
+
const repoEntry = join38(repo, "shared", "extras", logical, dirname7);
|
|
4382
|
+
if (!existsSync32(local) || !existsSync32(repoEntry)) continue;
|
|
4383
|
+
const diff = listDivergingFiles(local, repoEntry);
|
|
4384
|
+
if (diff.length === 0) continue;
|
|
4385
|
+
const projectBackupRoot = join38(backupRoot, encodePath(localRoot));
|
|
4386
|
+
warn(
|
|
4387
|
+
`local ${dirname7} for ${logical} diverges from origin in ${diff.length} file(s); next remapExtrasPull will overwrite them (backups at ${projectBackupRoot}/)`
|
|
4388
|
+
);
|
|
4389
|
+
for (const f of diff) warn(` ${f}`);
|
|
4390
|
+
}
|
|
4391
|
+
}
|
|
4379
4392
|
|
|
4380
|
-
// src/
|
|
4393
|
+
// src/links.ts
|
|
4381
4394
|
init_config();
|
|
4382
|
-
init_config_sharedDirs_guard();
|
|
4383
|
-
import { cpSync as cpSync6, existsSync as existsSync33, mkdirSync as mkdirSync7, statSync as statSync8 } from "node:fs";
|
|
4384
|
-
import { dirname as dirname6, join as join38, sep as sep3 } from "node:path";
|
|
4385
|
-
init_push_gitleaks_scan();
|
|
4386
|
-
init_utils_json();
|
|
4387
4395
|
init_utils();
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4396
|
+
init_utils_fs();
|
|
4397
|
+
init_utils_json();
|
|
4398
|
+
import { existsSync as existsSync33, lstatSync as lstatSync8, rmSync as rmSync11 } from "node:fs";
|
|
4399
|
+
import { join as join39 } from "node:path";
|
|
4400
|
+
function emitAutoMove(onPreview, linkPath, ts, name) {
|
|
4401
|
+
if (onPreview) {
|
|
4402
|
+
onPreview({ kind: "auto-move", from: linkPath, to: `backup/${ts}/${name}` });
|
|
4403
|
+
} else {
|
|
4404
|
+
log(`would auto-move non-symlink: ${linkPath} -> backup/${ts}/${name}`);
|
|
4405
|
+
}
|
|
4393
4406
|
}
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4407
|
+
function emitCreate(onPreview, from, to) {
|
|
4408
|
+
if (onPreview) {
|
|
4409
|
+
onPreview({ kind: "create", from, to });
|
|
4410
|
+
} else {
|
|
4411
|
+
log(`would create symlink: ${from} -> ${to}`);
|
|
4412
|
+
}
|
|
4400
4413
|
}
|
|
4401
|
-
function
|
|
4402
|
-
|
|
4403
|
-
if (t === "r" || t === "redact") return "redact";
|
|
4404
|
-
if (t === "a" || t === "allow") return "allow";
|
|
4405
|
-
if (t === "d" || t === "drop") return "drop";
|
|
4406
|
-
return "skip";
|
|
4414
|
+
function isAlreadySymlink(linkPath) {
|
|
4415
|
+
return existsSync33(linkPath) && lstatSync8(linkPath).isSymbolicLink();
|
|
4407
4416
|
}
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
if (
|
|
4415
|
-
if (
|
|
4416
|
-
|
|
4417
|
+
function runAutoMovePasses(linkNames, claude, repo, ts, dryRun, onPreview) {
|
|
4418
|
+
for (const name of linkNames) {
|
|
4419
|
+
const linkPath = join39(claude, name);
|
|
4420
|
+
const target = join39(repo, "shared", name);
|
|
4421
|
+
if (!existsSync33(linkPath)) continue;
|
|
4422
|
+
if (lstatSync8(linkPath).isSymbolicLink()) continue;
|
|
4423
|
+
if (!existsSync33(target)) continue;
|
|
4424
|
+
if (dryRun) {
|
|
4425
|
+
emitAutoMove(onPreview, linkPath, ts, name);
|
|
4426
|
+
continue;
|
|
4417
4427
|
}
|
|
4428
|
+
backupBeforeWrite(linkPath, ts);
|
|
4429
|
+
rmSync11(linkPath, { recursive: true, force: true });
|
|
4418
4430
|
}
|
|
4419
|
-
return null;
|
|
4420
4431
|
}
|
|
4421
|
-
function
|
|
4422
|
-
const
|
|
4423
|
-
log(msg);
|
|
4424
|
-
return false;
|
|
4425
|
-
};
|
|
4432
|
+
function applySharedLinks(ts, map, opts = {}) {
|
|
4433
|
+
const dryRun = opts.dryRun === true;
|
|
4426
4434
|
const claude = claudeHome();
|
|
4427
4435
|
const repo = repoHome();
|
|
4428
|
-
const
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
);
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
const sessionDir = join38(dirname6(localPath), sid);
|
|
4441
|
-
const subtreeFiles = listSubtreeFiles(sessionDir);
|
|
4442
|
-
const subtreeMtime = newestSubtreeMtimeMs(localPath, subtreeFiles, (p) => statSync8(p).mtimeMs);
|
|
4443
|
-
if (isRecentlyModified(subtreeMtime, nowMs())) {
|
|
4444
|
-
return refuse(
|
|
4445
|
-
`session ${sid} looks active (modified within the last 5 minutes); refusing to redact, no changes made.
|
|
4446
|
-
End the session and choose Redact again, or choose Drop session (holds this session back from the push, local copy kept) or Skip.`
|
|
4447
|
-
);
|
|
4448
|
-
}
|
|
4449
|
-
const stagedProjectDir = resolveStagedDir(localPath, map, claude, repo);
|
|
4450
|
-
if (stagedProjectDir === null) {
|
|
4451
|
-
return refuse(
|
|
4452
|
-
`could not map the local transcript for session ${sid} to a staged copy; choose Drop session or Skip.`
|
|
4453
|
-
);
|
|
4436
|
+
const linkNames = allSharedLinks(map);
|
|
4437
|
+
runAutoMovePasses(linkNames, claude, repo, ts, dryRun, opts.onPreview);
|
|
4438
|
+
for (const name of linkNames) {
|
|
4439
|
+
const target = join39(repo, "shared", name);
|
|
4440
|
+
if (!existsSync33(target)) continue;
|
|
4441
|
+
const linkPath = join39(claude, name);
|
|
4442
|
+
if (isAlreadySymlink(linkPath)) continue;
|
|
4443
|
+
if (dryRun) {
|
|
4444
|
+
emitCreate(opts.onPreview, linkPath, target);
|
|
4445
|
+
continue;
|
|
4446
|
+
}
|
|
4447
|
+
ensureSymlink(linkPath, target);
|
|
4454
4448
|
}
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4449
|
+
}
|
|
4450
|
+
function regenerateSettings(ts, opts = {}) {
|
|
4451
|
+
const dryRun = opts.dryRun === true;
|
|
4452
|
+
const repo = repoHome();
|
|
4453
|
+
const claude = claudeHome();
|
|
4454
|
+
const basePath = join39(repo, "shared", "settings.base.json");
|
|
4455
|
+
const hostPath = join39(repo, "hosts", `${HOST}.json`);
|
|
4456
|
+
if (!existsSync33(basePath)) {
|
|
4457
|
+
die("repo not initialized; run 'nomad init' to scaffold");
|
|
4458
4458
|
}
|
|
4459
|
-
const
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4459
|
+
const base = readJson(basePath);
|
|
4460
|
+
const hasOverrides = existsSync33(hostPath);
|
|
4461
|
+
const overrides = hasOverrides ? readJson(hostPath) : {};
|
|
4462
|
+
const merged = deepMerge(base, overrides);
|
|
4463
|
+
const settingsPath = join39(claude, "settings.json");
|
|
4464
|
+
if (!hasOverrides && existsSync33(settingsPath)) {
|
|
4465
|
+
try {
|
|
4466
|
+
const existing = readJson(settingsPath);
|
|
4467
|
+
const baseKeys = new Set(Object.keys(base));
|
|
4468
|
+
const drift = Object.keys(existing).filter((k) => !baseKeys.has(k));
|
|
4469
|
+
if (drift.length > 0) {
|
|
4470
|
+
warn(
|
|
4471
|
+
`no hosts/${HOST}.json found; existing settings has unbased keys ${JSON.stringify(drift)}. Set NOMAD_HOST to match a hosts/*.json or rerun 'nomad doctor' for candidates.`
|
|
4472
|
+
);
|
|
4473
|
+
}
|
|
4474
|
+
} catch {
|
|
4475
|
+
warn("existing settings.json is malformed; skipping drift-check and regenerating.");
|
|
4476
|
+
}
|
|
4472
4477
|
}
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4478
|
+
const overrideLabel = hasOverrides ? `${HOST}.json` : "no host overrides";
|
|
4479
|
+
if (dryRun) {
|
|
4480
|
+
log(`would write settings.json (base + ${overrideLabel})`);
|
|
4481
|
+
return { label: overrideLabel };
|
|
4477
4482
|
}
|
|
4478
|
-
|
|
4483
|
+
backupBeforeWrite(settingsPath, ts);
|
|
4484
|
+
writeJsonAtomic(settingsPath, merged);
|
|
4485
|
+
return { label: overrideLabel };
|
|
4479
4486
|
}
|
|
4480
4487
|
|
|
4481
|
-
// src/
|
|
4488
|
+
// src/preview.ts
|
|
4482
4489
|
init_config();
|
|
4483
|
-
import {
|
|
4484
|
-
import { join as
|
|
4485
|
-
function dropSessionFromStaged(sid, map) {
|
|
4486
|
-
const logicals = Object.keys(map.projects);
|
|
4487
|
-
if (logicals.length === 0) return false;
|
|
4488
|
-
const repo = repoHome();
|
|
4489
|
-
for (const logical of logicals) {
|
|
4490
|
-
const jsonl = join39(repo, "shared", "projects", logical, `${sid}.jsonl`);
|
|
4491
|
-
const dir = join39(repo, "shared", "projects", logical, sid);
|
|
4492
|
-
rmSync10(jsonl, { force: true });
|
|
4493
|
-
rmSync10(dir, { recursive: true, force: true });
|
|
4494
|
-
}
|
|
4495
|
-
return true;
|
|
4496
|
-
}
|
|
4490
|
+
import { existsSync as existsSync34 } from "node:fs";
|
|
4491
|
+
import { join as join40 } from "node:path";
|
|
4497
4492
|
|
|
4498
|
-
//
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4493
|
+
// node_modules/diff/libesm/diff/base.js
|
|
4494
|
+
var Diff = class {
|
|
4495
|
+
diff(oldStr, newStr, options = {}) {
|
|
4496
|
+
let callback;
|
|
4497
|
+
if (typeof options === "function") {
|
|
4498
|
+
callback = options;
|
|
4499
|
+
options = {};
|
|
4500
|
+
} else if ("callback" in options) {
|
|
4501
|
+
callback = options.callback;
|
|
4502
|
+
}
|
|
4503
|
+
const oldString = this.castInput(oldStr, options);
|
|
4504
|
+
const newString = this.castInput(newStr, options);
|
|
4505
|
+
const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
|
|
4506
|
+
const newTokens = this.removeEmpty(this.tokenize(newString, options));
|
|
4507
|
+
return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
|
|
4507
4508
|
}
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4509
|
+
diffWithOptionsObj(oldTokens, newTokens, options, callback) {
|
|
4510
|
+
var _a;
|
|
4511
|
+
const done = (value) => {
|
|
4512
|
+
value = this.postProcess(value, options);
|
|
4513
|
+
if (callback) {
|
|
4514
|
+
setTimeout(function() {
|
|
4515
|
+
callback(value);
|
|
4516
|
+
}, 0);
|
|
4517
|
+
return void 0;
|
|
4518
|
+
} else {
|
|
4519
|
+
return value;
|
|
4520
|
+
}
|
|
4521
|
+
};
|
|
4522
|
+
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
4523
|
+
let editLength = 1;
|
|
4524
|
+
let maxEditLength = newLen + oldLen;
|
|
4525
|
+
if (options.maxEditLength != null) {
|
|
4526
|
+
maxEditLength = Math.min(maxEditLength, options.maxEditLength);
|
|
4527
|
+
}
|
|
4528
|
+
const maxExecutionTime = (_a = options.timeout) !== null && _a !== void 0 ? _a : Infinity;
|
|
4529
|
+
const abortAfterTimestamp = Date.now() + maxExecutionTime;
|
|
4530
|
+
const bestPath = [{ oldPos: -1, lastComponent: void 0 }];
|
|
4531
|
+
let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
|
|
4532
|
+
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
4533
|
+
return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
|
|
4534
|
+
}
|
|
4535
|
+
let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
|
|
4536
|
+
const execEditLength = () => {
|
|
4537
|
+
for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
|
|
4538
|
+
let basePath;
|
|
4539
|
+
const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
|
|
4540
|
+
if (removePath) {
|
|
4541
|
+
bestPath[diagonalPath - 1] = void 0;
|
|
4542
|
+
}
|
|
4543
|
+
let canAdd = false;
|
|
4544
|
+
if (addPath) {
|
|
4545
|
+
const addPathNewPos = addPath.oldPos - diagonalPath;
|
|
4546
|
+
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
|
|
4547
|
+
}
|
|
4548
|
+
const canRemove = removePath && removePath.oldPos + 1 < oldLen;
|
|
4549
|
+
if (!canAdd && !canRemove) {
|
|
4550
|
+
bestPath[diagonalPath] = void 0;
|
|
4551
|
+
continue;
|
|
4552
|
+
}
|
|
4553
|
+
if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
|
|
4554
|
+
basePath = this.addToPath(addPath, true, false, 0, options);
|
|
4555
|
+
} else {
|
|
4556
|
+
basePath = this.addToPath(removePath, false, true, 1, options);
|
|
4557
|
+
}
|
|
4558
|
+
newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
|
|
4559
|
+
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
4560
|
+
return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
|
|
4561
|
+
} else {
|
|
4562
|
+
bestPath[diagonalPath] = basePath;
|
|
4563
|
+
if (basePath.oldPos + 1 >= oldLen) {
|
|
4564
|
+
maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
|
|
4565
|
+
}
|
|
4566
|
+
if (newPos + 1 >= newLen) {
|
|
4567
|
+
minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
|
|
4568
|
+
}
|
|
4569
|
+
}
|
|
4570
|
+
}
|
|
4571
|
+
editLength++;
|
|
4572
|
+
};
|
|
4573
|
+
if (callback) {
|
|
4574
|
+
(function exec() {
|
|
4575
|
+
setTimeout(function() {
|
|
4576
|
+
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
|
|
4577
|
+
return callback(void 0);
|
|
4578
|
+
}
|
|
4579
|
+
if (!execEditLength()) {
|
|
4580
|
+
exec();
|
|
4581
|
+
}
|
|
4582
|
+
}, 0);
|
|
4583
|
+
})();
|
|
4584
|
+
} else {
|
|
4585
|
+
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
4586
|
+
const ret = execEditLength();
|
|
4587
|
+
if (ret) {
|
|
4588
|
+
return ret;
|
|
4589
|
+
}
|
|
4590
|
+
}
|
|
4515
4591
|
}
|
|
4516
4592
|
}
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
}
|
|
4529
|
-
|
|
4530
|
-
const action = ctx.actions.get(findingKey(f)) ?? "skip";
|
|
4531
|
-
if (action === "skip") return;
|
|
4532
|
-
const sid = sessionIdFromFinding(f);
|
|
4533
|
-
if (sid !== null && ctx.droppedSids.has(sid)) return;
|
|
4534
|
-
if (action === "allow") {
|
|
4535
|
-
applyAllow(f, ctx.repo);
|
|
4536
|
-
return;
|
|
4593
|
+
addToPath(path, added, removed, oldPosInc, options) {
|
|
4594
|
+
const last = path.lastComponent;
|
|
4595
|
+
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
4596
|
+
return {
|
|
4597
|
+
oldPos: path.oldPos + oldPosInc,
|
|
4598
|
+
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
4599
|
+
};
|
|
4600
|
+
} else {
|
|
4601
|
+
return {
|
|
4602
|
+
oldPos: path.oldPos + oldPosInc,
|
|
4603
|
+
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
4604
|
+
};
|
|
4605
|
+
}
|
|
4537
4606
|
}
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4607
|
+
extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
|
|
4608
|
+
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
4609
|
+
let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
|
|
4610
|
+
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
|
|
4611
|
+
newPos++;
|
|
4612
|
+
oldPos++;
|
|
4613
|
+
commonCount++;
|
|
4614
|
+
if (options.oneChangePerToken) {
|
|
4615
|
+
basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
4616
|
+
}
|
|
4545
4617
|
}
|
|
4546
|
-
|
|
4618
|
+
if (commonCount && !options.oneChangePerToken) {
|
|
4619
|
+
basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
4620
|
+
}
|
|
4621
|
+
basePath.oldPos = oldPos;
|
|
4622
|
+
return newPos;
|
|
4547
4623
|
}
|
|
4548
|
-
|
|
4549
|
-
if (
|
|
4624
|
+
equals(left, right, options) {
|
|
4625
|
+
if (options.comparator) {
|
|
4626
|
+
return options.comparator(left, right);
|
|
4627
|
+
} else {
|
|
4628
|
+
return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|
4629
|
+
}
|
|
4550
4630
|
}
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
repo,
|
|
4560
|
-
scan,
|
|
4561
|
-
drop,
|
|
4562
|
-
redactedSids: /* @__PURE__ */ new Set(),
|
|
4563
|
-
droppedSids: /* @__PURE__ */ new Set()
|
|
4564
|
-
};
|
|
4565
|
-
for (const f of findings) {
|
|
4566
|
-
dispatchOne(f, ctx);
|
|
4631
|
+
removeEmpty(array) {
|
|
4632
|
+
const ret = [];
|
|
4633
|
+
for (let i = 0; i < array.length; i++) {
|
|
4634
|
+
if (array[i]) {
|
|
4635
|
+
ret.push(array[i]);
|
|
4636
|
+
}
|
|
4637
|
+
}
|
|
4638
|
+
return ret;
|
|
4567
4639
|
}
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
for (const f of findings) {
|
|
4572
|
-
const sid = sessionIdFromFinding(f);
|
|
4573
|
-
if (sid === null || redactedSids.has(sid)) continue;
|
|
4574
|
-
if (applyRedact(f, ts, map, nowMs, scan)) redactedSids.add(sid);
|
|
4640
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4641
|
+
castInput(value, options) {
|
|
4642
|
+
return value;
|
|
4575
4643
|
}
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
init_push_gitleaks_scan();
|
|
4580
|
-
init_push_gitleaks();
|
|
4581
|
-
init_utils();
|
|
4582
|
-
function isTTY(stdin = process.stdin, stdout = process.stdout) {
|
|
4583
|
-
return stdin.isTTY === true && stdout.isTTY === true;
|
|
4584
|
-
}
|
|
4585
|
-
function hasUnresolved(actions) {
|
|
4586
|
-
for (const action of actions.values()) {
|
|
4587
|
-
if (action === "skip") return true;
|
|
4644
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4645
|
+
tokenize(value, options) {
|
|
4646
|
+
return Array.from(value);
|
|
4588
4647
|
}
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
function printRecoveryLegend(print = console.log) {
|
|
4592
|
-
print("");
|
|
4593
|
-
print("Recovery actions:");
|
|
4594
|
-
print(" Redact - scrub the secret from the local transcript, push the cleaned copy");
|
|
4595
|
-
print(" Allow - mark as false positive (adds a .gitleaksignore fingerprint), push as-is");
|
|
4596
|
-
print(" Drop session - exclude this session from this push (local transcript kept, running");
|
|
4597
|
-
print(" session is not stopped)");
|
|
4598
|
-
print(" Skip - leave unresolved (the push aborts)");
|
|
4599
|
-
print("");
|
|
4600
|
-
}
|
|
4601
|
-
function applyThenRescan(scanVerdict, repoHome2) {
|
|
4602
|
-
gitOrFatal(["add", "-A"], "git add", repoHome2);
|
|
4603
|
-
const next = scanVerdict(repoHome2);
|
|
4604
|
-
if (next.leak) {
|
|
4605
|
-
const { bySession, other } = partitionFindings(next.findings);
|
|
4606
|
-
throw new NomadFatal(buildSessionAwareFatal(bySession, other));
|
|
4648
|
+
join(chars) {
|
|
4649
|
+
return chars.join("");
|
|
4607
4650
|
}
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
function allowThenRescan(append, scanVerdict, repoHome2) {
|
|
4611
|
-
const ignPath = join40(repoHome2, ".gitleaksignore");
|
|
4612
|
-
let before;
|
|
4613
|
-
try {
|
|
4614
|
-
before = readFileSync12(ignPath, "utf8");
|
|
4615
|
-
} catch {
|
|
4616
|
-
before = null;
|
|
4651
|
+
postProcess(changeObjects, options) {
|
|
4652
|
+
return changeObjects;
|
|
4617
4653
|
}
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
return applyThenRescan(scanVerdict, repoHome2);
|
|
4621
|
-
} catch (err) {
|
|
4622
|
-
if (before === null) rmSync11(ignPath, { force: true });
|
|
4623
|
-
else writeFileSync5(ignPath, before, "utf8");
|
|
4624
|
-
throw err;
|
|
4654
|
+
get useLongestToken() {
|
|
4655
|
+
return false;
|
|
4625
4656
|
}
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4657
|
+
buildValues(lastComponent, newTokens, oldTokens) {
|
|
4658
|
+
const components = [];
|
|
4659
|
+
let nextComponent;
|
|
4660
|
+
while (lastComponent) {
|
|
4661
|
+
components.push(lastComponent);
|
|
4662
|
+
nextComponent = lastComponent.previousComponent;
|
|
4663
|
+
delete lastComponent.previousComponent;
|
|
4664
|
+
lastComponent = nextComponent;
|
|
4665
|
+
}
|
|
4666
|
+
components.reverse();
|
|
4667
|
+
const componentLen = components.length;
|
|
4668
|
+
let componentPos = 0, newPos = 0, oldPos = 0;
|
|
4669
|
+
for (; componentPos < componentLen; componentPos++) {
|
|
4670
|
+
const component = components[componentPos];
|
|
4671
|
+
if (!component.removed) {
|
|
4672
|
+
if (!component.added && this.useLongestToken) {
|
|
4673
|
+
let value = newTokens.slice(newPos, newPos + component.count);
|
|
4674
|
+
value = value.map(function(value2, i) {
|
|
4675
|
+
const oldValue = oldTokens[oldPos + i];
|
|
4676
|
+
return oldValue.length > value2.length ? oldValue : value2;
|
|
4677
|
+
});
|
|
4678
|
+
component.value = this.join(value);
|
|
4679
|
+
} else {
|
|
4680
|
+
component.value = this.join(newTokens.slice(newPos, newPos + component.count));
|
|
4681
|
+
}
|
|
4682
|
+
newPos += component.count;
|
|
4683
|
+
if (!component.added) {
|
|
4684
|
+
oldPos += component.count;
|
|
4685
|
+
}
|
|
4686
|
+
} else {
|
|
4687
|
+
component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
|
|
4688
|
+
oldPos += component.count;
|
|
4689
|
+
}
|
|
4638
4690
|
}
|
|
4639
|
-
|
|
4640
|
-
}
|
|
4641
|
-
async function resolveLeakFindings(verdict, ts, map, deps = {}) {
|
|
4642
|
-
const {
|
|
4643
|
-
isTTYCheck = isTTY,
|
|
4644
|
-
nowMs = Date.now,
|
|
4645
|
-
redactAll = false,
|
|
4646
|
-
allowAll = false,
|
|
4647
|
-
allowRule,
|
|
4648
|
-
makePrompt: makePromptFn = makeRealPrompt,
|
|
4649
|
-
scan = scanFile,
|
|
4650
|
-
printLegend = printRecoveryLegend
|
|
4651
|
-
} = deps;
|
|
4652
|
-
const scanVerdict = deps.scanVerdict ?? (await Promise.resolve().then(() => (init_push_leak_verdict(), push_leak_verdict_exports))).scanPushVerdict;
|
|
4653
|
-
const repo = repoHome();
|
|
4654
|
-
let current = verdict;
|
|
4655
|
-
if (redactAll) {
|
|
4656
|
-
redactAllFindings(current.findings, ts, map, nowMs, scan);
|
|
4657
|
-
return applyThenRescan(scanVerdict, repo);
|
|
4691
|
+
return components;
|
|
4658
4692
|
}
|
|
4659
|
-
|
|
4660
|
-
|
|
4693
|
+
};
|
|
4694
|
+
|
|
4695
|
+
// node_modules/diff/libesm/diff/line.js
|
|
4696
|
+
var LineDiff = class extends Diff {
|
|
4697
|
+
constructor() {
|
|
4698
|
+
super(...arguments);
|
|
4699
|
+
this.tokenize = tokenize;
|
|
4661
4700
|
}
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
()
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
)
|
|
4701
|
+
equals(left, right, options) {
|
|
4702
|
+
if (options.ignoreWhitespace) {
|
|
4703
|
+
if (!options.newlineIsToken || !left.includes("\n")) {
|
|
4704
|
+
left = left.trim();
|
|
4705
|
+
}
|
|
4706
|
+
if (!options.newlineIsToken || !right.includes("\n")) {
|
|
4707
|
+
right = right.trim();
|
|
4708
|
+
}
|
|
4709
|
+
} else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
|
|
4710
|
+
if (left.endsWith("\n")) {
|
|
4711
|
+
left = left.slice(0, -1);
|
|
4712
|
+
}
|
|
4713
|
+
if (right.endsWith("\n")) {
|
|
4714
|
+
right = right.slice(0, -1);
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4717
|
+
return super.equals(left, right, options);
|
|
4671
4718
|
}
|
|
4672
|
-
|
|
4673
|
-
|
|
4719
|
+
};
|
|
4720
|
+
var lineDiff = new LineDiff();
|
|
4721
|
+
function diffLines(oldStr, newStr, options) {
|
|
4722
|
+
return lineDiff.diff(oldStr, newStr, options);
|
|
4723
|
+
}
|
|
4724
|
+
function tokenize(value, options) {
|
|
4725
|
+
if (options.stripTrailingCr) {
|
|
4726
|
+
value = value.replace(/\r\n/g, "\n");
|
|
4674
4727
|
}
|
|
4675
|
-
const
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4728
|
+
const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
|
|
4729
|
+
if (!linesAndNewlines[linesAndNewlines.length - 1]) {
|
|
4730
|
+
linesAndNewlines.pop();
|
|
4731
|
+
}
|
|
4732
|
+
for (let i = 0; i < linesAndNewlines.length; i++) {
|
|
4733
|
+
const line = linesAndNewlines[i];
|
|
4734
|
+
if (i % 2 && !options.newlineIsToken) {
|
|
4735
|
+
retLines[retLines.length - 1] += line;
|
|
4736
|
+
} else {
|
|
4737
|
+
retLines.push(line);
|
|
4683
4738
|
}
|
|
4684
|
-
dispatchActions(current.findings, actions, { ts, map, nowMs, repo, scan });
|
|
4685
|
-
gitOrFatal(["add", "-A"], "git add", repo);
|
|
4686
|
-
current = scanVerdict(repo);
|
|
4687
4739
|
}
|
|
4688
|
-
return
|
|
4740
|
+
return retLines;
|
|
4689
4741
|
}
|
|
4690
4742
|
|
|
4691
|
-
// src/
|
|
4692
|
-
|
|
4693
|
-
|
|
4743
|
+
// src/diff-lines.ts
|
|
4744
|
+
init_color();
|
|
4745
|
+
function diffLinesToUnified(oldStr, newStr) {
|
|
4746
|
+
const parts = diffLines(oldStr, newStr);
|
|
4747
|
+
const lines = [];
|
|
4748
|
+
for (const part of parts) {
|
|
4749
|
+
const partLines = part.value.split("\n");
|
|
4750
|
+
if (partLines.at(-1) === "") {
|
|
4751
|
+
partLines.pop();
|
|
4752
|
+
}
|
|
4753
|
+
let prefix;
|
|
4754
|
+
if (part.removed) prefix = (line) => red(`-${line}`);
|
|
4755
|
+
else if (part.added) prefix = (line) => green(`+${line}`);
|
|
4756
|
+
else prefix = (line) => ` ${line}`;
|
|
4757
|
+
for (const line of partLines) {
|
|
4758
|
+
lines.push(prefix(line));
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4761
|
+
return lines;
|
|
4694
4762
|
}
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4763
|
+
|
|
4764
|
+
// src/preview.ts
|
|
4765
|
+
init_utils_json();
|
|
4766
|
+
var CANONICAL_ORDER_NOTE = "settings.json will be rewritten in canonical key order; no value changes";
|
|
4767
|
+
function diffJsonStrings(currentJsonText, newJsonText) {
|
|
4768
|
+
if (currentJsonText === newJsonText) return "";
|
|
4769
|
+
const lines = [
|
|
4770
|
+
"--- ~/.claude/settings.json",
|
|
4771
|
+
"+++ would write",
|
|
4772
|
+
...diffLinesToUnified(currentJsonText, newJsonText)
|
|
4773
|
+
];
|
|
4774
|
+
return lines.join("\n");
|
|
4698
4775
|
}
|
|
4699
|
-
function
|
|
4700
|
-
|
|
4701
|
-
|
|
4776
|
+
function readJsonOrNull(path) {
|
|
4777
|
+
if (!existsSync34(path)) return null;
|
|
4778
|
+
try {
|
|
4779
|
+
return readJson(path);
|
|
4780
|
+
} catch {
|
|
4781
|
+
return null;
|
|
4782
|
+
}
|
|
4702
4783
|
}
|
|
4703
|
-
function
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4784
|
+
function previewSettings(basePath, hostPath, settingsPath) {
|
|
4785
|
+
const base = readJsonOrNull(basePath);
|
|
4786
|
+
if (base === null) {
|
|
4787
|
+
return { diff: "", notes: ["section skipped (base or current missing)"] };
|
|
4788
|
+
}
|
|
4789
|
+
const notes = [];
|
|
4790
|
+
const hostOverrides = readJsonOrNull(hostPath);
|
|
4791
|
+
if (hostOverrides === null && existsSync34(hostPath)) {
|
|
4792
|
+
notes.push(`malformed hosts/${HOST}.json; ignoring overrides`);
|
|
4793
|
+
}
|
|
4794
|
+
const merged = deepMerge(base, hostOverrides ?? {});
|
|
4795
|
+
const current = readJsonOrNull(settingsPath);
|
|
4796
|
+
if (current === null && existsSync34(settingsPath)) {
|
|
4797
|
+
return { diff: "", notes: [...notes, "malformed; skipping diff"] };
|
|
4798
|
+
}
|
|
4799
|
+
const rawEqual = JSON.stringify(current ?? {}, null, 2) === JSON.stringify(merged, null, 2);
|
|
4800
|
+
const diff = diffJsonStrings(
|
|
4801
|
+
JSON.stringify(sortKeysDeep(current ?? {}), null, 2),
|
|
4802
|
+
JSON.stringify(sortKeysDeep(merged), null, 2)
|
|
4803
|
+
);
|
|
4804
|
+
if (diff === "" && !rawEqual) notes.push(CANONICAL_ORDER_NOTE);
|
|
4805
|
+
return { diff, notes };
|
|
4708
4806
|
}
|
|
4709
|
-
function
|
|
4710
|
-
|
|
4711
|
-
const base = deps.baseUrl ?? import.meta.url;
|
|
4712
|
-
const mjs = fileURLToPath4(new URL("./nomad.worker.mjs", base));
|
|
4713
|
-
if (check(mjs)) return mjs;
|
|
4714
|
-
return fileURLToPath4(new URL("./spinner.worker.ts", base));
|
|
4807
|
+
function formatLinkRow(e) {
|
|
4808
|
+
return `${e.kind} ${e.from} -> ${e.to}`;
|
|
4715
4809
|
}
|
|
4716
|
-
function
|
|
4717
|
-
return
|
|
4810
|
+
function formatSessionRow(e) {
|
|
4811
|
+
return e.kind === "overwrite" ? `overwrite ${e.dst} (from ${e.src})` : e.text;
|
|
4718
4812
|
}
|
|
4719
|
-
function
|
|
4720
|
-
const
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
const startMs = now();
|
|
4725
|
-
const animate = ttyCheck() && !env.CI;
|
|
4726
|
-
let worker = null;
|
|
4727
|
-
let degraded = false;
|
|
4728
|
-
let finalized = false;
|
|
4729
|
-
if (animate) {
|
|
4730
|
-
const factory = deps.makeWorker ?? makeRealWorker;
|
|
4731
|
-
try {
|
|
4732
|
-
worker = factory();
|
|
4733
|
-
worker.unref?.();
|
|
4734
|
-
worker.postMessage({ type: "start", label });
|
|
4735
|
-
} catch {
|
|
4736
|
-
degraded = true;
|
|
4737
|
-
worker = null;
|
|
4738
|
-
writePlainStart(out, label);
|
|
4813
|
+
function buildSettingsSectionForPreview(result) {
|
|
4814
|
+
const s = section("settings.json", true);
|
|
4815
|
+
if (result.diff !== "") {
|
|
4816
|
+
for (const line of result.diff.split("\n")) {
|
|
4817
|
+
addItem(s, line);
|
|
4739
4818
|
}
|
|
4740
|
-
} else {
|
|
4741
|
-
writePlainStart(out, label);
|
|
4742
4819
|
}
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
finalized = true;
|
|
4746
|
-
const dl = doneLabel ?? label;
|
|
4747
|
-
const elapsed = now() - startMs;
|
|
4748
|
-
if (animate && !degraded && worker !== null) {
|
|
4749
|
-
worker.postMessage({ type: "pause" });
|
|
4750
|
-
worker.terminate();
|
|
4751
|
-
worker = null;
|
|
4752
|
-
if (success) writeAnimatedDone(out, dl, elapsed, ttyCheck());
|
|
4753
|
-
else out.write("\r\x1B[K");
|
|
4754
|
-
} else if (success) {
|
|
4755
|
-
writePlainDone(out, dl, elapsed);
|
|
4756
|
-
}
|
|
4820
|
+
for (const note of result.notes) {
|
|
4821
|
+
addItem(s, `note: ${note}`);
|
|
4757
4822
|
}
|
|
4758
|
-
return
|
|
4759
|
-
succeed: (doneLabel) => finalize(true, doneLabel),
|
|
4760
|
-
stop: () => finalize(false)
|
|
4761
|
-
};
|
|
4823
|
+
return s;
|
|
4762
4824
|
}
|
|
4763
|
-
function
|
|
4764
|
-
const
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4825
|
+
function computePreview(ts, map, verb = "pull") {
|
|
4826
|
+
const repo = repoHome();
|
|
4827
|
+
const claude = claudeHome();
|
|
4828
|
+
console.log(`would pull on host=${HOST} (dry-run; no mutation)`);
|
|
4829
|
+
console.log("");
|
|
4830
|
+
const links = section("Symlinks");
|
|
4831
|
+
applySharedLinks(ts, map, {
|
|
4832
|
+
dryRun: true,
|
|
4833
|
+
onPreview: (e) => addItem(links, formatLinkRow(e))
|
|
4834
|
+
});
|
|
4835
|
+
const settingsResult = previewSettings(
|
|
4836
|
+
join40(repo, "shared", "settings.base.json"),
|
|
4837
|
+
join40(repo, "hosts", `${HOST}.json`),
|
|
4838
|
+
join40(claude, "settings.json")
|
|
4839
|
+
);
|
|
4840
|
+
const settingsSection = buildSettingsSectionForPreview(settingsResult);
|
|
4841
|
+
const sessions = section("Sessions");
|
|
4842
|
+
const remapResult = remapPull(ts, {
|
|
4843
|
+
dryRun: true,
|
|
4844
|
+
onPreview: (e) => addItem(sessions, formatSessionRow(e))
|
|
4845
|
+
});
|
|
4846
|
+
const summary = section("Summary");
|
|
4847
|
+
addItem(summary, summaryRow(verb, remapResult.unmapped));
|
|
4848
|
+
renderTree([links, settingsSection, sessions, summary]);
|
|
4849
|
+
return { unmapped: remapResult.unmapped, collisions: 0 };
|
|
4772
4850
|
}
|
|
4773
4851
|
|
|
4774
4852
|
// src/commands.pull.recovery.ts
|
|
@@ -5724,7 +5802,7 @@ function parsePushArgs(argv) {
|
|
|
5724
5802
|
// package.json
|
|
5725
5803
|
var package_default = {
|
|
5726
5804
|
name: "claude-nomad",
|
|
5727
|
-
version: "0.
|
|
5805
|
+
version: "0.46.0",
|
|
5728
5806
|
type: "module",
|
|
5729
5807
|
description: "Sync Claude Code config (~/.claude/) across machines via a private Git repo, with path remapping and per-host settings overrides.",
|
|
5730
5808
|
keywords: [
|
|
@@ -5926,7 +6004,7 @@ var DEFAULT_HELP = [
|
|
|
5926
6004
|
init_config();
|
|
5927
6005
|
init_utils();
|
|
5928
6006
|
init_utils_json();
|
|
5929
|
-
import { existsSync as existsSync41, readFileSync as
|
|
6007
|
+
import { existsSync as existsSync41, readFileSync as readFileSync14, readdirSync as readdirSync12 } from "node:fs";
|
|
5930
6008
|
import { join as join47 } from "node:path";
|
|
5931
6009
|
function resumeCmd(sessionId) {
|
|
5932
6010
|
if (!/^[A-Za-z0-9_-]+$/.test(sessionId) || sessionId.length > 128) {
|
|
@@ -5978,7 +6056,7 @@ function findTranscriptPath(projectsRoot, sessionId) {
|
|
|
5978
6056
|
return null;
|
|
5979
6057
|
}
|
|
5980
6058
|
function extractRecordedCwd(jsonlPath) {
|
|
5981
|
-
for (const line of
|
|
6059
|
+
for (const line of readFileSync14(jsonlPath, "utf8").split("\n")) {
|
|
5982
6060
|
if (!line.trim()) continue;
|
|
5983
6061
|
try {
|
|
5984
6062
|
const obj = JSON.parse(line);
|