@stupify/cli 0.0.2 → 0.0.4

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 (66) hide show
  1. package/README.md +55 -0
  2. package/dist/analysis.d.ts +16 -0
  3. package/dist/analysis.js +133 -0
  4. package/dist/cache.d.ts +2 -0
  5. package/dist/cache.js +59 -0
  6. package/dist/checks.d.ts +4 -0
  7. package/dist/checks.js +218 -0
  8. package/dist/command.d.ts +2 -0
  9. package/dist/command.js +147 -0
  10. package/dist/constants.d.ts +4 -0
  11. package/dist/constants.js +53 -0
  12. package/dist/counter-scout.d.ts +14 -0
  13. package/dist/counter-scout.js +159 -0
  14. package/dist/diff.d.ts +1 -0
  15. package/dist/diff.js +10 -0
  16. package/dist/doctor.d.ts +4 -0
  17. package/dist/doctor.js +131 -0
  18. package/dist/git.d.ts +11 -0
  19. package/dist/git.js +253 -0
  20. package/dist/hooks.d.ts +3 -0
  21. package/dist/hooks.js +117 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +1 -0
  24. package/dist/model.d.ts +10 -0
  25. package/dist/model.js +297 -0
  26. package/dist/prompts.d.ts +8 -0
  27. package/dist/prompts.js +87 -0
  28. package/dist/render.d.ts +3 -0
  29. package/dist/render.js +93 -0
  30. package/dist/repomix-provider.d.ts +12 -0
  31. package/dist/repomix-provider.js +196 -0
  32. package/dist/search-bench.d.ts +1 -0
  33. package/dist/search-bench.js +675 -0
  34. package/dist/search-profile.d.ts +6 -0
  35. package/dist/search-profile.js +73 -0
  36. package/dist/sem-provider.d.ts +2 -0
  37. package/dist/sem-provider.js +247 -0
  38. package/dist/stupify.d.ts +4 -0
  39. package/dist/stupify.js +237 -0
  40. package/dist/trace.d.ts +29 -0
  41. package/dist/trace.js +64 -0
  42. package/dist/types.d.ts +320 -0
  43. package/dist/types.js +6 -0
  44. package/package.json +42 -5
  45. package/src/analysis.ts +188 -0
  46. package/src/cache.ts +65 -0
  47. package/src/checks.ts +221 -0
  48. package/src/command.ts +173 -0
  49. package/src/constants.ts +56 -0
  50. package/src/counter-scout.ts +175 -0
  51. package/src/diff.ts +9 -0
  52. package/src/doctor.ts +140 -0
  53. package/src/git.ts +262 -0
  54. package/src/hooks.ts +134 -0
  55. package/src/index.ts +1 -0
  56. package/src/model.ts +373 -0
  57. package/src/prompts.ts +98 -0
  58. package/src/render.ts +96 -0
  59. package/src/repomix-provider.ts +219 -0
  60. package/src/search-bench.ts +783 -0
  61. package/src/search-profile.ts +89 -0
  62. package/src/sem-provider.ts +282 -0
  63. package/src/stupify.ts +285 -0
  64. package/src/trace.ts +103 -0
  65. package/src/types.ts +340 -0
  66. package/bin/stupify.mjs +0 -3
@@ -0,0 +1,196 @@
1
+ import { mkdtemp, readFile, rm, stat } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import path from "node:path";
4
+ import { pack, setLogLevel } from "repomix";
5
+ const MAX_PACK_FILE_SIZE_BYTES = 48 * 1024;
6
+ const MAX_PACK_TOTAL_SIZE_BYTES = 128 * 1024;
7
+ export function emptyContextPack() {
8
+ const config = repomixSearchConfig();
9
+ return {
10
+ provider: "repomix",
11
+ filePaths: [],
12
+ totalCharacters: 0,
13
+ totalTokens: 0,
14
+ text: "",
15
+ config,
16
+ };
17
+ }
18
+ export async function repomixContextPack(cwd, contexts, changes, config = repomixSearchConfig()) {
19
+ const filePaths = await candidateFilePaths(cwd, contexts, changes, config);
20
+ if (filePaths.length === 0) {
21
+ return {
22
+ ...emptyContextPack(),
23
+ config,
24
+ };
25
+ }
26
+ setLogLevel(-1);
27
+ const tempDir = await mkdtemp(path.join(tmpdir(), "stupify-repomix-"));
28
+ const outputPath = path.join(tempDir, "context.xml");
29
+ try {
30
+ const result = await pack([cwd], {
31
+ cwd,
32
+ input: { maxFileSize: config.maxFileSizeBytes },
33
+ output: {
34
+ filePath: outputPath,
35
+ style: "xml",
36
+ parsableStyle: false,
37
+ fileSummary: false,
38
+ directoryStructure: false,
39
+ files: true,
40
+ removeComments: false,
41
+ removeEmptyLines: config.removeEmptyLines,
42
+ compress: config.compress,
43
+ topFilesLength: 0,
44
+ showLineNumbers: config.showLineNumbers,
45
+ truncateBase64: true,
46
+ copyToClipboard: false,
47
+ includeFullDirectoryStructure: false,
48
+ tokenCountTree: false,
49
+ git: {
50
+ sortByChanges: false,
51
+ sortByChangesMaxCommits: 1,
52
+ includeDiffs: false,
53
+ includeLogs: false,
54
+ includeLogsCount: 1,
55
+ },
56
+ },
57
+ include: [],
58
+ ignore: {
59
+ useGitignore: true,
60
+ useDotIgnore: true,
61
+ useDefaultPatterns: true,
62
+ customPatterns: [...config.ignorePatterns],
63
+ },
64
+ security: { enableSecurityCheck: false },
65
+ tokenCount: { encoding: "o200k_base" },
66
+ }, () => undefined, {}, [...filePaths]);
67
+ return {
68
+ provider: "repomix",
69
+ filePaths,
70
+ totalCharacters: result.totalCharacters,
71
+ totalTokens: result.totalTokens,
72
+ text: await readFile(outputPath, "utf8"),
73
+ config,
74
+ };
75
+ }
76
+ finally {
77
+ await rm(tempDir, { recursive: true, force: true });
78
+ }
79
+ }
80
+ export function entityContextsFromChanges(candidates, changes) {
81
+ const byEntityId = new Map(changes.map((change) => [change.entityId, change]));
82
+ return candidates.flatMap((candidate) => {
83
+ const change = byEntityId.get(candidate.entityId);
84
+ if (!change)
85
+ return [];
86
+ return [{
87
+ targetId: candidate.targetId,
88
+ entityId: change.entityId,
89
+ entityName: change.entityName,
90
+ entityKind: change.entityType,
91
+ changeKind: change.changeType,
92
+ checkId: candidate.checkId,
93
+ reason: candidate.reason,
94
+ filePath: change.filePath,
95
+ text: JSON.stringify({
96
+ source: "sem diff",
97
+ file: change.filePath,
98
+ type: change.entityType,
99
+ name: change.entityName,
100
+ change: change.changeType,
101
+ before: shortenCode(change.beforeContent),
102
+ after: shortenCode(change.afterContent),
103
+ }, null, 2),
104
+ }];
105
+ });
106
+ }
107
+ async function candidateFilePaths(cwd, contexts, changes, config) {
108
+ const byEntityId = new Map(changes.map((change) => [change.entityId, change.filePath]));
109
+ const paths = contexts.flatMap((context) => context.filePath ?? byEntityId.get(context.entityId) ?? []);
110
+ const safePaths = [...new Set(paths)].filter(isSafeRelativeFilePath);
111
+ const selected = [];
112
+ let totalBytes = 0;
113
+ for (const filePath of safePaths) {
114
+ if (matchesAnyPattern(filePath, config.ignorePatterns))
115
+ continue;
116
+ const bytes = await fileSize(cwd, filePath);
117
+ if (bytes === null || bytes > config.maxFileSizeBytes)
118
+ continue;
119
+ if (totalBytes + bytes > config.maxTotalSizeBytes)
120
+ continue;
121
+ totalBytes += bytes;
122
+ selected.push(filePath);
123
+ }
124
+ return selected;
125
+ }
126
+ export function repomixSearchConfig() {
127
+ return {
128
+ compress: envBoolean("STUPIFY_REPOMIX_COMPRESS", true),
129
+ showLineNumbers: envBoolean("STUPIFY_REPOMIX_SHOW_LINE_NUMBERS", true),
130
+ removeEmptyLines: envBoolean("STUPIFY_REPOMIX_REMOVE_EMPTY_LINES", true),
131
+ maxFileSizeBytes: envInteger("STUPIFY_REPOMIX_MAX_FILE_BYTES", MAX_PACK_FILE_SIZE_BYTES),
132
+ maxTotalSizeBytes: envInteger("STUPIFY_REPOMIX_MAX_TOTAL_BYTES", MAX_PACK_TOTAL_SIZE_BYTES),
133
+ ignorePatterns: envList("STUPIFY_REPOMIX_IGNORE_PATTERNS"),
134
+ };
135
+ }
136
+ function envBoolean(name, fallback) {
137
+ const value = process.env[name];
138
+ if (value === undefined || value === "")
139
+ return fallback;
140
+ return /^(1|true|yes|on)$/i.test(value);
141
+ }
142
+ function envInteger(name, fallback) {
143
+ const value = Number(process.env[name]);
144
+ return Number.isInteger(value) && value > 0 ? value : fallback;
145
+ }
146
+ function envList(name) {
147
+ return (process.env[name] ?? "")
148
+ .split(",")
149
+ .map((item) => item.trim())
150
+ .filter(Boolean);
151
+ }
152
+ function matchesAnyPattern(filePath, patterns) {
153
+ return patterns.some((pattern) => matchesPattern(filePath, pattern));
154
+ }
155
+ function matchesPattern(filePath, pattern) {
156
+ if (pattern === filePath)
157
+ return true;
158
+ if (!pattern.includes("*"))
159
+ return false;
160
+ const escaped = pattern
161
+ .split("*")
162
+ .map(escapeRegExp)
163
+ .join(".*");
164
+ return new RegExp(`^${escaped}$`).test(filePath);
165
+ }
166
+ function escapeRegExp(value) {
167
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
168
+ }
169
+ function isSafeRelativeFilePath(value) {
170
+ if (!value || path.isAbsolute(value))
171
+ return false;
172
+ const normalized = path.normalize(value);
173
+ return normalized !== "." && !normalized.startsWith("..") && !path.isAbsolute(normalized);
174
+ }
175
+ async function fileSize(cwd, filePath) {
176
+ try {
177
+ const fullPath = path.join(cwd, filePath);
178
+ if (!fullPath.startsWith(`${cwd}${path.sep}`))
179
+ return null;
180
+ const result = await stat(fullPath);
181
+ return result.isFile() ? result.size : null;
182
+ }
183
+ catch {
184
+ return null;
185
+ }
186
+ }
187
+ function shortenCode(value) {
188
+ if (!value)
189
+ return "(none)";
190
+ const lines = value.split(/\r?\n/);
191
+ const limit = 120;
192
+ if (lines.length <= limit)
193
+ return value;
194
+ return `${lines.slice(0, limit).join("\n")}
195
+ [stupify: sem entity content shortened after ${limit} lines]`;
196
+ }
@@ -0,0 +1 @@
1
+ export declare function runSearchBench(configPath: string): Promise<string>;