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,184 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { resolveExportedSymbol } from './module-graph.js';
|
|
3
|
+
function isUsageIdentifier(node) {
|
|
4
|
+
const parent = node.parent;
|
|
5
|
+
if (!parent)
|
|
6
|
+
return false;
|
|
7
|
+
if (ts.isPropertyAccessExpression(parent) && parent.name === node)
|
|
8
|
+
return false;
|
|
9
|
+
if (ts.isQualifiedName(parent) && parent.right === node)
|
|
10
|
+
return false;
|
|
11
|
+
if (ts.isPropertyAssignment(parent) && parent.name === node)
|
|
12
|
+
return false;
|
|
13
|
+
if (ts.isPropertySignature(parent) && parent.name === node)
|
|
14
|
+
return false;
|
|
15
|
+
if (ts.isPropertyDeclaration(parent) && parent.name === node)
|
|
16
|
+
return false;
|
|
17
|
+
if (ts.isMethodDeclaration(parent) && parent.name === node)
|
|
18
|
+
return false;
|
|
19
|
+
if (ts.isMethodSignature(parent) && parent.name === node)
|
|
20
|
+
return false;
|
|
21
|
+
if (ts.isEnumMember(parent) && parent.name === node)
|
|
22
|
+
return false;
|
|
23
|
+
if (ts.isBindingElement(parent) && (parent.name === node || parent.propertyName === node))
|
|
24
|
+
return false;
|
|
25
|
+
if (ts.isParameter(parent) && parent.name === node)
|
|
26
|
+
return false;
|
|
27
|
+
if (ts.isVariableDeclaration(parent) && parent.name === node)
|
|
28
|
+
return false;
|
|
29
|
+
if (ts.isFunctionDeclaration(parent) && parent.name === node)
|
|
30
|
+
return false;
|
|
31
|
+
if (ts.isClassDeclaration(parent) && parent.name === node)
|
|
32
|
+
return false;
|
|
33
|
+
if (ts.isInterfaceDeclaration(parent) && parent.name === node)
|
|
34
|
+
return false;
|
|
35
|
+
if (ts.isTypeAliasDeclaration(parent) && parent.name === node)
|
|
36
|
+
return false;
|
|
37
|
+
if (ts.isEnumDeclaration(parent) && parent.name === node)
|
|
38
|
+
return false;
|
|
39
|
+
if (ts.isModuleDeclaration(parent) && parent.name === node)
|
|
40
|
+
return false;
|
|
41
|
+
if (ts.isLabeledStatement(parent) && parent.label === node)
|
|
42
|
+
return false;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
function isInvoked(node) {
|
|
46
|
+
const parent = node.parent;
|
|
47
|
+
if (!parent)
|
|
48
|
+
return false;
|
|
49
|
+
if (ts.isCallExpression(parent) && parent.expression === node)
|
|
50
|
+
return true;
|
|
51
|
+
if (ts.isNewExpression(parent) && parent.expression === node)
|
|
52
|
+
return true;
|
|
53
|
+
if (ts.isTaggedTemplateExpression(parent) && parent.tag === node)
|
|
54
|
+
return true;
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
function recordUsage(usages, binding, exportName, line, call) {
|
|
58
|
+
const key = `${binding.local}|${exportName}`;
|
|
59
|
+
const existing = usages.get(key);
|
|
60
|
+
if (!existing) {
|
|
61
|
+
usages.set(key, { binding, exportName, line, callLine: call ? line : null });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (call && existing.callLine === null)
|
|
65
|
+
existing.callLine = line;
|
|
66
|
+
}
|
|
67
|
+
function collectUsages(parsed, bindings) {
|
|
68
|
+
const usages = new Map();
|
|
69
|
+
const byLocal = new Map();
|
|
70
|
+
for (const binding of bindings)
|
|
71
|
+
if (!byLocal.has(binding.local))
|
|
72
|
+
byLocal.set(binding.local, binding);
|
|
73
|
+
if (!byLocal.size)
|
|
74
|
+
return usages;
|
|
75
|
+
const sourceFile = parsed.sourceFile;
|
|
76
|
+
const handle = (node) => {
|
|
77
|
+
const binding = byLocal.get(node.text);
|
|
78
|
+
if (!binding || !binding.targetRel)
|
|
79
|
+
return;
|
|
80
|
+
if (!isUsageIdentifier(node))
|
|
81
|
+
return;
|
|
82
|
+
const line = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
|
|
83
|
+
const parent = node.parent;
|
|
84
|
+
if (binding.exportName === '*') {
|
|
85
|
+
if (!parent || !ts.isPropertyAccessExpression(parent) || parent.expression !== node)
|
|
86
|
+
return;
|
|
87
|
+
if (!ts.isIdentifier(parent.name))
|
|
88
|
+
return;
|
|
89
|
+
recordUsage(usages, binding, parent.name.text, line, isInvoked(parent));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
recordUsage(usages, binding, binding.exportName, line, isInvoked(node));
|
|
93
|
+
};
|
|
94
|
+
const visit = (node) => {
|
|
95
|
+
if (ts.isImportDeclaration(node) || ts.isImportEqualsDeclaration(node) || ts.isExportDeclaration(node))
|
|
96
|
+
return;
|
|
97
|
+
if (ts.isIdentifier(node)) {
|
|
98
|
+
handle(node);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
ts.forEachChild(node, visit);
|
|
102
|
+
};
|
|
103
|
+
ts.forEachChild(sourceFile, visit);
|
|
104
|
+
return usages;
|
|
105
|
+
}
|
|
106
|
+
function resolveUsage(tables, usage) {
|
|
107
|
+
const targetRel = usage.binding.targetRel;
|
|
108
|
+
if (!targetRel)
|
|
109
|
+
return null;
|
|
110
|
+
const resolved = resolveExportedSymbol(tables, targetRel, usage.exportName);
|
|
111
|
+
if (resolved)
|
|
112
|
+
return { symbolNodeId: resolved.symbol.nodeId, definingRel: resolved.rel, confidence: 'exact' };
|
|
113
|
+
const declared = tables.declaredByRel.get(targetRel)?.get(usage.exportName);
|
|
114
|
+
if (declared)
|
|
115
|
+
return { symbolNodeId: declared.nodeId, definingRel: targetRel, confidence: 'syntactic' };
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
export function buildReferenceEdges(sink, inputs) {
|
|
119
|
+
const rels = [...inputs.parsedByRel.keys()].sort();
|
|
120
|
+
for (const rel of rels) {
|
|
121
|
+
const parsed = inputs.parsedByRel.get(rel);
|
|
122
|
+
const record = inputs.byRel.get(rel);
|
|
123
|
+
const from = inputs.fileNodeIdByRel.get(rel);
|
|
124
|
+
const facts = inputs.tables.factsByRel.get(rel);
|
|
125
|
+
if (!parsed || !record || !from || !facts)
|
|
126
|
+
continue;
|
|
127
|
+
const testNodeId = inputs.testNodeIdByRel.get(rel);
|
|
128
|
+
for (const usage of collectUsages(parsed, facts.bindings).values()) {
|
|
129
|
+
const resolved = resolveUsage(inputs.tables, usage);
|
|
130
|
+
if (!resolved)
|
|
131
|
+
continue;
|
|
132
|
+
sink.addEdge({
|
|
133
|
+
from,
|
|
134
|
+
to: resolved.symbolNodeId,
|
|
135
|
+
type: 'references',
|
|
136
|
+
confidence: resolved.confidence,
|
|
137
|
+
path: rel,
|
|
138
|
+
hash: record.hash,
|
|
139
|
+
line: usage.line
|
|
140
|
+
});
|
|
141
|
+
if (usage.callLine !== null) {
|
|
142
|
+
sink.addEdge({
|
|
143
|
+
from,
|
|
144
|
+
to: resolved.symbolNodeId,
|
|
145
|
+
type: 'calls',
|
|
146
|
+
confidence: resolved.confidence,
|
|
147
|
+
path: rel,
|
|
148
|
+
hash: record.hash,
|
|
149
|
+
line: usage.callLine
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (testNodeId && !inputs.byRel.get(resolved.definingRel)?.isTest) {
|
|
153
|
+
sink.addEdge({
|
|
154
|
+
from: testNodeId,
|
|
155
|
+
to: resolved.symbolNodeId,
|
|
156
|
+
type: 'tests',
|
|
157
|
+
confidence: resolved.confidence,
|
|
158
|
+
path: rel,
|
|
159
|
+
hash: record.hash,
|
|
160
|
+
line: usage.line
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (!testNodeId)
|
|
165
|
+
continue;
|
|
166
|
+
for (const entry of facts.imports) {
|
|
167
|
+
const target = inputs.byRel.get(entry.targetRel);
|
|
168
|
+
if (!target || target.isTest)
|
|
169
|
+
continue;
|
|
170
|
+
const to = inputs.fileNodeIdByRel.get(entry.targetRel);
|
|
171
|
+
if (!to)
|
|
172
|
+
continue;
|
|
173
|
+
sink.addEdge({
|
|
174
|
+
from: testNodeId,
|
|
175
|
+
to,
|
|
176
|
+
type: 'tests',
|
|
177
|
+
confidence: 'exact',
|
|
178
|
+
path: rel,
|
|
179
|
+
hash: record.hash,
|
|
180
|
+
line: entry.line
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { tryNormalizeGraphPath } from '../../paths.js';
|
|
3
|
+
import { resolveSpecifier } from './ts-config.js';
|
|
4
|
+
function impliedFormat(context, record) {
|
|
5
|
+
try {
|
|
6
|
+
return ts.getImpliedNodeFormatForFile(record.abs, context.cache.getPackageJsonInfoCache(), context.host, context.options);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function buildForwardDependencies(context, inventory) {
|
|
13
|
+
const forward = new Map();
|
|
14
|
+
for (const record of inventory.files) {
|
|
15
|
+
const mode = impliedFormat(context, record);
|
|
16
|
+
const targets = new Set();
|
|
17
|
+
let preprocessed;
|
|
18
|
+
try {
|
|
19
|
+
preprocessed = ts.preProcessFile(record.text, true, true);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
forward.set(record.rel, []);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
for (const reference of preprocessed.importedFiles) {
|
|
26
|
+
const resolved = resolveSpecifier(context, reference.fileName, record.abs, mode);
|
|
27
|
+
if (!resolved)
|
|
28
|
+
continue;
|
|
29
|
+
const rel = tryNormalizeGraphPath(context.root, resolved.fileName);
|
|
30
|
+
if (rel === null || !inventory.byRel.has(rel))
|
|
31
|
+
continue;
|
|
32
|
+
targets.add(rel);
|
|
33
|
+
}
|
|
34
|
+
forward.set(record.rel, [...targets].sort());
|
|
35
|
+
}
|
|
36
|
+
return forward;
|
|
37
|
+
}
|
|
38
|
+
function invert(forward) {
|
|
39
|
+
const reverse = new Map();
|
|
40
|
+
for (const [from, targets] of forward) {
|
|
41
|
+
for (const target of targets) {
|
|
42
|
+
const bucket = reverse.get(target);
|
|
43
|
+
if (bucket)
|
|
44
|
+
bucket.push(from);
|
|
45
|
+
else
|
|
46
|
+
reverse.set(target, [from]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const [, importers] of reverse)
|
|
50
|
+
importers.sort();
|
|
51
|
+
return reverse;
|
|
52
|
+
}
|
|
53
|
+
export function selectExtractionTargets(context, inventory, changedPaths) {
|
|
54
|
+
if (changedPaths === null) {
|
|
55
|
+
return { targets: [...inventory.files], full: true, unknownChanged: [], unmappableChanged: 0 };
|
|
56
|
+
}
|
|
57
|
+
const seeds = [];
|
|
58
|
+
const unknownChanged = [];
|
|
59
|
+
let unmappableChanged = 0;
|
|
60
|
+
for (const candidate of changedPaths) {
|
|
61
|
+
const rel = tryNormalizeGraphPath(context.root, candidate);
|
|
62
|
+
if (rel === null) {
|
|
63
|
+
unmappableChanged += 1;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (inventory.byRel.has(rel))
|
|
67
|
+
seeds.push(rel);
|
|
68
|
+
else
|
|
69
|
+
unknownChanged.push(rel);
|
|
70
|
+
}
|
|
71
|
+
const forward = buildForwardDependencies(context, inventory);
|
|
72
|
+
const reverse = invert(forward);
|
|
73
|
+
const closure = new Set();
|
|
74
|
+
const queue = [...new Set(seeds)].sort();
|
|
75
|
+
for (const seed of queue)
|
|
76
|
+
closure.add(seed);
|
|
77
|
+
while (queue.length) {
|
|
78
|
+
const current = queue.shift();
|
|
79
|
+
if (current === undefined)
|
|
80
|
+
break;
|
|
81
|
+
for (const importer of reverse.get(current) ?? []) {
|
|
82
|
+
if (closure.has(importer))
|
|
83
|
+
continue;
|
|
84
|
+
closure.add(importer);
|
|
85
|
+
queue.push(importer);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const selected = new Set(closure);
|
|
89
|
+
for (const rel of closure) {
|
|
90
|
+
for (const dependency of forward.get(rel) ?? [])
|
|
91
|
+
selected.add(dependency);
|
|
92
|
+
}
|
|
93
|
+
const targets = inventory.files.filter((record) => selected.has(record.rel));
|
|
94
|
+
return {
|
|
95
|
+
targets,
|
|
96
|
+
full: false,
|
|
97
|
+
unknownChanged: [...new Set(unknownChanged)].sort(),
|
|
98
|
+
unmappableChanged
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import ts from 'typescript';
|
|
5
|
+
const FALLBACK_OPTIONS = {
|
|
6
|
+
allowJs: true,
|
|
7
|
+
checkJs: false,
|
|
8
|
+
target: ts.ScriptTarget.ESNext,
|
|
9
|
+
module: ts.ModuleKind.ESNext,
|
|
10
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
11
|
+
jsx: ts.JsxEmit.ReactJSX,
|
|
12
|
+
resolveJsonModule: false
|
|
13
|
+
};
|
|
14
|
+
export function sanitizeCompilerOptions(options) {
|
|
15
|
+
const sanitized = { ...options };
|
|
16
|
+
delete sanitized.plugins;
|
|
17
|
+
delete sanitized.outFile;
|
|
18
|
+
delete sanitized.out;
|
|
19
|
+
delete sanitized.declarationDir;
|
|
20
|
+
delete sanitized.tsBuildInfoFile;
|
|
21
|
+
delete sanitized.incremental;
|
|
22
|
+
delete sanitized.composite;
|
|
23
|
+
sanitized.noEmit = true;
|
|
24
|
+
sanitized.declaration = false;
|
|
25
|
+
sanitized.declarationMap = false;
|
|
26
|
+
sanitized.sourceMap = false;
|
|
27
|
+
sanitized.skipLibCheck = true;
|
|
28
|
+
sanitized.allowJs = true;
|
|
29
|
+
sanitized.checkJs = false;
|
|
30
|
+
sanitized.types = [];
|
|
31
|
+
return sanitized;
|
|
32
|
+
}
|
|
33
|
+
function readConfigOptions(root) {
|
|
34
|
+
for (const name of ['tsconfig.json', 'jsconfig.json']) {
|
|
35
|
+
const absolute = path.join(root, name);
|
|
36
|
+
let raw;
|
|
37
|
+
try {
|
|
38
|
+
raw = fs.readFileSync(absolute);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const read = ts.readConfigFile(absolute, () => raw.toString('utf8'));
|
|
44
|
+
if (read.error || !read.config)
|
|
45
|
+
continue;
|
|
46
|
+
const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, root, undefined, absolute);
|
|
47
|
+
return {
|
|
48
|
+
options: sanitizeCompilerOptions(parsed.options),
|
|
49
|
+
rel: name,
|
|
50
|
+
hash: crypto.createHash('sha256').update(raw).digest('hex')
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return { options: sanitizeCompilerOptions(FALLBACK_OPTIONS), rel: null, hash: null };
|
|
54
|
+
}
|
|
55
|
+
function createResolutionHost() {
|
|
56
|
+
const existsCache = new Map();
|
|
57
|
+
const dirCache = new Map();
|
|
58
|
+
const host = {
|
|
59
|
+
fileExists: (fileName) => {
|
|
60
|
+
const cached = existsCache.get(fileName);
|
|
61
|
+
if (cached !== undefined)
|
|
62
|
+
return cached;
|
|
63
|
+
const value = ts.sys.fileExists(fileName);
|
|
64
|
+
existsCache.set(fileName, value);
|
|
65
|
+
return value;
|
|
66
|
+
},
|
|
67
|
+
readFile: (fileName) => ts.sys.readFile(fileName),
|
|
68
|
+
directoryExists: (directoryName) => {
|
|
69
|
+
const cached = dirCache.get(directoryName);
|
|
70
|
+
if (cached !== undefined)
|
|
71
|
+
return cached;
|
|
72
|
+
const value = ts.sys.directoryExists(directoryName);
|
|
73
|
+
dirCache.set(directoryName, value);
|
|
74
|
+
return value;
|
|
75
|
+
},
|
|
76
|
+
getDirectories: (directoryName) => ts.sys.getDirectories(directoryName),
|
|
77
|
+
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames
|
|
78
|
+
};
|
|
79
|
+
if (typeof ts.sys.realpath === 'function') {
|
|
80
|
+
const realpath = ts.sys.realpath.bind(ts.sys);
|
|
81
|
+
host.realpath = (fileName) => realpath(fileName);
|
|
82
|
+
}
|
|
83
|
+
return host;
|
|
84
|
+
}
|
|
85
|
+
export function createResolutionContext(root) {
|
|
86
|
+
const absoluteRoot = path.resolve(root);
|
|
87
|
+
const config = readConfigOptions(absoluteRoot);
|
|
88
|
+
const host = createResolutionHost();
|
|
89
|
+
const canonical = ts.sys.useCaseSensitiveFileNames
|
|
90
|
+
? (value) => value
|
|
91
|
+
: (value) => value.toLowerCase();
|
|
92
|
+
const cache = ts.createModuleResolutionCache(absoluteRoot, canonical, config.options);
|
|
93
|
+
return {
|
|
94
|
+
root: absoluteRoot,
|
|
95
|
+
options: config.options,
|
|
96
|
+
configRel: config.rel,
|
|
97
|
+
configHash: config.hash,
|
|
98
|
+
host,
|
|
99
|
+
cache
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export function scriptKindForPath(relativePath) {
|
|
103
|
+
const lower = relativePath.toLowerCase();
|
|
104
|
+
if (lower.endsWith('.tsx'))
|
|
105
|
+
return ts.ScriptKind.TSX;
|
|
106
|
+
if (lower.endsWith('.jsx'))
|
|
107
|
+
return ts.ScriptKind.JSX;
|
|
108
|
+
if (lower.endsWith('.mts') || lower.endsWith('.cts') || lower.endsWith('.ts'))
|
|
109
|
+
return ts.ScriptKind.TS;
|
|
110
|
+
if (lower.endsWith('.mjs') || lower.endsWith('.cjs') || lower.endsWith('.js'))
|
|
111
|
+
return ts.ScriptKind.JS;
|
|
112
|
+
return ts.ScriptKind.TS;
|
|
113
|
+
}
|
|
114
|
+
export function createCodeSourceFile(context, record) {
|
|
115
|
+
let impliedNodeFormat;
|
|
116
|
+
try {
|
|
117
|
+
impliedNodeFormat = ts.getImpliedNodeFormatForFile(record.abs, context.cache.getPackageJsonInfoCache(), context.host, context.options);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
impliedNodeFormat = undefined;
|
|
121
|
+
}
|
|
122
|
+
const options = {
|
|
123
|
+
languageVersion: context.options.target ?? ts.ScriptTarget.ESNext,
|
|
124
|
+
...(impliedNodeFormat === undefined ? {} : { impliedNodeFormat })
|
|
125
|
+
};
|
|
126
|
+
return ts.createSourceFile(record.abs, record.text, options, true, scriptKindForPath(record.rel));
|
|
127
|
+
}
|
|
128
|
+
export function modeForSpecifier(context, sourceFile, usage) {
|
|
129
|
+
try {
|
|
130
|
+
return ts.getModeForUsageLocation(sourceFile, usage, context.options);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export function resolveSpecifier(context, specifier, containingFile, mode) {
|
|
137
|
+
if (!specifier)
|
|
138
|
+
return null;
|
|
139
|
+
let resolved;
|
|
140
|
+
try {
|
|
141
|
+
resolved = ts.resolveModuleName(specifier, containingFile, context.options, context.host, context.cache, undefined, mode);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const module = resolved.resolvedModule;
|
|
147
|
+
if (!module)
|
|
148
|
+
return null;
|
|
149
|
+
return { fileName: module.resolvedFileName, external: module.isExternalLibraryImport === true };
|
|
150
|
+
}
|
|
151
|
+
export function isBareSpecifier(specifier) {
|
|
152
|
+
if (!specifier)
|
|
153
|
+
return false;
|
|
154
|
+
if (specifier.startsWith('.'))
|
|
155
|
+
return false;
|
|
156
|
+
if (specifier.startsWith('/'))
|
|
157
|
+
return false;
|
|
158
|
+
if (/^[A-Za-z]:[\\/]/.test(specifier))
|
|
159
|
+
return false;
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const CODE_GRAPH_EXTRACTOR_ID = 'code';
|
|
2
|
+
export const CODE_GRAPH_EXTRACTOR_REVISION = '1.0.0';
|
|
3
|
+
export const MAX_REEXPORT_DEPTH = 8;
|
|
4
|
+
export const CODE_SYMBOL_KINDS = [
|
|
5
|
+
'function',
|
|
6
|
+
'class',
|
|
7
|
+
'interface',
|
|
8
|
+
'type',
|
|
9
|
+
'enum',
|
|
10
|
+
'namespace',
|
|
11
|
+
'const',
|
|
12
|
+
'let',
|
|
13
|
+
'var',
|
|
14
|
+
'default'
|
|
15
|
+
];
|
|
16
|
+
export function estimateTokenCost(length) {
|
|
17
|
+
return Math.max(1, Math.ceil(Math.max(0, length) / 4));
|
|
18
|
+
}
|