Skip to content

Commit 32fa1cb

Browse files
committed
fix: fail-closed implement-start without task or design artifacts
Control-plane mutations no longer pass when taskRoot is unbound. Require 00/01 plus 02 in addition to 04/05/checklist. Blocks promise-process-then-skip path used when editing global-host without a requirement package.
1 parent 19f348c commit 32fa1cb

5 files changed

Lines changed: 176 additions & 22 deletions

File tree

‎changelogs/unreleased.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
> **当前**: v1.15.3 已归档到 `changelogs/releases/v1.15.3.md`;本文件仅保留历史锚点索引与镜像供 validate 探针消费。发版后新实现再写入下方「当前未发布」。
55
66
## 当前未发布实现候选
7+
- **控制面 ImplementStartGate 防过程跳过**:`classifyImplementStartGate` 对控制面 mutation **禁止 unbound 放行**(`implement-start-without-task-binding`);绑定任务后除 04/05/复审清单外还须 **00/01 + 02 技术方案**(`implement-start-without-design`);lifecycle PreTool 无任务也 enforce。探针 `test-implement-start-gate.js`。需求:`VSCode全局MCP与五宿主同刷`(过程事故:承诺按流程却直接改码)。
78
- **VS Code 全局 MCP 与五宿主同刷**:`global-adapters apply` / 全局安装在 Copilot host 事务中合并写入用户级 `Code/User/mcp.json`(及已存在的 Code - Insiders)的 `servers.devcodex-memory|profile`(stdio→copilot runtime mcp),保留既有 `inputs`/其它 server;测试与边界见 `global-host-target.resolveVscodeUserMcpPaths`。
89
- **SkillsDeployModeV1(隐蔽运行时 + PR-1 防假绿)**:默认 `skillsDeployMode=hidden` 将 active skills 部署到 `~/.agents/devcodex/skills`(G_RUNTIME),停写/目录 prune `~/.agents/skills`、`~/.claude/skills`、`~/.copilot/skills` 中的包 managed id;`resolveGlobalSkillsRoot` 随 mode 切换(ENV `DEVCODEX_GLOBAL_SKILLS_ROOT` 仍最高优先);`global-adapters apply --mode=hidden|legacy` 与 npm lifecycle 透传;receipt 记录 mode。强化 `pr1EvidenceOk`:有 `02` 须独立实质 `03` 复审(长度+blocker=0+实质章节),拒绝 thin open-blocker / sessions-only;改写 stop-gate 负向探针。需求:`全局Skill与插件隐蔽运行时`。
910
- **Runtime 白名单闭包防复发**:新增 `scripts/lib/runtime-dependency-closure.js` 作为统一 runtime require 闭包 Owner;`MCP_RUNTIME_DEPS` / `PROJECT_RUNTIME_SCRIPT_DEPS`(兼容 `CLAUDE_MCP_RUNTIME_SCRIPT_DEPS`)改为派生;Codex project hook 复制到 `.codex/scripts/lib`;`test:mcp-runtime-closure` 覆盖 allowlist-only layout/MCP smoke/负向/packlist;validation 节点 `mcp-runtime-closure` 接入 fast/full/profile-deploy/package-release。需求:`bugs/runtime白名单闭包防复发修复`。

‎hooks/_runtime/lifecycle.cjs‎

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,25 +1521,37 @@ async function main() {
15211521
? findIncompleteTaskForPaths(payload, state)
15221522
: null
15231523
const bound = task || (typeof findIncompleteTask === 'function' ? findIncompleteTask(state) : null)
1524-
if (bound && bound.fullPath) {
1525-
const startGate = classifyImplementStartGate({
1526-
controlPlaneMutation: true,
1527-
taskRoot: bound.fullPath,
1528-
fs
1529-
})
1530-
if (!startGate.ok) {
1531-
const code = startGate.code || PROCESS_ENFORCEMENT_CODES.IMPLEMENT_START_WITHOUT_PROCESS
1532-
state.lastReason = code
1533-
saveState(state)
1534-
writeStdout(buildInterceptionOutput(
1535-
state, platform, eventName, INTERCEPTION_ACTION.REQUIRE_COMPLETION,
1536-
code,
1537-
'Implement process triad required',
1538-
`控制面 mutation 前须在任务目录齐备 04-实施计划.md + 05-实施进度.md + 复审清单(缺: ${(startGate.missing || []).join(', ')}):${bound.name || bound.fullPath}`,
1539-
'Create 04-实施计划.md, 05-实施进度.md, and 03-复审清单*.md under the active requirement before mutating hooks/skills/instructions.'
1540-
))
1541-
return
1524+
// Fail-closed when no bound task: was the loophole for skip-process after promising 概况/方案
1525+
const taskRoot = bound && bound.fullPath ? bound.fullPath : null
1526+
const startGate = classifyImplementStartGate({
1527+
controlPlaneMutation: true,
1528+
taskRoot,
1529+
fs
1530+
})
1531+
if (!startGate.ok) {
1532+
const code = startGate.code || PROCESS_ENFORCEMENT_CODES.IMPLEMENT_START_WITHOUT_PROCESS
1533+
state.lastReason = code
1534+
saveState(state)
1535+
let detail
1536+
let next
1537+
if (code === PROCESS_ENFORCEMENT_CODES.IMPLEMENT_START_WITHOUT_TASK_BINDING || startGate.unbound) {
1538+
detail = '控制面 mutation 必须绑定 active 需求/bug 任务目录(禁止无任务包直接改 hooks/scripts/instructions)。'
1539+
next = 'Create or resume a requirements/<name>/ package (00/01/02 + 04/05/checklist), bind the task, then retry the edit.'
1540+
} else if (code === PROCESS_ENFORCEMENT_CODES.IMPLEMENT_START_WITHOUT_DESIGN) {
1541+
detail = `控制面 mutation 前须有设计产物(缺: ${(startGate.missing || []).join(', ')})${bound ? `:${bound.name || bound.fullPath}` : ''}`
1542+
next = 'Write 00-需求概况/01-需求确认 and 02-技术方案 under the bound task, then 04/05/checklist, then mutate control-plane files.'
1543+
} else {
1544+
detail = `控制面 mutation 前须在任务目录齐备 04-实施计划.md + 05-实施进度.md + 复审清单(缺: ${(startGate.missing || []).join(', ')}):${bound ? (bound.name || bound.fullPath) : ''}`
1545+
next = 'Create 04-实施计划.md, 05-实施进度.md, and 03-复审清单*.md under the active requirement before mutating hooks/skills/instructions.'
15421546
}
1547+
writeStdout(buildInterceptionOutput(
1548+
state, platform, eventName, INTERCEPTION_ACTION.REQUIRE_COMPLETION,
1549+
code,
1550+
'Implement process gate required',
1551+
detail,
1552+
next
1553+
))
1554+
return
15431555
}
15441556
}
15451557
}

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"test:workspace-skill-intent": "node scripts/test-workspace-skill-intent.js",
118118
"test:workspace-skill-intent-e2e": "node scripts/test-workspace-skill-intent-e2e.js",
119119
"test:stop-gate": "node scripts/test-lifecycle-stop-gate.js && node scripts/test-r10-control-plane-honesty.js && node scripts/replay-stop-gate-hook-matrix.js && node scripts/test-process-enforcement-e2e.js && node scripts/test-delivery-honesty.js && node scripts/test-ecr-closure.js",
120-
"test:process-enforcement-e2e": "node scripts/test-process-enforcement-e2e.js",
120+
"test:process-enforcement-e2e": "node scripts/test-process-enforcement-e2e.js && node scripts/test-implement-start-gate.js",
121121
"test:docs-surface-inventory": "node scripts/test-docs-surface-inventory.js",
122122
"test:delivery-honesty": "node scripts/test-delivery-honesty.js",
123123
"test:ecr-closure": "node scripts/test-ecr-closure.js",
@@ -187,6 +187,7 @@
187187
"scripts/test-npm-lifecycle-adapter.js",
188188
"scripts/test-global-host-config.js",
189189
"scripts/test-skills-deploy-mode.js",
190+
"scripts/test-implement-start-gate.js",
190191
"scripts/lib/skills-deploy-mode.js",
191192
"scripts/test-global-host-runtime-verifier.js",
192193
"scripts/test-global-install-smoke.js",

‎scripts/lib/process-enforcement.js‎

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ const ERROR_CODES = Object.freeze({
2323
* yes-implement / Batch mutation must not skip CP3 materialization (ESC-01 / P0-1 process gate).
2424
*/
2525
IMPLEMENT_START_WITHOUT_PROCESS: 'implement-start-without-process',
26+
/**
27+
* Control-plane mutation with no bound requirement/bug task root.
28+
* Fail-closed so "do the feature" cannot mutate scripts/hooks without a task package
29+
* (promise-to-follow-process then skip was an unbound-task loophole).
30+
*/
31+
IMPLEMENT_START_WITHOUT_TASK_BINDING: 'implement-start-without-task-binding',
32+
/**
33+
* Control-plane mutation without CP1/CP2 design artifacts (01 需求确认 and/or 02 技术方案方案).
34+
*/
35+
IMPLEMENT_START_WITHOUT_DESIGN: 'implement-start-without-design',
2636
/** Completion claim without discoverable stage report path */
2737
STAGE_REPORT_MISSING: 'stage-report-missing',
2838
/** Over-claim progress without validation evidence rows */
@@ -281,6 +291,43 @@ function probeProcessTriad (taskRoot, fsys = null) {
281291
* }} input
282292
* @returns {{ ok: boolean, code: string|null, missing: string[], triad: object|null }}
283293
*/
294+
function listDirNames (root, fsImpl) {
295+
try {
296+
if (!fsImpl || typeof fsImpl.readdirSync !== 'function') return []
297+
return fsImpl.readdirSync(root)
298+
} catch {
299+
return []
300+
}
301+
}
302+
303+
function probeDesignArtifacts (taskRoot, fsImpl) {
304+
const fsx = fsImpl || { existsSync: () => false, readdirSync: () => [] }
305+
const names = listDirNames(taskRoot, fsx)
306+
const has01 = names.some(n =>
307+
/^01-.*需求确认/i.test(n) ||
308+
/^01-.*问题确认/i.test(n) ||
309+
/^01-.*产品需求/i.test(n) ||
310+
n === '01-需求确认.md' ||
311+
n === '01-问题确认.md'
312+
) || (fsx.existsSync && (
313+
fsx.existsSync(path.join(taskRoot, '01-需求确认.md')) ||
314+
fsx.existsSync(path.join(taskRoot, '01-问题确认.md'))
315+
))
316+
const has02 = names.some(n =>
317+
/^02-.*技术方案/i.test(n) ||
318+
n === '02-技术方案.md'
319+
) || (fsx.existsSync && fsx.existsSync(path.join(taskRoot, '02-技术方案.md')))
320+
const has00 = names.some(n =>
321+
/^00-.*概况/i.test(n) ||
322+
n === '00-需求概况.md' ||
323+
n === '00-问题概况.md'
324+
) || (fsx.existsSync && (
325+
fsx.existsSync(path.join(taskRoot, '00-需求概况.md')) ||
326+
fsx.existsSync(path.join(taskRoot, '00-问题概况.md'))
327+
))
328+
return { has00, has01, has02 }
329+
}
330+
284331
function classifyImplementStartGate (input = {}) {
285332
if (input.skip === true) {
286333
return { ok: true, code: null, missing: [], triad: null }
@@ -293,10 +340,18 @@ function classifyImplementStartGate (input = {}) {
293340
}
294341
const root = input.taskRoot
295342
if (!root) {
296-
// No bound task: cannot enforce triad; caller may still require task binding elsewhere
297-
return { ok: true, code: null, missing: [], triad: null, unbound: true }
343+
// Fail-closed: unbound control-plane mutation was the loophole for
344+
// "will follow process" then edit scripts/hooks without any requirement dir.
345+
return {
346+
ok: false,
347+
code: ERROR_CODES.IMPLEMENT_START_WITHOUT_TASK_BINDING,
348+
missing: ['bound-requirement-or-bug-task'],
349+
triad: null,
350+
unbound: true
351+
}
298352
}
299-
const triad = probeProcessTriad(root, input.fs || null)
353+
const fsImpl = input.fs || null
354+
const triad = probeProcessTriad(root, fsImpl)
300355
if (triad.missing.length) {
301356
return {
302357
ok: false,
@@ -305,6 +360,24 @@ function classifyImplementStartGate (input = {}) {
305360
triad
306361
}
307362
}
363+
// Control-plane / implement-start also need design artifacts (概况/确认/方案 at least 01+02 or 02)
364+
const requireDesign = input.requireDesignArtifacts !== false
365+
if (requireDesign && input.controlPlaneMutation === true) {
366+
const design = probeDesignArtifacts(root, fsImpl)
367+
const missingDesign = []
368+
if (!design.has02) missingDesign.push('02-技术方案.md')
369+
if (!design.has01 && !design.has00) missingDesign.push('00-概况-or-01-确认')
370+
// Prefer 02 always; also require 00 or 01 so pure-02 without product intake is not enough alone for full CP story
371+
if (!design.has02 || (!design.has01 && !design.has00)) {
372+
return {
373+
ok: false,
374+
code: ERROR_CODES.IMPLEMENT_START_WITHOUT_DESIGN,
375+
missing: missingDesign.length ? missingDesign : ['01-需求确认.md', '02-技术方案.md'],
376+
triad,
377+
design
378+
}
379+
}
380+
}
308381
return { ok: true, code: null, missing: [], triad }
309382
}
310383

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict'
2+
3+
/**
4+
* ImplementStartGate: unbound fail-closed + design artifacts for control-plane.
5+
* Prevents "will follow process" then mutate scripts/hooks without requirement package.
6+
*/
7+
8+
const assert = require('assert')
9+
const fs = require('fs')
10+
const os = require('os')
11+
const path = require('path')
12+
const {
13+
classifyImplementStartGate,
14+
ERROR_CODES
15+
} = require('./lib/process-enforcement.js')
16+
17+
// unbound control-plane → fail
18+
{
19+
const r = classifyImplementStartGate({ controlPlaneMutation: true, taskRoot: null })
20+
assert.strictEqual(r.ok, false)
21+
assert.strictEqual(r.code, ERROR_CODES.IMPLEMENT_START_WITHOUT_TASK_BINDING)
22+
assert.strictEqual(r.unbound, true)
23+
}
24+
25+
// skip still ok
26+
{
27+
const r = classifyImplementStartGate({ controlPlaneMutation: true, taskRoot: null, skip: true })
28+
assert.strictEqual(r.ok, true)
29+
}
30+
31+
// triad only, no 00/01/02 → design fail
32+
{
33+
const t = fs.mkdtempSync(path.join(os.tmpdir(), 'imp-triad-'))
34+
fs.writeFileSync(path.join(t, '04-实施计划.md'), '#')
35+
fs.writeFileSync(path.join(t, '05-实施进度.md'), '#')
36+
fs.writeFileSync(path.join(t, '03-复审清单.md'), '#')
37+
const r = classifyImplementStartGate({ controlPlaneMutation: true, taskRoot: t, fs })
38+
assert.strictEqual(r.ok, false)
39+
assert.strictEqual(r.code, ERROR_CODES.IMPLEMENT_START_WITHOUT_DESIGN)
40+
fs.rmSync(t, { recursive: true, force: true })
41+
}
42+
43+
// full package → ok
44+
{
45+
const t = fs.mkdtempSync(path.join(os.tmpdir(), 'imp-full-'))
46+
for (const name of [
47+
'00-需求概况.md',
48+
'01-需求确认.md',
49+
'02-技术方案.md',
50+
'04-实施计划.md',
51+
'05-实施进度.md',
52+
'03-复审清单.md'
53+
]) {
54+
fs.writeFileSync(path.join(t, name), '#\n')
55+
}
56+
const r = classifyImplementStartGate({ controlPlaneMutation: true, taskRoot: t, fs })
57+
assert.strictEqual(r.ok, true, JSON.stringify(r))
58+
fs.rmSync(t, { recursive: true, force: true })
59+
}
60+
61+
// non-control-plane → ok without task
62+
{
63+
const r = classifyImplementStartGate({ controlPlaneMutation: false, taskRoot: null })
64+
assert.strictEqual(r.ok, true)
65+
}
66+
67+
console.log('test-implement-start-gate: ok')

0 commit comments

Comments
 (0)