@crewx/sdk 0.9.0-rc.17 → 0.9.0-rc.171

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 (343) hide show
  1. package/README.md +1 -1
  2. package/dist/account/auth-client.d.ts +61 -0
  3. package/dist/account/auth-json-v2.d.ts +1 -0
  4. package/dist/account/auth-json.d.ts +30 -0
  5. package/dist/account/config.d.ts +37 -0
  6. package/dist/account/env-bootstrap.d.ts +11 -0
  7. package/dist/account/errors.d.ts +24 -0
  8. package/dist/account/index.d.ts +12 -0
  9. package/dist/account/index.js +2 -0
  10. package/dist/account/session-manager.d.ts +47 -0
  11. package/dist/activity-log/builder.d.ts +59 -6
  12. package/dist/agent/agent-list-view.d.ts +19 -0
  13. package/dist/agent-interceptor/chain.d.ts +25 -0
  14. package/dist/agent-interceptor/index.d.ts +6 -0
  15. package/dist/agent-interceptor/model-runner.d.ts +19 -0
  16. package/dist/agent-interceptor/program-runner.d.ts +13 -0
  17. package/dist/agent-interceptor/protocol.d.ts +68 -0
  18. package/dist/agent-interceptor/run-stop.d.ts +3 -0
  19. package/dist/agent-interceptor/schema.d.ts +267 -0
  20. package/dist/agent-interceptor/types.d.ts +88 -0
  21. package/dist/app/app.d.ts +167 -0
  22. package/dist/app/backend-env.d.ts +3 -0
  23. package/dist/app/content-media-types.d.ts +2 -0
  24. package/dist/app/context.d.ts +2 -0
  25. package/dist/app/entry.d.ts +9 -0
  26. package/dist/app/frame.d.ts +55 -0
  27. package/dist/app/index.d.ts +18 -0
  28. package/dist/app/index.js +12 -0
  29. package/dist/app/job-bridge.child.d.ts +1 -0
  30. package/dist/app/job-bridge.d.ts +67 -0
  31. package/dist/app/job-bridge.drain.child.d.ts +1 -0
  32. package/dist/app/job-bridge.example.d.ts +11 -0
  33. package/dist/app/job-contract.d.ts +40 -0
  34. package/dist/app/job-wire.d.ts +149 -0
  35. package/dist/app/protocol.d.ts +9 -0
  36. package/dist/app/runtime.d.ts +23 -0
  37. package/dist/app/schedule-contract.d.ts +59 -0
  38. package/dist/app/tool-mode.d.ts +3 -0
  39. package/dist/app-artifact-policy/check.d.ts +2 -0
  40. package/dist/app-artifact-policy/contract.d.ts +54 -0
  41. package/dist/app-artifact-policy/helper.d.ts +15 -0
  42. package/dist/app-artifact-policy/index.d.ts +3 -0
  43. package/dist/app-artifact-policy/index.js +18 -0
  44. package/dist/app-artifact-policy/paths.d.ts +24 -0
  45. package/dist/app-artifact-policy/scan.d.ts +47 -0
  46. package/dist/boxing/box.types.d.ts +4 -0
  47. package/dist/config/canonicalize-agent-options.d.ts +18 -0
  48. package/dist/config/default-agent-models.d.ts +11 -0
  49. package/dist/config/global-settings.d.ts +33 -0
  50. package/dist/config/migrate-grok-mode.d.ts +6 -0
  51. package/dist/config/model-compat.d.ts +31 -0
  52. package/dist/config/models.generated.d.ts +37 -0
  53. package/dist/config/models.remote.d.ts +1 -0
  54. package/dist/config/overdrive.d.ts +7 -0
  55. package/dist/config/pricing.d.ts +6 -3
  56. package/dist/config/pricing.generated.d.ts +4 -0
  57. package/dist/config/pricing.types.d.ts +4 -0
  58. package/dist/config/timeout.config.d.ts +4 -0
  59. package/dist/config/wi-boards.d.ts +19 -0
  60. package/dist/context-budget/continuity.d.ts +63 -0
  61. package/dist/context-budget/index.d.ts +142 -0
  62. package/dist/conversation/index.d.ts +1 -1
  63. package/dist/conversation/sqlite-provider.d.ts +6 -3
  64. package/dist/conversation/to-template-messages.d.ts +9 -0
  65. package/dist/conversation/types.d.ts +58 -1
  66. package/dist/desktop/command-runner.d.ts +4 -0
  67. package/dist/desktop/default-adapters.d.ts +4 -0
  68. package/dist/desktop/global-install.d.ts +19 -0
  69. package/dist/desktop/index.d.ts +3 -0
  70. package/dist/desktop/index.js +3 -0
  71. package/dist/desktop/install.d.ts +5 -0
  72. package/dist/desktop/lnk.d.ts +22 -0
  73. package/dist/desktop/manifest.d.ts +21 -0
  74. package/dist/desktop/types.d.ts +67 -0
  75. package/dist/desktop/version.d.ts +1 -0
  76. package/dist/desktop/windows-paths.d.ts +21 -0
  77. package/dist/desktop/wrapper.d.ts +18 -0
  78. package/dist/esm/account/index.js +2 -0
  79. package/dist/esm/app/index.js +12 -0
  80. package/dist/esm/app-artifact-policy/index.js +18 -0
  81. package/dist/esm/desktop/index.js +3 -0
  82. package/dist/esm/index.js +1175 -224
  83. package/dist/esm/node/index.js +2 -0
  84. package/dist/esm/plugins/index.js +527 -214
  85. package/dist/esm/process/index.js +1 -0
  86. package/dist/esm/publish/index.js +2 -0
  87. package/dist/esm/repository/index.js +648 -211
  88. package/dist/esm/skills/index.js +2 -0
  89. package/dist/esm/testing/index.js +1 -1
  90. package/dist/events/types.d.ts +28 -0
  91. package/dist/facade/Crewx.d.ts +70 -5
  92. package/dist/facade/task-ticket.d.ts +14 -0
  93. package/dist/highlight/thread-highlight-prompt.d.ts +2 -0
  94. package/dist/highlight/thread-highlighter.d.ts +326 -0
  95. package/dist/index.browser.d.ts +25 -1
  96. package/dist/index.browser.js +6 -2
  97. package/dist/index.d.ts +157 -17
  98. package/dist/index.js +1175 -224
  99. package/dist/internal/console-decoder.d.ts +38 -0
  100. package/dist/internal/windows-spawn.d.ts +10 -0
  101. package/dist/layout/types.d.ts +18 -1
  102. package/dist/lifecycle/process-lease.d.ts +80 -0
  103. package/dist/lifecycle/process-owner.d.ts +20 -0
  104. package/dist/lifecycle/task-heartbeat.d.ts +41 -0
  105. package/dist/lifecycle/task-stop.d.ts +82 -0
  106. package/dist/lifecycle/update-admission.d.ts +45 -0
  107. package/dist/local-server/base-url.d.ts +18 -0
  108. package/dist/local-server/index.d.ts +8 -0
  109. package/dist/local-server/opencode.d.ts +8 -0
  110. package/dist/local-server/probe.d.ts +3 -0
  111. package/dist/local-server/runtime.d.ts +26 -0
  112. package/dist/local-server/types.d.ts +43 -0
  113. package/dist/mcp-app/agent-access.d.ts +26 -0
  114. package/dist/mcp-app/app-handoff.d.ts +109 -0
  115. package/dist/mcp-app/app-icon-read.d.ts +7 -0
  116. package/dist/mcp-app/app-job-bridge.d.ts +30 -0
  117. package/dist/mcp-app/app-job-bridge.example.d.ts +36 -0
  118. package/dist/mcp-app/app-job.d.ts +168 -0
  119. package/dist/mcp-app/app-schedule.d.ts +85 -0
  120. package/dist/mcp-app/apps-context.d.ts +32 -0
  121. package/dist/mcp-app/bundle-provenance.d.ts +3 -0
  122. package/dist/mcp-app/candidate-registration.d.ts +4 -0
  123. package/dist/mcp-app/card-handler.d.ts +7 -0
  124. package/dist/mcp-app/catalog.d.ts +7 -0
  125. package/dist/mcp-app/content-channel.d.ts +86 -0
  126. package/dist/mcp-app/content-declarations.d.ts +31 -0
  127. package/dist/mcp-app/dev-checks.d.ts +31 -0
  128. package/dist/mcp-app/diagnostic-reason.d.ts +3 -0
  129. package/dist/mcp-app/discovery.d.ts +164 -0
  130. package/dist/mcp-app/errors.d.ts +7 -0
  131. package/dist/mcp-app/index.d.ts +45 -0
  132. package/dist/mcp-app/installed-app-ref.d.ts +25 -0
  133. package/dist/mcp-app/model-context.d.ts +29 -0
  134. package/dist/mcp-app/node-app-discovery-fs.d.ts +23 -0
  135. package/dist/mcp-app/product-bundle-assets.d.ts +27 -0
  136. package/dist/mcp-app/product-bundle-loader.d.ts +53 -0
  137. package/dist/mcp-app/projection.d.ts +14 -0
  138. package/dist/mcp-app/prompt-cards.d.ts +28 -0
  139. package/dist/mcp-app/registry.d.ts +28 -0
  140. package/dist/mcp-app/skill-backend.d.ts +141 -0
  141. package/dist/mcp-app/state-set.d.ts +9 -0
  142. package/dist/mcp-app/types.d.ts +490 -0
  143. package/dist/mcp-app/workspace-app-assets.d.ts +42 -0
  144. package/dist/mcp-app/workspace-app-scan-cache.d.ts +27 -0
  145. package/dist/mcp-app/workspace-snapshot.d.ts +76 -0
  146. package/dist/migrations/0011_far_black_tarantula.sql +1 -0
  147. package/dist/migrations/0012_blue_turbo.sql +23 -0
  148. package/dist/migrations/0013_hesitant_adam_destine.sql +15 -0
  149. package/dist/migrations/0014_organic_mongu.sql +73 -0
  150. package/dist/migrations/0015_panoramic_gorilla_man.sql +71 -0
  151. package/dist/migrations/0016_fuzzy_hemingway.sql +14 -0
  152. package/dist/migrations/0017_project_stage_sdk_migration.sql +29 -0
  153. package/dist/migrations/0018_bored_jackal.sql +33 -0
  154. package/dist/migrations/0019_backfill_task_thread_ids.sql +74 -0
  155. package/dist/migrations/0020_useful_iron_lad.sql +55 -0
  156. package/dist/migrations/0021_dashing_peter_quill.sql +51 -0
  157. package/dist/migrations/0022_wandering_bucky.sql +1 -0
  158. package/dist/migrations/0023_red_payback.sql +1 -0
  159. package/dist/migrations/0024_storage_metadata.sql +262 -0
  160. package/dist/migrations/0025_task_heartbeat.sql +8 -0
  161. package/dist/migrations/0025_thread_app_instance_ledger.sql +2 -0
  162. package/dist/migrations/0026_mcp_action_source.sql +47 -0
  163. package/dist/migrations/0027_task_stop_scope_cleanup.sql +5 -0
  164. package/dist/migrations/0027_ui_instance_active_unique.sql +2 -0
  165. package/dist/migrations/0029_nice_rhino.sql +1 -0
  166. package/dist/migrations/0031_petite_arclight.sql +6 -0
  167. package/dist/migrations/0032_ui_instance_opened_by.sql +1 -0
  168. package/dist/migrations/0033_thread_creator_boundary_guard.sql +38 -0
  169. package/dist/migrations/0034_keen_fallen_one.sql +36 -0
  170. package/dist/migrations/0035_request_log_daily.sql +11 -0
  171. package/dist/migrations/0036_ui_definition_archive.sql +8 -0
  172. package/dist/migrations/0037_ui_instance_agent_open_request.sql +1 -0
  173. package/dist/migrations/0038_task_rating.sql +3 -0
  174. package/dist/migrations/0039_aspiring_purifiers.sql +9 -0
  175. package/dist/migrations/0040_task_provider_inputs.sql +53 -0
  176. package/dist/migrations/0041_tranquil_vivisector.sql +54 -0
  177. package/dist/migrations/meta/0011_snapshot.json +1342 -0
  178. package/dist/migrations/meta/0012_snapshot.json +1494 -0
  179. package/dist/migrations/meta/0013_snapshot.json +1592 -0
  180. package/dist/migrations/meta/0014_snapshot.json +1975 -0
  181. package/dist/migrations/meta/0015_snapshot.json +2315 -0
  182. package/dist/migrations/meta/0016_snapshot.json +2419 -0
  183. package/dist/migrations/meta/0017_snapshot.json +2419 -0
  184. package/dist/migrations/meta/0018_snapshot.json +2570 -0
  185. package/dist/migrations/meta/0020_snapshot.json +2895 -0
  186. package/dist/migrations/meta/0021_snapshot.json +3031 -0
  187. package/dist/migrations/meta/0022_snapshot.json +3039 -0
  188. package/dist/migrations/meta/0023_snapshot.json +3047 -0
  189. package/dist/migrations/meta/0029_snapshot.json +3206 -0
  190. package/dist/migrations/meta/0031_snapshot.json +3251 -0
  191. package/dist/migrations/meta/0034_snapshot.json +3473 -0
  192. package/dist/migrations/meta/0035_snapshot.json +3547 -0
  193. package/dist/migrations/meta/0036_snapshot.json +3591 -0
  194. package/dist/migrations/meta/0037_snapshot.json +3598 -0
  195. package/dist/migrations/meta/0038_snapshot.json +3626 -0
  196. package/dist/migrations/meta/0039_snapshot.json +3684 -0
  197. package/dist/migrations/meta/0040_snapshot.json +3759 -0
  198. package/dist/migrations/meta/0041_snapshot.json +4156 -0
  199. package/dist/migrations/meta/_journal.json +217 -0
  200. package/dist/node/index.d.ts +1 -0
  201. package/dist/node/index.js +2 -0
  202. package/dist/paths.d.ts +1 -0
  203. package/dist/plugin/types.d.ts +1 -0
  204. package/dist/plugins/index.d.ts +1 -1
  205. package/dist/plugins/index.js +527 -214
  206. package/dist/plugins/sqlite-tracing.d.ts +46 -0
  207. package/dist/process/index.d.ts +2 -0
  208. package/dist/process/index.js +1 -0
  209. package/dist/process/process-control.d.ts +60 -0
  210. package/dist/prompt/tag-names.d.ts +22 -0
  211. package/dist/provider/acp/connection.d.ts +6 -0
  212. package/dist/provider/acp/meta.d.ts +11 -0
  213. package/dist/provider/bridge.d.ts +12 -2
  214. package/dist/provider/classify-task-error.d.ts +2 -0
  215. package/dist/provider/claude-agent-env.d.ts +1 -0
  216. package/dist/provider/cli/adapter.types.d.ts +23 -2
  217. package/dist/provider/cli/adapters/agent-call.util.d.ts +1 -1
  218. package/dist/provider/cli/adapters/cli-knob.util.d.ts +7 -0
  219. package/dist/provider/cli/adapters/codex-item.d.ts +1 -0
  220. package/dist/provider/cli/adapters/event-timestamp.util.d.ts +1 -0
  221. package/dist/provider/cli/adapters/grok.d.ts +2 -0
  222. package/dist/provider/cli/adapters/index.d.ts +5 -0
  223. package/dist/provider/cli/index.d.ts +3 -2
  224. package/dist/provider/cli/meta.d.ts +5 -0
  225. package/dist/provider/cli/protocol-envelope.d.ts +3 -0
  226. package/dist/provider/errors.d.ts +5 -1
  227. package/dist/provider/idle-watchdog.d.ts +19 -0
  228. package/dist/provider/models.d.ts +17 -12
  229. package/dist/provider/order.d.ts +1 -1
  230. package/dist/provider/parse-usage.d.ts +6 -0
  231. package/dist/provider/provider-selection.d.ts +8 -0
  232. package/dist/provider/redact-technical-message.d.ts +1 -0
  233. package/dist/provider/task-error.types.d.ts +17 -0
  234. package/dist/provider-account/accounts.d.ts +15 -0
  235. package/dist/provider-account/index.d.ts +5 -0
  236. package/dist/provider-account/registry.d.ts +30 -0
  237. package/dist/provider-account/types.d.ts +40 -0
  238. package/dist/publish/constants.d.ts +6 -0
  239. package/dist/publish/errors.d.ts +7 -0
  240. package/dist/publish/index.d.ts +55 -0
  241. package/dist/publish/index.js +2 -0
  242. package/dist/publish/manifest.d.ts +47 -0
  243. package/dist/publish/marketplace-api.constants.d.ts +1 -0
  244. package/dist/publish/pack.d.ts +6 -0
  245. package/dist/publish/scan.d.ts +10 -0
  246. package/dist/publish/secrets.d.ts +6 -0
  247. package/dist/publish/upload.d.ts +19 -0
  248. package/dist/remote/execution-profile.d.ts +9 -0
  249. package/dist/remote/index.d.ts +1 -0
  250. package/dist/remote/types.d.ts +28 -0
  251. package/dist/repository/agent-send-history.repository.d.ts +23 -0
  252. package/dist/repository/agent-suggestion.repository.d.ts +34 -0
  253. package/dist/repository/base-sqlite-repository.d.ts +1 -0
  254. package/dist/repository/common-code.repository.d.ts +45 -0
  255. package/dist/repository/db.d.ts +12 -1
  256. package/dist/repository/index.d.ts +53 -6
  257. package/dist/repository/index.js +648 -211
  258. package/dist/repository/logs-db.d.ts +12 -0
  259. package/dist/repository/notification.repository.d.ts +58 -0
  260. package/dist/repository/project.repository.d.ts +90 -0
  261. package/dist/repository/public-task-answer.d.ts +24 -0
  262. package/dist/repository/request-log-mover.d.ts +70 -0
  263. package/dist/repository/request-log.repository.d.ts +7 -3
  264. package/dist/repository/sidebar-tab.repository.d.ts +86 -0
  265. package/dist/repository/storage-metadata.repository.d.ts +64 -0
  266. package/dist/repository/task-log-migration.d.ts +74 -0
  267. package/dist/repository/task-log.repository.d.ts +44 -0
  268. package/dist/repository/task-status.d.ts +21 -0
  269. package/dist/repository/task.repository.d.ts +307 -8
  270. package/dist/repository/thread-history.repository.d.ts +193 -0
  271. package/dist/repository/thread-origin-verdict.d.ts +27 -0
  272. package/dist/repository/thread-title.types.d.ts +29 -0
  273. package/dist/repository/thread.repository.d.ts +134 -5
  274. package/dist/repository/usage-backfill.d.ts +62 -0
  275. package/dist/repository/usage-from-logs.d.ts +21 -0
  276. package/dist/repository/workspace.repository.d.ts +3 -0
  277. package/dist/schema/agent-send-history.d.ts +85 -0
  278. package/dist/schema/agent-suggestions.d.ts +199 -0
  279. package/dist/schema/common-codes.d.ts +216 -0
  280. package/dist/schema/index.d.ts +16 -0
  281. package/dist/schema/notifications.d.ts +303 -0
  282. package/dist/schema/projects.d.ts +610 -0
  283. package/dist/schema/request-log-daily.d.ts +151 -0
  284. package/dist/schema/sidebar-tabs.d.ts +466 -0
  285. package/dist/schema/storage-metadata.d.ts +181 -0
  286. package/dist/schema/task-log-events.d.ts +119 -0
  287. package/dist/schema/task-provider-inputs.d.ts +100 -0
  288. package/dist/schema/tasks.d.ts +1058 -1
  289. package/dist/schema/thread-creator-unverified.d.ts +45 -0
  290. package/dist/schema/thread-history.d.ts +734 -0
  291. package/dist/schema/threads.d.ts +59 -0
  292. package/dist/schema/ui-action-receipts.d.ts +358 -0
  293. package/dist/schema/ui-definition-archive.d.ts +63 -0
  294. package/dist/schema/ui-instance-repins.d.ts +222 -0
  295. package/dist/schema/ui-instances.d.ts +324 -0
  296. package/dist/schema/workspaces.d.ts +17 -0
  297. package/dist/skills/index.d.ts +15 -0
  298. package/dist/skills/index.js +2 -0
  299. package/dist/skills/types.d.ts +18 -0
  300. package/dist/task-log/anchor-child-tasks.d.ts +7 -0
  301. package/dist/task-log/delegation-trailer.d.ts +34 -0
  302. package/dist/template/engine.d.ts +2 -2
  303. package/dist/template/helpers/exec.browser.d.ts +4 -3
  304. package/dist/template/helpers/exec.d.ts +4 -3
  305. package/dist/template/helpers/format-conversation.d.ts +1 -0
  306. package/dist/template/types.d.ts +20 -0
  307. package/dist/testing/index.js +1 -1
  308. package/dist/types/index.d.ts +1611 -3
  309. package/dist/types/task-log.types.d.ts +6 -1
  310. package/dist/ui-card/index.d.ts +2 -0
  311. package/dist/ui-card/legacy-card-parser.d.ts +11 -0
  312. package/dist/ui-instance/definition.d.ts +6 -0
  313. package/dist/ui-instance/errors.d.ts +18 -0
  314. package/dist/ui-instance/index.d.ts +11 -0
  315. package/dist/ui-instance/json.d.ts +19 -0
  316. package/dist/ui-instance/lineage.d.ts +24 -0
  317. package/dist/ui-instance/runtime.d.ts +19 -0
  318. package/dist/ui-instance/store.d.ts +213 -0
  319. package/dist/ui-instance/types.d.ts +343 -0
  320. package/dist/ui-plugin/app-icon.d.ts +50 -0
  321. package/dist/ui-plugin/app-manifest.d.ts +64 -0
  322. package/dist/ui-plugin/csp.d.ts +28 -0
  323. package/dist/ui-plugin/index.d.ts +8 -0
  324. package/dist/ui-plugin/limits.d.ts +27 -0
  325. package/dist/ui-plugin/manifest.d.ts +3 -0
  326. package/dist/ui-plugin/types.d.ts +208 -0
  327. package/dist/ui-plugin/validator.d.ts +18 -0
  328. package/dist/utils/crewx-executable.d.ts +76 -0
  329. package/dist/utils/crewx-home.d.ts +1 -0
  330. package/dist/utils/env-defaults.d.ts +3 -0
  331. package/dist/utils/id.d.ts +1 -1
  332. package/dist/utils/local-identity.d.ts +2 -0
  333. package/dist/utils/runner-env.d.ts +3 -0
  334. package/dist/utils/timestamp.d.ts +1 -0
  335. package/dist/utils/workspace.d.ts +1 -0
  336. package/dist/wi/create.d.ts +48 -0
  337. package/dist/wi/select.d.ts +20 -0
  338. package/package.json +63 -3
  339. package/templates/agents/default.yaml +303 -128
  340. package/templates/documents/crewx-manual.md +138 -138
  341. package/templates/documents/crewx-quick-guide.md +8 -7
  342. package/templates/workflows/wi-default-flow.yaml +65 -0
  343. package/templates/workflows/wi-plan-flow.yaml +140 -0
@@ -1,21 +1,123 @@
1
1
  import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
+ import type { DrizzleDb } from './db.js';
3
+ import { RepositoryError } from './errors.js';
2
4
  import { tasks } from '../schema/index.js';
3
- export type TaskRow = typeof tasks.$inferSelect;
5
+ import type { TaskLogEntry, TaskLogReadResult, TaskLogState } from './task-log.repository.js';
6
+ import { type TaskStatus, type TaskTerminalReason } from './task-status.js';
7
+ import { type StopTaskOptions, type StopTaskGenerationForInstructionOptions, type StopTaskResult } from '../lifecycle/task-stop.js';
8
+ export { TASK_HEARTBEAT_HARD_STALE_MS, TASK_HEARTBEAT_INTERVAL_MS, TASK_HEARTBEAT_STALE_MS, resolveTaskHeartbeatHardStaleMs, resolveTaskHeartbeatIntervalMs, resolveTaskHeartbeatStaleMs, } from '../lifecycle/task-heartbeat.js';
9
+ type RawTaskRow = Omit<typeof tasks.$inferSelect, 'security_key'>;
10
+ export type TaskRow = Omit<RawTaskRow, 'status'> & {
11
+ status: TaskStatus;
12
+ };
13
+ export interface ProviderInputRecord {
14
+ runEpoch: number;
15
+ input: string;
16
+ keyWrapSkipped: boolean;
17
+ recordedAt: string;
18
+ }
19
+ export interface ProviderInputEpochEntry {
20
+ runEpoch: number;
21
+ available: boolean;
22
+ reason?: 'absent' | 'pruned';
23
+ keyWrapSkipped?: true;
24
+ }
4
25
  export type NewTask = typeof tasks.$inferInsert;
5
- export type TaskListRow = Pick<TaskRow, 'id' | 'thread_id' | 'agent_id' | 'status' | 'parent_task_id' | 'started_at' | 'completed_at' | 'duration_ms' | 'input_tokens' | 'output_tokens' | 'cost_usd' | 'error'>;
26
+ type TaskActorKind = NonNullable<NewTask['actor_kind']>;
27
+ export type TaskKillStatus = 'terminated' | 'not_found' | 'failed' | 'not_running';
28
+ export interface TaskKillResult {
29
+ status: TaskKillStatus;
30
+ killed: boolean;
31
+ pid?: number;
32
+ error?: string;
33
+ }
34
+ export interface TaskStopRequestResult {
35
+ accepted: boolean;
36
+ status: string | null;
37
+ runEpoch: number;
38
+ alreadyRequestedAt?: string;
39
+ }
40
+ export type TaskStopOrigin = 'http' | 'cli' | 'instruction' | 'workflow' | 'internal';
41
+ export interface TaskStopRequestContext {
42
+ origin?: TaskStopOrigin;
43
+ at?: string;
44
+ callerPid?: number;
45
+ callerTaskId?: string;
46
+ }
47
+ export type TaskStopMethod = 'cooperative' | 'forced';
48
+ export interface FinalizeTaskStopOptions {
49
+ id: string;
50
+ runEpoch: number;
51
+ completedAt?: string;
52
+ method: TaskStopMethod;
53
+ error?: string;
54
+ terminalReason?: TaskTerminalReason;
55
+ durationMs?: number | null;
56
+ }
57
+ export interface FinalizeTaskForHostShutdownOptions {
58
+ id: string;
59
+ expectedRunEpoch: number;
60
+ workspaceId?: string | null;
61
+ completedAt?: string;
62
+ }
63
+ export type FinalizeTaskForHostShutdownOutcome = 'settled' | 'not_running' | 'epoch_mismatch' | 'workspace_mismatch';
64
+ export type TaskListRow = Pick<TaskRow, 'id' | 'thread_id' | 'agent_id' | 'status' | 'parent_task_id' | 'started_at' | 'completed_at' | 'duration_ms' | 'input_tokens' | 'output_tokens' | 'cost_usd' | 'error' | 'rating' | 'rated_at'> & {
65
+ terminalReason: TaskTerminalReason | null;
66
+ };
67
+ export type TaskActivityLogRow = Pick<TaskRow, 'id' | 'thread_id' | 'agent_id' | 'parent_task_id' | 'started_at' | 'completed_at'>;
68
+ export type FindTasksByThreadOptions = {
69
+ projection: 'activity-log';
70
+ };
71
+ export interface WorkflowCardRow {
72
+ taskId: string;
73
+ workflowRunId?: string;
74
+ raw?: string;
75
+ }
76
+ export interface WorkflowParentTaskRow {
77
+ id: string;
78
+ agent_id: string;
79
+ thread_id: string | null;
80
+ workspace_id: string | null;
81
+ platform: string | null;
82
+ status: string;
83
+ error: string | null;
84
+ completed_at: string | null;
85
+ duration_ms: number | null;
86
+ started_at: string;
87
+ metadata: string | null;
88
+ }
89
+ export type WorkflowParentTaskKind = 'workflow_card' | 'workflow_ui_instance';
90
+ export interface WorkflowParentTaskLookup {
91
+ workspaceId: string;
92
+ workflowRunId: string;
93
+ kind: WorkflowParentTaskKind;
94
+ }
95
+ export interface AgentProviderUsageRow {
96
+ provider: string;
97
+ inputTokens: number;
98
+ outputTokens: number;
99
+ cachedInputTokens: number;
100
+ totalTokens: number;
101
+ costUsd: number;
102
+ totalTasks: number;
103
+ unavailableTaskCount: number;
104
+ }
6
105
  export interface AgentUsageRow {
7
106
  agentId: string;
8
107
  workspaceId: string | null;
9
108
  totalTasks: number;
109
+ unavailableTaskCount?: number;
10
110
  inputTokens: number;
11
111
  outputTokens: number;
12
112
  cachedInputTokens: number;
13
113
  costUsd: number;
14
114
  totalTokens: number;
115
+ providers: AgentProviderUsageRow[];
15
116
  }
16
117
  export interface TrendRow {
17
118
  date: string;
18
119
  agentId: string;
120
+ unavailableTaskCount?: number;
19
121
  inputTokens: number;
20
122
  outputTokens: number;
21
123
  cachedInputTokens: number;
@@ -25,6 +127,7 @@ export interface TrendRow {
25
127
  export interface ProviderUsageRow {
26
128
  provider: string;
27
129
  totalTasks: number;
130
+ unavailableTaskCount?: number;
28
131
  inputTokens: number;
29
132
  outputTokens: number;
30
133
  cachedInputTokens: number;
@@ -37,6 +140,7 @@ export interface ModelUsageRow {
37
140
  model: string;
38
141
  provider: string;
39
142
  totalTasks: number;
143
+ unavailableTaskCount?: number;
40
144
  inputTokens: number;
41
145
  outputTokens: number;
42
146
  cachedInputTokens: number;
@@ -52,20 +156,80 @@ export interface ReportTaskRow {
52
156
  status: string;
53
157
  error: string | null;
54
158
  exitCode: number | null;
159
+ terminalReason: TaskTerminalReason | null;
160
+ }
161
+ export interface DelegationEdge {
162
+ callerAgentId: string | null;
163
+ agentId: string;
164
+ taskCount: number;
165
+ totalTokens: number;
166
+ outputTokens: number;
167
+ }
168
+ export interface DelegationMatrixResult {
169
+ edges: DelegationEdge[];
170
+ truncated: boolean;
171
+ }
172
+ export type TaskEvidenceRow = Pick<TaskRow, 'id' | 'agent_id' | 'status' | 'prompt' | 'started_at' | 'completed_at' | 'thread_id'> & {
173
+ terminalReason: TaskTerminalReason | null;
174
+ };
175
+ export interface ThreadChainTurn {
176
+ id: string;
177
+ agentId: string;
178
+ status: string;
179
+ prompt: string;
180
+ startedAt: string;
181
+ completedAt: string | null;
55
182
  }
183
+ export interface ThreadChain {
184
+ threadId: string;
185
+ targetAgentTurnCount: number;
186
+ turns: ThreadChainTurn[];
187
+ }
188
+ export declare const HOST_SHUTDOWN_TERMINAL_ERROR = "Stopped by app shutdown";
189
+ type TaskUsageColumns = Pick<TaskRow, 'input_tokens' | 'output_tokens' | 'cached_input_tokens' | 'cost_usd'>;
190
+ export declare function mergeTerminalReason(metadataJson: string | null | undefined, reason: TaskTerminalReason): string;
191
+ export declare function hasRecordedUsage(task: TaskUsageColumns): boolean;
56
192
  export declare const PID_NULL_REAP_GRACE_MS: number;
193
+ export declare const PENDING_ADOPT_GRACE_MS: number;
194
+ export declare const DEFAULT_TASK_REAPER_TICK_INTERVAL_MS: number;
195
+ export interface ReapOrphanedTasksOptions {
196
+ tickIntervalMs?: number;
197
+ }
57
198
  export declare class TaskRepository extends BaseSqliteRepository {
58
199
  private readonly dbPath?;
200
+ private readonly clock;
201
+ private readonly taskLogRepository;
202
+ private lastReaperTickAt?;
59
203
  private readonly pidNullObservedSince;
60
204
  constructor(opts?: {
61
205
  dbPath?: string;
62
206
  dbRoot?: string;
207
+ clock?: () => number;
63
208
  });
64
209
  resolveDbPath(): string;
65
210
  private openHandle;
211
+ heartbeatTask(opts: {
212
+ id: string;
213
+ runEpoch: number;
214
+ }): boolean;
215
+ requestTaskStop(opts: {
216
+ id: string;
217
+ requestedAt: string;
218
+ origin?: TaskStopOrigin;
219
+ callerPid?: number;
220
+ callerTaskId?: string;
221
+ }): TaskStopRequestResult;
222
+ private requestTaskStopForInstruction;
223
+ finalizeTaskStop(opts: FinalizeTaskStopOptions): boolean;
224
+ finalizeTaskForHostShutdown(opts: FinalizeTaskForHostShutdownOptions): FinalizeTaskForHostShutdownOutcome;
225
+ stopTask(id: string, options?: StopTaskOptions): Promise<StopTaskResult>;
226
+ stopTaskGenerationForInstruction(options: StopTaskGenerationForInstructionOptions): Promise<StopTaskResult>;
66
227
  startTask(opts: {
67
228
  id: string;
68
229
  agentId: string;
230
+ actorKind?: TaskActorKind | null;
231
+ actorId?: string | null;
232
+ userId?: string | null;
69
233
  prompt: string;
70
234
  mode: string;
71
235
  status: string;
@@ -77,13 +241,38 @@ export declare class TaskRepository extends BaseSqliteRepository {
77
241
  command?: string | null;
78
242
  metadata?: string | null;
79
243
  workspaceId?: string | null;
244
+ cwd?: string | null;
245
+ projectId?: string | null;
80
246
  platform?: string | null;
81
247
  crewxVersion?: string | null;
82
248
  threadId?: string | null;
83
249
  model?: string | null;
84
250
  renderedPrompt?: string | null;
251
+ securityKey?: string | null;
85
252
  codingAgentCommand?: string | null;
86
253
  }): void;
254
+ recordTaskPid(opts: {
255
+ id: string;
256
+ runEpoch: number;
257
+ pid: number;
258
+ }): boolean;
259
+ updateTaskOwnership(opts: {
260
+ id: string;
261
+ runEpoch: number;
262
+ ownership: 'runner' | 'caller';
263
+ providerPid?: number | null;
264
+ runtime?: {
265
+ model?: string | null;
266
+ renderedPrompt?: string | null;
267
+ securityKey?: string | null;
268
+ codingAgentCommand?: string | null;
269
+ metadata?: Record<string, unknown>;
270
+ };
271
+ }): boolean;
272
+ adoptPendingTask(id: string): boolean;
273
+ failPendingTask(id: string, error: string, completedAt?: string): boolean;
274
+ stopPendingTask(id: string, error?: string, completedAt?: string, stopRequest?: TaskStopRequestContext): boolean;
275
+ listTasksByProjectId(projectId: string): TaskRow[];
87
276
  finishTask(opts: {
88
277
  id: string;
89
278
  status: string;
@@ -98,20 +287,46 @@ export declare class TaskRepository extends BaseSqliteRepository {
98
287
  costUsd?: number;
99
288
  model?: string | null;
100
289
  runEpoch?: number | null;
290
+ partialResultRecovered?: boolean;
291
+ }): void;
292
+ updateTaskLifecycle(opts: {
293
+ id: string;
294
+ status: TaskStatus;
295
+ error: string | null;
296
+ completedAt: string | null;
297
+ durationMs: number | null;
298
+ workspaceId: string;
299
+ terminalReason?: TaskTerminalReason;
101
300
  }): void;
102
301
  appendLog(taskId: string, entry: {
103
302
  timestamp: string;
104
303
  level: string;
105
304
  message: string;
106
305
  }): void;
306
+ appendLogs(taskId: string, entries: readonly TaskLogEntry[]): void;
307
+ readLogs(taskId: string): TaskLogReadResult | undefined;
308
+ readLogsTail(taskId: string, limit: number): TaskLogReadResult | undefined;
309
+ getLogState(taskId: string): TaskLogState | undefined;
107
310
  getRunningTasks(): TaskRow[];
311
+ getActiveTasks(): TaskRow[];
108
312
  getAllTasks(): TaskRow[];
313
+ readTaskSecurityKey(id: string): string | null;
314
+ recordProviderInput(opts: {
315
+ id: string;
316
+ runEpoch: number;
317
+ input: string;
318
+ keyWrapSkipped: boolean;
319
+ interceptedRequest?: boolean;
320
+ recordedAt?: string;
321
+ }): boolean;
322
+ listProviderInputEpochs(id: string, opts?: {
323
+ archivedRunEpochs?: ReadonlySet<number>;
324
+ }): ProviderInputEpochEntry[];
325
+ readProviderInput(id: string, runEpoch: number): ProviderInputRecord | undefined;
109
326
  getTask(id: string): TaskRow | undefined;
110
- killTask(id: string): {
111
- killed: boolean;
112
- pid?: number;
113
- };
114
- reapOrphanedTasks(): number;
327
+ killTask(id: string): Promise<TaskKillResult>;
328
+ reapOrphanedTasks(options?: ReapOrphanedTasksOptions): number;
329
+ reapRunningWorkflowTasks(graceMs?: number): number;
115
330
  findTaskStatus(taskId: string, workspaceId?: string): TaskRow | undefined;
116
331
  findChildTasks(parentTaskId: string, workspaceId?: string): TaskRow[];
117
332
  getWorkspaceUsageSummary(workspaceId?: string): Array<{
@@ -126,7 +341,14 @@ export declare class TaskRepository extends BaseSqliteRepository {
126
341
  outputTokens: number;
127
342
  costUsd: number;
128
343
  };
344
+ findTasksByThread(threadId: string, workspaceId: string | undefined, options: FindTasksByThreadOptions): TaskActivityLogRow[];
129
345
  findTasksByThread(threadId: string, workspaceId?: string): TaskRow[];
346
+ private parseWorkflowCardMetadata;
347
+ private extractThreadIdFromCommand;
348
+ findRunningWorkflowParentTasks(): WorkflowParentTaskRow[];
349
+ findWorkflowParentTasksByWorkspace(workspaceId: string): WorkflowParentTaskRow[];
350
+ findWorkflowParentTask(opts: WorkflowParentTaskLookup): WorkflowParentTaskRow | undefined;
351
+ batchFetchWorkflowCards(threadIds: string[], workspaceId?: string): Map<string, WorkflowCardRow>;
130
352
  findAllTasks(params: {
131
353
  workspaceId?: string;
132
354
  agentId?: string;
@@ -147,9 +369,86 @@ export declare class TaskRepository extends BaseSqliteRepository {
147
369
  getAgentUsage(from: string, to: string, workspace?: string): AgentUsageRow[];
148
370
  getAgentUsageTrendRaw(from: string, to: string, workspace?: string): TrendRow[];
149
371
  findTaskForStop(taskId: string, workspaceId: string): TaskRow | undefined;
150
- markTaskFailed(taskId: string, error: string, workspaceId?: string): void;
372
+ findLatestTaskByMetadata(opts: {
373
+ agentId: string;
374
+ workspaceId: string;
375
+ metaKey: string;
376
+ metaValue: string;
377
+ }): {
378
+ id: string;
379
+ thread_id: string | null;
380
+ status: string;
381
+ result: string | null;
382
+ error: string | null;
383
+ started_at: string;
384
+ completed_at: string | null;
385
+ metadata: string | null;
386
+ } | null;
387
+ markTaskFailed(taskId: string, error: string, workspaceId?: string, status?: TaskStatus, terminalReason?: TaskTerminalReason): void;
151
388
  findTasksByPromptHint(hint: string, workspaceId?: string): TaskRow[];
152
389
  getProviderUsage(from: string, to: string, workspace?: string): ProviderUsageRow[];
153
390
  getModelUsage(from: string, to: string, workspace?: string): ModelUsageRow[];
154
391
  getTasksForReport(from: string, to: string, workspace?: string): ReportTaskRow[];
392
+ getDelegationMatrix(from: string, to: string, workspace?: string): DelegationMatrixResult;
393
+ findTaskEvidence(params: {
394
+ workspaceId?: string;
395
+ agents?: string[];
396
+ statuses?: string[];
397
+ from?: string;
398
+ to?: string;
399
+ limit?: number;
400
+ order?: 'ASC' | 'DESC';
401
+ }): TaskEvidenceRow[];
402
+ findThreadChains(params: {
403
+ targetAgentId: string;
404
+ workspaceId?: string;
405
+ from?: string;
406
+ to?: string;
407
+ maxThreads?: number;
408
+ maxTurnsPerThread?: number;
409
+ }): ThreadChain[];
410
+ }
411
+ export declare const TASK_RATINGS: readonly ["up", "down"];
412
+ export type TaskRating = (typeof TASK_RATINGS)[number];
413
+ export declare const RATED_TASK_EXCERPT_MAX_CHARS = 1000;
414
+ export declare const RATED_TASK_LIST_MAX_LIMIT = 200;
415
+ export type TaskRatingErrorCode = 'TASK_NOT_FOUND' | 'TASK_RATING_NOT_TERMINAL';
416
+ export declare class TaskRatingError extends RepositoryError {
417
+ readonly stableCode: TaskRatingErrorCode;
418
+ readonly taskId: string;
419
+ constructor(stableCode: TaskRatingErrorCode, taskId: string);
420
+ }
421
+ export interface SetTaskRatingInput {
422
+ workspaceId: string;
423
+ taskId: string;
424
+ rating: TaskRating | null;
425
+ now?: string;
426
+ }
427
+ export interface SetTaskRatingResult {
428
+ taskId: string;
429
+ rating: TaskRating | null;
430
+ ratedAt: string | null;
431
+ changed: boolean;
432
+ }
433
+ export declare function setTaskRating(db: DrizzleDb, input: SetTaskRatingInput): SetTaskRatingResult;
434
+ export interface ListRatedTasksInput {
435
+ workspaceId: string;
436
+ agentId?: string;
437
+ sinceIso?: string;
438
+ limit: number;
439
+ }
440
+ export interface RatedTaskRow {
441
+ taskId: string;
442
+ agentId: string;
443
+ threadId: string | null;
444
+ status: TaskStatus;
445
+ rating: TaskRating;
446
+ ratedAt: string;
447
+ promptExcerpt: string | null;
448
+ resultExcerpt: string | null;
155
449
  }
450
+ export declare function buildRatedTasksQuery(input: ListRatedTasksInput): import("drizzle-orm").SQL<unknown>;
451
+ export declare function listRatedTasks(db: DrizzleDb, input: ListRatedTasksInput): RatedTaskRow[];
452
+ export type CountRatedTasksInput = Omit<ListRatedTasksInput, 'limit'>;
453
+ export declare function buildRatedTasksCountQuery(input: CountRatedTasksInput): import("drizzle-orm").SQL<unknown>;
454
+ export declare function countRatedTasks(db: DrizzleDb, input: CountRatedTasksInput): number;
@@ -0,0 +1,193 @@
1
+ import { BaseSqliteRepository } from './base-sqlite-repository.js';
2
+ import { RepositoryError } from './errors.js';
3
+ import type { ThreadActorType, ThreadEvent, ThreadHighlight, ThreadHighlightKind, ThreadHighlightRun, ThreadHighlightSource } from '../schema/index.js';
4
+ import type { ThreadPriority, ThreadState } from './thread-title.types.js';
5
+ export interface ThreadActorInput {
6
+ actorType?: ThreadActorType;
7
+ actorId?: string | null;
8
+ actor?: {
9
+ actorType?: ThreadActorType;
10
+ actorId?: string | null;
11
+ };
12
+ }
13
+ export interface ThreadSnapshotMutationInput extends ThreadActorInput {
14
+ threadId: string;
15
+ workspaceId?: string | null;
16
+ title?: string | null;
17
+ priority?: ThreadPriority | null;
18
+ state?: ThreadState | null;
19
+ taskId?: string | null;
20
+ }
21
+ export interface ThreadSnapshot {
22
+ threadId: string;
23
+ workspaceId: string | null;
24
+ title: string | null;
25
+ priority: ThreadPriority | null;
26
+ state: ThreadState | null;
27
+ metadata: string | null;
28
+ titleLocked: boolean;
29
+ updatedAt: string;
30
+ }
31
+ export interface ThreadTimelineOptions {
32
+ beforeSeq?: number;
33
+ afterSeq?: number;
34
+ limit?: number;
35
+ }
36
+ export interface ThreadTimelineQuery extends ThreadTimelineOptions {
37
+ threadId: string;
38
+ workspaceId: string;
39
+ }
40
+ export interface ThreadTimeline {
41
+ items: ThreadEvent[];
42
+ latestSeq: number;
43
+ hasMoreOlder: boolean;
44
+ }
45
+ export interface CreateThreadHighlightInput extends ThreadActorInput {
46
+ threadId: string;
47
+ workspaceId: string;
48
+ source?: ThreadHighlightSource;
49
+ kind: ThreadHighlightKind;
50
+ text: string;
51
+ taskId?: string;
52
+ coversFromTaskId?: string;
53
+ coversToTaskId?: string;
54
+ fromTaskId?: string;
55
+ toTaskId?: string;
56
+ agentId?: string | null;
57
+ sourceTaskId?: string | null;
58
+ detectorVersion?: string | null;
59
+ contentFingerprint?: string | null;
60
+ idempotencyKey?: string;
61
+ id?: string;
62
+ }
63
+ export interface UpdateThreadHighlightInput extends ThreadActorInput {
64
+ threadId: string;
65
+ workspaceId: string;
66
+ highlightId: string;
67
+ expectedRevision: number;
68
+ text?: string;
69
+ kind?: ThreadHighlightKind;
70
+ coversFromTaskId?: string;
71
+ coversToTaskId?: string;
72
+ }
73
+ export interface DismissThreadHighlightInput extends ThreadActorInput {
74
+ threadId: string;
75
+ workspaceId: string;
76
+ highlightId: string;
77
+ expectedRevision: number;
78
+ }
79
+ export interface ListActiveHighlightsOptions {
80
+ taskId?: string;
81
+ coversFromTaskId?: string;
82
+ coversToTaskId?: string;
83
+ }
84
+ export interface ThreadHighlightEligibleTurn {
85
+ taskId: string;
86
+ prompt: string;
87
+ result: string;
88
+ status: string;
89
+ startedAt: string;
90
+ completedAt: string | null;
91
+ }
92
+ export interface CreateThreadHighlightRegenerationRunInput extends ThreadActorInput {
93
+ threadId: string;
94
+ workspaceId: string;
95
+ requestId: string;
96
+ detectorVersion: string;
97
+ runId?: string;
98
+ }
99
+ export interface CreateThreadHighlightRegenerationRunResult {
100
+ run: ThreadHighlightRun;
101
+ created: boolean;
102
+ }
103
+ export interface FailThreadHighlightRegenerationRunInput extends ThreadActorInput {
104
+ runId: string;
105
+ workspaceId?: string;
106
+ errorCode: string;
107
+ }
108
+ export interface ThreadHighlightRegenerationCandidate {
109
+ kind: ThreadHighlightKind;
110
+ text: string;
111
+ anchorTaskId: string;
112
+ coversFromTaskId: string;
113
+ coversToTaskId: string;
114
+ contentFingerprint?: string;
115
+ }
116
+ export interface CompleteThreadHighlightRegenerationInput extends ThreadActorInput {
117
+ runId: string;
118
+ threadId: string;
119
+ workspaceId: string;
120
+ detectorVersion: string;
121
+ agentId?: string | null;
122
+ candidates: readonly ThreadHighlightRegenerationCandidate[];
123
+ }
124
+ export interface CompleteThreadHighlightRegenerationResult {
125
+ run: ThreadHighlightRun;
126
+ deletedCount: number;
127
+ createdCount: number;
128
+ previousAutoCount: number;
129
+ newAutoCount: number;
130
+ }
131
+ export declare const THREAD_HIGHLIGHT_DELETION_REASON_REGENERATION_REPLACED: "regeneration_replaced";
132
+ export type ThreadHighlightDeletionReason = typeof THREAD_HIGHLIGHT_DELETION_REASON_REGENERATION_REPLACED;
133
+ export declare const THREAD_HIGHLIGHT_REGENERATION_NO_ELIGIBLE_TURNS: "THREAD_HIGHLIGHT_REGENERATION_NO_ELIGIBLE_TURNS";
134
+ export declare const THREAD_HIGHLIGHT_REGENERATION_INTERRUPTED: "THREAD_HIGHLIGHT_REGENERATION_INTERRUPTED";
135
+ export declare const THREAD_HIGHLIGHT_REGENERATION_DETECTION_FAILED: "THREAD_HIGHLIGHT_REGENERATION_DETECTION_FAILED";
136
+ export declare const THREAD_HIGHLIGHT_REGENERATION_COMMIT_FAILED: "THREAD_HIGHLIGHT_REGENERATION_COMMIT_FAILED";
137
+ export type ThreadHighlightRegenerationErrorCode = typeof THREAD_HIGHLIGHT_REGENERATION_NO_ELIGIBLE_TURNS | typeof THREAD_HIGHLIGHT_REGENERATION_INTERRUPTED | typeof THREAD_HIGHLIGHT_REGENERATION_DETECTION_FAILED | typeof THREAD_HIGHLIGHT_REGENERATION_COMMIT_FAILED | string;
138
+ export declare class ThreadHistoryConflictError extends RepositoryError {
139
+ readonly threadId: string;
140
+ readonly highlightId: string;
141
+ readonly expectedRevision: number;
142
+ readonly currentRevision: number;
143
+ constructor(threadId: string, highlightId: string, expectedRevision: number, currentRevision: number);
144
+ }
145
+ export declare class ThreadHighlightConflictError extends ThreadHistoryConflictError {
146
+ }
147
+ export declare class ThreadHighlightRegenerationConflictError extends RepositoryError {
148
+ readonly stableCode: "THREAD_HIGHLIGHT_REGENERATION_IN_PROGRESS";
149
+ readonly run: ThreadHighlightRun;
150
+ constructor(run: ThreadHighlightRun);
151
+ }
152
+ export declare class ThreadHistoryRepository extends BaseSqliteRepository {
153
+ private readonly dbPath?;
154
+ constructor(opts?: {
155
+ dbPath?: string;
156
+ dbRoot?: string;
157
+ });
158
+ resolveDbPath(): string;
159
+ private openHandle;
160
+ private findThread;
161
+ private findRegenerationRun;
162
+ resolveWorkspaceId(threadId: string): string | null;
163
+ getSnapshot(threadId: string, workspaceId?: string | null): ThreadSnapshot | null;
164
+ updateSnapshot(input: ThreadSnapshotMutationInput): ThreadSnapshot;
165
+ mutateSnapshot(input: ThreadSnapshotMutationInput): ThreadSnapshot;
166
+ updateThreadSnapshot(input: ThreadSnapshotMutationInput): ThreadSnapshot;
167
+ getLatestSeq(threadId: string, workspaceId?: string | null): number | null;
168
+ listCompletedThreadHighlightTurns(threadId: string, workspaceId: string): ThreadHighlightEligibleTurn[] | null;
169
+ createHighlightRegenerationRun(input: CreateThreadHighlightRegenerationRunInput): CreateThreadHighlightRegenerationRunResult;
170
+ beginHighlightRegenerationRun(input: CreateThreadHighlightRegenerationRunInput): CreateThreadHighlightRegenerationRunResult;
171
+ queueHighlightRegenerationRun(input: CreateThreadHighlightRegenerationRunInput): CreateThreadHighlightRegenerationRunResult;
172
+ getHighlightRegenerationRun(runId: string, workspaceId?: string): ThreadHighlightRun | null;
173
+ getHighlightRegenerationRunByRequest(threadId: string, workspaceId: string, requestId: string): ThreadHighlightRun | null;
174
+ findHighlightRegenerationRun(threadId: string, workspaceId: string, requestId: string): ThreadHighlightRun | null;
175
+ startHighlightRegenerationRun(runId: string, workspaceId?: string): ThreadHighlightRun;
176
+ startHighlightRegeneration(runId: string, workspaceId?: string): ThreadHighlightRun;
177
+ failHighlightRegenerationRun(input: FailThreadHighlightRegenerationRunInput): ThreadHighlightRun;
178
+ failHighlightRegeneration(input: FailThreadHighlightRegenerationRunInput): ThreadHighlightRun;
179
+ recoverInterruptedHighlightRegenerationRuns(errorCode?: string): number;
180
+ completeHighlightRegenerationRun(input: CompleteThreadHighlightRegenerationInput): CompleteThreadHighlightRegenerationResult;
181
+ completeHighlightRegeneration(input: CompleteThreadHighlightRegenerationInput): CompleteThreadHighlightRegenerationResult;
182
+ replaceAutoHighlightsAtomically(input: CompleteThreadHighlightRegenerationInput): CompleteThreadHighlightRegenerationResult;
183
+ listTimeline(query: ThreadTimelineQuery): ThreadTimeline | null;
184
+ listTimeline(threadId: string, workspaceId: string, options?: ThreadTimelineOptions): ThreadTimeline | null;
185
+ listEvents(threadId: string, workspaceId: string, options?: ThreadTimelineOptions): ThreadTimeline | null;
186
+ getTimeline(threadId: string, workspaceId: string, options?: ThreadTimelineOptions): ThreadTimeline | null;
187
+ createHighlight(input: CreateThreadHighlightInput): ThreadHighlight;
188
+ updateHighlight(input: UpdateThreadHighlightInput): ThreadHighlight;
189
+ dismissHighlight(input: DismissThreadHighlightInput): ThreadHighlight;
190
+ listActiveHighlights(threadId: string, workspaceId: string, options?: ListActiveHighlightsOptions): ThreadHighlight[] | null;
191
+ listHighlights(threadId: string, workspaceId: string, options?: ListActiveHighlightsOptions): ThreadHighlight[] | null;
192
+ getActiveHighlights(threadId: string, workspaceId: string, options?: ListActiveHighlightsOptions): ThreadHighlight[] | null;
193
+ }
@@ -0,0 +1,27 @@
1
+ export type ThreadOriginKind = 'human' | 'agent' | 'system';
2
+ export interface ThreadOriginRow {
3
+ origin: 'direct' | 'delegated';
4
+ delegatedByAgentId: string | null;
5
+ }
6
+ export interface RawThreadOriginRow {
7
+ task_id: string;
8
+ thread_id: string;
9
+ caller_agent_id: string | null;
10
+ parent_task_id: string | null;
11
+ schedule_id: unknown;
12
+ platform: string | null;
13
+ parent_thread_id: string | null;
14
+ parent_agent_id: string | null;
15
+ }
16
+ export interface RawThreadCreatorPointerRow {
17
+ thread_id: string;
18
+ created_by_kind: string | null;
19
+ created_by_id: string | null;
20
+ created_by_task_id: string | null;
21
+ creator_task_id: string | null;
22
+ creator_actor_kind: string | null;
23
+ creator_actor_id: string | null;
24
+ creator_pointer_unverified: number;
25
+ }
26
+ export declare function lineageThreadOrigin(row: RawThreadOriginRow): ThreadOriginRow;
27
+ export declare function resolveThreadOrigin(row: RawThreadCreatorPointerRow, pointerLineage?: RawThreadOriginRow, fallbackLineage?: RawThreadOriginRow): ThreadOriginRow | undefined;
@@ -0,0 +1,29 @@
1
+ export declare const THREAD_PRIORITIES: readonly ["urgent", "high", "medium", "low"];
2
+ export type ThreadPriority = (typeof THREAD_PRIORITIES)[number];
3
+ export declare const BUILTIN_THREAD_STATES: readonly ["investigating", "in-progress", "in-review", "on-hold", "done"];
4
+ export type BuiltinThreadState = (typeof BUILTIN_THREAD_STATES)[number];
5
+ export type StableThreadState = BuiltinThreadState | `c_${string}`;
6
+ export type LegacyThreadState = `custom:${string}`;
7
+ export type ThreadState = StableThreadState | LegacyThreadState;
8
+ export interface ThreadTitleMeta {
9
+ priority?: ThreadPriority;
10
+ state?: ThreadState;
11
+ }
12
+ export interface ThreadTitlePatch {
13
+ priority?: ThreadPriority | null;
14
+ state?: ThreadState | null;
15
+ }
16
+ export declare function isThreadPriority(value: unknown): value is ThreadPriority;
17
+ export declare function isThreadState(value: unknown): value is ThreadState;
18
+ export declare function customStateLabel(state: ThreadState): string | undefined;
19
+ export declare function hasThreadTitleKey(metadataJson: string | null | undefined): boolean;
20
+ export declare function readThreadTitleMeta(metadataJson: string | null | undefined): ThreadTitleMeta;
21
+ export declare function mergeThreadTitleMeta(metadataJson: string | null | undefined, patch: ThreadTitlePatch): string | null;
22
+ export declare function threadTitleSearchHaystack(meta: ThreadTitleMeta, labelNames?: ReadonlyMap<string, string>): string;
23
+ export interface ThreadTitleFilter {
24
+ values: Set<string>;
25
+ includeNone: boolean;
26
+ }
27
+ export declare function parseThreadPriorityFilter(raw: string | undefined): ThreadTitleFilter | undefined;
28
+ export declare function parseThreadStateFilter(raw: string | undefined): ThreadTitleFilter | undefined;
29
+ export declare function matchesThreadTitleFilter(current: string | undefined, filter: ThreadTitleFilter | undefined): boolean;