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,18 +1,12 @@
1
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_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-doc"]
3
- // CIL[DOC-RESPONSIBILITY responsibility="Own module-level imports, exports, and configuration for cortex.functions.custom_cil-doc"]
4
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[\"custom/apps/cortex/pages/operations/OperationsDashboard.tsx\",\"custom/apps/portal/pages/ContentPage.tsx\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\".framework/functions/_shared/schema-utils.ts\",\"\\\"]"]
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-doc" notable_decisions="[]"]
7
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:module_header:module_header" type="module_header" identity="module_header" parent="~/.framework/functions/cil-doc.ts"]
2
+ // CIL[DOC-MACRO purpose="Module header for the CIL documentation service, defining imports and module constants."]
3
+ // CIL[DOC-RESPONSIBILITY responsibility="Orients readers to the module, its entry points, and key dependencies."]
4
+ // CIL[DOC-CONTEXT module="cil-doc" layer="shared-core" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts"]
5
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
6
+ // CIL[DOC-MICRO logic_summary="Declares imports and constants used throughout the CIL documentation pipeline." notable_decisions="none"]
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: custom/apps/cortex/pages/operations/OperationsDashboard.tsx, custom/apps/portal/pages/ContentPage.tsx, .framework/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, .framework/functions/_shared/schema-utils.ts, \."]
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"]
9
+ // CIL[DOC-AUDIENCE audience="both"]
16
10
 
17
11
 
18
12
 
@@ -22,9 +16,16 @@ import { createHandler } from './_shared/middleware'
22
16
  import { adminDb } from './_shared/db'
23
17
  import { update as adminUpdate } from './admin-data'
24
18
  import { callOpenAIChat } from './_shared/llm'
25
- import { FileStatus, FileTreeNode, isSelectedPath, getFileStatus, updateTreeNodeStatus, saveProjectTree } from './_shared/cil'
19
+ import { FileStatus, FileTreeNode, isSelectedPath, getFileStatus, updateTreeNodeStatus, saveProjectTree, parseStableId } from './_shared/cil'
26
20
  import * as fs from 'fs'
27
21
  import * as path from 'path'
22
+ // CIL[DOC-VECTOR type="context" content="purpose='Module header for the CIL documentation service, defining imports and module constants.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
23
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
24
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
25
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
26
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
27
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
28
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:module_header:module_header"]
28
29
 
29
30
 
30
31
 
@@ -34,22 +35,22 @@ import * as path from 'path'
34
35
 
35
36
 
36
37
 
37
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_module_header_1784235266"]
38
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_default_model_1784235266" type="variable" identity="default_model" parent="none"]
39
- // CIL[DOC-MACRO purpose="Defines default_model configuration or state in cortex.functions.custom_cil-doc"]
40
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for default_model"]
41
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[\"custom/apps/cortex/functions/custom_cil-embeddings.ts\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\"\\\"]"]
42
- // CIL[DOC-CONTRACT inputs="none" outputs="value of default_model" errors="none" side_effects="none"]
43
- // CIL[DOC-MICRO logic_summary="Declares default_model with initial value or constant binding used by cortex.functions.custom_cil-doc" notable_decisions="[]"]
44
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
38
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:DEFAULT_MODEL:constant" type="constant" identity="DEFAULT_MODEL" parent="~/.framework/functions/cil-doc.ts"]
39
+ // CIL[DOC-MACRO purpose="Declares the d e f a u l t_ m o d e l constant used by the documentation pipeline."]
40
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides the d e f a u l t_ m o d e l value used across documentation operations."]
41
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
42
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
43
+ // CIL[DOC-MICRO logic_summary="none" notable_decisions="none"]
44
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
45
45
  // CIL[DOC-STABILITY stability="stable"]
46
- // 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/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, .framework/src/pages/admin/IntegrationsPage.tsx, \."]
47
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
48
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
49
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
46
+ const DEFAULT_MODEL = 'gpt-4o-mini'
47
+ // CIL[DOC-VECTOR type="context" content="purpose='Declares the d e f a u l t_ m o d e l constant used by the documentation pipeline.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
48
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
49
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
50
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
50
51
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
51
52
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
52
- const DEFAULT_MODEL = 'gpt-4o-mini'
53
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:DEFAULT_MODEL:constant"]
53
54
 
54
55
 
55
56
 
@@ -59,27 +60,27 @@ const DEFAULT_MODEL = 'gpt-4o-mini'
59
60
 
60
61
 
61
62
 
62
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_default_model_1784235266"]
63
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_model_prices_1784235266" type="variable" identity="model_prices" parent="none"]
64
- // CIL[DOC-MACRO purpose="Defines model_prices configuration or state in cortex.functions.custom_cil-doc"]
65
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for model_prices"]
66
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[\"custom/apps/cortex/functions/custom_cil-embeddings.ts\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\"\\\"]"]
67
- // CIL[DOC-CONTRACT inputs="none" outputs="value of model_prices" errors="none" side_effects="none"]
68
- // CIL[DOC-MICRO logic_summary="Declares model_prices with initial value or constant binding used by cortex.functions.custom_cil-doc" notable_decisions="[]"]
69
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
63
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:MODEL_PRICES:constant" type="constant" identity="MODEL_PRICES" parent="~/.framework/functions/cil-doc.ts"]
64
+ // CIL[DOC-MACRO purpose="Declares the m o d e l_ p r i c e s constant used by the documentation pipeline."]
65
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides the m o d e l_ p r i c e s value used across documentation operations."]
66
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
67
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
68
+ // CIL[DOC-MICRO logic_summary="none" notable_decisions="none"]
69
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
70
70
  // CIL[DOC-STABILITY stability="stable"]
71
- // 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/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, .framework/src/pages/admin/IntegrationsPage.tsx, \."]
72
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
73
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
74
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
75
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
76
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
77
71
  const MODEL_PRICES: Record<string, { input_per_1m: number; output_per_1m: number }> = {
78
72
  'gpt-4o-mini': { input_per_1m: 0.15, output_per_1m: 0.60 },
79
73
  'gpt-4o': { input_per_1m: 2.50, output_per_1m: 10.00 },
80
74
  'gpt-4-turbo': { input_per_1m: 10.00, output_per_1m: 30.00 },
81
75
  'gpt-3.5-turbo': { input_per_1m: 0.50, output_per_1m: 1.50 },
82
76
  }
77
+ // CIL[DOC-VECTOR type="context" content="purpose='Declares the m o d e l_ p r i c e s constant used by the documentation pipeline.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
78
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
79
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
80
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
81
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
82
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
83
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:MODEL_PRICES:constant"]
83
84
 
84
85
 
85
86
 
@@ -88,22 +89,22 @@ const MODEL_PRICES: Record<string, { input_per_1m: number; output_per_1m: number
88
89
 
89
90
 
90
91
 
91
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_model_prices_1784235266"]
92
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_estimated_output_tokens_per_chunk_1784235266" type="variable" identity="estimated_output_tokens_per_chunk" parent="none"]
93
- // CIL[DOC-MACRO purpose="Defines estimated_output_tokens_per_chunk configuration or state in cortex.functions.custom_cil-doc"]
94
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for estimated_output_tokens_per_chunk"]
95
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[\"custom/apps/cortex/functions/custom_cil-embeddings.ts\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\"\\\"]"]
96
- // CIL[DOC-CONTRACT inputs="none" outputs="value of estimated_output_tokens_per_chunk" errors="none" side_effects="none"]
97
- // CIL[DOC-MICRO logic_summary="Declares estimated_output_tokens_per_chunk with initial value or constant binding used by cortex.functions.custom_cil-doc" notable_decisions="[]"]
98
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
92
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:ESTIMATED_OUTPUT_TOKENS_PER_CHUNK:constant" type="constant" identity="ESTIMATED_OUTPUT_TOKENS_PER_CHUNK" parent="~/.framework/functions/cil-doc.ts"]
93
+ // CIL[DOC-MACRO purpose="Declares the e s t i m a t e d_ o u t p u t_ t o k e n s_ p e r_ c h u n k constant used by the documentation pipeline."]
94
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides the e s t i m a t e d_ o u t p u t_ t o k e n s_ p e r_ c h u n k value used across documentation operations."]
95
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
96
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
97
+ // CIL[DOC-MICRO logic_summary="none" notable_decisions="none"]
98
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
99
99
  // CIL[DOC-STABILITY stability="stable"]
100
- // 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/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, .framework/src/pages/admin/IntegrationsPage.tsx, \."]
101
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
102
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
103
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
100
+ const ESTIMATED_OUTPUT_TOKENS_PER_CHUNK = 200
101
+ // CIL[DOC-VECTOR type="context" content="purpose='Declares the e s t i m a t e d_ o u t p u t_ t o k e n s_ p e r_ c h u n k constant used by the documentation pipeline.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
102
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
103
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
104
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
104
105
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
105
106
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
106
- const ESTIMATED_OUTPUT_TOKENS_PER_CHUNK = 200
107
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:ESTIMATED_OUTPUT_TOKENS_PER_CHUNK:constant"]
107
108
 
108
109
 
109
110
 
@@ -111,22 +112,22 @@ const ESTIMATED_OUTPUT_TOKENS_PER_CHUNK = 200
111
112
 
112
113
 
113
114
 
114
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_estimated_output_tokens_per_chunk_1784235266"]
115
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_system_prompt_overhead_tokens_1784235266" type="variable" identity="system_prompt_overhead_tokens" parent="none"]
116
- // CIL[DOC-MACRO purpose="Defines system_prompt_overhead_tokens configuration or state in cortex.functions.custom_cil-doc"]
117
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for system_prompt_overhead_tokens"]
118
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[\"custom/apps/cortex/functions/custom_cil-embeddings.ts\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\"\\\"]"]
119
- // CIL[DOC-CONTRACT inputs="none" outputs="value of system_prompt_overhead_tokens" errors="none" side_effects="none"]
120
- // CIL[DOC-MICRO logic_summary="Declares system_prompt_overhead_tokens with initial value or constant binding used by cortex.functions.custom_cil-doc" notable_decisions="[]"]
121
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
115
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:SYSTEM_PROMPT_OVERHEAD_TOKENS:constant" type="constant" identity="SYSTEM_PROMPT_OVERHEAD_TOKENS" parent="~/.framework/functions/cil-doc.ts"]
116
+ // CIL[DOC-MACRO purpose="Declares the s y s t e m_ p r o m p t_ o v e r h e a d_ t o k e n s constant used by the documentation pipeline."]
117
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides the s y s t e m_ p r o m p t_ o v e r h e a d_ t o k e n s value used across documentation operations."]
118
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
119
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
120
+ // CIL[DOC-MICRO logic_summary="none" notable_decisions="none"]
121
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
122
122
  // CIL[DOC-STABILITY stability="stable"]
123
- // 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/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, .framework/src/pages/admin/IntegrationsPage.tsx, \."]
124
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
125
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
126
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
123
+ const SYSTEM_PROMPT_OVERHEAD_TOKENS = 350
124
+ // CIL[DOC-VECTOR type="context" content="purpose='Declares the s y s t e m_ p r o m p t_ o v e r h e a d_ t o k e n s constant used by the documentation pipeline.'; 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"]
127
128
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
128
129
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
129
- const SYSTEM_PROMPT_OVERHEAD_TOKENS = 350
130
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:SYSTEM_PROMPT_OVERHEAD_TOKENS:constant"]
130
131
 
131
132
 
132
133
 
@@ -136,24 +137,24 @@ const SYSTEM_PROMPT_OVERHEAD_TOKENS = 350
136
137
 
137
138
 
138
139
 
139
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_system_prompt_overhead_tokens_1784235266"]
140
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_estimatetokens_1784235266" type="function" identity="estimatetokens" parent="none"]
141
- // CIL[DOC-MACRO purpose="Implements estimatetokens logic in cortex.functions.custom_cil-doc"]
142
- // CIL[DOC-RESPONSIBILITY responsibility="Execute estimatetokens and return its computed result"]
143
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
144
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
145
- // CIL[DOC-MICRO logic_summary="Provides estimatetokens with estimateTokens(text: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
146
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
140
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:estimateTokens:function" type="function" identity="estimateTokens" parent="~/.framework/functions/cil-doc.ts"]
141
+ // CIL[DOC-MACRO purpose="Implements the estimate tokens behavior for CIL documentation processing."]
142
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the estimate tokens responsibility within the documentation workflow."]
143
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
144
+ // CIL[DOC-CONTRACT inputs="text: string" outputs="number" errors="none" side_effects="none"]
145
+ // CIL[DOC-MICRO logic_summary="Computes the estimate tokens result from the provided input parameters." notable_decisions="none"]
146
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
147
147
  // CIL[DOC-STABILITY stability="stable"]
148
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
149
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
150
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
151
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
152
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
153
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
154
148
  function estimateTokens(text: string): number {
155
149
  return Math.ceil(text.length / 4)
156
150
  }
151
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the estimate tokens behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
152
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
153
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
154
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
155
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
156
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
157
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:estimateTokens:function"]
157
158
 
158
159
 
159
160
 
@@ -161,21 +162,14 @@ function estimateTokens(text: string): number {
161
162
 
162
163
 
163
164
 
164
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_estimatetokens_1784235266"]
165
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_needsdocumentation_1784235266" type="function" identity="needsdocumentation" parent="none"]
166
- // CIL[DOC-MACRO purpose="Implements needsdocumentation logic in cortex.functions.custom_cil-doc"]
167
- // CIL[DOC-RESPONSIBILITY responsibility="Execute needsdocumentation and return its computed result"]
168
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
169
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
170
- // CIL[DOC-MICRO logic_summary="Provides needsdocumentation with needsDocumentation(chunk: any inputs, handling internal flow and returning a result" notable_decisions="[]"]
171
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
165
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:needsDocumentation:function" type="function" identity="needsDocumentation" parent="~/.framework/functions/cil-doc.ts"]
166
+ // CIL[DOC-MACRO purpose="Implements the needs documentation behavior for CIL documentation processing."]
167
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the needs documentation responsibility within the documentation workflow."]
168
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
169
+ // CIL[DOC-CONTRACT inputs="chunk: any" outputs="boolean" errors="none" side_effects="none"]
170
+ // CIL[DOC-MICRO logic_summary="Computes the needs documentation result from the provided input parameters." notable_decisions="none"]
171
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
172
172
  // CIL[DOC-STABILITY stability="stable"]
173
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
174
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
175
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
176
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
177
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
178
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
179
173
  function needsDocumentation(chunk: any): boolean {
180
174
  const d = chunk.data || {}
181
175
 
@@ -188,6 +182,13 @@ function needsDocumentation(chunk: any): boolean {
188
182
  : REQUIRED_CHUNK_FIELDS
189
183
  return required.some(f => !d[f] || String(d[f]).trim() === '')
190
184
  }
185
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the needs documentation behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
186
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
187
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
188
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
189
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
190
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
191
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:needsDocumentation:function"]
191
192
 
192
193
 
193
194
 
@@ -196,21 +197,14 @@ function needsDocumentation(chunk: any): boolean {
196
197
 
197
198
 
198
199
 
199
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_needsdocumentation_1784235266"]
200
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_loadallchunks_1784235266" type="function" identity="loadallchunks" parent="none"]
201
- // CIL[DOC-MACRO purpose="Implements loadallchunks logic in cortex.functions.custom_cil-doc"]
202
- // CIL[DOC-RESPONSIBILITY responsibility="Execute loadallchunks and return its computed result"]
203
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
204
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
205
- // CIL[DOC-MICRO logic_summary="Provides loadallchunks with loadAllChunks(projectId: string, filePath?: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
206
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
200
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:loadAllChunks:function" type="function" identity="loadAllChunks" parent="~/.framework/functions/cil-doc.ts"]
201
+ // CIL[DOC-MACRO purpose="Implements the load all chunks behavior for CIL documentation processing."]
202
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the load all chunks responsibility within the documentation workflow."]
203
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
204
+ // CIL[DOC-CONTRACT inputs="projectId: string, filePath?: string" outputs="Promise<any[]>" errors="Throws Error on invalid input or missing resources" side_effects="none"]
205
+ // CIL[DOC-MICRO logic_summary="Computes the load all chunks result from the provided input parameters." notable_decisions="none"]
206
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
207
207
  // CIL[DOC-STABILITY stability="stable"]
208
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
209
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
210
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
211
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
212
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
213
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
214
208
  async function loadAllChunks(projectId: string, filePath?: string): Promise<any[]> {
215
209
  const PAGE = 1000
216
210
  const all: any[] = []
@@ -232,25 +226,114 @@ async function loadAllChunks(projectId: string, filePath?: string): Promise<any[
232
226
  }
233
227
  return all
234
228
  }
229
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the load all chunks behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
230
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
231
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
232
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
233
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
234
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
235
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:loadAllChunks:function"]
236
+
235
237
 
236
238
 
237
239
 
238
240
 
239
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_loadallchunks_1784235266"]
240
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_loadpendingchunks_1784235266" type="function" identity="loadpendingchunks" parent="none"]
241
- // CIL[DOC-MACRO purpose="Implements loadpendingchunks logic in cortex.functions.custom_cil-doc"]
242
- // CIL[DOC-RESPONSIBILITY responsibility="Execute loadpendingchunks and return its computed result"]
243
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
244
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
245
- // CIL[DOC-MICRO logic_summary="Provides loadpendingchunks with loadPendingChunks(projectId: string, selectedPaths: string[], requiredStatus: FileStatus inputs, handling internal flow and returning a result" notable_decisions="[]"]
246
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
241
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:resolveChunk:function" type="function" identity="resolveChunk" parent="~/.framework/functions/cil-doc.ts"]
242
+ // CIL[DOC-MACRO purpose="Implements the resolve chunk behavior for CIL documentation processing."]
243
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the resolve chunk responsibility within the documentation workflow."]
244
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
245
+ // CIL[DOC-CONTRACT inputs="ctx: any, body: any" outputs="Promise<any>" errors="Throws Error on invalid input or missing resources" side_effects="Supabase database queries and updates"]
246
+ // CIL[DOC-MICRO logic_summary="Computes the resolve chunk result from the provided input parameters." notable_decisions="none"]
247
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
247
248
  // 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."]
249
+ async function resolveChunk(
250
+ ctx: any,
251
+ body: any
252
+ ): Promise<any> {
253
+ const stableId = body?.stable_id || ctx.query?.stable_id
254
+ const versionId = body?.version_id || ctx.query?.version_id
255
+ const chunkId = body?.chunk_id || ctx.query?.chunk_id
256
+ const chunkName = body?.chunk_name || ctx.query?.chunk_name
257
+ const projectId = body?.project_id || ctx.query?.project_id
258
+
259
+ if (stableId) {
260
+ if (parseStableId(stableId) === null) {
261
+ throw new Error(`Invalid stable_id: ${stableId}`)
262
+ }
263
+
264
+ if (versionId) {
265
+ const { data: chunk, error } = await adminDb
266
+ .from('items')
267
+ .select('id, title, data')
268
+ .filter('data->>kb_type', 'eq', 'cil_chunk')
269
+ .filter('data->>stable_id', 'eq', stableId)
270
+ .filter('data->>version_id', 'eq', versionId)
271
+ .eq('is_active', true)
272
+ .maybeSingle()
273
+ if (error || !chunk) throw new Error(`Chunk not found for stable_id: ${stableId}, version_id: ${versionId}`)
274
+ return chunk
275
+ }
276
+
277
+ let activeVersion: string | undefined
278
+ if (projectId) {
279
+ const { data: proj } = await adminDb.from('items').select('data').eq('id', projectId).maybeSingle()
280
+ activeVersion = proj?.data?.active_version_id
281
+ }
282
+
283
+ let q = adminDb
284
+ .from('items')
285
+ .select('id, title, data')
286
+ .filter('data->>kb_type', 'eq', 'cil_chunk')
287
+ .filter('data->>stable_id', 'eq', stableId)
288
+ .eq('is_active', true)
289
+ if (activeVersion) q = q.filter('data->>version_id', 'eq', activeVersion)
290
+ const { data: chunk, error } = await q.maybeSingle()
291
+ if (error || !chunk) {
292
+ throw new Error(`Chunk not found for stable_id: ${stableId}${activeVersion ? ` (active version ${activeVersion})` : ''}`)
293
+ }
294
+ return chunk
295
+ }
296
+
297
+ if (chunkId) {
298
+ const { data: chunk, error } = await adminDb
299
+ .from('items')
300
+ .select('id, title, data')
301
+ .eq('id', chunkId)
302
+ .maybeSingle()
303
+ if (error || !chunk) throw new Error(`Chunk not found: ${chunkId}`)
304
+ return chunk
305
+ }
306
+
307
+ if (chunkName) {
308
+ const { data: chunk, error } = await adminDb
309
+ .from('items')
310
+ .select('id, title, data')
311
+ .filter('data->>kb_type', 'eq', 'cil_chunk')
312
+ .filter('data->>chunk_name', 'eq', chunkName)
313
+ .eq('is_active', true)
314
+ .maybeSingle()
315
+ if (error || !chunk) throw new Error(`Chunk not found: ${chunkName}`)
316
+ return chunk
317
+ }
318
+
319
+ throw new Error('chunk_id, stable_id, or chunk_name is required')
320
+ }
321
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the resolve chunk behavior for CIL documentation processing.'; 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"]
252
325
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
253
326
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
327
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:resolveChunk:function"]
328
+
329
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:loadPendingChunks:function" type="function" identity="loadPendingChunks" parent="~/.framework/functions/cil-doc.ts"]
330
+ // CIL[DOC-MACRO purpose="Implements the load pending chunks behavior for CIL documentation processing."]
331
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the load pending chunks responsibility within the documentation workflow."]
332
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
333
+ // CIL[DOC-CONTRACT inputs="projectId: string, selectedPaths: string[], requiredStatus: FileStatus" outputs="Promise<any[]>" errors="none" side_effects="none"]
334
+ // CIL[DOC-MICRO logic_summary="Computes the load pending chunks result from the provided input parameters." notable_decisions="none"]
335
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
336
+ // CIL[DOC-STABILITY stability="stable"]
254
337
  async function loadPendingChunks(projectId: string, selectedPaths: string[], requiredStatus: FileStatus): Promise<any[]> {
255
338
  const { data: fileItems } = await adminDb
256
339
  .from('items')
@@ -274,25 +357,25 @@ async function loadPendingChunks(projectId: string, selectedPaths: string[], req
274
357
 
275
358
  return (allChunks || []).filter((c: any) => selectedFileIds.includes(c.data?.file_id))
276
359
  }
360
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the load pending chunks behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
361
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
362
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
363
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
364
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
365
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
366
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:loadPendingChunks:function"]
277
367
 
278
368
 
279
369
 
280
370
 
281
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_loadpendingchunks_1784235266"]
282
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_maybeadvancefiletopass3_1784235266" type="function" identity="maybeadvancefiletopass3" parent="none"]
283
- // CIL[DOC-MACRO purpose="Implements maybeadvancefiletopass3 logic in cortex.functions.custom_cil-doc"]
284
- // CIL[DOC-RESPONSIBILITY responsibility="Execute maybeadvancefiletopass3 and return its computed result"]
285
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
286
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
287
- // CIL[DOC-MICRO logic_summary="Provides maybeadvancefiletopass3 with maybeAdvanceFileToPass3(ctx: any, fileId: string, tree: FileTreeNode | null inputs, handling internal flow and returning a result" notable_decisions="[]"]
288
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
371
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:maybeAdvanceFileToPass3:function" type="function" identity="maybeAdvanceFileToPass3" parent="~/.framework/functions/cil-doc.ts"]
372
+ // CIL[DOC-MACRO purpose="Implements the maybe advance file to pass3 behavior for CIL documentation processing."]
373
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the maybe advance file to pass3 responsibility within the documentation workflow."]
374
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
375
+ // CIL[DOC-CONTRACT inputs="ctx: any, fileId: string, tree: FileTreeNode | null" outputs="Promise<void>" errors="none" side_effects="Supabase database queries and updates"]
376
+ // CIL[DOC-MICRO logic_summary="Computes the maybe advance file to pass3 result from the provided input parameters." notable_decisions="none"]
377
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
289
378
  // CIL[DOC-STABILITY stability="stable"]
290
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
291
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
292
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
293
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
294
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
295
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
296
379
  async function maybeAdvanceFileToPass3(ctx: any, fileId: string, tree: FileTreeNode | null): Promise<void> {
297
380
  const { data: fileChunks } = await adminDb
298
381
  .from('items')
@@ -316,13 +399,20 @@ async function maybeAdvanceFileToPass3(ctx: any, fileId: string, tree: FileTreeN
316
399
  await adminUpdate(updateCtx, {
317
400
  data: {
318
401
  ...fileItem.data,
319
- status: 'pass3_complete',
402
+ status: '3-documented',
320
403
  last_status_at: new Date().toISOString(),
321
404
  },
322
405
  }).catch((e: any) => console.error('advance to pass3 failed:', e.message))
323
406
 
324
- if (tree) updateTreeNodeStatus(tree, fileId, 'pass3_complete')
407
+ if (tree) updateTreeNodeStatus(tree, fileId, '3-documented')
325
408
  }
409
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the maybe advance file to pass3 behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
410
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
411
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
412
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
413
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
414
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
415
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:maybeAdvanceFileToPass3:function"]
326
416
 
327
417
 
328
418
 
@@ -377,83 +467,76 @@ async function maybeAdvanceFileToPass3(ctx: any, fileId: string, tree: FileTreeN
377
467
 
378
468
 
379
469
 
380
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_maybeadvancefiletopass3_1784235266"]
381
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_required_module_fields_1784235266" type="variable" identity="required_module_fields" parent="none"]
382
- // CIL[DOC-MACRO purpose="Defines required_module_fields configuration or state in cortex.functions.custom_cil-doc"]
383
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for required_module_fields"]
384
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
385
- // CIL[DOC-CONTRACT inputs="none" outputs="value of required_module_fields" errors="none" side_effects="none"]
386
- // CIL[DOC-MICRO logic_summary="Declares required_module_fields with initial value or constant binding used by cortex.functions.custom_cil-doc" notable_decisions="[]"]
387
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
470
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:REQUIRED_MODULE_FIELDS:constant" type="constant" identity="REQUIRED_MODULE_FIELDS" parent="~/.framework/functions/cil-doc.ts"]
471
+ // CIL[DOC-MACRO purpose="Declares the r e q u i r e d_ m o d u l e_ f i e l d s constant used by the documentation pipeline."]
472
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides the r e q u i r e d_ m o d u l e_ f i e l d s value used across documentation operations."]
473
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
474
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
475
+ // CIL[DOC-MICRO logic_summary="none" notable_decisions="none"]
476
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
388
477
  // CIL[DOC-STABILITY stability="stable"]
389
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
390
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
391
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
392
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
478
+ const REQUIRED_MODULE_FIELDS = ['module', 'audience', 'layer', 'stability', 'description']
479
+ // CIL[DOC-VECTOR type="context" content="purpose='Declares the r e q u i r e d_ m o d u l e_ f i e l d s constant used by the documentation pipeline.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
480
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
481
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
482
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
393
483
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
394
484
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
395
- const REQUIRED_MODULE_FIELDS = ['module', 'audience', 'layer', 'stability', 'description']
485
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:REQUIRED_MODULE_FIELDS:constant"]
396
486
 
397
487
 
398
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_required_module_fields_1784235266"]
399
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_required_chunk_fields_1784235266" type="variable" identity="required_chunk_fields" parent="none"]
400
- // CIL[DOC-MACRO purpose="Defines required_chunk_fields configuration or state in cortex.functions.custom_cil-doc"]
401
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for required_chunk_fields"]
402
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
403
- // CIL[DOC-CONTRACT inputs="none" outputs="value of required_chunk_fields" errors="none" side_effects="none"]
404
- // CIL[DOC-MICRO logic_summary="Declares required_chunk_fields with initial value or constant binding used by cortex.functions.custom_cil-doc" notable_decisions="[]"]
405
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
488
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:REQUIRED_CHUNK_FIELDS:constant" type="constant" identity="REQUIRED_CHUNK_FIELDS" parent="~/.framework/functions/cil-doc.ts"]
489
+ // CIL[DOC-MACRO purpose="Declares the r e q u i r e d_ c h u n k_ f i e l d s constant used by the documentation pipeline."]
490
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides the r e q u i r e d_ c h u n k_ f i e l d s value used across documentation operations."]
491
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
492
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
493
+ // CIL[DOC-MICRO logic_summary="none" notable_decisions="none"]
494
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
406
495
  // CIL[DOC-STABILITY stability="stable"]
407
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
408
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
409
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
410
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
496
+ const REQUIRED_CHUNK_FIELDS = ['description', 'input_spec', 'output_spec', 'side_effects', 'stability']
497
+ // CIL[DOC-VECTOR type="context" content="purpose='Declares the r e q u i r e d_ c h u n k_ f i e l d s constant used by the documentation pipeline.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
498
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
499
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
500
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
411
501
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
412
502
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
413
- const REQUIRED_CHUNK_FIELDS = ['description', 'input_spec', 'output_spec', 'side_effects', 'stability']
503
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:REQUIRED_CHUNK_FIELDS:constant"]
414
504
 
415
505
 
416
506
 
417
507
 
418
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_required_chunk_fields_1784235266"]
419
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_modulenamefrompath_1784235266" type="function" identity="modulenamefrompath" parent="none"]
420
- // CIL[DOC-MACRO purpose="Implements modulenamefrompath logic in cortex.functions.custom_cil-doc"]
421
- // CIL[DOC-RESPONSIBILITY responsibility="Execute modulenamefrompath and return its computed result"]
422
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
423
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
424
- // CIL[DOC-MICRO logic_summary="Provides modulenamefrompath with moduleNameFromPath(relPath: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
425
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
508
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:moduleNameFromPath:function" type="function" identity="moduleNameFromPath" parent="~/.framework/functions/cil-doc.ts"]
509
+ // CIL[DOC-MACRO purpose="Implements the module name from path behavior for CIL documentation processing."]
510
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the module name from path responsibility within the documentation workflow."]
511
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
512
+ // CIL[DOC-CONTRACT inputs="relPath: string" outputs="string" errors="none" side_effects="none"]
513
+ // CIL[DOC-MICRO logic_summary="Computes the module name from path result from the provided input parameters." notable_decisions="none"]
514
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
426
515
  // CIL[DOC-STABILITY stability="stable"]
427
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
428
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
429
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
430
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
431
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
432
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
433
516
  function moduleNameFromPath(relPath: string): string {
434
517
  return path.basename(relPath, path.extname(relPath))
435
518
  }
519
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the module name from path behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
520
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
521
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
522
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
523
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
524
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
525
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:moduleNameFromPath:function"]
436
526
 
437
527
 
438
528
 
439
529
 
440
530
 
441
531
 
442
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_modulenamefrompath_1784235266"]
443
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_buildjsdoc_1784235266" type="function" identity="buildjsdoc" parent="none"]
444
- // CIL[DOC-MACRO purpose="Implements buildjsdoc logic in cortex.functions.custom_cil-doc"]
445
- // CIL[DOC-RESPONSIBILITY responsibility="Execute buildjsdoc and return its computed result"]
446
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
447
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
448
- // CIL[DOC-MICRO logic_summary="Provides buildjsdoc with buildJsDoc(chunk: any inputs, handling internal flow and returning a result" notable_decisions="[]"]
449
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
532
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:buildJsDoc:function" type="function" identity="buildJsDoc" parent="~/.framework/functions/cil-doc.ts"]
533
+ // CIL[DOC-MACRO purpose="Implements the build js doc behavior for CIL documentation processing."]
534
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the build js doc responsibility within the documentation workflow."]
535
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
536
+ // CIL[DOC-CONTRACT inputs="chunk: any" outputs="string" errors="none" side_effects="local file system access"]
537
+ // CIL[DOC-MICRO logic_summary="Computes the build js doc result from the provided input parameters." notable_decisions="Skips redundant macro/micro lines and filters trivial calls from the @calls tag."]
538
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
450
539
  // CIL[DOC-STABILITY stability="stable"]
451
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
452
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
453
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
454
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
455
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
456
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
457
540
  function buildJsDoc(chunk: any): string {
458
541
  const d = chunk.data || {}
459
542
  const isModuleHeader = d.chunk_type === 'module_header'
@@ -565,26 +648,83 @@ function buildJsDoc(chunk: any): string {
565
648
  ]
566
649
  return docLines.join('\n')
567
650
  }
651
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the build js doc behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
652
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
653
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
654
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
655
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
656
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
657
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:buildJsDoc:function"]
568
658
 
569
659
 
570
660
 
571
661
 
572
662
 
573
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_buildjsdoc_1784235266"]
574
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_validatechunkdocs_1784235266" type="function" identity="validatechunkdocs" parent="none"]
575
- // CIL[DOC-MACRO purpose="Implements validatechunkdocs logic in cortex.functions.custom_cil-doc"]
576
- // CIL[DOC-RESPONSIBILITY responsibility="Execute validatechunkdocs and return its computed result"]
577
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
578
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
579
- // CIL[DOC-MICRO logic_summary="Provides validatechunkdocs with validateChunkDocs(chunk: any inputs, handling internal flow and returning a result" notable_decisions="[]"]
580
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
663
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:validateChunkDocs:function" type="function" identity="validateChunkDocs" parent="~/.framework/functions/cil-doc.ts"]
664
+ // CIL[DOC-MACRO purpose="Implements the validate chunk docs behavior for CIL documentation processing."]
665
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the validate chunk docs responsibility within the documentation workflow."]
666
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
667
+ // CIL[DOC-CONTRACT inputs="chunk: any, text: string" outputs="string[]" errors="none" side_effects="none"]
668
+ // CIL[DOC-MICRO logic_summary="Computes the validate chunk docs result from the provided input parameters." notable_decisions="none"]
669
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
581
670
  // CIL[DOC-STABILITY stability="stable"]
582
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
583
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
584
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
585
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
586
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
587
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
671
+ function splitParameterList(text: string): string[] {
672
+ const parts: string[] = []
673
+ let depth = 0
674
+ let inString = false
675
+ let quote = ''
676
+ let current = ''
677
+ for (const ch of text) {
678
+ if (inString) {
679
+ if (ch === quote) inString = false
680
+ current += ch
681
+ continue
682
+ }
683
+ if (ch === '"' || ch === "'" || ch === '`') {
684
+ inString = true
685
+ quote = ch
686
+ current += ch
687
+ continue
688
+ }
689
+ if (ch === '(' || ch === '[' || ch === '<' || ch === '{') depth++
690
+ else if (ch === ')' || ch === ']' || ch === '>' || ch === '}') depth = Math.max(0, depth - 1)
691
+ else if ((ch === ',' || ch === '\n') && depth === 0) {
692
+ parts.push(current)
693
+ current = ''
694
+ continue
695
+ }
696
+ current += ch
697
+ }
698
+ parts.push(current)
699
+ return parts.map(s => s.trim()).filter(Boolean)
700
+ }
701
+
702
+ function expandParamEntries(rawParams: string): Array<{ name: string; type: string; optional: boolean }> {
703
+ const out: Array<{ name: string; type: string; optional: boolean }> = []
704
+ const push = (part: string, depth: number): void => {
705
+ if (depth > 4) return
706
+ const t = part.trim()
707
+ if (!t) return
708
+ const open = t[0]
709
+ if (open === '{' || open === '[') {
710
+ const close = open === '{' ? '}' : ']'
711
+ let d = 0
712
+ let end = -1
713
+ for (let i = 0; i < t.length; i++) {
714
+ if (t[i] === open) d++
715
+ else if (t[i] === close) { d--; if (d === 0) { end = i; break } }
716
+ }
717
+ const inner = end > 0 ? t.slice(1, end) : t.slice(1, -1)
718
+ for (const p of splitParameterList(inner)) push(p, depth + 1)
719
+ return
720
+ }
721
+ const m = t.replace(/^\.\.\./, '').match(/^([A-Za-z_$][A-Za-z0-9_$]*)(\?)?\s*(?::\s*([^=]+?))?(?:\s*=.*)?$/)
722
+ if (m) out.push({ name: m[1], type: (m[3] || 'any').trim(), optional: !!m[2] || t.includes('=') })
723
+ }
724
+ for (const part of splitParameterList(rawParams)) push(part, 0)
725
+ return out
726
+ }
727
+
588
728
  function validateChunkDocs(chunk: any): string[] {
589
729
  const d = chunk.data || {}
590
730
  const errors: string[] = []
@@ -598,8 +738,7 @@ function validateChunkDocs(chunk: any): string[] {
598
738
  }
599
739
 
600
740
  if (!isModuleHeader && d.input_spec && d.input_spec !== 'none') {
601
- const params = d.input_spec.split(/\n/).map((s: string) => s.trim()).filter(Boolean)
602
- const paramNames = params.map(p => {
741
+ const paramNames = splitParameterList(d.input_spec).map(p => {
603
742
  const m = p.match(/^[-\s]*([a-zA-Z0-9_]+)/)
604
743
  return m ? m[1] : ''
605
744
  }).filter(Boolean)
@@ -608,12 +747,7 @@ function validateChunkDocs(chunk: any): string[] {
608
747
  const signatureMatch = code.match(/(?:function|const|let|var)\s+\w+\s*\(([^)]*)\)/)
609
748
  if (signatureMatch) {
610
749
  const rawParams = signatureMatch[1]
611
- const declaredNames = rawParams
612
- .split(',')
613
- .map(s => s.trim())
614
- .filter(s => s)
615
- .map(s => s.split(/[:=]/)[0].trim().replace(/\?/, ''))
616
- .filter(Boolean)
750
+ const declaredNames = expandParamEntries(rawParams).map(p => p.name)
617
751
  for (const declared of declaredNames) {
618
752
  if (!paramNames.includes(declared)) {
619
753
  errors.push(`undocumented parameter: ${declared}`)
@@ -624,26 +758,22 @@ function validateChunkDocs(chunk: any): string[] {
624
758
 
625
759
  return errors
626
760
  }
627
-
628
-
629
-
630
-
631
-
632
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_validatechunkdocs_1784235266"]
633
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_findexistingciljsdoc_1784235266" type="function" identity="findexistingciljsdoc" parent="none"]
634
- // CIL[DOC-MACRO purpose="Implements findexistingciljsdoc logic in cortex.functions.custom_cil-doc"]
635
- // CIL[DOC-RESPONSIBILITY responsibility="Execute findexistingciljsdoc and return its computed result"]
636
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
637
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
638
- // CIL[DOC-MICRO logic_summary="Provides findexistingciljsdoc with findExistingCilJsDoc(lines: string[], markerIdx: number inputs, handling internal flow and returning a result" notable_decisions="[]"]
639
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
640
- // CIL[DOC-STABILITY stability="stable"]
641
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
642
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
643
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
644
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
761
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the validate chunk docs behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
762
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
763
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
764
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
645
765
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
646
766
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
767
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:validateChunkDocs:function"]
768
+
769
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:findExistingCilJsDoc:function" type="function" identity="findExistingCilJsDoc" parent="~/.framework/functions/cil-doc.ts"]
770
+ // CIL[DOC-MACRO purpose="Implements the find existing cil js doc behavior for CIL documentation processing."]
771
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the find existing cil js doc responsibility within the documentation workflow."]
772
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
773
+ // CIL[DOC-CONTRACT inputs="lines: string[], markerIdx: number" outputs="void" errors="none" side_effects="none"]
774
+ // CIL[DOC-MICRO logic_summary="Computes the find existing cil js doc result from the provided input parameters." notable_decisions="none"]
775
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
776
+ // CIL[DOC-STABILITY stability="stable"]
647
777
  function findExistingCilJsDoc(lines: string[], markerIdx: number): { start: number; end: number } | null {
648
778
  let startIdx = -1
649
779
  for (let i = markerIdx + 1; i < lines.length; i++) {
@@ -664,26 +794,26 @@ function findExistingCilJsDoc(lines: string[], markerIdx: number): { start: numb
664
794
  if (endIdx === -1 || !hasCilTag) return null
665
795
  return { start: startIdx, end: endIdx }
666
796
  }
797
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the find existing cil js doc behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
798
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
799
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
800
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
801
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
802
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
803
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:findExistingCilJsDoc:function"]
667
804
 
668
805
 
669
806
 
670
807
 
671
808
 
672
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_findexistingciljsdoc_1784235266"]
673
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_findlegacyciljsdocabove_1784235266" type="function" identity="findlegacyciljsdocabove" parent="none"]
674
- // CIL[DOC-MACRO purpose="Implements findlegacyciljsdocabove logic in cortex.functions.custom_cil-doc"]
675
- // CIL[DOC-RESPONSIBILITY responsibility="Execute findlegacyciljsdocabove and return its computed result"]
676
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
677
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
678
- // CIL[DOC-MICRO logic_summary="Provides findlegacyciljsdocabove with findLegacyCilJsDocAbove(lines: string[], markerIdx: number inputs, handling internal flow and returning a result" notable_decisions="[]"]
679
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
809
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:findLegacyCilJsDocAbove:function" type="function" identity="findLegacyCilJsDocAbove" parent="~/.framework/functions/cil-doc.ts"]
810
+ // CIL[DOC-MACRO purpose="Implements the find legacy cil js doc above behavior for CIL documentation processing."]
811
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the find legacy cil js doc above responsibility within the documentation workflow."]
812
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
813
+ // CIL[DOC-CONTRACT inputs="lines: string[], markerIdx: number" outputs="void" errors="none" side_effects="none"]
814
+ // CIL[DOC-MICRO logic_summary="Computes the find legacy cil js doc above result from the provided input parameters." notable_decisions="none"]
815
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
680
816
  // CIL[DOC-STABILITY stability="stable"]
681
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
682
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
683
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
684
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
685
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
686
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
687
817
  function findLegacyCilJsDocAbove(lines: string[], markerIdx: number): { start: number; end: number } | null {
688
818
  let endIdx = -1
689
819
  for (let i = markerIdx - 1; i >= 0; i--) {
@@ -705,26 +835,26 @@ function findLegacyCilJsDocAbove(lines: string[], markerIdx: number): { start: n
705
835
 
706
836
  return { start: startIdx, end: endIdx }
707
837
  }
838
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the find legacy cil js doc above behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
839
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
840
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
841
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
842
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
843
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
844
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:findLegacyCilJsDocAbove:function"]
708
845
 
709
846
 
710
847
 
711
848
 
712
849
 
713
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_findlegacyciljsdocabove_1784235266"]
714
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_writejsdoctosource_1784235266" type="function" identity="writejsdoctosource" parent="none"]
715
- // CIL[DOC-MACRO purpose="Implements writejsdoctosource logic in cortex.functions.custom_cil-doc"]
716
- // CIL[DOC-RESPONSIBILITY responsibility="Execute writejsdoctosource and return its computed result"]
717
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
718
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
719
- // CIL[DOC-MICRO logic_summary="Provides writejsdoctosource with writeJsDocToSource(chunk: any, repoPath: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
720
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
850
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:writeJsDocToSource:function" type="function" identity="writeJsDocToSource" parent="~/.framework/functions/cil-doc.ts"]
851
+ // CIL[DOC-MACRO purpose="Implements the write js doc to source behavior for CIL documentation processing."]
852
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the write js doc to source responsibility within the documentation workflow."]
853
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
854
+ // CIL[DOC-CONTRACT inputs="chunk: any, repoPath: string" outputs="void" errors="none" side_effects="local file system access"]
855
+ // CIL[DOC-MICRO logic_summary="Computes the write js doc to source result from the provided input parameters." notable_decisions="none"]
856
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
721
857
  // CIL[DOC-STABILITY stability="stable"]
722
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
723
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
724
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
725
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
726
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
727
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
728
858
  function writeJsDocToSource(chunk: any, repoPath: string): void {
729
859
  const d = chunk.data || {}
730
860
  const relPath = d.file_path
@@ -765,27 +895,34 @@ function writeJsDocToSource(chunk: any, repoPath: string): void {
765
895
 
766
896
  fs.writeFileSync(absPath, newLines.join('\n'), 'utf-8')
767
897
  }
898
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the write js doc to source behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
899
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
900
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
901
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
902
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
903
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
904
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:writeJsDocToSource:function"]
768
905
 
769
906
 
770
907
 
771
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_writejsdoctosource_1784235266"]
772
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_escaperegexp_1784235266" type="function" identity="escaperegexp" parent="none"]
773
- // CIL[DOC-MACRO purpose="Implements escaperegexp logic in cortex.functions.custom_cil-doc"]
774
- // CIL[DOC-RESPONSIBILITY responsibility="Execute escaperegexp and return its computed result"]
775
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
776
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
777
- // CIL[DOC-MICRO logic_summary="Provides escaperegexp with escapeRegExp(s: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
778
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
908
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:escapeRegExp:function" type="function" identity="escapeRegExp" parent="~/.framework/functions/cil-doc.ts"]
909
+ // CIL[DOC-MACRO purpose="Implements the escape reg exp behavior for CIL documentation processing."]
910
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the escape reg exp responsibility within the documentation workflow."]
911
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
912
+ // CIL[DOC-CONTRACT inputs="s: string" outputs="string" errors="none" side_effects="none"]
913
+ // CIL[DOC-MICRO logic_summary="Computes the escape reg exp result from the provided input parameters." notable_decisions="none"]
914
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
779
915
  // CIL[DOC-STABILITY stability="stable"]
780
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
781
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
782
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
783
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
784
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
785
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
786
916
  function escapeRegExp(s: string): string {
787
917
  return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
788
918
  }
919
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the escape reg exp behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
920
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
921
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
922
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
923
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
924
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
925
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:escapeRegExp:function"]
789
926
 
790
927
 
791
928
 
@@ -796,22 +933,22 @@ function escapeRegExp(s: string): string {
796
933
 
797
934
 
798
935
 
799
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_escaperegexp_1784235266"]
800
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_chunk_start_marker_re_1784235266" type="variable" identity="chunk_start_marker_re" parent="none"]
801
- // CIL[DOC-MACRO purpose="Defines chunk_start_marker_re configuration or state in cortex.functions.custom_cil-doc"]
802
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for chunk_start_marker_re"]
803
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
804
- // CIL[DOC-CONTRACT inputs="none" outputs="value of chunk_start_marker_re" errors="none" side_effects="none"]
805
- // CIL[DOC-MICRO logic_summary="Declares chunk_start_marker_re with initial value or constant binding used by cortex.functions.custom_cil-doc" notable_decisions="[]"]
806
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
936
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:CHUNK_START_MARKER_RE:constant" type="constant" identity="CHUNK_START_MARKER_RE" parent="~/.framework/functions/cil-doc.ts"]
937
+ // CIL[DOC-MACRO purpose="Declares the c h u n k_ s t a r t_ m a r k e r_ r e constant used by the documentation pipeline."]
938
+ // CIL[DOC-RESPONSIBILITY responsibility="Provides the c h u n k_ s t a r t_ m a r k e r_ r e value used across documentation operations."]
939
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
940
+ // CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
941
+ // CIL[DOC-MICRO logic_summary="none" notable_decisions="none"]
942
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
807
943
  // CIL[DOC-STABILITY stability="stable"]
808
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
809
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
810
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
811
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
944
+ const CHUNK_START_MARKER_RE = /^\s*\/\/\s*CIL\[BEGIN\s+[^\]]*identity="([^"]+)"[^\]]*\]\s*$/
945
+ // CIL[DOC-VECTOR type="context" content="purpose='Declares the c h u n k_ s t a r t_ m a r k e r_ r e constant used by the documentation pipeline.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
946
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
947
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
948
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
812
949
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
813
950
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
814
- const CHUNK_START_MARKER_RE = /^\s*\/\*\*\s*[─\-]+\s*CHUNK_START:\s*(?:PROPOSAL\s+|REJECTED\s+)?(.+?)\s*[─\-]*\s*\*\/\s*$/
951
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:CHUNK_START_MARKER_RE:constant"]
815
952
 
816
953
 
817
954
 
@@ -822,21 +959,14 @@ const CHUNK_START_MARKER_RE = /^\s*\/\*\*\s*[─\-]+\s*CHUNK_START:\s*(?:PROPOSA
822
959
 
823
960
 
824
961
 
825
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_chunk_start_marker_re_1784235266"]
826
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_findchunkstartmarkers_1784235266" type="function" identity="findchunkstartmarkers" parent="none"]
827
- // CIL[DOC-MACRO purpose="Implements findchunkstartmarkers logic in cortex.functions.custom_cil-doc"]
828
- // CIL[DOC-RESPONSIBILITY responsibility="Execute findchunkstartmarkers and return its computed result"]
829
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
830
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
831
- // CIL[DOC-MICRO logic_summary="Provides findchunkstartmarkers with findChunkStartMarkers(lines: string[] inputs, handling internal flow and returning a result" notable_decisions="[]"]
832
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
962
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:findChunkStartMarkers:function" type="function" identity="findChunkStartMarkers" parent="~/.framework/functions/cil-doc.ts"]
963
+ // CIL[DOC-MACRO purpose="Implements the find chunk start markers behavior for CIL documentation processing."]
964
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the find chunk start markers responsibility within the documentation workflow."]
965
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
966
+ // CIL[DOC-CONTRACT inputs="lines: string[]" outputs="Map<string," errors="none" side_effects="none"]
967
+ // CIL[DOC-MICRO logic_summary="Computes the find chunk start markers result from the provided input parameters." notable_decisions="none"]
968
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
833
969
  // CIL[DOC-STABILITY stability="stable"]
834
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
835
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
836
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
837
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
838
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
839
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
840
970
  function findChunkStartMarkers(lines: string[]): Map<string, number> {
841
971
  const map = new Map<string, number>()
842
972
  for (let i = 0; i < lines.length; i++) {
@@ -848,6 +978,13 @@ function findChunkStartMarkers(lines: string[]): Map<string, number> {
848
978
  }
849
979
  return map
850
980
  }
981
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the find chunk start markers behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
982
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
983
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
984
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
985
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
986
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
987
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:findChunkStartMarkers:function"]
851
988
 
852
989
 
853
990
 
@@ -855,27 +992,27 @@ function findChunkStartMarkers(lines: string[]): Map<string, number> {
855
992
 
856
993
 
857
994
 
858
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_findchunkstartmarkers_1784235266"]
859
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_builddocprompt_1784235266" type="function" identity="builddocprompt" parent="none"]
860
- // CIL[DOC-MACRO purpose="Implements builddocprompt logic in cortex.functions.custom_cil-doc"]
861
- // CIL[DOC-RESPONSIBILITY responsibility="Execute builddocprompt and return its computed result"]
862
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
863
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
864
- // CIL[DOC-MICRO logic_summary="Provides builddocprompt with buildDocPrompt(chunk: any inputs, handling internal flow and returning a result" notable_decisions="[]"]
865
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
995
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:buildDocPrompt:function" type="function" identity="buildDocPrompt" parent="~/.framework/functions/cil-doc.ts"]
996
+ // CIL[DOC-MACRO purpose="Implements the build doc prompt behavior for CIL documentation processing."]
997
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the build doc prompt responsibility within the documentation workflow."]
998
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
999
+ // CIL[DOC-CONTRACT inputs="chunk: any" outputs="string" errors="none" side_effects="none"]
1000
+ // CIL[DOC-MICRO logic_summary="Computes the build doc prompt result from the provided input parameters." notable_decisions="none"]
1001
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
866
1002
  // CIL[DOC-STABILITY stability="stable"]
867
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
868
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
869
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
870
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
871
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
872
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
873
1003
  function buildDocPrompt(chunk: any): string {
874
1004
  const d = chunk.data || {}
875
1005
  const code = (d.code_content || '').slice(0, 3000)
876
1006
  const isModuleHeader = d.chunk_type === 'module_header'
877
1007
  return isModuleHeader ? buildModuleHeaderPrompt(d, code) : buildChunkPrompt(d, code)
878
1008
  }
1009
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the build doc prompt behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1010
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1011
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1012
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1013
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1014
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1015
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:buildDocPrompt:function"]
879
1016
 
880
1017
 
881
1018
 
@@ -886,21 +1023,14 @@ function buildDocPrompt(chunk: any): string {
886
1023
 
887
1024
 
888
1025
 
889
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_builddocprompt_1784235266"]
890
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_buildmoduleheaderprompt_1784235266" type="function" identity="buildmoduleheaderprompt" parent="none"]
891
- // CIL[DOC-MACRO purpose="Implements buildmoduleheaderprompt logic in cortex.functions.custom_cil-doc"]
892
- // CIL[DOC-RESPONSIBILITY responsibility="Execute buildmoduleheaderprompt and return its computed result"]
893
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
894
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
895
- // CIL[DOC-MICRO logic_summary="Provides buildmoduleheaderprompt with buildModuleHeaderPrompt(d: any, code: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
896
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1026
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:buildModuleHeaderPrompt:function" type="function" identity="buildModuleHeaderPrompt" parent="~/.framework/functions/cil-doc.ts"]
1027
+ // CIL[DOC-MACRO purpose="Implements the build module header prompt behavior for CIL documentation processing."]
1028
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the build module header prompt responsibility within the documentation workflow."]
1029
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
1030
+ // CIL[DOC-CONTRACT inputs="d: any, code: string" outputs="string" errors="none" side_effects="none"]
1031
+ // CIL[DOC-MICRO logic_summary="Computes the build module header prompt result from the provided input parameters." notable_decisions="none"]
1032
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
897
1033
  // CIL[DOC-STABILITY stability="stable"]
898
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
899
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
900
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
901
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
902
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
903
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
904
1034
  function buildModuleHeaderPrompt(d: any, code: string): string {
905
1035
  const filePath = d.file_path || 'unknown'
906
1036
  return `You are documenting the MODULE HEADER for file: ${filePath}
@@ -935,6 +1065,13 @@ Respond ONLY with a JSON object (no markdown, no commentary):
935
1065
  "tags": "<comma-separated relevant tags>"
936
1066
  }`
937
1067
  }
1068
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the build module header prompt behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1069
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1070
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1071
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1072
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1073
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1074
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:buildModuleHeaderPrompt:function"]
938
1075
 
939
1076
 
940
1077
 
@@ -945,21 +1082,14 @@ Respond ONLY with a JSON object (no markdown, no commentary):
945
1082
 
946
1083
 
947
1084
 
948
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_buildmoduleheaderprompt_1784235266"]
949
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_buildchunkprompt_1784235266" type="function" identity="buildchunkprompt" parent="none"]
950
- // CIL[DOC-MACRO purpose="Implements buildchunkprompt logic in cortex.functions.custom_cil-doc"]
951
- // CIL[DOC-RESPONSIBILITY responsibility="Execute buildchunkprompt and return its computed result"]
952
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
953
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
954
- // CIL[DOC-MICRO logic_summary="Provides buildchunkprompt with buildChunkPrompt(d: any, code: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
955
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1085
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:buildChunkPrompt:function" type="function" identity="buildChunkPrompt" parent="~/.framework/functions/cil-doc.ts"]
1086
+ // CIL[DOC-MACRO purpose="Implements the build chunk prompt behavior for CIL documentation processing."]
1087
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the build chunk prompt responsibility within the documentation workflow."]
1088
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
1089
+ // CIL[DOC-CONTRACT inputs="d: any, code: string" outputs="string" errors="none" side_effects="Supabase database queries and updates"]
1090
+ // CIL[DOC-MICRO logic_summary="Computes the build chunk prompt result from the provided input parameters." notable_decisions="none"]
1091
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
956
1092
  // CIL[DOC-STABILITY stability="stable"]
957
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
958
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
959
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
960
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
961
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
962
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
963
1093
  function buildChunkPrompt(d: any, code: string): string {
964
1094
  const chunkType = d.chunk_type || 'function'
965
1095
  const chunkName = d.chunk_name || 'unknown'
@@ -1026,6 +1156,13 @@ Respond ONLY with a JSON object (no markdown, no commentary):
1026
1156
  "tags": "<comma-separated tags>"
1027
1157
  }`
1028
1158
  }
1159
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the build chunk prompt behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1160
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1161
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1162
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1163
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1164
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1165
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:buildChunkPrompt:function"]
1029
1166
 
1030
1167
 
1031
1168
 
@@ -1035,21 +1172,14 @@ Respond ONLY with a JSON object (no markdown, no commentary):
1035
1172
 
1036
1173
 
1037
1174
 
1038
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_buildchunkprompt_1784235266"]
1039
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_callllm_1784235266" type="function" identity="callllm" parent="none"]
1040
- // CIL[DOC-MACRO purpose="Implements callllm logic in cortex.functions.custom_cil-doc"]
1041
- // CIL[DOC-RESPONSIBILITY responsibility="Execute callllm and return its computed result"]
1042
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
1043
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
1044
- // CIL[DOC-MICRO logic_summary="Provides callllm with callLLM(prompt: string, model: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
1045
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1175
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:callLLM:function" type="function" identity="callLLM" parent="~/.framework/functions/cil-doc.ts"]
1176
+ // CIL[DOC-MACRO purpose="Implements the call l l m behavior for CIL documentation processing."]
1177
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the call l l m responsibility within the documentation workflow."]
1178
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
1179
+ // CIL[DOC-CONTRACT inputs="prompt: string, model: string" outputs="Promise<string>" errors="none" side_effects="OpenAI chat API call"]
1180
+ // CIL[DOC-MICRO logic_summary="Computes the call l l m result from the provided input parameters." notable_decisions="none"]
1181
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
1046
1182
  // CIL[DOC-STABILITY stability="stable"]
1047
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1048
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1049
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1050
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
1051
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1052
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1053
1183
  async function callLLM(prompt: string, model: string): Promise<string> {
1054
1184
  const j = await callOpenAIChat(undefined, [
1055
1185
  {
@@ -1064,26 +1194,26 @@ async function callLLM(prompt: string, model: string): Promise<string> {
1064
1194
  })
1065
1195
  return j.choices?.[0]?.message?.content?.trim() || '{}'
1066
1196
  }
1197
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the call l l m behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1198
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1199
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1200
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1201
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1202
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1203
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:callLLM:function"]
1067
1204
 
1068
1205
 
1069
1206
 
1070
1207
 
1071
1208
 
1072
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_callllm_1784235266"]
1073
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_parsedocresponse_1784235266" type="function" identity="parsedocresponse" parent="none"]
1074
- // CIL[DOC-MACRO purpose="Implements parsedocresponse logic in cortex.functions.custom_cil-doc"]
1075
- // CIL[DOC-RESPONSIBILITY responsibility="Execute parsedocresponse and return its computed result"]
1076
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
1077
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
1078
- // CIL[DOC-MICRO logic_summary="Provides parsedocresponse with parseDocResponse(raw: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
1079
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1209
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:parseDocResponse:function" type="function" identity="parseDocResponse" parent="~/.framework/functions/cil-doc.ts"]
1210
+ // CIL[DOC-MACRO purpose="Implements the parse doc response behavior for CIL documentation processing."]
1211
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the parse doc response responsibility within the documentation workflow."]
1212
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
1213
+ // CIL[DOC-CONTRACT inputs="raw: string" outputs="Record<string," errors="none" side_effects="none"]
1214
+ // CIL[DOC-MICRO logic_summary="Computes the parse doc response result from the provided input parameters." notable_decisions="none"]
1215
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
1080
1216
  // CIL[DOC-STABILITY stability="stable"]
1081
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1082
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1083
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1084
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
1085
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1086
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1087
1217
  function parseDocResponse(raw: string): Record<string, string> {
1088
1218
  try {
1089
1219
 
@@ -1119,6 +1249,13 @@ function parseDocResponse(raw: string): Record<string, string> {
1119
1249
  return {}
1120
1250
  }
1121
1251
  }
1252
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the parse doc response behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1253
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1254
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1255
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1256
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1257
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1258
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:parseDocResponse:function"]
1122
1259
 
1123
1260
 
1124
1261
 
@@ -1128,25 +1265,25 @@ function parseDocResponse(raw: string): Record<string, string> {
1128
1265
 
1129
1266
 
1130
1267
 
1131
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_parsedocresponse_1784235266"]
1132
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_hasmeaningfulllmfields_1784235266" type="function" identity="hasmeaningfulllmfields" parent="none"]
1133
- // CIL[DOC-MACRO purpose="Implements hasmeaningfulllmfields logic in cortex.functions.custom_cil-doc"]
1134
- // CIL[DOC-RESPONSIBILITY responsibility="Execute hasmeaningfulllmfields and return its computed result"]
1135
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
1136
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
1137
- // CIL[DOC-MICRO logic_summary="Provides hasmeaningfulllmfields with hasMeaningfulLlmFields(fields: Record<string, string> inputs, handling internal flow and returning a result" notable_decisions="[]"]
1138
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1268
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:hasMeaningfulLlmFields:function" type="function" identity="hasMeaningfulLlmFields" parent="~/.framework/functions/cil-doc.ts"]
1269
+ // CIL[DOC-MACRO purpose="Implements the has meaningful llm fields behavior for CIL documentation processing."]
1270
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the has meaningful llm fields responsibility within the documentation workflow."]
1271
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
1272
+ // CIL[DOC-CONTRACT inputs="fields: Record<string, string>" outputs="boolean" errors="none" side_effects="none"]
1273
+ // CIL[DOC-MICRO logic_summary="Computes the has meaningful llm fields result from the provided input parameters." notable_decisions="none"]
1274
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
1139
1275
  // CIL[DOC-STABILITY stability="stable"]
1140
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1141
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1142
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1143
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
1144
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1145
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1146
1276
  function hasMeaningfulLlmFields(fields: Record<string, string>): boolean {
1147
1277
  const meaningfulKeys = ['description', 'macro', 'micro', 'input_spec', 'output_spec']
1148
1278
  return meaningfulKeys.some(k => (fields[k] || '').trim() !== '')
1149
1279
  }
1280
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the has meaningful llm fields behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1281
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1282
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1283
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1284
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1285
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1286
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:hasMeaningfulLlmFields:function"]
1150
1287
 
1151
1288
 
1152
1289
 
@@ -1154,21 +1291,14 @@ function hasMeaningfulLlmFields(fields: Record<string, string>): boolean {
1154
1291
 
1155
1292
 
1156
1293
 
1157
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_hasmeaningfulllmfields_1784235266"]
1158
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_normalizedocfields_1784235266" type="function" identity="normalizedocfields" parent="none"]
1159
- // CIL[DOC-MACRO purpose="Implements normalizedocfields logic in cortex.functions.custom_cil-doc"]
1160
- // CIL[DOC-RESPONSIBILITY responsibility="Execute normalizedocfields and return its computed result"]
1161
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
1162
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
1163
- // CIL[DOC-MICRO logic_summary="Provides normalizedocfields with normalizeDocFields(fields: Record<string, string>, chunk: any inputs, handling internal flow and returning a result" notable_decisions="[]"]
1164
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1294
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:normalizeDocFields:function" type="function" identity="normalizeDocFields" parent="~/.framework/functions/cil-doc.ts"]
1295
+ // CIL[DOC-MACRO purpose="Implements the normalize doc fields behavior for CIL documentation processing."]
1296
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the normalize doc fields responsibility within the documentation workflow."]
1297
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
1298
+ // CIL[DOC-CONTRACT inputs="fields: Record<string, string>, chunk: any" outputs="Record<string," errors="none" side_effects="none"]
1299
+ // CIL[DOC-MICRO logic_summary="Computes the normalize doc fields result from the provided input parameters." notable_decisions="none"]
1300
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
1165
1301
  // CIL[DOC-STABILITY stability="stable"]
1166
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1167
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1168
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1169
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
1170
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1171
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1172
1302
  function normalizeDocFields(fields: Record<string, string>, chunk: any): Record<string, string> {
1173
1303
  const d = chunk.data || {}
1174
1304
  const isModuleHeader = d.chunk_type === 'module_header'
@@ -1194,13 +1324,14 @@ function normalizeDocFields(fields: Record<string, string>, chunk: any): Record<
1194
1324
 
1195
1325
 
1196
1326
 
1197
- const macroFromLlm = fields.macro
1198
- const microFromLlm = fields.micro
1199
- if (macroFromLlm === undefined || macroFromLlm === null) {
1327
+ const macroFromLlm = (fields.macro || '').trim()
1328
+ const microFromLlm = (fields.micro || '').trim()
1329
+ if (!macroFromLlm) {
1200
1330
  normalized.macro = normalized.description.split(/(?<=[.!?])\s+/)[0] || normalized.description
1201
1331
  }
1202
- if (microFromLlm === undefined || microFromLlm === null) {
1203
- normalized.micro = ''
1332
+ if (!microFromLlm) {
1333
+ const rest = normalized.description.split(/(?<=[.!?])\s+/).slice(1).join(' ').trim()
1334
+ normalized.micro = rest || normalized.description
1204
1335
  }
1205
1336
 
1206
1337
 
@@ -1209,11 +1340,7 @@ function normalizeDocFields(fields: Record<string, string>, chunk: any): Record<
1209
1340
  if (isCallable) {
1210
1341
  const sigMatch = code.match(/(?:function|const|let|var)\s+\w+\s*\(([^)]*)\)|(?:async\s+)?function\s*\(([^)]*)\)/)
1211
1342
  const paramStr = sigMatch?.[1] || sigMatch?.[2] || ''
1212
- const params = paramStr.split(',').map(s => s.trim()).filter(Boolean).map(p => {
1213
- const [name, type] = p.split(/[:=]/).map(s => s.trim())
1214
- const optional = p.includes('?')
1215
- return `- ${name.replace(/\?$/, '')}: ${type || 'any'} (${optional ? 'optional' : 'required'})`
1216
- })
1343
+ const params = expandParamEntries(paramStr).map(p => `- ${p.name}: ${p.type} (${p.optional ? 'optional' : 'required'})`)
1217
1344
  normalized.input_spec = params.length ? params.join('\n') : 'none'
1218
1345
  } else {
1219
1346
  normalized.input_spec = 'none'
@@ -1242,26 +1369,26 @@ function normalizeDocFields(fields: Record<string, string>, chunk: any): Record<
1242
1369
 
1243
1370
  return normalized
1244
1371
  }
1372
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the normalize doc fields behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1373
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1374
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1375
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1376
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1377
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1378
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:normalizeDocFields:function"]
1245
1379
 
1246
1380
 
1247
1381
 
1248
1382
 
1249
1383
 
1250
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_normalizedocfields_1784235266"]
1251
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_documentchunk_1784235266" type="function" identity="documentchunk" parent="none"]
1252
- // CIL[DOC-MACRO purpose="Implements documentchunk logic in cortex.functions.custom_cil-doc"]
1253
- // CIL[DOC-RESPONSIBILITY responsibility="Execute documentchunk and return its computed result"]
1254
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
1255
- // CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
1256
- // CIL[DOC-MICRO logic_summary="Provides documentchunk with documentChunk( inputs, handling internal flow and returning a result" notable_decisions="[]"]
1257
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1384
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:documentChunk:function" type="function" identity="documentChunk" parent="~/.framework/functions/cil-doc.ts"]
1385
+ // CIL[DOC-MACRO purpose="Implements the document chunk behavior for CIL documentation processing."]
1386
+ // CIL[DOC-RESPONSIBILITY responsibility="Carries out the document chunk responsibility within the documentation workflow."]
1387
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
1388
+ // CIL[DOC-CONTRACT inputs="ctx: any, chunk: any, model: string, force: boolean, repoPath?: string" outputs="Promise<" errors="none" side_effects="Supabase database queries and updates"]
1389
+ // CIL[DOC-MICRO logic_summary="Computes the document chunk result from the provided input parameters." notable_decisions="Writes generated fields to the database and optionally persists JSDoc back to the source file."]
1390
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
1258
1391
  // CIL[DOC-STABILITY stability="stable"]
1259
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1260
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1261
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1262
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
1263
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1264
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1265
1392
  async function documentChunk(
1266
1393
  ctx: any,
1267
1394
  chunk: any,
@@ -1275,7 +1402,8 @@ async function documentChunk(
1275
1402
 
1276
1403
  const d = chunk.data || {}
1277
1404
  if (!d.code_content && !d.chunk_name) {
1278
- return { success: false, fields_set: [], error: 'No code content to document' }
1405
+ const ref = d.stable_id || d.chunk_name || chunk.id
1406
+ return { success: false, fields_set: [], error: `No code content to document: ${ref}` }
1279
1407
  }
1280
1408
 
1281
1409
  const prompt = buildDocPrompt(chunk)
@@ -1328,26 +1456,26 @@ async function documentChunk(
1328
1456
 
1329
1457
  return { success: true, fields_set: Object.keys(toWrite), updatedChunk }
1330
1458
  }
1459
+ // CIL[DOC-VECTOR type="context" content="purpose='Implements the document chunk behavior for CIL documentation processing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1460
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1461
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1462
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1463
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1464
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1465
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:documentChunk:function"]
1331
1466
 
1332
1467
 
1333
1468
 
1334
1469
 
1335
1470
 
1336
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_documentchunk_1784235266"]
1337
- // CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_doc_handler_1784235266" type="variable" identity="handler" parent="none"]
1338
- // CIL[DOC-MACRO purpose="Defines handler configuration or state in cortex.functions.custom_cil-doc"]
1339
- // CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for handler"]
1340
- // CIL[DOC-CONTEXT module="cortex.functions.custom_cil-doc" layer="function" related_files="[]"]
1341
- // CIL[DOC-CONTRACT inputs="none" outputs="value of handler" errors="none" side_effects="none"]
1342
- // CIL[DOC-MICRO logic_summary="Declares handler with initial value or constant binding used by cortex.functions.custom_cil-doc" notable_decisions="[]"]
1343
- // CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
1471
+ // CIL[BEGIN stable_id="~/.framework/functions/cil-doc.ts:handler:constant" type="constant" identity="handler" parent="~/.framework/functions/cil-doc.ts"]
1472
+ // CIL[DOC-MACRO purpose="Netlify handler that dispatches documentation-related HTTP actions."]
1473
+ // CIL[DOC-RESPONSIBILITY responsibility="Routes documentation actions to the appropriate sub-handler and returns JSON responses."]
1474
+ // CIL[DOC-CONTEXT module="cil-doc" layer="app-specific" related_files=".framework/functions/_shared/cil.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/admin-data.ts,.framework/functions/cil-doc.ts"]
1475
+ // CIL[DOC-CONTRACT inputs="ctx: any, body: any" outputs="Promise<any>" errors="Throws Error on invalid input or missing resources" side_effects="Supabase database queries and updates; local file system access"]
1476
+ // CIL[DOC-MICRO logic_summary="Uses query.action to route to estimate, gap_report, document, doc_chunk, or validate logic." notable_decisions="Supports estimate, gap_report, document, doc_chunk, and validate actions."]
1477
+ // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
1344
1478
  // CIL[DOC-STABILITY stability="stable"]
1345
- // CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
1346
- // CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
1347
- // CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
1348
- // CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
1349
- // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1350
- // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1351
1479
  export const handler = createHandler(async (ctx, body) => {
1352
1480
  const action = ctx.query?.action
1353
1481
 
@@ -1374,6 +1502,7 @@ export const handler = createHandler(async (ctx, body) => {
1374
1502
  ? Math.round((documented.length / chunks.length) * 100) : 0,
1375
1503
  undocumented: undocumented.slice(0, 100).map(c => ({
1376
1504
  id: c.id,
1505
+ stable_id: c.data?.stable_id || null,
1377
1506
  chunk_name: c.data?.chunk_name || c.title,
1378
1507
  file_path: c.data?.file_path || '',
1379
1508
  chunk_type: c.data?.chunk_type || '',
@@ -1403,6 +1532,7 @@ export const handler = createHandler(async (ctx, body) => {
1403
1532
  const inputTokens = estimateTokens(prompt) + SYSTEM_PROMPT_OVERHEAD_TOKENS
1404
1533
  totalInputTokens += inputTokens
1405
1534
  breakdown.push({
1535
+ stable_id: chunk.data?.stable_id || null,
1406
1536
  chunk_name: chunk.data?.chunk_name || chunk.title,
1407
1537
  file_path: chunk.data?.file_path || '',
1408
1538
  input_tokens: inputTokens,
@@ -1441,18 +1571,10 @@ export const handler = createHandler(async (ctx, body) => {
1441
1571
 
1442
1572
 
1443
1573
  if (action === 'doc_chunk') {
1444
- const chunkId = body?.chunk_id || ctx.query?.chunk_id
1445
1574
  const model = body?.model || ctx.query?.model || DEFAULT_MODEL
1446
1575
  const force = body?.force ?? false
1447
- if (!chunkId) throw new Error('chunk_id is required')
1448
-
1449
- const { data: chunk, error } = await adminDb
1450
- .from('items')
1451
- .select('id, title, data')
1452
- .eq('id', chunkId)
1453
- .maybeSingle()
1454
-
1455
- if (error || !chunk) throw new Error(`Chunk not found: ${chunkId}`)
1576
+ const chunk = await resolveChunk(ctx, body)
1577
+ const chunkId = chunk.id
1456
1578
 
1457
1579
  const projectId = chunk.data?.project_id
1458
1580
  let repoPath = ''
@@ -1462,7 +1584,7 @@ export const handler = createHandler(async (ctx, body) => {
1462
1584
  }
1463
1585
 
1464
1586
  const result = await documentChunk(ctx, chunk, model, force, repoPath)
1465
- return { chunk_id: chunkId, chunk_name: chunk.data?.chunk_name || chunk.title, ...result }
1587
+ return { chunk_id: chunkId, chunk_name: chunk.data?.chunk_name || chunk.title, stable_id: chunk.data?.stable_id || null, ...result }
1466
1588
  }
1467
1589
 
1468
1590
 
@@ -1480,6 +1602,7 @@ export const handler = createHandler(async (ctx, body) => {
1480
1602
  if (errors.length > 0) {
1481
1603
  invalid.push({
1482
1604
  chunk_id: chunk.id,
1605
+ stable_id: chunk.data?.stable_id || null,
1483
1606
  chunk_name: chunk.data?.chunk_name || chunk.title,
1484
1607
  file_path: chunk.data?.file_path || '',
1485
1608
  chunk_type: chunk.data?.chunk_type || '',
@@ -1546,7 +1669,7 @@ export const handler = createHandler(async (ctx, body) => {
1546
1669
  stableList = data || []
1547
1670
  } else if (selectedPaths.length > 0 && !filePath) {
1548
1671
 
1549
- stableList = await loadPendingChunks(projectId, selectedPaths, 'pass2_complete')
1672
+ stableList = await loadPendingChunks(projectId, selectedPaths, '2-chunked')
1550
1673
  } else {
1551
1674
  stableList = await loadAllChunks(projectId, filePath)
1552
1675
  }
@@ -1583,7 +1706,8 @@ export const handler = createHandler(async (ctx, body) => {
1583
1706
  const subResults = await Promise.all(subBatch.map(async chunk => {
1584
1707
  const d = chunk.data || {}
1585
1708
  if (!d.code_content && !d.chunk_name) {
1586
- return { chunk, fields: null, error: 'No code content' }
1709
+ const ref = d.stable_id || d.chunk_name || chunk.id
1710
+ return { chunk, fields: null, error: `No code content: ${ref}` }
1587
1711
  }
1588
1712
  const prompt = buildDocPrompt(chunk)
1589
1713
  try {
@@ -1610,7 +1734,7 @@ export const handler = createHandler(async (ctx, body) => {
1610
1734
 
1611
1735
  await Promise.all(results.map(async ({ chunk, fields, is_fallback, error: llmError }) => {
1612
1736
  if (!fields) {
1613
- if (llmError) { failed++; errors.push(`${chunk.data?.chunk_name || chunk.id}: ${llmError}`) }
1737
+ if (llmError) { failed++; errors.push(`${chunk.data?.stable_id || chunk.data?.chunk_name || chunk.id}: ${llmError}`) }
1614
1738
  else skipped++
1615
1739
  return
1616
1740
  }
@@ -1629,7 +1753,7 @@ export const handler = createHandler(async (ctx, body) => {
1629
1753
  const chunkUpdateCtx = { ...ctx, query: { ...ctx.query, entity: 'items', id: chunk.id } }
1630
1754
  if (validationErrors.length > 0) {
1631
1755
  failed++
1632
- errors.push(`${chunk.data?.chunk_name || chunk.id}: ${validationErrors.join(', ')}`)
1756
+ errors.push(`${chunk.data?.stable_id || chunk.data?.chunk_name || chunk.id}: ${validationErrors.join(', ')}`)
1633
1757
  await adminUpdate(chunkUpdateCtx, { data: { ...updatedData, doc_validation_errors: validationErrors } })
1634
1758
  .catch(() => { /* non-fatal — don't mask original validation error */ })
1635
1759
  return
@@ -1638,7 +1762,7 @@ export const handler = createHandler(async (ctx, body) => {
1638
1762
  try {
1639
1763
  await adminUpdate(chunkUpdateCtx, { data: updatedData })
1640
1764
  } catch (updateError: any) {
1641
- failed++; errors.push(`${chunk.data?.chunk_name || chunk.id}: ${updateError.message}`)
1765
+ failed++; errors.push(`${chunk.data?.stable_id || chunk.data?.chunk_name || chunk.id}: ${updateError.message}`)
1642
1766
  return
1643
1767
  }
1644
1768
  {
@@ -1677,14 +1801,14 @@ export const handler = createHandler(async (ctx, body) => {
1677
1801
  .sort((a, b) => b.markerIdx - a.markerIdx)
1678
1802
  const missed = chunks
1679
1803
  .filter(c => markerMap.get((c.data?.chunk_name || c.title).trim().toLowerCase()) === undefined)
1680
- .map(c => c.data?.chunk_name || c.title)
1804
+ .map(c => c.data?.stable_id || c.data?.chunk_name || c.title)
1681
1805
  if (missed.length > 0) {
1682
1806
  errors.push(`Write-back: could not find markers for ${missed.join(', ')} in ${relPath}`)
1683
1807
  }
1684
1808
  for (const { chunk, markerIdx } of sorted) {
1685
1809
  const jsDoc = buildJsDoc(chunk)
1686
1810
  if (!jsDoc) {
1687
- errors.push(`Write-back: no JSDoc built for ${chunk.data?.chunk_name || chunk.title}`)
1811
+ errors.push(`Write-back: no JSDoc built for ${chunk.data?.stable_id || chunk.data?.chunk_name || chunk.title}`)
1688
1812
  continue
1689
1813
  }
1690
1814
  const existing = findExistingCilJsDoc(newLines, markerIdx)
@@ -1745,8 +1869,13 @@ export const handler = createHandler(async (ctx, body) => {
1745
1869
 
1746
1870
  throw new Error(`Unknown action: ${action}. Valid: estimate, gap_report, document, doc_chunk, validate`)
1747
1871
  })
1872
+ // CIL[DOC-VECTOR type="context" content="purpose='Netlify handler that dispatches documentation-related HTTP actions.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/admin-data.ts"]
1873
+ // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
1874
+ // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
1875
+ // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1876
+ // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1877
+ // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1878
+ // CIL[END stable_id="~/.framework/functions/cil-doc.ts:handler:constant"]
1748
1879
 
1749
1880
 
1750
1881
 
1751
-
1752
- // CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_doc_handler_1784235266"]