@stupify/cli 0.0.3 → 0.0.5

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 (59) hide show
  1. package/README.md +26 -31
  2. package/dist/analysis.d.ts +11 -9
  3. package/dist/analysis.js +30 -173
  4. package/dist/checks.d.ts +1 -0
  5. package/dist/checks.js +89 -2
  6. package/dist/command.js +55 -91
  7. package/dist/constants.d.ts +1 -1
  8. package/dist/constants.js +1 -1
  9. package/dist/counter-scout.js +70 -8
  10. package/dist/doctor.d.ts +4 -0
  11. package/dist/doctor.js +131 -0
  12. package/dist/git.d.ts +4 -1
  13. package/dist/git.js +34 -0
  14. package/dist/hooks.d.ts +3 -0
  15. package/dist/hooks.js +117 -0
  16. package/dist/model.d.ts +1 -15
  17. package/dist/model.js +37 -21
  18. package/dist/prompts.d.ts +8 -5
  19. package/dist/prompts.js +58 -168
  20. package/dist/render.d.ts +2 -2
  21. package/dist/render.js +70 -78
  22. package/dist/repomix-provider.d.ts +10 -2
  23. package/dist/repomix-provider.js +62 -11
  24. package/dist/search-bench.d.ts +1 -0
  25. package/dist/search-bench.js +675 -0
  26. package/dist/search-profile.d.ts +6 -0
  27. package/dist/search-profile.js +73 -0
  28. package/dist/sem-provider.d.ts +2 -2
  29. package/dist/sem-provider.js +33 -7
  30. package/dist/stupify.d.ts +2 -0
  31. package/dist/stupify.js +185 -334
  32. package/dist/types.d.ts +193 -109
  33. package/package.json +1 -1
  34. package/src/analysis.ts +48 -268
  35. package/src/checks.ts +91 -2
  36. package/src/command.ts +62 -107
  37. package/src/constants.ts +1 -1
  38. package/src/counter-scout.ts +63 -7
  39. package/src/doctor.ts +140 -0
  40. package/src/git.ts +35 -1
  41. package/src/hooks.ts +134 -0
  42. package/src/model.ts +39 -26
  43. package/src/prompts.ts +66 -202
  44. package/src/render.ts +68 -79
  45. package/src/repomix-provider.ts +66 -10
  46. package/src/search-bench.ts +783 -0
  47. package/src/search-profile.ts +89 -0
  48. package/src/sem-provider.ts +36 -9
  49. package/src/stupify.ts +215 -527
  50. package/src/types.ts +195 -119
  51. package/dist/batcher.d.ts +0 -3
  52. package/dist/batcher.js +0 -142
  53. package/dist/candidate-context.d.ts +0 -2
  54. package/dist/candidate-context.js +0 -40
  55. package/dist/experiment.d.ts +0 -1
  56. package/dist/experiment.js +0 -225
  57. package/src/batcher.ts +0 -198
  58. package/src/candidate-context.ts +0 -43
  59. package/src/experiment.ts +0 -317
@@ -0,0 +1,89 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { defaultChecks, searchChecks } from "./checks.ts";
4
+ import type {
5
+ RepomixSearchConfig,
6
+ SearchProfile,
7
+ SearchProfilePattern,
8
+ StupifyCheck,
9
+ } from "./types.ts";
10
+
11
+ export async function loadSearchProfile(profilePath: string | null): Promise<SearchProfile | null> {
12
+ if (!profilePath) return null;
13
+ const fullPath = path.resolve(profilePath);
14
+ const value = JSON.parse(await readFile(fullPath, "utf8")) as SearchProfile;
15
+ if (!value || typeof value !== "object" || typeof value.id !== "string" || value.id.length === 0) {
16
+ throw new Error(`Invalid search profile: ${profilePath}`);
17
+ }
18
+ return value;
19
+ }
20
+
21
+ export function effectiveSearchChecks(
22
+ explicitCheckIds: readonly string[] | null,
23
+ profile: SearchProfile | null,
24
+ ): readonly StupifyCheck[] {
25
+ const checks = explicitCheckIds
26
+ ? searchChecks(explicitCheckIds)
27
+ : profilePatternIds(profile).length > 0
28
+ ? checksById(profilePatternIds(profile))
29
+ : searchChecks(null);
30
+
31
+ if (!profile?.patterns) return checks;
32
+ return checks.map((check) => applyPatternOverride(check, profile.patterns?.[check.id]));
33
+ }
34
+
35
+ export function effectiveMaxCandidates(defaultValue: number, profile: SearchProfile | null): number {
36
+ return positiveInteger(profile?.maxCandidates) ?? defaultValue;
37
+ }
38
+
39
+ export function effectiveMaxSearchInputTokens(defaultValue: number, profile: SearchProfile | null): number {
40
+ return positiveInteger(profile?.maxSearchInputTokens) ?? defaultValue;
41
+ }
42
+
43
+ export function effectiveRepomixConfig(
44
+ defaultValue: RepomixSearchConfig,
45
+ profile: SearchProfile | null,
46
+ ): RepomixSearchConfig {
47
+ const override = profile?.repomix;
48
+ if (!override) return defaultValue;
49
+ return {
50
+ compress: override.compress ?? defaultValue.compress,
51
+ showLineNumbers: override.showLineNumbers ?? defaultValue.showLineNumbers,
52
+ removeEmptyLines: override.removeEmptyLines ?? defaultValue.removeEmptyLines,
53
+ maxFileSizeBytes: positiveInteger(override.maxFileBytes) ?? defaultValue.maxFileSizeBytes,
54
+ maxTotalSizeBytes: positiveInteger(override.maxTotalBytes) ?? defaultValue.maxTotalSizeBytes,
55
+ ignorePatterns: override.ignorePatterns ?? defaultValue.ignorePatterns,
56
+ };
57
+ }
58
+
59
+ function profilePatternIds(profile: SearchProfile | null): readonly string[] {
60
+ if (!profile?.patterns) return [];
61
+ return Object.entries(profile.patterns)
62
+ .filter(([, pattern]) => pattern.enabled === true)
63
+ .map(([id]) => id);
64
+ }
65
+
66
+ function checksById(ids: readonly string[]): readonly StupifyCheck[] {
67
+ const byId = new Map<string, StupifyCheck>(defaultChecks.map((check) => [check.id, check]));
68
+ return ids.map((id) => {
69
+ const check = byId.get(id);
70
+ if (!check) throw new Error(`Unknown check in search profile: ${id}`);
71
+ return check;
72
+ });
73
+ }
74
+
75
+ function applyPatternOverride(check: StupifyCheck, override: SearchProfilePattern | undefined): StupifyCheck {
76
+ if (!override) return check;
77
+ return {
78
+ ...check,
79
+ searchPrompt: override.searchPrompt ?? check.searchPrompt,
80
+ searchExamples: {
81
+ match: override.matchExamples ?? check.searchExamples?.match ?? check.examples?.match ?? [],
82
+ nonMatch: override.nonMatchExamples ?? check.searchExamples?.nonMatch ?? check.examples?.noMatch ?? [],
83
+ },
84
+ };
85
+ }
86
+
87
+ function positiveInteger(value: unknown): number | null {
88
+ return Number.isInteger(value) && Number(value) > 0 ? Number(value) : null;
89
+ }
@@ -10,9 +10,10 @@ import {
10
10
  sourceRangeForCommit,
11
11
  sourceRangeForRecentCommits,
12
12
  sourceRangeSince,
13
+ stagedDiff,
13
14
  } from "./git.ts";
14
15
  import type {
15
- AnalyzeCommand,
16
+ SearchCommand,
16
17
  SemChange,
17
18
  SemChangeSet,
18
19
  SemChangeSummary,
@@ -23,9 +24,14 @@ import { sourceId } from "./types.ts";
23
24
  const execFileAsync = promisify(execFile);
24
25
 
25
26
  export async function semChangeSetForCommand(
26
- command: AnalyzeCommand,
27
+ command: SearchCommand,
27
28
  ): Promise<SemChangeSet> {
28
29
  if (command.kind === "stdin") return semChangeSetFromPatch(await readDiffFromStdin(), command.debugSem);
30
+ if (command.kind === "staged") {
31
+ const diff = await stagedDiff();
32
+ if (!diff.text.trim()) return emptyChangeSet("staged", diff.stats);
33
+ return semChangeSetFromPatch(diff.text, command.debugSem, "staged");
34
+ }
29
35
  if (command.kind === "commit") {
30
36
  const range = await sourceRangeForCommit(command.commit);
31
37
  const raw = await cachedSemDiff(
@@ -45,14 +51,35 @@ export async function semChangeSetForCommand(
45
51
  return withContextWorkspace(normalizeSemDiff(raw, range), command.debugSem);
46
52
  }
47
53
 
48
- async function semRangeForCommand(command: AnalyzeCommand): Promise<SourceRange> {
54
+ function emptyChangeSet(label: string, stats: SourceRange["stats"]): SemChangeSet {
55
+ return {
56
+ id: sourceId(label),
57
+ label,
58
+ base: label,
59
+ target: label,
60
+ contextCwd: process.cwd(),
61
+ cleanup: async () => undefined,
62
+ changes: [],
63
+ summary: {
64
+ added: stats.additions,
65
+ deleted: stats.deletions,
66
+ modified: 0,
67
+ moved: 0,
68
+ renamed: 0,
69
+ fileCount: stats.filesChanged,
70
+ total: 0,
71
+ },
72
+ };
73
+ }
74
+
75
+ async function semRangeForCommand(command: SearchCommand): Promise<SourceRange> {
49
76
  if (command.kind === "since") return sourceRangeSince(command.since);
50
77
  if (command.kind === "commit") return sourceRangeForCommit(command.commit);
51
78
  if (command.kind === "commits") return sourceRangeForRecentCommits(command.count);
52
- throw new Error("sem engine cannot resolve stdin as a git range.");
79
+ throw new Error("sem cannot resolve stdin as a git range.");
53
80
  }
54
81
 
55
- async function semChangeSetFromPatch(patch: string, debugSem: boolean): Promise<SemChangeSet> {
82
+ async function semChangeSetFromPatch(patch: string, debugSem: boolean, label = "stdin"): Promise<SemChangeSet> {
56
83
  if (!patch.trim()) throw new Error("No diff received on stdin.");
57
84
  const raw = await cachedJson(
58
85
  "sem-diff",
@@ -66,10 +93,10 @@ async function semChangeSetFromPatch(patch: string, debugSem: boolean): Promise<
66
93
  );
67
94
  return {
68
95
  ...normalizeSemDiff(raw, {
69
- id: sourceId("stdin"),
70
- label: "stdin",
71
- base: "stdin",
72
- target: "stdin",
96
+ id: sourceId(label),
97
+ label,
98
+ base: label,
99
+ target: label,
73
100
  stats: { filesChanged: 0, additions: 0, deletions: 0 },
74
101
  }),
75
102
  contextCwd: process.cwd(),