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
@@ -1,766 +0,0 @@
1
- ################################################################################
2
- # Cognee (Optional Ontology/KG Add-On) - App Module
3
- #
4
- # Provisions the phase-1 Cognee substrate as an internal ECS/Fargate service.
5
- # The module intentionally does not expose a public endpoint mode; Thinkwork API
6
- # wrappers own tenant/auth boundaries in follow-up work.
7
- ################################################################################
8
-
9
- locals {
10
- legacy_name = "thinkwork-${var.stage}-cognee"
11
- legacy_cluster_name = "thinkwork-${var.stage}-brain-cluster"
12
-
13
- raw_brain_instance_key = var.brain_instance_key != "" ? var.brain_instance_key : var.brain_tenant_id
14
- normalized_brain_instance_key = trim(replace(replace(lower(local.raw_brain_instance_key), "/[^a-z0-9-]/", "-"), "/-+/", "-"), "-")
15
- tenant_scoped_brain_instance = local.normalized_brain_instance_key != ""
16
- brain_instance_hash = substr(sha1(local.raw_brain_instance_key), 0, 12)
17
- name = local.tenant_scoped_brain_instance ? "thinkwork-${var.stage}-cb-${local.brain_instance_hash}" : local.legacy_name
18
- cluster_name = local.tenant_scoped_brain_instance ? "${local.name}-cluster" : local.legacy_cluster_name
19
- resource_short_name = local.tenant_scoped_brain_instance ? "tw-${substr(var.stage, 0, 8)}-cb-${substr(local.brain_instance_hash, 0, 10)}" : "tw-${var.stage}-cognee"
20
-
21
- data_root_directory = "/app/cognee-storage/data"
22
- system_root_directory = "/app/cognee-storage/system"
23
-
24
- vector_db_url = (
25
- var.vector_db_url != ""
26
- ? var.vector_db_url
27
- : var.vector_db_provider == "neptune_analytics" && var.neptune_endpoint != ""
28
- ? var.neptune_endpoint
29
- : "${local.system_root_directory}/databases/cognee.lancedb"
30
- )
31
- graph_db_url = (
32
- var.graph_database_url != ""
33
- ? var.graph_database_url
34
- : var.graph_database_provider == "neptune_analytics" && var.neptune_endpoint != ""
35
- ? var.neptune_endpoint
36
- : "${local.system_root_directory}/databases/cognee.kuzu"
37
- )
38
- log_group_name = local.tenant_scoped_brain_instance ? "/thinkwork/${var.stage}/brain/${local.normalized_brain_instance_key}/cognee" : "/thinkwork/${var.stage}/cognee"
39
-
40
- managed_secret_specs = {
41
- db_password = {
42
- enabled = var.create_secret_placeholders && var.db_password_secret_arn == ""
43
- name = local.tenant_scoped_brain_instance ? "thinkwork/${var.stage}/brain/${local.normalized_brain_instance_key}/db-credentials" : "thinkwork/${var.stage}/cognee/db-credentials"
44
- description = "Dedicated Brain/Cognee PostgreSQL credentials"
45
- secret_string = jsonencode({ password = "PLACEHOLDER_SET_VIA_CLI" })
46
- }
47
- llm_api_key = {
48
- enabled = var.create_secret_placeholders && var.llm_provider != "bedrock" && var.llm_api_key_secret_arn == ""
49
- name = local.tenant_scoped_brain_instance ? "thinkwork/${var.stage}/brain/${local.normalized_brain_instance_key}/llm-api-key" : "thinkwork/${var.stage}/cognee/llm-api-key"
50
- description = "Brain/Cognee non-Bedrock LLM provider API key"
51
- secret_string = "PLACEHOLDER_SET_VIA_CLI"
52
- }
53
- embedding_api_key = {
54
- enabled = var.create_secret_placeholders && var.embedding_provider != "bedrock" && var.embedding_api_key_secret_arn == ""
55
- name = local.tenant_scoped_brain_instance ? "thinkwork/${var.stage}/brain/${local.normalized_brain_instance_key}/embedding-api-key" : "thinkwork/${var.stage}/cognee/embedding-api-key"
56
- description = "Brain/Cognee non-Bedrock embedding provider API key"
57
- secret_string = "PLACEHOLDER_SET_VIA_CLI"
58
- }
59
- vector_db_key = {
60
- enabled = var.create_secret_placeholders && var.vector_db_provider != "lancedb" && var.vector_db_key_secret_arn == ""
61
- name = local.tenant_scoped_brain_instance ? "thinkwork/${var.stage}/brain/${local.normalized_brain_instance_key}/vector-db-key" : "thinkwork/${var.stage}/cognee/vector-db-key"
62
- description = "Brain/Cognee remote vector store key"
63
- secret_string = "PLACEHOLDER_SET_VIA_CLI"
64
- }
65
- graph_database_password = {
66
- enabled = var.create_secret_placeholders && var.graph_database_provider != "kuzu" && var.graph_database_password_secret_arn == ""
67
- name = local.tenant_scoped_brain_instance ? "thinkwork/${var.stage}/brain/${local.normalized_brain_instance_key}/graph-database-password" : "thinkwork/${var.stage}/cognee/graph-database-password"
68
- description = "Brain/Cognee remote graph store password"
69
- secret_string = "PLACEHOLDER_SET_VIA_CLI"
70
- }
71
- }
72
-
73
- managed_secrets = {
74
- for key, spec in local.managed_secret_specs : key => spec if spec.enabled
75
- }
76
-
77
- effective_db_password_secret_arn = (
78
- var.db_password_secret_arn != ""
79
- ? var.db_password_secret_arn
80
- : try(aws_secretsmanager_secret.cognee["db_password"].arn, "")
81
- )
82
- effective_llm_api_key_secret_arn = (
83
- var.llm_api_key_secret_arn != ""
84
- ? var.llm_api_key_secret_arn
85
- : try(aws_secretsmanager_secret.cognee["llm_api_key"].arn, "")
86
- )
87
- effective_embedding_api_key_secret_arn = (
88
- var.embedding_api_key_secret_arn != ""
89
- ? var.embedding_api_key_secret_arn
90
- : try(aws_secretsmanager_secret.cognee["embedding_api_key"].arn, "")
91
- )
92
- effective_vector_db_key_secret_arn = (
93
- var.vector_db_key_secret_arn != ""
94
- ? var.vector_db_key_secret_arn
95
- : try(aws_secretsmanager_secret.cognee["vector_db_key"].arn, "")
96
- )
97
- effective_graph_database_password_secret_arn = (
98
- var.graph_database_password_secret_arn != ""
99
- ? var.graph_database_password_secret_arn
100
- : try(aws_secretsmanager_secret.cognee["graph_database_password"].arn, "")
101
- )
102
-
103
- efs_mount_subnet_ids_by_index = {
104
- for index, subnet_id in var.subnet_ids : tostring(index) => subnet_id
105
- }
106
-
107
- brain_artifact_object_arns = [
108
- for prefix in var.brain_artifacts_prefixes :
109
- "${var.brain_artifacts_bucket_arn}/${trim(prefix, "/")}/*"
110
- ]
111
-
112
- base_environment = [
113
- { name = "DB_PROVIDER", value = "postgres" },
114
- { name = "DB_HOST", value = var.db_host },
115
- { name = "DB_PORT", value = tostring(var.db_port) },
116
- { name = "DB_NAME", value = var.db_name },
117
- { name = "DB_USERNAME", value = var.db_username },
118
- { name = "LLM_PROVIDER", value = var.llm_provider },
119
- { name = "LLM_MODEL", value = var.llm_model },
120
- { name = "EMBEDDING_PROVIDER", value = var.embedding_provider },
121
- { name = "EMBEDDING_MODEL", value = var.embedding_model },
122
- { name = "EMBEDDING_DIMENSIONS", value = tostring(var.embedding_dimensions) },
123
- { name = "VECTOR_DB_PROVIDER", value = var.vector_db_provider },
124
- { name = "VECTOR_DB_URL", value = local.vector_db_url },
125
- { name = "GRAPH_DATABASE_PROVIDER", value = var.graph_database_provider },
126
- { name = "GRAPH_DATABASE_URL", value = local.graph_db_url },
127
- { name = "DATA_ROOT_DIRECTORY", value = local.data_root_directory },
128
- { name = "SYSTEM_ROOT_DIRECTORY", value = local.system_root_directory },
129
- { name = "BRAIN_TENANT_ID", value = var.brain_tenant_id },
130
- { name = "BRAIN_INSTANCE_KEY", value = local.normalized_brain_instance_key },
131
- { name = "BRAIN_STORAGE_TIER", value = var.brain_storage_tier },
132
- { name = "BRAIN_S3_ARTIFACT_ROOT", value = var.brain_s3_artifact_root },
133
- { name = "BRAIN_S3_MANIFEST_ROOT", value = var.brain_s3_manifest_root },
134
- { name = "BRAIN_S3_VAULT_PROJECTION_ROOT", value = var.brain_s3_vault_projection_root },
135
- { name = "NEPTUNE_GRAPH_ID", value = var.neptune_graph_id },
136
- { name = "NEPTUNE_ENDPOINT", value = var.neptune_endpoint },
137
- { name = "TELEMETRY_DISABLED", value = "true" },
138
- { name = "REQUIRE_AUTHENTICATION", value = tostring(var.require_authentication) },
139
- { name = "ENABLE_BACKEND_ACCESS_CONTROL", value = tostring(var.enable_backend_access_control) },
140
- { name = "CORS_ALLOWED_ORIGINS", value = var.cors_allowed_origins },
141
- { name = "AWS_DEFAULT_REGION", value = data.aws_region.current.name },
142
- { name = "AWS_REGION", value = data.aws_region.current.name },
143
- # litellm's default embedding timeout (30s) is too tight for a batch of
144
- # entity embeddings routed sequentially through the Bedrock VPC endpoint —
145
- # cognify errored with EmbeddingException (timeout) mid-run. Raise the
146
- # per-request embedding + LLM timeouts so a batch completes.
147
- { name = "EMBEDDING_REQUEST_TIMEOUT", value = "180" },
148
- { name = "LLM_REQUEST_TIMEOUT", value = "180" },
149
- # Bedrock throttles (HTTP 429) the burst of per-entity titan embedding
150
- # calls cognify fires — the pipeline errored on EmbeddingException. The
151
- # account's hard quota is exactly 60 req/min for Titan Text Embeddings V2
152
- # (Service Quotas), so a limiter set AT 60 still tips over under any
153
- # concurrency. Pace embeddings to 25/min — comfortably under the ceiling
154
- # with headroom for litellm retries. The single dogfood task is slow but
155
- # completes; the self-invoke ingest chain drains the backlog across runs.
156
- # Production-scale volume needs a Titan-embed quota increase (Service
157
- # Quotas) — 60 RPM caps throughput regardless of pacing.
158
- { name = "EMBEDDING_RATE_LIMIT_ENABLED", value = "true" },
159
- { name = "EMBEDDING_RATE_LIMIT_REQUESTS", value = "25" },
160
- { name = "EMBEDDING_RATE_LIMIT_INTERVAL", value = "60" },
161
- # Cognee's generic LLM rate limiter (shared limiter implementation) —
162
- # enable it too so the Kimi extraction calls don't trip Bedrock either.
163
- { name = "LLM_RATE_LIMIT_ENABLED", value = "true" },
164
- { name = "LLM_RATE_LIMIT_REQUESTS", value = "30" },
165
- { name = "LLM_RATE_LIMIT_INTERVAL", value = "60" },
166
- ]
167
-
168
- optional_environment = concat(
169
- var.embedding_max_completion_tokens != "" ? [{ name = "EMBEDDING_MAX_COMPLETION_TOKENS", value = var.embedding_max_completion_tokens }] : [],
170
- var.graph_database_username != "" ? [{ name = "GRAPH_DATABASE_USERNAME", value = var.graph_database_username }] : []
171
- )
172
-
173
- container_secrets = concat(
174
- [{ name = "DB_PASSWORD", valueFrom = "${local.effective_db_password_secret_arn}:password::" }],
175
- local.effective_llm_api_key_secret_arn != "" ? [{ name = "LLM_API_KEY", valueFrom = local.effective_llm_api_key_secret_arn }] : [],
176
- local.effective_embedding_api_key_secret_arn != "" ? [{ name = "EMBEDDING_API_KEY", valueFrom = local.effective_embedding_api_key_secret_arn }] : [],
177
- local.effective_vector_db_key_secret_arn != "" ? [{ name = "VECTOR_DB_KEY", valueFrom = local.effective_vector_db_key_secret_arn }] : [],
178
- local.effective_graph_database_password_secret_arn != "" ? [{ name = "GRAPH_DATABASE_PASSWORD", valueFrom = local.effective_graph_database_password_secret_arn }] : []
179
- )
180
-
181
- secret_arns = compact([
182
- local.effective_db_password_secret_arn,
183
- local.effective_llm_api_key_secret_arn,
184
- local.effective_embedding_api_key_secret_arn,
185
- local.effective_vector_db_key_secret_arn,
186
- local.effective_graph_database_password_secret_arn,
187
- ])
188
- }
189
-
190
- data "aws_region" "current" {}
191
-
192
- resource "aws_secretsmanager_secret" "cognee" {
193
- for_each = local.managed_secrets
194
-
195
- name = each.value.name
196
- description = each.value.description
197
-
198
- tags = {
199
- Name = each.value.name
200
- Role = "cognee"
201
- }
202
- }
203
-
204
- resource "aws_secretsmanager_secret_version" "cognee" {
205
- for_each = local.managed_secrets
206
-
207
- secret_id = aws_secretsmanager_secret.cognee[each.key].id
208
- secret_string = each.value.secret_string
209
-
210
- lifecycle {
211
- ignore_changes = [secret_string]
212
- }
213
- }
214
-
215
- ################################################################################
216
- # Plan-time safety guardrails
217
- ################################################################################
218
-
219
- resource "terraform_data" "configuration_guardrails" {
220
- input = {
221
- backend_mode = var.backend_mode
222
- brain_tenant_id = var.brain_tenant_id
223
- brain_instance_key = local.normalized_brain_instance_key
224
- brain_storage_tier = var.brain_storage_tier
225
- desired_count = var.desired_count
226
- vector_db_url = local.vector_db_url
227
- vector_db_provider = var.vector_db_provider
228
- graph_database_url = local.graph_db_url
229
- graph_database_provider = var.graph_database_provider
230
- neptune_graph_id = var.neptune_graph_id
231
- neptune_endpoint = var.neptune_endpoint
232
- llm_provider = var.llm_provider
233
- embedding_provider = var.embedding_provider
234
- db_password_secret_arn = local.effective_db_password_secret_arn
235
- llm_api_key_secret_arn = local.effective_llm_api_key_secret_arn
236
- embedding_api_key_secret_arn = local.effective_embedding_api_key_secret_arn
237
- bedrock_model_resource_arns = var.bedrock_model_resource_arns
238
- }
239
-
240
- lifecycle {
241
- precondition {
242
- condition = var.backend_mode != "dogfood" || var.desired_count == 1
243
- error_message = "dogfood backend mode uses local graph/vector storage and must run with desired_count = 1."
244
- }
245
-
246
- precondition {
247
- condition = (
248
- var.brain_storage_tier != "default" ||
249
- (
250
- var.backend_mode == "dogfood" &&
251
- var.vector_db_provider == "lancedb" &&
252
- var.graph_database_provider == "kuzu" &&
253
- var.desired_count == 1
254
- )
255
- )
256
- error_message = "default Brain tier must use dogfood backend mode, lancedb vectors, kuzu graph storage, and desired_count = 1."
257
- }
258
-
259
- precondition {
260
- condition = (
261
- var.brain_storage_tier != "production" ||
262
- (
263
- var.backend_mode == "remote" &&
264
- var.vector_db_provider == "neptune_analytics" &&
265
- var.graph_database_provider == "neptune_analytics" &&
266
- var.neptune_graph_id != "" &&
267
- var.neptune_endpoint != ""
268
- )
269
- )
270
- error_message = "production Brain tier must use remote mode with Neptune Analytics graph/vector providers, neptune_graph_id, and neptune_endpoint."
271
- }
272
-
273
- precondition {
274
- condition = !contains(["opensearch", "opensearch_serverless", "aoss"], lower(var.vector_db_provider))
275
- error_message = "Company Brain production must not use direct OpenSearch vector storage; use Neptune Analytics for production graph/vector."
276
- }
277
-
278
- precondition {
279
- condition = var.private_substrate_mode
280
- error_message = "Company Brain substrate must remain private/internal-only."
281
- }
282
-
283
- precondition {
284
- condition = (
285
- var.backend_mode != "remote" ||
286
- (
287
- local.vector_db_url != "" &&
288
- local.graph_db_url != "" &&
289
- local.vector_db_url != "${local.system_root_directory}/databases/cognee.lancedb" &&
290
- local.graph_db_url != "${local.system_root_directory}/databases/cognee.kuzu"
291
- )
292
- )
293
- error_message = "remote backend mode requires vector and graph URLs, or Neptune Analytics providers with neptune_endpoint."
294
- }
295
-
296
- precondition {
297
- condition = local.effective_db_password_secret_arn != ""
298
- error_message = "Cognee requires db_password_secret_arn or create_secret_placeholders = true."
299
- }
300
-
301
- precondition {
302
- condition = (
303
- var.llm_provider == "bedrock" || local.effective_llm_api_key_secret_arn != ""
304
- ) && (
305
- var.embedding_provider == "bedrock" || local.effective_embedding_api_key_secret_arn != ""
306
- )
307
- error_message = "Non-Bedrock LLM or embedding providers must use Secrets Manager ARNs, not plaintext environment values."
308
- }
309
-
310
- precondition {
311
- condition = (
312
- (var.llm_provider != "bedrock" && var.embedding_provider != "bedrock") ||
313
- length(var.bedrock_model_resource_arns) > 0
314
- )
315
- error_message = "Bedrock LLM or embedding providers require explicit bedrock_model_resource_arns."
316
- }
317
- }
318
- }
319
-
320
- ################################################################################
321
- # ECS Cluster
322
- ################################################################################
323
-
324
- resource "aws_ecs_cluster" "main" {
325
- name = local.cluster_name
326
-
327
- setting {
328
- name = "containerInsights"
329
- value = "enabled"
330
- }
331
-
332
- tags = { Name = local.cluster_name }
333
- }
334
-
335
- ################################################################################
336
- # IAM
337
- ################################################################################
338
-
339
- resource "aws_iam_role" "ecs_execution" {
340
- name = "${local.name}-execution"
341
-
342
- assume_role_policy = jsonencode({
343
- Version = "2012-10-17"
344
- Statement = [{
345
- Action = "sts:AssumeRole"
346
- Effect = "Allow"
347
- Principal = { Service = "ecs-tasks.amazonaws.com" }
348
- }]
349
- })
350
- }
351
-
352
- resource "aws_iam_role_policy_attachment" "ecs_execution" {
353
- role = aws_iam_role.ecs_execution.name
354
- policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
355
- }
356
-
357
- resource "aws_iam_role_policy" "ecs_execution_secrets" {
358
- name = "cognee-secrets"
359
- role = aws_iam_role.ecs_execution.id
360
-
361
- policy = jsonencode({
362
- Version = "2012-10-17"
363
- Statement = concat(
364
- [{
365
- Effect = "Allow"
366
- Action = ["secretsmanager:GetSecretValue"]
367
- Resource = local.secret_arns
368
- }],
369
- length(var.kms_key_arns) > 0 ? [{
370
- Effect = "Allow"
371
- Action = ["kms:Decrypt"]
372
- Resource = var.kms_key_arns
373
- }] : []
374
- )
375
- })
376
- }
377
-
378
- resource "aws_iam_role" "ecs_task" {
379
- name = "${local.name}-task"
380
-
381
- assume_role_policy = jsonencode({
382
- Version = "2012-10-17"
383
- Statement = [{
384
- Action = "sts:AssumeRole"
385
- Effect = "Allow"
386
- Principal = { Service = "ecs-tasks.amazonaws.com" }
387
- }]
388
- })
389
- }
390
-
391
- resource "aws_iam_role_policy" "bedrock_access" {
392
- count = var.llm_provider == "bedrock" || var.embedding_provider == "bedrock" ? 1 : 0
393
-
394
- name = "bedrock-access"
395
- role = aws_iam_role.ecs_task.id
396
-
397
- policy = jsonencode({
398
- Version = "2012-10-17"
399
- Statement = [{
400
- Effect = "Allow"
401
- Action = ["bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream"]
402
- Resource = var.bedrock_model_resource_arns
403
- }]
404
- })
405
- }
406
-
407
- resource "aws_iam_role_policy" "brain_artifacts" {
408
- count = var.brain_artifacts_bucket_arn != "" && length(var.brain_artifacts_prefixes) > 0 ? 1 : 0
409
-
410
- name = "brain-artifacts"
411
- role = aws_iam_role.ecs_task.id
412
-
413
- policy = jsonencode({
414
- Version = "2012-10-17"
415
- Statement = [
416
- {
417
- Effect = "Allow"
418
- Action = ["s3:ListBucket"]
419
- Resource = var.brain_artifacts_bucket_arn
420
- Condition = {
421
- StringLike = {
422
- "s3:prefix" = [for prefix in var.brain_artifacts_prefixes : "${trim(prefix, "/")}/*"]
423
- }
424
- }
425
- },
426
- {
427
- Effect = "Allow"
428
- Action = [
429
- "s3:GetObject",
430
- "s3:PutObject",
431
- "s3:DeleteObject",
432
- "s3:GetObjectVersion",
433
- ]
434
- Resource = local.brain_artifact_object_arns
435
- },
436
- ]
437
- })
438
- }
439
-
440
- resource "aws_iam_role_policy" "neptune_graph_access" {
441
- count = var.neptune_graph_arn != "" ? 1 : 0
442
-
443
- name = "neptune-graph-access"
444
- role = aws_iam_role.ecs_task.id
445
-
446
- policy = jsonencode({
447
- Version = "2012-10-17"
448
- Statement = [{
449
- Effect = "Allow"
450
- Action = [
451
- "neptune-graph:GetGraph",
452
- "neptune-graph:ReadDataViaQuery",
453
- "neptune-graph:WriteDataViaQuery",
454
- ]
455
- Resource = var.neptune_graph_arn
456
- }]
457
- })
458
- }
459
-
460
- # ECS Exec (`aws ecs execute-command`) needs the SSM messages channel on the
461
- # TASK role. Gated by var.enable_execute_command so it only grants when exec is
462
- # on. Used operationally to inspect the dogfood Cognee store / API directly
463
- # (its ALB is VPC-internal) — e.g. verify dataset names and graph-fetch scope.
464
- resource "aws_iam_role_policy" "ecs_exec_ssm" {
465
- count = var.enable_execute_command ? 1 : 0
466
-
467
- name = "ecs-exec-ssm-messages"
468
- role = aws_iam_role.ecs_task.id
469
-
470
- policy = jsonencode({
471
- Version = "2012-10-17"
472
- Statement = [{
473
- Effect = "Allow"
474
- Action = [
475
- "ssmmessages:CreateControlChannel",
476
- "ssmmessages:CreateDataChannel",
477
- "ssmmessages:OpenControlChannel",
478
- "ssmmessages:OpenDataChannel",
479
- ]
480
- Resource = "*"
481
- }]
482
- })
483
- }
484
-
485
- ################################################################################
486
- # Security Groups
487
- ################################################################################
488
-
489
- resource "aws_security_group" "cognee" {
490
- name_prefix = "${local.name}-"
491
- description = "Cognee ECS task"
492
- vpc_id = var.vpc_id
493
-
494
- ingress {
495
- description = "Internal ALB to Cognee API"
496
- from_port = var.container_port
497
- to_port = var.container_port
498
- protocol = "tcp"
499
- security_groups = [aws_security_group.alb.id]
500
- }
501
-
502
- egress {
503
- from_port = 0
504
- to_port = 0
505
- protocol = "-1"
506
- cidr_blocks = ["0.0.0.0/0"]
507
- }
508
-
509
- tags = { Name = "${local.name}-sg" }
510
- lifecycle { create_before_destroy = true }
511
- }
512
-
513
- resource "aws_security_group" "alb" {
514
- name_prefix = "${local.name}-alb-"
515
- description = "Internal Cognee ALB"
516
- vpc_id = var.vpc_id
517
-
518
- dynamic "ingress" {
519
- for_each = var.allowed_internal_cidr_blocks
520
-
521
- content {
522
- description = "Allowed internal caller CIDR"
523
- from_port = 80
524
- to_port = 80
525
- protocol = "tcp"
526
- cidr_blocks = [ingress.value]
527
- }
528
- }
529
-
530
- dynamic "ingress" {
531
- for_each = var.allowed_internal_security_group_ids
532
-
533
- content {
534
- description = "Allowed internal caller security group"
535
- from_port = 80
536
- to_port = 80
537
- protocol = "tcp"
538
- security_groups = [ingress.value]
539
- }
540
- }
541
-
542
- egress {
543
- from_port = 0
544
- to_port = 0
545
- protocol = "-1"
546
- cidr_blocks = ["0.0.0.0/0"]
547
- }
548
-
549
- tags = { Name = "${local.name}-alb-sg" }
550
- lifecycle { create_before_destroy = true }
551
- }
552
-
553
- resource "aws_security_group" "efs" {
554
- name_prefix = "${local.name}-efs-"
555
- description = "Cognee EFS storage"
556
- vpc_id = var.vpc_id
557
-
558
- ingress {
559
- description = "Cognee task to EFS"
560
- from_port = 2049
561
- to_port = 2049
562
- protocol = "tcp"
563
- security_groups = [aws_security_group.cognee.id]
564
- }
565
-
566
- egress {
567
- from_port = 0
568
- to_port = 0
569
- protocol = "-1"
570
- cidr_blocks = ["0.0.0.0/0"]
571
- }
572
-
573
- tags = { Name = "${local.name}-efs-sg" }
574
- lifecycle { create_before_destroy = true }
575
- }
576
-
577
- resource "aws_security_group_rule" "aurora_from_cognee" {
578
- type = "ingress"
579
- from_port = var.db_port
580
- to_port = var.db_port
581
- protocol = "tcp"
582
- source_security_group_id = aws_security_group.cognee.id
583
- security_group_id = var.db_security_group_id
584
- }
585
-
586
- ################################################################################
587
- # ALB
588
- ################################################################################
589
-
590
- resource "aws_lb" "cognee" {
591
- name = local.resource_short_name
592
- internal = true
593
- load_balancer_type = "application"
594
- security_groups = [aws_security_group.alb.id]
595
- subnets = var.subnet_ids
596
-
597
- tags = { Name = "${local.name}-alb" }
598
- }
599
-
600
- resource "aws_lb_target_group" "cognee" {
601
- name = local.resource_short_name
602
- port = var.container_port
603
- protocol = "HTTP"
604
- vpc_id = var.vpc_id
605
- target_type = "ip"
606
-
607
- health_check {
608
- path = var.health_check_path
609
- port = tostring(var.container_port)
610
- protocol = "HTTP"
611
- healthy_threshold = 2
612
- unhealthy_threshold = 3
613
- timeout = 10
614
- interval = 30
615
- matcher = "200-399"
616
- }
617
-
618
- tags = { Name = "${local.name}-tg" }
619
- }
620
-
621
- resource "aws_lb_listener" "cognee" {
622
- load_balancer_arn = aws_lb.cognee.arn
623
- port = 80
624
- protocol = "HTTP"
625
-
626
- default_action {
627
- type = "forward"
628
- target_group_arn = aws_lb_target_group.cognee.arn
629
- }
630
- }
631
-
632
- ################################################################################
633
- # Persistent writable storage
634
- ################################################################################
635
-
636
- resource "aws_efs_file_system" "cognee" {
637
- creation_token = local.name
638
- encrypted = true
639
-
640
- tags = { Name = "${local.name}-efs" }
641
- }
642
-
643
- resource "aws_efs_mount_target" "cognee" {
644
- for_each = local.efs_mount_subnet_ids_by_index
645
-
646
- file_system_id = aws_efs_file_system.cognee.id
647
- subnet_id = each.value
648
- security_groups = [aws_security_group.efs.id]
649
- }
650
-
651
- ################################################################################
652
- # CloudWatch Logs
653
- ################################################################################
654
-
655
- resource "aws_cloudwatch_log_group" "cognee" {
656
- name = local.log_group_name
657
- retention_in_days = var.log_retention_days
658
-
659
- tags = { Name = "${local.name}-logs" }
660
- }
661
-
662
- ################################################################################
663
- # ECS Task Definition
664
- ################################################################################
665
-
666
- resource "aws_ecs_task_definition" "cognee" {
667
- family = local.name
668
- requires_compatibilities = ["FARGATE"]
669
- network_mode = "awsvpc"
670
- cpu = var.cpu
671
- memory = var.memory
672
- execution_role_arn = aws_iam_role.ecs_execution.arn
673
- task_role_arn = aws_iam_role.ecs_task.arn
674
-
675
- runtime_platform {
676
- operating_system_family = "LINUX"
677
- cpu_architecture = var.cpu_architecture
678
- }
679
-
680
- volume {
681
- name = "cognee-storage"
682
-
683
- efs_volume_configuration {
684
- file_system_id = aws_efs_file_system.cognee.id
685
- transit_encryption = "ENABLED"
686
- }
687
- }
688
-
689
- container_definitions = jsonencode([{
690
- name = "cognee"
691
- image = var.image_uri
692
- essential = true
693
-
694
- portMappings = [{
695
- containerPort = var.container_port
696
- protocol = "tcp"
697
- }]
698
-
699
- environment = concat(local.base_environment, local.optional_environment)
700
- secrets = local.container_secrets
701
-
702
- mountPoints = [{
703
- sourceVolume = "cognee-storage"
704
- containerPath = "/app/cognee-storage"
705
- readOnly = false
706
- }]
707
-
708
- logConfiguration = {
709
- logDriver = "awslogs"
710
- options = {
711
- "awslogs-group" = aws_cloudwatch_log_group.cognee.name
712
- "awslogs-region" = data.aws_region.current.name
713
- "awslogs-stream-prefix" = "cognee"
714
- }
715
- }
716
-
717
- healthCheck = {
718
- command = ["CMD-SHELL", "curl -f http://localhost:${var.container_port}${var.health_check_path} || exit 1"]
719
- interval = 30
720
- timeout = 10
721
- retries = 3
722
- startPeriod = 300
723
- }
724
- }])
725
-
726
- depends_on = [aws_efs_mount_target.cognee, terraform_data.configuration_guardrails]
727
-
728
- tags = { Name = local.name }
729
- }
730
-
731
- ################################################################################
732
- # ECS Service
733
- ################################################################################
734
-
735
- resource "aws_ecs_service" "cognee" {
736
- name = local.name
737
- cluster = aws_ecs_cluster.main.id
738
- task_definition = aws_ecs_task_definition.cognee.arn
739
- desired_count = var.desired_count
740
- launch_type = "FARGATE"
741
-
742
- # Allow `aws ecs execute-command` into the running container (operational
743
- # introspection of the dogfood Cognee store/API, whose ALB is VPC-internal).
744
- enable_execute_command = var.enable_execute_command
745
-
746
- deployment_minimum_healthy_percent = var.backend_mode == "dogfood" ? 0 : 100
747
- deployment_maximum_percent = var.backend_mode == "dogfood" ? 100 : 200
748
- health_check_grace_period_seconds = var.health_check_grace_period_seconds
749
- wait_for_steady_state = var.wait_for_steady_state
750
-
751
- network_configuration {
752
- subnets = var.subnet_ids
753
- security_groups = [aws_security_group.cognee.id]
754
- assign_public_ip = true
755
- }
756
-
757
- load_balancer {
758
- target_group_arn = aws_lb_target_group.cognee.arn
759
- container_name = "cognee"
760
- container_port = var.container_port
761
- }
762
-
763
- depends_on = [aws_lb_listener.cognee, terraform_data.configuration_guardrails]
764
-
765
- tags = { Name = local.name }
766
- }