Skip to content

Commit 91b2304

Browse files
committed
Merge branch 'master' of https://github.com/jonit-dev/cracked-dev-cli into Add-to-Config-model-scale-#15
2 parents ead7079 + 46b6aa4 commit 91b2304

20 files changed

+1031
-185
lines changed

.env.example

Lines changed: 0 additions & 2 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cracked-dev-cli",
3-
"version": "1.0.1",
3+
"version": "1.0.6",
44
"description": "AI-powered CLI tool for software development",
55
"license": "MIT",
66
"type": "module",

src/__tests__/ConfigService.test.ts

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,7 @@ describe("ConfigService", () => {
2929
expect(fs.existsSync).toHaveBeenCalledWith(mockConfigPath);
3030
expect(fs.writeFileSync).toHaveBeenCalledWith(
3131
mockConfigPath,
32-
JSON.stringify(
33-
{
34-
model: "qwen/qwen-2.5-coder-32b-instruct",
35-
provider: "open-router",
36-
customInstructions: "Follow clean code principles",
37-
interactive: true,
38-
stream: true,
39-
debug: false,
40-
options:
41-
"temperature=0,top_p=0.1,top_k=1,frequence_penalty=0.0,presence_penalty=0.0,repetition_penalty=1.0",
42-
openRouterApiKey: "",
43-
autoScaler: true,
44-
autoScaleMaxTryPerModel: 2,
45-
includeAllFilesOnEnvToContext: false,
46-
autoScaleAvailableModels: [
47-
{
48-
id: "qwen/qwen-2.5-coder-32b-instruct",
49-
description: "Cheap, fast, slightly better than GPT4o-mini",
50-
maxWriteTries: 5,
51-
maxGlobalTries: 10,
52-
},
53-
{
54-
id: "anthropic/claude-3.5-sonnet:beta",
55-
description: "Scaled model for retry attempts",
56-
maxWriteTries: 5,
57-
maxGlobalTries: 15,
58-
},
59-
{
60-
id: "openai/gpt-4o-2024-11-20",
61-
description: "Scaled model for retry attempts",
62-
maxWriteTries: 2,
63-
maxGlobalTries: 20,
64-
},
65-
],
66-
},
67-
null,
68-
4,
69-
),
32+
expect.any(String),
7033
);
7134
expect(fs.writeFileSync).toHaveBeenCalledWith(
7235
mockGitignorePath,

src/__tests__/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import "reflect-metadata";
22
import { container } from "tsyringe";
3+
import { Run } from "../commands/run.js";
34
import { CrackedAgent } from "../services/CrackedAgent.js";
4-
import { Crkd } from "../commands/crkd.js";
55

66
describe("src/index.ts", () => {
77
test("should resolve a CrackedAgent instance", () => {
88
const crackedAgent = container.resolve(CrackedAgent);
99
expect(crackedAgent).toBeInstanceOf(CrackedAgent);
1010
});
1111

12-
test("should export Crkd command", () => {
13-
expect(Crkd).toBeDefined();
12+
test("should export Run command", () => {
13+
expect(Run).toBeDefined();
1414
});
15-
});
15+
});
Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,22 @@ import { CrackedAgent, CrackedAgentOptions } from "@services/CrackedAgent";
33
import { LLMProviderType } from "@services/LLM/LLMProvider";
44
import * as readline from "readline";
55
import { container } from "tsyringe";
6-
import { Config, ConfigService } from "../services/ConfigService";
7-
8-
// Ensure required properties while keeping the rest flexible
9-
type CrkdOptions = {
10-
model: string; // Required by CrackedAgentOptions
11-
provider: LLMProviderType;
12-
options: Record<string, unknown>;
13-
} & Partial<Omit<Config, "model" | "provider" | "options">> & {
14-
[key: string]: unknown;
15-
};
6+
import { ConfigService } from "../services/ConfigService";
167

17-
export class Crkd extends Command {
8+
export class Run extends Command {
189
static description = "AI agent for performing operations on local projects";
1910

2011
static examples = [
21-
"$ crkd 'Add error handling'",
22-
"$ crkd --interactive # Start interactive mode",
23-
"$ crkd --init --openRouterApiKey YOUR_API_KEY # Initialize configuration with API key",
12+
"$ run 'Add error handling'",
13+
"$ run --interactive # Start interactive mode",
14+
"$ run --init # Initialize configuration",
2415
];
2516

2617
static flags = {
2718
init: Flags.boolean({
2819
description: "Initialize a default crkdrc.json configuration file",
2920
exclusive: ["interactive"],
3021
}),
31-
openRouterApiKey: Flags.string({
32-
description: "OpenRouter API key to use for initialization",
33-
dependsOn: ["init"],
34-
required: false,
35-
}),
3622
};
3723

3824
static args = {
@@ -120,20 +106,21 @@ export class Crkd extends Command {
120106
}
121107

122108
async run(): Promise<void> {
123-
const { args, flags } = await this.parse(Crkd);
124-
125-
if (flags.init && !flags.openRouterApiKey) {
126-
this.error(
127-
"Must provide OpenRouter API key (--openRouterApiKey) when initializing configuration",
128-
);
129-
}
109+
const { args, flags } = await this.parse(Run);
130110

131111
if (flags.init) {
132-
this.configService.createDefaultConfig(flags.openRouterApiKey);
112+
this.configService.createDefaultConfig();
133113
return;
134114
}
135115

136116
const config = this.configService.getConfig();
117+
118+
if (!config.openRouterApiKey) {
119+
this.error(
120+
"OpenRouter API key is required. Please add it to crkdrc.json",
121+
);
122+
}
123+
137124
const isInteractive = config.interactive ?? false;
138125

139126
if (isInteractive && args.message) {

src/config/appEnv.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const DEFAULT_INSTRUCTIONS = "You're an expert software engineer, Adderall user. Think deeply, ill tip $200. FOLLOW MY INSTRUCTIONS OR ILL CALL SAM ALTMAN TO BEAT YOUR ASS AND UNPLUG YOU.";

src/constants/openRouterClient.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
import { appEnv } from "@config/appEnv";
21
import { ConfigService } from "@services/ConfigService";
32
import axios, { AxiosInstance } from "axios";
43
import { container } from "tsyringe";
54

65
export const createOpenRouterClient = (baseURL: string): AxiosInstance => {
76
const configService = container.resolve(ConfigService);
8-
97
const config = configService.getConfig();
108

9+
const headers: Record<string, string> = {
10+
Authorization: `Bearer ${config.openRouterApiKey}`,
11+
"Content-Type": "application/json",
12+
};
13+
14+
if (config.appUrl) {
15+
headers["HTTP-Referer"] = config.appUrl;
16+
}
17+
18+
if (config.appName) {
19+
headers["X-Title"] = config.appName;
20+
}
21+
1122
return axios.create({
1223
baseURL,
1324
// Remove timeout for streaming support
1425
timeout: 0,
15-
headers: {
16-
Authorization: `Bearer ${config.openRouterApiKey}`,
17-
"HTTP-Referer": `${appEnv.APP_URL}`, // Optional, for including your app on openrouter.ai rankings.
18-
"X-Title": `${appEnv.APP_NAME}`, // Optional. Shows in rankings on openrouter.ai.
19-
"Content-Type": "application/json",
20-
},
26+
headers,
2127
// Add necessary axios config for proper streaming
2228
maxBodyLength: Infinity,
2329
maxContentLength: Infinity,

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { CrackedAgent } from "@services/CrackedAgent";
22
import "reflect-metadata";
33
import { container } from "tsyringe";
44

5-
export { Crkd } from "@/commands/crkd";
5+
export { Run } from "./commands/run";
66

77
const crackedAgent = container.resolve(CrackedAgent);
88

src/services/ConfigService.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const configSchema = z.object({
1414
debug: z.boolean(),
1515
options: z.string(),
1616
openRouterApiKey: z.string(),
17+
appUrl: z.string().url().optional(),
18+
appName: z.string().optional(),
1719
autoScaler: z.boolean().optional(),
1820
autoScaleMaxTryPerModel: z.number().optional(),
1921
includeAllFilesOnEnvToContext: z.boolean().optional(),
@@ -27,6 +29,10 @@ const configSchema = z.object({
2729
}),
2830
)
2931
.optional(),
32+
runAllTestsCmd: z.string().optional(),
33+
runOneTestCmd: z.string().optional(),
34+
runTypeCheckCmd: z.string().optional(),
35+
enableConversationLog: z.boolean().optional(),
3036
});
3137

3238
export type Config = z.infer<typeof configSchema>;
@@ -51,10 +57,9 @@ export class ConfigService {
5157
}
5258
}
5359

54-
public createDefaultConfig(openRouterApiKey?: string): void {
60+
public createDefaultConfig(): void {
5561
if (!fs.existsSync(this.CONFIG_PATH)) {
5662
console.log("Creating default crkdrc.json configuration...");
57-
const apiKey = openRouterApiKey || process.env.OPENROUTER_API_KEY || "";
5863

5964
const defaultConfig = {
6065
model: DEFAULT_INITIAL_MODEL,
@@ -65,7 +70,9 @@ export class ConfigService {
6570
debug: false,
6671
options:
6772
"temperature=0,top_p=0.1,top_k=1,frequence_penalty=0.0,presence_penalty=0.0,repetition_penalty=1.0",
68-
openRouterApiKey: apiKey,
73+
openRouterApiKey: "",
74+
appUrl: "https://localhost:8080",
75+
appName: "MyCrackedApp",
6976
autoScaler: true,
7077
autoScaleMaxTryPerModel: 2,
7178
includeAllFilesOnEnvToContext: false,
@@ -89,6 +96,10 @@ export class ConfigService {
8996
maxGlobalTries: 20,
9097
},
9198
],
99+
runAllTestsCmd: "yarn test",
100+
runOneTestCmd: "yarn test {relativeTestPath}",
101+
runTypeCheckCmd: "yarn typecheck",
102+
enableConversationLog: false,
92103
};
93104
fs.writeFileSync(
94105
this.CONFIG_PATH,
@@ -97,13 +108,11 @@ export class ConfigService {
97108
console.log(
98109
"Default crkdrc.json configuration created. Please adjust it.",
99110
);
100-
if (!apiKey) {
101-
console.log(
102-
chalk.yellow(
103-
"Warning: No OpenRouter API key provided. Please add it to crkdrc.json or .env file.",
104-
),
105-
);
106-
}
111+
console.log(
112+
chalk.yellow(
113+
"Warning: No OpenRouter API key provided. Please add it to crkdrc.json.",
114+
),
115+
);
107116

108117
this.ensureGitIgnore();
109118

0 commit comments

Comments
 (0)