bonecode 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (605) hide show
  1. package/ARCHITECTURE.md +183 -0
  2. package/README.md +71 -0
  3. package/bin/bonecode +62 -0
  4. package/bone/migrations/rag_vectors.sql +258 -0
  5. package/bone/output/agent/.dockerignore +7 -0
  6. package/bone/output/agent/.env.example +36 -0
  7. package/bone/output/agent/.github/workflows/ci.yaml +58 -0
  8. package/bone/output/agent/AgentDomain.bone.map +350 -0
  9. package/bone/output/agent/AgentDomain.postman_collection.json +958 -0
  10. package/bone/output/agent/Dockerfile +22 -0
  11. package/bone/output/agent/README.md +47 -0
  12. package/bone/output/agent/admin/index.html +740 -0
  13. package/bone/output/agent/docker-compose.yaml +22 -0
  14. package/bone/output/agent/k8s/deployment.yaml +75 -0
  15. package/bone/output/agent/migrations/agent.sql +36 -0
  16. package/bone/output/agent/migrations/agent_instance.sql +36 -0
  17. package/bone/output/agent/migrations/audit_log.sql +18 -0
  18. package/bone/output/agent/migrations/build_step.sql +34 -0
  19. package/bone/output/agent/migrations/event_outbox.sql +31 -0
  20. package/bone/output/agent/migrations/plan.sql +30 -0
  21. package/bone/output/agent/migrations/task.sql +30 -0
  22. package/bone/output/agent/migrations/tool_call.sql +33 -0
  23. package/bone/output/agent/openapi.yaml +1116 -0
  24. package/bone/output/agent/package.json +36 -0
  25. package/bone/output/agent/schema.graphql +233 -0
  26. package/bone/output/agent/sdk/client.ts +231 -0
  27. package/bone/output/agent/src/algorithms.ts +2 -0
  28. package/bone/output/agent/src/audit.ts +44 -0
  29. package/bone/output/agent/src/auth.ts +57 -0
  30. package/bone/output/agent/src/cron.ts +12 -0
  31. package/bone/output/agent/src/db.ts +32 -0
  32. package/bone/output/agent/src/debug.ts +66 -0
  33. package/bone/output/agent/src/events.ts +243 -0
  34. package/bone/output/agent/src/extensions.ts +54 -0
  35. package/bone/output/agent/src/failure_rules.ts +323 -0
  36. package/bone/output/agent/src/flows.ts +168 -0
  37. package/bone/output/agent/src/health.ts +43 -0
  38. package/bone/output/agent/src/index.ts +100 -0
  39. package/bone/output/agent/src/logger.ts +66 -0
  40. package/bone/output/agent/src/metrics.ts +75 -0
  41. package/bone/output/agent/src/migrate.ts +352 -0
  42. package/bone/output/agent/src/migration_diff.ts +108 -0
  43. package/bone/output/agent/src/notify.ts +125 -0
  44. package/bone/output/agent/src/routes/agent_instance.ts +234 -0
  45. package/bone/output/agent/src/routes/build_step.ts +105 -0
  46. package/bone/output/agent/src/routes/plan.ts +91 -0
  47. package/bone/output/agent/src/routes/task.ts +105 -0
  48. package/bone/output/agent/src/routes/tool_call.ts +166 -0
  49. package/bone/output/agent/src/schemas.ts +384 -0
  50. package/bone/output/agent/src/state_machines/agent_instance.ts +24 -0
  51. package/bone/output/agent/src/state_machines/build_step.ts +22 -0
  52. package/bone/output/agent/src/state_machines/plan.ts +22 -0
  53. package/bone/output/agent/src/state_machines/task.ts +22 -0
  54. package/bone/output/agent/src/state_machines/tool_call.ts +22 -0
  55. package/bone/output/agent/src/tests.ts +362 -0
  56. package/bone/output/agent/src/websocket.ts +201 -0
  57. package/bone/output/agent/tsconfig.json +25 -0
  58. package/bone/output/rag/.dockerignore +7 -0
  59. package/bone/output/rag/.env.example +36 -0
  60. package/bone/output/rag/.github/workflows/ci.yaml +58 -0
  61. package/bone/output/rag/Dockerfile +22 -0
  62. package/bone/output/rag/RAGDomain.bone.map +287 -0
  63. package/bone/output/rag/RAGDomain.postman_collection.json +923 -0
  64. package/bone/output/rag/README.md +47 -0
  65. package/bone/output/rag/admin/index.html +818 -0
  66. package/bone/output/rag/docker-compose.yaml +22 -0
  67. package/bone/output/rag/k8s/deployment.yaml +75 -0
  68. package/bone/output/rag/migrations/audit_log.sql +18 -0
  69. package/bone/output/rag/migrations/code_chunk.sql +34 -0
  70. package/bone/output/rag/migrations/code_file.sql +33 -0
  71. package/bone/output/rag/migrations/event_outbox.sql +31 -0
  72. package/bone/output/rag/migrations/indexing_job.sql +33 -0
  73. package/bone/output/rag/migrations/knowledge_base.sql +35 -0
  74. package/bone/output/rag/migrations/memory_entry.sql +34 -0
  75. package/bone/output/rag/openapi.yaml +1097 -0
  76. package/bone/output/rag/package.json +36 -0
  77. package/bone/output/rag/schema.graphql +245 -0
  78. package/bone/output/rag/sdk/client.ts +234 -0
  79. package/bone/output/rag/src/algorithms.ts +2 -0
  80. package/bone/output/rag/src/audit.ts +37 -0
  81. package/bone/output/rag/src/auth.ts +57 -0
  82. package/bone/output/rag/src/cron.ts +12 -0
  83. package/bone/output/rag/src/db.ts +32 -0
  84. package/bone/output/rag/src/debug.ts +66 -0
  85. package/bone/output/rag/src/events.ts +243 -0
  86. package/bone/output/rag/src/extensions.ts +350 -0
  87. package/bone/output/rag/src/failure_rules.ts +315 -0
  88. package/bone/output/rag/src/flows.ts +239 -0
  89. package/bone/output/rag/src/health.ts +43 -0
  90. package/bone/output/rag/src/index.ts +95 -0
  91. package/bone/output/rag/src/logger.ts +66 -0
  92. package/bone/output/rag/src/metrics.ts +75 -0
  93. package/bone/output/rag/src/migrate.ts +364 -0
  94. package/bone/output/rag/src/migration_diff.ts +108 -0
  95. package/bone/output/rag/src/notify.ts +99 -0
  96. package/bone/output/rag/src/routes/code_chunk.ts +75 -0
  97. package/bone/output/rag/src/routes/code_file.ts +101 -0
  98. package/bone/output/rag/src/routes/indexing_job.ts +87 -0
  99. package/bone/output/rag/src/routes/knowledge_base.ts +230 -0
  100. package/bone/output/rag/src/routes/memory_entry.ts +87 -0
  101. package/bone/output/rag/src/schemas.ts +394 -0
  102. package/bone/output/rag/src/state_machines/code_file.ts +23 -0
  103. package/bone/output/rag/src/state_machines/indexing_job.ts +22 -0
  104. package/bone/output/rag/src/state_machines/knowledge_base.ts +23 -0
  105. package/bone/output/rag/src/state_machines/memory_entry.ts +20 -0
  106. package/bone/output/rag/src/tests.ts +340 -0
  107. package/bone/output/rag/tsconfig.json +25 -0
  108. package/bone/output/session/.dockerignore +7 -0
  109. package/bone/output/session/.env.example +36 -0
  110. package/bone/output/session/.github/workflows/ci.yaml +58 -0
  111. package/bone/output/session/Dockerfile +22 -0
  112. package/bone/output/session/README.md +47 -0
  113. package/bone/output/session/SessionDomain.bone.map +350 -0
  114. package/bone/output/session/SessionDomain.postman_collection.json +958 -0
  115. package/bone/output/session/admin/index.html +667 -0
  116. package/bone/output/session/docker-compose.yaml +22 -0
  117. package/bone/output/session/k8s/deployment.yaml +75 -0
  118. package/bone/output/session/migrations/audit_log.sql +18 -0
  119. package/bone/output/session/migrations/event_outbox.sql +31 -0
  120. package/bone/output/session/migrations/message.sql +31 -0
  121. package/bone/output/session/migrations/part.sql +28 -0
  122. package/bone/output/session/migrations/permission.sql +28 -0
  123. package/bone/output/session/migrations/project.sql +28 -0
  124. package/bone/output/session/migrations/session.sql +38 -0
  125. package/bone/output/session/openapi.yaml +1101 -0
  126. package/bone/output/session/package.json +36 -0
  127. package/bone/output/session/schema.graphql +222 -0
  128. package/bone/output/session/sdk/client.ts +225 -0
  129. package/bone/output/session/src/algorithms.ts +2 -0
  130. package/bone/output/session/src/audit.ts +44 -0
  131. package/bone/output/session/src/auth.ts +57 -0
  132. package/bone/output/session/src/cron.ts +12 -0
  133. package/bone/output/session/src/db.ts +32 -0
  134. package/bone/output/session/src/debug.ts +66 -0
  135. package/bone/output/session/src/events.ts +270 -0
  136. package/bone/output/session/src/extensions.ts +215 -0
  137. package/bone/output/session/src/failure_rules.ts +284 -0
  138. package/bone/output/session/src/flows.ts +168 -0
  139. package/bone/output/session/src/health.ts +43 -0
  140. package/bone/output/session/src/index.ts +100 -0
  141. package/bone/output/session/src/logger.ts +66 -0
  142. package/bone/output/session/src/metrics.ts +75 -0
  143. package/bone/output/session/src/migrate.ts +332 -0
  144. package/bone/output/session/src/migration_diff.ts +108 -0
  145. package/bone/output/session/src/notify.ts +112 -0
  146. package/bone/output/session/src/routes/message.ts +93 -0
  147. package/bone/output/session/src/routes/part.ts +79 -0
  148. package/bone/output/session/src/routes/permission.ts +79 -0
  149. package/bone/output/session/src/routes/project.ts +79 -0
  150. package/bone/output/session/src/routes/session.ts +294 -0
  151. package/bone/output/session/src/schemas.ts +357 -0
  152. package/bone/output/session/src/state_machines/session.ts +23 -0
  153. package/bone/output/session/src/tests.ts +326 -0
  154. package/bone/output/session/src/websocket.ts +201 -0
  155. package/bone/output/session/tsconfig.json +25 -0
  156. package/bone/output/workspace/.dockerignore +7 -0
  157. package/bone/output/workspace/.env.example +36 -0
  158. package/bone/output/workspace/.github/workflows/ci.yaml +58 -0
  159. package/bone/output/workspace/Dockerfile +22 -0
  160. package/bone/output/workspace/README.md +45 -0
  161. package/bone/output/workspace/WorkspaceDomain.bone.map +189 -0
  162. package/bone/output/workspace/WorkspaceDomain.postman_collection.json +621 -0
  163. package/bone/output/workspace/admin/index.html +485 -0
  164. package/bone/output/workspace/docker-compose.yaml +22 -0
  165. package/bone/output/workspace/k8s/deployment.yaml +75 -0
  166. package/bone/output/workspace/migrations/audit_log.sql +18 -0
  167. package/bone/output/workspace/migrations/codebase.sql +34 -0
  168. package/bone/output/workspace/migrations/event_outbox.sql +31 -0
  169. package/bone/output/workspace/migrations/snapshot.sql +32 -0
  170. package/bone/output/workspace/migrations/workspace.sql +33 -0
  171. package/bone/output/workspace/openapi.yaml +721 -0
  172. package/bone/output/workspace/package.json +36 -0
  173. package/bone/output/workspace/schema.graphql +153 -0
  174. package/bone/output/workspace/sdk/client.ts +155 -0
  175. package/bone/output/workspace/src/algorithms.ts +2 -0
  176. package/bone/output/workspace/src/audit.ts +37 -0
  177. package/bone/output/workspace/src/auth.ts +57 -0
  178. package/bone/output/workspace/src/cron.ts +12 -0
  179. package/bone/output/workspace/src/db.ts +32 -0
  180. package/bone/output/workspace/src/debug.ts +66 -0
  181. package/bone/output/workspace/src/events.ts +243 -0
  182. package/bone/output/workspace/src/extensions.ts +44 -0
  183. package/bone/output/workspace/src/failure_rules.ts +153 -0
  184. package/bone/output/workspace/src/health.ts +43 -0
  185. package/bone/output/workspace/src/index.ts +89 -0
  186. package/bone/output/workspace/src/logger.ts +66 -0
  187. package/bone/output/workspace/src/metrics.ts +75 -0
  188. package/bone/output/workspace/src/migrate.ts +220 -0
  189. package/bone/output/workspace/src/migration_diff.ts +108 -0
  190. package/bone/output/workspace/src/notify.ts +73 -0
  191. package/bone/output/workspace/src/routes/codebase.ts +87 -0
  192. package/bone/output/workspace/src/routes/snapshot.ts +127 -0
  193. package/bone/output/workspace/src/routes/workspace.ts +190 -0
  194. package/bone/output/workspace/src/schemas.ts +231 -0
  195. package/bone/output/workspace/src/state_machines/codebase.ts +21 -0
  196. package/bone/output/workspace/src/state_machines/snapshot.ts +20 -0
  197. package/bone/output/workspace/src/state_machines/workspace.ts +21 -0
  198. package/bone/output/workspace/src/tests.ts +249 -0
  199. package/bone/output/workspace/tsconfig.json +25 -0
  200. package/compat/opencode_adapter.ts +410 -0
  201. package/package.json +69 -0
  202. package/scripts/check_benchmark_session.js +34 -0
  203. package/scripts/check_finish_event.js +24 -0
  204. package/scripts/check_parts.js +15 -0
  205. package/scripts/compile.js +79 -0
  206. package/scripts/copy_opencode.ps1 +53 -0
  207. package/scripts/create_functions.sql +129 -0
  208. package/scripts/migrate.js +85 -0
  209. package/scripts/migrate_from_opencode.ts +218 -0
  210. package/scripts/test_agent_loop.js +101 -0
  211. package/scripts/test_api.ps1 +116 -0
  212. package/scripts/test_context_builder.js +136 -0
  213. package/scripts/test_context_builder.ts +97 -0
  214. package/scripts/test_rag.js +189 -0
  215. package/scripts/test_stream_events.js +36 -0
  216. package/scripts/test_websocket_and_saga.js +216 -0
  217. package/src/cli.ts +475 -0
  218. package/src/config.ts +162 -0
  219. package/src/context_builder.ts +598 -0
  220. package/src/engine/account/account.sql.ts +39 -0
  221. package/src/engine/account/account.ts +456 -0
  222. package/src/engine/account/repo.ts +166 -0
  223. package/src/engine/account/schema.ts +99 -0
  224. package/src/engine/account/url.ts +8 -0
  225. package/src/engine/acp/README.md +174 -0
  226. package/src/engine/acp/agent.ts +1968 -0
  227. package/src/engine/acp/runtime.ts +22 -0
  228. package/src/engine/acp/session.ts +122 -0
  229. package/src/engine/acp/types.ts +24 -0
  230. package/src/engine/agent/agent.ts +463 -0
  231. package/src/engine/agent/generate.txt +75 -0
  232. package/src/engine/agent/prompt/compaction.txt +9 -0
  233. package/src/engine/agent/prompt/explore.txt +18 -0
  234. package/src/engine/agent/prompt/scout.txt +36 -0
  235. package/src/engine/agent/prompt/summary.txt +11 -0
  236. package/src/engine/agent/prompt/title.txt +44 -0
  237. package/src/engine/agent/subagent-permissions.ts +34 -0
  238. package/src/engine/auth/index.ts +96 -0
  239. package/src/engine/background/background/job.ts +200 -0
  240. package/src/engine/background/job.ts +200 -0
  241. package/src/engine/bus/bus-event.ts +45 -0
  242. package/src/engine/bus/global.ts +22 -0
  243. package/src/engine/bus/index.ts +203 -0
  244. package/src/engine/command/command/index.ts +181 -0
  245. package/src/engine/command/command/template/initialize.txt +66 -0
  246. package/src/engine/command/command/template/review.txt +101 -0
  247. package/src/engine/command/index.ts +181 -0
  248. package/src/engine/command/template/initialize.txt +66 -0
  249. package/src/engine/command/template/review.txt +101 -0
  250. package/src/engine/config/agent.ts +172 -0
  251. package/src/engine/config/attachment.ts +25 -0
  252. package/src/engine/config/command.ts +62 -0
  253. package/src/engine/config/config.ts +833 -0
  254. package/src/engine/config/console-state.ts +14 -0
  255. package/src/engine/config/entry-name.ts +16 -0
  256. package/src/engine/config/error.ts +23 -0
  257. package/src/engine/config/formatter.ts +13 -0
  258. package/src/engine/config/layout.ts +6 -0
  259. package/src/engine/config/lsp.ts +43 -0
  260. package/src/engine/config/managed.ts +71 -0
  261. package/src/engine/config/markdown.ts +96 -0
  262. package/src/engine/config/mcp.ts +56 -0
  263. package/src/engine/config/model-id.ts +5 -0
  264. package/src/engine/config/parse.ts +79 -0
  265. package/src/engine/config/paths.ts +45 -0
  266. package/src/engine/config/permission.ts +58 -0
  267. package/src/engine/config/plugin.ts +84 -0
  268. package/src/engine/config/provider.ts +111 -0
  269. package/src/engine/config/reference.ts +23 -0
  270. package/src/engine/config/server.ts +19 -0
  271. package/src/engine/config/skills.ts +14 -0
  272. package/src/engine/config/variable.ts +90 -0
  273. package/src/engine/control-plane/adapters/index.ts +41 -0
  274. package/src/engine/control-plane/adapters/worktree.ts +96 -0
  275. package/src/engine/control-plane/dev/README.md +19 -0
  276. package/src/engine/control-plane/dev/debug-workspace-plugin.ts +73 -0
  277. package/src/engine/control-plane/schema.ts +14 -0
  278. package/src/engine/control-plane/types.ts +59 -0
  279. package/src/engine/control-plane/util.ts +39 -0
  280. package/src/engine/control-plane/workspace-adapter-runtime.ts +51 -0
  281. package/src/engine/control-plane/workspace-context.ts +26 -0
  282. package/src/engine/control-plane/workspace.sql.ts +20 -0
  283. package/src/engine/control-plane/workspace.ts +1072 -0
  284. package/src/engine/data-migration.ts +161 -0
  285. package/src/engine/effect/app-runtime.ts +143 -0
  286. package/src/engine/effect/bootstrap-runtime.ts +29 -0
  287. package/src/engine/effect/bridge.ts +84 -0
  288. package/src/engine/effect/config-service.ts +67 -0
  289. package/src/engine/effect/instance-ref.ts +11 -0
  290. package/src/engine/effect/instance-registry.ts +12 -0
  291. package/src/engine/effect/instance-state.ts +72 -0
  292. package/src/engine/effect/promise.ts +17 -0
  293. package/src/engine/effect/run-service.ts +47 -0
  294. package/src/engine/effect/runner.ts +217 -0
  295. package/src/engine/effect/runtime-flags.ts +74 -0
  296. package/src/engine/effect/service-use.ts +38 -0
  297. package/src/engine/env/index.ts +37 -0
  298. package/src/engine/event-v2-bridge.ts +89 -0
  299. package/src/engine/file/file/ignore.ts +81 -0
  300. package/src/engine/file/file/index.ts +651 -0
  301. package/src/engine/file/file/protected.ts +59 -0
  302. package/src/engine/file/file/ripgrep.ts +481 -0
  303. package/src/engine/file/file/watcher.ts +167 -0
  304. package/src/engine/file/ignore.ts +81 -0
  305. package/src/engine/file/index.ts +651 -0
  306. package/src/engine/file/protected.ts +59 -0
  307. package/src/engine/file/ripgrep.ts +481 -0
  308. package/src/engine/file/watcher.ts +167 -0
  309. package/src/engine/format/format/formatter.ts +404 -0
  310. package/src/engine/format/format/index.ts +209 -0
  311. package/src/engine/format/formatter.ts +404 -0
  312. package/src/engine/format/index.ts +209 -0
  313. package/src/engine/git/git/index.ts +347 -0
  314. package/src/engine/git/index.ts +347 -0
  315. package/src/engine/id/id.ts +80 -0
  316. package/src/engine/ide/index.ts +70 -0
  317. package/src/engine/image/image/image.ts +176 -0
  318. package/src/engine/image/image.ts +176 -0
  319. package/src/engine/index.ts +251 -0
  320. package/src/engine/installation/index.ts +327 -0
  321. package/src/engine/lsp/client.ts +707 -0
  322. package/src/engine/lsp/diagnostic.ts +29 -0
  323. package/src/engine/lsp/language.ts +121 -0
  324. package/src/engine/lsp/launch.ts +21 -0
  325. package/src/engine/lsp/lsp/client.ts +707 -0
  326. package/src/engine/lsp/lsp/diagnostic.ts +29 -0
  327. package/src/engine/lsp/lsp/language.ts +121 -0
  328. package/src/engine/lsp/lsp/launch.ts +21 -0
  329. package/src/engine/lsp/lsp/lsp.ts +507 -0
  330. package/src/engine/lsp/lsp/server.ts +2064 -0
  331. package/src/engine/lsp/lsp.ts +507 -0
  332. package/src/engine/lsp/server.ts +2064 -0
  333. package/src/engine/mcp/auth.ts +146 -0
  334. package/src/engine/mcp/index.ts +958 -0
  335. package/src/engine/mcp/mcp/auth.ts +146 -0
  336. package/src/engine/mcp/mcp/index.ts +958 -0
  337. package/src/engine/mcp/mcp/oauth-callback.ts +232 -0
  338. package/src/engine/mcp/mcp/oauth-provider.ts +214 -0
  339. package/src/engine/mcp/oauth-callback.ts +232 -0
  340. package/src/engine/mcp/oauth-provider.ts +214 -0
  341. package/src/engine/node.ts +6 -0
  342. package/src/engine/patch/index.ts +689 -0
  343. package/src/engine/patch/patch/index.ts +689 -0
  344. package/src/engine/permission/arity.ts +163 -0
  345. package/src/engine/permission/evaluate.ts +15 -0
  346. package/src/engine/permission/index.ts +306 -0
  347. package/src/engine/permission/permission/arity.ts +163 -0
  348. package/src/engine/permission/permission/evaluate.ts +15 -0
  349. package/src/engine/permission/permission/index.ts +306 -0
  350. package/src/engine/permission/permission/schema.ts +13 -0
  351. package/src/engine/permission/schema.ts +13 -0
  352. package/src/engine/plugin/azure.ts +26 -0
  353. package/src/engine/plugin/cloudflare.ts +76 -0
  354. package/src/engine/plugin/codex.ts +622 -0
  355. package/src/engine/plugin/digitalocean.ts +411 -0
  356. package/src/engine/plugin/github-copilot/copilot.ts +394 -0
  357. package/src/engine/plugin/github-copilot/models.ts +196 -0
  358. package/src/engine/plugin/index.ts +295 -0
  359. package/src/engine/plugin/install.ts +439 -0
  360. package/src/engine/plugin/loader.ts +216 -0
  361. package/src/engine/plugin/meta.ts +188 -0
  362. package/src/engine/plugin/shared.ts +323 -0
  363. package/src/engine/project/bootstrap-service.ts +9 -0
  364. package/src/engine/project/bootstrap.ts +75 -0
  365. package/src/engine/project/instance-context.ts +24 -0
  366. package/src/engine/project/instance-layer.ts +11 -0
  367. package/src/engine/project/instance-runtime.ts +16 -0
  368. package/src/engine/project/instance-store.ts +193 -0
  369. package/src/engine/project/project.sql.ts +17 -0
  370. package/src/engine/project/project.ts +537 -0
  371. package/src/engine/project/schema.ts +13 -0
  372. package/src/engine/project/vcs.ts +405 -0
  373. package/src/engine/provider/auth.ts +225 -0
  374. package/src/engine/provider/error.ts +204 -0
  375. package/src/engine/provider/model-status.ts +8 -0
  376. package/src/engine/provider/provider.ts +1843 -0
  377. package/src/engine/provider/schema.ts +30 -0
  378. package/src/engine/provider/sdk/copilot/AGENTS.md +1 -0
  379. package/src/engine/provider/transform.ts +1376 -0
  380. package/src/engine/pty/index.ts +365 -0
  381. package/src/engine/pty/input.ts +24 -0
  382. package/src/engine/pty/pty/index.ts +365 -0
  383. package/src/engine/pty/pty/input.ts +24 -0
  384. package/src/engine/pty/pty/pty.bun.ts +26 -0
  385. package/src/engine/pty/pty/pty.node.ts +27 -0
  386. package/src/engine/pty/pty/pty.ts +25 -0
  387. package/src/engine/pty/pty/schema.ts +14 -0
  388. package/src/engine/pty/pty/ticket.ts +68 -0
  389. package/src/engine/pty/pty.bun.ts +26 -0
  390. package/src/engine/pty/pty.node.ts +27 -0
  391. package/src/engine/pty/pty.ts +25 -0
  392. package/src/engine/pty/schema.ts +14 -0
  393. package/src/engine/pty/ticket.ts +68 -0
  394. package/src/engine/question/index.ts +213 -0
  395. package/src/engine/question/question/index.ts +213 -0
  396. package/src/engine/question/question/schema.ts +10 -0
  397. package/src/engine/question/schema.ts +10 -0
  398. package/src/engine/reference/reference/reference.ts +241 -0
  399. package/src/engine/reference/reference/repository-cache.ts +147 -0
  400. package/src/engine/reference/reference.ts +241 -0
  401. package/src/engine/reference/repository-cache.ts +147 -0
  402. package/src/engine/session/compaction.ts +651 -0
  403. package/src/engine/session/compaction_logic.ts +120 -0
  404. package/src/engine/session/instruction.ts +238 -0
  405. package/src/engine/session/instruction_loader.ts +54 -0
  406. package/src/engine/session/llm.ts +459 -0
  407. package/src/engine/session/message-error.ts +14 -0
  408. package/src/engine/session/message-v2.ts +1202 -0
  409. package/src/engine/session/message.ts +146 -0
  410. package/src/engine/session/overflow.ts +32 -0
  411. package/src/engine/session/overflow_check.ts +46 -0
  412. package/src/engine/session/processor.ts +823 -0
  413. package/src/engine/session/prompt/anthropic.txt +105 -0
  414. package/src/engine/session/prompt/beast.txt +147 -0
  415. package/src/engine/session/prompt/build-switch.txt +5 -0
  416. package/src/engine/session/prompt/codex.txt +79 -0
  417. package/src/engine/session/prompt/copilot-gpt-5.txt +143 -0
  418. package/src/engine/session/prompt/default.txt +105 -0
  419. package/src/engine/session/prompt/gemini.txt +155 -0
  420. package/src/engine/session/prompt/gpt.txt +107 -0
  421. package/src/engine/session/prompt/kimi.txt +95 -0
  422. package/src/engine/session/prompt/max-steps.txt +16 -0
  423. package/src/engine/session/prompt/plan-reminder-anthropic.txt +67 -0
  424. package/src/engine/session/prompt/plan.txt +26 -0
  425. package/src/engine/session/prompt/trinity.txt +97 -0
  426. package/src/engine/session/prompt.ts +671 -0
  427. package/src/engine/session/provider_transform.ts +187 -0
  428. package/src/engine/session/retry.ts +200 -0
  429. package/src/engine/session/retry_logic.ts +65 -0
  430. package/src/engine/session/revert.ts +162 -0
  431. package/src/engine/session/run-state.ts +153 -0
  432. package/src/engine/session/schema.ts +26 -0
  433. package/src/engine/session/session.sql.ts +137 -0
  434. package/src/engine/session/session.ts +1011 -0
  435. package/src/engine/session/status.ts +94 -0
  436. package/src/engine/session/summary.ts +164 -0
  437. package/src/engine/session/system.ts +84 -0
  438. package/src/engine/session/system_prompt.ts +65 -0
  439. package/src/engine/session/todo.ts +81 -0
  440. package/src/engine/session/tool_registry.ts +162 -0
  441. package/src/engine/share/session.ts +61 -0
  442. package/src/engine/share/share-next.ts +376 -0
  443. package/src/engine/share/share.sql.ts +13 -0
  444. package/src/engine/shell/shell/shell.ts +215 -0
  445. package/src/engine/shell/shell.ts +215 -0
  446. package/src/engine/skill/discovery.ts +116 -0
  447. package/src/engine/skill/index.ts +336 -0
  448. package/src/engine/skill/prompt/customize-opencode.md +377 -0
  449. package/src/engine/skill/skill/discovery.ts +116 -0
  450. package/src/engine/skill/skill/index.ts +336 -0
  451. package/src/engine/skill/skill/prompt/customize-opencode.md +377 -0
  452. package/src/engine/snapshot/index.ts +762 -0
  453. package/src/engine/snapshot/snapshot/index.ts +762 -0
  454. package/src/engine/sync/README.md +179 -0
  455. package/src/engine/sync/event.sql.ts +17 -0
  456. package/src/engine/sync/index.ts +410 -0
  457. package/src/engine/sync/schema.ts +11 -0
  458. package/src/engine/temporary.ts +33 -0
  459. package/src/engine/tool/apply_patch.ts +313 -0
  460. package/src/engine/tool/apply_patch.txt +33 -0
  461. package/src/engine/tool/edit.ts +711 -0
  462. package/src/engine/tool/edit.txt +10 -0
  463. package/src/engine/tool/external-directory.ts +49 -0
  464. package/src/engine/tool/glob.ts +103 -0
  465. package/src/engine/tool/glob.txt +6 -0
  466. package/src/engine/tool/grep.ts +156 -0
  467. package/src/engine/tool/grep.txt +8 -0
  468. package/src/engine/tool/invalid.ts +21 -0
  469. package/src/engine/tool/json-schema.ts +164 -0
  470. package/src/engine/tool/lsp.ts +113 -0
  471. package/src/engine/tool/lsp.txt +24 -0
  472. package/src/engine/tool/mcp-websearch.ts +96 -0
  473. package/src/engine/tool/plan-enter.txt +14 -0
  474. package/src/engine/tool/plan-exit.txt +13 -0
  475. package/src/engine/tool/plan.ts +78 -0
  476. package/src/engine/tool/question.ts +44 -0
  477. package/src/engine/tool/question.txt +10 -0
  478. package/src/engine/tool/read.ts +337 -0
  479. package/src/engine/tool/read.txt +14 -0
  480. package/src/engine/tool/registry.ts +472 -0
  481. package/src/engine/tool/repo_clone.ts +80 -0
  482. package/src/engine/tool/repo_clone.txt +5 -0
  483. package/src/engine/tool/repo_overview.ts +279 -0
  484. package/src/engine/tool/repo_overview.txt +4 -0
  485. package/src/engine/tool/schema.ts +14 -0
  486. package/src/engine/tool/shell/id.ts +19 -0
  487. package/src/engine/tool/shell/prompt.ts +295 -0
  488. package/src/engine/tool/shell/shell.txt +77 -0
  489. package/src/engine/tool/shell.ts +647 -0
  490. package/src/engine/tool/skill.ts +75 -0
  491. package/src/engine/tool/skill.txt +5 -0
  492. package/src/engine/tool/task.ts +337 -0
  493. package/src/engine/tool/task.txt +58 -0
  494. package/src/engine/tool/task_status.ts +179 -0
  495. package/src/engine/tool/task_status.txt +13 -0
  496. package/src/engine/tool/todo.ts +57 -0
  497. package/src/engine/tool/todowrite.txt +167 -0
  498. package/src/engine/tool/tool/apply_patch.ts +313 -0
  499. package/src/engine/tool/tool/apply_patch.txt +33 -0
  500. package/src/engine/tool/tool/edit.ts +711 -0
  501. package/src/engine/tool/tool/edit.txt +10 -0
  502. package/src/engine/tool/tool/external-directory.ts +49 -0
  503. package/src/engine/tool/tool/glob.ts +103 -0
  504. package/src/engine/tool/tool/glob.txt +6 -0
  505. package/src/engine/tool/tool/grep.ts +156 -0
  506. package/src/engine/tool/tool/grep.txt +8 -0
  507. package/src/engine/tool/tool/invalid.ts +21 -0
  508. package/src/engine/tool/tool/json-schema.ts +164 -0
  509. package/src/engine/tool/tool/lsp.ts +113 -0
  510. package/src/engine/tool/tool/lsp.txt +24 -0
  511. package/src/engine/tool/tool/mcp-websearch.ts +96 -0
  512. package/src/engine/tool/tool/plan-enter.txt +14 -0
  513. package/src/engine/tool/tool/plan-exit.txt +13 -0
  514. package/src/engine/tool/tool/plan.ts +78 -0
  515. package/src/engine/tool/tool/question.ts +44 -0
  516. package/src/engine/tool/tool/question.txt +10 -0
  517. package/src/engine/tool/tool/read.ts +337 -0
  518. package/src/engine/tool/tool/read.txt +14 -0
  519. package/src/engine/tool/tool/registry.ts +472 -0
  520. package/src/engine/tool/tool/repo_clone.ts +80 -0
  521. package/src/engine/tool/tool/repo_clone.txt +5 -0
  522. package/src/engine/tool/tool/repo_overview.ts +279 -0
  523. package/src/engine/tool/tool/repo_overview.txt +4 -0
  524. package/src/engine/tool/tool/schema.ts +14 -0
  525. package/src/engine/tool/tool/shell/id.ts +19 -0
  526. package/src/engine/tool/tool/shell/prompt.ts +295 -0
  527. package/src/engine/tool/tool/shell/shell.txt +77 -0
  528. package/src/engine/tool/tool/shell.ts +647 -0
  529. package/src/engine/tool/tool/skill.ts +75 -0
  530. package/src/engine/tool/tool/skill.txt +5 -0
  531. package/src/engine/tool/tool/task.ts +337 -0
  532. package/src/engine/tool/tool/task.txt +58 -0
  533. package/src/engine/tool/tool/task_status.ts +179 -0
  534. package/src/engine/tool/tool/task_status.txt +13 -0
  535. package/src/engine/tool/tool/todo.ts +57 -0
  536. package/src/engine/tool/tool/todowrite.txt +167 -0
  537. package/src/engine/tool/tool/tool.ts +164 -0
  538. package/src/engine/tool/tool/truncate.ts +160 -0
  539. package/src/engine/tool/tool/truncation-dir.ts +4 -0
  540. package/src/engine/tool/tool/webfetch.ts +192 -0
  541. package/src/engine/tool/tool/webfetch.txt +13 -0
  542. package/src/engine/tool/tool/websearch.ts +143 -0
  543. package/src/engine/tool/tool/websearch.txt +14 -0
  544. package/src/engine/tool/tool/write.ts +104 -0
  545. package/src/engine/tool/tool/write.txt +8 -0
  546. package/src/engine/tool/tool.ts +164 -0
  547. package/src/engine/tool/truncate.ts +160 -0
  548. package/src/engine/tool/truncation-dir.ts +4 -0
  549. package/src/engine/tool/webfetch.ts +192 -0
  550. package/src/engine/tool/webfetch.txt +13 -0
  551. package/src/engine/tool/websearch.ts +143 -0
  552. package/src/engine/tool/websearch.txt +14 -0
  553. package/src/engine/tool/write.ts +104 -0
  554. package/src/engine/tool/write.txt +8 -0
  555. package/src/engine/util/archive.ts +17 -0
  556. package/src/engine/util/bom.ts +31 -0
  557. package/src/engine/util/data-url.ts +9 -0
  558. package/src/engine/util/defer.ts +10 -0
  559. package/src/engine/util/effect-http-client.ts +11 -0
  560. package/src/engine/util/error.ts +88 -0
  561. package/src/engine/util/filesystem.ts +252 -0
  562. package/src/engine/util/format.ts +20 -0
  563. package/src/engine/util/iife.ts +3 -0
  564. package/src/engine/util/lazy.ts +20 -0
  565. package/src/engine/util/local-context.ts +25 -0
  566. package/src/engine/util/locale.ts +86 -0
  567. package/src/engine/util/media.ts +26 -0
  568. package/src/engine/util/process.ts +176 -0
  569. package/src/engine/util/queue.ts +32 -0
  570. package/src/engine/util/record.ts +3 -0
  571. package/src/engine/util/repository.ts +158 -0
  572. package/src/engine/util/rpc.ts +66 -0
  573. package/src/engine/util/signal.ts +12 -0
  574. package/src/engine/util/timeout.ts +13 -0
  575. package/src/engine/util/token.ts +7 -0
  576. package/src/engine/util/util/archive.ts +17 -0
  577. package/src/engine/util/util/bom.ts +31 -0
  578. package/src/engine/util/util/data-url.ts +9 -0
  579. package/src/engine/util/util/defer.ts +10 -0
  580. package/src/engine/util/util/effect-http-client.ts +11 -0
  581. package/src/engine/util/util/error.ts +88 -0
  582. package/src/engine/util/util/filesystem.ts +252 -0
  583. package/src/engine/util/util/format.ts +20 -0
  584. package/src/engine/util/util/iife.ts +3 -0
  585. package/src/engine/util/util/lazy.ts +20 -0
  586. package/src/engine/util/util/local-context.ts +25 -0
  587. package/src/engine/util/util/locale.ts +86 -0
  588. package/src/engine/util/util/media.ts +26 -0
  589. package/src/engine/util/util/process.ts +176 -0
  590. package/src/engine/util/util/queue.ts +32 -0
  591. package/src/engine/util/util/record.ts +3 -0
  592. package/src/engine/util/util/repository.ts +158 -0
  593. package/src/engine/util/util/rpc.ts +66 -0
  594. package/src/engine/util/util/signal.ts +12 -0
  595. package/src/engine/util/util/timeout.ts +13 -0
  596. package/src/engine/util/util/token.ts +7 -0
  597. package/src/engine/util/util/which.ts +14 -0
  598. package/src/engine/util/util/wildcard.ts +59 -0
  599. package/src/engine/util/which.ts +14 -0
  600. package/src/engine/util/wildcard.ts +59 -0
  601. package/src/engine/worktree/index.ts +621 -0
  602. package/src/rag_worker.ts +519 -0
  603. package/src/server.ts +201 -0
  604. package/src/tui.ts +637 -0
  605. package/tsconfig.json +24 -0
@@ -0,0 +1,183 @@
1
+ # BoneCode Architecture
2
+
3
+ ## Overview
4
+
5
+ BoneCode replaces OpenCode's Bun + Hono + SQLite backend with a BoneScript-generated Node.js + PostgreSQL backend. The declarative `.bone` files are the single source of truth for the domain model. The BoneScript compiler generates all boilerplate: migrations, routes, state machines, event bus, WebSocket channels, OpenAPI spec, and more.
6
+
7
+ ```
8
+ ┌─────────────────────────────────────────────────────────────────────┐
9
+ │ Client Layer │
10
+ │ TUI (Go) Desktop (Electron) VS Code Extension │
11
+ │ │ │ │ │
12
+ │ └──────────────┴──────────────────────┘ │
13
+ │ HTTP + SSE + WebSocket │
14
+ └─────────────────────────────────────────────────────────────────────┘
15
+
16
+ ┌─────────────────────────────────────────────────────────────────────┐
17
+ │ Compatibility Adapter │
18
+ │ compat/opencode_adapter.ts │
19
+ │ Maps OpenCode v2 API → BoneCode domain capabilities │
20
+ └─────────────────────────────────────────────────────────────────────┘
21
+
22
+ ┌─────────────────────────────────────────────────────────────────────┐
23
+ │ BoneScript-Generated Backend │
24
+ │ bone/output/src/ │
25
+ │ │
26
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
27
+ │ │ Session │ │ Agent │ │ RAG │ │
28
+ │ │ Domain │ │ Domain │ │ Domain │ │
29
+ │ │ Routes │ │ Routes │ │ Routes │ │
30
+ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
31
+ │ │ │ │ │
32
+ │ ┌──────▼─────────────────▼──────────────────▼───────┐ │
33
+ │ │ State Machines │ │
34
+ │ │ Session: created→active→busy→compacting→archived │ │
35
+ │ │ Agent: idle→running→waiting_for_tool→done │ │
36
+ │ │ RAG: empty→indexing→ready→stale │ │
37
+ │ └────────────────────────┬──────────────────────────┘ │
38
+ │ │ │
39
+ │ ┌────────────────────────▼──────────────────────────┐ │
40
+ │ │ Durable Event Bus │ │
41
+ │ │ Transactional outbox (Postgres-backed) │ │
42
+ │ │ at_least_once / exactly_once delivery │ │
43
+ │ └────────────────────────┬──────────────────────────┘ │
44
+ │ │ │
45
+ │ ┌────────────────────────▼──────────────────────────┐ │
46
+ │ │ Saga Flows │ │
47
+ │ │ run_agent_turn: start→prompt→tools→persist→notify│ │
48
+ │ │ agent_coding_loop: plan→edit→test→fix→commit │ │
49
+ │ │ ingest_codebase: scan→chunk→embed→finalize │ │
50
+ │ └───────────────────────────────────────────────────┘ │
51
+ └─────────────────────────────────────────────────────────────────────┘
52
+
53
+ ┌─────────────────────────────────────────────────────────────────────┐
54
+ │ Extension Points │
55
+ │ extensions/ (custom TypeScript) │
56
+ │ │
57
+ │ llm_provider.ts → send_prompt_to_llm, cancel_llm_request │
58
+ │ tool_executor.ts → execute_tool_calls, revert_tool_effects │
59
+ │ embedding_provider.ts→ embed_text, embed_batch │
60
+ │ chunker.ts → chunk_file, detect_language │
61
+ │ rag_search.ts → hybrid_search │
62
+ │ snapshot.ts → git_snapshot, git_revert, git_diff │
63
+ │ mcp_bridge.ts → MCP server integration │
64
+ └─────────────────────────────────────────────────────────────────────┘
65
+
66
+ ┌─────────────────────────────────────────────────────────────────────┐
67
+ │ PostgreSQL + pgvector │
68
+ │ │
69
+ │ Core tables (BoneScript-generated): │
70
+ │ projects, sessions, messages, parts, permissions │
71
+ │ agent_instances, tasks, plans, build_steps, tool_calls │
72
+ │ workspaces, codebases, snapshots │
73
+ │ knowledge_bases, code_files, code_chunks, memory_entries │
74
+ │ indexing_jobs │
75
+ │ event_outbox, event_processed (durable events) │
76
+ │ audit_log │
77
+ │ │
78
+ │ RAG extensions (rag_vectors.sql): │
79
+ │ code_chunks.embedding vector(1536) + IVFFlat index │
80
+ │ memory_entries.embedding vector(1536) + IVFFlat index │
81
+ │ bonecode_hybrid_search() stored function (RRF) │
82
+ │ bonecode_memory_search() stored function │
83
+ └─────────────────────────────────────────────────────────────────────┘
84
+ ```
85
+
86
+ ## Domain Model
87
+
88
+ ### Session Domain (`session.bone`)
89
+
90
+ The core conversation primitive. A `Session` belongs to a `Project` and contains an ordered sequence of `Message` objects, each composed of `Part` objects (text, tool_invocation, tool_result, file, reasoning).
91
+
92
+ State machine: `created → active → busy → compacting → archived | deleted`
93
+
94
+ Key capabilities:
95
+ - `create_session` — transactional, emits `SessionCreated`
96
+ - `add_message` — transactional, emits `MessageAdded`
97
+ - `update_part` — realtime (WebSocket broadcast), emits `PartUpdated`
98
+ - `compact_session` — triggers context compaction flow
99
+
100
+ ### Agent Domain (`agent.bone`)
101
+
102
+ Models the full lifecycle of an AI agent working on a coding task.
103
+
104
+ - `AgentInstance` — one per session turn, tracks model/provider/cost/tokens
105
+ - `Task` — a discrete coding objective
106
+ - `Plan` — the agent's step-by-step plan for a task
107
+ - `BuildStep` — a single action (read_file, write_file, run_command, etc.)
108
+ - `ToolCall` — a single tool invocation with input/output/permission
109
+
110
+ State machine (AgentInstance): `idle → running → waiting_for_tool → compacting → done | failed | cancelled`
111
+
112
+ The `agent_coding_loop` saga: `plan → edit → test → fix → commit` with full backward compensation.
113
+
114
+ ### RAG Domain (`rag.bone`)
115
+
116
+ Production-grade pgvector RAG for codebase indexing and long-term agent memory.
117
+
118
+ - `KnowledgeBase` — one per project, configures embedding model and chunking strategy
119
+ - `CodeFile` — a file in the knowledge base, tracks hash for change detection
120
+ - `CodeChunk` — a chunk of code with a `vector(1536)` embedding
121
+ - `MemoryEntry` — long-term agent memory with vector embedding
122
+ - `IndexingJob` — tracks ingestion pipeline progress
123
+
124
+ Hybrid search combines:
125
+ 1. pgvector cosine similarity (semantic)
126
+ 2. PostgreSQL full-text search (keyword)
127
+ 3. Reciprocal Rank Fusion (RRF) to merge results
128
+
129
+ The `bonecode_hybrid_search()` stored function runs both searches in a single SQL query for maximum efficiency.
130
+
131
+ ### Workspace Domain (`workspace.bone`)
132
+
133
+ Manages the filesystem context for agent operations.
134
+
135
+ - `Workspace` — the root directory, git state
136
+ - `Codebase` — language/framework analysis
137
+ - `Snapshot` — git-based undo/revert tracking (separate internal git repo)
138
+
139
+ ## Key Design Decisions
140
+
141
+ ### Why PostgreSQL instead of SQLite?
142
+
143
+ OpenCode uses SQLite for simplicity. BoneCode upgrades to PostgreSQL for:
144
+ - **pgvector**: Native vector similarity search for RAG
145
+ - **Transactional outbox**: Durable event delivery with `FOR UPDATE SKIP LOCKED`
146
+ - **Concurrent access**: Multiple agent instances, multi-user support
147
+ - **Full-text search**: `tsvector`/`tsquery` for hybrid RAG search
148
+ - **Stored functions**: `bonecode_hybrid_search()` runs RRF in a single round-trip
149
+
150
+ ### Why BoneScript?
151
+
152
+ BoneScript generates ~80% of the backend boilerplate from declarative `.bone` files:
153
+ - SQL migrations with proper indexes and triggers
154
+ - Express routes with CRUD + capability endpoints
155
+ - State machine runtimes with transition validation
156
+ - Durable event bus with transactional outbox
157
+ - Saga flows with backward compensation
158
+ - WebSocket channels with causal ordering
159
+ - OpenAPI spec, TypeScript SDK, Zod schemas, Postman collection
160
+ - Docker, K8s, GitHub Actions CI/CD
161
+
162
+ The remaining ~20% is custom TypeScript in `extensions/` — the parts that genuinely require custom logic (LLM calls, tool execution, embedding, chunking, git operations).
163
+
164
+ ### Extension Points
165
+
166
+ BoneScript's `extension_point` declarations create named escape hatches that are preserved across recompilation. This means you can recompile the `.bone` files to pick up schema changes without losing your custom implementations.
167
+
168
+ ### Backward Compatibility
169
+
170
+ The `compat/opencode_adapter.ts` maps the OpenCode v2 HTTP + SSE API to BoneCode's domain capabilities. Existing clients (TUI, Desktop, VS Code) connect to this adapter and receive responses in the exact format they expect. No client changes required.
171
+
172
+ ## Performance Characteristics
173
+
174
+ | Operation | Latency | Notes |
175
+ |---|---|---|
176
+ | Session CRUD | < 5ms | Indexed PK lookups |
177
+ | Message list | < 10ms | Indexed by session_id |
178
+ | Part stream | < 2ms | Realtime WebSocket |
179
+ | Vector search (10K chunks) | < 50ms | IVFFlat approximate NN |
180
+ | Hybrid search (10K chunks) | < 100ms | RRF in single SQL query |
181
+ | Memory recall | < 30ms | IVFFlat + FTS |
182
+ | Tool execution | varies | Depends on tool |
183
+ | LLM streaming | varies | Depends on provider |
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # BoneCode
2
+
3
+ **BoneCode** is a production-grade fork of [OpenCode](https://github.com/sst/opencode) — an open-source AI coding agent.
4
+
5
+ The core backend has been redesigned using [BoneScript](../BoneScript%20example/) as the declarative backbone, replacing the original Bun + Hono + SQLite stack with a BoneScript-generated Node.js + PostgreSQL backend featuring:
6
+
7
+ - **Declarative domain models** for all agent/session/RAG entities
8
+ - **State machines** for session and agent lifecycles
9
+ - **Saga flows** with compensation for complex agent workflows
10
+ - **Durable events** with transactional outbox for long-running tasks
11
+ - **Realtime WebSocket channels** with causal ordering for live session updates
12
+ - **Production-grade pgvector RAG** for codebase indexing and long-term agent memory
13
+ - **Full backward compatibility** with existing TUI (Go), Desktop (Electron), and VS Code clients
14
+
15
+ ## Quick Start
16
+
17
+ ```bash
18
+ # 1. Compile the BoneScript domain models
19
+ cd bone
20
+ npx bonec compile bonecode.bone --target express
21
+
22
+ # 2. Start dependencies
23
+ cd bone/output
24
+ docker compose up -d
25
+
26
+ # 3. Install and migrate
27
+ npm install
28
+ npm run migrate
29
+
30
+ # 4. Start the server
31
+ npm run dev
32
+ ```
33
+
34
+ The server exposes the same HTTP + WebSocket API as OpenCode, so all existing clients work without changes.
35
+
36
+ ## Architecture
37
+
38
+ See [ARCHITECTURE.md](./ARCHITECTURE.md) for the full design.
39
+ See [MIGRATION.md](./MIGRATION.md) for the migration guide from OpenCode.
40
+
41
+ ## Folder Structure
42
+
43
+ ```
44
+ BoneCode/
45
+ ├── bone/ # BoneScript source files (the declarative backbone)
46
+ │ ├── bonecode.bone # Main system definition (imports all modules)
47
+ │ ├── session.bone # Session, Message, Part, Project entities
48
+ │ ├── agent.bone # AgentInstance, Task, Plan, BuildStep, ToolCall
49
+ │ ├── rag.bone # RAG: KnowledgeBase, CodeFile, CodeChunk (pgvector)
50
+ │ ├── workspace.bone # Workspace, Codebase, Snapshot entities
51
+ │ └── output/ # BoneScript compiler output (generated, do not edit)
52
+ │ ├── src/
53
+ │ ├── migrations/
54
+ │ ├── openapi.yaml
55
+ │ └── ...
56
+ ├── extensions/ # Custom TypeScript extension points
57
+ │ ├── llm_provider.ts # LLM provider integration (Anthropic, OpenAI, etc.)
58
+ │ ├── tool_executor.ts # Tool execution (bash, read, write, edit, grep)
59
+ │ ├── mcp_bridge.ts # MCP server bridge
60
+ │ ├── embedding_provider.ts # Embedding provider (OpenAI, Ollama, Voyage)
61
+ │ ├── chunker.ts # Code chunking logic
62
+ │ └── snapshot.ts # Git-based snapshot/revert
63
+ ├── compat/ # Compatibility layer for existing clients
64
+ │ └── opencode_adapter.ts # Maps OpenCode v2 API → BoneCode API
65
+ ├── clients/ # Unchanged client packages (TUI, Desktop, VS Code)
66
+ │ ├── tui/ # Go TUI (unchanged)
67
+ │ ├── desktop/ # Electron desktop (unchanged)
68
+ │ └── vscode/ # VS Code extension (unchanged)
69
+ ├── ARCHITECTURE.md
70
+ └── MIGRATION.md
71
+ ```
package/bin/bonecode ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+ // BoneCode CLI entry point
3
+ // Resolves and runs the CLI via ts-node (dev) or compiled JS (prod).
4
+
5
+ const path = require("path");
6
+ const { spawnSync } = require("child_process");
7
+ const fs = require("fs");
8
+ const os = require("os");
9
+
10
+ const isWindows = os.platform() === "win32";
11
+
12
+ // Resolve the package root (two levels up from bin/)
13
+ const scriptPath = fs.realpathSync(__filename);
14
+ const pkgRoot = path.dirname(path.dirname(scriptPath));
15
+
16
+ const cliJs = path.join(pkgRoot, "dist", "src", "cli.js");
17
+ const cliTs = path.join(pkgRoot, "src", "cli.ts");
18
+
19
+ function findTsNode() {
20
+ // Try local node_modules first
21
+ const local = path.join(pkgRoot, "node_modules", ".bin", isWindows ? "ts-node.cmd" : "ts-node");
22
+ if (fs.existsSync(local)) return local;
23
+ // Fall back to global ts-node
24
+ return isWindows ? "ts-node.cmd" : "ts-node";
25
+ }
26
+
27
+ function run(cmd, args) {
28
+ const result = spawnSync(cmd, args, {
29
+ stdio: "inherit",
30
+ cwd: process.cwd(),
31
+ env: process.env,
32
+ shell: false,
33
+ });
34
+
35
+ if (result.error) {
36
+ // If the command failed (e.g. .cmd not found), try with shell: true
37
+ const result2 = spawnSync(cmd, args, {
38
+ stdio: "inherit",
39
+ cwd: process.cwd(),
40
+ env: process.env,
41
+ shell: true,
42
+ });
43
+ process.exit(result2.status ?? 0);
44
+ return;
45
+ }
46
+
47
+ process.exit(result.status ?? 0);
48
+ }
49
+
50
+ if (fs.existsSync(cliJs)) {
51
+ // Production: use compiled JS
52
+ run(process.execPath, [cliJs, ...process.argv.slice(2)]);
53
+ } else if (fs.existsSync(cliTs)) {
54
+ // Development: use ts-node
55
+ const tsNode = findTsNode();
56
+ const tsconfig = path.join(pkgRoot, "tsconfig.json");
57
+ run(tsNode, ["--project", tsconfig, cliTs, ...process.argv.slice(2)]);
58
+ } else {
59
+ console.error("BoneCode: could not find CLI entry point.");
60
+ console.error(" Run `npm run build` to compile, or ensure ts-node is installed.");
61
+ process.exit(1);
62
+ }
@@ -0,0 +1,258 @@
1
+ -- BoneCode: RAG Vector Extension Migration
2
+ -- Run AFTER the BoneScript-generated migrations.
3
+ -- Adds pgvector columns and indexes to code_chunks and memory_entrys.
4
+ --
5
+ -- Prerequisites:
6
+ -- CREATE EXTENSION IF NOT EXISTS vector;
7
+ -- (Requires pgvector: https://github.com/pgvector/pgvector)
8
+
9
+ -- ─── Enable pgvector ──────────────────────────────────────────────────────────
10
+
11
+ CREATE EXTENSION IF NOT EXISTS vector;
12
+
13
+ -- ─── code_chunks: Add embedding column ───────────────────────────────────────
14
+
15
+ ALTER TABLE code_chunks
16
+ ADD COLUMN IF NOT EXISTS embedding vector(768);
17
+
18
+ -- IVFFlat index for approximate nearest neighbor search
19
+ -- lists = 100 is a good default for up to ~1M vectors
20
+ -- For larger datasets, increase lists (sqrt(n) is a common heuristic)
21
+ CREATE INDEX IF NOT EXISTS idx_code_chunks_embedding
22
+ ON code_chunks
23
+ USING ivfflat (embedding vector_cosine_ops)
24
+ WITH (lists = 100);
25
+
26
+ -- Full-text search index on content
27
+ CREATE INDEX IF NOT EXISTS idx_code_chunks_fts
28
+ ON code_chunks
29
+ USING gin (to_tsvector('english', content));
30
+
31
+ -- Composite index for filtered vector search
32
+ CREATE INDEX IF NOT EXISTS idx_code_chunks_kb_lang
33
+ ON code_chunks (knowledge_base_id, language, symbol_type);
34
+
35
+ -- ─── memory_entrys: Add embedding column ────────────────────────────────────
36
+
37
+ ALTER TABLE memory_entrys
38
+ ADD COLUMN IF NOT EXISTS embedding vector(768);
39
+
40
+ CREATE INDEX IF NOT EXISTS idx_memory_entrys_embedding
41
+ ON memory_entrys
42
+ USING ivfflat (embedding vector_cosine_ops)
43
+ WITH (lists = 50);
44
+
45
+ -- Full-text search on memory content
46
+ CREATE INDEX IF NOT EXISTS idx_memory_entrys_fts
47
+ ON memory_entrys
48
+ USING gin (to_tsvector('english', content));
49
+
50
+ -- Composite index for filtered memory search
51
+ CREATE INDEX IF NOT EXISTS idx_memory_entrys_session_type
52
+ ON memory_entrys (session_id, project_id, memory_type, importance DESC);
53
+
54
+ -- ─── Hybrid Search Function ───────────────────────────────────────────────────
55
+ -- A stored procedure for efficient hybrid search combining vector + FTS.
56
+ -- Called by the hybrid_search extension point.
57
+
58
+ CREATE OR REPLACE FUNCTION bonecode_hybrid_search(
59
+ p_knowledge_base_id UUID,
60
+ p_query_embedding vector(768),
61
+ p_query_text TEXT,
62
+ p_language TEXT DEFAULT NULL,
63
+ p_symbol_type TEXT DEFAULT NULL,
64
+ p_limit INT DEFAULT 20
65
+ )
66
+ RETURNS TABLE (
67
+ chunk_id UUID,
68
+ code_file_id UUID,
69
+ file_path TEXT,
70
+ content TEXT,
71
+ start_line BIGINT,
72
+ end_line BIGINT,
73
+ language TEXT,
74
+ symbol_name TEXT,
75
+ symbol_type TEXT,
76
+ vector_score FLOAT,
77
+ text_score FLOAT,
78
+ rrf_score FLOAT
79
+ )
80
+ LANGUAGE SQL STABLE
81
+ AS $$
82
+ WITH
83
+ -- Vector similarity search (top 2x limit for RRF)
84
+ vector_results AS (
85
+ SELECT
86
+ cc.id AS chunk_id,
87
+ cc.code_file_id,
88
+ cf.file_path,
89
+ cc.content,
90
+ cc.start_line,
91
+ cc.end_line,
92
+ cc.language,
93
+ cc.symbol_name,
94
+ cc.symbol_type,
95
+ 1 - (cc.embedding <=> p_query_embedding) AS vector_score,
96
+ ROW_NUMBER() OVER (ORDER BY cc.embedding <=> p_query_embedding) AS vector_rank
97
+ FROM code_chunks cc
98
+ JOIN code_files cf ON cf.id = cc.code_file_id
99
+ WHERE cc.knowledge_base_id = p_knowledge_base_id
100
+ AND cc.embedding IS NOT NULL
101
+ AND (p_language IS NULL OR cc.language = p_language)
102
+ AND (p_symbol_type IS NULL OR cc.symbol_type = p_symbol_type)
103
+ ORDER BY cc.embedding <=> p_query_embedding
104
+ LIMIT p_limit * 2
105
+ ),
106
+ -- Full-text search (top 2x limit for RRF)
107
+ text_results AS (
108
+ SELECT
109
+ cc.id AS chunk_id,
110
+ cc.code_file_id,
111
+ cf.file_path,
112
+ cc.content,
113
+ cc.start_line,
114
+ cc.end_line,
115
+ cc.language,
116
+ cc.symbol_name,
117
+ cc.symbol_type,
118
+ ts_rank(
119
+ to_tsvector('english', cc.content),
120
+ plainto_tsquery('english', p_query_text)
121
+ ) AS text_score,
122
+ ROW_NUMBER() OVER (
123
+ ORDER BY ts_rank(
124
+ to_tsvector('english', cc.content),
125
+ plainto_tsquery('english', p_query_text)
126
+ ) DESC
127
+ ) AS text_rank
128
+ FROM code_chunks cc
129
+ JOIN code_files cf ON cf.id = cc.code_file_id
130
+ WHERE cc.knowledge_base_id = p_knowledge_base_id
131
+ AND to_tsvector('english', cc.content) @@ plainto_tsquery('english', p_query_text)
132
+ AND (p_language IS NULL OR cc.language = p_language)
133
+ AND (p_symbol_type IS NULL OR cc.symbol_type = p_symbol_type)
134
+ ORDER BY text_score DESC
135
+ LIMIT p_limit * 2
136
+ ),
137
+ -- Reciprocal Rank Fusion (k=60)
138
+ rrf AS (
139
+ SELECT
140
+ COALESCE(v.chunk_id, t.chunk_id) AS chunk_id,
141
+ COALESCE(v.code_file_id, t.code_file_id) AS code_file_id,
142
+ COALESCE(v.file_path, t.file_path) AS file_path,
143
+ COALESCE(v.content, t.content) AS content,
144
+ COALESCE(v.start_line, t.start_line) AS start_line,
145
+ COALESCE(v.end_line, t.end_line) AS end_line,
146
+ COALESCE(v.language, t.language) AS language,
147
+ COALESCE(v.symbol_name, t.symbol_name) AS symbol_name,
148
+ COALESCE(v.symbol_type, t.symbol_type) AS symbol_type,
149
+ COALESCE(v.vector_score, 0) AS vector_score,
150
+ COALESCE(t.text_score, 0) AS text_score,
151
+ COALESCE(1.0 / (60 + v.vector_rank), 0)
152
+ + COALESCE(1.0 / (60 + t.text_rank), 0) AS rrf_score
153
+ FROM vector_results v
154
+ FULL OUTER JOIN text_results t ON t.chunk_id = v.chunk_id
155
+ )
156
+ SELECT
157
+ chunk_id, code_file_id, file_path, content,
158
+ start_line, end_line, language, symbol_name, symbol_type,
159
+ vector_score, text_score, rrf_score
160
+ FROM rrf
161
+ ORDER BY rrf_score DESC
162
+ LIMIT p_limit;
163
+ $$;
164
+
165
+ -- ─── Memory Search Function ───────────────────────────────────────────────────
166
+
167
+ CREATE OR REPLACE FUNCTION bonecode_memory_search(
168
+ p_session_id UUID,
169
+ p_project_id UUID,
170
+ p_query_embedding vector(768),
171
+ p_query_text TEXT,
172
+ p_memory_type TEXT DEFAULT NULL,
173
+ p_limit INT DEFAULT 10
174
+ )
175
+ RETURNS TABLE (
176
+ memory_id UUID,
177
+ memory_type TEXT,
178
+ content TEXT,
179
+ importance FLOAT,
180
+ access_count BIGINT,
181
+ vector_score FLOAT,
182
+ rrf_score FLOAT
183
+ )
184
+ LANGUAGE SQL STABLE
185
+ AS $$
186
+ WITH
187
+ vector_results AS (
188
+ SELECT
189
+ me.id AS memory_id,
190
+ me.memory_type,
191
+ me.content,
192
+ me.importance,
193
+ me.access_count,
194
+ 1 - (me.embedding <=> p_query_embedding) AS vector_score,
195
+ ROW_NUMBER() OVER (ORDER BY me.embedding <=> p_query_embedding) AS vector_rank
196
+ FROM memory_entrys me
197
+ WHERE (me.session_id = p_session_id OR me.project_id = p_project_id)
198
+ AND me.state = 'active'
199
+ AND me.embedding IS NOT NULL
200
+ AND (p_memory_type IS NULL OR me.memory_type = p_memory_type)
201
+ ORDER BY me.embedding <=> p_query_embedding
202
+ LIMIT p_limit * 2
203
+ ),
204
+ text_results AS (
205
+ SELECT
206
+ me.id AS memory_id,
207
+ me.memory_type,
208
+ me.content,
209
+ me.importance,
210
+ me.access_count,
211
+ ts_rank(
212
+ to_tsvector('english', me.content),
213
+ plainto_tsquery('english', p_query_text)
214
+ ) AS text_score,
215
+ ROW_NUMBER() OVER (
216
+ ORDER BY ts_rank(
217
+ to_tsvector('english', me.content),
218
+ plainto_tsquery('english', p_query_text)
219
+ ) DESC
220
+ ) AS text_rank
221
+ FROM memory_entrys me
222
+ WHERE (me.session_id = p_session_id OR me.project_id = p_project_id)
223
+ AND me.state = 'active'
224
+ AND to_tsvector('english', me.content) @@ plainto_tsquery('english', p_query_text)
225
+ AND (p_memory_type IS NULL OR me.memory_type = p_memory_type)
226
+ ORDER BY text_score DESC
227
+ LIMIT p_limit * 2
228
+ ),
229
+ rrf AS (
230
+ SELECT
231
+ COALESCE(v.memory_id, t.memory_id) AS memory_id,
232
+ COALESCE(v.memory_type, t.memory_type) AS memory_type,
233
+ COALESCE(v.content, t.content) AS content,
234
+ COALESCE(v.importance, t.importance) AS importance,
235
+ COALESCE(v.access_count, t.access_count) AS access_count,
236
+ COALESCE(v.vector_score, 0) AS vector_score,
237
+ COALESCE(1.0 / (60 + v.vector_rank), 0)
238
+ + COALESCE(1.0 / (60 + t.text_rank), 0) AS rrf_score
239
+ FROM vector_results v
240
+ FULL OUTER JOIN text_results t ON t.memory_id = v.memory_id
241
+ )
242
+ SELECT memory_id, memory_type, content, importance, access_count, vector_score, rrf_score
243
+ FROM rrf
244
+ ORDER BY rrf_score DESC, importance DESC
245
+ LIMIT p_limit;
246
+ $$;
247
+
248
+ -- ─── Auto-update access_count on memory recall ────────────────────────────────
249
+
250
+ CREATE OR REPLACE FUNCTION bonecode_record_memory_access(p_memory_id UUID)
251
+ RETURNS VOID
252
+ LANGUAGE SQL
253
+ AS $$
254
+ UPDATE memory_entrys
255
+ SET access_count = access_count + 1,
256
+ last_accessed_at = NOW()
257
+ WHERE id = p_memory_id;
258
+ $$;
@@ -0,0 +1,7 @@
1
+ node_modules
2
+ dist
3
+ .env
4
+ *.log
5
+ .git
6
+ *.bone
7
+ *.bone.map
@@ -0,0 +1,36 @@
1
+ # AgentDomain Environment Variables
2
+ # Copy this file to .env and fill in real values. Never commit .env to source control.
3
+
4
+ # --- Required in production ---
5
+ # Generate with: node -e "console.log(require('crypto').randomBytes(48).toString('hex'))"
6
+ JWT_SECRET=
7
+
8
+ # --- Database ---
9
+ DATABASE_URL=postgresql://postgres:postgres@localhost:5432/agent_domain
10
+
11
+ # --- Redis (optional, used by some domain templates) ---
12
+ REDIS_URL=redis://localhost:6379
13
+
14
+ # --- Server ---
15
+ PORT=3000
16
+ NODE_ENV=development
17
+
18
+ # --- CORS ---
19
+ # Comma-separated list of allowed origins. Leave empty to disallow all cross-origin requests.
20
+ # Example: ALLOWED_ORIGINS=https://app.example.com,https://admin.example.com
21
+ ALLOWED_ORIGINS=
22
+
23
+ # --- Event delivery mode ---
24
+ # in_process: in-memory, fast, no durability guarantees (default for development)
25
+ # durable: Postgres-backed transactional outbox (recommended for production)
26
+ EVENT_MODE=in_process
27
+ EVENT_WORKER_INTERVAL_MS=1000
28
+
29
+ # --- Request timeout ---
30
+ REQUEST_TIMEOUT_MS=30000
31
+
32
+ # --- Notifications ---
33
+ # NOTIFY_PROVIDER=log|resend|sendgrid (default: log)
34
+ NOTIFY_PROVIDER=log
35
+ NOTIFY_API_KEY=
36
+ NOTIFY_FROM_EMAIL=noreply@example.com
@@ -0,0 +1,58 @@
1
+ # Generated by BoneScript compiler.
2
+ name: CI/CD
3
+
4
+ on:
5
+ push:
6
+ branches: [main]
7
+ pull_request:
8
+ branches: [main]
9
+
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-latest
13
+ services:
14
+ postgres:
15
+ image: postgres:16
16
+ env:
17
+ POSTGRES_DB: agent_domain_test
18
+ POSTGRES_USER: postgres
19
+ POSTGRES_PASSWORD: postgres
20
+ ports:
21
+ - 5432:5432
22
+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
23
+
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+ - uses: actions/setup-node@v4
27
+ with:
28
+ node-version: 20
29
+ cache: npm
30
+
31
+ - name: Install dependencies
32
+ run: npm ci
33
+
34
+ - name: Type check
35
+ run: npx tsc --noEmit
36
+
37
+ - name: Run migrations
38
+ run: npm run migrate
39
+ env:
40
+ DATABASE_URL: postgresql://postgres:postgres@localhost:5432/agent_domain_test
41
+
42
+ - name: Run tests
43
+ run: npx ts-node src/tests.ts
44
+ env:
45
+ DATABASE_URL: postgresql://postgres:postgres@localhost:5432/agent_domain_test
46
+ JWT_SECRET: test-secret
47
+ TEST_BASE_URL: http://localhost:3000
48
+
49
+ build:
50
+ needs: test
51
+ runs-on: ubuntu-latest
52
+ if: github.ref == 'refs/heads/main'
53
+ steps:
54
+ - uses: actions/checkout@v4
55
+ - name: Build Docker image
56
+ run: docker build -t agent-domain:${{ github.sha }} .
57
+ - name: Tag as latest
58
+ run: docker tag agent-domain:${{ github.sha }} agent-domain:latest