@g3nomaly/analyze 0.0.0-stage → 0.1.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.
Files changed (130) hide show
  1. package/LICENSE +95 -0
  2. package/README.md +71 -2
  3. package/dist/THIRD_PARTY_LICENSES.txt +1904 -0
  4. package/dist/api/bundle-builder.d.ts +75 -0
  5. package/dist/api/bundle-cache.d.ts +70 -0
  6. package/dist/api/bundle-loader.d.ts +58 -0
  7. package/dist/api/create-docs.d.ts +72 -0
  8. package/dist/api/embedding.d.ts +32 -0
  9. package/dist/api/errors.d.ts +28 -0
  10. package/dist/api/list.d.ts +106 -0
  11. package/dist/api/options.d.ts +78 -0
  12. package/dist/api/refs.d.ts +133 -0
  13. package/dist/api/scan.d.ts +44 -0
  14. package/dist/api/search.d.ts +126 -0
  15. package/dist/api/services.d.ts +7 -0
  16. package/dist/api/show.d.ts +104 -0
  17. package/dist/api/site-reader.d.ts +11 -0
  18. package/dist/api/site-writer.d.ts +20 -0
  19. package/dist/api/source.d.ts +46 -0
  20. package/dist/api/target.d.ts +10 -0
  21. package/dist/api/template.d.ts +5 -0
  22. package/dist/assets/tree-sitter-c-sharp.wasm +0 -0
  23. package/dist/assets/tree-sitter-c.wasm +0 -0
  24. package/dist/assets/tree-sitter-cpp.wasm +0 -0
  25. package/dist/assets/tree-sitter-go.wasm +0 -0
  26. package/dist/assets/tree-sitter-java.wasm +0 -0
  27. package/dist/assets/tree-sitter-javascript.wasm +0 -0
  28. package/dist/assets/tree-sitter-kotlin.wasm +0 -0
  29. package/dist/assets/tree-sitter-php.wasm +0 -0
  30. package/dist/assets/tree-sitter-python.wasm +0 -0
  31. package/dist/assets/tree-sitter-ruby.wasm +0 -0
  32. package/dist/assets/tree-sitter-rust.wasm +0 -0
  33. package/dist/assets/tree-sitter-scala.wasm +0 -0
  34. package/dist/assets/tree-sitter-tsx.wasm +0 -0
  35. package/dist/assets/tree-sitter-typescript.wasm +0 -0
  36. package/dist/assets/vectors.bin +0 -0
  37. package/dist/assets/vocab.txt +33731 -0
  38. package/dist/cli.js +8885 -0
  39. package/dist/embeddings/abbreviations.d.ts +7 -0
  40. package/dist/embeddings/index-builder.d.ts +10 -0
  41. package/dist/embeddings/index.d.ts +10 -0
  42. package/dist/embeddings/model.d.ts +113 -0
  43. package/dist/embeddings/searcher.d.ts +67 -0
  44. package/dist/embeddings/vectors.d.ts +75 -0
  45. package/dist/embeddings/words.d.ts +42 -0
  46. package/dist/index.d.ts +9 -0
  47. package/dist/index.js +8329 -0
  48. package/dist/model/index.d.ts +560 -0
  49. package/dist/model/registry.d.ts +494 -0
  50. package/dist/query/graph.d.ts +66 -0
  51. package/dist/query/index.d.ts +4 -0
  52. package/dist/query/name-search.d.ts +47 -0
  53. package/dist/query/semantic.d.ts +30 -0
  54. package/dist/query/text.d.ts +22 -0
  55. package/dist/retrieval/describe.d.ts +26 -0
  56. package/dist/retrieval/filter.d.ts +17 -0
  57. package/dist/retrieval/index.d.ts +7 -0
  58. package/dist/retrieval/markdown.d.ts +16 -0
  59. package/dist/retrieval/report.d.ts +214 -0
  60. package/dist/retrieval/resolve.d.ts +27 -0
  61. package/dist/retrieval/retriever.d.ts +94 -0
  62. package/dist/retrieval/summary.d.ts +24 -0
  63. package/dist/scanner/code/doc/clean.d.ts +10 -0
  64. package/dist/scanner/code/doc/index.d.ts +6 -0
  65. package/dist/scanner/code/doc/markdown.d.ts +3 -0
  66. package/dist/scanner/code/doc/python.d.ts +3 -0
  67. package/dist/scanner/code/doc/tagged.d.ts +10 -0
  68. package/dist/scanner/code/doc/types.d.ts +22 -0
  69. package/dist/scanner/code/doc/xml.d.ts +3 -0
  70. package/dist/scanner/code/example.d.ts +36 -0
  71. package/dist/scanner/code/extract.d.ts +78 -0
  72. package/dist/scanner/code/grammar.d.ts +29 -0
  73. package/dist/scanner/code/language.d.ts +149 -0
  74. package/dist/scanner/code/languages/c-family.d.ts +5 -0
  75. package/dist/scanner/code/languages/csharp.d.ts +3 -0
  76. package/dist/scanner/code/languages/ecmascript.d.ts +7 -0
  77. package/dist/scanner/code/languages/go.d.ts +3 -0
  78. package/dist/scanner/code/languages/index.d.ts +19 -0
  79. package/dist/scanner/code/languages/java.d.ts +3 -0
  80. package/dist/scanner/code/languages/kotlin.d.ts +3 -0
  81. package/dist/scanner/code/languages/php.d.ts +3 -0
  82. package/dist/scanner/code/languages/python.d.ts +3 -0
  83. package/dist/scanner/code/languages/ruby.d.ts +3 -0
  84. package/dist/scanner/code/languages/rust.d.ts +3 -0
  85. package/dist/scanner/code/languages/scala.d.ts +3 -0
  86. package/dist/scanner/code/languages/shared.d.ts +17 -0
  87. package/dist/scanner/code/planner.d.ts +71 -0
  88. package/dist/scanner/code/symbols.d.ts +68 -0
  89. package/dist/scanner/code/types.d.ts +93 -0
  90. package/dist/scanner/content.d.ts +38 -0
  91. package/dist/scanner/decisions/parse.d.ts +28 -0
  92. package/dist/scanner/decisions/planner.d.ts +30 -0
  93. package/dist/scanner/docs.d.ts +52 -0
  94. package/dist/scanner/files.d.ts +60 -0
  95. package/dist/scanner/glossary/parse.d.ts +30 -0
  96. package/dist/scanner/glossary/planner.d.ts +42 -0
  97. package/dist/scanner/glossary/terms.d.ts +86 -0
  98. package/dist/scanner/graph/builder.d.ts +55 -0
  99. package/dist/scanner/highlight.d.ts +31 -0
  100. package/dist/scanner/index.d.ts +40 -0
  101. package/dist/scanner/markdown/frontmatter.d.ts +9 -0
  102. package/dist/scanner/markdown/links.d.ts +50 -0
  103. package/dist/scanner/markdown/outline.d.ts +27 -0
  104. package/dist/scanner/markdown/renderer.d.ts +44 -0
  105. package/dist/scanner/openapi/planner.d.ts +84 -0
  106. package/dist/scanner/reporter.d.ts +7 -0
  107. package/dist/scanner/scanner.d.ts +52 -0
  108. package/dist/scanner/schema/definitions.d.ts +69 -0
  109. package/dist/scanner/schema/describe.d.ts +79 -0
  110. package/dist/scanner/schema/planner.d.ts +46 -0
  111. package/dist/scanner/schema/registry.d.ts +61 -0
  112. package/dist/scanner/skills/classify.d.ts +20 -0
  113. package/dist/scanner/skills/layout.d.ts +28 -0
  114. package/dist/scanner/skills/planner.d.ts +46 -0
  115. package/dist/scanner/specs.d.ts +50 -0
  116. package/dist/scanner/sql/catalog.d.ts +84 -0
  117. package/dist/scanner/sql/cursor.d.ts +107 -0
  118. package/dist/scanner/sql/database.d.ts +48 -0
  119. package/dist/scanner/sql/parse.d.ts +87 -0
  120. package/dist/scanner/sql/planner.d.ts +65 -0
  121. package/dist/scanner/sql/query.d.ts +60 -0
  122. package/dist/scanner/sql/registry.d.ts +49 -0
  123. package/dist/scanner/sql/source.d.ts +9 -0
  124. package/dist/scanner/sql/statements.d.ts +36 -0
  125. package/dist/scanner/sql/tokens.d.ts +38 -0
  126. package/dist/scanner/tasks/layout.d.ts +40 -0
  127. package/dist/scanner/tasks/planner.d.ts +75 -0
  128. package/dist/scanner/tasks/schema.d.ts +88 -0
  129. package/dist/scanner/text.d.ts +14 -0
  130. package/package.json +104 -4
@@ -0,0 +1,26 @@
1
+ import { type EdgeKind, type NodeRef } from '../model';
2
+ import { type Graph } from '../query';
3
+ import type { NodeReport, References } from './report';
4
+ /** Which edges of a node to report. */
5
+ export interface ReferenceOptions {
6
+ readonly direction: 'in' | 'out' | 'both';
7
+ /** Edge kinds to keep. Empty keeps every kind. */
8
+ readonly kinds: readonly EdgeKind[];
9
+ }
10
+ /** The options that keep every edge in both directions. */
11
+ export declare const ALL_REFERENCES: ReferenceOptions;
12
+ /**
13
+ * Lists the edges of a node in both directions. The edges of its parameters
14
+ * and fields count as its own, as on its page.
15
+ *
16
+ * @param node - A page or an entry.
17
+ * @returns What the node links to and what links to it.
18
+ */
19
+ export declare function referencesOf(graph: Graph, node: NodeRef, options: ReferenceOptions): References;
20
+ /**
21
+ * Builds the full report of a node: everything its page shows, as data.
22
+ *
23
+ * @param node - A page or an entry.
24
+ * @returns The report. Texts are markdown.
25
+ */
26
+ export declare function describeNode(graph: Graph, node: NodeRef): NodeReport;
@@ -0,0 +1,17 @@
1
+ import type { NodeKind, NodeRef, Section } from '../model';
2
+ import { type Graph } from '../query';
3
+ /** Which nodes a query looks at. An empty filter accepts every page and entry. */
4
+ export interface NodeFilter {
5
+ /** Kinds to keep. Empty keeps every kind. */
6
+ readonly kinds: readonly NodeKind[];
7
+ /** Section to stay in. `null` looks in every section. */
8
+ readonly section: Section | null;
9
+ }
10
+ /** The filter that keeps every page and entry. */
11
+ export declare const NO_FILTER: NodeFilter;
12
+ /**
13
+ * Turns a filter into a test for one node.
14
+ *
15
+ * @returns A function that says whether a node passes. Parameters and fields never pass: they have no id.
16
+ */
17
+ export declare function nodeTest(graph: Graph, filter: NodeFilter): (node: NodeRef) => boolean;
@@ -0,0 +1,7 @@
1
+ export { ALL_REFERENCES, describeNode, type ReferenceOptions, referencesOf } from './describe';
2
+ export { NO_FILTER, type NodeFilter, nodeTest } from './filter';
3
+ export { codeBlock, htmlToMarkdown } from './markdown';
4
+ export type { ContentReport, DatabaseObjectReport, DeclarationReport, ForeignKeyReport, NodeReport, NodeSummary, OperationReport, QueryReport, Reference, References, TableReport, TagReport, TaskReport, } from './report';
5
+ export { type Resolution, resolveNode } from './resolve';
6
+ export { Retriever, SEARCH_MODES, type SearchHit, type SearchMode, type SearchOptions } from './retriever';
7
+ export { nodeId, normalizeId, summarize } from './summary';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Turns scanner HTML back into markdown, for output that is read in a
3
+ * terminal or by a program. Headings, lists, tables and code blocks keep
4
+ * their structure. Links into the site and images are reduced to text.
5
+ *
6
+ * @param html - HTML of a description or a page.
7
+ * @returns Markdown without a trailing line break. `''` for empty HTML.
8
+ */
9
+ export declare function htmlToMarkdown(html: string): string;
10
+ /**
11
+ * Wraps code in a markdown code block that the code itself cannot close.
12
+ *
13
+ * @param language - Display name of its language, such as `TypeScript`, or `null`.
14
+ * @returns The block, or `''` for empty code. The fence is longer than any run of backticks in the code.
15
+ */
16
+ export declare function codeBlock(code: string, language: string | null): string;
@@ -0,0 +1,214 @@
1
+ import type { ApiServer, DocTagKind, EdgeKind, NodeKind, QueryEffect, Section, TableIndex, TaskPriority, TaskStatus } from '../model';
2
+ /** What every listing shows of a node. */
3
+ export interface NodeSummary {
4
+ /**
5
+ * Route of the node, as in the address of its page: `code/src/app.ts#symbol:App.run`.
6
+ * Every retrieval command takes it where it takes a node.
7
+ */
8
+ readonly id: string;
9
+ readonly kind: NodeKind;
10
+ /** Name as other places refer to it: `App.run`, the title of a page, `3. Use hash routes`. */
11
+ readonly title: string;
12
+ /** A short fact that belongs beside the title: the status of a decision, a plan, a phase or a task, the language of a source file, the version of an API, the verb of a query. `''` for other nodes. */
13
+ readonly note: string;
14
+ /** Path on disk of the file the node is or is in. For a catalog, the path of its directory. `null` for a section or a folder. */
15
+ readonly path: string | null;
16
+ /** Line of a symbol, a table or a query in its file. `null` for every other node. */
17
+ readonly line: number | null;
18
+ /**
19
+ * First paragraph of its description, as plain text. A table or a query
20
+ * without a description gets what its SQL states instead: the number of
21
+ * columns and the tables it is connected to, or the tables it reads and
22
+ * writes. `''` for any other node without a description.
23
+ */
24
+ readonly summary: string;
25
+ }
26
+ /** A parameter or a field of a symbol, a parameter of an operation, a property of a definition, a column of a table, or a placeholder or a result column of a query. */
27
+ export interface DeclarationReport {
28
+ readonly name: string;
29
+ readonly type: string | null;
30
+ readonly defaultValue: string | null;
31
+ readonly optional: boolean;
32
+ /** Where an operation takes a parameter from: `path`, `query`, `header` or `cookie`. `null` for every other declaration. */
33
+ readonly location: string | null;
34
+ /** Further facts about a field, verbatim: annotations in code, constraints of a property or a column, the expression behind a result column. */
35
+ readonly annotations: readonly string[];
36
+ /** The table column a placeholder or a result column of a query stands for, as `table.column`. `null` for every other declaration, and when the scan does not have the column. */
37
+ readonly column: string | null;
38
+ /** Markdown. */
39
+ readonly description: string;
40
+ }
41
+ /** One media type of a request body or a response. */
42
+ export interface ContentReport {
43
+ readonly mediaType: string;
44
+ /** The schema as a type expression, or `null`. */
45
+ readonly schema: string | null;
46
+ }
47
+ /** What an operation of an API states beside its parameters. */
48
+ export interface OperationReport {
49
+ readonly method: string;
50
+ /** Path template, or the name of a webhook. */
51
+ readonly path: string;
52
+ readonly operationId: string;
53
+ readonly tags: readonly string[];
54
+ readonly deprecated: boolean;
55
+ /** The ways a caller can authenticate. */
56
+ readonly security: readonly string[];
57
+ readonly requestBody: {
58
+ readonly required: boolean;
59
+ /** Markdown. */
60
+ readonly description: string;
61
+ readonly content: readonly ContentReport[];
62
+ } | null;
63
+ readonly responses: readonly {
64
+ readonly status: string;
65
+ /** Markdown. */
66
+ readonly description: string;
67
+ readonly content: readonly ContentReport[];
68
+ }[];
69
+ }
70
+ /** A foreign key of a table. */
71
+ export interface ForeignKeyReport {
72
+ readonly name: string;
73
+ readonly columns: readonly string[];
74
+ /** Name of the referenced table. */
75
+ readonly table: string;
76
+ /** Id of the referenced table, or `null` when the scan does not have it. */
77
+ readonly tableId: string | null;
78
+ readonly referencedColumns: readonly string[];
79
+ readonly onDelete: string;
80
+ readonly onUpdate: string;
81
+ }
82
+ /** What a table states beside its columns. */
83
+ export interface TableReport {
84
+ readonly primaryKey: readonly string[];
85
+ readonly foreignKeys: readonly ForeignKeyReport[];
86
+ readonly indexes: readonly TableIndex[];
87
+ readonly constraints: readonly string[];
88
+ readonly options: readonly string[];
89
+ }
90
+ /** A view or a trigger of a database. */
91
+ export interface DatabaseObjectReport {
92
+ readonly kind: 'view' | 'trigger';
93
+ readonly name: string;
94
+ /** The table a trigger fires on. `''` for a view. */
95
+ readonly table: string;
96
+ readonly line: number;
97
+ /** Markdown. */
98
+ readonly description: string;
99
+ readonly sql: string;
100
+ }
101
+ /** What an entry of a query catalog states beside its placeholders and result columns. */
102
+ export interface QueryReport {
103
+ readonly effect: QueryEffect;
104
+ /** The keywords that open the statement, in capitals. */
105
+ readonly verb: string;
106
+ /** The SQL as the file writes it. */
107
+ readonly sql: string;
108
+ /** The tables the SQL names. */
109
+ readonly tables: readonly {
110
+ readonly name: string;
111
+ readonly access: 'read' | 'write';
112
+ /** Id of the table, or `null` when the scan does not have it. */
113
+ readonly tableId: string | null;
114
+ }[];
115
+ }
116
+ /** A doc comment tag that is not a parameter or a return value, such as `throws`. */
117
+ export interface TagReport {
118
+ readonly kind: DocTagKind;
119
+ /** Label to print: the kind, or the original label of an `other` tag. */
120
+ readonly label: string;
121
+ /** What the tag is about, such as the exception type of a `throws` tag. */
122
+ readonly subject: string | null;
123
+ /** Markdown. */
124
+ readonly text: string;
125
+ }
126
+ /** One edge of the graph, seen from the node a report is about. */
127
+ export interface Reference {
128
+ readonly relation: EdgeKind;
129
+ /** The node at the other end. For a parameter or a field, the symbol that declares it. */
130
+ readonly node: NodeSummary;
131
+ /** Name of the parameter or field the edge starts at, when it does not start at a page or an entry. */
132
+ readonly via: string | null;
133
+ }
134
+ /** Both directions of the edges of a node. */
135
+ export interface References {
136
+ readonly linksTo: readonly Reference[];
137
+ readonly linkedFrom: readonly Reference[];
138
+ }
139
+ /** Everything the site shows about one node, as data. Texts are markdown. */
140
+ export interface NodeReport extends NodeSummary, References {
141
+ readonly section: Section | null;
142
+ /** Declaration head of a symbol. */
143
+ readonly signature: string | null;
144
+ /** Language of a source file or of the file a symbol is in. */
145
+ readonly language: string | null;
146
+ readonly modifiers: readonly string[];
147
+ readonly annotations: readonly string[];
148
+ /** Description of a symbol, an operation, a definition or a table, note of a query, definition of a term, text of a decision, frontmatter description of a file. */
149
+ readonly description: string;
150
+ /** Content of a file: its markdown, or its text in a code block. The description of an API, the opening comment of a database. `''` for every other node. */
151
+ readonly body: string;
152
+ readonly parameters: readonly DeclarationReport[];
153
+ readonly fields: readonly DeclarationReport[];
154
+ readonly returns: {
155
+ readonly type: string | null;
156
+ readonly description: string;
157
+ } | null;
158
+ readonly tags: readonly TagReport[];
159
+ readonly example: {
160
+ readonly code: string;
161
+ readonly origin: 'documented' | 'generated';
162
+ } | null;
163
+ /** Set for a glossary term. */
164
+ readonly term: {
165
+ readonly group: string;
166
+ readonly avoid: readonly string[];
167
+ } | null;
168
+ /** Set for a decision. */
169
+ readonly decision: {
170
+ readonly number: string;
171
+ readonly status: string;
172
+ readonly date: string;
173
+ } | null;
174
+ /** Set for a plan, a phase and a task. */
175
+ readonly task: TaskReport | null;
176
+ /** Set for an API document. */
177
+ readonly api: {
178
+ readonly version: string;
179
+ readonly specVersion: string;
180
+ readonly servers: readonly ApiServer[];
181
+ } | null;
182
+ /** Set for an operation of an API. */
183
+ readonly operation: OperationReport | null;
184
+ /** Set for a schema definition. */
185
+ readonly definition: {
186
+ readonly type: string | null;
187
+ readonly constraints: readonly string[];
188
+ /** Values of an `enum`, as JSON. */
189
+ readonly values: readonly string[];
190
+ } | null;
191
+ /** Set for a table. */
192
+ readonly table: TableReport | null;
193
+ /** Views and triggers. Set for a database. */
194
+ readonly objects: readonly DatabaseObjectReport[];
195
+ /** Set for an entry of a query catalog. */
196
+ readonly query: QueryReport | null;
197
+ /** The pages and entries inside the node: files of a folder or a skill, symbols of a file, members of a class, tables of a database, queries of a catalog. */
198
+ readonly contains: readonly NodeSummary[];
199
+ }
200
+ /** Where a plan, a phase or a task of the task tree stands, as `show` reports it. */
201
+ export interface TaskReport {
202
+ /** The id of a task, such as `TASK-006`. `null` for a plan or a phase. */
203
+ readonly id: string | null;
204
+ readonly status: TaskStatus;
205
+ readonly priority: TaskPriority;
206
+ /** Names or ids of what it waits for, as the file writes them. */
207
+ readonly dependsOn: readonly string[];
208
+ /** The package a task changes. `null` for a plan or a phase. */
209
+ readonly package: string | null;
210
+ /** From 1 to 5. `null` when a task states none, and for a plan or a phase. */
211
+ readonly complexity: number | null;
212
+ /** Whether the tasks of a phase run side by side. `null` for a plan or a task. */
213
+ readonly parallel: boolean | null;
214
+ }
@@ -0,0 +1,27 @@
1
+ import { type NodeRef } from '../model';
2
+ import { type Graph } from '../query';
3
+ /** What a reference to a node turned out to name. */
4
+ export type Resolution = {
5
+ readonly kind: 'found';
6
+ readonly node: NodeRef;
7
+ }
8
+ /** Several nodes fit equally well. The caller has to pick one by id. */
9
+ | {
10
+ readonly kind: 'ambiguous';
11
+ readonly candidates: readonly NodeRef[];
12
+ } | {
13
+ readonly kind: 'missing';
14
+ };
15
+ /**
16
+ * Finds the node a caller means. The first of these rules that fits any node decides:
17
+ *
18
+ * 1. The text is the id of a node, with or without `#/` in front. An id with the anchor of a heading names its page.
19
+ * 2. The text is the path of a file on disk. The path of a query file names its query.
20
+ * 3. The text is the name of a node, with the same capitals.
21
+ * 4. The text is the name of a node, capitals ignored.
22
+ *
23
+ * @param text - An id, a path or a name.
24
+ * @param accepts - Narrows the nodes that count, such as to one kind.
25
+ * @returns The node, the candidates when several fit the deciding rule, or `missing`.
26
+ */
27
+ export declare function resolveNode(graph: Graph, text: string, accepts: (node: NodeRef) => boolean): Resolution;
@@ -0,0 +1,94 @@
1
+ import type { NodeRef } from '../model';
2
+ import { type Graph } from '../query';
3
+ import { type ReferenceOptions } from './describe';
4
+ import { type NodeFilter } from './filter';
5
+ import type { NodeReport, NodeSummary, References } from './report';
6
+ import { type Resolution } from './resolve';
7
+ /** The search modes a caller can pick from, the default first. */
8
+ export declare const SEARCH_MODES: readonly ['both', 'name', 'meaning'];
9
+ /** How a search matches: `name` by the words of a name or a description, `meaning` by the embedding model, `both` by words first and then by meaning. */
10
+ export type SearchMode = (typeof SEARCH_MODES)[number];
11
+ /** How one search is run. */
12
+ export interface SearchOptions {
13
+ readonly mode: SearchMode;
14
+ /** Most hits to return, both ways of matching together. */
15
+ readonly limit: number;
16
+ readonly filter: NodeFilter;
17
+ }
18
+ /** One result of a search. */
19
+ export interface SearchHit extends NodeSummary {
20
+ /**
21
+ * `name`: every word of the query is in the name or the path of the node.
22
+ * `text`: at least one word is only in its description.
23
+ * `meaning`: the node is close to the query in the embedding model.
24
+ */
25
+ readonly match: 'name' | 'text' | 'meaning';
26
+ /** From 0 to 1 for a match by meaning. `null` for a match by words. */
27
+ readonly score: number | null;
28
+ }
29
+ /**
30
+ * Answers queries on one bundle: search, list, look up, describe.
31
+ *
32
+ * Holds the graph of the bundle and, after the first search by name, the
33
+ * search index. `openRetriever` in `api/source.ts` creates one per request;
34
+ * `listIn`, `searchIn`, `showIn` and `refsIn` in `api/` each call one method.
35
+ * Every answer is plain data with ids, so a caller can print it, serialize it
36
+ * or feed an id into the next call.
37
+ */
38
+ export declare class Retriever {
39
+ private readonly graph;
40
+ /** Built on the first search by name. */
41
+ private nameIndex;
42
+ /** Creates a retriever for one bundle. */
43
+ constructor(graph: Graph);
44
+ /**
45
+ * Names the embedding model that searches by meaning.
46
+ *
47
+ * @returns The name, or `null` when the bundle was built without embeddings.
48
+ */
49
+ get model(): string | null;
50
+ /**
51
+ * Finds pages and entries for a query. Matches by words come first, in the
52
+ * order the site lists them. Matches by meaning follow, best first.
53
+ *
54
+ * @param query - Words of a name, or a query in plain language.
55
+ * @returns The hits, each once.
56
+ */
57
+ search(query: string, options: SearchOptions): SearchHit[];
58
+ /**
59
+ * Lists pages and entries in display order.
60
+ *
61
+ * @param limit - Most rows to return. `null` returns all of them.
62
+ * @returns One row per node.
63
+ */
64
+ list(filter: NodeFilter, limit: number | null): NodeSummary[];
65
+ /**
66
+ * Finds the node a caller means by an id, a file path or a name.
67
+ *
68
+ * @param text - What the caller wrote.
69
+ * @param filter - Narrows the nodes that count, to tell two nodes with one name apart.
70
+ * @returns The node, the candidates when several fit, or `missing`.
71
+ */
72
+ resolve(text: string, filter: NodeFilter): Resolution;
73
+ /**
74
+ * Describes a node in one row.
75
+ *
76
+ * @param node - A page or an entry.
77
+ * @returns Its id, kind, title, place on disk and summary.
78
+ */
79
+ summarize(node: NodeRef): NodeSummary;
80
+ /**
81
+ * Builds the full report of a node.
82
+ *
83
+ * @param node - A page or an entry.
84
+ * @returns Everything its page shows, with texts as markdown.
85
+ */
86
+ describe(node: NodeRef): NodeReport;
87
+ /**
88
+ * Lists the edges of a node.
89
+ *
90
+ * @param node - A page or an entry.
91
+ * @returns What the node links to and what links to it.
92
+ */
93
+ references(node: NodeRef, options?: ReferenceOptions): References;
94
+ }
@@ -0,0 +1,24 @@
1
+ import { type NodeRef } from '../model';
2
+ import { type Graph } from '../query';
3
+ import type { NodeSummary } from './report';
4
+ /**
5
+ * Builds the id of a node: its route as the address of its page spells it,
6
+ * without the leading `#/`.
7
+ *
8
+ * @param node - The node. A parameter or a field has the id of its symbol.
9
+ * @returns The id, such as `docs/glossary.md#term:lane`.
10
+ */
11
+ export declare function nodeId(graph: Graph, node: NodeRef): string;
12
+ /**
13
+ * Reduces an id, an address copied from the browser or an href of the site to an id.
14
+ *
15
+ * @param text - What the caller wrote, such as `#/code/src/app.ts#symbol:App.run` or `file:///site/docs.html#/code/src/app.ts`.
16
+ * @returns The id without the file, `#/` or slashes around it, with percent escapes decoded.
17
+ */
18
+ export declare function normalizeId(text: string): string;
19
+ /**
20
+ * Describes a node in one row: what a search hit, a list row and a reference show.
21
+ *
22
+ * @param node - The node. A parameter or a field is not listed on its own, so pass its symbol.
23
+ */
24
+ export declare function summarize(graph: Graph, node: NodeRef): NodeSummary;
@@ -0,0 +1,10 @@
1
+ /** Strips comment markers from the text of consecutive comment nodes. */
2
+ export declare function cleanComments(comments: readonly string[]): string;
3
+ /** Content of a Python string literal used as a docstring, laid out like `inspect.cleandoc`. */
4
+ export declare function cleanDocstring(literal: string): string;
5
+ /** Text of the first fenced code block, or `null`. */
6
+ export declare function firstFencedBlock(markdown: string): string | null;
7
+ /** Applies `transform` to every line outside fenced code blocks. */
8
+ export declare function mapProseLines(markdown: string, transform: (line: string) => string): string;
9
+ /** Turns markdown headings into bold lines, so a description never outranks its symbol title. */
10
+ export declare function demoteHeadings(markdown: string): string;
@@ -0,0 +1,6 @@
1
+ import type { DocStyle } from '../language';
2
+ import { type ParsedDoc } from './types';
3
+ export { cleanComments, cleanDocstring } from './clean';
4
+ export type { ParsedDoc, ParsedTag, ParsedTagKind } from './types';
5
+ /** Parses cleaned doc comment text in the given dialect. */
6
+ export declare function parseDoc(style: DocStyle, text: string | null): ParsedDoc;
@@ -0,0 +1,3 @@
1
+ import type { ParsedDoc } from './types';
2
+ /** Parses a markdown doc comment (rustdoc, godoc). An "Examples" section becomes the example. */
3
+ export declare function parseMarkdownDoc(text: string): ParsedDoc;
@@ -0,0 +1,3 @@
1
+ import type { ParsedDoc } from './types';
2
+ /** Parses a docstring in Google, NumPy or reST layout. */
3
+ export declare function parsePythonDoc(text: string): ParsedDoc;
@@ -0,0 +1,10 @@
1
+ import type { ParsedDoc } from './types';
2
+ /** Dialect switches for `parseTagged`. */
3
+ export interface TaggedOptions {
4
+ /** YARD puts an example title on the `@example` line. */
5
+ readonly titledExamples?: boolean;
6
+ /** YARD links to code with braces, as in `{Label.parse}` and `{#render}`. */
7
+ readonly braceLinks?: boolean;
8
+ }
9
+ /** Parses a doc comment written with `@tag` lines. */
10
+ export declare function parseTagged(text: string, options?: TaggedOptions): ParsedDoc;
@@ -0,0 +1,22 @@
1
+ import type { DocTagKind } from '../../../model';
2
+ /** Tag kinds a parser emits. The planner folds the first three into parameters, return value and fields. */
3
+ export type ParsedTagKind = 'param' | 'returns' | 'field' | DocTagKind;
4
+ /** One tag of a parsed doc comment, such as a parameter or a return value. */
5
+ export interface ParsedTag {
6
+ readonly kind: ParsedTagKind;
7
+ readonly label?: string;
8
+ readonly name?: string;
9
+ readonly type?: string;
10
+ /** Markdown. */
11
+ readonly text: string;
12
+ }
13
+ /** A doc comment parsed into description, tags and example, the same for every dialect. */
14
+ export interface ParsedDoc {
15
+ /** Markdown. */
16
+ readonly description: string;
17
+ readonly tags: readonly ParsedTag[];
18
+ /** Example source code, when the comment documents one. */
19
+ readonly example: string | null;
20
+ }
21
+ /** Result for a symbol with no doc comment. */
22
+ export declare const EMPTY_DOC: ParsedDoc;
@@ -0,0 +1,3 @@
1
+ import type { ParsedDoc } from './types';
2
+ /** Parses C# XML documentation comments. Text without XML elements is the description. */
3
+ export declare function parseXmlDoc(text: string): ParsedDoc;
@@ -0,0 +1,36 @@
1
+ import { type SymbolKind } from '../../model';
2
+ import type { CallStyle, ImportContext } from './language';
3
+ /** What a generated example needs to know about the type a method belongs to. */
4
+ export interface ParentTarget {
5
+ readonly kind: SymbolKind;
6
+ readonly name: string;
7
+ /** Constructor arguments of the type. */
8
+ readonly args: readonly string[];
9
+ readonly hasConstructor: boolean;
10
+ readonly instantiable: boolean;
11
+ }
12
+ /** The symbol a generated example calls or constructs, with what decides how. */
13
+ export interface CallTarget {
14
+ readonly kind: SymbolKind;
15
+ readonly name: string;
16
+ /** Argument expressions, receivers excluded. */
17
+ readonly args: readonly string[];
18
+ readonly parent: ParentTarget | null;
19
+ readonly isStatic: boolean;
20
+ readonly isAsync: boolean;
21
+ /** For types: false when abstract or a singleton. */
22
+ readonly instantiable: boolean;
23
+ readonly isConstructor: boolean;
24
+ /** For types: whether a constructor was found. */
25
+ readonly hasConstructor: boolean;
26
+ readonly returnsValue: boolean;
27
+ readonly returnType: string | null;
28
+ /** What to import, or `null` when the symbol needs no import or none can be derived. */
29
+ readonly importContext: ImportContext | null;
30
+ }
31
+ /**
32
+ * Builds a usage example from a signature: an import where the language
33
+ * allows one, the instance a method needs, then the call.
34
+ * Returns `null` for symbols that are not called.
35
+ */
36
+ export declare function buildExample(style: CallStyle, target: CallTarget): string | null;
@@ -0,0 +1,78 @@
1
+ import { type SymbolKind } from '../../model';
2
+ import type { Node, Query } from 'web-tree-sitter';
3
+ import type { LanguageSpec } from './language';
4
+ /** One parameter as declared. */
5
+ export interface RawParameter {
6
+ /** Name with its variadic marker, such as `...rest` or `*args`. */
7
+ readonly name: string;
8
+ readonly type: string | null;
9
+ defaultValue: string | null;
10
+ optional: boolean;
11
+ /** Expression a generated call passes for this parameter. */
12
+ readonly argument: string;
13
+ }
14
+ /** A field, property or enum member as declared. */
15
+ export interface RawField {
16
+ readonly name: string;
17
+ readonly type: string | null;
18
+ readonly defaultValue: string | null;
19
+ readonly optional: boolean;
20
+ readonly annotations: readonly string[];
21
+ /** Cleaned doc comment text, or `null`. */
22
+ readonly comment: string | null;
23
+ }
24
+ /** One definition as found in the syntax tree, before rendering. */
25
+ export interface RawSymbol {
26
+ kind: SymbolKind;
27
+ readonly name: string;
28
+ readonly line: number;
29
+ /** Declaration head. Empty when `inferred`. */
30
+ readonly signature: string;
31
+ /** Keywords in front of the name, such as `export` or `static`. */
32
+ readonly modifiers: readonly string[];
33
+ readonly annotations: readonly string[];
34
+ /** Cleaned doc comment text, or `null`. */
35
+ readonly comment: string | null;
36
+ /** Receivers excluded. */
37
+ readonly parameters: readonly RawParameter[];
38
+ readonly fields: RawField[];
39
+ readonly returnType: string | null;
40
+ /** Names the declaration introduces as type parameters, such as `T`. They never name a real type. */
41
+ readonly typeParameters: readonly string[];
42
+ /** For a type: the text after its name that lists what it extends or is composed of. `''` otherwise. */
43
+ readonly heritage: string;
44
+ readonly isAsync: boolean;
45
+ /** False for abstract classes and singletons. */
46
+ readonly instantiable: boolean;
47
+ isStatic: boolean;
48
+ returnsValue: boolean;
49
+ /** True for an owner type that is not declared in this file. */
50
+ readonly inferred: boolean;
51
+ readonly children: RawSymbol[];
52
+ }
53
+ /** Symbols and package name extracted from one source file. */
54
+ export interface ExtractedFile {
55
+ readonly symbols: RawSymbol[];
56
+ /** Package or namespace the file declares, when the language has one. */
57
+ readonly packageName: string | null;
58
+ }
59
+ /**
60
+ * Turns a parsed file into a tree of {@link RawSymbol}s, driven by a {@link LanguageSpec}.
61
+ *
62
+ * Holds no state, so one instance serves every file. Created by `RepositoryScanner`
63
+ * in `scanner/scanner.ts` and passed to `CodePlanner` in `planner.ts`, which calls
64
+ * {@link SymbolExtractor.extract} once per parsed file.
65
+ */
66
+ export declare class SymbolExtractor {
67
+ /**
68
+ * Runs the language's tags query over the tree and builds the symbol tree from its matches.
69
+ *
70
+ * @param source - Full text of the file the tree was parsed from; node offsets index into it.
71
+ */
72
+ extract(root: Node, query: Query, spec: LanguageSpec, source: string): ExtractedFile;
73
+ /**
74
+ * Merges the query matches into one definition per node (per name for fields), sorted by
75
+ * position with outer nodes first, and picks up the declared package name.
76
+ */
77
+ private collect;
78
+ }
@@ -0,0 +1,29 @@
1
+ import { Parser, Query } from 'web-tree-sitter';
2
+ import type { LanguageSpec } from './language';
3
+ /** Parser and compiled tags query for one language. */
4
+ export interface LoadedGrammar {
5
+ readonly parser: Parser;
6
+ readonly query: Query;
7
+ }
8
+ /**
9
+ * Loads tree-sitter grammars on first use and keeps one parser and compiled query per language.
10
+ *
11
+ * Holds the tree-sitter runtime init promise and one pending {@link LoadedGrammar} per
12
+ * language id. Created by `RepositoryScanner` in `scanner/scanner.ts`; `CodePlanner` in
13
+ * `planner.ts` loads a grammar for each file it parses.
14
+ */
15
+ export declare class GrammarLoader {
16
+ private readonly baseDir;
17
+ private runtime;
18
+ private readonly grammars;
19
+ /**
20
+ * Stores the directory grammar paths resolve against. Nothing loads until the first `load`.
21
+ *
22
+ * @param baseDir - Absolute directory that relative grammar paths resolve against.
23
+ */
24
+ constructor(baseDir: string);
25
+ /** Returns the cached grammar of the spec's language, loading it on the first call. */
26
+ load(spec: LanguageSpec): Promise<LoadedGrammar>;
27
+ /** Initialises the tree-sitter runtime once, then loads the grammar `.wasm` and compiles the query. */
28
+ private create;
29
+ }