@memnexus-ai/mx-agent-cli 0.1.303 → 0.1.305
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-config/.mx-config-generation.json +2 -2
- package/dist/agent-config/AGENTS.md.template +1 -1
- package/dist/agent-config/agents/bar-raiser.md +41 -1
- package/dist/agent-config/agents/git-expert.md +58 -54
- package/dist/agent-config/claude-md/CLAUDE.core.md +1 -1
- package/dist/agent-config/hooks/session-idle-gate.sh +14 -1
- package/dist/agent-config/hooks/subagent-write-guard.sh +198 -12
- package/dist/agent-config/hooks/worktree-guard.sh +8 -6
- package/dist/agent-config/skills/mx-post-merge-sync/SKILL.md +59 -51
- package/dist/commands/codex-agent-gate.d.ts +1 -2
- package/dist/commands/codex-agent-gate.d.ts.map +1 -1
- package/dist/commands/codex-agent-gate.js +1 -2
- package/dist/commands/codex-agent-gate.js.map +1 -1
- package/dist/commands/codex-deploy-config.d.ts +6 -0
- package/dist/commands/codex-deploy-config.d.ts.map +1 -1
- package/dist/commands/codex-deploy-config.js +28 -8
- package/dist/commands/codex-deploy-config.js.map +1 -1
- package/dist/commands/codex-prove-guards.d.ts +2 -0
- package/dist/commands/codex-prove-guards.d.ts.map +1 -1
- package/dist/commands/codex-prove-guards.js +31 -3
- package/dist/commands/codex-prove-guards.js.map +1 -1
- package/dist/commands/codex-trust-keys.d.ts +2 -0
- package/dist/commands/codex-trust-keys.d.ts.map +1 -1
- package/dist/commands/codex-trust-keys.js +27 -7
- package/dist/commands/codex-trust-keys.js.map +1 -1
- package/dist/commands/coordination.d.ts +16 -0
- package/dist/commands/coordination.d.ts.map +1 -1
- package/dist/commands/coordination.js +24 -2
- package/dist/commands/coordination.js.map +1 -1
- package/dist/commands/create.d.ts +164 -7
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +293 -91
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/doctor.d.ts +17 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +33 -0
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/gh.d.ts +3 -2
- package/dist/commands/gh.d.ts.map +1 -1
- package/dist/commands/gh.js +3 -2
- package/dist/commands/gh.js.map +1 -1
- package/dist/commands/new.d.ts +132 -17
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +426 -74
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/start.d.ts +6 -0
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +105 -17
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/status.d.ts +7 -0
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +21 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-session.d.ts +11 -0
- package/dist/lib/agent-session.d.ts.map +1 -1
- package/dist/lib/agent-session.js +26 -7
- package/dist/lib/agent-session.js.map +1 -1
- package/dist/lib/behavioral-injection.d.ts.map +1 -1
- package/dist/lib/behavioral-injection.js +25 -7
- package/dist/lib/behavioral-injection.js.map +1 -1
- package/dist/lib/catalog-commit.d.ts.map +1 -1
- package/dist/lib/catalog-commit.js +17 -14
- package/dist/lib/catalog-commit.js.map +1 -1
- package/dist/lib/catalog.d.ts +93 -2
- package/dist/lib/catalog.d.ts.map +1 -1
- package/dist/lib/catalog.js +116 -9
- package/dist/lib/catalog.js.map +1 -1
- package/dist/lib/claude.d.ts.map +1 -1
- package/dist/lib/claude.js +28 -4
- package/dist/lib/claude.js.map +1 -1
- package/dist/lib/fleet-data.d.ts +98 -9
- package/dist/lib/fleet-data.d.ts.map +1 -1
- package/dist/lib/fleet-data.js +353 -34
- package/dist/lib/fleet-data.js.map +1 -1
- package/dist/lib/fleet-render.d.ts +8 -1
- package/dist/lib/fleet-render.d.ts.map +1 -1
- package/dist/lib/fleet-render.js +10 -3
- package/dist/lib/fleet-render.js.map +1 -1
- package/dist/lib/gh-remote.d.ts +15 -1
- package/dist/lib/gh-remote.d.ts.map +1 -1
- package/dist/lib/gh-remote.js +27 -2
- package/dist/lib/gh-remote.js.map +1 -1
- package/dist/lib/gh-token-run.d.ts +140 -14
- package/dist/lib/gh-token-run.d.ts.map +1 -1
- package/dist/lib/gh-token-run.js +187 -15
- package/dist/lib/gh-token-run.js.map +1 -1
- package/dist/lib/git-identity.d.ts +6 -2
- package/dist/lib/git-identity.d.ts.map +1 -1
- package/dist/lib/git-identity.js +17 -8
- package/dist/lib/git-identity.js.map +1 -1
- package/dist/lib/guarded-read.d.ts +15 -0
- package/dist/lib/guarded-read.d.ts.map +1 -0
- package/dist/lib/guarded-read.js +73 -0
- package/dist/lib/guarded-read.js.map +1 -0
- package/dist/lib/machine-setup.d.ts +165 -0
- package/dist/lib/machine-setup.d.ts.map +1 -0
- package/dist/lib/machine-setup.js +441 -0
- package/dist/lib/machine-setup.js.map +1 -0
- package/dist/lib/native-realpath.d.ts +70 -0
- package/dist/lib/native-realpath.d.ts.map +1 -0
- package/dist/lib/native-realpath.js +95 -0
- package/dist/lib/native-realpath.js.map +1 -0
- package/dist/lib/project-config.d.ts +2 -6
- package/dist/lib/project-config.d.ts.map +1 -1
- package/dist/lib/project-config.js.map +1 -1
- package/dist/lib/project-name.d.ts +15 -0
- package/dist/lib/project-name.d.ts.map +1 -0
- package/dist/lib/project-name.js +22 -0
- package/dist/lib/project-name.js.map +1 -0
- package/dist/lib/push-to.d.ts +113 -0
- package/dist/lib/push-to.d.ts.map +1 -0
- package/dist/lib/push-to.js +240 -0
- package/dist/lib/push-to.js.map +1 -0
- package/dist/lib/runtime/claude-gateway-routing.d.ts +161 -0
- package/dist/lib/runtime/claude-gateway-routing.d.ts.map +1 -0
- package/dist/lib/runtime/claude-gateway-routing.js +466 -0
- package/dist/lib/runtime/claude-gateway-routing.js.map +1 -0
- package/dist/lib/runtime/codex-adapter.d.ts +91 -5
- package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
- package/dist/lib/runtime/codex-adapter.js +204 -44
- package/dist/lib/runtime/codex-adapter.js.map +1 -1
- package/dist/lib/runtime/codex-config.d.ts +6 -12
- package/dist/lib/runtime/codex-config.d.ts.map +1 -1
- package/dist/lib/runtime/codex-config.js +17 -24
- package/dist/lib/runtime/codex-config.js.map +1 -1
- package/dist/lib/runtime/codex-guard-proof.d.ts +4 -7
- package/dist/lib/runtime/codex-guard-proof.d.ts.map +1 -1
- package/dist/lib/runtime/codex-guard-proof.js +16 -14
- package/dist/lib/runtime/codex-guard-proof.js.map +1 -1
- package/dist/lib/runtime/codex-hooks-list.d.ts +20 -0
- package/dist/lib/runtime/codex-hooks-list.d.ts.map +1 -1
- package/dist/lib/runtime/codex-hooks-list.js +20 -8
- package/dist/lib/runtime/codex-hooks-list.js.map +1 -1
- package/dist/lib/runtime/types.d.ts +1 -1
- package/dist/lib/runtime/types.d.ts.map +1 -1
- package/dist/lib/standards.d.ts +3 -0
- package/dist/lib/standards.d.ts.map +1 -1
- package/dist/lib/standards.js +1 -0
- package/dist/lib/standards.js.map +1 -1
- package/dist/lib/team-identity.d.ts.map +1 -1
- package/dist/lib/team-identity.js +18 -53
- package/dist/lib/team-identity.js.map +1 -1
- package/dist/lib/team-restore.d.ts +281 -0
- package/dist/lib/team-restore.d.ts.map +1 -0
- package/dist/lib/team-restore.js +533 -0
- package/dist/lib/team-restore.js.map +1 -0
- package/dist/lib/window-view.d.ts +5 -0
- package/dist/lib/window-view.d.ts.map +1 -1
- package/dist/lib/window-view.js +67 -6
- package/dist/lib/window-view.js.map +1 -1
- package/dist/lib/worktree-sync.d.ts +139 -11
- package/dist/lib/worktree-sync.d.ts.map +1 -1
- package/dist/lib/worktree-sync.js +327 -46
- package/dist/lib/worktree-sync.js.map +1 -1
- package/dist/standards/merge-gates.md +26 -0
- package/package.json +2 -2
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The machine setup `mx-agent start` runs itself (#1155 slice 2).
|
|
3
|
+
*
|
|
4
|
+
* SPEC. Plan comment 6961512321 on #1155 and its amendment 1, comment
|
|
5
|
+
* 6961573086. The amendment governs where they differ.
|
|
6
|
+
*
|
|
7
|
+
* `ensureMachineSetup` checks three settings and returns exactly one result for
|
|
8
|
+
* each: `already-set`, `set`, `not-set` (with the one command that sets it) or
|
|
9
|
+
* `could-not-check` (with the reason). In `apply` mode it writes a setting only
|
|
10
|
+
* under that setting's rule below. In `report` mode it writes nothing.
|
|
11
|
+
*
|
|
12
|
+
* extensions.worktreeConfig The repository's own `.git/config`. Set only when
|
|
13
|
+
* the repository has no linked worktree other than
|
|
14
|
+
* the main one and the pre-flight passes.
|
|
15
|
+
* coordination-brief-enabled `~/.mx-agent/config.json`. Set to the string
|
|
16
|
+
* "true" only when the key is absent.
|
|
17
|
+
* project slug Tracked `mx-agent.config.json`. Report only.
|
|
18
|
+
*
|
|
19
|
+
* ONE WRITER PER SETTING. `setWorktreeConfigExtension` is the only code that
|
|
20
|
+
* writes `extensions.worktreeConfig`; `enableWorktreeConfig` in
|
|
21
|
+
* `commands/new.ts` calls it. `ensureBriefEnabled` is the only code that writes
|
|
22
|
+
* `coordination-brief-enabled` on its own initiative; `mx-agent config set`
|
|
23
|
+
* still writes it when an operator asks.
|
|
24
|
+
*/
|
|
25
|
+
import { spawnSync } from 'child_process';
|
|
26
|
+
import { chmodSync, chownSync, existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync, } from 'fs';
|
|
27
|
+
import { basename, dirname, join } from 'path';
|
|
28
|
+
import { randomBytes } from 'crypto';
|
|
29
|
+
import { getConfigPath } from './config.js';
|
|
30
|
+
import { checkWorktreeConfigPreflight, describePreflight } from './git-identity.js';
|
|
31
|
+
import { scrubGitRedirectEnv } from './git-scrub-env.js';
|
|
32
|
+
export const BRIEF_KEY = 'coordination-brief-enabled';
|
|
33
|
+
export const BRIEF_COMMAND = `mx-agent config set ${BRIEF_KEY} true`;
|
|
34
|
+
/**
|
|
35
|
+
* The environment every git call here runs with: `process.env` minus the
|
|
36
|
+
* variables that redirect git to another repository (GIT_DIR, GIT_WORK_TREE,
|
|
37
|
+
* GIT_COMMON_DIR and the rest of `lib/git-scrub-env.ts`'s list). An inherited
|
|
38
|
+
* GIT_DIR would otherwise send the `extensions.worktreeConfig` write to a
|
|
39
|
+
* repository other than the one `-C` names (security review on PR #1176).
|
|
40
|
+
* Read at each call, so a later change to process.env is seen.
|
|
41
|
+
*/
|
|
42
|
+
function gitEnv() {
|
|
43
|
+
return scrubGitRedirectEnv(process.env);
|
|
44
|
+
}
|
|
45
|
+
const defaultRunGitConfig = (args) => spawnSync('git', args, { env: gitEnv(), encoding: 'utf-8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
46
|
+
const defaultReadGit = (args) => {
|
|
47
|
+
const r = spawnSync('git', args, { env: gitEnv(), encoding: 'utf-8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
48
|
+
return {
|
|
49
|
+
status: r.error ? null : r.status,
|
|
50
|
+
stdout: String(r.stdout ?? '').trim(),
|
|
51
|
+
stderr: (String(r.stderr ?? '').trim() || (r.error ? r.error.message : '')),
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/** Strip control characters and cap the length, so a value cannot forge terminal output. */
|
|
55
|
+
function safe(s, cap = 300) {
|
|
56
|
+
return String(s ?? '').replace(/[\x00-\x1f\x7f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g, '?').replace(/\s+/g, ' ').trim().slice(0, cap);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Strip control and bidi characters from a path that lands in a printed
|
|
60
|
+
* command. Unlike `safe`, it keeps whitespace runs and a path-length cap, so an
|
|
61
|
+
* ordinary path prints unchanged (security review INFO on PR #1176).
|
|
62
|
+
*/
|
|
63
|
+
function safePath(s) {
|
|
64
|
+
return s.replace(/[\x00-\x1f\x7f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g, '?').slice(0, 4096);
|
|
65
|
+
}
|
|
66
|
+
/** Single-quote a value that lands inside a command an operator may paste into a shell. */
|
|
67
|
+
function shq(s) {
|
|
68
|
+
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
69
|
+
}
|
|
70
|
+
/** The command that enables the extension on `repo`. */
|
|
71
|
+
export function worktreeConfigCommand(repo) {
|
|
72
|
+
return `git -C ${shq(safePath(repo))} config extensions.worktreeConfig true`;
|
|
73
|
+
}
|
|
74
|
+
/** The oldest git that understands `rev-parse --path-format=absolute`. */
|
|
75
|
+
const MIN_GIT_FOR_PATH_FORMAT = [2, 31];
|
|
76
|
+
/**
|
|
77
|
+
* " (needs git 2.31 or later; this is git X.Y.Z)" when `git --version` reads
|
|
78
|
+
* older than 2.31, otherwise "" (red-team R3 on PR #1176).
|
|
79
|
+
*/
|
|
80
|
+
function gitVersionHint(read) {
|
|
81
|
+
const v = read(['--version']);
|
|
82
|
+
const m = /(\d+)\.(\d+)(?:\.(\d+))?/.exec(v.stdout);
|
|
83
|
+
if (v.status !== 0 || !m)
|
|
84
|
+
return '';
|
|
85
|
+
const major = Number(m[1]);
|
|
86
|
+
const minor = Number(m[2]);
|
|
87
|
+
const older = major < MIN_GIT_FOR_PATH_FORMAT[0] || (major === MIN_GIT_FOR_PATH_FORMAT[0] && minor < MIN_GIT_FOR_PATH_FORMAT[1]);
|
|
88
|
+
return older ? ` (needs git 2.31 or later; this is git ${safe(m[0], 20)})` : '';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolve the repository from `projectRoot` through `git rev-parse
|
|
92
|
+
* --git-common-dir`, so `start` run from inside a linked worktree gets the same
|
|
93
|
+
* answer as from the main one (amendment 1 section 2, red-team finding 3).
|
|
94
|
+
*/
|
|
95
|
+
function resolveRepo(projectRoot, read) {
|
|
96
|
+
const r = read(['-C', projectRoot, 'rev-parse', '--path-format=absolute', '--git-common-dir']);
|
|
97
|
+
if (r.status !== 0 || !r.stdout) {
|
|
98
|
+
return { error: `git rev-parse --git-common-dir failed in ${safe(projectRoot)}: ${safe(r.stderr) || `exit ${r.status ?? 'without a status'}`}${gitVersionHint(read)}` };
|
|
99
|
+
}
|
|
100
|
+
let commonDir = r.stdout;
|
|
101
|
+
try {
|
|
102
|
+
commonDir = realpathSync(commonDir);
|
|
103
|
+
}
|
|
104
|
+
catch { /* keep git's answer */ }
|
|
105
|
+
// A non-bare repository keeps its common directory at `<main worktree>/.git`.
|
|
106
|
+
// Anything else is reported by the bare check below, not guessed at here.
|
|
107
|
+
const repo = basename(commonDir) === '.git' ? dirname(commonDir) : commonDir;
|
|
108
|
+
return { commonDir, repo };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Count the linked worktrees from `git worktree list --porcelain`.
|
|
112
|
+
*
|
|
113
|
+
* Skips the first entry, which is the main worktree or a `bare` entry. Counts
|
|
114
|
+
* every other entry, including `prunable`, `locked` and entries whose directory
|
|
115
|
+
* is gone, because each still has an admin directory that reads the shared
|
|
116
|
+
* config (amendment 1 section 2, red-team finding 2).
|
|
117
|
+
*/
|
|
118
|
+
export function countLinkedWorktrees(porcelain) {
|
|
119
|
+
const entries = porcelain.split(/\n\s*\n/).map((e) => e.trim()).filter((e) => e.length > 0);
|
|
120
|
+
const lines = (e) => e.split('\n').map((l) => l.trim());
|
|
121
|
+
const first = entries[0] ? lines(entries[0]) : [];
|
|
122
|
+
const others = entries.slice(1).filter((e) => lines(e).some((l) => l.startsWith('worktree '))).length;
|
|
123
|
+
return { others, bare: first.includes('bare') };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Decide, and in `apply` mode set, `extensions.worktreeConfig`.
|
|
127
|
+
*
|
|
128
|
+
* Order (amendment 1 section 2):
|
|
129
|
+
* 1. already `true` locally: `already-set`, nothing more is read. Any other
|
|
130
|
+
* present value (`false`): `not-set` with the command, and no write.
|
|
131
|
+
* 2. count linked worktrees from the common directory.
|
|
132
|
+
* 3. a bare main entry, or any git failure: `could-not-check`.
|
|
133
|
+
* 4. count 0 and the pre-flight passes: set it and report the old and new value.
|
|
134
|
+
* Count above 0, or the pre-flight refuses: `not-set` with the command.
|
|
135
|
+
*
|
|
136
|
+
* THE GUARD IS STRICTER THAN GIT'S OWN HAZARD. With no `config.worktree` files,
|
|
137
|
+
* enabling the extension changes nothing for existing worktrees. It stays,
|
|
138
|
+
* because #919 is the precedent for refusing a shared git config change made
|
|
139
|
+
* from inside one worktree.
|
|
140
|
+
*/
|
|
141
|
+
export function setWorktreeConfigExtension(opts) {
|
|
142
|
+
const setting = 'extensions.worktreeConfig';
|
|
143
|
+
const read = opts.readGit ?? defaultReadGit;
|
|
144
|
+
const write = opts.runGitConfig ?? defaultRunGitConfig;
|
|
145
|
+
const resolved = resolveRepo(opts.projectRoot, read);
|
|
146
|
+
if ('error' in resolved) {
|
|
147
|
+
return { setting, status: 'could-not-check', detail: resolved.error, cause: 'unreadable' };
|
|
148
|
+
}
|
|
149
|
+
const { commonDir, repo } = resolved;
|
|
150
|
+
const current = read(['-C', commonDir, 'config', '--local', '--type=bool', '--get', 'extensions.worktreeConfig']);
|
|
151
|
+
if (current.status === 0 && current.stdout === 'true') {
|
|
152
|
+
return { setting, status: 'already-set', detail: `true in ${safe(repo)}`, repo };
|
|
153
|
+
}
|
|
154
|
+
// Exit 1 is "unset". Anything else (an unparseable value, an unreadable
|
|
155
|
+
// config) is not a reading this function can act on.
|
|
156
|
+
if (current.status !== 0 && current.status !== 1) {
|
|
157
|
+
return {
|
|
158
|
+
setting, status: 'could-not-check', repo, cause: 'unreadable',
|
|
159
|
+
detail: `git config --get extensions.worktreeConfig failed in ${safe(repo)}: ${safe(current.stderr) || `exit ${current.status ?? 'without a status'}`}`,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
// A present value that is not true is respected, like a present
|
|
163
|
+
// coordination-brief-enabled: only an ABSENT key is ever set.
|
|
164
|
+
if (current.status === 0) {
|
|
165
|
+
return {
|
|
166
|
+
setting, status: 'not-set', repo, command: worktreeConfigCommand(repo), cause: 'present-value',
|
|
167
|
+
detail: `explicitly set to ${safe(current.stdout, 40)} in ${safe(repo)}, left as it is because a present value is respected`,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const from = 'unset';
|
|
171
|
+
const list = read(['-C', commonDir, 'worktree', 'list', '--porcelain']);
|
|
172
|
+
if (list.status !== 0) {
|
|
173
|
+
return {
|
|
174
|
+
setting, status: 'could-not-check', repo, cause: 'unreadable',
|
|
175
|
+
detail: `git worktree list failed in ${safe(repo)}: ${safe(list.stderr) || `exit ${list.status ?? 'without a status'}`}`,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const count = countLinkedWorktrees(list.stdout);
|
|
179
|
+
if (count.bare) {
|
|
180
|
+
return {
|
|
181
|
+
setting, status: 'could-not-check', repo, cause: 'unreadable',
|
|
182
|
+
detail: `${safe(repo)} is a bare repository, and this rule is written for a clone with a main worktree`,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const command = worktreeConfigCommand(repo);
|
|
186
|
+
if (count.others > 0) {
|
|
187
|
+
return {
|
|
188
|
+
setting, status: 'not-set', repo, command, cause: 'other-worktrees',
|
|
189
|
+
detail: `${from} in ${safe(repo)}, which has ${count.others} linked worktree(s); start enables it only on a clone with no other worktrees`,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const preflight = checkWorktreeConfigPreflight(repo, { env: gitEnv() });
|
|
193
|
+
if (preflight.couldNotRun !== null || !preflight.safe) {
|
|
194
|
+
return {
|
|
195
|
+
setting, status: preflight.couldNotRun !== null ? 'could-not-check' : 'not-set', repo,
|
|
196
|
+
cause: preflight.couldNotRun !== null ? 'unreadable' : 'preflight',
|
|
197
|
+
...(preflight.couldNotRun !== null ? {} : { command: `a migration first (git-worktree(1), CONFIGURATION FILE), then ${command}` }),
|
|
198
|
+
detail: `${from} in ${safe(repo)}; pre-flight ${safe(describePreflight(preflight))}`,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
if (opts.mode === 'report') {
|
|
202
|
+
return {
|
|
203
|
+
setting, status: 'not-set', repo, command, cause: 'report-mode',
|
|
204
|
+
detail: `${from} in ${safe(repo)}; start would enable it here (no other worktrees, pre-flight passes)`,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const r = write(['-C', repo, 'config', '--local', 'extensions.worktreeConfig', 'true']);
|
|
208
|
+
if (r.error || r.status !== 0) {
|
|
209
|
+
const why = safe(r.error ? r.error.message : String(r.stderr ?? ''), 240);
|
|
210
|
+
return {
|
|
211
|
+
setting, status: 'not-set', repo, command, cause: 'write-failed',
|
|
212
|
+
writeError: { status: r.status ?? null, why },
|
|
213
|
+
detail: `git config exited ${r.status ?? 'without a status'}${why ? `: ${why}` : ''}`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return { setting, status: 'set', repo, change: { from, to: 'true' }, detail: `in ${safe(repo)}/.git/config` };
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Read config.json without `loadConfig`. That function returns `{}` for a file
|
|
220
|
+
* that does not parse, and `saveConfig` would then rewrite the file with one key
|
|
221
|
+
* and lose every token in it (amendment 1 section 1, red-team findings 1 and 4).
|
|
222
|
+
*/
|
|
223
|
+
function readConfigFile(path) {
|
|
224
|
+
let link;
|
|
225
|
+
try {
|
|
226
|
+
link = lstatSync(path);
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
if (err.code === 'ENOENT')
|
|
230
|
+
return { kind: 'absent-file' };
|
|
231
|
+
return { kind: 'unreadable', why: `${safe(path)} could not be read: ${safe(err instanceof Error ? err.message : String(err))}` };
|
|
232
|
+
}
|
|
233
|
+
// A dangling symlink is not an absent file. Writing would replace the link
|
|
234
|
+
// with a regular file, so it is could-not-check (red-team R4 on PR #1176).
|
|
235
|
+
if (link.isSymbolicLink() && !existsSync(path)) {
|
|
236
|
+
return { kind: 'unreadable', why: `${safe(path)} is a symlink whose target does not exist` };
|
|
237
|
+
}
|
|
238
|
+
let raw;
|
|
239
|
+
try {
|
|
240
|
+
raw = readFileSync(path, 'utf-8');
|
|
241
|
+
}
|
|
242
|
+
catch (err) {
|
|
243
|
+
return { kind: 'unreadable', why: `${safe(path)} could not be read: ${safe(err instanceof Error ? err.message : String(err))}` };
|
|
244
|
+
}
|
|
245
|
+
let parsed;
|
|
246
|
+
try {
|
|
247
|
+
parsed = JSON.parse(raw);
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
// The parse error message can quote file content, and the file holds
|
|
251
|
+
// tokens, so only the fact is reported.
|
|
252
|
+
return { kind: 'unreadable', why: `${safe(path)} is not valid JSON` };
|
|
253
|
+
}
|
|
254
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
255
|
+
return { kind: 'unreadable', why: `${safe(path)} does not hold a JSON object` };
|
|
256
|
+
}
|
|
257
|
+
return { kind: 'ok', config: parsed };
|
|
258
|
+
}
|
|
259
|
+
/** A present value, described without printing anything that could be a secret. */
|
|
260
|
+
function describePresent(v) {
|
|
261
|
+
if (typeof v === 'string')
|
|
262
|
+
return v === '' ? 'an empty string' : `"${safe(v, 40)}"`;
|
|
263
|
+
return safe(JSON.stringify(v), 40);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Set `coordination-brief-enabled` to the string "true" when the key is absent.
|
|
267
|
+
*
|
|
268
|
+
* Any present value is respected, `false`, `0` and an empty string included,
|
|
269
|
+
* and reported as `not-set` with the command (amendment 1 section 3). The write
|
|
270
|
+
* goes to a temp file in the same directory and is renamed over the target,
|
|
271
|
+
* after a re-read that confirms the key is still absent.
|
|
272
|
+
*
|
|
273
|
+
* ACCEPTED RISK. Two writers can still race: the window is the time between the
|
|
274
|
+
* re-read and the rename, and a writer outside this function is not covered.
|
|
275
|
+
*/
|
|
276
|
+
export function ensureBriefEnabled(opts) {
|
|
277
|
+
const setting = 'coordination-brief-enabled';
|
|
278
|
+
const path = opts.configPath;
|
|
279
|
+
const first = readConfigFile(path);
|
|
280
|
+
if (first.kind === 'unreadable') {
|
|
281
|
+
return { setting, status: 'could-not-check', cause: 'unreadable', detail: `${first.why}; nothing was written` };
|
|
282
|
+
}
|
|
283
|
+
const present = (c) => c.kind === 'ok' && Object.prototype.hasOwnProperty.call(c.config, BRIEF_KEY);
|
|
284
|
+
const presentResult = (c) => {
|
|
285
|
+
const v = c.config[BRIEF_KEY];
|
|
286
|
+
if (v === 'true')
|
|
287
|
+
return { setting, status: 'already-set', detail: `"true" in ${safe(path)}` };
|
|
288
|
+
return {
|
|
289
|
+
setting, status: 'not-set', command: BRIEF_COMMAND, cause: 'present-value',
|
|
290
|
+
detail: `${describePresent(v)} in ${safe(path)}, left as it is because a present value is respected`,
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
if (first.kind === 'ok' && present(first))
|
|
294
|
+
return presentResult(first);
|
|
295
|
+
if (opts.mode === 'report') {
|
|
296
|
+
return { setting, status: 'not-set', command: BRIEF_COMMAND, cause: 'report-mode', detail: `absent in ${safe(path)}; start would set it to "true"` };
|
|
297
|
+
}
|
|
298
|
+
opts.beforeConfigWrite?.();
|
|
299
|
+
// The re-read, just before the write.
|
|
300
|
+
const again = readConfigFile(path);
|
|
301
|
+
if (again.kind === 'unreadable') {
|
|
302
|
+
return { setting, status: 'could-not-check', cause: 'unreadable', detail: `${again.why}; nothing was written` };
|
|
303
|
+
}
|
|
304
|
+
if (again.kind === 'ok' && present(again))
|
|
305
|
+
return presentResult(again);
|
|
306
|
+
const base = again.kind === 'ok' ? again.config : {};
|
|
307
|
+
const next = { ...base, [BRIEF_KEY]: 'true' };
|
|
308
|
+
// Write beside the real file, so a live symlinked config.json keeps its link.
|
|
309
|
+
// An existing file's mode and owner carry over to the replacement (red-team
|
|
310
|
+
// R1 on PR #1176); a new file is 0600, the mode `saveConfig` uses.
|
|
311
|
+
let target = path;
|
|
312
|
+
let existing = null;
|
|
313
|
+
if (again.kind === 'ok') {
|
|
314
|
+
try {
|
|
315
|
+
target = realpathSync(path);
|
|
316
|
+
existing = statSync(target);
|
|
317
|
+
}
|
|
318
|
+
catch (err) {
|
|
319
|
+
return { setting, status: 'could-not-check', cause: 'unreadable', detail: `${safe(path)} could not be resolved: ${safe(err instanceof Error ? err.message : String(err))}; nothing was written` };
|
|
320
|
+
}
|
|
321
|
+
if ((Number(existing.mode) & 0o200) === 0) {
|
|
322
|
+
return {
|
|
323
|
+
setting, status: 'not-set', command: BRIEF_COMMAND, cause: 'read-only',
|
|
324
|
+
detail: `${safe(path)} is read-only for its owner (mode ${(Number(existing.mode) & 0o777).toString(8).padStart(4, '0')}), left as it is because a read-only file is a deliberate choice`,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const mode = existing ? Number(existing.mode) & 0o777 : 0o600;
|
|
329
|
+
const dir = dirname(target);
|
|
330
|
+
const tmp = join(dir, `.${basename(target)}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`);
|
|
331
|
+
try {
|
|
332
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
333
|
+
// The same shape `saveConfig` writes, so the other keys keep their bytes.
|
|
334
|
+
writeFileSync(tmp, JSON.stringify(next, null, 2), { mode, flag: 'wx' });
|
|
335
|
+
// Exactly the target's mode: `mode` above is filtered by the umask.
|
|
336
|
+
chmodSync(tmp, mode);
|
|
337
|
+
if (existing) {
|
|
338
|
+
// Best effort, BEFORE the rename so the file never exists at the target
|
|
339
|
+
// path under another owner. Not permitted (EPERM) is ignored: an
|
|
340
|
+
// unprivileged process can only give a file its own uid anyway.
|
|
341
|
+
try {
|
|
342
|
+
chownSync(tmp, Number(existing.uid), Number(existing.gid));
|
|
343
|
+
}
|
|
344
|
+
catch { /* ignored */ }
|
|
345
|
+
}
|
|
346
|
+
renameSync(tmp, target);
|
|
347
|
+
}
|
|
348
|
+
catch (err) {
|
|
349
|
+
try {
|
|
350
|
+
unlinkSync(tmp);
|
|
351
|
+
}
|
|
352
|
+
catch { /* nothing to remove */ }
|
|
353
|
+
return {
|
|
354
|
+
setting, status: 'not-set', command: BRIEF_COMMAND, cause: 'write-failed',
|
|
355
|
+
detail: `the write to ${safe(path)} failed: ${safe(err instanceof Error ? err.message : String(err))}`,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
return {
|
|
359
|
+
setting, status: 'set', change: { from: 'absent', to: '"true"' },
|
|
360
|
+
// What the write does, in the line itself (red-team R2 on PR #1176).
|
|
361
|
+
detail: `every team's session start on this machine will now read its coordination inbox; turn off: mx-agent config set ${BRIEF_KEY} false; file: ${safe(path)}`,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
// ── 3. Project slug, report only ─────────────────────────────────────────────
|
|
365
|
+
/**
|
|
366
|
+
* Report `projectSlug` from the tracked `mx-agent.config.json`. Never written:
|
|
367
|
+
* a clone already carries it. `start` does not set `MX_PRODUCT_SLUG` either,
|
|
368
|
+
* because a process cannot set its parent shell's environment.
|
|
369
|
+
*/
|
|
370
|
+
export function reportProjectSlug(projectRoot) {
|
|
371
|
+
const setting = 'projectSlug';
|
|
372
|
+
const path = join(projectRoot, 'mx-agent.config.json');
|
|
373
|
+
const fix = `add "projectSlug": "<your-project-slug>" to ${shq(safePath(path))} and commit it`;
|
|
374
|
+
if (!existsSync(path)) {
|
|
375
|
+
return { setting, status: 'not-set', command: fix, detail: `${safe(path)} does not exist` };
|
|
376
|
+
}
|
|
377
|
+
const read = readConfigFile(path);
|
|
378
|
+
if (read.kind !== 'ok') {
|
|
379
|
+
return { setting, status: 'could-not-check', cause: 'unreadable', detail: read.kind === 'unreadable' ? read.why : `${safe(path)} does not exist` };
|
|
380
|
+
}
|
|
381
|
+
const v = read.config.projectSlug;
|
|
382
|
+
if (typeof v === 'string' && v.trim() !== '') {
|
|
383
|
+
return { setting, status: 'already-set', detail: `"${safe(v, 80)}" in ${safe(path)}` };
|
|
384
|
+
}
|
|
385
|
+
return { setting, status: 'not-set', command: fix, detail: `${safe(path)} has no projectSlug` };
|
|
386
|
+
}
|
|
387
|
+
// ── The entry point ──────────────────────────────────────────────────────────
|
|
388
|
+
/**
|
|
389
|
+
* Check every setting and, in `apply` mode, write the ones whose rule allows it.
|
|
390
|
+
* Never throws for a setting it cannot read: that is a `could-not-check` result.
|
|
391
|
+
*/
|
|
392
|
+
export function ensureMachineSetup(opts) {
|
|
393
|
+
if (opts.configPath === undefined && process.env.VITEST) {
|
|
394
|
+
throw new Error('ensureMachineSetup called without configPath under the test runner. Pass a temp path: '
|
|
395
|
+
+ 'no test may read or write the real ~/.mx-agent/config.json (#651).');
|
|
396
|
+
}
|
|
397
|
+
const configPath = opts.configPath ?? getConfigPath();
|
|
398
|
+
return {
|
|
399
|
+
mode: opts.mode,
|
|
400
|
+
results: [
|
|
401
|
+
setWorktreeConfigExtension({
|
|
402
|
+
projectRoot: opts.projectRoot,
|
|
403
|
+
mode: opts.mode,
|
|
404
|
+
...(opts.runGitConfig ? { runGitConfig: opts.runGitConfig } : {}),
|
|
405
|
+
...(opts.readGit ? { readGit: opts.readGit } : {}),
|
|
406
|
+
}),
|
|
407
|
+
ensureBriefEnabled({
|
|
408
|
+
configPath,
|
|
409
|
+
mode: opts.mode,
|
|
410
|
+
...(opts.beforeConfigWrite ? { beforeConfigWrite: opts.beforeConfigWrite } : {}),
|
|
411
|
+
}),
|
|
412
|
+
reportProjectSlug(opts.projectRoot),
|
|
413
|
+
],
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
/** One line for a result. */
|
|
417
|
+
export function describeSetting(r) {
|
|
418
|
+
switch (r.status) {
|
|
419
|
+
case 'set':
|
|
420
|
+
return `${r.setting}: ${r.change?.from ?? '?'} -> ${r.change?.to ?? '?'} (${r.detail})`;
|
|
421
|
+
case 'already-set':
|
|
422
|
+
return `${r.setting}: already set, ${r.detail}`;
|
|
423
|
+
case 'not-set':
|
|
424
|
+
return `${r.setting}: not set, ${r.detail}. To set it, run: ${r.command ?? 'no command available'}`;
|
|
425
|
+
default:
|
|
426
|
+
return `${r.setting}: could not check, ${r.detail}`;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* The lines `start` prints. `already-set` prints nothing, so a second start on
|
|
431
|
+
* a configured machine is quiet about these settings. Every other result prints
|
|
432
|
+
* one line, and a write prints its old and new value once.
|
|
433
|
+
*/
|
|
434
|
+
export function describeMachineSetupForStart(result) {
|
|
435
|
+
return result.results.filter((r) => r.status !== 'already-set').map(describeSetting);
|
|
436
|
+
}
|
|
437
|
+
/** The lines `doctor` prints: every setting, every time. */
|
|
438
|
+
export function describeMachineSetupForReport(result) {
|
|
439
|
+
return result.results.map(describeSetting);
|
|
440
|
+
}
|
|
441
|
+
//# sourceMappingURL=machine-setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine-setup.js","sourceRoot":"","sources":["../../src/lib/machine-setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EACL,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,UAAU,EACV,aAAa,GACd,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AA8DzD,MAAM,CAAC,MAAM,SAAS,GAAG,4BAA4B,CAAC;AACtD,MAAM,CAAC,MAAM,aAAa,GAAG,uBAAuB,SAAS,OAAO,CAAC;AAErE;;;;;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D,KAAK,SAAS;YACZ,OAAO,GAAG,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,qBAAqB,CAAC,CAAC,OAAO,IAAI,sBAAsB,EAAE,CAAC;QACtG;YACE,OAAO,GAAG,CAAC,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,EAAE,CAAC;IACxD,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAAC,MAA0B;IACrE,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,aAAa,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AACvF,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,6BAA6B,CAAC,MAA0B;IACtE,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* native-realpath -- resolve a path the way the operating system names it, and
|
|
3
|
+
* compare two resolved paths, for checks that ask "is this the same directory?"
|
|
4
|
+
* (for #1123).
|
|
5
|
+
*
|
|
6
|
+
* WHY `realpathSync.native`. Node's default `realpathSync` is written in
|
|
7
|
+
* JavaScript and keeps a Windows 8.3 short name as it finds it, so the temp
|
|
8
|
+
* directory resolves to `C:\Users\RUNNER~1\...`. git prints the long name, with
|
|
9
|
+
* forward slashes: `C:/Users/runneradmin/.../.git`. `ownGitDirProblem` in
|
|
10
|
+
* `commands/new.ts` compared the two as strings and refused every native
|
|
11
|
+
* Windows run. `realpathSync.native` calls the operating system (GetFinalPathNameByHandle
|
|
12
|
+
* on Windows, realpath(3) elsewhere), which returns the long name.
|
|
13
|
+
*
|
|
14
|
+
* WHY THE WIN32 NORMALISATION. The two sides can still differ in spelling only:
|
|
15
|
+
* `/` against `\`, `c:` against `C:`, a `\\?\` prefix, or a trailing separator.
|
|
16
|
+
* On win32 both sides are normalised the same way and then compared exactly.
|
|
17
|
+
* Letter case below the drive letter is NOT folded: both sides already hold the
|
|
18
|
+
* on-disk case (GetFinalPathNameByHandle), and a fold equates directories NTFS
|
|
19
|
+
* keeps apart, such as `Proj` and `proj` in a case-sensitive directory, or the
|
|
20
|
+
* Kelvin sign U+212A and `k` (security review comment 6774664573 on PR #1133).
|
|
21
|
+
* A difference in case refuses, which is the fail-closed outcome #864 asks for.
|
|
22
|
+
* Every other platform is left exactly as resolved, and compared exactly.
|
|
23
|
+
*
|
|
24
|
+
* `path.win32` is used explicitly rather than `path`, so the win32 rules run,
|
|
25
|
+
* and are tested, on Linux through the `platform` option.
|
|
26
|
+
*
|
|
27
|
+
* FAIL-CLOSED. `nativeRealpath` throws when the path cannot be resolved; it never
|
|
28
|
+
* falls back to `path.resolve`. The caller decides what an unresolvable path
|
|
29
|
+
* means, and for a security check the answer is a refusal (#864, amendment 1
|
|
30
|
+
* MF3 of the #1123 plan).
|
|
31
|
+
*
|
|
32
|
+
* Reusable for #867, which hardens the same comparison family.
|
|
33
|
+
*/
|
|
34
|
+
import { type PlatformPath } from 'path';
|
|
35
|
+
/** The part of `fs` this module calls. Tests inject one; the default is `fs` itself. */
|
|
36
|
+
export interface RealpathFs {
|
|
37
|
+
realpathSync: {
|
|
38
|
+
(p: string): string;
|
|
39
|
+
native: (p: string) => string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface NativeRealpathOptions {
|
|
43
|
+
/** Defaults to `fs`, looked up at call time so a spy on `fs.realpathSync.native` sees the call. */
|
|
44
|
+
fs?: RealpathFs;
|
|
45
|
+
/** Defaults to `process.platform`. Tests pass `'win32'` to run the win32 rules on Linux. */
|
|
46
|
+
platform?: NodeJS.Platform;
|
|
47
|
+
}
|
|
48
|
+
/** `path.win32` on win32, `path.posix` everywhere else. */
|
|
49
|
+
export declare function pathFor(platform?: NodeJS.Platform): PlatformPath;
|
|
50
|
+
/**
|
|
51
|
+
* One spelling for a resolved path. On win32: `\` separators, no `\\?\` or
|
|
52
|
+
* `\\?\UNC\` prefix, an upper-case drive letter, `.` and `..` and repeated
|
|
53
|
+
* separators collapsed, and no trailing separator except on a root. Unchanged
|
|
54
|
+
* on every other platform.
|
|
55
|
+
*/
|
|
56
|
+
export declare function normaliseResolvedPath(p: string, platform?: NodeJS.Platform): string;
|
|
57
|
+
/**
|
|
58
|
+
* `realpathSync.native(p)`, then `realpathSync(p)` if the native call throws,
|
|
59
|
+
* normalised by `normaliseResolvedPath`. Throws the native error when neither
|
|
60
|
+
* resolves `p`: never `path.resolve(p)`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function nativeRealpath(p: string, options?: NativeRealpathOptions): string;
|
|
63
|
+
/**
|
|
64
|
+
* True when `a` and `b`, each already passed through `normaliseResolvedPath`
|
|
65
|
+
* or `nativeRealpath`, name the same path. win32 normalises the spelling of
|
|
66
|
+
* both sides and then compares exactly, with no case fold; every other
|
|
67
|
+
* platform compares exactly.
|
|
68
|
+
*/
|
|
69
|
+
export declare function sameResolvedPath(a: string, b: string, platform?: NodeJS.Platform): boolean;
|
|
70
|
+
//# sourceMappingURL=native-realpath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-realpath.d.ts","sourceRoot":"","sources":["../../src/lib/native-realpath.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAEvD,wFAAwF;AACxF,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;KAAE,CAAC;CACtE;AAED,MAAM,WAAW,qBAAqB;IACpC,mGAAmG;IACnG,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,4FAA4F;IAC5F,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;CAC5B;AAED,2DAA2D;AAC3D,wBAAgB,OAAO,CAAC,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,YAAY,CAElF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,MAAM,CAWrG;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAcrF;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,OAAO,CAG5G"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* native-realpath -- resolve a path the way the operating system names it, and
|
|
3
|
+
* compare two resolved paths, for checks that ask "is this the same directory?"
|
|
4
|
+
* (for #1123).
|
|
5
|
+
*
|
|
6
|
+
* WHY `realpathSync.native`. Node's default `realpathSync` is written in
|
|
7
|
+
* JavaScript and keeps a Windows 8.3 short name as it finds it, so the temp
|
|
8
|
+
* directory resolves to `C:\Users\RUNNER~1\...`. git prints the long name, with
|
|
9
|
+
* forward slashes: `C:/Users/runneradmin/.../.git`. `ownGitDirProblem` in
|
|
10
|
+
* `commands/new.ts` compared the two as strings and refused every native
|
|
11
|
+
* Windows run. `realpathSync.native` calls the operating system (GetFinalPathNameByHandle
|
|
12
|
+
* on Windows, realpath(3) elsewhere), which returns the long name.
|
|
13
|
+
*
|
|
14
|
+
* WHY THE WIN32 NORMALISATION. The two sides can still differ in spelling only:
|
|
15
|
+
* `/` against `\`, `c:` against `C:`, a `\\?\` prefix, or a trailing separator.
|
|
16
|
+
* On win32 both sides are normalised the same way and then compared exactly.
|
|
17
|
+
* Letter case below the drive letter is NOT folded: both sides already hold the
|
|
18
|
+
* on-disk case (GetFinalPathNameByHandle), and a fold equates directories NTFS
|
|
19
|
+
* keeps apart, such as `Proj` and `proj` in a case-sensitive directory, or the
|
|
20
|
+
* Kelvin sign U+212A and `k` (security review comment 6774664573 on PR #1133).
|
|
21
|
+
* A difference in case refuses, which is the fail-closed outcome #864 asks for.
|
|
22
|
+
* Every other platform is left exactly as resolved, and compared exactly.
|
|
23
|
+
*
|
|
24
|
+
* `path.win32` is used explicitly rather than `path`, so the win32 rules run,
|
|
25
|
+
* and are tested, on Linux through the `platform` option.
|
|
26
|
+
*
|
|
27
|
+
* FAIL-CLOSED. `nativeRealpath` throws when the path cannot be resolved; it never
|
|
28
|
+
* falls back to `path.resolve`. The caller decides what an unresolvable path
|
|
29
|
+
* means, and for a security check the answer is a refusal (#864, amendment 1
|
|
30
|
+
* MF3 of the #1123 plan).
|
|
31
|
+
*
|
|
32
|
+
* Reusable for #867, which hardens the same comparison family.
|
|
33
|
+
*/
|
|
34
|
+
import { realpathSync } from 'fs';
|
|
35
|
+
import { posix, win32 } from 'path';
|
|
36
|
+
/** `path.win32` on win32, `path.posix` everywhere else. */
|
|
37
|
+
export function pathFor(platform = process.platform) {
|
|
38
|
+
return platform === 'win32' ? win32 : posix;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* One spelling for a resolved path. On win32: `\` separators, no `\\?\` or
|
|
42
|
+
* `\\?\UNC\` prefix, an upper-case drive letter, `.` and `..` and repeated
|
|
43
|
+
* separators collapsed, and no trailing separator except on a root. Unchanged
|
|
44
|
+
* on every other platform.
|
|
45
|
+
*/
|
|
46
|
+
export function normaliseResolvedPath(p, platform = process.platform) {
|
|
47
|
+
if (platform !== 'win32')
|
|
48
|
+
return p;
|
|
49
|
+
let s = p.replace(/\//g, '\\');
|
|
50
|
+
// `\\?\UNC\server\share` is the long form of `\\server\share`; `\\?\C:\x` of `C:\x`.
|
|
51
|
+
if (/^\\\\\?\\UNC\\/i.test(s))
|
|
52
|
+
s = `\\\\${s.slice('\\\\?\\UNC\\'.length)}`;
|
|
53
|
+
else if (s.startsWith('\\\\?\\'))
|
|
54
|
+
s = s.slice('\\\\?\\'.length);
|
|
55
|
+
s = win32.normalize(s);
|
|
56
|
+
s = s.replace(/^([a-z]):/, (_m, d) => `${d.toUpperCase()}:`);
|
|
57
|
+
// A trailing separator, except on a root such as `C:\` or `\\server\share\`.
|
|
58
|
+
if (s.length > 1 && s.endsWith('\\') && win32.parse(s).root !== s)
|
|
59
|
+
s = s.slice(0, -1);
|
|
60
|
+
return s;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* `realpathSync.native(p)`, then `realpathSync(p)` if the native call throws,
|
|
64
|
+
* normalised by `normaliseResolvedPath`. Throws the native error when neither
|
|
65
|
+
* resolves `p`: never `path.resolve(p)`.
|
|
66
|
+
*/
|
|
67
|
+
export function nativeRealpath(p, options = {}) {
|
|
68
|
+
const platform = options.platform ?? process.platform;
|
|
69
|
+
const fsLike = options.fs ?? { realpathSync };
|
|
70
|
+
let real;
|
|
71
|
+
try {
|
|
72
|
+
real = fsLike.realpathSync.native(p);
|
|
73
|
+
}
|
|
74
|
+
catch (nativeErr) {
|
|
75
|
+
try {
|
|
76
|
+
real = fsLike.realpathSync(p);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
throw nativeErr;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return normaliseResolvedPath(real, platform);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* True when `a` and `b`, each already passed through `normaliseResolvedPath`
|
|
86
|
+
* or `nativeRealpath`, name the same path. win32 normalises the spelling of
|
|
87
|
+
* both sides and then compares exactly, with no case fold; every other
|
|
88
|
+
* platform compares exactly.
|
|
89
|
+
*/
|
|
90
|
+
export function sameResolvedPath(a, b, platform = process.platform) {
|
|
91
|
+
if (platform !== 'win32')
|
|
92
|
+
return a === b;
|
|
93
|
+
return normaliseResolvedPath(a, platform) === normaliseResolvedPath(b, platform);
|
|
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