@g3nomaly/analyze 0.1.5 → 0.1.6
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 +21 -7
- package/dist/api/create-docs.d.ts +10 -4
- package/dist/api/graph.d.ts +3 -2
- package/dist/api/path.d.ts +143 -0
- package/dist/api/refs.d.ts +23 -14
- package/dist/api/search.d.ts +12 -10
- package/dist/api/target.d.ts +3 -2
- package/dist/cli.js +768 -162
- package/dist/index.d.ts +2 -1
- package/dist/index.js +654 -119
- package/dist/model/index.d.ts +4 -1
- package/dist/model/registry.d.ts +14 -0
- package/dist/query/graph.d.ts +2 -1
- package/dist/query/name-search.d.ts +19 -1
- package/dist/retrieval/describe.d.ts +33 -1
- package/dist/retrieval/graph-export.d.ts +21 -1
- package/dist/retrieval/index.d.ts +5 -4
- package/dist/retrieval/report.d.ts +14 -0
- package/dist/retrieval/resolve.d.ts +25 -1
- package/dist/retrieval/retriever.d.ts +67 -7
- package/dist/retrieval/walk.d.ts +66 -0
- package/dist/scanner/code/calls.d.ts +39 -12
- package/dist/scanner/code/exports.d.ts +70 -0
- package/dist/scanner/code/extract.d.ts +11 -3
- package/dist/scanner/code/imports.d.ts +42 -1
- package/dist/scanner/code/language.d.ts +4 -0
- package/dist/scanner/code/symbols.d.ts +2 -2
- package/dist/scanner/files.d.ts +3 -1
- package/dist/scanner/graph/communities.d.ts +3 -2
- package/dist/scanner/index.d.ts +1 -1
- package/dist/scanner/packages.d.ts +4 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ cd ~/code/my-repo
|
|
|
11
11
|
bunx @g3nomaly/analyze create_docs
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
This writes `analyze_out/index.html` in the repository, and the query commands keep their scan cache in `analyze_out/` as well. analyze puts a `.gitignore` holding `*` in `analyze_out/`, so git skips the directory. It writes nothing else in the repository.
|
|
14
|
+
This writes `analyze_out/index.html` in the repository, and the query commands keep their scan cache in `analyze_out/` as well. analyze puts a `.gitignore` holding `*` in `analyze_out/`, so git skips the directory. It writes nothing else in the repository. `--out <file>` writes the site to that file instead, and then `create_docs` writes nothing in the repository.
|
|
15
15
|
|
|
16
16
|
## What it skips
|
|
17
17
|
|
|
@@ -30,34 +30,46 @@ On top of `.gitignore`, the scan skips `node_modules/`, `dist/`, `build/`, `out/
|
|
|
30
30
|
| Tasks | The plans, phases and tasks that task-manager keeps, in `skills.settings.filetreeRoot` of `.g3n.config.json` (default `docs/task-manager`) |
|
|
31
31
|
| Packages | A directory with a `package.json`, `pyproject.toml`, `Cargo.toml`, `go.mod`, `pom.xml`, `build.gradle`, `composer.json`, `.csproj`, `.gemspec`, `Gemfile`, `vcpkg.json` or `CMakeLists.txt` is shown as a package: an app, a library or a workspace. A `CMakeLists.txt` counts when it calls `project(`, builds a library or an executable (`add_library`, `add_executable`, or a macro whose name holds `library` or `executable`), or sits beside an `include/` folder. In a `src/`, `test/`, `tests/`, `cmake/` or `examples/` directory only `project(` counts, so `libs/<lib>/src/CMakeLists.txt` stays part of `libs/<lib>` |
|
|
32
32
|
|
|
33
|
-
Every page, entry, parameter and field is a node of one graph. Edges connect a type to where it is used, a source file to the files it includes or imports, a function to the functions it calls, a term to the text that uses it, a decision to the code it affects, a table to its foreign keys and queries, and a task to the code, docs and decisions it names and to the tasks it depends on. One registry in `src/model/registry.ts` defines every kind of node and edge.
|
|
33
|
+
Every page, entry, parameter and field is a node of one graph. Edges connect a type to where it is used, a source file to the files it includes or imports, a function to the functions it calls and to those it passes on as values, a term to the text that uses it, a decision to the code it affects, a table to its foreign keys and queries, and a task to the code, docs and decisions it names and to the tasks it depends on. One registry in `src/model/registry.ts` defines every kind of node and edge.
|
|
34
34
|
|
|
35
35
|
## Querying
|
|
36
36
|
|
|
37
37
|
```sh
|
|
38
|
-
g3n-analyze search how are routes chosen # by words and by meaning
|
|
38
|
+
g3n-analyze search how are routes chosen # by words and by meaning, per section
|
|
39
39
|
g3n-analyze show choose_route # one page or entry in full
|
|
40
40
|
g3n-analyze refs Sailing --kind term # what it links to, and what links to it
|
|
41
|
+
g3n-analyze refs Rates.find --incoming --depth 3 # what links to it, and what links to those
|
|
42
|
+
g3n-analyze path Rates.price LineItem.perTeu # the shortest chain of edges from one to the other
|
|
41
43
|
g3n-analyze list --kind task # every task with its status
|
|
42
44
|
g3n-analyze graph --level packages --json # which package uses which, as nodes and edges
|
|
43
45
|
g3n-analyze list --community 3 # every page and entry of one community
|
|
44
46
|
g3n-analyze show TASK-002 --json # a task, as JSON
|
|
45
47
|
```
|
|
46
48
|
|
|
49
|
+
`search` searches each section on its own and lists the hits under one heading per section, so the docs of a repository never crowd out its code. `-n` is the most hits per section, 5 by default, and `--section` keeps to one section. In the JSON the hits come in the same order, each with its `section`. Hits are best first in each section. `score` is set only for a match by meaning, from 0 to 1; a match by words has `score: null`, and its place in the list is its rank.
|
|
50
|
+
|
|
51
|
+
Hits that match the same way, with the same kind, type, title, summary, score and matched member, such as nine `hooks.json` files that say nothing, are one hit. It says how many nodes it stands for and lists the path of each, in `duplicates` in the JSON. A hit found through a parameter, field, operation or definition names it, as in `interface InstallerIO (field hashFile)`, and so does the message for a name that fits several nodes. A name that fits no node suggests the closest names.
|
|
52
|
+
|
|
47
53
|
When nothing matches, `search` lists up to three weak matches by meaning instead, under a note and with `weak: true` in the JSON. Rewording the query often finds a better one. Output is markdown, or JSON with `--json`. `--from analyze_out/index.html` queries a built site without the repository. `g3n-analyze --help` lists every option, node kind, section and edge kind.
|
|
48
54
|
|
|
55
|
+
`refs --depth <n>` follows the edges `n` hops, one hop at a time in each direction, and prints each hop indented under the reference it follows. A node is listed once. `--edge`, `--incoming` and `--outgoing` apply at every hop; `--kind` and `--section` only pick the node to start from. `refs` lists at most 50 references over every hop, or `-n`, and says how many more it left out. `path <from> <to>` follows edges the way they point, so `path a b` and `path b a` differ; `--edge` keeps it to some kinds. A name with spaces goes in quotes.
|
|
56
|
+
|
|
57
|
+
The commands exit with 0 when they answer, also for a search that finds nothing, with 1 for a node that does not exist, a name that fits several nodes, a `path` with no chain, or a repository or site that cannot be read, and with 2 for a call that is not valid, such as an unknown flag.
|
|
58
|
+
|
|
49
59
|
`graph` exports the whole graph in one call. `--level` picks how much of it: `files`, `entries` and `all` are the levels of the graph page of the site, and `packages` and `communities` sum the edges between packages or communities. `--kind`, `--section`, `--community` and `--edge` narrow the nodes and edges. An edge of a node the level leaves out, such as a call at the `files` level, counts for the node that holds it, such as its file.
|
|
50
60
|
|
|
51
61
|
### Communities
|
|
52
62
|
|
|
53
|
-
A **community** is a group of nodes that link to each other more than to the rest, such as the classes and functions of one feature. Each scan splits the graph once, with the Louvain method, over every page and entry; a parameter or field is in the community of its entry, and a folder or package is in none. The community is a value of the node: `graph --level communities` lists them with their ids, `--community <id>` narrows `list`, `search`, `show`, `refs` and `graph` to one, and every node of a `graph` export carries its id. On the graph page of the site, dots can be colored by community and one community can be shown on its own.
|
|
63
|
+
A **community** is a group of nodes that link to each other more than to the rest, such as the classes and functions of one feature. Each scan splits the graph once, with the Louvain method, over every page and entry; a parameter or field is in the community of its entry, and a folder or package is in none, nor is a page or entry that would be alone in one. The community is a value of the node: `graph --level communities` lists them with their ids, their size in pages and entries (a parameter or field counts with its entry) and their five best-linked pages and entries, `--community <id>` narrows `list`, `search`, `show`, `refs` and `graph` to one, and every node of a `graph` export carries its id. On the graph page of the site, dots can be colored by community and one community can be shown on its own.
|
|
54
64
|
|
|
55
65
|
### How code links
|
|
56
66
|
|
|
57
67
|
- **Imports**: C and C++ `#include`, JavaScript and TypeScript imports, and Python imports link to the file of the repository they name. An include resolves next to the including file, then against every file whose path ends with it, the closest winning. A TypeScript import resolves a relative path, a package of the repository by name (`@scope/core`), or a path alias (`@/lib/api`). A header or package from outside the repository links to nothing.
|
|
58
68
|
- **What a file sees**: in C, C++, JavaScript, TypeScript and Python, a file sees itself and the files it imports, directly or through other files. A type name or a call only links to a declaration in a file it sees, so a common name never links across the repository. In the other languages every file is seen, and a type name links to the closest declaration of that name.
|
|
59
69
|
- **Types**: a qualified C++ name such as `geo::Point` only links to a `Point` inside `geo`. A type declared in a C or C++ source file is seen only in that file.
|
|
60
|
-
- **Calls**: a call links when it names one function: by name, through a namespace or type (`geo::distance()`, `Timer.once()`), through `this` or `self`, or through a parameter or field whose declared type is known. A call through a local variable, a module alias such as `helpers.go()`, or any other expression links nowhere, since its type is unknown. A bare call inside a JavaScript, TypeScript or Python method never means a method of its own class. A C++ method declared in a header and defined in a source file is called at its declaration.
|
|
70
|
+
- **Calls**: a call links when it names one function: by name, through a namespace or type (`geo::distance()`, `Timer.once()`), through `this` or `self`, or through a parameter or field whose declared type is known. A call through a local variable, a module alias such as `helpers.go()`, or any other expression links nowhere, since its type is unknown. A bare call inside a JavaScript, TypeScript or Python method never means a method of its own class. A C++ method declared in a header and defined in a source file is called at its declaration. Only the calls inside a function or method link: code at the top level of a file, such as the callbacks a CLI registers there, belongs to no function.
|
|
71
|
+
- **Values**: a function handed on without a call, such as the callback in `run(onDone)`, the entry of `{ add: addCommand }`, an element of `[first, second]` or `this.flush`, links as `passes`. It links the way a call of that name would. A name the function binds itself, as a parameter, a local, a loop variable or a lambda parameter, links nowhere, and nor does a getter or setter, which reading runs.
|
|
72
|
+
- **Examples**: the generated example of a JavaScript or TypeScript symbol imports it the way code outside its package does: from the package name, or from a subpath of its `exports` such as `@scope/core/hash`, under the name the entry file there exports it as, through `export … from`. A symbol no package exports has no import line.
|
|
61
73
|
|
|
62
74
|
## From hooks
|
|
63
75
|
|
|
@@ -80,20 +92,22 @@ const callers = await refs({
|
|
|
80
92
|
});
|
|
81
93
|
```
|
|
82
94
|
|
|
83
|
-
`createDocs`, `search`, `show`, `refs`, `list` and `graph` take the options of the CLI as fields.
|
|
95
|
+
`createDocs`, `search`, `show`, `refs`, `path`, `list` and `graph` take the options of the CLI as fields. `path` takes its two nodes as `start` and `end`, since `from` names a site to read.
|
|
84
96
|
|
|
85
97
|
## Development
|
|
86
98
|
|
|
87
99
|
Run every command from this directory.
|
|
88
100
|
|
|
89
101
|
```sh
|
|
90
|
-
bun run build # web app, CLI and library into dist/
|
|
102
|
+
bun run build # web app, CLI and library into dist/, examples into build/
|
|
91
103
|
bun run typecheck
|
|
92
104
|
bun test # unit tests
|
|
93
105
|
bun run test:integration # builds first
|
|
94
106
|
bun run analyze -- --help # the CLI from source, after one build
|
|
95
107
|
```
|
|
96
108
|
|
|
109
|
+
The build also runs a set of queries on the g3n monorepo and writes what each prints, as text and as JSON, to `build/examples/`, beside the site it queries. Its `README.md` lists them. `build/` is gitignored and never ships. The queries are in `scripts/examples.ts`.
|
|
110
|
+
|
|
97
111
|
The web primitives in `src/web/components/shadcn/` are installed with `@g3nomaly/ui`. The reasons behind the design are in [`decisions.md`](decisions.md).
|
|
98
112
|
|
|
99
113
|
## License
|
|
@@ -4,6 +4,8 @@ import { type PackageRole } from '../model';
|
|
|
4
4
|
* Schema of the `createDocs` options.
|
|
5
5
|
*
|
|
6
6
|
* @property title - Site title. Default: the name of the repository directory.
|
|
7
|
+
* @property out - Path of the site file, relative to the working directory. Default: `analyze_out/index.html` in the
|
|
8
|
+
* repository.
|
|
7
9
|
*/
|
|
8
10
|
declare const createDocsSchema: z.ZodPipe<z.ZodObject<{
|
|
9
11
|
onWarning: z.ZodOptional<z.ZodCustom<import("./options").WarningHandler, import("./options").WarningHandler>>;
|
|
@@ -13,9 +15,11 @@ declare const createDocsSchema: z.ZodPipe<z.ZodObject<{
|
|
|
13
15
|
excludes: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
14
16
|
embeddings: z.ZodOptional<z.ZodBoolean>;
|
|
15
17
|
title: z.ZodOptional<z.ZodString>;
|
|
18
|
+
out: z.ZodOptional<z.ZodString>;
|
|
16
19
|
}, z.core.$strict>, z.ZodTransform<{
|
|
17
20
|
scan: import("./scan").ScanOptions;
|
|
18
21
|
title: string;
|
|
22
|
+
out: string | null;
|
|
19
23
|
reporter: import("../scanner").Reporter;
|
|
20
24
|
}, {
|
|
21
25
|
onWarning?: import("./options").WarningHandler | undefined;
|
|
@@ -25,13 +29,14 @@ declare const createDocsSchema: z.ZodPipe<z.ZodObject<{
|
|
|
25
29
|
excludes?: readonly string[] | undefined;
|
|
26
30
|
embeddings?: boolean | undefined;
|
|
27
31
|
title?: string | undefined;
|
|
32
|
+
out?: string | undefined;
|
|
28
33
|
}>>;
|
|
29
|
-
/** Options of `createDocs`: what to scan
|
|
34
|
+
/** Options of `createDocs`: what to scan, the title of the site and where to write it. */
|
|
30
35
|
export type CreateDocsOptions = z.input<typeof createDocsSchema>;
|
|
31
36
|
/**
|
|
32
37
|
* Where `createDocs` wrote the site and what the site holds.
|
|
33
38
|
*
|
|
34
|
-
* @property out - Absolute path of the site: `analyze_out/index.html` in the repository.
|
|
39
|
+
* @property out - Absolute path of the site: the `out` option, else `analyze_out/index.html` in the repository.
|
|
35
40
|
* @property bytes - Size of the site in bytes.
|
|
36
41
|
* @property skills - Skills of the bundle.
|
|
37
42
|
* @property docs - Pages of the docs section.
|
|
@@ -80,9 +85,10 @@ export interface CreateDocsResult {
|
|
|
80
85
|
} | null;
|
|
81
86
|
}
|
|
82
87
|
/**
|
|
83
|
-
* Scans a repository and writes its documentation site to `analyze_out/index.html` in the
|
|
88
|
+
* @brief Scans a repository and writes its documentation site to `out`, or to `analyze_out/index.html` in the
|
|
89
|
+
* repository. With `out`, it writes nothing in the repository.
|
|
84
90
|
*
|
|
85
|
-
* @param options - What to scan and
|
|
91
|
+
* @param options - What to scan, the title and where to write. Default: the working directory.
|
|
86
92
|
* @returns Where the site was written and what it holds.
|
|
87
93
|
* @throws {OptionsError} When the options are not valid.
|
|
88
94
|
* @throws {SourceError} When the repository or one of the directories does not exist.
|
package/dist/api/graph.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ declare const graphSchema: z.ZodPipe<z.ZodObject<{
|
|
|
65
65
|
imports: "imports";
|
|
66
66
|
mentions: "mentions";
|
|
67
67
|
names: "names";
|
|
68
|
+
passes: "passes";
|
|
68
69
|
reads: "reads";
|
|
69
70
|
references: "references";
|
|
70
71
|
returns: "returns";
|
|
@@ -79,7 +80,7 @@ declare const graphSchema: z.ZodPipe<z.ZodObject<{
|
|
|
79
80
|
request: {
|
|
80
81
|
level: "all" | "communities" | "entries" | "files" | "packages";
|
|
81
82
|
filter: NodeFilter;
|
|
82
|
-
edges: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[];
|
|
83
|
+
edges: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "passes" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[];
|
|
83
84
|
};
|
|
84
85
|
}, {
|
|
85
86
|
onWarning?: import("./options").WarningHandler | undefined;
|
|
@@ -94,7 +95,7 @@ declare const graphSchema: z.ZodPipe<z.ZodObject<{
|
|
|
94
95
|
from?: string | undefined;
|
|
95
96
|
cache?: boolean | undefined;
|
|
96
97
|
level?: "all" | "communities" | "entries" | "files" | "packages" | undefined;
|
|
97
|
-
edges?: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[] | undefined;
|
|
98
|
+
edges?: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "passes" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[] | undefined;
|
|
98
99
|
}>>;
|
|
99
100
|
/** Options of `graph`: the level, the nodes and edges to keep, and the bundle to read. */
|
|
100
101
|
export type GraphOptions = z.input<typeof graphSchema>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type EdgeKind } from '../model';
|
|
3
|
+
import type { NodeFilter, NodeSummary, Reference, Retriever } from '../retrieval';
|
|
4
|
+
/**
|
|
5
|
+
* Schema of the `path` options.
|
|
6
|
+
*
|
|
7
|
+
* @property start - Id, path or name of the node the chain starts at. Not `from`, which names a site to read.
|
|
8
|
+
* @property end - Id, path or name of the node the chain ends at.
|
|
9
|
+
* @property edges - Only edges of these kinds. Empty or absent follows every kind.
|
|
10
|
+
*/
|
|
11
|
+
declare const pathSchema: z.ZodPipe<z.ZodObject<{
|
|
12
|
+
onWarning: z.ZodOptional<z.ZodCustom<import("./options").WarningHandler, import("./options").WarningHandler>>;
|
|
13
|
+
kinds: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
14
|
+
class: "class";
|
|
15
|
+
decision: "decision";
|
|
16
|
+
definition: "definition";
|
|
17
|
+
enum: "enum";
|
|
18
|
+
field: "field";
|
|
19
|
+
file: "file";
|
|
20
|
+
folder: "folder";
|
|
21
|
+
function: "function";
|
|
22
|
+
interface: "interface";
|
|
23
|
+
namespace: "namespace";
|
|
24
|
+
operation: "operation";
|
|
25
|
+
package: "package";
|
|
26
|
+
parameter: "parameter";
|
|
27
|
+
phase: "phase";
|
|
28
|
+
plan: "plan";
|
|
29
|
+
query: "query";
|
|
30
|
+
struct: "struct";
|
|
31
|
+
table: "table";
|
|
32
|
+
task: "task";
|
|
33
|
+
term: "term";
|
|
34
|
+
trait: "trait";
|
|
35
|
+
type: "type";
|
|
36
|
+
}>>>>;
|
|
37
|
+
section: z.ZodOptional<z.ZodEnum<{
|
|
38
|
+
code: "code";
|
|
39
|
+
database: "database";
|
|
40
|
+
docs: "docs";
|
|
41
|
+
skills: "skills";
|
|
42
|
+
tasks: "tasks";
|
|
43
|
+
}>>;
|
|
44
|
+
communities: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodNumber>>>;
|
|
45
|
+
repo: z.ZodOptional<z.ZodString>;
|
|
46
|
+
skillDirs: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
47
|
+
docDirs: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
48
|
+
excludes: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
49
|
+
embeddings: z.ZodOptional<z.ZodBoolean>;
|
|
50
|
+
from: z.ZodOptional<z.ZodString>;
|
|
51
|
+
cache: z.ZodOptional<z.ZodBoolean>;
|
|
52
|
+
start: z.ZodString;
|
|
53
|
+
end: z.ZodString;
|
|
54
|
+
edges: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
55
|
+
affects: "affects";
|
|
56
|
+
calls: "calls";
|
|
57
|
+
depends: "depends";
|
|
58
|
+
extends: "extends";
|
|
59
|
+
imports: "imports";
|
|
60
|
+
mentions: "mentions";
|
|
61
|
+
names: "names";
|
|
62
|
+
passes: "passes";
|
|
63
|
+
reads: "reads";
|
|
64
|
+
references: "references";
|
|
65
|
+
returns: "returns";
|
|
66
|
+
throws: "throws";
|
|
67
|
+
type: "type";
|
|
68
|
+
uses: "uses";
|
|
69
|
+
writes: "writes";
|
|
70
|
+
}>>>>;
|
|
71
|
+
}, z.core.$strict>, z.ZodTransform<{
|
|
72
|
+
source: import("./source").BundleSource;
|
|
73
|
+
reporter: import("../scanner").Reporter;
|
|
74
|
+
request: {
|
|
75
|
+
start: string;
|
|
76
|
+
end: string;
|
|
77
|
+
filter: NodeFilter;
|
|
78
|
+
kinds: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "passes" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[];
|
|
79
|
+
};
|
|
80
|
+
}, {
|
|
81
|
+
onWarning?: import("./options").WarningHandler | undefined;
|
|
82
|
+
kinds?: readonly ("class" | "decision" | "definition" | "enum" | "field" | "file" | "folder" | "function" | "interface" | "namespace" | "operation" | "package" | "parameter" | "phase" | "plan" | "query" | "struct" | "table" | "task" | "term" | "trait" | "type")[] | undefined;
|
|
83
|
+
section?: "code" | "database" | "docs" | "skills" | "tasks" | undefined;
|
|
84
|
+
communities?: readonly number[] | undefined;
|
|
85
|
+
repo?: string | undefined;
|
|
86
|
+
skillDirs?: readonly string[] | undefined;
|
|
87
|
+
docDirs?: readonly string[] | undefined;
|
|
88
|
+
excludes?: readonly string[] | undefined;
|
|
89
|
+
embeddings?: boolean | undefined;
|
|
90
|
+
from?: string | undefined;
|
|
91
|
+
cache?: boolean | undefined;
|
|
92
|
+
start: string;
|
|
93
|
+
end: string;
|
|
94
|
+
edges?: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "passes" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[] | undefined;
|
|
95
|
+
}>>;
|
|
96
|
+
/** Options of `path`: the two nodes, the edges to follow, and the bundle to read. */
|
|
97
|
+
export type PathOptions = z.input<typeof pathSchema>;
|
|
98
|
+
/**
|
|
99
|
+
* One `path` on a loaded bundle.
|
|
100
|
+
*
|
|
101
|
+
* @property start - Id, path or name of the node the chain starts at.
|
|
102
|
+
* @property end - Id, path or name of the node the chain ends at.
|
|
103
|
+
* @property filter - Narrows both names to one node each.
|
|
104
|
+
* @property kinds - Edge kinds to follow. Empty follows every kind.
|
|
105
|
+
*/
|
|
106
|
+
export interface PathRequest {
|
|
107
|
+
readonly start: string;
|
|
108
|
+
readonly end: string;
|
|
109
|
+
readonly filter: NodeFilter;
|
|
110
|
+
readonly kinds: readonly EdgeKind[];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* What `path` finds. The CLI prints it with `path --json`.
|
|
114
|
+
*
|
|
115
|
+
* @property start - The node the chain starts at.
|
|
116
|
+
* @property end - The node the chain ends at.
|
|
117
|
+
* @property steps - Each edge of the chain in order, with the node it leads to. The last leads to `end`.
|
|
118
|
+
*/
|
|
119
|
+
export interface PathResult {
|
|
120
|
+
readonly start: NodeSummary;
|
|
121
|
+
readonly end: NodeSummary;
|
|
122
|
+
readonly steps: readonly Reference[];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* @brief Finds the shortest chain of edges between two nodes of a loaded bundle, following edges the way they point.
|
|
126
|
+
*
|
|
127
|
+
* @param retriever - The loaded bundle to read.
|
|
128
|
+
* @param request - The two nodes, the filter that narrows their names, and the edge kinds to follow.
|
|
129
|
+
* @returns Both nodes and the chain between them.
|
|
130
|
+
* @throws {QueryError} When no node fits a name, several do, or no chain leads from one node to the other.
|
|
131
|
+
*/
|
|
132
|
+
export declare function pathIn(retriever: Retriever, request: PathRequest): PathResult;
|
|
133
|
+
/**
|
|
134
|
+
* @brief Finds the shortest chain of edges from one node to another, such as the calls from a command to a helper.
|
|
135
|
+
*
|
|
136
|
+
* @param options - The two nodes, the edges to follow, and the repository or site to read.
|
|
137
|
+
* @returns Both nodes and the chain between them.
|
|
138
|
+
* @throws {OptionsError} When the options are not valid.
|
|
139
|
+
* @throws {SourceError} When the repository or the site cannot be read.
|
|
140
|
+
* @throws {QueryError} When no node fits a name, several do, or no chain leads from one node to the other.
|
|
141
|
+
*/
|
|
142
|
+
export declare function path(options: PathOptions): Promise<PathResult>;
|
|
143
|
+
export {};
|
package/dist/api/refs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type
|
|
2
|
+
import { type NodeFilter, type NodeSummary, type Retriever, type Walk, type WalkOptions } from '../retrieval';
|
|
3
3
|
/**
|
|
4
4
|
* Schema of the `refs` options.
|
|
5
5
|
*
|
|
@@ -7,6 +7,8 @@ import type { NodeFilter, NodeSummary, ReferenceOptions, References, Retriever }
|
|
|
7
7
|
* @property incoming - Only what links to the node.
|
|
8
8
|
* @property outgoing - Only what the node links to.
|
|
9
9
|
* @property edges - Only edges of these kinds. Empty or absent keeps every kind.
|
|
10
|
+
* @property depth - Hops to follow from the node. Default: 1, the node's own references.
|
|
11
|
+
* @property limit - Most references to list, every hop and both directions together. Default: 50.
|
|
10
12
|
*/
|
|
11
13
|
declare const refsSchema: z.ZodPipe<z.ZodObject<{
|
|
12
14
|
onWarning: z.ZodOptional<z.ZodCustom<import("./options").WarningHandler, import("./options").WarningHandler>>;
|
|
@@ -60,6 +62,7 @@ declare const refsSchema: z.ZodPipe<z.ZodObject<{
|
|
|
60
62
|
imports: "imports";
|
|
61
63
|
mentions: "mentions";
|
|
62
64
|
names: "names";
|
|
65
|
+
passes: "passes";
|
|
63
66
|
reads: "reads";
|
|
64
67
|
references: "references";
|
|
65
68
|
returns: "returns";
|
|
@@ -68,15 +71,19 @@ declare const refsSchema: z.ZodPipe<z.ZodObject<{
|
|
|
68
71
|
uses: "uses";
|
|
69
72
|
writes: "writes";
|
|
70
73
|
}>>>>;
|
|
74
|
+
depth: z.ZodOptional<z.ZodNumber>;
|
|
75
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
71
76
|
}, z.core.$strict>, z.ZodTransform<{
|
|
72
77
|
source: import("./source").BundleSource;
|
|
73
78
|
reporter: import("../scanner").Reporter;
|
|
74
79
|
request: {
|
|
75
80
|
target: string;
|
|
76
81
|
filter: NodeFilter;
|
|
77
|
-
|
|
82
|
+
walk: {
|
|
78
83
|
direction: "both" | "in" | "out";
|
|
79
|
-
kinds: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[];
|
|
84
|
+
kinds: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "passes" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[];
|
|
85
|
+
depth: number;
|
|
86
|
+
limit: number;
|
|
80
87
|
};
|
|
81
88
|
};
|
|
82
89
|
}, {
|
|
@@ -94,43 +101,45 @@ declare const refsSchema: z.ZodPipe<z.ZodObject<{
|
|
|
94
101
|
target: string;
|
|
95
102
|
incoming?: boolean | undefined;
|
|
96
103
|
outgoing?: boolean | undefined;
|
|
97
|
-
edges?: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[] | undefined;
|
|
104
|
+
edges?: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "passes" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[] | undefined;
|
|
105
|
+
depth?: number | undefined;
|
|
106
|
+
limit?: number | undefined;
|
|
98
107
|
}>>;
|
|
99
|
-
/** Options of `refs`: the node, which links to follow, and the bundle to read. */
|
|
108
|
+
/** Options of `refs`: the node, which links to follow and how far, and the bundle to read. */
|
|
100
109
|
export type RefsOptions = z.input<typeof refsSchema>;
|
|
101
110
|
/**
|
|
102
111
|
* One `refs` on a loaded bundle.
|
|
103
112
|
*
|
|
104
113
|
* @property target - Id, path or name of the node.
|
|
105
|
-
* @property filter - Narrows a name to one node.
|
|
106
|
-
* @property
|
|
114
|
+
* @property filter - Narrows a name to one node. The references themselves are not narrowed by it.
|
|
115
|
+
* @property walk - Which links to follow: direction, edge kinds, depth and limit.
|
|
107
116
|
*/
|
|
108
117
|
export interface RefsRequest {
|
|
109
118
|
readonly target: string;
|
|
110
119
|
readonly filter: NodeFilter;
|
|
111
|
-
readonly
|
|
120
|
+
readonly walk: WalkOptions;
|
|
112
121
|
}
|
|
113
122
|
/**
|
|
114
123
|
* What `refs` finds. The CLI prints it with `refs --json`.
|
|
115
124
|
*
|
|
116
125
|
* @property node - The node the references are of.
|
|
117
126
|
*/
|
|
118
|
-
export interface RefsResult extends
|
|
127
|
+
export interface RefsResult extends Walk {
|
|
119
128
|
readonly node: NodeSummary;
|
|
120
129
|
}
|
|
121
130
|
/**
|
|
122
|
-
* Lists the references of one node of a loaded bundle.
|
|
131
|
+
* @brief Lists the references of one node of a loaded bundle, followed for some hops.
|
|
123
132
|
*
|
|
124
133
|
* @param retriever - The loaded bundle to read.
|
|
125
|
-
* @param request - The node, the filter that narrows a name, and the
|
|
126
|
-
* @returns The node with what it links to and what links to it.
|
|
134
|
+
* @param request - The node, the filter that narrows a name, and the walk to make.
|
|
135
|
+
* @returns The node with what it links to and what links to it, and how many references the limit left out.
|
|
127
136
|
* @throws {QueryError} When no node fits the target, or several do.
|
|
128
137
|
*/
|
|
129
138
|
export declare function refsIn(retriever: Retriever, request: RefsRequest): RefsResult;
|
|
130
139
|
/**
|
|
131
|
-
* Lists what a node links to and what links to it.
|
|
140
|
+
* @brief Lists what a node links to and what links to it, and with `depth` what those link to in turn.
|
|
132
141
|
*
|
|
133
|
-
* @param options - The node, which links to follow, and the repository or site to read.
|
|
142
|
+
* @param options - The node, which links to follow and how far, and the repository or site to read.
|
|
134
143
|
* @returns The node with its references.
|
|
135
144
|
* @throws {OptionsError} When the options are not valid.
|
|
136
145
|
* @throws {SourceError} When the repository or the site cannot be read.
|
package/dist/api/search.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { type NodeFilter, type Retriever, type SearchHit, type SearchMode } from '../retrieval';
|
|
3
|
-
/** Most hits of a search without a limit. */
|
|
4
|
-
export declare const DEFAULT_SEARCH_LIMIT =
|
|
3
|
+
/** Most hits per section of a search without a limit. */
|
|
4
|
+
export declare const DEFAULT_SEARCH_LIMIT = 5;
|
|
5
5
|
/**
|
|
6
6
|
* Schema of the `search` options.
|
|
7
7
|
*
|
|
8
8
|
* @property query - Words to find.
|
|
9
9
|
* @property by - `name` searches by words, `meaning` by the embedding model, `both` by both. Default: `both`.
|
|
10
|
-
* @property limit - Most hits. Default:
|
|
10
|
+
* @property limit - Most hits per section. Default: 5.
|
|
11
11
|
*/
|
|
12
12
|
declare const searchSchema: z.ZodPipe<z.ZodObject<{
|
|
13
13
|
onWarning: z.ZodOptional<z.ZodCustom<import("./options").WarningHandler, import("./options").WarningHandler>>;
|
|
@@ -89,8 +89,8 @@ export type SearchOptions = z.input<typeof searchSchema>;
|
|
|
89
89
|
*
|
|
90
90
|
* @property query - The words to find.
|
|
91
91
|
* @property mode - How to match them: by words, by meaning, or both.
|
|
92
|
-
* @property limit - Most hits.
|
|
93
|
-
* @property filter - Narrows the nodes that count.
|
|
92
|
+
* @property limit - Most hits per section.
|
|
93
|
+
* @property filter - Narrows the nodes that count. With a section, only that section is searched.
|
|
94
94
|
*/
|
|
95
95
|
export interface SearchRequest {
|
|
96
96
|
readonly query: string;
|
|
@@ -104,7 +104,8 @@ export interface SearchRequest {
|
|
|
104
104
|
* @property query - The words searched for.
|
|
105
105
|
* @property mode - How the words were matched.
|
|
106
106
|
* @property model - Name of the embedding model of the bundle. `null` when the bundle has none.
|
|
107
|
-
* @property hits - Hits,
|
|
107
|
+
* @property hits - Hits grouped by section, the sections in the order the site lists them, and best first in each.
|
|
108
|
+
* When nothing matched, the few closest by meaning in all of them, each marked `weak`, in the same order.
|
|
108
109
|
*/
|
|
109
110
|
export interface SearchResult {
|
|
110
111
|
readonly query: string;
|
|
@@ -113,12 +114,13 @@ export interface SearchResult {
|
|
|
113
114
|
readonly hits: readonly SearchHit[];
|
|
114
115
|
}
|
|
115
116
|
/**
|
|
116
|
-
* @brief Searches a loaded bundle
|
|
117
|
-
* below it instead, each
|
|
117
|
+
* @brief Searches a loaded bundle, each section on its own, so the hits of one section never crowd out another.
|
|
118
|
+
* When nothing clears the cut-off in any section, it returns the few closest hits by meaning below it instead, each
|
|
119
|
+
* marked `weak`.
|
|
118
120
|
*
|
|
119
121
|
* @param retriever - The loaded bundle to search.
|
|
120
|
-
* @param request - The words, the mode, the limit and the filter.
|
|
121
|
-
* @returns The hits, best first.
|
|
122
|
+
* @param request - The words, the mode, the limit per section and the filter.
|
|
123
|
+
* @returns The hits, grouped by section and best first in each.
|
|
122
124
|
* @throws {QueryError} When the search is by meaning and the bundle has no embeddings.
|
|
123
125
|
*/
|
|
124
126
|
export declare function searchIn(retriever: Retriever, request: SearchRequest): SearchResult;
|
package/dist/api/target.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { NodeRef } from '../model';
|
|
2
2
|
import type { NodeFilter, Retriever } from '../retrieval';
|
|
3
3
|
/**
|
|
4
|
-
* Finds the one node a caller means.
|
|
4
|
+
* @brief Finds the one node a caller means.
|
|
5
5
|
*
|
|
6
6
|
* @param retriever - Retriever the node is looked up in.
|
|
7
7
|
* @param target - An id, a path or a name.
|
|
8
8
|
* @param filter - Narrows the nodes that count.
|
|
9
9
|
* @returns The one node that fits.
|
|
10
|
-
* @throws {QueryError} When no node fits, or several do.
|
|
10
|
+
* @throws {QueryError} When no node fits, or several do. For no node, the message names the closest names. For
|
|
11
|
+
* several, it lists the candidates with their ids, and the field or parameter a candidate matched by.
|
|
11
12
|
*/
|
|
12
13
|
export declare function nodeOf(retriever: Retriever, target: string, filter: NodeFilter): NodeRef;
|