@quolu/lattice 0.1.0 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/README.md +87 -4
  2. package/bin/lattice-bridge.mjs +87 -0
  3. package/bin/lattice-dashboard.mjs +70 -0
  4. package/bin/lattice-mcp.mjs +9 -9
  5. package/bin/lattice.mjs +61 -8
  6. package/docs/bridge-setup.md +87 -0
  7. package/docs/schemas/lattice.plan_create_input.v1.schema.json +56 -0
  8. package/docs/schemas/lattice.plan_create_input.v2.schema.json +72 -0
  9. package/docs/schemas/lattice.plan_create_input.v3.schema.json +81 -0
  10. package/package.json +19 -7
  11. package/sensor/dist/bin/command-supervision.d.ts +1 -1
  12. package/sensor/dist/bin/command-supervision.js +4 -4
  13. package/sensor/dist/bin/command-supervision.js.map +1 -1
  14. package/sensor/dist/bin/fatal-handler.js +2 -2
  15. package/sensor/dist/bin/fatal-handler.js.map +1 -1
  16. package/sensor/dist/bin/{codegraph.js → lattice-sensor.js} +207 -328
  17. package/sensor/dist/bin/node-version-check.d.ts +7 -5
  18. package/sensor/dist/bin/node-version-check.d.ts.map +1 -1
  19. package/sensor/dist/bin/node-version-check.js +19 -14
  20. package/sensor/dist/bin/node-version-check.js.map +1 -1
  21. package/sensor/dist/context/index.d.ts +1 -1
  22. package/sensor/dist/context/index.js +6 -6
  23. package/sensor/dist/context/index.js.map +1 -1
  24. package/sensor/dist/db/index.d.ts +5 -5
  25. package/sensor/dist/db/index.d.ts.map +1 -1
  26. package/sensor/dist/db/index.js +7 -7
  27. package/sensor/dist/db/index.js.map +1 -1
  28. package/sensor/dist/db/migrations.js +1 -1
  29. package/sensor/dist/db/migrations.js.map +1 -1
  30. package/sensor/dist/db/queries.d.ts +1 -1
  31. package/sensor/dist/db/queries.js +5 -5
  32. package/sensor/dist/db/queries.js.map +1 -1
  33. package/sensor/dist/db/schema.sql +2 -2
  34. package/sensor/dist/db/sqlite-adapter.d.ts +2 -2
  35. package/sensor/dist/db/sqlite-adapter.js +3 -3
  36. package/sensor/dist/db/sqlite-adapter.js.map +1 -1
  37. package/sensor/dist/db/wal-valve.d.ts +1 -1
  38. package/sensor/dist/db/wal-valve.d.ts.map +1 -1
  39. package/sensor/dist/db/wal-valve.js +2 -2
  40. package/sensor/dist/db/wal-valve.js.map +1 -1
  41. package/sensor/dist/directory.d.ts +27 -63
  42. package/sensor/dist/directory.d.ts.map +1 -1
  43. package/sensor/dist/directory.js +78 -134
  44. package/sensor/dist/directory.js.map +1 -1
  45. package/sensor/dist/errors.d.ts +15 -15
  46. package/sensor/dist/errors.d.ts.map +1 -1
  47. package/sensor/dist/errors.js +21 -21
  48. package/sensor/dist/errors.js.map +1 -1
  49. package/sensor/dist/extraction/dynamic-import.d.ts +1 -1
  50. package/sensor/dist/extraction/dynamic-import.js +1 -1
  51. package/sensor/dist/extraction/extraction-version.d.ts +1 -1
  52. package/sensor/dist/extraction/extraction-version.js +1 -1
  53. package/sensor/dist/extraction/generated-detection.d.ts +1 -1
  54. package/sensor/dist/extraction/generated-detection.js +1 -1
  55. package/sensor/dist/extraction/grammars.d.ts +3 -3
  56. package/sensor/dist/extraction/grammars.js +5 -5
  57. package/sensor/dist/extraction/grammars.js.map +1 -1
  58. package/sensor/dist/extraction/index.d.ts +6 -6
  59. package/sensor/dist/extraction/index.js +50 -50
  60. package/sensor/dist/extraction/index.js.map +1 -1
  61. package/sensor/dist/extraction/kernel/decode.d.ts +1 -1
  62. package/sensor/dist/extraction/kernel/decode.js +1 -1
  63. package/sensor/dist/extraction/kernel/index.d.ts +3 -3
  64. package/sensor/dist/extraction/kernel/index.js +6 -6
  65. package/sensor/dist/extraction/kernel/index.js.map +1 -1
  66. package/sensor/dist/extraction/kernel/layout.d.ts +1 -1
  67. package/sensor/dist/extraction/kernel/layout.js +1 -1
  68. package/sensor/dist/extraction/kernel/loader.d.ts +6 -6
  69. package/sensor/dist/extraction/kernel/loader.js +13 -13
  70. package/sensor/dist/extraction/kernel/loader.js.map +1 -1
  71. package/sensor/dist/extraction/languages/cfquery.d.ts +1 -1
  72. package/sensor/dist/extraction/languages/cfquery.js +1 -1
  73. package/sensor/dist/extraction/languages/lua.d.ts +11 -0
  74. package/sensor/dist/extraction/languages/lua.d.ts.map +1 -1
  75. package/sensor/dist/extraction/languages/lua.js +1 -0
  76. package/sensor/dist/extraction/languages/lua.js.map +1 -1
  77. package/sensor/dist/extraction/parse-pool.d.ts +5 -5
  78. package/sensor/dist/extraction/parse-pool.d.ts.map +1 -1
  79. package/sensor/dist/extraction/parse-pool.js +4 -4
  80. package/sensor/dist/extraction/parse-worker.js +1 -1
  81. package/sensor/dist/extraction/parse-worker.js.map +1 -1
  82. package/sensor/dist/extraction/store-writer.d.ts +1 -1
  83. package/sensor/dist/extraction/store-writer.js +1 -1
  84. package/sensor/dist/extraction/svelte-extractor.d.ts +1 -1
  85. package/sensor/dist/extraction/svelte-extractor.js +1 -1
  86. package/sensor/dist/extraction/tree-sitter-helpers.js +1 -1
  87. package/sensor/dist/extraction/tree-sitter.d.ts +2 -2
  88. package/sensor/dist/extraction/tree-sitter.d.ts.map +1 -1
  89. package/sensor/dist/extraction/tree-sitter.js +71 -4
  90. package/sensor/dist/extraction/tree-sitter.js.map +1 -1
  91. package/sensor/dist/extraction/wasm-runtime-flags.d.ts +2 -2
  92. package/sensor/dist/extraction/wasm-runtime-flags.d.ts.map +1 -1
  93. package/sensor/dist/extraction/wasm-runtime-flags.js +5 -5
  94. package/sensor/dist/extraction/wasm-runtime-flags.js.map +1 -1
  95. package/sensor/dist/index.d.ts +36 -36
  96. package/sensor/dist/index.d.ts.map +1 -1
  97. package/sensor/dist/index.js +71 -71
  98. package/sensor/dist/index.js.map +1 -1
  99. package/sensor/dist/mcp/daemon-manager.js +1 -1
  100. package/sensor/dist/mcp/daemon-paths.d.ts +3 -3
  101. package/sensor/dist/mcp/daemon-paths.js +7 -7
  102. package/sensor/dist/mcp/daemon-paths.js.map +1 -1
  103. package/sensor/dist/mcp/daemon-registry.d.ts +2 -2
  104. package/sensor/dist/mcp/daemon-registry.js +5 -5
  105. package/sensor/dist/mcp/daemon.d.ts +7 -7
  106. package/sensor/dist/mcp/daemon.d.ts.map +1 -1
  107. package/sensor/dist/mcp/daemon.js +21 -21
  108. package/sensor/dist/mcp/daemon.js.map +1 -1
  109. package/sensor/dist/mcp/dynamic-boundaries.js +1 -1
  110. package/sensor/dist/mcp/engine.d.ts +9 -9
  111. package/sensor/dist/mcp/engine.d.ts.map +1 -1
  112. package/sensor/dist/mcp/engine.js +44 -44
  113. package/sensor/dist/mcp/engine.js.map +1 -1
  114. package/sensor/dist/mcp/index.d.ts +14 -14
  115. package/sensor/dist/mcp/index.d.ts.map +1 -1
  116. package/sensor/dist/mcp/index.js +41 -41
  117. package/sensor/dist/mcp/index.js.map +1 -1
  118. package/sensor/dist/mcp/liveness-watchdog.js +7 -7
  119. package/sensor/dist/mcp/liveness-watchdog.js.map +1 -1
  120. package/sensor/dist/mcp/ppid-watchdog.d.ts +3 -3
  121. package/sensor/dist/mcp/ppid-watchdog.js +2 -2
  122. package/sensor/dist/mcp/proxy.d.ts.map +1 -1
  123. package/sensor/dist/mcp/proxy.js +37 -37
  124. package/sensor/dist/mcp/proxy.js.map +1 -1
  125. package/sensor/dist/mcp/query-pool.d.ts +3 -3
  126. package/sensor/dist/mcp/query-pool.js +7 -7
  127. package/sensor/dist/mcp/query-pool.js.map +1 -1
  128. package/sensor/dist/mcp/query-worker.d.ts +2 -2
  129. package/sensor/dist/mcp/query-worker.js +7 -7
  130. package/sensor/dist/mcp/query-worker.js.map +1 -1
  131. package/sensor/dist/mcp/server-instructions.d.ts +10 -12
  132. package/sensor/dist/mcp/server-instructions.d.ts.map +1 -1
  133. package/sensor/dist/mcp/server-instructions.js +39 -37
  134. package/sensor/dist/mcp/server-instructions.js.map +1 -1
  135. package/sensor/dist/mcp/session.d.ts +2 -2
  136. package/sensor/dist/mcp/session.js +18 -18
  137. package/sensor/dist/mcp/session.js.map +1 -1
  138. package/sensor/dist/mcp/startup-handshake.d.ts +3 -3
  139. package/sensor/dist/mcp/startup-handshake.d.ts.map +1 -1
  140. package/sensor/dist/mcp/startup-handshake.js +3 -3
  141. package/sensor/dist/mcp/startup-handshake.js.map +1 -1
  142. package/sensor/dist/mcp/tools.d.ts +53 -53
  143. package/sensor/dist/mcp/tools.d.ts.map +1 -1
  144. package/sensor/dist/mcp/tools.js +180 -216
  145. package/sensor/dist/mcp/tools.js.map +1 -1
  146. package/sensor/dist/mcp/transport.d.ts +1 -1
  147. package/sensor/dist/mcp/transport.js +6 -6
  148. package/sensor/dist/mcp/transport.js.map +1 -1
  149. package/sensor/dist/mcp/version.d.ts +2 -2
  150. package/sensor/dist/mcp/version.d.ts.map +1 -1
  151. package/sensor/dist/mcp/version.js +3 -3
  152. package/sensor/dist/mcp/version.js.map +1 -1
  153. package/sensor/dist/project-config.d.ts +6 -6
  154. package/sensor/dist/project-config.d.ts.map +1 -1
  155. package/sensor/dist/project-config.js +10 -10
  156. package/sensor/dist/project-config.js.map +1 -1
  157. package/sensor/dist/resolution/callback-synthesizer.js +4 -4
  158. package/sensor/dist/resolution/callback-synthesizer.js.map +1 -1
  159. package/sensor/dist/resolution/frameworks/drupal.d.ts +3 -3
  160. package/sensor/dist/resolution/frameworks/drupal.js +3 -3
  161. package/sensor/dist/resolution/frameworks/fabric.js +1 -1
  162. package/sensor/dist/resolution/frameworks/fabric.js.map +1 -1
  163. package/sensor/dist/resolution/frameworks/java.js +1 -1
  164. package/sensor/dist/resolution/frameworks/java.js.map +1 -1
  165. package/sensor/dist/resolution/frameworks/svelte.js +1 -1
  166. package/sensor/dist/resolution/frameworks/svelte.js.map +1 -1
  167. package/sensor/dist/resolution/goframe-synthesizer.d.ts +1 -1
  168. package/sensor/dist/resolution/goframe-synthesizer.js +1 -1
  169. package/sensor/dist/resolution/index.d.ts +1 -1
  170. package/sensor/dist/resolution/index.js +9 -9
  171. package/sensor/dist/resolution/index.js.map +1 -1
  172. package/sensor/dist/resolution/name-matcher.js +2 -2
  173. package/sensor/dist/resolution/name-matcher.js.map +1 -1
  174. package/sensor/dist/resolution/resolver-pool.d.ts +2 -2
  175. package/sensor/dist/resolution/resolver-pool.js +4 -4
  176. package/sensor/dist/resolution/resolver-pool.js.map +1 -1
  177. package/sensor/dist/resolution/resolver-worker.js +2 -2
  178. package/sensor/dist/resolution/resolver-worker.js.map +1 -1
  179. package/sensor/dist/resolution/workspace-packages.js +1 -1
  180. package/sensor/dist/resolution/workspace-packages.js.map +1 -1
  181. package/sensor/dist/search/identifier-segments.d.ts +1 -1
  182. package/sensor/dist/search/identifier-segments.js +1 -1
  183. package/sensor/dist/search/query-utils.d.ts +1 -0
  184. package/sensor/dist/search/query-utils.d.ts.map +1 -1
  185. package/sensor/dist/search/query-utils.js +10 -3
  186. package/sensor/dist/search/query-utils.js.map +1 -1
  187. package/sensor/dist/sync/git-hooks.d.ts +9 -9
  188. package/sensor/dist/sync/git-hooks.d.ts.map +1 -1
  189. package/sensor/dist/sync/git-hooks.js +15 -15
  190. package/sensor/dist/sync/git-hooks.js.map +1 -1
  191. package/sensor/dist/sync/watch-policy.d.ts +2 -2
  192. package/sensor/dist/sync/watch-policy.js +5 -5
  193. package/sensor/dist/sync/watch-policy.js.map +1 -1
  194. package/sensor/dist/sync/watcher.d.ts +2 -2
  195. package/sensor/dist/sync/watcher.d.ts.map +1 -1
  196. package/sensor/dist/sync/watcher.js +16 -16
  197. package/sensor/dist/sync/watcher.js.map +1 -1
  198. package/sensor/dist/sync/worktree.d.ts +5 -5
  199. package/sensor/dist/sync/worktree.d.ts.map +1 -1
  200. package/sensor/dist/sync/worktree.js +9 -9
  201. package/sensor/dist/sync/worktree.js.map +1 -1
  202. package/sensor/dist/telemetry/index.d.ts +8 -8
  203. package/sensor/dist/telemetry/index.d.ts.map +1 -1
  204. package/sensor/dist/telemetry/index.js +16 -16
  205. package/sensor/dist/telemetry/index.js.map +1 -1
  206. package/sensor/dist/types.d.ts +2 -2
  207. package/sensor/dist/types.js +1 -1
  208. package/sensor/dist/ui/color.d.ts +2 -2
  209. package/sensor/dist/ui/color.js +2 -2
  210. package/sensor/dist/ui/glyphs.d.ts +3 -3
  211. package/sensor/dist/ui/glyphs.js +7 -7
  212. package/sensor/dist/ui/glyphs.js.map +1 -1
  213. package/sensor/dist/utils.d.ts +4 -4
  214. package/sensor/dist/utils.js +8 -8
  215. package/sensor/dist/utils.js.map +1 -1
  216. package/sensor/package.json +8 -13
  217. package/src/artifact-contracts.mjs +2 -2
  218. package/src/boundary-compiler.mjs +28 -28
  219. package/src/boundary-observation-compiler-v2.mjs +10 -10
  220. package/src/bounded-seam.mjs +144 -0
  221. package/src/bridge-cli.mjs +227 -0
  222. package/src/bridge-config.mjs +346 -0
  223. package/src/bridge-daemon.mjs +328 -0
  224. package/src/bridge-launch-agent.mjs +311 -0
  225. package/src/bridge-server.mjs +309 -0
  226. package/src/cli-help.mjs +163 -0
  227. package/src/control-compiler.mjs +30 -30
  228. package/src/dag-chain.mjs +261 -0
  229. package/src/factory-diagnostics.mjs +8 -7
  230. package/src/hash-chain.mjs +76 -0
  231. package/src/node-version-guard.mjs +5 -4
  232. package/src/project-cli.mjs +392 -0
  233. package/src/project-identity.mjs +71 -0
  234. package/src/rc1-evidence-bundle.mjs +16 -16
  235. package/src/rc1-v4-campaign.mjs +15 -14
  236. package/src/rc1-v5-artifact-set.mjs +2 -2
  237. package/src/rc1-v5-campaign.mjs +15 -14
  238. package/src/rc1-v6-artifact-set.mjs +18 -18
  239. package/src/rc1-v6-campaign.mjs +16 -16
  240. package/src/rc1-v6-causal-binding.mjs +16 -14
  241. package/src/rc1-v6-measurement.mjs +20 -38
  242. package/src/rc2-artifact-set.mjs +45 -40
  243. package/src/rc2-campaign.mjs +48 -66
  244. package/src/rc2-delivery-policy-front-end.mjs +30 -30
  245. package/src/rc2-rc1-transfer-front-end.mjs +5 -5
  246. package/src/rc3-actual-dogfood.mjs +6 -6
  247. package/src/rc3-dogfood-scaffold.mjs +12 -7
  248. package/src/rc3-scripted-campaign.mjs +75 -21
  249. package/src/rc4-stage1-dogfood.mjs +24 -7
  250. package/src/runtime-cli.mjs +2424 -45
  251. package/src/runtime-contracts.mjs +7 -7
  252. package/src/runtime-control-store.mjs +547 -0
  253. package/src/runtime-controller-protocol.mjs +517 -0
  254. package/src/runtime-direct-os-observer.mjs +284 -0
  255. package/src/runtime-engine.mjs +2 -2
  256. package/src/runtime-errors.mjs +1 -1
  257. package/src/runtime-event-store.mjs +15 -43
  258. package/src/runtime-front-end.mjs +26 -26
  259. package/src/runtime-gate-store.mjs +477 -0
  260. package/src/runtime-hold-recompile.mjs +214 -23
  261. package/src/runtime-lifecycle-lock.mjs +290 -0
  262. package/src/runtime-managed-supervisor.mjs +1276 -0
  263. package/src/runtime-multi-epoch-store.mjs +761 -0
  264. package/src/runtime-projection.mjs +62 -0
  265. package/src/seam-transform.mjs +38 -38
  266. package/src/{codegraph-adapter.mjs → sensor-adapter.mjs} +7 -7
  267. package/src/sensor-cli.mjs +107 -0
  268. package/src/sensor-runtime.mjs +48 -0
  269. package/src/timestamp-contract.mjs +8 -0
  270. package/src/todo-chain.mjs +178 -0
  271. package/src/todo-cli.mjs +1032 -0
  272. package/src/todo-contracts.mjs +501 -0
  273. package/src/todo-dashboard-registry.mjs +318 -0
  274. package/src/todo-gantt-html.mjs +416 -0
  275. package/src/todo-gantt-layout.mjs +603 -0
  276. package/src/todo-gantt-live.mjs +269 -0
  277. package/src/todo-gantt-presentation.mjs +217 -0
  278. package/src/todo-gantt-svg.mjs +249 -0
  279. package/src/todo-markdown-renderer.mjs +260 -0
  280. package/src/todo-migration.mjs +260 -0
  281. package/src/todo-narrative-anchor.mjs +130 -0
  282. package/src/todo-revision.mjs +425 -0
  283. package/src/todo-status.mjs +340 -0
  284. package/src/todo-store.mjs +3451 -0
  285. package/src/treatment-compiler.mjs +28 -28
  286. package/src/treatment-runner.mjs +42 -44
  287. package/sensor/dist/bin/codegraph.d.ts +0 -26
  288. package/sensor/dist/bin/codegraph.d.ts.map +0 -1
  289. package/sensor/dist/bin/codegraph.js.map +0 -1
  290. package/sensor/dist/bin/uninstall.d.ts +0 -14
  291. package/sensor/dist/bin/uninstall.d.ts.map +0 -1
  292. package/sensor/dist/bin/uninstall.js +0 -36
  293. package/sensor/dist/bin/uninstall.js.map +0 -1
  294. package/sensor/dist/installer/beta-signup.d.ts +0 -54
  295. package/sensor/dist/installer/beta-signup.d.ts.map +0 -1
  296. package/sensor/dist/installer/beta-signup.js +0 -178
  297. package/sensor/dist/installer/beta-signup.js.map +0 -1
  298. package/sensor/dist/installer/config-writer.d.ts +0 -28
  299. package/sensor/dist/installer/config-writer.d.ts.map +0 -1
  300. package/sensor/dist/installer/config-writer.js +0 -91
  301. package/sensor/dist/installer/config-writer.js.map +0 -1
  302. package/sensor/dist/installer/index.d.ts +0 -142
  303. package/sensor/dist/installer/index.d.ts.map +0 -1
  304. package/sensor/dist/installer/index.js +0 -622
  305. package/sensor/dist/installer/index.js.map +0 -1
  306. package/sensor/dist/installer/instructions-template.d.ts +0 -41
  307. package/sensor/dist/installer/instructions-template.d.ts.map +0 -1
  308. package/sensor/dist/installer/instructions-template.js +0 -53
  309. package/sensor/dist/installer/instructions-template.js.map +0 -1
  310. package/sensor/dist/installer/targets/antigravity.d.ts +0 -57
  311. package/sensor/dist/installer/targets/antigravity.d.ts.map +0 -1
  312. package/sensor/dist/installer/targets/antigravity.js +0 -308
  313. package/sensor/dist/installer/targets/antigravity.js.map +0 -1
  314. package/sensor/dist/installer/targets/claude.d.ts +0 -62
  315. package/sensor/dist/installer/targets/claude.d.ts.map +0 -1
  316. package/sensor/dist/installer/targets/claude.js +0 -454
  317. package/sensor/dist/installer/targets/claude.js.map +0 -1
  318. package/sensor/dist/installer/targets/codex.d.ts +0 -18
  319. package/sensor/dist/installer/targets/codex.d.ts.map +0 -1
  320. package/sensor/dist/installer/targets/codex.js +0 -185
  321. package/sensor/dist/installer/targets/codex.js.map +0 -1
  322. package/sensor/dist/installer/targets/cursor.d.ts +0 -35
  323. package/sensor/dist/installer/targets/cursor.d.ts.map +0 -1
  324. package/sensor/dist/installer/targets/cursor.js +0 -254
  325. package/sensor/dist/installer/targets/cursor.js.map +0 -1
  326. package/sensor/dist/installer/targets/gemini.d.ts +0 -26
  327. package/sensor/dist/installer/targets/gemini.d.ts.map +0 -1
  328. package/sensor/dist/installer/targets/gemini.js +0 -165
  329. package/sensor/dist/installer/targets/gemini.js.map +0 -1
  330. package/sensor/dist/installer/targets/hermes.d.ts +0 -18
  331. package/sensor/dist/installer/targets/hermes.d.ts.map +0 -1
  332. package/sensor/dist/installer/targets/hermes.js +0 -359
  333. package/sensor/dist/installer/targets/hermes.js.map +0 -1
  334. package/sensor/dist/installer/targets/kiro.d.ts +0 -27
  335. package/sensor/dist/installer/targets/kiro.d.ts.map +0 -1
  336. package/sensor/dist/installer/targets/kiro.js +0 -178
  337. package/sensor/dist/installer/targets/kiro.js.map +0 -1
  338. package/sensor/dist/installer/targets/opencode.d.ts +0 -38
  339. package/sensor/dist/installer/targets/opencode.d.ts.map +0 -1
  340. package/sensor/dist/installer/targets/opencode.js +0 -288
  341. package/sensor/dist/installer/targets/opencode.js.map +0 -1
  342. package/sensor/dist/installer/targets/registry.d.ts +0 -35
  343. package/sensor/dist/installer/targets/registry.d.ts.map +0 -1
  344. package/sensor/dist/installer/targets/registry.js +0 -91
  345. package/sensor/dist/installer/targets/registry.js.map +0 -1
  346. package/sensor/dist/installer/targets/shared.d.ts +0 -101
  347. package/sensor/dist/installer/targets/shared.d.ts.map +0 -1
  348. package/sensor/dist/installer/targets/shared.js +0 -264
  349. package/sensor/dist/installer/targets/shared.js.map +0 -1
  350. package/sensor/dist/installer/targets/toml.d.ts +0 -52
  351. package/sensor/dist/installer/targets/toml.d.ts.map +0 -1
  352. package/sensor/dist/installer/targets/toml.js +0 -147
  353. package/sensor/dist/installer/targets/toml.js.map +0 -1
  354. package/sensor/dist/installer/targets/types.d.ts +0 -108
  355. package/sensor/dist/installer/targets/types.d.ts.map +0 -1
  356. package/sensor/dist/installer/targets/types.js +0 -16
  357. package/sensor/dist/installer/targets/types.js.map +0 -1
  358. package/sensor/dist/upgrade/index.d.ts +0 -171
  359. package/sensor/dist/upgrade/index.d.ts.map +0 -1
  360. package/sensor/dist/upgrade/index.js +0 -659
  361. package/sensor/dist/upgrade/index.js.map +0 -1
  362. package/sensor/dist/upgrade/remove-binary.d.ts +0 -87
  363. package/sensor/dist/upgrade/remove-binary.d.ts.map +0 -1
  364. package/sensor/dist/upgrade/remove-binary.js +0 -289
  365. package/sensor/dist/upgrade/remove-binary.js.map +0 -1
  366. package/sensor/dist/upgrade/update-check.d.ts +0 -92
  367. package/sensor/dist/upgrade/update-check.d.ts.map +0 -1
  368. package/sensor/dist/upgrade/update-check.js +0 -258
  369. package/sensor/dist/upgrade/update-check.js.map +0 -1
  370. package/src/bootstrap.mjs +0 -88
@@ -0,0 +1,249 @@
1
+ import stringWidth from 'fast-string-width';
2
+
3
+ const STATUS_CLASSES = Object.freeze({
4
+ pending: 'status-pending',
5
+ 'in-progress': 'status-in-progress',
6
+ blocked: 'status-blocked',
7
+ done: 'status-done',
8
+ });
9
+
10
+ export const TODO_GANTT_STATUS_PRESENTATION = Object.freeze({
11
+ pending: Object.freeze({ mark: '☐', label: '未着手' }),
12
+ 'in-progress': Object.freeze({ mark: '▶', label: '作業中' }),
13
+ blocked: Object.freeze({ mark: '⛔', label: 'ブロック中' }),
14
+ done: Object.freeze({ mark: '✅', label: '完了' }),
15
+ });
16
+
17
+ export function escapeSvgText(value) {
18
+ return String(value).replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
19
+ }
20
+
21
+ export function escapeSvgAttribute(value) {
22
+ return escapeSvgText(value).replaceAll('"', '&quot;').replaceAll("'", '&#39;')
23
+ .replace(/[\u0000-\u001f\u007f]/gu, '');
24
+ }
25
+
26
+ function nodeKey(ref) {
27
+ return JSON.stringify([ref.project_id, ref.plan_key, ref.task_id]);
28
+ }
29
+
30
+ function laneKey(planKey, lane) {
31
+ return JSON.stringify([planKey, lane]);
32
+ }
33
+
34
+ const BRIDGE_RADIUS = 5;
35
+
36
+ function edgePath(edge) {
37
+ const commands = [`M ${edge.route[0][0]} ${edge.route[0][1]}`];
38
+ for (let segmentIndex = 0; segmentIndex < edge.route.length - 1; segmentIndex += 1) {
39
+ const start = edge.route[segmentIndex];
40
+ const end = edge.route[segmentIndex + 1];
41
+ const bridges = (edge.bridges ?? []).filter((bridge) => bridge.segment_index === segmentIndex);
42
+ if (start[1] !== end[1] || bridges.length === 0) {
43
+ commands.push(`L ${end[0]} ${end[1]}`);
44
+ continue;
45
+ }
46
+ const direction = end[0] > start[0] ? 1 : -1;
47
+ for (const bridge of bridges) {
48
+ commands.push(`L ${bridge.x - direction * BRIDGE_RADIUS} ${bridge.y}`);
49
+ commands.push(`A ${BRIDGE_RADIUS} ${BRIDGE_RADIUS} 0 0 ${direction > 0 ? 1 : 0} ${bridge.x + direction * BRIDGE_RADIUS} ${bridge.y}`);
50
+ }
51
+ commands.push(`L ${end[0]} ${end[1]}`);
52
+ }
53
+ return commands.join(' ');
54
+ }
55
+
56
+ function arrowHead(route) {
57
+ const [x, y] = route.at(-1);
58
+ const [previousX, previousY] = route.at(-2);
59
+ const deltaX = x - previousX;
60
+ const deltaY = y - previousY;
61
+ const length = Math.hypot(deltaX, deltaY) || 1;
62
+ const unitX = deltaX / length;
63
+ const unitY = deltaY / length;
64
+ const baseX = x - unitX * 6;
65
+ const baseY = y - unitY * 6;
66
+ const perpendicularX = -unitY * 3;
67
+ const perpendicularY = unitX * 3;
68
+ const compact = (value) => Number(value.toFixed(3));
69
+ return `<polygon class="edge-arrow" points="${x},${y} ${compact(baseX + perpendicularX)},${compact(baseY + perpendicularY)} ${compact(baseX - perpendicularX)},${compact(baseY - perpendicularY)}"></polygon>`;
70
+ }
71
+
72
+ function renderJunction(edge) {
73
+ if (edge.junction === null || edge.junction === undefined) return '';
74
+ const [x, y] = edge.junction;
75
+ return `<g class="join-marker" aria-label="join ${escapeSvgAttribute(edge.join_ids.join(', '))}"><circle cx="${x}" cy="${y}" r="4"></circle><title>${escapeSvgText(edge.join_ids.join(', '))}</title></g>`;
76
+ }
77
+
78
+ function renderConnector(connector) {
79
+ return `<g class="join-connector" data-connector-id="${escapeSvgAttribute(connector.id)}"><path class="edge-route" d="${escapeSvgAttribute(edgePath(connector))}"></path></g>`;
80
+ }
81
+
82
+ function renderEdge(edge, laneKeysByNode) {
83
+ if (!edge.visible || edge.route === null) return '';
84
+ const classes = ['dependency-edge'];
85
+ if (edge.visibility.longest_dependency_chain) classes.push('longest-chain-edge');
86
+ if (edge.visibility.selected_incident) classes.push('selected-incident-edge');
87
+ const fromLaneKey = laneKeysByNode.get(nodeKey(edge.from));
88
+ const toLaneKey = laneKeysByNode.get(nodeKey(edge.to));
89
+ return `<g class="${classes.join(' ')}" data-edge-id="${escapeSvgAttribute(edge.id)}" data-from-node-key="${escapeSvgAttribute(nodeKey(edge.from))}" data-to-node-key="${escapeSvgAttribute(nodeKey(edge.to))}" data-from-lane-key="${escapeSvgAttribute(fromLaneKey)}" data-to-lane-key="${escapeSvgAttribute(toLaneKey)}"><path class="edge-route" d="${escapeSvgAttribute(edgePath(edge))}"></path>${arrowHead(edge.route)}</g>`;
90
+ }
91
+
92
+ function truncateLabel(value, maximum = 17) {
93
+ const source = String(value);
94
+ if (stringWidth(source) <= maximum) return source;
95
+ let result = '';
96
+ for (const character of source) {
97
+ if (stringWidth(`${result}${character}…`) > maximum) break;
98
+ result += character;
99
+ }
100
+ return `${result}…`;
101
+ }
102
+
103
+ function wrapLabel(value, maximum = 30, maximumLines = 2) {
104
+ const characters = [...String(value)];
105
+ const lines = [];
106
+ let cursor = 0;
107
+ for (let lineIndex = 0; lineIndex < maximumLines && cursor < characters.length; lineIndex += 1) {
108
+ const remaining = characters.slice(cursor).join('');
109
+ if (stringWidth(remaining) <= maximum) {
110
+ lines.push(remaining);
111
+ cursor = characters.length;
112
+ break;
113
+ }
114
+ if (lineIndex === maximumLines - 1) {
115
+ lines.push(truncateLabel(remaining, maximum));
116
+ cursor = characters.length;
117
+ break;
118
+ }
119
+ let line = '';
120
+ while (cursor < characters.length && stringWidth(`${line}${characters[cursor]}`) <= maximum) {
121
+ line += characters[cursor];
122
+ cursor += 1;
123
+ }
124
+ if (line === '') {
125
+ line = characters[cursor];
126
+ cursor += 1;
127
+ }
128
+ lines.push(line);
129
+ }
130
+ return lines.length === 0 ? [''] : lines;
131
+ }
132
+
133
+ function presentationMaps(presentation) {
134
+ return {
135
+ lanes: new Map((presentation?.lanes ?? []).map((entry) => [laneKey(entry.plan_key, entry.lane), entry])),
136
+ taskNumbers: new Map((presentation?.task_numbers ?? []).map((entry) => [nodeKey(entry), entry])),
137
+ };
138
+ }
139
+
140
+ function renderNode(node, maps) {
141
+ if (!node.visible || node.geometry === null) return '';
142
+ const { x, y, width, height } = node.geometry;
143
+ const classes = ['todo-node', STATUS_CLASSES[node.status] ?? 'status-unknown'];
144
+ if (node.visibility.longest_dependency_chain) classes.push('longest-chain-node');
145
+ if (node.visibility.active) classes.push('active-node');
146
+ if (node.visibility.next_ready) classes.push('next-ready-node');
147
+ if (node.visibility.selected) classes.push('selected-node');
148
+ const key = nodeKey(node.ref);
149
+ const nodeLaneKey = laneKey(node.ref.plan_key, node.lane);
150
+ const status = TODO_GANTT_STATUS_PRESENTATION[node.status] ?? { mark: '?', label: '状態不明' };
151
+ const lane = maps.lanes.get(nodeLaneKey);
152
+ const laneLabel = lane === undefined ? node.lane : `${node.lane}、${lane.name}`;
153
+ const taskNumber = maps.taskNumbers.get(key);
154
+ const visibleReference = taskNumber === undefined ? `ID ${node.ref.task_id}` : `工程 ${taskNumber.display_number}`;
155
+ const spokenReference = taskNumber === undefined ? `ID ${node.ref.task_id}` : `工程${taskNumber.display_number}`;
156
+ const readyLabel = node.visibility.next_ready ? '。ready frontierの同時dispatch候補' : '';
157
+ const ariaLabel = `${spokenReference}。${status.label}。${laneLabel}。${node.title}。正規ID ${node.ref.plan_key}/${node.ref.task_id}${readyLabel}`;
158
+ const statusBar = node.status === 'in-progress'
159
+ ? `<line class="status-bar" x1="${x + 5}" y1="${y + 6}" x2="${x + 5}" y2="${y + height - 6}"></line>` : '';
160
+ const titleLines = wrapLabel(node.title);
161
+ const titleMarkup = titleLines.map((line, index) => `<tspan x="${x + 10}" dy="${index === 0 ? 0 : 17}" class="node-title-line">${escapeSvgText(line)}</tspan>`).join('');
162
+ const taskNumberAttributes = taskNumber === undefined ? ''
163
+ : ` data-task-number="${escapeSvgAttribute(taskNumber.display_number)}" data-task-number-normalized="${escapeSvgAttribute(taskNumber.normalized_number)}" data-task-number-globally-unique="${taskNumber.globally_unique ? 'true' : 'false'}"`;
164
+ return `<g class="${classes.join(' ')}" data-node-key="${escapeSvgAttribute(key)}" data-lane-key="${escapeSvgAttribute(nodeLaneKey)}" data-project-id="${escapeSvgAttribute(node.ref.project_id)}" data-plan-key="${escapeSvgAttribute(node.ref.plan_key)}" data-task-id="${escapeSvgAttribute(node.ref.task_id)}"${taskNumberAttributes} tabindex="0" role="button" aria-selected="${node.visibility.selected ? 'true' : 'false'}" aria-label="${escapeSvgAttribute(ariaLabel)}"><rect class="node-surface" x="${x}" y="${y}" width="${width}" height="${height}" rx="4"></rect>${statusBar}<text class="status-mark" x="${x + 10}" y="${y + 21}">${escapeSvgText(status.mark)}</text><text class="node-meta" x="${x + 34}" y="${y + 20}">${escapeSvgText(`${status.label} · ${visibleReference}`)}</text><text class="node-title" x="${x + 10}" y="${y + 42}">${titleMarkup}</text><title>${escapeSvgText(`${spokenReference}: ${node.title} — ${status.label} — ${laneLabel} — 正規ID ${node.ref.plan_key}/${node.ref.task_id}`)}</title></g>`;
165
+ }
166
+
167
+ function summaryLabel(value, maximum = 34) {
168
+ return truncateLabel(value, maximum);
169
+ }
170
+
171
+ function summaryChipWidth(label, minimum = 116) {
172
+ return Math.max(minimum, Math.min(280, 24 + stringWidth(label) * 7));
173
+ }
174
+
175
+ function renderTodoSummary(layout, maps) {
176
+ const markup = [];
177
+ let groupX = 16;
178
+ for (const plan of layout.groups.plans) {
179
+ const lanes = layout.groups.lanes.filter((lane) => lane.plan_key === plan.plan_key);
180
+ const laneChips = lanes.map((lane) => {
181
+ const metadata = maps.lanes.get(laneKey(lane.plan_key, lane.lane));
182
+ const fullLabel = metadata === undefined
183
+ ? `${lane.lane} ${lane.task_count}`
184
+ : `${lane.lane} · ${metadata.name} ${lane.task_count}`;
185
+ const label = summaryLabel(fullLabel);
186
+ const ariaLabel = metadata === undefined
187
+ ? `${lane.lane} — ${lane.task_count} ToDo`
188
+ : `${lane.lane} — ${metadata.name}、${lane.task_count} ToDo。${metadata.description}`;
189
+ return { lane, metadata, fullLabel, ariaLabel, label, width: summaryChipWidth(label) };
190
+ });
191
+ const childrenWidth = laneChips.reduce((total, chip) => total + chip.width, 0)
192
+ + Math.max(0, laneChips.length - 1) * 8;
193
+ const planLabel = summaryLabel(`${plan.plan_key} · ${plan.task_count} ToDo`);
194
+ const contentWidth = Math.max(summaryChipWidth(planLabel, 152), childrenWidth);
195
+ const groupWidth = contentWidth + 16;
196
+ markup.push(`<g class="summary-plan-group" aria-label="${escapeSvgAttribute(`${plan.plan_key} — ${plan.task_count} ToDo、${laneChips.length} lanes`)}"><rect class="summary-container" x="${groupX}" y="8" width="${groupWidth}" height="72" rx="8"></rect><g class="summary-plan" aria-label="${escapeSvgAttribute(`${plan.plan_key} — ${plan.task_count} ToDo`)}"><rect class="summary-chip plan-chip" x="${groupX + 8}" y="16" width="${summaryChipWidth(planLabel, 152)}" height="24" rx="9999"></rect><text x="${groupX + 20}" y="33">${escapeSvgText(planLabel)}</text><title>${escapeSvgText(`${plan.plan_key}: ${plan.task_count} ToDo`)}</title></g>`);
197
+ let laneX = groupX + 8;
198
+ for (const chip of laneChips) {
199
+ const key = laneKey(chip.lane.plan_key, chip.lane.lane);
200
+ markup.push(`<g class="summary-lane" data-lane-key="${escapeSvgAttribute(key)}" role="button" tabindex="0" aria-pressed="false" aria-label="${escapeSvgAttribute(chip.ariaLabel)}"><rect class="summary-chip lane-chip" x="${laneX}" y="48" width="${chip.width}" height="24" rx="9999"></rect><text x="${laneX + 12}" y="65">${escapeSvgText(chip.label)}</text><title>${escapeSvgText(chip.ariaLabel)}</title></g>`);
201
+ laneX += chip.width + 8;
202
+ }
203
+ markup.push('</g>');
204
+ groupX += groupWidth + 16;
205
+ }
206
+ return { markup: `<g class="todo-summary" aria-label="カテゴリ別ToDo集計表">${markup.join('')}</g>`, height: 96, width: groupX };
207
+ }
208
+
209
+ export function renderTodoGanttSvg(layout, options = {}) {
210
+ if (layout === null || typeof layout !== 'object' || layout.schema !== 'lattice.todo_gantt_layout.v1'
211
+ || !Array.isArray(layout.nodes) || !Array.isArray(layout.edges)) {
212
+ throw new TypeError('layout must be lattice.todo_gantt_layout.v1');
213
+ }
214
+ const maps = presentationMaps(options.presentation);
215
+ const summary = renderTodoSummary(layout, maps);
216
+ const contentOffset = summary.height;
217
+ const width = Math.max(240, layout.bounds.width + 40, summary.width + 12);
218
+ const height = Math.max(240, layout.bounds.height + contentOffset + 32);
219
+ const laneKeysByNode = new Map(layout.nodes.map((node) => [
220
+ nodeKey(node.ref), laneKey(node.ref.plan_key, node.lane),
221
+ ]));
222
+ const nodes = layout.nodes.map((node) => {
223
+ if (node.geometry === null) return '';
224
+ return renderNode({ ...node, geometry: { ...node.geometry, y: node.geometry.y + contentOffset } }, maps);
225
+ }).join('');
226
+ // Edge coordinates need the same vertical offset as nodes.
227
+ const shiftedEdgeModels = layout.edges.map((edge) => edge.route === null ? edge : ({
228
+ ...edge,
229
+ route: edge.route.map(([x, y]) => [x, y + contentOffset]),
230
+ bridges: (edge.bridges ?? []).map((bridge) => ({ ...bridge, y: bridge.y + contentOffset })),
231
+ junction: edge.junction === null || edge.junction === undefined
232
+ ? null : [edge.junction[0], edge.junction[1] + contentOffset],
233
+ }));
234
+ const shiftedConnectors = (layout.connectors ?? []).map((connector) => ({
235
+ ...connector,
236
+ route: connector.route.map(([x, y]) => [x, y + contentOffset]),
237
+ bridges: (connector.bridges ?? []).map((bridge) => ({ ...bridge, y: bridge.y + contentOffset })),
238
+ contacts: (connector.contacts ?? []).map(([x, y]) => [x, y + contentOffset]),
239
+ }));
240
+ const shiftedEdges = shiftedEdgeModels.map((edge) => renderEdge(edge, laneKeysByNode)).join('');
241
+ const connectors = shiftedConnectors.map(renderConnector).join('');
242
+ const junctions = shiftedEdgeModels.map(renderJunction).join('');
243
+ const mainJunctions = new Set(shiftedEdgeModels.filter(({ junction }) => junction !== null)
244
+ .map(({ junction }) => junction.join(',')));
245
+ const contactMarkers = shiftedConnectors.flatMap(({ contacts }) => contacts)
246
+ .filter((contact) => !mainJunctions.has(contact.join(',')))
247
+ .map(([x, y]) => `<circle class="join-contact-marker" cx="${x}" cy="${y}" r="3"></circle>`).join('');
248
+ return `<svg class="todo-gantt" data-gantt-svg data-svg-width="${width}" data-svg-height="${height}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}" role="group" aria-label="Todo依存工程図"><desc>縦方向は登録済み依存関係による工程段階。構造上の最長依存鎖は各工程を同じ重みとして数え、実時間・工数・資源律速を表さない。</desc>${summary.markup}<g class="edge-layer">${shiftedEdges}<g class="connector-layer">${connectors}</g><g class="junction-layer">${junctions}${contactMarkers}</g></g><g class="node-layer">${nodes}</g></svg>`;
249
+ }
@@ -0,0 +1,260 @@
1
+ import { unified } from 'unified';
2
+ import remarkGfm from 'remark-gfm';
3
+ import remarkParse from 'remark-parse';
4
+
5
+ export const TODO_MARKDOWN_SECTION_MAX_BYTES = 256 * 1024;
6
+
7
+ const markdownParser = unified().use(remarkParse).use(remarkGfm);
8
+ const unicodeDirectionControl = /[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/u;
9
+ const unicodeDirectionControls = /[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/gu;
10
+ const scriptUnsafeCharacters = /[<>&\u061c\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/gu;
11
+
12
+ export class TodoMarkdownRenderError extends Error {
13
+ constructor(code, message, detail = {}) {
14
+ super(message);
15
+ this.name = 'TodoMarkdownRenderError';
16
+ this.code = code;
17
+ this.detail = detail;
18
+ }
19
+ }
20
+
21
+ export class TodoMarkdownSectionTooLargeError extends TodoMarkdownRenderError {
22
+ constructor(actualBytes) {
23
+ super(
24
+ 'TODO_MARKDOWN_SECTION_TOO_LARGE',
25
+ `todo Markdown section is ${actualBytes} bytes; maximum is ${TODO_MARKDOWN_SECTION_MAX_BYTES}`,
26
+ { actual_bytes: actualBytes, maximum_bytes: TODO_MARKDOWN_SECTION_MAX_BYTES },
27
+ );
28
+ this.name = 'TodoMarkdownSectionTooLargeError';
29
+ }
30
+ }
31
+
32
+ function escapeHtml(value) {
33
+ return value.replaceAll('&', '&amp;')
34
+ .replaceAll('<', '&lt;')
35
+ .replaceAll('>', '&gt;')
36
+ .replaceAll('"', '&quot;')
37
+ .replaceAll("'", '&#39;');
38
+ }
39
+
40
+ function isNode(value) {
41
+ return value !== null && typeof value === 'object' && typeof value.type === 'string';
42
+ }
43
+
44
+ function safeHttpUrl(value) {
45
+ if (typeof value !== 'string' || !/^https?:\/\//iu.test(value)) return null;
46
+ if (/[\u0000-\u0020\u007f]/u.test(value)) return null;
47
+ if (unicodeDirectionControl.test(value)) return null;
48
+ try {
49
+ const parsed = new URL(value);
50
+ if ((parsed.protocol !== 'https:' && parsed.protocol !== 'http:') || parsed.hostname === '') {
51
+ return null;
52
+ }
53
+ return parsed.href;
54
+ } catch {
55
+ return null;
56
+ }
57
+ }
58
+
59
+ function renderChildren(node, path, state, context = {}) {
60
+ if (!Array.isArray(node.children)) {
61
+ state.discarded.push({ path, type: node.type, reason: 'invalid_children' });
62
+ return '';
63
+ }
64
+ return node.children
65
+ .map((child, index) => renderNode(child, `${path}.children[${index}]`, state, context))
66
+ .join('');
67
+ }
68
+
69
+ function renderText(node, path, state) {
70
+ if (typeof node.value !== 'string') {
71
+ state.discarded.push({ path, type: node.type, reason: 'invalid_value' });
72
+ return '';
73
+ }
74
+ const withoutDirectionControls = node.value.replace(unicodeDirectionControls, '');
75
+ if (withoutDirectionControls !== node.value) {
76
+ state.discarded.push({ path, type: node.type, reason: 'unicode_direction_control' });
77
+ }
78
+ return escapeHtml(withoutDirectionControls);
79
+ }
80
+
81
+ function renderNode(node, path, state, context = {}) {
82
+ if (!isNode(node)) {
83
+ state.discarded.push({ path, type: 'invalid', reason: 'invalid_node' });
84
+ return '';
85
+ }
86
+
87
+ switch (node.type) {
88
+ case 'root':
89
+ return renderChildren(node, path, state, context);
90
+ case 'text':
91
+ return renderText(node, path, state);
92
+ case 'heading': {
93
+ if (!Number.isInteger(node.depth) || node.depth < 1 || node.depth > 6) {
94
+ state.discarded.push({ path, type: node.type, reason: 'invalid_depth' });
95
+ return '';
96
+ }
97
+ return `<h${node.depth}>${renderChildren(node, path, state)}</h${node.depth}>`;
98
+ }
99
+ case 'paragraph': {
100
+ const content = renderChildren(node, path, state);
101
+ return content === '' ? '' : `<p>${content}</p>`;
102
+ }
103
+ case 'list': {
104
+ const tag = node.ordered === true ? 'ol' : 'ul';
105
+ let start = '';
106
+ if (tag === 'ol' && Number.isSafeInteger(node.start) && node.start > 1) {
107
+ start = ` start="${node.start}"`;
108
+ }
109
+ return `<${tag}${start}>${renderChildren(node, path, state, context)}</${tag}>`;
110
+ }
111
+ case 'listItem': {
112
+ const line = node.position?.start?.line;
113
+ const taskState = context.taskCheckboxes === true && typeof node.checked === 'boolean'
114
+ && Number.isSafeInteger(line) ? context.taskStatesByLine?.get(line) : undefined;
115
+ const checkbox = taskState === undefined
116
+ ? (context.taskCheckboxes === true && typeof node.checked === 'boolean'
117
+ ? `<span title="状態表示(更新は lattice todo CLI)" class="markdown-checkbox" role="img" aria-label="${node.checked ? 'checked' : 'unchecked'}">${node.checked ? '☑' : '☐'}</span>` : '')
118
+ : `<span title="状態表示(更新は lattice todo CLI)" class="document-status status-${escapeHtml(String(taskState.status))}" data-narrative-key="${escapeHtml(String(taskState.narrativeKey))}" role="img" aria-label="${escapeHtml(String(taskState.label))}">${escapeHtml(String(taskState.mark))}</span>`;
119
+ const taskClass = checkbox === '' ? '' : ' class="markdown-task"';
120
+ const blockedReason = taskState?.status === 'blocked'
121
+ ? `<span class="blocked-reason"> — ${escapeHtml(String(taskState.blockedReason ?? '理由未記録'))}</span>` : '';
122
+ return `<li${taskClass}>${checkbox}${renderChildren(node, path, state, context)}${blockedReason}</li>`;
123
+ }
124
+ case 'strong':
125
+ return `<strong>${renderChildren(node, path, state)}</strong>`;
126
+ case 'emphasis':
127
+ return `<em>${renderChildren(node, path, state)}</em>`;
128
+ case 'inlineCode':
129
+ return `<code>${renderText(node, path, state)}</code>`;
130
+ case 'code':
131
+ return `<pre><code>${renderText(node, path, state)}</code></pre>`;
132
+ case 'blockquote':
133
+ return `<blockquote>${renderChildren(node, path, state, context)}</blockquote>`;
134
+ case 'link': {
135
+ const href = safeHttpUrl(node.url);
136
+ const label = renderChildren(node, path, state);
137
+ if (href === null) {
138
+ state.discarded.push({ path, type: node.type, reason: 'unsafe_url' });
139
+ return label;
140
+ }
141
+ let title = '';
142
+ if (typeof node.title === 'string') {
143
+ const safeTitle = node.title.replace(unicodeDirectionControls, '');
144
+ if (safeTitle !== node.title) {
145
+ state.discarded.push({ path, type: node.type, reason: 'unicode_direction_control' });
146
+ }
147
+ title = ` title="${escapeHtml(safeTitle)}"`;
148
+ }
149
+ return `<a href="${escapeHtml(href)}"${title}>${label}</a>`;
150
+ }
151
+ case 'break':
152
+ return '<br>';
153
+ case 'thematicBreak':
154
+ return '<hr>';
155
+ case 'table': {
156
+ if (!Array.isArray(node.children)) {
157
+ state.discarded.push({ path, type: node.type, reason: 'invalid_children' });
158
+ return '';
159
+ }
160
+ const rows = node.children.map((child, index) => renderNode(
161
+ child,
162
+ `${path}.children[${index}]`,
163
+ state,
164
+ { ...context, tableHeader: index === 0 },
165
+ )).join('');
166
+ return `<table><tbody>${rows}</tbody></table>`;
167
+ }
168
+ case 'tableRow':
169
+ return `<tr>${renderChildren(node, path, state, context)}</tr>`;
170
+ case 'tableCell': {
171
+ const tag = context.tableHeader ? 'th' : 'td';
172
+ return `<${tag}>${renderChildren(node, path, state, context)}</${tag}>`;
173
+ }
174
+ case 'html':
175
+ state.discarded.push({ path, type: node.type, reason: 'raw_html' });
176
+ return '';
177
+ case 'image':
178
+ state.discarded.push({ path, type: node.type, reason: 'image' });
179
+ return '';
180
+ default:
181
+ state.discarded.push({ path, type: node.type, reason: 'unknown_type' });
182
+ return '';
183
+ }
184
+ }
185
+
186
+ export function renderTodoMarkdownAst(tree) {
187
+ if (!isNode(tree) || tree.type !== 'root') {
188
+ throw new TodoMarkdownRenderError(
189
+ 'TODO_MARKDOWN_INVALID_AST',
190
+ 'todo Markdown AST must be an mdast root node',
191
+ );
192
+ }
193
+ const state = { discarded: [] };
194
+ return {
195
+ html: renderNode(tree, 'root', state),
196
+ discarded: state.discarded,
197
+ };
198
+ }
199
+
200
+ export function renderTodoMarkdown(markdown) {
201
+ if (typeof markdown !== 'string') {
202
+ throw new TodoMarkdownRenderError(
203
+ 'TODO_MARKDOWN_INVALID_INPUT',
204
+ 'todo Markdown section must be a string',
205
+ );
206
+ }
207
+ const actualBytes = Buffer.byteLength(markdown, 'utf8');
208
+ if (actualBytes > TODO_MARKDOWN_SECTION_MAX_BYTES) {
209
+ throw new TodoMarkdownSectionTooLargeError(actualBytes);
210
+ }
211
+ return renderTodoMarkdownAst(markdownParser.parse(markdown));
212
+ }
213
+
214
+ export function parseTodoMarkdownDocument(markdown) {
215
+ if (typeof markdown !== 'string') {
216
+ throw new TodoMarkdownRenderError(
217
+ 'TODO_MARKDOWN_INVALID_INPUT',
218
+ 'todo Markdown section must be a string',
219
+ );
220
+ }
221
+ const actualBytes = Buffer.byteLength(markdown, 'utf8');
222
+ if (actualBytes > TODO_MARKDOWN_SECTION_MAX_BYTES) {
223
+ throw new TodoMarkdownSectionTooLargeError(actualBytes);
224
+ }
225
+ return markdownParser.parse(markdown);
226
+ }
227
+
228
+ export function renderTodoMarkdownDocument(markdown, { taskStatesByLine = new Map() } = {}) {
229
+ if (!(taskStatesByLine instanceof Map)) {
230
+ throw new TodoMarkdownRenderError(
231
+ 'TODO_MARKDOWN_INVALID_OPTIONS',
232
+ 'taskStatesByLine must be a Map',
233
+ );
234
+ }
235
+ const tree = parseTodoMarkdownDocument(markdown);
236
+ if (!isNode(tree) || tree.type !== 'root') {
237
+ throw new TodoMarkdownRenderError(
238
+ 'TODO_MARKDOWN_INVALID_AST',
239
+ 'todo Markdown AST must be an mdast root node',
240
+ );
241
+ }
242
+ const state = { discarded: [] };
243
+ return {
244
+ html: renderNode(tree, 'root', state, { taskCheckboxes: true, taskStatesByLine }),
245
+ discarded: state.discarded,
246
+ };
247
+ }
248
+
249
+ export function serializeJsonForScript(value) {
250
+ const serialized = JSON.stringify(value);
251
+ if (serialized === undefined) {
252
+ throw new TodoMarkdownRenderError(
253
+ 'TODO_MARKDOWN_JSON_NOT_SERIALIZABLE',
254
+ 'script JSON value must be JSON-serializable',
255
+ );
256
+ }
257
+ return serialized.replace(scriptUnsafeCharacters, (character) => (
258
+ `\\u${character.codePointAt(0).toString(16).padStart(4, '0')}`
259
+ ));
260
+ }