modkh 0.0.0-stage → 0.2.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.
Files changed (327) hide show
  1. package/README.md +66 -2
  2. package/dist/agent/bundled-skills.d.ts +13 -0
  3. package/dist/agent/bundled-skills.js +95 -0
  4. package/dist/agent/compaction.d.ts +53 -0
  5. package/dist/agent/compaction.js +191 -0
  6. package/dist/agent/images.d.ts +10 -0
  7. package/dist/agent/images.js +33 -0
  8. package/dist/agent/loop.d.ts +103 -0
  9. package/dist/agent/loop.js +267 -0
  10. package/dist/agent/skills.d.ts +26 -0
  11. package/dist/agent/skills.js +190 -0
  12. package/dist/agent/types.d.ts +137 -0
  13. package/dist/agent/types.js +12 -0
  14. package/dist/cli/agenticreplay.d.ts +1 -0
  15. package/dist/cli/agenticreplay.js +66 -0
  16. package/dist/cli/agents.d.ts +8 -0
  17. package/dist/cli/agents.js +12 -0
  18. package/dist/cli/answer-markdown.d.ts +3 -0
  19. package/dist/cli/answer-markdown.js +29 -0
  20. package/dist/cli/approval.d.ts +29 -0
  21. package/dist/cli/approval.js +92 -0
  22. package/dist/cli/catalog.d.ts +37 -0
  23. package/dist/cli/catalog.js +46 -0
  24. package/dist/cli/chat.d.ts +18 -0
  25. package/dist/cli/chat.js +1061 -0
  26. package/dist/cli/clipboard.d.ts +11 -0
  27. package/dist/cli/clipboard.js +82 -0
  28. package/dist/cli/color.d.ts +59 -0
  29. package/dist/cli/color.js +244 -0
  30. package/dist/cli/compaction-settings.d.ts +21 -0
  31. package/dist/cli/compaction-settings.js +54 -0
  32. package/dist/cli/completion-art.d.ts +2 -0
  33. package/dist/cli/completion-art.js +62 -0
  34. package/dist/cli/config.d.ts +50 -0
  35. package/dist/cli/config.js +192 -0
  36. package/dist/cli/editor.d.ts +23 -0
  37. package/dist/cli/editor.js +115 -0
  38. package/dist/cli/file-mentions.d.ts +14 -0
  39. package/dist/cli/file-mentions.js +141 -0
  40. package/dist/cli/head-checks.d.ts +41 -0
  41. package/dist/cli/head-checks.js +146 -0
  42. package/dist/cli/initial-connection.d.ts +7 -0
  43. package/dist/cli/initial-connection.js +20 -0
  44. package/dist/cli/keys.d.ts +29 -0
  45. package/dist/cli/keys.js +107 -0
  46. package/dist/cli/language.d.ts +1 -0
  47. package/dist/cli/language.js +105 -0
  48. package/dist/cli/limits.d.ts +13 -0
  49. package/dist/cli/limits.js +19 -0
  50. package/dist/cli/lines.d.ts +18 -0
  51. package/dist/cli/lines.js +80 -0
  52. package/dist/cli/model-catalog.d.ts +16 -0
  53. package/dist/cli/model-catalog.js +130 -0
  54. package/dist/cli/models.d.ts +4 -0
  55. package/dist/cli/models.js +101 -0
  56. package/dist/cli/official-models.d.ts +6 -0
  57. package/dist/cli/official-models.js +77 -0
  58. package/dist/cli/pdf.d.ts +8 -0
  59. package/dist/cli/pdf.js +71 -0
  60. package/dist/cli/permissions.d.ts +25 -0
  61. package/dist/cli/permissions.js +30 -0
  62. package/dist/cli/plugins.d.ts +1 -0
  63. package/dist/cli/plugins.js +53 -0
  64. package/dist/cli/providers.d.ts +10 -0
  65. package/dist/cli/providers.js +82 -0
  66. package/dist/cli/shell-display.d.ts +6 -0
  67. package/dist/cli/shell-display.js +35 -0
  68. package/dist/cli/stateright.d.ts +1 -0
  69. package/dist/cli/stateright.js +37 -0
  70. package/dist/cli/terminal-mouse.d.ts +21 -0
  71. package/dist/cli/terminal-mouse.js +51 -0
  72. package/dist/cli/terminal.d.ts +231 -0
  73. package/dist/cli/terminal.js +1417 -0
  74. package/dist/cli/tool-display.d.ts +9 -0
  75. package/dist/cli/tool-display.js +87 -0
  76. package/dist/cli/transcript-selection.d.ts +22 -0
  77. package/dist/cli/transcript-selection.js +75 -0
  78. package/dist/cli/usage.d.ts +22 -0
  79. package/dist/cli/usage.js +117 -0
  80. package/dist/cli/waiting-nyan.d.ts +3 -0
  81. package/dist/cli/waiting-nyan.js +17 -0
  82. package/dist/cli/waiting-whales.d.ts +3 -0
  83. package/dist/cli/waiting-whales.js +24 -0
  84. package/dist/index.d.ts +11 -0
  85. package/dist/index.js +186 -0
  86. package/dist/language/catalog.d.ts +44 -0
  87. package/dist/language/catalog.js +100 -0
  88. package/dist/language/commonlisp-bundled.d.ts +11 -0
  89. package/dist/language/commonlisp-bundled.js +22 -0
  90. package/dist/language/commonlisp-dependencies.d.ts +16 -0
  91. package/dist/language/commonlisp-dependencies.js +68 -0
  92. package/dist/language/commonlisp-install.d.ts +15 -0
  93. package/dist/language/commonlisp-install.js +214 -0
  94. package/dist/language/commonlisp-reader.d.ts +17 -0
  95. package/dist/language/commonlisp-reader.js +47 -0
  96. package/dist/language/commonlisp-systems.d.ts +3 -0
  97. package/dist/language/commonlisp-systems.js +32 -0
  98. package/dist/language/commonlisp-tls.d.ts +10 -0
  99. package/dist/language/commonlisp-tls.js +51 -0
  100. package/dist/language/detect.d.ts +29 -0
  101. package/dist/language/detect.js +103 -0
  102. package/dist/language/grammars/LICENSE +24 -0
  103. package/dist/language/grammars/manifest.json +76 -0
  104. package/dist/language/grammars/tree-sitter-c.wasm +0 -0
  105. package/dist/language/grammars/tree-sitter-cpp.wasm +0 -0
  106. package/dist/language/grammars/tree-sitter-css.wasm +0 -0
  107. package/dist/language/grammars/tree-sitter-html.wasm +0 -0
  108. package/dist/language/grammars/tree-sitter-javascript.wasm +0 -0
  109. package/dist/language/grammars/tree-sitter-php.wasm +0 -0
  110. package/dist/language/grammars/tree-sitter-python.wasm +0 -0
  111. package/dist/language/grammars/tree-sitter-ruby.wasm +0 -0
  112. package/dist/language/grammars/tree-sitter-rust.wasm +0 -0
  113. package/dist/language/grammars/tree-sitter-swift.wasm +0 -0
  114. package/dist/language/grammars/tree-sitter-tsx.wasm +0 -0
  115. package/dist/language/grammars/tree-sitter-typescript.wasm +0 -0
  116. package/dist/language/install.d.ts +50 -0
  117. package/dist/language/install.js +293 -0
  118. package/dist/language/lsp/client.d.ts +97 -0
  119. package/dist/language/lsp/client.js +340 -0
  120. package/dist/language/lsp/pool.d.ts +75 -0
  121. package/dist/language/lsp/pool.js +140 -0
  122. package/dist/language/lsp/service.d.ts +50 -0
  123. package/dist/language/lsp/service.js +174 -0
  124. package/dist/language/native.d.ts +8 -0
  125. package/dist/language/native.js +100 -0
  126. package/dist/language/platform.d.ts +14 -0
  127. package/dist/language/platform.js +20 -0
  128. package/dist/language/positions.d.ts +20 -0
  129. package/dist/language/positions.js +46 -0
  130. package/dist/language/syntax/assets.d.ts +9 -0
  131. package/dist/language/syntax/assets.js +73 -0
  132. package/dist/language/syntax/parser.d.ts +33 -0
  133. package/dist/language/syntax/parser.js +162 -0
  134. package/dist/language/typescript-capability.d.ts +6 -0
  135. package/dist/language/typescript-capability.js +42 -0
  136. package/dist/lisp/builtin-agents.d.ts +5 -0
  137. package/dist/lisp/builtin-agents.js +52 -0
  138. package/dist/lisp/config.d.ts +25 -0
  139. package/dist/lisp/config.js +202 -0
  140. package/dist/lisp/routing.d.ts +5 -0
  141. package/dist/lisp/routing.js +24 -0
  142. package/dist/lisp/runtime.d.ts +26 -0
  143. package/dist/lisp/runtime.js +107 -0
  144. package/dist/memory/kiokuko.d.ts +32 -0
  145. package/dist/memory/kiokuko.js +102 -0
  146. package/dist/memory/mcp.d.ts +38 -0
  147. package/dist/memory/mcp.js +211 -0
  148. package/dist/model/ai-sdk.d.ts +27 -0
  149. package/dist/model/ai-sdk.js +185 -0
  150. package/dist/model/chatgpt/login.d.ts +42 -0
  151. package/dist/model/chatgpt/login.js +180 -0
  152. package/dist/model/chatgpt/responses.d.ts +41 -0
  153. package/dist/model/chatgpt/responses.js +254 -0
  154. package/dist/model/chatgpt/tokens.d.ts +11 -0
  155. package/dist/model/chatgpt/tokens.js +50 -0
  156. package/dist/model/connection.d.ts +6 -0
  157. package/dist/model/connection.js +67 -0
  158. package/dist/model/context-window.d.ts +3 -0
  159. package/dist/model/context-window.js +64 -0
  160. package/dist/model/context.d.ts +11 -0
  161. package/dist/model/context.js +69 -0
  162. package/dist/model/factory.d.ts +27 -0
  163. package/dist/model/factory.js +89 -0
  164. package/dist/model/fixed.d.ts +17 -0
  165. package/dist/model/fixed.js +41 -0
  166. package/dist/model/harness-profile.d.ts +6 -0
  167. package/dist/model/harness-profile.js +23 -0
  168. package/dist/model/providers.d.ts +32 -0
  169. package/dist/model/providers.js +72 -0
  170. package/dist/model/reasoning.d.ts +16 -0
  171. package/dist/model/reasoning.js +84 -0
  172. package/dist/model/record-fetch.d.ts +2 -0
  173. package/dist/model/record-fetch.js +19 -0
  174. package/dist/plugins/api.d.ts +60 -0
  175. package/dist/plugins/api.js +1 -0
  176. package/dist/plugins/manager.d.ts +35 -0
  177. package/dist/plugins/manager.js +280 -0
  178. package/dist/plugins/package.d.ts +13 -0
  179. package/dist/plugins/package.js +99 -0
  180. package/dist/plugins/registry.d.ts +8 -0
  181. package/dist/plugins/registry.js +14 -0
  182. package/dist/session/store.d.ts +93 -0
  183. package/dist/session/store.js +311 -0
  184. package/dist/session/workspace.d.ts +19 -0
  185. package/dist/session/workspace.js +73 -0
  186. package/dist/subagents/head-assignment.d.ts +11 -0
  187. package/dist/subagents/head-assignment.js +47 -0
  188. package/dist/subagents/limits.d.ts +4 -0
  189. package/dist/subagents/limits.js +6 -0
  190. package/dist/subagents/processes.d.ts +18 -0
  191. package/dist/subagents/processes.js +73 -0
  192. package/dist/subagents/request.d.ts +4 -0
  193. package/dist/subagents/request.js +38 -0
  194. package/dist/subagents/service.d.ts +73 -0
  195. package/dist/subagents/service.js +645 -0
  196. package/dist/subagents/settings.d.ts +10 -0
  197. package/dist/subagents/settings.js +32 -0
  198. package/dist/subagents/types.d.ts +63 -0
  199. package/dist/subagents/types.js +1 -0
  200. package/dist/subagents/verification.d.ts +34 -0
  201. package/dist/subagents/verification.js +215 -0
  202. package/dist/tools/browse.d.ts +13 -0
  203. package/dist/tools/browse.js +117 -0
  204. package/dist/tools/browser-capability.d.ts +3 -0
  205. package/dist/tools/browser-capability.js +29 -0
  206. package/dist/tools/diff.d.ts +6 -0
  207. package/dist/tools/diff.js +82 -0
  208. package/dist/tools/edit.d.ts +3 -0
  209. package/dist/tools/edit.js +152 -0
  210. package/dist/tools/files.d.ts +6 -0
  211. package/dist/tools/files.js +96 -0
  212. package/dist/tools/formal-input.d.ts +6 -0
  213. package/dist/tools/formal-input.js +29 -0
  214. package/dist/tools/formal.d.ts +9 -0
  215. package/dist/tools/formal.js +79 -0
  216. package/dist/tools/guard.d.ts +7 -0
  217. package/dist/tools/guard.js +48 -0
  218. package/dist/tools/job-tools.d.ts +19 -0
  219. package/dist/tools/job-tools.js +148 -0
  220. package/dist/tools/jobs.d.ts +79 -0
  221. package/dist/tools/jobs.js +186 -0
  222. package/dist/tools/language.d.ts +6 -0
  223. package/dist/tools/language.js +172 -0
  224. package/dist/tools/lean-proof.d.ts +38 -0
  225. package/dist/tools/lean-proof.js +83 -0
  226. package/dist/tools/registry.d.ts +30 -0
  227. package/dist/tools/registry.js +113 -0
  228. package/dist/tools/run.d.ts +13 -0
  229. package/dist/tools/run.js +163 -0
  230. package/dist/tools/search.d.ts +2 -0
  231. package/dist/tools/search.js +156 -0
  232. package/dist/tools/shell-process.d.ts +115 -0
  233. package/dist/tools/shell-process.js +297 -0
  234. package/dist/tools/skills.d.ts +2 -0
  235. package/dist/tools/skills.js +46 -0
  236. package/dist/tools/stateright-runtime.d.ts +3 -0
  237. package/dist/tools/stateright-runtime.js +16 -0
  238. package/dist/tools/stateright.d.ts +3 -0
  239. package/dist/tools/stateright.js +78 -0
  240. package/dist/tools/web.d.ts +24 -0
  241. package/dist/tools/web.js +391 -0
  242. package/dist/version.d.ts +2 -0
  243. package/dist/version.js +2 -0
  244. package/docs/ci-repair-20261116.md +30 -0
  245. package/docs/commonlisp-build-output.md +14 -0
  246. package/docs/commonlisp-provider-migration.md +22 -0
  247. package/docs/commonlisp-qlot-recovery.md +28 -0
  248. package/docs/commonlisp-tls-recovery.md +28 -0
  249. package/docs/context-efficiency.md +122 -0
  250. package/docs/input.md +126 -0
  251. package/docs/languages.md +117 -0
  252. package/docs/models.md +109 -0
  253. package/docs/modkh-evidence.json +641 -0
  254. package/docs/modkh-failure-comparison.json +675 -0
  255. package/docs/modkh-namespace.md +39 -0
  256. package/docs/modkh-qlot-evidence.json +37 -0
  257. package/docs/modkh-verification.md +173 -0
  258. package/docs/modkh.md +128 -0
  259. package/docs/presets.md +64 -0
  260. package/docs/setup.md +99 -0
  261. package/docs/stateright.md +45 -0
  262. package/docs/subagents.md +152 -0
  263. package/docs/web.md +57 -0
  264. package/experiments/presets/common-lisp.lisp +38 -0
  265. package/experiments/presets/css.lisp +38 -0
  266. package/experiments/presets/formal.lisp +18 -0
  267. package/experiments/presets/html.lisp +38 -0
  268. package/experiments/presets/js.lisp +38 -0
  269. package/experiments/presets/language-microagents.lisp +29 -0
  270. package/experiments/presets/php.lisp +38 -0
  271. package/experiments/presets/svelte.lisp +38 -0
  272. package/experiments/presets/tailwindcss.lisp +24 -0
  273. package/experiments/presets/ts.lisp +38 -0
  274. package/native/stateright/Cargo.lock +478 -0
  275. package/native/stateright/Cargo.toml +11 -0
  276. package/native/stateright/src/lib.rs +163 -0
  277. package/native/stateright/src/main.rs +38 -0
  278. package/package.json +57 -4
  279. package/plugins/modkh-explorer/index.mjs +3 -0
  280. package/plugins/modkh-explorer/plugin.json +1 -0
  281. package/plugins/modkh-worker/index.mjs +3 -0
  282. package/plugins/modkh-worker/plugin.json +1 -0
  283. package/skills/kiokuko-dsh/LICENSE +21 -0
  284. package/skills/kiokuko-dsh/coding-ideal-routine-skill/SKILL.md +106 -0
  285. package/skills/kiokuko-dsh/japanese-translation-for-oss-models/SKILL.md +65 -0
  286. package/skills/kiokuko-dsh/kiokuko-architecture/SKILL.md +20 -0
  287. package/skills/kiokuko-dsh/kiokuko-architecture/references/cases.md +11 -0
  288. package/skills/kiokuko-dsh/kiokuko-benchmark/SKILL.md +20 -0
  289. package/skills/kiokuko-dsh/kiokuko-benchmark/references/cases.md +11 -0
  290. package/skills/kiokuko-dsh/kiokuko-investigate/SKILL.md +20 -0
  291. package/skills/kiokuko-dsh/kiokuko-investigate/references/cases.md +11 -0
  292. package/skills/kiokuko-dsh/kiokuko-lisp/SKILL.md +390 -0
  293. package/skills/kiokuko-dsh/kiokuko-review/SKILL.md +20 -0
  294. package/skills/kiokuko-dsh/kiokuko-review/references/cases.md +11 -0
  295. package/skills/kiokuko-dsh/kiokuko-simple-work/SKILL.md +70 -0
  296. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/SKILL.md +79 -0
  297. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/boundaries-and-ownership.md +52 -0
  298. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/domain-and-types.md +48 -0
  299. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/effects-and-data.md +43 -0
  300. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/kiokuko-patterns.md +314 -0
  301. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/problem-shaping-and-language.md +90 -0
  302. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/protocols-and-idempotency.md +42 -0
  303. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/review-checklist.md +92 -0
  304. package/skills/kiokuko-dsh/kiokuko-single-purpose-functions/references/verification.md +45 -0
  305. package/skills/kiokuko-dsh/kiokuko-skill-authoring/SKILL.md +20 -0
  306. package/skills/kiokuko-dsh/kiokuko-skill-authoring/references/cases.md +11 -0
  307. package/skills/kiokuko-dsh/kiokuko-soul/SKILL.md +25 -0
  308. package/skills/kiokuko-dsh/kiokuko-technical-writing/SKILL.md +20 -0
  309. package/skills/kiokuko-dsh/kiokuko-technical-writing/references/cases.md +11 -0
  310. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/SKILL.md +64 -0
  311. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/accessibility-and-navigation.md +31 -0
  312. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/async-recovery.md +49 -0
  313. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/forms-and-controls.md +35 -0
  314. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/interaction-feedback.md +34 -0
  315. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/responsive-and-platform.md +38 -0
  316. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/safety-and-review.md +43 -0
  317. package/skills/kiokuko-dsh/kiokuko-ui-design-soul/references/ui-checklist.md +75 -0
  318. package/skills/kiokuko-dsh/kiokuko-verification/SKILL.md +20 -0
  319. package/skills/kiokuko-dsh/kiokuko-verification/references/cases.md +11 -0
  320. package/skills/kiokuko-dsh/manifest.json +168 -0
  321. package/skills/kiokuko-dsh/memory-reasoning/SKILL.md +44 -0
  322. package/skills/kiokuko-dsh/one-shot-software-completion/SKILL.md +113 -0
  323. package/skills/kiokuko-dsh/one-shot-software-completion/references/boundaries-and-lifecycle.md +70 -0
  324. package/skills/kiokuko-dsh/one-shot-software-completion/references/discovery-and-scope.md +71 -0
  325. package/skills/kiokuko-dsh/one-shot-software-completion/references/failure-recovery.md +43 -0
  326. package/skills/kiokuko-dsh/one-shot-software-completion/references/verification-and-completion.md +73 -0
  327. package/skills/kiokuko-dsh/veteran-programmer-skill/SKILL.md +66 -0
@@ -0,0 +1,9 @@
1
+ import type { AgentMessage, ToolCall, ToolResult } from '../agent/types.ts';
2
+ /** View state only; never feeds truncated output back to the model or session journal. */
3
+ export declare class ToolDisplay {
4
+ private entries;
5
+ constructor(messages?: readonly AgentMessage[]);
6
+ call(call: ToolCall): string;
7
+ result(result: ToolResult): string;
8
+ details(argument: string): string;
9
+ }
@@ -0,0 +1,87 @@
1
+ import { stripVTControlCharacters } from 'node:util';
2
+ import { fitText, textWidth } from "./editor.js";
3
+ import { shellOutput } from "./shell-display.js";
4
+ function brief(value, width = 76) {
5
+ const text = stripVTControlCharacters(value).replace(/[\r\n\t]+/g, ' ').trim();
6
+ return textWidth(text) > width ? `${fitText(text, width - 1)}…` : text;
7
+ }
8
+ const LABELS = {
9
+ read_file: '読む', create_file: '作成', edit_file: '編集', list_files: 'ファイル一覧', search_files: '検索',
10
+ run_command: 'コマンド', read_skill: '手順を確認', list_skills: '手順一覧',
11
+ list_subagents: '担当一覧', start_subagent: '子を起動', run_subagent: '子を実行',
12
+ subagent_output: '子の結果', list_subagent_runs: '子の状態',
13
+ };
14
+ function title(call) {
15
+ const args = call.args;
16
+ const target = [args.path, args.pattern, args.query, args.name, args.pluginId, args.description]
17
+ .find(value => typeof value === 'string');
18
+ return `${LABELS[call.name] ?? call.name}${target ? ` · ${brief(String(target), 60)}` : ''}`;
19
+ }
20
+ /** Display a bounded summary only. Exact inputs and outputs remain available through details. */
21
+ function resultSummary(result) {
22
+ if (result.name === 'run_command') {
23
+ const lines = shellOutput(result).trim().split('\n');
24
+ return lines.length > 7 ? [...lines.slice(0, 2), '│ …', ...lines.slice(-4)] : lines;
25
+ }
26
+ const lines = result.output.trim().split('\n');
27
+ const status = { ok: '完了', error: 'エラー', unknown: '結果不明', 'not-executed': '未実行' }[result.status];
28
+ if (result.status !== 'ok')
29
+ return [`${status} · ${lines[0]}`, ...lines.slice(1, 3), ...(lines.length > 3 ? [lines.at(-1)] : [])];
30
+ if (result.name === 'read_skill')
31
+ return [`${status} · ${lines.length}行の手順を取得`];
32
+ try {
33
+ const data = JSON.parse(result.output);
34
+ if (Array.isArray(data))
35
+ return [`${status} · ${data.length}件`];
36
+ if (data && typeof data === 'object') {
37
+ const fields = data;
38
+ const description = [fields.status, fields.summary, fields.message].filter(v => typeof v === 'string').join(' · ');
39
+ return [`${status}${description ? ` · ${description}` : ' · 詳細あり'}`];
40
+ }
41
+ }
42
+ catch { /* Text output has no structured summary. */ }
43
+ const diagnostics = lines.find(line => line.startsWith('解析:'));
44
+ return [`${status} · ${lines[0] || '出力なし'}`, ...(diagnostics ? [diagnostics] : [])];
45
+ }
46
+ /** View state only; never feeds truncated output back to the model or session journal. */
47
+ export class ToolDisplay {
48
+ entries = [];
49
+ constructor(messages = []) {
50
+ for (const message of messages) {
51
+ if (message.role === 'assistant')
52
+ for (const call of message.toolCalls ?? [])
53
+ this.call(call);
54
+ if (message.role === 'tool')
55
+ for (const result of message.results)
56
+ this.result(result);
57
+ }
58
+ }
59
+ call(call) {
60
+ this.entries.push({ call });
61
+ const command = call.name === 'run_command' && typeof call.args.command === 'string' ? ` $ ${brief(call.args.command)}\n` : '';
62
+ return `\n▶ ${title(call)}\n${command}`;
63
+ }
64
+ result(result) {
65
+ let index = this.entries.findLastIndex(entry => entry.call.id === result.callId && !entry.result);
66
+ if (index < 0) {
67
+ this.entries.push({ call: { id: result.callId, name: result.name, args: {} } });
68
+ index = this.entries.length - 1;
69
+ }
70
+ this.entries[index].result = result;
71
+ return resultSummary(result).map(line => ` ${brief(line)}`).join('\n') + `\n 詳細: /tools ${index + 1}\n`;
72
+ }
73
+ details(argument) {
74
+ if (!argument) {
75
+ if (!this.entries.length)
76
+ return 'ツール履歴はありません。\n';
77
+ return this.entries.slice(-20).map((entry, i) => `${Math.max(0, this.entries.length - 20) + i + 1}. ${title(entry.call)} · ${entry.result?.status ?? '結果未確認'}`).join('\n')
78
+ + '\n/tools <番号>: 引数と結果の全文(直近20件を表示)\n';
79
+ }
80
+ if (!/^[1-9]\d*$/.test(argument))
81
+ return '使い方: /tools または /tools <番号>\n';
82
+ const entry = this.entries[Number(argument) - 1];
83
+ if (!entry)
84
+ return 'その番号のツール履歴はありません。/tools で一覧を確認してください。\n';
85
+ return stripVTControlCharacters(`\nツール詳細 #${argument} · ${entry.call.name}\n引数:\n${JSON.stringify(entry.call.args, null, 2)}\n結果: ${entry.result?.status ?? '未確認'}\n${entry.result?.output ?? '結果はまだありません。'}\n`);
86
+ }
87
+ }
@@ -0,0 +1,22 @@
1
+ import type { ScreenPoint } from './terminal-mouse.ts';
2
+ export interface TranscriptLine {
3
+ text: string;
4
+ newline: boolean;
5
+ }
6
+ export interface TranscriptScreenLine extends TranscriptLine {
7
+ painted: string;
8
+ }
9
+ export declare function transcriptLine(text: string, width: number, newline: boolean): TranscriptLine[];
10
+ export declare function transcriptLines(text: string, width: number): TranscriptLine[];
11
+ /** Rewrap plain text and carry the renderer's self-contained SGR spans across soft breaks. */
12
+ export declare function reflowTranscript(rows: readonly TranscriptScreenLine[], width: number): TranscriptScreenLine[];
13
+ export interface DragSelection {
14
+ anchor: ScreenPoint;
15
+ end: ScreenPoint;
16
+ }
17
+ export declare function selectedTranscript(rows: ReadonlyMap<number, TranscriptScreenLine>, selection: DragSelection): {
18
+ row: number;
19
+ column: number;
20
+ text: string;
21
+ newline: boolean;
22
+ }[];
@@ -0,0 +1,75 @@
1
+ import { cellWidth, chars, wrapText } from "./editor.js";
2
+ export function transcriptLine(text, width, newline) {
3
+ const wrapped = wrapText(text, width);
4
+ return wrapped.map((text, row) => ({ text, newline: newline && row === wrapped.length - 1 }));
5
+ }
6
+ export function transcriptLines(text, width) {
7
+ const lines = text.split('\n');
8
+ return lines.flatMap((line, index) => transcriptLine(line, width, index < lines.length - 1));
9
+ }
10
+ /** Rewrap plain text and carry the renderer's self-contained SGR spans across soft breaks. */
11
+ export function reflowTranscript(rows, width) {
12
+ const result = [];
13
+ let text = '';
14
+ let spans = [];
15
+ for (const [index, row] of rows.entries()) {
16
+ let position = 0;
17
+ for (const match of row.painted.matchAll(/\x1b\[([0-9;]+)m([^\x1b]*)\x1b\[0m|([^\x1b]+)/g)) {
18
+ const end = Math.min(row.text.length, position + (match[2] ?? match[3]).length);
19
+ if (match[1] && end > position)
20
+ spans.push({ start: text.length + position, end: text.length + end, style: match[1] });
21
+ position = end;
22
+ }
23
+ text += row.text;
24
+ if (!row.newline && index < rows.length - 1)
25
+ continue;
26
+ let start = 0;
27
+ let spanIndex = 0;
28
+ for (const line of transcriptLine(text, width, row.newline)) {
29
+ const end = start + line.text.length;
30
+ let cursor = start;
31
+ let painted = '';
32
+ for (; spanIndex < spans.length && spans[spanIndex].start < end; spanIndex++) {
33
+ const span = spans[spanIndex];
34
+ const spanStart = Math.max(start, span.start);
35
+ painted += text.slice(cursor, spanStart);
36
+ cursor = Math.min(end, span.end);
37
+ painted += `\x1b[${span.style}m${text.slice(spanStart, cursor)}\x1b[0m`;
38
+ if (span.end > end)
39
+ break;
40
+ }
41
+ result.push({ ...line, painted: painted + text.slice(cursor, end) });
42
+ start = end;
43
+ }
44
+ text = '';
45
+ spans = [];
46
+ }
47
+ return result;
48
+ }
49
+ export function selectedTranscript(rows, selection) {
50
+ const { anchor, end } = selection;
51
+ const forward = anchor.row < end.row || (anchor.row === end.row && anchor.column <= end.column);
52
+ const [first, last] = forward ? [anchor, end] : [end, anchor];
53
+ const result = [];
54
+ for (let row = first.row; row <= last.row; row++) {
55
+ const line = rows.get(row);
56
+ if (!line)
57
+ continue;
58
+ const start = row === first.row ? first.column : 1;
59
+ const stop = row === last.row ? last.column : Infinity;
60
+ let column = 1;
61
+ let text = '';
62
+ let selectedColumn = 0;
63
+ for (const char of chars(line.text)) {
64
+ const next = column + cellWidth(char, column - 1);
65
+ if (next > start && column <= stop) {
66
+ if (!selectedColumn)
67
+ selectedColumn = column;
68
+ text += char;
69
+ }
70
+ column = next;
71
+ }
72
+ result.push({ row, column: selectedColumn, text, newline: row < last.row && line.newline });
73
+ }
74
+ return result;
75
+ }
@@ -0,0 +1,22 @@
1
+ import type { TokenUsage } from '../agent/types.ts';
2
+ export interface UsageTotals extends TokenUsage {
3
+ responses: number;
4
+ /** Some reported usage lacks a comparable input and cache-read pair. */
5
+ cacheHitIncomplete?: true;
6
+ }
7
+ export declare const EMPTY_USAGE: UsageTotals;
8
+ export declare function addUsage(total: UsageTotals, reported: TokenUsage): UsageTotals;
9
+ /** 142,296,676 -> 142M. Keeps the footer short while staying recognizable. */
10
+ export declare function compactTokens(value: number): string;
11
+ /** Share of input tokens served from cache. Undefined when the provider reports no input. */
12
+ export declare function cacheHitRate(usage: UsageTotals): number | undefined;
13
+ /** One footer line, most useful numbers first. `width` is the usable cell width; narrower terminals
14
+ * drop trailing fields instead of wrapping, so the composer never moves. */
15
+ export declare function usageFooter(usage: UsageTotals, width: number): string;
16
+ /** 右下ステータス用のコンパクトな使用量表示。maxWidth を超えるときは後ろの項目から落とす。
17
+ * 幅は textWidth(表示幅)で測る(全角の「計」なども2セルとして数える)。 */
18
+ export declare function usageBadgeLine(usage: UsageTotals, maxWidth?: number): string;
19
+ export declare const USAGE_HEADING = "\u30C8\u30FC\u30AF\u30F3\u4F7F\u7528\u91CF";
20
+ export declare function usageBreakdown(usage: UsageTotals): string;
21
+ /** Width is omitted for /usage, which always shows exact counts and every field. */
22
+ export declare function usageBreakdownLines(usage: UsageTotals, width?: number): string[];
@@ -0,0 +1,117 @@
1
+ /** Token accounting for the status footer. Values are reported by the provider, never estimated. */
2
+ import { textWidth } from "./editor.js";
3
+ export const EMPTY_USAGE = { responses: 0 };
4
+ /** A reported zero is meaningful; missing or invalid data stays unknown. */
5
+ function count(value) {
6
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
7
+ }
8
+ function sumReported(total, value) {
9
+ return value === undefined ? total : (total ?? 0) + value;
10
+ }
11
+ export function addUsage(total, reported) {
12
+ const input = count(reported.input);
13
+ const output = count(reported.output);
14
+ const cacheRead = count(reported.cacheRead);
15
+ const cacheWrite = count(reported.cacheWrite);
16
+ const uncachedInput = count(reported.uncachedInput) ?? (input !== undefined && cacheRead !== undefined && cacheWrite !== undefined
17
+ ? count(input - cacheRead - cacheWrite) : undefined);
18
+ if ([input, output, cacheRead, cacheWrite, uncachedInput].every(value => value === undefined))
19
+ return total;
20
+ return {
21
+ input: sumReported(total.input, input),
22
+ uncachedInput: sumReported(total.uncachedInput, uncachedInput),
23
+ output: sumReported(total.output, output),
24
+ cacheRead: sumReported(total.cacheRead, cacheRead),
25
+ cacheWrite: sumReported(total.cacheWrite, cacheWrite),
26
+ responses: total.responses + 1,
27
+ ...(total.cacheHitIncomplete || input === undefined || (input > 0 && cacheRead === undefined) ||
28
+ (cacheRead ?? 0) > input ? { cacheHitIncomplete: true } : {}),
29
+ };
30
+ }
31
+ /** 142,296,676 -> 142M. Keeps the footer short while staying recognizable. */
32
+ export function compactTokens(value) {
33
+ if (value < 1000)
34
+ return String(value);
35
+ if (value < 1_000_000)
36
+ return `${Math.round(value / 1000)}k`;
37
+ if (value < 100_000_000)
38
+ return `${(value / 1_000_000).toFixed(1)}M`;
39
+ return `${Math.round(value / 1_000_000)}M`;
40
+ }
41
+ /** Share of input tokens served from cache. Undefined when the provider reports no input. */
42
+ export function cacheHitRate(usage) {
43
+ if (usage.cacheHitIncomplete || !usage.input || usage.cacheRead === undefined || usage.cacheRead > usage.input)
44
+ return undefined;
45
+ return Math.round((usage.cacheRead / usage.input) * 100);
46
+ }
47
+ /** One footer line, most useful numbers first. `width` is the usable cell width; narrower terminals
48
+ * drop trailing fields instead of wrapping, so the composer never moves. */
49
+ export function usageFooter(usage, width) {
50
+ if (usage.responses === 0)
51
+ return '';
52
+ const rate = cacheHitRate(usage);
53
+ const fields = [
54
+ `計 ${compactTokens((usage.input ?? 0) + (usage.output ?? 0))} tok`,
55
+ ...(rate === undefined ? [] : [`cache ${rate}%`]),
56
+ `入 ${compactTokens(usage.input ?? 0)}`,
57
+ `出 ${compactTokens(usage.output ?? 0)}`,
58
+ ];
59
+ // Drop trailing fields rather than wrapping: the footer must never move the composer.
60
+ const lines = fields.map((_, index) => fields.slice(0, index + 1).join(' · '));
61
+ for (const line of [...lines].reverse())
62
+ if (line.length <= width)
63
+ return line;
64
+ return fields[fields.length - 1];
65
+ }
66
+ /** 右下ステータス用のコンパクトな使用量表示。maxWidth を超えるときは後ろの項目から落とす。
67
+ * 幅は textWidth(表示幅)で測る(全角の「計」なども2セルとして数える)。 */
68
+ export function usageBadgeLine(usage, maxWidth) {
69
+ if (usage.responses === 0)
70
+ return '';
71
+ const rate = cacheHitRate(usage);
72
+ const fields = [
73
+ `計 ${compactTokens((usage.input ?? 0) + (usage.output ?? 0))} tok`,
74
+ ...(rate === undefined ? [] : [`cache ${rate}%`]),
75
+ `in ${compactTokens(usage.input ?? 0)}`,
76
+ `out ${compactTokens(usage.output ?? 0)}`,
77
+ ];
78
+ const lines = fields.map((_, index) => fields.slice(0, index + 1).join(' · '));
79
+ if (maxWidth === undefined)
80
+ return lines[lines.length - 1];
81
+ for (const line of [...lines].reverse())
82
+ if (textWidth(line) <= maxWidth)
83
+ return line;
84
+ return '';
85
+ }
86
+ const exactNumber = new Intl.NumberFormat('en-US');
87
+ const compactNumber = new Intl.NumberFormat('en-US', { notation: 'compact', maximumFractionDigits: 1 });
88
+ export const USAGE_HEADING = 'トークン使用量';
89
+ function tokenRow(label, value, suffix = '') {
90
+ if (value === undefined)
91
+ return [label, '—'];
92
+ return [label, exactNumber.format(value) + suffix, compactNumber.format(value) + suffix];
93
+ }
94
+ export function usageBreakdown(usage) {
95
+ return usage.responses === 0 ? 'トークン使用量はまだ報告されていません' : usageBreakdownLines(usage).join('\n');
96
+ }
97
+ /** Width is omitted for /usage, which always shows exact counts and every field. */
98
+ export function usageBreakdownLines(usage, width) {
99
+ const total = usage.input === undefined && usage.output === undefined
100
+ ? undefined : (usage.input ?? 0) + (usage.output ?? 0);
101
+ const rate = cacheHitRate(usage);
102
+ const rows = [
103
+ tokenRow(USAGE_HEADING, total, ' tok'),
104
+ ['キャッシュヒット', rate === undefined ? '—' : `${rate}%`],
105
+ tokenRow('未キャッシュ入力', usage.uncachedInput),
106
+ tokenRow('キャッシュ済み入力', usage.cacheRead),
107
+ ];
108
+ if (width === undefined || (usage.cacheWrite ?? 0) > 0)
109
+ rows.push(tokenRow('キャッシュ書き込み', usage.cacheWrite));
110
+ rows.push(tokenRow('出力', usage.output));
111
+ const lineWidth = width ?? Math.max(...rows.map(([label, value]) => textWidth(label) + 2 + textWidth(value)));
112
+ return rows.map(([label, exact, compact = exact]) => {
113
+ const available = lineWidth - textWidth(label);
114
+ const value = textWidth(exact) + 2 <= available ? exact : compact;
115
+ return label + ' '.repeat(Math.max(2, available - textWidth(value))) + value;
116
+ });
117
+ }
@@ -0,0 +1,3 @@
1
+ export declare const WHALE_FRAME_MS = 180;
2
+ /** Render one frame in terminal columns, leaving a gutter on both sides. */
3
+ export declare function whaleRow(frame: number, width: number): string;
@@ -0,0 +1,17 @@
1
+ import { textWidth } from "./editor.js";
2
+ export const WHALE_FRAME_MS = 180;
3
+ const WHALES = '🐳 🐋';
4
+ const WHALE_WIDTH = textWidth(WHALES);
5
+ const WAVES = '∿~ ';
6
+ /** Render one frame in terminal columns, leaving a gutter on both sides. */
7
+ export function whaleRow(frame, width) {
8
+ const waterWidth = width - 2;
9
+ const travel = waterWidth - WHALE_WIDTH;
10
+ if (travel < WAVES.length)
11
+ return '';
12
+ // Fold the path at each end instead of jumping back to the start.
13
+ const phase = (frame * 2) % (2 * travel);
14
+ const position = travel - Math.abs(travel - phase);
15
+ const water = Array.from({ length: waterWidth }, (_, column) => WAVES[(column + frame) % WAVES.length]).join('');
16
+ return ` ${water.slice(0, position)}${WHALES}${water.slice(position + WHALE_WIDTH)} `;
17
+ }
@@ -0,0 +1,3 @@
1
+ export declare const WHALE_FRAME_MS = 180;
2
+ /** Render one frame in terminal columns, leaving a gutter on both sides. */
3
+ export declare function whaleRow(frame: number, width: number): string;
@@ -0,0 +1,24 @@
1
+ import { textWidth } from "./editor.js";
2
+ export const WHALE_FRAME_MS = 180;
3
+ const LEAD_WHALE = '🐳';
4
+ const TRAILING_WHALE = '🐋';
5
+ const LEAD_WIDTH = textWidth(LEAD_WHALE);
6
+ const TRAILING_WIDTH = textWidth(TRAILING_WHALE);
7
+ const WHALE_GAP = 8;
8
+ const WAVES = '∿~ ';
9
+ /** Render one frame in terminal columns, leaving a gutter on both sides. */
10
+ export function whaleRow(frame, width) {
11
+ const waterWidth = width - 2;
12
+ const space = waterWidth - LEAD_WIDTH - TRAILING_WIDTH;
13
+ const gap = Math.min(WHALE_GAP, space - WAVES.length);
14
+ if (gap < 1)
15
+ return '';
16
+ const travel = space - gap;
17
+ // Swim left, then start the next pass at the right edge.
18
+ const passFrames = Math.ceil(travel / 2) + 1;
19
+ const position = Math.max(0, travel - (frame % passFrames) * 2);
20
+ const leadEnd = position + LEAD_WIDTH;
21
+ const trailingPosition = leadEnd + gap;
22
+ const water = Array.from({ length: waterWidth }, (_, column) => WAVES[(column + frame) % WAVES.length]).join('');
23
+ return ` ${water.slice(0, position)}${LEAD_WHALE}${water.slice(leadEnd, trailingPosition)}${TRAILING_WHALE}${water.slice(trailingPosition + TRAILING_WIDTH)} `;
24
+ }
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ export interface ParsedInvocation {
3
+ cmd: string;
4
+ args: Record<string, string | undefined>;
5
+ }
6
+ /**
7
+ * 引数を解釈する。最初の非フラグ引数がコマンド。
8
+ * コマンドがない(引数なし、または --cwd 等のフラグのみ)場合は chat を既定とする。
9
+ */
10
+ export declare function parseInvocation(argv: readonly string[]): ParsedInvocation;
11
+ export declare function main(argv: readonly string[]): void;
package/dist/index.js ADDED
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+ // modkh — MoDKH (Mixture of DKH)
3
+ import fs from 'node:fs';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { APP_VERSION } from "./version.js";
6
+ const VERSION = APP_VERSION;
7
+ const HELP = `modkh ${VERSION} — MoDKH (Mixture of DKH)
8
+
9
+ 使い方:
10
+ modkh [--model <provider>/<model>] [--cwd <dir>] [--resume <id>] [--base-url <url>]
11
+ (対話ハーネスを開く。言語別の調査担当は /agents で確認)
12
+ modkh chat --model <provider>/<model> [--cwd <dir>] [--resume <id>] [--base-url <url>]
13
+ modkh chat --lisp-config agents.lisp --trust-lisp-sha256 SHA256 [--sbcl PATH] [--verification-isolation required|integrity-only]
14
+ [--routing auto] [--lean PATH] [--stateright PATH]
15
+ [--lean-contract FILE.lean --lean-theorem NAME]
16
+ modkh auth login chatgpt
17
+ modkh session list
18
+ modkh plugin list | add <directory> | enable <id> | disable <id> | remove <id>
19
+ modkh stateright install | status
20
+ modkh language status | install [--detected] | retry <id> | update
21
+
22
+ 対話中のコマンド:
23
+ /connect 検索できるプロバイダー一覧
24
+ /connect openai ChatGPT OAuth / APIキーを選択
25
+ /connect chatgpt ブラウザで ChatGPT 認証
26
+ /connect opencode OpenCode Zen のモデル選択
27
+ /connect opencode-go OpenCode Go のモデル選択(同じ OPENCODE_API_KEY)
28
+ /connect ollama Ollama Local のモデル選択
29
+ /connect ollama-cloud Ollama Cloud の認証・モデル選択
30
+ /agents 子エージェント一覧
31
+ /agents run [ID] [依頼] 子を選んで限定した仕事を委譲
32
+ /models [検索語] 接続先からモデル一覧を取得して選択
33
+ /reasoning [レベル] [--save] 推論レベル off/minimal/low/medium/high/max(既定は前回保存値)
34
+ /connect <provider>/<model> [--base-url <url>] モデルをその場で接続(AI API / chatgpt / fixed)
35
+
36
+ 接続先:
37
+ fixed/scripted 固定応答モデル(オフライン検証用)
38
+ openai|anthropic|google|deepseek/<model> AI SDK アダプター
39
+ opencode|opencode-go/<model> OpenCode Zen / Go(同じ OPENCODE_API_KEY)
40
+ openrouter|infron|ollama|hermes/<model> OpenAI互換アダプター
41
+ ollama-cloud/<model> Ollama Cloud (OLLAMA_API_KEY)
42
+ groq|xai|lmstudio/<model> 既存の互換アダプター
43
+ compatible/<model> --base-url <url> 任意のOpenAI互換URL
44
+ chatgpt/<model> Sign in with ChatGPT(/connect で認証可能)
45
+
46
+ モデル一覧は固定値を持たず、/connect と /models のたびに各プロバイダーの一覧APIから取得する。
47
+ 取得できないときは理由を表示し、モデルIDの直接入力を案内する(古い一覧へのフォールバックはしない)。
48
+
49
+ キーは環境変数から読む(例: OPENAI_API_KEY, ANTHROPIC_API_KEY,
50
+ GOOGLE_GENERATIVE_AI_API_KEY, DEEPSEEK_API_KEY, OPENCODE_API_KEY, OPENROUTER_API_KEY,
51
+ INFRON_API_KEY, HERMES_API_KEY, OLLAMA_API_KEY, GROQ_API_KEY, XAI_API_KEY)。
52
+ OPENCODE_API_KEY は OpenCode Zen と Go の両方で使う(片方の入力で両方に接続できる)。
53
+ 接続先URLの差し替え: OPENCODE_BASE_URL (Zen) / OPENCODE_GO_BASE_URL (Go)。
54
+
55
+ TTYではMODKHロゴ・コマンド補完・検索メニューを表示。↑↓/Enterで選択、Escで戻る。
56
+ 出力は通常のスクリーンバッファに流れるので、端末のスクロール(マウスホイール等)で履歴を辿れる。
57
+ 各セッションの記録はワークスペースの .modkh/sessions/<id>.md にも保存される(.gitignoreに .modkh/ を追加している)。
58
+ timeoutMs(既定600000=10分)は応答の無通信時間の上限。config.json で 5000〜1800000 ms に変更できる。
59
+ MODKH_PLAIN=1 modkh で行入力モード(スクリーンリーダー向け)。NO_COLORで色を無効化。
60
+ `;
61
+ /**
62
+ * 引数を解釈する。最初の非フラグ引数がコマンド。
63
+ * コマンドがない(引数なし、または --cwd 等のフラグのみ)場合は chat を既定とする。
64
+ */
65
+ export function parseInvocation(argv) {
66
+ const args = {};
67
+ let positional = [];
68
+ let cmd;
69
+ for (let i = 0; i < argv.length; i++) {
70
+ const a = argv[i];
71
+ if (a === '--help' || a === '-h') {
72
+ args['help'] = 'true';
73
+ }
74
+ else if (a === '--version' || a === '-v') {
75
+ args['version'] = 'true';
76
+ }
77
+ else if (a?.startsWith('--')) {
78
+ const next = argv[i + 1];
79
+ if (next !== undefined && !next.startsWith('--')) {
80
+ args[a.slice(2)] = next;
81
+ i++;
82
+ }
83
+ else {
84
+ args[a.slice(2)] = 'true';
85
+ }
86
+ }
87
+ else if (cmd === undefined) {
88
+ cmd = a;
89
+ }
90
+ else {
91
+ positional = [...positional, a];
92
+ }
93
+ }
94
+ args['@positional'] = positional.join(' ');
95
+ return { cmd: cmd ?? 'chat', args };
96
+ }
97
+ export function main(argv) {
98
+ const { cmd, args } = parseInvocation(argv);
99
+ if (args['help'] === 'true') {
100
+ process.stdout.write(HELP);
101
+ return;
102
+ }
103
+ if (args['version'] === 'true') {
104
+ process.stdout.write(`${VERSION}\n`);
105
+ return;
106
+ }
107
+ void dispatch(cmd, args, argv);
108
+ }
109
+ async function dispatch(cmd, args, argv) {
110
+ try {
111
+ if (cmd === 'chat') {
112
+ const { recordChat } = await import("./cli/agenticreplay.js");
113
+ const exitCode = await recordChat(fileURLToPath(import.meta.url), argv, args);
114
+ if (exitCode !== undefined) {
115
+ process.exitCode = exitCode;
116
+ return;
117
+ }
118
+ const { runChat } = await import("./cli/chat.js");
119
+ await runChat({ args });
120
+ return;
121
+ }
122
+ if (cmd === 'stateright') {
123
+ const { runStaterightCommand } = await import("./cli/stateright.js");
124
+ await runStaterightCommand(args['@positional'] ?? 'status');
125
+ return;
126
+ }
127
+ if (cmd === 'language') {
128
+ const { runLanguageCommand } = await import("./cli/language.js");
129
+ await runLanguageCommand(args['@positional'] ?? '', process.cwd());
130
+ return;
131
+ }
132
+ if (cmd === 'plugin') {
133
+ const { runPluginCommand } = await import("./cli/plugins.js");
134
+ await runPluginCommand(args['@positional'] ?? '');
135
+ return;
136
+ }
137
+ if (cmd === 'auth') {
138
+ if (args['@positional'] !== 'login chatgpt') {
139
+ process.stderr.write('使い方: modkh auth login chatgpt\n');
140
+ process.exit(1);
141
+ }
142
+ const { loginChatGpt } = await import("./model/chatgpt/login.js");
143
+ const tokens = await loginChatGpt();
144
+ process.stdout.write('ログインしました(トークンはハーネス専用の保存先に保存済み)。\n');
145
+ if (tokens.expiresAt)
146
+ process.stdout.write(`有効期限: ${tokens.expiresAt}\n`);
147
+ return;
148
+ }
149
+ if (cmd === 'session') {
150
+ const { SessionStore } = await import("./session/store.js");
151
+ if (args['@positional'] === 'list') {
152
+ const list = new SessionStore().list();
153
+ if (list.length === 0) {
154
+ process.stdout.write('セッションはまだありません。\n');
155
+ return;
156
+ }
157
+ for (const s of list) {
158
+ process.stdout.write(`${s.id} ${s.status.padEnd(11)} ${s.createdAt} ${s.model} ${s.cwd}\n`);
159
+ }
160
+ return;
161
+ }
162
+ process.stderr.write('使い方: modkh session list\n');
163
+ process.exit(1);
164
+ }
165
+ process.stderr.write(`不明なコマンド: ${cmd}\n\n${HELP}`);
166
+ process.exit(1);
167
+ }
168
+ catch (e) {
169
+ process.stderr.write(`エラー: ${e.message}\n`);
170
+ process.exit(1);
171
+ }
172
+ }
173
+ // 直接起動されたときだけ main を走らせる(import された場合は副作用なし)。
174
+ // realpath で比較する(/tmp のようなシンボリックリンク経由の起動に対応)。
175
+ const entryArg = process.argv[1];
176
+ let isMainModule = false;
177
+ if (entryArg !== undefined) {
178
+ try {
179
+ isMainModule = fs.realpathSync(entryArg) === fs.realpathSync(fileURLToPath(import.meta.url));
180
+ }
181
+ catch {
182
+ isMainModule = false;
183
+ }
184
+ }
185
+ if (isMainModule)
186
+ main(process.argv.slice(2));
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Fixed, reviewed installation recipes. Runtime code never invents a URL or a shell string.
3
+ * A language is only advertised as `ready` after its own verification passes; this table is a
4
+ * declaration of the intended route, not proof that a route works on every OS.
5
+ */
6
+ export type LanguageId = 'typescript' | 'javascript' | 'tsx' | 'svelte' | 'html' | 'css' | 'tailwind' | 'rust' | 'python' | 'c' | 'cpp' | 'ruby' | 'swift' | 'php' | 'commonlisp';
7
+ export interface LaunchSpec {
8
+ /** Executable inside an installed npm prefix, or an absolute host binary. */
9
+ readonly bin: string;
10
+ readonly args: readonly string[];
11
+ /** Some servers need the workspace URI as the final argument. */
12
+ readonly needsRootUri?: boolean;
13
+ }
14
+ export interface NpmRecipe {
15
+ readonly kind: 'npm';
16
+ readonly packages: readonly string[];
17
+ /** Which installed package's `.bin` entry is the server. */
18
+ readonly entry: string;
19
+ }
20
+ export interface HostRecipe {
21
+ readonly kind: 'host';
22
+ /** Absolute candidates probed in order; the first executable wins. */
23
+ readonly candidates: readonly string[];
24
+ readonly requirement?: string;
25
+ }
26
+ export type Recipe = NpmRecipe | HostRecipe;
27
+ export interface LanguageDefinition {
28
+ readonly id: LanguageId;
29
+ /** File extensions without a dot, lower case. */
30
+ readonly extensions: readonly string[];
31
+ /** Manifest files whose presence suggests this language, relative to a project root. */
32
+ readonly manifests: readonly string[];
33
+ /** tree-sitter grammar id when a reviewed WASM grammar exists for this language. */
34
+ readonly grammar?: string;
35
+ /** Grammar used to parse embedded regions of this file type, e.g. Vue/Svelte markup. */
36
+ readonly lsp?: LaunchSpec;
37
+ readonly install?: Recipe;
38
+ /** Reason semantic analysis is expected to be unavailable without a user-provided SDK. */
39
+ readonly hostRequirement?: string;
40
+ }
41
+ export declare const LANGUAGES: readonly LanguageDefinition[];
42
+ export declare function languageById(id: string): LanguageDefinition | undefined;
43
+ export declare function languageForPath(filePath: string): LanguageDefinition | undefined;
44
+ export declare function grammarFor(language: LanguageDefinition): string | undefined;