@askdkc/kiokuko 0.1.17 → 0.1.20

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 (539) hide show
  1. package/README.ja.md +91 -112
  2. package/README.ko.md +90 -102
  3. package/README.md +103 -262
  4. package/README.zh-CN.md +88 -102
  5. package/dist/agent-file/atomic-write.d.ts +90 -3
  6. package/dist/agent-file/atomic-write.d.ts.map +1 -1
  7. package/dist/agent-file/atomic-write.js +990 -14
  8. package/dist/agent-file/atomic-write.js.map +1 -1
  9. package/dist/agent-file/managed-block.d.ts +12 -1
  10. package/dist/agent-file/managed-block.d.ts.map +1 -1
  11. package/dist/agent-file/managed-block.js +49 -4
  12. package/dist/agent-file/managed-block.js.map +1 -1
  13. package/dist/agent-file/render.d.ts +1 -1
  14. package/dist/agent-file/render.d.ts.map +1 -1
  15. package/dist/agent-file/render.js +10 -7
  16. package/dist/agent-file/render.js.map +1 -1
  17. package/dist/akinator/agent-task.d.ts +11 -22
  18. package/dist/akinator/agent-task.d.ts.map +1 -1
  19. package/dist/akinator/agent-task.js +454 -99
  20. package/dist/akinator/agent-task.js.map +1 -1
  21. package/dist/akinator/capabilities.d.ts +18 -6
  22. package/dist/akinator/capabilities.d.ts.map +1 -1
  23. package/dist/akinator/capabilities.js +72 -35
  24. package/dist/akinator/capabilities.js.map +1 -1
  25. package/dist/akinator/capability-binding.d.ts +11 -0
  26. package/dist/akinator/capability-binding.d.ts.map +1 -0
  27. package/dist/akinator/capability-binding.js +56 -0
  28. package/dist/akinator/capability-binding.js.map +1 -0
  29. package/dist/akinator/domain.js +2 -2
  30. package/dist/akinator/domain.js.map +1 -1
  31. package/dist/akinator/knowledge-path.d.ts.map +1 -1
  32. package/dist/akinator/knowledge-path.js +409 -39
  33. package/dist/akinator/knowledge-path.js.map +1 -1
  34. package/dist/akinator/orchestrator.d.ts +3 -4
  35. package/dist/akinator/orchestrator.d.ts.map +1 -1
  36. package/dist/akinator/orchestrator.js +1 -4
  37. package/dist/akinator/orchestrator.js.map +1 -1
  38. package/dist/akinator/service.d.ts +0 -4
  39. package/dist/akinator/service.d.ts.map +1 -1
  40. package/dist/akinator/service.js +19 -35
  41. package/dist/akinator/service.js.map +1 -1
  42. package/dist/akinator/skill-discovery-attempt.d.ts +20 -0
  43. package/dist/akinator/skill-discovery-attempt.d.ts.map +1 -0
  44. package/dist/akinator/skill-discovery-attempt.js +390 -0
  45. package/dist/akinator/skill-discovery-attempt.js.map +1 -0
  46. package/dist/akinator/store.d.ts.map +1 -1
  47. package/dist/akinator/store.js +107 -52
  48. package/dist/akinator/store.js.map +1 -1
  49. package/dist/akinator/types.d.ts +0 -12
  50. package/dist/akinator/types.d.ts.map +1 -1
  51. package/dist/cli.d.ts +2 -0
  52. package/dist/cli.d.ts.map +1 -1
  53. package/dist/cli.js +560 -150
  54. package/dist/cli.js.map +1 -1
  55. package/dist/client/server-client.d.ts +5 -3
  56. package/dist/client/server-client.d.ts.map +1 -1
  57. package/dist/client/server-client.js +486 -181
  58. package/dist/client/server-client.js.map +1 -1
  59. package/dist/commands/agent.d.ts +2 -0
  60. package/dist/commands/agent.d.ts.map +1 -1
  61. package/dist/commands/agent.js +861 -86
  62. package/dist/commands/agent.js.map +1 -1
  63. package/dist/commands/backup.d.ts +2 -1
  64. package/dist/commands/backup.d.ts.map +1 -1
  65. package/dist/commands/backup.js +71 -8
  66. package/dist/commands/backup.js.map +1 -1
  67. package/dist/commands/doctor.d.ts +5 -1
  68. package/dist/commands/doctor.d.ts.map +1 -1
  69. package/dist/commands/doctor.js +70 -26
  70. package/dist/commands/doctor.js.map +1 -1
  71. package/dist/commands/export.d.ts +0 -4
  72. package/dist/commands/export.d.ts.map +1 -1
  73. package/dist/commands/export.js +191 -32
  74. package/dist/commands/export.js.map +1 -1
  75. package/dist/commands/import.d.ts +10 -1
  76. package/dist/commands/import.d.ts.map +1 -1
  77. package/dist/commands/import.js +592 -113
  78. package/dist/commands/import.js.map +1 -1
  79. package/dist/commands/init.d.ts +19 -1
  80. package/dist/commands/init.d.ts.map +1 -1
  81. package/dist/commands/init.js +569 -22
  82. package/dist/commands/init.js.map +1 -1
  83. package/dist/commands/purge.d.ts.map +1 -1
  84. package/dist/commands/purge.js +3 -0
  85. package/dist/commands/purge.js.map +1 -1
  86. package/dist/commands/setup.d.ts +37 -8
  87. package/dist/commands/setup.d.ts.map +1 -1
  88. package/dist/commands/setup.js +448 -86
  89. package/dist/commands/setup.js.map +1 -1
  90. package/dist/commands/skills.d.ts +9 -0
  91. package/dist/commands/skills.d.ts.map +1 -0
  92. package/dist/commands/skills.js +317 -0
  93. package/dist/commands/skills.js.map +1 -0
  94. package/dist/commands/use.d.ts +10 -2
  95. package/dist/commands/use.d.ts.map +1 -1
  96. package/dist/commands/use.js +851 -73
  97. package/dist/commands/use.js.map +1 -1
  98. package/dist/config/paths.d.ts +11 -1
  99. package/dist/config/paths.d.ts.map +1 -1
  100. package/dist/config/paths.js +64 -29
  101. package/dist/config/paths.js.map +1 -1
  102. package/dist/config/project-config.d.ts +1 -0
  103. package/dist/config/project-config.d.ts.map +1 -1
  104. package/dist/config/project-config.js +70 -32
  105. package/dist/config/project-config.js.map +1 -1
  106. package/dist/context/broker.d.ts +28 -14
  107. package/dist/context/broker.d.ts.map +1 -1
  108. package/dist/context/broker.js +604 -145
  109. package/dist/context/broker.js.map +1 -1
  110. package/dist/context/delivery.d.ts +6 -21
  111. package/dist/context/delivery.d.ts.map +1 -1
  112. package/dist/context/delivery.js +196 -147
  113. package/dist/context/delivery.js.map +1 -1
  114. package/dist/context/feedback.d.ts +11 -12
  115. package/dist/context/feedback.d.ts.map +1 -1
  116. package/dist/context/feedback.js +229 -261
  117. package/dist/context/feedback.js.map +1 -1
  118. package/dist/context/ranking.d.ts +1 -12
  119. package/dist/context/ranking.d.ts.map +1 -1
  120. package/dist/context/ranking.js +13 -4
  121. package/dist/context/ranking.js.map +1 -1
  122. package/dist/context/recommendations.d.ts +0 -5
  123. package/dist/context/recommendations.d.ts.map +1 -1
  124. package/dist/context/recommendations.js +0 -1
  125. package/dist/context/recommendations.js.map +1 -1
  126. package/dist/context/run-state.d.ts +26 -0
  127. package/dist/context/run-state.d.ts.map +1 -0
  128. package/dist/context/run-state.js +399 -0
  129. package/dist/context/run-state.js.map +1 -0
  130. package/dist/context/scoped-broker.d.ts +17 -5
  131. package/dist/context/scoped-broker.d.ts.map +1 -1
  132. package/dist/context/scoped-broker.js +512 -106
  133. package/dist/context/scoped-broker.js.map +1 -1
  134. package/dist/context/selection-state.d.ts +19 -0
  135. package/dist/context/selection-state.d.ts.map +1 -0
  136. package/dist/context/selection-state.js +250 -0
  137. package/dist/context/selection-state.js.map +1 -0
  138. package/dist/db/adapter.d.ts +5 -3
  139. package/dist/db/adapter.d.ts.map +1 -1
  140. package/dist/db/adapter.js +7 -3
  141. package/dist/db/adapter.js.map +1 -1
  142. package/dist/db/capabilities.d.ts.map +1 -1
  143. package/dist/db/capabilities.js +34 -16
  144. package/dist/db/capabilities.js.map +1 -1
  145. package/dist/db/connection.d.ts +8 -0
  146. package/dist/db/connection.d.ts.map +1 -1
  147. package/dist/db/connection.js +55 -26
  148. package/dist/db/connection.js.map +1 -1
  149. package/dist/db/migrate.d.ts +28 -7
  150. package/dist/db/migrate.d.ts.map +1 -1
  151. package/dist/db/migrate.js +106 -78
  152. package/dist/db/migrate.js.map +1 -1
  153. package/dist/db/sqlite-retry.d.ts +11 -0
  154. package/dist/db/sqlite-retry.d.ts.map +1 -0
  155. package/dist/db/sqlite-retry.js +66 -0
  156. package/dist/db/sqlite-retry.js.map +1 -0
  157. package/dist/db/transaction.d.ts +13 -0
  158. package/dist/db/transaction.d.ts.map +1 -1
  159. package/dist/db/transaction.js +53 -24
  160. package/dist/db/transaction.js.map +1 -1
  161. package/dist/db/upgrade-backup.d.ts +58 -2
  162. package/dist/db/upgrade-backup.d.ts.map +1 -1
  163. package/dist/db/upgrade-backup.js +758 -28
  164. package/dist/db/upgrade-backup.js.map +1 -1
  165. package/dist/errors.d.ts +4 -0
  166. package/dist/errors.d.ts.map +1 -1
  167. package/dist/errors.js +29 -1
  168. package/dist/errors.js.map +1 -1
  169. package/dist/gateway/agent-service.d.ts +4 -1
  170. package/dist/gateway/agent-service.d.ts.map +1 -1
  171. package/dist/gateway/agent-service.js +71 -58
  172. package/dist/gateway/agent-service.js.map +1 -1
  173. package/dist/gateway/checkpoint-service.d.ts +1 -0
  174. package/dist/gateway/checkpoint-service.d.ts.map +1 -1
  175. package/dist/gateway/checkpoint-service.js +47 -24
  176. package/dist/gateway/checkpoint-service.js.map +1 -1
  177. package/dist/ledger/archive.d.ts +1 -4
  178. package/dist/ledger/archive.d.ts.map +1 -1
  179. package/dist/ledger/archive.js +77 -39
  180. package/dist/ledger/archive.js.map +1 -1
  181. package/dist/ledger/maintenance.d.ts +0 -11
  182. package/dist/ledger/maintenance.d.ts.map +1 -1
  183. package/dist/ledger/maintenance.js +24 -40
  184. package/dist/ledger/maintenance.js.map +1 -1
  185. package/dist/ledger/projection.d.ts +0 -1
  186. package/dist/ledger/projection.d.ts.map +1 -1
  187. package/dist/ledger/projection.js.map +1 -1
  188. package/dist/ledger/promotion.d.ts +0 -9
  189. package/dist/ledger/promotion.d.ts.map +1 -1
  190. package/dist/ledger/promotion.js.map +1 -1
  191. package/dist/ledger/query.d.ts +1 -15
  192. package/dist/ledger/query.d.ts.map +1 -1
  193. package/dist/ledger/query.js.map +1 -1
  194. package/dist/ledger/store.d.ts +0 -1
  195. package/dist/ledger/store.d.ts.map +1 -1
  196. package/dist/ledger/store.js +11 -8
  197. package/dist/ledger/store.js.map +1 -1
  198. package/dist/ledger/types.d.ts +0 -4
  199. package/dist/ledger/types.d.ts.map +1 -1
  200. package/dist/ledger/types.js.map +1 -1
  201. package/dist/ledger/validate.d.ts.map +1 -1
  202. package/dist/ledger/validate.js +0 -5
  203. package/dist/ledger/validate.js.map +1 -1
  204. package/dist/mcp/server.d.ts +4 -0
  205. package/dist/mcp/server.d.ts.map +1 -1
  206. package/dist/mcp/server.js +105 -54
  207. package/dist/mcp/server.js.map +1 -1
  208. package/dist/memory/audit.d.ts +0 -1
  209. package/dist/memory/audit.d.ts.map +1 -1
  210. package/dist/memory/audit.js +0 -1
  211. package/dist/memory/audit.js.map +1 -1
  212. package/dist/memory/curator.d.ts.map +1 -1
  213. package/dist/memory/curator.js +172 -96
  214. package/dist/memory/curator.js.map +1 -1
  215. package/dist/memory/entries.d.ts +12 -2
  216. package/dist/memory/entries.d.ts.map +1 -1
  217. package/dist/memory/entries.js +199 -115
  218. package/dist/memory/entries.js.map +1 -1
  219. package/dist/memory/federated-retrieval.d.ts +12 -1
  220. package/dist/memory/federated-retrieval.d.ts.map +1 -1
  221. package/dist/memory/federated-retrieval.js +183 -70
  222. package/dist/memory/federated-retrieval.js.map +1 -1
  223. package/dist/memory/hybrid-retrieval.d.ts +5 -11
  224. package/dist/memory/hybrid-retrieval.d.ts.map +1 -1
  225. package/dist/memory/hybrid-retrieval.js +78 -58
  226. package/dist/memory/hybrid-retrieval.js.map +1 -1
  227. package/dist/memory/lifecycle.d.ts.map +1 -1
  228. package/dist/memory/lifecycle.js +17 -13
  229. package/dist/memory/lifecycle.js.map +1 -1
  230. package/dist/memory/rebuild-search.d.ts +5 -0
  231. package/dist/memory/rebuild-search.d.ts.map +1 -1
  232. package/dist/memory/rebuild-search.js +101 -76
  233. package/dist/memory/rebuild-search.js.map +1 -1
  234. package/dist/memory/retrieval-query.d.ts +0 -5
  235. package/dist/memory/retrieval-query.d.ts.map +1 -1
  236. package/dist/memory/retrieval-query.js +0 -5
  237. package/dist/memory/retrieval-query.js.map +1 -1
  238. package/dist/memory/retrieval.d.ts.map +1 -1
  239. package/dist/memory/retrieval.js +25 -131
  240. package/dist/memory/retrieval.js.map +1 -1
  241. package/dist/memory/revisions.d.ts +76 -1
  242. package/dist/memory/revisions.d.ts.map +1 -1
  243. package/dist/memory/revisions.js +540 -36
  244. package/dist/memory/revisions.js.map +1 -1
  245. package/dist/memory/scoped-memory.d.ts +16 -1
  246. package/dist/memory/scoped-memory.d.ts.map +1 -1
  247. package/dist/memory/scoped-memory.js +240 -107
  248. package/dist/memory/scoped-memory.js.map +1 -1
  249. package/dist/memory/secrets.d.ts +2 -0
  250. package/dist/memory/secrets.d.ts.map +1 -1
  251. package/dist/memory/secrets.js +36 -0
  252. package/dist/memory/secrets.js.map +1 -1
  253. package/dist/memory/structured-memory.d.ts +3 -2
  254. package/dist/memory/structured-memory.d.ts.map +1 -1
  255. package/dist/memory/structured-memory.js +54 -22
  256. package/dist/memory/structured-memory.js.map +1 -1
  257. package/dist/memory/workspaces.d.ts +9 -0
  258. package/dist/memory/workspaces.d.ts.map +1 -1
  259. package/dist/memory/workspaces.js +67 -0
  260. package/dist/memory/workspaces.js.map +1 -1
  261. package/dist/package-version.d.ts +2 -0
  262. package/dist/package-version.d.ts.map +1 -0
  263. package/dist/package-version.js +7 -0
  264. package/dist/package-version.js.map +1 -0
  265. package/dist/repository/binding.d.ts +5 -0
  266. package/dist/repository/binding.d.ts.map +1 -1
  267. package/dist/repository/binding.js +117 -17
  268. package/dist/repository/binding.js.map +1 -1
  269. package/dist/repository/framework-version.d.ts +8 -0
  270. package/dist/repository/framework-version.d.ts.map +1 -0
  271. package/dist/repository/framework-version.js +29 -0
  272. package/dist/repository/framework-version.js.map +1 -0
  273. package/dist/repository/identity-value.d.ts +4 -0
  274. package/dist/repository/identity-value.d.ts.map +1 -0
  275. package/dist/repository/identity-value.js +24 -0
  276. package/dist/repository/identity-value.js.map +1 -0
  277. package/dist/repository/identity.d.ts.map +1 -1
  278. package/dist/repository/identity.js +2 -0
  279. package/dist/repository/identity.js.map +1 -1
  280. package/dist/repository/project-fingerprint.d.ts +14 -2
  281. package/dist/repository/project-fingerprint.d.ts.map +1 -1
  282. package/dist/repository/project-fingerprint.js +312 -33
  283. package/dist/repository/project-fingerprint.js.map +1 -1
  284. package/dist/repository/remote-url.d.ts +0 -1
  285. package/dist/repository/remote-url.d.ts.map +1 -1
  286. package/dist/repository/remote-url.js +0 -1
  287. package/dist/repository/remote-url.js.map +1 -1
  288. package/dist/runtime-version.d.ts +2 -1
  289. package/dist/runtime-version.d.ts.map +1 -1
  290. package/dist/runtime-version.js +21 -4
  291. package/dist/runtime-version.js.map +1 -1
  292. package/dist/serialization/boundary-json.d.ts +20 -0
  293. package/dist/serialization/boundary-json.d.ts.map +1 -0
  294. package/dist/serialization/boundary-json.js +129 -0
  295. package/dist/serialization/boundary-json.js.map +1 -0
  296. package/dist/serialization/envelope.js +1 -1
  297. package/dist/serialization/envelope.js.map +1 -1
  298. package/dist/serialization/validate.d.ts +7 -0
  299. package/dist/serialization/validate.d.ts.map +1 -1
  300. package/dist/serialization/validate.js +53 -13
  301. package/dist/serialization/validate.js.map +1 -1
  302. package/dist/server/app.js +1 -1
  303. package/dist/server/app.js.map +1 -1
  304. package/dist/server/http.d.ts +4 -3
  305. package/dist/server/http.d.ts.map +1 -1
  306. package/dist/server/http.js +90 -50
  307. package/dist/server/http.js.map +1 -1
  308. package/dist/server/idempotency.d.ts +0 -6
  309. package/dist/server/idempotency.d.ts.map +1 -1
  310. package/dist/server/idempotency.js.map +1 -1
  311. package/dist/server/router.d.ts.map +1 -1
  312. package/dist/server/router.js +21 -4
  313. package/dist/server/router.js.map +1 -1
  314. package/dist/server/routes/agent-capability-gate.d.ts +40 -0
  315. package/dist/server/routes/agent-capability-gate.d.ts.map +1 -0
  316. package/dist/server/routes/agent-capability-gate.js +182 -0
  317. package/dist/server/routes/agent-capability-gate.js.map +1 -0
  318. package/dist/server/routes/agent-events.d.ts.map +1 -1
  319. package/dist/server/routes/agent-events.js +8 -1
  320. package/dist/server/routes/agent-events.js.map +1 -1
  321. package/dist/server/routes/agent-intake.d.ts.map +1 -1
  322. package/dist/server/routes/agent-intake.js +10 -2
  323. package/dist/server/routes/agent-intake.js.map +1 -1
  324. package/dist/server/routes/agent-promotions.d.ts.map +1 -1
  325. package/dist/server/routes/agent-promotions.js +5 -2
  326. package/dist/server/routes/agent-promotions.js.map +1 -1
  327. package/dist/server/routes/agent-runs.d.ts.map +1 -1
  328. package/dist/server/routes/agent-runs.js +18 -4
  329. package/dist/server/routes/agent-runs.js.map +1 -1
  330. package/dist/server/routes/request-binding.d.ts +5 -0
  331. package/dist/server/routes/request-binding.d.ts.map +1 -0
  332. package/dist/server/routes/request-binding.js +49 -0
  333. package/dist/server/routes/request-binding.js.map +1 -0
  334. package/dist/server/routes/task5-support.d.ts +1 -8
  335. package/dist/server/routes/task5-support.d.ts.map +1 -1
  336. package/dist/server/routes/task5-support.js +1 -17
  337. package/dist/server/routes/task5-support.js.map +1 -1
  338. package/dist/server/routes/task5.d.ts.map +1 -1
  339. package/dist/server/routes/task5.js +106 -36
  340. package/dist/server/routes/task5.js.map +1 -1
  341. package/dist/server/write-queue.js +2 -2
  342. package/dist/server/write-queue.js.map +1 -1
  343. package/dist/setup/claude-config.d.ts +4 -1
  344. package/dist/setup/claude-config.d.ts.map +1 -1
  345. package/dist/setup/claude-config.js +62 -4
  346. package/dist/setup/claude-config.js.map +1 -1
  347. package/dist/setup/client-detection.d.ts +7 -2
  348. package/dist/setup/client-detection.d.ts.map +1 -1
  349. package/dist/setup/client-detection.js +27 -9
  350. package/dist/setup/client-detection.js.map +1 -1
  351. package/dist/setup/hermes-config.d.ts +4 -1
  352. package/dist/setup/hermes-config.d.ts.map +1 -1
  353. package/dist/setup/hermes-config.js +71 -17
  354. package/dist/setup/hermes-config.js.map +1 -1
  355. package/dist/setup/legacy-client-cleanup.d.ts +6 -0
  356. package/dist/setup/legacy-client-cleanup.d.ts.map +1 -0
  357. package/dist/setup/legacy-client-cleanup.js +152 -0
  358. package/dist/setup/legacy-client-cleanup.js.map +1 -0
  359. package/dist/setup/managed-text.d.ts.map +1 -1
  360. package/dist/setup/managed-text.js +11 -1
  361. package/dist/setup/managed-text.js.map +1 -1
  362. package/dist/setup/mcp-conflict.d.ts +4 -0
  363. package/dist/setup/mcp-conflict.d.ts.map +1 -0
  364. package/dist/setup/mcp-conflict.js +15 -0
  365. package/dist/setup/mcp-conflict.js.map +1 -0
  366. package/dist/setup/opencode-config.d.ts +4 -1
  367. package/dist/setup/opencode-config.d.ts.map +1 -1
  368. package/dist/setup/opencode-config.js +65 -5
  369. package/dist/setup/opencode-config.js.map +1 -1
  370. package/dist/setup/render.d.ts +4 -1
  371. package/dist/setup/render.d.ts.map +1 -1
  372. package/dist/setup/render.js +168 -18
  373. package/dist/setup/render.js.map +1 -1
  374. package/dist/setup/standard-skills.d.ts +16 -2
  375. package/dist/setup/standard-skills.d.ts.map +1 -1
  376. package/dist/setup/standard-skills.js +37 -13
  377. package/dist/setup/standard-skills.js.map +1 -1
  378. package/dist/setup/strict-json.d.ts +7 -0
  379. package/dist/setup/strict-json.d.ts.map +1 -0
  380. package/dist/setup/strict-json.js +98 -0
  381. package/dist/setup/strict-json.js.map +1 -0
  382. package/dist/setup/strict-toml.d.ts +18 -0
  383. package/dist/setup/strict-toml.d.ts.map +1 -0
  384. package/dist/setup/strict-toml.js +491 -0
  385. package/dist/setup/strict-toml.js.map +1 -0
  386. package/dist/skills/cache.d.ts +15 -0
  387. package/dist/skills/cache.d.ts.map +1 -0
  388. package/dist/skills/cache.js +19 -0
  389. package/dist/skills/cache.js.map +1 -0
  390. package/dist/skills/candidate-ranking.d.ts +15 -0
  391. package/dist/skills/candidate-ranking.d.ts.map +1 -0
  392. package/dist/skills/candidate-ranking.js +52 -0
  393. package/dist/skills/candidate-ranking.js.map +1 -0
  394. package/dist/skills/chunking.d.ts +11 -0
  395. package/dist/skills/chunking.d.ts.map +1 -0
  396. package/dist/skills/chunking.js +291 -0
  397. package/dist/skills/chunking.js.map +1 -0
  398. package/dist/skills/config.d.ts +19 -0
  399. package/dist/skills/config.d.ts.map +1 -0
  400. package/dist/skills/config.js +103 -0
  401. package/dist/skills/config.js.map +1 -0
  402. package/dist/skills/discovery-service.d.ts +26 -0
  403. package/dist/skills/discovery-service.d.ts.map +1 -0
  404. package/dist/skills/discovery-service.js +921 -0
  405. package/dist/skills/discovery-service.js.map +1 -0
  406. package/dist/skills/external-transport.d.ts +2 -0
  407. package/dist/skills/external-transport.d.ts.map +1 -0
  408. package/dist/skills/external-transport.js +30 -0
  409. package/dist/skills/external-transport.js.map +1 -0
  410. package/dist/skills/find.d.ts +16 -0
  411. package/dist/skills/find.d.ts.map +1 -0
  412. package/dist/skills/find.js +58 -0
  413. package/dist/skills/find.js.map +1 -0
  414. package/dist/skills/gap-detection.d.ts +23 -0
  415. package/dist/skills/gap-detection.d.ts.map +1 -0
  416. package/dist/skills/gap-detection.js +62 -0
  417. package/dist/skills/gap-detection.js.map +1 -0
  418. package/dist/skills/import-preparation.d.ts +4 -0
  419. package/dist/skills/import-preparation.d.ts.map +1 -0
  420. package/dist/skills/import-preparation.js +20 -0
  421. package/dist/skills/import-preparation.js.map +1 -0
  422. package/dist/skills/materialization-authority.d.ts +11 -0
  423. package/dist/skills/materialization-authority.d.ts.map +1 -0
  424. package/dist/skills/materialization-authority.js +92 -0
  425. package/dist/skills/materialization-authority.js.map +1 -0
  426. package/dist/skills/materialization-service.d.ts +22 -0
  427. package/dist/skills/materialization-service.d.ts.map +1 -0
  428. package/dist/skills/materialization-service.js +101 -0
  429. package/dist/skills/materialization-service.js.map +1 -0
  430. package/dist/skills/official-catalog.d.ts +31 -0
  431. package/dist/skills/official-catalog.d.ts.map +1 -0
  432. package/dist/skills/official-catalog.js +110 -0
  433. package/dist/skills/official-catalog.js.map +1 -0
  434. package/dist/skills/providers/schema.d.ts +30 -0
  435. package/dist/skills/providers/schema.d.ts.map +1 -0
  436. package/dist/skills/providers/schema.js +354 -0
  437. package/dist/skills/providers/schema.js.map +1 -0
  438. package/dist/skills/providers/skills-sh-compat.d.ts +17 -0
  439. package/dist/skills/providers/skills-sh-compat.d.ts.map +1 -0
  440. package/dist/skills/providers/skills-sh-compat.js +71 -0
  441. package/dist/skills/providers/skills-sh-compat.js.map +1 -0
  442. package/dist/skills/providers/skills-sh-v1.d.ts +23 -0
  443. package/dist/skills/providers/skills-sh-v1.d.ts.map +1 -0
  444. package/dist/skills/providers/skills-sh-v1.js +134 -0
  445. package/dist/skills/providers/skills-sh-v1.js.map +1 -0
  446. package/dist/skills/query-builder.d.ts +18 -0
  447. package/dist/skills/query-builder.d.ts.map +1 -0
  448. package/dist/skills/query-builder.js +93 -0
  449. package/dist/skills/query-builder.js.map +1 -0
  450. package/dist/skills/source/errors.d.ts +9 -0
  451. package/dist/skills/source/errors.d.ts.map +1 -0
  452. package/dist/skills/source/errors.js +15 -0
  453. package/dist/skills/source/errors.js.map +1 -0
  454. package/dist/skills/source/frontmatter.d.ts +9 -0
  455. package/dist/skills/source/frontmatter.d.ts.map +1 -0
  456. package/dist/skills/source/frontmatter.js +77 -0
  457. package/dist/skills/source/frontmatter.js.map +1 -0
  458. package/dist/skills/source/github-fetcher.d.ts +20 -0
  459. package/dist/skills/source/github-fetcher.d.ts.map +1 -0
  460. package/dist/skills/source/github-fetcher.js +292 -0
  461. package/dist/skills/source/github-fetcher.js.map +1 -0
  462. package/dist/skills/source/snapshot-validator.d.ts +28 -0
  463. package/dist/skills/source/snapshot-validator.d.ts.map +1 -0
  464. package/dist/skills/source/snapshot-validator.js +186 -0
  465. package/dist/skills/source/snapshot-validator.js.map +1 -0
  466. package/dist/skills/store.d.ts +181 -0
  467. package/dist/skills/store.d.ts.map +1 -0
  468. package/dist/skills/store.js +1710 -0
  469. package/dist/skills/store.js.map +1 -0
  470. package/dist/skills/types.d.ts +169 -0
  471. package/dist/skills/types.d.ts.map +1 -0
  472. package/dist/skills/types.js +2 -0
  473. package/dist/skills/types.js.map +1 -0
  474. package/dist/web/i18n.d.ts +32 -0
  475. package/dist/web/i18n.d.ts.map +1 -1
  476. package/dist/web/i18n.js +128 -0
  477. package/dist/web/i18n.js.map +1 -1
  478. package/dist/web/server.d.ts.map +1 -1
  479. package/dist/web/server.js +386 -38
  480. package/dist/web/server.js.map +1 -1
  481. package/dist/web/ui.d.ts +4 -0
  482. package/dist/web/ui.d.ts.map +1 -1
  483. package/dist/web/ui.js +382 -6
  484. package/dist/web/ui.js.map +1 -1
  485. package/migrations/009_external_skill_discovery.sql +126 -0
  486. package/package.json +6 -3
  487. package/skills/kiokuko-single-purpose-functions/SKILL.md +288 -0
  488. package/skills/kiokuko-single-purpose-functions/references/kiokuko-patterns.md +344 -0
  489. package/skills/kiokuko-single-purpose-functions/references/review-checklist.md +97 -0
  490. package/skills/kiokuko-ui-design-soul/SKILL.md +1186 -28
  491. package/templates/AGENTS.md +8 -7
  492. package/dist/client/runtime-discovery.d.ts +0 -15
  493. package/dist/client/runtime-discovery.d.ts.map +0 -1
  494. package/dist/client/runtime-discovery.js +0 -45
  495. package/dist/client/runtime-discovery.js.map +0 -1
  496. package/dist/commands/call.d.ts +0 -7
  497. package/dist/commands/call.d.ts.map +0 -1
  498. package/dist/commands/call.js +0 -10
  499. package/dist/commands/call.js.map +0 -1
  500. package/dist/commands/link.d.ts +0 -6
  501. package/dist/commands/link.d.ts.map +0 -1
  502. package/dist/commands/link.js +0 -6
  503. package/dist/commands/link.js.map +0 -1
  504. package/dist/commands/promote.d.ts +0 -6
  505. package/dist/commands/promote.d.ts.map +0 -1
  506. package/dist/commands/promote.js +0 -6
  507. package/dist/commands/promote.js.map +0 -1
  508. package/dist/commands/read.d.ts +0 -6
  509. package/dist/commands/read.d.ts.map +0 -1
  510. package/dist/commands/read.js +0 -4
  511. package/dist/commands/read.js.map +0 -1
  512. package/dist/commands/recall.d.ts +0 -6
  513. package/dist/commands/recall.d.ts.map +0 -1
  514. package/dist/commands/recall.js +0 -4
  515. package/dist/commands/recall.js.map +0 -1
  516. package/dist/commands/record.d.ts +0 -6
  517. package/dist/commands/record.d.ts.map +0 -1
  518. package/dist/commands/record.js +0 -4
  519. package/dist/commands/record.js.map +0 -1
  520. package/dist/commands/search.d.ts +0 -6
  521. package/dist/commands/search.d.ts.map +0 -1
  522. package/dist/commands/search.js +0 -4
  523. package/dist/commands/search.js.map +0 -1
  524. package/dist/commands/supersede.d.ts +0 -6
  525. package/dist/commands/supersede.d.ts.map +0 -1
  526. package/dist/commands/supersede.js +0 -6
  527. package/dist/commands/supersede.js.map +0 -1
  528. package/dist/knowledge/sources.d.ts +0 -72
  529. package/dist/knowledge/sources.d.ts.map +0 -1
  530. package/dist/knowledge/sources.js +0 -388
  531. package/dist/knowledge/sources.js.map +0 -1
  532. package/dist/setup/opencode-evidence.d.ts +0 -37
  533. package/dist/setup/opencode-evidence.d.ts.map +0 -1
  534. package/dist/setup/opencode-evidence.js +0 -58
  535. package/dist/setup/opencode-evidence.js.map +0 -1
  536. package/dist/setup/opencode-loop-guard.d.ts +0 -9
  537. package/dist/setup/opencode-loop-guard.d.ts.map +0 -1
  538. package/dist/setup/opencode-loop-guard.js +0 -248
  539. package/dist/setup/opencode-loop-guard.js.map +0 -1
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@askdkc/kiokuko",
3
- "version": "0.1.17",
3
+ "version": "0.1.20",
4
4
  "description": "Model-agnostic external memory for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "kiokuko": "dist/bin/kiokuko.js"
8
8
  },
9
9
  "engines": {
10
- "node": ">=24.0.0"
10
+ "node": ">=24.16.0"
11
11
  },
12
12
  "publishConfig": {
13
13
  "access": "public"
@@ -24,12 +24,15 @@
24
24
  "LICENSE"
25
25
  ],
26
26
  "scripts": {
27
- "build": "tsc -p tsconfig.build.json",
27
+ "clean:dist": "node --input-type=module --eval \"import { rmSync } from 'node:fs'; rmSync('dist', { recursive: true, force: true });\"",
28
+ "set-bin-permissions": "node --input-type=module --eval \"import { chmodSync } from 'node:fs'; chmodSync('dist/bin/kiokuko.js', 0o755);\"",
29
+ "build": "npm run clean:dist && tsc -p tsconfig.build.json && npm run set-bin-permissions",
28
30
  "typecheck": "tsc -p tsconfig.json --noEmit",
29
31
  "test": "node --import tsx --test tests/**/*.test.ts",
30
32
  "test:unit": "node --import tsx --test tests/unit/**/*.test.ts",
31
33
  "test:integration": "node --import tsx --test tests/integration/**/*.test.ts",
32
34
  "pack:check": "npm pack --dry-run",
35
+ "prepare": "npm run build",
33
36
  "prepublishOnly": "npm run typecheck && npm test && npm run build && npm run pack:check"
34
37
  },
35
38
  "dependencies": {
@@ -0,0 +1,288 @@
1
+ ---
2
+ name: kiokuko-single-purpose-functions
3
+ description: Use whenever writing, modifying, reviewing, debugging, or refactoring code in any language or repository. Enforce one cohesive contract per function, validation at hostile boundaries, caller-owned input immutability, narrow types, deterministic domain logic, explicit safe failures, separation of persistence and external effects, and focused runnable tests. Do not create meaningless micro-functions or rewrite unrelated code.
4
+ ---
5
+
6
+ <!-- KIOKUKO MANAGED STANDARD SKILL: kiokuko-single-purpose-functions -->
7
+
8
+ # Single-purpose function contracts
9
+
10
+ ## Objective
11
+
12
+ Build and change software by composing functions that each fulfill one explicit, testable contract.
13
+
14
+ Apply this guidance across languages, frameworks, and repositories. Typed examples are intentional: adapt their contracts to the project’s type system, validation tools, error model, persistence layer, and test framework instead of treating TypeScript syntax as a requirement.
15
+
16
+ Use it for the smallest coherent surface touched by the task. Do not turn an ordinary change into a repository-wide rewrite.
17
+
18
+ ## What “one thing” means
19
+
20
+ A function does one thing when it has:
21
+
22
+ - one cohesive externally observable responsibility;
23
+ - one primary reason to change;
24
+ - one defined success result;
25
+ - one explicit set of expected failures;
26
+ - one declared effect profile.
27
+
28
+ “One thing” does not mean one statement, one branch, or the shortest possible function.
29
+
30
+ Good examples include:
31
+
32
+ - parse one untrusted request;
33
+ - normalize one validated configuration value;
34
+ - calculate one price or ranking;
35
+ - load one record through a persistence interface;
36
+ - render one output representation;
37
+ - coordinate one atomic use case.
38
+
39
+ An orchestration function may call several functions. Its single responsibility is coordinating one use case. Keep detailed policy in domain functions and external mechanics in adapters or stores.
40
+
41
+ ## Project contracts outrank generic advice
42
+
43
+ Before changing code, inspect the relevant source, tests, documentation, types, error conventions, and adjacent helpers.
44
+
45
+ Preserve the repository’s established contracts unless the task explicitly changes them:
46
+
47
+ - public APIs and serialized formats;
48
+ - error types, codes, and messages;
49
+ - transaction and concurrency rules;
50
+ - ownership and mutation conventions;
51
+ - framework and dependency boundaries;
52
+ - security and privacy requirements;
53
+ - test and build commands.
54
+
55
+ Reuse a project helper when it already implements the required behavior. Do not introduce a parallel result type, validation library, database wrapper, dependency container, or architecture merely because it is familiar from another project.
56
+
57
+ ## Function layers
58
+
59
+ Classify every new or materially changed function before implementing it.
60
+
61
+ ### Boundary parser or validator
62
+
63
+ A boundary function receives data that is not yet trusted, including network requests, command-line input, environment variables, configuration files, database rows, files, messages, provider responses, and deserialized state.
64
+
65
+ It should:
66
+
67
+ 1. bound work before expensive processing;
68
+ 2. reject malformed shape, type, range, encoding, size, depth, count, or unknown fields when required;
69
+ 3. avoid invoking caller-controlled getters, proxies, hooks, or serialization behavior;
70
+ 4. create an owned normalized value;
71
+ 5. return that value or produce one narrow, safe expected failure.
72
+
73
+ After validation, delegate to typed or otherwise constrained internal code. Do not make every internal helper revalidate the same value.
74
+
75
+ ### Pure domain function
76
+
77
+ A pure domain function performs one decision, state transition, normalization, ranking, projection, or calculation over validated values.
78
+
79
+ It must not hide reads of time, randomness, environment, locale-sensitive state, mutable globals, filesystem, database, or network. Pass variable dependencies explicitly. The same explicit inputs should produce the same output.
80
+
81
+ ### Persistence function
82
+
83
+ A persistence function performs one storage capability.
84
+
85
+ It should:
86
+
87
+ - use the project’s established database or storage abstraction;
88
+ - parameterize queries where applicable;
89
+ - avoid transport and presentation concerns;
90
+ - avoid network and unrelated filesystem work;
91
+ - remain transaction-agnostic unless it explicitly owns the transaction;
92
+ - validate stored data before treating it as domain state;
93
+ - preserve revision, idempotency, ordering, and identity invariants.
94
+
95
+ ### Effect adapter
96
+
97
+ An adapter wraps one external capability, such as reading a file, calling a provider, obtaining time, generating an identifier, writing a response, or opening a database.
98
+
99
+ Expose the smallest capability required. Prefer a narrow function or interface over a broad service container.
100
+
101
+ ### Use-case orchestrator
102
+
103
+ An orchestrator coordinates one application operation. It may combine validation, pure decisions, persistence, and adapters, but it should not absorb their detailed policies.
104
+
105
+ ## Required contract
106
+
107
+ Before implementing a new function or materially changing an existing one, determine:
108
+
109
+ ```text
110
+ Function:
111
+ Layer: boundary | domain | persistence | adapter | orchestrator
112
+ Responsibility:
113
+ Inputs and trust level:
114
+ Input ownership:
115
+ Success output:
116
+ Expected failures:
117
+ Other propagated failures:
118
+ External effects:
119
+ Transaction or resource ownership:
120
+ Idempotency or replay behavior:
121
+ Security and privacy constraints:
122
+ Preconditions:
123
+ Postconditions:
124
+ ```
125
+
126
+ The contract may remain internal for a small change, but the implementation and tests must reflect it.
127
+
128
+ ## Non-negotiable rules
129
+
130
+ ### 1. Do not mutate caller-owned input
131
+
132
+ Treat parameters as immutable unless the contract explicitly transfers ownership.
133
+
134
+ - Do not modify caller-provided objects, arrays, maps, sets, buffers, collections, or records.
135
+ - Return a new value for transformations.
136
+ - Local mutation of newly allocated, unobservable data is allowed when it improves clarity or measured performance.
137
+ - Do not use shared mutable state for domain behavior.
138
+
139
+ Add an input-snapshot test when accidental mutation is plausible.
140
+
141
+ ### 2. Validate values at the real trust boundary
142
+
143
+ Static types, annotations, interfaces, and schemas known only to the compiler do not validate runtime data.
144
+
145
+ Use the repository’s established validation approach. Validate external JSON, database rows, configuration, files, provider responses, and messages before converting them into domain values. Reject or explicitly handle unknown fields when the contract is closed.
146
+
147
+ Use an unconstrained type such as `unknown`, a raw byte buffer, or a generic map only at a real boundary. Internal helpers should receive constrained values.
148
+
149
+ ### 3. Bound work before trust
150
+
151
+ Every externally influenced collection, string, nested object, retry loop, result set, or payload needs a justified bound.
152
+
153
+ Check limits before full traversal, expansion, hashing, serialization, proportional allocation, persistence, retrying, or returning data. Truncate only when the contract explicitly defines a preview or diagnostic field; otherwise reject oversized authoritative input.
154
+
155
+ ### 4. Produce an owned snapshot
156
+
157
+ Do not retain references to hostile or caller-controlled data after validation. Copy accepted values into owned structures before canonicalization, hashing, persistence, or asynchronous use.
158
+
159
+ Where the runtime permits hostile object behavior, account for accessors, proxies, cycles, malformed text, unsupported prototypes, and non-finite numbers.
160
+
161
+ ### 5. Use narrow types and exact states
162
+
163
+ - Prefer the strongest practical static analysis and type-checking mode supported by the project.
164
+ - Avoid escape hatches such as `any`, unchecked casts, suppressed diagnostics, or untyped dictionaries when a narrower representation is possible.
165
+ - Use enums, literal unions, sealed variants, value objects, or equivalent exact state models.
166
+ - Distinguish missing, null, unknown, empty, unavailable, and invalid when the protocol distinguishes them.
167
+ - Omit absent optional values rather than inventing ambiguous placeholders.
168
+ - Keep assertions adjacent to the runtime check that proves them.
169
+
170
+ ### 6. Make expected failures explicit and safe
171
+
172
+ Use the project’s established error taxonomy or result convention. Choose the narrowest existing failure category.
173
+
174
+ Do not use `false`, `null`, an empty string, or a swallowed exception to represent several unrelated failures. Do not catch an error merely to hide it or continue from uncertain state.
175
+
176
+ At public boundaries:
177
+
178
+ - map internal failures to stable public behavior;
179
+ - keep details bounded and allowlisted;
180
+ - never echo credentials, tokens, private data, raw request bodies, or unsafe provider responses;
181
+ - preserve both operation and cleanup failures when both occur.
182
+
183
+ ### 7. Keep domain decisions deterministic
184
+
185
+ Inject time, randomness, environment, current directory, locale, filesystem, database, network, and provider access. Use stable ordering and serialization when output participates in hashes, identities, manifests, caches, snapshots, or replay.
186
+
187
+ ### 8. Preserve transaction and resource discipline
188
+
189
+ - Let one use case own the transaction or resource lifecycle.
190
+ - Keep low-level storage functions composable inside that owner.
191
+ - Do not perform network calls, user prompts, or unrelated slow work while holding a write transaction or scarce lock.
192
+ - Do not add nested transaction ownership where an outer transaction already exists.
193
+ - Treat ambiguous commit or cleanup state explicitly; do not compensate as though rollback were proven.
194
+
195
+ ### 9. Preserve idempotency and compare-and-swap semantics
196
+
197
+ Bind every meaning-bearing input to request identities, expected revisions, generation tokens, content hashes, or cache keys.
198
+
199
+ - Exact replay may reuse the recorded acknowledgement.
200
+ - Reusing an identity with changed input is a conflict.
201
+ - Compare the exact observed version before mutation.
202
+ - Never silently overwrite newer or independently owned state.
203
+ - Never present partial or ambiguous cleanup as full success.
204
+
205
+ ### 10. Preserve external contracts
206
+
207
+ A refactor is not behavior-preserving if it accidentally changes a machine contract.
208
+
209
+ Preserve applicable command output, exit status, API schema, HTTP status, protocol envelope, database migration history, file format, line ending, file mode, ownership marker, event order, and backward-compatibility behavior.
210
+
211
+ ### 11. Keep security checks in the success path
212
+
213
+ Security validation is not optional logging. Apply required authorization, normalization, sanitization, size checks, secret detection, and path or URL restrictions before persistence or delivery.
214
+
215
+ A detected secret or invalid value must not reappear in errors, logs, hashes exposed to callers, temporary diagnostics, or responses.
216
+
217
+ ### 12. Test the contract independently
218
+
219
+ Use the repository’s existing test framework and style. Cover the applicable cases:
220
+
221
+ - normal success;
222
+ - empty, minimum, maximum, and exact boundary values;
223
+ - wrong primitive type or malformed structure;
224
+ - unknown fields for closed inputs;
225
+ - each expected failure category;
226
+ - no mutation of caller-owned input;
227
+ - no secret or raw invalid-value echo;
228
+ - deterministic ordering, hashing, or replay identity;
229
+ - exact replay and changed-input conflict;
230
+ - bounded retry and non-retryable failure;
231
+ - operation-plus-cleanup failure;
232
+ - integration with the real boundary when adapter behavior changes.
233
+
234
+ Assert observable behavior, not private call order, unless ordering itself is a documented invariant.
235
+
236
+ ## Required workflow
237
+
238
+ 1. Read the governing repository contracts and adjacent implementation.
239
+ 2. Define the smallest coherent behavior change.
240
+ 3. Classify each changed function’s layer.
241
+ 4. Determine its input, output, failure, effect, ownership, and replay contract.
242
+ 5. Validate once at the hostile boundary and create owned data.
243
+ 6. Implement deterministic policy in the pure core.
244
+ 7. Add only the narrow external capability required.
245
+ 8. Compose the use case without mixing detailed policies into orchestration.
246
+ 9. Add a regression test for the counterexample that would disprove the contract.
247
+ 10. Run the narrowest affected tests, then the repository’s documented static, type, test, build, and package checks as applicable.
248
+ 11. Report what changed, what was verified, what was skipped, and any residual risk.
249
+
250
+ Do not invent commands that are absent from the repository.
251
+
252
+ ## Decomposition tests
253
+
254
+ Split or redesign a function when one or more are true:
255
+
256
+ 1. Its responsibility requires “and then” to join unrelated observable outcomes.
257
+ 2. It validates transport data, decides policy, performs persistence, and formats a response in one body.
258
+ 3. It directly uses more than one unrelated external subsystem.
259
+ 4. It returns a value while mutating external state not required by its contract.
260
+ 5. It owns a transaction while performing network or unrelated slow work.
261
+ 6. Its pure decision can be tested only by booting unrelated infrastructure.
262
+ 7. A boolean flag switches between unrelated modes.
263
+ 8. Error mapping or validation policy is duplicated across layers.
264
+ 9. Security, replay, or cleanup state is implicit instead of represented.
265
+
266
+ Do not split when extraction would create a meaningless one-line wrapper, scatter one atomic state machine, or obscure resource ownership.
267
+
268
+ ## Prohibited shortcuts
269
+
270
+ Do not:
271
+
272
+ - claim static types prove external input is valid;
273
+ - cast external data directly into a domain type;
274
+ - weaken types merely to satisfy one inconvenient call site;
275
+ - mutate input because copying is inconvenient;
276
+ - swallow corruption, conflict, partial failure, or uncertain state;
277
+ - echo invalid or secret-like values in public failures;
278
+ - retry by matching error-message text when structured classification exists;
279
+ - run external work inside a write transaction without a documented reason;
280
+ - bypass revision, idempotency, identity, authorization, or ownership checks;
281
+ - overwrite independently owned state;
282
+ - create dozens of trivial wrappers to satisfy a function-count or line-count target;
283
+ - change public contracts as incidental cleanup;
284
+ - declare completion without naming the verification actually run.
285
+
286
+ ## Completion gate
287
+
288
+ Before declaring completion, use `references/review-checklist.md`. Read `references/kiokuko-patterns.md` when examples would help; despite the historical filename, its guidance applies across languages and repositories.
@@ -0,0 +1,344 @@
1
+ <!-- KIOKUKO MANAGED STANDARD SKILL: kiokuko-single-purpose-functions -->
2
+
3
+ # Single-purpose implementation patterns
4
+
5
+ These patterns are repository- and language-agnostic contracts illustrated with TypeScript for concreteness. Translate them into the project’s language, framework, error model, persistence layer, and test tools. Reuse existing project helpers before creating substitutes.
6
+
7
+ ## 1. Hostile boundary, constrained private core
8
+
9
+ An exported operation may accept unconstrained input when it is the real trust boundary. Validate once, create an owned value, then call a constrained helper.
10
+
11
+ ```ts
12
+ interface ValidatedWindow {
13
+ readonly start: number;
14
+ readonly limit: number;
15
+ }
16
+
17
+ function isPlainRecord(value: unknown): value is Record<string, unknown> {
18
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;
19
+ const prototype = Object.getPrototypeOf(value);
20
+ return prototype === Object.prototype || prototype === null;
21
+ }
22
+
23
+ function parseWindow(value: unknown): ValidatedWindow {
24
+ if (!isPlainRecord(value)) throw new Error('window must be an object');
25
+ if (typeof value.start !== 'number' || !Number.isInteger(value.start) || value.start < 0) {
26
+ throw new Error('window start is invalid');
27
+ }
28
+ if (typeof value.limit !== 'number' || !Number.isInteger(value.limit)
29
+ || value.limit < 1 || value.limit > 100) {
30
+ throw new Error('window limit is invalid');
31
+ }
32
+ return { start: value.start, limit: value.limit };
33
+ }
34
+
35
+ function calculateEnd(window: ValidatedWindow): number {
36
+ return window.start + window.limit;
37
+ }
38
+
39
+ export function endOfWindow(value: unknown): number {
40
+ return calculateEnd(parseWindow(value));
41
+ }
42
+ ```
43
+
44
+ Use the project’s error type and validation library where available. Do not make `calculateEnd` accept `unknown` or repeat transport validation throughout the domain.
45
+
46
+ ## 2. Closed schema at a request boundary
47
+
48
+ Use bounded schemas and reject unknown fields when the protocol is closed.
49
+
50
+ ```ts
51
+ import * as z from 'zod/v4';
52
+
53
+ const requestSchema = z.object({
54
+ requestId: z.string().trim().min(1).max(256),
55
+ paths: z.array(z.string().trim().min(1).max(1_024)).max(100),
56
+ limit: z.number().int().min(1).max(100).default(20),
57
+ }).strict();
58
+ ```
59
+
60
+ A schema is the boundary. Internal helpers should consume its validated output or a narrower domain value.
61
+
62
+ ## 3. Exact optional values
63
+
64
+ Omit absent optional properties rather than assigning ambiguous placeholders.
65
+
66
+ ```ts
67
+ interface Candidate {
68
+ readonly id: string;
69
+ readonly description?: string;
70
+ }
71
+
72
+ function candidate(id: string, description: string | undefined): Candidate {
73
+ return {
74
+ id,
75
+ ...(description === undefined ? {} : { description }),
76
+ };
77
+ }
78
+ ```
79
+
80
+ Use the equivalent convention in languages that distinguish missing, null, and empty values.
81
+
82
+ ## 4. Immutable transformation and mutation test
83
+
84
+ ```ts
85
+ interface Profile {
86
+ readonly mode: 'build' | 'debug' | null;
87
+ readonly target: string | null;
88
+ }
89
+
90
+ function withTarget(profile: Profile, target: string): Profile {
91
+ return { ...profile, target: target.trim() };
92
+ }
93
+ ```
94
+
95
+ ```ts
96
+ import assert from 'node:assert/strict';
97
+ import test from 'node:test';
98
+
99
+ test('returns a new profile without mutating the input', () => {
100
+ const input = { mode: 'build' as const, target: null };
101
+ const before = structuredClone(input);
102
+
103
+ const result = withTarget(input, ' src/index.ts ');
104
+
105
+ assert.deepEqual(result, { mode: 'build', target: 'src/index.ts' });
106
+ assert.deepEqual(input, before);
107
+ assert.notEqual(result, input);
108
+ });
109
+ ```
110
+
111
+ ## 5. Explicit variable dependencies
112
+
113
+ Keep time and randomness out of pure ranking, hashing, transition, and validation functions.
114
+
115
+ ```ts
116
+ interface Dependencies {
117
+ readonly now: () => string;
118
+ readonly createId: () => string;
119
+ }
120
+
121
+ interface CreatedRecord {
122
+ readonly id: string;
123
+ readonly createdAt: string;
124
+ }
125
+
126
+ function createRecord(dependencies: Dependencies): CreatedRecord {
127
+ return {
128
+ id: dependencies.createId(),
129
+ createdAt: dependencies.now(),
130
+ };
131
+ }
132
+ ```
133
+
134
+ Production composition supplies real dependencies; tests supply deterministic ones.
135
+
136
+ ## 6. Transaction-agnostic store, transaction-owning use case
137
+
138
+ The store performs persistence. The service or use case owns the atomic operation.
139
+
140
+ ```ts
141
+ interface Transaction {
142
+ execute(sql: string, parameters: readonly unknown[]): void;
143
+ }
144
+
145
+ interface NewItem {
146
+ readonly id: string;
147
+ readonly value: string;
148
+ }
149
+
150
+ function insertItem(transaction: Transaction, item: NewItem): void {
151
+ transaction.execute(
152
+ 'INSERT INTO items (id, value) VALUES (?, ?)',
153
+ [item.id, item.value],
154
+ );
155
+ }
156
+
157
+ function createItem(
158
+ runTransaction: (operation: (transaction: Transaction) => void) => void,
159
+ item: NewItem,
160
+ ): void {
161
+ runTransaction((transaction) => {
162
+ insertItem(transaction, item);
163
+ transaction.execute(
164
+ 'INSERT INTO audit_events (event_type, target_id) VALUES (?, ?)',
165
+ ['item_created', item.id],
166
+ );
167
+ });
168
+ }
169
+ ```
170
+
171
+ Do not let `insertItem` start its own transaction if it must compose with other writes. Do not call a provider or perform unrelated slow I/O inside the transaction.
172
+
173
+ ## 7. Validate stored data before domain use
174
+
175
+ Driver types and generated models are not always runtime proof, especially across migrations or external storage.
176
+
177
+ ```ts
178
+ interface StoredItem {
179
+ readonly id: string;
180
+ readonly revision: number;
181
+ }
182
+
183
+ function parseStoredItem(row: Record<string, unknown> | undefined): StoredItem {
184
+ if (row === undefined) throw new Error('Item not found');
185
+ if (typeof row.id !== 'string'
186
+ || typeof row.revision !== 'number'
187
+ || !Number.isInteger(row.revision)
188
+ || row.revision < 1) {
189
+ throw new Error('Stored item is invalid');
190
+ }
191
+ return { id: row.id, revision: row.revision };
192
+ }
193
+ ```
194
+
195
+ Do not include malformed row contents in a public error.
196
+
197
+ ## 8. Safe public error mapping
198
+
199
+ Public messages should be stable. Keep only allowlisted bounded details.
200
+
201
+ ```ts
202
+ interface PublicFailure {
203
+ readonly code: 'busy' | 'invalid' | 'internal';
204
+ readonly message: string;
205
+ readonly retryAfterSeconds?: number;
206
+ }
207
+
208
+ function publicFailure(error: unknown): PublicFailure {
209
+ if (isBusyFailure(error)) {
210
+ return {
211
+ code: 'busy',
212
+ message: 'Service is busy',
213
+ retryAfterSeconds: clampRetryDelay(error.retryAfterSeconds),
214
+ };
215
+ }
216
+ if (isValidationFailure(error)) {
217
+ return { code: 'invalid', message: 'Request is invalid' };
218
+ }
219
+ return { code: 'internal', message: 'Internal error' };
220
+ }
221
+ ```
222
+
223
+ Do not copy unknown exception messages, submitted values, credentials, URLs with secret query parameters, or provider bodies into public output.
224
+
225
+ ## 9. Preserve operation and cleanup failures
226
+
227
+ When both fail, retain both failures without replacing the primary one.
228
+
229
+ ```ts
230
+ async function useResource<T>(
231
+ open: () => Promise<{ close: () => Promise<void> }>,
232
+ operation: (resource: { close: () => Promise<void> }) => Promise<T>,
233
+ ): Promise<T> {
234
+ const resource = await open();
235
+ let operationFailure: unknown;
236
+ let result: { value: T } | undefined;
237
+
238
+ try {
239
+ result = { value: await operation(resource) };
240
+ } catch (error) {
241
+ operationFailure = error;
242
+ }
243
+
244
+ try {
245
+ await resource.close();
246
+ } catch (cleanupFailure) {
247
+ if (operationFailure !== undefined) {
248
+ throw new AggregateError(
249
+ [operationFailure, cleanupFailure],
250
+ 'Resource operation and cleanup failed',
251
+ );
252
+ }
253
+ throw cleanupFailure;
254
+ }
255
+
256
+ if (operationFailure !== undefined) throw operationFailure;
257
+ if (result === undefined) throw new Error('Resource operation produced no result');
258
+ return result.value;
259
+ }
260
+ ```
261
+
262
+ Use the language’s structured multi-error or error-chaining mechanism where possible.
263
+
264
+ ## 10. Classify failures by structured fields
265
+
266
+ Prefer error types, codes, status values, or discriminated variants over message matching.
267
+
268
+ ```ts
269
+ interface RetryableFailure extends Error {
270
+ readonly code: 'temporarily_unavailable';
271
+ readonly retryAfterSeconds: number;
272
+ }
273
+
274
+ function isRetryableFailure(error: unknown): error is RetryableFailure {
275
+ return error instanceof Error
276
+ && 'code' in error
277
+ && error.code === 'temporarily_unavailable'
278
+ && 'retryAfterSeconds' in error
279
+ && typeof error.retryAfterSeconds === 'number';
280
+ }
281
+ ```
282
+
283
+ Do not treat an unrelated exception containing “busy” or “timeout” as retryable.
284
+
285
+ ## 11. Immutable replay identity
286
+
287
+ Bind every field that changes the meaning of an idempotent operation.
288
+
289
+ ```ts
290
+ interface BoundRequest {
291
+ readonly operation: string;
292
+ readonly subjectId: string;
293
+ readonly expectedRevision: number;
294
+ readonly mode: 'validate' | 'apply';
295
+ }
296
+
297
+ function replayMatches(left: BoundRequest, right: BoundRequest): boolean {
298
+ return left.operation === right.operation
299
+ && left.subjectId === right.subjectId
300
+ && left.expectedRevision === right.expectedRevision
301
+ && left.mode === right.mode;
302
+ }
303
+ ```
304
+
305
+ Reusing an identity with changed bound input is a conflict, not a second mutation.
306
+
307
+ ## 12. Compare-and-swap filesystem changes
308
+
309
+ For managed files, the contract may include expected content, expected file identity, expected parent-directory identity, alternate paths that must remain absent, restrictive mode, reverse-order rollback, and explicit ambiguous-cleanup failure.
310
+
311
+ Use the project’s atomic compare-and-swap helpers where available. Plain write, rename, or delete calls are insufficient when concurrent changes or independently owned files must be protected.
312
+
313
+ ## 13. Test secret non-echo
314
+
315
+ ```ts
316
+ test('rejects invalid input without echoing it', () => {
317
+ const submitted = 'secret-sentinel-value';
318
+
319
+ assert.throws(
320
+ () => parseWindow({ start: submitted, limit: 10 }),
321
+ (error: unknown) => {
322
+ assert.ok(error instanceof Error);
323
+ assert.equal(error.message.includes(submitted), false);
324
+ return true;
325
+ },
326
+ );
327
+ });
328
+ ```
329
+
330
+ ## 14. Test deterministic output
331
+
332
+ For canonical order, hashes, manifests, and rankings, construct semantically equivalent inputs with different insertion order and assert identical output.
333
+
334
+ ## 15. Verification sequence
335
+
336
+ Run commands that actually exist in the repository:
337
+
338
+ 1. the narrowest test covering the changed contract;
339
+ 2. relevant integration tests;
340
+ 3. type or static checks;
341
+ 4. the broader test suite when shared behavior changed;
342
+ 5. build and package checks when distribution changed.
343
+
344
+ Report skipped commands and failures exactly. Do not invent a lint, formatter, build, or test command that the project does not define.