@stmcw1/dacw 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plugin.js ADDED
@@ -0,0 +1,994 @@
1
+ import * as fs from 'fs/promises';
2
+ import * as os from 'os';
3
+ import * as path from 'path';
4
+ import { apply as createEngine } from './index.js';
5
+ const PLUGIN_VERSION = '1.0.0';
6
+ const WRITER_PRESET_ID = 'dacw-writer';
7
+ const REVIEWER_PRESET_ID = 'dacw-reviewer';
8
+ const WORKSPACE_MARKER = '.dacw-workspace';
9
+ const WORKSPACE_MARKER_MANAGED_BY = '@stmcw1/dacw';
10
+ const LEGACY_WORKSPACE_MARKER_MANAGED_BY = '@local/dacw';
11
+ const WORKSPACE_MARKER_CONTENT = `{"managedBy":"${WORKSPACE_MARKER_MANAGED_BY}","version":"${PLUGIN_VERSION}",` + `"note":"DACW resets non-foundation files in this directory every round. Remove this marker to revoke that."}\n`;
12
+ const MAX_TASK_CHARS = 20_000;
13
+ const MAX_TASK_ID_CHARS = 128;
14
+ const MAX_WORKSPACE_ARG_CHARS = 1_024;
15
+ const WRITER_PERSONA = '你是 DACW(防御性智能体编程工作流)的写手。你的唯一输出是符合「输出协议 v2」的 JSON 变更集:' + '不要调用任何工具,不要解释,不要输出 JSON 之外的任何文字。' + '收到任务与当前文件基线后,changed 里必须是【完整文件内容】(严禁 diff/补丁/省略号截断),' + '未提及的文件由环境原样保留。';
16
+ const REVIEWER_PERSONA = '你是 DACW(防御性智能体编程工作流)的审查者。你不写代码、不调用任何工具,只做防御性、安全、' + '边界与需求符合性审查。审查完成后,你必须只输出一个 JSON 对象:' + '{"verdict":"PASS"} 或 {"verdict":"REJECTED","reasons":["问题1","问题2"]}。' + '禁止输出任何其他判定性文字。';
17
+ export const inject = [
18
+ 'tools'
19
+ ];
20
+ export const DEFAULT_PLUGIN_CONFIG = {
21
+ toolName: 'dacw_run',
22
+ workspace: '',
23
+ workspacePolicy: 'guarded',
24
+ maxRounds: 3,
25
+ subagentProvider: 'spawn',
26
+ writerModel: null,
27
+ reviewerModel: null,
28
+ stateDir: '',
29
+ chatTimeoutBaseMs: 120_000,
30
+ chatTimeoutPer10kCharsMs: 20_000,
31
+ chatTimeoutMaxMs: 300_000,
32
+ chatMaxAttempts: 2,
33
+ writerOutputMaxChars: 2_000_000,
34
+ manifestMaxEntries: 400,
35
+ allowInheritedPresets: false,
36
+ enforceChildToolIsolation: true
37
+ };
38
+ function positiveIntOr(value, fallback, warnings, field) {
39
+ if (value === undefined || value === null) return fallback;
40
+ if (typeof value === 'number' && Number.isFinite(value) && value > 0) return Math.floor(value);
41
+ warnings.push(`config.${field} 非法(需要正整数),已回退默认值 ${fallback}`);
42
+ return fallback;
43
+ }
44
+ function nonEmptyStringOr(value, fallback, warnings, field) {
45
+ if (value === undefined || value === null || value === '') return fallback;
46
+ if (typeof value === 'string') return value;
47
+ warnings.push(`config.${field} 非法(需要字符串),已回退默认值`);
48
+ return fallback;
49
+ }
50
+ function normalizeModelConfig(value, warnings, field) {
51
+ if (value === undefined || value === null || value === '') return null;
52
+ if (typeof value === 'string') {
53
+ const text = value.trim();
54
+ if (!text || text.toLowerCase() === 'inherit') return null;
55
+ return text;
56
+ }
57
+ if (typeof value !== 'object' || Array.isArray(value)) {
58
+ warnings.push(`config.${field} 非法(需要字符串或 { provider, model }),已忽略`);
59
+ return null;
60
+ }
61
+ const obj = value;
62
+ const provider = typeof obj.provider === 'string' && obj.provider.trim() ? obj.provider.trim() : undefined;
63
+ const model = typeof obj.model === 'string' && obj.model.trim() ? obj.model.trim() : undefined;
64
+ const reasoningEffort = typeof obj.reasoningEffort === 'string' && obj.reasoningEffort.trim() ? obj.reasoningEffort.trim() : undefined;
65
+ if (!provider && !model) {
66
+ warnings.push(`config.${field} 需要至少提供 model(可只写模型名,由 DSH 已配置模型目录解析 provider),已忽略`);
67
+ return null;
68
+ }
69
+ if (provider && !model) {
70
+ warnings.push(`config.${field} 只有 provider 没有 model,运行时会 fail-closed 报错;请补 model 或删除该字段`);
71
+ return {
72
+ provider,
73
+ ...reasoningEffort ? {
74
+ reasoningEffort
75
+ } : {}
76
+ };
77
+ }
78
+ return {
79
+ ...provider ? {
80
+ provider
81
+ } : {},
82
+ ...model ? {
83
+ model
84
+ } : {},
85
+ ...reasoningEffort ? {
86
+ reasoningEffort
87
+ } : {}
88
+ };
89
+ }
90
+ export function normalizePluginConfig(raw) {
91
+ const warnings = [];
92
+ const input = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
93
+ let toolName = nonEmptyStringOr(input.toolName, DEFAULT_PLUGIN_CONFIG.toolName, warnings, 'toolName');
94
+ if (!/^[a-z][a-z0-9_]*$/.test(toolName)) {
95
+ warnings.push(`config.toolName 非法(需匹配 /^[a-z][a-z0-9_]*$/),已回退默认值 ${DEFAULT_PLUGIN_CONFIG.toolName}`);
96
+ toolName = DEFAULT_PLUGIN_CONFIG.toolName;
97
+ }
98
+ const workspacePolicy = input.workspacePolicy === 'allow' || input.workspacePolicy === 'guarded' ? input.workspacePolicy : (warnings.push(`config.workspacePolicy 只接受 "guarded" 或 "allow",已回退 guarded`), 'guarded');
99
+ const config = {
100
+ toolName,
101
+ workspace: nonEmptyStringOr(input.workspace, DEFAULT_PLUGIN_CONFIG.workspace, warnings, 'workspace'),
102
+ workspacePolicy,
103
+ maxRounds: positiveIntOr(input.maxRounds, DEFAULT_PLUGIN_CONFIG.maxRounds, warnings, 'maxRounds'),
104
+ subagentProvider: nonEmptyStringOr(input.subagentProvider, DEFAULT_PLUGIN_CONFIG.subagentProvider, warnings, 'subagentProvider'),
105
+ writerModel: normalizeModelConfig(input.writerModel, warnings, 'writerModel'),
106
+ reviewerModel: normalizeModelConfig(input.reviewerModel, warnings, 'reviewerModel'),
107
+ stateDir: nonEmptyStringOr(input.stateDir, DEFAULT_PLUGIN_CONFIG.stateDir, warnings, 'stateDir'),
108
+ chatTimeoutBaseMs: positiveIntOr(input.chatTimeoutBaseMs, DEFAULT_PLUGIN_CONFIG.chatTimeoutBaseMs, warnings, 'chatTimeoutBaseMs'),
109
+ chatTimeoutPer10kCharsMs: positiveIntOr(input.chatTimeoutPer10kCharsMs, DEFAULT_PLUGIN_CONFIG.chatTimeoutPer10kCharsMs, warnings, 'chatTimeoutPer10kCharsMs'),
110
+ chatTimeoutMaxMs: positiveIntOr(input.chatTimeoutMaxMs, DEFAULT_PLUGIN_CONFIG.chatTimeoutMaxMs, warnings, 'chatTimeoutMaxMs'),
111
+ chatMaxAttempts: positiveIntOr(input.chatMaxAttempts, DEFAULT_PLUGIN_CONFIG.chatMaxAttempts, warnings, 'chatMaxAttempts'),
112
+ writerOutputMaxChars: positiveIntOr(input.writerOutputMaxChars, DEFAULT_PLUGIN_CONFIG.writerOutputMaxChars, warnings, 'writerOutputMaxChars'),
113
+ manifestMaxEntries: positiveIntOr(input.manifestMaxEntries, DEFAULT_PLUGIN_CONFIG.manifestMaxEntries, warnings, 'manifestMaxEntries'),
114
+ allowInheritedPresets: input.allowInheritedPresets === true,
115
+ enforceChildToolIsolation: input.enforceChildToolIsolation !== false
116
+ };
117
+ if (config.chatTimeoutMaxMs < config.chatTimeoutBaseMs) {
118
+ warnings.push('config.chatTimeoutMaxMs 小于 chatTimeoutBaseMs,已把 chatTimeoutMaxMs 提升到 base');
119
+ config.chatTimeoutMaxMs = config.chatTimeoutBaseMs;
120
+ }
121
+ if (config.allowInheritedPresets) {
122
+ warnings.push('config.allowInheritedPresets=true:子代理将继承父会话工具,写手可能获得执行通道(DACW 核心安全保证失效)');
123
+ }
124
+ if (!config.enforceChildToolIsolation) {
125
+ warnings.push('config.enforceChildToolIsolation=false:不再强制剥离子代理的宿主全局工具');
126
+ }
127
+ return {
128
+ config,
129
+ warnings
130
+ };
131
+ }
132
+ export function extractTextBlocks(output) {
133
+ if (!Array.isArray(output)) return '';
134
+ const texts = [];
135
+ for (const block of output){
136
+ if (!block || typeof block !== 'object') continue;
137
+ const record = block;
138
+ if (record.type === 'text' && typeof record.text === 'string') texts.push(record.text);
139
+ }
140
+ return texts.join('\n').trim();
141
+ }
142
+ function isAbortLike(error) {
143
+ if (!error || typeof error !== 'object') return false;
144
+ const record = error;
145
+ return record.isAbort === true || record.name === 'AbortError';
146
+ }
147
+ function abortError() {
148
+ const error = new Error('DACW 调用已取消');
149
+ error.isAbort = true;
150
+ return error;
151
+ }
152
+ export function buildActivationSpec(input) {
153
+ const { config, role, text } = input;
154
+ const request = {
155
+ prompt: [
156
+ {
157
+ type: 'text',
158
+ text
159
+ }
160
+ ],
161
+ parent: input.parent
162
+ };
163
+ if (typeof input.cwd === 'string' && input.cwd) request.cwd = input.cwd;
164
+ if (typeof input.presetId === 'string' && input.presetId) request.agentPreset = input.presetId;
165
+ if (input.model) {
166
+ request.agentOptions = {
167
+ provider: input.model.provider,
168
+ model: input.model.model,
169
+ ...input.model.reasoningEffort ? {
170
+ reasoningEffort: input.model.reasoningEffort
171
+ } : {}
172
+ };
173
+ }
174
+ return {
175
+ provider: config.subagentProvider,
176
+ label: `dacw-${role}`,
177
+ request,
178
+ signal: input.signal,
179
+ delivery: 'caller'
180
+ };
181
+ }
182
+ function presetDefinition(presetId, name, description, order, persona) {
183
+ return {
184
+ id: presetId,
185
+ name,
186
+ description,
187
+ order,
188
+ plugins: [
189
+ {
190
+ id: 'persona',
191
+ name: '@deepseek-ai/dsh-persona',
192
+ config: {
193
+ prefix: persona,
194
+ complete: true,
195
+ includeRuntimeContext: false
196
+ }
197
+ }
198
+ ]
199
+ };
200
+ }
201
+ function errorMessage(error) {
202
+ if (error instanceof Error) return error.message;
203
+ return String(error);
204
+ }
205
+ function makeLogger(ctx) {
206
+ let sink = null;
207
+ try {
208
+ const logger = ctx.logger;
209
+ if (typeof logger === 'function') sink = logger('dacw');
210
+ else if (logger) sink = logger;
211
+ } catch {}
212
+ const write = (level, message)=>{
213
+ try {
214
+ if (sink && typeof sink[level] === 'function') sink[level](message);
215
+ else if (level !== 'info') console.warn(`[dacw] ${message}`);
216
+ } catch {}
217
+ };
218
+ return {
219
+ info: (m)=>write('info', m),
220
+ warn: (m)=>write('warn', m),
221
+ error: (m)=>write('error', m)
222
+ };
223
+ }
224
+ export function parseModelSpec(spec) {
225
+ const withEffort = (parsed, reasoningEffort)=>reasoningEffort ? {
226
+ ...parsed,
227
+ reasoningEffort
228
+ } : parsed;
229
+ if (spec === null) return {
230
+ mode: 'inherit'
231
+ };
232
+ if (typeof spec === 'string') {
233
+ const text = spec.trim();
234
+ if (!text || text.toLowerCase() === 'inherit') return {
235
+ mode: 'inherit'
236
+ };
237
+ const slash = text.indexOf('/');
238
+ if (slash > 0 && slash < text.length - 1) {
239
+ return {
240
+ mode: 'explicit',
241
+ provider: text.slice(0, slash).trim(),
242
+ model: text.slice(slash + 1).trim()
243
+ };
244
+ }
245
+ return {
246
+ mode: 'model-only',
247
+ model: text
248
+ };
249
+ }
250
+ const provider = spec.provider && spec.provider.trim() ? spec.provider.trim() : undefined;
251
+ const model = spec.model && spec.model.trim() ? spec.model.trim() : undefined;
252
+ const reasoningEffort = spec.reasoningEffort && spec.reasoningEffort.trim() ? spec.reasoningEffort.trim() : undefined;
253
+ if (provider && model) return withEffort({
254
+ mode: 'explicit',
255
+ provider,
256
+ model
257
+ }, reasoningEffort);
258
+ if (model) return withEffort({
259
+ mode: 'model-only',
260
+ model
261
+ }, reasoningEffort);
262
+ return {
263
+ mode: 'invalid',
264
+ reason: `缺少 model(provider="${provider ?? ''}");可写成 "provider/model"、"model",或 { model, provider? }`
265
+ };
266
+ }
267
+ export function formatModelLabel(provider, model, reasoningEffort) {
268
+ return `${provider}/${model}${reasoningEffort ? `(reasoning=${reasoningEffort})` : ''}`;
269
+ }
270
+ export function formatInheritLabel(dshDefault) {
271
+ if (dshDefault && typeof dshDefault.provider === 'string' && dshDefault.provider && typeof dshDefault.model === 'string' && dshDefault.model) {
272
+ return `继承父会话路由(DSH 默认: ${dshDefault.provider}/${dshDefault.model})`;
273
+ }
274
+ return '继承父会话路由';
275
+ }
276
+ export function matchModelInCatalogue(modelId, catalogue) {
277
+ const target = modelId.trim().toLowerCase();
278
+ if (!target) return {
279
+ error: '模型名为空'
280
+ };
281
+ const idMatches = catalogue.filter((entry)=>entry.models.some((model)=>model.id.toLowerCase() === target));
282
+ if (idMatches.length === 1) return {
283
+ provider: idMatches[0].provider,
284
+ matchedBy: 'id'
285
+ };
286
+ if (idMatches.length > 1) {
287
+ return {
288
+ error: `模型 "${modelId}" 在多个 provider 的目录中同名:${idMatches.map((entry)=>entry.provider).join(', ')};请写成 "provider/model"`
289
+ };
290
+ }
291
+ const nameMatches = catalogue.filter((entry)=>entry.models.some((model)=>(model.name ?? '').toLowerCase() === target));
292
+ if (nameMatches.length === 1) return {
293
+ provider: nameMatches[0].provider,
294
+ matchedBy: 'name'
295
+ };
296
+ if (nameMatches.length > 1) {
297
+ return {
298
+ error: `模型显示名 "${modelId}" 在多个 provider 的目录中同名:${nameMatches.map((entry)=>entry.provider).join(', ')};请写成 "provider/model"`
299
+ };
300
+ }
301
+ const known = catalogue.flatMap((entry)=>entry.models.map((model)=>`${entry.provider}/${model.id}`));
302
+ const sample = known.slice(0, 12).join(', ');
303
+ return {
304
+ error: `在 DSH 已配置模型目录中找不到模型 "${modelId}"` + (known.length > 0 ? `(可用示例:${sample}${known.length > 12 ? ' …' : ''})` : '(目录为空)')
305
+ };
306
+ }
307
+ function withTimeout(promise, ms, label) {
308
+ return new Promise((resolve, reject)=>{
309
+ const timer = setTimeout(()=>reject(new Error(label)), ms);
310
+ promise.then((value)=>{
311
+ clearTimeout(timer);
312
+ resolve(value);
313
+ }, (error)=>{
314
+ clearTimeout(timer);
315
+ reject(error);
316
+ });
317
+ });
318
+ }
319
+ function readConfiguredProviders(ctx) {
320
+ try {
321
+ const llm = ctx.get('llm');
322
+ if (!llm || typeof llm.listProviders !== 'function') return null;
323
+ const list = llm.listProviders();
324
+ if (!Array.isArray(list)) return null;
325
+ return list.map((provider)=>typeof provider === 'string' ? provider : provider && (provider.id ?? provider.provider)).filter((id)=>typeof id === 'string' && id.length > 0);
326
+ } catch {
327
+ return null;
328
+ }
329
+ }
330
+ async function readModelCatalogue(ctx, logger, timeoutMs = 2500) {
331
+ let llm = null;
332
+ try {
333
+ llm = ctx.get('llm');
334
+ } catch {
335
+ llm = null;
336
+ }
337
+ const providers = readConfiguredProviders(ctx);
338
+ if (!llm || providers === null) return [];
339
+ const entries = [];
340
+ for (const provider of providers){
341
+ let models = [];
342
+ if (typeof llm.listModels === 'function') {
343
+ try {
344
+ const list = await withTimeout(Promise.resolve(llm.listModels(provider)), timeoutMs, `读取 ${provider} 模型目录超时`);
345
+ models = Array.isArray(list) ? list : [];
346
+ } catch (error) {
347
+ logger.warn(`DACW: 读取 provider "${provider}" 的模型目录失败(${errorMessage(error)}),按无目录处理`);
348
+ }
349
+ }
350
+ entries.push({
351
+ provider,
352
+ models: models.map((model)=>({
353
+ id: typeof model === 'string' ? model : String(model && (model.id ?? model.model ?? '')),
354
+ name: model && typeof model.name === 'string' ? model.name : undefined
355
+ })).filter((model)=>model.id)
356
+ });
357
+ }
358
+ return entries;
359
+ }
360
+ export function readDshDefaultModel(ctx) {
361
+ try {
362
+ const service = ctx.get('agentDefaultModel');
363
+ if (!service || typeof service.currentSelection !== 'function') return null;
364
+ const selection = service.currentSelection();
365
+ if (!selection || typeof selection !== 'object') return null;
366
+ return {
367
+ provider: typeof selection.provider === 'string' ? selection.provider : undefined,
368
+ model: typeof selection.model === 'string' ? selection.model : undefined,
369
+ reasoningEffort: typeof selection.reasoningEffort === 'string' ? selection.reasoningEffort : undefined
370
+ };
371
+ } catch {
372
+ return null;
373
+ }
374
+ }
375
+ async function resolveRoleModel(ctx, spec, role, logger) {
376
+ const field = role === 'writer' ? 'writerModel' : 'reviewerModel';
377
+ const parsed = parseModelSpec(spec);
378
+ if (parsed.mode === 'inherit') {
379
+ return {
380
+ agentOptions: null,
381
+ label: formatInheritLabel(readDshDefaultModel(ctx)),
382
+ source: 'inherit'
383
+ };
384
+ }
385
+ if (parsed.mode === 'invalid') {
386
+ throw new Error(`[DACW] config.${field} 非法:${parsed.reason}`);
387
+ }
388
+ if (parsed.mode === 'model-only') {
389
+ logger.info(`DACW: config.${field} 只给了模型名 "${parsed.model}",正在读取 DSH 已配置模型目录解析 provider…`);
390
+ const catalogue = await readModelCatalogue(ctx, logger);
391
+ if (catalogue.length === 0) {
392
+ throw new Error(`[DACW] config.${field} 只给了模型名 "${parsed.model}",但无法读取 DSH 已配置模型目录` + `(llm 服务不可用或没有已注册 provider);请写成 "provider/model" 形式。`);
393
+ }
394
+ const match = matchModelInCatalogue(parsed.model, catalogue);
395
+ if ('error' in match) throw new Error(`[DACW] config.${field}: ${match.error}`);
396
+ return {
397
+ agentOptions: {
398
+ provider: match.provider,
399
+ model: parsed.model,
400
+ ...parsed.reasoningEffort ? {
401
+ reasoningEffort: parsed.reasoningEffort
402
+ } : {}
403
+ },
404
+ label: formatModelLabel(match.provider, parsed.model, parsed.reasoningEffort) + '(插件配置)',
405
+ source: 'config'
406
+ };
407
+ }
408
+ const providers = readConfiguredProviders(ctx);
409
+ if (providers && !providers.includes(parsed.provider)) {
410
+ throw new Error(`[DACW] config.${field} 的 provider "${parsed.provider}" 未在 DSH 中注册` + `(已配置:${providers.length > 0 ? providers.join(', ') : '无'});` + `请检查 config,或改用纯模型名形式 "model" 让插件从 DSH 目录解析。`);
411
+ }
412
+ return {
413
+ agentOptions: {
414
+ provider: parsed.provider,
415
+ model: parsed.model,
416
+ ...parsed.reasoningEffort ? {
417
+ reasoningEffort: parsed.reasoningEffort
418
+ } : {}
419
+ },
420
+ label: formatModelLabel(parsed.provider, parsed.model, parsed.reasoningEffort) + '(插件配置)',
421
+ source: 'config'
422
+ };
423
+ }
424
+ function restrictChildTools(ctx, agent, isolation, logger) {
425
+ const fail = (reason)=>{
426
+ isolation.failures += 1;
427
+ isolation.lastError = reason;
428
+ logger.error(`DACW: 子代理工具隔离失败:${reason}`);
429
+ throw new Error(`[DACW] 子代理工具隔离失败:${reason}`);
430
+ };
431
+ if (!agent || !agent.ctx || !agent.ctx.tools || typeof agent.ctx.tools.restrict !== 'function') {
432
+ fail('子代理上下文缺少 tools.restrict');
433
+ }
434
+ const childId = String(agent.id);
435
+ let dispose = null;
436
+ let strategy = '';
437
+ try {
438
+ dispose = agent.ctx.tools.restrict({
439
+ allow: []
440
+ });
441
+ strategy = 'allow:[]';
442
+ } catch {
443
+ let names = [];
444
+ try {
445
+ if (typeof ctx.tools.schemas !== 'function') fail('无法枚举宿主全局工具(ctx.tools.schemas 缺失),无法安全回退');
446
+ names = ctx.tools.schemas().map((schema)=>schema && schema.name).filter((name)=>typeof name === 'string' && name);
447
+ } catch (error) {
448
+ fail(`读取宿主全局工具列表失败:${errorMessage(error)}`);
449
+ }
450
+ if (names.length === 0) {
451
+ dispose = null;
452
+ strategy = 'no-global-tools';
453
+ } else {
454
+ try {
455
+ dispose = agent.ctx.tools.restrict({
456
+ deny: names
457
+ });
458
+ strategy = `deny:${names.join(',')}`;
459
+ } catch (error) {
460
+ fail(`ctx.tools.restrict 执行失败:${errorMessage(error)}`);
461
+ }
462
+ }
463
+ }
464
+ try {
465
+ if (typeof agent.ctx.tools.schemas === 'function') {
466
+ const visible = agent.ctx.tools.schemas(agent);
467
+ if (Array.isArray(visible) && visible.length > 0) {
468
+ const names = visible.map((schema)=>schema && schema.name).filter(Boolean).join(', ');
469
+ fail(`隔离后子代理仍可见 ${visible.length} 个工具(${names})`);
470
+ }
471
+ }
472
+ } catch (error) {
473
+ if (error instanceof Error && error.message.startsWith('[DACW]')) throw error;
474
+ fail(`隔离生效校验失败:${errorMessage(error)}`);
475
+ }
476
+ if (typeof dispose === 'function') isolation.disposers.set(childId, dispose);
477
+ isolation.restricted.add(childId);
478
+ isolation.applied += 1;
479
+ logger.info(`DACW: 子代理 ${childId} 工具隔离已生效(策略 ${strategy},隔离后可见工具 0 个)`);
480
+ }
481
+ async function runSubagentChat(options) {
482
+ const { subagents, config, presets, isolation, agent, workspaceDir, signal, role, text, dacwChildren, logger, roleModel } = options;
483
+ const presetId = presets.ready ? role === 'writer' ? WRITER_PRESET_ID : REVIEWER_PRESET_ID : null;
484
+ if (signal && signal.aborted) throw abortError();
485
+ const spec = buildActivationSpec({
486
+ config,
487
+ role,
488
+ text,
489
+ parent: agent,
490
+ cwd: workspaceDir,
491
+ presetId,
492
+ signal,
493
+ model: roleModel.agentOptions
494
+ });
495
+ let activation;
496
+ try {
497
+ activation = await subagents.startActivation(spec);
498
+ } catch (error) {
499
+ if (signal && signal.aborted || isAbortLike(error)) throw abortError();
500
+ throw new Error(`[DACW] ${role} 子代理启动失败:${errorMessage(error)}`);
501
+ }
502
+ const childId = activation && activation.childId ? String(activation.childId) : '';
503
+ if (config.enforceChildToolIsolation && presets.ready && childId && !isolation.restricted.has(childId)) {
504
+ try {
505
+ if (activation && typeof activation.dispose === 'function') await activation.dispose();
506
+ } catch {}
507
+ throw new Error(`[DACW] 子代理 ${childId} 的工具隔离未生效(${isolation.lastError || '未知原因'}):` + `拒绝在写手/审查者可能继承宿主工具的情况下运行。可修复宿主环境,或在明确接受风险后设置 config.allowInheritedPresets / enforceChildToolIsolation=false。`);
508
+ }
509
+ if (childId) dacwChildren.add(childId);
510
+ let abortListener = null;
511
+ const resultPromise = activation && activation.result;
512
+ if (resultPromise && typeof resultPromise.catch === 'function') resultPromise.catch(()=>{});
513
+ const abortPromise = signal ? new Promise((_resolve, reject)=>{
514
+ abortListener = ()=>{
515
+ reject(abortError());
516
+ try {
517
+ if (childId && typeof subagents.interrupt === 'function') {
518
+ subagents.interrupt(childId, {
519
+ kind: 'ancestor',
520
+ agent
521
+ });
522
+ }
523
+ } catch {}
524
+ };
525
+ if (signal.aborted) abortListener();
526
+ else signal.addEventListener('abort', abortListener, {
527
+ once: true
528
+ });
529
+ }) : null;
530
+ try {
531
+ const result = abortPromise ? await Promise.race([
532
+ resultPromise,
533
+ abortPromise
534
+ ]) : await resultPromise;
535
+ const stopReason = result && result.stopReason;
536
+ if (stopReason && stopReason !== 'completed') {
537
+ const diagnostic = result && result.diagnostic ? `;诊断:${result.diagnostic}` : '';
538
+ throw new Error(`[DACW] ${role} 子代理未正常完成(stopReason=${stopReason}${diagnostic})`);
539
+ }
540
+ const output = extractTextBlocks(result && result.output);
541
+ if (!output) throw new Error(`[DACW] ${role} 子代理返回空文本`);
542
+ return output;
543
+ } catch (error) {
544
+ if (signal && signal.aborted || isAbortLike(error)) throw abortError();
545
+ throw error;
546
+ } finally{
547
+ if (signal && abortListener) signal.removeEventListener('abort', abortListener);
548
+ try {
549
+ if (activation && typeof activation.dispose === 'function') await activation.dispose();
550
+ } catch {}
551
+ if (childId) dacwChildren.delete(childId);
552
+ }
553
+ }
554
+ const PROTECTED_WORKSPACE_ENTRIES = new Set([
555
+ WORKSPACE_MARKER,
556
+ 'node_modules',
557
+ '.git'
558
+ ]);
559
+ export function isValidWorkspaceMarker(content) {
560
+ if (typeof content !== 'string' || content.trim() === '') return false;
561
+ try {
562
+ const parsed = JSON.parse(content);
563
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return false;
564
+ const managedBy = parsed.managedBy;
565
+ return managedBy === WORKSPACE_MARKER_MANAGED_BY || managedBy === LEGACY_WORKSPACE_MARKER_MANAGED_BY;
566
+ } catch {
567
+ return false;
568
+ }
569
+ }
570
+ function isSameOrInside(parent, child) {
571
+ const relative = path.relative(parent, child);
572
+ return relative === '' || !relative.startsWith('..') && !path.isAbsolute(relative);
573
+ }
574
+ function forbiddenDirectoryReason(directory) {
575
+ const parsed = path.parse(directory);
576
+ if (directory === parsed.root) return '文件系统根目录';
577
+ const home = os.homedir();
578
+ if (home && (isSameOrInside(directory, home) || isSameOrInside(home, directory))) {
579
+ if (directory === home) return '用户主目录';
580
+ if (isSameOrInside(directory, home)) return '用户主目录的祖先目录';
581
+ }
582
+ for (const [label, envName] of [
583
+ [
584
+ 'DSH_HOME',
585
+ 'DSH_HOME'
586
+ ],
587
+ [
588
+ 'DSH profile 目录',
589
+ 'DSH_PROFILE_DIR'
590
+ ]
591
+ ]){
592
+ const value = process.env[envName];
593
+ if (!value) continue;
594
+ if (isSameOrInside(directory, value) || isSameOrInside(value, directory)) return label;
595
+ }
596
+ return null;
597
+ }
598
+ export async function prepareWorkspace(baseDir, requested, policy) {
599
+ const lexical = path.resolve(baseDir, requested && requested.trim() ? requested : '.');
600
+ const lexicalReason = forbiddenDirectoryReason(lexical);
601
+ if (lexicalReason) throw new Error(`[DACW 安全拦截] 拒绝把${lexicalReason}作为工作区:${lexical}`);
602
+ await fs.mkdir(lexical, {
603
+ recursive: true
604
+ });
605
+ const directory = await fs.realpath(lexical);
606
+ const realReason = forbiddenDirectoryReason(directory);
607
+ if (realReason) throw new Error(`[DACW 安全拦截] 拒绝把${realReason}作为工作区:${directory}(realpath)`);
608
+ const entries = await fs.readdir(directory, {
609
+ withFileTypes: true
610
+ });
611
+ const markerEntry = entries.find((entry)=>entry.name === WORKSPACE_MARKER);
612
+ let hasMarker = false;
613
+ const markerPath = path.join(directory, WORKSPACE_MARKER);
614
+ if (markerEntry) {
615
+ if (!markerEntry.isFile()) {
616
+ throw new Error(`[DACW 安全拦截] 工作区的 ${WORKSPACE_MARKER} 不是普通文件:${directory}`);
617
+ }
618
+ const content = await fs.readFile(markerPath, 'utf-8').catch(()=>'');
619
+ if (!isValidWorkspaceMarker(content)) {
620
+ throw new Error(`[DACW 安全拦截] 工作区存在 ${WORKSPACE_MARKER},但不是本插件写入的标记(managedBy 不匹配):${directory}。` + `为避免误删该目录中的文件,DACW 拒绝运行;请换一个新目录,或确认后手动删除该标记文件。`);
621
+ }
622
+ hasMarker = true;
623
+ }
624
+ if (policy === 'guarded' && !hasMarker) {
625
+ const foreign = entries.filter((entry)=>!PROTECTED_WORKSPACE_ENTRIES.has(entry.name));
626
+ if (foreign.length > 0) {
627
+ throw new Error(`[DACW 安全拦截] 工作区不是空目录,也没有合法的 ${WORKSPACE_MARKER} 标记:${directory}。` + `DACW 每轮会把工作区内容重置为产出文件集(仅保留 package.json 等地基文件与 .git/node_modules),` + `为避免误删,请指向新的空目录,或显式把 config.workspacePolicy 设为 "allow"。`);
628
+ }
629
+ }
630
+ if (!hasMarker) await fs.writeFile(markerPath, WORKSPACE_MARKER_CONTENT, 'utf-8');
631
+ return directory;
632
+ }
633
+ function tailLogs(logs, maxLines, maxChars) {
634
+ const lines = logs.length > maxLines ? logs.slice(logs.length - maxLines) : logs.slice();
635
+ let total = 0;
636
+ const kept = [];
637
+ for(let i = lines.length - 1; i >= 0; i -= 1){
638
+ const line = lines[i];
639
+ if (total + line.length > maxChars && kept.length > 0) break;
640
+ kept.unshift(line);
641
+ total += line.length;
642
+ }
643
+ if (kept.length < logs.length) kept.unshift(`...(已省略前 ${logs.length - kept.length} 行日志)`);
644
+ return kept;
645
+ }
646
+ function renderToolResultText(value) {
647
+ const lines = [];
648
+ lines.push(`DACW 结果:${value.success ? '机器闸门通过' : '未通过'}`);
649
+ lines.push(`状态:${value.status}${value.status === 'NEED_HUMAN' ? '(需要人工终审,未经确认不要合入)' : ''}`);
650
+ lines.push(`工作区:${value.workspace}`);
651
+ if (value.models && typeof value.models.writer === 'string' && typeof value.models.reviewer === 'string') {
652
+ lines.push(`模型:✍️ 写手 ${value.models.writer} | 🔍 审查者 ${value.models.reviewer}`);
653
+ }
654
+ if (typeof value.round === 'number' && value.round > 0) lines.push(`轮次:${value.round}`);
655
+ if (Array.isArray(value.files) && value.files.length > 0) {
656
+ lines.push(`文件(${value.files.length}):`);
657
+ for (const file of value.files.slice(0, 200))lines.push(` - ${file}`);
658
+ if (value.files.length > 200) lines.push(` ...(其余 ${value.files.length - 200} 个文件略)`);
659
+ }
660
+ lines.push('');
661
+ lines.push(`说明:${value.message}`);
662
+ if (Array.isArray(value.logs) && value.logs.length > 0) {
663
+ lines.push('');
664
+ lines.push('运行日志(尾部):');
665
+ for (const line of value.logs)lines.push(` ${line}`);
666
+ }
667
+ return lines.join('\n');
668
+ }
669
+ const TOOL_DESCRIPTION = '运行 DACW(防御性智能体编程工作流)闭环:写手子代理按增量协议产出代码变更 → 确定性运行机执行项目自带测试 → ' + '独立审查者子代理审计全量文件并给出 JSON 裁决 → 通过后停在人工闸门(NEED_HUMAN),绝不自动合入。' + '当需要"让模型写代码、让真实测试验证、让独立审查者把关、最后人工确认"时使用本工具。' + '注意:DACW 每轮都会把工作区内容重置为产出文件集(仅保留 package.json 等地基文件与 .git/node_modules),' + '因此必须指向专用空目录(工具会写入 .dacw-workspace 标记);不要在存放重要文件的目录上运行。' + '模型调用发生在独立子代理会话里,不污染当前会话;子代理在创建时被剥除全部宿主工具。' + '写手/审查者可分别配置模型:支持 "provider/model"、纯 "model"(按 DSH 已配置模型目录自动解析 provider)或 inherit;' + '运行日志首行与结果 models 字段显示实际生效的写手/审查者模型。';
670
+ export function apply(ctx, rawConfig) {
671
+ const { config, warnings } = normalizePluginConfig(rawConfig);
672
+ const logger = makeLogger(ctx);
673
+ for (const warning of warnings)logger.warn(`DACW: ${warning}`);
674
+ const presets = {
675
+ ready: false,
676
+ reason: '尚未注册',
677
+ disposers: []
678
+ };
679
+ const agentPresets = (()=>{
680
+ try {
681
+ return ctx.get('agentPresets');
682
+ } catch {
683
+ return undefined;
684
+ }
685
+ })();
686
+ if (agentPresets && typeof agentPresets.register === 'function') {
687
+ ctx.effect(()=>{
688
+ let disposed = false;
689
+ void (async ()=>{
690
+ try {
691
+ const definitions = [
692
+ presetDefinition(WRITER_PRESET_ID, 'DACW Writer', 'DACW 写手子代理:只输出增量 JSON 变更集,创建时剥除全部宿主工具。', 91, WRITER_PERSONA),
693
+ presetDefinition(REVIEWER_PRESET_ID, 'DACW Reviewer', 'DACW 审查者子代理:只输出 JSON 裁决,创建时剥除全部宿主工具。', 92, REVIEWER_PERSONA)
694
+ ];
695
+ for (const definition of definitions){
696
+ const dispose = await agentPresets.register(definition);
697
+ if (disposed) {
698
+ try {
699
+ await dispose();
700
+ } catch {}
701
+ continue;
702
+ }
703
+ if (typeof dispose === 'function') presets.disposers.push(dispose);
704
+ if (typeof agentPresets.resolve === 'function') {
705
+ const detail = await agentPresets.resolve(definition.id).catch(()=>null);
706
+ if (detail && typeof detail.broken === 'string' && detail.broken) {
707
+ throw new Error(`${definition.id} 激活失败:${detail.broken}`);
708
+ }
709
+ }
710
+ }
711
+ presets.ready = true;
712
+ presets.reason = '';
713
+ logger.info('DACW: 写手/审查者子代理 preset 已注册');
714
+ } catch (error) {
715
+ presets.ready = false;
716
+ presets.reason = errorMessage(error);
717
+ logger.error(`DACW: 子代理 preset 注册失败:${presets.reason}`);
718
+ }
719
+ })();
720
+ return ()=>{
721
+ disposed = true;
722
+ for (const dispose of presets.disposers.splice(0)){
723
+ try {
724
+ void Promise.resolve(dispose()).catch(()=>{});
725
+ } catch {}
726
+ }
727
+ };
728
+ });
729
+ } else {
730
+ presets.reason = '宿主未提供 agentPresets 服务';
731
+ logger.warn('DACW: 宿主未提供 agentPresets 服务,无法注册写手/审查者 preset');
732
+ }
733
+ const isolation = {
734
+ enabled: config.enforceChildToolIsolation,
735
+ restricted: new Set(),
736
+ disposers: new Map(),
737
+ applied: 0,
738
+ failures: 0,
739
+ lastError: ''
740
+ };
741
+ const composedPresetOf = (agent)=>{
742
+ try {
743
+ if (agentPresets && typeof agentPresets.composedPreset === 'function' && agent && agent.ctx) {
744
+ return agentPresets.composedPreset(agent.ctx);
745
+ }
746
+ } catch {}
747
+ return undefined;
748
+ };
749
+ const isDacwPreset = (preset)=>preset === WRITER_PRESET_ID || preset === REVIEWER_PRESET_ID;
750
+ if (config.enforceChildToolIsolation) {
751
+ ctx.effect(()=>ctx.on('agent/created', (payload)=>{
752
+ const agent = payload && payload.agent ? payload.agent : null;
753
+ if (!agent) return;
754
+ if (!isDacwPreset(composedPresetOf(agent))) return;
755
+ restrictChildTools(ctx, agent, isolation, logger);
756
+ }));
757
+ ctx.effect(()=>ctx.on('agent/disposed', (payload)=>{
758
+ const agent = payload && payload.agent ? payload.agent : null;
759
+ if (!agent) return;
760
+ const childId = String(agent.id);
761
+ const dispose = isolation.disposers.get(childId);
762
+ if (dispose) {
763
+ try {
764
+ dispose();
765
+ } catch {}
766
+ isolation.disposers.delete(childId);
767
+ }
768
+ isolation.restricted.delete(childId);
769
+ }));
770
+ }
771
+ const dacwChildren = new Set();
772
+ const isDacwChild = (agent)=>{
773
+ if (!agent) return false;
774
+ const id = String(agent.id ?? '');
775
+ if (id && (dacwChildren.has(id) || isolation.restricted.has(id))) return true;
776
+ return isDacwPreset(composedPresetOf(agent));
777
+ };
778
+ const callerWorkingDirectory = async (agent, signal)=>{
779
+ const workingDirectory = (()=>{
780
+ try {
781
+ return ctx.get('workingDirectory');
782
+ } catch {
783
+ return undefined;
784
+ }
785
+ })();
786
+ if (workingDirectory && typeof workingDirectory.ensure === 'function') {
787
+ try {
788
+ const directory = await workingDirectory.ensure(agent, signal);
789
+ if (typeof directory === 'string' && directory) return directory;
790
+ } catch {}
791
+ }
792
+ return process.cwd();
793
+ };
794
+ const toolDefinition = {
795
+ name: config.toolName,
796
+ description: TOOL_DESCRIPTION,
797
+ parameters: {
798
+ type: 'object',
799
+ properties: {
800
+ task: {
801
+ type: 'string',
802
+ description: '要实现/修改的需求描述(自然语言,越具体越好)。'
803
+ },
804
+ workspace: {
805
+ type: 'string',
806
+ description: 'DACW 专用工作区目录;绝对路径,或相对当前会话工作目录。省略则用配置的 workspace,再退回当前会话工作目录。'
807
+ },
808
+ task_id: {
809
+ type: 'string',
810
+ description: '可选任务 ID,用于状态/审计记录文件名;省略则自动生成。'
811
+ }
812
+ },
813
+ required: [
814
+ 'task'
815
+ ],
816
+ additionalProperties: false
817
+ },
818
+ output: {
819
+ schema: {
820
+ type: 'object',
821
+ properties: {
822
+ success: {
823
+ type: 'boolean'
824
+ },
825
+ status: {
826
+ type: 'string'
827
+ },
828
+ message: {
829
+ type: 'string'
830
+ },
831
+ workspace: {
832
+ type: 'string'
833
+ },
834
+ models: {
835
+ type: 'object',
836
+ properties: {
837
+ writer: {
838
+ type: 'string'
839
+ },
840
+ reviewer: {
841
+ type: 'string'
842
+ }
843
+ },
844
+ required: [
845
+ 'writer',
846
+ 'reviewer'
847
+ ],
848
+ additionalProperties: false
849
+ },
850
+ round: {
851
+ type: 'integer'
852
+ },
853
+ files: {
854
+ type: 'array',
855
+ items: {
856
+ type: 'string'
857
+ }
858
+ },
859
+ logs: {
860
+ type: 'array',
861
+ items: {
862
+ type: 'string'
863
+ }
864
+ },
865
+ elapsed_ms: {
866
+ type: 'integer'
867
+ }
868
+ },
869
+ required: [
870
+ 'success',
871
+ 'status',
872
+ 'message',
873
+ 'workspace',
874
+ 'models',
875
+ 'round',
876
+ 'files',
877
+ 'logs',
878
+ 'elapsed_ms'
879
+ ],
880
+ additionalProperties: false
881
+ },
882
+ render: (_args, value)=>[
883
+ {
884
+ type: 'text',
885
+ text: renderToolResultText(value)
886
+ }
887
+ ]
888
+ },
889
+ async execute (rawArgs, exec) {
890
+ const startedAt = Date.now();
891
+ const args = rawArgs && typeof rawArgs === 'object' ? rawArgs : {};
892
+ const task = typeof args.task === 'string' ? args.task.trim() : '';
893
+ if (!task) throw new Error('[DACW] 参数 task 必须是非空字符串');
894
+ if (task.length > MAX_TASK_CHARS) throw new Error(`[DACW] 参数 task 过长(${task.length} > ${MAX_TASK_CHARS} 字符)`);
895
+ const taskIdArg = typeof args.task_id === 'string' ? args.task_id.trim() : '';
896
+ if (taskIdArg.length > MAX_TASK_ID_CHARS) throw new Error(`[DACW] 参数 task_id 过长(${taskIdArg.length} > ${MAX_TASK_ID_CHARS} 字符)`);
897
+ const workspaceArg = typeof args.workspace === 'string' ? args.workspace.trim() : '';
898
+ if (workspaceArg.length > MAX_WORKSPACE_ARG_CHARS) throw new Error(`[DACW] 参数 workspace 过长(${workspaceArg.length} > ${MAX_WORKSPACE_ARG_CHARS} 字符)`);
899
+ const subagents = (()=>{
900
+ try {
901
+ return ctx.get('subagents');
902
+ } catch {
903
+ return undefined;
904
+ }
905
+ })();
906
+ if (!subagents) throw new Error('[DACW] 宿主缺少 subagents 服务:DACW 需要它创建写手/审查者子代理');
907
+ const providerName = config.subagentProvider;
908
+ const provider = typeof subagents.getProvider === 'function' ? subagents.getProvider(providerName) : undefined;
909
+ if (!provider) {
910
+ const available = typeof subagents.list === 'function' ? subagents.list().join(', ') : '未知';
911
+ throw new Error(`[DACW] 子代理 provider "${providerName}" 未注册(可用:${available})`);
912
+ }
913
+ if (presets.ready && provider.capabilities && provider.capabilities.agentPreset === false) {
914
+ throw new Error(`[DACW] 子代理 provider "${providerName}" 不支持 agentPreset(独立 preset 子代理),` + `无法保证写手/审查者运行在专用零工具 preset 上;请改用 spawn(@deepseek-ai/dsh-subagent-spawn-in-process),` + `或在明确接受风险后设置 config.allowInheritedPresets: true。`);
915
+ }
916
+ const agent = exec && exec.agent ? exec.agent : null;
917
+ if (!agent) throw new Error('[DACW] 只能由 Agent 调用:执行上下文缺少调用方 Agent');
918
+ if (isDacwChild(agent)) throw new Error('[DACW] 禁止在 DACW 写手/审查者子代理内再次运行 dacw_run(防递归)');
919
+ if (!presets.ready && !config.allowInheritedPresets) {
920
+ throw new Error(`[DACW] 写手/审查者专用 preset 不可用(${presets.reason}),拒绝让子代理继承父会话工具运行。` + `请修复 preset 注册(需要 @deepseek-ai/dsh-persona 与 agentPresets 服务),` + `或在明确接受风险后设置 config.allowInheritedPresets: true。`);
921
+ }
922
+ const roleModels = {
923
+ writer: await resolveRoleModel(ctx, config.writerModel, 'writer', logger),
924
+ reviewer: await resolveRoleModel(ctx, config.reviewerModel, 'reviewer', logger)
925
+ };
926
+ const roleModelLabels = {
927
+ writer: roleModels.writer.label,
928
+ reviewer: roleModels.reviewer.label
929
+ };
930
+ const signal = exec && exec.signal ? exec.signal : undefined;
931
+ const baseDir = await callerWorkingDirectory(agent, signal);
932
+ const requested = workspaceArg || config.workspace;
933
+ const workspaceDir = await prepareWorkspace(baseDir, requested, config.workspacePolicy);
934
+ const logs = [];
935
+ const log = (message)=>{
936
+ logs.push(message);
937
+ logger.info(message);
938
+ };
939
+ const engineContext = {
940
+ async chat (agentId, prompt, contextStr) {
941
+ const role = agentId === 'reviewer-agent' ? 'reviewer' : 'writer';
942
+ const text = contextStr && contextStr.trim() ? `${prompt}\n\n${contextStr}` : prompt;
943
+ return runSubagentChat({
944
+ subagents,
945
+ config,
946
+ presets,
947
+ isolation,
948
+ agent,
949
+ workspaceDir,
950
+ signal,
951
+ role,
952
+ text,
953
+ dacwChildren,
954
+ logger,
955
+ roleModel: role === 'writer' ? roleModels.writer : roleModels.reviewer
956
+ });
957
+ },
958
+ log
959
+ };
960
+ const executeTask = createEngine(engineContext, {
961
+ maxRounds: config.maxRounds,
962
+ chatTimeoutBaseMs: config.chatTimeoutBaseMs,
963
+ chatTimeoutPer10kCharsMs: config.chatTimeoutPer10kCharsMs,
964
+ chatTimeoutMaxMs: config.chatTimeoutMaxMs,
965
+ chatMaxAttempts: config.chatMaxAttempts,
966
+ writerOutputMaxChars: config.writerOutputMaxChars,
967
+ manifestMaxEntries: config.manifestMaxEntries,
968
+ stateDir: config.stateDir || null,
969
+ roleModels: roleModelLabels
970
+ });
971
+ const rawTaskId = taskIdArg || `dacw-${Date.now().toString(36)}`;
972
+ const result = await executeTask(rawTaskId, workspaceDir, task);
973
+ const value = {
974
+ success: result.success === true,
975
+ status: String(result.status),
976
+ message: String(result.message),
977
+ workspace: workspaceDir,
978
+ models: roleModelLabels,
979
+ round: typeof result.round === 'number' ? result.round : 0,
980
+ files: Array.isArray(result.files) ? result.files.map(String) : [],
981
+ logs: tailLogs(logs, 60, 8000),
982
+ elapsed_ms: Date.now() - startedAt
983
+ };
984
+ if (!value.success) {
985
+ const failure = new Error(`[DACW] 工作流未通过(status=${value.status},round=${value.round}):${value.message}\n` + `工作区:${value.workspace}\n\n${renderToolResultText(value)}`);
986
+ failure.dacw = value;
987
+ throw failure;
988
+ }
989
+ return value;
990
+ }
991
+ };
992
+ ctx.effect(()=>ctx.tools.register(toolDefinition));
993
+ logger.info(`DACW: 工具 ${config.toolName} 已注册(workspacePolicy=${config.workspacePolicy}, provider=${config.subagentProvider}, ` + `enforceChildToolIsolation=${config.enforceChildToolIsolation})`);
994
+ }