@yankeguo/dsh-devlead 0.4.2-rc.6 → 0.4.2-rc.7
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 +21 -17
- package/lib/index.js +98 -70
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,17 +16,19 @@ lead-AI-writable and human/browser-read-only.
|
|
|
16
16
|
The same Host-owned board service also owns `ctx.devLead.notes`, a `DevLeadBoardNotesStore` rooted at
|
|
17
17
|
`dirname(boardPath)/notes/` and swapped/closed with the board lifecycle. Tool-facing service methods are
|
|
18
18
|
`readBoardNote(agent, { project, note? })` and
|
|
19
|
-
`writeBoardNote(agent, { project, operation, note?, title?, summary?, content?, expectedRevision
|
|
20
|
-
|
|
21
|
-
`
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
`writeBoardNote(agent, { project, operation, note?, title?, summary?, content?, expectedRevision? }, signal?)`;
|
|
20
|
+
both recheck the active lead and accept no filesystem path input. Results derive an `absolutePath` for native
|
|
21
|
+
DSH `read`/`write`/`edit` body editing; it is never persisted in the index. Operations are `create` (optional
|
|
22
|
+
initial content), `update-metadata`, and `delete`; there is no tool body-update/append or body-byte CAS. The store
|
|
23
|
+
exposes `path` / `indexPath` / `enabled`, `start()` / `close()`, cache-only `summaryIndex()`, and logical `read()` /
|
|
24
|
+
`write()`. Its strict schema-v1 `index.json` is the committed source of truth and contains only project/note
|
|
25
|
+
metadata; Markdown bodies live at `<sanitized project>/<note-id>.md`, and orphan files are ignored. Every index
|
|
26
|
+
mutation resolves the board project by id/title/absolute workspace path, fresh-reads under the cross-process file
|
|
27
|
+
lock, checks `expected_revision`, validates the complete next index, and atomically replaces it. Reads/lists also
|
|
28
|
+
serialize through that lock, validate stable UTF-8 body snapshots within 256 KiB, and lazily repair `bytes` and
|
|
29
|
+
file-mtime `updatedAt` without writing bodies; any invalid/missing body aborts the repair and preserves the old
|
|
30
|
+
index. The index is capped at 128 KiB and each project at 100 notes. A bad index is never overwritten from a stale
|
|
31
|
+
cache and does not block the board or DevLead; notes operations still require a valid board project. The synchronous board summary
|
|
30
32
|
reads the valid board + notes caches and adds
|
|
31
33
|
active-project note counts/latest titles within its existing 1536-byte cap. Humans and browsers stay
|
|
32
34
|
read-only.
|
|
@@ -126,12 +128,14 @@ lead off/切换会释放旧 store/watcher,start/预创建失败只记 warning
|
|
|
126
128
|
`@deepseek-ai/dsh-atomic-write`(安装运行时提供)。同一 Host board service 拥有随 board
|
|
127
129
|
切换/关闭的 `ctx.devLead.notes`(`DevLeadBoardNotesStore`,root 固定
|
|
128
130
|
`dirname(boardPath)/notes/`)。工具侧 service 方法是 `readBoardNote(agent,{project,note?})` 与
|
|
129
|
-
`writeBoardNote(agent,patch,signal?)`,patch 含
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
`writeBoardNote(agent,patch,signal?)`,patch 含 create/update-metadata/delete operation、可选
|
|
132
|
+
note/title/summary/create-only content 与 expectedRevision,均不接受文件路径输入;返回的 absolutePath 供
|
|
133
|
+
DSH 原生 read/write/edit 编辑正文,不写入 index,也不再提供工具 update/append 或正文 bytes CAS。store
|
|
134
|
+
暴露 path/indexPath/enabled、start/close、summaryIndex 与逻辑 read/write。严格 schema-v1 `index.json`
|
|
135
|
+
是提交事实、只存 metadata,正文位于 `<sanitized project>/<note-id>.md`,orphan 忽略。每次 index 修改在
|
|
136
|
+
跨进程文件锁内 fresh read,校验 `expected_revision`,验证完整 next index 后原子替换;read/list 也串行
|
|
137
|
+
进入该锁,验证稳定、≤256 KiB 的合法 UTF-8 正文快照并惰性修复 bytes/文件 mtime updatedAt,绝不重写正文;
|
|
138
|
+
缺失/非法正文会中止修复并保留旧 index。index ≤128 KiB、每项目 ≤100 条。坏 index 不会用旧缓存覆盖,也不阻塞 board/DevLead;
|
|
135
139
|
notes 操作仍要求能解析合法 board project。同步 board summary 从合法缓存为 active 项目附加 note 数/
|
|
136
140
|
最近标题,整体仍 ≤1536 bytes。人类与浏览器
|
|
137
141
|
只读。
|
package/lib/index.js
CHANGED
|
@@ -18884,9 +18884,8 @@ function boundNoteRead(result) {
|
|
|
18884
18884
|
}
|
|
18885
18885
|
function validateWriteShape(patch) {
|
|
18886
18886
|
validateNonNegativeInteger(patch.expectedRevision, "expectedRevision");
|
|
18887
|
-
|
|
18888
|
-
|
|
18889
|
-
throw invalid("operation must be create, update, append, or delete", "/operation");
|
|
18887
|
+
if (!["create", "update-metadata", "delete"].includes(patch.operation)) {
|
|
18888
|
+
throw invalid("operation must be create, update-metadata, or delete", "/operation");
|
|
18890
18889
|
}
|
|
18891
18890
|
if (patch.operation !== "create" && patch.note === void 0) {
|
|
18892
18891
|
throw invalid(`note is required for ${patch.operation}`, "/note");
|
|
@@ -18895,18 +18894,11 @@ function validateWriteShape(patch) {
|
|
|
18895
18894
|
if (patch.title === void 0 || patch.title.trim().length === 0) {
|
|
18896
18895
|
throw invalid("create requires a non-empty title", "/title");
|
|
18897
18896
|
}
|
|
18898
|
-
|
|
18899
|
-
|
|
18900
|
-
}
|
|
18901
|
-
}
|
|
18902
|
-
if (patch.operation === "append") {
|
|
18903
|
-
if (patch.content === void 0) throw invalid("append requires content", "/content");
|
|
18904
|
-
if (patch.title !== void 0 || patch.summary !== void 0) {
|
|
18905
|
-
throw invalid("append accepts content but not title or summary", "/content");
|
|
18906
|
-
}
|
|
18897
|
+
} else if (patch.content !== void 0) {
|
|
18898
|
+
throw invalid(`${patch.operation} does not accept content; edit the returned Markdown path with native file tools`, "/content");
|
|
18907
18899
|
}
|
|
18908
|
-
if (patch.operation === "delete" && (patch.title !== void 0 || patch.summary !== void 0
|
|
18909
|
-
throw invalid("delete does not accept title
|
|
18900
|
+
if (patch.operation === "delete" && (patch.title !== void 0 || patch.summary !== void 0)) {
|
|
18901
|
+
throw invalid("delete does not accept title or summary", "/operation");
|
|
18910
18902
|
}
|
|
18911
18903
|
if (patch.content !== void 0) validateContentSize(patch.content);
|
|
18912
18904
|
const id = patch.note ?? "00000000-0000-4000-8000-000000000000";
|
|
@@ -19066,30 +19058,83 @@ var DevLeadBoardNotesStore = class {
|
|
|
19066
19058
|
/** Read one project's metadata list, or one note body bounded for the model result. */
|
|
19067
19059
|
async read(filter) {
|
|
19068
19060
|
this.requireRoot();
|
|
19069
|
-
const
|
|
19070
|
-
|
|
19071
|
-
|
|
19072
|
-
|
|
19073
|
-
|
|
19074
|
-
|
|
19075
|
-
|
|
19076
|
-
|
|
19077
|
-
|
|
19078
|
-
|
|
19079
|
-
|
|
19061
|
+
const operation = this.writeTail.then(() => this.readReconciled(filter));
|
|
19062
|
+
this.writeTail = operation.catch(() => void 0);
|
|
19063
|
+
return operation;
|
|
19064
|
+
}
|
|
19065
|
+
/**
|
|
19066
|
+
* Native Markdown edits bypass this store, so every model read/list lazily
|
|
19067
|
+
* reconciles the selected file snapshots. One locked transaction validates
|
|
19068
|
+
* all selected bodies before committing any metadata repair; an invalid or
|
|
19069
|
+
* missing body therefore leaves the previous index untouched.
|
|
19070
|
+
*/
|
|
19071
|
+
async readReconciled(filter) {
|
|
19072
|
+
const root = this.requireRoot();
|
|
19073
|
+
const filePath = this.requireIndexPath();
|
|
19074
|
+
try {
|
|
19075
|
+
const boardProject = await this.board.resolveProject(filter.project);
|
|
19076
|
+
return await withFileLock2(filePath, async () => {
|
|
19077
|
+
const current = await this.current();
|
|
19078
|
+
const currentProject = current.projects.find((candidate) => candidate.id === boardProject.id);
|
|
19079
|
+
let selected = currentProject?.notes ?? [];
|
|
19080
|
+
if (filter.note !== void 0) {
|
|
19081
|
+
const metadata2 = currentProject?.notes.find((note) => note.id === filter.note);
|
|
19082
|
+
if (currentProject === void 0 || metadata2 === void 0) {
|
|
19083
|
+
throw new DevLeadBoardError(`note "${filter.note}" was not found`, "BOARD_NOTE_NOT_FOUND");
|
|
19084
|
+
}
|
|
19085
|
+
selected = [metadata2];
|
|
19086
|
+
}
|
|
19087
|
+
const bodies = /* @__PURE__ */ new Map();
|
|
19088
|
+
if (currentProject !== void 0) {
|
|
19089
|
+
for (const metadata2 of selected) bodies.set(metadata2.id, await this.readBody(currentProject, metadata2));
|
|
19090
|
+
}
|
|
19091
|
+
let index = current;
|
|
19092
|
+
if (currentProject !== void 0 && selected.some((metadata2) => {
|
|
19093
|
+
const body = bodies.get(metadata2.id);
|
|
19094
|
+
return metadata2.bytes !== body.buffer.length || metadata2.updatedAt !== body.updatedAt;
|
|
19095
|
+
})) {
|
|
19096
|
+
const next = structuredClone(current);
|
|
19097
|
+
const project2 = next.projects.find((candidate) => candidate.id === boardProject.id);
|
|
19098
|
+
for (const metadata2 of project2.notes) {
|
|
19099
|
+
const body = bodies.get(metadata2.id);
|
|
19100
|
+
if (body === void 0) continue;
|
|
19101
|
+
metadata2.bytes = body.buffer.length;
|
|
19102
|
+
metadata2.updatedAt = body.updatedAt;
|
|
19103
|
+
}
|
|
19104
|
+
next.revision = current.revision + 1;
|
|
19105
|
+
next.updatedAt = new Date(this.now()).toISOString();
|
|
19106
|
+
index = this.validateNext(next);
|
|
19107
|
+
await this.commitIndex(filePath, index);
|
|
19108
|
+
}
|
|
19109
|
+
const project = index.projects.find((candidate) => candidate.id === boardProject.id);
|
|
19110
|
+
const view = { id: boardProject.id, directory: projectDirectory(boardProject.id, index) };
|
|
19111
|
+
if (filter.note === void 0) {
|
|
19112
|
+
return {
|
|
19113
|
+
revision: index.revision,
|
|
19114
|
+
updatedAt: index.updatedAt,
|
|
19115
|
+
project: view,
|
|
19116
|
+
notes: (project?.notes ?? []).map((metadata2) => this.publicMetadata(root, project, metadata2))
|
|
19117
|
+
};
|
|
19118
|
+
}
|
|
19119
|
+
const metadata = project.notes.find((note) => note.id === filter.note);
|
|
19120
|
+
return boundNoteRead({
|
|
19121
|
+
revision: index.revision,
|
|
19122
|
+
updatedAt: index.updatedAt,
|
|
19123
|
+
project: view,
|
|
19124
|
+
note: {
|
|
19125
|
+
...this.publicMetadata(root, project, metadata),
|
|
19126
|
+
content: bodies.get(metadata.id).content
|
|
19127
|
+
}
|
|
19128
|
+
});
|
|
19129
|
+
});
|
|
19130
|
+
} catch (error51) {
|
|
19131
|
+
if (isDevLeadBoardError(error51)) throw error51;
|
|
19132
|
+
if (isWriteIoError2(error51)) throw ioError("read notes", filePath, error51);
|
|
19133
|
+
throw error51;
|
|
19080
19134
|
}
|
|
19081
|
-
|
|
19082
|
-
|
|
19083
|
-
|
|
19084
|
-
throw new DevLeadBoardError(`note "${filter.note}" was not found`, "BOARD_NOTE_NOT_FOUND");
|
|
19085
|
-
}
|
|
19086
|
-
const body = await this.readBody(project, metadata);
|
|
19087
|
-
return boundNoteRead({
|
|
19088
|
-
revision: index.revision,
|
|
19089
|
-
updatedAt: index.updatedAt,
|
|
19090
|
-
project: view,
|
|
19091
|
-
note: { ...structuredClone(metadata), content: body.content }
|
|
19092
|
-
});
|
|
19135
|
+
}
|
|
19136
|
+
publicMetadata(root, project, metadata) {
|
|
19137
|
+
return { ...structuredClone(metadata), absolutePath: noteFilePath(root, project, metadata) };
|
|
19093
19138
|
}
|
|
19094
19139
|
/** Serialize Host calls, then use the index file's cross-process writer lock for each mutation. */
|
|
19095
19140
|
async write(patch, signal) {
|
|
@@ -19131,18 +19176,10 @@ var DevLeadBoardNotesStore = class {
|
|
|
19131
19176
|
if (metadata === void 0) {
|
|
19132
19177
|
throw new DevLeadBoardError(`note "${patch.note ?? ""}" was not found`, "BOARD_NOTE_NOT_FOUND");
|
|
19133
19178
|
}
|
|
19134
|
-
const body = patch.operation === "delete" && patch.expectedBytes === void 0 ? void 0 : await this.readBody(project, metadata);
|
|
19135
|
-
if (body !== void 0 && patch.expectedBytes !== void 0 && body.buffer.length !== patch.expectedBytes) {
|
|
19136
|
-
throw new DevLeadBoardError(
|
|
19137
|
-
`note byte conflict: expected ${patch.expectedBytes}, current ${body.buffer.length}`,
|
|
19138
|
-
"BOARD_BYTES_CONFLICT",
|
|
19139
|
-
[{ pointer: "/expectedBytes", message: `expected ${patch.expectedBytes}, current ${body.buffer.length}` }]
|
|
19140
|
-
);
|
|
19141
|
-
}
|
|
19142
19179
|
if (patch.operation === "delete") {
|
|
19143
19180
|
return await this.deleteNote(root, filePath, current, next, project, metadata, timestamp);
|
|
19144
19181
|
}
|
|
19145
|
-
return await this.
|
|
19182
|
+
return await this.changeMetadata(root, filePath, current, next, project, metadata, patch);
|
|
19146
19183
|
}, signal === void 0 ? {} : { signal });
|
|
19147
19184
|
} catch (error51) {
|
|
19148
19185
|
if (isDevLeadBoardError(error51)) throw error51;
|
|
@@ -19199,45 +19236,38 @@ var DevLeadBoardNotesStore = class {
|
|
|
19199
19236
|
revision: validated.revision,
|
|
19200
19237
|
updatedAt: validated.updatedAt,
|
|
19201
19238
|
project: { id: project.id, directory: project.directory },
|
|
19202
|
-
note:
|
|
19239
|
+
note: this.publicMetadata(root, validatedProject, validatedNote),
|
|
19203
19240
|
operation: "create",
|
|
19204
19241
|
changed: true
|
|
19205
19242
|
};
|
|
19206
19243
|
}
|
|
19207
|
-
async
|
|
19244
|
+
async changeMetadata(root, filePath, current, next, project, metadata, patch) {
|
|
19208
19245
|
const title = patch.title === void 0 ? metadata.title : patch.title.trim();
|
|
19209
19246
|
if (title.length === 0) throw invalid("title must not be empty", "/title");
|
|
19210
19247
|
const summary = patch.summary ?? metadata.summary;
|
|
19211
|
-
const
|
|
19212
|
-
validateContentSize(content);
|
|
19213
|
-
const changed = title !== metadata.title || summary !== metadata.summary || content !== body.content;
|
|
19248
|
+
const changed = title !== metadata.title || summary !== metadata.summary;
|
|
19214
19249
|
if (!changed) {
|
|
19215
19250
|
return {
|
|
19216
19251
|
revision: current.revision,
|
|
19217
19252
|
updatedAt: current.updatedAt,
|
|
19218
19253
|
project: { id: project.id, directory: project.directory },
|
|
19219
|
-
note:
|
|
19254
|
+
note: this.publicMetadata(root, project, metadata),
|
|
19220
19255
|
operation: patch.operation,
|
|
19221
19256
|
changed: false
|
|
19222
19257
|
};
|
|
19223
19258
|
}
|
|
19224
|
-
Object.assign(metadata, {
|
|
19225
|
-
title,
|
|
19226
|
-
summary,
|
|
19227
|
-
updatedAt: timestamp,
|
|
19228
|
-
bytes: Buffer.byteLength(content, "utf8")
|
|
19229
|
-
});
|
|
19259
|
+
Object.assign(metadata, { title, summary });
|
|
19230
19260
|
next.revision = current.revision + 1;
|
|
19231
|
-
next.updatedAt =
|
|
19261
|
+
next.updatedAt = new Date(this.now()).toISOString();
|
|
19232
19262
|
const validated = this.validateNext(next);
|
|
19233
19263
|
const validatedProject = validated.projects.find((candidate) => candidate.id === project.id);
|
|
19234
19264
|
const validatedNote = validatedProject.notes.find((note) => note.id === metadata.id);
|
|
19235
|
-
await this.
|
|
19265
|
+
await this.commitIndex(filePath, validated);
|
|
19236
19266
|
return {
|
|
19237
19267
|
revision: validated.revision,
|
|
19238
19268
|
updatedAt: validated.updatedAt,
|
|
19239
19269
|
project: { id: project.id, directory: project.directory },
|
|
19240
|
-
note:
|
|
19270
|
+
note: this.publicMetadata(root, validatedProject, validatedNote),
|
|
19241
19271
|
operation: patch.operation,
|
|
19242
19272
|
changed: true
|
|
19243
19273
|
};
|
|
@@ -19258,7 +19288,7 @@ var DevLeadBoardNotesStore = class {
|
|
|
19258
19288
|
revision: validated.revision,
|
|
19259
19289
|
updatedAt: validated.updatedAt,
|
|
19260
19290
|
project: { id: project.id, directory: project.directory },
|
|
19261
|
-
note:
|
|
19291
|
+
note: this.publicMetadata(root, project, metadata),
|
|
19262
19292
|
operation: "delete",
|
|
19263
19293
|
changed: true,
|
|
19264
19294
|
deleted: true
|
|
@@ -19298,7 +19328,7 @@ var DevLeadBoardNotesStore = class {
|
|
|
19298
19328
|
this.cache = validated;
|
|
19299
19329
|
this.lastError = void 0;
|
|
19300
19330
|
}
|
|
19301
|
-
/** Read a stable body
|
|
19331
|
+
/** Read a stable native-edited body; reconciliation, never body rewriting, handles stale metadata. */
|
|
19302
19332
|
async readBody(project, metadata) {
|
|
19303
19333
|
const root = this.requireRoot();
|
|
19304
19334
|
const path = noteFilePath(root, project, metadata);
|
|
@@ -19311,13 +19341,11 @@ var DevLeadBoardNotesStore = class {
|
|
|
19311
19341
|
const buffer = await readFile2(path);
|
|
19312
19342
|
const after = await stat3(path);
|
|
19313
19343
|
if (before.mtimeMs !== after.mtimeMs || before.size !== after.size || before.ino !== after.ino || buffer.length !== after.size) continue;
|
|
19314
|
-
|
|
19315
|
-
|
|
19316
|
-
|
|
19317
|
-
|
|
19318
|
-
|
|
19319
|
-
}
|
|
19320
|
-
return { buffer, content: decodeUtf8(buffer, `note "${metadata.id}"`) };
|
|
19344
|
+
return {
|
|
19345
|
+
buffer,
|
|
19346
|
+
content: decodeUtf8(buffer, `note "${metadata.id}"`),
|
|
19347
|
+
updatedAt: after.mtime.toISOString()
|
|
19348
|
+
};
|
|
19321
19349
|
}
|
|
19322
19350
|
throw ioError("read stable note", path, new Error("file changed repeatedly; retry"));
|
|
19323
19351
|
} catch (error51) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yankeguo/dsh-devlead",
|
|
3
|
-
"version": "0.4.2-rc.
|
|
3
|
+
"version": "0.4.2-rc.7",
|
|
4
4
|
"description": "DevLead mode core service for the DeepSeek Harness: durable per-session mode, Workspace and Session orchestration, watched-session notifications, and the `devLead` Session projection.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@yankeguo/dsh-devlead-protocol": "0.4.2-rc.
|
|
48
|
+
"@yankeguo/dsh-devlead-protocol": "0.4.2-rc.7"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
51
|
"dsh": ">=0.2.2-rc.1 <0.3.0"
|