@alexwkleung/reika 0.9.0 → 0.10.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/dist/agent/compaction.js +9 -4
- package/dist/agent/liveusage.js +58 -0
- package/dist/agent/loop.js +155 -73
- package/dist/agent/readfirst.js +30 -8
- package/dist/cli.js +3 -3
- package/dist/headless/headless.js +65 -6
- package/dist/headless/headlessargs.js +1 -1
- package/dist/headless/headlessprompt.js +2 -1
- package/dist/provider/client.js +65 -5
- package/dist/provider/latches.js +2 -0
- package/dist/provider/toolcall.js +29 -7
- package/dist/search/_chrome.js +38 -0
- package/dist/tools/_readonly.js +17 -1
- package/dist/tools/_sandbox.js +139 -20
- package/dist/ui/App.js +73 -34
- package/dist/ui/Approval.js +1 -6
- package/dist/ui/Scrollback.js +11 -3
- package/dist/ui/Working.js +18 -7
- package/dist/ui/format.js +23 -0
- package/dist/ui/layout.js +6 -0
- package/dist/ui/markdown.js +30 -2
- package/dist/ui/termtext.js +11 -0
- package/dist/ui/theme.js +5 -1
- package/package.json +1 -1
package/dist/tools/_sandbox.js
CHANGED
|
@@ -3,7 +3,7 @@ import { homedir, tmpdir } from 'node:os';
|
|
|
3
3
|
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
4
|
import { execFileSync, spawnSync } from 'node:child_process';
|
|
5
5
|
import { expandingHeredocBodies, stripHeredocs } from './_heredoc.js';
|
|
6
|
-
import { dropCarriers, hasExecutableSubstitution, hasRawSubstitution, maskQuoted, splitSegments, words, INSPECTION_COMMANDS, } from './_readonly.js';
|
|
6
|
+
import { WORD_RE, dropCarriers, hasExecutableSubstitution, hasRawSubstitution, maskQuoted, splitSegments, words, INSPECTION_COMMANDS, } from './_readonly.js';
|
|
7
7
|
// Kernel-enforced confinement for model-chosen shell commands (#163). Seatbelt (`sandbox-exec`)
|
|
8
8
|
// only: bubblewrap has no port-level network filtering, so a sandboxed process gets its own
|
|
9
9
|
// loopback and cannot reach the host's model server — the one thing bash needs localhost for. The
|
|
@@ -241,24 +241,94 @@ const GIT_PROGRAM_SHORT_FLAGS = {
|
|
|
241
241
|
rebase: { run: 'x', value: 'sXxC' },
|
|
242
242
|
difftool: { run: 'x', value: 'tx' },
|
|
243
243
|
};
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
244
|
+
// The subcommands a `git` segment may keep the network with — an ALLOWLIST since #910, the polarity
|
|
245
|
+
// `gh` and `hf` already have, because the blocklist it replaced (`filter-branch`, `submodule
|
|
246
|
+
// foreach`, `bisect run`, `send-email`) left every subcommand nobody had listed open: `git
|
|
247
|
+
// remote-ext`, `git submodule--helper foreach` and `git merge-index ./x.sh -a` each ran a program
|
|
248
|
+
// with the network. A missed subcommand is now a false deny. Only the first group needs the network;
|
|
249
|
+
// the second is here so a read or a branch switch beside a fetch (`git fetch && git log ..@{u}`,
|
|
250
|
+
// `git checkout main && git pull`) does not cost the fetch its allow, and each was checked for an
|
|
251
|
+
// option that names a program on the command line (`merge -s` looks a strategy up on PATH only, so
|
|
252
|
+
// `-s ./x` is refused by git itself). `send-email`, `filter-branch`, `bisect`, `worktree add`, `help`
|
|
253
|
+
// (`-w` starts a browser) and every plumbing command not named are out.
|
|
254
|
+
const GIT_NETWORK_SUBCOMMANDS = new Set(['fetch', 'pull', 'clone', 'ls-remote', 'push', 'remote']);
|
|
255
|
+
const GIT_LOCAL_SUBCOMMANDS = new Set([
|
|
256
|
+
'add',
|
|
257
|
+
'apply',
|
|
258
|
+
'blame',
|
|
259
|
+
'branch',
|
|
260
|
+
'cat-file',
|
|
261
|
+
'check-ignore',
|
|
262
|
+
'checkout',
|
|
263
|
+
'cherry',
|
|
264
|
+
'cherry-pick',
|
|
265
|
+
'commit',
|
|
266
|
+
'config',
|
|
267
|
+
'count-objects',
|
|
268
|
+
'describe',
|
|
269
|
+
'diff',
|
|
270
|
+
'for-each-ref',
|
|
271
|
+
'grep',
|
|
272
|
+
'hash-object',
|
|
273
|
+
'log',
|
|
274
|
+
'ls-files',
|
|
275
|
+
'ls-tree',
|
|
276
|
+
'merge',
|
|
277
|
+
'merge-base',
|
|
278
|
+
'merge-tree',
|
|
279
|
+
'mv',
|
|
280
|
+
'name-rev',
|
|
281
|
+
'range-diff',
|
|
282
|
+
'rebase',
|
|
283
|
+
'reflog',
|
|
284
|
+
'reset',
|
|
285
|
+
'restore',
|
|
286
|
+
'rev-list',
|
|
287
|
+
'rev-parse',
|
|
288
|
+
'revert',
|
|
289
|
+
'rm',
|
|
290
|
+
'shortlog',
|
|
291
|
+
'show',
|
|
292
|
+
'show-ref',
|
|
293
|
+
'stash',
|
|
294
|
+
'status',
|
|
295
|
+
'stripspace',
|
|
296
|
+
'switch',
|
|
297
|
+
'symbolic-ref',
|
|
298
|
+
'tag',
|
|
299
|
+
'version',
|
|
300
|
+
'whatchanged',
|
|
251
301
|
]);
|
|
302
|
+
// Subcommands allowed only with one of these as their first operand: `submodule foreach` and `lfs`'s
|
|
303
|
+
// own verbs that push or install hooks are the rest of those namespaces.
|
|
304
|
+
const GIT_SUBCOMMAND_OPERANDS = {
|
|
305
|
+
submodule: new Set(['update', 'init', 'sync', 'status', 'summary', 'deinit', 'absorbgitdirs']),
|
|
306
|
+
lfs: new Set(['fetch', 'pull', 'ls-files', 'status', 'env', 'version']),
|
|
307
|
+
worktree: new Set(['list', 'prune', 'remove']),
|
|
308
|
+
};
|
|
252
309
|
function gitSubcommandRunsProgram(sub, args) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
310
|
+
const operands = GIT_SUBCOMMAND_OPERANDS[sub];
|
|
311
|
+
if (operands) {
|
|
312
|
+
const first = args.find(a => !a.startsWith('-'));
|
|
313
|
+
if (!first || !operands.has(first))
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
else if (!GIT_NETWORK_SUBCOMMANDS.has(sub) && !GIT_LOCAL_SUBCOMMANDS.has(sub)) {
|
|
257
317
|
return true;
|
|
318
|
+
}
|
|
258
319
|
const short = GIT_PROGRAM_SHORT_FLAGS[sub];
|
|
259
|
-
for (
|
|
260
|
-
|
|
261
|
-
|
|
320
|
+
for (let i = 0; i < args.length; i++) {
|
|
321
|
+
const a = args[i];
|
|
322
|
+
// `--` ends the options only when it is not the VALUE of the option before it: in `git
|
|
323
|
+
// ls-remote -o -- --upload-pack=./x.sh .` it is `-o`'s value and git read the next word as an
|
|
324
|
+
// option (measured, #910). Which options take a value is per subcommand and not worth a table,
|
|
325
|
+
// so any bare option before it (one carrying no `=value`) keeps the scan going.
|
|
326
|
+
if (a === '--') {
|
|
327
|
+
const prev = args[i - 1];
|
|
328
|
+
if (prev === undefined || !prev.startsWith('-') || prev.includes('='))
|
|
329
|
+
return false;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
262
332
|
if (a.startsWith('--')) {
|
|
263
333
|
const name = a.slice(2).split('=')[0];
|
|
264
334
|
// Any prefix, down to one letter (`--u=cmd` ran); `--=x` has an empty name, which is none.
|
|
@@ -276,6 +346,46 @@ function gitSubcommandRunsProgram(sub, args) {
|
|
|
276
346
|
}
|
|
277
347
|
return false;
|
|
278
348
|
}
|
|
349
|
+
// Whether a raw (still-quoted) word holds something the shell expands before git sees it, so the
|
|
350
|
+
// classifier cannot read the option git will get (#910): a parameter (`"$f"` from a `for` loop), a
|
|
351
|
+
// backtick, a glob (`--up*` matches a file of that name) or a brace expansion (`{--u=./x.sh,.}`,
|
|
352
|
+
// `git {send-email,p}`). Single quotes and backslashes make each of these literal. A brace counts only
|
|
353
|
+
// with a `,` or `..` before its `}`, since `HEAD@{1}` and `@{u}` are not expansions.
|
|
354
|
+
function shellExpandsWord(raw) {
|
|
355
|
+
let quote = null;
|
|
356
|
+
for (let i = 0; i < raw.length; i++) {
|
|
357
|
+
const c = raw[i];
|
|
358
|
+
if (c === '\\') {
|
|
359
|
+
i++;
|
|
360
|
+
}
|
|
361
|
+
else if (quote === '"') {
|
|
362
|
+
if (c === '"')
|
|
363
|
+
quote = null;
|
|
364
|
+
else if (c === '$' || c === '`')
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
else if (c === "'") {
|
|
368
|
+
const end = raw.indexOf("'", i + 1);
|
|
369
|
+
i = end < 0 ? raw.length : end;
|
|
370
|
+
}
|
|
371
|
+
else if (c === '$' && (raw[i + 1] === "'" || raw[i + 1] === '"')) {
|
|
372
|
+
// `$'…'` and `$"…"` are quoting, not a parameter; the quote itself is read next.
|
|
373
|
+
}
|
|
374
|
+
else if (c === '"') {
|
|
375
|
+
quote = '"';
|
|
376
|
+
}
|
|
377
|
+
else if (c === '$' || c === '`' || c === '*' || c === '?' || c === '[') {
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
else if (c === '{') {
|
|
381
|
+
const close = raw.indexOf('}', i + 1);
|
|
382
|
+
const inner = close < 0 ? '' : raw.slice(i + 1, close);
|
|
383
|
+
if (inner.includes(',') || inner.includes('..'))
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
279
389
|
// Called with the git segment's OWN words (verb, `timeout`/`xargs` carrier and xargs flags already
|
|
280
390
|
// dropped), so a carrier's data cannot pose as the verb's arguments: `xargs -I git git -c k=v
|
|
281
391
|
// fetch` would otherwise find the `-I` placeholder where it looks for `git`.
|
|
@@ -394,7 +504,8 @@ function effectiveWords(segment) {
|
|
|
394
504
|
// `timeout` and `xargs` each name the command they run rather than being it, so both are skipped to
|
|
395
505
|
// reach it — a carrier inside the command xargs runs included.
|
|
396
506
|
let ws = dropCarriers(words(segment.trim().replace(VERB_PREFIX_RE, '')));
|
|
397
|
-
|
|
507
|
+
const viaXargs = ws[0] === 'xargs';
|
|
508
|
+
if (viaXargs) {
|
|
398
509
|
let i = 1;
|
|
399
510
|
while (i < ws.length && ws[i].startsWith('-')) {
|
|
400
511
|
if (XARGS_VALUE_FLAGS.has(ws[i]))
|
|
@@ -403,7 +514,7 @@ function effectiveWords(segment) {
|
|
|
403
514
|
}
|
|
404
515
|
ws = dropCarriers(ws.slice(i));
|
|
405
516
|
}
|
|
406
|
-
return ws;
|
|
517
|
+
return { ws, viaXargs };
|
|
407
518
|
}
|
|
408
519
|
/**
|
|
409
520
|
* Whether `command` may run sandboxed WITH network: every segment is a `NET_VERBS` command or one
|
|
@@ -443,7 +554,7 @@ export function networkDecision(command) {
|
|
|
443
554
|
let net = false;
|
|
444
555
|
let blockedBy;
|
|
445
556
|
for (const seg of segments) {
|
|
446
|
-
const ws = effectiveWords(seg);
|
|
557
|
+
const { ws, viaXargs } = effectiveWords(seg);
|
|
447
558
|
const verb = ws[0];
|
|
448
559
|
if (!verb)
|
|
449
560
|
return { allowed: false };
|
|
@@ -451,8 +562,16 @@ export function networkDecision(command) {
|
|
|
451
562
|
if (NET_VERBS.has(verb)) {
|
|
452
563
|
if (!envPrefixHarmless(seg))
|
|
453
564
|
return { allowed: false };
|
|
454
|
-
if (verb === 'git'
|
|
455
|
-
|
|
565
|
+
if (verb === 'git') {
|
|
566
|
+
// What `xargs` appends comes from stdin and what the shell expands is decided at run time, so
|
|
567
|
+
// neither is an argument this reader has seen (#910): `echo --upload-pack=./x.sh . | xargs
|
|
568
|
+
// git ls-remote` ran the program. `gh`/`hf` keep both shapes, which their verb tables bound.
|
|
569
|
+
if (viaXargs || (seg.match(WORD_RE) ?? []).some(shellExpandsWord)) {
|
|
570
|
+
return { allowed: false };
|
|
571
|
+
}
|
|
572
|
+
if (gitArgsRunProgram(args))
|
|
573
|
+
return { allowed: false };
|
|
574
|
+
}
|
|
456
575
|
net = true;
|
|
457
576
|
}
|
|
458
577
|
else if (!NET_PIPE_COMMANDS.has(verb)) {
|
package/dist/ui/App.js
CHANGED
|
@@ -30,6 +30,7 @@ import { saveTranscript, buildTranscriptMeta, } from '../store/transcript.js';
|
|
|
30
30
|
import {} from '../agent/loop.js';
|
|
31
31
|
import { compactThreshold } from '../agent/compaction.js';
|
|
32
32
|
import { createPrefixWarmer } from '../agent/warm.js';
|
|
33
|
+
import { withLiveUsage } from '../agent/liveusage.js';
|
|
33
34
|
import { execStream } from '../tools/bash.js';
|
|
34
35
|
import { isOffline } from '../tools/_net.js';
|
|
35
36
|
import { expandMentions } from '../agent/mentions.js';
|
|
@@ -43,7 +44,7 @@ import { clipboardImageSupported, readClipboardImage } from './clipboard.js';
|
|
|
43
44
|
import { isWarmEdge } from './warmtrigger.js';
|
|
44
45
|
import { Suggestions, suggestionRows } from './Suggestions.js';
|
|
45
46
|
import { ModelSelect } from './ModelSelect.js';
|
|
46
|
-
import { mcpStartupLine } from './format.js';
|
|
47
|
+
import { mcpStartupLine, prefillLabel } from './format.js';
|
|
47
48
|
import { useContentWidth } from './layout.js';
|
|
48
49
|
import { ResumeSelect } from './ResumeSelect.js';
|
|
49
50
|
import { countRealTurns, forAutosave, listSessions, loadSession, modelHistoryFromScrollback, newSessionPath, projectHistoryDir, ROOT_HISTORY_DIR, saveHeader, writeSession, } from '../store/sessions.js';
|
|
@@ -58,7 +59,7 @@ import { buildShellRunsBlock, captureShellRun, holdShellRun, shellRunBudget, } f
|
|
|
58
59
|
import { invokeMcpTool, parseMcpArgs } from '../mcp/tools.js';
|
|
59
60
|
// How long the "Typechecking" indicator lingers after a check settles, so a sub-second warm check
|
|
60
61
|
// still reads. Long enough to perceive, short enough not to imply the check is still running.
|
|
61
|
-
const TYPECHECK_LINGER_MS = 650;
|
|
62
|
+
export const TYPECHECK_LINGER_MS = 650;
|
|
62
63
|
function expandHome(p) {
|
|
63
64
|
if (p === '~')
|
|
64
65
|
return homedir();
|
|
@@ -121,6 +122,7 @@ export function App() {
|
|
|
121
122
|
// Relabels the busy indicator so the user can decide to abort (ctrl-c) or wait it out. A soft
|
|
122
123
|
// hint, not an automated cutoff — human-only, never part of model context. See loop.ts.
|
|
123
124
|
const [reasoningSpin, setReasoningSpin] = useState(false);
|
|
125
|
+
const [promptProgress, setPromptProgress] = useState(undefined);
|
|
124
126
|
// Checklist of the plan currently being implemented (#71), snapshotted from the loop's
|
|
125
127
|
// deterministic tracker. Non-null only after an agent turn found a written plan in history;
|
|
126
128
|
// persists between turns so the user can see what's left before continuing. Human-only.
|
|
@@ -166,7 +168,13 @@ export function App() {
|
|
|
166
168
|
const activeProfile = snapshot?.profile ?? 'default';
|
|
167
169
|
const [error, setError] = useState(null);
|
|
168
170
|
const [elapsed, setElapsed] = useState(0);
|
|
169
|
-
|
|
171
|
+
// The session total and the estimate for the request in flight (#925), one state so the real
|
|
172
|
+
// count replaces the estimate in a single commit: apart, the chip blinks out between them. The
|
|
173
|
+
// loop reports on every delta, and `live` takes it on the clock tick so the chips move once a
|
|
174
|
+
// second rather than on every stream flush.
|
|
175
|
+
const [usage, setUsage] = useState({
|
|
176
|
+
total: { promptTokens: 0, completionTokens: 0 },
|
|
177
|
+
});
|
|
170
178
|
// Most recent call's usage (the authoritative current context size + cache hit rate),
|
|
171
179
|
// and the pre-send estimate used to fill the gauge before that real count arrives.
|
|
172
180
|
const [lastUsage, setLastUsage] = useState(null);
|
|
@@ -180,6 +188,7 @@ export function App() {
|
|
|
180
188
|
// Decode throughput (tokens/second) for the status bar's tok/s chip (#204). The session keeps
|
|
181
189
|
// the learned value a turn seeds from; this is what the chip shows.
|
|
182
190
|
const [decodeRate, setDecodeRate] = useState(undefined);
|
|
191
|
+
const liveUsageRef = useRef(undefined);
|
|
183
192
|
const [pending, setPending] = useState(null);
|
|
184
193
|
const [approvalSelected, setApprovalSelected] = useState(0);
|
|
185
194
|
// Typing the reason for a decline: like `questionTyping`, the input box underneath is the field.
|
|
@@ -379,7 +388,7 @@ export function App() {
|
|
|
379
388
|
// model-facing side of each is the session's (switchSide).
|
|
380
389
|
const stashedMessagesRef = useRef({});
|
|
381
390
|
const usageRef = useRef({ promptTokens: 0, completionTokens: 0 });
|
|
382
|
-
usageRef.current =
|
|
391
|
+
usageRef.current = usage.total;
|
|
383
392
|
// The other two halves of the status line's accounting, mirrored for the same reason as
|
|
384
393
|
// `usageRef`: /save reads them from a handler that may be a render behind (#199).
|
|
385
394
|
const lastUsageRef = useRef(null);
|
|
@@ -615,6 +624,7 @@ export function App() {
|
|
|
615
624
|
if (startedAtRef.current != null) {
|
|
616
625
|
setElapsed(Math.floor((Date.now() - startedAtRef.current) / 1000));
|
|
617
626
|
}
|
|
627
|
+
setUsage(u => ({ total: u.total, live: liveUsageRef.current }));
|
|
618
628
|
}, 1000);
|
|
619
629
|
return () => clearInterval(id);
|
|
620
630
|
}, [status, pending, question]);
|
|
@@ -1095,7 +1105,7 @@ export function App() {
|
|
|
1095
1105
|
stashedMessagesRef.current = {};
|
|
1096
1106
|
sessionRef.current?.reset({ relearn });
|
|
1097
1107
|
setPlanSteps(null);
|
|
1098
|
-
|
|
1108
|
+
setUsage({ total: { promptTokens: 0, completionTokens: 0 } });
|
|
1099
1109
|
setLastUsage(null);
|
|
1100
1110
|
setEstimatedContext(null);
|
|
1101
1111
|
setShrink({ sheds: 0, folds: 0 });
|
|
@@ -1859,8 +1869,8 @@ export function App() {
|
|
|
1859
1869
|
response = bundle?.cwd ?? '(unknown)';
|
|
1860
1870
|
break;
|
|
1861
1871
|
case 'tokens': {
|
|
1862
|
-
const approx =
|
|
1863
|
-
response = `prompt: ${approx}${
|
|
1872
|
+
const approx = usage.total.estimated ? '~' : '';
|
|
1873
|
+
response = `prompt: ${approx}${usage.total.promptTokens}\ncompletion: ${approx}${usage.total.completionTokens}`;
|
|
1864
1874
|
break;
|
|
1865
1875
|
}
|
|
1866
1876
|
case 'skills': {
|
|
@@ -2448,6 +2458,13 @@ export function App() {
|
|
|
2448
2458
|
}, TYPECHECK_LINGER_MS);
|
|
2449
2459
|
}
|
|
2450
2460
|
};
|
|
2461
|
+
// The linger exists to keep a finished check on screen; a prefill worth naming is the newer fact,
|
|
2462
|
+
// and holding it back made its label land late (#914). A check still running keeps its label.
|
|
2463
|
+
const onPromptProgressChange = (progress) => {
|
|
2464
|
+
setPromptProgress(progress);
|
|
2465
|
+
if (typecheckHideTimerRef.current && prefillLabel(progress))
|
|
2466
|
+
resetTypecheck();
|
|
2467
|
+
};
|
|
2451
2468
|
// Immediate, un-lingered clear for turn boundaries.
|
|
2452
2469
|
const resetTypecheck = () => {
|
|
2453
2470
|
if (typecheckHideTimerRef.current) {
|
|
@@ -2541,6 +2558,9 @@ export function App() {
|
|
|
2541
2558
|
noteLiveRef.current = false;
|
|
2542
2559
|
setSubagentLive(false);
|
|
2543
2560
|
setNoteLive(false);
|
|
2561
|
+
// A request that threw reports no usage, so nothing else would clear it.
|
|
2562
|
+
liveUsageRef.current = undefined;
|
|
2563
|
+
setUsage(u => ({ total: u.total }));
|
|
2544
2564
|
resetTypecheck();
|
|
2545
2565
|
setReasoningSpin(false);
|
|
2546
2566
|
setStatus('idle');
|
|
@@ -2634,6 +2654,7 @@ export function App() {
|
|
|
2634
2654
|
// re-render.
|
|
2635
2655
|
onPlanProgress: steps => setPlanSteps(steps.map(st => ({ ...st }))),
|
|
2636
2656
|
onReasoningStatus: setReasoningSpin,
|
|
2657
|
+
onPromptProgress: onPromptProgressChange,
|
|
2637
2658
|
onReasoningReset: () => {
|
|
2638
2659
|
// Loop-break recovery: end the degenerate looped reasoning's live preview so the
|
|
2639
2660
|
// recovery notice is visible and the next round streams into a fresh Thinking block
|
|
@@ -2666,17 +2687,27 @@ export function App() {
|
|
|
2666
2687
|
// The gauge and cache chip read lastUsage, and an estimate has no real count for either.
|
|
2667
2688
|
if (!u.estimated)
|
|
2668
2689
|
setLastUsage(u);
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2690
|
+
setUsage(({ total: t }) => ({
|
|
2691
|
+
total: {
|
|
2692
|
+
promptTokens: t.promptTokens + u.promptTokens,
|
|
2693
|
+
completionTokens: t.completionTokens + u.completionTokens,
|
|
2694
|
+
...(u.cachedTokens != null
|
|
2695
|
+
? { cachedTokens: (t.cachedTokens ?? 0) + u.cachedTokens }
|
|
2696
|
+
: t.cachedTokens != null
|
|
2697
|
+
? { cachedTokens: t.cachedTokens }
|
|
2698
|
+
: {}),
|
|
2699
|
+
...(u.estimated || t.estimated ? { estimated: true } : {}),
|
|
2700
|
+
},
|
|
2678
2701
|
}));
|
|
2679
2702
|
},
|
|
2703
|
+
onLiveUsage: live => {
|
|
2704
|
+
// A round's first report skips the tick so ↑ moves as the request goes out. A clear only
|
|
2705
|
+
// touches the ref: onUsage drops `live` with the real count, or the next tick does.
|
|
2706
|
+
const first = live && !liveUsageRef.current;
|
|
2707
|
+
liveUsageRef.current = live;
|
|
2708
|
+
if (first)
|
|
2709
|
+
setUsage(u => ({ total: u.total, live }));
|
|
2710
|
+
},
|
|
2680
2711
|
onContextEstimate: t => setEstimatedContext(t),
|
|
2681
2712
|
onShrink: (event, counts) => {
|
|
2682
2713
|
setShrink(counts);
|
|
@@ -2701,20 +2732,21 @@ export function App() {
|
|
|
2701
2732
|
statusProfile?.minGenTokens ??
|
|
2702
2733
|
config.minGenTokens))
|
|
2703
2734
|
: undefined;
|
|
2735
|
+
const prefilling = prefillLabel(promptProgress);
|
|
2704
2736
|
const statusWidth = useContentWidth();
|
|
2705
2737
|
const statusProps = {
|
|
2706
2738
|
model: config?.profiles[activeProfile]?.model ?? config?.model ?? '',
|
|
2707
2739
|
turns: messages.filter(m => m.role === 'assistant').length,
|
|
2708
2740
|
status: status === 'busy' ? phase : status,
|
|
2709
2741
|
elapsed: status === 'busy' ? elapsed : null,
|
|
2710
|
-
usage:
|
|
2742
|
+
usage: withLiveUsage(usage.total, usage.live),
|
|
2711
2743
|
contextTokens: lastUsage?.promptTokens ?? estimatedContext,
|
|
2712
2744
|
contextWindow: statusWindow,
|
|
2713
2745
|
contextUsable: statusUsable,
|
|
2714
2746
|
sheds: shrink.sheds,
|
|
2715
2747
|
folds: shrink.folds,
|
|
2716
2748
|
cachedTokens: lastUsage?.cachedTokens,
|
|
2717
|
-
decodeRate: decodeRate,
|
|
2749
|
+
decodeRate: usage.live?.rate ?? decodeRate,
|
|
2718
2750
|
pr: pr,
|
|
2719
2751
|
autoApprove: config?.autoApprove === 'bypass'
|
|
2720
2752
|
? 'bypass'
|
|
@@ -2822,27 +2854,34 @@ export function App() {
|
|
|
2822
2854
|
// height, where Ink repaints with a scrollback clear on every chunk (#470).
|
|
2823
2855
|
chromeRows: dialogReservedRows + suggestionRows(suggestionState) }), heldRows !== undefined ? _jsx(Box, { ref: holdSpacerRef, flexGrow: 1 }) : null, planSteps && (mode === 'agent' || mode === 'vibe') ? (_jsx(PlanProgress, { steps: planSteps })) : null, status === 'busy' && pending === null && question === null ? (_jsx(Working
|
|
2824
2856
|
// Definite harness actions (typecheck, loop recovery) take priority over the soft spin
|
|
2825
|
-
// hint — they're things the harness is actively doing, not a maybe.
|
|
2857
|
+
// hint — they're things the harness is actively doing, not a maybe. Prefill outranks
|
|
2858
|
+
// recovery (#916): the scrollback already records the recovery, and the wait is longer.
|
|
2826
2859
|
, {
|
|
2827
2860
|
// Definite harness actions (typecheck, loop recovery) take priority over the soft spin
|
|
2828
|
-
// hint — they're things the harness is actively doing, not a maybe.
|
|
2861
|
+
// hint — they're things the harness is actively doing, not a maybe. Prefill outranks
|
|
2862
|
+
// recovery (#916): the scrollback already records the recovery, and the wait is longer.
|
|
2829
2863
|
label: typechecking
|
|
2830
2864
|
? 'Typechecking'
|
|
2831
|
-
:
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2865
|
+
: (prefilling ??
|
|
2866
|
+
(recovering
|
|
2867
|
+
? 'Recovering from a loop'
|
|
2868
|
+
: reasoningSpin
|
|
2869
|
+
? 'Thinking — may be looping (ctrl-c to abort)'
|
|
2870
|
+
: noteLive
|
|
2871
|
+
? 'Writing compaction note'
|
|
2872
|
+
: subagentLive
|
|
2873
|
+
? 'Subagent working'
|
|
2874
|
+
: undefined)), words: config?.workingWords ? WORKING_WORDS : undefined, accent: typechecking
|
|
2840
2875
|
? theme.info
|
|
2841
|
-
:
|
|
2842
|
-
? theme.
|
|
2843
|
-
:
|
|
2844
|
-
? theme.
|
|
2845
|
-
:
|
|
2876
|
+
: prefilling
|
|
2877
|
+
? theme.prefill
|
|
2878
|
+
: recovering || noteLive
|
|
2879
|
+
? theme.info
|
|
2880
|
+
: reasoningSpin
|
|
2881
|
+
? theme.warning
|
|
2882
|
+
: subagentLive
|
|
2883
|
+
? theme.subagent
|
|
2884
|
+
: 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 &&
|
|
2846
2885
|
config.subagentModel !== (config.profiles[activeProfile]?.model ?? config.model)
|
|
2847
2886
|
? config.subagentModel
|
|
2848
2887
|
: undefined })) : resumeSelect ? (_jsx(ResumeSelect, { entries: resumeSelect.entries, selectedIndex: resumeSelected, heading: resumeSelect.heading })) : confirm ? (_jsx(Confirm, { spec: confirm.spec, selectedIndex: confirmSelected })) : null, _jsx(Input
|
package/dist/ui/Approval.js
CHANGED
|
@@ -7,7 +7,7 @@ import { theme } from './theme.js';
|
|
|
7
7
|
import { DiffView } from './DiffView.js';
|
|
8
8
|
import { highlightCode } from './highlight.js';
|
|
9
9
|
import { sanitizeTerminalText } from './termtext.js';
|
|
10
|
-
import { hangingRows, hangingWrap, useContentWidth, wrappedRows, wrapStyledRows, } from './layout.js';
|
|
10
|
+
import { hangingRows, dropWrapWhitespace, hangingWrap, useContentWidth, wrappedRows, wrapStyledRows, } from './layout.js';
|
|
11
11
|
import { toolLabel } from './format.js';
|
|
12
12
|
// The dialog's own border (1 column each side) plus its paddingX={1}, on top of the App padding
|
|
13
13
|
// contentWidth already accounts for. The diff has to wrap inside all of it or its rows push
|
|
@@ -127,11 +127,6 @@ function CommandPreview({ command, maxRows, width, }) {
|
|
|
127
127
|
return rows.map((row, j) => (_jsxs(Box, { children: [_jsx(Text, { color: theme.success, children: j === 0 && i === 0 ? MARKER : ' '.repeat(MARKER_WIDTH) }), _jsx(Text, { children: j === 0 ? row : dropWrapWhitespace(row) })] }, `${i}:${j}`)));
|
|
128
128
|
}), hidden > 0 ? _jsx(Text, { color: theme.muted, children: `… ${hidden} more lines` }) : null] }));
|
|
129
129
|
}
|
|
130
|
-
// trim:false leaves the space wrap-ansi broke on at the head of a continuation row, one column
|
|
131
|
-
// right of the hang — the same noise hangingWrap drops. Highlighting can open a color ahead of it.
|
|
132
|
-
function dropWrapWhitespace(row) {
|
|
133
|
-
return row.replace(/^((?:\x1b\[[0-9;]*m)*) +/, '$1');
|
|
134
|
-
}
|
|
135
130
|
// Leading lines that fit in `maxRows` wrapped rows, one reserved for the footer when any are cut.
|
|
136
131
|
export function fitCommandLines(lines, maxRows, width) {
|
|
137
132
|
const heights = lines.map(l => wrapAnsi(l, Math.max(1, width), { trim: false, hard: true }).split('\n').length);
|
package/dist/ui/Scrollback.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useMemo, useRef } from 'react';
|
|
|
3
3
|
import { Box, Static, Text } from 'ink';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import stringWidth from 'string-width';
|
|
6
|
-
import { hideDanglingMarkers, renderMarkdown, renderReasoningMarkdown } from './markdown.js';
|
|
6
|
+
import { hideDanglingMarkers, openFenceBefore, renderMarkdown, renderReasoningMarkdown, } from './markdown.js';
|
|
7
7
|
import { glyphs } from './glyphs.js';
|
|
8
8
|
import { theme, themeChalk } from './theme.js';
|
|
9
9
|
import { scrubGeneration } from './identity.js';
|
|
@@ -161,13 +161,21 @@ export function tailText(text, maxLines, maxChars = maxLines * 240) {
|
|
|
161
161
|
}
|
|
162
162
|
return { text: out, truncated };
|
|
163
163
|
}
|
|
164
|
+
// `tailText` for text that gets rendered as markdown: a cut inside a code block keeps the block.
|
|
165
|
+
export function markdownTail(text, maxLines) {
|
|
166
|
+
const pre = tailText(text, maxLines);
|
|
167
|
+
if (!pre.truncated)
|
|
168
|
+
return pre;
|
|
169
|
+
const fence = openFenceBefore(text, text.length - pre.text.length);
|
|
170
|
+
return fence ? { text: `${fence}\n${pre.text}`, truncated: true } : pre;
|
|
171
|
+
}
|
|
164
172
|
// Live assistant text: rendered as a bounded tail (markdown preview); the committed
|
|
165
173
|
// message re-renders the full text in <Static>. The logical-line pre-trim caps markdown render cost
|
|
166
174
|
// on very long streams; the factor keeps enough lines to fill `bound` display rows even when each
|
|
167
175
|
// wraps. The rows are measured *rendered* (markdown can expand lines, e.g. code fences), which is
|
|
168
176
|
// what Ink counts against the viewport.
|
|
169
177
|
function streamingContentRows(text, width, bound) {
|
|
170
|
-
const pre =
|
|
178
|
+
const pre = markdownTail(text, bound * 4);
|
|
171
179
|
// A pre-trimmed tail starts mid-message, so its first row gets the indent, not the marker.
|
|
172
180
|
const prose = markProse(renderMarkdown(hideDanglingMarkers(pre.text), width - CALL_MARKER_MEASURED), !pre.truncated);
|
|
173
181
|
return { rows: displayRows(prose, width), cut: pre.truncated };
|
|
@@ -175,7 +183,7 @@ function streamingContentRows(text, width, bound) {
|
|
|
175
183
|
// The live tail of a compaction note: its rows sit behind the bar, so no prose marker and two
|
|
176
184
|
// columns narrower. Same pre-trim and measuring as streamingContentRows.
|
|
177
185
|
function streamingNoteRows(text, width, bound) {
|
|
178
|
-
const pre =
|
|
186
|
+
const pre = markdownTail(text, bound * 4);
|
|
179
187
|
return { rows: noteBodyRows(hideDanglingMarkers(pre.text), width), cut: pre.truncated };
|
|
180
188
|
}
|
|
181
189
|
function noteBodyRows(text, width) {
|
package/dist/ui/Working.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { Box, Text } from 'ink';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import { glyphs } from './glyphs.js';
|
|
@@ -200,6 +200,11 @@ export function nextWordIndex(current, count, rand = Math.random) {
|
|
|
200
200
|
const step = 1 + Math.floor(rand() * (count - 1));
|
|
201
201
|
return (current + step) % count;
|
|
202
202
|
}
|
|
203
|
+
// Stepped rather than derived from the tick: `cycle` follows the label's length, so a modulo moved
|
|
204
|
+
// the tip whenever a prefill label changed width (#914). A shorter label past its end wraps here.
|
|
205
|
+
export function nextSweep(sweep, cycle) {
|
|
206
|
+
return sweep + 1 >= cycle ? 0 : sweep + 1;
|
|
207
|
+
}
|
|
203
208
|
// `accent` colors the spinner glyph (default = brand magenta). A distinct accent — e.g. cyan while
|
|
204
209
|
// the harness is typechecking — makes a transient state read at a glance rather than as a mere
|
|
205
210
|
// word-swap on an already-spinning indicator. `words` rotates the default label when no `label`
|
|
@@ -210,27 +215,33 @@ export function Working({ label, accent = theme.accent, words, }) {
|
|
|
210
215
|
tick: 0,
|
|
211
216
|
word: words && words.length > 0 ? Math.floor(Math.random() * words.length) : 0,
|
|
212
217
|
since: 0,
|
|
218
|
+
sweep: 0,
|
|
213
219
|
}));
|
|
220
|
+
const cycleRef = useRef(0);
|
|
214
221
|
useEffect(() => {
|
|
215
222
|
const id = setInterval(() => setClock(c => {
|
|
216
223
|
const tick = c.tick + 1;
|
|
217
224
|
if (pool && tick - c.since >= ticksPerWord(pool[c.word % pool.length])) {
|
|
218
|
-
return { tick, word: nextWordIndex(c.word, pool.length), since: tick };
|
|
225
|
+
return { tick, word: nextWordIndex(c.word, pool.length), since: tick, sweep: 0 };
|
|
219
226
|
}
|
|
220
|
-
|
|
227
|
+
const stepped = (tick - c.since) % SHIMMER_STEP === 0;
|
|
228
|
+
return { ...c, tick, sweep: stepped ? nextSweep(c.sweep, cycleRef.current) : c.sweep };
|
|
221
229
|
}), TICK_MS);
|
|
222
230
|
return () => clearInterval(id);
|
|
223
231
|
}, [pool]);
|
|
232
|
+
// A new accent is a new state on the line, so it opens on a fresh sweep rather than mid-glow.
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
setClock(c => (c.sweep === 0 ? c : { ...c, sweep: 0 }));
|
|
235
|
+
}, [accent]);
|
|
224
236
|
const text = pool ? pool[clock.word % pool.length] : (label ?? 'Working');
|
|
225
237
|
const chars = `${text}…`.split('');
|
|
226
238
|
const frame = clock.tick % FRAMES.length;
|
|
227
239
|
const ramp = shimmerRamp(accent);
|
|
228
240
|
const base = shimmerBase(accent);
|
|
229
241
|
// The shimmer tip sweeps across every char, then sits in a "pause" region past
|
|
230
|
-
// the end of the label where no char is highlighted, before looping.
|
|
231
|
-
|
|
232
|
-
const
|
|
233
|
-
const pos = Math.floor((clock.tick - clock.since) / SHIMMER_STEP) % cycle;
|
|
242
|
+
// the end of the label where no char is highlighted, before looping.
|
|
243
|
+
cycleRef.current = chars.length + SHIMMER_PAUSE;
|
|
244
|
+
const pos = clock.sweep;
|
|
234
245
|
return (_jsxs(Box, { marginTop: 1, children: [_jsx(Text, { color: accent, children: FRAMES[frame] }), _jsx(Text, { color: theme.muted, children: " " }), chalk.level === 1 ? _jsx(Text, { color: accent, children: chars.join('') }) : null, chalk.level === 1
|
|
235
246
|
? null
|
|
236
247
|
: chars.map((ch, i) => {
|
package/dist/ui/format.js
CHANGED
|
@@ -17,6 +17,29 @@ export function formatElapsed(seconds) {
|
|
|
17
17
|
export function formatDurationMs(ms) {
|
|
18
18
|
return formatElapsed(Math.round(ms / 1000));
|
|
19
19
|
}
|
|
20
|
+
// Below both, the label would flash past on an ordinary append round.
|
|
21
|
+
const PREFILL_LABEL_MIN_TOKENS = 2048;
|
|
22
|
+
const PREFILL_LABEL_MIN_MS = 2000;
|
|
23
|
+
// `Processing context 41% · ~30s left` while a local engine prefills (#912), or undefined when the wait
|
|
24
|
+
// is too short to name. Over the uncached work, because `processed/total` opens at 98% on a round
|
|
25
|
+
// that reuses the cache. The estimate is this request's own rate, and appears once a batch is done.
|
|
26
|
+
export function prefillLabel(progress) {
|
|
27
|
+
if (!progress)
|
|
28
|
+
return undefined;
|
|
29
|
+
const work = progress.total - progress.cached;
|
|
30
|
+
const done = Math.min(Math.max(progress.processed - progress.cached, 0), work);
|
|
31
|
+
if (work <= 0)
|
|
32
|
+
return undefined;
|
|
33
|
+
const remainingMs = done > 0 && progress.elapsedMs > 0 ? (work - done) * (progress.elapsedMs / done) : undefined;
|
|
34
|
+
const projectedMs = remainingMs === undefined ? 0 : progress.elapsedMs + remainingMs;
|
|
35
|
+
if (work < PREFILL_LABEL_MIN_TOKENS && projectedMs < PREFILL_LABEL_MIN_MS)
|
|
36
|
+
return undefined;
|
|
37
|
+
const percent = Math.floor((done / work) * 100);
|
|
38
|
+
const estimate = remainingMs !== undefined && remainingMs >= PREFILL_LABEL_MIN_MS
|
|
39
|
+
? ` · ~${formatDurationMs(remainingMs)} left`
|
|
40
|
+
: '';
|
|
41
|
+
return `Processing context ${percent}%${estimate}`;
|
|
42
|
+
}
|
|
20
43
|
// Compact token counts: `999`, `1.2k`, `126k`, `1.3M`, `2.5B`. Lives here rather than in the
|
|
21
44
|
// status bar because the saved transcript's header quotes the same numbers (issue #199), and the
|
|
22
45
|
// two must not drift.
|
package/dist/ui/layout.js
CHANGED
|
@@ -84,6 +84,12 @@ export function wrapStyledRows(text, width, trim = false) {
|
|
|
84
84
|
return lead + row + close;
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
+
// trim:false leaves the space wrap-ansi broke on at the head of a continuation row, one column
|
|
88
|
+
// right of the block's edge. A style can open ahead of it. Never for a row that starts a real line,
|
|
89
|
+
// whose leading whitespace is content.
|
|
90
|
+
export function dropWrapWhitespace(row) {
|
|
91
|
+
return row.replace(/^((?:\x1b\[[0-9;]*m)*) +/, '$1');
|
|
92
|
+
}
|
|
87
93
|
// The styled text whose plain characters are `[start, end)`, opening with the styles active at
|
|
88
94
|
// `start` and closing what is still open at `end`, so the slice stands on its own. Lets a caller
|
|
89
95
|
// style a whole line in one pass and cut it afterwards: a fragment styled alone loses its context,
|