aegiscode 7.0.14 → 7.0.16
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/SOURCE-OFFER.txt +9 -0
- package/package.json +4 -7
- package/scripts/check.mjs +1 -52
- package/scripts/demo.mjs +1 -94
- package/scripts/predist.mjs +1 -75
- package/scripts/runtests.mjs +1 -56
- package/scripts/seal-gate.mjs +1 -74
- package/src/agents.js +1 -139
- package/src/app.js +1 -2932
- package/src/art.js +1 -289
- package/src/chatflow.js +1 -3020
- package/src/checkpoint.js +1 -90
- package/src/clipboard.js +1 -424
- package/src/cloudsync.js +1 -528
- package/src/commands.js +1 -4003
- package/src/config.js +1 -581
- package/src/connect.js +1 -349
- package/src/credentials.js +1 -33
- package/src/deps.js +1 -232
- package/src/devrun.js +1 -187
- package/src/diff.js +1 -333
- package/src/diffview.js +1 -296
- package/src/engine.js +1 -297
- package/src/entitlement.js +1 -355
- package/src/events.js +1 -707
- package/src/export.js +1 -67
- package/src/fingerprint.js +1 -592
- package/src/format.js +1 -259
- package/src/fuzzy.js +1 -119
- package/src/history.js +1 -401
- package/src/init.js +1 -175
- package/src/input.js +1 -139
- package/src/keys.js +1 -183
- package/src/markdown.js +1 -306
- package/src/models.js +1 -487
- package/src/naming.js +1 -229
- package/src/overlays.js +1 -461
- package/src/panels.js +1 -1418
- package/src/ping.js +1 -226
- package/src/presence.js +1 -238
- package/src/render.js +1 -515
- package/src/screen.js +1 -518
- package/src/screens.js +1 -896
- package/src/secret.js +1 -59
- package/src/securefs.js +1 -359
- package/src/settings.js +1 -155
- package/src/shared.js +1 -52
- package/src/sharedpaths.js +1 -53
- package/src/signup.js +1 -156
- package/src/summarize.js +1 -95
- package/src/sysdiag.js +1 -585
- package/src/system.js +1 -40
- package/src/theme.js +1 -570
- package/src/title.js +1 -220
- package/src/todos.js +1 -115
- package/src/tokens.js +1 -263
- package/src/topup.js +1 -210
- package/src/update.js +1 -181
- package/vendor/client/aegis.js +1 -2179
- package/vendor/client/attest.js +1 -442
- package/vendor/client/authorship-key.js +1 -410
- package/vendor/client/auto-provision.js +1 -134
- package/vendor/client/brain-catalog.js +1 -268
- package/vendor/client/byok-catalog.js +1 -230
- package/vendor/client/credentials.js +1 -494
- package/vendor/client/device-fingerprint.js +1 -141
- package/vendor/client/drive-connect.js +1 -110
- package/vendor/client/drive-upload.js +1 -174
- package/vendor/client/env-file.js +1 -1273
- package/vendor/client/fingerprint.js +1 -1064
- package/vendor/client/foreign-memory.js +1 -669
- package/vendor/client/google-signin.js +1 -133
- package/vendor/client/hooks.js +1 -430
- package/vendor/client/model-discovery.js +1 -373
- package/vendor/client/platform.js +1 -937
- package/vendor/client/prefs.js +1 -351
- package/vendor/client/presence-constants.js +1 -107
- package/vendor/client/presence.js +1 -438
- package/vendor/client/record-vault.js +3 -1055
- package/vendor/client/session-store.js +1 -548
- package/vendor/client/topup.js +1 -297
- package/vendor/client/touch.js +1 -458
- package/vendor/client/update.js +1 -704
- package/vendor/client/user-models.js +1 -381
- package/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/desktop/lib/local/claude-pro.js +1 -993
- package/vendor/desktop/lib/local/context.js +1 -95
- package/vendor/desktop/lib/local/engine.js +1 -3301
- package/vendor/desktop/lib/local/entitlement.js +1 -660
- package/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/desktop/lib/local/local.js +1 -2135
- package/vendor/desktop/lib/local/prompt.js +1 -275
- package/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/desktop/lib/local/session-rounds.js +1 -208
- package/vendor/desktop/lib/local/shell.js +1 -680
- package/vendor/desktop/lib/local/tools.js +1 -1238
- package/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/desktop/lib/settings.js +1 -890
- package/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/hosts/install.js +1 -638
- package/vendor/hosts/openai-shim.js +1 -515
- package/vendor/hosts/spec.js +1 -164
- package/vendor/hosts/targets.js +1 -346
- package/vendor/mcp/server.js +1 -221
- package/vendor/mcp/tools.js +1 -408
- package/vendor/one/src/child.js +1 -285
- package/vendor/one/src/permissions.js +1 -369
package/src/topup.js
CHANGED
|
@@ -1,212 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
4
|
-
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
-
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* topup.js — `aegiscode topup [EUR]`: the terminal's own top-up.
|
|
10
|
-
*
|
|
11
|
-
* WHY THE TERMINAL NEEDS THIS AT ALL. `/billing` prints a link (`/go/topup`) and
|
|
12
|
-
* that was the whole funding affordance: the CLI could not start a checkout.
|
|
13
|
-
* The link is real but it lands on `/topup`, which is `@login_required` against
|
|
14
|
-
* a browser SESSION — and the account this product auto-provisions is created by
|
|
15
|
-
* `POST /api/v1/auth/register-device`, with a password that is never returned
|
|
16
|
-
* and an email at `@device.aegiscloud`. So the user who most needs to fund a
|
|
17
|
-
* free account is the one who cannot sign in to the page that funds it: they pay
|
|
18
|
-
* the link a visit, hit a login wall, and conclude it failed while the money is
|
|
19
|
-
* real.
|
|
20
|
-
*
|
|
21
|
-
* What makes this work is that the credential which CREATES the checkout can
|
|
22
|
-
* also READ the result: `POST /api/token-bank/topup` and `GET
|
|
23
|
-
* /api/token-bank/balance` are both `login_required`, which accepts
|
|
24
|
-
* `X-API-Key`/Bearer. So this command starts the session, opens the hosted page
|
|
25
|
-
* for the actual card entry, and then confirms the credit itself from the
|
|
26
|
-
* balance endpoint — the same confirmation the desktop does, over the same state
|
|
27
|
-
* machine (`client/topup.js`, `createCreditWatch`), so the terminal and the GUI
|
|
28
|
-
* cannot disagree about whether the money arrived.
|
|
29
|
-
*
|
|
30
|
-
* It BLOCKS on purpose. The desktop's watch is an unref'd interval because the
|
|
31
|
-
* window stays open for hours; here the process exits, so a detached timer would
|
|
32
|
-
* be killed before the webhook fires. A loop is the honest scheduler for a
|
|
33
|
-
* one-shot command, and it is why the shared module owns the state machine and
|
|
34
|
-
* not the timer.
|
|
35
|
-
*
|
|
36
|
-
* Exit codes (a script can gate on them): 0 credited, 1 checkout opened but no
|
|
37
|
-
* credit observed in the window, 2 usage / no usable credential / the server
|
|
38
|
-
* refused the checkout.
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
const { resolveShared } = require('./sharedpaths.js');
|
|
42
|
-
const { openUrl: defaultOpenUrl } = require('./system.js');
|
|
43
|
-
const credentials = require('./credentials.js');
|
|
44
|
-
|
|
45
|
-
/** Resolve a shared module by existence (repo checkout or the staged tree). */
|
|
46
|
-
function loadShared(rel) {
|
|
47
|
-
return require(resolveShared(rel));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** The same thin client the session and the entitlement gate use. */
|
|
51
|
-
function createCliClient() {
|
|
52
|
-
const { createClient } = loadShared('client/aegis.js');
|
|
53
|
-
return createClient(credentials.clientOptions({ channel: 'cli' }));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* A key is needed to create a checkout at all, so a fresh machine gets the same
|
|
58
|
-
* free device key the session path asks for — one implementation, the shared
|
|
59
|
-
* auto-provision helper (client/auto-provision.js), and one attempt.
|
|
60
|
-
*
|
|
61
|
-
* Best-effort by design: if the helper is unreachable or the server declines,
|
|
62
|
-
* this returns false and the caller says so, rather than throwing a module error
|
|
63
|
-
* at a user who is trying to give us money.
|
|
64
|
-
*/
|
|
65
|
-
async function ensureKey(client, store) {
|
|
66
|
-
if (client.apiKey) return true;
|
|
67
|
-
try {
|
|
68
|
-
const mod = loadShared('client/auto-provision.js');
|
|
69
|
-
const provision = mod.autoProvisionApiKey || mod.default;
|
|
70
|
-
if (typeof provision === 'function') {
|
|
71
|
-
const res = await provision(client, store, { app: 'cli' });
|
|
72
|
-
if (res && res.key && typeof client.setApiKey === 'function') client.setApiKey(res.key);
|
|
73
|
-
}
|
|
74
|
-
} catch {
|
|
75
|
-
/* fall through: the caller reports the missing credential plainly */
|
|
76
|
-
}
|
|
77
|
-
return Boolean(client.apiKey);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Run the command and return a process exit code.
|
|
82
|
-
*
|
|
83
|
-
* @param {string|null} arg the typed amount (null ⇒ the server default, 10 EUR)
|
|
84
|
-
* @param {object} [io] injectable for tests: `stdout`, `stderr`, `client`,
|
|
85
|
-
* `openUrl`, `sleep`, `intervalMs`, `maxTries`, `json`, `onStep`.
|
|
86
|
-
*/
|
|
87
|
-
async function runTopupCommand(arg, io) {
|
|
88
|
-
const options = io || {};
|
|
89
|
-
const stdout = options.stdout || process.stdout;
|
|
90
|
-
const stderr = options.stderr || process.stderr;
|
|
91
|
-
// JSON mode is a script's stdout: one object (written by finish()) and no
|
|
92
|
-
// human chatter, so a parser never has to skip progress lines. Errors still
|
|
93
|
-
// go to stderr, which is not the stream being parsed.
|
|
94
|
-
const out = options.json ? () => {} : (s) => stdout.write(s);
|
|
95
|
-
let payload = null;
|
|
96
|
-
|
|
97
|
-
// JSON mode prints ONE object and nothing else, so a script parsing stdout
|
|
98
|
-
// does not have to skip progress chatter.
|
|
99
|
-
const finish = (code, result) => {
|
|
100
|
-
if (options.json) stdout.write(JSON.stringify(result) + '\n');
|
|
101
|
-
return code;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
let shared;
|
|
105
|
-
try {
|
|
106
|
-
shared = loadShared('client/topup.js');
|
|
107
|
-
} catch (error) {
|
|
108
|
-
stderr.write(`aegiscode: the shared top-up module is missing — ${(error && error.message) || error}\n`);
|
|
109
|
-
return 2;
|
|
110
|
-
}
|
|
111
|
-
const {
|
|
112
|
-
parseTopupAmount,
|
|
113
|
-
startTopup,
|
|
114
|
-
createCreditWatch,
|
|
115
|
-
TOPUP_POLL_MS,
|
|
116
|
-
TOPUP_POLL_TRIES,
|
|
117
|
-
TOPUP_MIN_EUR,
|
|
118
|
-
TOPUP_MAX_EUR,
|
|
119
|
-
} = shared;
|
|
120
|
-
|
|
121
|
-
const parsed = parseTopupAmount(arg);
|
|
122
|
-
if (!parsed.ok) {
|
|
123
|
-
stderr.write(
|
|
124
|
-
`aegiscode: ${parsed.message}\n` +
|
|
125
|
-
` usage: aegiscode topup [${TOPUP_MIN_EUR}..${TOPUP_MAX_EUR}] (default 10)\n`
|
|
126
|
-
);
|
|
127
|
-
// JSON mode still emits its ONE object here: a script that checks the exit
|
|
128
|
-
// code must not be the only way to learn why — "no stdout at all" reads as
|
|
129
|
-
// a crash, not as a rejected amount.
|
|
130
|
-
return finish(2, { ok: false, credited: false, amount_eur: null, url: null, balance_eur: null, error: parsed.message });
|
|
131
|
-
}
|
|
132
|
-
payload = { ok: false, credited: false, amount_eur: parsed.amount, url: null, balance_eur: null };
|
|
133
|
-
|
|
134
|
-
// Say something BEFORE the first network call. The transport's ceiling is 60s
|
|
135
|
-
// per request and this path can make two (auto-provision, then the checkout),
|
|
136
|
-
// so an unreachable server used to mean two silent minutes and then a line —
|
|
137
|
-
// which a user reads as a hung command, not as a network problem. stderr, not
|
|
138
|
-
// stdout: in --json mode stdout is a script's parse target.
|
|
139
|
-
stderr.write(`aegiscode: requesting a ${parsed.amount} EUR top-up from the account service…\n`);
|
|
140
|
-
|
|
141
|
-
const client = options.client || createCliClient();
|
|
142
|
-
if (!client.apiKey && !(await ensureKey(client, credentials))) {
|
|
143
|
-
stderr.write(
|
|
144
|
-
'aegiscode: no AEGIS key on this machine and none could be provisioned —\n' +
|
|
145
|
-
' `aegiscode login <api_key>` (from https://aegiscloud.org/dashboard) first\n'
|
|
146
|
-
);
|
|
147
|
-
payload.error = 'no usable AEGIS key';
|
|
148
|
-
return finish(2, payload);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const started = await startTopup(client, parsed.amount);
|
|
152
|
-
if (!started.ok) {
|
|
153
|
-
stderr.write(`aegiscode: the top-up could not be started — ${started.message}\n`);
|
|
154
|
-
if (started.hint) stderr.write(`aegiscode: ${started.hint}\n`);
|
|
155
|
-
payload.error = started.message;
|
|
156
|
-
payload.status = started.status;
|
|
157
|
-
return finish(2, payload);
|
|
158
|
-
}
|
|
159
|
-
payload.url = started.url;
|
|
160
|
-
|
|
161
|
-
const open = options.openUrl || defaultOpenUrl;
|
|
162
|
-
const sleep = options.sleep || ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
163
|
-
const intervalMs = options.intervalMs == null ? TOPUP_POLL_MS : options.intervalMs;
|
|
164
|
-
const maxTries = options.maxTries == null ? TOPUP_POLL_TRIES : options.maxTries;
|
|
165
|
-
const windowSeconds = Math.max(1, Math.round((intervalMs * maxTries) / 1000));
|
|
166
|
-
|
|
167
|
-
// `openUrl` returns false when the platform opener is missing (a container, a
|
|
168
|
-
// server over ssh); the URL is then the ONLY way to pay, so it is printed
|
|
169
|
-
// rather than swallowed — a command that silently does nothing is worse than
|
|
170
|
-
// one that says "paste this".
|
|
171
|
-
if (open(started.url)) {
|
|
172
|
-
out(`aegiscode: opening the payment page in your browser — ${started.amount} EUR\n`);
|
|
173
|
-
} else {
|
|
174
|
-
out(`aegiscode: open this to pay ${started.amount} EUR:\n ${started.url}\n`);
|
|
175
|
-
}
|
|
176
|
-
out(`aegiscode: watching this account's bank for up to ${windowSeconds}s to confirm the credit\n`);
|
|
177
|
-
|
|
178
|
-
const watch = createCreditWatch(client, { maxTries });
|
|
179
|
-
let announcedBaseline = false;
|
|
180
|
-
for (;;) {
|
|
181
|
-
const step = await watch.tick();
|
|
182
|
-
if (typeof options.onStep === 'function') options.onStep(step);
|
|
183
|
-
if (step.state === 'credited') {
|
|
184
|
-
payload.ok = true;
|
|
185
|
-
payload.credited = true;
|
|
186
|
-
payload.balance_eur = step.amount;
|
|
187
|
-
out(
|
|
188
|
-
`aegiscode: credit confirmed — the bank is now ${step.amount.toFixed(2)} EUR\n` +
|
|
189
|
-
'aegiscode: (this account was created by this machine, so the browser there has no\n' +
|
|
190
|
-
' session for it — the confirmation comes from the API, not the page)\n'
|
|
191
|
-
);
|
|
192
|
-
return finish(0, payload);
|
|
193
|
-
}
|
|
194
|
-
if (step.state === 'expired') {
|
|
195
|
-
// Honest about what is and is not known: the window closed on OUR watch,
|
|
196
|
-
// which is not the same claim as "you were not charged".
|
|
197
|
-
out(
|
|
198
|
-
`aegiscode: no credit observed within ${windowSeconds}s — if you completed the payment it\n` +
|
|
199
|
-
'aegiscode: may still land; re-run `aegiscode topup` or check `/billing` in a session\n'
|
|
200
|
-
);
|
|
201
|
-
payload.error = 'no credit observed within the watch window';
|
|
202
|
-
return finish(1, payload);
|
|
203
|
-
}
|
|
204
|
-
if (step.baseline != null && !announcedBaseline && !options.json) {
|
|
205
|
-
announcedBaseline = true;
|
|
206
|
-
out(`aegiscode: bank before the payment: ${step.baseline.toFixed(2)} EUR\n`);
|
|
207
|
-
}
|
|
208
|
-
await sleep(intervalMs);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
module.exports = { runTopupCommand, ensureKey, createCliClient };
|
|
3
|
+
"use strict";const{resolveShared:resolveShared}=require("./sharedpaths.js"),{openUrl:defaultOpenUrl}=require("./system.js"),credentials=require("./credentials.js");function loadShared(e){return require(resolveShared(e))}function createCliClient(){const{createClient:e}=loadShared("client/aegis.js");return e(credentials.clientOptions({channel:"cli"}))}async function ensureKey(e,t){if(e.apiKey)return!0;try{const n=loadShared("client/auto-provision.js"),o=n.autoProvisionApiKey||n.default;if("function"==typeof o){const n=await o(e,t,{app:"cli"});n&&n.key&&"function"==typeof e.setApiKey&&e.setApiKey(n.key)}}catch{}return Boolean(e.apiKey)}async function runTopupCommand(e,t){const n=t||{},o=n.stdout||process.stdout,r=n.stderr||process.stderr,i=n.json?()=>{}:e=>o.write(e);let a=null;const s=(e,t)=>(n.json&&o.write(JSON.stringify(t)+"\n"),e);let c;try{c=loadShared("client/topup.js")}catch(e){return r.write(`aegiscode: the shared top-up module is missing — ${e&&e.message||e}\n`),2}const{parseTopupAmount:u,startTopup:l,createCreditWatch:d,TOPUP_POLL_MS:p,TOPUP_POLL_TRIES:h,TOPUP_MIN_EUR:m,TOPUP_MAX_EUR:g}=c,f=u(e);if(!f.ok)return r.write(`aegiscode: ${f.message}\n usage: aegiscode topup [${m}..${g}] (default 10)\n`),s(2,{ok:!1,credited:!1,amount_eur:null,url:null,balance_eur:null,error:f.message});a={ok:!1,credited:!1,amount_eur:f.amount,url:null,balance_eur:null},r.write(`aegiscode: requesting a ${f.amount} EUR top-up from the account service…\n`);const y=n.client||createCliClient();if(!y.apiKey&&!await ensureKey(y,credentials))return r.write("aegiscode: no AEGIS key on this machine and none could be provisioned —\n `aegiscode login <api_key>` (from https://aegiscloud.org/dashboard) first\n"),a.error="no usable AEGIS key",s(2,a);const w=await l(y,f.amount);if(!w.ok)return r.write(`aegiscode: the top-up could not be started — ${w.message}\n`),w.hint&&r.write(`aegiscode: ${w.hint}\n`),a.error=w.message,a.status=w.status,s(2,a);a.url=w.url;const b=n.openUrl||defaultOpenUrl,k=n.sleep||(e=>new Promise((t=>setTimeout(t,e)))),U=null==n.intervalMs?p:n.intervalMs,S=null==n.maxTries?h:n.maxTries,T=Math.max(1,Math.round(U*S/1e3));b(w.url)?i(`aegiscode: opening the payment page in your browser — ${w.amount} EUR\n`):i(`aegiscode: open this to pay ${w.amount} EUR:\n ${w.url}\n`),i(`aegiscode: watching this account's bank for up to ${T}s to confirm the credit\n`);const $=d(y,{maxTries:S});let _=!1;for(;;){const e=await $.tick();if("function"==typeof n.onStep&&n.onStep(e),"credited"===e.state)return a.ok=!0,a.credited=!0,a.balance_eur=e.amount,i(`aegiscode: credit confirmed — the bank is now ${e.amount.toFixed(2)} EUR\naegiscode: (this account was created by this machine, so the browser there has no\n session for it — the confirmation comes from the API, not the page)\n`),s(0,a);if("expired"===e.state)return i(`aegiscode: no credit observed within ${T}s — if you completed the payment it\naegiscode: may still land; re-run \`aegiscode topup\` or check \`/billing\` in a session\n`),a.error="no credit observed within the watch window",s(1,a);null==e.baseline||_||n.json||(_=!0,i(`aegiscode: bank before the payment: ${e.baseline.toFixed(2)} EUR\n`)),await k(U)}}module.exports={runTopupCommand:runTopupCommand,ensureKey:ensureKey,createCliClient:createCliClient};
|
package/src/update.js
CHANGED
|
@@ -1,183 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
4
|
-
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
-
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The CLI's view of the shared npm update checker (client/update.js).
|
|
10
|
-
*
|
|
11
|
-
* It lives at the repo root rather than here because the desktop host needs
|
|
12
|
-
* the same thing for `aegis-desktop`: two hosts, two package names, one
|
|
13
|
-
* checker. Resolved through deps.js so the in-repo and published-vendor
|
|
14
|
-
* layouts both work.
|
|
15
|
-
*
|
|
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
|
-
* here, next to `isNewer`/`updateLine`, so the CLI has ONE idea of "is there a
|
|
20
|
-
* newer published version": the welcome-box notice and /upgrade now answer
|
|
21
|
-
* from the same place and compare versions the same way. The shared module's
|
|
22
|
-
* own functions are spread through unchanged, keeping the identity the
|
|
23
|
-
* update-channel test pins (the shim and the shared file must be the SAME
|
|
24
|
-
* code, not a copy).
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
const path = require('node:path');
|
|
28
|
-
const fs = require('node:fs');
|
|
29
|
-
const { execFileSync } = require('node:child_process');
|
|
30
|
-
|
|
31
|
-
const { resolveShared } = require('./deps.js');
|
|
32
|
-
|
|
33
|
-
const shared = require(resolveShared('client/update.js'));
|
|
34
|
-
|
|
35
|
-
const VERSION = require('../package.json').version;
|
|
36
|
-
/** Both hosts publish from npm; the CLI is `aegiscode`. */
|
|
37
|
-
const PKG = shared.PKG || 'aegiscode';
|
|
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
|
-
|
|
68
|
-
// ── /upgrade ─────────────────────────────────────────────────────────────────
|
|
69
|
-
|
|
70
|
-
/** Compare two dotted version strings: -1 | 0 | 1 (prerelease tags ignored). */
|
|
71
|
-
function compareVersions(a, b) {
|
|
72
|
-
const pa = String(a || '0').split('-')[0].split('.').map((n) => Number.parseInt(n, 10) || 0);
|
|
73
|
-
const pb = String(b || '0').split('-')[0].split('.').map((n) => Number.parseInt(n, 10) || 0);
|
|
74
|
-
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
75
|
-
const d = (pa[i] || 0) - (pb[i] || 0);
|
|
76
|
-
if (d) return d > 0 ? 1 : -1;
|
|
77
|
-
}
|
|
78
|
-
return 0;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** What /upgrade should say, given the local and published versions. */
|
|
82
|
-
function upgradeAdvice({ current = VERSION, latest = null, packageName = PKG, method = 'npm' } = {}) {
|
|
83
|
-
if (!latest) {
|
|
84
|
-
return {
|
|
85
|
-
upToDate: null,
|
|
86
|
-
lines: [` Could not read the npm registry — local version is ${current}.`],
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
const cmp = compareVersions(latest, current);
|
|
90
|
-
if (cmp > 0) {
|
|
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 };
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
upToDate: true,
|
|
110
|
-
lines: [` Installed ${current} is the published ${latest} — nothing to upgrade.`],
|
|
111
|
-
};
|
|
112
|
-
}
|
|
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
|
-
|
|
164
|
-
/** Best-effort registry lookup (5s cap). Returns a version string or null. */
|
|
165
|
-
function latestPublishedVersion({ packageName = PKG, timeoutMs = 5000 } = {}) {
|
|
166
|
-
try {
|
|
167
|
-
const out = execFileSync('npm', ['view', packageName, 'version'], {
|
|
168
|
-
encoding: 'utf8', timeout: timeoutMs, stdio: ['ignore', 'pipe', 'ignore'],
|
|
169
|
-
});
|
|
170
|
-
const v = String(out).trim();
|
|
171
|
-
return /^\d+\.\d+\.\d+/.test(v) ? v : null;
|
|
172
|
-
} catch { return null; }
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
module.exports = {
|
|
176
|
-
...shared,
|
|
177
|
-
VERSION,
|
|
178
|
-
compareVersions,
|
|
179
|
-
upgradeAdvice,
|
|
180
|
-
applyUpgrade,
|
|
181
|
-
installMethod,
|
|
182
|
-
latestPublishedVersion,
|
|
183
|
-
};
|
|
3
|
+
"use strict";const path=require("node:path"),fs=require("node:fs"),{execFileSync:execFileSync}=require("node:child_process"),{resolveShared:resolveShared}=require("./deps.js"),shared=require(resolveShared("client/update.js")),VERSION=require("../package.json").version,PKG=shared.PKG||"aegiscode";let methodCache=null;function installMethod(){if(methodCache)return methodCache;const e=shared.detectInstallMethod;if("function"!=typeof e)return methodCache="npm",methodCache;try{methodCache=e({env:process.env,argv:process.argv,pkg:PKG,entry:path.resolve(__dirname,".."),fileExists:e=>fs.existsSync(path.resolve(__dirname,"..","..",e))})}catch{methodCache="npm"}return methodCache}function compareVersions(e,n){const t=String(e||"0").split("-")[0].split(".").map((e=>Number.parseInt(e,10)||0)),r=String(n||"0").split("-")[0].split(".").map((e=>Number.parseInt(e,10)||0));for(let e=0;e<Math.max(t.length,r.length);e++){const n=(t[e]||0)-(r[e]||0);if(n)return n>0?1:-1}return 0}function upgradeAdvice({current:e=VERSION,latest:n=null,packageName:t=PKG,method:r="npm"}={}){if(!n)return{upToDate:null,lines:[` Could not read the npm registry — local version is ${e}.`]};if(compareVersions(n,e)>0){const a="function"==typeof shared.updatePlan?shared.updatePlan({current:e,latest:n,behind:!0,channel:"npm",pkg:t,method:r}):null,s=[` Installed: ${e}`,` Published: ${n}`,` Channel: ${r}`,` Upgrade: ${a&&a.instruction||`npm i -g ${t}@latest`}`];return a&&a.apply&&s.push(" (or run `/upgrade apply` to do it here)"),{upToDate:!1,lines:s,plan:a}}return{upToDate:!0,lines:[` Installed ${e} is the published ${n} — nothing to upgrade.`]}}function applyUpgrade({current:e=VERSION,packageName:n=PKG,method:t="npm",latest:r=null}={}){const a="function"==typeof shared.updatePlan&&r?shared.updatePlan({current:e,latest:r,behind:!0,channel:"npm",pkg:n,method:t}):null,s=a&&a.apply?a.apply:null;if(!s)return{ok:!0,skipped:!0,channel:t,command:null,instruction:a&&a.instruction||("npm"===t?`npm i -g ${n}@latest`:"restart to pick up the new version")};try{const e=("function"==typeof shared.installSpawn?shared.installSpawn(s,{env:process.env}):{command:s.command,args:s.args,shell:!1})||{command:s.command,args:s.args,shell:!1},n=execFileSync(e.command,e.args,{encoding:"utf8",timeout:18e4,stdio:["ignore","pipe","pipe"],shell:!0===e.shell,windowsHide:!0});return{ok:!0,channel:t,command:`${s.command} ${s.args.join(" ")}`,output:String(n||"").trim()}}catch(e){return{ok:!1,channel:t,command:`${s.command} ${s.args.join(" ")}`,error:String(e&&(e.stderr||e.message)||e).trim()}}}function latestPublishedVersion({packageName:e=PKG,timeoutMs:n=5e3}={}){try{const t=execFileSync("npm",["view",e,"version"],{encoding:"utf8",timeout:n,stdio:["ignore","pipe","ignore"]}),r=String(t).trim();return/^\d+\.\d+\.\d+/.test(r)?r:null}catch{return null}}module.exports={...shared,VERSION:VERSION,compareVersions:compareVersions,upgradeAdvice:upgradeAdvice,applyUpgrade:applyUpgrade,installMethod:installMethod,latestPublishedVersion:latestPublishedVersion};
|