Entities.vala 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. using InvercargillSql.Orm;
  2. namespace ClankerSaddle.Data {
  3. /**
  4. * A software project worked on by saddle agents, stored in the
  5. * `projects` table.
  6. */
  7. public class Project : Object {
  8. public int64 id { get; set; }
  9. public string name { get; set; default = ""; }
  10. public string git_url { get; set; default = ""; }
  11. public string default_branch { get; set; default = "main"; }
  12. public string? summary { get; set; default = null; }
  13. public DateTime? created_at { get; set; default = null; }
  14. public static void entity_mapping(EntityMapperBuilder<Project> cfg) {
  15. cfg.table("projects")
  16. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  17. .column<string>("name", o => o.name, (o, v) => o.name = v)
  18. .column<string>("git_url", o => o.git_url, (o, v) => o.git_url = v)
  19. .column<string>("default_branch", o => o.default_branch, (o, v) => o.default_branch = v)
  20. .column<string>("summary", o => o.summary, (o, v) => o.summary = v)
  21. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  22. }
  23. }
  24. /**
  25. * A directed relationship between two projects ('co-developed' or
  26. * 'reference'), stored in the `project_links` table.
  27. */
  28. public class ProjectLink : Object {
  29. public int64 id { get; set; }
  30. public int64 parent_project_id { get; set; }
  31. public int64 linked_project_id { get; set; }
  32. public string relationship { get; set; default = "reference"; }
  33. public static void entity_mapping(EntityMapperBuilder<ProjectLink> cfg) {
  34. cfg.table("project_links")
  35. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  36. .column<int64?>("parent_project_id", o => o.parent_project_id, (o, v) => o.parent_project_id = v)
  37. .column<int64?>("linked_project_id", o => o.linked_project_id, (o, v) => o.linked_project_id = v)
  38. .column<string>("relationship", o => o.relationship, (o, v) => o.relationship = v);
  39. }
  40. }
  41. /**
  42. * A unit of work for a saddle agent: created in {@link
  43. * TaskService.STATUS_DRAFT}, queued by its creator (human or goal
  44. * agent), dispatched to a saddle, worked, possibly blocked on
  45. * questions, and eventually done or failed (completion is
  46. * agent-only). The plan-12 shape: goals own the task graph — a task
  47. * links its {@link goal_id}, runs as a plain worker or the goal
  48. * agent itself ({@link kind}), carries a work {@link mode} and its
  49. * {@link creator}, and human tasks may carry an auto-enqueue
  50. * predecessor ({@link enqueue_after_task_id}). Stored in the
  51. * `tasks` table. Named `TaskEntity` (not `Task`) to stay clear of
  52. * `GLib.Task` in files that import Gio transitively.
  53. */
  54. public class TaskEntity : Object {
  55. public int64 id { get; set; }
  56. public int64 project_id { get; set; }
  57. public string title { get; set; default = ""; }
  58. public string? description { get; set; default = null; }
  59. public string status { get; set; default = "draft"; }
  60. public int64 priority { get; set; default = 5; }
  61. public string? working_branch { get; set; default = null; }
  62. public string? summary { get; set; default = null; }
  63. public string? task_branch { get; set; default = null; }
  64. public string? branch_from { get; set; default = null; }
  65. public DateTime? created_at { get; set; default = null; }
  66. public DateTime? started_at { get; set; default = null; }
  67. public DateTime? completed_at { get; set; default = null; }
  68. public DateTime? suspended_at { get; set; default = null; }
  69. /** The goal this task belongs to (0 = standalone). */
  70. public int64 goal_id { get; set; default = 0; }
  71. /** "task" (a worker) or "goal_run" (the goal agent's own run). */
  72. public string kind { get; set; default = "task"; }
  73. /** implement / investigate / review / test (orchestrate for goal runs). */
  74. public string mode { get; set; default = "implement"; }
  75. /** "human" or "goal" — enqueueing is creator-only. */
  76. public string creator { get; set; default = "human"; }
  77. /** Human-created tasks only: auto-enqueue when this predecessor is done. */
  78. public int64 enqueue_after_task_id { get; set; default = 0; }
  79. public static void entity_mapping(EntityMapperBuilder<TaskEntity> cfg) {
  80. cfg.table("tasks")
  81. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  82. .column<int64?>("project_id", o => o.project_id, (o, v) => o.project_id = v)
  83. .column<string>("title", o => o.title, (o, v) => o.title = v)
  84. .column<string>("description", o => o.description, (o, v) => o.description = v)
  85. .column<string>("status", o => o.status, (o, v) => o.status = v)
  86. .column<int64?>("priority", o => o.priority, (o, v) => o.priority = v)
  87. .column<string>("working_branch", o => o.working_branch, (o, v) => o.working_branch = v)
  88. .column<string>("summary", o => o.summary, (o, v) => o.summary = v)
  89. .column<string>("task_branch", o => o.task_branch, (o, v) => o.task_branch = v)
  90. .column<string>("branch_from", o => o.branch_from, (o, v) => o.branch_from = v)
  91. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v)
  92. .column<DateTime?>("started_at", o => o.started_at, (o, v) => o.started_at = v)
  93. .column<DateTime?>("completed_at", o => o.completed_at, (o, v) => o.completed_at = v)
  94. .column<DateTime?>("suspended_at", o => o.suspended_at, (o, v) => o.suspended_at = v)
  95. .column<int64?>("goal_id", o => o.goal_id, (o, v) => o.goal_id = v ?? 0)
  96. .column<string>("kind", o => o.kind, (o, v) => o.kind = v)
  97. .column<string>("mode", o => o.mode, (o, v) => o.mode = v)
  98. .column<string>("creator", o => o.creator, (o, v) => o.creator = v)
  99. .column<int64?>("enqueue_after_task_id", o => o.enqueue_after_task_id, (o, v) => o.enqueue_after_task_id = v ?? 0);
  100. }
  101. }
  102. /**
  103. * One LLM-reported progress line on a task (`saddle progress-update`),
  104. * stored in the `task_progress` table.
  105. */
  106. public class TaskProgress : Object {
  107. public int64 id { get; set; }
  108. public int64 task_id { get; set; }
  109. public string summary { get; set; default = ""; }
  110. public DateTime? created_at { get; set; default = null; }
  111. public static void entity_mapping(EntityMapperBuilder<TaskProgress> cfg) {
  112. cfg.table("task_progress")
  113. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  114. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v)
  115. .column<string>("summary", o => o.summary, (o, v) => o.summary = v)
  116. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  117. }
  118. }
  119. /** A remark on a task, authored either by a human or by the agent ('agent'). */
  120. public class TaskComment : Object {
  121. public int64 id { get; set; }
  122. public int64 task_id { get; set; }
  123. public string author { get; set; default = "agent"; }
  124. public string body { get; set; default = ""; }
  125. public string? quote { get; set; default = null; }
  126. public DateTime? created_at { get; set; default = null; }
  127. public static void entity_mapping(EntityMapperBuilder<TaskComment> cfg) {
  128. cfg.table("task_comments")
  129. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  130. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v)
  131. .column<string>("author", o => o.author, (o, v) => o.author = v)
  132. .column<string>("body", o => o.body, (o, v) => o.body = v)
  133. .column<string>("quote", o => o.quote, (o, v) => o.quote = v)
  134. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  135. }
  136. }
  137. /**
  138. * A blocking prompt raised by an agent mid-task — a multiple-choice
  139. * {@link block_type} question, a request for comment or a review
  140. * request — answered by a human in the web UI; the answer is collected
  141. * by the saddle on its next
  142. * {@link ClankerSaddle.Api.SaddlePollEndpoint} poll.
  143. */
  144. public class TaskBlock : Object {
  145. public int64 id { get; set; }
  146. public int64 task_id { get; set; }
  147. public string question { get; set; default = ""; }
  148. public string? answer { get; set; default = null; }
  149. public string block_type { get; set; default = "question"; }
  150. public string? options { get; set; default = null; }
  151. public string? body { get; set; default = null; }
  152. public DateTime? answered_at { get; set; default = null; }
  153. public string? answered_by { get; set; default = null; }
  154. public DateTime? created_at { get; set; default = null; }
  155. public static void entity_mapping(EntityMapperBuilder<TaskBlock> cfg) {
  156. cfg.table("task_blocks")
  157. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  158. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v)
  159. .column<string>("question", o => o.question, (o, v) => o.question = v)
  160. .column<string>("answer", o => o.answer, (o, v) => o.answer = v)
  161. .column<string>("type", o => o.block_type, (o, v) => o.block_type = v)
  162. .column<string>("options", o => o.options, (o, v) => o.options = v)
  163. .column<string>("body", o => o.body, (o, v) => o.body = v)
  164. .column<DateTime?>("answered_at", o => o.answered_at, (o, v) => o.answered_at = v)
  165. .column<string>("answered_by", o => o.answered_by, (o, v) => o.answered_by = v)
  166. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  167. }
  168. }
  169. /**
  170. * A saddle container registered with this app: one daemon managing one
  171. * bash session at a time, controlled over HTTP at {@link host}. The
  172. * per-saddle token ({@link token}, plan 10) authorises every
  173. * daemon→web call; removing the row revokes it.
  174. */
  175. public class Saddle : Object {
  176. public int64 id { get; set; }
  177. public string name { get; set; default = ""; }
  178. public string? container_id { get; set; default = null; }
  179. public string host { get; set; default = ""; }
  180. public string status { get; set; default = "offline"; }
  181. public int64 current_task_id { get; set; default = 0; }
  182. public DateTime? allocated_at { get; set; default = null; }
  183. public string? git_name { get; set; default = null; }
  184. public string? git_email { get; set; default = null; }
  185. public string? ssh_public_key { get; set; default = null; }
  186. public string? token { get; set; default = null; }
  187. public static void entity_mapping(EntityMapperBuilder<Saddle> cfg) {
  188. cfg.table("saddles")
  189. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  190. .column<string>("name", o => o.name, (o, v) => o.name = v)
  191. .column<string>("container_id", o => o.container_id, (o, v) => o.container_id = v)
  192. .column<string>("host", o => o.host, (o, v) => o.host = v)
  193. .column<string>("status", o => o.status, (o, v) => o.status = v)
  194. .column<int64?>("current_task_id", o => o.current_task_id, (o, v) => o.current_task_id = v)
  195. .column<DateTime?>("allocated_at", o => o.allocated_at, (o, v) => o.allocated_at = v)
  196. .column<string>("git_name", o => o.git_name, (o, v) => o.git_name = v)
  197. .column<string>("git_email", o => o.git_email, (o, v) => o.git_email = v)
  198. .column<string>("ssh_public_key", o => o.ssh_public_key, (o, v) => o.ssh_public_key = v)
  199. .column<string>("token", o => o.token, (o, v) => o.token = v);
  200. }
  201. }
  202. /**
  203. * One run of a task on a saddle: opened when the dispatcher assigns
  204. * the task, closed with an outcome when the session ends.
  205. */
  206. public class Session : Object {
  207. public int64 id { get; set; }
  208. public int64 task_id { get; set; }
  209. public int64 saddle_id { get; set; }
  210. public DateTime? started_at { get; set; default = null; }
  211. public DateTime? ended_at { get; set; default = null; }
  212. public string? outcome { get; set; default = null; }
  213. public static void entity_mapping(EntityMapperBuilder<Session> cfg) {
  214. cfg.table("sessions")
  215. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  216. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v)
  217. .column<int64?>("saddle_id", o => o.saddle_id, (o, v) => o.saddle_id = v)
  218. .column<DateTime?>("started_at", o => o.started_at, (o, v) => o.started_at = v)
  219. .column<DateTime?>("ended_at", o => o.ended_at, (o, v) => o.ended_at = v)
  220. .column<string>("outcome", o => o.outcome, (o, v) => o.outcome = v);
  221. }
  222. }
  223. /**
  224. * A numbered entry captured during a {@link Session} — a bash
  225. * command/output pair or a conversation-level event (comment, block,
  226. * progress, review, plan, user-comment) — stored as the saddle daemon
  227. * reports it.
  228. */
  229. public class SessionCommand : Object {
  230. public int64 id { get; set; }
  231. public int64 session_id { get; set; }
  232. public string command_text { get; set; default = ""; }
  233. public string? output_text { get; set; default = null; }
  234. public int64 exit_code { get; set; default = 0; }
  235. public string entry_type { get; set; default = "command"; }
  236. public string? piped_input { get; set; default = null; }
  237. public DateTime? started_at { get; set; default = null; }
  238. public DateTime? completed_at { get; set; default = null; }
  239. public int64 duration_ms { get; set; default = 0; }
  240. public static void entity_mapping(EntityMapperBuilder<SessionCommand> cfg) {
  241. cfg.table("session_commands")
  242. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  243. .column<int64?>("session_id", o => o.session_id, (o, v) => o.session_id = v)
  244. .column<string>("command_text", o => o.command_text, (o, v) => o.command_text = v)
  245. .column<string>("output_text", o => o.output_text, (o, v) => o.output_text = v)
  246. .column<int64?>("exit_code", o => o.exit_code, (o, v) => o.exit_code = v)
  247. .column<string>("type", o => o.entry_type, (o, v) => o.entry_type = v)
  248. .column<string>("piped_input", o => o.piped_input, (o, v) => o.piped_input = v)
  249. .column<DateTime?>("started_at", o => o.started_at, (o, v) => o.started_at = v)
  250. .column<DateTime?>("completed_at", o => o.completed_at, (o, v) => o.completed_at = v)
  251. .column<int64?>("duration_ms", o => o.duration_ms, (o, v) => o.duration_ms = v);
  252. }
  253. }
  254. /**
  255. * A reusable instruction the dispatched agent must follow, stored in
  256. * the `rules` table and attached to projects and/or tasks.
  257. * `updated_at` stamps the last body/name edit (null until edited)
  258. * — the resume-time context_update delta keys on it.
  259. */
  260. public class Rule : Object {
  261. public int64 id { get; set; }
  262. public string name { get; set; default = ""; }
  263. public string body { get; set; default = ""; }
  264. public DateTime? created_at { get; set; default = null; }
  265. public DateTime? updated_at { get; set; default = null; }
  266. public static void entity_mapping(EntityMapperBuilder<Rule> cfg) {
  267. cfg.table("rules")
  268. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  269. .column<string>("name", o => o.name, (o, v) => o.name = v)
  270. .column<string>("body", o => o.body, (o, v) => o.body = v)
  271. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v)
  272. .column<DateTime?>("updated_at", o => o.updated_at, (o, v) => o.updated_at = v);
  273. }
  274. }
  275. /** An attachment of a rule to a project (`rule_projects`). */
  276. public class RuleProject : Object {
  277. public int64 id { get; set; }
  278. public int64 rule_id { get; set; }
  279. public int64 project_id { get; set; }
  280. public DateTime? created_at { get; set; default = null; }
  281. public static void entity_mapping(EntityMapperBuilder<RuleProject> cfg) {
  282. cfg.table("rule_projects")
  283. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  284. .column<int64?>("rule_id", o => o.rule_id, (o, v) => o.rule_id = v)
  285. .column<int64?>("project_id", o => o.project_id, (o, v) => o.project_id = v)
  286. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  287. }
  288. }
  289. /** An attachment of a rule to a task (`task_rules`). */
  290. public class TaskRule : Object {
  291. public int64 id { get; set; }
  292. public int64 rule_id { get; set; }
  293. public int64 task_id { get; set; }
  294. public DateTime? created_at { get; set; default = null; }
  295. public static void entity_mapping(EntityMapperBuilder<TaskRule> cfg) {
  296. cfg.table("task_rules")
  297. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  298. .column<int64?>("rule_id", o => o.rule_id, (o, v) => o.rule_id = v)
  299. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v)
  300. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  301. }
  302. }
  303. /**
  304. * An LLM-authored remark about a project (`saddle note` via the
  305. * callback endpoint), curated from the project page. The source task
  306. * is null for notes without one.
  307. */
  308. public class ProjectNote : Object {
  309. public int64 id { get; set; }
  310. public int64 project_id { get; set; }
  311. public int64 source_task_id { get; set; default = 0; }
  312. public string body { get; set; default = ""; }
  313. public DateTime? created_at { get; set; default = null; }
  314. public static void entity_mapping(EntityMapperBuilder<ProjectNote> cfg) {
  315. cfg.table("project_notes")
  316. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  317. .column<int64?>("project_id", o => o.project_id, (o, v) => o.project_id = v)
  318. .column<int64?>("source_task_id", o => o.source_task_id, (o, v) => o.source_task_id = v ?? 0)
  319. .column<string>("body", o => o.body, (o, v) => o.body = v)
  320. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  321. }
  322. }
  323. /**
  324. * One raw PTY output chunk of a {@link Session}, pulled from the
  325. * daemon's `GET /log` ring buffer while the session is active
  326. * (`session_raw_log`); `seq` is the daemon's monotonic chunk
  327. * sequence number.
  328. */
  329. public class SessionRawLog : Object {
  330. public int64 id { get; set; }
  331. public int64 session_id { get; set; }
  332. public int64 seq { get; set; }
  333. public string chunk { get; set; default = ""; }
  334. public static void entity_mapping(EntityMapperBuilder<SessionRawLog> cfg) {
  335. cfg.table("session_raw_log")
  336. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  337. .column<int64?>("session_id", o => o.session_id, (o, v) => o.session_id = v)
  338. .column<int64?>("seq", o => o.seq, (o, v) => o.seq = v)
  339. .column<string>("chunk", o => o.chunk, (o, v) => o.chunk = v);
  340. }
  341. }
  342. /**
  343. * A named tag used for dispatch routing (`capabilities`): saddles
  344. * declare the tags they carry, tasks the tags they require.
  345. */
  346. public class Capability : Object {
  347. public int64 id { get; set; }
  348. public string name { get; set; default = ""; }
  349. public DateTime? created_at { get; set; default = null; }
  350. public static void entity_mapping(EntityMapperBuilder<Capability> cfg) {
  351. cfg.table("capabilities")
  352. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  353. .column<string>("name", o => o.name, (o, v) => o.name = v)
  354. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  355. }
  356. }
  357. /** A tag declaration on a saddle (`saddle_capabilities`). */
  358. public class SaddleCapability : Object {
  359. public int64 id { get; set; }
  360. public int64 capability_id { get; set; }
  361. public int64 saddle_id { get; set; }
  362. public static void entity_mapping(EntityMapperBuilder<SaddleCapability> cfg) {
  363. cfg.table("saddle_capabilities")
  364. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  365. .column<int64?>("capability_id", o => o.capability_id, (o, v) => o.capability_id = v)
  366. .column<int64?>("saddle_id", o => o.saddle_id, (o, v) => o.saddle_id = v);
  367. }
  368. }
  369. /** A required tag on a task (`task_capabilities`). */
  370. public class TaskCapability : Object {
  371. public int64 id { get; set; }
  372. public int64 capability_id { get; set; }
  373. public int64 task_id { get; set; }
  374. public static void entity_mapping(EntityMapperBuilder<TaskCapability> cfg) {
  375. cfg.table("task_capabilities")
  376. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  377. .column<int64?>("capability_id", o => o.capability_id, (o, v) => o.capability_id = v)
  378. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v);
  379. }
  380. }
  381. /**
  382. * A bearer token authorising one saddle daemon's calls against the
  383. * `/api/saddle/*` endpoints, generated at registration.
  384. */
  385. public class ApiToken : Object {
  386. public int64 id { get; set; }
  387. public int64 saddle_id { get; set; }
  388. public string token { get; set; default = ""; }
  389. public DateTime? created_at { get; set; default = null; }
  390. public static void entity_mapping(EntityMapperBuilder<ApiToken> cfg) {
  391. cfg.table("api_tokens")
  392. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  393. .column<int64?>("saddle_id", o => o.saddle_id, (o, v) => o.saddle_id = v)
  394. .column<string>("token", o => o.token, (o, v) => o.token = v)
  395. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  396. }
  397. }
  398. /**
  399. * A user's Web Push subscription endpoint (plan 11 task E shape):
  400. * `p256dh`/`auth` are the browser's application server keys; the
  401. * endpoint URL is unique per browser. `user_id` references the
  402. * Spry users table by value (no FK — the auth schema owns that
  403. * table).
  404. */
  405. public class PushSubscription : Object {
  406. public int64 id { get; set; }
  407. public int64 user_id { get; set; }
  408. public string endpoint { get; set; default = ""; }
  409. public string p256dh { get; set; default = ""; }
  410. public string auth { get; set; default = ""; }
  411. public DateTime? created_at { get; set; default = null; }
  412. public static void entity_mapping(EntityMapperBuilder<PushSubscription> cfg) {
  413. cfg.table("push_subscriptions")
  414. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  415. .column<int64?>("user_id", o => o.user_id, (o, v) => o.user_id = v)
  416. .column<string>("endpoint", o => o.endpoint, (o, v) => o.endpoint = v)
  417. .column<string>("p256dh", o => o.p256dh, (o, v) => o.p256dh = v)
  418. .column<string>("auth", o => o.auth, (o, v) => o.auth = v)
  419. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  420. }
  421. }
  422. /**
  423. * A user's per-task "Notify me" opt-in (plan 11 task E shape): the
  424. * task's first start, failure and completion notify the opted-in
  425. * user; block events notify all push-subscribed users globally.
  426. */
  427. public class TaskNotifyPref : Object {
  428. public int64 id { get; set; }
  429. public int64 task_id { get; set; }
  430. public int64 user_id { get; set; }
  431. public static void entity_mapping(EntityMapperBuilder<TaskNotifyPref> cfg) {
  432. cfg.table("task_notify_prefs")
  433. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  434. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v)
  435. .column<int64?>("user_id", o => o.user_id, (o, v) => o.user_id = v);
  436. }
  437. }
  438. /**
  439. * A user-created goal (plan 12): an agent-orchestrated unit of
  440. * work over one primary project plus optional links. The brief
  441. * locks once started; the lifecycle runs draft → planning → plan
  442. * review → active → completion review → complete / failed /
  443. * cancelled, with paused freezing supervision in between. Stored
  444. * in the `goals` table.
  445. */
  446. public class Goal : Object {
  447. public int64 id { get; set; }
  448. public int64 project_id { get; set; }
  449. public string title { get; set; default = ""; }
  450. public string brief { get; set; default = ""; }
  451. public string branch_name { get; set; default = ""; }
  452. public string? base_branch { get; set; default = null; }
  453. public string status { get; set; default = "draft"; }
  454. public int64 priority { get; set; default = 3; }
  455. public string? plan { get; set; default = null; }
  456. public string? completion_report { get; set; default = null; }
  457. public string creator { get; set; default = "human"; }
  458. public int64 last_seen_event_id { get; set; default = 0; }
  459. public string? branch_push_state { get; set; default = null; }
  460. public DateTime? created_at { get; set; default = null; }
  461. public DateTime? started_at { get; set; default = null; }
  462. public DateTime? completed_at { get; set; default = null; }
  463. public DateTime? paused_at { get; set; default = null; }
  464. public static void entity_mapping(EntityMapperBuilder<Goal> cfg) {
  465. cfg.table("goals")
  466. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  467. .column<int64?>("project_id", o => o.project_id, (o, v) => o.project_id = v)
  468. .column<string>("title", o => o.title, (o, v) => o.title = v)
  469. .column<string>("brief", o => o.brief, (o, v) => o.brief = v)
  470. .column<string>("branch_name", o => o.branch_name, (o, v) => o.branch_name = v)
  471. .column<string>("base_branch", o => o.base_branch, (o, v) => o.base_branch = v)
  472. .column<string>("status", o => o.status, (o, v) => o.status = v)
  473. .column<int64?>("priority", o => o.priority, (o, v) => o.priority = v)
  474. .column<string>("plan", o => o.plan, (o, v) => o.plan = v)
  475. .column<string>("completion_report", o => o.completion_report, (o, v) => o.completion_report = v)
  476. .column<string>("creator", o => o.creator, (o, v) => o.creator = v)
  477. .column<int64?>("last_seen_event_id", o => o.last_seen_event_id, (o, v) => o.last_seen_event_id = v ?? 0)
  478. .column<string>("branch_push_state", o => o.branch_push_state, (o, v) => o.branch_push_state = v)
  479. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v)
  480. .column<DateTime?>("started_at", o => o.started_at, (o, v) => o.started_at = v)
  481. .column<DateTime?>("completed_at", o => o.completed_at, (o, v) => o.completed_at = v)
  482. .column<DateTime?>("paused_at", o => o.paused_at, (o, v) => o.paused_at = v);
  483. }
  484. }
  485. /** A project link on a goal (`goal_links`): co-developed or reference. */
  486. public class GoalLink : Object {
  487. public int64 id { get; set; }
  488. public int64 goal_id { get; set; }
  489. public int64 project_id { get; set; }
  490. public string relationship { get; set; default = "reference"; }
  491. public static void entity_mapping(EntityMapperBuilder<GoalLink> cfg) {
  492. cfg.table("goal_links")
  493. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  494. .column<int64?>("goal_id", o => o.goal_id, (o, v) => o.goal_id = v)
  495. .column<int64?>("project_id", o => o.project_id, (o, v) => o.project_id = v)
  496. .column<string>("relationship", o => o.relationship, (o, v) => o.relationship = v);
  497. }
  498. }
  499. /** A remark on a goal, authored by a human or by the goal agent ('agent'). */
  500. public class GoalComment : Object {
  501. public int64 id { get; set; }
  502. public int64 goal_id { get; set; }
  503. public string author { get; set; default = "agent"; }
  504. public string body { get; set; default = ""; }
  505. public string? quote { get; set; default = null; }
  506. public DateTime? created_at { get; set; default = null; }
  507. public static void entity_mapping(EntityMapperBuilder<GoalComment> cfg) {
  508. cfg.table("goal_comments")
  509. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  510. .column<int64?>("goal_id", o => o.goal_id, (o, v) => o.goal_id = v)
  511. .column<string>("author", o => o.author, (o, v) => o.author = v)
  512. .column<string>("body", o => o.body, (o, v) => o.body = v)
  513. .column<string>("quote", o => o.quote, (o, v) => o.quote = v)
  514. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  515. }
  516. }
  517. /**
  518. * A goal-level blocking prompt (plan 12): the goal agent's
  519. * question/RFC blocks, its plan submissions/revisions (type
  520. * 'plan', the approved one mirrored into {@link Goal.plan}) and
  521. * the completion report awaiting review (type 'completion').
  522. * Answered by a human on the goal page.
  523. */
  524. public class GoalBlock : Object {
  525. public int64 id { get; set; }
  526. public int64 goal_id { get; set; }
  527. public string question { get; set; default = ""; }
  528. public string? answer { get; set; default = null; }
  529. public string block_type { get; set; default = "question"; }
  530. public string? options { get; set; default = null; }
  531. public string? body { get; set; default = null; }
  532. public DateTime? answered_at { get; set; default = null; }
  533. public string? answered_by { get; set; default = null; }
  534. public DateTime? created_at { get; set; default = null; }
  535. public static void entity_mapping(EntityMapperBuilder<GoalBlock> cfg) {
  536. cfg.table("goal_blocks")
  537. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  538. .column<int64?>("goal_id", o => o.goal_id, (o, v) => o.goal_id = v)
  539. .column<string>("question", o => o.question, (o, v) => o.question = v)
  540. .column<string>("answer", o => o.answer, (o, v) => o.answer = v)
  541. .column<string>("type", o => o.block_type, (o, v) => o.block_type = v)
  542. .column<string>("options", o => o.options, (o, v) => o.options = v)
  543. .column<string>("body", o => o.body, (o, v) => o.body = v)
  544. .column<DateTime?>("answered_at", o => o.answered_at, (o, v) => o.answered_at = v)
  545. .column<string>("answered_by", o => o.answered_by, (o, v) => o.answered_by = v)
  546. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  547. }
  548. }
  549. /**
  550. * One entry of a goal's supervision narrative (`goal_events`):
  551. * lifecycle moves, plan submissions/reviews, the goal agent's task
  552. * operations and its tasks' terminal events. Also the resume
  553. * machinery's queue — {@link Goal.last_seen_event_id} marks the
  554. * events the goal agent has already consumed.
  555. */
  556. public class GoalEvent : Object {
  557. public int64 id { get; set; }
  558. public int64 goal_id { get; set; }
  559. public string kind { get; set; default = ""; }
  560. public string text { get; set; default = ""; }
  561. public int64 task_id { get; set; default = 0; }
  562. public DateTime? created_at { get; set; default = null; }
  563. public static void entity_mapping(EntityMapperBuilder<GoalEvent> cfg) {
  564. cfg.table("goal_events")
  565. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  566. .column<int64?>("goal_id", o => o.goal_id, (o, v) => o.goal_id = v)
  567. .column<string>("kind", o => o.kind, (o, v) => o.kind = v)
  568. .column<string>("text", o => o.text, (o, v) => o.text = v)
  569. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v ?? 0)
  570. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  571. }
  572. }
  573. }