@ywldan/kiro 0.4.0 → 0.5.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 +669 -519
- package/dist/agent/loop.js +25 -3
- package/dist/agent/prompt.js +3 -1
- package/dist/config.js +87 -0
- package/dist/cost.js +87 -0
- package/dist/doctor.js +14 -13
- package/dist/headless.js +21 -4
- package/dist/index.js +84 -47
- package/dist/mcp/client.js +112 -0
- package/dist/mcp/config.js +112 -0
- package/dist/mcp/env.js +28 -0
- package/dist/mcp/http.js +168 -0
- package/dist/mcp/prompt.js +24 -0
- package/dist/mcp/registry.js +206 -0
- package/dist/mcp/rpc.js +208 -0
- package/dist/mcp/stdio.js +106 -0
- package/dist/model/cli.js +27 -4
- package/dist/model/discovery.js +8 -8
- package/dist/model/wizard.js +60 -1
- package/dist/permissions.js +240 -0
- package/dist/providers/openai.js +5 -7
- package/dist/providers/request.js +71 -0
- package/dist/tools/fs.js +6 -0
- package/dist/tools/index.js +18 -4
- package/dist/tools/patch.js +3 -0
- package/dist/tools/registry.js +16 -0
- package/dist/tools/shell.js +21 -2
- package/dist/ui/App.js +157 -8
- package/dist/ui/ApprovalPrompt.js +31 -34
- package/dist/ui/MessageList.js +10 -0
- package/dist/ui/StatusBar.js +6 -2
- package/dist/ui/UsageCard.js +3 -2
- package/dist/ui/approval-policy.js +40 -2
- package/dist/ui/approval-preview.js +81 -0
- package/dist/ui/commands.js +2 -0
- package/package.json +61 -61
package/dist/ui/App.js
CHANGED
|
@@ -31,9 +31,14 @@ import { formatProfileList } from './profile-list.js';
|
|
|
31
31
|
import { loadPromptHistory, recordPrompt } from './prompt-history.js';
|
|
32
32
|
import { StatusBar } from './StatusBar.js';
|
|
33
33
|
import { summarizeToolArgs } from './text.js';
|
|
34
|
+
import { MAX_PREVIEW_LINES } from './approval-preview.js';
|
|
35
|
+
import { formatMcpStatus } from '../mcp/registry.js';
|
|
34
36
|
import { UsageCard, USAGE_CARD_GAP, USAGE_CARD_WIDTH, shouldShowUsageCard, } from './UsageCard.js';
|
|
35
37
|
import { addUsage, EMPTY_USAGE } from '../usage.js';
|
|
38
|
+
import { formatCost } from '../cost.js';
|
|
39
|
+
import { addCost, priceFor, sessionCost as restoredCost, } from '../cost.js';
|
|
36
40
|
import { undoLastCheckpoint } from '../tools/checkpoint.js';
|
|
41
|
+
import { addRule, clearRules, loadRules, permissionsPath, removeRule, } from '../permissions.js';
|
|
37
42
|
import { MAX_EXPANDED_TOOL_CHARS, MAX_REASONING_CHARS, } from './types.js';
|
|
38
43
|
/** Idle Ctrl+C must be pressed again within this window to exit. */
|
|
39
44
|
const QUIT_CONFIRM_MS = 2_000;
|
|
@@ -55,7 +60,7 @@ function useTerminalSize() {
|
|
|
55
60
|
}, [stdout, read]);
|
|
56
61
|
return size;
|
|
57
62
|
}
|
|
58
|
-
export function App({ config, baseConfig, overrides, configPath, configCreated, cwd: initialCwd, version, yolo, mouseEnabled, initialSession, startupNotices, }) {
|
|
63
|
+
export function App({ config, baseConfig, overrides, configPath, configCreated, cwd: initialCwd, version, yolo, mouseEnabled, initialSession, startupNotices, mcp, }) {
|
|
59
64
|
const { exit } = useApp();
|
|
60
65
|
const { stdout } = useStdout();
|
|
61
66
|
const { columns, rows } = useTerminalSize();
|
|
@@ -88,6 +93,8 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
88
93
|
const [wizardPrompt, setWizardPrompt] = useState(null);
|
|
89
94
|
const [wizardActive, setWizardActive] = useState(false);
|
|
90
95
|
const [activeTool, setActiveTool] = useState(null);
|
|
96
|
+
/** Newest output line of the running command, shown in the status bar. */
|
|
97
|
+
const [liveTail, setLiveTail] = useState(null);
|
|
91
98
|
const [cancelling, setCancelling] = useState(false);
|
|
92
99
|
const [pendingApproval, setPendingApproval] = useState(null);
|
|
93
100
|
const [pendingQuestion, setPendingQuestion] = useState(null);
|
|
@@ -115,6 +122,16 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
115
122
|
const roundCompletionTokensRef = useRef(null);
|
|
116
123
|
const [sessionUsage, setSessionUsage] = useState(() => initialSession?.usage ?? EMPTY_USAGE);
|
|
117
124
|
const sessionUsageRef = useRef(sessionUsage);
|
|
125
|
+
/** Running cost estimate; `complete` turns false once a request had no known price. */
|
|
126
|
+
const [sessionCost, setSessionCost] = useState({ dollars: 0, complete: true });
|
|
127
|
+
const sessionCostRef = useRef(sessionCost);
|
|
128
|
+
/** Price of the active profile's model; a profile `pricing` entry wins over the table. */
|
|
129
|
+
const profilePricing = config.profiles[profileName]?.pricing;
|
|
130
|
+
const currentPrice = profilePricing ?? priceFor(config.profiles[profileName]?.model ?? '', config.profiles[profileName]?.baseUrl);
|
|
131
|
+
const currentPriceRef = useRef(currentPrice);
|
|
132
|
+
currentPriceRef.current = currentPrice;
|
|
133
|
+
const priceRef = currentPriceRef;
|
|
134
|
+
const hasPrice = currentPrice !== null;
|
|
118
135
|
const [lastReply, setLastReply] = useState(null);
|
|
119
136
|
const [contextTokens, setContextTokens] = useState(() => estimateMessagesTokens(messagesRef.current));
|
|
120
137
|
const contextTokensRef = useRef(contextTokens);
|
|
@@ -148,6 +165,10 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
148
165
|
const quitTimerRef = useRef(null);
|
|
149
166
|
const [approvalPolicy] = useState(() => new ApprovalPolicy(yolo));
|
|
150
167
|
const [autoAllowed, setAutoAllowed] = useState([]);
|
|
168
|
+
/** Saved rules for this project; empty until the first read finishes. */
|
|
169
|
+
const [savedRules, setSavedRules] = useState([]);
|
|
170
|
+
/** Set when a saved rule refused the pending request. */
|
|
171
|
+
const [ruleNote, setRuleNote] = useState(null);
|
|
151
172
|
const pendingApprovalRef = useRef(null);
|
|
152
173
|
const pendingResolverRef = useRef(null);
|
|
153
174
|
const pendingQuestionRef = useRef(null);
|
|
@@ -165,6 +186,19 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
165
186
|
{ kind: 'notice', id: nextItemIdRef.current++, level, text },
|
|
166
187
|
]);
|
|
167
188
|
}, []);
|
|
189
|
+
/** Reads this project's saved rules; a broken file reports once and never blocks a turn. */
|
|
190
|
+
const refreshRules = useCallback(async (report = false) => {
|
|
191
|
+
const set = await loadRules(cwd);
|
|
192
|
+
if (set.problem && report)
|
|
193
|
+
addNotice('error', set.problem);
|
|
194
|
+
approvalPolicy.setRules(set.rules);
|
|
195
|
+
setSavedRules(set.rules);
|
|
196
|
+
return set.rules;
|
|
197
|
+
}, [addNotice, approvalPolicy, cwd]);
|
|
198
|
+
// Rules live in the project, so a resumed session in another directory reloads them.
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
void refreshRules();
|
|
201
|
+
}, [refreshRules]);
|
|
168
202
|
const updateContextTokens = useCallback((tokens) => {
|
|
169
203
|
const rounded = Math.max(0, Math.round(tokens));
|
|
170
204
|
contextTokensRef.current = rounded;
|
|
@@ -250,7 +284,11 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
250
284
|
if (profile.apiKeyEnv && !key) {
|
|
251
285
|
return { ok: false, message: `API key is missing: $${profile.apiKeyEnv} is not set.` };
|
|
252
286
|
}
|
|
253
|
-
const result = await discoverModels({
|
|
287
|
+
const result = await discoverModels({
|
|
288
|
+
baseUrl: profile.baseUrl,
|
|
289
|
+
apiKey: key,
|
|
290
|
+
headers: profile.headers,
|
|
291
|
+
});
|
|
254
292
|
if (!result.ok)
|
|
255
293
|
return { ok: false, message: result.message };
|
|
256
294
|
if (result.models.length === 0) {
|
|
@@ -471,17 +509,38 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
471
509
|
pendingApprovalRef.current = null;
|
|
472
510
|
pendingResolverRef.current = null;
|
|
473
511
|
setPendingApproval(null);
|
|
512
|
+
setRuleNote(null);
|
|
474
513
|
if (!request || !resolver)
|
|
475
514
|
return;
|
|
515
|
+
const saveRule = (rule, note) => {
|
|
516
|
+
if (!rule)
|
|
517
|
+
return;
|
|
518
|
+
void addRule(cwd, rule)
|
|
519
|
+
.then((set) => {
|
|
520
|
+
approvalPolicy.setRules(set.rules);
|
|
521
|
+
setSavedRules(set.rules);
|
|
522
|
+
addNotice('info', note(set.path));
|
|
523
|
+
})
|
|
524
|
+
.catch((error) => {
|
|
525
|
+
addNotice('error', `Could not save the rule: ${error instanceof Error ? error.message : String(error)}`);
|
|
526
|
+
});
|
|
527
|
+
};
|
|
476
528
|
if (decision === 'allow-session') {
|
|
477
529
|
approvalPolicy.markSession(request.tool);
|
|
478
530
|
setAutoAllowed(approvalPolicy.list());
|
|
479
531
|
addNotice('info', `${request.tool} will run without asking. Use /allow to list, /allow clear to revoke.`);
|
|
480
532
|
}
|
|
481
|
-
|
|
482
|
-
|
|
533
|
+
else if (decision === 'allow-rule') {
|
|
534
|
+
saveRule(approvalPolicy.ruleFor(request), (file) => `Saved ${approvalPolicy.ruleFor(request)?.match} to ${file}. Edit or delete it with /rules.`);
|
|
535
|
+
}
|
|
536
|
+
else if (decision === 'deny-rule') {
|
|
537
|
+
saveRule(approvalPolicy.denyRuleFor(request), (file) => `Added a deny rule for ${request.subject} to ${file}. /rules lists and removes it.`);
|
|
538
|
+
}
|
|
539
|
+
resolver(decision === 'allow-rule' ? 'allow' : decision === 'deny-rule' ? 'deny' : decision);
|
|
540
|
+
}, [addNotice, approvalPolicy, cwd]);
|
|
483
541
|
const approve = useCallback((request) => {
|
|
484
|
-
|
|
542
|
+
const verdict = approvalPolicy.decide(request);
|
|
543
|
+
if (verdict === 'allow')
|
|
485
544
|
return Promise.resolve('allow');
|
|
486
545
|
if (abortRef.current?.signal.aborted)
|
|
487
546
|
return Promise.resolve('deny');
|
|
@@ -489,6 +548,9 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
489
548
|
pendingApprovalRef.current = request;
|
|
490
549
|
pendingResolverRef.current = resolve;
|
|
491
550
|
setPendingApproval(request);
|
|
551
|
+
setRuleNote(verdict === 'deny'
|
|
552
|
+
? `A saved rule denies this ${request.tool === 'run_command' ? 'command' : 'path'}.`
|
|
553
|
+
: null);
|
|
492
554
|
});
|
|
493
555
|
}, [approvalPolicy]);
|
|
494
556
|
const resolveQuestion = useCallback((answer) => {
|
|
@@ -662,8 +724,23 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
662
724
|
},
|
|
663
725
|
]);
|
|
664
726
|
break;
|
|
727
|
+
case 'tool-output':
|
|
728
|
+
setLiveTail(event.tail);
|
|
729
|
+
setItems((current) => {
|
|
730
|
+
const index = current.findIndex((item) => item.kind === 'tool' && item.callId === event.toolCall.id);
|
|
731
|
+
if (index === -1)
|
|
732
|
+
return current;
|
|
733
|
+
const item = current[index];
|
|
734
|
+
if (item?.kind !== 'tool' || item.liveTail === event.tail)
|
|
735
|
+
return current;
|
|
736
|
+
const next = [...current];
|
|
737
|
+
next[index] = { ...item, liveTail: event.tail };
|
|
738
|
+
return next;
|
|
739
|
+
});
|
|
740
|
+
break;
|
|
665
741
|
case 'tool-end':
|
|
666
742
|
setActiveTool(null);
|
|
743
|
+
setLiveTail(null);
|
|
667
744
|
setItems((current) => {
|
|
668
745
|
const index = current.findIndex((item) => item.kind === 'tool' && item.callId === event.toolCall.id && item.status === 'running');
|
|
669
746
|
if (index === -1)
|
|
@@ -675,6 +752,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
675
752
|
next[index] = {
|
|
676
753
|
...item,
|
|
677
754
|
status: event.result.status,
|
|
755
|
+
liveTail: undefined,
|
|
678
756
|
resultSummary: event.result.summary,
|
|
679
757
|
resultFull: event.result.content.slice(0, MAX_EXPANDED_TOOL_CHARS),
|
|
680
758
|
durationMs: event.durationMs,
|
|
@@ -702,6 +780,9 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
702
780
|
const totals = addUsage(sessionUsageRef.current, event.usage);
|
|
703
781
|
sessionUsageRef.current = totals;
|
|
704
782
|
setSessionUsage(totals);
|
|
783
|
+
const priced = addCost(sessionCostRef.current, event.usage, currentPriceRef.current);
|
|
784
|
+
sessionCostRef.current = priced;
|
|
785
|
+
setSessionCost(priced);
|
|
705
786
|
roundCompletionTokensRef.current = event.usage.completionTokens;
|
|
706
787
|
recomputeContext();
|
|
707
788
|
break;
|
|
@@ -815,7 +896,11 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
815
896
|
return;
|
|
816
897
|
}
|
|
817
898
|
addNotice('muted', `Fetching models from ${profile.baseUrl}…`);
|
|
818
|
-
const result = await discoverModels({
|
|
899
|
+
const result = await discoverModels({
|
|
900
|
+
baseUrl: profile.baseUrl,
|
|
901
|
+
apiKey: key,
|
|
902
|
+
headers: profile.headers,
|
|
903
|
+
});
|
|
819
904
|
if (!result.ok) {
|
|
820
905
|
addNotice('error', result.message);
|
|
821
906
|
return;
|
|
@@ -862,6 +947,9 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
862
947
|
const restoredUsage = record.usage ?? EMPTY_USAGE;
|
|
863
948
|
sessionUsageRef.current = restoredUsage;
|
|
864
949
|
setSessionUsage(restoredUsage);
|
|
950
|
+
const restored = restoredCost(restoredUsage, priceRef.current);
|
|
951
|
+
sessionCostRef.current = restored;
|
|
952
|
+
setSessionCost(restored);
|
|
865
953
|
setLastReply(null);
|
|
866
954
|
recomputeContext();
|
|
867
955
|
sessionRef.current = {
|
|
@@ -990,6 +1078,10 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
990
1078
|
? `Session usage: ↑ ${formatTokens(totals.promptTokens)} sent, ↓ ${formatTokens(totals.completionTokens)} received ` +
|
|
991
1079
|
`across ${totals.requests} API request${totals.requests === 1 ? '' : 's'} (saved with this session).`
|
|
992
1080
|
: 'Session usage: the endpoint has not reported token counts for this session yet.',
|
|
1081
|
+
hasPrice
|
|
1082
|
+
? `Estimated cost: ${sessionCost.complete ? '' : '~'}${formatCost(sessionCost.dollars)} ` +
|
|
1083
|
+
`($${currentPrice.input}/M in, $${currentPrice.output}/M out${profilePricing ? ', from the profile' : ', list price'}).`
|
|
1084
|
+
: 'Cost: no known list price for this model. Set "pricing" in the profile to track it.',
|
|
993
1085
|
`Auto-compaction runs at ${Math.round(COMPACT_THRESHOLD * 100)}% and keeps the last ${COMPACT_KEEP_USER_TURNS} user turns verbatim. /compact runs it now.`,
|
|
994
1086
|
].join('\n'));
|
|
995
1087
|
return;
|
|
@@ -1196,6 +1288,8 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1196
1288
|
usageRef.current = null;
|
|
1197
1289
|
sessionUsageRef.current = EMPTY_USAGE;
|
|
1198
1290
|
setSessionUsage(EMPTY_USAGE);
|
|
1291
|
+
sessionCostRef.current = { dollars: 0, complete: true };
|
|
1292
|
+
setSessionCost(sessionCostRef.current);
|
|
1199
1293
|
setLastReply(null);
|
|
1200
1294
|
updateContextTokens(0);
|
|
1201
1295
|
sessionRef.current = null;
|
|
@@ -1255,6 +1349,61 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1255
1349
|
: 'Mouse reporting off: click-drag selects text normally; use PgUp/PgDn to scroll.');
|
|
1256
1350
|
return;
|
|
1257
1351
|
}
|
|
1352
|
+
case '/mcp': {
|
|
1353
|
+
if (argument) {
|
|
1354
|
+
addNotice('error', 'Usage: /mcp (lists configured servers for this session)');
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
addNotice('info', formatMcpStatus(mcp ?? null, cwd));
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
case '/rules': {
|
|
1361
|
+
const rules = await refreshRules(true);
|
|
1362
|
+
if (argument === 'clear') {
|
|
1363
|
+
try {
|
|
1364
|
+
const file = await clearRules(cwd);
|
|
1365
|
+
approvalPolicy.setRules([]);
|
|
1366
|
+
setSavedRules([]);
|
|
1367
|
+
addNotice('info', `Removed ${file}. Every tool asks for approval again.`);
|
|
1368
|
+
}
|
|
1369
|
+
catch (error) {
|
|
1370
|
+
addNotice('error', `Could not clear the rules: ${error.message}`);
|
|
1371
|
+
}
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
if (argument?.startsWith('remove ')) {
|
|
1375
|
+
const index = Number(argument.slice('remove '.length).trim());
|
|
1376
|
+
const rule = rules[index - 1];
|
|
1377
|
+
if (!Number.isInteger(index) || !rule) {
|
|
1378
|
+
addNotice('error', `Usage: /rules remove <n>, where n is 1-${rules.length}.`);
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
try {
|
|
1382
|
+
const set = await removeRule(cwd, rule);
|
|
1383
|
+
approvalPolicy.setRules(set.rules);
|
|
1384
|
+
setSavedRules(set.rules);
|
|
1385
|
+
addNotice('info', `Removed "${rule.match}" for ${rule.tool}. ${set.rules.length} rules left.`);
|
|
1386
|
+
}
|
|
1387
|
+
catch (error) {
|
|
1388
|
+
addNotice('error', `Could not remove the rule: ${error.message}`);
|
|
1389
|
+
}
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
if (argument) {
|
|
1393
|
+
addNotice('error', 'Usage: /rules, /rules remove <n>, or /rules clear');
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
const numbered = rules.map((rule, index) => ` ${index + 1}. ${rule.action} ${rule.tool} ~ ${rule.match}`);
|
|
1397
|
+
addNotice('info', rules.length === 0
|
|
1398
|
+
? `No saved rules for this project. Choose [s] on an approval prompt to allow a pattern, or [d] to deny one.\nRules live in ${permissionsPath(cwd)}.`
|
|
1399
|
+
: [
|
|
1400
|
+
`Saved rules (${permissionsPath(cwd)}):`,
|
|
1401
|
+
...numbered,
|
|
1402
|
+
'',
|
|
1403
|
+
'/rules remove <n> deletes one; /rules clear deletes the file.',
|
|
1404
|
+
].join('\n'));
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1258
1407
|
case '/allow': {
|
|
1259
1408
|
if (argument === 'clear') {
|
|
1260
1409
|
resetAutoAllowed();
|
|
@@ -1536,7 +1685,7 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1536
1685
|
!pickerOpen &&
|
|
1537
1686
|
sessionPicker === null &&
|
|
1538
1687
|
!wizardActive &&
|
|
1539
|
-
wizardPrompt === null }), showUsageCard ? (_jsx(Box, { marginLeft: USAGE_CARD_GAP, flexShrink: 0, children: _jsx(UsageCard, { usage: sessionUsage, contextTokens: contextTokens, contextWindow: contextWindow, contextEstimated: usageRef.current === null, lastReply: lastReply, busy: busy }) })) : null] }), pendingApproval ? (_jsx(ApprovalPrompt, { request: pendingApproval, width: width, onDecision: resolveApproval })) : questionInline && pendingQuestion ? (_jsx(AskUserPrompt, { request: pendingQuestion, width: width, onAnswer: resolveQuestion, onCancel: () => resolveQuestion({ selected: [], cancelled: true }) })) : pickerInline ? (_jsx(ModelPicker, { config: runtimeConfig, activeProfile: profileName, width: width, onSelect: (name, model) => void selectModel(name, model), onRefresh: refreshProfileModels, onCancel: () => setPickerOpen(false) })) : sessionInline && sessionPicker ? (_jsx(SessionPicker, { cwd: cwd, data: sessionPicker, activeSessionId: sessionRef.current?.id ?? null, width: width, onSelect: handleSessionPick, onCancel: () => setSessionPicker(null) })) : (_jsx(Input, { disabled: pickerOpen || sessionPicker !== null || pendingQuestion !== null, width: width, mask: wizardPrompt?.mask, allowEmpty: wizardPrompt?.allowEmpty, fileMenu: !wizardActive && !wizardPrompt, loadFiles: loadFileIndex, maxRows: Math.max(1, Math.min(6, rows - 9)), history: wizardPrompt || wizardActive ? undefined : promptHistory, slashCommands: [...SLASH_COMMANDS, ...skillCommands], onPaletteChange: setPalette, onHeightChange: setInputRows, placeholder: pickerOpen
|
|
1688
|
+
wizardPrompt === null }), showUsageCard ? (_jsx(Box, { marginLeft: USAGE_CARD_GAP, flexShrink: 0, children: _jsx(UsageCard, { usage: sessionUsage, contextTokens: contextTokens, contextWindow: contextWindow, contextEstimated: usageRef.current === null, lastReply: lastReply, cost: hasPrice ? sessionCost : undefined, busy: busy }) })) : null] }), pendingApproval ? (_jsx(ApprovalPrompt, { request: pendingApproval, width: width, rulePattern: approvalPolicy.ruleFor(pendingApproval)?.match, ruleNote: ruleNote ?? undefined, maxPreviewLines: rows - 5 - extraInputRows - 12 >= 16 ? MAX_PREVIEW_LINES : 3, onDecision: resolveApproval })) : questionInline && pendingQuestion ? (_jsx(AskUserPrompt, { request: pendingQuestion, width: width, onAnswer: resolveQuestion, onCancel: () => resolveQuestion({ selected: [], cancelled: true }) })) : pickerInline ? (_jsx(ModelPicker, { config: runtimeConfig, activeProfile: profileName, width: width, onSelect: (name, model) => void selectModel(name, model), onRefresh: refreshProfileModels, onCancel: () => setPickerOpen(false) })) : sessionInline && sessionPicker ? (_jsx(SessionPicker, { cwd: cwd, data: sessionPicker, activeSessionId: sessionRef.current?.id ?? null, width: width, onSelect: handleSessionPick, onCancel: () => setSessionPicker(null) })) : (_jsx(Input, { disabled: pickerOpen || sessionPicker !== null || pendingQuestion !== null, width: width, mask: wizardPrompt?.mask, allowEmpty: wizardPrompt?.allowEmpty, fileMenu: !wizardActive && !wizardPrompt, loadFiles: loadFileIndex, maxRows: Math.max(1, Math.min(6, rows - 9)), history: wizardPrompt || wizardActive ? undefined : promptHistory, slashCommands: [...SLASH_COMMANDS, ...skillCommands], onPaletteChange: setPalette, onHeightChange: setInputRows, placeholder: pickerOpen
|
|
1540
1689
|
? 'Model picker open · Esc to close'
|
|
1541
1690
|
: sessionPicker
|
|
1542
1691
|
? 'Session picker open · Esc to close'
|
|
@@ -1550,6 +1699,6 @@ export function App({ config, baseConfig, overrides, configPath, configCreated,
|
|
|
1550
1699
|
? 'Kiro is working… type ahead, or Ctrl+C to cancel'
|
|
1551
1700
|
: wizardActive
|
|
1552
1701
|
? 'Working… Esc to cancel'
|
|
1553
|
-
: 'Ask Kiro to build or change something…', slashMenu: !wizardActive && !wizardPrompt, onSubmit: handleSubmit, onCancel: wizardActive ? cancelWizard : undefined }, wizardPrompt?.id ?? 0)), _jsx(StatusBar, { width: width, profile: profileName, model: activeProfile?.model ?? 'unknown', cwd: cwd, activity: activity, toolName: activeTool ?? undefined, busySince: busySince ?? undefined, queued: queuedCount > 0 ? queuedCount : undefined, yolo: yolo, autoAllowed: autoAllowed, quitHint: quitArmed, contextTokens: showUsageCard ? undefined : contextTokens, contextWindow: showUsageCard ? undefined : contextWindow }), pendingQuestion && questionPopup ? (_jsx(Box, { position: "absolute", marginTop: questionPopup.top, marginLeft: questionPopup.left, children: _jsx(AskUserPrompt, { request: pendingQuestion, width: questionPopup.width, height: questionPopup.height, onAnswer: resolveQuestion, onCancel: () => resolveQuestion({ selected: [], cancelled: true }) }) })) : pickerOpen && pickerPopup ? (_jsx(Box, { position: "absolute", marginTop: pickerPopup.top, marginLeft: pickerPopup.left, children: _jsx(ModelPicker, { config: runtimeConfig, activeProfile: profileName, width: pickerPopup.width, height: pickerPopup.height, onSelect: (name, model) => void selectModel(name, model), onRefresh: refreshProfileModels, onCancel: () => setPickerOpen(false) }) })) : sessionPicker && pickerPopup ? (_jsx(Box, { position: "absolute", marginTop: pickerPopup.top, marginLeft: pickerPopup.left, children: _jsx(SessionPicker, { cwd: cwd, data: sessionPicker, activeSessionId: sessionRef.current?.id ?? null, width: pickerPopup.width, height: pickerPopup.height, onSelect: handleSessionPick, onCancel: () => setSessionPicker(null) }) })) : null] }));
|
|
1702
|
+
: 'Ask Kiro to build or change something…', slashMenu: !wizardActive && !wizardPrompt, onSubmit: handleSubmit, onCancel: wizardActive ? cancelWizard : undefined }, wizardPrompt?.id ?? 0)), _jsx(StatusBar, { width: width, profile: profileName, model: activeProfile?.model ?? 'unknown', cwd: cwd, activity: activity, toolName: activeTool ?? undefined, liveTail: liveTail, busySince: busySince ?? undefined, queued: queuedCount > 0 ? queuedCount : undefined, yolo: yolo, autoAllowed: autoAllowed, quitHint: quitArmed, contextTokens: showUsageCard ? undefined : contextTokens, contextWindow: showUsageCard ? undefined : contextWindow }), pendingQuestion && questionPopup ? (_jsx(Box, { position: "absolute", marginTop: questionPopup.top, marginLeft: questionPopup.left, children: _jsx(AskUserPrompt, { request: pendingQuestion, width: questionPopup.width, height: questionPopup.height, onAnswer: resolveQuestion, onCancel: () => resolveQuestion({ selected: [], cancelled: true }) }) })) : pickerOpen && pickerPopup ? (_jsx(Box, { position: "absolute", marginTop: pickerPopup.top, marginLeft: pickerPopup.left, children: _jsx(ModelPicker, { config: runtimeConfig, activeProfile: profileName, width: pickerPopup.width, height: pickerPopup.height, onSelect: (name, model) => void selectModel(name, model), onRefresh: refreshProfileModels, onCancel: () => setPickerOpen(false) }) })) : sessionPicker && pickerPopup ? (_jsx(Box, { position: "absolute", marginTop: pickerPopup.top, marginLeft: pickerPopup.left, children: _jsx(SessionPicker, { cwd: cwd, data: sessionPicker, activeSessionId: sessionRef.current?.id ?? null, width: pickerPopup.width, height: pickerPopup.height, onSelect: handleSessionPick, onCancel: () => setSessionPicker(null) }) })) : null] }));
|
|
1554
1703
|
}
|
|
1555
1704
|
//# sourceMappingURL=App.js.map
|
|
@@ -1,48 +1,45 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text, useInput } from 'ink';
|
|
3
|
+
import { MAX_PREVIEW_LINES, windowPreview } from './approval-preview.js';
|
|
3
4
|
import { sanitizeText, truncateToWidth, wrapPlain } from './text.js';
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
function lineColor(line) {
|
|
6
|
+
if (line.startsWith('+'))
|
|
7
|
+
return 'green';
|
|
8
|
+
if (line.startsWith('-'))
|
|
9
|
+
return 'red';
|
|
10
|
+
if (line.startsWith('@@'))
|
|
11
|
+
return 'cyan';
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
export function ApprovalPrompt({ request, width, rulePattern, ruleNote, maxPreviewLines = MAX_PREVIEW_LINES, onDecision, }) {
|
|
6
15
|
useInput((input, key) => {
|
|
7
16
|
if (input === 'y' || input === 'Y')
|
|
8
17
|
onDecision('allow');
|
|
9
18
|
else if (input === 'a' || input === 'A')
|
|
10
19
|
onDecision('allow-session');
|
|
20
|
+
else if (input === 's' || input === 'S') {
|
|
21
|
+
if (rulePattern)
|
|
22
|
+
onDecision('allow-rule');
|
|
23
|
+
}
|
|
24
|
+
else if (input === 'd' || input === 'D') {
|
|
25
|
+
if (request.subject !== undefined)
|
|
26
|
+
onDecision('deny-rule');
|
|
27
|
+
}
|
|
11
28
|
else if (input === 'n' || input === 'N' || key.escape)
|
|
12
29
|
onDecision('deny');
|
|
13
30
|
});
|
|
14
31
|
const innerWidth = Math.max(10, width - 4);
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.slice(0, MAX_PREVIEW_LINES)
|
|
26
|
-
.map((line) => truncateToWidth(line, innerWidth));
|
|
27
|
-
truncated = rawDetail.length > MAX_PREVIEW_LINES;
|
|
28
|
-
}
|
|
29
|
-
if (truncated && previewLines.length > 0) {
|
|
30
|
-
const last = previewLines.length - 1;
|
|
31
|
-
previewLines[last] = `${truncateToWidth(previewLines[last] ?? '', innerWidth - 2)} …`;
|
|
32
|
-
}
|
|
33
|
-
if (previewLines.length === 0)
|
|
34
|
-
previewLines = ['(no preview)'];
|
|
35
|
-
return (_jsxs(Box, { flexDirection: "column", width: width, borderStyle: "round", borderColor: "yellow", paddingX: 1, flexShrink: 0, children: [_jsx(Text, { bold: true, color: "yellow", wrap: "truncate-end", children: `⚠ Approval needed · ${request.title}` }), request.warning ? (_jsx(Text, { color: "red", wrap: "truncate-end", children: `! ${request.warning}` })) : null, previewLines.map((line, index) => {
|
|
36
|
-
const color = request.tool !== 'run_command'
|
|
37
|
-
? line.startsWith('+') && !line.startsWith('+++')
|
|
38
|
-
? 'green'
|
|
39
|
-
: line.startsWith('-') && !line.startsWith('---')
|
|
40
|
-
? 'red'
|
|
41
|
-
: line.startsWith('@@')
|
|
42
|
-
? 'cyan'
|
|
43
|
-
: undefined
|
|
44
|
-
: undefined;
|
|
32
|
+
const detail = sanitizeText(request.detail ?? '').trimEnd();
|
|
33
|
+
const rawDetail = detail ? detail.split('\n') : [];
|
|
34
|
+
// Commands are wrapped so a long line does not hide the rest of the script;
|
|
35
|
+
// diffs are clipped, since a wrapped diff row reads as a different change.
|
|
36
|
+
const fitted = request.tool === 'run_command'
|
|
37
|
+
? rawDetail.flatMap((line) => wrapPlain(line, innerWidth))
|
|
38
|
+
: rawDetail.map((line) => truncateToWidth(line, innerWidth));
|
|
39
|
+
const previewLines = fitted.length === 0 ? ['(no preview yet)'] : windowPreview(fitted, request.tool, maxPreviewLines);
|
|
40
|
+
return (_jsxs(Box, { flexDirection: "column", width: width, borderStyle: "round", borderColor: "yellow", paddingX: 1, flexShrink: 0, children: [_jsx(Text, { bold: true, color: "yellow", wrap: "truncate-end", children: `⚠ Approval needed · ${request.title}` }), request.warning ? (_jsx(Text, { color: "red", wrap: "truncate-end", children: `! ${request.warning}` })) : null, ruleNote ? (_jsx(Text, { color: "magenta", wrap: "truncate-end", children: `! ${ruleNote}` })) : null, previewLines.map((line, index) => {
|
|
41
|
+
const color = request.tool === 'run_command' ? undefined : lineColor(line);
|
|
45
42
|
return (_jsx(Text, { color: color, dimColor: color === undefined, wrap: "truncate-end", children: line || ' ' }, index));
|
|
46
|
-
}), _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: "green", bold: true, children: "[y]" }), _jsx(Text, { children: " allow once " }), _jsx(Text, { color: "red", bold: true, children: "[n]" }), _jsx(Text, { children: " deny" })] }), _jsxs(Text, { dimColor: true, wrap: "truncate-end", children: [_jsx(Text, { color: "cyan", bold: true, children: "[a]" }), ' ', "
|
|
43
|
+
}), _jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: "green", bold: true, children: "[y]" }), _jsx(Text, { children: " allow once " }), _jsx(Text, { color: "red", bold: true, children: "[n]" }), _jsx(Text, { children: " deny" })] }), _jsxs(Text, { dimColor: true, wrap: "truncate-end", children: [_jsx(Text, { color: "cyan", bold: true, children: "[a]" }), ' ', "allow ", request.tool, " for this session", rulePattern ? (_jsxs(_Fragment, { children: [_jsx(Text, { children: " " }), _jsx(Text, { color: "green", bold: true, children: "[s]" }), _jsx(Text, { children: ` always allow ${rulePattern}` })] })) : null] }), request.subject !== undefined ? (_jsxs(Text, { dimColor: true, wrap: "truncate-end", children: [_jsx(Text, { color: "magenta", bold: true, children: "[d]" }), _jsx(Text, { children: ` always deny this ${request.tool === 'run_command' ? 'command' : 'path'}` })] })) : null] }));
|
|
47
44
|
}
|
|
48
45
|
//# sourceMappingURL=ApprovalPrompt.js.map
|
package/dist/ui/MessageList.js
CHANGED
|
@@ -57,6 +57,16 @@ function toolLines(item, width, expanded) {
|
|
|
57
57
|
suffix,
|
|
58
58
|
},
|
|
59
59
|
];
|
|
60
|
+
if (item.status === 'running' && item.liveTail) {
|
|
61
|
+
// The newest output line, so a long build shows progress instead of a spinner.
|
|
62
|
+
const livePrefix = ' ⎿ ';
|
|
63
|
+
lines.push({
|
|
64
|
+
prefix: livePrefix,
|
|
65
|
+
prefixDim: true,
|
|
66
|
+
text: truncateToWidth(item.liveTail, Math.max(1, width - displayWidth(livePrefix))),
|
|
67
|
+
dim: true,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
60
70
|
if (item.resultSummary && item.status !== 'running') {
|
|
61
71
|
const resultPrefix = ' ⎿ ';
|
|
62
72
|
const resultWidth = Math.max(1, width - displayWidth(resultPrefix));
|
package/dist/ui/StatusBar.js
CHANGED
|
@@ -14,7 +14,7 @@ function prettyCwd(cwd) {
|
|
|
14
14
|
}
|
|
15
15
|
return cwd;
|
|
16
16
|
}
|
|
17
|
-
export function StatusBar({ width, profile, model, cwd, activity, toolName, busySince, queued, yolo = false, autoAllowed = [], quitHint = false, contextTokens, contextWindow, }) {
|
|
17
|
+
export function StatusBar({ width, profile, model, cwd, activity, toolName, liveTail, busySince, queued, yolo = false, autoAllowed = [], quitHint = false, contextTokens, contextWindow, }) {
|
|
18
18
|
const busy = activity !== null;
|
|
19
19
|
const [frame, setFrame] = useState(0);
|
|
20
20
|
useEffect(() => {
|
|
@@ -58,7 +58,11 @@ export function StatusBar({ width, profile, model, cwd, activity, toolName, busy
|
|
|
58
58
|
const badgeWidth = badge === '' ? 0 : displayWidth(badge) + 2;
|
|
59
59
|
// The bar is indented to line up with the chat text, so budgets use the inner width.
|
|
60
60
|
const innerWidth = Math.max(10, width - 2);
|
|
61
|
-
|
|
61
|
+
// While a command runs, its newest output line says more than "running…".
|
|
62
|
+
const liveLine = activity === 'running' && liveTail ? liveTail.trim() : '';
|
|
63
|
+
const state = liveLine
|
|
64
|
+
? `${spinner}${liveLine}${elapsedNote}`
|
|
65
|
+
: `${spinner}${queueNote}${stateText}${elapsedNote}`;
|
|
62
66
|
const stateBudget = Math.max(4, Math.max(10, Math.floor(innerWidth / 2)) - badgeWidth);
|
|
63
67
|
const stateShown = truncateToWidth(state, stateBudget);
|
|
64
68
|
const restBudget = Math.max(0, innerWidth - badgeWidth - displayWidth(stateShown) - 2 - 6);
|
package/dist/ui/UsageCard.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from 'ink';
|
|
3
3
|
import { formatPercent, formatTokens } from '../agent/tokens.js';
|
|
4
|
+
import { formatCost } from '../cost.js';
|
|
4
5
|
import { formatDuration, truncateToWidth } from './text.js';
|
|
5
6
|
export const USAGE_CARD_WIDTH = 27;
|
|
6
7
|
/** Space between the transcript column and the card. */
|
|
@@ -18,7 +19,7 @@ export function contextBar(used, window, width) {
|
|
|
18
19
|
const filled = Math.min(size, Math.round(ratio * size));
|
|
19
20
|
return `${'█'.repeat(filled)}${'░'.repeat(size - filled)}`;
|
|
20
21
|
}
|
|
21
|
-
export function UsageCard({ usage, contextTokens, contextWindow, contextEstimated, lastReply, busy, width = USAGE_CARD_WIDTH, }) {
|
|
22
|
+
export function UsageCard({ usage, contextTokens, contextWindow, contextEstimated, lastReply, cost, busy, width = USAGE_CARD_WIDTH, }) {
|
|
22
23
|
const accent = busy ? 'cyan' : 'gray';
|
|
23
24
|
const innerWidth = Math.max(8, width - 4);
|
|
24
25
|
const title = truncateToWidth(`Usage · ${usage.requests} req`, innerWidth);
|
|
@@ -35,6 +36,6 @@ export function UsageCard({ usage, contextTokens, contextWindow, contextEstimate
|
|
|
35
36
|
const lastLine = truncateToWidth(lastReply
|
|
36
37
|
? `last ${formatDuration(lastReply.durationMs)}${speed ? ` · ${speed}` : ''}`
|
|
37
38
|
: 'no timed reply yet', innerWidth);
|
|
38
|
-
return (_jsxs(Box, { flexDirection: "column", width: width, borderStyle: "round", borderColor: accent, paddingX: 1, flexShrink: 0, children: [_jsx(Text, { bold: true, color: accent, wrap: "truncate-end", children: title }), _jsxs(Text, { wrap: "truncate-end", children: [_jsxs(Text, { color: "green", children: ["\u2191 ", prompt] }), _jsx(Text, { children: " " }), _jsxs(Text, { color: "blue", children: ["\u2193 ", completion] })] }), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: contextLine }), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: windowLine }), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: lastLine })] }));
|
|
39
|
+
return (_jsxs(Box, { flexDirection: "column", width: width, borderStyle: "round", borderColor: accent, paddingX: 1, flexShrink: 0, children: [_jsx(Text, { bold: true, color: accent, wrap: "truncate-end", children: title }), _jsxs(Text, { wrap: "truncate-end", children: [_jsxs(Text, { color: "green", children: ["\u2191 ", prompt] }), _jsx(Text, { children: " " }), _jsxs(Text, { color: "blue", children: ["\u2193 ", completion] })] }), cost ? (_jsxs(Text, { wrap: "truncate-end", children: [_jsx(Text, { color: "yellow", children: `${cost.complete ? '' : '~'}${formatCost(cost.dollars)}` }), _jsx(Text, { dimColor: true, children: cost.dollars === 0 ? ' free' : ' est.' })] })) : null, _jsx(Text, { dimColor: true, wrap: "truncate-end", children: contextLine }), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: windowLine }), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: lastLine })] }));
|
|
39
40
|
}
|
|
40
41
|
//# sourceMappingURL=UsageCard.js.map
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { evaluateRules, suggestRulePattern } from '../permissions.js';
|
|
2
|
+
/**
|
|
3
|
+
* Tracks which requests skip approval prompts, so the UI can show and revoke it.
|
|
4
|
+
* YOLO wins over everything; a saved deny rule still stops a request that YOLO
|
|
5
|
+
* would otherwise run, because denying is the more specific instruction.
|
|
6
|
+
*/
|
|
2
7
|
export class ApprovalPolicy {
|
|
3
8
|
yolo;
|
|
9
|
+
rules;
|
|
4
10
|
autoAllowed = new Set();
|
|
5
|
-
constructor(yolo = false) {
|
|
11
|
+
constructor(yolo = false, rules = []) {
|
|
6
12
|
this.yolo = yolo;
|
|
13
|
+
this.rules = rules;
|
|
7
14
|
}
|
|
8
15
|
markSession(tool) {
|
|
9
16
|
this.autoAllowed.add(tool);
|
|
@@ -18,5 +25,36 @@ export class ApprovalPolicy {
|
|
|
18
25
|
clear() {
|
|
19
26
|
this.autoAllowed.clear();
|
|
20
27
|
}
|
|
28
|
+
setRules(rules) {
|
|
29
|
+
this.rules = rules;
|
|
30
|
+
}
|
|
31
|
+
savedRules() {
|
|
32
|
+
return this.rules;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Saved rules first: a deny always applies, and an allow only pre-approves a
|
|
36
|
+
* request that stays inside the workspace.
|
|
37
|
+
*/
|
|
38
|
+
decide(request) {
|
|
39
|
+
// Undefined means the tool did not say; only an explicit false blocks a rule.
|
|
40
|
+
if (request.insideWorkspace === false) {
|
|
41
|
+
const denied = evaluateRules(this.rules, { tool: request.tool, subject: request.subject });
|
|
42
|
+
return denied === 'deny' ? 'deny' : 'ask';
|
|
43
|
+
}
|
|
44
|
+
return evaluateRules(this.rules, { tool: request.tool, subject: request.subject });
|
|
45
|
+
}
|
|
46
|
+
/** The rule a `[s]` press would save, or null when the request has no subject. */
|
|
47
|
+
ruleFor(request) {
|
|
48
|
+
if (request.subject === undefined)
|
|
49
|
+
return null;
|
|
50
|
+
const match = suggestRulePattern(request.tool, request.subject);
|
|
51
|
+
return match ? { tool: request.tool, match, action: 'allow' } : null;
|
|
52
|
+
}
|
|
53
|
+
/** The rule a `[d]` press would save: the exact subject, denied. */
|
|
54
|
+
denyRuleFor(request) {
|
|
55
|
+
if (request.subject === undefined)
|
|
56
|
+
return null;
|
|
57
|
+
return { tool: request.tool, match: request.subject, action: 'deny' };
|
|
58
|
+
}
|
|
21
59
|
}
|
|
22
60
|
//# sourceMappingURL=approval-policy.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows the rows shown in an approval prompt.
|
|
3
|
+
*
|
|
4
|
+
* The prompt asks the user to approve a change, so the preview must show what
|
|
5
|
+
* actually changes. A unified diff starts with header lines that would
|
|
6
|
+
* otherwise eat most of the budget, so headers are dropped and the first hunk
|
|
7
|
+
* is windowed around its first change. Long commands keep both ends, because
|
|
8
|
+
* the destructive half (`rm -rf`, `curl | sh`) is often the last line.
|
|
9
|
+
*
|
|
10
|
+
* Rows are already fitted to the prompt width before they get here.
|
|
11
|
+
*/
|
|
12
|
+
export const MAX_PREVIEW_LINES = 6;
|
|
13
|
+
const DIFF_HEADER = /^(---|\+\+\+|diff --git|index |new file |deleted file |similarity index|rename |Binary files)/;
|
|
14
|
+
function isHunk(line) {
|
|
15
|
+
return line.startsWith('@@');
|
|
16
|
+
}
|
|
17
|
+
function isChange(line) {
|
|
18
|
+
return ((line.startsWith('+') || line.startsWith('-')) &&
|
|
19
|
+
!line.startsWith('+++') &&
|
|
20
|
+
!line.startsWith('---'));
|
|
21
|
+
}
|
|
22
|
+
/** Hides the middle of a list, keeping `head` leading and the rest trailing. */
|
|
23
|
+
function windowed(lines, budget, head) {
|
|
24
|
+
if (lines.length <= budget)
|
|
25
|
+
return lines;
|
|
26
|
+
const showHead = Math.max(1, Math.min(head, budget - 1));
|
|
27
|
+
const showTail = Math.max(0, budget - showHead - 1);
|
|
28
|
+
const hidden = lines.length - showHead - showTail;
|
|
29
|
+
return [
|
|
30
|
+
...lines.slice(0, showHead),
|
|
31
|
+
`… ${hidden} line${hidden === 1 ? '' : 's'} hidden …`,
|
|
32
|
+
...(showTail > 0 ? lines.slice(lines.length - showTail) : []),
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
function diffBody(lines, budget) {
|
|
36
|
+
const hunks = lines.filter(isHunk);
|
|
37
|
+
const body = lines.filter((line) => !isHunk(line) && !DIFF_HEADER.test(line));
|
|
38
|
+
const hunkBudget = hunks.length > 0 ? 1 : 0;
|
|
39
|
+
const moreBudget = hunks.length > 1 ? 1 : 0;
|
|
40
|
+
const bodyBudget = Math.max(1, budget - hunkBudget - moreBudget);
|
|
41
|
+
let shown;
|
|
42
|
+
if (body.length <= bodyBudget) {
|
|
43
|
+
shown = body;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// Slide the window so the first change is visible, not just the context.
|
|
47
|
+
const visible = Math.max(1, bodyBudget - 1);
|
|
48
|
+
const firstChange = body.findIndex(isChange);
|
|
49
|
+
const start = Math.min(Math.max(0, body.length - visible), Math.max(0, firstChange === -1 ? 0 : Math.max(0, firstChange - 1)));
|
|
50
|
+
const slice = body.slice(start, start + visible);
|
|
51
|
+
const hiddenBefore = start;
|
|
52
|
+
const hiddenAfter = body.length - start - slice.length;
|
|
53
|
+
const parts = [
|
|
54
|
+
hiddenBefore > 0 ? `${hiddenBefore} before` : '',
|
|
55
|
+
hiddenAfter > 0 ? `${hiddenAfter} after` : '',
|
|
56
|
+
].filter(Boolean);
|
|
57
|
+
shown = [...slice, `… ${parts.join(', ')} hidden …`];
|
|
58
|
+
}
|
|
59
|
+
const out = [];
|
|
60
|
+
if (hunks.length > 0)
|
|
61
|
+
out.push(hunks[0]);
|
|
62
|
+
out.push(...shown);
|
|
63
|
+
if (hunks.length > 1)
|
|
64
|
+
out.push(`… ${hunks.length - 1} more hunk${hunks.length === 2 ? '' : 's'} …`);
|
|
65
|
+
return out.slice(0, budget);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns at most `budget` rows for the prompt. Diffs drop their file headers
|
|
69
|
+
* and hunk markers; anything else keeps both ends when it does not fit.
|
|
70
|
+
*/
|
|
71
|
+
export function windowPreview(rows, tool, budget = MAX_PREVIEW_LINES) {
|
|
72
|
+
const limit = Math.max(1, budget);
|
|
73
|
+
if (rows.length === 0)
|
|
74
|
+
return [];
|
|
75
|
+
if (tool !== 'run_command' && rows.some(isHunk)) {
|
|
76
|
+
return diffBody(rows, limit);
|
|
77
|
+
}
|
|
78
|
+
const head = Math.max(1, Math.ceil((limit - 1) / 2));
|
|
79
|
+
return windowed(rows, limit, head);
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=approval-preview.js.map
|
package/dist/ui/commands.js
CHANGED
|
@@ -2,6 +2,7 @@ export const SLASH_COMMANDS = [
|
|
|
2
2
|
{ name: '/help', description: 'show this help' },
|
|
3
3
|
{ name: '/model', usage: '[name | add | edit | remove | test | list]', description: 'list or switch models' },
|
|
4
4
|
{ name: '/skills', description: 'list installed skills and where they were found' },
|
|
5
|
+
{ name: '/mcp', description: 'list MCP servers, their tools, and any startup errors' },
|
|
5
6
|
{ name: '/skill', usage: '<name> [request]', description: 'load a skill and apply it to your next request' },
|
|
6
7
|
{ name: '/context', description: 'show approximate context usage' },
|
|
7
8
|
{ name: '/usage', description: 'show or hide the usage card' },
|
|
@@ -13,6 +14,7 @@ export const SLASH_COMMANDS = [
|
|
|
13
14
|
{ name: '/export', usage: '[file]', description: 'write the transcript to a Markdown file' },
|
|
14
15
|
{ name: '/mouse', description: 'toggle mouse reporting (wheel scroll vs text selection)' },
|
|
15
16
|
{ name: '/allow', usage: '[clear]', description: 'manage tools that skip approval' },
|
|
17
|
+
{ name: '/rules', usage: '[clear | remove <n>]', description: 'saved approval rules in .kiro/permissions.json' },
|
|
16
18
|
{ name: '/exit', description: 'quit Kiro' },
|
|
17
19
|
];
|
|
18
20
|
/** A skill called `/model` would be unreachable, so built-in names are claimed. */
|