larness 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +40 -2
- package/app.js +122 -0
- package/apps/server/dist/address-BE25lU9-.js +94 -0
- package/apps/server/dist/client-Co1thYbK.js +120 -0
- package/apps/server/dist/doctor-ClvbJZvj.js +127 -0
- package/apps/server/dist/doctor.js +12 -0
- package/apps/server/dist/index.js +27349 -0
- package/apps/server/dist/lock-DyEoZgG_.js +101 -0
- package/apps/server/dist/managed-CLFUiDbj.js +2138 -0
- package/apps/server/dist/paths-BHryFHwq.js +2337 -0
- package/apps/server/dist/status-idXF0pm6.js +49 -0
- package/apps/server/dist/status.js +30 -0
- package/apps/server/dist/tui.js +1626 -0
- package/apps/server/drizzle/0001_auth.sql +110 -0
- package/apps/server/drizzle/0002_projects.sql +13 -0
- package/apps/server/drizzle/0003_workspace.sql +81 -0
- package/apps/server/drizzle/0004_models.sql +30 -0
- package/apps/server/drizzle/0005_resources.sql +54 -0
- package/apps/server/drizzle/0006_commands.sql +24 -0
- package/apps/server/drizzle/0007_terminals.sql +42 -0
- package/apps/server/drizzle/0008_resource_actions.sql +24 -0
- package/apps/server/drizzle/0009_terminal_title.sql +1 -0
- package/apps/server/drizzle/0010_services.sql +32 -0
- package/apps/server/drizzle/0011_deployments.sql +88 -0
- package/apps/server/drizzle/0012_deployment_authorizations.sql +67 -0
- package/apps/server/drizzle/0013_service_ops.sql +64 -0
- package/apps/server/drizzle/0014_service_actions.sql +36 -0
- package/apps/server/drizzle/0015_model_catalog.sql +17 -0
- package/apps/server/drizzle/0016_multi_provider.sql +2 -0
- package/apps/server/drizzle/0017_model_visibility.sql +10 -0
- package/apps/server/drizzle/0018_model_defaults.sql +9 -0
- package/apps/server/drizzle/0019_credential_endpoint.sql +1 -0
- package/apps/server/drizzle/0020_compatible_context.sql +1 -0
- package/apps/server/drizzle/0021_context_summaries.sql +13 -0
- package/apps/server/drizzle/0022_scheduler.sql +58 -0
- package/apps/server/drizzle/0023_turn_terminal_reason.sql +1 -0
- package/apps/server/drizzle/0024_turn_checkpoints.sql +4 -0
- package/apps/server/drizzle/0025_turn_resume.sql +1 -0
- package/apps/server/drizzle/0026_session_pin.sql +1 -0
- package/apps/server/drizzle/0027_project_sort_order.sql +2 -0
- package/apps/server/drizzle/meta/0001_snapshot.json +705 -0
- package/apps/server/drizzle/meta/0002_snapshot.json +784 -0
- package/apps/server/drizzle/meta/0003_snapshot.json +1300 -0
- package/apps/server/drizzle/meta/0004_snapshot.json +1489 -0
- package/apps/server/drizzle/meta/0005_snapshot.json +1794 -0
- package/apps/server/drizzle/meta/0006_snapshot.json +1953 -0
- package/apps/server/drizzle/meta/0007_snapshot.json +2232 -0
- package/apps/server/drizzle/meta/0008_snapshot.json +2391 -0
- package/apps/server/drizzle/meta/0009_snapshot.json +2398 -0
- package/apps/server/drizzle/meta/0010_snapshot.json +2601 -0
- package/apps/server/drizzle/meta/0015_snapshot.json +4332 -0
- package/apps/server/drizzle/meta/0016_snapshot.json +4346 -0
- package/apps/server/drizzle/meta/0017_snapshot.json +4408 -0
- package/apps/server/drizzle/meta/0018_snapshot.json +4468 -0
- package/apps/server/drizzle/meta/0019_snapshot.json +4475 -0
- package/apps/server/drizzle/meta/0020_snapshot.json +4482 -0
- package/apps/server/drizzle/meta/0021_snapshot.json +4565 -0
- package/apps/server/drizzle/meta/0022_snapshot.json +4960 -0
- package/apps/server/drizzle/meta/0023_snapshot.json +4967 -0
- package/apps/server/drizzle/meta/0024_snapshot.json +4994 -0
- package/apps/server/drizzle/meta/0025_snapshot.json +5001 -0
- package/apps/server/drizzle/meta/0026_snapshot.json +5008 -0
- package/apps/server/drizzle/meta/0027_snapshot.json +5021 -0
- package/apps/server/drizzle/meta/_journal.json +195 -0
- package/apps/server/package.json +57 -0
- package/apps/web/dist/assets/FileEditor-twkRcPR8.js +1 -0
- package/apps/web/dist/assets/FileViewer-B6J1gfWW.js +1 -0
- package/apps/web/dist/assets/abap-08VXUWAP.js +1 -0
- package/apps/web/dist/assets/apex-BWPQTe0t.js +1 -0
- package/apps/web/dist/assets/azcli-Bc_sGQ0U.js +1 -0
- package/apps/web/dist/assets/bat-i0X4ZdIN.js +1 -0
- package/apps/web/dist/assets/bicep-B5-_aFwp.js +2 -0
- package/apps/web/dist/assets/cameligo-DMUM7wLl.js +1 -0
- package/apps/web/dist/assets/clojure-Cm7r79vr.js +1 -0
- package/apps/web/dist/assets/codicon-DF1abBS2.ttf +0 -0
- package/apps/web/dist/assets/coffee-Ba7i2nA0.js +1 -0
- package/apps/web/dist/assets/cpp-C7h46wYY.js +1 -0
- package/apps/web/dist/assets/csharp-BKxtCVv1.js +1 -0
- package/apps/web/dist/assets/csp-bTuwJoIa.js +1 -0
- package/apps/web/dist/assets/css-DIMkf-bt.js +3 -0
- package/apps/web/dist/assets/css.worker-C5TGqYcS.js +96 -0
- package/apps/web/dist/assets/cssMode-B2gCrV51.js +1 -0
- package/apps/web/dist/assets/cypher-CVaqCwHa.js +1 -0
- package/apps/web/dist/assets/dart-onAF5SnQ.js +1 -0
- package/apps/web/dist/assets/dockerfile-DZFCIeNp.js +1 -0
- package/apps/web/dist/assets/ecl-94qehhXe.js +1 -0
- package/apps/web/dist/assets/editor-B8GMDV7_.css +1 -0
- package/apps/web/dist/assets/editor.api-TQGsXQVT.js +908 -0
- package/apps/web/dist/assets/editor.worker-uJzjfcWc.js +33 -0
- package/apps/web/dist/assets/elixir-6RTg0lbw.js +1 -0
- package/apps/web/dist/assets/flow9-C5_-GSwl.js +1 -0
- package/apps/web/dist/assets/freemarker2-Due01FLd.js +3 -0
- package/apps/web/dist/assets/fsharp-C8Ef5oNN.js +1 -0
- package/apps/web/dist/assets/go-C-y9NEjX.js +1 -0
- package/apps/web/dist/assets/graphql-fmXr3nnJ.js +1 -0
- package/apps/web/dist/assets/handlebars-Cbmho-0R.js +1 -0
- package/apps/web/dist/assets/hcl-CpzslTdj.js +1 -0
- package/apps/web/dist/assets/html-1Ke8CI8o.js +1 -0
- package/apps/web/dist/assets/html.worker-DthhmbAk.js +509 -0
- package/apps/web/dist/assets/htmlMode-KxcipU--.js +1 -0
- package/apps/web/dist/assets/index-BvfzAW2A.js +158 -0
- package/apps/web/dist/assets/index-DxcI8GSl.css +1 -0
- package/apps/web/dist/assets/ini-sBoK_t0W.js +1 -0
- package/apps/web/dist/assets/java-BEtHBSE6.js +1 -0
- package/apps/web/dist/assets/javascript-DMPkDcJu.js +1 -0
- package/apps/web/dist/assets/json.worker-BGaEIa3n.js +65 -0
- package/apps/web/dist/assets/jsonMode-CLqudskm.js +7 -0
- package/apps/web/dist/assets/julia-Bri6UV-V.js +1 -0
- package/apps/web/dist/assets/kotlin-BOotOW0E.js +1 -0
- package/apps/web/dist/assets/less-B9JPFI3C.js +2 -0
- package/apps/web/dist/assets/lexon-CfSJPG6W.js +1 -0
- package/apps/web/dist/assets/liquid-bIUiAHG1.js +1 -0
- package/apps/web/dist/assets/lspLanguageFeatures-CplKbdW4.js +4 -0
- package/apps/web/dist/assets/lua-CsQS60Ue.js +1 -0
- package/apps/web/dist/assets/m3-D-oSqn_W.js +1 -0
- package/apps/web/dist/assets/markdown-Cimd5fb3.js +1 -0
- package/apps/web/dist/assets/mdx-DiInMCu3.js +1 -0
- package/apps/web/dist/assets/mips-CIPQ_RoX.js +1 -0
- package/apps/web/dist/assets/monaco-D_A7VB90.js +68 -0
- package/apps/web/dist/assets/monaco-n7clI0si.css +1 -0
- package/apps/web/dist/assets/msdax-DauUninz.js +1 -0
- package/apps/web/dist/assets/mysql-SOo6toE5.js +1 -0
- package/apps/web/dist/assets/objective-c-FvmIjYaQ.js +1 -0
- package/apps/web/dist/assets/pascal-DrH0SRf2.js +1 -0
- package/apps/web/dist/assets/pascaligo-D-ptJ9y-.js +1 -0
- package/apps/web/dist/assets/perl-oz_6vUea.js +1 -0
- package/apps/web/dist/assets/pgsql-DTj74zXo.js +1 -0
- package/apps/web/dist/assets/php-nr791fC2.js +1 -0
- package/apps/web/dist/assets/pla-CopQ2nXW.js +1 -0
- package/apps/web/dist/assets/postiats-43DmfD33.js +1 -0
- package/apps/web/dist/assets/powerquery-D3hlyOfw.js +1 -0
- package/apps/web/dist/assets/powershell-DmHpPYUd.js +1 -0
- package/apps/web/dist/assets/protobuf-C531GsRP.js +2 -0
- package/apps/web/dist/assets/pug-Z5eAx3Zn.js +1 -0
- package/apps/web/dist/assets/python-O93J5sRJ.js +1 -0
- package/apps/web/dist/assets/qsharp-DkqhCAOL.js +1 -0
- package/apps/web/dist/assets/r-BwWrilGY.js +1 -0
- package/apps/web/dist/assets/razor-DpA8sAYd.js +1 -0
- package/apps/web/dist/assets/redis-ClamHrr6.js +1 -0
- package/apps/web/dist/assets/redshift-DT7zqm-g.js +1 -0
- package/apps/web/dist/assets/restructuredtext-BYgofb2h.js +1 -0
- package/apps/web/dist/assets/ruby-DezsRK8O.js +1 -0
- package/apps/web/dist/assets/rust-DdL9SqIa.js +1 -0
- package/apps/web/dist/assets/sb-CcwsVR0C.js +1 -0
- package/apps/web/dist/assets/scala-DHpiXF5c.js +1 -0
- package/apps/web/dist/assets/scheme-BeGwcela.js +1 -0
- package/apps/web/dist/assets/scss-gp-XZpBa.js +3 -0
- package/apps/web/dist/assets/shell-CC2rA5mh.js +1 -0
- package/apps/web/dist/assets/solidity-BEEn4gHE.js +1 -0
- package/apps/web/dist/assets/sophia-CRfGWb83.js +1 -0
- package/apps/web/dist/assets/sparql-D_Lu-MrJ.js +1 -0
- package/apps/web/dist/assets/sql-NEE52Syq.js +1 -0
- package/apps/web/dist/assets/st-DbInun42.js +1 -0
- package/apps/web/dist/assets/swift-Bxkupp3x.js +1 -0
- package/apps/web/dist/assets/systemverilog-Bz4Y3fRF.js +1 -0
- package/apps/web/dist/assets/tcl-DISqw1ZD.js +1 -0
- package/apps/web/dist/assets/ts.worker-CUR_zL4j.js +67741 -0
- package/apps/web/dist/assets/tsMode-qBmFN2NS.js +11 -0
- package/apps/web/dist/assets/twig-De2hgUGE.js +1 -0
- package/apps/web/dist/assets/typescript-BjR2yH8S.js +1 -0
- package/apps/web/dist/assets/typespec-B8J7ngcE.js +1 -0
- package/apps/web/dist/assets/vb-DV3o63ZY.js +1 -0
- package/apps/web/dist/assets/wgsl-DpFanUEy.js +298 -0
- package/apps/web/dist/assets/workers-x9_8y1ur.js +1 -0
- package/apps/web/dist/assets/xml-CL70_TAY.js +1 -0
- package/apps/web/dist/assets/yaml-qno5z39m.js +1 -0
- package/apps/web/dist/favicon.svg +4 -0
- package/apps/web/dist/index.html +15 -0
- package/docs/README.md +26 -0
- package/docs/guides/install.md +88 -0
- package/package.json +95 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Larness contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Larness
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Larness 是在自己电脑上运行的 AI 开发工作台。配对浏览器后,可以在同一个工作空间里和 Agent 协作,编辑文件、使用终端、管理 Git、预览开发服务,并查看本机运行的应用。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g larness
|
|
9
|
+
larness
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
使用 Node.js 22.22+(22.x)/ 24+。macOS Apple Silicon 已验证 Node.js 22 和 24;Windows 11 x64 已验证 Node.js 24 的原生 TUI、ConPTY 终端、命令与 PM2。其他平台的状态见 [支持范围](https://github.com/bulv0620/Larness/blob/main/docs/known-limitations.md)。升级和卸载步骤见 [安装指南](docs/guides/install.md)。
|
|
13
|
+
|
|
14
|
+
## 开始使用
|
|
15
|
+
|
|
16
|
+
1. 在终端控制台(TUI)完成首次初始化,打开控制台显示的 Web 地址,默认是 `http://localhost:3210`。
|
|
17
|
+
2. 从浏览器发起配对,在本机控制台处理申请。可以临时授权,也可以通过 Passkey 保存可信凭据。
|
|
18
|
+
3. 在「设置与模型」添加模型 API Key,选择默认工作区或关联本机项目,然后开启对话。
|
|
19
|
+
|
|
20
|
+
## 可以做什么
|
|
21
|
+
|
|
22
|
+
- **开发协作**:使用 DeepSeek、GLM 或兼容端点,查看任务计划、工具执行进度和上下文用量。可以让 Agent 读写项目文件、运行命令,或把项目终端交给 Agent 操作。
|
|
23
|
+
- **本机预览与运维**:打开已登记的开发服务预览。通过项目会话使用 PM2 命令,在服务运维界面查看日志、启动、停止或重启正式服务。
|
|
24
|
+
- **定时运行**:从工作台设置 Cron 或固定间隔任务,运行 JavaScript 脚本或 Agent,查看运行历史。
|
|
25
|
+
|
|
26
|
+
退出控制台会停止 Web 管理面和临时开发资源。已由 PM2 托管的正式服务会继续运行。命令、项目脚本和定时任务使用 Larness 运行账户的权限,请在可信开发机上使用。
|
|
27
|
+
|
|
28
|
+
## 从源码运行
|
|
29
|
+
|
|
30
|
+
源码工具链请使用 Node.js 22.22+(22.x)或 24.11+(24.x)。
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pnpm install
|
|
34
|
+
pnpm dev
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
构建后可用 `pnpm build` 和 `node app.js` 启动打包形态。
|
|
38
|
+
|
|
39
|
+
## 许可证
|
|
40
|
+
|
|
41
|
+
[MIT](LICENSE)
|
package/app.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
+
|
|
8
|
+
const root = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
|
|
10
|
+
const commands = {
|
|
11
|
+
tui: { dist: "apps/server/dist/tui.js", source: "apps/server/src/tui/main.ts" },
|
|
12
|
+
status: { dist: "apps/server/dist/status.js", source: "apps/server/src/cli/status.ts" },
|
|
13
|
+
doctor: { dist: "apps/server/dist/doctor.js", source: "apps/server/src/cli/doctor.ts" },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function version() {
|
|
17
|
+
try {
|
|
18
|
+
const pkg = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8"));
|
|
19
|
+
return typeof pkg.version === "string" ? pkg.version : "0.0.0";
|
|
20
|
+
} catch {
|
|
21
|
+
return "0.0.0";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function help() {
|
|
26
|
+
console.log(`Larness ${version()}
|
|
27
|
+
|
|
28
|
+
Usage:
|
|
29
|
+
node app.js Start Server + Web and enter the TUI
|
|
30
|
+
node app.js tui Same as above
|
|
31
|
+
node app.js status Print a read-only status snapshot
|
|
32
|
+
node app.js doctor Run local diagnostics (non-zero on failure)
|
|
33
|
+
node app.js --version Print the version
|
|
34
|
+
node app.js --help Show this help
|
|
35
|
+
|
|
36
|
+
Closing the TUI stops the Server and Web processes (ADR-023).
|
|
37
|
+
Environment:
|
|
38
|
+
LARNESS_DATA_DIR, LARNESS_HOST, LARNESS_PORT, LARNESS_PUBLIC_URL,
|
|
39
|
+
LARNESS_LOG_LEVEL, LARNESS_WEB_DIST`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function runSource(sourcePath, args) {
|
|
43
|
+
// Avoid a pnpm shell shim (and Windows .cmd quoting) by loading tsx through
|
|
44
|
+
// Node's own --import flag, exactly like the managed TUI does.
|
|
45
|
+
const require = createRequire(path.join(root, "apps", "server", "package.json"));
|
|
46
|
+
const loader = pathToFileURL(require.resolve("tsx/esm")).href;
|
|
47
|
+
const result = spawnSync(process.execPath, ["--import", loader, sourcePath, ...args], {
|
|
48
|
+
cwd: root,
|
|
49
|
+
stdio: "inherit",
|
|
50
|
+
env: process.env,
|
|
51
|
+
});
|
|
52
|
+
if (result.error) {
|
|
53
|
+
console.error(`[larness] cannot run source entry: ${result.error.message}`);
|
|
54
|
+
console.error("Build first with `pnpm build`, or ensure tsx is installed.");
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
process.exitCode = result.status ?? 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function runTui() {
|
|
62
|
+
const distPath = path.join(root, commands.tui.dist);
|
|
63
|
+
const useDist = existsSync(distPath);
|
|
64
|
+
|
|
65
|
+
process.env.LARNESS_TUI_MANAGED = "1";
|
|
66
|
+
process.env.LARNESS_TUI_DEV = useDist ? "0" : "1";
|
|
67
|
+
|
|
68
|
+
if (useDist) {
|
|
69
|
+
import(pathToFileURL(distPath).href).catch((error) => {
|
|
70
|
+
console.error(`[larness] tui failed: ${error instanceof Error ? error.message : error}`);
|
|
71
|
+
process.exitCode = 1;
|
|
72
|
+
});
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!existsSync(path.join(root, commands.tui.source))) {
|
|
77
|
+
console.error("[larness] install is incomplete: apps/server/dist/tui.js is missing.");
|
|
78
|
+
console.error("Reinstall with `npm install -g larness`.");
|
|
79
|
+
process.exitCode = 1;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
runSource(path.join(root, commands.tui.source), ["--managed", "--dev"]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function runReadOnly(name) {
|
|
87
|
+
const command = commands[name];
|
|
88
|
+
const distPath = path.join(root, command.dist);
|
|
89
|
+
|
|
90
|
+
if (existsSync(distPath)) {
|
|
91
|
+
import(pathToFileURL(distPath).href).catch((error) => {
|
|
92
|
+
console.error(`[larness] ${name} failed: ${error instanceof Error ? error.message : error}`);
|
|
93
|
+
process.exitCode = 1;
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!existsSync(path.join(root, command.source))) {
|
|
99
|
+
console.error(`[larness] install is incomplete: apps/server/dist/${name}.js is missing.`);
|
|
100
|
+
console.error("Reinstall with `npm install -g larness`.");
|
|
101
|
+
process.exitCode = 1;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
runSource(path.join(root, command.source), []);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const [first, ...rest] = process.argv.slice(2);
|
|
109
|
+
|
|
110
|
+
if (first === undefined || first === "tui" || first === "start") {
|
|
111
|
+
runTui();
|
|
112
|
+
} else if (first === "--version" || first === "-v") {
|
|
113
|
+
console.log(version());
|
|
114
|
+
} else if (first === "--help" || first === "-h" || first === "help") {
|
|
115
|
+
help();
|
|
116
|
+
} else if ((first === "status" || first === "doctor") && rest.length === 0) {
|
|
117
|
+
runReadOnly(first);
|
|
118
|
+
} else {
|
|
119
|
+
console.error(`[larness] unknown command: ${first}`);
|
|
120
|
+
help();
|
|
121
|
+
process.exitCode = 1;
|
|
122
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { _n as OriginUrlSchema } from "./paths-BHryFHwq.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
// src/ipc/protocol.ts
|
|
7
|
+
const MAX_FRAME_BYTES = 1048576;
|
|
8
|
+
const DEFAULT_IDLE_TIMEOUT_MS = 18e5;
|
|
9
|
+
var IpcError = class extends Error {
|
|
10
|
+
code;
|
|
11
|
+
constructor(code, message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "IpcError";
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const RequestEnvelopeSchema = z.object({
|
|
18
|
+
id: z.string().min(1).max(128),
|
|
19
|
+
method: z.string().min(1).max(64),
|
|
20
|
+
params: z.unknown().optional()
|
|
21
|
+
});
|
|
22
|
+
const HelloParamsSchema = z.object({
|
|
23
|
+
token: z.string().min(1).max(256),
|
|
24
|
+
client: z.string().min(1).max(64),
|
|
25
|
+
pid: z.int().positive().optional()
|
|
26
|
+
}).strict();
|
|
27
|
+
const InitApplyParamsSchema = z.object({
|
|
28
|
+
host: z.string().min(1).max(255).optional(),
|
|
29
|
+
port: z.int().min(1).max(65535).optional(),
|
|
30
|
+
publicUrl: OriginUrlSchema.nullable().optional(),
|
|
31
|
+
channel: z.enum(["stable", "beta"]).optional()
|
|
32
|
+
}).strict();
|
|
33
|
+
const LogsTailParamsSchema = z.object({ lines: z.int().min(1).max(500).optional() }).strict();
|
|
34
|
+
const AuditTailParamsSchema = z.object({ limit: z.int().min(1).max(200).optional() }).strict();
|
|
35
|
+
const ShutdownParamsSchema = z.object({ confirm: z.literal(true) }).strict();
|
|
36
|
+
const PairingListParamsSchema = z.object({ status: z.enum([
|
|
37
|
+
"pending",
|
|
38
|
+
"approved",
|
|
39
|
+
"denied",
|
|
40
|
+
"expired",
|
|
41
|
+
"enrollment_pending",
|
|
42
|
+
"redeemed"
|
|
43
|
+
]).optional() }).strict();
|
|
44
|
+
const PairingApproveParamsSchema = z.object({
|
|
45
|
+
requestId: z.string().min(1).max(128),
|
|
46
|
+
decision: z.enum(["allow_once", "trust"])
|
|
47
|
+
}).strict();
|
|
48
|
+
const PairingDenyParamsSchema = z.object({ requestId: z.string().min(1).max(128) }).strict();
|
|
49
|
+
const DeviceRevokeParamsSchema = z.object({ deviceId: z.string().min(1).max(128) }).strict();
|
|
50
|
+
const SessionRevokeParamsSchema = z.object({ sessionId: z.string().min(1).max(128) }).strict();
|
|
51
|
+
function errorResponse(id, error) {
|
|
52
|
+
if (error instanceof IpcError) return {
|
|
53
|
+
id,
|
|
54
|
+
ok: false,
|
|
55
|
+
error: {
|
|
56
|
+
code: error.code,
|
|
57
|
+
message: error.message
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
id,
|
|
62
|
+
ok: false,
|
|
63
|
+
error: {
|
|
64
|
+
code: "INTERNAL",
|
|
65
|
+
message: "Internal IPC error"
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function shortHash(dataDir) {
|
|
70
|
+
return createHash("sha256").update(dataDir).digest("hex").slice(0, 16);
|
|
71
|
+
}
|
|
72
|
+
function resolveIpcAddress(dataDir, platform = process.platform, tempRoot = tmpdir()) {
|
|
73
|
+
if (platform === "win32") return {
|
|
74
|
+
path: `\\\\.\\pipe\\larness-${shortHash(dataDir)}`,
|
|
75
|
+
kind: "pipe",
|
|
76
|
+
tempDirectory: null
|
|
77
|
+
};
|
|
78
|
+
const localPath = path.join(dataDir, "ipc", "larness.sock");
|
|
79
|
+
if (Buffer.byteLength(localPath, "utf8") <= 100) return {
|
|
80
|
+
path: localPath,
|
|
81
|
+
kind: "unix",
|
|
82
|
+
tempDirectory: null
|
|
83
|
+
};
|
|
84
|
+
const directory = path.join(tempRoot, `larness-${shortHash(dataDir)}`);
|
|
85
|
+
return {
|
|
86
|
+
path: path.join(directory, "larness.sock"),
|
|
87
|
+
kind: "unix",
|
|
88
|
+
tempDirectory: directory
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function ipcTokenPath(dataDir) {
|
|
92
|
+
return path.join(dataDir, "ipc", "token");
|
|
93
|
+
}
|
|
94
|
+
export { errorResponse as _, DeviceRevokeParamsSchema as a, IpcError as c, PairingApproveParamsSchema as d, PairingDenyParamsSchema as f, ShutdownParamsSchema as g, SessionRevokeParamsSchema as h, DEFAULT_IDLE_TIMEOUT_MS as i, LogsTailParamsSchema as l, RequestEnvelopeSchema as m, resolveIpcAddress as n, HelloParamsSchema as o, PairingListParamsSchema as p, AuditTailParamsSchema as r, InitApplyParamsSchema as s, ipcTokenPath as t, MAX_FRAME_BYTES as u };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { c as IpcError, n as resolveIpcAddress, t as ipcTokenPath } from "./address-BE25lU9-.js";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { connect } from "node:net";
|
|
4
|
+
// src/ipc/client.ts
|
|
5
|
+
var IpcClientError = class extends Error {
|
|
6
|
+
code;
|
|
7
|
+
constructor(code, message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "IpcClientError";
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const DEFAULT_TIMEOUT_MS = 5e3;
|
|
14
|
+
function connectSocket(address, timeoutMs) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const socket = connect(address);
|
|
17
|
+
const timer = setTimeout(() => {
|
|
18
|
+
socket.destroy();
|
|
19
|
+
reject(new IpcClientError("TIMEOUT", "timed out connecting to the IPC socket"));
|
|
20
|
+
}, timeoutMs);
|
|
21
|
+
socket.once("connect", () => {
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
socket.removeAllListeners("error");
|
|
24
|
+
resolve(socket);
|
|
25
|
+
});
|
|
26
|
+
socket.once("error", (error) => {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
reject(error);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async function connectIpc(options) {
|
|
33
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
34
|
+
const token = (await readFile(ipcTokenPath(options.dataDir), "utf8")).trim();
|
|
35
|
+
const socket = await connectSocket(resolveIpcAddress(options.dataDir, options.platform).path, timeoutMs);
|
|
36
|
+
const pending = /* @__PURE__ */ new Map();
|
|
37
|
+
let buffer = "";
|
|
38
|
+
let nextId = 1;
|
|
39
|
+
let closed = false;
|
|
40
|
+
const rejectAll = (error) => {
|
|
41
|
+
for (const request of pending.values()) {
|
|
42
|
+
clearTimeout(request.timer);
|
|
43
|
+
request.reject(error);
|
|
44
|
+
}
|
|
45
|
+
pending.clear();
|
|
46
|
+
};
|
|
47
|
+
socket.setEncoding("utf8");
|
|
48
|
+
socket.on("data", (chunk) => {
|
|
49
|
+
buffer += chunk;
|
|
50
|
+
let newline = buffer.indexOf("\n");
|
|
51
|
+
while (newline >= 0) {
|
|
52
|
+
const line = buffer.slice(0, newline).trim();
|
|
53
|
+
buffer = buffer.slice(newline + 1);
|
|
54
|
+
newline = buffer.indexOf("\n");
|
|
55
|
+
if (line.length === 0) continue;
|
|
56
|
+
let message;
|
|
57
|
+
try {
|
|
58
|
+
message = JSON.parse(line);
|
|
59
|
+
} catch {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (!("id" in message)) continue;
|
|
63
|
+
const request = pending.get(message.id);
|
|
64
|
+
if (request === void 0) continue;
|
|
65
|
+
pending.delete(message.id);
|
|
66
|
+
clearTimeout(request.timer);
|
|
67
|
+
if (message.ok) request.resolve(message.result);
|
|
68
|
+
else request.reject(new IpcError(message.error.code, message.error.message));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
socket.on("error", () => socket.destroy());
|
|
72
|
+
socket.on("close", () => {
|
|
73
|
+
closed = true;
|
|
74
|
+
rejectAll(new IpcClientError("CONNECTION_CLOSED", "IPC connection closed"));
|
|
75
|
+
});
|
|
76
|
+
const send = (method, params, requestTimeoutMs) => {
|
|
77
|
+
if (closed) return Promise.reject(new IpcClientError("CONNECTION_CLOSED", "IPC connection closed"));
|
|
78
|
+
const id = String(nextId++);
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
const timer = setTimeout(() => {
|
|
81
|
+
pending.delete(id);
|
|
82
|
+
reject(new IpcClientError("TIMEOUT", `IPC request ${method} timed out`));
|
|
83
|
+
}, requestTimeoutMs);
|
|
84
|
+
pending.set(id, {
|
|
85
|
+
resolve,
|
|
86
|
+
reject,
|
|
87
|
+
timer
|
|
88
|
+
});
|
|
89
|
+
socket.write(`${JSON.stringify({
|
|
90
|
+
id,
|
|
91
|
+
method,
|
|
92
|
+
params
|
|
93
|
+
})}\n`);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
if ((await send("hello", {
|
|
97
|
+
token,
|
|
98
|
+
client: options.client ?? "status",
|
|
99
|
+
pid: process.pid
|
|
100
|
+
}, timeoutMs).catch((error) => {
|
|
101
|
+
socket.destroy();
|
|
102
|
+
throw error;
|
|
103
|
+
})).protocolVersion !== 1) {
|
|
104
|
+
socket.destroy();
|
|
105
|
+
throw new IpcClientError("PROTOCOL_MISMATCH", "IPC protocol version mismatch");
|
|
106
|
+
}
|
|
107
|
+
const keepAliveTimer = options.keepAliveMs !== void 0 && options.keepAliveMs > 0 ? setInterval(() => {
|
|
108
|
+
send("system.ping", {}, timeoutMs).catch(() => void 0);
|
|
109
|
+
}, options.keepAliveMs) : null;
|
|
110
|
+
keepAliveTimer?.unref();
|
|
111
|
+
return {
|
|
112
|
+
request: (method, params, requestTimeoutMs = timeoutMs) => send(method, params ?? {}, requestTimeoutMs),
|
|
113
|
+
close: () => {
|
|
114
|
+
closed = true;
|
|
115
|
+
if (keepAliveTimer !== null) clearInterval(keepAliveTimer);
|
|
116
|
+
socket.destroy();
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
export { connectIpc as n, IpcClientError as t };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { c as loadConfig, d as expectedMigrationCount, h as SUPPORTED_NODE_RANGE, i as inspectDatabase, m as SERVER_VERSION, r as resolveDataDir, t as DATA_SUBDIRS } from "./paths-BHryFHwq.js";
|
|
2
|
+
import { n as inspectInstanceLock } from "./lock-DyEoZgG_.js";
|
|
3
|
+
import { constants } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { access, stat } from "node:fs/promises";
|
|
6
|
+
import { createServer } from "node:net";
|
|
7
|
+
import { satisfies } from "semver";
|
|
8
|
+
// src/doctor.ts
|
|
9
|
+
function checkPort(host, port) {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
const server = createServer();
|
|
12
|
+
server.once("error", (error) => {
|
|
13
|
+
resolve({
|
|
14
|
+
ok: false,
|
|
15
|
+
detail: `unavailable: ${error.code ?? error.message}`
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
server.listen({
|
|
19
|
+
host,
|
|
20
|
+
port,
|
|
21
|
+
exclusive: true
|
|
22
|
+
}, () => {
|
|
23
|
+
server.close(() => resolve({
|
|
24
|
+
ok: true,
|
|
25
|
+
detail: `available on ${host}:${port}`
|
|
26
|
+
}));
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function runDoctor(options = {}) {
|
|
31
|
+
const env = options.env ?? process.env;
|
|
32
|
+
const dataDir = options.dataDir ?? resolveDataDir(env);
|
|
33
|
+
const checks = [];
|
|
34
|
+
const add = (id, label, status, detail) => {
|
|
35
|
+
checks.push({
|
|
36
|
+
id,
|
|
37
|
+
label,
|
|
38
|
+
status,
|
|
39
|
+
detail
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
add("node", `Node.js ${SUPPORTED_NODE_RANGE}`, satisfies(process.versions.node, SUPPORTED_NODE_RANGE) ? "ok" : "fail", process.versions.node);
|
|
43
|
+
let dataInfo = null;
|
|
44
|
+
try {
|
|
45
|
+
dataInfo = await stat(dataDir);
|
|
46
|
+
} catch {
|
|
47
|
+
dataInfo = null;
|
|
48
|
+
}
|
|
49
|
+
if (dataInfo === null || !dataInfo.isDirectory()) {
|
|
50
|
+
add("data-dir", "数据目录", "fail", `missing or not a directory: ${dataDir}`);
|
|
51
|
+
add("data-dir-permissions", "数据目录权限", "skip", "data directory unavailable");
|
|
52
|
+
add("data-dir-subdirs", "数据子目录", "skip", "data directory unavailable");
|
|
53
|
+
} else {
|
|
54
|
+
add("data-dir", "数据目录", "ok", dataDir);
|
|
55
|
+
if (process.platform === "win32") add("data-dir-permissions", "数据目录权限", "skip", "POSIX permissions not enforced on Windows");
|
|
56
|
+
else {
|
|
57
|
+
const mode = dataInfo.mode & 511;
|
|
58
|
+
add("data-dir-permissions", "数据目录权限", mode & 63 ? "fail" : "ok", `mode ${mode.toString(8).padStart(4, "0")} (expected 0700)`);
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
await access(dataDir, constants.W_OK);
|
|
62
|
+
} catch {
|
|
63
|
+
add("data-dir-writable", "数据目录可写", "fail", "directory is not writable");
|
|
64
|
+
}
|
|
65
|
+
const missing = [];
|
|
66
|
+
for (const name of DATA_SUBDIRS) try {
|
|
67
|
+
if (!(await stat(path.join(dataDir, name))).isDirectory()) missing.push(name);
|
|
68
|
+
} catch {
|
|
69
|
+
missing.push(name);
|
|
70
|
+
}
|
|
71
|
+
add("data-dir-subdirs", "数据子目录", missing.length === 0 ? "ok" : "warn", missing.length === 0 ? DATA_SUBDIRS.join(", ") : `missing: ${missing.join(", ")}`);
|
|
72
|
+
}
|
|
73
|
+
let loaded = null;
|
|
74
|
+
try {
|
|
75
|
+
loaded = await loadConfig({
|
|
76
|
+
dataDir,
|
|
77
|
+
env
|
|
78
|
+
});
|
|
79
|
+
add("config", "config.json", "ok", loaded.source === "file" ? loaded.path : "not initialized; defaults in use");
|
|
80
|
+
} catch (error) {
|
|
81
|
+
add("config", "config.json", "fail", error instanceof Error ? error.message : String(error));
|
|
82
|
+
}
|
|
83
|
+
if (loaded?.source === "file" && process.platform !== "win32") try {
|
|
84
|
+
const mode = (await stat(loaded.path)).mode & 511;
|
|
85
|
+
add("config-permissions", "配置文件权限", mode & 63 ? "fail" : "ok", `mode ${mode.toString(8).padStart(4, "0")} (expected 0600)`);
|
|
86
|
+
} catch {
|
|
87
|
+
add("config-permissions", "配置文件权限", "warn", "cannot stat config.json");
|
|
88
|
+
}
|
|
89
|
+
if (loaded === null) {
|
|
90
|
+
add("https", "HTTPS / publicUrl", "skip", "config invalid");
|
|
91
|
+
add("webauthn", "WebAuthn canonical origin", "skip", "config invalid");
|
|
92
|
+
add("port", "监听端口", "skip", "config invalid");
|
|
93
|
+
} else {
|
|
94
|
+
const { publicUrl } = loaded.config.server;
|
|
95
|
+
const httpsRequired = loaded.config.auth.requireHttpsForRemote;
|
|
96
|
+
if (publicUrl === null) add("https", "HTTPS / publicUrl", "warn", "no publicUrl; local-only http://localhost origin");
|
|
97
|
+
else {
|
|
98
|
+
const url = new URL(publicUrl);
|
|
99
|
+
const remoteHttp = url.protocol === "http:" && url.hostname !== "localhost";
|
|
100
|
+
add("https", "HTTPS / publicUrl", remoteHttp && httpsRequired ? "fail" : "ok", remoteHttp ? `${publicUrl} is plain http; remote access must use https` : `${publicUrl} (${url.protocol.slice(0, -1)})`);
|
|
101
|
+
}
|
|
102
|
+
add("webauthn", "WebAuthn canonical origin", loaded.webAuthn.enabled ? "ok" : "warn", loaded.webAuthn.enabled ? `origin ${loaded.webAuthn.origin}, rpId ${loaded.webAuthn.rpId}` : `passkeys disabled: ${loaded.webAuthn.reason}`);
|
|
103
|
+
const lock = await inspectInstanceLock(dataDir);
|
|
104
|
+
if (lock?.alive) add("port", "监听端口", "ok", `served by running instance (pid ${lock.record?.pid})`);
|
|
105
|
+
else {
|
|
106
|
+
const availability = await checkPort(loaded.config.server.host, loaded.config.server.port);
|
|
107
|
+
add("port", "监听端口", availability.ok ? "ok" : "fail", availability.detail);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const database = inspectDatabase(path.join(dataDir, "larness.db"));
|
|
111
|
+
if (database === null) {
|
|
112
|
+
add("database", "SQLite", "warn", "not initialized; start the server to run migrations");
|
|
113
|
+
add("migrations", "数据库迁移", "warn", "no database yet");
|
|
114
|
+
} else {
|
|
115
|
+
add("database", "SQLite", database.ok ? "ok" : "fail", `${database.detail} (schema version ${database.schemaVersion})`);
|
|
116
|
+
const expected = expectedMigrationCount();
|
|
117
|
+
const pending = Math.max(0, expected - database.schemaVersion);
|
|
118
|
+
add("migrations", "数据库迁移", pending === 0 ? "ok" : "fail", pending === 0 ? `applied ${database.schemaVersion} of ${expected}` : `${pending} pending of ${expected}`);
|
|
119
|
+
}
|
|
120
|
+
add("clock", "时钟偏移", "skip", "requires a trusted time reference (not implemented)");
|
|
121
|
+
return {
|
|
122
|
+
version: SERVER_VERSION,
|
|
123
|
+
dataDir,
|
|
124
|
+
checks
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export { runDoctor as t };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as runDoctor } from "./doctor-ClvbJZvj.js";
|
|
2
|
+
// src/cli/doctor.ts
|
|
3
|
+
try {
|
|
4
|
+
const report = await runDoctor();
|
|
5
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
6
|
+
if (report.checks.some((check) => check.status === "fail")) process.exitCode = 1;
|
|
7
|
+
} catch (error) {
|
|
8
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9
|
+
process.stderr.write(`[larness] doctor failed: ${message}\n`);
|
|
10
|
+
process.exitCode = 1;
|
|
11
|
+
}
|
|
12
|
+
export {};
|