@kangyishuai/dsh-casefile 0.5.1 → 0.7.0
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 -3
- package/README.zh-CN.md +6 -3
- package/lib/actions.js +296 -7
- package/lib/client.js +16 -0
- package/lib/core/autonomy.js +143 -0
- package/lib/core/bundle.js +136 -0
- package/lib/core/checks.js +56 -5
- package/lib/core/ingest.js +213 -0
- package/lib/core/model.js +2 -0
- package/lib/core/png.js +33 -0
- package/lib/core/report.js +142 -0
- package/lib/core/store.js +7 -0
- package/lib/service.js +90 -8
- package/lib/tools.js +103 -1
- package/package.json +1 -1
package/lib/service.js
CHANGED
|
@@ -70,6 +70,8 @@ function fail(error) {
|
|
|
70
70
|
"project-exists",
|
|
71
71
|
"not-found",
|
|
72
72
|
"confirm-required",
|
|
73
|
+
"autonomy-blocked",
|
|
74
|
+
"autonomy-stop",
|
|
73
75
|
"project-not-found",
|
|
74
76
|
"obligationTooTall",
|
|
75
77
|
"coverage-not-met",
|
|
@@ -99,18 +101,36 @@ export class CasefileService extends TypertRemoteService {
|
|
|
99
101
|
this.accessWait = null;
|
|
100
102
|
// casefile 自己起子进程读系统信息(plutil/lipo);这类只读命令不走会话终端,
|
|
101
103
|
// 避免污染用户 shell 历史,也不需要交互。
|
|
104
|
+
// casefile 自己起子进程读系统信息 / 跑 checker 命令。**不要**因为非零退出就 reject:
|
|
105
|
+
// checker 需要拿到「退出码是多少」来判定 fail,reject 会把它变成 internal 错误。
|
|
106
|
+
// 只有 spawn 级别失败(命令不存在 / 无权限)才算真的无法执行。
|
|
102
107
|
this.runner = async (/** @type {string} */ command, /** @type {any} */ options) => {
|
|
103
108
|
const { exec } = await import("node:child_process");
|
|
104
109
|
return await new Promise((resolve, reject) => {
|
|
105
|
-
exec(
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
exec(
|
|
111
|
+
command,
|
|
112
|
+
{ timeout: options?.timeoutMs ?? 15000, cwd: options?.cwd, maxBuffer: 8 * 1024 * 1024 },
|
|
113
|
+
(error, stdout, stderr) => {
|
|
114
|
+
const code = /** @type {any} */ (error)?.code;
|
|
115
|
+
// exec 把「命令不存在 / 不可执行」报成退出码 127 / 126(数字,不是 ENOENT 字符串),
|
|
116
|
+
// 且此时没有任何输出。这不是"命令跑了但失败",而是"根本没跑起来"。
|
|
117
|
+
const spawnFailed =
|
|
118
|
+
typeof code === "string"
|
|
119
|
+
? /ENOENT|EACCES|EPERM/u.test(code)
|
|
120
|
+
: (code === 127 || code === 126) && !stdout && !stderr;
|
|
121
|
+
if (spawnFailed) {
|
|
122
|
+
reject(error);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const killed = Boolean(error && /** @type {any} */ (error).killed === true);
|
|
108
126
|
resolve({
|
|
127
|
+
exitCode: killed ? null : typeof code === "number" ? code : error ? 1 : 0,
|
|
109
128
|
stdout: String(stdout ?? ""),
|
|
110
129
|
stderr: String(stderr ?? ""),
|
|
111
|
-
|
|
130
|
+
killed,
|
|
112
131
|
});
|
|
113
|
-
|
|
132
|
+
},
|
|
133
|
+
);
|
|
114
134
|
});
|
|
115
135
|
};
|
|
116
136
|
this.actions = createActions(this.actionOptions());
|
|
@@ -328,7 +348,12 @@ export class CasefileService extends TypertRemoteService {
|
|
|
328
348
|
this.store.listBuilderSessions().has(String(sessionId ?? "")),
|
|
329
349
|
closeProject: (projectId, options) => this.actions.closeProject(projectId, options),
|
|
330
350
|
closePreview: (projectId, options) => this.actions.closePreview(projectId, options),
|
|
331
|
-
exportReport: (projectId) => this.actions.exportReport(projectId),
|
|
351
|
+
exportReport: (projectId, options) => this.actions.exportReport(projectId, options),
|
|
352
|
+
exportBundle: (projectId, options) => this.actions.exportBundle(projectId, options),
|
|
353
|
+
ingestReport: (projectId, payload, options) =>
|
|
354
|
+
this.actions.ingestReport(projectId, payload, options),
|
|
355
|
+
setAutonomy: (projectId, input) => this.actions.setAutonomy(projectId, input),
|
|
356
|
+
autonomyStatus: (projectId) => this.actions.autonomyStatus(projectId),
|
|
332
357
|
advanceLoop: (projectId, input) => this.actions.advanceLoop(projectId, input),
|
|
333
358
|
startBuilder: (projectId, input) => this.actions.startBuilder(projectId, input),
|
|
334
359
|
awaitBuilder: (projectId, input) => this.actions.awaitBuilder(projectId, input),
|
|
@@ -644,11 +669,64 @@ export class CasefileService extends TypertRemoteService {
|
|
|
644
669
|
|
|
645
670
|
/**
|
|
646
671
|
* @param {string} projectId
|
|
672
|
+
* @param {any} payload
|
|
673
|
+
* @param {{ dryRun?: boolean }} [options]
|
|
674
|
+
* @returns {Promise<Record<string, any>>}
|
|
675
|
+
*/
|
|
676
|
+
async ingestReport(projectId, payload, options) {
|
|
677
|
+
try {
|
|
678
|
+
return await this.actions.ingestReport(projectId, payload, options ?? {});
|
|
679
|
+
} catch (error) {
|
|
680
|
+
fail(error);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* @param {string} projectId
|
|
686
|
+
* @param {{ level?: string, budget?: Record<string, any> | null }} input
|
|
687
|
+
* @returns {Promise<Record<string, any>>}
|
|
688
|
+
*/
|
|
689
|
+
async setAutonomy(projectId, input) {
|
|
690
|
+
try {
|
|
691
|
+
return await this.actions.setAutonomy(projectId, input ?? {});
|
|
692
|
+
} catch (error) {
|
|
693
|
+
fail(error);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* @param {string} projectId
|
|
699
|
+
* @returns {Promise<Record<string, any>>}
|
|
700
|
+
*/
|
|
701
|
+
async autonomyStatus(projectId) {
|
|
702
|
+
try {
|
|
703
|
+
return await this.actions.autonomyStatus(projectId);
|
|
704
|
+
} catch (error) {
|
|
705
|
+
fail(error);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* @param {string} projectId
|
|
711
|
+
* @param {{ redact?: boolean }} [options]
|
|
712
|
+
* @returns {Promise<Record<string, any>>}
|
|
713
|
+
*/
|
|
714
|
+
async exportBundle(projectId, options) {
|
|
715
|
+
try {
|
|
716
|
+
return await this.actions.exportBundle(projectId, options ?? {});
|
|
717
|
+
} catch (error) {
|
|
718
|
+
fail(error);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* @param {string} projectId
|
|
724
|
+
* @param {{ format?: "md" | "html" | "both" }} [options]
|
|
647
725
|
* @returns {Promise<Record<string, any>>}
|
|
648
726
|
*/
|
|
649
|
-
async exportReport(projectId) {
|
|
727
|
+
async exportReport(projectId, options) {
|
|
650
728
|
try {
|
|
651
|
-
return await this.actions.exportReport(projectId);
|
|
729
|
+
return await this.actions.exportReport(projectId, options);
|
|
652
730
|
} catch (error) {
|
|
653
731
|
fail(error);
|
|
654
732
|
}
|
|
@@ -831,6 +909,10 @@ declareRemote(CasefileService, "awaitLogin");
|
|
|
831
909
|
declareRemote(CasefileService, "runCycle");
|
|
832
910
|
declareRemote(CasefileService, "closeProject");
|
|
833
911
|
declareRemote(CasefileService, "exportReport");
|
|
912
|
+
declareRemote(CasefileService, "exportBundle");
|
|
913
|
+
declareRemote(CasefileService, "ingestReport");
|
|
914
|
+
declareRemote(CasefileService, "setAutonomy");
|
|
915
|
+
declareRemote(CasefileService, "autonomyStatus");
|
|
834
916
|
declareRemote(CasefileService, "advanceLoop");
|
|
835
917
|
declareRemote(CasefileService, "startBuilder");
|
|
836
918
|
declareRemote(CasefileService, "awaitBuilder");
|
package/lib/tools.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// 让模型读到稳定错误码并自行纠正;
|
|
8
8
|
// - 每个工具都接受 projectId;省略时用「本会话最近打开的项目」(由 service 维护)。
|
|
9
9
|
|
|
10
|
+
import { describeIngestSchema } from "./core/ingest.js";
|
|
10
11
|
import { renderToolResult, TOOL_OUTPUT_SCHEMA } from "./tool-schema.js";
|
|
11
12
|
|
|
12
13
|
/** 六个工具名(文档、测试、冒烟共用)。 */
|
|
@@ -19,6 +20,7 @@ export const TOOL_NAMES = /** @type {const} */ ({
|
|
|
19
20
|
obligation: "case_obligation",
|
|
20
21
|
access: "case_access",
|
|
21
22
|
app: "case_app",
|
|
23
|
+
ingest: "case_ingest",
|
|
22
24
|
build: "case_build",
|
|
23
25
|
check: "case_check",
|
|
24
26
|
brief: "case_brief",
|
|
@@ -173,6 +175,30 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
173
175
|
patch: { type: "object", description: "update 时的字段(title/authTier/scope/state)" },
|
|
174
176
|
minCoverage: { type: "number", description: "close 时的覆盖率下限(默认 1)" },
|
|
175
177
|
reason: { type: "string", description: "archive 时的原因(进审计)" },
|
|
178
|
+
format: {
|
|
179
|
+
type: "string",
|
|
180
|
+
enum: ["md", "html", "both"],
|
|
181
|
+
description: "report 时的输出格式:md(默认)/ html(单文件、可外发归档)/ both",
|
|
182
|
+
},
|
|
183
|
+
level: {
|
|
184
|
+
type: "string",
|
|
185
|
+
enum: ["L0", "L1", "L2", "L3"],
|
|
186
|
+
description: "autonomy 动作的目标级别;L3 需 scope=selected 且义务全有检查配方",
|
|
187
|
+
},
|
|
188
|
+
budget: {
|
|
189
|
+
type: "object",
|
|
190
|
+
additionalProperties: false,
|
|
191
|
+
description: "L3 预算:maxRounds / maxBuilds / maxWallClockMs,缺项用默认",
|
|
192
|
+
properties: {
|
|
193
|
+
maxRounds: { type: "integer" },
|
|
194
|
+
maxBuilds: { type: "integer" },
|
|
195
|
+
maxWallClockMs: { type: "integer" },
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
redact: {
|
|
199
|
+
type: "boolean",
|
|
200
|
+
description: "bundle 时是否脱敏(默认 true)",
|
|
201
|
+
},
|
|
176
202
|
confirm: {
|
|
177
203
|
type: "boolean",
|
|
178
204
|
description: "drop 时必须传 true:把整个项目目录移进 trash(可手动移回)",
|
|
@@ -235,6 +261,30 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
235
261
|
summary: `项目已关闭(覆盖率 ${(preview.coverage.ratio * 100).toFixed(0)}%)`,
|
|
236
262
|
};
|
|
237
263
|
}
|
|
264
|
+
case "autonomy": {
|
|
265
|
+
if (args.level == null) {
|
|
266
|
+
const status = await handlers.autonomyStatus(projectId(args, exec));
|
|
267
|
+
return {
|
|
268
|
+
autonomy: status.autonomy,
|
|
269
|
+
unlock: status.unlock,
|
|
270
|
+
summary: `当前 ${status.autonomy.level}${status.unlock.ok ? "(可升 L3)" : `(不可升 L3:${status.unlock.blockers.join("、")})`}`,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
const updated = await handlers.setAutonomy(projectId(args, exec), {
|
|
274
|
+
level: args.level,
|
|
275
|
+
budget: args.budget,
|
|
276
|
+
});
|
|
277
|
+
return {
|
|
278
|
+
...updated,
|
|
279
|
+
summary: `自主性已设为 ${updated.autonomy.level}`,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
case "bundle": {
|
|
283
|
+
const bundle = await handlers.exportBundle(projectId(args, exec), {
|
|
284
|
+
redact: args.redact,
|
|
285
|
+
});
|
|
286
|
+
return bundle;
|
|
287
|
+
}
|
|
238
288
|
case "archive": {
|
|
239
289
|
const archived = await handlers.archiveProject(projectId(args, exec), {
|
|
240
290
|
reason: args.reason,
|
|
@@ -251,7 +301,13 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
251
301
|
};
|
|
252
302
|
}
|
|
253
303
|
case "report": {
|
|
254
|
-
|
|
304
|
+
const exported = await handlers.exportReport(projectId(args, exec), {
|
|
305
|
+
format: args.format,
|
|
306
|
+
});
|
|
307
|
+
return {
|
|
308
|
+
...exported,
|
|
309
|
+
summary: `报告已写入 ${exported.path}(${(exported.files ?? []).join(" / ")})`,
|
|
310
|
+
};
|
|
255
311
|
}
|
|
256
312
|
default:
|
|
257
313
|
throw Object.assign(new Error(`未知 action:${String(args.action)}`), {
|
|
@@ -536,6 +592,12 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
536
592
|
items: { type: "string" },
|
|
537
593
|
description: "挂到哪些功能上(用于按功能覆盖率)",
|
|
538
594
|
},
|
|
595
|
+
claimIds: {
|
|
596
|
+
type: "array",
|
|
597
|
+
items: { type: "string" },
|
|
598
|
+
description:
|
|
599
|
+
"这条义务验证的是哪些结论(交接给其他 agent 时用来判断「哪条结论还没人验」)",
|
|
600
|
+
},
|
|
539
601
|
},
|
|
540
602
|
required: ["statement"],
|
|
541
603
|
},
|
|
@@ -686,6 +748,46 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
686
748
|
},
|
|
687
749
|
},
|
|
688
750
|
|
|
751
|
+
{
|
|
752
|
+
name: TOOL_NAMES.ingest,
|
|
753
|
+
description:
|
|
754
|
+
"外部报告摄入:ingest 把别的 agent(如 Craft)产出的报告按通用契约写进案卷(只记录、不背书);schema 返回契约说明,便于对方生成正确格式。",
|
|
755
|
+
parameters: {
|
|
756
|
+
type: "object",
|
|
757
|
+
additionalProperties: false,
|
|
758
|
+
properties: {
|
|
759
|
+
action: { type: "string", enum: ["ingest", "schema"] },
|
|
760
|
+
projectId: PROJECT_ID,
|
|
761
|
+
dryRun: { type: "boolean", description: "ingest 时只预演,不写盘" },
|
|
762
|
+
payload: {
|
|
763
|
+
type: "object",
|
|
764
|
+
description:
|
|
765
|
+
"契约见 action=schema 的返回;claims.evidenceIds 用本次 evidence 的数组下标",
|
|
766
|
+
},
|
|
767
|
+
},
|
|
768
|
+
required: ["action"],
|
|
769
|
+
},
|
|
770
|
+
output: { schema: TOOL_OUTPUT_SCHEMA, render: renderToolResult },
|
|
771
|
+
/** @param {any} args @param {any} exec */
|
|
772
|
+
async execute(args, exec) {
|
|
773
|
+
return run(async () => {
|
|
774
|
+
await assertWriter(exec);
|
|
775
|
+
const action = assertAction(args.action, ["ingest", "schema"]);
|
|
776
|
+
if (action === "schema") {
|
|
777
|
+
return { schema: describeIngestSchema(), summary: "摄入契约 v1(见 schema 字段)" };
|
|
778
|
+
}
|
|
779
|
+
if (args.payload == null) {
|
|
780
|
+
throw Object.assign(new Error("ingest 需要 payload(契约见 action=schema)"), {
|
|
781
|
+
code: "invalid-input",
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
return await handlers.ingestReport(projectId(args, exec), args.payload, {
|
|
785
|
+
dryRun: args.dryRun,
|
|
786
|
+
});
|
|
787
|
+
});
|
|
788
|
+
},
|
|
789
|
+
},
|
|
790
|
+
|
|
689
791
|
{
|
|
690
792
|
name: TOOL_NAMES.build,
|
|
691
793
|
description:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kangyishuai/dsh-casefile",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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",
|