aegiscode 6.6.1 → 6.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/bin/aegiscode.js +87 -0
- package/package.json +1 -1
- package/src/app.js +156 -11
- package/src/art.js +114 -60
- package/src/autonomous.js +8 -2
- package/src/caps.js +597 -0
- package/src/chatflow.js +59 -6
- package/src/cloudsync.js +86 -6
- package/src/commands.js +243 -23
- package/src/config.js +87 -0
- package/src/diff.js +330 -0
- package/src/diffview.js +286 -0
- package/src/events.js +21 -10
- package/src/panels.js +59 -1
- package/src/render.js +39 -17
- package/src/screen.js +20 -20
- package/src/theme.js +334 -125
- package/vendor/desktop/lib/local/autonomous.js +45 -4
- package/vendor/desktop/lib/local/engine.js +38 -0
- package/vendor/desktop/lib/local/queue.js +4 -0
- package/vendor/desktop/lib/local/session-rounds.js +19 -2
package/src/chatflow.js
CHANGED
|
@@ -49,6 +49,8 @@ const { renderMarkdown } = require('./markdown.js');
|
|
|
49
49
|
const overlays = require('./overlays.js');
|
|
50
50
|
const fuzzy = require('./fuzzy.js');
|
|
51
51
|
const { fmtTokens, fmtEur, fmtElapsed } = require('./format.js');
|
|
52
|
+
const { editPreview } = require('./diff.js');
|
|
53
|
+
const { renderDiffBlock, defaultOpen } = require('./diffview.js');
|
|
52
54
|
|
|
53
55
|
/** The rotating placeholder shown on an empty input line. */
|
|
54
56
|
const SUGGESTIONS = [
|
|
@@ -438,6 +440,18 @@ function rowLines(msg, cols, ctx, now = Date.now()) {
|
|
|
438
440
|
} else {
|
|
439
441
|
out.push([span(t.gray, `${label}${where}`)]);
|
|
440
442
|
}
|
|
443
|
+
// An editFile/writeFile row carries a diff preview (built from the tool's
|
|
444
|
+
// `run` frame, before the executor reads/writes). Paint the colored block —
|
|
445
|
+
// summary always, body when open — instead of the gray `$ {args}` row, so
|
|
446
|
+
// the transcript shows *what* changed. renderDiffBlock emits ANSI strings,
|
|
447
|
+
// so each becomes one pre-styled span whose visible width padLine still
|
|
448
|
+
// measures and pads correctly.
|
|
449
|
+
if (msg.diff) {
|
|
450
|
+
for (const l of renderDiffBlock(msg.diff, ctx, cols, { open: !!msg.diffOpen })) {
|
|
451
|
+
out.push([span('', l)]);
|
|
452
|
+
}
|
|
453
|
+
return out;
|
|
454
|
+
}
|
|
441
455
|
const argsStr =
|
|
442
456
|
typeof msg.args === 'string'
|
|
443
457
|
? msg.args
|
|
@@ -560,21 +574,34 @@ function transcriptLines(rows, view, ctx, now = Date.now(), cache = null) {
|
|
|
560
574
|
const { cols, rows: termRows } = view;
|
|
561
575
|
const avail = Math.max(1, termRows - 6);
|
|
562
576
|
const out = [];
|
|
577
|
+
// Which transcript row produced each line, in lockstep with `out`. The frame
|
|
578
|
+
// builder needs it to map a clicked screen row back to the row it toggles.
|
|
579
|
+
const owners = [];
|
|
563
580
|
for (const msg of rows) {
|
|
564
581
|
const key = cache || null;
|
|
565
582
|
const isGrower = msg.role === 'assistant' && msg.streaming;
|
|
566
583
|
if (key && !isGrower) {
|
|
567
584
|
const hit = key.get(msg);
|
|
568
|
-
|
|
569
|
-
|
|
585
|
+
// diffOpen is part of the cache key: a toggled edit block must re-render.
|
|
586
|
+
if (hit && hit.text === msg.text && hit.cols === cols && hit.diffOpen === msg.diffOpen) {
|
|
587
|
+
for (const l of hit.segment) {
|
|
588
|
+
out.push(l);
|
|
589
|
+
owners.push(msg);
|
|
590
|
+
}
|
|
570
591
|
continue;
|
|
571
592
|
}
|
|
572
593
|
const segment = rowLines(msg, cols, ctx, now);
|
|
573
|
-
key.set(msg, { text: msg.text, cols, segment });
|
|
574
|
-
for (const l of segment)
|
|
594
|
+
key.set(msg, { text: msg.text, cols, diffOpen: msg.diffOpen, segment });
|
|
595
|
+
for (const l of segment) {
|
|
596
|
+
out.push(l);
|
|
597
|
+
owners.push(msg);
|
|
598
|
+
}
|
|
575
599
|
continue;
|
|
576
600
|
}
|
|
577
|
-
for (const l of rowLines(msg, cols, ctx, now))
|
|
601
|
+
for (const l of rowLines(msg, cols, ctx, now)) {
|
|
602
|
+
out.push(l);
|
|
603
|
+
owners.push(msg);
|
|
604
|
+
}
|
|
578
605
|
}
|
|
579
606
|
|
|
580
607
|
let scroll = view.scroll || 0;
|
|
@@ -596,7 +623,7 @@ function transcriptLines(rows, view, ctx, now = Date.now(), cache = null) {
|
|
|
596
623
|
end = total;
|
|
597
624
|
}
|
|
598
625
|
const start = Math.max(0, end - avail);
|
|
599
|
-
return { lines: out.slice(start, end), scroll, anchorEnd };
|
|
626
|
+
return { lines: out.slice(start, end), owners: owners.slice(start, end), scroll, anchorEnd };
|
|
600
627
|
}
|
|
601
628
|
|
|
602
629
|
// ── the input line ──────────────────────────────────────────────────────────
|
|
@@ -738,6 +765,10 @@ async function runSession(host) {
|
|
|
738
765
|
let suggestionIdx = 0;
|
|
739
766
|
let scroll = 0;
|
|
740
767
|
let anchorEnd = null;
|
|
768
|
+
// Screen row (1-based, as the mouse reports it) → the transcript row painted
|
|
769
|
+
// there. Rebuilt on every frame so it follows scrolling; a click reads it to
|
|
770
|
+
// find which edit block to toggle.
|
|
771
|
+
const clickHits = new Map();
|
|
741
772
|
let insertMode = false;
|
|
742
773
|
let hintUntil = 0;
|
|
743
774
|
let hintText = '';
|
|
@@ -767,6 +798,10 @@ async function runSession(host) {
|
|
|
767
798
|
const view = transcriptLines(transcript, { cols, rows, scroll, anchorEnd }, ctx, Date.now(), lineCache);
|
|
768
799
|
scroll = view.scroll;
|
|
769
800
|
anchorEnd = view.anchorEnd;
|
|
801
|
+
// The header is frame line 0 (screen row 1), so the transcript window starts
|
|
802
|
+
// at screen row 2; each painted line carries its source row in view.owners.
|
|
803
|
+
clickHits.clear();
|
|
804
|
+
for (let i = 0; i < view.lines.length; i++) clickHits.set(2 + i, view.owners[i]);
|
|
770
805
|
for (const l of view.lines) lines.push(l);
|
|
771
806
|
// Exactly `avail` transcript rows, so the frame is exactly `rows` lines:
|
|
772
807
|
// header(1) + transcript(avail) + spinner/effort + rule + input + rule +
|
|
@@ -1223,6 +1258,18 @@ async function runSession(host) {
|
|
|
1223
1258
|
if (key.name === KEY.PAGE_UP) d = +5;
|
|
1224
1259
|
else if (key.name === KEY.PAGE_DOWN) d = -5;
|
|
1225
1260
|
else if (key.name === 'wheel') d = key.dir === 'up' ? +3 : -3;
|
|
1261
|
+
else if (key.name === 'click') {
|
|
1262
|
+
// A click on an edit row toggles its diff block. Not a scroll, but the
|
|
1263
|
+
// same "act on the live frame, then repaint" shape — and routing it
|
|
1264
|
+
// through here means it works both at the idle prompt and mid-turn,
|
|
1265
|
+
// since drainWhileWorking feeds this same function.
|
|
1266
|
+
const msg = clickHits.get(key.row);
|
|
1267
|
+
if (msg && msg.diff) {
|
|
1268
|
+
msg.diffOpen = !msg.diffOpen;
|
|
1269
|
+
scheduleRender();
|
|
1270
|
+
}
|
|
1271
|
+
return true; // consumed: a click is never replayed as typed-ahead input
|
|
1272
|
+
}
|
|
1226
1273
|
else if (key.name === 'char' && ctx.vim && !insertMode && !editor.buf) {
|
|
1227
1274
|
if (key.ch === 'j') d = +1;
|
|
1228
1275
|
else if (key.ch === 'k') d = -1;
|
|
@@ -1654,6 +1701,12 @@ async function runSession(host) {
|
|
|
1654
1701
|
await dispatch('/permissions');
|
|
1655
1702
|
return;
|
|
1656
1703
|
}
|
|
1704
|
+
if (key.name === 'click') {
|
|
1705
|
+
// Consumed here: it either toggles an edit row's diff block or does
|
|
1706
|
+
// nothing, but must never fall through to the input editor.
|
|
1707
|
+
applyLiveScroll(key);
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1657
1710
|
if (key.name === KEY.PAGE_UP || key.name === KEY.PAGE_DOWN || key.name === 'wheel') {
|
|
1658
1711
|
applyLiveScroll(key);
|
|
1659
1712
|
return;
|
package/src/cloudsync.js
CHANGED
|
@@ -29,10 +29,22 @@
|
|
|
29
29
|
* Quota note, because it is the difference between a working sync and a
|
|
30
30
|
* surprise: the server charges a push for the *growth* of a session
|
|
31
31
|
* (`_session_token_delta` in aegis1's conversation_sync), refuses with 402 once
|
|
32
|
-
* the plan's synced-token ceiling would be exceeded
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
32
|
+
* the plan's synced-token ceiling would be exceeded (FREE_SYNC_TOKENS = 1 MB,
|
|
33
|
+
* PRO_SYNC_TOKENS = 10 MB), and always serves pulls. So a 402 is reported as the
|
|
34
|
+
* quota error it is instead of being swallowed into "sync failed".
|
|
35
|
+
*
|
|
36
|
+
* This used to be the reason sync was opt-IN (config `cloudSync`, default off):
|
|
37
|
+
* automatic writes against a metered ceiling felt like spending someone else's
|
|
38
|
+
* money. It is now default ON (config `memoryPersist` — see config.js for the
|
|
39
|
+
* migration), because the ceiling is not a hard stop: aegis1's
|
|
40
|
+
* `_memory_sync_access()` enforces the limit on WRITES only, so an over-quota
|
|
41
|
+
* account still reads back everything it stored. What was missing was not
|
|
42
|
+
* caution, it was honesty: a free account passes ~1 MB of transcript in weeks,
|
|
43
|
+
* and the old failure mode was a silent stop with no visible state. So this
|
|
44
|
+
* module now records the quota it is told about (`status().quota`) and
|
|
45
|
+
* classifies the refusal as "writes paused, reads fine" rather than as a
|
|
46
|
+
* generic failure — `/cloud memory` (and the first-run notice) say exactly
|
|
47
|
+
* that, and `/cloud memory off` is the explicit opt-out.
|
|
36
48
|
*/
|
|
37
49
|
|
|
38
50
|
const fs = require('node:fs');
|
|
@@ -70,10 +82,40 @@ function loadState() {
|
|
|
70
82
|
// whole transcript, so every pull duplicated every earlier exchange and
|
|
71
83
|
// /cost doubled with each sync.
|
|
72
84
|
importedRemoteCount: parsed.importedRemoteCount || {},
|
|
85
|
+
// The last quota the server told us about — `{ used, limit, at, over }`.
|
|
86
|
+
// Persisted because it is the only way the NEXT run can say "you are at
|
|
87
|
+
// the ceiling, only new writes are paused" before it has re-attempted a
|
|
88
|
+
// push: without it, a restarted session looks identical to a fresh one
|
|
89
|
+
// and the over-quota state is invisible until the next refused write.
|
|
90
|
+
quota: parsed.quota && typeof parsed.quota === 'object' ? parsed.quota : null,
|
|
73
91
|
};
|
|
74
92
|
}
|
|
75
93
|
} catch {}
|
|
76
|
-
return {
|
|
94
|
+
return {
|
|
95
|
+
sessions: {},
|
|
96
|
+
lastPushAt: null,
|
|
97
|
+
lastPullAt: null,
|
|
98
|
+
importedRemoteAt: {},
|
|
99
|
+
importedRemoteCount: {},
|
|
100
|
+
quota: null,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Remember a quota reading from either half of a response — the numbers ride on
|
|
106
|
+
* a successful push (`token_limit` / `tokens_used`) as well as on the 402 body,
|
|
107
|
+
* and both are worth keeping.
|
|
108
|
+
*
|
|
109
|
+
* `over` is derived here, once, so every surface (status panel, first-run
|
|
110
|
+
* notice, auto-sync refusal) agrees about what "at the ceiling" means instead
|
|
111
|
+
* of each comparing used >= limit on its own.
|
|
112
|
+
*/
|
|
113
|
+
function recordQuota(state, used, limit) {
|
|
114
|
+
const u = Number(used);
|
|
115
|
+
const l = Number(limit);
|
|
116
|
+
if (!state || !Number.isFinite(u) || !Number.isFinite(l) || l <= 0) return null;
|
|
117
|
+
state.quota = { used: u, limit: l, over: u >= l, at: Date.now() };
|
|
118
|
+
return state.quota;
|
|
77
119
|
}
|
|
78
120
|
|
|
79
121
|
function saveState(state) {
|
|
@@ -217,7 +259,23 @@ function describeError(err) {
|
|
|
217
259
|
const status = err && (err.status || (err.response && err.response.status));
|
|
218
260
|
const message = (err && err.message) || String(err);
|
|
219
261
|
if (status === 402) {
|
|
220
|
-
|
|
262
|
+
// The 402 body carries the quota (`tokensUsed` / `tokenLimit`, from aegis1
|
|
263
|
+
// `_token_quota_fields`); the legacy session-named keys are read only as a
|
|
264
|
+
// fallback for a server that predates the rename.
|
|
265
|
+
const data = (err && err.data) || {};
|
|
266
|
+
const used = data.tokensUsed != null ? data.tokensUsed : data.sessionsUsed;
|
|
267
|
+
const limit = data.tokenLimit != null ? data.tokenLimit : data.freeSessionLimit;
|
|
268
|
+
return {
|
|
269
|
+
kind: 'quota',
|
|
270
|
+
status,
|
|
271
|
+
message,
|
|
272
|
+
used: used != null ? Number(used) : null,
|
|
273
|
+
limit: limit != null ? Number(limit) : null,
|
|
274
|
+
// The refusal is about WRITES only — say what still works and how to stop
|
|
275
|
+
// trying, instead of implying the account lost its memory.
|
|
276
|
+
hint:
|
|
277
|
+
'the plan’s synced-token ceiling is reached — everything already stored stays readable, only NEW writes pause: /cloud memory shows the quota, /cloud memory off stops syncing',
|
|
278
|
+
};
|
|
221
279
|
}
|
|
222
280
|
if (status === 401) {
|
|
223
281
|
return { kind: 'auth', status, message, hint: 'the memory token was refused — run /key <api_key> to re-exchange it' };
|
|
@@ -263,11 +321,22 @@ async function push(client, o = {}) {
|
|
|
263
321
|
title: transcript.title,
|
|
264
322
|
quota: res && res.token_limit ? { used: res.tokens_used, limit: res.token_limit } : null,
|
|
265
323
|
});
|
|
324
|
+
// A successful push is also a quota reading — the response reports the
|
|
325
|
+
// running total, which is how the status panel can show "43k of 1M" on a
|
|
326
|
+
// healthy account instead of only ever saying something when it breaks.
|
|
327
|
+
if (res && res.token_limit != null) recordQuota(state, res.tokens_used, res.token_limit);
|
|
266
328
|
if (typeof o.onProgress === 'function') o.onProgress({ phase: 'push', id: session.id });
|
|
267
329
|
} catch (err) {
|
|
268
330
|
const info = describeError(err);
|
|
269
331
|
markFailed(state, session.id, info.message);
|
|
270
332
|
failed.push({ id: session.id, ...info });
|
|
333
|
+
// Record the ceiling state even when the body carried no numbers: the
|
|
334
|
+
// point of the honesty fix is that the stopped state is visible, and a
|
|
335
|
+
// server that refuses without reporting a limit must not produce a status
|
|
336
|
+
// panel that looks healthy.
|
|
337
|
+
if (info.kind === 'quota' && !recordQuota(state, info.used, info.limit)) {
|
|
338
|
+
state.quota = { used: null, limit: null, over: true, at: Date.now() };
|
|
339
|
+
}
|
|
271
340
|
if (info.kind === 'quota' || info.kind === 'auth') break; // every later one fails the same way
|
|
272
341
|
}
|
|
273
342
|
}
|
|
@@ -367,6 +436,8 @@ function status() {
|
|
|
367
436
|
const errors = sessions
|
|
368
437
|
.filter((s) => state.sessions[s.id] && state.sessions[s.id].lastError)
|
|
369
438
|
.map((s) => ({ id: s.id, error: state.sessions[s.id].lastError }));
|
|
439
|
+
const quota = state.quota || null;
|
|
440
|
+
const overQuota = Boolean(quota && quota.over);
|
|
370
441
|
return {
|
|
371
442
|
local: sessions.length,
|
|
372
443
|
pending: pending.length,
|
|
@@ -375,6 +446,14 @@ function status() {
|
|
|
375
446
|
lastPullAt: state.lastPullAt,
|
|
376
447
|
importedRemote: Object.keys(state.importedRemoteAt || {}).length,
|
|
377
448
|
errors,
|
|
449
|
+
// The ceiling, as last reported by the server, plus whether new writes are
|
|
450
|
+
// currently stopped by it. `paused` is the combination the panels print:
|
|
451
|
+
// there is local work waiting AND the last thing the server said was "no
|
|
452
|
+
// room". Both halves matter — a full account with nothing pending is not
|
|
453
|
+
// stuck, it is caught up.
|
|
454
|
+
quota,
|
|
455
|
+
overQuota,
|
|
456
|
+
paused: overQuota && pending.length > 0,
|
|
378
457
|
path: syncStatePath(),
|
|
379
458
|
historyPath: historyPath(),
|
|
380
459
|
};
|
|
@@ -394,6 +473,7 @@ module.exports = {
|
|
|
394
473
|
markFailed,
|
|
395
474
|
entriesFromRemote,
|
|
396
475
|
describeError,
|
|
476
|
+
recordQuota,
|
|
397
477
|
push,
|
|
398
478
|
pull,
|
|
399
479
|
syncNow,
|
package/src/commands.js
CHANGED
|
@@ -45,11 +45,15 @@ const { execSync } = require('node:child_process');
|
|
|
45
45
|
|
|
46
46
|
const { span } = require('./screen.js');
|
|
47
47
|
const { C, BOLD, BOLD_OFF } = require('./theme.js');
|
|
48
|
+
// `caps.js` is dependency-free (it requires nothing), so this cannot cycle the
|
|
49
|
+
// way a `theme.js` → `art.js` → `theme.js` require would.
|
|
50
|
+
const { caps, setCaps, resetCaps, describe } = require('./caps.js');
|
|
48
51
|
const panels = require('./panels.js');
|
|
49
52
|
const overlays = require('./overlays.js');
|
|
50
53
|
const {
|
|
51
54
|
updateConfig, loadConfig, loadPermissions, savePermissions, addPermissionRule,
|
|
52
55
|
DEFAULT_PERMISSIONS, permissionsPath, configPath,
|
|
56
|
+
memoryPersistState, setMemoryPersist,
|
|
53
57
|
} = require('./config.js');
|
|
54
58
|
const { copyToClipboard } = require('./clipboard.js');
|
|
55
59
|
const { snapshotCheckpoint, listCheckpoints, loadCheckpoint } = require('./checkpoint.js');
|
|
@@ -60,7 +64,7 @@ const { transcriptToMarkdown, transcriptToJSON, writeExportFile, lastAssistantTe
|
|
|
60
64
|
const { detectDevCommand, runDevServer } = require('./devrun.js');
|
|
61
65
|
const credentials = require('./credentials.js');
|
|
62
66
|
const cloudsync = require('./cloudsync.js');
|
|
63
|
-
const { maskKey } = require('./format.js');
|
|
67
|
+
const { maskKey, fmtTokens } = require('./format.js');
|
|
64
68
|
const { openUrl, URLS } = require('./system.js');
|
|
65
69
|
const { sniffProject, buildAegisMd } = require('./init.js');
|
|
66
70
|
const {
|
|
@@ -216,6 +220,113 @@ async function applyAccountKey(c, raw, { label = 'AEGIS API key' } = {}) {
|
|
|
216
220
|
return res;
|
|
217
221
|
}
|
|
218
222
|
|
|
223
|
+
/** Human token count for the sync quota: 1000000 -> "1M", 42800 -> "43k".
|
|
224
|
+
* The ceiling is denominated in tokens (aegis1 FREE_SYNC_TOKENS = 1 MB,
|
|
225
|
+
* PRO_SYNC_TOKENS = 10 MB), which for stored prose is about one per
|
|
226
|
+
* character — "1000000" at a glance tells a user nothing about how close they
|
|
227
|
+
* are to it. */
|
|
228
|
+
function fmtQuotaTokens(n) {
|
|
229
|
+
const v = Number(n);
|
|
230
|
+
if (!Number.isFinite(v)) return '?';
|
|
231
|
+
if (v >= 1e6) return `${(v / 1e6).toFixed(v % 1e6 === 0 ? 0 : 1)}M`;
|
|
232
|
+
if (v >= 1e4) return `${Math.round(v / 1e3)}k`;
|
|
233
|
+
return fmtTokens(v);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* The persisting-memory gate, read off the command context (the live app
|
|
238
|
+
* exposes `cloudSyncState()`) with a fallback for callers that only pass the
|
|
239
|
+
* older boolean probe — `/cloud` and `/sync` predate the rename, and a stub
|
|
240
|
+
* context in a test must not have to grow a method to render a panel.
|
|
241
|
+
*/
|
|
242
|
+
function memoryGate(c) {
|
|
243
|
+
if (c && typeof c.cloudSyncState === 'function') {
|
|
244
|
+
try {
|
|
245
|
+
return c.cloudSyncState();
|
|
246
|
+
} catch {
|
|
247
|
+
/* fall through to the boolean */
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const enabled =
|
|
251
|
+
c && typeof c.cloudSyncEnabled === 'function' ? c.cloudSyncEnabled() === true : true;
|
|
252
|
+
return { enabled, source: 'default' };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Flip the gate through the command context (app.js's `setCloudSync` is
|
|
257
|
+
* `config.setMemoryPersist`), which is what keeps the setting and the running
|
|
258
|
+
* session agreeing. Guarded because a context stub that never flips anything
|
|
259
|
+
* still has to be able to *run* the handler — the command smoke test drives
|
|
260
|
+
* every handler with no arguments.
|
|
261
|
+
*/
|
|
262
|
+
function setMemoryGate(c, on) {
|
|
263
|
+
if (c && typeof c.setCloudSync === 'function') return c.setCloudSync(on);
|
|
264
|
+
try {
|
|
265
|
+
return setMemoryPersist(on);
|
|
266
|
+
} catch {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The persisting-memory block every cloud surface shows: the switch, the
|
|
273
|
+
* ceiling, and — the part that was missing — what a stopped write does and
|
|
274
|
+
* does not cost.
|
|
275
|
+
*
|
|
276
|
+
* The honesty requirement is not cosmetic. aegis1 meters WRITES only
|
|
277
|
+
* (`_memory_sync_access`), so a free account that passes ~1 MB of transcript
|
|
278
|
+
* keeps every entry it stored and simply stops accumulating new ones. The old
|
|
279
|
+
* rollout printed nothing at all, so "memory is free with any account" and
|
|
280
|
+
* "nothing is being stored any more" were both true and indistinguishable.
|
|
281
|
+
* These lines make the ceiling a state the user can see: the number, whose
|
|
282
|
+
* limit it is, and the one sentence that separates the working half (reads)
|
|
283
|
+
* from the stopped half (new writes).
|
|
284
|
+
*/
|
|
285
|
+
function memoryStatusLines(c) {
|
|
286
|
+
const gate = memoryGate(c);
|
|
287
|
+
const st = cloudsync.status();
|
|
288
|
+
const q = st.quota;
|
|
289
|
+
const used = q && q.used != null ? fmtQuotaTokens(q.used) : null;
|
|
290
|
+
const limit = q && q.limit != null ? fmtQuotaTokens(q.limit) : null;
|
|
291
|
+
const how =
|
|
292
|
+
gate.source === 'legacy'
|
|
293
|
+
? ' (kept from your old cloudSync setting)'
|
|
294
|
+
: gate.source === 'default'
|
|
295
|
+
? ' (default)'
|
|
296
|
+
: '';
|
|
297
|
+
const rows = [
|
|
298
|
+
// Both names, one gate. The commit that flipped the default renamed the
|
|
299
|
+
// panel to say what is being stored, but `/sync`, `/cloud sync` and the
|
|
300
|
+
// docs all still call it cloud sync — a panel that only answers to its new
|
|
301
|
+
// name makes the setting unfindable to anyone who learned the old one.
|
|
302
|
+
[span(C.white + BOLD, 'Persisting memory'), span(C.gray, ' · Cloud sync'), span(BOLD_OFF, '')],
|
|
303
|
+
[span(C.gray, '─'.repeat(34))],
|
|
304
|
+
[
|
|
305
|
+
span(C.white, ` ${gate.enabled ? 'on' : 'off'}`),
|
|
306
|
+
span(C.gray, `${how} · ${gate.enabled ? 'each session is stored so an interrupted turn can be resumed' : 'nothing new is stored'}`),
|
|
307
|
+
],
|
|
308
|
+
];
|
|
309
|
+
if (limit) {
|
|
310
|
+
rows.push([
|
|
311
|
+
span(C.gray, ' quota: '),
|
|
312
|
+
span(C.white, `${used} of ${limit} tokens synced`),
|
|
313
|
+
span(C.gray, ' (aegis1 charges writes; reads are always served)'),
|
|
314
|
+
]);
|
|
315
|
+
} else {
|
|
316
|
+
rows.push([span(C.gray, ' quota: not reported yet — /sync now asks the server for the current numbers')]);
|
|
317
|
+
}
|
|
318
|
+
if (st.overQuota) {
|
|
319
|
+
rows.push([span(C.coral, ' writes: paused — the plan’s ceiling is reached, so new memory is not being stored')]);
|
|
320
|
+
rows.push([span(C.green, ' reads: still work — everything already stored stays readable (/aegis-recall <topic>)')]);
|
|
321
|
+
rows.push([span(C.gray, ' free room at https://aegiscloud.org/subscribe, or /cloud memory off to stop trying')]);
|
|
322
|
+
}
|
|
323
|
+
if (gate.enabled && st.pending > 0) {
|
|
324
|
+
rows.push([span(C.gray, ` pending: ${st.pending} session(s) waiting to sync`)]);
|
|
325
|
+
}
|
|
326
|
+
rows.push([span(C.gray, ` /cloud memory on | off · /sync now pushes once by hand`)]);
|
|
327
|
+
return rows;
|
|
328
|
+
}
|
|
329
|
+
|
|
219
330
|
/** Push + pull once, and report the counts (or the quota refusal). */
|
|
220
331
|
async function runCloudSync(c, o = {}) {
|
|
221
332
|
if (!c.client.apiKey) {
|
|
@@ -782,7 +893,7 @@ const COMMANDS = [
|
|
|
782
893
|
// This client's /status surface is the account-status tool (the same
|
|
783
894
|
// tool /aegis-status names) plus the local session panel below it.
|
|
784
895
|
await c.runTool('aegis_status', {});
|
|
785
|
-
panel(c, panels.buildStatus(c.state(), c.ctx));
|
|
896
|
+
panel(c, panels.buildStatus(c.state(), Object.assign({}, c.ctx, { caps: describe() })));
|
|
786
897
|
c.render();
|
|
787
898
|
return true;
|
|
788
899
|
},
|
|
@@ -818,6 +929,87 @@ const COMMANDS = [
|
|
|
818
929
|
return true;
|
|
819
930
|
},
|
|
820
931
|
},
|
|
932
|
+
{
|
|
933
|
+
name: 'terminal', aliases: ['tty'], args: ['mode', 'mode2'],
|
|
934
|
+
hint: '[ascii|unicode|color|no-color|star <native|narrow>|width <cols>|auto|status]', category: 'model',
|
|
935
|
+
desc: 'Show or override how this terminal is drawn (mark, colour, width)',
|
|
936
|
+
handler: async (c, args) => {
|
|
937
|
+
// The same report `aegiscode --terminal` prints, and the same switch the
|
|
938
|
+
// `--ascii` flag sets — so a session can be re-styled without restarting
|
|
939
|
+
// when a paste from PowerShell turns out to render badly in this host.
|
|
940
|
+
// `args` is positional (app.js `parseArgs`), so the second token is
|
|
941
|
+
// `mode2` for both `star narrow` and `width 100`.
|
|
942
|
+
const sub = (args.mode || '').toLowerCase();
|
|
943
|
+
const second = args.mode2 != null ? String(args.mode2).trim() : '';
|
|
944
|
+
|
|
945
|
+
if (sub === '' || sub === 'status') {
|
|
946
|
+
panel(c, panels.buildTerminalCaps(describe(), { pinned: !!caps().pinned }));
|
|
947
|
+
c.render();
|
|
948
|
+
return true;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// The patch pins every *axis* but never the frame: `cols`/`rows` must stay
|
|
952
|
+
// absent so `setCaps` leaves `sizePinned` false and a live resize keeps
|
|
953
|
+
// re-reading the stream (see caps.js). Copying the whole caps object here
|
|
954
|
+
// would freeze the width at the moment the command ran.
|
|
955
|
+
const cur = caps();
|
|
956
|
+
const axes = {
|
|
957
|
+
glyphs: cur.glyphs, face: cur.face, star: cur.star,
|
|
958
|
+
depth: cur.depth, vt: cur.vt, wideRunes: cur.wideRunes,
|
|
959
|
+
reasons: Object.assign({}, cur.reasons),
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
if (sub === 'auto') {
|
|
963
|
+
// Drop every override, including any the session inherited from the
|
|
964
|
+
// flags/env it was started with — "auto" means "probe again", not
|
|
965
|
+
// "restore what you were launched with".
|
|
966
|
+
resetCaps();
|
|
967
|
+
note(c, 'Terminal: auto — capabilities re-probed from the environment.');
|
|
968
|
+
c.render();
|
|
969
|
+
return true;
|
|
970
|
+
}
|
|
971
|
+
// `why` in the report must describe what the session is actually doing,
|
|
972
|
+
// not the probe it started from: after `/terminal ascii` on a truecolor
|
|
973
|
+
// host, `why: TERM=xterm-256color` would contradict `mark: ascii`.
|
|
974
|
+
if (sub === 'ascii' || sub === 'unicode') {
|
|
975
|
+
axes.glyphs = sub === 'ascii' ? 'ascii' : 'unicode';
|
|
976
|
+
axes.face = sub === 'ascii' ? 'edges' : 'native';
|
|
977
|
+
axes.star = sub === 'ascii' ? 'narrow' : 'native';
|
|
978
|
+
if (axes.reasons) axes.reasons.glyphs = `/terminal ${sub}`;
|
|
979
|
+
} else if (sub === 'color' || sub === 'no-color' || sub === 'nocolor') {
|
|
980
|
+
axes.depth = sub === 'color' ? 24 : 0;
|
|
981
|
+
if (axes.reasons) axes.reasons.depth = `/terminal ${sub}`;
|
|
982
|
+
} else if (sub === 'star') {
|
|
983
|
+
const want = second.toLowerCase();
|
|
984
|
+
if (!['native', 'narrow'].includes(want)) { note(c, 'Usage: /terminal star <native|narrow>'); c.render(); return true; }
|
|
985
|
+
axes.star = want;
|
|
986
|
+
if (axes.reasons) axes.reasons.star = `/terminal star ${want}`;
|
|
987
|
+
} else if (sub === 'width') {
|
|
988
|
+
// A pinned width is a frame override, so it goes in as cols — the one
|
|
989
|
+
// key that deliberately trips `sizePinned`.
|
|
990
|
+
const width = Number(second);
|
|
991
|
+
if (!Number.isFinite(width) || width < 20) { note(c, 'Usage: /terminal width <cols> (>= 20)'); c.render(); return true; }
|
|
992
|
+
setCaps(Object.assign({}, axes, { cols: Math.round(width) }));
|
|
993
|
+
note(c, `Terminal: width pinned to ${Math.round(width)} columns.`);
|
|
994
|
+
panel(c, panels.buildTerminalCaps(describe(), { pinned: !!caps().pinned }));
|
|
995
|
+
c.render();
|
|
996
|
+
return true;
|
|
997
|
+
} else {
|
|
998
|
+
note(c, 'Usage: /terminal [ascii|unicode|color|no-color|star <native|narrow>|width <cols>|auto|status]');
|
|
999
|
+
c.render();
|
|
1000
|
+
return true;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
setCaps(axes);
|
|
1004
|
+
panel(c, panels.buildTerminalCaps(describe(), { pinned: !!caps().pinned }));
|
|
1005
|
+
// Already-painted scrollback keeps the glyphs it was drawn with — a
|
|
1006
|
+
// terminal has no way to rewrite what it has scrolled past. Everything
|
|
1007
|
+
// from here on (and this viewport) uses the new mark.
|
|
1008
|
+
note(c, 'Terminal updated — the current viewport is redrawn; text already scrolled past keeps its old glyphs.');
|
|
1009
|
+
c.render();
|
|
1010
|
+
return true;
|
|
1011
|
+
},
|
|
1012
|
+
},
|
|
821
1013
|
{
|
|
822
1014
|
name: 'version', aliases: ['v'], hint: '', category: 'session',
|
|
823
1015
|
desc: 'Show version',
|
|
@@ -1364,7 +1556,7 @@ const COMMANDS = [
|
|
|
1364
1556
|
},
|
|
1365
1557
|
},
|
|
1366
1558
|
{
|
|
1367
|
-
name: 'cloud', args: ['sub', 'value'], hint: '[status|key <api_key>|activate|deactivate|sync [on|off|now]]', category: 'support',
|
|
1559
|
+
name: 'cloud', args: ['sub', 'value'], hint: '[status|key <api_key>|activate|deactivate|memory [on|off]|sync [on|off|now]]', category: 'support',
|
|
1368
1560
|
desc: 'Show and control ÆGIS cloud sync',
|
|
1369
1561
|
handler: async (c, args) => {
|
|
1370
1562
|
const sub = (args.sub || '').toLowerCase();
|
|
@@ -1408,12 +1600,35 @@ const COMMANDS = [
|
|
|
1408
1600
|
return true;
|
|
1409
1601
|
}
|
|
1410
1602
|
|
|
1603
|
+
if (sub === 'memory' || sub === 'persist' || sub === 'memory-persist') {
|
|
1604
|
+
// The write half's one switch. `/cloud sync on|off` and `/sync on|off`
|
|
1605
|
+
// still work (they always meant "should this host store my sessions"),
|
|
1606
|
+
// but this is the name that says what is actually being flipped.
|
|
1607
|
+
const mode = (rest || 'status').toLowerCase();
|
|
1608
|
+
if (mode === 'on' || mode === 'off') {
|
|
1609
|
+
const on = mode === 'on';
|
|
1610
|
+
setMemoryGate(c, on);
|
|
1611
|
+
if (on) {
|
|
1612
|
+
done(c, 'persisting memory on — sessions are stored to your account so an interrupted turn can be resumed');
|
|
1613
|
+
note(c, '/cloud memory shows the quota; past the plan’s ceiling reads keep working and only new writes pause');
|
|
1614
|
+
} else {
|
|
1615
|
+
note(c, 'persisting memory off — nothing new is stored');
|
|
1616
|
+
note(c, 'everything already in the cloud stays readable (/aegis-recall <topic>), and /sync now still pushes once by hand');
|
|
1617
|
+
}
|
|
1618
|
+
c.render();
|
|
1619
|
+
return true;
|
|
1620
|
+
}
|
|
1621
|
+
panel(c, memoryStatusLines(c));
|
|
1622
|
+
c.render();
|
|
1623
|
+
return true;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1411
1626
|
if (sub === 'sync' || sub === 'push' || sub === 'pull') {
|
|
1412
1627
|
const mode = sub === 'sync' ? (rest || 'status').toLowerCase() : sub;
|
|
1413
1628
|
if (mode === 'on' || mode === 'off') {
|
|
1414
1629
|
const on = mode === 'on';
|
|
1415
|
-
c
|
|
1416
|
-
note(c, on ? '
|
|
1630
|
+
setMemoryGate(c, on);
|
|
1631
|
+
note(c, on ? 'persisting memory on — sessions are stored after each turn (this is the old "cloud sync")' : 'persisting memory off — nothing new is stored; /sync now still runs a manual pass');
|
|
1417
1632
|
c.render();
|
|
1418
1633
|
return true;
|
|
1419
1634
|
}
|
|
@@ -1423,18 +1638,17 @@ const COMMANDS = [
|
|
|
1423
1638
|
return true;
|
|
1424
1639
|
}
|
|
1425
1640
|
const st = cloudsync.status();
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
[span(C.gray, '
|
|
1429
|
-
[span(C.white
|
|
1641
|
+
panel(c, [
|
|
1642
|
+
...memoryStatusLines(c),
|
|
1643
|
+
[span(C.gray, '')],
|
|
1644
|
+
[span(C.white + BOLD, 'Sync ledger'), span(BOLD_OFF, '')],
|
|
1430
1645
|
[span(C.gray, ` local sessions: ${st.local} · pending push: ${st.pending} · in sync: ${st.synced}`)],
|
|
1431
1646
|
[span(C.gray, ` last push: ${st.lastPushAt ? new Date(st.lastPushAt).toLocaleString() : 'never'} · last pull: ${st.lastPullAt ? new Date(st.lastPullAt).toLocaleString() : 'never'}`)],
|
|
1432
1647
|
[span(C.gray, ` state: ${st.path}`)],
|
|
1433
|
-
];
|
|
1648
|
+
]);
|
|
1434
1649
|
for (const e of st.errors.slice(0, 3)) {
|
|
1435
|
-
|
|
1650
|
+
panel(c, [[span(C.coral, ` ⚠ ${e.error}`)]]);
|
|
1436
1651
|
}
|
|
1437
|
-
panel(c, rows);
|
|
1438
1652
|
c.render();
|
|
1439
1653
|
return true;
|
|
1440
1654
|
}
|
|
@@ -1444,9 +1658,17 @@ const COMMANDS = [
|
|
|
1444
1658
|
panel(c, [
|
|
1445
1659
|
...keyPanelLines(c, 'AEGIS cloud'),
|
|
1446
1660
|
[span(C.gray, '')],
|
|
1661
|
+
...memoryStatusLines(c),
|
|
1662
|
+
[span(C.gray, '')],
|
|
1447
1663
|
[span(C.white + BOLD, ' Sync'), span(BOLD_OFF, '')],
|
|
1448
|
-
[span(C.gray, ` ${
|
|
1449
|
-
|
|
1664
|
+
[span(C.gray, ` ${st.pending} pending · ${st.synced} in sync · ${st.importedRemote} pulled from cloud`)],
|
|
1665
|
+
// Both names, because both work: `/cloud memory` is the new one that
|
|
1666
|
+
// says what is being flipped, and `/cloud sync` is what every user who
|
|
1667
|
+
// has ever turned this off typed (it dispatched here before the flip
|
|
1668
|
+
// renamed the panel, and still does — see the `sub === 'sync'` branch).
|
|
1669
|
+
// Advertising only the new name hides a working control behind a
|
|
1670
|
+
// rename, which is how a setting becomes a rumour.
|
|
1671
|
+
[span(C.gray, ' /cloud memory on | off · /cloud sync on | off · /sync now')],
|
|
1450
1672
|
]);
|
|
1451
1673
|
c.render();
|
|
1452
1674
|
return true;
|
|
@@ -1479,24 +1701,22 @@ const COMMANDS = [
|
|
|
1479
1701
|
},
|
|
1480
1702
|
{
|
|
1481
1703
|
name: 'sync', aliases: ['cloudsync', 'cloud-sync'], args: ['mode'], hint: '[now|on|off|status]', category: 'data',
|
|
1482
|
-
desc: '
|
|
1704
|
+
desc: 'Store sessions in AEGIS Cloud (cross-session memory)',
|
|
1483
1705
|
hidden: (c) => !cloudReady(),
|
|
1484
1706
|
handler: async (c, args) => {
|
|
1485
1707
|
const mode = (args.mode || '').toLowerCase();
|
|
1486
1708
|
if (mode === 'on' || mode === 'off') {
|
|
1487
|
-
c
|
|
1488
|
-
note(c, mode === 'on' ? '
|
|
1709
|
+
setMemoryGate(c, mode === 'on');
|
|
1710
|
+
note(c, mode === 'on' ? 'persisting memory on — sessions are stored so an interrupted turn can be resumed' : 'persisting memory off — nothing new is stored; /sync now still runs a manual pass');
|
|
1489
1711
|
c.render();
|
|
1490
1712
|
return true;
|
|
1491
1713
|
}
|
|
1492
1714
|
if (mode === 'status') {
|
|
1493
1715
|
const st = cloudsync.status();
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
[span(C.gray, ` local ${st.local} · pending ${st.pending} · in sync ${st.synced}`)],
|
|
1499
|
-
]);
|
|
1716
|
+
const rows = memoryStatusLines(c);
|
|
1717
|
+
rows.push([span(C.gray, '')]);
|
|
1718
|
+
rows.push([span(C.gray, ` local ${st.local} · pending ${st.pending} · in sync ${st.synced}`)]);
|
|
1719
|
+
panel(c, rows);
|
|
1500
1720
|
c.render();
|
|
1501
1721
|
return true;
|
|
1502
1722
|
}
|