@siming-org/core 0.3.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +2219 -147
  2. package/dist/index.js +2514 -420
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as mongodb from 'mongodb';
1
2
  import { Db, MongoClient, MongoClientOptions, ClientSession, Collection, Document, Filter, ObjectId } from 'mongodb';
2
3
  export { ClientSession, Db } from 'mongodb';
3
4
  import { z } from 'zod';
@@ -63,6 +64,26 @@ declare function createRepo<T extends {
63
64
  type Repo<T extends {
64
65
  id?: string | undefined;
65
66
  }> = ReturnType<typeof createRepo<T>>;
67
+ /**
68
+ * 模糊搜索关键词的正则元字符转义(单点收口防注入/ReDoS)——语义 = 不区分大小写的字面包含匹配。
69
+ * 消费方:任务 title / 资产 name 的 $regex 过滤(搜索输入长度上限由各路由 query schema 把守)。
70
+ */
71
+ declare function escapeRegExpLiteral(input: string): string;
72
+ /** 资产列举公共选项:includeDisabled(缺省 false = 排除停用,CLI/MCP 默认视图)+ q(名称模糊搜索)。
73
+ * 可选属性显式含 undefined(exactOptionalPropertyTypes 惯例)——路由层可直传 query 解析出的 T | undefined。 */
74
+ interface AssetListOpts {
75
+ includeDisabled?: boolean | undefined;
76
+ q?: string | undefined;
77
+ }
78
+ /**
79
+ * 可见性过滤字段片段——enabled === false 即停用,true/缺失均启用(存量零迁移语义)。
80
+ * 与既有查询条件同层展开合并(`{ ...原条件, ...enabledNeFalse() }`)。
81
+ */
82
+ declare function enabledNeFalse(): {
83
+ enabled: {
84
+ $ne: false;
85
+ };
86
+ };
66
87
 
67
88
  /**
68
89
  * Skill Schema — Skill 库(N012:支持全局 / 项目专用两种作用域)
@@ -73,6 +94,26 @@ declare const SkillScopeSchema: z.ZodEnum<{
73
94
  project: "project";
74
95
  }>;
75
96
  declare const OBJECT_ID_HEX: RegExp;
97
+ declare const SkillShapeSchema: z.ZodObject<{
98
+ id: z.ZodOptional<z.ZodString>;
99
+ name: z.ZodString;
100
+ description: z.ZodString;
101
+ content: z.ZodString;
102
+ category: z.ZodString;
103
+ version: z.ZodDefault<z.ZodString>;
104
+ references: z.ZodOptional<z.ZodArray<z.ZodObject<{
105
+ path: z.ZodString;
106
+ content: z.ZodString;
107
+ }, z.core.$strip>>>;
108
+ scope: z.ZodDefault<z.ZodEnum<{
109
+ global: "global";
110
+ project: "project";
111
+ }>>;
112
+ projectId: z.ZodOptional<z.ZodString>;
113
+ enabled: z.ZodOptional<z.ZodBoolean>;
114
+ createdAt: z.ZodOptional<z.ZodDate>;
115
+ updatedAt: z.ZodOptional<z.ZodDate>;
116
+ }, z.core.$strip>;
76
117
  declare const SkillSchema: z.ZodObject<{
77
118
  id: z.ZodOptional<z.ZodString>;
78
119
  name: z.ZodString;
@@ -80,11 +121,16 @@ declare const SkillSchema: z.ZodObject<{
80
121
  content: z.ZodString;
81
122
  category: z.ZodString;
82
123
  version: z.ZodDefault<z.ZodString>;
124
+ references: z.ZodOptional<z.ZodArray<z.ZodObject<{
125
+ path: z.ZodString;
126
+ content: z.ZodString;
127
+ }, z.core.$strip>>>;
83
128
  scope: z.ZodDefault<z.ZodEnum<{
84
129
  global: "global";
85
130
  project: "project";
86
131
  }>>;
87
132
  projectId: z.ZodOptional<z.ZodString>;
133
+ enabled: z.ZodOptional<z.ZodBoolean>;
88
134
  createdAt: z.ZodOptional<z.ZodDate>;
89
135
  updatedAt: z.ZodOptional<z.ZodDate>;
90
136
  }, z.core.$strip>;
@@ -97,9 +143,13 @@ type SkillScope = z.infer<typeof SkillScopeSchema>;
97
143
  */
98
144
  declare const SkillCreateSchema: z.ZodObject<{
99
145
  version: z.ZodDefault<z.ZodString>;
146
+ content: z.ZodString;
100
147
  name: z.ZodString;
148
+ references: z.ZodOptional<z.ZodArray<z.ZodObject<{
149
+ path: z.ZodString;
150
+ content: z.ZodString;
151
+ }, z.core.$strip>>>;
101
152
  description: z.ZodString;
102
- content: z.ZodString;
103
153
  category: z.ZodString;
104
154
  projectId: z.ZodOptional<z.ZodString>;
105
155
  scope: z.ZodEnum<{
@@ -116,9 +166,13 @@ type SkillCreate = z.infer<typeof SkillCreateSchema>;
116
166
  * 解析出 {scope:'global', version:'1.0.0'} 并被 $set 写库(version 被重置 + 项目专用资产假 409)。
117
167
  */
118
168
  declare const SkillUpdateSchema: z.ZodObject<{
169
+ content: z.ZodOptional<z.ZodString>;
119
170
  name: z.ZodOptional<z.ZodString>;
171
+ references: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodObject<{
172
+ path: z.ZodString;
173
+ content: z.ZodString;
174
+ }, z.core.$strip>>>>;
120
175
  description: z.ZodOptional<z.ZodString>;
121
- content: z.ZodOptional<z.ZodString>;
122
176
  category: z.ZodOptional<z.ZodString>;
123
177
  projectId: z.ZodOptional<z.ZodOptional<z.ZodString>>;
124
178
  version: z.ZodOptional<z.ZodOptional<z.ZodString>>;
@@ -151,14 +205,24 @@ type SkillRepo = Repo<Skill> & {
151
205
  updateByNameScoped(name: string, scope: SkillScope, projectId: string | undefined, patch: EoptPartial<Omit<Skill, 'id'>>): Promise<Skill | null>;
152
206
  /** N016 F02:by-name 消歧删除(同 updateByNameScoped,防止跨 scope 同名时误删) */
153
207
  deleteByNameScoped(name: string, scope: SkillScope, projectId: string | undefined): Promise<boolean>;
154
- /** N016 F12:by-name 消歧解析——scope 显式指定(project → {name, projectId};global → {name, scope:'global'}) */
155
- getByNameScoped(name: string, scope: SkillScope, projectId?: string | undefined): Promise<Skill | null>;
208
+ /**
209
+ * N016 F12:by-name 消歧解析——scope 显式指定(project → {name, projectId};global {name, scope:'global'})。
210
+ * T202608290001:缺省排除停用资产(读可见性——CLI/MCP show 404 与不存在同形);
211
+ * 写通道(update/delete/copy 源解析)经 opts.includeDisabled=true 显式放行(启停不冻结管理操作)。
212
+ */
213
+ getByNameScoped(name: string, scope: SkillScope, projectId?: string | undefined, opts?: {
214
+ includeDisabled?: boolean | undefined;
215
+ }): Promise<Skill | null>;
156
216
  /** 项目上下文叠加列表(F7):global + 指定项目专用 */
157
- listSkillsByScope(projectId: string): Promise<Skill[]>;
217
+ listSkillsByScope(projectId: string, opts?: AssetListOpts): Promise<Skill[]>;
158
218
  /** N015 F12:按作用域过滤(install 拉取;projectId 仅 scope=project 时生效) */
159
- listSkillsByScopeFilter(scope: SkillScope, projectId?: string): Promise<Skill[]>;
219
+ listSkillsByScopeFilter(scope: SkillScope, projectId?: string, opts?: AssetListOpts): Promise<Skill[]>;
220
+ /** T202608290001:全量列举(管理视角,路由缺省路径)——opts 语义同上,保持启停过滤单点在仓储层 */
221
+ listSkills(opts?: AssetListOpts): Promise<Skill[]>;
160
222
  /** 绑定校验批量预取(消 N+1):按引用方 scope 可见集过滤(N016 F04——project 引用方 = global + 本项目;global 引用方 = 仅 global) */
161
223
  listSkillsByNames(names: string[], scope?: SkillScope, projectId?: string): Promise<Map<string, Skill>>;
224
+ /** 仅判断目标作用域是否被对方作用域同名资产阻塞,不返回资产内容。 */
225
+ hasNameScopeConflict(name: string, scope: SkillScope): Promise<boolean>;
162
226
  /** by-name 复制(N016 F08/F11):源 scope 显式消歧 + 目标跨 scope 守卫;version 重置 '1.0.0' */
163
227
  copySkill(sourceName: string, source: {
164
228
  scope: SkillScope;
@@ -179,6 +243,39 @@ declare const AgentScopeSchema: z.ZodEnum<{
179
243
  global: "global";
180
244
  project: "project";
181
245
  }>;
246
+ /** T202608260002:Agent 功能类型——reviewer=审查(install 落盘注入信息边界)/ executor=执行/通用(不注入,默认值)。
247
+ * 消费方仅 cli writer 按 reviewer 判定注入;枚举固定于 schema 为唯一权威,registry agent_function 仅展示。 */
248
+ declare const AgentFunctionSchema: z.ZodEnum<{
249
+ reviewer: "reviewer";
250
+ executor: "executor";
251
+ }>;
252
+ declare const AgentShapeSchema: z.ZodObject<{
253
+ id: z.ZodOptional<z.ZodString>;
254
+ name: z.ZodString;
255
+ description: z.ZodString;
256
+ systemPrompt: z.ZodString;
257
+ boundSkills: z.ZodDefault<z.ZodArray<z.ZodString>>;
258
+ model: z.ZodString;
259
+ version: z.ZodDefault<z.ZodString>;
260
+ tools: z.ZodDefault<z.ZodArray<z.ZodString>>;
261
+ permissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
262
+ references: z.ZodOptional<z.ZodArray<z.ZodObject<{
263
+ path: z.ZodString;
264
+ content: z.ZodString;
265
+ }, z.core.$strip>>>;
266
+ scope: z.ZodDefault<z.ZodEnum<{
267
+ global: "global";
268
+ project: "project";
269
+ }>>;
270
+ function: z.ZodDefault<z.ZodEnum<{
271
+ reviewer: "reviewer";
272
+ executor: "executor";
273
+ }>>;
274
+ projectId: z.ZodOptional<z.ZodString>;
275
+ enabled: z.ZodOptional<z.ZodBoolean>;
276
+ createdAt: z.ZodOptional<z.ZodDate>;
277
+ updatedAt: z.ZodOptional<z.ZodDate>;
278
+ }, z.core.$strip>;
182
279
  declare const AgentSchema: z.ZodObject<{
183
280
  id: z.ZodOptional<z.ZodString>;
184
281
  name: z.ZodString;
@@ -189,16 +286,26 @@ declare const AgentSchema: z.ZodObject<{
189
286
  version: z.ZodDefault<z.ZodString>;
190
287
  tools: z.ZodDefault<z.ZodArray<z.ZodString>>;
191
288
  permissions: z.ZodDefault<z.ZodArray<z.ZodString>>;
289
+ references: z.ZodOptional<z.ZodArray<z.ZodObject<{
290
+ path: z.ZodString;
291
+ content: z.ZodString;
292
+ }, z.core.$strip>>>;
192
293
  scope: z.ZodDefault<z.ZodEnum<{
193
294
  global: "global";
194
295
  project: "project";
195
296
  }>>;
297
+ function: z.ZodDefault<z.ZodEnum<{
298
+ reviewer: "reviewer";
299
+ executor: "executor";
300
+ }>>;
196
301
  projectId: z.ZodOptional<z.ZodString>;
302
+ enabled: z.ZodOptional<z.ZodBoolean>;
197
303
  createdAt: z.ZodOptional<z.ZodDate>;
198
304
  updatedAt: z.ZodOptional<z.ZodDate>;
199
305
  }, z.core.$strip>;
200
306
  type Agent = z.infer<typeof AgentSchema>;
201
307
  type AgentScope = z.infer<typeof AgentScopeSchema>;
308
+ type AgentFunction = z.infer<typeof AgentFunctionSchema>;
202
309
  /**
203
310
  * 创建输入:scope 必填(PRD F7/Q6「无默认值,未选择不可提交」)。
204
311
  * extend 覆盖 scope 字段定义以剥离实体层 default(.omit() 会保留字段的 default,缺省会静默补 'global' 而非 422);
@@ -207,6 +314,10 @@ type AgentScope = z.infer<typeof AgentScopeSchema>;
207
314
  declare const AgentCreateSchema: z.ZodObject<{
208
315
  version: z.ZodDefault<z.ZodString>;
209
316
  name: z.ZodString;
317
+ references: z.ZodOptional<z.ZodArray<z.ZodObject<{
318
+ path: z.ZodString;
319
+ content: z.ZodString;
320
+ }, z.core.$strip>>>;
210
321
  description: z.ZodString;
211
322
  projectId: z.ZodOptional<z.ZodString>;
212
323
  systemPrompt: z.ZodString;
@@ -218,6 +329,10 @@ declare const AgentCreateSchema: z.ZodObject<{
218
329
  project: "project";
219
330
  }>;
220
331
  model: z.ZodString;
332
+ function: z.ZodDefault<z.ZodEnum<{
333
+ reviewer: "reviewer";
334
+ executor: "executor";
335
+ }>>;
221
336
  }, z.core.$strip>;
222
337
  type AgentCreate = z.infer<typeof AgentCreateSchema>;
223
338
  /**
@@ -229,6 +344,10 @@ type AgentCreate = z.infer<typeof AgentCreateSchema>;
229
344
  */
230
345
  declare const AgentUpdateSchema: z.ZodObject<{
231
346
  name: z.ZodOptional<z.ZodString>;
347
+ references: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodObject<{
348
+ path: z.ZodString;
349
+ content: z.ZodString;
350
+ }, z.core.$strip>>>>;
232
351
  description: z.ZodOptional<z.ZodString>;
233
352
  projectId: z.ZodOptional<z.ZodOptional<z.ZodString>>;
234
353
  systemPrompt: z.ZodOptional<z.ZodString>;
@@ -241,6 +360,10 @@ declare const AgentUpdateSchema: z.ZodObject<{
241
360
  project: "project";
242
361
  }>>>;
243
362
  model: z.ZodOptional<z.ZodOptional<z.ZodString>>;
363
+ function: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
364
+ reviewer: "reviewer";
365
+ executor: "executor";
366
+ }>>>;
244
367
  }, z.core.$strip>;
245
368
  type AgentUpdate = z.infer<typeof AgentUpdateSchema>;
246
369
  /**
@@ -266,12 +389,22 @@ type AgentRepo = Repo<Agent> & {
266
389
  updateByNameScoped(name: string, scope: AgentScope, projectId: string | undefined, patch: EoptPartial<Omit<Agent, 'id'>>): Promise<Agent | null>;
267
390
  /** N016 F02:by-name 消歧删除(同 updateByNameScoped,防止跨 scope 同名时误删) */
268
391
  deleteByNameScoped(name: string, scope: AgentScope, projectId: string | undefined): Promise<boolean>;
269
- /** N016 F12:by-name 消歧解析——scope 显式指定(project → {name, projectId};global → {name, scope:'global'}) */
270
- getByNameScoped(name: string, scope: AgentScope, projectId?: string | undefined): Promise<Agent | null>;
392
+ /**
393
+ * N016 F12:by-name 消歧解析——scope 显式指定(project → {name, projectId};global {name, scope:'global'})。
394
+ * T202608290001:缺省排除停用资产(读可见性——CLI/MCP show 404 与不存在同形);
395
+ * 写通道(update/delete/copy 源解析)经 opts.includeDisabled=true 显式放行(启停不冻结管理操作)。
396
+ */
397
+ getByNameScoped(name: string, scope: AgentScope, projectId?: string | undefined, opts?: {
398
+ includeDisabled?: boolean | undefined;
399
+ }): Promise<Agent | null>;
271
400
  /** 项目上下文叠加列表(F7):global + 指定项目专用 */
272
- listAgentsByScope(projectId: string): Promise<Agent[]>;
401
+ listAgentsByScope(projectId: string, opts?: AssetListOpts): Promise<Agent[]>;
273
402
  /** N015 F12:按作用域过滤(install 拉取;projectId 仅 scope=project 时生效) */
274
- listAgentsByScopeFilter(scope: AgentScope, projectId?: string): Promise<Agent[]>;
403
+ listAgentsByScopeFilter(scope: AgentScope, projectId?: string, opts?: AssetListOpts): Promise<Agent[]>;
404
+ /** T202608290001:全量列举(管理视角,路由缺省路径)——opts 语义同上,保持启停过滤单点在仓储层 */
405
+ listAgents(opts?: AssetListOpts): Promise<Agent[]>;
406
+ /** 仅判断目标作用域是否被对方作用域同名资产阻塞,不返回资产内容。 */
407
+ hasNameScopeConflict(name: string, scope: AgentScope): Promise<boolean>;
275
408
  /** by-name 复制(N016 F08/F11):源 scope 显式消歧 + 目标跨 scope 守卫 + boundSkills 按目标作用域重校验;version 重置 '1.0.0' */
276
409
  copyAgent(sourceName: string, source: {
277
410
  scope: AgentScope;
@@ -313,6 +446,19 @@ declare const DagNodeTrackSchema: z.ZodString;
313
446
  declare const DAG_PHASES: readonly ["entry", "track", "test", "exit"];
314
447
  declare const DAG_TRACKS: readonly ["backend", "ui", "all"];
315
448
  declare const NODE_ID_PATTERN: RegExp;
449
+ /**
450
+ * 来源标记(T202609020001 K2):组装值拷贝时写入,双信号分工——
451
+ * code = 升级寻址键 / version = updatable 判定(K13 升版强制保证「版本不变则内容不变」)/
452
+ * contentHash = local-modified 判定基线(算法单源 computeNodeContentHash)。
453
+ * 可选字段:存量模板无此键 = 自建节点,零迁移。
454
+ */
455
+ declare const SourcePresetSchema: z.ZodObject<{
456
+ code: z.ZodString;
457
+ version: z.ZodString;
458
+ contentHash: z.ZodString;
459
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
460
+ }, z.core.$strip>;
461
+ type SourcePreset = z.infer<typeof SourcePresetSchema>;
316
462
  declare const DagNodeSchema: z.ZodObject<{
317
463
  id: z.ZodString;
318
464
  label: z.ZodString;
@@ -320,6 +466,13 @@ declare const DagNodeSchema: z.ZodObject<{
320
466
  track: z.ZodString;
321
467
  prompt: z.ZodString;
322
468
  skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
469
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
470
+ sourcePreset: z.ZodOptional<z.ZodObject<{
471
+ code: z.ZodString;
472
+ version: z.ZodString;
473
+ contentHash: z.ZodString;
474
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
475
+ }, z.core.$strip>>;
323
476
  }, z.core.$strip>;
324
477
  type DagNode = z.infer<typeof DagNodeSchema>;
325
478
  /** 暂停点类型——固定枚举,引擎仅处理这两种语义(human_approval 落 paused / checkpoint 仅记录不停留) */
@@ -359,6 +512,22 @@ declare const EdgePausePointSchema: z.ZodObject<{
359
512
  autoResume: z.ZodDefault<z.ZodBoolean>;
360
513
  }, z.core.$strip>;
361
514
  type EdgePausePoint = z.infer<typeof EdgePausePointSchema>;
515
+ /**
516
+ * 模板业务 code 格式:kebab-case 且至少含一个连字符段('-' 分隔多段,如 full-workflow)。
517
+ * 含连字符约束使 code 与 24-hex 数据库 id 形态可区分(纯 hex 串无连字符,天然被排除)——
518
+ * 支撑寻址二阶段判定(先 id 直查命中、未命中再按 code 项目内检索)与 AI 转录可核对性。
519
+ */
520
+ declare const TEMPLATE_CODE_REGEX: RegExp;
521
+ declare const TEMPLATE_CODE_MAX_LENGTH = 31;
522
+ /** code 字段校验(创建侧强校验;长度与 project key 同口径 2-31,结构保证下限 3) */
523
+ declare const TemplateCodeFieldSchema: z.ZodString;
524
+ /** not-found 相近候选条目(防转录错误——错误信息携带项目内相近模板清单) */
525
+ declare const TemplateCandidateSchema: z.ZodObject<{
526
+ id: z.ZodString;
527
+ code: z.ZodString;
528
+ name: z.ZodString;
529
+ }, z.core.$strip>;
530
+ type TemplateCandidate = z.infer<typeof TemplateCandidateSchema>;
362
531
  declare const DagEdgeSchema: z.ZodObject<{
363
532
  from: z.ZodString;
364
533
  to: z.ZodString;
@@ -378,6 +547,7 @@ declare const DagTemplateSchema: z.ZodObject<{
378
547
  name: z.ZodString;
379
548
  projectId: z.ZodString;
380
549
  description: z.ZodString;
550
+ code: z.ZodOptional<z.ZodString>;
381
551
  nodes: z.ZodArray<z.ZodObject<{
382
552
  id: z.ZodString;
383
553
  label: z.ZodString;
@@ -385,6 +555,13 @@ declare const DagTemplateSchema: z.ZodObject<{
385
555
  track: z.ZodString;
386
556
  prompt: z.ZodString;
387
557
  skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
558
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
559
+ sourcePreset: z.ZodOptional<z.ZodObject<{
560
+ code: z.ZodString;
561
+ version: z.ZodString;
562
+ contentHash: z.ZodString;
563
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
564
+ }, z.core.$strip>>;
388
565
  }, z.core.$strip>>;
389
566
  edges: z.ZodArray<z.ZodObject<{
390
567
  from: z.ZodString;
@@ -405,6 +582,7 @@ declare const DagTemplateSchema: z.ZodObject<{
405
582
  }, z.core.$strip>>>;
406
583
  isDefault: z.ZodDefault<z.ZodBoolean>;
407
584
  version: z.ZodDefault<z.ZodString>;
585
+ enabled: z.ZodOptional<z.ZodBoolean>;
408
586
  createdAt: z.ZodOptional<z.ZodDate>;
409
587
  updatedAt: z.ZodOptional<z.ZodDate>;
410
588
  }, z.core.$strip>;
@@ -412,6 +590,7 @@ type DagTemplate = z.infer<typeof DagTemplateSchema>;
412
590
  declare const DagTemplateCreateSchema: z.ZodObject<{
413
591
  version: z.ZodDefault<z.ZodString>;
414
592
  name: z.ZodString;
593
+ code: z.ZodOptional<z.ZodString>;
415
594
  description: z.ZodString;
416
595
  projectId: z.ZodString;
417
596
  nodes: z.ZodArray<z.ZodObject<{
@@ -421,6 +600,13 @@ declare const DagTemplateCreateSchema: z.ZodObject<{
421
600
  track: z.ZodString;
422
601
  prompt: z.ZodString;
423
602
  skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
603
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
604
+ sourcePreset: z.ZodOptional<z.ZodObject<{
605
+ code: z.ZodString;
606
+ version: z.ZodString;
607
+ contentHash: z.ZodString;
608
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
609
+ }, z.core.$strip>>;
424
610
  }, z.core.$strip>>;
425
611
  edges: z.ZodArray<z.ZodObject<{
426
612
  from: z.ZodString;
@@ -445,9 +631,12 @@ type DagTemplateCreate = z.infer<typeof DagTemplateCreateSchema>;
445
631
  /**
446
632
  * 更新输入(PUT partial)。extend 剥离实体层 .default()——Zod 4 的 .partial() 保留字段
447
633
  * default,空 body 会解析出 {isDefault:false, version:'1.0.0'} 并被 $set 写库(字段被静默重置)。
634
+ * code 无实体层 default,partial 后 optional 进 Update——仅供路由层不可变检测
635
+ * (body.code ≠ 现值 → 409 TEMPLATE_CODE_IMMUTABLE;= 现值剥离不写),路由层负责剥离。
448
636
  */
449
637
  declare const DagTemplateUpdateSchema: z.ZodObject<{
450
638
  name: z.ZodOptional<z.ZodString>;
639
+ code: z.ZodOptional<z.ZodOptional<z.ZodString>>;
451
640
  description: z.ZodOptional<z.ZodString>;
452
641
  projectId: z.ZodOptional<z.ZodString>;
453
642
  nodes: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -457,6 +646,13 @@ declare const DagTemplateUpdateSchema: z.ZodObject<{
457
646
  track: z.ZodString;
458
647
  prompt: z.ZodString;
459
648
  skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
649
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
650
+ sourcePreset: z.ZodOptional<z.ZodObject<{
651
+ code: z.ZodString;
652
+ version: z.ZodString;
653
+ contentHash: z.ZodString;
654
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
655
+ }, z.core.$strip>>;
460
656
  }, z.core.$strip>>>;
461
657
  edges: z.ZodOptional<z.ZodArray<z.ZodObject<{
462
658
  from: z.ZodString;
@@ -481,23 +677,67 @@ declare const DagTemplateUpdateSchema: z.ZodObject<{
481
677
  type DagTemplateUpdate = z.infer<typeof DagTemplateUpdateSchema>;
482
678
  /**
483
679
  * 模板复制入参(N012 F5/D5,契约命名对齐方案 §3.2.3):目标项目 + 新名称;副本落库为可编辑独立实体(version 重置 '1.0.0',isDefault=false)。
680
+ * T202609020002:newCode 可选——显式指定副本 code(格式强校验);缺省按 newName 规范化自动生成。
681
+ * 副本 code 与源模板 code 相互独立(源 code 不随拷贝,同项目复制必撞唯一索引)。
484
682
  */
485
683
  declare const DagTemplateCopySchema: z.ZodObject<{
486
684
  newName: z.ZodString;
487
685
  targetProjectId: z.ZodString;
686
+ newCode: z.ZodOptional<z.ZodString>;
488
687
  }, z.core.$strip>;
489
688
  type DagTemplateCopy = z.infer<typeof DagTemplateCopySchema>;
689
+ /**
690
+ * K12:模板节点 id 唯一共享校验(core 单点,路由 create/PUT 与 template-transfer applyImport 双挂)。
691
+ * 函数级校验而非 schema 级——模板级 schema 禁挂 refine(Zod4 派生陷阱,见 DagTemplateSchema 注释)。
692
+ */
693
+ declare function findDuplicateNodeIds(nodes: ReadonlyArray<{
694
+ id: string;
695
+ }>): string[];
696
+ declare function assertUniqueNodeIds(nodes: ReadonlyArray<{
697
+ id: string;
698
+ }>): void;
490
699
 
491
700
  type DagTemplateRepo = Repo<DagTemplate> & {
492
701
  createDagTemplate(data: DagTemplateCreate): Promise<DagTemplate>;
493
- /** N015 F17:list 支持 name 过滤(export 查重按 projectId+name,name 项目内唯一) */
702
+ /**
703
+ * N015 F17:list 支持 name 过滤(export 查查重按 projectId+name,name 项目内唯一)。
704
+ * T202608290001:includeDisabled 缺省排除停用模板(CLI/MCP 列举 + 建任务选择器视图);
705
+ * true 时含停用(Web 管理台列表视图)。by-id 寻址不过滤(详情/创建守卫走显式判定)。
706
+ * T202609020002:code 精确过滤(与 q 正交;code 项目内唯一,命中至多一条)。
707
+ */
494
708
  listDagTemplates(filter?: {
495
709
  projectId?: string;
496
710
  name?: string;
711
+ code?: string;
712
+ includeDisabled?: boolean;
497
713
  }): Promise<DagTemplate[]>;
498
- /** 深拷贝复制(N012 F5/D5):副本落目标项目,version 重置 '1.0.0'、isDefault=false;目标项目内重名 → 409 */
499
- copyDagTemplate(sourceId: string, targetProjectId: string, newName: string): Promise<DagTemplate>;
714
+ /** 深拷贝复制(N012 F5/D5):副本落目标项目,version 重置 '1.0.0'、isDefault=false;目标项目内重名 → 409
715
+ * T202609020002:副本 code 独立——newCode 显式指定或按 newName 自动生成(源 code 不随拷贝,同项目必撞唯一索引)。 */
716
+ copyDagTemplate(sourceId: string, targetProjectId: string, newName: string, newCode?: string): Promise<DagTemplate>;
717
+ /** T202609020002:按 code 项目内寻址(含停用——与 by-id 详情同视图;启用过滤归创建守卫显式判定) */
718
+ getByCode(projectId: string, code: string): Promise<DagTemplate | null>;
719
+ /**
720
+ * T202609020002:二阶段寻址——24-hex 直查 id 命中即返回(兼容层优先探活,防正交误判劫持);
721
+ * hex 直查未命中不转 code 检索(code 必含连字符与 hex 形态互斥,检索必空)。
722
+ * 非 hex 形态且提供项目上下文 → 按 code 项目内检索;projectCtx 缺省时不检索
723
+ * (code 项目内唯一,无项目域无法消歧)。全未命中返回 null(候选清单归路由层)。
724
+ */
725
+ resolveTemplateByRef(ref: string, projectCtx?: string): Promise<DagTemplate | null>;
726
+ /** T202609020002:not-found 相近候选(项目内全量含停用 → 内存评分排序,上限 limit;空数组 = 无相近) */
727
+ findSimilarTemplates(projectId: string, ref: string, limit?: number): Promise<TemplateCandidate[]>;
500
728
  };
729
+ /** 展示名 → kebab 基串(纯函数):转小写、非字母数字折叠为连字符、合并连字符、裁长度。
730
+ * 中文名/纯特殊字符规范化后为空串(兜底序列覆盖,见 buildTemplateCode)。 */
731
+ declare function normalizeNameToTemplateCode(name: string): string;
732
+ /** code 合法口径单源(regex + 长度上限;创建生成/迁移判定/寻址校验共用)——server 迁移侧复用导出 */
733
+ declare function isLegalTemplateCode(code: string): boolean;
734
+ /**
735
+ * 生成项目内唯一合法 code(纯函数,创建缺省路径与存量迁移共用):
736
+ * - 多段名(规范化后含连字符)→ 原样采用;单段名 → 补 `tpl-` 前缀段(保证含连字符、与 id 形态可区分)
737
+ * - 规范化为空(纯中文/特殊字符名)→ `tpl-1` 兜底序列
738
+ * - 冲突消歧:`{primary}-2`、`{primary}-3` …(后缀追加前裁 base 保总长 ≤31)
739
+ */
740
+ declare function buildTemplateCode(seedName: string, takenCodes: Iterable<string>): string;
501
741
  declare function createDagTemplateRepo(db: Db): DagTemplateRepo;
502
742
 
503
743
  /**
@@ -646,6 +886,21 @@ declare const NodeStateSchema: z.ZodObject<{
646
886
  completedAt: z.ZodDefault<z.ZodNullable<z.ZodDate>>;
647
887
  }, z.core.$strip>;
648
888
  type NodeState = z.infer<typeof NodeStateSchema>;
889
+ /**
890
+ * 任务实例节点:任务创建时从模板值拷贝的运行态节点。
891
+ * `GET /api/tasks/:taskId/node/:nodeId` 在此结构上渲染 prompt 后返回同形 DTO;
892
+ * 它不同于流转资料包 NodeInfo(后者使用 nodeId 和 upcomingPause)。
893
+ */
894
+ declare const DagInstanceNodeSchema: z.ZodObject<{
895
+ id: z.ZodString;
896
+ label: z.ZodString;
897
+ phase: z.ZodString;
898
+ track: z.ZodString;
899
+ prompt: z.ZodString;
900
+ skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
901
+ agents: z.ZodDefault<z.ZodArray<z.ZodString>>;
902
+ }, z.core.$strip>;
903
+ type DagInstanceNode = z.infer<typeof DagInstanceNodeSchema>;
649
904
  declare const DagInstanceSchema: z.ZodObject<{
650
905
  templateId: z.ZodString;
651
906
  templateVersion: z.ZodString;
@@ -656,6 +911,7 @@ declare const DagInstanceSchema: z.ZodObject<{
656
911
  track: z.ZodString;
657
912
  prompt: z.ZodString;
658
913
  skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
914
+ agents: z.ZodDefault<z.ZodArray<z.ZodString>>;
659
915
  }, z.core.$strip>>;
660
916
  edges: z.ZodArray<z.ZodObject<{
661
917
  from: z.ZodString;
@@ -738,6 +994,7 @@ declare const TaskSchema: z.ZodObject<{
738
994
  track: z.ZodString;
739
995
  prompt: z.ZodString;
740
996
  skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
997
+ agents: z.ZodDefault<z.ZodArray<z.ZodString>>;
741
998
  }, z.core.$strip>>;
742
999
  edges: z.ZodArray<z.ZodObject<{
743
1000
  from: z.ZodString;
@@ -885,6 +1142,7 @@ declare const TaskContextSchema: z.ZodObject<{
885
1142
  track: z.ZodString;
886
1143
  prompt: z.ZodString;
887
1144
  skills: z.ZodArray<z.ZodString>;
1145
+ agents: z.ZodArray<z.ZodString>;
888
1146
  upcomingPause: z.ZodNullable<z.ZodString>;
889
1147
  }, z.core.$strip>>;
890
1148
  pausedAtEdge: z.ZodNullable<z.ZodObject<{
@@ -996,6 +1254,8 @@ type TaskListFilter = {
996
1254
  page?: number;
997
1255
  limit?: number;
998
1256
  sort?: 'progress' | 'createdAt' | 'updatedAt';
1257
+ /** T202608290001:标题模糊搜索(不区分大小写的包含匹配——元字符转义防注入,长度上限归路由层) */
1258
+ q?: string;
999
1259
  };
1000
1260
  /**
1001
1261
  * N020 D1:点路径小步更新载荷。sets/pushes 的 key 均为(点)路径字符串,
@@ -1180,7 +1440,7 @@ declare function assertModelAliasExists(repo: ModelAliasRepo, code: string): Pro
1180
1440
  * - color:可选 UI 语义色 token(如 --success);
1181
1441
  * - order:下拉排序;builtin:内置值(禁删,D8);active:启停(禁用值下拉不可选,D8)。
1182
1442
  */
1183
- /** 7 类注册表 category 白名单(D4:固定分类,不可增删) */
1443
+ /** 注册表 category 白名单(D4:固定分类,不可增删)。T202608260002:agent_function 为第二个「schema 固定枚举权威 + registry 仅展示」双轨类(继 pause_type 先例) */
1184
1444
  declare const EnumRegistryCategorySchema: z.ZodEnum<{
1185
1445
  scope: "scope";
1186
1446
  dag_phase: "dag_phase";
@@ -1189,6 +1449,7 @@ declare const EnumRegistryCategorySchema: z.ZodEnum<{
1189
1449
  task_status: "task_status";
1190
1450
  node_status: "node_status";
1191
1451
  skill_category: "skill_category";
1452
+ agent_function: "agent_function";
1192
1453
  }>;
1193
1454
  type EnumRegistryCategory = z.infer<typeof EnumRegistryCategorySchema>;
1194
1455
  /** 注册表条目(D5) */
@@ -1212,6 +1473,7 @@ declare const EnumRegistrySchema: z.ZodObject<{
1212
1473
  task_status: "task_status";
1213
1474
  node_status: "node_status";
1214
1475
  skill_category: "skill_category";
1476
+ agent_function: "agent_function";
1215
1477
  }>;
1216
1478
  entries: z.ZodDefault<z.ZodArray<z.ZodObject<{
1217
1479
  value: z.ZodString;
@@ -1241,7 +1503,7 @@ declare const EnumRegistryUpdateSchema: z.ZodObject<{
1241
1503
  type EnumRegistryUpdate = z.infer<typeof EnumRegistryUpdateSchema>;
1242
1504
 
1243
1505
  type EnumRegistryRepo = Repo<EnumRegistry> & {
1244
- /** 全量 7 类(SettingsPage 一次性加载;N017 删 gate_type 后由 8 类收窄) */
1506
+ /** 全量 8 类(SettingsPage 一次性加载;N017 删 gate_type 后收窄为 7 类,T202608260002 增 agent_function 复为 8 类) */
1245
1507
  listRegistries(): Promise<EnumRegistry[]>;
1246
1508
  /** 单类(按 category) */
1247
1509
  getRegistry(category: EnumRegistryCategory): Promise<EnumRegistry | null>;
@@ -1267,144 +1529,1394 @@ type EnumRegistryRepo = Repo<EnumRegistry> & {
1267
1529
  declare function createEnumRegistryRepo(db: Db): EnumRegistryRepo;
1268
1530
 
1269
1531
  /**
1270
- * Advance / Approve 相关 Schemas
1532
+ * NodePreset Schema 通用 DAG 节点资产(T202609020001)
1271
1533
  *
1272
- * N017 D5:审批(人工决策)与推进(节点完成)拆为两个动作——
1273
- * advance 请求体变可选 {note?}(原 gateResults 数组删除);
1274
- * 新增独立 ApproveRequest/ApproveResponse。
1534
+ * code = 全局唯一(跨作用域)业务键(npm 分发 / 组合引用 / 升级寻址),kebab-case、创建后不可变;
1535
+ * nodeId = 组装进模板时的默认节点标识(模板内可改名且不影响来源关联——升级按 code 寻址)。
1536
+ * skills 在 Shape 层无 default(F22):防 Update 派生后 default 注入清空绑定——Create 侧显式 extend 注入。
1275
1537
  */
1538
+ declare const NODE_PRESET_CODE_PATTERN: RegExp;
1276
1539
  /**
1277
- * N017 F8:gate 机制退役——advance 只是"当前节点完成,按出边流转"。
1278
- * N020 D1:轻量收尾——note 为可选历史备注;summary 为可选收尾摘要
1279
- * (写入 nodeRecords.<node>.summary,内容主体已在执行期间小步落库)。
1540
+ * Shape 层(纯 object 不挂 refine;default 字段一律不在本层——scope/skills/version 均无 default)。
1541
+ * 实体/派生全从本层 omit/extend,禁止在 refined 全量 schema 上调对象级方法(Zod4 运行时陷阱)。
1280
1542
  */
1281
- declare const AdvanceRequestSchema: z.ZodObject<{
1282
- note: z.ZodOptional<z.ZodString>;
1283
- summary: z.ZodOptional<z.ZodString>;
1284
- }, z.core.$strip>;
1285
- type AdvanceRequest = z.infer<typeof AdvanceRequestSchema>;
1286
- /** 暂停点审批:approved=通过并流转;rejected=驳回保持 paused(comment 为决策说明) */
1287
- declare const ApproveRequestSchema: z.ZodObject<{
1288
- decision: z.ZodEnum<{
1289
- approved: "approved";
1290
- rejected: "rejected";
1291
- }>;
1292
- comment: z.ZodOptional<z.ZodString>;
1293
- }, z.core.$strip>;
1294
- type ApproveRequest = z.infer<typeof ApproveRequestSchema>;
1295
- declare const TaskPublicSchema: z.ZodObject<{
1296
- taskId: z.ZodString;
1297
- title: z.ZodString;
1298
- type: z.ZodOptional<z.ZodEnum<{
1299
- feature: "feature";
1300
- bugfix: "bugfix";
1301
- "ui-tweak": "ui-tweak";
1302
- research: "research";
1303
- }>>;
1304
- currentNode: z.ZodString;
1305
- currentPhase: z.ZodString;
1306
- status: z.ZodString;
1307
- pausedAt: z.ZodNullable<z.ZodString>;
1543
+ declare const NodePresetShapeSchema: z.ZodObject<{
1544
+ id: z.ZodOptional<z.ZodString>;
1545
+ code: z.ZodString;
1546
+ label: z.ZodString;
1547
+ nodeId: z.ZodString;
1548
+ phase: z.ZodString;
1308
1549
  track: z.ZodString;
1550
+ prompt: z.ZodString;
1551
+ skills: z.ZodArray<z.ZodString>;
1552
+ agents: z.ZodArray<z.ZodString>;
1553
+ scope: z.ZodEnum<{
1554
+ global: "global";
1555
+ project: "project";
1556
+ }>;
1557
+ projectId: z.ZodOptional<z.ZodString>;
1558
+ description: z.ZodOptional<z.ZodString>;
1559
+ version: z.ZodString;
1560
+ source: z.ZodOptional<z.ZodObject<{
1561
+ package: z.ZodString;
1562
+ }, z.core.$strip>>;
1563
+ enabled: z.ZodOptional<z.ZodBoolean>;
1564
+ createdAt: z.ZodOptional<z.ZodDate>;
1565
+ updatedAt: z.ZodOptional<z.ZodDate>;
1309
1566
  }, z.core.$strip>;
1310
- type TaskPublic = z.infer<typeof TaskPublicSchema>;
1311
- /** N017 F8:删 gates;upcomingPause 语义改为"完成当前节点后出边上的暂停点描述"(经 findNextEdge 按轨选边) */
1312
- declare const NodeInfoSchema: z.ZodObject<{
1313
- nodeId: z.ZodString;
1567
+ declare const NodePresetSchema: z.ZodObject<{
1568
+ id: z.ZodOptional<z.ZodString>;
1569
+ code: z.ZodString;
1314
1570
  label: z.ZodString;
1571
+ nodeId: z.ZodString;
1572
+ phase: z.ZodString;
1315
1573
  track: z.ZodString;
1316
1574
  prompt: z.ZodString;
1317
1575
  skills: z.ZodArray<z.ZodString>;
1318
- upcomingPause: z.ZodNullable<z.ZodString>;
1576
+ agents: z.ZodArray<z.ZodString>;
1577
+ scope: z.ZodEnum<{
1578
+ global: "global";
1579
+ project: "project";
1580
+ }>;
1581
+ projectId: z.ZodOptional<z.ZodString>;
1582
+ description: z.ZodOptional<z.ZodString>;
1583
+ version: z.ZodString;
1584
+ source: z.ZodOptional<z.ZodObject<{
1585
+ package: z.ZodString;
1586
+ }, z.core.$strip>>;
1587
+ enabled: z.ZodOptional<z.ZodBoolean>;
1588
+ createdAt: z.ZodOptional<z.ZodDate>;
1589
+ updatedAt: z.ZodOptional<z.ZodDate>;
1319
1590
  }, z.core.$strip>;
1320
- type NodeInfo = z.infer<typeof NodeInfoSchema>;
1321
- /** N017 D7:删 gate_failed 分支(union 收窄为 advanced / paused / completed);paused 分支 pausePoint 类型改 EdgePausePoint */
1322
- declare const AdvanceResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1323
- status: z.ZodLiteral<"advanced">;
1324
- task: z.ZodObject<{
1325
- taskId: z.ZodString;
1326
- title: z.ZodString;
1327
- type: z.ZodOptional<z.ZodEnum<{
1328
- feature: "feature";
1329
- bugfix: "bugfix";
1330
- "ui-tweak": "ui-tweak";
1331
- research: "research";
1332
- }>>;
1333
- currentNode: z.ZodString;
1334
- currentPhase: z.ZodString;
1335
- status: z.ZodString;
1336
- pausedAt: z.ZodNullable<z.ZodString>;
1337
- track: z.ZodString;
1338
- }, z.core.$strip>;
1339
- nextNode: z.ZodObject<{
1340
- nodeId: z.ZodString;
1341
- label: z.ZodString;
1342
- track: z.ZodString;
1343
- prompt: z.ZodString;
1344
- skills: z.ZodArray<z.ZodString>;
1345
- upcomingPause: z.ZodNullable<z.ZodString>;
1346
- }, z.core.$strip>;
1347
- }, z.core.$strip>, z.ZodObject<{
1348
- status: z.ZodLiteral<"paused">;
1349
- task: z.ZodObject<{
1350
- taskId: z.ZodString;
1351
- title: z.ZodString;
1352
- type: z.ZodOptional<z.ZodEnum<{
1353
- feature: "feature";
1354
- bugfix: "bugfix";
1355
- "ui-tweak": "ui-tweak";
1356
- research: "research";
1357
- }>>;
1358
- currentNode: z.ZodString;
1359
- currentPhase: z.ZodString;
1360
- status: z.ZodString;
1361
- pausedAt: z.ZodNullable<z.ZodString>;
1362
- track: z.ZodString;
1363
- }, z.core.$strip>;
1364
- pausePoint: z.ZodObject<{
1365
- type: z.ZodEnum<{
1366
- human_approval: "human_approval";
1367
- checkpoint: "checkpoint";
1368
- }>;
1369
- description: z.ZodString;
1370
- autoResume: z.ZodDefault<z.ZodBoolean>;
1371
- }, z.core.$strip>;
1372
- guidance: z.ZodString;
1373
- }, z.core.$strip>, z.ZodObject<{
1374
- status: z.ZodLiteral<"completed">;
1375
- task: z.ZodObject<{
1376
- taskId: z.ZodString;
1377
- title: z.ZodString;
1378
- type: z.ZodOptional<z.ZodEnum<{
1379
- feature: "feature";
1380
- bugfix: "bugfix";
1381
- "ui-tweak": "ui-tweak";
1382
- research: "research";
1383
- }>>;
1384
- currentNode: z.ZodString;
1385
- currentPhase: z.ZodString;
1386
- status: z.ZodString;
1387
- pausedAt: z.ZodNullable<z.ZodString>;
1388
- track: z.ZodString;
1389
- }, z.core.$strip>;
1390
- }, z.core.$strip>], "status">;
1391
- type AdvanceResponse = z.infer<typeof AdvanceResponseSchema>;
1392
- declare const ApproveResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1393
- status: z.ZodLiteral<"advanced">;
1394
- task: z.ZodObject<{
1395
- taskId: z.ZodString;
1396
- title: z.ZodString;
1397
- type: z.ZodOptional<z.ZodEnum<{
1398
- feature: "feature";
1399
- bugfix: "bugfix";
1400
- "ui-tweak": "ui-tweak";
1401
- research: "research";
1402
- }>>;
1403
- currentNode: z.ZodString;
1404
- currentPhase: z.ZodString;
1405
- status: z.ZodString;
1406
- pausedAt: z.ZodNullable<z.ZodString>;
1407
- track: z.ZodString;
1591
+ type NodePreset = z.infer<typeof NodePresetSchema>;
1592
+ /**
1593
+ * 创建输入:default 一律在派生层显式注入(skills/agents/version),Shape 保持无 default——
1594
+ * UpdateSchema 由同一 Shape 派生,Shape 层 default 会被 .partial() 保留注入(F22 反例)。
1595
+ */
1596
+ declare const NodePresetCreateSchema: z.ZodObject<{
1597
+ code: z.ZodString;
1598
+ description: z.ZodOptional<z.ZodString>;
1599
+ scope: z.ZodEnum<{
1600
+ global: "global";
1601
+ project: "project";
1602
+ }>;
1603
+ projectId: z.ZodOptional<z.ZodString>;
1604
+ track: z.ZodString;
1605
+ phase: z.ZodString;
1606
+ label: z.ZodString;
1607
+ prompt: z.ZodString;
1608
+ nodeId: z.ZodString;
1609
+ source: z.ZodOptional<z.ZodObject<{
1610
+ package: z.ZodString;
1611
+ }, z.core.$strip>>;
1612
+ skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
1613
+ agents: z.ZodDefault<z.ZodArray<z.ZodString>>;
1614
+ version: z.ZodDefault<z.ZodString>;
1615
+ }, z.core.$strip>;
1616
+ type NodePresetCreate = z.infer<typeof NodePresetCreateSchema>;
1617
+ /**
1618
+ * 更新输入(PUT partial,先 partial 后挂 refine——Zod4 范式)。
1619
+ * code/scope/projectId 保留在 schema(partial 后可选)供不可变守卫判定:路由层「携带且与现值不同 → 409」
1620
+ * (对齐 skill/agent isScopeMutation 语义);同值携带为幂等 no-op,不触发守卫。
1621
+ */
1622
+ declare const NodePresetUpdateSchema: z.ZodObject<{
1623
+ code: z.ZodOptional<z.ZodString>;
1624
+ description: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1625
+ scope: z.ZodOptional<z.ZodEnum<{
1626
+ global: "global";
1627
+ project: "project";
1628
+ }>>;
1629
+ projectId: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1630
+ skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
1631
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
1632
+ track: z.ZodOptional<z.ZodString>;
1633
+ phase: z.ZodOptional<z.ZodString>;
1634
+ label: z.ZodOptional<z.ZodString>;
1635
+ prompt: z.ZodOptional<z.ZodString>;
1636
+ nodeId: z.ZodOptional<z.ZodString>;
1637
+ source: z.ZodOptional<z.ZodOptional<z.ZodObject<{
1638
+ package: z.ZodString;
1639
+ }, z.core.$strip>>>;
1640
+ version: z.ZodOptional<z.ZodOptional<z.ZodString>>;
1641
+ }, z.core.$strip>;
1642
+ type NodePresetUpdate = z.infer<typeof NodePresetUpdateSchema>;
1643
+ /** by-code 复制入参:newCode 全局唯一预校验;副本 version 重置 '1.0.0'、剥除 source(手工副本无包来源) */
1644
+ declare const NodePresetCopySchema: z.ZodObject<{
1645
+ newCode: z.ZodString;
1646
+ newScope: z.ZodEnum<{
1647
+ global: "global";
1648
+ project: "project";
1649
+ }>;
1650
+ targetProjectId: z.ZodOptional<z.ZodString>;
1651
+ }, z.core.$strip>;
1652
+ type NodePresetCopy = z.infer<typeof NodePresetCopySchema>;
1653
+
1654
+ interface NodePresetListFilter {
1655
+ scope?: 'global' | 'project' | undefined;
1656
+ /** 叠加可见语义(scope 缺省时):global + 该项目专用 */
1657
+ projectId?: string | undefined;
1658
+ q?: string | undefined;
1659
+ includeDisabled?: boolean | undefined;
1660
+ }
1661
+ type NodePresetRepo = Repo<NodePreset> & {
1662
+ /** code 预校验(409 NODE_PRESET_CODE_EXISTS 先于 E11000 兜底)+ 落库 */
1663
+ createNodePreset(data: NodePresetCreate): Promise<NodePreset>;
1664
+ /** by-code 寻址(code 全局唯一无 scope 消歧);缺省排除停用(读可见性),写通道显式 includeDisabled */
1665
+ getByCode(code: string, opts?: {
1666
+ includeDisabled?: boolean | undefined;
1667
+ }): Promise<NodePreset | null>;
1668
+ /** 写通道更新(显式放行停用资产——启停不冻结管理操作,对齐 skill 惯例) */
1669
+ updateByCode(code: string, patch: EoptPartial<Omit<NodePreset, 'id'>>): Promise<NodePreset | null>;
1670
+ /** 写通道删除(同上放行停用) */
1671
+ deleteByCode(code: string): Promise<boolean>;
1672
+ /** 作用域过滤列表(scope=精确作用域 / projectId=叠加可见 / 缺省全量管理视角;q 搜 code 与 label) */
1673
+ listNodePresets(filter?: NodePresetListFilter): Promise<NodePreset[]>;
1674
+ /** 批量预取(含停用——升级 plan 的 source-disabled 判定依赖;code 全局唯一直查) */
1675
+ listByCodes(codes: string[]): Promise<Map<string, NodePreset>>;
1676
+ /** 仅返回 code 是否已占用;供受限身份做安装预检,不暴露归属或内容。 */
1677
+ isCodeOccupied(code: string): Promise<boolean>;
1678
+ /** by-code 复制:newCode 全局预校验;version 重置 '1.0.0'、剥除 source(手工副本无包来源)、副本默认启用 */
1679
+ copyNodePreset(sourceCode: string, target: {
1680
+ scope: 'global' | 'project';
1681
+ projectId?: string;
1682
+ }, input: NodePresetCopy): Promise<NodePreset>;
1683
+ };
1684
+ declare function createNodePresetRepo(db: Db): NodePresetRepo;
1685
+
1686
+ /**
1687
+ * NodeLibrary Schema — npm 节点库安装登记(T202609020001 K7)
1688
+ *
1689
+ * 运维登记非用户资产:记录已装库的版本 / 节点 code 清单 / 组合定义全文(flow compose 数据通道)
1690
+ * 与漂移检测基线;同库重装按 name upsert 覆盖({name} unique)。
1691
+ * 写入经 server 端点 /api/node-libraries(CLI 是无状态 HTTP 客户端,不直连库)。
1692
+ */
1693
+ /** 组合边(暂停点内联于 edge——与 DagEdge 模型一致,无顶层 pausePoints 字段) */
1694
+ declare const CompositionEdgeSchema: z.ZodObject<{
1695
+ from: z.ZodString;
1696
+ to: z.ZodString;
1697
+ condition: z.ZodOptional<z.ZodString>;
1698
+ pausePoint: z.ZodOptional<z.ZodObject<{
1699
+ type: z.ZodEnum<{
1700
+ human_approval: "human_approval";
1701
+ checkpoint: "checkpoint";
1702
+ }>;
1703
+ description: z.ZodString;
1704
+ autoResume: z.ZodDefault<z.ZodBoolean>;
1705
+ }, z.core.$strip>>;
1706
+ }, z.core.$strip>;
1707
+ type CompositionEdge = z.infer<typeof CompositionEdgeSchema>;
1708
+ /** 组合定义(nodes 为 NodePreset code 引用清单;edges 拓扑照抄组装进模板) */
1709
+ declare const CompositionSchema: z.ZodObject<{
1710
+ name: z.ZodString;
1711
+ description: z.ZodOptional<z.ZodString>;
1712
+ nodes: z.ZodArray<z.ZodString>;
1713
+ edges: z.ZodArray<z.ZodObject<{
1714
+ from: z.ZodString;
1715
+ to: z.ZodString;
1716
+ condition: z.ZodOptional<z.ZodString>;
1717
+ pausePoint: z.ZodOptional<z.ZodObject<{
1718
+ type: z.ZodEnum<{
1719
+ human_approval: "human_approval";
1720
+ checkpoint: "checkpoint";
1721
+ }>;
1722
+ description: z.ZodString;
1723
+ autoResume: z.ZodDefault<z.ZodBoolean>;
1724
+ }, z.core.$strip>>;
1725
+ }, z.core.$strip>>;
1726
+ }, z.core.$strip>;
1727
+ type Composition = z.infer<typeof CompositionSchema>;
1728
+ declare const NodeLibrarySchema: z.ZodObject<{
1729
+ id: z.ZodOptional<z.ZodString>;
1730
+ name: z.ZodString;
1731
+ version: z.ZodString;
1732
+ scope: z.ZodEnum<{
1733
+ global: "global";
1734
+ project: "project";
1735
+ }>;
1736
+ projectId: z.ZodOptional<z.ZodString>;
1737
+ nodes: z.ZodArray<z.ZodString>;
1738
+ compositions: z.ZodArray<z.ZodObject<{
1739
+ name: z.ZodString;
1740
+ description: z.ZodOptional<z.ZodString>;
1741
+ nodes: z.ZodArray<z.ZodString>;
1742
+ edges: z.ZodArray<z.ZodObject<{
1743
+ from: z.ZodString;
1744
+ to: z.ZodString;
1745
+ condition: z.ZodOptional<z.ZodString>;
1746
+ pausePoint: z.ZodOptional<z.ZodObject<{
1747
+ type: z.ZodEnum<{
1748
+ human_approval: "human_approval";
1749
+ checkpoint: "checkpoint";
1750
+ }>;
1751
+ description: z.ZodString;
1752
+ autoResume: z.ZodDefault<z.ZodBoolean>;
1753
+ }, z.core.$strip>>;
1754
+ }, z.core.$strip>>;
1755
+ }, z.core.$strip>>;
1756
+ installedAt: z.ZodOptional<z.ZodDate>;
1757
+ }, z.core.$strip>;
1758
+ type NodeLibrary = z.infer<typeof NodeLibrarySchema>;
1759
+ /** 安装登记 upsert 入参(flow install 全部节点落库成功后写入——登记后置,防节点半落库登记先行的部分副作用) */
1760
+ declare const NodeLibraryUpsertSchema: z.ZodObject<{
1761
+ name: z.ZodString;
1762
+ version: z.ZodString;
1763
+ scope: z.ZodEnum<{
1764
+ global: "global";
1765
+ project: "project";
1766
+ }>;
1767
+ projectId: z.ZodOptional<z.ZodString>;
1768
+ nodes: z.ZodArray<z.ZodString>;
1769
+ compositions: z.ZodArray<z.ZodObject<{
1770
+ name: z.ZodString;
1771
+ description: z.ZodOptional<z.ZodString>;
1772
+ nodes: z.ZodArray<z.ZodString>;
1773
+ edges: z.ZodArray<z.ZodObject<{
1774
+ from: z.ZodString;
1775
+ to: z.ZodString;
1776
+ condition: z.ZodOptional<z.ZodString>;
1777
+ pausePoint: z.ZodOptional<z.ZodObject<{
1778
+ type: z.ZodEnum<{
1779
+ human_approval: "human_approval";
1780
+ checkpoint: "checkpoint";
1781
+ }>;
1782
+ description: z.ZodString;
1783
+ autoResume: z.ZodDefault<z.ZodBoolean>;
1784
+ }, z.core.$strip>>;
1785
+ }, z.core.$strip>>;
1786
+ }, z.core.$strip>>;
1787
+ }, z.core.$strip>;
1788
+ type NodeLibraryUpsert = z.infer<typeof NodeLibraryUpsertSchema>;
1789
+
1790
+ type NodeLibraryRepo = Repo<NodeLibrary> & {
1791
+ /**
1792
+ * 同库重装 upsert({name} unique):按 name 定位整笔替换 version/nodes/compositions,
1793
+ * installedAt 刷新为本次安装时刻。scope 变更(global ↔ project)随 upsert 一并生效——
1794
+ * 登记是运维态非用户资产,以最后一次安装的事实为准。
1795
+ */
1796
+ upsertNodeLibrary(data: NodeLibraryUpsert): Promise<NodeLibrary>;
1797
+ /** 可见性过滤列表(叠加/精确语义由路由层决定传参:project 上下文恒 overlay 本项目) */
1798
+ listNodeLibraries(filter?: {
1799
+ scope?: 'global' | 'project' | undefined;
1800
+ projectId?: string | undefined;
1801
+ }): Promise<NodeLibrary[]>;
1802
+ };
1803
+ declare function createNodeLibraryRepo(db: Db): NodeLibraryRepo;
1804
+
1805
+ /**
1806
+ * Auth Schema — 云主机部署权限体系(T202608310001)
1807
+ * 三凭证模型:管理员账号密码(Web 登录)/ 管理员 Token(admin- 前缀,全权)/
1808
+ * 项目 Token(project- 前缀,绑定单项目读写、全局资产只读)。
1809
+ * 服务端仅存单向哈希(密码 scrypt / Token sha256),明文零落库。
1810
+ */
1811
+ /** Token 类型:前缀自描述(admin- / project-),随机部分 43 字符 base64url */
1812
+ declare const AuthTokenTypeSchema: z.ZodEnum<{
1813
+ project: "project";
1814
+ admin: "admin";
1815
+ }>;
1816
+ type AuthTokenType = z.infer<typeof AuthTokenTypeSchema>;
1817
+ declare const AuthAccountSchema: z.ZodObject<{
1818
+ id: z.ZodOptional<z.ZodString>;
1819
+ username: z.ZodString;
1820
+ passwordHash: z.ZodString;
1821
+ createdAt: z.ZodOptional<z.ZodDate>;
1822
+ updatedAt: z.ZodOptional<z.ZodDate>;
1823
+ }, z.core.$strip>;
1824
+ type AuthAccount = z.infer<typeof AuthAccountSchema>;
1825
+ /** 初始化引导创建唯一管理员账号(PRD §3.2:密码最小长度 8) */
1826
+ declare const AuthAccountCreateSchema: z.ZodObject<{
1827
+ username: z.ZodString;
1828
+ password: z.ZodString;
1829
+ }, z.core.$strip>;
1830
+ type AuthAccountCreate = z.infer<typeof AuthAccountCreateSchema>;
1831
+ /** 修改密码:需验证当前密码;新密码策略同初始化(PRD §3.2) */
1832
+ declare const PasswordChangeSchema: z.ZodObject<{
1833
+ currentPassword: z.ZodString;
1834
+ newPassword: z.ZodString;
1835
+ }, z.core.$strip>;
1836
+ type PasswordChange = z.infer<typeof PasswordChangeSchema>;
1837
+ declare const LoginSchema: z.ZodObject<{
1838
+ username: z.ZodString;
1839
+ password: z.ZodString;
1840
+ }, z.core.$strip>;
1841
+ type LoginInput = z.infer<typeof LoginSchema>;
1842
+ declare const AuthTokenSchema: z.ZodObject<{
1843
+ id: z.ZodOptional<z.ZodString>;
1844
+ tokenHash: z.ZodString;
1845
+ type: z.ZodEnum<{
1846
+ project: "project";
1847
+ admin: "admin";
1848
+ }>;
1849
+ projectId: z.ZodOptional<z.ZodString>;
1850
+ createdAt: z.ZodOptional<z.ZodDate>;
1851
+ updatedAt: z.ZodOptional<z.ZodDate>;
1852
+ }, z.core.$strip>;
1853
+ type AuthToken = z.infer<typeof AuthTokenSchema>;
1854
+ /** Token 生成响应:明文 Token 仅此形态出现一次(PRD §3.5 一次性展示) */
1855
+ declare const AuthTokenGenResponseSchema: z.ZodObject<{
1856
+ token: z.ZodString;
1857
+ type: z.ZodEnum<{
1858
+ project: "project";
1859
+ admin: "admin";
1860
+ }>;
1861
+ projectId: z.ZodOptional<z.ZodString>;
1862
+ }, z.core.$strip>;
1863
+ type AuthTokenGenResponse = z.infer<typeof AuthTokenGenResponseSchema>;
1864
+ /** Token 状态视图(无值):列表/详情展示形态 */
1865
+ declare const AuthTokenStatusSchema: z.ZodObject<{
1866
+ type: z.ZodEnum<{
1867
+ project: "project";
1868
+ admin: "admin";
1869
+ }>;
1870
+ projectId: z.ZodOptional<z.ZodString>;
1871
+ hasToken: z.ZodBoolean;
1872
+ createdAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
1873
+ }, z.core.$strip>;
1874
+ type AuthTokenStatus = z.infer<typeof AuthTokenStatusSchema>;
1875
+ /** whoami 身份查询响应(身份四元组:身份 + 绑定项目 + server 地址 + 开关状态,PRD §3.6) */
1876
+ declare const AuthWhoamiSchema: z.ZodObject<{
1877
+ identity: z.ZodEnum<{
1878
+ none: "none";
1879
+ project: "project";
1880
+ admin: "admin";
1881
+ }>;
1882
+ project: z.ZodOptional<z.ZodNullable<z.ZodObject<{
1883
+ id: z.ZodString;
1884
+ key: z.ZodString;
1885
+ name: z.ZodString;
1886
+ }, z.core.$strip>>>;
1887
+ authEnabled: z.ZodBoolean;
1888
+ server: z.ZodObject<{
1889
+ url: z.ZodString;
1890
+ }, z.core.$strip>;
1891
+ }, z.core.$strip>;
1892
+ type AuthWhoami = z.infer<typeof AuthWhoamiSchema>;
1893
+ /** 鉴权开关状态(预鉴权可达,例外②身份元信息) */
1894
+ declare const AuthStatusSchema: z.ZodObject<{
1895
+ authEnabled: z.ZodBoolean;
1896
+ needsSetup: z.ZodBoolean;
1897
+ }, z.core.$strip>;
1898
+ type AuthStatus = z.infer<typeof AuthStatusSchema>;
1899
+
1900
+ /** 凭证哈希单源(T202608310001):密码 scrypt / Token sha256 / 会话 id 随机——全部 Node 内置 crypto,零新依赖 */
1901
+ declare const AUTH_COLLECTIONS: {
1902
+ readonly accounts: "auth_accounts";
1903
+ readonly tokens: "auth_tokens";
1904
+ readonly sessions: "auth_sessions";
1905
+ };
1906
+ declare function createAuthAccountRepo(db: Db): {
1907
+ getAccount(): Promise<AuthAccount | null>;
1908
+ /** 创建唯一管理员账号:已有账号 → 409(并发初始化仅首个成功,PRD §3.2)。
1909
+ * 单例机制 = 固定 _id 插入(E11000 兜底任意并发形态——异名并发同样仅首个成功) */
1910
+ createAccount(username: string, passwordHash: string): Promise<AuthAccount>;
1911
+ updatePassword(accountId: string, newPasswordHash: string): Promise<AuthAccount | null>;
1912
+ list(filter?: mongodb.Filter<mongodb.Document>): Promise<{
1913
+ username: string;
1914
+ passwordHash: string;
1915
+ id?: string | undefined;
1916
+ createdAt?: Date | undefined;
1917
+ updatedAt?: Date | undefined;
1918
+ }[]>;
1919
+ getById(id: string): Promise<{
1920
+ username: string;
1921
+ passwordHash: string;
1922
+ id?: string | undefined;
1923
+ createdAt?: Date | undefined;
1924
+ updatedAt?: Date | undefined;
1925
+ } | null>;
1926
+ getByName(name: string): Promise<{
1927
+ username: string;
1928
+ passwordHash: string;
1929
+ id?: string | undefined;
1930
+ createdAt?: Date | undefined;
1931
+ updatedAt?: Date | undefined;
1932
+ } | null>;
1933
+ create(data: OmitId<{
1934
+ username: string;
1935
+ passwordHash: string;
1936
+ id?: string | undefined;
1937
+ createdAt?: Date | undefined;
1938
+ updatedAt?: Date | undefined;
1939
+ }>): Promise<{
1940
+ username: string;
1941
+ passwordHash: string;
1942
+ id?: string | undefined;
1943
+ createdAt?: Date | undefined;
1944
+ updatedAt?: Date | undefined;
1945
+ }>;
1946
+ update(id: string, patch: EoptPartial<OmitId<{
1947
+ username: string;
1948
+ passwordHash: string;
1949
+ id?: string | undefined;
1950
+ createdAt?: Date | undefined;
1951
+ updatedAt?: Date | undefined;
1952
+ }>>): Promise<{
1953
+ username: string;
1954
+ passwordHash: string;
1955
+ id?: string | undefined;
1956
+ createdAt?: Date | undefined;
1957
+ updatedAt?: Date | undefined;
1958
+ } | null>;
1959
+ delete(id: string): Promise<boolean>;
1960
+ _collection: mongodb.Collection<mongodb.Document>;
1961
+ };
1962
+ declare function createAuthTokenRepo(db: Db): {
1963
+ /** sha256(token 全串含前缀) 等值查询(唯一索引命中) */
1964
+ findByHash(tokenHash: string): Promise<AuthToken | null>;
1965
+ getTokenStatus(type: AuthTokenType, projectId?: string): Promise<{
1966
+ hasToken: boolean;
1967
+ createdAt: Date | null;
1968
+ }>;
1969
+ /** 重置语义:旧 Token 删除 + 新 Token 落库(重置后旧值立即失效,PRD §3.4)。
1970
+ * 事务包删+插(rs0 支持——失败窗口不留零 Token 状态,失败不变性);admin 单例 /
1971
+ * project 每项目一枚由 partial unique 索引兜底并发交错 */
1972
+ upsertToken(type: AuthTokenType, tokenHash: string, projectId?: string): Promise<AuthToken>;
1973
+ listProjectTokenStatuses(projectIds: string[]): Promise<Map<string, {
1974
+ hasToken: boolean;
1975
+ createdAt: Date | null;
1976
+ }>>;
1977
+ list(filter?: mongodb.Filter<mongodb.Document>): Promise<{
1978
+ tokenHash: string;
1979
+ type: "project" | "admin";
1980
+ id?: string | undefined;
1981
+ projectId?: string | undefined;
1982
+ createdAt?: Date | undefined;
1983
+ updatedAt?: Date | undefined;
1984
+ }[]>;
1985
+ getById(id: string): Promise<{
1986
+ tokenHash: string;
1987
+ type: "project" | "admin";
1988
+ id?: string | undefined;
1989
+ projectId?: string | undefined;
1990
+ createdAt?: Date | undefined;
1991
+ updatedAt?: Date | undefined;
1992
+ } | null>;
1993
+ getByName(name: string): Promise<{
1994
+ tokenHash: string;
1995
+ type: "project" | "admin";
1996
+ id?: string | undefined;
1997
+ projectId?: string | undefined;
1998
+ createdAt?: Date | undefined;
1999
+ updatedAt?: Date | undefined;
2000
+ } | null>;
2001
+ create(data: OmitId<{
2002
+ tokenHash: string;
2003
+ type: "project" | "admin";
2004
+ id?: string | undefined;
2005
+ projectId?: string | undefined;
2006
+ createdAt?: Date | undefined;
2007
+ updatedAt?: Date | undefined;
2008
+ }>): Promise<{
2009
+ tokenHash: string;
2010
+ type: "project" | "admin";
2011
+ id?: string | undefined;
2012
+ projectId?: string | undefined;
2013
+ createdAt?: Date | undefined;
2014
+ updatedAt?: Date | undefined;
2015
+ }>;
2016
+ update(id: string, patch: EoptPartial<OmitId<{
2017
+ tokenHash: string;
2018
+ type: "project" | "admin";
2019
+ id?: string | undefined;
2020
+ projectId?: string | undefined;
2021
+ createdAt?: Date | undefined;
2022
+ updatedAt?: Date | undefined;
2023
+ }>>): Promise<{
2024
+ tokenHash: string;
2025
+ type: "project" | "admin";
2026
+ id?: string | undefined;
2027
+ projectId?: string | undefined;
2028
+ createdAt?: Date | undefined;
2029
+ updatedAt?: Date | undefined;
2030
+ } | null>;
2031
+ delete(id: string): Promise<boolean>;
2032
+ _collection: mongodb.Collection<mongodb.Document>;
2033
+ };
2034
+ /** 会话实体(Zod 单源——core DTO 约定;TTL 清理 + 查询二次有效期判定) */
2035
+ declare const AuthSessionSchema: z.ZodObject<{
2036
+ id: z.ZodOptional<z.ZodString>;
2037
+ sessionId: z.ZodString;
2038
+ accountId: z.ZodString;
2039
+ expiresAt: z.ZodDate;
2040
+ createdAt: z.ZodOptional<z.ZodDate>;
2041
+ updatedAt: z.ZodOptional<z.ZodDate>;
2042
+ }, z.core.$strip>;
2043
+ type AuthSession = z.infer<typeof AuthSessionSchema>;
2044
+ declare function createAuthSessionRepo(db: Db): {
2045
+ createSession(sessionId: string, accountId: string, expiresAt: Date): Promise<AuthSession>;
2046
+ /** 有效期判定内联:过期即删返回 null(不等 TTL 清理) */
2047
+ findValidSession(sessionId: string): Promise<AuthSession | null>;
2048
+ deleteBySessionId(sessionId: string): Promise<boolean>;
2049
+ /** 启动时清扫过期会话(幂等,配合 TTL 索引) */
2050
+ deleteExpiredSessions(): Promise<number>;
2051
+ list(filter?: mongodb.Filter<mongodb.Document>): Promise<{
2052
+ sessionId: string;
2053
+ accountId: string;
2054
+ expiresAt: Date;
2055
+ id?: string | undefined;
2056
+ createdAt?: Date | undefined;
2057
+ updatedAt?: Date | undefined;
2058
+ }[]>;
2059
+ getById(id: string): Promise<{
2060
+ sessionId: string;
2061
+ accountId: string;
2062
+ expiresAt: Date;
2063
+ id?: string | undefined;
2064
+ createdAt?: Date | undefined;
2065
+ updatedAt?: Date | undefined;
2066
+ } | null>;
2067
+ getByName(name: string): Promise<{
2068
+ sessionId: string;
2069
+ accountId: string;
2070
+ expiresAt: Date;
2071
+ id?: string | undefined;
2072
+ createdAt?: Date | undefined;
2073
+ updatedAt?: Date | undefined;
2074
+ } | null>;
2075
+ create(data: OmitId<{
2076
+ sessionId: string;
2077
+ accountId: string;
2078
+ expiresAt: Date;
2079
+ id?: string | undefined;
2080
+ createdAt?: Date | undefined;
2081
+ updatedAt?: Date | undefined;
2082
+ }>): Promise<{
2083
+ sessionId: string;
2084
+ accountId: string;
2085
+ expiresAt: Date;
2086
+ id?: string | undefined;
2087
+ createdAt?: Date | undefined;
2088
+ updatedAt?: Date | undefined;
2089
+ }>;
2090
+ update(id: string, patch: EoptPartial<OmitId<{
2091
+ sessionId: string;
2092
+ accountId: string;
2093
+ expiresAt: Date;
2094
+ id?: string | undefined;
2095
+ createdAt?: Date | undefined;
2096
+ updatedAt?: Date | undefined;
2097
+ }>>): Promise<{
2098
+ sessionId: string;
2099
+ accountId: string;
2100
+ expiresAt: Date;
2101
+ id?: string | undefined;
2102
+ createdAt?: Date | undefined;
2103
+ updatedAt?: Date | undefined;
2104
+ } | null>;
2105
+ delete(id: string): Promise<boolean>;
2106
+ _collection: mongodb.Collection<mongodb.Document>;
2107
+ };
2108
+
2109
+ /** 密码哈希存储形态:scrypt$N$r$p$salt$hash(参数内联,升参时存量哈希可校验迁移) */
2110
+ declare function hashPassword(password: string): Promise<string>;
2111
+ /** 密码校验(timingSafeEqual 防时序攻击;格式不符返回 false 不抛错) */
2112
+ declare function verifyPassword(password: string, stored: string): Promise<boolean>;
2113
+ /** Token 明文生成:前缀 + base64url(randomBytes(32))(43 字符 URL-safe,D3) */
2114
+ declare function generateToken(type: 'admin' | 'project'): string;
2115
+ /** Token 前缀合法性与类型提取(非前缀形态 = 格式非法) */
2116
+ declare function tokenTypeFromValue(token: string): AuthTokenKind | null;
2117
+ type AuthTokenKind = 'admin' | 'project';
2118
+ /** Token sha256 hex(哈希对象含前缀全串,D2) */
2119
+ declare function hashToken(token: string): string;
2120
+ /** 会话 id:256bit 随机 hex(D4) */
2121
+ declare function generateSessionId(): string;
2122
+
2123
+ /**
2124
+ * 引用文档 Schema(T202608270002:skill/agent 资产多文件支持)
2125
+ * 引用文档 = 资产主文档之外的附加文档集合,以相对路径标识、内嵌实体存储;
2126
+ * install 时按 path 相对资产根落盘(录入/存储/安装三环节同值,Q2 裁定:目录深度保真不限制)。
2127
+ */
2128
+ /**
2129
+ * 引用文档规模上限(PRD §7 Q1 用户裁定:宽松上限兜底,正常使用无感知,超限明确报错)。
2130
+ * 数学依据:maxTotalChars=3M 字符在 UTF-8 最坏 4 字节/字符下约 12MB,
2131
+ * 含字段名与元数据余量仍低于 MongoDB 16MB 单文档上限——分项全合法但聚合超标的 payload
2132
+ * 在应用层 422 拒绝,杜绝驱动层 BSONObjectTooLarge 落入 500 兜底。
2133
+ */
2134
+ declare const REFERENCE_LIMITS: {
2135
+ /** 单资产引用文档数量上限 */
2136
+ readonly maxCount: 20;
2137
+ /** 单引用文档内容字符数上限 */
2138
+ readonly maxContentChars: 1000000;
2139
+ /** 聚合护栏:主文档正文 + Σ引用文档内容的字符总量上限 */
2140
+ readonly maxTotalChars: 3000000;
2141
+ };
2142
+ /** skill 资产主文档文件名(install 落盘名与 path 校验共用同源,install writer 经此引用) */
2143
+ declare const SKILL_MAIN_DOC = "SKILL.md";
2144
+ /** agent 资产主文档文件名 */
2145
+ declare const AGENT_MAIN_DOC = "agent.md";
2146
+ type ReferenceDoc = z.infer<typeof ReferenceDocBaseSchema>;
2147
+ /** 单条引用文档基础形状(路径规则矩阵由 createReferenceDocSchema 按资产类型挂载) */
2148
+ declare const ReferenceDocBaseSchema: z.ZodObject<{
2149
+ path: z.ZodString;
2150
+ content: z.ZodString;
2151
+ }, z.core.$strip>;
2152
+ /**
2153
+ * 比对用规范化:去除 '.' 冗余段并统一小写。
2154
+ * 小写化使冲突判定按大小写不敏感执行——.agents 落盘目标含大小写不敏感文件系统(macOS 默认),
2155
+ * 大小写不敏感判重在该类系统上防真实覆盖冲突,在大小写敏感系统上只是额外保守。
2156
+ * 存储侧保留原始 path 不做改写(录入/存储/安装三环节同值)。
2157
+ *
2158
+ * ⚠️ 行为镜像防护:web 编辑器新增区有本地预检镜像副本(packages/web/src/components/common/
2159
+ * ReferencesEditor.tsx canonicalRefPath + validateNewRefPath)——本函数规则变更须同步该处。
2160
+ */
2161
+ declare function canonicalizeReferencePath(path: string): string;
2162
+ /** 聚合字符数:Σ引用文档 content 长度(undefined 安全,供实体级聚合上限 refine 使用) */
2163
+ declare function sumReferenceContentChars(references: ReadonlyArray<{
2164
+ content: string;
2165
+ }> | undefined): number;
2166
+ /**
2167
+ * 构造某资产类型的引用文档数组 schema。
2168
+ * 元素级:路径规则矩阵(禁绝对路径/反斜杠/空段/../主文档名冲突,中文错误带 path 值)。
2169
+ * 数组级:数量上限 + 规范化后判重 + 目录前缀冲突(`a` 与 `a/b.md` 并存会导致落盘文件/目录同名冲突)。
2170
+ * 元素与数组的 refine 位于本 schema 内部,随实体 shape 进入派生链后不受外层 .partial() 影响(运行时探针验证过)。
2171
+ */
2172
+ declare function createReferencesSchema(mainDocName: string): z.ZodArray<z.ZodObject<{
2173
+ path: z.ZodString;
2174
+ content: z.ZodString;
2175
+ }, z.core.$strip>>;
2176
+ /**
2177
+ * 引用文档删除保护(T202608270002 PRD 场景 C 边界规则):PUT 整笔替换时,
2178
+ * 被移除的引用文档 path 若仍以文本形式出现在本次提交后的主文档正文中 → 409 REFERENCE_IN_USE。
2179
+ * 两态语义:nextReferences=undefined 表示本次不修改 references(直接放行);
2180
+ * 主文档正文缺省时以现值正文参与判定(仅更新 references 的部分提交场景)。
2181
+ * 校验失败抛 ConflictError(skill/agent 路由共用同一规则,四面通道经 server schema 天然一致)。
2182
+ */
2183
+ declare function assertReferencesDeletable(params: {
2184
+ resource: 'skill' | 'agent';
2185
+ name: string;
2186
+ /** 库内现值 references(缺失 = 无引用文档可删) */
2187
+ existingReferences: ReadonlyArray<{
2188
+ path: string;
2189
+ }> | undefined;
2190
+ /** 本次提交的 references;undefined = 不修改该字段 */
2191
+ nextReferences: ReadonlyArray<{
2192
+ path: string;
2193
+ }> | undefined;
2194
+ /** 本次提交的主文档正文;undefined = 用现值判定 */
2195
+ nextMainBody: string | undefined;
2196
+ /** 库内现值主文档正文 */
2197
+ currentMainBody: string;
2198
+ }): void;
2199
+ /**
2200
+ * 引用文档聚合上限复核(server 路由层 PUT 专用):schema 级聚合校验只覆盖单次 payload——
2201
+ * 仅携带 references 的部分提交以现值主文档正文参与判定,堵住「分步提交绕过护栏」的通道
2202
+ * (先 PUT 大主文档、再 PUT 仅大 references 的两步合计可超 BSON 文档安全余量)。
2203
+ * nextMainBody 由调用方给出有效正文(payload 携带用 payload 值,未携带用库内现值)。
2204
+ * 超限抛 ValidationError(422)。
2205
+ */
2206
+ declare function assertReferenceAggregateLimit(params: {
2207
+ /** 有效主文档正文:本次提交携带则为其值,否则为库内现值 */
2208
+ effectiveMainBody: string;
2209
+ /** 本次提交的 references;undefined = 不修改该字段,跳过校验 */
2210
+ nextReferences: ReadonlyArray<{
2211
+ content: string;
2212
+ }> | undefined;
2213
+ }): void;
2214
+
2215
+ /**
2216
+ * 模板导入/导出 bundle 契约(T202608300002)
2217
+ *
2218
+ * 导出产物与导入请求的 `bundle` 字段共用同一 schema(单一真相源)。
2219
+ * Payload 全部从 Shape 层(纯 object schema)omit 派生——refined 全量 schema 上调
2220
+ * 对象级方法(.pick()/.omit() 后的 .partial() 同理)存在 Zod4 运行时陷阱,typecheck
2221
+ * 绿不算数;实体 schema 演进(新增内容字段)自动跟随进 payload。
2222
+ *
2223
+ * 剥离原则(PRD F4/F16):id / projectId / enabled / createdAt / updatedAt 不入 bundle——
2224
+ * projectId 由导入时的 targetProjectId 决定归属;enabled 属环境运营状态不迁移。
2225
+ */
2226
+ /** 当前导出格式版本(前向兼容锚点:升级格式时递增并处理旧版兼容) */
2227
+ declare const EXPORT_FORMAT_VERSION = "1.0";
2228
+ /** 模板内容投影:剥 id/projectId/enabled/时间戳/code;version/isDefault 剥 default 强制显式携带。
2229
+ * T202609020002:code 不入 bundle——code 项目内唯一且不可变,跨环境携带会在同名覆盖时违反不可变
2230
+ * (导入新建按目标项目自动生成,覆盖保留现值;跨环境稳定引用键是后续节点资产 code 的语义)。 */
2231
+ declare const TemplatePayloadSchema: z.ZodObject<{
2232
+ name: z.ZodString;
2233
+ description: z.ZodString;
2234
+ nodes: z.ZodArray<z.ZodObject<{
2235
+ id: z.ZodString;
2236
+ label: z.ZodString;
2237
+ phase: z.ZodString;
2238
+ track: z.ZodString;
2239
+ prompt: z.ZodString;
2240
+ skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
2241
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
2242
+ sourcePreset: z.ZodOptional<z.ZodObject<{
2243
+ code: z.ZodString;
2244
+ version: z.ZodString;
2245
+ contentHash: z.ZodString;
2246
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
2247
+ }, z.core.$strip>>;
2248
+ }, z.core.$strip>>;
2249
+ edges: z.ZodArray<z.ZodObject<{
2250
+ from: z.ZodString;
2251
+ to: z.ZodString;
2252
+ condition: z.ZodOptional<z.ZodString>;
2253
+ pausePoint: z.ZodOptional<z.ZodObject<{
2254
+ type: z.ZodEnum<{
2255
+ human_approval: "human_approval";
2256
+ checkpoint: "checkpoint";
2257
+ }>;
2258
+ description: z.ZodString;
2259
+ autoResume: z.ZodDefault<z.ZodBoolean>;
2260
+ }, z.core.$strip>>;
2261
+ }, z.core.$strip>>;
2262
+ layout: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
2263
+ x: z.ZodNumber;
2264
+ y: z.ZodNumber;
2265
+ }, z.core.$strip>>>;
2266
+ version: z.ZodString;
2267
+ isDefault: z.ZodBoolean;
2268
+ }, z.core.$strip>;
2269
+ type TemplatePayload = z.infer<typeof TemplatePayloadSchema>;
2270
+ /**
2271
+ * SKILL 内容投影:references 改必填数组(无引用文档的资产表达为 []——
2272
+ * 整笔替换语义无歧义,缺省键与「清空引用」不可区分是两态语义的坑);
2273
+ * scope/version 剥 default 强制显式携带。
2274
+ */
2275
+ declare const SkillPayloadSchema: z.ZodObject<{
2276
+ content: z.ZodString;
2277
+ name: z.ZodString;
2278
+ description: z.ZodString;
2279
+ category: z.ZodString;
2280
+ version: z.ZodString;
2281
+ scope: z.ZodEnum<{
2282
+ global: "global";
2283
+ project: "project";
2284
+ }>;
2285
+ references: z.ZodArray<z.ZodObject<{
2286
+ path: z.ZodString;
2287
+ content: z.ZodString;
2288
+ }, z.core.$strip>>;
2289
+ }, z.core.$strip>;
2290
+ type SkillPayload = z.infer<typeof SkillPayloadSchema>;
2291
+ /** AGENT 内容投影:同 SkillPayload 原则,另剥 boundSkills/tools/permissions/function 的 default */
2292
+ declare const AgentPayloadSchema: z.ZodObject<{
2293
+ name: z.ZodString;
2294
+ description: z.ZodString;
2295
+ systemPrompt: z.ZodString;
2296
+ model: z.ZodString;
2297
+ version: z.ZodString;
2298
+ scope: z.ZodEnum<{
2299
+ global: "global";
2300
+ project: "project";
2301
+ }>;
2302
+ references: z.ZodArray<z.ZodObject<{
2303
+ path: z.ZodString;
2304
+ content: z.ZodString;
2305
+ }, z.core.$strip>>;
2306
+ boundSkills: z.ZodArray<z.ZodString>;
2307
+ tools: z.ZodArray<z.ZodString>;
2308
+ permissions: z.ZodArray<z.ZodString>;
2309
+ function: z.ZodEnum<{
2310
+ reviewer: "reviewer";
2311
+ executor: "executor";
2312
+ }>;
2313
+ }, z.core.$strip>;
2314
+ type AgentPayload = z.infer<typeof AgentPayloadSchema>;
2315
+ /** 模型映射内容投影(无 scope/enabled 概念,仅剥 id/时间戳) */
2316
+ declare const ModelAliasPayloadSchema: z.ZodObject<{
2317
+ name: z.ZodString;
2318
+ code: z.ZodString;
2319
+ realModel: z.ZodString;
2320
+ }, z.core.$strip>;
2321
+ type ModelAliasPayload = z.infer<typeof ModelAliasPayloadSchema>;
2322
+ /**
2323
+ * 导出 bundle。exportFormatVersion 用 literal + 定制 error——`z.literal` 对非匹配值
2324
+ * parse 即失败 short-circuit,外挂 superRefine 不会执行,message 必须经 error 参数内联
2325
+ * (PRD 验收 14:错误信息明确提示版本不支持)。
2326
+ */
2327
+ declare const ExportBundleSchema: z.ZodObject<{
2328
+ exportFormatVersion: z.ZodLiteral<"1.0">;
2329
+ exportedAt: z.ZodString;
2330
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
2331
+ template: z.ZodObject<{
2332
+ name: z.ZodString;
2333
+ description: z.ZodString;
2334
+ nodes: z.ZodArray<z.ZodObject<{
2335
+ id: z.ZodString;
2336
+ label: z.ZodString;
2337
+ phase: z.ZodString;
2338
+ track: z.ZodString;
2339
+ prompt: z.ZodString;
2340
+ skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
2341
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
2342
+ sourcePreset: z.ZodOptional<z.ZodObject<{
2343
+ code: z.ZodString;
2344
+ version: z.ZodString;
2345
+ contentHash: z.ZodString;
2346
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
2347
+ }, z.core.$strip>>;
2348
+ }, z.core.$strip>>;
2349
+ edges: z.ZodArray<z.ZodObject<{
2350
+ from: z.ZodString;
2351
+ to: z.ZodString;
2352
+ condition: z.ZodOptional<z.ZodString>;
2353
+ pausePoint: z.ZodOptional<z.ZodObject<{
2354
+ type: z.ZodEnum<{
2355
+ human_approval: "human_approval";
2356
+ checkpoint: "checkpoint";
2357
+ }>;
2358
+ description: z.ZodString;
2359
+ autoResume: z.ZodDefault<z.ZodBoolean>;
2360
+ }, z.core.$strip>>;
2361
+ }, z.core.$strip>>;
2362
+ layout: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
2363
+ x: z.ZodNumber;
2364
+ y: z.ZodNumber;
2365
+ }, z.core.$strip>>>;
2366
+ version: z.ZodString;
2367
+ isDefault: z.ZodBoolean;
2368
+ }, z.core.$strip>;
2369
+ dependencies: z.ZodObject<{
2370
+ skills: z.ZodArray<z.ZodObject<{
2371
+ content: z.ZodString;
2372
+ name: z.ZodString;
2373
+ description: z.ZodString;
2374
+ category: z.ZodString;
2375
+ version: z.ZodString;
2376
+ scope: z.ZodEnum<{
2377
+ global: "global";
2378
+ project: "project";
2379
+ }>;
2380
+ references: z.ZodArray<z.ZodObject<{
2381
+ path: z.ZodString;
2382
+ content: z.ZodString;
2383
+ }, z.core.$strip>>;
2384
+ }, z.core.$strip>>;
2385
+ agents: z.ZodArray<z.ZodObject<{
2386
+ name: z.ZodString;
2387
+ description: z.ZodString;
2388
+ systemPrompt: z.ZodString;
2389
+ model: z.ZodString;
2390
+ version: z.ZodString;
2391
+ scope: z.ZodEnum<{
2392
+ global: "global";
2393
+ project: "project";
2394
+ }>;
2395
+ references: z.ZodArray<z.ZodObject<{
2396
+ path: z.ZodString;
2397
+ content: z.ZodString;
2398
+ }, z.core.$strip>>;
2399
+ boundSkills: z.ZodArray<z.ZodString>;
2400
+ tools: z.ZodArray<z.ZodString>;
2401
+ permissions: z.ZodArray<z.ZodString>;
2402
+ function: z.ZodEnum<{
2403
+ reviewer: "reviewer";
2404
+ executor: "executor";
2405
+ }>;
2406
+ }, z.core.$strip>>;
2407
+ modelAliases: z.ZodArray<z.ZodObject<{
2408
+ name: z.ZodString;
2409
+ code: z.ZodString;
2410
+ realModel: z.ZodString;
2411
+ }, z.core.$strip>>;
2412
+ }, z.core.$strip>;
2413
+ }, z.core.$strip>;
2414
+ type ExportBundle = z.infer<typeof ExportBundleSchema>;
2415
+ declare const ImportPlanRequestSchema: z.ZodObject<{
2416
+ targetProjectId: z.ZodString;
2417
+ bundle: z.ZodObject<{
2418
+ exportFormatVersion: z.ZodLiteral<"1.0">;
2419
+ exportedAt: z.ZodString;
2420
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
2421
+ template: z.ZodObject<{
2422
+ name: z.ZodString;
2423
+ description: z.ZodString;
2424
+ nodes: z.ZodArray<z.ZodObject<{
2425
+ id: z.ZodString;
2426
+ label: z.ZodString;
2427
+ phase: z.ZodString;
2428
+ track: z.ZodString;
2429
+ prompt: z.ZodString;
2430
+ skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
2431
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
2432
+ sourcePreset: z.ZodOptional<z.ZodObject<{
2433
+ code: z.ZodString;
2434
+ version: z.ZodString;
2435
+ contentHash: z.ZodString;
2436
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
2437
+ }, z.core.$strip>>;
2438
+ }, z.core.$strip>>;
2439
+ edges: z.ZodArray<z.ZodObject<{
2440
+ from: z.ZodString;
2441
+ to: z.ZodString;
2442
+ condition: z.ZodOptional<z.ZodString>;
2443
+ pausePoint: z.ZodOptional<z.ZodObject<{
2444
+ type: z.ZodEnum<{
2445
+ human_approval: "human_approval";
2446
+ checkpoint: "checkpoint";
2447
+ }>;
2448
+ description: z.ZodString;
2449
+ autoResume: z.ZodDefault<z.ZodBoolean>;
2450
+ }, z.core.$strip>>;
2451
+ }, z.core.$strip>>;
2452
+ layout: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
2453
+ x: z.ZodNumber;
2454
+ y: z.ZodNumber;
2455
+ }, z.core.$strip>>>;
2456
+ version: z.ZodString;
2457
+ isDefault: z.ZodBoolean;
2458
+ }, z.core.$strip>;
2459
+ dependencies: z.ZodObject<{
2460
+ skills: z.ZodArray<z.ZodObject<{
2461
+ content: z.ZodString;
2462
+ name: z.ZodString;
2463
+ description: z.ZodString;
2464
+ category: z.ZodString;
2465
+ version: z.ZodString;
2466
+ scope: z.ZodEnum<{
2467
+ global: "global";
2468
+ project: "project";
2469
+ }>;
2470
+ references: z.ZodArray<z.ZodObject<{
2471
+ path: z.ZodString;
2472
+ content: z.ZodString;
2473
+ }, z.core.$strip>>;
2474
+ }, z.core.$strip>>;
2475
+ agents: z.ZodArray<z.ZodObject<{
2476
+ name: z.ZodString;
2477
+ description: z.ZodString;
2478
+ systemPrompt: z.ZodString;
2479
+ model: z.ZodString;
2480
+ version: z.ZodString;
2481
+ scope: z.ZodEnum<{
2482
+ global: "global";
2483
+ project: "project";
2484
+ }>;
2485
+ references: z.ZodArray<z.ZodObject<{
2486
+ path: z.ZodString;
2487
+ content: z.ZodString;
2488
+ }, z.core.$strip>>;
2489
+ boundSkills: z.ZodArray<z.ZodString>;
2490
+ tools: z.ZodArray<z.ZodString>;
2491
+ permissions: z.ZodArray<z.ZodString>;
2492
+ function: z.ZodEnum<{
2493
+ reviewer: "reviewer";
2494
+ executor: "executor";
2495
+ }>;
2496
+ }, z.core.$strip>>;
2497
+ modelAliases: z.ZodArray<z.ZodObject<{
2498
+ name: z.ZodString;
2499
+ code: z.ZodString;
2500
+ realModel: z.ZodString;
2501
+ }, z.core.$strip>>;
2502
+ }, z.core.$strip>;
2503
+ }, z.core.$strip>;
2504
+ }, z.core.$strip>;
2505
+ type ImportPlanRequest = z.infer<typeof ImportPlanRequestSchema>;
2506
+ /** 依赖冲突决策向量(discriminated union:skill/agent 必填 scope 消歧同名双 scope 并存;modelAlias 无 scope) */
2507
+ declare const ImportDecisionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
2508
+ kind: z.ZodLiteral<"skill">;
2509
+ name: z.ZodString;
2510
+ scope: z.ZodEnum<{
2511
+ global: "global";
2512
+ project: "project";
2513
+ }>;
2514
+ action: z.ZodEnum<{
2515
+ skip: "skip";
2516
+ overwrite: "overwrite";
2517
+ }>;
2518
+ }, z.core.$strip>, z.ZodObject<{
2519
+ kind: z.ZodLiteral<"agent">;
2520
+ name: z.ZodString;
2521
+ scope: z.ZodEnum<{
2522
+ global: "global";
2523
+ project: "project";
2524
+ }>;
2525
+ action: z.ZodEnum<{
2526
+ skip: "skip";
2527
+ overwrite: "overwrite";
2528
+ }>;
2529
+ }, z.core.$strip>, z.ZodObject<{
2530
+ kind: z.ZodLiteral<"modelAlias">;
2531
+ name: z.ZodString;
2532
+ action: z.ZodEnum<{
2533
+ skip: "skip";
2534
+ overwrite: "overwrite";
2535
+ }>;
2536
+ }, z.core.$strip>], "kind">;
2537
+ type ImportDecision = z.infer<typeof ImportDecisionSchema>;
2538
+ declare const ImportApplyRequestSchema: z.ZodObject<{
2539
+ targetProjectId: z.ZodString;
2540
+ bundle: z.ZodObject<{
2541
+ exportFormatVersion: z.ZodLiteral<"1.0">;
2542
+ exportedAt: z.ZodString;
2543
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
2544
+ template: z.ZodObject<{
2545
+ name: z.ZodString;
2546
+ description: z.ZodString;
2547
+ nodes: z.ZodArray<z.ZodObject<{
2548
+ id: z.ZodString;
2549
+ label: z.ZodString;
2550
+ phase: z.ZodString;
2551
+ track: z.ZodString;
2552
+ prompt: z.ZodString;
2553
+ skills: z.ZodDefault<z.ZodArray<z.ZodString>>;
2554
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
2555
+ sourcePreset: z.ZodOptional<z.ZodObject<{
2556
+ code: z.ZodString;
2557
+ version: z.ZodString;
2558
+ contentHash: z.ZodString;
2559
+ agents: z.ZodOptional<z.ZodArray<z.ZodString>>;
2560
+ }, z.core.$strip>>;
2561
+ }, z.core.$strip>>;
2562
+ edges: z.ZodArray<z.ZodObject<{
2563
+ from: z.ZodString;
2564
+ to: z.ZodString;
2565
+ condition: z.ZodOptional<z.ZodString>;
2566
+ pausePoint: z.ZodOptional<z.ZodObject<{
2567
+ type: z.ZodEnum<{
2568
+ human_approval: "human_approval";
2569
+ checkpoint: "checkpoint";
2570
+ }>;
2571
+ description: z.ZodString;
2572
+ autoResume: z.ZodDefault<z.ZodBoolean>;
2573
+ }, z.core.$strip>>;
2574
+ }, z.core.$strip>>;
2575
+ layout: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
2576
+ x: z.ZodNumber;
2577
+ y: z.ZodNumber;
2578
+ }, z.core.$strip>>>;
2579
+ version: z.ZodString;
2580
+ isDefault: z.ZodBoolean;
2581
+ }, z.core.$strip>;
2582
+ dependencies: z.ZodObject<{
2583
+ skills: z.ZodArray<z.ZodObject<{
2584
+ content: z.ZodString;
2585
+ name: z.ZodString;
2586
+ description: z.ZodString;
2587
+ category: z.ZodString;
2588
+ version: z.ZodString;
2589
+ scope: z.ZodEnum<{
2590
+ global: "global";
2591
+ project: "project";
2592
+ }>;
2593
+ references: z.ZodArray<z.ZodObject<{
2594
+ path: z.ZodString;
2595
+ content: z.ZodString;
2596
+ }, z.core.$strip>>;
2597
+ }, z.core.$strip>>;
2598
+ agents: z.ZodArray<z.ZodObject<{
2599
+ name: z.ZodString;
2600
+ description: z.ZodString;
2601
+ systemPrompt: z.ZodString;
2602
+ model: z.ZodString;
2603
+ version: z.ZodString;
2604
+ scope: z.ZodEnum<{
2605
+ global: "global";
2606
+ project: "project";
2607
+ }>;
2608
+ references: z.ZodArray<z.ZodObject<{
2609
+ path: z.ZodString;
2610
+ content: z.ZodString;
2611
+ }, z.core.$strip>>;
2612
+ boundSkills: z.ZodArray<z.ZodString>;
2613
+ tools: z.ZodArray<z.ZodString>;
2614
+ permissions: z.ZodArray<z.ZodString>;
2615
+ function: z.ZodEnum<{
2616
+ reviewer: "reviewer";
2617
+ executor: "executor";
2618
+ }>;
2619
+ }, z.core.$strip>>;
2620
+ modelAliases: z.ZodArray<z.ZodObject<{
2621
+ name: z.ZodString;
2622
+ code: z.ZodString;
2623
+ realModel: z.ZodString;
2624
+ }, z.core.$strip>>;
2625
+ }, z.core.$strip>;
2626
+ }, z.core.$strip>;
2627
+ decisions: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
2628
+ kind: z.ZodLiteral<"skill">;
2629
+ name: z.ZodString;
2630
+ scope: z.ZodEnum<{
2631
+ global: "global";
2632
+ project: "project";
2633
+ }>;
2634
+ action: z.ZodEnum<{
2635
+ skip: "skip";
2636
+ overwrite: "overwrite";
2637
+ }>;
2638
+ }, z.core.$strip>, z.ZodObject<{
2639
+ kind: z.ZodLiteral<"agent">;
2640
+ name: z.ZodString;
2641
+ scope: z.ZodEnum<{
2642
+ global: "global";
2643
+ project: "project";
2644
+ }>;
2645
+ action: z.ZodEnum<{
2646
+ skip: "skip";
2647
+ overwrite: "overwrite";
2648
+ }>;
2649
+ }, z.core.$strip>, z.ZodObject<{
2650
+ kind: z.ZodLiteral<"modelAlias">;
2651
+ name: z.ZodString;
2652
+ action: z.ZodEnum<{
2653
+ skip: "skip";
2654
+ overwrite: "overwrite";
2655
+ }>;
2656
+ }, z.core.$strip>], "kind">>>;
2657
+ }, z.core.$strip>;
2658
+ type ImportApplyRequest = z.infer<typeof ImportApplyRequestSchema>;
2659
+ declare const DependencyStatusSchema: z.ZodEnum<{
2660
+ conflict: "conflict";
2661
+ create: "create";
2662
+ identical: "identical";
2663
+ }>;
2664
+ type DependencyStatus = z.infer<typeof DependencyStatusSchema>;
2665
+ declare const DependencyCheckSchema: z.ZodObject<{
2666
+ kind: z.ZodEnum<{
2667
+ skill: "skill";
2668
+ agent: "agent";
2669
+ modelAlias: "modelAlias";
2670
+ }>;
2671
+ name: z.ZodString;
2672
+ scope: z.ZodOptional<z.ZodEnum<{
2673
+ global: "global";
2674
+ project: "project";
2675
+ }>>;
2676
+ status: z.ZodEnum<{
2677
+ conflict: "conflict";
2678
+ create: "create";
2679
+ identical: "identical";
2680
+ }>;
2681
+ currentVersion: z.ZodOptional<z.ZodString>;
2682
+ importVersion: z.ZodOptional<z.ZodString>;
2683
+ changeSummary: z.ZodOptional<z.ZodString>;
2684
+ impact: z.ZodEnum<{
2685
+ global: "global";
2686
+ project: "project";
2687
+ }>;
2688
+ }, z.core.$strip>;
2689
+ type DependencyCheck = z.infer<typeof DependencyCheckSchema>;
2690
+ declare const ImportPlanResponseSchema: z.ZodObject<{
2691
+ template: z.ZodObject<{
2692
+ name: z.ZodString;
2693
+ willOverwrite: z.ZodBoolean;
2694
+ currentVersion: z.ZodOptional<z.ZodString>;
2695
+ importVersion: z.ZodString;
2696
+ isDefaultRequested: z.ZodBoolean;
2697
+ isDefaultEffect: z.ZodBoolean;
2698
+ downgradeReason: z.ZodOptional<z.ZodString>;
2699
+ }, z.core.$strip>;
2700
+ dependencies: z.ZodArray<z.ZodObject<{
2701
+ kind: z.ZodEnum<{
2702
+ skill: "skill";
2703
+ agent: "agent";
2704
+ modelAlias: "modelAlias";
2705
+ }>;
2706
+ name: z.ZodString;
2707
+ scope: z.ZodOptional<z.ZodEnum<{
2708
+ global: "global";
2709
+ project: "project";
2710
+ }>>;
2711
+ status: z.ZodEnum<{
2712
+ conflict: "conflict";
2713
+ create: "create";
2714
+ identical: "identical";
2715
+ }>;
2716
+ currentVersion: z.ZodOptional<z.ZodString>;
2717
+ importVersion: z.ZodOptional<z.ZodString>;
2718
+ changeSummary: z.ZodOptional<z.ZodString>;
2719
+ impact: z.ZodEnum<{
2720
+ global: "global";
2721
+ project: "project";
2722
+ }>;
2723
+ }, z.core.$strip>>;
2724
+ directSkillChecks: z.ZodArray<z.ZodObject<{
2725
+ node: z.ZodString;
2726
+ skill: z.ZodString;
2727
+ status: z.ZodEnum<{
2728
+ ok: "ok";
2729
+ missing: "missing";
2730
+ }>;
2731
+ }, z.core.$strip>>;
2732
+ warnings: z.ZodArray<z.ZodString>;
2733
+ }, z.core.$strip>;
2734
+ type ImportPlanResponse = z.infer<typeof ImportPlanResponseSchema>;
2735
+ declare const DependencyActionSchema: z.ZodEnum<{
2736
+ skipped: "skipped";
2737
+ identical: "identical";
2738
+ created: "created";
2739
+ updated: "updated";
2740
+ failed: "failed";
2741
+ }>;
2742
+ type DependencyAction = z.infer<typeof DependencyActionSchema>;
2743
+ declare const ImportApplyResponseSchema: z.ZodObject<{
2744
+ template: z.ZodObject<{
2745
+ id: z.ZodString;
2746
+ name: z.ZodString;
2747
+ action: z.ZodEnum<{
2748
+ created: "created";
2749
+ updated: "updated";
2750
+ }>;
2751
+ isDefaultEffect: z.ZodBoolean;
2752
+ }, z.core.$strip>;
2753
+ dependencies: z.ZodArray<z.ZodObject<{
2754
+ kind: z.ZodEnum<{
2755
+ skill: "skill";
2756
+ agent: "agent";
2757
+ modelAlias: "modelAlias";
2758
+ }>;
2759
+ name: z.ZodString;
2760
+ scope: z.ZodOptional<z.ZodEnum<{
2761
+ global: "global";
2762
+ project: "project";
2763
+ }>>;
2764
+ action: z.ZodEnum<{
2765
+ skipped: "skipped";
2766
+ identical: "identical";
2767
+ created: "created";
2768
+ updated: "updated";
2769
+ failed: "failed";
2770
+ }>;
2771
+ message: z.ZodOptional<z.ZodString>;
2772
+ }, z.core.$strip>>;
2773
+ sourceStripped: z.ZodArray<z.ZodString>;
2774
+ }, z.core.$strip>;
2775
+ type ImportApplyResponse = z.infer<typeof ImportApplyResponseSchema>;
2776
+ /** 决策向量寻址键(skill/agent 含 scope 段,modelAlias 空段) */
2777
+ declare function decisionKey(kind: 'skill' | 'agent' | 'modelAlias', scope: 'global' | 'project' | undefined, name: string): string;
2778
+
2779
+ /**
2780
+ * Advance / Approve 相关 Schemas
2781
+ *
2782
+ * N017 D5:审批(人工决策)与推进(节点完成)拆为两个动作——
2783
+ * advance 请求体变可选 {note?}(原 gateResults 数组删除);
2784
+ * 新增独立 ApproveRequest/ApproveResponse。
2785
+ */
2786
+ /**
2787
+ * N017 F8:gate 机制退役——advance 只是"当前节点完成,按出边流转"。
2788
+ * N020 D1:轻量收尾——note 为可选历史备注;summary 为可选收尾摘要
2789
+ * (写入 nodeRecords.<node>.summary,内容主体已在执行期间小步落库)。
2790
+ */
2791
+ declare const AdvanceRequestSchema: z.ZodObject<{
2792
+ note: z.ZodOptional<z.ZodString>;
2793
+ summary: z.ZodOptional<z.ZodString>;
2794
+ }, z.core.$strip>;
2795
+ type AdvanceRequest = z.infer<typeof AdvanceRequestSchema>;
2796
+ /** 暂停点审批:approved=通过并流转;rejected=驳回保持 paused(comment 为决策说明) */
2797
+ declare const ApproveRequestSchema: z.ZodObject<{
2798
+ decision: z.ZodEnum<{
2799
+ approved: "approved";
2800
+ rejected: "rejected";
2801
+ }>;
2802
+ comment: z.ZodOptional<z.ZodString>;
2803
+ }, z.core.$strip>;
2804
+ type ApproveRequest = z.infer<typeof ApproveRequestSchema>;
2805
+ declare const TaskPublicSchema: z.ZodObject<{
2806
+ taskId: z.ZodString;
2807
+ title: z.ZodString;
2808
+ type: z.ZodOptional<z.ZodEnum<{
2809
+ feature: "feature";
2810
+ bugfix: "bugfix";
2811
+ "ui-tweak": "ui-tweak";
2812
+ research: "research";
2813
+ }>>;
2814
+ currentNode: z.ZodString;
2815
+ currentPhase: z.ZodString;
2816
+ status: z.ZodString;
2817
+ pausedAt: z.ZodNullable<z.ZodString>;
2818
+ track: z.ZodString;
2819
+ }, z.core.$strip>;
2820
+ type TaskPublic = z.infer<typeof TaskPublicSchema>;
2821
+ /** N017 F8:删 gates;upcomingPause 语义改为"完成当前节点后出边上的暂停点描述"(经 findNextEdge 按轨选边) */
2822
+ declare const NodeInfoSchema: z.ZodObject<{
2823
+ nodeId: z.ZodString;
2824
+ label: z.ZodString;
2825
+ track: z.ZodString;
2826
+ prompt: z.ZodString;
2827
+ skills: z.ZodArray<z.ZodString>;
2828
+ agents: z.ZodArray<z.ZodString>;
2829
+ upcomingPause: z.ZodNullable<z.ZodString>;
2830
+ }, z.core.$strip>;
2831
+ type NodeInfo = z.infer<typeof NodeInfoSchema>;
2832
+ /** N017 D7:删 gate_failed 分支(union 收窄为 advanced / paused / completed);paused 分支 pausePoint 类型改 EdgePausePoint */
2833
+ declare const AdvanceResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
2834
+ status: z.ZodLiteral<"advanced">;
2835
+ task: z.ZodObject<{
2836
+ taskId: z.ZodString;
2837
+ title: z.ZodString;
2838
+ type: z.ZodOptional<z.ZodEnum<{
2839
+ feature: "feature";
2840
+ bugfix: "bugfix";
2841
+ "ui-tweak": "ui-tweak";
2842
+ research: "research";
2843
+ }>>;
2844
+ currentNode: z.ZodString;
2845
+ currentPhase: z.ZodString;
2846
+ status: z.ZodString;
2847
+ pausedAt: z.ZodNullable<z.ZodString>;
2848
+ track: z.ZodString;
2849
+ }, z.core.$strip>;
2850
+ nextNode: z.ZodObject<{
2851
+ nodeId: z.ZodString;
2852
+ label: z.ZodString;
2853
+ track: z.ZodString;
2854
+ prompt: z.ZodString;
2855
+ skills: z.ZodArray<z.ZodString>;
2856
+ agents: z.ZodArray<z.ZodString>;
2857
+ upcomingPause: z.ZodNullable<z.ZodString>;
2858
+ }, z.core.$strip>;
2859
+ }, z.core.$strip>, z.ZodObject<{
2860
+ status: z.ZodLiteral<"paused">;
2861
+ task: z.ZodObject<{
2862
+ taskId: z.ZodString;
2863
+ title: z.ZodString;
2864
+ type: z.ZodOptional<z.ZodEnum<{
2865
+ feature: "feature";
2866
+ bugfix: "bugfix";
2867
+ "ui-tweak": "ui-tweak";
2868
+ research: "research";
2869
+ }>>;
2870
+ currentNode: z.ZodString;
2871
+ currentPhase: z.ZodString;
2872
+ status: z.ZodString;
2873
+ pausedAt: z.ZodNullable<z.ZodString>;
2874
+ track: z.ZodString;
2875
+ }, z.core.$strip>;
2876
+ pausePoint: z.ZodObject<{
2877
+ type: z.ZodEnum<{
2878
+ human_approval: "human_approval";
2879
+ checkpoint: "checkpoint";
2880
+ }>;
2881
+ description: z.ZodString;
2882
+ autoResume: z.ZodDefault<z.ZodBoolean>;
2883
+ }, z.core.$strip>;
2884
+ guidance: z.ZodString;
2885
+ }, z.core.$strip>, z.ZodObject<{
2886
+ status: z.ZodLiteral<"completed">;
2887
+ task: z.ZodObject<{
2888
+ taskId: z.ZodString;
2889
+ title: z.ZodString;
2890
+ type: z.ZodOptional<z.ZodEnum<{
2891
+ feature: "feature";
2892
+ bugfix: "bugfix";
2893
+ "ui-tweak": "ui-tweak";
2894
+ research: "research";
2895
+ }>>;
2896
+ currentNode: z.ZodString;
2897
+ currentPhase: z.ZodString;
2898
+ status: z.ZodString;
2899
+ pausedAt: z.ZodNullable<z.ZodString>;
2900
+ track: z.ZodString;
2901
+ }, z.core.$strip>;
2902
+ }, z.core.$strip>], "status">;
2903
+ type AdvanceResponse = z.infer<typeof AdvanceResponseSchema>;
2904
+ declare const ApproveResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
2905
+ status: z.ZodLiteral<"advanced">;
2906
+ task: z.ZodObject<{
2907
+ taskId: z.ZodString;
2908
+ title: z.ZodString;
2909
+ type: z.ZodOptional<z.ZodEnum<{
2910
+ feature: "feature";
2911
+ bugfix: "bugfix";
2912
+ "ui-tweak": "ui-tweak";
2913
+ research: "research";
2914
+ }>>;
2915
+ currentNode: z.ZodString;
2916
+ currentPhase: z.ZodString;
2917
+ status: z.ZodString;
2918
+ pausedAt: z.ZodNullable<z.ZodString>;
2919
+ track: z.ZodString;
1408
2920
  }, z.core.$strip>;
1409
2921
  nextNode: z.ZodObject<{
1410
2922
  nodeId: z.ZodString;
@@ -1412,6 +2924,7 @@ declare const ApproveResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1412
2924
  track: z.ZodString;
1413
2925
  prompt: z.ZodString;
1414
2926
  skills: z.ZodArray<z.ZodString>;
2927
+ agents: z.ZodArray<z.ZodString>;
1415
2928
  upcomingPause: z.ZodNullable<z.ZodString>;
1416
2929
  }, z.core.$strip>;
1417
2930
  }, z.core.$strip>, z.ZodObject<{
@@ -1459,6 +2972,304 @@ declare const ResumeRequestSchema: z.ZodObject<{
1459
2972
  decision: z.ZodOptional<z.ZodString>;
1460
2973
  }, z.core.$strip>;
1461
2974
  type ResumeRequest = z.infer<typeof ResumeRequestSchema>;
2975
+ /**
2976
+ * 任务取消请求体:active/paused(含暂停点等待态)可取消 → cancelled 终态(不可逆)。
2977
+ * reason 可选——仅进 history 留痕 details(对齐 pause 的 reason 惯例,不改变行为流)。
2978
+ */
2979
+ declare const CancelRequestSchema: z.ZodObject<{
2980
+ reason: z.ZodOptional<z.ZodString>;
2981
+ }, z.core.$strip>;
2982
+ type CancelRequest = z.infer<typeof CancelRequestSchema>;
2983
+
2984
+ /**
2985
+ * T202608280007 F1:写入轻量回执——任务信息结构化写端点(doc/record/archnote 域 +
2986
+ * title/pause/resume)成功响应统一形态。调研实测写响应回灌完整 Task 实体占会话注入
2987
+ * 84.8%(写入 79B 换回 12.7KB),回执只携带「写成了什么 + 新条目标识 + 生效时间 +
2988
+ * 任务进度摘要」,投影发生在 server 路由层(仓储层保持全量实体返回供预读校验/CAS)。
2989
+ */
2990
+ /** 有服务端短 id 的条目类别($push 五类);acceptance/non-goal 为纯字符串条目无 id,不入 entry */
2991
+ declare const WRITE_ACK_ENTRY_KINDS: readonly ["check", "artifact", "decision", "confirmation", "archnote"];
2992
+ declare const WriteAckEntryKindSchema: z.ZodEnum<{
2993
+ check: "check";
2994
+ decision: "decision";
2995
+ artifact: "artifact";
2996
+ confirmation: "confirmation";
2997
+ archnote: "archnote";
2998
+ }>;
2999
+ type WriteAckEntryKind = z.infer<typeof WriteAckEntryKindSchema>;
3000
+ /** 写入回显项:触及字段点路径 + 值摘要(excerpt 上限 120 字符,多字段写入逐字段一条) */
3001
+ declare const EchoItemSchema: z.ZodObject<{
3002
+ path: z.ZodString;
3003
+ excerpt: z.ZodString;
3004
+ }, z.core.$strip>;
3005
+ type EchoItem = z.infer<typeof EchoItemSchema>;
3006
+ /** 任务进度计数(口径与列表概要投影一致:completed=completed 节点数,skipped 不计入分母) */
3007
+ declare const TaskProgressSchema: z.ZodObject<{
3008
+ completed: z.ZodNumber;
3009
+ total: z.ZodNumber;
3010
+ }, z.core.$strip>;
3011
+ type TaskProgress = z.infer<typeof TaskProgressSchema>;
3012
+ /** TaskPublic + projectId + progress:写入回执/创建响应共用的任务进度摘要。
3013
+ * projectId 单列(TaskPublic 无)——项目归属是创建响应的语义要点(N012 归属继承行为需在写入时点可见) */
3014
+ declare const TaskProgressPublicSchema: z.ZodObject<{
3015
+ taskId: z.ZodString;
3016
+ title: z.ZodString;
3017
+ type: z.ZodOptional<z.ZodEnum<{
3018
+ feature: "feature";
3019
+ bugfix: "bugfix";
3020
+ "ui-tweak": "ui-tweak";
3021
+ research: "research";
3022
+ }>>;
3023
+ currentNode: z.ZodString;
3024
+ currentPhase: z.ZodString;
3025
+ status: z.ZodString;
3026
+ pausedAt: z.ZodNullable<z.ZodString>;
3027
+ track: z.ZodString;
3028
+ projectId: z.ZodString;
3029
+ progress: z.ZodObject<{
3030
+ completed: z.ZodNumber;
3031
+ total: z.ZodNumber;
3032
+ }, z.core.$strip>;
3033
+ }, z.core.$strip>;
3034
+ type TaskProgressPublic = z.infer<typeof TaskProgressPublicSchema>;
3035
+ declare const WriteAckSchema: z.ZodObject<{
3036
+ taskId: z.ZodString;
3037
+ updated: z.ZodArray<z.ZodString>;
3038
+ entry: z.ZodOptional<z.ZodObject<{
3039
+ id: z.ZodString;
3040
+ kind: z.ZodEnum<{
3041
+ check: "check";
3042
+ decision: "decision";
3043
+ artifact: "artifact";
3044
+ confirmation: "confirmation";
3045
+ archnote: "archnote";
3046
+ }>;
3047
+ }, z.core.$strip>>;
3048
+ echo: z.ZodOptional<z.ZodArray<z.ZodObject<{
3049
+ path: z.ZodString;
3050
+ excerpt: z.ZodString;
3051
+ }, z.core.$strip>>>;
3052
+ updatedAt: z.ZodDate;
3053
+ task: z.ZodObject<{
3054
+ taskId: z.ZodString;
3055
+ title: z.ZodString;
3056
+ type: z.ZodOptional<z.ZodEnum<{
3057
+ feature: "feature";
3058
+ bugfix: "bugfix";
3059
+ "ui-tweak": "ui-tweak";
3060
+ research: "research";
3061
+ }>>;
3062
+ currentNode: z.ZodString;
3063
+ currentPhase: z.ZodString;
3064
+ status: z.ZodString;
3065
+ pausedAt: z.ZodNullable<z.ZodString>;
3066
+ track: z.ZodString;
3067
+ projectId: z.ZodString;
3068
+ progress: z.ZodObject<{
3069
+ completed: z.ZodNumber;
3070
+ total: z.ZodNumber;
3071
+ }, z.core.$strip>;
3072
+ }, z.core.$strip>;
3073
+ }, z.core.$strip>;
3074
+ type WriteAck = z.infer<typeof WriteAckSchema>;
3075
+ /** T202609010002 D6:批量写回执(WriteAck-B)——批量端点聚合形态:逐条新条目标识 +
3076
+ * 逐条失败定位 + 一份任务进度摘要;无逐条 echo(50 条 echo 反向制造膨胀)。
3077
+ * index 一律以调用方原始提交序为基准(artifact 本地 file 读取失败由 CLI 压缩提交,
3078
+ * CLI 负责把服务端序映射回原始序);applied=0 且有 failures 时由 CLI/MCP 层映射为
3079
+ * 失败三要素呈现。acceptance/non-goal 为纯字符串条目无 id/kind,entries 项仅 {index}。 */
3080
+ declare const TaskBatchEntrySchema: z.ZodObject<{
3081
+ index: z.ZodNumber;
3082
+ id: z.ZodOptional<z.ZodString>;
3083
+ kind: z.ZodOptional<z.ZodEnum<{
3084
+ check: "check";
3085
+ decision: "decision";
3086
+ artifact: "artifact";
3087
+ confirmation: "confirmation";
3088
+ archnote: "archnote";
3089
+ }>>;
3090
+ }, z.core.$strip>;
3091
+ declare const TaskBatchFailureSchema: z.ZodObject<{
3092
+ index: z.ZodNumber;
3093
+ message: z.ZodString;
3094
+ hint: z.ZodOptional<z.ZodString>;
3095
+ }, z.core.$strip>;
3096
+ declare const TaskBatchAckSchema: z.ZodObject<{
3097
+ taskId: z.ZodString;
3098
+ applied: z.ZodNumber;
3099
+ updated: z.ZodArray<z.ZodString>;
3100
+ entries: z.ZodArray<z.ZodObject<{
3101
+ index: z.ZodNumber;
3102
+ id: z.ZodOptional<z.ZodString>;
3103
+ kind: z.ZodOptional<z.ZodEnum<{
3104
+ check: "check";
3105
+ decision: "decision";
3106
+ artifact: "artifact";
3107
+ confirmation: "confirmation";
3108
+ archnote: "archnote";
3109
+ }>>;
3110
+ }, z.core.$strip>>;
3111
+ failures: z.ZodArray<z.ZodObject<{
3112
+ index: z.ZodNumber;
3113
+ message: z.ZodString;
3114
+ hint: z.ZodOptional<z.ZodString>;
3115
+ }, z.core.$strip>>;
3116
+ updatedAt: z.ZodDate;
3117
+ task: z.ZodObject<{
3118
+ taskId: z.ZodString;
3119
+ title: z.ZodString;
3120
+ type: z.ZodOptional<z.ZodEnum<{
3121
+ feature: "feature";
3122
+ bugfix: "bugfix";
3123
+ "ui-tweak": "ui-tweak";
3124
+ research: "research";
3125
+ }>>;
3126
+ currentNode: z.ZodString;
3127
+ currentPhase: z.ZodString;
3128
+ status: z.ZodString;
3129
+ pausedAt: z.ZodNullable<z.ZodString>;
3130
+ track: z.ZodString;
3131
+ projectId: z.ZodString;
3132
+ progress: z.ZodObject<{
3133
+ completed: z.ZodNumber;
3134
+ total: z.ZodNumber;
3135
+ }, z.core.$strip>;
3136
+ }, z.core.$strip>;
3137
+ }, z.core.$strip>;
3138
+ type TaskBatchEntry = z.infer<typeof TaskBatchEntrySchema>;
3139
+ type TaskBatchFailure = z.infer<typeof TaskBatchFailureSchema>;
3140
+ type TaskBatchAck = z.infer<typeof TaskBatchAckSchema>;
3141
+ /** T202608280007 F1:任务创建响应(原全量 Task 实体)——任务摘要 + 首节点开工资料,与 advance 轻量形态同构 */
3142
+ declare const CreateTaskResponseSchema: z.ZodObject<{
3143
+ task: z.ZodObject<{
3144
+ taskId: z.ZodString;
3145
+ title: z.ZodString;
3146
+ type: z.ZodOptional<z.ZodEnum<{
3147
+ feature: "feature";
3148
+ bugfix: "bugfix";
3149
+ "ui-tweak": "ui-tweak";
3150
+ research: "research";
3151
+ }>>;
3152
+ currentNode: z.ZodString;
3153
+ currentPhase: z.ZodString;
3154
+ status: z.ZodString;
3155
+ pausedAt: z.ZodNullable<z.ZodString>;
3156
+ track: z.ZodString;
3157
+ projectId: z.ZodString;
3158
+ progress: z.ZodObject<{
3159
+ completed: z.ZodNumber;
3160
+ total: z.ZodNumber;
3161
+ }, z.core.$strip>;
3162
+ }, z.core.$strip>;
3163
+ firstNode: z.ZodObject<{
3164
+ nodeId: z.ZodString;
3165
+ label: z.ZodString;
3166
+ track: z.ZodString;
3167
+ prompt: z.ZodString;
3168
+ skills: z.ZodArray<z.ZodString>;
3169
+ agents: z.ZodArray<z.ZodString>;
3170
+ upcomingPause: z.ZodNullable<z.ZodString>;
3171
+ }, z.core.$strip>;
3172
+ }, z.core.$strip>;
3173
+ type CreateTaskResponse = z.infer<typeof CreateTaskResponseSchema>;
3174
+ /**
3175
+ * 进度计数单源(列表聚合管道同口径,供路由层回执组装):
3176
+ * completed = nodeStates 中 status='completed' 的节点数;
3177
+ * total = 实例节点数 - skipped 节点数(裁剪节点不计分母)。
3178
+ */
3179
+ declare function taskProgress(task: Task): TaskProgress;
3180
+ /**
3181
+ * 值摘要截断——按 Unicode 码点截断(防 astral 字符劈开代理对产出非法 JSON),
3182
+ * 总长含省略号封顶 max。
3183
+ */
3184
+ declare function excerpt(value: string, max?: number): string;
3185
+ /**
3186
+ * T202608280007 F2:context 分层视图——basic(默认)剥离 artifact content 全文快照;
3187
+ * full 与既有形态逐字节等价(断点续跑自足性不回退红线)。HTTP query / CLI --view /
3188
+ * MCP view 三通道单源。
3189
+ *
3190
+ * 实现裁定(架构评审① F01 留痕):不另建 ArtifactRefSchema——ArtifactSchema.content
3191
+ * 本就 optional,basic 剥离后仍为合法 Artifact 形态,TaskContextSchema 原样可用;
3192
+ * 分层属传输投影(server 路由层 stripArtifactContent),不引入消费方可感知的类型分叉。
3193
+ */
3194
+ declare const CONTEXT_VIEWS: readonly ["basic", "full"];
3195
+ declare const ContextViewSchema: z.ZodEnum<{
3196
+ basic: "basic";
3197
+ full: "full";
3198
+ }>;
3199
+ type ContextView = z.infer<typeof ContextViewSchema>;
3200
+
3201
+ /**
3202
+ * 资产启停切换请求体(T202608290001)——skill / agent / dag-template 三类资产共用。
3203
+ * 专用端点唯一入参:POST /api/{skills|agents}/:name/enabled 与 POST /api/dag/templates/:id/enabled。
3204
+ * 启停不进 Create/Update schema、不触发版本号提升(内容未变——版本标记随产物走)。
3205
+ */
3206
+ declare const AssetSetEnabledSchema: z.ZodObject<{
3207
+ enabled: z.ZodBoolean;
3208
+ }, z.core.$strip>;
3209
+ type AssetSetEnabled = z.infer<typeof AssetSetEnabledSchema>;
3210
+
3211
+ /**
3212
+ * 模板升级 HTTP 契约(T202609020001 K5)——plan/apply 两阶段协议的请求形状。
3213
+ * plan 响应与 apply 回执形状由 core 顶层模块 template-upgrade.ts 的纯函数类型承载(UpgradePlanResult / UpgradeApplyOutcome)。
3214
+ */
3215
+ /** 升级节点五态(F23 组合态优先级:hash 差 ⇒ 一律 local-modified——本地修改保护优先于升级提示) */
3216
+ declare const UpgradeNodeStatusSchema: z.ZodEnum<{
3217
+ updatable: "updatable";
3218
+ "local-modified": "local-modified";
3219
+ "up-to-date": "up-to-date";
3220
+ "source-missing": "source-missing";
3221
+ "source-disabled": "source-disabled";
3222
+ }>;
3223
+ type UpgradeNodeStatus = z.infer<typeof UpgradeNodeStatusSchema>;
3224
+ declare const UpgradeActionSchema: z.ZodEnum<{
3225
+ skip: "skip";
3226
+ upgrade: "upgrade";
3227
+ keep: "keep";
3228
+ }>;
3229
+ type UpgradeAction = z.infer<typeof UpgradeActionSchema>;
3230
+ /**
3231
+ * 单节点升级决策。expected(可选)= 决策所依据的 plan 时刻状态——apply 重算当前状态与 expected
3232
+ * 不符 → 422 UPGRADE_STALE(防 plan→apply 时间窗内模板被编辑后决策静默覆盖本地修改);
3233
+ * 省略时仅做不变式校验(source-missing/source-disabled 一律按 skip、local-modified 必须显式决策)。
3234
+ */
3235
+ declare const UpgradeDecisionSchema: z.ZodObject<{
3236
+ nodeId: z.ZodString;
3237
+ action: z.ZodEnum<{
3238
+ skip: "skip";
3239
+ upgrade: "upgrade";
3240
+ keep: "keep";
3241
+ }>;
3242
+ expected: z.ZodOptional<z.ZodObject<{
3243
+ status: z.ZodEnum<{
3244
+ updatable: "updatable";
3245
+ "local-modified": "local-modified";
3246
+ "up-to-date": "up-to-date";
3247
+ "source-missing": "source-missing";
3248
+ "source-disabled": "source-disabled";
3249
+ }>;
3250
+ }, z.core.$strip>>;
3251
+ }, z.core.$strip>;
3252
+ type UpgradeDecision = z.infer<typeof UpgradeDecisionSchema>;
3253
+ declare const UpgradeApplyRequestSchema: z.ZodObject<{
3254
+ decisions: z.ZodArray<z.ZodObject<{
3255
+ nodeId: z.ZodString;
3256
+ action: z.ZodEnum<{
3257
+ skip: "skip";
3258
+ upgrade: "upgrade";
3259
+ keep: "keep";
3260
+ }>;
3261
+ expected: z.ZodOptional<z.ZodObject<{
3262
+ status: z.ZodEnum<{
3263
+ updatable: "updatable";
3264
+ "local-modified": "local-modified";
3265
+ "up-to-date": "up-to-date";
3266
+ "source-missing": "source-missing";
3267
+ "source-disabled": "source-disabled";
3268
+ }>;
3269
+ }, z.core.$strip>>;
3270
+ }, z.core.$strip>>;
3271
+ }, z.core.$strip>;
3272
+ type UpgradeApplyRequest = z.infer<typeof UpgradeApplyRequestSchema>;
1462
3273
 
1463
3274
  /**
1464
3275
  * 服务配置 schema(N018 D5):Zod 单一真相源,core 只承载纯 schema + env 键映射,
@@ -1483,12 +3294,14 @@ declare const SimingConfigSchema: z.ZodObject<{
1483
3294
  info: "info";
1484
3295
  warn: "warn";
1485
3296
  }>>;
1486
- auth: z.ZodOptional<z.ZodUnknown>;
3297
+ auth: z.ZodPrefault<z.ZodObject<{
3298
+ enabled: z.ZodDefault<z.ZodBoolean>;
3299
+ }, z.core.$strip>>;
1487
3300
  cors: z.ZodOptional<z.ZodUnknown>;
1488
3301
  }, z.core.$strip>;
1489
3302
  type SimingConfig = z.infer<typeof SimingConfigSchema>;
1490
- /** 可经环境变量/CLI 参数/配置文件配置的 key(预留字段 auth/cors 除外) */
1491
- declare const SIMING_CONFIG_KEYS: readonly ["mongoUri", "port", "host", "logLevel"];
3303
+ /** 可经环境变量/CLI 参数/配置文件配置的 keycors 仍为预留字段) */
3304
+ declare const SIMING_CONFIG_KEYS: readonly ["mongoUri", "port", "host", "logLevel", "auth"];
1492
3305
  type SimingConfigKey = (typeof SIMING_CONFIG_KEYS)[number];
1493
3306
  /**
1494
3307
  * env 键映射单源(N018 D5):server env resolver 与 cli loader 共用,
@@ -1496,12 +3309,17 @@ type SimingConfigKey = (typeof SIMING_CONFIG_KEYS)[number];
1496
3309
  * 沿用既有 server EnvSchema 约定(见 ENVIRONMENT.md)。
1497
3310
  */
1498
3311
  declare const SIMING_CONFIG_ENV_KEYS: Record<SimingConfigKey, string>;
3312
+ /**
3313
+ * auth 键的 env 值解析(布尔字符串形态):SIMING_AUTH_ENABLED=true/false,
3314
+ * 其余值 fail-fast 由调用方处理(返回 undefined 表示 env 未提供)。
3315
+ */
3316
+ declare function parseAuthEnabledEnvValue(raw: string): boolean | undefined;
1499
3317
 
1500
3318
  /**
1501
3319
  * Domain error types — thrown by core business logic, caught by server's app.onError().
1502
3320
  */
1503
3321
  /** N012 语义化业务错误码(可选挂载到 AppError 子类;HTTP 形状向后兼容:error 字段缺省仍为 http 级 code) */
1504
- type BizCode = 'PROJECT_ARCHIVED' | 'TEMPLATE_PROJECT_MISMATCH' | 'TEMPLATE_PROJECT_IMMUTABLE' | 'SCOPE_IMMUTABLE' | 'TASK_PROJECT_IMMUTABLE' | 'DEFAULT_PROJECT_IMMUTABLE' | 'TEMPLATE_NAME_CONFLICT' | 'PROJECT_NOT_FOUND' | 'AGENT_SKILL_SCOPE_CONFLICT' | 'MODEL_CODE_EXISTS' | 'MODEL_CODE_IMMUTABLE' | 'MODEL_ALIAS_IN_USE' | 'ENUM_ENTRY_BUILTIN' | 'ENUM_ENTRY_IN_USE' | 'ENUM_VALUE_CONFLICT' | 'NAME_SCOPE_CONFLICT' | 'TASK_DOC_NOT_SET' | 'TASK_DOC_NOT_FOUND' | 'TASK_DOC_SECTION_NOT_FOUND' | 'TASK_AT_PAUSE_POINT' | 'TASK_NOT_AT_PAUSE_POINT' | 'NODE_NOT_IN_INSTANCE' | 'CHECK_NOT_FOUND' | 'NODE_RECORD_NOT_WRITABLE' | 'TASK_TERMINATED' | 'TASK_PRUNE_GRAPH_INVALID' | 'TASK_SKIP_NODE_NOT_FOUND' | 'TASK_TYPE_TRACK_MISMATCH';
3322
+ type BizCode = 'PROJECT_ARCHIVED' | 'TEMPLATE_PROJECT_MISMATCH' | 'TEMPLATE_PROJECT_IMMUTABLE' | 'SCOPE_IMMUTABLE' | 'TASK_PROJECT_IMMUTABLE' | 'DEFAULT_PROJECT_IMMUTABLE' | 'TEMPLATE_NAME_CONFLICT' | 'TEMPLATE_CODE_CONFLICT' | 'TEMPLATE_CODE_IMMUTABLE' | 'PROJECT_NOT_FOUND' | 'AGENT_SKILL_SCOPE_CONFLICT' | 'MODEL_CODE_EXISTS' | 'MODEL_CODE_IMMUTABLE' | 'MODEL_ALIAS_IN_USE' | 'ENUM_ENTRY_BUILTIN' | 'ENUM_ENTRY_IN_USE' | 'ENUM_VALUE_CONFLICT' | 'NAME_SCOPE_CONFLICT' | 'REFERENCE_IN_USE' | 'TASK_DOC_NOT_SET' | 'TASK_DOC_NOT_FOUND' | 'TASK_DOC_SECTION_NOT_FOUND' | 'TASK_AT_PAUSE_POINT' | 'TASK_NOT_AT_PAUSE_POINT' | 'NODE_NOT_IN_INSTANCE' | 'CHECK_NOT_FOUND' | 'NODE_RECORD_NOT_WRITABLE' | 'TASK_TERMINATED' | 'TASK_PRUNE_GRAPH_INVALID' | 'TASK_SKIP_NODE_NOT_FOUND' | 'TASK_TYPE_TRACK_MISMATCH' | 'TEMPLATE_DISABLED' | 'AUTH_REQUIRED' | 'AUTH_TOKEN_INVALID' | 'AUTH_INVALID_CREDENTIALS' | 'AUTH_FORBIDDEN' | 'AUTH_ACCOUNT_EXISTS' | 'BATCH_EMPTY' | 'BATCH_LIMIT_EXCEEDED' | 'BATCH_PAYLOAD_TOO_LARGE' | 'NODE_PRESET_CODE_EXISTS' | 'NODE_PRESET_CODE_IMMUTABLE' | 'NODE_PRESET_VERSION_REQUIRED' | 'TEMPLATE_NODE_ID_DUPLICATE' | 'NODE_LIBRARY_COMPOSITION_NOT_FOUND' | 'UPGRADE_DECISION_REQUIRED' | 'UPGRADE_STALE' | 'FLOW_MANIFEST_INVALID';
1505
3323
  /** bizCode → 用户可读中文 message(单一真相源,路由层抛错时引用) */
1506
3324
  declare const BIZ_CODE_MESSAGES: Record<BizCode, string>;
1507
3325
  interface AppErrorOptions {
@@ -1522,7 +3340,28 @@ declare class NotFoundError extends AppError {
1522
3340
  readonly code = "not_found";
1523
3341
  constructor(resource: string, id: string, options?: AppErrorOptions);
1524
3342
  readonly bizCode?: BizCode;
3343
+ /**
3344
+ * T202609020002:not-found 相近候选清单(模板寻址防转录错误——格式合法但不存在的
3345
+ * code/数据库 id,错误信息携带项目内相近模板,转录错误可当场发现)。附加到响应体
3346
+ * 的 candidates 字段;仅模板寻址路由经 withTemplateCandidates 注入(构造后写入故非
3347
+ * readonly——外部读、内部一次写),其余资源 not-found 形态不变。
3348
+ */
3349
+ templateCandidates?: {
3350
+ id: string;
3351
+ code: string;
3352
+ name: string;
3353
+ }[];
3354
+ withTemplateCandidates(candidates: {
3355
+ id: string;
3356
+ code: string;
3357
+ name: string;
3358
+ }[]): this;
1525
3359
  toResponse(): {
3360
+ candidates?: {
3361
+ id: string;
3362
+ code: string;
3363
+ name: string;
3364
+ }[];
1526
3365
  error: string;
1527
3366
  message: string;
1528
3367
  resource: string;
@@ -1567,6 +3406,181 @@ declare class ValidationError extends AppError {
1567
3406
  issues: unknown[];
1568
3407
  };
1569
3408
  }
3409
+ /** 401 未授权(T202608310001:鉴权域——无凭证/凭证无效;message 取 BIZ_CODE_MESSAGES 单源) */
3410
+ declare class UnauthorizedError extends AppError {
3411
+ readonly bizCode: Extract<BizCode, 'AUTH_REQUIRED' | 'AUTH_TOKEN_INVALID' | 'AUTH_INVALID_CREDENTIALS'>;
3412
+ readonly statusCode = 401;
3413
+ readonly code = "unauthorized";
3414
+ constructor(bizCode: Extract<BizCode, 'AUTH_REQUIRED' | 'AUTH_TOKEN_INVALID' | 'AUTH_INVALID_CREDENTIALS'>);
3415
+ toResponse(): {
3416
+ error: "AUTH_REQUIRED" | "AUTH_TOKEN_INVALID" | "AUTH_INVALID_CREDENTIALS";
3417
+ message: string;
3418
+ };
3419
+ }
3420
+ /** 403 禁止(T202608310001:project 上下文越权 admin-only 端点) */
3421
+ declare class ForbiddenError extends AppError {
3422
+ readonly statusCode = 403;
3423
+ readonly code = "forbidden";
3424
+ readonly bizCode: "AUTH_FORBIDDEN";
3425
+ constructor();
3426
+ toResponse(): {
3427
+ error: "AUTH_FORBIDDEN";
3428
+ message: string;
3429
+ };
3430
+ }
3431
+
3432
+ /**
3433
+ * 资产版本(skill/agent 的 version 字段)递增单源(T202608260002 D1 自 cli export 上移)。
3434
+ * 注意与包版本 VERSION(index.ts,读 package.json 的发布版本)是两个概念——本文件只管资产版本 bump。
3435
+ * 两种语义并存(实现必须显式区分,禁止混用):
3436
+ * - bumpPatch:传播语义——解析失败以 '1.0.0' 为基准 +1(恒返回可比较的新版本)。
3437
+ * 用于服务端 function 变更自动 bump 与存量回填 bump:若原样返回旧值,
3438
+ * install 的版本相等 skip 会吞掉本次变更(已装环境旧文案残留)。
3439
+ * - bumpPatchOrPassthrough:export 宽松语义——解析失败原样返回。
3440
+ * export 条目版本允许自由文本(UpdateSchema 不限格式),不可解析时不误伤原值。
3441
+ */
3442
+ /** 传播语义:非法版本视为 '1.0.0' → 返回 '1.0.1'(保证版本必变,防 skip 吞传播) */
3443
+ declare function bumpPatch(version: string): string;
3444
+ /** export 宽松语义:解析失败原样返回(不误伤自由文本版本) */
3445
+ declare function bumpPatchOrPassthrough(version: string): string;
3446
+
3447
+ /**
3448
+ * 模板内容比较(T202609030001 F1):导入内容 vs 服务器现值(同名同版本场景的门控 +
3449
+ * 两条 updated 分支的变更范围)。纯函数,无 I/O。
3450
+ *
3451
+ * 比较域 = name / description / nodes / edges / layout;不参与比较 =
3452
+ * id / createdAt / updatedAt / enabled / code / projectId / isDefault / version
3453
+ *(isDefault 跟随 export 先例,不由导入通道管理)。
3454
+ */
3455
+ interface TemplateContentSource {
3456
+ name: string;
3457
+ description: string;
3458
+ nodes: DagNode[];
3459
+ edges: DagEdge[];
3460
+ layout?: Record<string, {
3461
+ x: number;
3462
+ y: number;
3463
+ }> | undefined;
3464
+ }
3465
+ /** 变更范围(预览 changes / 回执同构) */
3466
+ interface TemplateContentChanges {
3467
+ nodesAdded: string[];
3468
+ nodesRemoved: string[];
3469
+ nodesChanged: string[];
3470
+ edgesChanged: boolean;
3471
+ descriptionChanged: boolean;
3472
+ layoutChanged: boolean;
3473
+ }
3474
+ interface TemplateContentDiff {
3475
+ identical: boolean;
3476
+ changes: TemplateContentChanges;
3477
+ }
3478
+ /**
3479
+ * 导入内容 vs 服务器现值的内容比较。
3480
+ * canonical 归一:nodes 按 id 对齐(顺序差异不视为变更,skills 顺序不敏感由
3481
+ * computeNodeContentHash 保证);edges 排序后比较;layout 缺省归一为空对象;
3482
+ * description 原样比较(不 trim)。
3483
+ */
3484
+ declare function diffTemplateContent(imported: TemplateContentSource, existing: TemplateContentSource): TemplateContentDiff;
3485
+
3486
+ /** 参与 hash 的内容字段(nodeId 不参与——模板内可改名,属模板图结构域非内容域) */
3487
+ type NodeContentFields = Pick<DagNode, 'label' | 'phase' | 'track' | 'prompt' | 'skills'>;
3488
+ /**
3489
+ * 节点内容规范化摘要(T202609020001 K2):sha256 → hex 前 16 位。
3490
+ * core 单源导出——server(节点详情响应 contentHash / 升级基线)与模板组装方共用同一算法,杜绝两端漂移。
3491
+ * 规范化规则:skills 排序后参与(数组顺序不敏感);对象字面量序固定(JSON.stringify 按 key 声明序)。
3492
+ */
3493
+ declare function computeNodeContentHash(node: NodeContentFields): string;
3494
+
3495
+ /**
3496
+ * 模板升级状态机与决策执行(T202609020001 K5/K2/F23 纯函数层)。
3497
+ * server 路由层负责寻址/鉴权/落库,本模块只做「模板 + 节点库快照 → plan/apply 结果」的纯计算——
3498
+ * 单测直接覆盖五态与竞态路径,不依赖 HTTP。
3499
+ *
3500
+ * 双信号分工(K2):version 判 updatable(K13 升版强制保证版本信号可靠)、
3501
+ * contentHash 判 local-modified(模板节点当前内容 hash ≠ sourcePreset 基线)。
3502
+ * 组合态优先级(F23):hash 差存在 ⇒ status 一律 local-modified(本地修改保护优先于升级提示)。
3503
+ */
3504
+ /** 单节点升级计划条目(plan 响应形状) */
3505
+ interface UpgradePlanItem {
3506
+ nodeId: string;
3507
+ source: {
3508
+ code: string;
3509
+ version: string;
3510
+ contentHash: string;
3511
+ };
3512
+ latest: {
3513
+ version: string;
3514
+ contentHash: string;
3515
+ enabled: boolean;
3516
+ } | null;
3517
+ status: UpgradeNodeStatus;
3518
+ localModified: boolean;
3519
+ diff: {
3520
+ prompt: 'changed' | null;
3521
+ label: 'changed' | null;
3522
+ phase: 'changed' | null;
3523
+ track: 'changed' | null;
3524
+ skills: {
3525
+ added: string[];
3526
+ removed: string[];
3527
+ } | null;
3528
+ agents: {
3529
+ added: string[];
3530
+ removed: string[];
3531
+ } | null;
3532
+ };
3533
+ }
3534
+ interface UpgradePlanResult {
3535
+ templateVersion: string;
3536
+ items: UpgradePlanItem[];
3537
+ upgradableCount: number;
3538
+ }
3539
+ /** apply 结果条目 */
3540
+ interface UpgradeApplyResultItem {
3541
+ nodeId: string;
3542
+ action: 'upgrade' | 'keep' | 'skip';
3543
+ applied: boolean;
3544
+ reason?: string | undefined;
3545
+ }
3546
+ interface UpgradeApplyOutcome {
3547
+ /** apply 后的完整节点数组(路由层一次 repo.update 原子落库——单文档更新无中间态) */
3548
+ nodes: DagNode[];
3549
+ /** apply 后模板版本(patch+1);null = 无实际变更不升版 */
3550
+ nextVersion: string | null;
3551
+ results: UpgradeApplyResultItem[];
3552
+ }
3553
+ /** apply 决策入参(HTTP UpgradeDecision 的子集形状——expected 可选,见 schema 注释) */
3554
+ interface UpgradeDecisionInput {
3555
+ nodeId: string;
3556
+ action: 'upgrade' | 'keep' | 'skip';
3557
+ expected?: {
3558
+ status: UpgradeNodeStatus;
3559
+ } | undefined;
3560
+ }
3561
+ /** 单节点状态机(F23 组合态优先级)。无 sourcePreset 的节点不参与升级(plan 已过滤,此处为防御分支) */
3562
+ declare function computeUpgradeStatus(node: DagNode, latest: NodePreset | null): {
3563
+ status: UpgradeNodeStatus;
3564
+ localModified: boolean;
3565
+ };
3566
+ /** 组装升级计划(纯函数)。presetsByCode 须含停用资产(source-disabled 判定依赖) */
3567
+ declare function buildUpgradePlan(template: DagTemplate, presetsByCode: ReadonlyMap<string, NodePreset>): UpgradePlanResult;
3568
+ /**
3569
+ * apply 决策执行(纯函数;写库由路由层一次原子更新完成)。
3570
+ *
3571
+ * 决策表(K5):
3572
+ * - upgrade:节点内容 ← 库最新值拷贝(nodeId 保持模板内现值——图结构域不迁移),基线回到库内容
3573
+ * - keep:内容保持本地,基线重置为本地内容 hash + 版本对齐已读库版本(下轮 plan 以版本判定不再提示,
3574
+ * 库再演进才重新提示——「不重复骚扰」语义)
3575
+ * - skip:不动,下轮 plan 仍列出
3576
+ *
3577
+ * 守卫(按序):
3578
+ * 1. 决策 nodeId 必须命中带 sourcePreset 的模板节点(未知/重复 → 422)
3579
+ * 2. local-modified(含组合态)节点缺决策 → 422 UPGRADE_DECISION_REQUIRED(强制显式决策)
3580
+ * 3. source-missing / source-disabled 一律按缺省 skip(无 upgrade/keep 语义可执行)
3581
+ * 4. STALE 重验:决策携带 expected 且与 apply 时刻重算状态不符 → 422 UPGRADE_STALE(附变化清单)
3582
+ */
3583
+ declare function applyUpgradeDecisions(template: DagTemplate, presetsByCode: ReadonlyMap<string, NodePreset>, decisions: ReadonlyArray<UpgradeDecisionInput>): UpgradeApplyOutcome;
1570
3584
 
1571
3585
  /**
1572
3586
  * N017 F8 流转引擎(新语义状态机,见技术方案 §2.2):
@@ -1605,6 +3619,16 @@ declare function advanceTask(deps: AdvanceDeps, taskId: string, input?: AdvanceI
1605
3619
  declare function approveTask(deps: AdvanceDeps, taskId: string, request: ApproveRequest): Promise<ApproveResponse>;
1606
3620
  declare function pauseTask(deps: AdvanceDeps, taskId: string, reason?: string): Promise<Task>;
1607
3621
  declare function resumeTask(deps: AdvanceDeps, taskId: string, decision?: string): Promise<Task>;
3622
+ /**
3623
+ * T202608290001 任务取消:active/paused(含暂停点等待态)→ cancelled 终态(不可逆,无撤销)。
3624
+ *
3625
+ * - 既有记录(doc/nodeRecords/archNotes/dagInstance)原样冻结保留,零删除零补写;
3626
+ * - pausedAt 清 null(终态只读,残留暂停锚点无消费方但易误导);
3627
+ * - 取消后只读性由既有守卫天然构成:advance(非 active 拒绝)/ approve(非暂停点拒绝)/
3628
+ * pause(非 active 拒绝)/ resume(非手动暂停拒绝)/ 记录写端点(TASK_TERMINATED);
3629
+ * - 终态重复取消 → 400 TASK_TERMINATED(复用既有码:completed/cancelled 同语义)。
3630
+ */
3631
+ declare function cancelTask(deps: AdvanceDeps, taskId: string, reason?: string): Promise<Task>;
1608
3632
  /**
1609
3633
  * @internal 供单测直接验证的模块私有 helper(非公共 API)
1610
3634
  * N017:findNextNode → findNextEdge——返回边对象(调用方需要 pausePoint)
@@ -1665,6 +3689,8 @@ declare function pruneInstance(template: DagTemplate, taskTrack: string, skipNod
1665
3689
  * T202608240003:任务轨道 → 实例节点 track 匹配集。
1666
3690
  * 独立单源模块——prune(剪枝轨道剔除 + 引擎路径可达性校验)与 advance-engine
1667
3691
  * (流转路由 + 终止判定)消费同一语义,防止剪枝与路由口径漂移。
3692
+ * T202608280004:web dag-editor validate 规则 4 持有本函数的本地镜像副本——
3693
+ * 本函数语义演进须同步该副本。
1668
3694
  */
1669
3695
  /**
1670
3696
  * - backend/ui/research:匹配本轨道节点 + 'all' 哨兵
@@ -1690,7 +3716,53 @@ declare function generateEntryId(existing: readonly string[]): string;
1690
3716
  */
1691
3717
  declare function renderPrompt(template: string, task: Task): string;
1692
3718
 
3719
+ /** 模板导入/导出编排依赖(repo 显式注入,无 DI 框架);nodePresetRepo 供 K10 sourcePreset 存在性检查 */
3720
+ interface TemplateTransferDeps {
3721
+ templateRepo: DagTemplateRepo;
3722
+ skillRepo: SkillRepo;
3723
+ agentRepo: AgentRepo;
3724
+ modelAliasRepo: ModelAliasRepo;
3725
+ nodePresetRepo: NodePresetRepo;
3726
+ }
3727
+ /**
3728
+ * 导出依赖闭包推导(T202608300002 §2.2,PRD 3.1 规则 1-4,一跳封闭):
3729
+ * 1. SKILL 直接引用集 = 模板所有节点 skills 字段(去重)
3730
+ * 2. AGENT 集 = boundSkills 与直接引用集有交集的 agent(查询范围:global 全集 + 源项目 project 全集)
3731
+ * 3. SKILL 全集 = 直接引用 ∪ 被导出 AGENT 的 boundSkills(一跳封闭——新增 SKILL 不反查更多 AGENT)
3732
+ * 4. 模型映射集 = 被导出 AGENT 的 model code 对应别名
3733
+ *
3734
+ * 启停矩阵(统一含停用——备份完整性):agent/skill 收集查询显式含停用;
3735
+ * 停用模板可导出(与详情页 by-id 可见策略一致)。源环境悬空引用记入 warnings 不阻断。
3736
+ */
3737
+ declare function composeExportBundle(deps: TemplateTransferDeps, templateId: string): Promise<ExportBundle>;
3738
+
3739
+ /**
3740
+ * 项目内默认模板存在性(含停用——启停与默认无联动,排除停用会在「默认模板恰为停用态」时误判双默认)。
3741
+ * 不排除同名自身:D9-b 裁定「查项目内任何默认(含自身同名)」——F17/PRD 验收 19 字面语义
3742
+ * 「无论是否同名覆盖 → 降 false」,自指极端场景(默认位空缺)已登记 PRD 开放问题,由管理台重新指定。
3743
+ */
3744
+ declare function hasProjectDefault(deps: TemplateTransferDeps, targetProjectId: string): Promise<boolean>;
3745
+ /** 模板同名定位(含停用) */
3746
+ declare function findTemplateByName(deps: TemplateTransferDeps, targetProjectId: string, name: string): Promise<{
3747
+ id: string;
3748
+ version: string;
3749
+ } | null>;
3750
+ declare function buildImportPlan(deps: TemplateTransferDeps, targetProjectId: string, bundle: ExportBundle): Promise<ImportPlanResponse>;
3751
+
3752
+ /**
3753
+ * 导入执行(T202608300002 §2.5)。
3754
+ *
3755
+ * 模板写 = 单文档操作天然原子(同名覆盖 findOneAndUpdate / 新建 insertOne,无多步中间态,
3756
+ * PRD F7 失败不变性由此满足——repo 层无 session 贯通,不引入真事务)。
3757
+ * 依赖写逐条独立(顺序:重映射 → 写前自证校验 → 写库),任一失败不阻断其余,进结果清单。
3758
+ *
3759
+ * 写前自证校验(repo 直写不经路由 zValidator,校验责任内聚编排层):
3760
+ * scope=project 的 payload 先补 projectId=targetProjectId 再 safeParse——CreateSchema 的
3761
+ * superRefine 要求 scope=project ⇒ projectId 必填,先 parse 后补必失败。
3762
+ */
3763
+ declare function applyImport(deps: TemplateTransferDeps, targetProjectId: string, bundle: ExportBundle, decisions: ImportDecision[]): Promise<ImportApplyResponse>;
3764
+
1693
3765
  declare const VERSION: string;
1694
3766
  declare function ping(): string;
1695
3767
 
1696
- export { ARTIFACT_TYPES, type AdvanceDeps, type AdvanceInput, type AdvanceRequest, AdvanceRequestSchema, type AdvanceResponse, AdvanceResponseSchema, type Agent, type AgentCopy, AgentCopySchema, type AgentCreate, AgentCreateSchema, type AgentRepo, AgentSchema, type AgentScope, AgentScopeSchema, type AgentUpdate, AgentUpdateSchema, AppError, type AppErrorOptions, type ApproveRequest, ApproveRequestSchema, type ApproveResponse, ApproveResponseSchema, type ArchNote, ArchNoteSchema, type Artifact, ArtifactSchema, type ArtifactType, BIZ_CODE_MESSAGES, BadRequestError, type BizCode, type CheckItem, CheckItemSchema, type Confirmation, ConfirmationSchema, ConflictError, DAG_PHASES, DAG_TRACKS, DEFAULT_PROJECT_KEY, type DagEdge, DagEdgeSchema, type DagInstance, DagInstanceSchema, type DagNode, DagNodePhaseSchema, DagNodeSchema, DagNodeTrackSchema, type DagTemplate, type DagTemplateCopy, DagTemplateCopySchema, type DagTemplateCreate, DagTemplateCreateSchema, type DagTemplateRepo, DagTemplateSchema, type DagTemplateUpdate, DagTemplateUpdateSchema, type Decision, DecisionSchema, ENTRY_ID_REGEX, type EdgePausePoint, EdgePausePointBaseSchema, EdgePausePointSchema, type EnumEntry, EnumEntrySchema, type EnumRegistry, type EnumRegistryCategory, EnumRegistryCategorySchema, type EnumRegistryRepo, EnumRegistrySchema, type EnumRegistryUpdate, EnumRegistryUpdateSchema, HistoryActionSchema, type HistoryEntry, HistoryEntrySchema, type ModelAlias, type ModelAliasCreate, ModelAliasCreateSchema, type ModelAliasRepo, ModelAliasSchema, ModelAliasShapeSchema, type ModelAliasUpdate, ModelAliasUpdateSchema, type ModelAliasWithRefCount, ModelAliasWithRefCountSchema, NODE_ID_PATTERN, NODE_STATUSES, type NodeInfo, NodeInfoSchema, type NodeRecord, NodeRecordSchema, type NodeState, NodeStateSchema, NodeStatusSchema, NotFoundError, OBJECT_ID_HEX, type OmitId, PAUSE_POINT_TYPES, PausePointTypeSchema, type PauseRequest, PauseRequestSchema, type Project, type ProjectCreate, ProjectCreateSchema, type ProjectRepo, ProjectSchema, type ProjectStatus, ProjectStatusSchema, type ProjectUpdate, ProjectUpdateSchema, type PruneResult, type Repo, type ResumeRequest, ResumeRequestSchema, type ReviewSummary, ReviewSummarySchema, SIMING_CODE_REGEX, SIMING_CONFIG_ENV_KEYS, SIMING_CONFIG_KEYS, type SimingClient, type SimingConfig, type SimingConfigKey, SimingConfigSchema, SimingLogLevelSchema, type Skill, type SkillCopy, SkillCopySchema, type SkillCreate, SkillCreateSchema, type SkillRepo, SkillSchema, type SkillScope, SkillScopeSchema, type SkillUpdate, SkillUpdateSchema, TASK_PHASES, TASK_STATUSES, TASK_TYPES, type Task, type TaskContext, TaskContextSchema, type TaskCreateInput, TaskCreateInputSchema, type TaskDocContent, TaskDocContentSchema, type TaskPatch, TaskPhaseSchema, type TaskPublic, TaskPublicSchema, type TaskRepo, TaskSchema, TaskStatusSchema, type TaskSummary, TaskSummarySchema, type TaskType, VERSION, ValidationError, type WithId, advanceTask, approveTask, assertBoundSkillsCompatible, assertModelAliasExists, checkTermination, createAgentRepo, createDagTemplateRepo, createEnumRegistryRepo, createModelAliasRepo, createMongoClient, createProjectRepo, createRepo, createSkillRepo, createTaskRepo, findNextEdge, generateEntryId, generateProjectKey, mkHistory, pauseTask, ping, pruneInstance, renderPrompt, resumeTask, toNodeInfo, toTaskPublic, trackMatchSet, withTransaction };
3768
+ export { AGENT_MAIN_DOC, ARTIFACT_TYPES, AUTH_COLLECTIONS, type AdvanceDeps, type AdvanceInput, type AdvanceRequest, AdvanceRequestSchema, type AdvanceResponse, AdvanceResponseSchema, type Agent, type AgentCopy, AgentCopySchema, type AgentCreate, AgentCreateSchema, type AgentFunction, AgentFunctionSchema, type AgentPayload, AgentPayloadSchema, type AgentRepo, AgentSchema, type AgentScope, AgentScopeSchema, AgentShapeSchema, type AgentUpdate, AgentUpdateSchema, AppError, type AppErrorOptions, type ApproveRequest, ApproveRequestSchema, type ApproveResponse, ApproveResponseSchema, type ArchNote, ArchNoteSchema, type Artifact, ArtifactSchema, type ArtifactType, type AssetListOpts, type AssetSetEnabled, AssetSetEnabledSchema, type AuthAccount, type AuthAccountCreate, AuthAccountCreateSchema, AuthAccountSchema, type AuthSession, type AuthStatus, AuthStatusSchema, type AuthToken, type AuthTokenGenResponse, AuthTokenGenResponseSchema, type AuthTokenKind, AuthTokenSchema, type AuthTokenStatus, AuthTokenStatusSchema, type AuthTokenType, AuthTokenTypeSchema, type AuthWhoami, AuthWhoamiSchema, BIZ_CODE_MESSAGES, BadRequestError, type BizCode, CONTEXT_VIEWS, type CancelRequest, CancelRequestSchema, type CheckItem, CheckItemSchema, type Composition, type CompositionEdge, CompositionEdgeSchema, CompositionSchema, type Confirmation, ConfirmationSchema, ConflictError, type ContextView, ContextViewSchema, type CreateTaskResponse, CreateTaskResponseSchema, DAG_PHASES, DAG_TRACKS, DEFAULT_PROJECT_KEY, type DagEdge, DagEdgeSchema, type DagInstance, type DagInstanceNode, DagInstanceNodeSchema, DagInstanceSchema, type DagNode, DagNodePhaseSchema, DagNodeSchema, DagNodeTrackSchema, type DagTemplate, type DagTemplateCopy, DagTemplateCopySchema, type DagTemplateCreate, DagTemplateCreateSchema, type DagTemplateRepo, DagTemplateSchema, type DagTemplateUpdate, DagTemplateUpdateSchema, type Decision, DecisionSchema, type DependencyAction, DependencyActionSchema, type DependencyCheck, DependencyCheckSchema, type DependencyStatus, DependencyStatusSchema, ENTRY_ID_REGEX, EXPORT_FORMAT_VERSION, type EchoItem, EchoItemSchema, type EdgePausePoint, EdgePausePointBaseSchema, EdgePausePointSchema, type EnumEntry, EnumEntrySchema, type EnumRegistry, type EnumRegistryCategory, EnumRegistryCategorySchema, type EnumRegistryRepo, EnumRegistrySchema, type EnumRegistryUpdate, EnumRegistryUpdateSchema, type ExportBundle, ExportBundleSchema, ForbiddenError, HistoryActionSchema, type HistoryEntry, HistoryEntrySchema, type ImportApplyRequest, ImportApplyRequestSchema, type ImportApplyResponse, ImportApplyResponseSchema, type ImportDecision, ImportDecisionSchema, type ImportPlanRequest, ImportPlanRequestSchema, type ImportPlanResponse, ImportPlanResponseSchema, type LoginInput, LoginSchema, type ModelAlias, type ModelAliasCreate, ModelAliasCreateSchema, type ModelAliasPayload, ModelAliasPayloadSchema, type ModelAliasRepo, ModelAliasSchema, ModelAliasShapeSchema, type ModelAliasUpdate, ModelAliasUpdateSchema, type ModelAliasWithRefCount, ModelAliasWithRefCountSchema, NODE_ID_PATTERN, NODE_PRESET_CODE_PATTERN, NODE_STATUSES, type NodeContentFields, type NodeInfo, NodeInfoSchema, type NodeLibrary, type NodeLibraryRepo, NodeLibrarySchema, type NodeLibraryUpsert, NodeLibraryUpsertSchema, type NodePreset, type NodePresetCopy, NodePresetCopySchema, type NodePresetCreate, NodePresetCreateSchema, type NodePresetListFilter, type NodePresetRepo, NodePresetSchema, NodePresetShapeSchema, type NodePresetUpdate, NodePresetUpdateSchema, type NodeRecord, NodeRecordSchema, type NodeState, NodeStateSchema, NodeStatusSchema, NotFoundError, OBJECT_ID_HEX, type OmitId, PAUSE_POINT_TYPES, type PasswordChange, PasswordChangeSchema, PausePointTypeSchema, type PauseRequest, PauseRequestSchema, type Project, type ProjectCreate, ProjectCreateSchema, type ProjectRepo, ProjectSchema, type ProjectStatus, ProjectStatusSchema, type ProjectUpdate, ProjectUpdateSchema, type PruneResult, REFERENCE_LIMITS, type ReferenceDoc, type Repo, type ResumeRequest, ResumeRequestSchema, type ReviewSummary, ReviewSummarySchema, SIMING_CODE_REGEX, SIMING_CONFIG_ENV_KEYS, SIMING_CONFIG_KEYS, SKILL_MAIN_DOC, type SimingClient, type SimingConfig, type SimingConfigKey, SimingConfigSchema, SimingLogLevelSchema, type Skill, type SkillCopy, SkillCopySchema, type SkillCreate, SkillCreateSchema, type SkillPayload, SkillPayloadSchema, type SkillRepo, SkillSchema, type SkillScope, SkillScopeSchema, SkillShapeSchema, type SkillUpdate, SkillUpdateSchema, type SourcePreset, SourcePresetSchema, TASK_PHASES, TASK_STATUSES, TASK_TYPES, TEMPLATE_CODE_MAX_LENGTH, TEMPLATE_CODE_REGEX, type Task, type TaskBatchAck, TaskBatchAckSchema, type TaskBatchEntry, TaskBatchEntrySchema, type TaskBatchFailure, TaskBatchFailureSchema, type TaskContext, TaskContextSchema, type TaskCreateInput, TaskCreateInputSchema, type TaskDocContent, TaskDocContentSchema, type TaskPatch, TaskPhaseSchema, type TaskProgress, type TaskProgressPublic, TaskProgressPublicSchema, TaskProgressSchema, type TaskPublic, TaskPublicSchema, type TaskRepo, TaskSchema, TaskStatusSchema, type TaskSummary, TaskSummarySchema, type TaskType, type TemplateCandidate, TemplateCandidateSchema, TemplateCodeFieldSchema, type TemplateContentChanges, type TemplateContentDiff, type TemplateContentSource, type TemplatePayload, TemplatePayloadSchema, type TemplateTransferDeps, UnauthorizedError, type UpgradeAction, UpgradeActionSchema, type UpgradeApplyOutcome, type UpgradeApplyRequest, UpgradeApplyRequestSchema, type UpgradeApplyResultItem, type UpgradeDecision, type UpgradeDecisionInput, UpgradeDecisionSchema, type UpgradeNodeStatus, UpgradeNodeStatusSchema, type UpgradePlanItem, type UpgradePlanResult, VERSION, ValidationError, WRITE_ACK_ENTRY_KINDS, type WithId, type WriteAck, type WriteAckEntryKind, WriteAckEntryKindSchema, WriteAckSchema, advanceTask, applyImport, applyUpgradeDecisions, approveTask, assertBoundSkillsCompatible, assertModelAliasExists, assertReferenceAggregateLimit, assertReferencesDeletable, assertUniqueNodeIds, buildImportPlan, buildTemplateCode, buildUpgradePlan, bumpPatch, bumpPatchOrPassthrough, cancelTask, canonicalizeReferencePath, checkTermination, composeExportBundle, computeNodeContentHash, computeUpgradeStatus, createAgentRepo, createAuthAccountRepo, createAuthSessionRepo, createAuthTokenRepo, createDagTemplateRepo, createEnumRegistryRepo, createModelAliasRepo, createMongoClient, createNodeLibraryRepo, createNodePresetRepo, createProjectRepo, createReferencesSchema, createRepo, createSkillRepo, createTaskRepo, decisionKey, diffTemplateContent, enabledNeFalse, escapeRegExpLiteral, excerpt, findDuplicateNodeIds, findNextEdge, findTemplateByName, generateEntryId, generateProjectKey, generateSessionId, generateToken, hasProjectDefault, hashPassword, hashToken, isLegalTemplateCode, mkHistory, normalizeNameToTemplateCode, parseAuthEnabledEnvValue, pauseTask, ping, pruneInstance, renderPrompt, resumeTask, sumReferenceContentChars, taskProgress, toNodeInfo, toTaskPublic, tokenTypeFromValue, trackMatchSet, verifyPassword, withTransaction };