@zenera/rag 1.1.5 → 1.1.8

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 (41) hide show
  1. package/README.md +68 -6
  2. package/dist/command.js +41 -674
  3. package/dist/common/embedder.d.ts +3 -0
  4. package/dist/common/embedder.js +64 -0
  5. package/dist/common/locate.d.ts +18 -0
  6. package/dist/common/locate.js +155 -0
  7. package/dist/common/manifest.d.ts +50 -0
  8. package/dist/common/manifest.js +62 -0
  9. package/dist/{schema → common}/match.d.ts +4 -0
  10. package/dist/{schema → common}/match.js +7 -0
  11. package/dist/common/progress.d.ts +57 -0
  12. package/dist/common/progress.js +155 -0
  13. package/dist/common/prose.d.ts +13 -0
  14. package/dist/common/prose.js +56 -0
  15. package/dist/index.d.ts +6 -3
  16. package/dist/index.js +6 -3
  17. package/dist/schema/build.js +6 -2
  18. package/dist/schema/command.d.ts +3 -0
  19. package/dist/schema/command.js +819 -0
  20. package/dist/schema/files.d.ts +5 -27
  21. package/dist/schema/files.js +9 -29
  22. package/dist/schema/lookup.d.ts +12 -2
  23. package/dist/schema/lookup.js +29 -2
  24. package/dist/{present.d.ts → schema/present.d.ts} +5 -5
  25. package/dist/{present.js → schema/present.js} +2 -2
  26. package/dist/{query.d.ts → schema/query.d.ts} +1 -1
  27. package/dist/schema/readme.d.ts +6 -0
  28. package/dist/schema/readme.js +122 -0
  29. package/dist/schema/render.d.ts +8 -0
  30. package/dist/schema/render.js +12 -2
  31. package/dist/{repl.d.ts → schema/repl.d.ts} +1 -1
  32. package/dist/schema/search.js +2 -1
  33. package/dist/schema/tools.d.ts +3 -1
  34. package/dist/schema/tools.js +152 -19
  35. package/dist/schema/trace.d.ts +52 -0
  36. package/dist/schema/trace.js +144 -0
  37. package/package.json +3 -3
  38. package/dist/schema/progress.d.ts +0 -26
  39. package/dist/schema/progress.js +0 -316
  40. /package/dist/{query.js → schema/query.js} +0 -0
  41. /package/dist/{repl.js → schema/repl.js} +0 -0
package/README.md CHANGED
@@ -56,14 +56,52 @@ zen rag schema list methods --path "*/users*" # every route under /users
56
56
  zen rag schema list types --name "*Password*" # every schema so named
57
57
  zen rag schema grep password # every literal occurrence
58
58
  zen rag schema grep "pass(word|phrase)" --regex
59
+ zen rag schema trace city # which calls can reach the field
59
60
  zen rag schema show --method GetCurrentUserInfo --format openapi --exact
60
61
  ```
61
62
 
63
+ Patterns are globs by default and regular expressions under `--regex`, on
64
+ `list` as well as `grep`, which is the only way to say "one of these prefixes":
65
+
66
+ ```sh
67
+ zen rag schema list methods --regex --path "^/(users|teams)/"
68
+ zen rag schema grep status --path "/invoices/*" --kind property
69
+ ```
70
+
71
+ `grep` takes the same `--name` and `--path` constraints `list` takes, so a
72
+ common word can be narrowed to one corner of the API instead of being read out
73
+ of every document at once.
74
+
75
+ When an index holds more than one document, `--show-source` names the one each
76
+ row came from — `[source: billing_api_v2]` — on `list`, `grep`, `search` and
77
+ `show` alike, so the document does not have to be recovered from `--json`.
78
+
62
79
  `list` and `grep` report `found` as the true total even when `--limit` cuts the
63
80
  printed rows, so a shortened answer still tells you how much there is. Nothing
64
81
  matching exits 0 — an empty answer is an answer, and here it is a trustworthy
65
82
  one: if `grep` finds nothing, the word is not in the description.
66
83
 
84
+ Finding a field is half the job; the other half is which call can reach it, and
85
+ that is a walk up the `$ref`s rather than a match on anything. `trace` does it:
86
+
87
+ ```sh
88
+ zen rag schema trace city
89
+ ```
90
+
91
+ ```
92
+ Property:Address.city
93
+ GET /users/{userId} getUser output PublicUserProfile.address → Address.city
94
+ ```
95
+
96
+ No search can be relied on for that — `search` stitches its seeds into one
97
+ connected piece, but only between the nodes that ranked and only within
98
+ `--max-hops`, and `getUser` and `city` share no word for either of them to rank
99
+ on. `--direction` keeps just the calls that accept it or return it,
100
+ `--kind` narrows what a bare pattern may start from, `--routes` and `--limit`
101
+ cut the printed rows without lying about `found`, and `--ids-only` pipes the
102
+ operations onward. A node nothing carries says so, which is worth knowing: it
103
+ means no request in this document will ever carry it.
104
+
67
105
  Non-interactive search is a machine interface: every field is a flag, the whole
68
106
  query can arrive as one JSON object, the `--json` output keeps the same
69
107
  structure from run to run, no terminal is required, and an empty result exits 0.
@@ -79,6 +117,22 @@ zen rag schema search --query - --format ts <<'JSON'
79
117
  JSON
80
118
  ```
81
119
 
120
+ ## Which index
121
+
122
+ Every reading command takes `-d, --dir`. Without one, `$ZEN_SCHEMA_DB` is used
123
+ if it is set; without that, the nearest index to the working directory is found
124
+ and named on stderr as it is used.
125
+
126
+ Nearest means what it says: this directory, then a short way down into it, then
127
+ up a level and again, stopping at your home directory. What is looked for is a
128
+ `manifest.json` — an index is self-describing, so nothing here searches for a
129
+ directory called `schema-db`, and an index called anything else is found just
130
+ the same. `schema-db` is only the name a new one is given.
131
+
132
+ Two indexes the same distance away is a question, not a tie to break, and it is
133
+ refused: the wrong index does not fail, it answers confidently about a
134
+ different API. Name one with `--dir`, or set `ZEN_SCHEMA_DB`.
135
+
82
136
  ## Commands
83
137
 
84
138
  ```
@@ -86,6 +140,7 @@ zen rag schema index <spec...> Read the documents and write a searchable index
86
140
  zen rag schema search Ask it something. --interactive for a prompt.
87
141
  zen rag schema list <what> Every method, type or property. No ranking.
88
142
  zen rag schema grep <pattern> Every literal match across the whole index.
143
+ zen rag schema trace <what> Up from a field to the calls that carry it.
89
144
  zen rag schema show [id...] Print named nodes, with no search in between.
90
145
  zen rag schema stats What is in an index, and what built it.
91
146
  ```
@@ -96,10 +151,14 @@ by `--direction`, `--method-type`, `--limit`, `--max-hops`, `--max-nodes` and
96
151
  the four `--exclude-*` filters, and rendered by `--format text | mermaid |
97
152
  mermaid-flowchart | ts | openapi`. `zen help rag` prints the full table.
98
153
 
99
- `list` takes `--name` and `--path`, `grep` takes `--regex`, `--case-sensitive`,
100
- `--kind` and `--ids-only`. A pattern with `*` or `?` in it is a glob matched
101
- against the whole name; a plain word is a substring, so `--name password` finds
102
- `ResetPasswordPayload` rather than nothing. `show` takes ids, or `--method` and
154
+ `list` and `grep` share `--name`, `--path`, `--regex`, `--case-sensitive`,
155
+ `--source`, `--show-source` and `--limit`; `grep` adds `--kind` and
156
+ `--ids-only`. A pattern with `*` or `?` in it is a glob matched against the
157
+ whole name; a plain word is a substring, so `--name password` finds
158
+ `ResetPasswordPayload` rather than nothing; under `--regex` it is a regular
159
+ expression either way. `--path` selects on the route an operation sits on, and
160
+ on the route a parameter's operation sits on — a schema belongs to no one
161
+ route, so `--path` never selects one. `show` takes ids, or `--method` and
103
162
  `--type` by name, or `--source` for a whole document, and `--exact` to print
104
163
  only what was named instead of its neighbourhood.
105
164
 
@@ -121,7 +180,7 @@ const index = await SchemaIndex.open(
121
180
  const project = await loadProject('./my-project', { tools: schemaTools(index) });
122
181
  ```
123
182
 
124
- Five tools in the group `schema`, selectable as `schema:*`:
183
+ Six tools in the group `schema`, selectable as `schema:*`:
125
184
 
126
185
  | Tool | For |
127
186
  | -------------------------- | ------------------------------------------------------- |
@@ -130,6 +189,7 @@ Five tools in the group `schema`, selectable as `schema:*`:
130
189
  | `find_types_with_property` | which types have a field of this name — no search |
131
190
  | `list_api` | the shape of the API: methods, types or fields |
132
191
  | `grep_api` | every literal occurrence of a string — no search |
192
+ | `trace_api` | the operations that carry a given field or schema |
133
193
 
134
194
  Only the first of those ranks anything. The rest are exact, because a model
135
195
  told "no results" by a vector search has learned nothing: a ranking returns the
@@ -137,7 +197,9 @@ top of a list, so an empty answer and an absent thing look identical.
137
197
  `find_types_with_property` is the one for the repair loop — when `tsc` says
138
198
  `'password' does not exist in type 'PublicUserProfile'`, the model does not
139
199
  need the word explained again, it needs the list of types that have one.
140
- `grep_api` is the same instinct widened to the whole description.
200
+ `grep_api` is the same instinct widened to the whole description, and
201
+ `trace_api` is the step after both: a field is of no use until the call that
202
+ carries it is known.
141
203
 
142
204
  ## What an index is
143
205