@stupify/cli 0.0.16 → 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 -168
  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 -16
  24. package/dist/doctor.js +0 -143
  25. package/dist/git.d.ts +0 -17
  26. package/dist/git.js +0 -368
  27. package/dist/hooks.d.ts +0 -5
  28. package/dist/hooks.js +0 -135
  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 -6
  36. package/dist/render.js +0 -295
  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 -255
  45. package/dist/stupify.d.ts +0 -38
  46. package/dist/stupify.js +0 -505
  47. package/dist/trace.d.ts +0 -31
  48. package/dist/trace.js +0 -86
  49. package/dist/types.d.ts +0 -341
  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 -223
  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 -166
  61. package/src/git.ts +0 -380
  62. package/src/hooks.ts +0 -151
  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 -328
  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 -300
  71. package/src/stupify.ts +0 -604
  72. package/src/trace.ts +0 -126
  73. package/src/types.ts +0 -362
  74. package/src/ui.ts +0 -187
@@ -1,167 +0,0 @@
1
- const MAX_COUNTER_EXAMPLES_PER_CHECK = 20;
2
- export function counterScoutTargets(changeSet, checks, maxTargets) {
3
- return counterScoutPlan(changeSet, checks, maxTargets).targets;
4
- }
5
- export function counterScoutPlan(changeSet, checks, maxTargets) {
6
- const buckets = runSignalCounters(changeSet, checks);
7
- const targets = [];
8
- let cursor = 0;
9
- while (targets.length < maxTargets && buckets.some((bucket) => cursor < bucket.examples.length)) {
10
- for (const bucket of buckets) {
11
- const signal = bucket.examples[cursor];
12
- if (!signal)
13
- continue;
14
- targets.push({
15
- sourceId: changeSet.id,
16
- targetId: `t${String(targets.length + 1).padStart(3, "0")}`,
17
- entityId: signal.entityId,
18
- checkId: signal.checkId,
19
- reason: signal.reasonCode,
20
- });
21
- if (targets.length >= maxTargets)
22
- break;
23
- }
24
- cursor += 1;
25
- }
26
- return {
27
- buckets,
28
- totalSignals: buckets.reduce((sum, bucket) => sum + bucket.total, 0),
29
- maxTargets,
30
- targets,
31
- };
32
- }
33
- export function runSignalCounters(changeSet, checks) {
34
- return checks
35
- .map((check) => {
36
- const signals = changeSet.changes.flatMap((change) => {
37
- const reasonCode = reasonForCheck(check.id, change);
38
- return reasonCode ? [{ checkId: check.id, entityId: change.entityId, reasonCode }] : [];
39
- });
40
- return {
41
- checkId: check.id,
42
- total: signals.length,
43
- examples: signals.slice(0, MAX_COUNTER_EXAMPLES_PER_CHECK),
44
- };
45
- })
46
- .filter((bucket) => bucket.total > 0);
47
- }
48
- function reasonForCheck(checkId, change) {
49
- if (!isSearchableSourceChange(change))
50
- return null;
51
- const haystack = `${change.entityName}\n${change.entityType}\n${change.filePath}\n${change.afterContent ?? ""}`.toLowerCase();
52
- const changed = change.changeType === "added" || change.changeType === "modified";
53
- if (!changed)
54
- return null;
55
- switch (checkId) {
56
- case "duplicated_schema":
57
- return isDuplicatedSchemaCandidate(change) ? "local_schemaish_copy" : null;
58
- case "unnecessary_complexity":
59
- return /\b(helper|wrapper|service|provider|manager|factory|adapter|resolver|coordinator)\b/i.test(change.entityName)
60
- ? "new_abstraction_name"
61
- : null;
62
- case "fake_precision_windowing":
63
- return /\b(token|budget|window|batch|ratio|estimate|counter|count|limit)\b/i.test(haystack)
64
- ? "precision_accounting_terms"
65
- : null;
66
- case "coauthored_slop":
67
- return /\b(coauhtoried|coauthored|co-authored|co-authored-by)\b/i.test(haystack)
68
- ? "coauthor_text"
69
- : null;
70
- case "mega_file":
71
- return change.entityType === "chunk" && /lines\s+\d+-\d+/i.test(change.entityName)
72
- ? "large_changed_chunk"
73
- : null;
74
- case "over_commenting":
75
- return overCommentingSignal(change)
76
- ? "comment_lines_increased"
77
- : null;
78
- case "lint_bypass":
79
- return lintBypassSignal(change.afterContent ?? "")
80
- ? "lint_or_type_bypass_text"
81
- : null;
82
- case "inconsistent_patterns":
83
- return /\b(manager|factory|provider|adapter|orchestrator|coordinator)\b/i.test(change.entityName)
84
- ? "pattern_abstraction_name"
85
- : null;
86
- case "reinvented_utils":
87
- return reinventedUtilitySignal(change)
88
- ? "generic_utility_name"
89
- : null;
90
- case "operator_style_mismatch":
91
- return /\b(manager|factory|provider|enterprise|orchestrator)\b/i.test(haystack)
92
- ? "style_smell_terms"
93
- : null;
94
- default:
95
- return null;
96
- }
97
- }
98
- function isDuplicatedSchemaCandidate(change) {
99
- if (!/^(interface|type)$/i.test(change.entityType))
100
- return false;
101
- if (/^(public|external|internal|payment|.+client$)/i.test(change.entityName))
102
- return false;
103
- return /\b(local|payload|schema)\b/i.test(words(change.entityName));
104
- }
105
- function overCommentingSignal(change) {
106
- const before = commentLines(change.beforeContent);
107
- const after = commentLines(change.afterContent);
108
- if (after <= before + 3)
109
- return false;
110
- const comments = commentText(change.afterContent);
111
- if (/\b(because|why|constraint|provider|external|api|quirk|edge case|timezone|utc|ledger|finance|reconciliation|rejects|mirrors|keep this)\b/i.test(comments)) {
112
- return false;
113
- }
114
- return true;
115
- }
116
- function lintBypassSignal(value) {
117
- return value.split(/\r?\n/).some((line) => {
118
- const trimmed = line.trim();
119
- const comment = /^(\/\/|\/\*|\*)/.test(trimmed);
120
- if (comment && /@ts-ignore\s*$/i.test(trimmed))
121
- return true;
122
- if (comment && /@ts-expect-error\s*$/i.test(trimmed))
123
- return true;
124
- if (comment && /(eslint-disable|biome-ignore)/i.test(trimmed) && !/\s--\s*\S/.test(trimmed))
125
- return true;
126
- return /\bas unknown as\b|\bas any\b|:\s*any\b/i.test(trimmed);
127
- });
128
- }
129
- function reinventedUtilitySignal(change) {
130
- const name = change.entityName;
131
- if (!/^(clamp|debounce|throttle|slug|slugify|sort|shuffle|memoize|pick|omit|uniq)/i.test(name))
132
- return false;
133
- const content = change.afterContent ?? "";
134
- if (/currency|invoice|refund|subscription|tier|domain/i.test(`${name}\n${content}`))
135
- return false;
136
- return true;
137
- }
138
- function isSearchableSourceChange(change) {
139
- const filePath = change.filePath.toLowerCase();
140
- if (/(^|\/)(bun|package-lock|pnpm-lock|yarn)\.lock$/.test(filePath))
141
- return false;
142
- if (/(^|\/)(dist|build|coverage|generated|vendor|fixtures?|snapshots?)(\/|$)/.test(filePath))
143
- return false;
144
- if (/\.(md|mdx|txt|json|jsonc|ya?ml|toml|lock|csv|svg|png|jpe?g|gif|webp)$/i.test(filePath))
145
- return false;
146
- if (/\.(test|spec|fixture)\.[cm]?[jt]sx?$/i.test(filePath))
147
- return false;
148
- return /\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/i.test(filePath);
149
- }
150
- function commentLines(value) {
151
- if (!value)
152
- return 0;
153
- return value.split(/\r?\n/).filter((line) => /^\s*(\/\/|\/\*|\*|#)/.test(line)).length;
154
- }
155
- function commentText(value) {
156
- if (!value)
157
- return "";
158
- return value
159
- .split(/\r?\n/)
160
- .filter((line) => /^\s*(\/\/|\/\*|\*|#)/.test(line))
161
- .join("\n");
162
- }
163
- function words(value) {
164
- return value
165
- .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
166
- .replace(/[_-]+/g, " ");
167
- }
package/dist/diff.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function readDiffFromStdin(): Promise<string>;
package/dist/diff.js DELETED
@@ -1,10 +0,0 @@
1
- import { stdin as input } from "node:process";
2
- export async function readDiffFromStdin() {
3
- const chunks = [];
4
- for await (const chunk of input)
5
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
6
- const text = Buffer.concat(chunks).toString("utf8");
7
- if (!text.trim())
8
- throw new Error("No diff received on stdin.");
9
- return text;
10
- }
package/dist/doctor.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import type { CliUi } from "./ui.ts";
2
- type CheckStatus = "ok" | "missing" | "info";
3
- type DoctorCheck = Readonly<{
4
- label: string;
5
- status: CheckStatus;
6
- detail: string;
7
- required?: boolean;
8
- }>;
9
- export type DoctorResult = Readonly<{
10
- exitCode: number;
11
- text: string;
12
- checks: readonly DoctorCheck[];
13
- }>;
14
- export declare function runDoctor(): Promise<DoctorResult>;
15
- export declare function renderDoctorToUi(result: DoctorResult, ui: CliUi): void;
16
- export {};
package/dist/doctor.js DELETED
@@ -1,143 +0,0 @@
1
- import { execFile } from "node:child_process";
2
- import { createRequire } from "node:module";
3
- import { homedir, platform } from "node:os";
4
- import path from "node:path";
5
- import { promisify } from "node:util";
6
- import { DEFAULT_MODEL_ID, MODEL_REGISTRY } from "./constants.js";
7
- import { runHookCommand } from "./hooks.js";
8
- const execFileAsync = promisify(execFile);
9
- export async function runDoctor() {
10
- const checks = await Promise.all([
11
- gitCheck(),
12
- hookCheck(),
13
- semCheck(),
14
- repomixCheck(),
15
- llamaServerCheck(),
16
- modelCacheCheck(),
17
- ]);
18
- const requiredMissing = checks.some((check) => check.required && check.status === "missing");
19
- return {
20
- exitCode: requiredMissing ? 1 : 0,
21
- text: renderDoctor(checks),
22
- checks,
23
- };
24
- }
25
- export function renderDoctorToUi(result, ui) {
26
- const missingRequired = result.checks.filter((check) => check.required && check.status === "missing");
27
- if (missingRequired.length > 0) {
28
- ui.error(`Doctor found ${missingRequired.length} missing required dependency.`);
29
- }
30
- else {
31
- ui.success("Doctor checks complete.");
32
- }
33
- ui.note(result.checks.map((check) => `${icon(check.status)} ${check.label}: ${check.detail}`).join("\n"), "Doctor");
34
- ui.note("Local-only. Stupify does not upload source, diffs, filenames, repo URLs, commit messages, author names, or private package names.", "Privacy");
35
- }
36
- async function gitCheck() {
37
- try {
38
- const { stdout } = await execFileAsync("git", ["rev-parse", "--show-toplevel"], { maxBuffer: 1024 * 1024 });
39
- return { label: "git repo", status: "ok", detail: stdout.trim(), required: true };
40
- }
41
- catch {
42
- return { label: "git repo", status: "missing", detail: "not inside a git repository", required: true };
43
- }
44
- }
45
- async function hookCheck() {
46
- try {
47
- const status = await runHookCommand("status");
48
- return { label: "pre-commit hook", status: "info", detail: status.replace(/^Stupify hook:\s*/, "") };
49
- }
50
- catch (error) {
51
- return { label: "pre-commit hook", status: "info", detail: errorMessage(error) };
52
- }
53
- }
54
- async function semCheck() {
55
- const packageBin = resolvePackage("@ataraxy-labs/sem/bin/sem.js");
56
- if (packageBin)
57
- return { label: "sem", status: "ok", detail: "@ataraxy-labs/sem package binary found", required: true };
58
- if (await commandExists("sem"))
59
- return { label: "sem", status: "ok", detail: "sem found on PATH", required: true };
60
- return { label: "sem", status: "missing", detail: "install @ataraxy-labs/sem or put sem on PATH", required: true };
61
- }
62
- async function repomixCheck() {
63
- if (resolvePackage("repomix"))
64
- return { label: "Repomix", status: "ok", detail: "repomix package found", required: true };
65
- return { label: "Repomix", status: "missing", detail: "repomix package is not installed", required: true };
66
- }
67
- async function llamaServerCheck() {
68
- if (await commandExists("llama-server"))
69
- return { label: "llama-server", status: "ok", detail: "llama-server found on PATH", required: true };
70
- return { label: "llama-server", status: "missing", detail: "install llama.cpp, for example `brew install llama.cpp`", required: true };
71
- }
72
- async function modelCacheCheck() {
73
- const model = MODEL_REGISTRY[DEFAULT_MODEL_ID];
74
- const modelPath = path.join(cacheDir(), "models", model.file);
75
- if (await fileExists(modelPath))
76
- return { label: "default model", status: "ok", detail: `${model.name} cached` };
77
- return {
78
- label: "default model",
79
- status: "info",
80
- detail: `${model.name} not cached yet; first interactive search can download it locally`,
81
- };
82
- }
83
- function renderDoctor(checks) {
84
- const lines = [
85
- "Stupify doctor",
86
- "",
87
- ...checks.map((check) => `${icon(check.status)} ${check.label}: ${check.detail}`),
88
- "",
89
- "Privacy: local-only. Stupify does not upload source, diffs, filenames, repo URLs, commit messages, author names, or private package names.",
90
- ];
91
- return lines.join("\n");
92
- }
93
- function icon(status) {
94
- if (status === "ok")
95
- return "OK";
96
- if (status === "missing")
97
- return "MISSING";
98
- return "INFO";
99
- }
100
- function resolvePackage(specifier) {
101
- try {
102
- const require = createRequire(import.meta.url);
103
- return require.resolve(specifier);
104
- }
105
- catch {
106
- return null;
107
- }
108
- }
109
- async function commandExists(command) {
110
- try {
111
- await execFileAsync("sh", ["-c", `command -v ${shellQuote(command)}`], { maxBuffer: 1024 * 1024 });
112
- return true;
113
- }
114
- catch {
115
- return false;
116
- }
117
- }
118
- async function fileExists(filePath) {
119
- try {
120
- const { stat } = await import("node:fs/promises");
121
- return (await stat(filePath)).isFile();
122
- }
123
- catch {
124
- return false;
125
- }
126
- }
127
- function cacheDir() {
128
- if (process.env.STUPIFY_CACHE_DIR)
129
- return process.env.STUPIFY_CACHE_DIR;
130
- if (process.env.XDG_CACHE_HOME)
131
- return path.join(process.env.XDG_CACHE_HOME, "stupify");
132
- if (platform() === "darwin")
133
- return path.join(homedir(), "Library", "Caches", "stupify");
134
- if (platform() === "win32" && process.env.LOCALAPPDATA)
135
- return path.join(process.env.LOCALAPPDATA, "stupify", "Cache");
136
- return path.join(homedir(), ".cache", "stupify");
137
- }
138
- function shellQuote(value) {
139
- return `'${value.replace(/'/g, "'\\''")}'`;
140
- }
141
- function errorMessage(error) {
142
- return error instanceof Error ? error.message : String(error);
143
- }
package/dist/git.d.ts DELETED
@@ -1,17 +0,0 @@
1
- import { type BlameSummary, type NetDiff, type SourceRange, type StagedDiff } from "./types.ts";
2
- export declare function netDiffSince(since: string): Promise<NetDiff>;
3
- export declare function netDiffForCommit(commit: string): Promise<NetDiff>;
4
- export declare function netDiffForRecentCommits(count: number): Promise<NetDiff>;
5
- export declare function sourceRangeSince(since: string): Promise<SourceRange>;
6
- export declare function sourceRangeForCommit(commit: string): Promise<SourceRange>;
7
- export declare function sourceRangeForRecentCommits(count: number): Promise<SourceRange>;
8
- export declare function netDiffFromStdin(text: string): Promise<NetDiff>;
9
- export declare function stagedDiff(): Promise<StagedDiff>;
10
- export declare function gitRoot(): Promise<string>;
11
- export declare function gitPath(pathspec: string): Promise<string>;
12
- export declare function gitUserLabel(): Promise<string>;
13
- export declare function blameEntity(input: Readonly<{
14
- filePath: string;
15
- entityName: string;
16
- rev: string;
17
- }>): Promise<BlameSummary | null>;