aegiscode 7.0.13 → 7.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SOURCE-OFFER.txt +9 -0
- package/package.json +3 -2
- package/scripts/check.mjs +1 -52
- package/scripts/demo.mjs +1 -94
- package/scripts/predist.mjs +1 -75
- package/scripts/runtests.mjs +1 -56
- package/scripts/seal-gate.mjs +1 -74
- package/src/agents.js +1 -139
- package/src/app.js +1 -2932
- package/src/art.js +1 -289
- package/src/chatflow.js +1 -3008
- package/src/checkpoint.js +1 -90
- package/src/clipboard.js +1 -424
- package/src/cloudsync.js +1 -528
- package/src/commands.js +1 -3987
- package/src/config.js +1 -581
- package/src/connect.js +1 -349
- package/src/credentials.js +1 -33
- package/src/deps.js +1 -232
- package/src/devrun.js +1 -187
- package/src/diff.js +1 -333
- package/src/diffview.js +1 -296
- package/src/engine.js +1 -297
- package/src/entitlement.js +1 -355
- package/src/events.js +1 -707
- package/src/export.js +1 -67
- package/src/fingerprint.js +1 -592
- package/src/format.js +1 -259
- package/src/fuzzy.js +1 -119
- package/src/history.js +1 -401
- package/src/init.js +1 -175
- package/src/input.js +1 -139
- package/src/keys.js +1 -183
- package/src/markdown.js +1 -306
- package/src/models.js +1 -487
- package/src/naming.js +1 -229
- package/src/overlays.js +1 -461
- package/src/panels.js +1 -1418
- package/src/ping.js +1 -226
- package/src/presence.js +1 -238
- package/src/render.js +1 -515
- package/src/screen.js +1 -518
- package/src/screens.js +1 -896
- package/src/secret.js +1 -59
- package/src/securefs.js +1 -359
- package/src/settings.js +1 -155
- package/src/shared.js +1 -52
- package/src/sharedpaths.js +1 -53
- package/src/signup.js +1 -156
- package/src/summarize.js +1 -95
- package/src/sysdiag.js +1 -585
- package/src/system.js +1 -40
- package/src/theme.js +1 -570
- package/src/title.js +1 -220
- package/src/todos.js +1 -115
- package/src/tokens.js +1 -263
- package/src/topup.js +1 -210
- package/src/update.js +1 -181
- package/vendor/client/aegis.js +1 -2054
- package/vendor/client/attest.js +1 -442
- package/vendor/client/authorship-key.js +1 -410
- package/vendor/client/auto-provision.js +1 -134
- package/vendor/client/brain-catalog.js +1 -268
- package/vendor/client/byok-catalog.js +1 -230
- package/vendor/client/credentials.js +1 -494
- package/vendor/client/device-fingerprint.js +1 -141
- package/vendor/client/drive-connect.js +1 -85
- package/vendor/client/drive-upload.js +1 -174
- package/vendor/client/env-file.js +1 -1273
- package/vendor/client/fingerprint.js +1 -1064
- package/vendor/client/foreign-memory.js +1 -669
- package/vendor/client/google-signin.js +1 -125
- package/vendor/client/hooks.js +1 -430
- package/vendor/client/model-discovery.js +1 -330
- package/vendor/client/platform.js +1 -937
- package/vendor/client/prefs.js +1 -351
- package/vendor/client/presence-constants.js +1 -107
- package/vendor/client/presence.js +1 -438
- package/vendor/client/record-vault.js +3 -1055
- package/vendor/client/session-store.js +1 -548
- package/vendor/client/topup.js +1 -297
- package/vendor/client/touch.js +1 -458
- package/vendor/client/update.js +1 -704
- package/vendor/client/user-models.js +1 -381
- package/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/desktop/lib/local/claude-pro.js +1 -993
- package/vendor/desktop/lib/local/context.js +1 -95
- package/vendor/desktop/lib/local/engine.js +1 -3228
- package/vendor/desktop/lib/local/entitlement.js +1 -654
- package/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/desktop/lib/local/local.js +1 -2135
- package/vendor/desktop/lib/local/prompt.js +1 -275
- package/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/desktop/lib/local/session-rounds.js +1 -208
- package/vendor/desktop/lib/local/shell.js +1 -680
- package/vendor/desktop/lib/local/tools.js +1 -1238
- package/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/desktop/lib/settings.js +1 -890
- package/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/hosts/install.js +1 -638
- package/vendor/hosts/openai-shim.js +1 -515
- package/vendor/hosts/spec.js +1 -164
- package/vendor/hosts/targets.js +1 -346
- package/vendor/mcp/server.js +1 -221
- package/vendor/mcp/tools.js +1 -408
- package/vendor/one/src/child.js +1 -285
- package/vendor/one/src/permissions.js +1 -369
package/src/entitlement.js
CHANGED
|
@@ -1,357 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
4
|
-
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
-
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* entitlement.js — the terminal host's binding to the SHARED Pro gate.
|
|
10
|
-
*
|
|
11
|
-
* WHY THIS FILE EXISTS (and why it is six lines of real work). The gate that
|
|
12
|
-
* decides who may spend the fan-out lives in
|
|
13
|
-
* `desktop/lib/local/entitlement.js`, and the CLI has been the leak since the
|
|
14
|
-
* day it landed: `autonomous.js` drives the SAME queue file through the SAME
|
|
15
|
-
* worker, `createWorker` takes a `canFanOut` predicate, and the CLI simply
|
|
16
|
-
* never passed one — so it defaulted to `() => true`. A task queued with
|
|
17
|
-
* `--workers 8` or written into queue.jsonl by hand fans out on the free tier
|
|
18
|
-
* from `ssh box 'aegiscode autonomous proceed'`, costing the multiplier the
|
|
19
|
-
* gate exists to withhold, with no window and nobody to ask.
|
|
20
|
-
*
|
|
21
|
-
* The desktop's own comment named this as a known gap ("the CLI's own drain is
|
|
22
|
-
* a different host with no session to ask"). It had a session — it has the same
|
|
23
|
-
* account key in the same 0600 store, read through the same shared client. It
|
|
24
|
-
* was a wiring omission, not an architectural one.
|
|
25
|
-
*
|
|
26
|
-
* TWO THINGS ARE HOST-SPECIFIC, and both are handled by the shared module's own
|
|
27
|
-
* seams rather than reimplemented here:
|
|
28
|
-
*
|
|
29
|
-
* 1. THE CHANNEL. `host: 'cli'` makes every refusal link
|
|
30
|
-
* `/go/upgrade?s=cli&…`, so a terminal click is filed as a CLI conversion
|
|
31
|
-
* instead of a desktop one. The desktop's literals hardcode `s=desktop`;
|
|
32
|
-
* printing one from the terminal would have quietly moved every CLI
|
|
33
|
-
* conversion into the desktop's column.
|
|
34
|
-
* 2. THE PROBE. The CLI has no Electron session, so it builds the same
|
|
35
|
-
* reading the desktop builds — `verifyApiKey()` for the plan plus
|
|
36
|
-
* `tokenBankBalance()` for the operator's balance — from the shared client
|
|
37
|
-
* directly.
|
|
38
|
-
*
|
|
39
|
-
* Not reimplemented, deliberately: the plan vocabulary, the balance
|
|
40
|
-
* interpretation, the fail-closed rules, the refusal copy, the campaign ids.
|
|
41
|
-
* Two implementations of "is this account paid" is exactly how the terminal and
|
|
42
|
-
* the GUI would come to disagree about who owes money — and the disagreement
|
|
43
|
-
* would spend real money, in whichever host had the looser copy.
|
|
44
|
-
*
|
|
45
|
-
* Wired through `sharedpaths.js` (paths, no eager requires) rather than
|
|
46
|
-
* `deps.js`, because `deps.js` eagerly loads `autonomous.js`, which loads THIS
|
|
47
|
-
* file back: requiring deps.js here would be a require cycle handing one side a
|
|
48
|
-
* half-built exports object. Same reason `sharedpaths.js` was split out.
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
const { resolveShared } = require('./sharedpaths.js');
|
|
52
|
-
// The renderers' waiver rule, published to on every reading this gate takes —
|
|
53
|
-
// see `createCliEntitlement` below. `format.js` requires nothing from here, so
|
|
54
|
-
// this is a one-way edge and not a cycle.
|
|
55
|
-
const { noteTier } = require('./format.js');
|
|
56
|
-
|
|
57
|
-
/** The shared decision, resolved by existence (repo checkout or staged tree). */
|
|
58
|
-
function loadModule() {
|
|
59
|
-
// eslint-disable-next-line global-require
|
|
60
|
-
return require(resolveShared('desktop/lib/local/entitlement.js'));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** The shared thin transport, same two-layout resolution as deps.js. */
|
|
64
|
-
function loadClient() {
|
|
65
|
-
// eslint-disable-next-line global-require
|
|
66
|
-
const { createClient } = require(resolveShared('client/aegis.js'));
|
|
67
|
-
const credentials = require('./credentials.js');
|
|
68
|
-
return createClient(credentials.clientOptions({ channel: 'cli' }));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* The account probe, shaped exactly as the desktop builds it.
|
|
73
|
-
*
|
|
74
|
-
* A failed balance call leaves the balance UNKNOWN rather than inventing a
|
|
75
|
-
* zero: an unreadable bank must never manufacture a top-up prompt, and
|
|
76
|
-
* `classifyProbe` fails closed on the unknown anyway. Both calls are read-only
|
|
77
|
-
* and neither writes server-side — the gate observes the operator's number, it
|
|
78
|
-
* never sets one.
|
|
79
|
-
*/
|
|
80
|
-
function buildProbe(aegis) {
|
|
81
|
-
if (!aegis || typeof aegis.verifyApiKey !== 'function') return undefined;
|
|
82
|
-
return async () => {
|
|
83
|
-
const verify = await aegis.verifyApiKey();
|
|
84
|
-
const body = verify && typeof verify === 'object' ? { ...verify } : {};
|
|
85
|
-
if (typeof aegis.tokenBankBalance === 'function') {
|
|
86
|
-
try {
|
|
87
|
-
const bank = await aegis.tokenBankBalance();
|
|
88
|
-
if (bank && typeof bank === 'object') {
|
|
89
|
-
if (bank.balance_micros != null) body.balance_micros = bank.balance_micros;
|
|
90
|
-
else if (bank.balance_eur != null) body.balance_eur = bank.balance_eur;
|
|
91
|
-
}
|
|
92
|
-
} catch {
|
|
93
|
-
// Unknown stays unknown — see the docstring above.
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return body;
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* The gate for one CLI process, reading the SAME account the desktop reads.
|
|
102
|
-
*
|
|
103
|
-
* `host: 'cli'` is the whole reason campaign links can be trusted from here.
|
|
104
|
-
* Returns the shared gate object: `{ refresh, current, gateFanout }`.
|
|
105
|
-
*/
|
|
106
|
-
function createCliEntitlement({ aegis, now, ttlMs } = {}) {
|
|
107
|
-
const mod = loadModule();
|
|
108
|
-
const client = aegis || loadClient();
|
|
109
|
-
const gate = mod.createEntitlement({
|
|
110
|
-
probe: buildProbe(client),
|
|
111
|
-
host: 'cli',
|
|
112
|
-
...(now ? { now } : {}),
|
|
113
|
-
...(ttlMs ? { ttlMs } : {}),
|
|
114
|
-
});
|
|
115
|
-
// Publish every reading this gate takes to the renderers' waiver rule
|
|
116
|
-
// (`format.js` → `feeWaived`). The gate is what decides whether a turn is
|
|
117
|
-
// ALLOWED; the waiver decides whether a `€0.0031` is PRINTED under it, and the
|
|
118
|
-
// two reading different tiers is how a trial account ended up shown a fee it
|
|
119
|
-
// does not owe. Wrapping the instance rather than returning a copy keeps the
|
|
120
|
-
// method identity the rest of the host already holds a reference to.
|
|
121
|
-
if (gate && typeof gate.current === 'function') {
|
|
122
|
-
const read = gate.current.bind(gate);
|
|
123
|
-
try {
|
|
124
|
-
gate.current = (...args) => {
|
|
125
|
-
const snap = read(...args);
|
|
126
|
-
noteTier(snap);
|
|
127
|
-
return snap;
|
|
128
|
-
};
|
|
129
|
-
if (typeof gate.refresh === 'function') {
|
|
130
|
-
const refresh = gate.refresh.bind(gate);
|
|
131
|
-
gate.refresh = async (...args) => {
|
|
132
|
-
const out = await refresh(...args);
|
|
133
|
-
try { noteTier(read()); } catch { /* a failed read publishes nothing */ }
|
|
134
|
-
return out;
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
} catch { /* a frozen instance is readable, just not publishable */ }
|
|
138
|
-
}
|
|
139
|
-
return gate;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// ── the payment surface ─────────────────────────────────────────────────────
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* The copy every paid prompt in this host prints, read from the SHARED module
|
|
146
|
-
* when it resolves and from a frozen literal when it does not.
|
|
147
|
-
*
|
|
148
|
-
* Why a fallback at all: `loadModule()` requires a file that exists in a source
|
|
149
|
-
* checkout and in the `predist` staging tree, but the CLI also ships as an npm
|
|
150
|
-
* tarball where the shared modules live under `vendor/` — and a `/billing`
|
|
151
|
-
* panel that threw on a lookup would take the whole command down rather than
|
|
152
|
-
* show a user the one screen that can take their money. The literals below are
|
|
153
|
-
* therefore a COPY of the shared constants, and `test/cli-billing-payment.test.mjs`
|
|
154
|
-
* asserts copy === shared module so the copy cannot drift silently; if the
|
|
155
|
-
* shared module resolves, its strings win and the literal is never printed.
|
|
156
|
-
*/
|
|
157
|
-
const FALLBACK_COPY = Object.freeze({
|
|
158
|
-
paidReason: 'Pro puts the drain in the cloud, so the job keeps running after you close the laptop',
|
|
159
|
-
honesty:
|
|
160
|
-
'Everything on your machine is free, permanently. The cloud drain is what you pay for.',
|
|
161
|
-
ask: 'Do X autonomously',
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
/** The two walls, and the campaign id each one owns. Same ids the plan fixed
|
|
165
|
-
* (`status_card` for "an account prompt on a status/billing surface",
|
|
166
|
-
* `topup_bank` for the bank running dry) and the same ones aegis1 accepts. */
|
|
167
|
-
const BILLING_WALL = Object.freeze({ campaign: 'status_card', page: 'upgrade' });
|
|
168
|
-
const BALANCE_WALL = Object.freeze({ campaign: 'topup_bank', page: 'topup' });
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* The shared module, or undefined — resolved once and remembered, because
|
|
172
|
-
* `/billing` is a hot path for a user staring at a wall and a filesystem probe
|
|
173
|
-
* per panel render buys nothing. A `require` that throws is cached as
|
|
174
|
-
* undefined; the literals above are the answer from then on.
|
|
175
|
-
*/
|
|
176
|
-
let sharedCache;
|
|
177
|
-
function shared() {
|
|
178
|
-
if (sharedCache !== undefined) return sharedCache || undefined;
|
|
179
|
-
try {
|
|
180
|
-
sharedCache = loadModule();
|
|
181
|
-
} catch {
|
|
182
|
-
sharedCache = null;
|
|
183
|
-
}
|
|
184
|
-
return sharedCache || undefined;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/** The sentences a paid prompt prints, shared-first. */
|
|
188
|
-
function paymentCopy() {
|
|
189
|
-
const mod = shared();
|
|
190
|
-
return {
|
|
191
|
-
paidReason: str(mod && mod.PRO_VALUE, FALLBACK_COPY.paidReason),
|
|
192
|
-
honesty: str(mod && mod.FREE_HONESTY, FALLBACK_COPY.honesty),
|
|
193
|
-
ask: str(mod && mod.ASK_EXAMPLE, FALLBACK_COPY.ask),
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function str(v, fallback) {
|
|
198
|
-
const s = v == null ? '' : String(v);
|
|
199
|
-
return s.trim() ? s : fallback;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* The campaign-tagged link a wall sends someone to. Built here rather than in
|
|
204
|
-
* `panels.js` so the channel is `s=cli` by construction: the shared module's
|
|
205
|
-
* own URL literals hardcode `s=desktop` (they predate the host seam), and
|
|
206
|
-
* printing one from a terminal would file every terminal click as a desktop
|
|
207
|
-
* conversion — the silent zero `/go/` exists to prevent.
|
|
208
|
-
*
|
|
209
|
-
* `goUrl` is preferred when the shared module resolves (one implementation, and
|
|
210
|
-
* it validates the channel against aegis1's accepted set); the fallback spells
|
|
211
|
-
* the same URL for hosts that cannot resolve it.
|
|
212
|
-
*/
|
|
213
|
-
function paymentUrl(wall) {
|
|
214
|
-
const mod = shared();
|
|
215
|
-
if (mod && typeof mod.goUrl === 'function') {
|
|
216
|
-
try {
|
|
217
|
-
return mod.goUrl(wall.page, wall.campaign, 'cli');
|
|
218
|
-
} catch {
|
|
219
|
-
// Fall through to the literal below — a link is better than a throw.
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return `https://aegiscloud.org/go/${wall.page}?s=cli&c=${wall.campaign}`;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* The payment view for a surface that is allowed to ask: plain data, formatted
|
|
227
|
-
* by `panels.buildBilling` which stays pure (it renders what it is handed and
|
|
228
|
-
* never probes).
|
|
229
|
-
*
|
|
230
|
-
* `snapshot` is the shared gate's `current()`. The verdict is read through the
|
|
231
|
-
* MODULE's own rules — `entitled` is `pro || banked` — so this host cannot
|
|
232
|
-
* arrive at a different answer than the drain does about who owes money. The
|
|
233
|
-
* only branch taken here is which WALL the user is in front of, and that is the
|
|
234
|
-
* module's own `wall` field:
|
|
235
|
-
*
|
|
236
|
-
* entitled → the offer is already owned; state it, ask nothing
|
|
237
|
-
* wall === 'balance' → the bank ran dry: top up (campaign `topup_bank`)
|
|
238
|
-
* anything else / free → Pro (campaign `status_card`)
|
|
239
|
-
*
|
|
240
|
-
* `degraded` (no real answer: timeout, no key, unreadable body) still renders
|
|
241
|
-
* the offer — the panel is allowed to sell — but it is reported as `verified:
|
|
242
|
-
* false` so the caller can say the verdict was not confirmed rather than
|
|
243
|
-
* presenting a timeout as a fact about the account.
|
|
244
|
-
*/
|
|
245
|
-
/**
|
|
246
|
-
* The BYOK handling fee, as the TERMINAL renders it.
|
|
247
|
-
*
|
|
248
|
-
* Formatting only — the words and the numbers both come from one place: the
|
|
249
|
-
* rate is aegis1's published payload (never a literal here, or the two hosts
|
|
250
|
-
* drift from the ledger), and the sentence is the shared module's
|
|
251
|
-
* `byokFeeLine`, so the GUI and the terminal cannot describe the relay's price
|
|
252
|
-
* differently. `line === ''` means "no published fee" and every caller must
|
|
253
|
-
* then say nothing at all rather than guess.
|
|
254
|
-
*/
|
|
255
|
-
function feeView(fee) {
|
|
256
|
-
const f = fee && typeof fee === 'object' ? fee : null;
|
|
257
|
-
let line = '';
|
|
258
|
-
try {
|
|
259
|
-
const mod = loadModule();
|
|
260
|
-
if (typeof mod.byokFeeLine === 'function') line = String(mod.byokFeeLine(f) || '');
|
|
261
|
-
} catch {
|
|
262
|
-
// No shared module (staged tree without the host payload): silence, which
|
|
263
|
-
// is the honest reading of "this host cannot price the lane right now".
|
|
264
|
-
line = '';
|
|
265
|
-
}
|
|
266
|
-
return {
|
|
267
|
-
line,
|
|
268
|
-
published: line !== '',
|
|
269
|
-
// Enforcement, not price. A host that knows the relay demands an account
|
|
270
|
-
// can say so before the user meets the 402 instead of after.
|
|
271
|
-
accountRequired: !!(f && f.require_account === true),
|
|
272
|
-
anonymousDailyCalls: f && Number.isFinite(Number(f.anonymous_daily_calls))
|
|
273
|
-
? Number(f.anonymous_daily_calls) : 0,
|
|
274
|
-
gateMode: f && typeof f.gate_mode === 'string' ? f.gate_mode : '',
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Fetch the server's published BYOK fee. Non-throwing, and offline it returns
|
|
280
|
-
* null — the fee is disclosure, not a gate, so a failed read must not turn
|
|
281
|
-
* `/billing` into an error the user has to interpret.
|
|
282
|
-
*/
|
|
283
|
-
async function probeFee() {
|
|
284
|
-
try {
|
|
285
|
-
const client = loadClient();
|
|
286
|
-
if (!client || typeof client.byokProviders !== 'function') return null;
|
|
287
|
-
const data = await client.byokProviders();
|
|
288
|
-
return (data && data.fee) || null;
|
|
289
|
-
} catch {
|
|
290
|
-
return null;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function paymentView(snapshot, { host = 'cli', fee = null } = {}) {
|
|
295
|
-
const copy = paymentCopy();
|
|
296
|
-
const snap = snapshot && typeof snapshot === 'object' ? snapshot : {};
|
|
297
|
-
const entitled = snap.entitled === true;
|
|
298
|
-
const feeLine = feeView(fee).line;
|
|
299
|
-
const wall = entitled ? 'owned' : snap.wall === 'balance' ? 'balance' : 'plan';
|
|
300
|
-
// The paid tier's NAME, resolved from the server's plan string. `unlimited`
|
|
301
|
-
// is the tier currently sold (€9/mo); `pro` is the grandfathered €2 line —
|
|
302
|
-
// still paid, still named Pro, but no longer offered to anyone. The shared
|
|
303
|
-
// module's own `tierName` (TIER_NAMES) wins when the snapshot carries one, so
|
|
304
|
-
// this host cannot disagree with the gate about which tier was granted.
|
|
305
|
-
const tierName =
|
|
306
|
-
snap.tierName ||
|
|
307
|
-
{ unlimited: 'Unlimited', pro: 'Pro' }[String(snap.plan || '').toLowerCase()] ||
|
|
308
|
-
'Unlimited';
|
|
309
|
-
const which = wall === 'balance' ? BALANCE_WALL : BILLING_WALL;
|
|
310
|
-
return {
|
|
311
|
-
host,
|
|
312
|
-
wall,
|
|
313
|
-
entitled,
|
|
314
|
-
// "The module actually answered." `degraded` is the module's own flag for
|
|
315
|
-
// "no real answer" (timeout, no plan field, no probe), and it must ALSO have
|
|
316
|
-
// named where the verdict came from — an unresolved boot snapshot has
|
|
317
|
-
// `degraded === false` only because nothing ever ran, and reporting that as
|
|
318
|
-
// verified would present "we never asked" as a fact about the account.
|
|
319
|
-
// Derived from the module's two fields rather than from the plan string, so
|
|
320
|
-
// this host never re-decides what counts as knowledge.
|
|
321
|
-
verified: snap.degraded === false && typeof snap.source === 'string' && snap.source !== '',
|
|
322
|
-
plan: snap.plan ? String(snap.plan) : 'free',
|
|
323
|
-
paid: entitled,
|
|
324
|
-
reason: copy.paidReason,
|
|
325
|
-
honesty: copy.honesty,
|
|
326
|
-
ask: copy.ask,
|
|
327
|
-
// No link once the offer is owned: a paying customer being sold the thing
|
|
328
|
-
// they already bought is the one prompt that can only lose money.
|
|
329
|
-
url: entitled ? '' : paymentUrl(which),
|
|
330
|
-
campaign: entitled ? '' : which.campaign,
|
|
331
|
-
// The BYOK lane's price, from the server's own published rate. Empty when
|
|
332
|
-
// the server published none — never a client-side guess (see the shared
|
|
333
|
-
// module's byokFeeLine). This is the sentence that closes the one place the
|
|
334
|
-
// bill and the pitch disagreed: a user was told BYOK costs "your provider's
|
|
335
|
-
// cost" while aegis1 charged a handling fee on top of it.
|
|
336
|
-
byok: feeLine,
|
|
337
|
-
label: entitled ? tierName : wall === 'balance' ? 'Top up' : 'Upgrade',
|
|
338
|
-
unlock:
|
|
339
|
-
wall === 'balance'
|
|
340
|
-
? 'Unlock: top up the Token Bank, or upgrade to Unlimited'
|
|
341
|
-
: 'Unlock: Unlimited, or any Token Bank balance',
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
module.exports = {
|
|
346
|
-
createCliEntitlement,
|
|
347
|
-
buildProbe,
|
|
348
|
-
loadModule,
|
|
349
|
-
paymentView,
|
|
350
|
-
paymentCopy,
|
|
351
|
-
feeView,
|
|
352
|
-
probeFee,
|
|
353
|
-
paymentUrl,
|
|
354
|
-
FALLBACK_COPY,
|
|
355
|
-
BILLING_WALL,
|
|
356
|
-
BALANCE_WALL,
|
|
357
|
-
};
|
|
3
|
+
"use strict";const{resolveShared:resolveShared}=require("./sharedpaths.js"),{noteTier:noteTier}=require("./format.js");function loadModule(){return require(resolveShared("desktop/lib/local/entitlement.js"))}function loadClient(){const{createClient:e}=require(resolveShared("client/aegis.js"));return e(require("./credentials.js").clientOptions({channel:"cli"}))}function buildProbe(e){if(e&&"function"==typeof e.verifyApiKey)return async()=>{const n=await e.verifyApiKey(),t=n&&"object"==typeof n?{...n}:{};if("function"==typeof e.tokenBankBalance)try{const n=await e.tokenBankBalance();n&&"object"==typeof n&&(null!=n.balance_micros?t.balance_micros=n.balance_micros:null!=n.balance_eur&&(t.balance_eur=n.balance_eur))}catch{}return t}}function createCliEntitlement({aegis:e,now:n,ttlMs:t}={}){const a=loadModule(),o=e||loadClient(),r=a.createEntitlement({probe:buildProbe(o),host:"cli",...n?{now:n}:{},...t?{ttlMs:t}:{}});if(r&&"function"==typeof r.current){const e=r.current.bind(r);try{if(r.current=(...n)=>{const t=e(...n);return noteTier(t),t},"function"==typeof r.refresh){const n=r.refresh.bind(r);r.refresh=async(...t)=>{const a=await n(...t);try{noteTier(e())}catch{}return a}}}catch{}}return r}const FALLBACK_COPY=Object.freeze({paidReason:"Pro puts the drain in the cloud, so the job keeps running after you close the laptop",honesty:"Everything on your machine is free, permanently. The cloud drain is what you pay for.",ask:"Do X autonomously"}),BILLING_WALL=Object.freeze({campaign:"status_card",page:"upgrade"}),BALANCE_WALL=Object.freeze({campaign:"topup_bank",page:"topup"});let sharedCache;function shared(){if(void 0!==sharedCache)return sharedCache||void 0;try{sharedCache=loadModule()}catch{sharedCache=null}return sharedCache||void 0}function paymentCopy(){const e=shared();return{paidReason:str(e&&e.PRO_VALUE,FALLBACK_COPY.paidReason),honesty:str(e&&e.FREE_HONESTY,FALLBACK_COPY.honesty),ask:str(e&&e.ASK_EXAMPLE,FALLBACK_COPY.ask)}}function str(e,n){const t=null==e?"":String(e);return t.trim()?t:n}function paymentUrl(e){const n=shared();if(n&&"function"==typeof n.goUrl)try{return n.goUrl(e.page,e.campaign,"cli")}catch{}return`https://aegiscloud.org/go/${e.page}?s=cli&c=${e.campaign}`}function feeView(e){const n=e&&"object"==typeof e?e:null;let t="";try{const e=loadModule();"function"==typeof e.byokFeeLine&&(t=String(e.byokFeeLine(n)||""))}catch{t=""}return{line:t,published:""!==t,accountRequired:!(!n||!0!==n.require_account),anonymousDailyCalls:n&&Number.isFinite(Number(n.anonymous_daily_calls))?Number(n.anonymous_daily_calls):0,gateMode:n&&"string"==typeof n.gate_mode?n.gate_mode:""}}async function probeFee(){try{const e=loadClient();if(!e||"function"!=typeof e.byokProviders)return null;const n=await e.byokProviders();return n&&n.fee||null}catch{return null}}function paymentView(e,{host:n="cli",fee:t=null}={}){const a=paymentCopy(),o=e&&"object"==typeof e?e:{},r=!0===o.entitled,i=feeView(t).line,l=r?"owned":"balance"===o.wall?"balance":"plan",c=o.tierName||{unlimited:"Unlimited",pro:"Pro"}[String(o.plan||"").toLowerCase()]||"Unlimited",s="balance"===l?BALANCE_WALL:BILLING_WALL;return{host:n,wall:l,entitled:r,verified:!1===o.degraded&&"string"==typeof o.source&&""!==o.source,plan:o.plan?String(o.plan):"free",paid:r,reason:a.paidReason,honesty:a.honesty,ask:a.ask,url:r?"":paymentUrl(s),campaign:r?"":s.campaign,byok:i,label:r?c:"balance"===l?"Top up":"Upgrade",unlock:"balance"===l?"Unlock: top up the Token Bank, or upgrade to Unlimited":"Unlock: Unlimited, or any Token Bank balance"}}module.exports={createCliEntitlement:createCliEntitlement,buildProbe:buildProbe,loadModule:loadModule,paymentView:paymentView,paymentCopy:paymentCopy,feeView:feeView,probeFee:probeFee,paymentUrl:paymentUrl,FALLBACK_COPY:FALLBACK_COPY,BILLING_WALL:BILLING_WALL,BALANCE_WALL:BALANCE_WALL};
|