Skip to content

Commit 0cac0c2

Browse files
committed
feat(agent-workspace): add triage trend history and threshold governance
1 parent 5c75a96 commit 0cac0c2

8 files changed

Lines changed: 676 additions & 17 deletions

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,34 @@ Deliverables:
305305
- `npm run test:agent-workspace:contracts`
306306
- `npm run verify:agent-workspace:runtime`
307307

308+
### M7.9 (Now): Operator Triage Trend History and Alert-Threshold Governance (Lane Ops Bridge)
309+
310+
Deliverables:
311+
312+
- add operator triage trend-history surface with bounded time-window sampling.
313+
- add operator alert-threshold governance surface (read/write + persisted policy file + bounded normalization).
314+
- ensure triage summary and history outputs are driven by active threshold policy rather than fixed constants.
315+
316+
#### M7.9 Progress Note (2026-04-16)
317+
318+
- [Done] expanded `src/server.ts` with threshold-governed triage surfaces:
319+
- `GET /api/knowledge/operator/agent-workspace-diagnostics/triage/history?window=...`,
320+
- `GET /api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds`,
321+
- `POST /api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds`.
322+
- [Done] landed persisted threshold governance under runtime data:
323+
- `agent_workspace_diagnostics/triage_policy.v1.json` now stores replay-medium/high thresholds, failure-escalation rule, top-replay limit, and history-window defaults.
324+
- [Done] strengthened triage semantics:
325+
- `/triage` now returns threshold-governed risk buckets and embedded history payload,
326+
- `/triage/history` returns bounded trend points (`window`, `replayCandidateRateDelta`, risk-bucket counts, failure counts).
327+
- [Done] expanded evidence coverage:
328+
- `src/server.migration.test.ts` now validates threshold updates, history-window behavior, reset-to-default, and policy-file persistence,
329+
- `src/knowledge.api.contract.test.ts` now fail-fast checks history/threshold route contracts,
330+
- `src/agent_workspace.verification.contract.test.ts` + `scripts/verify-agent-workspace-runtime.js` now fail fast on threshold governance helper/route drift.
331+
- [Done] verification evidence:
332+
- `npm test -- src/server.migration.test.ts --runInBand --testNamePattern "triage route summarizes replay risk|triage history and alert-threshold governance"`
333+
- `npm run test:agent-workspace:contracts`
334+
- `npm run verify:agent-workspace:runtime`
335+
308336
## Success Criteria
309337

310338
- CI failure mode that previously blocked the three agent-workspace suites is eliminated on mainline.
@@ -314,4 +342,4 @@ Deliverables:
314342

315343
## Next Step
316344

317-
Proceed to `/prompts:ce-plan` using this document as the source for `M7.9` decomposition (operator triage trend history and alert-threshold governance), while preserving M7 lane boundary constraints.
345+
Proceed to `/prompts:ce-plan` using this document as the source for `M7.10` decomposition (operator runbook automation and threshold-change audit trail), while preserving M7 lane boundary constraints.

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,26 @@ Execution anchor:
366366
- `npm run test:agent-workspace:contracts`
367367
- `npm run verify:agent-workspace:runtime`
368368

369+
## Latest Mainline Increment (2026-04-16 M7.9 Operator Triage Trend History and Alert-Threshold Governance Lane)
370+
371+
- Expanded `src/server.ts` with threshold-governed triage surfaces:
372+
- `GET /api/knowledge/operator/agent-workspace-diagnostics/triage/history?window=...`,
373+
- `GET /api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds`,
374+
- `POST /api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds`.
375+
- Added persisted threshold governance artifact:
376+
- `runtime_data/agent_workspace_diagnostics/triage_policy.v1.json` now stores replay-medium/high thresholds, failure-escalation rule, top-replay limit, and history-window defaults.
377+
- Extended triage semantics:
378+
- `/triage` now returns threshold-governed risk summary plus embedded history payload,
379+
- `/triage/history` now returns bounded trend points, risk-bucket distribution, failure counts, and replay-rate delta.
380+
- Expanded executable evidence:
381+
- `src/server.migration.test.ts` now validates threshold updates, bounded history window behavior, default reset, and policy-file persistence.
382+
- Hardened runtime verification gate:
383+
- `src/knowledge.api.contract.test.ts`, `src/agent_workspace.verification.contract.test.ts`, and `scripts/verify-agent-workspace-runtime.js` now fail fast on history/threshold route and helper drift.
384+
- Verification evidence:
385+
- `npm test -- src/server.migration.test.ts --runInBand --testNamePattern \"triage route summarizes replay risk|triage history and alert-threshold governance\"`
386+
- `npm run test:agent-workspace:contracts`
387+
- `npm run verify:agent-workspace:runtime`
388+
369389
## Mainline vs Working-Branch Snapshot (2026-04-14)
370390

371391
| Capability Slice | Working Branch (`feat/learning-multi-tutor-adapter`) | Mainline (`origin/main`) | Integration Status |
@@ -374,7 +394,7 @@ Execution anchor:
374394
| Focus + learning-path side-by-side pane model | Implemented in branch UI/runtime | Dock coexistence baseline integrated (`styles.css`, `path_styles.css`, `path_app.js`) | Partially integrated |
375395
| Agent workspace contract parity suite | Implemented (`src/agent_workspace.contract.parity.test.ts`, `src/agent_workspace.frontend.test.ts`, `src/agent_workspace.locale.contract.test.ts`, `src/agent_workspace.tauri.contract.test.ts`) | Baseline parity suite integrated (`src/agent_workspace.contract.parity.test.ts`, `src/agent_workspace.frontend.test.ts`, `src/agent_workspace.runtime.integration.test.ts`) | Partially integrated |
376396
| Result-presentation allowlist/override fail-fast governance | Implemented in branch execution registry and parity tests | Integrated in M1 (`src/frontend/agent_workspace.js` + parity tests) | Baseline integrated |
377-
| Conversation turn stream/replay/operator diagnostics expansion | Implemented in branch routes/tests | Mainline has runtime snapshot+trend/index/export plus sidecar persistence+triage+bounded retention governance (`src/frontend/agent_workspace_runtime.js`, `src/server.ts`) | Partially integrated |
397+
| Conversation turn stream/replay/operator diagnostics expansion | Implemented in branch routes/tests | Mainline has runtime snapshot+trend/index/export plus sidecar persistence+triage+history+threshold governance (`src/frontend/agent_workspace_runtime.js`, `src/server.ts`) | Partially integrated |
378398
| Graphdb/ANN foundation hardening lane | Branch-oriented lane claims exist in prior docs | Mainline currently exposes file-backed store baseline (`src/learning/store.ts`) | Not integrated on mainline |
379399
| Markdown reader governance refactor lane | Planned and partially implemented in branch | Mainline baseline only | Partially integrated |
380400

@@ -414,7 +434,7 @@ This dashboard aligns against the following requirement chain:
414434
| 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 |
415435
| L3 Learning | mastery diagnostics + path/session loop | Expanded in branch | Partially integrated | Contract and integration parity |
416436
| L4 Interaction | agent conversation + focus/path pane runtime | Implemented in branch | M1-M4 baseline integrated on mainline | Expand capability surface via typed contract only |
417-
| L5 Governance | runbook, diagnostics, replay/autonomy controls | Expanded in branch | Operator diagnostics persistence/triage/retention baseline integrated | Expand operator runbook automation and CI evidence depth |
437+
| L5 Governance | runbook, diagnostics, replay/autonomy controls | Expanded in branch | Operator diagnostics persistence/triage/history/threshold governance baseline integrated | Expand operator runbook automation and CI evidence depth |
418438

419439
## Verification Baseline
420440

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,26 @@
368368
- `npm run test:agent-workspace:contracts`
369369
- `npm run verify:agent-workspace:runtime`
370370

371+
## 主线最新增量(2026-04-16 M7.9 运维分级趋势历史与阈值治理链路)
372+
373+
- 已在 `src/server.ts` 增加阈值驱动的 triage 路由面:
374+
- `GET /api/knowledge/operator/agent-workspace-diagnostics/triage/history?window=...`
375+
- `GET /api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds`
376+
- `POST /api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds`
377+
- 已增加阈值治理持久化工件:
378+
- `runtime_data/agent_workspace_diagnostics/triage_policy.v1.json` 持久化 replay 中/高阈值、失败升级策略、top-replay 限制与 history-window 默认值。
379+
- 已扩展 triage 语义:
380+
- `/triage` 输出基于当前阈值策略计算的风险分桶,并内嵌 history 摘要,
381+
- `/triage/history` 输出有界趋势点、风险分布、失败计数与 replay 比率变化量。
382+
- 已补可执行证据:
383+
- `src/server.migration.test.ts` 新增阈值更新、有界窗口、重置默认、策略文件落盘断言。
384+
- 已加固 runtime 门禁:
385+
- `src/knowledge.api.contract.test.ts``src/agent_workspace.verification.contract.test.ts``scripts/verify-agent-workspace-runtime.js` 新增 history/threshold 路由与 helper 的 fail-fast 断言。
386+
- 验证证据:
387+
- `npm test -- src/server.migration.test.ts --runInBand --testNamePattern \"triage route summarizes replay risk|triage history and alert-threshold governance\"`
388+
- `npm run test:agent-workspace:contracts`
389+
- `npm run verify:agent-workspace:runtime`
390+
371391
## 主线 vs 工作分支快照(2026-04-14)
372392

373393
| 能力切片 | 工作分支(`feat/learning-multi-tutor-adapter`| 主线(`origin/main`| 集成状态 |
@@ -376,7 +396,7 @@
376396
| Focus + learning-path 并排 pane 模型 | 分支已实现 | 已落入 dock 并排基线(`styles.css``path_styles.css``path_app.js`| 部分集成 |
377397
| Agent workspace 合同门禁测试 | 已实现(`src/agent_workspace.contract.parity.test.ts``src/agent_workspace.frontend.test.ts``src/agent_workspace.locale.contract.test.ts``src/agent_workspace.tauri.contract.test.ts`| 已落入基线门禁(`src/agent_workspace.contract.parity.test.ts``src/agent_workspace.frontend.test.ts``src/agent_workspace.runtime.integration.test.ts`| 部分集成 |
378398
| 结果呈现 allowlist/override fail-fast 治理 | 分支已实现 | M1 已集成(`src/frontend/agent_workspace.js` + parity tests) | 基线已集成 |
379-
| conversation turn 流式/重放/诊断扩展 | 分支已扩展 | 主线已落入 runtime snapshot+trend/index/export + sidecar 持久化/分级/有界保留治理基线`src/frontend/agent_workspace_runtime.js``src/server.ts`| 部分集成 |
399+
| conversation turn 流式/重放/诊断扩展 | 分支已扩展 | 主线已落入 runtime snapshot+trend/index/export + sidecar 持久化/分级/趋势历史/阈值治理基线`src/frontend/agent_workspace_runtime.js``src/server.ts`| 部分集成 |
380400
| graphdb/ANN 底座收敛 | 先前文档存在分支导向结论 | 主线当前为 file-backed store 基线(`src/learning/store.ts`| 主线未集成 |
381401
| Markdown 阅读器治理升级 | 分支已有规划与部分实现 | 主线为旧基线 | 部分集成 |
382402

@@ -416,7 +436,7 @@
416436
| L2 检索层 | 可解释混合/向量检索 + 治理 | 分支规划增强中 | 主线当前为 file-backed 基线(`src/learning/store.ts`| 待主线出现对应模块证据后再收敛 |
417437
| L3 学习层 | 掌握诊断 + 路径/会话闭环 | 分支增强中 | 主线部分集成 | 契约与集成一致性 |
418438
| L4 交互层 | agent 对话 + focus/path pane 运行时 | 分支已实现 | 主线 M1-M4 已落入基线 | 继续通过 typed contract 扩展动作面 |
419-
| L5 治理层 | runbook/诊断/回放与自动化 | 分支增强中 | 主线已集成运维诊断持久化/分级/保留治理基线 | 扩展 runbook 自动化与 CI 证据深度 |
439+
| L5 治理层 | runbook/诊断/回放与自动化 | 分支增强中 | 主线已集成运维诊断持久化/分级/趋势历史/阈值治理基线 | 扩展 runbook 自动化与 CI 证据深度 |
420440

421441
## 验证基线
422442

scripts/verify-agent-workspace-runtime.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ function verifyAgentWorkspaceRuntime(repoRoot = path.resolve(__dirname, '..')) {
108108
serverSource.includes('/api/knowledge/operator/agent-workspace-diagnostics/triage'),
109109
'Missing diagnostics report triage route in src/server.ts'
110110
);
111+
assert(
112+
serverSource.includes('/api/knowledge/operator/agent-workspace-diagnostics/triage/history'),
113+
'Missing diagnostics triage history route in src/server.ts'
114+
);
115+
assert(
116+
serverSource.includes('/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds'),
117+
'Missing diagnostics triage thresholds route in src/server.ts'
118+
);
111119
assert(
112120
serverSource.includes('cleanupStaleAgentWorkspaceDiagnosticsReports'),
113121
'Missing diagnostics retention cleanup helper in src/server.ts'
@@ -116,6 +124,14 @@ function verifyAgentWorkspaceRuntime(repoRoot = path.resolve(__dirname, '..')) {
116124
serverSource.includes('AGENT_WORKSPACE_DIAGNOSTICS_MAX_ENTRIES'),
117125
'Missing diagnostics retention bound constant in src/server.ts'
118126
);
127+
assert(
128+
serverSource.includes('readAgentWorkspaceDiagnosticsAlertThresholds'),
129+
'Missing diagnostics triage threshold reader in src/server.ts'
130+
);
131+
assert(
132+
serverSource.includes('persistAgentWorkspaceDiagnosticsAlertThresholds'),
133+
'Missing diagnostics triage threshold writer in src/server.ts'
134+
);
119135
assert(
120136
runtimeSource.includes('persistDiagnosticsReport'),
121137
'Missing persistDiagnosticsReport runtime surface in src/frontend/agent_workspace_runtime.js'
@@ -132,7 +148,10 @@ function verifyAgentWorkspaceRuntime(repoRoot = path.resolve(__dirname, '..')) {
132148
'conversation route wiring exists',
133149
'diagnostics report persistence routes exist',
134150
'diagnostics triage route exists',
151+
'diagnostics triage history route exists',
152+
'diagnostics triage threshold governance routes exist',
135153
'diagnostics retention governance exists',
154+
'diagnostics alert-threshold governance helpers exist',
136155
'runtime diagnostics persistence surface exists',
137156
'agent workspace contract test suite passes',
138157
],

src/agent_workspace.verification.contract.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ describe('agent workspace verification script contracts', () => {
4848
expect(runtimeSource).toContain('/api/knowledge/operator/agent-workspace-diagnostics/index');
4949
expect(runtimeSource).toContain('/api/knowledge/operator/agent-workspace-diagnostics/latest');
5050
expect(runtimeSource).toContain('/api/knowledge/operator/agent-workspace-diagnostics/triage');
51+
expect(runtimeSource).toContain('/api/knowledge/operator/agent-workspace-diagnostics/triage/history');
52+
expect(runtimeSource).toContain('/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds');
5153
expect(runtimeSource).toContain('cleanupStaleAgentWorkspaceDiagnosticsReports');
5254
expect(runtimeSource).toContain('AGENT_WORKSPACE_DIAGNOSTICS_MAX_ENTRIES');
55+
expect(runtimeSource).toContain('readAgentWorkspaceDiagnosticsAlertThresholds');
56+
expect(runtimeSource).toContain('persistAgentWorkspaceDiagnosticsAlertThresholds');
5357
expect(runtimeSource).toContain('persistDiagnosticsReport');
5458
expect(browserSource).toContain('verifyAgentWorkspaceBrowser');
5559
expect(tauriSource).toContain('verifyAgentWorkspaceTauri');

src/knowledge.api.contract.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ describe('Knowledge mastery API contract wiring', () => {
1212
'/api/knowledge/operator/agent-workspace-diagnostics/index',
1313
'/api/knowledge/operator/agent-workspace-diagnostics/latest',
1414
'/api/knowledge/operator/agent-workspace-diagnostics/triage',
15+
'/api/knowledge/operator/agent-workspace-diagnostics/triage/history',
16+
'/api/knowledge/operator/agent-workspace-diagnostics/triage/thresholds',
1517
'/api/knowledge/operator/agent-workspace-diagnostics/report',
1618
'/api/knowledge/store/reload',
1719
'/api/knowledge/ingest',

0 commit comments

Comments
 (0)