@g3nomaly/analyze 0.1.5 → 0.1.7

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 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,50 @@ 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. Without `--edge` it follows every kind but `mentions`, the links descriptions make; `--include-mentions` follows those too, and of equally short chains the one with the fewest `mentions` steps still wins. A name with spaces goes in quotes.
56
+
57
+ A call, a function passed on and an import say where they are made: `calls (add.ts:86, 112)` is a call on lines 86 and 112 of `add.ts`, the file of the node the edge starts at. In the JSON, such a reference has `location`, with the `path` of that file and its `lines`; any other reference has `location: null`. The links to one node print on one line, `calls (app.ts:7), passes (app.ts:9): function run`, and a heading counts the lines under it.
58
+
59
+ `refs --level files` lists the links between the file of the node and other files, the way the files level of the graph page draws them: every link of the file or of an entry in it, to another file or an entry in it, counts for that file. These are no links of their own. The default, `--level entries`, lists the links as they are stored.
60
+
61
+ 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.
62
+
49
63
  `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
64
 
51
65
  ### Communities
52
66
 
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.
67
+ 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
68
 
55
69
  ### How code links
56
70
 
57
- - **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.
71
+ - **Imports**: an import of a whole file links to that file: a C or C++ `#include`, a Python `import a.b`, and in JavaScript and TypeScript `import './x'`, `import * as x`, a default import, `export * from` and `require`. An import by name links to each class, function or type it names, through any `export … from` files in between, and not to the file: `import { recordedHashes } from "../../installer"` links to `recordedHashes` in `installer/classify.ts`, which `installer/index.ts` re-exports. Python's `from a import b` does the same for a `b` that is no module. A name that is no node, such as a constant, links to the file the import names. 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. The files level of the graph page and of `graph` draws the links of a file to the entries of another file as one arrow between the files.
58
72
  - **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
73
  - **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.
74
+ - **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.
75
+ - **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.
76
+ - **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
77
 
62
78
  ## From hooks
63
79
 
@@ -80,20 +96,22 @@ const callers = await refs({
80
96
  });
81
97
  ```
82
98
 
83
- `createDocs`, `search`, `show`, `refs`, `list` and `graph` take the options of the CLI as fields.
99
+ `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
100
 
85
101
  ## Development
86
102
 
87
103
  Run every command from this directory.
88
104
 
89
105
  ```sh
90
- bun run build # web app, CLI and library into dist/
106
+ bun run build # web app, CLI and library into dist/, examples into build/
91
107
  bun run typecheck
92
108
  bun test # unit tests
93
109
  bun run test:integration # builds first
94
110
  bun run analyze -- --help # the CLI from source, after one build
95
111
  ```
96
112
 
113
+ 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`.
114
+
97
115
  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
116
 
99
117
  ## 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 and the title of the site. */
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 repository.
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 the title. Default: the working directory.
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.
@@ -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,150 @@
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 but `mentions`.
10
+ * @property includeMentions - Also follow `mentions`, the links descriptions make, when `edges` is empty. Of the
11
+ * chains that are equally short, the one with the fewest `mentions` steps still wins.
12
+ */
13
+ declare const pathSchema: z.ZodPipe<z.ZodObject<{
14
+ onWarning: z.ZodOptional<z.ZodCustom<import("./options").WarningHandler, import("./options").WarningHandler>>;
15
+ kinds: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodEnum<{
16
+ class: "class";
17
+ decision: "decision";
18
+ definition: "definition";
19
+ enum: "enum";
20
+ field: "field";
21
+ file: "file";
22
+ folder: "folder";
23
+ function: "function";
24
+ interface: "interface";
25
+ namespace: "namespace";
26
+ operation: "operation";
27
+ package: "package";
28
+ parameter: "parameter";
29
+ phase: "phase";
30
+ plan: "plan";
31
+ query: "query";
32
+ struct: "struct";
33
+ table: "table";
34
+ task: "task";
35
+ term: "term";
36
+ trait: "trait";
37
+ type: "type";
38
+ }>>>>;
39
+ section: z.ZodOptional<z.ZodEnum<{
40
+ code: "code";
41
+ database: "database";
42
+ docs: "docs";
43
+ skills: "skills";
44
+ tasks: "tasks";
45
+ }>>;
46
+ communities: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodNumber>>>;
47
+ repo: z.ZodOptional<z.ZodString>;
48
+ skillDirs: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
49
+ docDirs: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
50
+ excludes: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
51
+ embeddings: z.ZodOptional<z.ZodBoolean>;
52
+ from: z.ZodOptional<z.ZodString>;
53
+ cache: z.ZodOptional<z.ZodBoolean>;
54
+ start: z.ZodString;
55
+ end: z.ZodString;
56
+ edges: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodEnum<{
57
+ affects: "affects";
58
+ calls: "calls";
59
+ depends: "depends";
60
+ extends: "extends";
61
+ imports: "imports";
62
+ mentions: "mentions";
63
+ names: "names";
64
+ passes: "passes";
65
+ reads: "reads";
66
+ references: "references";
67
+ returns: "returns";
68
+ throws: "throws";
69
+ type: "type";
70
+ uses: "uses";
71
+ writes: "writes";
72
+ }>>>>;
73
+ includeMentions: z.ZodOptional<z.ZodBoolean>;
74
+ }, z.core.$strict>, z.ZodTransform<{
75
+ source: import("./source").BundleSource;
76
+ reporter: import("../scanner").Reporter;
77
+ request: {
78
+ start: string;
79
+ end: string;
80
+ filter: NodeFilter;
81
+ kinds: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "passes" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[];
82
+ includeMentions: boolean;
83
+ };
84
+ }, {
85
+ onWarning?: import("./options").WarningHandler | undefined;
86
+ 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;
87
+ section?: "code" | "database" | "docs" | "skills" | "tasks" | undefined;
88
+ communities?: readonly number[] | undefined;
89
+ repo?: string | undefined;
90
+ skillDirs?: readonly string[] | undefined;
91
+ docDirs?: readonly string[] | undefined;
92
+ excludes?: readonly string[] | undefined;
93
+ embeddings?: boolean | undefined;
94
+ from?: string | undefined;
95
+ cache?: boolean | undefined;
96
+ start: string;
97
+ end: string;
98
+ edges?: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "passes" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[] | undefined;
99
+ includeMentions?: boolean | undefined;
100
+ }>>;
101
+ /** Options of `path`: the two nodes, the edges to follow, and the bundle to read. */
102
+ export type PathOptions = z.input<typeof pathSchema>;
103
+ /**
104
+ * One `path` on a loaded bundle.
105
+ *
106
+ * @property start - Id, path or name of the node the chain starts at.
107
+ * @property end - Id, path or name of the node the chain ends at.
108
+ * @property filter - Narrows both names to one node each.
109
+ * @property kinds - Edge kinds to follow. Empty follows every kind but `mentions`, unless `includeMentions` is set.
110
+ * @property includeMentions - Whether an empty `kinds` follows `mentions` too.
111
+ */
112
+ export interface PathRequest {
113
+ readonly start: string;
114
+ readonly end: string;
115
+ readonly filter: NodeFilter;
116
+ readonly kinds: readonly EdgeKind[];
117
+ readonly includeMentions: boolean;
118
+ }
119
+ /**
120
+ * What `path` finds. The CLI prints it with `path --json`.
121
+ *
122
+ * @property start - The node the chain starts at.
123
+ * @property end - The node the chain ends at.
124
+ * @property steps - Each edge of the chain in order, with the node it leads to. The last leads to `end`.
125
+ */
126
+ export interface PathResult {
127
+ readonly start: NodeSummary;
128
+ readonly end: NodeSummary;
129
+ readonly steps: readonly Reference[];
130
+ }
131
+ /**
132
+ * @brief Finds the shortest chain of edges between two nodes of a loaded bundle, following edges the way they point.
133
+ *
134
+ * @param retriever - The loaded bundle to read.
135
+ * @param request - The two nodes, the filter that narrows their names, and the edge kinds to follow.
136
+ * @returns Both nodes and the chain between them.
137
+ * @throws {QueryError} When no node fits a name, several do, or no chain leads from one node to the other.
138
+ */
139
+ export declare function pathIn(retriever: Retriever, request: PathRequest): PathResult;
140
+ /**
141
+ * @brief Finds the shortest chain of edges from one node to another, such as the calls from a command to a helper.
142
+ *
143
+ * @param options - The two nodes, the edges to follow, and the repository or site to read.
144
+ * @returns Both nodes and the chain between them.
145
+ * @throws {OptionsError} When the options are not valid.
146
+ * @throws {SourceError} When the repository or the site cannot be read.
147
+ * @throws {QueryError} When no node fits a name, several do, or no chain leads from one node to the other.
148
+ */
149
+ export declare function path(options: PathOptions): Promise<PathResult>;
150
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import type { NodeFilter, NodeSummary, ReferenceOptions, References, Retriever } from '../retrieval';
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,10 @@ 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.
12
+ * @property level - `entries` for the stored links, `files` for the links between the files that hold their ends,
13
+ * from the file of the node. Default: `entries`.
10
14
  */
11
15
  declare const refsSchema: z.ZodPipe<z.ZodObject<{
12
16
  onWarning: z.ZodOptional<z.ZodCustom<import("./options").WarningHandler, import("./options").WarningHandler>>;
@@ -60,6 +64,7 @@ declare const refsSchema: z.ZodPipe<z.ZodObject<{
60
64
  imports: "imports";
61
65
  mentions: "mentions";
62
66
  names: "names";
67
+ passes: "passes";
63
68
  reads: "reads";
64
69
  references: "references";
65
70
  returns: "returns";
@@ -68,15 +73,24 @@ declare const refsSchema: z.ZodPipe<z.ZodObject<{
68
73
  uses: "uses";
69
74
  writes: "writes";
70
75
  }>>>>;
76
+ depth: z.ZodOptional<z.ZodNumber>;
77
+ limit: z.ZodOptional<z.ZodNumber>;
78
+ level: z.ZodOptional<z.ZodEnum<{
79
+ entries: "entries";
80
+ files: "files";
81
+ }>>;
71
82
  }, z.core.$strict>, z.ZodTransform<{
72
83
  source: import("./source").BundleSource;
73
84
  reporter: import("../scanner").Reporter;
74
85
  request: {
75
86
  target: string;
76
87
  filter: NodeFilter;
77
- references: {
88
+ walk: {
78
89
  direction: "both" | "in" | "out";
79
- kinds: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[];
90
+ kinds: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "passes" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[];
91
+ depth: number;
92
+ limit: number;
93
+ level: "entries" | "files";
80
94
  };
81
95
  };
82
96
  }, {
@@ -94,43 +108,46 @@ declare const refsSchema: z.ZodPipe<z.ZodObject<{
94
108
  target: string;
95
109
  incoming?: boolean | undefined;
96
110
  outgoing?: boolean | undefined;
97
- edges?: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[] | undefined;
111
+ edges?: readonly ("affects" | "calls" | "depends" | "extends" | "imports" | "mentions" | "names" | "passes" | "reads" | "references" | "returns" | "throws" | "type" | "uses" | "writes")[] | undefined;
112
+ depth?: number | undefined;
113
+ limit?: number | undefined;
114
+ level?: "entries" | "files" | undefined;
98
115
  }>>;
99
- /** Options of `refs`: the node, which links to follow, and the bundle to read. */
116
+ /** Options of `refs`: the node, which links to follow and how far, and the bundle to read. */
100
117
  export type RefsOptions = z.input<typeof refsSchema>;
101
118
  /**
102
119
  * One `refs` on a loaded bundle.
103
120
  *
104
121
  * @property target - Id, path or name of the node.
105
- * @property filter - Narrows a name to one node.
106
- * @property references - Which links to keep: direction and edge kinds.
122
+ * @property filter - Narrows a name to one node. The references themselves are not narrowed by it.
123
+ * @property walk - Which links to follow: direction, edge kinds, depth and limit.
107
124
  */
108
125
  export interface RefsRequest {
109
126
  readonly target: string;
110
127
  readonly filter: NodeFilter;
111
- readonly references: ReferenceOptions;
128
+ readonly walk: WalkOptions;
112
129
  }
113
130
  /**
114
131
  * What `refs` finds. The CLI prints it with `refs --json`.
115
132
  *
116
- * @property node - The node the references are of.
133
+ * @property node - The node the references are of: the file of the target at the `files` level.
117
134
  */
118
- export interface RefsResult extends References {
135
+ export interface RefsResult extends Walk {
119
136
  readonly node: NodeSummary;
120
137
  }
121
138
  /**
122
- * Lists the references of one node of a loaded bundle.
139
+ * @brief Lists the references of one node of a loaded bundle, followed for some hops.
123
140
  *
124
141
  * @param retriever - The loaded bundle to read.
125
- * @param request - The node, the filter that narrows a name, and the references to keep.
126
- * @returns The node with what it links to and what links to it.
142
+ * @param request - The node, the filter that narrows a name, and the walk to make.
143
+ * @returns The node with what it links to and what links to it, and how many references the limit left out.
127
144
  * @throws {QueryError} When no node fits the target, or several do.
128
145
  */
129
146
  export declare function refsIn(retriever: Retriever, request: RefsRequest): RefsResult;
130
147
  /**
131
- * Lists what a node links to and what links to it.
148
+ * @brief Lists what a node links to and what links to it, and with `depth` what those link to in turn.
132
149
  *
133
- * @param options - The node, which links to follow, and the repository or site to read.
150
+ * @param options - The node, which links to follow and how far, and the repository or site to read.
134
151
  * @returns The node with its references.
135
152
  * @throws {OptionsError} When the options are not valid.
136
153
  * @throws {SourceError} When the repository or the site cannot be read.
@@ -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 = 10;
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.
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, best first. When nothing matched, the few closest by meaning, each marked `weak`.
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. When nothing clears the cut-off, it returns the few closest hits by meaning
117
- * below it instead, each marked `weak`.
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;
@@ -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. The message lists the candidates with their ids.
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;