attocode-code-intel 0.1.0__py3-none-any.whl
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.
- attocode_code_intel-0.1.0.dist-info/METADATA +221 -0
- attocode_code_intel-0.1.0.dist-info/RECORD +345 -0
- attocode_code_intel-0.1.0.dist-info/WHEEL +4 -0
- attocode_code_intel-0.1.0.dist-info/entry_points.txt +2 -0
- attocode_code_intel-0.1.0.dist-info/licenses/LICENSE +21 -0
- attocode_intel/GUIDELINES.md +432 -0
- attocode_intel/__init__.py +52 -0
- attocode_intel/_internal/__init__.py +1 -0
- attocode_intel/_internal/errors/__init__.py +126 -0
- attocode_intel/_internal/integrations/__init__.py +1 -0
- attocode_intel/_internal/integrations/context/__init__.py +1 -0
- attocode_intel/_internal/integrations/context/architecture_drift.py +354 -0
- attocode_intel/_internal/integrations/context/ast_chunker.py +202 -0
- attocode_intel/_internal/integrations/context/ast_service.py +1483 -0
- attocode_intel/_internal/integrations/context/blob_oid.py +423 -0
- attocode_intel/_internal/integrations/context/cache_manifest.py +221 -0
- attocode_intel/_internal/integrations/context/cas.py +466 -0
- attocode_intel/_internal/integrations/context/code_analyzer.py +528 -0
- attocode_intel/_internal/integrations/context/codebase_ast.py +1461 -0
- attocode_intel/_internal/integrations/context/codebase_context.py +1736 -0
- attocode_intel/_internal/integrations/context/cross_mode.py +263 -0
- attocode_intel/_internal/integrations/context/cross_references.py +616 -0
- attocode_intel/_internal/integrations/context/embedding_rotation.py +597 -0
- attocode_intel/_internal/integrations/context/embeddings.py +282 -0
- attocode_intel/_internal/integrations/context/frecency.py +427 -0
- attocode_intel/_internal/integrations/context/fuzzy.py +320 -0
- attocode_intel/_internal/integrations/context/hierarchical_explorer.py +331 -0
- attocode_intel/_internal/integrations/context/hydration.py +90 -0
- attocode_intel/_internal/integrations/context/index_repair.py +87 -0
- attocode_intel/_internal/integrations/context/index_store.py +586 -0
- attocode_intel/_internal/integrations/context/memory_store.py +602 -0
- attocode_intel/_internal/integrations/context/module_resolution.py +52 -0
- attocode_intel/_internal/integrations/context/query_constraints.py +361 -0
- attocode_intel/_internal/integrations/context/query_history.py +417 -0
- attocode_intel/_internal/integrations/context/reranker.py +351 -0
- attocode_intel/_internal/integrations/context/semantic_search.py +2931 -0
- attocode_intel/_internal/integrations/context/syntax_evidence.py +94 -0
- attocode_intel/_internal/integrations/context/systemone_ranker.py +245 -0
- attocode_intel/_internal/integrations/context/temporal_coupling.py +411 -0
- attocode_intel/_internal/integrations/context/trigram_index.py +820 -0
- attocode_intel/_internal/integrations/context/trigram_regex.py +171 -0
- attocode_intel/_internal/integrations/context/ts_parser.py +2199 -0
- attocode_intel/_internal/integrations/context/vector_store.py +795 -0
- attocode_intel/_internal/integrations/feature_flags/__init__.py +357 -0
- attocode_intel/_internal/integrations/lsp/__init__.py +1 -0
- attocode_intel/_internal/integrations/lsp/client.py +1140 -0
- attocode_intel/_internal/integrations/mcp/__init__.py +1 -0
- attocode_intel/_internal/integrations/mcp/client.py +253 -0
- attocode_intel/_internal/integrations/security/__init__.py +1 -0
- attocode_intel/_internal/integrations/security/custom_rules.py +176 -0
- attocode_intel/_internal/integrations/security/dataflow.py +522 -0
- attocode_intel/_internal/integrations/security/dependency_audit.py +303 -0
- attocode_intel/_internal/integrations/security/matcher.py +44 -0
- attocode_intel/_internal/integrations/security/patterns.py +724 -0
- attocode_intel/_internal/integrations/security/scanner.py +351 -0
- attocode_intel/_internal/integrations/utilities/__init__.py +1 -0
- attocode_intel/_internal/integrations/utilities/ignore.py +64 -0
- attocode_intel/_internal/integrations/utilities/token_estimate.py +51 -0
- attocode_intel/_internal/tricks/__init__.py +1 -0
- attocode_intel/_internal/tricks/recursive_context.py +357 -0
- attocode_intel/_internal/types/__init__.py +1 -0
- attocode_intel/_internal/types/events.py +289 -0
- attocode_intel/_internal/types/severity.py +15 -0
- attocode_intel/_shared.py +341 -0
- attocode_intel/analysis_coverage.py +56 -0
- attocode_intel/api/__init__.py +1 -0
- attocode_intel/api/access.py +32 -0
- attocode_intel/api/app.py +247 -0
- attocode_intel/api/auth/__init__.py +128 -0
- attocode_intel/api/auth/api_keys.py +61 -0
- attocode_intel/api/auth/context.py +34 -0
- attocode_intel/api/auth/jwt.py +66 -0
- attocode_intel/api/auth/oauth.py +146 -0
- attocode_intel/api/auth/passwords.py +15 -0
- attocode_intel/api/deps.py +351 -0
- attocode_intel/api/knowledge_bridge.py +13 -0
- attocode_intel/api/mcp_transport.py +51 -0
- attocode_intel/api/middleware.py +411 -0
- attocode_intel/api/models.py +698 -0
- attocode_intel/api/providers/__init__.py +1 -0
- attocode_intel/api/providers/db_provider.py +1106 -0
- attocode_intel/api/providers/local_provider.py +476 -0
- attocode_intel/api/providers/remote_provider.py +740 -0
- attocode_intel/api/repository_source.py +21 -0
- attocode_intel/api/routes/__init__.py +1 -0
- attocode_intel/api/routes/_pin_helper.py +158 -0
- attocode_intel/api/routes/activity.py +148 -0
- attocode_intel/api/routes/adr.py +102 -0
- attocode_intel/api/routes/analysis.py +515 -0
- attocode_intel/api/routes/api_keys.py +170 -0
- attocode_intel/api/routes/auth.py +428 -0
- attocode_intel/api/routes/branches.py +262 -0
- attocode_intel/api/routes/cross_repo_search.py +198 -0
- attocode_intel/api/routes/embeddings.py +386 -0
- attocode_intel/api/routes/files.py +132 -0
- attocode_intel/api/routes/files_v2.py +388 -0
- attocode_intel/api/routes/gc.py +322 -0
- attocode_intel/api/routes/git_v2.py +433 -0
- attocode_intel/api/routes/graph.py +174 -0
- attocode_intel/api/routes/graph_viz.py +160 -0
- attocode_intel/api/routes/health.py +62 -0
- attocode_intel/api/routes/history.py +175 -0
- attocode_intel/api/routes/jobs.py +84 -0
- attocode_intel/api/routes/learning.py +205 -0
- attocode_intel/api/routes/lsp.py +272 -0
- attocode_intel/api/routes/notify.py +623 -0
- attocode_intel/api/routes/operations.py +27 -0
- attocode_intel/api/routes/orgs.py +924 -0
- attocode_intel/api/routes/preferences.py +100 -0
- attocode_intel/api/routes/presence.py +42 -0
- attocode_intel/api/routes/projects.py +116 -0
- attocode_intel/api/routes/repos.py +47 -0
- attocode_intel/api/routes/search.py +180 -0
- attocode_intel/api/routes/snapshots.py +614 -0
- attocode_intel/api/routes/webhooks.py +313 -0
- attocode_intel/api/routes/websocket.py +116 -0
- attocode_intel/api/static/graph.html +239 -0
- attocode_intel/api/utils.py +96 -0
- attocode_intel/artifacts/__init__.py +45 -0
- attocode_intel/artifacts/hashing.py +230 -0
- attocode_intel/artifacts/provenance.py +190 -0
- attocode_intel/artifacts/retrieval_pin.py +159 -0
- attocode_intel/audit.py +59 -0
- attocode_intel/bug_finder.py +206 -0
- attocode_intel/bundle.py +80 -0
- attocode_intel/catalog.py +242 -0
- attocode_intel/change_review.py +75 -0
- attocode_intel/cli.py +3062 -0
- attocode_intel/community.py +63 -0
- attocode_intel/confidence/__init__.py +144 -0
- attocode_intel/confidence/jev.py +234 -0
- attocode_intel/confidence/llm.py +330 -0
- attocode_intel/confidence/redact.py +44 -0
- attocode_intel/confidence/settings.py +74 -0
- attocode_intel/config.py +256 -0
- attocode_intel/crypto.py +31 -0
- attocode_intel/db/__init__.py +7 -0
- attocode_intel/db/base.py +33 -0
- attocode_intel/db/engine.py +61 -0
- attocode_intel/db/models.py +529 -0
- attocode_intel/entrypoint.py +185 -0
- attocode_intel/focused_evidence.py +130 -0
- attocode_intel/freshness.py +154 -0
- attocode_intel/gateway.py +734 -0
- attocode_intel/git/__init__.py +7 -0
- attocode_intel/git/credentials.py +75 -0
- attocode_intel/git/manager.py +493 -0
- attocode_intel/git/models.py +96 -0
- attocode_intel/git/storage.py +98 -0
- attocode_intel/graph_query_parser.py +761 -0
- attocode_intel/helpers.py +712 -0
- attocode_intel/indexing/__init__.py +29 -0
- attocode_intel/indexing/debouncer.py +136 -0
- attocode_intel/indexing/delta_indexer.py +151 -0
- attocode_intel/indexing/full_indexer.py +323 -0
- attocode_intel/indexing/incremental.py +240 -0
- attocode_intel/indexing/parser.py +403 -0
- attocode_intel/indexing/summarizer.py +264 -0
- attocode_intel/installer.py +1896 -0
- attocode_intel/knowledge.py +269 -0
- attocode_intel/local_knowledge.py +77 -0
- attocode_intel/migrations/alembic.ini +36 -0
- attocode_intel/migrations/env.py +71 -0
- attocode_intel/migrations/script.py.mako +27 -0
- attocode_intel/migrations/versions/001_initial_schema.py +219 -0
- attocode_intel/migrations/versions/002_branch_version_and_embeddings.py +61 -0
- attocode_intel/migrations/versions/003_embedding_uniqueness_and_cascade.py +51 -0
- attocode_intel/migrations/versions/004_audit_events.py +38 -0
- attocode_intel/migrations/versions/005_user_preferences.py +30 -0
- attocode_intel/migrations/versions/006_google_oauth.py +27 -0
- attocode_intel/migrations/versions/007_pgvector_embeddings.py +28 -0
- attocode_intel/migrations/versions/008_symbol_references.py +37 -0
- attocode_intel/migrations/versions/009_webhook_secret_encryption.py +25 -0
- attocode_intel/migrations/versions/010_add_commits_table.py +40 -0
- attocode_intel/migrations/versions/011_commit_changed_files.py +25 -0
- attocode_intel/migrations/versions/012_branch_merged_at.py +25 -0
- attocode_intel/migrations/versions/013_revoked_tokens.py +32 -0
- attocode_intel/migrations/versions/014_blame_hunks.py +40 -0
- attocode_intel/migrations/versions/015_commit_file_stats.py +40 -0
- attocode_intel/migrations/versions/016_embedding_provenance_columns.py +179 -0
- attocode_intel/migrations/versions/017_provenance_table.py +102 -0
- attocode_intel/migrations/versions/018_repo_snapshots.py +178 -0
- attocode_intel/migrations/versions/019_symref_caller.py +42 -0
- attocode_intel/migrations/versions/020_shared_knowledge.py +29 -0
- attocode_intel/onboarding.py +258 -0
- attocode_intel/output.py +178 -0
- attocode_intel/precision.py +133 -0
- attocode_intel/presence.py +160 -0
- attocode_intel/probe.py +110 -0
- attocode_intel/project_dir.py +97 -0
- attocode_intel/pubsub.py +113 -0
- attocode_intel/query_ranking.py +242 -0
- attocode_intel/readiness.py +972 -0
- attocode_intel/redis.py +51 -0
- attocode_intel/reference_pages.py +60 -0
- attocode_intel/remote.py +131 -0
- attocode_intel/repo_ranker.py +246 -0
- attocode_intel/request_context.py +82 -0
- attocode_intel/rules/__init__.py +28 -0
- attocode_intel/rules/ci.py +320 -0
- attocode_intel/rules/combinators.py +293 -0
- attocode_intel/rules/enricher.py +127 -0
- attocode_intel/rules/evolution.py +452 -0
- attocode_intel/rules/executor.py +531 -0
- attocode_intel/rules/filters/__init__.py +5 -0
- attocode_intel/rules/filters/pipeline.py +151 -0
- attocode_intel/rules/formatter.py +198 -0
- attocode_intel/rules/hygiene.py +242 -0
- attocode_intel/rules/importers/__init__.py +1 -0
- attocode_intel/rules/importers/semgrep.py +382 -0
- attocode_intel/rules/loader.py +292 -0
- attocode_intel/rules/marketplace.py +375 -0
- attocode_intel/rules/metavar.py +181 -0
- attocode_intel/rules/model.py +317 -0
- attocode_intel/rules/packs/__init__.py +1 -0
- attocode_intel/rules/packs/community/_license_templates/Apache-2.0.txt +176 -0
- attocode_intel/rules/packs/community/_license_templates/MIT.txt +21 -0
- attocode_intel/rules/packs/community/bandit-python/LICENSE +176 -0
- attocode_intel/rules/packs/community/bandit-python/NOTICE +13 -0
- attocode_intel/rules/packs/community/bandit-python/PORTING.md +23 -0
- attocode_intel/rules/packs/community/bandit-python/manifest.yaml +14 -0
- attocode_intel/rules/packs/community/bandit-python/rules/B105-hardcoded-password.yaml +23 -0
- attocode_intel/rules/packs/community/bandit-python/rules/B303-weak-md5.yaml +21 -0
- attocode_intel/rules/packs/community/bandit-python/rules/B304-weak-des.yaml +20 -0
- attocode_intel/rules/packs/community/bandit-python/rules/B307-use-of-eval.yaml +22 -0
- attocode_intel/rules/packs/community/bandit-python/rules/B324-weak-sha1.yaml +21 -0
- attocode_intel/rules/packs/community/bandit-python/rules/B501-no-cert-validation.yaml +23 -0
- attocode_intel/rules/packs/community/bandit-python/rules/B602-shell-true.yaml +22 -0
- attocode_intel/rules/packs/community/bandit-python/rules/B608-sqli.yaml +22 -0
- attocode_intel/rules/packs/community/eslint-typescript/LICENSE +21 -0
- attocode_intel/rules/packs/community/eslint-typescript/NOTICE +13 -0
- attocode_intel/rules/packs/community/eslint-typescript/PORTING.md +23 -0
- attocode_intel/rules/packs/community/eslint-typescript/manifest.yaml +14 -0
- attocode_intel/rules/packs/community/eslint-typescript/rules/eqeqeq.yaml +20 -0
- attocode_intel/rules/packs/community/eslint-typescript/rules/no-eval.yaml +22 -0
- attocode_intel/rules/packs/community/eslint-typescript/rules/no-implied-eval.yaml +20 -0
- attocode_intel/rules/packs/community/eslint-typescript/rules/no-new-func.yaml +21 -0
- attocode_intel/rules/packs/community/eslint-typescript/rules/no-throw-literal.yaml +19 -0
- attocode_intel/rules/packs/community/eslint-typescript/rules/no-var.yaml +20 -0
- attocode_intel/rules/packs/community/eslint-typescript/rules/no-with.yaml +18 -0
- attocode_intel/rules/packs/community/gosec-go/LICENSE +176 -0
- attocode_intel/rules/packs/community/gosec-go/NOTICE +13 -0
- attocode_intel/rules/packs/community/gosec-go/PORTING.md +23 -0
- attocode_intel/rules/packs/community/gosec-go/manifest.yaml +14 -0
- attocode_intel/rules/packs/community/gosec-go/rules/G101-hardcoded-credentials.yaml +22 -0
- attocode_intel/rules/packs/community/gosec-go/rules/G102-bind-all-interfaces.yaml +21 -0
- attocode_intel/rules/packs/community/gosec-go/rules/G103-unsafe-block.yaml +21 -0
- attocode_intel/rules/packs/community/gosec-go/rules/G201-sql-format.yaml +21 -0
- attocode_intel/rules/packs/community/gosec-go/rules/G304-file-inclusion.yaml +23 -0
- attocode_intel/rules/packs/community/gosec-go/rules/G401-weak-cipher.yaml +20 -0
- attocode_intel/rules/packs/community/gosec-go/rules/G402-tls-min-version.yaml +20 -0
- attocode_intel/rules/packs/community/gosec-go/rules/G501-md5-import.yaml +21 -0
- attocode_intel/rules/packs/examples/cpp/manifest.yaml +4 -0
- attocode_intel/rules/packs/examples/cpp/rules/security.yaml +90 -0
- attocode_intel/rules/packs/examples/cpp/rules/structural.yaml +42 -0
- attocode_intel/rules/packs/examples/csharp/manifest.yaml +4 -0
- attocode_intel/rules/packs/examples/csharp/rules/security.yaml +69 -0
- attocode_intel/rules/packs/examples/csharp/rules/structural.yaml +42 -0
- attocode_intel/rules/packs/examples/go/manifest.yaml +4 -0
- attocode_intel/rules/packs/examples/go/rules/performance.yaml +136 -0
- attocode_intel/rules/packs/examples/go/rules/security.yaml +48 -0
- attocode_intel/rules/packs/examples/go/rules/structural.yaml +58 -0
- attocode_intel/rules/packs/examples/go/taint/sanitizers.yaml +24 -0
- attocode_intel/rules/packs/examples/go/taint/sinks.yaml +51 -0
- attocode_intel/rules/packs/examples/go/taint/sources.yaml +26 -0
- attocode_intel/rules/packs/examples/java/manifest.yaml +4 -0
- attocode_intel/rules/packs/examples/java/rules/correctness.yaml +55 -0
- attocode_intel/rules/packs/examples/java/rules/structural.yaml +48 -0
- attocode_intel/rules/packs/examples/java/taint/sinks.yaml +37 -0
- attocode_intel/rules/packs/examples/java/taint/sources.yaml +21 -0
- attocode_intel/rules/packs/examples/kotlin/manifest.yaml +4 -0
- attocode_intel/rules/packs/examples/kotlin/rules/correctness.yaml +50 -0
- attocode_intel/rules/packs/examples/kotlin/rules/structural.yaml +38 -0
- attocode_intel/rules/packs/examples/php/manifest.yaml +4 -0
- attocode_intel/rules/packs/examples/php/rules/security.yaml +66 -0
- attocode_intel/rules/packs/examples/php/rules/structural.yaml +41 -0
- attocode_intel/rules/packs/examples/python/manifest.yaml +4 -0
- attocode_intel/rules/packs/examples/python/rules/performance.yaml +90 -0
- attocode_intel/rules/packs/examples/python/rules/structural.yaml +55 -0
- attocode_intel/rules/packs/examples/ruby/manifest.yaml +4 -0
- attocode_intel/rules/packs/examples/ruby/rules/security.yaml +73 -0
- attocode_intel/rules/packs/examples/ruby/rules/structural.yaml +41 -0
- attocode_intel/rules/packs/examples/rust/manifest.yaml +4 -0
- attocode_intel/rules/packs/examples/rust/rules/correctness.yaml +51 -0
- attocode_intel/rules/packs/examples/rust/rules/structural.yaml +49 -0
- attocode_intel/rules/packs/examples/typescript/manifest.yaml +4 -0
- attocode_intel/rules/packs/examples/typescript/rules/performance.yaml +70 -0
- attocode_intel/rules/packs/examples/typescript/rules/structural.yaml +48 -0
- attocode_intel/rules/packs/pack_loader.py +244 -0
- attocode_intel/rules/plugins/__init__.py +1 -0
- attocode_intel/rules/plugins/plugin_loader.py +132 -0
- attocode_intel/rules/profiling.py +332 -0
- attocode_intel/rules/registry.py +213 -0
- attocode_intel/rules/sarif.py +187 -0
- attocode_intel/rules/synthesis.py +420 -0
- attocode_intel/rules/testing.py +326 -0
- attocode_intel/server.py +734 -0
- attocode_intel/service.py +3416 -0
- attocode_intel/sharing.py +57 -0
- attocode_intel/storage/__init__.py +6 -0
- attocode_intel/storage/branch_overlay.py +352 -0
- attocode_intel/storage/content_store.py +220 -0
- attocode_intel/storage/dependency_store.py +143 -0
- attocode_intel/storage/diff_engine.py +187 -0
- attocode_intel/storage/embedding_store.py +594 -0
- attocode_intel/storage/provenance_store.py +137 -0
- attocode_intel/storage/security_scanner_db.py +164 -0
- attocode_intel/storage/symbol_store.py +160 -0
- attocode_intel/structural_evidence.py +144 -0
- attocode_intel/symbol_inspection.py +141 -0
- attocode_intel/symbol_links.py +167 -0
- attocode_intel/telemetry.py +42 -0
- attocode_intel/test_ranking.py +73 -0
- attocode_intel/testing/__init__.py +43 -0
- attocode_intel/testing/fixtures.py +122 -0
- attocode_intel/testing/helpers.py +75 -0
- attocode_intel/testing/mocks.py +99 -0
- attocode_intel/tools/__init__.py +2 -0
- attocode_intel/tools/adr_tools.py +628 -0
- attocode_intel/tools/analysis_tools.py +382 -0
- attocode_intel/tools/composite_tools.py +695 -0
- attocode_intel/tools/cross_mode_tools.py +173 -0
- attocode_intel/tools/dead_code_tools.py +582 -0
- attocode_intel/tools/distill_tools.py +353 -0
- attocode_intel/tools/frecency_tools.py +220 -0
- attocode_intel/tools/fuzzy_tools.py +255 -0
- attocode_intel/tools/history_tools.py +486 -0
- attocode_intel/tools/learning_tools.py +222 -0
- attocode_intel/tools/lsp_tools.py +218 -0
- attocode_intel/tools/maintenance_tools.py +1662 -0
- attocode_intel/tools/navigation_tools.py +220 -0
- attocode_intel/tools/overlay_tools.py +540 -0
- attocode_intel/tools/pin_store.py +432 -0
- attocode_intel/tools/pin_tools.py +266 -0
- attocode_intel/tools/query_constraints_tools.py +262 -0
- attocode_intel/tools/query_history_tools.py +158 -0
- attocode_intel/tools/readiness_tools.py +44 -0
- attocode_intel/tools/rule_tools.py +992 -0
- attocode_intel/tools/search_tools.py +770 -0
- attocode_intel/tools/snapshot_tools.py +624 -0
- attocode_intel/workers/__init__.py +1 -0
- attocode_intel/workers/job_utils.py +111 -0
- attocode_intel/workers/jobs.py +573 -0
- attocode_intel/workers/run.py +30 -0
- attocode_intel/workers/settings.py +61 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"""Heuristic code-to-natural-language summarizer for embedding enrichment.
|
|
2
|
+
|
|
3
|
+
Generates natural language summaries of code chunks so that embedding models
|
|
4
|
+
produce vectors closer to how developers describe code in natural language
|
|
5
|
+
queries. The original code text is still stored for display — only the
|
|
6
|
+
embedding input changes.
|
|
7
|
+
|
|
8
|
+
No LLM is needed. All summaries are deterministic and fast (pure string
|
|
9
|
+
manipulation + lightweight regex parsing).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import re
|
|
15
|
+
|
|
16
|
+
# ---------------------------------------------------------------------------
|
|
17
|
+
# Public API
|
|
18
|
+
# ---------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class CodeSummarizer:
|
|
22
|
+
"""Generate natural language summaries of code chunks for better semantic search."""
|
|
23
|
+
|
|
24
|
+
def summarize(
|
|
25
|
+
self,
|
|
26
|
+
chunk_text: str,
|
|
27
|
+
chunk_type: str,
|
|
28
|
+
name: str,
|
|
29
|
+
language: str,
|
|
30
|
+
) -> str:
|
|
31
|
+
"""Create a natural language summary of a code chunk.
|
|
32
|
+
|
|
33
|
+
The returned string is *not* meant for display — it feeds the
|
|
34
|
+
embedding model. It combines a readable NL description with key
|
|
35
|
+
identifiers so the resulting vector captures both semantic meaning
|
|
36
|
+
and exact-match ability.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
chunk_text: The code / structured text of the chunk (as produced
|
|
40
|
+
by ``_chunk_single_file``).
|
|
41
|
+
chunk_type: One of ``"function"``, ``"class"``, ``"method"``,
|
|
42
|
+
``"file"``.
|
|
43
|
+
name: Symbol or file name (e.g. ``"parse_config"`` or
|
|
44
|
+
``"src/utils.py"``).
|
|
45
|
+
language: Programming language (e.g. ``"python"``).
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
A combined string: NL summary + ``"\\n"`` + key identifiers.
|
|
49
|
+
"""
|
|
50
|
+
if chunk_type == "function":
|
|
51
|
+
nl = self._summarize_function(chunk_text, name, language)
|
|
52
|
+
elif chunk_type == "method":
|
|
53
|
+
nl = self._summarize_method(chunk_text, name, language)
|
|
54
|
+
elif chunk_type == "class":
|
|
55
|
+
nl = self._summarize_class(chunk_text, name, language)
|
|
56
|
+
elif chunk_type == "file":
|
|
57
|
+
nl = self._summarize_file(chunk_text, name, language)
|
|
58
|
+
else:
|
|
59
|
+
nl = f"Code chunk named {name}."
|
|
60
|
+
|
|
61
|
+
identifiers = self._extract_identifiers(chunk_text, chunk_type, name)
|
|
62
|
+
if identifiers:
|
|
63
|
+
return nl + "\n" + identifiers
|
|
64
|
+
return nl
|
|
65
|
+
|
|
66
|
+
# ------------------------------------------------------------------
|
|
67
|
+
# Per-type summarizers
|
|
68
|
+
# ------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
def _summarize_function(
|
|
71
|
+
self, chunk_text: str, name: str, language: str,
|
|
72
|
+
) -> str:
|
|
73
|
+
"""Summarize a function chunk.
|
|
74
|
+
|
|
75
|
+
Target: "Function {name} that takes {params} and returns {return_type}.
|
|
76
|
+
{docstring_first_line}"
|
|
77
|
+
"""
|
|
78
|
+
params = self._extract_params(chunk_text)
|
|
79
|
+
return_type = self._extract_field(chunk_text, "returns")
|
|
80
|
+
docstring = self._extract_field(chunk_text, "docstring") or self._extract_docstring_line(chunk_text)
|
|
81
|
+
|
|
82
|
+
parts = [f"Function {name}"]
|
|
83
|
+
if params:
|
|
84
|
+
parts.append(f"that takes {params}")
|
|
85
|
+
if return_type:
|
|
86
|
+
parts.append(f"and returns {return_type}")
|
|
87
|
+
summary = " ".join(parts) + "."
|
|
88
|
+
if docstring:
|
|
89
|
+
summary += f" {docstring}"
|
|
90
|
+
return summary
|
|
91
|
+
|
|
92
|
+
def _summarize_method(
|
|
93
|
+
self, chunk_text: str, name: str, language: str,
|
|
94
|
+
) -> str:
|
|
95
|
+
"""Summarize a method chunk.
|
|
96
|
+
|
|
97
|
+
Target: "Method {class}.{method} that takes {params} and returns
|
|
98
|
+
{return_type}. {docstring_first_line}"
|
|
99
|
+
"""
|
|
100
|
+
params = self._extract_params(chunk_text)
|
|
101
|
+
return_type = self._extract_field(chunk_text, "returns")
|
|
102
|
+
docstring = self._extract_field(chunk_text, "docstring") or self._extract_docstring_line(chunk_text)
|
|
103
|
+
|
|
104
|
+
parts = [f"Method {name}"]
|
|
105
|
+
if params:
|
|
106
|
+
parts.append(f"that takes {params}")
|
|
107
|
+
if return_type:
|
|
108
|
+
parts.append(f"and returns {return_type}")
|
|
109
|
+
summary = " ".join(parts) + "."
|
|
110
|
+
if docstring:
|
|
111
|
+
summary += f" {docstring}"
|
|
112
|
+
return summary
|
|
113
|
+
|
|
114
|
+
def _summarize_class(
|
|
115
|
+
self, chunk_text: str, name: str, language: str,
|
|
116
|
+
) -> str:
|
|
117
|
+
"""Summarize a class chunk.
|
|
118
|
+
|
|
119
|
+
Target: "Class {name} extending {bases} with methods {method_names}.
|
|
120
|
+
{docstring_first_line}"
|
|
121
|
+
"""
|
|
122
|
+
bases = self._extract_field(chunk_text, "extends")
|
|
123
|
+
methods = self._extract_field(chunk_text, "methods")
|
|
124
|
+
docstring = self._extract_field(chunk_text, "docstring") or self._extract_docstring_line(chunk_text)
|
|
125
|
+
|
|
126
|
+
parts = [f"Class {name}"]
|
|
127
|
+
if bases:
|
|
128
|
+
parts.append(f"extending {bases}")
|
|
129
|
+
if methods:
|
|
130
|
+
parts.append(f"with methods {methods}")
|
|
131
|
+
summary = " ".join(parts) + "."
|
|
132
|
+
if docstring:
|
|
133
|
+
summary += f" {docstring}"
|
|
134
|
+
return summary
|
|
135
|
+
|
|
136
|
+
def _summarize_file(
|
|
137
|
+
self, chunk_text: str, name: str, language: str,
|
|
138
|
+
) -> str:
|
|
139
|
+
"""Summarize a file/module chunk.
|
|
140
|
+
|
|
141
|
+
Target: "Module {name} containing {N} functions and {M} classes.
|
|
142
|
+
{module_docstring_first_line}"
|
|
143
|
+
"""
|
|
144
|
+
defines = self._extract_field(chunk_text, "defines")
|
|
145
|
+
imports = self._extract_field(chunk_text, "imports")
|
|
146
|
+
docstring = self._extract_docstring_line(chunk_text)
|
|
147
|
+
|
|
148
|
+
# Count defined symbols heuristically
|
|
149
|
+
n_funcs = 0
|
|
150
|
+
n_classes = 0
|
|
151
|
+
if defines:
|
|
152
|
+
symbols = [s.strip() for s in defines.split(",")]
|
|
153
|
+
for sym in symbols:
|
|
154
|
+
# Heuristic: class names start uppercase, functions lowercase/underscore
|
|
155
|
+
if sym and sym[0].isupper():
|
|
156
|
+
n_classes += 1
|
|
157
|
+
else:
|
|
158
|
+
n_funcs += 1
|
|
159
|
+
|
|
160
|
+
parts = [f"Module {name}"]
|
|
161
|
+
if n_funcs or n_classes:
|
|
162
|
+
count_parts = []
|
|
163
|
+
if n_funcs:
|
|
164
|
+
count_parts.append(f"{n_funcs} function{'s' if n_funcs != 1 else ''}")
|
|
165
|
+
if n_classes:
|
|
166
|
+
count_parts.append(f"{n_classes} class{'es' if n_classes != 1 else ''}")
|
|
167
|
+
parts.append(f"containing {' and '.join(count_parts)}")
|
|
168
|
+
if imports:
|
|
169
|
+
parts.append(f"importing {imports}")
|
|
170
|
+
summary = " ".join(parts) + "."
|
|
171
|
+
if docstring:
|
|
172
|
+
summary += f" {docstring}"
|
|
173
|
+
return summary
|
|
174
|
+
|
|
175
|
+
# ------------------------------------------------------------------
|
|
176
|
+
# Extraction helpers
|
|
177
|
+
# ------------------------------------------------------------------
|
|
178
|
+
|
|
179
|
+
def _extract_field(self, chunk_text: str, field_name: str) -> str:
|
|
180
|
+
"""Extract a pipe-delimited field from chunk text.
|
|
181
|
+
|
|
182
|
+
Chunk text from ``_chunk_single_file`` uses the format:
|
|
183
|
+
``"function foo | docstring line | params: a, b | returns: int"``
|
|
184
|
+
|
|
185
|
+
This method extracts the value after ``"{field_name}: "`` up to the
|
|
186
|
+
next pipe delimiter (or end of string).
|
|
187
|
+
"""
|
|
188
|
+
# Try "field: value" pattern within pipe-delimited sections
|
|
189
|
+
pattern = rf"(?:^|\|)\s*{re.escape(field_name)}:\s*(.+?)(?:\s*\||$)"
|
|
190
|
+
m = re.search(pattern, chunk_text, re.IGNORECASE)
|
|
191
|
+
if m:
|
|
192
|
+
return m.group(1).strip()
|
|
193
|
+
return ""
|
|
194
|
+
|
|
195
|
+
def _extract_params(self, chunk_text: str) -> str:
|
|
196
|
+
"""Extract parameter names from chunk text."""
|
|
197
|
+
return self._extract_field(chunk_text, "params")
|
|
198
|
+
|
|
199
|
+
def _extract_docstring_line(self, chunk_text: str) -> str:
|
|
200
|
+
"""Extract a docstring first line from chunk text.
|
|
201
|
+
|
|
202
|
+
The chunk text format puts the docstring as the second
|
|
203
|
+
pipe-delimited section (after the "function foo" or "class bar" label)
|
|
204
|
+
if the docstring exists.
|
|
205
|
+
|
|
206
|
+
E.g.: ``"function parse_config | Parse configuration from file | params: path"``
|
|
207
|
+
"""
|
|
208
|
+
parts = [p.strip() for p in chunk_text.split("|")]
|
|
209
|
+
if len(parts) < 2:
|
|
210
|
+
return ""
|
|
211
|
+
# The second part is the docstring IF it doesn't contain a "field:" pattern
|
|
212
|
+
candidate = parts[1]
|
|
213
|
+
if ":" in candidate:
|
|
214
|
+
# Looks like a field (e.g. "params: x"), not a docstring
|
|
215
|
+
# But could also be a docstring like "Parse config: the main entry"
|
|
216
|
+
# Heuristic: if it starts with a known field prefix, skip it
|
|
217
|
+
lower = candidate.lower().lstrip()
|
|
218
|
+
for field_prefix in ("params", "returns", "extends", "methods", "imports", "defines"):
|
|
219
|
+
if lower.startswith(field_prefix + ":"):
|
|
220
|
+
return ""
|
|
221
|
+
# It has a colon but is not a known field — treat as docstring
|
|
222
|
+
return candidate
|
|
223
|
+
|
|
224
|
+
def _extract_identifiers(
|
|
225
|
+
self, chunk_text: str, chunk_type: str, name: str,
|
|
226
|
+
) -> str:
|
|
227
|
+
"""Extract key identifiers for exact-match retrieval.
|
|
228
|
+
|
|
229
|
+
Returns a space-separated string of symbol names, import modules,
|
|
230
|
+
and other identifiers that should be preserved verbatim in the
|
|
231
|
+
embedding input.
|
|
232
|
+
"""
|
|
233
|
+
ids: list[str] = [name]
|
|
234
|
+
|
|
235
|
+
# Split compound names (e.g. "ClassName.method_name")
|
|
236
|
+
for part in name.replace(".", " ").replace("_", " ").split():
|
|
237
|
+
if part and part not in ids:
|
|
238
|
+
ids.append(part)
|
|
239
|
+
|
|
240
|
+
# Extract identifiers from field values
|
|
241
|
+
for field_name in ("params", "defines", "imports", "methods", "extends"):
|
|
242
|
+
field_val = self._extract_field(chunk_text, field_name)
|
|
243
|
+
if field_val:
|
|
244
|
+
for token in re.split(r"[,\s]+", field_val):
|
|
245
|
+
token = token.strip()
|
|
246
|
+
if token and len(token) >= 2 and token not in ids:
|
|
247
|
+
ids.append(token)
|
|
248
|
+
|
|
249
|
+
return " ".join(ids)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
# ---------------------------------------------------------------------------
|
|
253
|
+
# Module-level singleton for performance
|
|
254
|
+
# ---------------------------------------------------------------------------
|
|
255
|
+
|
|
256
|
+
_summarizer: CodeSummarizer | None = None
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def get_summarizer() -> CodeSummarizer:
|
|
260
|
+
"""Return a cached ``CodeSummarizer`` instance."""
|
|
261
|
+
global _summarizer
|
|
262
|
+
if _summarizer is None:
|
|
263
|
+
_summarizer = CodeSummarizer()
|
|
264
|
+
return _summarizer
|