@openagile/avc 1.0.0-beta.41 → 1.0.0-beta.42
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/README.md +1 -1
- package/cli-wrapper.cjs +21 -13
- package/fetch-native.cjs +139 -0
- package/install.cjs +33 -17
- package/package.json +9 -8
package/README.md
CHANGED
package/cli-wrapper.cjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
//
|
|
3
|
-
// Fallback wrapper for @openagile/avc. Used when the postinstall
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
3
|
+
// Fallback wrapper for @openagile/avc. Used when the postinstall did not
|
|
4
|
+
// place the native binary (bin/avc.exe is still the small placeholder):
|
|
5
|
+
// --omit=optional, scripts disabled, or a download that failed. At runtime
|
|
6
|
+
// it re-resolves the matching native package; when that is missing it runs
|
|
7
|
+
// the postinstall once more, which downloads the package (fetch-native.cjs),
|
|
8
|
+
// and then exec's the binary.
|
|
8
9
|
|
|
9
10
|
const { spawn, spawnSync } = require('child_process');
|
|
10
11
|
const path = require('path');
|
|
11
12
|
const { arch } = require('os');
|
|
13
|
+
const { resolveNative, wantedVersion } = require('./fetch-native.cjs');
|
|
12
14
|
|
|
13
15
|
const PACKAGE_PREFIX = '@openagile/avc';
|
|
14
16
|
const BINARY_NAME = 'avc';
|
|
@@ -50,16 +52,22 @@ if (!info) {
|
|
|
50
52
|
process.exit(1);
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
let
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
let pkgDir = resolveNative(info.pkg, __dirname);
|
|
56
|
+
if (!pkgDir) {
|
|
57
|
+
// The install left the wrapper without its binary. Do now what the
|
|
58
|
+
// postinstall could not do then (its own messages say what happens).
|
|
59
|
+
spawnSync(process.execPath, [path.join(__dirname, 'install.cjs')], { stdio: ['ignore', 2, 2], env: { ...process.env, npm_config_omit: '' } });
|
|
60
|
+
pkgDir = resolveNative(info.pkg, __dirname);
|
|
61
|
+
}
|
|
62
|
+
if (!pkgDir) {
|
|
63
|
+
const wrapper = require('./package.json');
|
|
64
|
+
const version = wantedVersion(info.pkg, __dirname);
|
|
65
|
+
console.error(`[avc] Native package "${info.pkg}@${version}" is not installed and could not be downloaded.`);
|
|
66
|
+
console.error(' Check the network connection, then install this exact version again:');
|
|
67
|
+
console.error(` npm install -g ${wrapper.name}@${wrapper.version}`);
|
|
61
68
|
process.exit(1);
|
|
62
69
|
}
|
|
70
|
+
const binPath = path.join(pkgDir, info.bin);
|
|
63
71
|
|
|
64
72
|
const child = spawn(binPath, process.argv.slice(2), {
|
|
65
73
|
stdio: 'inherit',
|
package/fetch-native.cjs
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Gets the native package when npm did not install it.
|
|
3
|
+
//
|
|
4
|
+
// The native binary lives in a platform package that the wrapper lists as an
|
|
5
|
+
// optionalDependency. npm skips an optional dependency it cannot fetch
|
|
6
|
+
// WITHOUT failing the install and without a word: the user ends up with the
|
|
7
|
+
// wrapper alone and `avc` prints "Native package not installed".
|
|
8
|
+
//
|
|
9
|
+
// That happens for real right after a release. The platform packages are
|
|
10
|
+
// ~100 MB each; the registry (and its CDN, and npm's own 5-minute cache of
|
|
11
|
+
// package metadata) can serve the new wrapper while still answering "no such
|
|
12
|
+
// version" for the platform package it pins. Seen with 1.0.0-beta.41:
|
|
13
|
+
// installed four minutes after publishing, wrapper present, binary missing.
|
|
14
|
+
//
|
|
15
|
+
// So the wrapper fetches the package itself: `npm install` of that one
|
|
16
|
+
// package into a scratch folder, asking the registry again each time
|
|
17
|
+
// (`--prefer-online`), a few times with a pause, then moved into the
|
|
18
|
+
// wrapper's own node_modules, where `require.resolve` finds it.
|
|
19
|
+
|
|
20
|
+
const { spawnSync } = require('child_process');
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
const os = require('os');
|
|
23
|
+
const path = require('path');
|
|
24
|
+
|
|
25
|
+
/** The version of the platform package this wrapper was published with. */
|
|
26
|
+
function wantedVersion(pkgName, wrapperDir = __dirname) {
|
|
27
|
+
const wrapper = JSON.parse(fs.readFileSync(path.join(wrapperDir, 'package.json'), 'utf8'));
|
|
28
|
+
return (wrapper.optionalDependencies || {})[pkgName] || wrapper.version;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The user asked npm to leave optional dependencies out: respect it. */
|
|
32
|
+
function optionalOmitted(env = process.env) {
|
|
33
|
+
const omit = String(env.npm_config_omit || '').split(/[\s,]+/);
|
|
34
|
+
return omit.includes('optional') || env.npm_config_optional === 'false';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Where the package is, when it is installed where this wrapper can load it. */
|
|
38
|
+
function resolveNative(pkgName, wrapperDir = __dirname) {
|
|
39
|
+
let dir = null;
|
|
40
|
+
try {
|
|
41
|
+
dir = path.dirname(require.resolve(`${pkgName}/package.json`, { paths: [wrapperDir] }));
|
|
42
|
+
} catch {
|
|
43
|
+
const local = path.join(wrapperDir, 'node_modules', ...pkgName.split('/'));
|
|
44
|
+
if (fs.existsSync(path.join(local, 'package.json'))) dir = local;
|
|
45
|
+
}
|
|
46
|
+
if (!dir) return null;
|
|
47
|
+
// A copy of another version (one installed by hand next to the wrapper)
|
|
48
|
+
// is not the binary this wrapper was published with.
|
|
49
|
+
try {
|
|
50
|
+
const found = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')).version;
|
|
51
|
+
if (found !== wantedVersion(pkgName, wrapperDir)) return null;
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return dir;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The environment for the nested npm. Inside `npm install -g` the lifecycle
|
|
60
|
+
* environment says "global" and names the global prefix; passed on, the
|
|
61
|
+
* nested install would go there instead of the scratch folder.
|
|
62
|
+
*/
|
|
63
|
+
function nestedEnv(env) {
|
|
64
|
+
const out = {};
|
|
65
|
+
for (const [key, value] of Object.entries(env)) {
|
|
66
|
+
if (/^npm_config_(global|prefix|local_prefix|location|omit|optional|dry_run|global_style|install_links)$/i.test(key)) continue;
|
|
67
|
+
if (/^npm_(lifecycle|package)_/i.test(key)) continue;
|
|
68
|
+
out[key] = value;
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function npmInvocation(env) {
|
|
74
|
+
// Inside a lifecycle script npm says where it is; outside, it is on PATH.
|
|
75
|
+
if (env.npm_execpath && /npm-cli\.js$/.test(env.npm_execpath) && fs.existsSync(env.npm_execpath)) {
|
|
76
|
+
return { cmd: process.execPath, args: [env.npm_execpath], shell: false };
|
|
77
|
+
}
|
|
78
|
+
return { cmd: process.platform === 'win32' ? 'npm.cmd' : 'npm', args: [], shell: process.platform === 'win32' };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function sleepSync(ms) {
|
|
82
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Download `<pkgName>@<version>` into `<wrapperDir>/node_modules/<pkgName>`.
|
|
87
|
+
*
|
|
88
|
+
* @returns {{ ok: true, dir: string, attempts: number } | { ok: false, reason: string, attempts: number }}
|
|
89
|
+
*/
|
|
90
|
+
function fetchNative(pkgName, {
|
|
91
|
+
wrapperDir = __dirname, attempts = null, pauseMs = null,
|
|
92
|
+
log = (line) => console.error(line), env = process.env, run = spawnSync, sleep = sleepSync,
|
|
93
|
+
} = {}) {
|
|
94
|
+
// Six tries, ten seconds apart: about a minute, which covers the delay seen
|
|
95
|
+
// after a release. Both can be set from the environment (a slow mirror, a test).
|
|
96
|
+
const fromEnv = (name, fallback) => (Number.isFinite(Number(env[name])) && env[name] !== undefined && env[name] !== '' ? Number(env[name]) : fallback);
|
|
97
|
+
attempts = Math.max(1, attempts ?? fromEnv('AVC_NATIVE_FETCH_ATTEMPTS', 6));
|
|
98
|
+
pauseMs = Math.max(0, pauseMs ?? fromEnv('AVC_NATIVE_FETCH_PAUSE_MS', 10000));
|
|
99
|
+
const version = wantedVersion(pkgName, wrapperDir);
|
|
100
|
+
const dest = path.join(wrapperDir, 'node_modules', ...pkgName.split('/'));
|
|
101
|
+
const { cmd, args, shell } = npmInvocation(env);
|
|
102
|
+
let reason = 'npm did not run';
|
|
103
|
+
|
|
104
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
105
|
+
const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'avc-native-'));
|
|
106
|
+
try {
|
|
107
|
+
const r = run(cmd, [
|
|
108
|
+
...args, 'install', '--no-save', '--no-audit', '--no-fund', '--ignore-scripts', '--prefer-online',
|
|
109
|
+
'--prefix', scratch, `${pkgName}@${version}`,
|
|
110
|
+
], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], env: nestedEnv(env), shell, timeout: 300000 });
|
|
111
|
+
const got = path.join(scratch, 'node_modules', ...pkgName.split('/'));
|
|
112
|
+
if (r && r.status === 0 && fs.existsSync(path.join(got, 'package.json'))) {
|
|
113
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
114
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
115
|
+
try { fs.renameSync(got, dest); } catch { fs.cpSync(got, dest, { recursive: true }); }
|
|
116
|
+
return { ok: true, dir: dest, attempts: attempt };
|
|
117
|
+
}
|
|
118
|
+
const output = `${(r && r.stderr) || ''}\n${(r && r.stdout) || ''}`;
|
|
119
|
+
// npm prints `code ETARGET` and then what it means: keep both, in one line.
|
|
120
|
+
const lines = output.split('\n').map((l) => l.trim())
|
|
121
|
+
.filter((l) => /^npm (error|ERR!)/.test(l) && !/A complete log/.test(l))
|
|
122
|
+
.map((l) => l.replace(/^npm (error|ERR!)\s*/, ''));
|
|
123
|
+
const code = (lines.find((l) => /^code \S+/.test(l)) || '').replace(/^code\s+/, '');
|
|
124
|
+
const message = (lines.find((l) => l && !/^code \S+/.test(l)) || '').replace(/^(notarget|404|network)\s+/, '');
|
|
125
|
+
reason = (r && r.error && r.error.message) || [code, message].filter(Boolean).join(': ') || `npm exited with ${r ? r.status : 'no status'}`;
|
|
126
|
+
} catch (err) {
|
|
127
|
+
reason = err.message;
|
|
128
|
+
} finally {
|
|
129
|
+
try { fs.rmSync(scratch, { recursive: true, force: true }); } catch { /* scratch folder in use */ }
|
|
130
|
+
}
|
|
131
|
+
if (attempt < attempts) {
|
|
132
|
+
log(` ${pkgName}@${version} is not available yet (${reason}) — trying again in ${Math.round(pauseMs / 1000)} s (${attempt}/${attempts})`);
|
|
133
|
+
sleep(pauseMs);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return { ok: false, reason, attempts };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
module.exports = { fetchNative, resolveNative, optionalOmitted, wantedVersion, nestedEnv };
|
package/install.cjs
CHANGED
|
@@ -7,15 +7,19 @@
|
|
|
7
7
|
// and hardlinks it over the bin/avc.exe stub. Adapted from Claude Code's
|
|
8
8
|
// install.cjs (same pattern Bun, esbuild, swc, biome use).
|
|
9
9
|
//
|
|
10
|
-
// If the matching native package is missing
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
10
|
+
// If the matching native package is missing, it downloads it itself
|
|
11
|
+
// (fetch-native.cjs): npm skips an optional dependency it cannot fetch
|
|
12
|
+
// without failing and without a word, which happens right after a release
|
|
13
|
+
// while the registry does not serve the platform package yet. Only with
|
|
14
|
+
// --omit=optional, on an unsupported platform or when that download fails
|
|
15
|
+
// too, the stub stays in place; cli-wrapper.cjs then tries once more when
|
|
16
|
+
// `avc` is run, and says how to reinstall.
|
|
14
17
|
|
|
15
18
|
const { spawnSync } = require('child_process');
|
|
16
19
|
const { copyFileSync, linkSync, unlinkSync, chmodSync, readFileSync, writeFileSync, statSync, existsSync } = require('fs');
|
|
17
20
|
const { arch } = require('os');
|
|
18
21
|
const path = require('path');
|
|
22
|
+
const { fetchNative, resolveNative, optionalOmitted, wantedVersion } = require('./fetch-native.cjs');
|
|
19
23
|
|
|
20
24
|
const PACKAGE_PREFIX = '@openagile/avc';
|
|
21
25
|
const BINARY_NAME = 'avc';
|
|
@@ -98,26 +102,38 @@ function main() {
|
|
|
98
102
|
return;
|
|
99
103
|
}
|
|
100
104
|
|
|
101
|
-
let
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const pkgDir = path.dirname(require.resolve(info.pkg + '/package.json'));
|
|
105
|
-
srcBinary = path.join(pkgDir, info.bin);
|
|
106
|
-
srcClientDist = path.join(pkgDir, 'client-dist');
|
|
107
|
-
} catch {
|
|
108
|
-
console.error(`[${WRAPPER_NAME} postinstall] Native package "${info.pkg}" not found.`);
|
|
105
|
+
let pkgDir = resolveNative(info.pkg, __dirname);
|
|
106
|
+
if (!pkgDir) {
|
|
107
|
+
const version = wantedVersion(info.pkg, __dirname);
|
|
109
108
|
if (platformKey === 'darwin-arm64' && arch() === 'x64') {
|
|
109
|
+
console.error(`[${WRAPPER_NAME} postinstall] Native package "${info.pkg}" not found.`);
|
|
110
110
|
console.error(' You are running x64 Node under Rosetta 2 on Apple Silicon. npm only');
|
|
111
111
|
console.error(' installed the darwin-x64 binary, which requires AVX (not emulated by');
|
|
112
112
|
console.error(' Rosetta). Install arm64 Node and reinstall — e.g. via nvm:');
|
|
113
|
-
console.error(` arch -arm64 zsh -c "nvm install --lts && npm i -g ${WRAPPER_NAME}"`);
|
|
113
|
+
console.error(` arch -arm64 zsh -c "nvm install --lts && npm i -g ${WRAPPER_NAME}@${version}"`);
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
if (optionalOmitted()) {
|
|
117
|
+
console.error(`[${WRAPPER_NAME} postinstall] Native package "${info.pkg}" was left out (--omit=optional).`);
|
|
118
|
+
console.error(` The \`avc\` command needs it. Reinstall without that option:`);
|
|
119
|
+
console.error(` npm install -g ${WRAPPER_NAME}@${version}`);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
// npm skipped it silently: it could not fetch it (just after a release
|
|
123
|
+
// the registry may not serve the platform package yet).
|
|
124
|
+
console.error(`[${WRAPPER_NAME} postinstall] npm did not install the native package "${info.pkg}@${version}". Downloading it now...`);
|
|
125
|
+
const fetched = fetchNative(info.pkg, { wrapperDir: __dirname });
|
|
126
|
+
if (!fetched.ok) {
|
|
127
|
+
console.error(`[${WRAPPER_NAME} postinstall] Could not download "${info.pkg}@${version}": ${fetched.reason}`);
|
|
128
|
+
console.error(' `avc` will try once more when you run it. To install it by hand:');
|
|
129
|
+
console.error(` npm install -g ${WRAPPER_NAME}@${version}`);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
console.error(`[${WRAPPER_NAME} postinstall] Downloaded "${info.pkg}@${version}".`);
|
|
133
|
+
pkgDir = fetched.dir;
|
|
120
134
|
}
|
|
135
|
+
const srcBinary = path.join(pkgDir, info.bin);
|
|
136
|
+
const srcClientDist = path.join(pkgDir, 'client-dist');
|
|
121
137
|
|
|
122
138
|
// bin/avc.exe is the published stub; the npm bin shim was generated at
|
|
123
139
|
// install time pointing here, so we must write to the same path. The
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openagile/avc",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.42",
|
|
4
4
|
"description": "Open Agile (AVC) — native CLI for AI agent-based software development. Installs the right binary for your platform.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"bin": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"install.cjs",
|
|
14
14
|
"cli-wrapper.cjs",
|
|
15
|
+
"fetch-native.cjs",
|
|
15
16
|
"bin/avc.exe",
|
|
16
17
|
"LICENSE",
|
|
17
18
|
"README.md"
|
|
@@ -20,13 +21,13 @@
|
|
|
20
21
|
"node": ">=18.0.0"
|
|
21
22
|
},
|
|
22
23
|
"optionalDependencies": {
|
|
23
|
-
"@openagile/avc-darwin-arm64": "1.0.0-beta.
|
|
24
|
-
"@openagile/avc-darwin-x64": "1.0.0-beta.
|
|
25
|
-
"@openagile/avc-linux-arm64": "1.0.0-beta.
|
|
26
|
-
"@openagile/avc-linux-arm64-musl": "1.0.0-beta.
|
|
27
|
-
"@openagile/avc-linux-x64": "1.0.0-beta.
|
|
28
|
-
"@openagile/avc-linux-x64-musl": "1.0.0-beta.
|
|
29
|
-
"@openagile/avc-win32-x64": "1.0.0-beta.
|
|
24
|
+
"@openagile/avc-darwin-arm64": "1.0.0-beta.42",
|
|
25
|
+
"@openagile/avc-darwin-x64": "1.0.0-beta.42",
|
|
26
|
+
"@openagile/avc-linux-arm64": "1.0.0-beta.42",
|
|
27
|
+
"@openagile/avc-linux-arm64-musl": "1.0.0-beta.42",
|
|
28
|
+
"@openagile/avc-linux-x64": "1.0.0-beta.42",
|
|
29
|
+
"@openagile/avc-linux-x64-musl": "1.0.0-beta.42",
|
|
30
|
+
"@openagile/avc-win32-x64": "1.0.0-beta.42"
|
|
30
31
|
},
|
|
31
32
|
"publishConfig": {
|
|
32
33
|
"access": "public"
|