ld-vibe-harness 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.codex-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +33 -0
  4. package/README.en.md +8 -8
  5. package/README.md +12 -11
  6. package/adapters/antigravity/installer.js +43 -4
  7. package/adapters/dsh/index.js +84 -1
  8. package/adapters/dsh/package.json +1 -1
  9. package/agents/ldvh-friction-recorder.md +27 -0
  10. package/hooks/_client.mjs +20 -0
  11. package/hooks/hook-engine.js +496 -22
  12. package/hooks.json +1 -1
  13. package/lib/capture-notice.js +43 -0
  14. package/lib/carrier-ref.js +11 -0
  15. package/lib/commit-validation.js +2 -2
  16. package/lib/friction-tools.js +38 -7
  17. package/lib/goal-anchor.js +100 -0
  18. package/lib/goal-tools.js +28 -5
  19. package/lib/guidance-text.js +4 -4
  20. package/lib/host-seams.js +48 -24
  21. package/lib/intent-tools.js +38 -7
  22. package/lib/ldvh-tools.js +77 -249
  23. package/lib/milestone-tools.js +40 -8
  24. package/lib/norm-tools.js +44 -9
  25. package/lib/operation-declarations.bundle.json +313 -0
  26. package/lib/pitfall-tools.js +38 -7
  27. package/lib/progressive-read.js +250 -0
  28. package/lib/read-body-render.js +27 -3
  29. package/lib/recall-criteria.bundle.json +209 -0
  30. package/lib/recall-criteria.js +246 -0
  31. package/lib/recall-injection.js +161 -68
  32. package/lib/recall-synonyms.js +99 -0
  33. package/lib/report-tools.js +44 -13
  34. package/lib/review-ask-tool.js +191 -63
  35. package/lib/review-ask.js +70 -23
  36. package/lib/review-dispatch-template.js +75 -40
  37. package/lib/runtime-carrier-reader.js +811 -0
  38. package/lib/runtime-carrier-validator.js +948 -0
  39. package/lib/source-recall.js +445 -147
  40. package/lib/spec-registry.js +121 -5
  41. package/package.json +10 -4
  42. package/plugin-specs/controlled-commit.yaml +233 -0
  43. package/plugin-specs/experience-accumulation-system-foundation.yaml +308 -0
  44. package/plugin-specs/fact-model-common.yaml +313 -0
  45. package/plugin-specs/friction-fact-type.yaml +333 -0
  46. package/plugin-specs/friction-settlement-system-foundation.yaml +334 -0
  47. package/plugin-specs/gate-consult-system-foundation.yaml +337 -0
  48. package/plugin-specs/goal-fact-type.yaml +205 -0
  49. package/plugin-specs/goal-planning-system-foundation.yaml +296 -0
  50. package/plugin-specs/intent-fact-type.yaml +243 -0
  51. package/plugin-specs/intent-record-system-foundation.yaml +281 -0
  52. package/plugin-specs/ldvh-root.yaml +251 -0
  53. package/plugin-specs/milestone-fact-type.yaml +212 -0
  54. package/plugin-specs/norm-fact-type.yaml +172 -0
  55. package/plugin-specs/pitfall-fact-type.yaml +292 -0
  56. package/plugin-specs/report-fact-type.yaml +152 -0
  57. package/plugin-specs/research-system-foundation.yaml +306 -0
  58. package/plugin-specs/rule-compliance-recall.yaml +250 -0
  59. package/plugin-specs/rule-compliance-verification.yaml +207 -0
  60. package/plugin-specs/service-contract.yaml +218 -0
  61. package/plugin.json +1 -1
  62. package/rules/AGENTS.md +4 -4
  63. package/server/local-daemon.js +43 -2
  64. package/server/mcp-app-html.js +44 -1
  65. package/server/mcp-server.js +21 -0
  66. package/skills/ldvh-governance-flow/SKILL.md +10 -11
  67. package/specs/00-/347/220/206/345/277/265/344/270/216/346/236/204/346/210/220.md +0 -304
  68. package/specs/01-/350/247/204/350/214/203/346/272/220/344/270/216/350/247/204/350/214/203/346/250/241/345/236/213/345/237/272/347/241/200/350/247/204/350/214/203.md +0 -611
  69. package/specs/02-/344/272/213/345/256/236/346/272/220/344/270/216/344/272/213/345/256/236/346/250/241/345/236/213/345/237/272/347/241/200/350/247/204/350/214/203.md +0 -646
  70. package/specs/03-/344/270/232/345/212/241/347/263/273/347/273/237/345/237/272/347/241/200/350/247/204/350/214/203.md +0 -518
  71. package/specs/04-/346/243/200/346/237/245/344/270/216/350/276/205/345/212/251/346/234/272/345/210/266/350/247/204/350/214/203.md +0 -326
  72. package/specs/05-LDVH CLI /347/241/256/345/256/232/346/200/247/346/234/215/345/212/241/350/247/204/350/214/203.md" +0 -289
  73. package/specs/06-Code /345/256/236/350/267/265/344/270/216/346/265/213/350/257/225/350/247/204/350/214/203.md" +0 -364
  74. package/specs/07-Web /345/221/210/347/216/260/344/270/216/344/272/244/344/272/222/350/247/204/350/214/203.md" +0 -280
  75. package/specs/08-/347/256/241/350/276/226/350/214/203/345/233/264/350/247/204/350/214/203.md +0 -262
  76. package/specs/09-/345/217/227/346/216/247/346/217/220/344/272/244/344/270/216/346/234/272/346/242/260/345/256/210/346/212/244/350/247/204/350/214/203.md +0 -291
  77. package/specs/10-DSH /347/216/257/345/242/203/346/216/245/345/205/245/344/270/216/346/217/222/344/273/266/345/217/221/345/270/203/350/247/204/350/214/203.md" +0 -317
  78. package/specs/20-Goal-/351/241/271/347/233/256/347/233/256/346/240/207.md +0 -271
  79. package/specs/21-Milestone-/351/207/214/347/250/213/347/242/221.md +0 -413
  80. package/specs/22-Intent-/346/204/217/345/233/276.md +0 -459
  81. package/specs/23-Norm-/344/272/213/345/256/236/350/247/204/350/214/203.md +0 -397
  82. package/specs/24-Report-/346/212/245/345/221/212.md +0 -562
  83. package/specs/25-Pitfall-/350/270/251/345/235/221/347/273/217/351/252/214.md +0 -358
  84. package/specs/26-Friction-/346/221/251/346/223/246/350/264/246/346/234/254.md +0 -409
  85. package/specs/30-/347/233/256/346/240/207/350/247/204/345/210/222/347/263/273/347/273/237/350/247/204/350/214/203.md +0 -408
  86. package/specs/31-/346/204/217/345/233/276/350/256/260/345/275/225/347/263/273/347/273/237/350/247/204/350/214/203.md +0 -463
  87. package/specs/32-/346/212/212/345/205/263/350/257/267/347/244/272/347/263/273/347/273/237/350/247/204/350/214/203.md +0 -420
  88. package/specs/33-/350/260/203/347/240/224/345/220/270/346/224/266/347/263/273/347/273/237/350/247/204/350/214/203.md +0 -653
  89. package/specs/34-/345/217/214/346/272/220/345/217/254/345/233/236/347/263/273/347/273/237/350/247/204/350/214/203.md +0 -492
  90. package/specs/35-/347/273/217/351/252/214/347/247/257/347/264/257/347/263/273/347/273/237/350/247/204/350/214/203.md +0 -471
  91. package/specs/36-/346/221/251/346/223/246/351/224/200/350/264/246/347/263/273/347/273/237/350/247/204/350/214/203.md +0 -488
  92. package/specs/attachments/01.Att.01-LDVH/345/217/214/350/257/255/346/234/257/350/257/255/350/241/250.md +0 -128
  93. package/specs/attachments/01.Att.02-/350/247/204/350/214/203/350/272/253/344/273/275/345/255/227/346/256/265/350/241/250.md +0 -107
  94. package/specs/attachments/01.Att.03-/350/247/204/350/214/203/345/205/263/347/263/273/344/270/216/345/261/202/347/272/247/350/241/250.md +0 -63
  95. package/specs/attachments/02.Att.01-/344/272/213/345/256/236/345/217/254/345/233/236/345/210/206/345/261/202/350/241/250.md +0 -22
  96. package/specs/attachments/08.Att.01-/347/256/241/350/276/226/347/231/273/350/256/260/350/275/275/344/275/223Schema/350/241/250.md +0 -29
  97. package/specs/attachments/23.Att.01-Norm/346/226/271/345/220/221/346/270/205/345/215/225.md +0 -102
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldvh",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "把项目目标、里程碑、意图、规范、报告、踩坑经验与摩擦账本落盘为随 Git 演进的结构化事实(ldvh-base/);每轮动手前按预算只注入轻量候选索引(不灌全文、按需精读),高风险写入强制 Human 确认,支持零上下文子代理审方案、核结果与联网取证,提交由 Git Gate 校验并附会话签名,配本地/远程 Web 看板。",
5
5
  "author": {
6
6
  "name": "LaoDing",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.0",
2
+ "version": "0.2.0",
3
3
  "name": "ldvh",
4
4
  "description": "把项目目标、里程碑、意图、规范、报告、踩坑经验与摩擦账本落盘为随 Git 演进的结构化事实(ldvh-base/);每轮动手前按预算只注入轻量候选索引(不灌全文、按需精读),高风险写入强制 Human 确认,支持零上下文子代理审方案、核结果与联网取证,提交由 Git Gate 校验并附会话签名,配本地/远程 Web 看板。",
5
5
  "author": {
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # 变更日志
2
2
 
3
+ ## [0.2.0] - 2026-11-30
4
+
5
+ 面向外部开箱可用性的关键修复与核心能力升级:运行时规范打包解耦、Hook 注入与远程 MCP App 修复、双源召回优先级与零向量同义词/路径增量补强、7 类事实对象渐进式精读以及经验/摩擦独立子代理全权落盘。
6
+
7
+ ### 新增
8
+
9
+ - **随包精简运行时规范载体**:将运行期规范收口为 19 份 `plugin-specs/*.yaml` 与构建期生成的 `lib/*.bundle.json`(`specs/` 仅留存仓库作开发设计参考,不再打入 npm 包)。
10
+ - **确定性零向量同义词补漏**:新增 `lib/recall-synonyms.js`(21 组封闭工程与 LDVH 领域词组,兼容中文 bigram 粒度、排除泛词),接入事实源与载体召回,在原生弱命中/未命中时低权补漏并标注 `原词→扩展词`。
11
+ - **工具后路径上下文增量提醒**:`PostToolUse` 在受管辖仓库通过独立 `turn-paths/<hash>.json` 记录刚触及的源码相对路径(Windows realpath 归一化、排除 `ldvh-base/`),同回合后续 `PreInvocation` 按路径定向提醒 `active Norm` 与 `active Pitfall`(回合级去重、纯读取回合排除、`Stop` 自动清理)。
12
+ - **全系 7 类事实对象渐进式精读**:新增 `lib/progressive-read.js` 并重构 `lib/read-body-render.js`,统一接入 `ldvh_{goal,milestone,intent,norm,pitfall,friction,report}_read`,支持磁盘 1-based `headings` 目录、`include_body: false` 仅读大纲与 `sections` 按 H2 节选(显式披露 `missing_sections`、`outcome: "partial"` 与 CAS 写前全量回读警示)。
13
+ - **运行时载体条款级行号定位**:`lib/runtime-carrier-reader.js` 使用 `yaml` `LineCounter` 剥离尾空行精确提取 `requirements` 起止行号,`lib/recall-injection.js` 在预算允许时附带缩进式条款行号子行并透出实际送达的 `renderedFactUids`。
14
+ - **经验与摩擦独立子代理落盘**:新增 `agents/ldvh-friction-recorder.md` 与 `lib/capture-notice.js`;确立主控只发现可回指材料并后台派发子代理(经验由 `ldvh-experience-recorder` 授权直写,摩擦由 `ldvh-friction-recorder` 写观察缓冲并在同源满 3 次时由工具以子代理会话签名自动晋升),同时升级 `Stop` Hook 收口防死循环护栏。
15
+ - **双源召回高优锚点与基准评测**:新增 `lib/goal-anchor.js` 常驻目标与活跃里程碑锚点及 `scripts/eval-recall.mjs` 7 场景召回基准评测脚本。
16
+
17
+ ### 变更
18
+
19
+ - **双源召回优先级重构**:确立高优先权重(目标/里程碑/事实规范居首、踩坑经验次之,`FACT_TYPE_PRIORITY`),支持标识符子词拆解(`expandIdentifierSubtokens`)、显式路径上下文提权、运行时载体泛词停用治理及跨进程 `hook-turn-state.json` 同回合去重。
20
+ - **34 个模型可见 MCP 工具**:下线旧规范全文读取工具 `ldvh_read_specification_candidates` 与 `ldvh_read_specification_content`(运行时改走轻量载体定位 + 按行号按需读取)。
21
+ - **术语与把关点位统一**:清理 `plugin-specs/*.yaml` 中残留中文旧术语(`火花` → `意图`、`子目标` → `里程碑`);`ldvh_review_ask` 对齐 `pre-action`(`candidate_summary`)、`post-work`(`conclusion_summary`)摘要校验与 `point="research"` 统一请示点位;Git Gate 强拦范围扩展覆盖 `plugin-specs/`。
22
+
23
+ ### 修复
24
+
25
+ - **独立发布依赖与 Windows CRLF 兼容**:补齐 `web/api-js` 运行时依赖(`compression`、`cors`、`dotenv`、`express`、`js-yaml`)至根 `package.json`;修复 `lib/spec-registry.js` 在 Windows CRLF 换行下的解析失败。
26
+ - **Antigravity Hook 注入静默丢失与陈旧 daemon 淘汰**:移除 `PreInvocation` / `SessionStart` 中触发宿主静默丢弃的 `metadata.user_markdown`;在 `server/local-daemon.js` 与 `hooks/_client.mjs` 增加 `codeFingerprint` 与 `POST /admin/shutdown` 自动优雅淘汰陈旧常驻服务。
27
+ - **远程 MCP App 2 MiB 超限 500 故障**:`ObjectDetail.tsx` 改用 `PrismLight`(18 种语言)、仅开发环境启用 `react-dev-locator`、`server/mcp-app-html.js` 增设 1.4 MiB 自动 gzip + `DecompressionStream` 自解压兜底,将单文件序列化体积压至约 1.14 MiB(守卫阈值 `< 1.5 MiB`)。
28
+ - **事实源直写拦截与多宿主 Human Gate 闭环**:`hooks/hook-engine.js` 拦截受管辖项目 `write_file` / `edit_file` 直写 `ldvh-base/`(使用 `realpathSync.native` 兼容 Windows 8.3 短路径);非 Hook 宿主(Codex / Claude Code)支持 `human_confirmed: true` 闭环(Antigravity 下仍强制 `force_ask` 不可绕过);拦截子代理直调 `ldvh_friction_write`。
29
+ - **DSH 适配器补全与泛目录线索过滤**:`adapters/dsh/index.js` 补全 `/ldvh/api/plugin-settings` GET/POST 接口与 `systemPrompt` 注册;修复 `git status --porcelain` 对未跟踪目录产出纯目录线索导致路径召回误命中的缺陷。
30
+
31
+ ### 移除
32
+
33
+ - 模型可见工具 `ldvh_read_specification_candidates`、`ldvh_read_specification_content`。
34
+ - npm 发布包中的 `specs/` 目录(仍保留于仓库用于开发参考)。
35
+
3
36
  ## [0.1.0] - 2026-11-30
4
37
 
5
38
  多宿主「单核多壳」架构重构后的首个正式发布版本(旧版代码归档在分支 `backup/main-legacy`)。
package/README.en.md CHANGED
@@ -35,12 +35,12 @@ LDVH puts a harness on the AI. Goals, ideas, norms, lessons and frictions become
35
35
 
36
36
  ## Supported hosts
37
37
 
38
- | Host | Integration | MCP tools | Hook injection | Sub-agent review | Embedded dashboard |
39
- | :--- | :--- | :---: | :---: | :---: | :---: |
40
- | Antigravity | `plugin.json` + `mcp_config.json` + `hooks.json` | ✅ | ✅ (direct & `call_mcp_tool`) | ✅ | ✅ (local + remote self-contained MCP App) |
41
- | Codex | `.codex-plugin/plugin.json` + `.mcp.json` | ✅ | — | — | browser |
42
- | DSH | `adapters/dsh` (Cordis plugin) | ✅ | — | ✅ | ✅ |
43
- | Claude Code | `.claude-plugin/plugin.json` (reserved) | ✅ | — | — | browser |
38
+ | Host | Integration | MCP tools | Hook injection | Human Gate | Sub-agent review | Embedded dashboard |
39
+ | :--- | :--- | :---: | :---: | :---: | :---: | :---: |
40
+ | Antigravity | `plugin.json` + `mcp_config.json` + `hooks.json` | ✅ | ✅ (direct & `call_mcp_tool`) | Hook `force_ask` | ✅ | ✅ (local + remote self-contained MCP App) |
41
+ | Codex | `.codex-plugin/plugin.json` + `.mcp.json` | ✅ | — | `human_confirmed` / Web / CLI | — | browser |
42
+ | DSH | `adapters/dsh` (Cordis plugin) | ✅ | — | Embedded UI | ✅ | ✅ |
43
+ | Claude Code | `.claude-plugin/plugin.json` (reserved) | ✅ | — | `human_confirmed` / Web / CLI | — | browser |
44
44
 
45
45
  "—" means the host has no equivalent interface yet; that capability falls back to the model following the guidance in `skills/`. The fact store, tools and Git Gate are unaffected.
46
46
 
@@ -84,8 +84,8 @@ Without `--apply`, `host setup` is a dry run.
84
84
 
85
85
  ## Controlled commits & unified signing
86
86
 
87
- - Exposes **36 model-visible MCP tools** (including read-only `ldvh_session_signature`) plus app-only `ldvh_app_api_proxy`.
88
- - In governed repos, AI-initiated commits query `ldvh_session_signature` and attach `LDVH-Provider` / `LDVH-Model` trailers, while Git Gate only enforces strict checks when `ldvh-base/` or `specs/` are staged (leaving manual human commits and `git merge` unhindered).
87
+ - Exposes **34 model-visible MCP tools** (including read-only `ldvh_session_signature`) plus app-only `ldvh_app_api_proxy`. Runtime recall uses bundled `plugin-specs/*.yaml` (`specs/` stays in the git repo only and is excluded from the npm tarball).
88
+ - In governed repos, AI-initiated commits query `ldvh_session_signature` and attach `LDVH-Provider` / `LDVH-Model` trailers, while Git Gate only enforces strict checks when `ldvh-base/`, `specs/`, or `plugin-specs/` are staged (leaving manual human commits and `git merge` unhindered).
89
89
  - **Terminology**: v2 standardized `Intent` (replacing `Spark`) and `Milestone` (replacing `SubGoal`); see the Help page's Verify & FAQ chapter for legacy repo migration steps.
90
90
 
91
91
  See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) (Chinese) and [CHANGELOG.md](CHANGELOG.md). Legacy code lives on the `backup/main-legacy` branch.
package/README.md CHANGED
@@ -35,16 +35,16 @@ LDVH 给 AI 套一副工程缰绳:把目标、想法、规范、经验、摩
35
35
 
36
36
  ## 支持的宿主
37
37
 
38
- | 宿主 | 接入方式 | MCP 工具 | Hook 自动注入 | 子代理把关 | 内嵌看板 |
39
- | :--- | :--- | :---: | :---: | :---: | :---: |
40
- | Antigravity | `plugin.json` + `mcp_config.json` + `hooks.json` | ✅ | ✅(兼容直连与 `call_mcp_tool`) | ✅ | ✅(本地 + 远程自包含 MCP App) |
41
- | Codex | `.codex-plugin/plugin.json` + `.mcp.json` | ✅ | — | — | 浏览器 |
42
- | DSH | `adapters/dsh`(Cordis 插件) | ✅ | — | ✅ | ✅ |
43
- | Claude Code | `.claude-plugin/plugin.json`(预留) | ✅ | — | — | 浏览器 |
38
+ | 宿主 | 接入方式 | MCP 工具 | Hook 自动注入 | 人工门禁 | 子代理把关 | 内嵌看板 |
39
+ | :--- | :--- | :---: | :---: | :---: | :---: | :---: |
40
+ | Antigravity | `plugin.json` + `mcp_config.json` + `hooks.json` | ✅ | ✅(兼容直连与 `call_mcp_tool`) | Hook `force_ask` | ✅ | ✅(本地 + 远程自包含 MCP App) |
41
+ | Codex | `.codex-plugin/plugin.json` + `.mcp.json` | ✅ | — | `human_confirmed` / Web / CLI | — | 浏览器 |
42
+ | DSH | `adapters/dsh`(Cordis 插件) | ✅ | — | 内嵌交互 | ✅ | ✅ |
43
+ | Claude Code | `.claude-plugin/plugin.json`(预留) | ✅ | — | `human_confirmed` / Web / CLI | — | 浏览器 |
44
44
 
45
45
  “—”表示该宿主暂无等价接口,对应能力退化为按 `skills/` 指引由主控自觉执行;事实源、工具与 Git Gate 不受影响。
46
46
 
47
- 三个宿主默认**共享同一个数据目录 `~/.ldvh`**:在 Antigravity 里记下的目标与经验,换到 Codex 或 DSH 照样能召回。需要隔离时设置环境变量 `LDVH_DATA_DIR`。
47
+ 四个宿主默认**共享同一个数据目录 `~/.ldvh`**:在 Antigravity 里记下的目标与经验,换到 Codex 或 DSH 照样能召回。需要隔离时设置环境变量 `LDVH_DATA_DIR`。
48
48
 
49
49
  ## 七个业务系统
50
50
 
@@ -111,8 +111,8 @@ node cli/ldvh.mjs governed-project install --project /abs/path/to/repo --id my-r
111
111
 
112
112
  ## 受控提交与统一署名
113
113
 
114
- - 仓库提供 **36 个模型可见 MCP 工具**(含只读路由自查工具 `ldvh_session_signature`)及 app-only 隧道工具 `ldvh_app_api_proxy`。
115
- - 在受管辖仓库中,AI 发起任何 `git commit` 均统一先查询 `ldvh_session_signature`,使用中文标题、`关键变更:` 以及 `LDVH-Provider` / `LDVH-Model` trailer 署名;Git Gate 仅在暂存区触及 `ldvh-base/` 或 `specs/` 时强拦,不阻碍人类手工提交与 `git merge`。
114
+ - 仓库提供 **34 个模型可见 MCP 工具**(含只读路由自查工具 `ldvh_session_signature`)及 app-only 隧道工具 `ldvh_app_api_proxy`。
115
+ - 在受管辖仓库中,AI 发起任何 `git commit` 均统一先查询 `ldvh_session_signature`,使用中文标题、`关键变更:` 以及 `LDVH-Provider` / `LDVH-Model` trailer 署名;Git Gate 仅在暂存区触及 `ldvh-base/`、`specs/` 或 `plugin-specs/` 时强拦,不阻碍人类手工提交与 `git merge`。
116
116
  - **术语提示**:v2 已将 `Spark → Intent`(`ldvh-base/intents/`)、`SubGoal → Milestone`(`ldvh-base/milestones/`)彻底统一;旧仓迁移指引见看板帮助页「自检与排错」。
117
117
 
118
118
  ## 目录结构
@@ -122,10 +122,11 @@ plugin.json mcp_config.json hooks.json Antigravity 清单
122
122
  .codex-plugin/plugin.json .mcp.json Codex 清单(.mcp.json 同时供 Claude Code 使用)
123
123
  .claude-plugin/plugin.json Claude Code 清单
124
124
  lib/ server/ hooks/ cli/ 宿主无关核心:事实源、MCP 服务、Hook 引擎、命令行
125
- adapters/ 三宿主薄适配层与安装器
125
+ adapters/ 多宿主薄适配层与安装器
126
126
  skills/ agents/ rules/ 操作指引、子代理与治理锚点
127
+ plugin-specs/ 随包内置的运行时结构化规范(19 份 YAML)
127
128
  web/ React 看板与 Express 接口
128
- specs/ 规范原文
129
+ specs/ 开发期完整中文规范原文(不随 npm 包分发)
129
130
  ```
130
131
 
131
132
  更多设计见 [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md),版本变化见 [CHANGELOG.md](CHANGELOG.md)。
@@ -1,6 +1,7 @@
1
- import { rm } from "node:fs/promises";
1
+ import { readFile, rm } from "node:fs/promises";
2
2
  import { homedir } from "node:os";
3
3
  import { join, resolve } from "node:path";
4
+ import { createDataPathResolver } from "../../lib/data-paths.js";
4
5
  import { copyFileTo, linkDependencyDir, mirrorDir, pathKind, readJsonIfExists } from "../_fs.js";
5
6
 
6
7
  export const host = "antigravity";
@@ -16,7 +17,7 @@ export const capabilities = Object.freeze({
16
17
  });
17
18
 
18
19
  const FILES = Object.freeze(["plugin.json", "mcp_config.json", "hooks.json", "package.json", "LICENSE"]);
19
- const MIRRORED_DIRS = Object.freeze(["lib", "server", "hooks", "cli", "adapters", "specs", "rules", "skills", "agents", "assets"]);
20
+ const MIRRORED_DIRS = Object.freeze(["lib", "server", "hooks", "cli", "adapters", "plugin-specs", "rules", "skills", "agents", "assets"]);
20
21
  const WEB_MIRRORED = Object.freeze(["api", "api-js", "shared", "shared-js", "src", "public", "scripts", "dist"]);
21
22
  const WEB_FILES = Object.freeze([
22
23
  "package.json", "pnpm-lock.yaml", "pnpm-workspace.yaml", "tsconfig.json", "tsconfig.app.json",
@@ -63,7 +64,44 @@ function plan() {
63
64
  };
64
65
  }
65
66
 
66
- export async function install({ repoRoot, targetDir = defaultTargetDir(), apply = false } = {}) {
67
+ async function shutdownStaleDaemon(dataDir) {
68
+ const dataPath = createDataPathResolver(dataDir);
69
+ const runtimeFile = dataPath("ldvh", "runtime.json");
70
+ let runtime;
71
+ try {
72
+ runtime = JSON.parse(await readFile(runtimeFile, "utf8"));
73
+ } catch {
74
+ return { attempted: false, restarted: false, reason: "no_runtime_file" };
75
+ }
76
+ if (!runtime || typeof runtime.port !== "number" || typeof runtime.token !== "string") {
77
+ return { attempted: false, restarted: false, reason: "invalid_runtime_file" };
78
+ }
79
+ const hostAddr = typeof runtime.host === "string" && runtime.host.length > 0 ? runtime.host : "127.0.0.1";
80
+ const controller = new AbortController();
81
+ const timer = setTimeout(() => controller.abort(), 1500);
82
+ try {
83
+ const res = await fetch(`http://${hostAddr}:${runtime.port}/admin/shutdown`, {
84
+ method: "POST",
85
+ headers: { "x-ldvh-token": runtime.token },
86
+ signal: controller.signal,
87
+ });
88
+ if (res.ok) {
89
+ return { attempted: true, restarted: true, reason: "graceful_shutdown", pid: runtime.pid ?? null };
90
+ }
91
+ return {
92
+ attempted: true,
93
+ restarted: false,
94
+ reason: res.status === 404 ? "legacy_daemon_no_shutdown_endpoint" : `http_${res.status}`,
95
+ pid: runtime.pid ?? null,
96
+ };
97
+ } catch {
98
+ return { attempted: true, restarted: false, reason: "daemon_unreachable", pid: runtime.pid ?? null };
99
+ } finally {
100
+ clearTimeout(timer);
101
+ }
102
+ }
103
+
104
+ export async function install({ repoRoot, targetDir = defaultTargetDir(), apply = false, dataDir, restartDaemon = true } = {}) {
67
105
  const root = resolve(repoRoot);
68
106
  const target = resolve(targetDir);
69
107
  const steps = plan();
@@ -97,8 +135,9 @@ export async function install({ repoRoot, targetDir = defaultTargetDir(), apply
97
135
  nodeModules: await linkDependencyDir(join(root, "node_modules"), join(target, "node_modules")),
98
136
  webNodeModules: await linkDependencyDir(join(root, "web", "node_modules"), join(target, "web", "node_modules")),
99
137
  };
138
+ const daemon = restartDaemon ? await shutdownStaleDaemon(dataDir) : { attempted: false, restarted: false, reason: "skipped" };
100
139
  const after = await inspect({ repoRoot: root, targetDir: target });
101
- return { ok: after.realDirectory && after.upToDate, host, applied: true, targetDir: target, removed, links, state: after };
140
+ return { ok: after.realDirectory && after.upToDate, host, applied: true, targetDir: target, removed, links, daemon, state: after };
102
141
  }
103
142
 
104
143
  export function describeSetup({ repoRoot } = {}) {
@@ -1,12 +1,14 @@
1
1
  import { join } from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { collectLdvhTools } from "../../server/tool-registry.js";
4
- import { createDataPathResolver } from "../../lib/data-paths.js";
4
+ import { createDataPathResolver, readPluginSettings, writePluginSettings } from "../../lib/data-paths.js";
5
5
  import { createGovernanceHandler } from "../../lib/host-api.js";
6
6
  import { createHostSeams } from "../../lib/host-seams.js";
7
7
  import { ensureRegistrationCarrier } from "../../lib/governed-projects.js";
8
8
  import { repairHooksOnStartup } from "../../lib/hook-repair.js";
9
9
  import { createProxyHandler, createSpaHandler, createWebApiProcess } from "../../lib/web-mount.js";
10
+ import { resolveGovernanceScope } from "../../lib/governance-scope.js";
11
+ import { createAssembleHandler } from "../../lib/guidance.js";
10
12
 
11
13
  /**
12
14
  * DSH 宿主薄适配层。核心逻辑全部来自根仓 lib/ 与 server/,这里只做三件事:
@@ -69,6 +71,51 @@ function json(res, statusCode, body) {
69
71
  res.end(JSON.stringify(body));
70
72
  }
71
73
 
74
+ const ALLOWED_BUDGET_TIERS = new Set([10, 20, 30, 40, 50]);
75
+ const BOOLEAN_SETTING_KEYS = new Set([
76
+ "webEnabled",
77
+ "preActionReviewAskEnabled",
78
+ "postWorkReviewAskEnabled",
79
+ "researchConsultAskEnabled",
80
+ "reviewAskSilentRunEnabled",
81
+ "experienceAccumulationEnabled",
82
+ "frictionDiscoveryEnabled",
83
+ ]);
84
+
85
+ async function readJsonBody(req) {
86
+ const chunks = [];
87
+ let total = 0;
88
+ for await (const chunk of req) {
89
+ total += chunk.length;
90
+ if (total > 1024 * 1024) throw new Error("Request body too large");
91
+ chunks.push(chunk);
92
+ }
93
+ const text = Buffer.concat(chunks).toString("utf8").trim();
94
+ return text ? JSON.parse(text) : {};
95
+ }
96
+
97
+ function validateSettingsPatch(raw) {
98
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
99
+ return { ok: false, error: "Request body must be a JSON object" };
100
+ }
101
+ const clean = {};
102
+ for (const [key, value] of Object.entries(raw)) {
103
+ if (BOOLEAN_SETTING_KEYS.has(key)) {
104
+ if (typeof value !== "boolean") return { ok: false, error: `Setting "${key}" must be a boolean` };
105
+ clean[key] = value;
106
+ continue;
107
+ }
108
+ if (key === "injectionBudgetTier") {
109
+ const numeric = Number(value);
110
+ if (!Number.isInteger(numeric) || !ALLOWED_BUDGET_TIERS.has(numeric)) {
111
+ return { ok: false, error: "injectionBudgetTier must be one of 10, 20, 30, 40, 50" };
112
+ }
113
+ clean.injectionBudgetTier = numeric;
114
+ }
115
+ }
116
+ return { ok: true, patch: clean };
117
+ }
118
+
72
119
  export function apply(ctx, config = {}) {
73
120
  const dataPath = createDataPathResolver();
74
121
  const settings = () => ({
@@ -92,6 +139,20 @@ export function apply(ctx, config = {}) {
92
139
  ctx.logger?.info?.("[ldvh] host seam %s: %s (%s)", seam.state, seam.seam, seam.detail);
93
140
  }
94
141
 
142
+ // 若 DSH 宿主提供 systemPrompt 装配扩展,接入治理引导;未提供时安全降级不报错
143
+ try {
144
+ const sp = ctx.get?.("systemPrompt") ?? ctx.systemPrompt;
145
+ if (typeof sp?.register === "function") {
146
+ disposers.push(sp.register((agent) => createAssembleHandler(agent, {
147
+ resolve: (cwd) => resolveGovernanceScope(dataPath, cwd),
148
+ syncTools: () => {},
149
+ recordScope: () => {},
150
+ })));
151
+ }
152
+ } catch {
153
+ // 宿主未提供 systemPrompt 扩展时安全降级
154
+ }
155
+
95
156
  ctx.inject(["webServer"], (webCtx) => {
96
157
  const webServer = webCtx.webServer;
97
158
  if (webServer === undefined || readValue(config?.webEnabled, true) === false) return;
@@ -126,6 +187,28 @@ export function apply(ctx, config = {}) {
126
187
  json(res, 200, { ok: true, service: "ld-vibe-harness", host: "dsh" });
127
188
  return;
128
189
  }
190
+ if (path === `${API_PREFIX}/plugin-settings`) {
191
+ if (req.method === "GET") {
192
+ const current = await readPluginSettings(dataPath);
193
+ json(res, 200, { ok: true, settings: current, runtime: { host: "dsh", platform: process.platform } });
194
+ return;
195
+ }
196
+ if (req.method === "POST") {
197
+ try {
198
+ const raw = await readJsonBody(req);
199
+ const validated = validateSettingsPatch(raw);
200
+ if (!validated.ok) {
201
+ json(res, 400, { ok: false, error: validated.error });
202
+ return;
203
+ }
204
+ const updated = await writePluginSettings(dataPath, validated.patch);
205
+ json(res, 200, { ok: true, settings: updated });
206
+ } catch (error) {
207
+ json(res, 400, { ok: false, error: String(error?.message ?? error) });
208
+ }
209
+ return;
210
+ }
211
+ }
129
212
  if ((await governance(req, res)) !== false) return;
130
213
  const url = new URL(req.url ?? "/", "http://ldvh.local");
131
214
  await proxy(req, res, path.slice(API_PREFIX.length) || "/", url.search);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ldvh-dsh-adapter",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "LDVH 的 DSH Cordis 适配层:把仓库内七类结构化事实源工具、受控写入守卫与本地 Web 看板接入 DSH,并与 Antigravity / Codex 共享 ~/.ldvh 数据目录。",
5
5
  "private": true,
6
6
  "license": "MIT",
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: ldvh-friction-recorder
3
+ description: LDVH 摩擦观察代理。接收主控转发的阻碍材料(原话+定位),查重后调用 ldvh_friction_record_observation 写入观察缓冲;同源累计满 3 次时由工具以本代理签名自动晋升为待修 Friction,禁止直接调用 ldvh_friction_write。
4
+ ---
5
+
6
+ # LDVH 摩擦观察者
7
+
8
+ 你负责接收主控转发的**有界阻碍材料**,把查重、归组与记录观察留在你的独立上下文中完成,不占用主控上下文。
9
+
10
+ ## 做法
11
+
12
+ 1. **先查重**:用 `ldvh_friction_list`(查 `open` / `accepted` 账目)确认是否已有同类未关闭的 Friction 账目。
13
+ - 若已有对应 open/accepted 账目,记录其 `object_uid` 作为 `target_uid` 传入。
14
+ - 否则确定稳定一致的归组 key(`group`),保证同一障碍多次观察能落入同一组。
15
+ 2. **记录观察**:调用 `ldvh_friction_record_observation` 写入临时观察缓冲:
16
+ - `phenomenon`:写「观察到什么」,不把主观猜测写成结论;
17
+ - `evidence`:逐字引证主控交付的原话与定位;
18
+ - `group` / `target_uid`(如适用)。
19
+ 3. **自动晋升与回执**:
20
+ - 同一次 `ldvh_friction_record_observation` 调用内部会在同源观察累计 `>= 3` 次时,由工具自动使用**本代理会话的签名**晋升生成待修 Friction(结果见返回字段 `promotion`)。
21
+ - 未达阈值(`< 3`)仍属正常留观,不得视作失败。
22
+ - 将 `entry_id`、`group_pending_count` 与 `promotion` 结果如实交还主控。
23
+
24
+ ## 纪律
25
+
26
+ - 只允许使用只读工具与 `ldvh_friction_record_observation`;**严禁调用 `ldvh_friction_write`**,也不触碰其他类型事实对象的写入入口。
27
+ - 缺少原话或定位材料时如实交还缺口,不臆造证据。
package/hooks/_client.mjs CHANGED
@@ -1,7 +1,11 @@
1
1
  import { readFile } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ import { fileURLToPath } from "node:url";
2
4
  import { createDataPathResolver } from "../lib/data-paths.js";
5
+ import { computePluginCodeFingerprint } from "../server/local-daemon.js";
3
6
  import { createHookEngine } from "./hook-engine.js";
4
7
 
8
+ const REPO_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
5
9
  const DAEMON_TIMEOUT_MS = 2500;
6
10
 
7
11
  async function readStdinJson() {
@@ -31,6 +35,22 @@ async function tryCallDaemon(dataPath, route, payload) {
31
35
  return null;
32
36
  }
33
37
  const host = typeof runtime.host === "string" && runtime.host.length > 0 ? runtime.host : "127.0.0.1";
38
+ const localFingerprint = computePluginCodeFingerprint(REPO_ROOT);
39
+ if (runtime.codeFingerprint !== localFingerprint) {
40
+ try {
41
+ const shutdownController = new AbortController();
42
+ const shutdownTimer = setTimeout(() => shutdownController.abort(), 800);
43
+ await fetch(`http://${host}:${runtime.port}/admin/shutdown`, {
44
+ method: "POST",
45
+ headers: { "x-ldvh-token": runtime.token },
46
+ signal: shutdownController.signal,
47
+ }).catch(() => {});
48
+ clearTimeout(shutdownTimer);
49
+ } catch {
50
+ // 忽略关闭旧 daemon 时的连接错误
51
+ }
52
+ return null;
53
+ }
34
54
  const controller = new AbortController();
35
55
  const timer = setTimeout(() => controller.abort(), DAEMON_TIMEOUT_MS);
36
56
  try {