Skip to content

Commit 4a2b17c

Browse files
committed
feat: init DEVCODEX.md template and skill intent CLI (Batch2)
1 parent 66662f4 commit 4a2b17c

4 files changed

Lines changed: 77 additions & 7 deletions

File tree

‎changelogs/unreleased.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
## 当前未发布实现候选
77
- **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 完成**。需求:`开源发布前用户面与文档边界收口`。
8+
- **P0-1 Batch2**:`init`/`ensureRuntimeDirs` 写入 DEVCODEX.md 模板(不覆盖);CLI `devcodex skill intent <prompt> [--json]`;help 文案同步。
89
- **联系邮箱统一为 `rockyshi1993@gmail.com`**:`package.json` author 与 `SECURITY.md` 漏洞报告邮箱一致(唯一可用邮箱)。
910
- **npm 包名为未 scope 的 `devcodex`**:安装入口 `npm install -g devcodex` / `npm update -g devcodex`;GitHub 组织仓与 npm 模块身份分离;`package.json` name=`devcodex`;撤销 `devcodex` 误绑。
1011
pm install|update -g 对齐 devcodex; alidate-profile 识别 scoped 包名;修复正则字面量中 / 截断;managed deployment-manifest package 字段同步。

‎scripts/lib/cli-execution-commands.js‎

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ function buildCliExecutionCommands(ctx) {
323323
} else if (arg.startsWith('-')) options.errors.push(`unsupported option: ${arg}`)
324324
else options.candidateIds.push(arg)
325325
}
326-
if (!['plan', 'resolve', 'match'].includes(options.action)) {
326+
if (!['plan', 'resolve', 'match', 'intent'].includes(options.action)) {
327327
options.errors.push(`unknown skill subcommand: ${options.action || '(none)'}`)
328328
}
329329
if (options.action === 'plan' && !options.candidateIds.length) {
@@ -332,16 +332,18 @@ function buildCliExecutionCommands(ctx) {
332332
if (options.action === 'resolve' && !options.candidateIds.length) {
333333
options.errors.push('at least one skill id is required for resolve')
334334
}
335-
if (options.action === 'match' && !options.candidateIds.length) {
336-
options.errors.push('match requires a user prompt string (quote multi-word prompts)')
335+
if ((options.action === 'match' || options.action === 'intent') && !options.candidateIds.length) {
336+
options.errors.push(`${options.action} requires a user prompt string (quote multi-word prompts)`)
337337
}
338338
return options
339339
}
340340

341341
function printSkillFailure(options, errorCode, message, nextStep, details, exitCode) {
342342
const operation = options.action === 'match'
343343
? 'skill.match'
344-
: (options.action === 'resolve' ? 'skill.resolve' : 'skill.plan')
344+
: (options.action === 'intent'
345+
? 'skill.intent'
346+
: (options.action === 'resolve' ? 'skill.resolve' : 'skill.plan'))
345347
if (options.json) printCliJson(console, createCliFailure(operation, errorCode, message, nextStep, cliMetadata, details))
346348
else {
347349
console.log(c.red(` [${errorCode}] ${message}`))
@@ -396,6 +398,64 @@ function buildCliExecutionCommands(ctx) {
396398
return publicResult
397399
}
398400

401+
function cmdSkillIntent(options) {
402+
let routeWorkspaceSkillIntent
403+
try {
404+
;({ routeWorkspaceSkillIntent } = require('../../hooks/_runtime/workspace-skill-intent.cjs'))
405+
} catch (error) {
406+
printSkillFailure(options, 'SKILL_INTENT_UNAVAILABLE', error.message, 'Reinstall DevCodex runtime hooks and retry.', null, 1)
407+
return null
408+
}
409+
const prompt = options.candidateIds.join(' ')
410+
const result = routeWorkspaceSkillIntent(prompt, {
411+
cwd: process.cwd(),
412+
consumerAuthority: 'cli'
413+
})
414+
const publicResult = {
415+
mode: result.mode,
416+
matched: result.matched,
417+
skillId: result.skillId,
418+
decision: result.decision,
419+
mustReply: result.mustReply,
420+
selectedLayer: result.selectedLayer,
421+
selectedPath: result.selectedPath,
422+
digest: result.digest,
423+
alwaysOn: result.alwaysOn,
424+
catalogDigest: result.catalog && result.catalog.digest,
425+
entryExists: result.entry && result.entry.exists,
426+
content: options.json ? result.content : undefined,
427+
injectionText: options.json
428+
? result.injectionText
429+
: (result.injectionText ? '[present; use --json for full inject text]' : '')
430+
}
431+
if (options.json) {
432+
printCliJson(console, {
433+
schemaVersion: 'DevCodexCliEnvelopeV1',
434+
operation: 'skill.intent',
435+
ok: true,
436+
result: options.json ? result : publicResult
437+
})
438+
} else {
439+
console.log()
440+
console.log(c.bold(' DevCodex WorkspaceSkillIntent'))
441+
console.log(` ${c.cyan('prompt'.padEnd(16))} ${prompt}`)
442+
console.log(` ${c.cyan('mode'.padEnd(16))} ${result.mode}`)
443+
console.log(` ${c.cyan('matched'.padEnd(16))} ${result.matched}`)
444+
console.log(` ${c.cyan('skillId'.padEnd(16))} ${result.skillId || '(none)'}`)
445+
console.log(` ${c.cyan('source'.padEnd(16))} ${(result.decision && result.decision.source) || '(none)'}`)
446+
console.log(` ${c.cyan('score'.padEnd(16))} ${result.decision && result.decision.score != null ? result.decision.score : '(n/a)'}`)
447+
console.log(` ${c.cyan('layer'.padEnd(16))} ${result.selectedLayer || '(none)'}`)
448+
console.log(` ${c.cyan('mustReply'.padEnd(16))} ${result.mustReply || '(none)'}`)
449+
console.log(` ${c.cyan('reasons'.padEnd(16))} ${((result.decision && result.decision.reasons) || []).join(', ') || '(none)'}`)
450+
console.log(` ${c.cyan('entry'.padEnd(16))} ${result.entry && result.entry.exists ? 'DEVCODEX.md ok' : 'missing'}`)
451+
console.log(c.dim(' default route: catalog + intent; legacy: DEVCODEX_SKILL_MATCH_MODE=legacy-token'))
452+
console.log(c.dim(' closed-loop: UPS inject + Stop force when matched skill ignored'))
453+
console.log()
454+
}
455+
process.exitCode = 0
456+
return publicResult
457+
}
458+
399459
function cmdSkillResolve(options) {
400460
let resolveSkillReadPlan
401461
try {
@@ -458,14 +518,15 @@ function buildCliExecutionCommands(ctx) {
458518
options,
459519
'CLI_INVALID_OPTION',
460520
options.errors.join('; '),
461-
'Use: devcodex skill plan <candidate...> | skill resolve <id...> | skill match <prompt...> [--json]',
521+
'Use: devcodex skill plan <candidate...> | skill resolve <id...> | skill match <prompt...> | skill intent <prompt...> [--json]',
462522
{ errors: options.errors },
463523
2
464524
)
465525
return null
466526
}
467527
if (options.action === 'resolve') return cmdSkillResolve(options)
468528
if (options.action === 'match') return cmdSkillMatch(options)
529+
if (options.action === 'intent') return cmdSkillIntent(options)
469530
let portfolio
470531
try {
471532
portfolio = readSkillPortfolio()

‎scripts/lib/cli-maintenance-commands.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ function buildCliMaintenanceCommands(ctx) {
853853
const mod = workspaceSkills.autoMatchModule ? 'AutoMatch module OK' : 'AutoMatch module missing'
854854
console.log(` workspace skills: ${c.cyan(String(workspaceSkills.count || 0))} ${c.dim(`enabled=${workspaceSkills.enabled !== false}; ${mod}`)}`)
855855
console.log(c.dim(` W root: ${workspaceSkills.root || '(none)'} · ids: ${ids}`))
856-
console.log(c.dim(' diagnose: devcodex skill match "<prompt>" · skill resolve <id> · npm run test:skill-automatch-accept'))
856+
console.log(c.dim(' diagnose: devcodex skill intent "<prompt>" · skill match "<prompt>" · skill resolve <id> · npm run test:workspace-skill-intent-e2e'))
857857
}
858858
console.log()
859859
console.log(c.bold(' User-global host adapters:'))
@@ -1031,7 +1031,8 @@ function buildCliMaintenanceCommands(ctx) {
10311031
${c.cyan('trace show|replay')} Read LocalTaskTrace; trace show --completion reads receipt identities
10321032
${c.cyan('skill plan')} Plan a dependency-closed whole-SKILL bundle; add --json for BundleDecisionV2
10331033
${c.cyan('skill resolve')} Resolve skill ids W>G (workspace skills vs global); --json
1034-
${c.cyan('skill match')} Auto-match user prompt to workspace skill (P0.5 closed loop); --json
1034+
${c.cyan('skill intent')} Intent-route prompt → workspace skill (default catalog path); --json
1035+
${c.cyan('skill match')} Legacy token auto-match (P0.5); prefer skill intent; --json
10351036
${c.cyan('task resolve')} Resolve an active task by exact name, alias, project, or stable taskId
10361037
${c.cyan('task verify')} Reconcile one task; exact --task or unique-active fallback
10371038
${c.cyan('task risk')} Accept/revoke explicit, candidate-bound waivable risk

‎scripts/lib/cli-runtime-utils.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ function buildCliRuntimeUtils({
115115
fs.mkdirSync(path.join(runtimeRoot, '.memory'), { recursive: true })
116116
fs.mkdirSync(path.join(runtimeRoot, '.audit-state'), { recursive: true })
117117
ensureRuntimeDataTemplates(runtimeRoot, dryRun)
118+
// P0-1: workspace entry + skills dir under .devcodex/workspace/
119+
try {
120+
const { ensureDevcodexMdTemplate } = require('../../hooks/_runtime/devcodex-md-entry.cjs')
121+
ensureDevcodexMdTemplate(cwd, { dryRun: false })
122+
} catch {
123+
/* layout not ready or optional during partial installs */
124+
}
118125
return runtimeRoot
119126
}
120127

0 commit comments

Comments
 (0)