aegisone 1.0.34 → 1.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -976
  9. package/src/child.js +1 -285
  10. package/src/dispatch.js +1 -269
  11. package/src/doctor.js +1 -639
  12. package/src/host.js +1 -111
  13. package/src/permissions.js +1 -383
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/package.json +3 -7
  17. package/vendor/cli/scripts/check.mjs +1 -52
  18. package/vendor/cli/scripts/demo.mjs +1 -94
  19. package/vendor/cli/scripts/predist.mjs +1 -75
  20. package/vendor/cli/scripts/runtests.mjs +1 -56
  21. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  22. package/vendor/cli/src/agents.js +1 -139
  23. package/vendor/cli/src/app.js +1 -2957
  24. package/vendor/cli/src/art.js +1 -289
  25. package/vendor/cli/src/chatflow.js +1 -3023
  26. package/vendor/cli/src/checkpoint.js +1 -90
  27. package/vendor/cli/src/clipboard.js +1 -424
  28. package/vendor/cli/src/cloudsync.js +1 -528
  29. package/vendor/cli/src/commands.js +1 -4089
  30. package/vendor/cli/src/config.js +1 -581
  31. package/vendor/cli/src/connect.js +1 -349
  32. package/vendor/cli/src/credentials.js +1 -33
  33. package/vendor/cli/src/deps.js +1 -232
  34. package/vendor/cli/src/devrun.js +1 -187
  35. package/vendor/cli/src/diff.js +1 -333
  36. package/vendor/cli/src/diffview.js +1 -296
  37. package/vendor/cli/src/engine.js +1 -297
  38. package/vendor/cli/src/entitlement.js +1 -355
  39. package/vendor/cli/src/events.js +1 -707
  40. package/vendor/cli/src/export.js +1 -67
  41. package/vendor/cli/src/filepreview.js +1 -153
  42. package/vendor/cli/src/fingerprint.js +1 -592
  43. package/vendor/cli/src/format.js +1 -259
  44. package/vendor/cli/src/fuzzy.js +1 -119
  45. package/vendor/cli/src/history.js +1 -423
  46. package/vendor/cli/src/init.js +1 -175
  47. package/vendor/cli/src/input.js +1 -139
  48. package/vendor/cli/src/keys.js +1 -183
  49. package/vendor/cli/src/markdown.js +1 -306
  50. package/vendor/cli/src/models.js +1 -507
  51. package/vendor/cli/src/naming.js +1 -57
  52. package/vendor/cli/src/overlays.js +1 -462
  53. package/vendor/cli/src/panels.js +1 -1418
  54. package/vendor/cli/src/ping.js +1 -226
  55. package/vendor/cli/src/presence.js +1 -238
  56. package/vendor/cli/src/render.js +1 -516
  57. package/vendor/cli/src/screen.js +1 -518
  58. package/vendor/cli/src/screens.js +1 -896
  59. package/vendor/cli/src/secret.js +1 -59
  60. package/vendor/cli/src/securefs.js +1 -359
  61. package/vendor/cli/src/settings.js +1 -155
  62. package/vendor/cli/src/shared.js +1 -52
  63. package/vendor/cli/src/sharedpaths.js +1 -53
  64. package/vendor/cli/src/signup.js +1 -156
  65. package/vendor/cli/src/summarize.js +1 -95
  66. package/vendor/cli/src/sysdiag.js +1 -585
  67. package/vendor/cli/src/system.js +1 -40
  68. package/vendor/cli/src/theme.js +1 -570
  69. package/vendor/cli/src/title.js +1 -220
  70. package/vendor/cli/src/todos.js +1 -115
  71. package/vendor/cli/src/tokens.js +1 -263
  72. package/vendor/cli/src/topup.js +1 -210
  73. package/vendor/cli/src/update.js +1 -191
  74. package/vendor/cli/vendor/client/aegis.js +1 -2441
  75. package/vendor/cli/vendor/client/attest.js +1 -518
  76. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  77. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  78. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  79. package/vendor/cli/vendor/client/byok-catalog.js +1 -199
  80. package/vendor/cli/vendor/client/catalog-client.js +1 -487
  81. package/vendor/cli/vendor/client/conversation-export.js +1 -177
  82. package/vendor/cli/vendor/client/credentials.js +1 -494
  83. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  84. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  85. package/vendor/cli/vendor/client/drive-upload.js +1 -234
  86. package/vendor/cli/vendor/client/env-file.js +1 -1273
  87. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  88. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  89. package/vendor/cli/vendor/client/google-signin.js +1 -133
  90. package/vendor/cli/vendor/client/hooks.js +1 -430
  91. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  92. package/vendor/cli/vendor/client/naming.js +1 -283
  93. package/vendor/cli/vendor/client/platform.js +1 -937
  94. package/vendor/cli/vendor/client/prefs.js +1 -351
  95. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  96. package/vendor/cli/vendor/client/presence.js +1 -438
  97. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  98. package/vendor/cli/vendor/client/session-store.js +1 -575
  99. package/vendor/cli/vendor/client/topup.js +1 -297
  100. package/vendor/cli/vendor/client/touch.js +1 -458
  101. package/vendor/cli/vendor/client/update.js +1 -763
  102. package/vendor/cli/vendor/client/user-models.js +1 -381
  103. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  104. package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
  105. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  106. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
  107. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
  108. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
  109. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  110. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  111. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
  112. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
  113. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  114. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
  115. package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
  116. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  117. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  118. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  119. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  120. package/vendor/cli/vendor/hosts/install.js +1 -638
  121. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  122. package/vendor/cli/vendor/hosts/spec.js +1 -164
  123. package/vendor/cli/vendor/hosts/targets.js +1 -346
  124. package/vendor/cli/vendor/mcp/server.js +1 -221
  125. package/vendor/cli/vendor/mcp/tools.js +1 -408
  126. package/vendor/cli/vendor/one/src/child.js +1 -285
  127. package/vendor/cli/vendor/one/src/permissions.js +1 -383
  128. package/vendor/desktop/bin/aegis.js +1 -32
  129. package/vendor/desktop/lib/account-key.js +1 -56
  130. package/vendor/desktop/lib/auto.js +1 -461
  131. package/vendor/desktop/lib/avatar/companion.js +1 -698
  132. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  133. package/vendor/desktop/lib/avatar/events.js +1 -344
  134. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  135. package/vendor/desktop/lib/avatar/holders.js +1 -612
  136. package/vendor/desktop/lib/avatar/identity.js +1 -641
  137. package/vendor/desktop/lib/avatar/level.js +1 -368
  138. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  139. package/vendor/desktop/lib/avatar/persona.js +1 -388
  140. package/vendor/desktop/lib/avatar/profile.js +1 -977
  141. package/vendor/desktop/lib/avatar/register.js +1 -307
  142. package/vendor/desktop/lib/avatar/store.js +1 -472
  143. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  144. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  145. package/vendor/desktop/lib/avatar/turn.js +1 -216
  146. package/vendor/desktop/lib/avatar/voice.js +1 -328
  147. package/vendor/desktop/lib/avatar/xp.js +1 -404
  148. package/vendor/desktop/lib/deep-link.js +1 -120
  149. package/vendor/desktop/lib/fingerprint.js +2 -347
  150. package/vendor/desktop/lib/google-connect.js +1 -323
  151. package/vendor/desktop/lib/local/agents.js +1 -105
  152. package/vendor/desktop/lib/local/attachments.js +1 -276
  153. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  154. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  155. package/vendor/desktop/lib/local/context.js +1 -125
  156. package/vendor/desktop/lib/local/engine.js +1 -3666
  157. package/vendor/desktop/lib/local/entitlement.js +1 -660
  158. package/vendor/desktop/lib/local/git-scope.js +1 -228
  159. package/vendor/desktop/lib/local/local.js +1 -2145
  160. package/vendor/desktop/lib/local/prompt.js +1 -280
  161. package/vendor/desktop/lib/local/queue.js +1 -560
  162. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  163. package/vendor/desktop/lib/local/spill.js +1 -75
  164. package/vendor/desktop/lib/local/telemetry.js +1 -470
  165. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  166. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  167. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  168. package/vendor/desktop/lib/quick-launcher.js +1 -84
  169. package/vendor/desktop/lib/settings.js +1 -890
  170. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  171. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  172. package/vendor/desktop/lib/sync/sessions.js +1 -106
  173. package/vendor/desktop/lib/window-state.js +1 -66
  174. package/vendor/desktop/package.json +2 -4
  175. package/vendor/desktop/preload.js +1 -679
  176. package/vendor/desktop/renderer/app.js +1 -7250
  177. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  178. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  179. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  180. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  181. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  182. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  183. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  184. package/vendor/desktop/renderer/budget.js +1 -172
  185. package/vendor/desktop/renderer/companion.js +1 -223
  186. package/vendor/desktop/renderer/diff.js +1 -359
  187. package/vendor/desktop/renderer/diffview.js +1 -336
  188. package/vendor/desktop/renderer/filepreview.js +1 -211
  189. package/vendor/desktop/renderer/fingerprint.js +3 -789
  190. package/vendor/desktop/renderer/markdown.js +1 -168
  191. package/vendor/desktop/renderer/provider-mark.js +1 -311
  192. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  193. package/vendor/desktop/renderer/providers.js +1 -259
  194. package/vendor/desktop/renderer/quick.js +1 -285
  195. package/vendor/desktop/renderer/stream-policy.js +1 -387
  196. package/vendor/desktop/renderer/transcript-view.js +1 -323
  197. package/vendor/desktop/renderer/usage.js +1 -1239
  198. package/vendor/desktop/vendor/aegis.js +1 -2441
  199. package/vendor/desktop/vendor/attest.js +1 -518
  200. package/vendor/desktop/vendor/authorship-key.js +1 -410
  201. package/vendor/desktop/vendor/auto-provision.js +1 -134
  202. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  203. package/vendor/desktop/vendor/byok-catalog.js +1 -199
  204. package/vendor/desktop/vendor/catalog-client.js +1 -487
  205. package/vendor/desktop/vendor/conversation-export.js +1 -177
  206. package/vendor/desktop/vendor/credentials.js +1 -494
  207. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  208. package/vendor/desktop/vendor/drive-connect.js +1 -110
  209. package/vendor/desktop/vendor/drive-upload.js +1 -234
  210. package/vendor/desktop/vendor/env-file.js +1 -1273
  211. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  212. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  213. package/vendor/desktop/vendor/google-signin.js +1 -133
  214. package/vendor/desktop/vendor/hooks.js +1 -430
  215. package/vendor/desktop/vendor/model-discovery.js +1 -373
  216. package/vendor/desktop/vendor/naming.js +1 -283
  217. package/vendor/desktop/vendor/platform.js +1 -937
  218. package/vendor/desktop/vendor/prefs.js +1 -351
  219. package/vendor/desktop/vendor/presence-constants.js +1 -107
  220. package/vendor/desktop/vendor/presence.js +1 -438
  221. package/vendor/desktop/vendor/record-vault.js +3 -1055
  222. package/vendor/desktop/vendor/session-store.js +1 -575
  223. package/vendor/desktop/vendor/topup.js +1 -297
  224. package/vendor/desktop/vendor/touch.js +1 -458
  225. package/vendor/desktop/vendor/update.js +1 -763
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -1,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
- // 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
- * 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};