Skip to content

Commit a8e443b

Browse files
authored
Merge pull request #11 from bhouston/better-upgrade
Better upgrade + simplified logging
2 parents f781e22 + 71258f1 commit a8e443b

18 files changed

+160
-219
lines changed

src/commands/$default.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const builder = (yargs) => {
2424
};
2525

2626
export const handler = async (argv: ArgumentsCamelCase<Options>) => {
27-
const logger = new Logger({ name: "Default", color: "white" });
27+
const logger = new Logger({ name: "Default" });
2828
const require = createRequire(import.meta.url);
2929
const packageInfo = require("../../package.json");
3030

@@ -33,7 +33,7 @@ export const handler = async (argv: ArgumentsCamelCase<Options>) => {
3333
"WARNING: This tool can do anything on your command line that you ask it to.",
3434
"It can delete files, install software, and even send data to remote servers.",
3535
"It is a powerful tool that should be used with caution.",
36-
"By using this tool, you agree that the authors and contributors are not responsible for any damage that may occur as a result of using this tool."
36+
"By using this tool, you agree that the authors and contributors are not responsible for any damage that may occur as a result of using this tool.",
3737
);
3838
try {
3939
// Early API key check
@@ -50,7 +50,7 @@ export const handler = async (argv: ArgumentsCamelCase<Options>) => {
5050
prompt = await fs.readFile(argv.file, "utf-8");
5151
} catch (error: any) {
5252
logger.error(
53-
`Failed to read prompt file: ${argv.file}, ${error?.message}`
53+
`Failed to read prompt file: ${argv.file}, ${error?.message}`,
5454
);
5555
process.exit(1);
5656
}
@@ -65,7 +65,7 @@ export const handler = async (argv: ArgumentsCamelCase<Options>) => {
6565

6666
try {
6767
logger.info(
68-
"Type your request below or 'help' for usage information. Use Ctrl+C to exit."
68+
"Type your request below or 'help' for usage information. Use Ctrl+C to exit.",
6969
);
7070
prompt = await readline.question("\n> ");
7171
} finally {
@@ -78,7 +78,7 @@ export const handler = async (argv: ArgumentsCamelCase<Options>) => {
7878

7979
if (!prompt) {
8080
logger.error(
81-
"No prompt provided. Either specify a prompt, use --promptFile, or run in --interactive mode."
81+
"No prompt provided. Either specify a prompt, use --promptFile, or run in --interactive mode.",
8282
);
8383
process.exit(1);
8484
}

src/commands/tools.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ function formatSchema(schema: {
2121
if (schema.properties) {
2222
for (const [paramName, param] of Object.entries(schema.properties)) {
2323
const required = schema.required?.includes(paramName)
24-
? " (required)"
24+
? ""
2525
: " (optional)";
26-
const description =
27-
(param as any).description || "No description available";
26+
const description = (param as any).description || "";
2827
output += `${paramName}${required}: ${description}\n`;
2928

3029
if ((param as any).type) {
@@ -61,8 +60,8 @@ export const handler = async () => {
6160
tool.parameters as {
6261
properties?: Record<string, JsonSchema7Type>;
6362
required?: string[];
64-
}
65-
)
63+
},
64+
),
6665
);
6766

6867
// Returns section
@@ -73,8 +72,8 @@ export const handler = async () => {
7372
tool.returns as {
7473
properties?: Record<string, JsonSchema7Type>;
7574
required?: string[];
76-
}
77-
)
75+
},
76+
),
7877
);
7978
} else {
8079
console.log(" Type: any");

src/core/toolAgent.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
33
import { executeToolCall } from "./executeToolCall.js";
44
import { Tool } from "./types.js";
5-
import { Logger } from "../utils/logger.js";
65
import { toolAgent } from "./toolAgent.js";
6+
import { MockLogger } from "../utils/mockLogger.js";
77

8-
const logger = new Logger({ name: "toolAgent", logLevel: "warn" });
8+
const logger = new MockLogger();
99

1010
// Mock configuration for testing
1111
const testConfig = {
@@ -96,7 +96,7 @@ describe("toolAgent", () => {
9696
input: { input: "test" },
9797
},
9898
[mockTool],
99-
logger,
99+
logger
100100
);
101101

102102
expect(result.includes("Processed: test")).toBeTruthy();
@@ -111,8 +111,8 @@ describe("toolAgent", () => {
111111
input: {},
112112
},
113113
[mockTool],
114-
logger,
115-
),
114+
logger
115+
)
116116
).rejects.toThrow("No tool with the name 'nonexistentTool' exists.");
117117
});
118118

@@ -142,8 +142,8 @@ describe("toolAgent", () => {
142142
input: {},
143143
},
144144
[errorTool],
145-
logger,
146-
),
145+
logger
146+
)
147147
).rejects.toThrow("Deliberate failure");
148148
});
149149

@@ -153,7 +153,7 @@ describe("toolAgent", () => {
153153
"Test prompt",
154154
[sequenceCompleteTool],
155155
logger,
156-
testConfig,
156+
testConfig
157157
);
158158

159159
expect(result.result).toBe("Test complete");

src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as dotenv from "dotenv";
22
import yargs from "yargs";
33
import { hideBin } from "yargs/helpers";
4-
import { Logger } from "./utils/logger.js";
4+
import { Logger, LogLevel } from "./utils/logger.js";
55
import { createRequire } from "module";
66
import { join } from "path";
77
import { fileURLToPath } from "url";
@@ -16,14 +16,21 @@ import { getTools } from "./tools/getTools.js";
1616

1717
sourceMapSupport.install();
1818

19+
const nameToLogIndex = (logLevelName: string) => {
20+
// look up the log level name in the enum to get the value
21+
return LogLevel[logLevelName as keyof typeof LogLevel];
22+
};
23+
1924
const main = async () => {
2025
dotenv.config();
2126

22-
const logger = new Logger({ name: "Main", color: "white" });
27+
const logger = new Logger({ name: "Main" });
2328

2429
const updateMessage = await checkForUpdates();
2530
if (updateMessage) {
31+
console.log();
2632
logger.info(updateMessage);
33+
console.log();
2734
}
2835

2936
// Error handling
@@ -60,8 +67,7 @@ const main = async () => {
6067
// Set up logger with the specified log level
6168
argv.logger = new Logger({
6269
name: packageInfo.name!,
63-
color: "white",
64-
logLevel: argv.log,
70+
logLevel: nameToLogIndex(argv.log),
6571
});
6672
argv.tools = await getTools();
6773
})

src/test-eslint.ts

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

src/tools/interaction/subAgent.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
22
import { subAgentTool } from "./subAgent.js";
3-
import { Logger } from "../../utils/logger.js";
3+
import { MockLogger } from "../../utils/mockLogger.js";
44

5-
const logger = new Logger({ name: "subAgent", logLevel: "warn" });
5+
const logger = new MockLogger();
66

77
// Mock Anthropic client response
88
const mockResponse = {

src/tools/io/readFile.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { describe, it, expect } from "vitest";
2-
import { Logger } from "../../utils/logger.js";
32
import { readFileTool } from "./readFile.js";
3+
import { MockLogger } from "../../utils/mockLogger.js";
44

5-
const logger = new Logger({ name: "readFile", logLevel: "warn" });
5+
const logger = new MockLogger();
66

77
describe("readFile", () => {
88
it("should read a file", async () => {

src/tools/io/updateFile.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { join } from "path";
44
import { randomUUID } from "crypto";
55
import { mkdtemp } from "fs/promises";
66
import { tmpdir } from "os";
7-
import { Logger } from "../../utils/logger.js";
87
import { updateFileTool } from "./updateFile.js";
98
import { readFileTool } from "./readFile.js";
109
import { shellExecuteTool } from "../system/shellExecute.js";
10+
import { MockLogger } from "../../utils/mockLogger.js";
1111

12-
const logger = new Logger({ name: "updateFile", logLevel: "warn" });
12+
const logger = new MockLogger();
1313

1414
describe("updateFile", () => {
1515
let testDir: string;

src/tools/system/shellExecute.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { describe, it, expect } from "vitest";
2-
import { Logger } from "../../utils/logger.js";
32
import { shellExecuteTool } from "./shellExecute.js";
3+
import { MockLogger } from "../../utils/mockLogger.js";
44

5-
const logger = new Logger({ name: "shellExecute", logLevel: "warn" });
5+
const logger = new MockLogger();
66

77
describe("shellExecute", () => {
88
it("should execute shell commands", async () => {

src/tools/system/shellMessage.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { processStates, shellStartTool } from "./shellStart.js";
33
import { MockLogger } from "../../utils/mockLogger.js";
44
import { shellMessageTool } from "./shellMessage.js";
55

6+
const logger = new MockLogger();
7+
68
// Helper function to get instanceId from shellStart result
79
const getInstanceId = (
8-
result: Awaited<ReturnType<typeof shellStartTool.execute>>
10+
result: Awaited<ReturnType<typeof shellStartTool.execute>>,
911
) => {
1012
if (result.mode === "async") {
1113
return result.instanceId;
@@ -15,8 +17,6 @@ const getInstanceId = (
1517

1618
// eslint-disable-next-line max-lines-per-function
1719
describe("shellMessageTool", () => {
18-
const mockLogger = new MockLogger();
19-
2020
let testInstanceId = "";
2121

2222
beforeEach(() => {
@@ -38,7 +38,7 @@ describe("shellMessageTool", () => {
3838
description: "Test interactive process",
3939
timeout: 50, // Force async mode for interactive process
4040
},
41-
{ logger: mockLogger }
41+
{ logger },
4242
);
4343

4444
testInstanceId = getInstanceId(startResult);
@@ -50,7 +50,7 @@ describe("shellMessageTool", () => {
5050
stdin: "hello world",
5151
description: "Test interaction",
5252
},
53-
{ logger: mockLogger }
53+
{ logger },
5454
);
5555

5656
expect(result.stdout).toBe("hello world");
@@ -64,7 +64,7 @@ describe("shellMessageTool", () => {
6464
instanceId: "nonexistent-id",
6565
description: "Test invalid process",
6666
},
67-
{ logger: mockLogger }
67+
{ logger },
6868
);
6969

7070
expect(result.error).toBeDefined();
@@ -79,7 +79,7 @@ describe("shellMessageTool", () => {
7979
description: "Test completion",
8080
timeout: 0, // Force async mode
8181
},
82-
{ logger: mockLogger }
82+
{ logger },
8383
);
8484

8585
const instanceId = getInstanceId(startResult);
@@ -92,7 +92,7 @@ describe("shellMessageTool", () => {
9292
instanceId,
9393
description: "Check completion",
9494
},
95-
{ logger: mockLogger }
95+
{ logger },
9696
);
9797

9898
expect(result.completed).toBe(true);
@@ -108,7 +108,7 @@ describe("shellMessageTool", () => {
108108
description: "Test SIGTERM handling",
109109
timeout: 0, // Force async mode
110110
},
111-
{ logger: mockLogger }
111+
{ logger },
112112
);
113113

114114
const instanceId = getInstanceId(startResult);
@@ -119,7 +119,7 @@ describe("shellMessageTool", () => {
119119
signal: "SIGTERM",
120120
description: "Send SIGTERM",
121121
},
122-
{ logger: mockLogger }
122+
{ logger },
123123
);
124124
expect(result.signaled).toBe(true);
125125

@@ -130,7 +130,7 @@ describe("shellMessageTool", () => {
130130
instanceId,
131131
description: "Check on status",
132132
},
133-
{ logger: mockLogger }
133+
{ logger },
134134
);
135135

136136
expect(result2.completed).toBe(true);
@@ -145,7 +145,7 @@ describe("shellMessageTool", () => {
145145
description: "Test signal handling on terminated process",
146146
timeout: 0, // Force async mode
147147
},
148-
{ logger: mockLogger }
148+
{ logger },
149149
);
150150

151151
const instanceId = getInstanceId(startResult);
@@ -157,7 +157,7 @@ describe("shellMessageTool", () => {
157157
signal: "SIGTERM",
158158
description: "Send signal to terminated process",
159159
},
160-
{ logger: mockLogger }
160+
{ logger },
161161
);
162162

163163
expect(result.signaled).toBe(true);
@@ -172,7 +172,7 @@ describe("shellMessageTool", () => {
172172
description: "Test signal flag verification",
173173
timeout: 0, // Force async mode
174174
},
175-
{ logger: mockLogger }
175+
{ logger },
176176
);
177177

178178
const instanceId = getInstanceId(startResult);
@@ -184,7 +184,7 @@ describe("shellMessageTool", () => {
184184
signal: "SIGTERM",
185185
description: "Send SIGTERM",
186186
},
187-
{ logger: mockLogger }
187+
{ logger },
188188
);
189189

190190
await new Promise((resolve) => setTimeout(resolve, 50));
@@ -195,7 +195,7 @@ describe("shellMessageTool", () => {
195195
instanceId,
196196
description: "Check signal state",
197197
},
198-
{ logger: mockLogger }
198+
{ logger },
199199
);
200200

201201
expect(checkResult.signaled).toBe(true);

0 commit comments

Comments
 (0)