@llmtune/cli 0.1.0 → 0.1.2

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.
Files changed (198) hide show
  1. package/README.md +1 -1
  2. package/dist/agent/conversation.d.ts +42 -0
  3. package/dist/agent/conversation.js +105 -0
  4. package/dist/agent/loop.d.ts +19 -0
  5. package/dist/agent/loop.js +185 -0
  6. package/dist/agent/planner.d.ts +8 -0
  7. package/dist/agent/planner.js +43 -0
  8. package/dist/auth/client.d.ts +4 -0
  9. package/dist/auth/client.js +24 -0
  10. package/dist/auth/config.d.ts +21 -0
  11. package/dist/auth/config.js +83 -0
  12. package/dist/commands/chat.d.ts +5 -0
  13. package/dist/commands/chat.js +27 -0
  14. package/dist/commands/config.d.ts +2 -0
  15. package/dist/commands/config.js +37 -0
  16. package/dist/commands/login.d.ts +2 -0
  17. package/dist/commands/login.js +93 -0
  18. package/dist/commands/marketplace.d.ts +6 -0
  19. package/dist/commands/marketplace.js +213 -0
  20. package/dist/commands/models.d.ts +2 -0
  21. package/dist/commands/models.js +53 -0
  22. package/dist/compact/history-store.d.ts +29 -0
  23. package/dist/compact/history-store.js +110 -0
  24. package/dist/compact/microcompact.d.ts +10 -0
  25. package/dist/compact/microcompact.js +43 -0
  26. package/dist/compact/service.d.ts +13 -0
  27. package/dist/compact/service.js +156 -0
  28. package/dist/context/analyzer.d.ts +26 -0
  29. package/dist/context/analyzer.js +99 -0
  30. package/dist/context/builder.d.ts +13 -0
  31. package/dist/context/builder.js +144 -0
  32. package/dist/context/cache.d.ts +6 -0
  33. package/dist/context/cache.js +8 -0
  34. package/dist/context/git-context.d.ts +9 -0
  35. package/dist/context/git-context.js +39 -0
  36. package/dist/context/llmtune-md.d.ts +6 -0
  37. package/dist/context/llmtune-md.js +73 -0
  38. package/dist/context/workspace.d.ts +11 -0
  39. package/dist/context/workspace.js +115 -0
  40. package/dist/index.d.ts +3 -0
  41. package/dist/index.js +3 -2
  42. package/dist/marketplace/client.d.ts +52 -0
  43. package/dist/marketplace/client.js +86 -0
  44. package/dist/memory/files.d.ts +14 -0
  45. package/dist/memory/files.js +116 -0
  46. package/dist/memory/service.d.ts +22 -0
  47. package/dist/memory/service.js +146 -0
  48. package/dist/repl/repl.d.ts +8 -0
  49. package/dist/repl/repl.js +375 -0
  50. package/dist/skills/args.d.ts +10 -0
  51. package/dist/skills/args.js +37 -0
  52. package/dist/skills/frontmatter.d.ts +6 -0
  53. package/dist/skills/frontmatter.js +44 -0
  54. package/dist/skills/loader.d.ts +5 -0
  55. package/dist/skills/loader.js +59 -0
  56. package/dist/skills/registry.d.ts +27 -0
  57. package/dist/skills/registry.js +162 -0
  58. package/dist/skills/signing/signer.d.ts +19 -0
  59. package/dist/skills/signing/signer.js +110 -0
  60. package/dist/skills/trust.d.ts +11 -0
  61. package/dist/skills/trust.js +42 -0
  62. package/dist/telemetry/logger.d.ts +51 -0
  63. package/dist/telemetry/logger.js +135 -0
  64. package/dist/tools/permissions.d.ts +20 -0
  65. package/dist/tools/permissions.js +58 -0
  66. package/dist/tools/protocol.d.ts +22 -0
  67. package/dist/tools/protocol.js +3 -0
  68. package/dist/tools/registry.d.ts +20 -0
  69. package/dist/tools/registry.js +77 -0
  70. package/dist/tools/sandbox/docker.d.ts +16 -0
  71. package/dist/tools/sandbox/docker.js +240 -0
  72. package/dist/tools/sandbox/index.d.ts +18 -0
  73. package/dist/tools/sandbox/index.js +80 -0
  74. package/dist/tools/tools/ask-user.d.ts +3 -0
  75. package/dist/tools/tools/ask-user.js +56 -0
  76. package/dist/tools/tools/bash.d.ts +3 -0
  77. package/dist/tools/tools/bash.js +85 -0
  78. package/dist/tools/tools/edit.d.ts +3 -0
  79. package/dist/tools/tools/edit.js +138 -0
  80. package/dist/tools/tools/glob.d.ts +3 -0
  81. package/dist/tools/tools/glob.js +63 -0
  82. package/dist/tools/tools/grep.d.ts +3 -0
  83. package/dist/tools/tools/grep.js +148 -0
  84. package/dist/tools/tools/read.d.ts +3 -0
  85. package/dist/tools/tools/read.js +85 -0
  86. package/dist/tools/tools/web-fetch.d.ts +3 -0
  87. package/dist/tools/tools/web-fetch.js +143 -0
  88. package/dist/tools/tools/write.d.ts +3 -0
  89. package/dist/tools/tools/write.js +84 -0
  90. package/dist/tools/validation.d.ts +13 -0
  91. package/dist/tools/validation.js +142 -0
  92. package/dist/utils/markdown.d.ts +9 -0
  93. package/dist/utils/markdown.js +89 -0
  94. package/dist/utils/streaming.d.ts +10 -0
  95. package/dist/utils/streaming.js +63 -0
  96. package/dist/utils/tokens.d.ts +12 -0
  97. package/dist/utils/tokens.js +44 -0
  98. package/dist/version.d.ts +2 -0
  99. package/dist/version.js +9 -0
  100. package/package.json +2 -2
  101. package/dist/agent/conversation.d.ts.map +0 -1
  102. package/dist/agent/loop.d.ts.map +0 -1
  103. package/dist/agent/planner.d.ts.map +0 -1
  104. package/dist/auth/client.d.ts.map +0 -1
  105. package/dist/auth/config.d.ts.map +0 -1
  106. package/dist/commands/chat.d.ts.map +0 -1
  107. package/dist/commands/config.d.ts.map +0 -1
  108. package/dist/commands/login.d.ts.map +0 -1
  109. package/dist/commands/marketplace.d.ts.map +0 -1
  110. package/dist/commands/models.d.ts.map +0 -1
  111. package/dist/compact/history-store.d.ts.map +0 -1
  112. package/dist/compact/microcompact.d.ts.map +0 -1
  113. package/dist/compact/service.d.ts.map +0 -1
  114. package/dist/context/analyzer.d.ts.map +0 -1
  115. package/dist/context/builder.d.ts.map +0 -1
  116. package/dist/context/cache.d.ts.map +0 -1
  117. package/dist/context/git-context.d.ts.map +0 -1
  118. package/dist/context/llmtune-md.d.ts.map +0 -1
  119. package/dist/context/workspace.d.ts.map +0 -1
  120. package/dist/index.d.ts.map +0 -1
  121. package/dist/marketplace/client.d.ts.map +0 -1
  122. package/dist/memory/files.d.ts.map +0 -1
  123. package/dist/memory/service.d.ts.map +0 -1
  124. package/dist/repl/repl.d.ts.map +0 -1
  125. package/dist/skills/args.d.ts.map +0 -1
  126. package/dist/skills/frontmatter.d.ts.map +0 -1
  127. package/dist/skills/loader.d.ts.map +0 -1
  128. package/dist/skills/registry.d.ts.map +0 -1
  129. package/dist/skills/signing/signer.d.ts.map +0 -1
  130. package/dist/skills/trust.d.ts.map +0 -1
  131. package/dist/telemetry/logger.d.ts.map +0 -1
  132. package/dist/tools/permissions.d.ts.map +0 -1
  133. package/dist/tools/protocol.d.ts.map +0 -1
  134. package/dist/tools/registry.d.ts.map +0 -1
  135. package/dist/tools/sandbox/docker.d.ts.map +0 -1
  136. package/dist/tools/sandbox/index.d.ts.map +0 -1
  137. package/dist/tools/tools/ask-user.d.ts.map +0 -1
  138. package/dist/tools/tools/bash.d.ts.map +0 -1
  139. package/dist/tools/tools/edit.d.ts.map +0 -1
  140. package/dist/tools/tools/glob.d.ts.map +0 -1
  141. package/dist/tools/tools/grep.d.ts.map +0 -1
  142. package/dist/tools/tools/read.d.ts.map +0 -1
  143. package/dist/tools/tools/web-fetch.d.ts.map +0 -1
  144. package/dist/tools/tools/write.d.ts.map +0 -1
  145. package/dist/tools/validation.d.ts.map +0 -1
  146. package/dist/utils/markdown.d.ts.map +0 -1
  147. package/dist/utils/streaming.d.ts.map +0 -1
  148. package/dist/utils/tokens.d.ts.map +0 -1
  149. package/src/agent/conversation.ts +0 -140
  150. package/src/agent/loop.ts +0 -215
  151. package/src/agent/planner.ts +0 -55
  152. package/src/auth/client.ts +0 -19
  153. package/src/auth/config.ts +0 -89
  154. package/src/commands/chat.ts +0 -28
  155. package/src/commands/config.ts +0 -36
  156. package/src/commands/login.ts +0 -63
  157. package/src/commands/marketplace.ts +0 -190
  158. package/src/commands/models.ts +0 -74
  159. package/src/compact/history-store.ts +0 -101
  160. package/src/compact/microcompact.ts +0 -49
  161. package/src/compact/service.ts +0 -154
  162. package/src/context/analyzer.ts +0 -127
  163. package/src/context/builder.ts +0 -123
  164. package/src/context/cache.ts +0 -11
  165. package/src/context/git-context.ts +0 -58
  166. package/src/context/llmtune-md.ts +0 -48
  167. package/src/context/workspace.ts +0 -139
  168. package/src/index.ts +0 -100
  169. package/src/marketplace/client.ts +0 -118
  170. package/src/memory/files.ts +0 -81
  171. package/src/memory/service.ts +0 -124
  172. package/src/repl/repl.ts +0 -400
  173. package/src/skills/args.ts +0 -35
  174. package/src/skills/builtin/explain-code/SKILL.md +0 -30
  175. package/src/skills/frontmatter.ts +0 -47
  176. package/src/skills/loader.ts +0 -25
  177. package/src/skills/registry.ts +0 -155
  178. package/src/skills/signing/signer.ts +0 -101
  179. package/src/skills/trust.ts +0 -50
  180. package/src/telemetry/logger.ts +0 -108
  181. package/src/tools/permissions.ts +0 -83
  182. package/src/tools/protocol.ts +0 -24
  183. package/src/tools/registry.ts +0 -93
  184. package/src/tools/sandbox/docker.ts +0 -225
  185. package/src/tools/sandbox/index.ts +0 -91
  186. package/src/tools/tools/ask-user.ts +0 -60
  187. package/src/tools/tools/bash.ts +0 -97
  188. package/src/tools/tools/edit.ts +0 -111
  189. package/src/tools/tools/glob.ts +0 -68
  190. package/src/tools/tools/grep.ts +0 -121
  191. package/src/tools/tools/read.ts +0 -57
  192. package/src/tools/tools/web-fetch.ts +0 -158
  193. package/src/tools/tools/write.ts +0 -52
  194. package/src/tools/validation.ts +0 -164
  195. package/src/utils/markdown.ts +0 -96
  196. package/src/utils/streaming.ts +0 -63
  197. package/src/utils/tokens.ts +0 -41
  198. package/tsconfig.json +0 -20
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.editTool = void 0;
37
+ const fs = __importStar(require("fs/promises"));
38
+ const path = __importStar(require("path"));
39
+ exports.editTool = {
40
+ spec() {
41
+ return {
42
+ name: "edit",
43
+ description: "Edit a file by replacing old text with new text. Supports replacing all occurrences.",
44
+ inputSchema: {
45
+ type: "object",
46
+ properties: {
47
+ file_path: {
48
+ type: "string",
49
+ description: "Path to the file to edit",
50
+ },
51
+ old_string: {
52
+ type: "string",
53
+ description: "The text to find and replace",
54
+ },
55
+ new_string: {
56
+ type: "string",
57
+ description: "The replacement text",
58
+ },
59
+ replace_all: {
60
+ type: "boolean",
61
+ description: "Replace all occurrences (default: false)",
62
+ },
63
+ },
64
+ required: ["file_path", "old_string", "new_string"],
65
+ },
66
+ isReadOnly: false,
67
+ isDestructive: true,
68
+ };
69
+ },
70
+ async run(input, ctx) {
71
+ const filePath = String(input.file_path ?? "");
72
+ const oldString = String(input.old_string ?? "");
73
+ const newString = String(input.new_string ?? "");
74
+ const replaceAll = Boolean(input.replace_all);
75
+ if (!filePath) {
76
+ return { name: "edit", output: { error: "file_path is required" }, isError: true };
77
+ }
78
+ if (!oldString) {
79
+ return { name: "edit", output: { error: "old_string is required" }, isError: true };
80
+ }
81
+ const resolved = path.resolve(ctx.cwd, filePath);
82
+ let content;
83
+ try {
84
+ content = await fs.readFile(resolved, "utf-8");
85
+ }
86
+ catch (err) {
87
+ return {
88
+ name: "edit",
89
+ output: { error: `Failed to read file: ${err.message}` },
90
+ isError: true,
91
+ };
92
+ }
93
+ if (!content.includes(oldString)) {
94
+ return {
95
+ name: "edit",
96
+ output: {
97
+ error: `old_string not found in ${filePath}`,
98
+ hint: "Make sure the old_string matches exactly, including whitespace.",
99
+ },
100
+ isError: true,
101
+ };
102
+ }
103
+ const occurrences = content.split(oldString).length - 1;
104
+ if (occurrences > 1 && !replaceAll) {
105
+ return {
106
+ name: "edit",
107
+ output: {
108
+ error: `Found ${occurrences} occurrences. Use replace_all: true or provide more specific old_string.`,
109
+ occurrences,
110
+ },
111
+ isError: true,
112
+ };
113
+ }
114
+ const newContent = replaceAll
115
+ ? content.split(oldString).join(newString)
116
+ : content.replace(oldString, newString);
117
+ try {
118
+ await fs.writeFile(resolved, newContent, "utf-8");
119
+ }
120
+ catch (err) {
121
+ return {
122
+ name: "edit",
123
+ output: { error: `Failed to write file: ${err.message}` },
124
+ isError: true,
125
+ };
126
+ }
127
+ return {
128
+ name: "edit",
129
+ output: {
130
+ file_path: filePath,
131
+ replacements: replaceAll ? occurrences : 1,
132
+ status: "edited",
133
+ },
134
+ isError: false,
135
+ };
136
+ },
137
+ };
138
+ //# sourceMappingURL=edit.js.map
@@ -0,0 +1,3 @@
1
+ import type { Tool } from "../protocol";
2
+ export declare const globTool: Tool;
3
+ //# sourceMappingURL=glob.d.ts.map
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.globTool = void 0;
4
+ const glob_1 = require("glob");
5
+ exports.globTool = {
6
+ spec() {
7
+ return {
8
+ name: "glob",
9
+ description: "Search for files matching a glob pattern. Returns matching file paths relative to the workspace root.",
10
+ inputSchema: {
11
+ type: "object",
12
+ properties: {
13
+ pattern: {
14
+ type: "string",
15
+ description: "Glob pattern (e.g. '**/*.ts', 'src/**/*.py')",
16
+ },
17
+ path: {
18
+ type: "string",
19
+ description: "Base directory for the search (default: workspace root)",
20
+ },
21
+ },
22
+ required: ["pattern"],
23
+ },
24
+ isReadOnly: true,
25
+ };
26
+ },
27
+ async run(input, ctx) {
28
+ const pattern = String(input.pattern ?? "");
29
+ const baseDir = String(input.path ?? ctx.workspaceRoot);
30
+ if (!pattern) {
31
+ return { name: "glob", output: { error: "pattern is required" }, isError: true };
32
+ }
33
+ try {
34
+ const matches = await (0, glob_1.glob)(pattern, {
35
+ cwd: baseDir,
36
+ nodir: true,
37
+ absolute: false,
38
+ ignore: ["**/node_modules/**", "**/.git/**", "**/dist/**", "**/.next/**"],
39
+ });
40
+ const truncated = matches.length > 500;
41
+ const limited = truncated ? matches.slice(0, 500) : matches;
42
+ return {
43
+ name: "glob",
44
+ output: {
45
+ pattern,
46
+ baseDir,
47
+ matches: limited,
48
+ numFiles: matches.length,
49
+ truncated,
50
+ },
51
+ isError: false,
52
+ };
53
+ }
54
+ catch (err) {
55
+ return {
56
+ name: "glob",
57
+ output: { error: String(err.message ?? err) },
58
+ isError: true,
59
+ };
60
+ }
61
+ },
62
+ };
63
+ //# sourceMappingURL=glob.js.map
@@ -0,0 +1,3 @@
1
+ import type { Tool } from "../protocol";
2
+ export declare const grepTool: Tool;
3
+ //# sourceMappingURL=grep.d.ts.map
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.grepTool = void 0;
37
+ const path = __importStar(require("path"));
38
+ exports.grepTool = {
39
+ spec() {
40
+ return {
41
+ name: "grep",
42
+ description: 'Search for a pattern in files. Returns matching file paths and lines. Supports regex patterns.',
43
+ inputSchema: {
44
+ type: "object",
45
+ properties: {
46
+ pattern: {
47
+ type: "string",
48
+ description: "The pattern to search for (regex supported)",
49
+ },
50
+ path: {
51
+ type: "string",
52
+ description: "Directory to search in (default: workspace root)",
53
+ },
54
+ include: {
55
+ type: "string",
56
+ description: 'File glob to include (e.g. "*.ts", "*.{js,ts}")',
57
+ },
58
+ max_results: {
59
+ type: "number",
60
+ description: "Maximum number of results (default: 50)",
61
+ },
62
+ },
63
+ required: ["pattern"],
64
+ },
65
+ isReadOnly: true,
66
+ };
67
+ },
68
+ run(input, ctx) {
69
+ const pattern = String(input.pattern ?? "");
70
+ if (!pattern) {
71
+ return { name: "grep", output: { error: "pattern is required" }, isError: true };
72
+ }
73
+ const searchPath = input.path
74
+ ? path.resolve(ctx.cwd, String(input.path))
75
+ : ctx.cwd;
76
+ const maxResults = typeof input.max_results === "number" ? input.max_results : 50;
77
+ const include = input.include ? String(input.include) : undefined;
78
+ try {
79
+ const isWin = process.platform === "win32";
80
+ let cmd;
81
+ if (isWin) {
82
+ const includeOpt = include ? ` /include:${include.replace(/"/g, "")}` : "";
83
+ cmd = `findstr /s /n /r ${includeOpt} "${pattern.replace(/"/g, "")}" "${searchPath}\\*"`;
84
+ }
85
+ else {
86
+ const includeOpt = include ? ` --include="${include}"` : "";
87
+ cmd = `grep -r -n -E${includeOpt} "${pattern.replace(/"/g, "")}" "${searchPath}" 2>/dev/null | head -${maxResults}`;
88
+ }
89
+ const result = execSync(cmd, { maxBuffer: 1024 * 1024, timeout: 30000 });
90
+ const output = result.toString().trim();
91
+ const lines = output.split("\n").filter(Boolean);
92
+ const matches = lines.slice(0, maxResults).map((line) => {
93
+ const colonIdx = line.indexOf(":");
94
+ if (colonIdx === -1)
95
+ return { file: "", line: 0, text: line };
96
+ const fileAndLine = line.slice(0, colonIdx);
97
+ const lastColon = fileAndLine.lastIndexOf(":");
98
+ if (lastColon === -1) {
99
+ return { file: fileAndLine, line: 0, text: line.slice(colonIdx + 1) };
100
+ }
101
+ return {
102
+ file: fileAndLine.slice(0, lastColon),
103
+ line: parseInt(fileAndLine.slice(lastColon + 1), 10) || 0,
104
+ text: line.slice(colonIdx + 1),
105
+ };
106
+ });
107
+ const files = [...new Set(matches.map((m) => m.file))];
108
+ return {
109
+ name: "grep",
110
+ output: {
111
+ pattern,
112
+ path: searchPath,
113
+ matches: matches,
114
+ numFiles: files.length,
115
+ numMatches: matches.length,
116
+ truncated: matches.length >= maxResults,
117
+ },
118
+ isError: false,
119
+ };
120
+ }
121
+ catch (err) {
122
+ if (err.status === 1 || err.status === 2) {
123
+ return {
124
+ name: "grep",
125
+ output: {
126
+ pattern,
127
+ path: searchPath,
128
+ matches: [],
129
+ numFiles: 0,
130
+ numMatches: 0,
131
+ truncated: false,
132
+ },
133
+ isError: false,
134
+ };
135
+ }
136
+ return {
137
+ name: "grep",
138
+ output: { error: `grep failed: ${err.message}` },
139
+ isError: true,
140
+ };
141
+ }
142
+ },
143
+ };
144
+ function execSync(cmd, opts) {
145
+ const { execSync: _execSync } = require("child_process");
146
+ return _execSync(cmd, opts);
147
+ }
148
+ //# sourceMappingURL=grep.js.map
@@ -0,0 +1,3 @@
1
+ import type { Tool } from "../protocol";
2
+ export declare const readTool: Tool;
3
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.readTool = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ exports.readTool = {
40
+ spec() {
41
+ return {
42
+ name: "read",
43
+ description: "Read the contents of a file. Returns the file content with line numbers. Supports offset and limit for partial reads.",
44
+ inputSchema: {
45
+ type: "object",
46
+ properties: {
47
+ file_path: { type: "string", description: "Path to the file to read" },
48
+ offset: { type: "number", description: "Line number to start reading from (1-based)" },
49
+ limit: { type: "number", description: "Maximum number of lines to read" },
50
+ },
51
+ required: ["file_path"],
52
+ },
53
+ isReadOnly: true,
54
+ };
55
+ },
56
+ run(input, ctx) {
57
+ const filePath = path.resolve(ctx.cwd, String(input.file_path ?? ""));
58
+ if (!filePath.startsWith(ctx.cwd)) {
59
+ return { name: "read", output: { error: "Path is outside the workspace" }, isError: true };
60
+ }
61
+ if (!fs.existsSync(filePath)) {
62
+ return { name: "read", output: { error: `File not found: ${input.file_path}` }, isError: true };
63
+ }
64
+ const stat = fs.statSync(filePath);
65
+ if (stat.isDirectory()) {
66
+ return { name: "read", output: { error: `Path is a directory: ${input.file_path}` }, isError: true };
67
+ }
68
+ if (stat.size > 1_000_000) {
69
+ return { name: "read", output: { error: `File too large (${(stat.size / 1024).toFixed(0)}KB). Use offset/limit.` }, isError: true };
70
+ }
71
+ const raw = fs.readFileSync(filePath, "utf-8");
72
+ const lines = raw.split("\n");
73
+ const totalLines = lines.length;
74
+ const offset = typeof input.offset === "number" ? Math.max(1, input.offset) : 1;
75
+ const limit = typeof input.limit === "number" ? input.limit : Math.min(totalLines - offset + 1, 2000);
76
+ const sliced = lines.slice(offset - 1, offset - 1 + limit);
77
+ const numbered = sliced.map((line, i) => `${String(offset + i).padStart(6)}|${line}`).join("\n");
78
+ return {
79
+ name: "read",
80
+ output: { type: "text", file: { filePath: String(input.file_path), startLine: offset, numLines: sliced.length, totalLines }, content: numbered },
81
+ isError: false,
82
+ };
83
+ },
84
+ };
85
+ //# sourceMappingURL=read.js.map
@@ -0,0 +1,3 @@
1
+ import type { Tool } from "../protocol";
2
+ export declare const webFetchTool: Tool;
3
+ //# sourceMappingURL=web-fetch.d.ts.map
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.webFetchTool = void 0;
7
+ const https_1 = __importDefault(require("https"));
8
+ const http_1 = __importDefault(require("http"));
9
+ const version_1 = require("../../version");
10
+ const MAX_RESPONSE_SIZE = 500_000;
11
+ const TIMEOUT_MS = 30_000;
12
+ exports.webFetchTool = {
13
+ spec() {
14
+ return {
15
+ name: "web-fetch",
16
+ description: "Fetch content from a URL. Returns the response body as text. Supports HTTP and HTTPS. Use for reading web pages, API responses, or documentation.",
17
+ inputSchema: {
18
+ type: "object",
19
+ properties: {
20
+ url: {
21
+ type: "string",
22
+ description: "The URL to fetch (http:// or https://)",
23
+ },
24
+ method: {
25
+ type: "string",
26
+ description: "HTTP method (default: GET)",
27
+ },
28
+ headers: {
29
+ type: "object",
30
+ description: "Optional request headers as key-value pairs",
31
+ },
32
+ },
33
+ required: ["url"],
34
+ },
35
+ isReadOnly: true,
36
+ };
37
+ },
38
+ run(input, _ctx) {
39
+ const url = String(input.url ?? "");
40
+ const method = String(input.method ?? "GET").toUpperCase();
41
+ const headers = input.headers ?? {};
42
+ if (!url) {
43
+ return Promise.resolve({
44
+ name: "web-fetch",
45
+ output: { error: "url is required" },
46
+ isError: true,
47
+ });
48
+ }
49
+ let parsedUrl;
50
+ try {
51
+ parsedUrl = new URL(url);
52
+ }
53
+ catch {
54
+ return Promise.resolve({
55
+ name: "web-fetch",
56
+ output: { error: `Invalid URL: ${url}` },
57
+ isError: true,
58
+ });
59
+ }
60
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
61
+ return Promise.resolve({
62
+ name: "web-fetch",
63
+ output: { error: `Unsupported protocol: ${parsedUrl.protocol}. Use http:// or https://` },
64
+ isError: true,
65
+ });
66
+ }
67
+ return new Promise((resolve) => {
68
+ const lib = parsedUrl.protocol === "https:" ? https_1.default : http_1.default;
69
+ const req = lib.request(url, {
70
+ method,
71
+ headers: {
72
+ "User-Agent": `LLMTune-CLI/${version_1.CLI_VERSION}`,
73
+ Accept: "text/html,application/json,text/plain,*/*",
74
+ ...headers,
75
+ },
76
+ timeout: TIMEOUT_MS,
77
+ }, (res) => {
78
+ // Follow redirects (up to 5)
79
+ if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
80
+ const redirectUrl = new URL(res.headers.location, url).toString();
81
+ return Promise.resolve(exports.webFetchTool.run({ ...input, url: redirectUrl }, _ctx)).then(resolve);
82
+ }
83
+ const chunks = [];
84
+ let size = 0;
85
+ res.on("data", (chunk) => {
86
+ size += chunk.length;
87
+ if (size > MAX_RESPONSE_SIZE) {
88
+ req.destroy();
89
+ resolve({
90
+ name: "web-fetch",
91
+ output: {
92
+ error: `Response too large (${(size / 1024).toFixed(0)}KB). Maximum is ${MAX_RESPONSE_SIZE / 1024}KB.`,
93
+ },
94
+ isError: true,
95
+ });
96
+ return;
97
+ }
98
+ chunks.push(chunk);
99
+ });
100
+ res.on("end", () => {
101
+ const body = Buffer.concat(chunks).toString("utf-8");
102
+ const truncated = body.length > 50_000;
103
+ const content = truncated ? body.slice(0, 50_000) + "\n... (truncated)" : body;
104
+ resolve({
105
+ name: "web-fetch",
106
+ output: {
107
+ url,
108
+ status: res.statusCode ?? 0,
109
+ contentType: res.headers["content-type"] ?? "unknown",
110
+ content,
111
+ truncated,
112
+ },
113
+ isError: false,
114
+ });
115
+ });
116
+ res.on("error", (err) => {
117
+ resolve({
118
+ name: "web-fetch",
119
+ output: { error: `Response error: ${err.message}` },
120
+ isError: true,
121
+ });
122
+ });
123
+ });
124
+ req.on("error", (err) => {
125
+ resolve({
126
+ name: "web-fetch",
127
+ output: { error: `Request failed: ${err.message}` },
128
+ isError: true,
129
+ });
130
+ });
131
+ req.on("timeout", () => {
132
+ req.destroy();
133
+ resolve({
134
+ name: "web-fetch",
135
+ output: { error: `Request timed out after ${TIMEOUT_MS / 1000}s` },
136
+ isError: true,
137
+ });
138
+ });
139
+ req.end();
140
+ });
141
+ },
142
+ };
143
+ //# sourceMappingURL=web-fetch.js.map
@@ -0,0 +1,3 @@
1
+ import type { Tool } from "../protocol";
2
+ export declare const writeTool: Tool;
3
+ //# sourceMappingURL=write.d.ts.map