@cdoing/core 0.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/agents/coordinator.d.ts +114 -0
- package/dist/agents/coordinator.d.ts.map +1 -0
- package/dist/agents/coordinator.js +158 -0
- package/dist/agents/coordinator.js.map +1 -0
- package/dist/context-providers/clipboard.d.ts +13 -0
- package/dist/context-providers/clipboard.d.ts.map +1 -0
- package/dist/context-providers/clipboard.js +53 -0
- package/dist/context-providers/clipboard.js.map +1 -0
- package/dist/context-providers/codebase.d.ts +46 -0
- package/dist/context-providers/codebase.d.ts.map +1 -0
- package/dist/context-providers/codebase.js +273 -0
- package/dist/context-providers/codebase.js.map +1 -0
- package/dist/context-providers/diff.d.ts +18 -0
- package/dist/context-providers/diff.d.ts.map +1 -0
- package/dist/context-providers/diff.js +63 -0
- package/dist/context-providers/diff.js.map +1 -0
- package/dist/context-providers/docs.d.ts +21 -0
- package/dist/context-providers/docs.d.ts.map +1 -0
- package/dist/context-providers/docs.js +180 -0
- package/dist/context-providers/docs.js.map +1 -0
- package/dist/context-providers/file-include.d.ts +13 -0
- package/dist/context-providers/file-include.d.ts.map +1 -0
- package/dist/context-providers/file-include.js +82 -0
- package/dist/context-providers/file-include.js.map +1 -0
- package/dist/context-providers/folder.d.ts +19 -0
- package/dist/context-providers/folder.d.ts.map +1 -0
- package/dist/context-providers/folder.js +130 -0
- package/dist/context-providers/folder.js.map +1 -0
- package/dist/context-providers/git.d.ts +19 -0
- package/dist/context-providers/git.d.ts.map +1 -0
- package/dist/context-providers/git.js +74 -0
- package/dist/context-providers/git.js.map +1 -0
- package/dist/context-providers/index.d.ts +26 -0
- package/dist/context-providers/index.d.ts.map +1 -0
- package/dist/context-providers/index.js +37 -0
- package/dist/context-providers/index.js.map +1 -0
- package/dist/context-providers/open-files.d.ts +25 -0
- package/dist/context-providers/open-files.d.ts.map +1 -0
- package/dist/context-providers/open-files.js +134 -0
- package/dist/context-providers/open-files.js.map +1 -0
- package/dist/context-providers/problems.d.ts +24 -0
- package/dist/context-providers/problems.d.ts.map +1 -0
- package/dist/context-providers/problems.js +97 -0
- package/dist/context-providers/problems.js.map +1 -0
- package/dist/context-providers/registry.d.ts +61 -0
- package/dist/context-providers/registry.d.ts.map +1 -0
- package/dist/context-providers/registry.js +92 -0
- package/dist/context-providers/registry.js.map +1 -0
- package/dist/context-providers/terminal.d.ts +25 -0
- package/dist/context-providers/terminal.d.ts.map +1 -0
- package/dist/context-providers/terminal.js +55 -0
- package/dist/context-providers/terminal.js.map +1 -0
- package/dist/context-providers/tree.d.ts +29 -0
- package/dist/context-providers/tree.d.ts.map +1 -0
- package/dist/context-providers/tree.js +172 -0
- package/dist/context-providers/tree.js.map +1 -0
- package/dist/context-providers/types.d.ts +72 -0
- package/dist/context-providers/types.d.ts.map +1 -0
- package/dist/context-providers/types.js +10 -0
- package/dist/context-providers/types.js.map +1 -0
- package/dist/context-providers/url.d.ts +27 -0
- package/dist/context-providers/url.d.ts.map +1 -0
- package/dist/context-providers/url.js +131 -0
- package/dist/context-providers/url.js.map +1 -0
- package/dist/effort/index.d.ts +78 -0
- package/dist/effort/index.d.ts.map +1 -0
- package/dist/effort/index.js +146 -0
- package/dist/effort/index.js.map +1 -0
- package/dist/hooks/index.d.ts +47 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +151 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +152 -0
- package/dist/index.js.map +1 -0
- package/dist/indexing/chunker.d.ts +25 -0
- package/dist/indexing/chunker.d.ts.map +1 -0
- package/dist/indexing/chunker.js +217 -0
- package/dist/indexing/chunker.js.map +1 -0
- package/dist/indexing/database.d.ts +49 -0
- package/dist/indexing/database.d.ts.map +1 -0
- package/dist/indexing/database.js +287 -0
- package/dist/indexing/database.js.map +1 -0
- package/dist/indexing/index.d.ts +9 -0
- package/dist/indexing/index.d.ts.map +1 -0
- package/dist/indexing/index.js +13 -0
- package/dist/indexing/index.js.map +1 -0
- package/dist/indexing/indexer.d.ts +63 -0
- package/dist/indexing/indexer.d.ts.map +1 -0
- package/dist/indexing/indexer.js +352 -0
- package/dist/indexing/indexer.js.map +1 -0
- package/dist/indexing/recent-edits-cache.d.ts +77 -0
- package/dist/indexing/recent-edits-cache.d.ts.map +1 -0
- package/dist/indexing/recent-edits-cache.js +123 -0
- package/dist/indexing/recent-edits-cache.js.map +1 -0
- package/dist/indexing/types.d.ts +39 -0
- package/dist/indexing/types.d.ts.map +1 -0
- package/dist/indexing/types.js +6 -0
- package/dist/indexing/types.js.map +1 -0
- package/dist/mcp/index.d.ts +33 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +37 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +123 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/manager.js +331 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/oauth.d.ts +33 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +312 -0
- package/dist/oauth.js.map +1 -0
- package/dist/permissions/index.d.ts +216 -0
- package/dist/permissions/index.d.ts.map +1 -0
- package/dist/permissions/index.js +938 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/plan/index.d.ts +20 -0
- package/dist/plan/index.d.ts.map +1 -0
- package/dist/plan/index.js +24 -0
- package/dist/plan/index.js.map +1 -0
- package/dist/plan/manager.d.ts +101 -0
- package/dist/plan/manager.d.ts.map +1 -0
- package/dist/plan/manager.js +170 -0
- package/dist/plan/manager.js.map +1 -0
- package/dist/rules/index.d.ts +28 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +31 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/manager.d.ts +77 -0
- package/dist/rules/manager.d.ts.map +1 -0
- package/dist/rules/manager.js +279 -0
- package/dist/rules/manager.js.map +1 -0
- package/dist/rules/types.d.ts +34 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +9 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/sandbox/filesystem.d.ts +20 -0
- package/dist/sandbox/filesystem.d.ts.map +1 -0
- package/dist/sandbox/filesystem.js +141 -0
- package/dist/sandbox/filesystem.js.map +1 -0
- package/dist/sandbox/index.d.ts +4 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +8 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/manager.d.ts +47 -0
- package/dist/sandbox/manager.d.ts.map +1 -0
- package/dist/sandbox/manager.js +220 -0
- package/dist/sandbox/manager.js.map +1 -0
- package/dist/sandbox/network.d.ts +14 -0
- package/dist/sandbox/network.d.ts.map +1 -0
- package/dist/sandbox/network.js +87 -0
- package/dist/sandbox/network.js.map +1 -0
- package/dist/sandbox/types.d.ts +42 -0
- package/dist/sandbox/types.d.ts.map +1 -0
- package/dist/sandbox/types.js +25 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/tools/ast-edit.d.ts +57 -0
- package/dist/tools/ast-edit.d.ts.map +1 -0
- package/dist/tools/ast-edit.js +443 -0
- package/dist/tools/ast-edit.js.map +1 -0
- package/dist/tools/code-verify.d.ts +8 -0
- package/dist/tools/code-verify.d.ts.map +1 -0
- package/dist/tools/code-verify.js +159 -0
- package/dist/tools/code-verify.js.map +1 -0
- package/dist/tools/codebase-search.d.ts +17 -0
- package/dist/tools/codebase-search.d.ts.map +1 -0
- package/dist/tools/codebase-search.js +104 -0
- package/dist/tools/codebase-search.js.map +1 -0
- package/dist/tools/file-delete.d.ts +26 -0
- package/dist/tools/file-delete.d.ts.map +1 -0
- package/dist/tools/file-delete.js +179 -0
- package/dist/tools/file-delete.js.map +1 -0
- package/dist/tools/file-edit.d.ts +10 -0
- package/dist/tools/file-edit.d.ts.map +1 -0
- package/dist/tools/file-edit.js +138 -0
- package/dist/tools/file-edit.js.map +1 -0
- package/dist/tools/file-read.d.ts +12 -0
- package/dist/tools/file-read.d.ts.map +1 -0
- package/dist/tools/file-read.js +211 -0
- package/dist/tools/file-read.js.map +1 -0
- package/dist/tools/file-run.d.ts +10 -0
- package/dist/tools/file-run.d.ts.map +1 -0
- package/dist/tools/file-run.js +179 -0
- package/dist/tools/file-run.js.map +1 -0
- package/dist/tools/file-write.d.ts +10 -0
- package/dist/tools/file-write.d.ts.map +1 -0
- package/dist/tools/file-write.js +134 -0
- package/dist/tools/file-write.js.map +1 -0
- package/dist/tools/glob-search.d.ts +8 -0
- package/dist/tools/glob-search.d.ts.map +1 -0
- package/dist/tools/glob-search.js +108 -0
- package/dist/tools/glob-search.js.map +1 -0
- package/dist/tools/grep-search.d.ts +8 -0
- package/dist/tools/grep-search.d.ts.map +1 -0
- package/dist/tools/grep-search.js +139 -0
- package/dist/tools/grep-search.js.map +1 -0
- package/dist/tools/list-dir.d.ts +16 -0
- package/dist/tools/list-dir.d.ts.map +1 -0
- package/dist/tools/list-dir.js +183 -0
- package/dist/tools/list-dir.js.map +1 -0
- package/dist/tools/multi-edit.d.ts +16 -0
- package/dist/tools/multi-edit.d.ts.map +1 -0
- package/dist/tools/multi-edit.js +163 -0
- package/dist/tools/multi-edit.js.map +1 -0
- package/dist/tools/notebook-edit.d.ts +31 -0
- package/dist/tools/notebook-edit.d.ts.map +1 -0
- package/dist/tools/notebook-edit.js +321 -0
- package/dist/tools/notebook-edit.js.map +1 -0
- package/dist/tools/registry.d.ts +16 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +41 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/shell-exec.d.ts +12 -0
- package/dist/tools/shell-exec.d.ts.map +1 -0
- package/dist/tools/shell-exec.js +261 -0
- package/dist/tools/shell-exec.js.map +1 -0
- package/dist/tools/sub-agent-manager.d.ts +57 -0
- package/dist/tools/sub-agent-manager.d.ts.map +1 -0
- package/dist/tools/sub-agent-manager.js +153 -0
- package/dist/tools/sub-agent-manager.js.map +1 -0
- package/dist/tools/sub-agent-status.d.ts +12 -0
- package/dist/tools/sub-agent-status.d.ts.map +1 -0
- package/dist/tools/sub-agent-status.js +59 -0
- package/dist/tools/sub-agent-status.js.map +1 -0
- package/dist/tools/sub-agent-terminate.d.ts +12 -0
- package/dist/tools/sub-agent-terminate.d.ts.map +1 -0
- package/dist/tools/sub-agent-terminate.js +55 -0
- package/dist/tools/sub-agent-terminate.js.map +1 -0
- package/dist/tools/sub-agent.d.ts +34 -0
- package/dist/tools/sub-agent.d.ts.map +1 -0
- package/dist/tools/sub-agent.js +140 -0
- package/dist/tools/sub-agent.js.map +1 -0
- package/dist/tools/system-info.d.ts +24 -0
- package/dist/tools/system-info.d.ts.map +1 -0
- package/dist/tools/system-info.js +220 -0
- package/dist/tools/system-info.js.map +1 -0
- package/dist/tools/todo.d.ts +16 -0
- package/dist/tools/todo.d.ts.map +1 -0
- package/dist/tools/todo.js +144 -0
- package/dist/tools/todo.js.map +1 -0
- package/dist/tools/types.d.ts +20 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +3 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/view-diff.d.ts +11 -0
- package/dist/tools/view-diff.d.ts.map +1 -0
- package/dist/tools/view-diff.js +88 -0
- package/dist/tools/view-diff.js.map +1 -0
- package/dist/tools/view-repo-map.d.ts +18 -0
- package/dist/tools/view-repo-map.d.ts.map +1 -0
- package/dist/tools/view-repo-map.js +245 -0
- package/dist/tools/view-repo-map.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +13 -0
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +106 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +10 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +106 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/utils/gitignore.d.ts +10 -0
- package/dist/utils/gitignore.d.ts.map +1 -0
- package/dist/utils/gitignore.js +104 -0
- package/dist/utils/gitignore.js.map +1 -0
- package/dist/utils/lazy-apply.d.ts +45 -0
- package/dist/utils/lazy-apply.d.ts.map +1 -0
- package/dist/utils/lazy-apply.js +164 -0
- package/dist/utils/lazy-apply.js.map +1 -0
- package/dist/utils/memory.d.ts +36 -0
- package/dist/utils/memory.d.ts.map +1 -0
- package/dist/utils/memory.js +136 -0
- package/dist/utils/memory.js.map +1 -0
- package/dist/utils/path-matching.d.ts +24 -0
- package/dist/utils/path-matching.d.ts.map +1 -0
- package/dist/utils/path-matching.js +116 -0
- package/dist/utils/path-matching.js.map +1 -0
- package/dist/utils/path-safety.d.ts +13 -0
- package/dist/utils/path-safety.d.ts.map +1 -0
- package/dist/utils/path-safety.js +54 -0
- package/dist/utils/path-safety.js.map +1 -0
- package/dist/utils/project-config.d.ts +18 -0
- package/dist/utils/project-config.d.ts.map +1 -0
- package/dist/utils/project-config.js +76 -0
- package/dist/utils/project-config.js.map +1 -0
- package/dist/utils/search-match.d.ts +63 -0
- package/dist/utils/search-match.d.ts.map +1 -0
- package/dist/utils/search-match.js +426 -0
- package/dist/utils/search-match.js.map +1 -0
- package/dist/utils/shell-paths.d.ts +17 -0
- package/dist/utils/shell-paths.d.ts.map +1 -0
- package/dist/utils/shell-paths.js +107 -0
- package/dist/utils/shell-paths.js.map +1 -0
- package/dist/utils/streaming-diff.d.ts +45 -0
- package/dist/utils/streaming-diff.d.ts.map +1 -0
- package/dist/utils/streaming-diff.js +230 -0
- package/dist/utils/streaming-diff.js.map +1 -0
- package/dist/utils/todo.d.ts +47 -0
- package/dist/utils/todo.d.ts.map +1 -0
- package/dist/utils/todo.js +102 -0
- package/dist/utils/todo.js.map +1 -0
- package/package.json +23 -0
- package/src/agents/coordinator.ts +240 -0
- package/src/context-providers/clipboard.ts +48 -0
- package/src/context-providers/codebase.ts +274 -0
- package/src/context-providers/diff.ts +66 -0
- package/src/context-providers/docs.ts +160 -0
- package/src/context-providers/file-include.ts +54 -0
- package/src/context-providers/folder.ts +106 -0
- package/src/context-providers/git.ts +72 -0
- package/src/context-providers/index.ts +26 -0
- package/src/context-providers/open-files.ts +113 -0
- package/src/context-providers/problems.ts +100 -0
- package/src/context-providers/registry.ts +99 -0
- package/src/context-providers/terminal.ts +58 -0
- package/src/context-providers/tree.ts +161 -0
- package/src/context-providers/types.ts +84 -0
- package/src/context-providers/url.ts +138 -0
- package/src/effort/index.ts +177 -0
- package/src/hooks/index.ts +148 -0
- package/src/index.ts +114 -0
- package/src/indexing/README.md +267 -0
- package/src/indexing/chunker.ts +206 -0
- package/src/indexing/database.ts +299 -0
- package/src/indexing/index.ts +15 -0
- package/src/indexing/indexer.ts +383 -0
- package/src/indexing/recent-edits-cache.ts +150 -0
- package/src/indexing/types.ts +44 -0
- package/src/mcp/index.ts +33 -0
- package/src/mcp/manager.ts +385 -0
- package/src/oauth.ts +330 -0
- package/src/permissions/index.ts +1011 -0
- package/src/plan/index.ts +20 -0
- package/src/plan/manager.ts +233 -0
- package/src/rules/index.ts +28 -0
- package/src/rules/manager.ts +276 -0
- package/src/rules/types.ts +40 -0
- package/src/sandbox/filesystem.ts +135 -0
- package/src/sandbox/index.ts +9 -0
- package/src/sandbox/manager.ts +213 -0
- package/src/sandbox/network.ts +101 -0
- package/src/sandbox/types.ts +63 -0
- package/src/tools/ast-edit.ts +493 -0
- package/src/tools/code-verify.ts +143 -0
- package/src/tools/codebase-search.ts +117 -0
- package/src/tools/file-delete.ts +155 -0
- package/src/tools/file-edit.ts +115 -0
- package/src/tools/file-read.ts +195 -0
- package/src/tools/file-run.ts +158 -0
- package/src/tools/file-write.ts +104 -0
- package/src/tools/glob-search.ts +80 -0
- package/src/tools/grep-search.ts +120 -0
- package/src/tools/list-dir.ts +172 -0
- package/src/tools/multi-edit.ts +138 -0
- package/src/tools/notebook-edit.ts +342 -0
- package/src/tools/registry.ts +43 -0
- package/src/tools/shell-exec.ts +251 -0
- package/src/tools/sub-agent-manager.ts +183 -0
- package/src/tools/sub-agent-status.ts +67 -0
- package/src/tools/sub-agent-terminate.ts +62 -0
- package/src/tools/sub-agent.ts +162 -0
- package/src/tools/system-info.ts +248 -0
- package/src/tools/todo.ts +149 -0
- package/src/tools/types.ts +21 -0
- package/src/tools/view-diff.ts +99 -0
- package/src/tools/view-repo-map.ts +249 -0
- package/src/tools/web-fetch.ts +118 -0
- package/src/tools/web-search.ts +129 -0
- package/src/utils/gitignore.ts +73 -0
- package/src/utils/lazy-apply.ts +189 -0
- package/src/utils/memory.ts +124 -0
- package/src/utils/path-matching.ts +84 -0
- package/src/utils/path-safety.ts +19 -0
- package/src/utils/project-config.ts +41 -0
- package/src/utils/search-match.ts +495 -0
- package/src/utils/shell-paths.ts +79 -0
- package/src/utils/streaming-diff.ts +260 -0
- package/src/utils/todo.ts +115 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Multi Edit Tool — apply multiple find-and-replace edits to a single file atomically.
|
|
4
|
+
*
|
|
5
|
+
* Edits are applied sequentially (each operates on the result of the previous).
|
|
6
|
+
* If any edit fails, none are applied. Uses multi-strategy matching.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.MultiEditTool = void 0;
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const path_safety_1 = require("../utils/path-safety");
|
|
45
|
+
const search_match_1 = require("../utils/search-match");
|
|
46
|
+
class MultiEditTool {
|
|
47
|
+
definition = {
|
|
48
|
+
name: "multi_edit",
|
|
49
|
+
description: `Apply multiple find-and-replace edits to a single file in one atomic operation. Uses multi-strategy matching (exact → trimmed → case-insensitive → whitespace-ignored). Requires user permission.
|
|
50
|
+
|
|
51
|
+
Use this when you need to make several changes to different parts of the same file. This is more efficient than multiple file_edit calls and ensures all changes are applied together.
|
|
52
|
+
|
|
53
|
+
IMPORTANT:
|
|
54
|
+
- Always read the file first to see its current contents.
|
|
55
|
+
- All edits are applied sequentially — each edit operates on the result of the previous one.
|
|
56
|
+
- Edits are ATOMIC: if any edit fails, none are applied.
|
|
57
|
+
- old_string and new_string in each edit MUST be different.
|
|
58
|
+
- Plan edit order carefully — earlier edits change the text that later edits search in.
|
|
59
|
+
- This tool CANNOT be called in parallel with itself or file_edit on the SAME file.`,
|
|
60
|
+
inputSchema: {
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: {
|
|
63
|
+
file_path: {
|
|
64
|
+
type: "string",
|
|
65
|
+
description: "Path to the file to edit",
|
|
66
|
+
},
|
|
67
|
+
edits: {
|
|
68
|
+
type: "array",
|
|
69
|
+
description: "Array of edit operations to apply sequentially",
|
|
70
|
+
items: {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {
|
|
73
|
+
old_string: {
|
|
74
|
+
type: "string",
|
|
75
|
+
description: "The text to replace (matches with tolerance for whitespace/case differences)",
|
|
76
|
+
},
|
|
77
|
+
new_string: {
|
|
78
|
+
type: "string",
|
|
79
|
+
description: "The replacement text (MUST be different from old_string)",
|
|
80
|
+
},
|
|
81
|
+
replace_all: {
|
|
82
|
+
type: "boolean",
|
|
83
|
+
description: "Replace all occurrences of old_string (default: false)",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
required: ["old_string", "new_string"],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
required: ["file_path", "edits"],
|
|
91
|
+
},
|
|
92
|
+
requiresPermission: true,
|
|
93
|
+
permissionMessage: (input) => {
|
|
94
|
+
const edits = input.edits;
|
|
95
|
+
return `Multi-edit file: ${input.file_path} (${Array.isArray(edits) ? edits.length : "?"} edits)`;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
workingDir;
|
|
99
|
+
sandboxManager;
|
|
100
|
+
constructor(workingDir, sandboxManager) {
|
|
101
|
+
this.workingDir = workingDir;
|
|
102
|
+
this.sandboxManager = sandboxManager;
|
|
103
|
+
}
|
|
104
|
+
async execute(input) {
|
|
105
|
+
let filePath;
|
|
106
|
+
try {
|
|
107
|
+
filePath = (0, path_safety_1.safePath)(input.file_path, this.workingDir);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
return { success: false, output: "", error: err.message };
|
|
111
|
+
}
|
|
112
|
+
// Sandbox write check
|
|
113
|
+
if (this.sandboxManager) {
|
|
114
|
+
const check = this.sandboxManager.checkFileWrite(filePath);
|
|
115
|
+
if (!check.allowed) {
|
|
116
|
+
return { success: false, output: "", error: check.reason || "Sandbox: write access denied" };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const edits = input.edits;
|
|
120
|
+
// Validation
|
|
121
|
+
if (!Array.isArray(edits) || edits.length === 0) {
|
|
122
|
+
return { success: false, output: "", error: "edits must be a non-empty array" };
|
|
123
|
+
}
|
|
124
|
+
for (let i = 0; i < edits.length; i++) {
|
|
125
|
+
const e = edits[i];
|
|
126
|
+
if (!e.old_string && i > 0) {
|
|
127
|
+
return { success: false, output: "", error: `Edit ${i + 1}: only the first edit may have an empty old_string (insertion at beginning)` };
|
|
128
|
+
}
|
|
129
|
+
if (e.old_string === e.new_string) {
|
|
130
|
+
return { success: false, output: "", error: `Edit ${i + 1}: old_string and new_string are identical` };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!fs.existsSync(filePath))
|
|
134
|
+
return { success: false, output: "", error: `File not found: ${filePath}` };
|
|
135
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
136
|
+
try {
|
|
137
|
+
const { result, totalCount } = (0, search_match_1.executeMultiFindAndReplace)(content, edits);
|
|
138
|
+
fs.writeFileSync(filePath, result, "utf-8");
|
|
139
|
+
// Generate summary diff
|
|
140
|
+
const diffLines = [
|
|
141
|
+
`--- a/${filePath}`,
|
|
142
|
+
`+++ b/${filePath}`,
|
|
143
|
+
];
|
|
144
|
+
for (let i = 0; i < edits.length; i++) {
|
|
145
|
+
const e = edits[i];
|
|
146
|
+
diffLines.push(`@@ Edit ${i + 1}/${edits.length} @@`);
|
|
147
|
+
for (const line of e.old_string.split("\n"))
|
|
148
|
+
diffLines.push(`- ${line}`);
|
|
149
|
+
for (const line of e.new_string.split("\n"))
|
|
150
|
+
diffLines.push(`+ ${line}`);
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
success: true,
|
|
154
|
+
output: `Multi-edited ${filePath}: ${edits.length} edit(s), ${totalCount} total replacement(s)\n\n${diffLines.join("\n")}`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
return { success: false, output: "", error: err.message };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.MultiEditTool = MultiEditTool;
|
|
163
|
+
//# sourceMappingURL=multi-edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-edit.js","sourceRoot":"","sources":["../../src/tools/multi-edit.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AAEzB,sDAAgD;AAChD,wDAAmE;AAGnE,MAAa,aAAa;IACxB,UAAU,GAAmB;QAC3B,IAAI,EAAE,YAAY;QAClB,WAAW,EACT;;;;;;;;;;oFAU8E;QAChF,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,0BAA0B;iBACxC;gBACD,KAAK,EAAE;oBACL,IAAI,EAAE,OAAO;oBACb,WAAW,EAAE,gDAAgD;oBAC7D,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE;4BACV,UAAU,EAAE;gCACV,IAAI,EAAE,QAAQ;gCACd,WAAW,EAAE,8EAA8E;6BAC5F;4BACD,UAAU,EAAE;gCACV,IAAI,EAAE,QAAQ;gCACd,WAAW,EAAE,0DAA0D;6BACxE;4BACD,WAAW,EAAE;gCACX,IAAI,EAAE,SAAS;gCACf,WAAW,EAAE,wDAAwD;6BACtE;yBACF;wBACD,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC;qBACvC;iBACF;aACF;YACD,Q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C,CAAC;YAE5C,wBAAwB;YACxB,MAAM,SAAS,GAAa;gBAC1B,SAAS,QAAQ,EAAE;gBACnB,SAAS,QAAQ,EAAE;aACpB,CAAC;YACF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACtC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;gBACnB,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;gBACtD,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC;oBAAE,SAAS,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;gBACzE,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC;oBAAE,SAAS,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;YAC3E,CAAC;YAED,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,gBAAgB,QAAQ,KAAK,KAAK,CAAC,MAAM,aAAa,UAAU,4BAA4B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;aAC3H,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAG,GAAa,CAAC,OAAO,EAAE,CAAC;QACvE,CAAC;IACH,CAAC;CACF;AA5HD,sCA4HC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notebook Edit Tool — Read and edit Jupyter notebooks (.ipynb files).
|
|
3
|
+
*
|
|
4
|
+
* Supports:
|
|
5
|
+
* - Reading cells (code, markdown, raw)
|
|
6
|
+
* - Editing cell content by index
|
|
7
|
+
* - Inserting new cells
|
|
8
|
+
* - Deleting cells
|
|
9
|
+
* - Changing cell type
|
|
10
|
+
* - Clearing cell outputs
|
|
11
|
+
*/
|
|
12
|
+
import type { BaseTool, ToolDefinition, ToolResult } from "./types";
|
|
13
|
+
import type { SandboxManager } from "../sandbox";
|
|
14
|
+
export declare class NotebookEditTool implements BaseTool {
|
|
15
|
+
definition: ToolDefinition;
|
|
16
|
+
private workingDir;
|
|
17
|
+
private sandboxManager?;
|
|
18
|
+
constructor(workingDir: string, sandboxManager?: SandboxManager);
|
|
19
|
+
execute(input: Record<string, unknown>): Promise<ToolResult>;
|
|
20
|
+
private loadNotebook;
|
|
21
|
+
private saveNotebook;
|
|
22
|
+
private createEmptyNotebook;
|
|
23
|
+
private formatCell;
|
|
24
|
+
private readNotebook;
|
|
25
|
+
private editCell;
|
|
26
|
+
private insertCell;
|
|
27
|
+
private deleteCell;
|
|
28
|
+
private changeType;
|
|
29
|
+
private clearOutputs;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=notebook-edit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notebook-edit.d.ts","sourceRoot":"","sources":["../../src/tools/notebook-edit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAiBjD,qBAAa,gBAAiB,YAAW,QAAQ;IAC/C,UAAU,EAAE,cAAc,CAgDxB;IAEF,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,cAAc,CAAC,CAAiB;gBAE5B,UAAU,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,cAAc;IAKzD,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAiDlE,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,UAAU;IAelB,OAAO,CAAC,YAAY;IAiBpB,OAAO,CAAC,QAAQ;IAoChB,OAAO,CAAC,UAAU;IAkClB,OAAO,CAAC,UAAU;IAoBlB,OAAO,CAAC,UAAU;IAmClB,OAAO,CAAC,YAAY;CAmBrB"}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Notebook Edit Tool — Read and edit Jupyter notebooks (.ipynb files).
|
|
4
|
+
*
|
|
5
|
+
* Supports:
|
|
6
|
+
* - Reading cells (code, markdown, raw)
|
|
7
|
+
* - Editing cell content by index
|
|
8
|
+
* - Inserting new cells
|
|
9
|
+
* - Deleting cells
|
|
10
|
+
* - Changing cell type
|
|
11
|
+
* - Clearing cell outputs
|
|
12
|
+
*/
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.NotebookEditTool = void 0;
|
|
48
|
+
const fs = __importStar(require("fs"));
|
|
49
|
+
const path_safety_1 = require("../utils/path-safety");
|
|
50
|
+
class NotebookEditTool {
|
|
51
|
+
definition = {
|
|
52
|
+
name: "notebook_edit",
|
|
53
|
+
description: `Read and edit Jupyter notebook (.ipynb) files. Supports viewing cells, editing cell content, inserting/deleting cells, and changing cell types.
|
|
54
|
+
|
|
55
|
+
Actions:
|
|
56
|
+
- read: View all cells with their indices, types, and content
|
|
57
|
+
- edit_cell: Replace the content of a cell by index
|
|
58
|
+
- insert_cell: Insert a new cell at a position
|
|
59
|
+
- delete_cell: Remove a cell by index
|
|
60
|
+
- change_type: Change a cell's type (code/markdown/raw)
|
|
61
|
+
- clear_outputs: Clear all cell outputs
|
|
62
|
+
|
|
63
|
+
Use this for working with Jupyter notebooks without corrupting the JSON structure.`,
|
|
64
|
+
inputSchema: {
|
|
65
|
+
type: "object",
|
|
66
|
+
properties: {
|
|
67
|
+
file_path: {
|
|
68
|
+
type: "string",
|
|
69
|
+
description: "Path to the .ipynb notebook file",
|
|
70
|
+
},
|
|
71
|
+
action: {
|
|
72
|
+
type: "string",
|
|
73
|
+
enum: ["read", "edit_cell", "insert_cell", "delete_cell", "change_type", "clear_outputs"],
|
|
74
|
+
description: "Action to perform on the notebook",
|
|
75
|
+
},
|
|
76
|
+
cell_index: {
|
|
77
|
+
type: "number",
|
|
78
|
+
description: "Cell index (0-based) for edit_cell, delete_cell, change_type",
|
|
79
|
+
},
|
|
80
|
+
content: {
|
|
81
|
+
type: "string",
|
|
82
|
+
description: "New cell content (for edit_cell, insert_cell)",
|
|
83
|
+
},
|
|
84
|
+
cell_type: {
|
|
85
|
+
type: "string",
|
|
86
|
+
enum: ["code", "markdown", "raw"],
|
|
87
|
+
description: "Cell type (for insert_cell, change_type). Default: code",
|
|
88
|
+
},
|
|
89
|
+
insert_position: {
|
|
90
|
+
type: "number",
|
|
91
|
+
description: "Position to insert new cell (for insert_cell). Default: end of notebook",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
required: ["file_path", "action"],
|
|
95
|
+
},
|
|
96
|
+
requiresPermission: true,
|
|
97
|
+
permissionMessage: (input) => `Notebook ${input.action}: ${input.file_path}`,
|
|
98
|
+
};
|
|
99
|
+
workingDir;
|
|
100
|
+
sandboxManager;
|
|
101
|
+
constructor(workingDir, sandboxManager) {
|
|
102
|
+
this.workingDir = workingDir;
|
|
103
|
+
this.sandboxManager = sandboxManager;
|
|
104
|
+
}
|
|
105
|
+
async execute(input) {
|
|
106
|
+
let filePath;
|
|
107
|
+
try {
|
|
108
|
+
filePath = (0, path_safety_1.safePath)(input.file_path, this.workingDir);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
return { success: false, output: "", error: err.message };
|
|
112
|
+
}
|
|
113
|
+
const action = input.action;
|
|
114
|
+
// Read action doesn't need write permission
|
|
115
|
+
if (action !== "read") {
|
|
116
|
+
if (this.sandboxManager) {
|
|
117
|
+
const check = this.sandboxManager.checkFileWrite(filePath);
|
|
118
|
+
if (!check.allowed) {
|
|
119
|
+
return { success: false, output: "", error: check.reason || "Sandbox: write access denied" };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (!fs.existsSync(filePath)) {
|
|
124
|
+
if (action === "read") {
|
|
125
|
+
return { success: false, output: "", error: `Notebook not found: ${filePath}` };
|
|
126
|
+
}
|
|
127
|
+
// For write actions on non-existent file, create a new empty notebook
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
switch (action) {
|
|
131
|
+
case "read":
|
|
132
|
+
return this.readNotebook(filePath);
|
|
133
|
+
case "edit_cell":
|
|
134
|
+
return this.editCell(filePath, input);
|
|
135
|
+
case "insert_cell":
|
|
136
|
+
return this.insertCell(filePath, input);
|
|
137
|
+
case "delete_cell":
|
|
138
|
+
return this.deleteCell(filePath, input);
|
|
139
|
+
case "change_type":
|
|
140
|
+
return this.changeType(filePath, input);
|
|
141
|
+
case "clear_outputs":
|
|
142
|
+
return this.clearOutputs(filePath);
|
|
143
|
+
default:
|
|
144
|
+
return { success: false, output: "", error: `Unknown action: ${action}` };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
return { success: false, output: "", error: err.message };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
loadNotebook(filePath) {
|
|
152
|
+
const raw = fs.readFileSync(filePath, "utf-8");
|
|
153
|
+
const nb = JSON.parse(raw);
|
|
154
|
+
if (!nb.cells || !Array.isArray(nb.cells)) {
|
|
155
|
+
throw new Error("Invalid notebook: missing cells array");
|
|
156
|
+
}
|
|
157
|
+
return nb;
|
|
158
|
+
}
|
|
159
|
+
saveNotebook(filePath, nb) {
|
|
160
|
+
fs.writeFileSync(filePath, JSON.stringify(nb, null, 1) + "\n", "utf-8");
|
|
161
|
+
}
|
|
162
|
+
createEmptyNotebook() {
|
|
163
|
+
return {
|
|
164
|
+
nbformat: 4,
|
|
165
|
+
nbformat_minor: 5,
|
|
166
|
+
metadata: {
|
|
167
|
+
kernelspec: { display_name: "Python 3", language: "python", name: "python3" },
|
|
168
|
+
language_info: { name: "python", version: "3.10.0" },
|
|
169
|
+
},
|
|
170
|
+
cells: [],
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
formatCell(cell, index) {
|
|
174
|
+
const source = Array.isArray(cell.source) ? cell.source.join("") : String(cell.source);
|
|
175
|
+
const lines = source.split("\n");
|
|
176
|
+
const preview = lines.length > 10
|
|
177
|
+
? lines.slice(0, 10).join("\n") + `\n... (${lines.length - 10} more lines)`
|
|
178
|
+
: source;
|
|
179
|
+
const outputInfo = cell.cell_type === "code" && cell.outputs && Array.isArray(cell.outputs)
|
|
180
|
+
? ` [${cell.outputs.length} output(s)]`
|
|
181
|
+
: "";
|
|
182
|
+
const execCount = cell.execution_count != null ? ` In[${cell.execution_count}]` : "";
|
|
183
|
+
return `[${index}] ${cell.cell_type}${execCount}${outputInfo}\n${preview}`;
|
|
184
|
+
}
|
|
185
|
+
readNotebook(filePath) {
|
|
186
|
+
const nb = this.loadNotebook(filePath);
|
|
187
|
+
const parts = [
|
|
188
|
+
`Notebook: ${filePath}`,
|
|
189
|
+
`Format: ${nb.nbformat}.${nb.nbformat_minor}`,
|
|
190
|
+
`Cells: ${nb.cells.length}`,
|
|
191
|
+
`---`,
|
|
192
|
+
];
|
|
193
|
+
for (let i = 0; i < nb.cells.length; i++) {
|
|
194
|
+
parts.push(this.formatCell(nb.cells[i], i));
|
|
195
|
+
if (i < nb.cells.length - 1)
|
|
196
|
+
parts.push("");
|
|
197
|
+
}
|
|
198
|
+
return { success: true, output: parts.join("\n") };
|
|
199
|
+
}
|
|
200
|
+
editCell(filePath, input) {
|
|
201
|
+
const nb = this.loadNotebook(filePath);
|
|
202
|
+
const idx = input.cell_index;
|
|
203
|
+
const content = input.content;
|
|
204
|
+
if (idx === undefined || idx === null) {
|
|
205
|
+
return { success: false, output: "", error: "cell_index is required for edit_cell" };
|
|
206
|
+
}
|
|
207
|
+
if (content === undefined) {
|
|
208
|
+
return { success: false, output: "", error: "content is required for edit_cell" };
|
|
209
|
+
}
|
|
210
|
+
if (idx < 0 || idx >= nb.cells.length) {
|
|
211
|
+
return { success: false, output: "", error: `cell_index ${idx} out of range (0-${nb.cells.length - 1})` };
|
|
212
|
+
}
|
|
213
|
+
const oldSource = Array.isArray(nb.cells[idx].source) ? nb.cells[idx].source.join("") : "";
|
|
214
|
+
nb.cells[idx].source = content.split("\n").map((line, i, arr) => i < arr.length - 1 ? line + "\n" : line);
|
|
215
|
+
// Clear outputs for code cells when content changes
|
|
216
|
+
if (nb.cells[idx].cell_type === "code") {
|
|
217
|
+
nb.cells[idx].outputs = [];
|
|
218
|
+
nb.cells[idx].execution_count = null;
|
|
219
|
+
}
|
|
220
|
+
this.saveNotebook(filePath, nb);
|
|
221
|
+
const oldLines = oldSource.split("\n").length;
|
|
222
|
+
const newLines = content.split("\n").length;
|
|
223
|
+
return {
|
|
224
|
+
success: true,
|
|
225
|
+
output: `Edited cell [${idx}] (${nb.cells[idx].cell_type}): ${oldLines} → ${newLines} lines`,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
insertCell(filePath, input) {
|
|
229
|
+
let nb;
|
|
230
|
+
if (fs.existsSync(filePath)) {
|
|
231
|
+
nb = this.loadNotebook(filePath);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
nb = this.createEmptyNotebook();
|
|
235
|
+
}
|
|
236
|
+
const content = input.content || "";
|
|
237
|
+
const cellType = input.cell_type || "code";
|
|
238
|
+
const pos = input.insert_position !== undefined ? input.insert_position : nb.cells.length;
|
|
239
|
+
if (pos < 0 || pos > nb.cells.length) {
|
|
240
|
+
return { success: false, output: "", error: `insert_position ${pos} out of range (0-${nb.cells.length})` };
|
|
241
|
+
}
|
|
242
|
+
const newCell = {
|
|
243
|
+
cell_type: cellType,
|
|
244
|
+
source: content.split("\n").map((line, i, arr) => i < arr.length - 1 ? line + "\n" : line),
|
|
245
|
+
metadata: {},
|
|
246
|
+
...(cellType === "code" ? { outputs: [], execution_count: null } : {}),
|
|
247
|
+
};
|
|
248
|
+
nb.cells.splice(pos, 0, newCell);
|
|
249
|
+
this.saveNotebook(filePath, nb);
|
|
250
|
+
return {
|
|
251
|
+
success: true,
|
|
252
|
+
output: `Inserted ${cellType} cell at position [${pos}] (${nb.cells.length} cells total)`,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
deleteCell(filePath, input) {
|
|
256
|
+
const nb = this.loadNotebook(filePath);
|
|
257
|
+
const idx = input.cell_index;
|
|
258
|
+
if (idx === undefined || idx === null) {
|
|
259
|
+
return { success: false, output: "", error: "cell_index is required for delete_cell" };
|
|
260
|
+
}
|
|
261
|
+
if (idx < 0 || idx >= nb.cells.length) {
|
|
262
|
+
return { success: false, output: "", error: `cell_index ${idx} out of range (0-${nb.cells.length - 1})` };
|
|
263
|
+
}
|
|
264
|
+
const removed = nb.cells.splice(idx, 1)[0];
|
|
265
|
+
this.saveNotebook(filePath, nb);
|
|
266
|
+
return {
|
|
267
|
+
success: true,
|
|
268
|
+
output: `Deleted cell [${idx}] (${removed.cell_type}), ${nb.cells.length} cells remaining`,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
changeType(filePath, input) {
|
|
272
|
+
const nb = this.loadNotebook(filePath);
|
|
273
|
+
const idx = input.cell_index;
|
|
274
|
+
const newType = input.cell_type;
|
|
275
|
+
if (idx === undefined || idx === null) {
|
|
276
|
+
return { success: false, output: "", error: "cell_index is required for change_type" };
|
|
277
|
+
}
|
|
278
|
+
if (!newType) {
|
|
279
|
+
return { success: false, output: "", error: "cell_type is required for change_type" };
|
|
280
|
+
}
|
|
281
|
+
if (idx < 0 || idx >= nb.cells.length) {
|
|
282
|
+
return { success: false, output: "", error: `cell_index ${idx} out of range (0-${nb.cells.length - 1})` };
|
|
283
|
+
}
|
|
284
|
+
const oldType = nb.cells[idx].cell_type;
|
|
285
|
+
nb.cells[idx].cell_type = newType;
|
|
286
|
+
// Add/remove outputs field based on type
|
|
287
|
+
if (newType === "code") {
|
|
288
|
+
if (!nb.cells[idx].outputs)
|
|
289
|
+
nb.cells[idx].outputs = [];
|
|
290
|
+
if (nb.cells[idx].execution_count === undefined)
|
|
291
|
+
nb.cells[idx].execution_count = null;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
delete nb.cells[idx].outputs;
|
|
295
|
+
delete nb.cells[idx].execution_count;
|
|
296
|
+
}
|
|
297
|
+
this.saveNotebook(filePath, nb);
|
|
298
|
+
return {
|
|
299
|
+
success: true,
|
|
300
|
+
output: `Changed cell [${idx}] type: ${oldType} → ${newType}`,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
clearOutputs(filePath) {
|
|
304
|
+
const nb = this.loadNotebook(filePath);
|
|
305
|
+
let cleared = 0;
|
|
306
|
+
for (const cell of nb.cells) {
|
|
307
|
+
if (cell.cell_type === "code" && cell.outputs && cell.outputs.length > 0) {
|
|
308
|
+
cell.outputs = [];
|
|
309
|
+
cell.execution_count = null;
|
|
310
|
+
cleared++;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
this.saveNotebook(filePath, nb);
|
|
314
|
+
return {
|
|
315
|
+
success: true,
|
|
316
|
+
output: `Cleared outputs from ${cleared} code cell(s) in ${filePath}`,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
exports.NotebookEditTool = NotebookEditTool;
|
|
321
|
+
//# sourceMappingURL=notebook-edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notebook-edit.js","sourceRoot":"","sources":["../../src/tools/notebook-edit.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AAEzB,sDAAgD;AAkBhD,MAAa,gBAAgB;IAC3B,UAAU,GAAmB;QAC3B,IAAI,EAAE,eAAe;QACrB,WAAW,EACT;;;;;;;;;;mFAU6E;QAC/E,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd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C,GAAG,CAAC,CAAC,eAAe,KAAK,SAAS;gBAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,eAAe,GAAG,IAAI,CAAC;QACxF,CAAC;aAAM,CAAC;YACN,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;YAC7B,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,eAAe,CAAC;QACvC,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAEhC,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,iBAAiB,GAAG,WAAW,OAAO,MAAM,OAAO,EAAE;SAC9D,CAAC;IACJ,CAAC;IAEO,YAAY,CAAC,QAAgB;QACnC,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,OAAO,GAAG,CAAC,CAAC;QAEhB,KAAK,MAAM,IAAI,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC;YAC5B,IAAI,IAAI,CAAC,SAAS,KAAK,MAAM,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACzE,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;gBAClB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;gBAC5B,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAEhC,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,wBAAwB,OAAO,oBAAoB,QAAQ,EAAE;SACtE,CAAC;IACJ,CAAC;CACF;AArTD,4CAqTC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BaseTool, ToolResult } from "./types";
|
|
2
|
+
/** Central registry of all available tools */
|
|
3
|
+
export declare class ToolRegistry {
|
|
4
|
+
private tools;
|
|
5
|
+
register(tool: BaseTool): void;
|
|
6
|
+
get(name: string): BaseTool | undefined;
|
|
7
|
+
getAll(): BaseTool[];
|
|
8
|
+
getDefinitions(): import("./types").ToolDefinition[];
|
|
9
|
+
execute(name: string, input: Record<string, unknown>): Promise<ToolResult>;
|
|
10
|
+
getToolSchemas(): {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
inputSchema: Record<string, unknown>;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEpD,8CAA8C;AAC9C,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAoC;IAEjD,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAI9B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAIvC,MAAM,IAAI,QAAQ,EAAE;IAIpB,cAAc;IAIR,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAahF,cAAc;;;;;CAOf"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolRegistry = void 0;
|
|
4
|
+
/** Central registry of all available tools */
|
|
5
|
+
class ToolRegistry {
|
|
6
|
+
tools = new Map();
|
|
7
|
+
register(tool) {
|
|
8
|
+
this.tools.set(tool.definition.name, tool);
|
|
9
|
+
}
|
|
10
|
+
get(name) {
|
|
11
|
+
return this.tools.get(name);
|
|
12
|
+
}
|
|
13
|
+
getAll() {
|
|
14
|
+
return Array.from(this.tools.values());
|
|
15
|
+
}
|
|
16
|
+
getDefinitions() {
|
|
17
|
+
return this.getAll().map((t) => t.definition);
|
|
18
|
+
}
|
|
19
|
+
async execute(name, input) {
|
|
20
|
+
const tool = this.tools.get(name);
|
|
21
|
+
if (!tool) {
|
|
22
|
+
return { success: false, output: "", error: `Unknown tool: ${name}` };
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return await tool.execute(input);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
29
|
+
return { success: false, output: "", error: message };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
getToolSchemas() {
|
|
33
|
+
return this.getAll().map((t) => ({
|
|
34
|
+
name: t.definition.name,
|
|
35
|
+
description: t.definition.description,
|
|
36
|
+
inputSchema: t.definition.inputSchema,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.ToolRegistry = ToolRegistry;
|
|
41
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":";;;AAEA,8CAA8C;AAC9C,MAAa,YAAY;IACf,KAAK,GAA0B,IAAI,GAAG,EAAE,CAAC;IAEjD,QAAQ,CAAC,IAAc;QACrB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,KAA8B;QACxD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,iBAAiB,IAAI,EAAE,EAAE,CAAC;QACxE,CAAC;QACD,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QACxD,CAAC;IACH,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/B,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI;YACvB,WAAW,EAAE,CAAC,CAAC,UAAU,CAAC,WAAW;YACrC,WAAW,EAAE,CAAC,CAAC,UAAU,CAAC,WAAW;SACtC,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AAvCD,oCAuCC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BaseTool, ToolDefinition, ToolResult } from "./types";
|
|
2
|
+
import type { SandboxManager } from "../sandbox";
|
|
3
|
+
import type { PermissionManager } from "../permissions";
|
|
4
|
+
export declare class ShellExecTool implements BaseTool {
|
|
5
|
+
definition: ToolDefinition;
|
|
6
|
+
private workingDir;
|
|
7
|
+
private sandboxManager?;
|
|
8
|
+
private permissionManager?;
|
|
9
|
+
constructor(workingDir: string, sandboxManager?: SandboxManager, permissionManager?: PermissionManager);
|
|
10
|
+
execute(input: Record<string, unknown>): Promise<ToolResult>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=shell-exec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-exec.d.ts","sourceRoot":"","sources":["../../src/tools/shell-exec.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAiFxD,qBAAa,aAAc,YAAW,QAAQ;IAC5C,UAAU,EAAE,cAAc,CA6CxB;IAEF,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,cAAc,CAAC,CAAiB;IACxC,OAAO,CAAC,iBAAiB,CAAC,CAAoB;gBAElC,UAAU,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,cAAc,EAAE,iBAAiB,CAAC,EAAE,iBAAiB;IAMhG,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;CA2GnE"}
|