@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.
- package/README.md +26 -31
- package/dist/analysis.d.ts +11 -9
- package/dist/analysis.js +30 -173
- package/dist/checks.d.ts +1 -0
- package/dist/checks.js +89 -2
- package/dist/command.js +55 -91
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/counter-scout.js +70 -8
- package/dist/doctor.d.ts +4 -0
- package/dist/doctor.js +131 -0
- package/dist/git.d.ts +4 -1
- package/dist/git.js +34 -0
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.js +117 -0
- package/dist/model.d.ts +1 -15
- package/dist/model.js +37 -21
- package/dist/prompts.d.ts +8 -5
- package/dist/prompts.js +58 -168
- package/dist/render.d.ts +2 -2
- package/dist/render.js +70 -78
- package/dist/repomix-provider.d.ts +10 -2
- package/dist/repomix-provider.js +62 -11
- package/dist/search-bench.d.ts +1 -0
- package/dist/search-bench.js +675 -0
- package/dist/search-profile.d.ts +6 -0
- package/dist/search-profile.js +73 -0
- package/dist/sem-provider.d.ts +2 -2
- package/dist/sem-provider.js +33 -7
- package/dist/stupify.d.ts +2 -0
- package/dist/stupify.js +185 -334
- package/dist/types.d.ts +193 -109
- package/package.json +1 -1
- package/src/analysis.ts +48 -268
- package/src/checks.ts +91 -2
- package/src/command.ts +62 -107
- package/src/constants.ts +1 -1
- package/src/counter-scout.ts +63 -7
- package/src/doctor.ts +140 -0
- package/src/git.ts +35 -1
- package/src/hooks.ts +134 -0
- package/src/model.ts +39 -26
- package/src/prompts.ts +66 -202
- package/src/render.ts +68 -79
- package/src/repomix-provider.ts +66 -10
- package/src/search-bench.ts +783 -0
- package/src/search-profile.ts +89 -0
- package/src/sem-provider.ts +36 -9
- package/src/stupify.ts +215 -527
- package/src/types.ts +195 -119
- package/dist/batcher.d.ts +0 -3
- package/dist/batcher.js +0 -142
- package/dist/candidate-context.d.ts +0 -2
- package/dist/candidate-context.js +0 -40
- package/dist/experiment.d.ts +0 -1
- package/dist/experiment.js +0 -225
- package/src/batcher.ts +0 -198
- package/src/candidate-context.ts +0 -43
- package/src/experiment.ts +0 -317
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
}
|
package/dist/sem-provider.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function semChangeSetForCommand(command:
|
|
1
|
+
import type { SearchCommand, SemChangeSet } from "./types.ts";
|
|
2
|
+
export declare function semChangeSetForCommand(command: SearchCommand): Promise<SemChangeSet>;
|
package/dist/sem-provider.js
CHANGED
|
@@ -6,12 +6,18 @@ import path from "node:path";
|
|
|
6
6
|
import { promisify } from "node:util";
|
|
7
7
|
import { cachedJson, fingerprint } from "./cache.js";
|
|
8
8
|
import { readDiffFromStdin } from "./diff.js";
|
|
9
|
-
import { sourceRangeForCommit, sourceRangeForRecentCommits, sourceRangeSince, } from "./git.js";
|
|
9
|
+
import { sourceRangeForCommit, sourceRangeForRecentCommits, sourceRangeSince, stagedDiff, } from "./git.js";
|
|
10
10
|
import { sourceId } from "./types.js";
|
|
11
11
|
const execFileAsync = promisify(execFile);
|
|
12
12
|
export async function semChangeSetForCommand(command) {
|
|
13
13
|
if (command.kind === "stdin")
|
|
14
14
|
return semChangeSetFromPatch(await readDiffFromStdin(), command.debugSem);
|
|
15
|
+
if (command.kind === "staged") {
|
|
16
|
+
const diff = await stagedDiff();
|
|
17
|
+
if (!diff.text.trim())
|
|
18
|
+
return emptyChangeSet("staged", diff.stats);
|
|
19
|
+
return semChangeSetFromPatch(diff.text, command.debugSem, "staged");
|
|
20
|
+
}
|
|
15
21
|
if (command.kind === "commit") {
|
|
16
22
|
const range = await sourceRangeForCommit(command.commit);
|
|
17
23
|
const raw = await cachedSemDiff(["diff", "--commit", command.commit, "--format", "json"], range, command.debugSem);
|
|
@@ -21,6 +27,26 @@ export async function semChangeSetForCommand(command) {
|
|
|
21
27
|
const raw = await cachedSemDiff(["diff", "--from", range.base, "--to", range.target, "--format", "json"], range, command.debugSem);
|
|
22
28
|
return withContextWorkspace(normalizeSemDiff(raw, range), command.debugSem);
|
|
23
29
|
}
|
|
30
|
+
function emptyChangeSet(label, stats) {
|
|
31
|
+
return {
|
|
32
|
+
id: sourceId(label),
|
|
33
|
+
label,
|
|
34
|
+
base: label,
|
|
35
|
+
target: label,
|
|
36
|
+
contextCwd: process.cwd(),
|
|
37
|
+
cleanup: async () => undefined,
|
|
38
|
+
changes: [],
|
|
39
|
+
summary: {
|
|
40
|
+
added: stats.additions,
|
|
41
|
+
deleted: stats.deletions,
|
|
42
|
+
modified: 0,
|
|
43
|
+
moved: 0,
|
|
44
|
+
renamed: 0,
|
|
45
|
+
fileCount: stats.filesChanged,
|
|
46
|
+
total: 0,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
24
50
|
async function semRangeForCommand(command) {
|
|
25
51
|
if (command.kind === "since")
|
|
26
52
|
return sourceRangeSince(command.since);
|
|
@@ -28,9 +54,9 @@ async function semRangeForCommand(command) {
|
|
|
28
54
|
return sourceRangeForCommit(command.commit);
|
|
29
55
|
if (command.kind === "commits")
|
|
30
56
|
return sourceRangeForRecentCommits(command.count);
|
|
31
|
-
throw new Error("sem
|
|
57
|
+
throw new Error("sem cannot resolve stdin as a git range.");
|
|
32
58
|
}
|
|
33
|
-
async function semChangeSetFromPatch(patch, debugSem) {
|
|
59
|
+
async function semChangeSetFromPatch(patch, debugSem, label = "stdin") {
|
|
34
60
|
if (!patch.trim())
|
|
35
61
|
throw new Error("No diff received on stdin.");
|
|
36
62
|
const raw = await cachedJson("sem-diff", fingerprint({
|
|
@@ -41,10 +67,10 @@ async function semChangeSetFromPatch(patch, debugSem) {
|
|
|
41
67
|
}), () => runSemWithInput(["diff", "--patch", "--format", "json"], patch, debugSem));
|
|
42
68
|
return {
|
|
43
69
|
...normalizeSemDiff(raw, {
|
|
44
|
-
id: sourceId(
|
|
45
|
-
label
|
|
46
|
-
base:
|
|
47
|
-
target:
|
|
70
|
+
id: sourceId(label),
|
|
71
|
+
label,
|
|
72
|
+
base: label,
|
|
73
|
+
target: label,
|
|
48
74
|
stats: { filesChanged: 0, additions: 0, deletions: 0 },
|
|
49
75
|
}),
|
|
50
76
|
contextCwd: process.cwd(),
|
package/dist/stupify.d.ts
CHANGED