aegisone 1.0.21 → 1.0.23

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 -2
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -939
  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 -369
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/bin/aegiscode.js +2 -914
  17. package/vendor/cli/package.json +3 -2
  18. package/vendor/cli/scripts/check.mjs +1 -52
  19. package/vendor/cli/scripts/demo.mjs +1 -94
  20. package/vendor/cli/scripts/predist.mjs +1 -75
  21. package/vendor/cli/scripts/runtests.mjs +1 -56
  22. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  23. package/vendor/cli/src/agents.js +1 -139
  24. package/vendor/cli/src/app.js +1 -2932
  25. package/vendor/cli/src/art.js +1 -289
  26. package/vendor/cli/src/autonomous.js +1 -515
  27. package/vendor/cli/src/caps.js +1 -879
  28. package/vendor/cli/src/chatflow.js +1 -3008
  29. package/vendor/cli/src/checkpoint.js +1 -90
  30. package/vendor/cli/src/clipboard.js +1 -424
  31. package/vendor/cli/src/cloudsync.js +1 -528
  32. package/vendor/cli/src/commands.js +1 -3987
  33. package/vendor/cli/src/config.js +1 -581
  34. package/vendor/cli/src/connect.js +1 -349
  35. package/vendor/cli/src/credentials.js +1 -33
  36. package/vendor/cli/src/deps.js +1 -232
  37. package/vendor/cli/src/devrun.js +1 -187
  38. package/vendor/cli/src/diff.js +1 -333
  39. package/vendor/cli/src/diffview.js +1 -296
  40. package/vendor/cli/src/engine.js +1 -297
  41. package/vendor/cli/src/entitlement.js +1 -355
  42. package/vendor/cli/src/events.js +1 -707
  43. package/vendor/cli/src/export.js +1 -67
  44. package/vendor/cli/src/fingerprint.js +1 -592
  45. package/vendor/cli/src/format.js +1 -259
  46. package/vendor/cli/src/fuzzy.js +1 -119
  47. package/vendor/cli/src/gate.js +1 -55
  48. package/vendor/cli/src/history.js +1 -401
  49. package/vendor/cli/src/init.js +1 -175
  50. package/vendor/cli/src/input.js +1 -139
  51. package/vendor/cli/src/keys.js +1 -183
  52. package/vendor/cli/src/limits.js +1 -190
  53. package/vendor/cli/src/markdown.js +1 -306
  54. package/vendor/cli/src/mcp.js +1 -694
  55. package/vendor/cli/src/models.js +1 -487
  56. package/vendor/cli/src/naming.js +1 -229
  57. package/vendor/cli/src/overlays.js +1 -461
  58. package/vendor/cli/src/panels.js +1 -1418
  59. package/vendor/cli/src/permissions.js +1 -290
  60. package/vendor/cli/src/ping.js +1 -226
  61. package/vendor/cli/src/presence.js +1 -238
  62. package/vendor/cli/src/provenance.js +2 -182
  63. package/vendor/cli/src/render.js +1 -515
  64. package/vendor/cli/src/screen.js +1 -518
  65. package/vendor/cli/src/screens.js +1 -896
  66. package/vendor/cli/src/secret.js +1 -59
  67. package/vendor/cli/src/securefs.js +1 -359
  68. package/vendor/cli/src/settings.js +1 -155
  69. package/vendor/cli/src/shared.js +1 -52
  70. package/vendor/cli/src/sharedpaths.js +1 -53
  71. package/vendor/cli/src/signup.js +1 -156
  72. package/vendor/cli/src/summarize.js +1 -95
  73. package/vendor/cli/src/sysdiag.js +1 -585
  74. package/vendor/cli/src/system.js +1 -40
  75. package/vendor/cli/src/theme.js +1 -570
  76. package/vendor/cli/src/title.js +1 -220
  77. package/vendor/cli/src/todos.js +1 -115
  78. package/vendor/cli/src/tokens.js +1 -263
  79. package/vendor/cli/src/topup.js +1 -210
  80. package/vendor/cli/src/update.js +1 -181
  81. package/vendor/cli/vendor/client/aegis.js +1 -2054
  82. package/vendor/cli/vendor/client/attest.js +1 -442
  83. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  84. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  85. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  86. package/vendor/cli/vendor/client/byok-catalog.js +1 -230
  87. package/vendor/cli/vendor/client/credentials.js +1 -494
  88. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  89. package/vendor/cli/vendor/client/drive-connect.js +1 -85
  90. package/vendor/cli/vendor/client/drive-upload.js +1 -174
  91. package/vendor/cli/vendor/client/env-file.js +1 -1273
  92. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  93. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  94. package/vendor/cli/vendor/client/google-signin.js +1 -125
  95. package/vendor/cli/vendor/client/hooks.js +1 -430
  96. package/vendor/cli/vendor/client/model-discovery.js +1 -330
  97. package/vendor/cli/vendor/client/platform.js +1 -937
  98. package/vendor/cli/vendor/client/prefs.js +1 -351
  99. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  100. package/vendor/cli/vendor/client/presence.js +1 -438
  101. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  102. package/vendor/cli/vendor/client/session-store.js +1 -548
  103. package/vendor/cli/vendor/client/topup.js +1 -297
  104. package/vendor/cli/vendor/client/touch.js +1 -458
  105. package/vendor/cli/vendor/client/update.js +1 -704
  106. package/vendor/cli/vendor/client/user-models.js +1 -381
  107. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  108. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  109. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -993
  110. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -95
  111. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3228
  112. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -654
  113. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  114. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2135
  115. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -275
  116. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  117. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -208
  118. package/vendor/cli/vendor/desktop/lib/local/shell.js +1 -680
  119. package/vendor/cli/vendor/desktop/lib/local/tools.js +1 -1238
  120. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  121. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  122. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  123. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  124. package/vendor/cli/vendor/hosts/install.js +1 -638
  125. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  126. package/vendor/cli/vendor/hosts/spec.js +1 -164
  127. package/vendor/cli/vendor/hosts/targets.js +1 -346
  128. package/vendor/cli/vendor/mcp/server.js +1 -221
  129. package/vendor/cli/vendor/mcp/tools.js +1 -408
  130. package/vendor/cli/vendor/one/src/child.js +1 -285
  131. package/vendor/cli/vendor/one/src/permissions.js +1 -369
  132. package/vendor/desktop/bin/aegis.js +1 -32
  133. package/vendor/desktop/lib/account-key.js +1 -56
  134. package/vendor/desktop/lib/auto.js +1 -430
  135. package/vendor/desktop/lib/avatar/companion.js +1 -698
  136. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  137. package/vendor/desktop/lib/avatar/events.js +1 -344
  138. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  139. package/vendor/desktop/lib/avatar/holders.js +1 -612
  140. package/vendor/desktop/lib/avatar/identity.js +1 -641
  141. package/vendor/desktop/lib/avatar/level.js +1 -368
  142. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  143. package/vendor/desktop/lib/avatar/persona.js +1 -388
  144. package/vendor/desktop/lib/avatar/profile.js +1 -977
  145. package/vendor/desktop/lib/avatar/register.js +1 -307
  146. package/vendor/desktop/lib/avatar/store.js +1 -472
  147. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  148. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  149. package/vendor/desktop/lib/avatar/turn.js +1 -216
  150. package/vendor/desktop/lib/avatar/voice.js +1 -328
  151. package/vendor/desktop/lib/avatar/xp.js +1 -404
  152. package/vendor/desktop/lib/deep-link.js +1 -120
  153. package/vendor/desktop/lib/fingerprint.js +2 -347
  154. package/vendor/desktop/lib/google-connect.js +1 -169
  155. package/vendor/desktop/lib/local/agents.js +1 -105
  156. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  157. package/vendor/desktop/lib/local/claude-pro.js +1 -993
  158. package/vendor/desktop/lib/local/context.js +1 -95
  159. package/vendor/desktop/lib/local/engine.js +1 -3228
  160. package/vendor/desktop/lib/local/entitlement.js +1 -654
  161. package/vendor/desktop/lib/local/git-scope.js +1 -228
  162. package/vendor/desktop/lib/local/local.js +1 -2135
  163. package/vendor/desktop/lib/local/prompt.js +1 -275
  164. package/vendor/desktop/lib/local/queue.js +1 -560
  165. package/vendor/desktop/lib/local/session-rounds.js +1 -208
  166. package/vendor/desktop/lib/local/shell.js +1 -680
  167. package/vendor/desktop/lib/local/telemetry.js +1 -470
  168. package/vendor/desktop/lib/local/tools.js +1 -1238
  169. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  170. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  171. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  172. package/vendor/desktop/lib/quick-launcher.js +1 -84
  173. package/vendor/desktop/lib/settings.js +1 -890
  174. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  175. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  176. package/vendor/desktop/lib/sync/sessions.js +1 -106
  177. package/vendor/desktop/lib/window-state.js +1 -66
  178. package/vendor/desktop/main.js +1 -4390
  179. package/vendor/desktop/package.json +3 -5
  180. package/vendor/desktop/preload.js +1 -628
  181. package/vendor/desktop/renderer/app.js +1 -6560
  182. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  183. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  184. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  185. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  186. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  187. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  188. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  189. package/vendor/desktop/renderer/budget.js +1 -168
  190. package/vendor/desktop/renderer/companion.js +1 -223
  191. package/vendor/desktop/renderer/diff.js +1 -359
  192. package/vendor/desktop/renderer/diffview.js +1 -336
  193. package/vendor/desktop/renderer/fingerprint.js +3 -720
  194. package/vendor/desktop/renderer/markdown.js +1 -168
  195. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  196. package/vendor/desktop/renderer/providers.js +1 -259
  197. package/vendor/desktop/renderer/quick.js +1 -191
  198. package/vendor/desktop/renderer/stream-policy.js +1 -306
  199. package/vendor/desktop/renderer/transcript-view.js +1 -323
  200. package/vendor/desktop/renderer/usage.js +1 -1239
  201. package/vendor/desktop/vendor/aegis.js +1 -2054
  202. package/vendor/desktop/vendor/attest.js +1 -442
  203. package/vendor/desktop/vendor/authorship-key.js +1 -410
  204. package/vendor/desktop/vendor/auto-provision.js +1 -134
  205. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  206. package/vendor/desktop/vendor/byok-catalog.js +1 -230
  207. package/vendor/desktop/vendor/credentials.js +1 -494
  208. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  209. package/vendor/desktop/vendor/drive-connect.js +1 -85
  210. package/vendor/desktop/vendor/drive-upload.js +1 -174
  211. package/vendor/desktop/vendor/env-file.js +1 -1273
  212. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  213. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  214. package/vendor/desktop/vendor/google-signin.js +1 -125
  215. package/vendor/desktop/vendor/hooks.js +1 -430
  216. package/vendor/desktop/vendor/model-discovery.js +1 -330
  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 -548
  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 -704
  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,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
- // 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
- 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};