sneakoscope 7.3.0 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -10
- package/crates/sks-core/Cargo.lock +1 -1
- package/crates/sks-core/Cargo.toml +1 -1
- package/dist/cli/codex-app-command.js +1 -1
- package/dist/cli/command-manifest-lite.js +4 -1
- package/dist/cli/command-registry.js +2 -0
- package/dist/cli/install-helpers-codex-lb-chain.js +42 -0
- package/dist/cli/install-helpers-codex-lb-config.js +114 -9
- package/dist/cli/install-helpers-install-support.js +6 -16
- package/dist/cli/install-helpers.js +788 -600
- package/dist/cli/router.js +30 -2
- package/dist/commands/codex-app.js +37 -1
- package/dist/commands/codex-lb.js +491 -300
- package/dist/config/skills-manifest.json +57 -71
- package/dist/core/align/align-route.js +127 -0
- package/dist/core/codex-app/codex-app-fast-ui-repair.js +8 -4
- package/dist/core/codex-app/codex-app-restart.js +83 -0
- package/dist/core/codex-app/codex-app-ui-state-snapshot.js +8 -4
- package/dist/core/codex-app/desktop-routing-snapshot.js +1 -1
- package/dist/core/codex-app/menubar/constants.js +5 -0
- package/dist/core/codex-app/menubar/generation-transaction-journal.js +1 -3
- package/dist/core/codex-app/menubar/installer.js +18 -0
- package/dist/core/codex-app/multi-provider-router.js +22 -10
- package/dist/core/codex-app/openrouter-activate.js +26 -1
- package/dist/core/codex-app.js +118 -26
- package/dist/core/codex-control/codex-app-server-runtime-env.js +86 -0
- package/dist/core/codex-control/codex-app-server-v2-client.js +78 -8
- package/dist/core/codex-control/codex-task-runner.js +2 -2
- package/dist/core/codex-lb/capability-runner.js +204 -0
- package/dist/core/codex-lb/capability-types.js +1 -0
- package/dist/core/codex-lb/codex-lb-env.js +9 -13
- package/dist/core/codex-lb/codex-lb-setup.js +45 -8
- package/dist/core/codex-lb/codex-lb-tool-catalog.js +52 -74
- package/dist/core/codex-lb/codex-lb-tool-output-recovery.js +1 -1
- package/dist/core/codex-lb/desktop-auth-invariant.js +185 -0
- package/dist/core/codex-lb/desktop-bridge/client.js +34 -0
- package/dist/core/codex-lb/desktop-bridge/header-policy.js +106 -0
- package/dist/core/codex-lb/desktop-bridge/http-forward.js +101 -0
- package/dist/core/codex-lb/desktop-bridge/index.js +10 -0
- package/dist/core/codex-lb/desktop-bridge/launchd.js +81 -0
- package/dist/core/codex-lb/desktop-bridge/location-rewrite.js +27 -0
- package/dist/core/codex-lb/desktop-bridge/security.js +274 -0
- package/dist/core/codex-lb/desktop-bridge/server.js +179 -0
- package/dist/core/codex-lb/desktop-bridge/state.js +119 -0
- package/dist/core/codex-lb/desktop-bridge/types.js +16 -0
- package/dist/core/codex-lb/desktop-bridge/websocket-forward.js +151 -0
- package/dist/core/codex-lb/desktop-center-credentials.js +189 -0
- package/dist/core/codex-lb/desktop-controller.js +1410 -0
- package/dist/core/codex-lb/desktop-mode.js +32 -0
- package/dist/core/codex-lb/desktop-real-evidence.js +168 -0
- package/dist/core/codex-lb/desktop-service.js +613 -0
- package/dist/core/codex-lb/legacy-migration.js +575 -0
- package/dist/core/codex-lb/migration-receipt.js +246 -0
- package/dist/core/codex-lb/probes/auxiliary-surfaces-probe.js +60 -0
- package/dist/core/codex-lb/probes/bridge-probe.js +75 -0
- package/dist/core/codex-lb/probes/catalog-probe.js +128 -0
- package/dist/core/codex-lb/probes/computer-use-probe.js +50 -0
- package/dist/core/codex-lb/probes/image-generation-probe.js +47 -0
- package/dist/core/codex-lb/probes/probe-evidence.js +39 -0
- package/dist/core/codex-lb/probes/voice-realtime-probe.js +44 -0
- package/dist/core/codex-lb/trusted-deep-evidence.js +403 -0
- package/dist/core/codex-native/core-skill-manifest.js +22 -6
- package/dist/core/codex-runtime/codex-desktop-config-policy.js +2 -1
- package/dist/core/commands/align-command.js +220 -0
- package/dist/core/commands/image-ux-review-command.js +280 -68
- package/dist/core/commands/naruto-command.js +257 -8
- package/dist/core/commands/ppt-command.js +2 -2
- package/dist/core/commands/telegram-command.js +402 -34
- package/dist/core/commands/triwiki-command.js +11 -1
- package/dist/core/commands/triwiki-graph-command.js +160 -0
- package/dist/core/commands/wiki-command.js +100 -20
- package/dist/core/doctor/skill-legacy-surface.js +1 -3
- package/dist/core/errors/message.js +3 -0
- package/dist/core/evidence/evidence-freshness.js +14 -0
- package/dist/core/feature-fixtures.js +9 -1
- package/dist/core/feature-registry.js +5 -3
- package/dist/core/fsx.js +7 -3
- package/dist/core/hooks-runtime/codex-commit-hooks-selftest.js +82 -0
- package/dist/core/hooks-runtime/context-graph-freshness-preflight.js +113 -0
- package/dist/core/hooks-runtime/hook-context.js +15 -2
- package/dist/core/hooks-runtime/managed-skill-generation-heal.js +46 -0
- package/dist/core/hooks-runtime/naruto-terminal-finalization.js +1 -0
- package/dist/core/hooks-runtime/official-subagent-lifecycle.js +1 -1
- package/dist/core/hooks-runtime/tool-output-quarantine.js +1 -1
- package/dist/core/hooks-runtime.js +33 -89
- package/dist/core/image-ux-review/callout-extraction.js +6 -0
- package/dist/core/image-ux-review/imagegen-adapter.js +64 -23
- package/dist/core/image-ux-review/real-callout-extractor.js +1 -0
- package/dist/core/image-ux-review.js +230 -12
- package/dist/core/imagegen/codex-lb-imagegen-target.js +21 -7
- package/dist/core/imagegen/imagegen-capability.js +10 -4
- package/dist/core/imagegen/require-imagegen.js +29 -5
- package/dist/core/init/skills.js +25 -13
- package/dist/core/init.js +1 -1
- package/dist/core/install/installed-package-smoke.js +157 -4
- package/dist/core/managed-assets/managed-assets-manifest.js +2 -1
- package/dist/core/managed-path-safety.js +8 -10
- package/dist/core/mcp-config/backup.js +2 -4
- package/dist/core/mcp-config/config-reader.js +2 -4
- package/dist/core/mcp-config/scope.js +3 -5
- package/dist/core/naruto/context-graph-advisor-scope.js +242 -0
- package/dist/core/naruto/context-graph-advisor.js +0 -0
- package/dist/core/perf/release-latency-slo.js +12 -6
- package/dist/core/pipeline-internals/runtime-core.js +78 -0
- package/dist/core/pipeline-internals/runtime-gates.js +5 -2
- package/dist/core/policy/latest-version-guidance.js +113 -0
- package/dist/core/ppt.js +8 -8
- package/dist/core/preflight/parallel-preflight-engine.js +1 -1
- package/dist/core/proof/auto-finalize.js +98 -6
- package/dist/core/proof/route-proof-gate.js +12 -1
- package/dist/core/proof/route-proof-policy.js +8 -8
- package/dist/core/release/gate-manifest.js +32 -1
- package/dist/core/release/npm-stage-contract.js +21 -0
- package/dist/core/release/package-size-budget.js +2 -2
- package/dist/core/release/release-gate-contract.js +5 -0
- package/dist/core/release/release-proof-io.js +1 -3
- package/dist/core/release/release-real-contract.js +5 -4
- package/dist/core/release/release-stamp-proof.js +1 -3
- package/dist/core/release/stage-publish.js +27 -0
- package/dist/core/remote/audit-idempotency.js +50 -18
- package/dist/core/remote/codex-public-activity.js +283 -0
- package/dist/core/remote/index.js +1 -0
- package/dist/core/remote/ssh-worker-client.js +4 -1
- package/dist/core/remote/worker.js +206 -27
- package/dist/core/research/research-adversarial-review.js +1 -3
- package/dist/core/research/research-claim-synthesizer.js +1 -3
- package/dist/core/research/research-falsification-runner.js +1 -3
- package/dist/core/research/research-source-evidence.js +1 -3
- package/dist/core/responses-stream.js +65 -19
- package/dist/core/routes/constants.js +1 -1
- package/dist/core/routes/design-policy.js +7 -2
- package/dist/core/routes/dollar-manifest-lite.js +2 -4
- package/dist/core/routes/evidence.js +1 -1
- package/dist/core/routes.js +30 -10
- package/dist/core/safety/command-contract/contracts.js +2 -0
- package/dist/core/safety/command-contract/types.js +1 -1
- package/dist/core/search/context-graph-seeds.js +205 -0
- package/dist/core/search/context.js +0 -0
- package/dist/core/search/provider.js +2 -2
- package/dist/core/secret-redaction.js +6 -0
- package/dist/core/subagents/naruto-help-contract.js +2 -1
- package/dist/core/subagents/naruto-host-credentials.js +161 -0
- package/dist/core/subagents/official-subagent-preparation.js +4 -1
- package/dist/core/subagents/official-subagent-prompt.js +44 -2
- package/dist/core/subagents/official-subagent-runner.js +26 -8
- package/dist/core/subagents/triwiki-attention.js +135 -123
- package/dist/core/telegram/bot-api.js +85 -10
- package/dist/core/telegram/center-snapshot.js +718 -0
- package/dist/core/telegram/config.js +158 -31
- package/dist/core/telegram/hub.js +288 -33
- package/dist/core/telegram/index.js +2 -0
- package/dist/core/telegram/ingress-spool.js +419 -0
- package/dist/core/telegram/ledgers.js +188 -29
- package/dist/core/telegram/messages.js +26 -6
- package/dist/core/telegram/owner-lock.js +10 -7
- package/dist/core/telegram/runtime-projection.js +38 -3
- package/dist/core/telegram/runtime.js +298 -63
- package/dist/core/telegram/service.js +137 -8
- package/dist/core/telegram/setup.js +291 -73
- package/dist/core/text/strings.js +3 -0
- package/dist/core/triwiki/code-pack.js +12 -120
- package/dist/core/triwiki/context-graph/compiler/cache-key.js +277 -0
- package/dist/core/triwiki/context-graph/compiler/extract.js +104 -0
- package/dist/core/triwiki/context-graph/compiler/freshness.js +108 -0
- package/dist/core/triwiki/context-graph/compiler/index.js +237 -0
- package/dist/core/triwiki/context-graph/compiler/merge.js +0 -0
- package/dist/core/triwiki/context-graph/compiler/serialize.js +115 -0
- package/dist/core/triwiki/context-graph/contracts.js +236 -0
- package/dist/core/triwiki/context-graph/extractors/code/builders.js +150 -0
- package/dist/core/triwiki/context-graph/extractors/code/declarations.js +161 -0
- package/dist/core/triwiki/context-graph/extractors/code/index.js +265 -0
- package/dist/core/triwiki/context-graph/extractors/code/inventory.js +237 -0
- package/dist/core/triwiki/context-graph/extractors/code/module-graph.js +252 -0
- package/dist/core/triwiki/context-graph/extractors/code/modules.js +79 -0
- package/dist/core/triwiki/context-graph/extractors/code/references.js +184 -0
- package/dist/core/triwiki/context-graph/extractors/code/selection.js +100 -0
- package/dist/core/triwiki/context-graph/extractors/code/ts-config.js +161 -0
- package/dist/core/triwiki/context-graph/extractors/code/types.js +18 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/claims.js +289 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/index.js +54 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/proof-index.js +213 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/proofs.js +266 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/redaction.js +177 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/shared.js +0 -0
- package/dist/core/triwiki/context-graph/extractors/evidence/sources.js +154 -0
- package/dist/core/triwiki/context-graph/extractors/index.js +7 -0
- package/dist/core/triwiki/context-graph/extractors/topology/commands.js +207 -0
- package/dist/core/triwiki/context-graph/extractors/topology/gate-edges.js +201 -0
- package/dist/core/triwiki/context-graph/extractors/topology/gates.js +182 -0
- package/dist/core/triwiki/context-graph/extractors/topology/globs.js +124 -0
- package/dist/core/triwiki/context-graph/extractors/topology/index.js +92 -0
- package/dist/core/triwiki/context-graph/extractors/topology/routes.js +135 -0
- package/dist/core/triwiki/context-graph/extractors/topology/shared.js +215 -0
- package/dist/core/triwiki/context-graph/graph-index.js +143 -0
- package/dist/core/triwiki/context-graph/ids.js +0 -0
- package/dist/core/triwiki/context-graph/lint/index.js +0 -0
- package/dist/core/triwiki/context-graph/lint/rules.js +232 -0
- package/dist/core/triwiki/context-graph/lint/warnings.js +93 -0
- package/dist/core/triwiki/context-graph/paths.js +116 -0
- package/dist/core/triwiki/context-graph/profiles.js +78 -0
- package/dist/core/triwiki/context-graph/projections/anchors.js +91 -0
- package/dist/core/triwiki/context-graph/projections/attention.js +58 -0
- package/dist/core/triwiki/context-graph/projections/code-pack-workspace.js +62 -0
- package/dist/core/triwiki/context-graph/projections/code-pack.js +144 -0
- package/dist/core/triwiki/context-graph/projections/index.js +7 -0
- package/dist/core/triwiki/context-graph/projections/module-view.js +140 -0
- package/dist/core/triwiki/context-graph/projections/node-summary.js +118 -0
- package/dist/core/triwiki/context-graph/projections/pack-contract.js +6 -0
- package/dist/core/triwiki/context-graph/query/explain.js +0 -0
- package/dist/core/triwiki/context-graph/query/index.js +178 -0
- package/dist/core/triwiki/context-graph/query/load.js +116 -0
- package/dist/core/triwiki/context-graph/query/pack.js +117 -0
- package/dist/core/triwiki/context-graph/query/rank.js +142 -0
- package/dist/core/triwiki/context-graph/query/ranking-config.js +64 -0
- package/dist/core/triwiki/context-graph/query/seeds.js +241 -0
- package/dist/core/triwiki/context-graph/query/snapshot-cache.js +72 -0
- package/dist/core/triwiki/context-graph/query/traverse.js +154 -0
- package/dist/core/triwiki/context-graph/query-types.js +29 -0
- package/dist/core/triwiki/context-graph/store/compile-lock.js +21 -0
- package/dist/core/triwiki/context-graph/store/event-log.js +48 -0
- package/dist/core/triwiki/context-graph/store/fragment-cache.js +85 -0
- package/dist/core/triwiki/context-graph/store/graph-status.js +85 -0
- package/dist/core/triwiki/context-graph/store/snapshot-store.js +155 -0
- package/dist/core/triwiki/triwiki-proof-bank-index-repair.js +115 -0
- package/dist/core/triwiki/triwiki-proof-bank-index-store.js +290 -0
- package/dist/core/triwiki/triwiki-proof-bank-index.js +126 -0
- package/dist/core/triwiki/triwiki-proof-bank.js +7 -1
- package/dist/core/verification/context-graph-affected.js +271 -0
- package/dist/core/version.js +1 -1
- package/dist/native/sks-menubar/Sources/AlertFactory.swift +11 -3
- package/dist/native/sks-menubar/Sources/AppDelegate.swift +9 -0
- package/dist/native/sks-menubar/Sources/ControlCenterWindowController.swift +25 -3
- package/dist/native/sks-menubar/Sources/ControlKit.swift +19 -8
- package/dist/native/sks-menubar/Sources/DiagnosticsViewController.swift +1 -2
- package/dist/native/sks-menubar/Sources/MCPServersViewController.swift +45 -17
- package/dist/native/sks-menubar/Sources/OverviewSummary.swift +162 -0
- package/dist/native/sks-menubar/Sources/OverviewViewController.swift +136 -190
- package/dist/native/sks-menubar/Sources/ProcessClient.swift +107 -11
- package/dist/native/sks-menubar/Sources/ProvidersMultiProvider.swift +5 -1
- package/dist/native/sks-menubar/Sources/ProvidersOpenRouter.swift +16 -4
- package/dist/native/sks-menubar/Sources/ProvidersRoleModels.swift +4 -1
- package/dist/native/sks-menubar/Sources/ProvidersRoutingTruth.swift +131 -0
- package/dist/native/sks-menubar/Sources/ProvidersViewController.swift +288 -341
- package/dist/native/sks-menubar/Sources/RemoteTelegramCenterState.swift +447 -0
- package/dist/native/sks-menubar/Sources/RemoteTelegramRendering.swift +484 -0
- package/dist/native/sks-menubar/Sources/RemoteTelegramViewController.swift +364 -115
- package/dist/native/sks-menubar/Sources/SettingsViewController.swift +73 -12
- package/dist/native/sks-menubar/Sources/SidebarItem.swift +3 -3
- package/dist/native/sks-menubar/Sources/StatusItemController.swift +13 -13
- package/dist/native/sks-menubar/Sources/TelegramHubSupervisor.swift +469 -0
- package/dist/native/sks-menubar/Sources/UpdatesViewController.swift +1 -6
- package/dist/native/sks-menubar/Tests/AppRuntimeTestSupport.swift +12 -0
- package/dist/native/sks-menubar/Tests/NativeTelegramRegressionRunner.swift +55 -0
- package/dist/native/sks-menubar/Tests/ProcessClientTests.swift +33 -0
- package/dist/native/sks-menubar/Tests/ProvidersViewControllerTests.swift +142 -0
- package/dist/native/sks-menubar/Tests/RemoteTelegramCenterStateTests.swift +56 -0
- package/dist/native/sks-menubar/Tests/TelegramHubSupervisorTests.swift +55 -0
- package/dist/scripts/codex-lb-catalog-passthrough-check.js +120 -0
- package/dist/scripts/codex-lb-desktop-auth-invariant-check.js +169 -0
- package/dist/scripts/codex-lb-desktop-bridge-check.js +394 -0
- package/dist/scripts/codex-lb-desktop-bridge-latency-check.js +196 -0
- package/dist/scripts/codex-lb-desktop-capabilities-check.js +287 -0
- package/dist/scripts/codex-lb-desktop-real-evidence-check.js +123 -0
- package/dist/scripts/codex-lb-fast-mode-truth-check.js +10 -3
- package/dist/scripts/codex-lb-fast-ui-preservation-check.js +81 -40
- package/dist/scripts/codex-lb-gpt56-fast-profile-check.js +99 -37
- package/dist/scripts/context-graph-check.js +191 -0
- package/dist/scripts/doctor-fixes-codex-app-fast-ui-check.js +1 -1
- package/dist/scripts/gate-policy-audit-check.js +1 -1
- package/dist/scripts/helper-dedup-check.js +0 -2
- package/dist/scripts/installed-package-smoke-check.js +4 -1
- package/dist/scripts/latest-version-guidance-check.js +74 -0
- package/dist/scripts/release-metadata-check.js +21 -4
- package/dist/scripts/release-real-check.js +7 -0
- package/dist/scripts/ux-review-imagegen-blackbox-check.js +25 -1
- package/dist/scripts/ux-review-run-wires-imagegen-check.js +9 -1
- package/package.json +8 -3
- package/release-gates.v2.json +176 -1
- package/runtime-required-scripts.json +30 -0
- package/schemas/triwiki/context-graph.schema.json +119 -0
- package/dist/cli/install-helpers-codex-lb-selftest-chain.js +0 -112
- package/dist/cli/install-helpers-codex-lb-selftest.js +0 -481
- package/dist/core/triwiki/code-index-scanner.js +0 -309
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { lintError } from '../../contracts.js';
|
|
2
|
+
import { compareContextGraphIds, contextGraphEdgeId } from '../../ids.js';
|
|
3
|
+
import { isWorkspaceRelativePosixPath } from '../../paths.js';
|
|
4
|
+
import { CODE_GRAPH_EXTRACTOR_ID } from './types.js';
|
|
5
|
+
export class CodeGraphSink {
|
|
6
|
+
limits;
|
|
7
|
+
observedAt;
|
|
8
|
+
nodes = new Map();
|
|
9
|
+
edges = new Map();
|
|
10
|
+
skips = [];
|
|
11
|
+
skipKeys = new Set();
|
|
12
|
+
issues = [];
|
|
13
|
+
nodeCapReported = false;
|
|
14
|
+
edgeCapReported = false;
|
|
15
|
+
constructor(limits, observedAt) {
|
|
16
|
+
this.limits = limits;
|
|
17
|
+
this.observedAt = observedAt;
|
|
18
|
+
}
|
|
19
|
+
get nodeCount() {
|
|
20
|
+
return this.nodes.size;
|
|
21
|
+
}
|
|
22
|
+
get edgeCount() {
|
|
23
|
+
return this.edges.size;
|
|
24
|
+
}
|
|
25
|
+
hasNode(id) {
|
|
26
|
+
return this.nodes.has(id);
|
|
27
|
+
}
|
|
28
|
+
addNode(input, capPath) {
|
|
29
|
+
if (this.nodes.has(input.id))
|
|
30
|
+
return true;
|
|
31
|
+
if (input.path !== undefined && !isWorkspaceRelativePosixPath(input.path)) {
|
|
32
|
+
this.issues.push(lintError('absolute_or_escaping_path', `node ${input.id} carries a non workspace-relative path`, {
|
|
33
|
+
nodeId: input.id,
|
|
34
|
+
extractor: CODE_GRAPH_EXTRACTOR_ID
|
|
35
|
+
}));
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (this.nodes.size >= this.limits.maxNodes) {
|
|
39
|
+
if (!this.nodeCapReported) {
|
|
40
|
+
this.nodeCapReported = true;
|
|
41
|
+
this.addSkip({ path: capPath, reason: 'cap_reached', detail: `maxNodes=${this.limits.maxNodes} reached` });
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const node = {
|
|
46
|
+
id: input.id,
|
|
47
|
+
kind: input.kind,
|
|
48
|
+
label: input.label,
|
|
49
|
+
...(input.path === undefined ? {} : { path: input.path }),
|
|
50
|
+
...(input.locator === undefined ? {} : { locator: input.locator }),
|
|
51
|
+
...(input.contentHash === undefined ? {} : { contentHash: input.contentHash }),
|
|
52
|
+
trust: input.trust,
|
|
53
|
+
freshness: 'fresh',
|
|
54
|
+
risk: input.risk,
|
|
55
|
+
tokenCost: input.tokenCost,
|
|
56
|
+
metadata: input.metadata
|
|
57
|
+
};
|
|
58
|
+
this.nodes.set(node.id, node);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
addEdge(input) {
|
|
62
|
+
if (!this.nodes.has(input.from) || !this.nodes.has(input.to))
|
|
63
|
+
return false;
|
|
64
|
+
if (!input.path || !isWorkspaceRelativePosixPath(input.path) || !input.hash) {
|
|
65
|
+
this.issues.push(lintError('edge_without_provenance', `refused a ${input.type} edge without usable provenance`, {
|
|
66
|
+
extractor: CODE_GRAPH_EXTRACTOR_ID
|
|
67
|
+
}));
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const id = contextGraphEdgeId({ from: input.from, to: input.to, type: input.type });
|
|
71
|
+
if (this.edges.has(id))
|
|
72
|
+
return true;
|
|
73
|
+
if (this.edges.size >= this.limits.maxEdges) {
|
|
74
|
+
if (!this.edgeCapReported) {
|
|
75
|
+
this.edgeCapReported = true;
|
|
76
|
+
this.addSkip({ path: input.path, reason: 'cap_reached', detail: `maxEdges=${this.limits.maxEdges} reached` });
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
const line = typeof input.line === 'number' && Number.isFinite(input.line) && input.line > 0 ? Math.trunc(input.line) : undefined;
|
|
81
|
+
this.edges.set(id, {
|
|
82
|
+
id,
|
|
83
|
+
from: input.from,
|
|
84
|
+
to: input.to,
|
|
85
|
+
type: input.type,
|
|
86
|
+
confidence: input.confidence,
|
|
87
|
+
provenance: {
|
|
88
|
+
path: input.path,
|
|
89
|
+
...(line === undefined ? {} : { line }),
|
|
90
|
+
hash: input.hash,
|
|
91
|
+
extractor: CODE_GRAPH_EXTRACTOR_ID
|
|
92
|
+
},
|
|
93
|
+
observedAt: this.observedAt
|
|
94
|
+
});
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
addSkip(skip) {
|
|
98
|
+
if (!isWorkspaceRelativePosixPath(skip.path))
|
|
99
|
+
return;
|
|
100
|
+
const key = `${skip.path}\u0000${skip.reason}\u0000${skip.detail ?? ''}`;
|
|
101
|
+
if (this.skipKeys.has(key))
|
|
102
|
+
return;
|
|
103
|
+
this.skipKeys.add(key);
|
|
104
|
+
this.skips.push(skip);
|
|
105
|
+
}
|
|
106
|
+
addIssue(issue) {
|
|
107
|
+
this.issues.push(issue);
|
|
108
|
+
}
|
|
109
|
+
pruneUnreachableSymbols() {
|
|
110
|
+
const reachable = new Set();
|
|
111
|
+
for (const edge of this.edges.values()) {
|
|
112
|
+
if (edge.type === 'contains')
|
|
113
|
+
continue;
|
|
114
|
+
reachable.add(edge.from);
|
|
115
|
+
reachable.add(edge.to);
|
|
116
|
+
}
|
|
117
|
+
const dropped = new Set();
|
|
118
|
+
for (const [id, node] of this.nodes) {
|
|
119
|
+
if (node.kind !== 'symbol')
|
|
120
|
+
continue;
|
|
121
|
+
if (node.metadata.exported === true || reachable.has(id))
|
|
122
|
+
continue;
|
|
123
|
+
dropped.add(id);
|
|
124
|
+
this.nodes.delete(id);
|
|
125
|
+
}
|
|
126
|
+
if (!dropped.size)
|
|
127
|
+
return;
|
|
128
|
+
for (const [id, edge] of this.edges) {
|
|
129
|
+
if (dropped.has(edge.from) || dropped.has(edge.to))
|
|
130
|
+
this.edges.delete(id);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
result() {
|
|
134
|
+
this.pruneUnreachableSymbols();
|
|
135
|
+
const nodes = [...this.nodes.values()].sort((left, right) => compareContextGraphIds(left.id, right.id));
|
|
136
|
+
const edges = [...this.edges.values()].sort((left, right) => compareContextGraphIds(left.id, right.id));
|
|
137
|
+
const skipped = [...this.skips].sort((left, right) => compareContextGraphIds(left.path, right.path) || compareContextGraphIds(left.reason, right.reason) || compareContextGraphIds(left.detail ?? '', right.detail ?? ''));
|
|
138
|
+
const issues = [...this.issues].sort((left, right) => compareContextGraphIds(left.code, right.code) || compareContextGraphIds(left.message, right.message));
|
|
139
|
+
return { nodes, edges, issues, skipped };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function riskFromFanIn(fanIn, isTest) {
|
|
143
|
+
if (isTest)
|
|
144
|
+
return 'low';
|
|
145
|
+
if (fanIn >= 5)
|
|
146
|
+
return 'high';
|
|
147
|
+
if (fanIn >= 2)
|
|
148
|
+
return 'medium';
|
|
149
|
+
return 'low';
|
|
150
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { contextGraphNodeId } from '../../ids.js';
|
|
3
|
+
import { estimateTokenCost } from './types.js';
|
|
4
|
+
function hasFlag(node, flag) {
|
|
5
|
+
return (ts.getCombinedModifierFlags(node) & flag) !== 0;
|
|
6
|
+
}
|
|
7
|
+
function collectLocalExportAliases(sourceFile) {
|
|
8
|
+
const aliases = new Map();
|
|
9
|
+
for (const statement of sourceFile.statements) {
|
|
10
|
+
if (!ts.isExportDeclaration(statement))
|
|
11
|
+
continue;
|
|
12
|
+
if (statement.moduleSpecifier)
|
|
13
|
+
continue;
|
|
14
|
+
const clause = statement.exportClause;
|
|
15
|
+
if (!clause || !ts.isNamedExports(clause))
|
|
16
|
+
continue;
|
|
17
|
+
for (const element of clause.elements) {
|
|
18
|
+
const local = (element.propertyName ?? element.name).text;
|
|
19
|
+
const exported = element.name.text;
|
|
20
|
+
const bucket = aliases.get(local);
|
|
21
|
+
if (bucket)
|
|
22
|
+
bucket.push(exported);
|
|
23
|
+
else
|
|
24
|
+
aliases.set(local, [exported]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return aliases;
|
|
28
|
+
}
|
|
29
|
+
function pushSymbol(context, node, name, symbolKind, options) {
|
|
30
|
+
const startOffset = node.getStart(context.sourceFile);
|
|
31
|
+
const endOffset = node.getEnd();
|
|
32
|
+
const start = context.sourceFile.getLineAndCharacterOfPosition(startOffset);
|
|
33
|
+
const end = context.sourceFile.getLineAndCharacterOfPosition(endOffset);
|
|
34
|
+
const exportNames = new Set();
|
|
35
|
+
if (options.explicitExportNames)
|
|
36
|
+
for (const explicit of options.explicitExportNames)
|
|
37
|
+
exportNames.add(explicit);
|
|
38
|
+
else if (options.isDefault)
|
|
39
|
+
exportNames.add('default');
|
|
40
|
+
else if (options.exportedByModifier)
|
|
41
|
+
exportNames.add(name);
|
|
42
|
+
for (const alias of context.localExports.get(name) ?? [])
|
|
43
|
+
exportNames.add(alias);
|
|
44
|
+
context.out.push({
|
|
45
|
+
nodeId: contextGraphNodeId({ kind: 'symbol', path: context.rel, symbolKind, name, startOffset }),
|
|
46
|
+
name,
|
|
47
|
+
symbolKind,
|
|
48
|
+
startOffset,
|
|
49
|
+
endOffset,
|
|
50
|
+
line: start.line + 1,
|
|
51
|
+
column: start.character + 1,
|
|
52
|
+
endLine: end.line + 1,
|
|
53
|
+
endColumn: end.character + 1,
|
|
54
|
+
exported: exportNames.size > 0,
|
|
55
|
+
isDefault: options.isDefault,
|
|
56
|
+
exportNames: [...exportNames].sort(),
|
|
57
|
+
tokenCost: estimateTokenCost(endOffset - startOffset)
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function variableKind(statement) {
|
|
61
|
+
const flags = statement.declarationList.flags;
|
|
62
|
+
if (flags & ts.NodeFlags.Const)
|
|
63
|
+
return 'const';
|
|
64
|
+
if (flags & ts.NodeFlags.Let)
|
|
65
|
+
return 'let';
|
|
66
|
+
return 'var';
|
|
67
|
+
}
|
|
68
|
+
function collectBindingNames(name, out) {
|
|
69
|
+
if (ts.isIdentifier(name)) {
|
|
70
|
+
out.push(name);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
for (const element of name.elements) {
|
|
74
|
+
if (ts.isOmittedExpression(element))
|
|
75
|
+
continue;
|
|
76
|
+
collectBindingNames(element.name, out);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function visitVariableStatement(context, statement) {
|
|
80
|
+
const symbolKind = variableKind(statement);
|
|
81
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
82
|
+
const exported = hasFlag(declaration, ts.ModifierFlags.Export);
|
|
83
|
+
const identifiers = [];
|
|
84
|
+
collectBindingNames(declaration.name, identifiers);
|
|
85
|
+
for (const identifier of identifiers) {
|
|
86
|
+
const anchor = ts.isIdentifier(declaration.name) ? declaration : identifier;
|
|
87
|
+
pushSymbol(context, anchor, identifier.text, symbolKind, { exportedByModifier: exported, isDefault: false });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function namedDeclarationKind(statement) {
|
|
92
|
+
if (ts.isFunctionDeclaration(statement))
|
|
93
|
+
return 'function';
|
|
94
|
+
if (ts.isClassDeclaration(statement))
|
|
95
|
+
return 'class';
|
|
96
|
+
if (ts.isInterfaceDeclaration(statement))
|
|
97
|
+
return 'interface';
|
|
98
|
+
if (ts.isTypeAliasDeclaration(statement))
|
|
99
|
+
return 'type';
|
|
100
|
+
if (ts.isEnumDeclaration(statement))
|
|
101
|
+
return 'enum';
|
|
102
|
+
if (ts.isModuleDeclaration(statement) && ts.isIdentifier(statement.name))
|
|
103
|
+
return 'namespace';
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
function visitStatement(context, statement) {
|
|
107
|
+
if (ts.isVariableStatement(statement)) {
|
|
108
|
+
visitVariableStatement(context, statement);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (ts.isExportAssignment(statement)) {
|
|
112
|
+
const isEquals = statement.isExportEquals === true;
|
|
113
|
+
const expression = statement.expression;
|
|
114
|
+
const name = isEquals ? (ts.isIdentifier(expression) ? expression.text : 'exportEquals') : 'default';
|
|
115
|
+
pushSymbol(context, statement, name, 'default', {
|
|
116
|
+
exportedByModifier: true,
|
|
117
|
+
isDefault: !isEquals,
|
|
118
|
+
...(isEquals ? { explicitExportNames: ['export=', 'default'] } : {})
|
|
119
|
+
});
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const kind = namedDeclarationKind(statement);
|
|
123
|
+
if (!kind)
|
|
124
|
+
return;
|
|
125
|
+
const declaration = statement;
|
|
126
|
+
const isDefault = hasFlag(declaration, ts.ModifierFlags.Default);
|
|
127
|
+
const exported = hasFlag(declaration, ts.ModifierFlags.Export);
|
|
128
|
+
const name = declaration.name && ts.isIdentifier(declaration.name) ? declaration.name.text : isDefault ? 'default' : '';
|
|
129
|
+
if (!name)
|
|
130
|
+
return;
|
|
131
|
+
pushSymbol(context, statement, name, kind, { exportedByModifier: exported, isDefault });
|
|
132
|
+
}
|
|
133
|
+
export function extractDeclarations(sourceFile, rel) {
|
|
134
|
+
const context = {
|
|
135
|
+
sourceFile,
|
|
136
|
+
rel,
|
|
137
|
+
localExports: collectLocalExportAliases(sourceFile),
|
|
138
|
+
out: []
|
|
139
|
+
};
|
|
140
|
+
for (const statement of sourceFile.statements)
|
|
141
|
+
visitStatement(context, statement);
|
|
142
|
+
return context.out;
|
|
143
|
+
}
|
|
144
|
+
export function indexExports(symbols) {
|
|
145
|
+
const index = new Map();
|
|
146
|
+
for (const symbol of symbols) {
|
|
147
|
+
for (const exportName of symbol.exportNames) {
|
|
148
|
+
if (!index.has(exportName))
|
|
149
|
+
index.set(exportName, symbol);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return index;
|
|
153
|
+
}
|
|
154
|
+
export function indexDeclaredNames(symbols) {
|
|
155
|
+
const index = new Map();
|
|
156
|
+
for (const symbol of symbols) {
|
|
157
|
+
if (!index.has(symbol.name))
|
|
158
|
+
index.set(symbol.name, symbol);
|
|
159
|
+
}
|
|
160
|
+
return index;
|
|
161
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { emptyContextGraphFragment, lintWarning } from '../../contracts.js';
|
|
4
|
+
import { contextGraphNodeId } from '../../ids.js';
|
|
5
|
+
import { CodeGraphSink, riskFromFanIn } from './builders.js';
|
|
6
|
+
import { extractDeclarations, indexDeclaredNames, indexExports } from './declarations.js';
|
|
7
|
+
import { walkCodeInventory } from './inventory.js';
|
|
8
|
+
import { buildImportAndReexportEdges, collectModuleFacts } from './module-graph.js';
|
|
9
|
+
import { buildModuleContainsEdges, buildModuleNodes, inferModuleBoundaries, moduleDirForPath } from './modules.js';
|
|
10
|
+
import { buildReferenceEdges } from './references.js';
|
|
11
|
+
import { selectExtractionTargets } from './selection.js';
|
|
12
|
+
import { createCodeSourceFile, createResolutionContext } from './ts-config.js';
|
|
13
|
+
import { CODE_GRAPH_EXTRACTOR_ID, CODE_GRAPH_EXTRACTOR_REVISION, estimateTokenCost } from './types.js';
|
|
14
|
+
const MAX_UNRESOLVED_WARNINGS = 100;
|
|
15
|
+
function realRoot(root) {
|
|
16
|
+
const absolute = path.resolve(root);
|
|
17
|
+
try {
|
|
18
|
+
return fs.realpathSync(absolute);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return absolute;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function sortedHashes(hashes) {
|
|
25
|
+
const out = {};
|
|
26
|
+
for (const key of [...hashes.keys()].sort()) {
|
|
27
|
+
const value = hashes.get(key);
|
|
28
|
+
if (value !== undefined)
|
|
29
|
+
out[key] = value;
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
export class CodeGraphExtractor {
|
|
34
|
+
id = CODE_GRAPH_EXTRACTOR_ID;
|
|
35
|
+
revision = CODE_GRAPH_EXTRACTOR_REVISION;
|
|
36
|
+
async extract(input) {
|
|
37
|
+
const startedAt = Date.now();
|
|
38
|
+
const deadline = startedAt + Math.max(1, input.limits.timeoutMs);
|
|
39
|
+
const root = realRoot(input.root);
|
|
40
|
+
const sink = new CodeGraphSink(input.limits, input.observedAt);
|
|
41
|
+
const inventory = walkCodeInventory(root, input.limits);
|
|
42
|
+
for (const skip of inventory.skipped)
|
|
43
|
+
sink.addSkip(skip);
|
|
44
|
+
const hashes = new Map();
|
|
45
|
+
for (const file of inventory.files)
|
|
46
|
+
hashes.set(file.rel, file.hash);
|
|
47
|
+
const context = createResolutionContext(root);
|
|
48
|
+
if (context.configRel && context.configHash)
|
|
49
|
+
hashes.set(context.configRel, context.configHash);
|
|
50
|
+
const selection = selectExtractionTargets(context, inventory, input.changedPaths);
|
|
51
|
+
for (const unknown of selection.unknownChanged) {
|
|
52
|
+
sink.addIssue(lintWarning('extractor_skipped_input', 'changed path is not a scannable source file', {
|
|
53
|
+
path: unknown,
|
|
54
|
+
extractor: this.id
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
if (selection.unmappableChanged > 0) {
|
|
58
|
+
sink.addIssue(lintWarning('extractor_skipped_input', `${selection.unmappableChanged} changed path(s) are outside the workspace`, {
|
|
59
|
+
extractor: this.id
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
const phase = this.parseAndCollect(context, inventory, selection.targets, sink, deadline);
|
|
63
|
+
this.reportUnresolved(sink, phase.factsByRel);
|
|
64
|
+
const fanIn = countFanIn(phase.factsByRel);
|
|
65
|
+
const nodeRels = collectNodeRels(phase.factsByRel, phase.parsedByRel, inventory);
|
|
66
|
+
const fileNodeIdByRel = new Map();
|
|
67
|
+
const testNodeIdByRel = new Map();
|
|
68
|
+
this.buildFileNodes({ sink, inventory, nodeRels, parsed: phase.parsedByRel, fanIn, fileNodeIdByRel, testNodeIdByRel });
|
|
69
|
+
this.buildSymbolNodes(sink, inventory, phase.declarationsByRel);
|
|
70
|
+
const boundaries = inferModuleBoundaries([...fileNodeIdByRel.keys()].sort());
|
|
71
|
+
buildModuleNodes(sink, boundaries);
|
|
72
|
+
buildModuleContainsEdges(sink, boundaries, fileNodeIdByRel, inventory.byRel);
|
|
73
|
+
this.buildContainmentEdges(sink, inventory, phase.declarationsByRel, fileNodeIdByRel, testNodeIdByRel);
|
|
74
|
+
buildImportAndReexportEdges(sink, phase.tables, inventory.byRel, fileNodeIdByRel);
|
|
75
|
+
buildReferenceEdges(sink, {
|
|
76
|
+
tables: phase.tables,
|
|
77
|
+
parsedByRel: phase.parsedByRel,
|
|
78
|
+
byRel: inventory.byRel,
|
|
79
|
+
fileNodeIdByRel,
|
|
80
|
+
testNodeIdByRel
|
|
81
|
+
});
|
|
82
|
+
const result = sink.result();
|
|
83
|
+
const fragment = emptyContextGraphFragment(this.id, this.revision);
|
|
84
|
+
fragment.nodes = result.nodes;
|
|
85
|
+
fragment.edges = result.edges;
|
|
86
|
+
fragment.issues = result.issues;
|
|
87
|
+
fragment.skipped = result.skipped;
|
|
88
|
+
fragment.inputHashes = sortedHashes(hashes);
|
|
89
|
+
return fragment;
|
|
90
|
+
}
|
|
91
|
+
parseAndCollect(context, inventory, targets, sink, deadline) {
|
|
92
|
+
const parsedByRel = new Map();
|
|
93
|
+
const factsByRel = new Map();
|
|
94
|
+
const declarationsByRel = new Map();
|
|
95
|
+
const exportsByRel = new Map();
|
|
96
|
+
const declaredByRel = new Map();
|
|
97
|
+
const isKnownFile = (rel) => inventory.byRel.has(rel);
|
|
98
|
+
for (const record of targets) {
|
|
99
|
+
if (Date.now() >= deadline) {
|
|
100
|
+
sink.addSkip({ path: record.rel, reason: 'cap_reached', detail: 'timeoutMs exceeded before parse' });
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
const parsed = { record, sourceFile: createCodeSourceFile(context, record) };
|
|
104
|
+
parsedByRel.set(record.rel, parsed);
|
|
105
|
+
const facts = collectModuleFacts(context, parsed, isKnownFile);
|
|
106
|
+
factsByRel.set(record.rel, facts);
|
|
107
|
+
for (const skip of facts.skips)
|
|
108
|
+
sink.addSkip(skip);
|
|
109
|
+
const declarations = extractDeclarations(parsed.sourceFile, record.rel);
|
|
110
|
+
declarationsByRel.set(record.rel, declarations);
|
|
111
|
+
exportsByRel.set(record.rel, indexExports(declarations));
|
|
112
|
+
declaredByRel.set(record.rel, indexDeclaredNames(declarations));
|
|
113
|
+
}
|
|
114
|
+
return { parsedByRel, factsByRel, declarationsByRel, tables: { factsByRel, exportsByRel, declaredByRel } };
|
|
115
|
+
}
|
|
116
|
+
reportUnresolved(sink, factsByRel) {
|
|
117
|
+
let reported = 0;
|
|
118
|
+
for (const [rel, facts] of factsByRel) {
|
|
119
|
+
for (const entry of facts.unresolved) {
|
|
120
|
+
if (reported >= MAX_UNRESOLVED_WARNINGS)
|
|
121
|
+
return;
|
|
122
|
+
reported += 1;
|
|
123
|
+
sink.addIssue(lintWarning('extractor_skipped_input', `unresolved first-party import '${entry.specifier}'`, {
|
|
124
|
+
path: rel,
|
|
125
|
+
extractor: this.id
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
buildFileNodes(args) {
|
|
131
|
+
for (const rel of args.nodeRels) {
|
|
132
|
+
const record = args.inventory.byRel.get(rel);
|
|
133
|
+
if (!record)
|
|
134
|
+
continue;
|
|
135
|
+
const scanned = args.parsed.has(rel);
|
|
136
|
+
const id = contextGraphNodeId({ kind: 'file', path: rel });
|
|
137
|
+
const added = args.sink.addNode({
|
|
138
|
+
id,
|
|
139
|
+
kind: 'file',
|
|
140
|
+
label: path.posix.basename(rel),
|
|
141
|
+
path: rel,
|
|
142
|
+
contentHash: record.hash,
|
|
143
|
+
trust: 1,
|
|
144
|
+
risk: riskFromFanIn(args.fanIn.get(rel) ?? 0, record.isTest),
|
|
145
|
+
tokenCost: estimateTokenCost(record.bytes),
|
|
146
|
+
metadata: {
|
|
147
|
+
extension: record.extension,
|
|
148
|
+
language: record.language,
|
|
149
|
+
lines: record.lines,
|
|
150
|
+
bytes: record.bytes,
|
|
151
|
+
isTest: record.isTest,
|
|
152
|
+
fanIn: args.fanIn.get(rel) ?? 0,
|
|
153
|
+
scanned
|
|
154
|
+
}
|
|
155
|
+
}, rel);
|
|
156
|
+
if (!added)
|
|
157
|
+
continue;
|
|
158
|
+
args.fileNodeIdByRel.set(rel, id);
|
|
159
|
+
if (!record.isTest || !scanned)
|
|
160
|
+
continue;
|
|
161
|
+
const testId = contextGraphNodeId({ kind: 'test', path: rel });
|
|
162
|
+
if (args.sink.addNode({
|
|
163
|
+
id: testId,
|
|
164
|
+
kind: 'test',
|
|
165
|
+
label: path.posix.basename(rel),
|
|
166
|
+
path: rel,
|
|
167
|
+
contentHash: record.hash,
|
|
168
|
+
trust: 1,
|
|
169
|
+
risk: 'low',
|
|
170
|
+
tokenCost: estimateTokenCost(record.bytes),
|
|
171
|
+
metadata: { lines: record.lines, bytes: record.bytes, suite: 'file' }
|
|
172
|
+
}, rel)) {
|
|
173
|
+
args.testNodeIdByRel.set(rel, testId);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
buildSymbolNodes(sink, inventory, declarationsByRel) {
|
|
178
|
+
for (const rel of [...declarationsByRel.keys()].sort()) {
|
|
179
|
+
const record = inventory.byRel.get(rel);
|
|
180
|
+
const declarations = declarationsByRel.get(rel);
|
|
181
|
+
if (!record || !declarations)
|
|
182
|
+
continue;
|
|
183
|
+
const moduleDir = moduleDirForPath(rel);
|
|
184
|
+
for (const symbol of declarations) {
|
|
185
|
+
sink.addNode({
|
|
186
|
+
id: symbol.nodeId,
|
|
187
|
+
kind: 'symbol',
|
|
188
|
+
label: symbol.name,
|
|
189
|
+
path: rel,
|
|
190
|
+
contentHash: record.hash,
|
|
191
|
+
locator: { line: symbol.line, column: symbol.column, endLine: symbol.endLine, endColumn: symbol.endColumn },
|
|
192
|
+
trust: 1,
|
|
193
|
+
risk: 'low',
|
|
194
|
+
tokenCost: symbol.tokenCost,
|
|
195
|
+
metadata: {
|
|
196
|
+
symbolKind: symbol.symbolKind,
|
|
197
|
+
exported: symbol.exported,
|
|
198
|
+
default: symbol.isDefault,
|
|
199
|
+
exportNames: symbol.exportNames,
|
|
200
|
+
module: moduleDir
|
|
201
|
+
}
|
|
202
|
+
}, rel);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
buildContainmentEdges(sink, inventory, declarationsByRel, fileNodeIdByRel, testNodeIdByRel) {
|
|
207
|
+
for (const rel of [...declarationsByRel.keys()].sort()) {
|
|
208
|
+
const record = inventory.byRel.get(rel);
|
|
209
|
+
const from = fileNodeIdByRel.get(rel);
|
|
210
|
+
const declarations = declarationsByRel.get(rel);
|
|
211
|
+
if (!record || !from || !declarations)
|
|
212
|
+
continue;
|
|
213
|
+
const testNodeId = testNodeIdByRel.get(rel);
|
|
214
|
+
if (testNodeId) {
|
|
215
|
+
sink.addEdge({ from, to: testNodeId, type: 'contains', confidence: 'exact', path: rel, hash: record.hash });
|
|
216
|
+
}
|
|
217
|
+
for (const symbol of declarations) {
|
|
218
|
+
sink.addEdge({
|
|
219
|
+
from,
|
|
220
|
+
to: symbol.nodeId,
|
|
221
|
+
type: 'contains',
|
|
222
|
+
confidence: 'exact',
|
|
223
|
+
path: rel,
|
|
224
|
+
hash: record.hash,
|
|
225
|
+
line: symbol.line
|
|
226
|
+
});
|
|
227
|
+
if (!symbol.exported)
|
|
228
|
+
continue;
|
|
229
|
+
sink.addEdge({
|
|
230
|
+
from,
|
|
231
|
+
to: symbol.nodeId,
|
|
232
|
+
type: 'defines',
|
|
233
|
+
confidence: 'exact',
|
|
234
|
+
path: rel,
|
|
235
|
+
hash: record.hash,
|
|
236
|
+
line: symbol.line
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function countFanIn(factsByRel) {
|
|
243
|
+
const fanIn = new Map();
|
|
244
|
+
for (const facts of factsByRel.values()) {
|
|
245
|
+
for (const entry of facts.imports)
|
|
246
|
+
fanIn.set(entry.targetRel, (fanIn.get(entry.targetRel) ?? 0) + 1);
|
|
247
|
+
}
|
|
248
|
+
return fanIn;
|
|
249
|
+
}
|
|
250
|
+
function collectNodeRels(factsByRel, parsedByRel, inventory) {
|
|
251
|
+
const rels = new Set(parsedByRel.keys());
|
|
252
|
+
for (const facts of factsByRel.values()) {
|
|
253
|
+
for (const entry of facts.imports)
|
|
254
|
+
if (inventory.byRel.has(entry.targetRel))
|
|
255
|
+
rels.add(entry.targetRel);
|
|
256
|
+
for (const record of facts.reexports)
|
|
257
|
+
if (inventory.byRel.has(record.targetRel))
|
|
258
|
+
rels.add(record.targetRel);
|
|
259
|
+
}
|
|
260
|
+
return [...rels].sort();
|
|
261
|
+
}
|
|
262
|
+
export function createCodeGraphExtractor() {
|
|
263
|
+
return new CodeGraphExtractor();
|
|
264
|
+
}
|
|
265
|
+
export { CODE_GRAPH_EXTRACTOR_ID, CODE_GRAPH_EXTRACTOR_REVISION } from './types.js';
|