@alexwkleung/reika 0.5.0 → 0.6.0
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 +1 -1
- package/README.zh-CN.md +18 -18
- package/dist/agent/loop.js +31 -2
- package/dist/approval.js +6 -0
- package/dist/search/_chrome.js +92 -19
- package/dist/search/cdp.js +6 -1
- package/dist/tools/_danger.js +98 -20
- package/dist/tools/bash.js +2 -1
- package/dist/ui/App.js +78 -13
- package/dist/ui/Approval.js +15 -5
- package/dist/ui/Scrollback.js +7 -1
- package/dist/ui/framedrops.js +34 -0
- package/dist/ui/syncframe.js +7 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -141,7 +141,7 @@ The same pages are on the website, [reikacode.com](https://reikacode.com).
|
|
|
141
141
|
|
|
142
142
|
## Inspired by
|
|
143
143
|
|
|
144
|
-
Claude Code, Codex, Crush, OpenCode, Pi, Aider, DeepSeek Harness, Qwen Code, Kimi Code CLI, Gemini CLI, Junie, and
|
|
144
|
+
Claude Code, Codex, Crush, OpenCode, Pi, Aider, DeepSeek Harness, Qwen Code, Kimi Code CLI, Gemini CLI, Junie, DS4, and Ante.
|
|
145
145
|
|
|
146
146
|
## License
|
|
147
147
|
|
package/README.zh-CN.md
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
13
|
<p align="center">
|
|
14
|
-
<a href="https://reikacode.com">网站</a> ·
|
|
14
|
+
<a href="https://reikacode.com/zh/">网站</a> ·
|
|
15
15
|
<a href="#快速开始">快速开始</a> ·
|
|
16
16
|
<a href="#文档">文档</a> ·
|
|
17
|
-
<a href="docs/models.md">测试过的模型</a> ·
|
|
17
|
+
<a href="docs/zh/models.md">测试过的模型</a> ·
|
|
18
18
|
<a href="README.md">English</a>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
@@ -51,7 +51,7 @@ Reika 还处于 1.0 之前,命令、设置和行为在不同版本之间仍可
|
|
|
51
51
|
|
|
52
52
|
## 要求
|
|
53
53
|
|
|
54
|
-
- Node.js 22 或更新版本(macOS 11+,或 glibc 2.28+ 的 Linux —— 见[平台](docs/platforms.md))。
|
|
54
|
+
- Node.js 22 或更新版本(macOS 11+,或 glibc 2.28+ 的 Linux —— 见[平台](docs/zh/platforms.md))。
|
|
55
55
|
- 一个 OpenAI 兼容的模型服务器:llama.cpp、MLX、vLLM 或云端 API。
|
|
56
56
|
- macOS 是主要平台。Linux 可用,但没有 shell 沙箱和图片粘贴 OCR(可以设置 `REIKA_VISION_MODEL`,改用视觉模型读取粘贴的图片)。Windows 或许能在 WSL2 下运行。
|
|
57
57
|
- 现代终端(iTerm2、Ghostty、Kitty 等)。想要正确的 TUI 渲染,建议使用它们。
|
|
@@ -123,24 +123,24 @@ cd your-project && reika
|
|
|
123
123
|
|
|
124
124
|
## 文档
|
|
125
125
|
|
|
126
|
-
这些页面也在网站 [reikacode.com](https://reikacode.com)
|
|
127
|
-
|
|
128
|
-
| 文档
|
|
129
|
-
|
|
|
130
|
-
| [配置](docs/configuration.md)
|
|
131
|
-
| [模式、无头与命令](docs/usage.md)
|
|
132
|
-
| [工具](docs/tools.md)
|
|
133
|
-
| [指令与技能](docs/skills.md)
|
|
134
|
-
| [测试过的模型](docs/models.md) | Reika 实际跑过的本地量化版本和 API |
|
|
135
|
-
| [测量结果](docs/findings.md)
|
|
136
|
-
| [平台](docs/platforms.md) | 运行要求、在弱机器上运行、Linux 和 Windows 上的差异 |
|
|
137
|
-
| [架构与注意事项](docs/architecture.md) | 框架如何工作,以及已知限制 |
|
|
138
|
-
| [贡献](CONTRIBUTING.md)
|
|
139
|
-
| [更新日志](CHANGELOG.md)(英文)
|
|
126
|
+
这些页面也在网站 [reikacode.com/zh](https://reikacode.com/zh/) 上。模型、平台和架构已翻译为中文,其余页面暂为英文。
|
|
127
|
+
|
|
128
|
+
| 文档 | 内容 |
|
|
129
|
+
| ----------------------------------------- | ---------------------------------------------------------------- |
|
|
130
|
+
| [配置](docs/configuration.md) | 每一个 `.env` 键、实验性开关、具名 profile、上次会话状态 |
|
|
131
|
+
| [模式、无头与命令](docs/usage.md) | 各模式详解、`reika -p`、斜杠命令、`/save` 会话记录 |
|
|
132
|
+
| [工具](docs/tools.md) | 模型可用的工具、审批提示、网络搜索设置、MCP 服务器、`.gitignore` |
|
|
133
|
+
| [指令与技能](docs/skills.md) | `AGENTS.md`、作为斜杠命令的技能、自然语言路由、粘贴的链接 |
|
|
134
|
+
| [测试过的模型](docs/zh/models.md) | Reika 实际跑过的本地量化版本和 API |
|
|
135
|
+
| [测量结果](docs/findings.md) | 实测记录:什么坏了、什么撑住了,以及每个数字是怎么得到的 |
|
|
136
|
+
| [平台](docs/zh/platforms.md) | 运行要求、在弱机器上运行、Linux 和 Windows 上的差异 |
|
|
137
|
+
| [架构与注意事项](docs/zh/architecture.md) | 框架如何工作,以及已知限制 |
|
|
138
|
+
| [贡献](CONTRIBUTING.md) | 脚本、设计理念、`AGENTS.md` 指引,以及外部贡献者指南 |
|
|
139
|
+
| [更新日志](CHANGELOG.md)(英文) | 每个版本的变更 |
|
|
140
140
|
|
|
141
141
|
## 灵感来自
|
|
142
142
|
|
|
143
|
-
Claude Code、Codex、Crush、OpenCode、Pi、Aider、DeepSeek Harness、Qwen Code、Kimi Code CLI、Gemini CLI、Junie 和
|
|
143
|
+
Claude Code、Codex、Crush、OpenCode、Pi、Aider、DeepSeek Harness、Qwen Code、Kimi Code CLI、Gemini CLI、Junie、DS4 和 Ante。
|
|
144
144
|
|
|
145
145
|
## 许可
|
|
146
146
|
|
package/dist/agent/loop.js
CHANGED
|
@@ -15,6 +15,7 @@ import { ContinuationGate, continuationGate, continuationTail } from './continua
|
|
|
15
15
|
import { biasableShingles, buildRuminationLogitBias } from './logitrecovery.js';
|
|
16
16
|
import { EntropyTrace, formatEntropyReading } from './entropytrace.js';
|
|
17
17
|
import { extractPlanReferences, verifyPlanReferences, buildGroundingNote, shouldSuppressGrounding, } from './groundcheck.js';
|
|
18
|
+
import { withDeclineFeedback } from '../approval.js';
|
|
18
19
|
import { collectSourcedUrls } from '../tools/_exfil.js';
|
|
19
20
|
import { groundUrlsForPlan } from '../tools/_urls.js';
|
|
20
21
|
import { referencesSpill } from '../tools/_spill.js';
|
|
@@ -2856,6 +2857,8 @@ export async function runTurn(opts) {
|
|
|
2856
2857
|
subagentCalls.inRound = 0;
|
|
2857
2858
|
}
|
|
2858
2859
|
const subagentInRound = roundHasSubagent && subagentCalls.rounds <= MAX_SUBAGENTS_PER_TURN;
|
|
2860
|
+
// Reasons the user typed while declining this round's calls, sent after its results (below).
|
|
2861
|
+
const roundDeclineFeedback = [];
|
|
2859
2862
|
for (const call of toolCalls) {
|
|
2860
2863
|
if (opts.signal?.aborted)
|
|
2861
2864
|
return;
|
|
@@ -2908,6 +2911,8 @@ export async function runTurn(opts) {
|
|
|
2908
2911
|
let contentHash;
|
|
2909
2912
|
let toolNotice;
|
|
2910
2913
|
let editFailure;
|
|
2914
|
+
// The reason a user typed when declining this call, appended to its summary after the run.
|
|
2915
|
+
let declineFeedback;
|
|
2911
2916
|
// Read-first (#72): path this call put file bytes in front of the model for, and whether the
|
|
2912
2917
|
// model authored them (`write`) rather than being handed them. Applied once the tool message
|
|
2913
2918
|
// exists, since handed-back grounding keys on its history index. See readfirst.ts.
|
|
@@ -2995,7 +3000,14 @@ export async function runTurn(opts) {
|
|
|
2995
3000
|
groundedUrls,
|
|
2996
3001
|
sourcedUrls: () => collectSourcedUrls(opts.history),
|
|
2997
3002
|
askedQuestions,
|
|
2998
|
-
requestApproval: opts.requestApproval
|
|
3003
|
+
requestApproval: opts.requestApproval &&
|
|
3004
|
+
(async (req) => {
|
|
3005
|
+
const answer = await opts.requestApproval(req);
|
|
3006
|
+
if (typeof answer === 'boolean')
|
|
3007
|
+
return answer;
|
|
3008
|
+
declineFeedback = answer.feedback;
|
|
3009
|
+
return false;
|
|
3010
|
+
}),
|
|
2999
3011
|
requestQuestion,
|
|
3000
3012
|
onProgress: opts.onToolProgress && (chunk => opts.onToolProgress(chunk, tool.name)),
|
|
3001
3013
|
spawnSubagent: makeSpawnSubagent(opts, subagentCalls, decodeThroughput, genReserve),
|
|
@@ -3005,8 +3017,12 @@ export async function runTurn(opts) {
|
|
|
3005
3017
|
unattended: opts.isUnattended?.() ?? opts.config.unattended,
|
|
3006
3018
|
signal: opts.signal,
|
|
3007
3019
|
});
|
|
3008
|
-
summary =
|
|
3020
|
+
summary = declineFeedback
|
|
3021
|
+
? withDeclineFeedback(result.summary, declineFeedback)
|
|
3022
|
+
: result.summary;
|
|
3009
3023
|
payload = result.payload;
|
|
3024
|
+
if (declineFeedback)
|
|
3025
|
+
roundDeclineFeedback.push(declineFeedback);
|
|
3010
3026
|
diff = result.diff;
|
|
3011
3027
|
command = result.command;
|
|
3012
3028
|
changes = result.changes;
|
|
@@ -3239,6 +3255,19 @@ export async function runTurn(opts) {
|
|
|
3239
3255
|
opts.onMessage({ role: 'system', tone: 'info', content: planCheckoff });
|
|
3240
3256
|
}
|
|
3241
3257
|
}
|
|
3258
|
+
// The user's own words, as a user message rather than inside the declined call's result: in a
|
|
3259
|
+
// tool result even a framed quote read to lfm2.5-24b as the environment refusing ("maybe the
|
|
3260
|
+
// environment doesn't support it"), 0/3 on a reason asking for an answer instead of a command.
|
|
3261
|
+
// `harness`: not a turn boundary, so the task-spec pin stays put (#287). History only — the
|
|
3262
|
+
// declined call's row already shows the quote. The words go verbatim: opening with "I declined
|
|
3263
|
+
// `<command>`." gained nothing on a terse reason and buried an explicit one behind a long `cd`.
|
|
3264
|
+
if (roundDeclineFeedback.length > 0) {
|
|
3265
|
+
opts.history.push({
|
|
3266
|
+
role: 'user',
|
|
3267
|
+
content: roundDeclineFeedback.join('\n\n'),
|
|
3268
|
+
harness: true,
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3242
3271
|
// A round that added no new keys (all re-reads of already-seen sections / repeat searches) is a
|
|
3243
3272
|
// stall; enough consecutive stalls trip the adaptive force-write on the next iteration.
|
|
3244
3273
|
const roundLearned = seenReadOnly.size > seenBeforeRound || seenWebLookups.size > seenWebBeforeRound;
|
package/dist/approval.js
CHANGED
|
@@ -35,6 +35,12 @@ export function declineSummary(action, target, ctx) {
|
|
|
35
35
|
return `${action} declined by user${target}`;
|
|
36
36
|
return `${action} not run${target} — unattended session, nobody to approve it. Carry on without it, or leave it for the user in your final reply.`;
|
|
37
37
|
}
|
|
38
|
+
// A decline the user explained. A bare "declined by user" leaves a small model guessing what to do
|
|
39
|
+
// next, and the guess is often the same call again; the reason turns the dead end into the next
|
|
40
|
+
// instruction. The quote rides the summary, the part that survives aging and the user sees on the row.
|
|
41
|
+
export function withDeclineFeedback(summary, feedback) {
|
|
42
|
+
return `${summary}\nThe user wrote: "${feedback}"`;
|
|
43
|
+
}
|
|
38
44
|
// The end-of-turn roll-up of what an unattended turn declined (#526). Built from the approval
|
|
39
45
|
// requests themselves, so it is complete by construction — a model asked to recall its declines
|
|
40
46
|
// could drop one or invent one. Null when nothing was declined.
|
package/dist/search/_chrome.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
1
|
+
import { execFile, spawn } from 'node:child_process';
|
|
2
2
|
import { accessSync, constants, mkdirSync } from 'node:fs';
|
|
3
3
|
import { homedir, platform } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
@@ -28,19 +28,38 @@ export class ChromeHost {
|
|
|
28
28
|
async newTab() {
|
|
29
29
|
await this.ensure();
|
|
30
30
|
this.touch();
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
31
|
+
// Not `PUT /json/new`: that opens a foreground tab, which activates Chrome and takes focus on
|
|
32
|
+
// every search. A background target in a minimized window of its own never shows, and
|
|
33
|
+
// minimizing or showing one tab's window never moves another search's tab.
|
|
34
|
+
const browser = await openSession(await this.browserWsUrl());
|
|
35
|
+
let targetId;
|
|
36
|
+
try {
|
|
37
|
+
const res = (await browser.call('Target.createTarget', {
|
|
38
|
+
url: 'about:blank',
|
|
39
|
+
newWindow: true,
|
|
40
|
+
background: true,
|
|
41
|
+
windowState: 'minimized',
|
|
42
|
+
}));
|
|
43
|
+
if (res.error)
|
|
44
|
+
throw new Error(`could not open a tab (CDP ${res.error.message ?? 'error'})`);
|
|
45
|
+
targetId = res.result?.targetId;
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
browser.close();
|
|
49
|
+
}
|
|
50
|
+
if (!targetId)
|
|
51
|
+
throw new Error('CDP returned a tab with no target id');
|
|
52
|
+
const list = (await (await fetch(`http://127.0.0.1:${this.port}/json/list`)).json());
|
|
53
|
+
const tab = list.find(t => t.id === targetId);
|
|
54
|
+
if (!tab?.webSocketDebuggerUrl || !tab.id)
|
|
36
55
|
throw new Error('CDP returned a tab with no debugger URL');
|
|
37
56
|
const session = await openSession(tab.webSocketDebuggerUrl);
|
|
38
57
|
const port = this.port;
|
|
39
58
|
const touch = () => this.touch();
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
59
|
+
const activate = () => this.activate();
|
|
60
|
+
// The window should already be minimized from creation; this covers a Chrome that predates
|
|
61
|
+
// `windowState` on `Target.createTarget`. Only a bot check (`show`) is allowed to surface it;
|
|
62
|
+
// see CdpSearchProvider.
|
|
44
63
|
await setWindowState(session, 'minimized');
|
|
45
64
|
return {
|
|
46
65
|
async navigate(url) {
|
|
@@ -61,9 +80,11 @@ export class ChromeHost {
|
|
|
61
80
|
async show() {
|
|
62
81
|
touch();
|
|
63
82
|
await setWindowState(session, 'normal');
|
|
64
|
-
// Page.bringToFront
|
|
65
|
-
//
|
|
83
|
+
// Page.bringToFront raises the tab within its own browser, but a browser that never took
|
|
84
|
+
// focus stays behind the active app, so the instance is activated too — by pid, since
|
|
85
|
+
// activating by name would raise the user's own Chrome instead (#238).
|
|
66
86
|
await session.call('Page.bringToFront').catch(() => undefined);
|
|
87
|
+
await activate();
|
|
67
88
|
},
|
|
68
89
|
async hide() {
|
|
69
90
|
await setWindowState(session, 'minimized');
|
|
@@ -119,17 +140,17 @@ export class ChromeHost {
|
|
|
119
140
|
'--disable-sync',
|
|
120
141
|
'--password-store=basic',
|
|
121
142
|
'--mute-audio',
|
|
143
|
+
// Not `--no-startup-window`: Chrome then ignores Quit from the Dock, and it kept focus no
|
|
144
|
+
// better than a hidden launch does (measured on macOS 26, Chrome 155).
|
|
122
145
|
'about:blank',
|
|
123
146
|
];
|
|
124
147
|
debugLog(`[cdp] launching ${exe} on port ${this.port}`);
|
|
125
148
|
// Not headless, deliberately: a fresh headless profile is the shape search engines CAPTCHA.
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
stdio: 'ignore',
|
|
132
|
-
}).unref();
|
|
149
|
+
// `open -g` alone still let Chrome activate itself when its first window opened, so macOS
|
|
150
|
+
// also launches it hidden (`-j`): a real browser that never takes focus.
|
|
151
|
+
const hidden = platform() === 'darwin' && !this.binary;
|
|
152
|
+
if (hidden) {
|
|
153
|
+
spawn('/usr/bin/open', ['-g', '-j', '-na', macAppName() ?? 'Google Chrome', '--args', ...flags], { detached: true, stdio: 'ignore' }).unref();
|
|
133
154
|
}
|
|
134
155
|
else {
|
|
135
156
|
spawn(exe, flags, { detached: true, stdio: 'ignore' }).unref();
|
|
@@ -138,6 +159,10 @@ export class ChromeHost {
|
|
|
138
159
|
while (Date.now() < deadline) {
|
|
139
160
|
if (await this.alive()) {
|
|
140
161
|
debugLog(`[cdp] browser ready on port ${this.port}`);
|
|
162
|
+
// Searches open their own windows, and the startup one would surface beside the first bot
|
|
163
|
+
// check's tab. macOS only: elsewhere closing the last window quits Chrome.
|
|
164
|
+
if (hidden)
|
|
165
|
+
await this.closeStartupWindow();
|
|
141
166
|
return;
|
|
142
167
|
}
|
|
143
168
|
await sleep(LAUNCH_POLL_MS);
|
|
@@ -153,6 +178,54 @@ export class ChromeHost {
|
|
|
153
178
|
this.idleTimer = setTimeout(() => void this.shutdown(), IDLE_SHUTDOWN_MS);
|
|
154
179
|
this.idleTimer.unref?.();
|
|
155
180
|
}
|
|
181
|
+
async closeStartupWindow() {
|
|
182
|
+
try {
|
|
183
|
+
const res = await fetch(`http://127.0.0.1:${this.port}/json/list`);
|
|
184
|
+
const targets = (await res.json());
|
|
185
|
+
for (const t of targets) {
|
|
186
|
+
if (t.type === 'page' && t.url === 'about:blank' && t.id)
|
|
187
|
+
await fetch(`http://127.0.0.1:${this.port}/json/close/${t.id}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
/* cosmetic: a leftover blank window never fails a search */
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async browserWsUrl() {
|
|
195
|
+
const res = await fetch(`http://127.0.0.1:${this.port}/json/version`, {
|
|
196
|
+
signal: AbortSignal.timeout(1500),
|
|
197
|
+
});
|
|
198
|
+
const { webSocketDebuggerUrl } = (await res.json());
|
|
199
|
+
if (!webSocketDebuggerUrl)
|
|
200
|
+
throw new Error('CDP reported no browser debugger URL');
|
|
201
|
+
return webSocketDebuggerUrl;
|
|
202
|
+
}
|
|
203
|
+
// The pid comes from CDP because `open` doesn't report the one it launched. Best-effort, and a
|
|
204
|
+
// no-op off macOS: the window is restored either way, activation only saves the user a click.
|
|
205
|
+
async activate() {
|
|
206
|
+
if (platform() !== 'darwin')
|
|
207
|
+
return;
|
|
208
|
+
try {
|
|
209
|
+
const browser = await openSession(await this.browserWsUrl());
|
|
210
|
+
let pid;
|
|
211
|
+
try {
|
|
212
|
+
const res = (await browser.call('SystemInfo.getProcessInfo'));
|
|
213
|
+
pid = res.result?.processInfo?.find(p => p.type === 'browser')?.id;
|
|
214
|
+
}
|
|
215
|
+
finally {
|
|
216
|
+
browser.close();
|
|
217
|
+
}
|
|
218
|
+
if (!Number.isInteger(pid))
|
|
219
|
+
return;
|
|
220
|
+
const script = `ObjC.import('AppKit'); $.NSRunningApplication.runningApplicationWithProcessIdentifier(${pid}).activateWithOptions($.NSApplicationActivateAllWindows)`;
|
|
221
|
+
await new Promise(resolve => {
|
|
222
|
+
execFile('/usr/bin/osascript', ['-l', 'JavaScript', '-e', script], () => resolve());
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
/* best-effort */
|
|
227
|
+
}
|
|
228
|
+
}
|
|
156
229
|
async shutdown() {
|
|
157
230
|
if (this.idleTimer)
|
|
158
231
|
clearTimeout(this.idleTimer);
|
package/dist/search/cdp.js
CHANGED
|
@@ -8,6 +8,9 @@ import { SearchUnavailableError } from './types.js';
|
|
|
8
8
|
// Bing, so it isn't correlated with the engine most likely to block us next. See #235.
|
|
9
9
|
const SEARCH_URL = 'https://search.brave.com/search?q=';
|
|
10
10
|
const OWN_HOSTS = /(^|\.)(brave\.com|search\.brave\.com)$/;
|
|
11
|
+
// Brave ends some result anchors with a date line ("May 8, 2026", "3 days ago"), which the
|
|
12
|
+
// last-line rule below then reported as the result's title.
|
|
13
|
+
export const DATE_LINE = /^(?:(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\.? \d{1,2},? \d{4}|\d+ (?:second|minute|hour|day|week|month|year)s? ago)$/i;
|
|
11
14
|
// Deliberately structure-agnostic: every visible link, filtered and deduped. No result-card
|
|
12
15
|
// selectors, so a SERP redesign can't silently empty the results the way class-name scraping does.
|
|
13
16
|
// The snippet walks up from the anchor until a container holds meaningfully more text than the
|
|
@@ -24,9 +27,11 @@ function extractionScript(maxResults) {
|
|
|
24
27
|
// A result anchor's innerText is "SiteName / breadcrumb › path / actual title" on separate lines.
|
|
25
28
|
// The last line is the title; the earlier ones are chrome that would otherwise be fed to the model
|
|
26
29
|
// as part of it. No class names involved, so a redesign degrades this to "whole text", not to junk.
|
|
30
|
+
const dateLine = ${DATE_LINE.toString()};
|
|
27
31
|
const titleOf = a => {
|
|
28
32
|
const lines = (a.innerText || '').split('\\n').map(clean).filter(Boolean);
|
|
29
|
-
|
|
33
|
+
const named = lines.filter(l => !dateLine.test(l));
|
|
34
|
+
return named.length ? named[named.length - 1] : '';
|
|
30
35
|
};
|
|
31
36
|
// The container repeats the anchor's own text before the description; removing it stops every
|
|
32
37
|
// snippet from opening with a copy of the title it sits under.
|
package/dist/tools/_danger.js
CHANGED
|
@@ -9,7 +9,7 @@ import { execFileSync } from 'node:child_process';
|
|
|
9
9
|
import { existsSync } from 'node:fs';
|
|
10
10
|
import { homedir } from 'node:os';
|
|
11
11
|
import { dirname, join, resolve } from 'node:path';
|
|
12
|
-
import { maskQuoted, maskShellData, splitSegments, words } from './_readonly.js';
|
|
12
|
+
import { WORD_RE, maskQuoted, maskShellData, splitSegments, words } from './_readonly.js';
|
|
13
13
|
import { scanHeredocs, stripHeredocs } from './_heredoc.js';
|
|
14
14
|
import { maskMarkdownData } from './_markdown.js';
|
|
15
15
|
// Workflow-policy commands: not destructive (a commit is local and reversible, a push is
|
|
@@ -142,18 +142,41 @@ const PACKAGE_PATTERNS = [
|
|
|
142
142
|
// makes this precise: `grep -rn install src/` passes `install` as an *argument*, and the
|
|
143
143
|
// read-only leads below never install anything, so they are skipped outright.
|
|
144
144
|
//
|
|
145
|
-
// Position is read TWO ways
|
|
146
|
-
// `GENERIC_PACKAGE_RE` counted `CFLAGS="-O2`, `-g` and `-Wall"` in `make CFLAGS="-O2 -g
|
|
147
|
-
// install` as three leading tokens, so the verb landed past the budget and the install ran
|
|
145
|
+
// Position is read TWO ways, but only one of them reads every segment (#752, narrowed by #757). On
|
|
146
|
+
// whitespace, `GENERIC_PACKAGE_RE` counted `CFLAGS="-O2`, `-g` and `-Wall"` in `make CFLAGS="-O2 -g
|
|
147
|
+
// -Wall" install` as three leading tokens, so the verb landed past the budget and the install ran
|
|
148
148
|
// unprompted; `genericVerbWord` reads the same shape off the shell's own words, where that value is
|
|
149
|
-
// ONE token. The whitespace reading
|
|
150
|
-
// SPLITS an unterminated run (`FOO="a b` reads as `FOO=`, `a`, `b`), and the extra words
|
|
151
|
-
// the verb past the budget — an under-report.
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
// (`
|
|
155
|
-
// a
|
|
149
|
+
// ONE token. The whitespace reading exists for exactly one case: `words()` DROPS a quote it cannot
|
|
150
|
+
// close and so SPLITS an unterminated run (`FOO="a b` reads as `FOO=`, `a`, `b`), and the extra words
|
|
151
|
+
// can push the verb past the budget — an under-report. Unioned with the word reading on every segment
|
|
152
|
+
// it was also a false-positive machine, because the other half of the same weakness is that it cuts a
|
|
153
|
+
// CLOSED quoted argument at the spaces inside it: `cp -r "build install" dist` is one quoted argument
|
|
154
|
+
// to `cp`, which `words()` reads correctly and this reading re-accepted as a verb (#757). So it is
|
|
155
|
+
// consulted only where `words()` actually dropped a quote — the whole difference it was paying for —
|
|
156
|
+
// and nowhere else. The trade: an install carried in a CLOSED quoted value, `A="make install" bash -c
|
|
157
|
+
// "$A"`, is now read only off words, which sees one assignment word and reports nothing. That shape
|
|
158
|
+
// is indistinguishable from the false positive by any test cheaper than expanding the value, which is
|
|
159
|
+
// `bash`'s job and not this file's. A quote-aware token PATTERN stays the rejected option: an anchored
|
|
160
|
+
// reader that also tolerates an unterminated quote has two viable ends per token and re-explores every
|
|
161
|
+
// earlier one (`GENERIC_PACKAGE_RE` ends in `install`, so a `""` run backtracks catastrophically).
|
|
162
|
+
// `words()` is a lexer, so it costs one linear scan.
|
|
156
163
|
const GENERIC_PACKAGE_RE = /^(?:\S+\s+){1,3}?(?:-{1,2}[\w-]+\s+)*(un)?install(?![\w./-])/;
|
|
164
|
+
// Where `words()` first read this segment differently from the shell, or -1. A quote it cannot close
|
|
165
|
+
// is dropped, not failed, so the only characters a word list cannot consume are the quotes
|
|
166
|
+
// themselves. The position matters, not just the fact: a dropped quote only explains a verb the
|
|
167
|
+
// whitespace reading finds AFTER it, and an apostrophe in a trailing comment (`mv "old install" new
|
|
168
|
+
// # it's fine`) must not license a verb read out of the closed quote before it.
|
|
169
|
+
function firstDroppedQuote(segment) {
|
|
170
|
+
let at = 0;
|
|
171
|
+
for (const m of segment.matchAll(WORD_RE)) {
|
|
172
|
+
const gap = segment.slice(at, m.index).search(/["']/);
|
|
173
|
+
if (gap >= 0)
|
|
174
|
+
return at + gap;
|
|
175
|
+
at = m.index + m[0].length;
|
|
176
|
+
}
|
|
177
|
+
const gap = segment.slice(at).search(/["']/);
|
|
178
|
+
return gap >= 0 ? at + gap : -1;
|
|
179
|
+
}
|
|
157
180
|
// A flag token: the gap between the leading words and the verb.
|
|
158
181
|
const GENERIC_FLAG_RE = /^-{1,2}[\w-]+$/;
|
|
159
182
|
// A `VAR=value` operand (`make DESTDIR=/x install`) sits in the same gap: a make line carries
|
|
@@ -182,16 +205,38 @@ const READ_ONLY_LEAD_RE = /^(?:e?grep|fgrep|rg|ag|ack|find|man|which|type|wherei
|
|
|
182
205
|
// user reads to decide.
|
|
183
206
|
const SELF_COVERED_LEAD_RE = /^(?:helm|kubectl|oc|docker|podman|terraform|tofu|pulumi)\b/;
|
|
184
207
|
// Reads `verbSegments`' segments, so the two per-segment readers agree on what a segment is (#749).
|
|
208
|
+
//
|
|
209
|
+
// The lead is tested after the verb prefix is stripped, not on the raw segment (#757): what a
|
|
210
|
+
// segment runs is the command behind its assignments and wrappers, and `LANG=C grep -rn install src`
|
|
211
|
+
// runs `grep` — an argument, not a verb — while the raw test saw `LANG=C`, missed the read-only lead,
|
|
212
|
+
// and asked `grep`'s own word list for an install it never had. `stripVerbPrefix` is `verbLabels`'
|
|
213
|
+
// strip, so both per-segment readers agree on which command a segment runs. It skips a wrapper's
|
|
214
|
+
// options too (`sudo -u me grep …`), and strips `command -v x` to nothing, since that runs nothing.
|
|
215
|
+
//
|
|
216
|
+
// The VERB is still read off the raw segment as well as the stripped one: the strip brings a deep
|
|
217
|
+
// verb inside the budget (`env A=1 sudo time conda install numpy`) and can also move one out of it
|
|
218
|
+
// (`sudo install -m 644 x /etc/x` has its verb at word 1, and word 0 is past this reader by design).
|
|
219
|
+
// Both readings, unioned — the same rule that keeps a label at least as wide as it was.
|
|
185
220
|
function genericPackageLabel(segments) {
|
|
186
|
-
for (const
|
|
187
|
-
if (!
|
|
221
|
+
for (const segment of segments.map(s => s.trim())) {
|
|
222
|
+
if (!segment)
|
|
223
|
+
continue;
|
|
224
|
+
const stripped = stripVerbPrefix(segment);
|
|
225
|
+
if (!stripped || READ_ONLY_LEAD_RE.test(stripped) || SELF_COVERED_LEAD_RE.test(stripped)) {
|
|
188
226
|
continue;
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
227
|
+
}
|
|
228
|
+
for (const seg of stripped === segment ? [segment] : [segment, stripped]) {
|
|
229
|
+
const word = genericVerbWord(words(seg));
|
|
230
|
+
// The whitespace reading only where `words()` split a quote it could not close, and only for a
|
|
231
|
+
// verb that quote comes before — see above.
|
|
232
|
+
const dropped = firstDroppedQuote(seg);
|
|
233
|
+
const ws = dropped >= 0 ? GENERIC_PACKAGE_RE.exec(seg) : null;
|
|
234
|
+
const m = ws && dropped < ws[0].length ? ws : undefined;
|
|
235
|
+
if (word === 'uninstall' || m?.[1])
|
|
236
|
+
return 'Uninstall command (removes third-party code)';
|
|
237
|
+
if (word === 'install' || m)
|
|
238
|
+
return 'Install command (fetches and runs third-party code)';
|
|
239
|
+
}
|
|
195
240
|
}
|
|
196
241
|
return undefined;
|
|
197
242
|
}
|
|
@@ -650,8 +695,22 @@ const SHELL_WORD_RE = /(?:"(?:[^"\\]|\\[\s\S])*"|\$'(?:[^'\\]|\\[\s\S])*'|'[^']*
|
|
|
650
695
|
const NON_SPACE_RUN_RE = /\S*/y;
|
|
651
696
|
const WORD_GAP_RE = /\s+/y;
|
|
652
697
|
const ENV_ASSIGN_WORD_RE = /^[A-Za-z_]\w*=/;
|
|
698
|
+
// A wrapper's own options sit between it and the command it runs (`sudo -u me grep …`, `env -i …`,
|
|
699
|
+
// `time -p …`); left in place, the option became the lead and the command behind it read as an
|
|
700
|
+
// argument (#757 review). These are the options that consume the next word as their value.
|
|
701
|
+
const WRAPPER_VALUE_OPTIONS = {
|
|
702
|
+
sudo: new Set(['-u', '-g', '-U', '-C', '-D', '-h', '-p', '-r', '-t', '-T', '-R']),
|
|
703
|
+
env: new Set(['-u', '-C']),
|
|
704
|
+
exec: new Set(['-a']),
|
|
705
|
+
time: new Set(['-o', '-f']),
|
|
706
|
+
};
|
|
707
|
+
const WRAPPER_WORDS = new Set(['sudo', 'command', 'nohup', 'exec', 'env', 'time']);
|
|
708
|
+
// `command -v x` looks `x` up and runs nothing, so it has no verb at all.
|
|
709
|
+
const COMMAND_LOOKUP_RE = /^-[a-zA-Z]*[vV]/;
|
|
653
710
|
function stripVerbPrefix(segment) {
|
|
654
711
|
let at = 0;
|
|
712
|
+
let wrapper;
|
|
713
|
+
let takesValue = false;
|
|
655
714
|
for (;;) {
|
|
656
715
|
SHELL_WORD_RE.lastIndex = at;
|
|
657
716
|
let end = SHELL_WORD_RE.exec(segment) ? SHELL_WORD_RE.lastIndex : at;
|
|
@@ -661,11 +720,30 @@ function stripVerbPrefix(segment) {
|
|
|
661
720
|
end = NON_SPACE_RUN_RE.lastIndex;
|
|
662
721
|
}
|
|
663
722
|
const word = segment.slice(at, end);
|
|
723
|
+
if (wrapper === 'command' && COMMAND_LOOKUP_RE.test(word))
|
|
724
|
+
return '';
|
|
725
|
+
const isOption = wrapper !== undefined && (takesValue || word.startsWith('-'));
|
|
664
726
|
WORD_GAP_RE.lastIndex = end;
|
|
665
727
|
const gap = WORD_GAP_RE.exec(segment);
|
|
666
|
-
if (!gap || !(VERB_PREFIX_WORD_SET.has(word) || ENV_ASSIGN_WORD_RE.test(word))) {
|
|
728
|
+
if (!gap || !(isOption || VERB_PREFIX_WORD_SET.has(word) || ENV_ASSIGN_WORD_RE.test(word))) {
|
|
667
729
|
return segment.slice(at);
|
|
668
730
|
}
|
|
731
|
+
if (takesValue) {
|
|
732
|
+
takesValue = false;
|
|
733
|
+
}
|
|
734
|
+
else if (isOption) {
|
|
735
|
+
// `--` ends the wrapper's options: the next word is the command, even one spelled `-x`.
|
|
736
|
+
if (word === '--')
|
|
737
|
+
wrapper = undefined;
|
|
738
|
+
else
|
|
739
|
+
takesValue = WRAPPER_VALUE_OPTIONS[wrapper]?.has(word) ?? false;
|
|
740
|
+
}
|
|
741
|
+
else if (WRAPPER_WORDS.has(word)) {
|
|
742
|
+
wrapper = word;
|
|
743
|
+
}
|
|
744
|
+
else if (!ENV_ASSIGN_WORD_RE.test(word)) {
|
|
745
|
+
wrapper = undefined;
|
|
746
|
+
}
|
|
669
747
|
at = WORD_GAP_RE.lastIndex;
|
|
670
748
|
}
|
|
671
749
|
}
|
package/dist/tools/bash.js
CHANGED
|
@@ -19,7 +19,8 @@ const DEFAULT_IDLE_MS = 5 * 60_000;
|
|
|
19
19
|
const KILL_GRACE_MS = 2_000;
|
|
20
20
|
const MAX_PAYLOAD_BYTES = 64 * 1024;
|
|
21
21
|
const OUTPUT_TAIL_BYTES = 2 * 1024;
|
|
22
|
-
|
|
22
|
+
// Exported for the live tail (ui/Scrollback.tsx), which must never draw more rows than this chip.
|
|
23
|
+
export const OUTPUT_TAIL_LINES = 10;
|
|
23
24
|
// Retained for the UI chip's last-lines view. Larger than OUTPUT_TAIL_BYTES so the slice to 10
|
|
24
25
|
// lines always has enough to work with even when lines are long, and small enough to be free.
|
|
25
26
|
const UI_TAIL_BYTES = 4 * 1024;
|
package/dist/ui/App.js
CHANGED
|
@@ -14,7 +14,7 @@ import { createSession } from '../session.js';
|
|
|
14
14
|
import { resolvePr } from './pr.js';
|
|
15
15
|
import { clearIdentity, enableAnon, isAnon } from './identity.js';
|
|
16
16
|
import { theme } from './theme.js';
|
|
17
|
-
import { Approval } from './Approval.js';
|
|
17
|
+
import { APPROVAL_FEEDBACK_INDEX, APPROVAL_OPTIONS, Approval } from './Approval.js';
|
|
18
18
|
import { CONFIRM_ACCEPT, CONFIRM_DECLINE, Confirm, TOGGLE_CANCEL, TOGGLE_OFF, TOGGLE_ON, implementModeConfirmSpec, pastedUrlConfirmSpec, skillConfirmSpec, toggleConfirmSpec, } from './Confirm.js';
|
|
19
19
|
import { Question, questionDialogHeight } from './Question.js';
|
|
20
20
|
import { inheritProfile, loadConfig, modeSwitchProfile, resolveDefaultMode, resolveProfile, } from '../config.js';
|
|
@@ -22,7 +22,8 @@ import { loadLastState, persistableMode, saveLastState, startMode, startProfiles
|
|
|
22
22
|
import { autoApproveForced, autoApproves, effectiveAutoApprove, formatUnattendedDeclines, } from '../approval.js';
|
|
23
23
|
import { bootstrap } from '../context/bootstrap.js';
|
|
24
24
|
import { budgetWarning, formatBudget } from '../context/bundlesize.js';
|
|
25
|
-
import { debugLog, processSessionStem } from '../debug.js';
|
|
25
|
+
import { debugEnabled, debugLog, processSessionStem } from '../debug.js';
|
|
26
|
+
import { noteFrameState } from './framedrops.js';
|
|
26
27
|
import { addFileToIndex } from '../context/files.js';
|
|
27
28
|
import { saveTranscript, TRANSCRIPT_VERSION, } from '../store/transcript.js';
|
|
28
29
|
import {} from '../agent/loop.js';
|
|
@@ -141,6 +142,8 @@ export function App() {
|
|
|
141
142
|
const [decodeRate, setDecodeRate] = useState(undefined);
|
|
142
143
|
const [pending, setPending] = useState(null);
|
|
143
144
|
const [approvalSelected, setApprovalSelected] = useState(0);
|
|
145
|
+
// Typing the reason for a decline: like `questionTyping`, the input box underneath is the field.
|
|
146
|
+
const [approvalTyping, setApprovalTyping] = useState(false);
|
|
144
147
|
// An `ask_user` question waiting on the user (#198). Modal like Approval, with one difference: the
|
|
145
148
|
// input box stays LIVE underneath once `questionTyping` is set, because the free-text row hands the
|
|
146
149
|
// answer to Input rather than to a field rebuilt in the dialog.
|
|
@@ -271,6 +274,8 @@ export function App() {
|
|
|
271
274
|
questionTypingRef.current = questionTyping;
|
|
272
275
|
const approvalSelectedRef = useRef(0);
|
|
273
276
|
approvalSelectedRef.current = approvalSelected;
|
|
277
|
+
const approvalTypingRef = useRef(false);
|
|
278
|
+
approvalTypingRef.current = approvalTyping;
|
|
274
279
|
const confirmRef = useRef(null);
|
|
275
280
|
confirmRef.current = confirm;
|
|
276
281
|
const confirmSelectedRef = useRef(CONFIRM_DECLINE);
|
|
@@ -649,6 +654,14 @@ export function App() {
|
|
|
649
654
|
useInput((input, key) => {
|
|
650
655
|
if (key.ctrl && input === 'c') {
|
|
651
656
|
const hadPending = pendingRef.current !== null;
|
|
657
|
+
// Typing a decline's reason: back out to the options, as the question's field does (#651).
|
|
658
|
+
// Nothing is decided yet, so neither the approval nor the turn may end here.
|
|
659
|
+
if (hadPending && approvalTypingRef.current) {
|
|
660
|
+
setInputValue(preAnswerDraftRef.current);
|
|
661
|
+
setSuggestionState(null);
|
|
662
|
+
setApprovalTyping(false);
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
652
665
|
// Interrupt anything in flight: decline a pending approval, drop an unanswered question,
|
|
653
666
|
// abort a turn.
|
|
654
667
|
if (hadPending) {
|
|
@@ -719,16 +732,26 @@ export function App() {
|
|
|
719
732
|
return;
|
|
720
733
|
}
|
|
721
734
|
if (pendingRef.current) {
|
|
735
|
+
// Input owns the keyboard while the reason is typed; a key consumed here is a lost character.
|
|
736
|
+
if (approvalTypingRef.current)
|
|
737
|
+
return;
|
|
722
738
|
if (key.upArrow) {
|
|
723
739
|
setApprovalSelected(i => Math.max(0, i - 1));
|
|
724
740
|
return;
|
|
725
741
|
}
|
|
726
742
|
if (key.downArrow) {
|
|
727
|
-
setApprovalSelected(i => Math.min(
|
|
743
|
+
setApprovalSelected(i => Math.min(APPROVAL_OPTIONS.length - 1, i + 1));
|
|
728
744
|
return;
|
|
729
745
|
}
|
|
730
746
|
if (key.return) {
|
|
731
747
|
const sel = approvalSelectedRef.current;
|
|
748
|
+
if (sel === APPROVAL_FEEDBACK_INDEX) {
|
|
749
|
+
// Deferred like the question's field: enabling Input synchronously hands it this Enter.
|
|
750
|
+
preAnswerDraftRef.current = inputValueRef.current;
|
|
751
|
+
setInputValue('');
|
|
752
|
+
queueMicrotask(() => setApprovalTyping(true));
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
732
755
|
const resolve = pendingRef.current.resolve;
|
|
733
756
|
setPending(null);
|
|
734
757
|
if (sel === 0)
|
|
@@ -1174,10 +1197,11 @@ export function App() {
|
|
|
1174
1197
|
return Promise.resolve(false);
|
|
1175
1198
|
}
|
|
1176
1199
|
setApprovalSelected(0);
|
|
1200
|
+
setApprovalTyping(false);
|
|
1177
1201
|
return new Promise(resolve => {
|
|
1178
|
-
const wrappedResolve = (
|
|
1179
|
-
setApprovals(a =>
|
|
1180
|
-
resolve(
|
|
1202
|
+
const wrappedResolve = (answer) => {
|
|
1203
|
+
setApprovals(a => answer === true ? { ...a, approved: a.approved + 1 } : { ...a, declined: a.declined + 1 });
|
|
1204
|
+
resolve(answer);
|
|
1181
1205
|
};
|
|
1182
1206
|
setPending({ request: req, resolve: wrappedResolve });
|
|
1183
1207
|
});
|
|
@@ -2069,6 +2093,20 @@ export function App() {
|
|
|
2069
2093
|
// An answer being typed for `ask_user` — not a message for the model. Intercepted ahead of the
|
|
2070
2094
|
// busy-queue branch below: a question only exists mid-turn, so every such submit would otherwise
|
|
2071
2095
|
// be queued as the user's next prompt.
|
|
2096
|
+
// A decline's reason, likewise not a message for the model's next turn. An empty one is not a
|
|
2097
|
+
// reason; the field stays open, and ctrl-c is the way back to a plain Decline.
|
|
2098
|
+
const ap = pendingRef.current;
|
|
2099
|
+
if (ap && approvalTypingRef.current) {
|
|
2100
|
+
const text = input.trim();
|
|
2101
|
+
if (!text)
|
|
2102
|
+
return;
|
|
2103
|
+
setInputValue(preAnswerDraftRef.current);
|
|
2104
|
+
setSuggestionState(null);
|
|
2105
|
+
setPending(null);
|
|
2106
|
+
setApprovalTyping(false);
|
|
2107
|
+
ap.resolve({ feedback: text });
|
|
2108
|
+
return;
|
|
2109
|
+
}
|
|
2072
2110
|
const q = questionRef.current;
|
|
2073
2111
|
const typing = questionTypingRef.current;
|
|
2074
2112
|
if (q && typing) {
|
|
@@ -2507,6 +2545,28 @@ export function App() {
|
|
|
2507
2545
|
if (status === 'error') {
|
|
2508
2546
|
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "Error" }), _jsx(Text, { children: error })] }));
|
|
2509
2547
|
}
|
|
2548
|
+
if (debugEnabled()) {
|
|
2549
|
+
const live = [
|
|
2550
|
+
streamingReasoning && 'reasoning',
|
|
2551
|
+
streaming && 'content',
|
|
2552
|
+
streamingTool && `tool:${streamingToolName}`,
|
|
2553
|
+
].filter(Boolean);
|
|
2554
|
+
const dialog = pending
|
|
2555
|
+
? 'approval'
|
|
2556
|
+
: question
|
|
2557
|
+
? 'question'
|
|
2558
|
+
: modelSelect
|
|
2559
|
+
? 'model'
|
|
2560
|
+
: resumeSelect
|
|
2561
|
+
? 'resume'
|
|
2562
|
+
: confirm
|
|
2563
|
+
? 'confirm'
|
|
2564
|
+
: '-';
|
|
2565
|
+
noteFrameState(`${status === 'busy' ? phase : status} msgs=${messages.length} live=${live.join(',') || '-'}` +
|
|
2566
|
+
` pending=${pendingTool || '-'} dialog=${dialog} queue=${queue.length}` +
|
|
2567
|
+
` plan=${planSteps ? planSteps.length : 0} suggest=${suggestionState ? 1 : 0}` +
|
|
2568
|
+
`${subagentLive ? ' subagent' : ''}`);
|
|
2569
|
+
}
|
|
2510
2570
|
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [_jsx(Static, { items: headerItems, children: (h, i) => (_jsx(Splash, { model: h.model, cwd: h.cwd, version: h.version, subagent: h.subagent }, i)) }), status === 'loading' && loadingNote ? _jsx(Text, { color: theme.muted, children: loadingNote }) : null, status === 'loading' ? null : (_jsxs(_Fragment, { children: [_jsx(Scrollback, { messages: messages, streaming: status === 'busy' ? streaming : '', streamingReasoning: status === 'busy' ? streamingReasoning : '', streamingTool: status === 'busy' ? streamingTool : '', streamingNested: subagentLive, streamingCommand: streamingToolName === 'bash',
|
|
2511
2571
|
// Hidden while a dialog is up: the approval a tool asks for happens *inside* the call
|
|
2512
2572
|
// (after the loop announced it), so an "Editing…" row behind the prompt would name work
|
|
@@ -2541,7 +2601,7 @@ export function App() {
|
|
|
2541
2601
|
? theme.warning
|
|
2542
2602
|
: subagentLive
|
|
2543
2603
|
? theme.subagent
|
|
2544
|
-
: undefined })) : (pasting ?? expanding ?? resuming) ? (_jsx(Working, { label: pasting ?? expanding ?? resuming ?? undefined, accent: theme.info })) : null, _jsx(QueuedList, { queue: queue }), pending ? (_jsx(Approval, { request: pending.request, selectedIndex: approvalSelected, reservedRows: dialogReservedRows })) : question ? (_jsx(Question, { request: question.request, selectedIndex: questionSelected, typing: questionTyping, reservedRows: dialogReservedRows })) : modelSelect ? (_jsx(ModelSelect, { targets: modelSelect, selectedIndex: modelSelected, currentModel: config?.profiles[activeProfile]?.model ?? config?.model ?? '', baseURL: config?.baseURL ?? '', subagent: config?.subagentModel &&
|
|
2604
|
+
: undefined })) : (pasting ?? expanding ?? resuming) ? (_jsx(Working, { label: pasting ?? expanding ?? resuming ?? undefined, accent: theme.info })) : null, _jsx(QueuedList, { queue: queue }), pending ? (_jsx(Approval, { request: pending.request, selectedIndex: approvalSelected, typing: approvalTyping, reservedRows: dialogReservedRows })) : question ? (_jsx(Question, { request: question.request, selectedIndex: questionSelected, typing: questionTyping, reservedRows: dialogReservedRows })) : modelSelect ? (_jsx(ModelSelect, { targets: modelSelect, selectedIndex: modelSelected, currentModel: config?.profiles[activeProfile]?.model ?? config?.model ?? '', baseURL: config?.baseURL ?? '', subagent: config?.subagentModel &&
|
|
2545
2605
|
config.subagentModel !== (config.profiles[activeProfile]?.model ?? config.model)
|
|
2546
2606
|
? config.subagentModel
|
|
2547
2607
|
: undefined })) : resumeSelect ? (_jsx(ResumeSelect, { entries: resumeSelect.entries, selectedIndex: resumeSelected, heading: resumeSelect.heading })) : confirm ? (_jsx(Confirm, { spec: confirm.spec, selectedIndex: confirmSelected })) : null, _jsx(Input
|
|
@@ -2550,7 +2610,7 @@ export function App() {
|
|
|
2550
2610
|
, {
|
|
2551
2611
|
// The question dialog is modal only while its list is up; once the user is typing an
|
|
2552
2612
|
// answer the input has to be live, since it IS the answer field.
|
|
2553
|
-
disabled: pending !== null ||
|
|
2613
|
+
disabled: (pending !== null && !approvalTyping) ||
|
|
2554
2614
|
modelSelect !== null ||
|
|
2555
2615
|
resumeSelect !== null ||
|
|
2556
2616
|
confirm !== null ||
|
|
@@ -2560,11 +2620,16 @@ export function App() {
|
|
|
2560
2620
|
resumeSelect !== null ||
|
|
2561
2621
|
confirm !== null, attachedBelow: suggestionState !== null, reservedRows: question
|
|
2562
2622
|
? questionDialogHeight(question.request, questionTyping, dialogReservedRows)
|
|
2563
|
-
: 0, suggesting: !!suggestionState && suggestionState.items.length > 0, history: inputHistory, mode: mode, value: inputValue, onChange: onInputChange, onSubmit: onSubmit, onPasteImage: onPasteImageSafely, onPasteText: onPasteText, placeholder:
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2623
|
+
: 0, suggesting: !!suggestionState && suggestionState.items.length > 0, history: inputHistory, mode: mode, value: inputValue, onChange: onInputChange, onSubmit: onSubmit, onPasteImage: onPasteImageSafely, onPasteText: onPasteText, placeholder:
|
|
2624
|
+
// A reason that should stop the model has to say so: "tell me the script" read as
|
|
2625
|
+
// run-then-tell and drew retries, "don't run anything" did not (decline-terse/-ask).
|
|
2626
|
+
approvalTyping
|
|
2627
|
+
? 'e.g. "use pnpm instead", or "don\'t run anything, just tell me …"'
|
|
2628
|
+
: mode === 'shell'
|
|
2629
|
+
? 'Run a shell command'
|
|
2630
|
+
: mode === 'vibe'
|
|
2631
|
+
? 'Describe a change — it plans first, then implements'
|
|
2632
|
+
: promptPlaceholder() }), suggestionState ? (_jsx(Suggestions, { state: suggestionState, selectedIndex: suggestionSelected })) : null, _jsx(Status, { model: config?.profiles[activeProfile]?.model ?? config?.model ?? '', turns: messages.filter(m => m.role === 'assistant').length, status: status === 'busy' ? phase : status, elapsed: status === 'busy' ? elapsed : null, usage: totalUsage, contextTokens: lastUsage?.promptTokens ?? estimatedContext, contextWindow: statusWindow, contextUsable: statusUsable, sheds: shrink.sheds, folds: shrink.folds, cachedTokens: lastUsage?.cachedTokens, decodeRate: decodeRate, pr: pr, autoApprove: config?.autoApprove === 'bypass'
|
|
2568
2633
|
? 'bypass'
|
|
2569
2634
|
: effectiveAutoApprove(config, sessionAutoApprove) === 'safe'
|
|
2570
2635
|
? 'safe'
|
package/dist/ui/Approval.js
CHANGED
|
@@ -22,28 +22,38 @@ export const DIALOG_MARKER = glyphs.dialogCall;
|
|
|
22
22
|
// preview gets whatever the viewport has left. Fixed rows: marginTop, top border, both paddingY
|
|
23
23
|
// rows, the subject line, and the options and hint with their margins — then the input and status
|
|
24
24
|
// bar underneath, plus slack.
|
|
25
|
-
const DIALOG_FIXED_ROWS =
|
|
25
|
+
const DIALOG_FIXED_ROWS = 13;
|
|
26
26
|
const BELOW_DIALOG_ROWS = 6;
|
|
27
27
|
const MIN_PREVIEW_ROWS = 3;
|
|
28
28
|
export function approvalPreviewRows(warnings, reservedRows = 0, rows = process.stdout.rows || 24) {
|
|
29
29
|
const warningRows = warnings > 0 ? warnings + 1 : 0;
|
|
30
30
|
return Math.max(MIN_PREVIEW_ROWS, rows - DIALOG_FIXED_ROWS - BELOW_DIALOG_ROWS - warningRows - reservedRows);
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
// The last row declines with a reason the user types into the input box below. Last, not beside
|
|
33
|
+
// Decline, so the rows Approval-trained fingers already know keep their places.
|
|
34
|
+
export const APPROVAL_OPTIONS = [
|
|
35
|
+
'Approve',
|
|
36
|
+
'Decline',
|
|
37
|
+
'Always (this session)',
|
|
38
|
+
'Decline, and say what to do instead',
|
|
39
|
+
];
|
|
40
|
+
export const APPROVAL_FEEDBACK_INDEX = 3;
|
|
33
41
|
// The popup renders as the top half of one continuous frame whose bottom half is
|
|
34
42
|
// the input box (see Input's `attachedAbove`): `borderBottom={false}` + the input
|
|
35
43
|
// dropping its top border merges them into a single outline, so the prompt reads
|
|
36
44
|
// as part of the input region rather than a card floating above it. The frame
|
|
37
45
|
// stays neutral (no borderColor) to match the input; caution is signalled inside
|
|
38
46
|
// via themed `▲` warning lines, not a colored border.
|
|
39
|
-
export function Approval({ request, selectedIndex, reservedRows = 0, }) {
|
|
47
|
+
export function Approval({ request, selectedIndex, typing = false, reservedRows = 0, }) {
|
|
40
48
|
const isCommand = request.tool === 'bash';
|
|
41
49
|
const warnings = request.warnings ?? [];
|
|
42
50
|
const maxRows = approvalPreviewRows(warnings.length, reservedRows);
|
|
43
|
-
return (_jsxs(Box, { borderStyle: glyphs.border, borderBottom: false, flexDirection: "column", paddingX: 1, paddingY: 1, marginX: -1, marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: theme.tool, children: `${DIALOG_MARKER} ${toolLabel(request.tool)}` }), _jsx(Text, { color: theme.secondary, children: ` ${request.subject}` })] }), _jsx(Box, { flexDirection: "column", marginTop: 1, children: isCommand ? (_jsx(CommandPreview, { command: request.preview, maxRows: maxRows })) : request.tool === 'fetch_url' ? (_jsx(Text, { children: request.preview })) : (_jsx(DiffView, { diff: request.preview, path: request.subject, maxWidth: contentWidth(DIALOG_CHROME), startLine: request.startLine, maxRows: maxRows, hiddenNote: n => `… ${n} more lines — the full diff prints once approved` })) }), warnings.length > 0 ? (_jsx(Box, { flexDirection: "column", marginTop: 1, children: warnings.map((w, i) => (_jsx(Text, { color: theme.warning, children: `▲ ${w}` }, i))) })) : null, _jsx(Box, { flexDirection: "column", marginTop: 1, children: APPROVAL_OPTIONS.map((label, i) => {
|
|
51
|
+
return (_jsxs(Box, { borderStyle: glyphs.border, borderBottom: false, flexDirection: "column", paddingX: 1, paddingY: 1, marginX: -1, marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: theme.tool, children: `${DIALOG_MARKER} ${toolLabel(request.tool)}` }), _jsx(Text, { color: theme.secondary, children: ` ${request.subject}` })] }), _jsx(Box, { flexDirection: "column", marginTop: 1, children: isCommand ? (_jsx(CommandPreview, { command: request.preview, maxRows: maxRows })) : request.tool === 'fetch_url' ? (_jsx(Text, { children: request.preview })) : (_jsx(DiffView, { diff: request.preview, path: request.subject, maxWidth: contentWidth(DIALOG_CHROME), startLine: request.startLine, maxRows: maxRows, hiddenNote: n => `… ${n} more lines — the full diff prints once approved` })) }), warnings.length > 0 ? (_jsx(Box, { flexDirection: "column", marginTop: 1, children: warnings.map((w, i) => (_jsx(Text, { color: theme.warning, children: `▲ ${w}` }, i))) })) : null, _jsx(Box, { flexDirection: "column", marginTop: 1, children: typing ? (_jsx(Text, { color: theme.secondary, children: "Declining \u2014 type what to do instead below" })) : (APPROVAL_OPTIONS.map((label, i) => {
|
|
44
52
|
const selected = i === selectedIndex;
|
|
45
53
|
return (_jsxs(Text, { children: [_jsx(Text, { color: selected ? theme.accent : undefined, children: selected ? '› ' : ' ' }), _jsx(Text, { color: selected ? theme.accent : undefined, children: label })] }, i));
|
|
46
|
-
}) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { color: theme.muted, children:
|
|
54
|
+
})) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { color: theme.muted, children: typing
|
|
55
|
+
? 'enter send · ctrl-c back to the options'
|
|
56
|
+
: '↑↓ navigate · enter select · y/n shortcuts · ctrl-c abort' }) })] }));
|
|
47
57
|
}
|
|
48
58
|
// The marker on a command's first row; every wrapped/extra line hangs under it by this width.
|
|
49
59
|
const MARKER = '$ ';
|
package/dist/ui/Scrollback.js
CHANGED
|
@@ -13,6 +13,7 @@ import { DiffView } from './DiffView.js';
|
|
|
13
13
|
import { changeLabel, formatDurationMs, toolLabel, toolTimer, toolVerb } from './format.js';
|
|
14
14
|
import { contentWidth, hangingWrap } from './layout.js';
|
|
15
15
|
import { foldedAssistantFields, foldedLiveFields } from './reasoningfold.js';
|
|
16
|
+
import { OUTPUT_TAIL_LINES } from '../tools/bash.js';
|
|
16
17
|
export function Scrollback({ messages, streaming, streamingReasoning, streamingTool, streamingNested = false, streamingNote = false, streamingCommand = false, pendingTool = '', pendingToolMs = 0, chromeRows = 0, showHeldWorked = true, }) {
|
|
17
18
|
// The live (non-Static) region must never grow taller than the viewport: Ink can't
|
|
18
19
|
// erase a frame taller than the screen, which is what produces the "duplicated
|
|
@@ -55,7 +56,12 @@ export function Scrollback({ messages, streaming, streamingReasoning, streamingT
|
|
|
55
56
|
const { log: scrollback, held } = useScrollbackLog(messages);
|
|
56
57
|
const pendingGap = pendingTool ? pendingToolGap(pendingTool, scrollback.at(-1)) : 0;
|
|
57
58
|
const pool = region - (pendingTool ? 1 + pendingGap : 0) - blocks.reduce((sum, b) => sum + b.fixed, 0);
|
|
58
|
-
|
|
59
|
+
// A running command's tail is held to the rows its committed chip shows: grown to the pool, it
|
|
60
|
+
// pushed the input to the bottom and then dropped it by the difference when the chip replaced it.
|
|
61
|
+
const shares = allocateLiveRows(blocks.map(b => {
|
|
62
|
+
const need = b.live.cut ? Infinity : b.live.rows.length;
|
|
63
|
+
return b.kind === 'tool' && streamingCommand ? Math.min(need, OUTPUT_TAIL_LINES) : need;
|
|
64
|
+
}), pool);
|
|
59
65
|
const live = (_jsxs(_Fragment, { children: [pendingTool ? (_jsx(Box, { marginTop: pendingGap, children: _jsxs(Text, { color: theme.secondary, children: [_jsx(Text, { color: theme.tool, children: TOOL_MARKER }), `${toolVerb(pendingTool)}…`, _jsx(Text, { color: theme.muted, children: toolTimer(pendingTool, pendingToolMs) })] }) })) : null, blocks.map((b, i) => b.kind === 'reasoning' ? (_jsx(Box, { marginTop: 1, children: _jsx(ReasoningBlock, { lines: b.live.rows.slice(-shares[i]), barColor: streamingNote ? theme.info : undefined }) }, b.kind)) : b.kind === 'content' && streamingNote ? (_jsx(NoteBody, { tail: fitTail(b.live, shares[i]), joined: blocks[i - 1]?.kind === 'reasoning' }, b.kind)) : (_jsx(StreamingTail, { tail: fitTail(b.live, shares[i]), muted: b.kind === 'tool',
|
|
60
66
|
// Relative to the live wrapper (which already pays `indent`), so a command's output
|
|
61
67
|
// lands where the committed one will: inside the chip's margin, or flush left.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { debugLog } from '../debug.js';
|
|
2
|
+
// Input-jump measurement (REIKA_DEBUG only). Ink anchors the live frame to the cursor, so a frame
|
|
3
|
+
// that erases more rows than it prints back leaves the input box higher with blank rows under it,
|
|
4
|
+
// and the next stream pushes it back down. Read off the bytes the terminal actually gets, because
|
|
5
|
+
// that is the only place a commit's static rows and the redrawn frame are counted together.
|
|
6
|
+
const CURSOR_UP = '\x1b[1A';
|
|
7
|
+
const CLEAR_SCREEN = '\x1b[2J';
|
|
8
|
+
// Rows the cursor ended above where it started: Ink erases with one cursor-up per row and prints
|
|
9
|
+
// with newlines, so the difference is how far the input box moved up. Null for a full-screen
|
|
10
|
+
// repaint, which homes the cursor instead and says nothing about the frame it replaced.
|
|
11
|
+
export function frameRise(frame) {
|
|
12
|
+
if (frame.includes(CLEAR_SCREEN))
|
|
13
|
+
return null;
|
|
14
|
+
let up = 0;
|
|
15
|
+
for (let i = frame.indexOf(CURSOR_UP); i !== -1; i = frame.indexOf(CURSOR_UP, i + 1))
|
|
16
|
+
up++;
|
|
17
|
+
let down = 0;
|
|
18
|
+
for (let i = frame.indexOf('\n'); i !== -1; i = frame.indexOf('\n', i + 1))
|
|
19
|
+
down++;
|
|
20
|
+
return Math.max(0, up - down);
|
|
21
|
+
}
|
|
22
|
+
// What the App was drawing, noted each render, so a drop can name the change that caused it.
|
|
23
|
+
let current = '';
|
|
24
|
+
let previous = '';
|
|
25
|
+
export function noteFrameState(state) {
|
|
26
|
+
current = state;
|
|
27
|
+
}
|
|
28
|
+
export function recordFrame(frame) {
|
|
29
|
+
const rise = frameRise(frame);
|
|
30
|
+
if (rise !== null && rise > 0) {
|
|
31
|
+
debugLog(`frame-drop rows=${rise} from="${previous}" to="${current}"`);
|
|
32
|
+
}
|
|
33
|
+
previous = current;
|
|
34
|
+
}
|
package/dist/ui/syncframe.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
//
|
|
19
19
|
// Writes are only queued for a real TTY; a pipe (tests, CI) gets the stream back untouched.
|
|
20
20
|
// `REIKA_SYNC_OUTPUT=0` is the kill switch for a terminal that misbehaves on mode 2026.
|
|
21
|
+
import { recordFrame } from './framedrops.js';
|
|
21
22
|
// Ink gives every code point its own grid cell, so `⏺︎` (U+23FA + VS15) spends two cells on a
|
|
22
23
|
// glyph the terminal draws in one, and a bordered row comes up a column short (#450). Components
|
|
23
24
|
// write a bare `⏺` — one cell, no phantom — and the selector goes back on here, after Ink has laid
|
|
@@ -28,7 +29,7 @@ export function restoreTextPresentation(text) {
|
|
|
28
29
|
}
|
|
29
30
|
export const BEGIN_SYNC = '\x1b[?2026h';
|
|
30
31
|
export const END_SYNC = '\x1b[?2026l';
|
|
31
|
-
export function createFrameWriter(target) {
|
|
32
|
+
export function createFrameWriter(target, onFrame) {
|
|
32
33
|
let pending = [];
|
|
33
34
|
let scheduled = false;
|
|
34
35
|
let closed = false;
|
|
@@ -38,6 +39,7 @@ export function createFrameWriter(target) {
|
|
|
38
39
|
return;
|
|
39
40
|
const frame = pending.join('');
|
|
40
41
|
pending = [];
|
|
42
|
+
onFrame?.(frame);
|
|
41
43
|
target.write(BEGIN_SYNC + restoreTextPresentation(frame) + END_SYNC);
|
|
42
44
|
};
|
|
43
45
|
return {
|
|
@@ -73,8 +75,11 @@ export function createSyncedStdout(target, env = process.env) {
|
|
|
73
75
|
// The kill switch drops the frame batching, not the presentation fix: without it the dialog
|
|
74
76
|
// marker would be a bare `⏺` some terminals draw as an emoji.
|
|
75
77
|
let write;
|
|
78
|
+
// Measured per frame only: unbatched, Ink's erase and its reprint arrive as separate writes, and
|
|
79
|
+
// the erase alone would read as a drop.
|
|
80
|
+
const onFrame = env.REIKA_DEBUG ? recordFrame : undefined;
|
|
76
81
|
if (syncedOutputEnabled(env)) {
|
|
77
|
-
const writer = createFrameWriter(target);
|
|
82
|
+
const writer = createFrameWriter(target, onFrame);
|
|
78
83
|
process.once('exit', writer.close);
|
|
79
84
|
write = writer.write;
|
|
80
85
|
}
|