tarsk 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +447375 -37
- package/package.json +2 -2
- package/dist/agent/agent.error-utils.d.ts +0 -14
- package/dist/agent/agent.error-utils.js +0 -52
- package/dist/agent/agent.event-transformer.d.ts +0 -55
- package/dist/agent/agent.event-transformer.js +0 -175
- package/dist/agent/agent.executor.d.ts +0 -26
- package/dist/agent/agent.executor.js +0 -286
- package/dist/agent/agent.model-resolver.d.ts +0 -22
- package/dist/agent/agent.model-resolver.js +0 -67
- package/dist/agent/agent.process-manager.d.ts +0 -57
- package/dist/agent/agent.process-manager.js +0 -262
- package/dist/agent/agent.processing-state-manager.d.ts +0 -74
- package/dist/agent/agent.processing-state-manager.js +0 -87
- package/dist/agent/agent.prompt-loader.d.ts +0 -16
- package/dist/agent/agent.prompt-loader.js +0 -227
- package/dist/agent/agent.subagent-executor.d.ts +0 -35
- package/dist/agent/agent.subagent-executor.js +0 -135
- package/dist/bun/index.d.ts +0 -2
- package/dist/bun/index.js +0 -165
- package/dist/cli.d.ts +0 -3
- package/dist/cli.js +0 -22
- package/dist/core/crypto.d.ts +0 -29
- package/dist/core/crypto.js +0 -166
- package/dist/core/dev-server-cache.d.ts +0 -46
- package/dist/core/dev-server-cache.js +0 -59
- package/dist/core/env-manager.d.ts +0 -3
- package/dist/core/env-manager.js +0 -60
- package/dist/core/error-responses.d.ts +0 -61
- package/dist/core/error-responses.js +0 -64
- package/dist/core/logger.d.ts +0 -10
- package/dist/core/logger.js +0 -47
- package/dist/core/paths.d.ts +0 -22
- package/dist/core/paths.js +0 -26
- package/dist/core/random-words.d.ts +0 -18
- package/dist/core/random-words.js +0 -135
- package/dist/core/response-builder.d.ts +0 -50
- package/dist/core/response-builder.js +0 -56
- package/dist/core/route-helpers.d.ts +0 -47
- package/dist/core/route-helpers.js +0 -54
- package/dist/core/run-command-detector.d.ts +0 -26
- package/dist/core/run-command-detector.js +0 -98
- package/dist/core/stream-helper.d.ts +0 -44
- package/dist/core/stream-helper.js +0 -50
- package/dist/core/utils.d.ts +0 -43
- package/dist/core/utils.js +0 -113
- package/dist/core/validation.d.ts +0 -10
- package/dist/core/validation.js +0 -20
- package/dist/database/database.d.ts +0 -40
- package/dist/database/database.encryption.d.ts +0 -33
- package/dist/database/database.encryption.js +0 -62
- package/dist/database/database.js +0 -480
- package/dist/database/database.state.d.ts +0 -52
- package/dist/database/database.state.js +0 -119
- package/dist/database/database.test-utils.d.ts +0 -22
- package/dist/database/database.test-utils.js +0 -39
- package/dist/database/database.types.d.ts +0 -3
- package/dist/database/database.types.js +0 -2
- package/dist/features/agents/agents.manager.d.ts +0 -24
- package/dist/features/agents/agents.manager.js +0 -200
- package/dist/features/ask-user/ask-user.routes.d.ts +0 -9
- package/dist/features/ask-user/ask-user.routes.js +0 -35
- package/dist/features/chat/chat-delete.route.d.ts +0 -15
- package/dist/features/chat/chat-delete.route.js +0 -36
- package/dist/features/chat/chat-post.route.d.ts +0 -11
- package/dist/features/chat/chat-post.route.js +0 -270
- package/dist/features/chat/chat-stop.route.d.ts +0 -21
- package/dist/features/chat/chat-stop.route.js +0 -22
- package/dist/features/chat/chat-subscribe.route.d.ts +0 -9
- package/dist/features/chat/chat-subscribe.route.js +0 -71
- package/dist/features/chat/chat.routes.d.ts +0 -22
- package/dist/features/chat/chat.routes.js +0 -29
- package/dist/features/conversations/conversations-delete.route.d.ts +0 -16
- package/dist/features/conversations/conversations-delete.route.js +0 -34
- package/dist/features/conversations/conversations-get-all.route.d.ts +0 -16
- package/dist/features/conversations/conversations-get-all.route.js +0 -39
- package/dist/features/conversations/conversations-get-by-id.route.d.ts +0 -16
- package/dist/features/conversations/conversations-get-by-id.route.js +0 -38
- package/dist/features/conversations/conversations-get-deleted.route.d.ts +0 -15
- package/dist/features/conversations/conversations-get-deleted.route.js +0 -34
- package/dist/features/conversations/conversations-get-messages.route.d.ts +0 -16
- package/dist/features/conversations/conversations-get-messages.route.js +0 -49
- package/dist/features/conversations/conversations.content.d.ts +0 -28
- package/dist/features/conversations/conversations.content.js +0 -142
- package/dist/features/conversations/conversations.database.d.ts +0 -108
- package/dist/features/conversations/conversations.database.js +0 -373
- package/dist/features/conversations/conversations.manager.d.ts +0 -130
- package/dist/features/conversations/conversations.manager.js +0 -162
- package/dist/features/conversations/conversations.routes.d.ts +0 -21
- package/dist/features/conversations/conversations.routes.js +0 -38
- package/dist/features/conversations/token-usage.route.d.ts +0 -41
- package/dist/features/conversations/token-usage.route.js +0 -419
- package/dist/features/git/git-commit.route.d.ts +0 -12
- package/dist/features/git/git-commit.route.js +0 -39
- package/dist/features/git/git-create-branch.route.d.ts +0 -28
- package/dist/features/git/git-create-branch.route.js +0 -119
- package/dist/features/git/git-create-pr.route.d.ts +0 -13
- package/dist/features/git/git-create-pr.route.js +0 -50
- package/dist/features/git/git-create-repo.route.d.ts +0 -14
- package/dist/features/git/git-create-repo.route.js +0 -108
- package/dist/features/git/git-diff.route.d.ts +0 -30
- package/dist/features/git/git-diff.route.js +0 -189
- package/dist/features/git/git-fetch.route.d.ts +0 -12
- package/dist/features/git/git-fetch.route.js +0 -31
- package/dist/features/git/git-generate-commit-message.route.d.ts +0 -12
- package/dist/features/git/git-generate-commit-message.route.js +0 -76
- package/dist/features/git/git-generate-pr-info.route.d.ts +0 -13
- package/dist/features/git/git-generate-pr-info.route.js +0 -147
- package/dist/features/git/git-github-status.route.d.ts +0 -16
- package/dist/features/git/git-github-status.route.js +0 -68
- package/dist/features/git/git-log.route.d.ts +0 -17
- package/dist/features/git/git-log.route.js +0 -33
- package/dist/features/git/git-pr-status.route.d.ts +0 -15
- package/dist/features/git/git-pr-status.route.js +0 -33
- package/dist/features/git/git-pull.route.d.ts +0 -12
- package/dist/features/git/git-pull.route.js +0 -35
- package/dist/features/git/git-push.route.d.ts +0 -12
- package/dist/features/git/git-push.route.js +0 -46
- package/dist/features/git/git-status-cache.database.d.ts +0 -7
- package/dist/features/git/git-status-cache.database.js +0 -53
- package/dist/features/git/git-status.route.d.ts +0 -15
- package/dist/features/git/git-status.route.js +0 -62
- package/dist/features/git/git-sync-branch.route.d.ts +0 -4
- package/dist/features/git/git-sync-branch.route.js +0 -208
- package/dist/features/git/git-unified-status.route.d.ts +0 -30
- package/dist/features/git/git-unified-status.route.js +0 -165
- package/dist/features/git/git-username.route.d.ts +0 -3
- package/dist/features/git/git-username.route.js +0 -24
- package/dist/features/git/git.manager.d.ts +0 -139
- package/dist/features/git/git.manager.js +0 -352
- package/dist/features/git/git.routes.d.ts +0 -4
- package/dist/features/git/git.routes.js +0 -116
- package/dist/features/git/git.utils.d.ts +0 -82
- package/dist/features/git/git.utils.js +0 -1040
- package/dist/features/mcp/mcp.config.d.ts +0 -27
- package/dist/features/mcp/mcp.config.js +0 -148
- package/dist/features/mcp/mcp.manager.d.ts +0 -61
- package/dist/features/mcp/mcp.manager.js +0 -254
- package/dist/features/mcp/mcp.popular.json +0 -103
- package/dist/features/mcp/mcp.routes.d.ts +0 -13
- package/dist/features/mcp/mcp.routes.js +0 -159
- package/dist/features/mcp/mcp.types.d.ts +0 -80
- package/dist/features/mcp/mcp.types.js +0 -8
- package/dist/features/metadata/metadata.manager.d.ts +0 -126
- package/dist/features/metadata/metadata.manager.js +0 -423
- package/dist/features/models/model-info-aihubmix.d.ts +0 -25
- package/dist/features/models/model-info-aihubmix.js +0 -117
- package/dist/features/models/model-info-openrouter.d.ts +0 -25
- package/dist/features/models/model-info-openrouter.js +0 -104
- package/dist/features/models/model-info.d.ts +0 -37
- package/dist/features/models/model-info.js +0 -39
- package/dist/features/models/models-catalog.d.ts +0 -49
- package/dist/features/models/models-catalog.js +0 -80
- package/dist/features/models/models-catalog.route.d.ts +0 -43
- package/dist/features/models/models-catalog.route.js +0 -15
- package/dist/features/models/models-get-available.route.d.ts +0 -36
- package/dist/features/models/models-get-available.route.js +0 -66
- package/dist/features/models/models-get-enabled.route.d.ts +0 -33
- package/dist/features/models/models-get-enabled.route.js +0 -45
- package/dist/features/models/models-get-model-info.route.d.ts +0 -31
- package/dist/features/models/models-get-model-info.route.js +0 -84
- package/dist/features/models/models-model-disable.route.d.ts +0 -15
- package/dist/features/models/models-model-disable.route.js +0 -20
- package/dist/features/models/models-model-enable.route.d.ts +0 -13
- package/dist/features/models/models-model-enable.route.js +0 -20
- package/dist/features/models/models-provider-refresh.route.d.ts +0 -17
- package/dist/features/models/models-provider-refresh.route.js +0 -20
- package/dist/features/models/models.manager.d.ts +0 -58
- package/dist/features/models/models.manager.js +0 -138
- package/dist/features/models/models.routes.d.ts +0 -18
- package/dist/features/models/models.routes.js +0 -83
- package/dist/features/models/open-router-models.d.ts +0 -38
- package/dist/features/models/open-router-models.js +0 -73
- package/dist/features/models/openai-models.d.ts +0 -63
- package/dist/features/models/openai-models.js +0 -150
- package/dist/features/onboarding/onboarding-get-git-check.route.d.ts +0 -11
- package/dist/features/onboarding/onboarding-get-git-check.route.js +0 -28
- package/dist/features/onboarding/onboarding-get-status.route.d.ts +0 -12
- package/dist/features/onboarding/onboarding-get-status.route.js +0 -15
- package/dist/features/onboarding/onboarding-post-complete.route.d.ts +0 -12
- package/dist/features/onboarding/onboarding-post-complete.route.js +0 -15
- package/dist/features/onboarding/onboarding-post-reset.route.d.ts +0 -12
- package/dist/features/onboarding/onboarding-post-reset.route.js +0 -15
- package/dist/features/onboarding/onboarding.routes.d.ts +0 -18
- package/dist/features/onboarding/onboarding.routes.js +0 -28
- package/dist/features/project-todos/project-todos.database.d.ts +0 -38
- package/dist/features/project-todos/project-todos.database.js +0 -91
- package/dist/features/project-todos/project-todos.routes.d.ts +0 -4
- package/dist/features/project-todos/project-todos.routes.js +0 -94
- package/dist/features/projects/projects-ai-files.route.d.ts +0 -148
- package/dist/features/projects/projects-ai-files.route.js +0 -425
- package/dist/features/projects/projects-commands.route.d.ts +0 -27
- package/dist/features/projects/projects-commands.route.js +0 -39
- package/dist/features/projects/projects-create.route.d.ts +0 -19
- package/dist/features/projects/projects-create.route.js +0 -37
- package/dist/features/projects/projects-delete.route.d.ts +0 -24
- package/dist/features/projects/projects-delete.route.js +0 -34
- package/dist/features/projects/projects-get.route.d.ts +0 -47
- package/dist/features/projects/projects-get.route.js +0 -36
- package/dist/features/projects/projects-list.route.d.ts +0 -58
- package/dist/features/projects/projects-list.route.js +0 -59
- package/dist/features/projects/projects-open-folder.route.d.ts +0 -10
- package/dist/features/projects/projects-open-folder.route.js +0 -11
- package/dist/features/projects/projects-open.route.d.ts +0 -26
- package/dist/features/projects/projects-open.route.js +0 -49
- package/dist/features/projects/projects-package-scripts.route.d.ts +0 -15
- package/dist/features/projects/projects-package-scripts.route.js +0 -96
- package/dist/features/projects/projects-run-command.route.d.ts +0 -8
- package/dist/features/projects/projects-run-command.route.js +0 -21
- package/dist/features/projects/projects-run.route.d.ts +0 -51
- package/dist/features/projects/projects-run.route.js +0 -74
- package/dist/features/projects/projects-update.route.d.ts +0 -24
- package/dist/features/projects/projects-update.route.js +0 -81
- package/dist/features/projects/projects.creator.d.ts +0 -33
- package/dist/features/projects/projects.creator.js +0 -555
- package/dist/features/projects/projects.database.d.ts +0 -61
- package/dist/features/projects/projects.database.js +0 -212
- package/dist/features/projects/projects.manager.d.ts +0 -291
- package/dist/features/projects/projects.manager.js +0 -426
- package/dist/features/projects/projects.open-with.d.ts +0 -27
- package/dist/features/projects/projects.open-with.js +0 -156
- package/dist/features/projects/projects.routes.d.ts +0 -20
- package/dist/features/projects/projects.routes.js +0 -255
- package/dist/features/projects/terminal-session-manager.d.ts +0 -55
- package/dist/features/projects/terminal-session-manager.js +0 -90
- package/dist/features/providers/provider-resolver.d.ts +0 -13
- package/dist/features/providers/provider-resolver.js +0 -22
- package/dist/features/providers/providers-get-credits.route.d.ts +0 -15
- package/dist/features/providers/providers-get-credits.route.js +0 -51
- package/dist/features/providers/providers-get.route.d.ts +0 -16
- package/dist/features/providers/providers-get.route.js +0 -32
- package/dist/features/providers/providers-open-external.route.d.ts +0 -15
- package/dist/features/providers/providers-open-external.route.js +0 -49
- package/dist/features/providers/providers-post-bulk-keys.route.d.ts +0 -14
- package/dist/features/providers/providers-post-bulk-keys.route.js +0 -31
- package/dist/features/providers/providers-post-keys.route.d.ts +0 -14
- package/dist/features/providers/providers-post-keys.route.js +0 -25
- package/dist/features/providers/providers.routes.d.ts +0 -19
- package/dist/features/providers/providers.routes.js +0 -31
- package/dist/features/rules/rules-post.route.d.ts +0 -43
- package/dist/features/rules/rules-post.route.js +0 -89
- package/dist/features/rules/rules.manager.d.ts +0 -36
- package/dist/features/rules/rules.manager.js +0 -203
- package/dist/features/rules/rules.routes.d.ts +0 -12
- package/dist/features/rules/rules.routes.js +0 -13
- package/dist/features/run/run-get-running.route.d.ts +0 -15
- package/dist/features/run/run-get-running.route.js +0 -21
- package/dist/features/run/run-post-start.route.d.ts +0 -8
- package/dist/features/run/run-post-start.route.js +0 -21
- package/dist/features/run/run-post-stop.route.d.ts +0 -15
- package/dist/features/run/run-post-stop.route.js +0 -24
- package/dist/features/run/run-post-suggest.route.d.ts +0 -15
- package/dist/features/run/run-post-suggest.route.js +0 -21
- package/dist/features/run/run-put-command.route.d.ts +0 -15
- package/dist/features/run/run-put-command.route.js +0 -24
- package/dist/features/run/run.routes.d.ts +0 -19
- package/dist/features/run/run.routes.js +0 -31
- package/dist/features/scaffold/index.d.ts +0 -7
- package/dist/features/scaffold/index.js +0 -5
- package/dist/features/scaffold/scaffold-get-templates.route.d.ts +0 -27
- package/dist/features/scaffold/scaffold-get-templates.route.js +0 -17
- package/dist/features/scaffold/scaffold-post.route.d.ts +0 -8
- package/dist/features/scaffold/scaffold-post.route.js +0 -30
- package/dist/features/scaffold/scaffold.routes.d.ts +0 -10
- package/dist/features/scaffold/scaffold.routes.js +0 -16
- package/dist/features/scaffold/scaffold.runner.d.ts +0 -48
- package/dist/features/scaffold/scaffold.runner.js +0 -475
- package/dist/features/scaffold/scaffold.types.d.ts +0 -26
- package/dist/features/scaffold/scaffold.types.js +0 -5
- package/dist/features/skills/skills.activation.d.ts +0 -31
- package/dist/features/skills/skills.activation.js +0 -155
- package/dist/features/skills/skills.manager.d.ts +0 -35
- package/dist/features/skills/skills.manager.js +0 -251
- package/dist/features/slash-commands/slash-commands-delete.route.d.ts +0 -23
- package/dist/features/slash-commands/slash-commands-delete.route.js +0 -36
- package/dist/features/slash-commands/slash-commands-get.route.d.ts +0 -53
- package/dist/features/slash-commands/slash-commands-get.route.js +0 -54
- package/dist/features/slash-commands/slash-commands-post.route.d.ts +0 -39
- package/dist/features/slash-commands/slash-commands-post.route.js +0 -70
- package/dist/features/slash-commands/slash-commands-put.route.d.ts +0 -23
- package/dist/features/slash-commands/slash-commands-put.route.js +0 -36
- package/dist/features/slash-commands/slash-commands.manager.d.ts +0 -46
- package/dist/features/slash-commands/slash-commands.manager.js +0 -265
- package/dist/features/slash-commands/slash-commands.routes.d.ts +0 -13
- package/dist/features/slash-commands/slash-commands.routes.js +0 -20
- package/dist/features/threads/threads-ai-files.route.d.ts +0 -153
- package/dist/features/threads/threads-ai-files.route.js +0 -287
- package/dist/features/threads/threads-conversation-folder-path.route.d.ts +0 -14
- package/dist/features/threads/threads-conversation-folder-path.route.js +0 -23
- package/dist/features/threads/threads-create.route.d.ts +0 -22
- package/dist/features/threads/threads-create.route.js +0 -60
- package/dist/features/threads/threads-delete.route.d.ts +0 -25
- package/dist/features/threads/threads-delete.route.js +0 -35
- package/dist/features/threads/threads-files.route.d.ts +0 -15
- package/dist/features/threads/threads-files.route.js +0 -20
- package/dist/features/threads/threads-fix-comments.route.d.ts +0 -26
- package/dist/features/threads/threads-fix-comments.route.js +0 -45
- package/dist/features/threads/threads-get.route.d.ts +0 -30
- package/dist/features/threads/threads-get.route.js +0 -38
- package/dist/features/threads/threads-list.route.d.ts +0 -56
- package/dist/features/threads/threads-list.route.js +0 -58
- package/dist/features/threads/threads-messages.route.d.ts +0 -28
- package/dist/features/threads/threads-messages.route.js +0 -110
- package/dist/features/threads/threads-open.route.d.ts +0 -26
- package/dist/features/threads/threads-open.route.js +0 -62
- package/dist/features/threads/threads-select.route.d.ts +0 -25
- package/dist/features/threads/threads-select.route.js +0 -35
- package/dist/features/threads/threads-update.route.d.ts +0 -15
- package/dist/features/threads/threads-update.route.js +0 -30
- package/dist/features/threads/threads.database.d.ts +0 -68
- package/dist/features/threads/threads.database.js +0 -215
- package/dist/features/threads/threads.manager.d.ts +0 -204
- package/dist/features/threads/threads.manager.js +0 -505
- package/dist/features/threads/threads.routes.d.ts +0 -20
- package/dist/features/threads/threads.routes.js +0 -230
- package/dist/features/todos/todos.database.d.ts +0 -14
- package/dist/features/todos/todos.database.js +0 -31
- package/dist/features/updates/updates.routes.d.ts +0 -13
- package/dist/features/updates/updates.routes.js +0 -40
- package/dist/index.d.ts +0 -3
- package/dist/project-analyzer.d.ts +0 -26
- package/dist/project-analyzer.js +0 -307
- package/dist/server.d.ts +0 -12
- package/dist/server.js +0 -142
- package/dist/tools/agent-tool.d.ts +0 -49
- package/dist/tools/agent-tool.js +0 -131
- package/dist/tools/ask-user.d.ts +0 -25
- package/dist/tools/ask-user.js +0 -74
- package/dist/tools/ast-grep.d.ts +0 -28
- package/dist/tools/ast-grep.js +0 -273
- package/dist/tools/bash.d.ts +0 -33
- package/dist/tools/bash.js +0 -186
- package/dist/tools/edit-diff.d.ts +0 -24
- package/dist/tools/edit-diff.js +0 -136
- package/dist/tools/edit.d.ts +0 -28
- package/dist/tools/edit.js +0 -78
- package/dist/tools/find.d.ts +0 -31
- package/dist/tools/find.js +0 -117
- package/dist/tools/grep.d.ts +0 -37
- package/dist/tools/grep.js +0 -231
- package/dist/tools/index.d.ts +0 -93
- package/dist/tools/index.js +0 -110
- package/dist/tools/ls.d.ts +0 -31
- package/dist/tools/ls.js +0 -108
- package/dist/tools/mcp-tools.d.ts +0 -31
- package/dist/tools/mcp-tools.js +0 -59
- package/dist/tools/path-utils.d.ts +0 -14
- package/dist/tools/path-utils.js +0 -87
- package/dist/tools/read.d.ts +0 -27
- package/dist/tools/read.js +0 -86
- package/dist/tools/resolve-bin.d.ts +0 -5
- package/dist/tools/resolve-bin.js +0 -28
- package/dist/tools/shell.d.ts +0 -7
- package/dist/tools/shell.js +0 -143
- package/dist/tools/skill-reference-tool.d.ts +0 -30
- package/dist/tools/skill-reference-tool.js +0 -171
- package/dist/tools/skill-tool.d.ts +0 -33
- package/dist/tools/skill-tool.js +0 -213
- package/dist/tools/todo.d.ts +0 -20
- package/dist/tools/todo.js +0 -168
- package/dist/tools/tool-helpers.d.ts +0 -78
- package/dist/tools/tool-helpers.js +0 -109
- package/dist/tools/truncate.d.ts +0 -31
- package/dist/tools/truncate.js +0 -164
- package/dist/tools/write.d.ts +0 -21
- package/dist/tools/write.js +0 -65
package/dist/tools/ast-grep.js
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import { Type } from "@sinclair/typebox";
|
|
2
|
-
import { spawnProcess } from "../core/utils.js";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { existsSync, readdirSync } from "fs";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
import { resolveToCwd, validatePathWithinCwd } from "./path-utils.js";
|
|
7
|
-
import { DEFAULT_MAX_BYTES, formatSize, GREP_MAX_LINE_LENGTH, truncateHead, truncateLine, } from "./truncate.js";
|
|
8
|
-
const astGrepSchema = Type.Object({
|
|
9
|
-
command: Type.Union([Type.Literal("run"), Type.Literal("scan")], {
|
|
10
|
-
description: "Mode: 'run' for simple pattern search, 'scan' for complex rule-based search",
|
|
11
|
-
}),
|
|
12
|
-
pattern: Type.Optional(Type.String({
|
|
13
|
-
description: "AST pattern for 'run' command. Use metavariables like $NAME, $$$ARGS. Example: 'console.log($ARG)'",
|
|
14
|
-
})),
|
|
15
|
-
lang: Type.String({
|
|
16
|
-
description: "Language to parse: javascript, typescript, python, rust, go, java, css, html, etc.",
|
|
17
|
-
}),
|
|
18
|
-
rule: Type.Optional(Type.String({
|
|
19
|
-
description: "YAML rule for 'scan' command. Supports kind, has, inside, all, any, not. Example: 'id: test\\nlanguage: javascript\\nrule:\\n kind: function_declaration\\n has:\\n pattern: await $EXPR\\n stopBy: end'",
|
|
20
|
-
})),
|
|
21
|
-
path: Type.Optional(Type.String({
|
|
22
|
-
description: "Directory or file to search (default: current directory)",
|
|
23
|
-
})),
|
|
24
|
-
limit: Type.Optional(Type.Number({
|
|
25
|
-
description: "Maximum number of matches to return (default: 50)",
|
|
26
|
-
})),
|
|
27
|
-
});
|
|
28
|
-
const DEFAULT_LIMIT = 50;
|
|
29
|
-
const PLATFORM_PACKAGES = {
|
|
30
|
-
"darwin-arm64": "@ast-grep/cli-darwin-arm64",
|
|
31
|
-
"darwin-x64": "@ast-grep/cli-darwin-x64",
|
|
32
|
-
"linux-arm64": "@ast-grep/cli-linux-arm64-gnu",
|
|
33
|
-
"linux-x64": "@ast-grep/cli-linux-x64-gnu",
|
|
34
|
-
"win32-arm64": "@ast-grep/cli-win32-arm64-msvc",
|
|
35
|
-
"win32-ia32": "@ast-grep/cli-win32-ia32-msvc",
|
|
36
|
-
"win32-x64": "@ast-grep/cli-win32-x64-msvc",
|
|
37
|
-
};
|
|
38
|
-
function findBinInNodeModules(startDir, pkg, binName) {
|
|
39
|
-
const pkgPath = pkg.replace("/", path.sep);
|
|
40
|
-
let dir = startDir;
|
|
41
|
-
while (true) {
|
|
42
|
-
const nmDir = path.join(dir, "node_modules");
|
|
43
|
-
// Standard layout: node_modules/@ast-grep/cli-darwin-arm64/ast-grep
|
|
44
|
-
const standardPath = path.join(nmDir, pkgPath, binName);
|
|
45
|
-
if (existsSync(standardPath))
|
|
46
|
-
return standardPath;
|
|
47
|
-
// Bun cache layout: node_modules/.bun/@ast-grep+cli-darwin-arm64@*/node_modules/@ast-grep/cli-darwin-arm64/ast-grep
|
|
48
|
-
const bunDir = path.join(nmDir, ".bun");
|
|
49
|
-
if (existsSync(bunDir)) {
|
|
50
|
-
const bunPrefix = pkg.replace("/", "+");
|
|
51
|
-
try {
|
|
52
|
-
const entries = readdirSync(bunDir);
|
|
53
|
-
const match = entries.find((e) => e.startsWith(bunPrefix + "@"));
|
|
54
|
-
if (match) {
|
|
55
|
-
const bunPath = path.join(bunDir, match, "node_modules", pkgPath, binName);
|
|
56
|
-
if (existsSync(bunPath))
|
|
57
|
-
return bunPath;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
// ignore
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const parent = path.dirname(dir);
|
|
65
|
-
if (parent === dir)
|
|
66
|
-
break;
|
|
67
|
-
dir = parent;
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
// Resolve from the tarsk app's own install directory (where @ast-grep/cli is a dependency)
|
|
72
|
-
const APP_DIR = path.resolve(fileURLToPath(import.meta.url), "../../..");
|
|
73
|
-
function resolveAstGrepBin(cwd) {
|
|
74
|
-
const key = `${process.platform}-${process.arch}`;
|
|
75
|
-
const pkg = PLATFORM_PACKAGES[key];
|
|
76
|
-
if (!pkg)
|
|
77
|
-
return null;
|
|
78
|
-
const binName = process.platform === "win32" ? "ast-grep.exe" : "ast-grep";
|
|
79
|
-
console.log(`[ast-grep] resolving binary: platform=${key}, pkg=${pkg}, APP_DIR=${APP_DIR}`);
|
|
80
|
-
// First: search from the tarsk app's own directory (where @ast-grep/cli is installed as a dependency)
|
|
81
|
-
const appResult = findBinInNodeModules(APP_DIR, pkg, binName);
|
|
82
|
-
if (appResult)
|
|
83
|
-
return appResult;
|
|
84
|
-
// Fallback: search from the user's working directory
|
|
85
|
-
return findBinInNodeModules(cwd, pkg, binName);
|
|
86
|
-
}
|
|
87
|
-
export function createAstGrepTool(cwd) {
|
|
88
|
-
return {
|
|
89
|
-
name: "ast_grep",
|
|
90
|
-
label: "Code Search",
|
|
91
|
-
description: `Structural code search using AST patterns. Matches code by structure, not text. Use 'run' for simple pattern matching (e.g. 'console.log($ARG)') or 'scan' for complex YAML rules with kind/has/inside/all/any/not. Output truncated to ${DEFAULT_LIMIT} matches or ${DEFAULT_MAX_BYTES / 1024}KB.`,
|
|
92
|
-
parameters: astGrepSchema,
|
|
93
|
-
execute: async (_toolCallId, { command, pattern, lang, rule, path: searchDir, limit }, signal) => {
|
|
94
|
-
return new Promise((resolve, reject) => {
|
|
95
|
-
if (signal?.aborted) {
|
|
96
|
-
reject(new Error("Operation aborted"));
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
let settled = false;
|
|
100
|
-
const settle = (fn) => {
|
|
101
|
-
if (!settled) {
|
|
102
|
-
settled = true;
|
|
103
|
-
fn();
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
void (async () => {
|
|
107
|
-
try {
|
|
108
|
-
if (command === "run" && !pattern) {
|
|
109
|
-
settle(() => reject(new Error("'pattern' is required when command is 'run'")));
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (command === "scan" && !rule) {
|
|
113
|
-
settle(() => reject(new Error("'rule' is required when command is 'scan'")));
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const searchPath = resolveToCwd(searchDir ?? ".", cwd);
|
|
117
|
-
validatePathWithinCwd(searchPath, cwd);
|
|
118
|
-
const effectiveLimit = Math.max(1, limit ?? DEFAULT_LIMIT);
|
|
119
|
-
const args = [];
|
|
120
|
-
if (command === "run") {
|
|
121
|
-
args.push("run", "--pattern", pattern, "--lang", lang, "--json", searchPath);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
args.push("scan", "--inline-rules", rule, "--json", searchPath);
|
|
125
|
-
}
|
|
126
|
-
const binPath = resolveAstGrepBin(cwd);
|
|
127
|
-
if (!binPath) {
|
|
128
|
-
settle(() => reject(new Error("ast-grep is not available. Install @ast-grep/cli or add it to PATH.")));
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
console.log(`[ast-grep] ${binPath} ${args.join(" ")}`);
|
|
132
|
-
const child = spawnProcess(binPath, args, {
|
|
133
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
134
|
-
});
|
|
135
|
-
const MAX_STDOUT_BYTES = 2 * 1024 * 1024; // 2MB cap on raw stdout
|
|
136
|
-
let stdout = "";
|
|
137
|
-
let stdoutBytes = 0;
|
|
138
|
-
let stderr = "";
|
|
139
|
-
let aborted = false;
|
|
140
|
-
let killedDueToCap = false;
|
|
141
|
-
const onAbort = () => {
|
|
142
|
-
aborted = true;
|
|
143
|
-
if (!child.killed)
|
|
144
|
-
child.kill();
|
|
145
|
-
};
|
|
146
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
147
|
-
child.stdout?.on("data", (chunk) => {
|
|
148
|
-
if (killedDueToCap)
|
|
149
|
-
return;
|
|
150
|
-
stdoutBytes += chunk.length;
|
|
151
|
-
if (stdoutBytes > MAX_STDOUT_BYTES) {
|
|
152
|
-
killedDueToCap = true;
|
|
153
|
-
if (!child.killed)
|
|
154
|
-
child.kill();
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
stdout += chunk.toString();
|
|
158
|
-
});
|
|
159
|
-
child.stderr?.on("data", (chunk) => {
|
|
160
|
-
stderr += chunk.toString();
|
|
161
|
-
});
|
|
162
|
-
child.on("error", (error) => {
|
|
163
|
-
signal?.removeEventListener("abort", onAbort);
|
|
164
|
-
settle(() => reject(new Error(`Failed to run ast-grep: ${error.message}`)));
|
|
165
|
-
});
|
|
166
|
-
child.on("close", (code) => {
|
|
167
|
-
signal?.removeEventListener("abort", onAbort);
|
|
168
|
-
console.log(`[ast-grep] exit code: ${code}, stdout: ${stdout.length} bytes, stderr: ${stderr.length} bytes`);
|
|
169
|
-
if (stderr.trim())
|
|
170
|
-
console.log(`[ast-grep] stderr: ${stderr.trim()}`);
|
|
171
|
-
if (aborted) {
|
|
172
|
-
settle(() => reject(new Error("Operation aborted")));
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (!killedDueToCap && code !== 0 && code !== 1) {
|
|
176
|
-
const errMsg = stderr.trim() || `ast-grep exited with code ${code}`;
|
|
177
|
-
settle(() => reject(new Error(errMsg)));
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
let matches;
|
|
181
|
-
try {
|
|
182
|
-
matches = JSON.parse(stdout || "[]");
|
|
183
|
-
}
|
|
184
|
-
catch {
|
|
185
|
-
// If killed due to cap, stdout is truncated JSON — try to recover
|
|
186
|
-
if (killedDueToCap) {
|
|
187
|
-
const lastBrace = stdout.lastIndexOf("}");
|
|
188
|
-
if (lastBrace > 0) {
|
|
189
|
-
try {
|
|
190
|
-
matches = JSON.parse(stdout.slice(0, lastBrace + 1) + "]");
|
|
191
|
-
}
|
|
192
|
-
catch {
|
|
193
|
-
matches = [];
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
matches = [];
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
else if (!stdout.trim()) {
|
|
201
|
-
settle(() => resolve({
|
|
202
|
-
content: [{ type: "text", text: "No matches found" }],
|
|
203
|
-
details: undefined,
|
|
204
|
-
}));
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
settle(() => reject(new Error(`Failed to parse ast-grep JSON output: ${stdout.slice(0, 200)}`)));
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (!Array.isArray(matches) || matches.length === 0) {
|
|
213
|
-
settle(() => resolve({
|
|
214
|
-
content: [{ type: "text", text: "No matches found" }],
|
|
215
|
-
details: undefined,
|
|
216
|
-
}));
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
const matchLimitReached = matches.length > effectiveLimit;
|
|
220
|
-
if (matchLimitReached) {
|
|
221
|
-
matches = matches.slice(0, effectiveLimit);
|
|
222
|
-
}
|
|
223
|
-
let linesTruncated = false;
|
|
224
|
-
const outputLines = [];
|
|
225
|
-
for (const match of matches) {
|
|
226
|
-
const filePath = match.file ?? "unknown";
|
|
227
|
-
const relativePath = path.relative(searchPath, filePath).replace(/\\/g, "/") || filePath;
|
|
228
|
-
const lineNum = (match.range?.start?.line ?? 0) + 1;
|
|
229
|
-
const matchText = (match.lines ?? match.text ?? "").trimEnd();
|
|
230
|
-
const firstLine = matchText.split("\n")[0] ?? "";
|
|
231
|
-
const { text: truncatedText, wasTruncated } = truncateLine(firstLine);
|
|
232
|
-
if (wasTruncated)
|
|
233
|
-
linesTruncated = true;
|
|
234
|
-
outputLines.push(`${relativePath}:${lineNum}: ${truncatedText}`);
|
|
235
|
-
}
|
|
236
|
-
const rawOutput = outputLines.join("\n");
|
|
237
|
-
const truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });
|
|
238
|
-
let output = truncation.content;
|
|
239
|
-
const details = {};
|
|
240
|
-
const notices = [];
|
|
241
|
-
if (killedDueToCap) {
|
|
242
|
-
notices.push(`Output exceeded 2MB cap. Refine your pattern for more precise results`);
|
|
243
|
-
}
|
|
244
|
-
if (matchLimitReached) {
|
|
245
|
-
notices.push(`${effectiveLimit} matches limit reached. Use limit=${effectiveLimit * 2} for more, or refine pattern`);
|
|
246
|
-
details.matchLimitReached = effectiveLimit;
|
|
247
|
-
}
|
|
248
|
-
if (truncation.truncated) {
|
|
249
|
-
notices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);
|
|
250
|
-
details.truncation = truncation;
|
|
251
|
-
}
|
|
252
|
-
if (linesTruncated) {
|
|
253
|
-
notices.push(`Some lines truncated to ${GREP_MAX_LINE_LENGTH} chars. Use read tool to see full lines`);
|
|
254
|
-
details.linesTruncated = true;
|
|
255
|
-
}
|
|
256
|
-
if (notices.length > 0)
|
|
257
|
-
output += `\n\n[${notices.join(". ")}]`;
|
|
258
|
-
settle(() => resolve({
|
|
259
|
-
content: [{ type: "text", text: output }],
|
|
260
|
-
details: Object.keys(details).length > 0 ? details : undefined,
|
|
261
|
-
}));
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
catch {
|
|
265
|
-
settle(() => reject(new Error("Error processing ast-grep request")));
|
|
266
|
-
}
|
|
267
|
-
})();
|
|
268
|
-
});
|
|
269
|
-
},
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
export const astGrepTool = createAstGrepTool(process.cwd());
|
|
273
|
-
//# sourceMappingURL=ast-grep.js.map
|
package/dist/tools/bash.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
-
import { type Static } from "@sinclair/typebox";
|
|
3
|
-
import { type TruncationResult } from "./truncate.js";
|
|
4
|
-
declare const bashSchema: import("@sinclair/typebox").TObject<{
|
|
5
|
-
command: import("@sinclair/typebox").TString;
|
|
6
|
-
timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
7
|
-
}>;
|
|
8
|
-
export type BashToolInput = Static<typeof bashSchema>;
|
|
9
|
-
export interface BashToolDetails {
|
|
10
|
-
truncation?: TruncationResult;
|
|
11
|
-
fullOutputPath?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface BashOperations {
|
|
14
|
-
exec: (command: string, cwd: string, options: {
|
|
15
|
-
onData: (data: Buffer) => void;
|
|
16
|
-
signal?: AbortSignal;
|
|
17
|
-
timeout?: number;
|
|
18
|
-
env?: NodeJS.ProcessEnv;
|
|
19
|
-
}) => Promise<{
|
|
20
|
-
exitCode: number | null;
|
|
21
|
-
}>;
|
|
22
|
-
}
|
|
23
|
-
export interface BashToolOptions {
|
|
24
|
-
operations?: BashOperations;
|
|
25
|
-
commandPrefix?: string;
|
|
26
|
-
}
|
|
27
|
-
export declare function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema>;
|
|
28
|
-
export declare const bashTool: AgentTool<import("@sinclair/typebox").TObject<{
|
|
29
|
-
command: import("@sinclair/typebox").TString;
|
|
30
|
-
timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
31
|
-
}>, any>;
|
|
32
|
-
export {};
|
|
33
|
-
//# sourceMappingURL=bash.d.ts.map
|
package/dist/tools/bash.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { randomBytes } from "node:crypto";
|
|
2
|
-
import { createWriteStream, existsSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { Type } from "@sinclair/typebox";
|
|
6
|
-
import { spawnProcess } from "../core/utils.js";
|
|
7
|
-
import { getShellConfig, getShellEnv, killProcessTree } from "./shell.js";
|
|
8
|
-
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateTail, } from "./truncate.js";
|
|
9
|
-
function getTempFilePath() {
|
|
10
|
-
return join(tmpdir(), `tarsk-bash-${randomBytes(8).toString("hex")}.log`);
|
|
11
|
-
}
|
|
12
|
-
const bashSchema = Type.Object({
|
|
13
|
-
command: Type.String({ description: "Bash command to execute" }),
|
|
14
|
-
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional)" })),
|
|
15
|
-
});
|
|
16
|
-
const defaultBashOperations = {
|
|
17
|
-
exec: (command, cwd, { onData, signal, timeout, env }) => {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
const { shell, args } = getShellConfig();
|
|
20
|
-
if (!existsSync(cwd)) {
|
|
21
|
-
reject(new Error(`Working directory does not exist: ${cwd}`));
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const child = spawnProcess(shell, [...args, command], {
|
|
25
|
-
cwd,
|
|
26
|
-
detached: true,
|
|
27
|
-
env: (env
|
|
28
|
-
? Object.fromEntries(Object.entries(env)
|
|
29
|
-
.filter(([_, v]) => v !== undefined)
|
|
30
|
-
.map(([k, v]) => [k, v]))
|
|
31
|
-
: undefined) ??
|
|
32
|
-
Object.fromEntries(Object.entries(getShellEnv())
|
|
33
|
-
.filter(([_, v]) => v !== undefined)
|
|
34
|
-
.map(([k, v]) => [k, v])),
|
|
35
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
36
|
-
});
|
|
37
|
-
let timedOut = false;
|
|
38
|
-
let timeoutHandle;
|
|
39
|
-
if (timeout !== undefined && timeout > 0) {
|
|
40
|
-
timeoutHandle = setTimeout(() => {
|
|
41
|
-
timedOut = true;
|
|
42
|
-
if (child.pid)
|
|
43
|
-
killProcessTree(child.pid);
|
|
44
|
-
}, timeout * 1000);
|
|
45
|
-
}
|
|
46
|
-
if (child.stdout)
|
|
47
|
-
child.stdout.on("data", onData);
|
|
48
|
-
if (child.stderr)
|
|
49
|
-
child.stderr.on("data", onData);
|
|
50
|
-
child.on("error", (err) => {
|
|
51
|
-
if (timeoutHandle)
|
|
52
|
-
clearTimeout(timeoutHandle);
|
|
53
|
-
if (signal)
|
|
54
|
-
signal.removeEventListener("abort", onAbort);
|
|
55
|
-
reject(err);
|
|
56
|
-
});
|
|
57
|
-
const onAbort = () => {
|
|
58
|
-
if (child.pid)
|
|
59
|
-
killProcessTree(child.pid);
|
|
60
|
-
};
|
|
61
|
-
if (signal) {
|
|
62
|
-
if (signal.aborted)
|
|
63
|
-
onAbort();
|
|
64
|
-
else
|
|
65
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
66
|
-
}
|
|
67
|
-
child.on("close", (code) => {
|
|
68
|
-
if (timeoutHandle)
|
|
69
|
-
clearTimeout(timeoutHandle);
|
|
70
|
-
if (signal)
|
|
71
|
-
signal.removeEventListener("abort", onAbort);
|
|
72
|
-
if (signal?.aborted) {
|
|
73
|
-
reject(new Error("aborted"));
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (timedOut) {
|
|
77
|
-
reject(new Error(`timeout:${timeout}`));
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
resolve({ exitCode: code });
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
export function createBashTool(cwd, options) {
|
|
86
|
-
const ops = options?.operations ?? defaultBashOperations;
|
|
87
|
-
const commandPrefix = options?.commandPrefix;
|
|
88
|
-
return {
|
|
89
|
-
name: "bash",
|
|
90
|
-
label: "bash",
|
|
91
|
-
description: `Execute a bash command in the current working directory. Output truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB. Optionally provide a timeout in seconds.`,
|
|
92
|
-
parameters: bashSchema,
|
|
93
|
-
execute: async (_toolCallId, { command, timeout }, signal, onUpdate) => {
|
|
94
|
-
const resolvedCommand = commandPrefix ? `${commandPrefix}\n${command}` : command;
|
|
95
|
-
console.log(`[ai] bash-start: ${resolvedCommand}`);
|
|
96
|
-
return new Promise((resolve, reject) => {
|
|
97
|
-
let tempFilePath;
|
|
98
|
-
let tempFileStream;
|
|
99
|
-
let totalBytes = 0;
|
|
100
|
-
const chunks = [];
|
|
101
|
-
let chunksBytes = 0;
|
|
102
|
-
const maxChunksBytes = DEFAULT_MAX_BYTES * 2;
|
|
103
|
-
const handleData = (data) => {
|
|
104
|
-
totalBytes += data.length;
|
|
105
|
-
if (totalBytes > DEFAULT_MAX_BYTES && !tempFilePath) {
|
|
106
|
-
tempFilePath = getTempFilePath();
|
|
107
|
-
tempFileStream = createWriteStream(tempFilePath);
|
|
108
|
-
for (const chunk of chunks)
|
|
109
|
-
tempFileStream.write(chunk);
|
|
110
|
-
}
|
|
111
|
-
if (tempFileStream)
|
|
112
|
-
tempFileStream.write(data);
|
|
113
|
-
chunks.push(data);
|
|
114
|
-
chunksBytes += data.length;
|
|
115
|
-
while (chunksBytes > maxChunksBytes && chunks.length > 1) {
|
|
116
|
-
const removed = chunks.shift();
|
|
117
|
-
chunksBytes -= removed.length;
|
|
118
|
-
}
|
|
119
|
-
if (onUpdate) {
|
|
120
|
-
const fullText = Buffer.concat(chunks).toString("utf-8");
|
|
121
|
-
const truncation = truncateTail(fullText);
|
|
122
|
-
onUpdate({
|
|
123
|
-
content: [{ type: "text", text: truncation.content || "" }],
|
|
124
|
-
details: {
|
|
125
|
-
truncation: truncation.truncated ? truncation : undefined,
|
|
126
|
-
fullOutputPath: tempFilePath,
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
ops
|
|
132
|
-
.exec(resolvedCommand, cwd, { onData: handleData, signal, timeout, env: getShellEnv() })
|
|
133
|
-
.then(({ exitCode }) => {
|
|
134
|
-
console.log(`[ai] bash-end: ${resolvedCommand}`);
|
|
135
|
-
if (tempFileStream)
|
|
136
|
-
tempFileStream.end();
|
|
137
|
-
const fullOutput = Buffer.concat(chunks).toString("utf-8");
|
|
138
|
-
const truncation = truncateTail(fullOutput);
|
|
139
|
-
let outputText = truncation.content || "(no output)";
|
|
140
|
-
let details;
|
|
141
|
-
if (truncation.truncated) {
|
|
142
|
-
details = { truncation, fullOutputPath: tempFilePath };
|
|
143
|
-
const startLine = truncation.totalLines - truncation.outputLines + 1;
|
|
144
|
-
const endLine = truncation.totalLines;
|
|
145
|
-
if (truncation.lastLinePartial) {
|
|
146
|
-
outputText += `\n\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine}. Full output: ${tempFilePath}]`;
|
|
147
|
-
}
|
|
148
|
-
else if (truncation.truncatedBy === "lines") {
|
|
149
|
-
outputText += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${tempFilePath}]`;
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
outputText += `\n\n[Showing lines ${startLine}-${endLine} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${tempFilePath}]`;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (exitCode !== 0 && exitCode !== null) {
|
|
156
|
-
outputText += `\n\nCommand exited with code ${exitCode}`;
|
|
157
|
-
reject(new Error(outputText));
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
resolve({ content: [{ type: "text", text: outputText }], details });
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
.catch((err) => {
|
|
164
|
-
console.log(`[ai] bash-end: ${resolvedCommand}`);
|
|
165
|
-
if (tempFileStream)
|
|
166
|
-
tempFileStream.end();
|
|
167
|
-
const output = Buffer.concat(chunks).toString("utf-8");
|
|
168
|
-
if (err.message === "aborted") {
|
|
169
|
-
reject(new Error(output ? `${output}\n\nCommand aborted` : "Command aborted"));
|
|
170
|
-
}
|
|
171
|
-
else if (err.message.startsWith("timeout:")) {
|
|
172
|
-
const secs = err.message.split(":")[1];
|
|
173
|
-
reject(new Error(output
|
|
174
|
-
? `${output}\n\nCommand timed out after ${secs} seconds`
|
|
175
|
-
: `Command timed out after ${secs} seconds`));
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
reject(err);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
export const bashTool = createBashTool(process.cwd());
|
|
186
|
-
//# sourceMappingURL=bash.js.map
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared diff computation utilities for the edit tool.
|
|
3
|
-
*/
|
|
4
|
-
export declare function detectLineEnding(content: string): "\r\n" | "\n";
|
|
5
|
-
export declare function normalizeToLF(text: string): string;
|
|
6
|
-
export declare function restoreLineEndings(text: string, ending: "\r\n" | "\n"): string;
|
|
7
|
-
export declare function normalizeForFuzzyMatch(text: string): string;
|
|
8
|
-
export interface FuzzyMatchResult {
|
|
9
|
-
found: boolean;
|
|
10
|
-
index: number;
|
|
11
|
-
matchLength: number;
|
|
12
|
-
usedFuzzyMatch: boolean;
|
|
13
|
-
contentForReplacement: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult;
|
|
16
|
-
export declare function stripBom(content: string): {
|
|
17
|
-
bom: string;
|
|
18
|
-
text: string;
|
|
19
|
-
};
|
|
20
|
-
export declare function generateDiffString(oldContent: string, newContent: string, contextLines?: number): {
|
|
21
|
-
diff: string;
|
|
22
|
-
firstChangedLine: number | undefined;
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=edit-diff.d.ts.map
|
package/dist/tools/edit-diff.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared diff computation utilities for the edit tool.
|
|
3
|
-
*/
|
|
4
|
-
import * as Diff from "diff";
|
|
5
|
-
export function detectLineEnding(content) {
|
|
6
|
-
const crlfIdx = content.indexOf("\r\n");
|
|
7
|
-
const lfIdx = content.indexOf("\n");
|
|
8
|
-
if (lfIdx === -1)
|
|
9
|
-
return "\n";
|
|
10
|
-
if (crlfIdx === -1)
|
|
11
|
-
return "\n";
|
|
12
|
-
return crlfIdx < lfIdx ? "\r\n" : "\n";
|
|
13
|
-
}
|
|
14
|
-
export function normalizeToLF(text) {
|
|
15
|
-
return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
16
|
-
}
|
|
17
|
-
export function restoreLineEndings(text, ending) {
|
|
18
|
-
return ending === "\r\n" ? text.replace(/\n/g, "\r\n") : text;
|
|
19
|
-
}
|
|
20
|
-
export function normalizeForFuzzyMatch(text) {
|
|
21
|
-
return text
|
|
22
|
-
.split("\n")
|
|
23
|
-
.map((line) => line.trimEnd())
|
|
24
|
-
.join("\n")
|
|
25
|
-
.replace(/[\u2018\u2019\u201A\u201B]/g, "'")
|
|
26
|
-
.replace(/[\u201C\u201D\u201E\u201F]/g, '"')
|
|
27
|
-
.replace(/[\u2010\u2011\u2012\u2013\u2014\u2015\u2212]/g, "-")
|
|
28
|
-
.replace(/[\u00A0\u2002-\u200A\u202F\u205F\u3000]/g, " ");
|
|
29
|
-
}
|
|
30
|
-
export function fuzzyFindText(content, oldText) {
|
|
31
|
-
const exactIndex = content.indexOf(oldText);
|
|
32
|
-
if (exactIndex !== -1) {
|
|
33
|
-
return {
|
|
34
|
-
found: true,
|
|
35
|
-
index: exactIndex,
|
|
36
|
-
matchLength: oldText.length,
|
|
37
|
-
usedFuzzyMatch: false,
|
|
38
|
-
contentForReplacement: content,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const fuzzyContent = normalizeForFuzzyMatch(content);
|
|
42
|
-
const fuzzyOldText = normalizeForFuzzyMatch(oldText);
|
|
43
|
-
const fuzzyIndex = fuzzyContent.indexOf(fuzzyOldText);
|
|
44
|
-
if (fuzzyIndex === -1) {
|
|
45
|
-
return {
|
|
46
|
-
found: false,
|
|
47
|
-
index: -1,
|
|
48
|
-
matchLength: 0,
|
|
49
|
-
usedFuzzyMatch: false,
|
|
50
|
-
contentForReplacement: content,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
found: true,
|
|
55
|
-
index: fuzzyIndex,
|
|
56
|
-
matchLength: fuzzyOldText.length,
|
|
57
|
-
usedFuzzyMatch: true,
|
|
58
|
-
contentForReplacement: fuzzyContent,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
export function stripBom(content) {
|
|
62
|
-
return content.startsWith("\uFEFF")
|
|
63
|
-
? { bom: "\uFEFF", text: content.slice(1) }
|
|
64
|
-
: { bom: "", text: content };
|
|
65
|
-
}
|
|
66
|
-
export function generateDiffString(oldContent, newContent, contextLines = 4) {
|
|
67
|
-
const parts = Diff.diffLines(oldContent, newContent);
|
|
68
|
-
const output = [];
|
|
69
|
-
const oldLines = oldContent.split("\n");
|
|
70
|
-
const newLines = newContent.split("\n");
|
|
71
|
-
const maxLineNum = Math.max(oldLines.length, newLines.length);
|
|
72
|
-
const lineNumWidth = String(maxLineNum).length;
|
|
73
|
-
let oldLineNum = 1;
|
|
74
|
-
let newLineNum = 1;
|
|
75
|
-
let lastWasChange = false;
|
|
76
|
-
let firstChangedLine;
|
|
77
|
-
for (let i = 0; i < parts.length; i++) {
|
|
78
|
-
const part = parts[i];
|
|
79
|
-
const raw = part.value.split("\n");
|
|
80
|
-
if (raw[raw.length - 1] === "") {
|
|
81
|
-
raw.pop();
|
|
82
|
-
}
|
|
83
|
-
if (part.added || part.removed) {
|
|
84
|
-
firstChangedLine ??= newLineNum;
|
|
85
|
-
for (const line of raw) {
|
|
86
|
-
if (part.added) {
|
|
87
|
-
output.push(`+${String(newLineNum).padStart(lineNumWidth, " ")} ${line}`);
|
|
88
|
-
newLineNum++;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
output.push(`-${String(oldLineNum).padStart(lineNumWidth, " ")} ${line}`);
|
|
92
|
-
oldLineNum++;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
lastWasChange = true;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
const nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);
|
|
99
|
-
if (lastWasChange || nextPartIsChange) {
|
|
100
|
-
let linesToShow = raw;
|
|
101
|
-
let skipStart = 0;
|
|
102
|
-
let skipEnd = 0;
|
|
103
|
-
if (!lastWasChange) {
|
|
104
|
-
skipStart = Math.max(0, raw.length - contextLines);
|
|
105
|
-
linesToShow = raw.slice(skipStart);
|
|
106
|
-
}
|
|
107
|
-
if (!nextPartIsChange && linesToShow.length > contextLines) {
|
|
108
|
-
skipEnd = linesToShow.length - contextLines;
|
|
109
|
-
linesToShow = linesToShow.slice(0, contextLines);
|
|
110
|
-
}
|
|
111
|
-
if (skipStart > 0) {
|
|
112
|
-
output.push(` ${"".padStart(lineNumWidth, " ")} ...`);
|
|
113
|
-
oldLineNum += skipStart;
|
|
114
|
-
newLineNum += skipStart;
|
|
115
|
-
}
|
|
116
|
-
for (const line of linesToShow) {
|
|
117
|
-
output.push(` ${String(oldLineNum).padStart(lineNumWidth, " ")} ${line}`);
|
|
118
|
-
oldLineNum++;
|
|
119
|
-
newLineNum++;
|
|
120
|
-
}
|
|
121
|
-
if (skipEnd > 0) {
|
|
122
|
-
output.push(` ${"".padStart(lineNumWidth, " ")} ...`);
|
|
123
|
-
oldLineNum += skipEnd;
|
|
124
|
-
newLineNum += skipEnd;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
oldLineNum += raw.length;
|
|
129
|
-
newLineNum += raw.length;
|
|
130
|
-
}
|
|
131
|
-
lastWasChange = false;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return { diff: output.join("\n"), firstChangedLine };
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=edit-diff.js.map
|