@danielstyle/featflow 0.0.0-stage → 0.6.3
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 +206 -2
- package/README.zh-CN.md +163 -0
- package/bin/featflow.mjs +113 -0
- package/package.json +62 -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 +110 -0
- package/src/commands/doctor.mjs +265 -0
- package/src/commands/finish.mjs +249 -0
- package/src/commands/hook-cmd.mjs +78 -0
- package/src/commands/hooks-cmd.mjs +238 -0
- package/src/commands/init.mjs +382 -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 +51 -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/status.mjs +100 -0
- package/src/commands/sync.mjs +407 -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 +13 -0
- package/src/init-args.mjs +282 -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/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 +7 -0
- package/templates/githooks/pre-commit +11 -0
- package/templates/githooks/pre-push +10 -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,378 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
|
|
3
|
+
export function createPromptReader() {
|
|
4
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
5
|
+
const queuedLines = [];
|
|
6
|
+
const waiters = [];
|
|
7
|
+
let closed = false;
|
|
8
|
+
|
|
9
|
+
rl.on("line", (line) => {
|
|
10
|
+
if (waiters.length > 0) {
|
|
11
|
+
const resolve = waiters.shift();
|
|
12
|
+
resolve(line);
|
|
13
|
+
} else {
|
|
14
|
+
queuedLines.push(line);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
rl.on("close", () => {
|
|
19
|
+
closed = true;
|
|
20
|
+
while (waiters.length > 0) {
|
|
21
|
+
const resolve = waiters.shift();
|
|
22
|
+
resolve("");
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
async question(promptText) {
|
|
28
|
+
process.stdout.write(promptText);
|
|
29
|
+
if (queuedLines.length > 0) {
|
|
30
|
+
return queuedLines.shift();
|
|
31
|
+
}
|
|
32
|
+
if (closed) {
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
waiters.push(resolve);
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
close() {
|
|
40
|
+
rl.close();
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function isRawTtySupported() {
|
|
46
|
+
return Boolean(
|
|
47
|
+
process.stdin.isTTY &&
|
|
48
|
+
process.stdout.isTTY &&
|
|
49
|
+
typeof process.stdin.setRawMode === "function" &&
|
|
50
|
+
process.env.FEATFLOW_FORCE_TTY !== "1",
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function createSmartPrompter() {
|
|
55
|
+
let rl = null;
|
|
56
|
+
const rawTty = isRawTtySupported();
|
|
57
|
+
|
|
58
|
+
function ensureRl() {
|
|
59
|
+
if (!rl) {
|
|
60
|
+
rl = createPromptReader();
|
|
61
|
+
}
|
|
62
|
+
return rl;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function releaseRl() {
|
|
66
|
+
if (rl) {
|
|
67
|
+
rl.close();
|
|
68
|
+
rl = null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
isRawTty: rawTty,
|
|
74
|
+
async question(promptText) {
|
|
75
|
+
return ensureRl().question(promptText);
|
|
76
|
+
},
|
|
77
|
+
releaseRl,
|
|
78
|
+
close() {
|
|
79
|
+
releaseRl();
|
|
80
|
+
if (rawTty) {
|
|
81
|
+
process.stdin.pause();
|
|
82
|
+
if (typeof process.stdin.unref === "function") {
|
|
83
|
+
process.stdin.unref();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function visualLineCount(lines) {
|
|
91
|
+
const cols = Math.max(20, process.stdout.columns || 80);
|
|
92
|
+
let total = 0;
|
|
93
|
+
for (const line of lines) {
|
|
94
|
+
total += Math.max(1, Math.ceil(line.length / cols));
|
|
95
|
+
}
|
|
96
|
+
return total;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function renderLines(lines, prevVisualRows) {
|
|
100
|
+
if (prevVisualRows > 0) {
|
|
101
|
+
process.stdout.write(`\x1b[${prevVisualRows}A\x1b[0J`);
|
|
102
|
+
}
|
|
103
|
+
process.stdout.write(`${lines.join("\n")}\n`);
|
|
104
|
+
return visualLineCount(lines);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function tokenizeRawKeys(text) {
|
|
108
|
+
const keys = [];
|
|
109
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
110
|
+
if (text[i] === "\x1b") {
|
|
111
|
+
if ((text[i + 1] === "[" || text[i + 1] === "O") && i + 2 < text.length) {
|
|
112
|
+
keys.push(text.slice(i, i + 3));
|
|
113
|
+
i += 2;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
keys.push("\x1b");
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
keys.push(text[i]);
|
|
120
|
+
}
|
|
121
|
+
return keys;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function runRawSingleSelect(title, choices, defaultId) {
|
|
125
|
+
return new Promise((resolve) => {
|
|
126
|
+
const initialIdx = choices.findIndex((c) => c.id === defaultId);
|
|
127
|
+
let cursor = initialIdx >= 0 ? initialIdx : 0;
|
|
128
|
+
let renderedRows = 0;
|
|
129
|
+
|
|
130
|
+
const buildLines = () => [
|
|
131
|
+
`${title} (↑/↓ move, Enter confirm)`,
|
|
132
|
+
...choices.map((choice, idx) => {
|
|
133
|
+
const pointer = idx === cursor ? ">" : " ";
|
|
134
|
+
const radio = idx === cursor ? "(•)" : "( )";
|
|
135
|
+
const detail = choice.detail ? ` — ${choice.detail}` : "";
|
|
136
|
+
return ` ${pointer} ${radio} ${choice.label}${detail}`;
|
|
137
|
+
}),
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
const stdin = process.stdin;
|
|
141
|
+
const prevRaw = stdin.isRaw;
|
|
142
|
+
stdin.setRawMode(true);
|
|
143
|
+
stdin.resume();
|
|
144
|
+
process.stdout.write("\x1b[?25l");
|
|
145
|
+
renderedRows = renderLines(buildLines(), 0);
|
|
146
|
+
|
|
147
|
+
const cleanup = () => {
|
|
148
|
+
stdin.off("data", onData);
|
|
149
|
+
if (typeof stdin.setRawMode === "function") {
|
|
150
|
+
stdin.setRawMode(Boolean(prevRaw));
|
|
151
|
+
}
|
|
152
|
+
stdin.pause();
|
|
153
|
+
process.stdout.write("\x1b[?25h");
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const onData = (chunk) => {
|
|
157
|
+
let dirty = false;
|
|
158
|
+
for (const key of tokenizeRawKeys(chunk.toString("utf8"))) {
|
|
159
|
+
if (key === "\x03") {
|
|
160
|
+
cleanup();
|
|
161
|
+
process.stdout.write("\n");
|
|
162
|
+
process.exit(130);
|
|
163
|
+
}
|
|
164
|
+
if (key === "\r" || key === "\n") {
|
|
165
|
+
cleanup();
|
|
166
|
+
const chosen = choices[cursor];
|
|
167
|
+
if (renderedRows > 0) {
|
|
168
|
+
process.stdout.write(`\x1b[${renderedRows}A\x1b[0J`);
|
|
169
|
+
}
|
|
170
|
+
process.stdout.write(`${title}: ${chosen.label}\n`);
|
|
171
|
+
resolve(chosen.id);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (key === "\x1b[A" || key === "\x1bOA" || key === "k" || key === "K") {
|
|
175
|
+
cursor = (cursor - 1 + choices.length) % choices.length;
|
|
176
|
+
dirty = true;
|
|
177
|
+
} else if (key === "\x1b[B" || key === "\x1bOB" || key === "j" || key === "J") {
|
|
178
|
+
cursor = (cursor + 1) % choices.length;
|
|
179
|
+
dirty = true;
|
|
180
|
+
} else if (/^[1-9]$/.test(key)) {
|
|
181
|
+
const idx = Number.parseInt(key, 10) - 1;
|
|
182
|
+
if (idx >= 0 && idx < choices.length) {
|
|
183
|
+
cursor = idx;
|
|
184
|
+
dirty = true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (dirty) {
|
|
189
|
+
renderedRows = renderLines(buildLines(), renderedRows);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
stdin.on("data", onData);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function runRawMultiSelect(title, choices) {
|
|
198
|
+
return new Promise((resolve) => {
|
|
199
|
+
const selected = new Set(choices.filter((item) => item.checked).map((item) => item.id));
|
|
200
|
+
let cursor = 0;
|
|
201
|
+
let renderedRows = 0;
|
|
202
|
+
|
|
203
|
+
const buildLines = () => [
|
|
204
|
+
`${title} (↑/↓ move, Space toggle, a all/none, Enter confirm)`,
|
|
205
|
+
...choices.map((choice, idx) => {
|
|
206
|
+
const pointer = idx === cursor ? ">" : " ";
|
|
207
|
+
const box = selected.has(choice.id) ? "[x]" : "[ ]";
|
|
208
|
+
const detail = choice.detail ? ` — ${choice.detail}` : "";
|
|
209
|
+
return ` ${pointer} ${box} ${choice.label}${detail}`;
|
|
210
|
+
}),
|
|
211
|
+
];
|
|
212
|
+
|
|
213
|
+
const stdin = process.stdin;
|
|
214
|
+
const prevRaw = stdin.isRaw;
|
|
215
|
+
stdin.setRawMode(true);
|
|
216
|
+
stdin.resume();
|
|
217
|
+
process.stdout.write("\x1b[?25l");
|
|
218
|
+
renderedRows = renderLines(buildLines(), 0);
|
|
219
|
+
|
|
220
|
+
const cleanup = () => {
|
|
221
|
+
stdin.off("data", onData);
|
|
222
|
+
if (typeof stdin.setRawMode === "function") {
|
|
223
|
+
stdin.setRawMode(Boolean(prevRaw));
|
|
224
|
+
}
|
|
225
|
+
stdin.pause();
|
|
226
|
+
process.stdout.write("\x1b[?25h");
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const toggleId = (id) => {
|
|
230
|
+
if (selected.has(id)) selected.delete(id);
|
|
231
|
+
else selected.add(id);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const onData = (chunk) => {
|
|
235
|
+
let dirty = false;
|
|
236
|
+
for (const key of tokenizeRawKeys(chunk.toString("utf8"))) {
|
|
237
|
+
if (key === "\x03") {
|
|
238
|
+
cleanup();
|
|
239
|
+
process.stdout.write("\n");
|
|
240
|
+
process.exit(130);
|
|
241
|
+
}
|
|
242
|
+
if (key === "\r" || key === "\n") {
|
|
243
|
+
cleanup();
|
|
244
|
+
const chosenIds = choices.filter((c) => selected.has(c.id)).map((c) => c.id);
|
|
245
|
+
const chosenLabels = choices.filter((c) => selected.has(c.id)).map((c) => c.label);
|
|
246
|
+
if (renderedRows > 0) {
|
|
247
|
+
process.stdout.write(`\x1b[${renderedRows}A\x1b[0J`);
|
|
248
|
+
}
|
|
249
|
+
process.stdout.write(`${title}: ${chosenLabels.length > 0 ? chosenLabels.join(", ") : "(none)"}\n`);
|
|
250
|
+
resolve(chosenIds);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (key === "\x1b[A" || key === "\x1bOA" || key === "k" || key === "K") {
|
|
254
|
+
cursor = (cursor - 1 + choices.length) % choices.length;
|
|
255
|
+
dirty = true;
|
|
256
|
+
} else if (key === "\x1b[B" || key === "\x1bOB" || key === "j" || key === "J") {
|
|
257
|
+
cursor = (cursor + 1) % choices.length;
|
|
258
|
+
dirty = true;
|
|
259
|
+
} else if (key === " ") {
|
|
260
|
+
toggleId(choices[cursor].id);
|
|
261
|
+
dirty = true;
|
|
262
|
+
} else if (/^[1-9]$/.test(key)) {
|
|
263
|
+
const idx = Number.parseInt(key, 10) - 1;
|
|
264
|
+
if (idx >= 0 && idx < choices.length) {
|
|
265
|
+
cursor = idx;
|
|
266
|
+
toggleId(choices[idx].id);
|
|
267
|
+
dirty = true;
|
|
268
|
+
}
|
|
269
|
+
} else if (key === "a" || key === "A") {
|
|
270
|
+
if (selected.size === choices.length) {
|
|
271
|
+
selected.clear();
|
|
272
|
+
} else {
|
|
273
|
+
for (const choice of choices) selected.add(choice.id);
|
|
274
|
+
}
|
|
275
|
+
dirty = true;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (dirty) {
|
|
279
|
+
renderedRows = renderLines(buildLines(), renderedRows);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
stdin.on("data", onData);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export function parseSingleSelectInput(answer, choices, defaultId) {
|
|
288
|
+
const fallback = defaultId ?? choices[0]?.id ?? "";
|
|
289
|
+
const trimmed = String(answer ?? "").trim().toLowerCase();
|
|
290
|
+
if (!trimmed) {
|
|
291
|
+
return fallback;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const num = Number.parseInt(trimmed, 10);
|
|
295
|
+
if (Number.isInteger(num) && String(num) === trimmed && num >= 1 && num <= choices.length) {
|
|
296
|
+
return choices[num - 1].id;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
for (const choice of choices) {
|
|
300
|
+
if (choice.id.toLowerCase() === trimmed) {
|
|
301
|
+
return choice.id;
|
|
302
|
+
}
|
|
303
|
+
if (Array.isArray(choice.aliases) && choice.aliases.some((alias) => alias.toLowerCase() === trimmed)) {
|
|
304
|
+
return choice.id;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return fallback;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export async function promptSingleSelect(prompter, { title, choices, defaultId }) {
|
|
311
|
+
if (!Array.isArray(choices) || choices.length === 0) {
|
|
312
|
+
return defaultId ?? "";
|
|
313
|
+
}
|
|
314
|
+
const resolvedDefault = choices.some((c) => c.id === defaultId) ? defaultId : choices[0].id;
|
|
315
|
+
|
|
316
|
+
if (prompter?.isRawTty) {
|
|
317
|
+
prompter.releaseRl();
|
|
318
|
+
return runRawSingleSelect(title, choices, resolvedDefault);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
console.log(`${title}:`);
|
|
322
|
+
choices.forEach((choice, idx) => {
|
|
323
|
+
const marker = choice.id === resolvedDefault ? "(•)" : "( )";
|
|
324
|
+
const detail = choice.detail ? ` — ${choice.detail}` : "";
|
|
325
|
+
console.log(` ${idx + 1}. ${marker} ${choice.label}${detail}`);
|
|
326
|
+
});
|
|
327
|
+
const answer = await prompter.question(`Choose [1-${choices.length}] (Enter for ${resolvedDefault}): `);
|
|
328
|
+
return parseSingleSelectInput(answer, choices, resolvedDefault);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function parseMultiSelectInput(answer, choices) {
|
|
332
|
+
const trimmed = String(answer ?? "").trim().toLowerCase();
|
|
333
|
+
if (!trimmed) {
|
|
334
|
+
return choices.filter((c) => c.checked).map((c) => c.id);
|
|
335
|
+
}
|
|
336
|
+
if (trimmed === "all" || trimmed === "*") {
|
|
337
|
+
return choices.map((c) => c.id);
|
|
338
|
+
}
|
|
339
|
+
if (trimmed === "none" || trimmed === "0" || trimmed === "n") {
|
|
340
|
+
return [];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const picked = new Set();
|
|
344
|
+
const byId = new Map(choices.map((c) => [c.id.toLowerCase(), c.id]));
|
|
345
|
+
for (const token of trimmed.split(/[,\s]+/).filter(Boolean)) {
|
|
346
|
+
const num = Number.parseInt(token, 10);
|
|
347
|
+
if (Number.isInteger(num) && String(num) === token && num >= 1 && num <= choices.length) {
|
|
348
|
+
picked.add(choices[num - 1].id);
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (byId.has(token)) {
|
|
352
|
+
picked.add(byId.get(token));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return choices.filter((c) => picked.has(c.id)).map((c) => c.id);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export async function promptMultiSelect(prompter, { title, choices }) {
|
|
359
|
+
if (!Array.isArray(choices) || choices.length === 0) {
|
|
360
|
+
return [];
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (prompter?.isRawTty) {
|
|
364
|
+
prompter.releaseRl();
|
|
365
|
+
return runRawMultiSelect(title, choices);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
console.log(`${title}:`);
|
|
369
|
+
choices.forEach((choice, idx) => {
|
|
370
|
+
const box = choice.checked ? "[x]" : "[ ]";
|
|
371
|
+
const detail = choice.detail ? ` — ${choice.detail}` : "";
|
|
372
|
+
console.log(` ${idx + 1}. ${box} ${choice.label}${detail}`);
|
|
373
|
+
});
|
|
374
|
+
const answer = await prompter.question(
|
|
375
|
+
'Select numbers (e.g. 1,3), "all", "none", or Enter to keep defaults: ',
|
|
376
|
+
);
|
|
377
|
+
return parseMultiSelectInput(answer, choices);
|
|
378
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"featflow": {
|
|
3
|
+
"PreInvocation": [
|
|
4
|
+
{
|
|
5
|
+
"type": "command",
|
|
6
|
+
"command": "featflow hook antigravity pre-invocation",
|
|
7
|
+
"timeout": 5
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
"PreToolUse": [
|
|
11
|
+
{
|
|
12
|
+
"matcher": "run_command|edit_file|write_file|replace_file_content|multi_replace_file_content|write_to_file",
|
|
13
|
+
"hooks": [
|
|
14
|
+
{
|
|
15
|
+
"type": "command",
|
|
16
|
+
"command": "featflow hook antigravity pre-tool-use",
|
|
17
|
+
"timeout": 5
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"PostToolUse": [
|
|
23
|
+
{
|
|
24
|
+
"matcher": "edit_file|write_file|replace_file_content|multi_replace_file_content|write_to_file",
|
|
25
|
+
"hooks": [
|
|
26
|
+
{
|
|
27
|
+
"type": "command",
|
|
28
|
+
"command": "featflow hook antigravity post-tool-use",
|
|
29
|
+
"timeout": 15
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"Stop": [
|
|
35
|
+
{
|
|
36
|
+
"type": "command",
|
|
37
|
+
"command": "featflow hook antigravity stop",
|
|
38
|
+
"timeout": 15
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"UserPromptSubmit": [
|
|
4
|
+
{
|
|
5
|
+
"hooks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "command",
|
|
8
|
+
"command": "featflow hook claude-code user-prompt"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"PreToolUse": [
|
|
14
|
+
{
|
|
15
|
+
"matcher": "Bash|Edit|MultiEdit|Write|NotebookEdit",
|
|
16
|
+
"hooks": [
|
|
17
|
+
{
|
|
18
|
+
"type": "command",
|
|
19
|
+
"command": "featflow hook claude-code pre-tool-use"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"PostToolUse": [
|
|
25
|
+
{
|
|
26
|
+
"matcher": "Edit|MultiEdit|Write|NotebookEdit",
|
|
27
|
+
"hooks": [
|
|
28
|
+
{
|
|
29
|
+
"type": "command",
|
|
30
|
+
"command": "featflow hook claude-code post-tool-use"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"Stop": [
|
|
36
|
+
{
|
|
37
|
+
"hooks": [
|
|
38
|
+
{
|
|
39
|
+
"type": "command",
|
|
40
|
+
"command": "featflow hook claude-code stop"
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# featflow hooks adapter for OpenAI Codex (.codex/config.toml)
|
|
2
|
+
# Requires `featflow` on PATH (or replace `featflow` with `npx --no-install featflow`).
|
|
3
|
+
|
|
4
|
+
[hooks]
|
|
5
|
+
userPromptSubmit = [
|
|
6
|
+
{ command = "featflow hook codex user-prompt", timeoutSec = 5, statusMessage = "Checking featflow workflow routing" },
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
preToolUse = [
|
|
10
|
+
{ command = "featflow hook codex pre-tool-use", timeoutSec = 5, statusMessage = "Checking featflow branch and plan policy" },
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
postToolUse = [
|
|
14
|
+
{ command = "featflow hook codex post-tool-use", timeoutSec = 30, statusMessage = "Checking featflow file-size budget" },
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
stop = [
|
|
18
|
+
{ command = "featflow hook codex stop", timeoutSec = 8, statusMessage = "Checking featflow verification reminders" },
|
|
19
|
+
]
|