aegiscode 6.8.36 → 6.8.37
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/package.json +1 -1
- package/src/app.js +20 -0
- package/src/chatflow.js +141 -1
- package/src/engine.js +4 -2
- package/src/screens.js +118 -25
- package/vendor/desktop/lib/local/engine.js +113 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aegiscode",
|
|
3
3
|
"productName": "AEGIS Code",
|
|
4
|
-
"version": "6.8.
|
|
4
|
+
"version": "6.8.37",
|
|
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",
|
package/src/app.js
CHANGED
|
@@ -938,6 +938,13 @@ function createApp(options = {}) {
|
|
|
938
938
|
return Promise.resolve('deny');
|
|
939
939
|
};
|
|
940
940
|
|
|
941
|
+
// The round-horizon ask's own no-one-to-answer fallback. Unreachable in
|
|
942
|
+
// practice — `roundsAsk` below is only sent `true` when `p.rounds` exists,
|
|
943
|
+
// so the engine never raises the ask without a prompter — but kept so a
|
|
944
|
+
// future caller that forgets the guard fails safe (stop) instead of
|
|
945
|
+
// hanging the tool loop on an unanswerable promise.
|
|
946
|
+
const denyRoundsNoPrompter = () => Promise.resolve(false);
|
|
947
|
+
|
|
941
948
|
// Vocabulary bridging lives at module scope (see normalizeDecision) so the
|
|
942
949
|
// same function the tests import is the one the live path calls.
|
|
943
950
|
const onDelta = (chunk) => {
|
|
@@ -970,6 +977,14 @@ function createApp(options = {}) {
|
|
|
970
977
|
.catch(() => 'deny')
|
|
971
978
|
.then((decision) => engine.respondApproval(info.id, normalizeDecision(decision)));
|
|
972
979
|
}
|
|
980
|
+
if (chunk.rounds) {
|
|
981
|
+
const info = chunk.rounds;
|
|
982
|
+
if (live) live.clear();
|
|
983
|
+
const decide = p.rounds || denyRoundsNoPrompter;
|
|
984
|
+
Promise.resolve(decide(info))
|
|
985
|
+
.catch(() => false)
|
|
986
|
+
.then((decision) => engine.respondRoundsAsk(info.id, decision === true));
|
|
987
|
+
}
|
|
973
988
|
};
|
|
974
989
|
|
|
975
990
|
try {
|
|
@@ -1004,6 +1019,11 @@ function createApp(options = {}) {
|
|
|
1004
1019
|
// `--no-stream` and piped runs get a single body rather than SSE.
|
|
1005
1020
|
stream: commandCtx.stream !== false,
|
|
1006
1021
|
sessionId,
|
|
1022
|
+
// Opt-in to the round-horizon dialog (see engine.js requestRoundsAsk)
|
|
1023
|
+
// only when there is actually a `rounds` prompter to answer it — a
|
|
1024
|
+
// one-shot `-p` run or any other caller with no presenter keeps the
|
|
1025
|
+
// engine's old stop-and-record-session behaviour untouched.
|
|
1026
|
+
roundsAsk: Boolean(p.rounds),
|
|
1007
1027
|
},
|
|
1008
1028
|
onDelta
|
|
1009
1029
|
);
|
package/src/chatflow.js
CHANGED
|
@@ -349,7 +349,7 @@ function statusLine(state, cols, ctx) {
|
|
|
349
349
|
} else if (state.streamJob) {
|
|
350
350
|
left = [span(t.gray, `${GLYPH.bullet} esc to stop`)];
|
|
351
351
|
} else if (state.yolo) {
|
|
352
|
-
left = [span(t.gray, `${GLYPH.bullet} automode on ${GLYPH.bullet} ? for shortcuts ${GLYPH.bullet} ${GLYPH.rightarrow} for
|
|
352
|
+
left = [span(t.gray, `${GLYPH.bullet} automode on ${GLYPH.bullet} ${autoContinueLimit()} rounds then it asks ${GLYPH.bullet} ? for shortcuts ${GLYPH.bullet} ${GLYPH.rightarrow} for manual mode`)];
|
|
353
353
|
} else {
|
|
354
354
|
left = [span(t.gray, `${GLYPH.pause} manual mode on ${GLYPH.bullet} ? for shortcuts ${GLYPH.bullet} ${GLYPH.rightarrow} for auto mode`)];
|
|
355
355
|
}
|
|
@@ -435,6 +435,66 @@ function confirmLines(overlay, cols, ctx) {
|
|
|
435
435
|
return lines;
|
|
436
436
|
}
|
|
437
437
|
|
|
438
|
+
/**
|
|
439
|
+
* Automatic round-budget continuations automode may take before it has to
|
|
440
|
+
* ask for real — mirrors the upstream engine's `autoContinuePlan`
|
|
441
|
+
* (aegiscodex-dev's src/autonomous.js). Not "run forever": after `limit`
|
|
442
|
+
* silent yeses the real dialog is shown, so a turn that is genuinely stuck
|
|
443
|
+
* still puts a human in the loop. Pure, and exported, so the policy itself
|
|
444
|
+
* (not just the dialog it feeds) is directly testable.
|
|
445
|
+
*
|
|
446
|
+
* { auto: true, used: n } → answer the ask with "continue", no dialog
|
|
447
|
+
* { auto: false, used: 0 } → show the real dialog (allowance just spent)
|
|
448
|
+
* { auto: false, used: n } → show the real dialog (automode is off)
|
|
449
|
+
*/
|
|
450
|
+
const AUTO_CONTINUE_LIMIT = 3;
|
|
451
|
+
/**
|
|
452
|
+
* The allowance, honouring `AEGIS_AUTO_CONTINUE_MAX` exactly as the upstream
|
|
453
|
+
* engine's `autoContinueLimit` does (aegiscodex-dev's src/autonomous.js). Read
|
|
454
|
+
* per call, not frozen at module load, so a test or a wrapper can move the
|
|
455
|
+
* allowance without a reload — and so the number the status line advertises
|
|
456
|
+
* ("N rounds then it asks") is the number the plan will actually spend.
|
|
457
|
+
*/
|
|
458
|
+
function autoContinueLimit(env = process.env) {
|
|
459
|
+
const n = Number.parseInt(env && env.AEGIS_AUTO_CONTINUE_MAX, 10);
|
|
460
|
+
return Number.isFinite(n) && n > 0 ? n : AUTO_CONTINUE_LIMIT;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function autoContinuePlan({ on = false, used = 0, limit = autoContinueLimit() } = {}) {
|
|
464
|
+
const cap = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : AUTO_CONTINUE_LIMIT;
|
|
465
|
+
const spent = Number.isFinite(used) && used > 0 ? Math.floor(used) : 0;
|
|
466
|
+
if (!on) return { auto: false, used: spent, cap };
|
|
467
|
+
if (spent >= cap) return { auto: false, used: 0, cap };
|
|
468
|
+
return { auto: true, used: spent + 1, cap };
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** The round-budget extension dialog body — same shape as confirmLines, but
|
|
472
|
+
* the subject is a round budget rather than a tool call. */
|
|
473
|
+
function roundsLines(overlay, cols, ctx) {
|
|
474
|
+
const t = themeOf(ctx);
|
|
475
|
+
const lines = [];
|
|
476
|
+
lines.push([span(t.gray, '─'.repeat(Math.min(Math.max(10, cols - 4), 80)))]);
|
|
477
|
+
lines.push([span(t.white, `${overlay.spent}-round tool limit reached`)]);
|
|
478
|
+
lines.push([span('', '')]);
|
|
479
|
+
for (const l of wrapBlock(
|
|
480
|
+
'The turn is still working — it ended its last round on a tool call instead of an answer.',
|
|
481
|
+
Math.max(8, cols - 4)
|
|
482
|
+
)) {
|
|
483
|
+
lines.push([span(t.gray, l)]);
|
|
484
|
+
}
|
|
485
|
+
lines.push([span('', '')]);
|
|
486
|
+
const opt = (i, label) => {
|
|
487
|
+
const active = overlay.sel === i;
|
|
488
|
+
const left = active ? span(t.lavender, GLYPH.cursor) : span('', ' ');
|
|
489
|
+
return [left, span(t.gray, ` ${i + 1}. `), span(active ? t.lavender : t.white, label)];
|
|
490
|
+
};
|
|
491
|
+
lines.push(opt(0, `Yes, continue with ${overlay.size} more rounds`));
|
|
492
|
+
lines.push(opt(1, 'No, stop here and answer with what I have'));
|
|
493
|
+
lines.push([span('', '')]);
|
|
494
|
+
lines.push([span(t.gray, `extension ${overlay.extensions} of ${overlay.max} · Esc to stop`)]);
|
|
495
|
+
return lines;
|
|
496
|
+
}
|
|
497
|
+
|
|
438
498
|
/**
|
|
439
499
|
* The accounting bits for a turn — model, tokens, the in/out split, €, elapsed
|
|
440
500
|
* and call count. Shared by the standalone `meta` row and the folded footer, so
|
|
@@ -841,6 +901,12 @@ async function runSession(host) {
|
|
|
841
901
|
const lineCache = new WeakMap();
|
|
842
902
|
|
|
843
903
|
let overlay = null;
|
|
904
|
+
// Automode's running tally of silent "continue" answers to the round-budget
|
|
905
|
+
// dialog (see autoContinuePlan above). Cleared whenever the human is
|
|
906
|
+
// actually asked (autoContinuePlan resets it once the allowance is spent),
|
|
907
|
+
// so it is "N automatic continuations per block", never a life-of-session
|
|
908
|
+
// total that a long build could quietly exhaust.
|
|
909
|
+
let autoContinues = 0;
|
|
844
910
|
let working = false;
|
|
845
911
|
let abort = null;
|
|
846
912
|
let spinnerFrame = 0;
|
|
@@ -1124,6 +1190,8 @@ async function runSession(host) {
|
|
|
1124
1190
|
ol = shortcutsGrid(cols, ctx);
|
|
1125
1191
|
} else if (overlay.type === 'confirm') {
|
|
1126
1192
|
ol = confirmLines(overlay, cols, ctx);
|
|
1193
|
+
} else if (overlay.type === 'rounds') {
|
|
1194
|
+
ol = roundsLines(overlay, cols, ctx);
|
|
1127
1195
|
} else if (overlay.type === 'panel') {
|
|
1128
1196
|
ol = overlay.lines || [];
|
|
1129
1197
|
}
|
|
@@ -1224,6 +1292,73 @@ async function runSession(host) {
|
|
|
1224
1292
|
})();
|
|
1225
1293
|
});
|
|
1226
1294
|
|
|
1295
|
+
// The round-budget extension dialog (engine.js requestRoundsAsk, surfaced
|
|
1296
|
+
// here as `chunk.rounds` → `presenter.rounds`). Same own-nextKey-loop shape
|
|
1297
|
+
// as confirmTool above. The cursor starts on "No" deliberately: an Enter on
|
|
1298
|
+
// an untouched dialog must not spend another block of rounds, so a
|
|
1299
|
+
// declined dialog is bit-for-bit the engine's own hard stop.
|
|
1300
|
+
const confirmRoundsExtension = (info) =>
|
|
1301
|
+
new Promise((resolve) => {
|
|
1302
|
+
// ── automode: the first AUTO_CONTINUE_LIMIT asks are answered for the
|
|
1303
|
+
// human ───────────────────────────────────────────────────────────────
|
|
1304
|
+
// This is the "fund a few blocks automatically, then ask for real"
|
|
1305
|
+
// contract: with automode on, a turn that reaches its horizon is
|
|
1306
|
+
// extended silently a few times, and the ask after that is the real
|
|
1307
|
+
// dialog again — so automode is "don't make me answer the same budget
|
|
1308
|
+
// question every time", not "run forever with no one watching".
|
|
1309
|
+
const yolo = Boolean(host.isYolo && host.isYolo());
|
|
1310
|
+
const plan = autoContinuePlan({ on: yolo, used: autoContinues });
|
|
1311
|
+
autoContinues = plan.used;
|
|
1312
|
+
if (plan.auto) {
|
|
1313
|
+
note(
|
|
1314
|
+
`auto: ${info.spent}-round limit reached — continuing automatically` +
|
|
1315
|
+
` (${plan.used}/${plan.cap}, then it asks).`
|
|
1316
|
+
);
|
|
1317
|
+
render();
|
|
1318
|
+
resolve(true);
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
if (yolo) {
|
|
1322
|
+
// The allowance is spent: this IS the ask. Say so, or the dialog reads
|
|
1323
|
+
// as automode having silently switched itself off.
|
|
1324
|
+
note(`auto: ${plan.cap} automatic continuations used — asking you now (answering restarts the block).`);
|
|
1325
|
+
render();
|
|
1326
|
+
}
|
|
1327
|
+
overlay = {
|
|
1328
|
+
type: 'rounds',
|
|
1329
|
+
spent: Number(info.spent) || 0,
|
|
1330
|
+
extensions: Number(info.extensions) || 1,
|
|
1331
|
+
max: Number(info.max) || 8,
|
|
1332
|
+
size: Number(info.size) || Number(info.spent) || 0,
|
|
1333
|
+
sel: 1,
|
|
1334
|
+
};
|
|
1335
|
+
render();
|
|
1336
|
+
(async () => {
|
|
1337
|
+
const choose = (yes) => {
|
|
1338
|
+
overlay = null;
|
|
1339
|
+
render();
|
|
1340
|
+
resolve(yes);
|
|
1341
|
+
};
|
|
1342
|
+
for (;;) {
|
|
1343
|
+
const key = await nextKey();
|
|
1344
|
+
if (key.name === KEY.UP || key.name === KEY.DOWN || key.name === KEY.TAB) {
|
|
1345
|
+
overlay.sel = 1 - overlay.sel;
|
|
1346
|
+
render();
|
|
1347
|
+
} else if (key.name === KEY.ENTER) {
|
|
1348
|
+
choose(overlay.sel === 0);
|
|
1349
|
+
return;
|
|
1350
|
+
} else if (key.name === KEY.ESC || key.name === KEY.CTRL_C) {
|
|
1351
|
+
choose(false);
|
|
1352
|
+
return;
|
|
1353
|
+
} else if (key.name === 'char') {
|
|
1354
|
+
const c = String(key.ch).trim();
|
|
1355
|
+
if (c === '1') { choose(true); return; }
|
|
1356
|
+
if (c === '2') { choose(false); return; }
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
})();
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1227
1362
|
const startResponse = async (prompt) => {
|
|
1228
1363
|
working = true;
|
|
1229
1364
|
spinnerFrame = 0;
|
|
@@ -1326,6 +1461,7 @@ async function runSession(host) {
|
|
|
1326
1461
|
scheduleRender();
|
|
1327
1462
|
},
|
|
1328
1463
|
approval: (info) => confirmTool(info),
|
|
1464
|
+
rounds: (info) => confirmRoundsExtension(info),
|
|
1329
1465
|
};
|
|
1330
1466
|
|
|
1331
1467
|
let result = null;
|
|
@@ -2483,6 +2619,10 @@ module.exports = {
|
|
|
2483
2619
|
// answers with tokens the engine actually honours (see APPROVAL_CHOICES).
|
|
2484
2620
|
APPROVAL_CHOICES,
|
|
2485
2621
|
APPROVAL_DECISIONS,
|
|
2622
|
+
roundsLines,
|
|
2623
|
+
autoContinuePlan,
|
|
2624
|
+
autoContinueLimit,
|
|
2625
|
+
AUTO_CONTINUE_LIMIT,
|
|
2486
2626
|
rowLines,
|
|
2487
2627
|
transcriptLines,
|
|
2488
2628
|
inputPreviewText,
|
package/src/engine.js
CHANGED
|
@@ -71,8 +71,9 @@ const CLASS_LABELS = Object.freeze({
|
|
|
71
71
|
* (and by app.js, so one store serves both the engine and the commands);
|
|
72
72
|
* otherwise created against the CLI's data dir.
|
|
73
73
|
* @returns {{chat: Function, cancel: Function, respondApproval: Function,
|
|
74
|
-
*
|
|
75
|
-
* classLabel: Function, getClass: Function, setClass: Function,
|
|
74
|
+
* respondRoundsAsk: Function, clearSessionApprovals: Function, listClasses: Function,
|
|
75
|
+
* listModels: Function, classLabel: Function, getClass: Function, setClass: Function,
|
|
76
|
+
* settings: object}}
|
|
76
77
|
*/
|
|
77
78
|
function createEngine({ client, getConfirmMode, getClass, settings: injectedSettings } = {}) {
|
|
78
79
|
const settings = injectedSettings || createSettingsStore({ dir: credentials.aegisHome() });
|
|
@@ -114,6 +115,7 @@ function createEngine({ client, getConfirmMode, getClass, settings: injectedSett
|
|
|
114
115
|
chat,
|
|
115
116
|
cancel: local.cancel,
|
|
116
117
|
respondApproval: local.respondApproval,
|
|
118
|
+
respondRoundsAsk: local.respondRoundsAsk,
|
|
117
119
|
clearSessionApprovals: local.clearSessionApprovals,
|
|
118
120
|
// The engine's own class table, narrowed to the ones this host runs — so a
|
|
119
121
|
// UI built from listClasses() can never offer a class that would throw.
|
package/src/screens.js
CHANGED
|
@@ -91,7 +91,15 @@ const WHATS_NEW = [
|
|
|
91
91
|
* the Tips/What's-new pair already come to 21 of the 23 usable rows, so a
|
|
92
92
|
* boxed third panel (three rows minimum, two of them rules) would push the
|
|
93
93
|
* footer hint off the bottom of the commonest terminal there is. Two rows fit
|
|
94
|
-
* exactly
|
|
94
|
+
* exactly: one route row, and the desktop line under it.
|
|
95
|
+
*
|
|
96
|
+
* WHICH route row is the part that matters, and it is composed by
|
|
97
|
+
* `connectRows()` below rather than being a constant, because the two routes
|
|
98
|
+
* have separate gates. They used to share a single one that short-circuited on
|
|
99
|
+
* the account key, so the `/byok-key` row disappeared the moment a user
|
|
100
|
+
* redeemed an AEGIS key — see `byokRouteNeeded()`. Holding the block to two
|
|
101
|
+
* rows is why the both-owed case merges the routes into one row again: at
|
|
102
|
+
* 80×24 a third row is the footer hint.
|
|
95
103
|
*
|
|
96
104
|
* Both commands named here are real registry entries — `/byok-key` saves a
|
|
97
105
|
* provider key, `/key` saves the AEGIS account key — and the URL is the shared
|
|
@@ -100,20 +108,65 @@ const WHATS_NEW = [
|
|
|
100
108
|
* which the bare `aegiscloud.org` this row used to print did not. Nothing here
|
|
101
109
|
* is a URL or a command that only exists in this comment.
|
|
102
110
|
*/
|
|
103
|
-
const
|
|
111
|
+
const CONNECT_BYOK = [
|
|
112
|
+
'Your own provider key: /byok-key <provider> — works with your AEGIS key',
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
// The AEGIS Cloud route. The URL in the desktop row below is the shared signup
|
|
116
|
+
// deep link from signup.js, not a hand-written one: it lands on the register
|
|
117
|
+
// panel with the key page queued behind it and the channel attached, which the
|
|
118
|
+
// bare `aegiscloud.org` that row used to print did not.
|
|
119
|
+
//
|
|
120
|
+
// The scheme-less form, and this is the only link in the CLI that uses it. The
|
|
121
|
+
// row's copy spends 45 of the 75 cells `wrapped()` allows at 80 columns
|
|
122
|
+
// (cols - 4 - indent), so `https://aegiscloud.org/key?s=cli` makes the row 77
|
|
123
|
+
// and wraps — a line the 80x24 screen does not have, because the connect
|
|
124
|
+
// block sits on row 21 of 23 and the row it pushes out is the footer hint.
|
|
125
|
+
// `s=cli` is the parameter that files the signup, so it is the scheme that
|
|
126
|
+
// goes, not the channel: see signup.js `signupDisplayUrl()`. Editing this copy
|
|
127
|
+
// means re-measuring; test/cli-onboarding.test.mjs fails on the row count if
|
|
128
|
+
// the row grows past the budget, and names the row that caused it.
|
|
129
|
+
const CONNECT_CLOUD = [
|
|
130
|
+
'AEGIS Cloud, one account key: /key — no provider signup',
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
// Both routes still owed (a fresh install): one row naming both, the original
|
|
134
|
+
// copy. Two rows is the whole budget, so this is not a third line — see the
|
|
135
|
+
// block comment above.
|
|
136
|
+
const CONNECT_BOTH = [
|
|
104
137
|
'Your key, your bill: /byok-key <provider> — or AEGIS Cloud, /key',
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// and wraps — a line the 80x24 screen does not have, because the connect
|
|
109
|
-
// block sits on row 21 of 23 and the row it pushes out is the footer hint.
|
|
110
|
-
// `s=cli` is the parameter that files the signup, so it is the scheme that
|
|
111
|
-
// goes, not the channel: see signup.js `signupDisplayUrl()`. Editing this copy
|
|
112
|
-
// means re-measuring; test/cli-onboarding.test.mjs fails on the row count if
|
|
113
|
-
// the row grows past the budget, and names the row that caused it.
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
const CONNECT_DESKTOP = [
|
|
114
141
|
`AEGIS Desktop: same engine on your machine — ${signupDisplayUrl()}`,
|
|
115
142
|
];
|
|
116
143
|
|
|
144
|
+
/**
|
|
145
|
+
* The connect rows to draw, in order, for the machine as it stands now.
|
|
146
|
+
*
|
|
147
|
+
* `[]` means nothing to say — both routes are configured — and the caller then
|
|
148
|
+
* draws no block at all. Otherwise: one route row (both-owed merges into a
|
|
149
|
+
* single row, the 80×24 budget above, and the desktop pointer always shares
|
|
150
|
+
* the block with it).
|
|
151
|
+
*
|
|
152
|
+
* The gates are independent on purpose. An AEGIS key does not cancel the
|
|
153
|
+
* `/byok-key` row and a provider route does not cancel the `/key` row: the two
|
|
154
|
+
* are not alternatives, they are two ways in, and the row a user has already
|
|
155
|
+
* taken is the only one that may be dropped.
|
|
156
|
+
*/
|
|
157
|
+
function connectRows() {
|
|
158
|
+
const rows = [];
|
|
159
|
+
const byok = byokRouteNeeded();
|
|
160
|
+
const cloud = cloudRouteNeeded();
|
|
161
|
+
if (byok && cloud) rows.push(...CONNECT_BOTH);
|
|
162
|
+
else if (byok) rows.push(...CONNECT_BYOK);
|
|
163
|
+
else if (cloud) rows.push(...CONNECT_CLOUD);
|
|
164
|
+
// The desktop pointer is not a route, so it is not gated on one: whenever the
|
|
165
|
+
// block is drawn at all, the "why would I want the app" answer is in it.
|
|
166
|
+
if (rows.length) rows.push(...CONNECT_DESKTOP);
|
|
167
|
+
return rows;
|
|
168
|
+
}
|
|
169
|
+
|
|
117
170
|
/** Centre a plain string, returning one span line. Clip first, or a string
|
|
118
171
|
* wider than the terminal produces a row that wraps and shears the frame. */
|
|
119
172
|
function centered(text, cols, style) {
|
|
@@ -354,13 +407,14 @@ function welcomeLines(ctx, cols, rows, firstRun = true) {
|
|
|
354
407
|
|
|
355
408
|
lines.push(...boxes(t, cols, rows - lines.length - 4));
|
|
356
409
|
lines.push([span('', '')]);
|
|
357
|
-
// The connect block, before the footer hint
|
|
358
|
-
//
|
|
359
|
-
//
|
|
360
|
-
//
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
410
|
+
// The connect block, before the footer hint. The rows are composed by
|
|
411
|
+
// `connectRows()` — the two routes gate SEPARATELY, so an AEGIS-key holder
|
|
412
|
+
// with no provider route of their own is still told `/byok-key` exists,
|
|
413
|
+
// which is the whole point: holding an account key is not a reason to hide
|
|
414
|
+
// the bring-your-own-key route. `wrapped` splits rather than clips, so a
|
|
415
|
+
// narrow terminal gets short rows instead of sheared ones; the height budget
|
|
416
|
+
// is unaffected at 80×24, where each row still fits on one line.
|
|
417
|
+
for (const text of connectRows()) lines.push(...wrapped(text, cols, t.white, 1));
|
|
364
418
|
lines.push([span(t.gray, GLYPH.hint), span(t.white, ' Try "write a test for <filepath>"')]);
|
|
365
419
|
while (lines.length < rows - 1) lines.push([span('', '')]);
|
|
366
420
|
return lines;
|
|
@@ -492,12 +546,14 @@ function providerRouteConfigured() {
|
|
|
492
546
|
}
|
|
493
547
|
|
|
494
548
|
/**
|
|
495
|
-
* Whether the
|
|
549
|
+
* Whether ANY part of the connect block is still owed to this machine.
|
|
496
550
|
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
551
|
+
* It is the OR of the two route gates, and it is deliberately not the thing
|
|
552
|
+
* `welcomeLines` branches on any more: the rows are composed one at a time by
|
|
553
|
+
* `connectRows()`, so a machine that holds an AEGIS account key and no
|
|
554
|
+
* provider route still gets the `/byok-key` row. This helper is the coarse
|
|
555
|
+
* question ("is there anything left to say") — a caller that wants the rows
|
|
556
|
+
* should ask `connectRows()` instead.
|
|
501
557
|
*
|
|
502
558
|
* A read that fails (no credentials file, an unreadable one) resolves to
|
|
503
559
|
* "show it": the block is exactly what a user with no key needs, and a
|
|
@@ -506,7 +562,38 @@ function providerRouteConfigured() {
|
|
|
506
562
|
*/
|
|
507
563
|
function connectNeeded() {
|
|
508
564
|
try {
|
|
509
|
-
|
|
565
|
+
return byokRouteNeeded() || cloudRouteNeeded();
|
|
566
|
+
} catch {
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* The two halves of the connect block, gated SEPARATELY — this is the fix.
|
|
573
|
+
*
|
|
574
|
+
* They used to share one gate that short-circuited on the account key, so a
|
|
575
|
+
* user who redeemed an AEGIS key was never told BYOK exists at all: the row
|
|
576
|
+
* naming `/byok-key` was retired at the exact moment they had an account and
|
|
577
|
+
* were most likely to want a provider route of their own (unlimited/no relay
|
|
578
|
+
* billing, a model the pool does not carry). An account key and a provider
|
|
579
|
+
* route are not alternatives — `/byok-key` works alongside one — so the BYOK
|
|
580
|
+
* row is now gated on the BYOK route alone and an AEGIS-key holder still
|
|
581
|
+
* reads it. The Cloud row keeps the old account-key gate, because that is the
|
|
582
|
+
* thing it pitches.
|
|
583
|
+
*
|
|
584
|
+
* Both reads fail toward SHOWING the row: a failed status read must never be
|
|
585
|
+
* the reason a new install is told nothing about how to start.
|
|
586
|
+
*/
|
|
587
|
+
function byokRouteNeeded() {
|
|
588
|
+
try {
|
|
589
|
+
return !providerRouteConfigured();
|
|
590
|
+
} catch {
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function cloudRouteNeeded() {
|
|
596
|
+
try {
|
|
510
597
|
return !credentials.keyStatus().configured;
|
|
511
598
|
} catch {
|
|
512
599
|
return true;
|
|
@@ -754,8 +841,14 @@ module.exports = {
|
|
|
754
841
|
PRODUCT,
|
|
755
842
|
TIPS,
|
|
756
843
|
WHATS_NEW,
|
|
757
|
-
|
|
844
|
+
CONNECT_BYOK,
|
|
845
|
+
CONNECT_CLOUD,
|
|
846
|
+
CONNECT_BOTH,
|
|
847
|
+
CONNECT_DESKTOP,
|
|
848
|
+
connectRows,
|
|
758
849
|
connectNeeded,
|
|
850
|
+
byokRouteNeeded,
|
|
851
|
+
cloudRouteNeeded,
|
|
759
852
|
providerRouteConfigured,
|
|
760
853
|
trustLines,
|
|
761
854
|
themePickerLines,
|
|
@@ -797,6 +797,7 @@ function createLocalEngine({
|
|
|
797
797
|
// remembering "no" makes the first answer stick.
|
|
798
798
|
const sessionDenials = new Map(); // rootSessionId -> Set<toolName>
|
|
799
799
|
const pendingApprovals = new Map(); // approvalId -> { resolve }
|
|
800
|
+
const pendingRoundAsks = new Map(); // askId -> { resolve }
|
|
800
801
|
|
|
801
802
|
function sessionAllows(rootId, name) {
|
|
802
803
|
const set = sessionAllowlists.get(rootId);
|
|
@@ -911,6 +912,62 @@ function createLocalEngine({
|
|
|
911
912
|
});
|
|
912
913
|
}
|
|
913
914
|
|
|
915
|
+
/** The renderer's rounds-dialog answer resolves the pending
|
|
916
|
+
* requestRoundsAsk() promise below. An unknown/already-answered id is a
|
|
917
|
+
* no-op, same contract as respondApproval. */
|
|
918
|
+
function respondRoundsAsk(askId, decision) {
|
|
919
|
+
const pending = pendingRoundAsks.get(askId);
|
|
920
|
+
if (!pending) return { ok: false };
|
|
921
|
+
pendingRoundAsks.delete(askId);
|
|
922
|
+
pending.resolve(decision === true || decision === 'continue');
|
|
923
|
+
return { ok: true };
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Ask the renderer whether to fund another block of tool rounds, mirroring
|
|
928
|
+
* requestApproval's shape exactly: pushed over `rootOnDelta` as a `{ rounds }`
|
|
929
|
+
* chunk (the one channel a detached renderer has into a running turn) and
|
|
930
|
+
* resolved externally via `respondRoundsAsk`. Resolves `true` (fund one more
|
|
931
|
+
* block) or `false` (stop here) — never throws. Fails safe to `false`: no
|
|
932
|
+
* listener, an aborted turn, or an unanswered ask must not keep the loop
|
|
933
|
+
* waiting forever (or, worse, spend rounds nobody agreed to).
|
|
934
|
+
*/
|
|
935
|
+
function requestRoundsAsk(rootSessionId, rootOnDelta, signal, info) {
|
|
936
|
+
return new Promise((resolve) => {
|
|
937
|
+
if (signal && signal.aborted) {
|
|
938
|
+
resolve(false);
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
const id = randomUUID();
|
|
942
|
+
let settled = false;
|
|
943
|
+
const onAbort = () => finish(false);
|
|
944
|
+
const finish = (decision) => {
|
|
945
|
+
if (settled) return;
|
|
946
|
+
settled = true;
|
|
947
|
+
pendingRoundAsks.delete(id);
|
|
948
|
+
if (signal) signal.removeEventListener('abort', onAbort);
|
|
949
|
+
resolve(decision);
|
|
950
|
+
};
|
|
951
|
+
if (signal) signal.addEventListener('abort', onAbort, { once: true });
|
|
952
|
+
pendingRoundAsks.set(id, { resolve: finish });
|
|
953
|
+
if (typeof rootOnDelta !== 'function') {
|
|
954
|
+
finish(false);
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
rootOnDelta({
|
|
958
|
+
delta: '',
|
|
959
|
+
rounds: {
|
|
960
|
+
id,
|
|
961
|
+
sessionId: rootSessionId,
|
|
962
|
+
spent: info.spent,
|
|
963
|
+
extensions: info.extensions,
|
|
964
|
+
max: info.max,
|
|
965
|
+
size: info.size,
|
|
966
|
+
},
|
|
967
|
+
});
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
|
|
914
971
|
/**
|
|
915
972
|
* The gate itself: read-only tools and already-session-allowed mutating
|
|
916
973
|
* tools run exactly like executeTool always did. A first-time mutating
|
|
@@ -1522,6 +1579,12 @@ function createLocalEngine({
|
|
|
1522
1579
|
// synthesis pass) instead of a single provider call. UI-gated to the
|
|
1523
1580
|
// 'aegis' class only (see AUTONOMOUS_CLASS in app.js).
|
|
1524
1581
|
const autonomous = cls === 'aegis' && Boolean(payload && payload.autonomous);
|
|
1582
|
+
// Opt-in only: the round-horizon dialog (requestRoundsAsk below) needs a
|
|
1583
|
+
// live renderer on the other end of `rootOnDelta` able to answer it. The
|
|
1584
|
+
// interactive CLI session sets this; the queue worker and `-p` one-shot
|
|
1585
|
+
// runs never do (nobody is there to click), so they keep the old
|
|
1586
|
+
// stop-and-record-session behaviour (sessionRounds below) untouched.
|
|
1587
|
+
const roundsAsk = Boolean(payload && payload.roundsAsk);
|
|
1525
1588
|
const sessionId = (payload && payload.sessionId) || randomUUID();
|
|
1526
1589
|
// Recursion depth for the task tool: 0 for a real user turn, N+1 for a
|
|
1527
1590
|
// subagent spawned by depth N. Never set by an IPC caller — only by
|
|
@@ -1797,8 +1860,17 @@ function createLocalEngine({
|
|
|
1797
1860
|
}
|
|
1798
1861
|
// A resumed turn gets a small bonus on top of the base horizon so
|
|
1799
1862
|
// re-orientation does not consume the new budget before any work lands.
|
|
1800
|
-
|
|
1863
|
+
let maxRounds = statedRounds || baseRounds + (resumed ? sessionRounds.bonus(baseRounds) : 0);
|
|
1801
1864
|
let round = 0;
|
|
1865
|
+
// Rounds bought by one confirmed extension, and a hard cap on how many
|
|
1866
|
+
// extensions a single turn may spend — matching the upstream engine's
|
|
1867
|
+
// numbers (src/autonomous.js ROUND_EXTENSION_SIZE/MAX_ROUND_EXTENSIONS)
|
|
1868
|
+
// so a turn behaves the same whether it runs there or here. The cap
|
|
1869
|
+
// exists even though the renderer is the one asking: a dialog that
|
|
1870
|
+
// always says yes must still terminate (8 x baseRounds extra rounds).
|
|
1871
|
+
const ROUND_EXTENSION_SIZE = baseRounds;
|
|
1872
|
+
const MAX_ROUND_EXTENSIONS = 8;
|
|
1873
|
+
let extensions = 0;
|
|
1802
1874
|
|
|
1803
1875
|
// Token accounting for the whole TURN, not just its last round. An
|
|
1804
1876
|
// agentic turn makes one provider call per tool round, and returning only
|
|
@@ -1858,11 +1930,49 @@ function createLocalEngine({
|
|
|
1858
1930
|
// which is the same "(empty response)" failure the guards below exist
|
|
1859
1931
|
// to prevent.
|
|
1860
1932
|
if (round >= maxRounds) {
|
|
1933
|
+
// Before conceding, give an interactive caller the chance to fund
|
|
1934
|
+
// another block of rounds instead of ending the turn outright — the
|
|
1935
|
+
// upstream engine's "asks" contract (src/backend.js requestExtension).
|
|
1936
|
+
// Only reachable with `roundsAsk` AND a live signal: a caller with no
|
|
1937
|
+
// renderer on the other end (queue, `-p`) falls straight through to
|
|
1938
|
+
// the session-hold stop below, unchanged.
|
|
1939
|
+
if (roundsAsk && extensions < MAX_ROUND_EXTENSIONS && !signal.aborted) {
|
|
1940
|
+
const granted = await requestRoundsAsk(rootSessionId, rootOnDelta, signal, {
|
|
1941
|
+
spent: maxRounds,
|
|
1942
|
+
extensions: extensions + 1,
|
|
1943
|
+
max: MAX_ROUND_EXTENSIONS,
|
|
1944
|
+
size: ROUND_EXTENSION_SIZE,
|
|
1945
|
+
});
|
|
1946
|
+
if (granted) {
|
|
1947
|
+
extensions += 1;
|
|
1948
|
+
const spent = maxRounds;
|
|
1949
|
+
maxRounds += ROUND_EXTENSION_SIZE;
|
|
1950
|
+
history.push({
|
|
1951
|
+
role: 'user',
|
|
1952
|
+
content: `You have used all ${spent} tool rounds allowed for this turn; ` +
|
|
1953
|
+
`${ROUND_EXTENSION_SIZE} more have been granted (do not restart). Continue the task ` +
|
|
1954
|
+
'from exactly where you stopped — do not re-plan, do not repeat work already done, ' +
|
|
1955
|
+
'and finish with an answer.',
|
|
1956
|
+
});
|
|
1957
|
+
continue;
|
|
1958
|
+
}
|
|
1959
|
+
// Declined (or the extension cap is spent): fall through to the
|
|
1960
|
+
// same session-hold stop a non-interactive caller gets, so a "no"
|
|
1961
|
+
// here is bit-for-bit the old hard stop rather than a dead end.
|
|
1962
|
+
}
|
|
1963
|
+
// The knob is only advice where nobody could have been asked about
|
|
1964
|
+
// it. An interactive caller was already offered another block of
|
|
1965
|
+
// rounds (requestRoundsAsk above) and declined or spent the cap, so
|
|
1966
|
+
// pointing it at an env var it cannot set from inside the app — and
|
|
1967
|
+
// would have to restart to apply — is obsolete text: drop it. The
|
|
1968
|
+
// queue worker and `-p` one-shots have no dialog, so for them the
|
|
1969
|
+
// variable remains the only lever and is still named.
|
|
1970
|
+
const knob = roundsAsk ? '' : `, or raise ${roundEnvName} for a longer single turn`;
|
|
1861
1971
|
const note =
|
|
1862
1972
|
`[stopped at ${maxRounds} tool rounds` +
|
|
1863
1973
|
`${turnUsage.total_tokens ? `, ${turnUsage.total_tokens.toLocaleString()} tokens` : ''}` +
|
|
1864
1974
|
`. This session holds the work: your next message here resumes it automatically` +
|
|
1865
|
-
` (with a continuation preamble)
|
|
1975
|
+
` (with a continuation preamble)${knob}.]`;
|
|
1866
1976
|
// File the interruption before returning, so the horizon is a pause
|
|
1867
1977
|
// in the session rather than the end of the job. `chain` carries the
|
|
1868
1978
|
// count forward across resumes.
|
|
@@ -2146,6 +2256,7 @@ function createLocalEngine({
|
|
|
2146
2256
|
chat,
|
|
2147
2257
|
cancel,
|
|
2148
2258
|
respondApproval,
|
|
2259
|
+
respondRoundsAsk,
|
|
2149
2260
|
clearSessionApprovals,
|
|
2150
2261
|
settings,
|
|
2151
2262
|
unloadLocalModels,
|