spine-framework 0.3.145 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +76 -0
- package/.framework/.spine-manifest.json +19 -0
- package/.framework/cli/commands/agents.ts +61 -33
- package/.framework/cli/commands/auth.ts +60 -28
- package/.framework/cli/commands/create-app.ts +212 -80
- package/.framework/cli/commands/dev.ts +184 -68
- package/.framework/cli/commands/doctor.ts +324 -152
- package/.framework/cli/commands/generate.ts +119 -68
- package/.framework/cli/commands/init.ts +141 -242
- package/.framework/cli/commands/install-app.ts +1336 -314
- package/.framework/cli/commands/items.ts +31 -29
- package/.framework/cli/commands/migrate.ts +299 -156
- package/.framework/cli/commands/migrations.ts +62 -30
- package/.framework/cli/commands/pipelines.ts +31 -29
- package/.framework/cli/commands/status.ts +105 -45
- package/.framework/cli/commands/system.ts +47 -42
- package/.framework/cli/commands/test.ts +161 -102
- package/.framework/cli/commands/upgrade.ts +260 -0
- package/.framework/cli/commands/validate-app.ts +517 -161
- package/.framework/cli/context.ts +117 -85
- package/.framework/cli/env-loader.ts +74 -43
- package/.framework/cli/index.ts +70 -46
- package/.framework/cli/lib/project-files.ts +404 -0
- package/.framework/docs/guides/testing-guide.md +1 -1
- package/.framework/docs/runtime-types.md +72 -72
- package/.framework/functions/_shared/access.ts +84 -0
- package/.framework/functions/_shared/agent-runner.ts +5051 -1026
- package/.framework/functions/_shared/app-manifest.ts +214 -94
- package/.framework/functions/_shared/ast.ts +214 -0
- package/.framework/functions/_shared/audit.ts +91 -55
- package/.framework/functions/_shared/cil.ts +368 -127
- package/.framework/functions/_shared/db.ts +337 -68
- package/.framework/functions/_shared/funnel.ts +228 -0
- package/.framework/functions/_shared/geo.ts +105 -0
- package/.framework/functions/_shared/hash-api-key.ts +94 -17
- package/.framework/functions/_shared/index.ts +22 -224
- package/.framework/functions/_shared/kb.ts +832 -58
- package/.framework/functions/_shared/llm.ts +118 -18
- package/.framework/functions/_shared/logging.ts +317 -19
- package/.framework/functions/_shared/middleware.ts +701 -131
- package/.framework/functions/_shared/notify.ts +70 -0
- package/.framework/functions/_shared/outcomes.ts +34 -19
- package/.framework/functions/_shared/permissions.ts +501 -315
- package/.framework/functions/_shared/pipeline-runner.ts +704 -155
- package/.framework/functions/_shared/principal.ts +436 -263
- package/.framework/functions/_shared/rate-limit.ts +233 -0
- package/.framework/functions/_shared/resolve-credentials.ts +86 -19
- package/.framework/functions/_shared/resolve-ids.ts +203 -139
- package/.framework/functions/_shared/retry-deliveries.ts +51 -16
- package/.framework/functions/_shared/schema-utils.ts +602 -521
- package/.framework/functions/_shared/security.ts +345 -0
- package/.framework/functions/_shared/testing.ts +197 -172
- package/.framework/functions/_shared/tracing.ts +351 -21
- package/.framework/functions/_shared/trigger-engine.ts +425 -136
- package/.framework/functions/_shared/webhook-registration.ts +71 -70
- package/.framework/functions/_shared/webhook-registry.ts +126 -83
- package/.framework/functions/account-nodes.ts +30 -30
- package/.framework/functions/adapters/generic-webhook-inbound.ts +49 -16
- package/.framework/functions/adapters/generic-webhook-outbound.ts +17 -17
- package/.framework/functions/adapters/openai-outbound.ts +15 -16
- package/.framework/functions/admin-data.ts +596 -173
- package/.framework/functions/admin-funnel.ts +64 -60
- package/.framework/functions/admin-install-funnel.ts +84 -66
- package/.framework/functions/admin-signals.ts +69 -51
- package/.framework/functions/ai-agents.ts +431 -106
- package/.framework/functions/ai-interactions.ts +186 -112
- package/.framework/functions/api-keys.ts +107 -107
- package/.framework/functions/apps.ts +154 -136
- package/.framework/functions/auth.ts +83 -65
- package/.framework/functions/cil-agent-ingest.ts +189 -232
- package/.framework/functions/cil-agent.ts +433 -177
- package/.framework/functions/cil-callmap.ts +642 -430
- package/.framework/functions/cil-config.ts +139 -135
- package/.framework/functions/cil-context.ts +214 -127
- package/.framework/functions/cil-doc.ts +587 -458
- package/.framework/functions/cil-embeddings.ts +453 -364
- package/.framework/functions/cil-graph.ts +427 -142
- package/.framework/functions/cil-ingest.ts +1418 -1154
- package/.framework/functions/cil-pipeline.ts +276 -21
- package/.framework/functions/cil-project.ts +659 -132
- package/.framework/functions/cil-validate.ts +198 -164
- package/.framework/functions/debug-auth.ts +57 -55
- package/.framework/functions/deliveries.ts +80 -21
- package/.framework/functions/embeddings.ts +1023 -318
- package/.framework/functions/eval-harness.ts +146 -108
- package/.framework/functions/integration-outbound.ts +205 -75
- package/.framework/functions/integration-routes.ts +128 -23
- package/.framework/functions/integrations.ts +125 -100
- package/.framework/functions/invites.ts +1095 -460
- package/.framework/functions/item-progress.ts +158 -102
- package/.framework/functions/kb.ts +34 -10
- package/.framework/functions/logs.ts +133 -133
- package/.framework/functions/observability.ts +152 -122
- package/.framework/functions/pipeline-executions.ts +147 -132
- package/.framework/functions/pipelines.ts +134 -119
- package/.framework/functions/prompt-configs.ts +96 -80
- package/.framework/functions/roles.ts +112 -82
- package/.framework/functions/security.ts +450 -0
- package/.framework/functions/system-cron.ts +117 -80
- package/.framework/functions/system.ts +158 -98
- package/.framework/functions/tests.ts +29 -29
- package/.framework/functions/timers.ts +94 -95
- package/.framework/functions/trigger-scheduler.ts +10 -0
- package/.framework/functions/triggers.ts +179 -149
- package/.framework/functions/types.ts +137 -125
- package/.framework/mcp/index.ts +133 -0
- package/.framework/mcp/load-env.ts +60 -0
- package/.framework/mcp/shared/app-manifest.ts +275 -0
- package/.framework/mcp/shared/db.ts +477 -0
- package/.framework/mcp/shared/kb.ts +118 -0
- package/.framework/mcp/tools/architect.ts +431 -0
- package/.framework/mcp/tools/cil/context.ts +345 -0
- package/.framework/mcp/tools/cil/graph.ts +242 -0
- package/.framework/mcp/tools/cil/ingest.ts +1217 -0
- package/.framework/mcp/tools/cil/pipeline-orchestrator.ts +693 -0
- package/.framework/mcp/tools/cil/pipeline.ts +767 -0
- package/.framework/mcp/tools/cil/project.ts +791 -0
- package/.framework/mcp/tools/cil/retrieval.ts +336 -0
- package/.framework/mcp/tools/cil/search-core.ts +454 -0
- package/.framework/mcp/tools/cil/search.ts +97 -0
- package/.framework/mcp/tools/cil/suggest.ts +186 -0
- package/.framework/mcp/tools/cil/validate.ts +1369 -0
- package/.framework/mcp/tools/kb/delete.ts +139 -0
- package/.framework/mcp/tools/kb/index.ts +52 -0
- package/.framework/mcp/tools/kb/ingest.ts +84 -0
- package/.framework/mcp/tools/kb/list-types.ts +102 -0
- package/.framework/mcp/tools/kb/publish.ts +100 -0
- package/.framework/mcp/tools/kb/reindex.ts +86 -0
- package/.framework/mcp/tools/kb/revoke.ts +85 -0
- package/.framework/mcp/tools/kb/search.ts +101 -0
- package/.framework/mcp/tools/kb/upsert.ts +125 -0
- package/.framework/mcp/tools/observability.ts +510 -0
- package/.framework/migrations/001_core_schema.sql +15 -0
- package/.framework/migrations/002_core_rls_and_functions.sql +15 -0
- package/.framework/migrations/003_core_system_data.sql +16 -1
- package/.framework/migrations/004_core_rpc_and_broker.sql +17 -1
- package/.framework/migrations/005_core_observability.sql +17 -1
- package/.framework/migrations/006_security_hardening_rls.sql +15 -0
- package/.framework/migrations/007_kb_article_list.sql +17 -1
- package/.framework/migrations/008_items_target.sql +15 -0
- package/.framework/migrations/009_roles_slug_unique.sql +15 -0
- package/.framework/migrations/010_auth_user_trigger.sql +15 -0
- package/.framework/migrations/011_spine_system_account.sql +16 -0
- package/.framework/migrations/012_service_role_grants.sql +16 -0
- package/.framework/migrations/013_get_account_apps_role_filter.sql +15 -0
- package/.framework/migrations/014_apps_required_roles.sql +16 -0
- package/.framework/migrations/015_types_kind_slug_unique.sql +15 -0
- package/.framework/migrations/016_cil_types.sql +281 -0
- package/.framework/migrations/017_cil_stable_ids.sql +37 -0
- package/.framework/migrations/018_runtime_tables.sql +129 -0
- package/.framework/migrations/019_agent_prompt_columns.sql +56 -0
- package/.framework/migrations/020_schema_reconciliation.sql +67 -0
- package/.framework/migrations/021_kb_embedding_lifecycle.sql +31 -0
- package/.framework/migrations/032_cil_status_migration.sql +73 -0
- package/.framework/migrations/033_cil_versioning.sql +73 -0
- package/.framework/migrations/034_match_embeddings_knn.sql +115 -0
- package/.framework/migrations/035_rate_limits.sql +55 -0
- package/.framework/migrations/036_demo_record_flags.sql +72 -0
- package/.framework/migrations/037_kb_types_canonical.sql +244 -0
- package/.framework/migrations/038_drop_demo_record_flags.sql +38 -0
- package/.framework/migrations/042_registration_hierarchy.sql +309 -0
- package/.framework/migrations/043_policy_actor_cleanup.sql +39 -0
- package/.framework/migrations/044_match_embeddings_filtered_knn.sql +151 -0
- package/.framework/migrations/045_security_critical_rls.sql +139 -0
- package/.framework/migrations/046_security_missing_rls.sql +79 -0
- package/.framework/migrations/047_people_updated_by.sql +27 -0
- package/.framework/migrations/048_watcher_last_seen_at.sql +24 -0
- package/.framework/migrations/049_security_blocklist.sql +148 -0
- package/.framework/migrations/050_notifications.sql +49 -0
- package/.framework/migrations/051_message_agent_fields.sql +74 -0
- package/.framework/migrations/052_registration_security.sql +421 -0
- package/.framework/migrations/053_builtin_action_seeds.sql +66 -0
- package/.framework/migrations/054_kb_ingest_lease.sql +157 -0
- package/.framework/migrations/055_type_id_drift_reconciliation.sql +33 -0
- package/.framework/migrations/056_slug_column_reconciliation.sql +38 -0
- package/.framework/migrations/057_pipelines_slug_identity.sql +14 -0
- package/.framework/migrations/058_account_data_field_declarations.sql +53 -0
- package/.framework/migrations/059_registration_placement_fixes.sql +269 -0
- package/.framework/migrations/060_account_person_record_permissions.sql +38 -0
- package/.framework/migrations/061_fk_dedup.sql +32 -0
- package/.framework/public/spine-logo.svg +10 -3
- package/.framework/scripts/app-install-cli.ts +190 -93
- package/.framework/scripts/assemble-frontend.sh +127 -44
- package/.framework/scripts/assemble-functions.sh +128 -30
- package/.framework/scripts/boundary-check.sh +6 -2
- package/.framework/scripts/build-manifest.sh +24 -68
- package/.framework/scripts/check-core-integrity.sh +15 -76
- package/.framework/scripts/checksum-manifest.mts +343 -0
- package/.framework/scripts/cil-migrate-markers.ts +403 -0
- package/.framework/scripts/fix-cil-markers.mjs +176 -0
- package/.framework/scripts/verify-integrity.sh +21 -57
- package/.framework/scripts/verify-manifest.mts +305 -0
- package/.framework/seeds/types/funnel_signal_use.json +74 -21
- package/.framework/seeds/types/spine_instance.json +73 -21
- package/.framework/src/App.tsx +118 -72
- package/.framework/src/apps/admin/index.tsx +855 -58
- package/.framework/src/components/AppWrapper.tsx +43 -45
- package/.framework/src/components/CustomAppLoader.tsx +160 -116
- package/.framework/src/components/admin/AdminListPage.tsx +46 -44
- package/.framework/src/components/admin/AdminSidebar.tsx +57 -47
- package/.framework/src/components/admin/AdminStatsCard.tsx +46 -44
- package/.framework/src/components/admin/PageInstructions.tsx +98 -2
- package/.framework/src/components/admin/SortableTableHeader.tsx +44 -45
- package/.framework/src/components/app-shell/GenericAppShell.tsx +64 -65
- package/.framework/src/components/app-shell/GenericDetailPage.tsx +44 -47
- package/.framework/src/components/app-shell/GenericListPage.tsx +45 -49
- package/.framework/src/components/app-sidebar.tsx +42 -45
- package/.framework/src/components/auth/ProtectedRoute.tsx +48 -41
- package/.framework/src/components/auth/TurnstileWidget.tsx +27 -0
- package/.framework/src/components/kb/KBArticleEditor.tsx +231 -22
- package/.framework/src/components/kb/KBArticleList.tsx +251 -10
- package/.framework/src/components/layout/AppShell.tsx +51 -45
- package/.framework/src/components/layout/Header.tsx +42 -43
- package/.framework/src/components/layout/Layout.tsx +46 -46
- package/.framework/src/components/layout/Sidebar.tsx +196 -96
- package/.framework/src/components/runtime/DataDetailHeader.tsx +55 -30
- package/.framework/src/components/runtime/DataDetailPage.tsx +31 -269
- package/.framework/src/components/runtime/DataFilters.tsx +49 -74
- package/.framework/src/components/runtime/DataHeader.tsx +53 -32
- package/.framework/src/components/runtime/DataListPage.tsx +51 -155
- package/.framework/src/components/runtime/DataStats.tsx +66 -44
- package/.framework/src/components/runtime/DataTable.tsx +49 -149
- package/.framework/src/components/runtime/SchemaDetailForm.tsx +45 -75
- package/.framework/src/components/runtime/index.ts +119 -16
- package/.framework/src/components/search-form.tsx +46 -29
- package/.framework/src/components/shared/AgentView.tsx +65 -48
- package/.framework/src/components/shared/FieldRenderer.tsx +144 -50
- package/.framework/src/components/shared/InviteManager.tsx +207 -97
- package/.framework/src/components/shared/MemberList.tsx +97 -0
- package/.framework/src/components/shared/SchemaFields.tsx +107 -86
- package/.framework/src/components/ui/DataTable.tsx +80 -68
- package/.framework/src/components/ui/Form.tsx +157 -146
- package/.framework/src/components/ui/ItemCard.tsx +74 -67
- package/.framework/src/components/ui/ItemListView.tsx +73 -68
- package/.framework/src/components/ui/LoadingSpinner.tsx +43 -48
- package/.framework/src/components/ui/Modal.tsx +78 -68
- package/.framework/src/components/ui/RichTextEditor.tsx +89 -69
- package/.framework/src/components/ui/accordion.tsx +85 -86
- package/.framework/src/components/ui/alert-dialog.tsx +197 -184
- package/.framework/src/components/ui/alert.tsx +105 -94
- package/.framework/src/components/ui/aspect-ratio.tsx +57 -43
- package/.framework/src/components/ui/avatar.tsx +122 -107
- package/.framework/src/components/ui/badge.tsx +60 -55
- package/.framework/src/components/ui/breadcrumb.tsx +127 -128
- package/.framework/src/components/ui/button-group.tsx +86 -72
- package/.framework/src/components/ui/button.tsx +71 -50
- package/.framework/src/components/ui/calendar.tsx +72 -57
- package/.framework/src/components/ui/card.tsx +136 -129
- package/.framework/src/components/ui/carousel.tsx +226 -107
- package/.framework/src/components/ui/chart.tsx +252 -147
- package/.framework/src/components/ui/checkbox.tsx +43 -44
- package/.framework/src/components/ui/collapsible.tsx +86 -71
- package/.framework/src/components/ui/combobox.tsx +282 -249
- package/.framework/src/components/ui/command.tsx +158 -146
- package/.framework/src/components/ui/context-menu.tsx +239 -240
- package/.framework/src/components/ui/dialog.tsx +174 -157
- package/.framework/src/components/ui/direction.tsx +72 -56
- package/.framework/src/components/ui/drawer.tsx +168 -169
- package/.framework/src/components/ui/dropdown-menu.tsx +254 -223
- package/.framework/src/components/ui/empty.tsx +131 -120
- package/.framework/src/components/ui/field.tsx +205 -173
- package/.framework/src/components/ui/hover-card.tsx +71 -72
- package/.framework/src/components/ui/input-group.tsx +148 -133
- package/.framework/src/components/ui/input-otp.tsx +99 -86
- package/.framework/src/components/ui/input.tsx +43 -41
- package/.framework/src/components/ui/item.tsx +207 -185
- package/.framework/src/components/ui/kbd.tsx +57 -56
- package/.framework/src/components/ui/label.tsx +45 -41
- package/.framework/src/components/ui/menubar.tsx +268 -236
- package/.framework/src/components/ui/native-select.tsx +85 -86
- package/.framework/src/components/ui/navigation-menu.tsx +166 -156
- package/.framework/src/components/ui/pagination.tsx +131 -141
- package/.framework/src/components/ui/popover.tsx +125 -128
- package/.framework/src/components/ui/progress.tsx +47 -44
- package/.framework/src/components/ui/radio-group.tsx +60 -55
- package/.framework/src/components/ui/resizable.tsx +85 -72
- package/.framework/src/components/ui/scroll-area.tsx +57 -58
- package/.framework/src/components/ui/select.tsx +182 -169
- package/.framework/src/components/ui/separator.tsx +42 -43
- package/.framework/src/components/ui/sheet.tsx +170 -159
- package/.framework/src/components/ui/sidebar.tsx +395 -398
- package/.framework/src/components/ui/skeleton.tsx +42 -43
- package/.framework/src/components/ui/slider.tsx +61 -44
- package/.framework/src/components/ui/sonner.tsx +44 -44
- package/.framework/src/components/ui/spinner.tsx +47 -42
- package/.framework/src/components/ui/switch.tsx +56 -42
- package/.framework/src/components/ui/table-primitives.tsx +272 -132
- package/.framework/src/components/ui/table.tsx +140 -142
- package/.framework/src/components/ui/tabs.tsx +110 -93
- package/.framework/src/components/ui/textarea.tsx +43 -44
- package/.framework/src/components/ui/toggle-group.tsx +87 -71
- package/.framework/src/components/ui/toggle.tsx +56 -56
- package/.framework/src/components/ui/tooltip.tsx +99 -85
- package/.framework/src/contexts/AppContext.tsx +166 -114
- package/.framework/src/contexts/AuthContext.tsx +232 -137
- package/.framework/src/hooks/use-mobile.ts +43 -44
- package/.framework/src/hooks/useApi.ts +185 -172
- package/.framework/src/hooks/useAppPath.ts +31 -29
- package/.framework/src/hooks/useApps.ts +77 -42
- package/.framework/src/hooks/useEntityList.ts +66 -29
- package/.framework/src/hooks/useEntityRecord.ts +76 -32
- package/.framework/src/hooks/useForm.ts +62 -30
- package/.framework/src/hooks/useListSchema.ts +60 -43
- package/.framework/src/hooks/useSchemaRecord.ts +115 -95
- package/.framework/src/lib/api.ts +258 -134
- package/.framework/src/lib/registration.ts +181 -0
- package/.framework/src/lib/supabase.ts +118 -81
- package/.framework/src/lib/utils.ts +266 -266
- package/.framework/src/main.tsx +43 -44
- package/.framework/src/pages/DashboardPage.tsx +44 -43
- package/.framework/src/pages/NoAppPage.tsx +50 -0
- package/.framework/src/pages/NotFoundPage.tsx +32 -29
- package/.framework/src/pages/SetupPage.tsx +34 -33
- package/.framework/src/pages/admin/AIAgentDetailPage.tsx +69 -58
- package/.framework/src/pages/admin/AIAgentsPage.tsx +43 -40
- package/.framework/src/pages/admin/APIKeyDetailPage.tsx +63 -55
- package/.framework/src/pages/admin/APIKeysPage.tsx +44 -42
- package/.framework/src/pages/admin/AlertsConfigPage.tsx +117 -94
- package/.framework/src/pages/admin/AppDetailPage.tsx +48 -42
- package/.framework/src/pages/admin/AppsPage.tsx +45 -42
- package/.framework/src/pages/admin/DeliveriesPage.tsx +49 -17
- package/.framework/src/pages/admin/DesignedPage.tsx +31 -30
- package/.framework/src/pages/admin/EmbeddingDetailPage.tsx +58 -0
- package/.framework/src/pages/admin/EmbeddingsPage.tsx +49 -0
- package/.framework/src/pages/admin/ExtendedShadcnTestPage.tsx +31 -29
- package/.framework/src/pages/admin/IncrementalShadcnTestPage.tsx +46 -29
- package/.framework/src/pages/admin/IntegratedDashboard.tsx +32 -29
- package/.framework/src/pages/admin/IntegrationDetailPage.tsx +68 -55
- package/.framework/src/pages/admin/IntegrationsPage.tsx +45 -42
- package/.framework/src/pages/admin/InvitesPage.tsx +60 -44
- package/.framework/src/pages/admin/LogsPage.tsx +87 -137
- package/.framework/src/pages/admin/MinimalShadcnTestPage.tsx +31 -29
- package/.framework/src/pages/admin/ObservabilityDashboard.tsx +150 -89
- package/.framework/src/pages/admin/PipelineDetailPage.tsx +77 -104
- package/.framework/src/pages/admin/PipelineExecutionsPage.tsx +44 -43
- package/.framework/src/pages/admin/PipelinesPage.tsx +59 -145
- package/.framework/src/pages/admin/PromptConfigDetailPage.tsx +53 -42
- package/.framework/src/pages/admin/PromptConfigsPage.tsx +47 -117
- package/.framework/src/pages/admin/ProperlyDesignedPage.tsx +31 -44
- package/.framework/src/pages/admin/RoleDetailPage.tsx +49 -92
- package/.framework/src/pages/admin/RolesPage.tsx +47 -164
- package/.framework/src/pages/admin/SecurityPage.tsx +310 -0
- package/.framework/src/pages/admin/SelectTestPage.tsx +30 -32
- package/.framework/src/pages/admin/ShadcnTestPage.tsx +37 -44
- package/.framework/src/pages/admin/SimpleDashboard.tsx +32 -44
- package/.framework/src/pages/admin/TestRunDetailPage.tsx +97 -44
- package/.framework/src/pages/admin/TestingDashboard.tsx +126 -71
- package/.framework/src/pages/admin/TimerDetailPage.tsx +67 -55
- package/.framework/src/pages/admin/TimersPage.tsx +44 -42
- package/.framework/src/pages/admin/TriggerDetailPage.tsx +47 -42
- package/.framework/src/pages/admin/TriggersPage.tsx +58 -57
- package/.framework/src/pages/admin/TypeDetailPage.tsx +91 -55
- package/.framework/src/pages/admin/TypesPage.tsx +45 -42
- package/.framework/src/pages/admin/cil/CILAgentPage.tsx +258 -128
- package/.framework/src/pages/admin/cil/CILChunkDetailPage.tsx +127 -123
- package/.framework/src/pages/admin/cil/CILDashboardPage.tsx +308 -235
- package/.framework/src/pages/admin/cil/CILFileListPage.tsx +159 -110
- package/.framework/src/pages/admin/cil/CILFileSelectPage.tsx +432 -0
- package/.framework/src/pages/admin/cil/CILGraphPage.tsx +200 -178
- package/.framework/src/pages/admin/cil/CILIngestionPage.tsx +286 -239
- package/.framework/src/pages/admin/cil/CILProjectsPage.tsx +211 -90
- package/.framework/src/pages/admin/cil/CILSearchPage.tsx +156 -143
- package/.framework/src/pages/admin/cil/CILSuggestionsPage.tsx +379 -0
- package/.framework/src/pages/admin/cil/CILVersionsPage.tsx +337 -0
- package/.framework/src/pages/admin/cil/FlexiblePipelinePage.tsx +219 -214
- package/.framework/src/pages/admin/kb/KBAdminPage.tsx +64 -0
- package/.framework/src/pages/auth/AuthConfirmPage.tsx +135 -65
- package/.framework/src/pages/auth/ForgotPasswordPage.tsx +39 -31
- package/.framework/src/pages/auth/LoginPage.tsx +38 -32
- package/.framework/src/pages/auth/PendingApprovalPage.tsx +31 -28
- package/.framework/src/pages/auth/RegisterPage.tsx +429 -155
- package/.framework/src/pages/spine-framework/APIPage.tsx +33 -30
- package/.framework/src/pages/spine-framework/CLIPage.tsx +32 -30
- package/.framework/src/types/auth.ts +101 -93
- package/.framework/src/types/types.ts +283 -262
- package/.framework/templates/project.json +87 -0
- package/.framework/templates/spine.config.neutral.json +7 -0
- package/.framework/tests/api/api-surface.test.ts +381 -0
- package/.framework/tests/fixtures/seed.ts +427 -0
- package/.framework/tests/fixtures/teardown.ts +228 -0
- package/.framework/tests/reporter.ts +351 -0
- package/.framework/tests/setup.ts +135 -0
- package/.framework/tests/ui/ui-sweep.ts +278 -0
- package/.framework/tests/unit/admin-data-logger.test.ts +310 -0
- package/.framework/tests/unit/agent-runner.test.ts +2389 -0
- package/.framework/tests/unit/ai-interactions.test.ts +81 -0
- package/.framework/tests/unit/app-manifest.test.ts +359 -0
- package/.framework/tests/unit/assembly-scripts.test.ts +172 -0
- package/.framework/tests/unit/cil-determinism.test.ts +85 -0
- package/.framework/tests/unit/core-isolation.test.ts +153 -0
- package/.framework/tests/unit/funnel-signals.test.ts +135 -0
- package/.framework/tests/unit/install-app.test.ts +1759 -0
- package/.framework/tests/unit/invites-security.test.ts +572 -0
- package/.framework/tests/unit/kb-ingest-lease.test.ts +287 -0
- package/.framework/tests/unit/kb-search.test.ts +119 -0
- package/.framework/tests/unit/migrate.test.ts +509 -0
- package/.framework/tests/unit/notify.test.ts +136 -0
- package/.framework/tests/unit/permissions.test.ts +269 -0
- package/.framework/tests/unit/pipeline-runner.test.ts +755 -0
- package/.framework/tests/unit/principal-cache.test.ts +138 -0
- package/.framework/tests/unit/retrieval-golden.test.ts +520 -0
- package/.framework/tests/unit/runtime-isolation.test.ts +642 -0
- package/.framework/tests/unit/schema-utils.test.ts +225 -0
- package/.framework/tests/unit/trigger-engine.test.ts +513 -0
- package/.framework/tests/unit/validate-app.test.ts +527 -0
- package/README.md +34 -3
- package/bin/spine-framework.cjs +1 -0
- package/config/tailwind.config.cjs +7 -0
- package/config/tsconfig.functions.json +42 -0
- package/config/tsconfig.json +37 -9
- package/config/vite.config.ts +31 -2
- package/netlify.toml +31 -3
- package/package.json +46 -29
- package/scripts/assemble-frontend.sh +127 -44
- package/scripts/assemble-functions.sh +127 -29
- package/scripts/boundary-check.sh +6 -2
- package/scripts/build-manifest.sh +24 -68
- package/scripts/checksum-manifest.mts +345 -0
- package/scripts/dev-clean.sh +86 -0
- package/scripts/dev-netlify.sh +49 -0
- package/scripts/netlify-dev-wrapper.sh +2 -0
- package/scripts/verify-install.ts +358 -0
- package/scripts/verify-integrity.sh +21 -57
- package/scripts/verify-manifest.mts +305 -0
- package/templates/project/gitignore +45 -0
- package/{config → templates/project}/package-lock.json +22335 -9366
- package/vitest.config.ts +46 -0
- package/.framework/public/spine.config.json +0 -91
- package/config/deno.lock +0 -108
- package/config/tsconfig.node.tsbuildinfo +0 -1
- package/config/tsconfig.tsbuildinfo +0 -1
- package/config/vite.config.d.ts +0 -2
- package/custom/.devin/AGENT.md +0 -357
- package/custom/.devin/skills/install-app/SKILL.md +0 -39
- package/custom/.devin/skills/spine-workbench-discovery/SKILL.md +0 -39
- package/custom/.devin/skills/spine-workbench-idea/SKILL.md +0 -36
- package/custom/.devin/skills/spine-workbench-implement/SKILL.md +0 -46
- package/custom/.devin/skills/spine-workbench-initiative/SKILL.md +0 -28
- package/custom/.devin/skills/spine-workbench-plan/SKILL.md +0 -38
- package/custom/.devin/workflows/app-install.yaml +0 -83
- package/custom/README.md +0 -79
- package/docs/README.md +0 -15
- package/scripts/app-install-cli.ts +0 -286
- package/scripts/check-core-integrity.sh +0 -82
- package/scripts/ingest-chunks.cjs +0 -202
- package/scripts/kb-chunk-parser.cjs +0 -312
- package/scripts/kb-chunk-parser.ts +0 -330
- package/scripts/kb-ingest-docs.ts +0 -203
- package/scripts/load-test-app-install.ts +0 -484
- package/scripts/test-login.js +0 -33
- package/spine.config.json +0 -91
|
@@ -1,9 +1,32 @@
|
|
|
1
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:EMBED_SOURCE_STATUS:constant" type="constant" identity="EMBED_SOURCE_STATUS" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
2
|
+
// CIL[DOC-MACRO purpose="Defines the source and target status labels for embedding pipeline passes."]
|
|
3
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Holds the status mapping used to select files for first and second embedding passes."]
|
|
4
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
5
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
6
|
+
// CIL[DOC-MICRO logic_summary="Maps 'first' and 'second' pass keys to prior and target file status strings." notable_decisions="[]"]
|
|
7
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
8
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1
9
|
|
|
2
10
|
const EMBED_SOURCE_STATUS: Record<'first' | 'second', { prior: string; target: string }> = {
|
|
3
|
-
first: { prior: '
|
|
4
|
-
second: { prior: '
|
|
11
|
+
first: { prior: '6-enriched', target: '7-embedded-mapped' },
|
|
12
|
+
second: { prior: '6-enriched', target: '7-embedded-mapped' },
|
|
5
13
|
}
|
|
6
|
-
|
|
14
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Defines the source and target status labels for embedding pipeline passes.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
15
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
16
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
17
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
18
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
19
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
20
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:EMBED_SOURCE_STATUS:constant"]
|
|
21
|
+
|
|
22
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:getEmbedSourceFilePaths:function" type="function" identity="getEmbedSourceFilePaths" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
23
|
+
// CIL[DOC-MACRO purpose="Selects source file paths that are ready for embedding."]
|
|
24
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Filters project file_statuses for entries matching the configured embedding source or target status."]
|
|
25
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
26
|
+
// CIL[DOC-CONTRACT inputs="projectItem: any, secondPass: boolean" outputs="string[]" errors="none" side_effects="none"]
|
|
27
|
+
// CIL[DOC-MICRO logic_summary="Extracts the relevant prior and target statuses from EMBED_SOURCE_STATUS and filters file paths accordingly." notable_decisions="[]"]
|
|
28
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
29
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
7
30
|
function getEmbedSourceFilePaths(projectItem: any, secondPass: boolean): string[] {
|
|
8
31
|
const fileStatuses: Record<string, string> = projectItem?.data?.file_statuses || {}
|
|
9
32
|
const { prior, target } = secondPass ? EMBED_SOURCE_STATUS.second : EMBED_SOURCE_STATUS.first
|
|
@@ -11,12 +34,28 @@ function getEmbedSourceFilePaths(projectItem: any, secondPass: boolean): string[
|
|
|
11
34
|
.filter(([, status]) => status === prior || status === target)
|
|
12
35
|
.map(([filePath]) => filePath)
|
|
13
36
|
}
|
|
14
|
-
|
|
37
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Selects source file paths that are ready for embedding.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
38
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
39
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
40
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
41
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
42
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
43
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:getEmbedSourceFilePaths:function"]
|
|
44
|
+
|
|
45
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:loadSourceChunks:function" type="function" identity="loadSourceChunks" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
46
|
+
// CIL[DOC-MACRO purpose="Loads CIL chunks from a set of source file paths in batches."]
|
|
47
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Queries the database for active cil_chunk items matching the requested file paths and returns a paginated result."]
|
|
48
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
49
|
+
// CIL[DOC-CONTRACT inputs="projectId: string, sourceFilePaths: string[], offset: number, limit: number, projectItem?: any" outputs="{ chunks: any[]; total: number }" errors="none" side_effects="none"]
|
|
50
|
+
// CIL[DOC-MICRO logic_summary="Splits file paths into batches, counts matching chunks, then fetches the requested page by stable id order." notable_decisions="[]"]
|
|
51
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
52
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
15
53
|
async function loadSourceChunks(
|
|
16
54
|
projectId: string,
|
|
17
55
|
sourceFilePaths: string[],
|
|
18
56
|
offset: number,
|
|
19
|
-
limit: number
|
|
57
|
+
limit: number,
|
|
58
|
+
projectItem?: any
|
|
20
59
|
): Promise<{ chunks: any[]; total: number }> {
|
|
21
60
|
if (sourceFilePaths.length === 0) return { chunks: [], total: 0 }
|
|
22
61
|
|
|
@@ -28,23 +67,20 @@ async function loadSourceChunks(
|
|
|
28
67
|
|
|
29
68
|
for (let i = 0; i < sourceFilePaths.length; i += FILE_PATH_IN_BATCH) {
|
|
30
69
|
const batch = sourceFilePaths.slice(i, i + FILE_PATH_IN_BATCH)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.in('data->>file_path' as any, batch)
|
|
46
|
-
.order('id'),
|
|
47
|
-
])
|
|
70
|
+
let countQuery: any = (adminDb.from('items') as any)
|
|
71
|
+
.select('id', { count: 'exact', head: true })
|
|
72
|
+
.filter('data->>kb_type', 'eq', 'cil_chunk')
|
|
73
|
+
.filter('data->>project_id', 'eq', projectId)
|
|
74
|
+
.eq('is_active', true)
|
|
75
|
+
.in('data->>file_path' as any, batch)
|
|
76
|
+
let selectQuery: any = (adminDb.from('items') as any)
|
|
77
|
+
.select('id, data->>file_path')
|
|
78
|
+
.filter('data->>kb_type', 'eq', 'cil_chunk')
|
|
79
|
+
.filter('data->>project_id', 'eq', projectId)
|
|
80
|
+
.eq('is_active', true)
|
|
81
|
+
.in('data->>file_path' as any, batch)
|
|
82
|
+
.order('id')
|
|
83
|
+
const [{ count }, { data, error }] = await Promise.all([countQuery, selectQuery])
|
|
48
84
|
|
|
49
85
|
if (error) throw new Error(`Failed to load source chunk ids: ${error.message}`)
|
|
50
86
|
total += count || 0
|
|
@@ -66,31 +102,39 @@ async function loadSourceChunks(
|
|
|
66
102
|
const ordered = pageIds.map(id => chunkMap.get(id)).filter(Boolean) as any[]
|
|
67
103
|
return { chunks: ordered, total }
|
|
68
104
|
}
|
|
69
|
-
|
|
70
|
-
// CIL[
|
|
71
|
-
// CIL[DOC-
|
|
72
|
-
// CIL[DOC-
|
|
73
|
-
// CIL[DOC-CONTEXT module="cortex.functions.custom_cil-embeddings" layer="function" related_files="[\".framework/migrations/015_simplify_apps_table.sql\",\"custom/apps/cortex/pages/operations/OperationsDashboard.tsx\",\"custom/apps/portal/pages/ContentPage.tsx\",\".framework/src/components/ui/table-primitives.tsx\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\"\\\"]"]
|
|
74
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="module exports and side effects" errors="none" side_effects="none"]
|
|
75
|
-
// CIL[DOC-MICRO logic_summary="Declares module scope, imports dependencies, and exports public surface of cortex.functions.custom_cil-embeddings" notable_decisions="[]"]
|
|
76
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
77
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
78
|
-
// CIL[DOC-AUDIENCE audience="developer"]
|
|
79
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: .framework/migrations/015_simplify_apps_table.sql, custom/apps/cortex/pages/operations/OperationsDashboard.tsx, custom/apps/portal/pages/ContentPage.tsx, .framework/src/components/ui/table-primitives.tsx, .framework/src/pages/admin/TypeDetailPage.tsx, \."]
|
|
80
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
81
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
82
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
105
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Loads CIL chunks from a set of source file paths in batches.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
106
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
107
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
108
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
83
109
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
84
110
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
111
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:loadSourceChunks:function"]
|
|
85
112
|
|
|
86
113
|
|
|
87
114
|
|
|
88
115
|
|
|
116
|
+
|
|
117
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:module_header:module_header" type="module_header" identity="module_header" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
118
|
+
// CIL[DOC-MACRO purpose="Netlify handler for CIL embedding, search, and status operations."]
|
|
119
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Imports dependencies and exposes the module's main embeddings handler and helpers."]
|
|
120
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/embeddings.ts"]
|
|
121
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
122
|
+
// CIL[DOC-MICRO logic_summary="Imports shared middleware, database, embedding utilities, CIL helpers, and registers the handler." notable_decisions="[]"]
|
|
123
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
124
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
125
|
+
// CIL[DOC-AUDIENCE audience="internal"]
|
|
89
126
|
import { createHandler } from './_shared/middleware'
|
|
90
127
|
import { adminDb } from './_shared/db'
|
|
91
128
|
import { generate } from './embeddings'
|
|
92
129
|
import { callOpenAIEmbeddings, callEmbeddingApi } from './_shared/llm'
|
|
93
|
-
import { FileStatus, FileTreeNode, isSelectedPath, getFileStatus, updateTreeNodeStatus, saveProjectTree } from './_shared/cil'
|
|
130
|
+
import { FileStatus, FileTreeNode, isSelectedPath, getFileStatus, updateTreeNodeStatus, saveProjectTree, pipelineRank, computeContentHash, CIL_BOILERPLATE_PHRASES } from './_shared/cil'
|
|
131
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Netlify handler for CIL embedding, search, and status operations.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
132
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
133
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
134
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
135
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
136
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
137
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:module_header:module_header"]
|
|
94
138
|
|
|
95
139
|
|
|
96
140
|
|
|
@@ -98,62 +142,28 @@ import { FileStatus, FileTreeNode, isSelectedPath, getFileStatus, updateTreeNode
|
|
|
98
142
|
|
|
99
143
|
|
|
100
144
|
|
|
101
|
-
// CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_embeddings_module_header_1784235266"]
|
|
102
|
-
// CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_embeddings_status_rank_1784235266" type="variable" identity="status_rank" parent="none"]
|
|
103
|
-
// CIL[DOC-MACRO purpose="Defines status_rank configuration or state in cortex.functions.custom_cil-embeddings"]
|
|
104
|
-
// CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for status_rank"]
|
|
105
|
-
// CIL[DOC-CONTEXT module="cortex.functions.custom_cil-embeddings" layer="function" related_files="[\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\".framework/src/pages/admin/RolesPage.tsx\",\"\\\"]"]
|
|
106
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="value of status_rank" errors="none" side_effects="none"]
|
|
107
|
-
// CIL[DOC-MICRO logic_summary="Declares status_rank with initial value or constant binding used by cortex.functions.custom_cil-embeddings" notable_decisions="[]"]
|
|
108
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
109
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
110
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: .framework/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, .framework/src/pages/admin/IntegrationsPage.tsx, .framework/src/pages/admin/RolesPage.tsx, \."]
|
|
111
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
112
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
113
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
114
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
115
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
116
|
-
const STATUS_RANK: Record<string, number> = {
|
|
117
|
-
'2-discovered': 2,
|
|
118
|
-
'3-selected': 3,
|
|
119
|
-
'4-chunked': 4,
|
|
120
|
-
'5-documented': 5,
|
|
121
|
-
'6-embedded': 6,
|
|
122
|
-
'7-mapped': 7,
|
|
123
|
-
'8-enriched': 8,
|
|
124
|
-
'9-embedded': 9,
|
|
125
|
-
'10-mapped': 10,
|
|
126
|
-
|
|
127
|
-
'pass2_complete': 4,
|
|
128
|
-
'pass3_complete': 5,
|
|
129
|
-
'pass4_complete': 6,
|
|
130
|
-
'pass4b_complete': 7,
|
|
131
|
-
'pass6_complete': 8,
|
|
132
|
-
'pass7_complete': 9,
|
|
133
|
-
'pass8_complete': 10,
|
|
134
|
-
}
|
|
135
145
|
|
|
136
146
|
|
|
137
147
|
|
|
138
148
|
|
|
139
|
-
// CIL[
|
|
140
|
-
// CIL[
|
|
141
|
-
// CIL[DOC-
|
|
142
|
-
// CIL[DOC-
|
|
143
|
-
// CIL[DOC-
|
|
144
|
-
// CIL[DOC-
|
|
145
|
-
// CIL[DOC-
|
|
146
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
149
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:rank:function" type="function" identity="rank" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
150
|
+
// CIL[DOC-MACRO purpose="Returns the numeric pipeline rank for a status string."]
|
|
151
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Wraps the shared pipelineRank helper to provide a default of 0 for undefined statuses."]
|
|
152
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
153
|
+
// CIL[DOC-CONTRACT inputs="status: string | undefined" outputs="number" errors="none" side_effects="none"]
|
|
154
|
+
// CIL[DOC-MICRO logic_summary="Returns pipelineRank(status) when status is defined and 0 otherwise." notable_decisions="[]"]
|
|
155
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
147
156
|
// CIL[DOC-STABILITY stability="stable"]
|
|
148
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 1. Direct calls: 0. Related files: .framework/functions/_shared/principal.ts, .framework/src/pages/admin/TypeDetailPage.tsx, .framework/src/pages/admin/IntegrationsPage.tsx, .framework/migrations/015_simplify_apps_table.sql, \."]
|
|
149
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 1. Total affected: 1."]
|
|
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
157
|
function rank(status: string | undefined): number {
|
|
155
|
-
return status ?
|
|
158
|
+
return status ? pipelineRank(status) : 0
|
|
156
159
|
}
|
|
160
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Returns the numeric pipeline rank for a status string.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
161
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
162
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
163
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
164
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
165
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
166
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:rank:function"]
|
|
157
167
|
|
|
158
168
|
|
|
159
169
|
|
|
@@ -161,42 +171,42 @@ function rank(status: string | undefined): number {
|
|
|
161
171
|
|
|
162
172
|
|
|
163
173
|
|
|
164
|
-
// CIL[
|
|
165
|
-
// CIL[
|
|
166
|
-
// CIL[DOC-
|
|
167
|
-
// CIL[DOC-
|
|
168
|
-
// CIL[DOC-
|
|
169
|
-
// CIL[DOC-
|
|
170
|
-
// CIL[DOC-
|
|
171
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
174
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:EMBEDDING_MODEL:constant" type="constant" identity="EMBEDDING_MODEL" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
175
|
+
// CIL[DOC-MACRO purpose="Defines the default OpenAI embedding model used for vector generation."]
|
|
176
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Holds the model name string passed to embedding API calls."]
|
|
177
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
178
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
179
|
+
// CIL[DOC-MICRO logic_summary="Stores the 'text-embedding-3-small' model identifier as a constant." notable_decisions="[]"]
|
|
180
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
172
181
|
// CIL[DOC-STABILITY stability="stable"]
|
|
173
|
-
|
|
174
|
-
// CIL[DOC-VECTOR type="
|
|
175
|
-
// CIL[DOC-VECTOR type="
|
|
176
|
-
// CIL[DOC-VECTOR type="
|
|
182
|
+
const EMBEDDING_MODEL = 'text-embedding-3-small'
|
|
183
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Defines the default OpenAI embedding model used for vector generation.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
184
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
185
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
186
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
177
187
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
178
188
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
179
|
-
|
|
189
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:EMBEDDING_MODEL:constant"]
|
|
180
190
|
|
|
181
191
|
|
|
182
192
|
|
|
183
193
|
|
|
184
|
-
// CIL[
|
|
185
|
-
// CIL[
|
|
186
|
-
// CIL[DOC-
|
|
187
|
-
// CIL[DOC-
|
|
188
|
-
// CIL[DOC-
|
|
189
|
-
// CIL[DOC-
|
|
190
|
-
// CIL[DOC-
|
|
191
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
194
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:DEFAULT_BATCH_SIZE:constant" type="constant" identity="DEFAULT_BATCH_SIZE" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
195
|
+
// CIL[DOC-MACRO purpose="Defines the default number of embedding rows to insert per batch."]
|
|
196
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Provides a fallback batch size for bulk embedding insert operations."]
|
|
197
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
198
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
199
|
+
// CIL[DOC-MICRO logic_summary="Sets a constant default of 20 items per embedding insert batch." notable_decisions="[]"]
|
|
200
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
192
201
|
// CIL[DOC-STABILITY stability="stable"]
|
|
193
|
-
|
|
194
|
-
// CIL[DOC-VECTOR type="
|
|
195
|
-
// CIL[DOC-VECTOR type="
|
|
196
|
-
// CIL[DOC-VECTOR type="
|
|
202
|
+
const DEFAULT_BATCH_SIZE = 20
|
|
203
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Defines the default number of embedding rows to insert per batch.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
204
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
205
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
206
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
197
207
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
198
208
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
199
|
-
|
|
209
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:DEFAULT_BATCH_SIZE:constant"]
|
|
200
210
|
|
|
201
211
|
|
|
202
212
|
|
|
@@ -205,53 +215,55 @@ const DEFAULT_BATCH_SIZE = 20
|
|
|
205
215
|
|
|
206
216
|
|
|
207
217
|
|
|
208
|
-
// CIL[
|
|
209
|
-
// CIL[
|
|
210
|
-
// CIL[DOC-
|
|
211
|
-
// CIL[DOC-
|
|
212
|
-
// CIL[DOC-
|
|
213
|
-
// CIL[DOC-
|
|
214
|
-
// CIL[DOC-
|
|
215
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
218
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:VECTOR_TYPE_INDEX:constant" type="constant" identity="VECTOR_TYPE_INDEX" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
219
|
+
// CIL[DOC-MACRO purpose="Defines numeric chunk_index values for each embedding vector type."]
|
|
220
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Maps semantic, structure, context, blast_radius, configuration, and constraint vector names to fixed integer indices."]
|
|
221
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
222
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
223
|
+
// CIL[DOC-MICRO logic_summary="Records a static mapping from vector type names to their chunk_index values." notable_decisions="[]"]
|
|
224
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
216
225
|
// CIL[DOC-STABILITY stability="stable"]
|
|
217
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
218
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
219
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
220
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
221
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
222
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
223
226
|
const VECTOR_TYPE_INDEX: Record<string, number> = {
|
|
224
|
-
semantic:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
227
|
+
semantic: 0,
|
|
228
|
+
structure: 1,
|
|
229
|
+
context: 2,
|
|
230
|
+
blast_radius: 3,
|
|
231
|
+
configuration: 4,
|
|
232
|
+
constraint: 5,
|
|
228
233
|
}
|
|
234
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Defines numeric chunk_index values for each embedding vector type.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
235
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
236
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
237
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
238
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
239
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
240
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:VECTOR_TYPE_INDEX:constant"]
|
|
229
241
|
|
|
230
242
|
|
|
231
243
|
|
|
232
244
|
|
|
233
245
|
|
|
234
246
|
|
|
235
|
-
// CIL[
|
|
236
|
-
// CIL[
|
|
237
|
-
// CIL[DOC-
|
|
238
|
-
// CIL[DOC-
|
|
239
|
-
// CIL[DOC-
|
|
240
|
-
// CIL[DOC-
|
|
241
|
-
// CIL[DOC-
|
|
242
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
247
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:EMBEDDING_PRICES:constant" type="constant" identity="EMBEDDING_PRICES" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
248
|
+
// CIL[DOC-MACRO purpose="Defines the per-million-token price for each supported embedding model."]
|
|
249
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Provides cost lookup for the embedding cost estimator."]
|
|
250
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
251
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
252
|
+
// CIL[DOC-MICRO logic_summary="Maps supported model names to their USD price per 1M tokens." notable_decisions="[]"]
|
|
253
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
243
254
|
// CIL[DOC-STABILITY stability="stable"]
|
|
244
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
245
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
246
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
247
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
248
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
249
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
250
255
|
const EMBEDDING_PRICES: Record<string, number> = {
|
|
251
256
|
'text-embedding-3-small': 0.02,
|
|
252
257
|
'text-embedding-3-large': 0.13,
|
|
253
258
|
'text-embedding-ada-002': 0.10,
|
|
254
259
|
}
|
|
260
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Defines the per-million-token price for each supported embedding model.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
261
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
262
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
263
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
264
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
265
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
266
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:EMBEDDING_PRICES:constant"]
|
|
255
267
|
|
|
256
268
|
|
|
257
269
|
|
|
@@ -262,21 +274,14 @@ const EMBEDDING_PRICES: Record<string, number> = {
|
|
|
262
274
|
|
|
263
275
|
|
|
264
276
|
|
|
265
|
-
// CIL[
|
|
266
|
-
// CIL[
|
|
267
|
-
// CIL[DOC-
|
|
268
|
-
// CIL[DOC-
|
|
269
|
-
// CIL[DOC-
|
|
270
|
-
// CIL[DOC-
|
|
271
|
-
// CIL[DOC-
|
|
272
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
277
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:buildSemanticText:function" type="function" identity="buildSemanticText" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
278
|
+
// CIL[DOC-MACRO purpose="Builds the searchable semantic text payload for a CIL chunk."]
|
|
279
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Combines chunk metadata, vector content, macro, micro, inputs, outputs, notes, and learnings into a single string."]
|
|
280
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
281
|
+
// CIL[DOC-CONTRACT inputs="chunk: any" outputs="string" errors="none" side_effects="none"]
|
|
282
|
+
// CIL[DOC-MICRO logic_summary="Assembles available chunk data fields into a dot-separated summary string for embedding." notable_decisions="[]"]
|
|
283
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
273
284
|
// CIL[DOC-STABILITY stability="stable"]
|
|
274
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
275
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
276
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
277
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
278
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
279
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
280
285
|
export function buildSemanticText(chunk: any): string {
|
|
281
286
|
const d = chunk.data || {}
|
|
282
287
|
const parts: string[] = []
|
|
@@ -285,10 +290,12 @@ export function buildSemanticText(chunk: any): string {
|
|
|
285
290
|
if (d.file_path) parts.push(`in ${d.file_path}`)
|
|
286
291
|
|
|
287
292
|
const vc = d.vector_content || {}
|
|
288
|
-
|
|
293
|
+
const hasBoilerplate = (s: string) =>
|
|
294
|
+
CIL_BOILERPLATE_PHRASES.some(p => s.toLowerCase().includes(p.toLowerCase()))
|
|
295
|
+
if (vc.context?.status === 'ready' && vc.context.content && !hasBoilerplate(vc.context.content)) {
|
|
289
296
|
parts.push(`Context: ${vc.context.content}`)
|
|
290
297
|
}
|
|
291
|
-
if (vc.blast_radius?.status === 'ready' && vc.blast_radius.content) {
|
|
298
|
+
if (vc.blast_radius?.status === 'ready' && vc.blast_radius.content && !hasBoilerplate(vc.blast_radius.content)) {
|
|
292
299
|
parts.push(`Blast radius: ${vc.blast_radius.content}`)
|
|
293
300
|
}
|
|
294
301
|
|
|
@@ -308,24 +315,24 @@ export function buildSemanticText(chunk: any): string {
|
|
|
308
315
|
}
|
|
309
316
|
return parts.join('. ')
|
|
310
317
|
}
|
|
318
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Builds the searchable semantic text payload for a CIL chunk.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
319
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
320
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
321
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
322
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
323
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
324
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:buildSemanticText:function"]
|
|
311
325
|
|
|
312
326
|
|
|
313
327
|
|
|
314
|
-
// CIL[
|
|
315
|
-
// CIL[
|
|
316
|
-
// CIL[DOC-
|
|
317
|
-
// CIL[DOC-
|
|
318
|
-
// CIL[DOC-
|
|
319
|
-
// CIL[DOC-
|
|
320
|
-
// CIL[DOC-
|
|
321
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
328
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:buildStructuralText:function" type="function" identity="buildStructuralText" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
329
|
+
// CIL[DOC-MACRO purpose="Builds a structural JSON text payload for a CIL chunk."]
|
|
330
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Serializes key chunk metadata fields into a compact JSON string for structural vector indexing."]
|
|
331
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
332
|
+
// CIL[DOC-CONTRACT inputs="chunk: any" outputs="string" errors="none" side_effects="none"]
|
|
333
|
+
// CIL[DOC-MICRO logic_summary="Converts chunk_name, chunk_type, file_path, stability, is_dead_code, and other flags into JSON." notable_decisions="[]"]
|
|
334
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
322
335
|
// CIL[DOC-STABILITY stability="stable"]
|
|
323
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
324
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
325
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
326
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
327
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
328
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
329
336
|
export function buildStructuralText(chunk: any): string {
|
|
330
337
|
const d = chunk.data || {}
|
|
331
338
|
return JSON.stringify({
|
|
@@ -339,24 +346,24 @@ export function buildStructuralText(chunk: any): string {
|
|
|
339
346
|
review_status: d.review_status || '',
|
|
340
347
|
})
|
|
341
348
|
}
|
|
349
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Builds a structural JSON text payload for a CIL chunk.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
350
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
351
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
352
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
353
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
354
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
355
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:buildStructuralText:function"]
|
|
342
356
|
|
|
343
357
|
|
|
344
358
|
|
|
345
|
-
// CIL[
|
|
346
|
-
// CIL[
|
|
347
|
-
// CIL[DOC-
|
|
348
|
-
// CIL[DOC-
|
|
349
|
-
// CIL[DOC-
|
|
350
|
-
// CIL[DOC-
|
|
351
|
-
// CIL[DOC-
|
|
352
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
359
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:buildContractText:function" type="function" identity="buildContractText" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
360
|
+
// CIL[DOC-MACRO purpose="Builds the contract text payload for a CIL chunk."]
|
|
361
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Assembles input, output, side effect, and purpose descriptions into a contract vector string."]
|
|
362
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
363
|
+
// CIL[DOC-CONTRACT inputs="chunk: any" outputs="string" errors="none" side_effects="none"]
|
|
364
|
+
// CIL[DOC-MICRO logic_summary="Joins input_spec, output_spec, side_effects, and macro fields into a line-separated contract string." notable_decisions="[]"]
|
|
365
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
353
366
|
// CIL[DOC-STABILITY stability="stable"]
|
|
354
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
355
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
356
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
357
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
358
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
359
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
360
367
|
export function buildContractText(chunk: any): string {
|
|
361
368
|
const d = chunk.data || {}
|
|
362
369
|
const parts: string[] = []
|
|
@@ -366,10 +373,25 @@ export function buildContractText(chunk: any): string {
|
|
|
366
373
|
if (d.macro) parts.push(`PURPOSE: ${d.macro}`)
|
|
367
374
|
return parts.join('\n') || `${d.chunk_name || 'unknown'} — no contract yet`
|
|
368
375
|
}
|
|
376
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Builds the contract text payload for a CIL chunk.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
377
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
378
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
379
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
380
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
381
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
382
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:buildContractText:function"]
|
|
369
383
|
|
|
370
384
|
|
|
371
385
|
|
|
372
386
|
|
|
387
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:buildCodeText:function" type="function" identity="buildCodeText" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
388
|
+
// CIL[DOC-MACRO purpose="Builds the code text payload for a CIL chunk."]
|
|
389
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Produces a human-readable code vector string from chunk metadata and stored code content."]
|
|
390
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
391
|
+
// CIL[DOC-CONTRACT inputs="chunk: any" outputs="string" errors="none" side_effects="none"]
|
|
392
|
+
// CIL[DOC-MICRO logic_summary="Joins chunk name, file path, chunk type, macro, micro, and raw code content into a text block." notable_decisions="[]"]
|
|
393
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
394
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
373
395
|
function buildCodeText(chunk: any): string {
|
|
374
396
|
const d = chunk.data || {}
|
|
375
397
|
const parts: string[] = []
|
|
@@ -384,28 +406,61 @@ function buildCodeText(chunk: any): string {
|
|
|
384
406
|
}
|
|
385
407
|
return parts.join('\n') || `${d.chunk_name || 'unknown'} — no code content`
|
|
386
408
|
}
|
|
409
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Builds the code text payload for a CIL chunk.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.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-embeddings.ts:buildCodeText:function"]
|
|
387
416
|
|
|
388
417
|
|
|
389
418
|
|
|
419
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:buildConstraintText:function" type="function" identity="buildConstraintText" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
420
|
+
// CIL[DOC-MACRO purpose="Builds the constraint text payload for a CIL chunk."]
|
|
421
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Combines constraint vector content with contract and purpose details for vector indexing."]
|
|
422
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
423
|
+
// CIL[DOC-CONTRACT inputs="chunk: any" outputs="string" errors="none" side_effects="none"]
|
|
424
|
+
// CIL[DOC-MICRO logic_summary="Adds constraint vector content when ready and falls back to input/output specs and macro." notable_decisions="[]"]
|
|
425
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
426
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
427
|
+
export function buildConstraintText(chunk: any): string {
|
|
428
|
+
const d = chunk.data || {}
|
|
429
|
+
const vc = d.vector_content || {}
|
|
430
|
+
const parts: string[] = []
|
|
431
|
+
if (vc.constraint?.status === 'ready' && vc.constraint.content) {
|
|
432
|
+
parts.push(vc.constraint.content)
|
|
433
|
+
}
|
|
434
|
+
if (d.input_spec) parts.push(`INPUTS: ${d.input_spec}`)
|
|
435
|
+
if (d.output_spec) parts.push(`OUTPUTS: ${d.output_spec}`)
|
|
436
|
+
if (d.side_effects) parts.push(`SIDE_EFFECTS: ${d.side_effects}`)
|
|
437
|
+
if (d.macro) parts.push(`PURPOSE: ${d.macro}`)
|
|
438
|
+
return parts.join('\n') || `${d.chunk_name || 'unknown'} — no constraint yet`
|
|
439
|
+
}
|
|
440
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Builds the constraint text payload for a CIL chunk.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
441
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
442
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
443
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
444
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
445
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
446
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:buildConstraintText:function"]
|
|
447
|
+
|
|
448
|
+
|
|
390
449
|
|
|
391
450
|
|
|
392
451
|
|
|
393
|
-
|
|
394
|
-
// CIL[BEGIN
|
|
395
|
-
// CIL[DOC-MACRO purpose="
|
|
396
|
-
// CIL[DOC-RESPONSIBILITY responsibility="
|
|
397
|
-
// CIL[DOC-CONTEXT module="
|
|
398
|
-
// CIL[DOC-CONTRACT inputs="
|
|
399
|
-
// CIL[DOC-MICRO logic_summary="
|
|
400
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.
|
|
452
|
+
|
|
453
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:loadPendingChunks:function" type="function" identity="loadPendingChunks" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
454
|
+
// CIL[DOC-MACRO purpose="Loads approved CIL chunks for selected files that need embedding."]
|
|
455
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Queries active cil_file and cil_chunk items to find chunks matching the required status and selection."]
|
|
456
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
457
|
+
// CIL[DOC-CONTRACT inputs="projectId: string, selectedPaths: string[], requiredStatus: FileStatus, projectItem?: any" outputs="any[]" errors="none" side_effects="none"]
|
|
458
|
+
// CIL[DOC-MICRO logic_summary="Selects file ids with the required status, then filters active chunks by file_id." notable_decisions="[]"]
|
|
459
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
401
460
|
// CIL[DOC-STABILITY stability="stable"]
|
|
402
|
-
|
|
403
|
-
//
|
|
404
|
-
//
|
|
405
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
406
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
407
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
408
|
-
async function loadPendingChunks(projectId: string, selectedPaths: string[], requiredStatus: FileStatus): Promise<any[]> {
|
|
461
|
+
async function loadPendingChunks(projectId: string, selectedPaths: string[], requiredStatus: FileStatus, projectItem?: any): Promise<any[]> {
|
|
462
|
+
// The live project is scoped by project_id and is_active. The active_version_id is a
|
|
463
|
+
// pointer to the cil_version manifest, not a runtime filter.
|
|
409
464
|
const { data: fileItems } = await adminDb
|
|
410
465
|
.from('items')
|
|
411
466
|
.select('id, data')
|
|
@@ -428,26 +483,26 @@ async function loadPendingChunks(projectId: string, selectedPaths: string[], req
|
|
|
428
483
|
|
|
429
484
|
return (allChunks || []).filter((c: any) => selectedFileIds.includes(c.data?.file_id))
|
|
430
485
|
}
|
|
486
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Loads approved CIL chunks for selected files that need embedding.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
487
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
488
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
489
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
490
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
491
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
492
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:loadPendingChunks:function"]
|
|
431
493
|
|
|
432
494
|
|
|
433
495
|
|
|
434
496
|
|
|
435
497
|
|
|
436
|
-
// CIL[
|
|
437
|
-
// CIL[
|
|
438
|
-
// CIL[DOC-
|
|
439
|
-
// CIL[DOC-
|
|
440
|
-
// CIL[DOC-
|
|
441
|
-
// CIL[DOC-
|
|
442
|
-
// CIL[DOC-
|
|
443
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
498
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:maybeAdvanceFileToPass4:function" type="function" identity="maybeAdvanceFileToPass4" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
499
|
+
// CIL[DOC-MACRO purpose="Advances a file's pipeline status once all its chunks are embedded."]
|
|
500
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Checks embedding coverage for a file's stable ids, then updates file and project statuses if complete."]
|
|
501
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
502
|
+
// CIL[DOC-CONTRACT inputs="ctx: any, fileId: string, tree: FileTreeNode | null, secondPass: boolean, projectItem?: any" outputs="void" errors="none" side_effects="none"]
|
|
503
|
+
// CIL[DOC-MICRO logic_summary="Verifies all stable ids have active embeddings, then updates the cil_file status and file_tree when coverage is complete." notable_decisions="[]"]
|
|
504
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
444
505
|
// CIL[DOC-STABILITY stability="stable"]
|
|
445
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
446
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
447
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
448
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
449
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
450
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
451
506
|
async function maybeAdvanceFileToPass4(
|
|
452
507
|
ctx: any,
|
|
453
508
|
fileId: string,
|
|
@@ -464,15 +519,15 @@ async function maybeAdvanceFileToPass4(
|
|
|
464
519
|
|
|
465
520
|
if (!fileChunks || fileChunks.length === 0) return
|
|
466
521
|
|
|
467
|
-
const
|
|
522
|
+
const stableIds = fileChunks.map((c: any) => c.data?.stable_id).filter(Boolean)
|
|
468
523
|
const { data: embeddedDocs } = await adminDb
|
|
469
524
|
.from('embeddings')
|
|
470
525
|
.select('document_id')
|
|
471
|
-
.in('document_id',
|
|
526
|
+
.in('document_id', stableIds)
|
|
472
527
|
.is('revoked_at', null)
|
|
473
528
|
|
|
474
529
|
const embeddedChunkIds = new Set((embeddedDocs || []).map((e: any) => e.document_id))
|
|
475
|
-
const allEmbedded =
|
|
530
|
+
const allEmbedded = stableIds.every(id => embeddedChunkIds.has(id))
|
|
476
531
|
if (!allEmbedded) return
|
|
477
532
|
|
|
478
533
|
const { data: fileItem } = await adminDb
|
|
@@ -483,8 +538,8 @@ async function maybeAdvanceFileToPass4(
|
|
|
483
538
|
|
|
484
539
|
if (!fileItem) return
|
|
485
540
|
|
|
486
|
-
const cil_file_status = secondPass ? '
|
|
487
|
-
const pipeline_status = secondPass ? '
|
|
541
|
+
const cil_file_status = secondPass ? '7-embedded-mapped' : '7-embedded-mapped'
|
|
542
|
+
const pipeline_status = secondPass ? '7-embedded-mapped' : '7-embedded-mapped'
|
|
488
543
|
const currentFileStatus = getFileStatus(fileItem)
|
|
489
544
|
const filePath: string = fileItem.data?.file_path
|
|
490
545
|
|
|
@@ -535,27 +590,27 @@ async function maybeAdvanceFileToPass4(
|
|
|
535
590
|
projectItem.data.file_statuses = fileStatuses
|
|
536
591
|
}
|
|
537
592
|
}
|
|
593
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Advances a file's pipeline status once all its chunks are embedded.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
594
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
595
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
596
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
597
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
598
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
599
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:maybeAdvanceFileToPass4:function"]
|
|
538
600
|
|
|
539
601
|
|
|
540
602
|
|
|
541
603
|
|
|
542
604
|
|
|
543
|
-
// CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_embeddings_maybeadvancefiletopass4_1784235266"]
|
|
544
605
|
|
|
545
|
-
// CIL[BEGIN
|
|
546
|
-
// CIL[DOC-MACRO purpose="
|
|
547
|
-
// CIL[DOC-RESPONSIBILITY responsibility="
|
|
548
|
-
// CIL[DOC-CONTEXT module="
|
|
549
|
-
// CIL[DOC-CONTRACT inputs="
|
|
550
|
-
// CIL[DOC-MICRO logic_summary="
|
|
551
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.
|
|
606
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:contentHash:function" type="function" identity="contentHash" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
607
|
+
// CIL[DOC-MACRO purpose="Computes a 32-bit FNV-1a hash for a string."]
|
|
608
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Provides a fast content hash for comparing embedding input texts."]
|
|
609
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
610
|
+
// CIL[DOC-CONTRACT inputs="text: string" outputs="string" errors="none" side_effects="none"]
|
|
611
|
+
// CIL[DOC-MICRO logic_summary="Iterates over characters, mixing each into an FNV-style 32-bit integer and returning a zero-padded hex string." notable_decisions="[]"]
|
|
612
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
552
613
|
// CIL[DOC-STABILITY stability="stable"]
|
|
553
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
554
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
555
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
556
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
557
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
558
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
559
614
|
export function contentHash(text: string): string {
|
|
560
615
|
|
|
561
616
|
let h = 2166136261
|
|
@@ -565,50 +620,60 @@ export function contentHash(text: string): string {
|
|
|
565
620
|
}
|
|
566
621
|
return (h >>> 0).toString(16).padStart(8, '0')
|
|
567
622
|
}
|
|
623
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Computes a 32-bit FNV-1a hash for a string.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
624
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
625
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
626
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
627
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
628
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
629
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:contentHash:function"]
|
|
568
630
|
|
|
569
631
|
|
|
570
632
|
|
|
571
633
|
|
|
572
634
|
|
|
573
|
-
// CIL[
|
|
574
|
-
// CIL[
|
|
575
|
-
// CIL[DOC-
|
|
576
|
-
// CIL[DOC-
|
|
577
|
-
// CIL[DOC-
|
|
578
|
-
// CIL[DOC-
|
|
579
|
-
// CIL[DOC-
|
|
580
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
635
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:embedChunk:function" type="function" identity="embedChunk" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
636
|
+
// CIL[DOC-MACRO purpose="Generates or updates OpenAI embeddings for a single CIL chunk."]
|
|
637
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Builds vector texts, hashes them, calls the embedding API, and upserts rows in the embeddings table."]
|
|
638
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
639
|
+
// CIL[DOC-CONTRACT inputs="chunkItem: any, accountId: string, forceRegenerate: boolean" outputs="{ created: string[]; skipped: string[]; error?: string }" errors="Embedding API failures" side_effects="Inserts or updates rows in the embeddings table"]
|
|
640
|
+
// CIL[DOC-MICRO logic_summary="Skips unchanged vectors, calls the embedding API for new or changed texts, and writes the resulting vector rows." notable_decisions="[]"]
|
|
641
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
581
642
|
// 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"]
|
|
588
643
|
export async function embedChunk(
|
|
589
644
|
chunkItem: any,
|
|
590
645
|
accountId: string,
|
|
591
646
|
forceRegenerate: boolean
|
|
592
647
|
): Promise<{ created: string[]; skipped: string[]; error?: string }> {
|
|
593
648
|
const chunkId = chunkItem.id
|
|
649
|
+
const stableId = chunkItem.data?.stable_id || chunkId
|
|
594
650
|
const created: string[] = []
|
|
595
651
|
const skipped: string[] = []
|
|
596
652
|
|
|
597
653
|
|
|
654
|
+
const d = chunkItem.data || {}
|
|
655
|
+
const vc = d.vector_content || {}
|
|
656
|
+
const vectorReadyText = (t: string) => (vc[t]?.status === 'ready' && vc[t]?.content ? vc[t].content : '')
|
|
598
657
|
const vectors: { type: string; text: string }[] = [
|
|
599
|
-
{ type: 'semantic',
|
|
600
|
-
{ type: '
|
|
601
|
-
{ type: '
|
|
602
|
-
{ type: '
|
|
658
|
+
{ type: 'semantic', text: buildSemanticText(chunkItem) },
|
|
659
|
+
{ type: 'structure', text: buildStructuralText(chunkItem) },
|
|
660
|
+
{ type: 'context', text: vectorReadyText('context') },
|
|
661
|
+
{ type: 'blast_radius', text: vectorReadyText('blast_radius') },
|
|
662
|
+
{ type: 'configuration', text: vectorReadyText('configuration') },
|
|
663
|
+
{ type: 'constraint', text: buildConstraintText(chunkItem) },
|
|
603
664
|
].filter(v => v.text.trim().length > 0)
|
|
604
665
|
|
|
605
666
|
if (!vectors.length) return { created, skipped: ['all:empty'] }
|
|
606
667
|
|
|
607
668
|
|
|
669
|
+
// Retire legacy chunk-UUID keyed embeddings now that stable_id is the document key
|
|
670
|
+
await adminDb.from('embeddings').delete().eq('document_id', chunkId)
|
|
671
|
+
|
|
672
|
+
|
|
608
673
|
const { data: existing } = await adminDb
|
|
609
674
|
.from('embeddings')
|
|
610
675
|
.select('id, content_hash, metadata')
|
|
611
|
-
.eq('document_id',
|
|
676
|
+
.eq('document_id', stableId)
|
|
612
677
|
|
|
613
678
|
const existingMap = new Map<string, any>()
|
|
614
679
|
for (const row of existing || []) {
|
|
@@ -616,15 +681,15 @@ export async function embedChunk(
|
|
|
616
681
|
}
|
|
617
682
|
|
|
618
683
|
if (forceRegenerate && (existing || []).length > 0) {
|
|
619
|
-
await adminDb.from('embeddings').delete().eq('document_id',
|
|
684
|
+
await adminDb.from('embeddings').delete().eq('document_id', stableId)
|
|
620
685
|
existingMap.clear()
|
|
621
686
|
}
|
|
622
687
|
|
|
623
688
|
|
|
624
689
|
const toEmbed = vectors.filter(v => {
|
|
625
|
-
const
|
|
690
|
+
const inputHash = contentHash(v.text)
|
|
626
691
|
const row = existingMap.get(v.type)
|
|
627
|
-
if (row && row.
|
|
692
|
+
if (row && row.metadata?.input_hash === inputHash) { skipped.push(v.type); return false }
|
|
628
693
|
return true
|
|
629
694
|
})
|
|
630
695
|
|
|
@@ -636,7 +701,8 @@ export async function embedChunk(
|
|
|
636
701
|
|
|
637
702
|
for (let i = 0; i < toEmbed.length; i++) {
|
|
638
703
|
const { type, text } = toEmbed[i]
|
|
639
|
-
const hash =
|
|
704
|
+
const hash = computeContentHash(text)
|
|
705
|
+
const inputHash = contentHash(text)
|
|
640
706
|
const existingRow = existingMap.get(type)
|
|
641
707
|
|
|
642
708
|
|
|
@@ -645,7 +711,7 @@ export async function embedChunk(
|
|
|
645
711
|
const row = {
|
|
646
712
|
account_id: accountId,
|
|
647
713
|
model_id: EMBEDDING_MODEL,
|
|
648
|
-
document_id:
|
|
714
|
+
document_id: stableId,
|
|
649
715
|
chunk_index: VECTOR_TYPE_INDEX[type] ?? 0,
|
|
650
716
|
content: text,
|
|
651
717
|
embedding: vectorLiteral,
|
|
@@ -661,6 +727,8 @@ export async function embedChunk(
|
|
|
661
727
|
chunk_name: chunkItem.data?.chunk_name || '',
|
|
662
728
|
file_path: chunkItem.data?.file_path || '',
|
|
663
729
|
project_id: chunkItem.data?.project_id || '',
|
|
730
|
+
version_id: chunkItem.data?.version_id || '',
|
|
731
|
+
input_hash: inputHash,
|
|
664
732
|
},
|
|
665
733
|
}
|
|
666
734
|
|
|
@@ -677,26 +745,26 @@ export async function embedChunk(
|
|
|
677
745
|
|
|
678
746
|
return { created, skipped }
|
|
679
747
|
}
|
|
748
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Generates or updates OpenAI embeddings for a single CIL chunk.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
749
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
750
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
751
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
752
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
753
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
754
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:embedChunk:function"]
|
|
680
755
|
|
|
681
756
|
|
|
682
757
|
|
|
683
758
|
|
|
684
759
|
|
|
685
|
-
// CIL[
|
|
686
|
-
// CIL[
|
|
687
|
-
// CIL[DOC-
|
|
688
|
-
// CIL[DOC-
|
|
689
|
-
// CIL[DOC-
|
|
690
|
-
// CIL[DOC-
|
|
691
|
-
// CIL[DOC-
|
|
692
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
760
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:semanticSearch:function" type="function" identity="semanticSearch" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
761
|
+
// CIL[DOC-MACRO purpose="Performs a semantic search over embedded CIL chunks."]
|
|
762
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Embeds a query, calls the match_embeddings RPC, and returns matching chunk metadata."]
|
|
763
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
764
|
+
// CIL[DOC-CONTRACT inputs="query: string, projectId: string | null, limit: number, accountId: string" outputs="any[]" errors="Embedding or RPC failures" side_effects="none"]
|
|
765
|
+
// CIL[DOC-MICRO logic_summary="Generates a query embedding, runs match_embeddings, resolves chunks by stable_id, and applies project filtering." notable_decisions="[]"]
|
|
766
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
693
767
|
// CIL[DOC-STABILITY stability="stable"]
|
|
694
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
695
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
696
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
697
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
698
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
699
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
700
768
|
async function semanticSearch(
|
|
701
769
|
query: string,
|
|
702
770
|
projectId: string | null,
|
|
@@ -723,15 +791,15 @@ async function semanticSearch(
|
|
|
723
791
|
if (error) throw new Error(`match_embeddings RPC error: ${error.message}`)
|
|
724
792
|
|
|
725
793
|
|
|
726
|
-
const
|
|
727
|
-
if (!
|
|
794
|
+
const stableIds = [...new Set((matches || []).map((m: any) => m.document_id))]
|
|
795
|
+
if (!stableIds.length) return []
|
|
728
796
|
|
|
729
797
|
const { data: chunks } = await adminDb
|
|
730
798
|
.from('items')
|
|
731
799
|
.select('id, title, data')
|
|
732
|
-
.in('
|
|
800
|
+
.in('data->>stable_id', stableIds)
|
|
733
801
|
|
|
734
|
-
const chunkMap = new Map((chunks || []).map((c: any) => [c.
|
|
802
|
+
const chunkMap = new Map((chunks || []).map((c: any) => [c.data?.stable_id, c]))
|
|
735
803
|
|
|
736
804
|
return (matches || [])
|
|
737
805
|
.filter((m: any) => {
|
|
@@ -743,7 +811,7 @@ async function semanticSearch(
|
|
|
743
811
|
.map((m: any) => {
|
|
744
812
|
const chunk = chunkMap.get(m.document_id)
|
|
745
813
|
return {
|
|
746
|
-
chunk_id: m.document_id,
|
|
814
|
+
chunk_id: chunk?.data?.stable_id || m.document_id,
|
|
747
815
|
chunk_name: chunk?.data?.chunk_name || chunk?.title || '',
|
|
748
816
|
file_path: chunk?.data?.file_path || '',
|
|
749
817
|
macro: chunk?.data?.macro || '',
|
|
@@ -757,50 +825,50 @@ async function semanticSearch(
|
|
|
757
825
|
})
|
|
758
826
|
.slice(0, limit)
|
|
759
827
|
}
|
|
828
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Performs a semantic search over embedded CIL chunks.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
829
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
830
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
831
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
832
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
833
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
834
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:semanticSearch:function"]
|
|
760
835
|
|
|
761
836
|
|
|
762
837
|
|
|
763
838
|
|
|
764
839
|
|
|
765
|
-
// CIL[
|
|
766
|
-
// CIL[
|
|
767
|
-
// CIL[DOC-
|
|
768
|
-
// CIL[DOC-
|
|
769
|
-
// CIL[DOC-
|
|
770
|
-
// CIL[DOC-
|
|
771
|
-
// CIL[DOC-
|
|
772
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
840
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:getPlatformAccountId:function" type="function" identity="getPlatformAccountId" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
841
|
+
// CIL[DOC-MACRO purpose="Resolves the spine-system account id for platform-wide operations."]
|
|
842
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Looks up the 'spine-system' account record and returns its id."]
|
|
843
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
844
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="string" errors="none" side_effects="none"]
|
|
845
|
+
// CIL[DOC-MICRO logic_summary="Queries the accounts table for the slug 'spine-system' and returns the id or an empty string." notable_decisions="[]"]
|
|
846
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
773
847
|
// CIL[DOC-STABILITY stability="stable"]
|
|
774
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
775
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
776
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
777
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
778
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
779
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
780
848
|
async function getPlatformAccountId(): Promise<string> {
|
|
781
849
|
const { data } = await adminDb.from('accounts').select('id').eq('slug', 'spine-system').maybeSingle()
|
|
782
850
|
return data?.id || ''
|
|
783
851
|
}
|
|
852
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Resolves the spine-system account id for platform-wide operations.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
853
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
854
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
855
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
856
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
857
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
858
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:getPlatformAccountId:function"]
|
|
784
859
|
|
|
785
860
|
|
|
786
861
|
|
|
787
862
|
|
|
788
863
|
|
|
789
|
-
// CIL[
|
|
790
|
-
// CIL[
|
|
791
|
-
// CIL[DOC-
|
|
792
|
-
// CIL[DOC-
|
|
793
|
-
// CIL[DOC-
|
|
794
|
-
// CIL[DOC-
|
|
795
|
-
// CIL[DOC-
|
|
796
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
864
|
+
// CIL[BEGIN stable_id="~/.framework/functions/cil-embeddings.ts:handler:constant" type="constant" identity="handler" parent="~/.framework/functions/cil-embeddings.ts"]
|
|
865
|
+
// CIL[DOC-MACRO purpose="Exposes the Netlify function handler for embedding and search actions."]
|
|
866
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Routes action requests to estimate, embed_chunk, embed_project, embed_approved, status, search, and delete logic."]
|
|
867
|
+
// CIL[DOC-CONTEXT module="cil-embeddings" 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/cil-embeddings.ts,.framework/functions/embeddings.ts"]
|
|
868
|
+
// CIL[DOC-CONTRACT inputs="ctx: any, body: any" outputs="unknown" errors="none" side_effects="none"]
|
|
869
|
+
// CIL[DOC-MICRO logic_summary="Uses createHandler to dispatch action types and process embedding jobs through the CIL pipeline." notable_decisions="[]"]
|
|
870
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
797
871
|
// CIL[DOC-STABILITY stability="stable"]
|
|
798
|
-
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
799
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
800
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
801
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
802
|
-
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
803
|
-
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
804
872
|
export const handler = createHandler(async (ctx, body) => {
|
|
805
873
|
const action = ctx.query?.action
|
|
806
874
|
const accountId = ctx.accountId || await getPlatformAccountId()
|
|
@@ -835,18 +903,18 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
835
903
|
}
|
|
836
904
|
|
|
837
905
|
|
|
838
|
-
const
|
|
906
|
+
const chunkStableIds = (chunks || []).map((c: any) => c.data?.stable_id).filter(Boolean)
|
|
839
907
|
const existingDocIds = new Set<string>()
|
|
840
908
|
const SUPABASE_IN_LIMIT = 500
|
|
841
|
-
for (let i = 0; i <
|
|
909
|
+
for (let i = 0; i < chunkStableIds.length; i += SUPABASE_IN_LIMIT) {
|
|
842
910
|
const { data: emb } = await adminDb
|
|
843
911
|
.from('embeddings')
|
|
844
912
|
.select('document_id')
|
|
845
|
-
.in('document_id',
|
|
913
|
+
.in('document_id', chunkStableIds.slice(i, i + SUPABASE_IN_LIMIT))
|
|
846
914
|
for (const row of emb || []) existingDocIds.add(row.document_id)
|
|
847
915
|
}
|
|
848
916
|
|
|
849
|
-
const toEmbed = (chunks || []).filter((c: any) => !existingDocIds.has(c.
|
|
917
|
+
const toEmbed = (chunks || []).filter((c: any) => !existingDocIds.has(c.data?.stable_id))
|
|
850
918
|
const alreadyEmbedded = (chunks || []).length - toEmbed.length
|
|
851
919
|
|
|
852
920
|
|
|
@@ -875,20 +943,30 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
875
943
|
|
|
876
944
|
|
|
877
945
|
if (action === 'embed_chunk') {
|
|
878
|
-
const
|
|
879
|
-
|
|
946
|
+
const projectId = body?.project_id || ctx.query?.project_id
|
|
947
|
+
const stableId = body?.stable_id || ctx.query?.stable_id
|
|
948
|
+
const versionId = body?.version_id || ctx.query?.version_id
|
|
949
|
+
if (!projectId) throw new Error('project_id is required')
|
|
950
|
+
if (!stableId) throw new Error('stable_id is required')
|
|
880
951
|
|
|
881
|
-
|
|
952
|
+
let q = adminDb
|
|
882
953
|
.from('items')
|
|
883
954
|
.select('id, title, data')
|
|
884
|
-
.
|
|
885
|
-
.
|
|
955
|
+
.filter('data->>kb_type', 'eq', 'cil_chunk')
|
|
956
|
+
.filter('data->>project_id', 'eq', projectId)
|
|
957
|
+
.filter('data->>stable_id', 'eq', stableId)
|
|
958
|
+
.eq('is_active', true)
|
|
959
|
+
if (versionId) q = (q as any).filter('data->>version_id', 'eq', versionId)
|
|
886
960
|
|
|
887
|
-
|
|
961
|
+
const { data: chunk, error } = await (q as any).maybeSingle()
|
|
962
|
+
|
|
963
|
+
if (error || !chunk) throw new Error(`Chunk not found: ${stableId}`)
|
|
888
964
|
|
|
889
965
|
const result = await embedChunk(chunk, accountId, body?.force_regenerate ?? false)
|
|
890
966
|
return {
|
|
891
|
-
|
|
967
|
+
project_id: projectId,
|
|
968
|
+
stable_id: stableId,
|
|
969
|
+
version_id: versionId || chunk.data?.version_id || null,
|
|
892
970
|
chunk_name: chunk.data?.chunk_name || '',
|
|
893
971
|
...result,
|
|
894
972
|
}
|
|
@@ -927,13 +1005,13 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
927
1005
|
|
|
928
1006
|
if (action === 'embed_approved' && selectedPaths.length > 0 && !filePath) {
|
|
929
1007
|
|
|
930
|
-
const pending = await loadPendingChunks(projectId, selectedPaths, '
|
|
1008
|
+
const pending = await loadPendingChunks(projectId, selectedPaths, '3-documented', projectItem)
|
|
931
1009
|
const sorted = pending.sort((a: any, b: any) => a.id.localeCompare(b.id))
|
|
932
1010
|
totalChunks = sorted.length
|
|
933
1011
|
pageChunks = sorted.slice(pageOffset, pageOffset + pageLimit)
|
|
934
1012
|
} else {
|
|
935
1013
|
const sourceFilePaths = filePath ? [filePath] : getEmbedSourceFilePaths(projectItem, secondPass)
|
|
936
|
-
const sourceChunks = await loadSourceChunks(projectId, sourceFilePaths, pageOffset, pageLimit)
|
|
1014
|
+
const sourceChunks = await loadSourceChunks(projectId, sourceFilePaths, pageOffset, pageLimit, projectItem)
|
|
937
1015
|
totalChunks = sourceChunks.total
|
|
938
1016
|
pageChunks = sourceChunks.chunks
|
|
939
1017
|
error = null
|
|
@@ -946,14 +1024,14 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
946
1024
|
}
|
|
947
1025
|
|
|
948
1026
|
|
|
949
|
-
const
|
|
1027
|
+
const pageChunkDocumentIds = pageChunks.map((c: any) => c.data?.stable_id || c.id)
|
|
950
1028
|
const SUPABASE_IN_LIMIT = 500
|
|
951
1029
|
const existingRows: any[] = []
|
|
952
|
-
for (let i = 0; i <
|
|
1030
|
+
for (let i = 0; i < pageChunkDocumentIds.length; i += SUPABASE_IN_LIMIT) {
|
|
953
1031
|
const { data } = await adminDb
|
|
954
1032
|
.from('embeddings')
|
|
955
1033
|
.select('id, document_id, content_hash, metadata')
|
|
956
|
-
.in('document_id',
|
|
1034
|
+
.in('document_id', pageChunkDocumentIds.slice(i, i + SUPABASE_IN_LIMIT))
|
|
957
1035
|
existingRows.push(...(data || []))
|
|
958
1036
|
}
|
|
959
1037
|
|
|
@@ -969,28 +1047,34 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
969
1047
|
let totalSkipped = 0
|
|
970
1048
|
|
|
971
1049
|
for (const chunk of pageChunks) {
|
|
1050
|
+
const d = chunk.data || {}
|
|
1051
|
+
const vc = d.vector_content || {}
|
|
1052
|
+
const vectorReadyText = (t: string) => (vc[t]?.status === 'ready' && vc[t]?.content ? vc[t].content : '')
|
|
972
1053
|
const vectors = [
|
|
973
|
-
{ type: 'semantic',
|
|
974
|
-
{ type: '
|
|
975
|
-
{ type: '
|
|
976
|
-
{ type: '
|
|
1054
|
+
{ type: 'semantic', text: buildSemanticText(chunk) },
|
|
1055
|
+
{ type: 'structure', text: buildStructuralText(chunk) },
|
|
1056
|
+
{ type: 'context', text: vectorReadyText('context') },
|
|
1057
|
+
{ type: 'blast_radius', text: vectorReadyText('blast_radius') },
|
|
1058
|
+
{ type: 'configuration', text: vectorReadyText('configuration') },
|
|
1059
|
+
{ type: 'constraint', text: buildConstraintText(chunk) },
|
|
977
1060
|
].filter(v => v.text.trim().length > 0)
|
|
978
1061
|
|
|
1062
|
+
const chunkStableId = chunk.data?.stable_id || chunk.id
|
|
979
1063
|
for (const v of vectors) {
|
|
980
|
-
const
|
|
981
|
-
const existing = existingMap.get(
|
|
982
|
-
if (!forceRegenerate && existing && existing.
|
|
1064
|
+
const inputHash = contentHash(v.text)
|
|
1065
|
+
const existing = existingMap.get(chunkStableId)?.get(v.type)
|
|
1066
|
+
if (!forceRegenerate && existing && existing.metadata?.input_hash === inputHash) {
|
|
983
1067
|
totalSkipped++
|
|
984
1068
|
continue
|
|
985
1069
|
}
|
|
986
|
-
toEmbed.push({ chunkId:
|
|
1070
|
+
toEmbed.push({ chunkId: chunkStableId, type: v.type, text: v.text, existingRowId: existing?.id })
|
|
987
1071
|
}
|
|
988
1072
|
}
|
|
989
1073
|
|
|
990
1074
|
|
|
991
1075
|
|
|
992
1076
|
|
|
993
|
-
const targetPipelineStatus = secondPass ? '
|
|
1077
|
+
const targetPipelineStatus = secondPass ? '7-embedded-mapped' : '7-embedded-mapped'
|
|
994
1078
|
|
|
995
1079
|
const advanceFiles = async () => {
|
|
996
1080
|
const affectedFileIds = [...new Set(pageChunks.map(c => c.data?.file_id).filter(Boolean))]
|
|
@@ -1018,9 +1102,9 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
1018
1102
|
}
|
|
1019
1103
|
|
|
1020
1104
|
|
|
1021
|
-
if (forceRegenerate &&
|
|
1022
|
-
for (let i = 0; i <
|
|
1023
|
-
await adminDb.from('embeddings').delete().in('document_id',
|
|
1105
|
+
if (forceRegenerate && pageChunkDocumentIds.length > 0) {
|
|
1106
|
+
for (let i = 0; i < pageChunkDocumentIds.length; i += SUPABASE_IN_LIMIT) {
|
|
1107
|
+
await adminDb.from('embeddings').delete().in('document_id', pageChunkDocumentIds.slice(i, i + SUPABASE_IN_LIMIT))
|
|
1024
1108
|
}
|
|
1025
1109
|
for (const item of toEmbed) { item.existingRowId = undefined }
|
|
1026
1110
|
}
|
|
@@ -1053,7 +1137,7 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
1053
1137
|
|
|
1054
1138
|
|
|
1055
1139
|
const now = new Date().toISOString()
|
|
1056
|
-
const chunkMap = new Map(pageChunks.map((c: any) => [c.id, c]))
|
|
1140
|
+
const chunkMap = new Map(pageChunks.map((c: any) => [c.data?.stable_id || c.id, c]))
|
|
1057
1141
|
|
|
1058
1142
|
const rowsToInsert: object[] = []
|
|
1059
1143
|
const rowsToUpdate: { id: string; row: object }[] = []
|
|
@@ -1064,6 +1148,8 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
1064
1148
|
if (!vec || vec.length === 0) continue
|
|
1065
1149
|
|
|
1066
1150
|
const chunk = chunkMap.get(chunkId)
|
|
1151
|
+
const hash = computeContentHash(text)
|
|
1152
|
+
const inputHash = contentHash(text)
|
|
1067
1153
|
const row = {
|
|
1068
1154
|
account_id: accountId,
|
|
1069
1155
|
model_id: EMBEDDING_MODEL,
|
|
@@ -1071,7 +1157,7 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
1071
1157
|
chunk_index: VECTOR_TYPE_INDEX[type] ?? 0,
|
|
1072
1158
|
content: text,
|
|
1073
1159
|
embedding: `[${vec.join(',')}]`,
|
|
1074
|
-
content_hash:
|
|
1160
|
+
content_hash: hash,
|
|
1075
1161
|
approved_at: now,
|
|
1076
1162
|
revoked_at: null,
|
|
1077
1163
|
metadata: {
|
|
@@ -1083,6 +1169,8 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
1083
1169
|
chunk_name: chunk?.data?.chunk_name || '',
|
|
1084
1170
|
file_path: chunk?.data?.file_path || '',
|
|
1085
1171
|
project_id: projectId,
|
|
1172
|
+
version_id: chunk?.data?.version_id || '',
|
|
1173
|
+
input_hash: inputHash,
|
|
1086
1174
|
},
|
|
1087
1175
|
}
|
|
1088
1176
|
|
|
@@ -1104,7 +1192,7 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
1104
1192
|
for (const { id, row } of rowsToUpdate.slice(i, i + PARALLEL_UPDATE)) {
|
|
1105
1193
|
updatePromises.push(
|
|
1106
1194
|
adminDb.from('embeddings').update(row).eq('id', id)
|
|
1107
|
-
.then(({ error: e }) => { if (e) errors.push(`embedding update ${id}: ${e.message}`) })
|
|
1195
|
+
.then(({ error: e }) => { if (e) errors.push(`embedding update ${id}: ${e.message}`) }) as Promise<void>
|
|
1108
1196
|
)
|
|
1109
1197
|
}
|
|
1110
1198
|
}
|
|
@@ -1139,33 +1227,22 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
1139
1227
|
.filter('data->>project_id', 'eq', projectId)
|
|
1140
1228
|
.eq('is_active', true)
|
|
1141
1229
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
.
|
|
1145
|
-
.
|
|
1146
|
-
.filter('
|
|
1147
|
-
.
|
|
1148
|
-
.
|
|
1149
|
-
|
|
1150
|
-
const chunkIds = (chunkItems || []).map((c: any) => c.id)
|
|
1151
|
-
let embeddedCount = 0
|
|
1230
|
+
const { count: embeddedCount } = await adminDb
|
|
1231
|
+
.from('embeddings')
|
|
1232
|
+
.select('document_id', { count: 'exact', head: true })
|
|
1233
|
+
.filter('metadata->>project_id', 'eq', projectId)
|
|
1234
|
+
.filter('metadata->>vector_type', 'eq', 'semantic')
|
|
1235
|
+
.not('approved_at', 'is', null)
|
|
1236
|
+
.is('revoked_at', null)
|
|
1152
1237
|
|
|
1153
|
-
|
|
1154
|
-
const { data: embeddedDocs } = await adminDb
|
|
1155
|
-
.from('embeddings')
|
|
1156
|
-
.select('document_id')
|
|
1157
|
-
.in('document_id', chunkIds)
|
|
1158
|
-
.is('revoked_at', null)
|
|
1159
|
-
|
|
1160
|
-
embeddedCount = new Set((embeddedDocs || []).map((e: any) => e.document_id)).size
|
|
1161
|
-
}
|
|
1238
|
+
const safeEmbeddedCount = embeddedCount || 0
|
|
1162
1239
|
|
|
1163
1240
|
return {
|
|
1164
1241
|
project_id: projectId,
|
|
1165
1242
|
total_chunks: totalChunks || 0,
|
|
1166
|
-
embedded_chunks:
|
|
1167
|
-
unembedded_chunks: (totalChunks || 0) -
|
|
1168
|
-
coverage_pct: totalChunks ? Math.round((
|
|
1243
|
+
embedded_chunks: safeEmbeddedCount,
|
|
1244
|
+
unembedded_chunks: (totalChunks || 0) - safeEmbeddedCount,
|
|
1245
|
+
coverage_pct: totalChunks ? Math.round((safeEmbeddedCount / totalChunks) * 100) : 0,
|
|
1169
1246
|
}
|
|
1170
1247
|
}
|
|
1171
1248
|
|
|
@@ -1185,18 +1262,30 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
1185
1262
|
const chunkId = body?.chunk_id || ctx.query?.chunk_id
|
|
1186
1263
|
if (!chunkId) throw new Error('chunk_id is required')
|
|
1187
1264
|
|
|
1265
|
+
const { data: chunkItem } = await adminDb
|
|
1266
|
+
.from('items')
|
|
1267
|
+
.select('data')
|
|
1268
|
+
.eq('id', chunkId)
|
|
1269
|
+
.maybeSingle()
|
|
1270
|
+
const stableId = chunkItem?.data?.stable_id || chunkId
|
|
1271
|
+
|
|
1188
1272
|
const { error } = await adminDb
|
|
1189
1273
|
.from('embeddings')
|
|
1190
1274
|
.delete()
|
|
1191
|
-
.eq('document_id',
|
|
1275
|
+
.eq('document_id', stableId)
|
|
1192
1276
|
|
|
1193
1277
|
if (error) throw new Error(`Failed to delete embeddings: ${error.message}`)
|
|
1194
|
-
return { chunk_id:
|
|
1278
|
+
return { chunk_id: stableId, deleted: true }
|
|
1195
1279
|
}
|
|
1196
1280
|
|
|
1197
1281
|
throw new Error(`Unknown action: ${action}. Valid: embed_chunk, embed_project, embed_approved, status, search, delete`)
|
|
1198
1282
|
})
|
|
1283
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Exposes the Netlify function handler for embedding and search actions.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/embeddings.ts"]
|
|
1284
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1285
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1286
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
1287
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
1288
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1289
|
+
// CIL[END stable_id="~/.framework/functions/cil-embeddings.ts:handler:constant"]
|
|
1199
1290
|
|
|
1200
1291
|
|
|
1201
|
-
|
|
1202
|
-
// CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_embeddings_handler_1784235266"]
|