aegiscode 7.0.12 → 7.0.13
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/bin/aegiscode.js +12 -0
- package/package.json +2 -1
- package/scripts/predist.mjs +6 -3
- package/src/app.js +102 -1
- package/src/commands.js +45 -5
- package/src/limits.js +1 -1
- package/src/provenance.lock.json +2 -2
- package/src/update.js +103 -12
- package/vendor/client/aegis.js +169 -3
- package/vendor/client/drive-connect.js +87 -0
- package/vendor/client/drive-upload.js +176 -0
- package/vendor/client/update.js +100 -8
- package/vendor/desktop/lib/local/engine.js +64 -1
- package/vendor/desktop/lib/local/prompt.js +67 -37
- package/vendor/desktop/lib/local/tools.js +49 -13
package/bin/aegiscode.js
CHANGED
|
@@ -94,6 +94,11 @@ Provenance (this binary, and whether it is still the published one):
|
|
|
94
94
|
|
|
95
95
|
Options:
|
|
96
96
|
-m, --model <id> pin a model id (see /models; default: server choice)
|
|
97
|
+
--class <name> run this turn on aegis|byok|local|pro. The one-shot
|
|
98
|
+
path had no way to state a class, so '-p' always ran
|
|
99
|
+
the pooled route (DEFAULT_CLASS) no matter what was
|
|
100
|
+
pinned — a headless turn could not use a BYOK key at
|
|
101
|
+
all. '--class byok' needs '--model <provider>:<model>'.
|
|
97
102
|
--base <url> API base (default $AEGIS_API_BASE or aegiscloud.org)
|
|
98
103
|
--key <key> API key for THIS RUN only — it is not saved. Use
|
|
99
104
|
"aegiscode login" to store one for good.
|
|
@@ -128,6 +133,9 @@ function parseArgs(argv) {
|
|
|
128
133
|
base: null,
|
|
129
134
|
key: null,
|
|
130
135
|
json: false,
|
|
136
|
+
// No `--class` flag given: `null` (not DEFAULT_CLASS) so the stored config
|
|
137
|
+
// pin still wins, exactly as it does for a launch with no `--model`.
|
|
138
|
+
class: null,
|
|
131
139
|
stream: true,
|
|
132
140
|
maxTokens: undefined,
|
|
133
141
|
light: false,
|
|
@@ -261,6 +269,9 @@ function parseArgs(argv) {
|
|
|
261
269
|
case '--model':
|
|
262
270
|
opts.model = next();
|
|
263
271
|
break;
|
|
272
|
+
case '--class':
|
|
273
|
+
opts.class = next();
|
|
274
|
+
break;
|
|
264
275
|
case '--base':
|
|
265
276
|
opts.base = next();
|
|
266
277
|
break;
|
|
@@ -826,6 +837,7 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
826
837
|
|
|
827
838
|
const app = createApp({
|
|
828
839
|
model: opts.model,
|
|
840
|
+
class: opts.class,
|
|
829
841
|
stream: opts.stream,
|
|
830
842
|
light: opts.light,
|
|
831
843
|
maxTokens: opts.maxTokens,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aegiscode",
|
|
3
3
|
"productName": "AEGIS Code",
|
|
4
|
-
"version": "7.0.
|
|
4
|
+
"version": "7.0.13",
|
|
5
5
|
"description": "aegiscode — the command-line version of AEGIS Desktop. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "AEGIS Code",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"start": "node bin/aegiscode.js",
|
|
28
28
|
"predist": "node scripts/predist.mjs",
|
|
29
|
+
"prepack": "node scripts/predist.mjs --quiet",
|
|
29
30
|
"prepublishOnly": "npm run predist",
|
|
30
31
|
"precheck": "node scripts/predist.mjs",
|
|
31
32
|
"check": "node scripts/check.mjs",
|
package/scripts/predist.mjs
CHANGED
|
@@ -37,7 +37,10 @@ import { sealGate } from './seal-gate.mjs';
|
|
|
37
37
|
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
38
38
|
const SHARED = path.join(HERE, '..', '..', 'one', 'scripts', 'predist.mjs');
|
|
39
39
|
|
|
40
|
-
async function main() {
|
|
40
|
+
async function main(argv) {
|
|
41
|
+
// `--quiet` is forwarded, not swallowed: `prepack` passes it so these
|
|
42
|
+
// progress lines do not corrupt `npm pack --json`; publishing keeps them.
|
|
43
|
+
const args = Array.isArray(argv) ? argv : process.argv.slice(2), quiet = args.includes('--quiet') ? ['--quiet'] : [];
|
|
41
44
|
const gate = sealGate();
|
|
42
45
|
if (!gate.ok && !process.env.AEGIS_ALLOW_UNSEALED) {
|
|
43
46
|
process.stderr.write(
|
|
@@ -65,11 +68,11 @@ async function main() {
|
|
|
65
68
|
);
|
|
66
69
|
return 1;
|
|
67
70
|
}
|
|
68
|
-
return shared.main(['--mirror-only']);
|
|
71
|
+
return shared.main(['--mirror-only', ...quiet]);
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
72
|
-
process.exitCode = await main();
|
|
75
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
export { main, sealGate };
|
package/src/app.js
CHANGED
|
@@ -181,6 +181,24 @@ function providerRefusal(text, usage) {
|
|
|
181
181
|
return null;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* One tool call, readable — the arg summary published in `--json`'s `tool_log`.
|
|
186
|
+
*
|
|
187
|
+
* Truncated on a character boundary so a row stays a record a person can read
|
|
188
|
+
* while still showing WHAT each call was. A list of tool names cannot tell
|
|
189
|
+
* "read four files" apart from "ran the same test twelve times", and the
|
|
190
|
+
* archived AEGIS rows carried only names.
|
|
191
|
+
*
|
|
192
|
+
* @param {unknown} a the call's arguments
|
|
193
|
+
* @returns {string} a single line, at most 140 characters
|
|
194
|
+
*/
|
|
195
|
+
function briefArgs(a) {
|
|
196
|
+
let s;
|
|
197
|
+
try { s = typeof a === 'string' ? a : JSON.stringify(a ?? ''); } catch { s = String(a); }
|
|
198
|
+
s = String(s).replace(/\s+/g, ' ').trim();
|
|
199
|
+
return s.length > 140 ? `${s.slice(0, 137)}...` : s;
|
|
200
|
+
}
|
|
201
|
+
|
|
184
202
|
function createApp(options = {}) {
|
|
185
203
|
const opts = {
|
|
186
204
|
model: null,
|
|
@@ -2139,10 +2157,57 @@ function createApp(options = {}) {
|
|
|
2139
2157
|
// scored three tasks SOLVED with `tool_calls: 0` while the workspace showed
|
|
2140
2158
|
// genuine edits, because nothing published the count.
|
|
2141
2159
|
const toolsUsed = [];
|
|
2160
|
+
const toolLog = [];
|
|
2142
2161
|
const jsonPresenter = json
|
|
2143
2162
|
? {
|
|
2144
2163
|
tool: (tool) => {
|
|
2145
|
-
|
|
2164
|
+
// One entry per CALL, not per frame. The engine reports every tool
|
|
2165
|
+
// twice — `phase: 'run'` before it executes and `phase: 'done'`
|
|
2166
|
+
// with the outcome — and both arrive here. Pushing on both doubled
|
|
2167
|
+
// `tools` (a 6-call turn published 12-14 names), and the benchmark
|
|
2168
|
+
// adapters count array elements as calls, so AEGIS's tool count was
|
|
2169
|
+
// inflated by exactly 2x while its `tokens_per_solved` was flattered
|
|
2170
|
+
// by the same factor. The done frame now only settles the entry it
|
|
2171
|
+
// belongs to.
|
|
2172
|
+
const phase = tool && tool.phase;
|
|
2173
|
+
if (phase === 'done') {
|
|
2174
|
+
const match = (tool.id && toolLog.find((c) => c.id === tool.id && c.settled !== true))
|
|
2175
|
+
|| (tool.id ? null : toolLog[toolLog.length - 1]);
|
|
2176
|
+
if (match) {
|
|
2177
|
+
match.settled = true;
|
|
2178
|
+
match.ok = tool.ok !== false;
|
|
2179
|
+
} else {
|
|
2180
|
+
// A `done` frame with no unsettled entry to settle is a call we
|
|
2181
|
+
// are learning about for the first time — the engine batched or
|
|
2182
|
+
// outlived the matching `run` frame (seen on the sweep: one
|
|
2183
|
+
// `run` then every later call arriving already `done`). Falling
|
|
2184
|
+
// back to "settle the last entry" silently discarded those
|
|
2185
|
+
// calls: a task that ran 7 tools published `tool_calls: 1`
|
|
2186
|
+
// while its own stderr rendered all 7. Record it, already
|
|
2187
|
+
// settled, so counting stays at one per call.
|
|
2188
|
+
if (tool && tool.name) toolsUsed.push(tool.name);
|
|
2189
|
+
toolLog.push({
|
|
2190
|
+
name: (tool && tool.name) || null,
|
|
2191
|
+
id: (tool && tool.id) || null,
|
|
2192
|
+
args: briefArgs(tool && tool.args),
|
|
2193
|
+
settled: true,
|
|
2194
|
+
ok: tool.ok !== false,
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
} else {
|
|
2198
|
+
if (tool && tool.name) toolsUsed.push(tool.name);
|
|
2199
|
+
toolLog.push({
|
|
2200
|
+
name: (tool && tool.name) || null,
|
|
2201
|
+
id: (tool && tool.id) || null,
|
|
2202
|
+
// The same brief rendering a reader gets on stderr, so an
|
|
2203
|
+
// archived run can say WHAT the calls were rather than only how
|
|
2204
|
+
// many. `--json` used to publish the count and no evidence:
|
|
2205
|
+
// a 14-entry `tools` array was all a benchmark row could see.
|
|
2206
|
+
args: briefArgs(tool && tool.args),
|
|
2207
|
+
settled: false,
|
|
2208
|
+
ok: null,
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2146
2211
|
const diff = tool && tool.preview !== undefined ? tool.preview : null;
|
|
2147
2212
|
const lines = render.renderTurn(
|
|
2148
2213
|
ctx(),
|
|
@@ -2165,6 +2230,20 @@ function createApp(options = {}) {
|
|
|
2165
2230
|
{
|
|
2166
2231
|
text: res.text,
|
|
2167
2232
|
model: res.model,
|
|
2233
|
+
// The route this turn actually took, so a run can PROVE its class
|
|
2234
|
+
// instead of asserting it in prose. The benchmark spent two sweeps
|
|
2235
|
+
// comparing a pooled-relay CLI turn against a BYOK-direct desktop
|
|
2236
|
+
// turn while both rows claimed `deepseek-flash`; the 3.5× cost gap
|
|
2237
|
+
// was the transport, and nothing in the document said so. `--json`
|
|
2238
|
+
// is the only machine-readable surface this CLI has.
|
|
2239
|
+
class: commandCtx.modelClass,
|
|
2240
|
+
// The engine stamps `calls` onto this accumulator (one per provider
|
|
2241
|
+
// dispatch), so it is the turn's real round-trip count. Republished
|
|
2242
|
+
// under the name every benchmark adapter already looks for:
|
|
2243
|
+
// `harness-bench.mjs` read `e.rounds` and, finding nothing, fell
|
|
2244
|
+
// back to `1`, so every archived AEGIS row claimed a single round
|
|
2245
|
+
// for turns that made dozens.
|
|
2246
|
+
rounds: (res.usage && Number(res.usage.calls)) || null,
|
|
2168
2247
|
usage: res.usage,
|
|
2169
2248
|
tokens,
|
|
2170
2249
|
ms: res.ms,
|
|
@@ -2173,6 +2252,12 @@ function createApp(options = {}) {
|
|
|
2173
2252
|
// tell "answered from memory" from "did work" without inferring it
|
|
2174
2253
|
// from a token count.
|
|
2175
2254
|
...(toolsUsed.length ? { tools: toolsUsed } : {}),
|
|
2255
|
+
// The evidence beside the count: name + a one-line arg summary per
|
|
2256
|
+
// call, with the outcome written back from the matching done frame.
|
|
2257
|
+
// `tools` above is kept unchanged because five archived runs and a
|
|
2258
|
+
// test read it, and it is the field that says HOW MANY rounds
|
|
2259
|
+
// touched a tool; this one says which.
|
|
2260
|
+
...(toolLog.length ? { tool_log: toolLog } : {}),
|
|
2176
2261
|
// Present only when the reply was a provider refusal. A caller that
|
|
2177
2262
|
// gates on `error` can now tell a dead turn from a working one;
|
|
2178
2263
|
// before this field existed both were `{text, tokens: 0}` with
|
|
@@ -2593,6 +2678,22 @@ function createApp(options = {}) {
|
|
|
2593
2678
|
// it has been turned off, or where this install never opted in. Such a
|
|
2594
2679
|
// stored value falls back to the live default rather than being trusted.
|
|
2595
2680
|
if (selectableClasses().includes(cfg.modelClass)) commandCtx.modelClass = cfg.modelClass;
|
|
2681
|
+
// A `--class` flag outranks the stored pin, the same way `--model` outranks
|
|
2682
|
+
// `cfg.model` on the next line. Clamped to the OFFERED set for the reason
|
|
2683
|
+
// the restore above is: a class this host cannot run (or `pro` on an install
|
|
2684
|
+
// that never opted in) must not be honoured just because it was typed.
|
|
2685
|
+
// An unknown or unoffered value is refused rather than silently downgraded
|
|
2686
|
+
// to the pooled route — a headless turn that asked for byok and got billed
|
|
2687
|
+
// to the pool is the exact defect this flag exists to fix.
|
|
2688
|
+
if (opts.class) {
|
|
2689
|
+
const want = String(opts.class).trim().toLowerCase();
|
|
2690
|
+
if (!selectableClasses().includes(want)) {
|
|
2691
|
+
throw new Error(
|
|
2692
|
+
`--class ${opts.class}: not available on this host (offered: ${selectableClasses().join(', ')})`
|
|
2693
|
+
);
|
|
2694
|
+
}
|
|
2695
|
+
commandCtx.modelClass = want;
|
|
2696
|
+
}
|
|
2596
2697
|
if (!opts.model && cfg.model) commandCtx.model = cfg.model;
|
|
2597
2698
|
// Restored through effortRung(), so a config written by an older build is
|
|
2598
2699
|
// never a value this one does not send: `null`, `''` and the retired
|
package/src/commands.js
CHANGED
|
@@ -102,7 +102,9 @@ const { openUrl, URLS } = require('./system.js');
|
|
|
102
102
|
// they exist and why they never mutate anything.
|
|
103
103
|
const sysdiag = require('./sysdiag.js');
|
|
104
104
|
const { sniffProject, buildAegisMd } = require('./init.js');
|
|
105
|
-
const {
|
|
105
|
+
const {
|
|
106
|
+
upgradeAdvice, latestPublishedVersion, applyUpgrade, installMethod,
|
|
107
|
+
} = require('./update.js');
|
|
106
108
|
const {
|
|
107
109
|
AGENT_PRESETS, agentRoles, composeAgentPrompt, composeResearchPrompt, composeDebatePrompt,
|
|
108
110
|
} = require('./agents.js');
|
|
@@ -1986,9 +1988,19 @@ const COMMANDS = [
|
|
|
1986
1988
|
},
|
|
1987
1989
|
},
|
|
1988
1990
|
{
|
|
1989
|
-
name: 'upgrade', args: ['action'], hint: '[check]', category: 'support',
|
|
1990
|
-
desc: 'Check for a newer published version',
|
|
1991
|
-
handler: async (c) => {
|
|
1991
|
+
name: 'upgrade', args: ['action'], hint: '[check|apply]', category: 'support',
|
|
1992
|
+
desc: 'Check for a newer published version (apply: install it now)',
|
|
1993
|
+
handler: async (c, args) => {
|
|
1994
|
+
const action = String((args && args.action) || 'check').toLowerCase();
|
|
1995
|
+
if (!['check', 'apply'].includes(action)) {
|
|
1996
|
+
note(c, 'Usage: /upgrade [check|apply]');
|
|
1997
|
+
c.render();
|
|
1998
|
+
return true;
|
|
1999
|
+
}
|
|
2000
|
+
// The channel is what THIS process was installed from — npm, pip, npx or
|
|
2001
|
+
// a git checkout — so /upgrade never tells a pip install to run npm and
|
|
2002
|
+
// then report success for a second copy that nothing is running from.
|
|
2003
|
+
const method = installMethod();
|
|
1992
2004
|
note(c, 'Checking the npm registry…');
|
|
1993
2005
|
c.render();
|
|
1994
2006
|
// The registry lookup is a blocking `npm view`, so it runs inside the
|
|
@@ -1996,7 +2008,35 @@ const COMMANDS = [
|
|
|
1996
2008
|
// mode, where a network answer would be a lie).
|
|
1997
2009
|
const run = c && c.withWorking ? (fn) => c.withWorking(fn) : (fn) => fn();
|
|
1998
2010
|
const latest = c.ctx && c.ctx.demo ? null : await run(() => Promise.resolve(latestPublishedVersion()));
|
|
1999
|
-
|
|
2011
|
+
const advice = upgradeAdvice({ latest, method });
|
|
2012
|
+
panel(c, upgradePanelLines(advice.lines));
|
|
2013
|
+
c.render();
|
|
2014
|
+
if (action !== 'apply') return true;
|
|
2015
|
+
|
|
2016
|
+
// Applying is opt-in and never inferred: it replaces the binaries under
|
|
2017
|
+
// a running process, which is a different promise from "a release
|
|
2018
|
+
// exists". A channel with nothing to install says so instead of running
|
|
2019
|
+
// a command that would be a no-op.
|
|
2020
|
+
if (!advice.plan || !advice.plan.apply) {
|
|
2021
|
+
note(c, advice.plan ? `Nothing to install: ${advice.plan.instruction}` : 'Nothing to install.');
|
|
2022
|
+
c.render();
|
|
2023
|
+
return true;
|
|
2024
|
+
}
|
|
2025
|
+
note(c, `Running: ${advice.plan.instruction}`);
|
|
2026
|
+
c.render();
|
|
2027
|
+
const res = applyUpgrade({ method, latest, current: advice.plan.current });
|
|
2028
|
+
if (res.ok && !res.skipped) {
|
|
2029
|
+
// A global install does not touch the process already running, so the
|
|
2030
|
+
// honest last line is "installed, restart to use it" — not "upgraded",
|
|
2031
|
+
// which would claim this session is now on the new version.
|
|
2032
|
+
note(c, `Installed ${advice.plan.latest}. Restart aegiscode to use it.`);
|
|
2033
|
+
if (res.output) for (const line of res.output.split('\n').slice(-6)) note(c, ` ${line}`);
|
|
2034
|
+
} else if (res.skipped) {
|
|
2035
|
+
note(c, `Not applied: ${res.instruction}`);
|
|
2036
|
+
} else {
|
|
2037
|
+
note(c, `Upgrade failed: ${res.error}`);
|
|
2038
|
+
note(c, `Run it yourself: ${res.command}`);
|
|
2039
|
+
}
|
|
2000
2040
|
c.render();
|
|
2001
2041
|
return true;
|
|
2002
2042
|
},
|
package/src/limits.js
CHANGED
|
@@ -101,7 +101,7 @@ const UNITS = Object.freeze([
|
|
|
101
101
|
* The masked digest of the sealed set. Rewritten ONLY by
|
|
102
102
|
* `node tools/provenance.mjs seal --write`, never by hand.
|
|
103
103
|
*/
|
|
104
|
-
const SEALED = '
|
|
104
|
+
const SEALED = '5125d89e9e3488b276cecb70e0107daa55c1c96424641b985fc7321c63518884';
|
|
105
105
|
|
|
106
106
|
/** Subcommands that a build failing this check does not get to run. */
|
|
107
107
|
const PRIVILEGED = Object.freeze(['gate', 'provenance', 'mcp']);
|
package/src/provenance.lock.json
CHANGED
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"license": "AGPL-3.0-or-later",
|
|
25
25
|
"source": "https://github.com/aegisinfo/aegiscode-plugin",
|
|
26
26
|
"units": {
|
|
27
|
-
"p1": "
|
|
27
|
+
"p1": "14c0d9bed6de48582c23fecf7ab8b3126fc828554c383359317fcf7ee18a3f64",
|
|
28
28
|
"p2": "d63d147de5455eea111d000b748d7eef9572a11a08d31f2471d5ff146701342c",
|
|
29
29
|
"p3": "ff962ac8dbf42cecb2477e2f77bf5ec61f88aa1751b0d4e506bf030fbc5fc6c6",
|
|
30
30
|
"p4": "2e8385c3a653a2af324050b4b92aeb9d142fc6765c91a13ccc928c5d4a2dbedb",
|
|
31
31
|
"p5": "408d67f78f31f6d637a26d2852e0c809a260544e613afdc64b731401c0ba3801",
|
|
32
32
|
"p6": "22bcd0b5dc1afad8d870652fbf1fd25bd0a547be9d8700161449cafa35bab6eb",
|
|
33
|
-
"p7": "
|
|
33
|
+
"p7": "81f2819d246a73c93307885cf09d8b7843e1dc1ce2bd6b4632869c00613422f6",
|
|
34
34
|
"p8": "3cc054d06715e065fe635b37b7d1bb98bf7989d64453a572ddbb77cec5b830e7"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/update.js
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* checker. Resolved through deps.js so the in-repo and published-vendor
|
|
14
14
|
* layouts both work.
|
|
15
15
|
*
|
|
16
|
-
* On top of the shared checker this module carries the
|
|
17
|
-
*
|
|
18
|
-
* ported from the upstream engine reference. They belong
|
|
16
|
+
* On top of the shared checker this module carries the pieces /upgrade needs —
|
|
17
|
+
* `compareVersions`, `upgradeAdvice`, `latestPublishedVersion` and
|
|
18
|
+
* `installMethod` — ported from the upstream engine reference. They belong
|
|
19
19
|
* here, next to `isNewer`/`updateLine`, so the CLI has ONE idea of "is there a
|
|
20
20
|
* newer published version": the welcome-box notice and /upgrade now answer
|
|
21
21
|
* from the same place and compare versions the same way. The shared module's
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
* code, not a copy).
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
+
const path = require('node:path');
|
|
28
|
+
const fs = require('node:fs');
|
|
27
29
|
const { execFileSync } = require('node:child_process');
|
|
28
30
|
|
|
29
31
|
const { resolveShared } = require('./deps.js');
|
|
@@ -34,6 +36,35 @@ const VERSION = require('../package.json').version;
|
|
|
34
36
|
/** Both hosts publish from npm; the CLI is `aegiscode`. */
|
|
35
37
|
const PKG = shared.PKG || 'aegiscode';
|
|
36
38
|
|
|
39
|
+
/**
|
|
40
|
+
* How THIS copy was installed: 'npm' | 'pip' | 'npx' | 'source'.
|
|
41
|
+
*
|
|
42
|
+
* Lazy on purpose — `detectInstallMethod` probes the filesystem, and the four
|
|
43
|
+
* call sites that only want a version string should not pay for it. Memoised
|
|
44
|
+
* because the answer cannot change while the process runs.
|
|
45
|
+
*/
|
|
46
|
+
let methodCache = null;
|
|
47
|
+
function installMethod() {
|
|
48
|
+
if (methodCache) return methodCache;
|
|
49
|
+
const detect = shared.detectInstallMethod;
|
|
50
|
+
if (typeof detect !== 'function') { methodCache = 'npm'; return methodCache; }
|
|
51
|
+
try {
|
|
52
|
+
methodCache = detect({
|
|
53
|
+
env: process.env,
|
|
54
|
+
argv: process.argv,
|
|
55
|
+
pkg: PKG,
|
|
56
|
+
// The directory the running file lives in, and the package root above it
|
|
57
|
+
// (`cli/src` → `cli/`), which is what tells a checkout from a global
|
|
58
|
+
// install: `.git` exists in the repo, and in no published package.
|
|
59
|
+
entry: path.resolve(__dirname, '..'),
|
|
60
|
+
fileExists: (rel) => fs.existsSync(path.resolve(__dirname, '..', '..', rel)),
|
|
61
|
+
});
|
|
62
|
+
} catch {
|
|
63
|
+
methodCache = 'npm';
|
|
64
|
+
}
|
|
65
|
+
return methodCache;
|
|
66
|
+
}
|
|
67
|
+
|
|
37
68
|
// ── /upgrade ─────────────────────────────────────────────────────────────────
|
|
38
69
|
|
|
39
70
|
/** Compare two dotted version strings: -1 | 0 | 1 (prerelease tags ignored). */
|
|
@@ -48,7 +79,7 @@ function compareVersions(a, b) {
|
|
|
48
79
|
}
|
|
49
80
|
|
|
50
81
|
/** What /upgrade should say, given the local and published versions. */
|
|
51
|
-
function upgradeAdvice({ current = VERSION, latest = null, packageName = PKG } = {}) {
|
|
82
|
+
function upgradeAdvice({ current = VERSION, latest = null, packageName = PKG, method = 'npm' } = {}) {
|
|
52
83
|
if (!latest) {
|
|
53
84
|
return {
|
|
54
85
|
upToDate: null,
|
|
@@ -57,14 +88,22 @@ function upgradeAdvice({ current = VERSION, latest = null, packageName = PKG } =
|
|
|
57
88
|
}
|
|
58
89
|
const cmp = compareVersions(latest, current);
|
|
59
90
|
if (cmp > 0) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
91
|
+
// The command comes from the shared verdict, so /upgrade, the welcome box
|
|
92
|
+
// and the window's banner can never name three different installers — and
|
|
93
|
+
// so a pip install is not told to run npm (which would write a second copy
|
|
94
|
+
// beside the one it actually runs, and look like a no-op).
|
|
95
|
+
const plan = typeof shared.updatePlan === 'function'
|
|
96
|
+
? shared.updatePlan({ current, latest, behind: true, channel: 'npm', pkg: packageName, method })
|
|
97
|
+
: null;
|
|
98
|
+
const instruction = (plan && plan.instruction) || `npm i -g ${packageName}@latest`;
|
|
99
|
+
const lines = [
|
|
100
|
+
` Installed: ${current}`,
|
|
101
|
+
` Published: ${latest}`,
|
|
102
|
+
` Channel: ${method}`,
|
|
103
|
+
` Upgrade: ${instruction}`,
|
|
104
|
+
];
|
|
105
|
+
if (plan && plan.apply) lines.push(' (or run `/upgrade apply` to do it here)');
|
|
106
|
+
return { upToDate: false, lines, plan };
|
|
68
107
|
}
|
|
69
108
|
return {
|
|
70
109
|
upToDate: true,
|
|
@@ -72,6 +111,56 @@ function upgradeAdvice({ current = VERSION, latest = null, packageName = PKG } =
|
|
|
72
111
|
};
|
|
73
112
|
}
|
|
74
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Actually run the upgrade, when the channel has a command to run.
|
|
116
|
+
*
|
|
117
|
+
* `/upgrade` used to print a command and stop there, which put the whole update
|
|
118
|
+
* behind "copy a shell line correctly" — and the window's banner had a button
|
|
119
|
+
* for the same thing. `apply: false` stays available because a source checkout
|
|
120
|
+
* and an npx run both have nothing for us to install.
|
|
121
|
+
*
|
|
122
|
+
* Never throws: a failing installer is a result, because a half-upgraded global
|
|
123
|
+
* package is exactly when a user needs to read the output rather than lose it
|
|
124
|
+
* to a traceback.
|
|
125
|
+
*
|
|
126
|
+
* @returns {{ok: boolean, skipped?: boolean, channel: string, command: ?string,
|
|
127
|
+
* output?: string, error?: string, instruction?: string}}
|
|
128
|
+
*/
|
|
129
|
+
function applyUpgrade({ current = VERSION, packageName = PKG, method = 'npm', latest = null } = {}) {
|
|
130
|
+
const plan = typeof shared.updatePlan === 'function' && latest
|
|
131
|
+
? shared.updatePlan({ current, latest, behind: true, channel: 'npm', pkg: packageName, method })
|
|
132
|
+
: null;
|
|
133
|
+
const target = plan && plan.apply ? plan.apply : null;
|
|
134
|
+
if (!target) {
|
|
135
|
+
const instruction = (plan && plan.instruction) || (method === 'npm'
|
|
136
|
+
? `npm i -g ${packageName}@latest`
|
|
137
|
+
: 'restart to pick up the new version');
|
|
138
|
+
// Two different reasons to skip, and they are not interchangeable: a source
|
|
139
|
+
// checkout is the user's to pull, an npx run is already current by design.
|
|
140
|
+
return { ok: true, skipped: true, channel: method, command: null, instruction };
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const out = execFileSync(target.command, target.args, {
|
|
144
|
+
encoding: 'utf8',
|
|
145
|
+
timeout: 180_000,
|
|
146
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
ok: true,
|
|
150
|
+
channel: method,
|
|
151
|
+
command: `${target.command} ${target.args.join(' ')}`,
|
|
152
|
+
output: String(out || '').trim(),
|
|
153
|
+
};
|
|
154
|
+
} catch (err) {
|
|
155
|
+
return {
|
|
156
|
+
ok: false,
|
|
157
|
+
channel: method,
|
|
158
|
+
command: `${target.command} ${target.args.join(' ')}`,
|
|
159
|
+
error: String((err && (err.stderr || err.message)) || err).trim(),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
75
164
|
/** Best-effort registry lookup (5s cap). Returns a version string or null. */
|
|
76
165
|
function latestPublishedVersion({ packageName = PKG, timeoutMs = 5000 } = {}) {
|
|
77
166
|
try {
|
|
@@ -88,5 +177,7 @@ module.exports = {
|
|
|
88
177
|
VERSION,
|
|
89
178
|
compareVersions,
|
|
90
179
|
upgradeAdvice,
|
|
180
|
+
applyUpgrade,
|
|
181
|
+
installMethod,
|
|
91
182
|
latestPublishedVersion,
|
|
92
183
|
};
|