@dsh-plus/agent-preset-rea 0.1.0 → 0.1.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/index.d.ts CHANGED
@@ -14,6 +14,8 @@ declare const Config: z<Schemastery.ObjectS<NoInfer<{
14
14
  mcpEnabled: z<boolean, boolean, "defined">;
15
15
  mcpServerName: z<string, string, "defined">;
16
16
  reaVersion: z<string, string, "defined">;
17
+ installRoot: z<string, string, "defined">;
18
+ proxyPort: z<number, number, "volatile-defined">;
17
19
  mcpCommand: z<string, string, "defined">;
18
20
  mcpArgs: z<string[], string[], "defined">;
19
21
  inputSchemaProfile: z<"compact" | "full", "compact" | "full", "defined">;
@@ -30,6 +32,8 @@ declare const Config: z<Schemastery.ObjectS<NoInfer<{
30
32
  mcpEnabled: z<boolean, boolean, "defined">;
31
33
  mcpServerName: z<string, string, "defined">;
32
34
  reaVersion: z<string, string, "defined">;
35
+ installRoot: z<string, string, "defined">;
36
+ proxyPort: z<number, number, "volatile-defined">;
33
37
  mcpCommand: z<string, string, "defined">;
34
38
  mcpArgs: z<string[], string[], "defined">;
35
39
  inputSchemaProfile: z<"compact" | "full", "compact" | "full", "defined">;
@@ -43,6 +47,145 @@ type AgentPresetReaConfigFields = Schemastery.TypeT<typeof Config>;
43
47
  /** 平面配置形态(消费面的读取形态,由活动引用解包得到)。 */
44
48
  type AgentPresetReaConfig = UnwrapVolatile<AgentPresetReaConfigFields>;
45
49
  //#endregion
50
+ //#region src/exec.d.ts
51
+ /** npm 命令名(Windows 经 shell 执行,见 {@link spawnRunner} 注释)。 */
52
+ declare const NPM = "npm";
53
+ /** 作业取消(AbortSignal 触发后由 runner 抛出)。 */
54
+ declare class JobCancelled extends Error {
55
+ constructor();
56
+ }
57
+ /** 外部命令执行面。 */
58
+ interface CommandRunner {
59
+ run(command: string, args: string[], options: {
60
+ env: Record<string, string>;
61
+ signal: AbortSignal;
62
+ onLine(line: string): void;
63
+ }): Promise<{
64
+ code: number;
65
+ }>;
66
+ }
67
+ /** 作业执行上下文(阶段推进 + 日志 + 取消信号)。 */
68
+ interface JobTaskContext {
69
+ /** 进入第 step 个阶段(从 0 起,与 {@link JobOperation.phases} 对应)。 */
70
+ phase(step: number): void;
71
+ log(line: string): void;
72
+ signal: AbortSignal;
73
+ }
74
+ /** 一类作业:阶段名 + 实现。 */
75
+ interface JobOperation {
76
+ phases: string[];
77
+ run(ctx: JobTaskContext): Promise<string>;
78
+ }
79
+ /** 实际 runner:spawn 子进程、逐行回调、AbortSignal 触发即杀。 */
80
+ declare const spawnRunner: CommandRunner;
81
+ /**
82
+ * npm 子进程环境:继承宿主环境,附带代理端口(port > 0 时同时给 npm 与
83
+ * prebuild-install 注入代理——后者只认 `https_proxy` 系列环境变量,
84
+ * 这是原生依赖 prebuild 下载卡死的正解)。
85
+ */
86
+ declare function npmEnv(config: AgentPresetReaConfig): Record<string, string>;
87
+ /** 版本收窄:进命令前把配置里的钉版校验成纯版本号。 */
88
+ declare function safeVersion(version: string): string;
89
+ //#endregion
90
+ //#region src/manager.d.ts
91
+ /** npm 包名。 */
92
+ declare const REA_PACKAGE = "rea-agents";
93
+ /** 受管安装树目录名。 */
94
+ declare const REA_INSTALL_DIR = "rea-agent";
95
+ /** 手动更新 skill 的目录名。 */
96
+ declare const REA_SKILL_DIR = "skills";
97
+ /** REA 随包 skill 名(tar 包内路径与目录名同此)。 */
98
+ declare const REA_SKILL_NAME = "reverse-engineer-anything";
99
+ /** 已安装的 REA 事实。 */
100
+ interface ReaInstall {
101
+ version: string;
102
+ root: string;
103
+ /** spawn 用的可执行文件(`process.execPath`,即当前 node)。 */
104
+ command: string;
105
+ /** 入口脚本绝对路径(`scripts/rea.mjs`)。 */
106
+ entry: string;
107
+ }
108
+ /** skill 来源事实。 */
109
+ interface SkillState {
110
+ /** `bundled` = 随包副本;`updated` = 插件数据目录里的手动更新副本。 */
111
+ source: 'bundled' | 'updated';
112
+ /** 来源版本(从清单 source 解析;解析不出为 null)。 */
113
+ version: string | null;
114
+ root: string;
115
+ files: number;
116
+ updatedAt: string | null;
117
+ }
118
+ /** 运行期事实快照(现探,不进配置;声明组装按它决定 mcp 行与 skill 根)。 */
119
+ interface RuntimeSnapshot {
120
+ install: ReaInstall | null;
121
+ skill: SkillState;
122
+ }
123
+ /** skill 清单(与随包夹具同形;更新副本多写入 updatedAt)。 */
124
+ interface SkillManifest {
125
+ source: string;
126
+ files: {
127
+ path: string;
128
+ sha256: string;
129
+ bytes: number;
130
+ }[];
131
+ updatedAt?: string;
132
+ }
133
+ /** 受管路径。 */
134
+ interface ManagerPaths {
135
+ installRoot: string;
136
+ skillRoot: string;
137
+ }
138
+ /** 作业可一次性覆盖的配置项(卡片未保存的代理端口即时生效用)。 */
139
+ interface JobOverrides {
140
+ proxyPort?: number;
141
+ }
142
+ /** REA 管理面。 */
143
+ interface ReaManager {
144
+ paths(): ManagerPaths;
145
+ /** 现探运行期事实(同步;声明组装在 `apply` 期就要读到)。 */
146
+ snapshot(): RuntimeSnapshot;
147
+ /** 重新现探并更新快照(作业完成、volatile 变更后调用)。 */
148
+ refresh(): RuntimeSnapshot;
149
+ /** 受管作业(安装/更新 REA 包、更新 skill)。 */
150
+ operations(overrides?: JobOverrides): {
151
+ install: JobOperation;
152
+ skill: JobOperation;
153
+ };
154
+ }
155
+ /** 安装作业阶段名。 */
156
+ declare const INSTALL_PHASES: string[];
157
+ /** skill 作业阶段名。 */
158
+ declare const SKILL_PHASES: string[];
159
+ /**
160
+ * 解析受管路径:`installRoot` 非空即运维指定位置(部署方平面),
161
+ * 否则落插件数据目录;skill 更新副本固定落插件数据目录。
162
+ */
163
+ declare function managerPaths(config: AgentPresetReaConfig): ManagerPaths;
164
+ /**
165
+ * 探测已安装 REA:包版本可读 **且** 入口脚本存在才算安装完整
166
+ * (只有一半的安装树、或换目录中断留下的 staging 都不算)。
167
+ */
168
+ declare function probeInstall(paths: ManagerPaths): ReaInstall | null;
169
+ /** 探测 skill 来源:数据目录里清单完整且技能文件在位才认更新副本。 */
170
+ declare function probeSkill(paths: ManagerPaths, bundledRoot: string, bundledVersion: string): SkillState;
171
+ /** 现探运行期事实。 */
172
+ declare function probeRuntime(config: AgentPresetReaConfig, bundledRoot: string, bundledVersion: string): RuntimeSnapshot;
173
+ /** 作业依赖:生效配置、命令执行面、作业完成后的现探刷新。 */
174
+ interface JobDeps {
175
+ config: AgentPresetReaConfig;
176
+ runner: CommandRunner;
177
+ refresh(): void;
178
+ }
179
+ /** 生效配置:作业可带一次性覆盖(卡片未保存的代理端口即时可用)。 */
180
+ declare function configWith(base: AgentPresetReaConfig, overrides?: JobOverrides): AgentPresetReaConfig;
181
+ /** 建一个 REA 管理器。 */
182
+ declare function createManager(options: {
183
+ config: () => AgentPresetReaConfig;
184
+ bundledRoot: string;
185
+ bundledVersion: string;
186
+ runner?: CommandRunner;
187
+ }): ReaManager;
188
+ //#endregion
46
189
  //#region src/definition.d.ts
47
190
  /** 预设注册表身份(改 id 等于换预设,default 等引用都会落空)。 */
48
191
  declare const REA_PRESET_ID = "rea";
@@ -53,24 +196,149 @@ declare const ADDED_ROWS: readonly string[];
53
196
  * 删除某条等于把该行改回上游原文;改动上游不存在的字段会被测试拦下。
54
197
  */
55
198
  declare const CONFIG_DELTAS: Readonly<Record<string, readonly string[]>>;
199
+ /** 未安装、随包 skill 的运行期事实(默认值:测试与无 manager 场景)。 */
200
+ declare function emptyRuntime(): RuntimeSnapshot;
56
201
  /**
57
- * 由配置拼出注册表声明。
202
+ * 由配置 + 运行期事实拼出注册表声明。
58
203
  * @param config - 已验证的插件配置。
204
+ * @param runtime - 受管安装与 skill 来源事实(默认「未安装 + 随包 skill」)。
59
205
  * @returns id 固定为 `rea` 的预设声明。
60
206
  */
61
- declare function reaPresetDefinition(config: AgentPresetReaConfig): PresetDefinition;
207
+ declare function reaPresetDefinition(config: AgentPresetReaConfig, runtime?: RuntimeSnapshot): PresetDefinition;
208
+ //#endregion
209
+ //#region src/dto.d.ts
210
+ /**
211
+ * 宿主半与浏览器半之间的 wire 数据门面(纯类型 + 纯函数,零 node 依赖)。
212
+ *
213
+ * 浏览器半只 `import type` 消费本文件(编译期擦除,不进 client bundle),
214
+ * 两端共用同一份字段定义,避免「宿主改了字段、卡片还在读老名字」的静默漂移。
215
+ * @module @dsh-plus/agent-preset-rea/dto
216
+ */
217
+ /** 作业种类。 */
218
+ type JobKind = 'install' | 'skill';
219
+ /** 作业状态。 */
220
+ type JobState = 'running' | 'ok' | 'error' | 'cancelled';
221
+ /** 作业进度(按阶段推进;percent 为进入该阶段时的完成度)。 */
222
+ interface JobProgressDto {
223
+ step: number;
224
+ steps: number;
225
+ phase: string;
226
+ percent: number;
227
+ }
228
+ /** 作业快照。 */
229
+ interface JobDto {
230
+ id: number;
231
+ kind: JobKind;
232
+ state: JobState;
233
+ progress: JobProgressDto;
234
+ /** 日志尾部(宿主已有界)。 */
235
+ log: string[];
236
+ startedAt: string;
237
+ finishedAt: string | null;
238
+ version: string | null;
239
+ error: string | null;
240
+ }
241
+ /** 受管安装事实。 */
242
+ interface InstallDto {
243
+ installed: boolean;
244
+ /** 已安装版本(未安装为 null)。 */
245
+ version: string | null;
246
+ /** 受管安装树位置(无论是否已安装都有值,便于用户核对)。 */
247
+ root: string;
248
+ /** 入口脚本(未安装为 null)。 */
249
+ entry: string | null;
250
+ }
251
+ /** skill 来源事实。 */
252
+ interface SkillDto {
253
+ source: 'bundled' | 'updated';
254
+ version: string | null;
255
+ root: string;
256
+ files: number;
257
+ updatedAt: string | null;
258
+ }
259
+ /** MCP 行形态。 */
260
+ interface McpDto {
261
+ /** `installed` = 用受管安装入口;`custom` = 用显式 mcpCommand;`missing` = 未安装且无显式命令(行禁用)。 */
262
+ mode: 'installed' | 'custom' | 'missing';
263
+ /** 行是否启用(mcpEnabled && 有启动方式)。 */
264
+ enabled: boolean;
265
+ command: string | null;
266
+ args: string[];
267
+ }
268
+ /** `GET /status` 响应。 */
269
+ interface StatusDto {
270
+ config: {
271
+ reaVersion: string;
272
+ proxyPort: number;
273
+ mcpEnabled: boolean;
274
+ installRoot: string;
275
+ };
276
+ install: InstallDto;
277
+ skill: SkillDto;
278
+ mcp: McpDto;
279
+ paths: {
280
+ installRoot: string;
281
+ skillRoot: string;
282
+ };
283
+ job: JobDto | null;
284
+ }
285
+ /** 作业类响应(启动/取消)。 */
286
+ interface JobActionDto {
287
+ job: JobDto | null;
288
+ /** 拒绝原因(409/400 时给出人话)。 */
289
+ error?: string;
290
+ }
291
+ //#endregion
292
+ //#region src/jobs.d.ts
293
+ /** 作业快照(与 wire DTO 同形,HTTP 直接回传)。 */
294
+ type JobSnapshot = JobDto;
295
+ /** 作业板。 */
296
+ interface JobBoard {
297
+ /** 启动作业;已有作业在跑时返回 null(调用方回 409)。 */
298
+ start(kind: JobKind, operation: JobOperation): JobSnapshot | null;
299
+ /** 取消当前作业(返回是否真的发出取消)。 */
300
+ cancel(): boolean;
301
+ /** 当前/最近一次作业快照。 */
302
+ snapshot(): JobSnapshot | null;
303
+ /** 订阅作业完成(返回退订函数)。 */
304
+ onSettled(listener: (snapshot: JobSnapshot) => void): () => void;
305
+ }
306
+ /** 建一个作业板。 */
307
+ declare function createJobBoard(): JobBoard;
62
308
  //#endregion
63
309
  //#region src/mcp.d.ts
64
310
  /** 钉版基线:`rea-agents@6.5.0`(升级时同步测试断言、tests 清单与包文档)。 */
65
311
  declare const REA_PINNED_VERSION = "6.5.0";
66
- /** stdio 启动命令默认值:POSIX 用 `npx`;Windows 需 `cmd.exe /c npx`(见包文档)。 */
312
+ /** 显式命令配 npx 时的参数配方基准值(`mcpArgs` 留空即按它派生)。 */
67
313
  declare const DEFAULT_MCP_COMMAND = "npx";
68
314
  /** REA 工具入参 schema 广告档位:`compact` 压请求前缀体积,`full` 与上游默认一致。 */
69
315
  declare const INPUT_SCHEMA_PROFILES: readonly ['compact', 'full'];
70
316
  /** REA 工具出参 schema 广告档位:`off` 不下发(结果仍由 REA 侧校验),`full` 与上游默认一致。 */
71
317
  declare const OUTPUT_SCHEMA_PROFILES: readonly ['off', 'full'];
72
- /** stdio 参数:显式配置优先(Windows/全局安装配方),否则按钉版版本派生。 */
318
+ /** 受管安装的入口事实(结构上由 manager 的 ReaInstall 满足)。 */
319
+ interface InstalledEntry {
320
+ /** spawn 用的可执行文件。 */
321
+ command: string;
322
+ /** 入口脚本绝对路径。 */
323
+ entry: string;
324
+ }
325
+ /** MCP 行的启动方式。 */
326
+ interface McpLaunch {
327
+ command: string;
328
+ args: string[];
329
+ }
330
+ /**
331
+ * 显式命令(`mcpCommand` 非空)时的参数:`mcpArgs` 优先;
332
+ * 留空时 npx 走 `-y rea-agents@<钉版> mcp`,其他可执行文件只补 `mcp`。
333
+ */
73
334
  declare function reaMcpArgs(config: AgentPresetReaConfig): string[];
335
+ /**
336
+ * 本预设 MCP 行的启动方式:
337
+ * 1. `mcpCommand` 显式配置 → 用用户命令(Windows 配方、全局安装场景);
338
+ * 2. 受管安装存在 → 用当前 node 直接跑安装树里的入口脚本(跨平台、不经 shell shim);
339
+ * 3. 都没有 → `null`,调用方把该行置 `disabled`(未安装,等卡片上的安装动作)。
340
+ */
341
+ declare function reaMcpLaunch(config: AgentPresetReaConfig, installed: InstalledEntry | null): McpLaunch | null;
74
342
  /**
75
343
  * 传给 REA 子进程的环境变量(并入被清洗过的宿主环境之上)。
76
344
  *
@@ -117,6 +385,20 @@ interface PresetRegistrar {
117
385
  */
118
386
  declare function createPresetRegistrar(options: PresetRegistrarOptions): PresetRegistrar;
119
387
  //#endregion
388
+ //#region src/routes.d.ts
389
+ /** 路由前缀。 */
390
+ declare const ROUTE_BASE = "/dsh-plus/agent-preset-rea";
391
+ /** 路由依赖。 */
392
+ interface ReaRoutesOptions {
393
+ manager: ReaManager;
394
+ board: JobBoard;
395
+ config: () => AgentPresetReaConfig;
396
+ }
397
+ /** 组装状态响应(纯函数,可直接单测)。 */
398
+ declare function statusPayload(options: ReaRoutesOptions): StatusDto;
399
+ /** 注册全部路由。 */
400
+ declare function registerReaRoutes(ctx: Context, options: ReaRoutesOptions): void;
401
+ //#endregion
120
402
  //#region src/skill.d.ts
121
403
  /**
122
404
  * 随包 REA 官方 skill 根(包内 `skills/`)。
@@ -125,8 +407,12 @@ declare function createPresetRegistrar(options: PresetRegistrarOptions): PresetR
125
407
  * 运行产物两种位置下解析到同一目录。
126
408
  */
127
409
  declare const BUNDLED_SKILL_ROOT: string;
128
- /** skill-filesystem 的追加根清单:随包 REA skill 在前,配置追加目录随后。 */
129
- declare function reaSkillDirs(config: AgentPresetReaConfig): string[];
410
+ /**
411
+ * skill-filesystem 的追加根清单。
412
+ * @param config - 插件配置。
413
+ * @param updatedRoot - 手动更新副本根(存在即替代随包根;来自 manager 现探)。
414
+ */
415
+ declare function reaSkillDirs(config: AgentPresetReaConfig, updatedRoot?: string | null): string[];
130
416
  //#endregion
131
417
  //#region src/index.d.ts
132
418
  declare const name = "dsh-plus-agent-preset-rea";
@@ -142,4 +428,4 @@ declare const inject: readonly [];
142
428
  */
143
429
  declare function apply(ctx: Context, config: AgentPresetReaConfigFields): void;
144
430
  //#endregion
145
- export { ADDED_ROWS, type AgentPresetReaConfig, type AgentPresetReaConfigFields, BUNDLED_SKILL_ROOT, CONFIG_DELTAS, Config, DEFAULT_MCP_COMMAND, INPUT_SCHEMA_PROFILES, OUTPUT_SCHEMA_PROFILES, PLAN_MODE_SECTION, type PresetRegistrar, REA_PINNED_VERSION, REA_PRESET_ID, SETTINGS_NS, type Unregister, apply, createPresetRegistrar, inject, name, reaMcpArgs, reaMcpEnv, reaPresetDefinition, reaSkillDirs };
431
+ export { ADDED_ROWS, type AgentPresetReaConfig, type AgentPresetReaConfigFields, BUNDLED_SKILL_ROOT, CONFIG_DELTAS, type CommandRunner, Config, DEFAULT_MCP_COMMAND, INPUT_SCHEMA_PROFILES, INSTALL_PHASES, type InstallDto, type InstalledEntry, type JobActionDto, type JobBoard, JobCancelled, type JobDeps, type JobDto, type JobKind, type JobOperation, type JobOverrides, type JobProgressDto, type JobSnapshot, type JobState, type JobTaskContext, type ManagerPaths, type McpDto, type McpLaunch, NPM, OUTPUT_SCHEMA_PROFILES, PLAN_MODE_SECTION, type PresetRegistrar, REA_INSTALL_DIR, REA_PACKAGE, REA_PINNED_VERSION, REA_PRESET_ID, REA_SKILL_DIR, REA_SKILL_NAME, ROUTE_BASE, type ReaInstall, type ReaManager, type RuntimeSnapshot, SETTINGS_NS, SKILL_PHASES, type SkillDto, type SkillManifest, type SkillState, type StatusDto, type Unregister, apply, configWith, createJobBoard, createManager, createPresetRegistrar, emptyRuntime, inject, managerPaths, name, npmEnv, probeInstall, probeRuntime, probeSkill, reaMcpArgs, reaMcpEnv, reaMcpLaunch, reaPresetDefinition, reaSkillDirs, registerReaRoutes, safeVersion, spawnRunner, statusPayload };