@xenonbyte/da-vinci-workflow 0.2.2 → 0.2.3

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 (54) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +24 -14
  3. package/README.zh-CN.md +25 -14
  4. package/commands/claude/dv/breakdown.md +8 -0
  5. package/commands/claude/dv/build.md +11 -0
  6. package/commands/claude/dv/design.md +5 -2
  7. package/commands/claude/dv/tasks.md +8 -0
  8. package/commands/claude/dv/verify.md +9 -0
  9. package/commands/codex/prompts/dv-breakdown.md +8 -0
  10. package/commands/codex/prompts/dv-build.md +11 -0
  11. package/commands/codex/prompts/dv-design.md +5 -2
  12. package/commands/codex/prompts/dv-tasks.md +8 -0
  13. package/commands/codex/prompts/dv-verify.md +8 -0
  14. package/commands/gemini/dv/breakdown.toml +8 -0
  15. package/commands/gemini/dv/build.toml +11 -0
  16. package/commands/gemini/dv/design.toml +5 -2
  17. package/commands/gemini/dv/tasks.toml +8 -0
  18. package/commands/gemini/dv/verify.toml +8 -0
  19. package/docs/dv-command-reference.md +43 -0
  20. package/docs/execution-chain-plan.md +10 -3
  21. package/docs/mode-use-cases.md +2 -1
  22. package/docs/pencil-rendering-workflow.md +15 -12
  23. package/docs/prompt-presets/README.md +1 -1
  24. package/docs/prompt-presets/desktop-app.md +3 -3
  25. package/docs/prompt-presets/mobile-app.md +3 -3
  26. package/docs/prompt-presets/tablet-app.md +3 -3
  27. package/docs/prompt-presets/web-app.md +3 -3
  28. package/docs/skill-usage.md +45 -38
  29. package/docs/workflow-examples.md +16 -13
  30. package/docs/workflow-overview.md +2 -0
  31. package/docs/zh-CN/dv-command-reference.md +43 -0
  32. package/docs/zh-CN/mode-use-cases.md +2 -1
  33. package/docs/zh-CN/pencil-rendering-workflow.md +15 -12
  34. package/docs/zh-CN/prompt-presets/README.md +1 -1
  35. package/docs/zh-CN/prompt-presets/desktop-app.md +3 -3
  36. package/docs/zh-CN/prompt-presets/mobile-app.md +3 -3
  37. package/docs/zh-CN/prompt-presets/tablet-app.md +3 -3
  38. package/docs/zh-CN/prompt-presets/web-app.md +3 -3
  39. package/docs/zh-CN/skill-usage.md +45 -38
  40. package/docs/zh-CN/workflow-examples.md +15 -13
  41. package/docs/zh-CN/workflow-overview.md +2 -0
  42. package/examples/greenfield-spec-markupflow/.da-vinci/state/execution-signals/demo__lint-tasks.json +16 -0
  43. package/lib/audit-parsers.js +18 -9
  44. package/lib/audit.js +3 -26
  45. package/lib/cli.js +50 -1
  46. package/lib/design-source-registry.js +146 -0
  47. package/lib/save-current-design.js +790 -0
  48. package/lib/supervisor-review.js +1 -1
  49. package/lib/workflow-bootstrap.js +2 -13
  50. package/lib/workflow-persisted-state.js +3 -1
  51. package/lib/workflow-state.js +51 -3
  52. package/package.json +1 -1
  53. package/tui/catalog.js +103 -0
  54. package/tui/index.js +2274 -418
@@ -121,7 +121,7 @@ Design 1-3 anchor surfaces first, review screenshots, then expand.
121
121
  如果同一个 anchor surface 连续两次回滚,就切到每批不超过 6 个操作的微批次,直到拿到干净的 schema-safe pass。
122
122
  在第一次成功写入 Pencil 后、继续大范围扩展前,先运行 `da-vinci audit --mode integrity <project-path>`。
123
123
  如果 Pencil MCP 可用,在第一次成功写入 Pencil 后运行 MCP runtime gate,并把结果记录到 `pencil-design.md`。
124
- 在第一次 Pencil 编辑前,必须执行 `da-vinci pencil-session begin --project <project-path> --pen <path>`;发生实质性 live edit 后,必须执行 `da-vinci pencil-session persist --project <project-path> --pen <path> ...`。只有 session wrapper 不可用时,才退回 `ensure-pen + write-pen + check-pen-sync` 这条底层链路。
124
+ 在第一次 Pencil 编辑前,必须执行 `da-vinci pencil-session begin --project <project-path> --pen <path>`;发生实质性 live edit 后,优先执行 `da-vinci save-current-design --project <project-path>`。必须区分 `saved`、`blocked`、`unavailable` 三类结果;只有高层桥接返回 `unavailable` 时,才退回 `pencil-session persist --nodes-file/--variables-file` 这条底层链路。
125
125
  截图导出只能写到 `.da-vinci/changes/<change-id>/exports/`,不能写进 `.da-vinci/designs/`。
126
126
  截图审查必须记录明确的 `PASS` / `WARN` / `BLOCK`、问题列表和是否回改;“看起来很好”不算审查记录。
127
127
  如果 `DA-VINCI.md` 配置了 `Design-supervisor reviewers`,就在 screenshot review、layout hygiene 和 design checkpoint 之后再做 `design-supervisor review`,输入要同时包含 screenshots、Pencil variables 和设计 thesis。若 `Require Supervisor Review: true`,那么缺失、`BLOCK`、或未被接受的 review 结果都要视为阻断。
@@ -157,7 +157,7 @@ Design 1-3 anchor surfaces first, review screenshots, then expand.
157
157
  For each anchor surface, explain how the new composition differs structurally from the current layout and whether it is primarily HTML-referenced, partially HTML-referenced, or inferred.
158
158
 
159
159
  Before non-trivial `batch_design` calls, preflight the Pencil operations when shell access is available.
160
- Require `da-vinci pencil-session begin --project <project-path> --pen <path>` before the first Pencil edit, then use `da-vinci pencil-session persist --project <project-path> --pen <path> ...` after material live edits.
160
+ Require `da-vinci pencil-session begin --project <project-path> --pen <path>` before the first Pencil edit, then use `da-vinci save-current-design --project <project-path>` after material live edits. Treat `saved`, `blocked`, and `unavailable` as distinct outcomes.
161
161
  Run the MCP runtime gate after the first successful Pencil write and record it in `pencil-design.md`.
162
162
  Before reporting `design complete` or `workflow complete`, require both the MCP runtime gate and `da-vinci audit --mode completion --change <change-id> <project-path>` to pass.
163
163
  Persist project-local Pencil files under .da-vinci/designs/.
@@ -191,7 +191,7 @@ $da-vinci use continue for this existing web-product redesign workflow.
191
191
  Use the existing Da Vinci artifacts in this project.
192
192
  Do not restart discovery unless an artifact is missing or clearly wrong.
193
193
  选路先以当前工件和 checkpoint 真相为准,再把 Context Delta 作为辅助恢复信息;如果 Context Delta 与工件冲突,忽略冲突条目并记录冲突后继续。
194
- 把登记的项目内 Pencil 源保持在 `.da-vinci/designs/` 下,作为设计真相源。如果继续这一轮会做 Pencil 编辑,必须先执行 `da-vinci pencil-session begin --project <project-path> --pen <path>`,发生实质性 live edit 后再执行 `da-vinci pencil-session persist --project <project-path> --pen <path> ...`;只有 session wrapper 不可用时,才退回 `write-pen + check-pen-sync` 这条底层链路。
194
+ 把登记的项目内 Pencil 源保持在 `.da-vinci/designs/` 下,作为设计真相源。如果继续这一轮会做 Pencil 编辑,必须先执行 `da-vinci pencil-session begin --project <project-path> --pen <path>`,发生实质性 live edit 后优先执行 `da-vinci save-current-design --project <project-path>`。必须区分 `saved`、`blocked`、`unavailable`;只有高层桥接返回 `unavailable` 时,才回退到底层 payload 持久化链路。
195
195
  If the redesign is complex, continue from the approved anchor surfaces instead of restarting broad scaffolding.
196
196
  如果 Pencil MCP 可用,且这一轮继续做了新的 Pencil 写入,就重新运行 MCP runtime gate,并把最新结果记录到 `pencil-design.md`。
197
197
  在声明 `design complete` 或 `workflow complete` 之前,必须同时通过 MCP runtime gate 和 `da-vinci audit --mode completion --change <change-id> <project-path>`。
@@ -146,67 +146,74 @@ npx -p @xenonbyte/da-vinci-workflow da-vinci-tui
146
146
 
147
147
  TUI 提供这些能力:
148
148
 
149
- - 按工作流阶段对命令分组
150
- - 中英文双语界面说明
151
- - 顶部显示当前项目路径和 change-id 上下文
152
- - 执行前可先看命令预览
153
- - 一键切换 `--strict`、`--json`、`--continue-on-error`
154
- - `<pen-path>` 这类还没补具体路径的命令,支持先编辑预览再执行
149
+ - 首屏按场景组织:`安装与卸载`、`当前状态`、`切换工作项`、`设计操作`、`实施前检查`、`验收前检查`、`设置`
150
+ - 常用链路直接做成组合入口(续跑、实施前检查、验收前检查)
151
+ - `设计操作` 聚焦实用设计操作(`保存当前设计稿`、`同步图标库`、`Visual Assist 预设`)
152
+ - `安装与卸载` 提供三个动作:`状态`(查看 `da-vinci status`)、`安装`(一键安装所有支持平台)、`卸载`(一键卸载所有支持平台)
153
+ - 界面中英双语,但 Visual Assist 输出始终使用英文权威源
154
+ - 顶部只保留最小上下文(项目 + change)
155
+ - `设置` 仅保留 `语言` 和 `日志`
156
+ - `设置 > 日志` 提供项目内每日诊断日志(`.da-vinci/logs/YYYY-MM-DD.ndjson`)
155
157
 
156
- ### TUI 阶段图
158
+ ### TUI 场景图
157
159
 
158
160
  ```mermaid
159
161
  flowchart TD
160
- A[启动 da-vinci tui] --> B[设置 project path 和 change-id 上下文]
161
- B --> C[选路与续跑<br/>workflow-status / next-step]
162
- C --> D{当前处于哪个阶段?}
163
-
164
- D --> E[规划与漂移检查<br/>lint-spec / scope-check / lint-tasks / lint-bindings / generate-sidecars / diff-spec / scaffold]
165
- D --> F[视觉与审查<br/>icon-sync / icon-search / supervisor-review]
166
- D --> G[Pen 文件与同步<br/>preflight-pencil / ensure-pen / write-pen / check-pen-sync / check-pen-baseline / sync-pen-source / snapshot-pen]
167
- D --> H[Pencil 会话<br/>pencil-lock * / pencil-session begin|persist|end|status]
168
- D --> I[验证与完成<br/>verify-bindings / verify-implementation / verify-structure / verify-coverage / audit]
169
- D --> J[初始化与工具<br/>install / uninstall / status / validate-assets / bootstrap-project]
170
-
171
- E --> I
172
- F --> G
173
- G --> H
174
- H --> E
175
- I --> K{可以收尾了吗?}
176
- K -->|还不行| C
177
- K -->|可以| L[跑 completion audit 并做终态声明]
162
+ A[启动 da-vinci tui] --> B[设置 project 和 change 上下文]
163
+ B --> C[安装与卸载<br/>状态 + 一键安装/卸载全部平台]
164
+ B --> D[当前状态<br/>workflow-status + next-step 总结]
165
+ B --> E[切换工作项<br/>选择已有 change]
166
+ B --> F[设计操作<br/>图标同步 + Visual Assist 预设]
167
+ B --> G[实施前检查<br/>实现前就绪度检查]
168
+ B --> H[验收前检查<br/>verify-* 链路]
169
+ B --> I[设置<br/>语言 + 日志]
178
170
  ```
179
171
 
180
172
  你可以把它理解成这四条最实用的规则:
181
173
 
182
- - 先从“选路与续跑”开始
183
- - 再进入当前 blocker 所在的阶段
184
- - 只要中途暂停,或者工件发生了实质变化,就回到“选路与续跑”
185
- - 只有验证链和 completion audit 都通过了,才进入终态
174
+ - 先选“当前时机”对应的场景
175
+ - 优先用场景入口完成常用检查
176
+ - 只要中途暂停或路由不清晰,就进入“当前状态”
177
+ - 只有“验收前检查”通过,才进入终态
178
+
179
+ Visual Assist 预设映射(`设计操作 > Visual Assist 预设`):
180
+
181
+ - `Masterpiece` => `required reviewer signoff`
182
+ - `High Quality` => `advisory reviewer`
183
+ - `Normal` => `adapter-only`
184
+
185
+ Visual Assist 受控写入规则:
186
+
187
+ - 先选平台,再从 3 档质量中选择(对应 Variant 1/2/3)
188
+ - 内容来自 `docs/visual-assist-presets/` 的英文权威源
189
+ - 只替换项目根 `DA-VINCI.md` 的 `## Visual Assist`
190
+ - 保留无关章节,避免重复 `## Visual Assist`
186
191
 
187
192
  主要按键:
188
193
 
189
194
  - `Up/Down` 或 `j/k`:移动选中项
190
- - `Enter` 或 `r`:执行当前命令
191
- - `h`:查看当前命令参数
192
- - `m`:先编辑预览命令
195
+ - `Enter` 或 `r`:进入当前场景/动作
196
+ - `u/d`:长内容按页上下翻
197
+ - `g/G`:长内容跳到顶部/底部
193
198
  - `p`:修改项目路径上下文
194
199
  - `c`:修改或清空 change-id 上下文
195
200
  - `l`:切换中英文
201
+ - `t`:主题识别不准时,手动切换主题模式
196
202
  - `s`:切换 `--strict`
197
203
  - `J`:切换 `--json`
198
204
  - `e`:切换 `--continue-on-error`
199
205
  - `?`:打开帮助
200
- - `q`:退出
206
+ - `Ctrl-C`:紧急退出
201
207
 
202
208
  推荐的 TUI 使用顺序:
203
209
 
204
210
  1. 在项目根目录启动 TUI
205
- 2. 先确认顶部的 project path 和 change-id
206
- 3. 先跑 `workflow-status`
207
- 4. 再跑 `next-step`
208
- 5. 根据情况进入 `lint-spec`、`scope-check`、`tasks`、`verify-*`
209
- 6. 如果是 Pencil 相关特殊命令,按 `m` 先把剩余占位符补全后再执行
211
+ 2. 先选当前任务对应的场景
212
+ 3. 再确认顶部的 project path 和 change-id
213
+ 4. 优先执行场景入口(`切换工作项`、`实施前检查`、`安装与卸载`、`验收前检查`);需要续跑判断时进入 `当前状态`
214
+ 5. 需要管理 Visual Assist 时,进入 `设计操作 > Visual Assist 预设`,完成“平台 + 质量”选择后自动写入
215
+ 6. 需要查看安装态时进入 `安装与卸载 > 状态`;需要安装/卸载时进入 `安装与卸载 > 安装/卸载` 一键执行全部平台
216
+ 7. 排查问题时到 `设置 > 日志` 查看/复制当天日志;日志只做诊断证据,不替代工件真相
210
217
 
211
218
  ## 实用简化规则
212
219
 
@@ -110,17 +110,18 @@ $da-vinci use redesign-from-code to inventory the current app, identify current
110
110
  11. 如果同一个 anchor surface 连续两次回滚,就切到每批不超过 6 个操作的微批次,直到拿到干净的 schema-safe pass
111
111
  12. 如果这一轮开始时还没有登记的项目内 `.pen`,必须先执行 `da-vinci pencil-session begin --project <project-path> --pen <path>`,先 seed 登记路径并拿到全局锁,再开始第一次 Pencil 编辑
112
112
  13. 如果存在外部或历史 `.pen` 备份,在新一轮写入前先运行 `da-vinci check-pen-baseline --pen <project-pen> --baseline <other-pen>`;若 hash 不一致,先把选中的优先来源同步回 `<project-pen>`
113
- 14. 如果项目里原本已有登记的 `.pen`,继续设计时也必须先通过 `da-vinci pencil-session begin --project <project-path> --pen <path>` reopen 它;发生了实质性 live edit 后,再通过 `da-vinci pencil-session persist` 把当前 MCP 快照重新覆盖写回同一路径
114
- 15. 在第一次成功写入 Pencil 后,立即验证登记的项目内 `.pen` 路径已经成为 shell 可见文件
115
- 16. 紧接着运行 `da-vinci audit --mode integrity <project-path>`
116
- 17. 如果 Pencil MCP 可用,先运行 MCP runtime gate,并把结果记录到 `pencil-design.md`
117
- 18. 运行 `design-source checkpoint`,确认登记的项目内 `.pen` 路径、当前 Pencil 设计源和 shell 可见文件是一致的
118
- 19. 截图导出只放到 `.da-vinci/changes/<change-id>/exports/`,绝不能写进 `.da-vinci/designs/`
119
- 20. broad expansion 前,先把 screenshot review 的 `PASS` / `WARN` / `BLOCK`、问题列表和回改结果记清楚
120
- 21. 绑定路由和 Pencil 页面
121
- 22. 生成和 redesign slice 对齐的任务
122
- 23. 在任何终态完成声明之前,先运行 `da-vinci audit --mode completion --change <change-id> <project-path>`
123
- 24. 只有在 completion gate 最终能通过时,才进入实现和验证
113
+ 14. 如果项目里原本已有登记的 `.pen`,继续设计时也必须先通过 `da-vinci pencil-session begin --project <project-path> --pen <path>` reopen 它;发生实质性 live edit 后,优先执行 `da-vinci save-current-design --project <project-path>`
114
+ 15. 必须区分 `saved` / `blocked` / `unavailable`,只有 `saved` 才代表保存成功;`unavailable` 时才能回退到底层 payload 持久化链路
115
+ 16. 在第一次成功写入 Pencil 后,立即验证登记的项目内 `.pen` 路径已经成为 shell 可见文件
116
+ 17. 紧接着运行 `da-vinci audit --mode integrity <project-path>`
117
+ 18. 如果 Pencil MCP 可用,先运行 MCP runtime gate,并把结果记录到 `pencil-design.md`
118
+ 19. 运行 `design-source checkpoint`,确认登记的项目内 `.pen` 路径、当前 Pencil 设计源和 shell 可见文件是一致的
119
+ 20. 截图导出只放到 `.da-vinci/changes/<change-id>/exports/`,绝不能写进 `.da-vinci/designs/`
120
+ 21. broad expansion 前,先把 screenshot review 的 `PASS` / `WARN` / `BLOCK`、问题列表和回改结果记清楚
121
+ 22. 绑定路由和 Pencil 页面
122
+ 23. 生成和 redesign slice 对齐的任务
123
+ 24. 在任何终态完成声明之前,先运行 `da-vinci audit --mode completion --change <change-id> <project-path>`
124
+ 25. 只有在 completion gate 最终能通过时,才进入实现和验证
124
125
 
125
126
  ### 复杂 Android 页面示例
126
127
 
@@ -145,7 +146,8 @@ If the same anchor surface rolls back twice, switch to micro-batches of 6 or few
145
146
  Use only Pencil-supported properties; do not use web-only props like flex or margin.
146
147
  在第一次 Pencil 编辑前,必须执行 `da-vinci pencil-session begin --project <project-path> --pen <path>`,这样会先 seed 登记好的 `.pen` 并持有全局 Pencil 锁。
147
148
  如果存在外部或历史 `.pen`,先运行 `da-vinci check-pen-baseline --pen <project-pen> --baseline <other-pen>`;若 hash 分叉,先确认来源优先级并把选中的来源同步回 `<project-pen>` 再继续。
148
- 如果项目里原本已有登记的 `.pen`,继续设计时先打开它,但实质性 live edit 后优先通过 `da-vinci pencil-session persist` 把当前 live MCP 快照重新覆盖写回同一路径。
149
+ 如果项目里原本已有登记的 `.pen`,继续设计时先打开它,但实质性 live edit 后优先通过 `da-vinci save-current-design --project <project-path>` 保存。
150
+ 必须区分 `saved` / `blocked` / `unavailable`;只有 `saved` 才是保存成功,`unavailable` 才能触发底层回退。
149
151
  Verify the registered project-local `.pen` file exists as a shell-visible file after the first Pencil write.
150
152
  在第一次成功写入 Pencil 后、继续大范围扩展前,先运行 `da-vinci audit --mode integrity <project-path>`。
151
153
  Keep `.da-vinci/designs/` reserved for `.pen` files only.
@@ -218,7 +220,7 @@ If frontend-skill is available, use it as the primary visual adapter.
218
220
  If it is unavailable, fall back to native Da Vinci design rules and continue.
219
221
  Persist project-local Pencil files under .da-vinci/designs/.
220
222
  如果当前还没有登记的项目内 `.pen`,先在这里 seed 一个登记好的 `.pen`,再开始第一次 Pencil 编辑,并把后续 live 编辑持续绑定到这个路径。
221
- 如果项目里原本已有 `.pen`,继续设计后要把当前 MCP 快照覆盖写回同一路径。
223
+ 如果项目里原本已有 `.pen`,继续设计后优先执行 `da-vinci save-current-design --project <project-path>` 持久化;只有高层保存返回 `unavailable` 时才回退到底层 payload 持久化。
222
224
  ```
223
225
 
224
226
  ## 图标库辅助示例
@@ -159,6 +159,7 @@ anchor 通过后,再抽 shared primitives,然后再扩更多页面。
159
159
 
160
160
  - `design-source checkpoint`
161
161
  - 如果启用了 Pencil MCP,则跑 `MCP runtime gate`
162
+ - 发生实质性 live edit 后执行 `da-vinci save-current-design --project <project-path>`(高层绑定源保存路径)
162
163
  - 工作中期跑 `da-vinci audit --mode integrity <project-path>`
163
164
  - 在现有 change 工件里记录 checkpoint 邻近的 `Context Delta`
164
165
 
@@ -168,6 +169,7 @@ anchor 通过后,再抽 shared primitives,然后再扩更多页面。
168
169
  - active editor 是正确的设计源
169
170
  - shell 上确实有 `.pen`
170
171
  - live snapshot 和 persisted snapshot 已同步
172
+ - 高层保存结果被诚实处理(`saved` / `blocked` / `unavailable`)
171
173
  - 最近关键执行上下文可恢复,但不会替代工件真相的选路权
172
174
 
173
175
  ### 6. Mapping
@@ -0,0 +1,16 @@
1
+ {
2
+ "version": 1,
3
+ "surface": "lint-tasks",
4
+ "status": "WARN",
5
+ "advisory": true,
6
+ "strict": false,
7
+ "failures": [
8
+ "Missing `.da-vinci/` directory."
9
+ ],
10
+ "warnings": [],
11
+ "notes": [
12
+ "lint-tasks defaults to advisory mode; pass `--strict` to block on findings."
13
+ ],
14
+ "timestamp": "2026-03-31T16:22:40.193Z",
15
+ "changeId": "demo"
16
+ }
@@ -244,18 +244,27 @@ function normalizeCheckpointLabel(value) {
244
244
 
245
245
  function parseCheckpointStatusMap(markdownText) {
246
246
  const section = getMarkdownSection(markdownText, "Checkpoint Status");
247
- if (!section) {
248
- return {};
247
+ const statuses = {};
248
+
249
+ if (section) {
250
+ const matches = section.matchAll(/(?:^|\n)\s*-\s*`?([^`:\n]+?)`?\s*:\s*(PASS|WARN|BLOCK)\b/gi);
251
+ for (const match of matches) {
252
+ const label = normalizeCheckpointLabel(match[1]);
253
+ if (!label) {
254
+ continue;
255
+ }
256
+ statuses[label] = String(match[2]).toUpperCase();
257
+ }
249
258
  }
250
259
 
251
- const statuses = {};
252
- const matches = section.matchAll(/(?:^|\n)\s*-\s*`?([^`:\n]+?)`?\s*:\s*(PASS|WARN|BLOCK)\b/gi);
253
- for (const match of matches) {
254
- const label = normalizeCheckpointLabel(match[1]);
255
- if (!label) {
256
- continue;
260
+ const runtimeGateSection = getMarkdownSection(markdownText, "MCP Runtime Gate");
261
+ if (runtimeGateSection) {
262
+ const runtimeGateMatch = String(runtimeGateSection).match(
263
+ /(?:^|\n)\s*-\s*(?:Final runtime gate status|Status|状态)\s*:\s*`?(PASS|WARN|BLOCK)`?\b/i
264
+ );
265
+ if (runtimeGateMatch) {
266
+ statuses[normalizeCheckpointLabel("mcp runtime gate")] = String(runtimeGateMatch[1]).toUpperCase();
257
267
  }
258
- statuses[label] = String(match[2]).toUpperCase();
259
268
  }
260
269
 
261
270
  return statuses;
package/lib/audit.js CHANGED
@@ -8,7 +8,8 @@ const {
8
8
  assertPenDocumentShape
9
9
  } = require("./pen-persistence");
10
10
  const { getSessionStatePath, readSessionState } = require("./pencil-session");
11
- const { isPathInside, listFilesRecursiveSafe } = require("./fs-safety");
11
+ const { listFilesRecursiveSafe } = require("./fs-safety");
12
+ const { collectRegisteredPenPaths } = require("./design-source-registry");
12
13
  const { pathExists, readTextIfExists } = require("./utils");
13
14
  const { runModuleExportInWorker } = require("./async-offload");
14
15
  const { readExecutionSignals, summarizeSignalsBySurface } = require("./execution-signals");
@@ -69,30 +70,6 @@ function relativeTo(projectRoot, targetPath) {
69
70
  return path.relative(projectRoot, targetPath) || ".";
70
71
  }
71
72
 
72
- function collectRegisteredPenPaths(projectRoot, designRegistryPath) {
73
- const registryText = readTextIfExists(designRegistryPath);
74
- const matches = registryText.match(/\.da-vinci\/designs\/[^\s`]+\.pen/g) || [];
75
- const validPaths = [];
76
- const escapedPaths = [];
77
-
78
- for (const relativePath of [...new Set(matches)]) {
79
- const resolvedPath = path.resolve(projectRoot, relativePath);
80
- if (!isPathInside(projectRoot, resolvedPath)) {
81
- escapedPaths.push({
82
- relativePath,
83
- resolvedPath
84
- });
85
- continue;
86
- }
87
- validPaths.push(resolvedPath);
88
- }
89
-
90
- return {
91
- validPaths,
92
- escapedPaths
93
- };
94
- }
95
-
96
73
  function getNonEmptyChangeDirs(changesDir) {
97
74
  return listChildDirs(changesDir).filter((changeDir) => {
98
75
  const scan = listFilesRecursive(changeDir, CHANGE_SCAN_LIMITS);
@@ -368,7 +345,7 @@ function auditProject(projectPathInput, options = {}) {
368
345
  const {
369
346
  validPaths: registeredPenPaths,
370
347
  escapedPaths: escapedRegisteredPenPaths
371
- } = collectRegisteredPenPaths(projectRoot, designRegistryPath);
348
+ } = collectRegisteredPenPaths(projectRoot, readTextIfExists(designRegistryPath));
372
349
  for (const escapedPath of escapedRegisteredPenPaths) {
373
350
  const message =
374
351
  `Registered design source escapes project root and will be ignored: ${escapedPath.relativePath} ` +
package/lib/cli.js CHANGED
@@ -32,6 +32,11 @@ const {
32
32
  endPencilSession,
33
33
  getPencilSessionStatus
34
34
  } = require("./pencil-session");
35
+ const {
36
+ SAVE_STATUS,
37
+ saveCurrentDesign,
38
+ formatSaveCurrentDesignReport
39
+ } = require("./save-current-design");
35
40
  const {
36
41
  searchIconLibrary,
37
42
  formatIconSearchReport
@@ -83,6 +88,7 @@ const OPTION_FLAGS_WITH_VALUES = new Set([
83
88
  "--home",
84
89
  "--platform",
85
90
  "--lang",
91
+ "--tui-width",
86
92
  "--project",
87
93
  "--mode",
88
94
  "--change",
@@ -113,6 +119,7 @@ const OPTION_FLAGS_WITH_VALUES = new Set([
113
119
  "--from",
114
120
  "--to",
115
121
  "--pen",
122
+ "--pencil-bin",
116
123
  "--nodes-file",
117
124
  "--variables-file",
118
125
  "--version",
@@ -123,6 +130,7 @@ const OPTION_FLAGS_WITH_VALUES = new Set([
123
130
  const HELP_OPTION_SPECS = [
124
131
  { flag: "--platform <value>", description: "codex, claude, gemini, or all" },
125
132
  { flag: "--lang <value>", description: "ui language for `da-vinci tui`: en or zh" },
133
+ { flag: "--tui-width <cols>", description: "fixed layout width (columns) for `da-vinci tui`" },
126
134
  { flag: "--home <path>", description: "override HOME for installation targets" },
127
135
  { flag: "--project <path>", description: "override project path for audit" },
128
136
  {
@@ -188,12 +196,15 @@ const HELP_OPTION_SPECS = [
188
196
  flag: "--strict",
189
197
  description: "enable strict failure mode for commands that support advisory defaults (for example icon-sync, lint-spec)"
190
198
  },
199
+ { flag: "--alt-screen", description: "enable alternate terminal screen buffer for `da-vinci tui`" },
200
+ { flag: "--no-alt-screen", description: "disable alternate terminal screen buffer for `da-vinci tui`" },
191
201
  {
192
202
  flag: "--continue-on-error",
193
203
  description: "print BLOCK/FAIL command results without throwing process errors"
194
204
  },
195
205
  { flag: "--json", description: "print structured JSON output when supported by the command" },
196
206
  { flag: "--pen <path>", description: "registered .pen path for sync checks" },
207
+ { flag: "--pencil-bin <path>", description: "override Pencil executable for interactive capture/verify flows" },
197
208
  {
198
209
  flag: "--from <path>",
199
210
  description: "source path for sync-pen-source, or baseline sidecars directory for diff-spec"
@@ -475,7 +486,7 @@ function printHelp() {
475
486
  " da-vinci install --platform codex,claude,gemini",
476
487
  " da-vinci uninstall --platform codex,claude,gemini",
477
488
  " da-vinci status",
478
- " da-vinci tui [--project <path>] [--change <id>] [--lang en|zh] [--strict] [--json] [--continue-on-error]",
489
+ " da-vinci tui [--project <path>] [--change <id>] [--lang en|zh] [--strict] [--json] [--continue-on-error] [--tui-width <cols>] [--alt-screen|--no-alt-screen]",
479
490
  " da-vinci workflow-status [--project <path>] [--change <id>] [--json]",
480
491
  " da-vinci next-step [--project <path>] [--change <id>] [--json]",
481
492
  " da-vinci lint-spec [--project <path>] [--change <id>] [--strict] [--json]",
@@ -502,6 +513,7 @@ function printHelp() {
502
513
  " da-vinci check-pen-baseline --pen <path> --baseline <path>[,<path>...] [--baseline <path>] [--prefer-source <path>]",
503
514
  " da-vinci sync-pen-source --from <path> --to <path>",
504
515
  " da-vinci snapshot-pen --input <path> --output <path>",
516
+ " da-vinci save-current-design --project <path> [--json] [--continue-on-error]",
505
517
  " da-vinci pencil-lock acquire --project <path>",
506
518
  " da-vinci pencil-lock release --project <path>",
507
519
  " da-vinci pencil-lock status",
@@ -945,6 +957,12 @@ async function runCli(argv) {
945
957
  const projectPath = getOption(argv, "--project") || positionalArgs[0] || process.cwd();
946
958
  const changeId = getOption(argv, "--change");
947
959
  const lang = getOption(argv, "--lang");
960
+ const tuiWidth = getOption(argv, "--tui-width");
961
+ const altScreen = argv.includes("--alt-screen")
962
+ ? true
963
+ : argv.includes("--no-alt-screen")
964
+ ? false
965
+ : undefined;
948
966
  if (argv.includes("--help") || argv.includes("-h")) {
949
967
  console.log(formatTuiHelp(lang));
950
968
  return;
@@ -953,6 +971,8 @@ async function runCli(argv) {
953
971
  projectPath,
954
972
  changeId,
955
973
  lang,
974
+ tuiWidth,
975
+ altScreen,
956
976
  strict: argv.includes("--strict"),
957
977
  jsonOutput: argv.includes("--json"),
958
978
  continueOnError
@@ -1425,6 +1445,35 @@ async function runCli(argv) {
1425
1445
  return;
1426
1446
  }
1427
1447
 
1448
+ if (command === "save-current-design") {
1449
+ const projectPath = getOption(argv, "--project") || positionalArgs[0] || process.cwd();
1450
+ const pencilBin = getOption(argv, "--pencil-bin");
1451
+ const result = await saveCurrentDesign({
1452
+ projectPath,
1453
+ homeDir,
1454
+ pencilBin,
1455
+ allowLocalBridge: true
1456
+ });
1457
+ const useJson = argv.includes("--json");
1458
+ const output = useJson
1459
+ ? JSON.stringify(result, null, 2)
1460
+ : formatSaveCurrentDesignReport(result);
1461
+
1462
+ if (
1463
+ emitOrThrowOnStatus(
1464
+ result.status,
1465
+ [SAVE_STATUS.BLOCKED, SAVE_STATUS.UNAVAILABLE],
1466
+ output,
1467
+ continueOnError
1468
+ )
1469
+ ) {
1470
+ return;
1471
+ }
1472
+
1473
+ console.log(output);
1474
+ return;
1475
+ }
1476
+
1428
1477
  if (command === "pencil-lock") {
1429
1478
  handlePencilLockCommand(argv, homeDir);
1430
1479
  return;
@@ -0,0 +1,146 @@
1
+ const path = require("path");
2
+ const { isPathInside } = require("./fs-safety");
3
+
4
+ const REGISTERED_PEN_PATTERN = /\.da-vinci\/designs\/[^\s`]+\.pen/g;
5
+
6
+ function normalizeProjectRoot(projectRoot) {
7
+ return path.resolve(projectRoot || process.cwd());
8
+ }
9
+
10
+ function collectRegisteredPenReferences(registryText) {
11
+ const matches = String(registryText || "").match(REGISTERED_PEN_PATTERN) || [];
12
+ const seen = new Set();
13
+ const unique = [];
14
+
15
+ for (const match of matches) {
16
+ const normalized = String(match || "").trim();
17
+ if (!normalized || seen.has(normalized)) {
18
+ continue;
19
+ }
20
+ seen.add(normalized);
21
+ unique.push(normalized);
22
+ }
23
+
24
+ return unique;
25
+ }
26
+
27
+ function normalizeBoundPenPath(projectRoot, penPath, options = {}) {
28
+ const root = normalizeProjectRoot(projectRoot);
29
+ const raw = typeof penPath === "string" ? penPath.trim() : "";
30
+
31
+ if (!raw) {
32
+ return {
33
+ ok: false,
34
+ code: options.missingCode || "missing_path",
35
+ input: raw,
36
+ resolvedPath: ""
37
+ };
38
+ }
39
+
40
+ if (options.rejectNew && raw.toLowerCase() === "new") {
41
+ return {
42
+ ok: false,
43
+ code: options.newCode || "active_editor_new",
44
+ input: raw,
45
+ resolvedPath: ""
46
+ };
47
+ }
48
+
49
+ const resolvedPath = path.normalize(path.isAbsolute(raw) ? raw : path.resolve(root, raw));
50
+ if (!isPathInside(root, resolvedPath)) {
51
+ return {
52
+ ok: false,
53
+ code: options.outsideCode || "outside_project_root",
54
+ input: raw,
55
+ resolvedPath
56
+ };
57
+ }
58
+
59
+ if (options.requirePenExtension !== false && !/\.pen$/i.test(resolvedPath)) {
60
+ return {
61
+ ok: false,
62
+ code: options.extensionCode || "not_pen_path",
63
+ input: raw,
64
+ resolvedPath
65
+ };
66
+ }
67
+
68
+ return {
69
+ ok: true,
70
+ code: "ok",
71
+ input: raw,
72
+ resolvedPath
73
+ };
74
+ }
75
+
76
+ function normalizeRegisteredPenPath(projectRoot, penPath) {
77
+ return normalizeBoundPenPath(projectRoot, penPath, {
78
+ missingCode: "registered_pen_missing",
79
+ outsideCode: "registered_pen_outside_project_root",
80
+ extensionCode: "registered_pen_not_pen_path"
81
+ });
82
+ }
83
+
84
+ function normalizeSessionPenPath(projectRoot, penPath) {
85
+ return normalizeBoundPenPath(projectRoot, penPath, {
86
+ missingCode: "session_pen_missing",
87
+ outsideCode: "session_pen_outside_project_root",
88
+ extensionCode: "session_pen_not_pen_path"
89
+ });
90
+ }
91
+
92
+ function normalizeActiveEditorPath(projectRoot, activeEditorPath) {
93
+ return normalizeBoundPenPath(projectRoot, activeEditorPath, {
94
+ rejectNew: true,
95
+ missingCode: "active_editor_missing",
96
+ newCode: "active_editor_new",
97
+ outsideCode: "active_editor_outside_project_root",
98
+ extensionCode: "active_editor_not_pen_path"
99
+ });
100
+ }
101
+
102
+ function collectRegisteredPenPaths(projectRoot, registryText) {
103
+ const root = normalizeProjectRoot(projectRoot);
104
+ const references = collectRegisteredPenReferences(registryText);
105
+ const validPaths = [];
106
+ const escapedPaths = [];
107
+ const seenResolved = new Set();
108
+
109
+ for (const relativePath of references) {
110
+ const normalized = normalizeRegisteredPenPath(root, relativePath);
111
+ if (normalized.ok) {
112
+ if (!seenResolved.has(normalized.resolvedPath)) {
113
+ seenResolved.add(normalized.resolvedPath);
114
+ validPaths.push(normalized.resolvedPath);
115
+ }
116
+ continue;
117
+ }
118
+
119
+ if (normalized.code === "registered_pen_outside_project_root") {
120
+ escapedPaths.push({
121
+ relativePath,
122
+ resolvedPath: normalized.resolvedPath
123
+ });
124
+ }
125
+ }
126
+
127
+ return {
128
+ validPaths,
129
+ escapedPaths
130
+ };
131
+ }
132
+
133
+ function resolvePreferredRegisteredPenPath(projectRoot, registryText) {
134
+ const resolved = collectRegisteredPenPaths(projectRoot, registryText);
135
+ return resolved.validPaths[0] || "";
136
+ }
137
+
138
+ module.exports = {
139
+ collectRegisteredPenReferences,
140
+ normalizeBoundPenPath,
141
+ normalizeRegisteredPenPath,
142
+ normalizeSessionPenPath,
143
+ normalizeActiveEditorPath,
144
+ collectRegisteredPenPaths,
145
+ resolvePreferredRegisteredPenPath
146
+ };