Skip to content

Commit 3ec60c4

Browse files
committed
more fmt
1 parent 9af8453 commit 3ec60c4

11 files changed

Lines changed: 163 additions & 67 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929
- name: Install kit CLI (editable)
3030
run: uv pip install -e .
3131

32-
- name: Lint & Type Check (TypeScript)
33-
run: scripts/format-ts.sh --fix
32+
- name: Lint & Type Check (Python + TypeScript)
33+
run: scripts/format.sh --fix
3434

3535
- name: Run JS Tests
3636
run: npm test --prefix clients/typescript

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ The CLI supports all major repository operations with Unix-friendly output for s
148148
* **Multiple Access Methods:**
149149
* **Python API**: Direct integration for building applications and scripts.
150150
* **Command Line Interface**: 11+ commands for shell scripting, CI/CD, and automation workflows.
151+
* **TypeScript / Node Client**: `npm install @runcased/kit` for type-safe wrapper that shells out to the same CLI.
151152
* **REST API**: HTTP endpoints for web applications and microservices.
152153
* **MCP Server**: Model Context Protocol integration for AI agents and development tools.
153154

clients/typescript/README.md

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,54 @@
11
# Kit TypeScript Client
22

3-
TypeScript/Node.js wrapper for the Cased Kit CLI. This library provides a type-safe interface to Kit's code analysis capabilities.
3+
TypeScript/Node.js wrapper for the Cased **Kit** CLI. This library lets you call Kit’s powerful code-analysis features from JavaScript or TypeScript with first-class typings.
44

55
## Installation
66

77
```bash
8-
npm install @cased/kit
8+
# 1) Install the TypeScript wrapper
9+
npm install @runcased/kit # or pnpm add / yarn add
10+
11+
# 2) Install the Kit CLI itself (Python)
12+
uv pip install cased-kit # or pipx install cased-kit; or any other python way
13+
```
14+
15+
> The TS wrapper shells out to the `kit` executable, so the Python package must be on **$PATH** in the same environment where Node runs (local dev, Docker image, CI runner, etc.).
16+
17+
**Requirements**
18+
19+
- Node 16 or newer
20+
- Python 3.10+ with `cased-kit` installed
21+
22+
## Quick Start
23+
24+
```typescript
25+
import { Kit } from "@runcased/kit";
26+
27+
const kit = new Kit(); // uses `kit` from $PATH
28+
const repo = kit.repository("./"); // current repo
29+
30+
(async () => {
31+
const info = await repo.gitInfo();
32+
console.log(info);
33+
34+
const files = await repo.fileTree(); // structured file list
35+
console.log(`Repo has ${files.length} entries`);
36+
})();
937
```
1038

11-
**Prerequisites:**
39+
## Wrapper Highlights
1240

13-
- Node.js 16+
14-
- Kit CLI installed (`pip install cased-kit`)
41+
- **Type-safe** – full `.d.ts` bundled, generics for options & results.
42+
- **Same API shape as Python** – methods map 1-to-1 to CLI commands.
43+
- **Repository helper**`kit.repository(path)` returns convenience wrapper so you don’t repeat the path/ref.
44+
- **No native deps** – only uses Node’s `child_process` to invoke CLI.
1545

16-
## Usage
46+
The remainder of this README contains advanced usage & API reference.
1747

1848
### Basic Setup
1949

2050
```typescript
21-
import { Kit } from "@cased/kit";
51+
import { Kit } from "@runcased/kit";
2252

2353
const kit = new Kit({
2454
kitPath: "kit", // Path to kit executable (optional)
@@ -73,7 +103,7 @@ results.forEach((result) => {
73103
const review = await kit.reviewPR("https://github.com/owner/repo/pull/123", {
74104
githubToken: process.env.GITHUB_TOKEN,
75105
llmProvider: "anthropic",
76-
model: "claude-3-sonnet-20240229",
106+
model: "claude-4-sonnet",
77107
apiKey: process.env.ANTHROPIC_API_KEY,
78108
priorities: ["high", "medium"],
79109
postAsComment: false, // Don't post to GitHub
@@ -96,7 +126,7 @@ const tree = await repo.fileTree();
96126
### Error Handling
97127

98128
```typescript
99-
import { KitError } from "@cased/kit";
129+
import { KitError } from "@runcased/kit";
100130

101131
try {
102132
const symbols = await repo.symbols("nonexistent.ts");
@@ -207,7 +237,7 @@ See `types.ts` for complete option interfaces including:
207237
### Analyze a Repository
208238

209239
```typescript
210-
import { Kit } from "@cased/kit";
240+
import { Kit } from "@runcased/kit";
211241

212242
async function analyzeRepo(repoPath: string) {
213243
const kit = new Kit();

clients/typescript/examples/analyze-repo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Kit } from "@cased/kit";
1+
import { Kit } from "@runcased/kit";
22

33
async function main() {
44
// Initialize Kit

clients/typescript/src/__tests__/integration.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ maybeDescribe("Kit TypeScript wrapper – integration", () => {
99
const repoRoot = path.resolve(__dirname, "../../../../");
1010

1111
// Build the TypeScript client (dist/) – quiet if already built
12-
execSync("npm run build", { cwd: path.join(repoRoot, "clients/typescript"), stdio: "inherit" });
12+
execSync("npm run build", {
13+
cwd: path.join(repoRoot, "clients/typescript"),
14+
stdio: "inherit",
15+
});
1316

1417
// Run the manual wrapper test script; will throw if non-zero exit
15-
execSync("node clients/typescript/test-wrapper.js", { cwd: repoRoot, stdio: "inherit" });
18+
execSync("node clients/typescript/test-wrapper.js", {
19+
cwd: repoRoot,
20+
stdio: "inherit",
21+
});
1622
}, 300_000); // allow up to 5 min in CI
17-
});
23+
});

clients/typescript/src/__tests__/kit.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { spawn } from "child_process";
2-
import { Kit, Repository } from "../kit";
3-
import { KitError } from "../types";
2+
import { Kit } from "../kit";
43
import fs from "fs";
54

65
// Mock child_process

clients/typescript/src/__tests__/repository.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ jest.mock("child_process");
66
const mockSpawn = spawn as jest.MockedFunction<typeof spawn>;
77

88
jest.mock("fs");
9-
const mockFs = fs as unknown as { readFileSync: jest.Mock; unlinkSync: jest.Mock };
9+
const mockFs = fs as unknown as {
10+
readFileSync: jest.Mock;
11+
unlinkSync: jest.Mock;
12+
};
1013

1114
// Helper to create mock child process
1215
function createMockProcess(
@@ -84,7 +87,7 @@ describe("Repository", () => {
8487
mockSpawn.mockReturnValue(createMockProcess("File tree written") as any);
8588
mockFs.readFileSync.mockReturnValue(mockOutput);
8689

87-
const files = await repo.fileTree();
90+
const _files = await repo.fileTree();
8891

8992
expect(mockSpawn).toHaveBeenCalledWith(
9093
"kit",
@@ -98,6 +101,7 @@ describe("Repository", () => {
98101
],
99102
expect.any(Object),
100103
);
104+
expect(_files.length).toBeGreaterThanOrEqual(0);
101105
});
102106
});
103107

clients/typescript/src/kit.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ import {
1515
DependenciesOptions,
1616
GitInfo,
1717
} from "./types";
18+
import os from "os";
19+
import path from "path";
20+
21+
class KitCommandError extends Error implements KitError {
22+
code: string;
23+
exitCode: number;
24+
stderr: string;
25+
constructor(message: string, exitCode: number, stderr: string) {
26+
super(message);
27+
this.name = "KitCommandError";
28+
this.code = "KIT_COMMAND_FAILED";
29+
this.exitCode = exitCode;
30+
this.stderr = stderr;
31+
}
32+
}
1833

1934
export class Kit {
2035
private options: Required<KitOptions>;
@@ -55,11 +70,13 @@ export class Kit {
5570
if (code === 0) {
5671
resolve(stdout);
5772
} else {
58-
const error = new Error(`Kit command failed: ${stderr}`) as KitError;
59-
error.code = "KIT_COMMAND_FAILED";
60-
error.exitCode = code || 1;
61-
error.stderr = stderr;
62-
reject(error);
73+
reject(
74+
new KitCommandError(
75+
`Kit command failed: ${stderr}`,
76+
code || 1,
77+
stderr,
78+
),
79+
);
6380
}
6481
});
6582

@@ -102,11 +119,11 @@ export class Kit {
102119
/**
103120
* Get file tree structure
104121
*/
105-
async fileTree(path: string = ".", ref?: string): Promise<FileNode[]> {
106-
const args = ["file-tree", path];
122+
async fileTree(repoPath: string = ".", ref?: string): Promise<FileNode[]> {
123+
const args = ["file-tree", repoPath];
107124

108125
// Create a temporary file for JSON output
109-
const tmpFile = `/tmp/kit-file-tree-${Date.now()}.json`;
126+
const tmpFile = path.join(os.tmpdir(), `kit-file-tree-${Date.now()}.json`);
110127

111128
args.push("--output", tmpFile);
112129
if (ref) args.push("--ref", ref);
@@ -116,14 +133,11 @@ export class Kit {
116133
// Read the JSON from the temp file
117134
const fs = require("fs");
118135
const jsonData = fs.readFileSync(tmpFile, "utf8");
119-
fs.unlinkSync(tmpFile); // Clean up
120136
return JSON.parse(jsonData);
121-
} catch (error) {
122-
// Clean up temp file on error
137+
} finally {
123138
try {
124139
require("fs").unlinkSync(tmpFile);
125140
} catch {}
126-
throw error;
127141
}
128142
}
129143

scripts/format-ts.sh

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

scripts/format.sh

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,42 @@ else
2121
# Ruff check combines linting and format checking
2222
ruff check .
2323
echo "Ruff checks passed successfully!"
24-
fi
24+
fi
25+
26+
# -----------------------------------------------------------------------------
27+
# TypeScript Client formatting, linting, and type-checking
28+
# -----------------------------------------------------------------------------
29+
30+
echo "----------------------------------------------"
31+
echo "TypeScript client checks (clients/typescript)"
32+
echo "----------------------------------------------"
33+
34+
# Navigate to TypeScript client directory
35+
pushd clients/typescript > /dev/null
36+
37+
# Install dependencies if node_modules missing
38+
if [ ! -d "node_modules" ]; then
39+
echo "Installing TypeScript client dependencies..."
40+
npm ci
41+
fi
42+
43+
# Run Prettier and ESLint
44+
if [ "$1" == "--fix" ]; then
45+
echo "Running Prettier (write)..."
46+
npm run format:fix
47+
echo "Running ESLint with --fix..."
48+
npm run lint -- --fix
49+
else
50+
echo "Running Prettier (check)..."
51+
npm run format
52+
echo "Running ESLint..."
53+
npm run lint
54+
fi
55+
56+
# TypeScript type check
57+
echo "Running TypeScript type check (tsc --noEmit)..."
58+
npm run typecheck
59+
60+
popd > /dev/null
61+
62+
echo "✅ All Python & TypeScript formatting and lint checks passed!"

0 commit comments

Comments
 (0)