Skip to content

Commit 66662f4

Browse files
committed
feat: workspace skill intent route, DEVCODEX.md entry, and implement gate
1 parent cfcd36f commit 66662f4

11 files changed

Lines changed: 1586 additions & 39 deletions

‎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+
- **P0-1 工作区意图 + DEVCODEX.md + ImplementStartGate + e2e(Batch1)**:入口 `.devcodex/workspace/DEVCODEX.md`;`workspace-skill-intent` catalog/意图/lifecycle;控制面 mutation 前 04+05+复审清单门闩(`IMPLEMENT_START_WITHOUT_PROCESS`);全局 skill `workspace-skill-author`;`npm run test:workspace-skill-intent` / `test:workspace-skill-intent-e2e`(E2E-A~J+K)并入 `test:skill-resolve`。**无 e2e 不算 Batch1 完成**。需求:`开源发布前用户面与文档边界收口`。
78
- **联系邮箱统一为 `rockyshi1993@gmail.com`**:`package.json` author 与 `SECURITY.md` 漏洞报告邮箱一致(唯一可用邮箱)。
89
- **npm 包名为未 scope 的 `devcodex`**:安装入口 `npm install -g devcodex` / `npm update -g devcodex`;GitHub 组织仓与 npm 模块身份分离;`package.json` name=`devcodex`;撤销 `devcodex` 误绑。
910
pm install|update -g 对齐 devcodex; alidate-profile 识别 scoped 包名;修复正则字面量中 / 截断;managed deployment-manifest package 字段同步。
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
'use strict'
2+
3+
/**
4+
* DEVCODEX.md workspace entry — path locked under .devcodex/workspace/
5+
*/
6+
7+
const fs = require('fs')
8+
const path = require('path')
9+
const crypto = require('crypto')
10+
11+
const {
12+
findLayoutInfo
13+
} = require('./workspace-layout.cjs')
14+
15+
const MAX_ENTRY_BYTES = 24 * 1024
16+
const ENTRY_FILE = 'DEVCODEX.md'
17+
18+
const DEFAULT_TEMPLATE = `# DevCodex — 工作区入口
19+
20+
> 本文件给 AI/宿主阅读。人类安装说明见仓库 README.md。
21+
> 路径:\`.devcodex/workspace/DEVCODEX.md\`(与 \`skills/\` 并列)。
22+
23+
## 本仓约定
24+
25+
- (在此写短约束;勿粘贴完整全局内核)
26+
27+
## Skills
28+
29+
- 目录:\`./skills/<id>/SKILL.md\`
30+
- always-on:(可选,逗号分隔 skill id)
31+
32+
## 硬约束
33+
34+
- (短)
35+
`
36+
37+
function resolveWorkspaceRoot(cwdOrRoot, options = {}) {
38+
if (options.workspaceRoot) return path.resolve(options.workspaceRoot)
39+
const cwd = path.resolve(cwdOrRoot || options.cwd || process.cwd())
40+
const layout = typeof options.findLayoutInfo === 'function'
41+
? options.findLayoutInfo(cwd)
42+
: findLayoutInfo(cwd)
43+
if (layout && layout.enabled === true && String(layout.mode || '') === 'workspace-namespace') {
44+
return path.resolve(layout.workspaceRoot)
45+
}
46+
return null
47+
}
48+
49+
function resolveDevcodexMdPath(cwdOrRoot, options = {}) {
50+
const workspaceRoot = resolveWorkspaceRoot(cwdOrRoot, options)
51+
if (!workspaceRoot) return null
52+
return path.join(workspaceRoot, '.devcodex', 'workspace', ENTRY_FILE)
53+
}
54+
55+
function resolveWorkspaceSkillsDir(cwdOrRoot, options = {}) {
56+
const workspaceRoot = resolveWorkspaceRoot(cwdOrRoot, options)
57+
if (!workspaceRoot) return null
58+
return path.join(workspaceRoot, '.devcodex', 'workspace', 'skills')
59+
}
60+
61+
function sha256Text(text) {
62+
return crypto.createHash('sha256').update(String(text), 'utf8').digest('hex')
63+
}
64+
65+
function parseAlwaysOn(text) {
66+
const raw = String(text || '')
67+
const ids = []
68+
// always-on: a, b or always-on: a
69+
const lineRe = /always-on\s*:\s*([^\n\r]+)/gi
70+
let m
71+
while ((m = lineRe.exec(raw)) !== null) {
72+
const part = String(m[1] || '').trim()
73+
if (!part || part.startsWith('(') || part.startsWith('(')) continue
74+
for (const token of part.split(/[,,\s]+/)) {
75+
const id = token.trim().replace(/[`*]/g, '')
76+
if (id && /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(id) && !ids.includes(id)) ids.push(id)
77+
}
78+
}
79+
return ids
80+
}
81+
82+
/**
83+
* @returns {object} DevcodexMdEntryV1
84+
*/
85+
function readDevcodexMdEntry(cwdOrRoot, options = {}) {
86+
const fsImpl = options.fs || fs
87+
const maxBytes = options.maxBytes || MAX_ENTRY_BYTES
88+
const entryPath = resolveDevcodexMdPath(cwdOrRoot, options)
89+
const base = {
90+
schemaVersion: 'DevcodexMdEntryV1',
91+
path: entryPath,
92+
exists: false,
93+
truncated: false,
94+
content: '',
95+
digest: null,
96+
alwaysOn: [],
97+
markerPreview: '',
98+
bytes: 0
99+
}
100+
if (!entryPath) {
101+
return { ...base, path: null, reason: 'no-workspace-namespace' }
102+
}
103+
if (!fsImpl.existsSync(entryPath)) {
104+
return { ...base, reason: 'missing' }
105+
}
106+
let text = ''
107+
try {
108+
text = fsImpl.readFileSync(entryPath, 'utf8')
109+
} catch {
110+
return { ...base, reason: 'unreadable' }
111+
}
112+
const bytes = Buffer.byteLength(text, 'utf8')
113+
let truncated = false
114+
if (bytes > maxBytes) {
115+
// keep head only
116+
let cut = text
117+
while (Buffer.byteLength(cut, 'utf8') > maxBytes && cut.length > 0) {
118+
cut = cut.slice(0, Math.floor(cut.length * 0.9))
119+
}
120+
text = `${cut}\n\n…[truncated for DEVCODEX.md budget]\n`
121+
truncated = true
122+
}
123+
const alwaysOn = parseAlwaysOn(text)
124+
const firstLine = text.split(/\r?\n/).map(l => l.trim()).find(l => l && !l.startsWith('#')) || ''
125+
return {
126+
...base,
127+
exists: true,
128+
truncated,
129+
content: text,
130+
digest: sha256Text(text),
131+
alwaysOn,
132+
markerPreview: firstLine.slice(0, 120),
133+
bytes: Buffer.byteLength(text, 'utf8'),
134+
reason: truncated ? 'truncated' : 'ok'
135+
}
136+
}
137+
138+
function ensureDevcodexMdTemplate(cwdOrRoot, options = {}) {
139+
const fsImpl = options.fs || fs
140+
const entryPath = resolveDevcodexMdPath(cwdOrRoot, options)
141+
const skillsDir = resolveWorkspaceSkillsDir(cwdOrRoot, options)
142+
if (!entryPath || !skillsDir) {
143+
return { ok: false, created: false, path: entryPath, reason: 'no-workspace-namespace' }
144+
}
145+
if (options.dryRun) {
146+
return {
147+
ok: true,
148+
created: !fsImpl.existsSync(entryPath),
149+
planned: true,
150+
path: entryPath,
151+
skillsDir
152+
}
153+
}
154+
fsImpl.mkdirSync(skillsDir, { recursive: true })
155+
if (fsImpl.existsSync(entryPath)) {
156+
return { ok: true, created: false, path: entryPath, skillsDir, reason: 'exists' }
157+
}
158+
fsImpl.writeFileSync(entryPath, DEFAULT_TEMPLATE, 'utf8')
159+
return { ok: true, created: true, path: entryPath, skillsDir }
160+
}
161+
162+
function buildEntryInjection(entry) {
163+
if (!entry || !entry.exists || !entry.content) return ''
164+
return [
165+
'### DevCodex · Workspace entry (DEVCODEX.md)',
166+
`path: ${entry.path}`,
167+
entry.alwaysOn.length ? `alwaysOn: ${entry.alwaysOn.join(', ')}` : 'alwaysOn: (none)',
168+
'',
169+
'----- BEGIN DEVCODEX.md -----',
170+
entry.content.trim(),
171+
'----- END DEVCODEX.md -----'
172+
].join('\n')
173+
}
174+
175+
module.exports = {
176+
MAX_ENTRY_BYTES,
177+
ENTRY_FILE,
178+
DEFAULT_TEMPLATE,
179+
resolveWorkspaceRoot,
180+
resolveDevcodexMdPath,
181+
resolveWorkspaceSkillsDir,
182+
readDevcodexMdEntry,
183+
ensureDevcodexMdTemplate,
184+
parseAlwaysOn,
185+
buildEntryInjection,
186+
sha256Text
187+
}

‎hooks/_runtime/lifecycle.cjs‎

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const {
6565
classifyPathsForArtifacts,
6666
isStrictProtectedPath,
6767
simpleTaskForbidsPath,
68+
classifyImplementStartGate,
6869
ERROR_CODES: PROCESS_ENFORCEMENT_CODES
6970
} = require('../../scripts/lib/process-enforcement.js')
7071

@@ -1347,23 +1348,28 @@ async function main() {
13471348
}
13481349
}
13491350
}
1350-
// P0.5 WorkspaceSkillAutoMatch: message → W skill description/name → inject body
1351-
let workspaceSkillAutoMatchMsg = ''
1351+
// P0-1 WorkspaceSkillIntent (default) or legacy AutoMatch via DEVCODEX_SKILL_MATCH_MODE
1352+
let workspaceSkillRouteMsg = ''
13521353
try {
13531354
const {
1354-
matchWorkspaceSkills,
1355-
toStateRecord
1356-
} = require('./workspace-skill-auto-match.cjs')
1357-
const autoMatch = matchWorkspaceSkills(prompt, { cwd: CONTEXT_ROOT })
1358-
if (autoMatch.matched) {
1359-
state.workspaceSkillAutoMatch = toStateRecord(autoMatch)
1360-
workspaceSkillAutoMatchMsg = autoMatch.injectionText
1361-
state.lastReason = `workspace-skill-auto-match:${autoMatch.skillId}`
1355+
routeWorkspaceSkillIntent,
1356+
toIntentStateRecord,
1357+
getSkillMatchMode
1358+
} = require('./workspace-skill-intent.cjs')
1359+
const route = routeWorkspaceSkillIntent(prompt, { cwd: CONTEXT_ROOT })
1360+
const mode = getSkillMatchMode()
1361+
if (route.injectionText) {
1362+
state.workspaceSkillAutoMatch = toIntentStateRecord(route)
1363+
// keep legacy field name for Stop path compatibility
1364+
workspaceSkillRouteMsg = route.injectionText
1365+
state.lastReason = route.matched
1366+
? `workspace-skill-intent:${route.skillId}`
1367+
: (mode === 'legacy-token' ? 'workspace-skill-catalog-only' : 'workspace-skill-intent-catalog')
13621368
} else {
13631369
state.workspaceSkillAutoMatch = null
13641370
}
13651371
} catch {
1366-
/* auto-match optional during partial deploys */
1372+
/* intent/auto-match optional during partial deploys */
13671373
state.workspaceSkillAutoMatch = null
13681374
}
13691375

@@ -1378,7 +1384,7 @@ async function main() {
13781384
: '',
13791385
buildGovernanceIntakeContextMessage(state.governanceIntake),
13801386
formatTurnRecoveryMessage(livenessObservation.recoveryCard),
1381-
workspaceSkillAutoMatchMsg
1387+
workspaceSkillRouteMsg
13821388
].filter(Boolean).join('\n\n')
13831389
))
13841390
return
@@ -1502,7 +1508,8 @@ async function main() {
15021508
}
15031509
}
15041510

1505-
// 2.7 E: plan without progress forbids control-plane source mutation (delivery honesty H1)
1511+
// 2.7 E: implement-start gate — control-plane mutation needs 04+05+复审清单 triad
1512+
// (P0-1 / ESC-01: yes-implement must not skip CP3 materialization)
15061513
if (
15071514
isSourceCodeMutation(payload, platform, state) &&
15081515
!(state.simpleTaskFastPath === true || state.taskPathMode === 'simple')
@@ -1514,17 +1521,22 @@ async function main() {
15141521
? findIncompleteTaskForPaths(payload, state)
15151522
: null
15161523
const bound = task || (typeof findIncompleteTask === 'function' ? findIncompleteTask(state) : null)
1517-
if (bound && bound.fullPath && hasTaskArtifact(bound, 'CP3')) {
1518-
const progressPath = path.join(bound.fullPath, '05-实施进度.md')
1519-
if (!fs.existsSync(progressPath)) {
1520-
state.lastReason = PROCESS_ENFORCEMENT_CODES.PROGRESS_ARTIFACT_MISSING || 'progress-artifact-missing'
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
15211533
saveState(state)
15221534
writeStdout(buildInterceptionOutput(
15231535
state, platform, eventName, INTERCEPTION_ACTION.REQUIRE_COMPLETION,
1524-
'progress-artifact-missing',
1525-
'Progress artifact required',
1526-
`控制面 mutation 需要任务目录 05-实施进度.md(已有 04 实施计划):${bound.name || bound.fullPath}`,
1527-
'Create 05-实施进度.md under the active requirement before mutating control-plane sources.'
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.'
15281540
))
15291541
return
15301542
}
@@ -1641,19 +1653,17 @@ async function main() {
16411653
if (eventName === 'PreCompact') markContextAcquisitionStale(state, 'compact')
16421654
captureFinalPayloadSample(payload, eventName, state)
16431655

1644-
// P0.5: if UserPromptSubmit matched a W skill and reply ignored it, Stop-force one retry.
1645-
// Inject-capable hosts already got additionalContext; Grok passive UPS needs Stop block.
1656+
// P0-1: if UPS matched a W skill via intent and reply ignored it, Stop-force one retry.
16461657
if (eventName === 'Stop' && state.workspaceSkillAutoMatch && state.workspaceSkillAutoMatch.skillId) {
16471658
try {
16481659
const {
1649-
isSkillReplySatisfied,
1650-
buildStopForceReason,
1651-
matchWorkspaceSkills,
1652-
extractLastAssistantMessage
1653-
} = require('./workspace-skill-auto-match.cjs')
1660+
isIntentReplySatisfied,
1661+
buildIntentStopForceReason,
1662+
extractLastAssistantMessage,
1663+
routeWorkspaceSkillIntent
1664+
} = require('./workspace-skill-intent.cjs')
16541665
const lastAssistant = extractLastAssistantMessage(payload)
16551666
const stopHookActive = payload.stopHookActive === true || payload.stop_hook_active === true
1656-
// Rehydrate content for satisfaction check when state only kept meta
16571667
let matchForCheck = state.workspaceSkillAutoMatch
16581668
if (!matchForCheck.content && matchForCheck.injectionText) {
16591669
matchForCheck = {
@@ -1663,39 +1673,44 @@ async function main() {
16631673
content: matchForCheck.injectionText,
16641674
injectionText: matchForCheck.injectionText
16651675
}
1666-
} else if (!matchForCheck.injectionText) {
1667-
const rematch = matchWorkspaceSkills(matchForCheck.skillId, { cwd: CONTEXT_ROOT })
1676+
} else if (!matchForCheck.injectionText && matchForCheck.skillId) {
1677+
const rematch = routeWorkspaceSkillIntent(matchForCheck.skillId, { cwd: CONTEXT_ROOT })
16681678
if (rematch.matched) {
1669-
matchForCheck = { ...matchForCheck, ...rematch, matched: true }
1679+
matchForCheck = {
1680+
matched: true,
1681+
skillId: rematch.skillId,
1682+
mustReply: rematch.mustReply,
1683+
content: rematch.content,
1684+
injectionText: rematch.injectionText
1685+
}
16701686
} else {
16711687
matchForCheck = { ...matchForCheck, matched: true }
16721688
}
16731689
} else {
16741690
matchForCheck = { ...matchForCheck, matched: true }
16751691
}
16761692

1677-
const satisfied = isSkillReplySatisfied(lastAssistant, matchForCheck)
1693+
const satisfied = isIntentReplySatisfied(lastAssistant, matchForCheck)
16781694
if (satisfied) {
16791695
state.workspaceSkillAutoMatch = {
16801696
...state.workspaceSkillAutoMatch,
16811697
satisfied: true
16821698
}
16831699
} else {
16841700
const enforceCount = Number(state.workspaceSkillAutoMatch.enforceCount || 0)
1685-
// At most 2 force rounds; honor platform soft cap via stopHookActive after first force
16861701
if (enforceCount < 2 && !(stopHookActive && enforceCount >= 1)) {
1687-
const reason = buildStopForceReason(matchForCheck)
1702+
const reason = buildIntentStopForceReason(matchForCheck)
16881703
state.workspaceSkillAutoMatch = {
16891704
...state.workspaceSkillAutoMatch,
16901705
enforceCount: enforceCount + 1,
16911706
lastEnforceAt: new Date().toISOString()
16921707
}
1693-
state.lastReason = `workspace-skill-auto-match-stop:${state.workspaceSkillAutoMatch.skillId}`
1708+
state.lastReason = `workspace-skill-intent-stop:${state.workspaceSkillAutoMatch.skillId}`
16941709
const output = decorateHookOutput(
1695-
blockOutput(platform, 'Stop', 'workspace-skill-auto-match', reason),
1710+
blockOutput(platform, 'Stop', 'workspace-skill-intent', reason),
16961711
{
16971712
devcodexAction: INTERCEPTION_ACTION.FORBID,
1698-
devcodexCode: 'workspace-skill-auto-match',
1713+
devcodexCode: 'workspace-skill-intent',
16991714
devcodexEffective: true,
17001715
devcodexNextStep: 'Reply following the matched workspace skill body.'
17011716
}

0 commit comments

Comments
 (0)