@nanocollective/nanocoder 1.22.5 → 1.23.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 +93 -30
- package/assets/nanocoder-vscode.vsix +0 -0
- package/dist/ai-sdk-client/chat/chat-handler.js +1 -1
- package/dist/ai-sdk-client/chat/chat-handler.js.map +1 -1
- package/dist/ai-sdk-client/chat/tool-processor.d.ts +1 -1
- package/dist/ai-sdk-client/chat/tool-processor.d.ts.map +1 -1
- package/dist/ai-sdk-client/chat/tool-processor.js +8 -3
- package/dist/ai-sdk-client/chat/tool-processor.js.map +1 -1
- package/dist/ai-sdk-client/error-handling/error-parser.d.ts.map +1 -1
- package/dist/ai-sdk-client/error-handling/error-parser.js +4 -1
- package/dist/ai-sdk-client/error-handling/error-parser.js.map +1 -1
- package/dist/app/App.d.ts.map +1 -1
- package/dist/app/App.js +106 -11
- package/dist/app/App.js.map +1 -1
- package/dist/app/components/chat-input.d.ts +6 -1
- package/dist/app/components/chat-input.d.ts.map +1 -1
- package/dist/app/components/chat-input.js +9 -7
- package/dist/app/components/chat-input.js.map +1 -1
- package/dist/app/utils/app-util.d.ts +5 -0
- package/dist/app/utils/app-util.d.ts.map +1 -1
- package/dist/app/utils/app-util.js +265 -0
- package/dist/app/utils/app-util.js.map +1 -1
- package/dist/client-factory.d.ts.map +1 -1
- package/dist/client-factory.js +3 -2
- package/dist/client-factory.js.map +1 -1
- package/dist/commands/context-max.d.ts +15 -0
- package/dist/commands/context-max.d.ts.map +1 -0
- package/dist/commands/context-max.js +22 -0
- package/dist/commands/context-max.js.map +1 -0
- package/dist/commands/custom-commands.d.ts.map +1 -1
- package/dist/commands/custom-commands.js +88 -4
- package/dist/commands/custom-commands.js.map +1 -1
- package/dist/commands/exit.d.ts.map +1 -1
- package/dist/commands/exit.js +5 -8
- package/dist/commands/exit.js.map +1 -1
- package/dist/commands/ide.d.ts +3 -0
- package/dist/commands/ide.d.ts.map +1 -0
- package/dist/commands/ide.js +10 -0
- package/dist/commands/ide.js.map +1 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/schedule.d.ts +3 -0
- package/dist/commands/schedule.d.ts.map +1 -0
- package/dist/commands/schedule.js +177 -0
- package/dist/commands/schedule.js.map +1 -0
- package/dist/commands/usage.d.ts.map +1 -1
- package/dist/commands/usage.js +4 -3
- package/dist/commands/usage.js.map +1 -1
- package/dist/components/development-mode-indicator.d.ts +3 -2
- package/dist/components/development-mode-indicator.d.ts.map +1 -1
- package/dist/components/development-mode-indicator.js +23 -9
- package/dist/components/development-mode-indicator.js.map +1 -1
- package/dist/components/ide-selector.d.ts +7 -0
- package/dist/components/ide-selector.d.ts.map +1 -0
- package/dist/components/ide-selector.js +17 -0
- package/dist/components/ide-selector.js.map +1 -0
- package/dist/components/question-prompt.d.ts +8 -0
- package/dist/components/question-prompt.d.ts.map +1 -0
- package/dist/components/question-prompt.js +58 -0
- package/dist/components/question-prompt.js.map +1 -0
- package/dist/components/scheduler-view.d.ts +14 -0
- package/dist/components/scheduler-view.d.ts.map +1 -0
- package/dist/components/scheduler-view.js +17 -0
- package/dist/components/scheduler-view.js.map +1 -0
- package/dist/components/text-input.d.ts +13 -0
- package/dist/components/text-input.d.ts.map +1 -0
- package/dist/components/text-input.js +175 -0
- package/dist/components/text-input.js.map +1 -0
- package/dist/components/user-input.d.ts +2 -1
- package/dist/components/user-input.d.ts.map +1 -1
- package/dist/components/user-input.js +8 -15
- package/dist/components/user-input.js.map +1 -1
- package/dist/config/themes.d.ts.map +1 -1
- package/dist/config/themes.js +20 -0
- package/dist/config/themes.js.map +1 -1
- package/dist/custom-commands/command-integration.d.ts +24 -0
- package/dist/custom-commands/command-integration.d.ts.map +1 -0
- package/dist/custom-commands/command-integration.js +68 -0
- package/dist/custom-commands/command-integration.js.map +1 -0
- package/dist/custom-commands/executor.d.ts.map +1 -1
- package/dist/custom-commands/executor.js +12 -2
- package/dist/custom-commands/executor.js.map +1 -1
- package/dist/custom-commands/loader.d.ts +33 -5
- package/dist/custom-commands/loader.d.ts.map +1 -1
- package/dist/custom-commands/loader.js +191 -18
- package/dist/custom-commands/loader.js.map +1 -1
- package/dist/custom-commands/parser.d.ts.map +1 -1
- package/dist/custom-commands/parser.js +115 -48
- package/dist/custom-commands/parser.js.map +1 -1
- package/dist/hooks/chat-handler/conversation/conversation-loop.d.ts +1 -1
- package/dist/hooks/chat-handler/conversation/conversation-loop.d.ts.map +1 -1
- package/dist/hooks/chat-handler/conversation/conversation-loop.js +37 -5
- package/dist/hooks/chat-handler/conversation/conversation-loop.js.map +1 -1
- package/dist/hooks/chat-handler/types.d.ts +3 -1
- package/dist/hooks/chat-handler/types.d.ts.map +1 -1
- package/dist/hooks/chat-handler/useChatHandler.d.ts +1 -1
- package/dist/hooks/chat-handler/useChatHandler.d.ts.map +1 -1
- package/dist/hooks/chat-handler/useChatHandler.js +13 -5
- package/dist/hooks/chat-handler/useChatHandler.js.map +1 -1
- package/dist/hooks/useAppHandlers.d.ts +2 -0
- package/dist/hooks/useAppHandlers.d.ts.map +1 -1
- package/dist/hooks/useAppHandlers.js +5 -0
- package/dist/hooks/useAppHandlers.js.map +1 -1
- package/dist/hooks/useAppInitialization.d.ts.map +1 -1
- package/dist/hooks/useAppInitialization.js +4 -1
- package/dist/hooks/useAppInitialization.js.map +1 -1
- package/dist/hooks/useAppState.d.ts +15 -0
- package/dist/hooks/useAppState.d.ts.map +1 -1
- package/dist/hooks/useAppState.js +23 -0
- package/dist/hooks/useAppState.js.map +1 -1
- package/dist/hooks/useContextPercentage.d.ts +17 -0
- package/dist/hooks/useContextPercentage.d.ts.map +1 -0
- package/dist/hooks/useContextPercentage.js +71 -0
- package/dist/hooks/useContextPercentage.js.map +1 -0
- package/dist/hooks/useModeHandlers.d.ts +4 -1
- package/dist/hooks/useModeHandlers.d.ts.map +1 -1
- package/dist/hooks/useModeHandlers.js +11 -1
- package/dist/hooks/useModeHandlers.js.map +1 -1
- package/dist/hooks/useNonInteractiveMode.d.ts.map +1 -1
- package/dist/hooks/useNonInteractiveMode.js +3 -1
- package/dist/hooks/useNonInteractiveMode.js.map +1 -1
- package/dist/hooks/useSchedulerMode.d.ts +30 -0
- package/dist/hooks/useSchedulerMode.d.ts.map +1 -0
- package/dist/hooks/useSchedulerMode.js +99 -0
- package/dist/hooks/useSchedulerMode.js.map +1 -0
- package/dist/lsp/lsp-manager.d.ts.map +1 -1
- package/dist/lsp/lsp-manager.js +10 -0
- package/dist/lsp/lsp-manager.js.map +1 -1
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +20 -1
- package/dist/mcp/mcp-client.js.map +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +1 -1
- package/dist/models/index.js.map +1 -1
- package/dist/models/models-dev-client.d.ts +8 -1
- package/dist/models/models-dev-client.d.ts.map +1 -1
- package/dist/models/models-dev-client.js +50 -1
- package/dist/models/models-dev-client.js.map +1 -1
- package/dist/schedule/cron.d.ts +14 -0
- package/dist/schedule/cron.d.ts.map +1 -0
- package/dist/schedule/cron.js +107 -0
- package/dist/schedule/cron.js.map +1 -0
- package/dist/schedule/index.d.ts +4 -0
- package/dist/schedule/index.d.ts.map +1 -0
- package/dist/schedule/index.js +4 -0
- package/dist/schedule/index.js.map +1 -0
- package/dist/schedule/runner.d.ts +42 -0
- package/dist/schedule/runner.d.ts.map +1 -0
- package/dist/schedule/runner.js +136 -0
- package/dist/schedule/runner.js.map +1 -0
- package/dist/schedule/storage.d.ts +9 -0
- package/dist/schedule/storage.d.ts.map +1 -0
- package/dist/schedule/storage.js +68 -0
- package/dist/schedule/storage.js.map +1 -0
- package/dist/schedule/types.d.ts +24 -0
- package/dist/schedule/types.d.ts.map +1 -0
- package/dist/schedule/types.js +2 -0
- package/dist/schedule/types.js.map +1 -0
- package/dist/services/bash-executor.d.ts.map +1 -1
- package/dist/services/bash-executor.js +5 -0
- package/dist/services/bash-executor.js.map +1 -1
- package/dist/tool-calling/json-parser.d.ts +7 -3
- package/dist/tool-calling/json-parser.d.ts.map +1 -1
- package/dist/tool-calling/json-parser.js +30 -13
- package/dist/tool-calling/json-parser.js.map +1 -1
- package/dist/tool-calling/tool-parser.d.ts +2 -2
- package/dist/tool-calling/tool-parser.d.ts.map +1 -1
- package/dist/tool-calling/tool-parser.js +27 -23
- package/dist/tool-calling/tool-parser.js.map +1 -1
- package/dist/tool-calling/xml-parser.d.ts +8 -4
- package/dist/tool-calling/xml-parser.d.ts.map +1 -1
- package/dist/tool-calling/xml-parser.js +15 -5
- package/dist/tool-calling/xml-parser.js.map +1 -1
- package/dist/tools/ask-question.d.ts +3 -0
- package/dist/tools/ask-question.d.ts.map +1 -0
- package/dist/tools/ask-question.js +66 -0
- package/dist/tools/ask-question.js.map +1 -0
- package/dist/tools/execute-bash.js +1 -1
- package/dist/tools/execute-bash.js.map +1 -1
- package/dist/tools/file-ops/copy-file.d.ts +3 -0
- package/dist/tools/file-ops/copy-file.d.ts.map +1 -0
- package/dist/tools/file-ops/copy-file.js +126 -0
- package/dist/tools/file-ops/copy-file.js.map +1 -0
- package/dist/tools/file-ops/create-directory.d.ts +3 -0
- package/dist/tools/file-ops/create-directory.d.ts.map +1 -0
- package/dist/tools/file-ops/create-directory.js +76 -0
- package/dist/tools/file-ops/create-directory.js.map +1 -0
- package/dist/tools/file-ops/delete-file.d.ts +3 -0
- package/dist/tools/file-ops/delete-file.d.ts.map +1 -0
- package/dist/tools/file-ops/delete-file.js +88 -0
- package/dist/tools/file-ops/delete-file.js.map +1 -0
- package/dist/tools/file-ops/index.d.ts +3 -0
- package/dist/tools/file-ops/index.d.ts.map +1 -0
- package/dist/tools/file-ops/index.js +8 -0
- package/dist/tools/file-ops/index.js.map +1 -0
- package/dist/tools/file-ops/move-file.d.ts +3 -0
- package/dist/tools/file-ops/move-file.d.ts.map +1 -0
- package/dist/tools/file-ops/move-file.js +126 -0
- package/dist/tools/file-ops/move-file.js.map +1 -0
- package/dist/tools/file-ops/string-replace.d.ts +3 -0
- package/dist/tools/file-ops/string-replace.d.ts.map +1 -0
- package/dist/tools/{string-replace.js → file-ops/string-replace.js} +13 -13
- package/dist/tools/file-ops/string-replace.js.map +1 -0
- package/dist/tools/file-ops/write-file.d.ts +3 -0
- package/dist/tools/file-ops/write-file.d.ts.map +1 -0
- package/dist/tools/{write-file.js → file-ops/write-file.js} +31 -17
- package/dist/tools/file-ops/write-file.js.map +1 -0
- package/dist/tools/git/git-reset.js +1 -1
- package/dist/tools/git/git-reset.js.map +1 -1
- package/dist/tools/git/index.js +3 -3
- package/dist/tools/git/index.js.map +1 -1
- package/dist/tools/git/utils.d.ts +4 -0
- package/dist/tools/git/utils.d.ts.map +1 -1
- package/dist/tools/git/utils.js +12 -0
- package/dist/tools/git/utils.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +8 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/search-file-contents.d.ts.map +1 -1
- package/dist/tools/search-file-contents.js +59 -10
- package/dist/tools/search-file-contents.js.map +1 -1
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +9 -0
- package/dist/tools/tool-manager.js.map +1 -1
- package/dist/types/app.d.ts +2 -0
- package/dist/types/app.d.ts.map +1 -1
- package/dist/types/commands.d.ts +20 -0
- package/dist/types/commands.d.ts.map +1 -1
- package/dist/types/core.d.ts +2 -1
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/core.js +7 -0
- package/dist/types/core.js.map +1 -1
- package/dist/types/ui.d.ts +1 -1
- package/dist/types/ui.d.ts.map +1 -1
- package/dist/utils/auto-compact.d.ts.map +1 -1
- package/dist/utils/auto-compact.js +13 -7
- package/dist/utils/auto-compact.js.map +1 -1
- package/dist/utils/logging/index.d.ts.map +1 -1
- package/dist/utils/logging/index.js +18 -30
- package/dist/utils/logging/index.js.map +1 -1
- package/dist/utils/question-queue.d.ts +15 -0
- package/dist/utils/question-queue.d.ts.map +1 -0
- package/dist/utils/question-queue.js +25 -0
- package/dist/utils/question-queue.js.map +1 -0
- package/dist/utils/response-formatter.d.ts +108 -0
- package/dist/utils/response-formatter.d.ts.map +1 -0
- package/dist/utils/response-formatter.js +387 -0
- package/dist/utils/response-formatter.js.map +1 -0
- package/dist/utils/shutdown/index.d.ts +7 -0
- package/dist/utils/shutdown/index.d.ts.map +1 -0
- package/dist/utils/shutdown/index.js +6 -0
- package/dist/utils/shutdown/index.js.map +1 -0
- package/dist/utils/shutdown/shutdown-manager.d.ts +19 -0
- package/dist/utils/shutdown/shutdown-manager.d.ts.map +1 -0
- package/dist/utils/shutdown/shutdown-manager.js +100 -0
- package/dist/utils/shutdown/shutdown-manager.js.map +1 -0
- package/dist/utils/shutdown/types.d.ts +9 -0
- package/dist/utils/shutdown/types.d.ts.map +1 -0
- package/dist/utils/shutdown/types.js +2 -0
- package/dist/utils/shutdown/types.js.map +1 -0
- package/dist/utils/type-helpers.d.ts +140 -0
- package/dist/utils/type-helpers.d.ts.map +1 -0
- package/dist/utils/type-helpers.js +220 -0
- package/dist/utils/type-helpers.js.map +1 -0
- package/dist/utils/url-utils.d.ts +6 -0
- package/dist/utils/url-utils.d.ts.map +1 -0
- package/dist/utils/url-utils.js +22 -0
- package/dist/utils/url-utils.js.map +1 -0
- package/dist/vscode/vscode-server.d.ts.map +1 -1
- package/dist/vscode/vscode-server.js +10 -0
- package/dist/vscode/vscode-server.js.map +1 -1
- package/dist/wizards/steps/mcp-step.js +1 -1
- package/dist/wizards/steps/mcp-step.js.map +1 -1
- package/dist/wizards/steps/provider-step.js +1 -1
- package/dist/wizards/steps/provider-step.js.map +1 -1
- package/dist/wizards/templates/mcp-templates.d.ts.map +1 -1
- package/dist/wizards/templates/mcp-templates.js +8 -6
- package/dist/wizards/templates/mcp-templates.js.map +1 -1
- package/dist/wizards/validation.d.ts.map +1 -1
- package/dist/wizards/validation.js +2 -3
- package/dist/wizards/validation.js.map +1 -1
- package/package.json +8 -17
- package/source/app/prompts/main-prompt.md +21 -3
- package/dist/hooks/chat-handler/utils/context-checker.d.ts +0 -15
- package/dist/hooks/chat-handler/utils/context-checker.d.ts.map +0 -1
- package/dist/hooks/chat-handler/utils/context-checker.js +0 -68
- package/dist/hooks/chat-handler/utils/context-checker.js.map +0 -1
- package/dist/tools/string-replace.d.ts +0 -3
- package/dist/tools/string-replace.d.ts.map +0 -1
- package/dist/tools/string-replace.js.map +0 -1
- package/dist/tools/write-file.d.ts +0 -3
- package/dist/tools/write-file.d.ts.map +0 -1
- package/dist/tools/write-file.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-parser.js","sourceRoot":"","sources":["../../source/tool-calling/tool-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,2BAA2B,EAC3B,kBAAkB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-parser.js","sourceRoot":"","sources":["../../source/tool-calling/tool-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,2BAA2B,EAC3B,kBAAkB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAElD;;GAEG;AACH,SAAS,cAAc,CAAC,OAAe;IACtC,OAAO,CACN,OAAO;QACN,yBAAyB;SACxB,OAAO,CAAC,4BAA4B,EAAE,EAAE,CAAC;QAC1C,uCAAuC;SACtC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAC5B,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,mBA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;IAC9B,mEAAmE;IACnE,sFAAsF;IACtF,MAAM,SAAS,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAAC;IACtD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,cAAc,GAAG,kBAAkB,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;QACtE,OAAO;YACN,OAAO,EAAE,IAAI;YACb,SAAS,EAAE,SAAS;YACpB,cAAc;SACd,CAAC;IACH,CAAC;IAED,2DAA2D;IAC3D,MAAM,aAAa,GAAG,2BAA2B,CAAC,eAAe,CAAC,CAAC;IACnE,IAAI,aAAa,EAAE,CAAC;QACnB,OAAO;YACN,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,aAAa,CAAC,KAAK;YAC1B,QAAQ,EAAE,aAAa,CAAC,QAAQ;SAChC,CAAC;IACH,CAAC;IAED,iEAAiE;IACjE,OAAO;QACN,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,EAAE;QACb,cAAc,EAAE,mBAAmB,CAAC,eAAe,CAAC;KACpD,CAAC;AACH,CAAC"}
|
|
@@ -12,8 +12,9 @@ export declare class XMLToolCallParser {
|
|
|
12
12
|
private static readonly PARAMETER_REGEX;
|
|
13
13
|
/**
|
|
14
14
|
* Extracts tool calls from text content containing XML-formatted tool calls
|
|
15
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
15
16
|
*/
|
|
16
|
-
static parseToolCalls(content:
|
|
17
|
+
static parseToolCalls(content: unknown): ParsedToolCall[];
|
|
17
18
|
/**
|
|
18
19
|
* Validates that a matched string is a proper tool call
|
|
19
20
|
* Rejects partial matches, malformed syntax, and invalid structures
|
|
@@ -29,17 +30,20 @@ export declare class XMLToolCallParser {
|
|
|
29
30
|
static convertToToolCalls(parsedCalls: ParsedToolCall[]): ToolCall[];
|
|
30
31
|
/**
|
|
31
32
|
* Removes XML tool call blocks from content, leaving only the text
|
|
33
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
32
34
|
*/
|
|
33
|
-
static removeToolCallsFromContent(content:
|
|
35
|
+
static removeToolCallsFromContent(content: unknown): string;
|
|
34
36
|
/**
|
|
35
37
|
* Checks if content contains XML-formatted tool calls
|
|
38
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
36
39
|
*/
|
|
37
|
-
static hasToolCalls(content:
|
|
40
|
+
static hasToolCalls(content: unknown): boolean;
|
|
38
41
|
/**
|
|
39
42
|
* Detects malformed XML tool call attempts and returns error details
|
|
40
43
|
* Returns null if no malformed tool calls detected
|
|
44
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
41
45
|
*/
|
|
42
|
-
static detectMalformedToolCall(content:
|
|
46
|
+
static detectMalformedToolCall(content: unknown): {
|
|
43
47
|
error: string;
|
|
44
48
|
examples: string;
|
|
45
49
|
} | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-parser.d.ts","sourceRoot":"","sources":["../../source/tool-calling/xml-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"xml-parser.d.ts","sourceRoot":"","sources":["../../source/tool-calling/xml-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAG5C,UAAU,cAAc;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAA0B;IACjE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAA0B;IAEjE;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,EAAE;IA0CzD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAyE9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAyB9B;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,QAAQ,EAAE;IAUpE;;;OAGG;IACH,MAAM,CAAC,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;IA4C3D;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IAM9C;;;;OAIG;IACH,MAAM,CAAC,uBAAuB,CAC7B,OAAO,EAAE,OAAO,GACd;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAC,GAAG,IAAI;IAiD3C;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,wBAAwB;CAGvC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ensureString } from '../utils/type-helpers.js';
|
|
1
2
|
/**
|
|
2
3
|
* Parses XML-formatted tool calls from non-function-calling models
|
|
3
4
|
* Expected format: <tool_name><param1>value1</param1><param2>value2</param2></tool_name>
|
|
@@ -7,13 +8,14 @@ export class XMLToolCallParser {
|
|
|
7
8
|
static PARAMETER_REGEX = /<(\w+)>(.*?)<\/\1>/gs;
|
|
8
9
|
/**
|
|
9
10
|
* Extracts tool calls from text content containing XML-formatted tool calls
|
|
11
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
10
12
|
*/
|
|
11
13
|
static parseToolCalls(content) {
|
|
12
14
|
const toolCalls = [];
|
|
13
15
|
let match;
|
|
14
16
|
// Handle content that might be wrapped in markdown code blocks
|
|
15
|
-
let processedContent = content;
|
|
16
|
-
const codeBlockMatch =
|
|
17
|
+
let processedContent = ensureString(content);
|
|
18
|
+
const codeBlockMatch = processedContent.match(/```(?:\w+)?\s*\n?([\s\S]*?)\n?```/);
|
|
17
19
|
if (codeBlockMatch && codeBlockMatch[1]) {
|
|
18
20
|
processedContent = codeBlockMatch[1].trim();
|
|
19
21
|
}
|
|
@@ -142,15 +144,18 @@ export class XMLToolCallParser {
|
|
|
142
144
|
}
|
|
143
145
|
/**
|
|
144
146
|
* Removes XML tool call blocks from content, leaving only the text
|
|
147
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
145
148
|
*/
|
|
146
149
|
static removeToolCallsFromContent(content) {
|
|
147
|
-
let cleanedContent = content;
|
|
150
|
+
let cleanedContent = ensureString(content);
|
|
148
151
|
// Remove all markdown code blocks that contain XML tool calls (using global flag)
|
|
149
152
|
cleanedContent = cleanedContent.replace(/```(?:\w+)?\s*\n?([\s\S]*?)\n?```/g, (match, blockContent) => {
|
|
150
153
|
if (blockContent) {
|
|
151
154
|
// Reset regex and check if this block contains XML tool calls
|
|
152
155
|
this.TOOL_CALL_REGEX.lastIndex = 0;
|
|
153
|
-
|
|
156
|
+
const testResult = this.TOOL_CALL_REGEX.test(blockContent);
|
|
157
|
+
this.TOOL_CALL_REGEX.lastIndex = 0; // Reset again after test
|
|
158
|
+
if (testResult) {
|
|
154
159
|
// This code block contains XML tool calls, remove it entirely
|
|
155
160
|
return '';
|
|
156
161
|
}
|
|
@@ -178,6 +183,7 @@ export class XMLToolCallParser {
|
|
|
178
183
|
}
|
|
179
184
|
/**
|
|
180
185
|
* Checks if content contains XML-formatted tool calls
|
|
186
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
181
187
|
*/
|
|
182
188
|
static hasToolCalls(content) {
|
|
183
189
|
// Use parseToolCalls with validation to ensure we only detect valid tool calls
|
|
@@ -187,8 +193,12 @@ export class XMLToolCallParser {
|
|
|
187
193
|
/**
|
|
188
194
|
* Detects malformed XML tool call attempts and returns error details
|
|
189
195
|
* Returns null if no malformed tool calls detected
|
|
196
|
+
* Type-preserving: Accepts unknown type, converts to string for processing
|
|
190
197
|
*/
|
|
191
198
|
static detectMalformedToolCall(content) {
|
|
199
|
+
// Type guard: ensure content is string for processing operations
|
|
200
|
+
// BUT original type is preserved in memory via the ToolCall structure
|
|
201
|
+
const contentStr = ensureString(content);
|
|
192
202
|
// Common malformed patterns
|
|
193
203
|
const patterns = [
|
|
194
204
|
{
|
|
@@ -218,7 +228,7 @@ export class XMLToolCallParser {
|
|
|
218
228
|
},
|
|
219
229
|
];
|
|
220
230
|
for (const pattern of patterns) {
|
|
221
|
-
const match =
|
|
231
|
+
const match = contentStr.match(pattern.regex);
|
|
222
232
|
if (match) {
|
|
223
233
|
return {
|
|
224
234
|
error: pattern.error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-parser.js","sourceRoot":"","sources":["../../source/tool-calling/xml-parser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xml-parser.js","sourceRoot":"","sources":["../../source/tool-calling/xml-parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAOlD;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IACrB,MAAM,CAAU,eAAe,GAAG,sBAAsB,CAAC;IACzD,MAAM,CAAU,eAAe,GAAG,sBAAsB,CAAC;IAEjE;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,OAAgB;QACrC,MAAM,SAAS,GAAqB,EAAE,CAAC;QACvC,IAAI,KAAK,CAAC;QAEV,+DAA+D;QAC/D,IAAI,gBAAgB,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QAC7C,MAAM,cAAc,GAAG,gBAAgB,CAAC,KAAK,CAC5C,mCAAmC,CACnC,CAAC;QACF,IAAI,cAAc,IAAI,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;YACzC,gBAAgB,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC7C,CAAC;QAED,6CAA6C;QAC7C,gBAAgB,GAAG,gBAAgB,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAE1E,4BAA4B;QAC5B,IAAI,CAAC,eAAe,CAAC,SAAS,GAAG,C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AAK,EACJ,6EAA6E;aAC9E;SACD,CAAC;QAEF,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAChC,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC9C,IAAI,KAAK,EAAE,CAAC;gBACX,OAAO;oBACN,KAAK,EAAE,OAAO,CAAC,KAAK;oBACpB,QAAQ,EAAE,IAAI,CAAC,wBAAwB,EAAE;iBACzC,CAAC;YACH,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,wBAAwB;QACtC,OAAO,qKAAqK,CAAC;IAC9K,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-question.d.ts","sourceRoot":"","sources":["../../source/tools/ask-question.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAuGtD,eAAO,MAAM,eAAe,EAAE,mBAI7B,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import ToolMessage from '../components/tool-message.js';
|
|
5
|
+
import { ThemeContext } from '../hooks/useTheme.js';
|
|
6
|
+
import { jsonSchema, tool } from '../types/core.js';
|
|
7
|
+
import { signalQuestion } from '../utils/question-queue.js';
|
|
8
|
+
const executeAskQuestion = async (args) => {
|
|
9
|
+
const { question, options, allowFreeform = true } = args;
|
|
10
|
+
if (!options || options.length < 2 || options.length > 4) {
|
|
11
|
+
return 'Error: ⚒ options must contain 2-4 items.';
|
|
12
|
+
}
|
|
13
|
+
const answer = await signalQuestion({
|
|
14
|
+
question,
|
|
15
|
+
options,
|
|
16
|
+
allowFreeform,
|
|
17
|
+
});
|
|
18
|
+
return answer;
|
|
19
|
+
};
|
|
20
|
+
const askQuestionCoreTool = tool({
|
|
21
|
+
description: 'Ask the user a question with selectable options. Use when you need clarification, a decision between approaches, or user preference. The user sees the question with clickable options and can optionally type a custom answer. Returns the selected answer as a string. IMPORTANT: Never re-ask a question the user has already answered. Accept their response and proceed.',
|
|
22
|
+
inputSchema: jsonSchema({
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
question: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'The question to ask the user.',
|
|
28
|
+
},
|
|
29
|
+
options: {
|
|
30
|
+
type: 'array',
|
|
31
|
+
items: { type: 'string' },
|
|
32
|
+
description: '2-4 selectable answer options for the user to choose from.',
|
|
33
|
+
},
|
|
34
|
+
allowFreeform: {
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
description: 'If true (default), adds a "Type custom answer..." option so the user can provide their own response.',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
required: ['question', 'options'],
|
|
40
|
+
}),
|
|
41
|
+
needsApproval: false,
|
|
42
|
+
execute: async (args, _options) => {
|
|
43
|
+
return await executeAskQuestion(args);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
const AskQuestionFormatter = React.memo(({ args, result }) => {
|
|
47
|
+
const themeContext = React.useContext(ThemeContext);
|
|
48
|
+
if (!themeContext) {
|
|
49
|
+
throw new Error('ThemeContext not found');
|
|
50
|
+
}
|
|
51
|
+
const { colors } = themeContext;
|
|
52
|
+
const messageContent = (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: colors.tool, children: "\u2692 ask_user" }), _jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { color: colors.secondary, children: "Question:" }), _jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: colors.text, children: args.question }) })] }), result && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: colors.secondary, children: "Answer:" }), _jsx(Box, { marginLeft: 2, children: _jsx(Text, { color: colors.text, children: result }) })] }))] }));
|
|
53
|
+
return _jsx(ToolMessage, { message: messageContent, hideBox: true });
|
|
54
|
+
});
|
|
55
|
+
const askQuestionFormatter = (args, result) => {
|
|
56
|
+
if (result && result.startsWith('Error:')) {
|
|
57
|
+
return _jsx(_Fragment, {});
|
|
58
|
+
}
|
|
59
|
+
return _jsx(AskQuestionFormatter, { args: args, result: result });
|
|
60
|
+
};
|
|
61
|
+
export const askQuestionTool = {
|
|
62
|
+
name: 'ask_user',
|
|
63
|
+
tool: askQuestionCoreTool,
|
|
64
|
+
formatter: askQuestionFormatter,
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=ask-question.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-question.js","sourceRoot":"","sources":["../../source/tools/ask-question.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AAQtD,MAAM,kBAAkB,GAAG,KAAK,EAAE,IAAqB,EAAmB,EAAE;IAC3E,MAAM,EAAC,QAAQ,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,EAAC,GAAG,IAAI,CAAC;IAEvD,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1D,OAAO,0CAA0C,CAAC;IACnD,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC;QACnC,QAAQ;QACR,OAAO;QACP,aAAa;KACb,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AACf,CAAC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KAAC,GAAG,IAAC,UAAU,EAAE,CAAC,YACjB,KAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,IAAI,YAAG,IAAI,CAAC,QAAQ,GAAQ,GAC3C,IACD,EACL,MAAM,IAAI,CACV,MAAC,GAAG,IAAC,aAAa,EAAC,QAAQ,aAC1B,KAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,SAAS,wBAAgB,EAC7C,KAAC,GAAG,IAAC,UAAU,EAAE,CAAC,YACjB,KAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,IAAI,YAAG,MAAM,GAAQ,GACpC,IACD,CACN,IACI,CACN,CAAC;IAEF,OAAO,KAAC,WAAW,IAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,IAAI,GAAI,CAAC;AAChE,CAAC,CACD,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAC5B,IAAqB,EACrB,MAAe,EACM,EAAE;IACvB,IAAI,MAAM,IAAI,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3C,OAAO,mBAAK,CAAC;IACd,CAAC;IACD,OAAO,KAAC,oBAAoB,IAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAI,CAAC;AAC7D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAwB;IACnD,IAAI,EAAE,UAAmB;IACzB,IAAI,EAAE,mBAAmB;IACzB,SAAS,EAAE,oBAAoB;CAC/B,CAAC"}
|
|
@@ -79,7 +79,7 @@ const executeBashCoreTool = tool({
|
|
|
79
79
|
*/
|
|
80
80
|
function ExecuteBashFormatterComponent({ command, }) {
|
|
81
81
|
const { colors } = useTheme();
|
|
82
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: colors.tool, children: "\u2692 execute_bash" }), _jsxs(Box, { children: [_jsx(Text, { color: colors.secondary, children: "Command: " }), _jsx(Box, { marginLeft: 1, children: _jsx(Text, { color: colors.primary, children: command }) })] })] }));
|
|
82
|
+
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { color: colors.tool, children: "\u2692 execute_bash" }), _jsxs(Box, { children: [_jsx(Text, { color: colors.secondary, children: "Command: " }), _jsx(Box, { marginLeft: 1, children: _jsx(Text, { color: colors.primary, children: command }) })] })] }));
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Regular formatter - called for tool confirmation preview
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute-bash.js","sourceRoot":"","sources":["../../source/tools/execute-bash.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAC;AAG9B,OAAO,YAAY,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAC,4BAA4B,EAAC,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAC,uBAAuB,EAAC,MAAM,aAAa,CAAC;AACpD,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAA0B,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAE/E,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAIjD,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAA0B;IAChE,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,MAAM,YAAY,GACjB,MAAM,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,cAAc,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAEnE,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACnB,UAAU,GAAG,GAAG,YAAY,YAAY,MAAM,CAAC,MAAM,cAAc,MAAM,CAAC,UAAU,EAAE,CAAC;IACxF,CA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AE,6BAA6B;QACrD,OAAO,EAAE,oBAAoB;QAC7B,WAAW,EAAE,oBAAoB;QACjC,cAAc,EAAE,YAAY;QAC5B,qBAAqB,EAAE,8BAA8B;QACrD,mBAAmB,EAAE,qCAAqC;KAC1D,CAAC;IAEF,KAAK,MAAM,OAAO,IAAI,iBAAiB,EAAE,CAAC;QACzC,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,OAAO,OAAO,CAAC,OAAO,CAAC;gBACtB,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,0DAA0D,OAAO,wCAAwC;aAChH,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED,OAAO,OAAO,CAAC,OAAO,CAAC,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAwB;IACnD,IAAI,EAAE,cAAuB;IAC7B,IAAI,EAAE,mBAAmB;IACzB,SAAS,EAAE,oBAAoB;IAC/B,kBAAkB,EAAE,6BAA6B;IACjD,SAAS,EAAE,oBAAoB;CAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-file.d.ts","sourceRoot":"","sources":["../../../source/tools/file-ops/copy-file.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AA8JtD,eAAO,MAAM,YAAY,EAAE,mBAK1B,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { access, copyFile, stat } from 'node:fs/promises';
|
|
4
|
+
import { dirname, resolve } from 'node:path';
|
|
5
|
+
import { Box, Text } from 'ink';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import ToolMessage from '../../components/tool-message.js';
|
|
8
|
+
import { isNanocoderToolAlwaysAllowed } from '../../config/nanocoder-tools-config.js';
|
|
9
|
+
import { getCurrentMode } from '../../context/mode-context.js';
|
|
10
|
+
import { ThemeContext } from '../../hooks/useTheme.js';
|
|
11
|
+
import { jsonSchema, tool } from '../../types/core.js';
|
|
12
|
+
import { invalidateCache } from '../../utils/file-cache.js';
|
|
13
|
+
import { isValidFilePath, resolveFilePath } from '../../utils/path-validation.js';
|
|
14
|
+
const executeCopyFile = async (args) => {
|
|
15
|
+
const srcAbsPath = resolve(args.source);
|
|
16
|
+
const destAbsPath = resolve(args.destination);
|
|
17
|
+
await copyFile(srcAbsPath, destAbsPath);
|
|
18
|
+
invalidateCache(destAbsPath);
|
|
19
|
+
return `File copied: ${args.source} → ${args.destination}`;
|
|
20
|
+
};
|
|
21
|
+
const copyFileCoreTool = tool({
|
|
22
|
+
description: 'Copy a file to a new location. Use this instead of execute_bash with cp.',
|
|
23
|
+
inputSchema: jsonSchema({
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
source: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
description: 'The relative path of the file to copy.',
|
|
29
|
+
},
|
|
30
|
+
destination: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
description: 'The relative path for the copy.',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
required: ['source', 'destination'],
|
|
36
|
+
}),
|
|
37
|
+
needsApproval: () => {
|
|
38
|
+
if (isNanocoderToolAlwaysAllowed('copy_file')) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const mode = getCurrentMode();
|
|
42
|
+
return mode !== 'auto-accept';
|
|
43
|
+
},
|
|
44
|
+
execute: async (args, _options) => {
|
|
45
|
+
return await executeCopyFile(args);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const CopyFileFormatter = React.memo(({ args, result }) => {
|
|
49
|
+
const themeContext = React.useContext(ThemeContext);
|
|
50
|
+
if (!themeContext) {
|
|
51
|
+
throw new Error('ThemeContext is required');
|
|
52
|
+
}
|
|
53
|
+
const { colors } = themeContext;
|
|
54
|
+
const messageContent = (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: colors.tool, children: "\u2692 copy_file" }), _jsxs(Box, { children: [_jsx(Text, { color: colors.secondary, children: "Source: " }), _jsx(Text, { color: colors.text, children: args.source })] }), _jsxs(Box, { children: [_jsx(Text, { color: colors.secondary, children: "Destination: " }), _jsx(Text, { color: colors.text, children: args.destination })] }), result && (_jsxs(Box, { children: [_jsx(Text, { color: colors.secondary, children: "Result: " }), _jsx(Text, { color: colors.text, children: result })] }))] }));
|
|
55
|
+
return _jsx(ToolMessage, { message: messageContent, hideBox: true });
|
|
56
|
+
});
|
|
57
|
+
const copyFileFormatter = (args, result) => {
|
|
58
|
+
return _jsx(CopyFileFormatter, { args: args, result: result });
|
|
59
|
+
};
|
|
60
|
+
const copyFileValidator = async (args) => {
|
|
61
|
+
// Validate source path
|
|
62
|
+
if (!isValidFilePath(args.source)) {
|
|
63
|
+
return {
|
|
64
|
+
valid: false,
|
|
65
|
+
error: `⚒ Invalid source path: "${args.source}". Path must be relative and within the project directory.`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// Validate destination path
|
|
69
|
+
if (!isValidFilePath(args.destination)) {
|
|
70
|
+
return {
|
|
71
|
+
valid: false,
|
|
72
|
+
error: `⚒ Invalid destination path: "${args.destination}". Path must be relative and within the project directory.`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const cwd = process.cwd();
|
|
77
|
+
resolveFilePath(args.source, cwd);
|
|
78
|
+
resolveFilePath(args.destination, cwd);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
82
|
+
return {
|
|
83
|
+
valid: false,
|
|
84
|
+
error: `⚒ Path validation failed: ${errorMessage}`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// Check source exists
|
|
88
|
+
const srcAbsPath = resolve(args.source);
|
|
89
|
+
try {
|
|
90
|
+
await access(srcAbsPath, constants.F_OK);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return {
|
|
94
|
+
valid: false,
|
|
95
|
+
error: `⚒ Source file does not exist: "${args.source}"`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Check source is a file
|
|
99
|
+
const fileStat = await stat(srcAbsPath);
|
|
100
|
+
if (fileStat.isDirectory()) {
|
|
101
|
+
return {
|
|
102
|
+
valid: false,
|
|
103
|
+
error: `⚒ Source is a directory, not a file: "${args.source}"`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// Check destination parent directory exists
|
|
107
|
+
const destAbsPath = resolve(args.destination);
|
|
108
|
+
const parentDir = dirname(destAbsPath);
|
|
109
|
+
try {
|
|
110
|
+
await access(parentDir, constants.F_OK);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return {
|
|
114
|
+
valid: false,
|
|
115
|
+
error: `⚒ Destination parent directory does not exist: "${parentDir}"`,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return { valid: true };
|
|
119
|
+
};
|
|
120
|
+
export const copyFileTool = {
|
|
121
|
+
name: 'copy_file',
|
|
122
|
+
tool: copyFileCoreTool,
|
|
123
|
+
formatter: copyFileFormatter,
|
|
124
|
+
validator: copyFileValidator,
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=copy-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-file.js","sourceRoot":"","sources":["../../../source/tools/file-ops/copy-file.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAClC,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAC,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAC,GAAG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AC,MAAM,cAAc,CAAC;AAyGtD,eAAO,MAAM,mBAAmB,EAAE,mBAKjC,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { mkdir } from 'node:fs/promises';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { Box, Text } from 'ink';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import ToolMessage from '../../components/tool-message.js';
|
|
8
|
+
import { ThemeContext } from '../../hooks/useTheme.js';
|
|
9
|
+
import { jsonSchema, tool } from '../../types/core.js';
|
|
10
|
+
import { isValidFilePath, resolveFilePath } from '../../utils/path-validation.js';
|
|
11
|
+
const executeCreateDirectory = async (args) => {
|
|
12
|
+
const absPath = resolve(args.path);
|
|
13
|
+
const alreadyExists = existsSync(absPath);
|
|
14
|
+
await mkdir(absPath, { recursive: true });
|
|
15
|
+
if (alreadyExists) {
|
|
16
|
+
return `Directory already exists: ${args.path}`;
|
|
17
|
+
}
|
|
18
|
+
return `Directory created: ${args.path}`;
|
|
19
|
+
};
|
|
20
|
+
const createDirectoryCoreTool = tool({
|
|
21
|
+
description: 'Create a directory, including parent directories if needed. Idempotent — succeeds if the directory already exists. AUTO-ACCEPTED (no user approval needed).',
|
|
22
|
+
inputSchema: jsonSchema({
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
path: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'The relative path of the directory to create (e.g., "src/components/new-feature").',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ['path'],
|
|
31
|
+
}),
|
|
32
|
+
// Low risk: creating directories is non-destructive and idempotent
|
|
33
|
+
needsApproval: false,
|
|
34
|
+
execute: async (args, _options) => {
|
|
35
|
+
return await executeCreateDirectory(args);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const CreateDirectoryFormatter = React.memo(({ args, result }) => {
|
|
39
|
+
const themeContext = React.useContext(ThemeContext);
|
|
40
|
+
if (!themeContext) {
|
|
41
|
+
throw new Error('ThemeContext is required');
|
|
42
|
+
}
|
|
43
|
+
const { colors } = themeContext;
|
|
44
|
+
const messageContent = (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: colors.tool, children: "\u2692 create_directory" }), _jsxs(Box, { children: [_jsx(Text, { color: colors.secondary, children: "Path: " }), _jsx(Text, { color: colors.text, children: args.path })] }), result && (_jsxs(Box, { children: [_jsx(Text, { color: colors.secondary, children: "Result: " }), _jsx(Text, { color: colors.text, children: result })] }))] }));
|
|
45
|
+
return _jsx(ToolMessage, { message: messageContent, hideBox: true });
|
|
46
|
+
});
|
|
47
|
+
const createDirectoryFormatter = (args, result) => {
|
|
48
|
+
return _jsx(CreateDirectoryFormatter, { args: args, result: result });
|
|
49
|
+
};
|
|
50
|
+
const createDirectoryValidator = async (args) => {
|
|
51
|
+
if (!isValidFilePath(args.path)) {
|
|
52
|
+
return {
|
|
53
|
+
valid: false,
|
|
54
|
+
error: `⚒ Invalid path: "${args.path}". Path must be relative and within the project directory.`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const cwd = process.cwd();
|
|
59
|
+
resolveFilePath(args.path, cwd);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
63
|
+
return {
|
|
64
|
+
valid: false,
|
|
65
|
+
error: `⚒ Path validation failed: ${errorMessage}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return { valid: true };
|
|
69
|
+
};
|
|
70
|
+
export const createDirectoryTool = {
|
|
71
|
+
name: 'create_directory',
|
|
72
|
+
tool: createDirectoryCoreTool,
|
|
73
|
+
formatter: createDirectoryFormatter,
|
|
74
|
+
validator: createDirectoryValidator,
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=create-directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-directory.js","sourceRoot":"","sources":["../../../source/tools/file-ops/create-directory.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,SAAS,CAAC;AACnC,OAAO,EAAC,KAAK,EAAC,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAC,eAAe,EAAE,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAMzE,MAAM,sBAAsB,GAAG,KAAK,EACnC,IAAyB,EACP,EAAE;IACpB,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAE1C,MAAM,KAAK,CAAC,OAAO,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;IAExC,IAAI,aAAa,EAAE,CAAC;QACnB,OAAO,6BAA6B,IAAI,CAAC,IAAI,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,sBAAsB,IAAI,CAAC,IAAI,EAAE,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,IAAI,CAAC;IACpC,WAAW,EACV,6JAA6J;IAC9J,WAAW,EAAE,UAAU,CAAsB;QAC5C,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACX,IAAI,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EACV,oFAAoF;aACrF;SACD;QACD,QAAQ,EAAE,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,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAI,CAAC;AACjE,CAAC,CAAC;AAEF,MAAM,wBAAwB,GAAG,KAAK,EACrC,IAAyB,EACgC,EAAE;IAC3D,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,OAAO;YACN,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,oBAAoB,IAAI,CAAC,IAAI,4DAA4D;SAChG,CAAC;IACH,CAAC;IAED,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAC1B,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,YAAY,GACjB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;QAC1D,OAAO;YACN,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,6BAA6B,YAAY,EAAE;SAClD,CAAC;IACH,CAAC;IAED,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAwB;IACvD,IAAI,EAAE,kBAA2B;IACjC,IAAI,EAAE,uBAAuB;IAC7B,SAAS,EAAE,wBAAwB;IACnC,SAAS,EAAE,wBAAwB;CACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-file.d.ts","sourceRoot":"","sources":["../../../source/tools/file-ops/delete-file.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAoHtD,eAAO,MAAM,cAAc,EAAE,mBAK5B,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { access, rm, stat } from 'node:fs/promises';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { Box, Text } from 'ink';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import ToolMessage from '../../components/tool-message.js';
|
|
8
|
+
import { ThemeContext } from '../../hooks/useTheme.js';
|
|
9
|
+
import { jsonSchema, tool } from '../../types/core.js';
|
|
10
|
+
import { invalidateCache } from '../../utils/file-cache.js';
|
|
11
|
+
import { isValidFilePath, resolveFilePath } from '../../utils/path-validation.js';
|
|
12
|
+
const executeDeleteFile = async (args) => {
|
|
13
|
+
const absPath = resolve(args.path);
|
|
14
|
+
const fileStat = await stat(absPath);
|
|
15
|
+
if (fileStat.isDirectory()) {
|
|
16
|
+
return `Error: "${args.path}" is a directory. Use execute_bash with rm -r for directory removal.`;
|
|
17
|
+
}
|
|
18
|
+
await rm(absPath);
|
|
19
|
+
invalidateCache(absPath);
|
|
20
|
+
return `File deleted: ${args.path}`;
|
|
21
|
+
};
|
|
22
|
+
const deleteFileCoreTool = tool({
|
|
23
|
+
description: 'Delete a file. Only deletes single files, not directories. Always requires user approval.',
|
|
24
|
+
inputSchema: jsonSchema({
|
|
25
|
+
type: 'object',
|
|
26
|
+
properties: {
|
|
27
|
+
path: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'The relative path to the file to delete.',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
required: ['path'],
|
|
33
|
+
}),
|
|
34
|
+
// High risk: destructive operation, always requires approval
|
|
35
|
+
needsApproval: true,
|
|
36
|
+
execute: async (args, _options) => {
|
|
37
|
+
return await executeDeleteFile(args);
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
const DeleteFileFormatter = React.memo(({ args, result }) => {
|
|
41
|
+
const themeContext = React.useContext(ThemeContext);
|
|
42
|
+
if (!themeContext) {
|
|
43
|
+
throw new Error('ThemeContext is required');
|
|
44
|
+
}
|
|
45
|
+
const { colors } = themeContext;
|
|
46
|
+
const messageContent = (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: colors.tool, children: "\u2692 delete_file" }), _jsxs(Box, { children: [_jsx(Text, { color: colors.secondary, children: "Path: " }), _jsx(Text, { color: colors.text, children: args.path })] }), result && (_jsxs(Box, { children: [_jsx(Text, { color: colors.secondary, children: "Result: " }), _jsx(Text, { color: colors.text, children: result })] }))] }));
|
|
47
|
+
return _jsx(ToolMessage, { message: messageContent, hideBox: true });
|
|
48
|
+
});
|
|
49
|
+
const deleteFileFormatter = (args, result) => {
|
|
50
|
+
return _jsx(DeleteFileFormatter, { args: args, result: result });
|
|
51
|
+
};
|
|
52
|
+
const deleteFileValidator = async (args) => {
|
|
53
|
+
if (!isValidFilePath(args.path)) {
|
|
54
|
+
return {
|
|
55
|
+
valid: false,
|
|
56
|
+
error: `⚒ Invalid file path: "${args.path}". Path must be relative and within the project directory.`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const cwd = process.cwd();
|
|
61
|
+
resolveFilePath(args.path, cwd);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
65
|
+
return {
|
|
66
|
+
valid: false,
|
|
67
|
+
error: `⚒ Path validation failed: ${errorMessage}`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const absPath = resolve(args.path);
|
|
71
|
+
try {
|
|
72
|
+
await access(absPath, constants.F_OK);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return {
|
|
76
|
+
valid: false,
|
|
77
|
+
error: `⚒ File does not exist: "${args.path}"`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return { valid: true };
|
|
81
|
+
};
|
|
82
|
+
export const deleteFileTool = {
|
|
83
|
+
name: 'delete_file',
|
|
84
|
+
tool: deleteFileCoreTool,
|
|
85
|
+
formatter: deleteFileFormatter,
|
|
86
|
+
validator: deleteFileValidator,
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=delete-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-file.js","sourceRoot":"","sources":["../../../source/tools/file-ops/delete-file.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAClC,OAAO,EAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAC,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,KAAK,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAC,eAAe,EAAE,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAMzE,MAAM,iBAAiB,GAAG,KAAK,EAAE,IAAoB,EAAmB,EAAE;IACzE,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEnC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;IACrC,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC;QAC5B,OAAO,WAAW,IAAI,CAAC,IAAI,sEAAsE,CAAC;IACnG,CAAC;IAED,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;IAClB,eAAe,CAAC,OAAO,CAAC,CAAC;IAEzB,OAAO,iBAAiB,IAAI,CAAC,IAAI,EAAE,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,IAAI,CAAC;IAC/B,WAAW,EACV,2FAA2F;IAC5F,WAAW,E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