Skip to content

Commit cce8793

Browse files
committed
feat(agent-workspace): add adaptive threshold simulation and guarded remediation
1 parent dc1e0f3 commit cce8793

8 files changed

Lines changed: 669 additions & 3 deletions

docs/brainstorms/2026-04-16-mainline-ci-stabilization-and-m7-direction-requirements.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,33 @@ Deliverables:
360360
- `npm run test:agent-workspace:contracts`
361361
- `npm run verify:agent-workspace:runtime`
362362

363+
### M7.11 (Now): Adaptive Threshold-Policy Simulation and Auto-Remediation Guardrails (Lane Ops Bridge)
364+
365+
Deliverables:
366+
367+
- add adaptive threshold-policy simulation route bound to triage/history signals.
368+
- add guarded auto-remediation route with dry-run/apply/blocked modes.
369+
- enforce deterministic remediation guardrails (minimum sample depth and bounded deltas) before persistence.
370+
371+
#### M7.11 Progress Note (2026-04-16)
372+
373+
- [Done] expanded `src/server.ts` with adaptive policy simulation route:
374+
- `GET /api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds/simulate?window=...&strategy=...`.
375+
- [Done] expanded `src/server.ts` with guarded remediation route:
376+
- `POST /api/knowledge/operator/agent-workspace-diagnostics/triage/remediation`.
377+
- [Done] landed bounded remediation guardrails:
378+
- minimum indexed/history sample requirements before apply,
379+
- replay-rate/top-limit/history-window delta caps before apply,
380+
- deterministic mode outputs (`dry-run`, `applied`, `blocked`, `noop`).
381+
- [Done] expanded evidence coverage:
382+
- `src/server.migration.test.ts` now validates simulation payloads, dry-run immutability, apply-path persistence, blocked-path guardrails, and audit traceability,
383+
- `src/knowledge.api.contract.test.ts` now fail-fast checks simulation/remediation route contracts,
384+
- `src/agent_workspace.verification.contract.test.ts` + `scripts/verify-agent-workspace-runtime.js` now fail fast on simulation/remediation helper/route drift.
385+
- [Done] verification evidence:
386+
- `npm test -- src/server.migration.test.ts --runInBand --testNamePattern "triage route summarizes replay risk|triage history and alert-threshold governance|adaptive threshold simulation and remediation guardrails"`
387+
- `npm run test:agent-workspace:contracts`
388+
- `npm run verify:agent-workspace:runtime`
389+
363390
## Success Criteria
364391

365392
- CI failure mode that previously blocked the three agent-workspace suites is eliminated on mainline.
@@ -369,4 +396,4 @@ Deliverables:
369396

370397
## Next Step
371398

372-
Proceed to `/prompts:ce-plan` using this document as the source for `M7.11` decomposition (adaptive threshold-policy simulation and auto-remediation guardrails), while preserving M7 lane boundary constraints.
399+
Proceed to `/prompts:ce-plan` using this document as the source for `M7.12` decomposition (remediation efficacy backtesting and operator approval gates), while preserving M7 lane boundary constraints.

docs/diataxis/en/explanation/development-progress-dashboard.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,25 @@ Execution anchor:
405405
- `npm run test:agent-workspace:contracts`
406406
- `npm run verify:agent-workspace:runtime`
407407

408+
## Latest Mainline Increment (2026-04-16 M7.11 Adaptive Threshold Simulation and Guarded Auto-Remediation Lane)
409+
410+
- Expanded `src/server.ts` with adaptive threshold-policy simulation route:
411+
- `GET /api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds/simulate?window=...&strategy=...`.
412+
- Expanded `src/server.ts` with guarded auto-remediation route:
413+
- `POST /api/knowledge/operator/agent-workspace-diagnostics/triage/remediation`.
414+
- Added deterministic remediation guardrails:
415+
- minimum indexed/history sample depth before apply,
416+
- bounded replay-rate/top-replay/history-window deltas before apply,
417+
- deterministic remediation outcome modes (`dry-run`, `applied`, `blocked`, `noop`).
418+
- Expanded executable evidence:
419+
- `src/server.migration.test.ts` now validates simulation payload semantics, dry-run immutability, apply-path threshold persistence, blocked-path guardrail enforcement, and audit traceability.
420+
- Hardened runtime verification gate:
421+
- `src/knowledge.api.contract.test.ts`, `src/agent_workspace.verification.contract.test.ts`, and `scripts/verify-agent-workspace-runtime.js` now fail fast on simulation/remediation route and helper drift.
422+
- Verification evidence:
423+
- `npm test -- src/server.migration.test.ts --runInBand --testNamePattern \"triage route summarizes replay risk|triage history and alert-threshold governance|adaptive threshold simulation and remediation guardrails\"`
424+
- `npm run test:agent-workspace:contracts`
425+
- `npm run verify:agent-workspace:runtime`
426+
408427
## Mainline vs Working-Branch Snapshot (2026-04-14)
409428

410429
| Capability Slice | Working Branch (`feat/learning-multi-tutor-adapter`) | Mainline (`origin/main`) | Integration Status |
@@ -453,7 +472,7 @@ This dashboard aligns against the following requirement chain:
453472
| L2 Retrieval | explainable hybrid/vector retrieval + governance | Expanded in branch-oriented plans | Mainline file-backed baseline only (`src/learning/store.ts`) | Re-enter lane after concrete module evidence lands on mainline |
454473
| L3 Learning | mastery diagnostics + path/session loop | Expanded in branch | Partially integrated | Contract and integration parity |
455474
| L4 Interaction | agent conversation + focus/path pane runtime | Implemented in branch | M1-M4 baseline integrated on mainline | Expand capability surface via typed contract only |
456-
| L5 Governance | runbook, diagnostics, replay/autonomy controls | Expanded in branch | Operator diagnostics persistence/triage/history/threshold governance + runbook automation/audit baseline integrated | Expand adaptive policy simulation and CI evidence depth |
475+
| L5 Governance | runbook, diagnostics, replay/autonomy controls | Expanded in branch | Operator diagnostics persistence/triage/history/threshold governance + runbook automation/audit + adaptive simulation/remediation baseline integrated | Add remediation efficacy backtesting and approval-gate evidence |
457476

458477
## Verification Baseline
459478

docs/diataxis/zh/explanation/development-progress-dashboard.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,25 @@
407407
- `npm run test:agent-workspace:contracts`
408408
- `npm run verify:agent-workspace:runtime`
409409

410+
## 主线最新增量(2026-04-16 M7.11 自适应阈值模拟与受护栏自动修复链路)
411+
412+
- 已在 `src/server.ts` 增加自适应阈值策略模拟路由面:
413+
- `GET /api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds/simulate?window=...&strategy=...`
414+
- 已在 `src/server.ts` 增加受护栏自动修复路由面:
415+
- `POST /api/knowledge/operator/agent-workspace-diagnostics/triage/remediation`
416+
- 已增加确定性自动修复护栏:
417+
- apply 前强制最小 indexed/history 样本深度,
418+
- apply 前强制 replay-rate/top-replay/history-window 的有界 delta,
419+
- 输出确定性 remediation mode(`dry-run``applied``blocked``noop`)。
420+
- 已补可执行证据:
421+
- `src/server.migration.test.ts` 新增 simulation 语义、dry-run 不变性、apply 路径阈值落盘、blocked 路径护栏与审计追踪断言。
422+
- 已加固 runtime 门禁:
423+
- `src/knowledge.api.contract.test.ts``src/agent_workspace.verification.contract.test.ts``scripts/verify-agent-workspace-runtime.js` 新增 simulation/remediation 路由与 helper 的 fail-fast 断言。
424+
- 验证证据:
425+
- `npm test -- src/server.migration.test.ts --runInBand --testNamePattern \"triage route summarizes replay risk|triage history and alert-threshold governance|adaptive threshold simulation and remediation guardrails\"`
426+
- `npm run test:agent-workspace:contracts`
427+
- `npm run verify:agent-workspace:runtime`
428+
410429
## 主线 vs 工作分支快照(2026-04-14)
411430

412431
| 能力切片 | 工作分支(`feat/learning-multi-tutor-adapter`| 主线(`origin/main`| 集成状态 |
@@ -455,7 +474,7 @@
455474
| L2 检索层 | 可解释混合/向量检索 + 治理 | 分支规划增强中 | 主线当前为 file-backed 基线(`src/learning/store.ts`| 待主线出现对应模块证据后再收敛 |
456475
| L3 学习层 | 掌握诊断 + 路径/会话闭环 | 分支增强中 | 主线部分集成 | 契约与集成一致性 |
457476
| L4 交互层 | agent 对话 + focus/path pane 运行时 | 分支已实现 | 主线 M1-M4 已落入基线 | 继续通过 typed contract 扩展动作面 |
458-
| L5 治理层 | runbook/诊断/回放与自动化 | 分支增强中 | 主线已集成运维诊断持久化/分级/趋势历史/阈值治理 + runbook 自动化/阈值审计基线 | 扩展自适应策略模拟与 CI 证据深度 |
477+
| L5 治理层 | runbook/诊断/回放与自动化 | 分支增强中 | 主线已集成运维诊断持久化/分级/趋势历史/阈值治理 + runbook 自动化/阈值审计 + 自适应模拟/自动修复基线 | 增补修复效果回测与人工批准门禁证据 |
459478

460479
## 验证基线
461480

scripts/verify-agent-workspace-runtime.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,18 @@ function verifyAgentWorkspaceRuntime(repoRoot = path.resolve(__dirname, '..')) {
120120
serverSource.includes('/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds'),
121121
'Missing diagnostics triage thresholds route in src/server.ts'
122122
);
123+
assert(
124+
serverSource.includes('/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds/simulate'),
125+
'Missing diagnostics triage threshold simulation route in src/server.ts'
126+
);
123127
assert(
124128
serverSource.includes('/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds/audit'),
125129
'Missing diagnostics triage thresholds audit route in src/server.ts'
126130
);
131+
assert(
132+
serverSource.includes('/api/knowledge/operator/agent-workspace-diagnostics/triage/remediation'),
133+
'Missing diagnostics triage remediation route in src/server.ts'
134+
);
127135
assert(
128136
serverSource.includes('cleanupStaleAgentWorkspaceDiagnosticsReports'),
129137
'Missing diagnostics retention cleanup helper in src/server.ts'
@@ -140,6 +148,14 @@ function verifyAgentWorkspaceRuntime(repoRoot = path.resolve(__dirname, '..')) {
140148
serverSource.includes('persistAgentWorkspaceDiagnosticsAlertThresholds'),
141149
'Missing diagnostics triage threshold writer in src/server.ts'
142150
);
151+
assert(
152+
serverSource.includes('buildAgentWorkspaceDiagnosticsThresholdPolicySimulation'),
153+
'Missing diagnostics threshold policy simulation helper in src/server.ts'
154+
);
155+
assert(
156+
serverSource.includes('executeAgentWorkspaceDiagnosticsAutoRemediation'),
157+
'Missing diagnostics auto-remediation helper in src/server.ts'
158+
);
143159
assert(
144160
serverSource.includes('readAgentWorkspaceDiagnosticsThresholdAuditTrail'),
145161
'Missing diagnostics threshold audit reader in src/server.ts'
@@ -167,9 +183,12 @@ function verifyAgentWorkspaceRuntime(repoRoot = path.resolve(__dirname, '..')) {
167183
'diagnostics triage history route exists',
168184
'diagnostics triage runbook route exists',
169185
'diagnostics triage threshold governance routes exist',
186+
'diagnostics triage threshold simulation route exists',
170187
'diagnostics triage threshold audit route exists',
188+
'diagnostics triage remediation route exists',
171189
'diagnostics retention governance exists',
172190
'diagnostics alert-threshold governance helpers exist',
191+
'diagnostics threshold simulation and remediation helpers exist',
173192
'diagnostics threshold audit helpers exist',
174193
'runtime diagnostics persistence surface exists',
175194
'agent workspace contract test suite passes',

src/agent_workspace.verification.contract.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ describe('agent workspace verification script contracts', () => {
5151
expect(runtimeSource).toContain('/api/knowledge/operator/agent-workspace-diagnostics/triage/history');
5252
expect(runtimeSource).toContain('/api/knowledge/operator/agent-workspace-diagnostics/triage/runbook');
5353
expect(runtimeSource).toContain('/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds');
54+
expect(runtimeSource).toContain('/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds/simulate');
5455
expect(runtimeSource).toContain('/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds/audit');
56+
expect(runtimeSource).toContain('/api/knowledge/operator/agent-workspace-diagnostics/triage/remediation');
5557
expect(runtimeSource).toContain('cleanupStaleAgentWorkspaceDiagnosticsReports');
5658
expect(runtimeSource).toContain('AGENT_WORKSPACE_DIAGNOSTICS_MAX_ENTRIES');
5759
expect(runtimeSource).toContain('readAgentWorkspaceDiagnosticsAlertThresholds');
5860
expect(runtimeSource).toContain('persistAgentWorkspaceDiagnosticsAlertThresholds');
61+
expect(runtimeSource).toContain('buildAgentWorkspaceDiagnosticsThresholdPolicySimulation');
62+
expect(runtimeSource).toContain('executeAgentWorkspaceDiagnosticsAutoRemediation');
5963
expect(runtimeSource).toContain('readAgentWorkspaceDiagnosticsThresholdAuditTrail');
6064
expect(runtimeSource).toContain('appendAgentWorkspaceDiagnosticsThresholdAuditEntry');
6165
expect(runtimeSource).toContain('persistDiagnosticsReport');

src/knowledge.api.contract.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ describe('Knowledge mastery API contract wiring', () => {
1515
'/api/knowledge/operator/agent-workspace-diagnostics/triage/history',
1616
'/api/knowledge/operator/agent-workspace-diagnostics/triage/runbook',
1717
'/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds',
18+
'/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds/simulate',
1819
'/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds/audit',
20+
'/api/knowledge/operator/agent-workspace-diagnostics/triage/remediation',
1921
'/api/knowledge/operator/agent-workspace-diagnostics/report',
2022
'/api/knowledge/store/reload',
2123
'/api/knowledge/ingest',

0 commit comments

Comments
 (0)