@llmist/cli 16.0.4 → 16.1.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/dist/cli.js +1514 -1117
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +88 -44
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ declare class PathSandboxException extends Error {
|
|
|
19
19
|
*/
|
|
20
20
|
declare function validatePathIsWithinCwd(inputPath: string): string;
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* DeleteFile gadget - Deletes a file or directory.
|
|
24
|
+
* All paths are validated to be within the current working directory.
|
|
25
|
+
*/
|
|
26
|
+
declare const deleteFile: llmist.AbstractGadget;
|
|
27
|
+
|
|
22
28
|
declare const editFile: llmist.AbstractGadget;
|
|
23
29
|
|
|
24
30
|
/**
|
|
@@ -53,4 +59,4 @@ declare const writeFile: llmist.AbstractGadget;
|
|
|
53
59
|
*/
|
|
54
60
|
declare const runCommand: llmist.AbstractGadget;
|
|
55
61
|
|
|
56
|
-
export {
|
|
62
|
+
export { deleteFile as DeleteFile, listDirectory as ListDirectory, PathSandboxException, readFile as ReadFile, runCommand as RunCommand, writeFile as WriteFile, deleteFile, editFile, listDirectory, readFile, runCommand, validatePathIsWithinCwd, writeFile };
|
package/dist/index.js
CHANGED
|
@@ -28,10 +28,53 @@ function validatePathIsWithinCwd(inputPath) {
|
|
|
28
28
|
return finalPath;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// src/builtins/filesystem/
|
|
32
|
-
import
|
|
31
|
+
// src/builtins/filesystem/delete-file.ts
|
|
32
|
+
import fs2 from "fs";
|
|
33
33
|
import { createGadget } from "llmist";
|
|
34
34
|
import { z } from "zod";
|
|
35
|
+
var deleteFile = createGadget({
|
|
36
|
+
name: "DeleteFile",
|
|
37
|
+
description: "Delete a file or directory from the local filesystem. The path must be within the current working directory or its subdirectories.",
|
|
38
|
+
maxConcurrent: 1,
|
|
39
|
+
// Sequential execution to prevent race conditions
|
|
40
|
+
schema: z.object({
|
|
41
|
+
filePath: z.string().describe("Path to the file or directory to delete (relative or absolute)"),
|
|
42
|
+
recursive: z.boolean().optional().default(false).describe("If true, perform a recursive deletion (required for directories)")
|
|
43
|
+
}),
|
|
44
|
+
examples: [
|
|
45
|
+
{
|
|
46
|
+
params: { filePath: "temp.txt", recursive: false },
|
|
47
|
+
output: "path=temp.txt\n\nDeleted file successfully",
|
|
48
|
+
comment: "Delete a single file"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
params: { filePath: "tmp-dir", recursive: true },
|
|
52
|
+
output: "path=tmp-dir\n\nDeleted directory successfully",
|
|
53
|
+
comment: "Delete a directory and its contents"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
execute: ({ filePath, recursive }) => {
|
|
57
|
+
const validatedPath = validatePathIsWithinCwd(filePath);
|
|
58
|
+
if (!fs2.existsSync(validatedPath)) {
|
|
59
|
+
return `Error: Path does not exist: ${filePath}`;
|
|
60
|
+
}
|
|
61
|
+
const stats = fs2.statSync(validatedPath);
|
|
62
|
+
const isDirectory = stats.isDirectory();
|
|
63
|
+
if (isDirectory && !recursive) {
|
|
64
|
+
return `Error: ${filePath} is a directory. Set recursive=true to delete it.`;
|
|
65
|
+
}
|
|
66
|
+
fs2.rmSync(validatedPath, { recursive, force: true });
|
|
67
|
+
const type = isDirectory ? "directory" : "file";
|
|
68
|
+
return `path=${filePath}
|
|
69
|
+
|
|
70
|
+
Deleted ${type} successfully`;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// src/builtins/filesystem/edit-file.ts
|
|
75
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
76
|
+
import { createGadget as createGadget2 } from "llmist";
|
|
77
|
+
import { z as z2 } from "zod";
|
|
35
78
|
|
|
36
79
|
// src/builtins/filesystem/editfile/matcher.ts
|
|
37
80
|
import DiffMatchPatch from "diff-match-patch";
|
|
@@ -481,7 +524,7 @@ function formatFailure(filePath, search, failure, fileContent) {
|
|
|
481
524
|
lines.push("", "CURRENT FILE CONTENT:", "```", fileContent, "```");
|
|
482
525
|
return lines.join("\n");
|
|
483
526
|
}
|
|
484
|
-
var editFile =
|
|
527
|
+
var editFile = createGadget2({
|
|
485
528
|
name: "EditFile",
|
|
486
529
|
description: `Edit a file by searching for content and replacing it.
|
|
487
530
|
|
|
@@ -500,12 +543,12 @@ Options:
|
|
|
500
543
|
- expectedCount: Validate exact number of matches before applying`,
|
|
501
544
|
maxConcurrent: 1,
|
|
502
545
|
// Sequential execution to prevent race conditions
|
|
503
|
-
schema:
|
|
504
|
-
filePath:
|
|
505
|
-
search:
|
|
506
|
-
replace:
|
|
507
|
-
replaceAll:
|
|
508
|
-
expectedCount:
|
|
546
|
+
schema: z2.object({
|
|
547
|
+
filePath: z2.string().describe("Path to the file to edit (relative or absolute)"),
|
|
548
|
+
search: z2.string().describe("The content to search for in the file"),
|
|
549
|
+
replace: z2.string().describe("The content to replace it with (empty string to delete)"),
|
|
550
|
+
replaceAll: z2.boolean().optional().default(false).describe("Replace all occurrences instead of just the first match"),
|
|
551
|
+
expectedCount: z2.number().int().positive().optional().describe("Expected number of matches. Edit fails if actual count differs")
|
|
509
552
|
}),
|
|
510
553
|
examples: [
|
|
511
554
|
{
|
|
@@ -657,19 +700,19 @@ function executeReplaceAll(content, matches, replace) {
|
|
|
657
700
|
}
|
|
658
701
|
|
|
659
702
|
// src/builtins/filesystem/list-directory.ts
|
|
660
|
-
import
|
|
703
|
+
import fs3 from "fs";
|
|
661
704
|
import path2 from "path";
|
|
662
|
-
import { createGadget as
|
|
663
|
-
import { z as
|
|
705
|
+
import { createGadget as createGadget3 } from "llmist";
|
|
706
|
+
import { z as z3 } from "zod";
|
|
664
707
|
function listFiles(dirPath, basePath = dirPath, maxDepth = 1, currentDepth = 1) {
|
|
665
708
|
const entries = [];
|
|
666
709
|
try {
|
|
667
|
-
const items =
|
|
710
|
+
const items = fs3.readdirSync(dirPath);
|
|
668
711
|
for (const item of items) {
|
|
669
712
|
const fullPath = path2.join(dirPath, item);
|
|
670
713
|
const relativePath = path2.relative(basePath, fullPath);
|
|
671
714
|
try {
|
|
672
|
-
const stats =
|
|
715
|
+
const stats = fs3.lstatSync(fullPath);
|
|
673
716
|
let type;
|
|
674
717
|
let size;
|
|
675
718
|
if (stats.isSymbolicLink()) {
|
|
@@ -744,12 +787,12 @@ function formatEntriesAsString(entries) {
|
|
|
744
787
|
);
|
|
745
788
|
return [header, ...rows].join("\n");
|
|
746
789
|
}
|
|
747
|
-
var listDirectory =
|
|
790
|
+
var listDirectory = createGadget3({
|
|
748
791
|
name: "ListDirectory",
|
|
749
792
|
description: "List files and directories in a directory with full details (names, types, sizes, modification dates). Use maxDepth to explore subdirectories recursively. The directory path must be within the current working directory or its subdirectories.",
|
|
750
|
-
schema:
|
|
751
|
-
directoryPath:
|
|
752
|
-
maxDepth:
|
|
793
|
+
schema: z3.object({
|
|
794
|
+
directoryPath: z3.string().default(".").describe("Path to the directory to list"),
|
|
795
|
+
maxDepth: z3.number().int().min(1).max(10).default(3).describe(
|
|
753
796
|
"Maximum depth to recurse (1 = immediate children only, 2 = include grandchildren, etc.)"
|
|
754
797
|
)
|
|
755
798
|
}),
|
|
@@ -767,7 +810,7 @@ var listDirectory = createGadget2({
|
|
|
767
810
|
],
|
|
768
811
|
execute: ({ directoryPath, maxDepth }) => {
|
|
769
812
|
const validatedPath = validatePathIsWithinCwd(directoryPath);
|
|
770
|
-
const stats =
|
|
813
|
+
const stats = fs3.statSync(validatedPath);
|
|
771
814
|
if (!stats.isDirectory()) {
|
|
772
815
|
throw new Error(`Path is not a directory: ${directoryPath}`);
|
|
773
816
|
}
|
|
@@ -780,14 +823,14 @@ ${formattedList}`;
|
|
|
780
823
|
});
|
|
781
824
|
|
|
782
825
|
// src/builtins/filesystem/read-file.ts
|
|
783
|
-
import
|
|
784
|
-
import { createGadget as
|
|
785
|
-
import { z as
|
|
786
|
-
var readFile =
|
|
826
|
+
import fs4 from "fs";
|
|
827
|
+
import { createGadget as createGadget4 } from "llmist";
|
|
828
|
+
import { z as z4 } from "zod";
|
|
829
|
+
var readFile = createGadget4({
|
|
787
830
|
name: "ReadFile",
|
|
788
831
|
description: "Read the entire content of a file and return it as text. The file path must be within the current working directory or its subdirectories.",
|
|
789
|
-
schema:
|
|
790
|
-
filePath:
|
|
832
|
+
schema: z4.object({
|
|
833
|
+
filePath: z4.string().describe("Path to the file to read (relative or absolute)")
|
|
791
834
|
}),
|
|
792
835
|
examples: [
|
|
793
836
|
{
|
|
@@ -803,7 +846,7 @@ var readFile = createGadget3({
|
|
|
803
846
|
],
|
|
804
847
|
execute: ({ filePath }) => {
|
|
805
848
|
const validatedPath = validatePathIsWithinCwd(filePath);
|
|
806
|
-
const content =
|
|
849
|
+
const content = fs4.readFileSync(validatedPath, "utf-8");
|
|
807
850
|
return `path=${filePath}
|
|
808
851
|
|
|
809
852
|
${content}`;
|
|
@@ -811,18 +854,18 @@ ${content}`;
|
|
|
811
854
|
});
|
|
812
855
|
|
|
813
856
|
// src/builtins/filesystem/write-file.ts
|
|
814
|
-
import
|
|
857
|
+
import fs5 from "fs";
|
|
815
858
|
import path3 from "path";
|
|
816
|
-
import { createGadget as
|
|
817
|
-
import { z as
|
|
818
|
-
var writeFile =
|
|
859
|
+
import { createGadget as createGadget5 } from "llmist";
|
|
860
|
+
import { z as z5 } from "zod";
|
|
861
|
+
var writeFile = createGadget5({
|
|
819
862
|
name: "WriteFile",
|
|
820
863
|
description: "Write content to a file. Creates parent directories if needed. Overwrites existing files. The file path must be within the current working directory or its subdirectories.",
|
|
821
864
|
maxConcurrent: 1,
|
|
822
865
|
// Sequential execution to prevent race conditions
|
|
823
|
-
schema:
|
|
824
|
-
filePath:
|
|
825
|
-
content:
|
|
866
|
+
schema: z5.object({
|
|
867
|
+
filePath: z5.string().describe("Path to the file to write (relative or absolute)"),
|
|
868
|
+
content: z5.string().describe("Content to write to the file")
|
|
826
869
|
}),
|
|
827
870
|
examples: [
|
|
828
871
|
{
|
|
@@ -852,12 +895,12 @@ console.log(\`Server running on http://localhost:\${port}\`);`
|
|
|
852
895
|
const validatedPath = validatePathIsWithinCwd(filePath);
|
|
853
896
|
const parentDir = path3.dirname(validatedPath);
|
|
854
897
|
let createdDir = false;
|
|
855
|
-
if (!
|
|
898
|
+
if (!fs5.existsSync(parentDir)) {
|
|
856
899
|
validatePathIsWithinCwd(parentDir);
|
|
857
|
-
|
|
900
|
+
fs5.mkdirSync(parentDir, { recursive: true });
|
|
858
901
|
createdDir = true;
|
|
859
902
|
}
|
|
860
|
-
|
|
903
|
+
fs5.writeFileSync(validatedPath, content, "utf-8");
|
|
861
904
|
const bytesWritten = Buffer.byteLength(content, "utf-8");
|
|
862
905
|
const dirNote = createdDir ? ` (created directory: ${path3.dirname(filePath)})` : "";
|
|
863
906
|
return `path=${filePath}
|
|
@@ -867,8 +910,8 @@ Wrote ${bytesWritten} bytes${dirNote}`;
|
|
|
867
910
|
});
|
|
868
911
|
|
|
869
912
|
// src/builtins/run-command.ts
|
|
870
|
-
import { createGadget as
|
|
871
|
-
import { z as
|
|
913
|
+
import { createGadget as createGadget6 } from "llmist";
|
|
914
|
+
import { z as z6 } from "zod";
|
|
872
915
|
|
|
873
916
|
// src/spawn.ts
|
|
874
917
|
import { spawn as nodeSpawn } from "child_process";
|
|
@@ -929,13 +972,13 @@ function spawn(argv, options = {}) {
|
|
|
929
972
|
}
|
|
930
973
|
|
|
931
974
|
// src/builtins/run-command.ts
|
|
932
|
-
var runCommand =
|
|
975
|
+
var runCommand = createGadget6({
|
|
933
976
|
name: "RunCommand",
|
|
934
977
|
description: "Execute a command with arguments and return its output. Uses argv array to bypass shell - arguments are passed directly without interpretation. Returns stdout/stderr combined with exit status.",
|
|
935
|
-
schema:
|
|
936
|
-
argv:
|
|
937
|
-
cwd:
|
|
938
|
-
timeout:
|
|
978
|
+
schema: z6.object({
|
|
979
|
+
argv: z6.array(z6.string()).describe("Command and arguments as array (e.g., ['git', 'commit', '-m', 'message'])"),
|
|
980
|
+
cwd: z6.string().optional().describe("Working directory for the command (default: current directory)"),
|
|
981
|
+
timeout: z6.number().default(3e4).describe("Timeout in milliseconds (default: 30000)")
|
|
939
982
|
}),
|
|
940
983
|
examples: [
|
|
941
984
|
{
|
|
@@ -1036,12 +1079,13 @@ error: ${message}`;
|
|
|
1036
1079
|
}
|
|
1037
1080
|
});
|
|
1038
1081
|
export {
|
|
1039
|
-
|
|
1082
|
+
deleteFile as DeleteFile,
|
|
1040
1083
|
listDirectory as ListDirectory,
|
|
1041
1084
|
PathSandboxException,
|
|
1042
1085
|
readFile as ReadFile,
|
|
1043
1086
|
runCommand as RunCommand,
|
|
1044
1087
|
writeFile as WriteFile,
|
|
1088
|
+
deleteFile,
|
|
1045
1089
|
editFile,
|
|
1046
1090
|
listDirectory,
|
|
1047
1091
|
readFile,
|