larness 0.4.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/app.js +22 -105
- package/apps/server/dist/{address-BDs0FfMq.js → address-D0ZG5qR4.js} +5 -2
- package/apps/server/dist/args-CrKTPT06.js +92 -0
- package/apps/server/dist/cli.js +340 -0
- package/apps/server/dist/{client-D88ULjn9.js → client-D_Ni3Zpx.js} +21 -1
- package/apps/server/dist/code-B2JBoV4x.js +24 -0
- package/apps/server/dist/{doctor-dwTQiTef.js → doctor-CE6cONuz.js} +3 -2
- package/apps/server/dist/doctor-sPRlI92N.js +1 -0
- package/apps/server/dist/doctor.js +1 -1
- package/apps/server/dist/index.js +724 -126
- package/apps/server/dist/{paths-DUfwiH2X.js → inspect-XgAc84F9.js} +106 -87
- package/apps/server/dist/lifecycle-C3KV3-Ax.js +263 -0
- package/apps/server/dist/log-files-CFOaEy6O.js +26 -0
- package/apps/server/dist/{managed-Br7VqQiP.js → managed-Cw3MVilO.js} +221 -71
- package/apps/server/dist/paths-BhVn34MT.js +77 -0
- package/apps/server/dist/{status-D2oSIMoj.js → status-CV_zWfs6.js} +16 -3
- package/apps/server/dist/status.js +37 -9
- package/apps/server/dist/supervisor-IYDKL4iU.js +297 -0
- package/apps/server/dist/tui.js +167 -333
- package/apps/server/dist/version-ui_X8H2k.js +13 -0
- package/apps/server/drizzle/0001_auth.sql +109 -109
- package/apps/server/drizzle/0002_projects.sql +12 -12
- package/apps/server/drizzle/0003_workspace.sql +80 -80
- package/apps/server/drizzle/0004_models.sql +30 -30
- package/apps/server/drizzle/0005_resources.sql +54 -54
- package/apps/server/drizzle/0006_commands.sql +23 -23
- package/apps/server/drizzle/0007_terminals.sql +41 -41
- package/apps/server/drizzle/0008_resource_actions.sql +23 -23
- package/apps/server/drizzle/0010_services.sql +31 -31
- package/apps/web/dist/assets/{FileEditor-JaazRNUl.js → FileEditor-DnQa6Owc.js} +1 -1
- package/apps/web/dist/assets/{FileViewer-DzJpg82J.js → FileViewer-DKlF-CWF.js} +1 -1
- package/apps/web/dist/assets/{cssMode-B8mOf4OC.js → cssMode-C9KmpsHc.js} +1 -1
- package/apps/web/dist/assets/{editor.api-BQ-DCb9F.js → editor.api-BwfHyHQ6.js} +1 -1
- package/apps/web/dist/assets/{freemarker2-C1ckA1My.js → freemarker2-D41RlIQ5.js} +1 -1
- package/apps/web/dist/assets/{handlebars-suElsFdc.js → handlebars-D-7R6ic0.js} +1 -1
- package/apps/web/dist/assets/{html-CvWl95vU.js → html-CUME4rt-.js} +1 -1
- package/apps/web/dist/assets/{htmlMode-CrdRQhj8.js → htmlMode-8w7WLhnL.js} +1 -1
- package/apps/web/dist/assets/{index-C6uOTgh6.js → index-BOS3UrP1.js} +2 -2
- package/apps/web/dist/assets/{javascript-DmE3KPeg.js → javascript-_3pdDG34.js} +1 -1
- package/apps/web/dist/assets/{jsonMode-TuNjADgG.js → jsonMode-DiqocFCf.js} +1 -1
- package/apps/web/dist/assets/{liquid-C_Ceyr5s.js → liquid-j0FoiTXN.js} +1 -1
- package/apps/web/dist/assets/{lspLanguageFeatures-DZfo74cL.js → lspLanguageFeatures-Zj7K2sG4.js} +1 -1
- package/apps/web/dist/assets/main-DZIruO5x.js +157 -0
- package/apps/web/dist/assets/main-gq3n_vn8.css +1 -0
- package/apps/web/dist/assets/{mdx-D8eqTMYQ.js → mdx-CGQ8Cw6J.js} +1 -1
- package/apps/web/dist/assets/{monaco-BGhTlUO7.js → monaco-CyMA3azg.js} +3 -3
- package/apps/web/dist/assets/{python-Cx6dqJ-u.js → python-BtY34Z9A.js} +1 -1
- package/apps/web/dist/assets/{razor-u7rb64U6.js → razor-CzYHpLv5.js} +1 -1
- package/apps/web/dist/assets/{tsMode-Cu3GDz4d.js → tsMode-GZx3VEv9.js} +1 -1
- package/apps/web/dist/assets/{typescript-H0OSh9BN.js → typescript-CAfvuTDQ.js} +1 -1
- package/apps/web/dist/assets/{workers-DJ7JInlW.js → workers-C5BOxOmH.js} +1 -1
- package/apps/web/dist/assets/{xml-C_rrJhqX.js → xml-BGX4mtH7.js} +1 -1
- package/apps/web/dist/assets/{yaml-Cub5doLg.js → yaml-B2AgBtJB.js} +1 -1
- package/apps/web/dist/favicon.svg +4 -4
- package/apps/web/dist/index.html +1 -1
- package/docs/README.md +8 -1
- package/docs/guides/install.md +23 -7
- package/package.json +3 -1
- package/apps/server/dist/lock-DyEoZgG_.js +0 -101
- package/apps/web/dist/assets/main-C3xYrJa1.js +0 -157
- package/apps/web/dist/assets/main-ptChOROf.css +0 -1
package/README.md
CHANGED
|
@@ -6,24 +6,25 @@ Larness 是在自己电脑上运行的 AI 开发工作台。配对浏览器后
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install -g larness
|
|
9
|
-
larness
|
|
9
|
+
larness start
|
|
10
|
+
larness tui
|
|
10
11
|
```
|
|
11
12
|
|
|
12
13
|
使用 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
|
|
|
14
15
|
## 开始使用
|
|
15
16
|
|
|
16
|
-
1.
|
|
17
|
+
1. 执行 `larness start` 启动后台管理面;首次运行用 `larness tui` 完成初始化,打开控制台显示的 Web 地址,默认是 `http://localhost:3210`。
|
|
17
18
|
2. 从浏览器发起配对,在本机控制台处理申请。可以临时授权,也可以通过 Passkey 保存可信凭据。
|
|
18
19
|
3. 在「设置与模型」添加模型 API Key,选择默认工作区或关联本机项目,然后开启对话。
|
|
19
20
|
|
|
20
21
|
## 可以做什么
|
|
21
22
|
|
|
22
|
-
- **开发协作**:使用 DeepSeek、GLM 或兼容端点,查看任务计划、工具执行进度和上下文用量。可以让 Agent
|
|
23
|
+
- **开发协作**:使用 DeepSeek、GLM 或兼容端点,查看任务计划、工具执行进度和上下文用量。可以让 Agent 读写项目文件、运行命令、管理后台开发进程,也可以自己使用终端和 Git 面板。终端与 Git 只面向人工操作,不受 Agent 控制。
|
|
23
24
|
- **本机预览与运维**:打开已登记的开发服务预览。通过项目会话使用 PM2 命令,在服务运维界面查看日志、启动、停止或重启正式服务。
|
|
24
25
|
- **定时运行**:从工作台设置 Cron 或固定间隔任务,运行 JavaScript 脚本或 Agent,查看运行历史。
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
退出控制面板(`q` / Ctrl+C)不会停止服务,在途任务继续运行;需要停止时执行 `larness stop`,PM2 托管的正式服务会继续运行。`larness status` 查看状态,`larness logs` 查看最近日志。命令、项目脚本和定时任务使用 Larness 运行账户的权限,请在可信开发机上使用。
|
|
27
28
|
|
|
28
29
|
## 从源码运行
|
|
29
30
|
|
|
@@ -34,7 +35,7 @@ pnpm install
|
|
|
34
35
|
pnpm dev
|
|
35
36
|
```
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
构建后用 `larness start` 启动打包形态,`larness tui` 打开控制面板;`pnpm dev` 保持前台开发入口(Vite + 源码 Server + TUI,退出即停止)。
|
|
38
39
|
|
|
39
40
|
## 许可证
|
|
40
41
|
|
package/app.js
CHANGED
|
@@ -1,122 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawnSync } from "node:child_process";
|
|
3
|
-
import { existsSync
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
7
|
|
|
8
8
|
const root = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const distEntry = path.join(root, "apps", "server", "dist", "cli.js");
|
|
10
|
+
const sourceEntry = path.join(root, "apps", "server", "src", "cli", "main.ts");
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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.
|
|
12
|
+
if (existsSync(distEntry)) {
|
|
13
|
+
await import(pathToFileURL(distEntry).href);
|
|
14
|
+
} else if (existsSync(sourceEntry)) {
|
|
15
|
+
// Source checkouts without a build still get the same command surface.
|
|
45
16
|
const require = createRequire(path.join(root, "apps", "server", "package.json"));
|
|
46
17
|
const loader = pathToFileURL(require.resolve("tsx/esm")).href;
|
|
47
|
-
const result = spawnSync(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
18
|
+
const result = spawnSync(
|
|
19
|
+
process.execPath,
|
|
20
|
+
["--import", loader, sourceEntry, ...process.argv.slice(2)],
|
|
21
|
+
{
|
|
22
|
+
cwd: root,
|
|
23
|
+
stdio: "inherit",
|
|
24
|
+
env: process.env,
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
|
|
52
28
|
if (result.error) {
|
|
53
|
-
console.error(`[larness] cannot run source entry: ${result.error.message}`);
|
|
29
|
+
console.error(`[larness] cannot run the source entry: ${result.error.message}`);
|
|
54
30
|
console.error("Build first with `pnpm build`, or ensure tsx is installed.");
|
|
55
31
|
process.exitCode = 1;
|
|
56
|
-
|
|
32
|
+
} else {
|
|
33
|
+
process.exitCode = result.status ?? 1;
|
|
57
34
|
}
|
|
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
35
|
} else {
|
|
119
|
-
console.error(
|
|
120
|
-
|
|
36
|
+
console.error("[larness] install is incomplete: apps/server/dist/cli.js is missing.");
|
|
37
|
+
console.error("Reinstall with `npm install -g larness`.");
|
|
121
38
|
process.exitCode = 1;
|
|
122
39
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { An as OriginUrlSchema } from "./inspect-XgAc84F9.js";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { z } from "zod";
|
|
@@ -32,7 +32,10 @@ const InitApplyParamsSchema = z.object({
|
|
|
32
32
|
}).strict();
|
|
33
33
|
const LogsTailParamsSchema = z.object({ lines: z.int().min(1).max(500).optional() }).strict();
|
|
34
34
|
const AuditTailParamsSchema = z.object({ limit: z.int().min(1).max(200).optional() }).strict();
|
|
35
|
-
const ShutdownParamsSchema = z.object({
|
|
35
|
+
const ShutdownParamsSchema = z.object({
|
|
36
|
+
confirm: z.literal(true),
|
|
37
|
+
source: z.enum(["cli", "tui"]).optional()
|
|
38
|
+
}).strict();
|
|
36
39
|
const PairingListParamsSchema = z.object({ status: z.enum([
|
|
37
40
|
"pending",
|
|
38
41
|
"approved",
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// src/cli/args.ts
|
|
2
|
+
var UnknownCommandError = class extends Error {
|
|
3
|
+
command;
|
|
4
|
+
constructor(command) {
|
|
5
|
+
super(`unknown command: ${command}`);
|
|
6
|
+
this.command = command;
|
|
7
|
+
this.name = "UnknownCommandError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var UsageError = class extends Error {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "UsageError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const COMMANDS = /* @__PURE__ */ new Set([
|
|
17
|
+
"start",
|
|
18
|
+
"stop",
|
|
19
|
+
"restart",
|
|
20
|
+
"tui",
|
|
21
|
+
"status",
|
|
22
|
+
"logs",
|
|
23
|
+
"doctor"
|
|
24
|
+
]);
|
|
25
|
+
const DEFAULT_LOG_LINES = 200;
|
|
26
|
+
const MAX_LOG_LINES = 1e3;
|
|
27
|
+
function parseLines(value) {
|
|
28
|
+
if (!/^\d+$/.test(value)) throw new UsageError(`--lines expects an integer between 1 and ${MAX_LOG_LINES}`);
|
|
29
|
+
const lines = Number(value);
|
|
30
|
+
if (lines < 1 || lines > 1e3) throw new UsageError(`--lines expects an integer between 1 and ${MAX_LOG_LINES}`);
|
|
31
|
+
return lines;
|
|
32
|
+
}
|
|
33
|
+
function parseArgs(argv) {
|
|
34
|
+
const [first, ...rest] = argv;
|
|
35
|
+
if (first === void 0 || first === "help" || first === "--help" || first === "-h") {
|
|
36
|
+
if (rest.length > 0) throw new UsageError(`unexpected arguments after help: ${rest.join(" ")}`);
|
|
37
|
+
return {
|
|
38
|
+
name: "help",
|
|
39
|
+
json: false,
|
|
40
|
+
lines: DEFAULT_LOG_LINES,
|
|
41
|
+
daemon: false,
|
|
42
|
+
follow: false
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (first === "--version" || first === "-v") {
|
|
46
|
+
if (rest.length > 0) throw new UsageError("--version does not accept arguments");
|
|
47
|
+
return {
|
|
48
|
+
name: "version",
|
|
49
|
+
json: false,
|
|
50
|
+
lines: DEFAULT_LOG_LINES,
|
|
51
|
+
daemon: false,
|
|
52
|
+
follow: false
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (!COMMANDS.has(first)) throw new UnknownCommandError(first);
|
|
56
|
+
const command = first;
|
|
57
|
+
const parsed = {
|
|
58
|
+
name: command,
|
|
59
|
+
json: false,
|
|
60
|
+
lines: DEFAULT_LOG_LINES,
|
|
61
|
+
daemon: false,
|
|
62
|
+
follow: false
|
|
63
|
+
};
|
|
64
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
65
|
+
const arg = rest[index] ?? "";
|
|
66
|
+
if (command === "status" && arg === "--json") {
|
|
67
|
+
parsed.json = true;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (command === "logs" && arg === "--daemon") {
|
|
71
|
+
parsed.daemon = true;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (command === "logs" && (arg === "--follow" || arg === "-f")) {
|
|
75
|
+
parsed.follow = true;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (command === "logs" && (arg === "--lines" || arg.startsWith("--lines="))) {
|
|
79
|
+
if (arg === "--lines") {
|
|
80
|
+
const value = rest[index + 1];
|
|
81
|
+
if (value === void 0) throw new UsageError("--lines requires a value");
|
|
82
|
+
parsed.lines = parseLines(value);
|
|
83
|
+
index += 1;
|
|
84
|
+
} else parsed.lines = parseLines(arg.slice(8));
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (arg.startsWith("-")) throw new UsageError(`unknown option for ${command}: ${arg}`);
|
|
88
|
+
throw new UsageError(`unexpected argument for ${command}: ${arg}`);
|
|
89
|
+
}
|
|
90
|
+
return parsed;
|
|
91
|
+
}
|
|
92
|
+
export { UsageError as n, parseArgs as r, UnknownCommandError as t };
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { t as findMainLogFile } from "./log-files-CFOaEy6O.js";
|
|
2
|
+
import { r as resolveDataDir } from "./paths-BhVn34MT.js";
|
|
3
|
+
import { t as SERVER_VERSION } from "./version-ui_X8H2k.js";
|
|
4
|
+
import { n as UsageError, r as parseArgs, t as UnknownCommandError } from "./args-CrKTPT06.js";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { stripVTControlCharacters } from "node:util";
|
|
7
|
+
import { open } from "node:fs/promises";
|
|
8
|
+
// src/cli/format.ts
|
|
9
|
+
const LEVELS = {
|
|
10
|
+
10: "TRACE",
|
|
11
|
+
20: "DEBUG",
|
|
12
|
+
30: "INFO",
|
|
13
|
+
40: "WARN",
|
|
14
|
+
50: "ERROR",
|
|
15
|
+
60: "FATAL"
|
|
16
|
+
};
|
|
17
|
+
function formatDuration(ms) {
|
|
18
|
+
const totalSeconds = Math.max(0, Math.floor(ms / 1e3));
|
|
19
|
+
const days = Math.floor(totalSeconds / 86400);
|
|
20
|
+
const hours = Math.floor(totalSeconds % 86400 / 3600);
|
|
21
|
+
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
22
|
+
const seconds = totalSeconds % 60;
|
|
23
|
+
if (days > 0) return `${days}d ${hours}h`;
|
|
24
|
+
if (hours > 0) return `${hours}h ${minutes}m`;
|
|
25
|
+
if (minutes > 0) return `${minutes}m ${seconds}s`;
|
|
26
|
+
return `${seconds}s`;
|
|
27
|
+
}
|
|
28
|
+
function describeMode(report) {
|
|
29
|
+
if (report.mode === null) return "unknown";
|
|
30
|
+
const dev = report.dev ? "dev" : "packaged";
|
|
31
|
+
return `${report.mode} (${dev})`;
|
|
32
|
+
}
|
|
33
|
+
function formatStatus(report) {
|
|
34
|
+
const lines = [`Larness ${report.version}`];
|
|
35
|
+
if (report.running) {
|
|
36
|
+
const uptime = report.uptimeMs === null ? "" : ` · up ${formatDuration(report.uptimeMs)}`;
|
|
37
|
+
lines.push(`Status running · pid ${report.pid ?? "unknown"}${uptime}`);
|
|
38
|
+
} else lines.push("Status not running");
|
|
39
|
+
const host = report.listen.host === "0.0.0.0" ? "localhost" : report.listen.host;
|
|
40
|
+
const origin = report.publicUrl ?? `http://${host}:${report.listen.port}`;
|
|
41
|
+
lines.push(`Web ${origin}`);
|
|
42
|
+
lines.push(`Data ${report.dataDir}`);
|
|
43
|
+
lines.push(`Mode ${describeMode(report)}`);
|
|
44
|
+
if (report.db === null) lines.push("Database not initialized");
|
|
45
|
+
else lines.push(`Database ${report.db.ok ? "ok" : "error"} · schema ${report.db.schemaVersion}${report.initialized ? "" : " · not initialized"}`);
|
|
46
|
+
if (report.ipc === null) lines.push("IPC unreachable");
|
|
47
|
+
else lines.push(`IPC ok · ${report.ipc.clients} client(s)`);
|
|
48
|
+
lines.push(`Sessions ${report.sessions.online} online · ${report.sessions.pendingPairings} pending pairing(s)`);
|
|
49
|
+
lines.push(`Logs ${report.logPath ?? "none"}`);
|
|
50
|
+
if (report.daemonLogPath !== null) lines.push(` ${report.daemonLogPath}`);
|
|
51
|
+
lines.push(`PM2 ${report.formalServices.note}`);
|
|
52
|
+
for (const warning of report.warnings) lines.push(`! ${warning}`);
|
|
53
|
+
return `${lines.join("\n")}\n`;
|
|
54
|
+
}
|
|
55
|
+
function formatLogLine(line) {
|
|
56
|
+
const cleaned = stripVTControlCharacters(line);
|
|
57
|
+
try {
|
|
58
|
+
const value = JSON.parse(cleaned);
|
|
59
|
+
if (typeof value === "object" && value !== null && "msg" in value) {
|
|
60
|
+
const record = value;
|
|
61
|
+
const level = typeof record.level === "number" ? LEVELS[record.level] ?? String(record.level) : "INFO";
|
|
62
|
+
const time = typeof record.time === "number" ? new Date(record.time).toISOString().slice(11, 23) : "--:--:--.---";
|
|
63
|
+
const message = typeof record.msg === "string" ? record.msg : JSON.stringify(record.msg);
|
|
64
|
+
return `${time} ${level.padEnd(5)} ${message}`;
|
|
65
|
+
}
|
|
66
|
+
} catch {}
|
|
67
|
+
return cleaned;
|
|
68
|
+
}
|
|
69
|
+
// src/cli/help.ts
|
|
70
|
+
function helpText(version) {
|
|
71
|
+
return `Larness ${version}
|
|
72
|
+
|
|
73
|
+
Usage:
|
|
74
|
+
larness start Start the server in the background and wait until ready
|
|
75
|
+
larness stop Stop the background server gracefully (PM2 services keep running)
|
|
76
|
+
larness restart Stop, then start again (not available for pnpm dev instances)
|
|
77
|
+
larness tui Attach the control panel; quitting it leaves the server running
|
|
78
|
+
larness status [--json] Show a readable status summary or the machine-readable report
|
|
79
|
+
larness logs [options] Show recent logs from this data directory
|
|
80
|
+
larness doctor Run local diagnostics (non-zero on failure)
|
|
81
|
+
larness --version Print the version
|
|
82
|
+
larness --help Show this help
|
|
83
|
+
|
|
84
|
+
Log options:
|
|
85
|
+
--lines <1-1000> Number of lines to show (default 200)
|
|
86
|
+
--daemon Read the background stdout/stderr log instead
|
|
87
|
+
--follow, -f Keep printing new lines until Ctrl+C
|
|
88
|
+
|
|
89
|
+
Exit codes:
|
|
90
|
+
0 success 1 failure 2 usage error 3 not running / no logs
|
|
91
|
+
|
|
92
|
+
Environment:
|
|
93
|
+
LARNESS_DATA_DIR, LARNESS_HOST, LARNESS_PORT, LARNESS_PUBLIC_URL,
|
|
94
|
+
LARNESS_LOG_LEVEL, LARNESS_WEB_DIST
|
|
95
|
+
|
|
96
|
+
pnpm dev keeps the foreground Vite + source setup; quitting it stops that instance.
|
|
97
|
+
larness stop only stops the management server, never PM2 services or deployments.`;
|
|
98
|
+
}
|
|
99
|
+
// src/cli/logs.ts
|
|
100
|
+
const LOG_TAIL_LIMIT_BYTES = 1048576;
|
|
101
|
+
const FOLLOW_INTERVAL_MS = 150;
|
|
102
|
+
function logFilePath(dataDir, source) {
|
|
103
|
+
return path.join(dataDir, "logs", source === "daemon" ? "daemon.log" : "larness.log");
|
|
104
|
+
}
|
|
105
|
+
function splitLines(text) {
|
|
106
|
+
const lines = text.split(/\r?\n/);
|
|
107
|
+
if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
|
|
108
|
+
return lines;
|
|
109
|
+
}
|
|
110
|
+
async function readLogTail(file, options) {
|
|
111
|
+
let handle;
|
|
112
|
+
try {
|
|
113
|
+
handle = await open(file, "r");
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (error.code === "ENOENT") return null;
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const info = await handle.stat();
|
|
120
|
+
const maxBytes = options.maxBytes ?? 1048576;
|
|
121
|
+
const start = Math.max(0, info.size - maxBytes);
|
|
122
|
+
const length = info.size - start;
|
|
123
|
+
if (length === 0) return {
|
|
124
|
+
lines: [],
|
|
125
|
+
truncated: false
|
|
126
|
+
};
|
|
127
|
+
const buffer = Buffer.alloc(length);
|
|
128
|
+
await handle.read(buffer, 0, length, start);
|
|
129
|
+
let text = buffer.toString("utf8");
|
|
130
|
+
if (start > 0) {
|
|
131
|
+
const newline = text.indexOf("\n");
|
|
132
|
+
text = newline === -1 ? "" : text.slice(newline + 1);
|
|
133
|
+
}
|
|
134
|
+
const all = splitLines(text);
|
|
135
|
+
const truncated = start > 0 || all.length > options.lines;
|
|
136
|
+
return {
|
|
137
|
+
lines: all.length > options.lines ? all.slice(-options.lines) : all,
|
|
138
|
+
truncated
|
|
139
|
+
};
|
|
140
|
+
} finally {
|
|
141
|
+
await handle.close();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function readFrom(file, offset, maxBytes) {
|
|
145
|
+
let handle;
|
|
146
|
+
try {
|
|
147
|
+
handle = await open(file, "r");
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (error.code === "ENOENT") return null;
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const info = await handle.stat();
|
|
154
|
+
if (info.size < offset) return {
|
|
155
|
+
text: "",
|
|
156
|
+
next: info.size
|
|
157
|
+
};
|
|
158
|
+
if (info.size === offset) return {
|
|
159
|
+
text: "",
|
|
160
|
+
next: offset
|
|
161
|
+
};
|
|
162
|
+
const length = Math.min(info.size - offset, maxBytes);
|
|
163
|
+
const buffer = Buffer.alloc(length);
|
|
164
|
+
await handle.read(buffer, 0, length, offset);
|
|
165
|
+
return {
|
|
166
|
+
text: buffer.toString("utf8"),
|
|
167
|
+
next: offset + length
|
|
168
|
+
};
|
|
169
|
+
} finally {
|
|
170
|
+
await handle.close();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function followLog(file, onLine, options) {
|
|
174
|
+
let offset;
|
|
175
|
+
try {
|
|
176
|
+
const handle = await open(file, "r");
|
|
177
|
+
try {
|
|
178
|
+
offset = (await handle.stat()).size;
|
|
179
|
+
} finally {
|
|
180
|
+
await handle.close();
|
|
181
|
+
}
|
|
182
|
+
} catch (error) {
|
|
183
|
+
if (error.code === "ENOENT") return "missing";
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
let pending = "";
|
|
187
|
+
const interval = options.intervalMs ?? FOLLOW_INTERVAL_MS;
|
|
188
|
+
return new Promise((resolve) => {
|
|
189
|
+
let finished = false;
|
|
190
|
+
const finish = (reason) => {
|
|
191
|
+
if (finished) return;
|
|
192
|
+
finished = true;
|
|
193
|
+
clearInterval(timer);
|
|
194
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
195
|
+
resolve(reason);
|
|
196
|
+
};
|
|
197
|
+
const onAbort = () => finish("aborted");
|
|
198
|
+
const timer = setInterval(() => {
|
|
199
|
+
(async () => {
|
|
200
|
+
try {
|
|
201
|
+
const chunk = await readFrom(file, offset, LOG_TAIL_LIMIT_BYTES);
|
|
202
|
+
if (chunk === null) {
|
|
203
|
+
finish("missing");
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (chunk.next < offset) {
|
|
207
|
+
finish("replaced");
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (chunk.text.length === 0) return;
|
|
211
|
+
offset = chunk.next;
|
|
212
|
+
pending += chunk.text;
|
|
213
|
+
const lines = pending.split(/\r?\n/);
|
|
214
|
+
pending = lines.pop() ?? "";
|
|
215
|
+
for (const line of lines) onLine(line);
|
|
216
|
+
} catch {
|
|
217
|
+
finish("missing");
|
|
218
|
+
}
|
|
219
|
+
})();
|
|
220
|
+
}, interval);
|
|
221
|
+
if (options.signal.aborted) {
|
|
222
|
+
finish("aborted");
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
// src/cli/program.ts
|
|
229
|
+
function safeMessage(error) {
|
|
230
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
231
|
+
return stripVTControlCharacters(message);
|
|
232
|
+
}
|
|
233
|
+
async function runStatus(parsed, io) {
|
|
234
|
+
const { readStatus } = await import("./status.js");
|
|
235
|
+
const report = await readStatus({
|
|
236
|
+
dataDir: resolveDataDir(io.env),
|
|
237
|
+
env: io.env
|
|
238
|
+
});
|
|
239
|
+
if (parsed.json) io.stdout(`${JSON.stringify(report, null, 2)}\n`);
|
|
240
|
+
else io.stdout(formatStatus(report));
|
|
241
|
+
return report.running ? 0 : 3;
|
|
242
|
+
}
|
|
243
|
+
async function runLogs(parsed, io) {
|
|
244
|
+
const dataDir = resolveDataDir(io.env);
|
|
245
|
+
const source = parsed.daemon ? "daemon" : "main";
|
|
246
|
+
const file = parsed.daemon ? logFilePath(dataDir, "daemon") : await findMainLogFile(dataDir);
|
|
247
|
+
if (file === null) {
|
|
248
|
+
io.stderr(`[larness] no main log under ${path.join(dataDir, "logs")}\n`);
|
|
249
|
+
return 3;
|
|
250
|
+
}
|
|
251
|
+
const tail = await readLogTail(file, { lines: parsed.lines });
|
|
252
|
+
if (tail === null) {
|
|
253
|
+
io.stderr(`[larness] no ${source === "daemon" ? "background" : "main"} log at ${file}\n`);
|
|
254
|
+
return 3;
|
|
255
|
+
}
|
|
256
|
+
if (tail.truncated) io.stderr(`[larness] showing the last ${parsed.lines} line(s) of ${file}\n`);
|
|
257
|
+
for (const line of tail.lines) io.stdout(`${formatLogLine(line)}\n`);
|
|
258
|
+
if (!parsed.follow) return 0;
|
|
259
|
+
const abort = new AbortController();
|
|
260
|
+
const onInterrupt = () => abort.abort();
|
|
261
|
+
process.once("SIGINT", onInterrupt);
|
|
262
|
+
try {
|
|
263
|
+
const end = await followLog(file, (line) => io.stdout(`${formatLogLine(line)}\n`), { signal: abort.signal });
|
|
264
|
+
if (end === "missing") {
|
|
265
|
+
io.stderr(`[larness] ${file} disappeared; stopped following.\n`);
|
|
266
|
+
return 1;
|
|
267
|
+
}
|
|
268
|
+
if (end === "replaced") {
|
|
269
|
+
io.stderr(`[larness] ${file} was truncated or replaced; stopped following.\n`);
|
|
270
|
+
return 1;
|
|
271
|
+
}
|
|
272
|
+
return 0;
|
|
273
|
+
} finally {
|
|
274
|
+
process.off("SIGINT", onInterrupt);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async function runDoctorCommand(io) {
|
|
278
|
+
const { runDoctor } = await import("./doctor-sPRlI92N.js");
|
|
279
|
+
const report = await runDoctor({ env: io.env });
|
|
280
|
+
io.stdout(`${JSON.stringify(report, null, 2)}\n`);
|
|
281
|
+
return report.checks.some((check) => check.status === "fail") ? 1 : 0;
|
|
282
|
+
}
|
|
283
|
+
async function runCli(argv, io) {
|
|
284
|
+
let parsed;
|
|
285
|
+
try {
|
|
286
|
+
parsed = parseArgs(argv);
|
|
287
|
+
} catch (error) {
|
|
288
|
+
if (error instanceof UnknownCommandError) {
|
|
289
|
+
io.stderr(`[larness] ${safeMessage(error)}\n`);
|
|
290
|
+
io.stderr(`${helpText(SERVER_VERSION)}\n`);
|
|
291
|
+
return 1;
|
|
292
|
+
}
|
|
293
|
+
if (error instanceof UsageError) {
|
|
294
|
+
io.stderr(`[larness] ${safeMessage(error)}\n`);
|
|
295
|
+
io.stderr("[larness] run `larness --help` for usage.\n");
|
|
296
|
+
return 2;
|
|
297
|
+
}
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
try {
|
|
301
|
+
switch (parsed.name) {
|
|
302
|
+
case "help":
|
|
303
|
+
io.stdout(`${helpText(SERVER_VERSION)}\n`);
|
|
304
|
+
return 0;
|
|
305
|
+
case "version":
|
|
306
|
+
io.stdout(`${SERVER_VERSION}\n`);
|
|
307
|
+
return 0;
|
|
308
|
+
case "status": return await runStatus(parsed, io);
|
|
309
|
+
case "logs": return await runLogs(parsed, io);
|
|
310
|
+
case "doctor": return await runDoctorCommand(io);
|
|
311
|
+
case "start": {
|
|
312
|
+
const { startCommand } = await import("./lifecycle-C3KV3-Ax.js");
|
|
313
|
+
return await startCommand(io);
|
|
314
|
+
}
|
|
315
|
+
case "stop": {
|
|
316
|
+
const { stopCommand } = await import("./lifecycle-C3KV3-Ax.js");
|
|
317
|
+
return await stopCommand(io);
|
|
318
|
+
}
|
|
319
|
+
case "restart": {
|
|
320
|
+
const { restartCommand } = await import("./lifecycle-C3KV3-Ax.js");
|
|
321
|
+
return await restartCommand(io);
|
|
322
|
+
}
|
|
323
|
+
case "tui": {
|
|
324
|
+
const { tuiCommand } = await import("./lifecycle-C3KV3-Ax.js");
|
|
325
|
+
return await tuiCommand(io);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
} catch (error) {
|
|
329
|
+
io.stderr(`[larness] ${parsed.name} failed: ${safeMessage(error)}\n`);
|
|
330
|
+
return 1;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
// src/cli/main.ts
|
|
334
|
+
const code = await runCli(process.argv.slice(2), {
|
|
335
|
+
stdout: (text) => process.stdout.write(text),
|
|
336
|
+
stderr: (text) => process.stderr.write(text),
|
|
337
|
+
env: process.env
|
|
338
|
+
});
|
|
339
|
+
process.exitCode = code;
|
|
340
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as IpcError, n as resolveIpcAddress, t as ipcTokenPath } from "./address-
|
|
1
|
+
import { c as IpcError, n as resolveIpcAddress, t as ipcTokenPath } from "./address-D0ZG5qR4.js";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { connect } from "node:net";
|
|
4
4
|
// src/ipc/client.ts
|
|
@@ -34,9 +34,19 @@ async function connectIpc(options) {
|
|
|
34
34
|
const token = (await readFile(ipcTokenPath(options.dataDir), "utf8")).trim();
|
|
35
35
|
const socket = await connectSocket(resolveIpcAddress(options.dataDir, options.platform).path, timeoutMs);
|
|
36
36
|
const pending = /* @__PURE__ */ new Map();
|
|
37
|
+
const closeHandlers = /* @__PURE__ */ new Set();
|
|
37
38
|
let buffer = "";
|
|
38
39
|
let nextId = 1;
|
|
39
40
|
let closed = false;
|
|
41
|
+
let closedNotified = false;
|
|
42
|
+
const notifyClosed = () => {
|
|
43
|
+
if (closedNotified) return;
|
|
44
|
+
closedNotified = true;
|
|
45
|
+
for (const handler of closeHandlers) try {
|
|
46
|
+
handler();
|
|
47
|
+
} catch {}
|
|
48
|
+
closeHandlers.clear();
|
|
49
|
+
};
|
|
40
50
|
const rejectAll = (error) => {
|
|
41
51
|
for (const request of pending.values()) {
|
|
42
52
|
clearTimeout(request.timer);
|
|
@@ -72,6 +82,7 @@ async function connectIpc(options) {
|
|
|
72
82
|
socket.on("close", () => {
|
|
73
83
|
closed = true;
|
|
74
84
|
rejectAll(new IpcClientError("CONNECTION_CLOSED", "IPC connection closed"));
|
|
85
|
+
notifyClosed();
|
|
75
86
|
});
|
|
76
87
|
const send = (method, params, requestTimeoutMs) => {
|
|
77
88
|
if (closed) return Promise.reject(new IpcClientError("CONNECTION_CLOSED", "IPC connection closed"));
|
|
@@ -110,10 +121,19 @@ async function connectIpc(options) {
|
|
|
110
121
|
keepAliveTimer?.unref();
|
|
111
122
|
return {
|
|
112
123
|
request: (method, params, requestTimeoutMs = timeoutMs) => send(method, params ?? {}, requestTimeoutMs),
|
|
124
|
+
onClose: (handler) => {
|
|
125
|
+
if (closedNotified || closed) {
|
|
126
|
+
handler();
|
|
127
|
+
return () => void 0;
|
|
128
|
+
}
|
|
129
|
+
closeHandlers.add(handler);
|
|
130
|
+
return () => closeHandlers.delete(handler);
|
|
131
|
+
},
|
|
113
132
|
close: () => {
|
|
114
133
|
closed = true;
|
|
115
134
|
if (keepAliveTimer !== null) clearInterval(keepAliveTimer);
|
|
116
135
|
socket.destroy();
|
|
136
|
+
notifyClosed();
|
|
117
137
|
}
|
|
118
138
|
};
|
|
119
139
|
}
|