@uselana/cli 0.1.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/LICENSE +201 -0
- package/NOTICE +6 -0
- package/README.md +49 -0
- package/bin/lana.js +305 -0
- package/package.json +44 -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/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Lana CLI
|
|
2
|
+
|
|
3
|
+
Lana is a coding agent for your terminal. Ask it to explore a project, explain code, make changes, or run tests. You review its work and control command approvals.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Requires Node.js 22 or newer.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install -g @uselana/cli
|
|
11
|
+
lana --version
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Supported platforms: macOS (Apple Silicon and Intel), Linux (x64 and ARM64), and Windows (x64 and ARM64).
|
|
15
|
+
|
|
16
|
+
## Sign in
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
lana login
|
|
20
|
+
cd your-project
|
|
21
|
+
lana
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Complete Google sign-in in your browser, then return to the terminal. Access is currently invite-only. Coding requires an active account and available model credit; signing in alone does not grant credit.
|
|
25
|
+
|
|
26
|
+
If browser sign-in cannot finish, run `lana login --manual` and follow the prompts. Keep the one-use sign-in code private.
|
|
27
|
+
|
|
28
|
+
## Use Lana
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
lana "Explain this project"
|
|
32
|
+
lana "Fix the failing tests"
|
|
33
|
+
lana exec "Review this change for regressions"
|
|
34
|
+
lana account
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Use `/model` to select an available model, `/usage` to check access and credit, and `lana --help` for command help.
|
|
38
|
+
|
|
39
|
+
## Updates
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
npm install -g @uselana/cli@latest
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Privacy and support
|
|
46
|
+
|
|
47
|
+
Code and prompts needed for your task are sent to the Lana service for processing. Review what you share and the command permissions you approve. For access or support, contact the person who invited you to Lana.
|
|
48
|
+
|
|
49
|
+
This package includes the launcher and compiled runtime components, not the application source repository. See the included LICENSE and NOTICE for attribution and licence terms.
|
package/bin/lana.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Unified entry point for the Lana CLI.
|
|
3
|
+
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { existsSync, readFileSync, 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
|
+
const codexPackageRoot = realpathSync(path.join(__dirname, ".."));
|
|
15
|
+
|
|
16
|
+
const PLATFORM_PACKAGE_BY_TARGET = {
|
|
17
|
+
"x86_64-unknown-linux-musl": "@uselana/cli-linux-x64",
|
|
18
|
+
"aarch64-unknown-linux-musl": "@uselana/cli-linux-arm64",
|
|
19
|
+
"x86_64-apple-darwin": "@uselana/cli-darwin-x64",
|
|
20
|
+
"aarch64-apple-darwin": "@uselana/cli-darwin-arm64",
|
|
21
|
+
"x86_64-pc-windows-msvc": "@uselana/cli-win32-x64",
|
|
22
|
+
"aarch64-pc-windows-msvc": "@uselana/cli-win32-arm64",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const { platform, arch } = process;
|
|
26
|
+
|
|
27
|
+
let targetTriple = null;
|
|
28
|
+
switch (platform) {
|
|
29
|
+
case "linux":
|
|
30
|
+
case "android":
|
|
31
|
+
switch (arch) {
|
|
32
|
+
case "x64":
|
|
33
|
+
targetTriple = "x86_64-unknown-linux-musl";
|
|
34
|
+
break;
|
|
35
|
+
case "arm64":
|
|
36
|
+
targetTriple = "aarch64-unknown-linux-musl";
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
case "darwin":
|
|
43
|
+
switch (arch) {
|
|
44
|
+
case "x64":
|
|
45
|
+
targetTriple = "x86_64-apple-darwin";
|
|
46
|
+
break;
|
|
47
|
+
case "arm64":
|
|
48
|
+
targetTriple = "aarch64-apple-darwin";
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
case "win32":
|
|
55
|
+
switch (arch) {
|
|
56
|
+
case "x64":
|
|
57
|
+
targetTriple = "x86_64-pc-windows-msvc";
|
|
58
|
+
break;
|
|
59
|
+
case "arm64":
|
|
60
|
+
targetTriple = "aarch64-pc-windows-msvc";
|
|
61
|
+
break;
|
|
62
|
+
default:
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!targetTriple) {
|
|
71
|
+
throw new Error(`Unsupported platform: ${platform} (${arch})`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const releasePackage = JSON.parse(
|
|
75
|
+
readFileSync(path.join(codexPackageRoot, "package.json"), "utf8"),
|
|
76
|
+
);
|
|
77
|
+
if (
|
|
78
|
+
releasePackage.lanaSupportedTargets &&
|
|
79
|
+
!releasePackage.lanaSupportedTargets.includes(targetTriple)
|
|
80
|
+
) {
|
|
81
|
+
throw new Error(`Lana ${releasePackage.version} is not available for ${platform}/${arch}.`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
|
|
85
|
+
if (!platformPackage) {
|
|
86
|
+
throw new Error(`Unsupported target triple: ${targetTriple}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function findLanaExecutable() {
|
|
90
|
+
let vendorRoot;
|
|
91
|
+
try {
|
|
92
|
+
const packageJsonPath = require.resolve(`${platformPackage}/package.json`);
|
|
93
|
+
vendorRoot = path.join(path.dirname(packageJsonPath), "vendor");
|
|
94
|
+
} catch {
|
|
95
|
+
vendorRoot = path.join(__dirname, "..", "vendor");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const lanaExecutable = path.join(
|
|
99
|
+
vendorRoot,
|
|
100
|
+
targetTriple,
|
|
101
|
+
"bin",
|
|
102
|
+
process.platform === "win32" ? "lana.exe" : "lana",
|
|
103
|
+
);
|
|
104
|
+
if (existsSync(lanaExecutable)) {
|
|
105
|
+
return lanaExecutable;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const packageManager = detectPackageManager();
|
|
109
|
+
const updateCommand =
|
|
110
|
+
packageManager === "bun"
|
|
111
|
+
? "bun install -g @uselana/cli@latest"
|
|
112
|
+
: packageManager === "pnpm"
|
|
113
|
+
? "pnpm add -g @uselana/cli@latest"
|
|
114
|
+
: packageManager === "vite-plus"
|
|
115
|
+
? "vp install -g @uselana/cli@latest"
|
|
116
|
+
: "npm install -g @uselana/cli@latest";
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Missing optional dependency ${platformPackage}. Reinstall Lana: ${updateCommand}`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const binaryPath = findLanaExecutable();
|
|
123
|
+
|
|
124
|
+
// Use an asynchronous spawn instead of spawnSync so that Node is able to
|
|
125
|
+
// respond to signals (e.g. Ctrl-C / SIGINT) while the native binary is
|
|
126
|
+
// executing. This allows us to forward those signals to the child process
|
|
127
|
+
// and guarantees that when either the child terminates or the parent
|
|
128
|
+
// receives a fatal signal, both processes exit in a predictable manner.
|
|
129
|
+
|
|
130
|
+
function isPnpmOwnedCodexInstall(nodeModulesDir) {
|
|
131
|
+
if (!existsSync(path.join(nodeModulesDir, ".modules.yaml"))) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
return (
|
|
137
|
+
realpathSync(path.join(nodeModulesDir, "@uselana", "cli")) ===
|
|
138
|
+
codexPackageRoot
|
|
139
|
+
);
|
|
140
|
+
} catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function isVitePlusOwnedCodexInstall(packagesDir) {
|
|
146
|
+
if (path.basename(packagesDir) !== "packages") {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
const metadata = JSON.parse(
|
|
152
|
+
readFileSync(path.join(packagesDir, "@uselana", "cli.json"), "utf8"),
|
|
153
|
+
);
|
|
154
|
+
if (metadata.name !== "@uselana/cli") {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Vite+ records the active global installation in packages/@uselana/cli.json.
|
|
159
|
+
// Older installs have no ID or append a #-prefixed ID to the package name;
|
|
160
|
+
// newer installs put the ID in a subdirectory of the package prefix.
|
|
161
|
+
const installId = metadata.installId || "";
|
|
162
|
+
const installDir = installId.startsWith("#")
|
|
163
|
+
? path.join(packagesDir, `@uselana/cli${installId}`)
|
|
164
|
+
: path.join(packagesDir, "@uselana/cli", installId);
|
|
165
|
+
for (const nodeModulesDir of [
|
|
166
|
+
path.join(installDir, "lib", "node_modules"),
|
|
167
|
+
path.join(installDir, "node_modules"),
|
|
168
|
+
]) {
|
|
169
|
+
const packageRoot = path.join(nodeModulesDir, "@uselana", "cli");
|
|
170
|
+
if (
|
|
171
|
+
existsSync(packageRoot) &&
|
|
172
|
+
realpathSync(packageRoot) === codexPackageRoot
|
|
173
|
+
) {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
} catch {
|
|
178
|
+
// Missing or unreadable ownership metadata must not prevent Codex starting.
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Use heuristics to detect the package manager that was used to install Codex
|
|
185
|
+
* in order to give the user a hint about how to update it.
|
|
186
|
+
*/
|
|
187
|
+
function detectPackageManager() {
|
|
188
|
+
// Package-manager ownership metadata can be several parents above the package.
|
|
189
|
+
// Search ancestors of both the canonical package root and lexical entrypoint
|
|
190
|
+
// because the package manager may link either path.
|
|
191
|
+
const entrypointDir = path.dirname(path.resolve(process.argv[1]));
|
|
192
|
+
for (const startDir of new Set([codexPackageRoot, entrypointDir])) {
|
|
193
|
+
const filesystemRoot = path.parse(startDir).root;
|
|
194
|
+
for (
|
|
195
|
+
let currentDir = startDir;
|
|
196
|
+
currentDir !== filesystemRoot;
|
|
197
|
+
currentDir = path.dirname(currentDir)
|
|
198
|
+
) {
|
|
199
|
+
if (isVitePlusOwnedCodexInstall(currentDir)) {
|
|
200
|
+
return "vite-plus";
|
|
201
|
+
}
|
|
202
|
+
if (isPnpmOwnedCodexInstall(path.join(currentDir, "node_modules"))) {
|
|
203
|
+
return "pnpm";
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (isPnpmOwnedCodexInstall(path.join(filesystemRoot, "node_modules"))) {
|
|
208
|
+
return "pnpm";
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
213
|
+
if (/\bbun\//.test(userAgent)) {
|
|
214
|
+
return "bun";
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const execPath = process.env.npm_execpath || "";
|
|
218
|
+
if (execPath.includes("bun")) {
|
|
219
|
+
return "bun";
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (
|
|
223
|
+
__dirname.includes(".bun/install/global") ||
|
|
224
|
+
__dirname.includes(".bun\\install\\global")
|
|
225
|
+
) {
|
|
226
|
+
return "bun";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return userAgent ? "npm" : null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const packageManager = detectPackageManager();
|
|
233
|
+
const packageManagerEnvVar =
|
|
234
|
+
packageManager === "bun"
|
|
235
|
+
? "CODEX_MANAGED_BY_BUN"
|
|
236
|
+
: packageManager === "pnpm"
|
|
237
|
+
? "CODEX_MANAGED_BY_PNPM"
|
|
238
|
+
: packageManager === "vite-plus"
|
|
239
|
+
? "CODEX_MANAGED_BY_VITE_PLUS"
|
|
240
|
+
: "CODEX_MANAGED_BY_NPM";
|
|
241
|
+
const env = {
|
|
242
|
+
...process.env,
|
|
243
|
+
CODEX_MANAGED_PACKAGE_ROOT: codexPackageRoot,
|
|
244
|
+
};
|
|
245
|
+
delete env.CODEX_MANAGED_BY_NPM;
|
|
246
|
+
delete env.CODEX_MANAGED_BY_BUN;
|
|
247
|
+
delete env.CODEX_MANAGED_BY_PNPM;
|
|
248
|
+
delete env.CODEX_MANAGED_BY_VITE_PLUS;
|
|
249
|
+
env[packageManagerEnvVar] = "1";
|
|
250
|
+
|
|
251
|
+
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
252
|
+
stdio: "inherit",
|
|
253
|
+
env,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
child.on("error", (err) => {
|
|
257
|
+
// Typically triggered when the binary is missing or not executable.
|
|
258
|
+
// Re-throwing here will terminate the parent with a non-zero exit code
|
|
259
|
+
// while still printing a helpful stack trace.
|
|
260
|
+
// eslint-disable-next-line no-console
|
|
261
|
+
console.error(err);
|
|
262
|
+
process.exit(1);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// Forward common termination signals to the child so that it shuts down
|
|
266
|
+
// gracefully. In the handler we temporarily disable the default behavior of
|
|
267
|
+
// exiting immediately; once the child has been signaled we simply wait for
|
|
268
|
+
// its exit event which will in turn terminate the parent (see below).
|
|
269
|
+
const forwardSignal = (signal) => {
|
|
270
|
+
if (child.killed) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
child.kill(signal);
|
|
275
|
+
} catch {
|
|
276
|
+
/* ignore */
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
|
|
281
|
+
process.on(sig, () => forwardSignal(sig));
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// When the child exits, mirror its termination reason in the parent so that
|
|
285
|
+
// shell scripts and other tooling observe the correct exit status.
|
|
286
|
+
// Wrap the lifetime of the child process in a Promise so that we can await
|
|
287
|
+
// its termination in a structured way. The Promise resolves with an object
|
|
288
|
+
// describing how the child exited: either via exit code or due to a signal.
|
|
289
|
+
const childResult = await new Promise((resolve) => {
|
|
290
|
+
child.on("exit", (code, signal) => {
|
|
291
|
+
if (signal) {
|
|
292
|
+
resolve({ type: "signal", signal });
|
|
293
|
+
} else {
|
|
294
|
+
resolve({ type: "code", exitCode: code ?? 1 });
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
if (childResult.type === "signal") {
|
|
300
|
+
// Re-emit the same signal so that the parent terminates with the expected
|
|
301
|
+
// semantics (this also sets the correct exit code of 128 + n).
|
|
302
|
+
process.kill(process.pid, childResult.signal);
|
|
303
|
+
} else {
|
|
304
|
+
process.exit(childResult.exitCode);
|
|
305
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uselana/cli",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Lana CLI is a coding agent that runs locally on your computer.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"bin": {
|
|
7
|
+
"lana": "bin/lana.js"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=22"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin/lana.js",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"NOTICE"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/frain-dev/lana-cli.git",
|
|
22
|
+
"directory": "codex-cli"
|
|
23
|
+
},
|
|
24
|
+
"packageManager": "pnpm@10.34.5+sha512.a4ee05f2f73658255bd6a89859c065a45c28a57daefae2c893a168ee2b73168c37b91e83e57ea67654ad03f03031746430e8bce38e362e042605fb8abc80192e",
|
|
25
|
+
"optionalDependencies": {
|
|
26
|
+
"@uselana/cli-linux-x64": "0.1.1",
|
|
27
|
+
"@uselana/cli-linux-arm64": "0.1.1",
|
|
28
|
+
"@uselana/cli-darwin-x64": "0.1.1",
|
|
29
|
+
"@uselana/cli-darwin-arm64": "0.1.1",
|
|
30
|
+
"@uselana/cli-win32-x64": "0.1.1",
|
|
31
|
+
"@uselana/cli-win32-arm64": "0.1.1"
|
|
32
|
+
},
|
|
33
|
+
"lanaSupportedTargets": [
|
|
34
|
+
"x86_64-unknown-linux-musl",
|
|
35
|
+
"aarch64-unknown-linux-musl",
|
|
36
|
+
"x86_64-apple-darwin",
|
|
37
|
+
"aarch64-apple-darwin",
|
|
38
|
+
"x86_64-pc-windows-msvc",
|
|
39
|
+
"aarch64-pc-windows-msvc"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|