@danielstyle/featflow 0.0.0-stage → 0.6.4
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/LICENSE +21 -0
- package/README.md +249 -2
- package/README.zh-CN.md +250 -0
- package/bin/featflow.mjs +116 -0
- package/package.json +63 -4
- package/skills/featflow/SKILL.md +127 -0
- package/skills/featflow-issues/SKILL.md +104 -0
- package/skills/featflow-regression/SKILL.md +63 -0
- package/src/agent-docs.mjs +143 -0
- package/src/changed-files.mjs +204 -0
- package/src/commands/cleanup.mjs +221 -0
- package/src/commands/codegraph.mjs +108 -0
- package/src/commands/doctor.mjs +303 -0
- package/src/commands/finish.mjs +249 -0
- package/src/commands/hook-cmd.mjs +78 -0
- package/src/commands/hooks-cmd.mjs +247 -0
- package/src/commands/init.mjs +477 -0
- package/src/commands/issue.mjs +434 -0
- package/src/commands/new.mjs +311 -0
- package/src/commands/plan-check.mjs +75 -0
- package/src/commands/policy-cmd.mjs +55 -0
- package/src/commands/pr-cleanup.mjs +194 -0
- package/src/commands/regression.mjs +206 -0
- package/src/commands/setup.mjs +343 -0
- package/src/commands/size-check.mjs +137 -0
- package/src/commands/skills.mjs +181 -0
- package/src/commands/status.mjs +100 -0
- package/src/commands/sync.mjs +421 -0
- package/src/commands/verify.mjs +206 -0
- package/src/commands/worktree.mjs +205 -0
- package/src/config.mjs +295 -0
- package/src/detect.mjs +314 -0
- package/src/git.mjs +331 -0
- package/src/hook-adapters.mjs +218 -0
- package/src/hooks-core.mjs +420 -0
- package/src/index.mjs +14 -0
- package/src/init-args.mjs +294 -0
- package/src/init-hooks.mjs +312 -0
- package/src/init-prompts.mjs +191 -0
- package/src/issues-helpers.mjs +463 -0
- package/src/issues.mjs +521 -0
- package/src/plan.mjs +202 -0
- package/src/policy.mjs +143 -0
- package/src/regression.mjs +338 -0
- package/src/size-check.mjs +203 -0
- package/src/skills-manager.mjs +348 -0
- package/src/tui-select.mjs +378 -0
- package/templates/adapters/antigravity/hooks.json +42 -0
- package/templates/adapters/claude-code/settings.json +46 -0
- package/templates/adapters/codex/config.toml +19 -0
- package/templates/adapters/cursor/hooks.json +27 -0
- package/templates/agents/codex/codebase-locator.toml +28 -0
- package/templates/agents/codex/implementation-scout.toml +28 -0
- package/templates/agents/codex/regression-guard-planner.toml +20 -0
- package/templates/features/README.md +56 -0
- package/templates/features/_program_template.md +79 -0
- package/templates/features/_template.md +120 -0
- package/templates/features/current-feature.md +18 -0
- package/templates/githooks/post-merge +10 -0
- package/templates/githooks/pre-commit +14 -0
- package/templates/githooks/pre-push +13 -0
- package/templates/regression/regression-ledger.yml +23 -0
- package/templates/snippets/AGENTS-workflow.md +21 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { changedFileSelection, existingFiles, matchesAnyPattern, normalizeRelPath } from "./changed-files.mjs";
|
|
6
|
+
import { resolveFileSizeBudget } from "./config.mjs";
|
|
7
|
+
|
|
8
|
+
const STYLE_EXTENSIONS = new Set([".css", ".scss", ".sass", ".less"]);
|
|
9
|
+
|
|
10
|
+
function gitLsFiles(repoRoot, extraArgs = []) {
|
|
11
|
+
const res = spawnSync("git", ["ls-files", "-z", ...extraArgs], {
|
|
12
|
+
cwd: repoRoot,
|
|
13
|
+
encoding: "utf8",
|
|
14
|
+
});
|
|
15
|
+
if (res.status !== 0) {
|
|
16
|
+
throw new Error((res.stderr || "git ls-files failed").trim());
|
|
17
|
+
}
|
|
18
|
+
return (res.stdout ?? "").split("\0").filter(Boolean).map(normalizeRelPath);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isTestFilePath(relPath) {
|
|
22
|
+
const norm = normalizeRelPath(relPath);
|
|
23
|
+
const base = path.basename(norm);
|
|
24
|
+
return (
|
|
25
|
+
norm.startsWith("test/") ||
|
|
26
|
+
norm.startsWith("tests/") ||
|
|
27
|
+
norm.includes("/tests/") ||
|
|
28
|
+
norm.includes("/test/") ||
|
|
29
|
+
norm.includes("/__tests__/") ||
|
|
30
|
+
/\.(?:spec|test)\.[a-z0-9]+$/i.test(base) ||
|
|
31
|
+
/^test_.+\.py$/i.test(base) ||
|
|
32
|
+
/_test\.[^.]+$/i.test(base)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isStyleFilePath(relPath) {
|
|
37
|
+
return STYLE_EXTENSIONS.has(path.extname(relPath).toLowerCase());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function countFileLines(absPath) {
|
|
41
|
+
const content = readFileSync(absPath, "utf8");
|
|
42
|
+
if (content.length === 0) {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
const normalized = content.replace(/\r\n/g, "\n");
|
|
46
|
+
return normalized.split("\n").length - (normalized.endsWith("\n") ? 1 : 0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function budgetForFile(relPath, budgetConfig) {
|
|
50
|
+
if (isStyleFilePath(relPath)) {
|
|
51
|
+
return { category: "style", budget: budgetConfig.style };
|
|
52
|
+
}
|
|
53
|
+
if (isTestFilePath(relPath)) {
|
|
54
|
+
return { category: "test", budget: budgetConfig.test };
|
|
55
|
+
}
|
|
56
|
+
return { category: "production", budget: budgetConfig.production };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function loadSizeBaseline(repoRoot, baselineFile) {
|
|
60
|
+
if (!baselineFile) {
|
|
61
|
+
return { path: null, entries: {} };
|
|
62
|
+
}
|
|
63
|
+
const absPath = path.resolve(repoRoot, baselineFile);
|
|
64
|
+
if (!existsSync(absPath)) {
|
|
65
|
+
return { path: absPath, entries: {} };
|
|
66
|
+
}
|
|
67
|
+
const parsed = JSON.parse(readFileSync(absPath, "utf8"));
|
|
68
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
69
|
+
throw new Error(`Invalid file size baseline at ${absPath}: expected a JSON object.`);
|
|
70
|
+
}
|
|
71
|
+
const entries = {};
|
|
72
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
73
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
74
|
+
entries[normalizeRelPath(key)] = Math.floor(value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return { path: absPath, entries };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function evaluateFileSizeBudget(repoRoot, config, options = {}) {
|
|
81
|
+
const budgetConfig = options.budgetConfig ?? resolveFileSizeBudget(config);
|
|
82
|
+
const extSet = new Set(budgetConfig.extensions.map((ext) => ext.toLowerCase()));
|
|
83
|
+
const { entries: baseline } = loadSizeBaseline(repoRoot, budgetConfig.baselineFile);
|
|
84
|
+
const staleBaseline = new Set(Object.keys(baseline));
|
|
85
|
+
|
|
86
|
+
let candidatePaths;
|
|
87
|
+
let selection = null;
|
|
88
|
+
if (options.changed || (options.files && options.files.length > 0)) {
|
|
89
|
+
selection = changedFileSelection(repoRoot, config, {
|
|
90
|
+
base: options.base,
|
|
91
|
+
head: options.head,
|
|
92
|
+
files: options.files,
|
|
93
|
+
});
|
|
94
|
+
candidatePaths = existingFiles(repoRoot, selection.files);
|
|
95
|
+
} else {
|
|
96
|
+
candidatePaths = [
|
|
97
|
+
...new Set([...gitLsFiles(repoRoot), ...gitLsFiles(repoRoot, ["--others", "--exclude-standard"])]),
|
|
98
|
+
].sort();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const failures = [];
|
|
102
|
+
const tightenable = [];
|
|
103
|
+
let checkedCount = 0;
|
|
104
|
+
|
|
105
|
+
for (const relPath of candidatePaths) {
|
|
106
|
+
const ext = path.extname(relPath).toLowerCase();
|
|
107
|
+
if (!extSet.has(ext)) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (matchesAnyPattern(relPath, budgetConfig.ignore)) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const absPath = path.resolve(repoRoot, relPath);
|
|
114
|
+
if (!existsSync(absPath)) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
checkedCount += 1;
|
|
119
|
+
staleBaseline.delete(relPath);
|
|
120
|
+
|
|
121
|
+
const lines = countFileLines(absPath);
|
|
122
|
+
const { category, budget } = budgetForFile(relPath, budgetConfig);
|
|
123
|
+
const baselineLimit = baseline[relPath];
|
|
124
|
+
const hasBaseline = typeof baselineLimit === "number";
|
|
125
|
+
const limit = hasBaseline ? Math.max(budget, baselineLimit) : budget;
|
|
126
|
+
|
|
127
|
+
if (lines > limit) {
|
|
128
|
+
failures.push({
|
|
129
|
+
path: relPath,
|
|
130
|
+
category,
|
|
131
|
+
lines,
|
|
132
|
+
budget,
|
|
133
|
+
baselineLimit: hasBaseline ? baselineLimit : null,
|
|
134
|
+
limit,
|
|
135
|
+
label: hasBaseline ? `baseline ${baselineLimit}` : `budget ${budget}`,
|
|
136
|
+
});
|
|
137
|
+
} else if (hasBaseline && lines < baselineLimit) {
|
|
138
|
+
tightenable.push({ path: relPath, lines, baselineLimit, budget });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const stale = options.changed || (options.files && options.files.length > 0) ? [] : [...staleBaseline].sort();
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
ok: failures.length === 0,
|
|
146
|
+
changedOnly: Boolean(options.changed || (options.files && options.files.length > 0)),
|
|
147
|
+
selection,
|
|
148
|
+
checkedCount,
|
|
149
|
+
budgets: {
|
|
150
|
+
production: budgetConfig.production,
|
|
151
|
+
style: budgetConfig.style,
|
|
152
|
+
test: budgetConfig.test,
|
|
153
|
+
},
|
|
154
|
+
baselineFile: budgetConfig.baselineFile,
|
|
155
|
+
failures,
|
|
156
|
+
staleBaseline: stale,
|
|
157
|
+
tightenable,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function updateFileSizeBaseline(repoRoot, config, options = {}) {
|
|
162
|
+
const budgetConfig = options.budgetConfig ?? resolveFileSizeBudget(config);
|
|
163
|
+
if (!budgetConfig.baselineFile) {
|
|
164
|
+
throw new Error("Cannot update baseline because `fileSizeBudget.baselineFile` is null.");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const extSet = new Set(budgetConfig.extensions.map((ext) => ext.toLowerCase()));
|
|
168
|
+
const allPaths = [
|
|
169
|
+
...new Set([...gitLsFiles(repoRoot), ...gitLsFiles(repoRoot, ["--others", "--exclude-standard"])]),
|
|
170
|
+
].sort();
|
|
171
|
+
|
|
172
|
+
const nextBaseline = {};
|
|
173
|
+
let checkedCount = 0;
|
|
174
|
+
|
|
175
|
+
for (const relPath of allPaths) {
|
|
176
|
+
if (!extSet.has(path.extname(relPath).toLowerCase())) continue;
|
|
177
|
+
if (matchesAnyPattern(relPath, budgetConfig.ignore)) continue;
|
|
178
|
+
const absPath = path.resolve(repoRoot, relPath);
|
|
179
|
+
if (!existsSync(absPath)) continue;
|
|
180
|
+
|
|
181
|
+
checkedCount += 1;
|
|
182
|
+
const lines = countFileLines(absPath);
|
|
183
|
+
const { budget } = budgetForFile(relPath, budgetConfig);
|
|
184
|
+
if (lines > budget) {
|
|
185
|
+
nextBaseline[relPath] = lines;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const absTarget = path.resolve(repoRoot, budgetConfig.baselineFile);
|
|
190
|
+
if (!options.dryRun) {
|
|
191
|
+
mkdirSync(path.dirname(absTarget), { recursive: true });
|
|
192
|
+
writeFileSync(absTarget, `${JSON.stringify(nextBaseline, null, 2)}\n`, "utf8");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
baselineFile: budgetConfig.baselineFile,
|
|
197
|
+
absPath: absTarget,
|
|
198
|
+
checkedCount,
|
|
199
|
+
entryCount: Object.keys(nextBaseline).length,
|
|
200
|
+
entries: nextBaseline,
|
|
201
|
+
dryRun: Boolean(options.dryRun),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, rmSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { packageRoot } from "./config.mjs";
|
|
6
|
+
import { commandExists, findMainRepoRoot } from "./git.mjs";
|
|
7
|
+
|
|
8
|
+
export const BUNDLED_SKILLS = ["featflow", "featflow-issues", "featflow-regression"];
|
|
9
|
+
|
|
10
|
+
export const GLOBAL_SKILL_AGENTS = [
|
|
11
|
+
{
|
|
12
|
+
id: "agents",
|
|
13
|
+
label: "Standard (.agents / Antigravity / Codex / Cursor)",
|
|
14
|
+
parentDir: ".agents",
|
|
15
|
+
skillsRel: path.join(".agents", "skills"),
|
|
16
|
+
alwaysDefault: true,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "claude-code",
|
|
20
|
+
label: "Claude Code (.claude)",
|
|
21
|
+
parentDir: ".claude",
|
|
22
|
+
skillsRel: path.join(".claude", "skills"),
|
|
23
|
+
alwaysDefault: false,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "codex",
|
|
27
|
+
label: "OpenAI Codex (.codex)",
|
|
28
|
+
parentDir: ".codex",
|
|
29
|
+
skillsRel: path.join(".codex", "skills"),
|
|
30
|
+
alwaysDefault: false,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "cursor",
|
|
34
|
+
label: "Cursor (.cursor)",
|
|
35
|
+
parentDir: ".cursor",
|
|
36
|
+
skillsRel: path.join(".cursor", "skills"),
|
|
37
|
+
alwaysDefault: false,
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const AGENT_ALIASES = {
|
|
42
|
+
agents: "agents",
|
|
43
|
+
standard: "agents",
|
|
44
|
+
antigravity: "agents",
|
|
45
|
+
agy: "agents",
|
|
46
|
+
claude: "claude-code",
|
|
47
|
+
"claude-code": "claude-code",
|
|
48
|
+
codex: "codex",
|
|
49
|
+
cursor: "cursor",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function normalizeLineEndings(content) {
|
|
53
|
+
return content.replace(/\r\n/g, "\n");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function resolveFeatflowHome(env = process.env) {
|
|
57
|
+
return env.FEATFLOW_HOME || os.homedir() || "";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function formatHomePath(absPath, home) {
|
|
61
|
+
if (home && absPath.startsWith(home)) {
|
|
62
|
+
return `~${absPath.slice(home.length).replaceAll("\\", "/")}`;
|
|
63
|
+
}
|
|
64
|
+
return absPath.replaceAll("\\", "/");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function bundledSkillSourcePath(skillName) {
|
|
68
|
+
return path.join(packageRoot, "skills", skillName, "SKILL.md");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function parseSkillNamesList(rawValue) {
|
|
72
|
+
const normalized = String(rawValue ?? "").trim().toLowerCase();
|
|
73
|
+
if (!normalized || normalized === "all") {
|
|
74
|
+
return [...BUNDLED_SKILLS];
|
|
75
|
+
}
|
|
76
|
+
const result = [];
|
|
77
|
+
for (const item of normalized.split(",").map((s) => s.trim()).filter(Boolean)) {
|
|
78
|
+
if (!BUNDLED_SKILLS.includes(item)) {
|
|
79
|
+
throw new Error(`Unknown skill "${item}". Expected comma-separated values from: ${BUNDLED_SKILLS.join(", ")}, or "all".`);
|
|
80
|
+
}
|
|
81
|
+
if (!result.includes(item)) {
|
|
82
|
+
result.push(item);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (result.length === 0) {
|
|
86
|
+
throw new Error(`--only requires at least one skill (${BUNDLED_SKILLS.join(", ")}).`);
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function parseGlobalSkillAgents(rawValue) {
|
|
92
|
+
const normalized = String(rawValue ?? "").trim().toLowerCase();
|
|
93
|
+
if (!normalized || normalized === "auto") {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
if (normalized === "all") {
|
|
97
|
+
return GLOBAL_SKILL_AGENTS.map((entry) => entry.id);
|
|
98
|
+
}
|
|
99
|
+
const result = [];
|
|
100
|
+
for (const item of normalized.split(",").map((s) => s.trim()).filter(Boolean)) {
|
|
101
|
+
const mapped = AGENT_ALIASES[item];
|
|
102
|
+
if (!mapped) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Unknown agent target "${item}". Expected comma-separated values from: agents, antigravity, claude-code, codex, cursor, "all", or "auto".`,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
if (!result.includes(mapped)) {
|
|
108
|
+
result.push(mapped);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function requiredSkillsForConfig(config) {
|
|
115
|
+
const names = ["featflow"];
|
|
116
|
+
if (config?.issues) {
|
|
117
|
+
names.push("featflow-issues");
|
|
118
|
+
}
|
|
119
|
+
if (config?.regression) {
|
|
120
|
+
names.push("featflow-regression");
|
|
121
|
+
}
|
|
122
|
+
return names;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function mapHookAgentsToSkillTargets(hookFlags = {}) {
|
|
126
|
+
const targets = ["agents"];
|
|
127
|
+
if (hookFlags.withClaudeHooks) targets.push("claude-code");
|
|
128
|
+
if (hookFlags.withCodexHooks) targets.push("codex");
|
|
129
|
+
if (hookFlags.withCursorHooks) targets.push("cursor");
|
|
130
|
+
return targets;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function resolveGlobalSkillTargets({ home, agents = null, ensureAgents = [] }) {
|
|
134
|
+
if (!home) {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
const explicitSet = Array.isArray(agents) ? new Set(agents) : null;
|
|
138
|
+
const ensureSet = new Set(ensureAgents);
|
|
139
|
+
|
|
140
|
+
const selected = [];
|
|
141
|
+
for (const entry of GLOBAL_SKILL_AGENTS) {
|
|
142
|
+
const parentAbs = path.join(home, entry.parentDir);
|
|
143
|
+
const shouldInclude = explicitSet
|
|
144
|
+
? explicitSet.has(entry.id)
|
|
145
|
+
: entry.alwaysDefault || ensureSet.has(entry.id) || existsSync(parentAbs);
|
|
146
|
+
if (!shouldInclude) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const skillsDir = path.join(home, entry.skillsRel);
|
|
150
|
+
selected.push({
|
|
151
|
+
...entry,
|
|
152
|
+
skillsDir,
|
|
153
|
+
displayDir: formatHomePath(skillsDir, home),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return selected;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function inspectSkillFile(srcPath, destPath) {
|
|
160
|
+
if (!existsSync(destPath)) {
|
|
161
|
+
return "missing";
|
|
162
|
+
}
|
|
163
|
+
const expected = normalizeLineEndings(readFileSync(srcPath, "utf8"));
|
|
164
|
+
const actual = normalizeLineEndings(readFileSync(destPath, "utf8"));
|
|
165
|
+
return expected === actual ? "up-to-date" : "drifted";
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function isSymlink(targetPath) {
|
|
169
|
+
try {
|
|
170
|
+
return lstatSync(targetPath).isSymbolicLink();
|
|
171
|
+
} catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function inspectSkillsStatus({
|
|
177
|
+
repoRoot = null,
|
|
178
|
+
skillNames = BUNDLED_SKILLS,
|
|
179
|
+
agents = null,
|
|
180
|
+
ensureAgents = [],
|
|
181
|
+
env = process.env,
|
|
182
|
+
} = {}) {
|
|
183
|
+
const home = resolveFeatflowHome(env);
|
|
184
|
+
const targets = resolveGlobalSkillTargets({ home, agents, ensureAgents });
|
|
185
|
+
const skills = [];
|
|
186
|
+
|
|
187
|
+
for (const name of skillNames) {
|
|
188
|
+
const srcPath = bundledSkillSourcePath(name);
|
|
189
|
+
const globalTargets = targets.map((target) => {
|
|
190
|
+
const destPath = path.join(target.skillsDir, name, "SKILL.md");
|
|
191
|
+
const status = inspectSkillFile(srcPath, destPath);
|
|
192
|
+
return {
|
|
193
|
+
agentId: target.id,
|
|
194
|
+
label: target.label,
|
|
195
|
+
path: destPath,
|
|
196
|
+
display: formatHomePath(destPath, home),
|
|
197
|
+
status,
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const repoPath = repoRoot ? path.join(repoRoot, ".agents", "skills", name, "SKILL.md") : null;
|
|
202
|
+
const repoStatus = repoPath ? inspectSkillFile(srcPath, repoPath) : "missing";
|
|
203
|
+
|
|
204
|
+
const upToDateCount = globalTargets.filter((t) => t.status === "up-to-date").length;
|
|
205
|
+
const driftedCount = globalTargets.filter((t) => t.status === "drifted").length;
|
|
206
|
+
const missingCount = globalTargets.filter((t) => t.status === "missing").length;
|
|
207
|
+
const hasAnyGlobal = upToDateCount > 0 || driftedCount > 0;
|
|
208
|
+
const allTargetsUpToDate = globalTargets.length > 0 && driftedCount === 0 && missingCount === 0;
|
|
209
|
+
const hasRepoCopy = repoStatus !== "missing";
|
|
210
|
+
|
|
211
|
+
skills.push({
|
|
212
|
+
name,
|
|
213
|
+
globalTargets,
|
|
214
|
+
hasAnyGlobal,
|
|
215
|
+
allTargetsUpToDate,
|
|
216
|
+
upToDateCount,
|
|
217
|
+
driftedCount,
|
|
218
|
+
missingCount,
|
|
219
|
+
repoPath,
|
|
220
|
+
repoStatus,
|
|
221
|
+
hasRepoCopy,
|
|
222
|
+
repoShadowsGlobal: hasRepoCopy && hasAnyGlobal,
|
|
223
|
+
repoStaleShadow: repoStatus === "drifted" && hasAnyGlobal,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
home,
|
|
229
|
+
targets,
|
|
230
|
+
skills,
|
|
231
|
+
allGlobalReady: skills.length > 0 && skills.every((s) => s.allTargetsUpToDate),
|
|
232
|
+
missingSkills: skills.filter((s) => s.missingCount > 0).map((s) => s.name),
|
|
233
|
+
driftedSkills: skills.filter((s) => s.driftedCount > 0).map((s) => s.name),
|
|
234
|
+
shadowedSkills: skills.filter((s) => s.repoShadowsGlobal).map((s) => s.name),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function installGlobalSkills({
|
|
239
|
+
skillNames = BUNDLED_SKILLS,
|
|
240
|
+
agents = null,
|
|
241
|
+
ensureAgents = [],
|
|
242
|
+
dryRun = false,
|
|
243
|
+
env = process.env,
|
|
244
|
+
} = {}) {
|
|
245
|
+
const home = resolveFeatflowHome(env);
|
|
246
|
+
if (!home) {
|
|
247
|
+
throw new Error("Could not resolve home directory for global skill installation.");
|
|
248
|
+
}
|
|
249
|
+
const targets = resolveGlobalSkillTargets({ home, agents, ensureAgents });
|
|
250
|
+
const installed = [];
|
|
251
|
+
const updated = [];
|
|
252
|
+
const upToDate = [];
|
|
253
|
+
|
|
254
|
+
for (const target of targets) {
|
|
255
|
+
for (const name of skillNames) {
|
|
256
|
+
const srcPath = bundledSkillSourcePath(name);
|
|
257
|
+
const skillDir = path.join(target.skillsDir, name);
|
|
258
|
+
const destPath = path.join(skillDir, "SKILL.md");
|
|
259
|
+
const display = formatHomePath(destPath, home);
|
|
260
|
+
|
|
261
|
+
const status = inspectSkillFile(srcPath, destPath);
|
|
262
|
+
if (status === "up-to-date") {
|
|
263
|
+
upToDate.push({ name, agentId: target.id, path: destPath, display });
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (!dryRun) {
|
|
268
|
+
if (isSymlink(skillDir) && !existsSync(skillDir)) {
|
|
269
|
+
rmSync(skillDir, { force: true });
|
|
270
|
+
}
|
|
271
|
+
mkdirSync(skillDir, { recursive: true });
|
|
272
|
+
if (isSymlink(destPath) && !existsSync(destPath)) {
|
|
273
|
+
rmSync(destPath, { force: true });
|
|
274
|
+
}
|
|
275
|
+
copyFileSync(srcPath, destPath);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (status === "missing") {
|
|
279
|
+
installed.push({ name, agentId: target.id, path: destPath, display });
|
|
280
|
+
} else {
|
|
281
|
+
updated.push({ name, agentId: target.id, path: destPath, display });
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
home,
|
|
288
|
+
dryRun,
|
|
289
|
+
targets: targets.map((t) => ({ id: t.id, displayDir: t.displayDir })),
|
|
290
|
+
installed,
|
|
291
|
+
updated,
|
|
292
|
+
upToDate,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function uninstallGlobalSkills({
|
|
297
|
+
skillNames = BUNDLED_SKILLS,
|
|
298
|
+
agents = null,
|
|
299
|
+
dryRun = false,
|
|
300
|
+
env = process.env,
|
|
301
|
+
} = {}) {
|
|
302
|
+
const home = resolveFeatflowHome(env);
|
|
303
|
+
if (!home) {
|
|
304
|
+
throw new Error("Could not resolve home directory.");
|
|
305
|
+
}
|
|
306
|
+
const agentList = agents ?? GLOBAL_SKILL_AGENTS.map((entry) => entry.id);
|
|
307
|
+
const targets = resolveGlobalSkillTargets({ home, agents: agentList });
|
|
308
|
+
const removed = [];
|
|
309
|
+
|
|
310
|
+
for (const target of targets) {
|
|
311
|
+
for (const name of skillNames) {
|
|
312
|
+
const skillDir = path.join(target.skillsDir, name);
|
|
313
|
+
const skillFile = path.join(skillDir, "SKILL.md");
|
|
314
|
+
if (!existsSync(skillFile) && !isSymlink(skillDir)) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (!dryRun) {
|
|
318
|
+
rmSync(skillDir, { recursive: true, force: true });
|
|
319
|
+
}
|
|
320
|
+
removed.push({
|
|
321
|
+
name,
|
|
322
|
+
agentId: target.id,
|
|
323
|
+
path: skillDir,
|
|
324
|
+
display: formatHomePath(skillDir, home),
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return { home, dryRun, removed };
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export function inspectCliAvailability(repoRoot = null) {
|
|
333
|
+
const binName = process.platform === "win32" ? "featflow.cmd" : "featflow";
|
|
334
|
+
const onPath = commandExists("featflow");
|
|
335
|
+
const localBinPath = repoRoot ? path.join(repoRoot, "node_modules", ".bin", binName) : "";
|
|
336
|
+
const localBin = Boolean(localBinPath && existsSync(localBinPath));
|
|
337
|
+
|
|
338
|
+
const mainRoot = repoRoot ? (findMainRepoRoot(repoRoot) ?? repoRoot) : null;
|
|
339
|
+
const mainBinPath = mainRoot ? path.join(mainRoot, "node_modules", ".bin", binName) : "";
|
|
340
|
+
const mainLocalBin = Boolean(mainBinPath && existsSync(mainBinPath));
|
|
341
|
+
|
|
342
|
+
return {
|
|
343
|
+
onPath,
|
|
344
|
+
localBin,
|
|
345
|
+
mainLocalBin,
|
|
346
|
+
anyAvailable: onPath || localBin || mainLocalBin,
|
|
347
|
+
};
|
|
348
|
+
}
|