thinkwork-cli 0.12.16 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/cli.js +517 -10403
  2. package/dist/commands/enterprise/templates/deploy-repo/docs/runbook.md +3 -8
  3. package/dist/commands/enterprise/templates/deploy-repo/terraform/main.tf +1 -184
  4. package/dist/drizzle/0050_brain_v0_entity_subtype.sql +2 -2
  5. package/dist/drizzle/0051_brain_v0_tenant_entity_pages.sql +6 -6
  6. package/dist/drizzle/0052_brain_v0_external_refs.sql +2 -2
  7. package/dist/drizzle/0053_brain_v0_unresolved_mentions_subtype.sql +2 -2
  8. package/dist/drizzle/0145_knowledge_graph_thread_ingest.sql +14 -14
  9. package/dist/drizzle/0146_knowledge_graph_source_scope.sql +1 -1
  10. package/dist/drizzle/0157_knowledge_graph_observations_source.sql +2 -2
  11. package/dist/drizzle/0158_wiki_tenant_scope.sql +1 -1
  12. package/dist/drizzle/0165_plugin_premium_entitlements.sql +2 -2
  13. package/dist/drizzle/{0166_company_brain_substrate_contract.sql → 0166_brain_substrate_contract.sql} +9 -9
  14. package/dist/drizzle/{0167_company_brain_artifact_manifest_runtime.sql → 0167_brain_artifact_manifest_runtime.sql} +5 -5
  15. package/dist/drizzle/0168_eval_skill_gate.sql +1 -1
  16. package/dist/drizzle/0183_okf_artifact_manifests.sql +1 -1
  17. package/dist/drizzle/0200_eval_results_execution_tier.sql +40 -0
  18. package/dist/drizzle/0201_brain_dream_runs.sql +72 -0
  19. package/dist/drizzle/0202_backfill_thread_participants_from_senders.sql +110 -0
  20. package/dist/drizzle/0203_threads_mode_override.sql +61 -0
  21. package/dist/drizzle/0204_thread_turns_triggering_message_id.sql +48 -0
  22. package/dist/drizzle/0205_routines_git_python.sql +185 -0
  23. package/dist/drizzle/0206_agent_loop_versions_routine_actions.sql +40 -0
  24. package/dist/drizzle/0207_tenant_credentials_github_repo_kind.sql +52 -0
  25. package/dist/drizzle/0208_knowledge_graph_neutral_identifiers.sql +253 -0
  26. package/dist/drizzle/0209_living_artifacts_schema.sql +109 -0
  27. package/dist/drizzle/0210_think137_automations_additive_schema.sql +113 -0
  28. package/dist/drizzle/0211_backfill_agent_loop_versions_target_spec.sql +120 -0
  29. package/dist/drizzle/0212_fold_webhooks_into_automations.sql +312 -0
  30. package/dist/drizzle/0213_agent_loop_versions_judge_evidence_nullable.sql +63 -0
  31. package/dist/drizzle/0214_think137_drop_judge_evidence_roi.sql +99 -0
  32. package/dist/drizzle/0215_agent_loop_versions_goal_worker_policy_nullable.sql +70 -0
  33. package/dist/drizzle/0216_drop_agent_loop_versions_goal_worker_policy.sql +81 -0
  34. package/dist/drizzle/0217_agents_capability_folder_dispatch.sql +12 -0
  35. package/dist/drizzle/0218_document_plates.sql +30 -0
  36. package/dist/drizzle/0219_document_section_waivers.sql +29 -0
  37. package/dist/drizzle/0220_artifacts_created_by_user.sql +21 -0
  38. package/dist/drizzle/0221_artifact_shares.sql +29 -0
  39. package/dist/drizzle/0221_workflow_interpreter_thin_slice.sql +71 -0
  40. package/dist/drizzle/0222_compliance_drainer_select_audit_events.sql +21 -0
  41. package/dist/drizzle/0223_document_conformance_reports.sql +38 -0
  42. package/dist/drizzle/0224_artifact_refresh_state.sql +11 -0
  43. package/dist/drizzle/0225_think216_agent_loop_convergence.sql +21 -0
  44. package/dist/drizzle/0226_drop_n8n_agent_step_runs.sql +6 -0
  45. package/dist/drizzle/0227_analyst_reader_role.sql +1055 -0
  46. package/dist/drizzle/0228_tenant_credentials_rds_iam_kind.sql +62 -0
  47. package/dist/drizzle/0229_analyst_reader_rds_iam_grant.sql +79 -0
  48. package/dist/drizzle/0230_analyst_rls.sql +1613 -0
  49. package/dist/drizzle/0231_cost_events_cache_write_enforcement_exempt.sql +11 -0
  50. package/dist/plugins/catalog/package.json +0 -1
  51. package/dist/plugins/catalog/src/__tests__/build-catalog.test.ts +0 -1
  52. package/dist/plugins/catalog/src/__tests__/catalog.test.ts +16 -8
  53. package/dist/plugins/catalog/src/__tests__/contracts.test.ts +56 -0
  54. package/dist/plugins/catalog/src/__tests__/plugin-package.test.ts +0 -2
  55. package/dist/plugins/catalog/src/__tests__/plugin-registry.test.ts +0 -5
  56. package/dist/plugins/catalog/src/contracts.ts +112 -0
  57. package/dist/plugins/catalog/src/registry/generated-first-party.ts +0 -6
  58. package/dist/plugins/n8n/README.md +4 -36
  59. package/dist/plugins/n8n/src/deployment/managed-app.ts +0 -17
  60. package/dist/plugins/n8n/src/manifest.ts +0 -5
  61. package/dist/plugins/n8n/terraform/n8n/main.tf +0 -26
  62. package/dist/plugins/n8n/terraform/n8n/outputs.tf +0 -5
  63. package/dist/plugins/n8n/terraform/n8n/variables.tf +0 -6
  64. package/dist/plugins/n8n/test/manifest.test.ts +0 -1
  65. package/dist/plugins/twenty/package.json +5 -0
  66. package/dist/plugins/twenty/scripts/lib/__tests__/load-records.test.ts +232 -0
  67. package/dist/plugins/twenty/scripts/lib/__tests__/mappers.test.ts +489 -0
  68. package/dist/plugins/twenty/scripts/lib/__tests__/members-ensure.test.ts +199 -0
  69. package/dist/plugins/twenty/scripts/lib/__tests__/provision-members-db.test.ts +43 -0
  70. package/dist/plugins/twenty/scripts/lib/__tests__/schema-ensure.test.ts +230 -0
  71. package/dist/plugins/twenty/scripts/lib/__tests__/twenty-client.test.ts +207 -0
  72. package/dist/plugins/twenty/scripts/lib/lastmile-reader.ts +282 -0
  73. package/dist/plugins/twenty/scripts/lib/load-attachments.ts +220 -0
  74. package/dist/plugins/twenty/scripts/lib/load-records.ts +680 -0
  75. package/dist/plugins/twenty/scripts/lib/mappers.ts +559 -0
  76. package/dist/plugins/twenty/scripts/lib/members-ensure.ts +381 -0
  77. package/dist/plugins/twenty/scripts/lib/provision-members-db.ts +191 -0
  78. package/dist/plugins/twenty/scripts/lib/schema-ensure.ts +425 -0
  79. package/dist/plugins/twenty/scripts/lib/twenty-client.ts +246 -0
  80. package/dist/plugins/twenty/scripts/migrate-lastmile.ts +610 -0
  81. package/dist/plugins/twenty/scripts/provision-twenty-members.ts +214 -0
  82. package/dist/plugins/twenty/src/manifest.ts +99 -0
  83. package/dist/plugins/twenty/terraform/twenty/README.md +1 -1
  84. package/dist/plugins/twenty/test/manifest.test.ts +12 -2
  85. package/dist/terraform/examples/greenfield/main.tf +90 -380
  86. package/dist/terraform/examples/greenfield/terraform.tfvars.example +0 -1
  87. package/dist/terraform/modules/app/agentcore-pi/README.md +1 -3
  88. package/dist/terraform/modules/app/agentcore-pi/main.tf +29 -38
  89. package/dist/terraform/modules/app/agentcore-pi/variables.tf +23 -15
  90. package/dist/terraform/modules/app/agentcore-runtime/main.tf +3 -3
  91. package/dist/terraform/modules/app/customer-domain/main.tf +16 -2
  92. package/dist/terraform/modules/app/deployment-control-plane/main.tf +5 -0
  93. package/dist/terraform/modules/app/deployment-control-plane/runner.py +85 -207
  94. package/dist/terraform/modules/app/deployment-control-plane/test_runner_bundle.py +56 -2
  95. package/dist/terraform/modules/app/hindsight-memory/main.tf +52 -4
  96. package/dist/terraform/modules/app/lambda-api/eval-fanout.tf +7 -0
  97. package/dist/terraform/modules/app/lambda-api/handlers.tf +493 -89
  98. package/dist/terraform/modules/app/lambda-api/iam-grouped.tf +215 -96
  99. package/dist/terraform/modules/app/lambda-api/main.tf +24 -5
  100. package/dist/terraform/modules/app/lambda-api/outputs.tf +19 -11
  101. package/dist/terraform/modules/app/lambda-api/variables.tf +94 -67
  102. package/dist/terraform/modules/app/ses-email/main.tf +14 -2
  103. package/dist/terraform/modules/app/workflow-interpreter-stepfunctions/main.tf +493 -0
  104. package/dist/terraform/modules/app/workflow-interpreter-stepfunctions/outputs.tf +34 -0
  105. package/dist/terraform/modules/app/workflow-interpreter-stepfunctions/variables.tf +32 -0
  106. package/dist/terraform/modules/data/aurora-postgres/main.tf +55 -0
  107. package/dist/terraform/modules/data/aurora-postgres/outputs.tf +15 -0
  108. package/dist/terraform/modules/data/s3-buckets/main.tf +26 -0
  109. package/dist/terraform/modules/thinkwork/README.md +0 -1
  110. package/dist/terraform/modules/thinkwork/main.tf +167 -446
  111. package/dist/terraform/modules/thinkwork/outputs.tf +2 -142
  112. package/dist/terraform/modules/thinkwork/variables.tf +55 -309
  113. package/dist/terraform/schema.graphql +4 -0
  114. package/dist/workspace-defaults/files/AGENTS.md +45 -31
  115. package/dist/workspace-defaults/files/CONTEXT.md +48 -4
  116. package/dist/workspace-defaults/files/GUARDRAILS.md +18 -0
  117. package/dist/workspace-defaults/files/MEMORY_GUIDE.md +32 -4
  118. package/dist/workspace-defaults/files/SPACE.md +34 -19
  119. package/dist/workspace-defaults/files/TOOLS.md +30 -0
  120. package/dist/workspace-defaults/files/skills/document-composer/SKILL.md +154 -0
  121. package/dist/workspace-defaults/files/skills/document-composer/references/authoring-rules.md +101 -0
  122. package/package.json +1 -1
  123. package/dist/plugins/company-brain/README.md +0 -37
  124. package/dist/plugins/company-brain/package.json +0 -33
  125. package/dist/plugins/company-brain/runtime/cognee/Dockerfile +0 -11
  126. package/dist/plugins/company-brain/smoke/cognee-managed-app-smoke.mjs +0 -458
  127. package/dist/plugins/company-brain/smoke/cognee-memory-cutover-smoke.mjs +0 -539
  128. package/dist/plugins/company-brain/smoke/company-brain-context-engine-smoke.mjs +0 -312
  129. package/dist/plugins/company-brain/smoke/company-brain-operations-smoke.mjs +0 -449
  130. package/dist/plugins/company-brain/smoke/company-brain-plugin-smoke.mjs +0 -655
  131. package/dist/plugins/company-brain/smoke/hindsight-memory-isolation-smoke.mjs +0 -474
  132. package/dist/plugins/company-brain/src/api/cognee-client.ts +0 -896
  133. package/dist/plugins/company-brain/src/api/cognee-cluster-identity.ts +0 -49
  134. package/dist/plugins/company-brain/src/api/cognee-memory-scope.ts +0 -84
  135. package/dist/plugins/company-brain/src/api/context-engine-provider.ts +0 -888
  136. package/dist/plugins/company-brain/src/api/migration.ts +0 -665
  137. package/dist/plugins/company-brain/src/deployment/cognee-managed-app.ts +0 -396
  138. package/dist/plugins/company-brain/src/index.ts +0 -62
  139. package/dist/plugins/company-brain/src/manifest.ts +0 -112
  140. package/dist/plugins/company-brain/terraform/cognee/README.md +0 -263
  141. package/dist/plugins/company-brain/terraform/cognee/main.tf +0 -766
  142. package/dist/plugins/company-brain/terraform/cognee/outputs.tf +0 -144
  143. package/dist/plugins/company-brain/terraform/cognee/variables.tf +0 -402
  144. package/dist/plugins/company-brain/test/api/cognee-client.test.ts +0 -562
  145. package/dist/plugins/company-brain/test/api/cognee-memory-scope.test.ts +0 -74
  146. package/dist/plugins/company-brain/test/api/context-engine-provider.test.ts +0 -447
  147. package/dist/plugins/company-brain/test/api/migration.test.ts +0 -465
  148. package/dist/plugins/company-brain/test/manifest.test.ts +0 -95
  149. package/dist/plugins/company-brain/tsconfig.json +0 -8
@@ -0,0 +1,29 @@
1
+ -- THINK-183 U5: per-document section waivers (suitability waivers).
2
+ -- A plate's section manifest can require sections; when the model cannot
3
+ -- back one with data it waives explicitly, and the waiver is recorded here
4
+ -- so counts and reasons are queryable per document and per plate (the
5
+ -- THINK-189 conformance seam). Rows are rewritten per emission head
6
+ -- (delete + reinsert). Additive — safe to apply ahead of code deploy.
7
+ --
8
+ -- Hand-rolled (drizzle meta journal is not in use for this change);
9
+ -- apply with: psql "$DATABASE_URL" -f drizzle/0219_document_section_waivers.sql
10
+ -- creates: public.document_section_waivers
11
+
12
+ CREATE TABLE IF NOT EXISTS public.document_section_waivers (
13
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
14
+ tenant_id uuid NOT NULL REFERENCES public.tenants(id) ON DELETE CASCADE,
15
+ artifact_id uuid NOT NULL REFERENCES public.artifacts(id) ON DELETE CASCADE,
16
+ plate_slug text NOT NULL,
17
+ section_id text NOT NULL,
18
+ tier text NOT NULL,
19
+ reason text NOT NULL,
20
+ created_at timestamptz NOT NULL DEFAULT now(),
21
+ CONSTRAINT document_section_waivers_tier_check
22
+ CHECK (tier IN ('required', 'required-if-material'))
23
+ );
24
+
25
+ CREATE UNIQUE INDEX IF NOT EXISTS document_section_waivers_artifact_section_uidx
26
+ ON public.document_section_waivers (artifact_id, section_id);
27
+
28
+ CREATE INDEX IF NOT EXISTS document_section_waivers_tenant_plate_idx
29
+ ON public.document_section_waivers (tenant_id, plate_slug);
@@ -0,0 +1,21 @@
1
+ -- Artifacts carry the generating user directly: created_by_user_id is
2
+ -- stamped at creation (source thread's owner, or the acting caller) so list
3
+ -- surfaces resolve the User column without a thread join. Nullable: system
4
+ -- jobs with no user context. The backfill below covers all pre-existing rows
5
+ -- reachable through their source thread. Additive — safe to apply ahead of
6
+ -- code deploy.
7
+ --
8
+ -- Hand-rolled (drizzle meta journal is not in use for this change);
9
+ -- apply with: psql "$DATABASE_URL" -f drizzle/0220_artifacts_created_by_user.sql
10
+ -- creates-column: public.artifacts.created_by_user_id
11
+
12
+ ALTER TABLE public.artifacts
13
+ ADD COLUMN IF NOT EXISTS created_by_user_id uuid REFERENCES public.users(id);
14
+
15
+ -- Backfill existing artifacts from their source thread's owner.
16
+ UPDATE public.artifacts a
17
+ SET created_by_user_id = t.user_id
18
+ FROM public.threads t
19
+ WHERE a.thread_id = t.id
20
+ AND a.created_by_user_id IS NULL
21
+ AND t.user_id IS NOT NULL;
@@ -0,0 +1,29 @@
1
+ -- THINK-208 U1: public artifact share links.
2
+ -- One row per public "anyone with the link" grant on a document artifact.
3
+ -- The URL token is an HMAC signature over id — no token material at rest.
4
+ -- Revoke-only lifecycle (revoked_at flips the row dead); artifact delete
5
+ -- cascades rows away so the link 404s. Additive — safe to apply ahead of
6
+ -- code deploy.
7
+ --
8
+ -- Hand-rolled (drizzle meta journal is not in use for this change);
9
+ -- apply with: psql "$DATABASE_URL" -f drizzle/0221_artifact_shares.sql
10
+ -- creates: public.artifact_shares
11
+
12
+ CREATE TABLE IF NOT EXISTS public.artifact_shares (
13
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
14
+ tenant_id uuid NOT NULL REFERENCES public.tenants(id) ON DELETE CASCADE,
15
+ artifact_id uuid NOT NULL REFERENCES public.artifacts(id) ON DELETE CASCADE,
16
+ created_by uuid NOT NULL REFERENCES public.users(id),
17
+ created_at timestamptz NOT NULL DEFAULT now(),
18
+ revoked_at timestamptz,
19
+ revoked_by uuid REFERENCES public.users(id)
20
+ );
21
+
22
+ -- One active public link per artifact (get-or-create dedupe, R4).
23
+ CREATE UNIQUE INDEX IF NOT EXISTS artifact_shares_active_artifact_uidx
24
+ ON public.artifact_shares (artifact_id)
25
+ WHERE revoked_at IS NULL;
26
+
27
+ -- Operator tenant-wide share list.
28
+ CREATE INDEX IF NOT EXISTS artifact_shares_tenant_created_idx
29
+ ON public.artifact_shares (tenant_id, created_at);
@@ -0,0 +1,71 @@
1
+ -- THINK-219 U2: workflow interpreter thin slice — additive schema room.
2
+ -- Contents:
3
+ -- * workflow_runs_status_check widened with 'waiting_for_human' (approval
4
+ -- suspension state for task-token waits).
5
+ -- * workflow_engine_bindings_type_check widened with
6
+ -- 'step_functions_interpreter' (the shared interpreter machine binding).
7
+ -- * scheduled_jobs.workflow_id — nullable FK binding a schedule trigger to
8
+ -- a workflow (workflow_schedule trigger type; trigger_type itself is
9
+ -- unconstrained text, no CHECK exists for it).
10
+ -- * workflow_task_tokens — Step Functions task-token store keyed by
11
+ -- (run, step, iteration, purpose); tokens never travel in payloads.
12
+ --
13
+ -- NOT done here (deliberately): no agent_loops changes, no destructive
14
+ -- drops, no event_type constraints (workflow_run_events.event_type stays
15
+ -- convention-enforced text).
16
+ --
17
+ -- Hand-rolled (drizzle meta journal is not in use for this change);
18
+ -- apply with: psql "$DATABASE_URL" -f drizzle/0221_workflow_interpreter_thin_slice.sql
19
+ -- creates: public.workflow_task_tokens
20
+ -- creates-column: public.scheduled_jobs.workflow_id
21
+ -- creates-constraint: public.workflow_runs.workflow_runs_status_check
22
+ -- creates-constraint: public.workflow_engine_bindings.workflow_engine_bindings_type_check
23
+
24
+ ALTER TABLE public.workflow_runs
25
+ DROP CONSTRAINT IF EXISTS workflow_runs_status_check;
26
+ ALTER TABLE public.workflow_runs
27
+ ADD CONSTRAINT workflow_runs_status_check CHECK (
28
+ status IN (
29
+ 'queued', 'running', 'waiting_for_human', 'succeeded', 'failed',
30
+ 'canceled', 'timed_out', 'blocked_not_ready'
31
+ )
32
+ );
33
+
34
+ ALTER TABLE public.workflow_engine_bindings
35
+ DROP CONSTRAINT IF EXISTS workflow_engine_bindings_type_check;
36
+ ALTER TABLE public.workflow_engine_bindings
37
+ ADD CONSTRAINT workflow_engine_bindings_type_check CHECK (
38
+ binding_type IN (
39
+ 'step_functions_routine', 'step_functions_interpreter', 'n8n_bridge',
40
+ 'n8n_import', 'twenty_crm', 'connected_app', 'native'
41
+ )
42
+ );
43
+
44
+ ALTER TABLE public.scheduled_jobs
45
+ ADD COLUMN IF NOT EXISTS workflow_id uuid REFERENCES public.workflows(id) ON DELETE CASCADE;
46
+
47
+ CREATE INDEX IF NOT EXISTS idx_scheduled_jobs_workflow
48
+ ON public.scheduled_jobs (workflow_id);
49
+
50
+ CREATE TABLE IF NOT EXISTS public.workflow_task_tokens (
51
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
52
+ tenant_id uuid NOT NULL REFERENCES public.tenants(id) ON DELETE CASCADE,
53
+ workflow_run_id uuid NOT NULL REFERENCES public.workflow_runs(id) ON DELETE CASCADE,
54
+ step_id text NOT NULL,
55
+ iteration integer NOT NULL DEFAULT 1,
56
+ purpose text NOT NULL,
57
+ token text NOT NULL,
58
+ status text NOT NULL DEFAULT 'pending',
59
+ consumed_at timestamptz,
60
+ created_at timestamptz NOT NULL DEFAULT now(),
61
+ CONSTRAINT workflow_task_tokens_purpose_check
62
+ CHECK (purpose IN ('agent_step', 'approval')),
63
+ CONSTRAINT workflow_task_tokens_status_check
64
+ CHECK (status IN ('pending', 'consumed', 'expired'))
65
+ );
66
+
67
+ CREATE UNIQUE INDEX IF NOT EXISTS workflow_task_tokens_step_uidx
68
+ ON public.workflow_task_tokens (workflow_run_id, step_id, iteration, purpose);
69
+
70
+ CREATE INDEX IF NOT EXISTS workflow_task_tokens_tenant_idx
71
+ ON public.workflow_task_tokens (tenant_id);
@@ -0,0 +1,21 @@
1
+ -- Compliance outbox drainer: grant SELECT on audit_events.
2
+ --
3
+ -- The drainer computes the per-tenant hash chain by reading the current
4
+ -- chain head (`SELECT event_hash FROM compliance.audit_events WHERE
5
+ -- tenant_id = … ORDER BY … LIMIT 1`, compliance-outbox-drainer.ts) before
6
+ -- INSERTing the next event. 0070 granted INSERT but not SELECT, so every
7
+ -- drain attempt fails with "permission denied for table audit_events" and
8
+ -- the outbox backlog grows (observed on dev: all events since 2026-05-07
9
+ -- stuck with that drainer_error). Read access to the append-only log does
10
+ -- not weaken the immutability boundary — DELETE/TRUNCATE/UPDATE remain
11
+ -- ungranted and the U1 triggers still apply.
12
+ --
13
+ -- Hand-rolled (drizzle meta journal is not in use for this change);
14
+ -- apply with: psql "$DATABASE_URL" -f drizzle/0222_compliance_drainer_select_audit_events.sql
15
+ -- creates: public._noop_marker_0222 (grants-only migration; marker view for the drift reporter)
16
+
17
+ GRANT SELECT ON compliance.audit_events TO compliance_drainer;
18
+
19
+ -- Drift-reporter marker: grants aren't introspectable via the reporter's
20
+ -- object checks, so declare a tiny marker view it can verify.
21
+ CREATE OR REPLACE VIEW public._noop_marker_0222 AS SELECT 1 AS applied;
@@ -0,0 +1,38 @@
1
+ -- THINK-189 U2: per-emission document conformance reports.
2
+ -- One row per successful emission on a manifest-bearing plate: deterministic
3
+ -- structural facts recorded at the emission seam, judge columns filled
4
+ -- asynchronously by the conformance judge sweeper. Rows append as a corpus
5
+ -- (never head-rewritten). Additive — safe to apply ahead of code deploy.
6
+ --
7
+ -- Hand-rolled (drizzle meta journal is not in use for this change);
8
+ -- apply with: psql "$DATABASE_URL" -f drizzle/0223_document_conformance_reports.sql
9
+ -- creates: public.document_conformance_reports
10
+
11
+ CREATE TABLE IF NOT EXISTS public.document_conformance_reports (
12
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
13
+ tenant_id uuid NOT NULL REFERENCES public.tenants(id) ON DELETE CASCADE,
14
+ artifact_id uuid NOT NULL REFERENCES public.artifacts(id) ON DELETE CASCADE,
15
+ plate_slug text NOT NULL,
16
+ document_status text NOT NULL,
17
+ digest_revision text NOT NULL,
18
+ manifest_snapshot jsonb NOT NULL,
19
+ sections jsonb NOT NULL,
20
+ analyses jsonb NOT NULL,
21
+ judge_status text NOT NULL DEFAULT 'pending',
22
+ judge_attempts integer NOT NULL DEFAULT 0,
23
+ judge_model text,
24
+ judge_findings jsonb,
25
+ judge_completed_at timestamptz,
26
+ judge_error text,
27
+ created_at timestamptz NOT NULL DEFAULT now(),
28
+ CONSTRAINT document_conformance_reports_judge_status_check
29
+ CHECK (judge_status IN ('pending', 'complete', 'error', 'skipped'))
30
+ );
31
+
32
+ CREATE INDEX IF NOT EXISTS document_conformance_reports_tenant_plate_created_idx
33
+ ON public.document_conformance_reports (tenant_id, plate_slug, created_at);
34
+
35
+ -- Sweeper scan: pending rows only, oldest first.
36
+ CREATE INDEX IF NOT EXISTS document_conformance_reports_judge_pending_idx
37
+ ON public.document_conformance_reports (created_at)
38
+ WHERE judge_status = 'pending';
@@ -0,0 +1,11 @@
1
+ -- THINK-155 U3: scheduled-refresh observability on document artifacts.
2
+ -- Hand-rolled (db:generate is retired). Stamped only by the run-derived
3
+ -- emission path: success sets last_refresh_at and clears refresh_failed_at;
4
+ -- a failed scheduled refresh sets refresh_failed_at while the last good
5
+ -- finalized head stays in place.
6
+ -- creates-column: public.artifacts.last_refresh_at
7
+ -- creates-column: public.artifacts.refresh_failed_at
8
+
9
+ ALTER TABLE public.artifacts
10
+ ADD COLUMN IF NOT EXISTS last_refresh_at timestamptz,
11
+ ADD COLUMN IF NOT EXISTS refresh_failed_at timestamptz;
@@ -0,0 +1,21 @@
1
+ -- THINK-216: Automations (agent_loops) migrate to canonical workflows.
2
+ -- Hand-rolled (db:generate is retired).
3
+ -- workflows.source_agent_loop_id — idempotency + provenance link for the
4
+ -- migration (one workflow per migrated loop; plain uuid, no FK, so the
5
+ -- eventual agent_loops DROP needs no dependent-constraint ordering).
6
+ -- webhooks.workflow_id — webhook rows repointed from an Automation to its
7
+ -- workflow; the webhooks handler's `workflow` target branch starts a
8
+ -- shared-interpreter run.
9
+ -- creates-column: public.workflows.source_agent_loop_id
10
+ -- creates-column: public.webhooks.workflow_id
11
+ -- creates: public.workflows_source_agent_loop_uidx
12
+
13
+ ALTER TABLE public.workflows
14
+ ADD COLUMN IF NOT EXISTS source_agent_loop_id uuid;
15
+
16
+ CREATE UNIQUE INDEX IF NOT EXISTS workflows_source_agent_loop_uidx
17
+ ON public.workflows (tenant_id, source_agent_loop_id)
18
+ WHERE source_agent_loop_id IS NOT NULL;
19
+
20
+ ALTER TABLE public.webhooks
21
+ ADD COLUMN IF NOT EXISTS workflow_id uuid REFERENCES public.workflows(id) ON DELETE CASCADE;
@@ -0,0 +1,6 @@
1
+ -- THINK-217/218: drop the retired n8n agent-step bridge run table. The
2
+ -- code-removal deploy (PR #3519) landed first per the migration ordering
3
+ -- rules; no readers or writers remain.
4
+ -- drops: public.n8n_agent_step_runs
5
+
6
+ DROP TABLE IF EXISTS public.n8n_agent_step_runs;