aegiscode 6.8.4 → 6.8.6

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 (50) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -6
  3. package/scripts/predist.mjs +7 -0
  4. package/src/agents.js +1 -1
  5. package/src/app.js +2 -2
  6. package/src/autonomous.js +93 -3
  7. package/src/caps.js +1 -1
  8. package/src/chatflow.js +1 -1
  9. package/src/checkpoint.js +1 -1
  10. package/src/clipboard.js +1 -1
  11. package/src/commands.js +5 -5
  12. package/src/config.js +2 -2
  13. package/src/devrun.js +1 -1
  14. package/src/diff.js +1 -1
  15. package/src/entitlement.js +108 -0
  16. package/src/events.js +2 -2
  17. package/src/export.js +1 -1
  18. package/src/fuzzy.js +1 -1
  19. package/src/history.js +3 -3
  20. package/src/init.js +1 -1
  21. package/src/input.js +1 -1
  22. package/src/keys.js +1 -1
  23. package/src/markdown.js +2 -2
  24. package/src/overlays.js +2 -2
  25. package/src/panels.js +6 -6
  26. package/src/permissions.js +2 -2
  27. package/src/render.js +2 -2
  28. package/src/screen.js +4 -4
  29. package/src/screens.js +1 -1
  30. package/src/summarize.js +1 -1
  31. package/src/system.js +2 -2
  32. package/src/theme.js +6 -6
  33. package/src/tokens.js +2 -2
  34. package/src/update.js +1 -1
  35. package/vendor/client/aegis.js +146 -2
  36. package/vendor/client/credentials.js +4 -0
  37. package/vendor/desktop/lib/local/agents.js +1 -1
  38. package/vendor/desktop/lib/local/autonomous.js +70 -3
  39. package/vendor/desktop/lib/local/engine.js +19 -9
  40. package/vendor/desktop/lib/local/entitlement.js +487 -0
  41. package/vendor/desktop/lib/local/git-scope.js +1 -1
  42. package/vendor/desktop/lib/local/prompt.js +3 -3
  43. package/vendor/desktop/lib/local/queue.js +2 -2
  44. package/vendor/desktop/lib/local/shell.js +1 -1
  45. package/vendor/desktop/lib/local/tools.js +2 -2
  46. package/vendor/desktop/lib/local/turn-guard.js +1 -1
  47. package/vendor/desktop/lib/local/worktree-lock.js +1 -1
  48. package/vendor/desktop/lib/settings.js +36 -3
  49. package/vendor/desktop/renderer/usage.js +6 -6
  50. package/vendor/mcp/tools.js +9 -1
package/README.md CHANGED
@@ -58,12 +58,12 @@ product, so they are one name now:
58
58
  |---|---|
59
59
  | `aegiscode` | **this host**, v6.0.0. Installs a single binary, `aegiscode`. |
60
60
  | `aegis-terminal` | deprecated — the 0.1.x spelling of this package, folded into `aegiscode`. |
61
- | `aegiscode-cli` | 4.0.3, an earlier name of the full `aegisinfo/aegiscode` coding-assistant CLI. Untouched. |
61
+ | `aegiscode-cli` | 4.0.3, an earlier name of this CLI's predecessor line. Untouched. |
62
62
  | `aegis-cli` | 0.4.8 (unrelated). |
63
63
  | `aegis` (bin) | claimed **twice already** — by `aegiscode-cli` (→ `bin/cli.js`) and by `aegis-desktop` (→ `bin/aegis.js`). Pre-existing; whichever installs last wins. |
64
64
 
65
65
  Publishing this host as `aegiscode` moves the `latest` dist-tag for that name
66
- onto it. The previous line (`aegiscode@5.x`, the `aegisinfo/aegiscode` agent) is
66
+ onto it. The previous line (`aegiscode@5.x`, the earlier agent build) is
67
67
  still installable and immutable on the registry — pin `aegiscode@5` for it.
68
68
 
69
69
  ## Installation
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "aegiscode",
3
3
  "productName": "AEGIS Code",
4
- "version": "6.8.4",
4
+ "version": "6.8.6",
5
5
  "description": "aegiscode — the command-line version of AEGIS Desktop. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
6
6
  "author": {
7
7
  "name": "AEGIS Code",
@@ -9,11 +9,6 @@
9
9
  },
10
10
  "license": "MIT",
11
11
  "homepage": "https://aegiscloud.org",
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/aegisinfo/aegiscode-plugin.git",
15
- "directory": "cli"
16
- },
17
12
  "bin": {
18
13
  "aegiscode": "bin/aegiscode.js"
19
14
  },
@@ -116,6 +116,13 @@ const FILES = [
116
116
  // both sit above; `queue.js` requires only node builtins.
117
117
  'desktop/lib/local/queue.js',
118
118
  'desktop/lib/local/autonomous.js',
119
+ // The shared Pro gate. `autonomous.js` requires `src/entitlement.js` at load
120
+ // time, and that module locates this file by EXISTENCE through
121
+ // `resolveShared` — never by a fallback copy — so a vendor tree missing it
122
+ // throws before the CLI can print its usage, the same failure class as 6.5.6.
123
+ // The module requires nothing at all: the account probe is injected by the
124
+ // caller, which is why staging it alone is enough.
125
+ 'desktop/lib/local/entitlement.js',
119
126
  ];
120
127
 
121
128
  function main() {
package/src/agents.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * Sub-agent prompt presets — ported verbatim from aegiscodex-dev/src/agents.js
4
+ * Sub-agent prompt presets — ported verbatim from the upstream engine reference
5
5
  * (which in turn came from the reference's slash-commands builtinCommands.ts
6
6
  * buildMultiAgents() and the research-council member prompts). This build has
7
7
  * no parallel-agent runtime, so the presets are prompt composition:
package/src/app.js CHANGED
@@ -11,7 +11,7 @@
11
11
  * lives here.
12
12
  *
13
13
  * Commands come from `./commands.js`. Each entry is either handler-backed
14
- * (`cmd.handler(c, args)`, the reference aegiscodex-dev contract), tool-backed
14
+ * (`cmd.handler(c, args)`, the upstream engine contract), tool-backed
15
15
  * (`cmd.tool` + `cmd.build`), a generic escape hatch (`cmd.generic`, `/tool`),
16
16
  * or `unavailable` (a Claude Code auth-loop command this client cannot honour).
17
17
  * Handlers run against the FROZEN command context built below; the tool path
@@ -112,7 +112,7 @@ function createApp(options = {}) {
112
112
  // survive a new shell, and until it is *stored* every one of those launches
113
113
  // is "no key" with no in-band way to set one. An injected client keeps
114
114
  // whatever key it was built with.
115
- const client = options.client || createClient(credentials.clientOptions());
115
+ const client = options.client || createClient(credentials.clientOptions({ channel: 'cli' }));
116
116
  const { TOOLS, toolList } = options.tools || createTools(client);
117
117
 
118
118
  // Tool-approval gate (exec/writeFile/editFile confirm before running).
package/src/autonomous.js CHANGED
@@ -136,12 +136,26 @@ function printRunReport(ran, io) {
136
136
  */
137
137
  function buildEngine({ io, quiet = false }) {
138
138
  const credentials = require('./credentials.js');
139
- const client = require('./deps.js').createClient(credentials.clientOptions());
139
+ const client = require('./deps.js').createClient(credentials.clientOptions({ channel: 'cli' }));
140
140
  if (!client.apiKey) {
141
- return { error: `no AEGIS account key — ${credentials.HOW_TO_SET}, or set $${credentials.KEY_ENV}` };
141
+ return { error: `no AEGIS account key — ${credentials.HOW_TO_SET}, or set ${credentials.KEY_ENV}` };
142
142
  }
143
143
  const engine = createEngine({ client, getConfirmMode: () => false });
144
- return { client, engine };
144
+ // The Pro gate (Phase 7). Built from the SAME shared decision the desktop
145
+ // uses, bound to this host's channel so a refusal links `?s=cli` and not
146
+ // `?s=desktop` — see cli/src/entitlement.js. Passed to the worker below as
147
+ // `canFanOut`, which is the seam the shared worker already had and this host
148
+ // never supplied (so it defaulted to "yes" and the fan-out was free here).
149
+ let entitlement = null;
150
+ try {
151
+ entitlement = require('./entitlement.js').createCliEntitlement({ aegis: client });
152
+ } catch {
153
+ // A gate that cannot be built must not be a gate that says yes. The worker
154
+ // fails closed on a missing predicate (`safeCanFanOut`), so leaving this
155
+ // null clamps the drain to single passes rather than spending the fan-out.
156
+ entitlement = null;
157
+ }
158
+ return { client, engine, entitlement };
145
159
  }
146
160
 
147
161
  /** A progress sink for a headless drain: one line per step, never a chat delta. */
@@ -169,6 +183,14 @@ function progressSink(io, { json }) {
169
183
  io.stdout.write(`aegiscode: PLAN.md status list healed for phase(s) ${event.phases.join(', ')}\n`);
170
184
  return;
171
185
  }
186
+ // `note` is how the shared worker reports the fan-out clamp ("this task ran
187
+ // as a single pass"). It was emitted and then dropped on the floor here,
188
+ // which made the gate invisible from the terminal: a drain that silently
189
+ // ran one worker looked identical to one that was entitled to eight.
190
+ if (event.type === 'note' && event.note) {
191
+ io.stderr.write(` ⓘ ${event.note}\n`);
192
+ return;
193
+ }
172
194
  if (event.type === 'recovered') {
173
195
  io.stdout.write(`aegiscode: re-queued task(s) ${event.ids.join(', ')} from a dead worker\n`);
174
196
  }
@@ -277,11 +299,79 @@ async function runQueueCommand(command, argv, io = {}) {
277
299
  stderr.write(`aegiscode autonomous: ${built.error}\n`);
278
300
  return 2;
279
301
  }
302
+ // Read the gate BEFORE the first task, not lazily per task. A snapshot that
303
+ // was never refreshed reads as `unresolved`, which `current()` reports as
304
+ // free — so a PRO account would have its fan-out quietly clamped to a single
305
+ // pass for the whole drain. That is the gate failing in the direction that
306
+ // takes the paid feature away from the paying customer, so one awaited read
307
+ // happens up front and the rest of the drain answers from the cached
308
+ // snapshot (TTL a minute — see DEFAULT_TTL_MS; a drain must not probe per
309
+ // task).
310
+ if (built.entitlement) {
311
+ try {
312
+ await built.entitlement.refresh();
313
+ } catch {
314
+ // Unreachable leaves the snapshot unresolved, i.e. free. Fail-closed is
315
+ // the right direction: the alternative lets a network blip hand out the
316
+ // paid fan-out.
317
+ }
318
+ }
280
319
  const worker = autonomous.createQueueWorker({
281
320
  engine: built.engine,
282
321
  env: process.env,
283
322
  log: progressSink(out, { json }),
323
+ // THE SEAM THIS HOST NEVER SUPPLIED. `createQueueWorker` defaults this to
324
+ // `() => true`, so until now a fan-out asked for in the terminal — or
325
+ // written into queue.jsonl by hand, or left there by another host's older
326
+ // build — spent the multiplier the gate exists to withhold, with no window
327
+ // and nobody to ask. The shared worker already clamps it (`safeCanFanOut`),
328
+ // and a throwing predicate already fails closed; a gate that could not be
329
+ // BUILT at all must read the same way, hence the explicit null → false.
330
+ canFanOut: () => {
331
+ if (!built.entitlement) return false;
332
+ try {
333
+ const snap = built.entitlement.current();
334
+ return Boolean(snap && snap.entitled === true);
335
+ } catch {
336
+ return false;
337
+ }
338
+ },
284
339
  });
340
+ // One promotion per drain, not one per task: the clamp note fires for every
341
+ // fanned-out task, and repeating a checkout link eight times in a log is
342
+ // spam, not promotion. Printed only for a READ WE ACTUALLY TRUST —
343
+ // `degraded` is the module's flag for "we did not get a real answer"
344
+ // (timeout, unparseable body, missing plan field), and an upsell printed on
345
+ // the strength of a timeout is a guess wearing a price tag. `unresolved` is
346
+ // the same rule one level up: the boot snapshot, which nobody asked.
347
+ if (built.entitlement) {
348
+ try {
349
+ const snap = built.entitlement.current();
350
+ if (snap && snap.entitled === false && snap.degraded === false && snap.refusal) {
351
+ stderr.write(`aegiscode autonomous: ${snap.refusal}\n`);
352
+ // The ask, in the message, as an example to write — not as a feature
353
+ // name to decode. `autonomously` is the word the drain actually reads
354
+ // (queue.js stores the inverse as `singlePass`), so the terminal shows
355
+ // the sentence to type.
356
+ stderr.write(' ↳ write tasks like: Do X autonomously\n');
357
+ // HOW to unlock, and it names BOTH routes because there are two:
358
+ // `entitlement.js` sets `entitled = pro || banked`, where the bank is
359
+ // the operator's own lever (aegis1 admin `add_funds`). Printing only
360
+ // "upgrade" would send a user with an empty bank to the plan page when
361
+ // topping up is the action that clears their wall — `snap.wall` is the
362
+ // module's own word for which wall this is, so the line follows it
363
+ // instead of guessing.
364
+ stderr.write(
365
+ snap.wall === 'balance'
366
+ ? ' ↳ unlock: top up the Token Bank, or upgrade to Pro\n'
367
+ : ' ↳ unlock: Pro, or any Token Bank balance\n'
368
+ );
369
+ if (snap.upgradeUrl) stderr.write(` ${snap.upgradeUrl}\n`);
370
+ }
371
+ } catch {
372
+ // A snapshot that cannot be read prints nothing — same rule as above.
373
+ }
374
+ }
285
375
  const commit = args.flags.commit ? true : undefined;
286
376
  const onSigint = () => {
287
377
  // Ctrl-C stops the RUNNING turn, not the process: the task is settled back
package/src/caps.js CHANGED
@@ -55,7 +55,7 @@
55
55
 
56
56
  // ── the cell-width core ──────────────────────────────────────────────────────
57
57
  // Real terminal cell width (wcwidth-style), copied verbatim from
58
- // aegiscodex-dev/src/screen.js. Combining marks and variation selectors occupy
58
+ // the upstream engine reference. Combining marks and variation selectors occupy
59
59
  // no cell; CJK fullwidth forms and emoji-presentation glyphs occupy two;
60
60
  // everything else one. A plain code-point count misaligns every width decision
61
61
  // the moment a line contains CJK, emoji or a terminal's wide fallback glyph.
package/src/chatflow.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * The chatflow — the full-screen session loop, and the row/render helpers it
5
5
  * runs on.
6
6
  *
7
- * This is the aegiscodex-dev session loop: an alternate-screen frame of
7
+ * This is the upstream engine session loop: an alternate-screen frame of
8
8
  *
9
9
  * ╭──── AEGIS Code v6.2.0 ────╮ header rule
10
10
  * …transcript viewport… user rows, assistant markdown, tool rows
package/src/checkpoint.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * (bounded to the last CHECKPOINT_LIMIT), and /rewind lists or restores them.
7
7
  * Checkpoint 0 is the session start (empty transcript).
8
8
  *
9
- * Ported from aegiscodex-dev/src/checkpoint.js (ESM → CommonJS). The data dir
9
+ * Ported from the upstream engine reference (ESM → CommonJS). The data dir
10
10
  * now comes from config.js's shared `aegisDir()` helper.
11
11
  */
12
12
 
package/src/clipboard.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * clipboard availability. Set AEGISCODE_NO_CLIPBOARD=1 to force the file
8
8
  * fallback (used by tests and headless setups).
9
9
  *
10
- * Ported from aegiscodex-dev/src/clipboard.js (ESM → CommonJS). The data dir
10
+ * Ported from the upstream engine reference (ESM → CommonJS). The data dir
11
11
  * comes from the shared `aegisDir()` helper and the force-fallback env var was
12
12
  * renamed AEGISCODEX_NO_CLIPBOARD → AEGISCODE_NO_CLIPBOARD.
13
13
  */
package/src/commands.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  * Slash commands — the CLI's full command vocabulary, ported from the sibling
5
- * `aegiscodex-dev` client (`src/registry.js`), on top of the AEGIS tool registry
5
+ * the upstream engine client (`src/registry.js`), on top of the AEGIS tool registry
6
6
  * (`mcp/tools.js`).
7
7
  *
8
8
  * Three kinds of entry live in one table:
@@ -10,7 +10,7 @@
10
10
  * (a) handler — a local `async (c, args) => bool` that runs against the
11
11
  * frozen command context `c` (see `cli/src/app.js`). It returns false to
12
12
  * end the session. This is the reference's own contract, so a handler
13
- * body reads the same here as it does in aegiscodex-dev — only the panels
13
+ * body reads the same here as it does in the upstream engine — only the panels
14
14
  * and support modules it calls are this client's.
15
15
  * (b) tool-backed — names a tool from `mcp/tools.js` and carries a
16
16
  * `build(arg) -> object` that turns the typed argument into the tool's
@@ -23,7 +23,7 @@
23
23
  * reason and a working `alt`; `parseLine` returns `{ kind: 'unavailable' }`
24
24
  * and `app.js` prints the reason rather than a fake success.
25
25
  *
26
- * The names, aliases, categories and descriptions come from aegiscodex-dev's
26
+ * The names, aliases, categories and descriptions come from the upstream engine's
27
27
  * `COMMANDS`/`CATEGORIES`. Where this client's capability genuinely differs from
28
28
  * the reference's the handler says so honestly (a note, an honest panel, or a
29
29
  * real command run through the ported support modules) rather than copying a
@@ -127,7 +127,7 @@ const shortCwd = () => process.cwd().split('/').filter(Boolean).pop() || '~';
127
127
  // paste-ready panel and never executed anything at all, so its `savePermissions
128
128
  // ({ defaultMode: 'allow' })` turned YOLO on and then did nothing with it.
129
129
  //
130
- // The reference (aegiscodex-dev) calls `multiData(task, { signal })`, which
130
+ // The upstream engine calls `multiData(task, { signal })`, which
131
131
  // shells out to aegis-cli (`aegis --print "/multi <task>"`) because the fan-out
132
132
  // lives in that binary. This host has no aegis-cli, and a shell-out that fails
133
133
  // on every machine without one is not a port — so the real multi-agent runtime
@@ -1531,7 +1531,7 @@ const COMMANDS = [
1531
1531
  },
1532
1532
  },
1533
1533
 
1534
- // ── Phase 6 (part 2) families ─────────────────────────────────────────────
1534
+ // ── additional command families ─────────────────────────────────────────────
1535
1535
  {
1536
1536
  name: 'new', aliases: ['start'], hint: '', category: 'session',
1537
1537
  desc: 'Start a new session (clears the transcript, fresh session id)',
package/src/config.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * can redirect the data dir. Reads and writes are best-effort: a corrupt
7
7
  * config falls back to defaults, and write failures never crash the session.
8
8
  *
9
- * Ported from aegiscodex-dev/src/config.js (ESM → CommonJS). The data dir was
9
+ * Ported from the upstream engine reference (ESM → CommonJS). The data dir was
10
10
  * renamed ~/.aegiscodex → ~/.aegiscode and the override env var
11
11
  * AEGISCODEX_HOME → AEGISCODE_HOME; `aegisDir` is the one shared helper every
12
12
  * other module imports rather than recomputing the path.
@@ -68,7 +68,7 @@ const DEFAULT_CONFIG = {
68
68
  // back to. Defaulted to the pooled class, which is the only one an account
69
69
  // key alone can run.
70
70
  modelClass: 'aegis',
71
- // Phase 6: the full model table (seeded from src/models.js MODELS on first
71
+ // The full model table (seeded from src/models.js MODELS on first
72
72
  // read by pickerModels()). 'currentModelId' mirrors `model` under the
73
73
  // aegiscode- name so /model add/remove/switch stay compatible both ways.
74
74
  models: null,
package/src/devrun.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * sub-shell. Output streams to the transcript as it happens; the session loop
6
6
  * can stop the process (Esc) via the returned job handle.
7
7
  *
8
- * Ported from aegiscodex-dev/src/devrun.js (ESM → CommonJS).
8
+ * Ported from the upstream engine reference (ESM → CommonJS).
9
9
  */
10
10
 
11
11
  const { spawn } = require('node:child_process');
package/src/diff.js CHANGED
@@ -21,7 +21,7 @@
21
21
  * ANSI painting lives in diffview.js, exactly the split render.js already
22
22
  * keeps between structure and paint.
23
23
  *
24
- * Ported from `aegiscodex-dev/src/diff.js`; the engine's tool names are
24
+ * Ported from the upstream engine reference; the engine's tool names are
25
25
  * `Edit`/`Write`/`MultiEdit`, this host's are `editFile`/`writeFile`, so
26
26
  * `editPreview` accepts both spellings. `MultiEdit` has no counterpart here
27
27
  * and is kept only so a newer engine frame cannot silently render nothing.
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * entitlement.js — the terminal host's binding to the SHARED Pro gate.
5
+ *
6
+ * WHY THIS FILE EXISTS (and why it is six lines of real work). The gate that
7
+ * decides who may spend the fan-out lives in
8
+ * `desktop/lib/local/entitlement.js`, and the CLI has been the leak since the
9
+ * day it landed: `autonomous.js` drives the SAME queue file through the SAME
10
+ * worker, `createWorker` takes a `canFanOut` predicate, and the CLI simply
11
+ * never passed one — so it defaulted to `() => true`. A task queued with
12
+ * `--workers 8` or written into queue.jsonl by hand fans out on the free tier
13
+ * from `ssh box 'aegiscode autonomous proceed'`, costing the multiplier the
14
+ * gate exists to withhold, with no window and nobody to ask.
15
+ *
16
+ * The desktop's own comment named this as a known gap ("the CLI's own drain is
17
+ * a different host with no session to ask"). It had a session — it has the same
18
+ * account key in the same 0600 store, read through the same shared client. It
19
+ * was a wiring omission, not an architectural one.
20
+ *
21
+ * TWO THINGS ARE HOST-SPECIFIC, and both are handled by the shared module's own
22
+ * seams rather than reimplemented here:
23
+ *
24
+ * 1. THE CHANNEL. `host: 'cli'` makes every refusal link
25
+ * `/go/upgrade?s=cli&…`, so a terminal click is filed as a CLI conversion
26
+ * instead of a desktop one. The desktop's literals hardcode `s=desktop`;
27
+ * printing one from the terminal would have quietly moved every CLI
28
+ * conversion into the desktop's column.
29
+ * 2. THE PROBE. The CLI has no Electron session, so it builds the same
30
+ * reading the desktop builds — `verifyApiKey()` for the plan plus
31
+ * `tokenBankBalance()` for the operator's balance — from the shared client
32
+ * directly.
33
+ *
34
+ * Not reimplemented, deliberately: the plan vocabulary, the balance
35
+ * interpretation, the fail-closed rules, the refusal copy, the campaign ids.
36
+ * Two implementations of "is this account paid" is exactly how the terminal and
37
+ * the GUI would come to disagree about who owes money — and the disagreement
38
+ * would spend real money, in whichever host had the looser copy.
39
+ *
40
+ * Wired through `sharedpaths.js` (paths, no eager requires) rather than
41
+ * `deps.js`, because `deps.js` eagerly loads `autonomous.js`, which loads THIS
42
+ * file back: requiring deps.js here would be a require cycle handing one side a
43
+ * half-built exports object. Same reason `sharedpaths.js` was split out.
44
+ */
45
+
46
+ const { resolveShared } = require('./sharedpaths.js');
47
+
48
+ /** The shared decision, resolved by existence (repo checkout or staged tree). */
49
+ function loadModule() {
50
+ // eslint-disable-next-line global-require
51
+ return require(resolveShared('desktop/lib/local/entitlement.js'));
52
+ }
53
+
54
+ /** The shared thin transport, same two-layout resolution as deps.js. */
55
+ function loadClient() {
56
+ // eslint-disable-next-line global-require
57
+ const { createClient } = require(resolveShared('client/aegis.js'));
58
+ const credentials = require('./credentials.js');
59
+ return createClient(credentials.clientOptions({ channel: 'cli' }));
60
+ }
61
+
62
+ /**
63
+ * The account probe, shaped exactly as the desktop builds it.
64
+ *
65
+ * A failed balance call leaves the balance UNKNOWN rather than inventing a
66
+ * zero: an unreadable bank must never manufacture a top-up prompt, and
67
+ * `classifyProbe` fails closed on the unknown anyway. Both calls are read-only
68
+ * and neither writes server-side — the gate observes the operator's number, it
69
+ * never sets one.
70
+ */
71
+ function buildProbe(aegis) {
72
+ if (!aegis || typeof aegis.verifyApiKey !== 'function') return undefined;
73
+ return async () => {
74
+ const verify = await aegis.verifyApiKey();
75
+ const body = verify && typeof verify === 'object' ? { ...verify } : {};
76
+ if (typeof aegis.tokenBankBalance === 'function') {
77
+ try {
78
+ const bank = await aegis.tokenBankBalance();
79
+ if (bank && typeof bank === 'object') {
80
+ if (bank.balance_micros != null) body.balance_micros = bank.balance_micros;
81
+ else if (bank.balance_eur != null) body.balance_eur = bank.balance_eur;
82
+ }
83
+ } catch {
84
+ // Unknown stays unknown — see the docstring above.
85
+ }
86
+ }
87
+ return body;
88
+ };
89
+ }
90
+
91
+ /**
92
+ * The gate for one CLI process, reading the SAME account the desktop reads.
93
+ *
94
+ * `host: 'cli'` is the whole reason campaign links can be trusted from here.
95
+ * Returns the shared gate object: `{ refresh, current, gateFanout }`.
96
+ */
97
+ function createCliEntitlement({ aegis, now, ttlMs } = {}) {
98
+ const mod = loadModule();
99
+ const client = aegis || loadClient();
100
+ return mod.createEntitlement({
101
+ probe: buildProbe(client),
102
+ host: 'cli',
103
+ ...(now ? { now } : {}),
104
+ ...(ttlMs ? { ttlMs } : {}),
105
+ });
106
+ }
107
+
108
+ module.exports = { createCliEntitlement, buildProbe, loadModule };
package/src/events.js CHANGED
@@ -15,7 +15,7 @@
15
15
  * · SGR mouse wheel events (DECSET 1000+1006), decoded to `{name:'wheel'}`
16
16
  * instead of being mistaken for Escape (which would abort a working turn).
17
17
  *
18
- * Ported from `aegiscodex-dev/src/events.js`. It is a module-level singleton —
18
+ * Ported from the upstream engine reference. It is a module-level singleton —
19
19
  * one stdin, one queue — which is what lets the session loop, a command
20
20
  * handler's `askInput()`, and the mid-turn Esc drain all read keys through the
21
21
  * same nextKey() without fighting over the `data` listener.
@@ -209,7 +209,7 @@ function feed(c) {
209
209
  * one. Right/middle clicks and anything unrecognized return null, and the
210
210
  * caller then falls through to the ordinary CSI decoder, which ignores it — so
211
211
  * stray mouse bytes can't type into the editor or abort a turn.
212
- * Ported from aegiscodex-dev/src/events.js so both hosts mark identically.
212
+ * Ported from the upstream engine reference so both hosts mark identically.
213
213
  */
214
214
  function parseSgrMouse(seq) {
215
215
  const m = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])$/.exec(seq);
package/src/export.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * extraction for /copy. Exports are written to the current directory (or the
6
6
  * clipboard) and the resulting path is reported in the transcript.
7
7
  *
8
- * Ported from aegiscodex-dev/src/export.js (ESM → CommonJS). Output strings
8
+ * Ported from the upstream engine reference (ESM → CommonJS). Output strings
9
9
  * (the # Aegiscodex session header, the ## Claude / ## User role headers, the
10
10
  * aegiscodex-export- filename) are kept as in the reference.
11
11
  */
package/src/fuzzy.js CHANGED
@@ -14,7 +14,7 @@
14
14
  // substring 700 − position (earlier substring wins)
15
15
  // scattered 50 + bonuses (consecutive runs, name-start hits)
16
16
  //
17
- // Ported verbatim from aegiscodex-dev/src/fuzzy.js (ESM → CommonJS). The tier
17
+ // Ported verbatim from the upstream engine reference (ESM → CommonJS). The tier
18
18
  // numbers are a contract: cli-fuzzy.test.mjs asserts the ordering they encode.
19
19
 
20
20
  function fuzzyScore(query, name) {
package/src/history.js CHANGED
@@ -16,7 +16,7 @@
16
16
  * and without a key. `readResumeList` merges both sources by id, so no session
17
17
  * is listed twice.
18
18
  *
19
- * Ported from aegiscodex-dev/src/history.js (ESM → CommonJS). The data dir now
19
+ * Ported from the upstream engine reference (ESM → CommonJS). The data dir now
20
20
  * comes from config.js's shared `aegisDir()` helper.
21
21
  */
22
22
 
@@ -41,7 +41,7 @@ function ensureHistoryDir() {
41
41
 
42
42
  /**
43
43
  * Record one exchange. `reply` is stored in full so /resume can restore the
44
- * transcript exactly. Token accounting (Phase 4):
44
+ * transcript exactly. Token accounting:
45
45
  * live — `usage` carries the real numbers from the provider stream-json
46
46
  * (input/output/cacheRead/cacheWrite + costUsd), stored verbatim;
47
47
  * demo — estimated from text length (~4 chars/token), labeled real:false.
@@ -211,7 +211,7 @@ function sessionHistoryEntries(sessionId) {
211
211
  }
212
212
 
213
213
  /**
214
- * Drop every history record for a session (Phase 10b, 2.1.228 port). /clear
214
+ * Drop every history record for a session. /clear
215
215
  * calls this so /cost stops summing old rows — the sessionId stays stable, so
216
216
  * rewind checkpoints and the transcript lineage are unaffected.
217
217
  */
package/src/init.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * and generate an AEGIS.md with real project instructions. Never overwrites an
6
6
  * existing file — the handler reports and leaves the file alone.
7
7
  *
8
- * Ported from aegiscodex-dev/src/init.js (ESM → CommonJS). The reference wrote
8
+ * Ported from the upstream engine reference (ESM → CommonJS). The reference wrote
9
9
  * a CLAUDE.md; this build writes AEGIS.md and the generated document is headed
10
10
  * "# AEGIS.md" and references "AEGIS Code". The `buildClaudeMd` export is kept
11
11
  * as an alias of `buildAegisMd` so callers ported from the reference still
package/src/input.js CHANGED
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * Line editor with history — the input line's buffer, cursor and recall.
5
5
  *
6
- * Ported from `aegiscodex-dev/src/input.js`. The one thing worth knowing before
6
+ * Ported from the upstream engine reference. The one thing worth knowing before
7
7
  * touching it: `cursor` is a **codepoint** index, not a UTF-16 index. Slicing
8
8
  * `buf` directly corrupts a surrogate pair the moment one has been inserted
9
9
  * (the next insert's slice lands mid-pair and leaves a lone surrogate, which
package/src/keys.js CHANGED
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * Raw key decoding for the terminal (raw-mode stdin).
5
5
  *
6
- * Ported from `aegiscodex-dev/src/keys.js` so the aegiscode CLI and the
6
+ * Ported from the upstream engine reference so the aegiscode CLI and the
7
7
  * reference client decode the same bytes into the same key names — the
8
8
  * chatflow's key handling (history recall, vim motions, Esc-to-interrupt) is
9
9
  * only correct if the decoder agrees with it.
package/src/markdown.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // Minimal markdown → styled span lines, in the spirit of Claude Code's
4
4
  // transcript rendering (monokai-flavored code, bold text, inline code).
5
5
  //
6
- // Ported from aegiscodex-dev/src/markdown.js (ESM → CommonJS). The one
6
+ // Ported from the upstream engine reference (ESM → CommonJS). The one
7
7
  // structural change: instead of importing `span`/`w` from screen.js — which a
8
8
  // concurrent workstream is rewriting — this module carries a local cell-width
9
9
  // function and a local `span()` that produce the *same* shape the rest of the
@@ -24,7 +24,7 @@ const {
24
24
  themeOf,
25
25
  } = require('./theme.js');
26
26
 
27
- // Real terminal cell width, mirroring aegiscodex-dev/src/screen.js's w():
27
+ // Real terminal cell width, mirroring the upstream engine's w():
28
28
  // combining marks / variation selectors are zero-width, CJK fullwidth forms and
29
29
  // emoji are two cells, everything else one. A plain codepoint count misaligns
30
30
  // every width decision the moment a line contains CJK or emoji.
package/src/overlays.js CHANGED
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * Overlay renderers — the "/" command palette, the alt+p model picker, the
5
5
  * /effort picker and the /resume session list. Ported from
6
- * `aegiscodex-dev/src/commands.js` (which mirrors live captures of Claude Code
6
+ * the upstream engine reference (which mirrors live captures of Claude Code
7
7
  * 2.1.228: a gray `─` rule, a lavender `❯` cursor, a blue selected row, a
8
8
  * `⎿ Usage: /x hint` hook under the focused command and a `·`-separated footer).
9
9
  *
@@ -58,7 +58,7 @@ function fit(lines, width) {
58
58
  /** A full-width blank row. */
59
59
  const blank = (width) => [span('', ' '.repeat(Math.max(0, width)))];
60
60
 
61
- // Phase 10b (2.1.228 port): split a command name into spans that bold the
61
+ // Split a command name into spans that bold the
62
62
  // characters which matched the query; the selected row reads blue.
63
63
  function boldMatched(query, name, colour) {
64
64
  const pos = fuzzy && typeof fuzzy.fuzzyMatchPositions === 'function'
package/src/panels.js CHANGED
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * Panel builders — the bodies that slash-commands print.
5
5
  *
6
- * Ported from `aegiscodex-dev/src/panels.js` (868 lines), keeping its layouts
6
+ * Ported from the upstream engine reference (868 lines), keeping its layouts
7
7
  * and copy wherever the capability exists in this client. Everything here is
8
8
  * PURE: a builder receives all of its data as arguments and returns an array of
9
9
  * span lines (each line an array of `{ t, s, w }`, see `screen.js`). No stdout
@@ -14,8 +14,8 @@
14
14
  * module-scoped palette. Money is euro: `fmtEur` renders 4dp below a cent (a
15
15
  * pooled call settles near €0.0007) and 2dp at or above it, so a real charge
16
16
  * never reads as "€0.00". The reference printed USD; every `$` became `€`.
17
- * Claude/Anthropic names became AEGIS (`aegiscode`, `aegiscloud.org`,
18
- * `github.com/aegisinfo/aegiscode-plugin`) and `~/.aegiscodex` became
17
+ * Claude/Anthropic names became AEGIS (`aegiscode`, `aegiscloud.org`)
18
+ * and `~/.aegiscodex` became
19
19
  * `~/.aegiscode`.
20
20
  *
21
21
  * Every builder is defensive: a missing field is omitted, never rendered as
@@ -34,7 +34,7 @@
34
34
  *
35
35
  * ── Honest stubs (capability absent in this client) ──────────────────────────
36
36
  * buildDoctor — needs the local environment diagnostic suite (runDoctor),
37
- * which belongs to aegiscodex-dev; /doctor is unavailable.
37
+ * which belongs to the upstream engine; /doctor is unavailable.
38
38
  * buildBuildPanel — needs a local multi-model agent build loop this client
39
39
  * does not host.
40
40
  */
@@ -611,7 +611,7 @@ function buildTroubleshooting(state, ctx = {}) {
611
611
  lines.push([span('', ' '), span(t.gray, fix)]);
612
612
  }
613
613
  lines.push([span('', '')]);
614
- lines.push([span(t.gray, 'Run /status for account state. Help: https://github.com/aegisinfo/aegiscode-plugin')]);
614
+ lines.push([span(t.gray, 'Run /status for account state. Help: https://aegiscloud.org')]);
615
615
  return lines;
616
616
  }
617
617
 
@@ -1253,7 +1253,7 @@ function buildReleaseNotes(state, ctx = {}) {
1253
1253
  out.push([span(t.gray, ` ${counts.n} commands across ${counts.cats} categories — /help lists them.`)]);
1254
1254
  }
1255
1255
  out.push([span(t.gray, ' The version above is read from the package; the prose is not.')]);
1256
- out.push([span(t.gray, ' Repo: github.com/aegisinfo/aegiscode-plugin')]);
1256
+ out.push([span(t.gray, ' Repo: https://aegiscloud.org')]);
1257
1257
  return out;
1258
1258
  }
1259
1259
 
@@ -6,7 +6,7 @@
6
6
  * approval UX from the real binary, so this only applies to
7
7
  * Bash/Read/Write/Edit/Glob/Grep run by a provider model.
8
8
  *
9
- * Scope decision (Phase 12): the multi-directory-change Bash heuristic,
9
+ * Scope decision: the multi-directory-change Bash heuristic,
10
10
  * explicit /permissions allow|deny|ask rules, and `defaultMode: 'ask'` when
11
11
  * the permissions file *explicitly* writes it (rules.explicitAsk) are
12
12
  * enforced here. The file-free default ('ask' in DEFAULT_PERMISSIONS) is
@@ -24,7 +24,7 @@
24
24
  * imported so this module has no import-cycle with tools.js (executeTool's
25
25
  * home, which calls into this one).
26
26
  *
27
- * Ported from aegiscodex-dev/src/permissions.js (ESM → CommonJS).
27
+ * Ported from the upstream engine reference (ESM → CommonJS).
28
28
  */
29
29
 
30
30
  const RULE_RE = /^(\w+)(?:\((.*)\))?$/;