@jun133/kitty 0.0.8 → 0.0.9
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 +59 -20
- package/dist/App-6FETP3LH.mjs +521 -0
- package/dist/chunk-3KMC6H5K.mjs +2701 -0
- package/dist/chunk-4BN45TQG.mjs +654 -0
- package/dist/chunk-6NJJLOY3.mjs +2129 -0
- package/dist/chunk-DFDOKON5.mjs +530 -0
- package/dist/chunk-ELBEXOR7.mjs +10020 -0
- package/dist/chunk-YSWK3BGL.mjs +84 -0
- package/dist/cli.js +1321 -655
- package/dist/cli.js.map +1 -1
- package/dist/interactive-KLW4JL7R.mjs +340 -0
- package/dist/oneShot-YHDMPFQM.mjs +54 -0
- package/dist/session-XKWJHRVY.mjs +66 -0
- package/dist/tui.mjs +728 -0
- package/package.json +8 -2
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InteractiveSessionDriver,
|
|
3
|
+
createTerminalLogWriter,
|
|
4
|
+
formatLocalCommandHelpLine,
|
|
5
|
+
listIntroLocalCommands,
|
|
6
|
+
mirrorInteractionShellToTerminalLog,
|
|
7
|
+
mirrorProcessOutputToTerminalLog,
|
|
8
|
+
renderKittyBanner,
|
|
9
|
+
ui
|
|
10
|
+
} from "./chunk-6NJJLOY3.mjs";
|
|
11
|
+
import "./chunk-4BN45TQG.mjs";
|
|
12
|
+
import {
|
|
13
|
+
createRuntimeUiAgentCallbacks
|
|
14
|
+
} from "./chunk-YSWK3BGL.mjs";
|
|
15
|
+
import {
|
|
16
|
+
colorRuntimeUiText,
|
|
17
|
+
loadProjectContext,
|
|
18
|
+
writeStdout
|
|
19
|
+
} from "./chunk-ELBEXOR7.mjs";
|
|
20
|
+
import "./chunk-3KMC6H5K.mjs";
|
|
21
|
+
|
|
22
|
+
// src/shell/cli/intro.ts
|
|
23
|
+
import chalk from "chalk";
|
|
24
|
+
function writeCliInteractiveIntro(options) {
|
|
25
|
+
options.output.plain(chalk.bold(chalk.greenBright(renderKittyBanner())));
|
|
26
|
+
options.output.dim(`session: ${options.session.id}`);
|
|
27
|
+
options.output.dim(`cwd: ${options.cwd}`);
|
|
28
|
+
if (options.toolsLabel) {
|
|
29
|
+
options.output.dim(`Tools: ${options.toolsLabel}`);
|
|
30
|
+
}
|
|
31
|
+
options.output.dim("Commands:");
|
|
32
|
+
for (const command of listIntroLocalCommands()) {
|
|
33
|
+
options.output.dim(formatLocalCommandHelpLine(command.id));
|
|
34
|
+
}
|
|
35
|
+
options.output.dim("");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/shell/cli/output.ts
|
|
39
|
+
function createCliOutputPort() {
|
|
40
|
+
let lastInterruptAt = 0;
|
|
41
|
+
return {
|
|
42
|
+
plain: ui.plain,
|
|
43
|
+
info: ui.info,
|
|
44
|
+
warn: ui.warn,
|
|
45
|
+
error: ui.error,
|
|
46
|
+
dim: ui.dim,
|
|
47
|
+
heading: ui.heading,
|
|
48
|
+
interrupt(message) {
|
|
49
|
+
const now = Date.now();
|
|
50
|
+
if (now - lastInterruptAt < 150) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
lastInterruptAt = now;
|
|
54
|
+
writeStdout("\n");
|
|
55
|
+
ui.warn(message);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/shell/cli/readlineInput.ts
|
|
61
|
+
import readline from "readline";
|
|
62
|
+
import process2 from "process";
|
|
63
|
+
async function readPersistentInput(promptLabel, onInterrupt) {
|
|
64
|
+
return new Promise((resolve) => {
|
|
65
|
+
const rl = readline.createInterface({
|
|
66
|
+
input: process2.stdin,
|
|
67
|
+
output: process2.stdout,
|
|
68
|
+
terminal: true
|
|
69
|
+
});
|
|
70
|
+
let settled = false;
|
|
71
|
+
const cleanup = () => {
|
|
72
|
+
rl.removeAllListeners("line");
|
|
73
|
+
rl.removeAllListeners("close");
|
|
74
|
+
rl.removeAllListeners("SIGINT");
|
|
75
|
+
};
|
|
76
|
+
const finish = (value) => {
|
|
77
|
+
if (settled) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
settled = true;
|
|
81
|
+
cleanup();
|
|
82
|
+
rl.close();
|
|
83
|
+
resolve(value);
|
|
84
|
+
};
|
|
85
|
+
rl.on("line", (line) => {
|
|
86
|
+
finish(line);
|
|
87
|
+
});
|
|
88
|
+
rl.on("SIGINT", () => {
|
|
89
|
+
onInterrupt();
|
|
90
|
+
rl.prompt();
|
|
91
|
+
});
|
|
92
|
+
rl.on("close", () => {
|
|
93
|
+
if (settled) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
settled = true;
|
|
97
|
+
cleanup();
|
|
98
|
+
resolve(null);
|
|
99
|
+
});
|
|
100
|
+
rl.setPrompt(promptLabel);
|
|
101
|
+
rl.prompt();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function createReadlineInputPort() {
|
|
105
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
106
|
+
let releaseProcessInterrupt = null;
|
|
107
|
+
const notifyInterrupt = () => {
|
|
108
|
+
for (const listener of listeners) {
|
|
109
|
+
listener();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const ensureProcessInterruptBinding = () => {
|
|
113
|
+
if (releaseProcessInterrupt) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const handler = () => {
|
|
117
|
+
notifyInterrupt();
|
|
118
|
+
};
|
|
119
|
+
process2.on("SIGINT", handler);
|
|
120
|
+
releaseProcessInterrupt = () => {
|
|
121
|
+
process2.off("SIGINT", handler);
|
|
122
|
+
releaseProcessInterrupt = null;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
const maybeReleaseProcessInterruptBinding = () => {
|
|
126
|
+
if (listeners.size > 0) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
releaseProcessInterrupt?.();
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
async readInput(promptLabel = "> ") {
|
|
133
|
+
const value = await readPersistentInput(promptLabel, notifyInterrupt);
|
|
134
|
+
return value === null ? { kind: "closed" } : { kind: "submit", value };
|
|
135
|
+
},
|
|
136
|
+
bindInterrupt(handler) {
|
|
137
|
+
listeners.add(handler);
|
|
138
|
+
ensureProcessInterruptBinding();
|
|
139
|
+
return () => {
|
|
140
|
+
listeners.delete(handler);
|
|
141
|
+
maybeReleaseProcessInterruptBinding();
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/shell/cli/spinner.ts
|
|
148
|
+
var ASCII_BLOCK_FRAMES = ["[\u25A0 ]", "[ \u25A0 ]", "[ \u25A0 ]", "[ \u25A0]", "[ \u25A0 ]", "[ \u25A0 ]"];
|
|
149
|
+
function createWaitingSpinner(options = {}) {
|
|
150
|
+
const label = options.label ?? "thinking";
|
|
151
|
+
const intervalMs = Math.max(40, options.intervalMs ?? 80);
|
|
152
|
+
const enabled = options.enabled ?? process.stdout.isTTY;
|
|
153
|
+
const frames = ASCII_BLOCK_FRAMES;
|
|
154
|
+
const write = options.write ?? ((text) => {
|
|
155
|
+
writeStdout(text);
|
|
156
|
+
});
|
|
157
|
+
let frameIndex = 0;
|
|
158
|
+
let timer = null;
|
|
159
|
+
let active = false;
|
|
160
|
+
let lastLength = 0;
|
|
161
|
+
const render = () => {
|
|
162
|
+
const frame = `${frames[frameIndex]} ${label}`;
|
|
163
|
+
frameIndex = (frameIndex + 1) % frames.length;
|
|
164
|
+
lastLength = frame.length;
|
|
165
|
+
write(`\r${colorRuntimeUiText("system", frame)}`);
|
|
166
|
+
};
|
|
167
|
+
const clear = () => {
|
|
168
|
+
if (lastLength <= 0) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
write(`\r${" ".repeat(lastLength)}\r`);
|
|
172
|
+
lastLength = 0;
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
start() {
|
|
176
|
+
if (!enabled || active) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
active = true;
|
|
180
|
+
render();
|
|
181
|
+
timer = setInterval(render, intervalMs);
|
|
182
|
+
timer.unref?.();
|
|
183
|
+
},
|
|
184
|
+
stop() {
|
|
185
|
+
if (!active) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
active = false;
|
|
189
|
+
if (timer) {
|
|
190
|
+
clearInterval(timer);
|
|
191
|
+
timer = null;
|
|
192
|
+
}
|
|
193
|
+
clear();
|
|
194
|
+
},
|
|
195
|
+
isActive() {
|
|
196
|
+
return active;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function wrapCallbacksWithSpinnerStop(callbacks, stopSpinner) {
|
|
201
|
+
return {
|
|
202
|
+
onStatus(text) {
|
|
203
|
+
stopSpinner();
|
|
204
|
+
callbacks.onStatus?.(text);
|
|
205
|
+
},
|
|
206
|
+
onAssistantDelta(delta) {
|
|
207
|
+
stopSpinner();
|
|
208
|
+
callbacks.onAssistantDelta?.(delta);
|
|
209
|
+
},
|
|
210
|
+
onAssistantStage(text) {
|
|
211
|
+
stopSpinner();
|
|
212
|
+
callbacks.onAssistantStage?.(text);
|
|
213
|
+
},
|
|
214
|
+
onAssistantDone(fullText) {
|
|
215
|
+
stopSpinner();
|
|
216
|
+
callbacks.onAssistantDone?.(fullText);
|
|
217
|
+
},
|
|
218
|
+
onAssistantText(text) {
|
|
219
|
+
stopSpinner();
|
|
220
|
+
callbacks.onAssistantText?.(text);
|
|
221
|
+
},
|
|
222
|
+
onReasoningDelta(delta) {
|
|
223
|
+
stopSpinner();
|
|
224
|
+
callbacks.onReasoningDelta?.(delta);
|
|
225
|
+
},
|
|
226
|
+
onReasoning(text) {
|
|
227
|
+
stopSpinner();
|
|
228
|
+
callbacks.onReasoning?.(text);
|
|
229
|
+
},
|
|
230
|
+
onToolCall(name, args) {
|
|
231
|
+
stopSpinner();
|
|
232
|
+
callbacks.onToolCall?.(name, args);
|
|
233
|
+
},
|
|
234
|
+
onToolResult(name, output) {
|
|
235
|
+
stopSpinner();
|
|
236
|
+
callbacks.onToolResult?.(name, output);
|
|
237
|
+
},
|
|
238
|
+
onToolError(name, error) {
|
|
239
|
+
stopSpinner();
|
|
240
|
+
callbacks.onToolError?.(name, error);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/shell/cli/turnDisplay.ts
|
|
246
|
+
function createCliTurnDisplay(options) {
|
|
247
|
+
const runtimeUi = createRuntimeUiAgentCallbacks({
|
|
248
|
+
channel: "lead",
|
|
249
|
+
config: options.config,
|
|
250
|
+
cwd: options.cwd,
|
|
251
|
+
assistantLeadingBlankLine: true,
|
|
252
|
+
assistantTrailingNewlines: "\n\n",
|
|
253
|
+
reasoningLeadingBlankLine: true,
|
|
254
|
+
toolArgsMaxChars: 200,
|
|
255
|
+
abortSignal: options.abortSignal
|
|
256
|
+
});
|
|
257
|
+
const waitingSpinner = createWaitingSpinner({ label: "thinking" });
|
|
258
|
+
const callbacks = wrapCallbacksWithSpinnerStop(runtimeUi.callbacks, () => {
|
|
259
|
+
waitingSpinner.stop();
|
|
260
|
+
});
|
|
261
|
+
callbacks.onModelWaitStart = () => {
|
|
262
|
+
waitingSpinner.start();
|
|
263
|
+
};
|
|
264
|
+
callbacks.onModelWaitStop = () => {
|
|
265
|
+
waitingSpinner.stop();
|
|
266
|
+
};
|
|
267
|
+
return {
|
|
268
|
+
callbacks,
|
|
269
|
+
flush() {
|
|
270
|
+
waitingSpinner.stop();
|
|
271
|
+
runtimeUi.flush();
|
|
272
|
+
},
|
|
273
|
+
dispose() {
|
|
274
|
+
waitingSpinner.stop();
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// src/shell/cli/shell.ts
|
|
280
|
+
function createReadlineInteractionShell() {
|
|
281
|
+
return {
|
|
282
|
+
input: createReadlineInputPort(),
|
|
283
|
+
output: createCliOutputPort(),
|
|
284
|
+
createTurnDisplay(options) {
|
|
285
|
+
return createCliTurnDisplay(options);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function createCliInteractionShell() {
|
|
290
|
+
return createReadlineInteractionShell();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/shell/cli/interactive.ts
|
|
294
|
+
async function startInteractiveChat(options, dependencies = {}) {
|
|
295
|
+
const shell = resolveInteractiveShell(dependencies);
|
|
296
|
+
const projectContext = await loadProjectContext(options.cwd, {
|
|
297
|
+
projectDocMaxBytes: options.config.projectDocMaxBytes
|
|
298
|
+
});
|
|
299
|
+
const terminalLogWriter = createTerminalLogWriter(projectContext.stateRootDir, options.session.id);
|
|
300
|
+
const disposeTerminalOutputMirror = mirrorProcessOutputToTerminalLog(terminalLogWriter);
|
|
301
|
+
const terminalShell = mirrorInteractionShellToTerminalLog(
|
|
302
|
+
shell,
|
|
303
|
+
terminalLogWriter
|
|
304
|
+
);
|
|
305
|
+
(dependencies.writeIntro ?? ((context) => {
|
|
306
|
+
writeCliInteractiveIntro({
|
|
307
|
+
cwd: context.cwd,
|
|
308
|
+
session: context.session,
|
|
309
|
+
output: context.shell.output
|
|
310
|
+
});
|
|
311
|
+
}))({
|
|
312
|
+
cwd: options.cwd,
|
|
313
|
+
config: options.config,
|
|
314
|
+
session: options.session,
|
|
315
|
+
shell: terminalShell
|
|
316
|
+
});
|
|
317
|
+
const driver = dependencies.createDriver?.({
|
|
318
|
+
...options,
|
|
319
|
+
shell: terminalShell
|
|
320
|
+
}) ?? new InteractiveSessionDriver({
|
|
321
|
+
...options,
|
|
322
|
+
shell: terminalShell
|
|
323
|
+
});
|
|
324
|
+
try {
|
|
325
|
+
await driver.run();
|
|
326
|
+
} finally {
|
|
327
|
+
disposeTerminalOutputMirror();
|
|
328
|
+
terminalShell.dispose?.();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function resolveInteractiveShell(dependencies) {
|
|
332
|
+
if (dependencies.shell) {
|
|
333
|
+
return dependencies.shell;
|
|
334
|
+
}
|
|
335
|
+
const createShell = dependencies.createShell ?? createCliInteractionShell;
|
|
336
|
+
return createShell();
|
|
337
|
+
}
|
|
338
|
+
export {
|
|
339
|
+
startInteractiveChat
|
|
340
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRuntimeUiAgentCallbacks
|
|
3
|
+
} from "./chunk-YSWK3BGL.mjs";
|
|
4
|
+
import {
|
|
5
|
+
runHostTurn
|
|
6
|
+
} from "./chunk-ELBEXOR7.mjs";
|
|
7
|
+
import "./chunk-3KMC6H5K.mjs";
|
|
8
|
+
|
|
9
|
+
// src/cli/oneShot.ts
|
|
10
|
+
async function runOneShotPrompt(prompt, cwd, config, session, sessionStore, options = {}) {
|
|
11
|
+
void options;
|
|
12
|
+
const runtimeUi = createRuntimeUiAgentCallbacks({
|
|
13
|
+
channel: "lead",
|
|
14
|
+
config,
|
|
15
|
+
cwd,
|
|
16
|
+
assistantLeadingBlankLine: false,
|
|
17
|
+
assistantTrailingNewlines: "\n",
|
|
18
|
+
reasoningLeadingBlankLine: false,
|
|
19
|
+
toolArgsMaxChars: 160
|
|
20
|
+
});
|
|
21
|
+
const outcome = await runHostTurn({
|
|
22
|
+
host: "cli",
|
|
23
|
+
input: prompt,
|
|
24
|
+
cwd,
|
|
25
|
+
config,
|
|
26
|
+
session,
|
|
27
|
+
sessionStore,
|
|
28
|
+
callbacks: runtimeUi.callbacks
|
|
29
|
+
});
|
|
30
|
+
if (outcome.status === "failed" || outcome.status === "aborted") {
|
|
31
|
+
runtimeUi.flush();
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
session: outcome.session,
|
|
35
|
+
closeout: buildOneShotCloseoutReport(
|
|
36
|
+
outcome.session,
|
|
37
|
+
outcome.result?.transition ?? null,
|
|
38
|
+
outcome.status === "failed" || outcome.status === "aborted" ? outcome.errorMessage : void 0
|
|
39
|
+
)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function buildOneShotCloseoutReport(session, terminalTransition, defaultUnfinishedReason) {
|
|
43
|
+
const completed = terminalTransition?.action === "finalize";
|
|
44
|
+
return {
|
|
45
|
+
sessionId: session.id,
|
|
46
|
+
completed,
|
|
47
|
+
unfinishedReason: completed ? void 0 : terminalTransition?.reason.code ?? defaultUnfinishedReason ?? "unfinished",
|
|
48
|
+
terminalTransition
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
buildOneShotCloseoutReport,
|
|
53
|
+
runOneShotPrompt
|
|
54
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InProcessSessionStore,
|
|
3
|
+
SessionStore,
|
|
4
|
+
createSessionRecord
|
|
5
|
+
} from "./chunk-4BN45TQG.mjs";
|
|
6
|
+
import {
|
|
7
|
+
applyCurrentTurnFrame,
|
|
8
|
+
buildChatMessages,
|
|
9
|
+
collapseContentParts,
|
|
10
|
+
createEmptySessionDiff,
|
|
11
|
+
createEmptyTaskState,
|
|
12
|
+
createInternalReminder,
|
|
13
|
+
createMessage,
|
|
14
|
+
createToolMessage,
|
|
15
|
+
deriveTaskState,
|
|
16
|
+
expandStartToToolBoundary,
|
|
17
|
+
findLatestUserIndex,
|
|
18
|
+
findLatestUserInputIndex,
|
|
19
|
+
formatTaskStateBlock,
|
|
20
|
+
isAssistantMessageInLatestTurn,
|
|
21
|
+
isInternalMessage,
|
|
22
|
+
modelUsesReasoningContent,
|
|
23
|
+
normalizeSessionDiff,
|
|
24
|
+
normalizeSessionDiffState,
|
|
25
|
+
normalizeSessionRecord,
|
|
26
|
+
normalizeTaskState,
|
|
27
|
+
noteSessionDiff,
|
|
28
|
+
oneLine,
|
|
29
|
+
readReasoningContent,
|
|
30
|
+
readUserInput,
|
|
31
|
+
shouldIncludeStoredAssistantReasoning,
|
|
32
|
+
sliceCurrentUserInputFrame,
|
|
33
|
+
toChatMessage
|
|
34
|
+
} from "./chunk-3KMC6H5K.mjs";
|
|
35
|
+
export {
|
|
36
|
+
InProcessSessionStore,
|
|
37
|
+
SessionStore,
|
|
38
|
+
applyCurrentTurnFrame,
|
|
39
|
+
buildChatMessages,
|
|
40
|
+
collapseContentParts,
|
|
41
|
+
createEmptySessionDiff,
|
|
42
|
+
createEmptyTaskState,
|
|
43
|
+
createInternalReminder,
|
|
44
|
+
createMessage,
|
|
45
|
+
createSessionRecord,
|
|
46
|
+
createToolMessage,
|
|
47
|
+
deriveTaskState,
|
|
48
|
+
expandStartToToolBoundary,
|
|
49
|
+
findLatestUserIndex,
|
|
50
|
+
findLatestUserInputIndex,
|
|
51
|
+
formatTaskStateBlock,
|
|
52
|
+
isAssistantMessageInLatestTurn,
|
|
53
|
+
isInternalMessage,
|
|
54
|
+
modelUsesReasoningContent,
|
|
55
|
+
normalizeSessionDiff,
|
|
56
|
+
normalizeSessionDiffState,
|
|
57
|
+
normalizeSessionRecord,
|
|
58
|
+
normalizeTaskState,
|
|
59
|
+
noteSessionDiff,
|
|
60
|
+
oneLine,
|
|
61
|
+
readReasoningContent,
|
|
62
|
+
readUserInput,
|
|
63
|
+
shouldIncludeStoredAssistantReasoning,
|
|
64
|
+
sliceCurrentUserInputFrame,
|
|
65
|
+
toChatMessage
|
|
66
|
+
};
|