@jait/gateway 0.1.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 (474) hide show
  1. package/bin/jait.mjs +144 -0
  2. package/dist/config.d.ts +24 -0
  3. package/dist/config.d.ts.map +1 -0
  4. package/dist/config.js +73 -0
  5. package/dist/config.js.map +1 -0
  6. package/dist/db/connection.d.ts +37 -0
  7. package/dist/db/connection.d.ts.map +1 -0
  8. package/dist/db/connection.js +85 -0
  9. package/dist/db/connection.js.map +1 -0
  10. package/dist/db/index.d.ts +4 -0
  11. package/dist/db/index.d.ts.map +1 -0
  12. package/dist/db/index.js +4 -0
  13. package/dist/db/index.js.map +1 -0
  14. package/dist/db/migrations.d.ts +24 -0
  15. package/dist/db/migrations.d.ts.map +1 -0
  16. package/dist/db/migrations.js +312 -0
  17. package/dist/db/migrations.js.map +1 -0
  18. package/dist/db/schema.d.ts +2253 -0
  19. package/dist/db/schema.d.ts.map +1 -0
  20. package/dist/db/schema.js +195 -0
  21. package/dist/db/schema.js.map +1 -0
  22. package/dist/foundation.d.ts +26 -0
  23. package/dist/foundation.d.ts.map +1 -0
  24. package/dist/foundation.js +15 -0
  25. package/dist/foundation.js.map +1 -0
  26. package/dist/index.d.ts +3 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +413 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/lib/uuidv7.d.ts +10 -0
  31. package/dist/lib/uuidv7.d.ts.map +1 -0
  32. package/dist/lib/uuidv7.js +33 -0
  33. package/dist/lib/uuidv7.js.map +1 -0
  34. package/dist/memory/contracts.d.ts +42 -0
  35. package/dist/memory/contracts.d.ts.map +1 -0
  36. package/dist/memory/contracts.js +2 -0
  37. package/dist/memory/contracts.js.map +1 -0
  38. package/dist/memory/embeddings.d.ts +4 -0
  39. package/dist/memory/embeddings.d.ts.map +1 -0
  40. package/dist/memory/embeddings.js +26 -0
  41. package/dist/memory/embeddings.js.map +1 -0
  42. package/dist/memory/service.d.ts +17 -0
  43. package/dist/memory/service.d.ts.map +1 -0
  44. package/dist/memory/service.js +82 -0
  45. package/dist/memory/service.js.map +1 -0
  46. package/dist/memory/sqlite-backend.d.ts +11 -0
  47. package/dist/memory/sqlite-backend.d.ts.map +1 -0
  48. package/dist/memory/sqlite-backend.js +68 -0
  49. package/dist/memory/sqlite-backend.js.map +1 -0
  50. package/dist/plugins/contracts.d.ts +11 -0
  51. package/dist/plugins/contracts.d.ts.map +1 -0
  52. package/dist/plugins/contracts.js +2 -0
  53. package/dist/plugins/contracts.js.map +1 -0
  54. package/dist/providers/claude-code-provider.d.ts +39 -0
  55. package/dist/providers/claude-code-provider.d.ts.map +1 -0
  56. package/dist/providers/claude-code-provider.js +322 -0
  57. package/dist/providers/claude-code-provider.js.map +1 -0
  58. package/dist/providers/codex-provider.d.ts +51 -0
  59. package/dist/providers/codex-provider.d.ts.map +1 -0
  60. package/dist/providers/codex-provider.js +826 -0
  61. package/dist/providers/codex-provider.js.map +1 -0
  62. package/dist/providers/contracts.d.ts +167 -0
  63. package/dist/providers/contracts.d.ts.map +1 -0
  64. package/dist/providers/contracts.js +13 -0
  65. package/dist/providers/contracts.js.map +1 -0
  66. package/dist/providers/index.d.ts +6 -0
  67. package/dist/providers/index.d.ts.map +1 -0
  68. package/dist/providers/index.js +5 -0
  69. package/dist/providers/index.js.map +1 -0
  70. package/dist/providers/jait-provider.d.ts +23 -0
  71. package/dist/providers/jait-provider.d.ts.map +1 -0
  72. package/dist/providers/jait-provider.js +67 -0
  73. package/dist/providers/jait-provider.js.map +1 -0
  74. package/dist/providers/registry.d.ts +39 -0
  75. package/dist/providers/registry.d.ts.map +1 -0
  76. package/dist/providers/registry.js +64 -0
  77. package/dist/providers/registry.js.map +1 -0
  78. package/dist/pty-broker-client.d.ts +46 -0
  79. package/dist/pty-broker-client.d.ts.map +1 -0
  80. package/dist/pty-broker-client.js +142 -0
  81. package/dist/pty-broker-client.js.map +1 -0
  82. package/dist/routes/auth.d.ts +6 -0
  83. package/dist/routes/auth.d.ts.map +1 -0
  84. package/dist/routes/auth.js +236 -0
  85. package/dist/routes/auth.js.map +1 -0
  86. package/dist/routes/chat.d.ts +32 -0
  87. package/dist/routes/chat.d.ts.map +1 -0
  88. package/dist/routes/chat.js +1503 -0
  89. package/dist/routes/chat.js.map +1 -0
  90. package/dist/routes/consent.d.ts +10 -0
  91. package/dist/routes/consent.d.ts.map +1 -0
  92. package/dist/routes/consent.js +127 -0
  93. package/dist/routes/consent.js.map +1 -0
  94. package/dist/routes/filesystem.d.ts +14 -0
  95. package/dist/routes/filesystem.d.ts.map +1 -0
  96. package/dist/routes/filesystem.js +152 -0
  97. package/dist/routes/filesystem.js.map +1 -0
  98. package/dist/routes/git.d.ts +17 -0
  99. package/dist/routes/git.d.ts.map +1 -0
  100. package/dist/routes/git.js +213 -0
  101. package/dist/routes/git.js.map +1 -0
  102. package/dist/routes/health.d.ts +7 -0
  103. package/dist/routes/health.d.ts.map +1 -0
  104. package/dist/routes/health.js +21 -0
  105. package/dist/routes/health.js.map +1 -0
  106. package/dist/routes/hooks.d.ts +9 -0
  107. package/dist/routes/hooks.d.ts.map +1 -0
  108. package/dist/routes/hooks.js +22 -0
  109. package/dist/routes/hooks.js.map +1 -0
  110. package/dist/routes/jobs.d.ts +5 -0
  111. package/dist/routes/jobs.d.ts.map +1 -0
  112. package/dist/routes/jobs.js +333 -0
  113. package/dist/routes/jobs.js.map +1 -0
  114. package/dist/routes/mcp-server.d.ts +23 -0
  115. package/dist/routes/mcp-server.d.ts.map +1 -0
  116. package/dist/routes/mcp-server.js +177 -0
  117. package/dist/routes/mcp-server.js.map +1 -0
  118. package/dist/routes/mobile.d.ts +12 -0
  119. package/dist/routes/mobile.d.ts.map +1 -0
  120. package/dist/routes/mobile.js +64 -0
  121. package/dist/routes/mobile.js.map +1 -0
  122. package/dist/routes/network.d.ts +3 -0
  123. package/dist/routes/network.d.ts.map +1 -0
  124. package/dist/routes/network.js +367 -0
  125. package/dist/routes/network.js.map +1 -0
  126. package/dist/routes/repositories.d.ts +18 -0
  127. package/dist/routes/repositories.d.ts.map +1 -0
  128. package/dist/routes/repositories.js +90 -0
  129. package/dist/routes/repositories.js.map +1 -0
  130. package/dist/routes/screen-share.d.ts +17 -0
  131. package/dist/routes/screen-share.d.ts.map +1 -0
  132. package/dist/routes/screen-share.js +92 -0
  133. package/dist/routes/screen-share.js.map +1 -0
  134. package/dist/routes/sessions.d.ts +18 -0
  135. package/dist/routes/sessions.d.ts.map +1 -0
  136. package/dist/routes/sessions.js +169 -0
  137. package/dist/routes/sessions.js.map +1 -0
  138. package/dist/routes/terminals.d.ts +15 -0
  139. package/dist/routes/terminals.d.ts.map +1 -0
  140. package/dist/routes/terminals.js +326 -0
  141. package/dist/routes/terminals.js.map +1 -0
  142. package/dist/routes/threads.d.ts +38 -0
  143. package/dist/routes/threads.d.ts.map +1 -0
  144. package/dist/routes/threads.js +488 -0
  145. package/dist/routes/threads.js.map +1 -0
  146. package/dist/routes/trust.d.ts +9 -0
  147. package/dist/routes/trust.d.ts.map +1 -0
  148. package/dist/routes/trust.js +25 -0
  149. package/dist/routes/trust.js.map +1 -0
  150. package/dist/routes/voice.d.ts +5 -0
  151. package/dist/routes/voice.d.ts.map +1 -0
  152. package/dist/routes/voice.js +37 -0
  153. package/dist/routes/voice.js.map +1 -0
  154. package/dist/routes/workspace.d.ts +13 -0
  155. package/dist/routes/workspace.d.ts.map +1 -0
  156. package/dist/routes/workspace.js +275 -0
  157. package/dist/routes/workspace.js.map +1 -0
  158. package/dist/scheduler/contracts.d.ts +15 -0
  159. package/dist/scheduler/contracts.d.ts.map +1 -0
  160. package/dist/scheduler/contracts.js +2 -0
  161. package/dist/scheduler/contracts.js.map +1 -0
  162. package/dist/scheduler/hooks.d.ts +20 -0
  163. package/dist/scheduler/hooks.d.ts.map +1 -0
  164. package/dist/scheduler/hooks.js +78 -0
  165. package/dist/scheduler/hooks.js.map +1 -0
  166. package/dist/scheduler/service.d.ts +65 -0
  167. package/dist/scheduler/service.d.ts.map +1 -0
  168. package/dist/scheduler/service.js +188 -0
  169. package/dist/scheduler/service.js.map +1 -0
  170. package/dist/security/consent-executor.d.ts +48 -0
  171. package/dist/security/consent-executor.d.ts.map +1 -0
  172. package/dist/security/consent-executor.js +158 -0
  173. package/dist/security/consent-executor.js.map +1 -0
  174. package/dist/security/consent-manager.d.ts +105 -0
  175. package/dist/security/consent-manager.d.ts.map +1 -0
  176. package/dist/security/consent-manager.js +227 -0
  177. package/dist/security/consent-manager.js.map +1 -0
  178. package/dist/security/contracts.d.ts +31 -0
  179. package/dist/security/contracts.d.ts.map +1 -0
  180. package/dist/security/contracts.js +2 -0
  181. package/dist/security/contracts.js.map +1 -0
  182. package/dist/security/http-auth.d.ts +10 -0
  183. package/dist/security/http-auth.d.ts.map +1 -0
  184. package/dist/security/http-auth.js +48 -0
  185. package/dist/security/http-auth.js.map +1 -0
  186. package/dist/security/index.d.ts +10 -0
  187. package/dist/security/index.d.ts.map +1 -0
  188. package/dist/security/index.js +9 -0
  189. package/dist/security/index.js.map +1 -0
  190. package/dist/security/path-guard.d.ts +40 -0
  191. package/dist/security/path-guard.d.ts.map +1 -0
  192. package/dist/security/path-guard.js +125 -0
  193. package/dist/security/path-guard.js.map +1 -0
  194. package/dist/security/sandbox-manager.d.ts +43 -0
  195. package/dist/security/sandbox-manager.d.ts.map +1 -0
  196. package/dist/security/sandbox-manager.js +110 -0
  197. package/dist/security/sandbox-manager.js.map +1 -0
  198. package/dist/security/ssrf-guard.d.ts +11 -0
  199. package/dist/security/ssrf-guard.d.ts.map +1 -0
  200. package/dist/security/ssrf-guard.js +59 -0
  201. package/dist/security/ssrf-guard.js.map +1 -0
  202. package/dist/security/tool-permissions.d.ts +61 -0
  203. package/dist/security/tool-permissions.d.ts.map +1 -0
  204. package/dist/security/tool-permissions.js +105 -0
  205. package/dist/security/tool-permissions.js.map +1 -0
  206. package/dist/security/tool-profiles.d.ts +23 -0
  207. package/dist/security/tool-profiles.d.ts.map +1 -0
  208. package/dist/security/tool-profiles.js +106 -0
  209. package/dist/security/tool-profiles.js.map +1 -0
  210. package/dist/security/trust-engine.d.ts +61 -0
  211. package/dist/security/trust-engine.d.ts.map +1 -0
  212. package/dist/security/trust-engine.js +192 -0
  213. package/dist/security/trust-engine.js.map +1 -0
  214. package/dist/server.d.ts +54 -0
  215. package/dist/server.d.ts.map +1 -0
  216. package/dist/server.js +188 -0
  217. package/dist/server.js.map +1 -0
  218. package/dist/services/audit.d.ts +60 -0
  219. package/dist/services/audit.d.ts.map +1 -0
  220. package/dist/services/audit.js +58 -0
  221. package/dist/services/audit.js.map +1 -0
  222. package/dist/services/device-registry.d.ts +15 -0
  223. package/dist/services/device-registry.d.ts.map +1 -0
  224. package/dist/services/device-registry.js +32 -0
  225. package/dist/services/device-registry.js.map +1 -0
  226. package/dist/services/git.d.ts +168 -0
  227. package/dist/services/git.d.ts.map +1 -0
  228. package/dist/services/git.js +957 -0
  229. package/dist/services/git.js.map +1 -0
  230. package/dist/services/repositories.d.ts +32 -0
  231. package/dist/services/repositories.d.ts.map +1 -0
  232. package/dist/services/repositories.js +70 -0
  233. package/dist/services/repositories.js.map +1 -0
  234. package/dist/services/session-state.d.ts +20 -0
  235. package/dist/services/session-state.d.ts.map +1 -0
  236. package/dist/services/session-state.js +89 -0
  237. package/dist/services/session-state.js.map +1 -0
  238. package/dist/services/sessions.d.ts +68 -0
  239. package/dist/services/sessions.d.ts.map +1 -0
  240. package/dist/services/sessions.js +136 -0
  241. package/dist/services/sessions.js.map +1 -0
  242. package/dist/services/thread-title.d.ts +23 -0
  243. package/dist/services/thread-title.d.ts.map +1 -0
  244. package/dist/services/thread-title.js +141 -0
  245. package/dist/services/thread-title.js.map +1 -0
  246. package/dist/services/threads.d.ts +64 -0
  247. package/dist/services/threads.d.ts.map +1 -0
  248. package/dist/services/threads.js +202 -0
  249. package/dist/services/threads.js.map +1 -0
  250. package/dist/services/users.d.ts +39 -0
  251. package/dist/services/users.d.ts.map +1 -0
  252. package/dist/services/users.js +203 -0
  253. package/dist/services/users.js.map +1 -0
  254. package/dist/sessions/contracts.d.ts +14 -0
  255. package/dist/sessions/contracts.d.ts.map +1 -0
  256. package/dist/sessions/contracts.js +2 -0
  257. package/dist/sessions/contracts.js.map +1 -0
  258. package/dist/surfaces/browser.d.ts +65 -0
  259. package/dist/surfaces/browser.d.ts.map +1 -0
  260. package/dist/surfaces/browser.js +615 -0
  261. package/dist/surfaces/browser.js.map +1 -0
  262. package/dist/surfaces/contracts.d.ts +34 -0
  263. package/dist/surfaces/contracts.d.ts.map +1 -0
  264. package/dist/surfaces/contracts.js +2 -0
  265. package/dist/surfaces/contracts.js.map +1 -0
  266. package/dist/surfaces/filesystem.d.ts +76 -0
  267. package/dist/surfaces/filesystem.d.ts.map +1 -0
  268. package/dist/surfaces/filesystem.js +245 -0
  269. package/dist/surfaces/filesystem.js.map +1 -0
  270. package/dist/surfaces/index.d.ts +6 -0
  271. package/dist/surfaces/index.d.ts.map +1 -0
  272. package/dist/surfaces/index.js +5 -0
  273. package/dist/surfaces/index.js.map +1 -0
  274. package/dist/surfaces/registry.d.ts +24 -0
  275. package/dist/surfaces/registry.d.ts.map +1 -0
  276. package/dist/surfaces/registry.js +59 -0
  277. package/dist/surfaces/registry.js.map +1 -0
  278. package/dist/surfaces/terminal.d.ts +76 -0
  279. package/dist/surfaces/terminal.d.ts.map +1 -0
  280. package/dist/surfaces/terminal.js +271 -0
  281. package/dist/surfaces/terminal.js.map +1 -0
  282. package/dist/tools/agent-loop.d.ts +302 -0
  283. package/dist/tools/agent-loop.d.ts.map +1 -0
  284. package/dist/tools/agent-loop.js +918 -0
  285. package/dist/tools/agent-loop.js.map +1 -0
  286. package/dist/tools/agent-tools.d.ts +39 -0
  287. package/dist/tools/agent-tools.d.ts.map +1 -0
  288. package/dist/tools/agent-tools.js +263 -0
  289. package/dist/tools/agent-tools.js.map +1 -0
  290. package/dist/tools/browser-tools.d.ts +38 -0
  291. package/dist/tools/browser-tools.d.ts.map +1 -0
  292. package/dist/tools/browser-tools.js +725 -0
  293. package/dist/tools/browser-tools.js.map +1 -0
  294. package/dist/tools/chat-modes.d.ts +75 -0
  295. package/dist/tools/chat-modes.d.ts.map +1 -0
  296. package/dist/tools/chat-modes.js +228 -0
  297. package/dist/tools/chat-modes.js.map +1 -0
  298. package/dist/tools/contracts.d.ts +69 -0
  299. package/dist/tools/contracts.d.ts.map +1 -0
  300. package/dist/tools/contracts.js +2 -0
  301. package/dist/tools/contracts.js.map +1 -0
  302. package/dist/tools/core/agent.d.ts +31 -0
  303. package/dist/tools/core/agent.d.ts.map +1 -0
  304. package/dist/tools/core/agent.js +65 -0
  305. package/dist/tools/core/agent.js.map +1 -0
  306. package/dist/tools/core/edit.d.ts +30 -0
  307. package/dist/tools/core/edit.d.ts.map +1 -0
  308. package/dist/tools/core/edit.js +109 -0
  309. package/dist/tools/core/edit.js.map +1 -0
  310. package/dist/tools/core/execute.d.ts +36 -0
  311. package/dist/tools/core/execute.d.ts.map +1 -0
  312. package/dist/tools/core/execute.js +81 -0
  313. package/dist/tools/core/execute.js.map +1 -0
  314. package/dist/tools/core/get-fs.d.ts +32 -0
  315. package/dist/tools/core/get-fs.d.ts.map +1 -0
  316. package/dist/tools/core/get-fs.js +143 -0
  317. package/dist/tools/core/get-fs.js.map +1 -0
  318. package/dist/tools/core/index.d.ts +26 -0
  319. package/dist/tools/core/index.d.ts.map +1 -0
  320. package/dist/tools/core/index.js +26 -0
  321. package/dist/tools/core/index.js.map +1 -0
  322. package/dist/tools/core/jait.d.ts +60 -0
  323. package/dist/tools/core/jait.d.ts.map +1 -0
  324. package/dist/tools/core/jait.js +256 -0
  325. package/dist/tools/core/jait.js.map +1 -0
  326. package/dist/tools/core/read.d.ts +26 -0
  327. package/dist/tools/core/read.d.ts.map +1 -0
  328. package/dist/tools/core/read.js +118 -0
  329. package/dist/tools/core/read.js.map +1 -0
  330. package/dist/tools/core/search.d.ts +34 -0
  331. package/dist/tools/core/search.d.ts.map +1 -0
  332. package/dist/tools/core/search.js +187 -0
  333. package/dist/tools/core/search.js.map +1 -0
  334. package/dist/tools/core/todo.d.ts +38 -0
  335. package/dist/tools/core/todo.d.ts.map +1 -0
  336. package/dist/tools/core/todo.js +116 -0
  337. package/dist/tools/core/todo.js.map +1 -0
  338. package/dist/tools/core/web.d.ts +34 -0
  339. package/dist/tools/core/web.d.ts.map +1 -0
  340. package/dist/tools/core/web.js +120 -0
  341. package/dist/tools/core/web.js.map +1 -0
  342. package/dist/tools/cron-tools.d.ts +7 -0
  343. package/dist/tools/cron-tools.d.ts.map +1 -0
  344. package/dist/tools/cron-tools.js +116 -0
  345. package/dist/tools/cron-tools.js.map +1 -0
  346. package/dist/tools/file-tools.d.ts +32 -0
  347. package/dist/tools/file-tools.d.ts.map +1 -0
  348. package/dist/tools/file-tools.js +178 -0
  349. package/dist/tools/file-tools.js.map +1 -0
  350. package/dist/tools/gateway-tools.d.ts +15 -0
  351. package/dist/tools/gateway-tools.d.ts.map +1 -0
  352. package/dist/tools/gateway-tools.js +39 -0
  353. package/dist/tools/gateway-tools.js.map +1 -0
  354. package/dist/tools/index.d.ts +57 -0
  355. package/dist/tools/index.d.ts.map +1 -0
  356. package/dist/tools/index.js +170 -0
  357. package/dist/tools/index.js.map +1 -0
  358. package/dist/tools/mcp-bridge.d.ts +111 -0
  359. package/dist/tools/mcp-bridge.d.ts.map +1 -0
  360. package/dist/tools/mcp-bridge.js +166 -0
  361. package/dist/tools/mcp-bridge.js.map +1 -0
  362. package/dist/tools/memory-tools.d.ts +19 -0
  363. package/dist/tools/memory-tools.d.ts.map +1 -0
  364. package/dist/tools/memory-tools.js +78 -0
  365. package/dist/tools/memory-tools.js.map +1 -0
  366. package/dist/tools/meta-tools.d.ts +25 -0
  367. package/dist/tools/meta-tools.d.ts.map +1 -0
  368. package/dist/tools/meta-tools.js +125 -0
  369. package/dist/tools/meta-tools.js.map +1 -0
  370. package/dist/tools/network-tools.d.ts +21 -0
  371. package/dist/tools/network-tools.d.ts.map +1 -0
  372. package/dist/tools/network-tools.js +189 -0
  373. package/dist/tools/network-tools.js.map +1 -0
  374. package/dist/tools/os-tools.d.ts +18 -0
  375. package/dist/tools/os-tools.d.ts.map +1 -0
  376. package/dist/tools/os-tools.js +210 -0
  377. package/dist/tools/os-tools.js.map +1 -0
  378. package/dist/tools/prompts/claude-prompt.d.ts +8 -0
  379. package/dist/tools/prompts/claude-prompt.d.ts.map +1 -0
  380. package/dist/tools/prompts/claude-prompt.js +228 -0
  381. package/dist/tools/prompts/claude-prompt.js.map +1 -0
  382. package/dist/tools/prompts/default-openai-prompt.d.ts +8 -0
  383. package/dist/tools/prompts/default-openai-prompt.d.ts.map +1 -0
  384. package/dist/tools/prompts/default-openai-prompt.js +67 -0
  385. package/dist/tools/prompts/default-openai-prompt.js.map +1 -0
  386. package/dist/tools/prompts/default-prompt.d.ts +7 -0
  387. package/dist/tools/prompts/default-prompt.d.ts.map +1 -0
  388. package/dist/tools/prompts/default-prompt.js +50 -0
  389. package/dist/tools/prompts/default-prompt.js.map +1 -0
  390. package/dist/tools/prompts/gemini-prompt.d.ts +8 -0
  391. package/dist/tools/prompts/gemini-prompt.d.ts.map +1 -0
  392. package/dist/tools/prompts/gemini-prompt.js +118 -0
  393. package/dist/tools/prompts/gemini-prompt.js.map +1 -0
  394. package/dist/tools/prompts/gpt5-codex-prompt.d.ts +8 -0
  395. package/dist/tools/prompts/gpt5-codex-prompt.d.ts.map +1 -0
  396. package/dist/tools/prompts/gpt5-codex-prompt.js +72 -0
  397. package/dist/tools/prompts/gpt5-codex-prompt.js.map +1 -0
  398. package/dist/tools/prompts/gpt5-prompt.d.ts +8 -0
  399. package/dist/tools/prompts/gpt5-prompt.d.ts.map +1 -0
  400. package/dist/tools/prompts/gpt5-prompt.js +177 -0
  401. package/dist/tools/prompts/gpt5-prompt.js.map +1 -0
  402. package/dist/tools/prompts/gpt51-prompt.d.ts +8 -0
  403. package/dist/tools/prompts/gpt51-prompt.d.ts.map +1 -0
  404. package/dist/tools/prompts/gpt51-prompt.js +178 -0
  405. package/dist/tools/prompts/gpt51-prompt.js.map +1 -0
  406. package/dist/tools/prompts/gpt52-prompt.d.ts +8 -0
  407. package/dist/tools/prompts/gpt52-prompt.d.ts.map +1 -0
  408. package/dist/tools/prompts/gpt52-prompt.js +198 -0
  409. package/dist/tools/prompts/gpt52-prompt.js.map +1 -0
  410. package/dist/tools/prompts/index.d.ts +22 -0
  411. package/dist/tools/prompts/index.d.ts.map +1 -0
  412. package/dist/tools/prompts/index.js +23 -0
  413. package/dist/tools/prompts/index.js.map +1 -0
  414. package/dist/tools/prompts/prompt-registry.d.ts +44 -0
  415. package/dist/tools/prompts/prompt-registry.d.ts.map +1 -0
  416. package/dist/tools/prompts/prompt-registry.js +60 -0
  417. package/dist/tools/prompts/prompt-registry.js.map +1 -0
  418. package/dist/tools/prompts/shared-sections.d.ts +28 -0
  419. package/dist/tools/prompts/shared-sections.d.ts.map +1 -0
  420. package/dist/tools/prompts/shared-sections.js +111 -0
  421. package/dist/tools/prompts/shared-sections.js.map +1 -0
  422. package/dist/tools/prompts/xai-prompt.d.ts +8 -0
  423. package/dist/tools/prompts/xai-prompt.d.ts.map +1 -0
  424. package/dist/tools/prompts/xai-prompt.js +68 -0
  425. package/dist/tools/prompts/xai-prompt.js.map +1 -0
  426. package/dist/tools/redeploy-tools.d.ts +30 -0
  427. package/dist/tools/redeploy-tools.d.ts.map +1 -0
  428. package/dist/tools/redeploy-tools.js +191 -0
  429. package/dist/tools/redeploy-tools.js.map +1 -0
  430. package/dist/tools/registry.d.ts +51 -0
  431. package/dist/tools/registry.d.ts.map +1 -0
  432. package/dist/tools/registry.js +148 -0
  433. package/dist/tools/registry.js.map +1 -0
  434. package/dist/tools/screen-share-tools.d.ts +31 -0
  435. package/dist/tools/screen-share-tools.d.ts.map +1 -0
  436. package/dist/tools/screen-share-tools.js +183 -0
  437. package/dist/tools/screen-share-tools.js.map +1 -0
  438. package/dist/tools/surface-tools.d.ts +23 -0
  439. package/dist/tools/surface-tools.d.ts.map +1 -0
  440. package/dist/tools/surface-tools.js +99 -0
  441. package/dist/tools/surface-tools.js.map +1 -0
  442. package/dist/tools/terminal-tools.d.ts +37 -0
  443. package/dist/tools/terminal-tools.d.ts.map +1 -0
  444. package/dist/tools/terminal-tools.js +448 -0
  445. package/dist/tools/terminal-tools.js.map +1 -0
  446. package/dist/tools/thread-tools.d.ts +61 -0
  447. package/dist/tools/thread-tools.d.ts.map +1 -0
  448. package/dist/tools/thread-tools.js +484 -0
  449. package/dist/tools/thread-tools.js.map +1 -0
  450. package/dist/tools/token-estimator.d.ts +55 -0
  451. package/dist/tools/token-estimator.d.ts.map +1 -0
  452. package/dist/tools/token-estimator.js +82 -0
  453. package/dist/tools/token-estimator.js.map +1 -0
  454. package/dist/tools/tool-names.d.ts +64 -0
  455. package/dist/tools/tool-names.d.ts.map +1 -0
  456. package/dist/tools/tool-names.js +76 -0
  457. package/dist/tools/tool-names.js.map +1 -0
  458. package/dist/tools/validate.d.ts +27 -0
  459. package/dist/tools/validate.d.ts.map +1 -0
  460. package/dist/tools/validate.js +99 -0
  461. package/dist/tools/validate.js.map +1 -0
  462. package/dist/tools/voice-tools.d.ts +8 -0
  463. package/dist/tools/voice-tools.d.ts.map +1 -0
  464. package/dist/tools/voice-tools.js +32 -0
  465. package/dist/tools/voice-tools.js.map +1 -0
  466. package/dist/voice/service.d.ts +42 -0
  467. package/dist/voice/service.d.ts.map +1 -0
  468. package/dist/voice/service.js +75 -0
  469. package/dist/voice/service.js.map +1 -0
  470. package/dist/ws.d.ts +90 -0
  471. package/dist/ws.d.ts.map +1 -0
  472. package/dist/ws.js +562 -0
  473. package/dist/ws.js.map +1 -0
  474. package/package.json +61 -0
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Shared prompt sections used by all or most model-specific prompts.
3
+ *
4
+ * Adapted from VS Code Copilot Chat — tool names replaced with Jait
5
+ * equivalents, VS Code–specific features (notebooks, devcontainers,
6
+ * file-linkification) removed.
7
+ */
8
+ // ── Jait tool references ─────────────────────────────────────────────
9
+ export const JAIT_TOOLS = {
10
+ read: "read",
11
+ edit: "edit",
12
+ execute: "execute",
13
+ search: "search",
14
+ web: "web",
15
+ agent: "agent",
16
+ todo: "todo",
17
+ jait: "jait",
18
+ };
19
+ // ── Reusable instruction blocks ──────────────────────────────────────
20
+ export const CORE_INSTRUCTIONS = `You are a highly sophisticated automated coding agent with expert-level knowledge across many different programming languages and frameworks and software engineering tasks — this encompasses debugging issues, implementing new features, restructuring code, and providing code explanations, among other engineering activities.
21
+ The user will ask a question, or ask you to perform a task, and it may require lots of research to answer correctly. There is a selection of tools that let you perform actions or retrieve helpful context to answer the user's question.
22
+ By default, implement changes rather than only suggesting them. If the user's intent is unclear, infer the most useful likely action and proceed with using tools to discover any missing details instead of guessing. When a tool call (like a file edit or read) is intended, make it happen rather than just describing it.
23
+ You can call tools repeatedly to take actions or gather as much context as needed until you have completed the task fully. Don't give up unless you are sure the request cannot be fulfilled with the tools you have. It's YOUR RESPONSIBILITY to make sure that you have done all you can to collect necessary context.
24
+ Continue working until the user's request is completely resolved before ending your turn and yielding back to the user. Only terminate your turn when you are certain the task is complete. Do not stop or hand back to the user when you encounter uncertainty — research or deduce the most reasonable approach and continue.`;
25
+ export const TOOL_USE_INSTRUCTIONS = `If the user is requesting a code sample, you can answer it directly without using any tools.
26
+ When using a tool, follow the JSON schema very carefully and make sure to include ALL required properties.
27
+ No need to ask permission before using a tool.
28
+ NEVER say the name of a tool to a user. For example, instead of saying that you'll use the execute tool, say "I'll run the command in a terminal".
29
+ If you think running multiple tools can answer the user's question, prefer calling them in parallel whenever possible.
30
+ When using the read tool, prefer reading a large section over calling the read tool many times in sequence. You can also think of all the pieces you may be interested in and read them in parallel. Read large enough context to ensure you get what you need.
31
+ Don't call the execute tool multiple times in parallel. Instead, run one command and wait for the output before running the next command.
32
+ When creating files, be intentional and avoid unnecessary file creation. Only create files that are essential to completing the user's request.
33
+ NEVER try to edit a file by running terminal commands unless the user specifically asks for it.`;
34
+ export const EDITING_INSTRUCTIONS = `Before you edit an existing file, make sure you have read it first so that you can make proper changes.
35
+ Use the edit tool to modify files precisely. Pay attention to surrounding context to ensure your changes are correct.
36
+ When editing files, group your changes by file.
37
+ NEVER show the changes to the user in a codeblock when you can use the edit tool instead.
38
+ For each file, give a short description of what needs to be changed, then use the edit tool.`;
39
+ export const SEARCH_INSTRUCTIONS = `For codebase exploration, prefer the agent tool to search and gather data across files.
40
+ When using the search tool, prefer searching for specific patterns or identifiers.
41
+ If you don't know exactly what you're looking for, use broader search terms and refine.`;
42
+ export const TODO_INSTRUCTIONS = `You have access to the todo tool which tracks steps and progress. Using it helps demonstrate that you've understood the task and convey how you're approaching it.
43
+
44
+ Break complex work into logical, actionable steps that can be tracked and verified. Update task status consistently:
45
+ - Mark tasks as in-progress when you begin working on them
46
+ - Mark tasks as completed immediately after finishing each one — do not batch completions
47
+
48
+ Task tracking is valuable for:
49
+ - Multi-step work requiring careful sequencing
50
+ - Breaking down ambiguous or complex requests
51
+ - Maintaining checkpoints for feedback and validation
52
+ - When users provide multiple requests or numbered tasks
53
+
54
+ Skip task tracking for simple, single-step operations that can be completed directly without additional planning.`;
55
+ export const PLANNING_EXAMPLES = `### Examples
56
+
57
+ **High-quality plans**
58
+
59
+ Example 1:
60
+ 1. Add CLI entry with file args
61
+ 2. Parse Markdown via CommonMark library
62
+ 3. Apply semantic HTML template
63
+ 4. Handle code blocks, images, links
64
+ 5. Add error handling for invalid files
65
+
66
+ Example 2:
67
+ 1. Define CSS variables for colors
68
+ 2. Add toggle with localStorage state
69
+ 3. Refactor components to use variables
70
+ 4. Verify all views for readability
71
+ 5. Add smooth theme-change transition
72
+
73
+ Example 3:
74
+ 1. Set up Node.js + WebSocket server
75
+ 2. Add join/leave broadcast events
76
+ 3. Implement messaging with timestamps
77
+ 4. Add usernames + mention highlighting
78
+ 5. Persist messages in lightweight DB
79
+ 6. Add typing indicators + unread count
80
+
81
+ **Low-quality plans**
82
+
83
+ Example 1:
84
+ 1. Create CLI tool
85
+ 2. Add Markdown parser
86
+ 3. Convert to HTML
87
+
88
+ Example 2:
89
+ 1. Add dark mode toggle
90
+ 2. Save preference
91
+ 3. Make styles look good
92
+
93
+ If you need to write a plan, only write high quality plans, not low quality ones.`;
94
+ // ── Mode-specific preamble helpers ───────────────────────────────────
95
+ export function getAskModeInstructions() {
96
+ return `You are in ASK mode. The user is asking a question and expects an answer — not code changes. Respond with helpful, accurate information. You may read files and search the codebase for context, but do NOT make any file modifications or run any destructive commands.`;
97
+ }
98
+ export function getPlanModeInstructions() {
99
+ return `You are in PLAN mode. The user wants you to create a plan without implementing it. Analyze the request, explore the codebase as needed, and produce a clear, structured plan. Do NOT make any file changes — only describe what should be done.`;
100
+ }
101
+ export function getModeInstructions(mode) {
102
+ switch (mode) {
103
+ case "ask":
104
+ return getAskModeInstructions();
105
+ case "plan":
106
+ return getPlanModeInstructions();
107
+ default:
108
+ return "";
109
+ }
110
+ }
111
+ //# sourceMappingURL=shared-sections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-sections.js","sourceRoot":"","sources":["../../../src/tools/prompts/shared-sections.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,wEAAwE;AAExE,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX,wEAAwE;AAExE,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;gUAI+R,CAAC;AAEjU,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;gGAQ2D,CAAC;AAEjG,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;6FAIyD,CAAC;AAE9F,MAAM,CAAC,MAAM,mBAAmB,GAAG;;wFAEqD,CAAC;AAEzF,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;kHAYiF,CAAC;AAEnH,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kFAsCiD,CAAC;AAEnF,wEAAwE;AAExE,MAAM,UAAU,sBAAsB;IACpC,OAAO,0QAA0Q,CAAC;AACpR,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,OAAO,iPAAiP,CAAC;AAC3P,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAc;IAChD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,KAAK;YACR,OAAO,sBAAsB,EAAE,CAAC;QAClC,KAAK,MAAM;YACT,OAAO,uBAAuB,EAAE,CAAC;QACnC;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * xAI / Grok prompt — validation-heavy, deliverables focus, security awareness.
3
+ *
4
+ * Adapted from VS Code Copilot Chat's XAIPromptResolver.
5
+ * Prefixes: ['grok-code', 'grok'].
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=xai-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xai-prompt.d.ts","sourceRoot":"","sources":["../../../src/tools/prompts/xai-prompt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * xAI / Grok prompt — validation-heavy, deliverables focus, security awareness.
3
+ *
4
+ * Adapted from VS Code Copilot Chat's XAIPromptResolver.
5
+ * Prefixes: ['grok-code', 'grok'].
6
+ */
7
+ import { promptRegistry } from "./prompt-registry.js";
8
+ import { TOOL_USE_INSTRUCTIONS, EDITING_INSTRUCTIONS, SEARCH_INSTRUCTIONS, TODO_INSTRUCTIONS, getModeInstructions, } from "./shared-sections.js";
9
+ // ── System prompt ────────────────────────────────────────────────────
10
+ function resolveSystemPrompt(mode, _endpoint) {
11
+ const modeBlock = getModeInstructions(mode);
12
+ return `<instructions>
13
+ You are a highly sophisticated automated coding agent with expert-level knowledge across many different programming languages and frameworks.
14
+ The user will ask a question, or ask you to perform a task, and it may require lots of research to answer correctly. There is a selection of tools that let you perform actions or retrieve helpful context to answer the user's question.
15
+ Your main goal is to complete the user's request, denoted within the <user_query> tag.
16
+ You will be given some context and attachments along with the user prompt. You can use them if they are relevant to the task, and ignore them if not.
17
+ If you can infer the project type (languages, frameworks, and libraries) from the user's query or the context that you have, make sure to keep them in mind when making changes.
18
+ If the user wants you to implement a feature and they have not specified the files to edit, first break down the user's request into smaller concepts and think about the kinds of files you need to grasp each concept.
19
+ If you aren't sure which tool is relevant, you can call multiple tools. You can call tools repeatedly to take actions or gather as much context as needed until you have completed the task fully. Don't give up unless you are sure the request cannot be fulfilled with the tools you have. It's YOUR RESPONSIBILITY to make sure that you have done all you can to collect necessary context.
20
+ When reading files, prefer reading large meaningful chunks rather than consecutive small sections to minimize tool calls and gain better context.
21
+ Don't make assumptions about the situation — gather context first, then perform the task or answer the question.
22
+
23
+ Validation and green-before-done: After any substantive change, run the relevant build/tests/linters automatically. For runnable code that you created or edited, immediately run a test to validate the code works (fast, minimal input) yourself. Prefer automated code-based tests where possible. Then provide optional fenced code blocks with commands for larger or platform-specific runs. Don't end a turn with a broken build if you can fix it. If failures occur, iterate up to three targeted fixes; if still failing, summarize the root cause, options, and exact failing output. For non-critical checks (e.g., a flaky health check), retry briefly (2-3 attempts with short backoff) and then proceed.
24
+
25
+ Never invent file paths, APIs, or commands. Verify with tools (search/read/list) before acting when uncertain.
26
+ Security and side-effects: Do not exfiltrate secrets or make network calls unless explicitly required by the task. Prefer local actions first.
27
+ Reproducibility and dependencies: Follow the project's package manager and configuration; prefer minimal, pinned, widely-used libraries and update manifests or lockfiles appropriately. Prefer adding or updating tests when you change public behavior.
28
+ Build characterization: Before stating that a project "has no build" or requires a specific build step, verify by checking the provided context or quickly looking for common build config files (package.json, requirements.txt, Makefile, Dockerfile, etc.). If uncertain, say what you know and proceed with minimal setup instructions.
29
+ Deliverables for non-trivial code generation: Produce a complete, runnable solution, not just a snippet. Create the necessary source files plus a small runner or test/benchmark harness when relevant, a minimal README.md with usage and troubleshooting, and a dependency manifest updated or added as appropriate.
30
+
31
+ Think creatively and explore the workspace in order to make a complete fix.
32
+ Don't repeat yourself after a tool call, pick up where you left off.
33
+ NEVER print out a codeblock with file changes unless the user asked for it. Use the appropriate edit tool instead.
34
+ NEVER print out a codeblock with a terminal command to run unless the user asked for it. Use the execute tool instead.
35
+ You don't need to read a file if it's already provided in context.
36
+ </instructions>
37
+
38
+ <toolUseInstructions>
39
+ ${TOOL_USE_INSTRUCTIONS}
40
+ </toolUseInstructions>
41
+
42
+ <editFileInstructions>
43
+ ${EDITING_INSTRUCTIONS}
44
+ </editFileInstructions>
45
+
46
+ <searchInstructions>
47
+ ${SEARCH_INSTRUCTIONS}
48
+ </searchInstructions>
49
+
50
+ <taskTracking>
51
+ ${TODO_INSTRUCTIONS}
52
+ </taskTracking>
53
+
54
+ <outputFormatting>
55
+ Use proper Markdown formatting. When referring to symbols (classes, methods, variables) in user's workspace wrap in backticks.
56
+ Use KaTeX for math: wrap inline math in $, complex blocks in $$.
57
+ </outputFormatting>
58
+ ${modeBlock ? `\n${modeBlock}` : ""}`;
59
+ }
60
+ // ── Resolver ─────────────────────────────────────────────────────────
61
+ const XAIPromptResolver = {
62
+ name: "xai",
63
+ familyPrefixes: ["grok-code", "grok"],
64
+ resolveSystemPrompt,
65
+ // xAI uses no custom reminder — falls through to the default.
66
+ };
67
+ promptRegistry.register(XAIPromptResolver);
68
+ //# sourceMappingURL=xai-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xai-prompt.js","sourceRoot":"","sources":["../../../src/tools/prompts/xai-prompt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAE9B,wEAAwE;AAExE,SAAS,mBAAmB,CAAC,IAAc,EAAE,SAAwB;IACnE,MAAM,SAAS,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAE5C,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BP,qBAAqB;;;;EAIrB,oBAAoB;;;;EAIpB,mBAAmB;;;;EAInB,iBAAiB;;;;;;;EAOjB,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACtC,CAAC;AAED,wEAAwE;AAExE,MAAM,iBAAiB,GAAiB;IACtC,IAAI,EAAE,KAAK;IACX,cAAc,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC;IAErC,mBAAmB;IAEnB,8DAA8D;CAC/D,CAAC;AAEF,cAAc,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * gateway.redeploy — Self-update tool for the Jait gateway.
3
+ *
4
+ * Flow (blue-green for bare process, i.e. `npm install -g @jait/gateway`):
5
+ * 1. Pull the latest version: npm install -g @jait/gateway@latest
6
+ * 2. Spawn a canary on PORT+1 to verify the new code boots correctly
7
+ * 3. Health-check the canary
8
+ * 4. If healthy → spawn a fresh gateway on the original port (detached),
9
+ * kill the canary, then gracefully shut down the current process
10
+ * 5. If unhealthy → kill the canary, report failure, stay running
11
+ *
12
+ * For Docker Swarm the tool triggers `docker service update --image ...`
13
+ * which uses the stack's start-first rolling update policy.
14
+ */
15
+ import type { ToolDefinition } from "./contracts.js";
16
+ interface RedeployInput {
17
+ /** Version/tag to install. Defaults to "latest". */
18
+ version?: string;
19
+ /** Skip the canary health check (not recommended). */
20
+ skipCanary?: boolean;
21
+ }
22
+ interface RedeployDeps {
23
+ /** Current gateway port (from config) */
24
+ port: number;
25
+ /** Graceful shutdown callback — will be called when cutover succeeds */
26
+ shutdown: () => Promise<void>;
27
+ }
28
+ export declare function createRedeployTool(deps: RedeployDeps): ToolDefinition<RedeployInput>;
29
+ export {};
30
+ //# sourceMappingURL=redeploy-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redeploy-tools.d.ts","sourceRoot":"","sources":["../../src/tools/redeploy-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,gBAAgB,CAAC;AAE9E,UAAU,aAAa;IACrB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,UAAU,YAAY;IACpB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,cAAc,CAAC,aAAa,CAAC,CAsCpF"}
@@ -0,0 +1,191 @@
1
+ /**
2
+ * gateway.redeploy — Self-update tool for the Jait gateway.
3
+ *
4
+ * Flow (blue-green for bare process, i.e. `npm install -g @jait/gateway`):
5
+ * 1. Pull the latest version: npm install -g @jait/gateway@latest
6
+ * 2. Spawn a canary on PORT+1 to verify the new code boots correctly
7
+ * 3. Health-check the canary
8
+ * 4. If healthy → spawn a fresh gateway on the original port (detached),
9
+ * kill the canary, then gracefully shut down the current process
10
+ * 5. If unhealthy → kill the canary, report failure, stay running
11
+ *
12
+ * For Docker Swarm the tool triggers `docker service update --image ...`
13
+ * which uses the stack's start-first rolling update policy.
14
+ */
15
+ import { execSync, spawn } from "node:child_process";
16
+ import { existsSync } from "node:fs";
17
+ export function createRedeployTool(deps) {
18
+ return {
19
+ name: "gateway.redeploy",
20
+ description: "Self-update the Jait gateway. Pulls the latest version via npm, " +
21
+ "verifies it in a canary process, then performs a zero-downtime " +
22
+ "switchover. The current process shuts down after the new one is confirmed healthy. " +
23
+ "This tool requires human consent.",
24
+ tier: "standard",
25
+ category: "gateway",
26
+ source: "builtin",
27
+ parameters: {
28
+ type: "object",
29
+ properties: {
30
+ version: {
31
+ type: "string",
32
+ description: 'Version/tag to install (default: "latest")',
33
+ },
34
+ skipCanary: {
35
+ type: "boolean",
36
+ description: "Skip the canary health check (not recommended)",
37
+ },
38
+ },
39
+ },
40
+ async execute(input, context) {
41
+ const tag = input.version ?? "latest";
42
+ const log = context.onOutputChunk ?? console.log;
43
+ // ── Detect runtime mode ─────────────────────────────────────
44
+ const isDocker = existsSync("/.dockerenv") || existsSync("/run/.containerenv");
45
+ if (isDocker) {
46
+ return dockerRedeploy(tag, log);
47
+ }
48
+ return npmRedeploy(tag, input.skipCanary ?? false, deps, log);
49
+ },
50
+ };
51
+ }
52
+ // ── npm (bare process) redeploy ──────────────────────────────────────
53
+ async function npmRedeploy(tag, skipCanary, deps, log) {
54
+ const pkg = `@jait/gateway@${tag}`;
55
+ // 1. Get current version before updating
56
+ let oldVersion = "unknown";
57
+ try {
58
+ const pkgJson = JSON.parse(execSync("node -e \"process.stdout.write(require('@jait/gateway/package.json').version)\"", {
59
+ encoding: "utf8",
60
+ timeout: 10_000,
61
+ }));
62
+ oldVersion = pkgJson;
63
+ }
64
+ catch {
65
+ // non-critical
66
+ }
67
+ // 2. Install the latest version
68
+ log(`⬇ Installing ${pkg}...\n`);
69
+ try {
70
+ execSync(`npm install -g ${pkg}`, {
71
+ encoding: "utf8",
72
+ timeout: 120_000,
73
+ stdio: "pipe",
74
+ });
75
+ }
76
+ catch (err) {
77
+ const msg = err instanceof Error ? err.message : String(err);
78
+ return { ok: false, message: `npm install failed: ${msg}` };
79
+ }
80
+ // 3. Read new version
81
+ let newVersion = "unknown";
82
+ try {
83
+ newVersion = execSync("node -e \"process.stdout.write(require('@jait/gateway/package.json').version)\"", { encoding: "utf8", timeout: 10_000 });
84
+ }
85
+ catch {
86
+ // non-critical
87
+ }
88
+ log(`✓ Installed @jait/gateway ${newVersion} (was ${oldVersion})\n`);
89
+ if (!skipCanary) {
90
+ // 4. Canary — start the new version on PORT+1
91
+ const canaryPort = deps.port + 1;
92
+ log(`🐤 Starting canary on port ${canaryPort}...\n`);
93
+ const canary = spawn("jait", ["--port", String(canaryPort)], {
94
+ stdio: "ignore",
95
+ detached: true,
96
+ env: { ...process.env, PORT: String(canaryPort), __JAIT_CLI: "1" },
97
+ });
98
+ canary.unref();
99
+ // 5. Wait for canary health (up to 30s)
100
+ const healthy = await waitForHealth(`http://127.0.0.1:${canaryPort}`, 30_000);
101
+ if (!healthy) {
102
+ // Kill canary and abort
103
+ try {
104
+ process.kill(-canary.pid, "SIGTERM");
105
+ }
106
+ catch { /* ignore */ }
107
+ return {
108
+ ok: false,
109
+ message: `Canary failed health check on port ${canaryPort}. Update installed but NOT activated. Current gateway is still running.`,
110
+ data: { oldVersion, newVersion, canaryPort },
111
+ };
112
+ }
113
+ log(`✓ Canary healthy on port ${canaryPort}\n`);
114
+ // 6. Kill the canary (it was just a test)
115
+ try {
116
+ process.kill(-canary.pid, "SIGTERM");
117
+ }
118
+ catch { /* ignore */ }
119
+ // Brief wait for port release
120
+ await sleep(1_000);
121
+ }
122
+ // 7. Spawn the new gateway on the original port (detached, survives parent exit)
123
+ log(`🔄 Spawning new gateway on port ${deps.port}...\n`);
124
+ const fresh = spawn("jait", ["--port", String(deps.port)], {
125
+ stdio: "ignore",
126
+ detached: true,
127
+ env: { ...process.env, PORT: String(deps.port), __JAIT_CLI: "1" },
128
+ });
129
+ fresh.unref();
130
+ // 8. Shut down the current process
131
+ log(`✓ New gateway spawned (PID ${fresh.pid}). Shutting down current process...\n`);
132
+ // Give the response time to be sent before shutdown
133
+ setTimeout(() => {
134
+ deps.shutdown().catch(() => process.exit(0));
135
+ }, 500);
136
+ return {
137
+ ok: true,
138
+ message: `Gateway updated ${oldVersion} → ${newVersion}. New process (PID ${fresh.pid}) is starting on port ${deps.port}. This instance is shutting down.`,
139
+ data: { oldVersion, newVersion, pid: fresh.pid },
140
+ };
141
+ }
142
+ // ── Docker Swarm redeploy ────────────────────────────────────────────
143
+ async function dockerRedeploy(tag, log) {
144
+ // Detect the service name from Docker labels or hostname
145
+ let serviceName = "jait_gateway";
146
+ try {
147
+ const hostname = execSync("hostname", { encoding: "utf8" }).trim();
148
+ // In Docker Swarm the hostname is usually the task slot ID,
149
+ // but DOCKER_SERVICE_NAME env or container labels may be present
150
+ serviceName = process.env["DOCKER_SERVICE_NAME"] ?? serviceName;
151
+ log(`Docker service: ${serviceName} (host: ${hostname})\n`);
152
+ }
153
+ catch { /* ignore */ }
154
+ const image = `ghcr.io/jakobwl/jait-gateway:${tag}`;
155
+ log(`🐳 Triggering rolling update to ${image}...\n`);
156
+ try {
157
+ // The stack's update_config has order: start-first, so Docker will
158
+ // start the new container, health-check it, then stop the old one
159
+ execSync(`docker service update --image ${image} --with-registry-auth ${serviceName}`, { encoding: "utf8", timeout: 300_000, stdio: "pipe" });
160
+ }
161
+ catch (err) {
162
+ const msg = err instanceof Error ? err.message : String(err);
163
+ return { ok: false, message: `Docker service update failed: ${msg}` };
164
+ }
165
+ return {
166
+ ok: true,
167
+ message: `Rolling update to ${image} triggered. Docker Swarm will start-first, health-check, then drain the old container.`,
168
+ data: { image, serviceName },
169
+ };
170
+ }
171
+ // ── Helpers ──────────────────────────────────────────────────────────
172
+ async function waitForHealth(url, timeoutMs) {
173
+ const start = Date.now();
174
+ const healthUrl = `${url}/health`;
175
+ while (Date.now() - start < timeoutMs) {
176
+ try {
177
+ const res = await fetch(healthUrl, { signal: AbortSignal.timeout(3_000) });
178
+ if (res.ok)
179
+ return true;
180
+ }
181
+ catch {
182
+ // not ready yet
183
+ }
184
+ await sleep(1_000);
185
+ }
186
+ return false;
187
+ }
188
+ function sleep(ms) {
189
+ return new Promise((resolve) => setTimeout(resolve, ms));
190
+ }
191
+ //# sourceMappingURL=redeploy-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redeploy-tools.js","sourceRoot":"","sources":["../../src/tools/redeploy-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAiBrC,MAAM,UAAU,kBAAkB,CAAC,IAAkB;IACnD,OAAO;QACL,IAAI,EAAE,kBAAkB;QACxB,WAAW,EACT,kEAAkE;YAClE,iEAAiE;YACjE,qFAAqF;YACrF,mCAAmC;QACrC,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,SAAS;QACjB,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,4CAA4C;iBAC1D;gBACD,UAAU,EAAE;oBACV,IAAI,EAAE,SAAS;oBACf,WAAW,EAAE,gDAAgD;iBAC9D;aACF;SACF;QAED,KAAK,CAAC,OAAO,CAAC,KAAoB,EAAE,OAAoB;YACtD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,IAAI,QAAQ,CAAC;YACtC,MAAM,GAAG,GAAG,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC;YAEjD,+DAA+D;YAC/D,MAAM,QAAQ,GAAG,UAAU,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAC;YAE/E,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAClC,CAAC;YACD,OAAO,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,UAAU,IAAI,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QAChE,CAAC;K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,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC3E,IAAI,GAAG,CAAC,EAAE;gBAAE,OAAO,IAAI,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,gBAAgB;QAClB,CAAC;QACD,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Tool Registry — Sprint 3.5
3
+ *
4
+ * Central registry for all tool definitions. Tools are registered
5
+ * by name and executed through a unified interface.
6
+ */
7
+ import type { ToolDefinition, ToolContext, ToolResult, ToolTier, ToolCategory } from "./contracts.js";
8
+ import type { AuditWriter } from "../services/audit.js";
9
+ /** Summary of a tool for the settings UI and discovery endpoints */
10
+ export interface ToolInfo {
11
+ name: string;
12
+ description: string;
13
+ tier: ToolTier;
14
+ category: ToolCategory;
15
+ source: "builtin" | "mcp";
16
+ parameterCount: number;
17
+ }
18
+ export declare class ToolRegistry {
19
+ private readonly tools;
20
+ register(tool: ToolDefinition): void;
21
+ get(name: string): ToolDefinition | undefined;
22
+ list(): ToolDefinition[];
23
+ listNames(): string[];
24
+ has(name: string): boolean;
25
+ /** List tools filtered by tier */
26
+ listByTier(tier: ToolTier): ToolDefinition[];
27
+ /** List tools filtered by category */
28
+ listByCategory(category: ToolCategory): ToolDefinition[];
29
+ /** Search tools by name, description, or category (fuzzy keyword match) */
30
+ search(query: string): ToolDefinition[];
31
+ /** Get tool info summaries for all tools (lightweight, no execute fn) */
32
+ listInfo(): ToolInfo[];
33
+ /** Get tool info filtered to only enabled tools for a user */
34
+ listInfoFiltered(disabledTools?: Set<string>): ToolInfo[];
35
+ /**
36
+ * Get tools that should be sent in the initial LLM payload.
37
+ * Core tools always, standard tools unless user disabled them.
38
+ */
39
+ listForLLM(disabledTools?: Set<string>): ToolDefinition[];
40
+ /**
41
+ * Check if a tool is executable (registered and not disabled).
42
+ * Even discovered external tools can be executed if they're registered.
43
+ * The disabled check only gates what's sent to the LLM, not execution.
44
+ */
45
+ isExecutable(name: string, disabledTools?: Set<string>): boolean;
46
+ /**
47
+ * Execute a tool by name with audit logging.
48
+ */
49
+ execute(name: string, input: unknown, context: ToolContext, audit?: AuditWriter): Promise<ToolResult>;
50
+ }
51
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACtG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIxD,oEAAoE;AACpE,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,YAAY,CAAC;IACvB,MAAM,EAAE,SAAS,GAAG,KAAK,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqC;IAE3D,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAIpC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAI7C,IAAI,IAAI,cAAc,EAAE;IAIxB,SAAS,IAAI,MAAM,EAAE;IAIrB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,kCAAkC;IAClC,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,cAAc,EAAE;IAI5C,sCAAsC;IACtC,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,cAAc,EAAE;IAIxD,2EAA2E;IAC3E,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,EAAE;IASvC,yEAAyE;IACzE,QAAQ,IAAI,QAAQ,EAAE;IAWtB,8DAA8D;IAC9D,gBAAgB,CAAC,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,QAAQ,EAAE;IAIzD;;;OAGG;IACH,UAAU,CAAC,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,cAAc,EAAE;IAUzD;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO;IAMhE;;OAEG;IACG,OAAO,CACX,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,WAAW,EACpB,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,UAAU,CAAC;CAmEvB"}
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Tool Registry — Sprint 3.5
3
+ *
4
+ * Central registry for all tool definitions. Tools are registered
5
+ * by name and executed through a unified interface.
6
+ */
7
+ import { uuidv7 } from "../lib/uuidv7.js";
8
+ import { validateToolInput } from "./validate.js";
9
+ export class ToolRegistry {
10
+ tools = new Map();
11
+ register(tool) {
12
+ this.tools.set(tool.name, tool);
13
+ }
14
+ get(name) {
15
+ return this.tools.get(name);
16
+ }
17
+ list() {
18
+ return [...this.tools.values()];
19
+ }
20
+ listNames() {
21
+ return [...this.tools.keys()];
22
+ }
23
+ has(name) {
24
+ return this.tools.has(name);
25
+ }
26
+ /** List tools filtered by tier */
27
+ listByTier(tier) {
28
+ return this.list().filter((t) => (t.tier ?? "standard") === tier);
29
+ }
30
+ /** List tools filtered by category */
31
+ listByCategory(category) {
32
+ return this.list().filter((t) => (t.category ?? "external") === category);
33
+ }
34
+ /** Search tools by name, description, or category (fuzzy keyword match) */
35
+ search(query) {
36
+ const lower = query.toLowerCase();
37
+ const keywords = lower.split(/\s+/).filter(Boolean);
38
+ return this.list().filter((t) => {
39
+ const haystack = `${t.name} ${t.description} ${t.category ?? ""} ${t.tier ?? ""}`.toLowerCase();
40
+ return keywords.every((kw) => haystack.includes(kw));
41
+ });
42
+ }
43
+ /** Get tool info summaries for all tools (lightweight, no execute fn) */
44
+ listInfo() {
45
+ return this.list().map((t) => ({
46
+ name: t.name,
47
+ description: t.description,
48
+ tier: t.tier ?? "standard",
49
+ category: t.category ?? "external",
50
+ source: t.source ?? "builtin",
51
+ parameterCount: Object.keys(t.parameters.properties ?? {}).length,
52
+ }));
53
+ }
54
+ /** Get tool info filtered to only enabled tools for a user */
55
+ listInfoFiltered(disabledTools) {
56
+ return this.listInfo().filter((t) => !disabledTools?.has(t.name));
57
+ }
58
+ /**
59
+ * Get tools that should be sent in the initial LLM payload.
60
+ * Core tools always, standard tools unless user disabled them.
61
+ */
62
+ listForLLM(disabledTools) {
63
+ return this.list().filter((t) => {
64
+ if (disabledTools?.has(t.name))
65
+ return false;
66
+ const tier = t.tier ?? "standard";
67
+ // Core and standard go in the initial payload
68
+ // External (MCP) tools must be discovered via tools.search
69
+ return tier === "core" || tier === "standard";
70
+ });
71
+ }
72
+ /**
73
+ * Check if a tool is executable (registered and not disabled).
74
+ * Even discovered external tools can be executed if they're registered.
75
+ * The disabled check only gates what's sent to the LLM, not execution.
76
+ */
77
+ isExecutable(name, disabledTools) {
78
+ if (!this.tools.has(name))
79
+ return false;
80
+ if (disabledTools?.has(name))
81
+ return false;
82
+ return true;
83
+ }
84
+ /**
85
+ * Execute a tool by name with audit logging.
86
+ */
87
+ async execute(name, input, context, audit) {
88
+ const tool = this.tools.get(name);
89
+ if (!tool) {
90
+ return { ok: false, message: `Unknown tool: ${name}` };
91
+ }
92
+ const actionId = context.actionId || uuidv7();
93
+ // ── Input validation (fast-reject bad LLM arguments) ──
94
+ const validation = validateToolInput(tool.parameters, input);
95
+ if (!validation.valid) {
96
+ const errorMsg = `Input validation failed: ${validation.errors.join("; ")}`;
97
+ audit?.write({
98
+ sessionId: context.sessionId,
99
+ actionId,
100
+ actionType: "tool.validation_error",
101
+ toolName: name,
102
+ inputs: input,
103
+ outputs: { errors: validation.errors },
104
+ status: "failed",
105
+ });
106
+ return { ok: false, message: errorMsg };
107
+ }
108
+ // Log start
109
+ audit?.write({
110
+ sessionId: context.sessionId,
111
+ actionId,
112
+ actionType: "tool.execute",
113
+ toolName: name,
114
+ inputs: input,
115
+ status: "executing",
116
+ });
117
+ try {
118
+ const result = await tool.execute(input, { ...context, actionId });
119
+ // Log result
120
+ audit?.write({
121
+ sessionId: context.sessionId,
122
+ actionId: uuidv7(), // separate audit entry for completion
123
+ actionType: "tool.result",
124
+ toolName: name,
125
+ inputs: input,
126
+ outputs: result.data,
127
+ status: result.ok ? "completed" : "failed",
128
+ parentActionId: actionId,
129
+ });
130
+ return result;
131
+ }
132
+ catch (err) {
133
+ const message = err instanceof Error ? err.message : String(err);
134
+ audit?.write({
135
+ sessionId: context.sessionId,
136
+ actionId: uuidv7(),
137
+ actionType: "tool.error",
138
+ toolName: name,
139
+ inputs: input,
140
+ outputs: { error: message },
141
+ status: "failed",
142
+ parentActionId: actionId,
143
+ });
144
+ return { ok: false, message };
145
+ }
146
+ }
147
+ }
148
+ //# sourceMappingURL=registry.js.map