@nexaduo/marc 0.0.0-stage → 26.1125.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NexaDuo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,74 @@
1
- # Temporary Holding Version
1
+ # @nexaduo/marc
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Installer for [mARC](https://github.com/NexaDuo/mARC) (Multi-Agent Relay
4
+ Control), a team of AI engineering agents (`@techlead`, `@dev`, `@sec`, `@rev`,
5
+ `@sre`, `@design`, `@research`) that you install once and use in any repository.
6
+
7
+ It installs **and keeps in lockstep** the mARC plugin for every supported
8
+ harness found on your `PATH`:
9
+
10
+ | Harness | CLI used |
11
+ |---|---|
12
+ | Claude Code | `claude plugin …` |
13
+ | GitHub Copilot CLI | `copilot plugin …` |
14
+ | OpenAI Codex | `codex plugin …` |
15
+ | Google Antigravity | `agy plugin …` |
16
+
17
+ ## Usage
18
+
19
+ Requires Node.js 20 or later and at least one harness CLI on your `PATH`.
20
+
21
+ ```bash
22
+ npx @nexaduo/marc install # install on every detected harness
23
+ npx @nexaduo/marc update # update the plugin on every detected harness
24
+ npx @nexaduo/marc doctor # read-only: versions, drift, marketplace source
25
+ npx @nexaduo/marc uninstall # remove the plugin (marketplaces are kept)
26
+ ```
27
+
28
+ Then open any repository in your harness and run `/marc:tech-lead`.
29
+
30
+ | Flag | Effect |
31
+ |---|---|
32
+ | `--harness <claude\|copilot\|codex\|agy>` | Act only on the named harness; repeat for several. Default: every harness on `PATH` |
33
+ | `--scope <user\|project\|local>` | Claude Code only: the scope to install, update or uninstall |
34
+ | `--version <tag>` | Must equal the release embedded in this package; otherwise prints the matching `npx` command and exits |
35
+ | `--dry-run` | Print the plan and change nothing |
36
+ | `--yes` | Skip the confirmation prompt. Required for `install`, `update` and `uninstall` when not in a terminal; `doctor` and `--dry-run` never need it |
37
+
38
+ ## What it does, and what it doesn't
39
+
40
+ - It runs only each harness's own plugin commands. It never writes harness
41
+ settings or config files itself.
42
+ - Before anything changes it prints a plan and asks for confirmation. A few
43
+ steps (such as the Antigravity clone path or Claude update scopes) are
44
+ resolved while running and printed when they run.
45
+ - Antigravity installs from a shallow clone of the release tag, checked against
46
+ the commit embedded in this package, then deletes the clone.
47
+ - `uninstall` never removes a marketplace registration.
48
+ - `doctor` changes nothing and exits non-zero when it finds drift.
49
+
50
+ ## Versions
51
+
52
+ Each npm version embeds one mARC release tag. A tag `vYY.M.D[.N]` (no leading
53
+ zeros) maps to npm `YY.(M*100+D).N`, where a missing `.N` is `0`. For example,
54
+ `v26.11.25.3` is `26.1125.3` and `v26.12.1` is `26.1201.0`.
55
+
56
+ What a given package version pins:
57
+
58
+ - **Antigravity** installs exactly the embedded tag, verified by commit.
59
+ - **Claude Code, Copilot and Codex** install from the `nexaduo` marketplace,
60
+ whose catalog points at the latest mARC release. An older package still gives
61
+ these harnesses the latest release, and `doctor` reports any harness whose
62
+ installed version differs from the embedded one.
63
+
64
+ Use the latest package to keep every harness on the same release.
65
+
66
+ Releases from `26.1125.3` on are published from GitHub Actions with npm
67
+ provenance. `npx` does not verify provenance for you. To check it, run
68
+ `npm audit signatures` in a project that depends on the package; pinning an
69
+ exact version then keeps you on the release you checked.
70
+
71
+ ## Links
72
+
73
+ - Source, docs and issues: https://github.com/NexaDuo/mARC
74
+ - License: MIT
package/bin/marc.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { readFile } from 'node:fs/promises';
3
+ import { main } from '../lib/main.js';
4
+ const release = JSON.parse(await readFile(new URL('../release.json', import.meta.url), 'utf8'));
5
+ try {
6
+ process.exitCode = await main(process.argv.slice(2), { release });
7
+ } catch (error) {
8
+ console.error(`marc: ${error.message}`);
9
+ process.exitCode = 1;
10
+ }
package/lib/lists.js ADDED
@@ -0,0 +1,116 @@
1
+ const VERSION = /\b(?:v)?([0-9]{2}\.[0-9]{1,2}\.[0-9]{1,2}(?:\.[0-9]+)?)\b/;
2
+ const stripAnsi = s => s.replace(/\x1b\[[0-9;]*m/g, '');
3
+
4
+ export function parsePlugins(harness, output) {
5
+ const text = stripAnsi(output);
6
+ if (harness === 'copilot' && !text.trim().startsWith('[') && !text.trim().startsWith('{')) {
7
+ if (/No plugins installed/i.test(text)) return [];
8
+ // Copilot prints human-readable blocks, one header per plugin.
9
+ const blocks = text.split(/(?=^.*\b[A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\b)/m);
10
+ const result = [];
11
+ for (const block of blocks) {
12
+ if (!/\bmarc@nexaduo\b/.test(block)) continue;
13
+ const version = block.match(VERSION)?.[1];
14
+ if (!version) throw new Error('Cannot read Copilot plugin version');
15
+ result.push({ version, scope: '', enabled: !/disabled|enabled:\s*false/i.test(block), source: block.match(/Source:\s*(.+)/i)?.[1] });
16
+ }
17
+ if (!result.length && !/plugins?\s*:\s*0/i.test(text)) throw new Error('Unrecognized Copilot plugin list');
18
+ return result;
19
+ }
20
+ let data;
21
+ try { data = JSON.parse(text); } catch { throw new Error(`Invalid ${harness} plugin list JSON`); }
22
+ const rows = Array.isArray(data) ? data : harness === 'codex' ? data.installed : data.imports;
23
+ if (!Array.isArray(rows)) throw new Error(`Unrecognized ${harness} plugin list`);
24
+ return rows.filter(p => {
25
+ const id = p.id || p.pluginId;
26
+ if (id) return id === 'marc@nexaduo' || (harness === 'agy' && id === 'marc');
27
+ return p.name === 'marc' && (harness === 'agy' || (p.marketplaceName || p.marketplace) === 'nexaduo');
28
+ }).filter(p => p.installed !== false).map(p => ({
29
+ version: p.version, scope: p.scope || '', projectPath: p.projectPath,
30
+ enabled: p.enabled, source: p.source, installedFrom: p.installedFrom,
31
+ }));
32
+ }
33
+
34
+ export function parseMarketplaces(harness, output) {
35
+ let data;
36
+ try { data = JSON.parse(stripAnsi(output)); } catch { throw new Error(`Invalid ${harness} marketplace list JSON`); }
37
+ // Claude returns an array; Codex has a marketplaces array (also accept its
38
+ // name-keyed map). Keep the source fields for legacy pin diagnostics.
39
+ const rows = Array.isArray(data) ? data : data.marketplaces;
40
+ if (Array.isArray(rows)) return rows.filter(p => (p.name || p.marketplaceName) === 'nexaduo');
41
+ if (rows && typeof rows === 'object') return rows.nexaduo ? [rows.nexaduo] : [];
42
+ if (data.nexaduo) return [data.nexaduo];
43
+ throw new Error('Unrecognized marketplace list');
44
+ }
45
+
46
+ const REPOS = new Set(['NexaDuo/mARC', 'https://github.com/NexaDuo/mARC', 'https://github.com/NexaDuo/mARC.git']);
47
+
48
+ function marketplacePinned(value) {
49
+ if (typeof value === 'string') return value.includes('#');
50
+ return value && typeof value === 'object' && Object.entries(value).some(([key, v]) =>
51
+ (['ref', 'branch', 'tag', 'rev', 'commit', 'sha', 'gitRef'].includes(key) && v != null && v !== '') ||
52
+ (['repo', 'url', 'source'].includes(key) && typeof v === 'string' && v.includes('#')) ||
53
+ (typeof v === 'object' && marketplacePinned(v)));
54
+ }
55
+
56
+ export function marketplaceMatches(harness, market) {
57
+ const source = market.marketplaceSource ?? market.source;
58
+ // Reject visible pins. Codex and Copilot native lists hide the ref, so a
59
+ // matching source alone cannot prove that their registration is unpinned.
60
+ if (marketplacePinned(market)) return false;
61
+ if (harness === 'claude' && source === 'github') return market.repo === 'NexaDuo/mARC';
62
+ if (typeof source === 'string') return harness !== 'codex' &&
63
+ (source === 'NexaDuo/mARC' || source === 'GitHub: NexaDuo/mARC');
64
+ if (!source || typeof source !== 'object') return false;
65
+ if (harness === 'codex') return (source.sourceType ?? source.source) === 'git' &&
66
+ REPOS.has(source.sourceType ? source.source : source.url);
67
+ return source.source === 'github' && source.repo === 'NexaDuo/mARC';
68
+ }
69
+
70
+ export function marketplaceWarnings(marketplaces, harness) {
71
+ const warnings = [];
72
+ if (marketplaces.some(marketplacePinned)) warnings.push('legacy-pinned marketplace; manual re-registration required');
73
+ if (marketplaces.some(m => !marketplacePinned(m) && !marketplaceMatches(harness, m))) {
74
+ warnings.push('marketplace source drift; expected NexaDuo/mARC unpinned');
75
+ }
76
+ return warnings;
77
+ }
78
+
79
+ export function sourceHasPointer(source, tag, harness) {
80
+ const folder = { claude: 'claude-code', copilot: 'copilot', codex: 'codex' }[harness];
81
+ return source !== null && typeof source === 'object' && source.ref === tag &&
82
+ source.path === `harnesses/${folder}/marc` && (harness === 'copilot' ?
83
+ source.source === 'github' && source.repo === 'NexaDuo/mARC' :
84
+ source.source === 'git-subdir' && source.url === 'NexaDuo/mARC');
85
+ }
86
+
87
+ // Native lists sometimes expose the catalog checkout root instead of plugin
88
+ // source details. Reading that catalog is safe; never write it or fetch a URL.
89
+ export async function readCatalogSource(harness, marketplaces, rows, env = process.env) {
90
+ const { readFile } = await import('node:fs/promises');
91
+ const { default: path } = await import('node:path');
92
+ const catalog = { claude: '.claude-plugin/marketplace.json', copilot: '.github/plugin/marketplace.json', codex: '.agents/plugins/marketplace.json' }[harness];
93
+ const roots = [];
94
+ for (const market of marketplaces) {
95
+ for (const key of ['root', 'path', 'installLocation', 'installedRoot']) if (typeof market[key] === 'string') roots.push(market[key]);
96
+ if (typeof market.source === 'string' && market.source.startsWith('Local: ')) roots.push(market.source.slice(7));
97
+ }
98
+ for (const row of rows) if (row.installedFrom) roots.push(row.installedFrom);
99
+ if (harness === 'copilot' && marketplaces.some(m => /^GitHub: NexaDuo\/mARC(?:#|$)/.test(m.source || ''))) {
100
+ // Copilot 1.0.89 reports the GitHub slug, not its checkout path. This
101
+ // native cache location was probed with a local Git URL redirect (#424).
102
+ const { homedir } = await import('node:os');
103
+ const home = env.HOME || env.USERPROFILE || homedir();
104
+ const config = env.COPILOT_HOME || path.join(home, '.copilot');
105
+ for (const base of [config, home]) roots.push(path.join(base, '.cache', 'copilot', 'marketplaces', 'NexaDuo-mARC'));
106
+ }
107
+ for (const root of roots.filter(p => path.isAbsolute(p))) {
108
+ try {
109
+ const data = JSON.parse(await readFile(path.join(root, catalog), 'utf8'));
110
+ if (data.name !== 'nexaduo') continue;
111
+ const entries = data.plugins.filter(p => p.name === 'marc');
112
+ if (entries.length === 1) return entries[0].source;
113
+ } catch { /* Absence is reported as unverified by doctor, never fetched. */ }
114
+ }
115
+ return null;
116
+ }
package/lib/main.js ADDED
@@ -0,0 +1,287 @@
1
+ import { mkdtemp, rm, lstat, stat, readdir, readFile } from 'node:fs/promises';
2
+ import os from 'node:os';
3
+ import { realpathSync, statSync } from 'node:fs';
4
+ import path from 'node:path';
5
+ import { createInterface } from 'node:readline/promises';
6
+ import { createRunner, resolveExecutable, safeValue } from './process.js';
7
+ import { tagToNpm } from './version.js';
8
+ import { parsePlugins, parseMarketplaces, marketplaceWarnings, marketplaceMatches, sourceHasPointer, readCatalogSource } from './lists.js';
9
+
10
+ export const HARNESSES = ['claude', 'copilot', 'codex', 'agy'];
11
+ const SCOPES = ['user', 'project', 'local'];
12
+ const SLUG = 'NexaDuo/mARC';
13
+ const ID = 'marc@nexaduo';
14
+ const HELP = `Usage: marc install|update|doctor|uninstall [--yes] [--dry-run]
15
+ [--harness claude|copilot|codex|agy]... [--scope user|project|local]
16
+ [--version <embedded-tag>]
17
+ No --harness: use every harness found on PATH. Node >=20 required.
18
+ --scope applies to Claude only. Non-TTY install/update/uninstall requires --yes
19
+ (doctor and --dry-run never change anything and need no --yes).
20
+ The package release selects the tag; another tag prints its npx command.`;
21
+
22
+ export function parseArgs(argv) {
23
+ const opts = { command: argv[0], harnesses: [], yes: false, dryRun: false };
24
+ if (argv.length === 1 && argv[0] === '--help') return { help: true };
25
+ if (!['install', 'update', 'doctor', 'uninstall'].includes(opts.command)) throw new Error(HELP);
26
+ for (let i = 1; i < argv.length; i++) {
27
+ const flag = argv[i];
28
+ if (flag === '--yes') opts.yes = true;
29
+ else if (flag === '--dry-run') opts.dryRun = true;
30
+ else if (['--harness', '--scope', '--version'].includes(flag)) {
31
+ const value = argv[++i];
32
+ if (typeof value !== 'string') throw new Error(`Missing value for ${flag}`);
33
+ safeValue(value);
34
+ if (flag === '--harness') {
35
+ if (!HARNESSES.includes(value)) throw new Error(`Unknown harness: ${value}`);
36
+ if (!opts.harnesses.includes(value)) opts.harnesses.push(value);
37
+ } else {
38
+ const key = flag.slice(2);
39
+ if (opts[key]) throw new Error(`Repeated ${flag}`);
40
+ opts[key] = value;
41
+ }
42
+ } else throw new Error(`Unknown option: ${flag}`);
43
+ }
44
+ if (opts.scope && !SCOPES.includes(opts.scope)) throw new Error('Unknown Claude scope');
45
+ if (opts.scope && opts.harnesses.length && !opts.harnesses.includes('claude')) throw new Error('--scope requires Claude');
46
+ return opts;
47
+ }
48
+
49
+ const listArgs = () => ['plugin', 'list', '--json'];
50
+ const scopeArgs = scope => ['--scope', scope];
51
+
52
+ // A plan has no side effects. Claude update (including dry-run) reads its
53
+ // installed scopes and resolves project paths before interactive consent.
54
+ export function plan(opts) {
55
+ const plans = [];
56
+ for (const h of opts.harnesses) {
57
+ const commands = [];
58
+ if (opts.command === 'doctor') {
59
+ commands.push(listArgs(h));
60
+ if (h !== 'agy') commands.push(['plugin', 'marketplace', 'list', '--json']);
61
+ }
62
+ else if (h === 'agy' && opts.command !== 'uninstall') commands.push(['plugin', 'list', '--json'], ['<verified shallow tag clone and reinstall; preserve enablement>']);
63
+ else if (opts.command === 'install') {
64
+ commands.push(['plugin', 'marketplace', 'list', '--json'], ['plugin', 'marketplace', 'add', SLUG]);
65
+ commands.push(['plugin', h === 'codex' ? 'add' : 'install', ID, ...(h === 'claude' ? scopeArgs(opts.scope || 'user') : [])]);
66
+ } else if (opts.command === 'update') {
67
+ if (h === 'claude') commands.push(listArgs(h));
68
+ commands.push(['plugin', 'marketplace', h === 'codex' ? 'upgrade' : 'update', 'nexaduo']);
69
+ commands.push(h === 'claude' ? ['plugin', 'update', ID, '--scope', opts.scope || '<each installed scope>'] :
70
+ ['plugin', h === 'codex' ? 'add' : 'update', h === 'codex' ? ID : 'marc']);
71
+ } else commands.push(['plugin', h === 'codex' ? 'remove' : 'uninstall', h === 'agy' ? 'marc' : ID,
72
+ ...(h === 'claude' ? scopeArgs(opts.scope || 'user') : [])]);
73
+ plans.push({ harness: h, commands });
74
+ }
75
+ return plans;
76
+ }
77
+
78
+ async function checkTree(root, top = true) {
79
+ // Fail on all symlinks, including parent components and nested plugin files.
80
+ if (!(await lstat(root)).isDirectory() || (await lstat(root)).isSymbolicLink()) throw new Error('Unsafe clone directory');
81
+ for (const entry of await readdir(root, { withFileTypes: true })) {
82
+ const target = path.join(root, entry.name);
83
+ const stat = await lstat(target);
84
+ if (stat.isSymbolicLink()) throw new Error('Symlink in release clone');
85
+ if (top && entry.name === '.git' && stat.isDirectory()) continue;
86
+ if (stat.isDirectory()) await checkTree(target, false);
87
+ else if (!stat.isFile()) throw new Error('Special file in release clone');
88
+ }
89
+ }
90
+
91
+ export function tempRoots(tmpRoot, { platform = process.platform, env = process.env, realpath = realpathSync.native,
92
+ stat = statSync, home = os.homedir(), uid = process.getuid?.() } = {}) {
93
+ const candidates = tmpRoot ? [tmpRoot] : [os.tmpdir(), env.TMP, env.TEMP];
94
+ const roots = [...new Set(candidates.filter(Boolean).flatMap(p => { try { return [realpath(p)]; } catch { return []; } }))];
95
+ const safe = roots.filter(root => {
96
+ try {
97
+ if (platform === 'win32') {
98
+ // Node cannot verify Windows ACL ownership. Only accept canonical
99
+ // paths inside the user's profile, never a system/shared fallback.
100
+ const relative = path.win32.relative(realpath(home), root);
101
+ return !/\s/.test(root) && relative !== '' && relative !== '..' &&
102
+ !relative.startsWith('..\\') && !path.win32.isAbsolute(relative);
103
+ }
104
+ const info = stat(root);
105
+ // Shared POSIX temp is safe only under a root-owned sticky directory.
106
+ // The mkdtemp child is private and checked separately before use.
107
+ return info.isDirectory() && ((info.uid === uid && (info.mode & 0o022) === 0) ||
108
+ (info.uid === 0 && (info.mode & 0o1002) === 0o1002));
109
+ } catch { return false; }
110
+ });
111
+ if (!safe.length) throw new Error('No private temp root available; set TMP/TEMP to a user-owned writable directory without spaces');
112
+ return safe;
113
+ }
114
+
115
+ export async function installAgy({ run, release, tmpRoot }) {
116
+ if (typeof release.sha !== 'string' || release.sha.length !== 40 || !/^[a-f0-9]{40}$/.test(release.sha)) throw new Error('Release SHA is absent; use a published launcher');
117
+ const installed = parsePlugins('agy', await run('agy', listArgs('agy')));
118
+ if (installed.length > 1 || (installed.length && typeof installed[0].enabled !== 'boolean')) throw new Error('Cannot determine Antigravity enabled state');
119
+ const enable = !installed.length || installed[0].enabled;
120
+ let temp;
121
+ for (const root of tempRoots(tmpRoot)) {
122
+ try { temp = await mkdtemp(path.join(root, 'marc-')); break; } catch { /* Try the next existing root. */ }
123
+ }
124
+ if (!temp) throw new Error('Cannot create release directory; set TMP/TEMP to a writable directory without spaces');
125
+ const clone = path.join(temp, 'release');
126
+ // Git config and git's cwd are isolated before clone/checkout: no workspace
127
+ // hooks, URL rewrites, templates or environment-selected repositories.
128
+ const gitOptions = { cwd: temp, isolatedGit: true };
129
+ const cliPath = p => process.platform === 'win32' ? p.replaceAll('\\', '/') : p;
130
+ try {
131
+ if (process.platform !== 'win32') {
132
+ const info = await lstat(temp);
133
+ if (!info.isDirectory() || info.isSymbolicLink() || info.uid !== process.getuid() ||
134
+ (info.mode & 0o777) !== 0o700) throw new Error('Unsafe private release directory');
135
+ }
136
+ await run('git', ['clone', '--depth', '1', '--branch', release.tag, '--no-checkout',
137
+ 'https://github.com/NexaDuo/mARC.git', cliPath(clone)], { ...gitOptions, generatedPaths: [7] });
138
+ const options = { ...gitOptions, cwd: clone };
139
+ const sha = (await run('git', ['rev-parse', 'HEAD'], options)).trim();
140
+ if (sha !== release.sha) throw new Error(`Release SHA mismatch: expected ${release.sha}, got ${sha}`);
141
+ const tree = await run('git', ['ls-tree', '-r', 'HEAD'], options);
142
+ if (tree.split('\n').some(line => /^(120000|160000) /.test(line))) throw new Error('Symlink or submodule in release');
143
+ await run('git', ['checkout', '--detach', '--force', 'HEAD'], options);
144
+ await checkTree(clone);
145
+ const manifest = JSON.parse(await readFile(path.join(clone, 'harnesses/antigravity/marc/plugin.json'), 'utf8'));
146
+ if (`v${manifest.version}` !== release.tag) throw new Error('Antigravity manifest/tag mismatch');
147
+ await run('agy', ['plugin', 'install', cliPath(path.join(clone, 'harnesses/antigravity/marc'))], { generatedPaths: [2] });
148
+ if (enable) await run('agy', ['plugin', 'enable', 'marc']);
149
+ } finally {
150
+ await rm(temp, { recursive: true, force: true });
151
+ }
152
+ }
153
+
154
+ function manualRemedy(h, log, scope = 'user') {
155
+ log(`${h}: Manual remedy (review first; this removes the marketplace registration):`);
156
+ log(`${h} plugin marketplace remove nexaduo`);
157
+ log(`${h} plugin marketplace add NexaDuo/mARC`);
158
+ log(`${h} plugin ${h === 'codex' ? 'add' : 'install'} marc@nexaduo${h === 'claude' ? ` --scope ${scope}` : ''}`);
159
+ }
160
+
161
+ async function doctor(h, run, release, log, scope) {
162
+ const rows = parsePlugins(h, await run(h, listArgs(h))).filter(p => h !== 'claude' || !scope || p.scope === scope);
163
+ let drift = !rows.length;
164
+ if (!rows.length) log(`${h}\tmissing\t-`);
165
+ for (const row of rows) {
166
+ const match = `v${String(row.version).replace(/^v/, '')}` === release.tag;
167
+ log(`${h}\t${row.version || 'unknown'}\t${row.scope || '-'}\t${row.enabled === false ? 'disabled' : 'enabled'}${match ? '' : '\tDRIFT'}`);
168
+ drift ||= !match;
169
+ }
170
+ if (h !== 'agy') {
171
+ const markets = parseMarketplaces(h, await run(h, ['plugin', 'marketplace', 'list', '--json']));
172
+ const warnings = marketplaceWarnings(markets, h);
173
+ for (const warning of warnings) { log(`${h}: ${warning}`); drift = true; }
174
+ if (warnings.length) manualRemedy(h, log, scope);
175
+ if (['codex', 'copilot'].includes(h) && markets.some(m => marketplaceMatches(h, m))) {
176
+ log(`${h}: pin state unverifiable from native list`);
177
+ }
178
+ if (!markets.length) { log(`${h}: nexaduo marketplace missing`); drift = true; }
179
+ const source = await readCatalogSource(h, markets, rows);
180
+ const sources = source !== null ? [source] : rows.map(r => r.source).filter(Boolean);
181
+ if (!sources.length) {
182
+ log(`${h}: catalog pointer unavailable in native lists; cannot verify release source`);
183
+ drift = true;
184
+ } else if (!sources.every(s => sourceHasPointer(s, release.tag, h))) {
185
+ log(`${h}: main-tracking with no matching release pointer; upgrade the marketplace catalog`);
186
+ drift = true;
187
+ }
188
+ }
189
+ return drift ? 1 : 0;
190
+ }
191
+
192
+ export async function main(argv, { release, run = createRunner(), log = console.log,
193
+ isTTY = Boolean(process.stdin.isTTY), discover = h => resolveExecutable(h), confirm, cwd = process.cwd(), tmpRoot } = {}) {
194
+ const opts = parseArgs(argv);
195
+ if (opts.help) { log(HELP); return 0; }
196
+ if (tagToNpm(release.tag) !== release.npm) throw new Error('Invalid embedded release version');
197
+ if (opts.version && opts.version !== release.tag) {
198
+ const mapped = tagToNpm(opts.version);
199
+ const rest = argv.filter((v, i) => v !== '--version' && argv[i - 1] !== '--version');
200
+ log(`Use npx @nexaduo/marc@${mapped} ${rest.join(' ')}`);
201
+ return 1;
202
+ }
203
+ if (!opts.yes && !isTTY && !opts.dryRun && opts.command !== 'doctor') throw new Error('Non-TTY execution requires --yes');
204
+ if (!opts.harnesses.length) opts.harnesses = HARNESSES.filter(h => { try { discover(h); return true; } catch { return false; } });
205
+ if (!opts.harnesses.length) throw new Error('No supported harness found on PATH');
206
+ if (opts.scope && !opts.harnesses.includes('claude')) throw new Error('--scope requires Claude');
207
+ log(`mARC ${release.tag} (${release.npm}); ${opts.command}`);
208
+ for (const p of plan(opts)) {
209
+ for (const args of p.commands) log(`${p.harness} ${args.join(' ')}`);
210
+ }
211
+ let status = 0, claudeRows, claudeError;
212
+ if (opts.command === 'update' && opts.harnesses.includes('claude')) {
213
+ try {
214
+ const installed = parsePlugins('claude', await run('claude', listArgs('claude')));
215
+ claudeRows = installed.filter(row => !opts.scope || row.scope === opts.scope);
216
+ if (opts.scope && !claudeRows.length) {
217
+ const scopes = [...new Set(installed.map(row => row.scope || 'unknown'))];
218
+ throw new Error(`marc is not installed at scope ${opts.scope}; installed scopes: ${scopes.join(', ') || 'none'}`);
219
+ }
220
+ for (const row of claudeRows) if (row.scope !== 'user') {
221
+ const target = row.projectPath || cwd;
222
+ if (!path.isAbsolute(target)) throw new Error('Claude: invalid project path');
223
+ log(`Claude will edit ${path.join(target, '.claude', row.scope === 'local' ? 'settings.local.json' : 'settings.json')}`);
224
+ }
225
+ } catch (e) { claudeError = e; status = 1; log(`claude: ${e.message}`); }
226
+ } else if (opts.harnesses.includes('claude') && opts.command !== 'doctor') {
227
+ const scope = opts.scope || 'user';
228
+ if (scope !== 'user') log(`Claude may edit ${path.join(cwd, '.claude', scope === 'local' ? 'settings.local.json' : 'settings.json')} (${scope} scope)`);
229
+ }
230
+ if (opts.dryRun) return status;
231
+ if (!opts.yes && opts.command !== 'doctor') {
232
+ let accepted;
233
+ if (confirm) accepted = await confirm();
234
+ else {
235
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
236
+ try { accepted = /^y(es)?$/i.test((await rl.question('Run this plan? [y/N] ')).trim()); } finally { rl.close(); }
237
+ }
238
+ if (!accepted) return 1;
239
+ }
240
+ const results = [];
241
+ for (const h of opts.harnesses) {
242
+ let failed = false;
243
+ try {
244
+ if (opts.command === 'doctor') {
245
+ failed = Boolean(await doctor(h, run, release, log, opts.scope));
246
+ } else if (h === 'agy' && ['install', 'update'].includes(opts.command)) {
247
+ await installAgy({ run, release, tmpRoot });
248
+ } else if (h === 'claude' && opts.command === 'update') {
249
+ if (claudeError) throw claudeError;
250
+ const scopes = [...new Set(claudeRows.map(p => p.scope))];
251
+ if (!scopes.length) throw new Error('Claude: no installed mARC scopes; run install first');
252
+ if (scopes.some(s => !SCOPES.includes(s))) throw new Error('Claude: unmodifiable/unknown scope; update it manually');
253
+ const targets = new Map();
254
+ for (const row of claudeRows) {
255
+ const targetCwd = row.scope === 'user' ? cwd : row.projectPath || cwd;
256
+ if (!path.isAbsolute(targetCwd)) throw new Error('Claude: invalid project path');
257
+ targets.set(`${row.scope}\0${targetCwd}`, { scope: row.scope, cwd: targetCwd });
258
+ }
259
+ await run(h, ['plugin', 'marketplace', 'update', 'nexaduo']);
260
+ for (const target of targets.values()) {
261
+ try {
262
+ if (!(await stat(target.cwd)).isDirectory()) throw new Error('project path is not a directory');
263
+ await run(h, ['plugin', 'update', ID, ...scopeArgs(target.scope)], { cwd: target.cwd });
264
+ } catch (e) {
265
+ log(`claude: warning: skipped ${target.scope} scope at ${target.cwd}: ${e.message}`);
266
+ failed = true;
267
+ }
268
+ }
269
+ } else if (opts.command === 'install') {
270
+ const markets = parseMarketplaces(h, await run(h, ['plugin', 'marketplace', 'list', '--json']));
271
+ if (markets.length && !markets.every(m => marketplaceMatches(h, m))) {
272
+ manualRemedy(h, log, opts.scope);
273
+ throw new Error('nexaduo is registered from a different or unverified source; registration preserved');
274
+ }
275
+ if (!markets.length) await run(h, ['plugin', 'marketplace', 'add', SLUG]);
276
+ else log(`${h}: nexaduo already registered from ${SLUG}; skipping add`);
277
+ await run(h, ['plugin', h === 'codex' ? 'add' : 'install', ID, ...(h === 'claude' ? scopeArgs(opts.scope || 'user') : [])]);
278
+ } else {
279
+ for (const args of plan({ ...opts, harnesses: [h] })[0].commands) await run(h, args);
280
+ }
281
+ } catch (e) { log(`${h}: ${e.message}`); failed = true; }
282
+ results.push({ harness: h, failed });
283
+ if (failed) status = 1;
284
+ }
285
+ for (const { harness, failed } of results) log(`${harness}: ${failed ? 'FAILED' : 'OK'}`);
286
+ return status;
287
+ }
package/lib/process.js ADDED
@@ -0,0 +1,117 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { accessSync, constants, realpathSync, statSync } from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ export const SAFE_VALUE = /^[A-Za-z0-9@._/:#-]+$/;
6
+ const SAFE_GENERATED_PATH = /^[A-Za-z0-9@._/:#~\\-]+$/;
7
+ const FLAGS = new Set(['--json', '--dry-run', '--scope', '--depth', '--branch', '--no-checkout', '--no-optional-locks', '--detach', '--force', '-r']);
8
+ export function safeValue(value) {
9
+ if (typeof value !== 'string' || !SAFE_VALUE.test(value) || /[\r\n]/.test(value) || value.startsWith('-')) throw new Error(`Unsafe value: ${JSON.stringify(value)}`);
10
+ return value;
11
+ }
12
+ function samePath(a, b, p = path) {
13
+ return p.relative(a, b) === '';
14
+ }
15
+ function executableInCwd(file, cwd, p = path) {
16
+ return samePath(p.dirname(file), cwd, p);
17
+ }
18
+
19
+ // PATH is the user's trust boundary. Never search cwd, relative PATH entries,
20
+ // or symlinks into cwd. PATHEXT can only select known executable extensions.
21
+ export function resolveExecutable(name, { env = process.env, cwd = process.cwd(), platform = process.platform } = {}) {
22
+ safeValue(name);
23
+ if (/[/:]/.test(name)) throw new Error('Executable names must be bare names');
24
+ const win = platform === 'win32';
25
+ const p = win ? path.win32 : path;
26
+ const extensions = win ? (env.PATHEXT || '.COM;.EXE;.BAT;.CMD').split(';')
27
+ .map(e => e.toLowerCase()).filter(e => ['.com', '.exe', '.bat', '.cmd'].includes(e)) : [''];
28
+ let realCwd;
29
+ try { realCwd = realpathSync(cwd); } catch { realCwd = cwd; }
30
+ for (const dir of (env.PATH || env.Path || '').split(win ? ';' : ':')) {
31
+ if (!p.isAbsolute(dir) || samePath(p.resolve(dir), cwd, p)) continue;
32
+ for (const ext of extensions) {
33
+ const file = p.join(dir, name + ext);
34
+ try {
35
+ const real = realpathSync(file);
36
+ if (executableInCwd(real, realCwd, p) || !statSync(real).isFile()) continue;
37
+ accessSync(real, win ? constants.F_OK : constants.X_OK);
38
+ return real;
39
+ } catch { /* Try the next executable, without invoking anything. */ }
40
+ }
41
+ }
42
+ throw new Error(`${name} was not found on PATH outside the current directory`);
43
+ }
44
+
45
+ export function spawnSpec(file, args, { platform = process.platform, env = process.env, generatedPaths = [] } = {}) {
46
+ if (platform !== 'win32' || !/\.(cmd|bat)$/i.test(file)) return { file, args, options: {} };
47
+ for (const [index, arg] of args.entries()) {
48
+ // Only internal call sites mark generated absolute paths. User values
49
+ // always retain SAFE_VALUE and the constant-only flag check.
50
+ if (generatedPaths.includes(index)) {
51
+ if (typeof arg === 'string' && /\s/.test(arg) && !/[\r\n]/.test(arg)) throw new Error('Generated Windows batch path contains whitespace; set TMP/TEMP to a directory without spaces');
52
+ if (typeof arg !== 'string' || !path.win32.isAbsolute(arg) || !SAFE_GENERATED_PATH.test(arg) || /[\r\n]/.test(arg)) {
53
+ throw new Error(`Unsafe generated Windows batch path: ${JSON.stringify(arg)}`);
54
+ }
55
+ continue;
56
+ }
57
+ if (typeof arg !== 'string' || !SAFE_VALUE.test(arg) || /[\r\n]/.test(arg) || (arg.startsWith('-') && !FLAGS.has(arg))) {
58
+ throw new Error(`Unsafe Windows batch argument: ${JSON.stringify(arg)}`);
59
+ }
60
+ }
61
+ // Do not trust COMSPEC or resolve cmd.exe through PATH. Spaces are permitted
62
+ // only in the quoted, absolute executable path; all shell metacharacters fail.
63
+ if (!path.win32.isAbsolute(file) || /[&|%\^"!\r\n]/.test(file)) throw new Error('Unsafe batch path');
64
+ const root = env.SystemRoot || env.SYSTEMROOT;
65
+ if (!root || !path.win32.isAbsolute(root) || /[&|%\^"!\r\n]/.test(root)) throw new Error('Unsafe SystemRoot');
66
+ const cmd = path.win32.join(root, 'System32', 'cmd.exe');
67
+ const cwd = process.cwd();
68
+ if (executableInCwd(cmd, cwd, path.win32)) throw new Error('cmd.exe cannot come from cwd');
69
+ return { file: cmd, args: ['/d', '/s', '/c', `""${file}" ${args.join(' ')}"`],
70
+ options: { windowsVerbatimArguments: true } };
71
+ }
72
+
73
+ function childEnvironment(env, cwd) {
74
+ const win = process.platform === 'win32';
75
+ const paths = (env.PATH || env.Path || '').split(path.delimiter).filter(dir => {
76
+ try { return path.isAbsolute(dir) && !samePath(realpathSync(dir), realpathSync(cwd)); } catch { return false; }
77
+ });
78
+ const clean = Object.fromEntries(Object.entries(env).filter(([k]) => !['PATH', 'PATHEXT'].includes(k.toUpperCase())));
79
+ clean.PATH = paths.join(path.delimiter);
80
+ if (win) {
81
+ clean.PATHEXT = (env.PATHEXT || '.COM;.EXE;.BAT;.CMD').split(';').filter(e => /^\.(COM|EXE|BAT|CMD)$/i.test(e)).join(';');
82
+ clean.NoDefaultCurrentDirectoryInExePath = '1';
83
+ }
84
+ return clean;
85
+ }
86
+
87
+ export function createRunner({ env = process.env, cwd = process.cwd() } = {}) {
88
+ // Resolve and launch the same absolute path (no second PATH lookup).
89
+ return async (name, args, options = {}) => {
90
+ const file = resolveExecutable(name, { env, cwd });
91
+ if (options.cwd && executableInCwd(realpathSync(file), realpathSync(options.cwd))) throw new Error('Executable resolves inside command cwd');
92
+ let childEnv = childEnvironment(env, options.cwd || cwd);
93
+ if (options.isolatedGit) {
94
+ childEnv = Object.fromEntries(Object.entries(childEnv).filter(([k]) => !k.toUpperCase().startsWith('GIT_')));
95
+ Object.assign(childEnv, { GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: process.platform === 'win32' ? 'NUL' : '/dev/null',
96
+ GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'core.hooksPath',
97
+ GIT_CONFIG_VALUE_0: process.platform === 'win32' ? 'NUL' : '/dev/null', GIT_TERMINAL_PROMPT: '0' });
98
+ }
99
+ const spec = spawnSpec(file, args, { env: childEnv, generatedPaths: options.generatedPaths });
100
+ return new Promise((resolve, reject) => {
101
+ const child = spawn(spec.file, spec.args, { ...spec.options, env: childEnv, cwd: options.cwd || cwd,
102
+ stdio: ['ignore', 'pipe', 'pipe'] });
103
+ child.stdout.setEncoding('utf8');
104
+ child.stderr.setEncoding('utf8');
105
+ let stdout = '', stderr = '';
106
+ const timer = setTimeout(() => { child.kill(); reject(new Error(`${name} timed out`)); }, 120000);
107
+ child.stdout.on('data', b => { stdout += b; if (stdout.length > 4 * 1024 * 1024) child.kill(); });
108
+ child.stderr.on('data', b => { stderr += b; if (stderr.length > 4 * 1024 * 1024) child.kill(); });
109
+ child.on('error', e => { clearTimeout(timer); reject(e); });
110
+ child.on('close', code => {
111
+ clearTimeout(timer);
112
+ if (code !== 0) reject(new Error(`${name} ${args.join(' ')} failed (${code}): ${stderr.trim()}`));
113
+ else resolve(stdout);
114
+ });
115
+ });
116
+ };
117
+ }
package/lib/version.js ADDED
@@ -0,0 +1,22 @@
1
+ // Calendar tags have three components and an optional positive release number.
2
+ export function tagToNpm(tag) {
3
+ const m = /^v([1-9][0-9])\.([1-9][0-9]?)\.([1-9][0-9]?)(?:\.([1-9][0-9]*))?$/.exec(tag);
4
+ if (!m || m[0] !== tag) throw new Error(`Invalid release tag: ${tag}`);
5
+ const [y, month, day, n] = [Number(m[1]), Number(m[2]), Number(m[3]), Number(m[4] || 0)];
6
+ const date = new Date(Date.UTC(2000 + y, month - 1, day));
7
+ if (date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day ||
8
+ y * 10000 + month * 100 + day < 261125 || !Number.isSafeInteger(n)) {
9
+ throw new Error(`Unsupported release tag: ${tag}`);
10
+ }
11
+ return `${y}.${month * 100 + day}.${n}`;
12
+ }
13
+
14
+ export function npmToTag(version) {
15
+ if (!/^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/.test(version)) {
16
+ throw new Error(`Invalid npm version: ${version}`);
17
+ }
18
+ const [y, md, n] = version.split('.').map(Number);
19
+ const tag = `v${y}.${Math.floor(md / 100)}.${md % 100}${n ? `.${n}` : ''}`;
20
+ if (tagToNpm(tag) !== version) throw new Error(`Invalid npm version: ${version}`);
21
+ return tag;
22
+ }
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@nexaduo/marc",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "26.1125.3",
4
+ "description": "Install and update mARC through native harness plugin CLIs",
5
+ "type": "module",
6
+ "bin": {"marc": "bin/marc.js"},
7
+ "engines": {"node": ">=20"},
8
+ "files": ["bin/", "lib/", "release.json", "LICENSE", "README.md"],
9
+ "repository": {"type": "git", "url": "git+https://github.com/NexaDuo/mARC.git", "directory": "launcher"},
10
+ "license": "MIT"
11
+ }
package/release.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "tag": "v26.11.25.3",
3
+ "sha": "dc609f2b1fd4db7073a3470764577d117c868760",
4
+ "npm": "26.1125.3"
5
+ }