@nightloom/isy 1.0.1 → 1.0.3

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.
Files changed (152) hide show
  1. package/README.md +1 -1
  2. package/dist/agents/claude.js +18 -7
  3. package/dist/agents/claude.js.map +1 -1
  4. package/dist/agents/codex-records.js +16 -2
  5. package/dist/agents/codex-records.js.map +1 -1
  6. package/dist/agents/index.d.ts +16 -5
  7. package/dist/agents/index.js +21 -6
  8. package/dist/agents/index.js.map +1 -1
  9. package/dist/agents/kimi-cli-wire.d.ts +17 -0
  10. package/dist/agents/kimi-cli-wire.js +312 -0
  11. package/dist/agents/kimi-cli-wire.js.map +1 -0
  12. package/dist/agents/kimi-config.d.ts +29 -0
  13. package/dist/agents/kimi-config.js +193 -0
  14. package/dist/agents/kimi-config.js.map +1 -0
  15. package/dist/agents/kimi-records.d.ts +0 -6
  16. package/dist/agents/kimi-records.js +51 -31
  17. package/dist/agents/kimi-records.js.map +1 -1
  18. package/dist/agents/kimi-tools.d.ts +30 -0
  19. package/dist/agents/kimi-tools.js +100 -0
  20. package/dist/agents/kimi-tools.js.map +1 -0
  21. package/dist/agents/kimi-wire.d.ts +8 -0
  22. package/dist/agents/kimi-wire.js +245 -80
  23. package/dist/agents/kimi-wire.js.map +1 -1
  24. package/dist/agents/kimi.d.ts +13 -2
  25. package/dist/agents/kimi.js +633 -114
  26. package/dist/agents/kimi.js.map +1 -1
  27. package/dist/agents/timeline.d.ts +36 -0
  28. package/dist/agents/timeline.js +61 -0
  29. package/dist/agents/timeline.js.map +1 -0
  30. package/dist/agents/types.d.ts +12 -0
  31. package/dist/api.d.ts +3 -0
  32. package/dist/api.js +1 -1
  33. package/dist/api.js.map +1 -1
  34. package/dist/commands/analyze.d.ts +2 -0
  35. package/dist/commands/analyze.js +63 -6
  36. package/dist/commands/analyze.js.map +1 -1
  37. package/dist/commands/check.js +11 -0
  38. package/dist/commands/check.js.map +1 -1
  39. package/dist/commands/health.js +2 -2
  40. package/dist/commands/health.js.map +1 -1
  41. package/dist/commands/init.js +25 -2
  42. package/dist/commands/init.js.map +1 -1
  43. package/dist/commands/upload.d.ts +2 -0
  44. package/dist/commands/upload.js +38 -7
  45. package/dist/commands/upload.js.map +1 -1
  46. package/dist/detectors.js +40 -5
  47. package/dist/detectors.js.map +1 -1
  48. package/dist/hook.d.ts +12 -5
  49. package/dist/hook.js +73 -17
  50. package/dist/hook.js.map +1 -1
  51. package/dist/lines.d.ts +8 -0
  52. package/dist/lines.js +32 -0
  53. package/dist/lines.js.map +1 -0
  54. package/dist/mask-paths.js +31 -15
  55. package/dist/mask-paths.js.map +1 -1
  56. package/dist/parser.d.ts +41 -0
  57. package/dist/parser.js +345 -36
  58. package/dist/parser.js.map +1 -1
  59. package/dist/paths.d.ts +4 -0
  60. package/dist/paths.js +39 -39
  61. package/dist/paths.js.map +1 -1
  62. package/dist/plan.d.ts +3 -1
  63. package/dist/plan.js +5 -1
  64. package/dist/plan.js.map +1 -1
  65. package/dist/queue.d.ts +14 -2
  66. package/dist/queue.js +25 -3
  67. package/dist/queue.js.map +1 -1
  68. package/dist/redact.d.ts +17 -0
  69. package/dist/redact.js +202 -12
  70. package/dist/redact.js.map +1 -1
  71. package/dist/state.d.ts +15 -6
  72. package/dist/state.js +25 -9
  73. package/dist/state.js.map +1 -1
  74. package/dist/subagents.d.ts +53 -0
  75. package/dist/subagents.js +243 -0
  76. package/dist/subagents.js.map +1 -0
  77. package/dist/test/check.test.js +25 -3
  78. package/dist/test/check.test.js.map +1 -1
  79. package/dist/test/codex.test.js +21 -0
  80. package/dist/test/codex.test.js.map +1 -1
  81. package/dist/test/commit.test.js +9 -1
  82. package/dist/test/commit.test.js.map +1 -1
  83. package/dist/test/hook.test.js +66 -2
  84. package/dist/test/hook.test.js.map +1 -1
  85. package/dist/test/init.test.d.ts +1 -0
  86. package/dist/test/init.test.js +102 -0
  87. package/dist/test/init.test.js.map +1 -0
  88. package/dist/test/kimi-cli.test.d.ts +1 -0
  89. package/dist/test/kimi-cli.test.js +231 -0
  90. package/dist/test/kimi-cli.test.js.map +1 -0
  91. package/dist/test/kimi-code.test.d.ts +1 -0
  92. package/dist/test/kimi-code.test.js +302 -0
  93. package/dist/test/kimi-code.test.js.map +1 -0
  94. package/dist/test/kimi-config.test.d.ts +1 -0
  95. package/dist/test/kimi-config.test.js +224 -0
  96. package/dist/test/kimi-config.test.js.map +1 -0
  97. package/dist/test/kimi-hook.test.d.ts +1 -0
  98. package/dist/test/kimi-hook.test.js +163 -0
  99. package/dist/test/kimi-hook.test.js.map +1 -0
  100. package/dist/test/kimi-listing.test.d.ts +1 -0
  101. package/dist/test/kimi-listing.test.js +193 -0
  102. package/dist/test/kimi-listing.test.js.map +1 -0
  103. package/dist/test/kimi.test.js +52 -7
  104. package/dist/test/kimi.test.js.map +1 -1
  105. package/dist/test/mask-paths.test.js +31 -0
  106. package/dist/test/mask-paths.test.js.map +1 -1
  107. package/dist/test/parser.test.js +208 -5
  108. package/dist/test/parser.test.js.map +1 -1
  109. package/dist/test/plan.test.js +7 -6
  110. package/dist/test/plan.test.js.map +1 -1
  111. package/dist/test/redact.test.js +245 -8
  112. package/dist/test/redact.test.js.map +1 -1
  113. package/dist/test/stage0.test.js +49 -0
  114. package/dist/test/stage0.test.js.map +1 -1
  115. package/dist/test/subagents.test.d.ts +1 -0
  116. package/dist/test/subagents.test.js +290 -0
  117. package/dist/test/subagents.test.js.map +1 -0
  118. package/dist/test/sweep.test.js +25 -0
  119. package/dist/test/sweep.test.js.map +1 -1
  120. package/dist/test/upload.test.js +68 -6
  121. package/dist/test/upload.test.js.map +1 -1
  122. package/dist/types.d.ts +16 -0
  123. package/package.json +5 -3
  124. package/src/agents/claude.ts +17 -7
  125. package/src/agents/codex-records.ts +17 -2
  126. package/src/agents/index.ts +21 -6
  127. package/src/agents/kimi-cli-wire.ts +350 -0
  128. package/src/agents/kimi-config.ts +210 -0
  129. package/src/agents/kimi-records.ts +52 -29
  130. package/src/agents/kimi-tools.ts +128 -0
  131. package/src/agents/kimi-wire.ts +270 -82
  132. package/src/agents/kimi.ts +653 -113
  133. package/src/agents/timeline.ts +68 -0
  134. package/src/agents/types.ts +12 -0
  135. package/src/api.ts +5 -2
  136. package/src/commands/analyze.ts +62 -6
  137. package/src/commands/check.ts +11 -0
  138. package/src/commands/health.ts +2 -2
  139. package/src/commands/init.ts +26 -2
  140. package/src/commands/upload.ts +46 -7
  141. package/src/detectors.ts +39 -5
  142. package/src/hook.ts +81 -24
  143. package/src/lines.ts +31 -0
  144. package/src/mask-paths.ts +31 -14
  145. package/src/parser.ts +356 -35
  146. package/src/paths.ts +36 -33
  147. package/src/plan.ts +4 -1
  148. package/src/queue.ts +30 -4
  149. package/src/redact.ts +218 -15
  150. package/src/state.ts +34 -9
  151. package/src/subagents.ts +292 -0
  152. package/src/types.ts +16 -0
@@ -1,4 +1,4 @@
1
- import { EDIT_TOOLS } from "../parser.js";
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
- /** Reasoning, wherever this Kimi build happens to put it. */
52
- function reasoningText(line: Record<string, unknown>): string | undefined {
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 = asString(part.thinking) ?? asString(part.text) ?? asString(part.reasoning);
64
- if (text) parts.push(text);
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.join("\n") : undefined;
70
+ return parts.length > 0 ? parts : undefined;
67
71
  }
68
72
 
69
- /**
70
- * Kimi names the file argument `path` where Claude names it `file_path`.
71
- * Renaming here keeps parser.ts and detectors.ts free of Kimi knowledge.
72
- * Grep and Glob keep `path`, exactly as they do in Claude Code.
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
- blocks.push({ type: "tool_use", id, name, input: renameArgs(name, input) });
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: { stdout: text },
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 reasoning = reasoningText(line);
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
- blocks.push(...toolUseBlocks(line));
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
+ }