@alexwkleung/reika 0.4.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 +3 -3
- package/README.zh-CN.md +20 -20
- package/dist/agent/loop.js +35 -3
- package/dist/agent/shellruns.js +81 -0
- package/dist/approval.js +6 -0
- package/dist/cli.js +3 -0
- package/dist/config.js +2 -1
- package/dist/debug.js +135 -16
- package/dist/headlessargs.js +1 -1
- package/dist/provider/transport.js +13 -1
- package/dist/search/_chrome.js +92 -19
- package/dist/search/cdp.js +6 -1
- package/dist/store/sessions.js +5 -4
- package/dist/tools/_danger.js +383 -38
- package/dist/tools/_heredoc.js +22 -8
- package/dist/tools/_readonly.js +132 -4
- package/dist/tools/_writetargets.js +3 -6
- package/dist/tools/bash.js +2 -1
- package/dist/ui/App.js +109 -18
- package/dist/ui/Approval.js +15 -5
- package/dist/ui/Scrollback.js +9 -3
- package/dist/ui/framedrops.js +34 -0
- package/dist/ui/harnessecho.js +24 -0
- package/dist/ui/reasoningfold.js +8 -1
- package/dist/ui/syncframe.js +7 -2
- package/package.json +1 -1
package/dist/tools/_readonly.js
CHANGED
|
@@ -256,11 +256,115 @@ const MAX_OPERANDS = { uniq: 1 };
|
|
|
256
256
|
// ladder scores as "not inspection" is one it lets a withdrawn model keep circling on.
|
|
257
257
|
const VALUE_FLAGS = { uniq: new Set(['-f', '-s', '-w']) };
|
|
258
258
|
// Split into words the way the shell does, keeping a quoted run with spaces in it as ONE word, then
|
|
259
|
-
//
|
|
260
|
-
// `find . '-delete'` must be seen as the flag it is
|
|
261
|
-
|
|
259
|
+
// remove the quoting the way the shell does. Quoting changes nothing about how a command reads its
|
|
260
|
+
// own arguments, so `find . '-delete'` must be seen as the flag it is — and so must `-de\lete`,
|
|
261
|
+
// `\" -delete \"` and `$'\x2ddelete'`. Every reader that decides on these words is an allowlist
|
|
262
|
+
// (plan mode's read-only bash, the sandbox's network allow), so a word read differently from the
|
|
263
|
+
// shell is a flag the allowlist never saw: the first cut ignored backslashes, which joined
|
|
264
|
+
// `\" -delete \"` into one quoted word, and dropped quote characters without decoding `$'…'`.
|
|
265
|
+
export const WORD_RE = /(?:\$'(?:[^'\\]|\\[\s\S])*'|\$?"(?:[^"\\]|\\[\s\S])*"|'[^']*'|\\[\s\S]?|[^\s'"\\])+/g;
|
|
262
266
|
export function words(segment) {
|
|
263
|
-
return (segment.match(WORD_RE) ?? []).map(
|
|
267
|
+
return (segment.match(WORD_RE) ?? []).map(dequote);
|
|
268
|
+
}
|
|
269
|
+
// What a backslash keeps its meaning before inside `"…"`; before anything else it is literal there.
|
|
270
|
+
const DOUBLE_QUOTE_ESCAPES = '$`"\\\n';
|
|
271
|
+
const ANSI_C_ESCAPES = {
|
|
272
|
+
a: '\x07',
|
|
273
|
+
b: '\b',
|
|
274
|
+
e: '\x1b',
|
|
275
|
+
E: '\x1b',
|
|
276
|
+
f: '\f',
|
|
277
|
+
n: '\n',
|
|
278
|
+
r: '\r',
|
|
279
|
+
t: '\t',
|
|
280
|
+
v: '\v',
|
|
281
|
+
'\\': '\\',
|
|
282
|
+
"'": "'",
|
|
283
|
+
'"': '"',
|
|
284
|
+
'?': '?',
|
|
285
|
+
};
|
|
286
|
+
export function dequote(word) {
|
|
287
|
+
let out = '';
|
|
288
|
+
let i = 0;
|
|
289
|
+
while (i < word.length) {
|
|
290
|
+
const c = word[i];
|
|
291
|
+
if (c === '\\') {
|
|
292
|
+
// A backslash-newline is a line continuation and disappears; a trailing one is literal.
|
|
293
|
+
const next = word[i + 1];
|
|
294
|
+
if (next === undefined)
|
|
295
|
+
out += '\\';
|
|
296
|
+
else if (next !== '\n')
|
|
297
|
+
out += next;
|
|
298
|
+
i += 2;
|
|
299
|
+
}
|
|
300
|
+
else if (c === "'") {
|
|
301
|
+
const end = word.indexOf("'", i + 1);
|
|
302
|
+
out += word.slice(i + 1, end < 0 ? word.length : end);
|
|
303
|
+
i = end < 0 ? word.length : end + 1;
|
|
304
|
+
}
|
|
305
|
+
else if (c === '$' && word[i + 1] === "'") {
|
|
306
|
+
i = readAnsiC(word, i + 2, s => (out += s));
|
|
307
|
+
}
|
|
308
|
+
else if (c === '$' && word[i + 1] === '"') {
|
|
309
|
+
i++;
|
|
310
|
+
}
|
|
311
|
+
else if (c === '"') {
|
|
312
|
+
i++;
|
|
313
|
+
while (i < word.length && word[i] !== '"') {
|
|
314
|
+
if (word[i] === '\\' && DOUBLE_QUOTE_ESCAPES.includes(word[i + 1] ?? '')) {
|
|
315
|
+
if (word[i + 1] !== '\n')
|
|
316
|
+
out += word[i + 1];
|
|
317
|
+
i += 2;
|
|
318
|
+
}
|
|
319
|
+
else
|
|
320
|
+
out += word[i++];
|
|
321
|
+
}
|
|
322
|
+
i++;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
out += c;
|
|
326
|
+
i++;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return out;
|
|
330
|
+
}
|
|
331
|
+
// Bash's `$'…'` escapes, decoded so `$'\x2ddelete'` reads as the `-delete` it is.
|
|
332
|
+
function readAnsiC(word, start, emit) {
|
|
333
|
+
let i = start;
|
|
334
|
+
while (i < word.length && word[i] !== "'") {
|
|
335
|
+
if (word[i] !== '\\') {
|
|
336
|
+
emit(word[i++]);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const next = word[i + 1] ?? '';
|
|
340
|
+
const rest = word.slice(i + 2);
|
|
341
|
+
const hex = (max) => new RegExp(`^[0-9a-fA-F]{1,${max}}`).exec(rest)?.[0];
|
|
342
|
+
if (next in ANSI_C_ESCAPES) {
|
|
343
|
+
emit(ANSI_C_ESCAPES[next]);
|
|
344
|
+
i += 2;
|
|
345
|
+
}
|
|
346
|
+
else if (/[0-7]/.test(next)) {
|
|
347
|
+
const digits = /^[0-7]{1,3}/.exec(word.slice(i + 1))[0];
|
|
348
|
+
emit(String.fromCharCode(parseInt(digits, 8) & 0xff));
|
|
349
|
+
i += 1 + digits.length;
|
|
350
|
+
}
|
|
351
|
+
else if ((next === 'x' || next === 'u' || next === 'U') &&
|
|
352
|
+
hex(next === 'x' ? 2 : next === 'u' ? 4 : 8)) {
|
|
353
|
+
const digits = hex(next === 'x' ? 2 : next === 'u' ? 4 : 8);
|
|
354
|
+
const code = parseInt(digits, 16);
|
|
355
|
+
emit(code <= 0x10ffff ? String.fromCodePoint(code) : '');
|
|
356
|
+
i += 2 + digits.length;
|
|
357
|
+
}
|
|
358
|
+
else if (next === 'c' && i + 2 < word.length) {
|
|
359
|
+
emit(String.fromCharCode(word.charCodeAt(i + 2) & 0x1f));
|
|
360
|
+
i += 3;
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
emit('\\' + next);
|
|
364
|
+
i += 2;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return i + 1;
|
|
264
368
|
}
|
|
265
369
|
// The carrier that bounds ONE command and changes nothing else about it, skipped so both readers see
|
|
266
370
|
// the command itself. `timeout 120 gh issue view 621 --json title,body` is the shape a model writes
|
|
@@ -370,6 +474,30 @@ export function maskQuoted(command) {
|
|
|
370
474
|
return command;
|
|
371
475
|
return blankSpans(command, scan.spans, () => true);
|
|
372
476
|
}
|
|
477
|
+
// `maskQuoted` with the command text inside quotes given back: a `$(…)` or a backtick inside `"…"`
|
|
478
|
+
// runs, separators and all, while one inside `'…'` is a character. An escaped character is data too,
|
|
479
|
+
// so `make \`-newline-`install` stays one command and `a\;` ends nothing. For a reader that asks where
|
|
480
|
+
// the shell's own separators are. Regions apply outermost first, so an inner one decides its text.
|
|
481
|
+
export function maskShellData(command) {
|
|
482
|
+
const scan = scanQuotes(command);
|
|
483
|
+
if (scan.uncertain)
|
|
484
|
+
return command;
|
|
485
|
+
const regions = [
|
|
486
|
+
...scan.spans.map(s => ({ start: s.start, end: s.end, data: true })),
|
|
487
|
+
...scan.substitutions.map(s => ({ start: s.start, end: s.end, data: false })),
|
|
488
|
+
].sort((a, b) => a.start - b.start || b.end - a.end);
|
|
489
|
+
const out = command.split('');
|
|
490
|
+
for (const r of regions) {
|
|
491
|
+
for (let i = r.start; i < r.end; i++)
|
|
492
|
+
out[i] = r.data ? ' ' : command[i];
|
|
493
|
+
}
|
|
494
|
+
for (const i of scan.escapes) {
|
|
495
|
+
out[i] = ' ';
|
|
496
|
+
if (i + 1 < out.length)
|
|
497
|
+
out[i + 1] = ' ';
|
|
498
|
+
}
|
|
499
|
+
return out.join('');
|
|
500
|
+
}
|
|
373
501
|
// Cut the command at every separator that sits OUTSIDE quotes, returning each segment's RAW text —
|
|
374
502
|
// a search pattern like "a;b" carries separators that are data, not syntax, so the split walks the
|
|
375
503
|
// mask while the slices come from the original.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolve } from 'node:path';
|
|
2
2
|
import { stripHeredocs } from './_heredoc.js';
|
|
3
|
-
import { WORD_RE, maskQuoted, splitSegments } from './_readonly.js';
|
|
3
|
+
import { WORD_RE, dequote, maskQuoted, splitSegments } from './_readonly.js';
|
|
4
4
|
// The files a shell command names as things it will write — the fallback change detector for a
|
|
5
5
|
// project with no git (#278). Best-effort by construction: it sees the shapes a model reaches for
|
|
6
6
|
// when it edits through the shell (a heredoc or `echo` into a redirect, `sed -i`, `tee`, `cp`/`mv`,
|
|
@@ -23,12 +23,12 @@ export function writeTargets(command, cwd) {
|
|
|
23
23
|
// not. `>&1`-style descriptor dups name no file.
|
|
24
24
|
const m = REDIRECT_WORD_RE.exec(rawWords[i]);
|
|
25
25
|
if (m) {
|
|
26
|
-
const target =
|
|
26
|
+
const target = dequote(m[1] || rawWords[++i] || '');
|
|
27
27
|
if (target && !target.startsWith('&'))
|
|
28
28
|
targets.push(target);
|
|
29
29
|
continue;
|
|
30
30
|
}
|
|
31
|
-
const w =
|
|
31
|
+
const w = dequote(rawWords[i]);
|
|
32
32
|
if (w !== '')
|
|
33
33
|
bare.push(w);
|
|
34
34
|
}
|
|
@@ -52,9 +52,6 @@ export function writeTargets(command, cwd) {
|
|
|
52
52
|
}
|
|
53
53
|
// `&` is a segment separator, so `&>f` arrives as a segment starting with `>f`.
|
|
54
54
|
const REDIRECT_WORD_RE = /^\d?>>?(.*)$/;
|
|
55
|
-
function unquote(word) {
|
|
56
|
-
return word.replace(/['"]/g, '');
|
|
57
|
-
}
|
|
58
55
|
// Files a command writes by its own convention, from its operands.
|
|
59
56
|
function commandTargets(name, args) {
|
|
60
57
|
const operands = [];
|
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
3
|
import { Box, Static, Text, useApp, useInput } from 'ink';
|
|
4
|
-
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
5
5
|
import { homedir } from 'node:os';
|
|
6
6
|
import { Splash } from './Splash.js';
|
|
7
7
|
import { Scrollback } from './Scrollback.js';
|
|
@@ -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 } 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';
|
|
@@ -50,6 +51,7 @@ import { buildSummary, hasActivity } from './summary.js';
|
|
|
50
51
|
import { QueuedList } from './QueuedList.js';
|
|
51
52
|
import { queueReceipt } from './queue.js';
|
|
52
53
|
import { expandPastes, rememberPaste } from './pastes.js';
|
|
54
|
+
import { buildShellRunsBlock, captureShellRun, holdShellRun, shellRunBudget, } from '../agent/shellruns.js';
|
|
53
55
|
import { invokeMcpTool, parseMcpArgs } from '../mcp/tools.js';
|
|
54
56
|
// How long the "Typechecking" indicator lingers after a check settles, so a sub-second warm check
|
|
55
57
|
// still reads. Long enough to perceive, short enough not to imply the check is still running.
|
|
@@ -140,6 +142,8 @@ export function App() {
|
|
|
140
142
|
const [decodeRate, setDecodeRate] = useState(undefined);
|
|
141
143
|
const [pending, setPending] = useState(null);
|
|
142
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);
|
|
143
147
|
// An `ask_user` question waiting on the user (#198). Modal like Approval, with one difference: the
|
|
144
148
|
// input box stays LIVE underneath once `questionTyping` is set, because the free-text row hands the
|
|
145
149
|
// answer to Input rather than to a field rebuilt in the dialog.
|
|
@@ -188,6 +192,8 @@ export function App() {
|
|
|
188
192
|
// input buffer. Ref-held: the buffer's marker is the visible state, this is just its payload,
|
|
189
193
|
// and re-rendering on paste would fight the Input's own cursor bookkeeping.
|
|
190
194
|
const imageAttachmentsRef = useRef([]);
|
|
195
|
+
// Shell-mode runs since the last prompt, prepended to the next one (agent/shellruns.ts).
|
|
196
|
+
const heldShellRunsRef = useRef([]);
|
|
191
197
|
// Text from pastes too large to sit in the input buffer, keyed by the `[Pasted text #N +412 lines]` marker
|
|
192
198
|
// holding its place there (ui/pastes.ts). Ref-held for the same reason as image attachments.
|
|
193
199
|
// Unlike them it is NOT consumed at submit: the marker is plain text the user can recall from
|
|
@@ -268,6 +274,8 @@ export function App() {
|
|
|
268
274
|
questionTypingRef.current = questionTyping;
|
|
269
275
|
const approvalSelectedRef = useRef(0);
|
|
270
276
|
approvalSelectedRef.current = approvalSelected;
|
|
277
|
+
const approvalTypingRef = useRef(false);
|
|
278
|
+
approvalTypingRef.current = approvalTyping;
|
|
271
279
|
const confirmRef = useRef(null);
|
|
272
280
|
confirmRef.current = confirm;
|
|
273
281
|
const confirmSelectedRef = useRef(CONFIRM_DECLINE);
|
|
@@ -310,6 +318,7 @@ export function App() {
|
|
|
310
318
|
// The file this session auto-saves to (#1), fixed at its first save so every later save rewrites
|
|
311
319
|
// one file. null until then, and again after /new, so a new conversation gets a new file.
|
|
312
320
|
const sessionPathRef = useRef(null);
|
|
321
|
+
const sessionStemClaimedRef = useRef(false);
|
|
313
322
|
const autosaveTimerRef = useRef(null);
|
|
314
323
|
// Writes run one after another: two in flight could rename out of order and leave the older
|
|
315
324
|
// snapshot on disk.
|
|
@@ -645,6 +654,14 @@ export function App() {
|
|
|
645
654
|
useInput((input, key) => {
|
|
646
655
|
if (key.ctrl && input === 'c') {
|
|
647
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
|
+
}
|
|
648
665
|
// Interrupt anything in flight: decline a pending approval, drop an unanswered question,
|
|
649
666
|
// abort a turn.
|
|
650
667
|
if (hadPending) {
|
|
@@ -715,16 +732,26 @@ export function App() {
|
|
|
715
732
|
return;
|
|
716
733
|
}
|
|
717
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;
|
|
718
738
|
if (key.upArrow) {
|
|
719
739
|
setApprovalSelected(i => Math.max(0, i - 1));
|
|
720
740
|
return;
|
|
721
741
|
}
|
|
722
742
|
if (key.downArrow) {
|
|
723
|
-
setApprovalSelected(i => Math.min(
|
|
743
|
+
setApprovalSelected(i => Math.min(APPROVAL_OPTIONS.length - 1, i + 1));
|
|
724
744
|
return;
|
|
725
745
|
}
|
|
726
746
|
if (key.return) {
|
|
727
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
|
+
}
|
|
728
755
|
const resolve = pendingRef.current.resolve;
|
|
729
756
|
setPending(null);
|
|
730
757
|
if (sel === 0)
|
|
@@ -968,6 +995,10 @@ export function App() {
|
|
|
968
995
|
? { agent: stash.agent ?? [], chat: messagesRef.current }
|
|
969
996
|
: { agent: messagesRef.current, chat: stash.chat ?? [] };
|
|
970
997
|
};
|
|
998
|
+
// The basename only: enough to find the transcript under history/, no home path in the log.
|
|
999
|
+
const logSessionFile = (path) => {
|
|
1000
|
+
debugLog(`[reika:debug] session file=${basename(path)}`);
|
|
1001
|
+
};
|
|
971
1002
|
const autosaveNow = () => {
|
|
972
1003
|
if (autosaveTimerRef.current !== null) {
|
|
973
1004
|
clearTimeout(autosaveTimerRef.current);
|
|
@@ -982,7 +1013,14 @@ export function App() {
|
|
|
982
1013
|
if (turns === 0 || turns <= (autosaveHoldRef.current ?? 0))
|
|
983
1014
|
return autosaveChainRef.current;
|
|
984
1015
|
autosaveHoldRef.current = null;
|
|
985
|
-
sessionPathRef.current
|
|
1016
|
+
if (sessionPathRef.current === null) {
|
|
1017
|
+
// The process's first transcript shares the debug log's name (#761); a later /new gets its
|
|
1018
|
+
// own, and the log line below is what pairs it.
|
|
1019
|
+
const stem = sessionStemClaimedRef.current ? undefined : processSessionStem();
|
|
1020
|
+
sessionStemClaimedRef.current = true;
|
|
1021
|
+
sessionPathRef.current = newSessionPath(projectHistoryDir(bundle.cwd), new Date(), stem);
|
|
1022
|
+
logSessionFile(sessionPathRef.current);
|
|
1023
|
+
}
|
|
986
1024
|
const path = sessionPathRef.current;
|
|
987
1025
|
const meta = transcriptMeta(sides.agent, bundle.cwd, statusRef.current === 'busy');
|
|
988
1026
|
autosaveChainRef.current = autosaveChainRef.current
|
|
@@ -1063,8 +1101,10 @@ export function App() {
|
|
|
1063
1101
|
resetConversation();
|
|
1064
1102
|
// A project session carries on in its own file; a manual save from the root is left as it was
|
|
1065
1103
|
// and the continuation gets a project file of its own on its next save.
|
|
1066
|
-
if (dirname(entry.path) === projectDir)
|
|
1104
|
+
if (dirname(entry.path) === projectDir) {
|
|
1067
1105
|
sessionPathRef.current = entry.path;
|
|
1106
|
+
logSessionFile(entry.path);
|
|
1107
|
+
}
|
|
1068
1108
|
autosaveHoldRef.current = countRealTurns(sides.agent) + countRealTurns(sides.chat);
|
|
1069
1109
|
const inChat = modeRef.current === 'chat';
|
|
1070
1110
|
const active = inChat ? sides.chat : sides.agent;
|
|
@@ -1157,10 +1197,11 @@ export function App() {
|
|
|
1157
1197
|
return Promise.resolve(false);
|
|
1158
1198
|
}
|
|
1159
1199
|
setApprovalSelected(0);
|
|
1200
|
+
setApprovalTyping(false);
|
|
1160
1201
|
return new Promise(resolve => {
|
|
1161
|
-
const wrappedResolve = (
|
|
1162
|
-
setApprovals(a =>
|
|
1163
|
-
resolve(
|
|
1202
|
+
const wrappedResolve = (answer) => {
|
|
1203
|
+
setApprovals(a => answer === true ? { ...a, approved: a.approved + 1 } : { ...a, declined: a.declined + 1 });
|
|
1204
|
+
resolve(answer);
|
|
1164
1205
|
};
|
|
1165
1206
|
setPending({ request: req, resolve: wrappedResolve });
|
|
1166
1207
|
});
|
|
@@ -1255,6 +1296,7 @@ export function App() {
|
|
|
1255
1296
|
// may be a different model on different hardware (#204): the tok/s chip goes with the token
|
|
1256
1297
|
// counts it sits next to.
|
|
1257
1298
|
resetConversation(true);
|
|
1299
|
+
heldShellRunsRef.current = [];
|
|
1258
1300
|
sessionRef.current?.switchSide('agent');
|
|
1259
1301
|
setDecodeRate(undefined);
|
|
1260
1302
|
setApprovals({ approved: 0, declined: 0 });
|
|
@@ -1748,8 +1790,8 @@ export function App() {
|
|
|
1748
1790
|
const runShell = async (command) => {
|
|
1749
1791
|
if (!bundle)
|
|
1750
1792
|
return;
|
|
1751
|
-
// Shell mode is "raw bash, no model" — the
|
|
1752
|
-
//
|
|
1793
|
+
// Shell mode is "raw bash, no model" — the echo and the `shell` message below are UI-only. The
|
|
1794
|
+
// model sees the run through the held copy, attached to the next prompt.
|
|
1753
1795
|
const echo = { role: 'user', content: command, meta: true };
|
|
1754
1796
|
setMessages(prev => [...prev, echo]);
|
|
1755
1797
|
setStatus('busy');
|
|
@@ -1777,6 +1819,7 @@ export function App() {
|
|
|
1777
1819
|
output: result.payload ?? '',
|
|
1778
1820
|
};
|
|
1779
1821
|
setMessages(prev => [...prev, shellMsg]);
|
|
1822
|
+
heldShellRunsRef.current = holdShellRun(heldShellRunsRef.current, await captureShellRun(command, result.exitCode ?? null, result.payload ?? ''));
|
|
1780
1823
|
}
|
|
1781
1824
|
catch (e) {
|
|
1782
1825
|
setMessages(prev => [...prev, { role: 'error', content: e.message }]);
|
|
@@ -2050,6 +2093,20 @@ export function App() {
|
|
|
2050
2093
|
// An answer being typed for `ask_user` — not a message for the model. Intercepted ahead of the
|
|
2051
2094
|
// busy-queue branch below: a question only exists mid-turn, so every such submit would otherwise
|
|
2052
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
|
+
}
|
|
2053
2110
|
const q = questionRef.current;
|
|
2054
2111
|
const typing = questionTypingRef.current;
|
|
2055
2112
|
if (q && typing) {
|
|
@@ -2223,6 +2280,13 @@ export function App() {
|
|
|
2223
2280
|
// request to fetch a link inside it. The marker survives in `display`, keeping the user
|
|
2224
2281
|
// bubble (and the input history entry) short while the model gets the full text.
|
|
2225
2282
|
modelText = expandPastes(modelText, pastedTextsRef.current);
|
|
2283
|
+
// Chat's history is its own, and its tools could not act on a run anyway: held for the
|
|
2284
|
+
// agent side.
|
|
2285
|
+
if (heldShellRunsRef.current.length > 0 && modeRef.current !== 'chat') {
|
|
2286
|
+
const budget = shellRunBudget(sessionRef.current?.config.contextWindow);
|
|
2287
|
+
modelText = `${buildShellRunsBlock(heldShellRunsRef.current, budget)}\n\n${modelText}`;
|
|
2288
|
+
heldShellRunsRef.current = [];
|
|
2289
|
+
}
|
|
2226
2290
|
}
|
|
2227
2291
|
finally {
|
|
2228
2292
|
setExpanding(null);
|
|
@@ -2481,6 +2545,28 @@ export function App() {
|
|
|
2481
2545
|
if (status === 'error') {
|
|
2482
2546
|
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "Error" }), _jsx(Text, { children: error })] }));
|
|
2483
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
|
+
}
|
|
2484
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',
|
|
2485
2571
|
// Hidden while a dialog is up: the approval a tool asks for happens *inside* the call
|
|
2486
2572
|
// (after the loop announced it), so an "Editing…" row behind the prompt would name work
|
|
@@ -2515,7 +2601,7 @@ export function App() {
|
|
|
2515
2601
|
? theme.warning
|
|
2516
2602
|
: subagentLive
|
|
2517
2603
|
? theme.subagent
|
|
2518
|
-
: 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 &&
|
|
2519
2605
|
config.subagentModel !== (config.profiles[activeProfile]?.model ?? config.model)
|
|
2520
2606
|
? config.subagentModel
|
|
2521
2607
|
: undefined })) : resumeSelect ? (_jsx(ResumeSelect, { entries: resumeSelect.entries, selectedIndex: resumeSelected, heading: resumeSelect.heading })) : confirm ? (_jsx(Confirm, { spec: confirm.spec, selectedIndex: confirmSelected })) : null, _jsx(Input
|
|
@@ -2524,7 +2610,7 @@ export function App() {
|
|
|
2524
2610
|
, {
|
|
2525
2611
|
// The question dialog is modal only while its list is up; once the user is typing an
|
|
2526
2612
|
// answer the input has to be live, since it IS the answer field.
|
|
2527
|
-
disabled: pending !== null ||
|
|
2613
|
+
disabled: (pending !== null && !approvalTyping) ||
|
|
2528
2614
|
modelSelect !== null ||
|
|
2529
2615
|
resumeSelect !== null ||
|
|
2530
2616
|
confirm !== null ||
|
|
@@ -2534,11 +2620,16 @@ export function App() {
|
|
|
2534
2620
|
resumeSelect !== null ||
|
|
2535
2621
|
confirm !== null, attachedBelow: suggestionState !== null, reservedRows: question
|
|
2536
2622
|
? questionDialogHeight(question.request, questionTyping, dialogReservedRows)
|
|
2537
|
-
: 0, suggesting: !!suggestionState && suggestionState.items.length > 0, history: inputHistory, mode: mode, value: inputValue, onChange: onInputChange, onSubmit: onSubmit, onPasteImage: onPasteImageSafely, onPasteText: onPasteText, placeholder:
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
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'
|
|
2542
2633
|
? 'bypass'
|
|
2543
2634
|
: effectiveAutoApprove(config, sessionAutoApprove) === 'safe'
|
|
2544
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
|
@@ -12,7 +12,8 @@ import { scrubDisplay, scrubOutput } from './scrub.js';
|
|
|
12
12
|
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
|
-
import {
|
|
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
|
|
@@ -29,7 +30,7 @@ export function Scrollback({ messages, streaming, streamingReasoning, streamingT
|
|
|
29
30
|
// and whose block is sized for that aside's shape.
|
|
30
31
|
const folded = streamingNote
|
|
31
32
|
? { reasoning: streamingReasoning, content: streaming }
|
|
32
|
-
:
|
|
33
|
+
: foldedLiveFields(streamingReasoning, streaming);
|
|
33
34
|
// Each block's fixed rows: its marginTop, plus the reasoning block's "Thinking" label. The block
|
|
34
35
|
// builders are the memoized ones: a render where this block's text (or width, or the terminal's
|
|
35
36
|
// columns) is unchanged reuses the rows it built last time instead of re-parsing the same text.
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// A model reads its own earlier `content` as its own voice, and a carried continuation tail (#284)
|
|
2
|
+
// puts reika's marker there: `[reika: N chars of your earlier reasoning trimmed …]`. A verbose model
|
|
3
|
+
// then opens a LATER reply the same way — observed on mimo-v2.6-pro (#745): a reply with its own
|
|
4
|
+
// tool call opening with `[reika: 26476 chars …]` (the harness had written 26465) and an invented
|
|
5
|
+
// `[tool result omitted: repeated from earlier]`, a stub reika never emits. Both rendered as the
|
|
6
|
+
// answer. So the match is on the shape, not on reika's exact strings: the copy is never exact.
|
|
7
|
+
//
|
|
8
|
+
// Head only, line by line: that is where the tail template puts the marker, and further down the
|
|
9
|
+
// same text is just as likely the model quoting reika's markers on purpose (a review of this code).
|
|
10
|
+
// Display/transcript only, like the reasoning fold — the Message the loop keeps and sends back is
|
|
11
|
+
// untouched.
|
|
12
|
+
const HARNESS_ECHO_LINE = /^\s*(?:\[reika:[^\]\n]*\]|\(reika:[^)\n]*\)|\[tool (?:result|output)[^\]\n]*\])\s*$/;
|
|
13
|
+
export function stripHarnessEcho(content) {
|
|
14
|
+
let rest = content;
|
|
15
|
+
for (;;) {
|
|
16
|
+
const lead = rest.match(/^\s*/)[0].length;
|
|
17
|
+
const nl = rest.indexOf('\n', lead);
|
|
18
|
+
const line = nl < 0 ? rest : rest.slice(0, nl);
|
|
19
|
+
if (!line.trim() || !HARNESS_ECHO_LINE.test(line))
|
|
20
|
+
break;
|
|
21
|
+
rest = nl < 0 ? '' : rest.slice(nl + 1);
|
|
22
|
+
}
|
|
23
|
+
return rest === content ? content : rest.trimStart();
|
|
24
|
+
}
|