@kangyishuai/dsh-casefile 0.2.0 → 0.2.2
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/lib/actions.js +2 -0
- package/lib/core/brief.js +10 -0
- package/lib/core/store.js +39 -0
- package/lib/service.js +2 -0
- package/lib/tools.js +37 -0
- package/package.json +1 -1
package/lib/actions.js
CHANGED
|
@@ -969,6 +969,8 @@ export function createActions(options) {
|
|
|
969
969
|
].join("\n");
|
|
970
970
|
const created = await sessions.create({ cwd });
|
|
971
971
|
const sessionId = String(created.sessionId);
|
|
972
|
+
// builder 只该收到规格包:把它登记为"只读会话",写类工具会拒绝它。
|
|
973
|
+
store.recordBuilderSession(sessionId);
|
|
972
974
|
await sessions.prompt({ sessionId, text: prompt });
|
|
973
975
|
const record = {
|
|
974
976
|
id: newId("builder"),
|
package/lib/core/brief.js
CHANGED
|
@@ -207,6 +207,16 @@ export function renderSpecMarkdown(pack) {
|
|
|
207
207
|
for (const item of pack.evidence) {
|
|
208
208
|
lines.push("");
|
|
209
209
|
lines.push(`- \`${item.id}\` · ${item.kind} · ${item.confidence} / ${item.authority}`);
|
|
210
|
+
if (item.producer && typeof item.producer === "object") {
|
|
211
|
+
const producer = item.producer;
|
|
212
|
+
const bits = [
|
|
213
|
+
producer.tool == null ? "工具未知" : `工具 ${producer.tool}`,
|
|
214
|
+
producer.version == null ? null : `v${producer.version}`,
|
|
215
|
+
producer.mode == null ? null : `方式 ${producer.mode}`,
|
|
216
|
+
producer.accessConfirmedByUser === true ? "用户已确认" : "用户未确认",
|
|
217
|
+
].filter((value) => value != null);
|
|
218
|
+
lines.push(` - 生产者:${bits.join(" · ")}`);
|
|
219
|
+
}
|
|
210
220
|
if (item.summary) lines.push(` - ${item.summary}`);
|
|
211
221
|
if (item.limitations.length > 0) lines.push(` - 局限:${item.limitations.join(";")}`);
|
|
212
222
|
if (item.refs.length > 0) lines.push(` - 引用:${item.refs.join("、")}`);
|
package/lib/core/store.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// - 所有路径从 dataRoot 派生,不写死 ~/.dsh(可在临时目录里测)。
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
|
+
appendFileSync,
|
|
15
16
|
existsSync,
|
|
16
17
|
mkdirSync,
|
|
17
18
|
readdirSync,
|
|
@@ -363,6 +364,44 @@ export class CaseStore {
|
|
|
363
364
|
return candidate;
|
|
364
365
|
}
|
|
365
366
|
|
|
367
|
+
/**
|
|
368
|
+
* 记录一个 builder 子会话 id(数据根级,不分项目)。
|
|
369
|
+
* builder 只该收到规格包,不该写账本——写类工具遇到它会拒绝。
|
|
370
|
+
* @param {string} sessionId
|
|
371
|
+
*/
|
|
372
|
+
recordBuilderSession(sessionId) {
|
|
373
|
+
const id = String(sessionId ?? "").trim();
|
|
374
|
+
if (id === "") return;
|
|
375
|
+
const file = join(this.dataRoot, "builder-sessions.jsonl");
|
|
376
|
+
appendFileSync(
|
|
377
|
+
file,
|
|
378
|
+
`${JSON.stringify({ sessionId: id, at: new Date().toISOString() })}\n`,
|
|
379
|
+
"utf8",
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* 读 builder 会话 id 集合。
|
|
385
|
+
* @returns {Set<string>}
|
|
386
|
+
*/
|
|
387
|
+
listBuilderSessions() {
|
|
388
|
+
const file = join(this.dataRoot, "builder-sessions.jsonl");
|
|
389
|
+
if (!existsSync(file)) return new Set();
|
|
390
|
+
/** @type {Set<string>} */
|
|
391
|
+
const out = new Set();
|
|
392
|
+
for (const line of readFileSync(file, "utf8").split("\n")) {
|
|
393
|
+
const text = line.trim();
|
|
394
|
+
if (text === "") continue;
|
|
395
|
+
try {
|
|
396
|
+
const record = JSON.parse(text);
|
|
397
|
+
if (typeof record?.sessionId === "string") out.add(record.sessionId);
|
|
398
|
+
} catch {
|
|
399
|
+
// 坏行跳过:这份索引是"宁可少拦"的辅助数据,坏了不影响主记录。
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return out;
|
|
403
|
+
}
|
|
404
|
+
|
|
366
405
|
/**
|
|
367
406
|
* 项目列表(跳过坏项目并告警)。
|
|
368
407
|
* @returns {Record<string, any>[]}
|
package/lib/service.js
CHANGED
|
@@ -211,6 +211,8 @@ export class CasefileService extends TypertRemoteService {
|
|
|
211
211
|
reopenObligation: (projectId, id, note) => this.actions.reopenObligation(projectId, id, note),
|
|
212
212
|
overview: () => this.actions.overview(),
|
|
213
213
|
runCycle: (projectId, input) => this.actions.runCycle(projectId, input),
|
|
214
|
+
isBuilderSession: (sessionId) =>
|
|
215
|
+
this.store.listBuilderSessions().has(String(sessionId ?? "")),
|
|
214
216
|
closeProject: (projectId, options) => this.actions.closeProject(projectId, options),
|
|
215
217
|
closePreview: (projectId, options) => this.actions.closePreview(projectId, options),
|
|
216
218
|
exportReport: (projectId) => this.actions.exportReport(projectId),
|
package/lib/tools.js
CHANGED
|
@@ -84,6 +84,35 @@ function assertAction(action, allowed) {
|
|
|
84
84
|
* @returns {any[]}
|
|
85
85
|
*/
|
|
86
86
|
export function buildToolDefinitions(handlers, projectOf) {
|
|
87
|
+
/**
|
|
88
|
+
* @param {any} args
|
|
89
|
+
* @param {any} exec
|
|
90
|
+
* @returns {string}
|
|
91
|
+
*/
|
|
92
|
+
/**
|
|
93
|
+
* builder 子会话只该收到规格包,不得写账本。
|
|
94
|
+
* 写类工具在开跑前统一过这道门:exec.agent.id 命中 builder 登记就拒绝。
|
|
95
|
+
* @param {any} exec
|
|
96
|
+
* @returns {Promise<void>}
|
|
97
|
+
*/
|
|
98
|
+
/**
|
|
99
|
+
* builder 子会话只该收到规格包,不得写账本。
|
|
100
|
+
* @param {any} exec
|
|
101
|
+
* @returns {Promise<void>}
|
|
102
|
+
*/
|
|
103
|
+
const assertWriter = async (exec) => {
|
|
104
|
+
const sessionId = exec?.agent?.id;
|
|
105
|
+
if (typeof sessionId !== "string" || sessionId === "") return;
|
|
106
|
+
const lookup = handlers.isBuilderSession;
|
|
107
|
+
if (typeof lookup !== "function") return;
|
|
108
|
+
if (await lookup(sessionId)) {
|
|
109
|
+
throw Object.assign(
|
|
110
|
+
new Error("builder 会话不能写案卷:它只该收到规格包。写证据/结论/义务请在主线会话里做。"),
|
|
111
|
+
{ code: "builder-readonly" },
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
87
116
|
/**
|
|
88
117
|
* @param {any} args
|
|
89
118
|
* @param {any} exec
|
|
@@ -138,6 +167,7 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
138
167
|
/** @param {any} args @param {any} exec */
|
|
139
168
|
async execute(args, exec) {
|
|
140
169
|
return run(async () => {
|
|
170
|
+
await assertWriter(exec);
|
|
141
171
|
switch (args.action) {
|
|
142
172
|
case "open": {
|
|
143
173
|
if (typeof args.title !== "string" || args.title.trim() === "") {
|
|
@@ -262,6 +292,7 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
262
292
|
/** @param {any} args @param {any} exec */
|
|
263
293
|
async execute(args, exec) {
|
|
264
294
|
return run(async () => {
|
|
295
|
+
await assertWriter(exec);
|
|
265
296
|
const action = assertAction(args.action, ["add", "list", "show"]);
|
|
266
297
|
const id = projectId(args, exec);
|
|
267
298
|
if (action === "add") {
|
|
@@ -320,6 +351,7 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
320
351
|
/** @param {any} args @param {any} exec */
|
|
321
352
|
async execute(args, exec) {
|
|
322
353
|
return run(async () => {
|
|
354
|
+
await assertWriter(exec);
|
|
323
355
|
const action = assertAction(args.action, ["add", "list", "search", "select"]);
|
|
324
356
|
const id = projectId(args, exec);
|
|
325
357
|
if (action === "add") {
|
|
@@ -372,6 +404,7 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
372
404
|
/** @param {any} args @param {any} exec */
|
|
373
405
|
async execute(args, exec) {
|
|
374
406
|
return run(async () => {
|
|
407
|
+
await assertWriter(exec);
|
|
375
408
|
const action = assertAction(args.action, ["add", "list"]);
|
|
376
409
|
const id = projectId(args, exec);
|
|
377
410
|
if (action === "add") {
|
|
@@ -411,6 +444,7 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
411
444
|
/** @param {any} args @param {any} exec */
|
|
412
445
|
async execute(args, exec) {
|
|
413
446
|
return run(async () => {
|
|
447
|
+
await assertWriter(exec);
|
|
414
448
|
const action = assertAction(args.action, ["add", "list", "resolve"]);
|
|
415
449
|
const id = projectId(args, exec);
|
|
416
450
|
if (action === "add") {
|
|
@@ -475,6 +509,7 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
475
509
|
/** @param {any} args @param {any} exec */
|
|
476
510
|
async execute(args, exec) {
|
|
477
511
|
return run(async () => {
|
|
512
|
+
await assertWriter(exec);
|
|
478
513
|
const action = assertAction(args.action, ["add", "list", "close", "reopen"]);
|
|
479
514
|
const id = projectId(args, exec);
|
|
480
515
|
if (action === "add") {
|
|
@@ -532,6 +567,7 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
532
567
|
/** @param {any} args @param {any} exec */
|
|
533
568
|
async execute(args, exec) {
|
|
534
569
|
return run(async () => {
|
|
570
|
+
await assertWriter(exec);
|
|
535
571
|
const action = assertAction(args.action, ["start", "status", "agent", "loop", "cycle"]);
|
|
536
572
|
const id = projectId(args, exec);
|
|
537
573
|
if (action === "cycle") {
|
|
@@ -638,6 +674,7 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
638
674
|
/** @param {any} args @param {any} exec */
|
|
639
675
|
async execute(args, exec) {
|
|
640
676
|
return run(async () => {
|
|
677
|
+
await assertWriter(exec);
|
|
641
678
|
const action = assertAction(args.action, ["run", "list", "loop"]);
|
|
642
679
|
const id = projectId(args, exec);
|
|
643
680
|
if (action === "run") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kangyishuai/dsh-casefile",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Evidence-first reverse-engineering workbench on top of REA: observations become citable evidence, a handoff spec pack, and recomputable acceptance checks. No bridge, no engine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|