thinkwork-cli 0.13.1 → 0.13.2

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 (130) hide show
  1. package/dist/{api-client-4DZ266J5.js → api-client-JYZXYQJR.js} +3 -1
  2. package/dist/bowser-6Z6JFAIR.js +2822 -0
  3. package/dist/chunk-DV3MRBR5.js +43 -0
  4. package/dist/chunk-DVPBI5HM.js +1728 -0
  5. package/dist/chunk-EI5ZX7CN.js +522 -0
  6. package/dist/chunk-EUJ7X6YD.js +126 -0
  7. package/dist/chunk-GG5WKBOX.js +436 -0
  8. package/dist/chunk-I64EZSU5.js +358 -0
  9. package/dist/chunk-ILZKG5WV.js +6151 -0
  10. package/dist/chunk-KMIJ5KGT.js +128 -0
  11. package/dist/chunk-OCPHU34C.js +996 -0
  12. package/dist/chunk-QOERT44A.js +3286 -0
  13. package/dist/chunk-XYM7PE2A.js +2264 -0
  14. package/dist/{chunk-Y2WHJECR.js → chunk-Z2F6RJFR.js} +1 -39
  15. package/dist/cli.js +43080 -13150
  16. package/dist/dist-es-CRV46D5B.js +315 -0
  17. package/dist/dist-es-DCY4IC3Y.js +2000 -0
  18. package/dist/dist-es-ENBUC3JP.js +14726 -0
  19. package/dist/dist-es-G54LBMRN.js +48 -0
  20. package/dist/dist-es-G7PTG75M.js +176 -0
  21. package/dist/dist-es-GKDBE7E6.js +88 -0
  22. package/dist/dist-es-HY3535OI.js +70 -0
  23. package/dist/dist-es-KL7Y5NB2.js +377 -0
  24. package/dist/dist-es-LDE437AM.js +170 -0
  25. package/dist/dist-es-P26FWFLT.js +485 -0
  26. package/dist/dist-es-Q57SZXZ7.js +70 -0
  27. package/dist/dist-es-R7FGL2IB.js +88 -0
  28. package/dist/dist-es-USORBXZ5.js +318 -0
  29. package/dist/dist-es-ZKC2QKD2.js +377 -0
  30. package/dist/drizzle/0076_scheduled_jobs_marco_backfill.sql +2 -1
  31. package/dist/drizzle/0079_seed_tenant_customize_catalog.sql +1 -0
  32. package/dist/drizzle/0090_brain_schema_extraction.sql +10 -0
  33. package/dist/drizzle/0132_drop_computer_tables.sql +3 -0
  34. package/dist/drizzle/0160_compliance_event_types_plugins.sql +2 -0
  35. package/dist/drizzle/0214_think137_drop_judge_evidence_roi.sql +1 -0
  36. package/dist/drizzle/0216_drop_agent_loop_versions_goal_worker_policy.sql +1 -0
  37. package/dist/drizzle/0227_analyst_reader_role.sql +6 -0
  38. package/dist/drizzle/0230_analyst_rls.sql +9 -0
  39. package/dist/drizzle/0250_kg_schema_extraction.sql +27 -0
  40. package/dist/drizzle/0251_brain_stragglers.sql +21 -0
  41. package/dist/drizzle/0253_drop_brain_substrate.sql +2 -0
  42. package/dist/drizzle/0257_agents_runtime_allow_harness.sql +24 -0
  43. package/dist/drizzle/0261_managed_harness_multiplayer.sql +313 -0
  44. package/dist/drizzle/0261_native_auth_control_plane.sql +328 -0
  45. package/dist/drizzle/0262_auth_subscription_tickets.sql +59 -0
  46. package/dist/drizzle/0262_parallel_harness_threads.sql +9 -0
  47. package/dist/drizzle/0263_agentcore_runtime_identifier.sql +69 -0
  48. package/dist/drizzle/0263_drop_workos_auth_runtime.sql +236 -0
  49. package/dist/drizzle/0264_auth_enrollment_attempt_limits.sql +15 -0
  50. package/dist/drizzle/0264_harness_tool_execution_ledger.sql +113 -0
  51. package/dist/drizzle/0265_eval_runs_requester_identity.sql +28 -0
  52. package/dist/drizzle/0265_require_fully_valid_auth_publication.sql +27 -0
  53. package/dist/drizzle/0266_auth_identity_recovery_grants.sql +9 -0
  54. package/dist/drizzle/0266_eval_profiles_runtime_type.sql +12 -0
  55. package/dist/drizzle/0267_ontology_candidate_rejections.sql +53 -0
  56. package/dist/drizzle/0268_identity_crosswalk_routing.sql +182 -0
  57. package/dist/drizzle/0269_ontology_system_map.sql +31 -0
  58. package/dist/event-streams-7JNLJEEL.js +894 -0
  59. package/dist/event-streams-KDF5RWR6.js +1515 -0
  60. package/dist/loadSso-DJVB7BXE.js +576 -0
  61. package/dist/loadSso-JAMNA3WY.js +583 -0
  62. package/dist/plugins/catalog/package.json +1 -2
  63. package/dist/plugins/catalog/src/__tests__/build-catalog.test.ts +0 -1
  64. package/dist/plugins/catalog/src/__tests__/contracts.test.ts +0 -69
  65. package/dist/plugins/catalog/src/__tests__/plugin-package.test.ts +0 -2
  66. package/dist/plugins/catalog/src/__tests__/plugin-registry.test.ts +0 -5
  67. package/dist/plugins/catalog/src/contracts.ts +2 -179
  68. package/dist/plugins/catalog/src/registry/generated-first-party.ts +0 -6
  69. package/dist/signin-UGDWTGS4.js +821 -0
  70. package/dist/sso-oidc-Q4VXANXY.js +837 -0
  71. package/dist/sts-CWLSE3GH.js +1241 -0
  72. package/dist/sts-DNZLNVOV.js +1245 -0
  73. package/dist/terraform/examples/greenfield/main.tf +223 -66
  74. package/dist/terraform/examples/greenfield/terraform.tfvars.example +15 -1
  75. package/dist/terraform/modules/app/agentcore-gateway/main.tf +305 -0
  76. package/dist/terraform/modules/app/agentcore-gateway/outputs.tf +44 -0
  77. package/dist/terraform/modules/app/agentcore-gateway/scripts/delete_gateway.sh +93 -0
  78. package/dist/terraform/modules/app/agentcore-gateway/scripts/read_gateway.sh +33 -0
  79. package/dist/terraform/modules/app/agentcore-gateway/scripts/reconcile_gateway.sh +543 -0
  80. package/dist/terraform/modules/app/agentcore-gateway/variables.tf +70 -0
  81. package/dist/terraform/modules/app/agentcore-harness/main.tf +237 -8
  82. package/dist/terraform/modules/app/agentcore-harness/outputs.tf +63 -0
  83. package/dist/terraform/modules/app/agentcore-harness/scripts/delete_harness.sh +5 -0
  84. package/dist/terraform/modules/app/agentcore-harness/scripts/harness-lifecycle.mjs +430 -0
  85. package/dist/terraform/modules/app/agentcore-harness/scripts/harness-readback.mjs +180 -0
  86. package/dist/terraform/modules/app/agentcore-harness/scripts/harness-tool-contract.mjs +193 -0
  87. package/dist/terraform/modules/app/agentcore-harness/scripts/prune_harness.sh +5 -0
  88. package/dist/terraform/modules/app/agentcore-harness/scripts/read_harness.sh +5 -0
  89. package/dist/terraform/modules/app/agentcore-harness/scripts/reconcile_harness.sh +5 -0
  90. package/dist/terraform/modules/app/agentcore-harness/variables.tf +72 -1
  91. package/dist/terraform/modules/app/agentcore-identity/main.tf +173 -0
  92. package/dist/terraform/modules/app/agentcore-identity/outputs.tf +51 -0
  93. package/dist/terraform/modules/app/agentcore-identity/scripts/bootstrap_twenty_oauth_client.sh +122 -0
  94. package/dist/terraform/modules/app/agentcore-identity/scripts/delete_identity.sh +25 -0
  95. package/dist/terraform/modules/app/agentcore-identity/scripts/delete_twenty_identity.sh +16 -0
  96. package/dist/terraform/modules/app/agentcore-identity/scripts/read_identity.sh +40 -0
  97. package/dist/terraform/modules/app/agentcore-identity/scripts/reconcile_identity.sh +73 -0
  98. package/dist/terraform/modules/app/agentcore-identity/scripts/reconcile_twenty_identity.sh +74 -0
  99. package/dist/terraform/modules/app/agentcore-identity/scripts/reconcile_twenty_provider.mjs +61 -0
  100. package/dist/terraform/modules/app/agentcore-identity/variables.tf +54 -0
  101. package/dist/terraform/modules/app/appsync-subscriptions/main.tf +127 -21
  102. package/dist/terraform/modules/app/appsync-subscriptions/outputs.tf +0 -6
  103. package/dist/terraform/modules/app/appsync-subscriptions/variables.tf +5 -0
  104. package/dist/terraform/modules/app/deployment-control-plane/runner.py +966 -27
  105. package/dist/terraform/modules/app/deployment-control-plane/test_runner_bundle.py +581 -22
  106. package/dist/terraform/modules/app/lambda-api/agentcore-harness-alarms.tf +88 -0
  107. package/dist/terraform/modules/app/lambda-api/agentcore-identity-alarms.tf +91 -0
  108. package/dist/terraform/modules/app/lambda-api/handlers.tf +298 -74
  109. package/dist/terraform/modules/app/lambda-api/iam-grouped.tf +99 -54
  110. package/dist/terraform/modules/app/lambda-api/main.tf +24 -0
  111. package/dist/terraform/modules/app/lambda-api/mcp-oauth.tf +181 -4
  112. package/dist/terraform/modules/app/lambda-api/outputs.tf +35 -0
  113. package/dist/terraform/modules/app/lambda-api/runtime-config.tf +3 -21
  114. package/dist/terraform/modules/app/lambda-api/variables.tf +109 -16
  115. package/dist/terraform/modules/foundation/cognito/main.tf +294 -72
  116. package/dist/terraform/modules/foundation/cognito/outputs.tf +42 -0
  117. package/dist/terraform/modules/foundation/cognito/variables.tf +114 -4
  118. package/dist/terraform/modules/thinkwork/main.tf +269 -46
  119. package/dist/terraform/modules/thinkwork/outputs.tf +136 -8
  120. package/dist/terraform/modules/thinkwork/variables.tf +124 -17
  121. package/dist/terraform/schema.graphql +69 -36
  122. package/dist/workspace-defaults/files/USER.md +1 -0
  123. package/package.json +3 -2
  124. package/dist/drizzle/0261_thread_turns_origin_turn_index.sql +0 -11
  125. package/dist/plugins/workos-auth/package.json +0 -22
  126. package/dist/plugins/workos-auth/src/index.ts +0 -30
  127. package/dist/plugins/workos-auth/src/manifest.ts +0 -40
  128. package/dist/plugins/workos-auth/src/provider-contract.ts +0 -39
  129. package/dist/plugins/workos-auth/test/manifest.test.ts +0 -94
  130. package/dist/plugins/workos-auth/tsconfig.json +0 -8
@@ -0,0 +1,59 @@
1
+ -- One-use AppSync authorization tickets and durable revocation invalidations.
2
+ -- creates: public.auth_subscription_tickets
3
+ -- creates: public.auth_subscription_invalidations
4
+
5
+ CREATE TABLE IF NOT EXISTS "auth_subscription_tickets" (
6
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
7
+ "nonce_digest" text NOT NULL,
8
+ "kind" text NOT NULL,
9
+ "status" text DEFAULT 'issued' NOT NULL,
10
+ "stage" text NOT NULL,
11
+ "appsync_api_id" text NOT NULL,
12
+ "key_id" text NOT NULL,
13
+ "cognito_issuer" text NOT NULL,
14
+ "cognito_sub" text NOT NULL,
15
+ "user_id" uuid NOT NULL REFERENCES "users"("id") ON DELETE restrict,
16
+ "tenant_id" uuid NOT NULL REFERENCES "tenants"("id") ON DELETE restrict,
17
+ "auth_route_client_id" uuid NOT NULL REFERENCES "auth_route_clients"("id") ON DELETE restrict,
18
+ "operation_name" text,
19
+ "operation_hash" text,
20
+ "resource_kind" text,
21
+ "resource_id" text,
22
+ "expires_at" timestamp with time zone NOT NULL,
23
+ "consumed_at" timestamp with time zone,
24
+ "revoked_at" timestamp with time zone,
25
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
26
+ CONSTRAINT "auth_subscription_tickets_kind_allowed"
27
+ CHECK ("kind" IN ('connect', 'registration')),
28
+ CONSTRAINT "auth_subscription_tickets_status_allowed"
29
+ CHECK ("status" IN ('issued', 'consumed', 'expired', 'revoked')),
30
+ CONSTRAINT "auth_subscription_tickets_operation_shape"
31
+ CHECK (("kind" = 'connect' AND "operation_name" IS NULL AND "operation_hash" IS NULL)
32
+ OR ("kind" = 'registration' AND "operation_name" IS NOT NULL AND "operation_hash" IS NOT NULL))
33
+ );
34
+
35
+ CREATE UNIQUE INDEX IF NOT EXISTS "uq_auth_subscription_tickets_nonce"
36
+ ON "auth_subscription_tickets" ("nonce_digest");
37
+ CREATE INDEX IF NOT EXISTS "idx_auth_subscription_tickets_principal"
38
+ ON "auth_subscription_tickets" ("cognito_issuer", "cognito_sub", "status");
39
+ CREATE INDEX IF NOT EXISTS "idx_auth_subscription_tickets_expiry"
40
+ ON "auth_subscription_tickets" ("status", "expires_at");
41
+
42
+ CREATE TABLE IF NOT EXISTS "auth_subscription_invalidations" (
43
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
44
+ "tenant_id" uuid NOT NULL REFERENCES "tenants"("id") ON DELETE restrict,
45
+ "user_id" uuid REFERENCES "users"("id") ON DELETE restrict,
46
+ "resource_kind" text NOT NULL,
47
+ "resource_id" text,
48
+ "reason" text NOT NULL,
49
+ "status" text DEFAULT 'pending' NOT NULL,
50
+ "attempts" integer DEFAULT 0 NOT NULL,
51
+ "available_at" timestamp with time zone DEFAULT now() NOT NULL,
52
+ "processed_at" timestamp with time zone,
53
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
54
+ CONSTRAINT "auth_subscription_invalidations_status_allowed"
55
+ CHECK ("status" IN ('pending', 'processing', 'complete', 'failed'))
56
+ );
57
+
58
+ CREATE INDEX IF NOT EXISTS "idx_auth_subscription_invalidations_pending"
59
+ ON "auth_subscription_invalidations" ("status", "available_at");
@@ -0,0 +1,9 @@
1
+ -- creates: public.idx_harness_enrollment_active_profile
2
+ -- Allow multiple normal Composer threads to remain pinned to the same
3
+ -- tenant/trust-profile Harness while Pi threads continue independently.
4
+
5
+ DROP INDEX IF EXISTS public.uq_harness_enrollment_active_profile;
6
+
7
+ CREATE INDEX IF NOT EXISTS idx_harness_enrollment_active_profile
8
+ ON public.harness_managed_thread_enrollments (tenant_id, trust_profile)
9
+ WHERE status = 'active';
@@ -0,0 +1,69 @@
1
+ -- creates-constraint: public.agents.agents_runtime_check
2
+ -- Canonicalize the application runtime identifier from the proof-era
3
+ -- `harness` token to `agentcore`. AWS resource names, OAuth scopes, and
4
+ -- diagnostics may still use Harness terminology; persisted runtime routing
5
+ -- state must not.
6
+ --
7
+ -- Hand-rolled (NOT registered in meta/_journal.json) — apply via psql:
8
+ -- psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f packages/database-pg/drizzle/0263_agentcore_runtime_identifier.sql
9
+
10
+ BEGIN;
11
+
12
+ UPDATE public.agents
13
+ SET runtime = 'agentcore'
14
+ WHERE lower(runtime) = 'harness';
15
+
16
+ UPDATE public.agents
17
+ SET runtime_config = jsonb_set(
18
+ runtime_config,
19
+ '{defaultThreadRuntime}',
20
+ '"agentcore"'::jsonb,
21
+ true
22
+ )
23
+ WHERE jsonb_typeof(runtime_config) = 'object'
24
+ AND lower(runtime_config ->> 'defaultThreadRuntime') = 'harness';
25
+
26
+ UPDATE public.threads
27
+ SET metadata = jsonb_set(
28
+ metadata,
29
+ '{requestedRuntime}',
30
+ '"agentcore"'::jsonb,
31
+ true
32
+ )
33
+ WHERE jsonb_typeof(metadata) = 'object'
34
+ AND lower(metadata ->> 'requestedRuntime') = 'harness';
35
+
36
+ UPDATE public.messages
37
+ SET metadata = jsonb_set(
38
+ metadata,
39
+ '{requestedRuntime}',
40
+ '"agentcore"'::jsonb,
41
+ true
42
+ )
43
+ WHERE jsonb_typeof(metadata) = 'object'
44
+ AND lower(metadata ->> 'requestedRuntime') = 'harness';
45
+
46
+ UPDATE public.thread_turns
47
+ SET runtime_type = 'agentcore'
48
+ WHERE lower(runtime_type) = 'harness';
49
+
50
+ UPDATE public.cost_events
51
+ SET runtime_type = 'agentcore'
52
+ WHERE lower(runtime_type) = 'harness';
53
+
54
+ UPDATE public.trace_runs
55
+ SET runtime_type = 'agentcore'
56
+ WHERE lower(runtime_type) = 'harness';
57
+
58
+ UPDATE public.harness_managed_thread_enrollments
59
+ SET prior_runtime = 'agentcore'
60
+ WHERE lower(prior_runtime) = 'harness';
61
+
62
+ ALTER TABLE public.agents
63
+ DROP CONSTRAINT IF EXISTS agents_runtime_check;
64
+
65
+ ALTER TABLE public.agents
66
+ ADD CONSTRAINT agents_runtime_check
67
+ CHECK (runtime IN ('strands', 'flue', 'pi', 'agentcore'));
68
+
69
+ COMMIT;
@@ -0,0 +1,236 @@
1
+ -- 0263_drop_workos_auth_runtime.sql
2
+ --
3
+ -- Final guarded retirement of the WorkOS login broker. Historical migrations
4
+ -- 0174/0175 remain in the repository; this migration removes their runtime
5
+ -- tables only after a completed native-auth cutover proves identity,
6
+ -- client-shutdown, token-drain, realtime-drain, and zero-reader/writer gates.
7
+ -- Raw WorkOS profile/session data is deliberately purged, not archived.
8
+ --
9
+ -- drops: public.workos_auth_bridges
10
+ -- drops: public.workos_auth_sessions
11
+ -- creates-constraint: public.plugin_components.plugin_components_type_allowed
12
+ -- creates-constraint: public.auth_provider_resources.auth_provider_resources_lifecycle_state_allowed
13
+ -- creates-constraint: public.auth_route_clients.auth_route_clients_lifecycle_allowed
14
+ -- deployment-phase: auth-retired
15
+
16
+ \set ON_ERROR_STOP on
17
+
18
+ BEGIN;
19
+
20
+ SET LOCAL lock_timeout = '30s';
21
+ SET LOCAL statement_timeout = '300s';
22
+
23
+ SELECT pg_advisory_xact_lock(hashtext('drop_workos_auth_runtime'));
24
+ SELECT set_config('thinkwork.auth_retirement_stage', :'stage', true);
25
+
26
+ DO $$
27
+ DECLARE
28
+ cutover record;
29
+ residue_exists boolean;
30
+ table_has_rows boolean;
31
+ pending_count bigint;
32
+ BEGIN
33
+ IF current_database() != 'thinkwork' THEN
34
+ RAISE EXCEPTION 'wrong database: %, expected thinkwork', current_database();
35
+ END IF;
36
+
37
+ SELECT
38
+ EXISTS (
39
+ SELECT 1 FROM public.auth_provider_resources
40
+ WHERE provider_kind = 'legacy_workos' OR lifecycle_state = 'coexistence'
41
+ )
42
+ OR EXISTS (
43
+ SELECT 1 FROM public.auth_route_clients
44
+ WHERE lifecycle_state = 'coexistence'
45
+ )
46
+ OR EXISTS (
47
+ SELECT 1 FROM public.plugin_installs WHERE plugin_key = 'workos-auth'
48
+ )
49
+ INTO residue_exists;
50
+
51
+ IF to_regclass('public.workos_auth_bridges') IS NOT NULL THEN
52
+ EXECUTE 'SELECT EXISTS (SELECT 1 FROM public.workos_auth_bridges)'
53
+ INTO table_has_rows;
54
+ residue_exists := residue_exists OR table_has_rows;
55
+ END IF;
56
+ IF to_regclass('public.workos_auth_sessions') IS NOT NULL THEN
57
+ EXECUTE 'SELECT EXISTS (SELECT 1 FROM public.workos_auth_sessions)'
58
+ INTO table_has_rows;
59
+ residue_exists := residue_exists OR table_has_rows;
60
+ END IF;
61
+
62
+ IF NOT residue_exists THEN
63
+ RAISE NOTICE 'No WorkOS auth data exists — empty historical tables may be retired without cutover evidence';
64
+ RETURN;
65
+ END IF;
66
+
67
+ SELECT * INTO cutover
68
+ FROM public.auth_cutover_runs
69
+ WHERE stage = current_setting('thinkwork.auth_retirement_stage')
70
+ ORDER BY created_at DESC, id DESC
71
+ LIMIT 1;
72
+
73
+ IF cutover.id IS NULL THEN
74
+ RAISE EXCEPTION 'WorkOS retirement blocked: no auth_cutover_runs evidence for stage %',
75
+ current_setting('thinkwork.auth_retirement_stage');
76
+ END IF;
77
+
78
+ IF cutover.status <> 'complete' OR cutover.completed_at IS NULL THEN
79
+ RAISE EXCEPTION 'WorkOS retirement blocked: newest auth_cutover_runs evidence for stage % is %',
80
+ current_setting('thinkwork.auth_retirement_stage'), cutover.status;
81
+ END IF;
82
+
83
+ IF COALESCE((cutover.terminal_dispositions->>'allTerminal')::boolean, false) IS NOT TRUE
84
+ OR COALESCE((cutover.terminal_dispositions->>'unresolved')::bigint, -1) <> 0
85
+ OR COALESCE((cutover.terminal_dispositions->>'signoutExpected')::bigint, -1) <= 0
86
+ OR COALESCE((cutover.terminal_dispositions->>'signoutAttempts')::bigint, -1)
87
+ <> COALESCE((cutover.terminal_dispositions->>'signoutExpected')::bigint, -2)
88
+ OR COALESCE((cutover.terminal_dispositions->>'signoutFailures')::bigint, -1) <> 0
89
+ OR COALESCE((cutover.terminal_dispositions->>'compatibilityFallbackReads')::bigint, -1) <> 0
90
+ THEN
91
+ RAISE EXCEPTION 'WorkOS retirement blocked: identity/signout/fallback evidence is incomplete';
92
+ END IF;
93
+
94
+ IF COALESCE((cutover.client_shutdown_evidence->>'workosStartsEnabled')::boolean, true) IS NOT FALSE
95
+ OR COALESCE((cutover.client_shutdown_evidence->>'legacyClientsEnabled')::bigint, -1) <> 0
96
+ OR COALESCE((cutover.client_shutdown_evidence->>'legacyAudiencesAccepted')::bigint, -1) <> 0
97
+ THEN
98
+ RAISE EXCEPTION 'WorkOS retirement blocked: legacy clients or audiences remain enabled';
99
+ END IF;
100
+
101
+ IF COALESCE((cutover.drain_evidence->>'drainCompleted')::boolean, false) IS NOT TRUE
102
+ OR COALESCE((cutover.drain_evidence->>'legacyRouteTraffic')::bigint, -1) <> 0
103
+ OR COALESCE((cutover.drain_evidence->>'workosTableReads')::bigint, -1) <> 0
104
+ OR COALESCE((cutover.drain_evidence->>'workosTableWrites')::bigint, -1) <> 0
105
+ OR COALESCE((cutover.drain_evidence->>'activeLegacySubscriptions')::bigint, -1) <> 0
106
+ THEN
107
+ RAISE EXCEPTION 'WorkOS retirement blocked: traffic, persistence, or realtime drain evidence is incomplete';
108
+ END IF;
109
+
110
+ IF COALESCE(cutover.drain_evidence->'provenance'->>'domain', '')
111
+ <> 'thinkwork.auth-cutover-evidence.v1'
112
+ OR COALESCE(cutover.drain_evidence->'provenance'->>'source', '')
113
+ <> 'verify-native-auth-cutover'
114
+ OR COALESCE(cutover.drain_evidence->'provenance'->>'stage', '')
115
+ <> current_setting('thinkwork.auth_retirement_stage')
116
+ OR COALESCE(cutover.drain_evidence->'provenance'->>'runId', '') <> cutover.id::text
117
+ OR COALESCE(cutover.drain_evidence->'provenance'->>'deploymentRevision', '')
118
+ !~ '^([a-f0-9]{40}|[a-f0-9]{64})$'
119
+ OR COALESCE(cutover.drain_evidence->'provenance'->>'payloadHash', '')
120
+ !~ '^[a-f0-9]{64}$'
121
+ OR length(COALESCE(cutover.drain_evidence->'provenance'->>'signature', '')) < 40
122
+ OR (cutover.drain_evidence->'provenance'->>'observedAt')::timestamptz < cutover.started_at
123
+ OR cutover.completed_at < (cutover.drain_evidence->'provenance'->>'observedAt')::timestamptz
124
+ OR cutover.completed_at > (cutover.drain_evidence->'provenance'->>'expiresAt')::timestamptz
125
+ THEN
126
+ RAISE EXCEPTION 'WorkOS retirement blocked: signed stage/revision/time provenance is missing or stale';
127
+ END IF;
128
+
129
+ IF COALESCE((cutover.drain_evidence->>'guardEnabled')::boolean, false) IS NOT TRUE
130
+ -- AppSync GraphQL WebSocket connections can survive for 24 hours, longer
131
+ -- than the legacy clients' one-hour ID/access tokens.
132
+ OR COALESCE((cutover.drain_evidence->>'requiredSoakSeconds')::bigint, 0) < 86400
133
+ OR COALESCE(cutover.drain_evidence->>'deploymentRevision', '')
134
+ <> COALESCE(cutover.drain_evidence->'provenance'->>'deploymentRevision', '')
135
+ OR cutover.drain_evidence->>'baselineDatabaseStatsResetAt' IS NULL
136
+ OR cutover.drain_evidence->>'databaseStatsResetAt' IS NULL
137
+ OR cutover.drain_evidence->>'baselineDatabaseStatsResetAt'
138
+ <> cutover.drain_evidence->>'databaseStatsResetAt'
139
+ OR cutover.drain_evidence->>'soakStartedAt' IS NULL
140
+ OR (cutover.drain_evidence->'provenance'->>'observedAt')::timestamptz
141
+ < (cutover.drain_evidence->>'soakStartedAt')::timestamptz
142
+ + make_interval(secs => (cutover.drain_evidence->>'requiredSoakSeconds')::integer)
143
+ THEN
144
+ RAISE EXCEPTION 'WorkOS retirement blocked: revision-bound drain soak is missing or incomplete';
145
+ END IF;
146
+
147
+ SELECT count(*) INTO pending_count
148
+ FROM public.auth_identity_enrollments enrollment
149
+ JOIN public.auth_provider_resources resource
150
+ ON resource.id = enrollment.auth_provider_resource_id
151
+ WHERE (resource.provider_kind = 'legacy_workos' OR resource.lifecycle_state = 'coexistence')
152
+ AND enrollment.status = 'pending'
153
+ AND enrollment.expires_at > now();
154
+ IF pending_count <> 0 THEN
155
+ RAISE EXCEPTION 'WorkOS retirement blocked: % live legacy identity enrollment(s)', pending_count;
156
+ END IF;
157
+
158
+ IF to_regclass('public.workos_auth_sessions') IS NOT NULL THEN
159
+ EXECUTE 'SELECT count(*) FROM public.workos_auth_sessions WHERE status = ''active'' AND expires_at > now()'
160
+ INTO pending_count;
161
+ IF pending_count <> 0 THEN
162
+ RAISE EXCEPTION 'WorkOS retirement blocked: % active WorkOS session(s)', pending_count;
163
+ END IF;
164
+ END IF;
165
+
166
+ IF to_regclass('public.workos_auth_bridges') IS NOT NULL THEN
167
+ EXECUTE 'SELECT count(*) FROM public.workos_auth_bridges WHERE status = ''pending'' AND expires_at > now()'
168
+ INTO pending_count;
169
+ IF pending_count <> 0 THEN
170
+ RAISE EXCEPTION 'WorkOS retirement blocked: % live WorkOS bridge(s)', pending_count;
171
+ END IF;
172
+ END IF;
173
+ END $$;
174
+
175
+ DROP TABLE IF EXISTS public.workos_auth_bridges;
176
+ DROP TABLE IF EXISTS public.workos_auth_sessions;
177
+
178
+ DELETE FROM public.auth_identity_proofs proof
179
+ USING public.user_auth_identities identity, public.auth_provider_resources resource
180
+ WHERE proof.user_auth_identity_id = identity.id
181
+ AND identity.auth_provider_resource_id = resource.id
182
+ AND (resource.provider_kind = 'legacy_workos' OR resource.lifecycle_state = 'coexistence');
183
+
184
+ DELETE FROM public.auth_identity_enrollments enrollment
185
+ USING public.auth_provider_resources resource
186
+ WHERE enrollment.auth_provider_resource_id = resource.id
187
+ AND (resource.provider_kind = 'legacy_workos' OR resource.lifecycle_state = 'coexistence');
188
+
189
+ DELETE FROM public.user_auth_identities identity
190
+ USING public.auth_provider_resources resource
191
+ WHERE identity.auth_provider_resource_id = resource.id
192
+ AND (resource.provider_kind = 'legacy_workos' OR resource.lifecycle_state = 'coexistence');
193
+
194
+ DELETE FROM public.tenant_auth_provider_references reference
195
+ USING public.auth_provider_resources resource
196
+ WHERE reference.auth_provider_resource_id = resource.id
197
+ AND (resource.provider_kind = 'legacy_workos' OR resource.lifecycle_state = 'coexistence');
198
+
199
+ DELETE FROM public.auth_provider_resources
200
+ WHERE provider_kind = 'legacy_workos' OR lifecycle_state = 'coexistence';
201
+
202
+ DELETE FROM public.auth_route_clients WHERE lifecycle_state = 'coexistence';
203
+ DELETE FROM public.plugin_installs WHERE plugin_key = 'workos-auth';
204
+
205
+ DO $$
206
+ BEGIN
207
+ IF EXISTS (
208
+ SELECT 1 FROM public.plugin_components WHERE component_type = 'auth-provider'
209
+ ) THEN
210
+ RAISE EXCEPTION 'WorkOS retirement blocked: non-retired auth-provider plugin components remain';
211
+ END IF;
212
+ END $$;
213
+
214
+ ALTER TABLE public.plugin_components
215
+ DROP CONSTRAINT IF EXISTS plugin_components_type_allowed;
216
+ ALTER TABLE public.plugin_components
217
+ ADD CONSTRAINT plugin_components_type_allowed
218
+ CHECK (component_type IN ('mcp-server', 'skills', 'infrastructure', 'ui-surface'));
219
+
220
+ ALTER TABLE public.auth_provider_resources
221
+ ALTER COLUMN connection_key DROP DEFAULT,
222
+ ALTER COLUMN provider_kind DROP DEFAULT,
223
+ ALTER COLUMN lifecycle_state SET DEFAULT 'native';
224
+ ALTER TABLE public.auth_provider_resources
225
+ DROP CONSTRAINT IF EXISTS auth_provider_resources_lifecycle_state_allowed;
226
+ ALTER TABLE public.auth_provider_resources
227
+ ADD CONSTRAINT auth_provider_resources_lifecycle_state_allowed
228
+ CHECK (lifecycle_state IN ('native', 'denied'));
229
+
230
+ ALTER TABLE public.auth_route_clients
231
+ DROP CONSTRAINT IF EXISTS auth_route_clients_lifecycle_allowed;
232
+ ALTER TABLE public.auth_route_clients
233
+ ADD CONSTRAINT auth_route_clients_lifecycle_allowed
234
+ CHECK (lifecycle_state IN ('native', 'denied'));
235
+
236
+ COMMIT;
@@ -0,0 +1,15 @@
1
+ -- Cap recipient-challenge guesses across every route for an enrollment grant.
2
+ -- creates-column: public.auth_identity_enrollments.failed_attempts
3
+ -- creates-column: public.auth_identity_enrollments.locked_at
4
+ -- creates-constraint: public.auth_identity_enrollments.auth_identity_enrollments_failed_attempts_nonnegative
5
+
6
+ ALTER TABLE public.auth_identity_enrollments
7
+ ADD COLUMN IF NOT EXISTS failed_attempts integer NOT NULL DEFAULT 0,
8
+ ADD COLUMN IF NOT EXISTS locked_at timestamptz;
9
+
10
+ ALTER TABLE public.auth_identity_enrollments
11
+ DROP CONSTRAINT IF EXISTS auth_identity_enrollments_failed_attempts_nonnegative;
12
+
13
+ ALTER TABLE public.auth_identity_enrollments
14
+ ADD CONSTRAINT auth_identity_enrollments_failed_attempts_nonnegative
15
+ CHECK (failed_attempts >= 0);
@@ -0,0 +1,113 @@
1
+ -- creates: public.harness_tool_execution_events
2
+ -- creates: public.idx_harness_tool_execution_turn
3
+ -- creates: public.uq_harness_tool_execution_started
4
+ -- creates: public.uq_harness_tool_execution_terminal
5
+ -- creates-function: public.reject_harness_tool_execution_event_mutation
6
+ -- creates-function: public.validate_harness_tool_execution_event_insert
7
+ -- creates-trigger: public.harness_tool_execution_events.trg_reject_harness_tool_execution_event_mutation
8
+ -- creates-trigger: public.harness_tool_execution_events.trg_validate_harness_tool_execution_event_insert
9
+ -- Target-side Harness tool evidence. This is a sanitized append-only event
10
+ -- stream, separate from the governed-effect claim/result cache in migration
11
+ -- 0261. Targets write before credential resolution and once at terminal state.
12
+
13
+ CREATE TABLE IF NOT EXISTS public.harness_tool_execution_events (
14
+ id bigserial PRIMARY KEY,
15
+ tenant_id uuid NOT NULL REFERENCES public.tenants(id) ON DELETE CASCADE,
16
+ thread_id uuid NOT NULL REFERENCES public.threads(id) ON DELETE CASCADE,
17
+ turn_id uuid NOT NULL REFERENCES public.thread_turns(id) ON DELETE CASCADE,
18
+ principal_type text NOT NULL CHECK (principal_type IN ('user', 'service')),
19
+ principal_id text NOT NULL,
20
+ tool_use_id text NOT NULL,
21
+ operation text NOT NULL,
22
+ policy_revision text NOT NULL,
23
+ policy_decision_id text,
24
+ idempotency_key text NOT NULL,
25
+ credential_owner_alias text,
26
+ event_type text NOT NULL
27
+ CHECK (event_type IN ('started','completed','failed','uncertain')),
28
+ input_preview jsonb,
29
+ output_preview jsonb,
30
+ error_preview jsonb,
31
+ provider_request_id text,
32
+ duration_ms integer CHECK (duration_ms IS NULL OR duration_ms >= 0),
33
+ provider_cost_usd numeric(18,8)
34
+ CHECK (provider_cost_usd IS NULL OR provider_cost_usd >= 0),
35
+ created_at timestamptz NOT NULL DEFAULT now(),
36
+ CHECK (
37
+ (
38
+ event_type = 'started'
39
+ AND input_preview IS NOT NULL
40
+ AND output_preview IS NULL
41
+ AND error_preview IS NULL
42
+ AND provider_request_id IS NULL
43
+ AND duration_ms IS NULL
44
+ AND provider_cost_usd IS NULL
45
+ )
46
+ OR (
47
+ event_type IN ('completed','failed','uncertain')
48
+ AND input_preview IS NULL
49
+ )
50
+ )
51
+ );
52
+
53
+ CREATE UNIQUE INDEX IF NOT EXISTS uq_harness_tool_execution_started
54
+ ON public.harness_tool_execution_events (tenant_id, idempotency_key)
55
+ WHERE event_type = 'started';
56
+
57
+ CREATE UNIQUE INDEX IF NOT EXISTS uq_harness_tool_execution_terminal
58
+ ON public.harness_tool_execution_events (tenant_id, idempotency_key)
59
+ WHERE event_type IN ('completed','failed','uncertain');
60
+
61
+ CREATE INDEX IF NOT EXISTS idx_harness_tool_execution_turn
62
+ ON public.harness_tool_execution_events (tenant_id, thread_id, turn_id, id);
63
+
64
+ CREATE OR REPLACE FUNCTION public.validate_harness_tool_execution_event_insert()
65
+ RETURNS trigger
66
+ LANGUAGE plpgsql
67
+ AS $$
68
+ BEGIN
69
+ IF NEW.event_type = 'started' THEN
70
+ RETURN NEW;
71
+ END IF;
72
+
73
+ IF NOT EXISTS (
74
+ SELECT 1
75
+ FROM public.harness_tool_execution_events started
76
+ WHERE started.tenant_id = NEW.tenant_id
77
+ AND started.idempotency_key = NEW.idempotency_key
78
+ AND started.event_type = 'started'
79
+ AND started.thread_id = NEW.thread_id
80
+ AND started.turn_id = NEW.turn_id
81
+ AND started.principal_type = NEW.principal_type
82
+ AND started.principal_id = NEW.principal_id
83
+ AND started.tool_use_id = NEW.tool_use_id
84
+ AND started.operation = NEW.operation
85
+ AND started.policy_revision = NEW.policy_revision
86
+ ) THEN
87
+ RAISE EXCEPTION 'harness_tool_execution_terminal_without_matching_start';
88
+ END IF;
89
+
90
+ RETURN NEW;
91
+ END;
92
+ $$;
93
+
94
+ DROP TRIGGER IF EXISTS trg_validate_harness_tool_execution_event_insert
95
+ ON public.harness_tool_execution_events;
96
+ CREATE TRIGGER trg_validate_harness_tool_execution_event_insert
97
+ BEFORE INSERT ON public.harness_tool_execution_events
98
+ FOR EACH ROW EXECUTE FUNCTION public.validate_harness_tool_execution_event_insert();
99
+
100
+ CREATE OR REPLACE FUNCTION public.reject_harness_tool_execution_event_mutation()
101
+ RETURNS trigger
102
+ LANGUAGE plpgsql
103
+ AS $$
104
+ BEGIN
105
+ RAISE EXCEPTION 'harness_tool_execution_events_are_append_only';
106
+ END;
107
+ $$;
108
+
109
+ DROP TRIGGER IF EXISTS trg_reject_harness_tool_execution_event_mutation
110
+ ON public.harness_tool_execution_events;
111
+ CREATE TRIGGER trg_reject_harness_tool_execution_event_mutation
112
+ BEFORE UPDATE OR DELETE ON public.harness_tool_execution_events
113
+ FOR EACH ROW EXECUTE FUNCTION public.reject_harness_tool_execution_event_mutation();
@@ -0,0 +1,28 @@
1
+ -- creates-column: public.eval_runs.requester_user_id
2
+ -- creates: public.idx_eval_runs_requester_user_id
3
+ -- Exact human principal used to resolve per-user identity and capabilities for
4
+ -- production-shaped AgentCore Harness evaluation turns. Nullable preserves
5
+ -- legacy Pi evaluation rows; Harness dispatch fails closed when it is absent.
6
+
7
+ ALTER TABLE public.eval_runs
8
+ ADD COLUMN IF NOT EXISTS requester_user_id uuid;
9
+
10
+ DO $$
11
+ BEGIN
12
+ IF NOT EXISTS (
13
+ SELECT 1
14
+ FROM pg_constraint
15
+ WHERE conname = 'eval_runs_requester_user_id_users_id_fk'
16
+ AND conrelid = 'public.eval_runs'::regclass
17
+ ) THEN
18
+ ALTER TABLE public.eval_runs
19
+ ADD CONSTRAINT eval_runs_requester_user_id_users_id_fk
20
+ FOREIGN KEY (requester_user_id)
21
+ REFERENCES public.users(id)
22
+ ON DELETE SET NULL;
23
+ END IF;
24
+ END
25
+ $$;
26
+
27
+ CREATE INDEX IF NOT EXISTS idx_eval_runs_requester_user_id
28
+ ON public.eval_runs (requester_user_id);
@@ -0,0 +1,27 @@
1
+ -- 0265_require_fully_valid_auth_publication.sql
2
+ -- Partially validated providers must never be published or admitted. Existing
3
+ -- rows are unpublished before the stricter canonical constraint is installed.
4
+ -- creates-constraint: public.auth_provider_resources.auth_provider_resources_no_public_without_valid
5
+
6
+ BEGIN;
7
+
8
+ UPDATE public.auth_provider_resources
9
+ SET public_options_published = false,
10
+ updated_at = now()
11
+ WHERE public_options_published = true
12
+ AND validation_status <> 'valid';
13
+
14
+ ALTER TABLE public.auth_provider_resources
15
+ DROP CONSTRAINT IF EXISTS auth_provider_resources_no_public_without_valid;
16
+
17
+ ALTER TABLE public.auth_provider_resources
18
+ ADD CONSTRAINT auth_provider_resources_no_public_without_valid
19
+ CHECK (
20
+ public_options_published = false
21
+ OR (
22
+ validation_status = 'valid'
23
+ AND lifecycle_state <> 'denied'
24
+ )
25
+ );
26
+
27
+ COMMIT;
@@ -0,0 +1,9 @@
1
+ -- 0266_auth_identity_recovery_grants.sql
2
+ -- creates-constraint: public.auth_identity_enrollments.auth_identity_enrollments_grant_kind_allowed
3
+
4
+ ALTER TABLE public.auth_identity_enrollments
5
+ DROP CONSTRAINT IF EXISTS auth_identity_enrollments_grant_kind_allowed;
6
+
7
+ ALTER TABLE public.auth_identity_enrollments
8
+ ADD CONSTRAINT auth_identity_enrollments_grant_kind_allowed
9
+ CHECK (recipient_grant_kind IN ('membership', 'pending_owner', 'identity_recovery', 'session_migration'));
@@ -0,0 +1,12 @@
1
+ -- creates-column: public.eval_profiles.runtime_type
2
+ -- creates-constraint: public.eval_profiles.eval_profiles_runtime_type_check
3
+
4
+ ALTER TABLE public.eval_profiles
5
+ ADD COLUMN IF NOT EXISTS runtime_type text NOT NULL DEFAULT 'pi';
6
+
7
+ ALTER TABLE public.eval_profiles
8
+ DROP CONSTRAINT IF EXISTS eval_profiles_runtime_type_check;
9
+
10
+ ALTER TABLE public.eval_profiles
11
+ ADD CONSTRAINT eval_profiles_runtime_type_check
12
+ CHECK (runtime_type IN ('pi', 'agentcore'));
@@ -0,0 +1,53 @@
1
+ -- Purpose: durable candidate-rejection fingerprints (KTD-6 / R13) and the
2
+ -- `deferred` change-set item status (R15) for the Ontology Living Map.
3
+ -- Plan: docs/plans/2026-07-18-001-feat-ontology-living-map-plan.md (U2)
4
+ -- Apply manually: psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f packages/database-pg/drizzle/0267_ontology_candidate_rejections.sql
5
+ -- creates: ontology.candidate_rejections
6
+ -- creates: ontology.uq_ontology_candidate_rejections_fingerprint
7
+ -- creates: ontology.idx_ontology_candidate_rejections_tenant
8
+ -- creates-constraint: ontology.candidate_rejections.ontology_candidate_rejections_tenant_id_tenants_id_fk
9
+ -- creates-constraint: ontology.candidate_rejections.ontology_candidate_rejections_kind_allowed
10
+ -- creates-constraint: ontology.change_set_items.ontology_change_set_items_status_allowed
11
+
12
+ \set ON_ERROR_STOP on
13
+
14
+ BEGIN;
15
+
16
+ SET LOCAL lock_timeout = '5s';
17
+ SET LOCAL statement_timeout = '120s';
18
+
19
+ CREATE TABLE IF NOT EXISTS ontology.candidate_rejections (
20
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
21
+ tenant_id uuid NOT NULL,
22
+ kind text NOT NULL,
23
+ slug text NOT NULL,
24
+ fingerprint text NOT NULL,
25
+ rejected_by uuid,
26
+ rejected_at timestamptz NOT NULL DEFAULT now(),
27
+ CONSTRAINT ontology_candidate_rejections_tenant_id_tenants_id_fk
28
+ FOREIGN KEY (tenant_id)
29
+ REFERENCES public.tenants(id)
30
+ ON DELETE CASCADE,
31
+ CONSTRAINT ontology_candidate_rejections_rejected_by_users_id_fk
32
+ FOREIGN KEY (rejected_by)
33
+ REFERENCES public.users(id)
34
+ ON DELETE SET NULL,
35
+ CONSTRAINT ontology_candidate_rejections_kind_allowed
36
+ CHECK (kind IN ('entity_type','relationship_type','facet_template','external_mapping'))
37
+ );
38
+
39
+ CREATE UNIQUE INDEX IF NOT EXISTS uq_ontology_candidate_rejections_fingerprint
40
+ ON ontology.candidate_rejections (tenant_id, kind, fingerprint);
41
+
42
+ CREATE INDEX IF NOT EXISTS idx_ontology_candidate_rejections_tenant
43
+ ON ontology.candidate_rejections (tenant_id);
44
+
45
+ -- R15: excluded-at-approval items become `deferred` (re-reviewable) — widen
46
+ -- the item status CHECK to admit the new value.
47
+ ALTER TABLE ontology.change_set_items
48
+ DROP CONSTRAINT IF EXISTS ontology_change_set_items_status_allowed;
49
+ ALTER TABLE ontology.change_set_items
50
+ ADD CONSTRAINT ontology_change_set_items_status_allowed
51
+ CHECK (status IN ('pending_review','approved','rejected','applied','deferred'));
52
+
53
+ COMMIT;