@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,21 +0,0 @@
1
- import type { CheckId, SemCandidate, SemChangeSet, StupifyCheck } from "./types.ts";
2
- type Signal = Readonly<{
3
- checkId: CheckId;
4
- entityId: string;
5
- reasonCode: string;
6
- }>;
7
- type SignalBucket = Readonly<{
8
- checkId: CheckId;
9
- total: number;
10
- examples: readonly Signal[];
11
- }>;
12
- export type CounterScoutPlan = Readonly<{
13
- buckets: readonly SignalBucket[];
14
- totalSignals: number;
15
- maxTargets: number;
16
- targets: readonly SemCandidate[];
17
- }>;
18
- export declare function counterScoutTargets(changeSet: SemChangeSet, checks: readonly StupifyCheck[], maxTargets: number): readonly SemCandidate[];
19
- export declare function counterScoutPlan(changeSet: SemChangeSet, checks: readonly StupifyCheck[], maxTargets: number): CounterScoutPlan;
20
- export declare function runSignalCounters(changeSet: SemChangeSet, checks: readonly StupifyCheck[]): readonly SignalBucket[];
21
- export {};
@@ -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>;