@sleep2agi/commhub-server 0.9.0-preview.154 → 0.9.0-preview.155
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/package.json +1 -1
- package/src/project-viewer-can-http.test.ts +3 -1
- package/src/requirements-errors.ts +7 -0
- package/src/requirements-migrate.ts +3 -0
- package/src/requirements-projects-parent-http.test.ts +123 -0
- package/src/requirements-status-participants-http.test.ts +2 -2
- package/src/requirements.ts +74 -5
- package/src/tools.ts +8 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/commhub-server",
|
|
3
|
-
"version": "0.9.0-preview.
|
|
3
|
+
"version": "0.9.0-preview.155",
|
|
4
4
|
"description": "CommHub Server — AI Agent communication hub with MCP protocol, multi-network isolation, user auth, and MCP tools (17 collaboration-core + node/provider ops tools; authoritative list: docs-site/docs/api/mcp-tools.md).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -91,7 +91,9 @@ describe("GET /api/requirements/projects 的 viewer_can.edit", () => {
|
|
|
91
91
|
|
|
92
92
|
test("只加字段:其余键与之前逐字相同", async () => {
|
|
93
93
|
const row = (await projects("alice"))["pvc-P2"];
|
|
94
|
-
|
|
94
|
+
// parentId 是 2026-10-24 加的「子项目」字段(admin:管理项目里看不到层级);
|
|
95
|
+
// 它同样是加法式的:这里钉的是「已知键一个不多一个不少」,新键必须显式加进这个清单。
|
|
96
|
+
expect(Object.keys(row).sort()).toEqual(["archived", "color", "createdAt", "id", "name", "parentId", "sort", "viewer_can"]);
|
|
95
97
|
expect(Object.keys(row.viewer_can)).toEqual(["edit"]);
|
|
96
98
|
});
|
|
97
99
|
|
|
@@ -40,6 +40,13 @@ const ENTRIES: Record<string, Entry> = {
|
|
|
40
40
|
tag_parent_not_found: { field: 'parent_id', message: 'No tag named that in this network.', hint: 'Create the parent first (parent_id: null), or read GET /api/requirements/tags → nodes for the names that exist.' },
|
|
41
41
|
invalid_tag_parent_id: { field: 'parent_id', message: 'parent_id must be a tag name in this network, or null for the root.', hint: 'Tag names are 1–20 characters; read GET /api/requirements/tags → nodes for the names that exist.' },
|
|
42
42
|
tag_parent_cycle: { field: 'parent_id', message: 'A tag cannot be its own parent.', hint: 'Pass a different parent, or null for the root.' },
|
|
43
|
+
// 子项目(admin 2026-10-24):项目也能成层级,错误码与标签那几条**分开**,文案指向 proj_… 而不是标签名。
|
|
44
|
+
invalid_project_parent: { field: 'parent_id', message: 'parent_id must be a project id (proj_…) or null for a top-level project.', hint: 'Call projects_list to get project ids.' },
|
|
45
|
+
project_parent_not_found: { field: 'parent_id', message: 'No project with that id in this network (or it was deleted).', hint: 'Call projects_list to get the ids that exist.' },
|
|
46
|
+
project_parent_archived: { field: 'parent_id', message: 'That parent project is archived, so it cannot take children.', hint: 'Unarchive it first, or pick an active project.' },
|
|
47
|
+
project_parent_cycle: { field: 'parent_id', message: 'That parent would make the project its own ancestor.', hint: 'Pick a project that is not this one or one of its children.' },
|
|
48
|
+
project_parent_too_deep: { field: 'parent_id', message: 'Projects nest at most 3 levels (a top-level project counts as level 1).', hint: 'Attach it to a higher-level project.' },
|
|
49
|
+
project_has_children: { message: 'This project still has sub-projects, so it cannot be deleted.', hint: 'Move or delete the sub-projects first (a parent is never silently orphaned).' },
|
|
43
50
|
tag_depth_exceeded: { field: 'parent_id', message: 'Tags nest at most 4 levels (the root counts as level 1).', hint: 'Attach the tag to a higher-level tag.' },
|
|
44
51
|
invalid_tag: { field: 'name', message: 'Tag names are 1–20 characters after trimming, with no control characters.', hint: 'Shorten the name, or remove line breaks.' },
|
|
45
52
|
checklist_item_not_found: { field: 'item_id', message: 'This task has no checklist item with that id.', hint: 'Item ids (ck_…) are in requirements_get → checklist[].id.' },
|
|
@@ -41,6 +41,9 @@ export function ensureRequirementProjects(database: DbAdapter): void {
|
|
|
41
41
|
);
|
|
42
42
|
CREATE INDEX IF NOT EXISTS idx_requirement_projects_network ON requirement_projects(network_id, sort);
|
|
43
43
|
`);
|
|
44
|
+
// 子项目(admin 2026-10-24:管理项目里没有层级)。加法式列,老库用 ALTER 补;重复执行无副作用。
|
|
45
|
+
// NULL = 顶层项目,所以现有行不需要回填。
|
|
46
|
+
try { database.exec("ALTER TABLE requirement_projects ADD COLUMN parent_id TEXT"); } catch {}
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
/**
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// 子项目(admin 2026-10-24:管理项目里只能平铺,看不到层级)。
|
|
2
|
+
//
|
|
3
|
+
// 本文件钉住四件事,任何一条错都会让「项目」这个词变得不可信:
|
|
4
|
+
// 1. 建/搬家都能指定 parent_id,GET 列表能读回;
|
|
5
|
+
// 2. 深度上限 3 层(顶层=1),超了拒绝而不是悄悄截断;
|
|
6
|
+
// 3. 环(把自己挂到自己的后代下面 / 挂到自己身上)必须拒绝;
|
|
7
|
+
// 4. 有子项目的项目不能直接删(不偷偷把子项目变孤儿或改写它们的层级)。
|
|
8
|
+
// 另外:父项目必须同网络、未归档。
|
|
9
|
+
import { describe, expect, test, beforeAll, afterAll } from "bun:test";
|
|
10
|
+
import "./require-explicit-test-db.js";
|
|
11
|
+
import { register } from "./auth.js";
|
|
12
|
+
import { bootServer } from "./server.js";
|
|
13
|
+
|
|
14
|
+
let BASE = "";
|
|
15
|
+
let server: any = null;
|
|
16
|
+
let token = "";
|
|
17
|
+
let NET = "";
|
|
18
|
+
|
|
19
|
+
async function send(method: string, path: string, payload?: unknown) {
|
|
20
|
+
const res = await fetch(`${BASE}${path}`, {
|
|
21
|
+
method,
|
|
22
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
23
|
+
body: payload === undefined ? undefined : JSON.stringify(payload),
|
|
24
|
+
});
|
|
25
|
+
const text = await res.text();
|
|
26
|
+
let body: any = null;
|
|
27
|
+
try { body = JSON.parse(text); } catch {}
|
|
28
|
+
return { status: res.status, body };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const P = (path: string) => `${path}${path.includes("?") ? "&" : "?"}network_id=${NET}`;
|
|
32
|
+
const mk = (name: string, parent_id?: string | null) =>
|
|
33
|
+
send("POST", P("/api/requirements/projects"), parent_id === undefined ? { name } : { name, parent_id });
|
|
34
|
+
|
|
35
|
+
beforeAll(async () => {
|
|
36
|
+
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1000)}`;
|
|
37
|
+
const a = register(`projparent_${suffix}`, "ProjParentPw123!", undefined, "pp");
|
|
38
|
+
expect(a.ok).toBe(true);
|
|
39
|
+
token = a.token!;
|
|
40
|
+
NET = a.network_id!;
|
|
41
|
+
server = bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
42
|
+
BASE = `http://127.0.0.1:${server.port}`;
|
|
43
|
+
}, 30_000);
|
|
44
|
+
|
|
45
|
+
afterAll(() => { try { server?.stop?.(true); } catch {} });
|
|
46
|
+
|
|
47
|
+
describe("sub-projects (parent_id)", () => {
|
|
48
|
+
test("create a child and read the hierarchy back", async () => {
|
|
49
|
+
const parent = await mk("父项目");
|
|
50
|
+
expect(parent.status).toBe(201);
|
|
51
|
+
const parentId = parent.body.project.id;
|
|
52
|
+
expect(parent.body.project.parentId).toBeNull();
|
|
53
|
+
|
|
54
|
+
const child = await mk("子项目", parentId);
|
|
55
|
+
expect(child.status).toBe(201);
|
|
56
|
+
expect(child.body.project.parentId).toBe(parentId);
|
|
57
|
+
|
|
58
|
+
const list = await send("GET", P("/api/requirements/projects"));
|
|
59
|
+
expect(list.status).toBe(200);
|
|
60
|
+
const rows = list.body.projects as any[];
|
|
61
|
+
expect(rows.find((r) => r.name === "子项目")!.parentId).toBe(parentId);
|
|
62
|
+
expect(rows.find((r) => r.name === "父项目")!.parentId).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("a project can be moved under another one, and back to the top", async () => {
|
|
66
|
+
const a = await mk("可搬 A");
|
|
67
|
+
const b = await mk("可搬 B");
|
|
68
|
+
const moved = await send("PATCH", P(`/api/requirements/projects/${b.body.project.id}`), { parent_id: a.body.project.id });
|
|
69
|
+
expect(moved.status).toBe(200);
|
|
70
|
+
expect(moved.body.project.parentId).toBe(a.body.project.id);
|
|
71
|
+
|
|
72
|
+
const back = await send("PATCH", P(`/api/requirements/projects/${b.body.project.id}`), { parent_id: null });
|
|
73
|
+
expect(back.status).toBe(200);
|
|
74
|
+
expect(back.body.project.parentId).toBeNull();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("depth is capped at 3 (top level counts as 1)", async () => {
|
|
78
|
+
const l1 = await mk("深 1");
|
|
79
|
+
const l2 = await mk("深 2", l1.body.project.id);
|
|
80
|
+
const l3 = await mk("深 3", l2.body.project.id);
|
|
81
|
+
expect(l3.status).toBe(201);
|
|
82
|
+
const l4 = await mk("深 4", l3.body.project.id);
|
|
83
|
+
expect(l4.status).toBe(400);
|
|
84
|
+
expect(l4.body.error).toBe("project_parent_too_deep");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("a cycle is refused (self, and a descendant)", async () => {
|
|
88
|
+
const a = await mk("环 A");
|
|
89
|
+
const b = await mk("环 B", a.body.project.id);
|
|
90
|
+
const self = await send("PATCH", P(`/api/requirements/projects/${a.body.project.id}`), { parent_id: a.body.project.id });
|
|
91
|
+
expect(self.status).toBe(400);
|
|
92
|
+
expect(self.body.error).toBe("project_parent_cycle");
|
|
93
|
+
|
|
94
|
+
// 把 A 挂到它自己的子项目 B 下面 = 环
|
|
95
|
+
const loop = await send("PATCH", P(`/api/requirements/projects/${a.body.project.id}`), { parent_id: b.body.project.id });
|
|
96
|
+
expect(loop.status).toBe(400);
|
|
97
|
+
expect(loop.body.error).toBe("project_parent_cycle");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("a parent that does not exist, is archived, or lives in another network is refused", async () => {
|
|
101
|
+
const missing = await mk("缺父", "proj_does_not_exist");
|
|
102
|
+
expect(missing.status).toBe(404);
|
|
103
|
+
expect(missing.body.error).toBe("project_parent_not_found");
|
|
104
|
+
|
|
105
|
+
const parent = await mk("会归档的父");
|
|
106
|
+
await send("PATCH", P(`/api/requirements/projects/${parent.body.project.id}`), { archived: true });
|
|
107
|
+
const archived = await mk("挂到归档父", parent.body.project.id);
|
|
108
|
+
expect(archived.status).toBe(400);
|
|
109
|
+
expect(archived.body.error).toBe("project_parent_archived");
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("a project with children cannot be deleted (children are not silently orphaned)", async () => {
|
|
113
|
+
const parent = await mk("有孩子的父");
|
|
114
|
+
const child = await mk("孩子", parent.body.project.id);
|
|
115
|
+
const del = await send("DELETE", P(`/api/requirements/projects/${parent.body.project.id}`));
|
|
116
|
+
expect(del.status).toBe(409);
|
|
117
|
+
expect(del.body.error).toBe("project_has_children");
|
|
118
|
+
|
|
119
|
+
// 先删孩子,父就能删
|
|
120
|
+
expect((await send("DELETE", P(`/api/requirements/projects/${child.body.project.id}`))).status).toBe(200);
|
|
121
|
+
expect((await send("DELETE", P(`/api/requirements/projects/${parent.body.project.id}`))).status).toBe(200);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -213,8 +213,8 @@ describe("tool descriptions", () => {
|
|
|
213
213
|
// #478:节点令牌的 tools/list 里本来就没有 projects_create / projects_update(调了也是 403),那两条的说明从人的列表里读。
|
|
214
214
|
expect(byName.has("projects_create")).toBe(false);
|
|
215
215
|
const human = new Map(((await rpc(U.member.token, "tools/list", {})).result.tools as any[]).map(t => [t.name, t]));
|
|
216
|
-
expect(byName.get("projects_list").description).toMatch(/node
|
|
217
|
-
for (const name of ["projects_create", "projects_update"]) expect(human.get(name).description).toMatch(/node
|
|
216
|
+
expect(byName.get("projects_list").description).toMatch(/node (?:\(Agent\) )?tokens can only read projects/i);
|
|
217
|
+
for (const name of ["projects_create", "projects_update"]) expect(human.get(name).description).toMatch(/node (?:\(Agent\) )?tokens can only read projects/i);
|
|
218
218
|
const denied = await mcp(U.nodeA.token, "projects_create", { name: "示例项目" });
|
|
219
219
|
expect(denied.status).toBe(403);
|
|
220
220
|
expect(denied.error).toBe("user_token_required");
|
package/src/requirements.ts
CHANGED
|
@@ -348,11 +348,13 @@ function storedChecklist(raw: string | null): ChecklistItem[] {
|
|
|
348
348
|
// ── 项目 ──
|
|
349
349
|
// 按网络隔离;名字 1–40 字,同一网络里未归档的项目不重名;颜色 #RRGGBB;sort 越小越靠前。
|
|
350
350
|
// 删除 = 删项目行 + 把引用它的卡片 project_id 置空(卡片本身不动);归档 = 保留引用,只是不能再被选。
|
|
351
|
-
type ProjectRow = { project_id: string; network_id: string; name: string; color: string; sort: number; archived: number; created_at: string };
|
|
351
|
+
type ProjectRow = { project_id: string; network_id: string; name: string; color: string; sort: number; archived: number; created_at: string; parent_id: string | null };
|
|
352
352
|
const PROJECT_COLOR = /^#[0-9a-fA-F]{6}$/;
|
|
353
353
|
const PROJECT_PALETTE = ["#2563eb", "#16a34a", "#d97706", "#dc2626", "#7c3aed", "#0891b2", "#db2777", "#4b5563"];
|
|
354
|
-
const PROJECT_SELECT = "project_id, network_id, name, color, sort, archived, created_at";
|
|
355
|
-
|
|
354
|
+
const PROJECT_SELECT = "project_id, network_id, name, color, sort, archived, created_at, parent_id";
|
|
355
|
+
/** 子项目最多 3 层(顶层=1)。再深的话「项目」这个词就没有意义了,也没人能在选择器里点对。 */
|
|
356
|
+
const PROJECT_MAX_DEPTH = 3;
|
|
357
|
+
const projectPublic = (row: ProjectRow) => ({ id: row.project_id, name: row.name, color: row.color, sort: row.sort, archived: !!row.archived, createdAt: row.created_at, parentId: row.parent_id ?? null });
|
|
356
358
|
const projectName = (raw: unknown): string | null => {
|
|
357
359
|
if (typeof raw !== "string") return null;
|
|
358
360
|
const name = raw.replace(/[\r\n\t]+/g, " ").trim();
|
|
@@ -361,6 +363,50 @@ const projectName = (raw: unknown): string | null => {
|
|
|
361
363
|
function projectNameTaken(networkId: string, name: string, except?: string): boolean {
|
|
362
364
|
return !!db.get("SELECT 1 FROM requirement_projects WHERE network_id = ?1 AND name = ?2 AND archived = 0 AND project_id != ?3", networkId, name, except ?? "");
|
|
363
365
|
}
|
|
366
|
+
/** 这个项目往上数有几层(自己算第一层)。用于深度上限与环路判断。 */
|
|
367
|
+
function projectDepth(projectId: string): number {
|
|
368
|
+
let depth = 0;
|
|
369
|
+
let cur: string | null = projectId;
|
|
370
|
+
const seen = new Set<string>();
|
|
371
|
+
while (cur && depth < 64) {
|
|
372
|
+
if (seen.has(cur)) return Number.POSITIVE_INFINITY; // 循环:当成超深,调用方会拒绝
|
|
373
|
+
seen.add(cur);
|
|
374
|
+
depth++;
|
|
375
|
+
const row: { parent_id: string | null } | null = db.get("SELECT parent_id FROM requirement_projects WHERE project_id = ?1", cur);
|
|
376
|
+
cur = row?.parent_id ?? null;
|
|
377
|
+
}
|
|
378
|
+
return depth;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* 校验 parent_id(新项目或搬家时)。返回 { parent } 或错误码。
|
|
383
|
+
* 规则:同一网络、存在、未归档、不是自己或自己的后代、加进来后不超过 PROJECT_MAX_DEPTH。
|
|
384
|
+
*/
|
|
385
|
+
function validateProjectParent(
|
|
386
|
+
networkId: string, parentId: string, selfId: string | null,
|
|
387
|
+
): { ok: true; parent: ProjectRow } | { ok: false; error: string } {
|
|
388
|
+
const parent = db.get<ProjectRow>(`SELECT ${PROJECT_SELECT} FROM requirement_projects WHERE project_id = ?1`, parentId);
|
|
389
|
+
if (!parent || parent.network_id !== networkId) return { ok: false, error: "project_parent_not_found" };
|
|
390
|
+
if (parent.archived) return { ok: false, error: "project_parent_archived" };
|
|
391
|
+
if (selfId) {
|
|
392
|
+
if (parent.project_id === selfId) return { ok: false, error: "project_parent_cycle" };
|
|
393
|
+
// 把 A 挂到 A 的后代下面 = 环。沿 parent 链往上走,遇到自己就拒绝。
|
|
394
|
+
let cur: string | null = parent.parent_id ?? null;
|
|
395
|
+
const seen = new Set<string>();
|
|
396
|
+
while (cur && !seen.has(cur)) {
|
|
397
|
+
if (cur === selfId) return { ok: false, error: "project_parent_cycle" };
|
|
398
|
+
seen.add(cur);
|
|
399
|
+
cur = db.get<{ parent_id: string | null }>("SELECT parent_id FROM requirement_projects WHERE project_id = ?1", cur)?.parent_id ?? null;
|
|
400
|
+
}
|
|
401
|
+
if (projectDepth(selfId) + projectDepth(parent.project_id) > PROJECT_MAX_DEPTH) {
|
|
402
|
+
return { ok: false, error: "project_parent_too_deep" };
|
|
403
|
+
}
|
|
404
|
+
} else if (projectDepth(parent.project_id) + 1 > PROJECT_MAX_DEPTH) {
|
|
405
|
+
return { ok: false, error: "project_parent_too_deep" };
|
|
406
|
+
}
|
|
407
|
+
return { ok: true, parent };
|
|
408
|
+
}
|
|
409
|
+
|
|
364
410
|
/** 卡片上的 project_id:null 清空;字符串必须是同一网络、未归档的项目。 */
|
|
365
411
|
function projectRef(value: unknown, networkId: string): string | null {
|
|
366
412
|
if (value === null) return null;
|
|
@@ -405,13 +451,24 @@ async function handleProjects(ctx: RequirementsRequestContext): Promise<Response
|
|
|
405
451
|
const sort = body.sort === undefined ? count : body.sort;
|
|
406
452
|
if (!Number.isInteger(sort)) return jsonError("invalid_project_sort", 400);
|
|
407
453
|
const id = `proj_${crypto.randomUUID()}`;
|
|
408
|
-
|
|
454
|
+
// 子项目:parent_id 可选;null/缺省 = 顶层。
|
|
455
|
+
let parentId: string | null = null;
|
|
456
|
+
if (body.parent_id !== undefined && body.parent_id !== null && body.parent_id !== "") {
|
|
457
|
+
if (typeof body.parent_id !== "string") return jsonError("invalid_project_parent", 400);
|
|
458
|
+
const check = validateProjectParent(networkId, body.parent_id, null);
|
|
459
|
+
if (!check.ok) return jsonError(check.error, check.error === "project_parent_not_found" ? 404 : 400);
|
|
460
|
+
parentId = check.parent.project_id;
|
|
461
|
+
}
|
|
462
|
+
db.run(`INSERT INTO requirement_projects (${PROJECT_SELECT}) VALUES (?1, ?2, ?3, ?4, ?5, 0, ?6, ?7)`, [id, networkId, name, color, sort, new Date().toISOString(), parentId]);
|
|
409
463
|
return Response.json({ ok: true, project: projectPublic(db.get<ProjectRow>(`SELECT ${PROJECT_SELECT} FROM requirement_projects WHERE project_id = ?1`, id)!) }, { status: 201 });
|
|
410
464
|
}
|
|
411
465
|
if (!one) return jsonError("not_found", 404);
|
|
412
466
|
const current = db.get<ProjectRow>(`SELECT ${PROJECT_SELECT} FROM requirement_projects WHERE project_id = ?1`, decodeURIComponent(one[1]));
|
|
413
467
|
if (!current || current.network_id !== networkId) return jsonError("project_not_found", 404);
|
|
414
468
|
if (req.method === "DELETE") {
|
|
469
|
+
// 子项目不能凭空变孤儿:先搬走或删掉它们(明确拒绝,不偷偷改层级)。
|
|
470
|
+
const kids = db.get<{ n: number }>("SELECT COUNT(*) AS n FROM requirement_projects WHERE parent_id = ?1", current.project_id)?.n ?? 0;
|
|
471
|
+
if (kids > 0) return jsonError("project_has_children", 409);
|
|
415
472
|
// 先把卡片上的引用置空,再删项目:卡片一张不少。
|
|
416
473
|
// updated_at 跟着动:按 updated_since 增量同步的客户端要看得见「项目被清空」这一改动。
|
|
417
474
|
// 每张被清空项目的卡记一条「项目 X → 无」(与清空同一个事务)。
|
|
@@ -445,8 +502,20 @@ async function handleProjects(ctx: RequirementsRequestContext): Promise<Response
|
|
|
445
502
|
if (typeof body.archived !== "boolean") return jsonError("invalid_project_archived", 400);
|
|
446
503
|
archived = body.archived ? 1 : 0;
|
|
447
504
|
}
|
|
505
|
+
let parentId: string | null = current.parent_id ?? null;
|
|
506
|
+
if ("parent_id" in body) {
|
|
507
|
+
if (body.parent_id === null || body.parent_id === "") {
|
|
508
|
+
parentId = null; // 变成顶层
|
|
509
|
+
} else if (typeof body.parent_id !== "string") {
|
|
510
|
+
return jsonError("invalid_project_parent", 400);
|
|
511
|
+
} else {
|
|
512
|
+
const check = validateProjectParent(networkId, body.parent_id, current.project_id);
|
|
513
|
+
if (!check.ok) return jsonError(check.error, check.error === "project_parent_not_found" ? 404 : 400);
|
|
514
|
+
parentId = check.parent.project_id;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
448
517
|
if (!archived && projectNameTaken(networkId, name, current.project_id)) return jsonError("project_name_taken", 409);
|
|
449
|
-
db.run("UPDATE requirement_projects SET name = ?1, color = ?2, sort = ?3, archived = ?4 WHERE project_id = ?5", [name, color, sort, archived, current.project_id]);
|
|
518
|
+
db.run("UPDATE requirement_projects SET name = ?1, color = ?2, sort = ?3, archived = ?4, parent_id = ?6 WHERE project_id = ?5", [name, color, sort, archived, current.project_id, parentId]);
|
|
450
519
|
return Response.json({ ok: true, project: projectPublic(db.get<ProjectRow>(`SELECT ${PROJECT_SELECT} FROM requirement_projects WHERE project_id = ?1`, current.project_id)!) });
|
|
451
520
|
}
|
|
452
521
|
|
package/src/tools.ts
CHANGED
|
@@ -4104,7 +4104,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
4104
4104
|
|
|
4105
4105
|
server.tool(
|
|
4106
4106
|
"tail_node_logs",
|
|
4107
|
-
"
|
|
4107
|
+
"Tail of a node's own agent-node run log (read-only, redacted on the node). No path argument: it reads only its own log directory. User logins only (node owner or network owner/admin). Poll get_rules_file_result; JSON {files, lines, truncated, matched}; handed out once, then purged.",
|
|
4108
4108
|
{
|
|
4109
4109
|
...NODE_ID_ALIAS_FIELDS,
|
|
4110
4110
|
alias: z.string().min(1).max(200).optional().describe("Alias instead of node_id (a node, or a session reporting logs_capable)."),
|
|
@@ -6916,7 +6916,7 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
6916
6916
|
|
|
6917
6917
|
server.tool(
|
|
6918
6918
|
"projects_list",
|
|
6919
|
-
"List requirement projects
|
|
6919
|
+
"List requirement projects (id, name, color, sort, archived, parentId). node tokens can only read projects; creating / changing needs a person's token (projects_create / projects_update).",
|
|
6920
6920
|
{ network_id: z.string().max(200).optional() },
|
|
6921
6921
|
async ({ network_id }) => requirementsCall("GET", "/api/requirements/projects", network_id),
|
|
6922
6922
|
);
|
|
@@ -6926,19 +6926,20 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
6926
6926
|
// write access and is refused to 「仅相关任务」(task-scoped) members; events use the task list's visibility.
|
|
6927
6927
|
server.tool(
|
|
6928
6928
|
"projects_create",
|
|
6929
|
-
"Create a requirement project
|
|
6929
|
+
"Create a requirement project (管理项目 → 新建). name 1–40, unique; color #RRGGBB; sort int; parent_id optional (≤3 levels). Returns { project }. node tokens can only read projects (403 user_token_required); task-scoped / read-only members are refused.",
|
|
6930
6930
|
{
|
|
6931
6931
|
network_id: z.string().max(200).optional(),
|
|
6932
6932
|
name: z.string().min(1).max(40),
|
|
6933
6933
|
color: z.string().regex(/^#[0-9a-fA-F]{6}$/).optional(),
|
|
6934
6934
|
sort: z.number().int().optional(),
|
|
6935
|
+
parent_id: z.string().max(200).nullable().optional(),
|
|
6935
6936
|
},
|
|
6936
|
-
async (args) => requirementsCall("POST", "/api/requirements/projects", args.network_id, pick(args, ["name", "color", "sort"])),
|
|
6937
|
+
async (args) => requirementsCall("POST", "/api/requirements/projects", args.network_id, pick(args, ["name", "color", "sort", "parent_id"])),
|
|
6937
6938
|
);
|
|
6938
6939
|
|
|
6939
6940
|
server.tool(
|
|
6940
6941
|
"projects_update",
|
|
6941
|
-
"Rename, recolour, reorder, archive or
|
|
6942
|
+
"Rename, recolour, reorder, archive/unarchive, or move a project under another (parent_id; null = top level, cycles / depth>3 refused). Only the fields you pass change; archived hides it from pickers. Returns { project }. node tokens can only read projects (403); task-scoped / read-only members refused.",
|
|
6942
6943
|
{
|
|
6943
6944
|
network_id: z.string().max(200).optional(),
|
|
6944
6945
|
id: z.string().min(1).max(200).describe("project id (proj_…), from projects_list"),
|
|
@@ -6946,8 +6947,9 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
|
|
|
6946
6947
|
color: z.string().regex(/^#[0-9a-fA-F]{6}$/).optional(),
|
|
6947
6948
|
sort: z.number().int().optional(),
|
|
6948
6949
|
archived: z.boolean().optional(),
|
|
6950
|
+
parent_id: z.string().max(200).nullable().optional(),
|
|
6949
6951
|
},
|
|
6950
|
-
async (args) => requirementsCall("PATCH", `/api/requirements/projects/${encodeURIComponent(args.id)}`, args.network_id, pick(args, ["name", "color", "sort", "archived"])),
|
|
6952
|
+
async (args) => requirementsCall("PATCH", `/api/requirements/projects/${encodeURIComponent(args.id)}`, args.network_id, pick(args, ["name", "color", "sort", "archived", "parent_id"])),
|
|
6951
6953
|
);
|
|
6952
6954
|
|
|
6953
6955
|
// #476 —— 不带 requirement_id 的全网动态默认 50 条(REST 默认 200 不变,App 走 REST);严格参数同 #471。
|