@alexwkleung/reika 0.5.0 → 0.7.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/bashread.js +177 -0
- package/dist/agent/compaction.js +5 -0
- package/dist/agent/compactionreport.js +184 -0
- package/dist/agent/loop.js +191 -43
- package/dist/agent/noteslotmonitor.js +82 -0
- package/dist/agent/readtrace.js +18 -8
- package/dist/approval.js +6 -0
- package/dist/check/typecheck.js +29 -0
- package/dist/config.js +30 -17
- package/dist/context/bootstrap.js +3 -1
- package/dist/provider/client.js +15 -0
- package/dist/provider/latches.js +3 -0
- package/dist/provider/noteslot.js +239 -0
- package/dist/provider/templatekwargs.js +31 -0
- package/dist/provider/toolcall.js +22 -1
- package/dist/provider/transport.js +12 -9
- package/dist/search/_chrome.js +92 -19
- package/dist/search/cdp.js +6 -1
- package/dist/session.js +13 -1
- package/dist/tools/_danger.js +350 -45
- package/dist/tools/bash.js +2 -1
- package/dist/ui/App.js +111 -14
- package/dist/ui/Approval.js +15 -5
- package/dist/ui/Scrollback.js +7 -1
- package/dist/ui/commands.js +46 -0
- package/dist/ui/framedrops.js +34 -0
- package/dist/ui/syncframe.js +7 -2
- package/package.json +1 -1
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,13 +22,15 @@ 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';
|
|
29
30
|
import { compactThreshold } from '../agent/compaction.js';
|
|
30
31
|
import { createPrefixWarmer } from '../agent/warm.js';
|
|
31
32
|
import { execStream } from '../tools/bash.js';
|
|
33
|
+
import { isOffline } from '../tools/_net.js';
|
|
32
34
|
import { expandMentions } from '../agent/mentions.js';
|
|
33
35
|
import { attachImageBlocks, NATIVE_IMAGE_NOTE, readNativeAttachments, nextImageMarker, } from '../agent/attachments.js';
|
|
34
36
|
import { expandPastedUrls, planPastedUrls } from '../agent/pastedurls.js';
|
|
@@ -44,7 +46,7 @@ import { mcpStartupLine } from './format.js';
|
|
|
44
46
|
import { ResumeSelect } from './ResumeSelect.js';
|
|
45
47
|
import { countRealTurns, forAutosave, listSessions, loadSession, modelHistoryFromScrollback, newSessionPath, projectHistoryDir, ROOT_HISTORY_DIR, writeSession, } from '../store/sessions.js';
|
|
46
48
|
import { buildModelTargets } from './models.js';
|
|
47
|
-
import { buildImplementPrompt, IMPLEMENT_MODES, isImplementCommand, isMinimalPrompt, isGrindPrompt, isSaveCommand, nextMode, turnMode, turnPromptMode, turnRefines, turnTools, } from './commands.js';
|
|
49
|
+
import { buildImplementPrompt, buildSearchPrompt, IMPLEMENT_MODES, isImplementCommand, isMinimalPrompt, isGrindPrompt, isSaveCommand, nextMode, searchModeRefusal, searchUnavailableNotice, turnMode, turnPromptMode, turnRefines, turnTools, } from './commands.js';
|
|
48
50
|
import { acceptSuggestion, computeSuggestions } from './suggest.js';
|
|
49
51
|
import { buildSummary, hasActivity } from './summary.js';
|
|
50
52
|
import { QueuedList } from './QueuedList.js';
|
|
@@ -141,6 +143,8 @@ export function App() {
|
|
|
141
143
|
const [decodeRate, setDecodeRate] = useState(undefined);
|
|
142
144
|
const [pending, setPending] = useState(null);
|
|
143
145
|
const [approvalSelected, setApprovalSelected] = useState(0);
|
|
146
|
+
// Typing the reason for a decline: like `questionTyping`, the input box underneath is the field.
|
|
147
|
+
const [approvalTyping, setApprovalTyping] = useState(false);
|
|
144
148
|
// An `ask_user` question waiting on the user (#198). Modal like Approval, with one difference: the
|
|
145
149
|
// input box stays LIVE underneath once `questionTyping` is set, because the free-text row hands the
|
|
146
150
|
// answer to Input rather than to a field rebuilt in the dialog.
|
|
@@ -271,6 +275,8 @@ export function App() {
|
|
|
271
275
|
questionTypingRef.current = questionTyping;
|
|
272
276
|
const approvalSelectedRef = useRef(0);
|
|
273
277
|
approvalSelectedRef.current = approvalSelected;
|
|
278
|
+
const approvalTypingRef = useRef(false);
|
|
279
|
+
approvalTypingRef.current = approvalTyping;
|
|
274
280
|
const confirmRef = useRef(null);
|
|
275
281
|
confirmRef.current = confirm;
|
|
276
282
|
const confirmSelectedRef = useRef(CONFIRM_DECLINE);
|
|
@@ -649,6 +655,14 @@ export function App() {
|
|
|
649
655
|
useInput((input, key) => {
|
|
650
656
|
if (key.ctrl && input === 'c') {
|
|
651
657
|
const hadPending = pendingRef.current !== null;
|
|
658
|
+
// Typing a decline's reason: back out to the options, as the question's field does (#651).
|
|
659
|
+
// Nothing is decided yet, so neither the approval nor the turn may end here.
|
|
660
|
+
if (hadPending && approvalTypingRef.current) {
|
|
661
|
+
setInputValue(preAnswerDraftRef.current);
|
|
662
|
+
setSuggestionState(null);
|
|
663
|
+
setApprovalTyping(false);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
652
666
|
// Interrupt anything in flight: decline a pending approval, drop an unanswered question,
|
|
653
667
|
// abort a turn.
|
|
654
668
|
if (hadPending) {
|
|
@@ -719,16 +733,26 @@ export function App() {
|
|
|
719
733
|
return;
|
|
720
734
|
}
|
|
721
735
|
if (pendingRef.current) {
|
|
736
|
+
// Input owns the keyboard while the reason is typed; a key consumed here is a lost character.
|
|
737
|
+
if (approvalTypingRef.current)
|
|
738
|
+
return;
|
|
722
739
|
if (key.upArrow) {
|
|
723
740
|
setApprovalSelected(i => Math.max(0, i - 1));
|
|
724
741
|
return;
|
|
725
742
|
}
|
|
726
743
|
if (key.downArrow) {
|
|
727
|
-
setApprovalSelected(i => Math.min(
|
|
744
|
+
setApprovalSelected(i => Math.min(APPROVAL_OPTIONS.length - 1, i + 1));
|
|
728
745
|
return;
|
|
729
746
|
}
|
|
730
747
|
if (key.return) {
|
|
731
748
|
const sel = approvalSelectedRef.current;
|
|
749
|
+
if (sel === APPROVAL_FEEDBACK_INDEX) {
|
|
750
|
+
// Deferred like the question's field: enabling Input synchronously hands it this Enter.
|
|
751
|
+
preAnswerDraftRef.current = inputValueRef.current;
|
|
752
|
+
setInputValue('');
|
|
753
|
+
queueMicrotask(() => setApprovalTyping(true));
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
732
756
|
const resolve = pendingRef.current.resolve;
|
|
733
757
|
setPending(null);
|
|
734
758
|
if (sel === 0)
|
|
@@ -1174,10 +1198,11 @@ export function App() {
|
|
|
1174
1198
|
return Promise.resolve(false);
|
|
1175
1199
|
}
|
|
1176
1200
|
setApprovalSelected(0);
|
|
1201
|
+
setApprovalTyping(false);
|
|
1177
1202
|
return new Promise(resolve => {
|
|
1178
|
-
const wrappedResolve = (
|
|
1179
|
-
setApprovals(a =>
|
|
1180
|
-
resolve(
|
|
1203
|
+
const wrappedResolve = (answer) => {
|
|
1204
|
+
setApprovals(a => answer === true ? { ...a, approved: a.approved + 1 } : { ...a, declined: a.declined + 1 });
|
|
1205
|
+
resolve(answer);
|
|
1181
1206
|
};
|
|
1182
1207
|
setPending({ request: req, resolve: wrappedResolve });
|
|
1183
1208
|
});
|
|
@@ -1386,6 +1411,36 @@ export function App() {
|
|
|
1386
1411
|
undefined, mode === 'vibe' ? 'agent' : undefined, undefined, true);
|
|
1387
1412
|
return;
|
|
1388
1413
|
}
|
|
1414
|
+
if (name === 'search') {
|
|
1415
|
+
// `/search <query>` (#829): the direct road to the search tool. A mode's own prompt says to
|
|
1416
|
+
// use `search` only when the answer needs current information, which leaves the decision to
|
|
1417
|
+
// the model; this makes it the user's. Availability is read off the session's own tool lists
|
|
1418
|
+
// rather than re-derived from config, so it agrees with the offline case too — that one is
|
|
1419
|
+
// decided once at startup (`opts.offline` in tools/index.ts) and never revisited.
|
|
1420
|
+
const query = args.trim();
|
|
1421
|
+
const say = (content) => setMessages(prev => [...prev, echo, { role: 'system', content }]);
|
|
1422
|
+
if (!query) {
|
|
1423
|
+
say('Usage: /search <query> — the model runs one web search and answers from the results.');
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
const refusal = searchModeRefusal(mode);
|
|
1427
|
+
if (refusal) {
|
|
1428
|
+
say(refusal);
|
|
1429
|
+
return;
|
|
1430
|
+
}
|
|
1431
|
+
// Vibe plans before it acts, and a search is a question, not a task: it runs as an agent turn,
|
|
1432
|
+
// the same one-turn override /implement and /compact take out of vibe.
|
|
1433
|
+
const target = mode === 'vibe' ? 'agent' : mode;
|
|
1434
|
+
const lists = sessionRef.current?.lists;
|
|
1435
|
+
if (!lists || !turnTools(target, lists).some(t => t.name === 'search')) {
|
|
1436
|
+
say(searchUnavailableNotice(isOffline()));
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
// No echo of its own, like a skill: runTurn emits the user message, rendered from `raw`, so
|
|
1440
|
+
// the bubble reads `/search react 19` while the model receives the instructions.
|
|
1441
|
+
await submitToModel(buildSearchPrompt(query), raw, target === mode ? undefined : target);
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1389
1444
|
if (name === 'cd') {
|
|
1390
1445
|
const target = args.trim();
|
|
1391
1446
|
if (!target) {
|
|
@@ -1522,6 +1577,7 @@ export function App() {
|
|
|
1522
1577
|
' /skills list available skills (loaded from your skill directories)',
|
|
1523
1578
|
' /mcp list MCP servers and their tools (REIKA_MCP_SERVERS)',
|
|
1524
1579
|
' /<server>:<tool> call an MCP tool directly (JSON args, or the bare string for a one-arg tool)',
|
|
1580
|
+
' /search <query> search the web: the model runs one search and answers from the results',
|
|
1525
1581
|
' /exit, /quit exit reika (prints summary)',
|
|
1526
1582
|
' @<path> in agent mode, inline a file as context',
|
|
1527
1583
|
' ctrl-v paste an image; its text is read out and attached (macOS/Windows)',
|
|
@@ -2069,6 +2125,20 @@ export function App() {
|
|
|
2069
2125
|
// An answer being typed for `ask_user` — not a message for the model. Intercepted ahead of the
|
|
2070
2126
|
// busy-queue branch below: a question only exists mid-turn, so every such submit would otherwise
|
|
2071
2127
|
// be queued as the user's next prompt.
|
|
2128
|
+
// A decline's reason, likewise not a message for the model's next turn. An empty one is not a
|
|
2129
|
+
// reason; the field stays open, and ctrl-c is the way back to a plain Decline.
|
|
2130
|
+
const ap = pendingRef.current;
|
|
2131
|
+
if (ap && approvalTypingRef.current) {
|
|
2132
|
+
const text = input.trim();
|
|
2133
|
+
if (!text)
|
|
2134
|
+
return;
|
|
2135
|
+
setInputValue(preAnswerDraftRef.current);
|
|
2136
|
+
setSuggestionState(null);
|
|
2137
|
+
setPending(null);
|
|
2138
|
+
setApprovalTyping(false);
|
|
2139
|
+
ap.resolve({ feedback: text });
|
|
2140
|
+
return;
|
|
2141
|
+
}
|
|
2072
2142
|
const q = questionRef.current;
|
|
2073
2143
|
const typing = questionTypingRef.current;
|
|
2074
2144
|
if (q && typing) {
|
|
@@ -2507,6 +2577,28 @@ export function App() {
|
|
|
2507
2577
|
if (status === 'error') {
|
|
2508
2578
|
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "Error" }), _jsx(Text, { children: error })] }));
|
|
2509
2579
|
}
|
|
2580
|
+
if (debugEnabled()) {
|
|
2581
|
+
const live = [
|
|
2582
|
+
streamingReasoning && 'reasoning',
|
|
2583
|
+
streaming && 'content',
|
|
2584
|
+
streamingTool && `tool:${streamingToolName}`,
|
|
2585
|
+
].filter(Boolean);
|
|
2586
|
+
const dialog = pending
|
|
2587
|
+
? 'approval'
|
|
2588
|
+
: question
|
|
2589
|
+
? 'question'
|
|
2590
|
+
: modelSelect
|
|
2591
|
+
? 'model'
|
|
2592
|
+
: resumeSelect
|
|
2593
|
+
? 'resume'
|
|
2594
|
+
: confirm
|
|
2595
|
+
? 'confirm'
|
|
2596
|
+
: '-';
|
|
2597
|
+
noteFrameState(`${status === 'busy' ? phase : status} msgs=${messages.length} live=${live.join(',') || '-'}` +
|
|
2598
|
+
` pending=${pendingTool || '-'} dialog=${dialog} queue=${queue.length}` +
|
|
2599
|
+
` plan=${planSteps ? planSteps.length : 0} suggest=${suggestionState ? 1 : 0}` +
|
|
2600
|
+
`${subagentLive ? ' subagent' : ''}`);
|
|
2601
|
+
}
|
|
2510
2602
|
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
2603
|
// Hidden while a dialog is up: the approval a tool asks for happens *inside* the call
|
|
2512
2604
|
// (after the loop announced it), so an "Editing…" row behind the prompt would name work
|
|
@@ -2541,7 +2633,7 @@ export function App() {
|
|
|
2541
2633
|
? theme.warning
|
|
2542
2634
|
: subagentLive
|
|
2543
2635
|
? 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 &&
|
|
2636
|
+
: 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
2637
|
config.subagentModel !== (config.profiles[activeProfile]?.model ?? config.model)
|
|
2546
2638
|
? config.subagentModel
|
|
2547
2639
|
: 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 +2642,7 @@ export function App() {
|
|
|
2550
2642
|
, {
|
|
2551
2643
|
// The question dialog is modal only while its list is up; once the user is typing an
|
|
2552
2644
|
// answer the input has to be live, since it IS the answer field.
|
|
2553
|
-
disabled: pending !== null ||
|
|
2645
|
+
disabled: (pending !== null && !approvalTyping) ||
|
|
2554
2646
|
modelSelect !== null ||
|
|
2555
2647
|
resumeSelect !== null ||
|
|
2556
2648
|
confirm !== null ||
|
|
@@ -2560,11 +2652,16 @@ export function App() {
|
|
|
2560
2652
|
resumeSelect !== null ||
|
|
2561
2653
|
confirm !== null, attachedBelow: suggestionState !== null, reservedRows: question
|
|
2562
2654
|
? 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
|
-
|
|
2655
|
+
: 0, suggesting: !!suggestionState && suggestionState.items.length > 0, history: inputHistory, mode: mode, value: inputValue, onChange: onInputChange, onSubmit: onSubmit, onPasteImage: onPasteImageSafely, onPasteText: onPasteText, placeholder:
|
|
2656
|
+
// A reason that should stop the model has to say so: "tell me the script" read as
|
|
2657
|
+
// run-then-tell and drew retries, "don't run anything" did not (decline-terse/-ask).
|
|
2658
|
+
approvalTyping
|
|
2659
|
+
? 'e.g. "use pnpm instead", or "don\'t run anything, just tell me …"'
|
|
2660
|
+
: mode === 'shell'
|
|
2661
|
+
? 'Run a shell command'
|
|
2662
|
+
: mode === 'vibe'
|
|
2663
|
+
? 'Describe a change — it plans first, then implements'
|
|
2664
|
+
: 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
2665
|
? 'bypass'
|
|
2569
2666
|
: effectiveAutoApprove(config, sessionAutoApprove) === 'safe'
|
|
2570
2667
|
? '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.
|
package/dist/ui/commands.js
CHANGED
|
@@ -111,6 +111,10 @@ export const COMMANDS = [
|
|
|
111
111
|
name: 'mcp',
|
|
112
112
|
desc: 'list MCP servers and their tools (each tool is also a /<server>:<tool> command)',
|
|
113
113
|
},
|
|
114
|
+
{
|
|
115
|
+
name: 'search',
|
|
116
|
+
desc: 'search the web for a query (needs a search provider; the model runs it and answers from the results)',
|
|
117
|
+
},
|
|
114
118
|
{ name: 'stats', desc: 'show full session summary' },
|
|
115
119
|
{
|
|
116
120
|
name: 'save',
|
|
@@ -136,6 +140,48 @@ export function buildImplementPrompt(extra) {
|
|
|
136
140
|
const trimmed = extra.trim();
|
|
137
141
|
return trimmed ? `${base}\n\nAdditional guidance: ${trimmed}` : base;
|
|
138
142
|
}
|
|
143
|
+
// The model-facing prompt for /search (#829). Written like a shipped skill's body — the command
|
|
144
|
+
// hands over instructions, not a bare query — because the thing it exists for is the model that
|
|
145
|
+
// would otherwise answer a web question from memory: `search` is in every list the mode can reach,
|
|
146
|
+
// and a weak model uses it only when the first line says to. The rest is the discipline the search
|
|
147
|
+
// and fetch budgets already price: one query, the results as given, and no answer the results do not
|
|
148
|
+
// support. Not a bundled skill (the other option the issue raised): a skill's `requires:` is checked
|
|
149
|
+
// from files alone at load time (PATH, git remote) with no config in scope, so it could not be
|
|
150
|
+
// hidden on a machine with no provider, nor refuse in minimal mode, whose list has no web tools at
|
|
151
|
+
// all — it would offer a slash command whose first call cannot run.
|
|
152
|
+
export function buildSearchPrompt(query) {
|
|
153
|
+
return [
|
|
154
|
+
`Search the web for: ${query.trim()}`,
|
|
155
|
+
'',
|
|
156
|
+
'Your first action is a `search` tool call with that query. Answer from its results, not from memory.',
|
|
157
|
+
'',
|
|
158
|
+
'- Give each claim the URL the results returned, verbatim.',
|
|
159
|
+
'- Open the one or two most promising results with `fetch_url` before leaning on a snippet.',
|
|
160
|
+
'- If the results are off-topic, say so and stop — do not re-run the query in other words.',
|
|
161
|
+
'- If the search fails or is unavailable, say that in one line instead of answering from memory.',
|
|
162
|
+
].join('\n');
|
|
163
|
+
}
|
|
164
|
+
// Why /search cannot run in this mode, or undefined when it can. Checked before the provider, since
|
|
165
|
+
// the fix differs: shell has no model turn to hand the query to, and minimal mode's list is bash
|
|
166
|
+
// only — the same structural exclusions that keep the web pair out of those two modes
|
|
167
|
+
// (tools/index.ts).
|
|
168
|
+
export function searchModeRefusal(mode) {
|
|
169
|
+
const elsewhere = '/agent, /plan, /chat or /grind to search.';
|
|
170
|
+
if (mode === 'shell')
|
|
171
|
+
return `/search needs a model turn, and shell mode has none — ${elsewhere}`;
|
|
172
|
+
if (mode === 'minimal')
|
|
173
|
+
return `/search needs the web tools, and minimal mode carries none — ${elsewhere}`;
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
// The other refusal: the mode could search, but this session registered no `search` tool. Two causes
|
|
177
|
+
// with two different fixes, so they are named apart — and the provider one names the switches, the
|
|
178
|
+
// only place the user can act (`search.ts` keeps its own remedy out of the model's context for the
|
|
179
|
+
// same reason).
|
|
180
|
+
export function searchUnavailableNotice(offline) {
|
|
181
|
+
return offline
|
|
182
|
+
? '/search is off for this session: it started with no route out, so the web tools were not loaded (#392).'
|
|
183
|
+
: 'No search provider is configured, so this session has no `search` tool. Set REIKA_SEARXNG_URL to a SearXNG instance, or REIKA_CDP_SEARCH=1 to search through Chrome.';
|
|
184
|
+
}
|
|
139
185
|
// Whether a turn produced a plan worth acting on. The `planFinal` marker alone is not that:
|
|
140
186
|
// loop.ts stamps it on ANY final plan-mode message, including a force-write that ended a spiral,
|
|
141
187
|
// so "the plan turn finished" and "there is a plan" are different claims (#126). Requiring at
|
|
@@ -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
|
}
|