@holmes-lab/holmes-kit 0.30.0 → 0.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +505 -0
- package/README.md +10 -1
- package/bin/holmes-hook-antigravity.js +4 -0
- package/bin/holmes-kit.js +4 -0
- package/bin/holmes-pre-push.js +3 -0
- package/bin/holmes-stop-antigravity.js +4 -0
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/agents.d.ts +41 -0
- package/dist/holmes/cli/agents.js +382 -2
- package/dist/holmes/cli/attest.d.ts +2 -0
- package/dist/holmes/cli/attest.js +66 -15
- package/dist/holmes/cli/ci-gate.js +16 -1
- package/dist/holmes/cli/claude-switches.d.ts +95 -0
- package/dist/holmes/cli/claude-switches.js +967 -0
- package/dist/holmes/cli/codex-hooks.d.ts +77 -0
- package/dist/holmes/cli/codex-hooks.js +802 -0
- package/dist/holmes/cli/codex-oracle.d.ts +194 -0
- package/dist/holmes/cli/codex-oracle.js +1245 -0
- package/dist/holmes/cli/codex-toml.d.ts +35 -0
- package/dist/holmes/cli/codex-toml.js +321 -52
- package/dist/holmes/cli/doctor.d.ts +98 -8
- package/dist/holmes/cli/doctor.js +1328 -94
- package/dist/holmes/cli/index.js +26 -11
- package/dist/holmes/cli/init.d.ts +11 -0
- package/dist/holmes/cli/init.js +736 -44
- package/dist/holmes/cli/mcp-launcher.d.ts +64 -6
- package/dist/holmes/cli/mcp-launcher.js +189 -6
- package/dist/holmes/cli/mcp-version.js +13 -2
- package/dist/holmes/cli/settings-merge.js +8 -2
- package/dist/holmes/cli/upgrade.d.ts +18 -0
- package/dist/holmes/cli/upgrade.js +129 -24
- package/dist/holmes/cli/workspace-scope.d.ts +22 -0
- package/dist/holmes/cli/workspace-scope.js +375 -0
- package/dist/holmes/cpg/cpg-scanner.d.ts +29 -0
- package/dist/holmes/cpg/cpg-scanner.js +403 -3
- package/dist/holmes/cpg/cycle-detect.js +2 -1
- package/dist/holmes/cpg/forbidden-edges.js +9 -2
- package/dist/holmes/cpg/required-calls.js +8 -1
- package/dist/holmes/governance/constitution-debt.js +3 -2
- package/dist/holmes/governance/constitution.js +15 -3
- package/dist/holmes/governance/provenance-chain.js +3 -2
- package/dist/holmes/governance/push-gate-runner.js +4 -3
- package/dist/holmes/guardrail/dependency-delta.js +4 -3
- package/dist/holmes/guardrail/linear-match.d.ts +57 -0
- package/dist/holmes/guardrail/linear-match.js +256 -0
- package/dist/holmes/guardrail/risk-classifier.d.ts +6 -7
- package/dist/holmes/guardrail/risk-classifier.js +931 -44
- package/dist/holmes/guardrail/risk-types.d.ts +6 -0
- package/dist/holmes/guardrail/scope-judgment.d.ts +4 -24
- package/dist/holmes/guardrail/scope-judgment.js +100 -23
- package/dist/holmes/guardrail/shell-words.d.ts +42 -0
- package/dist/holmes/guardrail/shell-words.js +1720 -0
- package/dist/holmes/guardrail/write-target.d.ts +168 -3
- package/dist/holmes/guardrail/write-target.js +2379 -87
- package/dist/holmes/hooks/adapters/antigravity.d.ts +3 -1
- package/dist/holmes/hooks/adapters/antigravity.js +115 -11
- package/dist/holmes/hooks/pre-tool-use.d.ts +32 -6
- package/dist/holmes/hooks/pre-tool-use.js +923 -87
- package/dist/holmes/hooks/rtm-refresh-child.js +3 -1
- package/dist/holmes/hooks/rtm-refresh.js +8 -4
- package/dist/holmes/hooks/session-start.d.ts +10 -0
- package/dist/holmes/hooks/session-start.js +31 -7
- package/dist/holmes/hooks/stop.d.ts +2 -1
- package/dist/holmes/hooks/stop.js +197 -91
- package/dist/holmes/mcp/approval-commit.d.ts +5 -6
- package/dist/holmes/mcp/approval-commit.js +18 -2
- package/dist/holmes/mcp/elicit-approval.js +4 -2
- package/dist/holmes/mcp/handlers/graph-operations.js +3 -2
- package/dist/holmes/mcp/handlers/maintenance-analysis.js +11 -5
- package/dist/holmes/mcp/handlers/maintenance-evidence.js +3 -2
- package/dist/holmes/mcp/handlers/phase-queries.d.ts +22 -7
- package/dist/holmes/mcp/handlers/phase-queries.js +81 -2
- package/dist/holmes/mcp/handlers/requirement-triage.js +5 -3
- package/dist/holmes/mcp/handlers/review-evidence.js +8 -2
- package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +11 -0
- package/dist/holmes/mcp/handlers/slice-orchestration.js +115 -16
- package/dist/holmes/mcp/handlers/spec-approval.d.ts +9 -0
- package/dist/holmes/mcp/handlers/spec-approval.js +110 -17
- package/dist/holmes/mcp/handlers/spec-authoring.js +17 -2
- package/dist/holmes/mcp/handlers/spec-queries.d.ts +39 -3
- package/dist/holmes/mcp/handlers/spec-queries.js +114 -7
- package/dist/holmes/mcp/handlers/test-execution.js +9 -3
- package/dist/holmes/mcp/handlers.d.ts +81 -9
- package/dist/holmes/mcp/handlers.js +70 -23
- package/dist/holmes/mcp/harness-attestation.d.ts +20 -0
- package/dist/holmes/mcp/harness-attestation.js +179 -0
- package/dist/holmes/mcp/requirement-triage-evidence.d.ts +36 -0
- package/dist/holmes/mcp/requirement-triage-evidence.js +160 -4
- package/dist/holmes/mcp/server.js +20 -1
- package/dist/holmes/mcp/tool-schemas.js +26 -9
- package/dist/holmes/mcp/validate-args.js +12 -0
- package/dist/holmes/project/bounded-io.d.ts +102 -0
- package/dist/holmes/project/bounded-io.js +212 -0
- package/dist/holmes/project/change-source.js +3 -1
- package/dist/holmes/project/ci-runs.js +3 -2
- package/dist/holmes/project/ignore.d.ts +31 -2
- package/dist/holmes/project/ignore.js +409 -50
- package/dist/holmes/project/regular-file-guard.d.ts +13 -0
- package/dist/holmes/project/regular-file-guard.js +149 -0
- package/dist/holmes/project/root.js +12 -3
- package/dist/holmes/reverse/anchor.js +4 -3
- package/dist/holmes/reverse/scan.js +6 -2
- package/dist/holmes/review/commit-text.js +3 -2
- package/dist/holmes/review/condition-hunk-replay.js +3 -2
- package/dist/holmes/review/failed-test-names.js +13 -10
- package/dist/holmes/review/findings.js +3 -1
- package/dist/holmes/review/kills-check.js +6 -1
- package/dist/holmes/review/point-in-time-replay.js +5 -4
- package/dist/holmes/review/replay-corpus.js +5 -4
- package/dist/holmes/review/run-replay.js +3 -2
- package/dist/holmes/review/temporal-prior.js +3 -2
- package/dist/holmes/review/test-evidence.js +3 -2
- package/dist/holmes/review/test-outcomes.js +3 -2
- package/dist/holmes/review/test-runner.d.ts +6 -0
- package/dist/holmes/review/test-runner.js +36 -15
- package/dist/holmes/rtm/advisory-outcomes.js +3 -2
- package/dist/holmes/rtm/anchor-ids.js +42 -2
- package/dist/holmes/rtm/file-anchors.js +4 -1
- package/dist/holmes/rtm/ftt-fulfilment.js +8 -3
- package/dist/holmes/rtm/git-changes.js +3 -1
- package/dist/holmes/rtm/graph-store.js +3 -2
- package/dist/holmes/rtm/test-scope.js +9 -4
- package/dist/holmes/spec/compat-impact.d.ts +25 -4
- package/dist/holmes/spec/compat-impact.js +682 -11
- package/dist/holmes/spec/entity-git-snapshot.js +3 -2
- package/dist/holmes/spec/entity-integration.js +3 -2
- package/dist/holmes/spec/entity-renumber-transaction.d.ts +19 -0
- package/dist/holmes/spec/entity-renumber-transaction.js +79 -6
- package/dist/holmes/spec/remote-spec-refs.js +3 -2
- package/dist/holmes/spec/renumber.js +25 -10
- package/dist/holmes/spec/spec-parser.js +9 -3
- package/dist/holmes/spec/yaml-scalar.js +2 -2
- package/dist/holmes/update/refresh.d.ts +5 -0
- package/dist/holmes/update/refresh.js +26 -1
- package/dist/holmes/update/update-notice.d.ts +6 -0
- package/dist/holmes/update/update-notice.js +18 -1
- package/dist/holmes/update/upgrade-plan.d.ts +28 -0
- package/dist/holmes/update/upgrade-plan.js +31 -2
- package/package.json +11 -4
|
@@ -33,9 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.renderPlan = renderPlan;
|
|
36
37
|
exports.runUpgrade = runUpgrade;
|
|
37
38
|
// @implements A-SPEC-709
|
|
38
39
|
// @implements A-SPEC-543.2
|
|
40
|
+
// @implements A-SPEC-251.1
|
|
39
41
|
const fs = __importStar(require("node:fs"));
|
|
40
42
|
const os = __importStar(require("node:os"));
|
|
41
43
|
const path = __importStar(require("node:path"));
|
|
@@ -45,6 +47,7 @@ const workspaces_1 = require("../update/workspaces");
|
|
|
45
47
|
const upgrade_plan_1 = require("../update/upgrade-plan");
|
|
46
48
|
const session_start_1 = require("../hooks/session-start");
|
|
47
49
|
const npx_bin_1 = require("../project/npx-bin");
|
|
50
|
+
const codex_oracle_1 = require("./codex-oracle");
|
|
48
51
|
const PKG = '@holmes-lab/holmes-kit';
|
|
49
52
|
// Local copy of index.ts's packageRoot (dist/holmes/cli/upgrade.js → 3 up) — avoids a require cycle,
|
|
50
53
|
// since index.ts lazily requires THIS module.
|
|
@@ -61,14 +64,72 @@ function currentVersion(root) {
|
|
|
61
64
|
}
|
|
62
65
|
/** `npm` on POSIX, `npm.cmd` on win32 — the shim a spawn resolves (same binary-name reasoning as npxBin). */
|
|
63
66
|
function npmBin() { return process.platform === 'win32' ? 'npm.cmd' : 'npm'; }
|
|
64
|
-
/**
|
|
65
|
-
|
|
67
|
+
/** A-SPEC-251.1 (round 26): npm's own update check is not upgrade's egress (it raced every npm child — measured). */
|
|
68
|
+
const NPM_QUIET = ['--no-update-notifier'];
|
|
69
|
+
const realOrResolve = (p) => {
|
|
70
|
+
try {
|
|
71
|
+
return fs.realpathSync.native(p);
|
|
72
|
+
}
|
|
73
|
+
catch { /* not there yet */ }
|
|
74
|
+
try {
|
|
75
|
+
return path.join(fs.realpathSync.native(path.dirname(p)), path.basename(p));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return path.resolve(p);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* @implements A-SPEC-251.1 (confirmation round 24) — the holmes-kit install a workspace uses, found the way node finds a
|
|
83
|
+
* package: the nearest ancestor `node_modules/@holmes-lab/holmes-kit`. `pending` (the install this upgrade is about to
|
|
84
|
+
* write) counts even before it exists. A path-prefix test re-pinned an independent project nested under the installing
|
|
85
|
+
* one, and every workspace under a stray `~/node_modules` install (measured).
|
|
86
|
+
*/
|
|
87
|
+
function installOf(target, pending) {
|
|
88
|
+
let d = realOrResolve(target);
|
|
89
|
+
for (;;) {
|
|
90
|
+
const cand = path.join(d, 'node_modules', PKG);
|
|
91
|
+
const real = realOrResolve(cand);
|
|
92
|
+
if (real === pending || fs.existsSync(path.join(cand, 'package.json')))
|
|
93
|
+
return real;
|
|
94
|
+
const parent = path.dirname(d);
|
|
95
|
+
if (parent === d)
|
|
96
|
+
return null;
|
|
97
|
+
d = parent;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function decideRepin(w, installMode, pkgDir) {
|
|
101
|
+
const agents = w.agents.length ? w.agents : ['claude'];
|
|
102
|
+
if (!fs.existsSync(w.target))
|
|
103
|
+
return { target: w.target, agents, skip: 'no path' };
|
|
104
|
+
const own = installOf(w.target, pkgDir);
|
|
105
|
+
// local-dep: only the workspaces that resolve to this install. global: all but those resolving to an install of their own.
|
|
106
|
+
if (installMode === 'local-dep' && own === null)
|
|
107
|
+
return { target: w.target, agents, skip: 'not using this install' }; // round 25 wording
|
|
108
|
+
if (installMode === 'local-dep' ? own !== pkgDir : own !== null && own !== pkgDir)
|
|
109
|
+
return { target: w.target, agents, skip: 'its own install' };
|
|
110
|
+
// Round 23: Codex's wiring is user-level, shared by every workspace — a project-local re-pin moved every Codex session
|
|
111
|
+
// onto one project's install (measured). It is left as it is, and said so.
|
|
112
|
+
const kept = installMode === 'local-dep' ? agents.filter((a) => a !== 'codex') : agents;
|
|
113
|
+
if (kept.length === 0)
|
|
114
|
+
return { target: w.target, agents, skip: 'Codex only', codexLeft: true };
|
|
115
|
+
return { target: w.target, agents: kept, ...(kept.length < agents.length ? { codexLeft: true } : {}) };
|
|
116
|
+
}
|
|
117
|
+
/** Render the plan for the human, one line per fact — from the same decisions the run carries out (round 24). */
|
|
118
|
+
function renderPlan(plan, decisions, installAt) {
|
|
119
|
+
// @implements A-SPEC-251.2 (round 46) — a registry value is printed escaped (a newline in a target forged a plan line, an OSC
|
|
120
|
+
// sequence retitled the terminal — measured).
|
|
121
|
+
const shown = (v) => (0, codex_oracle_1.escapeForDisplay)(String(v));
|
|
122
|
+
const repins = decisions.filter((d) => d.skip === undefined);
|
|
123
|
+
const skips = decisions.filter((d) => d.skip !== undefined);
|
|
66
124
|
const lines = [
|
|
67
125
|
`Holmes-Kit upgrade: ${plan.current} → ${plan.latest} (install mode: ${plan.installMode})`,
|
|
68
|
-
plan
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
126
|
+
`Install location: ${installAt}`, // round 25: the plan never named where it would install
|
|
127
|
+
repins.length
|
|
128
|
+
? `Will re-pin ${repins.length} workspace(s):`
|
|
129
|
+
: 'No workspace uses this install — install only.',
|
|
130
|
+
...repins.map((d) => ` • ${shown(d.target)} [${shown(d.agents.join(', '))}]`),
|
|
131
|
+
...(skips.length ? [`Will skip ${skips.length}:`, ...skips.map((d) => ` • ${shown(d.target)} (${shown(d.skip)})`)] : []),
|
|
132
|
+
...(decisions.some((d) => d.codexLeft) ? ["Codex's user-level wiring is shared by every workspace and is left as it is."] : []),
|
|
72
133
|
];
|
|
73
134
|
return lines.join('\n') + '\n';
|
|
74
135
|
}
|
|
@@ -83,6 +144,18 @@ async function runUpgrade(io) {
|
|
|
83
144
|
const current = currentVersion(root);
|
|
84
145
|
const mode = (0, session_start_1.detectInstallMode)(root);
|
|
85
146
|
const cached = (0, update_notice_1.readCache)(os.homedir(), (p) => fs.readFileSync(p, 'utf8'));
|
|
147
|
+
// A-SPEC-543.2 (amendment 2026-09-29): the registry is asked first — the cache alone kept a release unseen for up to a
|
|
148
|
+
// day ("already up to date (current 0.31.0, latest 0.30.0)", measured). A fresh answer refreshes the cache.
|
|
149
|
+
const now = Date.now();
|
|
150
|
+
const fresh = io.queryLatest ? await io.queryLatest().catch(() => null) : null;
|
|
151
|
+
if (fresh !== null && !io.dryRun) { // --dry-run asks and shows, and writes nothing
|
|
152
|
+
try {
|
|
153
|
+
fs.mkdirSync(path.join(os.homedir(), '.holmes'), { recursive: true });
|
|
154
|
+
fs.writeFileSync(path.join(os.homedir(), '.holmes', 'update-check.json'), JSON.stringify({ latest: fresh, checkedAt: now }));
|
|
155
|
+
}
|
|
156
|
+
catch { /* the cache is a convenience; the plan below uses the fresh answer either way */ }
|
|
157
|
+
}
|
|
158
|
+
const resolved = (0, upgrade_plan_1.resolveLatest)({ fresh, cached: cached ? { latest: cached.latest, checkedAt: cached.checkedAt } : null, now });
|
|
86
159
|
const registry = (() => {
|
|
87
160
|
try {
|
|
88
161
|
return (0, workspaces_1.readRegistry)(fs.readFileSync(path.join(os.homedir(), '.holmes', 'workspaces.json'), 'utf8'));
|
|
@@ -91,20 +164,44 @@ async function runUpgrade(io) {
|
|
|
91
164
|
return (0, workspaces_1.readRegistry)(null);
|
|
92
165
|
}
|
|
93
166
|
})();
|
|
94
|
-
const plan = (0, upgrade_plan_1.planUpgrade)({ current, latest:
|
|
167
|
+
const plan = (0, upgrade_plan_1.planUpgrade)({ current, latest: resolved.latest, registry, installMode: mode, latestNote: (0, upgrade_plan_1.describeLatest)(resolved) });
|
|
95
168
|
if (plan.kind === 'noop') {
|
|
96
169
|
io.stdout(`${plan.reason}\n`);
|
|
97
170
|
return 0;
|
|
98
171
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
172
|
+
// @implements A-SPEC-251.1 (round 27) — only a strict semver is installed (`PKG@<latest>`): a cached `9.0.0.tgz` was read
|
|
173
|
+
// by npm as a local file (measured). The cache reader refuses such a value; this is the second line.
|
|
174
|
+
if (!(0, update_notice_1.isStrictSemver)(plan.latest)) {
|
|
175
|
+
io.stderr(`the cached latest version is not a version (${String(plan.latest).slice(0, 80)}); nothing installed or re-pinned.\n`);
|
|
176
|
+
return 1;
|
|
103
177
|
}
|
|
178
|
+
// Round 25: a source checkout is refused before any plan (its dry run printed "Will re-pin N" — code read).
|
|
104
179
|
if (plan.installMode === 'source') {
|
|
105
180
|
io.stderr('source checkout: upgrade via git (git pull && npm run build), not npm install.\n');
|
|
106
181
|
return 1;
|
|
107
182
|
}
|
|
183
|
+
// Round 24: where the install goes is known before installing (`npm root` only names the directory), so the plan
|
|
184
|
+
// shown before "Continue?" is the run's own decisions.
|
|
185
|
+
let pkgDir; // compared (real path)
|
|
186
|
+
let pkgPath; // run (as npm names it)
|
|
187
|
+
try {
|
|
188
|
+
const modulesRoot = (0, node_child_process_1.execFileSync)(npmBin(), ['root', ...(plan.installMode === 'global-npx' ? ['-g'] : []), ...NPM_QUIET], { cwd: process.cwd(), encoding: 'utf8', timeout: 30_000 }).trim();
|
|
189
|
+
// Round 25: npm redacts UUID-shaped path segments in its output (`***`) — such a path is no location (measured).
|
|
190
|
+
if (modulesRoot.includes('***'))
|
|
191
|
+
throw new Error(`npm root answered a redacted path (${modulesRoot.slice(0, 200)})`);
|
|
192
|
+
pkgPath = path.join(modulesRoot, PKG);
|
|
193
|
+
pkgDir = realOrResolve(pkgPath);
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
io.stderr(`the install location could not be resolved (npm root); nothing installed or re-pinned: ${String(e)}\n`);
|
|
197
|
+
return 1;
|
|
198
|
+
}
|
|
199
|
+
const decisions = registry.workspaces.map((w) => decideRepin(w, plan.installMode, pkgDir));
|
|
200
|
+
io.stdout(renderPlan(plan, decisions, pkgPath));
|
|
201
|
+
if (io.dryRun) {
|
|
202
|
+
io.stdout('(dry-run — nothing installed or re-pinned)\n');
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
108
205
|
const go = io.yes || await io.confirm('Continue? [y/N] ');
|
|
109
206
|
if (!go) {
|
|
110
207
|
io.stdout(io.yes ? '' : 'aborted — nothing installed or re-pinned.\n');
|
|
@@ -117,7 +214,7 @@ async function runUpgrade(io) {
|
|
|
117
214
|
const args = plan.installMode === 'global-npx'
|
|
118
215
|
? ['i', '-g', `${PKG}@${plan.latest}`]
|
|
119
216
|
: ['i', '-D', `${PKG}@${plan.latest}`];
|
|
120
|
-
(0, node_child_process_1.execFileSync)(npmBin(), args, { stdio: 'inherit', cwd: process.cwd() });
|
|
217
|
+
(0, node_child_process_1.execFileSync)(npmBin(), [...args, ...NPM_QUIET], { stdio: 'inherit', cwd: process.cwd() });
|
|
121
218
|
}
|
|
122
219
|
catch {
|
|
123
220
|
io.stderr(`install failed — nothing re-pinned. Try manually: ${npmBin()} i ${plan.installMode === 'global-npx' ? '-g' : '-D'} ${PKG}@${plan.latest}\n`);
|
|
@@ -133,12 +230,10 @@ async function runUpgrade(io) {
|
|
|
133
230
|
}
|
|
134
231
|
}
|
|
135
232
|
catch { /* cache clear is best-effort */ }
|
|
136
|
-
// (3) re-pin
|
|
233
|
+
// (3) re-pin the workspaces the decisions name.
|
|
137
234
|
// Load the newly installed package in a fresh process: the caller already cached old init.
|
|
138
|
-
|
|
235
|
+
const newCli = path.join(pkgPath, 'bin', 'holmes-kit.js');
|
|
139
236
|
try {
|
|
140
|
-
const modulesRoot = (0, node_child_process_1.execFileSync)(npmBin(), ['root', ...(plan.installMode === 'global-npx' ? ['-g'] : [])], { cwd: process.cwd(), encoding: 'utf8' }).trim();
|
|
141
|
-
newCli = path.join(modulesRoot, PKG, 'bin', 'holmes-kit.js');
|
|
142
237
|
if (!fs.statSync(newCli).isFile())
|
|
143
238
|
throw new Error('new CLI is not a file');
|
|
144
239
|
}
|
|
@@ -146,29 +241,39 @@ async function runUpgrade(io) {
|
|
|
146
241
|
io.stderr(`Installed package CLI could not be resolved; no workspace re-pinned: ${String(e)}\n`);
|
|
147
242
|
return 1;
|
|
148
243
|
}
|
|
244
|
+
// @implements A-SPEC-251.1 (confirmation round 25) — the install at the planned location must be the planned version:
|
|
245
|
+
// from an npm-workspaces member, `npm i -D` installed into the member while `npm root` named the root's old install,
|
|
246
|
+
// and the old CLI re-pinned everything and said "Upgraded" (measured).
|
|
247
|
+
const landed = currentVersion(pkgPath);
|
|
248
|
+
if (landed !== plan.latest) {
|
|
249
|
+
io.stderr(`npm did not install ${plan.latest} at ${pkgPath} (found ${landed}); no workspace re-pinned. Run holmes-kit upgrade from the project whose node_modules holds holmes-kit.\n`);
|
|
250
|
+
return 1;
|
|
251
|
+
}
|
|
149
252
|
let repinned = 0, skipped = 0, failed = 0;
|
|
150
253
|
io.stdout('\nRe-pinning workspaces:\n');
|
|
151
|
-
for (const
|
|
152
|
-
if (
|
|
153
|
-
io.stdout(` skipped (
|
|
254
|
+
for (const d of decisions) {
|
|
255
|
+
if (d.skip !== undefined) {
|
|
256
|
+
io.stdout(` skipped (${(0, codex_oracle_1.escapeForDisplay)(String(d.skip))}): ${(0, codex_oracle_1.escapeForDisplay)(d.target)}${d.skip === 'its own install' ? ' — run holmes-kit upgrade from that install' : ''}\n`);
|
|
154
257
|
skipped++;
|
|
155
258
|
continue;
|
|
156
259
|
}
|
|
157
260
|
try {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
'--agent', agents, '--mode', 'guardrail', '--mcp-launcher', 'npx'], { cwd: process.cwd(), encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
261
|
+
const output = (0, node_child_process_1.execFileSync)(process.execPath, [newCli, 'init', '--target', d.target,
|
|
262
|
+
'--agent', d.agents.join(','), '--mode', 'guardrail'], { cwd: process.cwd(), encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
161
263
|
io.stdout(output);
|
|
162
|
-
io.stdout(` re-pinned: ${
|
|
264
|
+
io.stdout(` re-pinned: ${(0, codex_oracle_1.escapeForDisplay)(d.target)}\n`);
|
|
163
265
|
repinned++;
|
|
164
266
|
}
|
|
165
267
|
catch (e) {
|
|
166
268
|
const failure = e;
|
|
167
|
-
io.stdout(` failed: ${
|
|
269
|
+
io.stdout(` failed: ${(0, codex_oracle_1.escapeForDisplay)(d.target)}: ${String(failure.stderr ?? failure.message ?? e).split('\n').map(codex_oracle_1.escapeForDisplay).join('\n ')}\n`);
|
|
168
270
|
failed++;
|
|
169
271
|
}
|
|
170
272
|
}
|
|
273
|
+
const codexLeft = decisions.some((d) => d.codexLeft);
|
|
171
274
|
io.stdout(`\nUpgraded to ${plan.latest}. re-pinned ${repinned} · skipped ${skipped} · failed ${failed}. A new session's hooks/MCP will read the new wiring.\n`);
|
|
275
|
+
if (codexLeft)
|
|
276
|
+
io.stdout(`Codex's user-level wiring was left as it is: it is shared by every workspace, so it is not moved onto this project's install. Re-wire it by running \`holmes-kit init --agent codex --force\` from the install you mean to share (a global install, outside any project).\n`);
|
|
172
277
|
io.stdout(`(You can re-wire any individual workspace at any time with ${(0, npx_bin_1.npxBin)()} holmes-kit init --agent <…> --force.)\n`);
|
|
173
278
|
return failed > 0 ? 1 : 0;
|
|
174
279
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare function workspaceRoots(realTarget: string): string[];
|
|
2
|
+
/**
|
|
3
|
+
* @implements A-SPEC-251.2 (round 34) — a real path is the workspace's when it lies under a workspace root, or when a
|
|
4
|
+
* directory above it holds a `.git` whose common git directory is (or lies under — a submodule's `modules/`) the common git
|
|
5
|
+
* directory of a workspace repository: round 33 listed `worktrees/` and kept the first 64 (the 65th sibling's wrapper ran
|
|
6
|
+
* and passed), re-reading the listing for every `.git` file (200,000 entries: 88 s — measured).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @implements A-SPEC-251.2 (round 51) — whether the target is the home directory or lies above it (a dotfiles repository
|
|
10
|
+
* taken as the target): every install under home (nvm, volta) is then "inside the workspace", so a `node` found through an
|
|
11
|
+
* ABSOLUTE PATH entry is not read as the workspace's there (an untouched canonical wiring read FAIL three times — measured).
|
|
12
|
+
*/
|
|
13
|
+
export declare function targetHoldsHome(realTarget: string): boolean;
|
|
14
|
+
export declare function inWorkspace(realTarget: string, real: string): boolean;
|
|
15
|
+
export declare const REMOTE_GIT = "\0remote";
|
|
16
|
+
/**
|
|
17
|
+
* The common git directory of the repository whose `.git` sits in `dir`, `REMOTE_GIT` when it names a network path, or null.
|
|
18
|
+
* Round 35: a symlinked `.git` is followed (a `repo`-tool main checkout's wrapper ran — measured); `.git`, `commondir` and
|
|
19
|
+
* `gitdir` files are read to 64 KiB (four 2 GB `.git` files took 12.5 s — measured).
|
|
20
|
+
*/
|
|
21
|
+
export declare function commonGitDirAt(dir: string): string | null;
|
|
22
|
+
export declare function isWithin(root: string, p: string): boolean;
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.REMOTE_GIT = void 0;
|
|
37
|
+
exports.workspaceRoots = workspaceRoots;
|
|
38
|
+
exports.targetHoldsHome = targetHoldsHome;
|
|
39
|
+
exports.inWorkspace = inWorkspace;
|
|
40
|
+
exports.commonGitDirAt = commonGitDirAt;
|
|
41
|
+
exports.isWithin = isWithin;
|
|
42
|
+
// @implements A-SPEC-251.2
|
|
43
|
+
// The workspace a wiring must not run a program from — shared by doctor and init (round 50: init judged by the target
|
|
44
|
+
// alone). Moved here from doctor.ts unchanged, so that init can use it without importing doctor (doctor imports init).
|
|
45
|
+
const fs = __importStar(require("node:fs"));
|
|
46
|
+
const os = __importStar(require("node:os"));
|
|
47
|
+
const path = __importStar(require("node:path"));
|
|
48
|
+
const codex_oracle_1 = require("./codex-oracle");
|
|
49
|
+
const claude_switches_1 = require("./claude-switches");
|
|
50
|
+
const ROOTS_MEMO = new Map();
|
|
51
|
+
function workspaceOf(realTarget) {
|
|
52
|
+
// Round 33: once per target within a doctor run, each directory walked once (`.git` files naming one `.git`-less
|
|
53
|
+
// directory made the walk (m+1)^8: 11 s at 3 levels, 66 s at 4 — measured).
|
|
54
|
+
const hit = ROOTS_MEMO.get(realTarget);
|
|
55
|
+
if (hit !== undefined && Date.now() - hit.at < 5000)
|
|
56
|
+
return hit.ws;
|
|
57
|
+
const ws = workspaceUncached(realTarget);
|
|
58
|
+
ROOTS_MEMO.set(realTarget, { at: Date.now(), ws });
|
|
59
|
+
return ws;
|
|
60
|
+
}
|
|
61
|
+
function workspaceRoots(realTarget) { return workspaceOf(realTarget).roots; }
|
|
62
|
+
/**
|
|
63
|
+
* @implements A-SPEC-251.2 (round 34) — a real path is the workspace's when it lies under a workspace root, or when a
|
|
64
|
+
* directory above it holds a `.git` whose common git directory is (or lies under — a submodule's `modules/`) the common git
|
|
65
|
+
* directory of a workspace repository: round 33 listed `worktrees/` and kept the first 64 (the 65th sibling's wrapper ran
|
|
66
|
+
* and passed), re-reading the listing for every `.git` file (200,000 entries: 88 s — measured).
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* @implements A-SPEC-251.2 (round 51) — whether the target is the home directory or lies above it (a dotfiles repository
|
|
70
|
+
* taken as the target): every install under home (nvm, volta) is then "inside the workspace", so a `node` found through an
|
|
71
|
+
* ABSOLUTE PATH entry is not read as the workspace's there (an untouched canonical wiring read FAIL three times — measured).
|
|
72
|
+
*/
|
|
73
|
+
function targetHoldsHome(realTarget) {
|
|
74
|
+
const home = (() => { try {
|
|
75
|
+
return fs.realpathSync.native(process.platform !== 'win32' && process.env.HOME ? process.env.HOME : os.homedir());
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return '';
|
|
79
|
+
} })();
|
|
80
|
+
return home !== '' && (home === realTarget || isWithin(realTarget, home));
|
|
81
|
+
}
|
|
82
|
+
function inWorkspace(realTarget, real) {
|
|
83
|
+
const ws = workspaceOf(realTarget);
|
|
84
|
+
if (ws.roots.some((r) => isWithin(r, real)))
|
|
85
|
+
return true;
|
|
86
|
+
if (ws.commons.length === 0)
|
|
87
|
+
return false;
|
|
88
|
+
for (let d = real, i = 0; i < 256; i++) {
|
|
89
|
+
const c = commonGitDirAt(d);
|
|
90
|
+
// Round 35: a `.git` naming a network path cannot be checked — it is read as the workspace's (never run).
|
|
91
|
+
if (c === exports.REMOTE_GIT)
|
|
92
|
+
return true;
|
|
93
|
+
if (c !== null && ws.commons.some((w) => isWithin(w, c)))
|
|
94
|
+
return true;
|
|
95
|
+
const parent = path.dirname(d);
|
|
96
|
+
if (parent === d)
|
|
97
|
+
break;
|
|
98
|
+
d = parent;
|
|
99
|
+
}
|
|
100
|
+
// @implements A-SPEC-251.2 (round 35) — a worktree the common directory lists whose own `.git` file is gone (round 34
|
|
101
|
+
// dropped the listing and its wrapper ran — measured): read once per common directory, only here.
|
|
102
|
+
for (const c of ws.commons) {
|
|
103
|
+
const listed = listedWorktrees(c);
|
|
104
|
+
if (listed === null || listed.some((w) => isWithin(w, real)))
|
|
105
|
+
return true;
|
|
106
|
+
// Round 36: what the text does not match is walked within one budget (4,096 entries naming a 428-level directory took
|
|
107
|
+
// 44 s — measured); past it the path is read as the workspace's.
|
|
108
|
+
const resolved = resolvedWorktrees(c, listed);
|
|
109
|
+
if (resolved === null || resolved.some((w) => isWithin(w, real)))
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
exports.REMOTE_GIT = '\u0000remote';
|
|
115
|
+
/**
|
|
116
|
+
* The common git directory of the repository whose `.git` sits in `dir`, `REMOTE_GIT` when it names a network path, or null.
|
|
117
|
+
* Round 35: a symlinked `.git` is followed (a `repo`-tool main checkout's wrapper ran — measured); `.git`, `commondir` and
|
|
118
|
+
* `gitdir` files are read to 64 KiB (four 2 GB `.git` files took 12.5 s — measured).
|
|
119
|
+
*/
|
|
120
|
+
function commonGitDirAt(dir) {
|
|
121
|
+
const gitPath = path.join(dir, '.git');
|
|
122
|
+
let st;
|
|
123
|
+
try {
|
|
124
|
+
st = fs.lstatSync(gitPath);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
let file = gitPath;
|
|
130
|
+
if (st.isSymbolicLink()) {
|
|
131
|
+
const walked = (0, claude_switches_1.localPhysicalRealpath)(gitPath);
|
|
132
|
+
if (walked.refused)
|
|
133
|
+
return exports.REMOTE_GIT;
|
|
134
|
+
if (walked.path === null)
|
|
135
|
+
return null;
|
|
136
|
+
try {
|
|
137
|
+
st = fs.statSync(walked.path);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
if (st.isDirectory())
|
|
143
|
+
return walked.path;
|
|
144
|
+
file = walked.path;
|
|
145
|
+
}
|
|
146
|
+
else if (st.isDirectory()) {
|
|
147
|
+
try {
|
|
148
|
+
return fs.realpathSync.native(gitPath);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return gitPath;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (!st.isFile())
|
|
155
|
+
return null;
|
|
156
|
+
const m = /^gitdir:[ \t]*(.+?)[ \t]*$/m.exec((0, claude_switches_1.readFileHead)(file) ?? '');
|
|
157
|
+
if (m === null)
|
|
158
|
+
return null;
|
|
159
|
+
const asWritten = path.resolve(dir, m[1]);
|
|
160
|
+
if (!(0, codex_oracle_1.openableLocalPath)(asWritten))
|
|
161
|
+
return exports.REMOTE_GIT;
|
|
162
|
+
// Round 36: walked before it is read (`gitdir: lnk/wt/.git/…` with `lnk -> /net/…` opened `commondir` — measured).
|
|
163
|
+
const walkedGitdir = (0, claude_switches_1.localPhysicalRealpath)(asWritten);
|
|
164
|
+
if (walkedGitdir.refused)
|
|
165
|
+
return exports.REMOTE_GIT;
|
|
166
|
+
const gitdir = walkedGitdir.path ?? asWritten;
|
|
167
|
+
// Round 37: the `commondir` file is walked too (a link into /net was opened — measured).
|
|
168
|
+
const commondirFile = walkedGitdir.path === null ? null : (0, claude_switches_1.localPhysicalRealpath)(path.join(gitdir, 'commondir'));
|
|
169
|
+
if (commondirFile?.refused)
|
|
170
|
+
return exports.REMOTE_GIT;
|
|
171
|
+
const commondir = commondirFile?.path ? (0, claude_switches_1.readFileHead)(commondirFile.path) : null;
|
|
172
|
+
const common = commondir === null ? gitdir : path.resolve(gitdir, commondir.trim());
|
|
173
|
+
if (!(0, codex_oracle_1.openableLocalPath)(common))
|
|
174
|
+
return exports.REMOTE_GIT;
|
|
175
|
+
const walked = (0, claude_switches_1.localPhysicalRealpath)(common);
|
|
176
|
+
return walked.refused ? exports.REMOTE_GIT : walked.path ?? common;
|
|
177
|
+
}
|
|
178
|
+
const LISTED_MEMO = new Map();
|
|
179
|
+
/**
|
|
180
|
+
* The checkouts each `<common>/worktrees/<id>/gitdir` names, as written (null past 4,096 entries, or when the `worktrees`
|
|
181
|
+
* directory reaches a network path: read as the workspace's). Round 36: the directory is walked before it is listed (a
|
|
182
|
+
* `worktrees -> /net/…` link was listed — measured).
|
|
183
|
+
*/
|
|
184
|
+
function listedWorktrees(common) {
|
|
185
|
+
const hit = LISTED_MEMO.get(common);
|
|
186
|
+
if (hit !== undefined && Date.now() - hit.at < 5000)
|
|
187
|
+
return hit.dirs;
|
|
188
|
+
const at = (0, claude_switches_1.localPhysicalRealpath)(path.join(common, 'worktrees'));
|
|
189
|
+
let dirs = [];
|
|
190
|
+
if (at.refused)
|
|
191
|
+
dirs = null;
|
|
192
|
+
else if (at.path !== null) {
|
|
193
|
+
let ids = [];
|
|
194
|
+
try {
|
|
195
|
+
ids = fs.readdirSync(at.path);
|
|
196
|
+
}
|
|
197
|
+
catch { /* none */ }
|
|
198
|
+
if (ids.length > 4096)
|
|
199
|
+
dirs = null;
|
|
200
|
+
else {
|
|
201
|
+
// Round 38: a plain entry and `gitdir` file cost two look-ups; only a link is walked, within 20,000 components for the
|
|
202
|
+
// whole list (4,096 entries linked to 428-level directories took 53 s — measured, a round-37 regression), past which
|
|
203
|
+
// the list is read as the workspace's.
|
|
204
|
+
const budget = { left: 20_000 };
|
|
205
|
+
for (const id of ids) {
|
|
206
|
+
// Round 37: the entry and its `gitdir` file are walked too (links into /net were opened — measured).
|
|
207
|
+
const gd = path.join(at.path, id, 'gitdir');
|
|
208
|
+
let fileAt = null;
|
|
209
|
+
try {
|
|
210
|
+
budget.left -= 2;
|
|
211
|
+
if (!fs.lstatSync(path.join(at.path, id)).isSymbolicLink() && fs.lstatSync(gd).isFile())
|
|
212
|
+
fileAt = gd;
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (budget.left < 0) {
|
|
218
|
+
dirs = null;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
if (fileAt === null) {
|
|
222
|
+
const file = (0, claude_switches_1.localPhysicalRealpath)(gd, budget);
|
|
223
|
+
if (file.exhausted) {
|
|
224
|
+
dirs = null;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
if (file.refused || file.path === null)
|
|
228
|
+
continue;
|
|
229
|
+
fileAt = file.path;
|
|
230
|
+
}
|
|
231
|
+
const g = (0, claude_switches_1.readFileHead)(fileAt)?.trim();
|
|
232
|
+
if (g === undefined || g === '')
|
|
233
|
+
continue;
|
|
234
|
+
const w = path.dirname(path.resolve(at.path, id, g));
|
|
235
|
+
if ((0, codex_oracle_1.openableLocalPath)(w))
|
|
236
|
+
dirs.push(w);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
LISTED_MEMO.set(common, { at: Date.now(), dirs });
|
|
241
|
+
return dirs;
|
|
242
|
+
}
|
|
243
|
+
const RESOLVED_MEMO = new Map();
|
|
244
|
+
/** The same checkouts' real paths, all walked within 20,000 components in total (null past the budget or on a network path). */
|
|
245
|
+
function resolvedWorktrees(common, listed) {
|
|
246
|
+
const hit = RESOLVED_MEMO.get(common);
|
|
247
|
+
if (hit !== undefined && Date.now() - hit.at < 5000)
|
|
248
|
+
return hit.dirs;
|
|
249
|
+
// Round 37: each parent directory is walked once (siblings share it — 1,250 worktrees ran out of the budget and every node
|
|
250
|
+
// wiring read FAIL, a round-36 regression, measured); an entry on a network path drops only itself.
|
|
251
|
+
const budget = { left: 20_000 };
|
|
252
|
+
const parents = new Map();
|
|
253
|
+
let dirs = [];
|
|
254
|
+
for (const w of listed) {
|
|
255
|
+
const parent = path.dirname(w);
|
|
256
|
+
let real = parents.get(parent);
|
|
257
|
+
if (real === undefined) {
|
|
258
|
+
const walked = (0, claude_switches_1.localPhysicalRealpath)(parent, budget);
|
|
259
|
+
if (walked.exhausted) {
|
|
260
|
+
dirs = null;
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
real = walked.path;
|
|
264
|
+
parents.set(parent, real);
|
|
265
|
+
}
|
|
266
|
+
if (real === null)
|
|
267
|
+
continue;
|
|
268
|
+
// Only the last component is new: a link there is walked in full.
|
|
269
|
+
const full = path.join(real, path.basename(w));
|
|
270
|
+
if (--budget.left < 0) {
|
|
271
|
+
dirs = null;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
let st;
|
|
275
|
+
try {
|
|
276
|
+
st = fs.lstatSync(full);
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (!st.isSymbolicLink()) {
|
|
282
|
+
dirs.push(full);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const walked = (0, claude_switches_1.localPhysicalRealpath)(full, budget);
|
|
286
|
+
if (walked.exhausted) {
|
|
287
|
+
dirs = null;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
if (walked.path !== null)
|
|
291
|
+
dirs.push(walked.path);
|
|
292
|
+
}
|
|
293
|
+
RESOLVED_MEMO.set(common, { at: Date.now(), dirs });
|
|
294
|
+
return dirs;
|
|
295
|
+
}
|
|
296
|
+
function workspaceUncached(realTarget) {
|
|
297
|
+
// Round 32: every repository around the target (below the home directory), and the repository that owns a `.git` FILE
|
|
298
|
+
// — a submodule's or a linked worktree's — followed through its `gitdir:` (the owning, enclosing or main checkout's
|
|
299
|
+
// wrapper, spelled as a known absolute path, ran and passed — measured).
|
|
300
|
+
// `$HOME` as os.homedir() reads it on POSIX, from this process's environment.
|
|
301
|
+
const home = (() => { try {
|
|
302
|
+
return fs.realpathSync.native(process.platform !== 'win32' && process.env.HOME ? process.env.HOME : os.homedir());
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
return '';
|
|
306
|
+
} })();
|
|
307
|
+
const atOrAboveHome = (d) => home !== '' && (d === home || isWithin(d, home));
|
|
308
|
+
const roots = new Set([realTarget]);
|
|
309
|
+
const commons = new Set();
|
|
310
|
+
// Round 34: a common git directory counts unless its checkout is the home directory or above it (round 33 added a home
|
|
311
|
+
// dotfiles repository as an owner: nvm's node under home read FAIL — measured, a regression).
|
|
312
|
+
const addCommon = (d) => {
|
|
313
|
+
const c = commonGitDirAt(d);
|
|
314
|
+
if (c === null || c === exports.REMOTE_GIT)
|
|
315
|
+
return;
|
|
316
|
+
if (path.basename(c) === '.git' && atOrAboveHome(path.dirname(c)))
|
|
317
|
+
return;
|
|
318
|
+
commons.add(c);
|
|
319
|
+
};
|
|
320
|
+
const walked = new Set();
|
|
321
|
+
const visit = (start, depth) => {
|
|
322
|
+
for (let d = start;;) {
|
|
323
|
+
if (walked.has(d) || walked.size > 4096)
|
|
324
|
+
return;
|
|
325
|
+
walked.add(d);
|
|
326
|
+
if (atOrAboveHome(d))
|
|
327
|
+
return;
|
|
328
|
+
let st = null;
|
|
329
|
+
try {
|
|
330
|
+
st = fs.lstatSync(path.join(d, '.git'));
|
|
331
|
+
}
|
|
332
|
+
catch { /* none here */ }
|
|
333
|
+
if (st !== null) {
|
|
334
|
+
roots.add(d);
|
|
335
|
+
addCommon(d);
|
|
336
|
+
if (st.isFile() && depth < 8)
|
|
337
|
+
for (const owner of gitdirOwners(d)) {
|
|
338
|
+
if (atOrAboveHome(owner))
|
|
339
|
+
continue;
|
|
340
|
+
roots.add(owner);
|
|
341
|
+
visit(owner, depth + 1);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const parent = path.dirname(d);
|
|
345
|
+
if (parent === d)
|
|
346
|
+
return;
|
|
347
|
+
d = parent;
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
visit(realTarget, 0);
|
|
351
|
+
return { roots: [...roots], commons: [...commons] };
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* The checkout a `.git` file shares a repository with: the parent of the `.git` directory its `gitdir:` points into (a
|
|
355
|
+
* submodule's super-repository, a worktree's main checkout). Round 34: sibling worktrees are found by their common git
|
|
356
|
+
* directory (`inWorkspace`), not by listing `worktrees/`.
|
|
357
|
+
*/
|
|
358
|
+
function gitdirOwners(dir) {
|
|
359
|
+
const c = commonGitDirAt(dir);
|
|
360
|
+
if (c === null || c === exports.REMOTE_GIT)
|
|
361
|
+
return [];
|
|
362
|
+
for (let d = c, i = 0; i < 64; i++) {
|
|
363
|
+
if (path.basename(d) === '.git')
|
|
364
|
+
return [path.dirname(d)];
|
|
365
|
+
const parent = path.dirname(d);
|
|
366
|
+
if (parent === d)
|
|
367
|
+
break;
|
|
368
|
+
d = parent;
|
|
369
|
+
}
|
|
370
|
+
return [];
|
|
371
|
+
}
|
|
372
|
+
function isWithin(root, p) {
|
|
373
|
+
const rel = path.relative(root, p);
|
|
374
|
+
return rel === '' || (rel !== '..' && !rel.startsWith('..' + path.sep) && !path.isAbsolute(rel));
|
|
375
|
+
}
|