@unerr-ai/unerr 0.2.1 → 0.2.3
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 +36 -45
- package/dist/cli.js +37443 -36022
- package/package.json +2 -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,484 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rust Language Plugin — entity, edge, and import extraction
|
|
3
|
-
* from Tree-sitter AST.
|
|
4
|
-
*
|
|
5
|
-
* Handles: .rs
|
|
6
|
-
*
|
|
7
|
-
* Entity extraction: functions, structs, enums, traits, impl blocks, type aliases
|
|
8
|
-
* Edge extraction: contains, calls, extends (trait bounds), implements (impl Trait)
|
|
9
|
-
* Import resolution: use declarations
|
|
10
|
-
*/
|
|
11
|
-
import { bodyHash, entityKey } from "../entity-key.js";
|
|
12
|
-
function textOf(node) {
|
|
13
|
-
return node?.text ?? "";
|
|
14
|
-
}
|
|
15
|
-
function hasPubVisibility(node) {
|
|
16
|
-
for (const child of node.children) {
|
|
17
|
-
if (child.type === "visibility_modifier")
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
function isAsync(node) {
|
|
23
|
-
for (const child of node.children) {
|
|
24
|
-
if (textOf(child) === "async")
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
function extractDoc(node) {
|
|
30
|
-
let doc = "";
|
|
31
|
-
let sibling = node.previousSibling;
|
|
32
|
-
while (sibling) {
|
|
33
|
-
if (sibling.type === "line_comment" || sibling.type === "block_comment") {
|
|
34
|
-
const text = textOf(sibling);
|
|
35
|
-
if (text.startsWith("///") ||
|
|
36
|
-
text.startsWith("//!") ||
|
|
37
|
-
text.startsWith("/**")) {
|
|
38
|
-
doc = `${text}\n${doc}`;
|
|
39
|
-
sibling = sibling.previousSibling;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
return doc.length > 0 ? doc.trim().slice(0, 500) : null;
|
|
46
|
-
}
|
|
47
|
-
function countParameters(node) {
|
|
48
|
-
const params = node.childForFieldName("parameters");
|
|
49
|
-
if (!params)
|
|
50
|
-
return 0;
|
|
51
|
-
return params.namedChildren.filter((c) => c.type === "parameter" ||
|
|
52
|
-
c.type === "self_parameter" ||
|
|
53
|
-
c.type === "variadic_parameter").length;
|
|
54
|
-
}
|
|
55
|
-
function countParametersExcludingSelf(node) {
|
|
56
|
-
const params = node.childForFieldName("parameters");
|
|
57
|
-
if (!params)
|
|
58
|
-
return 0;
|
|
59
|
-
return params.namedChildren.filter((c) => c.type === "parameter" || c.type === "variadic_parameter").length;
|
|
60
|
-
}
|
|
61
|
-
function hasSelfParam(node) {
|
|
62
|
-
const params = node.childForFieldName("parameters");
|
|
63
|
-
if (!params)
|
|
64
|
-
return false;
|
|
65
|
-
return params.namedChildren.some((c) => c.type === "self_parameter");
|
|
66
|
-
}
|
|
67
|
-
function extractSignature(node, name, kind) {
|
|
68
|
-
if (kind === "class")
|
|
69
|
-
return `struct ${name}`;
|
|
70
|
-
if (kind === "interface")
|
|
71
|
-
return `trait ${name}`;
|
|
72
|
-
if (kind === "enum")
|
|
73
|
-
return `enum ${name}`;
|
|
74
|
-
if (kind === "type")
|
|
75
|
-
return `type ${name}`;
|
|
76
|
-
if (kind === "namespace")
|
|
77
|
-
return `impl ${name}`;
|
|
78
|
-
const params = node.childForFieldName("parameters");
|
|
79
|
-
const returnType = node.childForFieldName("return_type");
|
|
80
|
-
const paramsText = params ? textOf(params) : "()";
|
|
81
|
-
const returnText = returnType ? ` -> ${textOf(returnType)}` : "";
|
|
82
|
-
const asyncPrefix = isAsync(node) ? "async " : "";
|
|
83
|
-
return `${asyncPrefix}fn ${name}${paramsText}${returnText}`;
|
|
84
|
-
}
|
|
85
|
-
function getBody(node) {
|
|
86
|
-
const body = node.childForFieldName("body");
|
|
87
|
-
return body ? textOf(body) : "";
|
|
88
|
-
}
|
|
89
|
-
function getName(node) {
|
|
90
|
-
const nameNode = node.childForFieldName("name");
|
|
91
|
-
if (nameNode)
|
|
92
|
-
return textOf(nameNode);
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
function currentScope(ctx) {
|
|
96
|
-
return ctx.scopeStack.length > 0
|
|
97
|
-
? ctx.scopeStack[ctx.scopeStack.length - 1].key
|
|
98
|
-
: "";
|
|
99
|
-
}
|
|
100
|
-
function addEntity(ctx, node, kind, name, opts = {}) {
|
|
101
|
-
const scope = currentScope(ctx);
|
|
102
|
-
const key = entityKey(ctx.filePath, kind, name, scope);
|
|
103
|
-
const doc = extractDoc(node);
|
|
104
|
-
const body = getBody(node);
|
|
105
|
-
const entity = {
|
|
106
|
-
key,
|
|
107
|
-
kind,
|
|
108
|
-
name,
|
|
109
|
-
file_path: ctx.filePath,
|
|
110
|
-
start_line: node.startPosition.row + 1,
|
|
111
|
-
end_line: node.endPosition.row + 1,
|
|
112
|
-
signature: opts.signature ?? extractSignature(node, name, kind),
|
|
113
|
-
body_hash: bodyHash(body || textOf(node)),
|
|
114
|
-
exported: opts.exported ?? hasPubVisibility(node),
|
|
115
|
-
parent_key: scope || null,
|
|
116
|
-
language: "rust",
|
|
117
|
-
is_async: opts.isAsync ?? false,
|
|
118
|
-
parameter_count: opts.paramCount ?? 0,
|
|
119
|
-
doc,
|
|
120
|
-
};
|
|
121
|
-
if (ctx.inCfgTest) {
|
|
122
|
-
entity.is_test = true;
|
|
123
|
-
}
|
|
124
|
-
ctx.entities.push(entity);
|
|
125
|
-
if (scope) {
|
|
126
|
-
ctx.edges.push({
|
|
127
|
-
from_key: scope,
|
|
128
|
-
to_key: key,
|
|
129
|
-
type: "contains",
|
|
130
|
-
file_path: ctx.filePath,
|
|
131
|
-
line: node.startPosition.row + 1,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
return key;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Check if a node has a #[cfg(test)] attribute.
|
|
138
|
-
* Tree-sitter represents this as an attribute_item sibling before the node.
|
|
139
|
-
*/
|
|
140
|
-
function hasCfgTestAttribute(node) {
|
|
141
|
-
let sibling = node.previousSibling;
|
|
142
|
-
while (sibling) {
|
|
143
|
-
if (sibling.type === "attribute_item") {
|
|
144
|
-
const text = textOf(sibling);
|
|
145
|
-
if (text.includes("cfg") && text.includes("test"))
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
else if (sibling.type !== "line_comment" &&
|
|
149
|
-
sibling.type !== "block_comment") {
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
sibling = sibling.previousSibling;
|
|
153
|
-
}
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
function visitNode(node, ctx) {
|
|
157
|
-
switch (node.type) {
|
|
158
|
-
case "function_item": {
|
|
159
|
-
const name = getName(node);
|
|
160
|
-
if (!name)
|
|
161
|
-
break;
|
|
162
|
-
const inImpl = ctx.scopeStack.length > 0;
|
|
163
|
-
const kind = inImpl && hasSelfParam(node) ? "method" : "function";
|
|
164
|
-
const paramCount = inImpl
|
|
165
|
-
? countParametersExcludingSelf(node)
|
|
166
|
-
: countParameters(node);
|
|
167
|
-
const key = addEntity(ctx, node, kind, name, {
|
|
168
|
-
exported: hasPubVisibility(node),
|
|
169
|
-
isAsync: isAsync(node),
|
|
170
|
-
paramCount,
|
|
171
|
-
});
|
|
172
|
-
ctx.scopeStack.push({ key, name });
|
|
173
|
-
visitChildren(node, ctx);
|
|
174
|
-
ctx.scopeStack.pop();
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
case "struct_item": {
|
|
178
|
-
const name = getName(node);
|
|
179
|
-
if (!name)
|
|
180
|
-
break;
|
|
181
|
-
const key = addEntity(ctx, node, "class", name, {
|
|
182
|
-
exported: hasPubVisibility(node),
|
|
183
|
-
signature: `struct ${name}`,
|
|
184
|
-
});
|
|
185
|
-
ctx.scopeStack.push({ key, name });
|
|
186
|
-
const body = node.childForFieldName("body");
|
|
187
|
-
if (body) {
|
|
188
|
-
for (const field of body.namedChildren) {
|
|
189
|
-
if (field.type === "field_declaration") {
|
|
190
|
-
const fieldName = getName(field);
|
|
191
|
-
if (fieldName) {
|
|
192
|
-
addEntity(ctx, field, "property", fieldName, {
|
|
193
|
-
exported: hasPubVisibility(field),
|
|
194
|
-
signature: fieldName,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
ctx.scopeStack.pop();
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
case "enum_item": {
|
|
204
|
-
const name = getName(node);
|
|
205
|
-
if (!name)
|
|
206
|
-
break;
|
|
207
|
-
addEntity(ctx, node, "enum", name, {
|
|
208
|
-
exported: hasPubVisibility(node),
|
|
209
|
-
signature: `enum ${name}`,
|
|
210
|
-
});
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
case "trait_item": {
|
|
214
|
-
const name = getName(node);
|
|
215
|
-
if (!name)
|
|
216
|
-
break;
|
|
217
|
-
const key = addEntity(ctx, node, "interface", name, {
|
|
218
|
-
exported: hasPubVisibility(node),
|
|
219
|
-
signature: `trait ${name}`,
|
|
220
|
-
});
|
|
221
|
-
const bounds = node.childForFieldName("bounds");
|
|
222
|
-
if (bounds) {
|
|
223
|
-
for (const bound of bounds.namedChildren) {
|
|
224
|
-
const boundName = textOf(bound).split("<")[0]?.trim();
|
|
225
|
-
if (boundName) {
|
|
226
|
-
ctx.edges.push({
|
|
227
|
-
from_key: key,
|
|
228
|
-
to_key: `unresolved:${boundName}`,
|
|
229
|
-
type: "extends",
|
|
230
|
-
file_path: ctx.filePath,
|
|
231
|
-
line: bound.startPosition.row + 1,
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
ctx.scopeStack.push({ key, name });
|
|
237
|
-
visitChildren(node, ctx);
|
|
238
|
-
ctx.scopeStack.pop();
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
case "impl_item": {
|
|
242
|
-
const typeNode = node.childForFieldName("type");
|
|
243
|
-
const traitNode = node.childForFieldName("trait");
|
|
244
|
-
const typeName = typeNode ? textOf(typeNode).split("<")[0]?.trim() : null;
|
|
245
|
-
if (!typeName)
|
|
246
|
-
break;
|
|
247
|
-
const implName = traitNode
|
|
248
|
-
? `${textOf(traitNode).split("<")[0]?.trim()} for ${typeName}`
|
|
249
|
-
: typeName;
|
|
250
|
-
const key = addEntity(ctx, node, "namespace", implName, {
|
|
251
|
-
exported: true,
|
|
252
|
-
signature: `impl ${implName}`,
|
|
253
|
-
});
|
|
254
|
-
if (traitNode) {
|
|
255
|
-
const traitName = textOf(traitNode).split("<")[0]?.trim();
|
|
256
|
-
const typeKey = entityKey(ctx.filePath, "class", typeName, "");
|
|
257
|
-
ctx.edges.push({
|
|
258
|
-
from_key: typeKey,
|
|
259
|
-
to_key: `unresolved:${traitName}`,
|
|
260
|
-
type: "implements",
|
|
261
|
-
file_path: ctx.filePath,
|
|
262
|
-
line: traitNode.startPosition.row + 1,
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
ctx.scopeStack.push({ key, name: implName });
|
|
266
|
-
visitChildren(node, ctx);
|
|
267
|
-
ctx.scopeStack.pop();
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
case "mod_item": {
|
|
271
|
-
const name = getName(node);
|
|
272
|
-
if (!name)
|
|
273
|
-
break;
|
|
274
|
-
// Detect #[cfg(test)] attribute on this module
|
|
275
|
-
const isCfgTest = hasCfgTestAttribute(node);
|
|
276
|
-
const key = addEntity(ctx, node, "namespace", name, {
|
|
277
|
-
exported: hasPubVisibility(node),
|
|
278
|
-
signature: `mod ${name}`,
|
|
279
|
-
});
|
|
280
|
-
const prevCfgTest = ctx.inCfgTest;
|
|
281
|
-
if (isCfgTest)
|
|
282
|
-
ctx.inCfgTest = true;
|
|
283
|
-
ctx.scopeStack.push({ key, name });
|
|
284
|
-
visitChildren(node, ctx);
|
|
285
|
-
ctx.scopeStack.pop();
|
|
286
|
-
ctx.inCfgTest = prevCfgTest;
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
case "type_item": {
|
|
290
|
-
const name = getName(node);
|
|
291
|
-
if (!name)
|
|
292
|
-
break;
|
|
293
|
-
addEntity(ctx, node, "type", name, {
|
|
294
|
-
exported: hasPubVisibility(node),
|
|
295
|
-
signature: `type ${name}`,
|
|
296
|
-
});
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
case "call_expression": {
|
|
300
|
-
const fn = node.childForFieldName("function") ?? node.namedChildren[0];
|
|
301
|
-
if (fn && ctx.scopeStack.length > 0) {
|
|
302
|
-
const calleeName = extractCalleeName(fn);
|
|
303
|
-
if (calleeName) {
|
|
304
|
-
ctx.edges.push({
|
|
305
|
-
from_key: currentScope(ctx),
|
|
306
|
-
to_key: `unresolved:${calleeName}`,
|
|
307
|
-
type: "calls",
|
|
308
|
-
file_path: ctx.filePath,
|
|
309
|
-
line: node.startPosition.row + 1,
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
case "macro_invocation": {
|
|
316
|
-
const macro = node.namedChildren[0];
|
|
317
|
-
if (macro && ctx.scopeStack.length > 0) {
|
|
318
|
-
const macroName = textOf(macro);
|
|
319
|
-
if (macroName) {
|
|
320
|
-
ctx.edges.push({
|
|
321
|
-
from_key: currentScope(ctx),
|
|
322
|
-
to_key: `unresolved:${macroName}`,
|
|
323
|
-
type: "calls",
|
|
324
|
-
file_path: ctx.filePath,
|
|
325
|
-
line: node.startPosition.row + 1,
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
visitChildren(node, ctx);
|
|
333
|
-
}
|
|
334
|
-
function visitChildren(node, ctx) {
|
|
335
|
-
for (const child of node.namedChildren) {
|
|
336
|
-
visitNode(child, ctx);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
function extractCalleeName(node) {
|
|
340
|
-
if (node.type === "identifier")
|
|
341
|
-
return textOf(node);
|
|
342
|
-
if (node.type === "field_expression") {
|
|
343
|
-
const field = node.childForFieldName("field");
|
|
344
|
-
return field ? textOf(field) : null;
|
|
345
|
-
}
|
|
346
|
-
if (node.type === "scoped_identifier") {
|
|
347
|
-
const name = node.childForFieldName("name");
|
|
348
|
-
return name ? textOf(name) : null;
|
|
349
|
-
}
|
|
350
|
-
return null;
|
|
351
|
-
}
|
|
352
|
-
function extractImports(tree, filePath) {
|
|
353
|
-
const imports = [];
|
|
354
|
-
function processUseTree(useTree, basePath, line) {
|
|
355
|
-
if (useTree.type === "use_as_clause") {
|
|
356
|
-
const path = useTree.namedChildren[0];
|
|
357
|
-
const alias = useTree.childForFieldName("alias");
|
|
358
|
-
const source = path ? basePath + textOf(path) : basePath;
|
|
359
|
-
const parts = source.split("::");
|
|
360
|
-
const symbol = parts[parts.length - 1];
|
|
361
|
-
imports.push({
|
|
362
|
-
source: parts.slice(0, -1).join("::"),
|
|
363
|
-
symbols: [symbol],
|
|
364
|
-
isDefault: false,
|
|
365
|
-
isNamespace: false,
|
|
366
|
-
localName: alias ? textOf(alias) : symbol,
|
|
367
|
-
line,
|
|
368
|
-
});
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
if (useTree.type === "use_list") {
|
|
372
|
-
for (const child of useTree.namedChildren) {
|
|
373
|
-
processUseTree(child, basePath, line);
|
|
374
|
-
}
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
if (useTree.type === "use_wildcard") {
|
|
378
|
-
imports.push({
|
|
379
|
-
source: basePath.replace(/::$/, ""),
|
|
380
|
-
symbols: ["*"],
|
|
381
|
-
isDefault: false,
|
|
382
|
-
isNamespace: true,
|
|
383
|
-
line,
|
|
384
|
-
});
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
if (useTree.type === "scoped_use_list") {
|
|
388
|
-
const path = useTree.childForFieldName("path");
|
|
389
|
-
const list = useTree.childForFieldName("list");
|
|
390
|
-
const newBase = path ? `${basePath + textOf(path)}::` : basePath;
|
|
391
|
-
if (list) {
|
|
392
|
-
processUseTree(list, newBase, line);
|
|
393
|
-
}
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
if (useTree.type === "scoped_identifier" || useTree.type === "identifier") {
|
|
397
|
-
const fullPath = basePath + textOf(useTree);
|
|
398
|
-
const parts = fullPath.split("::");
|
|
399
|
-
const symbol = parts[parts.length - 1];
|
|
400
|
-
imports.push({
|
|
401
|
-
source: parts.slice(0, -1).join("::"),
|
|
402
|
-
symbols: [symbol],
|
|
403
|
-
isDefault: false,
|
|
404
|
-
isNamespace: false,
|
|
405
|
-
localName: symbol,
|
|
406
|
-
line,
|
|
407
|
-
});
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
const text = textOf(useTree);
|
|
411
|
-
if (text) {
|
|
412
|
-
const fullPath = basePath + text;
|
|
413
|
-
const parts = fullPath.split("::");
|
|
414
|
-
const symbol = parts[parts.length - 1];
|
|
415
|
-
imports.push({
|
|
416
|
-
source: parts.slice(0, -1).join("::") || fullPath,
|
|
417
|
-
symbols: [symbol],
|
|
418
|
-
isDefault: false,
|
|
419
|
-
isNamespace: false,
|
|
420
|
-
localName: symbol,
|
|
421
|
-
line,
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
function visit(node) {
|
|
426
|
-
if (node.type === "use_declaration") {
|
|
427
|
-
const line = node.startPosition.row + 1;
|
|
428
|
-
const argument = node.namedChildren.find((c) => c.type !== "visibility_modifier" &&
|
|
429
|
-
c.type !== "line_comment" &&
|
|
430
|
-
c.type !== "block_comment");
|
|
431
|
-
if (argument) {
|
|
432
|
-
processUseTree(argument, "", line);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
for (const child of node.namedChildren) {
|
|
436
|
-
visit(child);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
visit(tree.rootNode);
|
|
440
|
-
return imports;
|
|
441
|
-
}
|
|
442
|
-
export const rustPlugin = {
|
|
443
|
-
id: "rust",
|
|
444
|
-
extensions: [".rs"],
|
|
445
|
-
grammarWasmName: "tree-sitter-rust.wasm",
|
|
446
|
-
extract(tree, filePath, source) {
|
|
447
|
-
const ctx = {
|
|
448
|
-
filePath,
|
|
449
|
-
source,
|
|
450
|
-
entities: [],
|
|
451
|
-
edges: [],
|
|
452
|
-
scopeStack: [],
|
|
453
|
-
inCfgTest: false,
|
|
454
|
-
};
|
|
455
|
-
for (const child of tree.rootNode.namedChildren) {
|
|
456
|
-
visitNode(child, ctx);
|
|
457
|
-
}
|
|
458
|
-
return { entities: ctx.entities, edges: ctx.edges };
|
|
459
|
-
},
|
|
460
|
-
resolveImports(tree, filePath) {
|
|
461
|
-
return extractImports(tree, filePath);
|
|
462
|
-
},
|
|
463
|
-
detectCalls(bodyNode) {
|
|
464
|
-
const calls = [];
|
|
465
|
-
function visit(node) {
|
|
466
|
-
if (node.type === "call_expression") {
|
|
467
|
-
const fn = node.childForFieldName("function") ?? node.namedChildren[0];
|
|
468
|
-
const name = fn ? extractCalleeName(fn) : null;
|
|
469
|
-
if (name) {
|
|
470
|
-
calls.push({
|
|
471
|
-
calleeName: name,
|
|
472
|
-
line: node.startPosition.row + 1,
|
|
473
|
-
isAwait: node.parent?.type === "await_expression",
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
for (const child of node.namedChildren) {
|
|
478
|
-
visit(child);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
visit(bodyNode);
|
|
482
|
-
return calls;
|
|
483
|
-
},
|
|
484
|
-
};
|