@dommaker/harness 4.0.2 → 5.0.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 (39) hide show
  1. package/README.md +7 -8
  2. package/dist/cli/commands/definitions.js +1 -1
  3. package/dist/core/config-files.d.ts +8 -0
  4. package/dist/core/config-files.js +62 -0
  5. package/dist/core/constraints/checker.d.ts +1 -1
  6. package/dist/core/constraints/checker.js +1 -1
  7. package/dist/core/constraints/definitions.d.ts +2 -2
  8. package/dist/core/constraints/definitions.js +2 -2
  9. package/dist/core/effective-constraints.d.ts +1 -1
  10. package/dist/core/effective-constraints.js +1 -1
  11. package/dist/gates/acceptance.d.ts +0 -1
  12. package/dist/gates/acceptance.js +0 -1
  13. package/dist/gates/command.d.ts +0 -1
  14. package/dist/gates/command.js +0 -1
  15. package/dist/gates/contract.d.ts +0 -1
  16. package/dist/gates/contract.js +0 -1
  17. package/dist/gates/definitions.d.ts +2 -4
  18. package/dist/gates/definitions.js +2 -8
  19. package/dist/gates/performance.d.ts +0 -1
  20. package/dist/gates/performance.js +0 -1
  21. package/dist/gates/review.d.ts +0 -1
  22. package/dist/gates/review.js +0 -1
  23. package/dist/gates/security.d.ts +0 -1
  24. package/dist/gates/security.js +0 -1
  25. package/dist/gates/types.d.ts +1 -3
  26. package/dist/index.d.ts +5 -4
  27. package/dist/index.js +9 -6
  28. package/dist/knowledge/index.d.ts +1 -1
  29. package/dist/knowledge/index.js +1 -2
  30. package/dist/knowledge/ingest.d.ts +1 -17
  31. package/dist/knowledge/ingest.js +0 -42
  32. package/dist/knowledge/query.d.ts +1 -1
  33. package/dist/knowledge/query.js +1 -1
  34. package/dist/monitoring/index.d.ts +2 -1
  35. package/dist/monitoring/index.js +3 -1
  36. package/dist/monitoring/traces.d.ts +12 -0
  37. package/dist/monitoring/traces.js +26 -4
  38. package/dist/types/constraint.d.ts +0 -12
  39. package/package.json +1 -1
package/README.md CHANGED
@@ -29,10 +29,10 @@ npx @dommaker/harness check
29
29
  **作为库使用**:
30
30
 
31
31
  ```typescript
32
- import { checkBeforeExecution, getAllConstraints } from '@dommaker/harness';
32
+ import { checkConstraints, getAllConstraints } from '@dommaker/harness';
33
33
 
34
34
  // Agent 启动前检查
35
- await checkBeforeExecution({
35
+ await checkConstraints({
36
36
  operation: 'code_implementation',
37
37
  taskDescription: '重构用户认证模块',
38
38
  projectPath: '/path/to/project',
@@ -85,8 +85,8 @@ harness validate # 检查点验证(读 .harness/checkpoints.yml,失败
85
85
  harness init # 初始化 .harness/ 目录(不覆盖已有运行时配置)
86
86
  harness status # 项目健康状态、统计、异常检测
87
87
  harness constraints # 约束元数据(版本/hash/计数/文本大小)
88
- harness constraints report # 约束使用报告:统计 + 退役候选诊断 + 配置健康 + 注入漂移(--export 脱敏)
89
- harness constraints retire # 约束退役:交互选择 + 人确认 → config.yml + KnowledgeStore + 注入段同步
88
+ harness constraints report # 约束使用报告:统计 + 退役候选诊断 + 配置健康(--export 脱敏)
89
+ harness constraints retire # 约束退役:交互选择 + 人确认 → config.yml + KnowledgeStore
90
90
  harness constraints retire <id> --yes # 直达退役:显式 --yes 人确认(无 --yes 拒绝执行)
91
91
  harness constraints disable <id> --yes # 裸禁用:config.yml enabled:false 无墓碑无沉淀(区别于 retire)
92
92
  harness report # 生成检查报告
@@ -122,11 +122,10 @@ harness release # npm 发布流水线(tsc → dist 验证 → version
122
122
 
123
123
  ```yaml
124
124
  # .harness/config.yml
125
- preset: standard # strict | standard | relaxed(relaxed 仅启用 5 条 check 约束)
126
- scenes: [] # 场景标签,命中场景专属 prompt 才进入生效集
125
+ preset: standard # strict | standard | relaxed(relaxed 仅启用 2 条核心约束)
127
126
  ```
128
127
 
129
- `preset` 真实影响运行时检查与注入;`constraints.<id>.enabled: false` 可单独禁用。
128
+ `preset` 真实影响运行时检查;`constraints.<id>.enabled: false` 可单独禁用。
130
129
 
131
130
  ---
132
131
 
@@ -134,7 +133,7 @@ scenes: [] # 场景标签,命中场景专属 prompt 才进入生效集
134
133
 
135
134
  | 模块 | 说明 |
136
135
  |------|------|
137
- | 约束引擎 | check/prompt 二元约束 + 生效集合并(`getEffectiveConstraints`)+ 注入渲染/漂移校验 |
136
+ | 约束引擎 | severity/channel 显式约束 + 生效集合并(`getEffectiveConstraints`)+ checker 分发 |
138
137
  | 知识引擎 | 约束退役 → KnowledgeStore 沉淀(规则原文 + 原因 + 历史统计),可检索、可追溯 |
139
138
  | 门禁系统 | 6 种门禁:验收/性能/安全/契约/审查/命令(另有测试门控命令 passes-gate) |
140
139
  | 检查点验证 | 项目在 checkpoints.yml 自声明的通用检查项(13 种 check type),由 `harness validate` 执行;与门禁的分工见 ADR-0036 |
@@ -238,7 +238,7 @@ exports.COMMAND_DEFINITIONS = [
238
238
  children: [
239
239
  {
240
240
  command: 'report',
241
- description: '约束使用报告:check 层统计表、退役候选诊断、prompt 注入清单、配置健康(只读)',
241
+ description: '约束使用报告:check 层统计表、退役候选诊断、配置健康(只读)',
242
242
  options: [
243
243
  { flags: '-p, --project-path <path>', description: '项目路径' },
244
244
  { flags: '--export [file]', description: '导出脱敏 markdown 摘要(缺省 .harness/reports/constraints-<YYYYMMDD>.md)' },
@@ -0,0 +1,8 @@
1
+ /** harness 拥有的配置文件(项目根相对路径,铺放/清点的唯一清单) */
2
+ export declare const HARNESS_CONFIG_FILES: readonly string[];
3
+ /**
4
+ * 把 harness 配置文件集合从 srcRoot 铺到 dstRoot(覆盖已存在的同名文件)
5
+ *
6
+ * @returns 实际铺放的文件(项目根相对路径,顺序 = HARNESS_CONFIG_FILES 声明序)
7
+ */
8
+ export declare function propagateConfig(srcRoot: string, dstRoot: string): string[];
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.HARNESS_CONFIG_FILES = void 0;
37
+ exports.propagateConfig = propagateConfig;
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ /** harness 拥有的配置文件(项目根相对路径,铺放/清点的唯一清单) */
41
+ exports.HARNESS_CONFIG_FILES = [
42
+ path.join('.harness', 'config.yml'),
43
+ path.join('.harness', 'checkpoints.yml'),
44
+ ];
45
+ /**
46
+ * 把 harness 配置文件集合从 srcRoot 铺到 dstRoot(覆盖已存在的同名文件)
47
+ *
48
+ * @returns 实际铺放的文件(项目根相对路径,顺序 = HARNESS_CONFIG_FILES 声明序)
49
+ */
50
+ function propagateConfig(srcRoot, dstRoot) {
51
+ const copied = [];
52
+ for (const rel of exports.HARNESS_CONFIG_FILES) {
53
+ const from = path.join(srcRoot, rel);
54
+ if (!fs.existsSync(from))
55
+ continue;
56
+ const to = path.join(dstRoot, rel);
57
+ fs.mkdirSync(path.dirname(to), { recursive: true });
58
+ fs.copyFileSync(from, to);
59
+ copied.push(rel);
60
+ }
61
+ return copied;
62
+ }
@@ -4,7 +4,7 @@
4
4
  * severity 显式模型(ADR-0029):
5
5
  * - severity='error':检查失败立即抛出异常(block 模式)
6
6
  * - severity='warning':检查失败记录警告
7
- * 全部约束 kind='check';channel='gate' 的约束必须带真实 checker(注册表闭环,
7
+ * channel='gate' 的约束必须带真实 checker(注册表闭环,
8
8
  * ADR-0035),非 gate 条目(workflow/discipline)不进入检查分发。
9
9
  */
10
10
  import { Constraint, ConstraintContext, ConstraintResult, ConstraintCheckResult } from '../../types/constraint';
@@ -5,7 +5,7 @@
5
5
  * severity 显式模型(ADR-0029):
6
6
  * - severity='error':检查失败立即抛出异常(block 模式)
7
7
  * - severity='warning':检查失败记录警告
8
- * 全部约束 kind='check';channel='gate' 的约束必须带真实 checker(注册表闭环,
8
+ * channel='gate' 的约束必须带真实 checker(注册表闭环,
9
9
  * ADR-0035),非 gate 条目(workflow/discipline)不进入检查分发。
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -2,7 +2,7 @@
2
2
  * 约束定义(薄聚合层)
3
3
  *
4
4
  * severity 显式模型(ADR-0029,取代 ADR-0001 三层命名):
5
- * 全部内置约束 kind='check',severity 写死在定义上(error / warning),
5
+ * severity 写死在定义上(error / warning),
6
6
  * 纯文本提示层(prompts.ts)已随文本注入层关停整体删除。
7
7
  *
8
8
  * 工单 20:字面量定义按 severity 分组放 ./definitions/{errors,warnings}.ts
@@ -13,7 +13,7 @@ import type { Constraint } from '../../types/constraint';
13
13
  /** 全部内置约束(check 层全量,severity 在条目上) */
14
14
  export declare const CONSTRAINTS: Record<string, Constraint>;
15
15
  /**
16
- * 获取所有约束(check 全量,带 kind/severity)
16
+ * 获取所有约束(check 全量,带 severity/channel)
17
17
  */
18
18
  export declare function getAllConstraints(): Constraint[];
19
19
  /**
@@ -3,7 +3,7 @@
3
3
  * 约束定义(薄聚合层)
4
4
  *
5
5
  * severity 显式模型(ADR-0029,取代 ADR-0001 三层命名):
6
- * 全部内置约束 kind='check',severity 写死在定义上(error / warning),
6
+ * severity 写死在定义上(error / warning),
7
7
  * 纯文本提示层(prompts.ts)已随文本注入层关停整体删除。
8
8
  *
9
9
  * 工单 20:字面量定义按 severity 分组放 ./definitions/{errors,warnings}.ts
@@ -26,7 +26,7 @@ exports.CONSTRAINTS = {
26
26
  // 辅助函数
27
27
  // ========================================
28
28
  /**
29
- * 获取所有约束(check 全量,带 kind/severity)
29
+ * 获取所有约束(check 全量,带 severity/channel)
30
30
  */
31
31
  function getAllConstraints() {
32
32
  return Object.values(exports.CONSTRAINTS);
@@ -10,7 +10,7 @@ import type { Constraint } from '../types/constraint';
10
10
  import type { MergedConstraintsConfig } from '../types/project-config';
11
11
  import type { RunTarget } from './constraints/run-env';
12
12
  /**
13
- * 获取项目当前生效的约束集(check 全量,带 kind/severity)
13
+ * 获取项目当前生效的约束集(check 全量,带 severity/channel)
14
14
  *
15
15
  * 生效集链路同 getMergedConstraintsConfig:内置 → preset 裁剪 → config.yml
16
16
  * `constraints.<id>.enabled:false` 删除。
@@ -14,7 +14,7 @@ exports.getMergedConstraintsConfig = getMergedConstraintsConfig;
14
14
  exports.lintEffectiveConfig = lintEffectiveConfig;
15
15
  const project_config_loader_1 = require("./project-config-loader");
16
16
  /**
17
- * 获取项目当前生效的约束集(check 全量,带 kind/severity)
17
+ * 获取项目当前生效的约束集(check 全量,带 severity/channel)
18
18
  *
19
19
  * 生效集链路同 getMergedConstraintsConfig:内置 → preset 裁剪 → config.yml
20
20
  * `constraints.<id>.enabled:false` 删除。
@@ -63,7 +63,6 @@ export interface E2ETestResult {
63
63
  */
64
64
  export declare class SpecAcceptanceGate implements Gate {
65
65
  readonly id = "acceptance";
66
- order: number;
67
66
  private config;
68
67
  constructor(config?: Partial<SpecAcceptanceGateConfig>);
69
68
  /**
@@ -141,7 +141,6 @@ function tokenizeCommand(command) {
141
141
  */
142
142
  class SpecAcceptanceGate {
143
143
  id = 'acceptance';
144
- order = 0;
145
144
  config;
146
145
  constructor(config) {
147
146
  this.config = {
@@ -15,7 +15,6 @@ export { DEFAULT_COMMAND_BLACKLIST } from './blacklist-rules';
15
15
  */
16
16
  export declare class CommandGate implements Gate {
17
17
  readonly id = "command";
18
- order: number;
19
18
  private config;
20
19
  private blacklist;
21
20
  constructor(config?: Partial<CommandGateConfig>);
@@ -19,7 +19,6 @@ Object.defineProperty(exports, "DEFAULT_COMMAND_BLACKLIST", { enumerable: true,
19
19
  */
20
20
  class CommandGate {
21
21
  id = 'command';
22
- order = 0;
23
22
  config;
24
23
  blacklist;
25
24
  constructor(config = {}) {
@@ -21,7 +21,6 @@ export interface BreakingChange {
21
21
  */
22
22
  export declare class ContractGate implements Gate {
23
23
  readonly id = "contract";
24
- order: number;
25
24
  private config;
26
25
  constructor(config?: Partial<ContractGateConfig>);
27
26
  /**
@@ -55,7 +55,6 @@ const decision_1 = require("./decision");
55
55
  */
56
56
  class ContractGate {
57
57
  id = 'contract';
58
- order = 0;
59
58
  config;
60
59
  constructor(config = {}) {
61
60
  this.config = {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 门禁定义表(G1:定义即注册的单一定义源)
3
3
  *
4
- * - 每个门禁在此声明 id / description / 默认 order / CLI 元数据;
4
+ * - 每个门禁在此声明 id / description / CLI 元数据;
5
5
  * 「定义↔实现」闭环由 `__tests__/definitions.test.ts` 断言(registry.ts 已删,
6
6
  * 闭环保护改测试形状承载)。
7
7
  * - CLI 元数据即 CommandDefinition(架构评审候选8,ADR-0007:形状对齐通用
@@ -24,12 +24,10 @@ export interface GateDefinition {
24
24
  id: string;
25
25
  /** 一句话描述 */
26
26
  description: string;
27
- /** 默认顺序(以此定义表为准,config.yml 无覆盖口——gates.order 生效集已删,ADR-0002「后续变更」),小者先执行 */
28
- order: number;
29
27
  /** CLI 元数据(形状 = CommandDefinition,bin/harness.js 通用引擎驱动生成) */
30
28
  cli: CommandDefinition;
31
29
  }
32
30
  /**
33
- * 6 门禁定义(默认 order 按字母序,与历史 bin 块顺序一致)
31
+ * 6 门禁定义
34
32
  */
35
33
  export declare const GATE_DEFINITIONS: GateDefinition[];
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * 门禁定义表(G1:定义即注册的单一定义源)
4
4
  *
5
- * - 每个门禁在此声明 id / description / 默认 order / CLI 元数据;
5
+ * - 每个门禁在此声明 id / description / CLI 元数据;
6
6
  * 「定义↔实现」闭环由 `__tests__/definitions.test.ts` 断言(registry.ts 已删,
7
7
  * 闭环保护改测试形状承载)。
8
8
  * - CLI 元数据即 CommandDefinition(架构评审候选8,ADR-0007:形状对齐通用
@@ -20,13 +20,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.GATE_DEFINITIONS = void 0;
21
21
  const numeric_flag_1 = require("../utils/numeric-flag");
22
22
  /**
23
- * 6 门禁定义(默认 order 按字母序,与历史 bin 块顺序一致)
23
+ * 6 门禁定义
24
24
  */
25
25
  exports.GATE_DEFINITIONS = [
26
26
  {
27
27
  id: 'acceptance',
28
28
  description: '验收标准门控,检查任务是否满足验收标准',
29
- order: 0,
30
29
  cli: {
31
30
  command: 'acceptance',
32
31
  alias: 'acc',
@@ -49,7 +48,6 @@ exports.GATE_DEFINITIONS = [
49
48
  {
50
49
  id: 'command',
51
50
  description: '命令黑名单门控,检查命令是否在禁用列表',
52
- order: 1,
53
51
  cli: {
54
52
  command: 'command',
55
53
  alias: 'cmd',
@@ -67,7 +65,6 @@ exports.GATE_DEFINITIONS = [
67
65
  {
68
66
  id: 'contract',
69
67
  description: 'API 契约门控,检查 OpenAPI Schema',
70
- order: 2,
71
68
  cli: {
72
69
  command: 'contract',
73
70
  argument: '[subcommand]',
@@ -88,7 +85,6 @@ exports.GATE_DEFINITIONS = [
88
85
  {
89
86
  id: 'performance',
90
87
  description: '性能门控,检查性能指标',
91
- order: 3,
92
88
  cli: {
93
89
  command: 'performance',
94
90
  alias: 'perf',
@@ -115,7 +111,6 @@ exports.GATE_DEFINITIONS = [
115
111
  {
116
112
  id: 'review',
117
113
  description: '代码审查门控,检查审查状态',
118
- order: 4,
119
114
  cli: {
120
115
  command: 'review',
121
116
  argument: '[subcommand]',
@@ -145,7 +140,6 @@ exports.GATE_DEFINITIONS = [
145
140
  {
146
141
  id: 'security',
147
142
  description: '安全门控,检查安全漏洞',
148
- order: 5,
149
143
  cli: {
150
144
  command: 'security',
151
145
  alias: 'sec',
@@ -27,7 +27,6 @@ export interface ExtendedPerformanceGateConfig extends PerformanceGateConfig {
27
27
  */
28
28
  export declare class PerformanceGate implements Gate {
29
29
  readonly id = "performance";
30
- order: number;
31
30
  private config;
32
31
  constructor(config?: Partial<ExtendedPerformanceGateConfig>);
33
32
  /**
@@ -72,7 +72,6 @@ function execErrorField(error, field) {
72
72
  */
73
73
  class PerformanceGate {
74
74
  id = 'performance';
75
- order = 0;
76
75
  config;
77
76
  constructor(config = {}) {
78
77
  this.config = {
@@ -33,7 +33,6 @@ export declare function parsePrView(stdout: string): GhPrView;
33
33
  */
34
34
  export declare class ReviewGate implements Gate {
35
35
  readonly id = "review";
36
- order: number;
37
36
  private config;
38
37
  constructor(config?: Partial<ReviewGateConfig>);
39
38
  /**
@@ -47,7 +47,6 @@ class ReviewCheckError extends Error {
47
47
  */
48
48
  class ReviewGate {
49
49
  id = 'review';
50
- order = 0;
51
50
  config;
52
51
  constructor(config = {}) {
53
52
  this.config = {
@@ -15,7 +15,6 @@ import type { GateResult, SecurityGateContext, SecurityGateConfig, Gate, GateDec
15
15
  */
16
16
  export declare class SecurityGate implements Gate {
17
17
  readonly id = "security";
18
- order: number;
19
18
  private config;
20
19
  constructor(config?: Partial<SecurityGateConfig>);
21
20
  /**
@@ -35,7 +35,6 @@ function viaTitle(via) {
35
35
  */
36
36
  class SecurityGate {
37
37
  id = 'security';
38
- order = 0;
39
38
  config;
40
39
  constructor(config = {}) {
41
40
  this.config = {
@@ -28,7 +28,7 @@ export declare function fromError(gate: string, label: string, error: unknown, s
28
28
  /**
29
29
  * 统一门禁接口(G1)
30
30
  *
31
- * 统一的是决策协议(id / 声明式 order / evaluate → 三态决策),
31
+ * 统一的是决策协议(id / evaluate → 三态决策),
32
32
  * 各门禁执行细节(gh pr view / 正则黑名单 / OpenAPI diff / benchmark…)私有。
33
33
  *
34
34
  * 注意:各实现 evaluate 收窄使用专属输入类型(`ReviewGateContext` 等),
@@ -39,8 +39,6 @@ export declare function fromError(gate: string, label: string, error: unknown, s
39
39
  export interface Gate {
40
40
  /** 门禁 id(与 gates/definitions.ts 定义一致,注册表闭环校验) */
41
41
  readonly id: string;
42
- /** 声明式顺序(以 gates/definitions.ts 定义表为准,config.yml 无覆盖口——gates.order 生效集已删,ADR-0002「后续变更」),小者先执行 */
43
- order: number;
44
42
  /** 决策协议:返回三态 GateDecision */
45
43
  evaluate(ctx: GateContext): Promise<GateDecision> | GateDecision;
46
44
  }
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * 通用工程约束框架
5
5
  *
6
6
  * 约束体系(ADR-0029 severity 显式模型):
7
- * - 全部约束 kind='check':可执行检查(error 阻断 / warning 告警)
7
+ * - 约束按 channel 分发:gate 通道执行检查(error 阻断 / warning 告警)
8
8
  * - 纯文本提示层已整体关停(ADR-0029)
9
9
  *
10
10
  * 门禁系统:
@@ -22,6 +22,7 @@ export { ConstraintViolationError, } from './types/constraint';
22
22
  export type { Constraint, ConstraintId, ConstraintChannel, ConstraintSeverity, ConstraintTrigger, ConstraintContext, ConstraintResult, ConstraintCheckResult, } from './types/constraint';
23
23
  export { CONSTRAINTS, getAllConstraints, getConstraint, } from './core/constraints/definitions';
24
24
  export { getEffectiveConstraints, } from './core/effective-constraints';
25
+ export { HARNESS_CONFIG_FILES, propagateConfig, } from './core/config-files';
25
26
  export { listRetiredConstraints, } from './core/retired-constraints';
26
27
  export type { RetiredConstraintEntry, RetiredConstraintMeta, } from './core/retired-constraints';
27
28
  export { retireConstraint, reactivateConstraint, disableConstraint, } from './core/constraint-lifecycle';
@@ -43,14 +44,14 @@ export type { PassesGateConfig, PassesGateCheckResult, PassesGateViolation, Test
43
44
  export type { StepMeta, ToolMeta, WorkflowMeta, } from './types/cso';
44
45
  export { DEFAULT_TRACE_FILE, } from './types/trace';
45
46
  export type { ExecutionTrace, TraceFilter, TraceSummary, TraceAnomaly, TraceCollectorConfig, TraceAnalyzerConfig, } from './types/trace';
46
- export { TraceCollector, TraceAnalyzer, } from './monitoring';
47
+ export { TraceCollector, TraceAnalyzer, pruneTraceLogs, } from './monitoring';
47
48
  export { ErrorType, FailureLevel, DEFAULT_FAILURE_LOG_FILE, DEFAULT_CLASSIFICATION_RULES, DEFAULT_LEVEL_MAPPING, ErrorClassifier, FailureRecorder, } from './failure';
48
49
  export type { FailureRecord, ErrorClassificationRule, ClassificationResult, ErrorClassifierConfig, FailureRecorderConfig, } from './failure';
49
50
  export { SessionManager, } from './context';
50
51
  export type { SessionCheckpoint, SessionEvent, SessionEventType, SessionHandle, } from './context';
51
- export { FileKnowledgeStore, KnowledgeQuery, KnowledgeLifecycle, KnowledgeIngest, sanitizeExternalContent, ColdStartImporter, KnowledgeAudit, DEFAULT_DECAY_CONFIG, estimateTokens, } from './knowledge';
52
+ export { FileKnowledgeStore, KnowledgeQuery, KnowledgeLifecycle, KnowledgeIngest, ColdStartImporter, KnowledgeAudit, DEFAULT_DECAY_CONFIG, estimateTokens, } from './knowledge';
52
53
  /**
53
- * 外部来源条目的 prompt 标记标准(harness#161 三层防御第二层 marking 的唯一正本,
54
+ * 外部来源条目的 prompt 标记标准(harness#161 retrieval marking 的唯一正本,
54
55
  * 定义在 `knowledge/query.ts`)。知识注入编排已归下游编排消费方(定位文档裁决),
55
56
  * 本标记作为标准/家具保留公开导出:消费方自行格式化注入内容时以此常量对齐标记,
56
57
  * 不得另存字面量。
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * 通用工程约束框架
6
6
  *
7
7
  * 约束体系(ADR-0029 severity 显式模型):
8
- * - 全部约束 kind='check':可执行检查(error 阻断 / warning 告警)
8
+ * - 约束按 channel 分发:gate 通道执行检查(error 阻断 / warning 告警)
9
9
  * - 纯文本提示层已整体关停(ADR-0029)
10
10
  *
11
11
  * 门禁系统:
@@ -20,8 +20,8 @@
20
20
  * (ConstraintChecker / ProjectConfigLoader)不进公共清单。
21
21
  */
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.verifyTddChain = exports.classifyCommitFiles = exports.EXTERNAL_SOURCE_MARKER = exports.estimateTokens = exports.DEFAULT_DECAY_CONFIG = exports.KnowledgeAudit = exports.ColdStartImporter = exports.sanitizeExternalContent = exports.KnowledgeIngest = exports.KnowledgeLifecycle = exports.KnowledgeQuery = exports.FileKnowledgeStore = exports.SessionManager = exports.FailureRecorder = exports.ErrorClassifier = exports.DEFAULT_LEVEL_MAPPING = exports.DEFAULT_CLASSIFICATION_RULES = exports.DEFAULT_FAILURE_LOG_FILE = exports.FailureLevel = exports.ErrorType = exports.TraceAnalyzer = exports.TraceCollector = exports.DEFAULT_TRACE_FILE = exports.CSOValidator = exports.PassesGate = exports.CheckpointValidator = exports.formatEvidence = exports.normalizeCheckOutcome = exports.buildCheckEnv = exports.collectConstraints = exports.checkConstraints = exports.checkConstraint = exports.DEFAULT_DIAGNOSE_THRESHOLDS = exports.CANDIDATE_KIND_LABEL = exports.readProjectTracesReport = exports.collectUsageByConstraint = exports.buildConstraintsUsageReport = exports.getConstraintsMeta = exports.renderProposalMarkdown = exports.collectProposalMaterial = exports.packProposal = exports.disableConstraint = exports.reactivateConstraint = exports.retireConstraint = exports.listRetiredConstraints = exports.getEffectiveConstraints = exports.getConstraint = exports.getAllConstraints = exports.CONSTRAINTS = exports.ConstraintViolationError = void 0;
24
- exports.AgentLifecycle = exports.bootstrapHarnessSync = exports.bootstrapHarness = exports.verifyReleaseArtifacts = exports.getCriticalArtifacts = exports.verifyContractPresence = exports.PHASE_SUBJECT_RE = exports.verifyPhaseFormat = exports.TESTS_NONE_RE = exports.TESTED_BY_RE = void 0;
23
+ exports.EXTERNAL_SOURCE_MARKER = exports.estimateTokens = exports.DEFAULT_DECAY_CONFIG = exports.KnowledgeAudit = exports.ColdStartImporter = exports.KnowledgeIngest = exports.KnowledgeLifecycle = exports.KnowledgeQuery = exports.FileKnowledgeStore = exports.SessionManager = exports.FailureRecorder = exports.ErrorClassifier = exports.DEFAULT_LEVEL_MAPPING = exports.DEFAULT_CLASSIFICATION_RULES = exports.DEFAULT_FAILURE_LOG_FILE = exports.FailureLevel = exports.ErrorType = exports.pruneTraceLogs = exports.TraceAnalyzer = exports.TraceCollector = exports.DEFAULT_TRACE_FILE = exports.CSOValidator = exports.PassesGate = exports.CheckpointValidator = exports.formatEvidence = exports.normalizeCheckOutcome = exports.buildCheckEnv = exports.collectConstraints = exports.checkConstraints = exports.checkConstraint = exports.DEFAULT_DIAGNOSE_THRESHOLDS = exports.CANDIDATE_KIND_LABEL = exports.readProjectTracesReport = exports.collectUsageByConstraint = exports.buildConstraintsUsageReport = exports.getConstraintsMeta = exports.renderProposalMarkdown = exports.collectProposalMaterial = exports.packProposal = exports.disableConstraint = exports.reactivateConstraint = exports.retireConstraint = exports.listRetiredConstraints = exports.propagateConfig = exports.HARNESS_CONFIG_FILES = exports.getEffectiveConstraints = exports.getConstraint = exports.getAllConstraints = exports.CONSTRAINTS = exports.ConstraintViolationError = void 0;
24
+ exports.AgentLifecycle = exports.bootstrapHarnessSync = exports.bootstrapHarness = exports.verifyReleaseArtifacts = exports.getCriticalArtifacts = exports.verifyContractPresence = exports.PHASE_SUBJECT_RE = exports.verifyPhaseFormat = exports.TESTS_NONE_RE = exports.TESTED_BY_RE = exports.verifyTddChain = exports.classifyCommitFiles = void 0;
25
25
  // ========================================
26
26
  // 约束类型(severity 显式模型)
27
27
  // ========================================
@@ -36,6 +36,9 @@ Object.defineProperty(exports, "getAllConstraints", { enumerable: true, get: fun
36
36
  Object.defineProperty(exports, "getConstraint", { enumerable: true, get: function () { return definitions_1.getConstraint; } });
37
37
  var effective_constraints_1 = require("./core/effective-constraints");
38
38
  Object.defineProperty(exports, "getEffectiveConstraints", { enumerable: true, get: function () { return effective_constraints_1.getEffectiveConstraints; } });
39
+ var config_files_1 = require("./core/config-files");
40
+ Object.defineProperty(exports, "HARNESS_CONFIG_FILES", { enumerable: true, get: function () { return config_files_1.HARNESS_CONFIG_FILES; } });
41
+ Object.defineProperty(exports, "propagateConfig", { enumerable: true, get: function () { return config_files_1.propagateConfig; } });
39
42
  var retired_constraints_1 = require("./core/retired-constraints");
40
43
  Object.defineProperty(exports, "listRetiredConstraints", { enumerable: true, get: function () { return retired_constraints_1.listRetiredConstraints; } });
41
44
  // ========================================
@@ -85,13 +88,14 @@ Object.defineProperty(exports, "CheckpointValidator", { enumerable: true, get: f
85
88
  Object.defineProperty(exports, "PassesGate", { enumerable: true, get: function () { return validators_1.PassesGate; } });
86
89
  Object.defineProperty(exports, "CSOValidator", { enumerable: true, get: function () { return validators_1.CSOValidator; } });
87
90
  // ========================================
88
- // 监控(Execution Trace 收集/分析)
91
+ // 监控(Execution Trace 收集/分析/轮转备份清理)
89
92
  // ========================================
90
93
  var trace_1 = require("./types/trace");
91
94
  Object.defineProperty(exports, "DEFAULT_TRACE_FILE", { enumerable: true, get: function () { return trace_1.DEFAULT_TRACE_FILE; } });
92
95
  var monitoring_1 = require("./monitoring");
93
96
  Object.defineProperty(exports, "TraceCollector", { enumerable: true, get: function () { return monitoring_1.TraceCollector; } });
94
97
  Object.defineProperty(exports, "TraceAnalyzer", { enumerable: true, get: function () { return monitoring_1.TraceAnalyzer; } });
98
+ Object.defineProperty(exports, "pruneTraceLogs", { enumerable: true, get: function () { return monitoring_1.pruneTraceLogs; } });
95
99
  // ========================================
96
100
  // 失败处理(错误分类 + 记录 + 违规处理策略)
97
101
  // ========================================
@@ -116,13 +120,12 @@ Object.defineProperty(exports, "FileKnowledgeStore", { enumerable: true, get: fu
116
120
  Object.defineProperty(exports, "KnowledgeQuery", { enumerable: true, get: function () { return knowledge_1.KnowledgeQuery; } });
117
121
  Object.defineProperty(exports, "KnowledgeLifecycle", { enumerable: true, get: function () { return knowledge_1.KnowledgeLifecycle; } });
118
122
  Object.defineProperty(exports, "KnowledgeIngest", { enumerable: true, get: function () { return knowledge_1.KnowledgeIngest; } });
119
- Object.defineProperty(exports, "sanitizeExternalContent", { enumerable: true, get: function () { return knowledge_1.sanitizeExternalContent; } });
120
123
  Object.defineProperty(exports, "ColdStartImporter", { enumerable: true, get: function () { return knowledge_1.ColdStartImporter; } });
121
124
  Object.defineProperty(exports, "KnowledgeAudit", { enumerable: true, get: function () { return knowledge_1.KnowledgeAudit; } });
122
125
  Object.defineProperty(exports, "DEFAULT_DECAY_CONFIG", { enumerable: true, get: function () { return knowledge_1.DEFAULT_DECAY_CONFIG; } });
123
126
  Object.defineProperty(exports, "estimateTokens", { enumerable: true, get: function () { return knowledge_1.estimateTokens; } });
124
127
  /**
125
- * 外部来源条目的 prompt 标记标准(harness#161 三层防御第二层 marking 的唯一正本,
128
+ * 外部来源条目的 prompt 标记标准(harness#161 retrieval marking 的唯一正本,
126
129
  * 定义在 `knowledge/query.ts`)。知识注入编排已归下游编排消费方(定位文档裁决),
127
130
  * 本标记作为标准/家具保留公开导出:消费方自行格式化注入内容时以此常量对齐标记,
128
131
  * 不得另存字面量。
@@ -11,7 +11,7 @@ export { KnowledgeQuery, EXTERNAL_SOURCE_MARKER } from './query';
11
11
  export { estimateTokens } from './token-estimate';
12
12
  export { KnowledgeLifecycle } from './lifecycle';
13
13
  export type { ConsumptionEvent } from './lifecycle';
14
- export { KnowledgeIngest, sanitizeExternalContent } from './ingest';
14
+ export { KnowledgeIngest } from './ingest';
15
15
  export type { IngestValidationIssue } from './ingest';
16
16
  export { ColdStartImporter } from './cold-start';
17
17
  export { KnowledgeAudit } from './audit';
@@ -5,7 +5,7 @@
5
5
  * Re-exports all knowledge module components.
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.KnowledgeAudit = exports.ColdStartImporter = exports.sanitizeExternalContent = exports.KnowledgeIngest = exports.KnowledgeLifecycle = exports.estimateTokens = exports.EXTERNAL_SOURCE_MARKER = exports.KnowledgeQuery = exports.FileKnowledgeStore = exports.DEFAULT_DECAY_CONFIG = void 0;
8
+ exports.KnowledgeAudit = exports.ColdStartImporter = exports.KnowledgeIngest = exports.KnowledgeLifecycle = exports.estimateTokens = exports.EXTERNAL_SOURCE_MARKER = exports.KnowledgeQuery = exports.FileKnowledgeStore = exports.DEFAULT_DECAY_CONFIG = void 0;
9
9
  var types_1 = require("./types");
10
10
  Object.defineProperty(exports, "DEFAULT_DECAY_CONFIG", { enumerable: true, get: function () { return types_1.DEFAULT_DECAY_CONFIG; } });
11
11
  var store_1 = require("./store");
@@ -19,7 +19,6 @@ var lifecycle_1 = require("./lifecycle");
19
19
  Object.defineProperty(exports, "KnowledgeLifecycle", { enumerable: true, get: function () { return lifecycle_1.KnowledgeLifecycle; } });
20
20
  var ingest_1 = require("./ingest");
21
21
  Object.defineProperty(exports, "KnowledgeIngest", { enumerable: true, get: function () { return ingest_1.KnowledgeIngest; } });
22
- Object.defineProperty(exports, "sanitizeExternalContent", { enumerable: true, get: function () { return ingest_1.sanitizeExternalContent; } });
23
22
  var cold_start_1 = require("./cold-start");
24
23
  Object.defineProperty(exports, "ColdStartImporter", { enumerable: true, get: function () { return cold_start_1.ColdStartImporter; } });
25
24
  var audit_1 = require("./audit");
@@ -16,7 +16,7 @@ export interface IngestValidationIssue {
16
16
  suggestion: string;
17
17
  }
18
18
  /**
19
- * `ingestEntry` / `ingestBatch` / `ingestExternal` 的返回(判别联合):
19
+ * `ingestEntry` / `ingestBatch` 的返回(判别联合):
20
20
  * - `accepted`:已落盘(新建或去重合并),`entry` 为最终形态
21
21
  * - `rejected`:审计质量门拒收、未落盘,`reasons` 为逐条拒绝理由
22
22
  *
@@ -31,13 +31,6 @@ export type IngestResult = {
31
31
  entry: KnowledgeEntry;
32
32
  reasons: string[];
33
33
  };
34
- /**
35
- * Sanitize external content for safe ingest.
36
- * - Strips known prompt injection patterns
37
- * - Limits content length
38
- * - Returns sanitized string
39
- */
40
- export declare function sanitizeExternalContent(content: string): string;
41
34
  export declare class KnowledgeIngest {
42
35
  private store;
43
36
  constructor(store: KnowledgeStore);
@@ -60,15 +53,6 @@ export declare class KnowledgeIngest {
60
53
  * 空批零读写。单条路径(ingestEntry)写时序不变。
61
54
  */
62
55
  ingestBatch(partials: Partial<KnowledgeEntry>[], options: IngestOptions): IngestResult[];
63
- /**
64
- * Ingest external content with sanitization.
65
- * - Sanitizes content (strips injection patterns, limits length)
66
- * - Forces origin: 'external'
67
- * - Uses consumptionMode from options (default: 'reference')
68
- */
69
- ingestExternal(partial: Partial<KnowledgeEntry>, options: Omit<IngestOptions, 'origin'> & {
70
- fullContentPath?: string;
71
- }): IngestResult;
72
56
  /**
73
57
  * 摄入前单条校验(KnowledgeLinter.validateEntry 的保种落点,ADR-0040 Phase 4;
74
58
  * 原 lint.ts 随 audit 正本收口删除)。返回空数组 = 可摄入。
@@ -7,42 +7,10 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.KnowledgeIngest = void 0;
10
- exports.sanitizeExternalContent = sanitizeExternalContent;
11
10
  const types_1 = require("./types");
12
11
  const audit_1 = require("./audit");
13
12
  const audit_rules_1 = require("./audit-rules");
14
13
  const frontmatter_1 = require("../utils/frontmatter");
15
- const MAX_EXTERNAL_CONTENT_LENGTH = 5000;
16
- /** Known prompt injection patterns to strip from external content */
17
- const INJECTION_PATTERNS = [
18
- /ignore\s+(all\s+)?previous\s+instructions/gi,
19
- /ignore\s+(all\s+)?prior\s+instructions/gi,
20
- /system:\s*/gi,
21
- /\[INST\]/gi,
22
- /\[\/INST\]/gi,
23
- /<\|im_start\|>/gi,
24
- /<\|im_end\|>/gi,
25
- /you\s+are\s+now\s+/gi,
26
- /forget\s+(everything|all)\s+(you|about)/gi,
27
- /new\s+instructions?:/gi,
28
- /override\s+(your|system)\s+(instructions|prompt)/gi,
29
- ];
30
- /**
31
- * Sanitize external content for safe ingest.
32
- * - Strips known prompt injection patterns
33
- * - Limits content length
34
- * - Returns sanitized string
35
- */
36
- function sanitizeExternalContent(content) {
37
- let sanitized = content;
38
- for (const pattern of INJECTION_PATTERNS) {
39
- sanitized = sanitized.replace(pattern, '[FILTERED]');
40
- }
41
- if (sanitized.length > MAX_EXTERNAL_CONTENT_LENGTH) {
42
- sanitized = sanitized.slice(0, MAX_EXTERNAL_CONTENT_LENGTH) + '...[truncated]';
43
- }
44
- return sanitized;
45
- }
46
14
  // ── Ingest ─────────────────────────────────────────────────
47
15
  /**
48
16
  * D7 ingest 批内上下文(包内私有):磁盘去重基线与虚拟序号起点惰性各读一次,
@@ -137,16 +105,6 @@ class KnowledgeIngest {
137
105
  }
138
106
  return results;
139
107
  }
140
- /**
141
- * Ingest external content with sanitization.
142
- * - Sanitizes content (strips injection patterns, limits length)
143
- * - Forces origin: 'external'
144
- * - Uses consumptionMode from options (default: 'reference')
145
- */
146
- ingestExternal(partial, options) {
147
- const sanitizedContent = sanitizeExternalContent(partial.content || '');
148
- return this.ingestEntry({ ...partial, content: sanitizedContent }, { ...options, origin: 'external' });
149
- }
150
108
  /**
151
109
  * 摄入前单条校验(KnowledgeLinter.validateEntry 的保种落点,ADR-0040 Phase 4;
152
110
  * 原 lint.ts 随 audit 正本收口删除)。返回空数组 = 可摄入。
@@ -8,7 +8,7 @@ import type { KnowledgeEntry, ConsumptionMode, QueryBudget, QueryResult, QueryFi
8
8
  import type { KnowledgeStore } from './store';
9
9
  import { KnowledgeLifecycle } from './lifecycle';
10
10
  /**
11
- * 外部来源条目的 prompt 标记(harness#161:三层防御第二层 marking 的唯一正本)。
11
+ * 外部来源条目的 retrieval marking 标准(harness#161:唯一正本)。
12
12
  * `KnowledgeQuery.formatForPrompt()` 与下游编排消费方的注入格式化共用同一常量,
13
13
  * 仓内不允许存在第二份字面量。
14
14
  */
@@ -14,7 +14,7 @@ const attempt_1 = require("../utils/attempt");
14
14
  // ── Constants ──────────────────────────────────────────────
15
15
  const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
16
16
  /**
17
- * 外部来源条目的 prompt 标记(harness#161:三层防御第二层 marking 的唯一正本)。
17
+ * 外部来源条目的 retrieval marking 标准(harness#161:唯一正本)。
18
18
  * `KnowledgeQuery.formatForPrompt()` 与下游编排消费方的注入格式化共用同一常量,
19
19
  * 仓内不允许存在第二份字面量。
20
20
  */
@@ -4,6 +4,7 @@
4
4
  * Execution Trace 系统:
5
5
  * - TraceCollector:轻量收集,零 Token
6
6
  * - TraceAnalyzer:统计汇总,异常检测
7
+ * - pruneTraceLogs:轮转备份清理
7
8
  */
8
- export { TraceCollector } from './traces';
9
+ export { TraceCollector, pruneTraceLogs } from './traces';
9
10
  export { TraceAnalyzer } from './trace-analyzer';
@@ -5,10 +5,12 @@
5
5
  * Execution Trace 系统:
6
6
  * - TraceCollector:轻量收集,零 Token
7
7
  * - TraceAnalyzer:统计汇总,异常检测
8
+ * - pruneTraceLogs:轮转备份清理
8
9
  */
9
10
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.TraceAnalyzer = exports.TraceCollector = void 0;
11
+ exports.TraceAnalyzer = exports.pruneTraceLogs = exports.TraceCollector = void 0;
11
12
  var traces_1 = require("./traces");
12
13
  Object.defineProperty(exports, "TraceCollector", { enumerable: true, get: function () { return traces_1.TraceCollector; } });
14
+ Object.defineProperty(exports, "pruneTraceLogs", { enumerable: true, get: function () { return traces_1.pruneTraceLogs; } });
13
15
  var trace_analyzer_1 = require("./trace-analyzer");
14
16
  Object.defineProperty(exports, "TraceAnalyzer", { enumerable: true, get: function () { return trace_analyzer_1.TraceAnalyzer; } });
@@ -9,6 +9,18 @@
9
9
  * - 文件滚动(防止文件过大)
10
10
  */
11
11
  import { type ExecutionTrace, type TraceFilter, type TraceCollectorConfig } from '../types/trace';
12
+ import type { RunTarget } from '../core/constraints/run-env';
13
+ /**
14
+ * traces 轮转备份清理的独立库入口(harness#198,#216 恢复)
15
+ *
16
+ * 不构造 TraceCollector——traces 目录不存在时 no-op 返回 0、不创建目录。
17
+ *
18
+ * @param target 项目根路径,或本 run 的运行级观察面
19
+ * @returns 实际删除的备份文件数
20
+ */
21
+ export declare function pruneTraceLogs(target: RunTarget, options?: {
22
+ maxAgeDays?: number;
23
+ }): number;
12
24
  /**
13
25
  * Trace 收集器
14
26
  *
@@ -44,24 +44,34 @@ var __importStar = (this && this.__importStar) || (function () {
44
44
  })();
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
46
  exports.TraceCollector = void 0;
47
+ exports.pruneTraceLogs = pruneTraceLogs;
47
48
  const fs = __importStar(require("fs"));
48
49
  const path = __importStar(require("path"));
49
50
  const jsonl_1 = require("../utils/jsonl");
50
51
  const log_rotate_1 = require("../utils/log-rotate");
51
52
  const trace_1 = require("../types/trace");
52
53
  /**
53
- * 清理某 trace 文件的轮转备份(traces-*.log):删除超过 maxAgeDays 天的 `.log` 备份,
54
- * 当前文件(traceFile 本体)与其他非 `.log` 文件不动。目录不存在 → 0。
54
+ * 清理某 trace 文件对应的时间戳轮转备份:删除超过 maxAgeDays 天的备份,
55
+ * 当前文件(traceFile 本体)、其他日志与非 `.log` 文件不动。目录不存在 → 0。
55
56
  *
56
- * `TraceCollector.cleanupOldFiles` 的实现本体(harness#198)。
57
+ * `TraceCollector.cleanupOldFiles` 与 `pruneTraceLogs` 共用的唯一实现(harness#198)。
57
58
  */
58
59
  function pruneRotatedTraceFiles(traceFile, maxAgeDays) {
59
60
  const dir = path.dirname(traceFile);
60
61
  if (!fs.existsSync(dir)) {
61
62
  return 0;
62
63
  }
64
+ const traceName = path.basename(traceFile);
65
+ const logExtensionIndex = traceName.indexOf('.log');
66
+ const backupPrefix = logExtensionIndex >= 0 ? `${traceName.slice(0, logExtensionIndex)}-` : '';
67
+ const backupSuffix = logExtensionIndex >= 0 ? traceName.slice(logExtensionIndex) : '';
68
+ const timestampPattern = /^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z$/;
63
69
  const files = fs.readdirSync(dir);
64
- const backupFiles = files.filter(f => f.endsWith('.log') && f !== path.basename(traceFile));
70
+ const backupFiles = backupPrefix
71
+ ? files.filter(f => f.startsWith(backupPrefix) &&
72
+ f.endsWith(backupSuffix) &&
73
+ timestampPattern.test(f.slice(backupPrefix.length, -backupSuffix.length)))
74
+ : [];
65
75
  const cutoffTime = Date.now() - maxAgeDays * 24 * 3600 * 1000;
66
76
  let deletedCount = 0;
67
77
  for (const file of backupFiles) {
@@ -74,6 +84,18 @@ function pruneRotatedTraceFiles(traceFile, maxAgeDays) {
74
84
  }
75
85
  return deletedCount;
76
86
  }
87
+ /**
88
+ * traces 轮转备份清理的独立库入口(harness#198,#216 恢复)
89
+ *
90
+ * 不构造 TraceCollector——traces 目录不存在时 no-op 返回 0、不创建目录。
91
+ *
92
+ * @param target 项目根路径,或本 run 的运行级观察面
93
+ * @returns 实际删除的备份文件数
94
+ */
95
+ function pruneTraceLogs(target, options = {}) {
96
+ const projectPath = typeof target === 'string' ? target : target.projectPath;
97
+ return pruneRotatedTraceFiles(path.resolve(projectPath, trace_1.DEFAULT_TRACE_FILE), options.maxAgeDays ?? 30);
98
+ }
77
99
  /**
78
100
  * 默认配置
79
101
  *
@@ -145,10 +145,6 @@ export interface ConstraintContext {
145
145
  * code_implementation 记录在此;匹配约束时 operation 与 extraTriggers 一并参与。
146
146
  */
147
147
  extraTriggers?: ConstraintTrigger[];
148
- /** 工作流 ID */
149
- workflowId?: string;
150
- /** 步骤 ID */
151
- stepId?: string;
152
148
  /** 任务描述 */
153
149
  taskDescription?: string;
154
150
  /** 项目路径 */
@@ -157,14 +153,6 @@ export interface ConstraintContext {
157
153
  sessionId?: string;
158
154
  /** 变更的文件列表 */
159
155
  changedFiles?: string[];
160
- /** 提交信息 */
161
- commitMessage?: string;
162
- /** 分支名称 */
163
- branch?: string;
164
- /** 是否已通过诊断→修复闸门(设计方案已确认) */
165
- hasPlanApproval?: boolean;
166
- /** worktree 路径(用于 worktree 相关检查) */
167
- worktreePath?: string;
168
156
  }
169
157
  /**
170
158
  * 约束违规错误
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dommaker/harness",
3
- "version": "4.0.2",
3
+ "version": "5.0.0",
4
4
  "description": "通用工程约束框架 - 约束检查(severity 分级)、检查点验证、测试门控",
5
5
  "keywords": [
6
6
  "harness",