prinfer 0.4.0 → 0.4.1
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 +46 -96
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,112 +1,51 @@
|
|
|
1
1
|
# prinfer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Typehints for your AI agent.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
prinfer gives AI coding assistants the ability to inspect TypeScript's inferred types — so they can write cleaner code without redundant type annotations.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
npm install prinfer
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## CLI Usage
|
|
7
|
+
## Why?
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
AI agents write TypeScript, but they can't see what the compiler infers. This leads to:
|
|
10
|
+
- Unnecessary explicit type annotations everywhere
|
|
11
|
+
- Verbose code that fights against TypeScript's design
|
|
12
|
+
- Missed opportunities to leverage type inference
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
prinfer src/utils.ts:75 commandResult
|
|
14
|
+
prinfer solves this by exposing TypeScript's type inference to your agent via MCP.
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
prinfer src/utils.ts myFunction --project ./tsconfig.json
|
|
16
|
+
## Quick Start
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
prinfer
|
|
18
|
+
```bash
|
|
19
|
+
npm i -g prinfer
|
|
25
20
|
```
|
|
26
21
|
|
|
27
|
-
|
|
22
|
+
That's it. On install, prinfer automatically:
|
|
23
|
+
1. Adds itself as an MCP tool for Claude
|
|
24
|
+
2. Installs a skill that teaches Claude to prefer type inference
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
(x: number, y: string) => boolean
|
|
31
|
-
returns: boolean
|
|
32
|
-
```
|
|
26
|
+
## What Gets Installed
|
|
33
27
|
|
|
34
|
-
|
|
28
|
+
### MCP Server (`prinfer-mcp`)
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
import { inferType } from "prinfer";
|
|
30
|
+
Your agent gets an `infer_type` tool to check what TypeScript infers:
|
|
38
31
|
|
|
39
|
-
// Basic usage
|
|
40
|
-
const result = inferType("./src/utils.ts", "myFunction");
|
|
41
|
-
console.log(result.signature);
|
|
42
|
-
// => "(x: number, y: string) => boolean"
|
|
43
|
-
console.log(result.returnType);
|
|
44
|
-
// => "boolean"
|
|
45
|
-
|
|
46
|
-
// Find variable at specific line
|
|
47
|
-
const result2 = inferType("./src/utils.ts", "commandResult", { line: 75 });
|
|
48
|
-
console.log(result2.signature);
|
|
49
|
-
// => "Result<VaultAction[], CommandError>"
|
|
50
|
-
|
|
51
|
-
// With custom tsconfig
|
|
52
|
-
const result3 = inferType("./src/utils.ts", "myFunction", { project: "./tsconfig.json" });
|
|
53
32
|
```
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
#### `inferType(file, name, options?)`
|
|
58
|
-
|
|
59
|
-
Infer the type of a function or variable in a TypeScript file.
|
|
60
|
-
|
|
61
|
-
**Parameters:**
|
|
62
|
-
- `file` - Path to the TypeScript file
|
|
63
|
-
- `name` - Name of the function/variable to inspect
|
|
64
|
-
- `options` - Optional object with:
|
|
65
|
-
- `line` - Line number to narrow search (1-based)
|
|
66
|
-
- `project` - Path to tsconfig.json
|
|
67
|
-
|
|
68
|
-
**Returns:** `InferredTypeResult`
|
|
69
|
-
- `signature` - The inferred type signature
|
|
70
|
-
- `returnType` - The return type (for functions)
|
|
71
|
-
- `line` - The line number where the symbol was found
|
|
72
|
-
|
|
73
|
-
#### Types
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
interface Options {
|
|
77
|
-
file: string;
|
|
78
|
-
name: string;
|
|
79
|
-
line?: number;
|
|
80
|
-
project?: string;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
interface InferredTypeResult {
|
|
84
|
-
signature: string;
|
|
85
|
-
returnType?: string;
|
|
86
|
-
line?: number;
|
|
87
|
-
}
|
|
33
|
+
infer_type(file: "src/utils.ts", name: "myFunction")
|
|
34
|
+
infer_type(file: "src/utils.ts", name: "commandResult", line: 75)
|
|
88
35
|
```
|
|
89
36
|
|
|
90
|
-
|
|
37
|
+
### Claude Skill (`~/.claude/skills/prinfer.md`)
|
|
91
38
|
|
|
92
|
-
|
|
39
|
+
A coding guideline that encourages your agent to:
|
|
40
|
+
- Rely on type inference instead of explicit annotations
|
|
41
|
+
- Use prinfer to verify types before adding redundant hints
|
|
42
|
+
- Write idiomatic TypeScript
|
|
93
43
|
|
|
94
|
-
|
|
44
|
+
Plus a `/check-type` command for quick lookups.
|
|
95
45
|
|
|
96
|
-
|
|
46
|
+
## MCP Setup
|
|
97
47
|
|
|
98
|
-
|
|
99
|
-
{
|
|
100
|
-
"mcpServers": {
|
|
101
|
-
"prinfer": {
|
|
102
|
-
"command": "npx",
|
|
103
|
-
"args": ["prinfer-mcp"]
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
Or if installed globally (`npm i -g prinfer`):
|
|
48
|
+
If the auto-setup didn't work, add to `~/.claude/claude_desktop_config.json`:
|
|
110
49
|
|
|
111
50
|
```json
|
|
112
51
|
{
|
|
@@ -118,21 +57,32 @@ Or if installed globally (`npm i -g prinfer`):
|
|
|
118
57
|
}
|
|
119
58
|
```
|
|
120
59
|
|
|
121
|
-
|
|
60
|
+
## CLI Usage
|
|
122
61
|
|
|
123
|
-
|
|
62
|
+
prinfer also works as a standalone CLI:
|
|
124
63
|
|
|
64
|
+
```bash
|
|
65
|
+
prinfer src/utils.ts myFunction
|
|
66
|
+
prinfer src/utils.ts:75 commandResult
|
|
125
67
|
```
|
|
126
|
-
|
|
127
|
-
|
|
68
|
+
|
|
69
|
+
Output:
|
|
70
|
+
```
|
|
71
|
+
(x: number, y: string) => boolean
|
|
72
|
+
returns: boolean
|
|
128
73
|
```
|
|
129
74
|
|
|
130
|
-
|
|
75
|
+
## Programmatic API
|
|
131
76
|
|
|
132
|
-
|
|
77
|
+
```typescript
|
|
78
|
+
import { inferType } from "prinfer";
|
|
133
79
|
|
|
134
|
-
|
|
135
|
-
|
|
80
|
+
const result = inferType("./src/utils.ts", "myFunction");
|
|
81
|
+
// => { signature: "(x: number, y: string) => boolean", returnType: "boolean", line: 4 }
|
|
82
|
+
|
|
83
|
+
// With line number for disambiguation
|
|
84
|
+
const result2 = inferType("./src/utils.ts", "commandResult", { line: 75 });
|
|
85
|
+
```
|
|
136
86
|
|
|
137
87
|
## Requirements
|
|
138
88
|
|