@nightloom/isy 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/agents/claude.js +18 -7
- package/dist/agents/claude.js.map +1 -1
- package/dist/agents/codex-records.js +3 -1
- package/dist/agents/codex-records.js.map +1 -1
- package/dist/agents/index.d.ts +16 -5
- package/dist/agents/index.js +21 -6
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/kimi-cli-wire.d.ts +17 -0
- package/dist/agents/kimi-cli-wire.js +312 -0
- package/dist/agents/kimi-cli-wire.js.map +1 -0
- package/dist/agents/kimi-config.d.ts +29 -0
- package/dist/agents/kimi-config.js +193 -0
- package/dist/agents/kimi-config.js.map +1 -0
- package/dist/agents/kimi-records.d.ts +0 -6
- package/dist/agents/kimi-records.js +51 -31
- package/dist/agents/kimi-records.js.map +1 -1
- package/dist/agents/kimi-tools.d.ts +30 -0
- package/dist/agents/kimi-tools.js +100 -0
- package/dist/agents/kimi-tools.js.map +1 -0
- package/dist/agents/kimi-wire.d.ts +8 -0
- package/dist/agents/kimi-wire.js +245 -80
- package/dist/agents/kimi-wire.js.map +1 -1
- package/dist/agents/kimi.d.ts +13 -2
- package/dist/agents/kimi.js +633 -114
- package/dist/agents/kimi.js.map +1 -1
- package/dist/agents/timeline.d.ts +36 -0
- package/dist/agents/timeline.js +61 -0
- package/dist/agents/timeline.js.map +1 -0
- package/dist/agents/types.d.ts +12 -0
- package/dist/commands/analyze.d.ts +2 -0
- package/dist/commands/analyze.js +63 -6
- package/dist/commands/analyze.js.map +1 -1
- package/dist/commands/check.js +11 -0
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/init.js +17 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/upload.js +8 -4
- package/dist/commands/upload.js.map +1 -1
- package/dist/detectors.js +40 -5
- package/dist/detectors.js.map +1 -1
- package/dist/hook.d.ts +12 -5
- package/dist/hook.js +73 -17
- package/dist/hook.js.map +1 -1
- package/dist/lines.d.ts +8 -0
- package/dist/lines.js +32 -0
- package/dist/lines.js.map +1 -0
- package/dist/parser.d.ts +41 -0
- package/dist/parser.js +328 -32
- package/dist/parser.js.map +1 -1
- package/dist/paths.d.ts +4 -0
- package/dist/paths.js +39 -39
- package/dist/paths.js.map +1 -1
- package/dist/redact.d.ts +10 -0
- package/dist/redact.js +49 -8
- package/dist/redact.js.map +1 -1
- package/dist/state.d.ts +6 -3
- package/dist/state.js +21 -5
- package/dist/state.js.map +1 -1
- package/dist/subagents.d.ts +49 -0
- package/dist/subagents.js +237 -0
- package/dist/subagents.js.map +1 -0
- package/dist/test/check.test.js +25 -3
- package/dist/test/check.test.js.map +1 -1
- package/dist/test/codex.test.js +6 -0
- package/dist/test/codex.test.js.map +1 -1
- package/dist/test/commit.test.js +9 -1
- package/dist/test/commit.test.js.map +1 -1
- package/dist/test/hook.test.js +66 -2
- package/dist/test/hook.test.js.map +1 -1
- package/dist/test/init.test.d.ts +1 -0
- package/dist/test/init.test.js +94 -0
- package/dist/test/init.test.js.map +1 -0
- package/dist/test/kimi-cli.test.d.ts +1 -0
- package/dist/test/kimi-cli.test.js +231 -0
- package/dist/test/kimi-cli.test.js.map +1 -0
- package/dist/test/kimi-code.test.d.ts +1 -0
- package/dist/test/kimi-code.test.js +302 -0
- package/dist/test/kimi-code.test.js.map +1 -0
- package/dist/test/kimi-config.test.d.ts +1 -0
- package/dist/test/kimi-config.test.js +224 -0
- package/dist/test/kimi-config.test.js.map +1 -0
- package/dist/test/kimi-hook.test.d.ts +1 -0
- package/dist/test/kimi-hook.test.js +163 -0
- package/dist/test/kimi-hook.test.js.map +1 -0
- package/dist/test/kimi-listing.test.d.ts +1 -0
- package/dist/test/kimi-listing.test.js +193 -0
- package/dist/test/kimi-listing.test.js.map +1 -0
- package/dist/test/kimi.test.js +52 -7
- package/dist/test/kimi.test.js.map +1 -1
- package/dist/test/parser.test.js +192 -5
- package/dist/test/parser.test.js.map +1 -1
- package/dist/test/redact.test.js +71 -7
- package/dist/test/redact.test.js.map +1 -1
- package/dist/test/stage0.test.js +49 -0
- package/dist/test/stage0.test.js.map +1 -1
- package/dist/test/subagents.test.d.ts +1 -0
- package/dist/test/subagents.test.js +272 -0
- package/dist/test/subagents.test.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/package.json +3 -2
- package/src/agents/claude.ts +17 -7
- package/src/agents/codex-records.ts +3 -1
- package/src/agents/index.ts +21 -6
- package/src/agents/kimi-cli-wire.ts +350 -0
- package/src/agents/kimi-config.ts +210 -0
- package/src/agents/kimi-records.ts +52 -29
- package/src/agents/kimi-tools.ts +128 -0
- package/src/agents/kimi-wire.ts +270 -82
- package/src/agents/kimi.ts +653 -113
- package/src/agents/timeline.ts +68 -0
- package/src/agents/types.ts +12 -0
- package/src/commands/analyze.ts +62 -6
- package/src/commands/check.ts +11 -0
- package/src/commands/init.ts +18 -2
- package/src/commands/upload.ts +8 -4
- package/src/detectors.ts +39 -5
- package/src/hook.ts +81 -24
- package/src/lines.ts +31 -0
- package/src/parser.ts +343 -31
- package/src/paths.ts +36 -33
- package/src/redact.ts +53 -10
- package/src/state.ts +24 -5
- package/src/subagents.ts +283 -0
- package/src/types.ts +16 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { claudeTool, wholeFileRead } from "./kimi-tools.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Kimi CLI keeps a session as `context.jsonl` (kosong Message records) plus an
|
|
@@ -14,9 +14,6 @@ import { EDIT_TOOLS } from "../parser.js";
|
|
|
14
14
|
/** Kimi's own bookkeeping roles, which are not conversation turns. */
|
|
15
15
|
const CONTROL_ROLES = new Set(["_system_prompt", "_usage", "_checkpoint"]);
|
|
16
16
|
|
|
17
|
-
/** Tools whose file argument Claude calls `file_path` and Kimi calls `path`. */
|
|
18
|
-
const PATH_ARG_TOOLS = new Set([...EDIT_TOOLS, "Read"]);
|
|
19
|
-
|
|
20
17
|
function isObject(value: unknown): value is Record<string, unknown> {
|
|
21
18
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22
19
|
}
|
|
@@ -48,10 +45,17 @@ function contentText(content: unknown): string {
|
|
|
48
45
|
return parts.join("\n");
|
|
49
46
|
}
|
|
50
47
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Reasoning, wherever this Kimi build happens to put it: a `reasoning_content`
|
|
50
|
+
* field, or content parts — `think` is Kimi CLI's own (`{type: "think", think}`),
|
|
51
|
+
* and the only one it writes, so reading `thinking` and `reasoning` alone lost
|
|
52
|
+
* every thought a real session recorded. A part left empty still says the model
|
|
53
|
+
* reasoned (the parser counts it as hidden), so it comes through as an empty
|
|
54
|
+
* block rather than as nothing.
|
|
55
|
+
*/
|
|
56
|
+
function reasoningParts(line: Record<string, unknown>): string[] | undefined {
|
|
53
57
|
const direct = asString(line.reasoning_content) ?? asString(line.reasoning);
|
|
54
|
-
if (direct) return direct;
|
|
58
|
+
if (direct) return [direct];
|
|
55
59
|
|
|
56
60
|
const content = line.content;
|
|
57
61
|
if (!Array.isArray(content)) return undefined;
|
|
@@ -59,25 +63,17 @@ function reasoningText(line: Record<string, unknown>): string | undefined {
|
|
|
59
63
|
const parts: string[] = [];
|
|
60
64
|
for (const part of content) {
|
|
61
65
|
if (!isObject(part)) continue;
|
|
62
|
-
if (part.type !== "thinking" && part.type !== "reasoning") continue;
|
|
63
|
-
const text =
|
|
64
|
-
|
|
66
|
+
if (part.type !== "think" && part.type !== "thinking" && part.type !== "reasoning") continue;
|
|
67
|
+
const text = [part.think, part.thinking, part.text, part.reasoning].find((value) => typeof value === "string");
|
|
68
|
+
parts.push(typeof text === "string" ? text : "");
|
|
65
69
|
}
|
|
66
|
-
return parts.length > 0 ? parts
|
|
70
|
+
return parts.length > 0 ? parts : undefined;
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
*/
|
|
74
|
-
export function renameArgs(tool: string, input: Record<string, unknown>): Record<string, unknown> {
|
|
75
|
-
if (!PATH_ARG_TOOLS.has(tool)) return input;
|
|
76
|
-
if (typeof input.path !== "string" || typeof input.file_path === "string") return input;
|
|
77
|
-
|
|
78
|
-
const { path, ...rest } = input;
|
|
79
|
-
return { ...rest, file_path: path };
|
|
80
|
-
}
|
|
73
|
+
/** Kimi CLI prefixes a failed call's result with this, and has no other error flag here. */
|
|
74
|
+
const FAILED_RESULT = /^<system>ERROR:/;
|
|
75
|
+
/** The status line Kimi CLI puts ahead of a result: `<system>…</system>`. */
|
|
76
|
+
const RESULT_STATUS = /^<system>([\s\S]*?)<\/system>/;
|
|
81
77
|
|
|
82
78
|
/** Tool calls, whether OpenAI-style `tool_calls` or inline content parts. */
|
|
83
79
|
function toolUseBlocks(line: Record<string, unknown>): Record<string, unknown>[] {
|
|
@@ -112,7 +108,8 @@ function toolUseBlocks(line: Record<string, unknown>): Record<string, unknown>[]
|
|
|
112
108
|
}
|
|
113
109
|
}
|
|
114
110
|
|
|
115
|
-
|
|
111
|
+
const use = claudeTool(name, input);
|
|
112
|
+
blocks.push({ type: "tool_use", id, name: use.name, input: use.input });
|
|
116
113
|
}
|
|
117
114
|
return blocks;
|
|
118
115
|
}
|
|
@@ -210,6 +207,9 @@ export function toClaudeRecords(context: Iterable<string>, options: KimiOptions)
|
|
|
210
207
|
return uuid;
|
|
211
208
|
};
|
|
212
209
|
|
|
210
|
+
/** What each call asked for, by id: a `ReadFile` result is only the file given its call. */
|
|
211
|
+
const calls = new Map<string, Record<string, unknown>>();
|
|
212
|
+
|
|
213
213
|
const emitTurn = (line: Record<string, unknown>, parent: string | null): string | undefined => {
|
|
214
214
|
const role = String(line.role);
|
|
215
215
|
const timestamp = asString(line.timestamp) ?? asString(line.created_at);
|
|
@@ -218,15 +218,37 @@ export function toClaudeRecords(context: Iterable<string>, options: KimiOptions)
|
|
|
218
218
|
const id = asString(line.tool_call_id);
|
|
219
219
|
if (!id) return undefined;
|
|
220
220
|
const text = contentText(line.content);
|
|
221
|
+
const failed = FAILED_RESULT.test(text);
|
|
222
|
+
// What the tool printed, without the status line Kimi put ahead of it.
|
|
223
|
+
const status = RESULT_STATUS.exec(text);
|
|
224
|
+
const output = status ? text.slice(status[0].length).replace(/^\n/, "") : text;
|
|
225
|
+
const call = calls.get(id);
|
|
226
|
+
const file =
|
|
227
|
+
call?.name === "Read" && !failed && typeof call.input === "object" && status
|
|
228
|
+
? wholeFileRead(output, status[1]!)
|
|
229
|
+
: undefined;
|
|
230
|
+
const filePath = isObject(call?.input) ? call.input.file_path : undefined;
|
|
221
231
|
return emit(
|
|
222
232
|
{
|
|
223
233
|
type: "user",
|
|
224
234
|
timestamp,
|
|
225
235
|
message: {
|
|
226
236
|
role: "user",
|
|
227
|
-
content: [{ type: "tool_result", tool_use_id: id, content: text }],
|
|
237
|
+
content: [{ type: "tool_result", tool_use_id: id, content: text, ...(failed ? { is_error: true } : {}) }],
|
|
228
238
|
},
|
|
229
|
-
toolUseResult:
|
|
239
|
+
toolUseResult:
|
|
240
|
+
file !== undefined && typeof filePath === "string"
|
|
241
|
+
? {
|
|
242
|
+
type: "text",
|
|
243
|
+
file: {
|
|
244
|
+
filePath,
|
|
245
|
+
content: file,
|
|
246
|
+
numLines: file.split("\n").length,
|
|
247
|
+
startLine: 1,
|
|
248
|
+
totalLines: file.split("\n").length,
|
|
249
|
+
},
|
|
250
|
+
}
|
|
251
|
+
: { stdout: output },
|
|
230
252
|
},
|
|
231
253
|
parent,
|
|
232
254
|
);
|
|
@@ -234,11 +256,12 @@ export function toClaudeRecords(context: Iterable<string>, options: KimiOptions)
|
|
|
234
256
|
|
|
235
257
|
if (role === "assistant") {
|
|
236
258
|
const blocks: Record<string, unknown>[] = [];
|
|
237
|
-
const
|
|
238
|
-
if (reasoning) blocks.push({ type: "thinking", thinking: reasoning });
|
|
259
|
+
for (const thinking of reasoningParts(line) ?? []) blocks.push({ type: "thinking", thinking });
|
|
239
260
|
const text = contentText(line.content);
|
|
240
261
|
if (text) blocks.push({ type: "text", text });
|
|
241
|
-
|
|
262
|
+
const uses = toolUseBlocks(line);
|
|
263
|
+
for (const use of uses) calls.set(String(use.id), use);
|
|
264
|
+
blocks.push(...uses);
|
|
242
265
|
if (blocks.length === 0) return undefined;
|
|
243
266
|
|
|
244
267
|
return emit(
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { EDIT_TOOLS } from "../parser.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Kimi's tools under the names and arguments Claude Code gives the same tools.
|
|
5
|
+
*
|
|
6
|
+
* The detectors read `Bash` for commands, `Edit`/`Write`/`MultiEdit` for edits
|
|
7
|
+
* and `Read` for what the agent looked at, with the file under `file_path`.
|
|
8
|
+
* Kimi CLI calls these `Shell`, `StrReplaceFile`, `WriteFile` and `ReadFile`,
|
|
9
|
+
* with the file under `path` — so an untranslated Kimi session showed stage 0
|
|
10
|
+
* no command it ran, no file it edited and none it read. Kimi Code took
|
|
11
|
+
* Claude's names but kept Kimi's arguments: its `Read` takes `path`,
|
|
12
|
+
* `line_offset` and `n_lines`, its `Write` a `mode`. Translating here, once,
|
|
13
|
+
* keeps parser.ts and detectors.ts free of Kimi knowledge, the way
|
|
14
|
+
* `codex-records.ts` does for Codex.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export interface ClaudeToolUse {
|
|
18
|
+
name: string;
|
|
19
|
+
input: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isObject(value: unknown): value is Record<string, unknown> {
|
|
23
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Only the arguments that are there: a translated call must not grow `undefined` keys. */
|
|
27
|
+
function defined(input: Record<string, unknown>): Record<string, unknown> {
|
|
28
|
+
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `StrReplaceFile`'s `{old, new, replace_all}` as one step of Claude's `Edit`. */
|
|
32
|
+
function step(edit: Record<string, unknown>): Record<string, unknown> {
|
|
33
|
+
return defined({ old_string: edit.old, new_string: edit.new, replace_all: edit.replace_all });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function claudeTool(name: string, args: Record<string, unknown>): ClaudeToolUse {
|
|
37
|
+
const { path, ...rest } = args;
|
|
38
|
+
// A Claude name with Kimi's arguments is Kimi Code's, and reads as Kimi CLI's tool of that job.
|
|
39
|
+
const kimiArgs = typeof path === "string" && args.file_path === undefined;
|
|
40
|
+
const tool = kimiArgs && name === "Read" ? "ReadFile" : kimiArgs && name === "Write" ? "WriteFile" : name;
|
|
41
|
+
|
|
42
|
+
switch (tool) {
|
|
43
|
+
case "Shell":
|
|
44
|
+
return { name: "Bash", input: args };
|
|
45
|
+
|
|
46
|
+
case "ReadFile":
|
|
47
|
+
case "ReadMediaFile": {
|
|
48
|
+
const { line_offset, n_lines, ...other } = rest;
|
|
49
|
+
return { name: "Read", input: defined({ file_path: path, offset: line_offset, limit: n_lines, ...other }) };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
case "WriteFile": {
|
|
53
|
+
const { content, mode, ...other } = rest;
|
|
54
|
+
// An append adds to a file whose content the call does not show, which is
|
|
55
|
+
// an edit with nothing replaced — not a `Write`, whose content the revert
|
|
56
|
+
// tracker takes for the whole file.
|
|
57
|
+
if (mode === "append") return { name: "Edit", input: defined({ file_path: path, new_string: content, ...other }) };
|
|
58
|
+
return { name: "Write", input: defined({ file_path: path, content, ...other }) };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
case "StrReplaceFile": {
|
|
62
|
+
const { edit, ...other } = rest;
|
|
63
|
+
if (Array.isArray(edit)) {
|
|
64
|
+
return { name: "MultiEdit", input: defined({ file_path: path, edits: edit.filter(isObject).map(step), ...other }) };
|
|
65
|
+
}
|
|
66
|
+
return { name: "Edit", input: defined({ file_path: path, ...(isObject(edit) ? step(edit) : {}), ...other }) };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
case "Glob": {
|
|
70
|
+
// Kimi CLI names the folder `directory`; Kimi Code, like Claude Code, `path`.
|
|
71
|
+
const { directory, ...other } = args;
|
|
72
|
+
return { name: "Glob", input: directory === undefined ? args : defined({ ...other, path: directory }) };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
case "SearchWeb":
|
|
76
|
+
return { name: "WebSearch", input: args };
|
|
77
|
+
case "FetchURL":
|
|
78
|
+
return { name: "WebFetch", input: args };
|
|
79
|
+
case "SetTodoList":
|
|
80
|
+
case "TodoList":
|
|
81
|
+
return { name: "TodoWrite", input: args };
|
|
82
|
+
// Older builds delegated through `Task`, as Claude Code once did.
|
|
83
|
+
case "Task":
|
|
84
|
+
return { name: "Agent", input: args };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Claude's edit names with Kimi's argument. Grep and Glob take `path` in
|
|
88
|
+
// Claude Code too and are left alone.
|
|
89
|
+
if (EDIT_TOOLS.has(name) && kimiArgs) return { name, input: { ...rest, file_path: path } };
|
|
90
|
+
return { name, input: args };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Anything in a read's status line that says the text is not the file as it is
|
|
95
|
+
* on disk: a line or the output cut short (Kimi CLI: `truncated`, `Max … reached`;
|
|
96
|
+
* Kimi Code: `Character limit reached`, a line `fragment`), or bytes shown other
|
|
97
|
+
* than they are (`\r` escapes, a lossy or transcoded decoding).
|
|
98
|
+
*/
|
|
99
|
+
const NOT_THE_FILE =
|
|
100
|
+
/truncated|Max \d+ (?:lines|bytes) reached|Character limit reached|fragment|carriage-return|Lossy|Detected file encoding/;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The file a Kimi `ReadFile` (Kimi Code: `Read`) returned, when it returned all
|
|
104
|
+
* of it.
|
|
105
|
+
*
|
|
106
|
+
* Kimi numbers every line the way `cat -n` does — `%6d\t<line>` in Kimi CLI,
|
|
107
|
+
* `<n>\t<line>` in Kimi Code — and says in its status line how much it read.
|
|
108
|
+
* Only a read that started at line 1, reached the end and cut nothing short is
|
|
109
|
+
* the file: anything less, fed to the revert tracker as the file's content,
|
|
110
|
+
* would invent reverts (`detectors.ts:trackContent`). Kimi Code leaves the last
|
|
111
|
+
* newline off; the tracker compares content with trailing newlines trimmed.
|
|
112
|
+
*/
|
|
113
|
+
export function wholeFileRead(output: string, message: string): string | undefined {
|
|
114
|
+
const read = /^(\d+) lines read from file starting from line 1\. Total lines in file: (\d+)\./.exec(message);
|
|
115
|
+
if (!read || read[1] !== read[2]) return undefined;
|
|
116
|
+
if (NOT_THE_FILE.test(message)) return undefined;
|
|
117
|
+
|
|
118
|
+
const lines = output.split(/(?<=\n)/);
|
|
119
|
+
if (lines.length !== Number(read[1])) return undefined;
|
|
120
|
+
|
|
121
|
+
const content: string[] = [];
|
|
122
|
+
for (const [index, line] of lines.entries()) {
|
|
123
|
+
const numbered = /^ *(\d+)\t/.exec(line);
|
|
124
|
+
if (!numbered || Number(numbered[1]) !== index + 1) return undefined;
|
|
125
|
+
content.push(line.slice(numbered[0].length));
|
|
126
|
+
}
|
|
127
|
+
return content.join("");
|
|
128
|
+
}
|