@kangyishuai/dsh-casefile 0.4.1 → 0.5.1

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 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,46 @@ 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 checkers = createCheckers(
78
- /** @type {any} */ (options.runner ? { runner: options.runner } : {}),
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 });
99
+
100
+ /**
101
+ * 把 Info.plist(XML 或二进制)转成 JSON 对象。
102
+ * @param {string} plistPath
103
+ * @returns {Promise<Record<string, any>>}
104
+ */
105
+ const readPlistAsJson = async (/** @type {string} */ plistPath) => {
106
+ if (runner != null) {
107
+ const result = await runner(`plutil -convert json -o - ${JSON.stringify(plistPath)}`);
108
+ const text = String(result?.stdout ?? "").trim();
109
+ if (text !== "") return JSON.parse(text);
110
+ }
111
+ // 没有 runner 或 plutil 没输出:只在文件本身就是 JSON 形式时接受
112
+ const raw = readFileSync(plistPath, "utf8").trim();
113
+ if (raw.startsWith("{")) return JSON.parse(raw);
114
+ throw new CasefileInputError(
115
+ "invalid-input",
116
+ "无法解析 Info.plist:它可能是 XML 或二进制,需要在 macOS 上用 plutil 转换(runner 不可用)",
117
+ );
118
+ };
80
119
 
81
120
  /**
82
121
  * @param {string} projectId
@@ -136,8 +175,16 @@ export function createActions(options) {
136
175
  */
137
176
  async openProject(input, exec) {
138
177
  const project = store.createProject(input ?? {});
178
+ // 把"当时用的哪套工具"锚进项目:REA 版本 + 工具面哈希。
179
+ const probe = typeof provenance === "function" ? provenance() : null;
180
+ const anchored = probe
181
+ ? store.updateProject(project.id, {
182
+ reaVersion: probe.reaVersion ?? undefined,
183
+ capabilityHash: probe.capabilityHash,
184
+ })
185
+ : project;
139
186
  if (exec) this.remember(exec, project.id);
140
- return project;
187
+ return anchored;
141
188
  },
142
189
 
143
190
  /**
@@ -1182,6 +1229,51 @@ export function createActions(options) {
1182
1229
 
1183
1230
  // ---------- 覆盖率 / 关闭 / 报告(M3 收尾) ----------
1184
1231
 
1232
+ /**
1233
+ * macOS .app 勘察第一跳:读 Info.plist + 可执行架构,给一屏摘要。
1234
+ * 依赖 runner 调 plutil / lipo(都是系统自带);拿不到就标 null,不猜。
1235
+ * @param {{ path: string }} input
1236
+ * @returns {Promise<Record<string, any>>}
1237
+ */
1238
+ async inspectAppBundle(input) {
1239
+ const appPath = String(input?.path ?? "").trim();
1240
+ if (appPath === "") {
1241
+ throw new CasefileInputError(
1242
+ "invalid-input",
1243
+ "path 不能为空(形如 /Applications/Foo.app)",
1244
+ );
1245
+ }
1246
+ const plistPath = join(appPath, "Contents", "Info.plist");
1247
+ if (!existsSync(plistPath)) {
1248
+ throw new CasefileInputError("invalid-input", `不是 macOS 应用包:缺 ${plistPath}`);
1249
+ }
1250
+ // Info.plist 可能是 XML(实测 Bob.app 就是),也可能是二进制;统一交给 plutil 转 JSON。
1251
+ // 直接 JSON.parse 会在 XML 上炸——真实使用一轮就踩到了。
1252
+ const plist = await readPlistAsJson(plistPath);
1253
+ const executableName =
1254
+ typeof plist.CFBundleExecutable === "string" ? plist.CFBundleExecutable : null;
1255
+ const executablePath =
1256
+ executableName == null ? null : join(appPath, "Contents", "MacOS", executableName);
1257
+ /** @type {string[]} */
1258
+ let architectures = [];
1259
+ if (executablePath != null && runner != null && existsSync(executablePath)) {
1260
+ try {
1261
+ const result = await runner(`lipo -archs ${JSON.stringify(executablePath)}`, {
1262
+ timeoutMs: 15000,
1263
+ });
1264
+ const out = typeof result?.stdout === "string" ? result.stdout : "";
1265
+ architectures = parseArchitectures(out);
1266
+ } catch {
1267
+ architectures = [];
1268
+ }
1269
+ }
1270
+ return summarizeAppBundle(plist, {
1271
+ architectures,
1272
+ executablePath: executablePath ?? undefined,
1273
+ infoPlistPath: plistPath,
1274
+ });
1275
+ },
1276
+
1185
1277
  /**
1186
1278
  * 归档项目(非破坏性):误建或暂存的项目收起来,文件都在。
1187
1279
  * @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,6 +97,22 @@ export class CasefileService extends TypertRemoteService {
93
97
  /** 会话 → 最近打开的项目(工具省略 projectId 时用)。 @type {Map<string, string>} */
94
98
  this.currentProject = new Map();
95
99
  this.accessWait = null;
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
+ };
96
116
  this.actions = createActions(this.actionOptions());
97
117
  this.installSessions();
98
118
  this.installTools();
@@ -115,6 +135,78 @@ export class CasefileService extends TypertRemoteService {
115
135
  }
116
136
  }
117
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
+
118
210
  /**
119
211
  * 拿到会话服务后重建 actions(builder 需要 create/prompt/wait)。
120
212
  */
@@ -130,6 +222,8 @@ export class CasefileService extends TypertRemoteService {
130
222
  onWaitChange: (/** @type {any} */ state) => {
131
223
  this.accessWait = state;
132
224
  },
225
+ provenance: () => this.provenance(),
226
+ runner: this.runner,
133
227
  };
134
228
  }
135
229
 
@@ -225,6 +319,8 @@ export class CasefileService extends TypertRemoteService {
225
319
  overview: () => this.actions.overview(),
226
320
  awaitLogin: (projectId, input) => this.actions.awaitLogin(projectId, input),
227
321
  accessState: () => this.accessState(),
322
+ provenanceInfo: () => this.provenance(),
323
+ inspectApp: (input) => this.actions.inspectAppBundle(input),
228
324
  archiveProject: (projectId, options) => this.actions.archiveProject(projectId, options),
229
325
  dropProject: (projectId, options) => this.actions.dropProject(projectId, options),
230
326
  runCycle: (projectId, input) => this.actions.runCycle(projectId, input),
@@ -727,6 +823,8 @@ declareRemote(CasefileService, "closeObligation");
727
823
  declareRemote(CasefileService, "reopenObligation");
728
824
  declareRemote(CasefileService, "overview");
729
825
  declareRemote(CasefileService, "accessState");
826
+ declareRemote(CasefileService, "inspectApp");
827
+ declareRemote(CasefileService, "provenanceInfo");
730
828
  declareRemote(CasefileService, "archiveProject");
731
829
  declareRemote(CasefileService, "dropProject");
732
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.4.1",
3
+ "version": "0.5.1",
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",