spine-framework 0.3.145 → 0.4.1

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 +5067 -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,48 +1,37 @@
1
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_module_header_1784235266" type="module_header" identity="module_header" parent="none"]
2
- // CIL[DOC-MACRO purpose="Module header and top-level exports for cortex.functions.custom_cil-ingest"]
3
- // CIL[DOC-RESPONSIBILITY responsibility="Own module-level imports, exports, and configuration for cortex.functions.custom_cil-ingest"]
4
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" 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\",\"\\\"]"]
5
- // CIL[DOC-CONTRACT inputs="none" outputs="module exports and side effects" errors="none" side_effects="none"]
6
- // CIL[DOC-MICRO logic_summary="Declares module scope, imports dependencies, and exports public surface of cortex.functions.custom_cil-ingest" notable_decisions="[]"]
7
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:module_header:module_header" type="module_header" identity="module_header" parent="none"]
2
+ // CIL[DOC-MACRO purpose="Module header, imports and handler export for cil-ingest"]
3
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides shared imports and the main Netlify handler export"]
4
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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"]
5
+ // CIL[DOC-CONTRACT inputs="none" outputs="imported modules and the exported handler" errors="none at import time" side_effects="none"]
6
+ // CIL[DOC-MICRO logic_summary="Imports shared modules and sets up the action dispatch handler" notable_decisions="Single handler routes all CIL ingestion actions"]
7
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
8
8
  // CIL[DOC-STABILITY stability="stable"]
9
- // CIL[DOC-AUDIENCE audience="developer"]
10
- // 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, \."]
11
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
12
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
13
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
14
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
15
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
16
-
17
-
18
-
9
+ // CIL[DOC-AUDIENCE audience="both"]
19
10
  import { createHandler } from './_shared/middleware'
20
11
  import { adminDb } from './_shared/db'
21
12
  import { create as adminCreate, update as adminUpdate } from './admin-data'
22
- import { FileTreeNode, FileStatus, isSelectedPath, getFileStatus, updateTreeNodeStatus, updateTreeNodeByPath, buildFileTree } from './_shared/cil'
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_module_header_1784235266"]
32
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_collectselectedfiles_1784235266" type="function" identity="collectselectedfiles" parent="none"]
33
- // CIL[DOC-MACRO purpose="Implements collectselectedfiles logic in cortex.functions.custom_cil-ingest"]
34
- // CIL[DOC-RESPONSIBILITY responsibility="Execute collectselectedfiles and return its computed result"]
35
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" 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\",\"\\\"]"]
36
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
37
- // CIL[DOC-MICRO logic_summary="Provides collectselectedfiles with collectSelectedFiles(tree: FileTreeNode | null, selectedPaths: string[], selectedExtensions: string[] inputs, handling internal flow and returning a result" notable_decisions="[]"]
38
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
39
- // CIL[DOC-STABILITY stability="stable"]
40
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. 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, \."]
41
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
42
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
43
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
13
+ import { resolveTypeId } from './_shared/resolve-ids'
14
+ import { FileTreeNode, FileStatus, isSelectedPath, getFileStatus, updateTreeNodeStatus, updateTreeNodeByPath, buildFileTree, toCanonicalPath, generateStableId, parseStableId, computeContentHash, pipelineRank } from './_shared/cil'
15
+ import { extractIdentities } from './_shared/ast'
16
+ import * as ts from 'typescript'
17
+ import * as fs from 'fs'
18
+ import * as path from 'path'
19
+ // CIL[DOC-VECTOR type="context" content="purpose='Module header, imports and handler export for cil-ingest'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
20
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
21
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
22
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
44
23
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
45
24
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
25
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:module_header:module_header"]
26
+
27
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:collectselectedfiles:function" type="function" identity="collectSelectedFiles" parent="none"]
28
+ // CIL[DOC-MACRO purpose="Implements the collectSelectedFiles logic"]
29
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides collectSelectedFiles functionality"]
30
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
31
+ // CIL[DOC-CONTRACT inputs="tree: FileTreeNode | null, selectedPaths: string[], selectedExtensions: string[]" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
32
+ // CIL[DOC-MICRO logic_summary="Processes inputs (tree: FileTreeNode | null, selectedPaths: string[], selectedExtensions: string[]) and returns the collectSelectedFiles result" notable_decisions="See source for implementation details"]
33
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
34
+ // CIL[DOC-STABILITY stability="internal"]
46
35
  function collectSelectedFiles(tree: FileTreeNode | null, selectedPaths: string[], selectedExtensions: string[]): string[] {
47
36
  const files: string[] = []
48
37
  if (!tree) return files
@@ -58,33 +47,22 @@ function collectSelectedFiles(tree: FileTreeNode | null, selectedPaths: string[]
58
47
  walk(tree)
59
48
  return files
60
49
  }
61
- import * as fs from 'fs'
62
- import * as path from 'path'
63
- import * as crypto from 'crypto'
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_collectselectedfiles_1784235266"]
74
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_ingestrequest_1784235266" type="interface" identity="ingestrequest" parent="none"]
75
- // CIL[DOC-MACRO purpose="Defines the ingestrequest type contract in cortex.functions.custom_cil-ingest"]
76
- // CIL[DOC-RESPONSIBILITY responsibility="Describe the shape and allowed fields for ingestrequest"]
77
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" 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\",\"\\\"]"]
78
- // CIL[DOC-CONTRACT inputs="none" outputs="type definition for ingestrequest" errors="none" side_effects="none"]
79
- // CIL[DOC-MICRO logic_summary="Declares TypeScript type/interface ingestrequest with member definitions" notable_decisions="[]"]
80
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
81
- // CIL[DOC-STABILITY stability="stable"]
82
- // 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, \."]
83
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
84
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
85
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
50
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the collectSelectedFiles logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
51
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
52
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
53
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
86
54
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
87
55
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
56
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:collectselectedfiles:function"]
57
+
58
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:ingestrequest:interface" type="interface" identity="IngestRequest" parent="none"]
59
+ // CIL[DOC-MACRO purpose="TypeScript interface defining IngestRequest"]
60
+ // CIL[DOC-RESPONSIBILITY responsibility="Describes the shape of IngestRequest"]
61
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
62
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
63
+ // CIL[DOC-MICRO logic_summary="Declares the fields and types for IngestRequest" notable_decisions="Structural contract for IngestRequest"]
64
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
65
+ // CIL[DOC-STABILITY stability="stable"]
88
66
  interface IngestRequest {
89
67
  project_id: string
90
68
  globs?: string[]
@@ -93,28 +71,22 @@ interface IngestRequest {
93
71
  file_path?: string
94
72
  selected_extensions?: string[]
95
73
  }
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_ingestrequest_1784235266"]
104
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_sourceset_1784235266" type="interface" identity="sourceset" parent="none"]
105
- // CIL[DOC-MACRO purpose="Defines the sourceset type contract in cortex.functions.custom_cil-ingest"]
106
- // CIL[DOC-RESPONSIBILITY responsibility="Describe the shape and allowed fields for sourceset"]
107
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" 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\",\"\\\"]"]
108
- // CIL[DOC-CONTRACT inputs="none" outputs="type definition for sourceset" errors="none" side_effects="none"]
109
- // CIL[DOC-MICRO logic_summary="Declares TypeScript type/interface sourceset with member definitions" notable_decisions="[]"]
110
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
111
- // CIL[DOC-STABILITY stability="stable"]
112
- // 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, \."]
113
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
114
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
115
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
74
+ // CIL[DOC-VECTOR type="context" content="purpose='TypeScript interface defining IngestRequest'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
75
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
76
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
77
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
116
78
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
117
79
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
80
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:ingestrequest:interface"]
81
+
82
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:sourceset:interface" type="interface" identity="SourceSet" parent="none"]
83
+ // CIL[DOC-MACRO purpose="TypeScript interface defining SourceSet"]
84
+ // CIL[DOC-STABILITY stability="internal"]
85
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
86
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
87
+ // CIL[DOC-RESPONSIBILITY responsibility="Describes the shape of SourceSet"]
88
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
89
+ // CIL[DOC-MICRO logic_summary="Declares the fields and types for SourceSet" notable_decisions="Structural contract for SourceSet"]
118
90
  interface SourceSet {
119
91
  id: string
120
92
  name: string
@@ -123,28 +95,22 @@ interface SourceSet {
123
95
  exclude_globs?: string[]
124
96
  layer?: string
125
97
  }
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_sourceset_1784235266"]
134
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_discoveredfile_1784235266" type="interface" identity="discoveredfile" parent="none"]
135
- // CIL[DOC-MACRO purpose="Defines the discoveredfile type contract in cortex.functions.custom_cil-ingest"]
136
- // CIL[DOC-RESPONSIBILITY responsibility="Describe the shape and allowed fields for discoveredfile"]
137
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" 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\",\"\\\"]"]
138
- // CIL[DOC-CONTRACT inputs="none" outputs="type definition for discoveredfile" errors="none" side_effects="none"]
139
- // CIL[DOC-MICRO logic_summary="Declares TypeScript type/interface discoveredfile with member definitions" notable_decisions="[]"]
140
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
141
- // CIL[DOC-STABILITY stability="stable"]
142
- // 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, \."]
143
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
144
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
145
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
98
+ // CIL[DOC-VECTOR type="context" content="purpose='TypeScript interface defining SourceSet'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
99
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
100
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
101
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
146
102
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
147
103
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
104
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:sourceset:interface"]
105
+
106
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:discoveredfile:interface" type="interface" identity="DiscoveredFile" parent="none"]
107
+ // CIL[DOC-MACRO purpose="TypeScript interface defining DiscoveredFile"]
108
+ // CIL[DOC-RESPONSIBILITY responsibility="Describes the shape of DiscoveredFile"]
109
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
110
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
111
+ // CIL[DOC-MICRO logic_summary="Declares the fields and types for DiscoveredFile" notable_decisions="Structural contract for DiscoveredFile"]
112
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
113
+ // CIL[DOC-STABILITY stability="stable"]
148
114
  interface DiscoveredFile {
149
115
  file_path: string
150
116
  language: string
@@ -155,28 +121,22 @@ interface DiscoveredFile {
155
121
  existing_marker_names: string[]
156
122
  status: FileStatus
157
123
  }
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_discoveredfile_1784235266"]
166
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_chunkproposal_1784235266" type="interface" identity="chunkproposal" parent="none"]
167
- // CIL[DOC-MACRO purpose="Defines the chunkproposal type contract in cortex.functions.custom_cil-ingest"]
168
- // CIL[DOC-RESPONSIBILITY responsibility="Describe the shape and allowed fields for chunkproposal"]
169
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
170
- // CIL[DOC-CONTRACT inputs="none" outputs="type definition for chunkproposal" errors="none" side_effects="none"]
171
- // CIL[DOC-MICRO logic_summary="Declares TypeScript type/interface chunkproposal with member definitions" notable_decisions="[]"]
172
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
173
- // CIL[DOC-STABILITY stability="stable"]
174
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
175
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
176
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
177
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
124
+ // CIL[DOC-VECTOR type="context" content="purpose='TypeScript interface defining DiscoveredFile'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
125
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
126
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
127
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
178
128
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
179
129
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
130
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:discoveredfile:interface"]
131
+
132
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:chunkproposal:interface" type="interface" identity="ChunkProposal" parent="none"]
133
+ // CIL[DOC-MACRO purpose="TypeScript interface defining ChunkProposal"]
134
+ // CIL[DOC-RESPONSIBILITY responsibility="Describes the shape of ChunkProposal"]
135
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
136
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
137
+ // CIL[DOC-MICRO logic_summary="Declares the fields and types for ChunkProposal" notable_decisions="Structural contract for ChunkProposal"]
138
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
139
+ // CIL[DOC-STABILITY stability="stable"]
180
140
  interface ChunkProposal {
181
141
  name: string
182
142
  line_start: number
@@ -190,30 +150,22 @@ interface ChunkProposal {
190
150
  code_preview: string
191
151
  token_count: number
192
152
  }
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_chunkproposal_1784235266"]
203
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_language_map_1784235266" type="variable" identity="language_map" parent="none"]
204
- // CIL[DOC-MACRO purpose="Defines language_map configuration or state in cortex.functions.custom_cil-ingest"]
205
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for language_map"]
206
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
207
- // CIL[DOC-CONTRACT inputs="none" outputs="value of language_map" errors="none" side_effects="none"]
208
- // CIL[DOC-MICRO logic_summary="Declares language_map with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
209
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
210
- // CIL[DOC-STABILITY stability="stable"]
211
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
212
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
213
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
214
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
153
+ // CIL[DOC-VECTOR type="context" content="purpose='TypeScript interface defining ChunkProposal'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
154
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
155
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
156
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
215
157
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
216
158
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
159
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:chunkproposal:interface"]
160
+
161
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:language_map:constant" type="constant" identity="LANGUAGE_MAP" parent="none"]
162
+ // CIL[DOC-STABILITY stability="internal"]
163
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
164
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
165
+ // CIL[DOC-MACRO purpose="Constant LANGUAGE_MAP"]
166
+ // CIL[DOC-RESPONSIBILITY responsibility="Supplies the static value for LANGUAGE_MAP"]
167
+ // CIL[DOC-CONTRACT inputs="none" outputs="value of LANGUAGE_MAP" errors="none" side_effects="none"]
168
+ // CIL[DOC-MICRO logic_summary="Holds the static LANGUAGE_MAP value" notable_decisions="Static value used across cil-ingest"]
217
169
  const LANGUAGE_MAP: Record<string, string> = {
218
170
  '.ts': 'typescript',
219
171
  '.tsx': 'typescript',
@@ -229,574 +181,416 @@ const LANGUAGE_MAP: Record<string, string> = {
229
181
  '.html': 'html',
230
182
  '.sh': 'shell',
231
183
  }
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_language_map_1784235266"]
240
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_default_globs_1784235266" type="variable" identity="default_globs" parent="none"]
241
- // CIL[DOC-MACRO purpose="Defines default_globs configuration or state in cortex.functions.custom_cil-ingest"]
242
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for default_globs"]
243
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
244
- // CIL[DOC-CONTRACT inputs="none" outputs="value of default_globs" errors="none" side_effects="none"]
245
- // CIL[DOC-MICRO logic_summary="Declares default_globs with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
246
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
247
- // CIL[DOC-STABILITY stability="stable"]
248
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
249
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
250
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
251
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
184
+ // CIL[DOC-VECTOR type="context" content="purpose='Constant LANGUAGE_MAP'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
185
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
186
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
187
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
252
188
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
253
189
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
190
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:language_map:constant"]
191
+
192
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:default_globs:constant" type="constant" identity="DEFAULT_GLOBS" parent="none"]
193
+ // CIL[DOC-MACRO purpose="Constant DEFAULT_GLOBS"]
194
+ // CIL[DOC-RESPONSIBILITY responsibility="Supplies the static value for DEFAULT_GLOBS"]
195
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
196
+ // CIL[DOC-CONTRACT inputs="none" outputs="value of DEFAULT_GLOBS" errors="none" side_effects="none"]
197
+ // CIL[DOC-STABILITY stability="internal"]
198
+ // CIL[DOC-MICRO logic_summary="Holds the static DEFAULT_GLOBS value" notable_decisions="Static value used across cil-ingest"]
199
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
254
200
  const DEFAULT_GLOBS = ['**/*.ts', '**/*.tsx', '**/*.sql']
255
-
256
-
257
-
258
-
259
-
260
-
261
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_default_globs_1784235266"]
262
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_default_exclude_1784235266" type="variable" identity="default_exclude" parent="none"]
263
- // CIL[DOC-MACRO purpose="Defines default_exclude configuration or state in cortex.functions.custom_cil-ingest"]
264
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for default_exclude"]
265
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
266
- // CIL[DOC-CONTRACT inputs="none" outputs="value of default_exclude" errors="none" side_effects="none"]
267
- // CIL[DOC-MICRO logic_summary="Declares default_exclude with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
268
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
269
- // CIL[DOC-STABILITY stability="stable"]
270
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
271
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
272
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
273
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
201
+ // CIL[DOC-VECTOR type="context" content="purpose='Constant DEFAULT_GLOBS'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
202
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
203
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
204
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
274
205
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
275
206
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
276
- const DEFAULT_EXCLUDE = ['node_modules/**', '.git/**', 'dist/**', 'build/**', '.netlify/**', '**/*.min.js', '**/*.d.ts']
277
-
278
-
279
-
280
-
281
-
282
-
283
-
284
-
285
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_default_exclude_1784235266"]
286
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_high_confidence_threshold_1784235266" type="variable" identity="high_confidence_threshold" parent="none"]
287
- // CIL[DOC-MACRO purpose="Defines high_confidence_threshold configuration or state in cortex.functions.custom_cil-ingest"]
288
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for high_confidence_threshold"]
289
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
290
- // CIL[DOC-CONTRACT inputs="none" outputs="value of high_confidence_threshold" errors="none" side_effects="none"]
291
- // CIL[DOC-MICRO logic_summary="Declares high_confidence_threshold with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
292
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
293
- // CIL[DOC-STABILITY stability="stable"]
294
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
295
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
296
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
297
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
207
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:default_globs:constant"]
208
+
209
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:default_exclude:constant" type="constant" identity="DEFAULT_EXCLUDE" parent="none"]
210
+ // CIL[DOC-MACRO purpose="Constant DEFAULT_EXCLUDE"]
211
+ // CIL[DOC-RESPONSIBILITY responsibility="Supplies the static value for DEFAULT_EXCLUDE"]
212
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
213
+ // CIL[DOC-CONTRACT inputs="none" outputs="value of DEFAULT_EXCLUDE" errors="none" side_effects="none"]
214
+ // CIL[DOC-MICRO logic_summary="Holds the static DEFAULT_EXCLUDE value" notable_decisions="Static value used across cil-ingest"]
215
+ // CIL[DOC-STABILITY stability="internal"]
216
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
217
+ const DEFAULT_EXCLUDE = ['node_modules/**', '.git/**', '.assembled/**', 'dist/**', 'build/**', '.netlify/**', '**/*.min.js', '**/*.d.ts']
218
+ // CIL[DOC-VECTOR type="context" content="purpose='Constant DEFAULT_EXCLUDE'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
219
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
220
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
221
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
298
222
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
299
223
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
300
- const HIGH_CONFIDENCE_THRESHOLD = 0.80
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
-
309
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_high_confidence_threshold_1784235266"]
310
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_marker_start_re_1784235266" type="variable" identity="marker_start_re" parent="none"]
311
- // CIL[DOC-MACRO purpose="Defines marker_start_re configuration or state in cortex.functions.custom_cil-ingest"]
312
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for marker_start_re"]
313
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
314
- // CIL[DOC-CONTRACT inputs="none" outputs="value of marker_start_re" errors="none" side_effects="none"]
315
- // CIL[DOC-MICRO logic_summary="Declares marker_start_re with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
316
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
224
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:default_exclude:constant"]
225
+ // CIL[DOC-CONTEXT module="unknown" layer="unknown" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
226
+
227
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:high_confidence_threshold:constant" type="constant" identity="HIGH_CONFIDENCE_THRESHOLD" parent="none"]
228
+ // CIL[DOC-MACRO purpose="Constant HIGH_CONFIDENCE_THRESHOLD"]
229
+ // CIL[DOC-RESPONSIBILITY responsibility="Supplies the static value for HIGH_CONFIDENCE_THRESHOLD"]
230
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
231
+ // CIL[DOC-CONTRACT inputs="none" outputs="value of HIGH_CONFIDENCE_THRESHOLD" errors="none" side_effects="none"]
232
+ // CIL[DOC-MICRO logic_summary="Holds the static HIGH_CONFIDENCE_THRESHOLD value" notable_decisions="Static value used across cil-ingest"]
233
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
317
234
  // CIL[DOC-STABILITY stability="stable"]
318
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
319
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
320
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
321
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
235
+ const HIGH_CONFIDENCE_THRESHOLD = 0.80
236
+ // CIL[DOC-VECTOR type="context" content="purpose='Constant HIGH_CONFIDENCE_THRESHOLD'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
237
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
238
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
239
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
322
240
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
323
241
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
324
- const MARKER_START_RE = /^\/\*\*\s*[─\-]+\s*CHUNK_START:\s*(.+?)\s*[─\-]*\s*\*\/\s*$/
325
-
326
-
327
-
328
-
329
-
330
-
331
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_marker_start_re_1784235266"]
332
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_marker_end_re_1784235266" type="variable" identity="marker_end_re" parent="none"]
333
- // CIL[DOC-MACRO purpose="Defines marker_end_re configuration or state in cortex.functions.custom_cil-ingest"]
334
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for marker_end_re"]
335
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
336
- // CIL[DOC-CONTRACT inputs="none" outputs="value of marker_end_re" errors="none" side_effects="none"]
337
- // CIL[DOC-MICRO logic_summary="Declares marker_end_re with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
338
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
242
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:high_confidence_threshold:constant"]
243
+
244
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:marker_start_re:constant" type="constant" identity="MARKER_START_RE" parent="none"]
245
+ // CIL[DOC-MACRO purpose="Regular expression constant MARKER_START_RE"]
246
+ // CIL[DOC-RESPONSIBILITY responsibility="Defines the matching pattern for MARKER_START_RE"]
247
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
248
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
249
+ // CIL[DOC-CONTRACT inputs="none" outputs="value of MARKER_START_RE" errors="none" side_effects="none"]
250
+ // CIL[DOC-MICRO logic_summary="Compiles and stores the MARKER_START_RE regex pattern" notable_decisions="Static value used across cil-ingest"]
339
251
  // CIL[DOC-STABILITY stability="stable"]
340
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
341
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
342
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
343
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
252
+ const MARKER_START_RE = /^\/\/\s*CIL\[BEGIN\s+stable_id="([^"]+)"[^\]]*\]\s*$/
253
+ // CIL[DOC-VECTOR type="context" content="purpose='Regular expression constant MARKER_START_RE'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
254
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
255
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
256
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
344
257
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
345
258
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
346
- const MARKER_END_RE = /^\/\*\*\s*[─\-]+\s*CHUNK_END:\s*(.+?)\s*[─\-]*\s*\*\/\s*$/
347
-
348
-
349
-
350
-
351
-
352
-
353
-
354
-
355
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_marker_end_re_1784235266"]
356
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_proposal_start_re_1784235266" type="variable" identity="proposal_start_re" parent="none"]
357
- // CIL[DOC-MACRO purpose="Defines proposal_start_re configuration or state in cortex.functions.custom_cil-ingest"]
358
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for proposal_start_re"]
359
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
360
- // CIL[DOC-CONTRACT inputs="none" outputs="value of proposal_start_re" errors="none" side_effects="none"]
361
- // CIL[DOC-MICRO logic_summary="Declares proposal_start_re with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
362
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
259
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:marker_start_re:constant"]
260
+
261
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:marker_end_re:constant" type="constant" identity="MARKER_END_RE" parent="none"]
262
+ // CIL[DOC-MACRO purpose="Regular expression constant MARKER_END_RE"]
263
+ // CIL[DOC-RESPONSIBILITY responsibility="Defines the matching pattern for MARKER_END_RE"]
264
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
265
+ // CIL[DOC-CONTRACT inputs="none" outputs="value of MARKER_END_RE" errors="none" side_effects="none"]
266
+ // CIL[DOC-MICRO logic_summary="Compiles and stores the MARKER_END_RE regex pattern" notable_decisions="Static value used across cil-ingest"]
267
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
363
268
  // CIL[DOC-STABILITY stability="stable"]
364
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
365
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
366
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
367
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
269
+ const MARKER_END_RE = /^\/\/\s*CIL\[END\s+stable_id="([^"]+)"[^\]]*\]\s*$/
270
+ // CIL[DOC-VECTOR type="context" content="purpose='Regular expression constant MARKER_END_RE'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
271
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
272
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
273
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
368
274
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
369
275
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
370
- const PROPOSAL_START_RE = /^\/\*\*\s*─+\s*CHUNK_START:\s*PROPOSAL\s+(.+?)\s*─+\s*\*\/\s*$/
371
-
372
-
373
-
374
-
375
-
376
-
377
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_proposal_start_re_1784235266"]
378
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_proposal_end_re_1784235266" type="variable" identity="proposal_end_re" parent="none"]
379
- // CIL[DOC-MACRO purpose="Defines proposal_end_re configuration or state in cortex.functions.custom_cil-ingest"]
380
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for proposal_end_re"]
381
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
382
- // CIL[DOC-CONTRACT inputs="none" outputs="value of proposal_end_re" errors="none" side_effects="none"]
383
- // CIL[DOC-MICRO logic_summary="Declares proposal_end_re with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
384
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
276
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:marker_end_re:constant"]
277
+
278
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:proposal_start_re:constant" type="constant" identity="PROPOSAL_START_RE" parent="none"]
279
+ // CIL[DOC-MACRO purpose="Regular expression constant PROPOSAL_START_RE"]
280
+ // CIL[DOC-RESPONSIBILITY responsibility="Defines the matching pattern for PROPOSAL_START_RE"]
281
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
282
+ // CIL[DOC-CONTRACT inputs="none" outputs="value of PROPOSAL_START_RE" errors="none" side_effects="none"]
283
+ // CIL[DOC-MICRO logic_summary="Compiles and stores the PROPOSAL_START_RE regex pattern" notable_decisions="Static value used across cil-ingest"]
284
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
385
285
  // CIL[DOC-STABILITY stability="stable"]
386
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
387
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
388
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
389
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
286
+ const PROPOSAL_START_RE = /^\/\*\*\s*─+\s*CHUNK_START:\s*PROPOSAL\s+(.+?)\s*─+\s*\*\/\s*$/
287
+ // CIL[DOC-VECTOR type="context" content="purpose='Regular expression constant PROPOSAL_START_RE'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
288
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
289
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
290
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
390
291
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
391
292
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
293
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:proposal_start_re:constant"]
294
+
295
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:proposal_end_re:constant" type="constant" identity="PROPOSAL_END_RE" parent="none"]
296
+ // CIL[DOC-MACRO purpose="Regular expression constant PROPOSAL_END_RE"]
297
+ // CIL[DOC-RESPONSIBILITY responsibility="Defines the matching pattern for PROPOSAL_END_RE"]
298
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
299
+ // CIL[DOC-CONTRACT inputs="none" outputs="value of PROPOSAL_END_RE" errors="none" side_effects="none"]
300
+ // CIL[DOC-STABILITY stability="internal"]
301
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
302
+ // CIL[DOC-MICRO logic_summary="Compiles and stores the PROPOSAL_END_RE regex pattern" notable_decisions="Static value used across cil-ingest"]
392
303
  const PROPOSAL_END_RE = /^\/\*\*\s*─+\s*CHUNK_END:\s*PROPOSAL\s+(.+?)\s*─+\s*\*\/\s*$/
393
-
394
-
395
-
396
-
397
-
398
-
399
-
400
-
401
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_proposal_end_re_1784235266"]
402
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_rejected_start_re_1784235266" type="variable" identity="rejected_start_re" parent="none"]
403
- // CIL[DOC-MACRO purpose="Defines rejected_start_re configuration or state in cortex.functions.custom_cil-ingest"]
404
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for rejected_start_re"]
405
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
406
- // CIL[DOC-CONTRACT inputs="none" outputs="value of rejected_start_re" errors="none" side_effects="none"]
407
- // CIL[DOC-MICRO logic_summary="Declares rejected_start_re with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
408
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
409
- // CIL[DOC-STABILITY stability="stable"]
410
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
411
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
412
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
413
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
304
+ // CIL[DOC-VECTOR type="context" content="purpose='Regular expression constant PROPOSAL_END_RE'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
305
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
306
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
307
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
414
308
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
415
309
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
416
- const REJECTED_START_RE = /^\/\*\*\s*─+\s*CHUNK_START:\s*REJECTED\s+(.+?)\s*─+\s*\*\/\s*$/
417
-
418
-
419
-
420
-
421
-
422
-
423
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_rejected_start_re_1784235266"]
424
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_rejected_end_re_1784235266" type="variable" identity="rejected_end_re" parent="none"]
425
- // CIL[DOC-MACRO purpose="Defines rejected_end_re configuration or state in cortex.functions.custom_cil-ingest"]
426
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for rejected_end_re"]
427
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
428
- // CIL[DOC-CONTRACT inputs="none" outputs="value of rejected_end_re" errors="none" side_effects="none"]
429
- // CIL[DOC-MICRO logic_summary="Declares rejected_end_re with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
430
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
310
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:proposal_end_re:constant"]
311
+
312
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:rejected_start_re:constant" type="constant" identity="REJECTED_START_RE" parent="none"]
313
+ // CIL[DOC-MACRO purpose="Regular expression constant REJECTED_START_RE"]
314
+ // CIL[DOC-RESPONSIBILITY responsibility="Defines the matching pattern for REJECTED_START_RE"]
315
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
316
+ // CIL[DOC-CONTRACT inputs="none" outputs="value of REJECTED_START_RE" errors="none" side_effects="none"]
317
+ // CIL[DOC-MICRO logic_summary="Compiles and stores the REJECTED_START_RE regex pattern" notable_decisions="Static value used across cil-ingest"]
318
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
431
319
  // CIL[DOC-STABILITY stability="stable"]
432
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
433
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
434
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
435
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
320
+ const REJECTED_START_RE = /^\/\*\*\s*─+\s*CHUNK_START:\s*REJECTED\s+(.+?)\s*─+\s*\*\/\s*$/
321
+ // CIL[DOC-VECTOR type="context" content="purpose='Regular expression constant REJECTED_START_RE'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
322
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
323
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
324
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
436
325
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
437
326
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
438
- const REJECTED_END_RE = /^\/\*\*\s*─+\s*CHUNK_END:\s*REJECTED\s+(.+?)\s*─+\s*\*\/\s*$/
439
-
440
-
441
-
442
-
443
-
444
-
445
-
446
-
447
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_rejected_end_re_1784235266"]
448
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_any_marker_re_1784235266" type="variable" identity="any_marker_re" parent="none"]
449
- // CIL[DOC-MACRO purpose="Defines any_marker_re configuration or state in cortex.functions.custom_cil-ingest"]
450
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for any_marker_re"]
451
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
452
- // CIL[DOC-CONTRACT inputs="none" outputs="value of any_marker_re" errors="none" side_effects="none"]
453
- // CIL[DOC-MICRO logic_summary="Declares any_marker_re with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
454
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
327
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:rejected_start_re:constant"]
328
+
329
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:rejected_end_re:constant" type="constant" identity="REJECTED_END_RE" parent="none"]
330
+ // CIL[DOC-MACRO purpose="Regular expression constant REJECTED_END_RE"]
331
+ // CIL[DOC-RESPONSIBILITY responsibility="Defines the matching pattern for REJECTED_END_RE"]
332
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
333
+ // CIL[DOC-CONTRACT inputs="none" outputs="value of REJECTED_END_RE" errors="none" side_effects="none"]
334
+ // CIL[DOC-MICRO logic_summary="Compiles and stores the REJECTED_END_RE regex pattern" notable_decisions="Static value used across cil-ingest"]
335
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
455
336
  // CIL[DOC-STABILITY stability="stable"]
456
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
457
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
458
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
459
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
337
+ const REJECTED_END_RE = /^\/\*\*\s*─+\s*CHUNK_END:\s*REJECTED\s+(.+?)\s*─+\s*\*\/\s*$/
338
+ // CIL[DOC-VECTOR type="context" content="purpose='Regular expression constant REJECTED_END_RE'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
339
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
340
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
341
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
460
342
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
461
343
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
462
- const ANY_MARKER_RE = /^\/\*\*\s*─+\s*CHUNK_(?:START|END):\s*(?:PROPOSAL\s+|REJECTED\s+)?(.+?)\s*─+\s*\*\/\s*$/
463
-
464
-
465
-
466
-
467
-
468
-
469
-
470
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_any_marker_re_1784235266"]
471
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_chunkstartmarker_1784235266" type="function" identity="chunkstartmarker" parent="none"]
472
- // CIL[DOC-MACRO purpose="Implements chunkstartmarker logic in cortex.functions.custom_cil-ingest"]
473
- // CIL[DOC-RESPONSIBILITY responsibility="Execute chunkstartmarker and return its computed result"]
474
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
475
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
476
- // CIL[DOC-MICRO logic_summary="Provides chunkstartmarker with chunkStartMarker(name: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
477
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
344
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:rejected_end_re:constant"]
345
+
346
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:any_marker_re:constant" type="constant" identity="ANY_MARKER_RE" parent="none"]
347
+ // CIL[DOC-MACRO purpose="Regular expression constant ANY_MARKER_RE"]
348
+ // CIL[DOC-RESPONSIBILITY responsibility="Defines the matching pattern for ANY_MARKER_RE"]
349
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
350
+ // CIL[DOC-CONTRACT inputs="none" outputs="value of ANY_MARKER_RE" errors="none" side_effects="none"]
351
+ // CIL[DOC-MICRO logic_summary="Compiles and stores the ANY_MARKER_RE regex pattern" notable_decisions="Static value used across cil-ingest"]
352
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
478
353
  // CIL[DOC-STABILITY stability="stable"]
479
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
480
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
481
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
482
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
354
+ const ANY_MARKER_RE = /^\/\/\s*CIL\[(BEGIN|END)\b.*stable_id="([^"]+)"[^\]]*\]/
355
+ // CIL[DOC-VECTOR type="context" content="purpose='Regular expression constant ANY_MARKER_RE'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
356
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
357
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
358
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
483
359
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
484
360
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
485
- function chunkStartMarker(name: string): string {
486
- return `/** ─── CHUNK_START: ${name} ─── */`
361
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:any_marker_re:constant"]
362
+
363
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:chunkstartmarker:function" type="function" identity="chunkStartMarker" parent="none"]
364
+ // CIL[DOC-MACRO purpose="Implements the chunkStartMarker logic"]
365
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides chunkStartMarker functionality"]
366
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
367
+ // CIL[DOC-CONTRACT inputs="stableId: string, chunkType: string, identity: string, parentStableId: string" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
368
+ // CIL[DOC-MICRO logic_summary="Processes inputs (stableId: string, chunkType: string, identity: string, parentStableId: string) and returns the chunkStartMarker result" notable_decisions="See source for implementation details"]
369
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
370
+ // CIL[DOC-STABILITY stability="internal"]
371
+ function chunkStartMarker(stableId: string, chunkType: string, identity: string, parentStableId: string): string {
372
+ return `// CIL[BEGIN stable_id="${stableId}" type="${chunkType || 'unknown'}" identity="${identity || 'unknown'}" parent="${parentStableId || 'none'}"]`
487
373
  }
488
-
489
-
490
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_chunkstartmarker_1784235266"]
491
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_chunkendmarker_1784235266" type="function" identity="chunkendmarker" parent="none"]
492
- // CIL[DOC-MACRO purpose="Implements chunkendmarker logic in cortex.functions.custom_cil-ingest"]
493
- // CIL[DOC-RESPONSIBILITY responsibility="Execute chunkendmarker and return its computed result"]
494
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
495
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
496
- // CIL[DOC-MICRO logic_summary="Provides chunkendmarker with chunkEndMarker(name: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
497
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
498
- // CIL[DOC-STABILITY stability="stable"]
499
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
500
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
501
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
502
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
374
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the chunkStartMarker logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
375
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
376
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
377
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
503
378
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
504
379
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
505
- function chunkEndMarker(name: string): string {
506
- return ``
380
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:chunkstartmarker:function"]
381
+
382
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:chunkendmarker:function" type="function" identity="chunkEndMarker" parent="none"]
383
+ // CIL[DOC-MACRO purpose="Implements the chunkEndMarker logic"]
384
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides chunkEndMarker functionality"]
385
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
386
+ // CIL[DOC-CONTRACT inputs="stableId: string" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
387
+ // CIL[DOC-MICRO logic_summary="Processes inputs (stableId: string) and returns the chunkEndMarker result" notable_decisions="See source for implementation details"]
388
+ // CIL[DOC-STABILITY stability="internal"]
389
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
390
+ function chunkEndMarker(stableId: string): string {
391
+ return `// CIL[END stable_id="${stableId}"]`
507
392
  }
508
-
509
-
510
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_chunkendmarker_1784235266"]
511
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_proposalstartmarker_1784235266" type="function" identity="proposalstartmarker" parent="none"]
512
- // CIL[DOC-MACRO purpose="Implements proposalstartmarker logic in cortex.functions.custom_cil-ingest"]
513
- // CIL[DOC-RESPONSIBILITY responsibility="Execute proposalstartmarker and return its computed result"]
514
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
515
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
516
- // CIL[DOC-MICRO logic_summary="Provides proposalstartmarker with proposalStartMarker(name: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
517
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
518
- // CIL[DOC-STABILITY stability="stable"]
519
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
520
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
521
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
522
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
393
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the chunkEndMarker logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
394
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
395
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
396
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
523
397
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
524
398
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
399
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:chunkendmarker:function"]
400
+
401
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:proposalstartmarker:function" type="function" identity="proposalStartMarker" parent="none"]
402
+ // CIL[DOC-MACRO purpose="Implements the proposalStartMarker logic"]
403
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides proposalStartMarker functionality"]
404
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
405
+ // CIL[DOC-CONTRACT inputs="name: string" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
406
+ // CIL[DOC-MICRO logic_summary="Processes inputs (name: string) and returns the proposalStartMarker result" notable_decisions="See source for implementation details"]
407
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
408
+ // CIL[DOC-STABILITY stability="internal"]
525
409
  function proposalStartMarker(name: string): string {
526
410
  return ``
527
411
  }
528
-
529
-
530
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_proposalstartmarker_1784235266"]
531
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_proposalendmarker_1784235266" type="function" identity="proposalendmarker" parent="none"]
532
- // CIL[DOC-MACRO purpose="Implements proposalendmarker logic in cortex.functions.custom_cil-ingest"]
533
- // CIL[DOC-RESPONSIBILITY responsibility="Execute proposalendmarker and return its computed result"]
534
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
535
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
536
- // CIL[DOC-MICRO logic_summary="Provides proposalendmarker with proposalEndMarker(name: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
537
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
538
- // CIL[DOC-STABILITY stability="stable"]
539
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
540
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
541
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
542
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
412
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the proposalStartMarker logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
413
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
414
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
415
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
543
416
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
544
417
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
418
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:proposalstartmarker:function"]
419
+
420
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:proposalendmarker:function" type="function" identity="proposalEndMarker" parent="none"]
421
+ // CIL[DOC-MACRO purpose="Implements the proposalEndMarker logic"]
422
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides proposalEndMarker functionality"]
423
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
424
+ // CIL[DOC-CONTRACT inputs="name: string" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
425
+ // CIL[DOC-MICRO logic_summary="Processes inputs (name: string) and returns the proposalEndMarker result" notable_decisions="See source for implementation details"]
426
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
427
+ // CIL[DOC-STABILITY stability="internal"]
545
428
  function proposalEndMarker(name: string): string {
546
429
  return ``
547
430
  }
548
-
549
-
550
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_proposalendmarker_1784235266"]
551
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_rejectedstartmarker_1784235266" type="function" identity="rejectedstartmarker" parent="none"]
552
- // CIL[DOC-MACRO purpose="Implements rejectedstartmarker logic in cortex.functions.custom_cil-ingest"]
553
- // CIL[DOC-RESPONSIBILITY responsibility="Execute rejectedstartmarker and return its computed result"]
554
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
555
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
556
- // CIL[DOC-MICRO logic_summary="Provides rejectedstartmarker with rejectedStartMarker(name: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
557
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
558
- // CIL[DOC-STABILITY stability="stable"]
559
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
560
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
561
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
562
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
431
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the proposalEndMarker logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
432
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
433
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
434
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
563
435
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
564
436
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
437
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:proposalendmarker:function"]
438
+
439
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:rejectedstartmarker:function" type="function" identity="rejectedStartMarker" parent="none"]
440
+ // CIL[DOC-MACRO purpose="Implements the rejectedStartMarker logic"]
441
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides rejectedStartMarker functionality"]
442
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
443
+ // CIL[DOC-STABILITY stability="internal"]
444
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
445
+ // CIL[DOC-CONTRACT inputs="name: string" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
446
+ // CIL[DOC-MICRO logic_summary="Processes inputs (name: string) and returns the rejectedStartMarker result" notable_decisions="See source for implementation details"]
565
447
  function rejectedStartMarker(name: string): string {
566
448
  return ``
567
449
  }
568
-
569
-
570
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_rejectedstartmarker_1784235266"]
571
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_rejectedendmarker_1784235266" type="function" identity="rejectedendmarker" parent="none"]
572
- // CIL[DOC-MACRO purpose="Implements rejectedendmarker logic in cortex.functions.custom_cil-ingest"]
573
- // CIL[DOC-RESPONSIBILITY responsibility="Execute rejectedendmarker and return its computed result"]
574
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
575
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
576
- // CIL[DOC-MICRO logic_summary="Provides rejectedendmarker with rejectedEndMarker(name: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
577
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
578
- // CIL[DOC-STABILITY stability="stable"]
579
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
580
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
581
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
582
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
450
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the rejectedStartMarker logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
451
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
452
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
453
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
583
454
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
584
455
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
456
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:rejectedstartmarker:function"]
457
+
458
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:rejectedendmarker:function" type="function" identity="rejectedEndMarker" parent="none"]
459
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
460
+ // CIL[DOC-MACRO purpose="Implements the rejectedEndMarker logic"]
461
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides rejectedEndMarker functionality"]
462
+ // CIL[DOC-CONTRACT inputs="name: string" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
463
+ // CIL[DOC-MICRO logic_summary="Processes inputs (name: string) and returns the rejectedEndMarker result" notable_decisions="See source for implementation details"]
464
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
465
+ // CIL[DOC-STABILITY stability="internal"]
585
466
  function rejectedEndMarker(name: string): string {
586
467
  return ``
587
468
  }
588
-
589
-
590
-
591
-
592
-
593
-
594
-
595
-
596
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_rejectedendmarker_1784235266"]
597
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_markerinsertidx_1784235266" type="function" identity="markerinsertidx" parent="none"]
598
- // CIL[DOC-MACRO purpose="Implements markerinsertidx logic in cortex.functions.custom_cil-ingest"]
599
- // CIL[DOC-RESPONSIBILITY responsibility="Execute markerinsertidx and return its computed result"]
600
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
601
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
602
- // CIL[DOC-MICRO logic_summary="Provides markerinsertidx with markerInsertIdx(_lines: string[], lineStart: number inputs, handling internal flow and returning a result" notable_decisions="[]"]
603
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
604
- // CIL[DOC-STABILITY stability="stable"]
605
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
606
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
607
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
608
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
469
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the rejectedEndMarker logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
470
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
471
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
472
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
609
473
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
610
474
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
475
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:rejectedendmarker:function"]
476
+
477
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:markerinsertidx:function" type="function" identity="markerInsertIdx" parent="none"]
478
+ // CIL[DOC-MACRO purpose="Implements the markerInsertIdx logic"]
479
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides markerInsertIdx functionality"]
480
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
481
+ // CIL[DOC-CONTRACT inputs="_lines: string[], lineStart: number" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
482
+ // CIL[DOC-MICRO logic_summary="Processes inputs (_lines: string[], lineStart: number) and returns the markerInsertIdx result" notable_decisions="See source for implementation details"]
483
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
484
+ // CIL[DOC-STABILITY stability="internal"]
611
485
  function markerInsertIdx(_lines: string[], lineStart: number): number {
612
486
  return lineStart - 1
613
487
  }
614
-
615
-
616
-
617
-
618
-
619
-
620
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_markerinsertidx_1784235266"]
621
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_markerendinsertidx_1784235266" type="function" identity="markerendinsertidx" parent="none"]
622
- // CIL[DOC-MACRO purpose="Implements markerendinsertidx logic in cortex.functions.custom_cil-ingest"]
623
- // CIL[DOC-RESPONSIBILITY responsibility="Execute markerendinsertidx and return its computed result"]
624
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
625
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
626
- // CIL[DOC-MICRO logic_summary="Provides markerendinsertidx with markerEndInsertIdx(_lines: string[], lineEnd: number inputs, handling internal flow and returning a result" notable_decisions="[]"]
627
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
628
- // CIL[DOC-STABILITY stability="stable"]
629
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
630
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
631
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
632
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
633
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
634
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
635
- function markerEndInsertIdx(_lines: string[], lineEnd: number): number {
636
- return lineEnd
637
- }
638
-
639
-
640
-
641
-
642
-
643
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_markerendinsertidx_1784235266"]
644
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_computefilehash_1784235266" type="function" identity="computefilehash" parent="none"]
645
- // CIL[DOC-MACRO purpose="Implements computefilehash logic in cortex.functions.custom_cil-ingest"]
646
- // CIL[DOC-RESPONSIBILITY responsibility="Execute computefilehash and return its computed result"]
647
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
648
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
649
- // CIL[DOC-MICRO logic_summary="Provides computefilehash with computeFileHash(content: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
650
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
651
- // CIL[DOC-STABILITY stability="stable"]
652
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
653
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
654
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
655
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
488
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the markerInsertIdx logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.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"]
656
492
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
657
493
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
658
- function computeFileHash(content: string): string {
659
- return crypto.createHash('sha256').update(content).digest('hex').slice(0, 16)
494
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:markerinsertidx:function"]
495
+
496
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:markerendinsertidx:function" type="function" identity="markerEndInsertIdx" parent="none"]
497
+ // CIL[DOC-MACRO purpose="Implements the markerEndInsertIdx logic"]
498
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides markerEndInsertIdx functionality"]
499
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
500
+ // CIL[DOC-CONTRACT inputs="lines: string[], lineStart: number, lineEnd: number" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
501
+ // CIL[DOC-MICRO logic_summary="Processes inputs (lines: string[], lineStart: number, lineEnd: number) and returns the markerEndInsertIdx result" notable_decisions="See source for implementation details"]
502
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
503
+ // CIL[DOC-STABILITY stability="internal"]
504
+ function markerEndInsertIdx(lines: string[], lineStart: number, lineEnd: number): number {
505
+ if (lineEnd > lines.length) return lines.length
506
+ if (lineEnd - lineStart <= 0) return lineEnd
507
+ const startLine = lines[lineStart - 1] || ''
508
+ const startIndent = (startLine.match(/^(\s*)/)?.[1] || '').length
509
+ const isBraceOnly = (line: string, maxIndent: number) => {
510
+ const indent = (line.match(/^(\s*)/)?.[1] || '').length
511
+ return /^\s*\}\s*$/.test(line) && indent <= maxIndent
512
+ }
513
+ // search backward from lineEnd for the closing brace of this block
514
+ const endCap = Math.min(lineEnd - 1, lines.length - 1)
515
+ for (let i = endCap; i >= lineStart - 1; i--) {
516
+ if (isBraceOnly(lines[i], startIndent)) return i + 1
517
+ }
518
+ return lineEnd
660
519
  }
661
-
662
-
663
-
664
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_computefilehash_1784235266"]
665
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_modulenamefrompath_1784235266" type="function" identity="modulenamefrompath" parent="none"]
666
- // CIL[DOC-MACRO purpose="Implements modulenamefrompath logic in cortex.functions.custom_cil-ingest"]
667
- // CIL[DOC-RESPONSIBILITY responsibility="Execute modulenamefrompath and return its computed result"]
668
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
669
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
670
- // CIL[DOC-MICRO logic_summary="Provides modulenamefrompath with moduleNameFromPath(relPath: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
671
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
672
- // CIL[DOC-STABILITY stability="stable"]
673
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
674
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
675
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
676
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
520
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the markerEndInsertIdx logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
521
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
522
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
523
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
677
524
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
678
525
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
526
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:markerendinsertidx:function"]
527
+
528
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:modulenamefrompath:function" type="function" identity="moduleNameFromPath" parent="none"]
529
+ // CIL[DOC-MACRO purpose="Implements the moduleNameFromPath logic"]
530
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides moduleNameFromPath functionality"]
531
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
532
+ // CIL[DOC-CONTRACT inputs="relPath: string" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
533
+ // CIL[DOC-MICRO logic_summary="Processes inputs (relPath: string) and returns the moduleNameFromPath result" notable_decisions="See source for implementation details"]
534
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
535
+ // CIL[DOC-STABILITY stability="internal"]
679
536
  function moduleNameFromPath(relPath: string): string {
680
537
  return path.basename(relPath, path.extname(relPath))
681
538
  }
682
-
683
-
684
-
685
-
686
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_modulenamefrompath_1784235266"]
687
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_normalisechunkcontent_1784235266" type="function" identity="normalisechunkcontent" parent="none"]
688
- // CIL[DOC-MACRO purpose="Implements normalisechunkcontent logic in cortex.functions.custom_cil-ingest"]
689
- // CIL[DOC-RESPONSIBILITY responsibility="Execute normalisechunkcontent and return its computed result"]
690
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
691
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
692
- // CIL[DOC-MICRO logic_summary="Provides normalisechunkcontent with normaliseChunkContent(raw: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
693
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
694
- // CIL[DOC-STABILITY stability="stable"]
695
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
696
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
697
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
698
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
699
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
700
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
701
- function normaliseChunkContent(raw: string): string {
702
- const lines = raw.replace(/\r\n/g, '\n').split('\n')
703
- const filtered = lines.filter(line => {
704
- const trimmed = line.trim()
705
- return !trimmed.match(/^\/\/\s*[─\-]+ CHUNK_(START|END):/)
706
- })
707
- const collapsed: string[] = []
708
- let lastBlank = false
709
- for (const line of filtered) {
710
- const isBlank = line.trim() === ''
711
- if (isBlank && lastBlank) continue
712
- collapsed.push(line)
713
- lastBlank = isBlank
714
- }
715
- return collapsed.join('\n').trim()
716
- }
717
-
718
-
719
-
720
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_normalisechunkcontent_1784235266"]
721
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_computechunkhash_1784235266" type="function" identity="computechunkhash" parent="none"]
722
- // CIL[DOC-MACRO purpose="Implements computechunkhash logic in cortex.functions.custom_cil-ingest"]
723
- // CIL[DOC-RESPONSIBILITY responsibility="Execute computechunkhash and return its computed result"]
724
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
725
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
726
- // CIL[DOC-MICRO logic_summary="Provides computechunkhash with computeChunkHash(codeContent: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
727
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
728
- // CIL[DOC-STABILITY stability="stable"]
729
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
730
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
731
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
732
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
733
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
734
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
735
- function computeChunkHash(codeContent: string): string {
736
- return crypto.createHash('sha256').update(normaliseChunkContent(codeContent)).digest('hex').slice(0, 16)
737
- }
738
-
739
-
740
-
741
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_computechunkhash_1784235266"]
742
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_estimatetokens_1784235266" type="function" identity="estimatetokens" parent="none"]
743
- // CIL[DOC-MACRO purpose="Implements estimatetokens logic in cortex.functions.custom_cil-ingest"]
744
- // CIL[DOC-RESPONSIBILITY responsibility="Execute estimatetokens and return its computed result"]
745
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
746
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
747
- // CIL[DOC-MICRO logic_summary="Provides estimatetokens with estimateTokens(text: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
748
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
749
- // CIL[DOC-STABILITY stability="stable"]
750
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
751
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
752
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
753
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
539
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the moduleNameFromPath logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
540
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
541
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
542
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
754
543
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
755
544
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
545
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:modulenamefrompath:function"]
546
+
547
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:estimatetokens:function" type="function" identity="estimateTokens" parent="none"]
548
+ // CIL[DOC-MACRO purpose="Implements the estimateTokens logic"]
549
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides estimateTokens functionality"]
550
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
551
+ // CIL[DOC-CONTRACT inputs="text: string" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
552
+ // CIL[DOC-MICRO logic_summary="Processes inputs (text: string) and returns the estimateTokens result" notable_decisions="See source for implementation details"]
553
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
554
+ // CIL[DOC-STABILITY stability="internal"]
756
555
  function estimateTokens(text: string): number {
757
556
  return Math.ceil(text.length / 4)
758
557
  }
759
-
760
-
761
-
762
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_estimatetokens_1784235266"]
763
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_detectlanguage_1784235266" type="function" identity="detectlanguage" parent="none"]
764
- // CIL[DOC-MACRO purpose="Implements detectlanguage logic in cortex.functions.custom_cil-ingest"]
765
- // CIL[DOC-RESPONSIBILITY responsibility="Execute detectlanguage and return its computed result"]
766
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
767
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
768
- // CIL[DOC-MICRO logic_summary="Provides detectlanguage with detectLanguage(filePath: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
769
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
770
- // CIL[DOC-STABILITY stability="stable"]
771
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
772
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
773
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
774
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
558
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the estimateTokens logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
559
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
560
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
561
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
775
562
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
776
563
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
564
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:estimatetokens:function"]
565
+
566
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:detectlanguage:function" type="function" identity="detectLanguage" parent="none"]
567
+ // CIL[DOC-MACRO purpose="Implements the detectLanguage logic"]
568
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides detectLanguage functionality"]
569
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
570
+ // CIL[DOC-CONTRACT inputs="filePath: string" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
571
+ // CIL[DOC-MICRO logic_summary="Processes inputs (filePath: string) and returns the detectLanguage result" notable_decisions="See source for implementation details"]
572
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
573
+ // CIL[DOC-STABILITY stability="internal"]
777
574
  function detectLanguage(filePath: string): string {
778
575
  const ext = path.extname(filePath).toLowerCase()
779
576
  return LANGUAGE_MAP[ext] || 'unknown'
780
577
  }
781
-
782
-
783
-
784
-
785
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_detectlanguage_1784235266"]
786
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_matchesglob_1784235266" type="function" identity="matchesglob" parent="none"]
787
- // CIL[DOC-MACRO purpose="Implements matchesglob logic in cortex.functions.custom_cil-ingest"]
788
- // CIL[DOC-RESPONSIBILITY responsibility="Execute matchesglob and return its computed result"]
789
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
790
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
791
- // CIL[DOC-MICRO logic_summary="Provides matchesglob with matchesGlob(filePath: string, pattern: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
792
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
793
- // CIL[DOC-STABILITY stability="stable"]
794
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
795
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
796
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
797
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
578
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the detectLanguage logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
579
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
580
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
581
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
798
582
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
799
583
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
584
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:detectlanguage:function"]
585
+
586
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:matchesglob:function" type="function" identity="matchesGlob" parent="none"]
587
+ // CIL[DOC-MACRO purpose="Implements the matchesGlob logic"]
588
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides matchesGlob functionality"]
589
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
590
+ // CIL[DOC-CONTRACT inputs="filePath: string, pattern: string" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
591
+ // CIL[DOC-MICRO logic_summary="Processes inputs (filePath: string, pattern: string) and returns the matchesGlob result" notable_decisions="See source for implementation details"]
592
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
593
+ // CIL[DOC-STABILITY stability="internal"]
800
594
  function matchesGlob(filePath: string, pattern: string): boolean {
801
595
  const regexStr = pattern
802
596
  .replace(/\./g, '\\.')
@@ -807,48 +601,44 @@ function matchesGlob(filePath: string, pattern: string): boolean {
807
601
  const re = new RegExp('^' + regexStr + '$')
808
602
  return re.test(filePath)
809
603
  }
810
-
811
-
812
-
813
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_matchesglob_1784235266"]
814
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_shouldinclude_1784235266" type="function" identity="shouldinclude" parent="none"]
815
- // CIL[DOC-MACRO purpose="Implements shouldinclude logic in cortex.functions.custom_cil-ingest"]
816
- // CIL[DOC-RESPONSIBILITY responsibility="Execute shouldinclude and return its computed result"]
817
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
818
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
819
- // CIL[DOC-MICRO logic_summary="Provides shouldinclude with shouldInclude(filePath: string, globs: string[], excludeGlobs: string[] inputs, handling internal flow and returning a result" notable_decisions="[]"]
820
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
821
- // CIL[DOC-STABILITY stability="stable"]
822
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
823
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
824
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
825
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
604
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the matchesGlob logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
605
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
606
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
607
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
826
608
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
827
609
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
610
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:matchesglob:function"]
611
+
612
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:shouldinclude:function" type="function" identity="shouldInclude" parent="none"]
613
+ // CIL[DOC-MACRO purpose="Implements the shouldInclude logic"]
614
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides shouldInclude functionality"]
615
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
616
+ // CIL[DOC-CONTRACT inputs="filePath: string, globs: string[], excludeGlobs: string[]" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
617
+ // CIL[DOC-MICRO logic_summary="Processes inputs (filePath: string, globs: string[], excludeGlobs: string[]) and returns the shouldInclude result" notable_decisions="See source for implementation details"]
618
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
619
+ // CIL[DOC-STABILITY stability="internal"]
828
620
  function shouldInclude(filePath: string, globs: string[], excludeGlobs: string[]): boolean {
829
621
  const normalised = filePath.replace(/\\/g, '/')
830
622
  const included = globs.some(g => matchesGlob(normalised, g) || matchesGlob(path.basename(normalised), g))
831
623
  const excluded = excludeGlobs.some(g => matchesGlob(normalised, g))
832
624
  return included && !excluded
833
625
  }
834
-
835
-
836
-
837
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_shouldinclude_1784235266"]
838
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_walkedfile_1784235266" type="interface" identity="walkedfile" parent="none"]
839
- // CIL[DOC-MACRO purpose="Defines the walkedfile type contract in cortex.functions.custom_cil-ingest"]
840
- // CIL[DOC-RESPONSIBILITY responsibility="Describe the shape and allowed fields for walkedfile"]
841
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
842
- // CIL[DOC-CONTRACT inputs="none" outputs="type definition for walkedfile" errors="none" side_effects="none"]
843
- // CIL[DOC-MICRO logic_summary="Declares TypeScript type/interface walkedfile with member definitions" notable_decisions="[]"]
844
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
845
- // CIL[DOC-STABILITY stability="stable"]
846
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
847
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
848
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
849
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
626
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the shouldInclude logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
627
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
628
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
629
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
850
630
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
851
631
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
632
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:shouldinclude:function"]
633
+
634
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:walkedfile:interface" type="interface" identity="WalkedFile" parent="none"]
635
+ // CIL[DOC-MACRO purpose="TypeScript interface defining WalkedFile"]
636
+ // CIL[DOC-RESPONSIBILITY responsibility="Describes the shape of WalkedFile"]
637
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
638
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
639
+ // CIL[DOC-MICRO logic_summary="Declares the fields and types for WalkedFile" notable_decisions="Structural contract for WalkedFile"]
640
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
641
+ // CIL[DOC-STABILITY stability="stable"]
852
642
  interface WalkedFile {
853
643
  path: string
854
644
  absPath: string
@@ -856,25 +646,22 @@ interface WalkedFile {
856
646
  extension: string
857
647
  language: string
858
648
  }
859
-
860
-
861
-
862
-
863
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_walkedfile_1784235266"]
864
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_walkdir_1784235266" type="function" identity="walkdir" parent="none"]
865
- // CIL[DOC-MACRO purpose="Implements walkdir logic in cortex.functions.custom_cil-ingest"]
866
- // CIL[DOC-RESPONSIBILITY responsibility="Execute walkdir and return its computed result"]
867
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
868
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
869
- // CIL[DOC-MICRO logic_summary="Provides walkdir with walkDir(dir: string, base: string, globs: string[], excludeGlobs: string[] inputs, handling internal flow and returning a result" notable_decisions="[]"]
870
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
871
- // CIL[DOC-STABILITY stability="stable"]
872
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
873
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
874
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
875
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
649
+ // CIL[DOC-VECTOR type="context" content="purpose='TypeScript interface defining WalkedFile'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
650
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
651
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
652
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
876
653
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
877
654
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
655
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:walkedfile:interface"]
656
+
657
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:walkdir:function" type="function" identity="walkDir" parent="none"]
658
+ // CIL[DOC-MACRO purpose="Implements the walkDir logic"]
659
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides walkDir functionality"]
660
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
661
+ // CIL[DOC-CONTRACT inputs="dir: string, base: string, globs: string[], excludeGlobs: string[]" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
662
+ // CIL[DOC-MICRO logic_summary="Processes inputs (dir: string, base: string, globs: string[], excludeGlobs: string[]) and returns the walkDir result" notable_decisions="See source for implementation details"]
663
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
664
+ // CIL[DOC-STABILITY stability="internal"]
878
665
  function walkDir(dir: string, base: string, globs: string[], excludeGlobs: string[]): WalkedFile[] {
879
666
  const results: WalkedFile[] = []
880
667
  let entries: fs.Dirent[]
@@ -903,64 +690,54 @@ function walkDir(dir: string, base: string, globs: string[], excludeGlobs: strin
903
690
  }
904
691
  return results
905
692
  }
906
-
907
-
908
-
909
-
910
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_walkdir_1784235266"]
911
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_parseexistingmarkers_1784235266" type="function" identity="parseexistingmarkers" parent="none"]
912
- // CIL[DOC-MACRO purpose="Implements parseexistingmarkers logic in cortex.functions.custom_cil-ingest"]
913
- // CIL[DOC-RESPONSIBILITY responsibility="Execute parseexistingmarkers and return its computed result"]
914
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
915
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
916
- // CIL[DOC-MICRO logic_summary="Provides parseexistingmarkers with parseExistingMarkers(lines: string[] inputs, handling internal flow and returning a result" notable_decisions="[]"]
917
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
918
- // CIL[DOC-STABILITY stability="stable"]
919
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
920
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
921
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
922
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
693
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the walkDir logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
694
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
695
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
696
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
923
697
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
924
698
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
925
- function parseExistingMarkers(lines: string[]): { name: string; line_start: number; line_end: number }[] {
926
- const markers: { name: string; line_start: number; line_end: number }[] = []
927
- const stack: { name: string; line_start: number }[] = []
699
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:walkdir:function"]
700
+
701
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:parseexistingmarkers:function" type="function" identity="parseExistingMarkers" parent="none"]
702
+ // CIL[DOC-STABILITY stability="internal"]
703
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
704
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
705
+ // CIL[DOC-MACRO purpose="Implements the parseExistingMarkers logic"]
706
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides parseExistingMarkers functionality"]
707
+ // CIL[DOC-CONTRACT inputs="lines: string[]" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
708
+ // CIL[DOC-MICRO logic_summary="Processes inputs (lines: string[]) and returns the parseExistingMarkers result" notable_decisions="See source for implementation details"]
709
+ function parseExistingMarkers(lines: string[]): { stable_id: string; line_start: number; line_end: number }[] {
710
+ const markers: { stable_id: string; line_start: number; line_end: number }[] = []
711
+ const stack: { stable_id: string; line_start: number }[] = []
928
712
  for (let i = 0; i < lines.length; i++) {
929
713
  const line = lines[i]
930
714
  const startMatch = line.match(MARKER_START_RE)
931
715
  const endMatch = line.match(MARKER_END_RE)
932
716
  if (startMatch) {
933
- stack.push({ name: startMatch[1], line_start: i + 1 })
717
+ stack.push({ stable_id: startMatch[1], line_start: i + 1 })
934
718
  } else if (endMatch && stack.length > 0) {
935
719
  const opened = stack.pop()!
936
- markers.push({ name: opened.name, line_start: opened.line_start, line_end: i + 1 })
720
+ markers.push({ stable_id: opened.stable_id, line_start: opened.line_start, line_end: i + 1 })
937
721
  }
938
722
  }
939
723
  return markers
940
724
  }
941
-
942
-
943
-
944
-
945
-
946
-
947
-
948
-
949
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_parseexistingmarkers_1784235266"]
950
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_extractedjsdoc_1784235266" type="interface" identity="extractedjsdoc" parent="none"]
951
- // CIL[DOC-MACRO purpose="Defines the extractedjsdoc type contract in cortex.functions.custom_cil-ingest"]
952
- // CIL[DOC-RESPONSIBILITY responsibility="Describe the shape and allowed fields for extractedjsdoc"]
953
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
954
- // CIL[DOC-CONTRACT inputs="none" outputs="type definition for extractedjsdoc" errors="none" side_effects="none"]
955
- // CIL[DOC-MICRO logic_summary="Declares TypeScript type/interface extractedjsdoc with member definitions" notable_decisions="[]"]
956
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
957
- // CIL[DOC-STABILITY stability="stable"]
958
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
959
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
960
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
961
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
725
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the parseExistingMarkers logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
726
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
727
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
728
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
962
729
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
963
730
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
731
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:parseexistingmarkers:function"]
732
+
733
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:extractedjsdoc:interface" type="interface" identity="ExtractedJsDoc" parent="none"]
734
+ // CIL[DOC-MACRO purpose="TypeScript interface defining ExtractedJsDoc"]
735
+ // CIL[DOC-RESPONSIBILITY responsibility="Describes the shape of ExtractedJsDoc"]
736
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
737
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
738
+ // CIL[DOC-MICRO logic_summary="Declares the fields and types for ExtractedJsDoc" notable_decisions="Structural contract for ExtractedJsDoc"]
739
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
740
+ // CIL[DOC-STABILITY stability="stable"]
964
741
  interface ExtractedJsDoc {
965
742
  raw: string
966
743
  description: string
@@ -987,24 +764,22 @@ interface ExtractedJsDoc {
987
764
  layer: string
988
765
  is_cil_generated: boolean
989
766
  }
990
-
991
-
992
-
993
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_extractedjsdoc_1784235266"]
994
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_extractjsdocabove_1784235266" type="function" identity="extractjsdocabove" parent="none"]
995
- // CIL[DOC-MACRO purpose="Implements extractjsdocabove logic in cortex.functions.custom_cil-ingest"]
996
- // CIL[DOC-RESPONSIBILITY responsibility="Execute extractjsdocabove and return its computed result"]
997
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
998
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
999
- // CIL[DOC-MICRO logic_summary="Provides extractjsdocabove with extractJsDocAbove(lines: string[], lineStart: number inputs, handling internal flow and returning a result" notable_decisions="[]"]
1000
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1001
- // CIL[DOC-STABILITY stability="stable"]
1002
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1003
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1004
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1005
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
767
+ // CIL[DOC-VECTOR type="context" content="purpose='TypeScript interface defining ExtractedJsDoc'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
768
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
769
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
770
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1006
771
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1007
772
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
773
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:extractedjsdoc:interface"]
774
+
775
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:extractjsdocabove:function" type="function" identity="extractJsDocAbove" parent="none"]
776
+ // CIL[DOC-MACRO purpose="Implements the extractJsDocAbove logic"]
777
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides extractJsDocAbove functionality"]
778
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
779
+ // CIL[DOC-CONTRACT inputs="lines: string[], lineStart: number" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
780
+ // CIL[DOC-MICRO logic_summary="Processes inputs (lines: string[], lineStart: number) and returns the extractJsDocAbove result" notable_decisions="See source for implementation details"]
781
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
782
+ // CIL[DOC-STABILITY stability="internal"]
1008
783
  function extractJsDocAbove(lines: string[], lineStart: number): ExtractedJsDoc | null {
1009
784
 
1010
785
  let endIdx = lineStart - 2
@@ -1021,7 +796,6 @@ function extractJsDocAbove(lines: string[], lineStart: number): ExtractedJsDoc |
1021
796
 
1022
797
  if (!endTrimmed.endsWith('*/')) return null
1023
798
 
1024
-
1025
799
  let startIdx = endIdx
1026
800
  for (let i = endIdx; i >= 0; i--) {
1027
801
  const t = lines[i].trim()
@@ -1029,7 +803,6 @@ function extractJsDocAbove(lines: string[], lineStart: number): ExtractedJsDoc |
1029
803
  if (i === 0) return null
1030
804
  }
1031
805
 
1032
-
1033
806
  const bodyLines: string[] = []
1034
807
  for (let i = startIdx; i <= endIdx; i++) {
1035
808
  const raw = lines[i]
@@ -1043,21 +816,25 @@ function extractJsDocAbove(lines: string[], lineStart: number): ExtractedJsDoc |
1043
816
  const raw = bodyLines.join('\n').trim()
1044
817
  if (!raw) return null
1045
818
 
1046
-
1047
- const get = (tags: string[]): string => {
819
+ const get = (tags: string[], preserveLines = false): string => {
1048
820
  for (const tag of tags) {
1049
821
  const re = new RegExp(`@${tag}\\s+(.+?)(?=\\n@|$)`, 'si')
1050
822
  const m = raw.match(re)
1051
- if (m) return m[1].replace(/\n\s*\*?\s*/g, ' ').trim()
823
+ if (!m) continue
824
+ if (preserveLines) {
825
+ // Multi-entry specs (one parameter per line) must keep their line
826
+ // breaks — splitParameterList in cil-doc splits on ',' and '\n', so
827
+ // flattening merges all params into a single unparseable blob.
828
+ return m[1].split('\n').map(s => s.trim()).filter(Boolean).join('\n')
829
+ }
830
+ return m[1].replace(/\n\s*\*?\s*/g, ' ').trim()
1052
831
  }
1053
832
  return ''
1054
833
  }
1055
834
 
1056
-
1057
835
  const descMatch = raw.match(/^([\s\S]*?)(?=@\w|$)/)
1058
836
  const description = descMatch ? descMatch[1].trim() : ''
1059
837
 
1060
-
1061
838
  const paramLines: string[] = []
1062
839
  for (const m of raw.matchAll(/@param\s+(.+?)(?=\n@|\n\n|$)/gsi)) {
1063
840
  paramLines.push(m[1].replace(/\n\s*\*?\s*/g, ' ').trim())
@@ -1066,15 +843,15 @@ function extractJsDocAbove(lines: string[], lineStart: number): ExtractedJsDoc |
1066
843
  return {
1067
844
  raw,
1068
845
  description,
1069
- params: paramLines.join('; '),
846
+ params: paramLines.join('\n'),
1070
847
  returns: get(['returns', 'return']),
1071
848
  throws: get(['throws', 'throw']),
1072
849
  side_effects: get(['sideEffects', 'side-effects', 'sideeffects']),
1073
850
  stability: get(['stability']),
1074
851
  macro: get(['macro']),
1075
852
  micro: get(['micro']),
1076
- input_spec: get(['inputSpec', 'inputs', 'input_spec']),
1077
- output_spec: get(['outputSpec', 'outputs', 'output_spec']),
853
+ input_spec: get(['inputSpec', 'inputs', 'input_spec'], true),
854
+ output_spec: get(['outputSpec', 'outputs', 'output_spec'], true),
1078
855
 
1079
856
  called_by: get(['calledBy', 'called_by']),
1080
857
  calls: get(['calls']),
@@ -1090,25 +867,22 @@ function extractJsDocAbove(lines: string[], lineStart: number): ExtractedJsDoc |
1090
867
  is_cil_generated: raw.includes('@cil-generated'),
1091
868
  }
1092
869
  }
1093
-
1094
-
1095
-
1096
-
1097
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_extractjsdocabove_1784235266"]
1098
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_extractfilejsdoc_1784235266" type="function" identity="extractfilejsdoc" parent="none"]
1099
- // CIL[DOC-MACRO purpose="Implements extractfilejsdoc logic in cortex.functions.custom_cil-ingest"]
1100
- // CIL[DOC-RESPONSIBILITY responsibility="Execute extractfilejsdoc and return its computed result"]
1101
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
1102
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
1103
- // CIL[DOC-MICRO logic_summary="Provides extractfilejsdoc with extractFileJsDoc(lines: string[] inputs, handling internal flow and returning a result" notable_decisions="[]"]
1104
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1105
- // CIL[DOC-STABILITY stability="stable"]
1106
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1107
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1108
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1109
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
870
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the extractJsDocAbove logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
871
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
872
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
873
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1110
874
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1111
875
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
876
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:extractjsdocabove:function"]
877
+
878
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:extractfilejsdoc:function" type="function" identity="extractFileJsDoc" parent="none"]
879
+ // CIL[DOC-MACRO purpose="Implements the extractFileJsDoc logic"]
880
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides extractFileJsDoc functionality"]
881
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
882
+ // CIL[DOC-CONTRACT inputs="lines: string[]" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
883
+ // CIL[DOC-MICRO logic_summary="Processes inputs (lines: string[]) and returns the extractFileJsDoc result" notable_decisions="See source for implementation details"]
884
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
885
+ // CIL[DOC-STABILITY stability="internal"]
1112
886
  function extractFileJsDoc(lines: string[]): string {
1113
887
  let inBlock = false
1114
888
  const bodyLines: string[] = []
@@ -1124,262 +898,354 @@ function extractFileJsDoc(lines: string[]): string {
1124
898
  }
1125
899
  return bodyLines.join('\n')
1126
900
  }
1127
-
1128
-
1129
-
1130
-
1131
-
1132
-
1133
-
1134
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_extractfilejsdoc_1784235266"]
1135
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_rawproposal_1784235266" type="interface" identity="rawproposal" parent="none"]
1136
- // CIL[DOC-MACRO purpose="Defines the rawproposal type contract in cortex.functions.custom_cil-ingest"]
1137
- // CIL[DOC-RESPONSIBILITY responsibility="Describe the shape and allowed fields for rawproposal"]
1138
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
1139
- // CIL[DOC-CONTRACT inputs="none" outputs="type definition for rawproposal" errors="none" side_effects="none"]
1140
- // CIL[DOC-MICRO logic_summary="Declares TypeScript type/interface rawproposal with member definitions" notable_decisions="[]"]
1141
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1142
- // CIL[DOC-STABILITY stability="stable"]
1143
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1144
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1145
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1146
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
901
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the extractFileJsDoc logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
902
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
903
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
904
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1147
905
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1148
906
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
907
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:extractfilejsdoc:function"]
908
+
909
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:rawproposal:interface" type="interface" identity="RawProposal" parent="none"]
910
+ // CIL[DOC-MACRO purpose="TypeScript interface defining RawProposal"]
911
+ // CIL[DOC-RESPONSIBILITY responsibility="Describes the shape of RawProposal"]
912
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
913
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
914
+ // CIL[DOC-MICRO logic_summary="Declares the fields and types for RawProposal" notable_decisions="Structural contract for RawProposal"]
915
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
916
+ // CIL[DOC-STABILITY stability="stable"]
1149
917
  interface RawProposal {
1150
918
  name: string
919
+ stable_id: string
920
+ parent_stable_id: string
1151
921
  line_start: number
1152
922
  line_end: number
1153
-
1154
-
1155
-
1156
923
  marker_line_end: number
1157
924
  chunk_type: string
1158
925
  confidence_score: number
1159
926
  confidence_reasons: string[]
1160
927
  existing_jsdoc?: ExtractedJsDoc | null
1161
928
  }
1162
-
1163
-
1164
-
1165
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_rawproposal_1784235266"]
1166
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_proposechunksfromsource_1784235266" type="function" identity="proposechunksfromsource" parent="none"]
1167
- // CIL[DOC-MACRO purpose="Implements proposechunksfromsource logic in cortex.functions.custom_cil-ingest"]
1168
- // CIL[DOC-RESPONSIBILITY responsibility="Execute proposechunksfromsource and return its computed result"]
1169
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
1170
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
1171
- // CIL[DOC-MICRO logic_summary="Provides proposechunksfromsource with proposeChunksFromSource(lines: string[], language: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
1172
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1173
- // CIL[DOC-STABILITY stability="stable"]
1174
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1175
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1176
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1177
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
929
+ // CIL[DOC-VECTOR type="context" content="purpose='TypeScript interface defining RawProposal'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
930
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
931
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
932
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1178
933
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1179
934
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1180
- function proposeChunksFromSource(lines: string[], language: string): RawProposal[] {
935
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:rawproposal:interface"]
936
+
937
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:proposechunksfromsource:function" type="function" identity="proposeChunksFromSource" parent="none"]
938
+ // CIL[DOC-MACRO purpose="Implements the proposeChunksFromSource logic"]
939
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides proposeChunksFromSource functionality"]
940
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
941
+ // CIL[DOC-CONTRACT inputs="content: string, lines: string[], language: string, canonicalPath: string" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="none"]
942
+ // CIL[DOC-MICRO logic_summary="Processes inputs (content: string, lines: string[], language: string, canonicalPath: string) and returns the proposeChunksFromSource result" notable_decisions="See source for implementation details"]
943
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
944
+ // CIL[DOC-STABILITY stability="internal"]
945
+ function proposeChunksFromSource(content: string, lines: string[], language: string, canonicalPath: string): RawProposal[] {
1181
946
  const proposals: RawProposal[] = []
1182
- if (!['typescript', 'javascript'].includes(language)) return proposals
947
+ if (['typescript', 'typescriptreact', 'javascript', 'javascriptreact'].includes(language)) {
1183
948
 
1184
-
1185
- let jsDocStart = -1, jsDocEnd = -1
1186
- for (let i = 0; i < lines.length; i++) {
1187
- const t = lines[i].trim()
1188
- if (t === '') continue
1189
- if ((t.startsWith('/**') || t.startsWith('/*')) && jsDocStart === -1) {
1190
- jsDocStart = i
1191
- } else if (jsDocStart !== -1 && t.endsWith('*/') && jsDocEnd === -1) {
1192
- jsDocEnd = i
1193
- } else if (jsDocStart === -1 && !t.startsWith('//') && !t.startsWith('/*')) {
1194
- break
949
+
950
+ let headerStart = -1
951
+
952
+
953
+ let headerEnd = -1
954
+
955
+ for (let i = 0; i < lines.length; i++) {
956
+ const t = lines[i].trim()
957
+ if (t.startsWith('import')) {
958
+ if (headerStart === -1) headerStart = i
959
+ headerEnd = i
960
+ continue
961
+ }
962
+ if (t === '' && headerStart !== -1) continue
963
+ if (headerStart !== -1) break
1195
964
  }
1196
- }
965
+ const scriptKind =
966
+ language === 'typescript' ? ts.ScriptKind.TS :
967
+ language === 'typescriptreact' ? ts.ScriptKind.TSX :
968
+ language === 'javascript' ? ts.ScriptKind.JS :
969
+ ts.ScriptKind.JSX
970
+ const sourceFile = ts.createSourceFile(canonicalPath, content, ts.ScriptTarget.Latest, true, scriptKind)
971
+ const identities = extractIdentities(sourceFile, canonicalPath)
972
+ const baseScore: Record<string, number> = {
973
+ function: 0.92,
974
+ hook: 0.94,
975
+ component: 0.94,
976
+ class: 0.90,
977
+ method: 0.85,
978
+ interface: 0.90,
979
+ type: 0.88,
980
+ variable: 0.70,
981
+ constant: 0.85,
982
+ module_header: 0.99,
983
+ }
984
+ for (const identity of identities) {
985
+ if (identity.identity === 'file' && identity.type === 'file') continue
986
+ const line = lines[identity.line_start - 1] || ''
987
+ const lineCount = identity.line_end - identity.line_start + 1
1197
988
 
1198
- const headerStart = jsDocStart >= 0 ? jsDocStart : 0
1199
- let headerEnd = jsDocEnd >= 0 ? jsDocEnd : headerStart - 1
1200
989
 
1201
-
1202
-
1203
- const DECL_RE = /^(?:export\s+)?(?:async\s+)?(?:function|class|interface)\s+\w+/
1204
- const EXPORT_DECL_RE = /^export\s+(?:default\s+)?(?:async\s+)?(?:function|class|interface|type|const|let|var)\s+\w+/
1205
- const startScan = Math.max(headerEnd + 1, 0)
990
+ let score = baseScore[identity.type] || 0.70
1206
991
 
1207
- for (let i = startScan; i < lines.length; i++) {
1208
- const t = lines[i].trim()
1209
- if (t === '' || t.startsWith('//')) continue
1210
- if (t.startsWith('import')) continue
1211
- if (EXPORT_DECL_RE.test(lines[i]) || DECL_RE.test(lines[i])) {
1212
- headerEnd = i - 1
1213
- break
992
+ const reasons: string[] = []
993
+ if (line.includes('export')) { score += 0.05; reasons.push('exported symbol') }
994
+ const existingJsDoc = extractJsDocAbove(lines, identity.line_start)
995
+ if (existingJsDoc) { score += 0.10; reasons.push('has JSDoc') }
996
+ if (lineCount > 200) { score -= 0.10; reasons.push('very large (>200 lines)') }
997
+ if (['function', 'hook', 'component'].includes(identity.type) && !line.match(/function\s+\w+/) && !line.match(/class\s+\w+/) && !line.match(/interface\s+\w+/)) {
998
+ score -= 0.05; reasons.push('arrow/assigned function')
999
+ }
1000
+
1001
+ score = Math.min(0.99, Math.max(0.1, score))
1002
+ const isModuleHeader = identity.identity === 'module_header'
1003
+ if (isModuleHeader && headerStart === -1) continue
1004
+ const lineStart = isModuleHeader ? headerStart + 1 : identity.line_start
1005
+ const endLine = isModuleHeader ? headerEnd + 1 : identity.line_end
1006
+ const markerEndLine = endLine
1007
+ proposals.push({
1008
+ name: identity.identity,
1009
+ stable_id: generateStableId(canonicalPath, identity.identity, identity.type),
1010
+ parent_stable_id: identity.parent,
1011
+ line_start: lineStart,
1012
+ line_end: endLine,
1013
+ marker_line_end: markerEndLine,
1014
+ chunk_type: identity.type,
1015
+ confidence_score: score,
1016
+ confidence_reasons: reasons,
1017
+ existing_jsdoc: existingJsDoc,
1018
+ })
1214
1019
  }
1215
- }
1020
+ } else {
1216
1021
 
1217
-
1218
- while (headerEnd > headerStart && lines[headerEnd].trim() === '') {
1219
- headerEnd--
1220
- }
1221
1022
 
1222
- if (headerEnd >= headerStart) {
1223
- proposals.push({
1224
- name: '__module_header__',
1225
- line_start: headerStart + 1,
1226
- line_end: headerEnd + 1,
1227
- marker_line_end: headerEnd + 1,
1228
- chunk_type: 'module_header',
1229
- confidence_score: 0.99,
1230
- confidence_reasons: ['file-level JSDoc, imports, and module setup'],
1231
- existing_jsdoc: null,
1232
- })
1233
- }
1023
+ let jsDocStart = -1, jsDocEnd = -1
1234
1024
 
1235
-
1236
- const scanStart = headerEnd >= 0 ? headerEnd + 1 : 0
1025
+ for (let i = 0; i < lines.length; i++) {
1026
+ const t = lines[i].trim()
1027
+ if (t === '') continue
1028
+ if ((t.startsWith('/**') || t.startsWith('/*')) && jsDocStart === -1) {
1029
+ jsDocStart = i
1030
+ } else if (jsDocStart !== -1 && t.endsWith('*/') && jsDocEnd === -1) {
1031
+ jsDocEnd = i
1032
+ } else if (jsDocStart === -1 && !t.startsWith('//') && !t.startsWith('/*')) {
1033
+ break
1034
+ }
1035
+ }
1237
1036
 
1238
-
1239
- const patterns: { re: RegExp; type: string; baseScore: number; nameGroup: number }[] = [
1240
-
1241
- { re: /^export\s+(?:default\s+)?(?:async\s+)?function\s+(\w+)/m, type: 'function', baseScore: 0.92, nameGroup: 1 },
1242
-
1243
- { re: /^export\s+const\s+(\w+)\s*[=:]/m, type: 'constant', baseScore: 0.85, nameGroup: 1 },
1244
-
1245
- { re: /^export\s+(?:let|var)\s+(\w+)\s*[=:]/m, type: 'constant', baseScore: 0.82, nameGroup: 1 },
1246
-
1247
- { re: /^export\s+(?:default\s+)?(?:abstract\s+)?class\s+(\w+)/m, type: 'class', baseScore: 0.90, nameGroup: 1 },
1248
-
1249
- { re: /^export\s+interface\s+(\w+)/m, type: 'interface', baseScore: 0.90, nameGroup: 1 },
1250
-
1251
- { re: /^export\s+type\s+(\w+)/m, type: 'type', baseScore: 0.88, nameGroup: 1 },
1252
-
1253
- { re: /^(?:async\s+)?function\s+(\w+)/m, type: 'function', baseScore: 0.78, nameGroup: 1 },
1254
-
1255
- { re: /^(?:abstract\s+)?class\s+(\w+)/m, type: 'class', baseScore: 0.80, nameGroup: 1 },
1256
-
1257
- { re: /^interface\s+(\w+)/m, type: 'interface', baseScore: 0.80, nameGroup: 1 },
1258
-
1259
- { re: /^type\s+(\w+)\s*=/m, type: 'type', baseScore: 0.78, nameGroup: 1 },
1260
-
1261
- { re: /^(?:const|let|var)\s+(\w+)\s*[=:]/m, type: 'constant', baseScore: 0.70, nameGroup: 1 },
1262
- ]
1263
1037
 
1264
-
1265
- let lineIdx = scanStart
1266
- while (lineIdx < lines.length) {
1267
- const line = lines[lineIdx]
1268
- let matched = false
1038
+ const headerStart = jsDocStart >= 0 ? jsDocStart : 0
1269
1039
 
1270
- for (const { re, type, baseScore, nameGroup } of patterns) {
1271
- const m = line.match(re)
1272
- if (m) {
1273
- const name = m[nameGroup]
1274
- if (!name) { lineIdx++; break }
1275
1040
 
1276
-
1277
-
1278
-
1279
-
1280
- let braceDepth = 0
1281
- let parenDepth = 0
1282
- let angleDepth = 0
1283
- let endLine = lineIdx
1284
- let foundOpen = false
1285
- let inString = false
1286
- let stringChar = ''
1287
-
1288
- for (let j = lineIdx; j < Math.min(lines.length, lineIdx + 500); j++) {
1289
- const l = lines[j]
1290
- let inLineComment = false
1291
- let inBlockComment = false
1292
- for (let ci = 0; ci < l.length; ci++) {
1293
- const c = l[ci]
1294
- const next = l[ci + 1]
1295
- const prev = l[ci - 1]
1296
-
1297
- if (inString) {
1298
- if (c === stringChar && prev !== '\\') inString = false
1299
- continue
1300
- }
1041
+ let headerEnd = jsDocEnd >= 0 ? jsDocEnd : headerStart - 1
1301
1042
 
1302
- if (inLineComment) continue
1303
- if (inBlockComment) {
1304
- if (c === '*' && next === '/') { inBlockComment = false; ci++ }
1305
- continue
1306
- }
1307
1043
 
1308
- if (c === '/' && next === '/') { inLineComment = true; ci++; continue }
1309
- if (c === '/' && next === '*') { inBlockComment = true; ci++; continue }
1044
+ const DECL_RE = /^(?:export\s+)?(?:async\s+)?(?:function|class|interface|const|let|var)\s+\w+/
1045
+ const EXPORT_DECL_RE = /^export\s+(?:default\s+)?(?:async\s+)?(?:function|class|interface|type|const|let|var)\s+\w+/
1046
+ const startScan = Math.max(headerEnd + 1, 0)
1310
1047
 
1311
- if (c === '"' || c === "'") { inString = true; stringChar = c; continue }
1312
- if (c === '`') { inString = true; stringChar = '`'; continue }
1048
+ for (let i = startScan; i < lines.length; i++) {
1049
+ const t = lines[i].trim()
1050
+ if (t === '' || t.startsWith('//')) continue
1051
+ if (t.startsWith('import')) continue
1052
+ if (EXPORT_DECL_RE.test(lines[i]) || DECL_RE.test(lines[i])) {
1053
+ headerEnd = i - 1
1054
+ break
1055
+ }
1056
+ }
1313
1057
 
1314
-
1315
- if (c === '(') { parenDepth++; continue }
1316
- if (c === ')') { parenDepth--; continue }
1317
- if (c === '<' && prev !== '=' && next !== '=') { angleDepth++; continue }
1318
- if (c === '>' && prev !== '=' && next !== '=') { angleDepth--; continue }
1319
-
1320
- if (c === '{') {
1321
- if (!foundOpen && (parenDepth !== 0 || angleDepth !== 0)) {
1322
-
1058
+
1059
+ while (headerEnd > headerStart && lines[headerEnd].trim() === '') {
1060
+ headerEnd--
1061
+ }
1062
+
1063
+ if (headerEnd >= headerStart) {
1064
+ proposals.push({
1065
+ name: '__module_header__',
1066
+ stable_id: generateStableId(canonicalPath, '__module_header__', 'module_header'),
1067
+ parent_stable_id: canonicalPath,
1068
+ line_start: headerStart + 1,
1069
+ line_end: headerEnd + 1,
1070
+ marker_line_end: headerEnd + 1,
1071
+ chunk_type: 'module_header',
1072
+ confidence_score: 0.99,
1073
+ confidence_reasons: ['file-level JSDoc, imports, and module setup'],
1074
+ existing_jsdoc: null,
1075
+ })
1076
+ }
1077
+
1078
+ const scanStart = headerEnd >= 0 ? headerEnd + 1 : 0
1079
+
1080
+ const patterns: { re: RegExp; type: string; baseScore: number; nameGroup: number }[] = [
1081
+ { re: /^export\s+(?:default\s+)?(?:async\s+)?function\s+(\w+)/m, type: 'function', baseScore: 0.92, nameGroup: 1 },
1082
+ { re: /^export\s+const\s+(\w+)\s*[=:]/m, type: 'constant', baseScore: 0.85, nameGroup: 1 },
1083
+ { re: /^export\s+(?:let|var)\s+(\w+)\s*[=:]/m, type: 'constant', baseScore: 0.82, nameGroup: 1 },
1084
+ { re: /^export\s+(?:default\s+)?(?:abstract\s+)?class\s+(\w+)/m, type: 'class', baseScore: 0.90, nameGroup: 1 },
1085
+ { re: /^export\s+interface\s+(\w+)/m, type: 'interface', baseScore: 0.90, nameGroup: 1 },
1086
+ { re: /^export\s+type\s+(\w+)/m, type: 'type', baseScore: 0.88, nameGroup: 1 },
1087
+ { re: /^(?:async\s+)?function\s+(\w+)/m, type: 'function', baseScore: 0.78, nameGroup: 1 },
1088
+ { re: /^(?:abstract\s+)?class\s+(\w+)/m, type: 'class', baseScore: 0.80, nameGroup: 1 },
1089
+ { re: /^interface\s+(\w+)/m, type: 'interface', baseScore: 0.80, nameGroup: 1 },
1090
+ { re: /^type\s+(\w+)\s*=/m, type: 'type', baseScore: 0.78, nameGroup: 1 },
1091
+ { re: /^(?:const|let|var)\s+(\w+)\s*[=:]/m, type: 'constant', baseScore: 0.70, nameGroup: 1 },
1092
+ ]
1093
+
1094
+
1095
+
1096
+ let lineIdx = scanStart
1097
+
1098
+ while (lineIdx < lines.length) {
1099
+ const line = lines[lineIdx]
1100
+
1101
+
1102
+ let matched = false
1103
+
1104
+
1105
+ for (const { re, type, baseScore, nameGroup } of patterns) {
1106
+ const m = line.match(re)
1107
+ if (m) {
1108
+ const name = m[nameGroup]
1109
+ if (!name) { lineIdx++; break }
1110
+
1111
+
1112
+
1113
+ let braceDepth = 0
1114
+
1115
+
1116
+
1117
+ let parenDepth = 0
1118
+
1119
+
1120
+
1121
+ let angleDepth = 0
1122
+
1123
+
1124
+
1125
+ let endLine = lineIdx
1126
+
1127
+
1128
+
1129
+ let foundOpen = false
1130
+
1131
+
1132
+
1133
+ let inString = false
1134
+
1135
+
1136
+
1137
+ let stringChar = ''
1138
+
1139
+
1140
+ for (let j = lineIdx; j < Math.min(lines.length, lineIdx + 500); j++) {
1141
+ const l = lines[j]
1142
+
1143
+
1144
+ let inLineComment = false
1145
+
1146
+
1147
+
1148
+ let inBlockComment = false
1149
+
1150
+ for (let ci = 0; ci < l.length; ci++) {
1151
+ const c = l[ci]
1152
+ const next = l[ci + 1]
1153
+ const prev = l[ci - 1]
1154
+
1155
+ if (inString) {
1156
+ if (c === stringChar && prev !== '\\') inString = false
1157
+ continue
1158
+ }
1159
+
1160
+ if (inLineComment) continue
1161
+ if (inBlockComment) {
1162
+ if (c === '*' && next === '/') { inBlockComment = false; ci++ }
1323
1163
  continue
1324
1164
  }
1325
- braceDepth++; foundOpen = true
1165
+
1166
+ if (c === '/' && next === '/') { inLineComment = true; ci++; continue }
1167
+ if (c === '/' && next === '*') { inBlockComment = true; ci++; continue }
1168
+
1169
+ if (c === '"' || c === "'") { inString = true; stringChar = c; continue }
1170
+ if (c === '`') { inString = true; stringChar = '`'; continue }
1171
+
1172
+ if (c === '(') { parenDepth++; continue }
1173
+ if (c === ')') { parenDepth--; continue }
1174
+ if (c === '<' && prev !== '=' && next !== '=') { angleDepth++; continue }
1175
+ if (c === '>' && prev !== '=' && next !== '=') { angleDepth--; continue }
1176
+
1177
+ if (c === '{') {
1178
+ if (!foundOpen && (parenDepth !== 0 || angleDepth !== 0)) {
1179
+ continue
1180
+ }
1181
+ braceDepth++; foundOpen = true
1182
+ }
1183
+ if (c === '}') {
1184
+ if (!foundOpen) continue
1185
+ braceDepth--
1186
+ }
1326
1187
  }
1327
- if (c === '}') {
1328
- if (!foundOpen) continue
1329
- braceDepth--
1188
+
1189
+
1190
+
1191
+ if (foundOpen && braceDepth === 0) {
1192
+ endLine = j
1193
+ break
1330
1194
  }
1331
1195
  }
1332
1196
 
1333
- if (foundOpen && braceDepth === 0) {
1334
- endLine = j
1335
- break
1197
+
1198
+
1199
+
1200
+
1201
+
1202
+
1203
+
1204
+ const lineCount = endLine - lineIdx + 1
1205
+ if (lineCount < 3) { lineIdx++; matched = true; break }
1206
+
1207
+ const confidenceReasons: string[] = []
1208
+
1209
+
1210
+ let score = baseScore
1211
+
1212
+ const existingJsDoc = extractJsDocAbove(lines, lineIdx + 1)
1213
+
1214
+ if (line.includes('export')) { score += 0.05; confidenceReasons.push('exported symbol') }
1215
+ if (existingJsDoc) { score += 0.10; confidenceReasons.push('has JSDoc') }
1216
+ if (lineCount > 200) { score -= 0.10; confidenceReasons.push('very large (>200 lines)') }
1217
+ if (!line.match(/function\s+\w+/) && !line.match(/class\s+\w+/) && !line.match(/interface\s+\w+/)) {
1218
+ score -= 0.05; confidenceReasons.push('arrow/assigned function')
1336
1219
  }
1337
- }
1338
1220
 
1339
-
1340
- const lineCount = endLine - lineIdx + 1
1341
- if (lineCount < 3) { lineIdx++; matched = true; break }
1342
1221
 
1343
- const confidenceReasons: string[] = []
1344
- let score = baseScore
1222
+ score = Math.min(0.99, Math.max(0.1, score))
1345
1223
 
1346
-
1347
- const existingJsDoc = extractJsDocAbove(lines, lineIdx + 1)
1224
+ proposals.push({
1225
+ name,
1226
+ stable_id: generateStableId(canonicalPath, name, type),
1227
+ parent_stable_id: canonicalPath,
1228
+ line_start: lineIdx + 1,
1229
+ line_end: endLine + 1,
1230
+ marker_line_end: endLine + 1,
1231
+ chunk_type: type,
1232
+ confidence_score: score,
1233
+ confidence_reasons: confidenceReasons,
1234
+ existing_jsdoc: existingJsDoc,
1235
+ })
1348
1236
 
1349
-
1350
- if (line.includes('export')) { score += 0.05; confidenceReasons.push('exported symbol') }
1351
-
1352
- if (existingJsDoc) { score += 0.10; confidenceReasons.push('has JSDoc') }
1353
-
1354
- if (lineCount > 200) { score -= 0.10; confidenceReasons.push('very large (>200 lines)') }
1355
-
1356
- if (!line.match(/function\s+\w+/) && !line.match(/class\s+\w+/) && !line.match(/interface\s+\w+/)) {
1357
- score -= 0.05; confidenceReasons.push('arrow/assigned function')
1237
+ lineIdx = endLine + 1
1238
+ matched = true
1239
+ break
1358
1240
  }
1241
+ }
1359
1242
 
1360
- score = Math.min(0.99, Math.max(0.1, score))
1361
-
1362
- proposals.push({
1363
- name,
1364
- line_start: lineIdx + 1,
1365
- line_end: endLine + 1,
1366
- marker_line_end: endLine + 1, // set here; never modified by gap-filling below
1367
- chunk_type: type,
1368
- confidence_score: score,
1369
- confidence_reasons: confidenceReasons,
1370
- existing_jsdoc: existingJsDoc,
1371
- })
1372
1243
 
1373
- lineIdx = endLine + 1
1374
- matched = true
1375
- break
1376
- }
1244
+ if (!matched) lineIdx++
1377
1245
  }
1378
1246
 
1379
- if (!matched) lineIdx++
1380
1247
  }
1381
1248
 
1382
-
1383
1249
  const deduped: RawProposal[] = []
1384
1250
  for (const p of proposals.sort((a, b) => b.confidence_score - a.confidence_score)) {
1385
1251
  const overlaps = deduped.some(d =>
@@ -1392,17 +1258,17 @@ function proposeChunksFromSource(lines: string[], language: string): RawProposal
1392
1258
 
1393
1259
  if (sorted.length === 0) return []
1394
1260
 
1395
-
1396
-
1397
-
1398
-
1399
-
1400
-
1401
1261
  for (let i = sorted.length - 1; i >= 0; i--) {
1402
1262
  const curr = sorted[i]
1403
1263
  const prevEnd = i > 0 ? sorted[i - 1].marker_line_end : 0
1264
+
1265
+
1404
1266
  let foundComment = false
1267
+
1268
+
1269
+
1405
1270
  let candidateStart = curr.line_start
1271
+
1406
1272
  for (let j = curr.line_start - 2; j >= prevEnd; j--) {
1407
1273
  const t = lines[j].trim()
1408
1274
  if (t === '') continue
@@ -1413,15 +1279,13 @@ function proposeChunksFromSource(lines: string[], language: string): RawProposal
1413
1279
  }
1414
1280
  break
1415
1281
  }
1282
+
1283
+
1416
1284
  if (foundComment) curr.line_start = candidateStart
1417
1285
  }
1418
1286
 
1419
-
1420
1287
  sorted[0].line_start = 1
1421
1288
 
1422
-
1423
-
1424
-
1425
1289
  for (let i = 1; i < sorted.length; i++) {
1426
1290
  const prev = sorted[i - 1]
1427
1291
  const curr = sorted[i]
@@ -1430,7 +1294,6 @@ function proposeChunksFromSource(lines: string[], language: string): RawProposal
1430
1294
  }
1431
1295
  }
1432
1296
 
1433
-
1434
1297
  const last = sorted[sorted.length - 1]
1435
1298
  if (last.line_end < lines.length) {
1436
1299
  last.line_end = lines.length
@@ -1438,26 +1301,22 @@ function proposeChunksFromSource(lines: string[], language: string): RawProposal
1438
1301
 
1439
1302
  return sorted
1440
1303
  }
1441
-
1442
-
1443
-
1444
-
1445
-
1446
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_proposechunksfromsource_1784235266"]
1447
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_pass1discover_1784235266" type="function" identity="pass1discover" parent="none"]
1448
- // CIL[DOC-MACRO purpose="Implements pass1discover logic in cortex.functions.custom_cil-ingest"]
1449
- // CIL[DOC-RESPONSIBILITY responsibility="Execute pass1discover and return its computed result"]
1450
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
1451
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
1452
- // CIL[DOC-MICRO logic_summary="Provides pass1discover with pass1Discover( inputs, handling internal flow and returning a result" notable_decisions="[]"]
1453
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1454
- // CIL[DOC-STABILITY stability="stable"]
1455
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1456
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1457
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1458
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
1304
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the proposeChunksFromSource logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1305
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1306
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1307
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1459
1308
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1460
1309
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1310
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:proposechunksfromsource:function"]
1311
+
1312
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:pass1discover:function" type="function" identity="pass1Discover" parent="none"]
1313
+ // CIL[DOC-MACRO purpose="Implements the pass1Discover logic"]
1314
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides pass1Discover functionality"]
1315
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
1316
+ // CIL[DOC-CONTRACT inputs="ctx: any, projectId: string, repoPath: string, globs: string[], excludeGlobs: string[], _forceReprocess: boolean, sourceSets?: SourceSet[]" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="executes database queries and updates and reads files from disk"]
1317
+ // CIL[DOC-MICRO logic_summary="Processes inputs (arguments as defined in source) and returns the pass1Discover result" notable_decisions="See source for implementation details"]
1318
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
1319
+ // CIL[DOC-STABILITY stability="internal"]
1461
1320
  async function pass1Discover(
1462
1321
  ctx: any,
1463
1322
  projectId: string,
@@ -1470,7 +1329,6 @@ async function pass1Discover(
1470
1329
  const errors: string[] = []
1471
1330
  let filesDiscovered = 0
1472
1331
 
1473
-
1474
1332
  const discoveryTargets: { sourceSetId?: string; layer?: string; basePath: string; globs: string[]; excludeGlobs: string[] }[] = []
1475
1333
  if (sourceSets && sourceSets.length > 0) {
1476
1334
  for (const ss of sourceSets) {
@@ -1487,8 +1345,23 @@ async function pass1Discover(
1487
1345
  discoveryTargets.push({ basePath: repoPath, globs, excludeGlobs })
1488
1346
  }
1489
1347
 
1490
-
1491
1348
  const treeRecords: { file_path: string; language: string; status?: FileStatus; extension: string }[] = []
1349
+ const newRows: any[] = []
1350
+
1351
+ const fileTypeId = await resolveTypeId('item', 'cil_file')
1352
+ const { data: projItem } = await adminDb
1353
+ .from('items').select('id, data').eq('id', projectId).maybeSingle()
1354
+ const versionId = projItem?.data?.active_version_id || projItem?.data?.default_version_id || 'default'
1355
+
1356
+ const { data: existingFiles } = await adminDb
1357
+ .from('items')
1358
+ .select('id, title, data')
1359
+ .filter('data->>project_id', 'eq', projectId)
1360
+ .filter('data->>kb_type', 'eq', 'cil_file')
1361
+ .eq('is_active', true)
1362
+ const existingPaths = new Set<string>(
1363
+ (existingFiles || []).map((f: any) => f.data?.file_path || f.title).filter(Boolean)
1364
+ )
1492
1365
 
1493
1366
  for (const target of discoveryTargets) {
1494
1367
  const files = walkDir(target.basePath, target.basePath, target.globs, target.excludeGlobs)
@@ -1499,22 +1372,72 @@ async function pass1Discover(
1499
1372
  language: file.language,
1500
1373
  extension: file.extension,
1501
1374
  })
1375
+
1376
+ if (!existingPaths.has(file.path)) {
1377
+ const absPath = path.join(repoPath, file.path)
1378
+ const content = fs.readFileSync(absPath, 'utf-8')
1379
+ const contentHash = computeContentHash(content)
1380
+ const canonical = toCanonicalPath(repoPath, absPath)
1381
+ newRows.push({
1382
+ type_id: fileTypeId,
1383
+ account_id: ctx.accountId,
1384
+ title: file.path,
1385
+ status: 'active',
1386
+ is_active: true,
1387
+ design_schema: {},
1388
+ validation_schema: {},
1389
+ created_by: null,
1390
+ created_at: new Date().toISOString(),
1391
+ updated_at: new Date().toISOString(),
1392
+ data: {
1393
+ kb_type: 'cil_file',
1394
+ project_id: projectId,
1395
+ file_path: file.path,
1396
+ stable_id: canonical,
1397
+ version_id: versionId,
1398
+ language: file.language,
1399
+ extension: file.extension,
1400
+ stored_hash: null,
1401
+ file_hash: contentHash,
1402
+ content_hash: contentHash,
1403
+ has_existing_markers: false,
1404
+ existing_marker_names: [],
1405
+ existing_marker_count: 0,
1406
+ line_count: 0,
1407
+ status: '0-discovered',
1408
+ ingestion_pass: 1,
1409
+ chunk_count: 0,
1410
+ is_dead_code: false,
1411
+ git_last_commit: null,
1412
+ existing_marker_agreement_count: 0,
1413
+ existing_marker_disagreement_count: 0,
1414
+ },
1415
+ })
1416
+ }
1502
1417
  }
1503
1418
  }
1504
1419
 
1505
-
1420
+ for (let i = 0; i < newRows.length; i += 50) {
1421
+ const batch = newRows.slice(i, i + 50)
1422
+ const { error: insertErr } = await adminDb.from('items').insert(batch)
1423
+ if (insertErr) errors.push(`batch insert failed: ${insertErr.message}`)
1424
+ }
1425
+
1506
1426
  const fileTree = buildFileTree(treeRecords)
1507
1427
 
1508
- const { data: projItem } = await adminDb
1509
- .from('items').select('id, data').eq('id', projectId).maybeSingle()
1510
1428
  if (projItem) {
1429
+ const fileStatuses: Record<string, string> = { ...(projItem.data?.file_statuses || {}) }
1430
+ for (const r of treeRecords) {
1431
+ if (!fileStatuses[r.file_path]) fileStatuses[r.file_path] = '0-discovered'
1432
+ }
1511
1433
  const updateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: projItem.id } }
1512
1434
  await adminUpdate(updateCtx, {
1513
1435
  data: {
1514
1436
  ...projItem.data,
1515
1437
  file_tree: fileTree,
1438
+ file_statuses: fileStatuses,
1516
1439
  ingestion_status: 'in_progress',
1517
- file_count: filesDiscovered,
1440
+ file_count: Object.keys(fileStatuses).length,
1518
1441
  last_ingested_at: new Date().toISOString(),
1519
1442
  },
1520
1443
  }).catch(() => { /* non-fatal */ })
@@ -1526,26 +1449,22 @@ async function pass1Discover(
1526
1449
  file_tree: fileTree,
1527
1450
  }
1528
1451
  }
1529
-
1530
-
1531
-
1532
-
1533
-
1534
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_pass1discover_1784235266"]
1535
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_pass2chunk_1784235266" type="function" identity="pass2chunk" parent="none"]
1536
- // CIL[DOC-MACRO purpose="Implements pass2chunk logic in cortex.functions.custom_cil-ingest"]
1537
- // CIL[DOC-RESPONSIBILITY responsibility="Execute pass2chunk and return its computed result"]
1538
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
1539
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
1540
- // CIL[DOC-MICRO logic_summary="Provides pass2chunk with pass2Chunk( inputs, handling internal flow and returning a result" notable_decisions="[]"]
1541
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1542
- // CIL[DOC-STABILITY stability="stable"]
1543
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1544
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1545
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1546
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
1452
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the pass1Discover logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1453
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1454
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1455
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1547
1456
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1548
1457
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1458
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:pass1discover:function"]
1459
+
1460
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:pass2chunk:function" type="function" identity="pass2Chunk" parent="none"]
1461
+ // CIL[DOC-MACRO purpose="Implements the pass2Chunk logic"]
1462
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides pass2Chunk functionality"]
1463
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
1464
+ // CIL[DOC-CONTRACT inputs="ctx: any, projectId: string, repoPath: string, globs: string[], excludeGlobs: string[], forceReprocess: boolean, filePath?: string, selectedPaths?: string[], selectedExtensions?: string[]" outputs="return value as defined in source" errors="throws on invalid inputs" side_effects="executes database queries and updates and writes files to disk and reads files from disk"]
1465
+ // CIL[DOC-MICRO logic_summary="Processes inputs (arguments as defined in source) and returns the pass2Chunk result" notable_decisions="See source for implementation details"]
1466
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
1467
+ // CIL[DOC-STABILITY stability="internal"]
1549
1468
  async function pass2Chunk(
1550
1469
  ctx: any,
1551
1470
  projectId: string,
@@ -1564,16 +1483,19 @@ async function pass2Chunk(
1564
1483
  errors: string[]
1565
1484
  }> {
1566
1485
  const errors: string[] = []
1486
+
1487
+
1567
1488
  let filesProcessed = 0, chunksAutoApproved = 0, chunksQueued = 0, markersWritten = 0
1568
1489
 
1569
-
1570
1490
 
1571
-
1572
1491
  const { data: projItem } = await adminDb.from('items').select('id, data').eq('id', projectId).maybeSingle()
1573
1492
  const fileTree = (projItem?.data?.file_tree as FileTreeNode) || null
1493
+ const versionId = projItem?.data?.active_version_id || projItem?.data?.default_version_id || 'default'
1494
+
1495
+
1574
1496
 
1575
-
1576
1497
  let targetFiles: string[] = []
1498
+
1577
1499
  if (filePath) {
1578
1500
  targetFiles = [filePath]
1579
1501
  } else if (fileTree) {
@@ -1583,7 +1505,8 @@ async function pass2Chunk(
1583
1505
  targetFiles = walkDir(repoPath, repoPath, globs, excludeGlobs).map(f => f.path)
1584
1506
  }
1585
1507
 
1586
-
1508
+
1509
+
1587
1510
  const { data: allFileItems } = await adminDb
1588
1511
  .from('items')
1589
1512
  .select('id, title, data')
@@ -1597,14 +1520,19 @@ async function pass2Chunk(
1597
1520
  if (fp) existingByPath.set(fp, item)
1598
1521
  }
1599
1522
 
1600
-
1601
-
1602
1523
  const fileItems: { id: string; title: string; data: any }[] = []
1603
1524
  for (const relPath of targetFiles) {
1525
+
1526
+
1604
1527
  let fileItem = existingByPath.get(relPath)
1528
+
1605
1529
  if (!fileItem) {
1606
- const language = detectLanguage(path.join(repoPath, relPath))
1530
+ const fileAbsPath = path.join(repoPath, relPath)
1531
+ const language = detectLanguage(fileAbsPath)
1607
1532
  const extension = path.extname(relPath).toLowerCase()
1533
+ const fileCanonical = toCanonicalPath(repoPath, fileAbsPath)
1534
+ const fileContent = fs.readFileSync(fileAbsPath, 'utf-8')
1535
+ const fileContentHash = computeContentHash(fileContent)
1608
1536
  try {
1609
1537
  const newFile = await adminCreate(ctx, {
1610
1538
  entity: 'items',
@@ -1616,14 +1544,18 @@ async function pass2Chunk(
1616
1544
  kb_type: 'cil_file',
1617
1545
  project_id: projectId,
1618
1546
  file_path: relPath,
1547
+ stable_id: fileCanonical,
1548
+ version_id: versionId,
1619
1549
  language,
1620
1550
  extension,
1621
1551
  stored_hash: null,
1552
+ file_hash: fileContentHash,
1553
+ content_hash: fileContentHash,
1622
1554
  has_existing_markers: false,
1623
1555
  existing_marker_names: [],
1624
1556
  existing_marker_count: 0,
1625
1557
  line_count: 0,
1626
- status: 'discovered',
1558
+ status: '0-discovered',
1627
1559
  ingestion_pass: 1,
1628
1560
  chunk_count: 0,
1629
1561
  is_dead_code: false,
@@ -1634,21 +1566,21 @@ async function pass2Chunk(
1634
1566
  })
1635
1567
  const fileData = newFile.data || newFile
1636
1568
  fileItem = { id: newFile.id, title: relPath, data: fileData }
1637
- if (fileTree) updateTreeNodeByPath(fileTree, relPath, { id: newFile.id, status: 'discovered' })
1569
+ if (fileTree) updateTreeNodeByPath(fileTree, relPath, { id: newFile.id, status: '0-discovered' })
1638
1570
  } catch (err) {
1639
1571
  errors.push(`${relPath}: create failed: ${err instanceof Error ? err.message : String(err)}`)
1640
1572
  continue
1641
1573
  }
1642
1574
  }
1575
+
1643
1576
  if (fileItem) {
1644
1577
  const status = getFileStatus(fileItem)
1645
- if (forceReprocess || status === 'discovered') {
1578
+ if (forceReprocess || status === '0-discovered' || status === '1-selected') {
1646
1579
  fileItems.push(fileItem)
1647
1580
  }
1648
1581
  }
1649
1582
  }
1650
1583
 
1651
-
1652
1584
  const { data: existingChunkRows } = await adminDb
1653
1585
  .from('items')
1654
1586
  .select('data->file_id, data->chunk_name')
@@ -1666,7 +1598,6 @@ async function pass2Chunk(
1666
1598
  .map((r: any) => `${r.file_id}::${r.chunk_name}`)
1667
1599
  )
1668
1600
 
1669
-
1670
1601
  const chunksToInsert: object[] = []
1671
1602
  const proposalsToInsert: object[] = []
1672
1603
 
@@ -1679,28 +1610,52 @@ async function pass2Chunk(
1679
1610
 
1680
1611
  if (!['typescript', 'javascript'].includes(language)) continue
1681
1612
 
1682
-
1683
1613
  if (!forceReprocess && alreadyChunkedFileIds.has(fileItem.id)) continue
1684
1614
 
1685
1615
  try {
1686
- const content = fs.readFileSync(absPath, 'utf-8')
1687
- const lines = content.split('\n')
1688
- const fileHash = computeFileHash(content)
1616
+ if (forceReprocess) {
1617
+ try {
1618
+ await adminDb.from('items')
1619
+ .update({ is_active: false })
1620
+ .filter('data->>file_id', 'eq', fileItem.id)
1621
+ .filter('data->>kb_type', 'eq', 'cil_chunk')
1622
+ .eq('is_active', true)
1623
+ } catch (_) { /* non-fatal */ }
1624
+ for (const key of existingChunkKeys) {
1625
+ if (key.startsWith(`${fileItem.id}::`)) existingChunkKeys.delete(key)
1626
+ }
1627
+ }
1628
+
1629
+ const rawContent = fs.readFileSync(absPath, 'utf-8')
1630
+ const rawLines = rawContent.split('\n')
1631
+ // Blank (rather than remove) CIL marker/DOC lines when force-reprocessing:
1632
+ // filtering them out shifts every line index, so stored line_start/line_end
1633
+ // land in stripped-file coordinates and validate_file reports false drift.
1634
+ // Blank lines are invisible to the AST proposer and collapse in
1635
+ // computeContentHash, keeping hashes identical to store_markers output.
1636
+ const lines = forceReprocess
1637
+ ? rawLines.map((l: string) => (/^\/\/\s*CIL\[/.test(l.trim()) || /^\s*\/\*\s*CIL\[/.test(l.trim())) ? '' : l)
1638
+ : rawLines
1639
+ const content = lines.join('\n')
1640
+
1641
+
1642
+ let fileHash = ''
1643
+
1644
+ const canonicalPath = fileItem.data?.stable_id || toCanonicalPath(repoPath, absPath)
1689
1645
 
1690
-
1691
1646
  const existingMarkers = parseExistingMarkers(lines)
1692
1647
  const hasExistingMarkers = existingMarkers.length > 0
1693
1648
 
1694
-
1695
- const rawProposals = proposeChunksFromSource(lines, language)
1649
+ const rawProposals = proposeChunksFromSource(content, lines, language, canonicalPath)
1696
1650
 
1697
- const approvedChunks: { name: string; line_start: number; line_end: number; marker_line_end: number; chunk_type: string; is_proposal: boolean }[] = []
1651
+ const approvedChunks: { name: string; stable_id: string; parent_stable_id: string; line_start: number; line_end: number; marker_line_end: number; chunk_type: string; is_proposal: boolean }[] = []
1698
1652
 
1699
1653
  for (const proposal of rawProposals) {
1700
1654
 
1701
-
1702
-
1655
+
1656
+
1703
1657
  let contentStart = proposal.line_start - 1
1658
+
1704
1659
  if (proposal.existing_jsdoc) {
1705
1660
  for (let i = proposal.line_start - 2; i >= 0; i--) {
1706
1661
  const t = lines[i].trim()
@@ -1709,24 +1664,29 @@ async function pass2Chunk(
1709
1664
  if (!t.startsWith('*')) break
1710
1665
  }
1711
1666
  }
1667
+
1712
1668
  const codeLines = lines.slice(contentStart, proposal.line_end)
1713
1669
  const codeContent = codeLines.join('\n')
1714
1670
  const codePreview = codeLines.slice(0, 8).join('\n')
1715
1671
  const tokenCount = estimateTokens(codeContent)
1716
- const contentHash = computeChunkHash(codeContent)
1672
+ const contentHash = computeContentHash(codeContent)
1717
1673
 
1718
-
1719
1674
  const overlappingMarker = existingMarkers.find(m =>
1720
1675
  Math.abs(m.line_start - proposal.line_start) <= 3
1721
1676
  )
1722
1677
  const existingMarkerMatch = !!overlappingMarker
1723
- const existingMarkerName = overlappingMarker?.name || ''
1678
+ const existingMarkerName = overlappingMarker?.stable_id || ''
1679
+
1680
+
1724
1681
 
1725
-
1726
1682
  let score = proposal.confidence_score
1683
+
1684
+
1685
+
1727
1686
  let reasons = proposal.confidence_reasons
1687
+
1728
1688
  if (existingMarkerMatch) {
1729
- if (overlappingMarker!.name === proposal.name) {
1689
+ if (overlappingMarker!.stable_id === proposal.stable_id) {
1730
1690
  score = Math.min(0.99, score + 0.08)
1731
1691
  reasons = [...reasons, 'matches existing marker name+position']
1732
1692
  } else {
@@ -1735,29 +1695,28 @@ async function pass2Chunk(
1735
1695
  }
1736
1696
  }
1737
1697
 
1698
+
1699
+
1738
1700
  const isHighConfidence = score >= HIGH_CONFIDENCE_THRESHOLD
1739
1701
 
1740
1702
  if (isHighConfidence) {
1741
1703
 
1742
1704
  const chunkKey = `${fileItem.id}::${proposal.name}`
1743
1705
  if (!forceReprocess && existingChunkKeys.has(chunkKey)) {
1744
- approvedChunks.push({ name: proposal.name, line_start: proposal.line_start, line_end: proposal.line_end, marker_line_end: proposal.marker_line_end, chunk_type: proposal.chunk_type, is_proposal: false })
1706
+ approvedChunks.push({ name: proposal.name, stable_id: proposal.stable_id, parent_stable_id: proposal.parent_stable_id || canonicalPath, line_start: proposal.line_start, line_end: proposal.line_end, marker_line_end: proposal.marker_line_end, chunk_type: proposal.chunk_type, is_proposal: false })
1745
1707
  chunksAutoApproved++
1746
1708
  continue
1747
1709
  }
1748
1710
 
1749
1711
  const existingMarkerAgreement = existingMarkerMatch
1750
- ? (overlappingMarker!.name === proposal.name ? 'agreed' : 'disagreed')
1712
+ ? (overlappingMarker!.stable_id === proposal.stable_id ? 'agreed' : 'disagreed')
1751
1713
  : 'none'
1752
1714
 
1753
-
1754
1715
  const jd = proposal.existing_jsdoc
1755
1716
  const hasSourceDoc = !!(jd && (jd.description || jd.params || jd.returns))
1756
1717
 
1757
-
1758
1718
  const docConfidence = jd?.is_cil_generated ? 'ai_generated' : hasSourceDoc ? 'from_source' : 'unverified_legacy'
1759
1719
 
1760
-
1761
1720
  const inputSpec = jd?.input_spec || jd?.params || ''
1762
1721
 
1763
1722
  const outputSpec = jd?.output_spec || jd?.returns || ''
@@ -1774,6 +1733,10 @@ async function pass2Chunk(
1774
1733
  const baseChunkData: Record<string, any> = {
1775
1734
  kb_type: 'cil_chunk',
1776
1735
  chunk_name: proposal.name,
1736
+ stable_id: proposal.stable_id,
1737
+ version_id: versionId,
1738
+ parent_stable_id: proposal.parent_stable_id,
1739
+ legacy_chunk_id: null,
1777
1740
  file_id: fileItem.id,
1778
1741
  project_id: projectId,
1779
1742
  file_path: relPath,
@@ -1783,6 +1746,7 @@ async function pass2Chunk(
1783
1746
  line_end: proposal.line_end,
1784
1747
  chunk_type: proposal.chunk_type,
1785
1748
  stored_hash: contentHash,
1749
+ content_hash: contentHash,
1786
1750
  boundary_confidence: 'high',
1787
1751
  boundary_source: 'ast_auto',
1788
1752
  review_status: 'approved',
@@ -1816,7 +1780,6 @@ async function pass2Chunk(
1816
1780
  baseChunkData.layer = layer
1817
1781
  baseChunkData.stability = jd?.stability || 'stable'
1818
1782
 
1819
-
1820
1783
  baseChunkData.description = jd?.description || ''
1821
1784
  baseChunkData.see_also = jd?.see_also || ''
1822
1785
  }
@@ -1831,7 +1794,7 @@ async function pass2Chunk(
1831
1794
  })
1832
1795
  existingChunkKeys.add(chunkKey)
1833
1796
 
1834
- approvedChunks.push({ name: proposal.name, line_start: proposal.line_start, line_end: proposal.line_end, marker_line_end: proposal.marker_line_end, chunk_type: proposal.chunk_type, is_proposal: false })
1797
+ approvedChunks.push({ name: proposal.name, stable_id: proposal.stable_id, parent_stable_id: proposal.parent_stable_id || canonicalPath, line_start: proposal.line_start, line_end: proposal.line_end, marker_line_end: proposal.marker_line_end, chunk_type: proposal.chunk_type, is_proposal: false })
1835
1798
  chunksAutoApproved++
1836
1799
  } else {
1837
1800
  proposalsToInsert.push({
@@ -1842,6 +1805,10 @@ async function pass2Chunk(
1842
1805
  is_active: true,
1843
1806
  data: {
1844
1807
  kb_type: 'cil_chunk_proposal',
1808
+ stable_id: proposal.stable_id,
1809
+ version_id: versionId,
1810
+ parent_stable_id: proposal.parent_stable_id,
1811
+ legacy_chunk_id: null,
1845
1812
  file_id: fileItem.id,
1846
1813
  project_id: projectId,
1847
1814
  file_path: relPath,
@@ -1854,6 +1821,7 @@ async function pass2Chunk(
1854
1821
  confidence_reasons: reasons.join('; '),
1855
1822
  existing_marker_match: existingMarkerMatch,
1856
1823
  existing_marker_name: existingMarkerName,
1824
+ content_hash: contentHash,
1857
1825
  review_status: 'pending_review',
1858
1826
  reviewed_by: null,
1859
1827
  reviewed_at: null,
@@ -1864,21 +1832,18 @@ async function pass2Chunk(
1864
1832
  },
1865
1833
  })
1866
1834
 
1867
-
1868
-
1869
- approvedChunks.push({ name: proposal.name, line_start: proposal.line_start, line_end: proposal.line_end, marker_line_end: proposal.marker_line_end, chunk_type: proposal.chunk_type, is_proposal: true })
1835
+ approvedChunks.push({ name: proposal.name, stable_id: proposal.stable_id, line_start: proposal.line_start, line_end: proposal.line_end, marker_line_end: proposal.marker_line_end, chunk_type: proposal.chunk_type, is_proposal: true })
1870
1836
  chunksQueued++
1871
1837
  }
1872
1838
  }
1873
1839
 
1874
-
1875
-
1876
-
1877
-
1878
-
1879
- if (approvedChunks.length > 0) {
1840
+
1841
+ if (approvedChunks.length > 0 || forceReprocess) {
1842
+
1843
+
1880
1844
  let resultLines = [...lines]
1881
1845
 
1846
+
1882
1847
  const sorted = [...approvedChunks].sort((a, b) => b.line_start - a.line_start)
1883
1848
 
1884
1849
  for (const chunk of sorted) {
@@ -1886,47 +1851,52 @@ async function pass2Chunk(
1886
1851
 
1887
1852
  if (startLine && ANY_MARKER_RE.test(startLine.trim())) continue
1888
1853
 
1889
- const startMarker = chunk.is_proposal ? proposalStartMarker(chunk.name) : chunkStartMarker(chunk.name)
1890
- const endMarker = chunk.is_proposal ? proposalEndMarker(chunk.name) : chunkEndMarker(chunk.name)
1854
+ const startMarker = chunk.is_proposal ? proposalStartMarker(chunk.name) : chunkStartMarker(chunk.stable_id, chunk.chunk_type, chunk.name, chunk.parent_stable_id)
1855
+ const endMarker = chunk.is_proposal ? proposalEndMarker(chunk.name) : chunkEndMarker(chunk.stable_id)
1891
1856
  const startIdx = markerInsertIdx(resultLines, chunk.line_start)
1892
1857
 
1893
- const endIdx = markerEndInsertIdx(resultLines, chunk.marker_line_end)
1858
+ const endIdx = chunk.chunk_type === 'module_header'
1859
+ ? chunk.marker_line_end
1860
+ : markerEndInsertIdx(resultLines, chunk.line_start, chunk.marker_line_end)
1894
1861
 
1895
1862
  resultLines.splice(endIdx, 0, endMarker)
1896
1863
  resultLines.splice(startIdx, 0, startMarker)
1897
1864
  markersWritten++
1898
1865
  }
1899
1866
 
1867
+
1900
1868
  fs.writeFileSync(absPath, resultLines.join('\n'), 'utf-8')
1869
+ fileHash = computeContentHash(resultLines.join('\n'))
1901
1870
  }
1902
1871
 
1903
-
1904
1872
  fileUpdates.push({
1905
1873
  id: fileItem.id,
1906
1874
  data: {
1907
1875
  ...fileItem.data,
1908
1876
  stored_hash: fileHash,
1877
+ file_hash: fileHash,
1878
+ content_hash: fileHash,
1909
1879
  line_count: lines.length,
1910
- has_existing_markers: hasExistingMarkers,
1911
- existing_marker_names: existingMarkers.map(m => m.name),
1912
- existing_marker_count: existingMarkers.length,
1880
+ has_existing_markers: approvedChunks.length > 0,
1881
+ existing_marker_names: approvedChunks.map(c => c.stable_id),
1882
+ existing_marker_count: approvedChunks.length,
1913
1883
  chunk_count: approvedChunks.length,
1914
1884
  ingestion_pass: 2,
1915
- status: 'pass2_complete',
1885
+ status: '2-chunked',
1916
1886
  last_status_at: new Date().toISOString(),
1917
1887
  existing_marker_agreement_count: approvedChunks.filter(c => {
1918
1888
  const em = existingMarkers.find(m => Math.abs(m.line_start - c.line_start) <= 3)
1919
- return em && em.name === c.name
1889
+ return em && em.stable_id === c.stable_id
1920
1890
  }).length,
1921
1891
  existing_marker_disagreement_count: approvedChunks.filter(c => {
1922
1892
  const em = existingMarkers.find(m => Math.abs(m.line_start - c.line_start) <= 3)
1923
- return em && em.name !== c.name
1893
+ return em && em.stable_id !== c.stable_id
1924
1894
  }).length,
1925
1895
  },
1926
1896
  })
1927
1897
 
1928
1898
  if (fileTree) {
1929
- updateTreeNodeStatus(fileTree, fileItem.id, 'pass2_complete')
1899
+ updateTreeNodeStatus(fileTree, fileItem.id, '2-chunked')
1930
1900
  }
1931
1901
 
1932
1902
  filesProcessed++
@@ -1935,8 +1905,6 @@ async function pass2Chunk(
1935
1905
  }
1936
1906
  }
1937
1907
 
1938
-
1939
-
1940
1908
  const PARALLEL_INSERT = 10
1941
1909
  const PARALLEL_UPDATE = 20
1942
1910
 
@@ -1958,7 +1926,6 @@ async function pass2Chunk(
1958
1926
  ))
1959
1927
  }
1960
1928
 
1961
-
1962
1929
  for (let i = 0; i < fileUpdates.length; i += PARALLEL_UPDATE) {
1963
1930
  const batch = fileUpdates.slice(i, i + PARALLEL_UPDATE)
1964
1931
  await Promise.all(batch.map(({ id, data }) => {
@@ -1969,13 +1936,18 @@ async function pass2Chunk(
1969
1936
  }))
1970
1937
  }
1971
1938
 
1972
-
1973
1939
  if (projItem) {
1940
+ const fileStatuses: Record<string, string> = { ...(projItem.data?.file_statuses || {}) }
1941
+ for (const { data } of fileUpdates) {
1942
+ const fp = data.file_path as string | undefined
1943
+ if (fp) fileStatuses[fp] = '2-chunked'
1944
+ }
1974
1945
  const updateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: projItem.id } }
1975
1946
  await adminUpdate(updateCtx, {
1976
1947
  data: {
1977
1948
  ...projItem.data,
1978
1949
  file_tree: fileTree,
1950
+ file_statuses: fileStatuses,
1979
1951
  ingestion_status: chunksQueued > 0 ? 'in_progress' : 'complete',
1980
1952
  chunk_count: chunksAutoApproved,
1981
1953
  last_ingested_at: new Date().toISOString(),
@@ -1991,33 +1963,28 @@ async function pass2Chunk(
1991
1963
  errors,
1992
1964
  }
1993
1965
  }
1966
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the pass2Chunk logic'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1967
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1968
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1969
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1970
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1971
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1972
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:pass2chunk:function"]
1994
1973
 
1995
-
1996
-
1997
-
1998
-
1999
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_pass2chunk_1784235266"]
2000
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_ingest_handler_1784235266" type="variable" identity="handler" parent="none"]
2001
- // CIL[DOC-MACRO purpose="Defines handler configuration or state in cortex.functions.custom_cil-ingest"]
2002
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for handler"]
2003
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-ingest" layer="function" related_files="[]"]
1974
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-ingest.ts:handler:constant" type="constant" identity="handler" parent="none"]
1975
+ // CIL[DOC-MACRO purpose="Constant handler"]
1976
+ // CIL[DOC-RESPONSIBILITY responsibility="Supplies the static value for handler"]
1977
+ // CIL[DOC-CONTEXT module="cil-ingest" layer="functions" related_files=".framework/functions/_shared/ast.ts,.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-ingest.ts"]
2004
1978
  // CIL[DOC-CONTRACT inputs="none" outputs="value of handler" errors="none" side_effects="none"]
2005
- // CIL[DOC-MICRO logic_summary="Declares handler with initial value or constant binding used by cortex.functions.custom_cil-ingest" notable_decisions="[]"]
2006
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1979
+ // CIL[DOC-MICRO logic_summary="Holds the static handler value" notable_decisions="Static value used across cil-ingest"]
1980
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
2007
1981
  // CIL[DOC-STABILITY stability="stable"]
2008
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
2009
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
2010
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
2011
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
2012
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
2013
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
2014
1982
  export const handler = createHandler(async (ctx, body) => {
2015
1983
  const action = ctx.query?.action
2016
1984
  const req = body as IngestRequest
2017
1985
 
2018
1986
  if (!req?.project_id) throw new Error('project_id is required')
2019
1987
 
2020
-
2021
1988
  const { data: projectItem, error: projectError } = await adminDb
2022
1989
  .from('items')
2023
1990
  .select('id, title, data')
@@ -2028,8 +1995,7 @@ export const handler = createHandler(async (ctx, body) => {
2028
1995
 
2029
1996
  const repoPath: string = projectItem.data?.repo_path
2030
1997
 
2031
-
2032
- const DISK_ACTIONS = ['pass1', 'pass2', 'reindex_chunk']
1998
+ const DISK_ACTIONS = ['pass1', 'pass2', 'reindex_chunk', 'validate_chunking']
2033
1999
  if (DISK_ACTIONS.includes(action || '')) {
2034
2000
  if (!repoPath) throw new Error('Project has no repo_path configured')
2035
2001
  if (!fs.existsSync(repoPath)) {
@@ -2037,12 +2003,11 @@ export const handler = createHandler(async (ctx, body) => {
2037
2003
  }
2038
2004
  }
2039
2005
 
2040
- const globs = req.globs || DEFAULT_GLOBS
2041
- const excludeGlobs = req.exclude_globs || DEFAULT_EXCLUDE
2006
+ const globs = req.globs || projectItem.data?.globs || DEFAULT_GLOBS
2007
+ const excludeGlobs = req.exclude_globs || projectItem.data?.exclude_globs || DEFAULT_EXCLUDE
2042
2008
  const forceReprocess = req.force_reprocess ?? false
2043
2009
  const sourceSets: SourceSet[] | undefined = projectItem.data?.source_sets
2044
2010
 
2045
-
2046
2011
  if (action === 'pass1') {
2047
2012
  if (!ctx.accountId) throw new Error('account_id required — user must be authenticated')
2048
2013
 
@@ -2059,7 +2024,6 @@ export const handler = createHandler(async (ctx, body) => {
2059
2024
  }
2060
2025
  }
2061
2026
 
2062
-
2063
2027
  if (action === 'pass2') {
2064
2028
  if (!ctx.accountId) throw new Error('account_id required — user must be authenticated')
2065
2029
  const selectedPaths = projectItem.data?.selected_paths as string[] | undefined
@@ -2075,13 +2039,250 @@ export const handler = createHandler(async (ctx, body) => {
2075
2039
  }
2076
2040
  }
2077
2041
 
2078
-
2079
-
2080
-
2081
-
2082
-
2083
-
2084
-
2042
+ if (action === 'validate_chunking') {
2043
+ const filePath = req.file_path
2044
+ if (!filePath) throw new Error('file_path is required for validate_chunking')
2045
+ if (!repoPath) throw new Error('Project has no repo_path configured')
2046
+
2047
+ const absPath = path.join(repoPath, filePath)
2048
+ if (!fs.existsSync(absPath)) {
2049
+ throw new Error(`Source file not found on disk: ${absPath}`)
2050
+ }
2051
+
2052
+ const content = fs.readFileSync(absPath, 'utf-8')
2053
+ const lines = content.split('\n')
2054
+ const language = detectLanguage(absPath)
2055
+ const canonicalPath = toCanonicalPath(repoPath, absPath)
2056
+ const existingMarkers = parseExistingMarkers(lines)
2057
+
2058
+ if (existingMarkers.length === 0) {
2059
+ return {
2060
+ file_path: filePath,
2061
+ canonical_path: canonicalPath,
2062
+ status: 'not_chunked',
2063
+ message: 'No CIL markers found',
2064
+ existing_marker_count: 0,
2065
+ proposed_chunk_count: 0,
2066
+ }
2067
+ }
2068
+
2069
+ const proposals = proposeChunksFromSource(content, lines, language, canonicalPath)
2070
+ const matchedProposalIdx = new Set<number>()
2071
+ const markerResults = existingMarkers.map(marker => {
2072
+ const overlapIdx = proposals.findIndex((p, idx) =>
2073
+ !matchedProposalIdx.has(idx) && Math.abs(p.line_start - marker.line_start) <= 3
2074
+ )
2075
+ if (overlapIdx === -1) {
2076
+ return { ...marker, status: 'orphan', reason: 'No matching proposed chunk within 3 lines' }
2077
+ }
2078
+ matchedProposalIdx.add(overlapIdx)
2079
+ const proposal = proposals[overlapIdx]
2080
+ if (proposal.stable_id === marker.stable_id) {
2081
+ return { ...marker, status: 'agreed', proposal_stable_id: proposal.stable_id, proposal_line_end: proposal.line_end }
2082
+ }
2083
+ return { ...marker, status: 'disagreed', proposal_stable_id: proposal.stable_id, proposal_line_end: proposal.line_end }
2084
+ })
2085
+
2086
+ const missing = proposals
2087
+ .map((p, idx) => ({ ...p, idx }))
2088
+ .filter(({ idx }) => !matchedProposalIdx.has(idx))
2089
+ .map(p => ({
2090
+ stable_id: p.stable_id,
2091
+ line_start: p.line_start,
2092
+ line_end: p.line_end,
2093
+ chunk_type: p.chunk_type,
2094
+ status: 'missing',
2095
+ }))
2096
+
2097
+ const allAgreed = markerResults.every(m => m.status === 'agreed') && missing.length === 0
2098
+ const status = allAgreed ? 'valid' : 'needs_rechunk'
2099
+
2100
+ return {
2101
+ file_path: filePath,
2102
+ canonical_path: canonicalPath,
2103
+ status,
2104
+ existing_marker_count: existingMarkers.length,
2105
+ proposed_chunk_count: proposals.length,
2106
+ agreed_count: markerResults.filter(m => m.status === 'agreed').length,
2107
+ disagreed_count: markerResults.filter(m => m.status === 'disagreed').length,
2108
+ orphan_count: markerResults.filter(m => m.status === 'orphan').length,
2109
+ missing_count: missing.length,
2110
+ markers: markerResults,
2111
+ missing,
2112
+ }
2113
+ }
2114
+
2115
+ if (action === 'step') {
2116
+ const step = Number((body as any).step ?? 2)
2117
+ const limit = Number((body as any).limit ?? 1)
2118
+ if (step !== 0 && step !== 1 && step !== 2) throw new Error(`step ${step} is not yet supported by the resumable worker`)
2119
+ if (step === 2 && (limit < 1 || limit > 50)) throw new Error('step 2 limit must be between 1 and 50')
2120
+ if (!ctx.accountId) throw new Error('account_id required — user must be authenticated')
2121
+ if (!repoPath) throw new Error('Project has no repo_path configured')
2122
+
2123
+ const selectedPaths = projectItem.data?.selected_paths as string[] | undefined
2124
+ const selectedExtensions = req.selected_extensions || (projectItem.data?.selected_extensions as string[] | undefined)
2125
+
2126
+ if (step === 0) {
2127
+ const filePath = req.file_path
2128
+ if (!filePath) throw new Error('file_path is required for step 0 (discover one file)')
2129
+ const result = await pass1Discover(ctx, req.project_id, repoPath, [filePath], [], forceReprocess, sourceSets)
2130
+
2131
+ const { data: projectAfter } = await adminDb
2132
+ .from('items')
2133
+ .select('data')
2134
+ .eq('id', req.project_id)
2135
+ .maybeSingle()
2136
+
2137
+ if (projectAfter) {
2138
+ const stepCursors = { ...(projectAfter.data?.step_cursors || {}), [String(step)]: filePath }
2139
+ const updateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: req.project_id } }
2140
+ await adminUpdate(updateCtx, {
2141
+ data: {
2142
+ ...projectAfter.data,
2143
+ step_cursors: stepCursors,
2144
+ },
2145
+ }).catch(() => { /* non-fatal */ })
2146
+ }
2147
+
2148
+ return {
2149
+ ok: true,
2150
+ step,
2151
+ file_path: filePath,
2152
+ status: 'in_progress',
2153
+ processed: 1,
2154
+ ...result,
2155
+ }
2156
+ }
2157
+
2158
+ if (step === 1) {
2159
+ const { data: fileItems } = await adminDb
2160
+ .from('items')
2161
+ .select('id, data')
2162
+ .filter('data->>project_id', 'eq', req.project_id)
2163
+ .filter('data->>kb_type', 'eq', 'cil_file')
2164
+ .eq('is_active', true)
2165
+
2166
+ const toSelect = (fileItems || [])
2167
+ .map((f: any) => ({ id: f.id, data: f.data, path: f.data?.file_path || f.title, status: getFileStatus(f) }))
2168
+ .filter((f: any) => isSelectedPath(f.path, selectedPaths || []) && f.status === '0-discovered')
2169
+ .sort((a: any, b: any) => a.path.localeCompare(b.path))
2170
+
2171
+ const now = new Date().toISOString()
2172
+ const fileStatuses = { ...(projectItem.data?.file_statuses || {}) }
2173
+ for (const f of toSelect) {
2174
+ const updateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: f.id } }
2175
+ await adminUpdate(updateCtx, {
2176
+ data: {
2177
+ ...f.data,
2178
+ status: '1-selected',
2179
+ selected_at: now,
2180
+ },
2181
+ }).catch(() => { /* non-fatal */ })
2182
+ fileStatuses[f.path] = '1-selected'
2183
+ }
2184
+
2185
+ const { data: projectAfter } = await adminDb
2186
+ .from('items')
2187
+ .select('data')
2188
+ .eq('id', req.project_id)
2189
+ .maybeSingle()
2190
+
2191
+ if (projectAfter) {
2192
+ const stepCursors = { ...(projectAfter.data?.step_cursors || {}), [String(step)]: toSelect[toSelect.length - 1]?.path || '' }
2193
+ const updateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: req.project_id } }
2194
+ await adminUpdate(updateCtx, {
2195
+ data: {
2196
+ ...projectAfter.data,
2197
+ file_statuses: fileStatuses,
2198
+ step_cursors: stepCursors,
2199
+ },
2200
+ }).catch(() => { /* non-fatal */ })
2201
+ }
2202
+
2203
+ return {
2204
+ ok: true,
2205
+ step,
2206
+ status: toSelect.length === 0 ? 'complete' : 'in_progress',
2207
+ processed: toSelect.length,
2208
+ remaining: 0,
2209
+ selected_paths: selectedPaths,
2210
+ selected_file_count: toSelect.length,
2211
+ }
2212
+ }
2213
+
2214
+ const { data: fileItems } = await adminDb
2215
+ .from('items')
2216
+ .select('id, title, data')
2217
+ .filter('data->>project_id', 'eq', req.project_id)
2218
+ .filter('data->>kb_type', 'eq', 'cil_file')
2219
+ .eq('is_active', true)
2220
+
2221
+ const pending = (fileItems || [])
2222
+ .map((f: any) => ({ path: f.data?.file_path || f.title, status: getFileStatus(f) }))
2223
+ .filter((f: any) => isSelectedPath(f.path, selectedPaths || []) && (f.status === '1-selected' || (forceReprocess && f.status === '2-chunked')))
2224
+ .sort((a: any, b: any) => a.path.localeCompare(b.path))
2225
+
2226
+ if (pending.length === 0) {
2227
+ return { ok: true, step, status: 'complete', processed: 0, remaining: 0, message: 'No files to chunk' }
2228
+ }
2229
+
2230
+ const cursorPath = (projectItem?.data?.step_cursors?.[String(step)] as string) || ''
2231
+ let startIdx = 0
2232
+ if (cursorPath) {
2233
+ const found = pending.findIndex((f: any) => f.path === cursorPath)
2234
+ if (found >= 0) startIdx = found + 1
2235
+ }
2236
+ const toProcess = req.file_path ? [{ path: req.file_path, status: '' }] : pending.slice(startIdx, startIdx + limit)
2237
+ let filesProcessed = 0
2238
+ let chunksAutoApproved = 0
2239
+ let chunksQueued = 0
2240
+ let markersWritten = 0
2241
+ const allErrors: string[] = []
2242
+ let lastPath = ''
2243
+
2244
+ for (const p of toProcess) {
2245
+ const result = await pass2Chunk(ctx, req.project_id, repoPath, globs, excludeGlobs, forceReprocess, p.path, selectedPaths, selectedExtensions)
2246
+ filesProcessed += result.files_processed || 0
2247
+ chunksAutoApproved += result.chunks_auto_approved || 0
2248
+ chunksQueued += result.chunks_queued_for_review || 0
2249
+ markersWritten += result.markers_written || 0
2250
+ allErrors.push(...(result.errors || []))
2251
+ lastPath = p.path
2252
+ }
2253
+
2254
+ const { data: projectAfter } = await adminDb
2255
+ .from('items')
2256
+ .select('data')
2257
+ .eq('id', req.project_id)
2258
+ .maybeSingle()
2259
+
2260
+ if (projectAfter) {
2261
+ const stepCursors = { ...(projectAfter.data?.step_cursors || {}), [String(step)]: lastPath }
2262
+ const updateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: req.project_id } }
2263
+ await adminUpdate(updateCtx, {
2264
+ data: {
2265
+ ...projectAfter.data,
2266
+ step_cursors: stepCursors,
2267
+ },
2268
+ }).catch(() => { /* non-fatal */ })
2269
+ }
2270
+
2271
+ return {
2272
+ ok: true,
2273
+ step,
2274
+ file_path: lastPath,
2275
+ status: toProcess.length >= pending.length ? 'complete' : 'in_progress',
2276
+ processed: toProcess.length,
2277
+ remaining: pending.length - toProcess.length,
2278
+ files_processed: filesProcessed,
2279
+ chunks_auto_approved: chunksAutoApproved,
2280
+ chunks_queued_for_review: chunksQueued,
2281
+ markers_written: markersWritten,
2282
+ errors: allErrors,
2283
+ }
2284
+ }
2285
+
2085
2286
  if (action === 'promote_proposal') {
2086
2287
  const proposalId = body?.proposal_id
2087
2288
  if (!proposalId) throw new Error('proposal_id is required')
@@ -2102,7 +2303,6 @@ export const handler = createHandler(async (ctx, body) => {
2102
2303
  const chunkType = pd.chunk_type || 'function'
2103
2304
  const projectId = pd.project_id || req.project_id
2104
2305
 
2105
-
2106
2306
  const { data: fileItem } = await adminDb
2107
2307
  .from('items').select('id, data').eq('id', fileId).maybeSingle()
2108
2308
  if (!fileItem) throw new Error(`File not found: ${fileId}`)
@@ -2120,33 +2320,30 @@ export const handler = createHandler(async (ctx, body) => {
2120
2320
 
2121
2321
  const fileContent = fs.readFileSync(absPath, 'utf-8')
2122
2322
  const resultLines = fileContent.split('\n')
2323
+ const canonicalPath = fileItem.data?.stable_id || toCanonicalPath(effectiveRepoPath, absPath)
2324
+ const promotionVersionId = projectItem?.data?.active_version_id || projectItem?.data?.default_version_id || 'default'
2325
+ const chunkStableId = generateStableId(canonicalPath, chunkName, chunkType)
2123
2326
 
2124
-
2125
-
2126
2327
  const proposalStartText = proposalStartMarker(chunkName)
2127
2328
  const proposalEndText = proposalEndMarker(chunkName)
2128
2329
  const startIdx = resultLines.findIndex(l => l.trim() === proposalStartText.trim())
2129
2330
  const endIdx = resultLines.findIndex(l => l.trim() === proposalEndText.trim())
2130
2331
 
2131
2332
  let markerReplaced = false
2132
- if (startIdx !== -1) { resultLines[startIdx] = chunkStartMarker(chunkName); markerReplaced = true }
2133
- if (endIdx !== -1) { resultLines[endIdx] = chunkEndMarker(chunkName); markerReplaced = true }
2333
+ if (startIdx !== -1) { resultLines[startIdx] = chunkStartMarker(chunkStableId); markerReplaced = true }
2334
+ if (endIdx !== -1) { resultLines[endIdx] = chunkEndMarker(chunkStableId); markerReplaced = true }
2134
2335
  if (markerReplaced) fs.writeFileSync(absPath, resultLines.join('\n'), 'utf-8')
2135
2336
 
2136
-
2137
-
2138
-
2139
2337
  const actualStart = startIdx !== -1 ? startIdx + 1 : (pd.line_start || 1)
2140
2338
  const actualEnd = endIdx !== -1 ? endIdx + 1 : (pd.line_end || actualStart)
2141
2339
 
2142
2340
  const codeLines = resultLines.slice(actualStart, actualEnd - 1)
2143
2341
  const codeContent = codeLines.join('\n')
2144
2342
  const tokenCount = estimateTokens(codeContent)
2145
- const contentHash = computeChunkHash(codeContent)
2343
+ const contentHash = computeContentHash(codeContent)
2146
2344
 
2147
2345
  if (!ctx.accountId) throw new Error('account_id required — user must be authenticated')
2148
2346
 
2149
-
2150
2347
  const newChunk = await adminCreate(ctx, {
2151
2348
  entity: 'items',
2152
2349
  type_slug: 'cil_chunk',
@@ -2156,6 +2353,10 @@ export const handler = createHandler(async (ctx, body) => {
2156
2353
  data: {
2157
2354
  kb_type: 'cil_chunk',
2158
2355
  chunk_name: chunkName,
2356
+ stable_id: chunkStableId,
2357
+ version_id: promotionVersionId,
2358
+ parent_stable_id: canonicalPath,
2359
+ legacy_chunk_id: proposal.id,
2159
2360
  file_id: fileId,
2160
2361
  project_id: projectId,
2161
2362
  file_path: relPath,
@@ -2163,6 +2364,7 @@ export const handler = createHandler(async (ctx, body) => {
2163
2364
  line_end: actualEnd,
2164
2365
  chunk_type: chunkType,
2165
2366
  stored_hash: contentHash,
2367
+ content_hash: contentHash,
2166
2368
  boundary_confidence: 'human_verified',
2167
2369
  boundary_source: 'ast_approved',
2168
2370
  review_status: 'approved',
@@ -2183,7 +2385,6 @@ export const handler = createHandler(async (ctx, body) => {
2183
2385
  })
2184
2386
  if (!newChunk?.id) throw new Error('Failed to create chunk record')
2185
2387
 
2186
-
2187
2388
  const propUpdateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: proposalId } }
2188
2389
  await adminUpdate(propUpdateCtx, {
2189
2390
  is_active: false,
@@ -2200,13 +2401,6 @@ export const handler = createHandler(async (ctx, body) => {
2200
2401
  }
2201
2402
  }
2202
2403
 
2203
-
2204
-
2205
-
2206
-
2207
-
2208
-
2209
-
2210
2404
  if (action === 'reject_proposal') {
2211
2405
  const proposalId = body?.proposal_id
2212
2406
  if (!proposalId) throw new Error('proposal_id is required')
@@ -2243,7 +2437,6 @@ export const handler = createHandler(async (ctx, body) => {
2243
2437
  const fileContent = fs.readFileSync(absPath, 'utf-8')
2244
2438
  const resultLines = fileContent.split('\n')
2245
2439
 
2246
-
2247
2440
  const proposalStartText = proposalStartMarker(chunkName)
2248
2441
  const proposalEndText = proposalEndMarker(chunkName)
2249
2442
  let markerReplaced = false
@@ -2254,7 +2447,6 @@ export const handler = createHandler(async (ctx, body) => {
2254
2447
  }
2255
2448
  if (markerReplaced) fs.writeFileSync(absPath, resultLines.join('\n'), 'utf-8')
2256
2449
 
2257
-
2258
2450
  const propUpdateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: proposalId } }
2259
2451
  await adminUpdate(propUpdateCtx, {
2260
2452
  is_active: false,
@@ -2270,7 +2462,6 @@ export const handler = createHandler(async (ctx, body) => {
2270
2462
  }
2271
2463
  }
2272
2464
 
2273
-
2274
2465
  if (action === 'status') {
2275
2466
  const { count: fileCount } = await adminDb
2276
2467
  .from('items').select('id', { count: 'exact' })
@@ -2298,13 +2489,6 @@ export const handler = createHandler(async (ctx, body) => {
2298
2489
  }
2299
2490
  }
2300
2491
 
2301
-
2302
-
2303
-
2304
-
2305
-
2306
-
2307
-
2308
2492
  if (action === 'reindex_chunk') {
2309
2493
  const chunkId = body?.chunk_id
2310
2494
  if (!chunkId) throw new Error('chunk_id is required')
@@ -2334,25 +2518,24 @@ export const handler = createHandler(async (ctx, body) => {
2334
2518
  const codeLines = lines.slice(lineStart - 1, lineEnd)
2335
2519
  const codeContent = codeLines.join('\n')
2336
2520
  const tokenCount = estimateTokens(codeContent)
2337
- const contentHash = computeChunkHash(codeContent)
2521
+ const contentHash = computeContentHash(codeContent)
2338
2522
 
2339
-
2340
2523
  const chunkUpdateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: chunkId } }
2341
2524
  await adminUpdate(chunkUpdateCtx, {
2342
2525
  data: {
2343
2526
  ...cd,
2344
2527
  code_content: codeContent,
2345
2528
  stored_hash: contentHash,
2529
+ content_hash: contentHash,
2346
2530
  token_count: tokenCount,
2347
2531
  hash_updated_at: new Date().toISOString(),
2348
2532
  },
2349
2533
  })
2350
2534
 
2351
-
2352
2535
  if (fileId) {
2353
- const fileHash = computeFileHash(fileContent)
2536
+ const fileHash = computeContentHash(fileContent)
2354
2537
  const fileUpdateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: fileId } }
2355
- await adminUpdate(fileUpdateCtx, { data: { stored_hash: fileHash } })
2538
+ await adminUpdate(fileUpdateCtx, { data: { stored_hash: fileHash, file_hash: fileHash, content_hash: fileHash } })
2356
2539
  }
2357
2540
 
2358
2541
  const result: Record<string, any> = {
@@ -2366,7 +2549,6 @@ export const handler = createHandler(async (ctx, body) => {
2366
2549
  doc_triggered: false,
2367
2550
  }
2368
2551
 
2369
-
2370
2552
  if (body?.also_embed) {
2371
2553
  try {
2372
2554
  const base = process.env.URL || 'http://localhost:8888'
@@ -2385,7 +2567,6 @@ export const handler = createHandler(async (ctx, body) => {
2385
2567
  }
2386
2568
  }
2387
2569
 
2388
-
2389
2570
  if (body?.also_doc) {
2390
2571
  try {
2391
2572
  const base = process.env.URL || 'http://localhost:8888'
@@ -2407,10 +2588,93 @@ export const handler = createHandler(async (ctx, body) => {
2407
2588
  return result
2408
2589
  }
2409
2590
 
2410
- throw new Error(`Unknown action: ${action}. Valid actions: pass1, pass2, status, promote_proposal, reject_proposal, reindex_chunk`)
2411
- })
2591
+ if (action === 'discover') {
2592
+ const result = await pass1Discover(ctx, req.project_id, repoPath, globs, excludeGlobs, forceReprocess, sourceSets)
2593
+ return {
2594
+ action: 'discover',
2595
+ project_id: req.project_id,
2596
+ repo_path: repoPath,
2597
+ ...result,
2598
+ }
2599
+ }
2600
+
2601
+ if (action === 'select') {
2602
+ const selectedPaths: string[] = req.selected_paths || []
2603
+ const { data: projectItem } = await adminDb.from('items').select('id, data').eq('id', req.project_id).maybeSingle()
2604
+ if (!projectItem) throw new Error('Project not found')
2605
+
2606
+ const now = new Date().toISOString()
2607
+ const fileStatuses: Record<string, string> = { ...(projectItem.data?.file_statuses || {}) }
2608
+
2609
+ // Preserve later pass statuses; only toggle between 0-discovered and 1-selected
2610
+ const canSelect = (status?: string) => !status || status === '0-discovered' || status === '1-selected'
2611
+
2612
+ for (const p of Object.keys(fileStatuses)) {
2613
+ const isSelected = selectedPaths.includes(p)
2614
+ const current = fileStatuses[p]
2615
+ if (isSelected && canSelect(current)) {
2616
+ fileStatuses[p] = '1-selected'
2617
+ } else if (!isSelected && current === '1-selected') {
2618
+ fileStatuses[p] = '0-discovered'
2619
+ }
2620
+ }
2621
+ for (const p of selectedPaths) {
2622
+ if (fileStatuses[p] == null) {
2623
+ fileStatuses[p] = '1-selected'
2624
+ }
2625
+ }
2626
+
2627
+ const updateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: projectItem.id } }
2628
+ await adminUpdate(updateCtx, {
2629
+ data: {
2630
+ ...projectItem.data,
2631
+ selected_paths: selectedPaths,
2632
+ file_statuses: fileStatuses,
2633
+ },
2634
+ })
2635
+
2636
+ const { data: files } = await adminDb.from('items')
2637
+ .select('id, data')
2638
+ .filter('data->>kb_type', 'eq', 'cil_file')
2639
+ .filter('data->>project_id', 'eq', req.project_id)
2640
+ .eq('is_active', true)
2412
2641
 
2642
+ let selectedCount = 0
2643
+ for (const f of files || []) {
2644
+ const fp = f.data?.file_path || f.title
2645
+ const isSelected = selectedPaths.includes(fp)
2646
+ const current = f.data?.status
2647
+ const canSelect = !current || current === '0-discovered' || current === '1-selected'
2648
+ if (isSelected && canSelect) {
2649
+ await adminDb.from('items').update({
2650
+ data: { ...f.data, status: '1-selected' },
2651
+ updated_at: now,
2652
+ }).eq('id', f.id)
2653
+ selectedCount++
2654
+ } else if (!isSelected && current === '1-selected') {
2655
+ await adminDb.from('items').update({
2656
+ data: { ...f.data, status: '0-discovered' },
2657
+ updated_at: now,
2658
+ }).eq('id', f.id)
2659
+ }
2660
+ }
2413
2661
 
2662
+ return {
2663
+ ok: true,
2664
+ action: 'select',
2665
+ project_id: req.project_id,
2666
+ selected_paths: selectedPaths,
2667
+ files_selected: selectedCount,
2668
+ }
2669
+ }
2414
2670
 
2671
+ throw new Error(`Unknown action: ${action}. Valid actions: pass1, pass2, discover, select, status, promote_proposal, reject_proposal, reindex_chunk`)
2672
+ })
2673
+ // CIL[DOC-VECTOR type="context" content="purpose='Constant handler'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
2674
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
2675
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
2676
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
2677
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
2678
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
2679
+ // CIL[END stable_id="~/.framework/functions/cil-ingest.ts:handler:constant"]
2415
2680
 
2416
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_ingest_handler_1784235266"]