@wavexzore/sandbox 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/Dockerfile +14 -0
- package/LICENSE +661 -0
- package/NOTICE +3 -0
- package/README.md +153 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/sandbox/cli/install.d.ts +5 -0
- package/dist/sandbox/cli/install.js +335 -0
- package/dist/sandbox/cli/local-store.d.ts +87 -0
- package/dist/sandbox/cli/local-store.js +604 -0
- package/dist/sandbox/cli/opencode-config.d.ts +25 -0
- package/dist/sandbox/cli/opencode-config.js +240 -0
- package/dist/sandbox/cli/path.d.ts +64 -0
- package/dist/sandbox/cli/path.js +127 -0
- package/dist/sandbox/cli/types.d.ts +145 -0
- package/dist/sandbox/cli/types.js +6 -0
- package/dist/sandbox/cli/wavexzore-sandbox.d.ts +65 -0
- package/dist/sandbox/cli/wavexzore-sandbox.js +577 -0
- package/dist/sandbox/core/cli-helper.d.ts +19 -0
- package/dist/sandbox/core/cli-helper.js +64 -0
- package/dist/sandbox/core/docker-archive-utils.d.ts +3 -0
- package/dist/sandbox/core/docker-archive-utils.js +50 -0
- package/dist/sandbox/core/docker-sandbox.d.ts +51 -0
- package/dist/sandbox/core/docker-sandbox.js +675 -0
- package/dist/sandbox/core/edit/filediff.d.ts +16 -0
- package/dist/sandbox/core/edit/filediff.js +21 -0
- package/dist/sandbox/core/edit/index.d.ts +5 -0
- package/dist/sandbox/core/edit/index.js +5 -0
- package/dist/sandbox/core/edit/line-endings.d.ts +4 -0
- package/dist/sandbox/core/edit/line-endings.js +10 -0
- package/dist/sandbox/core/edit/lock.d.ts +1 -0
- package/dist/sandbox/core/edit/lock.js +18 -0
- package/dist/sandbox/core/edit/replace.d.ts +10 -0
- package/dist/sandbox/core/edit/replace.js +14 -0
- package/dist/sandbox/core/edit/replacers.d.ts +15 -0
- package/dist/sandbox/core/edit/replacers.js +241 -0
- package/dist/sandbox/core/logger.d.ts +15 -0
- package/dist/sandbox/core/logger.js +59 -0
- package/dist/sandbox/core/lsp/client.d.ts +63 -0
- package/dist/sandbox/core/lsp/client.js +533 -0
- package/dist/sandbox/core/lsp/config.d.ts +13 -0
- package/dist/sandbox/core/lsp/config.js +36 -0
- package/dist/sandbox/core/lsp/diagnostics.d.ts +12 -0
- package/dist/sandbox/core/lsp/diagnostics.js +65 -0
- package/dist/sandbox/core/lsp/index.d.ts +4 -0
- package/dist/sandbox/core/lsp/index.js +4 -0
- package/dist/sandbox/core/lsp/language.d.ts +24 -0
- package/dist/sandbox/core/lsp/language.js +249 -0
- package/dist/sandbox/core/lsp/manager.d.ts +77 -0
- package/dist/sandbox/core/lsp/manager.js +237 -0
- package/dist/sandbox/core/lsp/tooling.d.ts +14 -0
- package/dist/sandbox/core/lsp/tooling.js +78 -0
- package/dist/sandbox/core/patch-parser.d.ts +23 -0
- package/dist/sandbox/core/patch-parser.js +248 -0
- package/dist/sandbox/core/path-map.d.ts +9 -0
- package/dist/sandbox/core/path-map.js +73 -0
- package/dist/sandbox/core/project-data-storage.d.ts +42 -0
- package/dist/sandbox/core/project-data-storage.js +167 -0
- package/dist/sandbox/core/read/binary.d.ts +4 -0
- package/dist/sandbox/core/read/binary.js +80 -0
- package/dist/sandbox/core/read/format.d.ts +38 -0
- package/dist/sandbox/core/read/format.js +85 -0
- package/dist/sandbox/core/read/index.d.ts +3 -0
- package/dist/sandbox/core/read/index.js +3 -0
- package/dist/sandbox/core/read/permissions.d.ts +7 -0
- package/dist/sandbox/core/read/permissions.js +13 -0
- package/dist/sandbox/core/session-manager.d.ts +29 -0
- package/dist/sandbox/core/session-manager.js +338 -0
- package/dist/sandbox/core/shell/config.d.ts +7 -0
- package/dist/sandbox/core/shell/config.js +82 -0
- package/dist/sandbox/core/shell/output.d.ts +35 -0
- package/dist/sandbox/core/shell/output.js +80 -0
- package/dist/sandbox/core/shell/parser.d.ts +7 -0
- package/dist/sandbox/core/shell/parser.js +122 -0
- package/dist/sandbox/core/shell/permissions.d.ts +13 -0
- package/dist/sandbox/core/shell/permissions.js +33 -0
- package/dist/sandbox/core/shell/workdir.d.ts +4 -0
- package/dist/sandbox/core/shell/workdir.js +19 -0
- package/dist/sandbox/core/stream-utils.d.ts +23 -0
- package/dist/sandbox/core/stream-utils.js +97 -0
- package/dist/sandbox/core/toast.d.ts +47 -0
- package/dist/sandbox/core/toast.js +73 -0
- package/dist/sandbox/core/types.d.ts +159 -0
- package/dist/sandbox/core/types.js +11 -0
- package/dist/sandbox/core/write/bom.d.ts +8 -0
- package/dist/sandbox/core/write/bom.js +15 -0
- package/dist/sandbox/core/write/config.d.ts +14 -0
- package/dist/sandbox/core/write/config.js +188 -0
- package/dist/sandbox/core/write/diagnostics.d.ts +19 -0
- package/dist/sandbox/core/write/diagnostics.js +120 -0
- package/dist/sandbox/core/write/diff.d.ts +7 -0
- package/dist/sandbox/core/write/diff.js +21 -0
- package/dist/sandbox/core/write/formatter.d.ts +16 -0
- package/dist/sandbox/core/write/formatter.js +51 -0
- package/dist/sandbox/core/write/index.d.ts +6 -0
- package/dist/sandbox/core/write/index.js +5 -0
- package/dist/sandbox/core/write/permissions.d.ts +13 -0
- package/dist/sandbox/core/write/permissions.js +19 -0
- package/dist/sandbox/core/write/pipeline.d.ts +48 -0
- package/dist/sandbox/core/write/pipeline.js +229 -0
- package/dist/sandbox/core/write/read-tracker.d.ts +13 -0
- package/dist/sandbox/core/write/read-tracker.js +30 -0
- package/dist/sandbox/git/host-git-manager.d.ts +40 -0
- package/dist/sandbox/git/host-git-manager.js +278 -0
- package/dist/sandbox/git/index.d.ts +5 -0
- package/dist/sandbox/git/index.js +5 -0
- package/dist/sandbox/git/sandbox-git-manager.d.ts +14 -0
- package/dist/sandbox/git/sandbox-git-manager.js +54 -0
- package/dist/sandbox/git/session-git-manager.d.ts +18 -0
- package/dist/sandbox/git/session-git-manager.js +85 -0
- package/dist/sandbox/index.d.ts +205 -0
- package/dist/sandbox/index.js +70 -0
- package/dist/sandbox/plugins/custom-tools.d.ts +203 -0
- package/dist/sandbox/plugins/custom-tools.js +15 -0
- package/dist/sandbox/plugins/session-events.d.ts +10 -0
- package/dist/sandbox/plugins/session-events.js +56 -0
- package/dist/sandbox/plugins/system-transform.d.ts +10 -0
- package/dist/sandbox/plugins/system-transform.js +23 -0
- package/dist/sandbox/tools/bash-output.d.ts +17 -0
- package/dist/sandbox/tools/bash-output.js +35 -0
- package/dist/sandbox/tools/bash-status.d.ts +13 -0
- package/dist/sandbox/tools/bash-status.js +29 -0
- package/dist/sandbox/tools/bash-stop.d.ts +13 -0
- package/dist/sandbox/tools/bash-stop.js +28 -0
- package/dist/sandbox/tools/bash.d.ts +26 -0
- package/dist/sandbox/tools/bash.js +120 -0
- package/dist/sandbox/tools/edit.d.ts +20 -0
- package/dist/sandbox/tools/edit.js +87 -0
- package/dist/sandbox/tools/get-preview-url.d.ts +17 -0
- package/dist/sandbox/tools/get-preview-url.js +16 -0
- package/dist/sandbox/tools/glob.d.ts +17 -0
- package/dist/sandbox/tools/glob.js +23 -0
- package/dist/sandbox/tools/grep.d.ts +17 -0
- package/dist/sandbox/tools/grep.js +23 -0
- package/dist/sandbox/tools/ls.d.ts +17 -0
- package/dist/sandbox/tools/ls.js +21 -0
- package/dist/sandbox/tools/lsp.d.ts +41 -0
- package/dist/sandbox/tools/lsp.js +198 -0
- package/dist/sandbox/tools/multiedit.d.ts +24 -0
- package/dist/sandbox/tools/multiedit.js +83 -0
- package/dist/sandbox/tools/patch.d.ts +14 -0
- package/dist/sandbox/tools/patch.js +260 -0
- package/dist/sandbox/tools/read.d.ts +22 -0
- package/dist/sandbox/tools/read.js +105 -0
- package/dist/sandbox/tools/write.d.ts +16 -0
- package/dist/sandbox/tools/write.js +27 -0
- package/dist/sandbox/tools.d.ts +200 -0
- package/dist/sandbox/tools.js +43 -0
- package/package.json +55 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Adds sandbox-specific instructions to the system prompt.
|
|
7
|
+
*/
|
|
8
|
+
export async function systemPromptTransform(ctx, repoPath) {
|
|
9
|
+
return async (input, output) => {
|
|
10
|
+
output.system.push([
|
|
11
|
+
'## Docker Sandbox Integration',
|
|
12
|
+
'This session is integrated with a Docker sandbox.',
|
|
13
|
+
`The main project repository is located at: ${repoPath}.`,
|
|
14
|
+
'Bash commands run inside the Docker sandbox, defaulting to this project directory.',
|
|
15
|
+
"Prefer the bash tool's workdir parameter over inline 'cd ... && ...' commands.",
|
|
16
|
+
'Bash output is truncated automatically when large; full output is saved outside the project when available.',
|
|
17
|
+
'Use read/write/edit/multiedit/apply_patch/glob/grep for file operations and search instead of shelling out to cat/echo/sed/find/grep when a dedicated tool fits.',
|
|
18
|
+
'Put all projects in the project directory. Do NOT try to use the current working directory of the host system.',
|
|
19
|
+
"When executing long-running commands, use the 'background' option and manage them with bash_status, bash_output, and bash_stop.",
|
|
20
|
+
'Before showing a preview URL, ensure the server is running in the sandbox on that port.',
|
|
21
|
+
].join('\n'));
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
3
|
+
import type { ToolContext } from '@opencode-ai/plugin/tool';
|
|
4
|
+
import type { SandboxSessionManager } from '../core/session-manager.js';
|
|
5
|
+
export declare const bashOutputTool: (sessionManager: SandboxSessionManager, projectId: string, worktree: string, pluginCtx: PluginInput) => {
|
|
6
|
+
description: string;
|
|
7
|
+
args: {
|
|
8
|
+
cmdId: z.ZodString;
|
|
9
|
+
maxBytes: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
maxLines: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
};
|
|
12
|
+
execute(args: {
|
|
13
|
+
cmdId: string;
|
|
14
|
+
maxBytes?: number;
|
|
15
|
+
maxLines?: number;
|
|
16
|
+
}, ctx: ToolContext): Promise<string>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { loadShellToolConfig } from '../core/shell/config.js';
|
|
3
|
+
export const bashOutputTool = (sessionManager, projectId, worktree, pluginCtx) => ({
|
|
4
|
+
description: 'Reads output from a managed background bash command in the Docker sandbox',
|
|
5
|
+
args: {
|
|
6
|
+
cmdId: z.string().min(1),
|
|
7
|
+
maxBytes: z.number().int().positive().optional().describe('Maximum bytes to read from stdout/stderr tail'),
|
|
8
|
+
maxLines: z.number().int().positive().optional().describe('Maximum lines to read from stdout/stderr tail'),
|
|
9
|
+
},
|
|
10
|
+
async execute(args, ctx) {
|
|
11
|
+
const sandbox = await sessionManager.getSandbox(ctx.sessionID, projectId, worktree, pluginCtx);
|
|
12
|
+
const shellConfig = loadShellToolConfig(worktree);
|
|
13
|
+
const output = await sandbox.process.readBackgroundCommand(args.cmdId, {
|
|
14
|
+
maxOutputBytes: args.maxBytes ?? shellConfig.maxOutputBytes,
|
|
15
|
+
maxOutputLines: args.maxLines ?? shellConfig.maxOutputLines,
|
|
16
|
+
});
|
|
17
|
+
if (typeof ctx.metadata === 'function') {
|
|
18
|
+
ctx.metadata({
|
|
19
|
+
title: `bash_output ${args.cmdId}`,
|
|
20
|
+
metadata: {
|
|
21
|
+
cmdId: output.cmdId,
|
|
22
|
+
stdoutBytes: output.stdoutBytes,
|
|
23
|
+
stderrBytes: output.stderrBytes,
|
|
24
|
+
stdoutLines: output.stdoutLines,
|
|
25
|
+
stderrLines: output.stderrLines,
|
|
26
|
+
truncated: output.truncated,
|
|
27
|
+
runDir: output.runDir,
|
|
28
|
+
sandbox: sandbox.id,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const text = output.output || '(no output)';
|
|
33
|
+
return `${text}\n\n<shell_background_output>\ncmdId: ${output.cmdId}\nstdoutBytes: ${output.stdoutBytes}\nstderrBytes: ${output.stderrBytes}\nstdoutLines: ${output.stdoutLines ?? 0}\nstderrLines: ${output.stderrLines ?? 0}\ntruncated: ${output.truncated}\n${output.runDir ? `runDir: ${output.runDir}\n` : ''}</shell_background_output>`;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
3
|
+
import type { ToolContext } from '@opencode-ai/plugin/tool';
|
|
4
|
+
import type { SandboxSessionManager } from '../core/session-manager.js';
|
|
5
|
+
export declare const bashStatusTool: (sessionManager: SandboxSessionManager, projectId: string, worktree: string, pluginCtx: PluginInput) => {
|
|
6
|
+
description: string;
|
|
7
|
+
args: {
|
|
8
|
+
cmdId: z.ZodString;
|
|
9
|
+
};
|
|
10
|
+
execute(args: {
|
|
11
|
+
cmdId: string;
|
|
12
|
+
}, ctx: ToolContext): Promise<string>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const bashStatusTool = (sessionManager, projectId, worktree, pluginCtx) => ({
|
|
3
|
+
description: 'Checks the status of a managed background bash command in the Docker sandbox',
|
|
4
|
+
args: {
|
|
5
|
+
cmdId: z.string().min(1),
|
|
6
|
+
},
|
|
7
|
+
async execute(args, ctx) {
|
|
8
|
+
const sandbox = await sessionManager.getSandbox(ctx.sessionID, projectId, worktree, pluginCtx);
|
|
9
|
+
const status = await sandbox.process.getBackgroundCommand(args.cmdId);
|
|
10
|
+
if (typeof ctx.metadata === 'function') {
|
|
11
|
+
ctx.metadata({
|
|
12
|
+
title: `bash_status ${args.cmdId}`,
|
|
13
|
+
metadata: {
|
|
14
|
+
...status,
|
|
15
|
+
sandbox: sandbox.id,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return [
|
|
20
|
+
`cmdId: ${status.cmdId}`,
|
|
21
|
+
`status: ${status.status}`,
|
|
22
|
+
`exitCode: ${status.exitCode === null ? 'null' : status.exitCode}`,
|
|
23
|
+
status.pid ? `pid: ${status.pid}` : undefined,
|
|
24
|
+
status.runDir ? `runDir: ${status.runDir}` : undefined,
|
|
25
|
+
]
|
|
26
|
+
.filter(Boolean)
|
|
27
|
+
.join('\n');
|
|
28
|
+
},
|
|
29
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
3
|
+
import type { ToolContext } from '@opencode-ai/plugin/tool';
|
|
4
|
+
import type { SandboxSessionManager } from '../core/session-manager.js';
|
|
5
|
+
export declare const bashStopTool: (sessionManager: SandboxSessionManager, projectId: string, worktree: string, pluginCtx: PluginInput) => {
|
|
6
|
+
description: string;
|
|
7
|
+
args: {
|
|
8
|
+
cmdId: z.ZodString;
|
|
9
|
+
};
|
|
10
|
+
execute(args: {
|
|
11
|
+
cmdId: string;
|
|
12
|
+
}, ctx: ToolContext): Promise<string>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const bashStopTool = (sessionManager, projectId, worktree, pluginCtx) => ({
|
|
3
|
+
description: 'Stops a managed background bash command in the Docker sandbox',
|
|
4
|
+
args: {
|
|
5
|
+
cmdId: z.string().min(1),
|
|
6
|
+
},
|
|
7
|
+
async execute(args, ctx) {
|
|
8
|
+
const sandbox = await sessionManager.getSandbox(ctx.sessionID, projectId, worktree, pluginCtx);
|
|
9
|
+
const status = await sandbox.process.stopBackgroundCommand(args.cmdId);
|
|
10
|
+
if (typeof ctx.metadata === 'function') {
|
|
11
|
+
ctx.metadata({
|
|
12
|
+
title: `bash_stop ${args.cmdId}`,
|
|
13
|
+
metadata: {
|
|
14
|
+
...status,
|
|
15
|
+
sandbox: sandbox.id,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return [
|
|
20
|
+
`cmdId: ${status.cmdId}`,
|
|
21
|
+
`status: ${status.status}`,
|
|
22
|
+
`exitCode: ${status.exitCode === null ? 'null' : status.exitCode}`,
|
|
23
|
+
status.runDir ? `runDir: ${status.runDir}` : undefined,
|
|
24
|
+
]
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join('\n');
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
7
|
+
import type { ToolContext } from '@opencode-ai/plugin/tool';
|
|
8
|
+
import type { SandboxSessionManager } from '../core/session-manager.js';
|
|
9
|
+
import type { PathMapper } from '../core/path-map.js';
|
|
10
|
+
export declare const bashTool: (sessionManager: SandboxSessionManager, projectId: string, worktree: string, pluginCtx: PluginInput, mapPath: PathMapper) => {
|
|
11
|
+
description: string;
|
|
12
|
+
args: {
|
|
13
|
+
command: z.ZodString;
|
|
14
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
15
|
+
workdir: z.ZodOptional<z.ZodString>;
|
|
16
|
+
description: z.ZodOptional<z.ZodString>;
|
|
17
|
+
background: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
+
};
|
|
19
|
+
execute(args: {
|
|
20
|
+
command: string;
|
|
21
|
+
timeout?: number;
|
|
22
|
+
workdir?: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
background?: boolean;
|
|
25
|
+
}, ctx: ToolContext): Promise<string>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { commandDescription, requestBashPermission } from '../core/shell/permissions.js';
|
|
7
|
+
import { previewOutput } from '../core/shell/output.js';
|
|
8
|
+
import { resolveShellWorkdir } from '../core/shell/workdir.js';
|
|
9
|
+
import { loadShellToolConfig } from '../core/shell/config.js';
|
|
10
|
+
export const bashTool = (sessionManager, projectId, worktree, pluginCtx, mapPath) => ({
|
|
11
|
+
description: 'Executes shell commands in the Docker sandbox with OpenCode-style bash permission, workdir, timeout, metadata, and output truncation. Prefer dedicated read/write/edit/glob/grep tools for file operations.',
|
|
12
|
+
args: {
|
|
13
|
+
command: z.string().min(1).describe('The command to execute'),
|
|
14
|
+
timeout: z.number().int().positive().optional().describe('Optional timeout in milliseconds'),
|
|
15
|
+
workdir: z
|
|
16
|
+
.string()
|
|
17
|
+
.optional()
|
|
18
|
+
.describe("Working directory. Defaults to the sandbox project root; prefer this over 'cd'."),
|
|
19
|
+
description: z.string().optional().describe('Clear, concise description of what this command does'),
|
|
20
|
+
background: z.boolean().optional().describe('Run as a managed long-lived background command'),
|
|
21
|
+
},
|
|
22
|
+
async execute(args, ctx) {
|
|
23
|
+
const sessionId = ctx.sessionID;
|
|
24
|
+
const sandbox = await sessionManager.getSandbox(sessionId, projectId, worktree, pluginCtx);
|
|
25
|
+
const shellConfig = loadShellToolConfig(worktree);
|
|
26
|
+
const cwd = resolveShellWorkdir(args.workdir, mapPath, {
|
|
27
|
+
allowOutsideProject: shellConfig.allowWorkdirOutsideProject,
|
|
28
|
+
});
|
|
29
|
+
const description = commandDescription(args.command, args.description);
|
|
30
|
+
const timeoutMs = args.timeout ?? shellConfig.defaultTimeoutMs;
|
|
31
|
+
await requestBashPermission({
|
|
32
|
+
ctx,
|
|
33
|
+
command: args.command,
|
|
34
|
+
description,
|
|
35
|
+
workdir: cwd,
|
|
36
|
+
timeoutMs,
|
|
37
|
+
background: args.background,
|
|
38
|
+
sandboxId: sandbox.id,
|
|
39
|
+
});
|
|
40
|
+
if (args.background) {
|
|
41
|
+
const result = await sandbox.process.startBackgroundCommand(args.command, {
|
|
42
|
+
cwd,
|
|
43
|
+
sessionId,
|
|
44
|
+
});
|
|
45
|
+
if (typeof ctx.metadata === 'function') {
|
|
46
|
+
ctx.metadata({
|
|
47
|
+
title: description,
|
|
48
|
+
metadata: {
|
|
49
|
+
command: args.command,
|
|
50
|
+
description,
|
|
51
|
+
workdir: cwd,
|
|
52
|
+
background: true,
|
|
53
|
+
cmdId: result.cmdId,
|
|
54
|
+
runDir: result.runDir,
|
|
55
|
+
sandbox: sandbox.id,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return [
|
|
60
|
+
`Command started in background.`,
|
|
61
|
+
`cmdId: ${result.cmdId}`,
|
|
62
|
+
`workdir: ${cwd}`,
|
|
63
|
+
`runDir: ${result.runDir}`,
|
|
64
|
+
'',
|
|
65
|
+
'Use bash_status, bash_output, or bash_stop with this cmdId to manage the command.',
|
|
66
|
+
].join('\n');
|
|
67
|
+
}
|
|
68
|
+
const result = await sandbox.process.executeCommand(args.command, {
|
|
69
|
+
cwd,
|
|
70
|
+
timeoutMs,
|
|
71
|
+
signal: ctx.abort,
|
|
72
|
+
sessionId,
|
|
73
|
+
maxOutputBytes: shellConfig.maxOutputBytes,
|
|
74
|
+
maxOutputLines: shellConfig.maxOutputLines,
|
|
75
|
+
onUpdate: (update) => {
|
|
76
|
+
if (typeof ctx.metadata !== 'function')
|
|
77
|
+
return;
|
|
78
|
+
ctx.metadata({
|
|
79
|
+
title: description,
|
|
80
|
+
metadata: {
|
|
81
|
+
command: args.command,
|
|
82
|
+
description,
|
|
83
|
+
workdir: cwd,
|
|
84
|
+
output: previewOutput(update.output || ''),
|
|
85
|
+
truncated: update.truncated,
|
|
86
|
+
stdoutBytes: update.stdoutBytes,
|
|
87
|
+
stderrBytes: update.stderrBytes,
|
|
88
|
+
stdoutLines: update.stdoutLines,
|
|
89
|
+
stderrLines: update.stderrLines,
|
|
90
|
+
durationMs: update.durationMs,
|
|
91
|
+
sandbox: sandbox.id,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
if (typeof ctx.metadata === 'function') {
|
|
97
|
+
ctx.metadata({
|
|
98
|
+
title: description,
|
|
99
|
+
metadata: {
|
|
100
|
+
command: args.command,
|
|
101
|
+
description,
|
|
102
|
+
workdir: cwd,
|
|
103
|
+
output: previewOutput(result.result || ''),
|
|
104
|
+
exit: result.exitCode,
|
|
105
|
+
timedOut: result.timedOut,
|
|
106
|
+
aborted: result.aborted,
|
|
107
|
+
truncated: result.truncated,
|
|
108
|
+
outputPath: result.outputPath,
|
|
109
|
+
stdoutBytes: result.stdoutBytes,
|
|
110
|
+
stderrBytes: result.stderrBytes,
|
|
111
|
+
stdoutLines: result.stdoutLines,
|
|
112
|
+
stderrLines: result.stderrLines,
|
|
113
|
+
durationMs: result.durationMs,
|
|
114
|
+
sandbox: sandbox.id,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return result.result;
|
|
119
|
+
},
|
|
120
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
3
|
+
import type { ToolContext } from '@opencode-ai/plugin/tool';
|
|
4
|
+
import type { SandboxSessionManager } from '../core/session-manager.js';
|
|
5
|
+
import type { PathMapper } from '../core/path-map.js';
|
|
6
|
+
export declare const editTool: (sessionManager: SandboxSessionManager, projectId: string, worktree: string, pluginCtx: PluginInput, mapPath: PathMapper) => {
|
|
7
|
+
description: string;
|
|
8
|
+
args: {
|
|
9
|
+
filePath: z.ZodString;
|
|
10
|
+
oldString: z.ZodString;
|
|
11
|
+
newString: z.ZodString;
|
|
12
|
+
replaceAll: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
};
|
|
14
|
+
execute(args: {
|
|
15
|
+
filePath: string;
|
|
16
|
+
oldString: string;
|
|
17
|
+
newString: string;
|
|
18
|
+
replaceAll?: boolean;
|
|
19
|
+
}, ctx: ToolContext): Promise<string>;
|
|
20
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { decodeUtf8, sandboxWriteFile, splitBom } from '../core/write/index.js';
|
|
3
|
+
import { applyOpenCodeEdit, createFileDiff, withFileLock } from '../core/edit/index.js';
|
|
4
|
+
function metadataDiagnostics(diagnostics) {
|
|
5
|
+
return {
|
|
6
|
+
current: diagnostics.current,
|
|
7
|
+
other: diagnostics.other,
|
|
8
|
+
unavailable: diagnostics.unavailable,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export const editTool = (sessionManager, projectId, worktree, pluginCtx, mapPath) => ({
|
|
12
|
+
description: 'Replaces text in a file in Docker sandbox using OpenCode-like edit permission, fuzzy matching, diff metadata, formatter, and host LSP diagnostics',
|
|
13
|
+
args: {
|
|
14
|
+
filePath: z.string(),
|
|
15
|
+
oldString: z.string(),
|
|
16
|
+
newString: z.string(),
|
|
17
|
+
replaceAll: z.boolean().optional().describe('Replace all occurrences of oldString (default false)'),
|
|
18
|
+
},
|
|
19
|
+
async execute(args, ctx) {
|
|
20
|
+
if (args.oldString === args.newString) {
|
|
21
|
+
throw new Error('No changes to apply: oldString and newString are identical.');
|
|
22
|
+
}
|
|
23
|
+
const sandbox = await sessionManager.getSandbox(ctx.sessionID, projectId, worktree, pluginCtx);
|
|
24
|
+
const containerPath = mapPath.toContainer(args.filePath);
|
|
25
|
+
const hostPath = mapPath.toHost(containerPath);
|
|
26
|
+
return withFileLock(hostPath, async () => {
|
|
27
|
+
let buffer;
|
|
28
|
+
let oldExists = false;
|
|
29
|
+
if (args.oldString !== '') {
|
|
30
|
+
try {
|
|
31
|
+
buffer = await sandbox.fs.downloadFile(containerPath);
|
|
32
|
+
oldExists = true;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
throw new Error(`File ${args.filePath} not found`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
buffer = await sandbox.fs.downloadFile(containerPath).catch(() => undefined);
|
|
40
|
+
oldExists = Boolean(buffer);
|
|
41
|
+
}
|
|
42
|
+
const oldContent = buffer ? splitBom(decodeUtf8(buffer)).text : '';
|
|
43
|
+
const nextContent = args.oldString === ''
|
|
44
|
+
? args.newString
|
|
45
|
+
: applyOpenCodeEdit({
|
|
46
|
+
content: oldContent,
|
|
47
|
+
oldString: args.oldString,
|
|
48
|
+
newString: args.newString,
|
|
49
|
+
replaceAll: args.replaceAll,
|
|
50
|
+
}).content;
|
|
51
|
+
const result = await sandboxWriteFile({
|
|
52
|
+
ctx,
|
|
53
|
+
sandbox,
|
|
54
|
+
sessionID: ctx.sessionID,
|
|
55
|
+
worktree,
|
|
56
|
+
paths: mapPath,
|
|
57
|
+
filePath: args.filePath,
|
|
58
|
+
content: nextContent,
|
|
59
|
+
operation: 'edit',
|
|
60
|
+
oldContentBuffer: buffer,
|
|
61
|
+
oldExists,
|
|
62
|
+
setMetadata: false,
|
|
63
|
+
});
|
|
64
|
+
const finalText = splitBom(result.finalContent).text;
|
|
65
|
+
const filediff = createFileDiff({ file: result.hostPath, oldContent, newContent: finalText });
|
|
66
|
+
if (typeof ctx.metadata === 'function') {
|
|
67
|
+
ctx.metadata({
|
|
68
|
+
title: result.relativePath,
|
|
69
|
+
metadata: {
|
|
70
|
+
operation: 'edit',
|
|
71
|
+
diagnostics: metadataDiagnostics(result.diagnostics),
|
|
72
|
+
filepath: result.hostPath,
|
|
73
|
+
containerPath: result.containerPath,
|
|
74
|
+
exists: result.exists,
|
|
75
|
+
diff: filediff.patch,
|
|
76
|
+
filediff,
|
|
77
|
+
formatted: result.formatted,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
let output = 'Edit applied successfully.';
|
|
82
|
+
if (result.diagnostics.output)
|
|
83
|
+
output += '\n\n' + result.diagnostics.output;
|
|
84
|
+
return output;
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
7
|
+
import type { ToolContext } from '@opencode-ai/plugin/tool';
|
|
8
|
+
import type { SandboxSessionManager } from '../core/session-manager.js';
|
|
9
|
+
export declare const getPreviewURLTool: (sessionManager: SandboxSessionManager, projectId: string, worktree: string, pluginCtx: PluginInput) => {
|
|
10
|
+
description: string;
|
|
11
|
+
args: {
|
|
12
|
+
port: z.ZodNumber;
|
|
13
|
+
};
|
|
14
|
+
execute(args: {
|
|
15
|
+
port: number;
|
|
16
|
+
}, ctx: ToolContext): Promise<string>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
export const getPreviewURLTool = (sessionManager, projectId, worktree, pluginCtx) => ({
|
|
7
|
+
description: 'Gets a preview URL for the Docker sandbox',
|
|
8
|
+
args: {
|
|
9
|
+
port: z.number(),
|
|
10
|
+
},
|
|
11
|
+
async execute(args, ctx) {
|
|
12
|
+
const sandbox = await sessionManager.getSandbox(ctx.sessionID, projectId, worktree, pluginCtx);
|
|
13
|
+
const previewLink = await sandbox.getPreviewLink(args.port);
|
|
14
|
+
return `Sandbox Preview URL: ${previewLink.url}`;
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
7
|
+
import type { ToolContext } from '@opencode-ai/plugin/tool';
|
|
8
|
+
import type { SandboxSessionManager } from '../core/session-manager.js';
|
|
9
|
+
export declare const globTool: (sessionManager: SandboxSessionManager, projectId: string, worktree: string, pluginCtx: PluginInput, mapPath: (p: string) => string) => {
|
|
10
|
+
description: string;
|
|
11
|
+
args: {
|
|
12
|
+
pattern: z.ZodString;
|
|
13
|
+
};
|
|
14
|
+
execute(args: {
|
|
15
|
+
pattern: string;
|
|
16
|
+
}, ctx: ToolContext): Promise<string>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
export const globTool = (sessionManager, projectId, worktree, pluginCtx, mapPath) => {
|
|
7
|
+
void mapPath;
|
|
8
|
+
return {
|
|
9
|
+
description: 'Searches for files matching a pattern in Docker sandbox',
|
|
10
|
+
args: {
|
|
11
|
+
pattern: z.string(),
|
|
12
|
+
},
|
|
13
|
+
async execute(args, ctx) {
|
|
14
|
+
const sandbox = await sessionManager.getSandbox(ctx.sessionID, projectId, worktree, pluginCtx);
|
|
15
|
+
const workDir = await sandbox.getWorkDir();
|
|
16
|
+
if (!workDir) {
|
|
17
|
+
throw new Error('Work directory not available');
|
|
18
|
+
}
|
|
19
|
+
const result = await sandbox.fs.searchFiles(workDir, args.pattern);
|
|
20
|
+
return result.files.join('\n');
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
7
|
+
import type { ToolContext } from '@opencode-ai/plugin/tool';
|
|
8
|
+
import type { SandboxSessionManager } from '../core/session-manager.js';
|
|
9
|
+
export declare const grepTool: (sessionManager: SandboxSessionManager, projectId: string, worktree: string, pluginCtx: PluginInput, mapPath: (p: string) => string) => {
|
|
10
|
+
description: string;
|
|
11
|
+
args: {
|
|
12
|
+
pattern: z.ZodString;
|
|
13
|
+
};
|
|
14
|
+
execute(args: {
|
|
15
|
+
pattern: string;
|
|
16
|
+
}, ctx: ToolContext): Promise<string>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
export const grepTool = (sessionManager, projectId, worktree, pluginCtx, mapPath) => {
|
|
7
|
+
void mapPath;
|
|
8
|
+
return {
|
|
9
|
+
description: 'Searches for text pattern in files in Docker sandbox',
|
|
10
|
+
args: {
|
|
11
|
+
pattern: z.string(),
|
|
12
|
+
},
|
|
13
|
+
async execute(args, ctx) {
|
|
14
|
+
const sandbox = await sessionManager.getSandbox(ctx.sessionID, projectId, worktree, pluginCtx);
|
|
15
|
+
const workDir = await sandbox.getWorkDir();
|
|
16
|
+
if (!workDir) {
|
|
17
|
+
throw new Error('Work directory not available');
|
|
18
|
+
}
|
|
19
|
+
const matches = await sandbox.fs.findFiles(workDir, args.pattern);
|
|
20
|
+
return matches.map((m) => `${m.file}:${m.line}: ${m.content}`).join('\n');
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
7
|
+
import type { ToolContext } from '@opencode-ai/plugin/tool';
|
|
8
|
+
import type { SandboxSessionManager } from '../core/session-manager.js';
|
|
9
|
+
export declare const lsTool: (sessionManager: SandboxSessionManager, projectId: string, worktree: string, pluginCtx: PluginInput, mapPath: (p: string) => string) => {
|
|
10
|
+
description: string;
|
|
11
|
+
args: {
|
|
12
|
+
dirPath: z.ZodOptional<z.ZodString>;
|
|
13
|
+
};
|
|
14
|
+
execute(args: {
|
|
15
|
+
dirPath?: string;
|
|
16
|
+
}, ctx: ToolContext): Promise<string>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Daytona Platforms Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
export const lsTool = (sessionManager, projectId, worktree, pluginCtx, mapPath) => ({
|
|
7
|
+
description: 'Lists files in a directory in Docker sandbox',
|
|
8
|
+
args: {
|
|
9
|
+
dirPath: z.string().optional(),
|
|
10
|
+
},
|
|
11
|
+
async execute(args, ctx) {
|
|
12
|
+
const sandbox = await sessionManager.getSandbox(ctx.sessionID, projectId, worktree, pluginCtx);
|
|
13
|
+
const workDir = await sandbox.getWorkDir();
|
|
14
|
+
const path = args.dirPath ? mapPath(args.dirPath) : workDir;
|
|
15
|
+
if (!path) {
|
|
16
|
+
throw new Error('Work directory not available');
|
|
17
|
+
}
|
|
18
|
+
const files = await sandbox.fs.listFiles(path);
|
|
19
|
+
return files.map((f) => f.name).join('\n');
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
3
|
+
import type { ToolContext } from '@opencode-ai/plugin/tool';
|
|
4
|
+
import type { SandboxSessionManager } from '../core/session-manager.js';
|
|
5
|
+
import type { PathMapper } from '../core/path-map.js';
|
|
6
|
+
declare const operations: readonly ["diagnostics", "hover", "documentSymbol", "workspaceSymbol", "references", "findReferences", "definition", "goToDefinition", "implementation", "goToImplementation", "prepareCallHierarchy", "incomingCalls", "outgoingCalls", "status"];
|
|
7
|
+
type LspOperation = (typeof operations)[number];
|
|
8
|
+
type LspArgs = {
|
|
9
|
+
operation: LspOperation;
|
|
10
|
+
filePath?: string;
|
|
11
|
+
line?: number;
|
|
12
|
+
character?: number;
|
|
13
|
+
query?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const lspTool: (sessionManager: SandboxSessionManager, projectId: string, worktree: string, pluginCtx: PluginInput, mapPath: PathMapper) => {
|
|
16
|
+
description: string;
|
|
17
|
+
args: {
|
|
18
|
+
operation: z.ZodEnum<{
|
|
19
|
+
status: "status";
|
|
20
|
+
diagnostics: "diagnostics";
|
|
21
|
+
hover: "hover";
|
|
22
|
+
documentSymbol: "documentSymbol";
|
|
23
|
+
workspaceSymbol: "workspaceSymbol";
|
|
24
|
+
references: "references";
|
|
25
|
+
findReferences: "findReferences";
|
|
26
|
+
definition: "definition";
|
|
27
|
+
goToDefinition: "goToDefinition";
|
|
28
|
+
implementation: "implementation";
|
|
29
|
+
goToImplementation: "goToImplementation";
|
|
30
|
+
prepareCallHierarchy: "prepareCallHierarchy";
|
|
31
|
+
incomingCalls: "incomingCalls";
|
|
32
|
+
outgoingCalls: "outgoingCalls";
|
|
33
|
+
}>;
|
|
34
|
+
filePath: z.ZodOptional<z.ZodString>;
|
|
35
|
+
line: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
character: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
query: z.ZodOptional<z.ZodString>;
|
|
38
|
+
};
|
|
39
|
+
execute(args: LspArgs, ctx: ToolContext): Promise<string>;
|
|
40
|
+
};
|
|
41
|
+
export {};
|