@elevasis/core 0.22.0 → 0.24.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 (244) hide show
  1. package/dist/index.d.ts +3214 -2501
  2. package/dist/index.js +3112 -1222
  3. package/dist/knowledge/index.d.ts +1108 -1264
  4. package/dist/knowledge/index.js +112 -9
  5. package/dist/organization-model/index.d.ts +3214 -2501
  6. package/dist/organization-model/index.js +3112 -1222
  7. package/dist/test-utils/index.d.ts +985 -1103
  8. package/dist/test-utils/index.js +2464 -1165
  9. package/package.json +5 -5
  10. package/src/README.md +14 -14
  11. package/src/__tests__/publish.test.ts +24 -24
  12. package/src/__tests__/template-core-compatibility.test.ts +9 -80
  13. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +2389 -2121
  14. package/src/_gen/__tests__/scaffold-contracts.test.ts +30 -30
  15. package/src/auth/multi-tenancy/credentials/__tests__/encryption.test.ts +217 -217
  16. package/src/auth/multi-tenancy/credentials/server/encryption.ts +69 -69
  17. package/src/auth/multi-tenancy/credentials/server/kek-loader.ts +37 -37
  18. package/src/auth/multi-tenancy/index.ts +26 -26
  19. package/src/auth/multi-tenancy/invitations/api-schemas.ts +104 -104
  20. package/src/auth/multi-tenancy/memberships/api-schemas.ts +143 -143
  21. package/src/auth/multi-tenancy/memberships/index.ts +26 -26
  22. package/src/auth/multi-tenancy/memberships/membership.ts +130 -130
  23. package/src/auth/multi-tenancy/organizations/__tests__/api-schemas.test.ts +194 -194
  24. package/src/auth/multi-tenancy/organizations/api-schemas.ts +136 -136
  25. package/src/auth/multi-tenancy/permissions.test.ts +42 -42
  26. package/src/auth/multi-tenancy/permissions.ts +123 -123
  27. package/src/auth/multi-tenancy/role-management/api-schemas.ts +78 -78
  28. package/src/auth/multi-tenancy/role-management/index.ts +16 -16
  29. package/src/auth/multi-tenancy/theme-presets.ts +45 -45
  30. package/src/auth/multi-tenancy/types.ts +57 -57
  31. package/src/auth/multi-tenancy/users/api-schemas.ts +165 -165
  32. package/src/business/README.md +2 -2
  33. package/src/business/acquisition/activity-events.test.ts +250 -250
  34. package/src/business/acquisition/activity-events.ts +93 -93
  35. package/src/business/acquisition/api-schemas.test.ts +1883 -1843
  36. package/src/business/acquisition/api-schemas.ts +1493 -1500
  37. package/src/business/acquisition/build-templates.test.ts +240 -240
  38. package/src/business/acquisition/build-templates.ts +83 -41
  39. package/src/business/acquisition/crm-next-action.test.ts +262 -262
  40. package/src/business/acquisition/crm-next-action.ts +220 -220
  41. package/src/business/acquisition/crm-priority.test.ts +216 -216
  42. package/src/business/acquisition/crm-priority.ts +349 -349
  43. package/src/business/acquisition/crm-state-actions.test.ts +153 -151
  44. package/src/business/acquisition/deal-ownership.test.ts +351 -351
  45. package/src/business/acquisition/deal-ownership.ts +120 -120
  46. package/src/business/acquisition/derive-actions.test.ts +129 -104
  47. package/src/business/acquisition/derive-actions.ts +74 -84
  48. package/src/business/acquisition/index.ts +171 -170
  49. package/src/business/acquisition/ontology-validation.ts +309 -0
  50. package/src/business/acquisition/stateful.ts +30 -30
  51. package/src/business/acquisition/types.ts +396 -392
  52. package/src/business/clients/api-schemas.test.ts +115 -115
  53. package/src/business/clients/api-schemas.ts +158 -158
  54. package/src/business/clients/index.ts +1 -1
  55. package/src/business/crm/api-schemas.ts +40 -40
  56. package/src/business/crm/index.ts +1 -1
  57. package/src/business/deals/api-schemas.ts +87 -87
  58. package/src/business/deals/index.ts +1 -1
  59. package/src/business/index.ts +5 -5
  60. package/src/business/projects/types.ts +144 -144
  61. package/src/commands/queue/types/task.ts +15 -15
  62. package/src/execution/core/runner-types.ts +61 -61
  63. package/src/execution/core/sse-executions.ts +7 -7
  64. package/src/execution/engine/__tests__/fixtures/test-agents.ts +10 -10
  65. package/src/execution/engine/agent/core/__tests__/agent.test.ts +16 -16
  66. package/src/execution/engine/agent/core/__tests__/error-passthrough.test.ts +4 -4
  67. package/src/execution/engine/agent/core/types.ts +25 -25
  68. package/src/execution/engine/agent/index.ts +6 -6
  69. package/src/execution/engine/agent/reasoning/__tests__/request-builder.test.ts +24 -24
  70. package/src/execution/engine/index.ts +443 -443
  71. package/src/execution/engine/tools/integration/server/adapters/apify/__tests__/apify-run-actor.integration.test.ts +298 -298
  72. package/src/execution/engine/tools/integration/server/adapters/apify/apify-adapter.test.ts +55 -55
  73. package/src/execution/engine/tools/integration/server/adapters/apify/apify-adapter.ts +107 -107
  74. package/src/execution/engine/tools/integration/server/adapters/apollo/apollo-adapter.test.ts +48 -48
  75. package/src/execution/engine/tools/integration/server/adapters/apollo/apollo-adapter.ts +99 -99
  76. package/src/execution/engine/tools/integration/server/adapters/apollo/index.ts +1 -1
  77. package/src/execution/engine/tools/integration/server/adapters/attio/__tests__/attio-crud.integration.test.ts +363 -363
  78. package/src/execution/engine/tools/integration/server/adapters/attio/fetch/get-record/index.test.ts +162 -162
  79. package/src/execution/engine/tools/integration/server/adapters/attio/fetch/list-records/index.test.ts +316 -316
  80. package/src/execution/engine/tools/integration/server/adapters/clickup/clickup-adapter.test.ts +18 -18
  81. package/src/execution/engine/tools/integration/server/adapters/clickup/clickup-adapter.ts +194 -194
  82. package/src/execution/engine/tools/integration/server/adapters/clickup/index.ts +7 -7
  83. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-adapter.ts +204 -204
  84. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-tools.ts +105 -105
  85. package/src/execution/engine/tools/integration/server/adapters/google-calendar/google-calendar-adapter.ts +428 -428
  86. package/src/execution/engine/tools/integration/server/adapters/google-calendar/index.ts +2 -2
  87. package/src/execution/engine/tools/integration/server/adapters/google-sheets/__tests__/google-sheets.integration.test.ts +261 -261
  88. package/src/execution/engine/tools/integration/server/adapters/instantly/instantly-tools.ts +1474 -1474
  89. package/src/execution/engine/tools/integration/server/adapters/millionverifier/millionverifier-tools.ts +103 -103
  90. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/send-email/index.test.ts +88 -88
  91. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/send-email/index.ts +141 -141
  92. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/utils/types.ts +76 -76
  93. package/src/execution/engine/tools/integration/server/adapters/signature-api/signature-api-tools.ts +182 -182
  94. package/src/execution/engine/tools/integration/server/adapters/stripe/stripe-tools.ts +310 -310
  95. package/src/execution/engine/tools/integration/service.test.ts +239 -239
  96. package/src/execution/engine/tools/integration/service.ts +172 -172
  97. package/src/execution/engine/tools/integration/tool.ts +255 -255
  98. package/src/execution/engine/tools/lead-service-types.ts +1005 -1005
  99. package/src/execution/engine/tools/messages.ts +43 -43
  100. package/src/execution/engine/tools/platform/acquisition/company-tools.ts +7 -7
  101. package/src/execution/engine/tools/platform/acquisition/contact-tools.ts +6 -6
  102. package/src/execution/engine/tools/platform/acquisition/list-tools.ts +6 -6
  103. package/src/execution/engine/tools/platform/acquisition/types.ts +280 -280
  104. package/src/execution/engine/tools/platform/email/types.ts +97 -97
  105. package/src/execution/engine/tools/registry.ts +704 -704
  106. package/src/execution/engine/tools/tool-maps.ts +831 -831
  107. package/src/execution/engine/tools/types.ts +234 -234
  108. package/src/execution/engine/workflow/types.ts +202 -202
  109. package/src/execution/external/__tests__/api-schemas.test.ts +127 -127
  110. package/src/execution/external/api-schemas.ts +40 -40
  111. package/src/execution/external/index.ts +1 -1
  112. package/src/index.ts +18 -18
  113. package/src/integrations/credentials/__tests__/api-schemas.test.ts +420 -420
  114. package/src/integrations/credentials/api-schemas.ts +146 -146
  115. package/src/integrations/credentials/schemas.ts +200 -200
  116. package/src/integrations/oauth/__tests__/provider-registry.test.ts +7 -7
  117. package/src/integrations/oauth/provider-registry.ts +74 -74
  118. package/src/integrations/oauth/server/credentials.ts +43 -43
  119. package/src/integrations/webhook-endpoints/__tests__/api-schemas.test.ts +327 -327
  120. package/src/integrations/webhook-endpoints/api-schemas.ts +103 -103
  121. package/src/integrations/webhook-endpoints/types.ts +58 -58
  122. package/src/knowledge/README.md +33 -32
  123. package/src/knowledge/__tests__/queries.test.ts +633 -541
  124. package/src/knowledge/format.ts +100 -99
  125. package/src/knowledge/index.ts +5 -5
  126. package/src/knowledge/published.ts +5 -5
  127. package/src/knowledge/queries.ts +274 -222
  128. package/src/operations/activities/api-schemas.ts +80 -80
  129. package/src/operations/activities/types.ts +64 -64
  130. package/src/organization-model/README.md +149 -109
  131. package/src/organization-model/__tests__/content-kinds-registry.test.ts +210 -0
  132. package/src/organization-model/__tests__/defaults.test.ts +168 -194
  133. package/src/organization-model/__tests__/domains/actions.test.ts +78 -0
  134. package/src/organization-model/__tests__/domains/customers.test.ts +48 -44
  135. package/src/organization-model/__tests__/domains/entities.test.ts +56 -0
  136. package/src/organization-model/__tests__/domains/goals.test.ts +110 -96
  137. package/src/organization-model/__tests__/domains/identity.test.ts +4 -3
  138. package/src/organization-model/__tests__/domains/navigation.test.ts +222 -166
  139. package/src/organization-model/__tests__/domains/offerings.test.ts +83 -88
  140. package/src/organization-model/__tests__/domains/policies.test.ts +323 -0
  141. package/src/organization-model/__tests__/domains/resource-mappings.test.ts +30 -30
  142. package/src/organization-model/__tests__/domains/resources.test.ts +396 -175
  143. package/src/organization-model/__tests__/domains/roles.test.ts +463 -402
  144. package/src/organization-model/__tests__/domains/statuses.test.ts +13 -10
  145. package/src/organization-model/__tests__/domains/systems.test.ts +209 -193
  146. package/src/organization-model/__tests__/flatten-additive-merge.test.ts +362 -0
  147. package/src/organization-model/__tests__/foundation.test.ts +47 -75
  148. package/src/organization-model/__tests__/get-resources-for-system.test.ts +144 -0
  149. package/src/organization-model/__tests__/graph.test.ts +1336 -149
  150. package/src/organization-model/__tests__/icons.test.ts +10 -1
  151. package/src/organization-model/__tests__/knowledge.test.ts +418 -61
  152. package/src/organization-model/__tests__/lookup-helpers.test.ts +438 -0
  153. package/src/organization-model/__tests__/migration-helpers.test.ts +591 -0
  154. package/src/organization-model/__tests__/prospecting-ssot.test.ts +103 -94
  155. package/src/organization-model/__tests__/recursive-system-schema.test.ts +549 -0
  156. package/src/organization-model/__tests__/resolve.test.ts +303 -42
  157. package/src/organization-model/__tests__/schema.test.ts +863 -153
  158. package/src/organization-model/__tests__/surface-projection.test.ts +284 -174
  159. package/src/organization-model/catalogs/lead-gen.ts +144 -0
  160. package/src/organization-model/content-kinds/config.ts +36 -0
  161. package/src/organization-model/content-kinds/index.ts +78 -0
  162. package/src/organization-model/content-kinds/pipeline.ts +68 -0
  163. package/src/organization-model/content-kinds/registry.ts +44 -0
  164. package/src/organization-model/content-kinds/status.ts +71 -0
  165. package/src/organization-model/content-kinds/template.ts +83 -0
  166. package/src/organization-model/content-kinds/types.ts +117 -0
  167. package/src/organization-model/contracts.ts +27 -17
  168. package/src/organization-model/defaults.ts +489 -107
  169. package/src/organization-model/domains/actions.ts +333 -0
  170. package/src/organization-model/domains/customers.ts +10 -7
  171. package/src/organization-model/domains/entities.ts +144 -0
  172. package/src/organization-model/domains/goals.ts +9 -6
  173. package/src/organization-model/domains/knowledge.ts +128 -54
  174. package/src/organization-model/domains/navigation.ts +139 -416
  175. package/src/organization-model/domains/offerings.ts +15 -10
  176. package/src/organization-model/domains/policies.ts +102 -0
  177. package/src/organization-model/domains/projects.ts +6 -40
  178. package/src/organization-model/domains/prospecting.ts +395 -514
  179. package/src/organization-model/domains/resources.ts +173 -81
  180. package/src/organization-model/domains/roles.ts +96 -93
  181. package/src/organization-model/domains/sales.test.ts +218 -218
  182. package/src/organization-model/domains/sales.ts +380 -589
  183. package/src/organization-model/domains/shared.ts +8 -8
  184. package/src/organization-model/domains/statuses.ts +298 -89
  185. package/src/organization-model/domains/systems.ts +240 -38
  186. package/src/organization-model/foundation.ts +35 -48
  187. package/src/organization-model/graph/build.ts +1035 -279
  188. package/src/organization-model/graph/index.ts +4 -4
  189. package/src/organization-model/graph/link.ts +10 -10
  190. package/src/organization-model/graph/schema.ts +77 -56
  191. package/src/organization-model/graph/types.ts +75 -56
  192. package/src/organization-model/helpers.ts +312 -59
  193. package/src/organization-model/icons.ts +78 -66
  194. package/src/organization-model/index.ts +129 -16
  195. package/src/organization-model/migration-helpers.ts +252 -0
  196. package/src/organization-model/ontology.ts +661 -0
  197. package/src/organization-model/organization-graph.mdx +110 -89
  198. package/src/organization-model/organization-model.mdx +226 -171
  199. package/src/organization-model/published.ts +295 -139
  200. package/src/organization-model/resolve.ts +139 -21
  201. package/src/organization-model/schema.ts +841 -301
  202. package/src/organization-model/surface-projection.ts +212 -218
  203. package/src/organization-model/types.ts +181 -90
  204. package/src/platform/api/types.ts +38 -38
  205. package/src/platform/constants/versions.ts +3 -3
  206. package/src/platform/index.ts +23 -23
  207. package/src/platform/registry/__tests__/command-view.test.ts +5 -7
  208. package/src/platform/registry/__tests__/resource-link.test.ts +35 -30
  209. package/src/platform/registry/__tests__/resource-registry.integration.test.ts +17 -32
  210. package/src/platform/registry/__tests__/resource-registry.nested-systems.test.ts +245 -0
  211. package/src/platform/registry/__tests__/resource-registry.test.ts +2053 -2051
  212. package/src/platform/registry/__tests__/validation.test.ts +1347 -1343
  213. package/src/platform/registry/command-view.ts +10 -10
  214. package/src/platform/registry/index.ts +103 -103
  215. package/src/platform/registry/resource-link.ts +32 -32
  216. package/src/platform/registry/resource-registry.ts +890 -878
  217. package/src/platform/registry/serialization.ts +295 -295
  218. package/src/platform/registry/serialized-types.ts +166 -166
  219. package/src/platform/registry/stats-types.ts +68 -68
  220. package/src/platform/registry/types.ts +425 -425
  221. package/src/platform/registry/validation.ts +745 -743
  222. package/src/platform/utils/__tests__/validation.test.ts +1084 -1084
  223. package/src/platform/utils/validation.ts +425 -425
  224. package/src/projects/api-schemas.test.ts +39 -39
  225. package/src/projects/api-schemas.ts +291 -291
  226. package/src/reference/_generated/contracts.md +2389 -2121
  227. package/src/reference/glossary.md +76 -76
  228. package/src/scaffold-registry/__tests__/index.test.ts +206 -206
  229. package/src/scaffold-registry/__tests__/schema.test.ts +166 -166
  230. package/src/scaffold-registry/index.ts +392 -392
  231. package/src/scaffold-registry/schema.ts +243 -243
  232. package/src/server.ts +289 -289
  233. package/src/supabase/database.types.ts +3153 -3093
  234. package/src/test-utils/README.md +37 -37
  235. package/src/test-utils/entities.ts +108 -108
  236. package/src/test-utils/fixtures/memberships.ts +82 -82
  237. package/src/test-utils/index.ts +12 -12
  238. package/src/test-utils/organization-model.ts +65 -65
  239. package/src/test-utils/published.ts +6 -6
  240. package/src/test-utils/rls/RLSTestContext.ts +588 -588
  241. package/src/test-utils/test-utils.test.ts +44 -49
  242. package/src/organization-model/__tests__/domains/operations.test.ts +0 -203
  243. package/src/organization-model/domains/features.ts +0 -31
  244. package/src/organization-model/domains/operations.ts +0 -85
@@ -1,98 +1,105 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { byFeature, byKind, byOwner, governs, governedBy, parsePath } from '../queries'
3
- import { formatText, formatJson, formatIdsOnly } from '../format'
4
- import type { OrganizationGraph } from '../../organization-model/graph/types'
5
- import type { OrgKnowledgeNode } from '../../organization-model/domains/knowledge'
6
-
7
- // ---------------------------------------------------------------------------
8
- // Synthetic fixtures
9
- // ---------------------------------------------------------------------------
10
-
11
- /**
12
- * Three knowledge nodes covering all three kinds.
13
- * - playbook-a governs feature:sales.crm and feature:sales.lead-gen
14
- * - strategy-b governs feature:sales.lead-gen
15
- * - reference-c has no links (no governs edges)
16
- * - playbook-d is owned by "role.ops-lead"
17
- */
18
- const NODES: OrgKnowledgeNode[] = [
19
- {
20
- id: 'knowledge.playbook-a',
21
- kind: 'playbook',
22
- title: 'Playbook A',
23
- summary: 'Playbook A summary.',
24
- body: '## Playbook A\n\nContent.',
25
- links: [{ nodeId: 'feature:sales.crm' }, { nodeId: 'feature:sales.lead-gen' }],
26
- ownerIds: [],
27
- updatedAt: '2026-01-01'
28
- },
29
- {
30
- id: 'knowledge.strategy-b',
31
- kind: 'strategy',
32
- title: 'Strategy B',
33
- summary: 'Strategy B summary.',
34
- body: '## Strategy B\n\nContent.',
35
- links: [{ nodeId: 'feature:sales.lead-gen' }],
36
- ownerIds: ['role.ops-lead'],
37
- updatedAt: '2026-01-02'
38
- },
39
- {
40
- id: 'knowledge.reference-c',
41
- kind: 'reference',
42
- title: 'Reference C',
43
- summary: 'Reference C summary.',
44
- body: '## Reference C\n\nContent.',
45
- links: [],
46
- ownerIds: [],
47
- updatedAt: '2026-01-03'
48
- },
49
- {
50
- id: 'knowledge.playbook-d',
51
- kind: 'playbook',
52
- title: 'Playbook D',
53
- summary: 'Playbook D summary.',
54
- body: '## Playbook D\n\nContent.',
55
- links: [],
56
- ownerIds: ['role.ops-lead', 'role.ceo'],
57
- updatedAt: '2026-01-04'
58
- }
59
- ]
60
-
61
- /**
62
- * Minimal synthetic OrganizationGraph derived from the above nodes.
63
- * Graph node IDs follow the convention: `knowledge:<om-node-id>`
64
- */
65
- const GRAPH: OrganizationGraph = {
66
- version: 1,
67
- organizationModelVersion: 1,
68
- nodes: [
69
- { id: 'organization-model', kind: 'organization', label: 'Organization Model' },
70
- { id: 'feature:sales.crm', kind: 'feature', label: 'CRM', sourceId: 'sales.crm', featureId: 'sales.crm' },
1
+ import { describe, expect, it } from 'vitest'
2
+ import { bySystem, byOntology, byKind, byOwner, governs, governedBy, parsePath } from '../queries'
3
+ import { byOntology as publicByOntology } from '../index'
4
+ import { formatText, formatJson, formatIdsOnly } from '../format'
5
+ import type { OrganizationGraph } from '../../organization-model/graph/types'
6
+ import type { OrgKnowledgeNode } from '../../organization-model/domains/knowledge'
7
+
8
+ // ---------------------------------------------------------------------------
9
+ // Synthetic fixtures
10
+ // ---------------------------------------------------------------------------
11
+
12
+ /**
13
+ * Three knowledge nodes covering all three kinds.
14
+ * - playbook-a governs system:sales.crm and system:sales.lead-gen
15
+ * - strategy-b governs system:sales.lead-gen
16
+ * - reference-c has no links (no governs edges)
17
+ * - playbook-d is owned by "role.ops-lead"
18
+ */
19
+ const NODES: OrgKnowledgeNode[] = [
20
+ {
21
+ id: 'knowledge.playbook-a',
22
+ kind: 'playbook',
23
+ title: 'Playbook A',
24
+ summary: 'Playbook A summary.',
25
+ body: '## Playbook A\n\nContent.',
26
+ links: [{ nodeId: 'system:sales.crm' }, { nodeId: 'system:sales.lead-gen' }],
27
+ ownerIds: [],
28
+ updatedAt: '2026-01-01'
29
+ },
30
+ {
31
+ id: 'knowledge.strategy-b',
32
+ kind: 'strategy',
33
+ title: 'Strategy B',
34
+ summary: 'Strategy B summary.',
35
+ body: '## Strategy B\n\nContent.',
36
+ links: [{ nodeId: 'system:sales.lead-gen' }],
37
+ ownerIds: ['role.ops-lead'],
38
+ updatedAt: '2026-01-02'
39
+ },
40
+ {
41
+ id: 'knowledge.reference-c',
42
+ kind: 'reference',
43
+ title: 'Reference C',
44
+ summary: 'Reference C summary.',
45
+ body: '## Reference C\n\nContent.',
46
+ links: [],
47
+ ownerIds: [],
48
+ updatedAt: '2026-01-03'
49
+ },
50
+ {
51
+ id: 'knowledge.playbook-d',
52
+ kind: 'playbook',
53
+ title: 'Playbook D',
54
+ summary: 'Playbook D summary.',
55
+ body: '## Playbook D\n\nContent.',
56
+ links: [],
57
+ ownerIds: ['role.ops-lead', 'role.ceo'],
58
+ updatedAt: '2026-01-04'
59
+ }
60
+ ]
61
+
62
+ /**
63
+ * Minimal synthetic OrganizationGraph derived from the above nodes.
64
+ * Graph node IDs follow the convention: `knowledge:<om-node-id>`
65
+ */
66
+ const GRAPH: OrganizationGraph = {
67
+ version: 1,
68
+ organizationModelVersion: 1,
69
+ nodes: [
70
+ { id: 'organization-model', kind: 'organization', label: 'Organization Model' },
71
+ { id: 'system:sales.crm', kind: 'system', label: 'CRM', sourceId: 'sales.crm', systemId: 'sales.crm' },
71
72
  {
72
- id: 'feature:sales.lead-gen',
73
- kind: 'feature',
73
+ id: 'system:sales.lead-gen',
74
+ kind: 'system',
74
75
  label: 'Lead Gen',
75
76
  sourceId: 'sales.lead-gen',
76
- featureId: 'sales.lead-gen'
77
- },
78
- {
79
- id: 'knowledge:knowledge.playbook-a',
80
- kind: 'knowledge',
81
- label: 'Playbook A',
82
- sourceId: 'knowledge.playbook-a'
77
+ systemId: 'sales.lead-gen'
83
78
  },
84
79
  {
85
- id: 'knowledge:knowledge.strategy-b',
86
- kind: 'knowledge',
87
- label: 'Strategy B',
88
- sourceId: 'knowledge.strategy-b'
80
+ id: 'ontology:sales.crm:object/deal',
81
+ kind: 'ontology',
82
+ label: 'Deal',
83
+ sourceId: 'sales.crm:object/deal'
89
84
  },
90
85
  {
91
- id: 'knowledge:knowledge.reference-c',
86
+ id: 'knowledge:knowledge.playbook-a',
92
87
  kind: 'knowledge',
93
- label: 'Reference C',
94
- sourceId: 'knowledge.reference-c'
95
- },
88
+ label: 'Playbook A',
89
+ sourceId: 'knowledge.playbook-a'
90
+ },
91
+ {
92
+ id: 'knowledge:knowledge.strategy-b',
93
+ kind: 'knowledge',
94
+ label: 'Strategy B',
95
+ sourceId: 'knowledge.strategy-b'
96
+ },
97
+ {
98
+ id: 'knowledge:knowledge.reference-c',
99
+ kind: 'knowledge',
100
+ label: 'Reference C',
101
+ sourceId: 'knowledge.reference-c'
102
+ },
96
103
  {
97
104
  id: 'knowledge:knowledge.playbook-d',
98
105
  kind: 'knowledge',
@@ -100,494 +107,579 @@ const GRAPH: OrganizationGraph = {
100
107
  sourceId: 'knowledge.playbook-d'
101
108
  }
102
109
  ],
103
- edges: [
104
- // contains edges (organization -> knowledge nodes)
110
+ edges: [
111
+ // contains edges (organization -> knowledge nodes)
112
+ {
113
+ id: 'edge:contains:organization-model:knowledge:knowledge.playbook-a',
114
+ kind: 'contains',
115
+ sourceId: 'organization-model',
116
+ targetId: 'knowledge:knowledge.playbook-a'
117
+ },
118
+ {
119
+ id: 'edge:contains:organization-model:knowledge:knowledge.strategy-b',
120
+ kind: 'contains',
121
+ sourceId: 'organization-model',
122
+ targetId: 'knowledge:knowledge.strategy-b'
123
+ },
124
+ {
125
+ id: 'edge:contains:organization-model:knowledge:knowledge.reference-c',
126
+ kind: 'contains',
127
+ sourceId: 'organization-model',
128
+ targetId: 'knowledge:knowledge.reference-c'
129
+ },
130
+ {
131
+ id: 'edge:contains:organization-model:knowledge:knowledge.playbook-d',
132
+ kind: 'contains',
133
+ sourceId: 'organization-model',
134
+ targetId: 'knowledge:knowledge.playbook-d'
135
+ },
136
+ // governs edges
137
+ {
138
+ id: 'edge:governs:knowledge:knowledge.playbook-a:system:sales.crm',
139
+ kind: 'governs',
140
+ sourceId: 'knowledge:knowledge.playbook-a',
141
+ targetId: 'system:sales.crm'
142
+ },
143
+ {
144
+ id: 'edge:governs:knowledge:knowledge.playbook-a:system:sales.lead-gen',
145
+ kind: 'governs',
146
+ sourceId: 'knowledge:knowledge.playbook-a',
147
+ targetId: 'system:sales.lead-gen'
148
+ },
105
149
  {
106
- id: 'edge:contains:organization-model:knowledge:knowledge.playbook-a',
107
- kind: 'contains',
108
- sourceId: 'organization-model',
109
- targetId: 'knowledge:knowledge.playbook-a'
110
- },
111
- {
112
- id: 'edge:contains:organization-model:knowledge:knowledge.strategy-b',
113
- kind: 'contains',
114
- sourceId: 'organization-model',
115
- targetId: 'knowledge:knowledge.strategy-b'
116
- },
117
- {
118
- id: 'edge:contains:organization-model:knowledge:knowledge.reference-c',
119
- kind: 'contains',
120
- sourceId: 'organization-model',
121
- targetId: 'knowledge:knowledge.reference-c'
122
- },
123
- {
124
- id: 'edge:contains:organization-model:knowledge:knowledge.playbook-d',
125
- kind: 'contains',
126
- sourceId: 'organization-model',
127
- targetId: 'knowledge:knowledge.playbook-d'
128
- },
129
- // governs edges
130
- {
131
- id: 'edge:governs:knowledge:knowledge.playbook-a:feature:sales.crm',
132
- kind: 'governs',
133
- sourceId: 'knowledge:knowledge.playbook-a',
134
- targetId: 'feature:sales.crm'
135
- },
136
- {
137
- id: 'edge:governs:knowledge:knowledge.playbook-a:feature:sales.lead-gen',
150
+ id: 'edge:governs:knowledge:knowledge.strategy-b:system:sales.lead-gen',
138
151
  kind: 'governs',
139
- sourceId: 'knowledge:knowledge.playbook-a',
140
- targetId: 'feature:sales.lead-gen'
152
+ sourceId: 'knowledge:knowledge.strategy-b',
153
+ targetId: 'system:sales.lead-gen'
141
154
  },
142
155
  {
143
- id: 'edge:governs:knowledge:knowledge.strategy-b:feature:sales.lead-gen',
156
+ id: 'edge:governs:knowledge:knowledge.playbook-d:ontology:sales.crm:object/deal',
144
157
  kind: 'governs',
145
- sourceId: 'knowledge:knowledge.strategy-b',
146
- targetId: 'feature:sales.lead-gen'
158
+ sourceId: 'knowledge:knowledge.playbook-d',
159
+ targetId: 'ontology:sales.crm:object/deal'
147
160
  }
148
161
  ]
149
162
  }
163
+
164
+ // ---------------------------------------------------------------------------
165
+ // bySystem
166
+ // ---------------------------------------------------------------------------
167
+
168
+ describe('bySystem', () => {
169
+ it('returns nodes that have governs edges to the given system', () => {
170
+ const result = bySystem(GRAPH, 'sales.crm', NODES)
171
+ expect(result).toHaveLength(1)
172
+ expect(result[0].id).toBe('knowledge.playbook-a')
173
+ })
174
+
175
+ it('returns multiple nodes when multiple knowledge nodes govern the same system', () => {
176
+ const result = bySystem(GRAPH, 'sales.lead-gen', NODES)
177
+ const ids = result.map((n) => n.id).sort()
178
+ expect(ids).toEqual(['knowledge.playbook-a', 'knowledge.strategy-b'].sort())
179
+ })
180
+
181
+ it('returns empty array when no node governs the system', () => {
182
+ const result = bySystem(GRAPH, 'system.does-not-exist', NODES)
183
+ expect(result).toHaveLength(0)
184
+ })
185
+
186
+ it('returns full OrgKnowledgeNode objects (not just graph stubs)', () => {
187
+ const result = bySystem(GRAPH, 'sales.crm', NODES)
188
+ expect(result[0].body).toBeDefined()
189
+ expect(result[0].links).toBeDefined()
190
+ expect(result[0].ownerIds).toBeDefined()
191
+ })
192
+ })
150
193
 
151
194
  // ---------------------------------------------------------------------------
152
- // byFeature
195
+ // byOntology
153
196
  // ---------------------------------------------------------------------------
154
197
 
155
- describe('byFeature', () => {
156
- it('returns nodes that have governs edges to the given feature', () => {
157
- const result = byFeature(GRAPH, 'sales.crm', NODES)
158
- expect(result).toHaveLength(1)
159
- expect(result[0].id).toBe('knowledge.playbook-a')
160
- })
161
-
162
- it('returns multiple nodes when multiple knowledge nodes govern the same feature', () => {
163
- const result = byFeature(GRAPH, 'sales.lead-gen', NODES)
164
- const ids = result.map((n) => n.id).sort()
165
- expect(ids).toEqual(['knowledge.playbook-a', 'knowledge.strategy-b'].sort())
166
- })
167
-
168
- it('returns empty array when no node governs the feature', () => {
169
- const result = byFeature(GRAPH, 'feature.does-not-exist', NODES)
170
- expect(result).toHaveLength(0)
171
- })
172
-
173
- it('returns full OrgKnowledgeNode objects (not just graph stubs)', () => {
174
- const result = byFeature(GRAPH, 'sales.crm', NODES)
175
- expect(result[0].body).toBeDefined()
176
- expect(result[0].links).toBeDefined()
177
- expect(result[0].ownerIds).toBeDefined()
198
+ describe('byOntology', () => {
199
+ it('returns nodes that have governs edges to the given ontology id', () => {
200
+ const result = byOntology(GRAPH, 'sales.crm:object/deal', NODES)
201
+ expect(result.map((node) => node.id)).toEqual(['knowledge.playbook-d'])
202
+ })
203
+
204
+ it('accepts an ontology graph node id', () => {
205
+ const result = byOntology(GRAPH, 'ontology:sales.crm:object/deal', NODES)
206
+ expect(result.map((node) => node.id)).toEqual(['knowledge.playbook-d'])
207
+ })
208
+
209
+ it('routes raw ontology ids to ontology graph nodes instead of bridge-era system ids', () => {
210
+ const graph: OrganizationGraph = {
211
+ ...GRAPH,
212
+ nodes: [
213
+ ...GRAPH.nodes,
214
+ {
215
+ id: 'system:sales.crm:object/deal',
216
+ kind: 'system',
217
+ label: 'Bridge-shaped System',
218
+ sourceId: 'sales.crm:object/deal',
219
+ systemId: 'sales.crm:object/deal'
220
+ },
221
+ {
222
+ id: 'knowledge:knowledge.system-shaped',
223
+ kind: 'knowledge',
224
+ label: 'System Shaped',
225
+ sourceId: 'knowledge.system-shaped'
226
+ }
227
+ ],
228
+ edges: [
229
+ ...GRAPH.edges,
230
+ {
231
+ id: 'edge:governs:knowledge:knowledge.system-shaped:system:sales.crm:object/deal',
232
+ kind: 'governs',
233
+ sourceId: 'knowledge:knowledge.system-shaped',
234
+ targetId: 'system:sales.crm:object/deal'
235
+ }
236
+ ]
237
+ }
238
+ const nodes: OrgKnowledgeNode[] = [
239
+ ...NODES,
240
+ {
241
+ id: 'knowledge.system-shaped',
242
+ kind: 'reference',
243
+ title: 'System Shaped',
244
+ summary: 'Should not match raw ontology lookup.',
245
+ body: 'Body.',
246
+ links: [{ nodeId: 'system:sales.crm:object/deal' }],
247
+ ownerIds: [],
248
+ updatedAt: '2026-05-14'
249
+ }
250
+ ]
251
+
252
+ expect(byOntology(graph, 'sales.crm:object/deal', nodes).map((node) => node.id)).toEqual([
253
+ 'knowledge.playbook-d'
254
+ ])
255
+ })
256
+
257
+ it('is exported from the public knowledge query API', () => {
258
+ expect(publicByOntology).toBe(byOntology)
259
+ expect(publicByOntology(GRAPH, 'sales.crm:object/deal', NODES).map((node) => node.id)).toEqual([
260
+ 'knowledge.playbook-d'
261
+ ])
178
262
  })
179
263
  })
180
264
 
181
265
  // ---------------------------------------------------------------------------
182
266
  // byKind
183
- // ---------------------------------------------------------------------------
184
-
267
+ // ---------------------------------------------------------------------------
268
+
185
269
  describe('byKind', () => {
186
- it('returns all playbook nodes', () => {
187
- const result = byKind(GRAPH, 'playbook', NODES)
188
- expect(result).toHaveLength(2)
189
- expect(result.every((n) => n.kind === 'playbook')).toBe(true)
190
- })
191
-
192
- it('returns strategy nodes', () => {
193
- const result = byKind(GRAPH, 'strategy', NODES)
194
- expect(result).toHaveLength(1)
195
- expect(result[0].id).toBe('knowledge.strategy-b')
196
- })
197
-
198
- it('returns reference nodes', () => {
199
- const result = byKind(GRAPH, 'reference', NODES)
200
- expect(result).toHaveLength(1)
201
- expect(result[0].id).toBe('knowledge.reference-c')
202
- })
203
-
204
- it('returns empty array when no nodes match the kind', () => {
205
- const result = byKind(GRAPH, 'playbook', [])
206
- expect(result).toHaveLength(0)
207
- })
270
+ it('returns all playbook nodes', () => {
271
+ const result = byKind(GRAPH, 'playbook', NODES)
272
+ expect(result).toHaveLength(2)
273
+ expect(result.every((n) => n.kind === 'playbook')).toBe(true)
274
+ })
275
+
276
+ it('returns strategy nodes', () => {
277
+ const result = byKind(GRAPH, 'strategy', NODES)
278
+ expect(result).toHaveLength(1)
279
+ expect(result[0].id).toBe('knowledge.strategy-b')
280
+ })
281
+
282
+ it('returns reference nodes', () => {
283
+ const result = byKind(GRAPH, 'reference', NODES)
284
+ expect(result).toHaveLength(1)
285
+ expect(result[0].id).toBe('knowledge.reference-c')
286
+ })
287
+
288
+ it('returns empty array when no nodes match the kind', () => {
289
+ const result = byKind(GRAPH, 'playbook', [])
290
+ expect(result).toHaveLength(0)
291
+ })
208
292
  })
209
293
 
210
294
  // ---------------------------------------------------------------------------
211
295
  // byOwner
212
296
  // ---------------------------------------------------------------------------
213
-
214
- describe('byOwner', () => {
215
- it('returns nodes where ownerIds includes the given owner', () => {
216
- const result = byOwner(GRAPH, 'role.ops-lead', NODES)
217
- const ids = result.map((n) => n.id).sort()
218
- expect(ids).toEqual(['knowledge.playbook-d', 'knowledge.strategy-b'].sort())
219
- })
220
-
221
- it('returns nodes for a second owner', () => {
222
- const result = byOwner(GRAPH, 'role.ceo', NODES)
223
- expect(result).toHaveLength(1)
224
- expect(result[0].id).toBe('knowledge.playbook-d')
225
- })
226
-
227
- it('returns empty array when ownerId is not present in any node', () => {
228
- const result = byOwner(GRAPH, 'role.unknown', NODES)
229
- expect(result).toHaveLength(0)
230
- })
231
- })
232
-
233
- // ---------------------------------------------------------------------------
234
- // governs
235
- // ---------------------------------------------------------------------------
236
-
237
- describe('governs', () => {
238
- it('returns target graph node IDs for outgoing governs edges (OM node id input)', () => {
239
- const result = governs(GRAPH, 'knowledge.playbook-a')
240
- expect(result.sort()).toEqual(['feature:sales.crm', 'feature:sales.lead-gen'].sort())
241
- })
242
-
243
- it('accepts graph node ID format input', () => {
244
- const result = governs(GRAPH, 'knowledge:knowledge.playbook-a')
245
- expect(result.sort()).toEqual(['feature:sales.crm', 'feature:sales.lead-gen'].sort())
246
- })
247
-
248
- it('returns single target for a node with one link', () => {
249
- const result = governs(GRAPH, 'knowledge.strategy-b')
250
- expect(result).toEqual(['feature:sales.lead-gen'])
251
- })
252
-
297
+
298
+ describe('byOwner', () => {
299
+ it('returns nodes where ownerIds includes the given owner', () => {
300
+ const result = byOwner(GRAPH, 'role.ops-lead', NODES)
301
+ const ids = result.map((n) => n.id).sort()
302
+ expect(ids).toEqual(['knowledge.playbook-d', 'knowledge.strategy-b'].sort())
303
+ })
304
+
305
+ it('returns nodes for a second owner', () => {
306
+ const result = byOwner(GRAPH, 'role.ceo', NODES)
307
+ expect(result).toHaveLength(1)
308
+ expect(result[0].id).toBe('knowledge.playbook-d')
309
+ })
310
+
311
+ it('returns empty array when ownerId is not present in any node', () => {
312
+ const result = byOwner(GRAPH, 'role.unknown', NODES)
313
+ expect(result).toHaveLength(0)
314
+ })
315
+ })
316
+
317
+ // ---------------------------------------------------------------------------
318
+ // governs
319
+ // ---------------------------------------------------------------------------
320
+
321
+ describe('governs', () => {
322
+ it('returns target graph node IDs for outgoing governs edges (OM node id input)', () => {
323
+ const result = governs(GRAPH, 'knowledge.playbook-a')
324
+ expect(result.sort()).toEqual(['system:sales.crm', 'system:sales.lead-gen'].sort())
325
+ })
326
+
327
+ it('accepts graph node ID format input', () => {
328
+ const result = governs(GRAPH, 'knowledge:knowledge.playbook-a')
329
+ expect(result.sort()).toEqual(['system:sales.crm', 'system:sales.lead-gen'].sort())
330
+ })
331
+
332
+ it('returns single target for a node with one link', () => {
333
+ const result = governs(GRAPH, 'knowledge.strategy-b')
334
+ expect(result).toEqual(['system:sales.lead-gen'])
335
+ })
336
+
253
337
  it('returns empty array for a node with no governs edges', () => {
254
338
  const result = governs(GRAPH, 'knowledge.reference-c')
255
339
  expect(result).toHaveLength(0)
256
340
  })
257
-
258
- it('returns empty array for an unknown nodeId', () => {
259
- const result = governs(GRAPH, 'knowledge.does-not-exist')
260
- expect(result).toHaveLength(0)
261
- })
262
- })
263
-
264
- // ---------------------------------------------------------------------------
265
- // governedBy
266
- // ---------------------------------------------------------------------------
267
-
268
- describe('governedBy', () => {
269
- it('returns knowledge graph node IDs for incoming governs edges (prefixed feature id)', () => {
270
- const result = governedBy(GRAPH, 'feature:sales.lead-gen')
271
- const sorted = result.sort()
272
- expect(sorted).toEqual(['knowledge:knowledge.playbook-a', 'knowledge:knowledge.strategy-b'].sort())
273
- })
274
-
275
- it('accepts bare feature id (auto-prefixes with feature:)', () => {
276
- const result = governedBy(GRAPH, 'sales.crm')
277
- expect(result).toEqual(['knowledge:knowledge.playbook-a'])
278
- })
279
-
280
- it('returns empty array when no knowledge node governs the target', () => {
281
- const result = governedBy(GRAPH, 'feature:dashboard')
282
- expect(result).toHaveLength(0)
283
- })
284
-
341
+
342
+ it('returns empty array for an unknown nodeId', () => {
343
+ const result = governs(GRAPH, 'knowledge.does-not-exist')
344
+ expect(result).toHaveLength(0)
345
+ })
346
+ })
347
+
348
+ // ---------------------------------------------------------------------------
349
+ // governedBy
350
+ // ---------------------------------------------------------------------------
351
+
352
+ describe('governedBy', () => {
353
+ it('returns knowledge graph node IDs for incoming governs edges (prefixed system id)', () => {
354
+ const result = governedBy(GRAPH, 'system:sales.lead-gen')
355
+ const sorted = result.sort()
356
+ expect(sorted).toEqual(['knowledge:knowledge.playbook-a', 'knowledge:knowledge.strategy-b'].sort())
357
+ })
358
+
359
+ it('accepts bare system id (auto-prefixes with system:)', () => {
360
+ const result = governedBy(GRAPH, 'sales.crm')
361
+ expect(result).toEqual(['knowledge:knowledge.playbook-a'])
362
+ })
363
+
364
+ it('returns empty array when no knowledge node governs the target', () => {
365
+ const result = governedBy(GRAPH, 'system:dashboard')
366
+ expect(result).toHaveLength(0)
367
+ })
368
+
285
369
  it('returns empty array for unknown target node id', () => {
286
- const result = governedBy(GRAPH, 'feature:does-not-exist')
370
+ const result = governedBy(GRAPH, 'system:does-not-exist')
287
371
  expect(result).toHaveLength(0)
288
372
  })
289
373
  })
290
-
291
- // ---------------------------------------------------------------------------
292
- // parsePath happy paths (all five mount axes)
293
- // ---------------------------------------------------------------------------
294
-
295
- describe('parsePath happy paths', () => {
296
- it('/by-kind/playbook mount:by-kind args:[playbook]', () => {
297
- expect(parsePath('/by-kind/playbook')).toEqual({ mount: 'by-kind', args: ['playbook'] })
298
- })
299
-
300
- it('/by-kind/strategy mount:by-kind args:[strategy]', () => {
301
- expect(parsePath('/by-kind/strategy')).toEqual({ mount: 'by-kind', args: ['strategy'] })
302
- })
303
-
304
- it('/by-feature/sales.crm mount:by-feature args:[sales.crm]', () => {
305
- expect(parsePath('/by-feature/sales.crm')).toEqual({ mount: 'by-feature', args: ['sales.crm'] })
306
- })
307
-
308
- it('/by-feature/sales/crm (slash-delimited) mount:by-feature args:[sales/crm]', () => {
309
- // featureId with slashes is joined and passed as-is for the caller to interpret
310
- expect(parsePath('/by-feature/sales/crm')).toEqual({ mount: 'by-feature', args: ['sales/crm'] })
311
- })
312
-
313
- it('/by-owner/role.ops-lead mount:by-owner args:[role.ops-lead]', () => {
374
+
375
+ // ---------------------------------------------------------------------------
376
+ // parsePath — happy paths (all five mount axes)
377
+ // ---------------------------------------------------------------------------
378
+
379
+ describe('parsePath — happy paths', () => {
380
+ it('/by-kind/playbook → mount:by-kind args:[playbook]', () => {
381
+ expect(parsePath('/by-kind/playbook')).toEqual({ mount: 'by-kind', args: ['playbook'] })
382
+ })
383
+
384
+ it('/by-kind/strategy → mount:by-kind args:[strategy]', () => {
385
+ expect(parsePath('/by-kind/strategy')).toEqual({ mount: 'by-kind', args: ['strategy'] })
386
+ })
387
+
388
+ it('/by-system/sales.crm → mount:by-system args:[sales.crm]', () => {
389
+ expect(parsePath('/by-system/sales.crm')).toEqual({ mount: 'by-system', args: ['sales.crm'] })
390
+ })
391
+
392
+ it('/by-system/sales/crm (slash-delimited) → mount:by-system args:[sales/crm]', () => {
393
+ // systemId with slashes is joined and passed as-is for the caller to interpret
394
+ expect(parsePath('/by-system/sales/crm')).toEqual({ mount: 'by-system', args: ['sales/crm'] })
395
+ })
396
+
397
+ it('/by-owner/role.ops-lead → mount:by-owner args:[role.ops-lead]', () => {
314
398
  expect(parsePath('/by-owner/role.ops-lead')).toEqual({ mount: 'by-owner', args: ['role.ops-lead'] })
315
399
  })
316
400
 
317
- it('/graph/knowledge.outreach-playbook/governs mount:graph args:[knowledge.outreach-playbook,governs]', () => {
318
- expect(parsePath('/graph/knowledge.outreach-playbook/governs')).toEqual({
319
- mount: 'graph',
320
- args: ['knowledge.outreach-playbook', 'governs']
321
- })
322
- })
323
-
324
- it('/graph/knowledge.outreach-playbook/governed-by → mount:graph args:[knowledge.outreach-playbook,governed-by]', () => {
325
- expect(parsePath('/graph/knowledge.outreach-playbook/governed-by')).toEqual({
326
- mount: 'graph',
327
- args: ['knowledge.outreach-playbook', 'governed-by']
328
- })
329
- })
330
-
331
- it('/<nodeId> single segment → mount:node args:[nodeId]', () => {
332
- expect(parsePath('/knowledge.outreach-playbook')).toEqual({
333
- mount: 'node',
334
- args: ['knowledge.outreach-playbook']
401
+ it('/by-ontology/sales.crm:object/deal → mount:by-ontology args:[sales.crm:object/deal]', () => {
402
+ expect(parsePath('/by-ontology/sales.crm:object/deal')).toEqual({
403
+ mount: 'by-ontology',
404
+ args: ['sales.crm:object/deal']
335
405
  })
336
406
  })
337
407
 
338
- it('trailing slash is stripped before parsing', () => {
339
- expect(parsePath('/by-kind/playbook/')).toEqual({ mount: 'by-kind', args: ['playbook'] })
340
- })
341
- })
342
-
343
- // ---------------------------------------------------------------------------
344
- // parsePath — invalid inputs (5+)
345
- // ---------------------------------------------------------------------------
346
-
347
- describe('parsePath — invalid inputs', () => {
348
- it('throws on empty string', () => {
349
- expect(() => parsePath('')).toThrow('parsePath: path must be a non-empty string')
350
- })
351
-
352
- it('throws when path does not start with /', () => {
353
- expect(() => parsePath('by-kind/playbook')).toThrow('parsePath: path must start with "/"')
354
- })
355
-
356
- it('throws on bare root path "/"', () => {
357
- expect(() => parsePath('/')).toThrow('parsePath: path resolves to root with no mount')
358
- })
359
-
360
- it('throws on /by-feature with no featureId argument', () => {
361
- expect(() => parsePath('/by-feature')).toThrow('/by-feature requires a featureId argument')
362
- })
363
-
364
- it('throws on /by-kind with no kind argument', () => {
365
- expect(() => parsePath('/by-kind')).toThrow('/by-kind requires a kind argument')
366
- })
367
-
368
- it('throws on /by-owner with no ownerId argument', () => {
369
- expect(() => parsePath('/by-owner')).toThrow('/by-owner requires an ownerId argument')
370
- })
371
-
372
- it('throws on /graph with only nodeId (missing verb)', () => {
373
- expect(() => parsePath('/graph/knowledge.outreach-playbook')).toThrow('/graph requires <nodeId>/<verb>')
374
- })
375
-
376
- it('throws on /graph/<nodeId>/<unknown-verb>', () => {
377
- expect(() => parsePath('/graph/knowledge.outreach-playbook/list')).toThrow(
378
- 'verb must be "governs" or "governed-by"'
379
- )
380
- })
381
-
382
- it('throws on multi-segment path with unrecognized first segment', () => {
383
- expect(() => parsePath('/unknown-mount/some-arg')).toThrow('unrecognized path pattern')
384
- })
385
- })
386
-
387
- // ---------------------------------------------------------------------------
388
- // parsePath — edge cases
389
- // ---------------------------------------------------------------------------
390
-
391
- describe('parsePath edge cases', () => {
392
- // Whitespace handling — the parser does NOT trim the incoming string.
393
- // A path with leading whitespace does not start with '/' so it throws.
394
- it('throws on path with leading whitespace', () => {
395
- expect(() => parsePath(' /by-kind/playbook')).toThrow('parsePath: path must start with "/"')
396
- })
397
-
398
- // Trailing whitespace becomes part of the last segment (not stripped).
399
- // The segment is non-empty so parsing proceeds and the whitespace is
400
- // included verbatim in the returned arg.
401
- it('preserves trailing whitespace inside the last segment', () => {
402
- const result = parsePath('/by-kind/playbook ')
403
- expect(result.mount).toBe('by-kind')
404
- expect(result.args[0]).toBe('playbook ')
405
- })
406
-
407
- // Multiple trailing slashes are all stripped (regex /\/+$/).
408
- it('strips multiple trailing slashes', () => {
409
- expect(parsePath('/by-kind/playbook///')).toEqual({ mount: 'by-kind', args: ['playbook'] })
410
- })
411
-
412
- // Lone-slash variants a path of only slashes normalises to an empty
413
- // segments list and must throw the root-with-no-mount error.
414
- it('throws on path consisting only of slashes', () => {
415
- expect(() => parsePath('///')).toThrow('parsePath: path resolves to root with no mount')
416
- })
417
-
418
- // Case sensitivity — parsePath does not normalise case.
419
- // 'Playbook' (capitalised) is passed through as-is to the caller.
420
- it('preserves node-id case (no case normalisation)', () => {
421
- // /by-kind takes rest[0] verbatim
422
- const result = parsePath('/by-kind/Playbook')
423
- expect(result.args[0]).toBe('Playbook')
424
- })
425
-
426
- // Feature ID: dot notation passes through unchanged.
427
- it('/by-feature/sales.crm preserves dot notation', () => {
428
- expect(parsePath('/by-feature/sales.crm')).toEqual({ mount: 'by-feature', args: ['sales.crm'] })
429
- })
430
-
431
- // Feature ID: slash notation joins rest segments with '/'.
432
- // The parser does NOT convert slashes to dots — the caller must normalise.
433
- it('/by-feature/sales/crm joins segments with slash (no dot conversion)', () => {
434
- const result = parsePath('/by-feature/sales/crm')
435
- expect(result.mount).toBe('by-feature')
436
- // args[0] is 'sales/crm', NOT 'sales.crm'
437
- expect(result.args[0]).toBe('sales/crm')
438
- })
439
-
440
- // /by-kind silently ignores extra path segments beyond the kind argument.
441
- it('/by-kind/playbook/extra silently uses only first kind segment', () => {
442
- // First segment after 'by-kind' is taken; extra is ignored.
443
- const result = parsePath('/by-kind/playbook/extra')
444
- expect(result.mount).toBe('by-kind')
445
- expect(result.args[0]).toBe('playbook')
446
- expect(result.args).toHaveLength(1)
447
- })
448
-
449
- // /by-owner joins rest with '/' (same behaviour as /by-feature).
450
- it('/by-owner/role.ops-lead/sub joins segments with slash', () => {
451
- const result = parsePath('/by-owner/role.ops-lead/sub')
452
- expect(result.mount).toBe('by-owner')
453
- expect(result.args[0]).toBe('role.ops-lead/sub')
454
- })
455
-
456
- // Graph node ID may contain a colon prefix (e.g. knowledge:knowledge.foo).
457
- // The parser accepts it — the rest before the verb is joined with '/'.
458
- it('/graph/<prefixed-nodeId>/governs round-trips the prefixed id', () => {
459
- const result = parsePath('/graph/knowledge:knowledge.test-node/governs')
460
- expect(result.mount).toBe('graph')
461
- expect(result.args[0]).toBe('knowledge:knowledge.test-node')
462
- expect(result.args[1]).toBe('governs')
463
- })
464
-
465
- // /graph with no arguments at all (just '/graph').
466
- it('throws on /graph with no nodeId or verb', () => {
467
- expect(() => parsePath('/graph')).toThrow('/graph requires <nodeId>/<verb>')
468
- })
469
-
470
- // /node mount single-segment path works for any non-reserved first segment.
471
- it('single-segment non-reserved path is treated as node mount', () => {
472
- expect(parsePath('/knowledge.my-doc')).toEqual({ mount: 'node', args: ['knowledge.my-doc'] })
473
- })
474
- })
475
-
476
- // ---------------------------------------------------------------------------
477
- // formatText
478
- // ---------------------------------------------------------------------------
479
-
480
- describe('formatText', () => {
481
- it('returns "(no results)" for empty array', () => {
482
- expect(formatText([])).toBe('(no results)')
483
- })
484
-
485
- it('includes header row with KIND and ID columns', () => {
486
- const output = formatText([NODES[0]])
487
- expect(output).toContain('KIND')
488
- expect(output).toContain('ID')
489
- expect(output).toContain('TITLE')
490
- })
491
-
492
- it('includes node id and title in output', () => {
493
- const output = formatText([NODES[0]])
494
- expect(output).toContain('knowledge.playbook-a')
495
- expect(output).toContain('Playbook A')
496
- })
497
-
498
- it('truncates long summaries', () => {
499
- const longSummary = 'x'.repeat(200)
500
- const node: OrgKnowledgeNode = { ...NODES[0], summary: longSummary }
501
- const output = formatText([node])
502
- expect(output).toContain('...')
503
- })
504
- })
505
-
506
- // ---------------------------------------------------------------------------
507
- // formatJson envelope shape
508
- // ---------------------------------------------------------------------------
509
-
510
- describe('formatJson', () => {
511
- it('returns a JSON string with top-level keys: path, mount, args, results', () => {
512
- const raw = formatJson({
513
- path: '/by-kind/playbook',
514
- parsed: { mount: 'by-kind', args: ['playbook'] },
515
- results: [NODES[0]]
516
- })
517
- const parsed = JSON.parse(raw) as Record<string, unknown>
518
- expect(Object.keys(parsed).sort()).toEqual(['args', 'mount', 'path', 'results'].sort())
519
- })
520
-
521
- it('preserves path in envelope', () => {
522
- const raw = formatJson({
523
- path: '/by-kind/playbook',
524
- parsed: { mount: 'by-kind', args: ['playbook'] },
525
- results: []
526
- })
527
- expect(JSON.parse(raw)).toMatchObject({ path: '/by-kind/playbook' })
528
- })
529
-
530
- it('preserves mount in envelope', () => {
531
- const raw = formatJson({
532
- path: '/by-kind/strategy',
533
- parsed: { mount: 'by-kind', args: ['strategy'] },
534
- results: []
535
- })
536
- expect(JSON.parse(raw)).toMatchObject({ mount: 'by-kind' })
537
- })
538
-
539
- it('preserves args array in envelope', () => {
540
- const raw = formatJson({
541
- path: '/by-feature/sales.crm',
542
- parsed: { mount: 'by-feature', args: ['sales.crm'] },
543
- results: []
544
- })
545
- expect(JSON.parse(raw)).toMatchObject({ args: ['sales.crm'] })
546
- })
547
-
548
- it('includes results in envelope for string[] (governs/governedBy)', () => {
549
- const raw = formatJson({
550
- path: '/graph/knowledge.playbook-a/governs',
551
- parsed: { mount: 'graph', args: ['knowledge.playbook-a', 'governs'] },
552
- results: ['feature:sales.crm', 'feature:sales.lead-gen']
553
- })
554
- const parsed = JSON.parse(raw) as { results: string[] }
555
- expect(parsed.results).toEqual(['feature:sales.crm', 'feature:sales.lead-gen'])
556
- })
557
-
558
- it('envelope is NOT flat { results } — must have path/mount/args siblings', () => {
559
- const raw = formatJson({
560
- path: '/by-kind/playbook',
561
- parsed: { mount: 'by-kind', args: ['playbook'] },
562
- results: [NODES[0]]
563
- })
564
- const parsed = JSON.parse(raw) as Record<string, unknown>
565
- // Must NOT be flat (only results key)
566
- expect(parsed).toHaveProperty('path')
567
- expect(parsed).toHaveProperty('mount')
568
- expect(parsed).toHaveProperty('args')
569
- expect(parsed).toHaveProperty('results')
570
- })
571
- })
572
-
573
- // ---------------------------------------------------------------------------
574
- // formatIdsOnly
575
- // ---------------------------------------------------------------------------
576
-
577
- describe('formatIdsOnly', () => {
578
- it('returns empty string for empty array', () => {
579
- expect(formatIdsOnly([])).toBe('')
580
- })
581
-
582
- it('returns newline-separated ids for OrgKnowledgeNode array', () => {
583
- const output = formatIdsOnly([NODES[0], NODES[1]])
584
- const lines = output.split('\n')
585
- expect(lines).toContain('knowledge.playbook-a')
586
- expect(lines).toContain('knowledge.strategy-b')
587
- })
588
-
589
- it('returns newline-separated strings for string[] (governs results)', () => {
590
- const output = formatIdsOnly(['feature:sales.crm', 'feature:sales.lead-gen'])
591
- expect(output).toBe('feature:sales.crm\nfeature:sales.lead-gen')
592
- })
593
- })
408
+ it('/graph/knowledge.outreach-playbook/governs → mount:graph args:[knowledge.outreach-playbook,governs]', () => {
409
+ expect(parsePath('/graph/knowledge.outreach-playbook/governs')).toEqual({
410
+ mount: 'graph',
411
+ args: ['knowledge.outreach-playbook', 'governs']
412
+ })
413
+ })
414
+
415
+ it('/graph/knowledge.outreach-playbook/governed-by → mount:graph args:[knowledge.outreach-playbook,governed-by]', () => {
416
+ expect(parsePath('/graph/knowledge.outreach-playbook/governed-by')).toEqual({
417
+ mount: 'graph',
418
+ args: ['knowledge.outreach-playbook', 'governed-by']
419
+ })
420
+ })
421
+
422
+ it('/<nodeId> single segment → mount:node args:[nodeId]', () => {
423
+ expect(parsePath('/knowledge.outreach-playbook')).toEqual({
424
+ mount: 'node',
425
+ args: ['knowledge.outreach-playbook']
426
+ })
427
+ })
428
+
429
+ it('trailing slash is stripped before parsing', () => {
430
+ expect(parsePath('/by-kind/playbook/')).toEqual({ mount: 'by-kind', args: ['playbook'] })
431
+ })
432
+ })
433
+
434
+ // ---------------------------------------------------------------------------
435
+ // parsePath — invalid inputs (5+)
436
+ // ---------------------------------------------------------------------------
437
+
438
+ describe('parsePath — invalid inputs', () => {
439
+ it('throws on empty string', () => {
440
+ expect(() => parsePath('')).toThrow('parsePath: path must be a non-empty string')
441
+ })
442
+
443
+ it('throws when path does not start with /', () => {
444
+ expect(() => parsePath('by-kind/playbook')).toThrow('parsePath: path must start with "/"')
445
+ })
446
+
447
+ it('throws on bare root path "/"', () => {
448
+ expect(() => parsePath('/')).toThrow('parsePath: path resolves to root with no mount')
449
+ })
450
+
451
+ it('throws on /by-system with no systemId argument', () => {
452
+ expect(() => parsePath('/by-system')).toThrow('/by-system requires a systemId argument')
453
+ })
454
+
455
+ it('throws on /by-kind with no kind argument', () => {
456
+ expect(() => parsePath('/by-kind')).toThrow('/by-kind requires a kind argument')
457
+ })
458
+
459
+ it('throws on /by-owner with no ownerId argument', () => {
460
+ expect(() => parsePath('/by-owner')).toThrow('/by-owner requires an ownerId argument')
461
+ })
462
+
463
+ it('throws on /graph with only nodeId (missing verb)', () => {
464
+ expect(() => parsePath('/graph/knowledge.outreach-playbook')).toThrow('/graph requires <nodeId>/<verb>')
465
+ })
466
+
467
+ it('throws on /graph/<nodeId>/<unknown-verb>', () => {
468
+ expect(() => parsePath('/graph/knowledge.outreach-playbook/list')).toThrow(
469
+ 'verb must be "governs" or "governed-by"'
470
+ )
471
+ })
472
+
473
+ it('throws on multi-segment path with unrecognized first segment', () => {
474
+ expect(() => parsePath('/unknown-mount/some-arg')).toThrow('unrecognized path pattern')
475
+ })
476
+ })
477
+
478
+ // ---------------------------------------------------------------------------
479
+ // parsePath — edge cases
480
+ // ---------------------------------------------------------------------------
481
+
482
+ describe('parsePath edge cases', () => {
483
+ // Whitespace handling — the parser does NOT trim the incoming string.
484
+ // A path with leading whitespace does not start with '/' so it throws.
485
+ it('throws on path with leading whitespace', () => {
486
+ expect(() => parsePath(' /by-kind/playbook')).toThrow('parsePath: path must start with "/"')
487
+ })
488
+
489
+ // Trailing whitespace becomes part of the last segment (not stripped).
490
+ // The segment is non-empty so parsing proceeds and the whitespace is
491
+ // included verbatim in the returned arg.
492
+ it('preserves trailing whitespace inside the last segment', () => {
493
+ const result = parsePath('/by-kind/playbook ')
494
+ expect(result.mount).toBe('by-kind')
495
+ expect(result.args[0]).toBe('playbook ')
496
+ })
497
+
498
+ // Multiple trailing slashes are all stripped (regex /\/+$/).
499
+ it('strips multiple trailing slashes', () => {
500
+ expect(parsePath('/by-kind/playbook///')).toEqual({ mount: 'by-kind', args: ['playbook'] })
501
+ })
502
+
503
+ // Lone-slash variants — a path of only slashes normalises to an empty
504
+ // segments list and must throw the root-with-no-mount error.
505
+ it('throws on path consisting only of slashes', () => {
506
+ expect(() => parsePath('///')).toThrow('parsePath: path resolves to root with no mount')
507
+ })
508
+
509
+ // Case sensitivity — parsePath does not normalise case.
510
+ // 'Playbook' (capitalised) is passed through as-is to the caller.
511
+ it('preserves node-id case (no case normalisation)', () => {
512
+ // /by-kind takes rest[0] verbatim
513
+ const result = parsePath('/by-kind/Playbook')
514
+ expect(result.args[0]).toBe('Playbook')
515
+ })
516
+
517
+ // system id: dot notation passes through unchanged.
518
+ it('/by-system/sales.crm preserves dot notation', () => {
519
+ expect(parsePath('/by-system/sales.crm')).toEqual({ mount: 'by-system', args: ['sales.crm'] })
520
+ })
521
+
522
+ // system id: slash notation joins rest segments with '/'.
523
+ // The parser does NOT convert slashes to dots — the caller must normalise.
524
+ it('/by-system/sales/crm joins segments with slash (no dot conversion)', () => {
525
+ const result = parsePath('/by-system/sales/crm')
526
+ expect(result.mount).toBe('by-system')
527
+ // args[0] is 'sales/crm', NOT 'sales.crm'
528
+ expect(result.args[0]).toBe('sales/crm')
529
+ })
530
+
531
+ // /by-kind silently ignores extra path segments beyond the kind argument.
532
+ it('/by-kind/playbook/extra silently uses only first kind segment', () => {
533
+ // First segment after 'by-kind' is taken; extra is ignored.
534
+ const result = parsePath('/by-kind/playbook/extra')
535
+ expect(result.mount).toBe('by-kind')
536
+ expect(result.args[0]).toBe('playbook')
537
+ expect(result.args).toHaveLength(1)
538
+ })
539
+
540
+ // /by-owner joins rest with '/' (same behaviour as /by-system).
541
+ it('/by-owner/role.ops-lead/sub joins segments with slash', () => {
542
+ const result = parsePath('/by-owner/role.ops-lead/sub')
543
+ expect(result.mount).toBe('by-owner')
544
+ expect(result.args[0]).toBe('role.ops-lead/sub')
545
+ })
546
+
547
+ // Graph node ID may contain a colon prefix (e.g. knowledge:knowledge.foo).
548
+ // The parser accepts it — the rest before the verb is joined with '/'.
549
+ it('/graph/<prefixed-nodeId>/governs round-trips the prefixed id', () => {
550
+ const result = parsePath('/graph/knowledge:knowledge.test-node/governs')
551
+ expect(result.mount).toBe('graph')
552
+ expect(result.args[0]).toBe('knowledge:knowledge.test-node')
553
+ expect(result.args[1]).toBe('governs')
554
+ })
555
+
556
+ // /graph with no arguments at all (just '/graph').
557
+ it('throws on /graph with no nodeId or verb', () => {
558
+ expect(() => parsePath('/graph')).toThrow('/graph requires <nodeId>/<verb>')
559
+ })
560
+
561
+ // /node mount — single-segment path works for any non-reserved first segment.
562
+ it('single-segment non-reserved path is treated as node mount', () => {
563
+ expect(parsePath('/knowledge.my-doc')).toEqual({ mount: 'node', args: ['knowledge.my-doc'] })
564
+ })
565
+ })
566
+
567
+ // ---------------------------------------------------------------------------
568
+ // formatText
569
+ // ---------------------------------------------------------------------------
570
+
571
+ describe('formatText', () => {
572
+ it('returns "(no results)" for empty array', () => {
573
+ expect(formatText([])).toBe('(no results)')
574
+ })
575
+
576
+ it('includes header row with KIND and ID columns', () => {
577
+ const output = formatText([NODES[0]])
578
+ expect(output).toContain('KIND')
579
+ expect(output).toContain('ID')
580
+ expect(output).toContain('TITLE')
581
+ })
582
+
583
+ it('includes node id and title in output', () => {
584
+ const output = formatText([NODES[0]])
585
+ expect(output).toContain('knowledge.playbook-a')
586
+ expect(output).toContain('Playbook A')
587
+ })
588
+
589
+ it('truncates long summaries', () => {
590
+ const longSummary = 'x'.repeat(200)
591
+ const node: OrgKnowledgeNode = { ...NODES[0], summary: longSummary }
592
+ const output = formatText([node])
593
+ expect(output).toContain('...')
594
+ })
595
+ })
596
+
597
+ // ---------------------------------------------------------------------------
598
+ // formatJson — envelope shape
599
+ // ---------------------------------------------------------------------------
600
+
601
+ describe('formatJson', () => {
602
+ it('returns a JSON string with top-level keys: path, mount, args, results', () => {
603
+ const raw = formatJson({
604
+ path: '/by-kind/playbook',
605
+ parsed: { mount: 'by-kind', args: ['playbook'] },
606
+ results: [NODES[0]]
607
+ })
608
+ const parsed = JSON.parse(raw) as Record<string, unknown>
609
+ expect(Object.keys(parsed).sort()).toEqual(['args', 'mount', 'path', 'results'].sort())
610
+ })
611
+
612
+ it('preserves path in envelope', () => {
613
+ const raw = formatJson({
614
+ path: '/by-kind/playbook',
615
+ parsed: { mount: 'by-kind', args: ['playbook'] },
616
+ results: []
617
+ })
618
+ expect(JSON.parse(raw)).toMatchObject({ path: '/by-kind/playbook' })
619
+ })
620
+
621
+ it('preserves mount in envelope', () => {
622
+ const raw = formatJson({
623
+ path: '/by-kind/strategy',
624
+ parsed: { mount: 'by-kind', args: ['strategy'] },
625
+ results: []
626
+ })
627
+ expect(JSON.parse(raw)).toMatchObject({ mount: 'by-kind' })
628
+ })
629
+
630
+ it('preserves args array in envelope', () => {
631
+ const raw = formatJson({
632
+ path: '/by-system/sales.crm',
633
+ parsed: { mount: 'by-system', args: ['sales.crm'] },
634
+ results: []
635
+ })
636
+ expect(JSON.parse(raw)).toMatchObject({ args: ['sales.crm'] })
637
+ })
638
+
639
+ it('includes results in envelope for string[] (governs/governedBy)', () => {
640
+ const raw = formatJson({
641
+ path: '/graph/knowledge.playbook-a/governs',
642
+ parsed: { mount: 'graph', args: ['knowledge.playbook-a', 'governs'] },
643
+ results: ['system:sales.crm', 'system:sales.lead-gen']
644
+ })
645
+ const parsed = JSON.parse(raw) as { results: string[] }
646
+ expect(parsed.results).toEqual(['system:sales.crm', 'system:sales.lead-gen'])
647
+ })
648
+
649
+ it('envelope is NOT flat { results } — must have path/mount/args siblings', () => {
650
+ const raw = formatJson({
651
+ path: '/by-kind/playbook',
652
+ parsed: { mount: 'by-kind', args: ['playbook'] },
653
+ results: [NODES[0]]
654
+ })
655
+ const parsed = JSON.parse(raw) as Record<string, unknown>
656
+ // Must NOT be flat (only results key)
657
+ expect(parsed).toHaveProperty('path')
658
+ expect(parsed).toHaveProperty('mount')
659
+ expect(parsed).toHaveProperty('args')
660
+ expect(parsed).toHaveProperty('results')
661
+ })
662
+ })
663
+
664
+ // ---------------------------------------------------------------------------
665
+ // formatIdsOnly
666
+ // ---------------------------------------------------------------------------
667
+
668
+ describe('formatIdsOnly', () => {
669
+ it('returns empty string for empty array', () => {
670
+ expect(formatIdsOnly([])).toBe('')
671
+ })
672
+
673
+ it('returns newline-separated ids for OrgKnowledgeNode array', () => {
674
+ const output = formatIdsOnly([NODES[0], NODES[1]])
675
+ const lines = output.split('\n')
676
+ expect(lines).toContain('knowledge.playbook-a')
677
+ expect(lines).toContain('knowledge.strategy-b')
678
+ })
679
+
680
+ it('returns newline-separated strings for string[] (governs results)', () => {
681
+ const output = formatIdsOnly(['system:sales.crm', 'system:sales.lead-gen'])
682
+ expect(output).toBe('system:sales.crm\nsystem:sales.lead-gen')
683
+ })
684
+ })
685
+