dotdo 0.0.2 → 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/cli/README.md +238 -0
- package/cli/agent.ts +72 -0
- package/cli/bin.js +44 -0
- package/cli/bin.ts +38 -0
- package/cli/build.ts +157 -0
- package/cli/commands/auth/login.ts +14 -0
- package/cli/commands/auth/logout.ts +6 -0
- package/cli/commands/auth/whoami.ts +16 -0
- package/cli/commands/deploy-multi.ts +245 -0
- package/cli/commands/dev/deploy.ts +100 -0
- package/cli/commands/dev/dev.ts +95 -0
- package/cli/commands/dev/logs.ts +91 -0
- package/cli/commands/dev-local.ts +88 -0
- package/cli/commands/do-ops.ts +314 -0
- package/cli/commands/index.ts +100 -0
- package/cli/commands/init.ts +247 -0
- package/cli/commands/introspect/emitter.ts +315 -0
- package/cli/commands/introspect/index.ts +193 -0
- package/cli/commands/link.ts +598 -0
- package/cli/commands/snippets.ts +415 -0
- package/cli/commands/tunnel.ts +239 -0
- package/cli/device-auth.ts +289 -0
- package/cli/fallback.ts +12 -0
- package/cli/index.ts +121 -0
- package/cli/main.ts +246 -0
- package/cli/mcp-stdio.ts +790 -0
- package/cli/package.json +62 -0
- package/cli/runtime/do-registry.ts +193 -0
- package/cli/runtime/embedded-db.ts +344 -0
- package/cli/runtime/index.ts +9 -0
- package/cli/runtime/miniflare-adapter.ts +162 -0
- package/cli/sandbox.ts +82 -0
- package/cli/src/args.ts +174 -0
- package/cli/src/auth.ts +55 -0
- package/cli/src/commands/call.ts +84 -0
- package/cli/src/commands/charge.ts +96 -0
- package/cli/src/commands/config.ts +115 -0
- package/cli/src/commands/email.ts +112 -0
- package/cli/src/commands/llm.ts +115 -0
- package/cli/src/commands/queue.ts +134 -0
- package/cli/src/commands/text.ts +86 -0
- package/cli/src/config.ts +185 -0
- package/cli/src/output.ts +246 -0
- package/cli/src/rpc.ts +192 -0
- package/cli/utils/config.ts +282 -0
- package/cli/utils/detect.ts +73 -0
- package/cli/utils/index.ts +15 -0
- package/cli/utils/logger.ts +232 -0
- package/dist/ai/template-literals.js +2 -2
- package/dist/ai/template-literals.js.map +1 -1
- package/dist/api/middleware/auth.js +3 -2
- package/dist/api/middleware/auth.js.map +1 -1
- package/dist/db/iceberg/inverted-index.js +1 -1
- package/dist/db/iceberg/inverted-index.js.map +1 -1
- package/dist/db/iceberg/puffin.js.map +1 -1
- package/dist/db/json-indexes.js.map +1 -1
- package/dist/db/objects.js.map +1 -1
- package/dist/db/primitives/dag-scheduler/index.js +1 -1
- package/dist/db/primitives/dag-scheduler/index.js.map +1 -1
- package/dist/db/primitives/observability.js.map +1 -1
- package/dist/db/primitives/schema-evolution.js.map +1 -1
- package/dist/db/primitives/temporal-store.js.map +1 -1
- package/dist/db/primitives/typed-column-store.js.map +1 -1
- package/dist/db/primitives/utils/duration.js.map +1 -1
- package/dist/db/primitives/utils/murmur3.js +12 -14
- package/dist/db/primitives/utils/murmur3.js.map +1 -1
- package/dist/db/primitives/window-manager.js.map +1 -1
- package/dist/db/stores.js.map +1 -1
- package/dist/db/things.js.map +1 -1
- package/dist/lib/DODispatcher.js +2 -2
- package/dist/lib/DODispatcher.js.map +1 -1
- package/dist/lib/auto-wiring.js.map +1 -1
- package/dist/lib/channels/email.js +1 -1
- package/dist/lib/channels/email.js.map +1 -1
- package/dist/lib/channels/slack-blockkit.js.map +1 -1
- package/dist/lib/cloudflare/ai.js +1 -1
- package/dist/lib/cloudflare/ai.js.map +1 -1
- package/dist/lib/cloudflare/kv.js +1 -1
- package/dist/lib/cloudflare/kv.js.map +1 -1
- package/dist/lib/cloudflare/r2.js +3 -3
- package/dist/lib/cloudflare/r2.js.map +1 -1
- package/dist/lib/cloudflare/vectorize.js.map +1 -1
- package/dist/lib/cloudflare/workflows.js.map +1 -1
- package/dist/lib/executors/AgenticFunctionExecutor.js.map +1 -1
- package/dist/lib/executors/CodeFunctionExecutor.js.map +1 -1
- package/dist/lib/executors/GenerativeFunctionExecutor.js.map +1 -1
- package/dist/lib/executors/HumanFunctionExecutor.js +1 -1
- package/dist/lib/executors/HumanFunctionExecutor.js.map +1 -1
- package/dist/lib/executors/ParallelStepExecutor.js.map +1 -1
- package/dist/lib/experiments.js.map +1 -1
- package/dist/lib/flags/store.js.map +1 -1
- package/dist/lib/functions/FunctionComposition.js.map +1 -1
- package/dist/lib/functions/FunctionMiddleware.js.map +1 -1
- package/dist/lib/functions/FunctionRegistry.js.map +1 -1
- package/dist/lib/humans/templates.js.map +1 -1
- package/dist/lib/identity.js +2 -2
- package/dist/lib/identity.js.map +1 -1
- package/dist/lib/logging/index.js.map +1 -1
- package/dist/lib/mixins/bash.js +1 -73
- package/dist/lib/mixins/bash.js.map +1 -1
- package/dist/lib/mixins/git.js +0 -5
- package/dist/lib/mixins/git.js.map +1 -1
- package/dist/lib/mixins/npm.js.map +1 -1
- package/dist/lib/noun-id.js.map +1 -1
- package/dist/lib/rate-limit/sliding-window.js.map +1 -1
- package/dist/lib/rpc/bindings.js.map +1 -1
- package/dist/lib/safe-stringify.js.map +1 -1
- package/dist/lib/sandbox/miniflare-sandbox.js.map +1 -1
- package/dist/lib/sqids.js.map +1 -1
- package/dist/lib/sql/adapters/node-sql-parser.js.map +1 -1
- package/dist/lib/sql/adapters/pgsql-parser.js +19 -18
- package/dist/lib/sql/adapters/pgsql-parser.js.map +1 -1
- package/dist/metrics/hunch.js.map +1 -1
- package/dist/objects/API.js +1 -1
- package/dist/objects/API.js.map +1 -1
- package/dist/objects/Agent.js.map +1 -1
- package/dist/objects/Browser.js.map +1 -1
- package/dist/objects/CLI.js.map +1 -1
- package/dist/objects/DOBase.js.map +1 -1
- package/dist/objects/DOCache.js +153 -0
- package/dist/objects/DOCache.js.map +1 -0
- package/dist/objects/DOFull.js.map +1 -1
- package/dist/objects/Entity.js.map +1 -1
- package/dist/objects/Human.js.map +1 -1
- package/dist/objects/IcebergMetadataDO.js.map +1 -1
- package/dist/objects/IntegrationsDO.js.map +1 -1
- package/dist/objects/ObservabilityBroadcaster.js.map +1 -1
- package/dist/objects/Package.js.map +1 -1
- package/dist/objects/Product.js +1 -1
- package/dist/objects/Product.js.map +1 -1
- package/dist/objects/SaaS.js.map +1 -1
- package/dist/objects/SandboxDO.js.map +1 -1
- package/dist/objects/Service.js.map +1 -1
- package/dist/objects/VectorShardDO.js +9 -7
- package/dist/objects/VectorShardDO.js.map +1 -1
- package/dist/objects/Workflow.js.map +1 -1
- package/dist/objects/WorkflowFactory.js.map +1 -1
- package/dist/objects/WorkflowRuntime.js.map +1 -1
- package/dist/objects/lifecycle/Branch.js.map +1 -1
- package/dist/objects/lifecycle/Clone.js +1 -1
- package/dist/objects/lifecycle/Clone.js.map +1 -1
- package/dist/objects/lifecycle/Compact.js.map +1 -1
- package/dist/objects/lifecycle/Shard.js.map +1 -1
- package/dist/objects/persistence/checkpoint-manager.js.map +1 -1
- package/dist/objects/persistence/migration-runner.js.map +1 -1
- package/dist/objects/persistence/replication-manager.js +2 -2
- package/dist/objects/persistence/replication-manager.js.map +1 -1
- package/dist/objects/persistence/tiered-storage-manager.js.map +1 -1
- package/dist/objects/persistence/wal-manager.js.map +1 -1
- package/dist/objects/transport/auth-layer.js.map +1 -1
- package/dist/objects/transport/chain.js.map +1 -1
- package/dist/objects/transport/mcp-server.js +7 -6
- package/dist/objects/transport/mcp-server.js.map +1 -1
- package/dist/objects/transport/rest-autowire.js +3 -2
- package/dist/objects/transport/rest-autowire.js.map +1 -1
- package/dist/objects/transport/rest-router.js.map +1 -1
- package/dist/objects/transport/rpc-server.js +18 -15
- package/dist/objects/transport/rpc-server.js.map +1 -1
- package/dist/objects/transport/shared.js +2 -1
- package/dist/objects/transport/shared.js.map +1 -1
- package/dist/snippets/artifacts-ingest.js.map +1 -1
- package/dist/snippets/artifacts-serve.js.map +1 -1
- package/dist/snippets/search.js.map +1 -1
- package/dist/workflows/ScheduleManager.js.map +1 -1
- package/dist/workflows/StepResultStorage.js.map +1 -1
- package/dist/workflows/WaitForEventManager.js.map +1 -1
- package/dist/workflows/compat/backends/cloudflare-workflows.js.map +1 -1
- package/dist/workflows/compat/inngest/index.js.map +1 -1
- package/dist/workflows/compat/qstash/index.js.map +1 -1
- package/dist/workflows/compat/temporal/client.js.map +1 -1
- package/dist/workflows/compat/temporal/index.js.map +1 -1
- package/dist/workflows/compat/trigger/index.js.map +1 -1
- package/dist/workflows/compat/utils/index.js.map +1 -1
- package/dist/workflows/context/correlation.js +2 -2
- package/dist/workflows/context/correlation.js.map +1 -1
- package/dist/workflows/context/experiment.js +1 -1
- package/dist/workflows/context/experiment.js.map +1 -1
- package/dist/workflows/context/flag.js +1 -1
- package/dist/workflows/context/flag.js.map +1 -1
- package/dist/workflows/context/measure.js +1 -1
- package/dist/workflows/context/measure.js.map +1 -1
- package/dist/workflows/context/rate-limit.js.map +1 -1
- package/dist/workflows/data/entity-events/entity-events.js.map +1 -1
- package/dist/workflows/data/experiment/index.js.map +1 -1
- package/dist/workflows/data/goal/context.js +1 -1
- package/dist/workflows/data/goal/context.js.map +1 -1
- package/dist/workflows/data/measure/index.js +1 -1
- package/dist/workflows/data/measure/index.js.map +1 -1
- package/dist/workflows/data/stream/index.js +10 -76
- package/dist/workflows/data/stream/index.js.map +1 -1
- package/dist/workflows/data/track/context.js.map +1 -1
- package/dist/workflows/data/view/context.js.map +1 -1
- package/dist/workflows/domain.js.map +1 -1
- package/dist/workflows/flags.js +1 -1
- package/dist/workflows/flags.js.map +1 -1
- package/dist/workflows/hash.js.map +1 -1
- package/dist/workflows/on.js +1 -1
- package/dist/workflows/on.js.map +1 -1
- package/dist/workflows/schedule-builder.js.map +1 -1
- package/dist/workflows/visibility/index.js +0 -2
- package/dist/workflows/visibility/index.js.map +1 -1
- package/dist/workflows/visibility/query-parser.js.map +1 -1
- package/package.json +18 -3
- package/dist/api/analytics/router.js +0 -601
- package/dist/api/analytics/router.js.map +0 -1
- package/dist/api/index.js +0 -158
- package/dist/api/index.js.map +0 -1
- package/dist/api/middleware/error-handling.js +0 -176
- package/dist/api/middleware/error-handling.js.map +0 -1
- package/dist/api/middleware/request-id.js +0 -21
- package/dist/api/middleware/request-id.js.map +0 -1
- package/dist/api/pages.js +0 -1180
- package/dist/api/pages.js.map +0 -1
- package/dist/api/routes/api.js +0 -612
- package/dist/api/routes/api.js.map +0 -1
- package/dist/api/routes/browsers.js +0 -471
- package/dist/api/routes/browsers.js.map +0 -1
- package/dist/api/routes/do.js +0 -188
- package/dist/api/routes/do.js.map +0 -1
- package/dist/api/routes/mcp.js +0 -459
- package/dist/api/routes/mcp.js.map +0 -1
- package/dist/api/routes/obs.js +0 -445
- package/dist/api/routes/obs.js.map +0 -1
- package/dist/api/routes/openapi.js +0 -794
- package/dist/api/routes/openapi.js.map +0 -1
- package/dist/api/routes/rpc.js +0 -1103
- package/dist/api/routes/rpc.js.map +0 -1
- package/dist/api/routes/sandboxes.js +0 -389
- package/dist/api/routes/sandboxes.js.map +0 -1
- package/dist/api/test-do.js +0 -38
- package/dist/api/test-do.js.map +0 -1
- package/dist/api/types.js +0 -11
- package/dist/api/types.js.map +0 -1
- package/dist/cli/bin.js +0 -2
- package/dist/cli/main.js +0 -52342
- package/dist/do/bash.js +0 -35
- package/dist/do/bash.js.map +0 -1
- package/dist/do/fs.js +0 -25
- package/dist/do/fs.js.map +0 -1
- package/dist/do/full.js +0 -61
- package/dist/do/full.js.map +0 -1
- package/dist/do/git.js +0 -28
- package/dist/do/git.js.map +0 -1
- package/dist/do/index.js +0 -52
- package/dist/do/index.js.map +0 -1
- package/dist/lib/agent/tools/bash.js +0 -336
- package/dist/lib/agent/tools/bash.js.map +0 -1
- package/dist/lib/agent/tools/edit.js +0 -157
- package/dist/lib/agent/tools/edit.js.map +0 -1
- package/dist/lib/agent/tools/glob.js +0 -137
- package/dist/lib/agent/tools/glob.js.map +0 -1
- package/dist/lib/agent/tools/grep.js +0 -315
- package/dist/lib/agent/tools/grep.js.map +0 -1
- package/dist/lib/agent/tools/index.js +0 -71
- package/dist/lib/agent/tools/index.js.map +0 -1
- package/dist/lib/agent/tools/read.js +0 -212
- package/dist/lib/agent/tools/read.js.map +0 -1
- package/dist/lib/agent/tools/types.js +0 -197
- package/dist/lib/agent/tools/types.js.map +0 -1
- package/dist/lib/agent/tools/write.js +0 -159
- package/dist/lib/agent/tools/write.js.map +0 -1
- package/dist/lib/mixins/index.js +0 -29
- package/dist/lib/mixins/index.js.map +0 -1
- package/dist/primitives/bashx/src/ast/analyze.js +0 -1472
- package/dist/primitives/bashx/src/ast/analyze.js.map +0 -1
- package/dist/primitives/bashx/src/ast/parser.js +0 -1488
- package/dist/primitives/bashx/src/ast/parser.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/crypto.js +0 -1954
- package/dist/primitives/bashx/src/do/commands/crypto.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/data-processing.js +0 -1812
- package/dist/primitives/bashx/src/do/commands/data-processing.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/extended-utils.js +0 -804
- package/dist/primitives/bashx/src/do/commands/extended-utils.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/math-control.js +0 -1122
- package/dist/primitives/bashx/src/do/commands/math-control.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/posix-utils.js +0 -1015
- package/dist/primitives/bashx/src/do/commands/posix-utils.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/system-utils.js +0 -687
- package/dist/primitives/bashx/src/do/commands/system-utils.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/test-command.js +0 -523
- package/dist/primitives/bashx/src/do/commands/test-command.js.map +0 -1
- package/dist/primitives/bashx/src/do/commands/text-processing.js +0 -1550
- package/dist/primitives/bashx/src/do/commands/text-processing.js.map +0 -1
- package/dist/primitives/bashx/src/do/container-executor.js +0 -429
- package/dist/primitives/bashx/src/do/container-executor.js.map +0 -1
- package/dist/primitives/bashx/src/do/index.js +0 -668
- package/dist/primitives/bashx/src/do/index.js.map +0 -1
- package/dist/primitives/bashx/src/do/tiered-executor.js +0 -2647
- package/dist/primitives/bashx/src/do/tiered-executor.js.map +0 -1
- package/dist/primitives/bashx/src/do/worker.js +0 -352
- package/dist/primitives/bashx/src/do/worker.js.map +0 -1
- package/dist/primitives/bashx/src/types.js +0 -10
- package/dist/primitives/bashx/src/types.js.map +0 -1
- package/dist/primitives/fsx/core/backend.js +0 -480
- package/dist/primitives/fsx/core/backend.js.map +0 -1
- package/dist/primitives/fsx/core/constants.js +0 -140
- package/dist/primitives/fsx/core/constants.js.map +0 -1
- package/dist/primitives/fsx/core/fsx.js +0 -1184
- package/dist/primitives/fsx/core/fsx.js.map +0 -1
- package/dist/primitives/fsx/core/glob/glob.js +0 -438
- package/dist/primitives/fsx/core/glob/glob.js.map +0 -1
- package/dist/primitives/fsx/core/glob/index.js +0 -8
- package/dist/primitives/fsx/core/glob/index.js.map +0 -1
- package/dist/primitives/fsx/core/glob/match.js +0 -392
- package/dist/primitives/fsx/core/glob/match.js.map +0 -1
- package/dist/primitives/fsx/core/types.js +0 -307
- package/dist/primitives/fsx/core/types.js.map +0 -1
- package/dist/sdk/capnweb-compat.js +0 -42
- package/dist/sdk/capnweb-compat.js.map +0 -1
- package/dist/sdk/client.js +0 -20
- package/dist/sdk/client.js.map +0 -1
- package/dist/sdk/index.js +0 -17
- package/dist/sdk/index.js.map +0 -1
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool Adapters for Claude Code in Workers
|
|
3
|
-
*
|
|
4
|
-
* Maps Claude SDK tools (Read, Write, Edit, Glob, Grep, Bash)
|
|
5
|
-
* to fsx.do and bashx.do capabilities for running agents in Workers.
|
|
6
|
-
*
|
|
7
|
-
* @module lib/agent/tools
|
|
8
|
-
*/
|
|
9
|
-
// Types
|
|
10
|
-
export * from './types';
|
|
11
|
-
// Adapters
|
|
12
|
-
export { ReadToolAdapter } from './read';
|
|
13
|
-
export { WriteToolAdapter } from './write';
|
|
14
|
-
export { EditToolAdapter } from './edit';
|
|
15
|
-
export { GlobToolAdapter } from './glob';
|
|
16
|
-
export { GrepToolAdapter } from './grep';
|
|
17
|
-
export { BashToolAdapter } from './bash';
|
|
18
|
-
import { ReadToolAdapter } from './read';
|
|
19
|
-
import { WriteToolAdapter } from './write';
|
|
20
|
-
import { EditToolAdapter } from './edit';
|
|
21
|
-
import { GlobToolAdapter } from './glob';
|
|
22
|
-
import { GrepToolAdapter } from './grep';
|
|
23
|
-
import { BashToolAdapter } from './bash';
|
|
24
|
-
/**
|
|
25
|
-
* All available tool adapters
|
|
26
|
-
*/
|
|
27
|
-
export const toolAdapters = {
|
|
28
|
-
Read: new ReadToolAdapter(),
|
|
29
|
-
Write: new WriteToolAdapter(),
|
|
30
|
-
Edit: new EditToolAdapter(),
|
|
31
|
-
Glob: new GlobToolAdapter(),
|
|
32
|
-
Grep: new GrepToolAdapter(),
|
|
33
|
-
Bash: new BashToolAdapter(),
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Get all tool adapters as an array
|
|
37
|
-
*/
|
|
38
|
-
export function getAllToolAdapters() {
|
|
39
|
-
return Object.values(toolAdapters);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Get a tool adapter by name
|
|
43
|
-
*/
|
|
44
|
-
export function getToolAdapter(name) {
|
|
45
|
-
return toolAdapters[name];
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Create a tool context for executing tools
|
|
49
|
-
*/
|
|
50
|
-
export function createToolContext(fs, options = {}) {
|
|
51
|
-
return {
|
|
52
|
-
fs,
|
|
53
|
-
bash: options.bash,
|
|
54
|
-
cwd: options.cwd ?? '/',
|
|
55
|
-
readFiles: new Set(),
|
|
56
|
-
env: options.env,
|
|
57
|
-
uid: options.uid,
|
|
58
|
-
gid: options.gid,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Execute a tool by name with the given input and context
|
|
63
|
-
*/
|
|
64
|
-
export async function executeTool(name, input, context) {
|
|
65
|
-
const adapter = getToolAdapter(name);
|
|
66
|
-
if (!adapter) {
|
|
67
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
68
|
-
}
|
|
69
|
-
return adapter.execute(input, context);
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/agent/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,QAAQ;AACR,cAAc,SAAS,CAAA;AAEvB,WAAW;AACX,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AAGxC,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,IAAI,eAAe,EAAE;IAC3B,KAAK,EAAE,IAAI,gBAAgB,EAAE;IAC7B,IAAI,EAAE,IAAI,eAAe,EAAE;IAC3B,IAAI,EAAE,IAAI,eAAe,EAAE;IAC3B,IAAI,EAAE,IAAI,eAAe,EAAE;IAC3B,IAAI,EAAE,IAAI,eAAe,EAAE;CACnB,CAAA;AAEV;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAQ,YAA4C,CAAC,IAAI,CAAC,CAAA;AAC5D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,EAAqB,EACrB,UAMI,EAAE;IAEN,OAAO;QACL,EAAE;QACF,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG;QACvB,SAAS,EAAE,IAAI,GAAG,EAAE;QACpB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,GAAG,EAAE,OAAO,CAAC,GAAG;KACjB,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAY,EACZ,KAAc,EACd,OAAoB;IAEpB,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;IACpC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAA;IAC1C,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAe,CAAA;AACtD,CAAC"}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Read Tool Adapter
|
|
3
|
-
*
|
|
4
|
-
* Maps Claude SDK Read tool to fsx.do filesystem capabilities.
|
|
5
|
-
* Supports text files, binary files (base64), images (multimodal),
|
|
6
|
-
* and partial reads with offset/limit.
|
|
7
|
-
*
|
|
8
|
-
* @module lib/agent/tools/read
|
|
9
|
-
*/
|
|
10
|
-
import { FileNotFoundError, IsDirectoryError, PathTraversalError, BINARY_MIME_TYPES, IMAGE_EXTENSIONS, } from './types';
|
|
11
|
-
/**
|
|
12
|
-
* Maximum file size for direct reading (1MB)
|
|
13
|
-
* Files larger than this will be chunked
|
|
14
|
-
*/
|
|
15
|
-
const MAX_DIRECT_READ_SIZE = 1024 * 1024;
|
|
16
|
-
/**
|
|
17
|
-
* Default line limit if file is too large
|
|
18
|
-
*/
|
|
19
|
-
const DEFAULT_LINE_LIMIT = 2000;
|
|
20
|
-
/**
|
|
21
|
-
* Maximum line length before truncation
|
|
22
|
-
*/
|
|
23
|
-
const MAX_LINE_LENGTH = 2000;
|
|
24
|
-
/**
|
|
25
|
-
* Validate and normalize a file path
|
|
26
|
-
* Prevents path traversal attacks
|
|
27
|
-
*/
|
|
28
|
-
function validatePath(path) {
|
|
29
|
-
// Must be absolute
|
|
30
|
-
if (!path.startsWith('/')) {
|
|
31
|
-
throw new PathTraversalError(path);
|
|
32
|
-
}
|
|
33
|
-
// Normalize the path
|
|
34
|
-
const parts = path.split('/').filter(Boolean);
|
|
35
|
-
const resolved = [];
|
|
36
|
-
for (const part of parts) {
|
|
37
|
-
if (part === '.')
|
|
38
|
-
continue;
|
|
39
|
-
if (part === '..') {
|
|
40
|
-
if (resolved.length === 0) {
|
|
41
|
-
// Trying to go above root
|
|
42
|
-
throw new PathTraversalError(path);
|
|
43
|
-
}
|
|
44
|
-
resolved.pop();
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
resolved.push(part);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return '/' + resolved.join('/');
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Get the file extension from a path
|
|
54
|
-
*/
|
|
55
|
-
function getExtension(path) {
|
|
56
|
-
const lastDot = path.lastIndexOf('.');
|
|
57
|
-
const lastSlash = path.lastIndexOf('/');
|
|
58
|
-
if (lastDot === -1 || lastDot < lastSlash)
|
|
59
|
-
return '';
|
|
60
|
-
return path.slice(lastDot).toLowerCase();
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Check if a file is binary based on extension
|
|
64
|
-
*/
|
|
65
|
-
function isBinaryFile(path) {
|
|
66
|
-
const ext = getExtension(path);
|
|
67
|
-
return ext in BINARY_MIME_TYPES;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Check if a file is an image
|
|
71
|
-
*/
|
|
72
|
-
function isImageFile(path) {
|
|
73
|
-
const ext = getExtension(path);
|
|
74
|
-
return IMAGE_EXTENSIONS.has(ext);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Get MIME type for a file
|
|
78
|
-
*/
|
|
79
|
-
function getMimeType(path) {
|
|
80
|
-
const ext = getExtension(path);
|
|
81
|
-
return BINARY_MIME_TYPES[ext] || 'application/octet-stream';
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Convert Uint8Array to base64
|
|
85
|
-
*/
|
|
86
|
-
function toBase64(bytes) {
|
|
87
|
-
let binary = '';
|
|
88
|
-
for (const byte of bytes) {
|
|
89
|
-
binary += String.fromCharCode(byte);
|
|
90
|
-
}
|
|
91
|
-
return btoa(binary);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Apply line numbering in cat -n format
|
|
95
|
-
*/
|
|
96
|
-
function formatWithLineNumbers(content, startLine = 1) {
|
|
97
|
-
const lines = content.split('\n');
|
|
98
|
-
const maxLineNum = startLine + lines.length - 1;
|
|
99
|
-
const numWidth = String(maxLineNum).length;
|
|
100
|
-
return lines.map((line, i) => {
|
|
101
|
-
const lineNum = startLine + i;
|
|
102
|
-
const paddedNum = String(lineNum).padStart(numWidth, ' ');
|
|
103
|
-
// Truncate long lines
|
|
104
|
-
const truncatedLine = line.length > MAX_LINE_LENGTH
|
|
105
|
-
? line.slice(0, MAX_LINE_LENGTH) + '...'
|
|
106
|
-
: line;
|
|
107
|
-
return `${paddedNum}\t${truncatedLine}`;
|
|
108
|
-
}).join('\n');
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Read Tool Adapter
|
|
112
|
-
*
|
|
113
|
-
* Reads file contents from the filesystem. Supports:
|
|
114
|
-
* - Text files (returns string with line numbers)
|
|
115
|
-
* - Binary files (returns base64-encoded)
|
|
116
|
-
* - Images (returns base64 for multimodal)
|
|
117
|
-
* - Partial reads with offset/limit
|
|
118
|
-
*/
|
|
119
|
-
export class ReadToolAdapter {
|
|
120
|
-
name = 'Read';
|
|
121
|
-
description = `Reads a file from the local filesystem. You can access any file directly by using this tool.
|
|
122
|
-
|
|
123
|
-
Usage:
|
|
124
|
-
- The file_path parameter must be an absolute path, not a relative path
|
|
125
|
-
- By default, it reads up to ${DEFAULT_LINE_LIMIT} lines starting from the beginning of the file
|
|
126
|
-
- You can optionally specify a line offset and limit (especially handy for long files)
|
|
127
|
-
- Any lines longer than ${MAX_LINE_LENGTH} characters will be truncated
|
|
128
|
-
- Results are returned using cat -n format, with line numbers starting at 1
|
|
129
|
-
- This tool allows reading images (PNG, JPG, etc) for multimodal analysis
|
|
130
|
-
- This tool can read PDF files and Jupyter notebooks`;
|
|
131
|
-
inputSchema = {
|
|
132
|
-
type: 'object',
|
|
133
|
-
properties: {
|
|
134
|
-
file_path: {
|
|
135
|
-
type: 'string',
|
|
136
|
-
description: 'The absolute path to the file to read',
|
|
137
|
-
},
|
|
138
|
-
offset: {
|
|
139
|
-
type: 'number',
|
|
140
|
-
description: 'The line number to start reading from (1-indexed). Only provide if the file is too large to read at once',
|
|
141
|
-
},
|
|
142
|
-
limit: {
|
|
143
|
-
type: 'number',
|
|
144
|
-
description: 'The number of lines to read. Only provide if the file is too large to read at once',
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
required: ['file_path'],
|
|
148
|
-
additionalProperties: false,
|
|
149
|
-
};
|
|
150
|
-
async execute(input, context) {
|
|
151
|
-
const { file_path, offset, limit } = input;
|
|
152
|
-
const { fs, readFiles } = context;
|
|
153
|
-
// Validate path
|
|
154
|
-
const normalizedPath = validatePath(file_path);
|
|
155
|
-
// Check if file exists and get stats
|
|
156
|
-
const exists = await fs.exists(normalizedPath);
|
|
157
|
-
if (!exists) {
|
|
158
|
-
throw new FileNotFoundError(normalizedPath);
|
|
159
|
-
}
|
|
160
|
-
const stats = await fs.stat(normalizedPath);
|
|
161
|
-
if (stats.isDirectory()) {
|
|
162
|
-
throw new IsDirectoryError(normalizedPath);
|
|
163
|
-
}
|
|
164
|
-
// Track that we've read this file (for Edit validation)
|
|
165
|
-
readFiles.add(normalizedPath);
|
|
166
|
-
// Handle binary/image files
|
|
167
|
-
if (isBinaryFile(normalizedPath)) {
|
|
168
|
-
const bytes = await fs.readFile(normalizedPath, undefined);
|
|
169
|
-
const base64 = toBase64(bytes);
|
|
170
|
-
const mimeType = getMimeType(normalizedPath);
|
|
171
|
-
// For images, return in multimodal format
|
|
172
|
-
if (isImageFile(normalizedPath)) {
|
|
173
|
-
return {
|
|
174
|
-
content: {
|
|
175
|
-
type: 'base64',
|
|
176
|
-
data: base64,
|
|
177
|
-
media_type: mimeType,
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
// For other binary files, return base64 string
|
|
182
|
-
return {
|
|
183
|
-
content: {
|
|
184
|
-
type: 'base64',
|
|
185
|
-
data: base64,
|
|
186
|
-
media_type: mimeType,
|
|
187
|
-
},
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
// Read text content
|
|
191
|
-
const rawContent = await fs.readFile(normalizedPath);
|
|
192
|
-
// Split into lines
|
|
193
|
-
const allLines = rawContent.split('\n');
|
|
194
|
-
const totalLines = allLines.length;
|
|
195
|
-
// Apply offset and limit
|
|
196
|
-
const startLine = offset ?? 1;
|
|
197
|
-
const lineLimit = limit ?? DEFAULT_LINE_LIMIT;
|
|
198
|
-
const startIndex = Math.max(0, startLine - 1); // Convert to 0-indexed
|
|
199
|
-
const endIndex = Math.min(totalLines, startIndex + lineLimit);
|
|
200
|
-
const selectedLines = allLines.slice(startIndex, endIndex);
|
|
201
|
-
// Check if truncated
|
|
202
|
-
const truncated = endIndex < totalLines;
|
|
203
|
-
// Format with line numbers
|
|
204
|
-
const formattedContent = formatWithLineNumbers(selectedLines.join('\n'), startLine);
|
|
205
|
-
return {
|
|
206
|
-
content: formattedContent,
|
|
207
|
-
truncated,
|
|
208
|
-
total_lines: totalLines,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
//# sourceMappingURL=read.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../../../lib/agent/tools/read.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,SAAS,CAAA;AAEhB;;;GAGG;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,IAAI,CAAA;AAExC;;GAEG;AACH,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAE/B;;GAEG;AACH,MAAM,eAAe,GAAG,IAAI,CAAA;AAE5B;;;GAGG;AACH,SAAS,YAAY,CAAC,IAAY;IAChC,mBAAmB;IACnB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC;IAED,qBAAqB;IACrB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC7C,MAAM,QAAQ,GAAa,EAAE,CAAA;IAE7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,KAAK,GAAG;YAAE,SAAQ;QAC1B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC1B,0BAA0B;gBAC1B,MAAM,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAA;YACpC,CAAC;YACD,QAAQ,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
-
*
|
|
7
|
-
* @module lib/agent/tools/types
|
|
8
|
-
*/
|
|
9
|
-
// ============================================================================
|
|
10
|
-
// ERRORS
|
|
11
|
-
// ============================================================================
|
|
12
|
-
/**
|
|
13
|
-
* Base error class for tool errors
|
|
14
|
-
*/
|
|
15
|
-
export class ToolError extends Error {
|
|
16
|
-
/** Error code for Claude SDK compatibility */
|
|
17
|
-
code;
|
|
18
|
-
/** Additional error details */
|
|
19
|
-
details;
|
|
20
|
-
constructor(message, code, details) {
|
|
21
|
-
super(message);
|
|
22
|
-
this.name = 'ToolError';
|
|
23
|
-
this.code = code;
|
|
24
|
-
this.details = details;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* File not found error
|
|
29
|
-
*/
|
|
30
|
-
export class FileNotFoundError extends ToolError {
|
|
31
|
-
constructor(path) {
|
|
32
|
-
super(`ENOENT: no such file or directory: '${path}'`, 'ENOENT', { path });
|
|
33
|
-
this.name = 'FileNotFoundError';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Permission denied error
|
|
38
|
-
*/
|
|
39
|
-
export class PermissionError extends ToolError {
|
|
40
|
-
constructor(path, operation) {
|
|
41
|
-
super(`EACCES: permission denied: '${path}' (${operation})`, 'EACCES', { path, operation });
|
|
42
|
-
this.name = 'PermissionError';
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Is a directory error
|
|
47
|
-
*/
|
|
48
|
-
export class IsDirectoryError extends ToolError {
|
|
49
|
-
constructor(path) {
|
|
50
|
-
super(`EISDIR: illegal operation on a directory: '${path}'`, 'EISDIR', { path });
|
|
51
|
-
this.name = 'IsDirectoryError';
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Not a directory error
|
|
56
|
-
*/
|
|
57
|
-
export class NotDirectoryError extends ToolError {
|
|
58
|
-
constructor(path) {
|
|
59
|
-
super(`ENOTDIR: not a directory: '${path}'`, 'ENOTDIR', { path });
|
|
60
|
-
this.name = 'NotDirectoryError';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* File already exists error
|
|
65
|
-
*/
|
|
66
|
-
export class FileExistsError extends ToolError {
|
|
67
|
-
constructor(path) {
|
|
68
|
-
super(`EEXIST: file already exists: '${path}'`, 'EEXIST', { path });
|
|
69
|
-
this.name = 'FileExistsError';
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Timeout error
|
|
74
|
-
*/
|
|
75
|
-
export class TimeoutError extends ToolError {
|
|
76
|
-
constructor(operation, timeout) {
|
|
77
|
-
super(`ETIMEDOUT: operation timed out after ${timeout}ms: ${operation}`, 'ETIMEDOUT', { operation, timeout });
|
|
78
|
-
this.name = 'TimeoutError';
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Uniqueness error (for Edit tool)
|
|
83
|
-
*/
|
|
84
|
-
export class NotUniqueError extends ToolError {
|
|
85
|
-
constructor(substring, count) {
|
|
86
|
-
super(`String to replace is not unique (found ${count} occurrences)`, 'NOT_UNIQUE', { substring, count });
|
|
87
|
-
this.name = 'NotUniqueError';
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Command blocked error (for Bash tool)
|
|
92
|
-
*/
|
|
93
|
-
export class CommandBlockedError extends ToolError {
|
|
94
|
-
constructor(command, reason) {
|
|
95
|
-
super(`Command blocked: ${reason}`, 'BLOCKED', { command, reason });
|
|
96
|
-
this.name = 'CommandBlockedError';
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* File not read error (for Edit tool)
|
|
101
|
-
*/
|
|
102
|
-
export class FileNotReadError extends ToolError {
|
|
103
|
-
constructor(path) {
|
|
104
|
-
super(`File must be read before editing: '${path}'`, 'NOT_READ', { path });
|
|
105
|
-
this.name = 'FileNotReadError';
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Path traversal error
|
|
110
|
-
*/
|
|
111
|
-
export class PathTraversalError extends ToolError {
|
|
112
|
-
constructor(path) {
|
|
113
|
-
super(`Path traversal detected: '${path}'`, 'PATH_TRAVERSAL', { path });
|
|
114
|
-
this.name = 'PathTraversalError';
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// ============================================================================
|
|
118
|
-
// UTILITY TYPES
|
|
119
|
-
// ============================================================================
|
|
120
|
-
/**
|
|
121
|
-
* MIME types for binary file detection
|
|
122
|
-
*/
|
|
123
|
-
export const BINARY_MIME_TYPES = {
|
|
124
|
-
// Images
|
|
125
|
-
'.png': 'image/png',
|
|
126
|
-
'.jpg': 'image/jpeg',
|
|
127
|
-
'.jpeg': 'image/jpeg',
|
|
128
|
-
'.gif': 'image/gif',
|
|
129
|
-
'.webp': 'image/webp',
|
|
130
|
-
'.svg': 'image/svg+xml',
|
|
131
|
-
'.ico': 'image/x-icon',
|
|
132
|
-
'.bmp': 'image/bmp',
|
|
133
|
-
'.tiff': 'image/tiff',
|
|
134
|
-
'.tif': 'image/tiff',
|
|
135
|
-
// Documents
|
|
136
|
-
'.pdf': 'application/pdf',
|
|
137
|
-
// Archives
|
|
138
|
-
'.zip': 'application/zip',
|
|
139
|
-
'.tar': 'application/x-tar',
|
|
140
|
-
'.gz': 'application/gzip',
|
|
141
|
-
'.7z': 'application/x-7z-compressed',
|
|
142
|
-
'.rar': 'application/vnd.rar',
|
|
143
|
-
// Binary
|
|
144
|
-
'.wasm': 'application/wasm',
|
|
145
|
-
'.exe': 'application/octet-stream',
|
|
146
|
-
'.dll': 'application/octet-stream',
|
|
147
|
-
'.so': 'application/octet-stream',
|
|
148
|
-
'.dylib': 'application/octet-stream',
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* Image extensions for multimodal support
|
|
152
|
-
*/
|
|
153
|
-
export const IMAGE_EXTENSIONS = new Set([
|
|
154
|
-
'.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp', '.tiff', '.tif',
|
|
155
|
-
]);
|
|
156
|
-
/**
|
|
157
|
-
* File type mappings for Grep --type option (ripgrep compatible)
|
|
158
|
-
*/
|
|
159
|
-
export const FILE_TYPE_GLOBS = {
|
|
160
|
-
ts: ['*.ts', '*.tsx', '*.mts', '*.cts'],
|
|
161
|
-
typescript: ['*.ts', '*.tsx', '*.mts', '*.cts'],
|
|
162
|
-
js: ['*.js', '*.jsx', '*.mjs', '*.cjs'],
|
|
163
|
-
javascript: ['*.js', '*.jsx', '*.mjs', '*.cjs'],
|
|
164
|
-
py: ['*.py', '*.pyi', '*.pyw'],
|
|
165
|
-
python: ['*.py', '*.pyi', '*.pyw'],
|
|
166
|
-
rust: ['*.rs'],
|
|
167
|
-
go: ['*.go'],
|
|
168
|
-
java: ['*.java'],
|
|
169
|
-
c: ['*.c', '*.h'],
|
|
170
|
-
cpp: ['*.cpp', '*.cc', '*.cxx', '*.hpp', '*.hh', '*.hxx', '*.C', '*.H'],
|
|
171
|
-
cs: ['*.cs'],
|
|
172
|
-
csharp: ['*.cs'],
|
|
173
|
-
rb: ['*.rb', '*.rake', 'Rakefile'],
|
|
174
|
-
ruby: ['*.rb', '*.rake', 'Rakefile'],
|
|
175
|
-
php: ['*.php', '*.php3', '*.php4', '*.php5', '*.phtml'],
|
|
176
|
-
swift: ['*.swift'],
|
|
177
|
-
kotlin: ['*.kt', '*.kts'],
|
|
178
|
-
scala: ['*.scala'],
|
|
179
|
-
html: ['*.html', '*.htm', '*.xhtml'],
|
|
180
|
-
css: ['*.css', '*.scss', '*.sass', '*.less'],
|
|
181
|
-
json: ['*.json', '*.jsonc', '*.json5'],
|
|
182
|
-
yaml: ['*.yaml', '*.yml'],
|
|
183
|
-
xml: ['*.xml', '*.xsd', '*.xsl', '*.xslt'],
|
|
184
|
-
md: ['*.md', '*.markdown'],
|
|
185
|
-
markdown: ['*.md', '*.markdown'],
|
|
186
|
-
sql: ['*.sql'],
|
|
187
|
-
sh: ['*.sh', '*.bash', '*.zsh'],
|
|
188
|
-
shell: ['*.sh', '*.bash', '*.zsh'],
|
|
189
|
-
docker: ['Dockerfile', 'Dockerfile.*', '*.dockerfile'],
|
|
190
|
-
make: ['Makefile', 'makefile', 'GNUmakefile', '*.mk'],
|
|
191
|
-
toml: ['*.toml'],
|
|
192
|
-
ini: ['*.ini', '*.cfg', '*.conf'],
|
|
193
|
-
vue: ['*.vue'],
|
|
194
|
-
svelte: ['*.svelte'],
|
|
195
|
-
astro: ['*.astro'],
|
|
196
|
-
};
|
|
197
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../lib/agent/tools/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA6QH,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,8CAA8C;IAC9C,IAAI,CAAQ;IACZ,+BAA+B;IAC/B,OAAO,CAAU;IAEjB,YAAY,OAAe,EAAE,IAAY,EAAE,OAAiB;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC9C,YAAY,IAAY;QACtB,KAAK,CAAC,uCAAuC,IAAI,GAAG,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;QACzE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,YAAY,IAAY,EAAE,SAAiB;QACzC,KAAK,CAAC,+BAA+B,IAAI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@ -1,159 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Write Tool Adapter
|
|
3
|
-
*
|
|
4
|
-
* Maps Claude SDK Write tool to fsx.do filesystem capabilities.
|
|
5
|
-
* Creates parent directories automatically and supports atomic writes.
|
|
6
|
-
*
|
|
7
|
-
* @module lib/agent/tools/write
|
|
8
|
-
*/
|
|
9
|
-
import { IsDirectoryError, PathTraversalError, PermissionError, } from './types';
|
|
10
|
-
/**
|
|
11
|
-
* Dangerous paths that should never be written to
|
|
12
|
-
*/
|
|
13
|
-
const DANGEROUS_PATHS = new Set([
|
|
14
|
-
'/etc/passwd',
|
|
15
|
-
'/etc/shadow',
|
|
16
|
-
'/etc/hosts',
|
|
17
|
-
'/etc/sudoers',
|
|
18
|
-
'/.env',
|
|
19
|
-
'/.bashrc',
|
|
20
|
-
'/.profile',
|
|
21
|
-
'/.zshrc',
|
|
22
|
-
'/.ssh/authorized_keys',
|
|
23
|
-
'/.ssh/id_rsa',
|
|
24
|
-
'/.ssh/id_ed25519',
|
|
25
|
-
]);
|
|
26
|
-
/**
|
|
27
|
-
* Patterns for credential files that should not be written
|
|
28
|
-
*/
|
|
29
|
-
const CREDENTIAL_PATTERNS = [
|
|
30
|
-
/\.env$/,
|
|
31
|
-
/\.env\..+$/,
|
|
32
|
-
/credentials\.json$/,
|
|
33
|
-
/secrets\.json$/,
|
|
34
|
-
/\.pem$/,
|
|
35
|
-
/\.key$/,
|
|
36
|
-
/id_rsa$/,
|
|
37
|
-
/id_ed25519$/,
|
|
38
|
-
];
|
|
39
|
-
/**
|
|
40
|
-
* Validate and normalize a file path
|
|
41
|
-
* Prevents path traversal attacks
|
|
42
|
-
*/
|
|
43
|
-
function validatePath(path) {
|
|
44
|
-
// Must be absolute
|
|
45
|
-
if (!path.startsWith('/')) {
|
|
46
|
-
throw new PathTraversalError(path);
|
|
47
|
-
}
|
|
48
|
-
// Normalize the path
|
|
49
|
-
const parts = path.split('/').filter(Boolean);
|
|
50
|
-
const resolved = [];
|
|
51
|
-
for (const part of parts) {
|
|
52
|
-
if (part === '.')
|
|
53
|
-
continue;
|
|
54
|
-
if (part === '..') {
|
|
55
|
-
if (resolved.length === 0) {
|
|
56
|
-
throw new PathTraversalError(path);
|
|
57
|
-
}
|
|
58
|
-
resolved.pop();
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
resolved.push(part);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return '/' + resolved.join('/');
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Check if a path is a dangerous system path
|
|
68
|
-
*/
|
|
69
|
-
function isDangerousPath(path) {
|
|
70
|
-
if (DANGEROUS_PATHS.has(path)) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
// Check credential patterns
|
|
74
|
-
for (const pattern of CREDENTIAL_PATTERNS) {
|
|
75
|
-
if (pattern.test(path)) {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get the parent directory of a path
|
|
83
|
-
*/
|
|
84
|
-
function getParentDir(path) {
|
|
85
|
-
const lastSlash = path.lastIndexOf('/');
|
|
86
|
-
if (lastSlash <= 0)
|
|
87
|
-
return '/';
|
|
88
|
-
return path.slice(0, lastSlash);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Write Tool Adapter
|
|
92
|
-
*
|
|
93
|
-
* Writes content to a file, replacing the file if it already exists.
|
|
94
|
-
* Creates parent directories as needed (like mkdir -p).
|
|
95
|
-
*/
|
|
96
|
-
export class WriteToolAdapter {
|
|
97
|
-
name = 'Write';
|
|
98
|
-
description = `Writes a file to the local filesystem.
|
|
99
|
-
|
|
100
|
-
Usage:
|
|
101
|
-
- This tool will overwrite the existing file if there is one at the provided path.
|
|
102
|
-
- If this is an existing file, you MUST use the Read tool first to read the file's contents.
|
|
103
|
-
- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
|
|
104
|
-
- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested.
|
|
105
|
-
- Only use emojis if the user explicitly requests it.`;
|
|
106
|
-
inputSchema = {
|
|
107
|
-
type: 'object',
|
|
108
|
-
properties: {
|
|
109
|
-
file_path: {
|
|
110
|
-
type: 'string',
|
|
111
|
-
description: 'The absolute path to the file to write (must be absolute, not relative)',
|
|
112
|
-
},
|
|
113
|
-
content: {
|
|
114
|
-
type: 'string',
|
|
115
|
-
description: 'The content to write to the file',
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
required: ['file_path', 'content'],
|
|
119
|
-
additionalProperties: false,
|
|
120
|
-
};
|
|
121
|
-
async execute(input, context) {
|
|
122
|
-
const { file_path, content } = input;
|
|
123
|
-
const { fs, readFiles } = context;
|
|
124
|
-
// Validate path
|
|
125
|
-
const normalizedPath = validatePath(file_path);
|
|
126
|
-
// Check for dangerous paths
|
|
127
|
-
if (isDangerousPath(normalizedPath)) {
|
|
128
|
-
throw new PermissionError(normalizedPath, 'write');
|
|
129
|
-
}
|
|
130
|
-
// Check if path is a directory
|
|
131
|
-
const exists = await fs.exists(normalizedPath);
|
|
132
|
-
if (exists) {
|
|
133
|
-
const stats = await fs.stat(normalizedPath);
|
|
134
|
-
if (stats.isDirectory()) {
|
|
135
|
-
throw new IsDirectoryError(normalizedPath);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// Create parent directories if needed
|
|
139
|
-
const parentDir = getParentDir(normalizedPath);
|
|
140
|
-
if (parentDir !== '/') {
|
|
141
|
-
const parentExists = await fs.exists(parentDir);
|
|
142
|
-
if (!parentExists) {
|
|
143
|
-
await fs.mkdir(parentDir, { recursive: true });
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// Write the file
|
|
147
|
-
await fs.writeFile(normalizedPath, content);
|
|
148
|
-
// Track that we've written (and implicitly read) this file
|
|
149
|
-
readFiles.add(normalizedPath);
|
|
150
|
-
// Calculate bytes written
|
|
151
|
-
const encoder = new TextEncoder();
|
|
152
|
-
const bytes = encoder.encode(content);
|
|
153
|
-
return {
|
|
154
|
-
success: true,
|
|
155
|
-
bytes_written: bytes.length,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
//# sourceMappingURL=write.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../../../lib/agent/tools/write.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,GAChB,MAAM,SAAS,CAAA;AAEhB;;GAEG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,aAAa;IACb,aAAa;IACb,YAAY;IACZ,cAAc;IACd,OAAO;IACP,UAAU;IACV,WAAW;IACX,SAAS;IACT,uBAAuB;IACvB,cAAc;IACd,kBAAkB;CACnB,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAAG;IAC1B,QAAQ;IACR,YAAY;IACZ,oBAAoB;IACpB,gBAAgB;IAChB,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,aAAa;CACd,CAAA;AAED;;;GAGG;AACH,SAAS,YAAY,CAAC,IAAY;IAChC,mBAAmB;IACnB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC;IAED,qBAAqB;IACrB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC7C,MAAM,QAAQ,GAAa,EAAE,CAAA;IAE7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,KAAK,GAAG;YAAE,SAAQ;QAC1B,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACl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