@hyperxenonzephyr/kv-code 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +114 -0
- package/bin/kv-code.js +194 -0
- package/package.json +49 -0
- package/scripts/README.md +23 -0
- package/scripts/postinstall.js +267 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 OpenAI
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# KV Code
|
|
2
|
+
|
|
3
|
+
KV Code is a local-first coding agent for terminal workflows, repository
|
|
4
|
+
maintenance, review, and controlled command execution.
|
|
5
|
+
|
|
6
|
+
This project is based on OpenAI Codex and has been heavily modified into KV
|
|
7
|
+
Code. It is not presented as an original-from-zero codebase or a simple mirror:
|
|
8
|
+
the public command, package metadata, configuration home, documentation, and
|
|
9
|
+
repository target have been changed for KV Code. Some internal compatibility
|
|
10
|
+
names may remain where changing them would break upstream crate wiring, but the
|
|
11
|
+
product identity is KV Code.
|
|
12
|
+
|
|
13
|
+
## Quickstart
|
|
14
|
+
|
|
15
|
+
Install the npm launcher:
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
npm install -g @hyperxenonzephyr/kv-code
|
|
19
|
+
kv-code --help
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Build the CLI from source:
|
|
23
|
+
|
|
24
|
+
```shell
|
|
25
|
+
cd kv-code-rs
|
|
26
|
+
cargo build -p kv-code-cli --bin kv-code
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Run it locally:
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
cargo run -p kv-code-cli --bin kv-code -- --help
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The preferred command is:
|
|
36
|
+
|
|
37
|
+
```shell
|
|
38
|
+
kv-code
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Practical Additions
|
|
42
|
+
|
|
43
|
+
KV Code adds a workspace snapshot command for fast handoff and debugging:
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
kv-code workspace
|
|
47
|
+
kv-code workspace --json
|
|
48
|
+
kv-code workspace --brief --top 6
|
|
49
|
+
kv-code workspace D:\work\project --top 20 --max-files 50000
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
It reports the inspected path, KV Code home, Git branch, working tree change
|
|
53
|
+
counts, file counts, skipped heavy directories, total size, and top file types.
|
|
54
|
+
Use `--brief` for low-token model handoffs, `--top` to cap file-type output,
|
|
55
|
+
and `--json` when feeding the snapshot to scripts or other tools.
|
|
56
|
+
|
|
57
|
+
KV Code also includes local utility commands that do not call an AI service:
|
|
58
|
+
|
|
59
|
+
```shell
|
|
60
|
+
kv-code tools hash "hello"
|
|
61
|
+
kv-code tools base64 "hello"
|
|
62
|
+
kv-code tools url "a value with spaces"
|
|
63
|
+
kv-code tools json --file package.json
|
|
64
|
+
kv-code tools json --summary --file package.json
|
|
65
|
+
kv-code tools uuid -n 3
|
|
66
|
+
kv-code tools time --utc
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Model Providers
|
|
70
|
+
|
|
71
|
+
KV Code can be configured for OpenAI and OpenAI-compatible Responses API
|
|
72
|
+
providers. Use the provider helper to print templates for common services:
|
|
73
|
+
|
|
74
|
+
```shell
|
|
75
|
+
kv-code providers list
|
|
76
|
+
kv-code providers show openai
|
|
77
|
+
kv-code providers show azure-openai
|
|
78
|
+
kv-code providers show openrouter
|
|
79
|
+
kv-code providers show anthropic
|
|
80
|
+
kv-code providers show gemini
|
|
81
|
+
kv-code providers show groq
|
|
82
|
+
kv-code providers show deepseek
|
|
83
|
+
kv-code providers show xai
|
|
84
|
+
kv-code providers show ollama
|
|
85
|
+
kv-code providers show lmstudio
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Copy the generated TOML into `~/.kv-code/config.toml` and set the referenced
|
|
89
|
+
API key environment variable. Some vendors expose OpenAI-compatible model
|
|
90
|
+
endpoints through a gateway; use a Responses-compatible endpoint when the
|
|
91
|
+
vendor's native API is not directly compatible.
|
|
92
|
+
|
|
93
|
+
## Configuration
|
|
94
|
+
|
|
95
|
+
KV Code resolves its home directory in this order:
|
|
96
|
+
|
|
97
|
+
1. `KV_CODE_HOME`
|
|
98
|
+
2. `CODEX_HOME` for migration compatibility
|
|
99
|
+
3. `~/.kv-code`
|
|
100
|
+
|
|
101
|
+
## Repository
|
|
102
|
+
|
|
103
|
+
The upstream Git history is intentionally not carried into this repository. KV
|
|
104
|
+
Code is published at:
|
|
105
|
+
|
|
106
|
+
```text
|
|
107
|
+
https://github.com/HyperXenonZephyr/Kv-code
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## License And Attribution
|
|
111
|
+
|
|
112
|
+
KV Code is licensed under Apache-2.0. Because it is based on OpenAI Codex, the
|
|
113
|
+
required upstream license and notice information is preserved in [LICENSE](LICENSE)
|
|
114
|
+
and [NOTICE](NOTICE).
|
package/bin/kv-code.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Unified entry point for the KV Code CLI.
|
|
3
|
+
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { existsSync, realpathSync } from "fs";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
9
|
+
|
|
10
|
+
// __dirname equivalent in ESM
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
|
|
15
|
+
const PLATFORM_PACKAGE_BY_TARGET = {
|
|
16
|
+
"x86_64-unknown-linux-musl": "@hyperxenonzephyr/kv-code-linux-x64",
|
|
17
|
+
"aarch64-unknown-linux-musl": "@hyperxenonzephyr/kv-code-linux-arm64",
|
|
18
|
+
"x86_64-apple-darwin": "@hyperxenonzephyr/kv-code-darwin-x64",
|
|
19
|
+
"aarch64-apple-darwin": "@hyperxenonzephyr/kv-code-darwin-arm64",
|
|
20
|
+
"x86_64-pc-windows-msvc": "@hyperxenonzephyr/kv-code-win32-x64",
|
|
21
|
+
"aarch64-pc-windows-msvc": "@hyperxenonzephyr/kv-code-win32-arm64",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const { platform, arch } = process;
|
|
25
|
+
|
|
26
|
+
let targetTriple = null;
|
|
27
|
+
switch (platform) {
|
|
28
|
+
case "linux":
|
|
29
|
+
case "android":
|
|
30
|
+
switch (arch) {
|
|
31
|
+
case "x64":
|
|
32
|
+
targetTriple = "x86_64-unknown-linux-musl";
|
|
33
|
+
break;
|
|
34
|
+
case "arm64":
|
|
35
|
+
targetTriple = "aarch64-unknown-linux-musl";
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case "darwin":
|
|
42
|
+
switch (arch) {
|
|
43
|
+
case "x64":
|
|
44
|
+
targetTriple = "x86_64-apple-darwin";
|
|
45
|
+
break;
|
|
46
|
+
case "arm64":
|
|
47
|
+
targetTriple = "aarch64-apple-darwin";
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case "win32":
|
|
54
|
+
switch (arch) {
|
|
55
|
+
case "x64":
|
|
56
|
+
targetTriple = "x86_64-pc-windows-msvc";
|
|
57
|
+
break;
|
|
58
|
+
case "arm64":
|
|
59
|
+
targetTriple = "aarch64-pc-windows-msvc";
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!targetTriple) {
|
|
70
|
+
throw new Error(`Unsupported platform: ${platform} (${arch})`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
|
|
74
|
+
if (!platformPackage) {
|
|
75
|
+
throw new Error(`Unsupported target triple: ${targetTriple}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function findKvCodeExecutable() {
|
|
79
|
+
let vendorRoot;
|
|
80
|
+
try {
|
|
81
|
+
const packageJsonPath = require.resolve(`${platformPackage}/package.json`);
|
|
82
|
+
vendorRoot = path.join(path.dirname(packageJsonPath), "vendor");
|
|
83
|
+
} catch {
|
|
84
|
+
vendorRoot = path.join(__dirname, "..", "vendor");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const kvCodeExecutable = path.join(
|
|
88
|
+
vendorRoot,
|
|
89
|
+
targetTriple,
|
|
90
|
+
"bin",
|
|
91
|
+
process.platform === "win32" ? "kv-code.exe" : "kv-code",
|
|
92
|
+
);
|
|
93
|
+
if (existsSync(kvCodeExecutable)) {
|
|
94
|
+
return kvCodeExecutable;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const compatibilityExecutable = path.join(
|
|
98
|
+
vendorRoot,
|
|
99
|
+
targetTriple,
|
|
100
|
+
"bin",
|
|
101
|
+
process.platform === "win32" ? "codex.exe" : "codex",
|
|
102
|
+
);
|
|
103
|
+
if (existsSync(compatibilityExecutable)) {
|
|
104
|
+
return compatibilityExecutable;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const packageManager = detectPackageManager();
|
|
108
|
+
const updateCommand =
|
|
109
|
+
packageManager === "bun"
|
|
110
|
+
? "bun install -g @hyperxenonzephyr/kv-code@latest"
|
|
111
|
+
: "npm install -g @hyperxenonzephyr/kv-code@latest";
|
|
112
|
+
throw new Error(
|
|
113
|
+
`Missing optional dependency ${platformPackage}. Reinstall KV Code: ${updateCommand}`,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const binaryPath = findKvCodeExecutable();
|
|
118
|
+
|
|
119
|
+
// Use an asynchronous spawn instead of spawnSync so Node can forward Ctrl-C
|
|
120
|
+
// and other termination signals while the native binary is running.
|
|
121
|
+
function detectPackageManager() {
|
|
122
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
123
|
+
if (/\bbun\//.test(userAgent)) {
|
|
124
|
+
return "bun";
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const execPath = process.env.npm_execpath || "";
|
|
128
|
+
if (execPath.includes("bun")) {
|
|
129
|
+
return "bun";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (
|
|
133
|
+
__dirname.includes(".bun/install/global") ||
|
|
134
|
+
__dirname.includes(".bun\\install\\global")
|
|
135
|
+
) {
|
|
136
|
+
return "bun";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return userAgent ? "npm" : null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const packageManagerEnvVar =
|
|
143
|
+
detectPackageManager() === "bun"
|
|
144
|
+
? "KV_CODE_MANAGED_BY_BUN"
|
|
145
|
+
: "KV_CODE_MANAGED_BY_NPM";
|
|
146
|
+
const packageRoot = realpathSync(path.join(__dirname, ".."));
|
|
147
|
+
const env = {
|
|
148
|
+
...process.env,
|
|
149
|
+
[packageManagerEnvVar]: "1",
|
|
150
|
+
KV_CODE_MANAGED_PACKAGE_ROOT: packageRoot,
|
|
151
|
+
CODEX_MANAGED_PACKAGE_ROOT: packageRoot,
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
155
|
+
stdio: "inherit",
|
|
156
|
+
env,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
child.on("error", (err) => {
|
|
160
|
+
// eslint-disable-next-line no-console
|
|
161
|
+
console.error(err);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const forwardSignal = (signal) => {
|
|
166
|
+
if (child.killed) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
child.kill(signal);
|
|
171
|
+
} catch {
|
|
172
|
+
/* ignore */
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
|
|
177
|
+
process.on(sig, () => forwardSignal(sig));
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const childResult = await new Promise((resolve) => {
|
|
181
|
+
child.on("exit", (code, signal) => {
|
|
182
|
+
if (signal) {
|
|
183
|
+
resolve({ type: "signal", signal });
|
|
184
|
+
} else {
|
|
185
|
+
resolve({ type: "code", exitCode: code ?? 1 });
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
if (childResult.type === "signal") {
|
|
191
|
+
process.kill(process.pid, childResult.signal);
|
|
192
|
+
} else {
|
|
193
|
+
process.exit(childResult.exitCode);
|
|
194
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hyperxenonzephyr/kv-code",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "KV Code is a local-first coding agent for terminal workflows.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://github.com/HyperXenonZephyr/Kv-code#readme",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/HyperXenonZephyr/Kv-code/issues"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"kv-code",
|
|
12
|
+
"coding-agent",
|
|
13
|
+
"terminal",
|
|
14
|
+
"ai",
|
|
15
|
+
"developer-tools"
|
|
16
|
+
],
|
|
17
|
+
"bin": {
|
|
18
|
+
"kv-code": "bin/kv-code.js"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"postinstall": "node scripts/postinstall.js",
|
|
22
|
+
"build": "python scripts/build_npm_package.py --package kv-code --version $npm_package_version --vendor-src ./vendor --pack-output ./dist/kv-code.tgz",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=16"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"bin/kv-code.js",
|
|
31
|
+
"scripts/postinstall.js",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"optionalDependencies": {
|
|
36
|
+
"@hyperxenonzephyr/kv-code-linux-x64": "0.0.0-dev",
|
|
37
|
+
"@hyperxenonzephyr/kv-code-linux-arm64": "0.0.0-dev",
|
|
38
|
+
"@hyperxenonzephyr/kv-code-darwin-x64": "0.0.0-dev",
|
|
39
|
+
"@hyperxenonzephyr/kv-code-darwin-arm64": "0.0.0-dev",
|
|
40
|
+
"@hyperxenonzephyr/kv-code-win32-x64": "0.0.0-dev",
|
|
41
|
+
"@hyperxenonzephyr/kv-code-win32-arm64": "0.0.0-dev"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/HyperXenonZephyr/Kv-code.git",
|
|
46
|
+
"directory": "kv-code-cli"
|
|
47
|
+
},
|
|
48
|
+
"packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319"
|
|
49
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# npm releases
|
|
2
|
+
|
|
3
|
+
Use the staging helper in the repo root to generate npm tarballs for a release. For
|
|
4
|
+
example, to stage the CLI, responses proxy, and SDK packages for version `0.6.0`:
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
./scripts/stage_npm_packages.py \
|
|
8
|
+
--release-version 0.6.0 \
|
|
9
|
+
--package codex \
|
|
10
|
+
--package codex-responses-api-proxy \
|
|
11
|
+
--package codex-sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
This downloads the required native package archive artifacts, hydrates `vendor/` for
|
|
15
|
+
each package, and writes tarballs to `dist/npm/`.
|
|
16
|
+
|
|
17
|
+
When `--package codex` is provided, the staging helper builds the lightweight
|
|
18
|
+
`@HyperXenonZephyr/Kv-code` meta package plus all platform-native `@HyperXenonZephyr/Kv-code` variants
|
|
19
|
+
that are later published under platform-specific dist-tags.
|
|
20
|
+
|
|
21
|
+
Direct `build_npm_package.py` invocations are still useful for package-specific
|
|
22
|
+
debugging, but native packages expect `--vendor-src` to point at a prehydrated
|
|
23
|
+
`vendor/` tree. Release packaging should use `scripts/stage_npm_packages.py`.
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { existsSync, mkdirSync } from "fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import { execSync } from "child_process";
|
|
8
|
+
import https from "https";
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
|
|
14
|
+
const GITHUB_REPO = "HyperXenonZephyr/Kv-code";
|
|
15
|
+
|
|
16
|
+
const TARGET_BY_PLATFORM_ARCH = {
|
|
17
|
+
"win32-x64": "x86_64-pc-windows-msvc",
|
|
18
|
+
"win32-arm64": "aarch64-pc-windows-msvc",
|
|
19
|
+
"darwin-x64": "x86_64-apple-darwin",
|
|
20
|
+
"darwin-arm64": "aarch64-apple-darwin",
|
|
21
|
+
"linux-x64": "x86_64-unknown-linux-musl",
|
|
22
|
+
"linux-arm64": "aarch64-unknown-linux-musl",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const PLATFORM_PACKAGE_BY_TARGET = {
|
|
26
|
+
"x86_64-unknown-linux-musl": "@hyperxenonzephyr/kv-code-linux-x64",
|
|
27
|
+
"aarch64-unknown-linux-musl": "@hyperxenonzephyr/kv-code-linux-arm64",
|
|
28
|
+
"x86_64-apple-darwin": "@hyperxenonzephyr/kv-code-darwin-x64",
|
|
29
|
+
"aarch64-apple-darwin": "@hyperxenonzephyr/kv-code-darwin-arm64",
|
|
30
|
+
"x86_64-pc-windows-msvc": "@hyperxenonzephyr/kv-code-win32-x64",
|
|
31
|
+
"aarch64-pc-windows-msvc": "@hyperxenonzephyr/kv-code-win32-arm64",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const { platform, arch } = process;
|
|
35
|
+
const platformKey = `${platform}-${arch}`;
|
|
36
|
+
const targetTriple = TARGET_BY_PLATFORM_ARCH[platformKey];
|
|
37
|
+
|
|
38
|
+
if (!targetTriple) {
|
|
39
|
+
console.error(`[kv-code] Unsupported platform: ${platform} (${arch})`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const packageRoot = path.resolve(__dirname, "..");
|
|
44
|
+
const vendorDir = path.join(packageRoot, "vendor", targetTriple, "bin");
|
|
45
|
+
const binaryName = platform === "win32" ? "kv-code.exe" : "kv-code";
|
|
46
|
+
const binaryPath = path.join(vendorDir, binaryName);
|
|
47
|
+
|
|
48
|
+
function findExistingBinary() {
|
|
49
|
+
if (existsSync(binaryPath)) return binaryPath;
|
|
50
|
+
|
|
51
|
+
// Try platform-specific optional dependency
|
|
52
|
+
const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
|
|
53
|
+
try {
|
|
54
|
+
const pkgJsonPath = require.resolve(`${platformPackage}/package.json`);
|
|
55
|
+
const pkgDir = path.dirname(pkgJsonPath);
|
|
56
|
+
const depBinary = path.join(pkgDir, "vendor", targetTriple, "bin", binaryName);
|
|
57
|
+
if (existsSync(depBinary)) return depBinary;
|
|
58
|
+
const compatBinary = path.join(pkgDir, "vendor", targetTriple, platform === "win32" ? "codex.exe" : "codex");
|
|
59
|
+
if (existsSync(compatBinary)) return compatBinary;
|
|
60
|
+
} catch {
|
|
61
|
+
// optional dependency not installed
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function fetchJSON(url) {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
https.get(url, { headers: { "User-Agent": "kv-code-installer" } }, (res) => {
|
|
70
|
+
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
71
|
+
https.get(res.headers.location, { headers: { "User-Agent": "kv-code-installer" } }, (r) => {
|
|
72
|
+
let d = "";
|
|
73
|
+
r.on("data", (c) => d += c);
|
|
74
|
+
r.on("end", () => resolve(JSON.parse(d)));
|
|
75
|
+
}).on("error", reject);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
let data = "";
|
|
79
|
+
res.on("data", (chunk) => data += chunk);
|
|
80
|
+
res.on("end", () => {
|
|
81
|
+
if (res.statusCode !== 200) reject(new Error(`HTTP ${res.statusCode}: ${data}`));
|
|
82
|
+
else resolve(JSON.parse(data));
|
|
83
|
+
});
|
|
84
|
+
}).on("error", reject);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function downloadFile(url, destPath) {
|
|
89
|
+
mkdirSync(path.dirname(destPath), { recursive: true });
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
const file = require("fs").createWriteStream(destPath);
|
|
92
|
+
https.get(url, { headers: { "User-Agent": "kv-code-installer" } }, (res) => {
|
|
93
|
+
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
94
|
+
file.close();
|
|
95
|
+
require("fs").unlinkSync(destPath);
|
|
96
|
+
downloadFile(res.headers.location, destPath).then(resolve).catch(reject);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (res.statusCode !== 200) {
|
|
100
|
+
file.close();
|
|
101
|
+
require("fs").unlinkSync(destPath);
|
|
102
|
+
reject(new Error(`HTTP ${res.statusCode}`));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const totalSize = parseInt(res.headers["content-length"] || "0", 10);
|
|
106
|
+
let downloaded = 0;
|
|
107
|
+
res.on("data", (chunk) => {
|
|
108
|
+
downloaded += chunk.length;
|
|
109
|
+
if (totalSize > 0) {
|
|
110
|
+
const pct = Math.round((downloaded / totalSize) * 100);
|
|
111
|
+
process.stderr.write(`\r[kv-code] Downloading binary... ${pct}%`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
res.pipe(file);
|
|
115
|
+
file.on("finish", () => {
|
|
116
|
+
file.close();
|
|
117
|
+
if (totalSize > 0) process.stderr.write("\n");
|
|
118
|
+
resolve();
|
|
119
|
+
});
|
|
120
|
+
}).on("error", (err) => {
|
|
121
|
+
file.close();
|
|
122
|
+
require("fs").unlinkSync(destPath);
|
|
123
|
+
reject(err);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function downloadAndInstall() {
|
|
129
|
+
console.error(`[kv-code] Downloading native binary for ${platform} (${arch})...`);
|
|
130
|
+
|
|
131
|
+
let releaseInfo;
|
|
132
|
+
try {
|
|
133
|
+
releaseInfo = await fetchJSON(`https://api.github.com/repos/${GITHUB_REPO}/releases/latest`);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
console.error(`[kv-code] Failed to query GitHub releases: ${err.message}`);
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const version = releaseInfo.tag_name || "";
|
|
140
|
+
const assets = releaseInfo.assets || [];
|
|
141
|
+
|
|
142
|
+
// Try package archive first
|
|
143
|
+
const packageAssetName = `codex-package-${targetTriple}.tar.gz`;
|
|
144
|
+
|
|
145
|
+
let assetUrl = null;
|
|
146
|
+
for (const a of assets) {
|
|
147
|
+
if (a.name === packageAssetName) {
|
|
148
|
+
assetUrl = a.browser_download_url;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!assetUrl) {
|
|
154
|
+
// Try npm platform package as fallback
|
|
155
|
+
const versionNum = version.replace(/^rust-v/, "");
|
|
156
|
+
const os = targetTriple.includes("win32") ? "win32" : targetTriple.includes("darwin") ? "darwin" : "linux";
|
|
157
|
+
const cpu = targetTriple.includes("x86_64") ? "x64" : "arm64";
|
|
158
|
+
const npmAssetName = `codex-npm-${os}-${cpu}-${versionNum}.tgz`;
|
|
159
|
+
for (const a of assets) {
|
|
160
|
+
if (a.name === npmAssetName) {
|
|
161
|
+
assetUrl = a.browser_download_url;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!assetUrl) {
|
|
168
|
+
console.error(`[kv-code] No binary asset found in ${GITHUB_REPO} release ${version}`);
|
|
169
|
+
console.error(`[kv-code] Expected asset: ${packageAssetName}`);
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Download to temp directory
|
|
174
|
+
const tmpDir = path.join(packageRoot, ".tmp-install");
|
|
175
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
176
|
+
const archivePath = path.join(tmpDir, path.basename(assetUrl));
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
console.error(`[kv-code] Downloading from ${GITHUB_REPO}...`);
|
|
180
|
+
await downloadFile(assetUrl, archivePath);
|
|
181
|
+
|
|
182
|
+
// Extract archive
|
|
183
|
+
console.error(`[kv-code] Extracting binary...`);
|
|
184
|
+
const extractDir = path.join(tmpDir, "extract");
|
|
185
|
+
mkdirSync(extractDir, { recursive: true });
|
|
186
|
+
|
|
187
|
+
execSync(`tar -xzf "${archivePath}" -C "${extractDir}"`, { stdio: "pipe" });
|
|
188
|
+
|
|
189
|
+
// Find the binary in the extracted structure
|
|
190
|
+
// Package layout: bin/kv-code(.exe), codex-path/rg, etc.
|
|
191
|
+
// NPM layout: package/vendor/{triple}/codex/codex(.exe)
|
|
192
|
+
let srcBinary = null;
|
|
193
|
+
|
|
194
|
+
// Try package layout first
|
|
195
|
+
const packageBin = path.join(extractDir, "bin", binaryName);
|
|
196
|
+
if (existsSync(packageBin)) {
|
|
197
|
+
srcBinary = packageBin;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Try NPM legacy layout
|
|
201
|
+
if (!srcBinary) {
|
|
202
|
+
const npmVendorBin = path.join(extractDir, "package", "vendor", targetTriple, "codex", binaryName);
|
|
203
|
+
if (existsSync(npmVendorBin)) {
|
|
204
|
+
srcBinary = npmVendorBin;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Try flat codex binary
|
|
209
|
+
if (!srcBinary) {
|
|
210
|
+
const flatCodex = path.join(extractDir, platform === "win32" ? "codex.exe" : "codex");
|
|
211
|
+
if (existsSync(flatCodex)) {
|
|
212
|
+
srcBinary = flatCodex;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!srcBinary) {
|
|
217
|
+
console.error(`[kv-code] Could not find binary in downloaded archive`);
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Copy binary to vendor directory
|
|
222
|
+
mkdirSync(vendorDir, { recursive: true });
|
|
223
|
+
require("fs").copyFileSync(srcBinary, binaryPath);
|
|
224
|
+
if (platform !== "win32") {
|
|
225
|
+
execSync(`chmod +x "${binaryPath}"`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
console.error(`[kv-code] Binary installed to ${binaryPath}`);
|
|
229
|
+
return true;
|
|
230
|
+
} catch (err) {
|
|
231
|
+
console.error(`[kv-code] Failed to install binary: ${err.message}`);
|
|
232
|
+
return false;
|
|
233
|
+
} finally {
|
|
234
|
+
// Cleanup temp files
|
|
235
|
+
try { require("fs").rmSync(tmpDir, { recursive: true, force: true }); } catch {}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function main() {
|
|
240
|
+
const existing = findExistingBinary();
|
|
241
|
+
if (existing) {
|
|
242
|
+
console.error(`[kv-code] Native binary found at ${existing}`);
|
|
243
|
+
process.exit(0);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const installed = await downloadAndInstall();
|
|
247
|
+
if (installed) {
|
|
248
|
+
process.exit(0);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
console.error("");
|
|
252
|
+
console.error(`[kv-code] Native binary not found for ${platform} (${arch})`);
|
|
253
|
+
console.error("");
|
|
254
|
+
console.error(" To install manually:");
|
|
255
|
+
console.error("");
|
|
256
|
+
console.error(` 1. Download from GitHub Releases:`);
|
|
257
|
+
console.error(` https://github.com/${GITHUB_REPO}/releases`);
|
|
258
|
+
console.error("");
|
|
259
|
+
console.error(" 2. Build from source:");
|
|
260
|
+
console.error(" cd kv-code-rs && cargo build --release");
|
|
261
|
+
console.error(` Then copy the binary to:`);
|
|
262
|
+
console.error(` ${binaryPath}`);
|
|
263
|
+
console.error("");
|
|
264
|
+
process.exit(1);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
main();
|