spine-framework 0.3.145 → 0.4.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 (451) hide show
  1. package/.env.example +76 -0
  2. package/.framework/.spine-manifest.json +19 -0
  3. package/.framework/cli/commands/agents.ts +61 -33
  4. package/.framework/cli/commands/auth.ts +60 -28
  5. package/.framework/cli/commands/create-app.ts +212 -80
  6. package/.framework/cli/commands/dev.ts +184 -68
  7. package/.framework/cli/commands/doctor.ts +324 -152
  8. package/.framework/cli/commands/generate.ts +119 -68
  9. package/.framework/cli/commands/init.ts +141 -242
  10. package/.framework/cli/commands/install-app.ts +1336 -314
  11. package/.framework/cli/commands/items.ts +31 -29
  12. package/.framework/cli/commands/migrate.ts +299 -156
  13. package/.framework/cli/commands/migrations.ts +62 -30
  14. package/.framework/cli/commands/pipelines.ts +31 -29
  15. package/.framework/cli/commands/status.ts +105 -45
  16. package/.framework/cli/commands/system.ts +47 -42
  17. package/.framework/cli/commands/test.ts +161 -102
  18. package/.framework/cli/commands/upgrade.ts +260 -0
  19. package/.framework/cli/commands/validate-app.ts +517 -161
  20. package/.framework/cli/context.ts +117 -85
  21. package/.framework/cli/env-loader.ts +74 -43
  22. package/.framework/cli/index.ts +70 -46
  23. package/.framework/cli/lib/project-files.ts +404 -0
  24. package/.framework/docs/guides/testing-guide.md +1 -1
  25. package/.framework/docs/runtime-types.md +72 -72
  26. package/.framework/functions/_shared/access.ts +84 -0
  27. package/.framework/functions/_shared/agent-runner.ts +5051 -1026
  28. package/.framework/functions/_shared/app-manifest.ts +214 -94
  29. package/.framework/functions/_shared/ast.ts +214 -0
  30. package/.framework/functions/_shared/audit.ts +91 -55
  31. package/.framework/functions/_shared/cil.ts +368 -127
  32. package/.framework/functions/_shared/db.ts +337 -68
  33. package/.framework/functions/_shared/funnel.ts +228 -0
  34. package/.framework/functions/_shared/geo.ts +105 -0
  35. package/.framework/functions/_shared/hash-api-key.ts +94 -17
  36. package/.framework/functions/_shared/index.ts +22 -224
  37. package/.framework/functions/_shared/kb.ts +832 -58
  38. package/.framework/functions/_shared/llm.ts +118 -18
  39. package/.framework/functions/_shared/logging.ts +317 -19
  40. package/.framework/functions/_shared/middleware.ts +701 -131
  41. package/.framework/functions/_shared/notify.ts +70 -0
  42. package/.framework/functions/_shared/outcomes.ts +34 -19
  43. package/.framework/functions/_shared/permissions.ts +501 -315
  44. package/.framework/functions/_shared/pipeline-runner.ts +704 -155
  45. package/.framework/functions/_shared/principal.ts +436 -263
  46. package/.framework/functions/_shared/rate-limit.ts +233 -0
  47. package/.framework/functions/_shared/resolve-credentials.ts +86 -19
  48. package/.framework/functions/_shared/resolve-ids.ts +203 -139
  49. package/.framework/functions/_shared/retry-deliveries.ts +51 -16
  50. package/.framework/functions/_shared/schema-utils.ts +602 -521
  51. package/.framework/functions/_shared/security.ts +345 -0
  52. package/.framework/functions/_shared/testing.ts +197 -172
  53. package/.framework/functions/_shared/tracing.ts +351 -21
  54. package/.framework/functions/_shared/trigger-engine.ts +425 -136
  55. package/.framework/functions/_shared/webhook-registration.ts +71 -70
  56. package/.framework/functions/_shared/webhook-registry.ts +126 -83
  57. package/.framework/functions/account-nodes.ts +30 -30
  58. package/.framework/functions/adapters/generic-webhook-inbound.ts +49 -16
  59. package/.framework/functions/adapters/generic-webhook-outbound.ts +17 -17
  60. package/.framework/functions/adapters/openai-outbound.ts +15 -16
  61. package/.framework/functions/admin-data.ts +596 -173
  62. package/.framework/functions/admin-funnel.ts +64 -60
  63. package/.framework/functions/admin-install-funnel.ts +84 -66
  64. package/.framework/functions/admin-signals.ts +69 -51
  65. package/.framework/functions/ai-agents.ts +431 -106
  66. package/.framework/functions/ai-interactions.ts +186 -112
  67. package/.framework/functions/api-keys.ts +107 -107
  68. package/.framework/functions/apps.ts +154 -136
  69. package/.framework/functions/auth.ts +83 -65
  70. package/.framework/functions/cil-agent-ingest.ts +189 -232
  71. package/.framework/functions/cil-agent.ts +433 -177
  72. package/.framework/functions/cil-callmap.ts +642 -430
  73. package/.framework/functions/cil-config.ts +139 -135
  74. package/.framework/functions/cil-context.ts +214 -127
  75. package/.framework/functions/cil-doc.ts +587 -458
  76. package/.framework/functions/cil-embeddings.ts +453 -364
  77. package/.framework/functions/cil-graph.ts +427 -142
  78. package/.framework/functions/cil-ingest.ts +1418 -1154
  79. package/.framework/functions/cil-pipeline.ts +276 -21
  80. package/.framework/functions/cil-project.ts +659 -132
  81. package/.framework/functions/cil-validate.ts +198 -164
  82. package/.framework/functions/debug-auth.ts +57 -55
  83. package/.framework/functions/deliveries.ts +80 -21
  84. package/.framework/functions/embeddings.ts +1023 -318
  85. package/.framework/functions/eval-harness.ts +146 -108
  86. package/.framework/functions/integration-outbound.ts +205 -75
  87. package/.framework/functions/integration-routes.ts +128 -23
  88. package/.framework/functions/integrations.ts +125 -100
  89. package/.framework/functions/invites.ts +1095 -460
  90. package/.framework/functions/item-progress.ts +158 -102
  91. package/.framework/functions/kb.ts +34 -10
  92. package/.framework/functions/logs.ts +133 -133
  93. package/.framework/functions/observability.ts +152 -122
  94. package/.framework/functions/pipeline-executions.ts +147 -132
  95. package/.framework/functions/pipelines.ts +134 -119
  96. package/.framework/functions/prompt-configs.ts +96 -80
  97. package/.framework/functions/roles.ts +112 -82
  98. package/.framework/functions/security.ts +450 -0
  99. package/.framework/functions/system-cron.ts +117 -80
  100. package/.framework/functions/system.ts +158 -98
  101. package/.framework/functions/tests.ts +29 -29
  102. package/.framework/functions/timers.ts +94 -95
  103. package/.framework/functions/trigger-scheduler.ts +10 -0
  104. package/.framework/functions/triggers.ts +179 -149
  105. package/.framework/functions/types.ts +137 -125
  106. package/.framework/mcp/index.ts +133 -0
  107. package/.framework/mcp/load-env.ts +60 -0
  108. package/.framework/mcp/shared/app-manifest.ts +275 -0
  109. package/.framework/mcp/shared/db.ts +477 -0
  110. package/.framework/mcp/shared/kb.ts +118 -0
  111. package/.framework/mcp/tools/architect.ts +431 -0
  112. package/.framework/mcp/tools/cil/context.ts +345 -0
  113. package/.framework/mcp/tools/cil/graph.ts +242 -0
  114. package/.framework/mcp/tools/cil/ingest.ts +1217 -0
  115. package/.framework/mcp/tools/cil/pipeline-orchestrator.ts +693 -0
  116. package/.framework/mcp/tools/cil/pipeline.ts +767 -0
  117. package/.framework/mcp/tools/cil/project.ts +791 -0
  118. package/.framework/mcp/tools/cil/retrieval.ts +336 -0
  119. package/.framework/mcp/tools/cil/search-core.ts +454 -0
  120. package/.framework/mcp/tools/cil/search.ts +97 -0
  121. package/.framework/mcp/tools/cil/suggest.ts +186 -0
  122. package/.framework/mcp/tools/cil/validate.ts +1369 -0
  123. package/.framework/mcp/tools/kb/delete.ts +139 -0
  124. package/.framework/mcp/tools/kb/index.ts +52 -0
  125. package/.framework/mcp/tools/kb/ingest.ts +84 -0
  126. package/.framework/mcp/tools/kb/list-types.ts +102 -0
  127. package/.framework/mcp/tools/kb/publish.ts +100 -0
  128. package/.framework/mcp/tools/kb/reindex.ts +86 -0
  129. package/.framework/mcp/tools/kb/revoke.ts +85 -0
  130. package/.framework/mcp/tools/kb/search.ts +101 -0
  131. package/.framework/mcp/tools/kb/upsert.ts +125 -0
  132. package/.framework/mcp/tools/observability.ts +510 -0
  133. package/.framework/migrations/001_core_schema.sql +15 -0
  134. package/.framework/migrations/002_core_rls_and_functions.sql +15 -0
  135. package/.framework/migrations/003_core_system_data.sql +16 -1
  136. package/.framework/migrations/004_core_rpc_and_broker.sql +17 -1
  137. package/.framework/migrations/005_core_observability.sql +17 -1
  138. package/.framework/migrations/006_security_hardening_rls.sql +15 -0
  139. package/.framework/migrations/007_kb_article_list.sql +17 -1
  140. package/.framework/migrations/008_items_target.sql +15 -0
  141. package/.framework/migrations/009_roles_slug_unique.sql +15 -0
  142. package/.framework/migrations/010_auth_user_trigger.sql +15 -0
  143. package/.framework/migrations/011_spine_system_account.sql +16 -0
  144. package/.framework/migrations/012_service_role_grants.sql +16 -0
  145. package/.framework/migrations/013_get_account_apps_role_filter.sql +15 -0
  146. package/.framework/migrations/014_apps_required_roles.sql +16 -0
  147. package/.framework/migrations/015_types_kind_slug_unique.sql +15 -0
  148. package/.framework/migrations/016_cil_types.sql +281 -0
  149. package/.framework/migrations/017_cil_stable_ids.sql +37 -0
  150. package/.framework/migrations/018_runtime_tables.sql +129 -0
  151. package/.framework/migrations/019_agent_prompt_columns.sql +56 -0
  152. package/.framework/migrations/020_schema_reconciliation.sql +67 -0
  153. package/.framework/migrations/021_kb_embedding_lifecycle.sql +31 -0
  154. package/.framework/migrations/032_cil_status_migration.sql +73 -0
  155. package/.framework/migrations/033_cil_versioning.sql +73 -0
  156. package/.framework/migrations/034_match_embeddings_knn.sql +115 -0
  157. package/.framework/migrations/035_rate_limits.sql +55 -0
  158. package/.framework/migrations/036_demo_record_flags.sql +72 -0
  159. package/.framework/migrations/037_kb_types_canonical.sql +244 -0
  160. package/.framework/migrations/038_drop_demo_record_flags.sql +38 -0
  161. package/.framework/migrations/042_registration_hierarchy.sql +309 -0
  162. package/.framework/migrations/043_policy_actor_cleanup.sql +39 -0
  163. package/.framework/migrations/044_match_embeddings_filtered_knn.sql +151 -0
  164. package/.framework/migrations/045_security_critical_rls.sql +139 -0
  165. package/.framework/migrations/046_security_missing_rls.sql +79 -0
  166. package/.framework/migrations/047_people_updated_by.sql +27 -0
  167. package/.framework/migrations/048_watcher_last_seen_at.sql +24 -0
  168. package/.framework/migrations/049_security_blocklist.sql +148 -0
  169. package/.framework/migrations/050_notifications.sql +49 -0
  170. package/.framework/migrations/051_message_agent_fields.sql +74 -0
  171. package/.framework/migrations/052_registration_security.sql +421 -0
  172. package/.framework/migrations/053_builtin_action_seeds.sql +66 -0
  173. package/.framework/migrations/054_kb_ingest_lease.sql +157 -0
  174. package/.framework/migrations/055_type_id_drift_reconciliation.sql +33 -0
  175. package/.framework/migrations/056_slug_column_reconciliation.sql +38 -0
  176. package/.framework/migrations/057_pipelines_slug_identity.sql +14 -0
  177. package/.framework/migrations/058_account_data_field_declarations.sql +53 -0
  178. package/.framework/migrations/059_registration_placement_fixes.sql +269 -0
  179. package/.framework/migrations/060_account_person_record_permissions.sql +38 -0
  180. package/.framework/migrations/061_fk_dedup.sql +32 -0
  181. package/.framework/public/spine-logo.svg +10 -3
  182. package/.framework/scripts/app-install-cli.ts +190 -93
  183. package/.framework/scripts/assemble-frontend.sh +127 -44
  184. package/.framework/scripts/assemble-functions.sh +128 -30
  185. package/.framework/scripts/boundary-check.sh +6 -2
  186. package/.framework/scripts/build-manifest.sh +24 -68
  187. package/.framework/scripts/check-core-integrity.sh +15 -76
  188. package/.framework/scripts/checksum-manifest.mts +343 -0
  189. package/.framework/scripts/cil-migrate-markers.ts +403 -0
  190. package/.framework/scripts/fix-cil-markers.mjs +176 -0
  191. package/.framework/scripts/verify-integrity.sh +21 -57
  192. package/.framework/scripts/verify-manifest.mts +305 -0
  193. package/.framework/seeds/types/funnel_signal_use.json +74 -21
  194. package/.framework/seeds/types/spine_instance.json +73 -21
  195. package/.framework/src/App.tsx +118 -72
  196. package/.framework/src/apps/admin/index.tsx +855 -58
  197. package/.framework/src/components/AppWrapper.tsx +43 -45
  198. package/.framework/src/components/CustomAppLoader.tsx +160 -116
  199. package/.framework/src/components/admin/AdminListPage.tsx +46 -44
  200. package/.framework/src/components/admin/AdminSidebar.tsx +57 -47
  201. package/.framework/src/components/admin/AdminStatsCard.tsx +46 -44
  202. package/.framework/src/components/admin/PageInstructions.tsx +98 -2
  203. package/.framework/src/components/admin/SortableTableHeader.tsx +44 -45
  204. package/.framework/src/components/app-shell/GenericAppShell.tsx +64 -65
  205. package/.framework/src/components/app-shell/GenericDetailPage.tsx +44 -47
  206. package/.framework/src/components/app-shell/GenericListPage.tsx +45 -49
  207. package/.framework/src/components/app-sidebar.tsx +42 -45
  208. package/.framework/src/components/auth/ProtectedRoute.tsx +48 -41
  209. package/.framework/src/components/auth/TurnstileWidget.tsx +27 -0
  210. package/.framework/src/components/kb/KBArticleEditor.tsx +231 -22
  211. package/.framework/src/components/kb/KBArticleList.tsx +251 -10
  212. package/.framework/src/components/layout/AppShell.tsx +51 -45
  213. package/.framework/src/components/layout/Header.tsx +42 -43
  214. package/.framework/src/components/layout/Layout.tsx +46 -46
  215. package/.framework/src/components/layout/Sidebar.tsx +196 -96
  216. package/.framework/src/components/runtime/DataDetailHeader.tsx +55 -30
  217. package/.framework/src/components/runtime/DataDetailPage.tsx +31 -269
  218. package/.framework/src/components/runtime/DataFilters.tsx +49 -74
  219. package/.framework/src/components/runtime/DataHeader.tsx +53 -32
  220. package/.framework/src/components/runtime/DataListPage.tsx +51 -155
  221. package/.framework/src/components/runtime/DataStats.tsx +66 -44
  222. package/.framework/src/components/runtime/DataTable.tsx +49 -149
  223. package/.framework/src/components/runtime/SchemaDetailForm.tsx +45 -75
  224. package/.framework/src/components/runtime/index.ts +119 -16
  225. package/.framework/src/components/search-form.tsx +46 -29
  226. package/.framework/src/components/shared/AgentView.tsx +65 -48
  227. package/.framework/src/components/shared/FieldRenderer.tsx +144 -50
  228. package/.framework/src/components/shared/InviteManager.tsx +207 -97
  229. package/.framework/src/components/shared/MemberList.tsx +97 -0
  230. package/.framework/src/components/shared/SchemaFields.tsx +107 -86
  231. package/.framework/src/components/ui/DataTable.tsx +80 -68
  232. package/.framework/src/components/ui/Form.tsx +157 -146
  233. package/.framework/src/components/ui/ItemCard.tsx +74 -67
  234. package/.framework/src/components/ui/ItemListView.tsx +73 -68
  235. package/.framework/src/components/ui/LoadingSpinner.tsx +43 -48
  236. package/.framework/src/components/ui/Modal.tsx +78 -68
  237. package/.framework/src/components/ui/RichTextEditor.tsx +89 -69
  238. package/.framework/src/components/ui/accordion.tsx +85 -86
  239. package/.framework/src/components/ui/alert-dialog.tsx +197 -184
  240. package/.framework/src/components/ui/alert.tsx +105 -94
  241. package/.framework/src/components/ui/aspect-ratio.tsx +57 -43
  242. package/.framework/src/components/ui/avatar.tsx +122 -107
  243. package/.framework/src/components/ui/badge.tsx +60 -55
  244. package/.framework/src/components/ui/breadcrumb.tsx +127 -128
  245. package/.framework/src/components/ui/button-group.tsx +86 -72
  246. package/.framework/src/components/ui/button.tsx +71 -50
  247. package/.framework/src/components/ui/calendar.tsx +72 -57
  248. package/.framework/src/components/ui/card.tsx +136 -129
  249. package/.framework/src/components/ui/carousel.tsx +226 -107
  250. package/.framework/src/components/ui/chart.tsx +252 -147
  251. package/.framework/src/components/ui/checkbox.tsx +43 -44
  252. package/.framework/src/components/ui/collapsible.tsx +86 -71
  253. package/.framework/src/components/ui/combobox.tsx +282 -249
  254. package/.framework/src/components/ui/command.tsx +158 -146
  255. package/.framework/src/components/ui/context-menu.tsx +239 -240
  256. package/.framework/src/components/ui/dialog.tsx +174 -157
  257. package/.framework/src/components/ui/direction.tsx +72 -56
  258. package/.framework/src/components/ui/drawer.tsx +168 -169
  259. package/.framework/src/components/ui/dropdown-menu.tsx +254 -223
  260. package/.framework/src/components/ui/empty.tsx +131 -120
  261. package/.framework/src/components/ui/field.tsx +205 -173
  262. package/.framework/src/components/ui/hover-card.tsx +71 -72
  263. package/.framework/src/components/ui/input-group.tsx +148 -133
  264. package/.framework/src/components/ui/input-otp.tsx +99 -86
  265. package/.framework/src/components/ui/input.tsx +43 -41
  266. package/.framework/src/components/ui/item.tsx +207 -185
  267. package/.framework/src/components/ui/kbd.tsx +57 -56
  268. package/.framework/src/components/ui/label.tsx +45 -41
  269. package/.framework/src/components/ui/menubar.tsx +268 -236
  270. package/.framework/src/components/ui/native-select.tsx +85 -86
  271. package/.framework/src/components/ui/navigation-menu.tsx +166 -156
  272. package/.framework/src/components/ui/pagination.tsx +131 -141
  273. package/.framework/src/components/ui/popover.tsx +125 -128
  274. package/.framework/src/components/ui/progress.tsx +47 -44
  275. package/.framework/src/components/ui/radio-group.tsx +60 -55
  276. package/.framework/src/components/ui/resizable.tsx +85 -72
  277. package/.framework/src/components/ui/scroll-area.tsx +57 -58
  278. package/.framework/src/components/ui/select.tsx +182 -169
  279. package/.framework/src/components/ui/separator.tsx +42 -43
  280. package/.framework/src/components/ui/sheet.tsx +170 -159
  281. package/.framework/src/components/ui/sidebar.tsx +395 -398
  282. package/.framework/src/components/ui/skeleton.tsx +42 -43
  283. package/.framework/src/components/ui/slider.tsx +61 -44
  284. package/.framework/src/components/ui/sonner.tsx +44 -44
  285. package/.framework/src/components/ui/spinner.tsx +47 -42
  286. package/.framework/src/components/ui/switch.tsx +56 -42
  287. package/.framework/src/components/ui/table-primitives.tsx +272 -132
  288. package/.framework/src/components/ui/table.tsx +140 -142
  289. package/.framework/src/components/ui/tabs.tsx +110 -93
  290. package/.framework/src/components/ui/textarea.tsx +43 -44
  291. package/.framework/src/components/ui/toggle-group.tsx +87 -71
  292. package/.framework/src/components/ui/toggle.tsx +56 -56
  293. package/.framework/src/components/ui/tooltip.tsx +99 -85
  294. package/.framework/src/contexts/AppContext.tsx +166 -114
  295. package/.framework/src/contexts/AuthContext.tsx +232 -137
  296. package/.framework/src/hooks/use-mobile.ts +43 -44
  297. package/.framework/src/hooks/useApi.ts +185 -172
  298. package/.framework/src/hooks/useAppPath.ts +31 -29
  299. package/.framework/src/hooks/useApps.ts +77 -42
  300. package/.framework/src/hooks/useEntityList.ts +66 -29
  301. package/.framework/src/hooks/useEntityRecord.ts +76 -32
  302. package/.framework/src/hooks/useForm.ts +62 -30
  303. package/.framework/src/hooks/useListSchema.ts +60 -43
  304. package/.framework/src/hooks/useSchemaRecord.ts +115 -95
  305. package/.framework/src/lib/api.ts +258 -134
  306. package/.framework/src/lib/registration.ts +181 -0
  307. package/.framework/src/lib/supabase.ts +118 -81
  308. package/.framework/src/lib/utils.ts +266 -266
  309. package/.framework/src/main.tsx +43 -44
  310. package/.framework/src/pages/DashboardPage.tsx +44 -43
  311. package/.framework/src/pages/NoAppPage.tsx +50 -0
  312. package/.framework/src/pages/NotFoundPage.tsx +32 -29
  313. package/.framework/src/pages/SetupPage.tsx +34 -33
  314. package/.framework/src/pages/admin/AIAgentDetailPage.tsx +69 -58
  315. package/.framework/src/pages/admin/AIAgentsPage.tsx +43 -40
  316. package/.framework/src/pages/admin/APIKeyDetailPage.tsx +63 -55
  317. package/.framework/src/pages/admin/APIKeysPage.tsx +44 -42
  318. package/.framework/src/pages/admin/AlertsConfigPage.tsx +117 -94
  319. package/.framework/src/pages/admin/AppDetailPage.tsx +48 -42
  320. package/.framework/src/pages/admin/AppsPage.tsx +45 -42
  321. package/.framework/src/pages/admin/DeliveriesPage.tsx +49 -17
  322. package/.framework/src/pages/admin/DesignedPage.tsx +31 -30
  323. package/.framework/src/pages/admin/EmbeddingDetailPage.tsx +58 -0
  324. package/.framework/src/pages/admin/EmbeddingsPage.tsx +49 -0
  325. package/.framework/src/pages/admin/ExtendedShadcnTestPage.tsx +31 -29
  326. package/.framework/src/pages/admin/IncrementalShadcnTestPage.tsx +46 -29
  327. package/.framework/src/pages/admin/IntegratedDashboard.tsx +32 -29
  328. package/.framework/src/pages/admin/IntegrationDetailPage.tsx +68 -55
  329. package/.framework/src/pages/admin/IntegrationsPage.tsx +45 -42
  330. package/.framework/src/pages/admin/InvitesPage.tsx +60 -44
  331. package/.framework/src/pages/admin/LogsPage.tsx +87 -137
  332. package/.framework/src/pages/admin/MinimalShadcnTestPage.tsx +31 -29
  333. package/.framework/src/pages/admin/ObservabilityDashboard.tsx +150 -89
  334. package/.framework/src/pages/admin/PipelineDetailPage.tsx +77 -104
  335. package/.framework/src/pages/admin/PipelineExecutionsPage.tsx +44 -43
  336. package/.framework/src/pages/admin/PipelinesPage.tsx +59 -145
  337. package/.framework/src/pages/admin/PromptConfigDetailPage.tsx +53 -42
  338. package/.framework/src/pages/admin/PromptConfigsPage.tsx +47 -117
  339. package/.framework/src/pages/admin/ProperlyDesignedPage.tsx +31 -44
  340. package/.framework/src/pages/admin/RoleDetailPage.tsx +49 -92
  341. package/.framework/src/pages/admin/RolesPage.tsx +47 -164
  342. package/.framework/src/pages/admin/SecurityPage.tsx +310 -0
  343. package/.framework/src/pages/admin/SelectTestPage.tsx +30 -32
  344. package/.framework/src/pages/admin/ShadcnTestPage.tsx +37 -44
  345. package/.framework/src/pages/admin/SimpleDashboard.tsx +32 -44
  346. package/.framework/src/pages/admin/TestRunDetailPage.tsx +97 -44
  347. package/.framework/src/pages/admin/TestingDashboard.tsx +126 -71
  348. package/.framework/src/pages/admin/TimerDetailPage.tsx +67 -55
  349. package/.framework/src/pages/admin/TimersPage.tsx +44 -42
  350. package/.framework/src/pages/admin/TriggerDetailPage.tsx +47 -42
  351. package/.framework/src/pages/admin/TriggersPage.tsx +58 -57
  352. package/.framework/src/pages/admin/TypeDetailPage.tsx +91 -55
  353. package/.framework/src/pages/admin/TypesPage.tsx +45 -42
  354. package/.framework/src/pages/admin/cil/CILAgentPage.tsx +258 -128
  355. package/.framework/src/pages/admin/cil/CILChunkDetailPage.tsx +127 -123
  356. package/.framework/src/pages/admin/cil/CILDashboardPage.tsx +308 -235
  357. package/.framework/src/pages/admin/cil/CILFileListPage.tsx +159 -110
  358. package/.framework/src/pages/admin/cil/CILFileSelectPage.tsx +432 -0
  359. package/.framework/src/pages/admin/cil/CILGraphPage.tsx +200 -178
  360. package/.framework/src/pages/admin/cil/CILIngestionPage.tsx +286 -239
  361. package/.framework/src/pages/admin/cil/CILProjectsPage.tsx +211 -90
  362. package/.framework/src/pages/admin/cil/CILSearchPage.tsx +156 -143
  363. package/.framework/src/pages/admin/cil/CILSuggestionsPage.tsx +379 -0
  364. package/.framework/src/pages/admin/cil/CILVersionsPage.tsx +337 -0
  365. package/.framework/src/pages/admin/cil/FlexiblePipelinePage.tsx +219 -214
  366. package/.framework/src/pages/admin/kb/KBAdminPage.tsx +64 -0
  367. package/.framework/src/pages/auth/AuthConfirmPage.tsx +135 -65
  368. package/.framework/src/pages/auth/ForgotPasswordPage.tsx +39 -31
  369. package/.framework/src/pages/auth/LoginPage.tsx +38 -32
  370. package/.framework/src/pages/auth/PendingApprovalPage.tsx +31 -28
  371. package/.framework/src/pages/auth/RegisterPage.tsx +429 -155
  372. package/.framework/src/pages/spine-framework/APIPage.tsx +33 -30
  373. package/.framework/src/pages/spine-framework/CLIPage.tsx +32 -30
  374. package/.framework/src/types/auth.ts +101 -93
  375. package/.framework/src/types/types.ts +283 -262
  376. package/.framework/templates/project.json +87 -0
  377. package/.framework/templates/spine.config.neutral.json +7 -0
  378. package/.framework/tests/api/api-surface.test.ts +381 -0
  379. package/.framework/tests/fixtures/seed.ts +427 -0
  380. package/.framework/tests/fixtures/teardown.ts +228 -0
  381. package/.framework/tests/reporter.ts +351 -0
  382. package/.framework/tests/setup.ts +135 -0
  383. package/.framework/tests/ui/ui-sweep.ts +278 -0
  384. package/.framework/tests/unit/admin-data-logger.test.ts +310 -0
  385. package/.framework/tests/unit/agent-runner.test.ts +2389 -0
  386. package/.framework/tests/unit/ai-interactions.test.ts +81 -0
  387. package/.framework/tests/unit/app-manifest.test.ts +359 -0
  388. package/.framework/tests/unit/assembly-scripts.test.ts +172 -0
  389. package/.framework/tests/unit/cil-determinism.test.ts +85 -0
  390. package/.framework/tests/unit/core-isolation.test.ts +153 -0
  391. package/.framework/tests/unit/funnel-signals.test.ts +135 -0
  392. package/.framework/tests/unit/install-app.test.ts +1759 -0
  393. package/.framework/tests/unit/invites-security.test.ts +572 -0
  394. package/.framework/tests/unit/kb-ingest-lease.test.ts +287 -0
  395. package/.framework/tests/unit/kb-search.test.ts +119 -0
  396. package/.framework/tests/unit/migrate.test.ts +509 -0
  397. package/.framework/tests/unit/notify.test.ts +136 -0
  398. package/.framework/tests/unit/permissions.test.ts +269 -0
  399. package/.framework/tests/unit/pipeline-runner.test.ts +755 -0
  400. package/.framework/tests/unit/principal-cache.test.ts +138 -0
  401. package/.framework/tests/unit/retrieval-golden.test.ts +520 -0
  402. package/.framework/tests/unit/runtime-isolation.test.ts +642 -0
  403. package/.framework/tests/unit/schema-utils.test.ts +225 -0
  404. package/.framework/tests/unit/trigger-engine.test.ts +513 -0
  405. package/.framework/tests/unit/validate-app.test.ts +527 -0
  406. package/README.md +34 -3
  407. package/bin/spine-framework.cjs +1 -0
  408. package/config/tailwind.config.cjs +7 -0
  409. package/config/tsconfig.functions.json +42 -0
  410. package/config/tsconfig.json +37 -9
  411. package/config/vite.config.ts +31 -2
  412. package/netlify.toml +31 -3
  413. package/package.json +46 -29
  414. package/scripts/assemble-frontend.sh +127 -44
  415. package/scripts/assemble-functions.sh +127 -29
  416. package/scripts/boundary-check.sh +6 -2
  417. package/scripts/build-manifest.sh +24 -68
  418. package/scripts/checksum-manifest.mts +345 -0
  419. package/scripts/dev-clean.sh +86 -0
  420. package/scripts/dev-netlify.sh +49 -0
  421. package/scripts/netlify-dev-wrapper.sh +2 -0
  422. package/scripts/verify-install.ts +358 -0
  423. package/scripts/verify-integrity.sh +21 -57
  424. package/scripts/verify-manifest.mts +305 -0
  425. package/templates/project/gitignore +45 -0
  426. package/{config → templates/project}/package-lock.json +22335 -9366
  427. package/vitest.config.ts +46 -0
  428. package/.framework/public/spine.config.json +0 -91
  429. package/config/deno.lock +0 -108
  430. package/config/tsconfig.node.tsbuildinfo +0 -1
  431. package/config/tsconfig.tsbuildinfo +0 -1
  432. package/config/vite.config.d.ts +0 -2
  433. package/custom/.devin/AGENT.md +0 -357
  434. package/custom/.devin/skills/install-app/SKILL.md +0 -39
  435. package/custom/.devin/skills/spine-workbench-discovery/SKILL.md +0 -39
  436. package/custom/.devin/skills/spine-workbench-idea/SKILL.md +0 -36
  437. package/custom/.devin/skills/spine-workbench-implement/SKILL.md +0 -46
  438. package/custom/.devin/skills/spine-workbench-initiative/SKILL.md +0 -28
  439. package/custom/.devin/skills/spine-workbench-plan/SKILL.md +0 -38
  440. package/custom/.devin/workflows/app-install.yaml +0 -83
  441. package/custom/README.md +0 -79
  442. package/docs/README.md +0 -15
  443. package/scripts/app-install-cli.ts +0 -286
  444. package/scripts/check-core-integrity.sh +0 -82
  445. package/scripts/ingest-chunks.cjs +0 -202
  446. package/scripts/kb-chunk-parser.cjs +0 -312
  447. package/scripts/kb-chunk-parser.ts +0 -330
  448. package/scripts/kb-ingest-docs.ts +0 -203
  449. package/scripts/load-test-app-install.ts +0 -484
  450. package/scripts/test-login.js +0 -33
  451. package/spine.config.json +0 -91
@@ -1,8 +1,32 @@
1
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:MAP_SOURCE_STATUS:constant" type="constant" identity="MAP_SOURCE_STATUS" parent="~/.framework/functions/cil-callmap.ts"]
2
+ // CIL[DOC-MACRO purpose="Define source file status mapping for CIL callmap pass transitions"]
3
+ // CIL[DOC-RESPONSIBILITY responsibility="Provide the prior and target statuses that qualify files for mapping"]
4
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="constant" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
5
+ // CIL[DOC-CONTRACT inputs="none" outputs="Record of first/second pass status transitions" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
6
+ // CIL[DOC-MICRO logic_summary="Maps 'first' and 'second' pass statuses to prior and target FileStatus values" notable_decisions="[]"]
7
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
8
+ // CIL[DOC-STABILITY stability="stable"]
1
9
 
2
- const MAP_SOURCE_STATUS: Record<'first' | 'second', { prior: string; target: string }> = {
3
- first: { prior: '6-embedded', target: '7-mapped' },
4
- second: { prior: '9-embedded', target: '10-mapped' },
10
+ const MAP_SOURCE_STATUS: Record<'first' | 'second', { prior: FileStatus; target: FileStatus }> = {
11
+ first: { prior: '6-enriched', target: '7-embedded-mapped' },
12
+ second: { prior: '6-enriched', target: '7-embedded-mapped' },
5
13
  }
14
+ // CIL[DOC-VECTOR type="context" content="purpose='Define source file status mapping for CIL callmap pass transitions'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
15
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
16
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
17
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
18
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
19
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
20
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:MAP_SOURCE_STATUS:constant"]
21
+
22
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:getMapSourceFilePaths:function" type="function" identity="getMapSourceFilePaths" parent="~/.framework/functions/cil-callmap.ts"]
23
+ // CIL[DOC-MACRO purpose="Filter project file statuses to find files eligible for mapping"]
24
+ // CIL[DOC-RESPONSIBILITY responsibility="Return the list of file paths whose current status matches the mapping prior status"]
25
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
26
+ // CIL[DOC-CONTRACT inputs="projectItem, secondPass flag" outputs="string[] of file paths" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
27
+ // CIL[DOC-MICRO logic_summary="Reads project file statuses and returns paths whose status equals the configured prior status" notable_decisions="[]"]
28
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
29
+ // CIL[DOC-STABILITY stability="stable"]
6
30
 
7
31
  function getMapSourceFilePaths(projectItem: any, secondPass: boolean): string[] {
8
32
  const fileStatuses: Record<string, string> = projectItem?.data?.file_statuses || {}
@@ -11,34 +35,43 @@ function getMapSourceFilePaths(projectItem: any, secondPass: boolean): string[]
11
35
  .filter(([, status]) => status === prior)
12
36
  .map(([filePath]) => filePath)
13
37
  }
14
-
15
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_module_header_1784235266" type="module_header" identity="module_header" parent="none"]
16
- // CIL[DOC-MACRO purpose="Module header and top-level exports for cortex.functions.custom_cil-callmap"]
17
- // CIL[DOC-RESPONSIBILITY responsibility="Own module-level imports, exports, and configuration for cortex.functions.custom_cil-callmap"]
18
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[\".framework/migrations/015_simplify_apps_table.sql\",\"custom/apps/cortex/pages/operations/OperationsDashboard.tsx\",\"custom/apps/portal/pages/ContentPage.tsx\",\".framework/src/components/ui/table-primitives.tsx\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\"\\\"]"]
19
- // CIL[DOC-CONTRACT inputs="none" outputs="module exports and side effects" errors="none" side_effects="none"]
20
- // CIL[DOC-MICRO logic_summary="Declares module scope, imports dependencies, and exports public surface of cortex.functions.custom_cil-callmap" notable_decisions="[]"]
21
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
22
- // CIL[DOC-STABILITY stability="stable"]
23
- // CIL[DOC-AUDIENCE audience="developer"]
24
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: .framework/migrations/015_simplify_apps_table.sql, custom/apps/cortex/pages/operations/OperationsDashboard.tsx, custom/apps/portal/pages/ContentPage.tsx, .framework/src/components/ui/table-primitives.tsx, .framework/src/pages/admin/TypeDetailPage.tsx, \."]
25
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
26
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
27
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
38
+ // CIL[DOC-VECTOR type="context" content="purpose='Filter project file statuses to find files eligible for mapping'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
39
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
40
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
41
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
28
42
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
29
43
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
44
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:getMapSourceFilePaths:function"]
45
+
30
46
 
31
47
 
32
48
 
33
49
 
34
50
 
51
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:module_header:module_header" type="module_header" identity="module_header" parent="~/.framework/functions/cil-callmap.ts"]
52
+ // CIL[DOC-MACRO purpose="Import dependencies and set module context for the .framework/functions/cil-callmap Netlify function"]
53
+ // CIL[DOC-RESPONSIBILITY responsibility="Load shared middleware, database, admin-data, CIL helpers and path utilities for the callmap handler"]
54
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="module_header" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts"]
55
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
56
+ // CIL[DOC-MICRO logic_summary="Imports createHandler, adminDb, resolve-ids, admin-data CRUD, CIL status helpers, fs and path for the handler" notable_decisions="[]"]
57
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
58
+ // CIL[DOC-STABILITY stability="stable"]
59
+ // CIL[DOC-AUDIENCE audience="maintainer"]
60
+
35
61
  import { createHandler } from './_shared/middleware'
36
62
  import { adminDb } from './_shared/db'
37
- import { resolveLinkTypeId } from './_shared/resolve-ids'
63
+ import { resolveLinkTypeIds } from './_shared/resolve-ids'
38
64
  import { create as adminCreate, update as adminUpdate } from './admin-data'
39
65
  import { FileStatus, FileTreeNode, isSelectedPath, getFileStatus, updateTreeNodeStatus, saveProjectTree } from './_shared/cil'
40
66
  import * as fs from 'fs'
41
67
  import * as path from 'path'
68
+ // CIL[DOC-VECTOR type="context" content="purpose='Import dependencies and set module context for the .framework/functions/cil-callmap Netlify function'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
69
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
70
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
71
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
72
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
73
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
74
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:module_header:module_header"]
42
75
 
43
76
 
44
77
 
@@ -48,67 +81,209 @@ import * as path from 'path'
48
81
 
49
82
 
50
83
 
51
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_module_header_1784235266"]
52
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_status_rank_1784235266" type="variable" identity="status_rank" parent="none"]
53
- // CIL[DOC-MACRO purpose="Defines status_rank configuration or state in cortex.functions.custom_cil-callmap"]
54
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for status_rank"]
55
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\"custom/apps/cortex/functions/custom_cil-embeddings.ts\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\"custom/apps/portal/pages/ContentPage.tsx\",\"\\\"]"]
56
- // CIL[DOC-CONTRACT inputs="none" outputs="value of status_rank" errors="none" side_effects="none"]
57
- // CIL[DOC-MICRO logic_summary="Declares status_rank with initial value or constant binding used by cortex.functions.custom_cil-callmap" notable_decisions="[]"]
58
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
59
- // CIL[DOC-STABILITY stability="stable"]
60
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: .framework/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, custom/apps/cortex/functions/custom_cil-embeddings.ts, .framework/src/pages/admin/IntegrationsPage.tsx, custom/apps/portal/pages/ContentPage.tsx, \."]
61
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
62
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
63
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
64
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
65
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
84
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:STATUS_RANK:constant" type="constant" identity="STATUS_RANK" parent="~/.framework/functions/cil-callmap.ts"]
85
+ // CIL[DOC-MACRO purpose="Define numeric ordering for CIL pipeline file statuses"]
86
+ // CIL[DOC-RESPONSIBILITY responsibility="Provide a rank lookup for comparing CIL file status progression"]
87
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="constant" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
88
+ // CIL[DOC-CONTRACT inputs="none" outputs="Record<string, number>" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
89
+ // CIL[DOC-MICRO logic_summary="Maps each pipeline status string to an integer rank for ordering comparisons" notable_decisions="[]"]
90
+ // CIL[DOC-STABILITY stability="internal"]
91
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
92
+
66
93
  const STATUS_RANK: Record<string, number> = {
67
- '2-discovered': 2,
68
- '3-selected': 3,
69
- '4-chunked': 4,
70
- '5-documented': 5,
71
- '6-embedded': 6,
72
- '7-mapped': 7,
73
- '8-enriched': 8,
74
- '9-embedded': 9,
75
- '10-mapped': 10,
76
-
77
- 'pass2_complete': 4,
78
- 'pass3_complete': 5,
79
- 'pass4_complete': 6,
80
- 'pass4b_complete': 7,
81
- 'pass6_complete': 8,
82
- 'pass7_complete': 9,
83
- 'pass8_complete': 10,
94
+ '0-discovered': 0,
95
+ '1-selected': 1,
96
+ '2-chunked': 2,
97
+ '3-documented': 3,
98
+ '4-chunk-validated': 4,
99
+ '5-doc-validated': 5,
100
+ '6-enriched': 6,
101
+ '7-embedded-mapped': 7,
102
+ '8-published': 8,
84
103
  }
104
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:STATUS_RANK:constant"]
85
105
 
86
106
  // Keep REST URL length under the ~8k character limit for UUID IN clauses.
107
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:UUID_IN_LIMIT:constant" type="constant" identity="UUID_IN_LIMIT" parent="~/.framework/functions/cil-callmap.ts"]
108
+ // CIL[DOC-VECTOR type="context" content="purpose='Define numeric ordering for CIL pipeline file statuses'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
109
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
110
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
111
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
112
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
113
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
114
+ // CIL[DOC-MACRO purpose="Set the maximum UUID count for IN clause link deletions"]
115
+ // CIL[DOC-RESPONSIBILITY responsibility="Limit the size of UUID IN clause batches to keep REST URLs under ~8k"]
116
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="constant" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
117
+ // CIL[DOC-CONTRACT inputs="none" outputs="number" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
118
+ // CIL[DOC-MICRO logic_summary="Declares a constant of 100 UUIDs per batched IN clause" notable_decisions="[]"]
119
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
120
+ // CIL[DOC-STABILITY stability="stable"]
121
+
87
122
  const UUID_IN_LIMIT = 100
123
+ // CIL[DOC-VECTOR type="context" content="purpose='Set the maximum UUID count for IN clause link deletions'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
124
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
125
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
126
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
127
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
128
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
129
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:UUID_IN_LIMIT:constant"]
130
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:PAGE_SIZE:constant" type="constant" identity="PAGE_SIZE" parent="~/.framework/functions/cil-callmap.ts"]
131
+ // CIL[DOC-MACRO purpose="Set the page size for batched project record fetching"]
132
+ // CIL[DOC-RESPONSIBILITY responsibility="Limit each adminDb query to 1000 rows for pagination"]
133
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="constant" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
134
+ // CIL[DOC-CONTRACT inputs="none" outputs="number" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
135
+ // CIL[DOC-MICRO logic_summary="Declares a constant of 1000 records per page" notable_decisions="[]"]
136
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
137
+ // CIL[DOC-STABILITY stability="stable"]
88
138
 
139
+ const PAGE_SIZE = 1000
140
+ // CIL[DOC-VECTOR type="context" content="purpose='Set the page size for batched project record fetching'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
141
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
142
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
143
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
144
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
145
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
146
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:PAGE_SIZE:constant"]
147
+
148
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:fetchAllProjectRecords:function" type="function" identity="fetchAllProjectRecords" parent="~/.framework/functions/cil-callmap.ts"]
149
+ // CIL[DOC-MACRO purpose="Fetch all project records of a given KB type in pages"]
150
+ // CIL[DOC-RESPONSIBILITY responsibility="Return every active item of the requested kb_type for a project"]
151
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
152
+ // CIL[DOC-CONTRACT inputs="projectId, kbType" outputs="any[] of item rows" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
153
+ // CIL[DOC-MICRO logic_summary="Paginates through items using offset ranges and accumulates all rows" notable_decisions="[]"]
154
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
155
+ // CIL[DOC-STABILITY stability="stable"]
89
156
 
157
+ async function fetchAllProjectRecords(
158
+ projectId: string,
159
+ kbType: 'cil_file' | 'cil_chunk'
160
+ ): Promise<any[]> {
161
+ const out: any[] = []
162
+ let offset = 0
163
+ while (true) {
164
+ const { data } = await adminDb
165
+ .from('items')
166
+ .select('id, title, data')
167
+ .filter('data->>project_id', 'eq', projectId)
168
+ .filter('data->>kb_type', 'eq', kbType)
169
+ .eq('is_active', true)
170
+ .order('id')
171
+ .range(offset, offset + PAGE_SIZE - 1)
172
+ const rows = data || []
173
+ out.push(...rows)
174
+ if (rows.length < PAGE_SIZE) break
175
+ offset += PAGE_SIZE
176
+ }
177
+ return out
178
+ }
179
+ // CIL[DOC-VECTOR type="context" content="purpose='Fetch all project records of a given KB type in pages'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
180
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
181
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
182
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
183
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
184
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
185
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:fetchAllProjectRecords:function"]
186
+
187
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:fetchAllProjectChunkNames:function" type="function" identity="fetchAllProjectChunkNames" parent="~/.framework/functions/cil-callmap.ts"]
188
+ // CIL[DOC-MACRO purpose="Fetch all chunk names and IDs for a project"]
189
+ // CIL[DOC-RESPONSIBILITY responsibility="Return chunk id, chunk_name and kb_type for every active cil_chunk"]
190
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
191
+ // CIL[DOC-CONTRACT inputs="projectId" outputs="{id, chunk_name, kb_type}[]" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
192
+ // CIL[DOC-MICRO logic_summary="Paginates cil_chunk items and projects minimal fields for name lookup" notable_decisions="[]"]
193
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
194
+ // CIL[DOC-STABILITY stability="stable"]
90
195
 
196
+ async function fetchAllProjectChunkNames(projectId: string): Promise<{ id: string; chunk_name: string; kb_type: string }[]> {
197
+ const out: any[] = []
198
+ let offset = 0
199
+ while (true) {
200
+ const { data } = await adminDb
201
+ .from('items')
202
+ .select('id, data->>chunk_name, data->>kb_type')
203
+ .filter('data->>project_id', 'eq', projectId)
204
+ .filter('data->>kb_type', 'eq', 'cil_chunk')
205
+ .eq('is_active', true)
206
+ .order('id')
207
+ .range(offset, offset + PAGE_SIZE - 1)
208
+ const rows = data || []
209
+ out.push(...rows)
210
+ if (rows.length < PAGE_SIZE) break
211
+ offset += PAGE_SIZE
212
+ }
213
+ return out
214
+ }
215
+ // CIL[DOC-VECTOR type="context" content="purpose='Fetch all chunk names and IDs for a project'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
216
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
217
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
218
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
219
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
220
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
221
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:fetchAllProjectChunkNames:function"]
222
+
223
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:fetchFileChunks:function" type="function" identity="fetchFileChunks" parent="~/.framework/functions/cil-callmap.ts"]
224
+ // CIL[DOC-MACRO purpose="Fetch all chunks for a specific file path"]
225
+ // CIL[DOC-RESPONSIBILITY responsibility="Return every active cil_chunk belonging to a file"]
226
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
227
+ // CIL[DOC-CONTRACT inputs="projectId, filePath" outputs="any[] of chunk rows" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
228
+ // CIL[DOC-STABILITY stability="internal"]
229
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
230
+ // CIL[DOC-MICRO logic_summary="Paginates cil_chunk items filtered by project and file_path" notable_decisions="[]"]
231
+
232
+ async function fetchFileChunks(projectId: string, filePath: string): Promise<any[]> {
233
+ const out: any[] = []
234
+ let offset = 0
235
+ while (true) {
236
+ const { data } = await adminDb
237
+ .from('items')
238
+ .select('id, title, data')
239
+ .filter('data->>project_id', 'eq', projectId)
240
+ .filter('data->>kb_type', 'eq', 'cil_chunk')
241
+ .filter('data->>file_path', 'eq', filePath)
242
+ .eq('is_active', true)
243
+ .order('id')
244
+ .range(offset, offset + PAGE_SIZE - 1)
245
+ const rows = data || []
246
+ out.push(...rows)
247
+ if (rows.length < PAGE_SIZE) break
248
+ offset += PAGE_SIZE
249
+ }
250
+ return out
251
+ }
252
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:fetchFileChunks:function"]
91
253
 
92
254
 
93
255
 
94
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_status_rank_1784235266"]
95
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_rank_1784235266" type="function" identity="rank" parent="none"]
96
- // CIL[DOC-MACRO purpose="Implements rank logic in cortex.functions.custom_cil-callmap"]
97
- // CIL[DOC-RESPONSIBILITY responsibility="Execute rank and return its computed result"]
98
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[\"custom/apps/cortex/functions/custom_cil-embeddings.ts\",\".framework/functions/_shared/principal.ts\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\".framework/migrations/015_simplify_apps_table.sql\",\"\\\"]"]
99
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
100
- // CIL[DOC-MICRO logic_summary="Provides rank with rank(status: string | undefined inputs, handling internal flow and returning a result" notable_decisions="[]"]
101
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
102
- // CIL[DOC-STABILITY stability="stable"]
103
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 2. Direct calls: 0. Related files: custom/apps/cortex/functions/custom_cil-embeddings.ts, .framework/functions/_shared/principal.ts, .framework/src/pages/admin/TypeDetailPage.tsx, .framework/src/pages/admin/IntegrationsPage.tsx, .framework/migrations/015_simplify_apps_table.sql, \."]
104
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 2. Total affected: 2."]
105
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
106
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
256
+ // CIL[DOC-VECTOR type="context" content="purpose='Fetch all chunks for a specific file path'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
257
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
258
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
259
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
107
260
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
108
261
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
262
+
263
+ // CIL[DOC-STABILITY stability="internal"]
264
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
265
+ // CIL[DOC-CONTEXT module="unknown" layer="unknown" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
266
+
267
+
268
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:rank:function" type="function" identity="rank" parent="~/.framework/functions/cil-callmap.ts"]
269
+ // CIL[DOC-MACRO purpose="Return numeric rank for a CIL file status"]
270
+ // CIL[DOC-RESPONSIBILITY responsibility="Convert a status string to its position in the pipeline"]
271
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
272
+ // CIL[DOC-CONTRACT inputs="status string or undefined" outputs="number rank" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
273
+ // CIL[DOC-MICRO logic_summary="Looks up the status in STATUS_RANK and returns 0 for unknown or missing values" notable_decisions="[]"]
274
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
275
+ // CIL[DOC-STABILITY stability="stable"]
276
+
109
277
  function rank(status: string | undefined): number {
110
278
  return status ? STATUS_RANK[status] || 0 : 0
111
279
  }
280
+ // CIL[DOC-VECTOR type="context" content="purpose='Return numeric rank for a CIL file status'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
281
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
282
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
283
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
284
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
285
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
286
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:rank:function"]
112
287
 
113
288
 
114
289
 
@@ -118,26 +293,27 @@ function rank(status: string | undefined): number {
118
293
 
119
294
 
120
295
 
121
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_rank_1784235266"]
122
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractedimport_1784235266" type="interface" identity="extractedimport" parent="none"]
123
- // CIL[DOC-MACRO purpose="Defines the extractedimport type contract in cortex.functions.custom_cil-callmap"]
124
- // CIL[DOC-RESPONSIBILITY responsibility="Describe the shape and allowed fields for extractedimport"]
125
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\".framework/migrations/015_simplify_apps_table.sql\",\"custom/apps/cortex/pages/operations/OperationsDashboard.tsx\",\"\\\"]"]
126
- // CIL[DOC-CONTRACT inputs="none" outputs="type definition for extractedimport" errors="none" side_effects="none"]
127
- // CIL[DOC-MICRO logic_summary="Declares TypeScript type/interface extractedimport with member definitions" notable_decisions="[]"]
128
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
296
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:ExtractedImport:interface" type="interface" identity="ExtractedImport" parent="~/.framework/functions/cil-callmap.ts"]
297
+ // CIL[DOC-MACRO purpose="Define the shape of an extracted ES import"]
298
+ // CIL[DOC-RESPONSIBILITY responsibility="Declare the fields of a parsed import statement"]
299
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="interface" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
300
+ // CIL[DOC-CONTRACT inputs="none" outputs="TypeScript interface" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
301
+ // CIL[DOC-MICRO logic_summary="Declares from_path, symbols and is_default fields" notable_decisions="[]"]
302
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
129
303
  // CIL[DOC-STABILITY stability="stable"]
130
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: .framework/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, .framework/src/pages/admin/IntegrationsPage.tsx, .framework/migrations/015_simplify_apps_table.sql, custom/apps/cortex/pages/operations/OperationsDashboard.tsx, \."]
131
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
132
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
133
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
134
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
135
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
304
+
136
305
  interface ExtractedImport {
137
306
  from_path: string
138
307
  symbols: string[]
139
308
  is_default: boolean
140
309
  }
310
+ // CIL[DOC-VECTOR type="context" content="purpose='Define the shape of an extracted ES import'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
311
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
312
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
313
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
314
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
315
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
316
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:ExtractedImport:interface"]
141
317
 
142
318
 
143
319
 
@@ -145,25 +321,26 @@ interface ExtractedImport {
145
321
 
146
322
 
147
323
 
148
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractedimport_1784235266"]
149
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractedcall_1784235266" type="interface" identity="extractedcall" parent="none"]
150
- // CIL[DOC-MACRO purpose="Defines the extractedcall type contract in cortex.functions.custom_cil-callmap"]
151
- // CIL[DOC-RESPONSIBILITY responsibility="Describe the shape and allowed fields for extractedcall"]
152
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\".framework/migrations/015_simplify_apps_table.sql\",\"custom/apps/cortex/pages/operations/OperationsDashboard.tsx\",\"\\\"]"]
153
- // CIL[DOC-CONTRACT inputs="none" outputs="type definition for extractedcall" errors="none" side_effects="none"]
154
- // CIL[DOC-MICRO logic_summary="Declares TypeScript type/interface extractedcall with member definitions" notable_decisions="[]"]
155
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
324
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:ExtractedCall:interface" type="interface" identity="ExtractedCall" parent="~/.framework/functions/cil-callmap.ts"]
325
+ // CIL[DOC-MACRO purpose="Define the shape of an extracted function call"]
326
+ // CIL[DOC-RESPONSIBILITY responsibility="Declare the fields of a parsed function call"]
327
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="interface" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
328
+ // CIL[DOC-CONTRACT inputs="none" outputs="TypeScript interface" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
329
+ // CIL[DOC-MICRO logic_summary="Declares callee_name and is_await fields" notable_decisions="[]"]
330
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
156
331
  // CIL[DOC-STABILITY stability="stable"]
157
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: .framework/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, .framework/src/pages/admin/IntegrationsPage.tsx, .framework/migrations/015_simplify_apps_table.sql, custom/apps/cortex/pages/operations/OperationsDashboard.tsx, \."]
158
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
159
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
160
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
161
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
162
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
332
+
163
333
  interface ExtractedCall {
164
334
  callee_name: string
165
335
  is_await: boolean
166
336
  }
337
+ // CIL[DOC-VECTOR type="context" content="purpose='Define the shape of an extracted function call'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
338
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
339
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
340
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
341
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
342
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
343
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:ExtractedCall:interface"]
167
344
 
168
345
 
169
346
 
@@ -174,21 +351,15 @@ interface ExtractedCall {
174
351
 
175
352
 
176
353
 
177
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractedcall_1784235266"]
178
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractimports_1784235266" type="function" identity="extractimports" parent="none"]
179
- // CIL[DOC-MACRO purpose="Implements extractimports logic in cortex.functions.custom_cil-callmap"]
180
- // CIL[DOC-RESPONSIBILITY responsibility="Execute extractimports and return its computed result"]
181
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[]"]
182
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
183
- // CIL[DOC-MICRO logic_summary="Provides extractimports with extractImports(source: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
184
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
354
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:extractImports:function" type="function" identity="extractImports" parent="~/.framework/functions/cil-callmap.ts"]
355
+ // CIL[DOC-MACRO purpose="Parse ES import statements from source text"]
356
+ // CIL[DOC-RESPONSIBILITY responsibility="Return a list of extracted imports with named, default and star aliases"]
357
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
358
+ // CIL[DOC-CONTRACT inputs="source string" outputs="ExtractedImport[]" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
359
+ // CIL[DOC-MICRO logic_summary="Regex scans import declarations and resolves specifier blocks into symbol lists" notable_decisions="[]"]
360
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
185
361
  // CIL[DOC-STABILITY stability="stable"]
186
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
187
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
188
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
189
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
190
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
191
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
362
+
192
363
  export function extractImports(source: string): ExtractedImport[] {
193
364
  const results: ExtractedImport[] = []
194
365
 
@@ -227,29 +398,30 @@ export function extractImports(source: string): ExtractedImport[] {
227
398
  }
228
399
  return results
229
400
  }
401
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:extractImports:function"]
230
402
 
231
403
 
404
+ // CIL[DOC-VECTOR type="context" content="purpose='Parse ES import statements from source text'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
405
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
406
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
407
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
408
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
409
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
232
410
 
233
411
 
234
412
 
235
413
 
236
414
 
237
415
 
238
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractimports_1784235266"]
239
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractcalls_1784235266" type="function" identity="extractcalls" parent="none"]
240
- // CIL[DOC-MACRO purpose="Implements extractcalls logic in cortex.functions.custom_cil-callmap"]
241
- // CIL[DOC-RESPONSIBILITY responsibility="Execute extractcalls and return its computed result"]
242
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[]"]
243
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
244
- // CIL[DOC-MICRO logic_summary="Provides extractcalls with extractCalls(source: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
245
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
416
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:extractCalls:function" type="function" identity="extractCalls" parent="~/.framework/functions/cil-callmap.ts"]
417
+ // CIL[DOC-MACRO purpose="Parse function calls and symbol references from source text"]
418
+ // CIL[DOC-RESPONSIBILITY responsibility="Return a deduplicated list of extracted calls, filtering keywords and short names"]
419
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
420
+ // CIL[DOC-CONTRACT inputs="source string" outputs="ExtractedCall[]" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
421
+ // CIL[DOC-MICRO logic_summary="Regex scans for function call tokens, filters reserved words and context names, and deduplicates" notable_decisions="[]"]
422
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
246
423
  // CIL[DOC-STABILITY stability="stable"]
247
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
248
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
249
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
250
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
251
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
252
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
424
+
253
425
  export function extractCalls(source: string): ExtractedCall[] {
254
426
  const seen = new Set<string>()
255
427
  const results: ExtractedCall[] = []
@@ -274,7 +446,17 @@ export function extractCalls(source: string): ExtractedCall[] {
274
446
  }
275
447
  return results
276
448
  }
449
+ // CIL[DOC-VECTOR type="context" content="purpose='Parse function calls and symbol references from source text'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
450
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
451
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
452
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
453
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
454
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
455
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:extractCalls:function"]
277
456
 
457
+ // CIL[DOC-STABILITY stability="internal"]
458
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
459
+ // CIL[DOC-CONTEXT module="unknown" layer="unknown" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
278
460
 
279
461
 
280
462
 
@@ -282,53 +464,47 @@ export function extractCalls(source: string): ExtractedCall[] {
282
464
 
283
465
 
284
466
 
285
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractcalls_1784235266"]
286
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractsymbolreferences_1784235266" type="function" identity="extractsymbolreferences" parent="none"]
287
- // CIL[DOC-MACRO purpose="Find symbol/name references from one chunk to other chunk identities"]
288
- // CIL[DOC-RESPONSIBILITY responsibility="Detect non-call references to exported chunk names/types to enrich the call graph"]
289
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[]"]
290
- // CIL[DOC-CONTRACT inputs="source string, candidate symbol list" outputs="matching symbol names" errors="none" side_effects="none"]
291
- // CIL[DOC-MICRO logic_summary="Builds a single regex from chunk identities and returns the set of names found as whole-word tokens in the source" notable_decisions="[]"]
292
- // CIL[DOC-CONFIDENCE pass="first" score="0.85" flags="possible_false_positives"]
293
- // CIL[DOC-STABILITY stability="experimental"]
294
- function escapeRegex(s: string): string {
295
- return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
296
- }
467
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:extractSymbolReferences:function" type="function" identity="extractSymbolReferences" parent="~/.framework/functions/cil-callmap.ts"]
468
+ // CIL[DOC-MACRO purpose="Find token references to a candidate set in source text"]
469
+ // CIL[DOC-RESPONSIBILITY responsibility="Return the set of candidate symbol names found as bare references"]
470
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
471
+ // CIL[DOC-CONTRACT inputs="source, candidateSet, ownName" outputs="string[] of matching symbols" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
472
+ // CIL[DOC-MICRO logic_summary="Tokenises the source, skips reserved and own name, and returns matched candidate tokens" notable_decisions="[]"]
473
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
474
+ // CIL[DOC-STABILITY stability="stable"]
297
475
 
298
- function extractSymbolReferences(source: string, candidateNames: string[], ownName?: string): string[] {
476
+ function extractSymbolReferences(source: string, candidateSet: Set<string>, ownName?: string): string[] {
299
477
  const reserved = new Set(['if','for','while','switch','catch','return','new','typeof','instanceof','function','const','let','var','class','interface','type','enum','export','import','from','await','async','true','false','null','undefined','this','super','extends','implements','as','in','of','with','yield'])
300
- const candidates = candidateNames
301
- .filter(n => n && n !== ownName && n.length >= 2 && !reserved.has(n))
302
- .sort((a, b) => b.length - a.length)
303
- if (candidates.length === 0) return []
304
-
305
- const pattern = new RegExp(`(?:^|[^A-Za-z0-9_$])(${candidates.map(escapeRegex).join('|')})(?=[^A-Za-z0-9_$]|$)`, 'g')
478
+ const tokenRe = /[A-Za-z_$][A-Za-z0-9_$]*/g
306
479
  const seen = new Set<string>()
307
480
  let m: RegExpExecArray | null
308
- while ((m = pattern.exec(source)) !== null) {
309
- seen.add(m[1])
481
+ while ((m = tokenRe.exec(source)) !== null) {
482
+ const name = m[0].toLowerCase()
483
+ if (name === ownName || name.length < 2 || reserved.has(name) || !candidateSet.has(name)) continue
484
+ seen.add(name)
310
485
  }
311
486
  return [...seen]
312
487
  }
488
+ // CIL[DOC-VECTOR type="context" content="purpose='Find token references to a candidate set in source text'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
489
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
490
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
491
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
492
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
493
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
494
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:extractSymbolReferences:function"]
313
495
 
314
496
 
315
497
 
316
498
 
317
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractsymbolreferences_1784235266"]
318
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractexports_1784235266" type="function" identity="extractexports" parent="none"]
319
- // CIL[DOC-MACRO purpose="Implements extractexports logic in cortex.functions.custom_cil-callmap"]
320
- // CIL[DOC-RESPONSIBILITY responsibility="Execute extractexports and return its computed result"]
321
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[]"]
322
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
323
- // CIL[DOC-MICRO logic_summary="Provides extractexports with extractExports(source: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
324
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
499
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:extractExports:function" type="function" identity="extractExports" parent="~/.framework/functions/cil-callmap.ts"]
500
+ // CIL[DOC-MACRO purpose="Parse exported declarations from source text"]
501
+ // CIL[DOC-RESPONSIBILITY responsibility="Return the list of exported names including named re-exports"]
502
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
503
+ // CIL[DOC-CONTRACT inputs="source string" outputs="string[] of exported identifiers" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
504
+ // CIL[DOC-MICRO logic_summary="Regex matches export declarations and export blocks, resolving aliases" notable_decisions="[]"]
505
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
325
506
  // CIL[DOC-STABILITY stability="stable"]
326
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
327
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
328
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
329
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
330
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
331
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
507
+
332
508
  export function extractExports(source: string): string[] {
333
509
  const exports: string[] = []
334
510
 
@@ -345,6 +521,13 @@ export function extractExports(source: string): string[] {
345
521
  }
346
522
  return [...new Set(exports)]
347
523
  }
524
+ // CIL[DOC-VECTOR type="context" content="purpose='Parse exported declarations from source text'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
525
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
526
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
527
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
528
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
529
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
530
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:extractExports:function"]
348
531
 
349
532
 
350
533
 
@@ -354,21 +537,15 @@ export function extractExports(source: string): string[] {
354
537
 
355
538
 
356
539
 
357
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_extractexports_1784235266"]
358
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_resolveimportpath_1784235266" type="function" identity="resolveimportpath" parent="none"]
359
- // CIL[DOC-MACRO purpose="Implements resolveimportpath logic in cortex.functions.custom_cil-callmap"]
360
- // CIL[DOC-RESPONSIBILITY responsibility="Execute resolveimportpath and return its computed result"]
361
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[]"]
362
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
363
- // CIL[DOC-MICRO logic_summary="Provides resolveimportpath with resolveImportPath(fromFilePath: string, importSpecifier: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
364
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
540
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:resolveImportPath:function" type="function" identity="resolveImportPath" parent="~/.framework/functions/cil-callmap.ts"]
541
+ // CIL[DOC-MACRO purpose="Resolve a relative import specifier to a project file path"]
542
+ // CIL[DOC-RESPONSIBILITY responsibility="Convert a local import specifier to a normalised project-relative base path"]
543
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
544
+ // CIL[DOC-CONTRACT inputs="fromFilePath, importSpecifier" outputs="string | null" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
545
+ // CIL[DOC-MICRO logic_summary="Normalises '.' and '..' segments relative to the importing file and returns the base path" notable_decisions="[]"]
546
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
365
547
  // CIL[DOC-STABILITY stability="stable"]
366
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
367
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
368
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
369
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
370
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
371
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
548
+
372
549
  function resolveImportPath(fromFilePath: string, importSpecifier: string): string | null {
373
550
 
374
551
  if (!importSpecifier.startsWith('.')) return null
@@ -386,26 +563,27 @@ function resolveImportPath(fromFilePath: string, importSpecifier: string): strin
386
563
 
387
564
  return base
388
565
  }
566
+ // CIL[DOC-VECTOR type="context" content="purpose='Resolve a relative import specifier to a project file path'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
567
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
568
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
569
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
570
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
571
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
572
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:resolveImportPath:function"]
389
573
 
390
574
 
391
575
 
392
576
 
393
577
 
394
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_resolveimportpath_1784235266"]
395
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_upsertlink_1784235266" type="function" identity="upsertlink" parent="none"]
396
- // CIL[DOC-MACRO purpose="Implements upsertlink logic in cortex.functions.custom_cil-callmap"]
397
- // CIL[DOC-RESPONSIBILITY responsibility="Execute upsertlink and return its computed result"]
398
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[]"]
399
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
400
- // CIL[DOC-MICRO logic_summary="Provides upsertlink with upsertLink( inputs, handling internal flow and returning a result" notable_decisions="[]"]
401
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
578
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:upsertLink:function" type="function" identity="upsertLink" parent="~/.framework/functions/cil-callmap.ts"]
579
+ // CIL[DOC-MACRO purpose="Create a single link if no matching link already exists"]
580
+ // CIL[DOC-RESPONSIBILITY responsibility="Insert a link record between a source and target item for a given link type"]
581
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
582
+ // CIL[DOC-CONTRACT inputs="ctx, sourceItem, targetItem, linkTypeId, metadata" outputs="boolean indicating created" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
583
+ // CIL[DOC-MICRO logic_summary="Checks for an existing link and calls adminCreate when none is found" notable_decisions="[]"]
584
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
402
585
  // CIL[DOC-STABILITY stability="stable"]
403
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
404
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
405
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
406
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
407
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
408
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
586
+
409
587
  export async function upsertLink(
410
588
  ctx: any,
411
589
  sourceItem: any,
@@ -413,20 +591,22 @@ export async function upsertLink(
413
591
  linkTypeId: string,
414
592
  metadata: Record<string, any> = {}
415
593
  ): Promise<boolean> {
416
-
594
+
595
+ const sourceType = sourceItem.data?.kb_type
596
+ const targetType = targetItem.data?.kb_type
597
+ if (!sourceType || !targetType) return false
598
+
417
599
  const { data: existing } = await adminDb
418
600
  .from('links')
419
601
  .select('id')
602
+ .eq('source_type', sourceType)
420
603
  .eq('source_id', sourceItem.id)
604
+ .eq('target_type', targetType)
421
605
  .eq('target_id', targetItem.id)
422
606
  .eq('link_type_id', linkTypeId)
423
607
  .maybeSingle()
424
608
 
425
- if (existing) return false
426
-
427
- const sourceType = sourceItem.data?.kb_type
428
- const targetType = targetItem.data?.kb_type
429
- if (!sourceType || !targetType) return false
609
+ if (existing) return false
430
610
 
431
611
  try {
432
612
  await adminCreate(ctx, {
@@ -445,32 +625,36 @@ export async function upsertLink(
445
625
  return false
446
626
  }
447
627
  }
628
+ // CIL[DOC-VECTOR type="context" content="purpose='Create a single link if no matching link already exists'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
629
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
630
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
631
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
632
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
633
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
634
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:upsertLink:function"]
448
635
 
449
636
 
450
637
 
451
638
 
452
639
 
453
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_upsertlink_1784235266"]
454
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_clearprojectlinks_1784235266" type="function" identity="clearprojectlinks" parent="none"]
640
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:clearProjectLinks:function" type="function" identity="clearProjectLinks" parent="~/.framework/functions/cil-callmap.ts"]
641
+ // CIL[DOC-MACRO purpose="Delete all cil links for a project in batches"]
642
+ // CIL[DOC-RESPONSIBILITY responsibility="Remove import, call and export links tied to a project's file and chunk items"]
643
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
644
+ // CIL[DOC-CONTRACT inputs="projectId, linkTypeIds" outputs="number of deleted links" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
645
+ // CIL[DOC-MICRO logic_summary="Collects file and chunk ids, then deletes links in UUID_IN_LIMIT sized IN batches" notable_decisions="[]"]
646
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
647
+ // CIL[DOC-STABILITY stability="stable"]
648
+
455
649
  async function clearProjectLinks(projectId: string, linkTypeIds: string[]): Promise<number> {
456
- const [{ data: fileItems }, { data: chunkItems }] = await Promise.all([
457
- adminDb
458
- .from('items')
459
- .select('id')
460
- .filter('data->>project_id', 'eq', projectId)
461
- .filter('data->>kb_type', 'eq', 'cil_file')
462
- .eq('is_active', true),
463
- adminDb
464
- .from('items')
465
- .select('id')
466
- .filter('data->>project_id', 'eq', projectId)
467
- .filter('data->>kb_type', 'eq', 'cil_chunk')
468
- .eq('is_active', true),
650
+ const [fileItems, chunkItems] = await Promise.all([
651
+ fetchAllProjectRecords(projectId, 'cil_file'),
652
+ fetchAllProjectRecords(projectId, 'cil_chunk'),
469
653
  ])
470
654
 
471
655
  const ids = [
472
- ...(fileItems || []).map((f: any) => f.id),
473
- ...(chunkItems || []).map((c: any) => c.id),
656
+ ...fileItems.map((f: any) => f.id),
657
+ ...chunkItems.map((c: any) => c.id),
474
658
  ]
475
659
  if (!ids.length) return 0
476
660
 
@@ -488,27 +672,28 @@ async function clearProjectLinks(projectId: string, linkTypeIds: string[]): Prom
488
672
  }
489
673
  return deleted
490
674
  }
491
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_clearprojectlinks_1784235266"]
492
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_mapfile_1784235266" type="function" identity="mapfile" parent="none"]
493
- // CIL[DOC-MACRO purpose="Implements mapfile logic in cortex.functions.custom_cil-callmap"]
494
- // CIL[DOC-RESPONSIBILITY responsibility="Execute mapfile and return its computed result"]
495
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[]"]
496
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
497
- // CIL[DOC-MICRO logic_summary="Provides mapfile with mapFile( inputs, handling internal flow and returning a result" notable_decisions="[]"]
498
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
499
- // CIL[DOC-STABILITY stability="stable"]
500
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
501
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
502
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
503
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
675
+ // CIL[DOC-VECTOR type="context" content="purpose='Delete all cil links for a project in batches'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
676
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
677
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
678
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
504
679
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
505
680
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
681
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:clearProjectLinks:function"]
682
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:mapFile:function" type="function" identity="mapFile" parent="~/.framework/functions/cil-callmap.ts"]
683
+ // CIL[DOC-MACRO purpose="Create import, call and export links for a single file"]
684
+ // CIL[DOC-RESPONSIBILITY responsibility="Map a file's chunks and full content to related files and chunks"]
685
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
686
+ // CIL[DOC-CONTRACT inputs="ctx, fileItem, projectId, allChunksByFile, chunksByNameArg, fileItemsByPath, importsLinkTypeId, callsLinkTypeId, exportsLinkTypeId" outputs="{imports_created, calls_created, exports_created}" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
687
+ // CIL[DOC-MICRO logic_summary="Extracts calls and symbols per chunk, imports per file, and exports back to the file item" notable_decisions="[]"]
688
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
689
+ // CIL[DOC-STABILITY stability="stable"]
690
+
506
691
  export async function mapFile(
507
692
  ctx: any,
508
693
  fileItem: any,
509
694
  projectId: string,
510
695
  allChunksByFile: Map<string, any[]>,
511
- chunksByName: Map<string, any>,
696
+ chunksByNameArg: Map<string, any>,
512
697
  fileItemsByPath: Map<string, any>,
513
698
  importsLinkTypeId: string,
514
699
  callsLinkTypeId: string,
@@ -517,10 +702,14 @@ export async function mapFile(
517
702
  let importsCreated = 0, callsCreated = 0, exportsCreated = 0
518
703
 
519
704
  const filePath: string = fileItem.data?.file_path || fileItem.title
520
- const chunksInFile = allChunksByFile.get(fileItem.id) || []
705
+ const chunksInFile = allChunksByFile.get(filePath) || []
521
706
 
522
-
707
+ const chunksByName = new Map<string, any>()
708
+ for (const [name, chunk] of chunksByNameArg.entries()) {
709
+ if (name) chunksByName.set(name.toLowerCase(), chunk)
710
+ }
523
711
  const allChunkNames = Array.from(chunksByName.keys())
712
+ const candidateSet = new Set(allChunkNames)
524
713
 
525
714
  for (const chunk of chunksInFile) {
526
715
  const codeContent: string = chunk.data?.code_content || ''
@@ -528,27 +717,41 @@ export async function mapFile(
528
717
 
529
718
 
530
719
  const calls = extractCalls(codeContent)
531
- for (const call of calls) {
532
- const targetChunk = chunksByName.get(call.callee_name)
533
- if (!targetChunk || targetChunk.id === chunk.id) continue
534
- const created = await upsertLink(ctx, chunk, targetChunk, callsLinkTypeId, {
535
- callee_name: call.callee_name,
536
- is_await: call.is_await,
720
+ const callPromises = calls
721
+ .filter((call) => {
722
+ const targetChunk = chunksByName.get(call.callee_name.toLowerCase())
723
+ return targetChunk && targetChunk.id !== chunk.id
537
724
  })
538
- if (created) callsCreated++
539
- }
725
+ .map((call) => {
726
+ const targetChunk = chunksByName.get(call.callee_name.toLowerCase())!
727
+ const callMetadata: Record<string, any> = {
728
+ callee_name: call.callee_name,
729
+ is_await: call.is_await,
730
+ }
731
+ if (chunk.data?.version_id) callMetadata.version_id = chunk.data.version_id
732
+ return upsertLink(ctx, chunk, targetChunk, callsLinkTypeId, callMetadata)
733
+ })
734
+ const callResults = await Promise.all(callPromises)
735
+ callsCreated += callResults.filter(Boolean).length
540
736
 
541
737
 
542
- const symbolRefs = extractSymbolReferences(codeContent, allChunkNames, chunk.data?.chunk_name || '')
543
- for (const refName of symbolRefs) {
544
- const targetChunk = chunksByName.get(refName)
545
- if (!targetChunk || targetChunk.id === chunk.id) continue
546
- const created = await upsertLink(ctx, chunk, targetChunk, callsLinkTypeId, {
547
- callee_name: refName,
548
- is_symbol_reference: true,
738
+ const symbolRefs = extractSymbolReferences(codeContent, candidateSet, (chunk.data?.chunk_name || '').toLowerCase())
739
+ const refPromises = symbolRefs
740
+ .filter((refName) => {
741
+ const targetChunk = chunksByName.get(refName.toLowerCase())
742
+ return targetChunk && targetChunk.id !== chunk.id
549
743
  })
550
- if (created) callsCreated++
551
- }
744
+ .map((refName) => {
745
+ const targetChunk = chunksByName.get(refName.toLowerCase())!
746
+ const refMetadata: Record<string, any> = {
747
+ callee_name: refName,
748
+ is_symbol_reference: true,
749
+ }
750
+ if (chunk.data?.version_id) refMetadata.version_id = chunk.data.version_id
751
+ return upsertLink(ctx, chunk, targetChunk, callsLinkTypeId, refMetadata)
752
+ })
753
+ const refResults = await Promise.all(refPromises)
754
+ callsCreated += refResults.filter(Boolean).length
552
755
  }
553
756
 
554
757
 
@@ -556,62 +759,71 @@ export async function mapFile(
556
759
  const fullFileContent = chunksInFile.map((c: any) => c.data?.code_content || '').join('\n')
557
760
  const imports = extractImports(fullFileContent)
558
761
 
559
- for (const imp of imports) {
560
- const resolvedBase = resolveImportPath(filePath, imp.from_path)
561
- if (!resolvedBase) continue
762
+ const importPromises = imports
763
+ .map((imp) => {
764
+ const resolvedBase = resolveImportPath(filePath, imp.from_path)
765
+ if (!resolvedBase) return null
562
766
 
563
-
564
- const targetFile =
565
- fileItemsByPath.get(resolvedBase) ||
566
- fileItemsByPath.get(resolvedBase + '.ts') ||
567
- fileItemsByPath.get(resolvedBase + '.tsx') ||
568
- fileItemsByPath.get(resolvedBase + '/index.ts') ||
569
- fileItemsByPath.get(resolvedBase + '/index.tsx')
570
-
571
- if (!targetFile || targetFile.id === fileItem.id) continue
572
-
573
- const created = await upsertLink(ctx, fileItem, targetFile, importsLinkTypeId, {
574
- symbols: imp.symbols,
575
- is_default: imp.is_default,
576
- specifier: imp.from_path,
767
+
768
+ const targetFile =
769
+ fileItemsByPath.get(resolvedBase) ||
770
+ fileItemsByPath.get(resolvedBase + '.ts') ||
771
+ fileItemsByPath.get(resolvedBase + '.tsx') ||
772
+ fileItemsByPath.get(resolvedBase + '/index.ts') ||
773
+ fileItemsByPath.get(resolvedBase + '/index.tsx')
774
+
775
+ if (!targetFile || targetFile.id === fileItem.id) return null
776
+
777
+ const importMetadata: Record<string, any> = {
778
+ symbols: imp.symbols,
779
+ is_default: imp.is_default,
780
+ specifier: imp.from_path,
781
+ }
782
+ if (fileItem.data?.version_id) importMetadata.version_id = fileItem.data.version_id
783
+ return upsertLink(ctx, fileItem, targetFile, importsLinkTypeId, importMetadata)
577
784
  })
578
- if (created) importsCreated++
579
- }
785
+ .filter((p): p is Promise<boolean> => p !== null)
786
+ const importResults = await Promise.all(importPromises)
787
+ importsCreated += importResults.filter(Boolean).length
580
788
 
581
789
 
582
790
  const exportedNames = extractExports(fullFileContent)
583
- for (const exportedName of exportedNames) {
584
- const chunk = chunksByName.get(exportedName)
585
- if (!chunk) continue
586
- const created = await upsertLink(ctx, chunk, fileItem, exportsLinkTypeId, {
587
- exported_name: exportedName,
791
+ const exportPromises = exportedNames
792
+ .map((exportedName) => {
793
+ const chunk = chunksByName.get(exportedName.toLowerCase())
794
+ if (!chunk) return null
795
+ return upsertLink(ctx, chunk, fileItem, exportsLinkTypeId, {
796
+ exported_name: exportedName,
797
+ })
588
798
  })
589
- if (created) exportsCreated++
590
- }
799
+ .filter((p): p is Promise<boolean> => p !== null)
800
+ const exportResults = await Promise.all(exportPromises)
801
+ exportsCreated += exportResults.filter(Boolean).length
591
802
 
592
803
  return { imports_created: importsCreated, calls_created: callsCreated, exports_created: exportsCreated }
593
804
  }
805
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:mapFile:function"]
594
806
 
595
807
 
596
808
 
809
+ // CIL[DOC-VECTOR type="context" content="purpose='Create import, call and export links for a single file'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
810
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
811
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
812
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
813
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
814
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
597
815
 
598
816
 
599
817
 
600
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_mapfile_1784235266"]
601
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_markfilepass4bcomplete_1784235266" type="function" identity="markfilepass4bcomplete" parent="none"]
602
- // CIL[DOC-MACRO purpose="Implements markfilepass4bcomplete logic in cortex.functions.custom_cil-callmap"]
603
- // CIL[DOC-RESPONSIBILITY responsibility="Execute markfilepass4bcomplete and return its computed result"]
604
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[]"]
605
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
606
- // CIL[DOC-MICRO logic_summary="Provides markfilepass4bcomplete with markFilePass4bComplete( inputs, handling internal flow and returning a result" notable_decisions="[]"]
607
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
818
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:markFilePass4bComplete:function" type="function" identity="markFilePass4bComplete" parent="~/.framework/functions/cil-callmap.ts"]
819
+ // CIL[DOC-MACRO purpose="Advance a file to the embedded-mapped pipeline status"]
820
+ // CIL[DOC-RESPONSIBILITY responsibility="Update the file item and project tree status after mapping completes"]
821
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
822
+ // CIL[DOC-CONTRACT inputs="ctx, fileItem, tree, secondPass, projectItem" outputs="void" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
823
+ // CIL[DOC-MICRO logic_summary="Skips files before 6-enriched, updates file status, advances project file_statuses and mutates projectItem" notable_decisions="[]"]
824
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
608
825
  // CIL[DOC-STABILITY stability="stable"]
609
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
610
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
611
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
612
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
613
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
614
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
826
+
615
827
  async function markFilePass4bComplete(
616
828
  ctx: any,
617
829
  fileItem: any,
@@ -619,12 +831,18 @@ async function markFilePass4bComplete(
619
831
  secondPass = false,
620
832
  projectItem?: any
621
833
  ): Promise<void> {
622
- const cil_file_status = secondPass ? 'pass8_complete' : 'pass4b_complete'
623
- const pipeline_status = secondPass ? '10-mapped' : '7-mapped'
834
+ const cil_file_status: FileStatus = secondPass ? '7-embedded-mapped' : '7-embedded-mapped'
835
+ const pipeline_status: FileStatus = secondPass ? '7-embedded-mapped' : '7-embedded-mapped'
624
836
  const currentFileStatus = getFileStatus(fileItem)
625
837
  const filePath: string = fileItem.data?.file_path
626
838
 
627
839
 
840
+ if (rank(currentFileStatus) < rank('6-enriched')) {
841
+ console.error(`markFilePass4bComplete skipped ${filePath}: current status ${currentFileStatus} is before 6-enriched`)
842
+ return
843
+ }
844
+
845
+
628
846
  if (rank(currentFileStatus) < rank(cil_file_status)) {
629
847
  const updateCtx = { ...ctx, query: { ...(ctx.query || {}), entity: 'items', id: fileItem.id } }
630
848
  await adminUpdate(updateCtx, {
@@ -670,68 +888,70 @@ async function markFilePass4bComplete(
670
888
  projectItem.data.file_statuses = fileStatuses
671
889
  }
672
890
  }
891
+ // CIL[DOC-VECTOR type="context" content="purpose='Advance a file to the embedded-mapped pipeline status'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
892
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
893
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
894
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
895
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
896
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
897
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:markFilePass4bComplete:function"]
673
898
 
674
899
 
675
900
 
676
901
 
677
902
 
678
903
 
679
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_markfilepass4bcomplete_1784235266"]
680
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_istestfile_1784235266" type="function" identity="istestfile" parent="none"]
681
- // CIL[DOC-MACRO purpose="Implements istestfile logic in cortex.functions.custom_cil-callmap"]
682
- // CIL[DOC-RESPONSIBILITY responsibility="Execute istestfile and return its computed result"]
683
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[]"]
684
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
685
- // CIL[DOC-MICRO logic_summary="Provides istestfile with isTestFile(filePath: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
686
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
904
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:isTestFile:function" type="function" identity="isTestFile" parent="~/.framework/functions/cil-callmap.ts"]
905
+ // CIL[DOC-MACRO purpose="Detect whether a file path is a test file"]
906
+ // CIL[DOC-RESPONSIBILITY responsibility="Return true for paths that look like unit, spec or E2E tests"]
907
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
908
+ // CIL[DOC-CONTRACT inputs="filePath" outputs="boolean" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
909
+ // CIL[DOC-MICRO logic_summary="Tests the path against common test, __tests__ and tests directory patterns" notable_decisions="[]"]
910
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
687
911
  // CIL[DOC-STABILITY stability="stable"]
688
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
689
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
690
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
691
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
692
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
693
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
912
+
694
913
  function isTestFile(filePath: string): boolean {
695
914
  return /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filePath) ||
696
915
  /\/__tests__\//.test(filePath) ||
697
916
  /\/tests?\//.test(filePath)
698
917
  }
918
+ // CIL[DOC-VECTOR type="context" content="purpose='Detect whether a file path is a test file'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
919
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
920
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
921
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
922
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
923
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
924
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:isTestFile:function"]
699
925
 
700
926
 
701
927
 
702
928
 
703
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_istestfile_1784235266"]
704
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_maptests_1784235266" type="function" identity="maptests" parent="none"]
705
- // CIL[DOC-MACRO purpose="Implements maptests logic in cortex.functions.custom_cil-callmap"]
706
- // CIL[DOC-RESPONSIBILITY responsibility="Execute maptests and return its computed result"]
707
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[]"]
708
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
709
- // CIL[DOC-MICRO logic_summary="Provides maptests with mapTests( inputs, handling internal flow and returning a result" notable_decisions="[]"]
710
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
929
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:mapTests:function" type="function" identity="mapTests" parent="~/.framework/functions/cil-callmap.ts"]
930
+ // CIL[DOC-MACRO purpose="Create tested_by links between chunks and test files"]
931
+ // CIL[DOC-RESPONSIBILITY responsibility="Scan test files, match chunk names and upsert tested_by links and test path fields"]
932
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="function" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
933
+ // CIL[DOC-CONTRACT inputs="ctx, projectId, repoPath, testedByLinkTypeId, chunksByNameArg" outputs="{test_files_scanned, tested_by_links_created, chunks_updated, errors}" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
934
+ // CIL[DOC-MICRO logic_summary="Reads test sources, matches imported names, describe/it strings and calls, then links and updates chunk test paths" notable_decisions="[]"]
935
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
711
936
  // CIL[DOC-STABILITY stability="stable"]
712
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
713
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
714
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
715
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
716
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
717
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
937
+
718
938
  async function mapTests(
719
939
  ctx: any,
720
940
  projectId: string,
721
941
  repoPath: string,
722
942
  testedByLinkTypeId: string,
723
- chunksByName: Map<string, any>
943
+ chunksByNameArg: Map<string, any>
724
944
  ): Promise<{ test_files_scanned: number; tested_by_links_created: number; chunks_updated: number; errors: string[] }> {
945
+ const chunksByName = new Map<string, any>()
946
+ for (const [name, chunk] of chunksByNameArg.entries()) {
947
+ if (name) chunksByName.set(name.toLowerCase(), chunk)
948
+ }
725
949
  const errors: string[] = []
726
950
  let testFilesScanned = 0, linksCreated = 0, chunksUpdated = 0
727
951
 
728
- const { data: allFiles } = await adminDb
729
- .from('items').select('id, title, data')
730
- .filter('data->>project_id', 'eq', projectId)
731
- .filter('data->>kb_type', 'eq', 'cil_file')
732
- .eq('is_active', true)
952
+ const allFiles = await fetchAllProjectRecords(projectId, 'cil_file')
733
953
 
734
- const testFiles = (allFiles || []).filter((f: any) => isTestFile(f.data?.file_path || f.title))
954
+ const testFiles = allFiles.filter((f: any) => isTestFile(f.data?.file_path || f.title))
735
955
 
736
956
  const matchesByFile = new Map<string, Set<string>>()
737
957
  const allMatchedNames = new Set<string>()
@@ -752,7 +972,7 @@ async function mapTests(
752
972
  while ((m = importRe.exec(source)) !== null) {
753
973
  const names = m[1].split(',').map(s => s.trim().split(/\s+as\s+/).shift()!.trim()).filter(Boolean)
754
974
  for (const n of names) {
755
- if (chunksByName.has(n)) matchedChunkNames.add(n)
975
+ if (chunksByName.has(n.toLowerCase())) matchedChunkNames.add(n.toLowerCase())
756
976
  }
757
977
  }
758
978
 
@@ -760,13 +980,13 @@ async function mapTests(
760
980
  while ((m = stringRe.exec(source)) !== null) {
761
981
  const words = m[1].split(/\W+/)
762
982
  for (const word of words) {
763
- if (chunksByName.has(word)) matchedChunkNames.add(word)
983
+ if (chunksByName.has(word.toLowerCase())) matchedChunkNames.add(word.toLowerCase())
764
984
  }
765
985
  }
766
986
 
767
987
  const callRe = /\b(\w{3,})\s*\(/g
768
988
  while ((m = callRe.exec(source)) !== null) {
769
- const name = m[1]
989
+ const name = m[1].toLowerCase()
770
990
  if (chunksByName.has(name)) matchedChunkNames.add(name)
771
991
  }
772
992
 
@@ -788,7 +1008,7 @@ async function mapTests(
788
1008
  .in('id', matchedIds.slice(i, i + UUID_IN_LIMIT))
789
1009
  for (const c of data || []) {
790
1010
  const name = c.data?.chunk_name
791
- if (name) fullChunksByName.set(name, c)
1011
+ if (name) fullChunksByName.set(name.toLowerCase(), c)
792
1012
  }
793
1013
  }
794
1014
 
@@ -823,26 +1043,27 @@ async function mapTests(
823
1043
 
824
1044
  return { test_files_scanned: testFilesScanned, tested_by_links_created: linksCreated, chunks_updated: chunksUpdated, errors }
825
1045
  }
1046
+ // CIL[DOC-VECTOR type="context" content="purpose='Create tested_by links between chunks and test files'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
1047
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1048
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1049
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1050
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1051
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1052
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:mapTests:function"]
826
1053
 
827
1054
 
828
1055
 
829
1056
 
830
1057
 
831
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_maptests_1784235266"]
832
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_callmap_handler_1784235266" type="variable" identity="handler" parent="none"]
833
- // CIL[DOC-MACRO purpose="Defines handler configuration or state in cortex.functions.custom_cil-callmap"]
834
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for handler"]
835
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-callmap" layer="function" related_files="[]"]
836
- // CIL[DOC-CONTRACT inputs="none" outputs="value of handler" errors="none" side_effects="none"]
837
- // CIL[DOC-MICRO logic_summary="Declares handler with initial value or constant binding used by cortex.functions.custom_cil-callmap" notable_decisions="[]"]
838
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1058
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-callmap.ts:handler:constant" type="constant" identity="handler" parent="~/.framework/functions/cil-callmap.ts"]
1059
+ // CIL[DOC-MACRO purpose="Expose the CIL callmap Netlify function handler"]
1060
+ // CIL[DOC-RESPONSIBILITY responsibility="Dispatch map_project, map_file, map_tests, status and clear actions"]
1061
+ // CIL[DOC-CONTEXT module=".framework/functions/cil-callmap" layer="constant" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/resolve-ids.ts,.framework/functions/admin-data.ts,.framework/functions/cil-callmap.ts"]
1062
+ // CIL[DOC-CONTRACT inputs="ctx, body, typeId, ids" outputs="JSON response object" errors="throws or returns error strings" side_effects="reads/writes CIL items and links via adminDb and admin-data"]
1063
+ // CIL[DOC-MICRO logic_summary="createHandler that resolves link type ids, queries chunks/files, calls mapFile/mapTests and returns counts" notable_decisions="[]"]
1064
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
839
1065
  // CIL[DOC-STABILITY stability="stable"]
840
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
841
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
842
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
843
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
844
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
845
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1066
+
846
1067
  export const handler = createHandler(async (ctx, body) => {
847
1068
  const action = ctx.query?.action
848
1069
 
@@ -851,43 +1072,35 @@ export const handler = createHandler(async (ctx, body) => {
851
1072
  const projectId = ctx.query?.project_id || body?.project_id
852
1073
  if (!projectId) throw new Error('project_id is required')
853
1074
 
854
- const [importsTypeId, callsTypeId, exportsTypeId, testedByTypeId] = await Promise.all([
855
- resolveLinkTypeId('cil_imports').catch(() => null),
856
- resolveLinkTypeId('cil_calls').catch(() => null),
857
- resolveLinkTypeId('cil_exports').catch(() => null),
858
- resolveLinkTypeId('cil_tested_by').catch(() => null),
859
- ])
860
-
861
- const { data: fileItems } = await adminDb
862
- .from('items')
863
- .select('id')
864
- .filter('data->>project_id', 'eq', projectId)
865
- .filter('data->>kb_type', 'eq', 'cil_file')
1075
+ const linkTypeIds = await resolveLinkTypeIds(['cil_imports','cil_calls','cil_exports','cil_tested_by'])
1076
+ const importsTypeId = linkTypeIds['cil_imports'] ?? null
1077
+ const callsTypeId = linkTypeIds['cil_calls'] ?? null
1078
+ const exportsTypeId = linkTypeIds['cil_exports'] ?? null
1079
+ const testedByTypeId = linkTypeIds['cil_tested_by'] ?? null
866
1080
 
867
- const { data: chunkItems } = await adminDb
868
- .from('items')
869
- .select('id')
870
- .filter('data->>project_id', 'eq', projectId)
871
- .filter('data->>kb_type', 'eq', 'cil_chunk')
1081
+ const fileItems = await fetchAllProjectRecords(projectId, 'cil_file')
1082
+ const chunkItems = await fetchAllProjectRecords(projectId, 'cil_chunk')
872
1083
 
873
- const fileIds = (fileItems || []).map((f: any) => f.id)
874
- const chunkIds = (chunkItems || []).map((c: any) => c.id)
1084
+ const fileIds = fileItems.map((f: any) => f.id)
1085
+ const chunkIds = chunkItems.map((c: any) => c.id)
875
1086
 
876
- async function countLinksForIds(typeId: string, ids: string[]): Promise<number> {
1087
+ async function countLinksForIds(typeId: string, ids: string[], batchSize = UUID_IN_LIMIT): Promise<number> {
877
1088
  if (!typeId || !ids.length) return 0
878
1089
  let total = 0
879
- for (let i = 0; i < ids.length; i += UUID_IN_LIMIT) {
1090
+ for (let i = 0; i < ids.length; i += batchSize) {
880
1091
  const { count } = await adminDb.from('links').select('id', { count: 'exact' })
881
- .eq('link_type_id', typeId).in('source_id', ids.slice(i, i + UUID_IN_LIMIT))
1092
+ .eq('link_type_id', typeId).in('source_id', ids.slice(i, i + batchSize))
882
1093
  total += count || 0
883
1094
  }
884
1095
  return total
885
1096
  }
886
1097
 
887
- const importCount = await countLinksForIds(importsTypeId, fileIds)
888
- const callCount = await countLinksForIds(callsTypeId, chunkIds)
889
- const exportCount = await countLinksForIds(exportsTypeId, chunkIds)
890
- const testedByCount = await countLinksForIds(testedByTypeId, chunkIds)
1098
+ const [importCount, callCount, exportCount, testedByCount] = await Promise.all([
1099
+ countLinksForIds(importsTypeId, fileIds),
1100
+ countLinksForIds(callsTypeId, chunkIds),
1101
+ countLinksForIds(exportsTypeId, chunkIds),
1102
+ countLinksForIds(testedByTypeId, chunkIds),
1103
+ ])
891
1104
 
892
1105
  return {
893
1106
  project_id: projectId,
@@ -906,11 +1119,10 @@ export const handler = createHandler(async (ctx, body) => {
906
1119
  const projectId = body?.project_id
907
1120
  if (!projectId) throw new Error('project_id is required')
908
1121
 
909
- const [importsTypeId, callsTypeId, exportsTypeId] = await Promise.all([
910
- resolveLinkTypeId('cil_imports').catch(() => null),
911
- resolveLinkTypeId('cil_calls').catch(() => null),
912
- resolveLinkTypeId('cil_exports').catch(() => null),
913
- ])
1122
+ const clearLinkTypeIds = await resolveLinkTypeIds(['cil_imports','cil_calls','cil_exports']).catch(() => ({} as Record<string, string>))
1123
+ const importsTypeId = clearLinkTypeIds['cil_imports'] ?? null
1124
+ const callsTypeId = clearLinkTypeIds['cil_calls'] ?? null
1125
+ const exportsTypeId = clearLinkTypeIds['cil_exports'] ?? null
914
1126
 
915
1127
  const { data: chunkItems } = await adminDb
916
1128
  .from('items').select('id')
@@ -941,16 +1153,16 @@ export const handler = createHandler(async (ctx, body) => {
941
1153
 
942
1154
  let resetCount = 0
943
1155
  for (const fileItem of fileItems || []) {
944
- if (getFileStatus(fileItem) === 'pass4b_complete') {
1156
+ if (getFileStatus(fileItem) === '7-embedded-mapped' || getFileStatus(fileItem) === '7-embedded-mapped') {
945
1157
  const updateCtx = { ...ctx, query: { ...(ctx.query || {}), entity: 'items', id: fileItem.id } }
946
1158
  await adminUpdate(updateCtx, {
947
1159
  data: {
948
1160
  ...fileItem.data,
949
- status: 'pass3_complete',
1161
+ status: '3-documented',
950
1162
  last_status_at: new Date().toISOString(),
951
1163
  },
952
1164
  }).catch((e: any) => console.error(`reset status ${fileItem.id}: ${e.message}`))
953
- if (fileTree) updateTreeNodeStatus(fileTree, fileItem.id, 'pass3_complete')
1165
+ if (fileTree) updateTreeNodeStatus(fileTree, fileItem.id, '3-documented')
954
1166
  resetCount++
955
1167
  }
956
1168
  }
@@ -973,35 +1185,29 @@ export const handler = createHandler(async (ctx, body) => {
973
1185
  const projectId = fileItem.data?.project_id
974
1186
  if (!projectId) throw new Error('File has no project_id')
975
1187
 
976
- const [importsTypeId, callsTypeId, exportsTypeId] = await Promise.all([
977
- resolveLinkTypeId('cil_imports'),
978
- resolveLinkTypeId('cil_calls'),
979
- resolveLinkTypeId('cil_exports'),
980
- ])
1188
+ const fileLinkTypeIds = await resolveLinkTypeIds(['cil_imports','cil_calls','cil_exports'])
1189
+ const importsTypeId = fileLinkTypeIds['cil_imports']
1190
+ const callsTypeId = fileLinkTypeIds['cil_calls']
1191
+ const exportsTypeId = fileLinkTypeIds['cil_exports']
981
1192
 
982
1193
 
983
- const { data: allFiles } = await adminDb
984
- .from('items').select('id, title, data')
985
- .filter('data->>project_id', 'eq', projectId)
986
- .filter('data->>kb_type', 'eq', 'cil_file').eq('is_active', true)
987
-
988
- const { data: allChunks } = await adminDb
989
- .from('items').select('id, title, data')
990
- .filter('data->>project_id', 'eq', projectId)
991
- .filter('data->>kb_type', 'eq', 'cil_chunk').eq('is_active', true)
1194
+ const [allFiles, allChunkNames, fileChunks] = await Promise.all([
1195
+ fetchAllProjectRecords(projectId, 'cil_file'),
1196
+ fetchAllProjectChunkNames(projectId),
1197
+ fetchFileChunks(projectId, fileItem.data?.file_path || fileItem.title),
1198
+ ])
992
1199
 
993
1200
  const fileItemsByPath = new Map((allFiles || []).map((f: any) => [f.data?.file_path || f.title, f]))
994
- const chunksByName = new Map((allChunks || []).map((c: any) => [c.data?.chunk_name || '', c]))
995
- const allChunksByFile = new Map<string, any[]>()
996
- for (const c of allChunks || []) {
997
- const fid = c.data?.file_id
998
- if (!fid) continue
999
- if (!allChunksByFile.has(fid)) allChunksByFile.set(fid, [])
1000
- allChunksByFile.get(fid)!.push(c)
1201
+ const chunksByName = new Map<string, any>()
1202
+ for (const c of allChunkNames) {
1203
+ if (c.chunk_name) chunksByName.set(c.chunk_name.toLowerCase(), { id: c.id, data: { chunk_name: c.chunk_name, kb_type: c.kb_type || 'cil_chunk' } })
1001
1204
  }
1205
+ const allChunksByFile = new Map<string, any[]>()
1206
+ const fp = fileItem.data?.file_path || fileItem.title
1207
+ allChunksByFile.set(fp, fileChunks)
1002
1208
 
1003
1209
  const result = await mapFile(
1004
- fileItem, projectId,
1210
+ ctx, fileItem, projectId,
1005
1211
  allChunksByFile, chunksByName, fileItemsByPath,
1006
1212
  importsTypeId, callsTypeId, exportsTypeId
1007
1213
  )
@@ -1020,17 +1226,13 @@ export const handler = createHandler(async (ctx, body) => {
1020
1226
  const repoPath: string = projectItem?.data?.repo_path || body?.repo_path || ''
1021
1227
  if (!repoPath) throw new Error('Project has no repo_path — pass repo_path in body')
1022
1228
 
1023
- const testedByTypeId = await resolveLinkTypeId('cil_tested_by')
1024
- const { data: allChunks } = await adminDb
1025
- .from('items')
1026
- .select('id, data->>chunk_name, data->>kb_type')
1027
- .filter('data->>project_id', 'eq', projectId)
1028
- .filter('data->>kb_type', 'eq', 'cil_chunk')
1029
- .eq('is_active', true)
1229
+ const testLinkTypeIds = await resolveLinkTypeIds(['cil_tested_by'])
1230
+ const testedByTypeId = testLinkTypeIds['cil_tested_by']
1231
+ const allChunks = await fetchAllProjectRecords(projectId, 'cil_chunk')
1030
1232
  const chunksByName = new Map<string, any>()
1031
- for (const c of allChunks || []) {
1032
- const name = c.chunk_name
1033
- if (name) chunksByName.set(name, { id: c.id, data: { chunk_name: c.chunk_name, kb_type: c.kb_type || 'cil_chunk' } })
1233
+ for (const c of allChunks) {
1234
+ const name = c.data?.chunk_name
1235
+ if (name) chunksByName.set(name, { id: c.id, data: { chunk_name: c.data?.chunk_name, kb_type: c.data?.kb_type || 'cil_chunk' } })
1034
1236
  }
1035
1237
  const result = await mapTests(ctx, projectId, repoPath, testedByTypeId, chunksByName)
1036
1238
  return { project_id: projectId, repo_path: repoPath, ...result }
@@ -1051,15 +1253,15 @@ export const handler = createHandler(async (ctx, body) => {
1051
1253
  const filePath = body?.file_path || undefined
1052
1254
  const force = body?.force_regenerate ?? body?.force ?? false
1053
1255
  const secondPass = body?.second_pass ?? false
1256
+ const fast = body?.fast === true
1054
1257
 
1055
- const targetPipelineStatus = secondPass ? '10-mapped' : '7-mapped'
1258
+ const targetPipelineStatus = secondPass ? '7-embedded-mapped' : '7-embedded-mapped'
1056
1259
 
1057
- const [importsTypeId, callsTypeId, exportsTypeId, testedByTypeId] = await Promise.all([
1058
- resolveLinkTypeId('cil_imports'),
1059
- resolveLinkTypeId('cil_calls'),
1060
- resolveLinkTypeId('cil_exports'),
1061
- resolveLinkTypeId('cil_tested_by').catch(() => null),
1062
- ])
1260
+ const projectLinkTypeIds = await resolveLinkTypeIds(['cil_imports','cil_calls','cil_exports','cil_tested_by']).catch(() => ({} as Record<string, string>))
1261
+ const importsTypeId = projectLinkTypeIds['cil_imports']
1262
+ const callsTypeId = projectLinkTypeIds['cil_calls']
1263
+ const exportsTypeId = projectLinkTypeIds['cil_exports']
1264
+ const testedByTypeId = projectLinkTypeIds['cil_tested_by'] ?? null
1063
1265
 
1064
1266
  if (force && pageOffset === 0) {
1065
1267
  await clearProjectLinks(projectId, [importsTypeId, callsTypeId, exportsTypeId, testedByTypeId])
@@ -1074,36 +1276,35 @@ export const handler = createHandler(async (ctx, body) => {
1074
1276
 
1075
1277
  const sourceFilePaths = filePath
1076
1278
  ? [filePath]
1077
- : force
1279
+ : fast
1078
1280
  ? selectedPaths
1079
- : getMapSourceFilePaths(projectItem, secondPass)
1281
+ : force
1282
+ ? selectedPaths
1283
+ : getMapSourceFilePaths(projectItem, secondPass)
1080
1284
 
1081
1285
  let filesQ = adminDb.from('items').select('id, title, data')
1082
1286
  .filter('data->>project_id', 'eq', projectId)
1083
1287
  .filter('data->>kb_type', 'eq', 'cil_file').eq('is_active', true)
1084
1288
  .order('id')
1289
+ .limit(100000)
1085
1290
  if (filePath) filesQ = filesQ.filter('data->>file_path', 'eq', filePath)
1086
1291
 
1087
- const [filesResult, allChunksMinimalResult] = await Promise.all([
1292
+ const [filesResult, allChunkNamesResult] = await Promise.all([
1088
1293
  filesQ,
1089
- adminDb.from('items').select('id, data->>chunk_name, data->>kb_type')
1090
- .filter('data->>project_id', 'eq', projectId)
1091
- .filter('data->>kb_type', 'eq', 'cil_chunk')
1092
- .eq('is_active', true),
1294
+ fetchAllProjectChunkNames(projectId),
1093
1295
  ])
1094
1296
 
1095
1297
  const allFiles = filesResult.data || []
1096
- const allChunksMinimal = allChunksMinimalResult.data || []
1097
1298
 
1098
1299
  const fileItemsByPath = new Map(allFiles.map((f: any) => [f.data?.file_path || f.title, f]))
1099
1300
 
1100
1301
  const chunksByName = new Map<string, any>()
1101
- for (const c of allChunksMinimal) {
1302
+ for (const c of allChunkNamesResult) {
1102
1303
  const name = c.chunk_name
1103
- if (name) chunksByName.set(name, { id: c.id, data: { chunk_name: c.chunk_name, kb_type: c.kb_type || 'cil_chunk' } })
1304
+ if (name) chunksByName.set(name.toLowerCase(), { id: c.id, data: { chunk_name: c.chunk_name, kb_type: c.kb_type || 'cil_chunk' } })
1104
1305
  }
1105
1306
 
1106
- const mappedFileStatus = secondPass ? 'pass8_complete' : 'pass4b_complete'
1307
+ const mappedFileStatus: FileStatus = secondPass ? '7-embedded-mapped' : '7-embedded-mapped'
1107
1308
  const syncFiles = allFiles.filter((f: any) => {
1108
1309
  const fp = f.data?.file_path || f.title
1109
1310
  const status = getFileStatus(f)
@@ -1114,8 +1315,10 @@ export const handler = createHandler(async (ctx, body) => {
1114
1315
  && isSelectedPath(fp, selectedPaths)
1115
1316
  && extMatch
1116
1317
  })
1117
- for (const fileItem of syncFiles) {
1118
- await markFilePass4bComplete(ctx, fileItem, fileTree, secondPass, projectItem)
1318
+ if (!fast) {
1319
+ for (const fileItem of syncFiles) {
1320
+ await markFilePass4bComplete(ctx, fileItem, fileTree, secondPass, projectItem)
1321
+ }
1119
1322
  }
1120
1323
 
1121
1324
  const eligibleFiles = allFiles.filter((f: any) => {
@@ -1137,17 +1340,18 @@ export const handler = createHandler(async (ctx, body) => {
1137
1340
  .filter('data->>kb_type', 'eq', 'cil_chunk')
1138
1341
  .eq('is_active', true)
1139
1342
  .in('data->>file_path' as any, pageFilePaths)
1343
+ .limit(100000)
1140
1344
  pageChunks = data || []
1141
1345
  }
1142
1346
 
1143
1347
  const allChunksByFile = new Map<string, any[]>()
1144
1348
  for (const c of pageChunks) {
1145
1349
  const name = c.data?.chunk_name || ''
1146
- if (name) chunksByName.set(name, c)
1147
- const fid = c.data?.file_id
1148
- if (!fid) continue
1149
- if (!allChunksByFile.has(fid)) allChunksByFile.set(fid, [])
1150
- allChunksByFile.get(fid)!.push(c)
1350
+ if (name) chunksByName.set(name.toLowerCase(), c)
1351
+ const fp = c.data?.file_path
1352
+ if (!fp) continue
1353
+ if (!allChunksByFile.has(fp)) allChunksByFile.set(fp, [])
1354
+ allChunksByFile.get(fp)!.push(c)
1151
1355
  }
1152
1356
 
1153
1357
  if (!chunksByName.size) {
@@ -1169,7 +1373,9 @@ export const handler = createHandler(async (ctx, body) => {
1169
1373
  totalExports += result.exports_created
1170
1374
 
1171
1375
 
1172
- await markFilePass4bComplete(ctx, fileItem, fileTree, secondPass, projectItem)
1376
+ if (!fast) {
1377
+ await markFilePass4bComplete(ctx, fileItem, fileTree, secondPass, projectItem)
1378
+ }
1173
1379
  } catch (err) {
1174
1380
  errors.push(`${fileItem.data?.file_path || fileItem.id}: ${err instanceof Error ? err.message : String(err)}`)
1175
1381
  }
@@ -1180,11 +1386,12 @@ export const handler = createHandler(async (ctx, body) => {
1180
1386
 
1181
1387
 
1182
1388
  let testResult: { test_files_scanned: number; tested_by_links_created: number; chunks_updated: number; errors: string[] } | null = null
1183
- if (isLastPage) {
1389
+ if (isLastPage && !fast) {
1184
1390
  const repoPath: string = projectItem?.data?.repo_path || ''
1185
1391
  if (repoPath) {
1186
1392
  try {
1187
- const testedByTypeId = await resolveLinkTypeId('cil_tested_by').catch(() => null)
1393
+ const testByLinkIds = await resolveLinkTypeIds(['cil_tested_by']).catch(() => ({} as Record<string, string>))
1394
+ const testedByTypeId = testByLinkIds['cil_tested_by']
1188
1395
  if (testedByTypeId) {
1189
1396
  testResult = await mapTests(ctx, projectId, repoPath, testedByTypeId, chunksByName)
1190
1397
  errors.push(...(testResult.errors || []))
@@ -1195,7 +1402,7 @@ export const handler = createHandler(async (ctx, body) => {
1195
1402
  }
1196
1403
 
1197
1404
 
1198
- if (fileTree) {
1405
+ if (fileTree && isLastPage && !fast) {
1199
1406
  await saveProjectTree(ctx, projectId, fileTree, { last_ingested_at: new Date().toISOString() }, projectItem)
1200
1407
  }
1201
1408
 
@@ -1220,8 +1427,13 @@ export const handler = createHandler(async (ctx, body) => {
1220
1427
 
1221
1428
  throw new Error(`Unknown action: ${action}. Valid: map_project, map_file, map_tests, status, clear`)
1222
1429
  })
1430
+ // CIL[DOC-VECTOR type="context" content="purpose='Expose the CIL callmap Netlify function handler'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/resolve-ids.ts"]
1431
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1432
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1433
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1434
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1435
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1436
+ // CIL[END stable_id="~/.framework/functions/cil-callmap.ts:handler:constant"]
1223
1437
 
1224
1438
 
1225
1439
 
1226
-
1227
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_callmap_handler_1784235266"]