aegiscode 6.8.2 → 6.8.4
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/bin/aegiscode.js +35 -5
- package/package.json +1 -1
- package/scripts/predist.mjs +99 -0
- package/src/app.js +40 -8
- package/src/chatflow.js +181 -33
- package/src/commands.js +172 -22
- package/src/deps.js +2 -1
- package/src/events.js +37 -14
- package/src/mcp.js +683 -0
- package/src/panels.js +65 -15
- package/src/screen.js +130 -5
- package/src/screens.js +36 -7
- package/src/signup.js +153 -0
- package/src/title.js +217 -0
- package/src/tokens.js +74 -95
- package/src/update.js +75 -1
- package/vendor/desktop/lib/local/engine.js +24 -0
- package/vendor/desktop/lib/settings.js +67 -0
- package/vendor/desktop/renderer/usage.js +372 -41
- package/vendor/hosts/install.js +638 -0
- package/vendor/hosts/openai-shim.js +419 -0
- package/vendor/hosts/spec.js +164 -0
- package/vendor/hosts/targets.js +346 -0
- package/vendor/mcp/server.js +186 -0
package/src/commands.js
CHANGED
|
@@ -57,6 +57,7 @@ const {
|
|
|
57
57
|
} = require('./config.js');
|
|
58
58
|
const { copyToClipboard } = require('./clipboard.js');
|
|
59
59
|
const { snapshotCheckpoint, listCheckpoints, loadCheckpoint } = require('./checkpoint.js');
|
|
60
|
+
const { signupUrl, goUrl } = require('./signup.js');
|
|
60
61
|
const screens = require('./screens.js');
|
|
61
62
|
const { summarizeTranscript, recapLine } = require('./summarize.js');
|
|
62
63
|
const { sessionAccounting, accountingFromUsage, estimateTokens } = require('./tokens.js');
|
|
@@ -68,6 +69,7 @@ const { maskKey, fmtTokens } = require('./format.js');
|
|
|
68
69
|
const { pickerEntries } = require('./models.js');
|
|
69
70
|
const { openUrl, URLS } = require('./system.js');
|
|
70
71
|
const { sniffProject, buildAegisMd } = require('./init.js');
|
|
72
|
+
const { upgradeAdvice, latestPublishedVersion } = require('./update.js');
|
|
71
73
|
const {
|
|
72
74
|
AGENT_PRESETS, agentRoles, composeAgentPrompt, composeResearchPrompt, composeDebatePrompt,
|
|
73
75
|
} = require('./agents.js');
|
|
@@ -116,6 +118,106 @@ const tip = (c, text) => c.push({ role: 'tip', text });
|
|
|
116
118
|
const done = (c, text) => c.push({ role: 'done', text });
|
|
117
119
|
const shortCwd = () => process.cwd().split('/').filter(Boolean).pop() || '~';
|
|
118
120
|
|
|
121
|
+
// ── The multi-agent fan-out (/multi run, /multiyolo, /aegis-multi run) ────────
|
|
122
|
+
//
|
|
123
|
+
// These three commands used to only *compose* text: /multi <task> run and
|
|
124
|
+
// /aegis-multi <task> run printed "Running the task through the pooled brain
|
|
125
|
+
// (single-model — the reference fans it out)" and handed the raw task to
|
|
126
|
+
// c.runPrompt — a single turn, not a fan-out — while /multiyolo printed the
|
|
127
|
+
// paste-ready panel and never executed anything at all, so its `savePermissions
|
|
128
|
+
// ({ defaultMode: 'allow' })` turned YOLO on and then did nothing with it.
|
|
129
|
+
//
|
|
130
|
+
// The reference (aegiscodex-dev) calls `multiData(task, { signal })`, which
|
|
131
|
+
// shells out to aegis-cli (`aegis --print "/multi <task>"`) because the fan-out
|
|
132
|
+
// lives in that binary. This host has no aegis-cli, and a shell-out that fails
|
|
133
|
+
// on every machine without one is not a port — so the real multi-agent runtime
|
|
134
|
+
// here is the engine's own `task` tool (desktop/lib/local/engine.js
|
|
135
|
+
// `runSubagent`: a specialist subagent with its own tool loop, session id and
|
|
136
|
+
// approval card, primed from agents.js). One turn drives it, and the delegation
|
|
137
|
+
// is executed rather than described.
|
|
138
|
+
|
|
139
|
+
/** The fan-out prompt handed to the engine — the specialists are named so the delegation actually happens. */
|
|
140
|
+
function composeMultiFanoutPrompt(task) {
|
|
141
|
+
return [
|
|
142
|
+
'Execute this task as a multi-agent fan-out.',
|
|
143
|
+
'',
|
|
144
|
+
`Task: ${task}`,
|
|
145
|
+
'',
|
|
146
|
+
`Workspace: ${process.cwd()}`,
|
|
147
|
+
'',
|
|
148
|
+
'Use the task tool to delegate the independent parts to specialist subagents, in parallel where they do not depend on each other:',
|
|
149
|
+
'- reconnaissance first (scanner for secrets/unsafe patterns, analyzer for refactor targets),',
|
|
150
|
+
'- then design (architect, or planner when the work is a change to existing code),',
|
|
151
|
+
'- then an implementer subagent to make the change.',
|
|
152
|
+
'Finally review the result (reviewer subagent), fix what it finds, and verify with the repository\'s real commands.',
|
|
153
|
+
'',
|
|
154
|
+
'Return one consolidated report: what each subagent found, the files you changed, the exact commands you ran and their real output, and anything still blocked. No preamble.',
|
|
155
|
+
].join('\n');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The this-host `multiData(task, { signal })`. Returns the reference's shape —
|
|
160
|
+
* `{ result, model, provider }`, `{ cancelled }`, or `{ error }` — so callers
|
|
161
|
+
* render it through `panels.buildAegisPrint` exactly as the reference does.
|
|
162
|
+
* `{ error }` is the honest fallback: the caller says why and still hands the
|
|
163
|
+
* user a paste-ready command instead of pretending the fan-out ran.
|
|
164
|
+
*/
|
|
165
|
+
async function multiData(c, task) {
|
|
166
|
+
const prompt = composeMultiFanoutPrompt(task);
|
|
167
|
+
const run = c && c.withWorking ? (fn) => c.withWorking(fn) : (fn) => fn();
|
|
168
|
+
// A context with no agent loop at all (no ask, no runPrompt) is the one case
|
|
169
|
+
// this cannot execute — say so rather than returning an empty success.
|
|
170
|
+
if (!c || (typeof c.ask !== 'function' && typeof c.runPrompt !== 'function')) {
|
|
171
|
+
return { error: 'No agent loop in this context — the fan-out prompt was composed, not run.' };
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
if (typeof c.ask === 'function') {
|
|
175
|
+
const res = await run((signal) => c.ask(prompt, { signal }));
|
|
176
|
+
const text = (res && res.text) || '';
|
|
177
|
+
if (res && res.interrupted && !text) return { cancelled: true };
|
|
178
|
+
if (!text) return { error: 'The multi-agent fan-out returned nothing (the turn failed before it could delegate).' };
|
|
179
|
+
return { result: text, model: (res && res.model) || (c.ctx && c.ctx.model) || null, provider: 'aegis' };
|
|
180
|
+
}
|
|
181
|
+
// No captured-answer path: still execute, streamed into the transcript.
|
|
182
|
+
await run(() => c.runPrompt(prompt));
|
|
183
|
+
return { streamed: true };
|
|
184
|
+
} catch (e) {
|
|
185
|
+
return { error: `ÆGIS multi failed — ${(e && e.message) || e}` };
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Drive one of the three fan-out commands end to end. `yolo` is /multiyolo's
|
|
191
|
+
* edge: the permission mode is set to allow *and* the task then executes under
|
|
192
|
+
* it (previously it was set and never used).
|
|
193
|
+
*/
|
|
194
|
+
async function runMultiCommand(c, task, { yolo = false, title = 'ÆGIS Multi' } = {}) {
|
|
195
|
+
if (yolo) {
|
|
196
|
+
const rules = loadPermissions();
|
|
197
|
+
savePermissions({ ...rules, defaultMode: 'allow' });
|
|
198
|
+
panel(c, panels.buildYolo(c.state(), c.ctx));
|
|
199
|
+
}
|
|
200
|
+
note(c, 'Running the multi-agent fan-out — the engine delegates to specialist subagents (headless: this skips aegis-cli\'s own confirmation step).');
|
|
201
|
+
c.render();
|
|
202
|
+
const res = await multiData(c, task);
|
|
203
|
+
if (res.cancelled) { note(c, 'ÆGIS multi cancelled.'); c.render(); return true; }
|
|
204
|
+
if (res.error) {
|
|
205
|
+
note(c, res.error);
|
|
206
|
+
// Unreachable is not the same as useless: hand over the command that runs
|
|
207
|
+
// it in a real aegis-cli session.
|
|
208
|
+
panel(c, panels.buildAegisMulti(task, c.ctx));
|
|
209
|
+
c.render();
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
if (res.streamed) return true;
|
|
213
|
+
panel(c, panels.buildAegisPrint(title, res, c.ctx));
|
|
214
|
+
c.render();
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** /upgrade's advice as panel rows (the advice itself is plain strings). */
|
|
219
|
+
const upgradePanelLines = (lines) => lines.map((l) => [span(C.white, l)]);
|
|
220
|
+
|
|
119
221
|
/**
|
|
120
222
|
* The pinnable-model list for the class the session is on, fetched fresh.
|
|
121
223
|
*
|
|
@@ -258,7 +360,7 @@ function keyPanelLines(c, title = 'AEGIS account key') {
|
|
|
258
360
|
if (!st.configured) {
|
|
259
361
|
lines.push([span(C.gray, '')]);
|
|
260
362
|
lines.push([span(C.white, ' Set one with /key <api_key>, or press Enter on /key to paste it.')]);
|
|
261
|
-
lines.push([span(C.gray,
|
|
363
|
+
lines.push([span(C.gray, ` Free key: ${signupUrl('key_status')}`)]);
|
|
262
364
|
}
|
|
263
365
|
if (st.legacyPlaintext) {
|
|
264
366
|
lines.push([span(C.gray, '')]);
|
|
@@ -406,7 +508,15 @@ function memoryStatusLines(c) {
|
|
|
406
508
|
if (st.overQuota) {
|
|
407
509
|
rows.push([span(C.coral, ' writes: paused — the plan’s ceiling is reached, so new memory is not being stored')]);
|
|
408
510
|
rows.push([span(C.green, ' reads: still work — everything already stored stays readable (/aegis-recall <topic>)')]);
|
|
409
|
-
rows
|
|
511
|
+
// Two rows, not one. This was a single 92-cell line ending in
|
|
512
|
+
// "or /cloud memory off to stop trying", and panel rows go through
|
|
513
|
+
// `padLine()`, which TRUNCATES at `cols` instead of wrapping — so at 80
|
|
514
|
+
// columns the escape hatch was cut off the end and never rendered. The URL
|
|
515
|
+
// gets its own row for the same reason: it is the actionable half, and
|
|
516
|
+
// truncation is survivable in prose and fatal in a URL. The rows are 76 and
|
|
517
|
+
// 45 cells of 80, both asserted by test/cli-commands.test.mjs.
|
|
518
|
+
rows.push([span(C.gray, ` free room at ${goUrl('upgrade', 'cloud_quota')}`)]);
|
|
519
|
+
rows.push([span(C.gray, ' or /cloud memory off to stop trying')]);
|
|
410
520
|
}
|
|
411
521
|
if (gate.enabled && st.pending > 0) {
|
|
412
522
|
rows.push([span(C.gray, ` pending: ${st.pending} session(s) waiting to sync`)]);
|
|
@@ -843,7 +953,7 @@ const COMMANDS = [
|
|
|
843
953
|
: // The key travels in the environment only (client/aegis.js reads
|
|
844
954
|
// AEGIS_API_KEY); /login is an unavailable command here, so
|
|
845
955
|
// pointing at it would send the user to a refusal.
|
|
846
|
-
|
|
956
|
+
`No API key set, so the model catalog cannot be read — export AEGIS_API_KEY (free key: ${signupUrl('model_blocked')}), then retry /model.`);
|
|
847
957
|
c.render();
|
|
848
958
|
return true;
|
|
849
959
|
}
|
|
@@ -993,7 +1103,13 @@ const COMMANDS = [
|
|
|
993
1103
|
const task = (args._rest || '').trim().replace(/^\S+\s*/, '').trim();
|
|
994
1104
|
if (!task) { note(c, `Usage: /agents <role> <task> — roles: ${agentRoles().join(', ')}`); c.render(); return true; }
|
|
995
1105
|
if (!AGENT_PRESETS[role]) { note(c, `Unknown agent role "${role}". Roles: ${agentRoles().join(', ')}`); c.render(); return true; }
|
|
996
|
-
|
|
1106
|
+
const prompt = composeAgentPrompt(role, task);
|
|
1107
|
+
if (c.runPrompt) {
|
|
1108
|
+
await c.runPrompt(prompt);
|
|
1109
|
+
return true;
|
|
1110
|
+
}
|
|
1111
|
+
note(c, `Composed ${role} prompt (${prompt.length} chars) — run in the TUI to send it.`);
|
|
1112
|
+
c.render();
|
|
997
1113
|
return true;
|
|
998
1114
|
}
|
|
999
1115
|
panel(c, panels.buildAgents(c.state(), c.ctx));
|
|
@@ -1151,7 +1267,7 @@ const COMMANDS = [
|
|
|
1151
1267
|
ks.configured,
|
|
1152
1268
|
ks.configured
|
|
1153
1269
|
? `${maskKey(ks.key)} via ${credentials.sourceLabel(ks.source)}`
|
|
1154
|
-
: `not set — ${credentials.HOW_TO_SET} (free
|
|
1270
|
+
: `not set — ${credentials.HOW_TO_SET} (free key: ${signupUrl('doctor')})`
|
|
1155
1271
|
);
|
|
1156
1272
|
ok('credentials', true, `${ks.path}${ks.fileMode ? ` (${ks.fileMode})` : ''}`);
|
|
1157
1273
|
ok('cloud memory', ks.memoryToken, ks.memoryToken ? 'token held' : 'no memory token — /cloud activate');
|
|
@@ -1172,6 +1288,22 @@ const COMMANDS = [
|
|
|
1172
1288
|
return true;
|
|
1173
1289
|
},
|
|
1174
1290
|
},
|
|
1291
|
+
{
|
|
1292
|
+
name: 'upgrade', args: ['action'], hint: '[check]', category: 'support',
|
|
1293
|
+
desc: 'Check for a newer published version',
|
|
1294
|
+
handler: async (c) => {
|
|
1295
|
+
note(c, 'Checking the npm registry…');
|
|
1296
|
+
c.render();
|
|
1297
|
+
// The registry lookup is a blocking `npm view`, so it runs inside the
|
|
1298
|
+
// spinner when the context offers one (and is skipped entirely in demo
|
|
1299
|
+
// mode, where a network answer would be a lie).
|
|
1300
|
+
const run = c && c.withWorking ? (fn) => c.withWorking(fn) : (fn) => fn();
|
|
1301
|
+
const latest = c.ctx && c.ctx.demo ? null : await run(() => Promise.resolve(latestPublishedVersion()));
|
|
1302
|
+
panel(c, upgradePanelLines(upgradeAdvice({ latest }).lines));
|
|
1303
|
+
c.render();
|
|
1304
|
+
return true;
|
|
1305
|
+
},
|
|
1306
|
+
},
|
|
1175
1307
|
{
|
|
1176
1308
|
name: 'vim', args: ['mode'], hint: '[on|off]', category: 'model',
|
|
1177
1309
|
desc: 'Toggle vim keymap',
|
|
@@ -1572,13 +1704,10 @@ const COMMANDS = [
|
|
|
1572
1704
|
handler: async (c, args) => {
|
|
1573
1705
|
const task = (args._rest || args.task || '').trim();
|
|
1574
1706
|
if (!task) { note(c, 'Usage: /multiyolo <task>'); c.render(); return true; }
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
panel(c, panels.buildAegisMulti(task, c.ctx));
|
|
1580
|
-
c.render();
|
|
1581
|
-
return true;
|
|
1707
|
+
// YOLO is the point of this alias: auto-approve, then actually run the
|
|
1708
|
+
// fan-out. Composing the text and stopping (what this used to do) left the
|
|
1709
|
+
// user with an enabled YOLO mode and an unexecuted task.
|
|
1710
|
+
return runMultiCommand(c, task, { yolo: true });
|
|
1582
1711
|
},
|
|
1583
1712
|
},
|
|
1584
1713
|
{
|
|
@@ -1628,9 +1757,7 @@ const COMMANDS = [
|
|
|
1628
1757
|
if (mode !== 'run' && /\s+run$/i.test(task)) { mode = 'run'; task = task.replace(/\s+run$/i, '').trim(); }
|
|
1629
1758
|
if (!task) { note(c, 'Usage: /multi <task> [run]'); c.render(); return true; }
|
|
1630
1759
|
if (mode !== 'run') { panel(c, panels.buildAegisMulti(task, c.ctx)); c.render(); return true; }
|
|
1631
|
-
|
|
1632
|
-
await c.runPrompt(task);
|
|
1633
|
-
return true;
|
|
1760
|
+
return runMultiCommand(c, task);
|
|
1634
1761
|
},
|
|
1635
1762
|
},
|
|
1636
1763
|
{
|
|
@@ -1639,7 +1766,16 @@ const COMMANDS = [
|
|
|
1639
1766
|
handler: async (c, args) => {
|
|
1640
1767
|
const q = (args._rest || args.question || '').trim();
|
|
1641
1768
|
if (!q) { note(c, 'Usage: /research <question>'); c.render(); return true; }
|
|
1642
|
-
|
|
1769
|
+
const prompt = composeResearchPrompt(q, process.cwd());
|
|
1770
|
+
// Unguarded, `c.runPrompt` made this throw on any context without one
|
|
1771
|
+
// (the command smoke test caught the class of bug; the reference guards
|
|
1772
|
+
// it the same way). Composed-but-unrunnable is reported, not swallowed.
|
|
1773
|
+
if (c.runPrompt) {
|
|
1774
|
+
await c.runPrompt(prompt);
|
|
1775
|
+
return true;
|
|
1776
|
+
}
|
|
1777
|
+
note(c, `Composed research prompt (${prompt.length} chars) — run in the TUI to send it.`);
|
|
1778
|
+
c.render();
|
|
1643
1779
|
return true;
|
|
1644
1780
|
},
|
|
1645
1781
|
},
|
|
@@ -1649,7 +1785,13 @@ const COMMANDS = [
|
|
|
1649
1785
|
handler: async (c, args) => {
|
|
1650
1786
|
const topic = (args._rest || args.topic || '').trim();
|
|
1651
1787
|
if (!topic) { note(c, 'Usage: /debate <topic>'); c.render(); return true; }
|
|
1652
|
-
|
|
1788
|
+
const prompt = composeDebatePrompt(topic, c.ctx.model || '');
|
|
1789
|
+
if (c.runPrompt) {
|
|
1790
|
+
await c.runPrompt(prompt);
|
|
1791
|
+
return true;
|
|
1792
|
+
}
|
|
1793
|
+
note(c, `Composed debate prompt (${prompt.length} chars) — run in the TUI to send it.`);
|
|
1794
|
+
c.render();
|
|
1653
1795
|
return true;
|
|
1654
1796
|
},
|
|
1655
1797
|
},
|
|
@@ -1710,7 +1852,11 @@ const COMMANDS = [
|
|
|
1710
1852
|
credentials.clearMemoryToken();
|
|
1711
1853
|
c.client.setApiKey(c.client.apiKey);
|
|
1712
1854
|
note(c, 'cloud memory token cleared locally — sync stops until /cloud activate re-issues one');
|
|
1713
|
-
|
|
1855
|
+
// The URL rides its own note: `note` rows are a single unwrapped span
|
|
1856
|
+
// (chatflow.js), so appending it to that sentence would push the tail
|
|
1857
|
+
// past `cols` where `padLine()` cuts it — and the tail is the URL.
|
|
1858
|
+
note(c, 'the account itself is still subscribed; manage the subscription here:');
|
|
1859
|
+
note(c, goUrl('upgrade', 'cloud_deactivate'));
|
|
1714
1860
|
c.render();
|
|
1715
1861
|
return true;
|
|
1716
1862
|
}
|
|
@@ -1904,7 +2050,13 @@ const COMMANDS = [
|
|
|
1904
2050
|
handler: async (c, args) => {
|
|
1905
2051
|
const q = (args._rest || args.question || '').trim();
|
|
1906
2052
|
if (!q) { note(c, 'Usage: /aegis-council <question>'); c.render(); return true; }
|
|
1907
|
-
|
|
2053
|
+
const prompt = composeResearchPrompt(`Deliberate as a council and vote on: ${q}`, process.cwd());
|
|
2054
|
+
if (c.runPrompt) {
|
|
2055
|
+
await c.runPrompt(prompt);
|
|
2056
|
+
return true;
|
|
2057
|
+
}
|
|
2058
|
+
note(c, `Composed council prompt (${prompt.length} chars) — run in the TUI to send it.`);
|
|
2059
|
+
c.render();
|
|
1908
2060
|
return true;
|
|
1909
2061
|
},
|
|
1910
2062
|
},
|
|
@@ -1931,9 +2083,7 @@ const COMMANDS = [
|
|
|
1931
2083
|
if (mode !== 'run' && /\s+run$/i.test(task)) { mode = 'run'; task = task.replace(/\s+run$/i, '').trim(); }
|
|
1932
2084
|
if (!task) { note(c, 'Usage: /aegis-multi <task> [run]'); c.render(); return true; }
|
|
1933
2085
|
if (mode !== 'run') { panel(c, panels.buildAegisMulti(task, c.ctx)); c.render(); return true; }
|
|
1934
|
-
|
|
1935
|
-
await c.runPrompt(task);
|
|
1936
|
-
return true;
|
|
2086
|
+
return runMultiCommand(c, task);
|
|
1937
2087
|
},
|
|
1938
2088
|
},
|
|
1939
2089
|
|
package/src/deps.js
CHANGED
|
@@ -66,7 +66,7 @@ const autonomousPath = resolveShared(path.join('desktop', 'lib', 'local', 'auton
|
|
|
66
66
|
|
|
67
67
|
const { createClient } = require(clientPath);
|
|
68
68
|
const { createTools } = require(toolsPath);
|
|
69
|
-
const { usageTokens } = require(usagePath);
|
|
69
|
+
const { usageTokens, usageBuckets } = require(usagePath);
|
|
70
70
|
const { createLocalEngine } = require(enginePath);
|
|
71
71
|
const { createSettingsStore, isReservedNamespace } = require(settingsPath);
|
|
72
72
|
const { agentRoles, agentRoleLabel } = require(agentsPath);
|
|
@@ -80,6 +80,7 @@ module.exports = {
|
|
|
80
80
|
createClient,
|
|
81
81
|
createTools,
|
|
82
82
|
usageTokens,
|
|
83
|
+
usageBuckets,
|
|
83
84
|
createLocalEngine,
|
|
84
85
|
createSettingsStore,
|
|
85
86
|
isReservedNamespace,
|
package/src/events.js
CHANGED
|
@@ -188,28 +188,45 @@ function feed(c) {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
/**
|
|
191
|
-
* SGR mouse
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
191
|
+
* SGR mouse sequence → a wheel direction ('up'/'down') or a left-button
|
|
192
|
+
* gesture, with the wire's own 1-based coordinates.
|
|
193
|
+
*
|
|
194
|
+
* Button codes: 0/1/2 are left/middle/right, 64/65 are wheel up/down, and bit
|
|
195
|
+
* 32 (0b100000) marks a motion event — with DECSET 1002 the terminal reports
|
|
196
|
+
* one per cell of a sweep while the left button is held. Modifier bits (shift
|
|
197
|
+
* 4, meta 8, ctrl 16) are masked off so Shift+wheel and Shift-click still work.
|
|
198
|
+
*
|
|
199
|
+
* A gesture therefore arrives as a triplet and is named stage by stage, so the
|
|
200
|
+
* caller can tell a click from a marking:
|
|
201
|
+
*
|
|
202
|
+
* press {name:'click'} 'M', left button, no motion bit
|
|
203
|
+
* sweep {name:'drag'} 'M', left button, motion bit set
|
|
204
|
+
* release {name:'release'} 'm' terminator (or the X10-style code 3)
|
|
205
|
+
*
|
|
206
|
+
* chatflow.js defers the click to the release, because with 1002 tracking
|
|
207
|
+
* enabled the SAME press can turn into a drag: acting on 'click' straight away
|
|
208
|
+
* would toggle an edit block at the start of every text selection swept across
|
|
209
|
+
* one. Right/middle clicks and anything unrecognized return null, and the
|
|
210
|
+
* caller then falls through to the ordinary CSI decoder, which ignores it — so
|
|
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.
|
|
197
213
|
*/
|
|
198
214
|
function parseSgrMouse(seq) {
|
|
199
215
|
const m = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])$/.exec(seq);
|
|
200
216
|
if (!m) return null;
|
|
201
217
|
const code = parseInt(m[1], 10);
|
|
202
|
-
|
|
218
|
+
const col = parseInt(m[2], 10);
|
|
219
|
+
const row = parseInt(m[3], 10);
|
|
220
|
+
if (!Number.isFinite(code) || !Number.isFinite(col) || !Number.isFinite(row)) return null;
|
|
203
221
|
const base = code & ~0b111100;
|
|
204
222
|
if (base === 64) return 'up';
|
|
205
223
|
if (base === 65) return 'down';
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
return null;
|
|
224
|
+
// Code 3 is "no button" — the X10 encoding of a release, which some
|
|
225
|
+
// terminals and multiplexers still send instead of SGR's `m`.
|
|
226
|
+
if ((code & 3) === 3 && m[4] === 'M') return { name: 'release', col, row };
|
|
227
|
+
if ((code & 3) !== 0) return null; // middle/right button — not ours
|
|
228
|
+
if (m[4] === 'm') return { name: 'release', col, row };
|
|
229
|
+
return (code & 32) !== 0 ? { name: 'drag', col, row } : { name: 'click', col, row };
|
|
213
230
|
}
|
|
214
231
|
|
|
215
232
|
function dispatch(key) {
|
|
@@ -307,6 +324,12 @@ function resetKeyStream() {
|
|
|
307
324
|
|
|
308
325
|
module.exports = {
|
|
309
326
|
KEY,
|
|
327
|
+
// Exported for `test/cli-marking.test.mjs`: the click/drag/release split is
|
|
328
|
+
// the half of the marking gesture that is pure decoding, and it is the half
|
|
329
|
+
// that regressed silently once already (only left presses were named, so a
|
|
330
|
+
// sweep arrived as a single cell and nothing copied). A test that can't reach
|
|
331
|
+
// it can't pin it.
|
|
332
|
+
parseSgrMouse,
|
|
310
333
|
attachKeyStream,
|
|
311
334
|
suspendKeyStream,
|
|
312
335
|
resumeKeyStream,
|