cc-devflow 2.4.6 → 4.1.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/CLAUDE.md +1065 -48
- package/.claude/agents/dev-implementer.md +195 -0
- package/.claude/commands/{flow-archive.md → flow/archive.md} +46 -11
- package/.claude/commands/flow/context.md +150 -0
- package/.claude/commands/flow/delta.md +245 -0
- package/.claude/commands/{flow-dev.md → flow/dev.md} +112 -11
- package/.claude/commands/flow/init.md +45 -0
- package/.claude/commands/flow/quality.md +159 -0
- package/.claude/commands/flow/spec.md +186 -0
- package/.claude/commands/flow/workspace.md +146 -0
- package/.claude/commands/{cancel-ralph.md → util/cancel-ralph.md} +1 -0
- package/.claude/config/quality-gates.yml +305 -0
- package/.claude/docs/guides/TEAM_MODE_GUIDE.md +313 -0
- package/.claude/docs/templates/DELTA_SPEC_TEMPLATE.md +91 -0
- package/.claude/docs/templates/DESIGN_DECISIONS_TEMPLATE.md +151 -0
- package/.claude/docs/templates/JOURNAL_TEMPLATE.md +75 -0
- package/.claude/docs/templates/_shared/CLAUDE.md +36 -0
- package/.claude/docs/templates/_shared/CONSTITUTION_CHECK.md +125 -0
- package/.claude/docs/templates/_shared/VALIDATION_CHECKLIST.md +187 -0
- package/.claude/docs/templates/_shared/YAML_FRONTMATTER.md +164 -0
- package/.claude/docs/templates/context/dev.jsonl.template +6 -0
- package/.claude/docs/templates/context/epic.jsonl.template +5 -0
- package/.claude/docs/templates/context/prd.jsonl.template +4 -0
- package/.claude/docs/templates/context/research.jsonl.template +4 -0
- package/.claude/docs/templates/context/review.jsonl.template +5 -0
- package/.claude/docs/templates/context/tech.jsonl.template +5 -0
- package/.claude/hooks/CLAUDE.md +342 -0
- package/.claude/hooks/inject-agent-context.ts +480 -0
- package/.claude/hooks/inject-skill-context.ts +359 -0
- package/.claude/hooks/ralph-loop.ts +931 -0
- package/.claude/hooks/task-completed-hook.ts +593 -0
- package/.claude/hooks/teammate-idle-hook.ts +690 -0
- package/.claude/hooks/types/team-types.d.ts +238 -0
- package/.claude/rules/devflow-conventions.md +82 -9
- package/.claude/scripts/archive-requirement.sh +44 -1
- package/.claude/scripts/common.sh +670 -3
- package/.claude/scripts/delta-parser.ts +527 -0
- package/.claude/scripts/detect-file-conflicts.sh +151 -0
- package/.claude/scripts/flow-context-add.sh +134 -0
- package/.claude/scripts/flow-context-init.sh +133 -0
- package/.claude/scripts/flow-context-validate.sh +144 -0
- package/.claude/scripts/flow-delta-apply.sh +297 -0
- package/.claude/scripts/flow-delta-archive.sh +71 -0
- package/.claude/scripts/flow-delta-create.sh +202 -0
- package/.claude/scripts/flow-delta-list.sh +142 -0
- package/.claude/scripts/flow-delta-status.sh +235 -0
- package/.claude/scripts/flow-quality-full.sh +184 -0
- package/.claude/scripts/flow-quality-quick.sh +64 -0
- package/.claude/scripts/flow-workspace-init.sh +117 -0
- package/.claude/scripts/flow-workspace-record.sh +164 -0
- package/.claude/scripts/flow-workspace-start.sh +88 -0
- package/.claude/scripts/get-workflow-status.sh +415 -0
- package/.claude/scripts/parse-task-dependencies.js +334 -0
- package/.claude/scripts/record-quality-error.sh +165 -0
- package/.claude/scripts/run-quality-gates.sh +242 -0
- package/.claude/scripts/team-dev-init.sh +319 -0
- package/.claude/scripts/team-state-recovery.sh +229 -0
- package/.claude/scripts/workflow-status.ts +433 -0
- package/.claude/settings.json +19 -0
- package/.claude/skills/cc-devflow-orchestrator/SKILL.md +85 -200
- package/.claude/skills/domain/using-git-worktrees/SKILL.md +252 -0
- package/.claude/skills/domain/using-git-worktrees/assets/SHELL_ALIASES.md +133 -0
- package/.claude/skills/domain/using-git-worktrees/context.jsonl +4 -0
- package/.claude/skills/domain/using-git-worktrees/scripts/worktree-cleanup.sh +218 -0
- package/.claude/skills/domain/using-git-worktrees/scripts/worktree-create.sh +232 -0
- package/.claude/skills/domain/using-git-worktrees/scripts/worktree-list.sh +130 -0
- package/.claude/skills/domain/using-git-worktrees/scripts/worktree-status.sh +140 -0
- package/.claude/skills/domain/using-git-worktrees/scripts/worktree-switch.sh +70 -0
- package/.claude/skills/skill-rules.json +72 -1
- package/.claude/skills/utility/journey-checker/SKILL.md +199 -0
- package/.claude/skills/utility/journey-checker/pressure-scenarios.md +164 -0
- package/.claude/skills/utility/skill-creator/LICENSE.txt +202 -0
- package/.claude/skills/utility/skill-creator/SKILL.md +356 -0
- package/.claude/skills/utility/skill-creator/references/output-patterns.md +82 -0
- package/.claude/skills/utility/skill-creator/references/workflows.md +28 -0
- package/.claude/skills/utility/skill-creator/scripts/init_skill.py +303 -0
- package/.claude/skills/utility/skill-creator/scripts/package_skill.py +110 -0
- package/.claude/skills/utility/skill-creator/scripts/quick_validate.py +95 -0
- package/.claude/skills/workflow/flow-dev/CLAUDE.md +78 -0
- package/.claude/skills/workflow/flow-dev/SKILL.md +96 -0
- package/.claude/skills/workflow/flow-dev/assets/IMPLEMENTATION_PLAN_TEMPLATE.md +71 -0
- package/.claude/skills/workflow/flow-dev/context.jsonl +8 -0
- package/.claude/skills/workflow/flow-dev/dev-implementer.jsonl +8 -0
- package/.claude/skills/workflow/flow-dev/scripts/entry-gate.sh +116 -0
- package/.claude/skills/workflow/flow-dev/scripts/exit-gate.sh +101 -0
- package/.claude/skills/workflow/flow-dev/scripts/task-orchestrator.sh +106 -0
- package/.claude/skills/workflow/flow-fix/SKILL.md +105 -0
- package/.claude/skills/workflow/flow-fix/context.jsonl +6 -0
- package/.claude/skills/workflow/flow-fix/references/bug-analyzer.md +381 -0
- package/.claude/skills/workflow/flow-init/SKILL.md +211 -0
- package/.claude/skills/workflow/flow-init/assets/BRAINSTORM_TEMPLATE.md +148 -0
- package/.claude/skills/workflow/flow-init/assets/INIT_FLOW_TEMPLATE.md +198 -0
- package/.claude/skills/workflow/flow-init/assets/RESEARCH_TEMPLATE.md +276 -0
- package/.claude/skills/workflow/flow-init/context.jsonl +5 -0
- package/.claude/skills/workflow/flow-init/references/flow-researcher.md +132 -0
- package/.claude/skills/workflow/flow-init/scripts/check-prerequisites.sh +232 -0
- package/.claude/skills/workflow/flow-init/scripts/consolidate-research.sh +182 -0
- package/.claude/skills/workflow/flow-init/scripts/create-requirement.sh +515 -0
- package/.claude/skills/workflow/flow-init/scripts/generate-research-tasks.sh +157 -0
- package/.claude/skills/workflow/flow-init/scripts/populate-research-tasks.sh +284 -0
- package/.claude/skills/workflow/flow-init/scripts/validate-research.sh +332 -0
- package/.claude/skills/workflow/flow-quality/SKILL.md +94 -0
- package/.claude/skills/workflow/flow-quality/context.jsonl +6 -0
- package/.claude/skills/workflow/flow-quality/references/code-quality-reviewer.md +205 -0
- package/.claude/skills/workflow/flow-quality/references/qa-tester.md +313 -0
- package/.claude/skills/workflow/flow-quality/references/security-reviewer.md +314 -0
- package/.claude/skills/workflow/flow-quality/references/spec-reviewer.md +221 -0
- package/.claude/skills/workflow/flow-release/SKILL.md +126 -0
- package/.claude/skills/workflow/flow-release/context.jsonl +7 -0
- package/.claude/skills/workflow/flow-release/references/release-manager.md +295 -0
- package/.claude/skills/workflow/flow-spec/CLAUDE.md +103 -0
- package/.claude/skills/workflow/flow-spec/SKILL.md +545 -0
- package/.claude/skills/workflow/flow-spec/context.jsonl +7 -0
- package/.claude/skills/workflow/flow-spec/scripts/entry-gate.sh +194 -0
- package/.claude/skills/workflow/flow-spec/scripts/exit-gate.sh +244 -0
- package/.claude/skills/workflow/flow-spec/scripts/parallel-orchestrator.sh +205 -0
- package/.claude/skills/workflow/flow-spec/scripts/team-communication.sh +353 -0
- package/.claude/skills/workflow/flow-spec/scripts/team-init.sh +195 -0
- package/.claude/skills/workflow/flow-spec/scripts/test-team-mode.sh +496 -0
- package/.claude/skills/workflow/flow-spec/team-config.json +165 -0
- package/.claude/skills/workflow.yaml +417 -0
- package/CHANGELOG.md +254 -0
- package/README.md +193 -33
- package/README.zh-CN.md +206 -46
- package/lib/compiler/CLAUDE.md +77 -46
- package/lib/compiler/__tests__/multi-module-emitters.test.js +508 -0
- package/lib/compiler/context-expander.js +179 -0
- package/lib/compiler/emitters/antigravity-emitter.js +195 -5
- package/lib/compiler/emitters/base-emitter.js +217 -2
- package/lib/compiler/emitters/codex-emitter.js +200 -4
- package/lib/compiler/emitters/cursor-emitter.js +307 -3
- package/lib/compiler/emitters/qwen-emitter.js +196 -4
- package/lib/compiler/index.js +197 -2
- package/lib/compiler/platforms.js +270 -21
- package/package.json +1 -1
- package/.claude/commands/flow-epic.md +0 -183
- package/.claude/commands/flow-init.md +0 -370
- package/.claude/commands/flow-prd.md +0 -144
- package/.claude/commands/flow-qa.md +0 -93
- package/.claude/commands/flow-review.md +0 -257
- package/.claude/commands/flow-tech.md +0 -142
- package/.claude/commands/flow-ui.md +0 -189
- package/.claude/skills/file-header-guardian/SKILL.md +0 -56
- package/.claude/skills/skill-developer/ADVANCED.md +0 -197
- package/.claude/skills/skill-developer/HOOK_MECHANISMS.md +0 -306
- package/.claude/skills/skill-developer/PATTERNS_LIBRARY.md +0 -152
- package/.claude/skills/skill-developer/SKILL.md +0 -426
- package/.claude/skills/skill-developer/SKILL_RULES_REFERENCE.md +0 -315
- package/.claude/skills/skill-developer/TRIGGER_TYPES.md +0 -305
- package/.claude/skills/skill-developer/TROUBLESHOOTING.md +0 -514
- package/.claude/skills/writing-skills/SKILL.md +0 -655
- package/.claude/skills/writing-skills/anthropic-best-practices.md +0 -1150
- package/.claude/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +0 -189
- package/.claude/skills/writing-skills/graphviz-conventions.dot +0 -172
- package/.claude/skills/writing-skills/persuasion-principles.md +0 -187
- package/.claude/skills/writing-skills/render-graphs.js +0 -168
- package/.claude/skills/writing-skills/testing-skills-with-subagents.md +0 -384
- package/.claude/tsc-cache/795ba6e3-b98a-423b-bab2-51aa62812569/affected-repos.txt +0 -1
- package/.claude/tsc-cache/ae335694-be5a-4ba4-a1a0-b676c09a7906/affected-repos.txt +0 -1
- /package/.claude/commands/{core-architecture.md → core/architecture.md} +0 -0
- /package/.claude/commands/{core-guidelines.md → core/guidelines.md} +0 -0
- /package/.claude/commands/{core-roadmap.md → core/roadmap.md} +0 -0
- /package/.claude/commands/{core-style.md → core/style.md} +0 -0
- /package/.claude/commands/{flow-checklist.md → flow/checklist.md} +0 -0
- /package/.claude/commands/{flow-clarify.md → flow/clarify.md} +0 -0
- /package/.claude/commands/{flow-constitution.md → flow/constitution.md} +0 -0
- /package/.claude/commands/{flow-fix.md → flow/fix.md} +0 -0
- /package/.claude/commands/{flow-ideate.md → flow/ideate.md} +0 -0
- /package/.claude/commands/{flow-new.md → flow/new.md} +0 -0
- /package/.claude/commands/{flow-release.md → flow/release.md} +0 -0
- /package/.claude/commands/{flow-restart.md → flow/restart.md} +0 -0
- /package/.claude/commands/{flow-status.md → flow/status.md} +0 -0
- /package/.claude/commands/{flow-update.md → flow/update.md} +0 -0
- /package/.claude/commands/{flow-upgrade.md → flow/upgrade.md} +0 -0
- /package/.claude/commands/{flow-verify.md → flow/verify.md} +0 -0
- /package/.claude/commands/{code-review-high.md → util/code-review.md} +0 -0
- /package/.claude/commands/{git-commit.md → util/git-commit.md} +0 -0
- /package/.claude/commands/{problem-analyzer.md → util/problem-analyzer.md} +0 -0
- /package/.claude/skills/{flow-attention-refresh → domain/attention-refresh}/SKILL.md +0 -0
- /package/.claude/skills/{flow-brainstorming → domain/brainstorming}/SKILL.md +0 -0
- /package/.claude/skills/{flow-debugging → domain/debugging}/SKILL.md +0 -0
- /package/.claude/skills/{flow-finishing-branch → domain/finishing-branch}/SKILL.md +0 -0
- /package/.claude/skills/{flow-receiving-review → domain/receiving-review}/SKILL.md +0 -0
- /package/.claude/skills/{flow-tdd → domain/tdd}/SKILL.md +0 -0
- /package/.claude/skills/{verification-before-completion → domain/verification}/SKILL.md +0 -0
- /package/.claude/skills/{constitution-guardian → guardrail/constitution-guardian}/SKILL.md +0 -0
- /package/.claude/skills/{devflow-tdd-enforcer → guardrail/tdd-enforcer}/SKILL.md +0 -0
- /package/.claude/skills/{devflow-constitution-quick-ref → utility/constitution-quick-ref}/SKILL.md +0 -0
- /package/.claude/skills/{devflow-file-standards → utility/file-standards}/SKILL.md +0 -0
- /package/.claude/skills/{fractal-docs-generator → utility/fractal-docs}/SKILL.md +0 -0
- /package/.claude/skills/{npm-release → utility/npm-release}/SKILL.md +0 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Expander - context.jsonl 编译时展开
|
|
3
|
+
*
|
|
4
|
+
* [INPUT]: context.jsonl 文件内容, 目标平台
|
|
5
|
+
* [OUTPUT]: 展开后的上下文引用字符串
|
|
6
|
+
* [POS]: 编译器核心模块,将 context.jsonl 转换为平台特定格式
|
|
7
|
+
* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
|
|
8
|
+
*
|
|
9
|
+
* 功能:
|
|
10
|
+
* - 解析 JSONL 格式的上下文定义
|
|
11
|
+
* - 根据平台生成不同格式的上下文引用
|
|
12
|
+
* - Cursor 使用 @file 引用
|
|
13
|
+
* - 其他平台生成 "Required Context" 章节
|
|
14
|
+
*/
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
|
|
18
|
+
// ============================================================
|
|
19
|
+
// ContextExpander - 上下文展开器
|
|
20
|
+
// ============================================================
|
|
21
|
+
class ContextExpander {
|
|
22
|
+
/**
|
|
23
|
+
* 解析 context.jsonl 文件
|
|
24
|
+
* @param {string} jsonlPath - context.jsonl 文件路径
|
|
25
|
+
* @returns {Array<Object>} 上下文条目数组
|
|
26
|
+
*/
|
|
27
|
+
static parseContextFile(jsonlPath) {
|
|
28
|
+
if (!fs.existsSync(jsonlPath)) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const content = fs.readFileSync(jsonlPath, 'utf8');
|
|
33
|
+
return ContextExpander.parseJsonl(content);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 解析 JSONL 字符串
|
|
38
|
+
* @param {string} jsonlContent - JSONL 内容
|
|
39
|
+
* @returns {Array<Object>} 上下文条目数组
|
|
40
|
+
*/
|
|
41
|
+
static parseJsonl(jsonlContent) {
|
|
42
|
+
if (!jsonlContent || !jsonlContent.trim()) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const lines = jsonlContent.split('\n').filter(line => line.trim());
|
|
47
|
+
const contexts = [];
|
|
48
|
+
|
|
49
|
+
for (const line of lines) {
|
|
50
|
+
try {
|
|
51
|
+
const entry = JSON.parse(line);
|
|
52
|
+
if (entry.file) {
|
|
53
|
+
contexts.push({
|
|
54
|
+
file: entry.file,
|
|
55
|
+
reason: entry.reason || '',
|
|
56
|
+
optional: entry.optional || false
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
} catch (e) {
|
|
60
|
+
// 跳过无效行
|
|
61
|
+
console.warn(`Warning: Invalid JSONL line: ${line}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return contexts;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 展开上下文为平台特定格式
|
|
70
|
+
* @param {Array<Object>} contexts - 上下文条目数组
|
|
71
|
+
* @param {string} platform - 目标平台
|
|
72
|
+
* @returns {string} 展开后的字符串
|
|
73
|
+
*/
|
|
74
|
+
static expand(contexts, platform) {
|
|
75
|
+
if (!contexts || contexts.length === 0) {
|
|
76
|
+
return '';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
switch (platform) {
|
|
80
|
+
case 'cursor':
|
|
81
|
+
return ContextExpander.expandForCursor(contexts);
|
|
82
|
+
case 'codex':
|
|
83
|
+
return ContextExpander.expandForCodex(contexts);
|
|
84
|
+
case 'qwen':
|
|
85
|
+
return ContextExpander.expandForQwen(contexts);
|
|
86
|
+
case 'antigravity':
|
|
87
|
+
return ContextExpander.expandForAntigravity(contexts);
|
|
88
|
+
default:
|
|
89
|
+
return ContextExpander.expandDefault(contexts);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Cursor 格式: 使用 @file 引用
|
|
95
|
+
*/
|
|
96
|
+
static expandForCursor(contexts) {
|
|
97
|
+
const lines = contexts.map(c => {
|
|
98
|
+
const optional = c.optional ? ' (optional)' : '';
|
|
99
|
+
return `@${c.file}${optional}`;
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return `\n## Context Files\n\n${lines.join('\n')}\n`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Codex 格式: 生成 Required Context 章节
|
|
107
|
+
*/
|
|
108
|
+
static expandForCodex(contexts) {
|
|
109
|
+
return ContextExpander.expandDefault(contexts);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Qwen 格式: 生成 Required Context 章节
|
|
114
|
+
*/
|
|
115
|
+
static expandForQwen(contexts) {
|
|
116
|
+
return ContextExpander.expandDefault(contexts);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Antigravity 格式: 生成 Required Context 章节
|
|
121
|
+
*/
|
|
122
|
+
static expandForAntigravity(contexts) {
|
|
123
|
+
return ContextExpander.expandDefault(contexts);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 默认格式: 生成 Required Context 章节
|
|
128
|
+
*/
|
|
129
|
+
static expandDefault(contexts) {
|
|
130
|
+
const lines = contexts.map(c => {
|
|
131
|
+
const optional = c.optional ? ' (optional)' : '';
|
|
132
|
+
return `- \`${c.file}\` - ${c.reason}${optional}`;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return `
|
|
136
|
+
## Required Context
|
|
137
|
+
|
|
138
|
+
Before executing this skill, read the following files:
|
|
139
|
+
${lines.join('\n')}
|
|
140
|
+
`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 从 SKILL.md 所在目录读取并展开 context.jsonl
|
|
145
|
+
* @param {string} skillDir - SKILL.md 所在目录
|
|
146
|
+
* @param {string} platform - 目标平台
|
|
147
|
+
* @returns {string} 展开后的字符串
|
|
148
|
+
*/
|
|
149
|
+
static expandFromSkillDir(skillDir, platform) {
|
|
150
|
+
const contextPath = path.join(skillDir, 'context.jsonl');
|
|
151
|
+
const contexts = ContextExpander.parseContextFile(contextPath);
|
|
152
|
+
return ContextExpander.expand(contexts, platform);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 替换 SKILL.md 中的 {CONTEXT} 占位符
|
|
157
|
+
* @param {string} content - SKILL.md 内容
|
|
158
|
+
* @param {string} skillDir - SKILL.md 所在目录
|
|
159
|
+
* @param {string} platform - 目标平台
|
|
160
|
+
* @returns {string} 替换后的内容
|
|
161
|
+
*/
|
|
162
|
+
static replaceContextPlaceholder(content, skillDir, platform) {
|
|
163
|
+
const contextExpanded = ContextExpander.expandFromSkillDir(skillDir, platform);
|
|
164
|
+
|
|
165
|
+
// 替换 {CONTEXT} 占位符
|
|
166
|
+
if (content.includes('{CONTEXT}')) {
|
|
167
|
+
return content.replace('{CONTEXT}', contextExpanded);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// 如果没有占位符但有 context.jsonl,追加到末尾
|
|
171
|
+
if (contextExpanded) {
|
|
172
|
+
return content + '\n' + contextExpanded;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return content;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
module.exports = { ContextExpander };
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* T035: AntigravityEmitter - Antigravity 平台输出
|
|
2
|
+
* T035: AntigravityEmitter - Antigravity 平台输出 (v2.0)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* [INPUT]: CommandIR, SKILL.md, agents, rules
|
|
5
|
+
* [OUTPUT]: .agent/workflows/*.md, .agent/skills/*, .agent/rules/*.md, AGENTS.md
|
|
6
|
+
* [POS]: Antigravity 平台编译器,支持完整功能模块
|
|
7
|
+
* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
|
|
8
|
+
*
|
|
9
|
+
* 输出格式:
|
|
10
|
+
* - Commands: Markdown + YAML frontmatter -> .agent/workflows/
|
|
11
|
+
* - Skills: SKILL.md (YAML frontmatter) -> .agent/skills/
|
|
12
|
+
* - Agents: 合并到 AGENTS.md
|
|
13
|
+
* - Rules: Markdown -> .agent/rules/
|
|
14
|
+
*
|
|
15
|
+
* 限制: 单文件 <= 12,000 字符,超限时自动拆分
|
|
16
|
+
*
|
|
17
|
+
* v2.0: 支持多模块编译
|
|
8
18
|
*/
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const path = require('path');
|
|
9
21
|
const yaml = require('js-yaml');
|
|
22
|
+
const matter = require('gray-matter');
|
|
10
23
|
const BaseEmitter = require('./base-emitter.js');
|
|
24
|
+
const { ContextExpander } = require('../context-expander.js');
|
|
11
25
|
|
|
12
26
|
const CONTENT_LIMIT = 12000;
|
|
13
27
|
const DESCRIPTION_LIMIT = 250;
|
|
@@ -166,6 +180,182 @@ class AntigravityEmitter extends BaseEmitter {
|
|
|
166
180
|
content: this.createFrontmatter(description, index + 1, totalParts) + body
|
|
167
181
|
}));
|
|
168
182
|
}
|
|
183
|
+
|
|
184
|
+
// ----------------------------------------------------------
|
|
185
|
+
// Multi-Module Emit Methods (v2.0)
|
|
186
|
+
// ----------------------------------------------------------
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 编译 Skills 模块
|
|
190
|
+
* .claude/skills/[name]/SKILL.md -> .agent/skills/[name]/SKILL.md
|
|
191
|
+
*/
|
|
192
|
+
async emitSkills(sourceDir, targetDir) {
|
|
193
|
+
const results = [];
|
|
194
|
+
|
|
195
|
+
if (!fs.existsSync(sourceDir)) {
|
|
196
|
+
return results;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// 扫描技能分组目录
|
|
200
|
+
const groupDirs = await fs.promises.readdir(sourceDir, { withFileTypes: true });
|
|
201
|
+
|
|
202
|
+
for (const groupEntry of groupDirs) {
|
|
203
|
+
if (!groupEntry.isDirectory() || groupEntry.name.startsWith('_')) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const groupDir = path.join(sourceDir, groupEntry.name);
|
|
208
|
+
const skillEntries = await fs.promises.readdir(groupDir, { withFileTypes: true });
|
|
209
|
+
|
|
210
|
+
for (const skillEntry of skillEntries) {
|
|
211
|
+
if (!skillEntry.isDirectory() || skillEntry.name.startsWith('_')) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const skillDir = path.join(groupDir, skillEntry.name);
|
|
216
|
+
const skillMdPath = path.join(skillDir, 'SKILL.md');
|
|
217
|
+
|
|
218
|
+
if (!fs.existsSync(skillMdPath)) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
const result = await this._emitSingleSkill(
|
|
224
|
+
skillEntry.name,
|
|
225
|
+
skillDir,
|
|
226
|
+
skillMdPath,
|
|
227
|
+
targetDir
|
|
228
|
+
);
|
|
229
|
+
results.push(result);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
console.warn(`Warning: Failed to emit skill ${skillEntry.name}: ${error.message}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return results;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 编译单个 Skill
|
|
241
|
+
*/
|
|
242
|
+
async _emitSingleSkill(skillName, skillDir, skillMdPath, targetDir) {
|
|
243
|
+
let content = await fs.promises.readFile(skillMdPath, 'utf8');
|
|
244
|
+
const parsed = matter(content);
|
|
245
|
+
|
|
246
|
+
// 展开 context.jsonl
|
|
247
|
+
const contextExpanded = ContextExpander.expandFromSkillDir(skillDir, 'antigravity');
|
|
248
|
+
|
|
249
|
+
// 构建 frontmatter (Antigravity 支持 metadata)
|
|
250
|
+
const frontmatterData = {
|
|
251
|
+
name: parsed.data.name || skillName,
|
|
252
|
+
description: (parsed.data.description || '').substring(0, DESCRIPTION_LIMIT)
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// 添加 metadata (如果有)
|
|
256
|
+
if (parsed.data.metadata) {
|
|
257
|
+
frontmatterData.metadata = parsed.data.metadata;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const yamlStr = yaml.dump(frontmatterData, {
|
|
261
|
+
lineWidth: -1,
|
|
262
|
+
quotingType: '"',
|
|
263
|
+
forceQuotes: false
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// 组合最终内容:frontmatter + context + body
|
|
267
|
+
let body = parsed.content;
|
|
268
|
+
if (contextExpanded) {
|
|
269
|
+
body = contextExpanded + '\n' + body;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const finalContent = `---\n${yamlStr}---\n\n${body}`;
|
|
273
|
+
|
|
274
|
+
// 输出到 .agent/skills/<skill-name>/SKILL.md
|
|
275
|
+
const targetSkillDir = path.join(targetDir, skillName);
|
|
276
|
+
const targetPath = path.join(targetSkillDir, 'SKILL.md');
|
|
277
|
+
|
|
278
|
+
const result = await this.emitToPath(targetPath, finalContent);
|
|
279
|
+
|
|
280
|
+
// 复制 scripts/ 和 references/ 目录
|
|
281
|
+
await this._copySkillResources(skillDir, targetSkillDir);
|
|
282
|
+
|
|
283
|
+
return { ...result, skillName };
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* 复制 Skill 资源目录
|
|
288
|
+
*/
|
|
289
|
+
async _copySkillResources(sourceSkillDir, targetSkillDir) {
|
|
290
|
+
const resourceDirs = ['scripts', 'references', 'examples', 'resources'];
|
|
291
|
+
|
|
292
|
+
for (const dir of resourceDirs) {
|
|
293
|
+
const sourceResDir = path.join(sourceSkillDir, dir);
|
|
294
|
+
const targetResDir = path.join(targetSkillDir, dir);
|
|
295
|
+
|
|
296
|
+
if (fs.existsSync(sourceResDir)) {
|
|
297
|
+
await this._copyDir(sourceResDir, targetResDir);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* 递归复制目录
|
|
304
|
+
*/
|
|
305
|
+
async _copyDir(src, dest) {
|
|
306
|
+
await fs.promises.mkdir(dest, { recursive: true, mode: 0o755 });
|
|
307
|
+
const entries = await fs.promises.readdir(src, { withFileTypes: true });
|
|
308
|
+
|
|
309
|
+
for (const entry of entries) {
|
|
310
|
+
const srcPath = path.join(src, entry.name);
|
|
311
|
+
const destPath = path.join(dest, entry.name);
|
|
312
|
+
|
|
313
|
+
if (entry.isDirectory()) {
|
|
314
|
+
await this._copyDir(srcPath, destPath);
|
|
315
|
+
} else {
|
|
316
|
+
await fs.promises.copyFile(srcPath, destPath);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* 编译 Agents 模块
|
|
323
|
+
* .claude/agents/[name].md -> AGENTS.md (合并)
|
|
324
|
+
*/
|
|
325
|
+
async emitAgents(sourceDir, targetPath) {
|
|
326
|
+
return this._defaultAgentsEmit(sourceDir, targetPath);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* 编译 Rules 模块
|
|
331
|
+
* .claude/rules/[name].md -> .agent/rules/[name].md
|
|
332
|
+
*/
|
|
333
|
+
async emitRules(sourceDir, targetDir) {
|
|
334
|
+
const results = [];
|
|
335
|
+
|
|
336
|
+
if (!fs.existsSync(sourceDir)) {
|
|
337
|
+
return results;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const entries = await fs.promises.readdir(sourceDir, { withFileTypes: true });
|
|
341
|
+
|
|
342
|
+
for (const entry of entries) {
|
|
343
|
+
if (!entry.isFile() || !entry.name.endsWith('.md')) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const filePath = path.join(sourceDir, entry.name);
|
|
348
|
+
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
349
|
+
const ruleName = entry.name.replace('.md', '');
|
|
350
|
+
|
|
351
|
+
// Antigravity rules 是纯 Markdown
|
|
352
|
+
const targetPath = path.join(targetDir, `${ruleName}.md`);
|
|
353
|
+
const result = await this.emitToPath(targetPath, content);
|
|
354
|
+
results.push({ ...result, ruleName });
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return results;
|
|
358
|
+
}
|
|
169
359
|
}
|
|
170
360
|
|
|
171
361
|
module.exports = AntigravityEmitter;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* T031: BaseEmitter - Emitter 基类
|
|
2
|
+
* T031: BaseEmitter - Emitter 基类 (v2.0)
|
|
3
|
+
*
|
|
4
|
+
* [INPUT]: 平台配置 (platforms.js)
|
|
5
|
+
* [OUTPUT]: 编译后的文件
|
|
6
|
+
* [POS]: 编译器核心,定义 Emitter 接口和多模块编译能力
|
|
7
|
+
* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
|
|
3
8
|
*
|
|
4
9
|
* 定义 Emitter 接口:
|
|
5
10
|
* - name: 平台名称
|
|
@@ -7,6 +12,8 @@
|
|
|
7
12
|
* - fileExtension: 文件扩展名
|
|
8
13
|
* - format(ir, transformedContent): 格式化输出
|
|
9
14
|
* - emit(filename, content): 写入文件
|
|
15
|
+
*
|
|
16
|
+
* v2.0: 支持多模块编译 (skills, commands, agents, rules, hooks)
|
|
10
17
|
*/
|
|
11
18
|
const fs = require('fs');
|
|
12
19
|
const path = require('path');
|
|
@@ -17,6 +24,17 @@ const crypto = require('crypto');
|
|
|
17
24
|
// ============================================================
|
|
18
25
|
const MAX_OUTPUT_SIZE = 2 * 1024 * 1024; // 2MB limit
|
|
19
26
|
|
|
27
|
+
// ============================================================
|
|
28
|
+
// MODULE_TYPES - 支持的模块类型
|
|
29
|
+
// ============================================================
|
|
30
|
+
const MODULE_TYPES = {
|
|
31
|
+
SKILLS: 'skills',
|
|
32
|
+
COMMANDS: 'commands',
|
|
33
|
+
AGENTS: 'agents',
|
|
34
|
+
RULES: 'rules',
|
|
35
|
+
HOOKS: 'hooks'
|
|
36
|
+
};
|
|
37
|
+
|
|
20
38
|
class BaseEmitter {
|
|
21
39
|
// ----------------------------------------------------------
|
|
22
40
|
// Abstract properties - 子类必须覆盖
|
|
@@ -34,7 +52,7 @@ class BaseEmitter {
|
|
|
34
52
|
}
|
|
35
53
|
|
|
36
54
|
// ----------------------------------------------------------
|
|
37
|
-
// format() - 子类必须实现
|
|
55
|
+
// format() - 子类必须实现 (Commands 格式化)
|
|
38
56
|
// ----------------------------------------------------------
|
|
39
57
|
format(ir, transformedContent) {
|
|
40
58
|
throw new Error('Not implemented');
|
|
@@ -68,6 +86,203 @@ class BaseEmitter {
|
|
|
68
86
|
timestamp: new Date().toISOString()
|
|
69
87
|
};
|
|
70
88
|
}
|
|
89
|
+
|
|
90
|
+
// ----------------------------------------------------------
|
|
91
|
+
// emitToPath() - 写入文件到指定路径
|
|
92
|
+
// ----------------------------------------------------------
|
|
93
|
+
async emitToPath(filePath, content) {
|
|
94
|
+
if (content.length > MAX_OUTPUT_SIZE) {
|
|
95
|
+
throw new Error(`Output too large: ${filePath} (${content.length} bytes > ${MAX_OUTPUT_SIZE} bytes)`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const outputDir = path.dirname(filePath);
|
|
99
|
+
await fs.promises.mkdir(outputDir, { recursive: true, mode: 0o755 });
|
|
100
|
+
await fs.promises.writeFile(filePath, content, { encoding: 'utf8', mode: 0o644 });
|
|
101
|
+
|
|
102
|
+
const hash = crypto.createHash('sha256').update(content).digest('hex');
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
path: filePath,
|
|
106
|
+
hash,
|
|
107
|
+
timestamp: new Date().toISOString()
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ----------------------------------------------------------
|
|
112
|
+
// Multi-Module Emit Methods (v2.0)
|
|
113
|
+
// 子类可覆盖以实现平台特定逻辑
|
|
114
|
+
// ----------------------------------------------------------
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 编译 Skills 模块
|
|
118
|
+
* @param {string} sourceDir - 源目录 (.claude/skills/)
|
|
119
|
+
* @param {string} targetDir - 目标目录
|
|
120
|
+
* @returns {Promise<Array>} 编译结果
|
|
121
|
+
*/
|
|
122
|
+
async emitSkills(sourceDir, targetDir) {
|
|
123
|
+
// 默认实现: 复制 SKILL.md 文件
|
|
124
|
+
return this._defaultSkillsEmit(sourceDir, targetDir);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 编译 Commands 模块
|
|
129
|
+
* @param {Array} irs - 命令 IR 数组
|
|
130
|
+
* @param {string} targetDir - 目标目录
|
|
131
|
+
* @returns {Promise<Array>} 编译结果
|
|
132
|
+
*/
|
|
133
|
+
async emitCommands(irs, targetDir) {
|
|
134
|
+
// 默认实现: 使用现有 format/emit 逻辑
|
|
135
|
+
const results = [];
|
|
136
|
+
for (const ir of irs) {
|
|
137
|
+
const formatted = this.format(ir, ir.body);
|
|
138
|
+
const result = await this.emit(ir.source.filename, formatted);
|
|
139
|
+
results.push(result);
|
|
140
|
+
}
|
|
141
|
+
return results;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 编译 Agents 模块
|
|
146
|
+
* @param {string} sourceDir - 源目录 (.claude/agents/)
|
|
147
|
+
* @param {string} targetPath - 目标路径 (文件或目录)
|
|
148
|
+
* @returns {Promise<Array>} 编译结果
|
|
149
|
+
*/
|
|
150
|
+
async emitAgents(sourceDir, targetPath) {
|
|
151
|
+
// 默认实现: 合并到 AGENTS.md
|
|
152
|
+
return this._defaultAgentsEmit(sourceDir, targetPath);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 编译 Rules 模块
|
|
157
|
+
* @param {string} sourceDir - 源目录 (.claude/rules/)
|
|
158
|
+
* @param {string} targetPath - 目标路径 (文件或目录)
|
|
159
|
+
* @returns {Promise<Array>} 编译结果
|
|
160
|
+
*/
|
|
161
|
+
async emitRules(sourceDir, targetPath) {
|
|
162
|
+
// 默认实现: 复制或合并
|
|
163
|
+
return this._defaultRulesEmit(sourceDir, targetPath);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 编译 Hooks 模块
|
|
168
|
+
* @param {string} sourceDir - 源目录 (.claude/hooks/)
|
|
169
|
+
* @param {string} targetDir - 目标目录
|
|
170
|
+
* @returns {Promise<Array>} 编译结果
|
|
171
|
+
*/
|
|
172
|
+
async emitHooks(sourceDir, targetDir) {
|
|
173
|
+
// 默认实现: 不支持
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ----------------------------------------------------------
|
|
178
|
+
// Default Implementations
|
|
179
|
+
// ----------------------------------------------------------
|
|
180
|
+
|
|
181
|
+
async _defaultSkillsEmit(sourceDir, targetDir) {
|
|
182
|
+
const results = [];
|
|
183
|
+
|
|
184
|
+
if (!fs.existsSync(sourceDir)) {
|
|
185
|
+
return results;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const entries = await fs.promises.readdir(sourceDir, { withFileTypes: true });
|
|
189
|
+
|
|
190
|
+
for (const entry of entries) {
|
|
191
|
+
if (!entry.isDirectory() || entry.name.startsWith('_')) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const skillDir = path.join(sourceDir, entry.name);
|
|
196
|
+
const skillMdPath = path.join(skillDir, 'SKILL.md');
|
|
197
|
+
|
|
198
|
+
if (!fs.existsSync(skillMdPath)) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const content = await fs.promises.readFile(skillMdPath, 'utf8');
|
|
203
|
+
const targetSkillDir = path.join(targetDir, entry.name);
|
|
204
|
+
const targetPath = path.join(targetSkillDir, 'SKILL.md');
|
|
205
|
+
|
|
206
|
+
const result = await this.emitToPath(targetPath, content);
|
|
207
|
+
results.push({ ...result, skillName: entry.name });
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return results;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async _defaultAgentsEmit(sourceDir, targetPath) {
|
|
214
|
+
const results = [];
|
|
215
|
+
|
|
216
|
+
if (!fs.existsSync(sourceDir)) {
|
|
217
|
+
return results;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const entries = await fs.promises.readdir(sourceDir, { withFileTypes: true });
|
|
221
|
+
const sections = [];
|
|
222
|
+
|
|
223
|
+
for (const entry of entries) {
|
|
224
|
+
if (!entry.isFile() || !entry.name.endsWith('.md')) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const filePath = path.join(sourceDir, entry.name);
|
|
229
|
+
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
230
|
+
const agentName = entry.name.replace('.md', '');
|
|
231
|
+
|
|
232
|
+
sections.push(`## ${agentName}\n\n${content}`);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (sections.length > 0) {
|
|
236
|
+
const merged = `# Agents\n\n${sections.join('\n\n---\n\n')}`;
|
|
237
|
+
const result = await this.emitToPath(targetPath, merged);
|
|
238
|
+
results.push(result);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return results;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async _defaultRulesEmit(sourceDir, targetPath) {
|
|
245
|
+
const results = [];
|
|
246
|
+
|
|
247
|
+
if (!fs.existsSync(sourceDir)) {
|
|
248
|
+
return results;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const entries = await fs.promises.readdir(sourceDir, { withFileTypes: true });
|
|
252
|
+
const sections = [];
|
|
253
|
+
|
|
254
|
+
for (const entry of entries) {
|
|
255
|
+
if (!entry.isFile() || !entry.name.endsWith('.md')) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const filePath = path.join(sourceDir, entry.name);
|
|
260
|
+
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
261
|
+
const ruleName = entry.name.replace('.md', '');
|
|
262
|
+
|
|
263
|
+
sections.push(`## ${ruleName}\n\n${content}`);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (sections.length > 0) {
|
|
267
|
+
const merged = `# Rules\n\n${sections.join('\n\n---\n\n')}`;
|
|
268
|
+
const result = await this.emitToPath(targetPath, merged);
|
|
269
|
+
results.push(result);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return results;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ----------------------------------------------------------
|
|
276
|
+
// Utility Methods
|
|
277
|
+
// ----------------------------------------------------------
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* 计算内容哈希
|
|
281
|
+
*/
|
|
282
|
+
hashContent(content) {
|
|
283
|
+
return crypto.createHash('sha256').update(content).digest('hex');
|
|
284
|
+
}
|
|
71
285
|
}
|
|
72
286
|
|
|
73
287
|
module.exports = BaseEmitter;
|
|
288
|
+
module.exports.MODULE_TYPES = MODULE_TYPES;
|