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,100 @@
1
+ const TYPESCRIPT = {
2
+ id: 'typescript', extensions: ['ts', 'mts', 'cts'], manifests: ['tsconfig.json', 'package.json'],
3
+ grammar: 'typescript',
4
+ install: { kind: 'npm', packages: ['typescript-language-server@latest', 'typescript@latest'], entry: 'typescript-language-server' },
5
+ lsp: { bin: 'typescript-language-server', args: ['--stdio'] },
6
+ };
7
+ export const LANGUAGES = [
8
+ TYPESCRIPT,
9
+ {
10
+ id: 'javascript', extensions: ['js', 'mjs', 'cjs'], manifests: ['package.json'],
11
+ grammar: 'javascript', install: { kind: 'npm', packages: ['typescript-language-server@latest', 'typescript@latest'], entry: 'typescript-language-server' },
12
+ lsp: { bin: 'typescript-language-server', args: ['--stdio'] },
13
+ },
14
+ {
15
+ id: 'tsx', extensions: ['tsx'], manifests: ['tsconfig.json', 'package.json'],
16
+ grammar: 'tsx', install: { kind: 'npm', packages: ['typescript-language-server@latest', 'typescript@latest'], entry: 'typescript-language-server' },
17
+ lsp: { bin: 'typescript-language-server', args: ['--stdio'] },
18
+ },
19
+ {
20
+ id: 'svelte', extensions: ['svelte'], manifests: ['svelte.config.js', 'svelte.config.ts', 'package.json'],
21
+ grammar: 'svelte', install: { kind: 'npm', packages: ['svelte-language-server@latest'], entry: 'svelteserver' },
22
+ lsp: { bin: 'svelteserver', args: ['--stdio'] },
23
+ },
24
+ {
25
+ id: 'html', extensions: ['html', 'htm'], manifests: [],
26
+ grammar: 'html', install: { kind: 'npm', packages: ['vscode-langservers-extracted@latest'], entry: 'vscode-html-language-server' },
27
+ lsp: { bin: 'vscode-html-language-server', args: ['--stdio'] },
28
+ },
29
+ {
30
+ id: 'css', extensions: ['css', 'pcss'], manifests: [],
31
+ grammar: 'css', install: { kind: 'npm', packages: ['vscode-langservers-extracted@latest'], entry: 'vscode-css-language-server' },
32
+ lsp: { bin: 'vscode-css-language-server', args: ['--stdio'] },
33
+ },
34
+ {
35
+ id: 'tailwind', extensions: ['css', 'pcss', 'html', 'svelte', 'tsx', 'jsx'], manifests: ['tailwind.config.js', 'tailwind.config.ts', 'tailwind.config.cjs'],
36
+ install: { kind: 'npm', packages: ['@tailwindcss/language-server@latest'], entry: 'tailwindcss-language-server' },
37
+ lsp: { bin: 'tailwindcss-language-server', args: ['--stdio'] },
38
+ },
39
+ {
40
+ id: 'rust', extensions: ['rs'], manifests: ['Cargo.toml'],
41
+ grammar: 'rust',
42
+ install: { kind: 'host', candidates: ['rust-analyzer', '/opt/homebrew/bin/rust-analyzer', '/usr/local/bin/rust-analyzer'], requirement: 'rust-analyzer か Rust toolchain が必要' },
43
+ lsp: { bin: 'rust-analyzer', args: [] },
44
+ },
45
+ {
46
+ id: 'python', extensions: ['py', 'pyi'], manifests: ['pyproject.toml', 'setup.py', 'requirements.txt'],
47
+ grammar: 'python', install: { kind: 'npm', packages: ['basedpyright@latest'], entry: 'basedpyright-langserver' },
48
+ lsp: { bin: 'basedpyright-langserver', args: ['--stdio'] },
49
+ },
50
+ {
51
+ id: 'c', extensions: ['c', 'h'], manifests: ['compile_commands.json', 'Makefile', 'CMakeLists.txt'],
52
+ grammar: 'c',
53
+ install: { kind: 'host', candidates: ['clangd', '/opt/homebrew/opt/llvm/bin/clangd', '/usr/local/opt/llvm/bin/clangd', '/usr/bin/clangd'], requirement: 'clangd が必要' },
54
+ lsp: { bin: 'clangd', args: [] },
55
+ },
56
+ {
57
+ id: 'cpp', extensions: ['cc', 'cpp', 'cxx', 'hpp', 'hxx', 'hh'], manifests: ['compile_commands.json', 'CMakeLists.txt'],
58
+ grammar: 'cpp',
59
+ install: { kind: 'host', candidates: ['clangd', '/opt/homebrew/opt/llvm/bin/clangd', '/usr/local/opt/llvm/bin/clangd', '/usr/bin/clangd'], requirement: 'clangd が必要' },
60
+ lsp: { bin: 'clangd', args: [] },
61
+ },
62
+ {
63
+ id: 'ruby', extensions: ['rb', 'rake'], manifests: ['Gemfile', '*.gemspec'],
64
+ grammar: 'ruby', install: { kind: 'host', candidates: ['ruby-lsp', '/opt/homebrew/bin/ruby-lsp'], requirement: 'Ruby と ruby-lsp gem が必要' },
65
+ lsp: { bin: 'ruby-lsp', args: [] },
66
+ },
67
+ {
68
+ id: 'swift', extensions: ['swift'], manifests: ['Package.swift'],
69
+ grammar: 'swift',
70
+ install: { kind: 'host', candidates: ['sourcekit-lsp', '/usr/bin/sourcekit-lsp', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp'], requirement: 'Xcode / Swift toolchain が必要' },
71
+ lsp: { bin: 'sourcekit-lsp', args: [] },
72
+ },
73
+ {
74
+ id: 'php', extensions: ['php', 'phtml'], manifests: ['composer.json'],
75
+ grammar: 'php',
76
+ install: { kind: 'host', candidates: ['phpantom_lsp', 'phpantom-lsp'], requirement: 'PHPantom か PHP 用LSPが必要' },
77
+ lsp: { bin: 'phpantom_lsp', args: [] },
78
+ },
79
+ {
80
+ id: 'commonlisp', extensions: ['lisp', 'lsp', 'asd', 'cl'], manifests: ['*.asd'],
81
+ grammar: 'commonlisp',
82
+ install: { kind: 'host', candidates: ['cl-lsp', '/opt/homebrew/bin/cl-lsp'], requirement: 'SBCL と CL-LSP が必要' },
83
+ lsp: { bin: 'cl-lsp', args: [] },
84
+ },
85
+ ];
86
+ export function languageById(id) {
87
+ return LANGUAGES.find(language => language.id === id);
88
+ }
89
+ export function languageForPath(filePath) {
90
+ const name = filePath.toLowerCase();
91
+ const dot = name.lastIndexOf('.');
92
+ if (dot < 0)
93
+ return undefined;
94
+ const extension = name.slice(dot + 1);
95
+ // tsx and php have distinct grammars; check the more specific extension first.
96
+ return LANGUAGES.find(language => language.extensions.includes(extension));
97
+ }
98
+ export function grammarFor(language) {
99
+ return language.grammar;
100
+ }
@@ -0,0 +1,11 @@
1
+ export declare const CL_LSP_REPOSITORY = "askdkc/cl-lsp";
2
+ type Run = (name: string, command: string, args: string[], cwd?: string) => Promise<string>;
3
+ /** Upstream's headless installer loads vendor/, without Lem/Qlot/Quicklisp resolution. */
4
+ export declare function installBundledCommonLisp(root: string, source: string, ros: string, run: Run): Promise<{
5
+ command: string;
6
+ repository: string;
7
+ sourcesSha256: string;
8
+ installerSha256: string;
9
+ launcherSha256: string;
10
+ }>;
11
+ export {};
@@ -0,0 +1,22 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { sha256 } from "../lisp/runtime.js";
4
+ export const CL_LSP_REPOSITORY = 'askdkc/cl-lsp';
5
+ /** Upstream's headless installer loads vendor/, without Lem/Qlot/Quicklisp resolution. */
6
+ export async function installBundledCommonLisp(root, source, ros, run) {
7
+ const installer = path.join(source, 'scripts/install-headless.ros');
8
+ const manifest = path.join(source, 'vendor/SOURCES.md');
9
+ for (const file of [installer, manifest, path.join(source, 'vendor/setup.lisp')]) {
10
+ if (!fs.lstatSync(file).isFile())
11
+ throw new Error(`Bundled CL-LSP input is not a regular file: ${file}`);
12
+ }
13
+ const prefix = path.join(root, 'server');
14
+ await run('bundled-runtime-install', ros, ['-Q', '--', installer, '--prefix', prefix], source);
15
+ const command = path.join(prefix, 'cl-lsp');
16
+ if (!fs.lstatSync(command).isFile())
17
+ throw new Error('Bundled CL-LSP launcher missing or not a regular file');
18
+ await run('runtime-warmup', command, ['--help'], root);
19
+ // Actual initialize, document synchronization and definition responses are checked by the caller.
20
+ return { command, repository: CL_LSP_REPOSITORY, sourcesSha256: sha256(fs.readFileSync(manifest)),
21
+ installerSha256: sha256(fs.readFileSync(installer)), launcherSha256: sha256(fs.readFileSync(command)) };
22
+ }
@@ -0,0 +1,16 @@
1
+ type RunStage = (name: string, command: string, args: string[], cwd?: string) => Promise<string>;
2
+ /** Resolve the upstream manifest in an owned prefix, without touching the user's Quicklisp. */
3
+ export declare function installLemDependencies(root: string, lem: string, ros: string, rosHome: string, run: RunStage, tlsFile?: string): Promise<{
4
+ home: string;
5
+ version: string;
6
+ manifestSha256: string;
7
+ setupSha256: string;
8
+ lockSha256: string;
9
+ lock: string;
10
+ provider: string;
11
+ }>;
12
+ /** Locate the source actually resolved by ASDF, not a second unrelated Git checkout. */
13
+ export declare function resolvedDependencyDirectory(discovery: string, system: string, root: string): string;
14
+ /** async-process keeps its ASD in src/, while its Autotools entry lives above it. */
15
+ export declare function resolvedNativeBuildDirectory(discovery: string, root: string): string;
16
+ export {};
@@ -0,0 +1,68 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { sha256 } from "../lisp/runtime.js";
4
+ /** Resolve the upstream manifest in an owned prefix, without touching the user's Quicklisp. */
5
+ export async function installLemDependencies(root, lem, ros, rosHome, run, tlsFile) {
6
+ const directory = path.join(root, 'dependencies');
7
+ fs.mkdirSync(directory, { mode: 0o700 });
8
+ const manifest = fs.readFileSync(path.join(lem, 'qlfile'));
9
+ fs.writeFileSync(path.join(directory, 'qlfile'), manifest, { flag: 'wx' });
10
+ // Resolve the current upstream manifest; don't copy Lem's historical lock into a fresh install.
11
+ await run('qlot-bootstrap', ros, ['install', 'fukamachi/qlot']);
12
+ const qlot = path.join(rosHome, 'bin', 'qlot');
13
+ // Qlot deliberately quits -1 for --version; test the loadable CLI instead.
14
+ const probe = path.join(directory, 'probe-qlot.lisp');
15
+ fs.writeFileSync(probe, `(require :asdf)
16
+ (asdf:load-system "qlot/cli")
17
+ (assert (fboundp (find-symbol "QLOT-COMMAND" "QLOT/CLI")))
18
+ (format t "MODKH_QLOT_READY ~A~%" (asdf:component-version (asdf:find-system "qlot")))
19
+ `, { flag: 'wx' });
20
+ const bootstrap = ['-Q', '-e', '(ros:ensure-asdf)', ...(tlsFile ? ['-l', tlsFile] : [])];
21
+ const output = await run('qlot-capability', ros, [...bootstrap, '-l', probe, '-q']);
22
+ const evidence = output.split(/\r?\n/).filter(line => /^MODKH_QLOT_READY \S+$/.test(line));
23
+ if (evidence.length !== 1)
24
+ throw new Error('Qlot capability missing completion evidence');
25
+ const version = evidence[0].slice('MODKH_QLOT_READY '.length);
26
+ if (tlsFile) {
27
+ await run('lem-dependencies', ros, [...bootstrap, '-l', probe, '-e', '(qlot/cli:qlot-command "install" "--no-deps")', '-q'], directory);
28
+ }
29
+ else {
30
+ await run('lem-dependencies', qlot, ['install', '--no-deps'], directory);
31
+ }
32
+ const home = path.join(directory, '.qlot');
33
+ // Exit 0 alone is insufficient. Loading and ASDF resolution are checked by the next stage.
34
+ const setupDigest = sha256(fs.readFileSync(path.join(home, 'setup.lisp')));
35
+ const lock = fs.readFileSync(path.join(directory, 'qlfile.lock'), 'utf8');
36
+ return { home: home + path.sep, version, manifestSha256: sha256(manifest), setupSha256: setupDigest,
37
+ lockSha256: sha256(lock), lock, provider: 'https://github.com/fukamachi/qlot' };
38
+ }
39
+ /** Locate the source actually resolved by ASDF, not a second unrelated Git checkout. */
40
+ export function resolvedDependencyDirectory(discovery, system, root) {
41
+ const prefix = `MODKH_ASDF_SYSTEM ${system} `;
42
+ const matches = discovery.split(/\r?\n/).filter(line => line.startsWith(prefix));
43
+ if (matches.length !== 1)
44
+ throw new Error(`Missing or ambiguous ASDF source: ${system}`);
45
+ const source = fs.realpathSync(matches[0].slice(prefix.length));
46
+ const relative = path.relative(fs.realpathSync(root), source);
47
+ if (relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)
48
+ || !source.endsWith('.asd') || !fs.statSync(source).isFile()) {
49
+ throw new Error(`ASDF source outside owned dependency prefix: ${system}`);
50
+ }
51
+ return path.dirname(source);
52
+ }
53
+ /** async-process keeps its ASD in src/, while its Autotools entry lives above it. */
54
+ export function resolvedNativeBuildDirectory(discovery, root) {
55
+ const source = resolvedDependencyDirectory(discovery, 'async-process', root);
56
+ const owned = fs.realpathSync(root);
57
+ for (const candidate of [source, path.dirname(source)]) {
58
+ const relative = path.relative(owned, candidate);
59
+ if (relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative))
60
+ continue;
61
+ if (['GNUmakefile', 'Makefile.am', 'configure.ac'].every(name => {
62
+ const file = path.join(candidate, name);
63
+ return fs.existsSync(file) && fs.lstatSync(file).isFile();
64
+ }))
65
+ return candidate;
66
+ }
67
+ throw new Error('ASDF-resolved async-process has no supported native build entry');
68
+ }
@@ -0,0 +1,15 @@
1
+ import { type HostPlatform, type ReleaseAsset } from './platform.ts';
2
+ /** Official Roswell Lisp filenames include '+' (for example install+sigsegv.lisp). */
3
+ export declare function validateRoswellArchivePaths(output: string): void;
4
+ export declare function roswellAsset(assets: ReleaseAsset[], platform: HostPlatform, glibc?: string): ReleaseAsset;
5
+ export declare const COMMON_LISP_BUILD_OUTPUT_BYTES: number;
6
+ /** Called under install.ts's per-language lock. Every attempt owns a new non-relocated prefix. */
7
+ export declare function installCommonLisp(target: string, signal?: AbortSignal): Promise<{
8
+ command: string;
9
+ args: never[];
10
+ version: string;
11
+ digest: string;
12
+ receipt: Record<string, unknown>;
13
+ }>;
14
+ /** A partial directory or modified launcher is never a reusable managed installation. */
15
+ export declare function reusableCommonLisp(command: string, digest: string): boolean;
@@ -0,0 +1,214 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { download } from "./native.js";
4
+ import { installBundledCommonLisp, CL_LSP_REPOSITORY } from "./commonlisp-bundled.js";
5
+ import { hostPlatform } from "./platform.js";
6
+ import { executeBounded, privateEnvironment, sha256 } from "../lisp/runtime.js";
7
+ import { LspServer } from "./lsp/client.js";
8
+ /** Official Roswell Lisp filenames include '+' (for example install+sigsegv.lisp). */
9
+ export function validateRoswellArchivePaths(output) {
10
+ const names = output.replace(/\n$/, '').split('\n');
11
+ if (names.length > 2000)
12
+ throw new Error('Roswell archive exceeds 2000 entries');
13
+ for (const name of names) {
14
+ if (!/^roswell\/[A-Za-z0-9._+/-]*$/.test(name) || name.split('/').includes('..')) {
15
+ throw new Error(`Unsafe Roswell archive path: ${JSON.stringify(name)}`);
16
+ }
17
+ }
18
+ }
19
+ export function roswellAsset(assets, platform, glibc) {
20
+ const arch = platform.arch === 'arm64' ? 'arm64' : platform.os === 'darwin' ? 'x86-64' : 'x86_64';
21
+ const suffix = platform.os === 'darwin' ? new RegExp(`-darwin-${arch}\\.tar\\.bz2$`) : new RegExp(`-linux-${arch}-glibc([0-9]+\\.[0-9]+)\\.tar\\.bz2$`);
22
+ const candidates = assets.filter(a => {
23
+ const match = suffix.exec(a.name);
24
+ if (!match)
25
+ return false;
26
+ if (platform.os === 'linux') {
27
+ if (!glibc)
28
+ return false;
29
+ const actual = glibc.split('.').map(Number), required = match[1].split('.').map(Number);
30
+ if (actual[0] < required[0] || actual[0] === required[0] && actual[1] < required[1])
31
+ return false;
32
+ }
33
+ return true;
34
+ });
35
+ if (candidates.length !== 1)
36
+ throw new Error(`No unambiguous compatible official Roswell asset: ${platform.os}/${arch}, glibc=${glibc ?? 'unknown'}`);
37
+ const asset = candidates[0], url = new URL(asset.browser_download_url);
38
+ if (url.protocol !== 'https:' || url.hostname !== 'github.com' || !url.pathname.startsWith('/roswell/roswell/releases/download/') || !/^sha256:[a-f0-9]{64}$/.test(asset.digest ?? ''))
39
+ throw new Error('Official Roswell origin and SHA256 metadata required');
40
+ if (!Number.isSafeInteger(asset.size) || asset.size < 1 || asset.size > 64 * 1024 * 1024)
41
+ throw new Error('Invalid Roswell archive size');
42
+ return asset;
43
+ }
44
+ export const COMMON_LISP_BUILD_OUTPUT_BYTES = 16 * 1024 * 1024;
45
+ const repositories = [CL_LSP_REPOSITORY];
46
+ const failure = (error) => {
47
+ if (!(error instanceof Error))
48
+ return String(error);
49
+ const cause = error.cause;
50
+ return `${error.name}: ${error.message}${cause ? ` (${cause.code ?? ''}: ${cause.message ?? ''})` : ''}`;
51
+ };
52
+ const quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
53
+ /** Called under install.ts's per-language lock. Every attempt owns a new non-relocated prefix. */
54
+ export async function installCommonLisp(target, signal) {
55
+ const platform = hostPlatform();
56
+ if (!platform)
57
+ throw new Error('Unsupported Common Lisp host');
58
+ fs.mkdirSync(target, { recursive: true, mode: 0o700 });
59
+ const space = fs.statfsSync(target);
60
+ if (space.bavail * space.bsize < 2 * 1024 ** 3)
61
+ throw new Error('Insufficient disk space: CL bootstrap needs 2 GiB reserve');
62
+ const root = fs.realpathSync(fs.mkdtempSync(path.join(target, 'attempt-')));
63
+ const home = path.join(root, 'home'), rosHome = path.join(root, 'roswell-home'), prefix = path.join(root, 'runtime');
64
+ for (const dir of [home, rosHome, prefix])
65
+ fs.mkdirSync(dir, { mode: 0o700 });
66
+ const env = { ...privateEnvironment(home), ROSWELL_HOME: rosHome, PATH: `${prefix}/bin:${rosHome}/bin:${process.env.PATH ?? '/usr/bin:/bin'}`,
67
+ CL_SOURCE_REGISTRY: `(:source-registry (:tree ${JSON.stringify(path.join(rosHome, 'local-projects') + '/')}) :inherit-configuration)`,
68
+ GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null', GIT_TERMINAL_PROMPT: '0' };
69
+ const stages = [], revisions = {};
70
+ const report = { platform, startedAt: new Date().toISOString(), stages, revisions, status: 'installing',
71
+ provenance: 'Verification policy: Roswell archive must match official SHA256 metadata; completed Git checkouts record commits. Consult stage results for actual verification. Quicklisp transitive downloads are upstream-managed, not independently authenticated by this installer.' };
72
+ let settled = true, succeeded = false;
73
+ const deadline = AbortSignal.any([AbortSignal.timeout(20 * 60_000), ...(signal ? [signal] : [])]);
74
+ const record = () => fs.writeFileSync(path.join(root, 'install-receipt.json'), JSON.stringify(report, null, 2));
75
+ const stage = async (name, action) => {
76
+ const entry = { name, state: 'running' };
77
+ stages.push(entry);
78
+ record();
79
+ try {
80
+ const value = await action(entry);
81
+ entry.state = 'passed';
82
+ record();
83
+ return value;
84
+ }
85
+ catch (e) {
86
+ entry.state = 'failed';
87
+ entry.detail = failure(e);
88
+ record();
89
+ throw new Error(`Common Lisp ${name}: ${failure(e)}`);
90
+ }
91
+ };
92
+ const run = (name, command, args, cwd = root) => stage(name, async (entry) => {
93
+ const receipt = await executeBounded(command, args, { cwd, env, inputDigest: sha256(JSON.stringify([command, args])), timeoutMs: 20 * 60_000, maxOutputBytes: name === 'bundled-runtime-install' ? COMMON_LISP_BUILD_OUTPUT_BYTES : 512 * 1024, outputOverflow: name === 'bundled-runtime-install' ? 'tail' : 'stop', signal: deadline });
94
+ entry.receipt = receipt;
95
+ settled &&= receipt.cleanup === 'settled';
96
+ if (receipt.state !== 'exited' || receipt.exitCode !== 0 || receipt.cleanup !== 'settled')
97
+ throw new Error(`${receipt.state}/${receipt.exitCode} cleanup=${receipt.cleanup} cause=${receipt.terminationReason ?? receipt.state}: stderr=${receipt.stderr.slice(-1500)} stdout=${receipt.stdout.slice(-1500)}`);
98
+ return receipt.stdout;
99
+ });
100
+ try {
101
+ await run('compiler-capability', 'cc', ['--version']);
102
+ const metadata = await stage('release-metadata', async () => JSON.parse((await download('https://api.github.com/repos/roswell/roswell/releases/latest', 2 * 1024 ** 2, deadline)).toString('utf8')));
103
+ if (!Array.isArray(metadata.assets) || typeof metadata.tag_name !== 'string')
104
+ throw new Error('Invalid Roswell metadata');
105
+ const glibc = process.report.getReport().header.glibcVersionRuntime;
106
+ const asset = roswellAsset(metadata.assets, platform, glibc);
107
+ report.release = metadata.tag_name;
108
+ report.asset = asset;
109
+ const archive = path.join(root, 'roswell.tar.bz2');
110
+ await stage('release-download', async () => {
111
+ const bytes = await download(asset.browser_download_url, asset.size, deadline);
112
+ if (bytes.length !== asset.size || `sha256:${sha256(bytes)}` !== asset.digest)
113
+ throw new Error('Roswell SHA256/size mismatch');
114
+ fs.writeFileSync(archive, bytes, { flag: 'wx', mode: 0o600 });
115
+ });
116
+ const names = await run('archive-paths', '/usr/bin/tar', ['-tjf', archive]);
117
+ await stage('archive-layout', async () => validateRoswellArchivePaths(names));
118
+ const listing = (await run('archive-types', '/usr/bin/tar', ['-tvjf', archive])).trim().split('\n');
119
+ if (listing.some(n => !/^[-d]/.test(n)))
120
+ throw new Error('Roswell links/special files unsupported');
121
+ await run('archive-extract', '/usr/bin/tar', ['-xjf', archive, '--no-same-owner']);
122
+ await run('roswell-private-install', 'make', [`prefix=${prefix}`, 'install'], path.join(root, 'roswell'));
123
+ const ros = path.join(prefix, 'bin/ros');
124
+ await run('sbcl-quicklisp-setup', ros, ['setup']);
125
+ await run('asdf-bootstrap', ros, ['install', 'asdf']);
126
+ const projects = path.join(rosHome, 'local-projects');
127
+ fs.mkdirSync(projects, { recursive: true });
128
+ for (const repo of repositories) {
129
+ const destination = path.join(projects, repo.split('/')[1]);
130
+ await run(`source:${repo}`, 'git', ['-c', 'protocol.file.allow=never', 'clone', '--depth=1', `https://github.com/${repo}.git`, destination]);
131
+ revisions[repo] = (await run(`revision:${repo}`, 'git', ['rev-parse', 'HEAD'], destination)).trim();
132
+ }
133
+ report.repository = CL_LSP_REPOSITORY;
134
+ const bundled = await installBundledCommonLisp(root, path.join(projects, 'cl-lsp'), ros, run);
135
+ report.bundled = bundled;
136
+ // Both frontend and backend receive only this installation's private environment.
137
+ const command = path.join(root, 'cl-lsp');
138
+ fs.writeFileSync(command, `#!/bin/sh\ncd ${quote(root)} || exit 1\nexec /usr/bin/env -i ${Object.entries(env).filter(([, v]) => v !== undefined).map(([k, v]) => quote(`${k}=${v}`)).join(' ')} ${quote(bundled.command)} --stdio\n`, { mode: 0o700 });
139
+ const fixture = path.join(root, 'probe.lisp'), text = '(let ((value 1)) value)\n';
140
+ fs.writeFileSync(fixture, text);
141
+ const server = new LspServer({ id: 'commonlisp', command, args: [], root, requestTimeoutMs: 15000, inheritEnv: false, env: env });
142
+ try {
143
+ await stage('lsp-initialize', async () => { await server.start(deadline); report.capabilities = server.capabilities; });
144
+ await stage('lsp-synchronize', async () => { report.synchronization = await server.synchronize(fixture, text); });
145
+ await stage('lexical-definition', async () => {
146
+ const definitions = await server.definition(fixture, { line: 0, character: text.lastIndexOf('value') });
147
+ report.lexicalDefinitions = definitions;
148
+ if (!definitions.some(d => d.file === fixture && d.line === 1 && d.character === 8))
149
+ throw new Error('No matching lexical definition response');
150
+ });
151
+ await stage('unevaluated-global-observation', async () => {
152
+ const file = path.join(root, 'global.lisp'), source = '(defun modkh-unloaded () 1)\n(modkh-unloaded)\n';
153
+ fs.writeFileSync(file, source);
154
+ await server.synchronize(file, source);
155
+ report.unevaluatedGlobalDefinitions = await server.definition(file, { line: 1, character: 2 });
156
+ });
157
+ await stage('diagnostic-observation', async () => {
158
+ const invalid = path.join(root, 'invalid.lisp');
159
+ fs.writeFileSync(invalid, '(defun broken (');
160
+ const result = await server.synchronize(invalid, '(defun broken (');
161
+ report.diagnostics = { ...result, channels: server.diagnosticEvidence, verified: result.status === 'observed' && result.diagnostics.some(d => d.severity === 'error') };
162
+ });
163
+ }
164
+ finally {
165
+ try {
166
+ await server.dispose();
167
+ }
168
+ catch (e) {
169
+ settled = false;
170
+ throw e;
171
+ }
172
+ }
173
+ report.launcherSha256 = sha256(fs.readFileSync(command));
174
+ report.status = 'ready-for-lexical-definition';
175
+ report.finishedAt = new Date().toISOString();
176
+ record();
177
+ succeeded = true;
178
+ return { command, args: [], version: `cl-lsp@${revisions[CL_LSP_REPOSITORY]}`, digest: sha256(fs.readFileSync(command)), receipt: report };
179
+ }
180
+ finally {
181
+ if (!succeeded) {
182
+ report.status = 'failed';
183
+ report.finishedAt = new Date().toISOString();
184
+ record();
185
+ // Keep diagnostic evidence before deleting this failed attempt's private caches.
186
+ const diagnostics = {};
187
+ for (const name of fs.readdirSync(home)) {
188
+ if (!/^[A-Za-z0-9_-]+\.log$/.test(name))
189
+ continue;
190
+ const file = path.join(home, name), stat = fs.lstatSync(file);
191
+ if (stat.isFile() && stat.size <= 2 * 1024 * 1024)
192
+ diagnostics[name] = fs.readFileSync(file, 'utf8');
193
+ }
194
+ report.diagnostics = diagnostics;
195
+ record();
196
+ fs.copyFileSync(path.join(root, 'install-receipt.json'), path.join(target, 'last-failure.json'));
197
+ if (settled)
198
+ fs.rmSync(root, { recursive: true, force: true });
199
+ }
200
+ }
201
+ }
202
+ /** A partial directory or modified launcher is never a reusable managed installation. */
203
+ export function reusableCommonLisp(command, digest) {
204
+ try {
205
+ const receipt = JSON.parse(fs.readFileSync(path.join(path.dirname(command), 'install-receipt.json'), 'utf8'));
206
+ return receipt.repository === CL_LSP_REPOSITORY && receipt.status === 'ready-for-lexical-definition' && receipt.launcherSha256 === digest
207
+ && sha256(fs.readFileSync(command)) === digest
208
+ && receipt.stages.some((s) => s.name === 'lsp-initialize' && s.state === 'passed')
209
+ && receipt.stages.some((s) => s.name === 'lexical-definition' && s.state === 'passed');
210
+ }
211
+ catch {
212
+ return false;
213
+ }
214
+ }
@@ -0,0 +1,17 @@
1
+ import { type ExecutionReceipt } from '../lisp/runtime.ts';
2
+ export interface ReaderDiagnostic {
3
+ provider: 'SBCL reader';
4
+ scope: 'reader syntax only; no evaluation, macro expansion, type or project-package checking';
5
+ status: 'syntax-error' | 'readable' | 'unverified';
6
+ line?: number;
7
+ column?: number;
8
+ detail: string;
9
+ sourceSha256: string;
10
+ receipt?: ExecutionReceipt;
11
+ }
12
+ /** A supplemental reader check, never a substitute for CL-LSP semantic diagnostics. */
13
+ export declare function commonLispReader(text: string, options?: {
14
+ sbcl?: string;
15
+ signal?: AbortSignal;
16
+ timeoutMs?: number;
17
+ }): Promise<ReaderDiagnostic>;
@@ -0,0 +1,47 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { executeBounded, privateEnvironment, sha256, temporaryDirectory } from "../lisp/runtime.js";
4
+ /** A supplemental reader check, never a substitute for CL-LSP semantic diagnostics. */
5
+ export async function commonLispReader(text, options = {}) {
6
+ const base = { provider: 'SBCL reader', scope: 'reader syntax only; no evaluation, macro expansion, type or project-package checking', status: 'unverified', detail: '', sourceSha256: sha256(text) };
7
+ if (Buffer.byteLength(text) > 256 * 1024)
8
+ return { ...base, detail: 'Reader input exceeds 256 KiB' };
9
+ const root = temporaryDirectory('modkh-cl-reader-');
10
+ // Only fixed host code is evaluated. Project forms are read as data with #. disabled.
11
+ const driver = `(define-condition blocked-read-eval (error) ())
12
+ (let ((*read-eval* nil) (*readtable* (copy-readtable nil)) (*package* (find-package :cl-user)))
13
+ (set-dispatch-macro-character #\\# #\\. (lambda (stream char argument)
14
+ (declare (ignore stream char argument)) (error (quote blocked-read-eval))))
15
+ (with-open-file (in "input.lisp" :external-format :utf-8)
16
+ (let* ((text (with-output-to-string (out) (loop for c = (read-char in nil nil) while c do (write-char c out))))
17
+ (stream (make-string-input-stream text)) (end (gensym)))
18
+ (handler-case
19
+ (progn (loop for form = (read stream nil end) until (eq form end)) (format t "MODKH_READER_READABLE"))
20
+ (blocked-read-eval () (format t "MODKH_READER_UNVERIFIED") (princ "Read-time evaluation is disabled" *error-output*))
21
+ (package-error (e) (format t "MODKH_READER_UNVERIFIED") (princ e *error-output*))
22
+ (end-of-file (e) (format t "MODKH_READER_ERROR ~D" (file-position stream)) (princ e *error-output*))
23
+ (reader-error (e) (format t "MODKH_READER_ERROR ~D" (file-position stream)) (princ e *error-output*))
24
+ (error (e) (format t "MODKH_READER_UNVERIFIED") (princ e *error-output*))))))`;
25
+ let receipt;
26
+ try {
27
+ fs.writeFileSync(path.join(root, 'input.lisp'), text, { mode: 0o600 });
28
+ fs.writeFileSync(path.join(root, 'reader.lisp'), driver, { mode: 0o600 });
29
+ receipt = await executeBounded(options.sbcl ?? 'sbcl', ['--noinform', '--no-sysinit', '--no-userinit', '--disable-debugger', '--script', 'reader.lisp'], { cwd: root, env: privateEnvironment(root), inputDigest: base.sourceSha256, timeoutMs: options.timeoutMs ?? 5000, maxOutputBytes: 16384, signal: options.signal });
30
+ if (receipt.state !== 'exited' || receipt.exitCode !== 0)
31
+ return { ...base, receipt, detail: `Reader ${receipt.state}: ${receipt.stderr}` };
32
+ if (receipt.stdout === 'MODKH_READER_READABLE')
33
+ return { ...base, receipt, status: 'readable', detail: 'Reader accepted the input; semantic diagnostics remain unverified' };
34
+ const error = /^MODKH_READER_ERROR (\d+)$/.exec(receipt.stdout);
35
+ if (error) {
36
+ // SBCL string offsets count Unicode code points; public columns are UTF-16.
37
+ const prefix = Array.from(text).slice(0, Number(error[1])).join('');
38
+ const lines = prefix.split('\n');
39
+ return { ...base, receipt, status: 'syntax-error', line: lines.length, column: lines.at(-1).length + 1, detail: receipt.stderr };
40
+ }
41
+ return { ...base, receipt, detail: receipt.stderr || 'No valid reader completion receipt' };
42
+ }
43
+ finally {
44
+ if (receipt?.cleanup !== 'unknown')
45
+ fs.rmSync(root, { recursive: true, force: true });
46
+ }
47
+ }
@@ -0,0 +1,3 @@
1
+ /** Explicitly selected, trusted dependency sources, never an implicit project root. */
2
+ export declare function commonLispRegistry(projects: string): string;
3
+ export declare function commonLispSystemProbe(registry: string): string;
@@ -0,0 +1,32 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ /** Explicitly selected, trusted dependency sources, never an implicit project root. */
4
+ export function commonLispRegistry(projects) {
5
+ const root = fs.realpathSync(projects);
6
+ const directories = new Set();
7
+ let visited = 0;
8
+ const visit = (directory) => {
9
+ if (++visited > 10000)
10
+ throw new Error('Common Lisp dependency directory limit exceeded');
11
+ for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
12
+ if (entry.isSymbolicLink())
13
+ continue;
14
+ if (entry.isDirectory() && !['.git', 'node_modules', '.qlot'].includes(entry.name))
15
+ visit(path.join(directory, entry.name));
16
+ else if (entry.isFile() && entry.name.endsWith('.asd'))
17
+ directories.add(directory + path.sep);
18
+ }
19
+ };
20
+ visit(root);
21
+ // Explicit directories also work when an upstream tree ships an incomplete ASDF search cache.
22
+ const lispString = (s) => '"' + s.replaceAll('\\', '\\\\').replaceAll('"', '\\"') + '"';
23
+ return `(:source-registry ${[...directories].sort().map(dir => `(:directory ${lispString(dir)})`).join(' ')} :inherit-configuration)`;
24
+ }
25
+ export function commonLispSystemProbe(registry) {
26
+ return `(progn (require :asdf) (asdf:clear-source-registry) (asdf:initialize-source-registry '${registry})
27
+ (dolist (name '("cl-lsp" "lem-language-server/cli" "lem/core" "micros" "lem-mailbox" "lem-extension-manager" "async-process" "jsonrpc"))
28
+ (let ((system (asdf:find-system name nil)))
29
+ (unless system (error "MODKH_MISSING_ASDF_SYSTEM ~A" name))
30
+ (format t "MODKH_ASDF_SYSTEM ~A ~A~%" name (asdf:system-source-file system))))
31
+ (write-line "MODKH_ASDF_DISCOVERY_OK"))`;
32
+ }
@@ -0,0 +1,10 @@
1
+ type Run = (name: string, command: string, args: string[], cwd?: string) => Promise<string>;
2
+ export declare function opensslCandidates(opt: string): string[];
3
+ export declare const tlsProbeSource = "#include <dlfcn.h>\n#include <stdio.h>\nint main(int argc, char **argv) {\n if (argc != 3) return 2;\n void *crypto = dlopen(argv[1], RTLD_NOW | RTLD_LOCAL);\n void *ssl = dlopen(argv[2], RTLD_NOW | RTLD_LOCAL);\n if (!crypto || !ssl) { puts(\"MODKH_TLS_UNAVAILABLE\"); return 0; }\n if (!dlsym(crypto, \"ASN1_STRING_data\") || !dlsym(crypto, \"ASN1_STRING_length\") ||\n !dlsym(ssl, \"SSL_new\") || !dlsym(ssl, \"TLS_method\")) {\n puts(\"MODKH_TLS_MISSING_SYMBOLS\"); return 0;\n }\n puts(\"MODKH_TLS_COMPATIBLE\"); return 0;\n}\n";
4
+ export declare function tlsConfiguration(lib: string): string;
5
+ /** Explicit CL+SSL configuration; never relink Homebrew or change global loader settings. */
6
+ export declare function prepareDarwinTls(root: string, run: Run): Promise<{
7
+ file: string;
8
+ libraryDirectory: string;
9
+ }>;
10
+ export {};
@@ -0,0 +1,51 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export function opensslCandidates(opt) {
4
+ if (!fs.existsSync(opt))
5
+ return [];
6
+ return fs.readdirSync(opt).filter(name => /^openssl(?:@[\w.]+)?$/.test(name))
7
+ .sort((a, b) => a === 'openssl' ? -1 : b === 'openssl' ? 1 : b.localeCompare(a, undefined, { numeric: true }))
8
+ .map(name => path.join(opt, name, 'lib'))
9
+ .filter(dir => ['libcrypto.dylib', 'libssl.dylib'].every(name => fs.existsSync(path.join(dir, name))));
10
+ }
11
+ // Test loaded symbols, not a version number or the presence of a dylib filename.
12
+ export const tlsProbeSource = `#include <dlfcn.h>
13
+ #include <stdio.h>
14
+ int main(int argc, char **argv) {
15
+ if (argc != 3) return 2;
16
+ void *crypto = dlopen(argv[1], RTLD_NOW | RTLD_LOCAL);
17
+ void *ssl = dlopen(argv[2], RTLD_NOW | RTLD_LOCAL);
18
+ if (!crypto || !ssl) { puts("MODKH_TLS_UNAVAILABLE"); return 0; }
19
+ if (!dlsym(crypto, "ASN1_STRING_data") || !dlsym(crypto, "ASN1_STRING_length") ||
20
+ !dlsym(ssl, "SSL_new") || !dlsym(ssl, "TLS_method")) {
21
+ puts("MODKH_TLS_MISSING_SYMBOLS"); return 0;
22
+ }
23
+ puts("MODKH_TLS_COMPATIBLE"); return 0;
24
+ }
25
+ `;
26
+ export function tlsConfiguration(lib) {
27
+ return `(let ((*standard-output* *error-output*) (*trace-output* *error-output*))
28
+ (ql:quickload "cl+ssl/config" :silent t))
29
+ (cl+ssl/config:define-libcrypto-path ${JSON.stringify(fs.realpathSync(path.join(lib, 'libcrypto.dylib')))})
30
+ (cl+ssl/config:define-libssl-path ${JSON.stringify(fs.realpathSync(path.join(lib, 'libssl.dylib')))})
31
+ (let ((*standard-output* *error-output*) (*trace-output* *error-output*))
32
+ (ql:quickload "cl+ssl" :silent t)
33
+ (asdf:load-system "cl+ssl" :force t))
34
+ `;
35
+ }
36
+ /** Explicit CL+SSL configuration; never relink Homebrew or change global loader settings. */
37
+ export async function prepareDarwinTls(root, run) {
38
+ const source = path.join(root, 'probe-tls.c'), command = path.join(root, 'probe-tls');
39
+ fs.writeFileSync(source, tlsProbeSource, { flag: 'wx' });
40
+ await run('tls-probe-build', 'cc', [source, '-o', command]);
41
+ const candidates = [...opensslCandidates('/opt/homebrew/opt'), ...opensslCandidates('/usr/local/opt')];
42
+ for (const [index, lib] of candidates.entries()) {
43
+ const output = await run(`tls-library:${index}`, command, [path.join(lib, 'libcrypto.dylib'), path.join(lib, 'libssl.dylib')]);
44
+ if (!output.split(/\r?\n/).includes('MODKH_TLS_COMPATIBLE'))
45
+ continue;
46
+ const file = path.join(root, 'configure-tls.lisp');
47
+ fs.writeFileSync(file, tlsConfiguration(lib), { flag: 'wx' });
48
+ return { file, libraryDirectory: fs.realpathSync(lib) };
49
+ }
50
+ throw new Error('No installed Homebrew OpenSSL pair provides the CL+SSL APIs (ASN1_STRING_data, SSL_new, TLS_method). Install a compatible OpenSSL package; global libraries were not changed.');
51
+ }