aegiscode 6.8.30 → 6.8.31

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/src/config.js CHANGED
@@ -19,17 +19,32 @@ const { writePrivateFile } = require('./securefs.js');
19
19
  // The data dir is defined once, in the shared credential module, because the
20
20
  // desktop app and the MCP plugin now read and write the same store: a second
21
21
  // definition here is how the hosts would drift back apart.
22
- const { credentials } = require('./shared.js');
22
+ const { credentials, prefs } = require('./shared.js');
23
23
 
24
24
  /** Data directory: $AEGISCODE_HOME or ~/.aegiscode (see client/credentials.js). */
25
25
  function aegisDir(env) {
26
26
  return credentials.aegisHome(env);
27
27
  }
28
28
 
29
+ /**
30
+ * The host-local config file (`$AEGISCODE_HOME/config.json`).
31
+ *
32
+ * Since AEGISONE D5 this holds only what is HOST-LOCAL: the update-check cache,
33
+ * `lastCwd`, and anything the CLI alone owns (a stored `provider`/`baseURL` row,
34
+ * the `light` palette flag). Non-secret *preferences* live in the shared store
35
+ * (`$AEGISCODE_HOME/preferences.json`, client/prefs.js) so the window and the
36
+ * shell read one value instead of two that can disagree — see `SHARED_KEYS`, and
37
+ * `loadConfig()`/`updateConfig()` for the split and the one-way migration.
38
+ */
29
39
  function configPath() {
30
40
  return path.join(aegisDir(), 'config.json');
31
41
  }
32
42
 
43
+ /** The shared non-secret preference file the desktop's settings store writes too. */
44
+ function prefsPath() {
45
+ return prefs.prefsFile({ dir: aegisDir() });
46
+ }
47
+
33
48
  /**
34
49
  * True once the user has run before — the config file is written during
35
50
  * onboarding (and on the first preference change). Used to gate the trust
@@ -165,31 +180,152 @@ function setMemoryPersist(on) {
165
180
  });
166
181
  }
167
182
 
168
- /** Read the config, falling back to defaults (never throws). */
169
- function loadConfig() {
183
+ /**
184
+ * The config keys that live in the SHARED store (D5) rather than in this host's
185
+ * config.json: the non-secret preferences the window and the shell must agree
186
+ * about. The list itself lives in client/prefs.js (`SHARED_PREF_KEYS`) because
187
+ * the desktop's settings store reads it too — one definition, two readers.
188
+ */
189
+ const SHARED_KEYS = new Set(prefs.SHARED_PREF_KEYS);
190
+
191
+ /** The subset of `obj` whose keys live in the shared store. */
192
+ function pickShared(obj) {
193
+ const out = {};
194
+ for (const k of Object.keys(obj || {})) if (SHARED_KEYS.has(k)) out[k] = obj[k];
195
+ return out;
196
+ }
197
+
198
+ /** Read the host-local config file (never throws; {} when absent/corrupt). */
199
+ function readHostConfig() {
170
200
  try {
171
- const raw = fs.readFileSync(configPath(), 'utf8');
172
- const parsed = JSON.parse(raw);
173
- if (parsed && typeof parsed === 'object') return { ...DEFAULT_CONFIG, ...parsed };
201
+ const parsed = JSON.parse(fs.readFileSync(configPath(), 'utf8'));
202
+ if (parsed && typeof parsed === 'object') return parsed;
174
203
  } catch {}
175
- return { ...DEFAULT_CONFIG };
204
+ return {};
205
+ }
206
+
207
+ /** Read the shared preference store (`$AEGISCODE_HOME/preferences.json`). */
208
+ function readSharedPrefs() {
209
+ try {
210
+ return prefs.load({ dir: aegisDir() });
211
+ } catch {
212
+ return {};
213
+ }
214
+ }
215
+
216
+ /**
217
+ * Read the config, falling back to defaults (never throws).
218
+ *
219
+ * Three layers, lowest first: `DEFAULT_CONFIG`, this host's config.json, the
220
+ * shared preference store. The shared store wins because it is the store both
221
+ * faces write — reading it second is what makes a preference set in the window
222
+ * visible in the shell with no cloud round trip.
223
+ *
224
+ * A config.json written by an older CLI still holds the shared keys inline
225
+ * (`themeIndex`, `model`, `effort`, …). That legacy copy is read here — this is
226
+ * the read half of the one-way migration — but never written back: the next
227
+ * `updateConfig()` moves it into the shared store and drops it from
228
+ * config.json, so one preference ends up in exactly one place.
229
+ */
230
+ function loadConfig() {
231
+ const host = readHostConfig();
232
+ const shared = readSharedPrefs();
233
+ const merged = { ...DEFAULT_CONFIG, ...host };
234
+ const migrated = {};
235
+ for (const k of SHARED_KEYS) {
236
+ const inHost = host[k] !== undefined;
237
+ const inShared = shared[k] !== undefined;
238
+ if (inHost && inShared) {
239
+ // The shared store outranks the host copy — except when its value is an
240
+ // explicit `null` and the host copy is a real one. `sharedView()` writes
241
+ // EVERY shared key on every save, filling an unset `model`/`effort` with
242
+ // its `DEFAULT_CONFIG` value, so `null` there is usually the default and
243
+ // not a decision. Reading it as one swallowed a legacy pin: a config.json
244
+ // from a pre-D5 CLI keeps `model` inline, and the moment the new code
245
+ // saved any other preference it also wrote `model: null` to the shared
246
+ // store, which then beat the pin on every launch. That made the read half
247
+ // of the one-way migration described above dead code — the exact
248
+ // regression `test/cli-models.test.mjs` pins. A real value in the shared
249
+ // store still wins (that is what makes a pin chosen in the window visible
250
+ // in the shell), and once `updateConfig()` runs, shared keys are dropped
251
+ // from config.json, so there is no stale host copy left to prefer.
252
+ migrated[k] = shared[k] === null && host[k] !== null ? host[k] : shared[k];
253
+ } else if (inHost) {
254
+ migrated[k] = host[k];
255
+ } else if (inShared) {
256
+ migrated[k] = shared[k];
257
+ }
258
+ }
259
+ return { ...merged, ...migrated };
260
+ }
261
+
262
+ /**
263
+ * The shared store's view of this config.
264
+ *
265
+ * `model: null` / `effort: null` are written out explicitly rather than left
266
+ * absent: the shared document is the resolved preference set both faces read,
267
+ * and "no pin" is itself a stored decision (`DEFAULT_CONFIG` says so, and
268
+ * `validatePinnedModel()` clears a phantom pin by writing `null`).
269
+ *
270
+ * `memoryPersist` is the one exception, and deliberately: filling it with the
271
+ * default would defeat `memoryPersistState()`'s legacy migration, which exists
272
+ * so that an explicit pre-flip `cloudSync: false` on disk is never quietly
273
+ * opted back in. So it is written only when it is actually known — set by this
274
+ * patch, already in the shared store, already in config.json, or stated by the
275
+ * legacy `cloudSync` key.
276
+ */
277
+ function sharedView(patch, host, shared) {
278
+ const view = {};
279
+ for (const k of SHARED_KEYS) {
280
+ if (k === 'memoryPersist') continue;
281
+ if (patch[k] !== undefined) view[k] = patch[k];
282
+ else if (shared[k] !== undefined) view[k] = shared[k];
283
+ else if (host[k] !== undefined) view[k] = host[k];
284
+ else view[k] = DEFAULT_CONFIG[k];
285
+ }
286
+ if (patch.memoryPersist !== undefined) view.memoryPersist = patch.memoryPersist;
287
+ else if (shared.memoryPersist !== undefined) view.memoryPersist = shared.memoryPersist;
288
+ else if (host.memoryPersist !== undefined) view.memoryPersist = host.memoryPersist;
289
+ else if (typeof host[LEGACY_MEMORY_PERSIST_KEY] === 'boolean') {
290
+ view.memoryPersist = host[LEGACY_MEMORY_PERSIST_KEY];
291
+ }
292
+ return view;
176
293
  }
177
294
 
178
295
  /**
179
296
  * Merge a patch into the config on disk and return the merged config.
180
- * A no-op that still returns the merged view when the data dir is unwritable.
297
+ *
298
+ * Split by destination, never duplicated: the shared keys go to
299
+ * `$AEGISCODE_HOME/preferences.json`, everything else to this host's
300
+ * config.json (with any shared key a legacy file still carries dropped, which
301
+ * completes the one-way migration). A no-op that still returns the merged view
302
+ * when a file cannot be written.
181
303
  */
182
304
  function updateConfig(patch) {
183
- const next = { ...loadConfig(), ...patch };
305
+ const p = patch || {};
306
+ const host = readHostConfig();
307
+ const sharedNow = readSharedPrefs();
308
+ const sharedKeys = pickShared(p);
309
+ const hostKeys = { ...p };
310
+ for (const k of SHARED_KEYS) delete hostKeys[k];
311
+
312
+ try {
313
+ prefs.set(sharedView(p, host, sharedNow), { dir: aegisDir() });
314
+ } catch (e) {
315
+ if (process.env.AEGIS_HIST_DEBUG) console.error('[prefs] write failed:', e);
316
+ }
317
+
318
+ const hostNext = { ...DEFAULT_CONFIG, ...host, ...hostKeys };
319
+ for (const k of SHARED_KEYS) delete hostNext[k];
184
320
  try {
185
321
  // Atomic (tmp + rename) so a crash can't corrupt it, and written 0600:
186
322
  // config.json carries `provider` and `baseURL`, so a group-writable copy is
187
323
  // a way for another local account to repoint the session's endpoint.
188
- writePrivateFile(configPath(), JSON.stringify(next, null, 2) + '\n');
324
+ writePrivateFile(configPath(), JSON.stringify(hostNext, null, 2) + '\n');
189
325
  } catch (e) {
190
326
  if (process.env.AEGIS_HIST_DEBUG) console.error('[config] write failed:', e);
191
327
  }
192
- return next;
328
+ return loadConfig();
193
329
  }
194
330
 
195
331
  // ── Permissions (~/.aegiscode/permissions.json) ─────────────────────────────
@@ -259,6 +395,7 @@ function removePermissionRule(list, pattern, rules) {
259
395
  module.exports = {
260
396
  aegisDir,
261
397
  configPath,
398
+ prefsPath,
262
399
  configExists,
263
400
  permissionsPath,
264
401
  DEFAULT_CONFIG,
@@ -135,6 +135,95 @@ function evalPermission(toolName, args, rules = {}) {
135
135
  return 'allow';
136
136
  }
137
137
 
138
+ // ── "Skip permissions", resolved ONCE (AEGISONE, D8 rules 3 and 5) ──────────
139
+ //
140
+ // One resolver, two callers: `one/src/permissions.js` (the product's posture,
141
+ // which feeds a spawned Claude child's argv) and `cli/src/app.js` (this face's
142
+ // own confirmation gate). It lives HERE, beside `evalPermission`, so the rule
143
+ // engine and the skip resolver are one module rather than two spellings that
144
+ // can drift — the same reason D8 keeps one rule language.
145
+ //
146
+ // The three sources, and why they are three:
147
+ //
148
+ // flag `--dangerously-skip-permissions`, typed by a human. Always
149
+ // honored: it is the whole point of the flag, and rule 3 requires
150
+ // a one-line report of what it skipped (the caller prints it).
151
+ // productEnv `AEGISONE_SKIP_PERMISSIONS`, set by the `aegis` bin ONLY after
152
+ // it resolved the posture for the child it is about to spawn —
153
+ // i.e. the flag, already checked against rule 5. That indirection
154
+ // is what lets the terminal face honor `aegis … --dangerously-
155
+ // skip-permissions` without the face ever reading the *user's*
156
+ // environment for a skip it was not asked for.
157
+ // env `AEGIS_SKIP_PERMISSIONS`, the CI/queue spelling. It equals the
158
+ // flag only when the process is NON-interactive: a stray `export`
159
+ // in a shell profile must not be able to disarm a human's own
160
+ // gate (rule 5). Interactive + unasked ⇒ warn and ignore.
161
+ //
162
+ // It never returns why something was skipped beyond naming its source: what a
163
+ // skip DOES cover is rule 2's business, and rule 2's floors (the covenant
164
+ // assert and the four level-independent approvals) are not reachable from here
165
+ // at all.
166
+ const SKIP = Object.freeze({
167
+ flag: '--dangerously-skip-permissions',
168
+ env: 'AEGIS_SKIP_PERMISSIONS',
169
+ productEnv: 'AEGISONE_SKIP_PERMISSIONS',
170
+ truthy: Object.freeze(['1', 'true', 'yes', 'on']),
171
+ });
172
+
173
+ const isTruthyEnv = (v) => v !== undefined && SKIP.truthy.includes(String(v).trim().toLowerCase());
174
+
175
+ /** Rule 5's warning, spelled once so both callers print the same sentence. */
176
+ const SKIP_ENV_WARNING =
177
+ `AEGIS_SKIP_PERMISSIONS is set but this session is interactive — ignoring it. ` +
178
+ `Pass --dangerously-skip-permissions to skip the configurable gates on purpose; ` +
179
+ `the ÆGIS covenant and the write|shell|network|offDevice approvals are never skipped.`;
180
+
181
+ /**
182
+ * @param {object} [input]
183
+ * @param {boolean} [input.flag] the flag was explicitly passed
184
+ * @param {object} [input.env] environment to read (never mutated)
185
+ * @param {boolean} [input.interactive] both stdio ends are a terminal
186
+ * @returns {{skip: boolean, source: 'flag'|'product'|'env'|'env-ignored'|'none',
187
+ * flag: boolean, envSet: boolean, interactive: boolean,
188
+ * warned: boolean, warning: string|null}}
189
+ */
190
+ function resolveSkip(input = {}) {
191
+ const flag = input.flag === true;
192
+ const env = input.env || {};
193
+ const interactive = input.interactive === true;
194
+ const envSet = isTruthyEnv(env[SKIP.env]);
195
+ const productSet = isTruthyEnv(env[SKIP.productEnv]);
196
+
197
+ // src: flag → product → env(non-interactive). No `catch`-all default that
198
+ // could skip: every other path returns skip: false.
199
+ if (flag || productSet) {
200
+ return {
201
+ skip: true,
202
+ source: flag ? 'flag' : 'product',
203
+ flag,
204
+ envSet,
205
+ interactive,
206
+ warned: false,
207
+ warning: null,
208
+ };
209
+ }
210
+ if (envSet && !interactive) {
211
+ return { skip: true, source: 'env', flag, envSet, interactive, warned: false, warning: null };
212
+ }
213
+ if (envSet && interactive) {
214
+ return {
215
+ skip: false,
216
+ source: 'env-ignored',
217
+ flag,
218
+ envSet,
219
+ interactive,
220
+ warned: true,
221
+ warning: SKIP_ENV_WARNING,
222
+ };
223
+ }
224
+ return { skip: false, source: 'none', flag, envSet: false, interactive, warned: false, warning: null };
225
+ }
226
+
138
227
  module.exports = {
139
228
  canonTool,
140
229
  isShellTool,
@@ -142,4 +231,7 @@ module.exports = {
142
231
  matchRule,
143
232
  isMultiDirCommand,
144
233
  evalPermission,
234
+ SKIP,
235
+ SKIP_ENV_WARNING,
236
+ resolveSkip,
145
237
  };
package/src/shared.js CHANGED
@@ -41,5 +41,9 @@ function resolveClientModule(name) {
41
41
 
42
42
  const credentials = require(resolveClientModule('credentials.js'));
43
43
  const sessionStore = require(resolveClientModule('session-store.js'));
44
+ // The one shared non-secret preference store (AEGISONE D5). `config.js` reads
45
+ // and writes it, and the desktop's settings store writes the same file — so it
46
+ // belongs here, resolved by existence, rather than as a second path guess.
47
+ const prefs = require(resolveClientModule('prefs.js'));
44
48
 
45
- module.exports = { credentials, sessionStore, resolveClientModule };
49
+ module.exports = { credentials, sessionStore, prefs, resolveClientModule };
package/src/topup.js ADDED
@@ -0,0 +1,207 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * topup.js — `aegiscode topup [EUR]`: the terminal's own top-up.
5
+ *
6
+ * WHY THE TERMINAL NEEDS THIS AT ALL. `/billing` prints a link (`/go/topup`) and
7
+ * that was the whole funding affordance: the CLI could not start a checkout.
8
+ * The link is real but it lands on `/topup`, which is `@login_required` against
9
+ * a browser SESSION — and the account this product auto-provisions is created by
10
+ * `POST /api/v1/auth/register-device`, with a password that is never returned
11
+ * and an email at `@device.aegiscloud`. So the user who most needs to fund a
12
+ * free account is the one who cannot sign in to the page that funds it: they pay
13
+ * the link a visit, hit a login wall, and conclude it failed while the money is
14
+ * real.
15
+ *
16
+ * What makes this work is that the credential which CREATES the checkout can
17
+ * also READ the result: `POST /api/token-bank/topup` and `GET
18
+ * /api/token-bank/balance` are both `login_required`, which accepts
19
+ * `X-API-Key`/Bearer. So this command starts the session, opens the hosted page
20
+ * for the actual card entry, and then confirms the credit itself from the
21
+ * balance endpoint — the same confirmation the desktop does, over the same state
22
+ * machine (`client/topup.js`, `createCreditWatch`), so the terminal and the GUI
23
+ * cannot disagree about whether the money arrived.
24
+ *
25
+ * It BLOCKS on purpose. The desktop's watch is an unref'd interval because the
26
+ * window stays open for hours; here the process exits, so a detached timer would
27
+ * be killed before the webhook fires. A loop is the honest scheduler for a
28
+ * one-shot command, and it is why the shared module owns the state machine and
29
+ * not the timer.
30
+ *
31
+ * Exit codes (a script can gate on them): 0 credited, 1 checkout opened but no
32
+ * credit observed in the window, 2 usage / no usable credential / the server
33
+ * refused the checkout.
34
+ */
35
+
36
+ const { resolveShared } = require('./sharedpaths.js');
37
+ const { openUrl: defaultOpenUrl } = require('./system.js');
38
+ const credentials = require('./credentials.js');
39
+
40
+ /** Resolve a shared module by existence (repo checkout or the staged tree). */
41
+ function loadShared(rel) {
42
+ return require(resolveShared(rel));
43
+ }
44
+
45
+ /** The same thin client the session and the entitlement gate use. */
46
+ function createCliClient() {
47
+ const { createClient } = loadShared('client/aegis.js');
48
+ return createClient(credentials.clientOptions({ channel: 'cli' }));
49
+ }
50
+
51
+ /**
52
+ * A key is needed to create a checkout at all, so a fresh machine gets the same
53
+ * free device key the session path asks for — one implementation, the shared
54
+ * auto-provision helper (client/auto-provision.js), and one attempt.
55
+ *
56
+ * Best-effort by design: if the helper is unreachable or the server declines,
57
+ * this returns false and the caller says so, rather than throwing a module error
58
+ * at a user who is trying to give us money.
59
+ */
60
+ async function ensureKey(client, store) {
61
+ if (client.apiKey) return true;
62
+ try {
63
+ const mod = loadShared('client/auto-provision.js');
64
+ const provision = mod.autoProvisionApiKey || mod.default;
65
+ if (typeof provision === 'function') {
66
+ const res = await provision(client, store);
67
+ if (res && res.key && typeof client.setApiKey === 'function') client.setApiKey(res.key);
68
+ }
69
+ } catch {
70
+ /* fall through: the caller reports the missing credential plainly */
71
+ }
72
+ return Boolean(client.apiKey);
73
+ }
74
+
75
+ /**
76
+ * Run the command and return a process exit code.
77
+ *
78
+ * @param {string|null} arg the typed amount (null ⇒ the server default, 10 EUR)
79
+ * @param {object} [io] injectable for tests: `stdout`, `stderr`, `client`,
80
+ * `openUrl`, `sleep`, `intervalMs`, `maxTries`, `json`, `onStep`.
81
+ */
82
+ async function runTopupCommand(arg, io) {
83
+ const options = io || {};
84
+ const stdout = options.stdout || process.stdout;
85
+ const stderr = options.stderr || process.stderr;
86
+ // JSON mode is a script's stdout: one object (written by finish()) and no
87
+ // human chatter, so a parser never has to skip progress lines. Errors still
88
+ // go to stderr, which is not the stream being parsed.
89
+ const out = options.json ? () => {} : (s) => stdout.write(s);
90
+ let payload = null;
91
+
92
+ // JSON mode prints ONE object and nothing else, so a script parsing stdout
93
+ // does not have to skip progress chatter.
94
+ const finish = (code, result) => {
95
+ if (options.json) stdout.write(JSON.stringify(result) + '\n');
96
+ return code;
97
+ };
98
+
99
+ let shared;
100
+ try {
101
+ shared = loadShared('client/topup.js');
102
+ } catch (error) {
103
+ stderr.write(`aegiscode: the shared top-up module is missing — ${(error && error.message) || error}\n`);
104
+ return 2;
105
+ }
106
+ const {
107
+ parseTopupAmount,
108
+ startTopup,
109
+ createCreditWatch,
110
+ TOPUP_POLL_MS,
111
+ TOPUP_POLL_TRIES,
112
+ TOPUP_MIN_EUR,
113
+ TOPUP_MAX_EUR,
114
+ } = shared;
115
+
116
+ const parsed = parseTopupAmount(arg);
117
+ if (!parsed.ok) {
118
+ stderr.write(
119
+ `aegiscode: ${parsed.message}\n` +
120
+ ` usage: aegiscode topup [${TOPUP_MIN_EUR}..${TOPUP_MAX_EUR}] (default 10)\n`
121
+ );
122
+ // JSON mode still emits its ONE object here: a script that checks the exit
123
+ // code must not be the only way to learn why — "no stdout at all" reads as
124
+ // a crash, not as a rejected amount.
125
+ return finish(2, { ok: false, credited: false, amount_eur: null, url: null, balance_eur: null, error: parsed.message });
126
+ }
127
+ payload = { ok: false, credited: false, amount_eur: parsed.amount, url: null, balance_eur: null };
128
+
129
+ // Say something BEFORE the first network call. The transport's ceiling is 60s
130
+ // per request and this path can make two (auto-provision, then the checkout),
131
+ // so an unreachable server used to mean two silent minutes and then a line —
132
+ // which a user reads as a hung command, not as a network problem. stderr, not
133
+ // stdout: in --json mode stdout is a script's parse target.
134
+ stderr.write(`aegiscode: requesting a ${parsed.amount} EUR top-up from the account service…\n`);
135
+
136
+ const client = options.client || createCliClient();
137
+ if (!client.apiKey && !(await ensureKey(client, credentials))) {
138
+ stderr.write(
139
+ 'aegiscode: no AEGIS key on this machine and none could be provisioned —\n' +
140
+ ' `aegiscode login <api_key>` (from https://aegiscloud.org/dashboard) first\n'
141
+ );
142
+ payload.error = 'no usable AEGIS key';
143
+ return finish(2, payload);
144
+ }
145
+
146
+ const started = await startTopup(client, parsed.amount);
147
+ if (!started.ok) {
148
+ stderr.write(`aegiscode: the top-up could not be started — ${started.message}\n`);
149
+ if (started.hint) stderr.write(`aegiscode: ${started.hint}\n`);
150
+ payload.error = started.message;
151
+ payload.status = started.status;
152
+ return finish(2, payload);
153
+ }
154
+ payload.url = started.url;
155
+
156
+ const open = options.openUrl || defaultOpenUrl;
157
+ const sleep = options.sleep || ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
158
+ const intervalMs = options.intervalMs == null ? TOPUP_POLL_MS : options.intervalMs;
159
+ const maxTries = options.maxTries == null ? TOPUP_POLL_TRIES : options.maxTries;
160
+ const windowSeconds = Math.max(1, Math.round((intervalMs * maxTries) / 1000));
161
+
162
+ // `openUrl` returns false when the platform opener is missing (a container, a
163
+ // server over ssh); the URL is then the ONLY way to pay, so it is printed
164
+ // rather than swallowed — a command that silently does nothing is worse than
165
+ // one that says "paste this".
166
+ if (open(started.url)) {
167
+ out(`aegiscode: opening the payment page in your browser — ${started.amount} EUR\n`);
168
+ } else {
169
+ out(`aegiscode: open this to pay ${started.amount} EUR:\n ${started.url}\n`);
170
+ }
171
+ out(`aegiscode: watching this account's bank for up to ${windowSeconds}s to confirm the credit\n`);
172
+
173
+ const watch = createCreditWatch(client, { maxTries });
174
+ let announcedBaseline = false;
175
+ for (;;) {
176
+ const step = await watch.tick();
177
+ if (typeof options.onStep === 'function') options.onStep(step);
178
+ if (step.state === 'credited') {
179
+ payload.ok = true;
180
+ payload.credited = true;
181
+ payload.balance_eur = step.amount;
182
+ out(
183
+ `aegiscode: credit confirmed — the bank is now ${step.amount.toFixed(2)} EUR\n` +
184
+ 'aegiscode: (this account was created by this machine, so the browser there has no\n' +
185
+ ' session for it — the confirmation comes from the API, not the page)\n'
186
+ );
187
+ return finish(0, payload);
188
+ }
189
+ if (step.state === 'expired') {
190
+ // Honest about what is and is not known: the window closed on OUR watch,
191
+ // which is not the same claim as "you were not charged".
192
+ out(
193
+ `aegiscode: no credit observed within ${windowSeconds}s — if you completed the payment it\n` +
194
+ 'aegiscode: may still land; re-run `aegiscode topup` or check `/billing` in a session\n'
195
+ );
196
+ payload.error = 'no credit observed within the watch window';
197
+ return finish(1, payload);
198
+ }
199
+ if (step.baseline != null && !announcedBaseline && !options.json) {
200
+ announcedBaseline = true;
201
+ out(`aegiscode: bank before the payment: ${step.baseline.toFixed(2)} EUR\n`);
202
+ }
203
+ await sleep(intervalMs);
204
+ }
205
+ }
206
+
207
+ module.exports = { runTopupCommand, ensureKey, createCliClient };
@@ -909,6 +909,13 @@ function baseName(input) {
909
909
 
910
910
  const api = {
911
911
  IS_WIN32,
912
+ // The seam bag itself (`seams(options)` above), exported since ON6/ON7 of the
913
+ // AEGISONE plan: `one/src/host.js` is the product's single OS answer and it
914
+ // has to *ask* here rather than keep a second `process.platform` read. The
915
+ // bag is what makes the answer injectable (`seams({ platform: 'win32' })`),
916
+ // and the function itself was always the point of this module — it simply
917
+ // was not reachable from outside it.
918
+ seams,
912
919
  resolveExecutable,
913
920
  shellSpec,
914
921
  killTree,