ld-vibe-harness 0.2.0 → 0.3.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/.claude-plugin/plugin.json +2 -2
- package/.codex-plugin/plugin.json +4 -4
- package/CHANGELOG.md +32 -0
- package/README.en.md +13 -12
- package/README.md +20 -20
- package/adapters/antigravity/installer.js +26 -8
- package/adapters/dsh/index.js +0 -3
- package/adapters/dsh/package.json +2 -2
- package/agents/ldvh-experience-recorder.md +2 -3
- package/agents/ldvh-post-work-reviewer.md +0 -1
- package/agents/ldvh-pre-action-reviewer.md +0 -1
- package/agents/ldvh-researcher.md +1 -2
- package/cli/ldvh.mjs +137 -5
- package/docs/ARCHITECTURE.md +37 -37
- package/docs/PRIVACY.md +7 -6
- package/hooks/_client.mjs +1 -12
- package/hooks/hook-engine.js +684 -84
- package/lib/capture-notice.js +8 -22
- package/lib/commit-validation.js +0 -59
- package/lib/data-paths.js +0 -1
- package/lib/experience-arming.js +10 -4
- package/lib/gate-events.js +27 -2
- package/lib/git-gate-runner.js +83 -34
- package/lib/goal-anchor.js +17 -45
- package/lib/goal-tools.js +4 -26
- package/lib/goal-writer.js +5 -18
- package/lib/governed-projects.js +18 -7
- package/lib/guidance-budget.js +2 -2
- package/lib/guidance-text.js +7 -7
- package/lib/hook-manager.js +40 -14
- package/lib/hook-repair.js +77 -13
- package/lib/host-api.js +7 -3
- package/lib/host-seams.js +78 -57
- package/lib/idle-settings.js +1 -4
- package/lib/intent-tools.js +6 -14
- package/lib/intent-writer.js +12 -45
- package/lib/ldvh-tools.js +26 -61
- package/lib/object-identifier.js +0 -2
- package/lib/object-reference.js +0 -2
- package/lib/operation-declarations.bundle.json +1 -64
- package/lib/recall-criteria.bundle.json +2 -67
- package/lib/recall-criteria.js +0 -2
- package/lib/recall-injection.js +1 -5
- package/lib/recall-synonyms.js +1 -3
- package/lib/research-consult-tools.js +201 -19
- package/lib/research-consult.js +49 -27
- package/lib/review-ask-tool.js +75 -11
- package/lib/review-ask.js +12 -9
- package/lib/source-recall.js +6 -16
- package/lib/web-preferences.js +2 -2
- package/package.json +2 -2
- package/plugin-specs/experience-accumulation-system-foundation.yaml +5 -25
- package/plugin-specs/fact-model-common.yaml +3 -14
- package/plugin-specs/gate-consult-system-foundation.yaml +39 -29
- package/plugin-specs/goal-fact-type.yaml +20 -67
- package/plugin-specs/goal-planning-system-foundation.yaml +27 -98
- package/plugin-specs/intent-fact-type.yaml +13 -22
- package/plugin-specs/intent-record-system-foundation.yaml +1 -2
- package/plugin-specs/ldvh-root.yaml +6 -6
- package/plugin-specs/norm-fact-type.yaml +1 -1
- package/plugin-specs/pitfall-fact-type.yaml +5 -49
- package/plugin-specs/report-fact-type.yaml +1 -1
- package/plugin-specs/research-system-foundation.yaml +12 -9
- package/plugin.json +4 -4
- package/rules/AGENTS.md +3 -3
- package/server/local-daemon.js +86 -28
- package/server/mcp-server.js +211 -53
- package/server/tool-registry.js +0 -23
- package/skills/ldvh-governance-flow/SKILL.md +10 -19
- package/skills/ldvh-onboarding/SKILL.md +2 -2
- package/agents/ldvh-friction-recorder.md +0 -27
- package/lib/aux-task-registry.js +0 -129
- package/lib/friction-discovery.js +0 -383
- package/lib/friction-failure-registration.js +0 -56
- package/lib/friction-observation-buffer.js +0 -889
- package/lib/friction-promotion-lock.js +0 -124
- package/lib/friction-review-promotion.js +0 -193
- package/lib/friction-tools.js +0 -829
- package/lib/friction-writer.js +0 -1123
- package/lib/milestone-tools.js +0 -684
- package/lib/milestone-writer.js +0 -707
- package/lib/verification-run.js +0 -195
- package/plugin-specs/friction-fact-type.yaml +0 -333
- package/plugin-specs/friction-settlement-system-foundation.yaml +0 -334
- package/plugin-specs/milestone-fact-type.yaml +0 -212
package/lib/goal-writer.js
CHANGED
|
@@ -5,7 +5,6 @@ import { join } from "node:path";
|
|
|
5
5
|
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
6
6
|
|
|
7
7
|
import { requireAuthoritativeSignature } from "./signature-channel.js";
|
|
8
|
-
import { listResolvableMilestones } from "./milestone-writer.js";
|
|
9
8
|
import { buildUpdateFrontmatter } from "./after-integrity.js";
|
|
10
9
|
import { repairedLengthMessage } from "./write-diagnostics.js";
|
|
11
10
|
|
|
@@ -189,14 +188,14 @@ export function validateGoalBodyStructure(body) {
|
|
|
189
188
|
const isCurrent = headings.length === BODY_H2.length && headings.every((h, i) => h === BODY_H2[i]);
|
|
190
189
|
const isLegacy = headings.length === LEGACY_BODY_H2.length && headings.every((h, i) => h === LEGACY_BODY_H2[i]);
|
|
191
190
|
if (!isCurrent && !isLegacy) {
|
|
192
|
-
issues.push(`body: H2 sections must be exactly ${BODY_H2.map((h) => `"${h}"`).join(" then ")}, got ${JSON.stringify(headings)} (25 §7
|
|
191
|
+
issues.push(`body: H2 sections must be exactly ${BODY_H2.map((h) => `"${h}"`).join(" then ")}, got ${JSON.stringify(headings)} (25 §7)`);
|
|
193
192
|
}
|
|
194
193
|
const target = sections.find((s) => s.heading === "目标陈述");
|
|
195
194
|
if (target === undefined || target.text.length === 0) {
|
|
196
195
|
issues.push("body: 目标陈述 section must be present and non-empty (25 §12 创建检查)");
|
|
197
196
|
} else if (target.text.length > MAX_STATEMENT_LENGTH) {
|
|
198
197
|
issues.push(
|
|
199
|
-
repairedLengthMessage("body: 目标陈述", target.text, MAX_STATEMENT_LENGTH, "25 §7") + " — move implementation detail /
|
|
198
|
+
repairedLengthMessage("body: 目标陈述", target.text, MAX_STATEMENT_LENGTH, "25 §7") + " — move implementation detail / execution plan to Intent or Report",
|
|
200
199
|
);
|
|
201
200
|
}
|
|
202
201
|
return { ok: issues.length === 0, issues };
|
|
@@ -312,7 +311,7 @@ export async function createGoalObject(args) {
|
|
|
312
311
|
if (hasLegacyMilestoneSection(body)) {
|
|
313
312
|
return failure(
|
|
314
313
|
"goal/legacy_milestone_reintroduced",
|
|
315
|
-
"goal.md no longer carries a 子目标 section (25 §7
|
|
314
|
+
"goal.md no longer carries a 子目标 section (25 §7): keep only 目标陈述 in goal.md and track concrete direction lines as Intent objects",
|
|
316
315
|
);
|
|
317
316
|
}
|
|
318
317
|
const bodyCheck = validateGoalBodyStructure(body);
|
|
@@ -394,7 +393,7 @@ export async function updateGoalObject(args) {
|
|
|
394
393
|
if (changed) {
|
|
395
394
|
return failure(
|
|
396
395
|
"goal/legacy_milestone_immutable",
|
|
397
|
-
"the legacy 子目标 section in goal.md cannot be edited any more (25 §7
|
|
396
|
+
"the legacy 子目标 section in goal.md cannot be edited any more (25 §7): delete this section in one update instead of editing entries here",
|
|
398
397
|
{ existing_anchors: prevAnchors, attempted_anchors: nextAnchors },
|
|
399
398
|
);
|
|
400
399
|
}
|
|
@@ -403,7 +402,7 @@ export async function updateGoalObject(args) {
|
|
|
403
402
|
} else if (!prevHasLegacy && nextHasLegacy) {
|
|
404
403
|
return failure(
|
|
405
404
|
"goal/legacy_milestone_reintroduced",
|
|
406
|
-
"the 子目标 section was removed from goal.md (25 §7
|
|
405
|
+
"the 子目标 section was removed from goal.md (25 §7) and may not be reintroduced",
|
|
407
406
|
);
|
|
408
407
|
}
|
|
409
408
|
|
|
@@ -438,15 +437,3 @@ export async function updateGoalObject(args) {
|
|
|
438
437
|
legacy_milestones_dropped: droppedLegacy,
|
|
439
438
|
});
|
|
440
439
|
}
|
|
441
|
-
|
|
442
|
-
export async function readServableMilestones({ factSourceRoot }) {
|
|
443
|
-
const goal = await readGoalObject({ factSourceRoot });
|
|
444
|
-
if (!goal.ok) return goal;
|
|
445
|
-
const listed = await listResolvableMilestones(factSourceRoot);
|
|
446
|
-
if (!listed.ok) return failure(listed.error.code, listed.error.message);
|
|
447
|
-
return success({
|
|
448
|
-
milestones: listed.value.items,
|
|
449
|
-
status: goal.value.frontmatter.status,
|
|
450
|
-
file: goal.value.file,
|
|
451
|
-
});
|
|
452
|
-
}
|
package/lib/governed-projects.js
CHANGED
|
@@ -9,7 +9,7 @@ import { HOOK_BUNDLE_VERSION, inspectHook, installHook, uninstallHook as removeM
|
|
|
9
9
|
|
|
10
10
|
const execFileAsync = promisify(execFile);
|
|
11
11
|
const REGISTRATION_RELATIVE_PATH = ["ldvh", "governed-projects.yaml"];
|
|
12
|
-
const FACT_DIRECTORIES = ["intents", "pitfalls", "reports", "
|
|
12
|
+
const FACT_DIRECTORIES = ["intents", "pitfalls", "reports", "norms"];
|
|
13
13
|
|
|
14
14
|
export const REGISTRATION_UNAVAILABLE_CODES = Object.freeze({
|
|
15
15
|
USER_CONFIG_ROOT_UNAVAILABLE: "user_config_root_unavailable",
|
|
@@ -236,21 +236,28 @@ async function factSourceStatus(projectRoot) {
|
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
export async function inspectCandidate(candidate) {
|
|
239
|
+
export async function inspectCandidate(candidate, options = {}) {
|
|
240
240
|
try {
|
|
241
241
|
const identity = await resolveGitRoot(candidate);
|
|
242
|
-
|
|
242
|
+
const hookOptions = {};
|
|
243
|
+
if (typeof options?.expectedRunnerPath === "string" && options.expectedRunnerPath.length > 0) {
|
|
244
|
+
hookOptions.expectedRunnerPath = options.expectedRunnerPath;
|
|
245
|
+
}
|
|
246
|
+
if (typeof options?.expectedWorkspaceRoot === "string" && options.expectedWorkspaceRoot.length > 0) {
|
|
247
|
+
hookOptions.expectedWorkspaceRoot = options.expectedWorkspaceRoot;
|
|
248
|
+
}
|
|
249
|
+
return success({ ...identity, factSource: await factSourceStatus(identity.projectRoot), hook: await inspectHook(identity.projectRoot, hookOptions) });
|
|
243
250
|
} catch (error) {
|
|
244
251
|
return failure("candidate_invalid", String(error?.message || error));
|
|
245
252
|
}
|
|
246
253
|
}
|
|
247
254
|
|
|
248
|
-
export async function readGovernedProjects(dshHomePath) {
|
|
255
|
+
export async function readGovernedProjects(dshHomePath, options = {}) {
|
|
249
256
|
try {
|
|
250
257
|
const registration = await readRegistration(dshHomePath);
|
|
251
258
|
const projects = [];
|
|
252
259
|
for (const project of registration.document.projects) {
|
|
253
|
-
const inspected = await inspectCandidate(project.path);
|
|
260
|
+
const inspected = await inspectCandidate(project.path, options);
|
|
254
261
|
projects.push({ ...project, status: inspected.ok ? inspected.value : { error: inspected.error } });
|
|
255
262
|
}
|
|
256
263
|
return success({ initialized: registration.exists, projects, defaultProjectId: registration.document.default_project_id, fingerprint: registration.fingerprint });
|
|
@@ -332,7 +339,11 @@ export async function registerProject(dshHomePath, input) {
|
|
|
332
339
|
}
|
|
333
340
|
|
|
334
341
|
export async function installProject(dshHomePath, input, runtime) {
|
|
335
|
-
const
|
|
342
|
+
const inspectOptions = {
|
|
343
|
+
expectedRunnerPath: runtime?.runnerPath,
|
|
344
|
+
expectedWorkspaceRoot: runtime?.workspaceRoot,
|
|
345
|
+
};
|
|
346
|
+
const candidate = await inspectCandidate(input.path, inspectOptions);
|
|
336
347
|
if (!candidate.ok) return candidate;
|
|
337
348
|
const before = candidate.value;
|
|
338
349
|
const factBefore = before.factSource;
|
|
@@ -351,7 +362,7 @@ export async function installProject(dshHomePath, input, runtime) {
|
|
|
351
362
|
hookInstalled = hookBefore.state !== "managed";
|
|
352
363
|
const registered = await registerProject(dshHomePath, input);
|
|
353
364
|
if (!registered.ok) throw new Error(registered.error.message);
|
|
354
|
-
return success({ registration: registered.value, status: (await inspectCandidate(before.projectRoot)).value });
|
|
365
|
+
return success({ registration: registered.value, status: (await inspectCandidate(before.projectRoot, inspectOptions)).value });
|
|
355
366
|
} catch (error) {
|
|
356
367
|
const rollback = [];
|
|
357
368
|
if (hookInstalled) {
|
package/lib/guidance-budget.js
CHANGED
package/lib/guidance-text.js
CHANGED
|
@@ -15,7 +15,7 @@ export function noticeTextFor(scope) {
|
|
|
15
15
|
`登记指纹:${scope.registrationFingerprint ?? "未知"}`,
|
|
16
16
|
"",
|
|
17
17
|
"管辖效果:",
|
|
18
|
-
"- ldvh_* 工具已注册(管辖判定 / 能力发现 / 提交预检 /
|
|
18
|
+
"- ldvh_* 工具已注册(管辖判定 / 能力发现 / 提交预检 / 五类事实读写 / 把关与调研)",
|
|
19
19
|
"- 运行期规则载体随包(plugin-specs/*.yaml),每轮行动前按场景自动召回",
|
|
20
20
|
"- 受控提交经 Git Gate 机械校验",
|
|
21
21
|
"- 规则正文以随包 plugin-specs/*.yaml 与项目 ldvh-base/norms/ 为准(specs/ 仅为开发需求文档)"
|
|
@@ -42,18 +42,18 @@ export function migrationLineFor(fromState, toState) {
|
|
|
42
42
|
|
|
43
43
|
const GOVERNED_GUIDANCE = `本会话工作锚点(specs/00-理念与构成.md):
|
|
44
44
|
1. 身份块——每个 specs/ 载体首部 ldvh_spec/ldvh_attachment 声明身份、依据与关系
|
|
45
|
-
2. §1
|
|
46
|
-
3. §2 方法与构成——根方案六条(§2.1)+ 能力承载(LDVH CLI 确定性服务/宿主原生机制,§2.3)+ 规范源与事实源(元规范与事实规范两级承载,§2.4)+
|
|
45
|
+
2. §1 核心价值——对齐 Vibe(让人与 AI 对项目由来、现状、去向一致)与协调 Coding(明晰权责、记录意图、确立规范、构建报告、积累经验);价值纪律见 §5
|
|
46
|
+
3. §2 方法与构成——根方案六条(§2.1)+ 能力承载(LDVH CLI 确定性服务/宿主原生机制,§2.3)+ 规范源与事实源(元规范与事实规范两级承载,§2.4)+ 检查机制(主控自查/机械校验/代理审核/代理复核,§2.5)+ 业务系统(目标规划/意图记录/把关请示/调研吸收/双源召回/经验积累,§2.6 名录)+ 技术与机械保障(§2.7)+ 插件四种价值交付(§2.8)+ 下位承接(§2.9)
|
|
47
47
|
4. §3 Human 权利——根决定清单(§3.2)、Human Gate、受保护内容(§3.3)、可决提请与回应效力(§3.4)
|
|
48
48
|
5. §4 AI 责任与义务——主控发起的行动由单一主控 AI 最终负责、代理辅助任务由机械校验保障(00 §4.5)、非全知、委派不转责(代理辅助任务除外,00 §4.3)、反稀释(01 §5 第 13 项);§4.6 据实声明、§4.7 必停情形与恢复、§4.8 交还与撤回
|
|
49
49
|
6. §5 价值纪律——机制准入(§5.1)、价值不因材料存在而成立(§5.2)、冲突与变更(§5.3)
|
|
50
50
|
规则定位:行动前召回段给出本轮相关的随包运行时机制载体(plugin-specs/*.yaml)与项目事实规范(ldvh-base/norms/);需要条目正文时直接按给出的可读路径按需读取(specs/ 只是开发需求文档,不构成运行期规则)。
|
|
51
51
|
能力发现:ldvh_discover_capabilities;受控提交前:ldvh_precheck_git_commit;
|
|
52
|
-
把关请示:在行动前与收口前两处向 Human
|
|
53
|
-
|
|
54
|
-
创建确认不重复:当写入工具自带 Human 确认 Gate(如 Intent 22 §16、Norm 23 §15)时,该次写入的确认由工具内部 Gate 承担,主控不再就同一动作另发一次确认弹窗;呈报要素按该类型规范(22 §16、23 §15.2
|
|
52
|
+
把关请示:在行动前与收口前两处向 Human 请示是否安排一次独立核对(三选一),主控自查认为问题复杂、内部未调查过且联网调查更有帮助时第三处主动向 Human 请示「联网调查/不调查」(二选一,获准后由主控亲自执行完整调研工序;Human 主动要求调研时先查内部、免请示直接由主控调研),请示答复都留痕、不构成授权凭据、也不使行动在取得答复前暂停(§2.5);三处各有开关,缺省关闭;前两处关着只保证「不问」,不禁止 AI 按 04 §6.1 自行安排隔离视角,第三处关着则 AI 既不主动提请也不自行发起外部取证(不限制 Human 主动要求);第三处先查内部事实源,只有实质命中才拦下、命中只是候选不证明适用,「未命中」只表示按机制查过而未命中、不等于内部没有(34 §12);前两处另有执行档位(征询/静默,缺省征询),静默时该处不逐次征询、按 Human 的预先答复直接安排那次核对并留执行痕迹,它只免征询不免核对、不越过该处的询问开关,且不外推到意图/管辖项目等 Human Gate 的提请;「算不算复杂」与「该不该联网」都由 AI 判断,机械层不判定,故这不构成机械保障;
|
|
53
|
+
模型面提请:转调 ldvh_review_ask/ldvh_research_consult 返回的题面调用宿主 ask_question 时须原样传入 question 与 options、不自行改写或截断且不带 detail;自由发起 ask_question 时保持题面简明、判断依据写进对话正文;此为对 AI 的指令、无机械保障;
|
|
54
|
+
创建确认不重复:当写入工具自带 Human 确认 Gate(如 Intent 22 §16、Norm 23 §15)时,该次写入的确认由工具内部 Gate 承担,主控不再就同一动作另发一次确认弹窗;呈报要素按该类型规范(22 §16、23 §15.2 等)在调用工具前逐项写进对话正文。本行只免同一动作的重复弹窗,不减任何类型的确认义务;合并/拆分等组合处置按 22 §16 归属,逐步骤多出的询问属已知实现限制,须如实披露。此为对 AI 的指令、无机械保障;32 号两处把关请示是 Human Gate 之外的征询、由 ldvh_review_ask 承载,不是写入确认,不构成重复;
|
|
55
55
|
失败留痕:待处置队列已删除(Human 2026-11-17,00 §4.7)——代理辅助任务失败由执行体当次回执承载(主控按 00 §4.6 如实转述),另以运行痕迹跨会话可查(诊断页只读呈现);不再有「接管前先读账」的义务,也不再有结案通道。
|
|
56
|
-
|
|
56
|
+
经验主动记录:主控在当次行动中发现已查明验证的失败机制或反复卡点有效临时规避时,调 ldvh_pitfall_arm_delegate 授权并把所需上下文材料交给零上下文派生的代理(ldvh-experience-recorder)查重后经受控入口直接创建 Pitfall(只允许 create,禁止改旧或终态);**不继承主控对话**——材料由主控按该机制挑选,派完即撒手,收到回执顺手转告 Human。
|
|
57
57
|
管辖状态:ldvh_resolve_governance_scope。完整规则以规范源原文为准,本引导不复制规则正文。`;
|
|
58
58
|
|
|
59
59
|
const UNAVAILABLE_GUIDANCE = `LDVH 管辖登记当前不可读取。本项目暂按不受管辖处理(与 not_governed 一致),但状态确为「不可用」而非「不受辖」,不得据此认定本项目不受辖。
|
package/lib/hook-manager.js
CHANGED
|
@@ -16,7 +16,7 @@ export const MANAGED_HOOKS = Object.freeze([
|
|
|
16
16
|
]);
|
|
17
17
|
|
|
18
18
|
const DEFAULT_HOOK_NAME = "commit-msg";
|
|
19
|
-
export const HOOK_BUNDLE_VERSION = "
|
|
19
|
+
export const HOOK_BUNDLE_VERSION = "2.0.0";
|
|
20
20
|
|
|
21
21
|
export const INTERPRETER_UNAVAILABLE_PREFIX = "LDVH Git Gate cannot run: no node interpreter found";
|
|
22
22
|
|
|
@@ -102,13 +102,15 @@ function parseShellSingleQuoted(text, startIndex) {
|
|
|
102
102
|
let value = "";
|
|
103
103
|
for (let index = startIndex + 1; index < text.length; index += 1) {
|
|
104
104
|
const character = text[index];
|
|
105
|
-
if (character === "'")
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
if (character === "'") {
|
|
106
|
+
if (text.slice(index, index + 4) === "'\\''") {
|
|
107
|
+
value += "'";
|
|
108
|
+
index += 3;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
return { value, end: index + 1 };
|
|
111
112
|
}
|
|
113
|
+
value += character;
|
|
112
114
|
}
|
|
113
115
|
return null;
|
|
114
116
|
}
|
|
@@ -146,6 +148,21 @@ async function pathExists(target) {
|
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
150
|
|
|
151
|
+
async function canonicalizePath(target) {
|
|
152
|
+
try {
|
|
153
|
+
return await realpath(target);
|
|
154
|
+
} catch {
|
|
155
|
+
return resolve(target);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function samePath(actual, expected) {
|
|
160
|
+
if (typeof actual !== "string" || actual.length === 0) return false;
|
|
161
|
+
if (typeof expected !== "string" || expected.length === 0) return false;
|
|
162
|
+
const [a, b] = await Promise.all([canonicalizePath(actual), canonicalizePath(expected)]);
|
|
163
|
+
return process.platform === "win32" ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
164
|
+
}
|
|
165
|
+
|
|
149
166
|
export function renderHook({ runnerPath, workspaceRoot, bundleVersion = HOOK_BUNDLE_VERSION, interpreterCandidates = defaultInterpreterCandidates(), hookName = DEFAULT_HOOK_NAME }) {
|
|
150
167
|
const spec = MANAGED_HOOKS.find((hook) => hook.name === hookName);
|
|
151
168
|
if (spec === undefined) throw new Error(`unmanaged Git Hook: ${hookName}`);
|
|
@@ -194,7 +211,8 @@ export function renderHook({ runnerPath, workspaceRoot, bundleVersion = HOOK_BUN
|
|
|
194
211
|
return `#!/bin/sh\n${MARKER_PREFIX}${digest(body)}\n${body}`;
|
|
195
212
|
}
|
|
196
213
|
|
|
197
|
-
async function inspectOneHook(identity, spec) {
|
|
214
|
+
async function inspectOneHook(identity, spec, options = {}) {
|
|
215
|
+
const { expectedRunnerPath, expectedWorkspaceRoot } = options;
|
|
198
216
|
const hookPath = identity.hookPaths[spec.name];
|
|
199
217
|
let content;
|
|
200
218
|
try {
|
|
@@ -216,6 +234,12 @@ async function inspectOneHook(identity, spec) {
|
|
|
216
234
|
if (hookPaths.workspaceRoot !== null && !(await pathExists(hookPaths.workspaceRoot))) {
|
|
217
235
|
return { name: spec.name, hookPath, state: "outdated", detail: `LDVH Git Hook workspace root no longer exists: ${hookPaths.workspaceRoot}`, hookBundleVersion: parsed.version };
|
|
218
236
|
}
|
|
237
|
+
if (typeof expectedRunnerPath === "string" && expectedRunnerPath.length > 0 && !(await samePath(hookPaths.runnerPath, expectedRunnerPath))) {
|
|
238
|
+
return { name: spec.name, hookPath, state: "outdated", detail: `LDVH Git Hook runner points to a different installation: ${hookPaths.runnerPath ?? "unknown"}`, hookBundleVersion: parsed.version };
|
|
239
|
+
}
|
|
240
|
+
if (typeof expectedWorkspaceRoot === "string" && expectedWorkspaceRoot.length > 0 && !(await samePath(hookPaths.workspaceRoot, expectedWorkspaceRoot))) {
|
|
241
|
+
return { name: spec.name, hookPath, state: "outdated", detail: `LDVH Git Hook workspace root points to a different installation: ${hookPaths.workspaceRoot ?? "unknown"}`, hookBundleVersion: parsed.version };
|
|
242
|
+
}
|
|
219
243
|
return parsed.version === HOOK_BUNDLE_VERSION
|
|
220
244
|
? { name: spec.name, hookPath, state: "managed", detail: "LDVH Git Hook is current", hookBundleVersion: parsed.version }
|
|
221
245
|
: { name: spec.name, hookPath, state: "outdated", detail: `LDVH Git Hook ${parsed.version ?? "unknown"} requires update`, hookBundleVersion: parsed.version };
|
|
@@ -232,21 +256,22 @@ async function isExecutable(hookPath) {
|
|
|
232
256
|
|
|
233
257
|
const HOOK_STATE_SEVERITY = Object.freeze(["conflict", "unavailable", "absent", "outdated", "managed"]);
|
|
234
258
|
|
|
235
|
-
export async function inspectHook(candidate, { hookName } = {}) {
|
|
259
|
+
export async function inspectHook(candidate, { hookName, expectedRunnerPath, expectedWorkspaceRoot } = {}) {
|
|
236
260
|
let identity;
|
|
237
261
|
try {
|
|
238
262
|
identity = await resolveIdentity(candidate);
|
|
239
263
|
} catch (error) {
|
|
240
264
|
return { state: "unavailable", detail: String(error?.message || error), expectedHookBundleVersion: HOOK_BUNDLE_VERSION };
|
|
241
265
|
}
|
|
266
|
+
const inspectOptions = { expectedRunnerPath, expectedWorkspaceRoot };
|
|
242
267
|
if (hookName !== undefined) {
|
|
243
268
|
const spec = MANAGED_HOOKS.find((hook) => hook.name === hookName);
|
|
244
269
|
if (spec === undefined) return { ...identity, state: "unavailable", detail: `unmanaged Git Hook: ${hookName}`, hookBundleVersion: null, expectedHookBundleVersion: HOOK_BUNDLE_VERSION };
|
|
245
|
-
const single = await inspectOneHook(identity, spec);
|
|
270
|
+
const single = await inspectOneHook(identity, spec, inspectOptions);
|
|
246
271
|
return { ...identity, ...single, expectedHookBundleVersion: HOOK_BUNDLE_VERSION };
|
|
247
272
|
}
|
|
248
273
|
const hooks = [];
|
|
249
|
-
for (const spec of MANAGED_HOOKS) hooks.push(await inspectOneHook(identity, spec));
|
|
274
|
+
for (const spec of MANAGED_HOOKS) hooks.push(await inspectOneHook(identity, spec, inspectOptions));
|
|
250
275
|
const worst = HOOK_STATE_SEVERITY.find((state) => hooks.some((hook) => hook.state === state)) ?? "unavailable";
|
|
251
276
|
return {
|
|
252
277
|
...identity,
|
|
@@ -361,7 +386,7 @@ async function preflight(rendered, identity, spec, workspaceRoot) {
|
|
|
361
386
|
await mkdir(tempDir, { mode: 0o700 });
|
|
362
387
|
await writeFile(hook, rendered, { mode: 0o755 });
|
|
363
388
|
const preflightIndex = await seedPreflightIndex(identity, tempDir);
|
|
364
|
-
const hookEnv = { LDVH_WORKSPACE_ROOT: workspaceRoot };
|
|
389
|
+
const hookEnv = { LDVH_WORKSPACE_ROOT: workspaceRoot, LDVH_DISABLE_GATE_EVENTS: "1" };
|
|
365
390
|
if (spec.argument === "message-file") {
|
|
366
391
|
const invalid = join(tempDir, "invalid-message");
|
|
367
392
|
const valid = join(tempDir, "valid-message");
|
|
@@ -396,7 +421,8 @@ async function readOriginal(path) {
|
|
|
396
421
|
|
|
397
422
|
export async function installHook({ projectRoot, runnerPath, workspaceRoot }) {
|
|
398
423
|
const identity = await resolveIdentity(projectRoot);
|
|
399
|
-
const
|
|
424
|
+
const inspectOptions = { expectedRunnerPath: runnerPath, expectedWorkspaceRoot: workspaceRoot };
|
|
425
|
+
const status = await inspectHook(projectRoot, inspectOptions);
|
|
400
426
|
if (status.state === "conflict" || status.state === "unavailable") return { ok: false, error: { code: "hook_conflict", message: status.detail, details: status } };
|
|
401
427
|
const pending = [];
|
|
402
428
|
for (const spec of MANAGED_HOOKS) {
|
|
@@ -427,7 +453,7 @@ export async function installHook({ projectRoot, runnerPath, workspaceRoot }) {
|
|
|
427
453
|
}
|
|
428
454
|
return { ok: false, error: { code: "hook_install_failed", message: String(error?.message || error), details: { identity, rollback, rewritten: replaced.length } } };
|
|
429
455
|
}
|
|
430
|
-
const after = await inspectHook(projectRoot);
|
|
456
|
+
const after = await inspectHook(projectRoot, inspectOptions);
|
|
431
457
|
return after.state === "managed"
|
|
432
458
|
? { ok: true, value: { ...after, rewritten: replaced.length } }
|
|
433
459
|
: { ok: false, error: { code: "hook_verify_failed", message: after.detail, details: after } };
|
package/lib/hook-repair.js
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
+
import { realpath } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
1
3
|
import { readGovernedProjects } from "./governed-projects.js";
|
|
2
|
-
import { installHook } from "./hook-manager.js";
|
|
4
|
+
import { installHook, resolveIdentity } from "./hook-manager.js";
|
|
3
5
|
|
|
4
6
|
const REPAIRABLE = Object.freeze(["absent", "outdated"]);
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
const summary = { checked: 0, repaired: [], skipped: [], failed: [] };
|
|
8
|
-
let projects;
|
|
8
|
+
async function canonicalizePath(target) {
|
|
9
9
|
try {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return summary;
|
|
14
|
-
}
|
|
15
|
-
projects = registration.value.projects;
|
|
16
|
-
} catch (error) {
|
|
17
|
-
summary.failed.push({ projectRoot: null, detail: String(error?.message ?? error) });
|
|
18
|
-
return summary;
|
|
10
|
+
return await realpath(target);
|
|
11
|
+
} catch {
|
|
12
|
+
return resolve(target);
|
|
19
13
|
}
|
|
14
|
+
}
|
|
20
15
|
|
|
16
|
+
async function sameProjectPath(actual, expected) {
|
|
17
|
+
if (typeof actual !== "string" || actual.length === 0) return false;
|
|
18
|
+
if (typeof expected !== "string" || expected.length === 0) return false;
|
|
19
|
+
const [a, b] = await Promise.all([canonicalizePath(actual), canonicalizePath(expected)]);
|
|
20
|
+
return process.platform === "win32" ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function repairProjectsList(projects, { runnerPath, workspaceRoot, logger } = {}) {
|
|
24
|
+
const summary = { checked: 0, repaired: [], skipped: [], failed: [] };
|
|
21
25
|
for (const project of projects) {
|
|
22
26
|
const status = project.status;
|
|
23
27
|
if (status?.error !== undefined) {
|
|
@@ -52,3 +56,63 @@ export async function repairHooksOnStartup({ dshHomePath, runnerPath, workspaceR
|
|
|
52
56
|
}
|
|
53
57
|
return summary;
|
|
54
58
|
}
|
|
59
|
+
|
|
60
|
+
export async function repairHooksOnStartup({ dshHomePath, runnerPath, workspaceRoot, logger } = {}) {
|
|
61
|
+
let projects;
|
|
62
|
+
try {
|
|
63
|
+
const registration = await readGovernedProjects(dshHomePath, { expectedRunnerPath: runnerPath, expectedWorkspaceRoot: workspaceRoot });
|
|
64
|
+
if (!registration.ok) {
|
|
65
|
+
return { checked: 0, repaired: [], skipped: [], failed: [{ projectRoot: null, detail: registration.error?.message ?? "registration unavailable" }] };
|
|
66
|
+
}
|
|
67
|
+
projects = registration.value.projects;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return { checked: 0, repaired: [], skipped: [], failed: [{ projectRoot: null, detail: String(error?.message ?? error) }] };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return repairProjectsList(projects, { runnerPath, workspaceRoot, logger });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function repairGovernedProjectHooks({ dshHomePath, runnerPath, workspaceRoot, projectRoot, logger } = {}) {
|
|
76
|
+
const registration = await readGovernedProjects(dshHomePath, { expectedRunnerPath: runnerPath, expectedWorkspaceRoot: workspaceRoot });
|
|
77
|
+
if (!registration.ok) return registration;
|
|
78
|
+
|
|
79
|
+
let targetProjects = registration.value.projects;
|
|
80
|
+
if (typeof projectRoot === "string" && projectRoot.trim().length > 0) {
|
|
81
|
+
let targetIdentity;
|
|
82
|
+
try {
|
|
83
|
+
targetIdentity = await resolveIdentity(projectRoot);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
return { ok: false, error: { code: "candidate_invalid", message: String(error?.message ?? error) } };
|
|
86
|
+
}
|
|
87
|
+
const matched = [];
|
|
88
|
+
for (const entry of targetProjects) {
|
|
89
|
+
if (await sameProjectPath(entry.status?.projectRoot ?? entry.path, targetIdentity.projectRoot)) {
|
|
90
|
+
matched.push(entry);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (matched.length === 0) {
|
|
94
|
+
return {
|
|
95
|
+
ok: false,
|
|
96
|
+
error: {
|
|
97
|
+
code: "not_registered",
|
|
98
|
+
message: "project is not registered; use install --human-confirmed to govern a new project",
|
|
99
|
+
details: { projectRoot: targetIdentity.projectRoot },
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
targetProjects = matched;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const summary = await repairProjectsList(targetProjects, { runnerPath, workspaceRoot, logger });
|
|
107
|
+
if (summary.failed.length > 0) {
|
|
108
|
+
return {
|
|
109
|
+
ok: false,
|
|
110
|
+
error: {
|
|
111
|
+
code: "hook_repair_failed",
|
|
112
|
+
message: summary.failed.map((failure) => failure.detail).join("; "),
|
|
113
|
+
details: summary,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return { ok: true, value: summary };
|
|
118
|
+
}
|
package/lib/host-api.js
CHANGED
|
@@ -20,6 +20,10 @@ async function readJson(req) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function createGovernanceHandler(options) {
|
|
23
|
+
const inspectOptions = {
|
|
24
|
+
expectedRunnerPath: options.runnerPath,
|
|
25
|
+
expectedWorkspaceRoot: options.workspaceRoot,
|
|
26
|
+
};
|
|
23
27
|
return async function governanceHandler(req, res) {
|
|
24
28
|
const parsedUrl = new URL(req.url ?? "/", "http://ldvh.local");
|
|
25
29
|
const rawPath = parsedUrl.pathname;
|
|
@@ -37,15 +41,15 @@ export function createGovernanceHandler(options) {
|
|
|
37
41
|
}),
|
|
38
42
|
);
|
|
39
43
|
}
|
|
40
|
-
if (path === "/governed-projects" && req.method === "GET") return json(res, 200, await readGovernedProjects(options.dshHomePath));
|
|
41
|
-
if (path === "/governed-projects/with-colors" && req.method === "GET") return json(res, 200, await readGovernedProjectsWithColors(options.dshHomePath));
|
|
44
|
+
if (path === "/governed-projects" && req.method === "GET") return json(res, 200, await readGovernedProjects(options.dshHomePath, inspectOptions));
|
|
45
|
+
if (path === "/governed-projects/with-colors" && req.method === "GET") return json(res, 200, await readGovernedProjectsWithColors(options.dshHomePath, inspectOptions));
|
|
42
46
|
if (path === "/governed-projects/color" && req.method === "POST") {
|
|
43
47
|
const input = await readJson(req);
|
|
44
48
|
return json(res, 200, await updateProjectColor(options.dshHomePath, input.projectId, input.color === undefined ? null : input.color));
|
|
45
49
|
}
|
|
46
50
|
if (path === "/governed-projects/inspect" && req.method === "POST") {
|
|
47
51
|
const input = await readJson(req);
|
|
48
|
-
return json(res, 200, await inspectCandidate(input.path));
|
|
52
|
+
return json(res, 200, await inspectCandidate(input.path, inspectOptions));
|
|
49
53
|
}
|
|
50
54
|
if (path === "/governed-projects/install" && req.method === "POST") {
|
|
51
55
|
const input = await readJson(req);
|