lemma-agent 1.0.0 → 1.0.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 +22 -3
- package/bin/lemma.mjs +25 -7
- package/dist/main.js +61 -4
- package/dist/projects.js +282 -0
- package/dist/settings.js +3 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -38,12 +38,17 @@
|
|
|
38
38
|
- **成员准备**:支持 Claude / Codex / Gemini 本机 CLI(需提前各自登录),也支持直接配置 OpenAI / Anthropic 兼容 API 成员(见 [成员使用说明](docs/custom-agents.md))。
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
#
|
|
41
|
+
# 方式一:通过 npm 全局安装(任意项目目录直接敲 lemma 启动)
|
|
42
42
|
npm install -g lemma-agent
|
|
43
43
|
cd your-project && lemma
|
|
44
44
|
|
|
45
|
-
#
|
|
45
|
+
# 若本机默认使用国内镜像且尚未同步新版本,可显式指定官方源安装
|
|
46
|
+
npm install -g lemma-agent --registry=https://registry.npmjs.org/
|
|
47
|
+
|
|
48
|
+
# 或免安装直接运行 / 查看与直达本机纳管项目
|
|
46
49
|
npx lemma-agent
|
|
50
|
+
lemma projects
|
|
51
|
+
lemma --project=<编号|名称|路径>
|
|
47
52
|
|
|
48
53
|
# 方式二:从源码克隆本地开发(Node 原生 TypeScript 直跑)
|
|
49
54
|
git clone https://github.com/wangchneyu/Lemma.git pi-agent
|
|
@@ -52,7 +57,7 @@ npm install
|
|
|
52
57
|
npm start
|
|
53
58
|
```
|
|
54
59
|
|
|
55
|
-
> 直接运行 `lemma` 或 `npm start` 均默认启动交互终端与本地后台网页(`--no-web` 关闭网页,`--plain` 切换纯文本,`lemma "任务"`
|
|
60
|
+
> 直接运行 `lemma` 或 `npm start` 均默认启动交互终端与本地后台网页(`--no-web` 关闭网页,`--plain` 切换纯文本,`lemma "任务"` 单次运行后退出,`lemma --help` / `lemma --version` 查看说明与版本)。
|
|
56
61
|
|
|
57
62
|
首次使用在终端执行 `/setup` 配置总调度模型与凭据,用 `/agent add` 管理 API 成员;可用 `npm run check`(会产生真实调用)验证各成员连通性。API 密钥经隐藏输入存入本机 `~/.lemma/credentials.json`,配置文件与网页响应仅保留引用。
|
|
58
63
|
|
|
@@ -61,6 +66,7 @@ npm start
|
|
|
61
66
|
| 类别 | 常用命令与快捷键 |
|
|
62
67
|
|---|---|
|
|
63
68
|
| 任务与协作 | `/tasks` `/ready` `/jobs` `/jobs cancel <ID\|all>` `/workflow pause\|resume` `/task inspect\|resume\|supply\|reassign\|cancel` `/goal` |
|
|
69
|
+
| 项目管理与隔离 | `/projects` `/project use <编号\|名\|路径>` `/project init` `/project remove <名称>`(未配局部 `storage` 时运行库集中存 `~/.lemma/projects/`) |
|
|
64
70
|
| 代码隔离与集成 | `/changes` `/diff <ID>` `/apply [ID\|all]`(交互确认)/ `/drop <ID>` `/clean` `/integrate create\|list\|show\|rerun\|repair\|cancel` |
|
|
65
71
|
| 成员与规范 | `/setup` `/agents` `/agent add\|edit\|enable\|disable\|model\|key` `/tool` `/mcp` `/rules [init\|sync]` `/limits edit` |
|
|
66
72
|
| 会话与终端交互 | `/session new\|use\|rename` `/sessions` `/abort [all]` `/continue` `/compact` `/usage` `/web`<br>`Ctrl+K` 会话与只读子对话 · `Ctrl+L` (`/model`) 切换模型 · `Alt+C` (`/tree`) 关系树 · `Ctrl+T` (`/taskgraph`) 原生任务面板 · `Ctrl+N`/`Ctrl+O` 新建/切换会话 · `Ctrl+E` 展开输出 · `Alt+T` 思考块 |
|
|
@@ -120,3 +126,16 @@ npm run bench:chart # 扫描 data/benchmarks/ 刷新 SVG 图表与评测
|
|
|
120
126
|
```
|
|
121
127
|
|
|
122
128
|
详细数据与评测文档:[评测规范](docs/benchmarks/evaluation-spec.md) · [分层编码评测记录](docs/benchmarks/tiered-coding-evaluation.md) · [上下文裁剪记录](docs/benchmarks/initial-context-ablation.md) · [自定义成员说明](docs/custom-agents.md)
|
|
129
|
+
|
|
130
|
+
## 构建与发布(npm · [`lemma-agent`](https://www.npmjs.com/package/lemma-agent))
|
|
131
|
+
|
|
132
|
+
- **打包结构**:[tsconfig.build.json](tsconfig.build.json) 启用 `rewriteRelativeImportExtensions` 将 `src/` 编译为 `dist/*.js`,由 [bin/lemma.mjs](bin/lemma.mjs) 对外暴露全局命令 `lemma`;`package.json` 的 `files` 仅包含 `bin/`、`dist/`、`web/`、`README.md` 与 `package.json`。
|
|
133
|
+
- **发包配置**:`publishConfig.registry` 已固定为 `https://registry.npmjs.org/`(避免误发至只读镜像),发包需账号已启用 2FA(或配置免 2FA 的 Granular Access Token)。
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npm run build # 清理并编译 src/ -> dist/
|
|
137
|
+
npm run prepack # 依次执行 typecheck 与 build
|
|
138
|
+
npm pack --dry-run # 预览待发布压缩包内容
|
|
139
|
+
npm login --registry=https://registry.npmjs.org/
|
|
140
|
+
npm publish # 自动触发 prepack 并发布到 npmjs.org
|
|
141
|
+
```
|
package/bin/lemma.mjs
CHANGED
|
@@ -21,18 +21,36 @@ if (argv.includes("--help") || argv.includes("-h")) {
|
|
|
21
21
|
"Lemma (lemma-agent) — 面向 coding 场景的持久化多 Agent 协同终端与后台工作台",
|
|
22
22
|
"",
|
|
23
23
|
"用法:",
|
|
24
|
-
" lemma
|
|
25
|
-
" lemma \"你的任务\"
|
|
26
|
-
" lemma
|
|
27
|
-
" lemma --
|
|
28
|
-
" lemma --
|
|
29
|
-
" lemma --
|
|
24
|
+
" lemma 在当前项目目录启动 TUI 与本地后台网页 (http://127.0.0.1:8787)",
|
|
25
|
+
" lemma \"你的任务\" 单次运行任务,完成后自动退出",
|
|
26
|
+
" lemma projects 列出本机纳管的全部历史项目与路径",
|
|
27
|
+
" lemma --project=<编号|名|路径> 从任意目录直达已纳管项目并继续上次进度",
|
|
28
|
+
" lemma --plain 使用纯文本 REPL 模式代替 TUI",
|
|
29
|
+
" lemma --no-web 仅运行终端,不启动本地后台网页",
|
|
30
|
+
" lemma --session=<id> 指定/恢复会话 ID",
|
|
31
|
+
" lemma --version / -v 查看版本号",
|
|
30
32
|
"",
|
|
31
|
-
"
|
|
33
|
+
"零污染默认:未在仓库指定 storage 时,会话库与 worktree 自动存放于 ~/.lemma/projects/。",
|
|
34
|
+
"首次使用运行 /setup 配置总调度模型与 API 凭据,或用 /project init 为仓库生成检查模板。",
|
|
32
35
|
].join("\n"));
|
|
33
36
|
process.exit(0);
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
if (argv[0] === "projects" || argv.includes("--projects")) {
|
|
40
|
+
const { ProjectCatalog } = await import("../dist/projects.js");
|
|
41
|
+
const catalog = new ProjectCatalog();
|
|
42
|
+
const list = catalog.list();
|
|
43
|
+
if (!list.length) {
|
|
44
|
+
console.log("暂无历史项目记录;进入任意项目目录直接执行 lemma 即可自动纳管。");
|
|
45
|
+
} else {
|
|
46
|
+
console.log("已纳管项目(通过 lemma --project=<编号|名称> 启动):");
|
|
47
|
+
list.forEach((p, idx) => {
|
|
48
|
+
console.log(` [${idx + 1}] ${p.name} (${p.path})`);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
|
|
36
54
|
const hasPositional = argv.some((a) => !a.startsWith("--"));
|
|
37
55
|
if (!hasPositional && !argv.includes("--tui") && !argv.includes("--plain")) {
|
|
38
56
|
process.argv.push("--tui");
|
package/dist/main.js
CHANGED
|
@@ -33,13 +33,21 @@ import { readyTasks, taskReadiness } from "./task-readiness.js";
|
|
|
33
33
|
import { Integrations, integrationSummary } from "./integrations.js";
|
|
34
34
|
import { listNativeConversations, watchTerminalState } from "./terminal-state.js";
|
|
35
35
|
import { SessionCatalog } from "./sessions.js";
|
|
36
|
+
import { findRepoRoot, initProjectConfig, ProjectCatalog, projectIdForPath, resolveStartupWorkspace } from "./projects.js";
|
|
36
37
|
import { liveDigest, storedDigest } from "./digest.js";
|
|
37
38
|
export async function startMain(overrides) {
|
|
38
39
|
const context = BACKGROUND_CONTEXT;
|
|
39
40
|
const argv = process.argv.slice(2);
|
|
40
41
|
const flags = new Set(argv.filter((a) => a.startsWith("--")));
|
|
41
|
-
const
|
|
42
|
-
const
|
|
42
|
+
const projectArg = argv.find((a) => a.startsWith("--project="))?.slice(10);
|
|
43
|
+
const projectCatalog = new ProjectCatalog();
|
|
44
|
+
const startup = resolveStartupWorkspace({
|
|
45
|
+
envConfigPath: process.env.PI_AGENT_CONFIG,
|
|
46
|
+
projectArg,
|
|
47
|
+
catalog: projectCatalog,
|
|
48
|
+
});
|
|
49
|
+
const configPath = startup.configPath;
|
|
50
|
+
const baseConfig = startup.baseConfig;
|
|
43
51
|
const sessionCatalog = new SessionCatalog(overrides?.config ? overrides.config(baseConfig) : baseConfig);
|
|
44
52
|
let sessionId = argv.find((a) => a.startsWith("--session="))?.slice(10) ?? sessionCatalog.selected();
|
|
45
53
|
if (sessionId !== "default" && !sessionCatalog.list().some((s) => s.id === sessionId))
|
|
@@ -332,6 +340,7 @@ export async function startMain(overrides) {
|
|
|
332
340
|
log(c.cyan(`会话:${sessionId} · ${sessionCatalog.get(sessionId).title}(/sessions 管理与切换)`));
|
|
333
341
|
log(c.cyan(`当前输入 → 总控对话 ${root.id};成员各用独立 session_id(/conversation 查看隔离边界)`));
|
|
334
342
|
log(c.dim(`工作目录:${config.workdir}`));
|
|
343
|
+
log(c.dim(`配置文件:${configPath}`));
|
|
335
344
|
log(c.dim(`会话存储:${config.storage}`));
|
|
336
345
|
log(c.dim("/setup 配置总控 · /agent add 添加成员 · /agents 查看成员 · /help 操作帮助"));
|
|
337
346
|
if (admin)
|
|
@@ -719,11 +728,59 @@ export async function startMain(overrides) {
|
|
|
719
728
|
if (line === "/help") {
|
|
720
729
|
log(MEMBER_HELP);
|
|
721
730
|
log(TASK_HELP);
|
|
722
|
-
log("/fast [成员ID|readonly] <任务> 单跳快路直连 · /sessions 管理会话 · /tasks 分工 · /jobs 后台任务 · /model 选择当前总控模型 · /web 网页 · /exit 退出");
|
|
731
|
+
log("/fast [成员ID|readonly] <任务> 单跳快路直连 · /projects 项目管理 · /project use|init|remove · /sessions 管理会话 · /tasks 分工 · /jobs 后台任务 · /model 选择当前总控模型 · /web 网页 · /exit 退出");
|
|
723
732
|
log("/ready 就绪队列 · /workflow status|pause|resume 协作控制 · Enter 发送 · Ctrl+J 换行 · 滚轮/PgUp/PgDn 翻阅 · Ctrl+Home/End 到顶/最新 · Alt+End 最新 · Ctrl+K 会话 · Alt+C 关系树 · Ctrl+L 模型 · Ctrl+T 任务面板 · Ctrl+E 工具详情 · Alt+T 思考");
|
|
724
733
|
log("/history 补载更早记录 · /thinking 展开/收起思考 · Ctrl+Shift+F 搜索已加载记录;思考仅展示服务实际返回的内容。");
|
|
725
734
|
return true;
|
|
726
735
|
}
|
|
736
|
+
if (/^\/projects?(?:\s|$)/.test(line)) {
|
|
737
|
+
const [, sub = "list", ...rest] = line.split(/\s+/);
|
|
738
|
+
const targetQuery = rest.join(" ").trim();
|
|
739
|
+
if (sub === "list" || !sub || line.trim() === "/projects") {
|
|
740
|
+
const list = projectCatalog.list();
|
|
741
|
+
if (!list.length) {
|
|
742
|
+
log("暂无全局项目记录;在任意项目目录下运行 lemma 即可自动纳管。");
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
list.forEach((p, idx) => {
|
|
746
|
+
const active = (process.platform === "win32" ? p.path.toLowerCase() === resolve(config.workdir).toLowerCase() : p.path === resolve(config.workdir)) ? "●" : "○";
|
|
747
|
+
log(`${active} [${idx + 1}] ${p.name} · ${p.path}`);
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
log("/project use <编号|名称|路径> 切换项目 · /project init 为当前项目生成独立配置(自动侦测栈,零污染运行库) · /project remove <编号|名称>");
|
|
751
|
+
return true;
|
|
752
|
+
}
|
|
753
|
+
if (sub === "init") {
|
|
754
|
+
const force = rest.includes("--force");
|
|
755
|
+
const created = initProjectConfig(config.workdir, { force });
|
|
756
|
+
log(`已生成项目配置文件:${created.path}(自动探测 ${created.checks} 条验收检查,linkDirs=${created.linkDirs.join("、")};运行库继续保留于集中目录,不会污染仓库)`);
|
|
757
|
+
return true;
|
|
758
|
+
}
|
|
759
|
+
if (sub === "remove" || sub === "rm") {
|
|
760
|
+
if (!targetQuery)
|
|
761
|
+
throw new Error("用法:/project remove <编号|名称|路径>");
|
|
762
|
+
const removed = projectCatalog.remove(targetQuery);
|
|
763
|
+
if (!removed)
|
|
764
|
+
throw new Error(`找不到项目记录:${targetQuery}`);
|
|
765
|
+
log(`已从全局项目列表移除 ${removed.name}(${removed.path}),源码未受影响。`);
|
|
766
|
+
return true;
|
|
767
|
+
}
|
|
768
|
+
if (sub === "use" || sub === "switch" || sub === "open") {
|
|
769
|
+
if (!targetQuery)
|
|
770
|
+
throw new Error("用法:/project use <编号|名称|路径>");
|
|
771
|
+
const hit = projectCatalog.resolve(targetQuery);
|
|
772
|
+
const rawPath = hit?.path ?? resolve(config.workdir, targetQuery.replace(/^["']|["']$/g, ""));
|
|
773
|
+
const targetRoot = findRepoRoot(rawPath);
|
|
774
|
+
const id = `proj-${projectIdForPath(targetRoot)}`;
|
|
775
|
+
projectCatalog.touch(targetRoot);
|
|
776
|
+
if (sessionCatalog.list().some((s) => s.id === id))
|
|
777
|
+
await sessionCommand(`/session use ${id}`);
|
|
778
|
+
else
|
|
779
|
+
await sessionCommand(`/session new ${id} "${targetRoot}"`);
|
|
780
|
+
return true;
|
|
781
|
+
}
|
|
782
|
+
throw new Error("用法:/projects | /project use <编号|名称|路径> | /project init [--force] | /project remove <编号|名称>");
|
|
783
|
+
}
|
|
727
784
|
if (/^\/(?:agent|setup|tool|limits|mcp)(?:\s|$)/.test(line)) {
|
|
728
785
|
if (configuring)
|
|
729
786
|
throw new Error("配置正在进行中。");
|
|
@@ -1203,7 +1260,7 @@ export async function startMain(overrides) {
|
|
|
1203
1260
|
if (switchingSession && text !== "/exit" && text !== "/quit")
|
|
1204
1261
|
return log(c.dim("正在切换,命令未执行,请稍后重试。"));
|
|
1205
1262
|
// Task-owned 子对话由原派工管理,只允许查看或返回,不改变它的执行。
|
|
1206
|
-
const readCommand = /^(?:\/help|\/history|\/thinking|\/ready|\/main|\/conversations|\/tree|\/taskgraph|\/conversation|\/id|\/sessions?|\/members|\/tasks|\/goal|\/jobs|\/changes|\/diff|\/usage|\/agents|\/web|\/learn|\/repair|\/exit|\/quit)(?:\s|$)/.test(text) && !/^\/jobs\s+cancel/.test(text);
|
|
1263
|
+
const readCommand = /^(?:\/help|\/history|\/thinking|\/ready|\/main|\/conversations|\/tree|\/taskgraph|\/conversation|\/id|\/projects?|\/sessions?|\/members|\/tasks|\/goal|\/jobs|\/changes|\/diff|\/usage|\/agents|\/web|\/learn|\/repair|\/exit|\/quit)(?:\s|$)/.test(text) && !/^\/jobs\s+cancel/.test(text);
|
|
1207
1264
|
if (readingChild && !readCommand)
|
|
1208
1265
|
return log(c.yellow("子对话为只读查看;请先 /main 返回总控再执行控制命令。"));
|
|
1209
1266
|
const bindsView = /^\/(?:sessions?|conversations|tree|main)(?:\s|$)/.test(text);
|
package/dist/projects.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// 全局项目管理与零污染工作区解析(~/.lemma/projects.json & ~/.lemma/config.json):
|
|
2
|
+
// 1. 当在任意项目目录启动 lemma 且未显式指定局部 storage 时,将 session.sqlite、worktrees 与 ASSIGN.md
|
|
3
|
+
// 集中存放到 ~/.lemma/projects/<slug>-<hash>/,避免污染目标 Git 仓库工作区;
|
|
4
|
+
// 2. 全局配置 ~/.lemma/config.json 与凭据 ~/.lemma/credentials.json 在全部项目间共享;
|
|
5
|
+
// 3. 记录最近打开的项目清单,支持 /projects、/project use|init|remove 及 lemma --project / lemma projects。
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
10
|
+
import { loadConfig, normalizeConfig } from "./config.js";
|
|
11
|
+
export function lemmaHomeDir() {
|
|
12
|
+
return process.env.LEMMA_HOME?.trim() ? resolve(process.env.LEMMA_HOME.trim()) : join(homedir(), ".lemma");
|
|
13
|
+
}
|
|
14
|
+
export function globalConfigPath() {
|
|
15
|
+
return join(lemmaHomeDir(), "config.json");
|
|
16
|
+
}
|
|
17
|
+
export function projectsCatalogPath() {
|
|
18
|
+
return join(lemmaHomeDir(), "projects.json");
|
|
19
|
+
}
|
|
20
|
+
/** 向上查找 Git 仓库根目录;若当前不在 Git 仓库中则返回解析后的原目录。 */
|
|
21
|
+
export function findRepoRoot(cwd) {
|
|
22
|
+
let cur = resolve(cwd);
|
|
23
|
+
while (true) {
|
|
24
|
+
if (existsSync(join(cur, ".git")))
|
|
25
|
+
return cur;
|
|
26
|
+
const parent = dirname(cur);
|
|
27
|
+
if (parent === cur)
|
|
28
|
+
return resolve(cwd);
|
|
29
|
+
cur = parent;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function normalizedKeyPath(dir) {
|
|
33
|
+
const r = resolve(dir);
|
|
34
|
+
return process.platform === "win32" ? r.toLowerCase() : r;
|
|
35
|
+
}
|
|
36
|
+
export function projectIdForPath(projectRoot) {
|
|
37
|
+
const resolved = resolve(projectRoot);
|
|
38
|
+
const rawName = basename(resolved) || "workspace";
|
|
39
|
+
const slug = rawName
|
|
40
|
+
.replace(/[^\p{L}\p{N}_-]+/gu, "-")
|
|
41
|
+
.replace(/^-+|-+$/g, "")
|
|
42
|
+
.slice(0, 32) || "workspace";
|
|
43
|
+
const hash = createHash("sha256").update(normalizedKeyPath(resolved)).digest("hex").slice(0, 8);
|
|
44
|
+
return `${slug}-${hash}`;
|
|
45
|
+
}
|
|
46
|
+
export function projectStateDirFor(projectRoot) {
|
|
47
|
+
return join(lemmaHomeDir(), "projects", projectIdForPath(projectRoot));
|
|
48
|
+
}
|
|
49
|
+
export class ProjectCatalog {
|
|
50
|
+
filePath;
|
|
51
|
+
constructor(filePath = projectsCatalogPath()) {
|
|
52
|
+
this.filePath = resolve(filePath);
|
|
53
|
+
}
|
|
54
|
+
readRaw() {
|
|
55
|
+
if (!existsSync(this.filePath))
|
|
56
|
+
return [];
|
|
57
|
+
try {
|
|
58
|
+
const parsed = JSON.parse(readFileSync(this.filePath, "utf8"));
|
|
59
|
+
if (!Array.isArray(parsed))
|
|
60
|
+
return [];
|
|
61
|
+
return parsed.filter((x) => Boolean(x && typeof x === "object" && typeof x.id === "string" && typeof x.path === "string"));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
writeRaw(entries) {
|
|
68
|
+
mkdirSync(dirname(this.filePath), { recursive: true });
|
|
69
|
+
const tmp = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
70
|
+
try {
|
|
71
|
+
writeFileSync(tmp, `${JSON.stringify(entries, null, 2)}\n`, "utf8");
|
|
72
|
+
renameSync(tmp, this.filePath);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
rmSync(tmp, { force: true });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
list() {
|
|
79
|
+
return this.readRaw().sort((a, b) => b.lastOpenedAt - a.lastOpenedAt || a.name.localeCompare(b.name));
|
|
80
|
+
}
|
|
81
|
+
touch(projectRoot, opts) {
|
|
82
|
+
const resolved = resolve(projectRoot);
|
|
83
|
+
const id = projectIdForPath(resolved);
|
|
84
|
+
const stateDir = opts?.stateDir ? resolve(opts.stateDir) : projectStateDirFor(resolved);
|
|
85
|
+
const storage = opts?.storage ? resolve(opts.storage) : join(stateDir, "session.sqlite");
|
|
86
|
+
const now = opts?.now ?? Date.now();
|
|
87
|
+
const entries = this.readRaw();
|
|
88
|
+
const key = normalizedKeyPath(resolved);
|
|
89
|
+
const idx = entries.findIndex((e) => normalizedKeyPath(e.path) === key || e.id === id);
|
|
90
|
+
const existing = idx >= 0 ? entries[idx] : undefined;
|
|
91
|
+
const next = {
|
|
92
|
+
id,
|
|
93
|
+
name: basename(resolved) || id,
|
|
94
|
+
path: resolved,
|
|
95
|
+
storage,
|
|
96
|
+
stateDir,
|
|
97
|
+
createdAt: existing?.createdAt ?? now,
|
|
98
|
+
lastOpenedAt: now,
|
|
99
|
+
};
|
|
100
|
+
if (idx >= 0)
|
|
101
|
+
entries[idx] = next;
|
|
102
|
+
else
|
|
103
|
+
entries.push(next);
|
|
104
|
+
this.writeRaw(entries);
|
|
105
|
+
return next;
|
|
106
|
+
}
|
|
107
|
+
resolve(query) {
|
|
108
|
+
const trimmed = query.trim().replace(/^["']|["']$/g, "");
|
|
109
|
+
if (!trimmed)
|
|
110
|
+
return undefined;
|
|
111
|
+
const all = this.list();
|
|
112
|
+
if (/^\d+$/.test(trimmed)) {
|
|
113
|
+
const idx = Number.parseInt(trimmed, 10) - 1;
|
|
114
|
+
return idx >= 0 && idx < all.length ? all[idx] : undefined;
|
|
115
|
+
}
|
|
116
|
+
const lower = trimmed.toLowerCase();
|
|
117
|
+
return (all.find((e) => e.id.toLowerCase() === lower) ??
|
|
118
|
+
all.find((e) => e.name.toLowerCase() === lower) ??
|
|
119
|
+
all.find((e) => normalizedKeyPath(e.path) === normalizedKeyPath(trimmed)));
|
|
120
|
+
}
|
|
121
|
+
remove(query) {
|
|
122
|
+
const found = this.resolve(query);
|
|
123
|
+
if (!found)
|
|
124
|
+
return undefined;
|
|
125
|
+
const next = this.readRaw().filter((e) => e.id !== found.id);
|
|
126
|
+
this.writeRaw(next);
|
|
127
|
+
return found;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 解析启动工作区与配置:
|
|
132
|
+
* - 若显式指定 PI_AGENT_CONFIG,则完全沿用原路径解析,不触碰全局注册表;
|
|
133
|
+
* - 若当前仓库(或其 Git 根目录)无 pi-agent.config.json,则加载共享的 ~/.lemma/config.json,
|
|
134
|
+
* 并将 session.sqlite / worktrees / ASSIGN.md 集中隔离到 ~/.lemma/projects/<slug>-<hash>/;
|
|
135
|
+
* - 若仓库存在局部 pi-agent.config.json 但未显式指定 storage,同样使用 ~/.lemma/projects/ 集中存储。
|
|
136
|
+
*/
|
|
137
|
+
export function resolveStartupWorkspace(options) {
|
|
138
|
+
const catalog = options.catalog ?? new ProjectCatalog();
|
|
139
|
+
if (options.envConfigPath?.trim()) {
|
|
140
|
+
const configPath = resolve(options.cwd ?? process.cwd(), options.envConfigPath.trim());
|
|
141
|
+
const baseConfig = loadConfig(configPath);
|
|
142
|
+
return {
|
|
143
|
+
configPath,
|
|
144
|
+
baseConfig,
|
|
145
|
+
projectRoot: resolve(baseConfig.workdir),
|
|
146
|
+
isolatedExternally: false,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
let startDir = resolve(options.cwd ?? process.cwd());
|
|
150
|
+
if (options.projectArg?.trim()) {
|
|
151
|
+
const q = options.projectArg.trim().replace(/^["']|["']$/g, "");
|
|
152
|
+
const hit = catalog.resolve(q);
|
|
153
|
+
if (hit) {
|
|
154
|
+
if (!existsSync(hit.path) || !statSync(hit.path).isDirectory()) {
|
|
155
|
+
throw new Error(`项目目录不存在:${hit.path}`);
|
|
156
|
+
}
|
|
157
|
+
startDir = hit.path;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const candidate = resolve(startDir, q);
|
|
161
|
+
if (!existsSync(candidate) || !statSync(candidate).isDirectory()) {
|
|
162
|
+
throw new Error(`找不到项目“${q}”(可用 lemma projects 查看已记录项目或传入有效路径)。`);
|
|
163
|
+
}
|
|
164
|
+
startDir = candidate;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const projectRoot = findRepoRoot(startDir);
|
|
168
|
+
const cwdConfig = join(startDir, "pi-agent.config.json");
|
|
169
|
+
const rootConfig = join(projectRoot, "pi-agent.config.json");
|
|
170
|
+
const localConfigPath = existsSync(cwdConfig) ? cwdConfig : (existsSync(rootConfig) ? rootConfig : undefined);
|
|
171
|
+
const stateDir = projectStateDirFor(projectRoot);
|
|
172
|
+
const managedStorage = join(stateDir, "session.sqlite");
|
|
173
|
+
const managedProjectDir = join(stateDir, "project");
|
|
174
|
+
const sharedConfigPath = globalConfigPath();
|
|
175
|
+
const rawGlobal = existsSync(sharedConfigPath) ? JSON.parse(readFileSync(sharedConfigPath, "utf8")) : {};
|
|
176
|
+
const { workdir: _gw, storage: _gs, projectStateDir: _gp, ...sharedLayer } = rawGlobal;
|
|
177
|
+
if (localConfigPath) {
|
|
178
|
+
const rawLocal = JSON.parse(readFileSync(localConfigPath, "utf8"));
|
|
179
|
+
const mergedRaw = localConfigPath === sharedConfigPath
|
|
180
|
+
? rawLocal
|
|
181
|
+
: {
|
|
182
|
+
...sharedLayer,
|
|
183
|
+
...rawLocal,
|
|
184
|
+
...(rawLocal.orchestrator || rawGlobal.orchestrator ? { orchestrator: { ...sharedLayer.orchestrator, ...rawLocal.orchestrator } } : {}),
|
|
185
|
+
...(rawLocal.agents || rawGlobal.agents ? { agents: { ...sharedLayer.agents, ...rawLocal.agents } } : {}),
|
|
186
|
+
...(rawLocal.isolation || rawGlobal.isolation ? { isolation: { ...sharedLayer.isolation, ...rawLocal.isolation } } : {}),
|
|
187
|
+
...(rawLocal.budget || rawGlobal.budget ? { budget: { ...sharedLayer.budget, ...rawLocal.budget } } : {}),
|
|
188
|
+
...(rawLocal.autonomy || rawGlobal.autonomy ? { autonomy: { ...sharedLayer.autonomy, ...rawLocal.autonomy } } : {}),
|
|
189
|
+
};
|
|
190
|
+
const config = normalizeConfig(mergedRaw, localConfigPath);
|
|
191
|
+
const explicitStorage = typeof rawLocal.storage === "string" && rawLocal.storage.trim().length > 0;
|
|
192
|
+
const baseConfig = explicitStorage
|
|
193
|
+
? config
|
|
194
|
+
: { ...config, storage: managedStorage, projectStateDir: managedProjectDir };
|
|
195
|
+
const project = catalog.touch(resolve(baseConfig.workdir), {
|
|
196
|
+
storage: baseConfig.storage,
|
|
197
|
+
stateDir: explicitStorage ? dirname(baseConfig.storage) : stateDir,
|
|
198
|
+
});
|
|
199
|
+
return {
|
|
200
|
+
configPath: localConfigPath,
|
|
201
|
+
baseConfig,
|
|
202
|
+
projectRoot: resolve(baseConfig.workdir),
|
|
203
|
+
isolatedExternally: !explicitStorage,
|
|
204
|
+
project,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const normalizedGlobal = normalizeConfig(sharedLayer, existsSync(sharedConfigPath) ? sharedConfigPath : join(projectRoot, "pi-agent.config.json"));
|
|
208
|
+
const baseConfig = {
|
|
209
|
+
...normalizedGlobal,
|
|
210
|
+
workdir: projectRoot,
|
|
211
|
+
storage: managedStorage,
|
|
212
|
+
projectStateDir: managedProjectDir,
|
|
213
|
+
};
|
|
214
|
+
const project = catalog.touch(projectRoot, { storage: managedStorage, stateDir });
|
|
215
|
+
return {
|
|
216
|
+
configPath: sharedConfigPath,
|
|
217
|
+
baseConfig,
|
|
218
|
+
projectRoot,
|
|
219
|
+
isolatedExternally: true,
|
|
220
|
+
project,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/** 基于当前仓库技术栈探测,生成极简不污染仓库存储的项目级 pi-agent.config.json(仅写 checks 与 linkDirs)。 */
|
|
224
|
+
export function initProjectConfig(projectRoot, opts) {
|
|
225
|
+
const root = findRepoRoot(projectRoot);
|
|
226
|
+
const targetPath = join(root, "pi-agent.config.json");
|
|
227
|
+
if (existsSync(targetPath) && !opts?.force) {
|
|
228
|
+
throw new Error(`${targetPath} 已存在;若需覆盖请传入 --force(注意:无 storage 字段时仍会将运行库存于 ~/.lemma/projects/)。`);
|
|
229
|
+
}
|
|
230
|
+
const checks = [];
|
|
231
|
+
const linkDirs = new Set();
|
|
232
|
+
const hasRootPkg = existsSync(join(root, "package.json"));
|
|
233
|
+
const hasFrontendPkg = existsSync(join(root, "frontend", "package.json"));
|
|
234
|
+
const hasRootPom = existsSync(join(root, "pom.xml"));
|
|
235
|
+
const hasBackendPom = existsSync(join(root, "backend", "pom.xml"));
|
|
236
|
+
const hasPyproject = existsSync(join(root, "pyproject.toml")) || existsSync(join(root, "requirements.txt"));
|
|
237
|
+
const hasGoMod = existsSync(join(root, "go.mod"));
|
|
238
|
+
if (hasRootPkg) {
|
|
239
|
+
linkDirs.add("node_modules");
|
|
240
|
+
try {
|
|
241
|
+
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
242
|
+
if (pkg.scripts?.typecheck)
|
|
243
|
+
checks.push({ name: "typecheck", command: "npm", args: ["run", "typecheck"], timeoutSeconds: 120 });
|
|
244
|
+
if (pkg.scripts?.test)
|
|
245
|
+
checks.push({ name: "npm-test", command: "npm", args: ["test"], timeoutSeconds: 180 });
|
|
246
|
+
}
|
|
247
|
+
catch { }
|
|
248
|
+
}
|
|
249
|
+
if (hasFrontendPkg) {
|
|
250
|
+
linkDirs.add("frontend/node_modules");
|
|
251
|
+
checks.push({ name: "frontend-build", command: "npm", args: ["--prefix", "frontend", "run", "build"], timeoutSeconds: 180 });
|
|
252
|
+
}
|
|
253
|
+
if (hasRootPom) {
|
|
254
|
+
checks.push({ name: "maven-compile", command: "mvn", args: ["test-compile"], timeoutSeconds: 240 });
|
|
255
|
+
}
|
|
256
|
+
else if (hasBackendPom) {
|
|
257
|
+
checks.push({ name: "backend-compile", command: "mvn", args: ["-f", "backend/pom.xml", "test-compile"], timeoutSeconds: 240 });
|
|
258
|
+
}
|
|
259
|
+
if (hasPyproject) {
|
|
260
|
+
linkDirs.add(".venv");
|
|
261
|
+
linkDirs.add("venv");
|
|
262
|
+
checks.push({ name: "pytest", command: "pytest", args: [], timeoutSeconds: 180 });
|
|
263
|
+
}
|
|
264
|
+
if (hasGoMod) {
|
|
265
|
+
checks.push({ name: "go-test", command: "go", args: ["test", "./..."], timeoutSeconds: 180 });
|
|
266
|
+
}
|
|
267
|
+
const payload = {
|
|
268
|
+
isolation: {
|
|
269
|
+
enabled: true,
|
|
270
|
+
linkDirs: linkDirs.size ? [...linkDirs] : ["node_modules", ".venv", "venv"],
|
|
271
|
+
},
|
|
272
|
+
autonomy: {
|
|
273
|
+
enabled: checks.length > 0,
|
|
274
|
+
maxRepairAttempts: 2,
|
|
275
|
+
resultMaxChars: 4000,
|
|
276
|
+
checks,
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
normalizeConfig(payload, targetPath);
|
|
280
|
+
writeFileSync(targetPath, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
|
|
281
|
+
return { path: targetPath, checks: checks.length, linkDirs: payload.isolation.linkDirs };
|
|
282
|
+
}
|
package/dist/settings.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { existsSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
4
|
import { normalizeConfig } from "./config.js";
|
|
4
5
|
/** Optimistic, atomic config update; preserve unknown fields and never overwrite external edits. */
|
|
@@ -19,6 +20,7 @@ export function editSettings(path) {
|
|
|
19
20
|
if (current !== before)
|
|
20
21
|
throw new Error("配置在编辑期间已被其他操作修改,请重新执行命令;未覆盖外部改动。");
|
|
21
22
|
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
23
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
22
24
|
try {
|
|
23
25
|
writeFileSync(temporary, `${JSON.stringify(raw, null, 2)}\n`, { flag: "wx" });
|
|
24
26
|
renameSync(temporary, path);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lemma-agent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Lemma: durable local multi-agent coding orchestration with isolated worktrees, blind review, and verified integration",
|
|
5
5
|
"bin": {
|
|
6
6
|
"lemma": "bin/lemma.mjs"
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"test:cli-replay": "node --no-warnings test/cli-replay.ts",
|
|
37
37
|
"test:ux": "node --no-warnings test/ux-telemetry.ts",
|
|
38
38
|
"test:ood": "node --no-warnings test/ood-benchmark.ts",
|
|
39
|
+
"test:projects": "node --no-warnings test/projects.ts",
|
|
39
40
|
"test:collaboration": "node --no-warnings test/integrations.ts && node --no-warnings test/task-workflow.ts && node --no-warnings test/task-workflow-api.ts && node --no-warnings test/task-workflow-code.ts && node --no-warnings test/task-recovery.ts && node --no-warnings test/context-handoff.ts && node --no-warnings test/collaboration-controls.ts && node --no-warnings test/mcp.ts && node --no-warnings test/collaboration-benchmark.ts && node --no-warnings test/fast-path.ts && node --no-warnings test/coding-benchmark-suite.ts && npm run test:security && npm run test:chaos-durable && npm run test:cli-replay && npm run test:ux && npm run test:ood",
|
|
40
41
|
"test:metrics": "node --no-warnings test/selector-metadata.ts && node --no-warnings test/model-discovery.ts && node --no-warnings test/context-benchmark.ts",
|
|
41
42
|
"typecheck": "tsc -p .",
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"test:harness": "node --no-warnings test/sessions.ts && node --no-warnings test/repair.ts && node --no-warnings test/sessions-cli.ts",
|
|
44
45
|
"test:conversations": "node --no-warnings test/conversations-web.ts && node --no-warnings test/admin-rebind.ts && node --no-warnings test/web-controls.ts && node --no-warnings test/git-workbench.ts",
|
|
45
46
|
"test:terminal": "node --no-warnings test/terminal.ts && node --no-warnings test/terminal-state.ts && node --no-warnings test/model-selection.ts && npm run test:metrics && node --no-warnings test/terminal-cli.ts && node --no-warnings test/terminal-child-view.ts && node --no-warnings test/terminal-model-selection.ts",
|
|
46
|
-
"test": "npm run test:business && npm run test:collaboration && npm run test:settings && npm run test:custom-agents && npm run test:results && npm run test:dialogue && node --no-warnings test/smoke.ts && node --no-warnings test/crash.ts && node --no-warnings test/isolation.ts && node --no-warnings test/steer.ts && node --no-warnings test/board.ts && node --no-warnings test/jobs.ts && node --no-warnings test/api-member.ts && node --no-warnings test/lead.ts && node --no-warnings test/conventions.ts && node --no-warnings test/web.ts && npm run test:terminal && npm run test:harness && npm run test:conversations",
|
|
47
|
+
"test": "npm run test:business && npm run test:collaboration && npm run test:settings && npm run test:custom-agents && npm run test:results && npm run test:dialogue && npm run test:projects && node --no-warnings test/smoke.ts && node --no-warnings test/crash.ts && node --no-warnings test/isolation.ts && node --no-warnings test/steer.ts && node --no-warnings test/board.ts && node --no-warnings test/jobs.ts && node --no-warnings test/api-member.ts && node --no-warnings test/lead.ts && node --no-warnings test/conventions.ts && node --no-warnings test/web.ts && npm run test:terminal && npm run test:harness && npm run test:conversations",
|
|
47
48
|
"test:business": "node --no-warnings test/business.ts && node --no-warnings test/settlement.ts",
|
|
48
49
|
"test:results": "node --no-warnings test/result-retrieval.ts",
|
|
49
50
|
"test:custom-agents": "node --no-warnings test/custom-agent-config.ts && node --no-warnings test/custom-agents.ts",
|