@nacre.work/cli 0.14.3
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/LICENSE +202 -0
- package/NOTICE +9 -0
- package/README.md +79 -0
- package/dist/args.d.ts +30 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +72 -0
- package/dist/args.js.map +1 -0
- package/dist/commands.d.ts +82 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +540 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +39 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +70 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +27 -0
- package/dist/main.js.map +1 -0
- package/dist/run.d.ts +25 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +104 -0
- package/dist/run.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Nacre
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Nacre
|
|
2
|
+
Copyright 2026 Nacre
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Nacre (https://nacre.work).
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0. See LICENSE.
|
|
7
|
+
|
|
8
|
+
"Nacre" and the Nacre mark are trademarks. Section 6 of the Apache License
|
|
9
|
+
grants no trademark rights; permitted use is described in TRADEMARK.md.
|
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @nacre.work/cli
|
|
2
|
+
|
|
3
|
+
The command line client for a [Nacre](https://nacre.work) installation.
|
|
4
|
+
|
|
5
|
+
Longer than its sibling packages' READMEs on purpose: the others are libraries
|
|
6
|
+
an application imports and this is the one thing a person runs, so this page is
|
|
7
|
+
where they land.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @nacre.work/cli login --url https://api.example
|
|
11
|
+
npx @nacre.work/cli layers create handbook --name Handbook
|
|
12
|
+
npx @nacre.work/cli ingest ./docs --layer handbook
|
|
13
|
+
npx @nacre.work/cli search "when do new hires get access"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Commands
|
|
17
|
+
|
|
18
|
+
| | |
|
|
19
|
+
|---|---|
|
|
20
|
+
| `login --url <url>` | sign in and remember the session. `--email`, `--org` optional |
|
|
21
|
+
| `whoami` | which principal this session is, and where |
|
|
22
|
+
| `layers` | the layers you can read |
|
|
23
|
+
| `layers create <slug>` | `--name`, `--description`, `--workspace`, `--provider` |
|
|
24
|
+
| `grant <permission> <scope> --to <principal>` | see below |
|
|
25
|
+
| `ingest <file\|dir>... --layer <slug>` | index text files and wait. `--watch` keeps going |
|
|
26
|
+
| `search <query>` | `--layer`, `--top-k` |
|
|
27
|
+
| `eval --layer <slug>` | score the layer's reference queries. `--top-k`, `--floor` |
|
|
28
|
+
|
|
29
|
+
`--json` prints the response as JSON for a script rather than a person.
|
|
30
|
+
|
|
31
|
+
A **scope** is `layer:<slug>`, `workspace:<slug>` or `document:<id>`. A
|
|
32
|
+
**principal** is `user:<id>`, `group:<id>` or `service_account:<id>`.
|
|
33
|
+
|
|
34
|
+
## The session
|
|
35
|
+
|
|
36
|
+
`login` writes `~/.config/nacre/config.json` at mode `0600`, in a directory at
|
|
37
|
+
`0700`. It holds a refresh token, which renews itself and so outlives the access
|
|
38
|
+
token beside it; on a shared machine a default umask would leave that readable
|
|
39
|
+
by everyone.
|
|
40
|
+
|
|
41
|
+
`NACRE_API_URL` and `NACRE_TOKEN` override the file. That is what CI uses: there
|
|
42
|
+
is no terminal to sign in from and nothing that could write a renewed token
|
|
43
|
+
down, so the environment is the whole session — and the file's refresh token is
|
|
44
|
+
deliberately not paired with it.
|
|
45
|
+
|
|
46
|
+
## Exit codes
|
|
47
|
+
|
|
48
|
+
| | |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `0` | it worked |
|
|
51
|
+
| `1` | the request was refused, or a document failed to index |
|
|
52
|
+
| `2` | the invocation was wrong, and repeating it will fail the same way |
|
|
53
|
+
|
|
54
|
+
A script that cannot tell `1` from `2` retries the second one forever. **An
|
|
55
|
+
ingest where any document failed exits `1`** with the per-document summary still
|
|
56
|
+
on stdout, so a nightly pass cannot report success having indexed nothing.
|
|
57
|
+
|
|
58
|
+
## Two things that are not bugs
|
|
59
|
+
|
|
60
|
+
**Permissions are not a ladder.** `write` does not imply `read`; `admin` implies
|
|
61
|
+
both. An ingest-only service account holds `write` and cannot search back what
|
|
62
|
+
it wrote.
|
|
63
|
+
|
|
64
|
+
**"Not found" and "not allowed to see it" are the same answer.** The server
|
|
65
|
+
returns `404` for both, deliberately and everywhere, so this client cannot tell
|
|
66
|
+
you which one happened and does not guess.
|
|
67
|
+
|
|
68
|
+
## What it does not do
|
|
69
|
+
|
|
70
|
+
- **Upload binaries.** Text files only; a PDF goes through
|
|
71
|
+
`POST /v1/documents` as `multipart/form-data`.
|
|
72
|
+
- **Delete anything while watching.** A file disappearing is indistinguishable
|
|
73
|
+
from the first half of how every editor saves, so `--watch` never removes a
|
|
74
|
+
document. That is `DELETE /v1/documents/{id}`, by hand.
|
|
75
|
+
- **Administer an installation.** Creating organizations, users and service
|
|
76
|
+
accounts is the API and the admin UI.
|
|
77
|
+
|
|
78
|
+
Apache 2.0. Full documentation at
|
|
79
|
+
[github.com/nacre-work/nacre](https://github.com/nacre-work/nacre/tree/main/docs).
|
package/dist/args.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Argument parsing, by hand.
|
|
3
|
+
*
|
|
4
|
+
* The same argument the parser and the S3 client make: this is a small,
|
|
5
|
+
* completely specified surface, and a dependency here would be one more thing
|
|
6
|
+
* with a release cadence in a program whose whole job is to be quick to install.
|
|
7
|
+
* `node:util`'s `parseArgs` would do most of it and is deliberately not used —
|
|
8
|
+
* it throws on an unknown option with a message that names neither the command
|
|
9
|
+
* nor what was expected, and the first thing anybody does with a CLI is get an
|
|
10
|
+
* option wrong.
|
|
11
|
+
*/
|
|
12
|
+
export interface Parsed {
|
|
13
|
+
readonly positional: readonly string[];
|
|
14
|
+
readonly options: ReadonlyMap<string, string | true>;
|
|
15
|
+
}
|
|
16
|
+
export declare function parse(argv: readonly string[]): Parsed;
|
|
17
|
+
/** A flag that was given a value is still a flag; `--json=false` is not. */
|
|
18
|
+
export declare function flag(parsed: Parsed, name: string): boolean;
|
|
19
|
+
export declare function option(parsed: Parsed, name: string): string | undefined;
|
|
20
|
+
export declare function integer(parsed: Parsed, name: string): number | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Wrong usage, as opposed to a request the server refused.
|
|
23
|
+
*
|
|
24
|
+
* Separate from every other failure because it exits `2` rather than `1`: a
|
|
25
|
+
* script that cannot tell "I called this wrong" from "the document was not
|
|
26
|
+
* found" retries the first one forever.
|
|
27
|
+
*/
|
|
28
|
+
export declare class UsageError extends Error {
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;IACtC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CACrD;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAoCrD;AAED,4EAA4E;AAC5E,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAG1D;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGvE;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQxE;AAED;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,KAAK;CAAG"}
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Argument parsing, by hand.
|
|
3
|
+
*
|
|
4
|
+
* The same argument the parser and the S3 client make: this is a small,
|
|
5
|
+
* completely specified surface, and a dependency here would be one more thing
|
|
6
|
+
* with a release cadence in a program whose whole job is to be quick to install.
|
|
7
|
+
* `node:util`'s `parseArgs` would do most of it and is deliberately not used —
|
|
8
|
+
* it throws on an unknown option with a message that names neither the command
|
|
9
|
+
* nor what was expected, and the first thing anybody does with a CLI is get an
|
|
10
|
+
* option wrong.
|
|
11
|
+
*/
|
|
12
|
+
export function parse(argv) {
|
|
13
|
+
const positional = [];
|
|
14
|
+
const options = new Map();
|
|
15
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
16
|
+
const token = argv[i];
|
|
17
|
+
// Everything after `--` is positional, whatever it looks like. A query is
|
|
18
|
+
// the argument most likely to start with a dash.
|
|
19
|
+
if (token === '--') {
|
|
20
|
+
positional.push(...argv.slice(i + 1));
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
if (!token.startsWith('--')) {
|
|
24
|
+
positional.push(token);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const body = token.slice(2);
|
|
28
|
+
const equals = body.indexOf('=');
|
|
29
|
+
if (equals !== -1) {
|
|
30
|
+
options.set(body.slice(0, equals), body.slice(equals + 1));
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const next = argv[i + 1];
|
|
34
|
+
if (next !== undefined && !next.startsWith('--')) {
|
|
35
|
+
options.set(body, next);
|
|
36
|
+
i += 1;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
options.set(body, true);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { positional, options };
|
|
43
|
+
}
|
|
44
|
+
/** A flag that was given a value is still a flag; `--json=false` is not. */
|
|
45
|
+
export function flag(parsed, name) {
|
|
46
|
+
const value = parsed.options.get(name);
|
|
47
|
+
return value === true || (typeof value === 'string' && value !== 'false');
|
|
48
|
+
}
|
|
49
|
+
export function option(parsed, name) {
|
|
50
|
+
const value = parsed.options.get(name);
|
|
51
|
+
return typeof value === 'string' ? value : undefined;
|
|
52
|
+
}
|
|
53
|
+
export function integer(parsed, name) {
|
|
54
|
+
const raw = option(parsed, name);
|
|
55
|
+
if (raw === undefined)
|
|
56
|
+
return undefined;
|
|
57
|
+
const value = Number(raw);
|
|
58
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
59
|
+
throw new UsageError(`--${name} takes a positive whole number, not ${JSON.stringify(raw)}`);
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Wrong usage, as opposed to a request the server refused.
|
|
65
|
+
*
|
|
66
|
+
* Separate from every other failure because it exits `2` rather than `1`: a
|
|
67
|
+
* script that cannot tell "I called this wrong" from "the document was not
|
|
68
|
+
* found" retries the first one forever.
|
|
69
|
+
*/
|
|
70
|
+
export class UsageError extends Error {
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=args.js.map
|
package/dist/args.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|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K;CAAG"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { NacreClient } from '@nacre.work/sdk';
|
|
2
|
+
import { type Parsed } from './args.js';
|
|
3
|
+
import { type Session } from './config.js';
|
|
4
|
+
import type { Outcome } from './run.js';
|
|
5
|
+
/**
|
|
6
|
+
* The commands.
|
|
7
|
+
*
|
|
8
|
+
* Each one returns text; nothing here writes to stdout directly, so a command
|
|
9
|
+
* is testable without capturing a stream and `--json` is one branch rather than
|
|
10
|
+
* a rule every command has to remember.
|
|
11
|
+
*/
|
|
12
|
+
export interface Context {
|
|
13
|
+
readonly parsed: Parsed;
|
|
14
|
+
readonly env: NodeJS.ProcessEnv;
|
|
15
|
+
/** Injected so the tests do not have to run a terminal. */
|
|
16
|
+
readonly prompt: (question: string, hidden: boolean) => Promise<string>;
|
|
17
|
+
readonly clientFor: (session: Session) => NacreClient;
|
|
18
|
+
}
|
|
19
|
+
export declare function login(context: Context): Promise<string>;
|
|
20
|
+
export declare function whoami(context: Context): Promise<string>;
|
|
21
|
+
export declare function layers(context: Context): Promise<string>;
|
|
22
|
+
export declare function grant(context: Context): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Whether a path is one this command would have ingested.
|
|
25
|
+
*
|
|
26
|
+
* Split out because the watcher needs the same answer for a single path that
|
|
27
|
+
* `collect` reaches by walking, and two spellings of "is this a file we index"
|
|
28
|
+
* is how a watcher comes to index a `.git` object nobody asked for.
|
|
29
|
+
*/
|
|
30
|
+
export declare function eligible(path: string): boolean;
|
|
31
|
+
export declare function collect(target: string): readonly {
|
|
32
|
+
path: string;
|
|
33
|
+
externalId: string;
|
|
34
|
+
}[];
|
|
35
|
+
export declare function ingest(context: Context): Promise<Outcome>;
|
|
36
|
+
export declare function search(context: Context): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Score a layer's reference query set, from outside the worker.
|
|
39
|
+
*
|
|
40
|
+
* The same measurement the reindex gate makes and for a different purpose. That
|
|
41
|
+
* one asks "can the new model still answer?" at a moment nobody chose; this
|
|
42
|
+
* asks "how is retrieval doing?" at a moment somebody did — before and after a
|
|
43
|
+
* chunking change, a reranker being switched on, a corpus growing by a
|
|
44
|
+
* quarter. Until now the answer to "what is your recall?" was a number that
|
|
45
|
+
* existed only inside a migration nobody was running.
|
|
46
|
+
*
|
|
47
|
+
* **Recall@k against documents the deployment picked**, averaged per query,
|
|
48
|
+
* which is the core's definition and deliberately not agreement with a previous
|
|
49
|
+
* model — a better model disagrees with the worse one it replaces.
|
|
50
|
+
*
|
|
51
|
+
* It is a read-only measurement: nothing here writes a verdict, moves a layer
|
|
52
|
+
* or touches the index. A number leaves, and that is all.
|
|
53
|
+
*/
|
|
54
|
+
export declare function evaluate(context: Context): Promise<Outcome>;
|
|
55
|
+
export interface Terminal {
|
|
56
|
+
readonly input: NodeJS.ReadableStream & {
|
|
57
|
+
isTTY?: boolean;
|
|
58
|
+
setRawMode?: (raw: boolean) => void;
|
|
59
|
+
};
|
|
60
|
+
readonly output: NodeJS.WritableStream;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Ask for something, and for a password ask without echoing it.
|
|
64
|
+
*
|
|
65
|
+
* The first version of this drove `readline` with `terminal: true` and
|
|
66
|
+
* intercepted its private `_writeToOutput`. It printed the password. Found by
|
|
67
|
+
* running it rather than by reading it: `terminal: true` makes readline echo
|
|
68
|
+
* whatever it reads, the interception is against an API with a leading
|
|
69
|
+
* underscore for a reason, and the case it failed on is the one a script uses —
|
|
70
|
+
* stdin is a pipe, where readline echoes the piped bytes back out because it
|
|
71
|
+
* was told there was a terminal.
|
|
72
|
+
*
|
|
73
|
+
* So readline is not involved in the hidden path at all. A pipe does not echo
|
|
74
|
+
* on its own, and a terminal does it in the driver, which raw mode turns off —
|
|
75
|
+
* two cases, each handled by the mechanism that actually governs it.
|
|
76
|
+
*
|
|
77
|
+
* This is not a security control. Anyone who can read this process can read the
|
|
78
|
+
* password whatever it does. What it buys is that the password is not in the
|
|
79
|
+
* scrollback, not in a screen recording, and not on the projector.
|
|
80
|
+
*/
|
|
81
|
+
export declare function ask(question: string, hidden: boolean, io?: Terminal): Promise<string>;
|
|
82
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAA4B,MAAM,iBAAiB,CAAA;AAEvE,OAAO,EAAqC,KAAK,MAAM,EAAE,MAAM,WAAW,CAAA;AAC1E,OAAO,EAA4B,KAAK,OAAO,EAAE,MAAM,aAAa,CAAA;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAEvC;;;;;;GAMG;AAEH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;IAC/B,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IACvE,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,WAAW,CAAA;CACtD;AA8BD,wBAAsB,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CA8B7D;AAED,wBAAsB,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAY9D;AAED,wBAAsB,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAuB9D;AAgDD,wBAAsB,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAsC7D;AA0BD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI9C;AAKD,wBAAgB,OA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