iterate-plugin 3.8.0 → 3.9.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.
- package/README.md +10 -7
- package/README.zh-CN.md +4 -3
- package/dist/index.js +9 -4
- package/dist/report-render.js +452 -0
- package/dist/session-record.js +246 -0
- package/dist/skill-prompt.js +2 -1
- package/dist/tools/report.js +239 -0
- package/dist/tools/transcript.js +186 -9
- package/lib/client.js +453 -13
- package/package.json +17 -10
- package/src/client/i18n.ts +6 -0
- package/src/client/index.ts +44 -0
- package/src/index.ts +9 -4
- package/src/report-render.ts +578 -0
- package/src/session-record.ts +333 -0
- package/src/skill-prompt.ts +2 -1
- package/src/tools/report.ts +244 -0
- package/src/tools/transcript.ts +199 -9
package/README.md
CHANGED
|
@@ -107,7 +107,7 @@ Both modes share:
|
|
|
107
107
|
### UI layer (build-free client slots, v3.7: 11 tabs, bilingual)
|
|
108
108
|
|
|
109
109
|
- **ConvergenceDashboard** (`conversation.input.dock`) — live round progress bar, severity stats, dimension badges, trend mini-chart above the input; normal mode also shows fix-count badges; plus a live workflow-phase chip (current phase + running/stopped) and a **task_mode indicator (code / iterate)**, now backed by the persisted transcript (`iterate_status` / `iterate_transcript` emit `taskMode`). While a run is active the dashboard switches to a running state (round + phase) instead of the static empty state, and the start buttons are hidden.
|
|
110
|
-
- **ObservatoryPanel** (`conversation.input.dock`) — an **eleven-tab** runtime observatory below the input: **live activity stream** (default tab, type filter) + **F1** review threads (expand / collapse all), **F2** convergence trend (incl. the per-round comparison table: findings raised / fixed / severity mix / validation outcomes), **F3** finding locations (severity / dimension / search filter), **F4** fixes + rollback, **F5** checkpoint resume, **F6** run console, **F7** decision timeline (type / round filter + search), **F8** Quality Gate, **F9** Experience Bank, **F10** Defense Events. Number-key shortcuts: `1`–`9` jump to F1–F9, `0` to F10, `-` back to the live stream. **F8/F9/F10 are live** — they scan the session stream for the latest `iterate_quality_gate` / `iterate_experience` / `iterate_defense_events` results and render real data (PASS/FAIL chip + per-dimension score bars, experience entries with adopt buttons + client-side search, defense type-count chips + filtered event stream); when the session stream has none they distinguish "no data on disk" from "not pulled yet" and offer a **拉取磁盘快照 (pull disk snapshot)** instruction that has the model call the read-side tools and echo the `.iterate/` artifacts back into the stream. One-click JSON export of all observatory data — manifest + live + `qualityGate` / `experienceBank` / `defenseEvents` / `report` (download, copy fallback). **v3.5.3: reset actions surfaced** — F5 copies an `iterate_checkpoint clear` instruction, F8 an `iterate_quality_gate clear` instruction, F10 an `iterate_defense_events clear` instruction.
|
|
110
|
+
- **ObservatoryPanel** (`conversation.input.dock`) — an **eleven-tab** runtime observatory below the input: **live activity stream** (default tab, type filter) + **F1** review threads (expand / collapse all), **F2** convergence trend (incl. the per-round comparison table: findings raised / fixed / severity mix / validation outcomes), **F3** finding locations (severity / dimension / search filter), **F4** fixes + rollback, **F5** checkpoint resume, **F6** run console, **F7** decision timeline (type / round filter + search), **F8** Quality Gate, **F9** Experience Bank, **F10** Defense Events. Number-key shortcuts: `1`–`9` jump to F1–F9, `0` to F10, `-` back to the live stream. **F8/F9/F10 are live** — they scan the session stream for the latest `iterate_quality_gate` / `iterate_experience` / `iterate_defense_events` results and render real data (PASS/FAIL chip + per-dimension score bars, experience entries with adopt buttons + client-side search, defense type-count chips + filtered event stream); when the session stream has none they distinguish "no data on disk" from "not pulled yet" and offer a **拉取磁盘快照 (pull disk snapshot)** instruction that has the model call the read-side tools and echo the `.iterate/` artifacts back into the stream. One-click JSON export of all observatory data — manifest + live + `qualityGate` / `experienceBank` / `defenseEvents` / `report` (download, copy fallback). **v3.9: two report-export buttons** (导出报告 / 导出 SARIF) render the *same shared data model* as the `iterate_report` tool — a PR-pasteable Markdown run report and a SARIF 2.1.0 log for CI / GitHub Code Scanning. **v3.5.3: reset actions surfaced** — F5 copies an `iterate_checkpoint clear` instruction, F8 an `iterate_quality_gate clear` instruction, F10 an `iterate_defense_events clear` instruction.
|
|
111
111
|
- **TriagePanel** (`conversation.chat.turnTail`) — per-finding triage with `y` (keep → fix), `n` (skip), `a` (known-intentional) keyboard shortcuts and `↑`/`↓` navigation (focus-guarded: only active while the panel has focus), filtering, batch ops (incl. select-all), localStorage persistence. **Write-back closed loop**: the primary button copies an `iterate_triage apply` instruction for the marked entries (the tool validates, dedupes, backs up, rolls back on failure); a secondary button copies the raw `known_intentional` YAML; **回读已写入条目** copies an `iterate_triage list` instruction to confirm what actually landed. Copy payloads are aligned to the target tool schemas. **v3.2: native command buttons** (approve architectural fix, trigger new round, rollback to checkpoint). **v3.3: §8 指派修复 (assign)** — one click copies an `iterate_fix` instruction carrying every in-scope finding (respecting the batch toggle).
|
|
112
112
|
- **StatsCard** (`conversation.chat.turnTail`) — convergence stats, round history, trend chart and completion summary when no findings remain.
|
|
113
113
|
- **iterate theme skin** (`theme.overrideTokens`) — a warm-amber 13-token `--dsw-*` override, light/dark modes, togglable in settings.
|
|
@@ -303,10 +303,11 @@ validation:
|
|
|
303
303
|
- `iterate_status` — summarize current iteration state: mode, current/last round, fixes applied, remaining architectural, decision-log entry count, whether a checkpoint exists; **v3.4: also surfaces the persisted quality-gate snapshot, experience-bank summary, and defense-events summary** (`qualityGate` / `experienceBank` / `defenseEvents`)
|
|
304
304
|
- `iterate_history` — read iteration history (read-only): decision-log entries (filter by `type` / `since` / `round` / fixed `file` / `limit`, default latest 50, cap 200) + fix-registry summary (per-round fixed/failed counts, scoped by the same round/file filters; a `file`-scoped summary recomputes counts from the kept records). For auditing the run, tracing logs, and inventorying fixes
|
|
305
305
|
- `iterate_prune` — clean runtime artifacts: stale decision-log entries (by `retainDays`, default 30), stale checkpoints, orphaned fix backups, empty rounds, stray temp files (crashed atomic writes). Dry-run by default (report-only); real cleanup with `dryRun:false`, each cleanup logged
|
|
306
|
-
- `iterate_transcript` — runtime observatory: persist review transcripts, threads, fixes, and nudge directions to `.iterate/transcript.json` for the client observatory
|
|
306
|
+
- `iterate_transcript` — runtime observatory: persist review transcripts, threads, fixes, and nudge directions to `.iterate/transcript.json` for the client observatory. **v3.9: `read` recovers a summary manifest from the session log's run record when the file is lost/corrupt (`recovered:true`); `capture` links the run to the dsh session (`sessionRecord`); `recall` lists this session's run records (newest first)**
|
|
307
307
|
- `iterate_experience` — **v3.2** query the experience bank (list / search / get), `add` a new verified fix (re-adding the same pattern+dimension bumps its hit count instead of duplicating it), or **v3.5 remove a stale/incorrect entry by `id`** so bad experiences never resurface. Persists to `.iterate/experience.json`
|
|
308
308
|
- `iterate_quality_gate` — **v3.2** read the quality certificate (`read`), or recompute + persist a fresh one (`compute`) from findings, validation results, `findingsByRound`, and `fixedByDimension`. Real per-dimension convergence rates. **v3.5: `clear` removes the persisted certificate to reset a stale gate before a fresh iteration**
|
|
309
309
|
- `iterate_defense_events` — **v3.2** query defense events (list / counts), `record` a new one, or **v3.5.3 `clear` the persisted stream** so a fresh iteration starts without stale defensive data. Human-readable labels follow the project language (en / zh)
|
|
310
|
+
- `iterate_report` — **v3.9** export the run as a portable report. `format:"markdown"` (default) renders a PR-pasteable report (run header, quality gate, findings, fixes, validations, defense events, experience bank); `format:"sarif"` renders a SARIF 2.1.0 log for CI / GitHub Code Scanning (one rule per review dimension, severity → error/warning/note, file+line locations, suggested fix attached). `write:true` persists it to `.iterate/report.md` / `.iterate/report.sarif`; `lang` (zh | en) selects the report language. Read-only apart from the optional report file
|
|
310
311
|
|
|
311
312
|
---
|
|
312
313
|
|
|
@@ -343,12 +344,14 @@ All runtime state lives under `.iterate/` at the project root (can be excluded v
|
|
|
343
344
|
`0.1.5-rc.1`, `0.1.5-rc.2`, `0.1.6-alpha.1`, `0.1.6-alpha.2`,
|
|
344
345
|
`0.1.7-alpha.1`, `0.1.7-alpha.2`, `0.1.7-rc.1`, `0.1.7-rc.2`, `0.2.0-rc.1`,
|
|
345
346
|
`0.2.0-rc.2`, `0.2.1-alpha.1`, `0.2.1-alpha.2`, `0.2.1-alpha.3`,
|
|
346
|
-
`0.2.1-alpha.4
|
|
347
|
-
`0.
|
|
347
|
+
`0.2.1-alpha.4`, `0.2.1-alpha.5`, `0.2.1-rc.1`, `0.2.1-rc.2` (24 releases,
|
|
348
|
+
`0.1.1-rc.1` …
|
|
349
|
+
`0.2.1-rc.2`).
|
|
348
350
|
The plugin is built against `@deepseek-ai/dsh-tools` /
|
|
349
|
-
`@deepseek-ai/dsh-util-values` `0.2.1-
|
|
350
|
-
(tool registration, client slots + theme, bundle patch
|
|
351
|
-
|
|
351
|
+
`@deepseek-ai/dsh-util-values` `0.2.1-rc.2` and uses only public contracts
|
|
352
|
+
(tool registration, client slots + theme, bundle patch, and — since v3.9 —
|
|
353
|
+
the session state-record API for session-linked run records).
|
|
354
|
+
It also declares `engines.dsh` (`>=0.1.1-rc.1`) so the dsh ≥ 0.2.1-rc.2
|
|
352
355
|
runtime evaluates compatibility from that single range (earlier runtimes fall
|
|
353
356
|
back to the `@deepseek-ai/dsh-*` peer versions listed in `package.json`).
|
|
354
357
|
- **Disposable-Profile evidence (real, `dsh` CLI `0.1.1-rc.1`)**: on a temp
|
package/README.zh-CN.md
CHANGED
|
@@ -106,7 +106,7 @@ dsh plugin --profile web add iterate-plugin
|
|
|
106
106
|
### UI 层(客户端免构建槽位,v3.7:11 个页签,双语)
|
|
107
107
|
|
|
108
108
|
- **收敛看板 `ConvergenceDashboard`**(`conversation.input.dock`)— 输入框上方实时显示轮次进度条、严重度统计、维度徽章、趋势迷你图;normal 模式另显示修复计数徽章;还有运行阶段芯片(当前工作流阶段 + 运行中/已结束)与 **task_mode 指示器(code / iterate)**。运行期间看板切换为"运行中"状态(显示轮次与阶段),并隐藏启动按钮。
|
|
109
|
-
- **运行时观测台 `ObservatoryPanel`**(`conversation.input.dock`)— 输入框下方**十一个页签**运行时观测台:**实时活动流**(默认页,支持按活动类型筛选)+ **F1** 审查线程(全部展开/全部收起)、**F2** 收敛趋势(含跨轮对比表:每轮 findings / fixed / 严重度分布 / 验证结果)、**F3** 发现定位(按严重度/维度/关键词筛选)、**F4** 修复与回滚、**F5** 断点恢复、**F6** 运行控制台、**F7** 决策时间线(按类型/轮次筛选与关键词搜索)、**F8** 质量门禁、**F9** 经验银行、**F10** 防御事件。数字键快捷键:`1`–`9` 跳到 F1–F9,`0` 到 F10,`-` 回实时活动流。**F8/F9/F10 为实时数据**——扫描会话流中最近一次 `iterate_quality_gate` / `iterate_experience` / `iterate_defense_events` 结果并渲染真实数据(PASS/FAIL 徽章 + 分维度评分条、经验条目(含采纳按钮 + 客户端搜索)、防御类型计数芯片 + 筛选后的事件流);会话流中没有数据时区分"磁盘无数据"与"尚未拉取",并提供**拉取磁盘快照**指令(让模型调用只读工具、把 `.iterate/` 产物回显进会话流)。一键导出全部观测数据为 JSON——manifest + live + `qualityGate` / `experienceBank` / `defenseEvents` / `report`(优先下载,失败回退复制)。**v3.5.3 新增重置操作**:F5 复制 `iterate_checkpoint clear`、F8 复制 `iterate_quality_gate clear`、F10 复制 `iterate_defense_events clear` 指令。
|
|
109
|
+
- **运行时观测台 `ObservatoryPanel`**(`conversation.input.dock`)— 输入框下方**十一个页签**运行时观测台:**实时活动流**(默认页,支持按活动类型筛选)+ **F1** 审查线程(全部展开/全部收起)、**F2** 收敛趋势(含跨轮对比表:每轮 findings / fixed / 严重度分布 / 验证结果)、**F3** 发现定位(按严重度/维度/关键词筛选)、**F4** 修复与回滚、**F5** 断点恢复、**F6** 运行控制台、**F7** 决策时间线(按类型/轮次筛选与关键词搜索)、**F8** 质量门禁、**F9** 经验银行、**F10** 防御事件。数字键快捷键:`1`–`9` 跳到 F1–F9,`0` 到 F10,`-` 回实时活动流。**F8/F9/F10 为实时数据**——扫描会话流中最近一次 `iterate_quality_gate` / `iterate_experience` / `iterate_defense_events` 结果并渲染真实数据(PASS/FAIL 徽章 + 分维度评分条、经验条目(含采纳按钮 + 客户端搜索)、防御类型计数芯片 + 筛选后的事件流);会话流中没有数据时区分"磁盘无数据"与"尚未拉取",并提供**拉取磁盘快照**指令(让模型调用只读工具、把 `.iterate/` 产物回显进会话流)。一键导出全部观测数据为 JSON——manifest + live + `qualityGate` / `experienceBank` / `defenseEvents` / `report`(优先下载,失败回退复制)。**v3.9 新增两个报告导出按钮**(导出报告 / 导出 SARIF),与 `iterate_report` 工具共用同一份数据模型——分别产出可直接粘贴进 PR 的 Markdown 运行报告,与供 CI / GitHub Code Scanning 消费的 SARIF 2.1.0 日志。**v3.5.3 新增重置操作**:F5 复制 `iterate_checkpoint clear`、F8 复制 `iterate_quality_gate clear`、F10 复制 `iterate_defense_events clear` 指令。
|
|
110
110
|
- **Findings 分诊面板 `TriagePanel`**(`conversation.chat.turnTail`)— 逐条分诊,键盘快捷键 `y`(保留→修复)、`n`(跳过)、`a`(已知有意)与 `↑`/`↓` 移动(焦点守卫:仅面板内焦点时生效),支持筛选、批量(含一键全选所有 findings)、localStorage 持久化。**写回闭环**:主按钮复制已标记条目的 `iterate_triage apply` 指令(工具负责校验、去重、备份、失败回滚);次按钮复制裸 `known_intentional` YAML;**回读已写入条目**复制 `iterate_triage list` 指令核对实际落盘内容。复制载荷与目标工具 schema 对齐。**v3.2:原生命令按钮**(批准架构修复、触发新一轮、回滚到断点)。
|
|
111
111
|
- **收敛统计卡片 `StatsCard`**(`conversation.chat.turnTail`)— 无 findings 时显示收敛统计、历史轮次、趋势图、完成摘要。
|
|
112
112
|
- **iterate 主题皮肤**(`theme.overrideTokens`)— 暖琥珀配色的 13 个 `--dsw-*` token 覆盖,明暗双模式,可在设置页开关。
|
|
@@ -302,10 +302,11 @@ validation:
|
|
|
302
302
|
- `iterate_status` — 汇总当前迭代状态:模式、当前轮/总轮、已修复数、剩余 architectural、决策日志条数、是否存在 checkpoint;**v3.4:同时返回持久化的质量门禁快照、经验银行摘要与防御事件摘要**(`qualityGate` / `experienceBank` / `defenseEvents`)
|
|
303
303
|
- `iterate_history` — 读取迭代历史(只读):决策日志条目(可按 `type` / `since` / `round` / 修复文件 `file` / `limit` 过滤,默认取最新 50 条,上限 200 条)+ 修复注册表汇总(各轮 fixed/failed 计数,按同一 round/file 过滤收窄;`file` 过滤时按保留的记录重算计数)。用于审查运行过程、审计日志、盘点修复
|
|
304
304
|
- `iterate_prune` — 清理运行时产物:过期决策日志条目(按 `retainDays`,默认 30 天)、陈旧断点、孤儿修复备份、空轮次、崩溃原子写入残留的临时文件。默认 dry-run 只报告不删除;`dryRun:false` 才真正清理,每次清理写入决策日志
|
|
305
|
-
- `iterate_transcript` — 运行时观测台:把审查转录、线程、修复与 nudge 指令持久化到 `.iterate/transcript.json
|
|
305
|
+
- `iterate_transcript` — 运行时观测台:把审查转录、线程、修复与 nudge 指令持久化到 `.iterate/transcript.json`,供客户端观测台读取。**v3.9:`read` 在文件丢失/损坏时从会话日志的运行记录恢复出一份摘要 manifest(`recovered:true`);`capture` 把本次运行关联到 dsh 会话(`sessionRecord`);`recall` 列出本会话的运行记录(最新在前)**
|
|
306
306
|
- `iterate_experience` — **v3.2** 查询经验银行(list / search / get),或 `add` 一条新的已验证修复:重复添加同一 pattern + dimension 累加命中次数而非重复写入。**v3.5 新增 `remove`:按 `id` 删除过时或错误的经验条目**。持久化到 `.iterate/experience.json`
|
|
307
307
|
- `iterate_quality_gate` — **v3.2** 读取质量凭证(`read`),或基于 findings、验证结果、`findingsByRound` 与 `fixedByDimension` 重新计算并持久化一份新凭证(`compute`)。真实的逐维度收敛率。**v3.5 新增 `clear`:删除持久化的质量凭证**,用于新一轮迭代前重置陈旧的门禁
|
|
308
308
|
- `iterate_defense_events` — **v3.2** 查询防御事件(list / counts),`record` 记录一条新事件,或 **v3.5.3 `clear` 清除持久化事件流**,让新一轮迭代不带陈旧防御数据起跑。可读标签跟随项目语言(en / zh)
|
|
309
|
+
- `iterate_report` — **v3.9** 把本次运行导出为可移植报告。`format:"markdown"`(默认)产出可直接粘贴进 PR 的报告(运行头部、质量门禁、发现、修复、验证、防御事件、经验银行);`format:"sarif"` 产出 SARIF 2.1.0 日志供 CI / GitHub Code Scanning 消费(每个审查维度一条规则,严重度 → error/warning/note,携带文件+行号位置与建议修复)。`write:true` 持久化到 `.iterate/report.md` / `.iterate/report.sarif`;`lang`(zh | en)选择报告语言。除可选的报告文件外均为只读
|
|
309
310
|
|
|
310
311
|
---
|
|
311
312
|
|
|
@@ -334,7 +335,7 @@ validation:
|
|
|
334
335
|
### Node.js / DSH 兼容范围
|
|
335
336
|
|
|
336
337
|
- **Node.js**:`>=20`(`package.json` 的 `engines.node`)。
|
|
337
|
-
- **DSH**:`package.json` 的 `dsh.compatibility.dshReleases` 字段是发布兼容性的**唯一真源**(本 README 逐字镜像该字段;两者需同步更新)。以下官方版本声明为 `compatible`:`0.1.1-rc.1`、`0.1.2-alpha.4`、`0.1.2-alpha.5`、`0.1.2-rc.1`、`0.1.3-alpha.1`、`0.1.5-alpha.1`、`0.1.5-alpha.2`、`0.1.5-rc.1`、`0.1.5-rc.2`、`0.1.6-alpha.1`、`0.1.6-alpha.2`、`0.1.7-alpha.1`、`0.1.7-alpha.2`、`0.1.7-rc.1`、`0.1.7-rc.2`、`0.2.0-rc.1`、`0.2.0-rc.2`、`0.2.1-alpha.1`、`0.2.1-alpha.2`、`0.2.1-alpha.3`、`0.2.1-alpha.4`(共
|
|
338
|
+
- **DSH**:`package.json` 的 `dsh.compatibility.dshReleases` 字段是发布兼容性的**唯一真源**(本 README 逐字镜像该字段;两者需同步更新)。以下官方版本声明为 `compatible`:`0.1.1-rc.1`、`0.1.2-alpha.4`、`0.1.2-alpha.5`、`0.1.2-rc.1`、`0.1.3-alpha.1`、`0.1.5-alpha.1`、`0.1.5-alpha.2`、`0.1.5-rc.1`、`0.1.5-rc.2`、`0.1.6-alpha.1`、`0.1.6-alpha.2`、`0.1.7-alpha.1`、`0.1.7-alpha.2`、`0.1.7-rc.1`、`0.1.7-rc.2`、`0.2.0-rc.1`、`0.2.0-rc.2`、`0.2.1-alpha.1`、`0.2.1-alpha.2`、`0.2.1-alpha.3`、`0.2.1-alpha.4`、`0.2.1-alpha.5`、`0.2.1-rc.1`、`0.2.1-rc.2`(共 24 个版本,`0.1.1-rc.1` … `0.2.1-rc.2`)。插件基于 `@deepseek-ai/dsh-tools` / `@deepseek-ai/dsh-util-values` `0.2.1-rc.2` 构建,只使用公开契约(工具注册、客户端 slots + theme、bundle patch,以及 v3.9 起的会话状态记录接口)。插件同时声明 `engines.dsh`(`>=0.1.1-rc.1`),使 dsh ≥ 0.2.1-rc.2 运行时只依据该范围判断兼容性(更早的运行时仍回退校验 `package.json` 中列出的 `@deepseek-ai/dsh-*` peer 版本)。
|
|
338
339
|
- **一次性 Profile 证据(真实,`dsh` CLI `0.1.1-rc.1`)**:在临时 `$DSH_HOME` 下
|
|
339
340
|
`dsh plugin --profile <p> add <本仓库>` 约 449ms 完成安装;`dsh --profile <p>
|
|
340
341
|
--dump-config` 正确合成 `iterate-plugin` bundle patch;`dsh plugin --profile <p>
|
package/dist/index.js
CHANGED
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
* iterate-plugin — dsh plugin for the iterate autonomous closed-loop workflow
|
|
3
3
|
*
|
|
4
4
|
* Architecture:
|
|
5
|
-
* - The plugin registers
|
|
5
|
+
* - The plugin registers 18 tools (14 original + 3 v3.0 quality command center
|
|
6
|
+
* tools + 1 v3.9 report export)
|
|
6
7
|
* Original: config, validate, decision-log, context, review, triage, fix, diff,
|
|
7
8
|
* rollback, checkpoint, status, history, prune, transcript
|
|
8
9
|
* v3.0: experience, quality_gate, defense_events
|
|
10
|
+
* v3.9: report
|
|
9
11
|
* - The plugin injects a system prompt section teaching the iterate workflow pattern
|
|
10
12
|
* - The model (prompted by the skill) writes a workflow script using dsh's `workflow` tool
|
|
11
13
|
* - The workflow script uses `agent()` / `parallel()` / `phase()` / `log()` to orchestrate
|
|
12
|
-
* - Subagents use the
|
|
14
|
+
* - Subagents use the 18 tools to do real work (read config, run validation, log decisions,
|
|
13
15
|
* review, triage, apply/rollback/fixing, checkpoint, status, history, prune, transcript,
|
|
14
|
-
* query experience bank, check quality gates, query defense events)
|
|
16
|
+
* query experience bank, check quality gates, query defense events, export a report)
|
|
15
17
|
* - A `tools/pre-execute` hook gates destructive iterate calls behind human approval
|
|
16
18
|
* (F8 observatory approval policy: ask / deny / allow).
|
|
17
19
|
*
|
|
@@ -23,7 +25,7 @@
|
|
|
23
25
|
*
|
|
24
26
|
* Key files:
|
|
25
27
|
* - src/index.ts — Plugin entry: register tools + inject skill prompt
|
|
26
|
-
* - src/tools/ —
|
|
28
|
+
* - src/tools/ — 18 tool implementations (14 original + 3 v3.0 + 1 v3.9)
|
|
27
29
|
* - src/config-loader.ts — YAML config loading
|
|
28
30
|
* - src/types.ts — Shared types
|
|
29
31
|
*/
|
|
@@ -41,6 +43,7 @@ import { registerTranscriptTool } from "./tools/transcript.js";
|
|
|
41
43
|
import { registerExperienceBankTool } from "./tools/experience-bank.js";
|
|
42
44
|
import { registerQualityGateTool } from "./tools/quality-gate.js";
|
|
43
45
|
import { registerDefenseEventsTool } from "./tools/defense-events.js";
|
|
46
|
+
import { registerReportTool } from "./tools/report.js";
|
|
44
47
|
import { registerSessionHooks } from "./session-hooks.js";
|
|
45
48
|
import { registerLiveCapture } from "./live.js";
|
|
46
49
|
import { installWorkingDirectoryContext } from "./working-directory.js";
|
|
@@ -87,6 +90,8 @@ export function apply(ctx) {
|
|
|
87
90
|
['iterate_experience', () => registerExperienceBankTool(ctx)],
|
|
88
91
|
['iterate_quality_gate', () => registerQualityGateTool(ctx)],
|
|
89
92
|
['iterate_defense_events', () => registerDefenseEventsTool(ctx)],
|
|
93
|
+
// v3.9: PR-ready / CI-ready report export
|
|
94
|
+
['iterate_report', () => registerReportTool(ctx)],
|
|
90
95
|
];
|
|
91
96
|
for (const [toolName, register] of toolRegistrations) {
|
|
92
97
|
try {
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/report-render.ts — pure renderers for the portable iterate run report.
|
|
3
|
+
*
|
|
4
|
+
* ONE data model, TWO consumers that must never disagree:
|
|
5
|
+
* - the `iterate_report` tool (server side), and
|
|
6
|
+
* - the observatory's "导出报告 / 导出 SARIF" buttons (client side),
|
|
7
|
+
* both call {@link renderRunReportMarkdown} / {@link renderRunReportSarif} on
|
|
8
|
+
* the same normalized {@link RunReportData}.
|
|
9
|
+
*
|
|
10
|
+
* This module is deliberately dependency-free and DOM-free: it is compiled to
|
|
11
|
+
* `dist/` for the server AND inlined into `lib/client.js` by esbuild. It must
|
|
12
|
+
* import NOTHING — importing `lib/parse.js` would drag a file outside `src/`
|
|
13
|
+
* into the server's tsc program and scatter the emit into `dist/src/**`. Every
|
|
14
|
+
* extraction is tolerant: a hand-edited manifest can only ever produce an empty
|
|
15
|
+
* section, never a thrown export.
|
|
16
|
+
*
|
|
17
|
+
* Formats:
|
|
18
|
+
* - **markdown** — a PR-pasteable run report (header, quality gate, findings,
|
|
19
|
+
* fixes, validations, defense events, experience bank).
|
|
20
|
+
* - **sarif** — SARIF 2.1.0 for CI / GitHub Code Scanning (ruleId =
|
|
21
|
+
* review dimension, severity → error | warning | note, file+line
|
|
22
|
+
* locations, suggested fix attached).
|
|
23
|
+
*/
|
|
24
|
+
/** Report formats accepted by the tool and the export buttons. */
|
|
25
|
+
export const REPORT_FORMATS = ['markdown', 'sarif'];
|
|
26
|
+
/** Severity ordering (lowest index = most severe). */
|
|
27
|
+
const SEVERITY_ORDER = ['critical', 'high', 'medium', 'low'];
|
|
28
|
+
/** Human labels for the report, keyed by language. */
|
|
29
|
+
const REPORT_LABELS = {
|
|
30
|
+
en: {
|
|
31
|
+
title: 'iterate run report',
|
|
32
|
+
project: 'Project',
|
|
33
|
+
goal: 'Goal',
|
|
34
|
+
mode: 'Mode',
|
|
35
|
+
status: 'Status',
|
|
36
|
+
round: 'Round',
|
|
37
|
+
updated: 'Updated',
|
|
38
|
+
converged: 'converged',
|
|
39
|
+
running: 'running',
|
|
40
|
+
stopped: 'stopped',
|
|
41
|
+
qualityGate: 'Quality gate',
|
|
42
|
+
overall: 'Overall',
|
|
43
|
+
verification: 'Verification',
|
|
44
|
+
dimension: 'Dimension',
|
|
45
|
+
qstatus: 'Status',
|
|
46
|
+
score: 'Score',
|
|
47
|
+
findingsCount: 'Findings',
|
|
48
|
+
fixed: 'Fixed',
|
|
49
|
+
convergence: 'Convergence',
|
|
50
|
+
findings: 'Findings',
|
|
51
|
+
severity: 'Severity',
|
|
52
|
+
location: 'Location',
|
|
53
|
+
summary: 'Summary',
|
|
54
|
+
defensiveType: 'Type',
|
|
55
|
+
none: '_none_',
|
|
56
|
+
fixes: 'Fixes',
|
|
57
|
+
file: 'File',
|
|
58
|
+
delta: 'Δ',
|
|
59
|
+
result: 'Result',
|
|
60
|
+
applied: 'applied',
|
|
61
|
+
failed: 'failed',
|
|
62
|
+
validations: 'Validations',
|
|
63
|
+
command: 'Command',
|
|
64
|
+
exit: 'Exit',
|
|
65
|
+
allowed: 'Allowed',
|
|
66
|
+
yes: 'yes',
|
|
67
|
+
no: 'no',
|
|
68
|
+
defenseEvents: 'Defense events',
|
|
69
|
+
experienceBank: 'Experience bank',
|
|
70
|
+
hits: 'hits',
|
|
71
|
+
entries: 'entries',
|
|
72
|
+
generatedAt: 'Generated at',
|
|
73
|
+
notRecorded: 'not recorded',
|
|
74
|
+
},
|
|
75
|
+
zh: {
|
|
76
|
+
title: 'iterate 运行报告',
|
|
77
|
+
project: '项目',
|
|
78
|
+
goal: '目标',
|
|
79
|
+
mode: '模式',
|
|
80
|
+
status: '状态',
|
|
81
|
+
round: '轮次',
|
|
82
|
+
updated: '更新时间',
|
|
83
|
+
converged: '已收敛',
|
|
84
|
+
running: '运行中',
|
|
85
|
+
stopped: '已结束',
|
|
86
|
+
qualityGate: '质量门禁',
|
|
87
|
+
overall: '总体',
|
|
88
|
+
verification: '验证',
|
|
89
|
+
dimension: '维度',
|
|
90
|
+
qstatus: '状态',
|
|
91
|
+
score: '得分',
|
|
92
|
+
findingsCount: '发现数',
|
|
93
|
+
fixed: '已修复',
|
|
94
|
+
convergence: '收敛率',
|
|
95
|
+
findings: '发现',
|
|
96
|
+
severity: '严重度',
|
|
97
|
+
location: '位置',
|
|
98
|
+
summary: '摘要',
|
|
99
|
+
defensiveType: '类型',
|
|
100
|
+
none: '无',
|
|
101
|
+
fixes: '修复',
|
|
102
|
+
file: '文件',
|
|
103
|
+
delta: '变更',
|
|
104
|
+
result: '结果',
|
|
105
|
+
applied: '成功',
|
|
106
|
+
failed: '失败',
|
|
107
|
+
validations: '验证',
|
|
108
|
+
command: '命令',
|
|
109
|
+
exit: '退出码',
|
|
110
|
+
allowed: '已授权',
|
|
111
|
+
yes: '是',
|
|
112
|
+
no: '否',
|
|
113
|
+
defenseEvents: '防御事件',
|
|
114
|
+
experienceBank: '经验银行',
|
|
115
|
+
hits: '命中',
|
|
116
|
+
entries: '条目',
|
|
117
|
+
generatedAt: '生成时间',
|
|
118
|
+
notRecorded: '未记录',
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
function reportLabels(lang) {
|
|
122
|
+
return lang === 'en' ? REPORT_LABELS.en : REPORT_LABELS.zh;
|
|
123
|
+
}
|
|
124
|
+
/** Proxy-safe object read (never lets a hostile getter trap throw). */
|
|
125
|
+
function get(source, key) {
|
|
126
|
+
if (!source || typeof source !== 'object')
|
|
127
|
+
return undefined;
|
|
128
|
+
try {
|
|
129
|
+
return source[key];
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function asString(value) {
|
|
136
|
+
return typeof value === 'string' ? value : '';
|
|
137
|
+
}
|
|
138
|
+
function asNumber(value) {
|
|
139
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : 0;
|
|
140
|
+
}
|
|
141
|
+
function asArray(value) {
|
|
142
|
+
return Array.isArray(value) ? value : [];
|
|
143
|
+
}
|
|
144
|
+
function asObject(value) {
|
|
145
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
146
|
+
? value
|
|
147
|
+
: null;
|
|
148
|
+
}
|
|
149
|
+
/** Escape a value for a Markdown table cell / inline text. */
|
|
150
|
+
function mdCell(value) {
|
|
151
|
+
const s = value === null || value === undefined ? '' : String(value);
|
|
152
|
+
return s.replace(/\|/g, '\\|').replace(/\r?\n/g, ' ').trim();
|
|
153
|
+
}
|
|
154
|
+
/** Severity of a finding, defaulting to the least-severe bucket. */
|
|
155
|
+
function findingSeverity(f) {
|
|
156
|
+
const s = get(f, 'severity');
|
|
157
|
+
return typeof s === 'string' && SEVERITY_ORDER.includes(s) ? s : 'low';
|
|
158
|
+
}
|
|
159
|
+
/** Repo-relative POSIX uri for SARIF artifact locations. */
|
|
160
|
+
function sarifUri(file) {
|
|
161
|
+
const s = typeof file === 'string' ? file.trim() : '';
|
|
162
|
+
if (!s)
|
|
163
|
+
return '';
|
|
164
|
+
return s.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
165
|
+
}
|
|
166
|
+
/** SARIF result level for an iterate severity. */
|
|
167
|
+
export function sarifLevel(severity) {
|
|
168
|
+
if (severity === 'critical' || severity === 'high')
|
|
169
|
+
return 'error';
|
|
170
|
+
if (severity === 'medium')
|
|
171
|
+
return 'warning';
|
|
172
|
+
return 'note';
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Normalize a manifest (+ the pulled disk artifacts) into ONE shape. Pure;
|
|
176
|
+
* tolerates junk at every field.
|
|
177
|
+
*/
|
|
178
|
+
export function buildRunReportData(manifest, extra) {
|
|
179
|
+
const src = asObject(manifest) ?? {};
|
|
180
|
+
const ex = asObject(extra);
|
|
181
|
+
const qg = asObject(get(ex, 'qualityGate'));
|
|
182
|
+
const bank = asObject(get(ex, 'experienceBank'));
|
|
183
|
+
const defense = asObject(get(ex, 'defenseEvents'));
|
|
184
|
+
const findings = asArray(get(src, 'findings')).map((f) => ({
|
|
185
|
+
dimension: asString(get(f, 'dimension')),
|
|
186
|
+
file: asString(get(f, 'file')),
|
|
187
|
+
line: asNumber(get(f, 'line')),
|
|
188
|
+
severity: findingSeverity(f),
|
|
189
|
+
summary: asString(get(f, 'summary')),
|
|
190
|
+
failureScenario: asString(get(f, 'failure_scenario')),
|
|
191
|
+
suggestedFix: asString(get(f, 'suggested_fix')),
|
|
192
|
+
isAtomic: get(f, 'is_atomic') === true,
|
|
193
|
+
acknowledged: get(f, 'acknowledged') === true,
|
|
194
|
+
}));
|
|
195
|
+
findings.sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) -
|
|
196
|
+
SEVERITY_ORDER.indexOf(b.severity));
|
|
197
|
+
const fixes = asArray(get(src, 'fixes')).map((f) => ({
|
|
198
|
+
round: asNumber(get(f, 'round')),
|
|
199
|
+
file: asString(get(f, 'file')),
|
|
200
|
+
summary: asString(get(f, 'summary')),
|
|
201
|
+
linesAdded: asNumber(get(f, 'linesAdded')),
|
|
202
|
+
linesRemoved: asNumber(get(f, 'linesRemoved')),
|
|
203
|
+
success: get(f, 'success') !== false,
|
|
204
|
+
}));
|
|
205
|
+
const validations = asArray(get(src, 'validations')).map((v) => ({
|
|
206
|
+
round: asNumber(get(v, 'round')),
|
|
207
|
+
command: asString(get(v, 'command')),
|
|
208
|
+
exitCode: typeof get(v, 'exitCode') === 'number' ? asNumber(get(v, 'exitCode')) : null,
|
|
209
|
+
allowed: get(v, 'allowed') === true,
|
|
210
|
+
rejectReason: asString(get(v, 'rejectReason')),
|
|
211
|
+
}));
|
|
212
|
+
const severityCounts = { critical: 0, high: 0, medium: 0, low: 0 };
|
|
213
|
+
for (const f of findings) {
|
|
214
|
+
const key = f.severity;
|
|
215
|
+
if (key in severityCounts)
|
|
216
|
+
severityCounts[key] += 1;
|
|
217
|
+
}
|
|
218
|
+
const mode = get(src, 'mode');
|
|
219
|
+
const taskMode = get(src, 'taskMode');
|
|
220
|
+
const stoppedReason = get(src, 'stoppedReason');
|
|
221
|
+
return {
|
|
222
|
+
project: asString(get(src, 'project')),
|
|
223
|
+
goal: asString(get(src, 'goal')),
|
|
224
|
+
mode: mode === 'normal' || mode === 'dry-run' ? mode : null,
|
|
225
|
+
taskMode: taskMode === 'code' || taskMode === 'iterate' ? taskMode : null,
|
|
226
|
+
round: asNumber(get(src, 'round')),
|
|
227
|
+
maxRounds: asNumber(get(src, 'maxRounds')),
|
|
228
|
+
active: get(src, 'active') !== false,
|
|
229
|
+
stoppedReason: typeof stoppedReason === 'string' && stoppedReason ? stoppedReason : null,
|
|
230
|
+
updatedAt: asString(get(src, 'updatedAt')),
|
|
231
|
+
convergence: asArray(get(src, 'convergence')).filter((n) => typeof n === 'number' && Number.isFinite(n) && n >= 0),
|
|
232
|
+
findings,
|
|
233
|
+
severityCounts,
|
|
234
|
+
fixes,
|
|
235
|
+
validations,
|
|
236
|
+
qualityGate: qg,
|
|
237
|
+
experienceBank: bank,
|
|
238
|
+
defenseEvents: defense,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** One-line human status for the report header. */
|
|
242
|
+
function reportStatus(data, labels) {
|
|
243
|
+
if (data.active === true)
|
|
244
|
+
return labels.running;
|
|
245
|
+
if (data.stoppedReason)
|
|
246
|
+
return `${labels.stopped} · ${data.stoppedReason}`;
|
|
247
|
+
return labels.stopped;
|
|
248
|
+
}
|
|
249
|
+
/** Render a PR-pasteable Markdown run report. */
|
|
250
|
+
export function renderRunReportMarkdown(manifest, extra, opts) {
|
|
251
|
+
const data = buildRunReportData(manifest, extra);
|
|
252
|
+
const o = opts ?? {};
|
|
253
|
+
const labels = reportLabels(o.lang === 'en' ? 'en' : 'zh');
|
|
254
|
+
const when = o.now && o.now ? o.now : new Date().toISOString();
|
|
255
|
+
const lines = [];
|
|
256
|
+
lines.push(`# ${labels.title}`);
|
|
257
|
+
lines.push('');
|
|
258
|
+
lines.push(`- **${labels.project}**: \`${mdCell(data.project || labels.notRecorded)}\``);
|
|
259
|
+
if (data.goal)
|
|
260
|
+
lines.push(`- **${labels.goal}**: ${mdCell(data.goal)}`);
|
|
261
|
+
lines.push(`- **${labels.mode}**: ${mdCell(data.mode || labels.notRecorded)}${data.taskMode ? ` · task_mode: ${data.taskMode}` : ''}`);
|
|
262
|
+
const roundText = data.maxRounds > 0 ? `${data.round}/${data.maxRounds}` : String(data.round);
|
|
263
|
+
lines.push(`- **${labels.round}**: ${mdCell(roundText)} · **${labels.status}**: ${mdCell(reportStatus(data, labels))}`);
|
|
264
|
+
lines.push(`- **${labels.updated}**: ${mdCell(data.updatedAt || when)}`);
|
|
265
|
+
lines.push(`- **${labels.generatedAt}**: ${mdCell(when)}`);
|
|
266
|
+
lines.push('');
|
|
267
|
+
// ── Quality gate ──
|
|
268
|
+
const qg = data.qualityGate;
|
|
269
|
+
if (qg) {
|
|
270
|
+
lines.push(`## ${labels.qualityGate}`);
|
|
271
|
+
lines.push('');
|
|
272
|
+
const status = typeof qg.overallStatus === 'string' ? qg.overallStatus.toUpperCase() : 'PENDING';
|
|
273
|
+
lines.push(`- **${labels.overall}**: ${mdCell(status)} (${labels.score} ${asNumber(qg.overallScore)})`);
|
|
274
|
+
lines.push(`- **${labels.verification}**: ${asNumber(qg.passedChecks)}/${asNumber(qg.totalChecks)} (${asNumber(qg.verificationPassRate)}%)`);
|
|
275
|
+
if (typeof qg.failReason === 'string' && qg.failReason) {
|
|
276
|
+
lines.push(`- ${labels.status}: ${mdCell(qg.failReason)}`);
|
|
277
|
+
}
|
|
278
|
+
lines.push('');
|
|
279
|
+
const dims = asArray(qg.dimensions);
|
|
280
|
+
if (dims.length > 0) {
|
|
281
|
+
lines.push(`| ${labels.dimension} | ${labels.qstatus} | ${labels.score} | ${labels.findingsCount} | ${labels.fixed} | ${labels.convergence} |`);
|
|
282
|
+
lines.push('| --- | --- | --- | --- | --- | --- |');
|
|
283
|
+
for (const d of dims) {
|
|
284
|
+
lines.push(`| ${mdCell(get(d, 'dimension'))} | ${mdCell(get(d, 'status'))} | ${mdCell(get(d, 'score'))} | ${mdCell(get(d, 'findingsCount'))} | ${mdCell(get(d, 'fixedCount'))} | ${mdCell(get(d, 'convergenceRate'))}% |`);
|
|
285
|
+
}
|
|
286
|
+
lines.push('');
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
// ── Findings ──
|
|
290
|
+
lines.push(`## ${labels.findings} (${data.findings.length})`);
|
|
291
|
+
lines.push('');
|
|
292
|
+
if (data.findings.length === 0) {
|
|
293
|
+
lines.push(labels.none);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
lines.push(`| ${labels.severity} | ${labels.dimension} | ${labels.location} | ${labels.summary} |`);
|
|
297
|
+
lines.push('| --- | --- | --- | --- |');
|
|
298
|
+
for (const f of data.findings) {
|
|
299
|
+
const loc = f.file ? `${f.file}${f.line > 1 ? `:${f.line}` : ''}` : '';
|
|
300
|
+
lines.push(`| ${mdCell(f.severity)} | ${mdCell(f.dimension)} | ${mdCell(loc)} | ${mdCell(f.summary)} |`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
lines.push('');
|
|
304
|
+
// ── Fixes ──
|
|
305
|
+
lines.push(`## ${labels.fixes} (${data.fixes.length})`);
|
|
306
|
+
lines.push('');
|
|
307
|
+
if (data.fixes.length === 0) {
|
|
308
|
+
lines.push(labels.none);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
lines.push(`| # | ${labels.file} | ${labels.delta} | ${labels.result} | ${labels.summary} |`);
|
|
312
|
+
lines.push('| --- | --- | --- | --- | --- |');
|
|
313
|
+
for (const f of data.fixes) {
|
|
314
|
+
lines.push(`| ${mdCell(f.round)} | ${mdCell(f.file)} | ${mdCell(`+${f.linesAdded}/-${f.linesRemoved}`)} | ${f.success ? labels.applied : labels.failed} | ${mdCell(f.summary)} |`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
lines.push('');
|
|
318
|
+
// ── Validations ──
|
|
319
|
+
if (data.validations.length > 0) {
|
|
320
|
+
lines.push(`## ${labels.validations}`);
|
|
321
|
+
lines.push('');
|
|
322
|
+
lines.push(`| # | ${labels.command} | ${labels.exit} | ${labels.allowed} |`);
|
|
323
|
+
lines.push('| --- | --- | --- | --- |');
|
|
324
|
+
for (const v of data.validations) {
|
|
325
|
+
lines.push(`| ${mdCell(v.round)} | \`${mdCell(v.command)}\` | ${v.exitCode === null ? '—' : mdCell(v.exitCode)} | ${v.allowed ? labels.yes : labels.no} |`);
|
|
326
|
+
}
|
|
327
|
+
lines.push('');
|
|
328
|
+
}
|
|
329
|
+
// ── Defense events ──
|
|
330
|
+
const deEvents = asArray(get(data.defenseEvents, 'events'));
|
|
331
|
+
if (deEvents.length > 0) {
|
|
332
|
+
lines.push(`## ${labels.defenseEvents} (${deEvents.length})`);
|
|
333
|
+
lines.push('');
|
|
334
|
+
lines.push(`| ${labels.severity} | ${labels.defensiveType} | ${labels.round} | ${labels.summary} |`);
|
|
335
|
+
lines.push('| --- | --- | --- | --- |');
|
|
336
|
+
for (const e of deEvents) {
|
|
337
|
+
lines.push(`| ${mdCell(get(e, 'severity'))} | ${mdCell(get(e, 'type'))} | ${mdCell(get(e, 'round'))} | ${mdCell(get(e, 'description') || get(e, 'outcome'))} |`);
|
|
338
|
+
}
|
|
339
|
+
lines.push('');
|
|
340
|
+
}
|
|
341
|
+
// ── Experience bank ──
|
|
342
|
+
const entries = asArray(get(data.experienceBank, 'entries'));
|
|
343
|
+
if (entries.length > 0) {
|
|
344
|
+
const totalHits = asNumber(get(data.experienceBank, 'totalHits'));
|
|
345
|
+
lines.push(`## ${labels.experienceBank} (${entries.length} ${labels.entries}, ${totalHits} ${labels.hits})`);
|
|
346
|
+
lines.push('');
|
|
347
|
+
for (const e of entries) {
|
|
348
|
+
lines.push(`- **[${mdCell(get(e, 'id'))}]** ${mdCell(get(e, 'pattern'))} — ${mdCell(get(e, 'description'))} (${labels.hits}: ${mdCell(get(e, 'hitCount'))})`);
|
|
349
|
+
}
|
|
350
|
+
lines.push('');
|
|
351
|
+
}
|
|
352
|
+
return lines.join('\n').replace(/\n{3,}/g, '\n\n').trimEnd() + '\n';
|
|
353
|
+
}
|
|
354
|
+
/** Render a SARIF 2.1.0 document from the same normalized data. */
|
|
355
|
+
export function renderRunReportSarif(manifest, extra, opts) {
|
|
356
|
+
const data = buildRunReportData(manifest, extra);
|
|
357
|
+
const o = opts ?? {};
|
|
358
|
+
const rules = [];
|
|
359
|
+
const seenRules = new Set();
|
|
360
|
+
for (const f of data.findings) {
|
|
361
|
+
const id = f.dimension || 'review';
|
|
362
|
+
if (seenRules.has(id))
|
|
363
|
+
continue;
|
|
364
|
+
seenRules.add(id);
|
|
365
|
+
rules.push({
|
|
366
|
+
id,
|
|
367
|
+
name: id,
|
|
368
|
+
shortDescription: { text: `${id} review dimension` },
|
|
369
|
+
defaultConfiguration: { level: 'warning' },
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
const results = data.findings.map((f) => {
|
|
373
|
+
const result = {
|
|
374
|
+
ruleId: f.dimension || 'review',
|
|
375
|
+
level: sarifLevel(f.severity),
|
|
376
|
+
message: { text: f.summary || `${f.severity} finding` },
|
|
377
|
+
properties: {
|
|
378
|
+
severity: f.severity,
|
|
379
|
+
atomic: f.isAtomic,
|
|
380
|
+
acknowledged: f.acknowledged,
|
|
381
|
+
},
|
|
382
|
+
};
|
|
383
|
+
const uri = sarifUri(f.file);
|
|
384
|
+
if (uri) {
|
|
385
|
+
result.locations = [
|
|
386
|
+
{
|
|
387
|
+
physicalLocation: {
|
|
388
|
+
artifactLocation: { uri },
|
|
389
|
+
...(f.line > 0 ? { region: { startLine: f.line } } : {}),
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
];
|
|
393
|
+
}
|
|
394
|
+
if (f.suggestedFix)
|
|
395
|
+
result.fixes = [{ description: { text: f.suggestedFix } }];
|
|
396
|
+
return result;
|
|
397
|
+
});
|
|
398
|
+
const failedValidations = data.validations.filter((v) => v.exitCode !== 0).length;
|
|
399
|
+
return {
|
|
400
|
+
$schema: 'https://json.schemastore.org/sarif-2.1.0.json',
|
|
401
|
+
version: '2.1.0',
|
|
402
|
+
runs: [
|
|
403
|
+
{
|
|
404
|
+
tool: {
|
|
405
|
+
driver: {
|
|
406
|
+
name: 'iterate-plugin',
|
|
407
|
+
informationUri: o.informationUri && o.informationUri
|
|
408
|
+
? o.informationUri
|
|
409
|
+
: 'https://github.com/jingzhao-l/iterate-plugin',
|
|
410
|
+
...(o.toolVersion ? { version: o.toolVersion } : {}),
|
|
411
|
+
rules,
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
invocations: [
|
|
415
|
+
{
|
|
416
|
+
executionSuccessful: failedValidations === 0 && data.qualityGate?.overallStatus !== 'fail',
|
|
417
|
+
...(data.updatedAt ? { startTimeUtc: data.updatedAt } : {}),
|
|
418
|
+
properties: {
|
|
419
|
+
mode: data.mode,
|
|
420
|
+
taskMode: data.taskMode,
|
|
421
|
+
round: data.round,
|
|
422
|
+
maxRounds: data.maxRounds,
|
|
423
|
+
stoppedReason: data.stoppedReason,
|
|
424
|
+
qualityStatus: data.qualityGate ? (data.qualityGate.overallStatus ?? null) : null,
|
|
425
|
+
convergence: data.convergence,
|
|
426
|
+
findingsBySeverity: data.severityCounts,
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
],
|
|
430
|
+
results,
|
|
431
|
+
},
|
|
432
|
+
],
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Render a report in the requested format. Unknown formats fall back to
|
|
437
|
+
* Markdown (the tool's default).
|
|
438
|
+
*/
|
|
439
|
+
export function renderRunReport(format, manifest, extra, opts) {
|
|
440
|
+
if (format === 'sarif')
|
|
441
|
+
return renderRunReportSarif(manifest, extra, opts);
|
|
442
|
+
return renderRunReportMarkdown(manifest, extra, opts);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Deterministic download filename for a report, e.g.
|
|
446
|
+
* `iterate-report-2026-10-18T01-02-03-000Z.md`.
|
|
447
|
+
*/
|
|
448
|
+
export function runReportFilename(format, opts) {
|
|
449
|
+
const ext = format === 'sarif' ? 'sarif' : 'md';
|
|
450
|
+
const stamp = opts?.now && opts.now ? opts.now.replace(/[:.]/g, '-') : new Date().toISOString().replace(/[:.]/g, '-');
|
|
451
|
+
return `iterate-report-${stamp}.${ext}`;
|
|
452
|
+
}
|