@stupify/cli 0.0.15 → 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.
Files changed (74) hide show
  1. package/.review/CORPUS.md +73 -0
  2. package/.review/REVIEW-PROMPT.md +52 -0
  3. package/.review/RUBRIC.md +46 -0
  4. package/LICENSE +1 -1
  5. package/README.md +41 -39
  6. package/package.json +24 -25
  7. package/src/cli.ts +358 -0
  8. package/src/review-sweep.ts +492 -0
  9. package/dist/analysis.d.ts +0 -16
  10. package/dist/analysis.js +0 -165
  11. package/dist/cache.d.ts +0 -2
  12. package/dist/cache.js +0 -57
  13. package/dist/checks.d.ts +0 -4
  14. package/dist/checks.js +0 -228
  15. package/dist/command.d.ts +0 -2
  16. package/dist/command.js +0 -147
  17. package/dist/constants.d.ts +0 -4
  18. package/dist/constants.js +0 -53
  19. package/dist/counter-scout.d.ts +0 -21
  20. package/dist/counter-scout.js +0 -167
  21. package/dist/diff.d.ts +0 -1
  22. package/dist/diff.js +0 -10
  23. package/dist/doctor.d.ts +0 -4
  24. package/dist/doctor.js +0 -131
  25. package/dist/git.d.ts +0 -12
  26. package/dist/git.js +0 -298
  27. package/dist/hooks.d.ts +0 -3
  28. package/dist/hooks.js +0 -117
  29. package/dist/index.d.ts +0 -1
  30. package/dist/index.js +0 -1
  31. package/dist/model.d.ts +0 -11
  32. package/dist/model.js +0 -296
  33. package/dist/prompts.d.ts +0 -8
  34. package/dist/prompts.js +0 -89
  35. package/dist/render.d.ts +0 -3
  36. package/dist/render.js +0 -151
  37. package/dist/repomix-provider.d.ts +0 -12
  38. package/dist/repomix-provider.js +0 -196
  39. package/dist/search-bench.d.ts +0 -1
  40. package/dist/search-bench.js +0 -677
  41. package/dist/search-profile.d.ts +0 -6
  42. package/dist/search-profile.js +0 -73
  43. package/dist/sem-provider.d.ts +0 -2
  44. package/dist/sem-provider.js +0 -252
  45. package/dist/stupify.d.ts +0 -38
  46. package/dist/stupify.js +0 -474
  47. package/dist/trace.d.ts +0 -31
  48. package/dist/trace.js +0 -86
  49. package/dist/types.d.ts +0 -328
  50. package/dist/types.js +0 -6
  51. package/dist/ui.d.ts +0 -34
  52. package/dist/ui.js +0 -143
  53. package/src/analysis.ts +0 -220
  54. package/src/cache.ts +0 -63
  55. package/src/checks.ts +0 -231
  56. package/src/command.ts +0 -173
  57. package/src/constants.ts +0 -56
  58. package/src/counter-scout.ts +0 -195
  59. package/src/diff.ts +0 -9
  60. package/src/doctor.ts +0 -140
  61. package/src/git.ts +0 -306
  62. package/src/hooks.ts +0 -134
  63. package/src/index.ts +0 -1
  64. package/src/model.ts +0 -367
  65. package/src/prompts.ts +0 -100
  66. package/src/render.ts +0 -154
  67. package/src/repomix-provider.ts +0 -219
  68. package/src/search-bench.ts +0 -783
  69. package/src/search-profile.ts +0 -89
  70. package/src/sem-provider.ts +0 -297
  71. package/src/stupify.ts +0 -571
  72. package/src/trace.ts +0 -126
  73. package/src/types.ts +0 -348
  74. package/src/ui.ts +0 -187
@@ -1,73 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
- import path from "node:path";
3
- import { defaultChecks, searchChecks } from "./checks.js";
4
- export async function loadSearchProfile(profilePath) {
5
- if (!profilePath)
6
- return null;
7
- const fullPath = path.resolve(profilePath);
8
- const value = JSON.parse(await readFile(fullPath, "utf8"));
9
- if (!value || typeof value !== "object" || typeof value.id !== "string" || value.id.length === 0) {
10
- throw new Error(`Invalid search profile: ${profilePath}`);
11
- }
12
- return value;
13
- }
14
- export function effectiveSearchChecks(explicitCheckIds, profile) {
15
- const checks = explicitCheckIds
16
- ? searchChecks(explicitCheckIds)
17
- : profilePatternIds(profile).length > 0
18
- ? checksById(profilePatternIds(profile))
19
- : searchChecks(null);
20
- if (!profile?.patterns)
21
- return checks;
22
- return checks.map((check) => applyPatternOverride(check, profile.patterns?.[check.id]));
23
- }
24
- export function effectiveMaxCandidates(defaultValue, profile) {
25
- return positiveInteger(profile?.maxCandidates) ?? defaultValue;
26
- }
27
- export function effectiveMaxSearchInputTokens(defaultValue, profile) {
28
- return positiveInteger(profile?.maxSearchInputTokens) ?? defaultValue;
29
- }
30
- export function effectiveRepomixConfig(defaultValue, profile) {
31
- const override = profile?.repomix;
32
- if (!override)
33
- return defaultValue;
34
- return {
35
- compress: override.compress ?? defaultValue.compress,
36
- showLineNumbers: override.showLineNumbers ?? defaultValue.showLineNumbers,
37
- removeEmptyLines: override.removeEmptyLines ?? defaultValue.removeEmptyLines,
38
- maxFileSizeBytes: positiveInteger(override.maxFileBytes) ?? defaultValue.maxFileSizeBytes,
39
- maxTotalSizeBytes: positiveInteger(override.maxTotalBytes) ?? defaultValue.maxTotalSizeBytes,
40
- ignorePatterns: override.ignorePatterns ?? defaultValue.ignorePatterns,
41
- };
42
- }
43
- function profilePatternIds(profile) {
44
- if (!profile?.patterns)
45
- return [];
46
- return Object.entries(profile.patterns)
47
- .filter(([, pattern]) => pattern.enabled === true)
48
- .map(([id]) => id);
49
- }
50
- function checksById(ids) {
51
- const byId = new Map(defaultChecks.map((check) => [check.id, check]));
52
- return ids.map((id) => {
53
- const check = byId.get(id);
54
- if (!check)
55
- throw new Error(`Unknown check in search profile: ${id}`);
56
- return check;
57
- });
58
- }
59
- function applyPatternOverride(check, override) {
60
- if (!override)
61
- return check;
62
- return {
63
- ...check,
64
- searchPrompt: override.searchPrompt ?? check.searchPrompt,
65
- searchExamples: {
66
- match: override.matchExamples ?? check.searchExamples?.match ?? check.examples?.match ?? [],
67
- nonMatch: override.nonMatchExamples ?? check.searchExamples?.nonMatch ?? check.examples?.noMatch ?? [],
68
- },
69
- };
70
- }
71
- function positiveInteger(value) {
72
- return Number.isInteger(value) && Number(value) > 0 ? Number(value) : null;
73
- }
@@ -1,2 +0,0 @@
1
- import type { SearchCommand, SemChangeSet } from "./types.ts";
2
- export declare function semChangeSetForCommand(command: SearchCommand): Promise<SemChangeSet>;
@@ -1,252 +0,0 @@
1
- import { execFile, spawn } from "node:child_process";
2
- import { mkdtemp, realpath, rm } from "node:fs/promises";
3
- import { createRequire } from "node:module";
4
- import { tmpdir } from "node:os";
5
- import path from "node:path";
6
- import { promisify } from "node:util";
7
- import { cachedJson, fingerprint } from "./cache.js";
8
- import { readDiffFromStdin } from "./diff.js";
9
- import { gitUserLabel, sourceRangeForCommit, sourceRangeForRecentCommits, sourceRangeSince, stagedDiff, } from "./git.js";
10
- import { diagnostic } from "./ui.js";
11
- import { sourceId } from "./types.js";
12
- const execFileAsync = promisify(execFile);
13
- export async function semChangeSetForCommand(command) {
14
- if (command.kind === "stdin")
15
- return semChangeSetFromPatch(await readDiffFromStdin(), command.debugSem, "stdin", ["stdin"]);
16
- if (command.kind === "staged") {
17
- const [diff, committer] = await Promise.all([stagedDiff(), gitUserLabel()]);
18
- const committers = [committer];
19
- if (!diff.text.trim())
20
- return emptyChangeSet("staged", diff.stats, committers);
21
- return semChangeSetFromPatch(diff.text, command.debugSem, "staged", committers);
22
- }
23
- if (command.kind === "commit") {
24
- const range = await sourceRangeForCommit(command.commit);
25
- const raw = await cachedSemDiff(["diff", "--commit", command.commit, "--format", "json"], range, command.debugSem);
26
- return withContextWorkspace(normalizeSemDiff(raw, range), command.debugSem);
27
- }
28
- const range = await semRangeForCommand(command);
29
- const raw = await cachedSemDiff(["diff", "--from", range.base, "--to", range.target, "--format", "json"], range, command.debugSem);
30
- return withContextWorkspace(normalizeSemDiff(raw, range), command.debugSem);
31
- }
32
- function emptyChangeSet(label, stats, committers) {
33
- return {
34
- id: sourceId(label),
35
- label,
36
- base: label,
37
- target: label,
38
- committers,
39
- contextCwd: process.cwd(),
40
- cleanup: async () => undefined,
41
- changes: [],
42
- summary: {
43
- added: stats.additions,
44
- deleted: stats.deletions,
45
- modified: 0,
46
- moved: 0,
47
- renamed: 0,
48
- fileCount: stats.filesChanged,
49
- total: 0,
50
- },
51
- };
52
- }
53
- async function semRangeForCommand(command) {
54
- if (command.kind === "since")
55
- return sourceRangeSince(command.since);
56
- if (command.kind === "commit")
57
- return sourceRangeForCommit(command.commit);
58
- if (command.kind === "commits")
59
- return sourceRangeForRecentCommits(command.count);
60
- throw new Error("sem cannot resolve stdin as a git range.");
61
- }
62
- async function semChangeSetFromPatch(patch, debugSem, label = "stdin", committers) {
63
- if (!patch.trim())
64
- throw new Error("No diff received on stdin.");
65
- const raw = await cachedJson("sem-diff", fingerprint({
66
- version: 1,
67
- cwd: process.cwd(),
68
- command: ["diff", "--patch", "--format", "json"],
69
- patchHash: fingerprint(patch),
70
- }), () => runSemWithInput(["diff", "--patch", "--format", "json"], patch, debugSem));
71
- return {
72
- ...normalizeSemDiff(raw, {
73
- id: sourceId(label),
74
- label,
75
- base: label,
76
- target: label,
77
- committers,
78
- stats: { filesChanged: 0, additions: 0, deletions: 0 },
79
- }),
80
- contextCwd: process.cwd(),
81
- cleanup: async () => undefined,
82
- };
83
- }
84
- async function cachedSemDiff(args, range, debugSem) {
85
- return cachedJson("sem-diff", fingerprint({
86
- version: 1,
87
- cwd: process.cwd(),
88
- args,
89
- base: range.base,
90
- target: range.target,
91
- }), () => runSem(args, debugSem));
92
- }
93
- async function withContextWorkspace(changeSet, debugSem) {
94
- const tempDir = await realpath(await mkdtemp(path.join(tmpdir(), "stupify-sem-context-")));
95
- let worktreeAdded = false;
96
- try {
97
- await git(["worktree", "add", "--detach", tempDir, changeSet.target], debugSem);
98
- worktreeAdded = true;
99
- return {
100
- ...changeSet,
101
- contextCwd: tempDir,
102
- cleanup: async () => cleanupWorktree(tempDir, worktreeAdded, debugSem),
103
- };
104
- }
105
- catch (error) {
106
- await cleanupWorktree(tempDir, worktreeAdded, debugSem);
107
- throw error;
108
- }
109
- }
110
- async function runSem(args, debugSem, cwd = process.cwd()) {
111
- if (debugSem)
112
- diagnostic(`sem ${args.join(" ")}`);
113
- const { command, commandArgs } = resolveSemCommand(args);
114
- try {
115
- const { stdout, stderr } = await execFileAsync(command, commandArgs, {
116
- cwd,
117
- maxBuffer: 128 * 1024 * 1024,
118
- });
119
- if (debugSem && stderr.trim())
120
- diagnostic(stderr.trim());
121
- return JSON.parse(stdout);
122
- }
123
- catch (error) {
124
- const message = error instanceof Error ? error.message : String(error);
125
- throw new Error(`sem failed. Install @ataraxy-labs/sem and ensure its binary is downloaded.\n${message}`);
126
- }
127
- }
128
- async function runSemWithInput(args, stdin, debugSem) {
129
- if (debugSem)
130
- diagnostic(`sem ${args.join(" ")}`);
131
- const { command, commandArgs } = resolveSemCommand(args);
132
- return new Promise((resolve, reject) => {
133
- const child = spawn(command, commandArgs, { stdio: ["pipe", "pipe", "pipe"] });
134
- const stdout = [];
135
- const stderr = [];
136
- child.stdout.on("data", (chunk) => stdout.push(chunk));
137
- child.stderr.on("data", (chunk) => stderr.push(chunk));
138
- child.on("error", (error) => reject(error));
139
- child.on("close", (code) => {
140
- const stderrText = Buffer.concat(stderr).toString("utf8");
141
- if (debugSem && stderrText.trim())
142
- diagnostic(stderrText.trim());
143
- if (code !== 0) {
144
- reject(new Error(`sem failed with exit code ${code}${stderrText ? `: ${stderrText.trim()}` : ""}`));
145
- return;
146
- }
147
- try {
148
- resolve(JSON.parse(Buffer.concat(stdout).toString("utf8")));
149
- }
150
- catch (error) {
151
- reject(error);
152
- }
153
- });
154
- child.stdin.end(stdin);
155
- });
156
- }
157
- async function git(args, debugSem) {
158
- if (debugSem)
159
- diagnostic(`git ${args.join(" ")}`);
160
- await execFileAsync("git", [...args], { maxBuffer: 128 * 1024 * 1024 });
161
- }
162
- async function cleanupWorktree(tempDir, worktreeAdded, debugSem) {
163
- if (!worktreeAdded) {
164
- await rm(tempDir, { recursive: true, force: true });
165
- return;
166
- }
167
- try {
168
- await git(["worktree", "remove", "--force", tempDir], debugSem);
169
- }
170
- catch {
171
- await rm(tempDir, { recursive: true, force: true });
172
- await git(["worktree", "prune"], debugSem).catch(() => undefined);
173
- }
174
- }
175
- function resolveSemCommand(args) {
176
- const packageBin = semPackageBin();
177
- if (packageBin)
178
- return { command: process.execPath, commandArgs: [packageBin, ...args] };
179
- return { command: "sem", commandArgs: args };
180
- }
181
- function semPackageBin() {
182
- try {
183
- const require = createRequire(import.meta.url);
184
- return require.resolve("@ataraxy-labs/sem/bin/sem.js");
185
- }
186
- catch {
187
- return null;
188
- }
189
- }
190
- function normalizeSemDiff(value, range) {
191
- if (!value || typeof value !== "object")
192
- throw new Error("sem returned invalid diff JSON.");
193
- const record = value;
194
- const changes = Array.isArray(record.changes) ? record.changes.flatMap(normalizeSemChange) : [];
195
- const summary = normalizeSemSummary(record.summary, changes);
196
- return {
197
- id: range.id,
198
- label: range.label,
199
- base: range.base,
200
- target: range.target,
201
- committers: range.committers,
202
- contextCwd: process.cwd(),
203
- cleanup: async () => undefined,
204
- changes,
205
- summary,
206
- };
207
- }
208
- function normalizeSemChange(value) {
209
- if (!value || typeof value !== "object")
210
- return [];
211
- const record = value;
212
- const entityId = stringValue(record.entityId);
213
- const entityName = stringValue(record.entityName);
214
- const entityType = stringValue(record.entityType);
215
- const filePath = stringValue(record.filePath);
216
- const changeType = stringValue(record.changeType);
217
- if (!entityId || !entityName || !entityType || !filePath || !changeType)
218
- return [];
219
- return [{
220
- entityId,
221
- entityName,
222
- entityType,
223
- filePath,
224
- changeType,
225
- beforeContent: nullableString(record.beforeContent),
226
- afterContent: nullableString(record.afterContent),
227
- }];
228
- }
229
- function normalizeSemSummary(value, changes) {
230
- const record = value && typeof value === "object" ? value : {};
231
- return {
232
- added: numberValue(record.added) ?? countByChange(changes, "added"),
233
- deleted: numberValue(record.deleted) ?? countByChange(changes, "deleted"),
234
- modified: numberValue(record.modified) ?? countByChange(changes, "modified"),
235
- moved: numberValue(record.moved) ?? countByChange(changes, "moved"),
236
- renamed: numberValue(record.renamed) ?? countByChange(changes, "renamed"),
237
- fileCount: numberValue(record.fileCount) ?? new Set(changes.map((change) => change.filePath)).size,
238
- total: numberValue(record.total) ?? changes.length,
239
- };
240
- }
241
- function countByChange(changes, changeType) {
242
- return changes.filter((change) => change.changeType === changeType).length;
243
- }
244
- function stringValue(value) {
245
- return typeof value === "string" ? value : "";
246
- }
247
- function nullableString(value) {
248
- return typeof value === "string" ? value : null;
249
- }
250
- function numberValue(value) {
251
- return typeof value === "number" && Number.isFinite(value) ? value : null;
252
- }
package/dist/stupify.d.ts DELETED
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env node
2
- import type { SearchCommand, SearchRunJson } from "./types.ts";
3
- export declare function main(argv?: string[]): Promise<number>;
4
- export declare function runSearchCommand(command: SearchCommand, startedAt: number, ui?: {
5
- intro(title: string, logOptions?: Readonly<{
6
- force?: boolean;
7
- }>): void;
8
- outro(message: string, logOptions?: Readonly<{
9
- force?: boolean;
10
- }>): void;
11
- note(message: string, title?: string, logOptions?: Readonly<{
12
- force?: boolean;
13
- }>): void;
14
- info(message: string, logOptions?: Readonly<{
15
- force?: boolean;
16
- }>): void;
17
- step(message: string, logOptions?: Readonly<{
18
- force?: boolean;
19
- }>): void;
20
- success(message: string, logOptions?: Readonly<{
21
- force?: boolean;
22
- }>): void;
23
- warn(message: string, logOptions?: Readonly<{
24
- force?: boolean;
25
- }>): void;
26
- error(message: string, logOptions?: Readonly<{
27
- force?: boolean;
28
- }>): void;
29
- debug(message: string): void;
30
- confirm(message: string): Promise<boolean>;
31
- spinner(message: string, logOptions?: Readonly<{
32
- force?: boolean;
33
- }>): import("@clack/prompts").SpinnerResult;
34
- progress(message: string, max: number, logOptions?: Readonly<{
35
- force?: boolean;
36
- }>): import("@clack/prompts").ProgressResult;
37
- writeStdout(text: string): void;
38
- }): Promise<SearchRunJson>;