@unerr-ai/unerr 0.2.0 → 0.2.2
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/README.md +6 -0
- package/dist/cli.js +37236 -35793
- package/package.json +6 -1
- package/dist/behaviors/agent-llm-bridge.js +0 -166
- package/dist/behaviors/architecture-guard.js +0 -256
- package/dist/behaviors/auto-doc.js +0 -247
- package/dist/behaviors/cascade-guard.js +0 -289
- package/dist/behaviors/change-narrative.js +0 -270
- package/dist/behaviors/convention-drift.js +0 -290
- package/dist/behaviors/framework.js +0 -235
- package/dist/behaviors/guard-formatter.js +0 -44
- package/dist/behaviors/incomplete-work.js +0 -270
- package/dist/behaviors/loop-breaker.js +0 -300
- package/dist/behaviors/session-continuity.js +0 -208
- package/dist/commands/branches.js +0 -97
- package/dist/commands/check-commit.js +0 -225
- package/dist/commands/compress-output.js +0 -64
- package/dist/commands/config-verify.js +0 -243
- package/dist/commands/daemon.js +0 -905
- package/dist/commands/dashboard.js +0 -52
- package/dist/commands/debug.js +0 -200
- package/dist/commands/enrich.js +0 -184
- package/dist/commands/exec.js +0 -233
- package/dist/commands/gain.js +0 -156
- package/dist/commands/hook.js +0 -88
- package/dist/commands/index.js +0 -88
- package/dist/commands/init.js +0 -74
- package/dist/commands/install.js +0 -505
- package/dist/commands/learn.js +0 -116
- package/dist/commands/manifest.js +0 -193
- package/dist/commands/rewind.js +0 -103
- package/dist/commands/serve.js +0 -19
- package/dist/commands/setup-wizard.js +0 -414
- package/dist/commands/skills.js +0 -64
- package/dist/commands/stats.js +0 -20
- package/dist/commands/status.js +0 -654
- package/dist/commands/timeline.js +0 -139
- package/dist/commands/uninstall.js +0 -230
- package/dist/components/App.js +0 -109
- package/dist/components/Banner.js +0 -12
- package/dist/components/ConfirmPrompt.js +0 -25
- package/dist/components/DriftSummary.js +0 -23
- package/dist/components/GradeBadge.js +0 -15
- package/dist/components/HealthCard.js +0 -18
- package/dist/components/InkSpinner.js +0 -22
- package/dist/components/InputBox.js +0 -17
- package/dist/components/KeyValue.js +0 -13
- package/dist/components/MessageList.js +0 -14
- package/dist/components/ProgressBar.js +0 -26
- package/dist/components/Section.js +0 -16
- package/dist/components/SessionSummaryCard.js +0 -73
- package/dist/components/StartupDisplay.js +0 -24
- package/dist/components/StatusDashboard.js +0 -57
- package/dist/components/StatusLine.js +0 -8
- package/dist/components/StepLine.js +0 -22
- package/dist/components/Theme.js +0 -20
- package/dist/components/ToolProgress.js +0 -8
- package/dist/components/ViolationList.js +0 -21
- package/dist/components/render.js +0 -13
- package/dist/config/agent-registry.js +0 -237
- package/dist/config/claude-settings-hooks.js +0 -304
- package/dist/config/hook-installer.js +0 -65
- package/dist/config/instruction-writer.js +0 -388
- package/dist/config/mcp-config-writer.js +0 -266
- package/dist/config/settings.js +0 -174
- package/dist/config/tool-detector.js +0 -42
- package/dist/config/value-surfacing.js +0 -119
- package/dist/core/context-assembly.js +0 -108
- package/dist/core/conversation.js +0 -33
- package/dist/core/local-chat-provider.js +0 -475
- package/dist/core/provider-factory.js +0 -55
- package/dist/core/providers.js +0 -90
- package/dist/core/query-engine.js +0 -174
- package/dist/daemon/api.js +0 -312
- package/dist/daemon/autostart.js +0 -119
- package/dist/daemon/bootstrap.js +0 -39
- package/dist/daemon/client.js +0 -164
- package/dist/daemon/detect-ci.js +0 -81
- package/dist/daemon/platform-linux.js +0 -146
- package/dist/daemon/platform-macos.js +0 -134
- package/dist/daemon/platform-windows.js +0 -116
- package/dist/daemon/process-manager.js +0 -299
- package/dist/daemon/protocol.js +0 -23
- package/dist/daemon/registry.js +0 -270
- package/dist/daemon/settings-schema.js +0 -72
- package/dist/daemon/system-health.js +0 -134
- package/dist/daemon/version-checker.js +0 -262
- package/dist/daemon/warm-start.js +0 -223
- package/dist/entrypoints/cli.js +0 -1043
- package/dist/entrypoints/daemon.js +0 -380
- package/dist/entrypoints/repl.js +0 -147
- package/dist/hooks/adapters/claude-code.js +0 -90
- package/dist/hooks/adapters/cline.js +0 -100
- package/dist/hooks/adapters/cursor.js +0 -98
- package/dist/hooks/hook-dedup.js +0 -79
- package/dist/hooks/hook-runner.js +0 -113
- package/dist/hooks/navigation-hooks.js +0 -175
- package/dist/hooks/prompt-hooks.js +0 -63
- package/dist/hooks/shell-hooks.js +0 -47
- package/dist/ignore.js +0 -111
- package/dist/intelligence/approach-suggester.js +0 -61
- package/dist/intelligence/ast-extractor.js +0 -2615
- package/dist/intelligence/ast-worker.js +0 -34
- package/dist/intelligence/background-indexer.js +0 -121
- package/dist/intelligence/blast-radius.js +0 -200
- package/dist/intelligence/community-detection.js +0 -691
- package/dist/intelligence/community-detector.js +0 -184
- package/dist/intelligence/computation-scheduler.js +0 -75
- package/dist/intelligence/confidence-propagation.js +0 -47
- package/dist/intelligence/convention-detector.js +0 -242
- package/dist/intelligence/convention-learner.js +0 -205
- package/dist/intelligence/convention-matcher.js +0 -205
- package/dist/intelligence/cozo-schema.js +0 -376
- package/dist/intelligence/decision-point-detector.js +0 -90
- package/dist/intelligence/deep-dive-tools.js +0 -586
- package/dist/intelligence/durability-scorer.js +0 -84
- package/dist/intelligence/exploration-cost.js +0 -204
- package/dist/intelligence/exploration-pattern-tracker.js +0 -61
- package/dist/intelligence/fact-generator.js +0 -322
- package/dist/intelligence/facts-schema.js +0 -90
- package/dist/intelligence/file-intelligence.js +0 -59
- package/dist/intelligence/graph-holder.js +0 -220
- package/dist/intelligence/graph-temporal-joiner.js +0 -238
- package/dist/intelligence/health-grade.js +0 -423
- package/dist/intelligence/health-grader.js +0 -200
- package/dist/intelligence/health-map-data.js +0 -259
- package/dist/intelligence/import-symbols.js +0 -136
- package/dist/intelligence/incremental-indexer.js +0 -658
- package/dist/intelligence/indexer/centrality.js +0 -62
- package/dist/intelligence/indexer/cfg-context.js +0 -95
- package/dist/intelligence/indexer/confidence.js +0 -34
- package/dist/intelligence/indexer/cross-file-resolver.js +0 -104
- package/dist/intelligence/indexer/edge-repair.js +0 -89
- package/dist/intelligence/indexer/entity-key.js +0 -17
- package/dist/intelligence/indexer/export-map.js +0 -132
- package/dist/intelligence/indexer/git-cochange.js +0 -128
- package/dist/intelligence/indexer/graph-patch.js +0 -147
- package/dist/intelligence/indexer/incremental.js +0 -78
- package/dist/intelligence/indexer/ingest.js +0 -160
- package/dist/intelligence/indexer/language-detect.js +0 -226
- package/dist/intelligence/indexer/metadata.js +0 -63
- package/dist/intelligence/indexer/mutation-tracker.js +0 -79
- package/dist/intelligence/indexer/orchestrator.js +0 -155
- package/dist/intelligence/indexer/plugin-interface.js +0 -31
- package/dist/intelligence/indexer/plugins/csharp.js +0 -440
- package/dist/intelligence/indexer/plugins/go.js +0 -335
- package/dist/intelligence/indexer/plugins/java.js +0 -370
- package/dist/intelligence/indexer/plugins/python.js +0 -358
- package/dist/intelligence/indexer/plugins/regex-fallback.js +0 -82
- package/dist/intelligence/indexer/plugins/ruby.js +0 -290
- package/dist/intelligence/indexer/plugins/rust.js +0 -484
- package/dist/intelligence/indexer/plugins/tier2-generic.js +0 -310
- package/dist/intelligence/indexer/plugins/typescript.js +0 -456
- package/dist/intelligence/indexer/resource-monitor.js +0 -93
- package/dist/intelligence/indexer/scip/decoder.js +0 -253
- package/dist/intelligence/indexer/scip/detector.js +0 -232
- package/dist/intelligence/indexer/scip/downloader.js +0 -427
- package/dist/intelligence/indexer/scip/fallback.js +0 -34
- package/dist/intelligence/indexer/scip/merger.js +0 -109
- package/dist/intelligence/indexer/scip/orchestrator.js +0 -433
- package/dist/intelligence/indexer/scip/runner.js +0 -98
- package/dist/intelligence/indexer/snapshot.js +0 -66
- package/dist/intelligence/indexer/test-detector.js +0 -196
- package/dist/intelligence/indexer/watch-integration.js +0 -61
- package/dist/intelligence/indexer/worker.js +0 -85
- package/dist/intelligence/local-convention-detector.js +0 -437
- package/dist/intelligence/local-embeddings.js +0 -190
- package/dist/intelligence/local-graph.js +0 -1946
- package/dist/intelligence/local-indexer.js +0 -1575
- package/dist/intelligence/local-llm.js +0 -163
- package/dist/intelligence/local-rule-generator.js +0 -154
- package/dist/intelligence/local-snapshot.js +0 -213
- package/dist/intelligence/negative-knowledge.js +0 -103
- package/dist/intelligence/persistent-db.js +0 -85
- package/dist/intelligence/query-router.js +0 -2556
- package/dist/intelligence/risk-classifier.js +0 -116
- package/dist/intelligence/rule-evaluator.js +0 -380
- package/dist/intelligence/rule-generator.js +0 -49
- package/dist/intelligence/search-index.js +0 -173
- package/dist/intelligence/semantic/docstring-extractor.js +0 -67
- package/dist/intelligence/semantic/embedding-store.js +0 -52
- package/dist/intelligence/semantic/enrichment-orchestrator.js +0 -48
- package/dist/intelligence/semantic/git-message-miner.js +0 -114
- package/dist/intelligence/semantic/identifier-tokenizer.js +0 -51
- package/dist/intelligence/semantic/node2vec-embeddings.js +0 -71
- package/dist/intelligence/semantic/node2vec-walks.js +0 -103
- package/dist/intelligence/semantic/path-domain-inference.js +0 -112
- package/dist/intelligence/semantic/similarity-engine.js +0 -60
- package/dist/intelligence/semantic/tfidf-vectors.js +0 -88
- package/dist/intelligence/session-brief-builder.js +0 -159
- package/dist/intelligence/session-context.js +0 -221
- package/dist/intelligence/session-health-monitor.js +0 -211
- package/dist/intelligence/session-narrative.js +0 -197
- package/dist/intelligence/session-pattern-analyzer.js +0 -218
- package/dist/intelligence/signal-scorer.js +0 -390
- package/dist/intelligence/signal-show-store.js +0 -182
- package/dist/intelligence/smart-truncate.js +0 -158
- package/dist/intelligence/subgraph-cache.js +0 -88
- package/dist/intelligence/temporal-facts.js +0 -494
- package/dist/intelligence/token-estimator.js +0 -100
- package/dist/intelligence/tool-injector.js +0 -87
- package/dist/intelligence/tree-sitter-loader.js +0 -71
- package/dist/intelligence/worker-pool.js +0 -116
- package/dist/proxy/arg-validator.js +0 -79
- package/dist/proxy/auto-bootstrap.js +0 -167
- package/dist/proxy/bridge.js +0 -147
- package/dist/proxy/budget-enforcer.js +0 -70
- package/dist/proxy/compression-quality-monitor.js +0 -160
- package/dist/proxy/compression-stats.js +0 -51
- package/dist/proxy/context-rot-detector.js +0 -137
- package/dist/proxy/drift-detector.js +0 -139
- package/dist/proxy/efficiency-tracker.js +0 -79
- package/dist/proxy/fact-ranking.js +0 -154
- package/dist/proxy/format-encoder.js +0 -266
- package/dist/proxy/http-transport.js +0 -90
- package/dist/proxy/lifecycle-actor.js +0 -55
- package/dist/proxy/lifecycle-machine.js +0 -187
- package/dist/proxy/log-tailer.js +0 -265
- package/dist/proxy/model-pricing.js +0 -98
- package/dist/proxy/network-firewall.js +0 -141
- package/dist/proxy/nudge-state.js +0 -93
- package/dist/proxy/output-compressor.js +0 -185
- package/dist/proxy/pid-lock.js +0 -291
- package/dist/proxy/proxy-context.js +0 -11
- package/dist/proxy/proxy.js +0 -2633
- package/dist/proxy/response-enrichment.js +0 -32
- package/dist/proxy/response-envelope.js +0 -313
- package/dist/proxy/session-dedup.js +0 -82
- package/dist/proxy/session-legend.js +0 -30
- package/dist/proxy/session-persistence.js +0 -210
- package/dist/proxy/session-resume.js +0 -94
- package/dist/proxy/session-stats.js +0 -513
- package/dist/proxy/shell-classifier.js +0 -1346
- package/dist/proxy/shell-compression-log.js +0 -93
- package/dist/proxy/shell-compressor.js +0 -390
- package/dist/proxy/shell-graph-boost.js +0 -202
- package/dist/proxy/shell-monitor-map.js +0 -18
- package/dist/proxy/shell-stats.js +0 -54
- package/dist/proxy/shell-strategies/cloud.js +0 -215
- package/dist/proxy/shell-strategies/diff.js +0 -159
- package/dist/proxy/shell-strategies/error-diagnostic.js +0 -796
- package/dist/proxy/shell-strategies/filter-dsl.js +0 -358
- package/dist/proxy/shell-strategies/git-status.js +0 -177
- package/dist/proxy/shell-strategies/key-value.js +0 -193
- package/dist/proxy/shell-strategies/log-text.js +0 -154
- package/dist/proxy/shell-strategies/omni.js +0 -188
- package/dist/proxy/shell-strategies/progress.js +0 -55
- package/dist/proxy/shell-strategies/redact.js +0 -76
- package/dist/proxy/shell-strategies/structured.js +0 -241
- package/dist/proxy/shell-strategies/tabular.js +0 -243
- package/dist/proxy/shell-strategies/test-results-types.js +0 -13
- package/dist/proxy/shell-strategies/test-results.js +0 -784
- package/dist/proxy/shell-strategies/tree-paths.js +0 -144
- package/dist/proxy/shell-strategies/yaml.js +0 -182
- package/dist/proxy/shell-tee.js +0 -111
- package/dist/proxy/signal-dedup.js +0 -171
- package/dist/proxy/startup-renderer.js +0 -158
- package/dist/proxy/task-token-display.js +0 -38
- package/dist/proxy/token-counter.js +0 -61
- package/dist/proxy/tool-clusters.js +0 -273
- package/dist/proxy/tool-definitions.js +0 -525
- package/dist/proxy/transport-mux.js +0 -229
- package/dist/proxy/wire-cap.js +0 -268
- package/dist/rules/developer.mozilla.org.json +0 -9
- package/dist/rules/github.com.json +0 -21
- package/dist/schemas/api/skills.js +0 -19
- package/dist/schemas/common/errors.js +0 -7
- package/dist/schemas/common/headers.js +0 -5
- package/dist/schemas/entities/edge.js +0 -25
- package/dist/schemas/entities/entity.js +0 -22
- package/dist/schemas/entities/rule.js +0 -18
- package/dist/schemas/index.js +0 -14
- package/dist/server/event-bus.js +0 -59
- package/dist/server/http.js +0 -156
- package/dist/server/middleware.js +0 -70
- package/dist/server/routes/drift.js +0 -97
- package/dist/server/routes/intelligence.js +0 -1217
- package/dist/server/routes/reasoning-quality.js +0 -444
- package/dist/server/routes/session.js +0 -86
- package/dist/server/routes/stream.js +0 -120
- package/dist/server/routes/system.js +0 -73
- package/dist/server/routes/temporal.js +0 -170
- package/dist/server/routes/timeline.js +0 -232
- package/dist/server/routes/token-flow.js +0 -403
- package/dist/skills/effectiveness-tracker.js +0 -93
- package/dist/skills/local-pack.js +0 -380
- package/dist/skills/resolver.js +0 -495
- package/dist/state-detector.js +0 -83
- package/dist/timeline/intent-detector.js +0 -263
- package/dist/timeline/loop-miner.js +0 -140
- package/dist/timeline/open-threads.js +0 -49
- package/dist/timeline/signal-reinforcer.js +0 -62
- package/dist/timeline/timeline-bootstrap.js +0 -151
- package/dist/timeline/timeline-store.js +0 -618
- package/dist/tools/coding/bash.js +0 -49
- package/dist/tools/coding/file-edit.js +0 -72
- package/dist/tools/coding/file-outline.js +0 -227
- package/dist/tools/coding/file-read-protocol.js +0 -425
- package/dist/tools/coding/file-read.js +0 -35
- package/dist/tools/coding/file-write.js +0 -43
- package/dist/tools/coding/glob-tool.js +0 -109
- package/dist/tools/coding/grep.js +0 -162
- package/dist/tools/coding/index.js +0 -27
- package/dist/tools/intelligence/index.js +0 -269
- package/dist/tools/intelligence/record-fact.js +0 -48
- package/dist/tools/intelligence/timeline-markers.js +0 -130
- package/dist/tools/registry.js +0 -47
- package/dist/tools/types.js +0 -8
- package/dist/tracking/auto-snapshot-triggers.js +0 -246
- package/dist/tracking/branch-context.js +0 -115
- package/dist/tracking/branch-snapshot.js +0 -217
- package/dist/tracking/causal-bridge.js +0 -317
- package/dist/tracking/circuit-breaker.js +0 -147
- package/dist/tracking/commit-watcher.js +0 -114
- package/dist/tracking/context-ledger.js +0 -119
- package/dist/tracking/correction-detector.js +0 -324
- package/dist/tracking/drift-tracker.js +0 -874
- package/dist/tracking/durability-tracker.js +0 -94
- package/dist/tracking/entity-rewind.js +0 -200
- package/dist/tracking/file-hash-state.js +0 -114
- package/dist/tracking/git-attribution.js +0 -132
- package/dist/tracking/git-trailers.js +0 -171
- package/dist/tracking/intelligence-counter.js +0 -46
- package/dist/tracking/intent-correlator.js +0 -202
- package/dist/tracking/intent-encoder.js +0 -52
- package/dist/tracking/intent-token-tracker.js +0 -159
- package/dist/tracking/ledger-archiver.js +0 -94
- package/dist/tracking/ledger-chains.js +0 -245
- package/dist/tracking/metrics-store.js +0 -361
- package/dist/tracking/native-watcher.js +0 -131
- package/dist/tracking/offline-rewind.js +0 -295
- package/dist/tracking/pending-violations.js +0 -74
- package/dist/tracking/persistence-effectiveness.js +0 -167
- package/dist/tracking/prompt-durability.js +0 -202
- package/dist/tracking/quality-signals.js +0 -213
- package/dist/tracking/redactor.js +0 -73
- package/dist/tracking/rewind-engine.js +0 -161
- package/dist/tracking/session-history.js +0 -128
- package/dist/tracking/session-receipt.js +0 -88
- package/dist/tracking/session-summary-writer.js +0 -157
- package/dist/tracking/shadow-ledger.js +0 -321
- package/dist/tracking/stash-manager.js +0 -258
- package/dist/tracking/timeline-fork.js +0 -213
- package/dist/tracking/timeline.js +0 -69
- package/dist/tracking/token-flow.js +0 -276
- package/dist/tracking/turn-segmenter.js +0 -122
- package/dist/tracking/weekly-accumulator.js +0 -179
- package/dist/tracking/working-snapshots.js +0 -188
- package/dist/tracking/workspace-manifest.js +0 -176
- package/dist/transport/http.js +0 -102
- package/dist/utils/counterfactual.js +0 -65
- package/dist/utils/deep-link.js +0 -34
- package/dist/utils/detect.js +0 -193
- package/dist/utils/exec.js +0 -73
- package/dist/utils/file-logger.js +0 -87
- package/dist/utils/format-error.js +0 -29
- package/dist/utils/git.js +0 -181
- package/dist/utils/log.js +0 -57
- package/dist/utils/logger.js +0 -35
- package/dist/utils/mcp-content-json.js +0 -8
- package/dist/utils/session-logger.js +0 -154
- package/dist/utils/startup-log.js +0 -512
- package/dist/utils/ui.js +0 -56
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Python Language Plugin — entity, edge, and import extraction
|
|
3
|
-
* from Tree-sitter AST.
|
|
4
|
-
*
|
|
5
|
-
* Handles: .py
|
|
6
|
-
*
|
|
7
|
-
* Entity extraction: functions, classes, methods, decorators (unwrapped)
|
|
8
|
-
* Edge extraction: contains, calls, extends
|
|
9
|
-
* Import resolution: import, from...import
|
|
10
|
-
*/
|
|
11
|
-
import { bodyHash, entityKey } from "../entity-key.js";
|
|
12
|
-
function textOf(node) {
|
|
13
|
-
return node?.text ?? "";
|
|
14
|
-
}
|
|
15
|
-
function isAsync(node) {
|
|
16
|
-
for (const child of node.children) {
|
|
17
|
-
if (child.type === "async")
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
return (node.type === "async_function_definition" ||
|
|
21
|
-
node.type === "async_with_statement");
|
|
22
|
-
}
|
|
23
|
-
function extractDoc(node) {
|
|
24
|
-
const body = node.childForFieldName("body");
|
|
25
|
-
if (!body)
|
|
26
|
-
return null;
|
|
27
|
-
const firstStmt = body.namedChildren[0];
|
|
28
|
-
if (firstStmt?.type === "expression_statement") {
|
|
29
|
-
const expr = firstStmt.namedChildren[0];
|
|
30
|
-
if (expr?.type === "string" || expr?.type === "concatenated_string") {
|
|
31
|
-
const text = textOf(expr);
|
|
32
|
-
return text.slice(0, 500);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
function countParameters(node) {
|
|
38
|
-
const params = node.childForFieldName("parameters");
|
|
39
|
-
if (!params)
|
|
40
|
-
return 0;
|
|
41
|
-
return params.namedChildren.filter((c) => c.type === "identifier" ||
|
|
42
|
-
c.type === "default_parameter" ||
|
|
43
|
-
c.type === "typed_parameter" ||
|
|
44
|
-
c.type === "typed_default_parameter" ||
|
|
45
|
-
c.type === "list_splat_pattern" ||
|
|
46
|
-
c.type === "dictionary_splat_pattern").length;
|
|
47
|
-
}
|
|
48
|
-
function countParametersExcludingSelf(node) {
|
|
49
|
-
const params = node.childForFieldName("parameters");
|
|
50
|
-
if (!params)
|
|
51
|
-
return 0;
|
|
52
|
-
return params.namedChildren.filter((c) => {
|
|
53
|
-
if (c.type !== "identifier" &&
|
|
54
|
-
c.type !== "default_parameter" &&
|
|
55
|
-
c.type !== "typed_parameter" &&
|
|
56
|
-
c.type !== "typed_default_parameter" &&
|
|
57
|
-
c.type !== "list_splat_pattern" &&
|
|
58
|
-
c.type !== "dictionary_splat_pattern")
|
|
59
|
-
return false;
|
|
60
|
-
const nameNode = c.type === "identifier"
|
|
61
|
-
? c
|
|
62
|
-
: (c.childForFieldName("name") ?? c.namedChildren[0] ?? null);
|
|
63
|
-
const name = textOf(nameNode);
|
|
64
|
-
return name !== "self" && name !== "cls";
|
|
65
|
-
}).length;
|
|
66
|
-
}
|
|
67
|
-
function extractSignature(node, name) {
|
|
68
|
-
const params = node.childForFieldName("parameters");
|
|
69
|
-
const returnType = node.childForFieldName("return_type");
|
|
70
|
-
const paramsText = params ? textOf(params) : "()";
|
|
71
|
-
const returnText = returnType ? ` -> ${textOf(returnType)}` : "";
|
|
72
|
-
return `def ${name}${paramsText}${returnText}`;
|
|
73
|
-
}
|
|
74
|
-
function getBody(node) {
|
|
75
|
-
const body = node.childForFieldName("body");
|
|
76
|
-
return body ? textOf(body) : "";
|
|
77
|
-
}
|
|
78
|
-
function getName(node) {
|
|
79
|
-
const nameNode = node.childForFieldName("name");
|
|
80
|
-
if (nameNode)
|
|
81
|
-
return textOf(nameNode);
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
function isTopLevel(node) {
|
|
85
|
-
let parent = node.parent;
|
|
86
|
-
while (parent) {
|
|
87
|
-
if (parent.type === "module")
|
|
88
|
-
return true;
|
|
89
|
-
if (parent.type === "class_definition" ||
|
|
90
|
-
parent.type === "function_definition" ||
|
|
91
|
-
parent.type === "async_function_definition")
|
|
92
|
-
return false;
|
|
93
|
-
parent = parent.parent;
|
|
94
|
-
}
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
function currentScope(ctx) {
|
|
98
|
-
return ctx.scopeStack.length > 0
|
|
99
|
-
? ctx.scopeStack[ctx.scopeStack.length - 1].key
|
|
100
|
-
: "";
|
|
101
|
-
}
|
|
102
|
-
function addEntity(ctx, node, kind, name, opts = {}) {
|
|
103
|
-
const scope = currentScope(ctx);
|
|
104
|
-
const key = entityKey(ctx.filePath, kind, name, scope);
|
|
105
|
-
const doc = extractDoc(node);
|
|
106
|
-
const body = getBody(node);
|
|
107
|
-
ctx.entities.push({
|
|
108
|
-
key,
|
|
109
|
-
kind,
|
|
110
|
-
name,
|
|
111
|
-
file_path: ctx.filePath,
|
|
112
|
-
start_line: node.startPosition.row + 1,
|
|
113
|
-
end_line: node.endPosition.row + 1,
|
|
114
|
-
signature: opts.signature ?? extractSignature(node, name),
|
|
115
|
-
body_hash: bodyHash(body || textOf(node)),
|
|
116
|
-
exported: opts.exported ?? true,
|
|
117
|
-
parent_key: scope || null,
|
|
118
|
-
language: "python",
|
|
119
|
-
is_async: opts.isAsync ?? false,
|
|
120
|
-
parameter_count: opts.paramCount ?? 0,
|
|
121
|
-
doc,
|
|
122
|
-
});
|
|
123
|
-
if (scope) {
|
|
124
|
-
ctx.edges.push({
|
|
125
|
-
from_key: scope,
|
|
126
|
-
to_key: key,
|
|
127
|
-
type: "contains",
|
|
128
|
-
file_path: ctx.filePath,
|
|
129
|
-
line: node.startPosition.row + 1,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
return key;
|
|
133
|
-
}
|
|
134
|
-
function unwrapDecorated(node) {
|
|
135
|
-
if (node.type === "decorated_definition") {
|
|
136
|
-
const definition = node.childForFieldName("definition") ??
|
|
137
|
-
node.namedChildren[node.namedChildren.length - 1];
|
|
138
|
-
if (definition)
|
|
139
|
-
return definition;
|
|
140
|
-
}
|
|
141
|
-
return node;
|
|
142
|
-
}
|
|
143
|
-
function visitNode(node, ctx) {
|
|
144
|
-
const actualNode = unwrapDecorated(node);
|
|
145
|
-
switch (actualNode.type) {
|
|
146
|
-
case "function_definition":
|
|
147
|
-
case "async_function_definition": {
|
|
148
|
-
const name = getName(actualNode);
|
|
149
|
-
if (!name)
|
|
150
|
-
break;
|
|
151
|
-
const inClass = ctx.scopeStack.length > 0;
|
|
152
|
-
const kind = inClass ? "method" : "function";
|
|
153
|
-
const asyncFn = actualNode.type === "async_function_definition" || isAsync(actualNode);
|
|
154
|
-
const paramCount = inClass
|
|
155
|
-
? countParametersExcludingSelf(actualNode)
|
|
156
|
-
: countParameters(actualNode);
|
|
157
|
-
const key = addEntity(ctx, node, kind, name, {
|
|
158
|
-
exported: true,
|
|
159
|
-
isAsync: asyncFn,
|
|
160
|
-
paramCount,
|
|
161
|
-
signature: extractSignature(actualNode, name),
|
|
162
|
-
});
|
|
163
|
-
ctx.scopeStack.push({ key, name });
|
|
164
|
-
visitChildren(actualNode, ctx);
|
|
165
|
-
ctx.scopeStack.pop();
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
case "class_definition": {
|
|
169
|
-
const name = getName(actualNode);
|
|
170
|
-
if (!name)
|
|
171
|
-
break;
|
|
172
|
-
const key = addEntity(ctx, node, "class", name, {
|
|
173
|
-
exported: true,
|
|
174
|
-
signature: `class ${name}`,
|
|
175
|
-
});
|
|
176
|
-
const superclasses = actualNode.childForFieldName("superclasses");
|
|
177
|
-
if (superclasses) {
|
|
178
|
-
for (const arg of superclasses.namedChildren) {
|
|
179
|
-
const baseName = textOf(arg).split("(")[0]?.trim();
|
|
180
|
-
if (baseName && baseName !== "object") {
|
|
181
|
-
ctx.edges.push({
|
|
182
|
-
from_key: key,
|
|
183
|
-
to_key: `unresolved:${baseName}`,
|
|
184
|
-
type: "extends",
|
|
185
|
-
file_path: ctx.filePath,
|
|
186
|
-
line: arg.startPosition.row + 1,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
ctx.scopeStack.push({ key, name });
|
|
192
|
-
visitChildren(actualNode, ctx);
|
|
193
|
-
ctx.scopeStack.pop();
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
case "call": {
|
|
197
|
-
const fn = actualNode.childForFieldName("function") ?? actualNode.namedChildren[0];
|
|
198
|
-
if (fn && ctx.scopeStack.length > 0) {
|
|
199
|
-
const calleeName = extractCalleeName(fn);
|
|
200
|
-
if (calleeName) {
|
|
201
|
-
ctx.edges.push({
|
|
202
|
-
from_key: currentScope(ctx),
|
|
203
|
-
to_key: `unresolved:${calleeName}`,
|
|
204
|
-
type: "calls",
|
|
205
|
-
file_path: ctx.filePath,
|
|
206
|
-
line: actualNode.startPosition.row + 1,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
visitChildren(node, ctx);
|
|
214
|
-
}
|
|
215
|
-
function visitChildren(node, ctx) {
|
|
216
|
-
for (const child of node.namedChildren) {
|
|
217
|
-
visitNode(child, ctx);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function extractCalleeName(node) {
|
|
221
|
-
if (node.type === "identifier")
|
|
222
|
-
return textOf(node);
|
|
223
|
-
if (node.type === "attribute") {
|
|
224
|
-
const attr = node.childForFieldName("attribute");
|
|
225
|
-
return attr ? textOf(attr) : null;
|
|
226
|
-
}
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
function extractImports(tree, filePath) {
|
|
230
|
-
const imports = [];
|
|
231
|
-
function visit(node) {
|
|
232
|
-
if (node.type === "import_statement") {
|
|
233
|
-
const line = node.startPosition.row + 1;
|
|
234
|
-
for (const child of node.namedChildren) {
|
|
235
|
-
if (child.type === "dotted_name") {
|
|
236
|
-
const moduleName = textOf(child);
|
|
237
|
-
imports.push({
|
|
238
|
-
source: moduleName,
|
|
239
|
-
symbols: [moduleName.split(".").pop()],
|
|
240
|
-
isDefault: true,
|
|
241
|
-
isNamespace: false,
|
|
242
|
-
localName: moduleName.split(".").pop(),
|
|
243
|
-
line,
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
else if (child.type === "aliased_import") {
|
|
247
|
-
const name = child.childForFieldName("name");
|
|
248
|
-
const alias = child.childForFieldName("alias");
|
|
249
|
-
if (name) {
|
|
250
|
-
imports.push({
|
|
251
|
-
source: textOf(name),
|
|
252
|
-
symbols: [textOf(name)],
|
|
253
|
-
isDefault: true,
|
|
254
|
-
isNamespace: false,
|
|
255
|
-
localName: alias ? textOf(alias) : undefined,
|
|
256
|
-
line,
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
else if (node.type === "import_from_statement") {
|
|
263
|
-
const line = node.startPosition.row + 1;
|
|
264
|
-
const moduleNode = node.childForFieldName("module_name") ??
|
|
265
|
-
node.namedChildren.find((c) => c.type === "dotted_name" || c.type === "relative_import");
|
|
266
|
-
const source = moduleNode ? textOf(moduleNode) : ".";
|
|
267
|
-
const symbols = [];
|
|
268
|
-
let isWildcard = false;
|
|
269
|
-
for (const child of node.namedChildren) {
|
|
270
|
-
if (child.type === "dotted_name" && child !== moduleNode) {
|
|
271
|
-
symbols.push(textOf(child));
|
|
272
|
-
}
|
|
273
|
-
else if (child.type === "aliased_import") {
|
|
274
|
-
const name = child.childForFieldName("name");
|
|
275
|
-
if (name)
|
|
276
|
-
symbols.push(textOf(name));
|
|
277
|
-
}
|
|
278
|
-
else if (child.type === "wildcard_import") {
|
|
279
|
-
isWildcard = true;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
if (isWildcard) {
|
|
283
|
-
imports.push({
|
|
284
|
-
source,
|
|
285
|
-
symbols: ["*"],
|
|
286
|
-
isDefault: false,
|
|
287
|
-
isNamespace: true,
|
|
288
|
-
line,
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
else if (symbols.length > 0) {
|
|
292
|
-
imports.push({
|
|
293
|
-
source,
|
|
294
|
-
symbols,
|
|
295
|
-
isDefault: false,
|
|
296
|
-
isNamespace: false,
|
|
297
|
-
line,
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
imports.push({
|
|
302
|
-
source,
|
|
303
|
-
symbols: [],
|
|
304
|
-
isDefault: false,
|
|
305
|
-
isNamespace: false,
|
|
306
|
-
line,
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
for (const child of node.namedChildren) {
|
|
311
|
-
visit(child);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
visit(tree.rootNode);
|
|
315
|
-
return imports;
|
|
316
|
-
}
|
|
317
|
-
export const pythonPlugin = {
|
|
318
|
-
id: "python",
|
|
319
|
-
extensions: [".py"],
|
|
320
|
-
grammarWasmName: "tree-sitter-python.wasm",
|
|
321
|
-
extract(tree, filePath, source) {
|
|
322
|
-
const ctx = {
|
|
323
|
-
filePath,
|
|
324
|
-
source,
|
|
325
|
-
entities: [],
|
|
326
|
-
edges: [],
|
|
327
|
-
scopeStack: [],
|
|
328
|
-
};
|
|
329
|
-
for (const child of tree.rootNode.namedChildren) {
|
|
330
|
-
visitNode(child, ctx);
|
|
331
|
-
}
|
|
332
|
-
return { entities: ctx.entities, edges: ctx.edges };
|
|
333
|
-
},
|
|
334
|
-
resolveImports(tree, filePath) {
|
|
335
|
-
return extractImports(tree, filePath);
|
|
336
|
-
},
|
|
337
|
-
detectCalls(bodyNode) {
|
|
338
|
-
const calls = [];
|
|
339
|
-
function visit(node) {
|
|
340
|
-
if (node.type === "call") {
|
|
341
|
-
const fn = node.childForFieldName("function") ?? node.namedChildren[0];
|
|
342
|
-
const name = fn ? extractCalleeName(fn) : null;
|
|
343
|
-
if (name) {
|
|
344
|
-
calls.push({
|
|
345
|
-
calleeName: name,
|
|
346
|
-
line: node.startPosition.row + 1,
|
|
347
|
-
isAwait: node.parent?.type === "await",
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
for (const child of node.namedChildren) {
|
|
352
|
-
visit(child);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
visit(bodyNode);
|
|
356
|
-
return calls;
|
|
357
|
-
},
|
|
358
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tier-3 Regex Fallback Plugin — basic entity detection for unsupported languages.
|
|
3
|
-
*
|
|
4
|
-
* Produces file-level entities and basic function/class detection using
|
|
5
|
-
* language-agnostic regex patterns. Lower confidence than tree-sitter,
|
|
6
|
-
* but provides baseline coverage for any text file with code-like structure.
|
|
7
|
-
*/
|
|
8
|
-
import { bodyHash, entityKey } from "../entity-key.js";
|
|
9
|
-
const FUNCTION_PATTERN = /(?:^|\n)\s*(?:export\s+)?(?:async\s+)?(?:function|def|func|fn|fun|sub|proc)\s+(\w+)/gm;
|
|
10
|
-
const CLASS_PATTERN = /(?:^|\n)\s*(?:export\s+)?(?:abstract\s+)?(?:class|struct|interface|trait|enum|module|object)\s+(\w+)/gm;
|
|
11
|
-
function extractWithRegex(source, filePath, language) {
|
|
12
|
-
const entities = [];
|
|
13
|
-
const edges = [];
|
|
14
|
-
const lines = source.split("\n");
|
|
15
|
-
let match;
|
|
16
|
-
FUNCTION_PATTERN.lastIndex = 0;
|
|
17
|
-
match = FUNCTION_PATTERN.exec(source);
|
|
18
|
-
while (match !== null) {
|
|
19
|
-
const name = match[1];
|
|
20
|
-
const lineNum = source.slice(0, match.index).split("\n").length;
|
|
21
|
-
entities.push({
|
|
22
|
-
key: entityKey(filePath, "function", name, ""),
|
|
23
|
-
kind: "function",
|
|
24
|
-
name,
|
|
25
|
-
file_path: filePath,
|
|
26
|
-
start_line: lineNum,
|
|
27
|
-
end_line: lineNum + 5,
|
|
28
|
-
signature: `${name}()`,
|
|
29
|
-
body_hash: bodyHash(match[0]),
|
|
30
|
-
exported: match[0].includes("export"),
|
|
31
|
-
parent_key: null,
|
|
32
|
-
language,
|
|
33
|
-
is_async: match[0].includes("async"),
|
|
34
|
-
parameter_count: 0,
|
|
35
|
-
doc: null,
|
|
36
|
-
});
|
|
37
|
-
match = FUNCTION_PATTERN.exec(source);
|
|
38
|
-
}
|
|
39
|
-
CLASS_PATTERN.lastIndex = 0;
|
|
40
|
-
match = CLASS_PATTERN.exec(source);
|
|
41
|
-
while (match !== null) {
|
|
42
|
-
const name = match[1];
|
|
43
|
-
const lineNum = source.slice(0, match.index).split("\n").length;
|
|
44
|
-
entities.push({
|
|
45
|
-
key: entityKey(filePath, "class", name, ""),
|
|
46
|
-
kind: "class",
|
|
47
|
-
name,
|
|
48
|
-
file_path: filePath,
|
|
49
|
-
start_line: lineNum,
|
|
50
|
-
end_line: lineNum + 10,
|
|
51
|
-
signature: `class ${name}`,
|
|
52
|
-
body_hash: bodyHash(match[0]),
|
|
53
|
-
exported: match[0].includes("export"),
|
|
54
|
-
parent_key: null,
|
|
55
|
-
language,
|
|
56
|
-
is_async: false,
|
|
57
|
-
parameter_count: 0,
|
|
58
|
-
doc: null,
|
|
59
|
-
});
|
|
60
|
-
match = CLASS_PATTERN.exec(source);
|
|
61
|
-
}
|
|
62
|
-
return { entities, edges };
|
|
63
|
-
}
|
|
64
|
-
export const regexFallbackPlugin = {
|
|
65
|
-
id: "regex-fallback",
|
|
66
|
-
extensions: [],
|
|
67
|
-
grammarWasmName: "",
|
|
68
|
-
extract(_tree, filePath, source) {
|
|
69
|
-
const ext = filePath.slice(filePath.lastIndexOf(".") + 1);
|
|
70
|
-
return extractWithRegex(source, filePath, ext);
|
|
71
|
-
},
|
|
72
|
-
resolveImports() {
|
|
73
|
-
return [];
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Standalone extraction without tree-sitter (for files with no grammar).
|
|
78
|
-
*/
|
|
79
|
-
export function regexExtract(source, filePath) {
|
|
80
|
-
const ext = filePath.slice(filePath.lastIndexOf(".") + 1);
|
|
81
|
-
return extractWithRegex(source, filePath, ext);
|
|
82
|
-
}
|