@4onstudios/iris-agent 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/LICENSE +21 -0
- package/README.md +690 -0
- package/dist/api/acp/acpServer.d.ts +23 -0
- package/dist/api/acp/acpServer.js +814 -0
- package/dist/api/acp/index.d.ts +2 -0
- package/dist/api/acp/index.js +2 -0
- package/dist/api/acp/irisClient.d.ts +58 -0
- package/dist/api/acp/irisClient.js +214 -0
- package/dist/api/agent.d.ts +14 -0
- package/dist/api/agent.js +4171 -0
- package/dist/api/backendService.d.ts +4 -0
- package/dist/api/backendService.js +14 -0
- package/dist/api/core/agent/host/AgentContract.d.ts +82 -0
- package/dist/api/core/agent/host/AgentContract.js +1 -0
- package/dist/api/core/agent/host/AgentRegistry.d.ts +24 -0
- package/dist/api/core/agent/host/AgentRegistry.js +125 -0
- package/dist/api/core/agent/host/defaultRegistry.d.ts +15 -0
- package/dist/api/core/agent/host/defaultRegistry.js +46 -0
- package/dist/api/core/agent/host/externalAgentLifecycle.d.ts +65 -0
- package/dist/api/core/agent/host/externalAgentLifecycle.js +117 -0
- package/dist/api/core/agent/host/hostSessionManager.d.ts +111 -0
- package/dist/api/core/agent/host/hostSessionManager.js +352 -0
- package/dist/api/core/agent/host/index.d.ts +5 -0
- package/dist/api/core/agent/host/index.js +5 -0
- package/dist/api/core/agent/index.d.ts +87 -0
- package/dist/api/core/agent/index.js +1024 -0
- package/dist/api/core/agent/publicContracts.d.ts +35 -0
- package/dist/api/core/agent/publicContracts.js +103 -0
- package/dist/api/core/agent/tools/applyDiff.d.ts +51 -0
- package/dist/api/core/agent/tools/applyDiff.js +131 -0
- package/dist/api/core/agent/tools/backgroundTasks.d.ts +240 -0
- package/dist/api/core/agent/tools/backgroundTasks.js +313 -0
- package/dist/api/core/agent/tools/createDirectory.d.ts +43 -0
- package/dist/api/core/agent/tools/createDirectory.js +77 -0
- package/dist/api/core/agent/tools/deleteFile.d.ts +37 -0
- package/dist/api/core/agent/tools/deleteFile.js +66 -0
- package/dist/api/core/agent/tools/editFile.d.ts +73 -0
- package/dist/api/core/agent/tools/editFile.js +173 -0
- package/dist/api/core/agent/tools/executeCommand.d.ts +59 -0
- package/dist/api/core/agent/tools/executeCommand.js +250 -0
- package/dist/api/core/agent/tools/fileContent.d.ts +54 -0
- package/dist/api/core/agent/tools/fileContent.js +227 -0
- package/dist/api/core/agent/tools/findDefinition.d.ts +72 -0
- package/dist/api/core/agent/tools/findDefinition.js +109 -0
- package/dist/api/core/agent/tools/findReferences.d.ts +86 -0
- package/dist/api/core/agent/tools/findReferences.js +135 -0
- package/dist/api/core/agent/tools/formatDocument.d.ts +67 -0
- package/dist/api/core/agent/tools/formatDocument.js +90 -0
- package/dist/api/core/agent/tools/getCodeActions.d.ts +77 -0
- package/dist/api/core/agent/tools/getCodeActions.js +97 -0
- package/dist/api/core/agent/tools/getCodeCompletion.d.ts +77 -0
- package/dist/api/core/agent/tools/getCodeCompletion.js +174 -0
- package/dist/api/core/agent/tools/getCodeContext.d.ts +14 -0
- package/dist/api/core/agent/tools/getCodeContext.js +282 -0
- package/dist/api/core/agent/tools/getSignatureHelp.d.ts +61 -0
- package/dist/api/core/agent/tools/getSignatureHelp.js +85 -0
- package/dist/api/core/agent/tools/getSymbols.d.ts +50 -0
- package/dist/api/core/agent/tools/getSymbols.js +164 -0
- package/dist/api/core/agent/tools/getSymbolsLSP.d.ts +58 -0
- package/dist/api/core/agent/tools/getSymbolsLSP.js +147 -0
- package/dist/api/core/agent/tools/getTypeInfo.d.ts +70 -0
- package/dist/api/core/agent/tools/getTypeInfo.js +84 -0
- package/dist/api/core/agent/tools/getWorkspaceInfo.d.ts +80 -0
- package/dist/api/core/agent/tools/getWorkspaceInfo.js +281 -0
- package/dist/api/core/agent/tools/getWorkspaceSymbols.d.ts +53 -0
- package/dist/api/core/agent/tools/getWorkspaceSymbols.js +97 -0
- package/dist/api/core/agent/tools/grepSearch.d.ts +100 -0
- package/dist/api/core/agent/tools/grepSearch.js +211 -0
- package/dist/api/core/agent/tools/languageModelToolsIntegration.d.ts +13 -0
- package/dist/api/core/agent/tools/languageModelToolsIntegration.js +22 -0
- package/dist/api/core/agent/tools/listDirectory.d.ts +66 -0
- package/dist/api/core/agent/tools/listDirectory.js +161 -0
- package/dist/api/core/agent/tools/mcpTools.d.ts +48 -0
- package/dist/api/core/agent/tools/mcpTools.js +442 -0
- package/dist/api/core/agent/tools/queryKnowledgeGraph.d.ts +120 -0
- package/dist/api/core/agent/tools/queryKnowledgeGraph.js +306 -0
- package/dist/api/core/agent/tools/readFile.d.ts +92 -0
- package/dist/api/core/agent/tools/readFile.js +337 -0
- package/dist/api/core/agent/tools/renameFile.d.ts +49 -0
- package/dist/api/core/agent/tools/renameFile.js +86 -0
- package/dist/api/core/agent/tools/renameSymbol.d.ts +70 -0
- package/dist/api/core/agent/tools/renameSymbol.js +106 -0
- package/dist/api/core/agent/tools/runTerminalCommand.d.ts +72 -0
- package/dist/api/core/agent/tools/runTerminalCommand.js +69 -0
- package/dist/api/core/agent/tools/searchFiles.d.ts +82 -0
- package/dist/api/core/agent/tools/searchFiles.js +280 -0
- package/dist/api/core/agent/tools/terminalAutoApprove.d.ts +3 -0
- package/dist/api/core/agent/tools/terminalAutoApprove.js +676 -0
- package/dist/api/core/agent/tools/treeTraversal.d.ts +60 -0
- package/dist/api/core/agent/tools/treeTraversal.js +217 -0
- package/dist/api/core/agent/tools/webSearch.d.ts +37 -0
- package/dist/api/core/agent/tools/webSearch.js +80 -0
- package/dist/api/core/agent/tools/writeFile.d.ts +59 -0
- package/dist/api/core/agent/tools/writeFile.js +97 -0
- package/dist/api/core/agent/utils/capturedWorkspaceMutationBridge.d.ts +12 -0
- package/dist/api/core/agent/utils/capturedWorkspaceMutationBridge.js +67 -0
- package/dist/api/core/agent/utils/diffUtils.d.ts +14 -0
- package/dist/api/core/agent/utils/diffUtils.js +39 -0
- package/dist/api/core/agent/utils/environmentSnapshot.d.ts +42 -0
- package/dist/api/core/agent/utils/environmentSnapshot.js +213 -0
- package/dist/api/core/agent/utils/errorRecovery.d.ts +49 -0
- package/dist/api/core/agent/utils/errorRecovery.js +229 -0
- package/dist/api/core/agent/utils/multimodalTokenLimiter.d.ts +8 -0
- package/dist/api/core/agent/utils/multimodalTokenLimiter.js +238 -0
- package/dist/api/core/agent/utils/openRouterModelSettings.d.ts +12 -0
- package/dist/api/core/agent/utils/openRouterModelSettings.js +34 -0
- package/dist/api/core/agent/utils/pathRecovery.d.ts +1 -0
- package/dist/api/core/agent/utils/pathRecovery.js +29 -0
- package/dist/api/core/agent/utils/repoMapIndex.d.ts +3 -0
- package/dist/api/core/agent/utils/repoMapIndex.js +197 -0
- package/dist/api/core/agent/utils/skillsDiscovery.d.ts +10 -0
- package/dist/api/core/agent/utils/skillsDiscovery.js +50 -0
- package/dist/api/core/agent/utils/toolCallBudget.d.ts +9 -0
- package/dist/api/core/agent/utils/toolCallBudget.js +55 -0
- package/dist/api/core/agent/utils/toolLifecycle.d.ts +30 -0
- package/dist/api/core/agent/utils/toolLifecycle.js +361 -0
- package/dist/api/core/agent/utils/toolResultSafetyProcessor.d.ts +12 -0
- package/dist/api/core/agent/utils/toolResultSafetyProcessor.js +57 -0
- package/dist/api/core/agent/utils/workspaceMutationBridge.d.ts +13 -0
- package/dist/api/core/agent/utils/workspaceMutationBridge.js +149 -0
- package/dist/api/core/agent/utils/workspacePathGuard.d.ts +7 -0
- package/dist/api/core/agent/utils/workspacePathGuard.js +79 -0
- package/dist/api/core/containers/chat/toolResultSerialization.d.ts +8 -0
- package/dist/api/core/containers/chat/toolResultSerialization.js +71 -0
- package/dist/api/core/library/BrowserManager.d.ts +11 -0
- package/dist/api/core/library/BrowserManager.js +66 -0
- package/dist/api/core/library/desktopWorkspace.d.ts +1 -0
- package/dist/api/core/library/desktopWorkspace.js +3 -0
- package/dist/api/core/library/extensionManager.d.ts +10 -0
- package/dist/api/core/library/extensionManager.js +27 -0
- package/dist/api/core/library/knowledgeGraph.d.ts +268 -0
- package/dist/api/core/library/knowledgeGraph.js +989 -0
- package/dist/api/core/library/languageModelTools.d.ts +141 -0
- package/dist/api/core/library/languageModelTools.js +207 -0
- package/dist/api/core/library/localRuntime.d.ts +23 -0
- package/dist/api/core/library/localRuntime.js +144 -0
- package/dist/api/core/library/lsp/coreLsp.d.ts +367 -0
- package/dist/api/core/library/lsp/coreLsp.js +2076 -0
- package/dist/api/core/library/lsp/protocol.d.ts +25 -0
- package/dist/api/core/library/lsp/protocol.js +1 -0
- package/dist/api/core/library/lsp/serverManager.d.ts +37 -0
- package/dist/api/core/library/lsp/serverManager.js +427 -0
- package/dist/api/core/library/mcpServerProvider.d.ts +69 -0
- package/dist/api/core/library/mcpServerProvider.js +152 -0
- package/dist/api/core/library/mcpSettings.d.ts +20 -0
- package/dist/api/core/library/mcpSettings.js +131 -0
- package/dist/api/core/library/patternMatcher.d.ts +66 -0
- package/dist/api/core/library/patternMatcher.js +284 -0
- package/dist/api/core/library/regexEscape.d.ts +4 -0
- package/dist/api/core/library/regexEscape.js +4 -0
- package/dist/api/core/library/runtimeEventBus.d.ts +27 -0
- package/dist/api/core/library/runtimeEventBus.js +78 -0
- package/dist/api/core/library/safetyMiddleware.d.ts +98 -0
- package/dist/api/core/library/safetyMiddleware.js +215 -0
- package/dist/api/core/library/tauri.d.ts +71 -0
- package/dist/api/core/library/tauri.js +222 -0
- package/dist/api/core/library/tauriImport.d.ts +5 -0
- package/dist/api/core/library/tauriImport.js +7 -0
- package/dist/api/core/library/terminalAutoApproveSettings.d.ts +32 -0
- package/dist/api/core/library/terminalAutoApproveSettings.js +529 -0
- package/dist/api/core/library/workspaceIdentity.d.ts +10 -0
- package/dist/api/core/library/workspaceIdentity.js +49 -0
- package/dist/api/core/library/workspaceSummary.d.ts +19 -0
- package/dist/api/core/library/workspaceSummary.js +35 -0
- package/dist/api/core/skills/agent-customization/SKILL.md +27 -0
- package/dist/api/core/skills/bug-fix/SKILL.md +21 -0
- package/dist/api/core/skills/create-pr/SKILL.md +32 -0
- package/dist/api/core/skills/dev-server/SKILL.md +20 -0
- package/dist/api/core/skills/fix-suggestions/SKILL.md +21 -0
- package/dist/api/core/skills/github-search/SKILL.md +21 -0
- package/dist/api/core/skills/github-summary/SKILL.md +25 -0
- package/dist/api/core/skills/integration-tests/SKILL.md +29 -0
- package/dist/api/core/skills/pr-comments/SKILL.md +23 -0
- package/dist/api/core/skills/project-setup/SKILL.md +20 -0
- package/dist/api/core/skills/search-integration/SKILL.md +19 -0
- package/dist/api/core/skills/search-results/SKILL.md +19 -0
- package/dist/api/core/skills/typescript-upgrade/SKILL.md +21 -0
- package/dist/api/data/runStore.d.ts +46 -0
- package/dist/api/data/runStore.js +244 -0
- package/dist/api/helpers/agentUtils.d.ts +11 -0
- package/dist/api/helpers/agentUtils.js +23 -0
- package/dist/api/helpers/modelTokenLimits.d.ts +2 -0
- package/dist/api/helpers/modelTokenLimits.js +158 -0
- package/dist/api/helpers/observationalMemory.d.ts +10 -0
- package/dist/api/helpers/observationalMemory.js +36 -0
- package/dist/api/helpers/promptBudget.d.ts +30 -0
- package/dist/api/helpers/promptBudget.js +216 -0
- package/dist/api/helpers/resolveImageMessageParts.d.ts +9 -0
- package/dist/api/helpers/resolveImageMessageParts.js +140 -0
- package/dist/api/helpers/slashCommands.d.ts +31 -0
- package/dist/api/helpers/slashCommands.js +129 -0
- package/dist/api/helpers/tokenUsage.d.ts +19 -0
- package/dist/api/helpers/tokenUsage.js +81 -0
- package/dist/api/routes/fileRoutes.d.ts +2 -0
- package/dist/api/routes/fileRoutes.js +108 -0
- package/dist/api/routes/lspDocumentRoutes.d.ts +4 -0
- package/dist/api/routes/lspDocumentRoutes.js +84 -0
- package/dist/api/routes/lspHierarchyRoutes.d.ts +4 -0
- package/dist/api/routes/lspHierarchyRoutes.js +122 -0
- package/dist/api/routes/lspPositionRoutes.d.ts +4 -0
- package/dist/api/routes/lspPositionRoutes.js +263 -0
- package/dist/api/routes/lspQueryRoutes.d.ts +4 -0
- package/dist/api/routes/lspQueryRoutes.js +679 -0
- package/dist/api/routes/lspResolveRoutes.d.ts +4 -0
- package/dist/api/routes/lspResolveRoutes.js +143 -0
- package/dist/api/routes/lspSemanticDocumentRoutes.d.ts +4 -0
- package/dist/api/routes/lspSemanticDocumentRoutes.js +98 -0
- package/dist/api/routes/semanticRoutes.d.ts +2 -0
- package/dist/api/routes/semanticRoutes.js +126 -0
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +160 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +38 -0
- package/package.json +100 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type WorkspaceToolHooks } from "@mastra/core/workspace";
|
|
2
|
+
export declare const createIrisWorkspaceToolsConfig: (hooks?: WorkspaceToolHooks) => {
|
|
3
|
+
mastra_workspace_read_file: {
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
mastra_workspace_list_files: {
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
mastra_workspace_file_stat: {
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
mastra_workspace_grep: {
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
mastra_workspace_write_file: {
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
};
|
|
18
|
+
mastra_workspace_edit_file: {
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
};
|
|
21
|
+
mastra_workspace_delete: {
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
24
|
+
mastra_workspace_mkdir: {
|
|
25
|
+
name: string;
|
|
26
|
+
};
|
|
27
|
+
mastra_workspace_ast_edit: {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
};
|
|
30
|
+
mastra_workspace_search: {
|
|
31
|
+
name: string;
|
|
32
|
+
};
|
|
33
|
+
hooks?: WorkspaceToolHooks;
|
|
34
|
+
};
|
|
35
|
+
export declare const CODING_AGENT_INSTRUCTIONS: string;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { WORKSPACE_TOOLS, } from "@mastra/core/workspace";
|
|
2
|
+
export const createIrisWorkspaceToolsConfig = (hooks) => ({
|
|
3
|
+
...(hooks ? { hooks } : {}),
|
|
4
|
+
[WORKSPACE_TOOLS.FILESYSTEM.READ_FILE]: { name: "readFile" },
|
|
5
|
+
[WORKSPACE_TOOLS.FILESYSTEM.LIST_FILES]: { name: "listDirectory" },
|
|
6
|
+
[WORKSPACE_TOOLS.FILESYSTEM.FILE_STAT]: { name: "fileStat" },
|
|
7
|
+
[WORKSPACE_TOOLS.FILESYSTEM.GREP]: { name: "grepSearch" },
|
|
8
|
+
// Keep native mutations disabled: their string results omit the rich diff
|
|
9
|
+
// contract. AIRIS writeFile/editFile are registered on the agent below.
|
|
10
|
+
[WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE]: { enabled: false },
|
|
11
|
+
[WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE]: {
|
|
12
|
+
enabled: false,
|
|
13
|
+
},
|
|
14
|
+
[WORKSPACE_TOOLS.FILESYSTEM.DELETE]: { name: "deleteFile" },
|
|
15
|
+
[WORKSPACE_TOOLS.FILESYSTEM.MKDIR]: { name: "createDirectory" },
|
|
16
|
+
[WORKSPACE_TOOLS.FILESYSTEM.AST_EDIT]: { enabled: false },
|
|
17
|
+
[WORKSPACE_TOOLS.SEARCH.SEARCH]: { name: "workspaceSearch" },
|
|
18
|
+
});
|
|
19
|
+
export const CODING_AGENT_INSTRUCTIONS = `
|
|
20
|
+
You are AIRIS, a senior coding agent working in the user's current workspace.
|
|
21
|
+
Follow these rules in order; when rules conflict, the earlier rule wins.
|
|
22
|
+
|
|
23
|
+
## Priorities
|
|
24
|
+
|
|
25
|
+
1. Fulfill the user's actual request and preserve explicitly stated constraints.
|
|
26
|
+
2. Protect user data, existing work, credentials, and external systems.
|
|
27
|
+
3. Ground workspace-specific claims in current tool results.
|
|
28
|
+
4. Make the smallest complete change that solves the root problem.
|
|
29
|
+
5. Use the fewest tool calls that still provide enough evidence and validation.
|
|
30
|
+
|
|
31
|
+
## Decide Whether To Act
|
|
32
|
+
|
|
33
|
+
- Use tools when the request depends on workspace contents, runtime state, command output,
|
|
34
|
+
current web information, or an external system. Do not force a tool call for a purely
|
|
35
|
+
conceptual or conversational answer.
|
|
36
|
+
- When the user clearly requests a change or command, perform it instead of only proposing it.
|
|
37
|
+
- Ask one concise clarification only when missing information materially changes the result,
|
|
38
|
+
no safe default exists, or an irreversible/external action needs confirmation. Otherwise,
|
|
39
|
+
infer the most conservative reasonable intent and proceed.
|
|
40
|
+
- Respect tool approval and suspension flows. Waiting for required user input is a valid stop.
|
|
41
|
+
- Never invent paths, file contents, command output, tool capabilities, or successful completion.
|
|
42
|
+
|
|
43
|
+
## Working Method
|
|
44
|
+
|
|
45
|
+
1. Start from the most concrete available anchor: an exact file, symbol, error, command, test,
|
|
46
|
+
or nearby implementation.
|
|
47
|
+
2. Gather only enough current evidence to identify the controlling code path and a check that
|
|
48
|
+
can disprove the intended fix. Avoid broad project surveys when a local read or search is enough.
|
|
49
|
+
3. Make a focused change using the repository's existing patterns and public contracts.
|
|
50
|
+
4. After an edit, run the narrowest available validation that exercises the changed behavior.
|
|
51
|
+
5. If validation exposes a local defect, fix that same slice and rerun the same check. Do not
|
|
52
|
+
expand into unrelated cleanup.
|
|
53
|
+
6. Finish with a concise factual response once the request is complete, blocked, awaiting input,
|
|
54
|
+
or the action budget is exhausted.
|
|
55
|
+
|
|
56
|
+
## Tool Selection
|
|
57
|
+
|
|
58
|
+
- Treat the tools and their current schemas as authoritative. Never call aliases that are not
|
|
59
|
+
exposed in the current run.
|
|
60
|
+
- Known exact path: use readFile directly. Unknown filename: use searchFiles. Known text or code
|
|
61
|
+
pattern: use grepSearch. Use workspaceSearch, when exposed, for conceptual discovery. Use
|
|
62
|
+
getWorkspaceInfo only when a broad project overview is genuinely needed.
|
|
63
|
+
- Use getCodeContext or LSP tools when semantic precision matters. Use findReferences before
|
|
64
|
+
changing a shared symbol or contract, and prefer renameSymbol for semantic renames.
|
|
65
|
+
- Use editFile for exact, localized replacements, writeFile for new files or deliberate full
|
|
66
|
+
rewrites, and applyDiff for coordinated multi-hunk changes. These AIRIS mutation tools return
|
|
67
|
+
rich diff metadata for review.
|
|
68
|
+
- Prefer file tools over shell-based file mutation. Use runTerminalCommand for builds, tests,
|
|
69
|
+
package operations, git inspection, and commands whose behavior belongs in a shell.
|
|
70
|
+
- taskList, taskOutput, and taskStop manage background terminal tasks; they are not planning or
|
|
71
|
+
todo-list tools.
|
|
72
|
+
- Use MCP and web tools only when the request requires their external capability. Follow each
|
|
73
|
+
exposed schema exactly and avoid irreversible external actions without clear authorization.
|
|
74
|
+
- Issue independent reads or searches together when supported. Batch dependent shell commands
|
|
75
|
+
with && only when later commands should run solely after earlier ones succeed.
|
|
76
|
+
|
|
77
|
+
## Editing And Validation
|
|
78
|
+
|
|
79
|
+
- Read the relevant current region before modifying an existing file unless its current content
|
|
80
|
+
is already present in the conversation or a fresh tool result.
|
|
81
|
+
- Preserve repository style, public APIs, and user-authored changes. Do not reformat, revert,
|
|
82
|
+
delete, or refactor unrelated code.
|
|
83
|
+
- Do not perform destructive git operations, commit, push, deploy, publish, or install global
|
|
84
|
+
software unless the user explicitly requests or clearly authorizes it.
|
|
85
|
+
- Inspect the mutation result rather than rereading a file solely to confirm that the tool wrote it.
|
|
86
|
+
- Prefer a behavior-scoped test, then a targeted test, typecheck, lint, or build. Broaden validation
|
|
87
|
+
only when the change's risk or shared surface justifies it.
|
|
88
|
+
- Report pre-existing or unrelated failures without trying to repair them unless they block the task.
|
|
89
|
+
|
|
90
|
+
## Failure And Completion
|
|
91
|
+
|
|
92
|
+
- Read the exact error, correct the likely cause, and retry with a bounded alternative. Do not repeat
|
|
93
|
+
the same failing call or continue investigating after the answer is known.
|
|
94
|
+
- Continue autonomously until the requested outcome is complete. Stop only when complete, genuinely
|
|
95
|
+
blocked, waiting for required input/approval, or out of the runtime's action budget.
|
|
96
|
+
- The configured Mastra maxSteps value is the sole action budget. When it is nearly exhausted,
|
|
97
|
+
prioritize the essential implementation and validation. If exhausted, provide a final synthesis
|
|
98
|
+
of what completed, what remains, and the concrete blocker; do not claim success for partial work.
|
|
99
|
+
- After tools, always provide meaningful final text. State the result first, name changed files or
|
|
100
|
+
important findings, and include validation status. Keep details proportional to the request.
|
|
101
|
+
- Do not end with a generic offer, ask what to do next, narrate tool mechanics, or continue calling
|
|
102
|
+
tools after the task is resolved.
|
|
103
|
+
`.trim();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
type ApplyDiffParams = {
|
|
3
|
+
filePath: string;
|
|
4
|
+
patch: string;
|
|
5
|
+
};
|
|
6
|
+
type ApplyDiffSuccessResult = {
|
|
7
|
+
success: true;
|
|
8
|
+
filePath: string;
|
|
9
|
+
fileExisted: boolean;
|
|
10
|
+
size: number;
|
|
11
|
+
modified: Date;
|
|
12
|
+
linesAdded: number;
|
|
13
|
+
linesRemoved: number;
|
|
14
|
+
diff: string;
|
|
15
|
+
oldContent: string;
|
|
16
|
+
newContent: string;
|
|
17
|
+
};
|
|
18
|
+
type ApplyDiffErrorResult = {
|
|
19
|
+
success: false;
|
|
20
|
+
error: string;
|
|
21
|
+
patch?: string;
|
|
22
|
+
filePath?: string;
|
|
23
|
+
parsedChanges?: number;
|
|
24
|
+
};
|
|
25
|
+
type ApplyDiffResult = ApplyDiffSuccessResult | ApplyDiffErrorResult;
|
|
26
|
+
/**
|
|
27
|
+
* Tool for applying unified diff patches to files
|
|
28
|
+
* @param {Object} params - The parameters for applying a diff
|
|
29
|
+
* @param {string} params.filePath - The path to the file to patch
|
|
30
|
+
* @param {string} params.patch - The unified diff patch to apply
|
|
31
|
+
* @returns {Promise<Object>} Object containing success status and patch info or error
|
|
32
|
+
*/
|
|
33
|
+
export declare function applyDiff({ filePath, patch, }: ApplyDiffParams): Promise<ApplyDiffResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Tool metadata for agent system
|
|
36
|
+
*/
|
|
37
|
+
export declare const applyDiffTool: {
|
|
38
|
+
description: string;
|
|
39
|
+
parameters: z.ZodObject<{
|
|
40
|
+
filePath: z.ZodString;
|
|
41
|
+
patch: z.ZodString;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
filePath?: string;
|
|
44
|
+
patch?: string;
|
|
45
|
+
}, {
|
|
46
|
+
filePath?: string;
|
|
47
|
+
patch?: string;
|
|
48
|
+
}>;
|
|
49
|
+
execute: typeof applyDiff;
|
|
50
|
+
};
|
|
51
|
+
export default applyDiffTool;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { applyPatch, parsePatch } from "diff";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { generateDiff } from "../utils/diffUtils.js";
|
|
6
|
+
const normalizeDiffPath = (input) => {
|
|
7
|
+
if (!input)
|
|
8
|
+
return "";
|
|
9
|
+
const normalized = input.trim().replace(/\\/g, "/");
|
|
10
|
+
if (normalized.startsWith("a/") || normalized.startsWith("b/")) {
|
|
11
|
+
return normalized.slice(2);
|
|
12
|
+
}
|
|
13
|
+
return normalized;
|
|
14
|
+
};
|
|
15
|
+
const matchesTargetPath = (parsedPath, targetAbsolutePath) => {
|
|
16
|
+
if (!parsedPath || parsedPath === "/dev/null")
|
|
17
|
+
return false;
|
|
18
|
+
const normalizedParsed = parsedPath.replace(/\\/g, "/");
|
|
19
|
+
const normalizedTarget = targetAbsolutePath.replace(/\\/g, "/");
|
|
20
|
+
return (normalizedTarget.endsWith(`/${normalizedParsed}`) ||
|
|
21
|
+
normalizedTarget === normalizedParsed);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Tool for applying unified diff patches to files
|
|
25
|
+
* @param {Object} params - The parameters for applying a diff
|
|
26
|
+
* @param {string} params.filePath - The path to the file to patch
|
|
27
|
+
* @param {string} params.patch - The unified diff patch to apply
|
|
28
|
+
* @returns {Promise<Object>} Object containing success status and patch info or error
|
|
29
|
+
*/
|
|
30
|
+
export async function applyDiff({ filePath, patch, }) {
|
|
31
|
+
try {
|
|
32
|
+
if (!filePath || !patch) {
|
|
33
|
+
return {
|
|
34
|
+
success: false,
|
|
35
|
+
error: "Both filePath and patch are required",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const absolutePath = path.resolve(filePath);
|
|
39
|
+
const parsedPatches = parsePatch(patch);
|
|
40
|
+
if (parsedPatches.length === 0) {
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
error: "Invalid unified diff: no patch sections found",
|
|
44
|
+
patch,
|
|
45
|
+
filePath: absolutePath,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const targetPatch = parsedPatches.find((candidate) => {
|
|
49
|
+
const oldName = normalizeDiffPath(candidate.oldFileName);
|
|
50
|
+
const newName = normalizeDiffPath(candidate.newFileName);
|
|
51
|
+
return (matchesTargetPath(oldName, absolutePath) ||
|
|
52
|
+
matchesTargetPath(newName, absolutePath));
|
|
53
|
+
}) || parsedPatches[0];
|
|
54
|
+
let oldContent = "";
|
|
55
|
+
let existedBefore = false;
|
|
56
|
+
try {
|
|
57
|
+
oldContent = await fs.readFile(absolutePath, "utf8");
|
|
58
|
+
existedBefore = true;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
oldContent = "";
|
|
62
|
+
existedBefore = false;
|
|
63
|
+
}
|
|
64
|
+
const oldName = normalizeDiffPath(targetPatch.oldFileName);
|
|
65
|
+
const newName = normalizeDiffPath(targetPatch.newFileName);
|
|
66
|
+
const isDelete = oldName !== "/dev/null" && newName === "/dev/null";
|
|
67
|
+
if (isDelete) {
|
|
68
|
+
if (existedBefore) {
|
|
69
|
+
await fs.unlink(absolutePath);
|
|
70
|
+
}
|
|
71
|
+
const { diff, linesAdded, linesRemoved } = generateDiff(oldContent, "", absolutePath);
|
|
72
|
+
return {
|
|
73
|
+
success: true,
|
|
74
|
+
filePath: absolutePath,
|
|
75
|
+
fileExisted: existedBefore,
|
|
76
|
+
size: 0,
|
|
77
|
+
modified: new Date(),
|
|
78
|
+
linesAdded,
|
|
79
|
+
linesRemoved,
|
|
80
|
+
diff,
|
|
81
|
+
oldContent,
|
|
82
|
+
newContent: "",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const newContent = applyPatch(oldContent, patch);
|
|
86
|
+
if (newContent === false) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
error: "Failed to apply patch because file content no longer matches patch context",
|
|
90
|
+
patch,
|
|
91
|
+
filePath: absolutePath,
|
|
92
|
+
parsedChanges: targetPatch.hunks?.length || 0,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
await fs.mkdir(path.dirname(absolutePath), { recursive: true });
|
|
96
|
+
await fs.writeFile(absolutePath, newContent, "utf8");
|
|
97
|
+
const stats = await fs.stat(absolutePath);
|
|
98
|
+
const { diff, linesAdded, linesRemoved } = generateDiff(oldContent, newContent, absolutePath);
|
|
99
|
+
return {
|
|
100
|
+
success: true,
|
|
101
|
+
filePath: absolutePath,
|
|
102
|
+
fileExisted: existedBefore,
|
|
103
|
+
size: stats.size,
|
|
104
|
+
modified: stats.mtime,
|
|
105
|
+
linesAdded,
|
|
106
|
+
linesRemoved,
|
|
107
|
+
diff,
|
|
108
|
+
oldContent,
|
|
109
|
+
newContent,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
const err = error;
|
|
114
|
+
return {
|
|
115
|
+
success: false,
|
|
116
|
+
error: err.message,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Tool metadata for agent system
|
|
122
|
+
*/
|
|
123
|
+
export const applyDiffTool = {
|
|
124
|
+
description: "Apply a unified diff patch to a file",
|
|
125
|
+
parameters: z.object({
|
|
126
|
+
filePath: z.string().describe("The path to the file to patch"),
|
|
127
|
+
patch: z.string().describe("The unified diff patch to apply"),
|
|
128
|
+
}),
|
|
129
|
+
execute: applyDiff,
|
|
130
|
+
};
|
|
131
|
+
export default applyDiffTool;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export type BackgroundTaskStatus = "running" | "completed" | "failed" | "stopped";
|
|
3
|
+
type StartBackgroundTaskParams = {
|
|
4
|
+
command: string;
|
|
5
|
+
cwd: string;
|
|
6
|
+
env?: NodeJS.ProcessEnv;
|
|
7
|
+
description?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const __resetBackgroundTasksForTests: () => Promise<void>;
|
|
10
|
+
export declare const startBackgroundTask: ({ command, cwd, env, description, }: StartBackgroundTaskParams) => {
|
|
11
|
+
success: boolean;
|
|
12
|
+
status: string;
|
|
13
|
+
taskId: string;
|
|
14
|
+
pid: number;
|
|
15
|
+
command: string;
|
|
16
|
+
cwd: string;
|
|
17
|
+
description: string;
|
|
18
|
+
startedAt: number;
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const listBackgroundTasks: ({ activeOnly, limit, }: {
|
|
22
|
+
activeOnly?: boolean;
|
|
23
|
+
limit?: number;
|
|
24
|
+
}) => {
|
|
25
|
+
taskId: string;
|
|
26
|
+
command: string;
|
|
27
|
+
description: string;
|
|
28
|
+
cwd: string;
|
|
29
|
+
status: BackgroundTaskStatus;
|
|
30
|
+
startedAt: number;
|
|
31
|
+
endedAt: number;
|
|
32
|
+
pid: number;
|
|
33
|
+
exitCode: number;
|
|
34
|
+
signal: NodeJS.Signals;
|
|
35
|
+
retention: {
|
|
36
|
+
maxTerminalTasksRetained: number;
|
|
37
|
+
terminalTaskTtlMs: number;
|
|
38
|
+
evictedTasksTotal: number;
|
|
39
|
+
};
|
|
40
|
+
}[];
|
|
41
|
+
export declare const getBackgroundTaskOutput: ({ taskId, tailChars, }: {
|
|
42
|
+
taskId: string;
|
|
43
|
+
tailChars?: number;
|
|
44
|
+
}) => {
|
|
45
|
+
success: boolean;
|
|
46
|
+
error: string;
|
|
47
|
+
taskId?: undefined;
|
|
48
|
+
status?: undefined;
|
|
49
|
+
command?: undefined;
|
|
50
|
+
description?: undefined;
|
|
51
|
+
startedAt?: undefined;
|
|
52
|
+
endedAt?: undefined;
|
|
53
|
+
exitCode?: undefined;
|
|
54
|
+
signal?: undefined;
|
|
55
|
+
output?: undefined;
|
|
56
|
+
outputTruncated?: undefined;
|
|
57
|
+
totalOutputChars?: undefined;
|
|
58
|
+
retention?: undefined;
|
|
59
|
+
} | {
|
|
60
|
+
success: boolean;
|
|
61
|
+
taskId: string;
|
|
62
|
+
status: BackgroundTaskStatus;
|
|
63
|
+
command: string;
|
|
64
|
+
description: string;
|
|
65
|
+
startedAt: number;
|
|
66
|
+
endedAt: number;
|
|
67
|
+
exitCode: number;
|
|
68
|
+
signal: NodeJS.Signals;
|
|
69
|
+
output: string;
|
|
70
|
+
outputTruncated: boolean;
|
|
71
|
+
totalOutputChars: number;
|
|
72
|
+
retention: {
|
|
73
|
+
maxTerminalTasksRetained: number;
|
|
74
|
+
terminalTaskTtlMs: number;
|
|
75
|
+
evictedTasksTotal: number;
|
|
76
|
+
};
|
|
77
|
+
error?: undefined;
|
|
78
|
+
};
|
|
79
|
+
export declare const stopBackgroundTask: ({ taskId, reason, }: {
|
|
80
|
+
taskId: string;
|
|
81
|
+
reason?: string;
|
|
82
|
+
}) => Promise<{
|
|
83
|
+
success: boolean;
|
|
84
|
+
taskId: string;
|
|
85
|
+
status: BackgroundTaskStatus;
|
|
86
|
+
killed: boolean;
|
|
87
|
+
reason: string;
|
|
88
|
+
retention: {
|
|
89
|
+
maxTerminalTasksRetained: number;
|
|
90
|
+
terminalTaskTtlMs: number;
|
|
91
|
+
evictedTasksTotal: number;
|
|
92
|
+
};
|
|
93
|
+
message: string;
|
|
94
|
+
}> | {
|
|
95
|
+
success: boolean;
|
|
96
|
+
error: string;
|
|
97
|
+
taskId?: undefined;
|
|
98
|
+
status?: undefined;
|
|
99
|
+
message?: undefined;
|
|
100
|
+
} | {
|
|
101
|
+
success: boolean;
|
|
102
|
+
taskId: string;
|
|
103
|
+
status: "completed" | "failed" | "stopped";
|
|
104
|
+
message: string;
|
|
105
|
+
error?: undefined;
|
|
106
|
+
};
|
|
107
|
+
export declare const taskListTool: {
|
|
108
|
+
description: string;
|
|
109
|
+
parameters: z.ZodObject<{
|
|
110
|
+
activeOnly: z.ZodDefault<z.ZodBoolean>;
|
|
111
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
112
|
+
}, "strip", z.ZodTypeAny, {
|
|
113
|
+
activeOnly?: boolean;
|
|
114
|
+
limit?: number;
|
|
115
|
+
}, {
|
|
116
|
+
activeOnly?: boolean;
|
|
117
|
+
limit?: number;
|
|
118
|
+
}>;
|
|
119
|
+
execute: ({ activeOnly, limit }: {
|
|
120
|
+
activeOnly?: boolean;
|
|
121
|
+
limit?: number;
|
|
122
|
+
}) => Promise<{
|
|
123
|
+
success: boolean;
|
|
124
|
+
tasks: {
|
|
125
|
+
taskId: string;
|
|
126
|
+
command: string;
|
|
127
|
+
description: string;
|
|
128
|
+
cwd: string;
|
|
129
|
+
status: BackgroundTaskStatus;
|
|
130
|
+
startedAt: number;
|
|
131
|
+
endedAt: number;
|
|
132
|
+
pid: number;
|
|
133
|
+
exitCode: number;
|
|
134
|
+
signal: NodeJS.Signals;
|
|
135
|
+
retention: {
|
|
136
|
+
maxTerminalTasksRetained: number;
|
|
137
|
+
terminalTaskTtlMs: number;
|
|
138
|
+
evictedTasksTotal: number;
|
|
139
|
+
};
|
|
140
|
+
}[];
|
|
141
|
+
retention: {
|
|
142
|
+
maxTerminalTasksRetained: number;
|
|
143
|
+
terminalTaskTtlMs: number;
|
|
144
|
+
evictedTasksTotal: number;
|
|
145
|
+
};
|
|
146
|
+
}>;
|
|
147
|
+
};
|
|
148
|
+
export declare const taskOutputTool: {
|
|
149
|
+
description: string;
|
|
150
|
+
parameters: z.ZodObject<{
|
|
151
|
+
taskId: z.ZodString;
|
|
152
|
+
tailChars: z.ZodDefault<z.ZodNumber>;
|
|
153
|
+
}, "strip", z.ZodTypeAny, {
|
|
154
|
+
taskId?: string;
|
|
155
|
+
tailChars?: number;
|
|
156
|
+
}, {
|
|
157
|
+
taskId?: string;
|
|
158
|
+
tailChars?: number;
|
|
159
|
+
}>;
|
|
160
|
+
execute: ({ taskId, tailChars }: {
|
|
161
|
+
taskId: string;
|
|
162
|
+
tailChars?: number;
|
|
163
|
+
}) => Promise<{
|
|
164
|
+
success: boolean;
|
|
165
|
+
error: string;
|
|
166
|
+
taskId?: undefined;
|
|
167
|
+
status?: undefined;
|
|
168
|
+
command?: undefined;
|
|
169
|
+
description?: undefined;
|
|
170
|
+
startedAt?: undefined;
|
|
171
|
+
endedAt?: undefined;
|
|
172
|
+
exitCode?: undefined;
|
|
173
|
+
signal?: undefined;
|
|
174
|
+
output?: undefined;
|
|
175
|
+
outputTruncated?: undefined;
|
|
176
|
+
totalOutputChars?: undefined;
|
|
177
|
+
retention?: undefined;
|
|
178
|
+
} | {
|
|
179
|
+
success: boolean;
|
|
180
|
+
taskId: string;
|
|
181
|
+
status: BackgroundTaskStatus;
|
|
182
|
+
command: string;
|
|
183
|
+
description: string;
|
|
184
|
+
startedAt: number;
|
|
185
|
+
endedAt: number;
|
|
186
|
+
exitCode: number;
|
|
187
|
+
signal: NodeJS.Signals;
|
|
188
|
+
output: string;
|
|
189
|
+
outputTruncated: boolean;
|
|
190
|
+
totalOutputChars: number;
|
|
191
|
+
retention: {
|
|
192
|
+
maxTerminalTasksRetained: number;
|
|
193
|
+
terminalTaskTtlMs: number;
|
|
194
|
+
evictedTasksTotal: number;
|
|
195
|
+
};
|
|
196
|
+
error?: undefined;
|
|
197
|
+
}>;
|
|
198
|
+
};
|
|
199
|
+
export declare const taskStopTool: {
|
|
200
|
+
description: string;
|
|
201
|
+
parameters: z.ZodObject<{
|
|
202
|
+
taskId: z.ZodString;
|
|
203
|
+
reason: z.ZodDefault<z.ZodString>;
|
|
204
|
+
}, "strip", z.ZodTypeAny, {
|
|
205
|
+
taskId?: string;
|
|
206
|
+
reason?: string;
|
|
207
|
+
}, {
|
|
208
|
+
taskId?: string;
|
|
209
|
+
reason?: string;
|
|
210
|
+
}>;
|
|
211
|
+
execute: ({ taskId, reason }: {
|
|
212
|
+
taskId: string;
|
|
213
|
+
reason?: string;
|
|
214
|
+
}) => Promise<{
|
|
215
|
+
success: boolean;
|
|
216
|
+
taskId: string;
|
|
217
|
+
status: BackgroundTaskStatus;
|
|
218
|
+
killed: boolean;
|
|
219
|
+
reason: string;
|
|
220
|
+
retention: {
|
|
221
|
+
maxTerminalTasksRetained: number;
|
|
222
|
+
terminalTaskTtlMs: number;
|
|
223
|
+
evictedTasksTotal: number;
|
|
224
|
+
};
|
|
225
|
+
message: string;
|
|
226
|
+
} | {
|
|
227
|
+
success: boolean;
|
|
228
|
+
error: string;
|
|
229
|
+
taskId?: undefined;
|
|
230
|
+
status?: undefined;
|
|
231
|
+
message?: undefined;
|
|
232
|
+
} | {
|
|
233
|
+
success: boolean;
|
|
234
|
+
taskId: string;
|
|
235
|
+
status: "completed" | "failed" | "stopped";
|
|
236
|
+
message: string;
|
|
237
|
+
error?: undefined;
|
|
238
|
+
}>;
|
|
239
|
+
};
|
|
240
|
+
export {};
|