aegiscode 6.8.11 → 6.8.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -13
- package/bin/aegiscode.js +124 -2
- package/package.json +2 -2
- package/scripts/predist.mjs +47 -1
- package/src/app.js +77 -90
- package/src/caps.js +325 -1
- package/src/cloudsync.js +51 -7
- package/src/commands.js +114 -4
- package/src/entitlement.js +207 -1
- package/src/events.js +24 -0
- package/src/fingerprint.js +559 -0
- package/src/gate.js +45 -0
- package/src/panels.js +81 -11
- package/src/presence.js +235 -0
- package/src/screens.js +11 -4
- package/src/theme.js +126 -6
- package/vendor/client/aegis.js +180 -18
- package/vendor/client/attest.js +439 -0
- package/vendor/client/authorship-key.js +366 -0
- package/vendor/client/device-fingerprint.js +85 -3
- package/vendor/client/fingerprint.js +1061 -0
- package/vendor/client/presence-constants.js +104 -0
- package/vendor/client/presence.js +435 -0
- package/vendor/client/record-vault.js +834 -0
- package/vendor/client/touch.js +455 -0
- package/vendor/desktop/lib/local/autonomous.js +1 -0
- package/vendor/desktop/lib/local/entitlement.js +81 -0
- package/vendor/desktop/lib/local/prompt.js +6 -0
- package/vendor/desktop/lib/local/tools.js +113 -0
- package/vendor/desktop/lib/settings.js +154 -1
- package/vendor/tools/agent-gate.mjs +1063 -0
package/src/commands.js
CHANGED
|
@@ -44,10 +44,10 @@ const path = require('node:path');
|
|
|
44
44
|
const { execSync } = require('node:child_process');
|
|
45
45
|
|
|
46
46
|
const { span } = require('./screen.js');
|
|
47
|
-
const { C, BOLD, BOLD_OFF } = require('./theme.js');
|
|
47
|
+
const { C, BOLD, BOLD_OFF, THEME_TABLE, themeContradicts } = require('./theme.js');
|
|
48
48
|
// `caps.js` is dependency-free (it requires nothing), so this cannot cycle the
|
|
49
49
|
// way a `theme.js` → `art.js` → `theme.js` require would.
|
|
50
|
-
const { caps, setCaps, resetCaps, describe } = require('./caps.js');
|
|
50
|
+
const { caps, setCaps, resetCaps, describe, probeTerminalBackground } = require('./caps.js');
|
|
51
51
|
const panels = require('./panels.js');
|
|
52
52
|
const overlays = require('./overlays.js');
|
|
53
53
|
const {
|
|
@@ -69,6 +69,7 @@ const cloudsync = require('./cloudsync.js');
|
|
|
69
69
|
const { maskKey, fmtTokens } = require('./format.js');
|
|
70
70
|
const { pickerEntries } = require('./models.js');
|
|
71
71
|
const { resolveShared } = require('./sharedpaths.js');
|
|
72
|
+
const { createCliEntitlement, paymentView, probeFee } = require('./entitlement.js');
|
|
72
73
|
const { openUrl, URLS } = require('./system.js');
|
|
73
74
|
const { sniffProject, buildAegisMd } = require('./init.js');
|
|
74
75
|
const { upgradeAdvice, latestPublishedVersion } = require('./update.js');
|
|
@@ -220,6 +221,56 @@ async function runMultiCommand(c, task, { yolo = false, title = 'ÆGIS Multi' }
|
|
|
220
221
|
/** /upgrade's advice as panel rows (the advice itself is plain strings). */
|
|
221
222
|
const upgradePanelLines = (lines) => lines.map((l) => [span(C.white, l)]);
|
|
222
223
|
|
|
224
|
+
/**
|
|
225
|
+
* The paid prompt `/billing` prints, or `undefined` when it cannot be earned.
|
|
226
|
+
*
|
|
227
|
+
* WHY THIS EXISTS AS A FUNCTION. `/billing` is the one screen a user opens when
|
|
228
|
+
* they are already thinking about money, and it was the only money surface in
|
|
229
|
+
* this client that did not ask the account anything: it printed the ledger and
|
|
230
|
+
* the line "AEGIS has no subscription of its own". Both are now answered from
|
|
231
|
+
* the SAME decision the drain clamps on (`desktop/lib/local/entitlement.js`,
|
|
232
|
+
* reached through `cli/src/entitlement.js` with `host: 'cli'`), so the terminal
|
|
233
|
+
* cannot sell a plan the drain would refuse, or refuse a fan-out to a bank the
|
|
234
|
+
* panel just called funded.
|
|
235
|
+
*
|
|
236
|
+
* `force` on the refresh, deliberately: the gate's snapshot is a 60 s cache
|
|
237
|
+
* built for a drain that must not probe per task, but `/billing` is an explicit
|
|
238
|
+
* ask — "what do I owe" answered from a minute-old read is the wrong answer at
|
|
239
|
+
* exactly the moment it is being asked. One probe per `/billing`, not per task.
|
|
240
|
+
*
|
|
241
|
+
* Returns undefined rather than a guess when the gate cannot be built at all
|
|
242
|
+
* (no client, no shared module). The panel then prints its neutral top-up row.
|
|
243
|
+
* The failure direction matters: inventing a wall for an account we could not
|
|
244
|
+
* read is the one error here that costs real money — either selling Pro to
|
|
245
|
+
* someone who has it or telling a funded user their bank is empty.
|
|
246
|
+
*/
|
|
247
|
+
async function billingPayment(c) {
|
|
248
|
+
if (!c || !c.client) return undefined;
|
|
249
|
+
let gate;
|
|
250
|
+
try {
|
|
251
|
+
gate = createCliEntitlement({ aegis: c.client });
|
|
252
|
+
} catch {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
// Through the spinner when the host has one: this is a network read, and an
|
|
256
|
+
// unannounced two-second pause after `/billing` reads as a hang.
|
|
257
|
+
const run = c.withWorking ? (fn) => c.withWorking(fn) : (fn) => fn();
|
|
258
|
+
try {
|
|
259
|
+
await run(() => gate.refresh({ force: true }));
|
|
260
|
+
} catch {
|
|
261
|
+
// `refresh()` is contractually non-throwing, but a broken host could still
|
|
262
|
+
// reject; the cached (or boot) snapshot is a real read and still usable.
|
|
263
|
+
}
|
|
264
|
+
// The relay's handling fee, published by the same server the probe just
|
|
265
|
+
// talked to. Fetched here rather than in the panel because the panel is pure
|
|
266
|
+
// (and tested as such), and fetched WITHOUT `force`: a minute-old price is
|
|
267
|
+
// still the price, unlike a minute-old entitlement verdict, and this keeps
|
|
268
|
+
// `/billing` at one probe plus one cheap GET rather than two round trips to
|
|
269
|
+
// the same host.
|
|
270
|
+
const fee = await probeFee();
|
|
271
|
+
return paymentView(gate.current(), { host: 'cli', fee });
|
|
272
|
+
}
|
|
273
|
+
|
|
223
274
|
/**
|
|
224
275
|
* The pinnable-model list for the class the session is on, fetched fresh.
|
|
225
276
|
*
|
|
@@ -1216,13 +1267,24 @@ const COMMANDS = [
|
|
|
1216
1267
|
}
|
|
1217
1268
|
c.saveConfig({ themeIndex: c.ctx.themeIndex });
|
|
1218
1269
|
note(c, `Theme: ${c.ctx.light ? 'light' : 'dark'}`);
|
|
1270
|
+
// An explicit row is a real preference — the whole point of `/theme dark`
|
|
1271
|
+
// — so it is NOT overridden here, even on a terminal that will draw it
|
|
1272
|
+
// badly. It is only reported, because "my text vanished" is otherwise
|
|
1273
|
+
// indistinguishable from a crash and this is the one moment the user is
|
|
1274
|
+
// looking at the setting that caused it.
|
|
1275
|
+
const clash = themeContradicts(c.ctx.themeIndex);
|
|
1276
|
+
if (clash) {
|
|
1277
|
+
const background = caps().background;
|
|
1278
|
+
note(c, `warning: this ${background} terminal is not what "${THEME_TABLE[c.ctx.themeIndex].name}" is drawn for — body text may be unreadable.`);
|
|
1279
|
+
note(c, ` /terminal background ${background} pins the palette to this terminal, or /terminal background ${background === 'dark' ? 'light' : 'dark'} if it reads you wrong.`);
|
|
1280
|
+
}
|
|
1219
1281
|
c.render();
|
|
1220
1282
|
return true;
|
|
1221
1283
|
},
|
|
1222
1284
|
},
|
|
1223
1285
|
{
|
|
1224
1286
|
name: 'terminal', aliases: ['tty'], args: ['mode', 'mode2'],
|
|
1225
|
-
hint: '[ascii|unicode|color|no-color|star <native|narrow>|width <cols>|auto|status]', category: 'model',
|
|
1287
|
+
hint: '[ascii|unicode|color|no-color|background <dark|light>|probe|star <native|narrow>|width <cols>|auto|status]', category: 'model',
|
|
1226
1288
|
desc: 'Show or override how this terminal is drawn (mark, colour, width)',
|
|
1227
1289
|
handler: async (c, args) => {
|
|
1228
1290
|
// The same report `aegiscode --terminal` prints, and the same switch the
|
|
@@ -1247,6 +1309,8 @@ const COMMANDS = [
|
|
|
1247
1309
|
const axes = {
|
|
1248
1310
|
glyphs: cur.glyphs, face: cur.face, star: cur.star,
|
|
1249
1311
|
depth: cur.depth, vt: cur.vt, wideRunes: cur.wideRunes,
|
|
1312
|
+
background: cur.background,
|
|
1313
|
+
backgroundKnown: cur.backgroundKnown,
|
|
1250
1314
|
reasons: Object.assign({}, cur.reasons),
|
|
1251
1315
|
};
|
|
1252
1316
|
|
|
@@ -1259,6 +1323,23 @@ const COMMANDS = [
|
|
|
1259
1323
|
c.render();
|
|
1260
1324
|
return true;
|
|
1261
1325
|
}
|
|
1326
|
+
if (sub === 'probe') {
|
|
1327
|
+
// Ask the terminal outright (OSC 11) and use its own answer. This is
|
|
1328
|
+
// the same query the session runs once at startup, exposed because the
|
|
1329
|
+
// one case it cannot handle is a terminal that started reporting
|
|
1330
|
+
// differently afterwards — a terminal theme switched mid-session — and
|
|
1331
|
+
// because "what does my terminal say it is?" is the first question a
|
|
1332
|
+
// mis-rendered screen raises.
|
|
1333
|
+
const probed = await probeTerminalBackground();
|
|
1334
|
+
screens.applyTheme(c.ctx, c.ctx.themeIndex);
|
|
1335
|
+
note(c, probed.known
|
|
1336
|
+
? `Terminal: background ${probed.background} (${probed.reason}) — /theme auto follows it.`
|
|
1337
|
+
: `Terminal: no answer to the background query (${probed.reason}).`);
|
|
1338
|
+
note(c, ' /terminal background dark|light pins it without asking.');
|
|
1339
|
+
panel(c, panels.buildTerminalCaps(describe(), { pinned: !!caps().pinned }));
|
|
1340
|
+
c.render();
|
|
1341
|
+
return true;
|
|
1342
|
+
}
|
|
1262
1343
|
// `why` in the report must describe what the session is actually doing,
|
|
1263
1344
|
// not the probe it started from: after `/terminal ascii` on a truecolor
|
|
1264
1345
|
// host, `why: TERM=xterm-256color` would contradict `mark: ascii`.
|
|
@@ -1275,6 +1356,23 @@ const COMMANDS = [
|
|
|
1275
1356
|
if (!['native', 'narrow'].includes(want)) { note(c, 'Usage: /terminal star <native|narrow>'); c.render(); return true; }
|
|
1276
1357
|
axes.star = want;
|
|
1277
1358
|
if (axes.reasons) axes.reasons.star = `/terminal star ${want}`;
|
|
1359
|
+
} else if (sub === 'background' || sub === 'bg') {
|
|
1360
|
+
// The one axis that is not about drawing: it says which of the two
|
|
1361
|
+
// legible palettes "Auto (match terminal)" resolves to, for a terminal
|
|
1362
|
+
// that reports nothing about itself (or reports it wrong). Pinning it
|
|
1363
|
+
// here is the same decision `AEGIS_BACKGROUND` makes at launch, so a
|
|
1364
|
+
// user on a light terminal can fix an invisible UI without restarting.
|
|
1365
|
+
const want = second.toLowerCase();
|
|
1366
|
+
if (!['dark', 'light'].includes(want)) { note(c, 'Usage: /terminal background <dark|light>'); c.render(); return true; }
|
|
1367
|
+
axes.background = want;
|
|
1368
|
+
axes.backgroundKnown = true;
|
|
1369
|
+
if (axes.reasons) axes.reasons.background = `/terminal background ${want}`;
|
|
1370
|
+
setCaps(Object.assign({}, axes));
|
|
1371
|
+
screens.applyTheme(c.ctx, c.ctx.themeIndex);
|
|
1372
|
+
note(c, `Terminal: background pinned to ${want} — /theme auto follows it.`);
|
|
1373
|
+
panel(c, panels.buildTerminalCaps(describe(), { pinned: !!caps().pinned }));
|
|
1374
|
+
c.render();
|
|
1375
|
+
return true;
|
|
1278
1376
|
} else if (sub === 'width') {
|
|
1279
1377
|
// A pinned width is a frame override, so it goes in as cols — the one
|
|
1280
1378
|
// key that deliberately trips `sizePinned`.
|
|
@@ -1286,7 +1384,7 @@ const COMMANDS = [
|
|
|
1286
1384
|
c.render();
|
|
1287
1385
|
return true;
|
|
1288
1386
|
} else {
|
|
1289
|
-
note(c, 'Usage: /terminal [ascii|unicode|color|no-color|star <native|narrow>|width <cols>|auto|status]');
|
|
1387
|
+
note(c, 'Usage: /terminal [ascii|unicode|color|no-color|background <dark|light>|probe|star <native|narrow>|width <cols>|auto|status]');
|
|
1290
1388
|
c.render();
|
|
1291
1389
|
return true;
|
|
1292
1390
|
}
|
|
@@ -1910,6 +2008,18 @@ const COMMANDS = [
|
|
|
1910
2008
|
panel(c, panels.buildBilling({
|
|
1911
2009
|
...st,
|
|
1912
2010
|
balance: spend && spend.balance != null ? spend.balance : st.balance,
|
|
2011
|
+
// The paid prompt, from the SAME gate that decides the fan-out. This is
|
|
2012
|
+
// the whole reason `/billing` can be trusted to say what Pro costs: the
|
|
2013
|
+
// verdict and the ceiling come from one decision (`is_pro` mirrored by
|
|
2014
|
+
// the shared module) instead of a second, panel-local guess about the
|
|
2015
|
+
// account — two readings is how a screen ends up selling Pro to someone
|
|
2016
|
+
// who owns it, or telling a paying customer their bank is empty.
|
|
2017
|
+
//
|
|
2018
|
+
// A probe that cannot be built (no shared module, no client) leaves the
|
|
2019
|
+
// field unset: the panel then prints its plain top-up row rather than an
|
|
2020
|
+
// unverified pitch. Never the reverse — a failure here must not invent
|
|
2021
|
+
// a wall.
|
|
2022
|
+
payment: await billingPayment(c),
|
|
1913
2023
|
}, c.ctx));
|
|
1914
2024
|
c.render();
|
|
1915
2025
|
return true;
|
package/src/entitlement.js
CHANGED
|
@@ -105,4 +105,210 @@ function createCliEntitlement({ aegis, now, ttlMs } = {}) {
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
// ── the payment surface ─────────────────────────────────────────────────────
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The copy every paid prompt in this host prints, read from the SHARED module
|
|
112
|
+
* when it resolves and from a frozen literal when it does not.
|
|
113
|
+
*
|
|
114
|
+
* Why a fallback at all: `loadModule()` requires a file that exists in a source
|
|
115
|
+
* checkout and in the `predist` staging tree, but the CLI also ships as an npm
|
|
116
|
+
* tarball where the shared modules live under `vendor/` — and a `/billing`
|
|
117
|
+
* panel that threw on a lookup would take the whole command down rather than
|
|
118
|
+
* show a user the one screen that can take their money. The literals below are
|
|
119
|
+
* therefore a COPY of the shared constants, and `test/cli-billing-payment.test.mjs`
|
|
120
|
+
* asserts copy === shared module so the copy cannot drift silently; if the
|
|
121
|
+
* shared module resolves, its strings win and the literal is never printed.
|
|
122
|
+
*/
|
|
123
|
+
const FALLBACK_COPY = Object.freeze({
|
|
124
|
+
paidReason: 'Pro puts the drain in the cloud, so the job keeps running after you close the laptop',
|
|
125
|
+
honesty:
|
|
126
|
+
'Everything on your machine is free, permanently. The cloud drain is what you pay for.',
|
|
127
|
+
ask: 'Do X autonomously',
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
/** The two walls, and the campaign id each one owns. Same ids the plan fixed
|
|
131
|
+
* (`status_card` for "an account prompt on a status/billing surface",
|
|
132
|
+
* `topup_bank` for the bank running dry) and the same ones aegis1 accepts. */
|
|
133
|
+
const BILLING_WALL = Object.freeze({ campaign: 'status_card', page: 'upgrade' });
|
|
134
|
+
const BALANCE_WALL = Object.freeze({ campaign: 'topup_bank', page: 'topup' });
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The shared module, or undefined — resolved once and remembered, because
|
|
138
|
+
* `/billing` is a hot path for a user staring at a wall and a filesystem probe
|
|
139
|
+
* per panel render buys nothing. A `require` that throws is cached as
|
|
140
|
+
* undefined; the literals above are the answer from then on.
|
|
141
|
+
*/
|
|
142
|
+
let sharedCache;
|
|
143
|
+
function shared() {
|
|
144
|
+
if (sharedCache !== undefined) return sharedCache || undefined;
|
|
145
|
+
try {
|
|
146
|
+
sharedCache = loadModule();
|
|
147
|
+
} catch {
|
|
148
|
+
sharedCache = null;
|
|
149
|
+
}
|
|
150
|
+
return sharedCache || undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The sentences a paid prompt prints, shared-first. */
|
|
154
|
+
function paymentCopy() {
|
|
155
|
+
const mod = shared();
|
|
156
|
+
return {
|
|
157
|
+
paidReason: str(mod && mod.PRO_VALUE, FALLBACK_COPY.paidReason),
|
|
158
|
+
honesty: str(mod && mod.FREE_HONESTY, FALLBACK_COPY.honesty),
|
|
159
|
+
ask: str(mod && mod.ASK_EXAMPLE, FALLBACK_COPY.ask),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function str(v, fallback) {
|
|
164
|
+
const s = v == null ? '' : String(v);
|
|
165
|
+
return s.trim() ? s : fallback;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The campaign-tagged link a wall sends someone to. Built here rather than in
|
|
170
|
+
* `panels.js` so the channel is `s=cli` by construction: the shared module's
|
|
171
|
+
* own URL literals hardcode `s=desktop` (they predate the host seam), and
|
|
172
|
+
* printing one from a terminal would file every terminal click as a desktop
|
|
173
|
+
* conversion — the silent zero `/go/` exists to prevent.
|
|
174
|
+
*
|
|
175
|
+
* `goUrl` is preferred when the shared module resolves (one implementation, and
|
|
176
|
+
* it validates the channel against aegis1's accepted set); the fallback spells
|
|
177
|
+
* the same URL for hosts that cannot resolve it.
|
|
178
|
+
*/
|
|
179
|
+
function paymentUrl(wall) {
|
|
180
|
+
const mod = shared();
|
|
181
|
+
if (mod && typeof mod.goUrl === 'function') {
|
|
182
|
+
try {
|
|
183
|
+
return mod.goUrl(wall.page, wall.campaign, 'cli');
|
|
184
|
+
} catch {
|
|
185
|
+
// Fall through to the literal below — a link is better than a throw.
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return `https://aegiscloud.org/go/${wall.page}?s=cli&c=${wall.campaign}`;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The payment view for a surface that is allowed to ask: plain data, formatted
|
|
193
|
+
* by `panels.buildBilling` which stays pure (it renders what it is handed and
|
|
194
|
+
* never probes).
|
|
195
|
+
*
|
|
196
|
+
* `snapshot` is the shared gate's `current()`. The verdict is read through the
|
|
197
|
+
* MODULE's own rules — `entitled` is `pro || banked` — so this host cannot
|
|
198
|
+
* arrive at a different answer than the drain does about who owes money. The
|
|
199
|
+
* only branch taken here is which WALL the user is in front of, and that is the
|
|
200
|
+
* module's own `wall` field:
|
|
201
|
+
*
|
|
202
|
+
* entitled → the offer is already owned; state it, ask nothing
|
|
203
|
+
* wall === 'balance' → the bank ran dry: top up (campaign `topup_bank`)
|
|
204
|
+
* anything else / free → Pro (campaign `status_card`)
|
|
205
|
+
*
|
|
206
|
+
* `degraded` (no real answer: timeout, no key, unreadable body) still renders
|
|
207
|
+
* the offer — the panel is allowed to sell — but it is reported as `verified:
|
|
208
|
+
* false` so the caller can say the verdict was not confirmed rather than
|
|
209
|
+
* presenting a timeout as a fact about the account.
|
|
210
|
+
*/
|
|
211
|
+
/**
|
|
212
|
+
* The BYOK handling fee, as the TERMINAL renders it.
|
|
213
|
+
*
|
|
214
|
+
* Formatting only — the words and the numbers both come from one place: the
|
|
215
|
+
* rate is aegis1's published payload (never a literal here, or the two hosts
|
|
216
|
+
* drift from the ledger), and the sentence is the shared module's
|
|
217
|
+
* `byokFeeLine`, so the GUI and the terminal cannot describe the relay's price
|
|
218
|
+
* differently. `line === ''` means "no published fee" and every caller must
|
|
219
|
+
* then say nothing at all rather than guess.
|
|
220
|
+
*/
|
|
221
|
+
function feeView(fee) {
|
|
222
|
+
const f = fee && typeof fee === 'object' ? fee : null;
|
|
223
|
+
let line = '';
|
|
224
|
+
try {
|
|
225
|
+
const mod = loadModule();
|
|
226
|
+
if (typeof mod.byokFeeLine === 'function') line = String(mod.byokFeeLine(f) || '');
|
|
227
|
+
} catch {
|
|
228
|
+
// No shared module (staged tree without the host payload): silence, which
|
|
229
|
+
// is the honest reading of "this host cannot price the lane right now".
|
|
230
|
+
line = '';
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
line,
|
|
234
|
+
published: line !== '',
|
|
235
|
+
// Enforcement, not price. A host that knows the relay demands an account
|
|
236
|
+
// can say so before the user meets the 402 instead of after.
|
|
237
|
+
accountRequired: !!(f && f.require_account === true),
|
|
238
|
+
anonymousDailyCalls: f && Number.isFinite(Number(f.anonymous_daily_calls))
|
|
239
|
+
? Number(f.anonymous_daily_calls) : 0,
|
|
240
|
+
gateMode: f && typeof f.gate_mode === 'string' ? f.gate_mode : '',
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Fetch the server's published BYOK fee. Non-throwing, and offline it returns
|
|
246
|
+
* null — the fee is disclosure, not a gate, so a failed read must not turn
|
|
247
|
+
* `/billing` into an error the user has to interpret.
|
|
248
|
+
*/
|
|
249
|
+
async function probeFee() {
|
|
250
|
+
try {
|
|
251
|
+
const client = loadClient();
|
|
252
|
+
if (!client || typeof client.byokProviders !== 'function') return null;
|
|
253
|
+
const data = await client.byokProviders();
|
|
254
|
+
return (data && data.fee) || null;
|
|
255
|
+
} catch {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function paymentView(snapshot, { host = 'cli', fee = null } = {}) {
|
|
261
|
+
const copy = paymentCopy();
|
|
262
|
+
const snap = snapshot && typeof snapshot === 'object' ? snapshot : {};
|
|
263
|
+
const entitled = snap.entitled === true;
|
|
264
|
+
const feeLine = feeView(fee).line;
|
|
265
|
+
const wall = entitled ? 'owned' : snap.wall === 'balance' ? 'balance' : 'plan';
|
|
266
|
+
const which = wall === 'balance' ? BALANCE_WALL : BILLING_WALL;
|
|
267
|
+
return {
|
|
268
|
+
host,
|
|
269
|
+
wall,
|
|
270
|
+
entitled,
|
|
271
|
+
// "The module actually answered." `degraded` is the module's own flag for
|
|
272
|
+
// "no real answer" (timeout, no plan field, no probe), and it must ALSO have
|
|
273
|
+
// named where the verdict came from — an unresolved boot snapshot has
|
|
274
|
+
// `degraded === false` only because nothing ever ran, and reporting that as
|
|
275
|
+
// verified would present "we never asked" as a fact about the account.
|
|
276
|
+
// Derived from the module's two fields rather than from the plan string, so
|
|
277
|
+
// this host never re-decides what counts as knowledge.
|
|
278
|
+
verified: snap.degraded === false && typeof snap.source === 'string' && snap.source !== '',
|
|
279
|
+
plan: snap.plan ? String(snap.plan) : 'free',
|
|
280
|
+
paid: entitled,
|
|
281
|
+
reason: copy.paidReason,
|
|
282
|
+
honesty: copy.honesty,
|
|
283
|
+
ask: copy.ask,
|
|
284
|
+
// No link once the offer is owned: a paying customer being sold the thing
|
|
285
|
+
// they already bought is the one prompt that can only lose money.
|
|
286
|
+
url: entitled ? '' : paymentUrl(which),
|
|
287
|
+
campaign: entitled ? '' : which.campaign,
|
|
288
|
+
// The BYOK lane's price, from the server's own published rate. Empty when
|
|
289
|
+
// the server published none — never a client-side guess (see the shared
|
|
290
|
+
// module's byokFeeLine). This is the sentence that closes the one place the
|
|
291
|
+
// bill and the pitch disagreed: a user was told BYOK costs "your provider's
|
|
292
|
+
// cost" while aegis1 charged a handling fee on top of it.
|
|
293
|
+
byok: feeLine,
|
|
294
|
+
label: entitled ? 'Pro' : wall === 'balance' ? 'Top up' : 'Upgrade',
|
|
295
|
+
unlock:
|
|
296
|
+
wall === 'balance'
|
|
297
|
+
? 'Unlock: top up the Token Bank, or upgrade to Pro'
|
|
298
|
+
: 'Unlock: Pro, or any Token Bank balance',
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
module.exports = {
|
|
303
|
+
createCliEntitlement,
|
|
304
|
+
buildProbe,
|
|
305
|
+
loadModule,
|
|
306
|
+
paymentView,
|
|
307
|
+
paymentCopy,
|
|
308
|
+
feeView,
|
|
309
|
+
probeFee,
|
|
310
|
+
paymentUrl,
|
|
311
|
+
FALLBACK_COPY,
|
|
312
|
+
BILLING_WALL,
|
|
313
|
+
BALANCE_WALL,
|
|
314
|
+
};
|
package/src/events.js
CHANGED
|
@@ -119,6 +119,29 @@ function flushPaste() {
|
|
|
119
119
|
if (text) dispatch({ name: 'paste', text });
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Feed bytes that were read off the terminal by something *other* than this
|
|
124
|
+
* pump, as if they had arrived here.
|
|
125
|
+
*
|
|
126
|
+
* The startup background query (`caps.probeBackground`) is the caller: it must
|
|
127
|
+
* read stdin to see the terminal's answer (OSC 11), and a keypress can race the
|
|
128
|
+
* reply into the same read. Bytes it consumed are not lost — it hands them back
|
|
129
|
+
* here, and they take the identical path (`pushChars`) a `data` event would
|
|
130
|
+
* have taken, so the pump's parsing, paste handling and key queue all see them
|
|
131
|
+
* in order.
|
|
132
|
+
*
|
|
133
|
+
* This exists because the alternative — putting the bytes back on the stream
|
|
134
|
+
* (`stdin.unshift`) — is not lossless: `script`/`spawnSync` closes the write end
|
|
135
|
+
* immediately after sending a command, so by the time the probe's deadline
|
|
136
|
+
* expires stdin has already emitted `end` and the unshifted bytes are never
|
|
137
|
+
* delivered. The parked `nextKey()` then waits forever for a command it never
|
|
138
|
+
* receives. This runs through the queue instead, which `drainQueue`/`nextKey`
|
|
139
|
+
* consult regardless of the stream's state.
|
|
140
|
+
*/
|
|
141
|
+
function feedKeys(text) {
|
|
142
|
+
if (text) pushChars(String(text));
|
|
143
|
+
}
|
|
144
|
+
|
|
122
145
|
function pushChars(s) {
|
|
123
146
|
const framed = s.match(/^\x1b\[200~(.*)\x1b\[201~$/s);
|
|
124
147
|
if (framed) {
|
|
@@ -357,6 +380,7 @@ module.exports = {
|
|
|
357
380
|
// it can't pin it.
|
|
358
381
|
parseSgrMouse,
|
|
359
382
|
attachKeyStream,
|
|
383
|
+
feedKeys,
|
|
360
384
|
suspendKeyStream,
|
|
361
385
|
resumeKeyStream,
|
|
362
386
|
isKeyStreamSuspended,
|