@alexwkleung/reika 0.7.0 → 0.8.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 +15 -0
- package/README.zh-CN.md +15 -0
- package/dist/agent/loop.js +12 -4
- package/dist/agent/prefillcost.js +16 -0
- package/dist/agent/prompt.js +5 -2
- package/dist/cli.js +2 -2
- package/dist/context/bootstrap.js +1 -1
- package/dist/debug.js +15 -0
- package/dist/{headless.js → headless/headless.js} +182 -48
- package/dist/{headlessargs.js → headless/headlessargs.js} +12 -2
- package/dist/headless/headlessprompt.js +132 -0
- package/dist/mcp/client.js +97 -5
- package/dist/mcp/manager.js +15 -2
- package/dist/provider/client.js +13 -0
- package/dist/session.js +8 -0
- package/dist/{skills.js → skills/skills.js} +93 -13
- package/dist/store/sessions.js +39 -2
- package/dist/store/transcript.js +35 -0
- package/dist/tools/_carriers.js +119 -0
- package/dist/tools/_danger.js +304 -82
- package/dist/tools/_readonly.js +13 -12
- package/dist/ui/App.js +150 -69
- package/dist/ui/Approval.js +80 -33
- package/dist/ui/Confirm.js +1 -27
- package/dist/ui/DiffView.js +23 -12
- package/dist/ui/Question.js +152 -19
- package/dist/ui/ResumeSelect.js +3 -2
- package/dist/ui/Status.js +19 -7
- package/dist/ui/commands.js +1 -1
- package/dist/ui/dialogspecs.js +38 -0
- package/dist/ui/layout.js +118 -0
- package/package.json +1 -1
- /package/dist/{skillmatch.js → skills/skillmatch.js} +0 -0
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 { basename, dirname, isAbsolute,
|
|
4
|
+
import { basename, dirname, isAbsolute, 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';
|
|
@@ -9,13 +9,14 @@ import { VERSION } from '../version.js';
|
|
|
9
9
|
import { Input } from './Input.js';
|
|
10
10
|
import { Working, WORKING_WORDS } from './Working.js';
|
|
11
11
|
import { PlanProgress, planProgressRows } from './PlanProgress.js';
|
|
12
|
-
import { Status } from './Status.js';
|
|
12
|
+
import { Status, statusRows } from './Status.js';
|
|
13
13
|
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 {
|
|
18
|
-
import {
|
|
17
|
+
import { Approval } from './Approval.js';
|
|
18
|
+
import { APPROVAL_FEEDBACK_INDEX, APPROVAL_OPTIONS, CONFIRM_ACCEPT, CONFIRM_DECLINE, pastedUrlConfirmSpec, skillConfirmSpec, } from './dialogspecs.js';
|
|
19
|
+
import { Confirm, TOGGLE_CANCEL, TOGGLE_OFF, TOGGLE_ON, implementModeConfirmSpec, toggleConfirmSpec, } from './Confirm.js';
|
|
19
20
|
import { Question, questionDialogHeight } from './Question.js';
|
|
20
21
|
import { inheritProfile, loadConfig, modeSwitchProfile, resolveDefaultMode, resolveProfile, } from '../config.js';
|
|
21
22
|
import { loadLastState, persistableMode, saveLastState, startMode, startProfiles, } from '../laststate.js';
|
|
@@ -25,7 +26,7 @@ import { budgetWarning, formatBudget } from '../context/bundlesize.js';
|
|
|
25
26
|
import { debugEnabled, debugLog, processSessionStem } from '../debug.js';
|
|
26
27
|
import { noteFrameState } from './framedrops.js';
|
|
27
28
|
import { addFileToIndex } from '../context/files.js';
|
|
28
|
-
import { saveTranscript,
|
|
29
|
+
import { saveTranscript, buildTranscriptMeta, } from '../store/transcript.js';
|
|
29
30
|
import {} from '../agent/loop.js';
|
|
30
31
|
import { compactThreshold } from '../agent/compaction.js';
|
|
31
32
|
import { createPrefixWarmer } from '../agent/warm.js';
|
|
@@ -34,7 +35,7 @@ import { isOffline } from '../tools/_net.js';
|
|
|
34
35
|
import { expandMentions } from '../agent/mentions.js';
|
|
35
36
|
import { attachImageBlocks, NATIVE_IMAGE_NOTE, readNativeAttachments, nextImageMarker, } from '../agent/attachments.js';
|
|
36
37
|
import { expandPastedUrls, planPastedUrls } from '../agent/pastedurls.js';
|
|
37
|
-
import { matchSkill, shouldConfirmInject } from '../skillmatch.js';
|
|
38
|
+
import { matchSkill, shouldConfirmInject } from '../skills/skillmatch.js';
|
|
38
39
|
import { imageReader, pasteIsNative } from '../ocr/select.js';
|
|
39
40
|
import { systemOcr } from '../ocr/system.js';
|
|
40
41
|
import { sniffImageMime } from '../ocr/vision.js';
|
|
@@ -43,8 +44,9 @@ import { isWarmEdge } from './warmtrigger.js';
|
|
|
43
44
|
import { Suggestions, suggestionRows } from './Suggestions.js';
|
|
44
45
|
import { ModelSelect } from './ModelSelect.js';
|
|
45
46
|
import { mcpStartupLine } from './format.js';
|
|
47
|
+
import { useContentWidth } from './layout.js';
|
|
46
48
|
import { ResumeSelect } from './ResumeSelect.js';
|
|
47
|
-
import { countRealTurns, forAutosave, listSessions, loadSession, modelHistoryFromScrollback, newSessionPath, projectHistoryDir, ROOT_HISTORY_DIR, writeSession, } from '../store/sessions.js';
|
|
49
|
+
import { countRealTurns, forAutosave, listSessions, loadSession, modelHistoryFromScrollback, newSessionPath, projectHistoryDir, ROOT_HISTORY_DIR, saveHeader, writeSession, } from '../store/sessions.js';
|
|
48
50
|
import { buildModelTargets } from './models.js';
|
|
49
51
|
import { buildImplementPrompt, buildSearchPrompt, IMPLEMENT_MODES, isImplementCommand, isMinimalPrompt, isGrindPrompt, isSaveCommand, nextMode, searchModeRefusal, searchUnavailableNotice, turnMode, turnPromptMode, turnRefines, turnTools, } from './commands.js';
|
|
50
52
|
import { acceptSuggestion, computeSuggestions } from './suggest.js';
|
|
@@ -76,6 +78,18 @@ function promptPlaceholder() {
|
|
|
76
78
|
return withHint.length + 6 <= (process.stdout.columns || 80) ? withHint : base;
|
|
77
79
|
}
|
|
78
80
|
const AUTOSAVE_INTERVAL_MS = 3000;
|
|
81
|
+
// A resumed session reaches the scrollback a slice at a time (#854): a commit renders its messages'
|
|
82
|
+
// markdown, highlighting and wrap synchronously, and one commit for the whole session held the
|
|
83
|
+
// event loop — the resuming spinner's timer included — for as long as that took (~2s at 460
|
|
84
|
+
// messages). Slices are sized to about this long each, so the spinner ticks between them.
|
|
85
|
+
const RESUME_SLICE_MS = 40;
|
|
86
|
+
const RESUME_FIRST_SLICE = 4;
|
|
87
|
+
// Scaled from how long the last slice took, so its cost does not depend on what the messages hold;
|
|
88
|
+
// growth is held to doubling, since a run of tiny messages says little about the next ones.
|
|
89
|
+
function nextResumeSliceSize(size, tookMs) {
|
|
90
|
+
const scaled = Math.round((size * RESUME_SLICE_MS) / Math.max(tookMs, 1));
|
|
91
|
+
return Math.min(Math.max(scaled, 1), size * 2);
|
|
92
|
+
}
|
|
79
93
|
export function App() {
|
|
80
94
|
const { exit } = useApp();
|
|
81
95
|
const [messages, setMessages] = useState([]);
|
|
@@ -235,6 +249,9 @@ export function App() {
|
|
|
235
249
|
// the note on the label below), and without this the picker just vanished and the app sat on a
|
|
236
250
|
// stale frame until it landed.
|
|
237
251
|
const [resuming, setResuming] = useState(null);
|
|
252
|
+
// Held for the whole resume, slices included: a submit or a mode switch between two slices would
|
|
253
|
+
// land its rows in the middle of the resumed scrollback, or swap it for the other side's.
|
|
254
|
+
const resumingRef = useRef(false);
|
|
238
255
|
// `status` is still 'idle' during expansion (submitToModel flips it), so without this a second
|
|
239
256
|
// Enter during a slow fetch starts a duplicate turn. Ref, not state: the handler closes over
|
|
240
257
|
// its render's value, so a fast double-press would read a stale `false`.
|
|
@@ -908,8 +925,9 @@ export function App() {
|
|
|
908
925
|
// in-flight turn's tools and prompt, the same reason /plan et al. refuse while busy; a
|
|
909
926
|
// keystroke shouldn't spam that refusal into scrollback, so it just no-ops.
|
|
910
927
|
if (key.tab && key.shift) {
|
|
911
|
-
if (statusRef.current === 'idle')
|
|
928
|
+
if (statusRef.current === 'idle' && !resumingRef.current) {
|
|
912
929
|
transitionMode(nextMode(modeRef.current), []);
|
|
930
|
+
}
|
|
913
931
|
return;
|
|
914
932
|
}
|
|
915
933
|
const sug = suggestionStateRef.current;
|
|
@@ -950,44 +968,26 @@ export function App() {
|
|
|
950
968
|
// The header both /save and the auto-save write. `msgs` is what the file's body holds.
|
|
951
969
|
const transcriptMeta = (msgs, cwd, midTurn) => {
|
|
952
970
|
// Use the active profile's model/base so the saved meta reflects what was actually running,
|
|
953
|
-
// not the default.
|
|
971
|
+
// not the default.
|
|
954
972
|
const profile = config.profiles[activeProfileRef.current] ?? config.profiles.default;
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
// header and a screenshot of the footer can never disagree.
|
|
958
|
-
const last = lastUsageRef.current;
|
|
959
|
-
const totals = usageRef.current;
|
|
960
|
-
const shrink = sessionRef.current?.shrink ?? { sheds: 0, folds: 0 };
|
|
961
|
-
const window = profile.contextWindow ?? config.contextWindow;
|
|
962
|
-
// The session's reserve is the learned one (#551), the number the next round compacts at.
|
|
963
|
-
const minGen = sessionRef.current?.config.minGenTokens ?? profile.minGenTokens;
|
|
964
|
-
const usable = window ? Math.round(compactThreshold(window, minGen)) : undefined;
|
|
965
|
-
const usage = {
|
|
966
|
-
turns: msgs.filter(m => m.role === 'assistant').length,
|
|
967
|
-
promptTokens: totals.promptTokens,
|
|
968
|
-
completionTokens: totals.completionTokens,
|
|
969
|
-
...(totals.cachedTokens != null ? { cachedTokens: totals.cachedTokens } : {}),
|
|
970
|
-
contextTokens: last?.promptTokens ?? estimatedContextRef.current,
|
|
971
|
-
// No call has landed yet, so the context size above is the pre-send estimate.
|
|
972
|
-
...(last?.promptTokens == null ? { contextEstimated: true } : {}),
|
|
973
|
-
...(window ? { contextWindow: window } : {}),
|
|
974
|
-
...(usable ? { contextUsable: usable } : {}),
|
|
975
|
-
...(last?.cachedTokens != null ? { lastCachedTokens: last.cachedTokens } : {}),
|
|
976
|
-
...(shrink.sheds > 0 || shrink.folds > 0
|
|
977
|
-
? { ...shrink, shrinkEvents: shrinkEventsRef.current }
|
|
978
|
-
: {}),
|
|
979
|
-
};
|
|
980
|
-
return {
|
|
981
|
-
version: TRANSCRIPT_VERSION,
|
|
982
|
-
savedAt: new Date().toISOString(),
|
|
973
|
+
return buildTranscriptMeta({
|
|
974
|
+
msgs,
|
|
983
975
|
model: profile.model,
|
|
984
976
|
baseURL: profile.baseURL,
|
|
985
977
|
cwd,
|
|
986
|
-
messageCount: msgs.length,
|
|
987
978
|
mode: modeRef.current,
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
979
|
+
midTurn,
|
|
980
|
+
status: {
|
|
981
|
+
totals: usageRef.current,
|
|
982
|
+
lastUsage: lastUsageRef.current,
|
|
983
|
+
estimatedContext: estimatedContextRef.current,
|
|
984
|
+
shrink: sessionRef.current?.shrink ?? { sheds: 0, folds: 0 },
|
|
985
|
+
shrinkEvents: shrinkEventsRef.current,
|
|
986
|
+
contextWindow: profile.contextWindow ?? config.contextWindow,
|
|
987
|
+
// The session's reserve is the learned one (#551), the number the next round compacts at.
|
|
988
|
+
minGenTokens: sessionRef.current?.config.minGenTokens ?? profile.minGenTokens,
|
|
989
|
+
},
|
|
990
|
+
});
|
|
991
991
|
};
|
|
992
992
|
// Both sides of the chat boundary, wherever each currently lives.
|
|
993
993
|
const sessionSides = () => {
|
|
@@ -1081,9 +1081,16 @@ export function App() {
|
|
|
1081
1081
|
autosaveHoldRef.current = null;
|
|
1082
1082
|
};
|
|
1083
1083
|
const resumeSession = async (entry, projectDir) => {
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1084
|
+
resumingRef.current = true;
|
|
1085
|
+
try {
|
|
1086
|
+
await loadResumedSession(entry, projectDir);
|
|
1087
|
+
}
|
|
1088
|
+
finally {
|
|
1089
|
+
resumingRef.current = false;
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
const loadResumedSession = async (entry, projectDir) => {
|
|
1093
|
+
// Set before the first await, so the frame lands while the file is still being read.
|
|
1087
1094
|
setResuming(`Resuming "${entry.title ?? 'untitled'}"`);
|
|
1088
1095
|
let sides;
|
|
1089
1096
|
try {
|
|
@@ -1107,6 +1114,23 @@ export function App() {
|
|
|
1107
1114
|
logSessionFile(entry.path);
|
|
1108
1115
|
}
|
|
1109
1116
|
autosaveHoldRef.current = countRealTurns(sides.agent) + countRealTurns(sides.chat);
|
|
1117
|
+
// A session with only one side opens on that side (#875): resumed from the other, it would
|
|
1118
|
+
// land on an empty screen, its messages one /chat or /agent away. A session with both stays
|
|
1119
|
+
// put. Leaving chat goes to agent rather than the session's last mode, which could be plan or
|
|
1120
|
+
// shell. The conversation was just reset, so there is no screen to stash — only the session's
|
|
1121
|
+
// side and the mode move.
|
|
1122
|
+
const agentTurns = countRealTurns(sides.agent);
|
|
1123
|
+
const chatTurns = countRealTurns(sides.chat);
|
|
1124
|
+
const switchedTo = modeRef.current !== 'chat' && agentTurns === 0 && chatTurns > 0
|
|
1125
|
+
? 'chat'
|
|
1126
|
+
: modeRef.current === 'chat' && chatTurns === 0 && agentTurns > 0
|
|
1127
|
+
? 'agent'
|
|
1128
|
+
: null;
|
|
1129
|
+
if (switchedTo) {
|
|
1130
|
+
sessionRef.current?.switchSide(switchedTo === 'chat' ? 'chat' : 'agent');
|
|
1131
|
+
modeRef.current = switchedTo;
|
|
1132
|
+
setMode(switchedTo);
|
|
1133
|
+
}
|
|
1110
1134
|
const inChat = modeRef.current === 'chat';
|
|
1111
1135
|
const active = inChat ? sides.chat : sides.agent;
|
|
1112
1136
|
const other = inChat ? sides.agent : sides.chat;
|
|
@@ -1114,15 +1138,27 @@ export function App() {
|
|
|
1114
1138
|
sessionRef.current?.loadHistory(modelHistoryFromScrollback(active), modelHistoryFromScrollback(other));
|
|
1115
1139
|
const where = inChat ? 'chat' : 'agent';
|
|
1116
1140
|
const otherNote = other.length > 0 ? ` (+ ${other.length} on the ${inChat ? 'agent' : 'chat'} side)` : '';
|
|
1117
|
-
|
|
1141
|
+
const resumed = [
|
|
1118
1142
|
...active,
|
|
1119
1143
|
{
|
|
1120
1144
|
role: 'system',
|
|
1121
|
-
content: `Resumed "${entry.title ?? 'untitled'}" — ${active.length} ${where} messages${otherNote} from ${entry.path}`,
|
|
1145
|
+
content: `Resumed "${entry.title ?? 'untitled'}" — ${active.length} ${where} messages${otherNote}${switchedTo ? `, switched to ${switchedTo} mode,` : ''} from ${entry.path}`,
|
|
1122
1146
|
},
|
|
1123
|
-
]
|
|
1124
|
-
|
|
1125
|
-
|
|
1147
|
+
];
|
|
1148
|
+
let size = RESUME_FIRST_SLICE;
|
|
1149
|
+
for (let at = 0; at < resumed.length;) {
|
|
1150
|
+
const slice = resumed.slice(at, at + size);
|
|
1151
|
+
const started = performance.now();
|
|
1152
|
+
// The first slice replaces the old conversation; the rest extend it.
|
|
1153
|
+
setMessages(at === 0 ? slice : prev => [...prev, ...slice]);
|
|
1154
|
+
at += slice.length;
|
|
1155
|
+
if (at >= resumed.length)
|
|
1156
|
+
break;
|
|
1157
|
+
// A timer, not a microtask: the spinner ticks on an interval, which only a yield to the timer
|
|
1158
|
+
// phase lets fire. Measured past the yield, so the commit counts whenever React flushes it.
|
|
1159
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
1160
|
+
size = nextResumeSliceSize(size, performance.now() - started);
|
|
1161
|
+
}
|
|
1126
1162
|
setResuming(null);
|
|
1127
1163
|
};
|
|
1128
1164
|
const requestExit = () => {
|
|
@@ -1478,24 +1514,39 @@ export function App() {
|
|
|
1478
1514
|
return;
|
|
1479
1515
|
}
|
|
1480
1516
|
const target = args.trim().toLowerCase();
|
|
1481
|
-
if (target !== '' && target !== 'root') {
|
|
1482
|
-
say('Usage: /resume (this project) or /resume root (manual /save files).');
|
|
1517
|
+
if (target !== '' && target !== 'all' && target !== 'root') {
|
|
1518
|
+
say('Usage: /resume (this project; chats only in chat mode), /resume all, or /resume root (manual /save files).');
|
|
1483
1519
|
return;
|
|
1484
1520
|
}
|
|
1485
1521
|
const projectDir = projectHistoryDir(bundle.cwd);
|
|
1486
1522
|
// The session in progress is not something to resume into.
|
|
1487
1523
|
const notCurrent = (e) => e.path !== sessionPathRef.current;
|
|
1524
|
+
// Chat history is kept apart from every other mode's, so chat mode lists chats (#875). A
|
|
1525
|
+
// project file saved before the header counted chat turns is not listed here; /resume all
|
|
1526
|
+
// still has it.
|
|
1527
|
+
const chatsOnly = target === '' && modeRef.current === 'chat';
|
|
1488
1528
|
let entries = [];
|
|
1489
1529
|
let heading = 'saved with /save';
|
|
1490
|
-
if (target
|
|
1530
|
+
if (target !== 'root') {
|
|
1491
1531
|
entries = (await listSessions(projectDir)).filter(notCurrent);
|
|
1492
|
-
|
|
1532
|
+
if (chatsOnly)
|
|
1533
|
+
entries = entries.filter(e => e.chat);
|
|
1534
|
+
heading = chatsOnly ? 'chats in this project' : 'this project';
|
|
1493
1535
|
}
|
|
1494
|
-
// A project with
|
|
1536
|
+
// A project with nothing to list falls back to the manual saves — in chat mode, the ones that
|
|
1537
|
+
// hold a chat (#882).
|
|
1495
1538
|
if (entries.length === 0) {
|
|
1496
|
-
entries = await listSessions(ROOT_HISTORY_DIR);
|
|
1539
|
+
entries = await listSessions(ROOT_HISTORY_DIR, true);
|
|
1540
|
+
if (chatsOnly)
|
|
1541
|
+
entries = entries.filter(e => e.chat);
|
|
1497
1542
|
if (target === '' && entries.length > 0)
|
|
1498
|
-
heading =
|
|
1543
|
+
heading = chatsOnly
|
|
1544
|
+
? 'no chats for this project — saved with /save'
|
|
1545
|
+
: 'none for this project — saved with /save';
|
|
1546
|
+
}
|
|
1547
|
+
if (entries.length === 0 && chatsOnly) {
|
|
1548
|
+
say('No saved chats for this project. /resume all lists every session.');
|
|
1549
|
+
return;
|
|
1499
1550
|
}
|
|
1500
1551
|
if (entries.length === 0) {
|
|
1501
1552
|
say(target === 'root'
|
|
@@ -1529,7 +1580,7 @@ export function App() {
|
|
|
1529
1580
|
return;
|
|
1530
1581
|
}
|
|
1531
1582
|
try {
|
|
1532
|
-
const { jsonlPath, txtPath } = await saveTranscript(
|
|
1583
|
+
const { jsonlPath, txtPath } = await saveTranscript(ROOT_HISTORY_DIR, msgs, saveHeader(transcriptMeta(msgs, bundle.cwd, midTurn), msgs), { redact: !raw });
|
|
1533
1584
|
setMessages(prev => [
|
|
1534
1585
|
...prev,
|
|
1535
1586
|
echo,
|
|
@@ -1573,7 +1624,7 @@ export function App() {
|
|
|
1573
1624
|
' /tokens show token usage this session',
|
|
1574
1625
|
' /stats show full session summary',
|
|
1575
1626
|
' /save save the full conversation to history, even mid-turn (--raw skips redaction)',
|
|
1576
|
-
' /resume [root]
|
|
1627
|
+
' /resume [all|root] resume a saved session of this project (chat mode: chats only; all: every session; root: the /save files)',
|
|
1577
1628
|
' /skills list available skills (loaded from your skill directories)',
|
|
1578
1629
|
' /mcp list MCP servers and their tools (REIKA_MCP_SERVERS)',
|
|
1579
1630
|
' /<server>:<tool> call an MCP tool directly (JSON args, or the bare string for a one-arg tool)',
|
|
@@ -1771,12 +1822,12 @@ export function App() {
|
|
|
1771
1822
|
const list = bundle?.skills ?? [];
|
|
1772
1823
|
if (list.length === 0) {
|
|
1773
1824
|
response =
|
|
1774
|
-
'No skills loaded. Drop *.md files in ~/.config/reika/skills/ or <cwd>/.
|
|
1825
|
+
'No skills loaded. Drop *.md files or SKILL.md folders in ~/.config/reika/skills/, <cwd>/.reika/skills/, ~/.agents/skills/ or <cwd>/.agents/skills/.';
|
|
1775
1826
|
}
|
|
1776
1827
|
else {
|
|
1777
1828
|
response = [
|
|
1778
1829
|
'Available skills (invoke as /<name>):',
|
|
1779
|
-
...list.map(s => ` /${s.name.padEnd(16)} ${s.description} ${s.source === 'project' ? '(project)' : ''}`),
|
|
1830
|
+
...list.map(s => ` /${s.name.padEnd(16)} ${s.description} ${s.from ? `(${s.from})` : s.source === 'project' ? '(project)' : ''}`),
|
|
1780
1831
|
].join('\n');
|
|
1781
1832
|
}
|
|
1782
1833
|
break;
|
|
@@ -2122,6 +2173,10 @@ export function App() {
|
|
|
2122
2173
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2123
2174
|
}, [status, pending, confirm, queue]);
|
|
2124
2175
|
const onSubmit = async (input) => {
|
|
2176
|
+
// Left in the box rather than queued: the resume replaces the conversation the prompt was
|
|
2177
|
+
// typed against, and the user sees it land before deciding to send.
|
|
2178
|
+
if (resumingRef.current)
|
|
2179
|
+
return;
|
|
2125
2180
|
// An answer being typed for `ask_user` — not a message for the model. Intercepted ahead of the
|
|
2126
2181
|
// busy-queue branch below: a question only exists mid-turn, so every such submit would otherwise
|
|
2127
2182
|
// be queued as the user's next prompt.
|
|
@@ -2571,8 +2626,38 @@ export function App() {
|
|
|
2571
2626
|
statusProfile?.minGenTokens ??
|
|
2572
2627
|
config.minGenTokens))
|
|
2573
2628
|
: undefined;
|
|
2574
|
-
|
|
2575
|
-
const
|
|
2629
|
+
const statusWidth = useContentWidth();
|
|
2630
|
+
const statusProps = {
|
|
2631
|
+
model: config?.profiles[activeProfile]?.model ?? config?.model ?? '',
|
|
2632
|
+
turns: messages.filter(m => m.role === 'assistant').length,
|
|
2633
|
+
status: status === 'busy' ? phase : status,
|
|
2634
|
+
elapsed: status === 'busy' ? elapsed : null,
|
|
2635
|
+
usage: totalUsage,
|
|
2636
|
+
contextTokens: lastUsage?.promptTokens ?? estimatedContext,
|
|
2637
|
+
contextWindow: statusWindow,
|
|
2638
|
+
contextUsable: statusUsable,
|
|
2639
|
+
sheds: shrink.sheds,
|
|
2640
|
+
folds: shrink.folds,
|
|
2641
|
+
cachedTokens: lastUsage?.cachedTokens,
|
|
2642
|
+
decodeRate: decodeRate,
|
|
2643
|
+
pr: pr,
|
|
2644
|
+
autoApprove: config?.autoApprove === 'bypass'
|
|
2645
|
+
? 'bypass'
|
|
2646
|
+
: effectiveAutoApprove(config, sessionAutoApprove) === 'safe'
|
|
2647
|
+
? 'safe'
|
|
2648
|
+
: undefined,
|
|
2649
|
+
unattended: unattended,
|
|
2650
|
+
modeTag: mode,
|
|
2651
|
+
exitArmed: exitArmed && status === 'idle' && pending === null && inputValue === '',
|
|
2652
|
+
};
|
|
2653
|
+
// Status rows past the one the baseline chrome assumes: a narrow pane (three iTerm2 panes) wraps
|
|
2654
|
+
// the bar onto several, and unbudgeted they push the live frame to viewport height, where Ink
|
|
2655
|
+
// repaints with a scrollback clear on every chunk.
|
|
2656
|
+
const statusExtraRows = Math.max(0, statusRows(statusProps, statusWidth) - 1);
|
|
2657
|
+
// Live rows above a dialog (plan checklist, queued messages, a wrapped status bar) it has to
|
|
2658
|
+
// leave viewport room for.
|
|
2659
|
+
const dialogReservedRows = statusExtraRows +
|
|
2660
|
+
(planSteps && (mode === 'agent' || mode === 'vibe') ? planProgressRows(planSteps) : 0) +
|
|
2576
2661
|
(queue.length > 0 ? queue.length + 1 : 0);
|
|
2577
2662
|
if (status === 'error') {
|
|
2578
2663
|
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "Error" }), _jsx(Text, { children: error })] }));
|
|
@@ -2651,8 +2736,8 @@ export function App() {
|
|
|
2651
2736
|
modelSelect !== null ||
|
|
2652
2737
|
resumeSelect !== null ||
|
|
2653
2738
|
confirm !== null, attachedBelow: suggestionState !== null, reservedRows: question
|
|
2654
|
-
? questionDialogHeight(question.request, questionTyping, dialogReservedRows)
|
|
2655
|
-
:
|
|
2739
|
+
? questionDialogHeight(question.request, questionTyping, dialogReservedRows, questionSelected)
|
|
2740
|
+
: statusExtraRows, suggesting: !!suggestionState && suggestionState.items.length > 0, history: inputHistory, mode: mode, value: inputValue, onChange: onInputChange, onSubmit: onSubmit, onPasteImage: onPasteImageSafely, onPasteText: onPasteText, placeholder:
|
|
2656
2741
|
// A reason that should stop the model has to say so: "tell me the script" read as
|
|
2657
2742
|
// run-then-tell and drew retries, "don't run anything" did not (decline-terse/-ask).
|
|
2658
2743
|
approvalTyping
|
|
@@ -2661,9 +2746,5 @@ export function App() {
|
|
|
2661
2746
|
? 'Run a shell command'
|
|
2662
2747
|
: mode === 'vibe'
|
|
2663
2748
|
? 'Describe a change — it plans first, then implements'
|
|
2664
|
-
: promptPlaceholder() }), suggestionState ? (_jsx(Suggestions, { state: suggestionState, selectedIndex: suggestionSelected })) : null, _jsx(Status, {
|
|
2665
|
-
? 'bypass'
|
|
2666
|
-
: effectiveAutoApprove(config, sessionAutoApprove) === 'safe'
|
|
2667
|
-
? 'safe'
|
|
2668
|
-
: undefined, unattended: unattended, modeTag: mode, exitArmed: exitArmed && status === 'idle' && pending === null && inputValue === '' })] }))] }));
|
|
2749
|
+
: promptPlaceholder() }), suggestionState ? (_jsx(Suggestions, { state: suggestionState, selectedIndex: suggestionSelected })) : null, _jsx(Status, { ...statusProps })] }))] }));
|
|
2669
2750
|
}
|
package/dist/ui/Approval.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from 'ink';
|
|
3
3
|
import wrapAnsi from 'wrap-ansi';
|
|
4
|
+
import { APPROVAL_OPTIONS } from './dialogspecs.js';
|
|
4
5
|
import { glyphs } from './glyphs.js';
|
|
5
6
|
import { theme } from './theme.js';
|
|
6
7
|
import { DiffView } from './DiffView.js';
|
|
7
8
|
import { highlightCode } from './highlight.js';
|
|
8
9
|
import { sanitizeTerminalText } from './termtext.js';
|
|
9
|
-
import {
|
|
10
|
+
import { hangingRows, hangingWrap, useContentWidth, wrappedRows, wrapStyledRows, } from './layout.js';
|
|
10
11
|
import { toolLabel } from './format.js';
|
|
11
12
|
// The dialog's own border (1 column each side) plus its paddingX={1}, on top of the App padding
|
|
12
13
|
// contentWidth already accounts for. The diff has to wrap inside all of it or its rows push
|
|
@@ -19,46 +20,93 @@ export const DIALOG_MARKER = glyphs.dialogCall;
|
|
|
19
20
|
// The dialog sits in Ink's live frame, and a frame as tall as the viewport makes Ink repaint the
|
|
20
21
|
// whole terminal with `\x1b[3J` — iTerm2's "attempted to clear scrollback" — and leaves the rows
|
|
21
22
|
// that scrolled off the top stranded in the scrollback after the dialog closes (#447). So the
|
|
22
|
-
// preview gets whatever the viewport has left
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
// preview gets whatever the viewport has left: the frame, the subject, the warnings, the options
|
|
24
|
+
// and the hint are paid for first, and the input and status bar underneath get their reserve.
|
|
25
|
+
//
|
|
26
|
+
// Those chrome rows are MEASURED, not assumed (#842). On a narrow pane the subject, each warning,
|
|
27
|
+
// the option labels and the hint all wrap, and a constant that counted one row each undercounted
|
|
28
|
+
// the frame by the wraps — so the preview sized itself against a budget the dialog then overspent,
|
|
29
|
+
// and on a small pane the frame reached the viewport height and cleared the scrollback.
|
|
30
|
+
const FRAME_ROWS = 4; // marginTop, top border, and both paddingY rows
|
|
31
|
+
const GAP_ROWS = 1; // the margin above the preview, the warnings, the options and the hint
|
|
32
|
+
const OPTION_HANG = 2; // '› ' — the marker every option row hangs under
|
|
33
|
+
const BELOW_DIALOG_ROWS = 6; // the input box, the status bar, and slack
|
|
27
34
|
const MIN_PREVIEW_ROWS = 3;
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
export const APPROVAL_HINT = '↑↓ navigate · enter select · y/n shortcuts · ctrl-c abort';
|
|
36
|
+
export const APPROVAL_TYPING_HINT = 'enter send · ctrl-c back to the options';
|
|
37
|
+
const APPROVAL_TYPING_LINE = 'Declining — type what to do instead below';
|
|
38
|
+
// What the dialog costs vertically at `cols` columns and how much of `rows` the preview may take.
|
|
39
|
+
// `height` is what the dialog draws, so `height + BELOW_DIALOG_ROWS <= rows - 1` holds wherever the
|
|
40
|
+
// pane has room for the dialog at all.
|
|
41
|
+
//
|
|
42
|
+
// The budget is `rows - 1`: Ink's condition is `outputHeight >= stdout.rows` (build/ink.js), so a
|
|
43
|
+
// frame that lands exactly on the viewport height is already a full repaint. When the measured
|
|
44
|
+
// chrome leaves the preview under `MIN_PREVIEW_ROWS`, the HINT is what goes — the options and the
|
|
45
|
+
// warnings are what the user is deciding on, and the preview is where the evidence is.
|
|
46
|
+
const withGap = (rows) => rows + GAP_ROWS;
|
|
47
|
+
export function layoutApproval(request, typing, cols, rows = process.stdout.rows || 24, reservedRows = 0) {
|
|
48
|
+
const warnings = request.warnings ?? [];
|
|
49
|
+
// Pre-wrapped, so the rows counted here are the rows drawn whatever width Ink lays the frame
|
|
50
|
+
// out in, rather than only the width this measured at.
|
|
51
|
+
const hint = hangingWrap(typing ? APPROVAL_TYPING_HINT : APPROVAL_HINT, Math.max(1, cols), 0);
|
|
52
|
+
const hintRows = withGap(hint.split('\n').length);
|
|
53
|
+
const warningRows = warnings.length
|
|
54
|
+
? withGap(warnings.reduce((n, w) => n + wrappedRows(`▲ ${w}`, cols), 0))
|
|
55
|
+
: 0;
|
|
56
|
+
const optionRows = typing
|
|
57
|
+
? wrappedRows(APPROVAL_TYPING_LINE, cols)
|
|
58
|
+
: APPROVAL_OPTIONS.reduce((n, label) => n + hangingRows(label, cols, OPTION_HANG), 0);
|
|
59
|
+
const chrome = FRAME_ROWS +
|
|
60
|
+
wrappedRows(`${DIALOG_MARKER} ${toolLabel(request.tool)} ${request.subject}`, cols) +
|
|
61
|
+
GAP_ROWS +
|
|
62
|
+
warningRows +
|
|
63
|
+
GAP_ROWS +
|
|
64
|
+
optionRows;
|
|
65
|
+
// Whatever the chrome, the warnings and the reserve leave of the viewport.
|
|
66
|
+
const room = rows - 1 - BELOW_DIALOG_ROWS - reservedRows - chrome;
|
|
67
|
+
const withHint = room - hintRows;
|
|
68
|
+
if (withHint >= MIN_PREVIEW_ROWS) {
|
|
69
|
+
return { previewRows: withHint, showHint: true, hint, height: chrome + hintRows + withHint };
|
|
70
|
+
}
|
|
71
|
+
// The hint is the one block nothing else depends on, so it pays for the preview — even when the
|
|
72
|
+
// rows it frees still don't reach MIN_PREVIEW_ROWS: on a pane that narrow every row counts.
|
|
73
|
+
const previewRows = Math.max(1, room);
|
|
74
|
+
return { previewRows, showHint: false, hint, height: chrome + previewRows };
|
|
31
75
|
}
|
|
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;
|
|
41
76
|
// The popup renders as the top half of one continuous frame whose bottom half is
|
|
42
77
|
// the input box (see Input's `attachedAbove`): `borderBottom={false}` + the input
|
|
43
78
|
// dropping its top border merges them into a single outline, so the prompt reads
|
|
44
79
|
// as part of the input region rather than a card floating above it. The frame
|
|
45
80
|
// stays neutral (no borderColor) to match the input; caution is signalled inside
|
|
46
81
|
// via themed `▲` warning lines, not a colored border.
|
|
47
|
-
export function Approval({ request, selectedIndex, typing = false, reservedRows = 0, }) {
|
|
82
|
+
export function Approval({ request, selectedIndex, typing = false, width, rows = process.stdout.rows || 24, reservedRows = 0, }) {
|
|
48
83
|
const isCommand = request.tool === 'bash';
|
|
49
84
|
const warnings = request.warnings ?? [];
|
|
50
|
-
|
|
51
|
-
|
|
85
|
+
// `useContentWidth`, not a bare contentWidth(): the packing has to follow a resize, and this is
|
|
86
|
+
// the width the dialog's own rows cost against — the same number the rows are drawn at.
|
|
87
|
+
const liveWidth = useContentWidth(DIALOG_CHROME);
|
|
88
|
+
const layoutWidth = width ?? liveWidth;
|
|
89
|
+
const { previewRows, showHint, hint } = layoutApproval(request, typing, layoutWidth, rows, reservedRows);
|
|
90
|
+
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: previewRows, width: layoutWidth })) : request.tool === 'fetch_url' ? (_jsx(UrlPreview, { url: request.preview, maxRows: previewRows, width: layoutWidth })) : (_jsx(DiffView, { diff: request.preview, path: request.subject, maxWidth: layoutWidth, startLine: request.startLine, maxRows: previewRows, 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: APPROVAL_TYPING_LINE })) : (APPROVAL_OPTIONS.map((label, i) => {
|
|
52
91
|
const selected = i === selectedIndex;
|
|
53
|
-
return (_jsxs(Text, { children: [_jsx(Text, { color: selected ? theme.accent : undefined, children: selected ? '› ' : ' ' }), _jsx(Text, { color: selected ? theme.accent : undefined, children: label })] }, i));
|
|
54
|
-
})) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { color: theme.muted, children:
|
|
55
|
-
|
|
56
|
-
|
|
92
|
+
return (_jsxs(Text, { children: [_jsx(Text, { color: selected ? theme.accent : undefined, children: selected ? '› ' : ' ' }), _jsx(Text, { color: selected ? theme.accent : undefined, children: hangingWrap(label, layoutWidth, OPTION_HANG) })] }, i));
|
|
93
|
+
})) }), showHint ? (_jsx(Box, { marginTop: 1, children: _jsx(Text, { color: theme.muted, children: hint }) })) : null] }));
|
|
94
|
+
}
|
|
95
|
+
// A URL drawn as plain text, bounded to the rows the preview was given: it has no gutter and no
|
|
96
|
+
// line structure to fit, but it still wraps.
|
|
97
|
+
function UrlPreview({ url, maxRows, width }) {
|
|
98
|
+
const rows = wrapAnsi(url, Math.max(1, width), { trim: false, hard: true }).split('\n');
|
|
99
|
+
if (rows.length <= maxRows)
|
|
100
|
+
return _jsx(Text, { children: url });
|
|
101
|
+
// One row is the note's, as the diff and the command preview spend theirs, and what is left is
|
|
102
|
+
// what the URL may take: a one-row preview is the note alone.
|
|
103
|
+
const shown = rows.slice(0, Math.max(0, maxRows - 1));
|
|
104
|
+
return (_jsxs(_Fragment, { children: [shown.length > 0 ? _jsx(Text, { children: shown.join('\n') }) : null, _jsx(Text, { color: theme.muted, children: `… ${rows.length - shown.length} more lines` })] }));
|
|
57
105
|
}
|
|
58
106
|
// The marker on a command's first row; every wrapped/extra line hangs under it by this width.
|
|
59
107
|
const MARKER = '$ ';
|
|
60
108
|
const MARKER_WIDTH = 2;
|
|
61
|
-
function CommandPreview({ command, maxRows }) {
|
|
109
|
+
function CommandPreview({ command, maxRows, width, }) {
|
|
62
110
|
// Sanitized like the scrollback chip (issue #154), but NOT scrubbed: this is the dialog where
|
|
63
111
|
// the user decides whether to run the thing, so it must show the command as written, secrets
|
|
64
112
|
// and all. Tabs and cursor motions still go — inside a bordered box they wrap past the border
|
|
@@ -66,8 +114,8 @@ function CommandPreview({ command, maxRows }) {
|
|
|
66
114
|
const all = sanitizeTerminalText(command).split('\n');
|
|
67
115
|
// Same width the rows are rendered at below, so the row counts fitted here are the row counts
|
|
68
116
|
// the dialog actually draws.
|
|
69
|
-
const
|
|
70
|
-
const { lines, hidden } = fitCommandLines(all, maxRows,
|
|
117
|
+
const textWidth = Math.max(1, width - MARKER_WIDTH);
|
|
118
|
+
const { lines, hidden } = fitCommandLines(all, maxRows, textWidth);
|
|
71
119
|
// Each logical line is pre-wrapped to the dialog width the way DiffView's WrappedRow does it
|
|
72
120
|
// (#489): the `$`/` ` marker and the text are adjacent siblings in a row Box, and when the row
|
|
73
121
|
// is long enough to wrap, Ink drops the character at that sibling boundary — the space of `$ `,
|
|
@@ -75,10 +123,7 @@ function CommandPreview({ command, maxRows }) {
|
|
|
75
123
|
// Wrapping ourselves keeps each row inside the width, so Ink never wraps one and the marker's
|
|
76
124
|
// space survives; short commands were the only ones that kept their space before this.
|
|
77
125
|
return (_jsxs(_Fragment, { children: [lines.flatMap((line, i) => {
|
|
78
|
-
const rows =
|
|
79
|
-
trim: false,
|
|
80
|
-
hard: true,
|
|
81
|
-
}).split('\n');
|
|
126
|
+
const rows = wrapStyledRows(highlightCode(line, 'bash'), textWidth);
|
|
82
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}`)));
|
|
83
128
|
}), hidden > 0 ? _jsx(Text, { color: theme.muted, children: `… ${hidden} more lines` }) : null] }));
|
|
84
129
|
}
|
|
@@ -92,7 +137,9 @@ export function fitCommandLines(lines, maxRows, width) {
|
|
|
92
137
|
const heights = lines.map(l => wrapAnsi(l, Math.max(1, width), { trim: false, hard: true }).split('\n').length);
|
|
93
138
|
if (heights.reduce((a, b) => a + b, 0) <= maxRows)
|
|
94
139
|
return { lines, hidden: 0 };
|
|
95
|
-
|
|
140
|
+
// One row is the footer's when anything is cut, and the rows kept must stay INSIDE `maxRows`:
|
|
141
|
+
// a preview budgeted one row draws the footer alone rather than a line plus a footer.
|
|
142
|
+
const budget = Math.max(0, maxRows - 1);
|
|
96
143
|
let used = 0;
|
|
97
144
|
let kept = 0;
|
|
98
145
|
while (kept < lines.length && used + heights[kept] <= budget)
|
package/dist/ui/Confirm.js
CHANGED
|
@@ -1,35 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from 'ink';
|
|
3
|
+
import {} from './dialogspecs.js';
|
|
3
4
|
import { IMPLEMENT_MODES } from './commands.js';
|
|
4
5
|
import { glyphs } from './glyphs.js';
|
|
5
6
|
import { theme } from './theme.js';
|
|
6
|
-
// Row 0 is "send as typed" and starts selected — the inverse of Approval, where Approve is row 0.
|
|
7
|
-
// There the model has already committed to an action; here nothing has happened yet and the
|
|
8
|
-
// literal prompt is what was asked for. A wrong default that acts costs a turn (or a request
|
|
9
|
-
// nobody meant); a wrong default that doesn't costs a keystroke.
|
|
10
|
-
export const CONFIRM_DECLINE = 0;
|
|
11
|
-
export const CONFIRM_ACCEPT = 1;
|
|
12
|
-
export function skillConfirmSpec(match) {
|
|
13
|
-
return {
|
|
14
|
-
title: 'Skill',
|
|
15
|
-
subtitle: `/${match.skill.name} — ${match.skill.description}`,
|
|
16
|
-
details: [`matched: ${match.matched.join(', ')}`],
|
|
17
|
-
options: ['Send as typed', `Apply /${match.skill.name}`],
|
|
18
|
-
accept: 'apply',
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
// A long URL wraps the frame; the user just typed it, so the head is enough to recognize it.
|
|
22
|
-
const URL_DISPLAY_CHARS = 90;
|
|
23
|
-
export function pastedUrlConfirmSpec(urls) {
|
|
24
|
-
const n = urls.length;
|
|
25
|
-
return {
|
|
26
|
-
title: n > 1 ? 'Pasted links' : 'Pasted link',
|
|
27
|
-
subtitle: `the prompt doesn't read as a request to open ${n > 1 ? 'them' : 'it'} — fetch before the turn?`,
|
|
28
|
-
details: urls.map(u => u.length > URL_DISPLAY_CHARS ? `${u.slice(0, URL_DISPLAY_CHARS)}…` : u),
|
|
29
|
-
options: ['Send as typed', `Fetch ${n > 1 ? `${n} links` : 'the link'}`],
|
|
30
|
-
accept: 'fetch',
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
7
|
const IMPLEMENT_MODE_LABELS = {
|
|
34
8
|
agent: 'Agent — full tool set',
|
|
35
9
|
minimal: 'Minimal — shell only, no repo map or AGENTS.md',
|