Entities.vala 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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. /**
  214. * What a resumed session's agent first received (plan 14 B4):
  215. * the resume_notice the allocation built, stored on the row at
  216. * resume-allocation; null for fresh sessions.
  217. */
  218. public string? resume_notice { get; set; default = null; }
  219. public static void entity_mapping(EntityMapperBuilder<Session> cfg) {
  220. cfg.table("sessions")
  221. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  222. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v)
  223. .column<int64?>("saddle_id", o => o.saddle_id, (o, v) => o.saddle_id = v)
  224. .column<DateTime?>("started_at", o => o.started_at, (o, v) => o.started_at = v)
  225. .column<DateTime?>("ended_at", o => o.ended_at, (o, v) => o.ended_at = v)
  226. .column<string>("outcome", o => o.outcome, (o, v) => o.outcome = v)
  227. .column<string>("resume_notice", o => o.resume_notice, (o, v) => o.resume_notice = v);
  228. }
  229. }
  230. /**
  231. * One daemon-global entry id already ingested for a saddle (plan
  232. * 13 B1): the (saddle, entry id) pair is the replay-integrity key.
  233. * An outbox redelivery under ANY session id — a web restart, session
  234. * churn, a mis-keyed send — finds its row already here and is
  235. * consumed silently; the pair survives daemon restarts because it
  236. * lives in the database, not in memory.
  237. */
  238. public class SaddleEntryDedup : Object {
  239. public int64 id { get; set; }
  240. public int64 saddle_id { get; set; }
  241. public int64 entry_id { get; set; }
  242. public static void entity_mapping(EntityMapperBuilder<SaddleEntryDedup> cfg) {
  243. cfg.table("saddle_entry_dedup")
  244. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  245. .column<int64?>("saddle_id", o => o.saddle_id, (o, v) => o.saddle_id = v)
  246. .column<int64?>("entry_id", o => o.entry_id, (o, v) => o.entry_id = v);
  247. }
  248. }
  249. /**
  250. * A numbered entry captured during a {@link Session} — a bash
  251. * command/output pair or a conversation-level event (comment, block,
  252. * progress, review, plan, user-comment) — stored as the saddle daemon
  253. * reports it.
  254. */
  255. public class SessionCommand : Object {
  256. public int64 id { get; set; }
  257. public int64 session_id { get; set; }
  258. public string command_text { get; set; default = ""; }
  259. public string? output_text { get; set; default = null; }
  260. public int64 exit_code { get; set; default = 0; }
  261. public string entry_type { get; set; default = "command"; }
  262. public string? piped_input { get; set; default = null; }
  263. public DateTime? started_at { get; set; default = null; }
  264. public DateTime? completed_at { get; set; default = null; }
  265. public int64 duration_ms { get; set; default = 0; }
  266. public static void entity_mapping(EntityMapperBuilder<SessionCommand> cfg) {
  267. cfg.table("session_commands")
  268. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  269. .column<int64?>("session_id", o => o.session_id, (o, v) => o.session_id = v)
  270. .column<string>("command_text", o => o.command_text, (o, v) => o.command_text = v)
  271. .column<string>("output_text", o => o.output_text, (o, v) => o.output_text = v)
  272. .column<int64?>("exit_code", o => o.exit_code, (o, v) => o.exit_code = v)
  273. .column<string>("type", o => o.entry_type, (o, v) => o.entry_type = v)
  274. .column<string>("piped_input", o => o.piped_input, (o, v) => o.piped_input = v)
  275. .column<DateTime?>("started_at", o => o.started_at, (o, v) => o.started_at = v)
  276. .column<DateTime?>("completed_at", o => o.completed_at, (o, v) => o.completed_at = v)
  277. .column<int64?>("duration_ms", o => o.duration_ms, (o, v) => o.duration_ms = v);
  278. }
  279. }
  280. /**
  281. * A reusable instruction the dispatched agent must follow, stored in
  282. * the `rules` table and attached to projects and/or tasks.
  283. * `updated_at` stamps the last body/name edit (null until edited)
  284. * — the resume-time context_update delta keys on it.
  285. */
  286. public class Rule : Object {
  287. public int64 id { get; set; }
  288. public string name { get; set; default = ""; }
  289. public string body { get; set; default = ""; }
  290. public DateTime? created_at { get; set; default = null; }
  291. public DateTime? updated_at { get; set; default = null; }
  292. public static void entity_mapping(EntityMapperBuilder<Rule> cfg) {
  293. cfg.table("rules")
  294. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  295. .column<string>("name", o => o.name, (o, v) => o.name = v)
  296. .column<string>("body", o => o.body, (o, v) => o.body = v)
  297. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v)
  298. .column<DateTime?>("updated_at", o => o.updated_at, (o, v) => o.updated_at = v);
  299. }
  300. }
  301. /** An attachment of a rule to a project (`rule_projects`). */
  302. public class RuleProject : Object {
  303. public int64 id { get; set; }
  304. public int64 rule_id { get; set; }
  305. public int64 project_id { get; set; }
  306. public DateTime? created_at { get; set; default = null; }
  307. public static void entity_mapping(EntityMapperBuilder<RuleProject> cfg) {
  308. cfg.table("rule_projects")
  309. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  310. .column<int64?>("rule_id", o => o.rule_id, (o, v) => o.rule_id = v)
  311. .column<int64?>("project_id", o => o.project_id, (o, v) => o.project_id = v)
  312. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  313. }
  314. }
  315. /** An attachment of a rule to a task (`task_rules`). */
  316. public class TaskRule : Object {
  317. public int64 id { get; set; }
  318. public int64 rule_id { get; set; }
  319. public int64 task_id { get; set; }
  320. public DateTime? created_at { get; set; default = null; }
  321. public static void entity_mapping(EntityMapperBuilder<TaskRule> cfg) {
  322. cfg.table("task_rules")
  323. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  324. .column<int64?>("rule_id", o => o.rule_id, (o, v) => o.rule_id = v)
  325. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v)
  326. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  327. }
  328. }
  329. /**
  330. * An LLM-authored remark about a project (`saddle note` via the
  331. * callback endpoint), curated from the project page. The source task
  332. * is null for notes without one.
  333. */
  334. public class ProjectNote : Object {
  335. public int64 id { get; set; }
  336. public int64 project_id { get; set; }
  337. public int64 source_task_id { get; set; default = 0; }
  338. public string body { get; set; default = ""; }
  339. public DateTime? created_at { get; set; default = null; }
  340. public static void entity_mapping(EntityMapperBuilder<ProjectNote> cfg) {
  341. cfg.table("project_notes")
  342. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  343. .column<int64?>("project_id", o => o.project_id, (o, v) => o.project_id = v)
  344. .column<int64?>("source_task_id", o => o.source_task_id, (o, v) => o.source_task_id = v ?? 0)
  345. .column<string>("body", o => o.body, (o, v) => o.body = v)
  346. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  347. }
  348. }
  349. /**
  350. * One raw PTY output chunk of a {@link Session}, pulled from the
  351. * daemon's `GET /log` ring buffer while the session is active
  352. * (`session_raw_log`); `seq` is the daemon's monotonic chunk
  353. * sequence number.
  354. */
  355. public class SessionRawLog : Object {
  356. public int64 id { get; set; }
  357. public int64 session_id { get; set; }
  358. public int64 seq { get; set; }
  359. public string chunk { get; set; default = ""; }
  360. public static void entity_mapping(EntityMapperBuilder<SessionRawLog> cfg) {
  361. cfg.table("session_raw_log")
  362. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  363. .column<int64?>("session_id", o => o.session_id, (o, v) => o.session_id = v)
  364. .column<int64?>("seq", o => o.seq, (o, v) => o.seq = v)
  365. .column<string>("chunk", o => o.chunk, (o, v) => o.chunk = v);
  366. }
  367. }
  368. /**
  369. * A named tag used for dispatch routing (`capabilities`): saddles
  370. * declare the tags they carry, tasks the tags they require.
  371. */
  372. public class Capability : Object {
  373. public int64 id { get; set; }
  374. public string name { get; set; default = ""; }
  375. public DateTime? created_at { get; set; default = null; }
  376. public static void entity_mapping(EntityMapperBuilder<Capability> cfg) {
  377. cfg.table("capabilities")
  378. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  379. .column<string>("name", o => o.name, (o, v) => o.name = v)
  380. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  381. }
  382. }
  383. /** A tag declaration on a saddle (`saddle_capabilities`). */
  384. public class SaddleCapability : Object {
  385. public int64 id { get; set; }
  386. public int64 capability_id { get; set; }
  387. public int64 saddle_id { get; set; }
  388. public static void entity_mapping(EntityMapperBuilder<SaddleCapability> cfg) {
  389. cfg.table("saddle_capabilities")
  390. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  391. .column<int64?>("capability_id", o => o.capability_id, (o, v) => o.capability_id = v)
  392. .column<int64?>("saddle_id", o => o.saddle_id, (o, v) => o.saddle_id = v);
  393. }
  394. }
  395. /** A required tag on a task (`task_capabilities`). */
  396. public class TaskCapability : Object {
  397. public int64 id { get; set; }
  398. public int64 capability_id { get; set; }
  399. public int64 task_id { get; set; }
  400. public static void entity_mapping(EntityMapperBuilder<TaskCapability> cfg) {
  401. cfg.table("task_capabilities")
  402. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  403. .column<int64?>("capability_id", o => o.capability_id, (o, v) => o.capability_id = v)
  404. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v);
  405. }
  406. }
  407. /**
  408. * A bearer token authorising one saddle daemon's calls against the
  409. * `/api/saddle/*` endpoints, generated at registration.
  410. */
  411. public class ApiToken : Object {
  412. public int64 id { get; set; }
  413. public int64 saddle_id { get; set; }
  414. public string token { get; set; default = ""; }
  415. public DateTime? created_at { get; set; default = null; }
  416. public static void entity_mapping(EntityMapperBuilder<ApiToken> cfg) {
  417. cfg.table("api_tokens")
  418. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  419. .column<int64?>("saddle_id", o => o.saddle_id, (o, v) => o.saddle_id = v)
  420. .column<string>("token", o => o.token, (o, v) => o.token = v)
  421. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  422. }
  423. }
  424. /**
  425. * A user's Web Push subscription endpoint (plan 11 task E shape):
  426. * `p256dh`/`auth` are the browser's application server keys; the
  427. * endpoint URL is unique per browser. `user_id` references the
  428. * Spry users table by value (no FK — the auth schema owns that
  429. * table).
  430. */
  431. public class PushSubscription : Object {
  432. public int64 id { get; set; }
  433. public int64 user_id { get; set; }
  434. public string endpoint { get; set; default = ""; }
  435. public string p256dh { get; set; default = ""; }
  436. public string auth { get; set; default = ""; }
  437. public DateTime? created_at { get; set; default = null; }
  438. public static void entity_mapping(EntityMapperBuilder<PushSubscription> cfg) {
  439. cfg.table("push_subscriptions")
  440. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  441. .column<int64?>("user_id", o => o.user_id, (o, v) => o.user_id = v)
  442. .column<string>("endpoint", o => o.endpoint, (o, v) => o.endpoint = v)
  443. .column<string>("p256dh", o => o.p256dh, (o, v) => o.p256dh = v)
  444. .column<string>("auth", o => o.auth, (o, v) => o.auth = v)
  445. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v);
  446. }
  447. }
  448. /**
  449. * A user's per-task "Notify me" opt-in (plan 11 task E shape): the
  450. * task's first start, failure and completion notify the opted-in
  451. * user; block events notify all push-subscribed users globally.
  452. */
  453. public class TaskNotifyPref : Object {
  454. public int64 id { get; set; }
  455. public int64 task_id { get; set; }
  456. public int64 user_id { get; set; }
  457. public static void entity_mapping(EntityMapperBuilder<TaskNotifyPref> cfg) {
  458. cfg.table("task_notify_prefs")
  459. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  460. .column<int64?>("task_id", o => o.task_id, (o, v) => o.task_id = v)
  461. .column<int64?>("user_id", o => o.user_id, (o, v) => o.user_id = v);
  462. }
  463. }
  464. /**
  465. * A user-created goal (plan 12): an agent-orchestrated unit of
  466. * work over one primary project plus optional links. The brief
  467. * locks once started; the lifecycle runs draft → planning → plan
  468. * review → active → completion review → complete / failed /
  469. * cancelled, with paused freezing supervision in between. Stored
  470. * in the `goals` table.
  471. */
  472. public class Goal : Object {
  473. public int64 id { get; set; }
  474. public int64 project_id { get; set; }
  475. public string title { get; set; default = ""; }
  476. public string brief { get; set; default = ""; }
  477. public string branch_name { get; set; default = ""; }
  478. public string? base_branch { get; set; default = null; }
  479. public string status { get; set; default = "draft"; }
  480. public int64 priority { get; set; default = 3; }
  481. public string? plan { get; set; default = null; }
  482. public string? completion_report { get; set; default = null; }
  483. public string creator { get; set; default = "human"; }
  484. /**
  485. * Plan 15 C3 (was last_seen_event_id): the timestamp through
  486. * which the goal agent has consumed its tasks' terminal
  487. * transitions — resume_due fires on transitions newer than
  488. * it, and a resume advance it. The narrative itself is
  489. * derived at read time.
  490. */
  491. public DateTime? last_terminal_watermark { get; set; default = null; }
  492. public DateTime? created_at { get; set; default = null; }
  493. public DateTime? started_at { get; set; default = null; }
  494. public DateTime? completed_at { get; set; default = null; }
  495. public DateTime? paused_at { get; set; default = null; }
  496. public static void entity_mapping(EntityMapperBuilder<Goal> cfg) {
  497. cfg.table("goals")
  498. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  499. .column<int64?>("project_id", o => o.project_id, (o, v) => o.project_id = v)
  500. .column<string>("title", o => o.title, (o, v) => o.title = v)
  501. .column<string>("brief", o => o.brief, (o, v) => o.brief = v)
  502. .column<string>("branch_name", o => o.branch_name, (o, v) => o.branch_name = v)
  503. .column<string>("base_branch", o => o.base_branch, (o, v) => o.base_branch = v)
  504. .column<string>("status", o => o.status, (o, v) => o.status = v)
  505. .column<int64?>("priority", o => o.priority, (o, v) => o.priority = v)
  506. .column<string>("plan", o => o.plan, (o, v) => o.plan = v)
  507. .column<string>("completion_report", o => o.completion_report, (o, v) => o.completion_report = v)
  508. .column<string>("creator", o => o.creator, (o, v) => o.creator = v)
  509. .column<DateTime?>("last_terminal_watermark", o => o.last_terminal_watermark, (o, v) => o.last_terminal_watermark = v)
  510. .column<DateTime?>("created_at", o => o.created_at, (o, v) => o.created_at = v)
  511. .column<DateTime?>("started_at", o => o.started_at, (o, v) => o.started_at = v)
  512. .column<DateTime?>("completed_at", o => o.completed_at, (o, v) => o.completed_at = v)
  513. .column<DateTime?>("paused_at", o => o.paused_at, (o, v) => o.paused_at = v);
  514. }
  515. }
  516. /** A project link on a goal (`goal_links`): co-developed or reference. */
  517. public class GoalLink : Object {
  518. public int64 id { get; set; }
  519. public int64 goal_id { get; set; }
  520. public int64 project_id { get; set; }
  521. public string relationship { get; set; default = "reference"; }
  522. public static void entity_mapping(EntityMapperBuilder<GoalLink> cfg) {
  523. cfg.table("goal_links")
  524. .column<int64?>("id", o => o.id, (o, v) => o.id = v)
  525. .column<int64?>("goal_id", o => o.goal_id, (o, v) => o.goal_id = v)
  526. .column<int64?>("project_id", o => o.project_id, (o, v) => o.project_id = v)
  527. .column<string>("relationship", o => o.relationship, (o, v) => o.relationship = v);
  528. }
  529. }
  530. }