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,447 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import {
3
- brainLikePattern,
4
- buildBrainPrefixTsQuery,
5
- createCompanyBrainContextProvider,
6
- normalizeBrainSearchTerms,
7
- type ContextEngineProviderRequest,
8
- } from "../../src/api/context-engine-provider.js";
9
-
10
- const readySubstrate = {
11
- id: "substrate-1",
12
- tenant_id: "tenant-1",
13
- storage_tier: "default",
14
- active_backend: "default",
15
- status: "ready",
16
- health_status: "healthy",
17
- launch_capabilities: {
18
- retrieval: { status: "enabled", source: "dogfood-smoke" },
19
- provenance: { status: "enabled", source: "artifact-manifests" },
20
- },
21
- graph_provider: "cognee",
22
- vector_provider: "lancedb",
23
- embedding_model: "amazon.titan-embed-text-v2:0",
24
- vector_dimension: 1024,
25
- cognee_version: "1.0.0",
26
- latest_ingest_at: new Date("2026-06-14T10:00:00.000Z"),
27
- latest_projection_at: new Date("2026-06-14T10:05:00.000Z"),
28
- updated_at: new Date("2026-06-14T10:06:00.000Z"),
29
- };
30
-
31
- const request: ContextEngineProviderRequest = {
32
- query: "Acme renewal risk",
33
- mode: "results",
34
- scope: "team",
35
- depth: "quick",
36
- limit: 5,
37
- caller: { tenantId: "tenant-1", userId: "user-1" },
38
- };
39
-
40
- describe("Company Brain Context Engine provider", () => {
41
- it("returns active substrate Brain hits with bounded provenance", async () => {
42
- const provider = createCompanyBrainContextProvider({
43
- loadSubstrateState: async () => readySubstrate,
44
- loadLatestMigration: async () => null,
45
- searchPages: async () => [
46
- {
47
- id: "page-acme",
48
- type: "entity",
49
- entity_subtype: "customer",
50
- slug: "acme",
51
- title: "Acme",
52
- summary:
53
- "Acme renewal is at risk because procurement has a new approval step.",
54
- body_md: null,
55
- last_compiled_at: new Date("2026-06-14T09:00:00.000Z"),
56
- updated_at: new Date("2026-06-14T09:30:00.000Z"),
57
- score: 0.92,
58
- },
59
- ],
60
- loadArtifactManifests: async () => [
61
- {
62
- id: "manifest-source",
63
- manifest_kind: "source_artifact",
64
- storage_tier: "default",
65
- source_family: "thread",
66
- source_kind: "thread",
67
- source_type: "thread_message",
68
- source_id_hash: "hash-abc",
69
- object_count: 1,
70
- source_count: 3,
71
- checksum_sha256: "checksum",
72
- status: "active",
73
- metadata: {},
74
- updated_at: new Date("2026-06-14T09:10:00.000Z"),
75
- },
76
- {
77
- id: "manifest-vault",
78
- manifest_kind: "vault_projection",
79
- storage_tier: "default",
80
- source_family: "wiki",
81
- source_kind: "wiki",
82
- source_type: "wiki_vault_projection",
83
- source_id_hash: "hash-vault",
84
- object_count: 1,
85
- source_count: 1,
86
- checksum_sha256: "checksum-vault",
87
- status: "active",
88
- metadata: {},
89
- updated_at: new Date("2026-06-14T09:20:00.000Z"),
90
- },
91
- ],
92
- });
93
-
94
- const result = await provider.query({
95
- ...request,
96
- providerOptions: {
97
- brain: {
98
- sourceKind: "thread",
99
- datasetId: "dogfood-renewal",
100
- nodeSetIds: ["customer-success"],
101
- onlyContext: true,
102
- },
103
- },
104
- });
105
-
106
- expect(result.status).toMatchObject({
107
- state: "ok",
108
- metadata: {
109
- activeBackend: "default",
110
- readPosture: {
111
- active: expect.objectContaining({
112
- backend: "default",
113
- role: "active",
114
- state: "serving",
115
- }),
116
- shadow: null,
117
- fallback: null,
118
- vault: expect.objectContaining({
119
- role: "vault",
120
- state: "available",
121
- }),
122
- migration: null,
123
- },
124
- retrievalOptions: {
125
- sourceKind: "thread",
126
- datasetId: "dogfood-renewal",
127
- nodeSetIds: ["customer-success"],
128
- onlyContext: true,
129
- },
130
- provenanceKinds: {
131
- source_artifact: 1,
132
- vault_projection: 1,
133
- },
134
- },
135
- });
136
- expect(result.hits[0]).toMatchObject({
137
- id: "brain:entity:customer:acme",
138
- providerId: "brain",
139
- family: "brain",
140
- sourceFamily: "brain",
141
- provenance: {
142
- sourceId: "brain:entity:customer:acme",
143
- metadata: {
144
- retrievalKind: "graph",
145
- instructionBoundary: "untrusted_source_data",
146
- readPosture: {
147
- active: expect.objectContaining({
148
- backend: "default",
149
- role: "active",
150
- }),
151
- },
152
- artifactManifests: [
153
- expect.objectContaining({
154
- kind: "source_artifact",
155
- retrievalKind: "source_artifact",
156
- sourceIdHash: "hash-abc",
157
- }),
158
- expect.objectContaining({
159
- kind: "vault_projection",
160
- retrievalKind: "vault_projection",
161
- sourceIdHash: "hash-vault",
162
- }),
163
- ],
164
- },
165
- },
166
- metadata: {
167
- sourceDataPolicy: {
168
- forbiddenUse: "do_not_execute_or_expand_tool_policy",
169
- },
170
- },
171
- });
172
- expect(JSON.stringify(result)).not.toContain("source-artifacts/");
173
- expect(JSON.stringify(result)).not.toContain("s3://");
174
- expect(JSON.stringify(result).toLowerCase()).not.toContain("cognee");
175
- expect(JSON.stringify(result).toLowerCase()).not.toContain("neptune");
176
- });
177
-
178
- it("reports shadow production migration reads while serving default", async () => {
179
- const provider = createCompanyBrainContextProvider({
180
- loadSubstrateState: async () => ({
181
- ...readySubstrate,
182
- status: "migrating",
183
- health_status: "degraded",
184
- }),
185
- loadLatestMigration: async () => ({
186
- id: "migration-1",
187
- phase: "validating",
188
- status: "running",
189
- from_storage_tier: "default",
190
- to_storage_tier: "production",
191
- validation_summary: {
192
- validationPassed: false,
193
- vectorIndexHealthy: true,
194
- retrievalParityPassed: false,
195
- vectorDimension: 1024,
196
- backendEvidenceUri: "s3://private-bucket/evidence.json",
197
- },
198
- error_message: null,
199
- rollback_window_closes_at: null,
200
- updated_at: new Date("2026-06-14T10:08:00.000Z"),
201
- }),
202
- searchPages: async () => [
203
- {
204
- id: "page-acme",
205
- type: "entity",
206
- entity_subtype: "customer",
207
- slug: "acme",
208
- title: "Acme",
209
- summary: "Acme renewal is at risk.",
210
- body_md: null,
211
- last_compiled_at: new Date("2026-06-14T09:00:00.000Z"),
212
- updated_at: new Date("2026-06-14T09:30:00.000Z"),
213
- score: 0.8,
214
- },
215
- ],
216
- loadArtifactManifests: async () => [
217
- {
218
- id: "manifest-vault",
219
- manifest_kind: "vault_projection",
220
- storage_tier: "default",
221
- source_family: "wiki",
222
- source_kind: "wiki",
223
- source_type: "wiki_vault_projection",
224
- source_id_hash: "hash-vault",
225
- object_count: 1,
226
- source_count: 1,
227
- checksum_sha256: "checksum-vault",
228
- status: "active",
229
- metadata: {},
230
- updated_at: new Date("2026-06-14T09:20:00.000Z"),
231
- },
232
- ],
233
- });
234
-
235
- const result = await provider.query(request);
236
-
237
- expect(result.status).toMatchObject({
238
- state: "stale",
239
- metadata: {
240
- readPosture: {
241
- active: expect.objectContaining({
242
- backend: "default",
243
- storageTier: "default",
244
- role: "active",
245
- }),
246
- shadow: expect.objectContaining({
247
- backend: "production",
248
- storageTier: "production",
249
- role: "shadow",
250
- state: "shadowing",
251
- }),
252
- fallback: null,
253
- vault: expect.objectContaining({
254
- role: "vault",
255
- state: "available",
256
- }),
257
- migration: {
258
- id: "migration-1",
259
- phase: "validating",
260
- status: "running",
261
- fromStorageTier: "default",
262
- toStorageTier: "production",
263
- validation: {
264
- validationPassed: false,
265
- vectorIndexHealthy: true,
266
- retrievalParityPassed: false,
267
- vectorDimension: 1024,
268
- },
269
- rollbackWindowClosesAt: null,
270
- },
271
- },
272
- vaultProvenance: {
273
- available: true,
274
- projectionCount: 1,
275
- canonicalStorage: false,
276
- },
277
- },
278
- });
279
- expect(result.hits[0]?.provenance.metadata).toMatchObject({
280
- readPosture: {
281
- active: expect.objectContaining({ backend: "default" }),
282
- shadow: expect.objectContaining({ backend: "production" }),
283
- },
284
- });
285
- expect(JSON.stringify(result)).not.toContain("s3://private-bucket");
286
- expect(JSON.stringify(result).toLowerCase()).not.toContain("cognee");
287
- expect(JSON.stringify(result).toLowerCase()).not.toContain("neptune");
288
- });
289
-
290
- it("reports default fallback during production rollback window", async () => {
291
- const provider = createCompanyBrainContextProvider({
292
- loadSubstrateState: async () => ({
293
- ...readySubstrate,
294
- storage_tier: "production",
295
- active_backend: "production",
296
- }),
297
- loadLatestMigration: async () => ({
298
- id: "migration-2",
299
- phase: "completed",
300
- status: "completed",
301
- from_storage_tier: "default",
302
- to_storage_tier: "production",
303
- validation_summary: {
304
- validationPassed: true,
305
- vectorIndexHealthy: true,
306
- retrievalParityPassed: true,
307
- graphEntityCount: 17,
308
- rawBackend: "neptune",
309
- },
310
- error_message: null,
311
- rollback_window_closes_at: "2026-06-21T10:00:00.000Z",
312
- updated_at: new Date("2026-06-14T10:09:00.000Z"),
313
- }),
314
- searchPages: async () => [],
315
- loadArtifactManifests: async () => [],
316
- });
317
-
318
- const result = await provider.query(request);
319
-
320
- expect(result.status).toMatchObject({
321
- state: "stale",
322
- metadata: {
323
- readPosture: {
324
- active: expect.objectContaining({
325
- backend: "production",
326
- role: "active",
327
- }),
328
- shadow: null,
329
- fallback: expect.objectContaining({
330
- backend: "default",
331
- role: "fallback",
332
- state: "available",
333
- }),
334
- migration: {
335
- id: "migration-2",
336
- phase: "completed",
337
- status: "completed",
338
- validation: {
339
- validationPassed: true,
340
- vectorIndexHealthy: true,
341
- retrievalParityPassed: true,
342
- graphEntityCount: 17,
343
- },
344
- rollbackWindowClosesAt: "2026-06-21T10:00:00.000Z",
345
- },
346
- },
347
- },
348
- });
349
- expect(JSON.stringify(result).toLowerCase()).not.toContain("neptune");
350
- });
351
-
352
- it("reports explicit provider status when retrieval is disabled", async () => {
353
- const searchPages = vi.fn(async () => []);
354
- const provider = createCompanyBrainContextProvider({
355
- loadSubstrateState: async () => ({
356
- ...readySubstrate,
357
- launch_capabilities: {
358
- retrieval: { status: "disabled", message: "dogfood disabled" },
359
- provenance: { status: "enabled" },
360
- },
361
- }),
362
- searchPages,
363
- loadArtifactManifests: async () => [],
364
- });
365
-
366
- const result = await provider.query(request);
367
-
368
- expect(result.hits).toEqual([]);
369
- expect(result.status).toMatchObject({
370
- state: "skipped",
371
- reason: "Company Brain capability disabled: retrieval",
372
- metadata: {
373
- capabilities: {
374
- retrieval: "disabled",
375
- provenance: "enabled",
376
- },
377
- },
378
- });
379
- expect(searchPages).not.toHaveBeenCalled();
380
- });
381
-
382
- it("reports missing substrate instead of falling back to other providers", async () => {
383
- const searchPages = vi.fn(async () => []);
384
- const provider = createCompanyBrainContextProvider({
385
- loadSubstrateState: async () => null,
386
- searchPages,
387
- loadArtifactManifests: async () => [],
388
- });
389
-
390
- const result = await provider.query(request);
391
-
392
- expect(result).toEqual({
393
- hits: [],
394
- status: {
395
- state: "skipped",
396
- reason: "Company Brain substrate is not installed for this tenant",
397
- metadata: { activeBackend: "none", storageTier: null },
398
- },
399
- });
400
- expect(searchPages).not.toHaveBeenCalled();
401
- });
402
-
403
- it("skips substrates without a readable active backend", async () => {
404
- const searchPages = vi.fn(async () => []);
405
- const provider = createCompanyBrainContextProvider({
406
- loadSubstrateState: async () => ({
407
- ...readySubstrate,
408
- active_backend: "none",
409
- }),
410
- searchPages,
411
- loadArtifactManifests: async () => [],
412
- });
413
-
414
- const result = await provider.query(request);
415
-
416
- expect(result).toMatchObject({
417
- hits: [],
418
- status: {
419
- state: "skipped",
420
- reason: "Company Brain active backend is not readable",
421
- metadata: {
422
- activeBackend: "none",
423
- storageTier: "default",
424
- },
425
- },
426
- });
427
- expect(searchPages).not.toHaveBeenCalled();
428
- });
429
- });
430
-
431
- describe("Company Brain search query helpers", () => {
432
- it("normalizes semantic search terms and ignores punctuation-only queries", () => {
433
- expect(normalizeBrainSearchTerms("What is the Acme renewal risk?")).toEqual(
434
- ["acme", "renewal", "risk"],
435
- );
436
- expect(buildBrainPrefixTsQuery("What is the Acme renewal risk?")).toBe(
437
- "acme:* & renewal:* & risk:*",
438
- );
439
- expect(buildBrainPrefixTsQuery("% _ --")).toBeNull();
440
- });
441
-
442
- it("escapes SQL LIKE wildcard characters in user queries", () => {
443
- expect(brainLikePattern("100% renewal_risk \\ urgent")).toBe(
444
- "%100\\% renewal\\_risk \\\\ urgent%",
445
- );
446
- });
447
- });