@leocm/flowcraft 0.0.0-stage → 2.0.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/README.md +846 -3
- package/bin/cli.js +102 -0
- package/flowcraft.yaml +30 -0
- package/install.sh +24 -0
- package/lib/args.js +34 -0
- package/lib/config.js +20 -0
- package/lib/copy.js +131 -0
- package/lib/fix.js +110 -0
- package/lib/fsutil.js +104 -0
- package/lib/global.js +229 -0
- package/lib/init.js +43 -0
- package/lib/runtime.js +84 -0
- package/lib/version.js +55 -0
- package/lib/wizard.js +125 -0
- package/package.json +31 -4
- package/presets/backend.yaml +20 -0
- package/presets/default.yaml +15 -0
- package/presets/frontend.yaml +20 -0
- package/presets/quick-fix.yaml +15 -0
- package/setup/.claude/commands/P0.5.md +1 -0
- package/setup/.claude/commands/P0.md +1 -0
- package/setup/.claude/commands/P1.md +1 -0
- package/setup/.claude/commands/P2.md +1 -0
- package/setup/.claude/commands/P3.md +1 -0
- package/setup/.claude/commands/P4.md +1 -0
- package/setup/.claude/commands/P5.md +1 -0
- package/setup/.claude/commands/code-analysis-init.md +1 -0
- package/setup/.claude/commands/code-analysis-rebuild.md +1 -0
- package/setup/.claude/commands/code-analysis-show-memory.md +1 -0
- package/setup/.claude/commands/code-analysis-update.md +1 -0
- package/setup/.claude/hooks/check-phase-advancement.py +180 -0
- package/setup/.claude/hooks/check-phase-test.py +152 -0
- package/setup/.claude/hooks/check-phase-write.py +232 -0
- package/setup/.claude/hooks/dispatch.py +64 -0
- package/setup/.claude/hooks/file-suggestion.py +45 -0
- package/setup/.claude/hooks/flowcraft_env.py +99 -0
- package/setup/.claude/hooks/log_session.py +91 -0
- package/setup/.claude/hooks/permission-request.py +125 -0
- package/setup/.claude/hooks/post-tool-failure.py +34 -0
- package/setup/.claude/hooks/pre-compact.py +64 -0
- package/setup/.claude/hooks/review-runner.py +844 -0
- package/setup/.claude/hooks/session-end.py +182 -0
- package/setup/.claude/hooks/session-start.py +188 -0
- package/setup/.claude/hooks/settings.json +0 -0
- package/setup/.claude/hooks/setup-keys.py +280 -0
- package/setup/.claude/hooks/statusline.py +61 -0
- package/setup/.claude/hooks/stop-check.py +169 -0
- package/setup/.claude/hooks/subagent-start.py +48 -0
- package/setup/.claude/hooks/subagent-stop.py +61 -0
- package/setup/.claude/hooks/task-completed.py +55 -0
- package/setup/.claude/hooks/task_manager.py +592 -0
- package/setup/.claude/hooks/user-prompt-submit.py +85 -0
- package/setup/.claude/project-state.md +109 -0
- package/setup/.claude/settings.json +237 -0
- package/setup/.claude/settings.local.json +13 -0
- package/setup/.claude/skills/P5report/SKILL.md +77 -0
- package/setup/.claude/skills/Pstatus/SKILL.md +68 -0
- package/setup/.claude/skills/archive/SKILL.md +196 -0
- package/setup/.claude/skills/brainstorming/SKILL.md +155 -0
- package/setup/.claude/skills/brainstorming/scripts/frame-template.html +213 -0
- package/setup/.claude/skills/brainstorming/scripts/helper.js +167 -0
- package/setup/.claude/skills/brainstorming/scripts/server.cjs +723 -0
- package/setup/.claude/skills/brainstorming/scripts/start-server.py +245 -0
- package/setup/.claude/skills/brainstorming/scripts/stop-server.py +178 -0
- package/setup/.claude/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/setup/.claude/skills/brainstorming/visual-companion.md +298 -0
- package/setup/.claude/skills/checkpoint/SKILL.md +42 -0
- package/setup/.claude/skills/chrome-integration/SKILL.md +67 -0
- package/setup/.claude/skills/code-analysis/SKILL.md +1243 -0
- package/setup/.claude/skills/code-review/SKILL.md +265 -0
- package/setup/.claude/skills/cross-review/SKILL.md +41 -0
- package/setup/.claude/skills/executing-plans/SKILL.md +64 -0
- package/setup/.claude/skills/git-prep/SKILL.md +50 -0
- package/setup/.claude/skills/gitnexus/gitnexus-cli/SKILL.md +67 -0
- package/setup/.claude/skills/gitnexus/gitnexus-debugging/SKILL.md +89 -0
- package/setup/.claude/skills/gitnexus/gitnexus-exploring/SKILL.md +78 -0
- package/setup/.claude/skills/gitnexus/gitnexus-guide/SKILL.md +66 -0
- package/setup/.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +97 -0
- package/setup/.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md +121 -0
- package/setup/.claude/skills/graphify/SKILL.md +49 -0
- package/setup/.claude/skills/openspec-apply-change/SKILL.md +185 -0
- package/setup/.claude/skills/openspec-archive-change/SKILL.md +182 -0
- package/setup/.claude/skills/openspec-bulk-archive-change/SKILL.md +339 -0
- package/setup/.claude/skills/openspec-continue-change/SKILL.md +118 -0
- package/setup/.claude/skills/openspec-explore/SKILL.md +311 -0
- package/setup/.claude/skills/openspec-ff-change/SKILL.md +113 -0
- package/setup/.claude/skills/openspec-new-change/SKILL.md +77 -0
- package/setup/.claude/skills/openspec-onboard/SKILL.md +573 -0
- package/setup/.claude/skills/openspec-propose/SKILL.md +149 -0
- package/setup/.claude/skills/openspec-sync-specs/SKILL.md +262 -0
- package/setup/.claude/skills/openspec-update-change/SKILL.md +91 -0
- package/setup/.claude/skills/openspec-verify-change/SKILL.md +175 -0
- package/setup/.claude/skills/oss-version-check/SKILL.md +71 -0
- package/setup/.claude/skills/oss-version-check/check_oss_version.py +205 -0
- package/setup/.claude/skills/phase/SKILL.md +63 -0
- package/setup/.claude/skills/playwright/SKILL.md +86 -0
- package/setup/.claude/skills/playwright-cli/SKILL.md +420 -0
- package/setup/.claude/skills/playwright-cli/references/element-attributes.md +23 -0
- package/setup/.claude/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/setup/.claude/skills/playwright-cli/references/references/element-attributes.md +23 -0
- package/setup/.claude/skills/playwright-cli/references/references/playwright-tests.md +39 -0
- package/setup/.claude/skills/playwright-cli/references/references/request-mocking.md +87 -0
- package/setup/.claude/skills/playwright-cli/references/references/running-code.md +241 -0
- package/setup/.claude/skills/playwright-cli/references/references/session-management.md +225 -0
- package/setup/.claude/skills/playwright-cli/references/references/storage-state.md +275 -0
- package/setup/.claude/skills/playwright-cli/references/references/test-generation.md +433 -0
- package/setup/.claude/skills/playwright-cli/references/references/tracing.md +139 -0
- package/setup/.claude/skills/playwright-cli/references/references/video-recording.md +143 -0
- package/setup/.claude/skills/playwright-cli/references/request-mocking.md +87 -0
- package/setup/.claude/skills/playwright-cli/references/running-code.md +241 -0
- package/setup/.claude/skills/playwright-cli/references/session-management.md +225 -0
- package/setup/.claude/skills/playwright-cli/references/storage-state.md +275 -0
- package/setup/.claude/skills/playwright-cli/references/test-generation.md +433 -0
- package/setup/.claude/skills/playwright-cli/references/tracing.md +139 -0
- package/setup/.claude/skills/playwright-cli/references/video-recording.md +143 -0
- package/setup/.claude/skills/review/SKILL.md +98 -0
- package/setup/.claude/skills/review-tools/SKILL.md +76 -0
- package/setup/.claude/skills/subagent-driven-development/SKILL.md +94 -0
- package/setup/.claude/skills/task/SKILL.md +26 -0
- package/setup/.claude/skills/test-driven-development/SKILL.md +320 -0
- package/setup/.claude/skills/test-driven-development/writing-good-tests.md +198 -0
- package/setup/.claude/skills/ui-ux-pro-max/SKILL.md +377 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/styles.csv +68 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/setup/.claude/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/setup/.claude/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/setup/.claude/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/setup/.claude/skills/ui-ux-pro-max/scripts/search.py +114 -0
- package/setup/.claude/skills/ui-ux-standards/SKILL.md +154 -0
- package/setup/.claude/skills/verification-before-completion/SKILL.md +120 -0
- package/setup/.claude/skills/wiki-read/SKILL.md +190 -0
- package/setup/.claude/skills/writing-plans/SKILL.md +168 -0
- package/setup/.claude/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
- package/setup/.claude/tasks/.last-session +1 -0
- package/setup/.codex/.agents/skills/P5report/SKILL.md +77 -0
- package/setup/.codex/.agents/skills/Pstatus/SKILL.md +30 -0
- package/setup/.codex/.agents/skills/archive/SKILL.md +196 -0
- package/setup/.codex/.agents/skills/brainstorming/SKILL.md +155 -0
- package/setup/.codex/.agents/skills/brainstorming/scripts/frame-template.html +213 -0
- package/setup/.codex/.agents/skills/brainstorming/scripts/helper.js +167 -0
- package/setup/.codex/.agents/skills/brainstorming/scripts/server.cjs +723 -0
- package/setup/.codex/.agents/skills/brainstorming/scripts/start-server.py +245 -0
- package/setup/.codex/.agents/skills/brainstorming/scripts/stop-server.py +178 -0
- package/setup/.codex/.agents/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/setup/.codex/.agents/skills/brainstorming/visual-companion.md +298 -0
- package/setup/.codex/.agents/skills/checkpoint/SKILL.md +42 -0
- package/setup/.codex/.agents/skills/chrome-integration/SKILL.md +67 -0
- package/setup/.codex/.agents/skills/code-analysis/SKILL.md +1243 -0
- package/setup/.codex/.agents/skills/code-review/SKILL.md +265 -0
- package/setup/.codex/.agents/skills/cross-review/SKILL.md +42 -0
- package/setup/.codex/.agents/skills/executing-plans/SKILL.md +64 -0
- package/setup/.codex/.agents/skills/git-prep/SKILL.md +50 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-cli/SKILL.md +67 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-debugging/SKILL.md +89 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-exploring/SKILL.md +78 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-guide/SKILL.md +66 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +97 -0
- package/setup/.codex/.agents/skills/gitnexus/gitnexus-refactoring/SKILL.md +121 -0
- package/setup/.codex/.agents/skills/graphify/SKILL.md +49 -0
- package/setup/.codex/.agents/skills/openspec-apply-change/SKILL.md +185 -0
- package/setup/.codex/.agents/skills/openspec-archive-change/SKILL.md +182 -0
- package/setup/.codex/.agents/skills/openspec-bulk-archive-change/SKILL.md +339 -0
- package/setup/.codex/.agents/skills/openspec-continue-change/SKILL.md +118 -0
- package/setup/.codex/.agents/skills/openspec-explore/SKILL.md +311 -0
- package/setup/.codex/.agents/skills/openspec-ff-change/SKILL.md +113 -0
- package/setup/.codex/.agents/skills/openspec-new-change/SKILL.md +77 -0
- package/setup/.codex/.agents/skills/openspec-onboard/SKILL.md +573 -0
- package/setup/.codex/.agents/skills/openspec-propose/SKILL.md +149 -0
- package/setup/.codex/.agents/skills/openspec-sync-specs/SKILL.md +262 -0
- package/setup/.codex/.agents/skills/openspec-update-change/SKILL.md +91 -0
- package/setup/.codex/.agents/skills/openspec-verify-change/SKILL.md +175 -0
- package/setup/.codex/.agents/skills/oss-version-check/SKILL.md +71 -0
- package/setup/.codex/.agents/skills/oss-version-check/check_oss_version.py +205 -0
- package/setup/.codex/.agents/skills/phase/SKILL.md +63 -0
- package/setup/.codex/.agents/skills/playwright/SKILL.md +86 -0
- package/setup/.codex/.agents/skills/playwright-cli/SKILL.md +420 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/element-attributes.md +23 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/element-attributes.md +23 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/playwright-tests.md +39 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/request-mocking.md +87 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/running-code.md +241 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/session-management.md +225 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/storage-state.md +275 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/test-generation.md +433 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/tracing.md +139 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/references/video-recording.md +143 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/request-mocking.md +87 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/running-code.md +241 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/session-management.md +225 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/storage-state.md +275 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/test-generation.md +433 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/tracing.md +139 -0
- package/setup/.codex/.agents/skills/playwright-cli/references/video-recording.md +143 -0
- package/setup/.codex/.agents/skills/review/SKILL.md +98 -0
- package/setup/.codex/.agents/skills/review-tools/SKILL.md +76 -0
- package/setup/.codex/.agents/skills/subagent-driven-development/SKILL.md +94 -0
- package/setup/.codex/.agents/skills/task/SKILL.md +27 -0
- package/setup/.codex/.agents/skills/test-driven-development/SKILL.md +320 -0
- package/setup/.codex/.agents/skills/test-driven-development/writing-good-tests.md +198 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/SKILL.md +377 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/styles.csv +68 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/setup/.codex/.agents/skills/ui-ux-pro-max/scripts/search.py +114 -0
- package/setup/.codex/.agents/skills/ui-ux-standards/SKILL.md +154 -0
- package/setup/.codex/.agents/skills/verification-before-completion/SKILL.md +120 -0
- package/setup/.codex/.agents/skills/wiki-read/SKILL.md +190 -0
- package/setup/.codex/.agents/skills/writing-plans/SKILL.md +168 -0
- package/setup/.codex/.agents/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
- package/setup/.codex/config.toml +10 -0
- package/setup/.codex/hooks/log_session.py +85 -0
- package/setup/.codex/hooks/review-runner.py +844 -0
- package/setup/.codex/hooks/sdlc-codex-hook.cjs +1020 -0
- package/setup/.codex/hooks/setup-keys.py +280 -0
- package/setup/.codex/hooks.json +121 -0
- package/setup/.codex/model-catalog.json +154 -0
- package/setup/.codex/project-state.md +103 -0
- package/setup/AGENTS.md +722 -0
- package/setup/CLAUDE.md +717 -0
- package/setup/install.sh +24 -0
- package/setup/tests/test_decision_timeout.py +241 -0
- package/setup/tests/test_hook_guards.py +341 -0
- package/setup/tests/test_sdlc_bootstrap.py +167 -0
- package/setup/tests/test_task_manager.py +148 -0
package/lib/global.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* global.js — 全局安装(R4:对齐 install.sh install_global 及其子步骤)
|
|
3
|
+
*/
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const { timestamp, backupFile, copyDir, nowStr } = require('./fsutil');
|
|
9
|
+
const { fixLineEndings, replacePythonCommands } = require('./fix');
|
|
10
|
+
const { FRAMEWORK_VERSION } = require('./config');
|
|
11
|
+
|
|
12
|
+
/** hook 超时秒数(值与 legacy install.sh 完全一致,不改行为) */
|
|
13
|
+
const TIMEOUT_SHORT = 3;
|
|
14
|
+
const TIMEOUT_LONG = 5;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 构建 ~/.claude/settings.json 的 hooks 结构(对齐 install.sh 内联 JSON)
|
|
18
|
+
* @param {string} hookCmd hook 命令前缀(如 "python ~/.flowcraft/hooks/dispatch.py")
|
|
19
|
+
* @returns {object} settings 片段(hooks + statusLine)
|
|
20
|
+
*/
|
|
21
|
+
function buildHookSettings(hookCmd) {
|
|
22
|
+
const c = (sub, timeout, statusMessage) => {
|
|
23
|
+
const o = { type: 'command', command: `${hookCmd} ${sub}`, timeout };
|
|
24
|
+
if (statusMessage) o.statusMessage = statusMessage;
|
|
25
|
+
return o;
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
hooks: {
|
|
29
|
+
SessionStart: [{ matcher: 'startup|resume|compact', hooks: [c('session-start', TIMEOUT_LONG)] }],
|
|
30
|
+
UserPromptSubmit: [{ hooks: [c('user-prompt-submit', TIMEOUT_SHORT)] }],
|
|
31
|
+
PreToolUse: [
|
|
32
|
+
{
|
|
33
|
+
matcher: 'Write|Edit',
|
|
34
|
+
hooks: [
|
|
35
|
+
c('check-phase-advancement', TIMEOUT_SHORT, '检查阶段产出物...'),
|
|
36
|
+
c('check-phase-write', TIMEOUT_SHORT, '检查写入权限...'),
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{ matcher: 'Bash', hooks: [c('check-phase-test', TIMEOUT_SHORT, '检查命令权限...')] },
|
|
40
|
+
],
|
|
41
|
+
Stop: [{ hooks: [c('stop-check', TIMEOUT_LONG)] }],
|
|
42
|
+
PreCompact: [{ hooks: [c('pre-compact', TIMEOUT_LONG)] }],
|
|
43
|
+
SubagentStart: [{ hooks: [c('subagent-start', TIMEOUT_LONG, '注入 SDLC 上下文...')] }],
|
|
44
|
+
SubagentStop: [{ hooks: [c('subagent-stop', TIMEOUT_LONG, '验证子 Agent 输出...')] }],
|
|
45
|
+
TaskCompleted: [{ hooks: [c('task-completed', TIMEOUT_SHORT)] }],
|
|
46
|
+
PostToolUseFailure: [{ hooks: [c('post-tool-failure', TIMEOUT_LONG)] }],
|
|
47
|
+
PermissionRequest: [{ hooks: [c('permission-request', TIMEOUT_LONG, 'SDLC 权限决策...')] }],
|
|
48
|
+
SessionEnd: [{ hooks: [c('session-end', TIMEOUT_LONG)] }],
|
|
49
|
+
},
|
|
50
|
+
statusLine: { type: 'command', command: `${hookCmd} statusline`, padding: 1 },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 合并 ~/.claude/settings.json(仅覆盖 hooks/statusLine,其余键无损;覆盖前备份)
|
|
56
|
+
* @param {string} settingsPath settings.json 路径
|
|
57
|
+
* @param {string} hookCmd hook 命令前缀
|
|
58
|
+
* @returns {void}
|
|
59
|
+
*/
|
|
60
|
+
function mergeClaudeSettings(settingsPath, hookCmd) {
|
|
61
|
+
const built = buildHookSettings(hookCmd);
|
|
62
|
+
fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
|
|
63
|
+
if (!fs.existsSync(settingsPath)) {
|
|
64
|
+
const fresh = { $schema: 'https://json.schemastore.org/claude-code-settings.json', ...built };
|
|
65
|
+
fs.writeFileSync(settingsPath, JSON.stringify(fresh, null, 2));
|
|
66
|
+
console.log(`✓ 已创建 ${settingsPath}`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
console.log(`! 检测到已有 ${settingsPath},合并 hook 配置...`);
|
|
70
|
+
backupFile(settingsPath, timestamp());
|
|
71
|
+
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
72
|
+
settings.hooks = built.hooks;
|
|
73
|
+
settings.statusLine = built.statusLine;
|
|
74
|
+
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
|
75
|
+
console.log(' hooks 配置已合并');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 合并 Codex hooks.json:模板相对路径改写为用户级绝对路径(覆盖前备份)
|
|
80
|
+
* @param {string} tplPath 模板 hooks.json(setup/.codex/hooks.json)
|
|
81
|
+
* @param {string} dstPath 目标(~/.codex/hooks.json)
|
|
82
|
+
* @param {string} hooksDir 全局 hook 脚本目录(正斜杠)
|
|
83
|
+
* @returns {void}
|
|
84
|
+
*/
|
|
85
|
+
function mergeCodexHooksJson(tplPath, dstPath, hooksDir) {
|
|
86
|
+
if (fs.existsSync(dstPath)) backupFile(dstPath, timestamp());
|
|
87
|
+
const tpl = JSON.parse(fs.readFileSync(tplPath, 'utf8'));
|
|
88
|
+
for (const groups of Object.values(tpl.hooks || {})) {
|
|
89
|
+
for (const g of groups) {
|
|
90
|
+
for (const h of g.hooks || []) {
|
|
91
|
+
if (h.type === 'command' && typeof h.command === 'string') {
|
|
92
|
+
h.command = h.command.replace(/\.codex\/hooks\//g, `${hooksDir}/`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const existing = fs.existsSync(dstPath) ? JSON.parse(fs.readFileSync(dstPath, 'utf8')) : {};
|
|
98
|
+
const out = { ...existing, hooks: { ...(existing.hooks || {}), ...(tpl.hooks || {}) } };
|
|
99
|
+
fs.mkdirSync(path.dirname(dstPath), { recursive: true });
|
|
100
|
+
fs.writeFileSync(dstPath, JSON.stringify(out, null, 2));
|
|
101
|
+
console.log(` ✓ Codex hooks 注册 -> ${dstPath}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 合并 Codex 实验特性开关([features] skills/codex_hooks=true,已有配置无损)
|
|
106
|
+
* @param {string} configPath ~/.codex/config.toml
|
|
107
|
+
* @returns {void}
|
|
108
|
+
*/
|
|
109
|
+
function mergeCodexFeatures(configPath) {
|
|
110
|
+
if (fs.existsSync(configPath)) backupFile(configPath, timestamp());
|
|
111
|
+
const want = { skills: 'true', codex_hooks: 'true' };
|
|
112
|
+
let lines = fs.existsSync(configPath) ? fs.readFileSync(configPath, 'utf8').split('\n') : [];
|
|
113
|
+
const start = lines.findIndex((l) => /^\s*\[features\]\s*$/.test(l));
|
|
114
|
+
if (start === -1) {
|
|
115
|
+
if (lines.length && !lines[lines.length - 1].endsWith('\n')) lines[lines.length - 1] += '\n';
|
|
116
|
+
lines.push('[features]');
|
|
117
|
+
for (const [k, v] of Object.entries(want)) lines.push(`${k} = ${v}`);
|
|
118
|
+
} else {
|
|
119
|
+
let end = start + 1;
|
|
120
|
+
const have = new Set();
|
|
121
|
+
while (end < lines.length && !/^\s*\[/.test(lines[end])) {
|
|
122
|
+
const m = /^\s*([A-Za-z0-9_.-]+)\s*=/.exec(lines[end]);
|
|
123
|
+
if (m) have.add(m[1]);
|
|
124
|
+
end += 1;
|
|
125
|
+
}
|
|
126
|
+
const add = Object.entries(want).filter(([k]) => !have.has(k)).map(([k, v]) => `${k} = ${v}`);
|
|
127
|
+
lines = [...lines.slice(0, end), ...add, ...lines.slice(end)];
|
|
128
|
+
}
|
|
129
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
130
|
+
fs.writeFileSync(configPath, lines.join('\n'));
|
|
131
|
+
console.log(` ✓ Codex 特性开关已启用 -> ${configPath} [features]`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 分发 skills/commands 到用户级 Claude 与 Codex(全局兜底)
|
|
136
|
+
* @param {string} setupClaude setup/.claude
|
|
137
|
+
* @param {string} setupCodex setup/.codex
|
|
138
|
+
* @param {string} home 用户主目录
|
|
139
|
+
* @returns {void}
|
|
140
|
+
*/
|
|
141
|
+
function installGlobalSkills(setupClaude, setupCodex, home) {
|
|
142
|
+
const pairs = [
|
|
143
|
+
[path.join(setupClaude, 'skills'), path.join(home, '.claude', 'skills'), 'Claude skills'],
|
|
144
|
+
[path.join(setupClaude, 'commands'), path.join(home, '.claude', 'commands'), 'Claude commands'],
|
|
145
|
+
[path.join(setupCodex, '.agents', 'skills'), path.join(home, '.codex', 'skills'), 'Codex skills'],
|
|
146
|
+
];
|
|
147
|
+
for (const [src, dst, label] of pairs) {
|
|
148
|
+
if (!fs.existsSync(src)) continue;
|
|
149
|
+
copyDir(src, dst);
|
|
150
|
+
console.log(` ✓ ${label} -> ${dst}(全局兜底)`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 安装 Codex 全局 hooks:脚本入 ~/.flowcraft/codex-hooks 并注册 hooks.json
|
|
156
|
+
* @param {string} setupCodex setup/.codex
|
|
157
|
+
* @param {string} globalDir ~/.flowcraft
|
|
158
|
+
* @param {string} home 用户主目录
|
|
159
|
+
* @returns {void}
|
|
160
|
+
*/
|
|
161
|
+
function installGlobalCodexHooks(setupCodex, globalDir, home) {
|
|
162
|
+
const tplPath = path.join(setupCodex, 'hooks.json');
|
|
163
|
+
if (!fs.existsSync(tplPath)) {
|
|
164
|
+
console.log(' 跳过: setup/.codex/hooks.json 不存在');
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const codexHooksDir = path.join(globalDir, 'codex-hooks');
|
|
168
|
+
fs.mkdirSync(codexHooksDir, { recursive: true });
|
|
169
|
+
const hooksSrc = path.join(setupCodex, 'hooks');
|
|
170
|
+
if (fs.existsSync(hooksSrc)) {
|
|
171
|
+
copyDir(hooksSrc, codexHooksDir);
|
|
172
|
+
console.log(` ✓ Codex hook 脚本 -> ${codexHooksDir}`);
|
|
173
|
+
}
|
|
174
|
+
mergeCodexHooksJson(tplPath, path.join(home, '.codex', 'hooks.json'), codexHooksDir.replace(/\\/g, '/'));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 写入全局版本文件(对齐 install.sh 第 8 步)
|
|
179
|
+
* @param {string} globalDir ~/.flowcraft
|
|
180
|
+
* @returns {void}
|
|
181
|
+
*/
|
|
182
|
+
function writeGlobalVersion(globalDir) {
|
|
183
|
+
fs.mkdirSync(globalDir, { recursive: true });
|
|
184
|
+
const body = `${FRAMEWORK_VERSION}\ninstalled: ${nowStr()}\nmode: global\nskills: claude+codex\ncodex_hooks: global\n`;
|
|
185
|
+
fs.writeFileSync(path.join(globalDir, 'flowcraft-version'), body);
|
|
186
|
+
console.log('✓ 版本文件已写入');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 全局安装主流程(对齐 install_global 步骤 1-8)
|
|
191
|
+
* @param {string} pkgRoot 包根
|
|
192
|
+
* @param {string} home 用户主目录
|
|
193
|
+
* @param {string} pythonCmd 探测到的 python 命令
|
|
194
|
+
* @returns {void}
|
|
195
|
+
*/
|
|
196
|
+
function installGlobal(pkgRoot, home, pythonCmd) {
|
|
197
|
+
const setupClaude = path.join(pkgRoot, 'setup', '.claude');
|
|
198
|
+
const setupCodex = path.join(pkgRoot, 'setup', '.codex');
|
|
199
|
+
const globalDir = path.join(home, '.flowcraft');
|
|
200
|
+
const hooksDir = path.join(globalDir, 'hooks');
|
|
201
|
+
console.log('[全局模式] 安装 FlowCraft 到用户级(所有项目共享)');
|
|
202
|
+
console.log(` 全局目录: ${globalDir}`);
|
|
203
|
+
console.log(` 用户配置: ${path.join(home, '.claude', 'settings.json')}`);
|
|
204
|
+
console.log('');
|
|
205
|
+
if (!fs.existsSync(path.join(setupClaude, 'hooks'))) throw new Error('setup/.claude/hooks 目录不存在');
|
|
206
|
+
copyDir(path.join(setupClaude, 'hooks'), hooksDir);
|
|
207
|
+
console.log(`✓ hooks 已复制到 ${hooksDir}`);
|
|
208
|
+
fixLineEndings(hooksDir);
|
|
209
|
+
replacePythonCommands(hooksDir, pythonCmd);
|
|
210
|
+
let pyCmd = pythonCmd || 'python';
|
|
211
|
+
if (process.platform === 'win32' && (pyCmd === 'python3' || pyCmd === 'py')) pyCmd = 'python';
|
|
212
|
+
const dispatchPath = path.join(hooksDir, 'dispatch.py').replace(/\\/g, '/');
|
|
213
|
+
mergeClaudeSettings(path.join(home, '.claude', 'settings.json'), `${pyCmd} ${dispatchPath}`);
|
|
214
|
+
const tplDir = path.join(globalDir, 'templates');
|
|
215
|
+
fs.mkdirSync(tplDir, { recursive: true });
|
|
216
|
+
for (const tpl of ['CLAUDE.md', 'AGENTS.md']) {
|
|
217
|
+
const src = path.join(pkgRoot, 'setup', tpl);
|
|
218
|
+
if (fs.existsSync(src)) fs.copyFileSync(src, path.join(tplDir, tpl));
|
|
219
|
+
}
|
|
220
|
+
fs.copyFileSync(path.join(setupClaude, 'project-state.md'), path.join(tplDir, 'claude-project-state.md'));
|
|
221
|
+
fs.copyFileSync(path.join(setupCodex, 'project-state.md'), path.join(tplDir, 'codex-project-state.md'));
|
|
222
|
+
console.log(`✓ 模板目录已创建: ${tplDir}`);
|
|
223
|
+
installGlobalSkills(setupClaude, setupCodex, home);
|
|
224
|
+
installGlobalCodexHooks(setupCodex, globalDir, home);
|
|
225
|
+
mergeCodexFeatures(path.join(home, '.codex', 'config.toml'));
|
|
226
|
+
writeGlobalVersion(globalDir);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
module.exports = { buildHookSettings, mergeClaudeSettings, mergeCodexHooksJson, mergeCodexFeatures, installGlobalSkills, installGlobalCodexHooks, writeGlobalVersion, installGlobal };
|
package/lib/init.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* init.js — flowcraft init 最小化初始化(R2:对齐 install.sh --init/init_project)
|
|
3
|
+
*/
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 在目标目录创建最小化 .claude 与 flowcraft.yaml(已存在一律保留)
|
|
11
|
+
* @param {string} pkgRoot 包根(模板来源)
|
|
12
|
+
* @param {string} target 目标目录(默认 cwd)
|
|
13
|
+
* @returns {void}
|
|
14
|
+
*/
|
|
15
|
+
function initProject(pkgRoot, target) {
|
|
16
|
+
const dest = target || process.cwd();
|
|
17
|
+
const claudeDir = path.join(dest, '.claude');
|
|
18
|
+
console.log('[初始化] 在当前目录创建 FlowCraft 项目文件...');
|
|
19
|
+
console.log(` 目录: ${dest}`);
|
|
20
|
+
console.log('');
|
|
21
|
+
fs.mkdirSync(claudeDir, { recursive: true });
|
|
22
|
+
const stateDst = path.join(claudeDir, 'project-state.md');
|
|
23
|
+
const stateSrc = path.join(pkgRoot, 'setup', '.claude', 'project-state.md');
|
|
24
|
+
if (fs.existsSync(stateDst)) console.log(' 保留 .claude/project-state.md(已存在)');
|
|
25
|
+
else if (fs.existsSync(stateSrc)) {
|
|
26
|
+
fs.copyFileSync(stateSrc, stateDst);
|
|
27
|
+
console.log(' ✓ .claude/project-state.md');
|
|
28
|
+
}
|
|
29
|
+
for (const d of ['reports', 'reviews', 'archive']) fs.mkdirSync(path.join(claudeDir, d), { recursive: true });
|
|
30
|
+
console.log(' ✓ reports/ reviews/ archive/');
|
|
31
|
+
const cfgDst = path.join(dest, 'flowcraft.yaml');
|
|
32
|
+
const cfgSrc = path.join(pkgRoot, 'flowcraft.yaml');
|
|
33
|
+
if (fs.existsSync(cfgDst)) console.log(' 保留 flowcraft.yaml(已存在)');
|
|
34
|
+
else if (fs.existsSync(cfgSrc)) {
|
|
35
|
+
fs.copyFileSync(cfgSrc, cfgDst);
|
|
36
|
+
console.log(' ✓ flowcraft.yaml');
|
|
37
|
+
}
|
|
38
|
+
console.log('');
|
|
39
|
+
console.log('项目初始化完成!');
|
|
40
|
+
console.log(' 下一步: 1. 重启 Claude Code 2. 输入任务,SDLC 框架自动激活');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = { initProject };
|
package/lib/runtime.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runtime.js — 运行时探测/安装(R4:ensure_runtimes 等价,Python 必需 + Node 可选)
|
|
3
|
+
*/
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const { spawnSync } = require('node:child_process');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 探测 Python 3 命令(python3/python/py/py3 顺序,对齐 detect_python)
|
|
10
|
+
* @returns {string|null} 可用命令名,找不到返回 null
|
|
11
|
+
*/
|
|
12
|
+
function detectPython() {
|
|
13
|
+
for (const cand of ['python3', 'python', 'py', 'py3']) {
|
|
14
|
+
const r = spawnSync(cand, ['--version'], { encoding: 'utf8', shell: true });
|
|
15
|
+
const out = `${r.stdout || ''}${r.stderr || ''}`;
|
|
16
|
+
if (out.includes('Python 3')) return cand;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 探测 Node.js(>=20,对齐 detect_node)
|
|
23
|
+
* @returns {boolean} 是否可用
|
|
24
|
+
*/
|
|
25
|
+
function detectNode() {
|
|
26
|
+
const r = spawnSync('node', ['--version'], { encoding: 'utf8', shell: true });
|
|
27
|
+
const major = parseInt((r.stdout || '').replace(/^v/, ''), 10);
|
|
28
|
+
return Number.isInteger(major) && major >= 20;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 尝试安装 Python 3(winget/brew/apt/官方安装器,尽力而为)
|
|
33
|
+
* @returns {boolean} 是否执行成功
|
|
34
|
+
*/
|
|
35
|
+
function installPython() {
|
|
36
|
+
console.log('[运行时] 未检测到 Python 3,开始安装 Python 3.13 ...');
|
|
37
|
+
const tryRun = (cmd, args) => spawnSync(cmd, args, { encoding: 'utf8', shell: true }).status === 0;
|
|
38
|
+
if (tryRun('winget', ['install', '-e', '--id', 'Python.Python.3.13', '--accept-source-agreements', '--accept-package-agreements'])) return true;
|
|
39
|
+
if (tryRun('brew', ['install', 'python@3.13'])) return true;
|
|
40
|
+
if (tryRun('apt-get', ['install', '-y', 'python3'])) return true;
|
|
41
|
+
console.log('未能自动安装 Python,请手动安装 3.13(https://www.python.org/downloads/)');
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 尝试安装 Node.js 24(winget/brew/apt/官方安装器,尽力而为)
|
|
47
|
+
* @returns {boolean} 是否执行成功
|
|
48
|
+
*/
|
|
49
|
+
function installNode() {
|
|
50
|
+
console.log('[运行时] 未检测到可用 Node.js,开始安装 Node.js 24 ...');
|
|
51
|
+
const tryRun = (cmd, args) => spawnSync(cmd, args, { encoding: 'utf8', shell: true }).status === 0;
|
|
52
|
+
if (tryRun('winget', ['install', '-e', '--id', 'OpenJS.NodeJS.24', '--accept-source-agreements', '--accept-package-agreements'])) return true;
|
|
53
|
+
if (tryRun('brew', ['install', 'node@24'])) return true;
|
|
54
|
+
if (tryRun('apt-get', ['install', '-y', 'nodejs'])) return true;
|
|
55
|
+
console.log('未能自动安装 Node.js,请手动安装 24(https://nodejs.org/)');
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 检测/安装运行时(对齐 ensure_runtimes)
|
|
61
|
+
* @returns {string} 探测到的 python 命令(缺失且安装失败时抛错)
|
|
62
|
+
*/
|
|
63
|
+
function ensureRuntimes() {
|
|
64
|
+
console.log('[运行时] 检查 Python 与 Node.js ...');
|
|
65
|
+
let py = detectPython();
|
|
66
|
+
if (!py) {
|
|
67
|
+
installPython();
|
|
68
|
+
py = detectPython();
|
|
69
|
+
if (!py) throw new Error('未找到 Python 3(hooks 依赖),请手动安装后重试');
|
|
70
|
+
console.log(` Python(已安装): ${py}`);
|
|
71
|
+
} else {
|
|
72
|
+
console.log(` Python: ${py}`);
|
|
73
|
+
}
|
|
74
|
+
if (detectNode()) console.log(' Node.js: 可用');
|
|
75
|
+
else {
|
|
76
|
+
installNode();
|
|
77
|
+
if (detectNode()) console.log(' Node.js(已安装): 可用');
|
|
78
|
+
else console.log('警告: Node.js 未就绪(brainstorming 服务需要),可稍后手动安装');
|
|
79
|
+
}
|
|
80
|
+
console.log('');
|
|
81
|
+
return py;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = { detectPython, detectNode, installPython, installNode, ensureRuntimes };
|
package/lib/version.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* version.js — 项目类型探测与版本文件(R4:write_version_file 等价)
|
|
3
|
+
*/
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const { nowStr } = require('./fsutil');
|
|
9
|
+
const { FRAMEWORK_VERSION } = require('./config');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 检测项目类型(对齐 install.sh detect_project_type)
|
|
13
|
+
* @param {string} projectRoot 项目根
|
|
14
|
+
* @returns {string} java-maven/java-gradle/node/python/go/rust/unknown
|
|
15
|
+
*/
|
|
16
|
+
function detectProjectType(projectRoot) {
|
|
17
|
+
const has = (f) => fs.existsSync(path.join(projectRoot, f));
|
|
18
|
+
if (has('pom.xml')) return 'java-maven';
|
|
19
|
+
if (has('build.gradle') || has('build.gradle.kts')) return 'java-gradle';
|
|
20
|
+
if (has('package.json')) return 'node';
|
|
21
|
+
if (has('pyproject.toml') || has('setup.py')) return 'python';
|
|
22
|
+
if (has('go.mod')) return 'go';
|
|
23
|
+
if (has('Cargo.toml')) return 'rust';
|
|
24
|
+
return 'unknown';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 读取已安装版本(flowcraft-version 首行)
|
|
29
|
+
* @param {string} targetDir .claude 目录
|
|
30
|
+
* @returns {string} 版本号,未安装返回空串
|
|
31
|
+
*/
|
|
32
|
+
function getInstalledVersion(targetDir) {
|
|
33
|
+
const vfile = path.join(targetDir, 'flowcraft-version');
|
|
34
|
+
if (!fs.existsSync(vfile)) return '';
|
|
35
|
+
return fs.readFileSync(vfile, 'utf8').split('\n')[0].trim();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 写入版本文件(对齐 write_version_file)
|
|
40
|
+
* @param {string} targetDir .claude 目录
|
|
41
|
+
* @param {string} projectRoot 项目根(探测项目类型)
|
|
42
|
+
* @param {string} presetMode 预设模式
|
|
43
|
+
* @param {string} [version] 版本号,默认 FRAMEWORK_VERSION
|
|
44
|
+
* @returns {void}
|
|
45
|
+
*/
|
|
46
|
+
function writeVersionFile(targetDir, projectRoot, presetMode, version) {
|
|
47
|
+
const vfile = path.join(targetDir, 'flowcraft-version');
|
|
48
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
49
|
+
const ver = version || FRAMEWORK_VERSION;
|
|
50
|
+
const body = `${ver}\ninstalled: ${nowStr()}\npreset: ${presetMode || 'default'}\nproject_type: ${detectProjectType(projectRoot)}\n`;
|
|
51
|
+
fs.writeFileSync(vfile, body);
|
|
52
|
+
console.log(`✓ 版本文件已写入: ${vfile}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = { detectProjectType, getInstalledVersion, writeVersionFile };
|
package/lib/wizard.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wizard.js — 交互向导与完成提示(R2 --interactive,对齐 interactive_setup/show_stats/show_next_steps)
|
|
3
|
+
*/
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const readline = require('node:readline/promises');
|
|
9
|
+
const { stdin, stdout } = require('node:process');
|
|
10
|
+
const { timestamp } = require('./fsutil');
|
|
11
|
+
const { detectProjectType, getInstalledVersion } = require('./version');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 备份框架文件(升级时用,对齐 backup_framework_files)
|
|
15
|
+
* @param {string} targetDir .claude 目录
|
|
16
|
+
* @param {string} projectRoot 项目根
|
|
17
|
+
* @returns {void}
|
|
18
|
+
*/
|
|
19
|
+
function backupFrameworkFiles(targetDir, projectRoot) {
|
|
20
|
+
const backupDir = path.join(targetDir, 'backup', timestamp());
|
|
21
|
+
let backed = false;
|
|
22
|
+
for (const sub of ['hooks', 'skills']) {
|
|
23
|
+
const src = path.join(targetDir, sub);
|
|
24
|
+
if (fs.existsSync(src)) {
|
|
25
|
+
fs.cpSync(src, path.join(backupDir, sub), { recursive: true });
|
|
26
|
+
backed = true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
for (const f of ['CLAUDE.md', 'AGENTS.md']) {
|
|
30
|
+
const src = path.join(projectRoot, f);
|
|
31
|
+
if (fs.existsSync(src)) {
|
|
32
|
+
fs.mkdirSync(backupDir, { recursive: true });
|
|
33
|
+
fs.copyFileSync(src, path.join(backupDir, f));
|
|
34
|
+
backed = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (backed) console.log(`✓ 框架文件已备份到: ${backupDir}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 交互式配置向导(对齐 interactive_setup 提问流)
|
|
42
|
+
* @param {string} pkgRoot 包根
|
|
43
|
+
* @param {string} projectRoot 项目根
|
|
44
|
+
* @param {boolean} forceConfig 强制进入配置提问(--interactive 且已安装时)
|
|
45
|
+
* @returns {Promise<{presetFile:string|null,presetMode:string}>} 向导选择结果
|
|
46
|
+
*/
|
|
47
|
+
async function interactiveSetup(pkgRoot, projectRoot, forceConfig) {
|
|
48
|
+
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
49
|
+
try {
|
|
50
|
+
const projectType = detectProjectType(projectRoot);
|
|
51
|
+
console.log('\nFlowCraft 安装向导\n');
|
|
52
|
+
console.log(` 检测项目类型: ${projectType}\n`);
|
|
53
|
+
const installedVer = getInstalledVersion(path.join(projectRoot, '.claude'));
|
|
54
|
+
if (installedVer) {
|
|
55
|
+
console.log(` 检测到已安装 FlowCraft v${installedVer}\n`);
|
|
56
|
+
const up = (await rl.question(' 升级模式 A安全/B覆盖 [A]: ')).trim() || 'A';
|
|
57
|
+
const u = up.toUpperCase();
|
|
58
|
+
if (u === 'A' || u === 'B') {
|
|
59
|
+
console.log(u === 'B' ? '\n → 覆盖升级模式' : '\n → 安全升级模式');
|
|
60
|
+
backupFrameworkFiles(path.join(projectRoot, '.claude'), projectRoot);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!installedVer || forceConfig) return await askConfig(rl, pkgRoot);
|
|
64
|
+
return { presetFile: null, presetMode: '' };
|
|
65
|
+
} finally {
|
|
66
|
+
rl.close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 配置模式提问(快速/自定义/团队模板)
|
|
72
|
+
* @param {object} rl readline 接口
|
|
73
|
+
* @param {string} pkgRoot 包根
|
|
74
|
+
* @returns {Promise<{presetFile:string|null,presetMode:string}>} 选择结果
|
|
75
|
+
*/
|
|
76
|
+
async function askConfig(rl, pkgRoot) {
|
|
77
|
+
console.log('\n 配置模式:A快速安装 B自定义配置 C团队模板');
|
|
78
|
+
const choice = (await rl.question(' 请选择 [A]: ')).trim() || 'A';
|
|
79
|
+
if (choice.toUpperCase() === 'B') {
|
|
80
|
+
await rl.question(' 审查标准 (alibaba/google) [alibaba]: ');
|
|
81
|
+
await rl.question(' 默认语言 (java/typescript/python/go) []: ');
|
|
82
|
+
await rl.question(' 默认框架 (spring-boot/nextjs/fastapi) []: ');
|
|
83
|
+
console.log(' → 自定义配置已记录');
|
|
84
|
+
return { presetFile: null, presetMode: 'custom' };
|
|
85
|
+
}
|
|
86
|
+
if (choice.toUpperCase() === 'C') {
|
|
87
|
+
console.log('\n 内置预设:1.default 2.backend 3.frontend 4.quick-fix');
|
|
88
|
+
const num = (await rl.question(' 选择预设 [1]: ')).trim() || '1';
|
|
89
|
+
const map = { 1: 'default', 2: 'backend', 3: 'frontend', 4: 'quick-fix' };
|
|
90
|
+
const mode = map[num] || 'default';
|
|
91
|
+
console.log(` → 已选择预设: ${mode}`);
|
|
92
|
+
return { presetFile: path.join(pkgRoot, 'presets', `${mode}.yaml`), presetMode: mode };
|
|
93
|
+
}
|
|
94
|
+
console.log(' → 使用默认配置');
|
|
95
|
+
return { presetFile: null, presetMode: 'default' };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 显示安装统计(对齐 show_stats)
|
|
100
|
+
* @param {object} stats 统计对象
|
|
101
|
+
* @param {string} projectRoot 项目根
|
|
102
|
+
* @param {string} url sessionlog URL
|
|
103
|
+
* @returns {void}
|
|
104
|
+
*/
|
|
105
|
+
function showStats(stats, projectRoot, url) {
|
|
106
|
+
console.log('\n=== 安装完成 ===');
|
|
107
|
+
console.log(`项目根目录: ${projectRoot}`);
|
|
108
|
+
console.log(`复制文件数: ${stats.copyCount}`);
|
|
109
|
+
console.log(`Codex hooks: ${fs.existsSync(path.join(projectRoot, '.codex', 'hooks.json')) ? '已安装' : '未安装'}`);
|
|
110
|
+
console.log(`修复行尾符: ${stats.fixCount} 个文件`);
|
|
111
|
+
console.log(`替换 Python: ${stats.replaceCount} 个文件`);
|
|
112
|
+
console.log(`Sessionlog URL: ${url}(已分发 ${stats.urlCount} 个文件)`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 显示下一步引导(对齐 show_next_steps)
|
|
117
|
+
* @returns {void}
|
|
118
|
+
*/
|
|
119
|
+
function showNextSteps() {
|
|
120
|
+
console.log('\n安装完成!');
|
|
121
|
+
console.log(' 下一步: 1. 重启 Claude Code 或 Codex 2. 输入你的第一个任务 3. 或运行 /status 查看当前状态');
|
|
122
|
+
console.log(' 提示: 配置文件 flowcraft.yaml 可随时修改;团队共享将 flowcraft.yaml 提交到 git');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
module.exports = { backupFrameworkFiles, interactiveSetup, showStats, showNextSteps };
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leocm/flowcraft",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "FlowCraft SDLC 框架安装 CLI(跨平台,行为与 install.sh 等价)",
|
|
5
|
+
"bin": {
|
|
6
|
+
"flowcraft": "bin/cli.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin/",
|
|
10
|
+
"lib/",
|
|
11
|
+
"setup/",
|
|
12
|
+
"presets/",
|
|
13
|
+
"install.sh",
|
|
14
|
+
"README.md",
|
|
15
|
+
"flowcraft.yaml",
|
|
16
|
+
"!**/__pycache__/**",
|
|
17
|
+
"!**/*.pyc"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=20"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "node --test tests/*.test.js"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"sdlc",
|
|
28
|
+
"claude-code",
|
|
29
|
+
"flowcraft",
|
|
30
|
+
"installer"
|
|
31
|
+
],
|
|
32
|
+
"author": "leocm"
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# FlowCraft 预设: 后端服务
|
|
2
|
+
preset_name: "后端服务"
|
|
3
|
+
preset_version: "1.0"
|
|
4
|
+
description: "后端项目专用,P3测试强制,审查标准alibaba"
|
|
5
|
+
|
|
6
|
+
stages:
|
|
7
|
+
P1: auto
|
|
8
|
+
P2: true
|
|
9
|
+
P3: true # 后端必须测试
|
|
10
|
+
P4: true
|
|
11
|
+
P5: auto
|
|
12
|
+
|
|
13
|
+
review:
|
|
14
|
+
standard: alibaba
|
|
15
|
+
retry_limit: 3
|
|
16
|
+
|
|
17
|
+
tech_defaults:
|
|
18
|
+
language: java
|
|
19
|
+
framework: spring-boot
|
|
20
|
+
testing: junit
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# FlowCraft 预设: 前端项目
|
|
2
|
+
preset_name: "前端项目"
|
|
3
|
+
preset_version: "1.0"
|
|
4
|
+
description: "前端项目专用,P3含视觉回归测试,UI/UX强制"
|
|
5
|
+
|
|
6
|
+
stages:
|
|
7
|
+
P1: true # 前端需要设计确认
|
|
8
|
+
P2: true
|
|
9
|
+
P3: true # 含视觉回归
|
|
10
|
+
P4: true
|
|
11
|
+
P5: auto
|
|
12
|
+
|
|
13
|
+
review:
|
|
14
|
+
standard: alibaba
|
|
15
|
+
retry_limit: 3
|
|
16
|
+
|
|
17
|
+
tech_defaults:
|
|
18
|
+
language: typescript
|
|
19
|
+
framework: nextjs
|
|
20
|
+
testing: jest
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# FlowCraft 预设: 快速修复
|
|
2
|
+
preset_name: "快速修复"
|
|
3
|
+
preset_version: "1.0"
|
|
4
|
+
description: "Bug修复/小改动专用,P1/P3/P5可跳过,只保留编码和审查"
|
|
5
|
+
|
|
6
|
+
stages:
|
|
7
|
+
P1: auto # 小改动可跳过
|
|
8
|
+
P2: true
|
|
9
|
+
P3: auto # 简单修复可跳过
|
|
10
|
+
P4: true
|
|
11
|
+
P5: auto # 小改动可跳过
|
|
12
|
+
|
|
13
|
+
review:
|
|
14
|
+
standard: alibaba
|
|
15
|
+
retry_limit: 2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
将 .claude/project-state.md 中的 current_phase 改为 P0.5,更新 last_updated 为当前日期,然后报告:已切换到 P0.5(问题回溯阶段)。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
将 .claude/project-state.md 中的 current_phase 改为 P0,更新 last_updated 为当前日期,然后报告:已切换到 P0(待命阶段)。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
将 .claude/project-state.md 中的 current_phase 改为 P1,更新 last_updated 为当前日期,然后报告:已切换到 P1(需求澄清+设计阶段)。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
将 .claude/project-state.md 中的 current_phase 改为 P2,更新 last_updated 为当前日期,然后报告:已切换到 P2(编码阶段)。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
将 .claude/project-state.md 中的 current_phase 改为 P3,更新 last_updated 为当前日期,然后报告:已切换到 P3(测试阶段)。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
将 .claude/project-state.md 中的 current_phase 改为 P4,更新 last_updated 为当前日期,然后报告:已切换到 P4(审查阶段)。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
将 .claude/project-state.md 中的 current_phase 改为 P5,更新 last_updated 为当前日期,然后报告:已切换到 P5(交付阶段)。
|