@nidl/cli 0.0.0-stage → 0.2.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.
- package/LICENSE +43 -0
- package/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +21 -0
- package/README.md +47 -2
- package/dist/command.d.ts +37 -0
- package/dist/command.js +87 -0
- package/dist/commands.generated.d.ts +286 -0
- package/dist/commands.generated.js +99 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +10 -0
- package/dist/run.d.ts +44 -0
- package/dist/run.js +163 -0
- package/package.json +33 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Licence
|
|
2
|
+
|
|
3
|
+
nidl is dual-licensed under either of
|
|
4
|
+
|
|
5
|
+
- Apache License, Version 2.0 ([LICENSE-APACHE](./LICENSE-APACHE))
|
|
6
|
+
- MIT License ([LICENSE-MIT](./LICENSE-MIT))
|
|
7
|
+
|
|
8
|
+
at your option. This is the Rust ecosystem's customary dual licence, and it is what the
|
|
9
|
+
great majority of this project's own dependencies already use.
|
|
10
|
+
|
|
11
|
+
Unless you explicitly state otherwise, any contribution intentionally submitted for
|
|
12
|
+
inclusion in this work by you, as defined in the Apache-2.0 licence, shall be dual
|
|
13
|
+
licensed as above, without any additional terms or conditions.
|
|
14
|
+
|
|
15
|
+
## Third-party notice
|
|
16
|
+
|
|
17
|
+
This notice is scoped to what each build contains, as
|
|
18
|
+
`.hermes/artifacts/plugin-cli-foundation/F-DEPENDENCY-SECURITY-AUDIT.md` s.2 records it. Its
|
|
19
|
+
obligations are recorded here rather than left to be discovered.
|
|
20
|
+
|
|
21
|
+
**The headless binary** (`nidl-core`, built without default features: what a handed build
|
|
22
|
+
contains) has one dependency under a copyleft licence:
|
|
23
|
+
|
|
24
|
+
**`option-ext`** (MPL-2.0), used unmodified, reached through `dirs` → `dirs-sys`. MPL-2.0 is
|
|
25
|
+
file-level copyleft: the obligation attaches to modifications of MPL-licensed *files*, not
|
|
26
|
+
to the work that links them. nidl modifies none, so what is owed is the notice above and
|
|
27
|
+
availability of that component's source, which is published at its own repository. It
|
|
28
|
+
places no constraint on nidl's own terms.
|
|
29
|
+
|
|
30
|
+
Everything else in the headless binary's dependency graph is permissive. No crate in it is under
|
|
31
|
+
GPL, LGPL or AGPL.
|
|
32
|
+
|
|
33
|
+
**The desktop app** (built with default features, and not distributed today) also contains the
|
|
34
|
+
four MPL-2.0 crates of its webview's CSS stack, each used unmodified, with the same obligation as
|
|
35
|
+
`option-ext`: **`cssparser`**, **`cssparser-macros`**, **`dtoa-short`** and **`selectors`**. No
|
|
36
|
+
crate in it is under GPL, LGPL or AGPL either.
|
|
37
|
+
|
|
38
|
+
**The website** (`@nidl/web`, private, and not distributed) depends on
|
|
39
|
+
**`@img/sharp-libvips-darwin-arm64`** (LGPL-3.0-or-later), a prebuilt image library reached through
|
|
40
|
+
`next` → `sharp`. Publishing the website would make its LGPL obligation live.
|
|
41
|
+
|
|
42
|
+
`tests/licence_notice_test.rs` reads both Rust dependency graphs, and fails when a copyleft crate in
|
|
43
|
+
either is not named here or a crate under GPL, LGPL or AGPL appears.
|
package/LICENSE-APACHE
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 [yyyy] [name of copyright owner]
|
|
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/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Criss Moldovan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nidl/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
nidl watches your model provider accounts and routes your coding harness's traffic through one
|
|
4
|
+
place you control. This package is its command line, `nidl`, and a small function for apps.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npm install -g @nidl/cli
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
npm installs the one package with the core for your platform beside it:
|
|
13
|
+
|
|
14
|
+
| Platform | Package |
|
|
15
|
+
| --- | --- |
|
|
16
|
+
| macOS on Apple silicon | `@nidl/cli-darwin-arm64`, signed by the publisher's Apple team |
|
|
17
|
+
| Linux x64, glibc 2.17 or later | `@nidl/cli-linux-x64-gnu` |
|
|
18
|
+
| Linux arm64, glibc 2.17 or later | `@nidl/cli-linux-arm64-gnu` |
|
|
19
|
+
|
|
20
|
+
Intel Macs, Linux with musl, and Windows have no package yet; `nidl` says so when it starts.
|
|
21
|
+
Node.js 22 or later is required.
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
nidl version
|
|
25
|
+
nidl serve --data-dir ~/.nidl
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The full guide (connecting accounts, unlocking, routing a harness) is the README in the
|
|
29
|
+
repository's `packaging` folder.
|
|
30
|
+
|
|
31
|
+
## From an app
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { command, CommandError } from "@nidl/cli";
|
|
35
|
+
|
|
36
|
+
const targets = await command("targets.list", {}, { dataDir: `${process.env.HOME}/.nidl` });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`command(name, args, { dataDir })` runs one nidl command with this platform's core and returns its
|
|
40
|
+
result, or throws a `CommandError` with the core's own code and message. The arguments go to the
|
|
41
|
+
core on its standard input, never on its command line. Commands that handle credentials are refused:
|
|
42
|
+
connect accounts and unlock with the `nidl` command itself, which asks for keys in its own prompt.
|
|
43
|
+
Without `dataDir`, `~/.nidl` is used. `corePath()` answers this platform's core's path, for a
|
|
44
|
+
program that starts a core itself, as `@nidl/client`'s `startTaskCore` does in a Trigger.dev task.
|
|
45
|
+
|
|
46
|
+
## Licence
|
|
47
|
+
|
|
48
|
+
MIT OR Apache-2.0.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type CommandName } from "./commands.generated.js";
|
|
2
|
+
export { COMMANDS, type CommandEffect, type CommandName } from "./commands.generated.js";
|
|
3
|
+
/** A command's failure: the core's own code and words, or nidl's when it refused before running. */
|
|
4
|
+
export declare class CommandError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
constructor(code: string, message: string);
|
|
7
|
+
}
|
|
8
|
+
export interface CommandExecution {
|
|
9
|
+
executable: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
env: NodeJS.ProcessEnv;
|
|
12
|
+
input: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CommandOutput {
|
|
15
|
+
code: number | null;
|
|
16
|
+
stdout: string;
|
|
17
|
+
stderr: string;
|
|
18
|
+
}
|
|
19
|
+
export interface CommandOptions {
|
|
20
|
+
/** The core's data folder; `~/.nidl` when absent (NM1 D3). A pure command takes none. */
|
|
21
|
+
dataDir?: string;
|
|
22
|
+
env?: NodeJS.ProcessEnv;
|
|
23
|
+
moduleUrl?: string;
|
|
24
|
+
execute?: (request: CommandExecution) => Promise<CommandOutput>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* TQ3 (docs/specs/nidl-task-vaults.md D7): the path of this platform's core, the one `command`
|
|
28
|
+
* runs, for a program that starts a core of its own, such as a Trigger.dev task's.
|
|
29
|
+
*/
|
|
30
|
+
export declare function corePath(moduleUrl?: string): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* NM1 (docs/specs/nidl-npm-packages.md s.2 item 2): one nidl command, run by this platform's core,
|
|
33
|
+
* its reply's result returned or its error thrown. The arguments go on the core's stdin (D1), never
|
|
34
|
+
* on its command line. Credential commands are refused: keys stay with the CLI's own prompt.
|
|
35
|
+
*/
|
|
36
|
+
export declare function command(name: CommandName, args?: Record<string, unknown>, options?: CommandOptions): Promise<unknown>;
|
|
37
|
+
//# sourceMappingURL=command.d.ts.map
|
package/dist/command.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { COMMANDS } from "./commands.generated.js";
|
|
5
|
+
import { coreEnvironment, resolvePackagedCore } from "./run.js";
|
|
6
|
+
export { COMMANDS } from "./commands.generated.js";
|
|
7
|
+
/** A command's failure: the core's own code and words, or nidl's when it refused before running. */
|
|
8
|
+
export class CommandError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
constructor(code, message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.name = "CommandError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function execute(request) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const child = spawn(request.executable, request.args, {
|
|
19
|
+
env: request.env,
|
|
20
|
+
shell: false,
|
|
21
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
22
|
+
windowsHide: true,
|
|
23
|
+
});
|
|
24
|
+
const stdout = [];
|
|
25
|
+
const stderr = [];
|
|
26
|
+
child.stdout.on("data", (chunk) => stdout.push(chunk));
|
|
27
|
+
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
28
|
+
child.once("error", reject);
|
|
29
|
+
child.once("close", (code) => resolve({
|
|
30
|
+
code,
|
|
31
|
+
stdout: Buffer.concat(stdout).toString("utf8"),
|
|
32
|
+
stderr: Buffer.concat(stderr).toString("utf8"),
|
|
33
|
+
}));
|
|
34
|
+
child.stdin.end(request.input);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* TQ3 (docs/specs/nidl-task-vaults.md D7): the path of this platform's core, the one `command`
|
|
39
|
+
* runs, for a program that starts a core of its own, such as a Trigger.dev task's.
|
|
40
|
+
*/
|
|
41
|
+
export async function corePath(moduleUrl) {
|
|
42
|
+
return resolvePackagedCore(moduleUrl);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* NM1 (docs/specs/nidl-npm-packages.md s.2 item 2): one nidl command, run by this platform's core,
|
|
46
|
+
* its reply's result returned or its error thrown. The arguments go on the core's stdin (D1), never
|
|
47
|
+
* on its command line. Credential commands are refused: keys stay with the CLI's own prompt.
|
|
48
|
+
*/
|
|
49
|
+
export async function command(name, args = {}, options = {}) {
|
|
50
|
+
const known = COMMANDS.find((entry) => entry.name === name);
|
|
51
|
+
if (known === undefined) {
|
|
52
|
+
throw new CommandError("unknown_command", `nidl has no command named ${String(name)}`);
|
|
53
|
+
}
|
|
54
|
+
if (known.effect === "credential_owner") {
|
|
55
|
+
throw new CommandError("not_allowed", `${name} handles credentials, so apps cannot run it; run it with the nidl CLI, which asks for them itself`);
|
|
56
|
+
}
|
|
57
|
+
// PQ3 (docs/specs/nidl-external-pools.md D7): this runs the CLI, as the owner; an app lends its
|
|
58
|
+
// project's key through a client library, which proves the project with an app token.
|
|
59
|
+
if (known.effect === "credential_lend") {
|
|
60
|
+
throw new CommandError("not_allowed", `${name} lends or withdraws a project's key; an app runs it with a nidl client library, and the owner with the nidl CLI`);
|
|
61
|
+
}
|
|
62
|
+
const executable = await resolvePackagedCore(options.moduleUrl);
|
|
63
|
+
const argv = ["command", name, "--input", "-", "--json"];
|
|
64
|
+
if (known.effect !== "pure") {
|
|
65
|
+
argv.push("--data-dir", options.dataDir ?? join(homedir(), ".nidl"));
|
|
66
|
+
}
|
|
67
|
+
const output = await (options.execute ?? execute)({
|
|
68
|
+
executable,
|
|
69
|
+
args: argv,
|
|
70
|
+
env: coreEnvironment(options.env ?? process.env),
|
|
71
|
+
input: JSON.stringify(args),
|
|
72
|
+
});
|
|
73
|
+
let reply;
|
|
74
|
+
try {
|
|
75
|
+
reply = JSON.parse(output.stdout);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw new CommandError("invalid_reply", "The nidl core did not answer with one JSON reply");
|
|
79
|
+
}
|
|
80
|
+
if (reply.ok === true)
|
|
81
|
+
return reply.result;
|
|
82
|
+
if (reply.ok === false && reply.error !== undefined) {
|
|
83
|
+
throw new CommandError(String(reply.error.code), String(reply.error.message));
|
|
84
|
+
}
|
|
85
|
+
throw new CommandError("invalid_reply", "The nidl core did not answer with one JSON reply");
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
export declare const COMMANDS: readonly [{
|
|
2
|
+
readonly name: "accounts.connect";
|
|
3
|
+
readonly effect: "credential_owner";
|
|
4
|
+
}, {
|
|
5
|
+
readonly name: "accounts.disconnect";
|
|
6
|
+
readonly effect: "credential_owner";
|
|
7
|
+
}, {
|
|
8
|
+
readonly name: "accounts.get";
|
|
9
|
+
readonly effect: "read_local";
|
|
10
|
+
}, {
|
|
11
|
+
readonly name: "accounts.list";
|
|
12
|
+
readonly effect: "read_local";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "accounts.reconnect";
|
|
15
|
+
readonly effect: "credential_owner";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "accounts.recover";
|
|
18
|
+
readonly effect: "credential_owner";
|
|
19
|
+
}, {
|
|
20
|
+
readonly name: "accounts.remove";
|
|
21
|
+
readonly effect: "credential_owner";
|
|
22
|
+
}, {
|
|
23
|
+
readonly name: "accounts.settings";
|
|
24
|
+
readonly effect: "credential_owner";
|
|
25
|
+
}, {
|
|
26
|
+
readonly name: "accounts.sign_in_again_start";
|
|
27
|
+
readonly effect: "credential_owner";
|
|
28
|
+
}, {
|
|
29
|
+
readonly name: "accounts.sign_in_cancel";
|
|
30
|
+
readonly effect: "credential_owner";
|
|
31
|
+
}, {
|
|
32
|
+
readonly name: "accounts.sign_in_finish";
|
|
33
|
+
readonly effect: "credential_owner";
|
|
34
|
+
}, {
|
|
35
|
+
readonly name: "accounts.sign_in_start";
|
|
36
|
+
readonly effect: "credential_owner";
|
|
37
|
+
}, {
|
|
38
|
+
readonly name: "accounts.update";
|
|
39
|
+
readonly effect: "draft_write";
|
|
40
|
+
}, {
|
|
41
|
+
readonly name: "accounts.update_settings";
|
|
42
|
+
readonly effect: "credential_owner";
|
|
43
|
+
}, {
|
|
44
|
+
readonly name: "app_tokens.issue";
|
|
45
|
+
readonly effect: "credential_owner";
|
|
46
|
+
}, {
|
|
47
|
+
readonly name: "app_tokens.list";
|
|
48
|
+
readonly effect: "credential_owner";
|
|
49
|
+
}, {
|
|
50
|
+
readonly name: "app_tokens.revoke";
|
|
51
|
+
readonly effect: "credential_owner";
|
|
52
|
+
}, {
|
|
53
|
+
readonly name: "catalog.refresh";
|
|
54
|
+
readonly effect: "network_read";
|
|
55
|
+
}, {
|
|
56
|
+
readonly name: "catalog.search";
|
|
57
|
+
readonly effect: "read_local";
|
|
58
|
+
}, {
|
|
59
|
+
readonly name: "commands.list";
|
|
60
|
+
readonly effect: "pure";
|
|
61
|
+
}, {
|
|
62
|
+
readonly name: "costs.get";
|
|
63
|
+
readonly effect: "read_local";
|
|
64
|
+
}, {
|
|
65
|
+
readonly name: "credentials.lock";
|
|
66
|
+
readonly effect: "credential_owner";
|
|
67
|
+
}, {
|
|
68
|
+
readonly name: "credentials.set_passphrase";
|
|
69
|
+
readonly effect: "credential_owner";
|
|
70
|
+
}, {
|
|
71
|
+
readonly name: "credentials.status";
|
|
72
|
+
readonly effect: "credential_owner";
|
|
73
|
+
}, {
|
|
74
|
+
readonly name: "credentials.unlock";
|
|
75
|
+
readonly effect: "credential_owner";
|
|
76
|
+
}, {
|
|
77
|
+
readonly name: "credentials.unlock_passphrase";
|
|
78
|
+
readonly effect: "credential_owner";
|
|
79
|
+
}, {
|
|
80
|
+
readonly name: "custom_harnesses.list";
|
|
81
|
+
readonly effect: "read_local";
|
|
82
|
+
}, {
|
|
83
|
+
readonly name: "custom_harnesses.remove";
|
|
84
|
+
readonly effect: "draft_write";
|
|
85
|
+
}, {
|
|
86
|
+
readonly name: "custom_harnesses.save";
|
|
87
|
+
readonly effect: "draft_write";
|
|
88
|
+
}, {
|
|
89
|
+
readonly name: "generations.list";
|
|
90
|
+
readonly effect: "read_local";
|
|
91
|
+
}, {
|
|
92
|
+
readonly name: "generations.preview";
|
|
93
|
+
readonly effect: "read_local";
|
|
94
|
+
}, {
|
|
95
|
+
readonly name: "generations.retire";
|
|
96
|
+
readonly effect: "native_apply";
|
|
97
|
+
}, {
|
|
98
|
+
readonly name: "generations.stop";
|
|
99
|
+
readonly effect: "native_apply";
|
|
100
|
+
}, {
|
|
101
|
+
readonly name: "launch.apply";
|
|
102
|
+
readonly effect: "native_apply";
|
|
103
|
+
}, {
|
|
104
|
+
readonly name: "launch.preview";
|
|
105
|
+
readonly effect: "read_local";
|
|
106
|
+
}, {
|
|
107
|
+
readonly name: "launch.remove";
|
|
108
|
+
readonly effect: "native_apply";
|
|
109
|
+
}, {
|
|
110
|
+
readonly name: "launch.status";
|
|
111
|
+
readonly effect: "read_local";
|
|
112
|
+
}, {
|
|
113
|
+
readonly name: "mappings.suggest";
|
|
114
|
+
readonly effect: "read_local";
|
|
115
|
+
}, {
|
|
116
|
+
readonly name: "mappings.validate";
|
|
117
|
+
readonly effect: "pure";
|
|
118
|
+
}, {
|
|
119
|
+
readonly name: "monitor.probe_now";
|
|
120
|
+
readonly effect: "paid_probe";
|
|
121
|
+
}, {
|
|
122
|
+
readonly name: "monitor.start";
|
|
123
|
+
readonly effect: "paid_probe";
|
|
124
|
+
}, {
|
|
125
|
+
readonly name: "monitor.status";
|
|
126
|
+
readonly effect: "read_local";
|
|
127
|
+
}, {
|
|
128
|
+
readonly name: "monitor.stop";
|
|
129
|
+
readonly effect: "draft_write";
|
|
130
|
+
}, {
|
|
131
|
+
readonly name: "operations.get";
|
|
132
|
+
readonly effect: "read_local";
|
|
133
|
+
}, {
|
|
134
|
+
readonly name: "plugins.disable";
|
|
135
|
+
readonly effect: "draft_write";
|
|
136
|
+
}, {
|
|
137
|
+
readonly name: "plugins.enable";
|
|
138
|
+
readonly effect: "draft_write";
|
|
139
|
+
}, {
|
|
140
|
+
readonly name: "plugins.lifecycle";
|
|
141
|
+
readonly effect: "read_local";
|
|
142
|
+
}, {
|
|
143
|
+
readonly name: "plugins.lifecycle_preview";
|
|
144
|
+
readonly effect: "read_local";
|
|
145
|
+
}, {
|
|
146
|
+
readonly name: "plugins.list";
|
|
147
|
+
readonly effect: "pure";
|
|
148
|
+
}, {
|
|
149
|
+
readonly name: "pools.lend";
|
|
150
|
+
readonly effect: "credential_lend";
|
|
151
|
+
}, {
|
|
152
|
+
readonly name: "pools.withdraw";
|
|
153
|
+
readonly effect: "credential_lend";
|
|
154
|
+
}, {
|
|
155
|
+
readonly name: "presets.get";
|
|
156
|
+
readonly effect: "pure";
|
|
157
|
+
}, {
|
|
158
|
+
readonly name: "presets.list";
|
|
159
|
+
readonly effect: "pure";
|
|
160
|
+
}, {
|
|
161
|
+
readonly name: "presets.validate";
|
|
162
|
+
readonly effect: "pure";
|
|
163
|
+
}, {
|
|
164
|
+
readonly name: "probes.costs";
|
|
165
|
+
readonly effect: "read_local";
|
|
166
|
+
}, {
|
|
167
|
+
readonly name: "probes.history";
|
|
168
|
+
readonly effect: "read_local";
|
|
169
|
+
}, {
|
|
170
|
+
readonly name: "projects.add_account";
|
|
171
|
+
readonly effect: "credential_owner";
|
|
172
|
+
}, {
|
|
173
|
+
readonly name: "projects.create";
|
|
174
|
+
readonly effect: "credential_owner";
|
|
175
|
+
}, {
|
|
176
|
+
readonly name: "projects.list";
|
|
177
|
+
readonly effect: "read_local";
|
|
178
|
+
}, {
|
|
179
|
+
readonly name: "projects.remove";
|
|
180
|
+
readonly effect: "credential_owner";
|
|
181
|
+
}, {
|
|
182
|
+
readonly name: "providers.list";
|
|
183
|
+
readonly effect: "pure";
|
|
184
|
+
}, {
|
|
185
|
+
readonly name: "readings.observe";
|
|
186
|
+
readonly effect: "draft_write";
|
|
187
|
+
}, {
|
|
188
|
+
readonly name: "remote.disable";
|
|
189
|
+
readonly effect: "credential_owner";
|
|
190
|
+
}, {
|
|
191
|
+
readonly name: "remote.enable";
|
|
192
|
+
readonly effect: "credential_owner";
|
|
193
|
+
}, {
|
|
194
|
+
readonly name: "remote.status";
|
|
195
|
+
readonly effect: "read_local";
|
|
196
|
+
}, {
|
|
197
|
+
readonly name: "remote_tokens.issue";
|
|
198
|
+
readonly effect: "credential_owner";
|
|
199
|
+
}, {
|
|
200
|
+
readonly name: "remote_tokens.list";
|
|
201
|
+
readonly effect: "credential_owner";
|
|
202
|
+
}, {
|
|
203
|
+
readonly name: "remote_tokens.revoke";
|
|
204
|
+
readonly effect: "credential_owner";
|
|
205
|
+
}, {
|
|
206
|
+
readonly name: "routing.apply";
|
|
207
|
+
readonly effect: "native_apply";
|
|
208
|
+
}, {
|
|
209
|
+
readonly name: "routing.disable";
|
|
210
|
+
readonly effect: "native_apply";
|
|
211
|
+
}, {
|
|
212
|
+
readonly name: "routing.disable_preview";
|
|
213
|
+
readonly effect: "read_local";
|
|
214
|
+
}, {
|
|
215
|
+
readonly name: "routing.preview";
|
|
216
|
+
readonly effect: "read_local";
|
|
217
|
+
}, {
|
|
218
|
+
readonly name: "routing.status";
|
|
219
|
+
readonly effect: "read_local";
|
|
220
|
+
}, {
|
|
221
|
+
readonly name: "routing_presets.list";
|
|
222
|
+
readonly effect: "read_local";
|
|
223
|
+
}, {
|
|
224
|
+
readonly name: "routing_presets.remove";
|
|
225
|
+
readonly effect: "draft_write";
|
|
226
|
+
}, {
|
|
227
|
+
readonly name: "routing_presets.save";
|
|
228
|
+
readonly effect: "draft_write";
|
|
229
|
+
}, {
|
|
230
|
+
readonly name: "runtime.version";
|
|
231
|
+
readonly effect: "pure";
|
|
232
|
+
}, {
|
|
233
|
+
readonly name: "targets.clone";
|
|
234
|
+
readonly effect: "draft_write";
|
|
235
|
+
}, {
|
|
236
|
+
readonly name: "targets.create";
|
|
237
|
+
readonly effect: "draft_write";
|
|
238
|
+
}, {
|
|
239
|
+
readonly name: "targets.get";
|
|
240
|
+
readonly effect: "read_local";
|
|
241
|
+
}, {
|
|
242
|
+
readonly name: "targets.list";
|
|
243
|
+
readonly effect: "read_local";
|
|
244
|
+
}, {
|
|
245
|
+
readonly name: "targets.preset_refresh_apply";
|
|
246
|
+
readonly effect: "draft_write";
|
|
247
|
+
}, {
|
|
248
|
+
readonly name: "targets.preset_refresh_preview";
|
|
249
|
+
readonly effect: "read_local";
|
|
250
|
+
}, {
|
|
251
|
+
readonly name: "targets.remove";
|
|
252
|
+
readonly effect: "draft_write";
|
|
253
|
+
}, {
|
|
254
|
+
readonly name: "targets.save";
|
|
255
|
+
readonly effect: "draft_write";
|
|
256
|
+
}, {
|
|
257
|
+
readonly name: "task_vaults.export";
|
|
258
|
+
readonly effect: "credential_owner";
|
|
259
|
+
}, {
|
|
260
|
+
readonly name: "usage.get";
|
|
261
|
+
readonly effect: "read_local";
|
|
262
|
+
}, {
|
|
263
|
+
readonly name: "watchers.add_model";
|
|
264
|
+
readonly effect: "draft_write";
|
|
265
|
+
}, {
|
|
266
|
+
readonly name: "watchers.disable";
|
|
267
|
+
readonly effect: "draft_write";
|
|
268
|
+
}, {
|
|
269
|
+
readonly name: "watchers.enable";
|
|
270
|
+
readonly effect: "paid_probe";
|
|
271
|
+
}, {
|
|
272
|
+
readonly name: "watchers.get";
|
|
273
|
+
readonly effect: "read_local";
|
|
274
|
+
}, {
|
|
275
|
+
readonly name: "watchers.history";
|
|
276
|
+
readonly effect: "read_local";
|
|
277
|
+
}, {
|
|
278
|
+
readonly name: "watchers.refresh";
|
|
279
|
+
readonly effect: "network_read";
|
|
280
|
+
}, {
|
|
281
|
+
readonly name: "watchers.remove_model";
|
|
282
|
+
readonly effect: "draft_write";
|
|
283
|
+
}];
|
|
284
|
+
export type CommandName = (typeof COMMANDS)[number]["name"];
|
|
285
|
+
export type CommandEffect = (typeof COMMANDS)[number]["effect"];
|
|
286
|
+
//# sourceMappingURL=commands.generated.d.ts.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Generated from the core's command registry. Do not edit by hand: the Rust test
|
|
2
|
+
// `cli_command_list_test` fails when this file differs, and prints it as it should be.
|
|
3
|
+
export const COMMANDS = [
|
|
4
|
+
{ name: "accounts.connect", effect: "credential_owner" },
|
|
5
|
+
{ name: "accounts.disconnect", effect: "credential_owner" },
|
|
6
|
+
{ name: "accounts.get", effect: "read_local" },
|
|
7
|
+
{ name: "accounts.list", effect: "read_local" },
|
|
8
|
+
{ name: "accounts.reconnect", effect: "credential_owner" },
|
|
9
|
+
{ name: "accounts.recover", effect: "credential_owner" },
|
|
10
|
+
{ name: "accounts.remove", effect: "credential_owner" },
|
|
11
|
+
{ name: "accounts.settings", effect: "credential_owner" },
|
|
12
|
+
{ name: "accounts.sign_in_again_start", effect: "credential_owner" },
|
|
13
|
+
{ name: "accounts.sign_in_cancel", effect: "credential_owner" },
|
|
14
|
+
{ name: "accounts.sign_in_finish", effect: "credential_owner" },
|
|
15
|
+
{ name: "accounts.sign_in_start", effect: "credential_owner" },
|
|
16
|
+
{ name: "accounts.update", effect: "draft_write" },
|
|
17
|
+
{ name: "accounts.update_settings", effect: "credential_owner" },
|
|
18
|
+
{ name: "app_tokens.issue", effect: "credential_owner" },
|
|
19
|
+
{ name: "app_tokens.list", effect: "credential_owner" },
|
|
20
|
+
{ name: "app_tokens.revoke", effect: "credential_owner" },
|
|
21
|
+
{ name: "catalog.refresh", effect: "network_read" },
|
|
22
|
+
{ name: "catalog.search", effect: "read_local" },
|
|
23
|
+
{ name: "commands.list", effect: "pure" },
|
|
24
|
+
{ name: "costs.get", effect: "read_local" },
|
|
25
|
+
{ name: "credentials.lock", effect: "credential_owner" },
|
|
26
|
+
{ name: "credentials.set_passphrase", effect: "credential_owner" },
|
|
27
|
+
{ name: "credentials.status", effect: "credential_owner" },
|
|
28
|
+
{ name: "credentials.unlock", effect: "credential_owner" },
|
|
29
|
+
{ name: "credentials.unlock_passphrase", effect: "credential_owner" },
|
|
30
|
+
{ name: "custom_harnesses.list", effect: "read_local" },
|
|
31
|
+
{ name: "custom_harnesses.remove", effect: "draft_write" },
|
|
32
|
+
{ name: "custom_harnesses.save", effect: "draft_write" },
|
|
33
|
+
{ name: "generations.list", effect: "read_local" },
|
|
34
|
+
{ name: "generations.preview", effect: "read_local" },
|
|
35
|
+
{ name: "generations.retire", effect: "native_apply" },
|
|
36
|
+
{ name: "generations.stop", effect: "native_apply" },
|
|
37
|
+
{ name: "launch.apply", effect: "native_apply" },
|
|
38
|
+
{ name: "launch.preview", effect: "read_local" },
|
|
39
|
+
{ name: "launch.remove", effect: "native_apply" },
|
|
40
|
+
{ name: "launch.status", effect: "read_local" },
|
|
41
|
+
{ name: "mappings.suggest", effect: "read_local" },
|
|
42
|
+
{ name: "mappings.validate", effect: "pure" },
|
|
43
|
+
{ name: "monitor.probe_now", effect: "paid_probe" },
|
|
44
|
+
{ name: "monitor.start", effect: "paid_probe" },
|
|
45
|
+
{ name: "monitor.status", effect: "read_local" },
|
|
46
|
+
{ name: "monitor.stop", effect: "draft_write" },
|
|
47
|
+
{ name: "operations.get", effect: "read_local" },
|
|
48
|
+
{ name: "plugins.disable", effect: "draft_write" },
|
|
49
|
+
{ name: "plugins.enable", effect: "draft_write" },
|
|
50
|
+
{ name: "plugins.lifecycle", effect: "read_local" },
|
|
51
|
+
{ name: "plugins.lifecycle_preview", effect: "read_local" },
|
|
52
|
+
{ name: "plugins.list", effect: "pure" },
|
|
53
|
+
{ name: "pools.lend", effect: "credential_lend" },
|
|
54
|
+
{ name: "pools.withdraw", effect: "credential_lend" },
|
|
55
|
+
{ name: "presets.get", effect: "pure" },
|
|
56
|
+
{ name: "presets.list", effect: "pure" },
|
|
57
|
+
{ name: "presets.validate", effect: "pure" },
|
|
58
|
+
{ name: "probes.costs", effect: "read_local" },
|
|
59
|
+
{ name: "probes.history", effect: "read_local" },
|
|
60
|
+
{ name: "projects.add_account", effect: "credential_owner" },
|
|
61
|
+
{ name: "projects.create", effect: "credential_owner" },
|
|
62
|
+
{ name: "projects.list", effect: "read_local" },
|
|
63
|
+
{ name: "projects.remove", effect: "credential_owner" },
|
|
64
|
+
{ name: "providers.list", effect: "pure" },
|
|
65
|
+
{ name: "readings.observe", effect: "draft_write" },
|
|
66
|
+
{ name: "remote.disable", effect: "credential_owner" },
|
|
67
|
+
{ name: "remote.enable", effect: "credential_owner" },
|
|
68
|
+
{ name: "remote.status", effect: "read_local" },
|
|
69
|
+
{ name: "remote_tokens.issue", effect: "credential_owner" },
|
|
70
|
+
{ name: "remote_tokens.list", effect: "credential_owner" },
|
|
71
|
+
{ name: "remote_tokens.revoke", effect: "credential_owner" },
|
|
72
|
+
{ name: "routing.apply", effect: "native_apply" },
|
|
73
|
+
{ name: "routing.disable", effect: "native_apply" },
|
|
74
|
+
{ name: "routing.disable_preview", effect: "read_local" },
|
|
75
|
+
{ name: "routing.preview", effect: "read_local" },
|
|
76
|
+
{ name: "routing.status", effect: "read_local" },
|
|
77
|
+
{ name: "routing_presets.list", effect: "read_local" },
|
|
78
|
+
{ name: "routing_presets.remove", effect: "draft_write" },
|
|
79
|
+
{ name: "routing_presets.save", effect: "draft_write" },
|
|
80
|
+
{ name: "runtime.version", effect: "pure" },
|
|
81
|
+
{ name: "targets.clone", effect: "draft_write" },
|
|
82
|
+
{ name: "targets.create", effect: "draft_write" },
|
|
83
|
+
{ name: "targets.get", effect: "read_local" },
|
|
84
|
+
{ name: "targets.list", effect: "read_local" },
|
|
85
|
+
{ name: "targets.preset_refresh_apply", effect: "draft_write" },
|
|
86
|
+
{ name: "targets.preset_refresh_preview", effect: "read_local" },
|
|
87
|
+
{ name: "targets.remove", effect: "draft_write" },
|
|
88
|
+
{ name: "targets.save", effect: "draft_write" },
|
|
89
|
+
{ name: "task_vaults.export", effect: "credential_owner" },
|
|
90
|
+
{ name: "usage.get", effect: "read_local" },
|
|
91
|
+
{ name: "watchers.add_model", effect: "draft_write" },
|
|
92
|
+
{ name: "watchers.disable", effect: "draft_write" },
|
|
93
|
+
{ name: "watchers.enable", effect: "paid_probe" },
|
|
94
|
+
{ name: "watchers.get", effect: "read_local" },
|
|
95
|
+
{ name: "watchers.history", effect: "read_local" },
|
|
96
|
+
{ name: "watchers.refresh", effect: "network_read" },
|
|
97
|
+
{ name: "watchers.remove_model", effect: "draft_write" },
|
|
98
|
+
];
|
|
99
|
+
//# sourceMappingURL=commands.generated.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { CliFailure, run } from "./run.js";
|
|
3
|
+
try {
|
|
4
|
+
process.exitCode = await run(process.argv.slice(2));
|
|
5
|
+
}
|
|
6
|
+
catch (error) {
|
|
7
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
8
|
+
process.exitCode = error instanceof CliFailure ? error.exitCode : 1;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/dist/run.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare class CliFailure extends Error {
|
|
2
|
+
readonly exitCode: number;
|
|
3
|
+
constructor(exitCode: number, message: string);
|
|
4
|
+
}
|
|
5
|
+
export interface CoreInvocation {
|
|
6
|
+
executable: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
env: NodeJS.ProcessEnv;
|
|
9
|
+
shell: false;
|
|
10
|
+
stdio: "inherit";
|
|
11
|
+
windowsHide: true;
|
|
12
|
+
}
|
|
13
|
+
export interface CoreExit {
|
|
14
|
+
code: number | null;
|
|
15
|
+
signal: NodeJS.Signals | null;
|
|
16
|
+
}
|
|
17
|
+
export interface RunContext {
|
|
18
|
+
moduleUrl?: string;
|
|
19
|
+
env?: NodeJS.ProcessEnv;
|
|
20
|
+
invoke?: (request: CoreInvocation) => Promise<CoreExit>;
|
|
21
|
+
platform?: PlatformFacts;
|
|
22
|
+
}
|
|
23
|
+
/** What chooses the platform package: the OS, the CPU, and on Linux whether libc is glibc. */
|
|
24
|
+
export interface PlatformFacts {
|
|
25
|
+
platform: NodeJS.Platform;
|
|
26
|
+
arch: string;
|
|
27
|
+
glibc: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* NM1 (docs/specs/nidl-npm-packages.md s.2 item 1): the package carrying each platform's core.
|
|
31
|
+
* Intel Macs, musl and Windows have none yet.
|
|
32
|
+
*/
|
|
33
|
+
export declare const PLATFORM_PACKAGES: Readonly<Record<string, string>>;
|
|
34
|
+
export declare function currentPlatform(): PlatformFacts;
|
|
35
|
+
export declare function platformKey(facts: PlatformFacts): string;
|
|
36
|
+
/**
|
|
37
|
+
* NM1 (docs/specs/nidl-npm-packages.md s.2 item 1, D2): the core beside the CLI's own files, as the
|
|
38
|
+
* handed folder lays it out; otherwise the one in this platform's package, found the way Node finds
|
|
39
|
+
* any package from here.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolvePackagedCore(moduleUrl?: string, facts?: PlatformFacts): Promise<string>;
|
|
42
|
+
export declare function coreEnvironment(source: NodeJS.ProcessEnv, args?: readonly string[]): NodeJS.ProcessEnv;
|
|
43
|
+
export declare function run(args: string[], context?: RunContext): Promise<number>;
|
|
44
|
+
//# sourceMappingURL=run.d.ts.map
|
package/dist/run.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { lstat } from "node:fs/promises";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
const CORE_ENVIRONMENT_KEYS = [
|
|
7
|
+
"HOME",
|
|
8
|
+
"TMPDIR",
|
|
9
|
+
"LANG",
|
|
10
|
+
"LC_ALL",
|
|
11
|
+
"LC_CTYPE",
|
|
12
|
+
"TERM",
|
|
13
|
+
"NO_COLOR",
|
|
14
|
+
"FORCE_COLOR",
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* NR3 (docs/specs/nidl-remote-mode.md s.5 item 2): a core on another machine, and its token, which
|
|
18
|
+
* is never taken on the command line. Passed only to the words that can run on a remote core, so a
|
|
19
|
+
* long-lived `serve` or `mcp` never carries the token (NR3's review, m9).
|
|
20
|
+
*/
|
|
21
|
+
const REMOTE_ENVIRONMENT_KEYS = ["NIDL_REMOTE", "NIDL_TOKEN", "NIDL_FINGERPRINT"];
|
|
22
|
+
const REMOTE_WORDS = new Set(["targets", "app-tokens", "remote", "remote-tokens", "command"]);
|
|
23
|
+
export class CliFailure extends Error {
|
|
24
|
+
exitCode;
|
|
25
|
+
constructor(exitCode, message) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.exitCode = exitCode;
|
|
28
|
+
this.name = "CliFailure";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* NM1 (docs/specs/nidl-npm-packages.md s.2 item 1): the package carrying each platform's core.
|
|
33
|
+
* Intel Macs, musl and Windows have none yet.
|
|
34
|
+
*/
|
|
35
|
+
export const PLATFORM_PACKAGES = {
|
|
36
|
+
"darwin-arm64": "@nidl/cli-darwin-arm64",
|
|
37
|
+
"linux-x64-gnu": "@nidl/cli-linux-x64-gnu",
|
|
38
|
+
"linux-arm64-gnu": "@nidl/cli-linux-arm64-gnu",
|
|
39
|
+
};
|
|
40
|
+
export function currentPlatform() {
|
|
41
|
+
const report = process.report?.getReport();
|
|
42
|
+
return {
|
|
43
|
+
platform: process.platform,
|
|
44
|
+
arch: process.arch,
|
|
45
|
+
glibc: typeof report?.header?.glibcVersionRuntime === "string",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function platformKey(facts) {
|
|
49
|
+
if (facts.platform !== "linux")
|
|
50
|
+
return `${facts.platform}-${facts.arch}`;
|
|
51
|
+
return `${facts.platform}-${facts.arch}-${facts.glibc ? "gnu" : "musl"}`;
|
|
52
|
+
}
|
|
53
|
+
function failureForInspection(error) {
|
|
54
|
+
if (error?.code === "ENOENT") {
|
|
55
|
+
return new CliFailure(3, "Packaged nidl core is missing");
|
|
56
|
+
}
|
|
57
|
+
return new CliFailure(1, "Could not inspect the packaged nidl core");
|
|
58
|
+
}
|
|
59
|
+
function failureForLaunch(error) {
|
|
60
|
+
const code = error?.code;
|
|
61
|
+
if (code === "ENOENT")
|
|
62
|
+
return new CliFailure(3, "Packaged nidl core is missing");
|
|
63
|
+
if (code === "EACCES")
|
|
64
|
+
return new CliFailure(5, "Packaged nidl core is not executable");
|
|
65
|
+
return new CliFailure(1, "Could not launch the packaged nidl core");
|
|
66
|
+
}
|
|
67
|
+
async function checkedCore(executable, platform) {
|
|
68
|
+
let metadata;
|
|
69
|
+
try {
|
|
70
|
+
metadata = await lstat(executable);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw failureForInspection(error);
|
|
74
|
+
}
|
|
75
|
+
if (metadata.isSymbolicLink() || !metadata.isFile()) {
|
|
76
|
+
throw new CliFailure(5, "Packaged nidl core has an unsafe file type");
|
|
77
|
+
}
|
|
78
|
+
if (platform !== "win32" && (metadata.mode & 0o111) === 0) {
|
|
79
|
+
throw new CliFailure(5, "Packaged nidl core is not executable");
|
|
80
|
+
}
|
|
81
|
+
return executable;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* NM1 (docs/specs/nidl-npm-packages.md s.2 item 1, D2): the core beside the CLI's own files, as the
|
|
85
|
+
* handed folder lays it out; otherwise the one in this platform's package, found the way Node finds
|
|
86
|
+
* any package from here.
|
|
87
|
+
*/
|
|
88
|
+
export async function resolvePackagedCore(moduleUrl = import.meta.url, facts = currentPlatform()) {
|
|
89
|
+
const leaf = facts.platform === "win32" ? "nidl-core.exe" : "nidl-core";
|
|
90
|
+
const beside = join(dirname(fileURLToPath(moduleUrl)), leaf);
|
|
91
|
+
let besideExists = true;
|
|
92
|
+
try {
|
|
93
|
+
await lstat(beside);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error?.code !== "ENOENT") {
|
|
97
|
+
throw failureForInspection(error);
|
|
98
|
+
}
|
|
99
|
+
besideExists = false;
|
|
100
|
+
}
|
|
101
|
+
if (besideExists)
|
|
102
|
+
return checkedCore(beside, facts.platform);
|
|
103
|
+
const key = platformKey(facts);
|
|
104
|
+
const name = PLATFORM_PACKAGES[key];
|
|
105
|
+
if (name === undefined) {
|
|
106
|
+
throw new CliFailure(3, `nidl has no package for this platform (${key})`);
|
|
107
|
+
}
|
|
108
|
+
let manifest;
|
|
109
|
+
try {
|
|
110
|
+
manifest = createRequire(moduleUrl).resolve(`${name}/package.json`);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
throw new CliFailure(3, "Packaged nidl core is missing");
|
|
114
|
+
}
|
|
115
|
+
return checkedCore(join(dirname(manifest), "bin", leaf), facts.platform);
|
|
116
|
+
}
|
|
117
|
+
export function coreEnvironment(source, args = []) {
|
|
118
|
+
const environment = {};
|
|
119
|
+
const keys = [
|
|
120
|
+
...CORE_ENVIRONMENT_KEYS,
|
|
121
|
+
...(args[0] !== undefined && REMOTE_WORDS.has(args[0]) ? REMOTE_ENVIRONMENT_KEYS : []),
|
|
122
|
+
];
|
|
123
|
+
for (const key of keys) {
|
|
124
|
+
const value = source[key];
|
|
125
|
+
if (value !== undefined)
|
|
126
|
+
environment[key] = value;
|
|
127
|
+
}
|
|
128
|
+
return environment;
|
|
129
|
+
}
|
|
130
|
+
async function invokeCore(request) {
|
|
131
|
+
return new Promise((resolve, reject) => {
|
|
132
|
+
const child = spawn(request.executable, request.args, {
|
|
133
|
+
env: request.env,
|
|
134
|
+
shell: request.shell,
|
|
135
|
+
stdio: request.stdio,
|
|
136
|
+
windowsHide: request.windowsHide,
|
|
137
|
+
});
|
|
138
|
+
child.once("error", reject);
|
|
139
|
+
child.once("close", (code, signal) => resolve({ code, signal }));
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
export async function run(args, context = {}) {
|
|
143
|
+
const executable = await resolvePackagedCore(context.moduleUrl, context.platform);
|
|
144
|
+
const request = {
|
|
145
|
+
executable,
|
|
146
|
+
args,
|
|
147
|
+
env: coreEnvironment(context.env ?? process.env, args),
|
|
148
|
+
shell: false,
|
|
149
|
+
stdio: "inherit",
|
|
150
|
+
windowsHide: true,
|
|
151
|
+
};
|
|
152
|
+
let result;
|
|
153
|
+
try {
|
|
154
|
+
result = await (context.invoke ?? invokeCore)(request);
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
throw failureForLaunch(error);
|
|
158
|
+
}
|
|
159
|
+
if (result.code !== null)
|
|
160
|
+
return result.code;
|
|
161
|
+
throw new CliFailure(1, "Packaged nidl core terminated before returning an exit code");
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=run.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nidl/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "CLI for nidl: provider account watching, catalog search and harness routing.",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/command.d.ts",
|
|
10
|
+
"default": "./dist/command.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/command.d.ts",
|
|
15
|
+
"bin": {
|
|
16
|
+
"nidl": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"LICENSE-APACHE",
|
|
21
|
+
"LICENSE-MIT"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/crissmoldovan/nidl.git"
|
|
29
|
+
},
|
|
30
|
+
"optionalDependencies": {
|
|
31
|
+
"@nidl/cli-darwin-arm64": "0.2.0",
|
|
32
|
+
"@nidl/cli-linux-x64-gnu": "0.2.0",
|
|
33
|
+
"@nidl/cli-linux-arm64-gnu": "0.2.0"
|
|
34
|
+
}
|
|
35
|
+
}
|