@buildr-ai/buildr 0.1.0-rc.2 → 0.1.0-rc.21

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 (181) hide show
  1. package/README.md +47 -5
  2. package/application-payload.json +595 -0
  3. package/bin/buildr.mjs +14 -0
  4. package/installation-origin.json +13 -0
  5. package/package.json +16 -45
  6. package/payload/licenses/dependencies/yaml-LICENSE +13 -0
  7. package/payload/product/LICENSE +21 -0
  8. package/payload/product/README.md +59 -0
  9. package/payload/product/package/README.md +42 -0
  10. package/{package → payload/product/package}/bootstrap/contract.yml +26 -11
  11. package/{package → payload/product/package}/bootstrap/guide.md +11 -11
  12. package/payload/product/package/launchers/assets/Buildr.icns +0 -0
  13. package/payload/product/package/launchers/assets/Buildr.ico +0 -0
  14. package/payload/product/package/manifest.yml +547 -0
  15. package/payload/product/package/targets/runtime/skills/buildr/SKILL.md +174 -0
  16. package/{package → payload/product/package}/targets/workspace/commands/buildr/openspec/manifest.yml +2 -2
  17. package/payload/product/package/targets/workspace/components/buildr/openspec/component.yml +79 -0
  18. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +21 -0
  19. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-archive-converge.md +5 -0
  20. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-explore-terminology.md +5 -0
  21. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +21 -0
  22. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-sync-converge.md +5 -0
  23. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-update-sidebar.md +13 -0
  24. package/payload/product/package/targets/workspace/gitattributes +1 -0
  25. package/payload/product/package/targets/workspace/gitignore +31 -0
  26. package/{package → payload/product/package}/targets/workspace/projects/AGENTS.project.md +1 -1
  27. package/payload/product/package/targets/workspace/rules/buildr/core.md +62 -0
  28. package/payload/product/package/targets/workspace/skills/buildr/capability-adaptation/SKILL.md +56 -0
  29. package/payload/product/package/targets/workspace/skills/buildr/capability-adaptation/agents/openai.yaml +4 -0
  30. package/payload/product/package/targets/workspace/skills/buildr/current-knowledge-maintenance/SKILL.md +103 -0
  31. package/payload/product/package/targets/workspace/skills/buildr/declaration-intake/SKILL.md +65 -0
  32. package/payload/product/package/targets/workspace/skills/buildr/git-operations/SKILL.md +100 -0
  33. package/payload/product/package/targets/workspace/skills/buildr/openspec-contract-guard/SKILL.md +65 -0
  34. package/payload/product/package/targets/workspace/skills/buildr/project-daily-progress/SKILL.md +52 -0
  35. package/payload/product/package/targets/workspace/skills/buildr/project-testing/SKILL.md +84 -0
  36. package/payload/product/package/targets/workspace/skills/buildr/project-testing/references/testing-model-v1.md +116 -0
  37. package/payload/product/package/targets/workspace/skills/buildr/task-development/SKILL.md +108 -0
  38. package/payload/product/package/targets/workspace/skills/buildr/task-environment/SKILL.md +42 -0
  39. package/payload/product/package/targets/workspace/skills/buildr/task-environment/agents/openai.yaml +4 -0
  40. package/payload/product/package/targets/workspace/skills/buildr/task-environment/references/project-environment-preparation-v1.md +14 -0
  41. package/payload/product/package/targets/workspace/skills/buildr/task-environment/templates/project-preparation.yml +20 -0
  42. package/payload/product/package/targets/workspace/skills/buildr/task-environment/templates/task-environment-plan-request.json +17 -0
  43. package/payload/product/package/targets/workspace/skills/buildr/task-finish/SKILL.md +80 -0
  44. package/payload/product/package/targets/workspace/skills/buildr/task-manager/SKILL.md +47 -0
  45. package/payload/product/package/targets/workspace/skills/buildr/task-manager/agents/openai.yaml +4 -0
  46. package/payload/product/package/targets/workspace/skills/buildr/task-retrospective/SKILL.md +101 -0
  47. package/payload/product/package/targets/workspace/skills/buildr/task-retrospective/agents/openai.yaml +4 -0
  48. package/payload/product/package/targets/workspace/skills/buildr/task-review/SKILL.md +60 -0
  49. package/payload/product/package/targets/workspace/skills/buildr/task-review/agents/openai.yaml +4 -0
  50. package/payload/product/package/targets/workspace/skills/buildr/task-triage/SKILL.md +119 -0
  51. package/payload/product/package/targets/workspace/skills/buildr/task-verification/SKILL.md +142 -0
  52. package/payload/product/package/targets/workspace/skills/buildr/task-verification/references/project-verification-v2.md +51 -0
  53. package/payload/product/package/targets/workspace/skills/buildr/task-verification/templates/project-verification.yml +16 -0
  54. package/payload/product/package/targets/workspace/skills/buildr/task-worktree/SKILL.md +28 -0
  55. package/payload/product/package/targets/workspace/skills/buildr/terminology-governance/SKILL.md +60 -0
  56. package/payload/product/package/targets/workspace/skills/buildr/ui-preview/SKILL.md +74 -0
  57. package/payload/product/package/targets/workspace/skills/contracts/buildr/current-knowledge-maintenance/v1.md +36 -0
  58. package/payload/product/package/targets/workspace/skills/contracts/buildr/current-knowledge-maintenance/v2.md +45 -0
  59. package/payload/product/package/targets/workspace/skills/contracts/buildr/git-operations/v1.md +39 -0
  60. package/payload/product/package/targets/workspace/skills/contracts/buildr/git-worktree-provider/v1.md +35 -0
  61. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-development/v2.md +61 -0
  62. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-environment/v1.md +37 -0
  63. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-finish/v1.md +59 -0
  64. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-record/v2.md +35 -0
  65. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-retrospective/v2.md +41 -0
  66. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-review/v1.md +39 -0
  67. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-verification/v3.md +63 -0
  68. package/payload/product/package/targets/workspace/skills/contracts/buildr/terminology-governance/v1.md +36 -0
  69. package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-apply-change/SKILL.md +4 -3
  70. package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-archive-change/SKILL.md +4 -3
  71. package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-explore/SKILL.md +4 -1
  72. package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-propose/SKILL.md +4 -1
  73. package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-sync-specs/SKILL.md +4 -3
  74. package/payload/product/package/targets/workspace/skills/openspec/openspec-update-change/SKILL.md +86 -0
  75. package/payload/product/package.json +33 -0
  76. package/payload/product/src/infrastructure/sqlite/migrations/0000_create_migration_ledger.sql +16 -0
  77. package/payload/product/src/infrastructure/sqlite/migrations/0001_create_task_store.sql +47 -0
  78. package/payload/product/src/infrastructure/sqlite/migrations/0002_create_parent_task_relations.sql +7 -0
  79. package/payload/product/src/infrastructure/sqlite/migrations/0003_inline_parent_task_column.sql +19 -0
  80. package/payload/product/src/infrastructure/sqlite/migrations/0004_create_task_current_records.sql +16 -0
  81. package/payload/product/src/infrastructure/sqlite/migrations/0005_create_task_retrospective_current.sql +4 -0
  82. package/payload/product/src/infrastructure/sqlite/migrations/0006_create_task_lifecycle_current.sql +4 -0
  83. package/payload/product/src/infrastructure/sqlite/migrations/0007_create_task_finish_current.sql +46 -0
  84. package/payload/product/src/infrastructure/sqlite/migrations/0008_create_task_environment_current.sql +8 -0
  85. package/payload/product/src/infrastructure/sqlite/migrations/0009_retire_task_lifecycle_current.sql +107 -0
  86. package/payload/product/src/infrastructure/sqlite/migrations/0010_add_task_retrospective_disposition.sql +19 -0
  87. package/payload/product/src/infrastructure/sqlite/migrations/0011_create_task_execution_records.sql +115 -0
  88. package/payload/product/src/infrastructure/sqlite/migrations/0012_compact_task_finish_current.sql +261 -0
  89. package/payload/product/src/infrastructure/sqlite/migrations/0013_add_todo_task_retrospective_sources.sql +56 -0
  90. package/payload/product/src/infrastructure/sqlite/migrations/0014_add_task_execution_invocation_identity.sql +14 -0
  91. package/payload/product/src/infrastructure/sqlite/migrations/0015_add_task_execution_unknown_outcome.sql +143 -0
  92. package/payload/product/src/infrastructure/sqlite/migrations/0016_allow_terminal_task_finish_target_lease.sql +83 -0
  93. package/payload/product/src/infrastructure/sqlite/migrations/0017_expand_task_finish_repository_set.sql +111 -0
  94. package/payload/product/src/interfaces/local-app/web-dist/assets/antd-NAtxFWmu.js +394 -0
  95. package/payload/product/src/interfaces/local-app/web-dist/assets/index-BqoyfMSY.css +1 -0
  96. package/payload/product/src/interfaces/local-app/web-dist/assets/index-DTqvE0TF.js +39 -0
  97. package/payload/product/src/interfaces/local-app/web-dist/assets/react-9kRp7SbA.js +28 -0
  98. package/payload/product/src/interfaces/local-app/web-dist/index.html +19 -0
  99. package/payload/runtime/read-worker.cjs +45071 -0
  100. package/runtime/buildr.cjs +51533 -0
  101. package/scripts/postinstall.mjs +15 -0
  102. package/docs/agent-runtime-adapters.md +0 -94
  103. package/docs/cli-architecture.md +0 -65
  104. package/docs/cli-reference.md +0 -67
  105. package/docs/known-limitations.md +0 -15
  106. package/examples/minimal-workspace/README.md +0 -24
  107. package/package/README.md +0 -28
  108. package/package/manifest.yml +0 -150
  109. package/package/targets/runtime/skills/buildr/SKILL.md +0 -154
  110. package/package/targets/workspace/.buildr/workspace.yml +0 -5
  111. package/package/targets/workspace/commands/manifest.yml +0 -2
  112. package/package/targets/workspace/components/buildr/openspec/component.yml +0 -16
  113. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +0 -3
  114. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-archive-sidebar.md +0 -3
  115. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-explore-sidebar.md +0 -3
  116. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +0 -3
  117. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-sync-sidebar.md +0 -3
  118. package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-post-sync.md +0 -1
  119. package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-pre-sync.md +0 -1
  120. package/package/targets/workspace/components/buildr/openspec/contributions/task-triage-change-ready.md +0 -10
  121. package/package/targets/workspace/components/manifest.yml +0 -2
  122. package/package/targets/workspace/gitignore +0 -16
  123. package/package/targets/workspace/projects/manifest.yml +0 -2
  124. package/package/targets/workspace/projects/services/manifest.yml +0 -3
  125. package/package/targets/workspace/projects/skills/manifest.yml +0 -2
  126. package/package/targets/workspace/rules/buildr/core.md +0 -65
  127. package/package/targets/workspace/rules/manifest.yml +0 -9
  128. package/package/targets/workspace/skills/buildr/git-ops/SKILL.md +0 -73
  129. package/package/targets/workspace/skills/buildr/openspec-contract-guard/SKILL.md +0 -67
  130. package/package/targets/workspace/skills/buildr/task-finish/SKILL.md +0 -104
  131. package/package/targets/workspace/skills/buildr/task-triage/SKILL.md +0 -103
  132. package/package/targets/workspace/skills/buildr/task-worktree/SKILL.md +0 -104
  133. package/package/targets/workspace/skills/manifest.yml +0 -38
  134. package/tools/buildr +0 -11
  135. package/tools/cli/application/cli-update.mjs +0 -219
  136. package/tools/cli/application/compose-runtime.mjs +0 -38
  137. package/tools/cli/application/doctor/runtime-diagnostics.mjs +0 -227
  138. package/tools/cli/application/doctor/scope-diagnostics.mjs +0 -440
  139. package/tools/cli/application/doctor/service-diagnostics.mjs +0 -184
  140. package/tools/cli/application/doctor.mjs +0 -201
  141. package/tools/cli/application/package-maintenance/builtin-receipts.mjs +0 -73
  142. package/tools/cli/application/package-maintenance/output.mjs +0 -148
  143. package/tools/cli/application/package-maintenance/smoke-checks.mjs +0 -463
  144. package/tools/cli/application/package-maintenance/static-validation.mjs +0 -680
  145. package/tools/cli/application/package-maintenance.mjs +0 -540
  146. package/tools/cli/application/runtime.mjs +0 -118
  147. package/tools/cli/application/workspace-operations.mjs +0 -311
  148. package/tools/cli/bootstrap.mjs +0 -6
  149. package/tools/cli/command/help.mjs +0 -296
  150. package/tools/cli/command/registry.mjs +0 -97
  151. package/tools/cli/domains/commands.mjs +0 -661
  152. package/tools/cli/domains/components.mjs +0 -922
  153. package/tools/cli/domains/openspec.mjs +0 -603
  154. package/tools/cli/domains/package-assets.mjs +0 -652
  155. package/tools/cli/domains/rules.mjs +0 -380
  156. package/tools/cli/domains/runtime.mjs +0 -87
  157. package/tools/cli/domains/skills.mjs +0 -647
  158. package/tools/cli/domains/workspace.mjs +0 -571
  159. package/tools/cli/shared/infrastructure.mjs +0 -411
  160. package/tools/cli/shared/json-contracts.mjs +0 -22
  161. package/tools/cli/shared/platform.mjs +0 -52
  162. package/tools/runtime/adapter-contract.mjs +0 -655
  163. package/tools/runtime/check-claude-code.mjs +0 -23
  164. package/tools/runtime/check-codex.mjs +0 -23
  165. package/tools/runtime/check-runtime.mjs +0 -98
  166. package/tools/runtime/projection.mjs +0 -375
  167. package/tools/runtime/render-claude-code-rules.mjs +0 -459
  168. package/tools/runtime/render-claude-code.mjs +0 -59
  169. package/tools/runtime/skills/arguments.mjs +0 -51
  170. package/tools/runtime/skills/contributions.mjs +0 -171
  171. package/tools/runtime/skills/manifests.mjs +0 -167
  172. package/tools/runtime/skills/primitives.mjs +0 -86
  173. package/tools/runtime/skills/render-plan.mjs +0 -243
  174. package/tools/runtime/skills/sources.mjs +0 -276
  175. package/tools/shared/fetch-remote-text.mjs +0 -78
  176. package/tools/verification/integrity/managed-data-integrity.mjs +0 -107
  177. package/tools/verification/integrity/managed-mutations.mjs +0 -72
  178. package/tools/verification/openspec/contract.mjs +0 -212
  179. package/tools/verification/runtime/adapter-contract.mjs +0 -218
  180. package/tools/verification/runtime/adapter-parity.mjs +0 -173
  181. /package/{package → payload/product/package}/targets/workspace/AGENTS.md +0 -0
@@ -0,0 +1,261 @@
1
+ CREATE TEMP TABLE _buildr_task_finish_migration_assertion (
2
+ valid INTEGER NOT NULL CHECK (valid = 1)
3
+ ) STRICT;
4
+
5
+ INSERT INTO _buildr_task_finish_migration_assertion(valid)
6
+ SELECT CASE WHEN NOT EXISTS (SELECT 1 FROM task_finish_transient_artifacts) THEN 1 ELSE 0 END;
7
+
8
+ INSERT INTO _buildr_task_finish_migration_assertion(valid)
9
+ SELECT CASE WHEN NOT EXISTS (
10
+ SELECT 1
11
+ FROM task_finish_runs AS run
12
+ WHERE json_extract(run.run_json, '$.schemaVersion') <> 'buildr.task-finish-run/v2'
13
+ OR json_extract(run.run_json, '$.runId') <> run.run_id
14
+ OR json_extract(run.run_json, '$.identity.task') <> run.task_id
15
+ OR json_extract(run.run_json, '$.status') <> run.status
16
+ OR json_type(run.run_json, '$.phases') <> 'array'
17
+ OR json_array_length(run.run_json, '$.phases') <> 5
18
+ OR json_extract(run.run_json, '$.phases[0].id') <> 'preflight'
19
+ OR json_extract(run.run_json, '$.phases[1].id') <> 'prepare'
20
+ OR json_extract(run.run_json, '$.phases[2].id') <> 'verify'
21
+ OR json_extract(run.run_json, '$.phases[3].id') <> 'deliver'
22
+ OR json_extract(run.run_json, '$.phases[4].id') <> 'cleanup'
23
+ OR EXISTS (
24
+ SELECT 1 FROM json_each(run.run_json, '$.phases') AS phase
25
+ WHERE json_extract(phase.value, '$.status') NOT IN ('pending', 'running', 'passed', 'blocked', 'failed', 'not-applicable')
26
+ )
27
+ ) THEN 1 ELSE 0 END;
28
+
29
+ INSERT INTO _buildr_task_finish_migration_assertion(valid)
30
+ SELECT CASE WHEN NOT EXISTS (
31
+ SELECT 1
32
+ FROM task_finish_completions AS completion
33
+ LEFT JOIN task_finish_runs AS run ON run.task_id = completion.task_id
34
+ WHERE json_extract(completion.result_json, '$.runId') <> completion.run_id
35
+ OR json_extract(completion.result_json, '$.task') <> completion.task_id
36
+ OR (run.task_id IS NOT NULL AND run.run_id <> completion.run_id)
37
+ OR (run.task_id IS NULL AND completion.status <> 'complete')
38
+ OR (run.task_id IS NULL AND json_type(completion.result_json, '$.result.phases') <> 'array')
39
+ OR (run.task_id IS NULL AND json_array_length(completion.result_json, '$.result.phases') <> 5)
40
+ OR (run.task_id IS NULL AND json_extract(completion.result_json, '$.result.phases[0].id') <> 'preflight')
41
+ OR (run.task_id IS NULL AND json_extract(completion.result_json, '$.result.phases[1].id') <> 'prepare')
42
+ OR (run.task_id IS NULL AND json_extract(completion.result_json, '$.result.phases[2].id') <> 'verify')
43
+ OR (run.task_id IS NULL AND json_extract(completion.result_json, '$.result.phases[3].id') <> 'deliver')
44
+ OR (run.task_id IS NULL AND json_extract(completion.result_json, '$.result.phases[4].id') <> 'cleanup')
45
+ ) THEN 1 ELSE 0 END;
46
+
47
+ INSERT INTO _buildr_task_finish_migration_assertion(valid)
48
+ SELECT CASE WHEN NOT EXISTS (
49
+ SELECT 1
50
+ FROM task_finish_target_leases AS lease
51
+ LEFT JOIN task_finish_runs AS run
52
+ ON run.task_id = lease.task_id AND run.run_id = lease.run_id
53
+ WHERE run.task_id IS NULL
54
+ ) THEN 1 ELSE 0 END;
55
+
56
+ CREATE TABLE task_finish_current (
57
+ task_id TEXT PRIMARY KEY REFERENCES tasks(task_id) ON DELETE CASCADE,
58
+ run_id TEXT NOT NULL UNIQUE,
59
+ schema_version TEXT NOT NULL CHECK (schema_version = 'buildr.task-finish-current/v1'),
60
+ status TEXT NOT NULL CHECK (status IN ('active', 'blocked', 'failed', 'complete', 'cleanup_pending')),
61
+ identity_digest TEXT NOT NULL CHECK (trim(identity_digest) <> ''),
62
+ current_phase TEXT NOT NULL CHECK (current_phase IN ('preflight', 'prepare', 'verify', 'deliver', 'cleanup')),
63
+ handoff_identity TEXT NOT NULL CHECK (trim(handoff_identity) <> ''),
64
+ candidate_identity TEXT NOT NULL CHECK (trim(candidate_identity) <> ''),
65
+ candidate_generation INTEGER NOT NULL CHECK (candidate_generation >= 1),
66
+ content_target_identity TEXT NOT NULL CHECK (trim(content_target_identity) <> ''),
67
+ target_branch TEXT NOT NULL CHECK (trim(target_branch) <> ''),
68
+ target_remote TEXT,
69
+ carrier_identity TEXT,
70
+ association_handoff_identity TEXT,
71
+ association_candidate_identity TEXT,
72
+ association_candidate_generation INTEGER CHECK (association_candidate_generation IS NULL OR association_candidate_generation >= 1),
73
+ planning_gate_target_identity TEXT,
74
+ completion_gate_target_identity TEXT,
75
+ verification_gate_target_identity TEXT,
76
+ primary_failure_phase TEXT CHECK (primary_failure_phase IS NULL OR primary_failure_phase IN ('preflight', 'prepare', 'verify', 'deliver', 'cleanup')),
77
+ primary_failure_operation TEXT,
78
+ primary_failure_class TEXT,
79
+ primary_failure_code TEXT,
80
+ primary_failure_status TEXT,
81
+ primary_failure_exit_code INTEGER,
82
+ primary_failure_diagnostic_digest TEXT,
83
+ resume_phase TEXT CHECK (resume_phase IS NULL OR resume_phase IN ('preflight', 'prepare', 'verify', 'deliver', 'cleanup')),
84
+ resume_token TEXT,
85
+ cleanup_status TEXT,
86
+ lease_target_identity TEXT,
87
+ lease_token TEXT,
88
+ lease_expires_at TEXT,
89
+ phases_json TEXT NOT NULL CHECK (
90
+ json_valid(phases_json)
91
+ AND json_type(phases_json) = 'array'
92
+ AND json_array_length(phases_json) = 5
93
+ AND json_extract(phases_json, '$[0].id') = 'preflight'
94
+ AND json_extract(phases_json, '$[1].id') = 'prepare'
95
+ AND json_extract(phases_json, '$[2].id') = 'verify'
96
+ AND json_extract(phases_json, '$[3].id') = 'deliver'
97
+ AND json_extract(phases_json, '$[4].id') = 'cleanup'
98
+ AND json_extract(phases_json, '$[0].status') IN ('pending', 'running', 'passed', 'blocked', 'failed', 'not-applicable')
99
+ AND json_extract(phases_json, '$[1].status') IN ('pending', 'running', 'passed', 'blocked', 'failed', 'not-applicable')
100
+ AND json_extract(phases_json, '$[2].status') IN ('pending', 'running', 'passed', 'blocked', 'failed', 'not-applicable')
101
+ AND json_extract(phases_json, '$[3].status') IN ('pending', 'running', 'passed', 'blocked', 'failed', 'not-applicable')
102
+ AND json_extract(phases_json, '$[4].status') IN ('pending', 'running', 'passed', 'blocked', 'failed', 'not-applicable')
103
+ AND json_type(phases_json, '$[0].attempts') = 'integer' AND json_extract(phases_json, '$[0].attempts') >= 0
104
+ AND json_type(phases_json, '$[1].attempts') = 'integer' AND json_extract(phases_json, '$[1].attempts') >= 0
105
+ AND json_type(phases_json, '$[2].attempts') = 'integer' AND json_extract(phases_json, '$[2].attempts') >= 0
106
+ AND json_type(phases_json, '$[3].attempts') = 'integer' AND json_extract(phases_json, '$[3].attempts') >= 0
107
+ AND json_type(phases_json, '$[4].attempts') = 'integer' AND json_extract(phases_json, '$[4].attempts') >= 0
108
+ ),
109
+ payload_json TEXT NOT NULL CHECK (json_valid(payload_json) AND json_type(payload_json) = 'object'),
110
+ created_at TEXT NOT NULL CHECK (trim(created_at) <> ''),
111
+ updated_at TEXT NOT NULL CHECK (trim(updated_at) <> ''),
112
+ completed_at TEXT,
113
+ CHECK ((resume_phase IS NULL AND resume_token IS NULL) OR (resume_phase IS NOT NULL AND resume_token IS NOT NULL)),
114
+ CHECK (
115
+ (lease_target_identity IS NULL AND lease_token IS NULL AND lease_expires_at IS NULL)
116
+ OR (lease_target_identity IS NOT NULL AND lease_token IS NOT NULL AND lease_expires_at IS NOT NULL AND status <> 'complete')
117
+ ),
118
+ CHECK (
119
+ (association_handoff_identity IS NULL AND association_candidate_identity IS NULL AND association_candidate_generation IS NULL)
120
+ OR (association_handoff_identity IS NOT NULL AND association_candidate_identity IS NOT NULL AND association_candidate_generation IS NOT NULL)
121
+ ),
122
+ CHECK ((status = 'complete' AND completed_at IS NOT NULL) OR status <> 'complete')
123
+ ) STRICT, WITHOUT ROWID;
124
+
125
+ CREATE INDEX task_finish_current_status_updated_idx
126
+ ON task_finish_current(status, updated_at DESC, task_id);
127
+ CREATE UNIQUE INDEX task_finish_current_lease_target_idx
128
+ ON task_finish_current(lease_target_identity)
129
+ WHERE lease_target_identity IS NOT NULL;
130
+ CREATE UNIQUE INDEX task_finish_current_lease_token_idx
131
+ ON task_finish_current(lease_token)
132
+ WHERE lease_token IS NOT NULL;
133
+
134
+ INSERT INTO task_finish_current(
135
+ task_id, run_id, schema_version, status, identity_digest, current_phase,
136
+ handoff_identity, candidate_identity, candidate_generation, content_target_identity,
137
+ target_branch, target_remote, carrier_identity,
138
+ association_handoff_identity, association_candidate_identity, association_candidate_generation,
139
+ planning_gate_target_identity, completion_gate_target_identity, verification_gate_target_identity,
140
+ primary_failure_phase, primary_failure_operation, primary_failure_class, primary_failure_code,
141
+ primary_failure_status, primary_failure_exit_code, primary_failure_diagnostic_digest,
142
+ resume_phase, resume_token, cleanup_status,
143
+ lease_target_identity, lease_token, lease_expires_at,
144
+ phases_json, payload_json, created_at, updated_at, completed_at
145
+ )
146
+ SELECT
147
+ run.task_id,
148
+ run.run_id,
149
+ 'buildr.task-finish-current/v1',
150
+ run.status,
151
+ run.identity_digest,
152
+ COALESCE(
153
+ json_extract(run.run_json, '$.resume.phase'),
154
+ (SELECT json_extract(phase.value, '$.id') FROM json_each(run.run_json, '$.phases') AS phase WHERE json_extract(phase.value, '$.status') IN ('running', 'blocked', 'failed') ORDER BY CAST(phase.key AS INTEGER) LIMIT 1),
155
+ (SELECT json_extract(phase.value, '$.id') FROM json_each(run.run_json, '$.phases') AS phase WHERE json_extract(phase.value, '$.status') = 'pending' ORDER BY CAST(phase.key AS INTEGER) LIMIT 1),
156
+ 'cleanup'
157
+ ),
158
+ json_extract(run.run_json, '$.identity.handoffIdentity'),
159
+ json_extract(run.run_json, '$.identity.candidateIdentity'),
160
+ json_extract(run.run_json, '$.identity.candidateGeneration'),
161
+ json_extract(run.run_json, '$.identity.contentTargetIdentity'),
162
+ json_extract(run.run_json, '$.identity.targetBranch'),
163
+ json_extract(run.run_json, '$.identity.remote'),
164
+ json_extract(run.run_json, '$.deliveryCarrier.identity'),
165
+ json_extract(completion.result_json, '$.association.handoffIdentity'),
166
+ json_extract(completion.result_json, '$.association.candidateIdentity'),
167
+ json_extract(completion.result_json, '$.association.candidateGeneration'),
168
+ json_extract(completion.result_json, '$.association.gates.planning.targetIdentity'),
169
+ json_extract(completion.result_json, '$.association.gates.completion.targetIdentity'),
170
+ json_extract(completion.result_json, '$.association.gates.verification.targetIdentity'),
171
+ json_extract(run.run_json, '$.primaryFailure.phase'),
172
+ json_extract(run.run_json, '$.primaryFailure.operation'),
173
+ json_extract(run.run_json, '$.primaryFailure.failureClass'),
174
+ json_extract(run.run_json, '$.primaryFailure.code'),
175
+ json_extract(run.run_json, '$.primaryFailure.status'),
176
+ json_extract(run.run_json, '$.primaryFailure.exitCode'),
177
+ json_extract(run.run_json, '$.primaryFailure.diagnostic.digest'),
178
+ json_extract(run.run_json, '$.resume.phase'),
179
+ json_extract(run.run_json, '$.resume.token'),
180
+ COALESCE(json_extract(completion.result_json, '$.cleanup.status'), json_extract(run.run_json, '$.completion.cleanup.status')),
181
+ lease.target_identity,
182
+ lease.token,
183
+ lease.expires_at,
184
+ json_extract(run.run_json, '$.phases'),
185
+ json_object(
186
+ 'kind', 'run',
187
+ 'run', json(json_remove(run.run_json, '$.phases')),
188
+ 'preparedCompletion', CASE WHEN completion.task_id IS NULL THEN NULL ELSE json(completion.result_json) END
189
+ ),
190
+ COALESCE(json_extract(run.run_json, '$.createdAt'), run.updated_at),
191
+ run.updated_at,
192
+ run.completed_at
193
+ FROM task_finish_runs AS run
194
+ LEFT JOIN task_finish_completions AS completion ON completion.task_id = run.task_id
195
+ LEFT JOIN task_finish_target_leases AS lease ON lease.task_id = run.task_id AND lease.run_id = run.run_id;
196
+
197
+ INSERT INTO task_finish_current(
198
+ task_id, run_id, schema_version, status, identity_digest, current_phase,
199
+ handoff_identity, candidate_identity, candidate_generation, content_target_identity,
200
+ target_branch, target_remote, carrier_identity,
201
+ association_handoff_identity, association_candidate_identity, association_candidate_generation,
202
+ planning_gate_target_identity, completion_gate_target_identity, verification_gate_target_identity,
203
+ primary_failure_phase, primary_failure_operation, primary_failure_class, primary_failure_code,
204
+ primary_failure_status, primary_failure_exit_code, primary_failure_diagnostic_digest,
205
+ resume_phase, resume_token, cleanup_status,
206
+ lease_target_identity, lease_token, lease_expires_at,
207
+ phases_json, payload_json, created_at, updated_at, completed_at
208
+ )
209
+ SELECT
210
+ completion.task_id,
211
+ completion.run_id,
212
+ 'buildr.task-finish-current/v1',
213
+ 'complete',
214
+ COALESCE(json_extract(completion.result_json, '$.result.identityDigest'), 'terminal:' || completion.run_id),
215
+ 'cleanup',
216
+ json_extract(completion.result_json, '$.handoffIdentity'),
217
+ json_extract(completion.result_json, '$.candidateIdentity'),
218
+ json_extract(completion.result_json, '$.candidateGeneration'),
219
+ json_extract(completion.result_json, '$.contentTargetIdentity'),
220
+ json_extract(completion.result_json, '$.targetBranch'),
221
+ json_extract(completion.result_json, '$.result.identity.remote'),
222
+ json_extract(completion.result_json, '$.carrierIdentity'),
223
+ json_extract(completion.result_json, '$.association.handoffIdentity'),
224
+ json_extract(completion.result_json, '$.association.candidateIdentity'),
225
+ json_extract(completion.result_json, '$.association.candidateGeneration'),
226
+ json_extract(completion.result_json, '$.association.gates.planning.targetIdentity'),
227
+ json_extract(completion.result_json, '$.association.gates.completion.targetIdentity'),
228
+ json_extract(completion.result_json, '$.association.gates.verification.targetIdentity'),
229
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
230
+ NULL, NULL,
231
+ json_extract(completion.result_json, '$.cleanup.status'),
232
+ NULL, NULL, NULL,
233
+ json_extract(completion.result_json, '$.result.phases'),
234
+ json_object(
235
+ 'kind', 'terminal',
236
+ 'identityDigest', COALESCE(json_extract(completion.result_json, '$.result.identityDigest'), 'terminal:' || completion.run_id),
237
+ 'completion', json(json_remove(completion.result_json, '$.result.phases'))
238
+ ),
239
+ COALESCE(json_extract(completion.result_json, '$.preparedAt'), completion.updated_at),
240
+ completion.updated_at,
241
+ COALESCE(completion.completed_at, json_extract(completion.result_json, '$.completedAt'))
242
+ FROM task_finish_completions AS completion
243
+ LEFT JOIN task_finish_runs AS run ON run.task_id = completion.task_id
244
+ WHERE run.task_id IS NULL;
245
+
246
+ INSERT INTO _buildr_task_finish_migration_assertion(valid)
247
+ SELECT CASE WHEN (
248
+ SELECT COUNT(*) FROM task_finish_current
249
+ ) = (
250
+ SELECT COUNT(*) FROM task_finish_runs
251
+ ) + (
252
+ SELECT COUNT(*) FROM task_finish_completions AS completion
253
+ LEFT JOIN task_finish_runs AS run ON run.task_id = completion.task_id
254
+ WHERE run.task_id IS NULL
255
+ ) THEN 1 ELSE 0 END;
256
+
257
+ DROP TABLE task_finish_transient_artifacts;
258
+ DROP TABLE task_finish_target_leases;
259
+ DROP TABLE task_finish_completions;
260
+ DROP TABLE task_finish_runs;
261
+ DROP TABLE _buildr_task_finish_migration_assertion;
@@ -0,0 +1,56 @@
1
+ -- buildr:foreign-keys-off
2
+ PRAGMA legacy_alter_table = ON;
3
+
4
+ ALTER TABLE tasks RENAME TO tasks_v1;
5
+
6
+ CREATE TABLE tasks (
7
+ task_id TEXT PRIMARY KEY CHECK (
8
+ length(task_id) > 0
9
+ AND task_id NOT GLOB '*[^a-z0-9._-]*'
10
+ AND substr(task_id, 1, 1) GLOB '[a-z0-9]'
11
+ AND substr(task_id, -1, 1) GLOB '[a-z0-9]'
12
+ ),
13
+ schema_version TEXT NOT NULL CHECK (schema_version = 'buildr.task-record/v2'),
14
+ title TEXT NOT NULL CHECK (length(trim(title)) > 0),
15
+ intent TEXT NOT NULL CHECK (length(trim(intent)) > 0),
16
+ status TEXT NOT NULL CHECK (status IN ('todo', 'active', 'completed', 'abandoned')),
17
+ result_summary TEXT,
18
+ result_no_change INTEGER CHECK (result_no_change IN (0, 1)),
19
+ created_at TEXT NOT NULL CHECK (datetime(created_at) IS NOT NULL),
20
+ updated_at TEXT NOT NULL CHECK (datetime(updated_at) IS NOT NULL AND updated_at >= created_at),
21
+ parent_task_id TEXT REFERENCES tasks(task_id) ON DELETE SET NULL
22
+ CHECK (parent_task_id IS NULL OR parent_task_id <> task_id),
23
+ CHECK (
24
+ (status IN ('todo', 'active') AND result_summary IS NULL AND result_no_change IS NULL)
25
+ OR (status = 'completed' AND length(trim(result_summary)) > 0 AND result_no_change IS NOT NULL)
26
+ OR (status = 'abandoned' AND length(trim(result_summary)) > 0 AND result_no_change IS NULL)
27
+ )
28
+ ) STRICT;
29
+
30
+ INSERT INTO tasks(
31
+ task_id, schema_version, title, intent, status, result_summary,
32
+ result_no_change, created_at, updated_at, parent_task_id
33
+ )
34
+ SELECT
35
+ task_id, 'buildr.task-record/v2', title, intent, status, result_summary,
36
+ result_no_change, created_at, updated_at, parent_task_id
37
+ FROM tasks_v1;
38
+
39
+ DROP TABLE tasks_v1;
40
+
41
+ CREATE INDEX tasks_status_updated_at_idx ON tasks(status, updated_at DESC, task_id);
42
+ CREATE INDEX tasks_updated_at_idx ON tasks(updated_at DESC, task_id);
43
+ CREATE INDEX tasks_parent_task_idx ON tasks(parent_task_id, task_id);
44
+
45
+ CREATE TABLE task_retrospective_sources (
46
+ target_task_id TEXT NOT NULL REFERENCES tasks(task_id) ON DELETE CASCADE,
47
+ source_task_id TEXT NOT NULL REFERENCES tasks(task_id) ON DELETE CASCADE,
48
+ created_at TEXT NOT NULL CHECK (datetime(created_at) IS NOT NULL),
49
+ PRIMARY KEY (target_task_id, source_task_id),
50
+ CHECK (target_task_id <> source_task_id)
51
+ ) STRICT, WITHOUT ROWID;
52
+
53
+ CREATE INDEX task_retrospective_sources_source_idx
54
+ ON task_retrospective_sources(source_task_id, target_task_id);
55
+
56
+ PRAGMA legacy_alter_table = OFF;
@@ -0,0 +1,14 @@
1
+ ALTER TABLE task_execution_records
2
+ ADD COLUMN invocation_identity TEXT
3
+ CHECK (
4
+ invocation_identity IS NULL
5
+ OR (
6
+ length(invocation_identity) = 71
7
+ AND substr(invocation_identity, 1, 7) = 'sha256-'
8
+ AND substr(invocation_identity, 8) NOT GLOB '*[^0-9a-f]*'
9
+ )
10
+ );
11
+
12
+ CREATE INDEX task_execution_records_active_invocation_idx
13
+ ON task_execution_records(task_id, owner, kind, invocation_identity, lifecycle_status)
14
+ WHERE lifecycle_status = 'open' AND invocation_identity IS NOT NULL;
@@ -0,0 +1,143 @@
1
+ ALTER TABLE task_execution_records RENAME TO task_execution_records_before_unknown_outcome;
2
+
3
+ CREATE TABLE task_execution_records (
4
+ record_id TEXT PRIMARY KEY,
5
+ schema_version TEXT NOT NULL CHECK (schema_version = 'buildr.task-execution-record/v1'),
6
+ task_id TEXT NOT NULL REFERENCES tasks(task_id),
7
+ owner TEXT NOT NULL CHECK (owner IN ('task-verification', 'task-finish')),
8
+ kind TEXT NOT NULL,
9
+ run_identity TEXT NOT NULL CHECK (trim(run_identity) <> ''),
10
+ invocation_identity TEXT CHECK (
11
+ invocation_identity IS NULL
12
+ OR (
13
+ length(invocation_identity) = 71
14
+ AND substr(invocation_identity, 1, 7) = 'sha256-'
15
+ AND substr(invocation_identity, 8) NOT GLOB '*[^0-9a-f]*'
16
+ )
17
+ ),
18
+ target_identity TEXT NOT NULL CHECK (trim(target_identity) <> ''),
19
+ producer TEXT NOT NULL CHECK (trim(producer) <> ''),
20
+ outcome TEXT NOT NULL CHECK (outcome IN ('running', 'passed', 'failed', 'blocked', 'cancelled', 'unknown')),
21
+ lifecycle_status TEXT NOT NULL CHECK (lifecycle_status IN ('open', 'retained', 'cleanup_pending', 'cleaned', 'attention')),
22
+ resolution_status TEXT NOT NULL CHECK (resolution_status IN ('not-required', 'pending', 'acknowledged', 'recovered')),
23
+ body_status TEXT NOT NULL CHECK (body_status IN ('staging', 'available', 'cleaned')),
24
+ quota_status TEXT NOT NULL CHECK (quota_status IN ('reserved', 'charged', 'released')),
25
+ body_locator TEXT,
26
+ body_digest TEXT,
27
+ stored_size_bytes INTEGER NOT NULL CHECK (stored_size_bytes >= 0 AND stored_size_bytes <= 16777216),
28
+ original_size_bytes INTEGER NOT NULL CHECK (original_size_bytes >= 0),
29
+ truncated INTEGER NOT NULL CHECK (truncated IN (0, 1)),
30
+ redaction_version TEXT NOT NULL CHECK (redaction_version = 'buildr.task-execution-record-redaction/v1'),
31
+ reserved_size_bytes INTEGER NOT NULL CHECK (reserved_size_bytes IN (0, 16777216)),
32
+ retain_until TEXT,
33
+ opened_at TEXT NOT NULL CHECK (trim(opened_at) <> ''),
34
+ sealed_at TEXT,
35
+ resolved_at TEXT,
36
+ cleanup_started_at TEXT,
37
+ cleaned_at TEXT,
38
+ cleanup_code TEXT,
39
+ updated_at TEXT NOT NULL CHECK (trim(updated_at) <> ''),
40
+ UNIQUE (task_id, owner, kind, run_identity),
41
+ CHECK (
42
+ (owner = 'task-verification' AND kind = 'verification-execution')
43
+ OR (owner = 'task-finish' AND kind = 'finish-diagnostics')
44
+ ),
45
+ CHECK (
46
+ (lifecycle_status = 'open'
47
+ AND outcome = 'running'
48
+ AND resolution_status = 'not-required'
49
+ AND body_status = 'staging'
50
+ AND quota_status = 'reserved'
51
+ AND body_locator IS NULL
52
+ AND body_digest IS NULL
53
+ AND stored_size_bytes = 0
54
+ AND original_size_bytes = 0
55
+ AND truncated = 0
56
+ AND reserved_size_bytes = 16777216
57
+ AND retain_until IS NULL
58
+ AND sealed_at IS NULL
59
+ AND resolved_at IS NULL
60
+ AND cleanup_started_at IS NULL
61
+ AND cleaned_at IS NULL
62
+ AND cleanup_code IS NULL)
63
+ OR
64
+ (lifecycle_status IN ('retained', 'attention')
65
+ AND outcome IN ('passed', 'failed', 'blocked', 'cancelled', 'unknown')
66
+ AND body_status = 'available'
67
+ AND quota_status = 'charged'
68
+ AND body_locator GLOB '.buildr/local/task-execution-records/*/*/'
69
+ AND body_digest GLOB 'sha256-*'
70
+ AND length(body_digest) = 71
71
+ AND reserved_size_bytes = 0
72
+ AND retain_until IS NOT NULL
73
+ AND sealed_at IS NOT NULL
74
+ AND cleanup_started_at IS NULL
75
+ AND cleaned_at IS NULL
76
+ AND cleanup_code IS NULL)
77
+ OR
78
+ (lifecycle_status = 'cleanup_pending'
79
+ AND outcome IN ('passed', 'failed', 'blocked', 'cancelled', 'unknown')
80
+ AND body_status = 'available'
81
+ AND quota_status = 'charged'
82
+ AND body_locator GLOB '.buildr/local/task-execution-records/*/*/'
83
+ AND body_digest GLOB 'sha256-*'
84
+ AND length(body_digest) = 71
85
+ AND reserved_size_bytes = 0
86
+ AND retain_until IS NOT NULL
87
+ AND sealed_at IS NOT NULL
88
+ AND cleanup_started_at IS NOT NULL
89
+ AND cleaned_at IS NULL
90
+ AND cleanup_code IS NULL)
91
+ OR
92
+ (lifecycle_status = 'cleaned'
93
+ AND outcome IN ('passed', 'failed', 'blocked', 'cancelled', 'unknown')
94
+ AND body_status = 'cleaned'
95
+ AND quota_status = 'released'
96
+ AND body_locator IS NULL
97
+ AND body_digest GLOB 'sha256-*'
98
+ AND length(body_digest) = 71
99
+ AND reserved_size_bytes = 0
100
+ AND retain_until IS NOT NULL
101
+ AND sealed_at IS NOT NULL
102
+ AND cleanup_started_at IS NULL
103
+ AND cleaned_at IS NOT NULL
104
+ AND cleanup_code IS NOT NULL
105
+ AND trim(cleanup_code) <> '')
106
+ ),
107
+ CHECK (
108
+ (outcome IN ('running', 'passed') AND resolution_status = 'not-required' AND resolved_at IS NULL)
109
+ OR
110
+ (outcome IN ('failed', 'blocked', 'cancelled') AND resolution_status = 'pending' AND resolved_at IS NULL)
111
+ OR
112
+ (outcome IN ('failed', 'blocked', 'cancelled', 'unknown') AND resolution_status IN ('acknowledged', 'recovered') AND resolved_at IS NOT NULL)
113
+ )
114
+ ) STRICT, WITHOUT ROWID;
115
+
116
+ INSERT INTO task_execution_records(
117
+ record_id, schema_version, task_id, owner, kind, run_identity, invocation_identity, target_identity, producer,
118
+ outcome, lifecycle_status, resolution_status, body_status, quota_status, body_locator, body_digest,
119
+ stored_size_bytes, original_size_bytes, truncated, redaction_version, reserved_size_bytes, retain_until,
120
+ opened_at, sealed_at, resolved_at, cleanup_started_at, cleaned_at, cleanup_code, updated_at
121
+ )
122
+ SELECT
123
+ record_id, schema_version, task_id, owner, kind, run_identity, invocation_identity, target_identity, producer,
124
+ outcome, lifecycle_status, resolution_status, body_status, quota_status, body_locator, body_digest,
125
+ stored_size_bytes, original_size_bytes, truncated, redaction_version, reserved_size_bytes, retain_until,
126
+ opened_at, sealed_at, resolved_at, cleanup_started_at, cleaned_at, cleanup_code, updated_at
127
+ FROM task_execution_records_before_unknown_outcome;
128
+
129
+ DROP TABLE task_execution_records_before_unknown_outcome;
130
+
131
+ CREATE INDEX task_execution_records_task_timeline_idx
132
+ ON task_execution_records(task_id, opened_at DESC, record_id);
133
+ CREATE INDEX task_execution_records_task_owner_kind_recent_idx
134
+ ON task_execution_records(task_id, owner, kind, sealed_at DESC, record_id);
135
+ CREATE INDEX task_execution_records_lifecycle_retention_idx
136
+ ON task_execution_records(lifecycle_status, retain_until, task_id, record_id);
137
+ CREATE INDEX task_execution_records_task_owner_quota_idx
138
+ ON task_execution_records(task_id, owner, quota_status);
139
+ CREATE INDEX task_execution_records_workspace_quota_idx
140
+ ON task_execution_records(quota_status);
141
+ CREATE INDEX task_execution_records_active_invocation_idx
142
+ ON task_execution_records(task_id, owner, kind, invocation_identity, lifecycle_status)
143
+ WHERE lifecycle_status = 'open' AND invocation_identity IS NOT NULL;
@@ -0,0 +1,83 @@
1
+ CREATE TABLE task_finish_current_next (
2
+ task_id TEXT PRIMARY KEY REFERENCES tasks(task_id) ON DELETE CASCADE,
3
+ run_id TEXT NOT NULL UNIQUE,
4
+ schema_version TEXT NOT NULL CHECK (schema_version = 'buildr.task-finish-current/v1'),
5
+ status TEXT NOT NULL CHECK (status IN ('active', 'blocked', 'failed', 'complete', 'cleanup_pending')),
6
+ identity_digest TEXT NOT NULL CHECK (trim(identity_digest) <> ''),
7
+ current_phase TEXT NOT NULL CHECK (current_phase IN ('preflight', 'prepare', 'verify', 'deliver', 'cleanup')),
8
+ handoff_identity TEXT NOT NULL CHECK (trim(handoff_identity) <> ''),
9
+ candidate_identity TEXT NOT NULL CHECK (trim(candidate_identity) <> ''),
10
+ candidate_generation INTEGER NOT NULL CHECK (candidate_generation >= 1),
11
+ content_target_identity TEXT NOT NULL CHECK (trim(content_target_identity) <> ''),
12
+ target_branch TEXT NOT NULL CHECK (trim(target_branch) <> ''),
13
+ target_remote TEXT,
14
+ carrier_identity TEXT,
15
+ association_handoff_identity TEXT,
16
+ association_candidate_identity TEXT,
17
+ association_candidate_generation INTEGER CHECK (association_candidate_generation IS NULL OR association_candidate_generation >= 1),
18
+ planning_gate_target_identity TEXT,
19
+ completion_gate_target_identity TEXT,
20
+ verification_gate_target_identity TEXT,
21
+ primary_failure_phase TEXT CHECK (primary_failure_phase IS NULL OR primary_failure_phase IN ('preflight', 'prepare', 'verify', 'deliver', 'cleanup')),
22
+ primary_failure_operation TEXT,
23
+ primary_failure_class TEXT,
24
+ primary_failure_code TEXT,
25
+ primary_failure_status TEXT,
26
+ primary_failure_exit_code INTEGER,
27
+ primary_failure_diagnostic_digest TEXT,
28
+ resume_phase TEXT CHECK (resume_phase IS NULL OR resume_phase IN ('preflight', 'prepare', 'verify', 'deliver', 'cleanup')),
29
+ resume_token TEXT,
30
+ cleanup_status TEXT,
31
+ lease_target_identity TEXT,
32
+ lease_token TEXT,
33
+ lease_expires_at TEXT,
34
+ phases_json TEXT NOT NULL CHECK (
35
+ json_valid(phases_json)
36
+ AND json_type(phases_json) = 'array'
37
+ AND json_array_length(phases_json) = 5
38
+ AND json_extract(phases_json, '$[0].id') = 'preflight'
39
+ AND json_extract(phases_json, '$[1].id') = 'prepare'
40
+ AND json_extract(phases_json, '$[2].id') = 'verify'
41
+ AND json_extract(phases_json, '$[3].id') = 'deliver'
42
+ AND json_extract(phases_json, '$[4].id') = 'cleanup'
43
+ AND json_extract(phases_json, '$[0].status') IN ('pending', 'running', 'passed', 'blocked', 'failed', 'not-applicable')
44
+ AND json_extract(phases_json, '$[1].status') IN ('pending', 'running', 'passed', 'blocked', 'failed', 'not-applicable')
45
+ AND json_extract(phases_json, '$[2].status') IN ('pending', 'running', 'passed', 'blocked', 'failed', 'not-applicable')
46
+ AND json_extract(phases_json, '$[3].status') IN ('pending', 'running', 'passed', 'blocked', 'failed', 'not-applicable')
47
+ AND json_extract(phases_json, '$[4].status') IN ('pending', 'running', 'passed', 'blocked', 'failed', 'not-applicable')
48
+ AND json_type(phases_json, '$[0].attempts') = 'integer' AND json_extract(phases_json, '$[0].attempts') >= 0
49
+ AND json_type(phases_json, '$[1].attempts') = 'integer' AND json_extract(phases_json, '$[1].attempts') >= 0
50
+ AND json_type(phases_json, '$[2].attempts') = 'integer' AND json_extract(phases_json, '$[2].attempts') >= 0
51
+ AND json_type(phases_json, '$[3].attempts') = 'integer' AND json_extract(phases_json, '$[3].attempts') >= 0
52
+ AND json_type(phases_json, '$[4].attempts') = 'integer' AND json_extract(phases_json, '$[4].attempts') >= 0
53
+ ),
54
+ payload_json TEXT NOT NULL CHECK (json_valid(payload_json) AND json_type(payload_json) = 'object'),
55
+ created_at TEXT NOT NULL CHECK (trim(created_at) <> ''),
56
+ updated_at TEXT NOT NULL CHECK (trim(updated_at) <> ''),
57
+ completed_at TEXT,
58
+ CHECK ((resume_phase IS NULL AND resume_token IS NULL) OR (resume_phase IS NOT NULL AND resume_token IS NOT NULL)),
59
+ CHECK (
60
+ (lease_target_identity IS NULL AND lease_token IS NULL AND lease_expires_at IS NULL)
61
+ OR (lease_target_identity IS NOT NULL AND lease_token IS NOT NULL AND lease_expires_at IS NOT NULL)
62
+ ),
63
+ CHECK (
64
+ (association_handoff_identity IS NULL AND association_candidate_identity IS NULL AND association_candidate_generation IS NULL)
65
+ OR (association_handoff_identity IS NOT NULL AND association_candidate_identity IS NOT NULL AND association_candidate_generation IS NOT NULL)
66
+ ),
67
+ CHECK ((status = 'complete' AND completed_at IS NOT NULL) OR status <> 'complete')
68
+ ) STRICT, WITHOUT ROWID;
69
+
70
+ INSERT INTO task_finish_current_next SELECT * FROM task_finish_current;
71
+
72
+ DROP TABLE task_finish_current;
73
+
74
+ ALTER TABLE task_finish_current_next RENAME TO task_finish_current;
75
+
76
+ CREATE INDEX task_finish_current_status_updated_idx
77
+ ON task_finish_current(status, updated_at DESC, task_id);
78
+ CREATE UNIQUE INDEX task_finish_current_lease_target_idx
79
+ ON task_finish_current(lease_target_identity)
80
+ WHERE lease_target_identity IS NOT NULL;
81
+ CREATE UNIQUE INDEX task_finish_current_lease_token_idx
82
+ ON task_finish_current(lease_token)
83
+ WHERE lease_token IS NOT NULL;