@kangyishuai/dsh-casefile 0.4.0 → 0.5.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/lib/actions.js +76 -5
- package/lib/core/app-bundle.js +115 -0
- package/lib/core/provenance.js +66 -0
- package/lib/service.js +117 -11
- package/lib/tools.js +67 -0
- package/package.json +1 -1
package/lib/actions.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
// 分工:service.js 只做「数据根解析 + Remote 声明 + 会话记忆」;本文件承载
|
|
5
5
|
// 项目/证据/结论/功能/未知项/规格包的实际逻辑,tools.js 与 Remote 共用同一份实现。
|
|
6
6
|
|
|
7
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { join } from "node:path";
|
|
9
|
+
import { parseArchitectures, summarizeAppBundle } from "./core/app-bundle.js";
|
|
9
10
|
import { buildAttestation } from "./core/attestation.js";
|
|
10
11
|
import { buildSpecPack, redactPack, renderSpecMarkdown, writeSpecPack } from "./core/brief.js";
|
|
11
12
|
import { createCheckers } from "./core/checks.js";
|
|
@@ -61,6 +62,7 @@ export class CasefileActionError extends Error {
|
|
|
61
62
|
* dataRoot?: string,
|
|
62
63
|
* runner?: (command: string, options?: Record<string, any>) => Promise<Record<string, any>>,
|
|
63
64
|
* onWaitChange?: (state: Record<string, any> | null) => void,
|
|
65
|
+
* provenance?: () => { reaVersion?: string | null, capabilityHash?: string | null, toolNames?: readonly string[] } | null,
|
|
64
66
|
* sessions?: {
|
|
65
67
|
* create(input: { cwd: string }): Promise<{ sessionId: string }>,
|
|
66
68
|
* prompt(input: { sessionId: string, text: string }): Promise<void>,
|
|
@@ -74,9 +76,26 @@ export function createActions(options) {
|
|
|
74
76
|
const dataRoot = options.dataRoot ?? store.rootDir;
|
|
75
77
|
const sessions = options.sessions;
|
|
76
78
|
const onWaitChange = options.onWaitChange;
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
const runner = options.runner ?? null;
|
|
80
|
+
const provenance = options.provenance ?? null;
|
|
81
|
+
// checker 需要固定形状的 runner;外层 runner 更宽松,这里做一次归一。
|
|
82
|
+
const checkerRunner =
|
|
83
|
+
runner == null
|
|
84
|
+
? undefined
|
|
85
|
+
: async (/** @type {string} */ command, /** @type {any} */ runOptions) => {
|
|
86
|
+
const result = await runner(command, runOptions);
|
|
87
|
+
return {
|
|
88
|
+
exitCode:
|
|
89
|
+
typeof result?.exitCode === "number"
|
|
90
|
+
? result.exitCode
|
|
91
|
+
: typeof result?.code === "number"
|
|
92
|
+
? result.code
|
|
93
|
+
: 0,
|
|
94
|
+
stdout: String(result?.stdout ?? ""),
|
|
95
|
+
stderr: String(result?.stderr ?? ""),
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
const checkers = createCheckers({ runner: checkerRunner });
|
|
80
99
|
|
|
81
100
|
/**
|
|
82
101
|
* @param {string} projectId
|
|
@@ -136,8 +155,16 @@ export function createActions(options) {
|
|
|
136
155
|
*/
|
|
137
156
|
async openProject(input, exec) {
|
|
138
157
|
const project = store.createProject(input ?? {});
|
|
158
|
+
// 把"当时用的哪套工具"锚进项目:REA 版本 + 工具面哈希。
|
|
159
|
+
const probe = typeof provenance === "function" ? provenance() : null;
|
|
160
|
+
const anchored = probe
|
|
161
|
+
? store.updateProject(project.id, {
|
|
162
|
+
reaVersion: probe.reaVersion ?? undefined,
|
|
163
|
+
capabilityHash: probe.capabilityHash,
|
|
164
|
+
})
|
|
165
|
+
: project;
|
|
139
166
|
if (exec) this.remember(exec, project.id);
|
|
140
|
-
return
|
|
167
|
+
return anchored;
|
|
141
168
|
},
|
|
142
169
|
|
|
143
170
|
/**
|
|
@@ -1182,6 +1209,50 @@ export function createActions(options) {
|
|
|
1182
1209
|
|
|
1183
1210
|
// ---------- 覆盖率 / 关闭 / 报告(M3 收尾) ----------
|
|
1184
1211
|
|
|
1212
|
+
/**
|
|
1213
|
+
* macOS .app 勘察第一跳:读 Info.plist + 可执行架构,给一屏摘要。
|
|
1214
|
+
* 依赖 runner 调 plutil / lipo(都是系统自带);拿不到就标 null,不猜。
|
|
1215
|
+
* @param {{ path: string }} input
|
|
1216
|
+
* @returns {Promise<Record<string, any>>}
|
|
1217
|
+
*/
|
|
1218
|
+
async inspectAppBundle(input) {
|
|
1219
|
+
const appPath = String(input?.path ?? "").trim();
|
|
1220
|
+
if (appPath === "") {
|
|
1221
|
+
throw new CasefileInputError(
|
|
1222
|
+
"invalid-input",
|
|
1223
|
+
"path 不能为空(形如 /Applications/Foo.app)",
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1226
|
+
const plistPath = join(appPath, "Contents", "Info.plist");
|
|
1227
|
+
if (!existsSync(plistPath)) {
|
|
1228
|
+
throw new CasefileInputError("invalid-input", `不是 macOS 应用包:缺 ${plistPath}`);
|
|
1229
|
+
}
|
|
1230
|
+
/** @type {Record<string, any>} */
|
|
1231
|
+
const plist = JSON.parse(readFileSync(plistPath, "utf8"));
|
|
1232
|
+
const executableName =
|
|
1233
|
+
typeof plist.CFBundleExecutable === "string" ? plist.CFBundleExecutable : null;
|
|
1234
|
+
const executablePath =
|
|
1235
|
+
executableName == null ? null : join(appPath, "Contents", "MacOS", executableName);
|
|
1236
|
+
/** @type {string[]} */
|
|
1237
|
+
let architectures = [];
|
|
1238
|
+
if (executablePath != null && runner != null && existsSync(executablePath)) {
|
|
1239
|
+
try {
|
|
1240
|
+
const result = await runner(`lipo -archs ${JSON.stringify(executablePath)}`, {
|
|
1241
|
+
timeoutMs: 15000,
|
|
1242
|
+
});
|
|
1243
|
+
const out = typeof result?.stdout === "string" ? result.stdout : "";
|
|
1244
|
+
architectures = parseArchitectures(out);
|
|
1245
|
+
} catch {
|
|
1246
|
+
architectures = [];
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
return summarizeAppBundle(plist, {
|
|
1250
|
+
architectures,
|
|
1251
|
+
executablePath: executablePath ?? undefined,
|
|
1252
|
+
infoPlistPath: plistPath,
|
|
1253
|
+
});
|
|
1254
|
+
},
|
|
1255
|
+
|
|
1185
1256
|
/**
|
|
1186
1257
|
* 归档项目(非破坏性):误建或暂存的项目收起来,文件都在。
|
|
1187
1258
|
* @param {string} projectId
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// core/app-bundle.js:macOS .app 的一屏摘要(勘察第一跳)。
|
|
3
|
+
//
|
|
4
|
+
// 为什么需要:真实用过一轮,`inspect_desktop_application` 对纯原生 Swift 应用
|
|
5
|
+
// 返回 candidates=0,等于什么也没说,我只好手工 file / plutil / ls。
|
|
6
|
+
// 这里把"这是什么的 app、装了什么约束"一次说清,输出全部来自真实文件,
|
|
7
|
+
// 字段读不到就标 null,不猜。
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 从 Info.plist 的 JSON 形式里取一屏摘要。
|
|
11
|
+
* @param {Record<string, any>} plist
|
|
12
|
+
* @returns {Record<string, any>}
|
|
13
|
+
*/
|
|
14
|
+
export function summarizeInfoPlist(plist) {
|
|
15
|
+
const value = plist && typeof plist === "object" ? plist : {};
|
|
16
|
+
const exported = Array.isArray(value.UTExportedTypeDeclarations)
|
|
17
|
+
? value.UTExportedTypeDeclarations
|
|
18
|
+
: [];
|
|
19
|
+
const utis = exported
|
|
20
|
+
.map((item) => (typeof item?.UTTypeIdentifier === "string" ? item.UTTypeIdentifier : null))
|
|
21
|
+
.filter((item) => item != null);
|
|
22
|
+
const schemeHosts = Array.isArray(value.CFBundleURLTypes) ? value.CFBundleURLTypes : [];
|
|
23
|
+
const urlSchemes = schemeHosts.flatMap((item) =>
|
|
24
|
+
Array.isArray(item?.CFBundleURLSchemes) ? item.CFBundleURLSchemes.map(String) : [],
|
|
25
|
+
);
|
|
26
|
+
const docExtensions = (
|
|
27
|
+
Array.isArray(value.CFBundleDocumentTypes) ? value.CFBundleDocumentTypes : []
|
|
28
|
+
).flatMap((item) =>
|
|
29
|
+
Array.isArray(item?.CFBundleTypeExtensions) ? item.CFBundleTypeExtensions.map(String) : [],
|
|
30
|
+
);
|
|
31
|
+
const bundleId = typeof value.CFBundleIdentifier === "string" ? value.CFBundleIdentifier : null;
|
|
32
|
+
const ats = value.NSAppTransportSecurity;
|
|
33
|
+
return {
|
|
34
|
+
bundleId,
|
|
35
|
+
bundleName: typeof value.CFBundleName === "string" ? value.CFBundleName : null,
|
|
36
|
+
executable: typeof value.CFBundleExecutable === "string" ? value.CFBundleExecutable : null,
|
|
37
|
+
shortVersion:
|
|
38
|
+
typeof value.CFBundleShortVersionString === "string"
|
|
39
|
+
? value.CFBundleShortVersionString
|
|
40
|
+
: null,
|
|
41
|
+
buildVersion: typeof value.CFBundleVersion === "string" ? value.CFBundleVersion : null,
|
|
42
|
+
minSystemVersion:
|
|
43
|
+
typeof value.LSMinimumSystemVersion === "string" ? value.LSMinimumSystemVersion : null,
|
|
44
|
+
category:
|
|
45
|
+
typeof value.LSApplicationCategoryType === "string" ? value.LSApplicationCategoryType : null,
|
|
46
|
+
uiElement: value.LSUIElement === true,
|
|
47
|
+
sandboxed: value["MMKit_sandboxed"] === true || value.NSSandboxed === true || null,
|
|
48
|
+
allowsArbitraryLoads:
|
|
49
|
+
ats && typeof ats === "object" ? ats.NSAllowsArbitraryLoads === true : null,
|
|
50
|
+
urlSchemes: [...new Set(urlSchemes)],
|
|
51
|
+
documentExtensions: [...new Set(docExtensions)],
|
|
52
|
+
exportedUtis: utis,
|
|
53
|
+
utiPrefixes: [...new Set(utis.map((uti) => uti.split(".").slice(0, 2).join(".")))],
|
|
54
|
+
principalClass: typeof value.NSPrincipalClass === "string" ? value.NSPrincipalClass : null,
|
|
55
|
+
appleScriptEnabled: value.NSAppleScriptEnabled === true,
|
|
56
|
+
sdefFile:
|
|
57
|
+
typeof value.OSAScriptingDefinition === "string" ? value.OSAScriptingDefinition : null,
|
|
58
|
+
xcodeBuild: typeof value.DTXcode === "string" ? value.DTXcode : null,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 从 `lipo -archs` 输出取架构列表。
|
|
64
|
+
* @param {string} output 形如 "x86_64 arm64" 或 "Non-fat file: ... is architecture: arm64"
|
|
65
|
+
* @returns {string[]}
|
|
66
|
+
*/
|
|
67
|
+
export function parseArchitectures(output) {
|
|
68
|
+
const text = String(output ?? "").trim();
|
|
69
|
+
if (text === "") return [];
|
|
70
|
+
const nonFat = text.match(/is architecture:\s*(\S+)/u);
|
|
71
|
+
if (nonFat) return [nonFat[1]];
|
|
72
|
+
return [...new Set(text.split(/\s+/u).filter((item) => /^[\w-]+$/u.test(item)))];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 归属域一致性:bundle id 与导出 UTI 的域前缀是否同一套。
|
|
77
|
+
* 这不是"对错"判断,而是把真实存在的不一致摆出来给验收人看。
|
|
78
|
+
* @param {Record<string, any>} summary
|
|
79
|
+
* @returns {{ consistent: boolean | null, bundleDomain: string | null, utiDomains: string[] }}
|
|
80
|
+
*/
|
|
81
|
+
export function checkDomainConsistency(summary) {
|
|
82
|
+
const bundleId = typeof summary?.bundleId === "string" ? summary.bundleId : null;
|
|
83
|
+
/** @type {string[]} */
|
|
84
|
+
const utiDomains = Array.isArray(summary?.utiPrefixes) ? summary.utiPrefixes.map(String) : [];
|
|
85
|
+
if (bundleId == null || utiDomains.length === 0) {
|
|
86
|
+
return {
|
|
87
|
+
consistent: null,
|
|
88
|
+
bundleDomain: bundleId == null ? null : bundleId.split(".").slice(0, 2).join("."),
|
|
89
|
+
utiDomains,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const bundleDomain = bundleId.split(".").slice(0, 2).join(".");
|
|
93
|
+
return {
|
|
94
|
+
consistent: utiDomains.every((domain) => domain === bundleDomain),
|
|
95
|
+
bundleDomain,
|
|
96
|
+
utiDomains,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 组合成一屏摘要。
|
|
102
|
+
* @param {Record<string, any>} plist
|
|
103
|
+
* @param {{ architectures?: string[], executablePath?: string, infoPlistPath?: string }} facts
|
|
104
|
+
* @returns {Record<string, any>}
|
|
105
|
+
*/
|
|
106
|
+
export function summarizeAppBundle(plist, facts) {
|
|
107
|
+
const summary = summarizeInfoPlist(plist);
|
|
108
|
+
return {
|
|
109
|
+
...summary,
|
|
110
|
+
architectures: Array.isArray(facts?.architectures) ? facts.architectures : [],
|
|
111
|
+
executablePath: facts?.executablePath ?? null,
|
|
112
|
+
infoPlistPath: facts?.infoPlistPath ?? null,
|
|
113
|
+
domainConsistency: checkDomainConsistency(summary),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// core/provenance.js:把"当时用的哪套工具"锚进项目。
|
|
3
|
+
//
|
|
4
|
+
// 为什么需要:案卷的价值在于半年后别人还能复算。只写"我跑过 REA"不够——
|
|
5
|
+
// 要记下 REA 版本和当时的工具面(capability hash)。工具面变了,同样的
|
|
6
|
+
// 结论可能不再可复现。
|
|
7
|
+
//
|
|
8
|
+
// 版本从哪来:宿主没有暴露 MCP 服务器版本,所以从用户 profile 的 patch 文件里
|
|
9
|
+
// 解析 `rea-agents@x.y.z`(那是实际被启动的那个包);解析不到就留 null 并说明,
|
|
10
|
+
// 不猜。
|
|
11
|
+
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 从 cordis patch 文本里解析 REA 版本(`rea-agents@1.2.3` 或 `npx -y rea-agents@1.2.3`)。
|
|
16
|
+
* @param {string} text
|
|
17
|
+
* @returns {string | null}
|
|
18
|
+
*/
|
|
19
|
+
export function parseReaVersion(text) {
|
|
20
|
+
if (typeof text !== "string" || text === "") return null;
|
|
21
|
+
const match = text.match(/rea-agents(?:@|\/)(\d+\.\d+\.\d+(?:[-+][\w.-]+)?)/u);
|
|
22
|
+
return match ? match[1] : null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 从已安装的 rea-agents package.json 文本里取版本。
|
|
27
|
+
* @param {string} text
|
|
28
|
+
* @returns {string | null}
|
|
29
|
+
*/
|
|
30
|
+
export function parsePackageVersion(text) {
|
|
31
|
+
if (typeof text !== "string" || text === "") return null;
|
|
32
|
+
try {
|
|
33
|
+
const value = JSON.parse(text);
|
|
34
|
+
const version = value?.version;
|
|
35
|
+
return typeof version === "string" && version !== "" ? version : null;
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 工具面哈希:同一套工具(名字集合)得到同一个值。
|
|
43
|
+
* 只取名字,不取描述——描述会随版本微调,名字集合才是"能不能做这件事"的边界。
|
|
44
|
+
* @param {readonly string[]} toolNames
|
|
45
|
+
* @returns {string}
|
|
46
|
+
*/
|
|
47
|
+
export function capabilityHash(toolNames) {
|
|
48
|
+
const names = [...new Set(toolNames.map((name) => String(name)))].sort();
|
|
49
|
+
return createHash("sha256").update(names.join("\n")).digest("hex").slice(0, 16);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 组装项目溯源:REA 版本 + 工具面哈希 + 探测时间。
|
|
54
|
+
* @param {{ toolNames?: readonly string[], reaVersion?: string | null }} input
|
|
55
|
+
* @returns {{ reaVersion: string | null, capabilityHash: string, reaToolCount: number, probedAt: string }}
|
|
56
|
+
*/
|
|
57
|
+
export function buildProvenance(input) {
|
|
58
|
+
const names = Array.isArray(input.toolNames) ? input.toolNames : [];
|
|
59
|
+
return {
|
|
60
|
+
reaVersion:
|
|
61
|
+
typeof input.reaVersion === "string" && input.reaVersion !== "" ? input.reaVersion : null,
|
|
62
|
+
capabilityHash: capabilityHash(names),
|
|
63
|
+
reaToolCount: new Set(names).size,
|
|
64
|
+
probedAt: new Date().toISOString(),
|
|
65
|
+
};
|
|
66
|
+
}
|
package/lib/service.js
CHANGED
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
// 业务逻辑全部在 ./actions.js(可单测);Remote 方法必须声明在**被导出的类自身原型**上
|
|
4
4
|
// (否则 /api/casefile/* 返回 404,见 docs/runtime/0.2.1-rc.5.md §6.10)。
|
|
5
5
|
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
6
9
|
import { Remote, RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
7
10
|
|
|
8
11
|
import { createActions } from "./actions.js";
|
|
9
12
|
import { diffCapabilities, gradeCapabilities } from "./core/manifest.js";
|
|
13
|
+
import { buildProvenance, parsePackageVersion, parseReaVersion } from "./core/provenance.js";
|
|
10
14
|
import { CaseStore } from "./core/store.js";
|
|
11
15
|
import { buildToolDefinitions } from "./tools.js";
|
|
12
16
|
|
|
@@ -93,14 +97,23 @@ export class CasefileService extends TypertRemoteService {
|
|
|
93
97
|
/** 会话 → 最近打开的项目(工具省略 projectId 时用)。 @type {Map<string, string>} */
|
|
94
98
|
this.currentProject = new Map();
|
|
95
99
|
this.accessWait = null;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
// casefile 自己起子进程读系统信息(plutil/lipo);这类只读命令不走会话终端,
|
|
101
|
+
// 避免污染用户 shell 历史,也不需要交互。
|
|
102
|
+
this.runner = async (/** @type {string} */ command, /** @type {any} */ options) => {
|
|
103
|
+
const { exec } = await import("node:child_process");
|
|
104
|
+
return await new Promise((resolve, reject) => {
|
|
105
|
+
exec(command, { timeout: options?.timeoutMs ?? 15000 }, (error, stdout, stderr) => {
|
|
106
|
+
if (error && !stdout) reject(error);
|
|
107
|
+
else
|
|
108
|
+
resolve({
|
|
109
|
+
stdout: String(stdout ?? ""),
|
|
110
|
+
stderr: String(stderr ?? ""),
|
|
111
|
+
code: error ? 1 : 0,
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
this.actions = createActions(this.actionOptions());
|
|
104
117
|
this.installSessions();
|
|
105
118
|
this.installTools();
|
|
106
119
|
this.logger.info?.(`[casefile] loaded, dataRoot=${this.dataRoot}`);
|
|
@@ -122,18 +135,107 @@ export class CasefileService extends TypertRemoteService {
|
|
|
122
135
|
}
|
|
123
136
|
}
|
|
124
137
|
|
|
138
|
+
/**
|
|
139
|
+
* 探测当前 REA 版本与工具面哈希,用于把"当时的工具"锚进项目。
|
|
140
|
+
* 版本来源:profile patch 文件里实际被启动的 `rea-agents@x.y.z`;
|
|
141
|
+
* 找不到就留 null(不猜),工具面哈希始终可算。
|
|
142
|
+
* @returns {{ reaVersion: string | null, capabilityHash: string, reaToolCount: number, probedAt: string }}
|
|
143
|
+
*/
|
|
144
|
+
provenance() {
|
|
145
|
+
let toolNames = [];
|
|
146
|
+
try {
|
|
147
|
+
const tools = this.ctx.get?.("tools");
|
|
148
|
+
const definitions = tools?.definitions?.() ?? [];
|
|
149
|
+
toolNames = definitions
|
|
150
|
+
.map((/** @type {any} */ item) => String(item?.name ?? ""))
|
|
151
|
+
.filter((/** @type {string} */ name) => name.startsWith("mcp__rea__"));
|
|
152
|
+
} catch {
|
|
153
|
+
toolNames = [];
|
|
154
|
+
}
|
|
155
|
+
return buildProvenance({ toolNames, reaVersion: this.detectReaVersion() });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 从本机 DSH patch 文件 / 全局安装里找 REA 版本。
|
|
160
|
+
* @returns {string | null}
|
|
161
|
+
*/
|
|
162
|
+
detectReaVersion() {
|
|
163
|
+
const paths = [
|
|
164
|
+
process.env.DSH_HOME ? join(process.env.DSH_HOME, "cordis.patch.yml") : null,
|
|
165
|
+
join(homedir(), ".dsh", "cordis.patch.yml"),
|
|
166
|
+
].filter((item) => typeof item === "string");
|
|
167
|
+
for (const patchPath of paths) {
|
|
168
|
+
try {
|
|
169
|
+
if (!existsSync(patchPath)) continue;
|
|
170
|
+
const found = parseReaVersion(readFileSync(patchPath, "utf8"));
|
|
171
|
+
if (found != null) return found;
|
|
172
|
+
} catch {
|
|
173
|
+
// 读不到就继续试下一个来源
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
const meta = join(
|
|
178
|
+
homedir(),
|
|
179
|
+
".npm-global",
|
|
180
|
+
"lib",
|
|
181
|
+
"node_modules",
|
|
182
|
+
"rea-agents",
|
|
183
|
+
"package.json",
|
|
184
|
+
);
|
|
185
|
+
if (existsSync(meta)) return parsePackageVersion(readFileSync(meta, "utf8"));
|
|
186
|
+
} catch {
|
|
187
|
+
// 忽略
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** @returns {Promise<Record<string, any>>} */
|
|
193
|
+
async provenanceInfo() {
|
|
194
|
+
return this.provenance();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 应用包摘要(勘察第一跳)。
|
|
199
|
+
* @param {{ path: string }} input
|
|
200
|
+
* @returns {Promise<Record<string, any>>}
|
|
201
|
+
*/
|
|
202
|
+
async inspectApp(input) {
|
|
203
|
+
try {
|
|
204
|
+
return await this.actions.inspectAppBundle(input);
|
|
205
|
+
} catch (error) {
|
|
206
|
+
fail(error);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
125
210
|
/**
|
|
126
211
|
* 拿到会话服务后重建 actions(builder 需要 create/prompt/wait)。
|
|
127
212
|
*/
|
|
213
|
+
/**
|
|
214
|
+
* createActions 的公共选项(构造函数与 installSessions 必须共用)。
|
|
215
|
+
* @returns {Parameters<typeof createActions>[0]}
|
|
216
|
+
*/
|
|
217
|
+
actionOptions() {
|
|
218
|
+
return {
|
|
219
|
+
store: this.store,
|
|
220
|
+
currentProject: this.currentProject,
|
|
221
|
+
dataRoot: this.dataRoot,
|
|
222
|
+
onWaitChange: (/** @type {any} */ state) => {
|
|
223
|
+
this.accessWait = state;
|
|
224
|
+
},
|
|
225
|
+
provenance: () => this.provenance(),
|
|
226
|
+
runner: this.runner,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
128
230
|
installSessions() {
|
|
129
231
|
try {
|
|
130
232
|
this.ctx.inject?.(/** @type {any} */ (["sessionController"]), (/** @type {any} */ scope) => {
|
|
131
233
|
const controller = scope.sessionController;
|
|
132
234
|
if (!controller) return;
|
|
235
|
+
// 注意:这里必须和构造函数用同一份选项——漏掉 onWaitChange 会让
|
|
236
|
+
// 等待登录状态永远不生效(实测踩过:await-login 期间 accessState 恒为 false)。
|
|
133
237
|
this.actions = createActions({
|
|
134
|
-
|
|
135
|
-
currentProject: this.currentProject,
|
|
136
|
-
dataRoot: this.dataRoot,
|
|
238
|
+
...this.actionOptions(),
|
|
137
239
|
sessions: {
|
|
138
240
|
create: async (input) => {
|
|
139
241
|
const created = await controller.create({ cwd: input.cwd });
|
|
@@ -217,6 +319,8 @@ export class CasefileService extends TypertRemoteService {
|
|
|
217
319
|
overview: () => this.actions.overview(),
|
|
218
320
|
awaitLogin: (projectId, input) => this.actions.awaitLogin(projectId, input),
|
|
219
321
|
accessState: () => this.accessState(),
|
|
322
|
+
provenanceInfo: () => this.provenance(),
|
|
323
|
+
inspectApp: (input) => this.actions.inspectAppBundle(input),
|
|
220
324
|
archiveProject: (projectId, options) => this.actions.archiveProject(projectId, options),
|
|
221
325
|
dropProject: (projectId, options) => this.actions.dropProject(projectId, options),
|
|
222
326
|
runCycle: (projectId, input) => this.actions.runCycle(projectId, input),
|
|
@@ -719,6 +823,8 @@ declareRemote(CasefileService, "closeObligation");
|
|
|
719
823
|
declareRemote(CasefileService, "reopenObligation");
|
|
720
824
|
declareRemote(CasefileService, "overview");
|
|
721
825
|
declareRemote(CasefileService, "accessState");
|
|
826
|
+
declareRemote(CasefileService, "inspectApp");
|
|
827
|
+
declareRemote(CasefileService, "provenanceInfo");
|
|
722
828
|
declareRemote(CasefileService, "archiveProject");
|
|
723
829
|
declareRemote(CasefileService, "dropProject");
|
|
724
830
|
declareRemote(CasefileService, "awaitLogin");
|
package/lib/tools.js
CHANGED
|
@@ -18,6 +18,7 @@ export const TOOL_NAMES = /** @type {const} */ ({
|
|
|
18
18
|
unknown: "case_unknown",
|
|
19
19
|
obligation: "case_obligation",
|
|
20
20
|
access: "case_access",
|
|
21
|
+
app: "case_app",
|
|
21
22
|
build: "case_build",
|
|
22
23
|
check: "case_check",
|
|
23
24
|
brief: "case_brief",
|
|
@@ -619,6 +620,72 @@ export function buildToolDefinitions(handlers, projectOf) {
|
|
|
619
620
|
},
|
|
620
621
|
},
|
|
621
622
|
|
|
623
|
+
{
|
|
624
|
+
name: TOOL_NAMES.app,
|
|
625
|
+
description:
|
|
626
|
+
"应用勘察第一跳:inspect 读 macOS .app 的 Info.plist 与可执行架构,一次给出一屏摘要(bundle id/版本/沙盒/ATS/URL scheme/UTI 归属),并可选写入一条证据。",
|
|
627
|
+
parameters: {
|
|
628
|
+
type: "object",
|
|
629
|
+
additionalProperties: false,
|
|
630
|
+
properties: {
|
|
631
|
+
action: { type: "string", enum: ["inspect"] },
|
|
632
|
+
projectId: PROJECT_ID,
|
|
633
|
+
path: { type: "string", description: "绝对路径,形如 /Applications/Foo.app" },
|
|
634
|
+
record: {
|
|
635
|
+
type: "boolean",
|
|
636
|
+
description: "默认 true:把摘要写成一条结构证据(authority=shipped-artifact)",
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
required: ["action"],
|
|
640
|
+
},
|
|
641
|
+
output: { schema: TOOL_OUTPUT_SCHEMA, render: renderToolResult },
|
|
642
|
+
/** @param {any} args @param {any} exec */
|
|
643
|
+
async execute(args, exec) {
|
|
644
|
+
return run(async () => {
|
|
645
|
+
await assertWriter(exec);
|
|
646
|
+
assertAction(args.action, ["inspect"]);
|
|
647
|
+
if (typeof args.path !== "string" || args.path.trim() === "") {
|
|
648
|
+
throw Object.assign(new Error("inspect 需要 path(形如 /Applications/Foo.app)"), {
|
|
649
|
+
code: "invalid-input",
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
const summary = await handlers.inspectApp({ path: args.path });
|
|
653
|
+
const id = args.record === false ? null : projectId(args, exec);
|
|
654
|
+
let evidence = null;
|
|
655
|
+
if (id != null) {
|
|
656
|
+
evidence = await handlers.addEvidence(
|
|
657
|
+
id,
|
|
658
|
+
{
|
|
659
|
+
kind: "structure",
|
|
660
|
+
authority: "shipped-artifact",
|
|
661
|
+
confidence: "observed",
|
|
662
|
+
summary: `应用包摘要(${summary.bundleId ?? "未知 bundle id"}):版本 ${summary.shortVersion ?? "?"}(build ${summary.buildVersion ?? "?"})、架构 ${(summary.architectures ?? []).join("/") || "未知"}、沙盒 ${summary.sandboxed === true ? "是" : summary.sandboxed === false ? "否" : "未声明"}、ATS 任意加载 ${summary.allowsArbitraryLoads === true ? "开启" : "关闭/未声明"}、UTI 域一致性 ${summary.domainConsistency?.consistent === true ? "一致" : summary.domainConsistency?.consistent === false ? "不一致" : "无法判断"}`,
|
|
663
|
+
limitations: [
|
|
664
|
+
"只读 Info.plist 与可执行架构;plist 声明不等于运行时行为",
|
|
665
|
+
"未校验签名有效性,未进入二进制本体",
|
|
666
|
+
],
|
|
667
|
+
refs: [String(args.path)],
|
|
668
|
+
producer: {
|
|
669
|
+
tool: "casefile/app-bundle",
|
|
670
|
+
version: "1",
|
|
671
|
+
mode: "archive",
|
|
672
|
+
outputKind: "json-summary",
|
|
673
|
+
accessConfirmedByUser: true,
|
|
674
|
+
confirmationNote: "读取本机已安装应用包的静态信息(plutil/lipo),未执行该应用",
|
|
675
|
+
},
|
|
676
|
+
},
|
|
677
|
+
exec,
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
return {
|
|
681
|
+
summary: `应用:${summary.bundleId ?? "?"} · ${summary.shortVersion ?? "?"} · ${(summary.architectures ?? []).join("/") || "架构未知"}`,
|
|
682
|
+
app: summary,
|
|
683
|
+
evidenceId: evidence?.id ?? null,
|
|
684
|
+
};
|
|
685
|
+
});
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
|
|
622
689
|
{
|
|
623
690
|
name: TOOL_NAMES.build,
|
|
624
691
|
description:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kangyishuai/dsh-casefile",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|