aegisone 1.0.34 → 1.0.35

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.
Files changed (226) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -976
  9. package/src/child.js +1 -285
  10. package/src/dispatch.js +1 -269
  11. package/src/doctor.js +1 -639
  12. package/src/host.js +1 -111
  13. package/src/permissions.js +1 -383
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/package.json +3 -7
  17. package/vendor/cli/scripts/check.mjs +1 -52
  18. package/vendor/cli/scripts/demo.mjs +1 -94
  19. package/vendor/cli/scripts/predist.mjs +1 -75
  20. package/vendor/cli/scripts/runtests.mjs +1 -56
  21. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  22. package/vendor/cli/src/agents.js +1 -139
  23. package/vendor/cli/src/app.js +1 -2957
  24. package/vendor/cli/src/art.js +1 -289
  25. package/vendor/cli/src/chatflow.js +1 -3023
  26. package/vendor/cli/src/checkpoint.js +1 -90
  27. package/vendor/cli/src/clipboard.js +1 -424
  28. package/vendor/cli/src/cloudsync.js +1 -528
  29. package/vendor/cli/src/commands.js +1 -4089
  30. package/vendor/cli/src/config.js +1 -581
  31. package/vendor/cli/src/connect.js +1 -349
  32. package/vendor/cli/src/credentials.js +1 -33
  33. package/vendor/cli/src/deps.js +1 -232
  34. package/vendor/cli/src/devrun.js +1 -187
  35. package/vendor/cli/src/diff.js +1 -333
  36. package/vendor/cli/src/diffview.js +1 -296
  37. package/vendor/cli/src/engine.js +1 -297
  38. package/vendor/cli/src/entitlement.js +1 -355
  39. package/vendor/cli/src/events.js +1 -707
  40. package/vendor/cli/src/export.js +1 -67
  41. package/vendor/cli/src/filepreview.js +1 -153
  42. package/vendor/cli/src/fingerprint.js +1 -592
  43. package/vendor/cli/src/format.js +1 -259
  44. package/vendor/cli/src/fuzzy.js +1 -119
  45. package/vendor/cli/src/history.js +1 -423
  46. package/vendor/cli/src/init.js +1 -175
  47. package/vendor/cli/src/input.js +1 -139
  48. package/vendor/cli/src/keys.js +1 -183
  49. package/vendor/cli/src/markdown.js +1 -306
  50. package/vendor/cli/src/models.js +1 -507
  51. package/vendor/cli/src/naming.js +1 -57
  52. package/vendor/cli/src/overlays.js +1 -462
  53. package/vendor/cli/src/panels.js +1 -1418
  54. package/vendor/cli/src/ping.js +1 -226
  55. package/vendor/cli/src/presence.js +1 -238
  56. package/vendor/cli/src/render.js +1 -516
  57. package/vendor/cli/src/screen.js +1 -518
  58. package/vendor/cli/src/screens.js +1 -896
  59. package/vendor/cli/src/secret.js +1 -59
  60. package/vendor/cli/src/securefs.js +1 -359
  61. package/vendor/cli/src/settings.js +1 -155
  62. package/vendor/cli/src/shared.js +1 -52
  63. package/vendor/cli/src/sharedpaths.js +1 -53
  64. package/vendor/cli/src/signup.js +1 -156
  65. package/vendor/cli/src/summarize.js +1 -95
  66. package/vendor/cli/src/sysdiag.js +1 -585
  67. package/vendor/cli/src/system.js +1 -40
  68. package/vendor/cli/src/theme.js +1 -570
  69. package/vendor/cli/src/title.js +1 -220
  70. package/vendor/cli/src/todos.js +1 -115
  71. package/vendor/cli/src/tokens.js +1 -263
  72. package/vendor/cli/src/topup.js +1 -210
  73. package/vendor/cli/src/update.js +1 -191
  74. package/vendor/cli/vendor/client/aegis.js +1 -2441
  75. package/vendor/cli/vendor/client/attest.js +1 -518
  76. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  77. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  78. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  79. package/vendor/cli/vendor/client/byok-catalog.js +1 -199
  80. package/vendor/cli/vendor/client/catalog-client.js +1 -487
  81. package/vendor/cli/vendor/client/conversation-export.js +1 -177
  82. package/vendor/cli/vendor/client/credentials.js +1 -494
  83. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  84. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  85. package/vendor/cli/vendor/client/drive-upload.js +1 -234
  86. package/vendor/cli/vendor/client/env-file.js +1 -1273
  87. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  88. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  89. package/vendor/cli/vendor/client/google-signin.js +1 -133
  90. package/vendor/cli/vendor/client/hooks.js +1 -430
  91. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  92. package/vendor/cli/vendor/client/naming.js +1 -283
  93. package/vendor/cli/vendor/client/platform.js +1 -937
  94. package/vendor/cli/vendor/client/prefs.js +1 -351
  95. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  96. package/vendor/cli/vendor/client/presence.js +1 -438
  97. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  98. package/vendor/cli/vendor/client/session-store.js +1 -575
  99. package/vendor/cli/vendor/client/topup.js +1 -297
  100. package/vendor/cli/vendor/client/touch.js +1 -458
  101. package/vendor/cli/vendor/client/update.js +1 -763
  102. package/vendor/cli/vendor/client/user-models.js +1 -381
  103. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  104. package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
  105. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  106. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
  107. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
  108. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
  109. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  110. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  111. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
  112. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
  113. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  114. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
  115. package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
  116. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  117. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  118. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  119. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  120. package/vendor/cli/vendor/hosts/install.js +1 -638
  121. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  122. package/vendor/cli/vendor/hosts/spec.js +1 -164
  123. package/vendor/cli/vendor/hosts/targets.js +1 -346
  124. package/vendor/cli/vendor/mcp/server.js +1 -221
  125. package/vendor/cli/vendor/mcp/tools.js +1 -408
  126. package/vendor/cli/vendor/one/src/child.js +1 -285
  127. package/vendor/cli/vendor/one/src/permissions.js +1 -383
  128. package/vendor/desktop/bin/aegis.js +1 -32
  129. package/vendor/desktop/lib/account-key.js +1 -56
  130. package/vendor/desktop/lib/auto.js +1 -461
  131. package/vendor/desktop/lib/avatar/companion.js +1 -698
  132. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  133. package/vendor/desktop/lib/avatar/events.js +1 -344
  134. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  135. package/vendor/desktop/lib/avatar/holders.js +1 -612
  136. package/vendor/desktop/lib/avatar/identity.js +1 -641
  137. package/vendor/desktop/lib/avatar/level.js +1 -368
  138. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  139. package/vendor/desktop/lib/avatar/persona.js +1 -388
  140. package/vendor/desktop/lib/avatar/profile.js +1 -977
  141. package/vendor/desktop/lib/avatar/register.js +1 -307
  142. package/vendor/desktop/lib/avatar/store.js +1 -472
  143. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  144. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  145. package/vendor/desktop/lib/avatar/turn.js +1 -216
  146. package/vendor/desktop/lib/avatar/voice.js +1 -328
  147. package/vendor/desktop/lib/avatar/xp.js +1 -404
  148. package/vendor/desktop/lib/deep-link.js +1 -120
  149. package/vendor/desktop/lib/fingerprint.js +2 -347
  150. package/vendor/desktop/lib/google-connect.js +1 -323
  151. package/vendor/desktop/lib/local/agents.js +1 -105
  152. package/vendor/desktop/lib/local/attachments.js +1 -276
  153. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  154. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  155. package/vendor/desktop/lib/local/context.js +1 -125
  156. package/vendor/desktop/lib/local/engine.js +1 -3666
  157. package/vendor/desktop/lib/local/entitlement.js +1 -660
  158. package/vendor/desktop/lib/local/git-scope.js +1 -228
  159. package/vendor/desktop/lib/local/local.js +1 -2145
  160. package/vendor/desktop/lib/local/prompt.js +1 -280
  161. package/vendor/desktop/lib/local/queue.js +1 -560
  162. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  163. package/vendor/desktop/lib/local/spill.js +1 -75
  164. package/vendor/desktop/lib/local/telemetry.js +1 -470
  165. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  166. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  167. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  168. package/vendor/desktop/lib/quick-launcher.js +1 -84
  169. package/vendor/desktop/lib/settings.js +1 -890
  170. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  171. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  172. package/vendor/desktop/lib/sync/sessions.js +1 -106
  173. package/vendor/desktop/lib/window-state.js +1 -66
  174. package/vendor/desktop/package.json +2 -4
  175. package/vendor/desktop/preload.js +1 -679
  176. package/vendor/desktop/renderer/app.js +1 -7250
  177. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  178. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  179. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  180. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  181. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  182. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  183. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  184. package/vendor/desktop/renderer/budget.js +1 -172
  185. package/vendor/desktop/renderer/companion.js +1 -223
  186. package/vendor/desktop/renderer/diff.js +1 -359
  187. package/vendor/desktop/renderer/diffview.js +1 -336
  188. package/vendor/desktop/renderer/filepreview.js +1 -211
  189. package/vendor/desktop/renderer/fingerprint.js +3 -789
  190. package/vendor/desktop/renderer/markdown.js +1 -168
  191. package/vendor/desktop/renderer/provider-mark.js +1 -311
  192. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  193. package/vendor/desktop/renderer/providers.js +1 -259
  194. package/vendor/desktop/renderer/quick.js +1 -285
  195. package/vendor/desktop/renderer/stream-policy.js +1 -387
  196. package/vendor/desktop/renderer/transcript-view.js +1 -323
  197. package/vendor/desktop/renderer/usage.js +1 -1239
  198. package/vendor/desktop/vendor/aegis.js +1 -2441
  199. package/vendor/desktop/vendor/attest.js +1 -518
  200. package/vendor/desktop/vendor/authorship-key.js +1 -410
  201. package/vendor/desktop/vendor/auto-provision.js +1 -134
  202. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  203. package/vendor/desktop/vendor/byok-catalog.js +1 -199
  204. package/vendor/desktop/vendor/catalog-client.js +1 -487
  205. package/vendor/desktop/vendor/conversation-export.js +1 -177
  206. package/vendor/desktop/vendor/credentials.js +1 -494
  207. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  208. package/vendor/desktop/vendor/drive-connect.js +1 -110
  209. package/vendor/desktop/vendor/drive-upload.js +1 -234
  210. package/vendor/desktop/vendor/env-file.js +1 -1273
  211. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  212. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  213. package/vendor/desktop/vendor/google-signin.js +1 -133
  214. package/vendor/desktop/vendor/hooks.js +1 -430
  215. package/vendor/desktop/vendor/model-discovery.js +1 -373
  216. package/vendor/desktop/vendor/naming.js +1 -283
  217. package/vendor/desktop/vendor/platform.js +1 -937
  218. package/vendor/desktop/vendor/prefs.js +1 -351
  219. package/vendor/desktop/vendor/presence-constants.js +1 -107
  220. package/vendor/desktop/vendor/presence.js +1 -438
  221. package/vendor/desktop/vendor/record-vault.js +3 -1055
  222. package/vendor/desktop/vendor/session-store.js +1 -575
  223. package/vendor/desktop/vendor/topup.js +1 -297
  224. package/vendor/desktop/vendor/touch.js +1 -458
  225. package/vendor/desktop/vendor/update.js +1 -763
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -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
- // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
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};
@@ -1,193 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
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
- // Spawn through the shared resolver, not the bare name: on win32 npm is
144
- // `npm.cmd` (which `execFileSync` cannot execute without a shell) and a
145
- // GUI/desktop launch may not inherit the shell's PATH. `installSpawn` is
146
- // null only when the plan had nothing to run, which is handled above.
147
- const spec = typeof shared.installSpawn === 'function'
148
- ? shared.installSpawn(target, { env: process.env })
149
- : { command: target.command, args: target.args, shell: false };
150
- const spawned = spec || { command: target.command, args: target.args, shell: false };
151
- const out = execFileSync(spawned.command, spawned.args, {
152
- encoding: 'utf8',
153
- timeout: 180_000,
154
- stdio: ['ignore', 'pipe', 'pipe'],
155
- shell: spawned.shell === true,
156
- windowsHide: true,
157
- });
158
- return {
159
- ok: true,
160
- channel: method,
161
- command: `${target.command} ${target.args.join(' ')}`,
162
- output: String(out || '').trim(),
163
- };
164
- } catch (err) {
165
- return {
166
- ok: false,
167
- channel: method,
168
- command: `${target.command} ${target.args.join(' ')}`,
169
- error: String((err && (err.stderr || err.message)) || err).trim(),
170
- };
171
- }
172
- }
173
-
174
- /** Best-effort registry lookup (5s cap). Returns a version string or null. */
175
- function latestPublishedVersion({ packageName = PKG, timeoutMs = 5000 } = {}) {
176
- try {
177
- const out = execFileSync('npm', ['view', packageName, 'version'], {
178
- encoding: 'utf8', timeout: timeoutMs, stdio: ['ignore', 'pipe', 'ignore'],
179
- });
180
- const v = String(out).trim();
181
- return /^\d+\.\d+\.\d+/.test(v) ? v : null;
182
- } catch { return null; }
183
- }
184
-
185
- module.exports = {
186
- ...shared,
187
- VERSION,
188
- compareVersions,
189
- upgradeAdvice,
190
- applyUpgrade,
191
- installMethod,
192
- latestPublishedVersion,
193
- };
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};