aegiscode 6.8.31 → 6.8.34
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 +53 -8
- package/package.json +1 -1
- package/src/app.js +22 -7
- package/src/autonomous.js +2 -2
- package/src/chatflow.js +28 -1
- package/src/commands.js +203 -5
- package/src/config.js +113 -1
- package/src/entitlement.js +12 -3
- package/src/panels.js +1 -1
- package/src/ping.js +223 -0
- package/src/settings.js +152 -0
- package/src/todos.js +109 -0
- package/vendor/client/aegis.js +10 -4
- package/vendor/client/auto-provision.js +12 -5
- package/vendor/client/prefs.js +32 -2
- package/vendor/desktop/lib/local/autonomous.js +105 -38
- package/vendor/desktop/lib/local/engine.js +13 -0
- package/vendor/desktop/lib/local/entitlement.js +99 -16
- package/vendor/desktop/lib/local/queue.js +20 -16
- package/vendor/desktop/lib/settings.js +48 -14
- package/vendor/mcp/server.js +5 -3
|
@@ -97,48 +97,100 @@ function writtenPath(tool) {
|
|
|
97
97
|
const DEFAULT_MODEL = 'nexus-brain';
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
* THE QUEUE RUNS ON
|
|
100
|
+
* THE QUEUE RUNS ON WHATEVER CLASS THE TASK NAMES — aegis, byok, or local —
|
|
101
|
+
* the same three classes engine.js's interactive turns serve (engine.js's
|
|
102
|
+
* exported `CLASSES`). This module does not `require('./engine.js')` to read
|
|
103
|
+
* that list itself (same reason queue.js stays engine-free): duplicating the
|
|
104
|
+
* three names here keeps both modules testable with no Electron, no network,
|
|
105
|
+
* and no model.
|
|
101
106
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
107
|
+
* This used to be Aegis Cloud only, because runTask sent every turn out with
|
|
108
|
+
* a hardcoded `class: 'aegis'` — a byok or local model id would have gone out
|
|
109
|
+
* under the wrong transport and failed at the server, or worse, silently
|
|
110
|
+
* picked up the wrong provider's key. Now `class` travels with the task
|
|
111
|
+
* (`item.class`, defaulted to 'aegis' for every task that predates this field
|
|
112
|
+
* — the CLI, a hand-written queue file, the old desktop card), and runTask
|
|
113
|
+
* forwards it verbatim instead of overwriting it.
|
|
109
114
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
115
|
+
* Each class validates differently, because each has a different notion of
|
|
116
|
+
* "no model stated is fine":
|
|
117
|
+
* - 'aegis' has a real default (the pooled brain), so a blank model is
|
|
118
|
+
* accepted and resolveModel fills it in. The accept-list is the
|
|
119
|
+
* pooled-brain tier family — the one entry engine.js's offerableCatalog
|
|
120
|
+
* offers for the Aegis Cloud class, plus the `-smart`/`-neo` tier
|
|
121
|
+
* spellings the server still serves as aliases of it (mirrors
|
|
122
|
+
* selectBrainEntry() there rather than re-deriving "anything starting
|
|
123
|
+
* with nexus-": `nexus-fast` is not a tier the catalog has ever served).
|
|
124
|
+
* - 'byok' and 'local' have no such default: a blank byok model cannot be
|
|
125
|
+
* "whichever provider the pool picks" (there is no pool), and a blank
|
|
126
|
+
* local model cannot be "whichever model is pulled" when the answer
|
|
127
|
+
* depends on what the user's own daemon happens to have. Both REQUIRE an
|
|
128
|
+
* explicit model, refused by name instead of silently resolving to
|
|
129
|
+
* something nobody chose.
|
|
117
130
|
*/
|
|
131
|
+
const MODEL_CLASSES = Object.freeze(['aegis', 'byok', 'local']);
|
|
132
|
+
|
|
118
133
|
const AEGIS_MODEL_RE = /^(?:nexus|aegis)-brain(?:-(?:smart|neo))?$/;
|
|
119
134
|
const AEGIS_MODEL_IDS = Object.freeze(['nexus-brain', 'aegis-brain']);
|
|
120
135
|
|
|
121
|
-
/** True when `id` names an AEGIS Cloud pooled-brain tier
|
|
136
|
+
/** True when `id` names an AEGIS Cloud pooled-brain tier. */
|
|
122
137
|
function isAegisModel(id) {
|
|
123
138
|
return AEGIS_MODEL_RE.test(String(id == null ? '' : id).trim());
|
|
124
139
|
}
|
|
125
140
|
|
|
126
141
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
142
|
+
* Normalize a task's stated class to one this module (and engine.js) knows.
|
|
143
|
+
* Blank or absent — every task queued before this field existed — defaults to
|
|
144
|
+
* 'aegis', the only class the queue ever ran before today.
|
|
145
|
+
*/
|
|
146
|
+
function normalizeClass(cls) {
|
|
147
|
+
const stated = String(cls == null ? '' : cls).trim().toLowerCase();
|
|
148
|
+
return stated || 'aegis';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Whether `id` is shaped "<provider>:<model>" — the only form engine.js's
|
|
153
|
+
* byok class accepts (splitByokModel). Not re-deriving the live provider list
|
|
154
|
+
* here (that is a catalog call, `listModels('byok')`, this module has no
|
|
155
|
+
* business caching) — just enough of a shape check that a malformed id is
|
|
156
|
+
* refused at the door instead of failing splitByokModel at the server with no
|
|
157
|
+
* context.
|
|
158
|
+
*/
|
|
159
|
+
function looksLikeByokModel(id) {
|
|
160
|
+
const s = String(id == null ? '' : id).trim();
|
|
161
|
+
const i = s.indexOf(':');
|
|
162
|
+
return i > 0 && i < s.length - 1;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Why a STATED (model, class) pair cannot be queued, or '' when it can.
|
|
129
167
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* otherwise: `class: 'aegis'` would be sent with an id the server does not
|
|
133
|
-
* serve, and the task would come back as an opaque error minutes later.
|
|
168
|
+
* `cls` defaults to 'aegis' when omitted, so every existing caller of
|
|
169
|
+
* `modelRefusal(id)` keeps its old behaviour verbatim.
|
|
134
170
|
*/
|
|
135
|
-
function modelRefusal(id) {
|
|
171
|
+
function modelRefusal(id, cls) {
|
|
136
172
|
const stated = String(id == null ? '' : id).trim();
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
`
|
|
140
|
-
|
|
141
|
-
)
|
|
173
|
+
const normalized = normalizeClass(cls);
|
|
174
|
+
if (!MODEL_CLASSES.includes(normalized)) {
|
|
175
|
+
return `"${cls}" is not a model class the queue serves (${MODEL_CLASSES.join('/')})`;
|
|
176
|
+
}
|
|
177
|
+
if (normalized === 'aegis') {
|
|
178
|
+
if (!stated || isAegisModel(stated)) return '';
|
|
179
|
+
return (
|
|
180
|
+
`the autonomous queue's Aegis Cloud class runs pooled-brain models only (${DEFAULT_MODEL}, ` +
|
|
181
|
+
`${AEGIS_MODEL_IDS.join('/')} aliases); "${stated}" is not one`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
if (normalized === 'byok') {
|
|
185
|
+
if (!stated) return 'a byok task needs a model, as "<provider>:<model>" (pick one from /models)';
|
|
186
|
+
if (!looksLikeByokModel(stated)) {
|
|
187
|
+
return `"${stated}" is not a byok model id — it must be "<provider>:<model>" (pick one from /models)`;
|
|
188
|
+
}
|
|
189
|
+
return '';
|
|
190
|
+
}
|
|
191
|
+
// normalized === 'local'
|
|
192
|
+
if (!stated) return 'a local task needs a model — the tag of whatever is pulled into the local daemon';
|
|
193
|
+
return '';
|
|
142
194
|
}
|
|
143
195
|
|
|
144
196
|
/** Phrase match for "work autonomously" in a prompt or a queued task. */
|
|
@@ -239,10 +291,14 @@ function withRoundHorizon(rounds, env, fn) {
|
|
|
239
291
|
* task over it would break drains for a reason that is not the task's
|
|
240
292
|
* fault; a fallback to the pooled brain keeps the drain honest and on-cloud.
|
|
241
293
|
*/
|
|
242
|
-
function resolveModel({ model, env } = {}) {
|
|
243
|
-
const e = env || process.env;
|
|
294
|
+
function resolveModel({ model, env, cls } = {}) {
|
|
244
295
|
const picked = String(model || '').trim();
|
|
296
|
+
// byok/local have no cloud default to fall back to — modelRefusal already
|
|
297
|
+
// guaranteed a non-empty, shaped model at queue time, so the task's own pick
|
|
298
|
+
// is the only answer for either class.
|
|
299
|
+
if (normalizeClass(cls) !== 'aegis') return picked;
|
|
245
300
|
if (picked) return picked;
|
|
301
|
+
const e = env || process.env;
|
|
246
302
|
const fromEnv = String(e.AEGIS_AUTONOMOUS_MODEL || e.AEGIS_MODEL || '').trim();
|
|
247
303
|
return isAegisModel(fromEnv) ? fromEnv : DEFAULT_MODEL;
|
|
248
304
|
}
|
|
@@ -255,7 +311,8 @@ function resolveModel({ model, env } = {}) {
|
|
|
255
311
|
* it: the queue falls back to the pool, and the one place that says so is this
|
|
256
312
|
* string, which runTask emits as a note and the desktop card shows.
|
|
257
313
|
*/
|
|
258
|
-
function ignoredEnvModel({ model, env } = {}) {
|
|
314
|
+
function ignoredEnvModel({ model, env, cls } = {}) {
|
|
315
|
+
if (normalizeClass(cls) !== 'aegis') return ''; // AEGIS_AUTONOMOUS_MODEL is an Aegis-only pin
|
|
259
316
|
if (String(model || '').trim()) return ''; // the task's own pick is what counts
|
|
260
317
|
const e = env || process.env;
|
|
261
318
|
const fromEnv = String(e.AEGIS_AUTONOMOUS_MODEL || e.AEGIS_MODEL || '').trim();
|
|
@@ -462,16 +519,23 @@ function createQueueWorker({
|
|
|
462
519
|
// pool does not serve: billed work if it happens to be a per-provider
|
|
463
520
|
// spelling, an opaque server error otherwise. Failing here names the model
|
|
464
521
|
// and the allowed ones, and costs nothing.
|
|
465
|
-
const
|
|
522
|
+
const cls = normalizeClass(item.class);
|
|
523
|
+
const refusal = modelRefusal(item.model, cls);
|
|
466
524
|
if (refusal) {
|
|
467
|
-
const failed = { ok: false, error: refusal, model: item.model, ms: 0 };
|
|
525
|
+
const failed = { ok: false, error: refusal, model: item.model, class: cls, ms: 0 };
|
|
468
526
|
emit({ type: 'finish', taskId: item.id, ok: false, result: failed });
|
|
469
527
|
return failed;
|
|
470
528
|
}
|
|
471
|
-
const model = resolveModel({ model: item.model, env });
|
|
472
|
-
const ignored = ignoredEnvModel({ model: item.model, env });
|
|
529
|
+
const model = resolveModel({ model: item.model, env, cls });
|
|
530
|
+
const ignored = ignoredEnvModel({ model: item.model, env, cls });
|
|
473
531
|
if (ignored) emit({ type: 'note', taskId: item.id, note: ignored });
|
|
474
|
-
|
|
532
|
+
// The pooled-brain fan-out is an Aegis Cloud mechanism (aegis1
|
|
533
|
+
// services/pool_brain.py) — engine.js itself only honours `autonomous`
|
|
534
|
+
// under `cls === 'aegis'` (engine.js:1524), so a byok/local task asking for
|
|
535
|
+
// it is forced to a plain single pass HERE rather than relying on that
|
|
536
|
+
// silent no-op, which would otherwise size the task's effort/round
|
|
537
|
+
// reporting as if a fan-out it never got had been granted.
|
|
538
|
+
const fanoutAsked = cls === 'aegis' && resolveFanout(item, env);
|
|
475
539
|
// The clamp. `canFanOut()` is the entitlement answer (true everywhere
|
|
476
540
|
// except a non-Pro desktop session), and it can only ever take a fan-out
|
|
477
541
|
// AWAY: a task the session is not entitled to fan out runs as one plain
|
|
@@ -526,14 +590,14 @@ function createQueueWorker({
|
|
|
526
590
|
const wantCommit = commit === undefined ? Boolean(item.commit) : Boolean(commit);
|
|
527
591
|
const before = wantCommit ? safe(() => git.gitStatusSnapshot(cwd), null) : null;
|
|
528
592
|
|
|
529
|
-
emit({ type: 'start', taskId: item.id, model, cwd, rounds, fanout, effort });
|
|
593
|
+
emit({ type: 'start', taskId: item.id, model, class: cls, cwd, rounds, fanout, effort });
|
|
530
594
|
const started = now();
|
|
531
595
|
let result;
|
|
532
596
|
try {
|
|
533
597
|
const res = await withRoundHorizon(rounds, env, () =>
|
|
534
598
|
engine.chat(
|
|
535
599
|
{
|
|
536
|
-
class:
|
|
600
|
+
class: cls,
|
|
537
601
|
model,
|
|
538
602
|
prompt: taskPrompt(item, { carry, rounds }),
|
|
539
603
|
// The pooled-brain fan-out ("fan out this turn" in the GUI chat
|
|
@@ -831,8 +895,11 @@ module.exports = {
|
|
|
831
895
|
DEFAULT_MODEL,
|
|
832
896
|
DEFAULT_ROUNDS,
|
|
833
897
|
MAX_ROUND_STOPS,
|
|
898
|
+
MODEL_CLASSES,
|
|
834
899
|
AEGIS_MODEL_IDS,
|
|
835
900
|
isAegisModel,
|
|
901
|
+
normalizeClass,
|
|
902
|
+
looksLikeByokModel,
|
|
836
903
|
modelRefusal,
|
|
837
904
|
WRITE_TOOLS,
|
|
838
905
|
writtenPath,
|
|
@@ -968,6 +968,19 @@ function createLocalEngine({
|
|
|
968
968
|
// reverse its verdict. An approval that could waive Λ2 would be the exact
|
|
969
969
|
// capture K3 describes. To change what is permitted, the covenant text
|
|
970
970
|
// itself has to be re-sealed — which no runtime input can do.
|
|
971
|
+
//
|
|
972
|
+
// DO NOT MOVE THIS BELOW A SHORT-CIRCUIT. It sits above every `return` of
|
|
973
|
+
// the confirmation gate on purpose (ON8/D8 rule 2): `gatedExecuteTool`
|
|
974
|
+
// short-circuits on `!confirmModeEnabled()`, on a remembered session
|
|
975
|
+
// "allow", and on a `/permissions` skip — and since ON8 the confirm-mode
|
|
976
|
+
// preference is the SHARED store's, i.e. the same value the terminal face
|
|
977
|
+
// reads, and `--dangerously-skip-permissions` can arrive in that store as
|
|
978
|
+
// well. A refactor that hoists this below any of those three would make
|
|
979
|
+
// the covenant waivable by a setting a user can write, which is the one
|
|
980
|
+
// thing D8 rule 2 forbids outright. The frozen classes
|
|
981
|
+
// (`write`/`shell`/`network`/`offDevice`, always `'ask'`; see
|
|
982
|
+
// lib/avatar/level.js `LEVEL_INDEPENDENT_APPROVALS`) have the same floor
|
|
983
|
+
// and are asserted beside this one by one/test/permissions.test.mjs.
|
|
971
984
|
const cv = covenant.preActionAssert({ tool: name, args: args || {} });
|
|
972
985
|
if (!cv.allowed) {
|
|
973
986
|
// Non-silent (never a quiet no-op) and bound for Λ4 accountability.
|
|
@@ -28,17 +28,37 @@
|
|
|
28
28
|
* THE SIGNAL (see the report / the module's `probe`): main injects a probe that
|
|
29
29
|
* calls `aegis.verifyApiKey()` — aegis1 `/api/verify-api-key`, which its own
|
|
30
30
|
* docstring describes as "Verify a shared api_key and return plan/email/
|
|
31
|
-
* memory_token". The plan field is the account's
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* no new
|
|
31
|
+
* memory_token". The plan field is the account's plan, and aegis1 owns the
|
|
32
|
+
* vocabulary for it (`services/billing_service.py`: `TIERS = ("free", "pro",
|
|
33
|
+
* "unlimited")`, `PAID_PLANS = ("pro", "unlimited")`, plus the legacy aliases
|
|
34
|
+
* that normalize onto one of them). This module MIRRORS that vocabulary rather
|
|
35
|
+
* than inventing one; there is no new billing anything here, no new endpoint,
|
|
36
|
+
* and no write to the server. The probe prefers the server's `plan_effective`
|
|
37
|
+
* (its own `is_pro()` verdict, trial included) over the stored `plan` string
|
|
38
|
+
* when it is present, because a welcome-trial account is a real Unlimited
|
|
39
|
+
* entitlement that `users.plan` does not record — see `classifyProbe`.
|
|
40
|
+
*
|
|
41
|
+
* THE BUG THIS VOCABULARY COST (fixed here). `PAID_PLANS` read `("pro",)`,
|
|
42
|
+
* mirroring the retired €2 line and MISSING `unlimited` — the €9/mo tier that
|
|
43
|
+
* is the only one sold. So `normalizePlan('unlimited')` fell through to `free`,
|
|
44
|
+
* and a paying Unlimited subscriber with a spent-out bank was handed the
|
|
45
|
+
* free-tier boundary: the fan-out refused, the cloud drain clamped to one local
|
|
46
|
+
* worker, and a "top up your balance" prompt — for an account whose plan is
|
|
47
|
+
* precisely what pays for the drain. aegis1's own `LEGACY_PLAN_ALIASES` carries
|
|
48
|
+
* the matching warning from the other side ("Deliberately NOT an alias:
|
|
49
|
+
* `unlimited` is a live tier you can subscribe to, so it must resolve through
|
|
50
|
+
* TIERS"), and its `test_tier_vocabulary` pins `PAID_PLANS` at two entries.
|
|
51
|
+
* Two implementations of "is this account paid" had already drifted once; this
|
|
52
|
+
* was the drift.
|
|
36
53
|
*
|
|
37
54
|
* PHASE 6 — THE SECOND SIGNAL, THE BALANCE. The plan is only half of how this
|
|
38
55
|
* product charges. aegis1's actual paywall is the Token Bank running dry: the
|
|
39
56
|
* balance is prepaid EUR the OPERATOR credits by hand, and `app.py` states the
|
|
40
57
|
* consequence plainly — "Pool-key users with token bank balance skip legacy
|
|
41
|
-
* credit checks." So entitlement here is `
|
|
58
|
+
* credit checks." So entitlement here is `paid_plan || balance > 0` — and the
|
|
59
|
+
* `paid_plan` half is what carries an Unlimited subscriber whose bank is empty;
|
|
60
|
+
* the bank is an OVERAGE lever, never the thing that decides whether a paying
|
|
61
|
+
* account may use the feature it pays for. When the
|
|
42
62
|
* bank reads zero the wall names the fix that exists (a top-up, campaign
|
|
43
63
|
* `topup_bank`) instead of a plan checkout the user may already own. Nothing in
|
|
44
64
|
* this module grants a balance, expires one, or auto-charges: the operator
|
|
@@ -64,8 +84,33 @@
|
|
|
64
84
|
/** The free-tier fan-out ceiling: one worker per task, i.e. a plain turn. */
|
|
65
85
|
const FREE_MAX_WORKERS = 1;
|
|
66
86
|
|
|
67
|
-
/**
|
|
68
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Aegis1's paid tiers. MIRROR of services/billing_service.py
|
|
89
|
+
* `PAID_PLANS = ("pro", "unlimited")` — pinned literal on purpose, because this
|
|
90
|
+
* is the line that has to move whenever the server sells another tier.
|
|
91
|
+
*
|
|
92
|
+
* `unlimited` (€9/mo) is the tier ON SALE and the one a paying customer almost
|
|
93
|
+
* certainly owns; `pro` is the grandfathered €2 line, kept because its
|
|
94
|
+
* subscribers keep their entitlements. Reading only `pro` was not a narrower
|
|
95
|
+
* version of this gate, it was a gate pointing at the wrong tier: every
|
|
96
|
+
* Unlimited account fell to the free boundary. `starter` stays out — aegis1
|
|
97
|
+
* itself calls that one free.
|
|
98
|
+
*/
|
|
99
|
+
const PAID_PLANS = Object.freeze(['pro', 'unlimited']);
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* What each paid tier is CALLED, so a surface that names the account's plan
|
|
103
|
+
* names the one the server granted. The CLI has read the tier off the server's
|
|
104
|
+
* plan string since 6443a60 (`cli/src/entitlement.js::paymentView`) after it
|
|
105
|
+
* told a €9 subscriber they owned the retired €2 plan; this is the same value,
|
|
106
|
+
* resolved once in the shared module both hosts read.
|
|
107
|
+
*/
|
|
108
|
+
const TIER_NAMES = Object.freeze({ pro: 'Pro', unlimited: 'Unlimited' });
|
|
109
|
+
|
|
110
|
+
/** The display name for a plan string, or null when it is not a paid tier. */
|
|
111
|
+
function tierName(plan) {
|
|
112
|
+
return TIER_NAMES[normalizePlan(plan)] || null;
|
|
113
|
+
}
|
|
69
114
|
|
|
70
115
|
/**
|
|
71
116
|
* MIRROR of services/billing_service.py `LEGACY_PLAN_ALIASES`: every stored
|
|
@@ -251,11 +296,20 @@ function promptUrlFor(host) {
|
|
|
251
296
|
* card on the next refresh and long enough that a drain never probes per task. */
|
|
252
297
|
const DEFAULT_TTL_MS = 60 * 1000;
|
|
253
298
|
|
|
254
|
-
/** Collapse any stored/alias plan string onto a tier, exactly as aegis1 does.
|
|
299
|
+
/** Collapse any stored/alias plan string onto a tier, exactly as aegis1 does.
|
|
300
|
+
*
|
|
301
|
+
* Aegis1 checks its live `TIERS` BEFORE the alias table (`normalize_plan`), so
|
|
302
|
+
* an alias can never shadow a tier it also names — and `unlimited` is a live
|
|
303
|
+
* tier. It is therefore returned as itself and never collapsed onto `pro`: the
|
|
304
|
+
* two grant different entitlements server-side (the monthly Unlimited
|
|
305
|
+
* allowance and the BYOK fee waiver are `is_unlimited()`-gated), and telling a
|
|
306
|
+
* €9 customer they own the retired €2 plan is the mistake commit 6443a60
|
|
307
|
+
* exists to record.
|
|
308
|
+
*/
|
|
255
309
|
function normalizePlan(plan) {
|
|
256
310
|
const raw = String(plan == null ? '' : plan).trim().toLowerCase();
|
|
257
311
|
if (!raw) return 'free';
|
|
258
|
-
if (PAID_PLANS.includes(raw)) return
|
|
312
|
+
if (PAID_PLANS.includes(raw)) return raw;
|
|
259
313
|
const aliased = LEGACY_PLAN_ALIASES[raw];
|
|
260
314
|
return aliased || 'free';
|
|
261
315
|
}
|
|
@@ -265,9 +319,9 @@ function normalizePlan(plan) {
|
|
|
265
319
|
* drift into two different instructions. */
|
|
266
320
|
const ASK_EXAMPLE = 'Do X autonomously';
|
|
267
321
|
|
|
268
|
-
/** True only for a tier aegis1 itself would call paid. */
|
|
322
|
+
/** True only for a tier aegis1 itself would call paid (`pro` or `unlimited`). */
|
|
269
323
|
function isPaidPlan(plan) {
|
|
270
|
-
return normalizePlan(plan)
|
|
324
|
+
return normalizePlan(plan) !== 'free';
|
|
271
325
|
}
|
|
272
326
|
|
|
273
327
|
/**
|
|
@@ -367,7 +421,19 @@ function classifyProbe(result, error) {
|
|
|
367
421
|
const body = result && typeof result === 'object' ? result : {};
|
|
368
422
|
const bal = balanceOf(body);
|
|
369
423
|
if (body.valid === false) return { source: 'no-key', plan: 'free', degraded: false, ...bal };
|
|
370
|
-
|
|
424
|
+
// WHICH plan field. `plan_effective` is aegis1's own entitlement verdict —
|
|
425
|
+
// the same predicate its `is_pro()` gates pooled calls on, so it counts the
|
|
426
|
+
// 30-day welcome trial that never writes `users.plan` (see app.py's
|
|
427
|
+
// register_device: the trial lives in `subscriptions`). The stored `plan`
|
|
428
|
+
// column cannot express that account, so an installing user read as `free`
|
|
429
|
+
// here and only the €12 signup credit kept the gate open — spend it, or fail
|
|
430
|
+
// to receive it, and a real Unlimited account was refused the feature. The
|
|
431
|
+
// stored string is still the fallback: an older server that predates the
|
|
432
|
+
// field must keep working, and it is the same value when nothing is on trial.
|
|
433
|
+
const rawPlan = body.plan_effective != null && String(body.plan_effective).trim()
|
|
434
|
+
? body.plan_effective
|
|
435
|
+
: body.plan;
|
|
436
|
+
const stated = String(rawPlan == null ? '' : rawPlan).trim();
|
|
371
437
|
if (!stated) {
|
|
372
438
|
// A key that verified but carried no plan: aegis1's own default for such an
|
|
373
439
|
// account is `free` (the column default), and a missing field is not proof
|
|
@@ -411,6 +477,8 @@ function createEntitlement({
|
|
|
411
477
|
balanceZero: false,
|
|
412
478
|
wall: 'plan',
|
|
413
479
|
plan: 'free',
|
|
480
|
+
tier: null,
|
|
481
|
+
tierName: null,
|
|
414
482
|
planRaw: null,
|
|
415
483
|
maxWorkers: FREE_MAX_WORKERS,
|
|
416
484
|
source: 'unresolved',
|
|
@@ -424,12 +492,20 @@ function createEntitlement({
|
|
|
424
492
|
let inflight = null;
|
|
425
493
|
|
|
426
494
|
function fromProbe({ source, plan, degraded, planRaw, balanceKnown = false, balanceMicros = null }) {
|
|
427
|
-
|
|
495
|
+
// The tier itself, not a paid/not-paid bit: `unlimited` and `pro` are both
|
|
496
|
+
// paid and must stay distinguishable, because the surfaces that name the
|
|
497
|
+
// account's plan (the desktop's queue boundary, the CLI's `/billing`) name
|
|
498
|
+
// the one the server granted. `pro` below keeps its original meaning — "the
|
|
499
|
+
// PLAN is paid for", as opposed to a free plan carried by a funded bank.
|
|
500
|
+
const tier = normalizePlan(plan);
|
|
501
|
+
const pro = tier !== 'free';
|
|
428
502
|
const banked = balanceKnown && Number.isFinite(balanceMicros) && balanceMicros > 0;
|
|
429
503
|
// TWO independent ways to be paid for: a paid plan, or a funded bank. The
|
|
430
504
|
// operator controls the second by hand (aegis1 admin `add_funds`), which is
|
|
431
505
|
// the lever this wall is built around — nothing here grants, times out or
|
|
432
|
-
// auto-charges; it only reads the number the operator set.
|
|
506
|
+
// auto-charges; it only reads the number the operator set. The FIRST way is
|
|
507
|
+
// the one a paying subscriber holds, and it does not weaken when their bank
|
|
508
|
+
// runs dry: the balance is overage, the subscription is the entitlement.
|
|
433
509
|
const entitled = pro || banked;
|
|
434
510
|
// The bank was READABLE and EMPTY — the operator's own signal that this
|
|
435
511
|
// account is now paying, not the absence of a plan.
|
|
@@ -447,7 +523,12 @@ function createEntitlement({
|
|
|
447
523
|
balanceMicros: balanceKnown ? balanceMicros : null,
|
|
448
524
|
balanceZero,
|
|
449
525
|
wall,
|
|
450
|
-
|
|
526
|
+
// The tier a paid PLAN grants, else `free`. A funded bank on a free plan
|
|
527
|
+
// is still `free` here — the bank is not a tier, and naming one would put
|
|
528
|
+
// a plan on the account the server never granted.
|
|
529
|
+
plan: pro ? tier : 'free',
|
|
530
|
+
tier: pro ? tier : null,
|
|
531
|
+
tierName: pro ? (TIER_NAMES[tier] || null) : null,
|
|
451
532
|
planRaw: planRaw == null ? null : String(planRaw),
|
|
452
533
|
// A paid session has no ceiling of its own here: main.js still clamps the
|
|
453
534
|
// renderer's number to QUEUE_MAX_WORKERS, which stays the only upper bound.
|
|
@@ -543,6 +624,8 @@ module.exports = {
|
|
|
543
624
|
createEntitlement,
|
|
544
625
|
normalizePlan,
|
|
545
626
|
isPaidPlan,
|
|
627
|
+
tierName,
|
|
628
|
+
TIER_NAMES,
|
|
546
629
|
classifyProbe,
|
|
547
630
|
fanoutRefusal,
|
|
548
631
|
balanceRefusal,
|
|
@@ -176,34 +176,38 @@ function upsert(items, entry) {
|
|
|
176
176
|
|
|
177
177
|
/**
|
|
178
178
|
* Queue a task. `cwd` is where the work happens (the worker runs the turn
|
|
179
|
-
* with it as the tool loop's working directory), `model`
|
|
180
|
-
*
|
|
181
|
-
*
|
|
179
|
+
* with it as the tool loop's working directory), `class` + `model` are the
|
|
180
|
+
* same pair engine.js's interactive turns use ('aegis'/'byok'/'local' and the
|
|
181
|
+
* model id that class expects), and `commit` asks the worker to commit what
|
|
182
|
+
* the task changed (scoped — see autonomous.js).
|
|
182
183
|
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
184
|
+
* REFUSED AT THE DOOR, not three stages into a drain. `class` defaults to
|
|
185
|
+
* 'aegis' (every task queued before this field existed), and the (model,
|
|
186
|
+
* class) pair has to pass autonomous.js's own accept-list — the CLI
|
|
187
|
+
* (`aegiscode autonomous add --model`), the desktop card and a hand-written
|
|
188
|
+
* queue file are all held to the same rule, so a bad row fails here with a
|
|
189
|
+
* reason instead of coming back as an opaque server error after being picked
|
|
190
|
+
* up. `model: null` stays legal for the 'aegis' class only: that is "no
|
|
191
|
+
* pick", and autonomous.resolveModel fills in the pooled brain. 'byok' and
|
|
192
|
+
* 'local' have no such default and are refused if blank — see
|
|
193
|
+
* autonomous.modelRefusal. Required lazily: queue.js is a dependency of
|
|
194
|
+
* autonomous.js, and this check must not turn that into a load-order cycle.
|
|
192
195
|
*/
|
|
193
196
|
function addTask(env, opts = {}) {
|
|
194
197
|
const task = String(opts.task == null ? '' : opts.task).trim();
|
|
195
198
|
if (!task) throw new Error('queue: a task needs text');
|
|
199
|
+
const autonomousMod = require('./autonomous.js');
|
|
200
|
+
const cls = autonomousMod.normalizeClass(opts.class);
|
|
196
201
|
const statedModel = String(opts.model == null ? '' : opts.model).trim();
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (refusal) throw new Error(`queue: ${refusal}`);
|
|
200
|
-
}
|
|
202
|
+
const refusal = autonomousMod.modelRefusal(statedModel, cls);
|
|
203
|
+
if (refusal) throw new Error(`queue: ${refusal}`);
|
|
201
204
|
const items = loadQueue(env);
|
|
202
205
|
const now = opts.now || Date.now();
|
|
203
206
|
const entry = {
|
|
204
207
|
id: nextId(items),
|
|
205
208
|
task,
|
|
206
209
|
cwd: opts.cwd || process.cwd(),
|
|
210
|
+
class: cls,
|
|
207
211
|
model: statedModel || null,
|
|
208
212
|
effort: opts.effort || null,
|
|
209
213
|
workers: Number.isInteger(opts.workers) ? opts.workers : null,
|
|
@@ -270,6 +270,15 @@ function createSettingsStore({ dir, safeStorage, prefsDir, env } = {}) {
|
|
|
270
270
|
try {
|
|
271
271
|
return prefs.adopt({ dir: sharedDir, legacyDir: dir });
|
|
272
272
|
} catch (err) {
|
|
273
|
+
// Best-effort, but NOT silent (AEGISONE ON8). Swallowing this throw is how
|
|
274
|
+
// `prefs.adopt()`'s refusal to write its own ledger went unnoticed — the
|
|
275
|
+
// migration failed for every install that had something to adopt, and the
|
|
276
|
+
// store reported a healthy `adopted: false`. A failed migration is a
|
|
277
|
+
// preference a user set that this launch did not honor, so it is reported
|
|
278
|
+
// where a developer will see it; a store must still open either way.
|
|
279
|
+
if (process.env.AEGISCODE_DEBUG || process.env.AEGIS_HIST_DEBUG) {
|
|
280
|
+
process.stderr.write(`aegis-desktop: shared-preference adoption failed: ${err.message}\n`);
|
|
281
|
+
}
|
|
273
282
|
return { adopted: false, keys: [], reason: `adoption failed: ${err.message}` };
|
|
274
283
|
}
|
|
275
284
|
})();
|
|
@@ -525,26 +534,50 @@ function createSettingsStore({ dir, safeStorage, prefsDir, env } = {}) {
|
|
|
525
534
|
return quickLauncherConfig();
|
|
526
535
|
}
|
|
527
536
|
|
|
528
|
-
// --- Confirm mode:
|
|
529
|
-
// "Confirm before running tools" — the
|
|
530
|
-
//
|
|
531
|
-
//
|
|
532
|
-
//
|
|
533
|
-
//
|
|
534
|
-
//
|
|
537
|
+
// --- Confirm mode: SHARED preference (AEGISONE ON8, decision D8 rule 1) --
|
|
538
|
+
// "Confirm before running tools" — the switch for the renderer's tool-call
|
|
539
|
+
// approval gate (desktop/lib/local/engine.js gatedExecuteTool). ON (default,
|
|
540
|
+
// and the behaviour shipped so far) means every mutating tool call — exec /
|
|
541
|
+
// writeFile / editFile — is previewed and approved by the user first. OFF
|
|
542
|
+
// means the engine runs them straight through, like a tool the session
|
|
543
|
+
// already allowed. Nothing secret is stored here, so no encryption.
|
|
544
|
+
//
|
|
545
|
+
// This preference MOVED to the shared store (`confirmMode`) because D8 rule 1
|
|
546
|
+
// is "one posture, two faces": a rule set in the window has to be the rule the
|
|
547
|
+
// shell honors. The pre-ON8 `__confirmMode` namespace in `<userData>` is
|
|
548
|
+
// adopted once (client/prefs.js `extractNonSecretHalf`) and still read as a
|
|
549
|
+
// fallback, never written — a second writer is the split-brain this replaced.
|
|
550
|
+
// The gate's polarity is unchanged: ON when unset, in both places, so an
|
|
551
|
+
// install that never touched the switch keeps the gate exactly as it was.
|
|
552
|
+
|
|
553
|
+
function confirmModeState() {
|
|
554
|
+
const shared = loadShared();
|
|
555
|
+
if (typeof shared.confirmMode === 'boolean') {
|
|
556
|
+
return { enabled: shared.confirmMode, source: 'config' };
|
|
557
|
+
}
|
|
558
|
+
const cfg = load()[CONFIRM_MODE_NAMESPACE] || {};
|
|
559
|
+
if (cfg.enabled === undefined) return { enabled: true, source: 'default' };
|
|
560
|
+
return { enabled: Boolean(cfg.enabled), source: 'config' };
|
|
561
|
+
}
|
|
535
562
|
|
|
536
563
|
function getConfirmMode() {
|
|
537
|
-
|
|
538
|
-
// Unset === true: an existing install that never touched the toggle keeps
|
|
539
|
-
// the gate exactly as it was.
|
|
540
|
-
return cfg.enabled === undefined ? true : Boolean(cfg.enabled);
|
|
564
|
+
return confirmModeState().enabled;
|
|
541
565
|
}
|
|
542
566
|
|
|
543
567
|
function setConfirmMode(enabled) {
|
|
568
|
+
prefs.set({ confirmMode: Boolean(enabled) }, { dir: sharedDir });
|
|
569
|
+
// One-way: retire the legacy copy in the same breath, so the posture exists
|
|
570
|
+
// in exactly one place from here on (the same retirement the memory-persist
|
|
571
|
+
// preference below does).
|
|
544
572
|
const data = load();
|
|
545
|
-
data[CONFIRM_MODE_NAMESPACE]
|
|
546
|
-
|
|
547
|
-
|
|
573
|
+
if (data[CONFIRM_MODE_NAMESPACE] !== undefined) {
|
|
574
|
+
delete data[CONFIRM_MODE_NAMESPACE];
|
|
575
|
+
save(data);
|
|
576
|
+
}
|
|
577
|
+
// The boolean, not the state record: main.js's IPC reply is `{ enabled }`
|
|
578
|
+
// and it wraps the return value itself, so widening this would have put an
|
|
579
|
+
// object inside an object on the wire.
|
|
580
|
+
return confirmModeState().enabled;
|
|
548
581
|
}
|
|
549
582
|
|
|
550
583
|
// --- Telemetry: reserved namespace, plain preference, DEFAULT OFF --------
|
|
@@ -771,6 +804,7 @@ function createSettingsStore({ dir, safeStorage, prefsDir, env } = {}) {
|
|
|
771
804
|
setQuickLauncherConfig,
|
|
772
805
|
getConfirmMode,
|
|
773
806
|
setConfirmMode,
|
|
807
|
+
confirmModeState,
|
|
774
808
|
getTelemetryOptIn,
|
|
775
809
|
setTelemetryOptIn,
|
|
776
810
|
getMemoryPersist,
|
package/vendor/mcp/server.js
CHANGED
|
@@ -87,9 +87,11 @@ async function ensureApiKey() {
|
|
|
87
87
|
process.stderr.write('aegis: device auto-registration returned no usable key — falling back to manual setup.\n');
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
//
|
|
90
|
+
// The key comes with aegis1's one-time 30-day welcome-trial `unlimited`
|
|
91
|
+
// entitlement (token-bank credit + a `subscriptions` row, granted in the
|
|
92
|
+
// same register-device request — see registerDevice()'s doc in
|
|
93
|
+
// client/aegis.js), so the very next call works pooled. Once that allowance
|
|
94
|
+
// is spent or the trial lapses, the balance gate applies again.
|
|
93
95
|
process.stderr.write(
|
|
94
96
|
'aegis: no API key was configured — auto-provisioned a free AEGIS account' +
|
|
95
97
|
(result.ok ? ` (key saved to ${credentials.keyStatus().path}).\n` : ' (could not save it — see above).\n') +
|