@stupify/cli 0.0.16 → 0.2.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 (89) hide show
  1. package/.review/CORPUS.md +44 -0
  2. package/.review/CORPUS.template.md +73 -0
  3. package/.review/REVIEW-PROMPT.md +52 -0
  4. package/.review/RUBRIC.md +46 -0
  5. package/LICENSE +1 -1
  6. package/README.md +95 -37
  7. package/package.json +27 -26
  8. package/packs/antirez.md +10 -0
  9. package/packs/anton-kropp.md +10 -0
  10. package/packs/dhh.md +10 -0
  11. package/packs/dtolnay.md +10 -0
  12. package/packs/jarred-sumner.md +9 -0
  13. package/packs/mitchell-hashimoto.md +10 -0
  14. package/packs/rich-harris.md +10 -0
  15. package/packs/simon-willison.md +10 -0
  16. package/packs/sindre-sorhus.md +10 -0
  17. package/packs/tanner-linsley.md +10 -0
  18. package/packs/zod.md +10 -0
  19. package/src/cli.ts +626 -0
  20. package/src/prime-install.test.ts +109 -0
  21. package/src/prime.ts +50 -0
  22. package/src/review-sweep.test.ts +101 -0
  23. package/src/review-sweep.ts +526 -0
  24. package/dist/analysis.d.ts +0 -16
  25. package/dist/analysis.js +0 -168
  26. package/dist/cache.d.ts +0 -2
  27. package/dist/cache.js +0 -57
  28. package/dist/checks.d.ts +0 -4
  29. package/dist/checks.js +0 -228
  30. package/dist/command.d.ts +0 -2
  31. package/dist/command.js +0 -147
  32. package/dist/constants.d.ts +0 -4
  33. package/dist/constants.js +0 -53
  34. package/dist/counter-scout.d.ts +0 -21
  35. package/dist/counter-scout.js +0 -167
  36. package/dist/diff.d.ts +0 -1
  37. package/dist/diff.js +0 -10
  38. package/dist/doctor.d.ts +0 -16
  39. package/dist/doctor.js +0 -143
  40. package/dist/git.d.ts +0 -17
  41. package/dist/git.js +0 -368
  42. package/dist/hooks.d.ts +0 -5
  43. package/dist/hooks.js +0 -135
  44. package/dist/index.d.ts +0 -1
  45. package/dist/index.js +0 -1
  46. package/dist/model.d.ts +0 -11
  47. package/dist/model.js +0 -296
  48. package/dist/prompts.d.ts +0 -8
  49. package/dist/prompts.js +0 -89
  50. package/dist/render.d.ts +0 -6
  51. package/dist/render.js +0 -295
  52. package/dist/repomix-provider.d.ts +0 -12
  53. package/dist/repomix-provider.js +0 -196
  54. package/dist/search-bench.d.ts +0 -1
  55. package/dist/search-bench.js +0 -677
  56. package/dist/search-profile.d.ts +0 -6
  57. package/dist/search-profile.js +0 -73
  58. package/dist/sem-provider.d.ts +0 -2
  59. package/dist/sem-provider.js +0 -255
  60. package/dist/stupify.d.ts +0 -38
  61. package/dist/stupify.js +0 -505
  62. package/dist/trace.d.ts +0 -31
  63. package/dist/trace.js +0 -86
  64. package/dist/types.d.ts +0 -341
  65. package/dist/types.js +0 -6
  66. package/dist/ui.d.ts +0 -34
  67. package/dist/ui.js +0 -143
  68. package/src/analysis.ts +0 -223
  69. package/src/cache.ts +0 -63
  70. package/src/checks.ts +0 -231
  71. package/src/command.ts +0 -173
  72. package/src/constants.ts +0 -56
  73. package/src/counter-scout.ts +0 -195
  74. package/src/diff.ts +0 -9
  75. package/src/doctor.ts +0 -166
  76. package/src/git.ts +0 -380
  77. package/src/hooks.ts +0 -151
  78. package/src/index.ts +0 -1
  79. package/src/model.ts +0 -367
  80. package/src/prompts.ts +0 -100
  81. package/src/render.ts +0 -328
  82. package/src/repomix-provider.ts +0 -219
  83. package/src/search-bench.ts +0 -783
  84. package/src/search-profile.ts +0 -89
  85. package/src/sem-provider.ts +0 -300
  86. package/src/stupify.ts +0 -604
  87. package/src/trace.ts +0 -126
  88. package/src/types.ts +0 -362
  89. 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,255 +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
- commitSubjects: undefined,
40
- contextCwd: process.cwd(),
41
- cleanup: async () => undefined,
42
- changes: [],
43
- summary: {
44
- added: stats.additions,
45
- deleted: stats.deletions,
46
- modified: 0,
47
- moved: 0,
48
- renamed: 0,
49
- fileCount: stats.filesChanged,
50
- total: 0,
51
- },
52
- };
53
- }
54
- async function semRangeForCommand(command) {
55
- if (command.kind === "since")
56
- return sourceRangeSince(command.since);
57
- if (command.kind === "commit")
58
- return sourceRangeForCommit(command.commit);
59
- if (command.kind === "commits")
60
- return sourceRangeForRecentCommits(command.count);
61
- throw new Error("sem cannot resolve stdin as a git range.");
62
- }
63
- async function semChangeSetFromPatch(patch, debugSem, label = "stdin", committers) {
64
- if (!patch.trim())
65
- throw new Error("No diff received on stdin.");
66
- const raw = await cachedJson("sem-diff", fingerprint({
67
- version: 1,
68
- cwd: process.cwd(),
69
- command: ["diff", "--patch", "--format", "json"],
70
- patchHash: fingerprint(patch),
71
- }), () => runSemWithInput(["diff", "--patch", "--format", "json"], patch, debugSem));
72
- return {
73
- ...normalizeSemDiff(raw, {
74
- id: sourceId(label),
75
- label,
76
- base: label,
77
- target: label,
78
- committers,
79
- commitSubjects: undefined,
80
- stats: { filesChanged: 0, additions: 0, deletions: 0 },
81
- }),
82
- contextCwd: process.cwd(),
83
- cleanup: async () => undefined,
84
- };
85
- }
86
- async function cachedSemDiff(args, range, debugSem) {
87
- return cachedJson("sem-diff", fingerprint({
88
- version: 1,
89
- cwd: process.cwd(),
90
- args,
91
- base: range.base,
92
- target: range.target,
93
- }), () => runSem(args, debugSem));
94
- }
95
- async function withContextWorkspace(changeSet, debugSem) {
96
- const tempDir = await realpath(await mkdtemp(path.join(tmpdir(), "stupify-sem-context-")));
97
- let worktreeAdded = false;
98
- try {
99
- await git(["worktree", "add", "--detach", tempDir, changeSet.target], debugSem);
100
- worktreeAdded = true;
101
- return {
102
- ...changeSet,
103
- contextCwd: tempDir,
104
- cleanup: async () => cleanupWorktree(tempDir, worktreeAdded, debugSem),
105
- };
106
- }
107
- catch (error) {
108
- await cleanupWorktree(tempDir, worktreeAdded, debugSem);
109
- throw error;
110
- }
111
- }
112
- async function runSem(args, debugSem, cwd = process.cwd()) {
113
- if (debugSem)
114
- diagnostic(`sem ${args.join(" ")}`);
115
- const { command, commandArgs } = resolveSemCommand(args);
116
- try {
117
- const { stdout, stderr } = await execFileAsync(command, commandArgs, {
118
- cwd,
119
- maxBuffer: 128 * 1024 * 1024,
120
- });
121
- if (debugSem && stderr.trim())
122
- diagnostic(stderr.trim());
123
- return JSON.parse(stdout);
124
- }
125
- catch (error) {
126
- const message = error instanceof Error ? error.message : String(error);
127
- throw new Error(`sem failed. Install @ataraxy-labs/sem and ensure its binary is downloaded.\n${message}`);
128
- }
129
- }
130
- async function runSemWithInput(args, stdin, debugSem) {
131
- if (debugSem)
132
- diagnostic(`sem ${args.join(" ")}`);
133
- const { command, commandArgs } = resolveSemCommand(args);
134
- return new Promise((resolve, reject) => {
135
- const child = spawn(command, commandArgs, { stdio: ["pipe", "pipe", "pipe"] });
136
- const stdout = [];
137
- const stderr = [];
138
- child.stdout.on("data", (chunk) => stdout.push(chunk));
139
- child.stderr.on("data", (chunk) => stderr.push(chunk));
140
- child.on("error", (error) => reject(error));
141
- child.on("close", (code) => {
142
- const stderrText = Buffer.concat(stderr).toString("utf8");
143
- if (debugSem && stderrText.trim())
144
- diagnostic(stderrText.trim());
145
- if (code !== 0) {
146
- reject(new Error(`sem failed with exit code ${code}${stderrText ? `: ${stderrText.trim()}` : ""}`));
147
- return;
148
- }
149
- try {
150
- resolve(JSON.parse(Buffer.concat(stdout).toString("utf8")));
151
- }
152
- catch (error) {
153
- reject(error);
154
- }
155
- });
156
- child.stdin.end(stdin);
157
- });
158
- }
159
- async function git(args, debugSem) {
160
- if (debugSem)
161
- diagnostic(`git ${args.join(" ")}`);
162
- await execFileAsync("git", [...args], { maxBuffer: 128 * 1024 * 1024 });
163
- }
164
- async function cleanupWorktree(tempDir, worktreeAdded, debugSem) {
165
- if (!worktreeAdded) {
166
- await rm(tempDir, { recursive: true, force: true });
167
- return;
168
- }
169
- try {
170
- await git(["worktree", "remove", "--force", tempDir], debugSem);
171
- }
172
- catch {
173
- await rm(tempDir, { recursive: true, force: true });
174
- await git(["worktree", "prune"], debugSem).catch(() => undefined);
175
- }
176
- }
177
- function resolveSemCommand(args) {
178
- const packageBin = semPackageBin();
179
- if (packageBin)
180
- return { command: process.execPath, commandArgs: [packageBin, ...args] };
181
- return { command: "sem", commandArgs: args };
182
- }
183
- function semPackageBin() {
184
- try {
185
- const require = createRequire(import.meta.url);
186
- return require.resolve("@ataraxy-labs/sem/bin/sem.js");
187
- }
188
- catch {
189
- return null;
190
- }
191
- }
192
- function normalizeSemDiff(value, range) {
193
- if (!value || typeof value !== "object")
194
- throw new Error("sem returned invalid diff JSON.");
195
- const record = value;
196
- const changes = Array.isArray(record.changes) ? record.changes.flatMap(normalizeSemChange) : [];
197
- const summary = normalizeSemSummary(record.summary, changes);
198
- return {
199
- id: range.id,
200
- label: range.label,
201
- base: range.base,
202
- target: range.target,
203
- committers: range.committers,
204
- commitSubjects: range.commitSubjects,
205
- contextCwd: process.cwd(),
206
- cleanup: async () => undefined,
207
- changes,
208
- summary,
209
- };
210
- }
211
- function normalizeSemChange(value) {
212
- if (!value || typeof value !== "object")
213
- return [];
214
- const record = value;
215
- const entityId = stringValue(record.entityId);
216
- const entityName = stringValue(record.entityName);
217
- const entityType = stringValue(record.entityType);
218
- const filePath = stringValue(record.filePath);
219
- const changeType = stringValue(record.changeType);
220
- if (!entityId || !entityName || !entityType || !filePath || !changeType)
221
- return [];
222
- return [{
223
- entityId,
224
- entityName,
225
- entityType,
226
- filePath,
227
- changeType,
228
- beforeContent: nullableString(record.beforeContent),
229
- afterContent: nullableString(record.afterContent),
230
- }];
231
- }
232
- function normalizeSemSummary(value, changes) {
233
- const record = value && typeof value === "object" ? value : {};
234
- return {
235
- added: numberValue(record.added) ?? countByChange(changes, "added"),
236
- deleted: numberValue(record.deleted) ?? countByChange(changes, "deleted"),
237
- modified: numberValue(record.modified) ?? countByChange(changes, "modified"),
238
- moved: numberValue(record.moved) ?? countByChange(changes, "moved"),
239
- renamed: numberValue(record.renamed) ?? countByChange(changes, "renamed"),
240
- fileCount: numberValue(record.fileCount) ?? new Set(changes.map((change) => change.filePath)).size,
241
- total: numberValue(record.total) ?? changes.length,
242
- };
243
- }
244
- function countByChange(changes, changeType) {
245
- return changes.filter((change) => change.changeType === changeType).length;
246
- }
247
- function stringValue(value) {
248
- return typeof value === "string" ? value : "";
249
- }
250
- function nullableString(value) {
251
- return typeof value === "string" ? value : null;
252
- }
253
- function numberValue(value) {
254
- return typeof value === "number" && Number.isFinite(value) ? value : null;
255
- }
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>;