dislop 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/.cursor-plugin/plugin.json +1 -1
  5. package/PRODUCT.md +2 -2
  6. package/README.md +34 -33
  7. package/README.zh-CN.md +65 -61
  8. package/action.yml +17 -2
  9. package/gemini-extension.json +1 -1
  10. package/package.json +2 -2
  11. package/packs/common/artifact-qa/scripts/index.mjs +64 -2
  12. package/packs/en/artifact-qa/scripts/index.mjs +1 -1
  13. package/packs/en/prose/scripts/index.mjs +3 -0
  14. package/plugin.json +1 -1
  15. package/server.json +2 -2
  16. package/skills/dislop/SKILL.md +1 -1
  17. package/skills/dislop/agents/openai.yaml +1 -1
  18. package/skills/dislop/references/essay.md +5 -5
  19. package/skills/dislop/references/essay.zh-CN.md +5 -5
  20. package/skills/dislop/references/office.md +4 -4
  21. package/skills/dislop/references/office.zh-CN.md +4 -4
  22. package/skills/dislop/references/web-ui.md +4 -4
  23. package/skills/dislop/references/web-ui.zh-CN.md +4 -4
  24. package/skills/dislop/references/work-docs.md +6 -6
  25. package/skills/dislop/references/work-docs.zh-CN.md +6 -6
  26. package/src/cli-main.mjs +88 -6
  27. package/src/commands/check-fix.mjs +170 -15
  28. package/src/commands/doctor.mjs +23 -1
  29. package/src/commands/init.mjs +24 -18
  30. package/src/commands/packs.mjs +41 -4
  31. package/src/commands/verify.mjs +36 -4
  32. package/src/commands/voice.mjs +1 -1
  33. package/src/commands/worklog.mjs +424 -0
  34. package/src/kernel/config.mjs +546 -19
  35. package/src/kernel/document-model.mjs +30 -10
  36. package/src/kernel/fact-gate.mjs +160 -0
  37. package/src/kernel/file-discovery.mjs +168 -11
  38. package/src/kernel/ooxml-binary.mjs +86 -0
  39. package/src/kernel/pack-loader.mjs +107 -21
  40. package/src/kernel/pack-validator.mjs +491 -0
  41. package/src/kernel/patcher.mjs +177 -47
  42. package/src/kernel/pipeline.mjs +284 -21
  43. package/src/kernel/prompt-assembler.mjs +37 -8
  44. package/src/kernel/version.mjs +7 -0
  45. package/src/kernel/voice-profile.mjs +3 -0
  46. package/src/mcp/stdio-server.mjs +71 -1
  47. package/src/runners/auto-fix.mjs +17 -2
  48. package/src/runners/interactive-tty.mjs +32 -5
  49. package/src/runners/reporters.mjs +18 -2
  50. package/src/runtime/providers/cloud.mjs +4 -2
  51. package/src/runtime/providers/local-model.mjs +8 -0
  52. package/src/runtime/router.mjs +11 -2
  53. package/src/runtime/worklog.mjs +904 -0
@@ -1,3 +1,4 @@
1
+ import { spawnSync } from "node:child_process";
1
2
  import crypto from "node:crypto";
2
3
  import fs from "node:fs";
3
4
  import os from "node:os";
@@ -84,36 +85,341 @@ export function writeJsonFileSecure(filePath, data, { mode = 0o600 } = {}) {
84
85
  fs.renameSync(tmp, filePath);
85
86
  }
86
87
 
87
- const VALID_ROUTING_MODES = new Set(["local", "auto", "cloud", "byok"]);
88
+ const VALID_ROUTING_MODES = new Set(["off", "local", "auto", "cloud", "byok"]);
89
+ const VALID_PROJECT_ROUTING_MODES = new Set(["off", "local"]);
90
+ const VALID_WORKLOG_PRIVACY_MODES = new Set(["metadata", "redacted", "local-full"]);
91
+ const VALID_FAIL_ON_MODES = new Set(["none", "error", "warning"]);
92
+ const VALID_RULE_SEVERITIES = new Set(["off", "error", "warning", "strong", "moderate", "hint"]);
93
+
94
+ const PROJECT_ALLOWED_KEYS = new Set([
95
+ "$schema",
96
+ "routing",
97
+ "ignore",
98
+ "packs",
99
+ "extraPacks",
100
+ "overrides",
101
+ "rules",
102
+ "lang",
103
+ "level",
104
+ "concurrency",
105
+ "failOn",
106
+ "voice",
107
+ ]);
108
+
109
+ const PROJECT_PRIVILEGED_KEYS = new Set([
110
+ "providers",
111
+ "activeProvider",
112
+ "approvedHosts",
113
+ "worklog",
114
+ "credentialsPath",
115
+ "modelsDir",
116
+ ]);
117
+
118
+ function isPathInsideDir(targetPath, baseDir) {
119
+ const realBase = fs.existsSync(baseDir) ? fs.realpathSync(baseDir) : path.resolve(baseDir);
120
+ const candidate = fs.existsSync(targetPath)
121
+ ? fs.realpathSync(targetPath)
122
+ : path.resolve(targetPath);
123
+ const rel = path.relative(realBase, candidate);
124
+ return rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
125
+ }
126
+
127
+ function findProjectRootAndConfigs(cwd) {
128
+ const startDir = path.resolve(cwd);
129
+ let gitBoundary = null;
130
+ let probe = startDir;
131
+ while (true) {
132
+ if (fs.existsSync(path.join(probe, ".git"))) {
133
+ gitBoundary = probe;
134
+ break;
135
+ }
136
+ const parent = path.dirname(probe);
137
+ if (parent === probe) break;
138
+ probe = parent;
139
+ }
140
+
141
+ const stopDir = gitBoundary || startDir;
142
+ let projectConfigPath = null;
143
+ let projectDir = stopDir;
144
+ probe = startDir;
145
+ while (true) {
146
+ const candidate = path.join(probe, ".dislop.json");
147
+ if (fs.existsSync(candidate)) {
148
+ projectConfigPath = candidate;
149
+ projectDir = probe;
150
+ break;
151
+ }
152
+ if (probe === stopDir) break;
153
+ const parent = path.dirname(probe);
154
+ if (parent === probe) break;
155
+ probe = parent;
156
+ }
157
+
158
+ const localConfigInProject = path.join(projectDir, ".dislop.local.json");
159
+ const localConfigInCwd = path.join(startDir, ".dislop.local.json");
160
+ const localConfigPath = fs.existsSync(localConfigInCwd)
161
+ ? localConfigInCwd
162
+ : localConfigInProject;
163
+
164
+ return {
165
+ projectDir,
166
+ gitBoundary,
167
+ projectConfigPath: projectConfigPath || path.join(projectDir, ".dislop.json"),
168
+ localConfigPath,
169
+ };
170
+ }
171
+
172
+ function isLocalConfigTrustedUntracked(localConfigPath, gitBoundary) {
173
+ if (!gitBoundary || !fs.existsSync(localConfigPath)) return true;
174
+ const res = spawnSync("git", ["ls-files", "--error-unmatch", localConfigPath], {
175
+ cwd: gitBoundary,
176
+ stdio: "ignore",
177
+ });
178
+ if (res.status === 0) {
179
+ // Exit 0 means `.dislop.local.json` is tracked in git -> untrusted escalation vector (R4)
180
+ throw new DislopConfigError(
181
+ `Security error: '${localConfigPath}' is tracked by git. Remove it from git index (.gitignore) or move shared settings into '.dislop.json'.`,
182
+ );
183
+ }
184
+ if (res.error || res.status !== 1) {
185
+ // Fail closed if git check failed or errored: downgrade `.dislop.local.json` to untrusted
186
+ return false;
187
+ }
188
+ return true;
189
+ }
190
+
191
+ export function normalizeFailOnValue(raw, label = "failOn") {
192
+ const val = String(raw || "").trim().toLowerCase();
193
+ if (val === "info" || val === "suggestion" || val === "strong" || val === "moderate" || val === "hint") {
194
+ throw new DislopConfigError(
195
+ `Invalid ${label} '${raw}': Suggestions cannot fail CI (Exit 0 invariant). Expected 'none', 'error', or 'warning'.`,
196
+ );
197
+ }
198
+ if (!VALID_FAIL_ON_MODES.has(val)) {
199
+ throw new DislopConfigError(`Invalid ${label} '${raw}' (expected 'none', 'error', or 'warning')`);
200
+ }
201
+ return val;
202
+ }
203
+
204
+ function validateProjectLayerKeys(d, source) {
205
+ for (const key of Object.keys(d)) {
206
+ if (key === "pack") {
207
+ throw new DislopConfigError(
208
+ `Invalid config key 'pack' in '${source}'. Migrate to 'packs' (array) and remove singular 'pack'.`,
209
+ );
210
+ }
211
+ if (PROJECT_PRIVILEGED_KEYS.has(key)) {
212
+ throw new DislopConfigError(
213
+ `Config key '${key}' is not permitted in shared project '${source}'. Place credentials/providers/worklog settings in user config (~/.config/dislop/config.json) or untracked '.dislop.local.json'.`,
214
+ );
215
+ }
216
+ if (!PROJECT_ALLOWED_KEYS.has(key)) {
217
+ throw new DislopConfigError(`Unknown config key '${key}' in '${source}'.`);
218
+ }
219
+ }
220
+ }
221
+
222
+ function validateRuleConfigValue(ruleId, rawVal, source) {
223
+ if (rawVal === false || rawVal === "off") return "off";
224
+ if (rawVal === true) return "on";
225
+ if (typeof rawVal === "string") {
226
+ const val = rawVal.trim().toLowerCase();
227
+ if (!VALID_RULE_SEVERITIES.has(val)) {
228
+ throw new DislopConfigError(
229
+ `Invalid severity '${rawVal}' for rule '${ruleId}' in '${source}'`,
230
+ );
231
+ }
232
+ return val;
233
+ }
234
+ if (rawVal && typeof rawVal === "object" && !Array.isArray(rawVal)) {
235
+ const allowedObjKeys = new Set(["enabled", "severity", "level", "priority"]);
236
+ for (const k of Object.keys(rawVal)) {
237
+ if (!allowedObjKeys.has(k)) {
238
+ throw new DislopConfigError(`Invalid key '${k}' in rule setting for '${ruleId}' in '${source}'`);
239
+ }
240
+ }
241
+ if (rawVal.enabled !== undefined && typeof rawVal.enabled !== "boolean") {
242
+ throw new DislopConfigError(`'enabled' for rule '${ruleId}' in '${source}' must be boolean`);
243
+ }
244
+ for (const sevKey of ["severity", "level", "priority"]) {
245
+ if (rawVal[sevKey] !== undefined) {
246
+ const s = String(rawVal[sevKey]).trim().toLowerCase();
247
+ if (!VALID_RULE_SEVERITIES.has(s)) {
248
+ throw new DislopConfigError(
249
+ `Invalid ${sevKey} '${rawVal[sevKey]}' for rule '${ruleId}' in '${source}'`,
250
+ );
251
+ }
252
+ }
253
+ }
254
+ return rawVal;
255
+ }
256
+ throw new DislopConfigError(`Invalid rule setting for '${ruleId}' in '${source}'`);
257
+ }
258
+
259
+ function validateDeclarativeRuleEntry(entry, index, source) {
260
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
261
+ throw new DislopConfigError(`Declarative rule #${index} in '${source}' must be an object`);
262
+ }
263
+ const id = String(entry.id || entry.ruleId || "").trim();
264
+ if (!id || !/^[a-z0-9][a-z0-9/_-]{1,80}$/i.test(id)) {
265
+ throw new DislopConfigError(
266
+ `Declarative rule #${index} in '${source}' requires a safe alphanumeric 'id'`,
267
+ );
268
+ }
269
+ const pattern = entry.pattern ? String(entry.pattern) : null;
270
+ const terms = Array.isArray(entry.terms)
271
+ ? entry.terms.map(String).filter(Boolean)
272
+ : typeof entry.literal === "string" && entry.literal
273
+ ? [entry.literal]
274
+ : [];
275
+ if (!pattern && terms.length === 0) {
276
+ throw new DislopConfigError(
277
+ `Declarative rule '${id}' in '${source}' must define 'pattern', 'literal', or 'terms'`,
278
+ );
279
+ }
280
+ if (pattern) {
281
+ if (pattern.length > 500) {
282
+ throw new DislopConfigError(`Declarative rule '${id}' pattern exceeds 500 chars`);
283
+ }
284
+ if (/(\+|\*|\{[^}]+\})\s*\)?\s*(\+|\*|\{[^}]+\})/.test(pattern)) {
285
+ throw new DislopConfigError(
286
+ `Declarative rule '${id}' contains nested quantifiers prohibited for ReDoS safety`,
287
+ );
288
+ }
289
+ try {
290
+ new RegExp(pattern, entry.flags ? String(entry.flags).replace(/[^imu]/g, "") : "i");
291
+ } catch (err) {
292
+ throw new DislopConfigError(`Declarative rule '${id}' has invalid RegExp: ${err.message}`);
293
+ }
294
+ }
295
+ const kind = entry.kind === "suggestion" ? "suggestion" : "defect";
296
+ const severity = entry.severity ? String(entry.severity).toLowerCase() : "warning";
297
+ if (!["error", "warning"].includes(severity)) {
298
+ throw new DislopConfigError(
299
+ `Declarative rule '${id}' has invalid severity '${entry.severity}'`,
300
+ );
301
+ }
302
+ const priority = entry.priority ? String(entry.priority).toLowerCase() : "moderate";
303
+ if (!["strong", "moderate", "hint"].includes(priority)) {
304
+ throw new DislopConfigError(
305
+ `Declarative rule '${id}' has invalid priority '${entry.priority}'`,
306
+ );
307
+ }
308
+ const fixSafety = entry.fixSafety ? String(entry.fixSafety).toLowerCase() : "review";
309
+ if (!["safe", "review", "manual"].includes(fixSafety)) {
310
+ throw new DislopConfigError(
311
+ `Declarative rule '${id}' has invalid fixSafety '${entry.fixSafety}'`,
312
+ );
313
+ }
314
+
315
+ return {
316
+ id,
317
+ kind,
318
+ severity,
319
+ priority,
320
+ fixSafety,
321
+ pattern,
322
+ flags: entry.flags ? String(entry.flags).replace(/[^imu]/g, "") : "i",
323
+ terms,
324
+ formats: Array.isArray(entry.formats) ? entry.formats.map(String) : null,
325
+ files: Array.isArray(entry.files)
326
+ ? entry.files.map(String)
327
+ : typeof entry.files === "string"
328
+ ? [entry.files]
329
+ : null,
330
+ languages: Array.isArray(entry.languages) ? entry.languages.map(String) : null,
331
+ reason: String(entry.reason || entry.message || `Matched project rule '${id}'.`),
332
+ replacement:
333
+ entry.replacement !== undefined
334
+ ? String(entry.replacement)
335
+ : entry.suggestedReplacement !== undefined
336
+ ? String(entry.suggestedReplacement)
337
+ : undefined,
338
+ actionType: entry.actionType ? String(entry.actionType) : undefined,
339
+ };
340
+ }
341
+
342
+ function loadProjectDeclarativeRulesFile(projectDir) {
343
+ const rulesPath = path.join(projectDir, ".dislop", "rules.json");
344
+ if (!fs.existsSync(rulesPath)) return [];
345
+ let raw;
346
+ try {
347
+ raw = JSON.parse(fs.readFileSync(rulesPath, "utf8"));
348
+ } catch (err) {
349
+ throw new DislopConfigError(`Invalid JSON in '${rulesPath}': ${err.message}`);
350
+ }
351
+ const entries = Array.isArray(raw) ? raw : Array.isArray(raw?.rules) ? raw.rules : null;
352
+ if (!entries) {
353
+ throw new DislopConfigError(`'${rulesPath}' must export an array or { rules: [...] }`);
354
+ }
355
+ return entries.map((e, idx) => validateDeclarativeRuleEntry(e, idx, rulesPath));
356
+ }
357
+
358
+ export function isCiEnvironment(env = process.env) {
359
+ return Boolean((env.CI && env.CI !== "0" && env.CI !== "false") || env.GITHUB_ACTIONS);
360
+ }
361
+
362
+ function parseConcurrencyValue(raw, label) {
363
+ const num = Number(raw);
364
+ if (!Number.isInteger(num) || num < 1 || num > 16) {
365
+ throw new DislopConfigError(`Invalid ${label} '${raw}' (expected integer 1..16)`);
366
+ }
367
+ return num;
368
+ }
369
+
370
+ function parseRetentionDaysValue(raw, label) {
371
+ const num = Number(raw);
372
+ if (!Number.isInteger(num) || num < 1 || num > 365) {
373
+ throw new DislopConfigError(`Invalid ${label} '${raw}' (expected integer 1..365)`);
374
+ }
375
+ return num;
376
+ }
88
377
 
89
378
  /**
90
379
  * Resolve layered configuration:
91
- * `~/.config/dislop/config.json` <- `<cwd>/.dislop.json` <- `<cwd>/.dislop.local.json` <- CLI flags.
380
+ * `~/.config/dislop/config.json` <- `<projectDir>/.dislop.json` <- `<localDir>/.dislop.local.json` <- CLI flags.
92
381
  */
93
382
  export function resolveLayeredConfig({ cwd = process.cwd(), env = process.env, cliFlags = {} } = {}) {
94
383
  const homeDir = getDislopHomeDir(env);
95
384
  const userConfigPath = path.join(homeDir, "config.json");
96
- const projectConfigPath = path.join(cwd, ".dislop.json");
97
- const localConfigPath = path.join(cwd, ".dislop.local.json");
385
+ const { projectDir, gitBoundary, projectConfigPath, localConfigPath } =
386
+ findProjectRootAndConfigs(cwd);
387
+ const localTrusted = isLocalConfigTrustedUntracked(localConfigPath, gitBoundary);
98
388
 
99
389
  const defaults = {
100
390
  routing: "local",
101
391
  activeProvider: null,
102
392
  approvedHosts: [],
393
+ ignore: [],
394
+ concurrency: null,
103
395
  packs: null,
396
+ extraPacks: [],
397
+ extraPackSpecs: [],
398
+ packOrigin: "default",
399
+ projectDir,
400
+ overrides: [],
401
+ rules: {},
402
+ declarativeRules: [],
403
+ failOn: "error",
104
404
  lang: "auto",
105
405
  level: "all",
106
406
  voice: {
107
407
  referenceFiles: [],
108
408
  cachePath: path.join(homeDir, "voice.json"),
109
409
  },
410
+ worklog: {
411
+ enabled: false,
412
+ privacy: "metadata",
413
+ dir: path.join(homeDir, "worklog"),
414
+ retentionDays: 30,
415
+ },
110
416
  providers: {},
111
417
  };
112
418
 
113
419
  const layers = [
114
- { source: userConfigPath, data: readJsonFileStrict(userConfigPath) },
115
- { source: projectConfigPath, data: readJsonFileStrict(projectConfigPath) },
116
- { source: localConfigPath, data: readJsonFileStrict(localConfigPath) },
420
+ { source: userConfigPath, origin: "user", data: readJsonFileStrict(userConfigPath), isLocalTrusted: true },
421
+ { source: projectConfigPath, origin: "project", data: readJsonFileStrict(projectConfigPath), isLocalTrusted: false },
422
+ { source: localConfigPath, origin: localTrusted ? "local" : "project", data: readJsonFileStrict(localConfigPath), isLocalTrusted: localTrusted },
117
423
  ];
118
424
 
119
425
  const merged = structuredClone(defaults);
@@ -124,28 +430,71 @@ export function resolveLayeredConfig({ cwd = process.cwd(), env = process.env, c
124
430
  loadedSources.push(layer.source);
125
431
  const d = layer.data;
126
432
 
433
+ if (!layer.isLocalTrusted) {
434
+ validateProjectLayerKeys(d, layer.source);
435
+ }
436
+
127
437
  if (d.routing !== undefined) {
128
438
  if (!VALID_ROUTING_MODES.has(d.routing)) {
129
439
  throw new DislopConfigError(
130
- `Invalid 'routing' value '${d.routing}' in '${layer.source}' (expected local, auto, cloud, or byok)`,
440
+ `Invalid 'routing' value '${d.routing}' in '${layer.source}' (expected off, local, auto, cloud, or byok)`,
441
+ );
442
+ }
443
+ if (!layer.isLocalTrusted && !VALID_PROJECT_ROUTING_MODES.has(d.routing)) {
444
+ throw new DislopConfigError(
445
+ `Shared project '${layer.source}' cannot set routing '${d.routing}' (only 'local' or 'off' allowed; set 'byok'/'cloud'/'auto' in user or local config).`,
131
446
  );
132
447
  }
133
448
  merged.routing = d.routing;
134
449
  }
135
- if (d.activeProvider !== undefined) {
450
+ if (layer.isLocalTrusted && d.activeProvider !== undefined) {
136
451
  merged.activeProvider = d.activeProvider ? String(d.activeProvider) : null;
137
452
  }
138
- if (d.approvedHosts !== undefined) {
453
+ if (layer.isLocalTrusted && d.approvedHosts !== undefined) {
139
454
  if (!Array.isArray(d.approvedHosts)) {
140
455
  throw new DislopConfigError(`'approvedHosts' in '${layer.source}' must be an array`);
141
456
  }
142
457
  merged.approvedHosts = Array.from(new Set([...merged.approvedHosts, ...d.approvedHosts.map(String)]));
143
458
  }
459
+ if (d.ignore !== undefined) {
460
+ if (!Array.isArray(d.ignore)) {
461
+ throw new DislopConfigError(`'ignore' in '${layer.source}' must be an array`);
462
+ }
463
+ merged.ignore = Array.from(new Set([...merged.ignore, ...d.ignore.map((v) => String(v).trim()).filter(Boolean)]));
464
+ }
465
+ if (d.concurrency !== undefined && d.concurrency !== null) {
466
+ merged.concurrency = parseConcurrencyValue(d.concurrency, `'concurrency' in '${layer.source}'`);
467
+ }
144
468
  if (d.packs !== undefined) {
145
469
  if (!Array.isArray(d.packs)) {
146
470
  throw new DislopConfigError(`'packs' in '${layer.source}' must be an array`);
147
471
  }
148
472
  merged.packs = d.packs.map(String);
473
+ merged.packOrigin = layer.origin;
474
+ }
475
+ if (d.extraPacks !== undefined) {
476
+ if (!Array.isArray(d.extraPacks)) {
477
+ throw new DislopConfigError(`'extraPacks' in '${layer.source}' must be an array`);
478
+ }
479
+ for (const ep of d.extraPacks) {
480
+ if (typeof ep !== "string" || !ep.trim()) {
481
+ throw new DislopConfigError(`Each entry in 'extraPacks' in '${layer.source}' must be a non-empty string`);
482
+ }
483
+ const s = ep.trim();
484
+ if (!merged.extraPacks.includes(s)) {
485
+ merged.extraPacks.push(s);
486
+ merged.extraPackSpecs.push({ spec: s, origin: layer.origin });
487
+ } else {
488
+ // If added earlier and also listed from a stricter untrusted origin, keep untrusted origin
489
+ const existing = merged.extraPackSpecs.find((x) => x.spec === s);
490
+ if (existing && !layer.isLocalTrusted) {
491
+ existing.origin = layer.origin;
492
+ }
493
+ }
494
+ }
495
+ }
496
+ if (d.failOn !== undefined) {
497
+ merged.failOn = normalizeFailOnValue(d.failOn, `'failOn' in '${layer.source}'`);
149
498
  }
150
499
  if (d.lang !== undefined) {
151
500
  merged.lang = String(d.lang);
@@ -153,22 +502,192 @@ export function resolveLayeredConfig({ cwd = process.cwd(), env = process.env, c
153
502
  if (d.level !== undefined) {
154
503
  merged.level = String(d.level);
155
504
  }
156
- if (d.voice && typeof d.voice === "object" && !Array.isArray(d.voice)) {
157
- if (Array.isArray(d.voice.referenceFiles)) {
158
- merged.voice.referenceFiles = d.voice.referenceFiles.map((f) =>
159
- path.resolve(path.dirname(layer.source), expandTilde(f, env)),
505
+ if (d.rules !== undefined) {
506
+ if (Array.isArray(d.rules)) {
507
+ merged.declarativeRules.push(
508
+ ...d.rules.map((e, idx) => validateDeclarativeRuleEntry(e, idx, layer.source)),
160
509
  );
510
+ } else if (d.rules && typeof d.rules === "object") {
511
+ for (const [rId, rVal] of Object.entries(d.rules)) {
512
+ merged.rules[rId] = validateRuleConfigValue(rId, rVal, layer.source);
513
+ }
514
+ } else {
515
+ throw new DislopConfigError(`'rules' in '${layer.source}' must be an object or array`);
516
+ }
517
+ }
518
+ if (d.overrides !== undefined) {
519
+ if (!Array.isArray(d.overrides)) {
520
+ throw new DislopConfigError(`'overrides' in '${layer.source}' must be an array`);
161
521
  }
162
- if (d.voice.cachePath) {
163
- merged.voice.cachePath = path.resolve(cwd, expandTilde(d.voice.cachePath, env));
522
+ for (let i = 0; i < d.overrides.length; i++) {
523
+ const ov = d.overrides[i];
524
+ if (!ov || typeof ov !== "object" || Array.isArray(ov)) {
525
+ throw new DislopConfigError(`overrides[${i}] in '${layer.source}' must be an object`);
526
+ }
527
+ if (!ov.files || (typeof ov.files !== "string" && !Array.isArray(ov.files))) {
528
+ throw new DislopConfigError(
529
+ `overrides[${i}] in '${layer.source}' must define 'files' (string or array)`,
530
+ );
531
+ }
532
+ const ovAllowed = new Set(["files", "packs", "extraPacks", "rules", "failOn", "lang", "level", "ignore", "routing"]);
533
+ for (const k of Object.keys(ov)) {
534
+ if (!ovAllowed.has(k)) {
535
+ throw new DislopConfigError(`Invalid override key '${k}' in '${layer.source}'`);
536
+ }
537
+ }
538
+ if (ov.routing !== undefined && !layer.isLocalTrusted && !VALID_PROJECT_ROUTING_MODES.has(ov.routing)) {
539
+ throw new DislopConfigError(
540
+ `overrides[${i}].routing in '${layer.source}' only permits 'local' or 'off'`,
541
+ );
542
+ }
543
+ const filesList = Array.isArray(ov.files) ? ov.files : [ov.files];
544
+ if (filesList.length === 0 || filesList.some((f) => typeof f !== "string" || !f.trim())) {
545
+ throw new DislopConfigError(
546
+ `overrides[${i}].files in '${layer.source}' must contain only non-empty strings`,
547
+ );
548
+ }
549
+ for (const arrField of ["packs", "extraPacks", "ignore"]) {
550
+ if (
551
+ ov[arrField] !== undefined &&
552
+ (!Array.isArray(ov[arrField]) || ov[arrField].some((x) => typeof x !== "string"))
553
+ ) {
554
+ throw new DislopConfigError(
555
+ `overrides[${i}].${arrField} in '${layer.source}' must be an array of strings`,
556
+ );
557
+ }
558
+ }
559
+ merged.overrides.push({
560
+ files: filesList.map((f) => f.trim()),
561
+ packs: Array.isArray(ov.packs) ? ov.packs : undefined,
562
+ extraPacks: Array.isArray(ov.extraPacks) ? ov.extraPacks : undefined,
563
+ failOn: ov.failOn !== undefined ? normalizeFailOnValue(ov.failOn, `overrides[${i}].failOn`) : undefined,
564
+ lang: ov.lang !== undefined ? String(ov.lang) : undefined,
565
+ level: ov.level !== undefined ? String(ov.level) : undefined,
566
+ ignore: Array.isArray(ov.ignore) ? ov.ignore : undefined,
567
+ routing: ov.routing !== undefined ? String(ov.routing) : undefined,
568
+ origin: layer.origin,
569
+ rules:
570
+ ov.rules && typeof ov.rules === "object" && !Array.isArray(ov.rules)
571
+ ? Object.fromEntries(
572
+ Object.entries(ov.rules).map(([rk, rv]) => [
573
+ rk,
574
+ validateRuleConfigValue(rk, rv, layer.source),
575
+ ]),
576
+ )
577
+ : undefined,
578
+ });
164
579
  }
165
580
  }
166
- if (d.providers && typeof d.providers === "object" && !Array.isArray(d.providers)) {
581
+ if (d.voice !== undefined) {
582
+ if (!d.voice || typeof d.voice !== "object" || Array.isArray(d.voice)) {
583
+ throw new DislopConfigError(`'voice' in '${layer.source}' must be an object`);
584
+ }
585
+ if (!layer.isLocalTrusted) {
586
+ for (const vk of Object.keys(d.voice)) {
587
+ if (vk !== "referenceFiles") {
588
+ throw new DislopConfigError(
589
+ `'voice.${vk}' is not permitted in shared project '${layer.source}'`,
590
+ );
591
+ }
592
+ }
593
+ }
594
+ if (Array.isArray(d.voice.referenceFiles)) {
595
+ const baseDir = path.dirname(layer.source);
596
+ merged.voice.referenceFiles = d.voice.referenceFiles.map((f) => {
597
+ const resolved = path.resolve(baseDir, expandTilde(f, env));
598
+ if (!layer.isLocalTrusted && !isPathInsideDir(resolved, projectDir)) {
599
+ throw new DislopConfigError(
600
+ `'voice.referenceFiles' entry '${f}' in '${layer.source}' escapes project directory '${projectDir}'`,
601
+ );
602
+ }
603
+ return resolved;
604
+ });
605
+ }
606
+ if (layer.isLocalTrusted && d.voice.cachePath) {
607
+ const resolvedCache = path.resolve(cwd, expandTilde(d.voice.cachePath, env));
608
+ if (layer.origin !== "user" && !isPathInsideDir(resolvedCache, homeDir) && !isPathInsideDir(resolvedCache, projectDir)) {
609
+ throw new DislopConfigError(
610
+ `'voice.cachePath' '${d.voice.cachePath}' must stay inside dislop config dir or project root`,
611
+ );
612
+ }
613
+ merged.voice.cachePath = resolvedCache;
614
+ }
615
+ }
616
+ if (layer.isLocalTrusted && d.providers && typeof d.providers === "object" && !Array.isArray(d.providers)) {
167
617
  for (const [provName, provCfg] of Object.entries(d.providers)) {
168
618
  if (!provCfg || typeof provCfg !== "object") continue;
169
619
  merged.providers[provName] = { ...merged.providers[provName], ...provCfg };
170
620
  }
171
621
  }
622
+ if (layer.isLocalTrusted && d.worklog !== undefined) {
623
+ if (!d.worklog || typeof d.worklog !== "object" || Array.isArray(d.worklog)) {
624
+ throw new DislopConfigError(`'worklog' in '${layer.source}' must be an object`);
625
+ }
626
+ if (d.worklog.enabled !== undefined) {
627
+ if (typeof d.worklog.enabled !== "boolean") {
628
+ throw new DislopConfigError(`'worklog.enabled' in '${layer.source}' must be a boolean`);
629
+ }
630
+ merged.worklog.enabled = d.worklog.enabled;
631
+ }
632
+ if (d.worklog.privacy !== undefined) {
633
+ const priv = String(d.worklog.privacy).trim();
634
+ if (!VALID_WORKLOG_PRIVACY_MODES.has(priv)) {
635
+ throw new DislopConfigError(
636
+ `Invalid 'worklog.privacy' value '${d.worklog.privacy}' in '${layer.source}' (expected metadata, redacted, or local-full)`,
637
+ );
638
+ }
639
+ merged.worklog.privacy = priv;
640
+ }
641
+ if (d.worklog.dir !== undefined && d.worklog.dir !== null) {
642
+ if (typeof d.worklog.dir !== "string" || !d.worklog.dir.trim()) {
643
+ throw new DislopConfigError(`'worklog.dir' in '${layer.source}' must be a non-empty string`);
644
+ }
645
+ merged.worklog.dir = path.resolve(
646
+ path.dirname(layer.source),
647
+ expandTilde(d.worklog.dir.trim(), env),
648
+ );
649
+ }
650
+ if (d.worklog.retentionDays !== undefined && d.worklog.retentionDays !== null) {
651
+ merged.worklog.retentionDays = parseRetentionDaysValue(
652
+ d.worklog.retentionDays,
653
+ `'worklog.retentionDays' in '${layer.source}'`,
654
+ );
655
+ }
656
+ }
657
+ }
658
+
659
+ // Apply environment variable overrides for local worklog recording
660
+ if (env.DISLOP_WORKLOG !== undefined && String(env.DISLOP_WORKLOG).trim() !== "") {
661
+ const rawWl = String(env.DISLOP_WORKLOG).trim().toLowerCase();
662
+ if (rawWl === "0" || rawWl === "false" || rawWl === "off") {
663
+ merged.worklog.enabled = false;
664
+ } else if (rawWl === "1" || rawWl === "true" || rawWl === "on") {
665
+ merged.worklog.enabled = true;
666
+ } else if (VALID_WORKLOG_PRIVACY_MODES.has(rawWl)) {
667
+ merged.worklog.enabled = true;
668
+ merged.worklog.privacy = rawWl;
669
+ } else {
670
+ throw new DislopConfigError(
671
+ `Invalid DISLOP_WORKLOG '${env.DISLOP_WORKLOG}' (expected 0/1/false/true/off/on/metadata/redacted/local-full)`,
672
+ );
673
+ }
674
+ }
675
+ if (env.DISLOP_WORKLOG_DIR !== undefined && String(env.DISLOP_WORKLOG_DIR).trim() !== "") {
676
+ merged.worklog.dir = path.resolve(cwd, expandTilde(String(env.DISLOP_WORKLOG_DIR).trim(), env));
677
+ }
678
+ if (
679
+ env.DISLOP_WORKLOG_RETENTION_DAYS !== undefined &&
680
+ String(env.DISLOP_WORKLOG_RETENTION_DAYS).trim() !== ""
681
+ ) {
682
+ merged.worklog.retentionDays = parseRetentionDaysValue(
683
+ env.DISLOP_WORKLOG_RETENTION_DAYS,
684
+ "DISLOP_WORKLOG_RETENTION_DAYS",
685
+ );
686
+ }
687
+
688
+ const projectDeclarativeRules = loadProjectDeclarativeRulesFile(projectDir);
689
+ if (projectDeclarativeRules.length > 0) {
690
+ merged.declarativeRules.push(...projectDeclarativeRules);
172
691
  }
173
692
 
174
693
  // Apply CLI flag overrides
@@ -176,7 +695,7 @@ export function resolveLayeredConfig({ cwd = process.cwd(), env = process.env, c
176
695
  if (cliFlags.engine) {
177
696
  if (!VALID_ROUTING_MODES.has(cliFlags.engine)) {
178
697
  throw new DislopConfigError(
179
- `Invalid --engine '${cliFlags.engine}' (expected auto, cloud, byok, or local)`,
698
+ `Invalid --engine '${cliFlags.engine}' (expected off, auto, cloud, byok, or local)`,
180
699
  );
181
700
  }
182
701
  merged.routing = cliFlags.engine;
@@ -186,6 +705,10 @@ export function resolveLayeredConfig({ cwd = process.cwd(), env = process.env, c
186
705
  }
187
706
  if (cliFlags.packs && cliFlags.packs.length > 0) {
188
707
  merged.packs = cliFlags.packs;
708
+ merged.packOrigin = cliFlags.packOrigin || "cli";
709
+ }
710
+ if (cliFlags.failOn) {
711
+ merged.failOn = normalizeFailOnValue(cliFlags.failOn, "--fail-on");
189
712
  }
190
713
  if (cliFlags.lang) {
191
714
  if (!["auto", "en", "zh"].includes(cliFlags.lang)) {
@@ -204,12 +727,16 @@ export function resolveLayeredConfig({ cwd = process.cwd(), env = process.env, c
204
727
  if (cliFlags.voiceFiles && cliFlags.voiceFiles.length > 0) {
205
728
  merged.voice.referenceFiles = cliFlags.voiceFiles.map((f) => path.resolve(cwd, expandTilde(f, env)));
206
729
  }
730
+ if (cliFlags.concurrency !== undefined && cliFlags.concurrency !== null && cliFlags.concurrency !== "") {
731
+ merged.concurrency = parseConcurrencyValue(cliFlags.concurrency, "--concurrency");
732
+ }
207
733
 
208
734
  return {
209
735
  ...merged,
210
736
  explicitEngine,
737
+ explicitFailOn: Boolean(cliFlags.failOn),
211
738
  modelOverride: cliFlags.model ? String(cliFlags.model) : null,
212
- noLlm: Boolean(cliFlags.noLlm),
739
+ noLlm: Boolean(cliFlags.noLlm) || env.DISLOP_TEST_MODE === "1" || merged.routing === "off",
213
740
  homeDir,
214
741
  userConfigPath,
215
742
  credentialsPath: path.join(homeDir, "credentials.json"),