claude-everything-workflow 0.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/AGENTS.md +36 -0
- package/CLAUDE.md +7 -0
- package/LICENSE +22 -0
- package/README.md +369 -0
- package/agents/architect.md +59 -0
- package/agents/code-reviewer.md +57 -0
- package/agents/database-reviewer.md +44 -0
- package/agents/e2e-runner.md +153 -0
- package/agents/harness-optimizer.md +92 -0
- package/agents/planner.md +124 -0
- package/agents/refactor-cleaner.md +54 -0
- package/agents/security-reviewer.md +47 -0
- package/agents/tdd-guide.md +101 -0
- package/bin/claude-everything-workflow.js +91 -0
- package/commands/code-review.md +27 -0
- package/commands/e2e.md +28 -0
- package/commands/evolve.md +42 -0
- package/commands/harness-audit.md +27 -0
- package/commands/instinct-status.md +38 -0
- package/commands/learn-eval.md +91 -0
- package/commands/pr.md +88 -0
- package/commands/projects.md +27 -0
- package/commands/promote.md +29 -0
- package/commands/prune.md +46 -0
- package/commands/tdd.md +27 -0
- package/commands/verify.md +93 -0
- package/homunculus/instincts/personal/always-test-first.md +28 -0
- package/homunculus/instincts/personal/pr-ci-quality-gate.md +30 -0
- package/hooks/check-console-log.js +37 -0
- package/hooks/commit-quality.js +143 -0
- package/hooks/evaluate-session.js +59 -0
- package/hooks/pre-compact.js +92 -0
- package/hooks/runtime/hook-flags.js +40 -0
- package/hooks/runtime/run-with-flags.js +141 -0
- package/hooks/runtime/session-utils.js +45 -0
- package/hooks/session-end.js +62 -0
- package/hooks/session-start.js +60 -0
- package/package.json +48 -0
- package/references/agents/database-reviewer.md +657 -0
- package/references/agents/refactor-cleaner.md +75 -0
- package/references/agents/security-reviewer.md +542 -0
- package/rules/01-base.md +49 -0
- package/rules/02-code-size.md +13 -0
- package/rules/03-architecture.md +64 -0
- package/rules/04-error-handling.md +27 -0
- package/rules/05-git-workflow.md +56 -0
- package/rules/06-comments.md +44 -0
- package/rules/07-forbidden.md +43 -0
- package/rules/08-ecc-integration.md +46 -0
- package/rules/common/agent-orchestration.md +54 -0
- package/rules/common/context-hygiene.md +85 -0
- package/rules/common/harness-engineering.md +46 -0
- package/rules/common/hooks.md +87 -0
- package/rules/common/implementation.md +25 -0
- package/rules/common/performance.md +71 -0
- package/rules/common/pr-automation.md +73 -0
- package/rules/common/security.md +19 -0
- package/rules/common/skills-learning.md +39 -0
- package/rules/common/testing.md +68 -0
- package/scripts/install.ps1 +286 -0
- package/scripts/install.sh +214 -0
- package/scripts/learning/migrate-homunculus.js +93 -0
- package/scripts/learning/project-utils.js +214 -0
- package/scripts/learning/projects.js +60 -0
- package/scripts/learning/promote.js +98 -0
- package/scripts/learning/review-confidence.js +455 -0
- package/scripts/verify-harness.js +868 -0
- package/settings.json +77 -0
- package/skills/brainstorming/SKILL.md +185 -0
- package/skills/brainstorming/agents/openai.yaml +3 -0
- package/skills/brainstorming/scripts/frame-template.html +214 -0
- package/skills/brainstorming/scripts/helper.js +88 -0
- package/skills/brainstorming/scripts/server.cjs +354 -0
- package/skills/brainstorming/scripts/start-server.sh +148 -0
- package/skills/brainstorming/scripts/stop-server.sh +56 -0
- package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/skills/brainstorming/visual-companion.md +287 -0
- package/skills/continuous-learning-v2/SKILL.md +74 -0
- package/skills/continuous-learning-v2/agents/observer.md +129 -0
- package/skills/continuous-learning-v2/agents/start-observer.sh +83 -0
- package/skills/continuous-learning-v2/config.json +58 -0
- package/skills/continuous-learning-v2/hooks/observe-v2.js +144 -0
- package/skills/documentation-lookup/SKILL.md +90 -0
- package/skills/e2e-testing/SKILL.md +326 -0
- package/skills/executing-plans/SKILL.md +66 -0
- package/skills/find-skills/SKILL.md +142 -0
- package/skills/skill-creator/LICENSE.txt +202 -0
- package/skills/skill-creator/SKILL.md +356 -0
- package/skills/skill-creator/references/output-patterns.md +82 -0
- package/skills/skill-creator/references/workflows.md +28 -0
- package/skills/skill-creator/scripts/init_skill.py +303 -0
- package/skills/skill-creator/scripts/package_skill.py +110 -0
- package/skills/skill-creator/scripts/quick_validate.py +95 -0
- package/skills/systematic-debugging/SKILL.md +59 -0
- package/skills/test-driven-development/SKILL.md +71 -0
- package/skills/using-git-worktrees/SKILL.md +64 -0
- package/skills/verification-before-completion/SKILL.md +77 -0
- package/skills/writing-plans/SKILL.md +183 -0
- package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 将旧 ~/.claude/homunculus 结构迁移到 project/global 分层数据根目录
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict'
|
|
7
|
+
|
|
8
|
+
const fs = require('fs')
|
|
9
|
+
const path = require('path')
|
|
10
|
+
const os = require('os')
|
|
11
|
+
const {
|
|
12
|
+
ensureDir,
|
|
13
|
+
getDataRoot,
|
|
14
|
+
getGlobalInstinctsDir,
|
|
15
|
+
getProjectContext,
|
|
16
|
+
getProjectInstinctsDir,
|
|
17
|
+
loadConfig,
|
|
18
|
+
registerProject
|
|
19
|
+
} = require('./project-utils')
|
|
20
|
+
|
|
21
|
+
function parseArgs() {
|
|
22
|
+
const args = process.argv.slice(2)
|
|
23
|
+
return {
|
|
24
|
+
apply: args.includes('--apply'),
|
|
25
|
+
dryRun: args.includes('--dry-run') || !args.includes('--apply'),
|
|
26
|
+
scope: parseStringArg(args, '--scope') || 'project',
|
|
27
|
+
source: parseStringArg(args, '--source') ||
|
|
28
|
+
path.join(os.homedir(), '.claude', 'homunculus', 'instincts')
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function parseStringArg(args, flag) {
|
|
33
|
+
const index = args.indexOf(flag)
|
|
34
|
+
if (index === -1 || !args[index + 1]) return null
|
|
35
|
+
return args[index + 1]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function copyDirPreview(sourceRoot, destinationRoot, apply) {
|
|
39
|
+
const operations = []
|
|
40
|
+
for (const category of ['personal', 'inherited']) {
|
|
41
|
+
const sourceDir = path.join(sourceRoot, category)
|
|
42
|
+
if (!fs.existsSync(sourceDir)) continue
|
|
43
|
+
for (const file of fs.readdirSync(sourceDir)) {
|
|
44
|
+
if (!file.endsWith('.md')) continue
|
|
45
|
+
const source = path.join(sourceDir, file)
|
|
46
|
+
const destination = path.join(destinationRoot, category, file)
|
|
47
|
+
operations.push({ source, destination, exists: fs.existsSync(destination) })
|
|
48
|
+
if (apply && !fs.existsSync(destination)) {
|
|
49
|
+
ensureDir(path.dirname(destination))
|
|
50
|
+
fs.copyFileSync(source, destination)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return operations
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function main() {
|
|
58
|
+
const options = parseArgs()
|
|
59
|
+
const config = loadConfig()
|
|
60
|
+
const dataRoot = getDataRoot(config)
|
|
61
|
+
const context = getProjectContext({ cwd: process.cwd() })
|
|
62
|
+
const destinationRoot = options.scope === 'global'
|
|
63
|
+
? getGlobalInstinctsDir(dataRoot)
|
|
64
|
+
: getProjectInstinctsDir(dataRoot, context.project_id)
|
|
65
|
+
|
|
66
|
+
if (options.scope !== 'global') {
|
|
67
|
+
registerProject(dataRoot, context)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const operations = copyDirPreview(options.source, destinationRoot, options.apply)
|
|
71
|
+
|
|
72
|
+
console.log(options.apply ? '[Migrate] 已应用迁移' : '[Migrate] dry-run 预览')
|
|
73
|
+
console.log(`[Migrate] 源目录: ${options.source}`)
|
|
74
|
+
console.log(`[Migrate] 目标目录: ${destinationRoot}`)
|
|
75
|
+
console.log(`[Migrate] 范围: ${options.scope}`)
|
|
76
|
+
console.log('')
|
|
77
|
+
|
|
78
|
+
if (operations.length === 0) {
|
|
79
|
+
console.log('[Migrate] 没有找到可迁移的直觉文件。')
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
console.log('| 源文件 | 状态 | 目标 |')
|
|
84
|
+
console.log('|--------|------|------|')
|
|
85
|
+
for (const operation of operations) {
|
|
86
|
+
const status = operation.exists
|
|
87
|
+
? '已存在,跳过'
|
|
88
|
+
: options.apply ? '已复制' : '将复制'
|
|
89
|
+
console.log(`| ${operation.source} | ${status} | ${operation.destination} |`)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
main()
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Continuous Learning 项目隔离工具
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict'
|
|
7
|
+
|
|
8
|
+
const fs = require('fs')
|
|
9
|
+
const path = require('path')
|
|
10
|
+
const os = require('os')
|
|
11
|
+
const crypto = require('crypto')
|
|
12
|
+
const { execFileSync } = require('child_process')
|
|
13
|
+
|
|
14
|
+
function expandHome(value) {
|
|
15
|
+
if (!value) return value
|
|
16
|
+
if (value === '~') return os.homedir()
|
|
17
|
+
if (value.startsWith('~/')) {
|
|
18
|
+
return path.join(os.homedir(), value.slice(2))
|
|
19
|
+
}
|
|
20
|
+
return value
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getDefaultDataRoot() {
|
|
24
|
+
const xdg = process.env.XDG_DATA_HOME
|
|
25
|
+
if (xdg && xdg.trim()) {
|
|
26
|
+
return path.join(xdg, 'ecc-homunculus')
|
|
27
|
+
}
|
|
28
|
+
return path.join(os.homedir(), '.local', 'share', 'ecc-homunculus')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function readJson(filePath, fallback = {}) {
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
|
34
|
+
} catch {
|
|
35
|
+
return fallback
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function writeJson(filePath, value) {
|
|
40
|
+
ensureDir(path.dirname(filePath))
|
|
41
|
+
fs.writeFileSync(filePath, JSON.stringify(value, null, 2) + '\n', 'utf8')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function loadConfig() {
|
|
45
|
+
const cwdConfig = path.join(
|
|
46
|
+
process.cwd(),
|
|
47
|
+
'skills',
|
|
48
|
+
'continuous-learning-v2',
|
|
49
|
+
'config.json'
|
|
50
|
+
)
|
|
51
|
+
const homeConfig = path.join(
|
|
52
|
+
os.homedir(),
|
|
53
|
+
'.claude',
|
|
54
|
+
'skills',
|
|
55
|
+
'continuous-learning-v2',
|
|
56
|
+
'config.json'
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
return readJson(fs.existsSync(cwdConfig) ? cwdConfig : homeConfig, {})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getDataRoot(config = loadConfig()) {
|
|
63
|
+
return path.resolve(expandHome(config.homunculus?.data_root) || getDefaultDataRoot())
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function ensureDir(dirPath) {
|
|
67
|
+
fs.mkdirSync(dirPath, { recursive: true })
|
|
68
|
+
return dirPath
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function runGit(args, cwd) {
|
|
72
|
+
return execFileSync('git', args, {
|
|
73
|
+
cwd,
|
|
74
|
+
encoding: 'utf8',
|
|
75
|
+
timeout: 1000,
|
|
76
|
+
windowsHide: true,
|
|
77
|
+
stdio: ['ignore', 'pipe', 'ignore']
|
|
78
|
+
}).trim()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getProjectContext(input = {}) {
|
|
82
|
+
const cwd = input.cwd || input.tool_input?.cwd || process.cwd()
|
|
83
|
+
let projectRoot = path.resolve(cwd)
|
|
84
|
+
let remote = null
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
projectRoot = runGit(['rev-parse', '--show-toplevel'], cwd)
|
|
88
|
+
} catch {
|
|
89
|
+
projectRoot = path.resolve(cwd)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
remote = runGit(['remote', 'get-url', 'origin'], projectRoot)
|
|
94
|
+
} catch {
|
|
95
|
+
remote = null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const identity = remote || projectRoot.toLowerCase()
|
|
99
|
+
const projectId = crypto
|
|
100
|
+
.createHash('sha1')
|
|
101
|
+
.update(identity)
|
|
102
|
+
.digest('hex')
|
|
103
|
+
.slice(0, 12)
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
cwd: path.resolve(cwd),
|
|
107
|
+
project_root: projectRoot,
|
|
108
|
+
project_name: path.basename(projectRoot),
|
|
109
|
+
project_id: projectId,
|
|
110
|
+
remote
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function getProjectsRegistryPath(dataRoot) {
|
|
115
|
+
return path.join(dataRoot, 'projects.json')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function loadProjects(dataRoot) {
|
|
119
|
+
const registryPath = getProjectsRegistryPath(dataRoot)
|
|
120
|
+
const registry = readJson(registryPath, { projects: {} })
|
|
121
|
+
if (!registry.projects) registry.projects = {}
|
|
122
|
+
return registry
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function registerProject(dataRoot, context) {
|
|
126
|
+
const registry = loadProjects(dataRoot)
|
|
127
|
+
const now = new Date().toISOString()
|
|
128
|
+
const existing = registry.projects[context.project_id] || {}
|
|
129
|
+
|
|
130
|
+
registry.projects[context.project_id] = {
|
|
131
|
+
id: context.project_id,
|
|
132
|
+
name: context.project_name,
|
|
133
|
+
root: context.project_root,
|
|
134
|
+
remote: context.remote,
|
|
135
|
+
first_seen: existing.first_seen || now,
|
|
136
|
+
last_seen: now
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
writeJson(getProjectsRegistryPath(dataRoot), registry)
|
|
140
|
+
return registry.projects[context.project_id]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getProjectDir(dataRoot, projectId) {
|
|
144
|
+
return path.join(dataRoot, 'projects', projectId)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function getGlobalInstinctsDir(dataRoot) {
|
|
148
|
+
return path.join(dataRoot, 'global', 'instincts')
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function getProjectInstinctsDir(dataRoot, projectId) {
|
|
152
|
+
return path.join(getProjectDir(dataRoot, projectId), 'instincts')
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function listMarkdownFiles(dirPath) {
|
|
156
|
+
if (!fs.existsSync(dirPath)) return []
|
|
157
|
+
return fs.readdirSync(dirPath)
|
|
158
|
+
.filter(file => file.endsWith('.md'))
|
|
159
|
+
.map(file => path.join(dirPath, file))
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function scanInstincts(basePath, scope) {
|
|
163
|
+
const files = []
|
|
164
|
+
for (const category of ['personal', 'inherited']) {
|
|
165
|
+
const dirPath = path.join(basePath, category)
|
|
166
|
+
for (const filePath of listMarkdownFiles(dirPath)) {
|
|
167
|
+
files.push({ path: filePath, category, scope })
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return files
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function parseFrontmatter(content) {
|
|
174
|
+
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/)
|
|
175
|
+
if (!match) return { meta: {}, body: content }
|
|
176
|
+
|
|
177
|
+
const meta = {}
|
|
178
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
179
|
+
const colonIndex = line.indexOf(':')
|
|
180
|
+
if (colonIndex <= 0) continue
|
|
181
|
+
const key = line.slice(0, colonIndex).trim()
|
|
182
|
+
let value = line.slice(colonIndex + 1).trim()
|
|
183
|
+
if (
|
|
184
|
+
(value.startsWith('"') && value.endsWith('"')) ||
|
|
185
|
+
(value.startsWith("'") && value.endsWith("'"))
|
|
186
|
+
) {
|
|
187
|
+
value = value.slice(1, -1)
|
|
188
|
+
}
|
|
189
|
+
if (value === 'true') value = true
|
|
190
|
+
else if (value === 'false') value = false
|
|
191
|
+
else if (/^-?\d+\.?\d*$/.test(String(value))) value = parseFloat(value)
|
|
192
|
+
meta[key] = value
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return { meta, body: content.slice(match[0].length) }
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
module.exports = {
|
|
199
|
+
ensureDir,
|
|
200
|
+
expandHome,
|
|
201
|
+
getDataRoot,
|
|
202
|
+
getDefaultDataRoot,
|
|
203
|
+
getGlobalInstinctsDir,
|
|
204
|
+
getProjectContext,
|
|
205
|
+
getProjectDir,
|
|
206
|
+
getProjectInstinctsDir,
|
|
207
|
+
loadConfig,
|
|
208
|
+
loadProjects,
|
|
209
|
+
parseFrontmatter,
|
|
210
|
+
readJson,
|
|
211
|
+
registerProject,
|
|
212
|
+
scanInstincts,
|
|
213
|
+
writeJson
|
|
214
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 列出 Continuous Learning 项目注册表
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict'
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
getDataRoot,
|
|
10
|
+
getProjectContext,
|
|
11
|
+
loadConfig,
|
|
12
|
+
loadProjects,
|
|
13
|
+
registerProject
|
|
14
|
+
} = require('./project-utils')
|
|
15
|
+
|
|
16
|
+
function parseArgs() {
|
|
17
|
+
const args = process.argv.slice(2)
|
|
18
|
+
return {
|
|
19
|
+
json: args.includes('--json'),
|
|
20
|
+
registerCurrent: args.includes('--register-current')
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function main() {
|
|
25
|
+
const options = parseArgs()
|
|
26
|
+
const config = loadConfig()
|
|
27
|
+
const dataRoot = getDataRoot(config)
|
|
28
|
+
|
|
29
|
+
if (options.registerCurrent) {
|
|
30
|
+
registerProject(dataRoot, getProjectContext({ cwd: process.cwd() }))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const projects = Object.values(loadProjects(dataRoot).projects || {})
|
|
34
|
+
.sort((a, b) => String(b.last_seen).localeCompare(String(a.last_seen)))
|
|
35
|
+
|
|
36
|
+
if (options.json) {
|
|
37
|
+
console.log(JSON.stringify({ dataRoot, projects }, null, 2))
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log(`[Projects] 数据根目录: ${dataRoot}`)
|
|
42
|
+
console.log(`[Projects] 项目数量: ${projects.length}`)
|
|
43
|
+
console.log('')
|
|
44
|
+
|
|
45
|
+
if (projects.length === 0) {
|
|
46
|
+
console.log('[Projects] 未注册项目。运行一次观察 Hook 或使用 --register-current。')
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
console.log('| ID | 名称 | 最近观察 | 路径 |')
|
|
51
|
+
console.log('|----|------|----------|------|')
|
|
52
|
+
for (const project of projects) {
|
|
53
|
+
console.log(
|
|
54
|
+
`| ${project.id} | ${project.name} | ` +
|
|
55
|
+
`${project.last_seen || 'N/A'} | ${project.root || 'N/A'} |`
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
main()
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 预览或执行 project instinct -> global instinct 推广
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict'
|
|
7
|
+
|
|
8
|
+
const fs = require('fs')
|
|
9
|
+
const path = require('path')
|
|
10
|
+
const {
|
|
11
|
+
ensureDir,
|
|
12
|
+
getDataRoot,
|
|
13
|
+
getGlobalInstinctsDir,
|
|
14
|
+
getProjectContext,
|
|
15
|
+
getProjectInstinctsDir,
|
|
16
|
+
loadConfig,
|
|
17
|
+
parseFrontmatter,
|
|
18
|
+
scanInstincts
|
|
19
|
+
} = require('./project-utils')
|
|
20
|
+
|
|
21
|
+
function parseArgs() {
|
|
22
|
+
const args = process.argv.slice(2)
|
|
23
|
+
return {
|
|
24
|
+
apply: args.includes('--apply'),
|
|
25
|
+
dryRun: args.includes('--dry-run') || !args.includes('--apply'),
|
|
26
|
+
projectId: parseStringArg(args, '--project-id'),
|
|
27
|
+
minConfidence: parseFloat(parseStringArg(args, '--min-confidence') || '0.7')
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function parseStringArg(args, flag) {
|
|
32
|
+
const index = args.indexOf(flag)
|
|
33
|
+
if (index === -1 || !args[index + 1]) return null
|
|
34
|
+
return args[index + 1]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function candidateSlug(filePath) {
|
|
38
|
+
return path.basename(filePath)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function main() {
|
|
42
|
+
const options = parseArgs()
|
|
43
|
+
const config = loadConfig()
|
|
44
|
+
const dataRoot = getDataRoot(config)
|
|
45
|
+
const projectId = options.projectId || getProjectContext({ cwd: process.cwd() }).project_id
|
|
46
|
+
const projectInstinctsDir = getProjectInstinctsDir(dataRoot, projectId)
|
|
47
|
+
const globalInstinctsDir = getGlobalInstinctsDir(dataRoot)
|
|
48
|
+
const files = scanInstincts(projectInstinctsDir, 'project')
|
|
49
|
+
|
|
50
|
+
const candidates = []
|
|
51
|
+
for (const fileInfo of files) {
|
|
52
|
+
const content = fs.readFileSync(fileInfo.path, 'utf8')
|
|
53
|
+
const { meta } = parseFrontmatter(content)
|
|
54
|
+
const confidence = typeof meta.confidence === 'number'
|
|
55
|
+
? meta.confidence
|
|
56
|
+
: parseFloat(meta.confidence) || 0
|
|
57
|
+
|
|
58
|
+
if (confidence < options.minConfidence) continue
|
|
59
|
+
|
|
60
|
+
const destination = path.join(globalInstinctsDir, fileInfo.category, candidateSlug(fileInfo.path))
|
|
61
|
+
candidates.push({
|
|
62
|
+
id: meta.id || path.basename(fileInfo.path, '.md'),
|
|
63
|
+
confidence,
|
|
64
|
+
source: fileInfo.path,
|
|
65
|
+
destination,
|
|
66
|
+
exists: fs.existsSync(destination)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
if (options.apply && !fs.existsSync(destination)) {
|
|
70
|
+
ensureDir(path.dirname(destination))
|
|
71
|
+
fs.copyFileSync(fileInfo.path, destination)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
console.log(options.apply ? '[Promote] 已应用推广' : '[Promote] dry-run 预览')
|
|
76
|
+
console.log(`[Promote] 项目: ${projectId}`)
|
|
77
|
+
console.log(`[Promote] 最小置信度: ${options.minConfidence}`)
|
|
78
|
+
console.log('')
|
|
79
|
+
|
|
80
|
+
if (candidates.length === 0) {
|
|
81
|
+
console.log('[Promote] 没有符合条件的候选。')
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log('| 直觉 | 置信度 | 状态 | 目标 |')
|
|
86
|
+
console.log('|------|--------|------|------|')
|
|
87
|
+
for (const candidate of candidates) {
|
|
88
|
+
const status = candidate.exists
|
|
89
|
+
? '已存在,跳过'
|
|
90
|
+
: options.apply ? '已复制' : '将复制'
|
|
91
|
+
console.log(
|
|
92
|
+
`| ${candidate.id} | ${candidate.confidence} | ` +
|
|
93
|
+
`${status} | ${candidate.destination} |`
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
main()
|