@kitionstage/cli 0.0.0-stage → 0.5.2-stage.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -2
- package/dist/LICENSE +177 -0
- package/dist/chunks/resolve-qkpPHdnj.js +114 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +28 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +16 -0
- package/dist/install.ps1 +154 -0
- package/dist/install.sh +167 -0
- package/dist/machine.d.ts +3 -0
- package/dist/resolve.d.ts +82 -0
- package/package.json +49 -4
package/README.md
CHANGED
|
@@ -1,3 +1,137 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kition/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Kition's command line, from npm. `kition` holds no kit: it downloads each published kit the first
|
|
4
|
+
time you or your agent need it, into `~/.kition/kits`, and serves the kits' tools to any agent
|
|
5
|
+
over MCP (Claude Code, Claude Desktop, Cursor, Codex, or your own MCP client). No Kition app has
|
|
6
|
+
to run, nothing is compiled on your machine, and no license key is needed.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install -g @kition/cli
|
|
10
|
+
kition --version
|
|
11
|
+
kition kit install note
|
|
12
|
+
kition agent add claude # in your project folder: Claude Code runs `kition mcp` there
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
or, without installing:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npx -y @kition/cli kit list
|
|
19
|
+
npx -y @kition/cli mcp --workspace <folder>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Node.js 20 or later, on macOS (arm64, x64), Linux with glibc (arm64, x64) or Windows (x64). The
|
|
23
|
+
same `kition`, without Node.js: this package carries an install script (`dist/install.sh`,
|
|
24
|
+
`dist/install.ps1` on Windows) that downloads `@kition/cli-<platform>` from the npm registry
|
|
25
|
+
(registry.npmjs.org, else registry.npmmirror.com, or `KITION_NPM_REGISTRY`) with `curl` and `tar`,
|
|
26
|
+
checks its integrity, and installs `~/.kition/bin/kition`:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
curl -fsSL https://unpkg.com/@kition/cli/dist/install.sh | sh
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Every command (`kit`, `agent`, `mcp`, `serve`, `doctor`) is in
|
|
33
|
+
[docs/sdk/cli.md](https://github.com/KitionAI/kition-sdk/blob/main/docs/sdk/cli.md).
|
|
34
|
+
|
|
35
|
+
## Connect your agent
|
|
36
|
+
|
|
37
|
+
`kition agent add claude` (or `codex`, `cursor`) registers `kition mcp` with the agent and prints
|
|
38
|
+
what it ran or wrote. Installed with `npm install -g @kition/cli`, it registers npm's `kition` command;
|
|
39
|
+
run through `npx -y @kition/cli agent add ...`, it registers `npx -y @kition/cli mcp`, so the agent can
|
|
40
|
+
start it again after npm clears its cache. By hand:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
claude mcp add kition -- npx -y @kition/cli mcp --workspace "$PWD"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Claude Desktop, Cursor, and any client with an `mcpServers` file** (`claude_desktop_config.json`,
|
|
47
|
+
`.cursor/mcp.json`, `.mcp.json`, ...). Use an absolute path where the client does not start
|
|
48
|
+
servers in your project folder (Claude Desktop); Cursor fills in `${workspaceFolder}`:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"mcpServers": {
|
|
53
|
+
"kition": {
|
|
54
|
+
"command": "npx",
|
|
55
|
+
"args": ["-y", "@kition/cli", "mcp", "--workspace", "/absolute/path/to/folder"]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Codex**: `~/.codex/config.toml`:
|
|
62
|
+
|
|
63
|
+
```toml
|
|
64
|
+
[mcp_servers.kition]
|
|
65
|
+
command = "npx"
|
|
66
|
+
args = ["-y", "@kition/cli", "mcp", "--workspace", "/absolute/path/to/folder"]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
With `kition` installed globally, put `kition` as the command and drop `-y` and `@kition/cli`
|
|
70
|
+
from the arguments. On Windows, an agent starts `npx` (a batch file) as `cmd /c npx -y @kition/cli mcp ...`.
|
|
71
|
+
|
|
72
|
+
The server's tools, the workspace and its sandbox, drafts and kits installed on first use are in
|
|
73
|
+
[docs/sdk/agent.md](https://github.com/KitionAI/kition-sdk/blob/main/docs/sdk/agent.md) and
|
|
74
|
+
[docs/sdk/cli.md](https://github.com/KitionAI/kition-sdk/blob/main/docs/sdk/cli.md#your-agent).
|
|
75
|
+
|
|
76
|
+
## How the `kition` command finds kition
|
|
77
|
+
|
|
78
|
+
The `kition` command here is a small Node launcher. It starts the `kition` executable for this
|
|
79
|
+
platform with your arguments and your standard input, output and error, and exits with its exit
|
|
80
|
+
code or signal; a client's SIGTERM or SIGINT is passed on, and when the client closes standard
|
|
81
|
+
input, `kition mcp` ends by itself. The launcher itself never writes to standard output. It runs:
|
|
82
|
+
|
|
83
|
+
1. `KITION_BINARY`, an executable you name, for example a development build. If the variable
|
|
84
|
+
names a missing file, the launcher stops with an error.
|
|
85
|
+
2. Otherwise the `bin/kition` of the optional package `@kition/cli-<platform>`, which npm installs
|
|
86
|
+
with this one on `darwin-arm64`, `darwin-x64`, `linux-arm64` (glibc), `linux-x64` (glibc) and
|
|
87
|
+
`win32-x64`. It holds `kition` and nothing else.
|
|
88
|
+
|
|
89
|
+
It never looks on the `PATH`, where `npm install -g` puts this launcher itself. If there is no
|
|
90
|
+
`kition` for this platform, the launcher says why on standard error: the platform is not one of
|
|
91
|
+
those, Linux runs musl (Alpine), or npm left the optional package out (`--omit=optional`,
|
|
92
|
+
`--no-optional`); and it names `install.sh` (`install.ps1` on Windows) as the way without npm.
|
|
93
|
+
|
|
94
|
+
The launcher tells `kition` how it was started in `KITION_LAUNCHER`, a JSON object with `via`
|
|
95
|
+
(`npx` or `npm`), `command` (the words that start this `kition` again) and `executable` (the
|
|
96
|
+
`kition` it started), which `kition agent add` registers and `kition doctor` checks on the `PATH`.
|
|
97
|
+
|
|
98
|
+
Programs that start kition themselves can use the same lookup:
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
import { launchedAs, resolveKition, thisMachine } from '@kition/cli'
|
|
102
|
+
// resolveKition(thisMachine(file)) -> { ok, command } or { ok: false, message }
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
<!-- kition-family:begin (generated by kition-sdk from templates/community/repositories.json, its family; edit the data there, not this text) -->
|
|
106
|
+
## Part of the Kition SDK
|
|
107
|
+
|
|
108
|
+
`@kition/cli` is a package of the [Kition SDK](https://github.com/KitionAI/kition-sdk) ([its source](https://github.com/KitionAI/kition-sdk/tree/main/packages/kition)), which lets you put Kition's editors in your product, and give the same files to your AI agent. Guides and reference: [developer.kition.ai](https://developer.kition.ai).
|
|
109
|
+
|
|
110
|
+
## The Kition family
|
|
111
|
+
|
|
112
|
+
Kition is the open pro suite for AI: 16 kits, editors that people and AI agents use on the same files, and the products around them ([all repositories](https://github.com/KitionAI)).
|
|
113
|
+
|
|
114
|
+
| Product | What it is | Links |
|
|
115
|
+
| --- | --- | --- |
|
|
116
|
+
| Kition Desktop | The open pro suite for AI: 16 editors and an agent in one desktop app | [GitHub](https://github.com/KitionAI/kition) · [kition.ai](https://kition.ai) |
|
|
117
|
+
| Kition SDK | Put Kition's editors in your product, and give the same files to your AI agent | [GitHub](https://github.com/KitionAI/kition-sdk) · [developer.kition.ai](https://developer.kition.ai) |
|
|
118
|
+
| **`kition` command line** | Install kits on demand and run them for your agent: `npx @kition/cli` | [developer.kition.ai](https://developer.kition.ai) · [Guide](https://github.com/KitionAI/kition-sdk/blob/main/docs/sdk/cli.md) |
|
|
119
|
+
| Kition One | A self-hosted team workspace built on Kition's kits | [one.kition.ai](https://one.kition.ai) |
|
|
120
|
+
| Kition Server | Real-time co-editing for kits, self-hosted | [developer.kition.ai](https://developer.kition.ai) |
|
|
121
|
+
| Kit Harness Protocol (KHP) | The open protocol between a kit and its host | [GitHub](https://github.com/kitharness/kitharness) · [kitharness.org](https://kitharness.org) |
|
|
122
|
+
| Kition Tessera | The design system for kits | [GitHub](https://github.com/KitionAI/kition-tessera) · [tessera.kition.ai](https://tessera.kition.ai) |
|
|
123
|
+
| Kition Showcase | Sample files for every kit | [GitHub](https://github.com/KitionAI/kition-showcase) |
|
|
124
|
+
| Kition Universe | A 3D map of the kits and what they make | [GitHub](https://github.com/KitionAI/kition-universe) · [universe.kition.ai](https://universe.kition.ai) |
|
|
125
|
+
| Kition Fonts | The open fonts the editors use | [GitHub](https://github.com/KitionAI/kition-fonts) |
|
|
126
|
+
|
|
127
|
+
| Product line | Kits |
|
|
128
|
+
| --- | --- |
|
|
129
|
+
| Office | [Note](https://github.com/KitionAI/kition-note) · [Table](https://github.com/KitionAI/kition-table) · [Board](https://github.com/KitionAI/kition-board) · [Doc](https://github.com/KitionAI/kition-doc) · [Sheet](https://github.com/KitionAI/kition-sheet) · [Slide](https://github.com/KitionAI/kition-slide) · [PDF](https://github.com/KitionAI/kition-pdf) · [HTML](https://github.com/KitionAI/kition-html) (Preview) |
|
|
130
|
+
| Design | [Photo](https://github.com/KitionAI/kition-photo) · [Vector](https://github.com/KitionAI/kition-vector) · [Layout](https://github.com/KitionAI/kition-layout) · [Design](https://github.com/KitionAI/kition-design) (Preview) |
|
|
131
|
+
| Media | [Film](https://github.com/KitionAI/kition-film) · [Motion](https://github.com/KitionAI/kition-motion) |
|
|
132
|
+
| Engineering | [CAD](https://github.com/KitionAI/kition-cad) · [Scene](https://github.com/KitionAI/kition-scene) (Preview) |
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
Apache-2.0 ([LICENSE](https://github.com/KitionAI/kition-sdk/blob/main/LICENSE)).
|
|
137
|
+
<!-- kition-family:end -->
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
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
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import g from "node:fs";
|
|
2
|
+
import { createRequire as h } from "node:module";
|
|
3
|
+
import r from "node:path";
|
|
4
|
+
function x() {
|
|
5
|
+
return process.platform !== "linux" ? void 0 : !!process.report?.getReport()?.header?.glibcVersionRuntime;
|
|
6
|
+
}
|
|
7
|
+
const d = (t) => {
|
|
8
|
+
try {
|
|
9
|
+
return g.realpathSync(t);
|
|
10
|
+
} catch {
|
|
11
|
+
return t;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
function A(t) {
|
|
15
|
+
try {
|
|
16
|
+
const n = JSON.parse(g.readFileSync(r.join(r.dirname(r.dirname(t)), "package.json"), "utf8")).name;
|
|
17
|
+
return typeof n == "string" ? n : void 0;
|
|
18
|
+
} catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function O(t) {
|
|
23
|
+
const n = h(t);
|
|
24
|
+
return {
|
|
25
|
+
name: A(d(t)),
|
|
26
|
+
env: process.env,
|
|
27
|
+
platform: process.platform,
|
|
28
|
+
arch: process.arch,
|
|
29
|
+
glibc: x(),
|
|
30
|
+
packageDir(o) {
|
|
31
|
+
try {
|
|
32
|
+
return r.dirname(n.resolve(`${o}/package.json`));
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
isFile: (o) => g.statSync(o, { throwIfNoEntry: !1 })?.isFile() ?? !1,
|
|
38
|
+
realPath: d,
|
|
39
|
+
self: d(t),
|
|
40
|
+
join: r.join,
|
|
41
|
+
dirname: r.dirname,
|
|
42
|
+
basename: r.basename
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const I = "The platforms the npm package @kition/cli ships kition for, each as the optional package @kition/cli-<platform> (scripts/platform-package.mjs). The key is Node's `${process.platform}-${process.arch}`, which is also the SDK release's platform name.", N = {
|
|
46
|
+
$comment: I,
|
|
47
|
+
"darwin-arm64": { os: "darwin", cpu: "arm64", rustTarget: "aarch64-apple-darwin" },
|
|
48
|
+
"darwin-x64": { os: "darwin", cpu: "x64", rustTarget: "x86_64-apple-darwin" },
|
|
49
|
+
"linux-arm64": { os: "linux", cpu: "arm64", libc: "glibc", rustTarget: "aarch64-unknown-linux-gnu" },
|
|
50
|
+
"linux-x64": { os: "linux", cpu: "x64", libc: "glibc", rustTarget: "x86_64-unknown-linux-gnu" },
|
|
51
|
+
"win32-x64": { os: "win32", cpu: "x64", rustTarget: "x86_64-pc-windows-msvc" }
|
|
52
|
+
}, b = "@kition/cli", _ = "@kition", j = "KITION_NPM_SCOPE", p = "kition", k = "KITION_BINARY", y = "KITION_LAUNCHER", w = Object.fromEntries(Object.entries(N).filter(([t]) => !t.startsWith("$"))), $ = (t, n = b) => `${n}-${t}`;
|
|
53
|
+
function K(t, n) {
|
|
54
|
+
const o = /^(@[a-z0-9][a-z0-9-]*)\//.exec(t)?.[1];
|
|
55
|
+
return !o || o === _ || n[j] !== void 0 ? null : o;
|
|
56
|
+
}
|
|
57
|
+
const S = (t) => t === "win32" ? ".exe" : "";
|
|
58
|
+
function v() {
|
|
59
|
+
const t = Object.entries(w).map(([n, o]) => o.libc ? `${n} (${o.libc})` : n);
|
|
60
|
+
return `${t.slice(0, -1).join(", ")} and ${t[t.length - 1]}`;
|
|
61
|
+
}
|
|
62
|
+
const T = "curl -fsSL https://unpkg.com/@kition/cli/dist/install.sh | sh", E = "irm https://unpkg.com/@kition/cli/dist/install.ps1 | iex";
|
|
63
|
+
function B(t) {
|
|
64
|
+
const n = t.env[k];
|
|
65
|
+
if (n)
|
|
66
|
+
return t.isFile(n) ? { ok: !0, command: n, from: "env" } : { ok: !1, message: `${k} names ${n}, which is no file. Point it at a kition executable, or unset it.` };
|
|
67
|
+
const o = t.name ?? b, s = `${t.platform}-${t.arch}`, f = w[s], a = f?.libc === "glibc" && t.glibc === !1, l = f && !a;
|
|
68
|
+
if (l) {
|
|
69
|
+
const m = t.packageDir($(s, o));
|
|
70
|
+
if (m) {
|
|
71
|
+
const e = t.join(m, "bin", `${p}${S(t.platform)}`);
|
|
72
|
+
if (t.isFile(e)) return { ok: !0, command: e, from: "package" };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const i = a ? `${s} (not glibc: musl, as on Alpine)` : s, u = l ? `The optional package ${$(s, o)} that carries it is not installed: npm leaves it out when optional dependencies are omitted (--omit=optional, --no-optional) or when the install ran on another platform. Install ${o} again without omitting them.` : `${o} carries no kition for ${i}.`, c = t.platform === "win32" ? E : T;
|
|
76
|
+
return {
|
|
77
|
+
ok: !1,
|
|
78
|
+
message: [
|
|
79
|
+
`no kition for this platform (${i}).`,
|
|
80
|
+
u,
|
|
81
|
+
`${o} carries kition for ${v()}.`,
|
|
82
|
+
`Without npm, install kition with ${t.platform === "win32" ? "install.ps1" : "install.sh"}: ${c}`,
|
|
83
|
+
`(https://github.com/KitionAI/kition-sdk/blob/main/docs/sdk/cli.md), or set ${k} to a kition executable.`
|
|
84
|
+
].join(`
|
|
85
|
+
`)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function F(t, n) {
|
|
89
|
+
const o = t.name ?? b, s = t.self;
|
|
90
|
+
if (s.split(/[\\/]/).includes("_npx")) return { via: "npx", command: ["npx", "-y", o], executable: n };
|
|
91
|
+
const a = t.dirname(t.dirname(s)), l = t.dirname(a);
|
|
92
|
+
if (`${t.basename(l)}/${t.basename(a)}` !== o) return null;
|
|
93
|
+
const i = t.dirname(l);
|
|
94
|
+
if (t.basename(i) !== "node_modules") return null;
|
|
95
|
+
const u = t.platform === "win32", c = t.dirname(i), m = u ? [t.join(c, `${p}.cmd`), t.join(i, ".bin", `${p}.cmd`)] : [...t.basename(c) === "lib" ? [t.join(t.dirname(c), "bin", p)] : [], t.join(i, ".bin", p)];
|
|
96
|
+
for (const e of m)
|
|
97
|
+
if (t.isFile(e) && (u || t.realPath(e) === s)) return { via: "npm", command: [e], executable: n };
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
k as B,
|
|
102
|
+
p as K,
|
|
103
|
+
y as L,
|
|
104
|
+
b as P,
|
|
105
|
+
_ as R,
|
|
106
|
+
j as S,
|
|
107
|
+
w as a,
|
|
108
|
+
K as b,
|
|
109
|
+
F as l,
|
|
110
|
+
$ as p,
|
|
111
|
+
B as r,
|
|
112
|
+
v as s,
|
|
113
|
+
O as t
|
|
114
|
+
};
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn as d } from "node:child_process";
|
|
3
|
+
import { fileURLToPath as f } from "node:url";
|
|
4
|
+
import { t as E, r as h, l as u, b as A, L as t, P as I, S } from "./chunks/resolve-qkpPHdnj.js";
|
|
5
|
+
const r = E(f(import.meta.url)), e = h(r);
|
|
6
|
+
e.ok || (process.stderr.write(`kition (npm): ${e.message}
|
|
7
|
+
`), process.exit(1));
|
|
8
|
+
const c = u(r, e.command), n = { ...process.env };
|
|
9
|
+
c ? n[t] = JSON.stringify(c) : delete n[t];
|
|
10
|
+
const a = A(r.name ?? I, n);
|
|
11
|
+
a && (n[S] = a);
|
|
12
|
+
const l = process.platform === "win32" ? ["SIGINT", "SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"], p = (s) => {
|
|
13
|
+
o.exitCode === null && o.signalCode === null && o.kill(s);
|
|
14
|
+
};
|
|
15
|
+
for (const s of l) process.on(s, p);
|
|
16
|
+
const o = d(e.command, process.argv.slice(2), { stdio: "inherit", env: n, windowsHide: !0 });
|
|
17
|
+
o.on("error", (s) => {
|
|
18
|
+
process.stderr.write(`kition (npm): cannot start ${e.command}: ${s.message}
|
|
19
|
+
`), process.exit(s.code === "ENOENT" ? 127 : 126);
|
|
20
|
+
});
|
|
21
|
+
o.on("exit", (s, i) => {
|
|
22
|
+
for (const m of l) process.off(m, p);
|
|
23
|
+
if (i) {
|
|
24
|
+
process.kill(process.pid, i);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
process.exit(s ?? 1);
|
|
28
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@kition/cli` on npm: the `kition` command, a launcher that starts Kition's command line for this
|
|
3
|
+
* platform (from the optional package `@kition/cli-<platform>`). This module is how it finds
|
|
4
|
+
* kition, for programs that start kition themselves.
|
|
5
|
+
*/
|
|
6
|
+
export { BINARY_VARIABLE, KITION_NAME, LAUNCHER_VARIABLE, PACKAGE_NAME, PLATFORMS, REAL_SCOPE, SCOPE_VARIABLE, launchedAs, launcherScope, platformPackage, resolveKition, supportedPlatforms } from './resolve.js';
|
|
7
|
+
export type { Launched, Machine, Platform, Resolved } from './resolve.js';
|
|
8
|
+
export { thisMachine } from './machine.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { B as A, K as E, L as e, P as o, a as r, R, S as t, l as L, b as P, p as l, r as p, s as I, t as _ } from "./chunks/resolve-qkpPHdnj.js";
|
|
2
|
+
export {
|
|
3
|
+
A as BINARY_VARIABLE,
|
|
4
|
+
E as KITION_NAME,
|
|
5
|
+
e as LAUNCHER_VARIABLE,
|
|
6
|
+
o as PACKAGE_NAME,
|
|
7
|
+
r as PLATFORMS,
|
|
8
|
+
R as REAL_SCOPE,
|
|
9
|
+
t as SCOPE_VARIABLE,
|
|
10
|
+
L as launchedAs,
|
|
11
|
+
P as launcherScope,
|
|
12
|
+
l as platformPackage,
|
|
13
|
+
p as resolveKition,
|
|
14
|
+
I as supportedPlatforms,
|
|
15
|
+
_ as thisMachine
|
|
16
|
+
};
|
package/dist/install.ps1
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Installs `kition`, the Kition command line, on Windows, from npm without Node.js: the package
|
|
2
|
+
# @kition/cli-win32-x64 (the executable that `npm install -g @kition/cli` brings), from the first npm
|
|
3
|
+
# registry that serves it, checked against the integrity (SHA-512) the registry's metadata gives, as
|
|
4
|
+
# %USERPROFILE%\.kition\bin\kition.exe. Kits are not installed here: `kition` downloads each one when
|
|
5
|
+
# it is first needed, or with `kition kit install <kit>`.
|
|
6
|
+
#
|
|
7
|
+
# irm https://unpkg.com/@kition/cli/dist/install.ps1 | iex
|
|
8
|
+
# & ([scriptblock]::Create((irm https://unpkg.com/@kition/cli/dist/install.ps1))) 0.6.0 # a given version
|
|
9
|
+
#
|
|
10
|
+
# The registries, in order (as kition itself reads them, docs/sdk/cli.md):
|
|
11
|
+
# KITION_NPM_REGISTRY one address, or several separated by commas
|
|
12
|
+
# npm's own setting `@kition:registry`, else `npm_config_registry`, else `registry`, in the
|
|
13
|
+
# .npmrc that npm_config_userconfig names or %USERPROFILE%\.npmrc (read; npm is not needed)
|
|
14
|
+
# https://registry.npmjs.org/, then https://registry.npmmirror.com/
|
|
15
|
+
# A registry that does not answer, lacks the version, or serves other bytes than its metadata says
|
|
16
|
+
# passes to the next. Proxies: the system's (Internet Options), as PowerShell's.
|
|
17
|
+
#
|
|
18
|
+
# Environment:
|
|
19
|
+
# KITION_HOME the Kition home (default %USERPROFILE%\.kition); kition.exe goes to its bin\
|
|
20
|
+
# KITION_VERSION the version to install, as the argument does (default: the latest)
|
|
21
|
+
#
|
|
22
|
+
# It needs no administrator rights and never changes the PATH: it says how to put kition on it.
|
|
23
|
+
# Windows 10 1803 or later (for tar.exe). See docs/sdk/cli.md in https://github.com/KitionAI/kition-sdk.
|
|
24
|
+
param([string]$Version = $env:KITION_VERSION)
|
|
25
|
+
|
|
26
|
+
$ErrorActionPreference = 'Stop'
|
|
27
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
28
|
+
|
|
29
|
+
# throw, not exit: run through `irm | iex`, exit would close the person's PowerShell window.
|
|
30
|
+
function Fail([string]$Message) {
|
|
31
|
+
throw "kition install: $Message"
|
|
32
|
+
}
|
|
33
|
+
function Say([string]$Message) {
|
|
34
|
+
[Console]::Error.WriteLine("kition install: $Message")
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
$Version = if ($Version) { $Version.TrimStart('v') } else { '' }
|
|
38
|
+
$kitionHome = if ($env:KITION_HOME) { $env:KITION_HOME } else { Join-Path $env:USERPROFILE '.kition' }
|
|
39
|
+
|
|
40
|
+
# The platform, as @kition/cli names its packages. Windows on Arm runs the x64 build (Windows 11 emulates x64).
|
|
41
|
+
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
|
|
42
|
+
switch ($arch) {
|
|
43
|
+
'X64' { $target = 'win32-x64' }
|
|
44
|
+
'Arm64' { $target = 'win32-x64'; Say 'Windows on Arm: installing the x64 build, which Windows 11 runs by emulation.' }
|
|
45
|
+
default { Fail "kition is built for x64 Windows; not for $arch." }
|
|
46
|
+
}
|
|
47
|
+
if (-not (Get-Command tar.exe -ErrorAction SilentlyContinue)) { Fail 'tar.exe is missing (Windows 10 1803 or later has it).' }
|
|
48
|
+
$package = "@kition/cli-$target"
|
|
49
|
+
|
|
50
|
+
# setting <key> <file>: the value of `key=value` in an .npmrc, quotes taken off, ${VAR} expanded; '' without one.
|
|
51
|
+
function Setting([string]$Key, [string]$File) {
|
|
52
|
+
if (-not (Test-Path $File -PathType Leaf)) { return '' }
|
|
53
|
+
foreach ($line in Get-Content $File) {
|
|
54
|
+
$text = $line.Trim()
|
|
55
|
+
if (-not $text -or $text.StartsWith('#') -or $text.StartsWith(';')) { continue }
|
|
56
|
+
$at = $text.IndexOf('=')
|
|
57
|
+
if ($at -lt 1 -or $text.Substring(0, $at).Trim() -ne $Key) { continue }
|
|
58
|
+
$value = $text.Substring($at + 1).Trim().Trim('"').Trim("'")
|
|
59
|
+
return [regex]::Replace($value, '\$\{([^}]+)\}', { param($m) [Environment]::GetEnvironmentVariable($m.Groups[1].Value) })
|
|
60
|
+
}
|
|
61
|
+
return ''
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# The registries, in order, each once and ending with /.
|
|
65
|
+
$npmrc = if ($env:npm_config_userconfig) { $env:npm_config_userconfig } else { Join-Path $env:USERPROFILE '.npmrc' }
|
|
66
|
+
$general = if ($env:npm_config_registry) { $env:npm_config_registry } else { Setting 'registry' $npmrc }
|
|
67
|
+
$registries = New-Object System.Collections.Generic.List[string]
|
|
68
|
+
foreach ($candidate in @((("$env:KITION_NPM_REGISTRY") -split ',') + @((Setting '@kition:registry' $npmrc), $general, 'https://registry.npmjs.org/', 'https://registry.npmmirror.com/'))) {
|
|
69
|
+
$address = "$candidate".Trim()
|
|
70
|
+
if ($address -notmatch '^https?://') { continue }
|
|
71
|
+
$address = $address.TrimEnd('/') + '/'
|
|
72
|
+
if (-not $registries.Contains($address)) { $registries.Add($address) }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
|
76
|
+
|
|
77
|
+
$tmp = Join-Path $kitionHome 'tmp'
|
|
78
|
+
New-Item -ItemType Directory -Force -Path $tmp | Out-Null
|
|
79
|
+
$work = Join-Path $tmp ("install." + [Guid]::NewGuid().ToString('N').Substring(0, 8))
|
|
80
|
+
New-Item -ItemType Directory -Path $work | Out-Null
|
|
81
|
+
try {
|
|
82
|
+
$tried = @()
|
|
83
|
+
$from = $null
|
|
84
|
+
$file = Join-Path $work 'package.tgz'
|
|
85
|
+
$wanted = if ($Version) { $Version } else { 'latest' }
|
|
86
|
+
foreach ($registry in $registries) {
|
|
87
|
+
# The version's metadata: its version and npm's integrity of its tarball.
|
|
88
|
+
try {
|
|
89
|
+
$metadata = Invoke-RestMethod -Uri "$registry@kition%2fcli-$target/$wanted" -UseBasicParsing -TimeoutSec 30
|
|
90
|
+
} catch {
|
|
91
|
+
$tried += "${registry}: no $package@$wanted there, or no answer ($($_.Exception.Message))"
|
|
92
|
+
continue
|
|
93
|
+
}
|
|
94
|
+
$found = "$($metadata.version)"
|
|
95
|
+
$expected = "$($metadata.dist.integrity)"
|
|
96
|
+
if (-not $found -or $expected -notmatch '^sha512-[A-Za-z0-9+/]+={0,2}$') {
|
|
97
|
+
$tried += "${registry}: its metadata of $package names no version and sha512 integrity"
|
|
98
|
+
continue
|
|
99
|
+
}
|
|
100
|
+
if ($Version -and $found -ne $Version) {
|
|
101
|
+
$tried += "${registry}: it offers $package $found, not $Version"
|
|
102
|
+
continue
|
|
103
|
+
}
|
|
104
|
+
$tarball = "$registry@kition/cli-$target/-/cli-$target-$found.tgz"
|
|
105
|
+
try {
|
|
106
|
+
Invoke-WebRequest -Uri $tarball -OutFile $file -UseBasicParsing -TimeoutSec 600
|
|
107
|
+
} catch {
|
|
108
|
+
$tried += "${registry}: $tarball cannot be downloaded ($($_.Exception.Message))"
|
|
109
|
+
continue
|
|
110
|
+
}
|
|
111
|
+
$sha512 = [System.Security.Cryptography.SHA512]::Create()
|
|
112
|
+
$stream = [System.IO.File]::OpenRead($file)
|
|
113
|
+
try { $actual = 'sha512-' + [Convert]::ToBase64String($sha512.ComputeHash($stream)) } finally { $stream.Dispose(); $sha512.Dispose() }
|
|
114
|
+
if ($actual -cne $expected) {
|
|
115
|
+
$tried += "${registry}: $package $found has the integrity $actual, and its metadata gives ${expected}: refused"
|
|
116
|
+
continue
|
|
117
|
+
}
|
|
118
|
+
$from = $registry
|
|
119
|
+
break
|
|
120
|
+
}
|
|
121
|
+
if (-not $from) {
|
|
122
|
+
$what = if ($Version) { "$package $Version" } else { $package }
|
|
123
|
+
Fail "kition was not installed: no registry served $what with the integrity it gives (tried $($tried -join '; ')). Name a registry that answers with KITION_NPM_REGISTRY (such as https://registry.npmmirror.com/)."
|
|
124
|
+
}
|
|
125
|
+
$archive = "$package $found"
|
|
126
|
+
|
|
127
|
+
$unpacked = Join-Path $work 'unpacked'
|
|
128
|
+
New-Item -ItemType Directory -Path $unpacked | Out-Null
|
|
129
|
+
& tar.exe -xzf $file -C $unpacked
|
|
130
|
+
if ($LASTEXITCODE -ne 0) { Fail "cannot unpack $archive" }
|
|
131
|
+
$exe = Join-Path $unpacked 'package\bin\kition.exe'
|
|
132
|
+
if (-not (Test-Path $exe -PathType Leaf)) { Fail "$archive holds no bin\kition.exe" }
|
|
133
|
+
$ran = & $exe --version 2>&1
|
|
134
|
+
if ($LASTEXITCODE -ne 0) { Fail "the kition.exe in $archive does not run on this machine: $ran" }
|
|
135
|
+
|
|
136
|
+
$bin = Join-Path $kitionHome 'bin'
|
|
137
|
+
New-Item -ItemType Directory -Force -Path $bin | Out-Null
|
|
138
|
+
$installed = Join-Path $bin 'kition.exe'
|
|
139
|
+
try { Move-Item -Force -Path $exe -Destination $installed } catch { Fail "cannot write ${installed} (is kition running? close it and try again): $($_.Exception.Message)" }
|
|
140
|
+
Say "installed $(& $installed --version) as $installed (from $from)"
|
|
141
|
+
|
|
142
|
+
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
|
|
143
|
+
$onPath = (($env:Path -split ';') + ($userPath -split ';')) | Where-Object { $_ -and ($_.TrimEnd('\') -ieq $bin.TrimEnd('\')) }
|
|
144
|
+
if (-not $onPath) {
|
|
145
|
+
Say "$bin is not on your PATH. To use kition from any new terminal, run:"
|
|
146
|
+
[Console]::Error.WriteLine("")
|
|
147
|
+
[Console]::Error.WriteLine(" [Environment]::SetEnvironmentVariable('Path', `"$bin;`" + [Environment]::GetEnvironmentVariable('Path', 'User'), 'User')")
|
|
148
|
+
[Console]::Error.WriteLine("")
|
|
149
|
+
Say "or run it as $installed"
|
|
150
|
+
}
|
|
151
|
+
Say 'next: kition kit list; connect an agent with: kition mcp --workspace <folder> (docs/sdk/cli.md)'
|
|
152
|
+
} finally {
|
|
153
|
+
Remove-Item -Recurse -Force -Path $work -ErrorAction SilentlyContinue
|
|
154
|
+
}
|
package/dist/install.sh
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Installs `kition`, the Kition command line, on macOS or Linux, from npm without Node.js: the
|
|
3
|
+
# package @kition/cli-<platform> (the executable that `npm install -g @kition/cli` brings), from the
|
|
4
|
+
# first npm registry that serves it, checked against the integrity (SHA-512) the registry's
|
|
5
|
+
# metadata gives, as ~/.kition/bin/kition. Kits are not installed here: `kition` downloads each one
|
|
6
|
+
# when it is first needed, or with `kition kit install <kit>`.
|
|
7
|
+
#
|
|
8
|
+
# curl -fsSL https://unpkg.com/@kition/cli/dist/install.sh | sh
|
|
9
|
+
# curl -fsSL https://unpkg.com/@kition/cli/dist/install.sh | sh -s -- 0.6.0 # a given version
|
|
10
|
+
# It rides in the npm package @kition/cli (dist/install.sh), so any registry or mirror serves it:
|
|
11
|
+
# curl -fsSL https://registry.npmmirror.com/@kition/cli/-/cli-0.6.0.tgz | tar -xzO package/dist/install.sh | sh
|
|
12
|
+
#
|
|
13
|
+
# The registries, in order (as kition itself reads them, docs/sdk/cli.md):
|
|
14
|
+
# KITION_NPM_REGISTRY one address, or several separated by commas
|
|
15
|
+
# npm's own setting `@kition:registry`, else `npm_config_registry`, else `registry`, in the
|
|
16
|
+
# .npmrc that npm_config_userconfig names or ~/.npmrc (read; npm is not needed)
|
|
17
|
+
# https://registry.npmjs.org/, then https://registry.npmmirror.com/
|
|
18
|
+
# A registry that does not answer within 5 seconds, lacks the version, or serves other bytes than
|
|
19
|
+
# its metadata says passes to the next. Proxies: curl's (https_proxy, ...).
|
|
20
|
+
#
|
|
21
|
+
# Environment:
|
|
22
|
+
# KITION_HOME the Kition home (default ~/.kition); kition goes to $KITION_HOME/bin
|
|
23
|
+
# KITION_VERSION the version to install, as the argument does (default: the latest)
|
|
24
|
+
#
|
|
25
|
+
# It never uses sudo and never edits a shell profile: it says how to put kition on the PATH.
|
|
26
|
+
# See docs/sdk/cli.md in https://github.com/KitionAI/kition-sdk.
|
|
27
|
+
set -eu
|
|
28
|
+
|
|
29
|
+
version="${1:-${KITION_VERSION:-}}"
|
|
30
|
+
version="${version#v}"
|
|
31
|
+
home="${KITION_HOME:-${HOME:?HOME is not set; set KITION_HOME}/.kition}"
|
|
32
|
+
|
|
33
|
+
say() { printf 'kition install: %s\n' "$*" >&2; }
|
|
34
|
+
fail() {
|
|
35
|
+
say "$*"
|
|
36
|
+
exit 1
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# The platform of this machine, as @kition/cli names its packages.
|
|
40
|
+
platform() {
|
|
41
|
+
os=$(uname -s)
|
|
42
|
+
arch=$(uname -m)
|
|
43
|
+
case "$os" in
|
|
44
|
+
Darwin)
|
|
45
|
+
os=darwin
|
|
46
|
+
# A shell running under Rosetta says x86_64 on Apple silicon: take the native build.
|
|
47
|
+
if [ "$arch" = x86_64 ] && [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || true)" = 1 ]; then
|
|
48
|
+
arch=arm64
|
|
49
|
+
fi
|
|
50
|
+
;;
|
|
51
|
+
Linux)
|
|
52
|
+
os=linux
|
|
53
|
+
if [ -n "$(ls /lib/ld-musl-* /usr/lib/ld-musl-* 2>/dev/null || true)" ] || ldd --version 2>&1 | grep -qi musl; then
|
|
54
|
+
fail "this Linux uses the musl C library (Alpine, for example); kition is built for glibc 2.17 or later only. Use a glibc distribution (Debian, Ubuntu, Fedora, ...) or a glibc container image, or build kition from source: cargo build --release -p kition-cli in https://github.com/KitionAI/kition-sdk."
|
|
55
|
+
fi
|
|
56
|
+
;;
|
|
57
|
+
MINGW* | MSYS* | CYGWIN* | Windows_NT)
|
|
58
|
+
fail "on Windows, run install.ps1 in PowerShell instead (docs/sdk/cli.md)"
|
|
59
|
+
;;
|
|
60
|
+
*) fail "kition is built for macOS, Linux (glibc) and Windows; not for $os." ;;
|
|
61
|
+
esac
|
|
62
|
+
case "$arch" in
|
|
63
|
+
arm64 | aarch64) arch=arm64 ;;
|
|
64
|
+
x86_64 | amd64) arch=x64 ;;
|
|
65
|
+
*) fail "kition is built for arm64 and x64; not for $arch ($os)." ;;
|
|
66
|
+
esac
|
|
67
|
+
echo "$os-$arch"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
# fetch <url> <file>: downloads, quietly; fails (status 1) without a word.
|
|
71
|
+
fetch() {
|
|
72
|
+
if command -v curl >/dev/null 2>&1; then
|
|
73
|
+
curl -fsSL --connect-timeout 5 --retry 1 -o "$2" "$1" 2>/dev/null
|
|
74
|
+
elif command -v wget >/dev/null 2>&1; then
|
|
75
|
+
wget -q -T 30 -O "$2" "$1"
|
|
76
|
+
else
|
|
77
|
+
fail "neither curl nor wget is installed; install one of them"
|
|
78
|
+
fi
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# integrity <file>: npm's integrity of it, sha512-<base64>.
|
|
82
|
+
integrity() {
|
|
83
|
+
if command -v openssl >/dev/null 2>&1; then
|
|
84
|
+
printf 'sha512-%s' "$(openssl dgst -sha512 -binary "$1" | openssl base64 -A)"
|
|
85
|
+
elif command -v xxd >/dev/null 2>&1 && command -v base64 >/dev/null 2>&1; then
|
|
86
|
+
if command -v sha512sum >/dev/null 2>&1; then hex=$(sha512sum "$1" | cut -d ' ' -f 1); else hex=$(shasum -a 512 "$1" | cut -d ' ' -f 1); fi
|
|
87
|
+
printf 'sha512-%s' "$(printf '%s' "$hex" | xxd -r -p | base64 | tr -d '\n')"
|
|
88
|
+
else
|
|
89
|
+
fail "neither openssl nor xxd and base64 are installed; cannot check the download"
|
|
90
|
+
fi
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# setting <key> <file>: the value of `key=value` in an .npmrc, quotes taken off; empty without one.
|
|
94
|
+
setting() {
|
|
95
|
+
[ -f "$2" ] || return 0
|
|
96
|
+
sed -n "s/^[[:space:]]*$1[[:space:]]*=[[:space:]]*//p" "$2" | head -n 1 | sed "s/^[\"']//; s/[\"'][[:space:]]*\$//; s/[[:space:]]*\$//"
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# The registries, in order, each once and ending with /.
|
|
100
|
+
registries() {
|
|
101
|
+
npmrc="${npm_config_userconfig:-${NPM_CONFIG_USERCONFIG:-$HOME/.npmrc}}"
|
|
102
|
+
general="${npm_config_registry:-${NPM_CONFIG_REGISTRY:-$(setting registry "$npmrc")}}"
|
|
103
|
+
printf '%s\n' "$(printf '%s' "${KITION_NPM_REGISTRY:-}" | tr ',' '\n')" "$(setting @kition:registry "$npmrc")" "$general" https://registry.npmjs.org/ https://registry.npmmirror.com/ |
|
|
104
|
+
sed 's/^[[:space:]]*//; s/[[:space:]]*$//' | grep -E '^https?://' | sed 's#/*$#/#' | awk '!seen[$0]++'
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
target=$(platform) || exit 1
|
|
108
|
+
package="@kition/cli-$target"
|
|
109
|
+
mkdir -p "$home/tmp" || fail "cannot create $home/tmp"
|
|
110
|
+
work=$(mktemp -d "$home/tmp/install.XXXXXX") || fail "cannot create a folder in $home/tmp"
|
|
111
|
+
trap 'rm -rf "$work"' EXIT
|
|
112
|
+
trap 'exit 130' INT TERM
|
|
113
|
+
|
|
114
|
+
tried=""
|
|
115
|
+
installed_from=""
|
|
116
|
+
for registry in $(registries); do
|
|
117
|
+
# The version's metadata: its version and npm's integrity of its tarball.
|
|
118
|
+
if ! fetch "$registry@kition%2fcli-$target/${version:-latest}" "$work/metadata.json"; then
|
|
119
|
+
tried="$tried; $registry: no $package@${version:-latest} there, or no answer"
|
|
120
|
+
continue
|
|
121
|
+
fi
|
|
122
|
+
found=$(tr -d '\n' < "$work/metadata.json" | sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1)
|
|
123
|
+
expected=$(tr -d '\n' < "$work/metadata.json" | sed -n 's/.*"integrity"[[:space:]]*:[[:space:]]*"\(sha512-[A-Za-z0-9+/=]*\)".*/\1/p' | head -n 1)
|
|
124
|
+
if [ -z "$found" ] || [ -z "$expected" ]; then
|
|
125
|
+
tried="$tried; $registry: its metadata of $package names no version and sha512 integrity"
|
|
126
|
+
continue
|
|
127
|
+
fi
|
|
128
|
+
if [ -n "$version" ] && [ "$found" != "$version" ]; then
|
|
129
|
+
tried="$tried; $registry: it offers $package $found, not $version"
|
|
130
|
+
continue
|
|
131
|
+
fi
|
|
132
|
+
tarball="$registry@kition/cli-$target/-/cli-$target-$found.tgz"
|
|
133
|
+
if ! fetch "$tarball" "$work/package.tgz"; then
|
|
134
|
+
tried="$tried; $registry: $tarball cannot be downloaded"
|
|
135
|
+
continue
|
|
136
|
+
fi
|
|
137
|
+
actual=$(integrity "$work/package.tgz")
|
|
138
|
+
if [ "$actual" != "$expected" ]; then
|
|
139
|
+
tried="$tried; $registry: $package $found has the integrity $actual, and its metadata gives $expected: refused"
|
|
140
|
+
continue
|
|
141
|
+
fi
|
|
142
|
+
installed_from="$registry"
|
|
143
|
+
break
|
|
144
|
+
done
|
|
145
|
+
[ -n "$installed_from" ] || fail "kition was not installed: no registry served $package${version:+ $version} with the integrity it gives (tried${tried#;}). Name a registry that answers with KITION_NPM_REGISTRY (such as https://registry.npmmirror.com/)."
|
|
146
|
+
|
|
147
|
+
mkdir -p "$work/unpacked"
|
|
148
|
+
tar -xzf "$work/package.tgz" -C "$work/unpacked" || fail "cannot unpack $package $found"
|
|
149
|
+
[ -f "$work/unpacked/package/bin/kition" ] || fail "$package $found holds no bin/kition"
|
|
150
|
+
chmod 755 "$work/unpacked/package/bin/kition"
|
|
151
|
+
ran=$("$work/unpacked/package/bin/kition" --version 2>&1) || fail "the kition of $package $found does not run on this machine ($target): $ran"
|
|
152
|
+
|
|
153
|
+
mkdir -p "$home/bin" || fail "cannot create $home/bin"
|
|
154
|
+
# Moved into place with one rename, so a kition running now keeps its file.
|
|
155
|
+
mv -f "$work/unpacked/package/bin/kition" "$home/bin/kition" || fail "cannot write $home/bin/kition"
|
|
156
|
+
say "installed $("$home/bin/kition" --version) as $home/bin/kition (from $installed_from)"
|
|
157
|
+
|
|
158
|
+
case ":${PATH:-}:" in
|
|
159
|
+
*":$home/bin:"*) ;;
|
|
160
|
+
*)
|
|
161
|
+
say "$home/bin is not on your PATH. To use kition from any shell, add this line to your shell's profile (~/.zshrc, ~/.bashrc, ~/.profile, ...):"
|
|
162
|
+
printf '\n export PATH="%s/bin:$PATH"\n\n' "$home" >&2
|
|
163
|
+
say "for fish: fish_add_path $home/bin"
|
|
164
|
+
say "or run it as $home/bin/kition"
|
|
165
|
+
;;
|
|
166
|
+
esac
|
|
167
|
+
say "next: kition kit list; connect an agent with: kition mcp --workspace <folder> (docs/sdk/cli.md)"
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** The npm package, and the command it installs (sdk.json `binaries.cli.npm` and `name`). */
|
|
2
|
+
export declare const PACKAGE_NAME = "@kition/cli";
|
|
3
|
+
/** The scope of the real packages, whose kits kition installs when `KITION_NPM_SCOPE` is not set. */
|
|
4
|
+
export declare const REAL_SCOPE = "@kition";
|
|
5
|
+
/** The npm scope kition installs kits from (kition's `registry.rs`). */
|
|
6
|
+
export declare const SCOPE_VARIABLE = "KITION_NPM_SCOPE";
|
|
7
|
+
export declare const KITION_NAME = "kition";
|
|
8
|
+
/** The environment variable naming the executable to start instead (sdk.json `binaries.cli.binary`). */
|
|
9
|
+
export declare const BINARY_VARIABLE = "KITION_BINARY";
|
|
10
|
+
/** Set by the launcher for kition: how it was started (sdk.json `binaries.cli.launcher`). */
|
|
11
|
+
export declare const LAUNCHER_VARIABLE = "KITION_LAUNCHER";
|
|
12
|
+
export interface Platform {
|
|
13
|
+
os: string;
|
|
14
|
+
cpu: string;
|
|
15
|
+
libc?: string;
|
|
16
|
+
rustTarget: string;
|
|
17
|
+
}
|
|
18
|
+
/** The platforms a package carries kition for, by `${process.platform}-${process.arch}`. */
|
|
19
|
+
export declare const PLATFORMS: Readonly<Record<string, Platform>>;
|
|
20
|
+
/**
|
|
21
|
+
* The optional package that carries kition for `platform`: `<launcher>-<platform>`, beside the
|
|
22
|
+
* launcher `name` (`@kition/cli-darwin-arm64`; a rehearsal's `@kitionstage/cli-darwin-arm64`).
|
|
23
|
+
*/
|
|
24
|
+
export declare const platformPackage: (platform: string, name?: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* The scope kition is to install kits from when this launcher is published under another scope
|
|
27
|
+
* than the real one (a rehearsal, `@kitionstage/cli`) and `KITION_NPM_SCOPE` is not set: that
|
|
28
|
+
* scope, so the staged kition reads the staged kit index and kits. Null otherwise.
|
|
29
|
+
*/
|
|
30
|
+
export declare function launcherScope(name: string, env: Record<string, string | undefined>): string | null;
|
|
31
|
+
export interface Machine {
|
|
32
|
+
/** The npm package this launcher is installed as (its package.json's name); `PACKAGE_NAME` when unknown. */
|
|
33
|
+
name?: string;
|
|
34
|
+
env: Record<string, string | undefined>;
|
|
35
|
+
/** `process.platform` */
|
|
36
|
+
platform: string;
|
|
37
|
+
/** `process.arch` */
|
|
38
|
+
arch: string;
|
|
39
|
+
/** Linux only: false on a C library other than glibc (musl). */
|
|
40
|
+
glibc?: boolean;
|
|
41
|
+
/** The folder of an installed package, or null. */
|
|
42
|
+
packageDir(name: string): string | null;
|
|
43
|
+
isFile(path: string): boolean;
|
|
44
|
+
/** The real path of a file (symbolic links followed); the path itself when it has none. */
|
|
45
|
+
realPath(path: string): string;
|
|
46
|
+
/** This launcher's own file, its real path (`<package>/dist/cli.js`). */
|
|
47
|
+
self: string;
|
|
48
|
+
join(...parts: string[]): string;
|
|
49
|
+
dirname(path: string): string;
|
|
50
|
+
basename(path: string): string;
|
|
51
|
+
}
|
|
52
|
+
export type Resolved = {
|
|
53
|
+
ok: true;
|
|
54
|
+
command: string;
|
|
55
|
+
from: 'env' | 'package';
|
|
56
|
+
} | {
|
|
57
|
+
ok: false;
|
|
58
|
+
message: string;
|
|
59
|
+
};
|
|
60
|
+
export declare function supportedPlatforms(): string;
|
|
61
|
+
export declare function resolveKition(machine: Machine): Resolved;
|
|
62
|
+
/** How the launcher was started, as kition reads it from `KITION_LAUNCHER` (JSON). */
|
|
63
|
+
export interface Launched {
|
|
64
|
+
/** `npx`: from npx's cache; `npm`: npm's `kition` command, global or a project's. */
|
|
65
|
+
via: 'npx' | 'npm';
|
|
66
|
+
/** The command that starts this kition again, kition's arguments to follow. */
|
|
67
|
+
command: string[];
|
|
68
|
+
/** The executable the launcher started: kition takes the rest as its own only when it is that one. */
|
|
69
|
+
executable: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* How this launcher runs, and the command that starts it again; null when neither npx nor an npm
|
|
73
|
+
* command of its own is to be seen (kition then registers its own path).
|
|
74
|
+
*
|
|
75
|
+
* - npx runs packages from its cache, `<npm cache>/_npx/<hash>/node_modules/@kition/cli`.
|
|
76
|
+
* The package is `machine.name` (a rehearsal's `@kitionstage/cli`), `PACKAGE_NAME` by default.
|
|
77
|
+
* - npm's `kition` command: global, `<prefix>/bin/kition` (a link to this file) on macOS and
|
|
78
|
+
* Linux, `<prefix>\kition.cmd` on Windows, beside `<prefix>\node_modules`; a project's,
|
|
79
|
+
* `node_modules/.bin/kition` (`kition.cmd` on Windows). This file is
|
|
80
|
+
* `<modules>/@kition/cli/dist/cli.js` in both.
|
|
81
|
+
*/
|
|
82
|
+
export declare function launchedAs(machine: Machine, executable: string): Launched | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitionstage/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.2-stage.1",
|
|
4
|
+
"description": "Kition's command line from npm: `npm install -g @kition/cli` gives the `kition` command, and `npx -y @kition/cli mcp --workspace <folder>` serves the kits' tools to any agent over MCP. It downloads each published kit on first use.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"kition": "./dist/cli.js"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/KitionAI/kition-sdk.git",
|
|
25
|
+
"directory": "packages/kition"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/KitionAI/kition-sdk/tree/main/packages/kition#readme",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/KitionAI/kition-sdk/issues"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"kition",
|
|
33
|
+
"cli",
|
|
34
|
+
"mcp",
|
|
35
|
+
"model-context-protocol",
|
|
36
|
+
"khp",
|
|
37
|
+
"agent",
|
|
38
|
+
"markdown"
|
|
39
|
+
],
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"main": "./dist/index.js",
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "node ../../tools/build-package.mjs"
|
|
47
|
+
},
|
|
48
|
+
"optionalDependencies": {
|
|
49
|
+
"@kitionstage/cli-darwin-arm64": "0.5.2-stage.1"
|
|
50
|
+
}
|
|
51
|
+
}
|