@wrongstack/tools 0.299.0 → 0.300.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/dist/audit.js +6 -2
- package/dist/bash.js +6 -2
- package/dist/builtin.js +1473 -295
- package/dist/codebase-index/import-extractor.d.ts +39 -0
- package/dist/codebase-index/index.js +1396 -255
- package/dist/codebase-index/languages.d.ts +24 -0
- package/dist/codebase-index/module-resolver.d.ts +78 -0
- package/dist/codebase-index/module-roots.d.ts +81 -0
- package/dist/codebase-index/parser-output.d.ts +29 -0
- package/dist/codebase-index/project-server.js +1379 -236
- package/dist/codebase-index/rs-parser.d.ts +22 -0
- package/dist/codebase-index/schema.d.ts +24 -1
- package/dist/codebase-index/worker.js +1381 -238
- package/dist/codebase-index/writer-graph-helpers.d.ts +17 -5
- package/dist/codebase-index/writer-ref-mapper.d.ts +3 -0
- package/dist/codebase-index/writer-schema.d.ts +15 -3
- package/dist/codebase-index/writer.d.ts +76 -3
- package/dist/exec.js +35 -2
- package/dist/format.js +6 -2
- package/dist/index.js +1473 -295
- package/dist/install.js +6 -2
- package/dist/json.js +51 -2
- package/dist/languages/index.js +6 -2
- package/dist/lint.js +6 -2
- package/dist/outdated.js +6 -2
- package/dist/pack.js +1473 -295
- package/dist/process-registry.d.ts +6 -0
- package/dist/process-registry.js +6 -2
- package/dist/ps-slash.js +6 -2
- package/dist/read.js +1387 -244
- package/dist/test.js +6 -2
- package/dist/tool-tier.js +1473 -295
- package/dist/typecheck.js +6 -2
- package/package.json +3 -3
- package/dist/codebase-index/refs-extractor.d.ts +0 -11
|
@@ -22,4 +22,28 @@ export declare const INDEXABLE_EXTENSIONS: readonly string[];
|
|
|
22
22
|
export declare function detectLang(file: string): SymbolLang | null;
|
|
23
23
|
/** True when the path is eligible for the codebase index. */
|
|
24
24
|
export declare function isIndexablePath(file: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* A group of {@link SymbolLang}s whose symbols may legitimately reference each
|
|
27
|
+
* other by bare name.
|
|
28
|
+
*
|
|
29
|
+
* Ref resolution matches `to_name` against `symbols.name`. Done globally that
|
|
30
|
+
* is actively wrong once more than one language is indexed: `main`, `New`,
|
|
31
|
+
* `Get`, `String`, `__init__`, `Parse` and `Config` all exist in half a dozen
|
|
32
|
+
* languages at once, so a Go call would resolve to a TypeScript declaration and
|
|
33
|
+
* draw a Code Atlas edge between files that have nothing to do with each other.
|
|
34
|
+
* Scoping resolution to a family keeps cross-language noise out while still
|
|
35
|
+
* letting genuinely mixed families (`.ts`/`.tsx` + the script block of a
|
|
36
|
+
* `.vue`/`.svelte` file, `.java`/`.kt` on the JVM) resolve into one another.
|
|
37
|
+
*/
|
|
38
|
+
export type LangFamily = 'js' | 'go' | 'py' | 'rs' | 'jvm' | 'dotnet' | 'c' | 'ruby' | 'php' | 'swift' | 'dart' | 'elixir' | 'haskell' | 'zig' | 'lua' | 'r' | 'shell' | 'sql' | 'data' | 'web' | 'proto' | 'graphql' | 'other';
|
|
39
|
+
/**
|
|
40
|
+
* `(lang, family)` pairs, for mirroring the mapping into SQLite so ref
|
|
41
|
+
* resolution can join on it instead of expanding a family into an IN-list of
|
|
42
|
+
* placeholders on every statement.
|
|
43
|
+
*/
|
|
44
|
+
export declare const LANG_FAMILY_ENTRIES: ReadonlyArray<readonly [SymbolLang, LangFamily]>;
|
|
45
|
+
/** Family a language resolves within. */
|
|
46
|
+
export declare function languageFamily(lang: SymbolLang): LangFamily;
|
|
47
|
+
/** Every language in the same resolution family as `lang`, including itself. */
|
|
48
|
+
export declare function familyMembers(lang: SymbolLang): SymbolLang[];
|
|
25
49
|
//# sourceMappingURL=languages.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve an import specifier to the indexed file it refers to.
|
|
3
|
+
*
|
|
4
|
+
* Runs once, after indexing, filling `refs.to_file`. Doing it here rather than
|
|
5
|
+
* in the graph readers is what makes the Code Atlas language-agnostic: the
|
|
6
|
+
* readers only ever see "this ref points at that file", and never need to know
|
|
7
|
+
* that Go import paths come from `go.mod` while Python's come from a directory
|
|
8
|
+
* chain — knowledge that is not in the database and cannot be recovered from it.
|
|
9
|
+
*
|
|
10
|
+
* Resolution is best-effort by design. An unresolved specifier (a stdlib or
|
|
11
|
+
* third-party module, or an ecosystem whose layout we don't model) simply
|
|
12
|
+
* leaves `to_file` NULL, and the graph readers fall back to the ref's resolved
|
|
13
|
+
* symbol id. Guessing would draw edges that aren't there.
|
|
14
|
+
*/
|
|
15
|
+
import { type ProjectStructure } from './module-roots.js';
|
|
16
|
+
import type { SymbolLang } from './schema.js';
|
|
17
|
+
export declare class ModuleResolver {
|
|
18
|
+
private readonly structure;
|
|
19
|
+
/** Lowercased portable path → the path as indexed (case is preserved). */
|
|
20
|
+
private readonly byPath;
|
|
21
|
+
/** Lowercased portable directory → files directly inside it, as indexed. */
|
|
22
|
+
private readonly byDir;
|
|
23
|
+
/** Normalized namespace → the file declaring it (first by path, stable). */
|
|
24
|
+
private readonly byNamespace;
|
|
25
|
+
constructor(structure: ProjectStructure, files: readonly string[], namespaces?: ReadonlyArray<{
|
|
26
|
+
name: string;
|
|
27
|
+
file: string;
|
|
28
|
+
}>);
|
|
29
|
+
/**
|
|
30
|
+
* Resolve `specifier` as written in `fromFile`.
|
|
31
|
+
* Returns the indexed target path, or `undefined` when it is external or
|
|
32
|
+
* cannot be located.
|
|
33
|
+
*/
|
|
34
|
+
resolve(fromFile: string, lang: SymbolLang, specifier: string): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve a namespace specifier to the file declaring it.
|
|
37
|
+
*
|
|
38
|
+
* Tried whole first, then with the trailing segment dropped: `using Foo.Bar`
|
|
39
|
+
* names a namespace outright, while PHP's `use App\Models\User` names a
|
|
40
|
+
* *class* inside `App\Models`, so the prefix is what was declared.
|
|
41
|
+
*/
|
|
42
|
+
private resolveNamespace;
|
|
43
|
+
private lookup;
|
|
44
|
+
/**
|
|
45
|
+
* Try `base` verbatim, then `base` + each extension, then each directory
|
|
46
|
+
* entry point inside `base`.
|
|
47
|
+
*/
|
|
48
|
+
private lookupWithExtensions;
|
|
49
|
+
/**
|
|
50
|
+
* A representative indexed file inside `dir`, for ecosystems whose import
|
|
51
|
+
* unit is a directory rather than a file (Go packages, JVM wildcard imports).
|
|
52
|
+
*
|
|
53
|
+
* The choice is deterministic — a file named after the directory, else the
|
|
54
|
+
* first by name — so the same import always produces the same edge. Package
|
|
55
|
+
* grouping is unaffected either way: every file in the directory carries the
|
|
56
|
+
* same package label, so the package-level edge is exact regardless of which
|
|
57
|
+
* member represents it.
|
|
58
|
+
*/
|
|
59
|
+
private representativeIn;
|
|
60
|
+
/** Relative specifiers, then workspace package names and their subpaths. */
|
|
61
|
+
private resolveJs;
|
|
62
|
+
/** Go import paths are absolute module paths; a package is a directory. */
|
|
63
|
+
private resolveGo;
|
|
64
|
+
/**
|
|
65
|
+
* `import a.b.c` / `from a.b import c`, plus PEP 328 relative imports whose
|
|
66
|
+
* leading dots the extractor preserves (`.sibling`, `..parent.mod`).
|
|
67
|
+
*/
|
|
68
|
+
private resolvePython;
|
|
69
|
+
/** `use crate::a::b`, `use super::x`, `use self::y`, `use other_crate::z`. */
|
|
70
|
+
private resolveRust;
|
|
71
|
+
/** `com.example.Thing` and `com.example.*` against JVM source roots. */
|
|
72
|
+
private resolveJvm;
|
|
73
|
+
/** `#include "foo/bar.h"` — quoted form only; `<…>` is a system header. */
|
|
74
|
+
private resolveInclude;
|
|
75
|
+
/** `require_relative 'x'` is relative; `require 'x'` is looked up under lib/. */
|
|
76
|
+
private resolveRuby;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=module-resolver.d.ts.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ecosystem-aware project structure detection.
|
|
3
|
+
*
|
|
4
|
+
* The Code Atlas groups files into "packages". That grouping used to be two
|
|
5
|
+
* hardcoded npm-monorepo rules (`packages/<x>` → `@wrongstack/<x>`, `apps/<x>` →
|
|
6
|
+
* `app:<x>`), which put every Go, Python, Rust or JVM file of any other repo
|
|
7
|
+
* into a single `(root)` blob with no internal structure.
|
|
8
|
+
*
|
|
9
|
+
* This module derives the grouping from the markers each ecosystem actually
|
|
10
|
+
* uses, and — importantly — at the granularity that ecosystem's developers
|
|
11
|
+
* think in:
|
|
12
|
+
*
|
|
13
|
+
* | ecosystem | marker | one package node is… |
|
|
14
|
+
* |-----------|-----------------------------|---------------------------------|
|
|
15
|
+
* | npm | `package.json` | the package (marker directory) |
|
|
16
|
+
* | Cargo | `Cargo.toml` | the crate (marker directory) |
|
|
17
|
+
* | Go | `go.mod` | **a directory** — Go's own unit |
|
|
18
|
+
* | Python | `pyproject.toml`/`setup.py` | the dotted package (`a.b.c`) |
|
|
19
|
+
* | Maven | `pom.xml` | the project |
|
|
20
|
+
* | Gradle | `build.gradle[.kts]` | the project |
|
|
21
|
+
* | .NET | `*.csproj` | the project |
|
|
22
|
+
*
|
|
23
|
+
* Detection runs once per index over the already-discovered (and already
|
|
24
|
+
* gitignore-filtered) file list, so it costs a bounded number of reads rather
|
|
25
|
+
* than a second tree walk.
|
|
26
|
+
*/
|
|
27
|
+
/** Package-manager ecosystem a module root belongs to. */
|
|
28
|
+
export type ModuleRootKind = 'npm' | 'cargo' | 'go' | 'python' | 'maven' | 'gradle' | 'dotnet';
|
|
29
|
+
export interface ModuleRoot {
|
|
30
|
+
/** Absolute directory holding the marker file, forward-slash normalized. */
|
|
31
|
+
dir: string;
|
|
32
|
+
kind: ModuleRootKind;
|
|
33
|
+
/** Human-facing grouping label, e.g. `@scope/pkg`, `crate:parser`. */
|
|
34
|
+
name: string;
|
|
35
|
+
/**
|
|
36
|
+
* Import prefix this root owns, when its ecosystem has one:
|
|
37
|
+
* the `module` line of `go.mod`, the crate name for Cargo, the distribution
|
|
38
|
+
* name for Python. `undefined` when imports are not prefixed by the root.
|
|
39
|
+
*/
|
|
40
|
+
importPath?: string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Directories imports resolve against, forward-slash normalized absolute
|
|
43
|
+
* paths. JVM layouts put this at `src/main/java`; Python projects commonly
|
|
44
|
+
* use `src/`; most ecosystems just use the root directory itself.
|
|
45
|
+
*/
|
|
46
|
+
sourceRoots: string[];
|
|
47
|
+
}
|
|
48
|
+
/** Everything the resolver and the package labeller need, computed once. */
|
|
49
|
+
export interface ProjectStructure {
|
|
50
|
+
projectRoot: string;
|
|
51
|
+
/** Sorted longest-dir-first so a nearest-ancestor lookup is a linear scan. */
|
|
52
|
+
roots: ModuleRoot[];
|
|
53
|
+
}
|
|
54
|
+
/** Normalize to forward slashes; every path in this module is compared this way. */
|
|
55
|
+
export declare function toPortablePath(file: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Detect every module root reachable from the indexed file set.
|
|
58
|
+
*
|
|
59
|
+
* Candidate directories are the ancestors of directories that actually contain
|
|
60
|
+
* files of the relevant language, so a repo with no Go code never stats a
|
|
61
|
+
* single `go.mod`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function detectModuleRoots(projectRoot: string, files: readonly string[]): Promise<ProjectStructure>;
|
|
64
|
+
/** Nearest module root that contains `file`, preferring the deepest match. */
|
|
65
|
+
export declare function findOwningRoot(structure: ProjectStructure, file: string, kinds?: readonly ModuleRootKind[]): ModuleRoot | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Legacy npm-monorepo fallback, kept for repos with no manifest at all (and for
|
|
68
|
+
* the existing tests that assert on it). Only consulted when marker detection
|
|
69
|
+
* finds no owning root.
|
|
70
|
+
*/
|
|
71
|
+
export declare function derivePackageFromLayout(filePath: string): string | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Assign every indexed file its Code Atlas package label.
|
|
74
|
+
*
|
|
75
|
+
* Go is grouped per directory because that is Go's compilation unit — one node
|
|
76
|
+
* per module would collapse an entire repository into a single dot. Python is
|
|
77
|
+
* grouped by its dotted package for the same reason. Every other ecosystem is
|
|
78
|
+
* grouped by its manifest directory.
|
|
79
|
+
*/
|
|
80
|
+
export declare function assignPackageLabels(structure: ProjectStructure, files: readonly string[]): Map<string, string>;
|
|
81
|
+
//# sourceMappingURL=module-roots.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared decoding for the out-of-process parsers (Go's `go/ast`, Python's
|
|
3
|
+
* `ast`).
|
|
4
|
+
*
|
|
5
|
+
* Both emit `{"symbols": [...], "refs": [...]}` from a single run, so symbols
|
|
6
|
+
* and cross-references cost one child process rather than two — the same
|
|
7
|
+
* one-walk-yields-both shape the in-process TypeScript parser has.
|
|
8
|
+
*
|
|
9
|
+
* The older array-only payload (`[{name, kind, …}]`) is still accepted: parser
|
|
10
|
+
* scripts are written to a temp file that can outlive the process that wrote
|
|
11
|
+
* it, and a stale script must degrade to "symbols but no edges", never to a
|
|
12
|
+
* hard parse failure that drops the file from the index entirely.
|
|
13
|
+
*/
|
|
14
|
+
import type { Ref, SymbolLang } from './schema.js';
|
|
15
|
+
export interface RawParsedSymbol {
|
|
16
|
+
name: string;
|
|
17
|
+
kind: string;
|
|
18
|
+
line: number;
|
|
19
|
+
col: number;
|
|
20
|
+
signature: string;
|
|
21
|
+
scope: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ParsedParserOutput {
|
|
24
|
+
symbols: RawParsedSymbol[];
|
|
25
|
+
refs: Ref[];
|
|
26
|
+
}
|
|
27
|
+
/** Decode a parser child process's stdout. Never throws. */
|
|
28
|
+
export declare function parseParserOutput(stdout: string, lang: SymbolLang): ParsedParserOutput;
|
|
29
|
+
//# sourceMappingURL=parser-output.d.ts.map
|