prinfer 0.3.0 → 0.4.0

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 CHANGED
@@ -14,6 +14,9 @@ npm install prinfer
14
14
  # Basic usage
15
15
  prinfer src/utils.ts myFunction
16
16
 
17
+ # Find variable at specific line
18
+ prinfer src/utils.ts:75 commandResult
19
+
17
20
  # With custom tsconfig
18
21
  prinfer src/utils.ts myFunction --project ./tsconfig.json
19
22
 
@@ -40,24 +43,32 @@ console.log(result.signature);
40
43
  console.log(result.returnType);
41
44
  // => "boolean"
42
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
+
43
51
  // With custom tsconfig
44
- const result2 = inferType("./src/utils.ts", "myFunction", "./tsconfig.json");
52
+ const result3 = inferType("./src/utils.ts", "myFunction", { project: "./tsconfig.json" });
45
53
  ```
46
54
 
47
55
  ### API Reference
48
56
 
49
- #### `inferType(file, name, project?)`
57
+ #### `inferType(file, name, options?)`
50
58
 
51
59
  Infer the type of a function or variable in a TypeScript file.
52
60
 
53
61
  **Parameters:**
54
62
  - `file` - Path to the TypeScript file
55
63
  - `name` - Name of the function/variable to inspect
56
- - `project` - Optional path to tsconfig.json
64
+ - `options` - Optional object with:
65
+ - `line` - Line number to narrow search (1-based)
66
+ - `project` - Path to tsconfig.json
57
67
 
58
68
  **Returns:** `InferredTypeResult`
59
69
  - `signature` - The inferred type signature
60
70
  - `returnType` - The return type (for functions)
71
+ - `line` - The line number where the symbol was found
61
72
 
62
73
  #### Types
63
74
 
@@ -65,15 +76,64 @@ Infer the type of a function or variable in a TypeScript file.
65
76
  interface Options {
66
77
  file: string;
67
78
  name: string;
79
+ line?: number;
68
80
  project?: string;
69
81
  }
70
82
 
71
83
  interface InferredTypeResult {
72
84
  signature: string;
73
85
  returnType?: string;
86
+ line?: number;
74
87
  }
75
88
  ```
76
89
 
90
+ ## MCP Server (Claude Integration)
91
+
92
+ prinfer includes an MCP server for use with Claude Code or Claude Desktop.
93
+
94
+ ### Setup for Claude Code
95
+
96
+ Add to your `~/.claude/claude_desktop_config.json`:
97
+
98
+ ```json
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`):
110
+
111
+ ```json
112
+ {
113
+ "mcpServers": {
114
+ "prinfer": {
115
+ "command": "prinfer-mcp"
116
+ }
117
+ }
118
+ }
119
+ ```
120
+
121
+ ### Tool Usage
122
+
123
+ Once configured, Claude can use the `infer_type` tool:
124
+
125
+ ```
126
+ infer_type(file: "src/utils.ts", name: "myFunction")
127
+ infer_type(file: "src/utils.ts", name: "commandResult", line: 75)
128
+ ```
129
+
130
+ ### Auto-installed Skill
131
+
132
+ When you install prinfer globally (`npm i -g prinfer`), a Claude skill is automatically added to `~/.claude/skills/prinfer.md`. This provides:
133
+
134
+ 1. **Coding guideline** - Encourages Claude to prefer type inference over explicit annotations
135
+ 2. **`/check-type` command** - Check types directly: `/check-type src/utils.ts:75 commandResult`
136
+
77
137
  ## Requirements
78
138
 
79
139
  - Node.js >= 18.0.0
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/postinstall.ts
27
+ var import_node_fs = __toESM(require("fs"), 1);
28
+ var import_node_os = __toESM(require("os"), 1);
29
+ var import_node_path = __toESM(require("path"), 1);
30
+ var SKILL_CONTENT = `# TypeScript Type Inference (prinfer)
31
+
32
+ ## Coding Guideline
33
+
34
+ When writing TypeScript code, prefer relying on type inference over explicit type annotations:
35
+
36
+ - Let TypeScript infer return types for functions when the implementation makes them obvious
37
+ - Let TypeScript infer variable types from their initializers
38
+ - Only add explicit types when:
39
+ - The inferred type is too wide (e.g., \`string\` instead of a literal type)
40
+ - The type serves as documentation for complex structures
41
+ - You're defining a public API contract
42
+
43
+ Use the \`prinfer\` MCP tool (\`infer_type\`) to verify what TypeScript infers before adding explicit types.
44
+
45
+ ## Commands
46
+
47
+ ### /check-type
48
+
49
+ Check the inferred type of a TypeScript symbol.
50
+
51
+ Usage: \`/check-type <file>:<line> <name>\` or \`/check-type <file> <name>\`
52
+
53
+ Examples:
54
+ - \`/check-type src/utils.ts:75 commandResult\`
55
+ - \`/check-type src/utils.ts myFunction\`
56
+
57
+ <command-name>check-type</command-name>
58
+
59
+ Use the \`infer_type\` MCP tool to check the type:
60
+ 1. Parse the arguments to extract file, optional line number, and symbol name
61
+ 2. Call \`infer_type(file, name, line?)\`
62
+ 3. Report the inferred signature and return type
63
+ `;
64
+ function main() {
65
+ const homeDir = import_node_os.default.homedir();
66
+ const skillsDir = import_node_path.default.join(homeDir, ".claude", "skills");
67
+ const skillFile = import_node_path.default.join(skillsDir, "prinfer.md");
68
+ const claudeDir = import_node_path.default.join(homeDir, ".claude");
69
+ if (!import_node_fs.default.existsSync(claudeDir)) {
70
+ console.log(
71
+ "~/.claude directory not found. Skipping skill installation."
72
+ );
73
+ console.log("To manually install, create ~/.claude/skills/prinfer.md");
74
+ return;
75
+ }
76
+ if (!import_node_fs.default.existsSync(skillsDir)) {
77
+ import_node_fs.default.mkdirSync(skillsDir, { recursive: true });
78
+ }
79
+ if (import_node_fs.default.existsSync(skillFile)) {
80
+ console.log(
81
+ "prinfer skill already installed at ~/.claude/skills/prinfer.md"
82
+ );
83
+ return;
84
+ }
85
+ import_node_fs.default.writeFileSync(skillFile, SKILL_CONTENT);
86
+ console.log("Installed prinfer skill to ~/.claude/skills/prinfer.md");
87
+ console.log("You can now use /check-type to verify TypeScript types!");
88
+ }
89
+ main();
90
+ //# sourceMappingURL=postinstall.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/postinstall.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nconst SKILL_CONTENT = `# TypeScript Type Inference (prinfer)\n\n## Coding Guideline\n\nWhen writing TypeScript code, prefer relying on type inference over explicit type annotations:\n\n- Let TypeScript infer return types for functions when the implementation makes them obvious\n- Let TypeScript infer variable types from their initializers\n- Only add explicit types when:\n - The inferred type is too wide (e.g., \\`string\\` instead of a literal type)\n - The type serves as documentation for complex structures\n - You're defining a public API contract\n\nUse the \\`prinfer\\` MCP tool (\\`infer_type\\`) to verify what TypeScript infers before adding explicit types.\n\n## Commands\n\n### /check-type\n\nCheck the inferred type of a TypeScript symbol.\n\nUsage: \\`/check-type <file>:<line> <name>\\` or \\`/check-type <file> <name>\\`\n\nExamples:\n- \\`/check-type src/utils.ts:75 commandResult\\`\n- \\`/check-type src/utils.ts myFunction\\`\n\n<command-name>check-type</command-name>\n\nUse the \\`infer_type\\` MCP tool to check the type:\n1. Parse the arguments to extract file, optional line number, and symbol name\n2. Call \\`infer_type(file, name, line?)\\`\n3. Report the inferred signature and return type\n`;\n\nfunction main() {\n\tconst homeDir = os.homedir();\n\tconst skillsDir = path.join(homeDir, \".claude\", \"skills\");\n\tconst skillFile = path.join(skillsDir, \"prinfer.md\");\n\n\t// Check if ~/.claude exists\n\tconst claudeDir = path.join(homeDir, \".claude\");\n\tif (!fs.existsSync(claudeDir)) {\n\t\tconsole.log(\n\t\t\t\"~/.claude directory not found. Skipping skill installation.\",\n\t\t);\n\t\tconsole.log(\"To manually install, create ~/.claude/skills/prinfer.md\");\n\t\treturn;\n\t}\n\n\t// Create skills directory if it doesn't exist\n\tif (!fs.existsSync(skillsDir)) {\n\t\tfs.mkdirSync(skillsDir, { recursive: true });\n\t}\n\n\t// Check if skill already exists\n\tif (fs.existsSync(skillFile)) {\n\t\tconsole.log(\n\t\t\t\"prinfer skill already installed at ~/.claude/skills/prinfer.md\",\n\t\t);\n\t\treturn;\n\t}\n\n\t// Write the skill file\n\tfs.writeFileSync(skillFile, SKILL_CONTENT);\n\tconsole.log(\"Installed prinfer skill to ~/.claude/skills/prinfer.md\");\n\tconsole.log(\"You can now use /check-type to verify TypeScript types!\");\n}\n\nmain();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qBAAe;AACf,qBAAe;AACf,uBAAiB;AAEjB,IAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCtB,SAAS,OAAO;AACf,QAAM,UAAU,eAAAA,QAAG,QAAQ;AAC3B,QAAM,YAAY,iBAAAC,QAAK,KAAK,SAAS,WAAW,QAAQ;AACxD,QAAM,YAAY,iBAAAA,QAAK,KAAK,WAAW,YAAY;AAGnD,QAAM,YAAY,iBAAAA,QAAK,KAAK,SAAS,SAAS;AAC9C,MAAI,CAAC,eAAAC,QAAG,WAAW,SAAS,GAAG;AAC9B,YAAQ;AAAA,MACP;AAAA,IACD;AACA,YAAQ,IAAI,yDAAyD;AACrE;AAAA,EACD;AAGA,MAAI,CAAC,eAAAA,QAAG,WAAW,SAAS,GAAG;AAC9B,mBAAAA,QAAG,UAAU,WAAW,EAAE,WAAW,KAAK,CAAC;AAAA,EAC5C;AAGA,MAAI,eAAAA,QAAG,WAAW,SAAS,GAAG;AAC7B,YAAQ;AAAA,MACP;AAAA,IACD;AACA;AAAA,EACD;AAGA,iBAAAA,QAAG,cAAc,WAAW,aAAa;AACzC,UAAQ,IAAI,wDAAwD;AACpE,UAAQ,IAAI,yDAAyD;AACtE;AAEA,KAAK;","names":["os","path","fs"]}
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/postinstall.ts
4
+ import fs from "fs";
5
+ import os from "os";
6
+ import path from "path";
7
+ var SKILL_CONTENT = `# TypeScript Type Inference (prinfer)
8
+
9
+ ## Coding Guideline
10
+
11
+ When writing TypeScript code, prefer relying on type inference over explicit type annotations:
12
+
13
+ - Let TypeScript infer return types for functions when the implementation makes them obvious
14
+ - Let TypeScript infer variable types from their initializers
15
+ - Only add explicit types when:
16
+ - The inferred type is too wide (e.g., \`string\` instead of a literal type)
17
+ - The type serves as documentation for complex structures
18
+ - You're defining a public API contract
19
+
20
+ Use the \`prinfer\` MCP tool (\`infer_type\`) to verify what TypeScript infers before adding explicit types.
21
+
22
+ ## Commands
23
+
24
+ ### /check-type
25
+
26
+ Check the inferred type of a TypeScript symbol.
27
+
28
+ Usage: \`/check-type <file>:<line> <name>\` or \`/check-type <file> <name>\`
29
+
30
+ Examples:
31
+ - \`/check-type src/utils.ts:75 commandResult\`
32
+ - \`/check-type src/utils.ts myFunction\`
33
+
34
+ <command-name>check-type</command-name>
35
+
36
+ Use the \`infer_type\` MCP tool to check the type:
37
+ 1. Parse the arguments to extract file, optional line number, and symbol name
38
+ 2. Call \`infer_type(file, name, line?)\`
39
+ 3. Report the inferred signature and return type
40
+ `;
41
+ function main() {
42
+ const homeDir = os.homedir();
43
+ const skillsDir = path.join(homeDir, ".claude", "skills");
44
+ const skillFile = path.join(skillsDir, "prinfer.md");
45
+ const claudeDir = path.join(homeDir, ".claude");
46
+ if (!fs.existsSync(claudeDir)) {
47
+ console.log(
48
+ "~/.claude directory not found. Skipping skill installation."
49
+ );
50
+ console.log("To manually install, create ~/.claude/skills/prinfer.md");
51
+ return;
52
+ }
53
+ if (!fs.existsSync(skillsDir)) {
54
+ fs.mkdirSync(skillsDir, { recursive: true });
55
+ }
56
+ if (fs.existsSync(skillFile)) {
57
+ console.log(
58
+ "prinfer skill already installed at ~/.claude/skills/prinfer.md"
59
+ );
60
+ return;
61
+ }
62
+ fs.writeFileSync(skillFile, SKILL_CONTENT);
63
+ console.log("Installed prinfer skill to ~/.claude/skills/prinfer.md");
64
+ console.log("You can now use /check-type to verify TypeScript types!");
65
+ }
66
+ main();
67
+ //# sourceMappingURL=postinstall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/postinstall.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nconst SKILL_CONTENT = `# TypeScript Type Inference (prinfer)\n\n## Coding Guideline\n\nWhen writing TypeScript code, prefer relying on type inference over explicit type annotations:\n\n- Let TypeScript infer return types for functions when the implementation makes them obvious\n- Let TypeScript infer variable types from their initializers\n- Only add explicit types when:\n - The inferred type is too wide (e.g., \\`string\\` instead of a literal type)\n - The type serves as documentation for complex structures\n - You're defining a public API contract\n\nUse the \\`prinfer\\` MCP tool (\\`infer_type\\`) to verify what TypeScript infers before adding explicit types.\n\n## Commands\n\n### /check-type\n\nCheck the inferred type of a TypeScript symbol.\n\nUsage: \\`/check-type <file>:<line> <name>\\` or \\`/check-type <file> <name>\\`\n\nExamples:\n- \\`/check-type src/utils.ts:75 commandResult\\`\n- \\`/check-type src/utils.ts myFunction\\`\n\n<command-name>check-type</command-name>\n\nUse the \\`infer_type\\` MCP tool to check the type:\n1. Parse the arguments to extract file, optional line number, and symbol name\n2. Call \\`infer_type(file, name, line?)\\`\n3. Report the inferred signature and return type\n`;\n\nfunction main() {\n\tconst homeDir = os.homedir();\n\tconst skillsDir = path.join(homeDir, \".claude\", \"skills\");\n\tconst skillFile = path.join(skillsDir, \"prinfer.md\");\n\n\t// Check if ~/.claude exists\n\tconst claudeDir = path.join(homeDir, \".claude\");\n\tif (!fs.existsSync(claudeDir)) {\n\t\tconsole.log(\n\t\t\t\"~/.claude directory not found. Skipping skill installation.\",\n\t\t);\n\t\tconsole.log(\"To manually install, create ~/.claude/skills/prinfer.md\");\n\t\treturn;\n\t}\n\n\t// Create skills directory if it doesn't exist\n\tif (!fs.existsSync(skillsDir)) {\n\t\tfs.mkdirSync(skillsDir, { recursive: true });\n\t}\n\n\t// Check if skill already exists\n\tif (fs.existsSync(skillFile)) {\n\t\tconsole.log(\n\t\t\t\"prinfer skill already installed at ~/.claude/skills/prinfer.md\",\n\t\t);\n\t\treturn;\n\t}\n\n\t// Write the skill file\n\tfs.writeFileSync(skillFile, SKILL_CONTENT);\n\tconsole.log(\"Installed prinfer skill to ~/.claude/skills/prinfer.md\");\n\tconsole.log(\"You can now use /check-type to verify TypeScript types!\");\n}\n\nmain();\n"],"mappings":";;;AACA,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,IAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCtB,SAAS,OAAO;AACf,QAAM,UAAU,GAAG,QAAQ;AAC3B,QAAM,YAAY,KAAK,KAAK,SAAS,WAAW,QAAQ;AACxD,QAAM,YAAY,KAAK,KAAK,WAAW,YAAY;AAGnD,QAAM,YAAY,KAAK,KAAK,SAAS,SAAS;AAC9C,MAAI,CAAC,GAAG,WAAW,SAAS,GAAG;AAC9B,YAAQ;AAAA,MACP;AAAA,IACD;AACA,YAAQ,IAAI,yDAAyD;AACrE;AAAA,EACD;AAGA,MAAI,CAAC,GAAG,WAAW,SAAS,GAAG;AAC9B,OAAG,UAAU,WAAW,EAAE,WAAW,KAAK,CAAC;AAAA,EAC5C;AAGA,MAAI,GAAG,WAAW,SAAS,GAAG;AAC7B,YAAQ;AAAA,MACP;AAAA,IACD;AACA;AAAA,EACD;AAGA,KAAG,cAAc,WAAW,aAAa;AACzC,UAAQ,IAAI,wDAAwD;AACpE,UAAQ,IAAI,yDAAyD;AACtE;AAEA,KAAK;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prinfer",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "TypeScript type inference inspection tool",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -33,7 +33,8 @@
33
33
  "version": "changeset version",
34
34
  "release": "bun run build && changeset publish",
35
35
  "prepublishOnly": "bun run ci",
36
- "prepare": "simple-git-hooks"
36
+ "prepare": "simple-git-hooks",
37
+ "postinstall": "node ./dist/postinstall.js || true"
37
38
  },
38
39
  "simple-git-hooks": {
39
40
  "pre-commit": "bunx biome check ."