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/todo.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { Type } from "@sinclair/typebox";
|
|
2
|
-
import { getDatabase } from "../database/database.js";
|
|
3
|
-
import { fetchAllTodos, addTodos } from "../features/todos/todos.database.js";
|
|
4
|
-
const todoSchema = Type.Object({
|
|
5
|
-
action: Type.Union([Type.Literal("add"), Type.Literal("update"), Type.Literal("list"), Type.Literal("delete")], {
|
|
6
|
-
description: "Operation to perform: 'add' creates new items, 'update' changes status, 'list' returns all items, 'delete' removes items.",
|
|
7
|
-
}),
|
|
8
|
-
descriptions: Type.Optional(Type.Array(Type.String(), {
|
|
9
|
-
description: "Todo item descriptions. Required for 'add'. Provide one or more descriptions to create multiple items at once.",
|
|
10
|
-
})),
|
|
11
|
-
ids: Type.Optional(Type.Array(Type.String(), {
|
|
12
|
-
description: "Todo item IDs. Required for 'update' and 'delete'. Provide one or more IDs to update or delete multiple items at once.",
|
|
13
|
-
})),
|
|
14
|
-
status: Type.Optional(Type.Union([Type.Literal("pending"), Type.Literal("working"), Type.Literal("done")], {
|
|
15
|
-
description: "New status for 'update'. Applied to all specified IDs. 'pending' = not started, 'working' = in progress, 'done' = complete.",
|
|
16
|
-
})),
|
|
17
|
-
assignedTo: Type.Optional(Type.String({
|
|
18
|
-
description: "Who items are assigned to. Defaults to 'agent'. Applied to all specified items.",
|
|
19
|
-
})),
|
|
20
|
-
});
|
|
21
|
-
export function createTodoTool(threadId) {
|
|
22
|
-
return {
|
|
23
|
-
name: "todo",
|
|
24
|
-
label: "todo",
|
|
25
|
-
description: "Manage todo items to break down the current task into 2 more items. Use 'add' to create items when planning work, 'update' to change an item's status as you progress (pending → working → done), 'list' to see all current items, and 'delete' to remove one. Marking an item done does not end the conversation — continue working on remaining items. Call 'list' at the end so the user sees a completion checklist.",
|
|
26
|
-
parameters: todoSchema,
|
|
27
|
-
execute: async (_toolCallId, { action, descriptions, ids, status, assignedTo }) => {
|
|
28
|
-
const db = await getDatabase();
|
|
29
|
-
const now = new Date().toISOString();
|
|
30
|
-
switch (action) {
|
|
31
|
-
case "add": {
|
|
32
|
-
const validDescriptions = descriptions?.filter((d) => d.trim());
|
|
33
|
-
if (!validDescriptions?.length) {
|
|
34
|
-
return {
|
|
35
|
-
content: [
|
|
36
|
-
{ type: "text", text: "Error: descriptions is required for 'add'" },
|
|
37
|
-
],
|
|
38
|
-
details: undefined,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const todosAfterAdd = await addTodos(threadId, validDescriptions, assignedTo ?? "agent");
|
|
42
|
-
return {
|
|
43
|
-
content: [
|
|
44
|
-
{
|
|
45
|
-
type: "text",
|
|
46
|
-
text: JSON.stringify({ todos: todosAfterAdd }),
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
details: undefined,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
case "update": {
|
|
53
|
-
if (!ids?.length) {
|
|
54
|
-
return {
|
|
55
|
-
content: [{ type: "text", text: "Error: ids is required for 'update'" }],
|
|
56
|
-
details: undefined,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const notFound = [];
|
|
60
|
-
for (const id of ids) {
|
|
61
|
-
const existing = await db.execute({
|
|
62
|
-
sql: `SELECT id FROM todos WHERE id = ? AND threadId = ?`,
|
|
63
|
-
args: [id, threadId],
|
|
64
|
-
});
|
|
65
|
-
if (existing.rows.length === 0) {
|
|
66
|
-
notFound.push(id);
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
const updates = [];
|
|
70
|
-
const args = [];
|
|
71
|
-
if (status) {
|
|
72
|
-
updates.push("status = ?");
|
|
73
|
-
args.push(status);
|
|
74
|
-
}
|
|
75
|
-
if (assignedTo !== undefined) {
|
|
76
|
-
updates.push("assignedTo = ?");
|
|
77
|
-
args.push(assignedTo);
|
|
78
|
-
}
|
|
79
|
-
updates.push("updatedAt = ?");
|
|
80
|
-
args.push(now);
|
|
81
|
-
args.push(id, threadId);
|
|
82
|
-
await db.execute({
|
|
83
|
-
sql: `UPDATE todos SET ${updates.join(", ")} WHERE id = ? AND threadId = ?`,
|
|
84
|
-
args,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
if (notFound.length > 0) {
|
|
88
|
-
return {
|
|
89
|
-
content: [
|
|
90
|
-
{
|
|
91
|
-
type: "text",
|
|
92
|
-
text: `Error: todos not found: ${notFound.join(", ")}`,
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
details: undefined,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
const todosAfterUpdate = await fetchAllTodos(db, threadId);
|
|
99
|
-
// If all items are now done, delete them all
|
|
100
|
-
const allDone = todosAfterUpdate.length > 0 && todosAfterUpdate.every((t) => t.status === "done");
|
|
101
|
-
if (allDone) {
|
|
102
|
-
await db.execute({
|
|
103
|
-
sql: `DELETE FROM todos WHERE threadId = ?`,
|
|
104
|
-
args: [threadId],
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
content: [
|
|
109
|
-
{
|
|
110
|
-
type: "text",
|
|
111
|
-
text: JSON.stringify({ todos: allDone ? [] : todosAfterUpdate }),
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
details: undefined,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
case "list": {
|
|
118
|
-
const todos = await fetchAllTodos(db, threadId);
|
|
119
|
-
return {
|
|
120
|
-
content: [
|
|
121
|
-
{
|
|
122
|
-
type: "text",
|
|
123
|
-
text: JSON.stringify({ todos }),
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
details: undefined,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
case "delete": {
|
|
130
|
-
if (!ids?.length) {
|
|
131
|
-
return {
|
|
132
|
-
content: [{ type: "text", text: "Error: ids is required for 'delete'" }],
|
|
133
|
-
details: undefined,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
for (const id of ids) {
|
|
137
|
-
await db.execute({
|
|
138
|
-
sql: `DELETE FROM todos WHERE id = ? AND threadId = ?`,
|
|
139
|
-
args: [id, threadId],
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
const todosAfterDelete = await fetchAllTodos(db, threadId);
|
|
143
|
-
return {
|
|
144
|
-
content: [
|
|
145
|
-
{
|
|
146
|
-
type: "text",
|
|
147
|
-
text: JSON.stringify({ todos: todosAfterDelete }),
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
details: undefined,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
default:
|
|
154
|
-
return {
|
|
155
|
-
content: [
|
|
156
|
-
{
|
|
157
|
-
type: "text",
|
|
158
|
-
text: `Unknown action: ${String(action)}`,
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
details: undefined,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
export const todoTool = createTodoTool("");
|
|
168
|
-
//# sourceMappingURL=todo.js.map
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool helper utilities for reducing duplication in tool implementations
|
|
3
|
-
*
|
|
4
|
-
* Provides:
|
|
5
|
-
* - Abort signal handling wrapper to eliminate boilerplate in tool execute functions
|
|
6
|
-
* - Tool result formatting utilities for consistent output across tools
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Wraps an async operation with abort signal handling
|
|
10
|
-
*
|
|
11
|
-
* Eliminates the need for each tool to implement the same abort signal
|
|
12
|
-
* setup, cleanup, and error handling logic.
|
|
13
|
-
*
|
|
14
|
-
* @param signal - Optional abort signal from the tool execution
|
|
15
|
-
* @param operation - The async operation to perform, receives an abort check function
|
|
16
|
-
* @returns Promise that resolves with the operation result or rejects if aborted
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* execute: async (_toolCallId, { path, content }, signal) => {
|
|
21
|
-
* return withAbortSignal(signal, async (isAborted) => {
|
|
22
|
-
* await ops.mkdir(dir);
|
|
23
|
-
* if (isAborted()) return { content: [], details: undefined };
|
|
24
|
-
* await ops.writeFile(absolutePath, content);
|
|
25
|
-
* return {
|
|
26
|
-
* content: [{ type: "text", text: `Successfully wrote ${content.length} bytes to ${path}` }],
|
|
27
|
-
* details: undefined,
|
|
28
|
-
* };
|
|
29
|
-
* });
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare function withAbortSignal<T>(signal: AbortSignal | undefined, operation: (abortCheck: () => boolean) => Promise<T>): Promise<T>;
|
|
34
|
-
/**
|
|
35
|
-
* Represents a notice message to be appended to tool output
|
|
36
|
-
*/
|
|
37
|
-
export interface ToolNotice {
|
|
38
|
-
/** Human-readable notice message */
|
|
39
|
-
message: string;
|
|
40
|
-
/** Key for the details object */
|
|
41
|
-
detailKey: string;
|
|
42
|
-
/** Value to include in details */
|
|
43
|
-
detailValue: unknown;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Formats tool output with optional notices appended
|
|
47
|
-
*
|
|
48
|
-
* Creates a consistent format for tool results that include notices
|
|
49
|
-
* (e.g., truncation warnings, result limits reached) and details metadata.
|
|
50
|
-
*
|
|
51
|
-
* @param baseOutput - The primary tool output text
|
|
52
|
-
* @param notices - Array of notices to append to the output
|
|
53
|
-
* @returns Object containing formatted output and optional details
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* const notices: ToolNotice[] = [];
|
|
58
|
-
*
|
|
59
|
-
* if (resultLimitReached) {
|
|
60
|
-
* notices.push({
|
|
61
|
-
* message: `${effectiveLimit} results limit reached. Use limit=${effectiveLimit * 2} for more`,
|
|
62
|
-
* detailKey: 'resultLimitReached',
|
|
63
|
-
* detailValue: effectiveLimit,
|
|
64
|
-
* });
|
|
65
|
-
* }
|
|
66
|
-
*
|
|
67
|
-
* const { output, details } = formatToolOutput(truncation.content, notices);
|
|
68
|
-
* return {
|
|
69
|
-
* content: [{ type: "text", text: output }],
|
|
70
|
-
* details,
|
|
71
|
-
* };
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
export declare function formatToolOutput(baseOutput: string, notices: ToolNotice[]): {
|
|
75
|
-
output: string;
|
|
76
|
-
details: Record<string, unknown> | undefined;
|
|
77
|
-
};
|
|
78
|
-
//# sourceMappingURL=tool-helpers.d.ts.map
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool helper utilities for reducing duplication in tool implementations
|
|
3
|
-
*
|
|
4
|
-
* Provides:
|
|
5
|
-
* - Abort signal handling wrapper to eliminate boilerplate in tool execute functions
|
|
6
|
-
* - Tool result formatting utilities for consistent output across tools
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Wraps an async operation with abort signal handling
|
|
10
|
-
*
|
|
11
|
-
* Eliminates the need for each tool to implement the same abort signal
|
|
12
|
-
* setup, cleanup, and error handling logic.
|
|
13
|
-
*
|
|
14
|
-
* @param signal - Optional abort signal from the tool execution
|
|
15
|
-
* @param operation - The async operation to perform, receives an abort check function
|
|
16
|
-
* @returns Promise that resolves with the operation result or rejects if aborted
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* execute: async (_toolCallId, { path, content }, signal) => {
|
|
21
|
-
* return withAbortSignal(signal, async (isAborted) => {
|
|
22
|
-
* await ops.mkdir(dir);
|
|
23
|
-
* if (isAborted()) return { content: [], details: undefined };
|
|
24
|
-
* await ops.writeFile(absolutePath, content);
|
|
25
|
-
* return {
|
|
26
|
-
* content: [{ type: "text", text: `Successfully wrote ${content.length} bytes to ${path}` }],
|
|
27
|
-
* details: undefined,
|
|
28
|
-
* };
|
|
29
|
-
* });
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export async function withAbortSignal(signal, operation) {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
if (signal?.aborted) {
|
|
36
|
-
reject(new Error("Operation aborted"));
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
let aborted = false;
|
|
40
|
-
const onAbort = () => {
|
|
41
|
-
aborted = true;
|
|
42
|
-
reject(new Error("Operation aborted"));
|
|
43
|
-
};
|
|
44
|
-
if (signal) {
|
|
45
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
46
|
-
}
|
|
47
|
-
const cleanup = () => {
|
|
48
|
-
if (signal)
|
|
49
|
-
signal.removeEventListener("abort", onAbort);
|
|
50
|
-
};
|
|
51
|
-
const abortCheck = () => aborted;
|
|
52
|
-
operation(abortCheck)
|
|
53
|
-
.then((result) => {
|
|
54
|
-
cleanup();
|
|
55
|
-
if (!aborted)
|
|
56
|
-
resolve(result);
|
|
57
|
-
})
|
|
58
|
-
.catch((error) => {
|
|
59
|
-
cleanup();
|
|
60
|
-
if (!aborted)
|
|
61
|
-
reject(error);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Formats tool output with optional notices appended
|
|
67
|
-
*
|
|
68
|
-
* Creates a consistent format for tool results that include notices
|
|
69
|
-
* (e.g., truncation warnings, result limits reached) and details metadata.
|
|
70
|
-
*
|
|
71
|
-
* @param baseOutput - The primary tool output text
|
|
72
|
-
* @param notices - Array of notices to append to the output
|
|
73
|
-
* @returns Object containing formatted output and optional details
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```typescript
|
|
77
|
-
* const notices: ToolNotice[] = [];
|
|
78
|
-
*
|
|
79
|
-
* if (resultLimitReached) {
|
|
80
|
-
* notices.push({
|
|
81
|
-
* message: `${effectiveLimit} results limit reached. Use limit=${effectiveLimit * 2} for more`,
|
|
82
|
-
* detailKey: 'resultLimitReached',
|
|
83
|
-
* detailValue: effectiveLimit,
|
|
84
|
-
* });
|
|
85
|
-
* }
|
|
86
|
-
*
|
|
87
|
-
* const { output, details } = formatToolOutput(truncation.content, notices);
|
|
88
|
-
* return {
|
|
89
|
-
* content: [{ type: "text", text: output }],
|
|
90
|
-
* details,
|
|
91
|
-
* };
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
export function formatToolOutput(baseOutput, notices) {
|
|
95
|
-
let output = baseOutput;
|
|
96
|
-
const details = {};
|
|
97
|
-
if (notices.length > 0) {
|
|
98
|
-
const messages = notices.map((n) => n.message);
|
|
99
|
-
output += `\n\n[${messages.join(". ")}]`;
|
|
100
|
-
for (const notice of notices) {
|
|
101
|
-
details[notice.detailKey] = notice.detailValue;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
output,
|
|
106
|
-
details: Object.keys(details).length > 0 ? details : undefined,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
//# sourceMappingURL=tool-helpers.js.map
|
package/dist/tools/truncate.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared truncation utilities for tool outputs.
|
|
3
|
-
*/
|
|
4
|
-
export declare const DEFAULT_MAX_LINES = 2000;
|
|
5
|
-
export declare const DEFAULT_MAX_BYTES: number;
|
|
6
|
-
export declare const GREP_MAX_LINE_LENGTH = 500;
|
|
7
|
-
export interface TruncationResult {
|
|
8
|
-
content: string;
|
|
9
|
-
truncated: boolean;
|
|
10
|
-
truncatedBy: "lines" | "bytes" | null;
|
|
11
|
-
totalLines: number;
|
|
12
|
-
totalBytes: number;
|
|
13
|
-
outputLines: number;
|
|
14
|
-
outputBytes: number;
|
|
15
|
-
lastLinePartial: boolean;
|
|
16
|
-
firstLineExceedsLimit: boolean;
|
|
17
|
-
maxLines: number;
|
|
18
|
-
maxBytes: number;
|
|
19
|
-
}
|
|
20
|
-
export interface TruncationOptions {
|
|
21
|
-
maxLines?: number;
|
|
22
|
-
maxBytes?: number;
|
|
23
|
-
}
|
|
24
|
-
export declare function formatSize(bytes: number): string;
|
|
25
|
-
export declare function truncateHead(content: string, options?: TruncationOptions): TruncationResult;
|
|
26
|
-
export declare function truncateTail(content: string, options?: TruncationOptions): TruncationResult;
|
|
27
|
-
export declare function truncateLine(line: string, maxChars?: number): {
|
|
28
|
-
text: string;
|
|
29
|
-
wasTruncated: boolean;
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=truncate.d.ts.map
|
package/dist/tools/truncate.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared truncation utilities for tool outputs.
|
|
3
|
-
*/
|
|
4
|
-
export const DEFAULT_MAX_LINES = 2000;
|
|
5
|
-
export const DEFAULT_MAX_BYTES = 50 * 1024; // 50KB
|
|
6
|
-
export const GREP_MAX_LINE_LENGTH = 500;
|
|
7
|
-
export function formatSize(bytes) {
|
|
8
|
-
if (bytes < 1024) {
|
|
9
|
-
return `${bytes}B`;
|
|
10
|
-
}
|
|
11
|
-
else if (bytes < 1024 * 1024) {
|
|
12
|
-
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export function truncateHead(content, options = {}) {
|
|
19
|
-
const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
20
|
-
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
21
|
-
const totalBytes = Buffer.byteLength(content, "utf-8");
|
|
22
|
-
const lines = content.split("\n");
|
|
23
|
-
const totalLines = lines.length;
|
|
24
|
-
if (totalLines <= maxLines && totalBytes <= maxBytes) {
|
|
25
|
-
return {
|
|
26
|
-
content,
|
|
27
|
-
truncated: false,
|
|
28
|
-
truncatedBy: null,
|
|
29
|
-
totalLines,
|
|
30
|
-
totalBytes,
|
|
31
|
-
outputLines: totalLines,
|
|
32
|
-
outputBytes: totalBytes,
|
|
33
|
-
lastLinePartial: false,
|
|
34
|
-
firstLineExceedsLimit: false,
|
|
35
|
-
maxLines,
|
|
36
|
-
maxBytes,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const firstLineBytes = Buffer.byteLength(lines[0], "utf-8");
|
|
40
|
-
if (firstLineBytes > maxBytes) {
|
|
41
|
-
return {
|
|
42
|
-
content: "",
|
|
43
|
-
truncated: true,
|
|
44
|
-
truncatedBy: "bytes",
|
|
45
|
-
totalLines,
|
|
46
|
-
totalBytes,
|
|
47
|
-
outputLines: 0,
|
|
48
|
-
outputBytes: 0,
|
|
49
|
-
lastLinePartial: false,
|
|
50
|
-
firstLineExceedsLimit: true,
|
|
51
|
-
maxLines,
|
|
52
|
-
maxBytes,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
const outputLinesArr = [];
|
|
56
|
-
let outputBytesCount = 0;
|
|
57
|
-
let truncatedBy = "lines";
|
|
58
|
-
for (let i = 0; i < lines.length && i < maxLines; i++) {
|
|
59
|
-
const line = lines[i];
|
|
60
|
-
const lineBytes = Buffer.byteLength(line, "utf-8") + (i > 0 ? 1 : 0);
|
|
61
|
-
if (outputBytesCount + lineBytes > maxBytes) {
|
|
62
|
-
truncatedBy = "bytes";
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
outputLinesArr.push(line);
|
|
66
|
-
outputBytesCount += lineBytes;
|
|
67
|
-
}
|
|
68
|
-
if (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {
|
|
69
|
-
truncatedBy = "lines";
|
|
70
|
-
}
|
|
71
|
-
const outputContent = outputLinesArr.join("\n");
|
|
72
|
-
const finalOutputBytes = Buffer.byteLength(outputContent, "utf-8");
|
|
73
|
-
return {
|
|
74
|
-
content: outputContent,
|
|
75
|
-
truncated: true,
|
|
76
|
-
truncatedBy,
|
|
77
|
-
totalLines,
|
|
78
|
-
totalBytes,
|
|
79
|
-
outputLines: outputLinesArr.length,
|
|
80
|
-
outputBytes: finalOutputBytes,
|
|
81
|
-
lastLinePartial: false,
|
|
82
|
-
firstLineExceedsLimit: false,
|
|
83
|
-
maxLines,
|
|
84
|
-
maxBytes,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
export function truncateTail(content, options = {}) {
|
|
88
|
-
const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
89
|
-
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
90
|
-
const totalBytes = Buffer.byteLength(content, "utf-8");
|
|
91
|
-
const lines = content.split("\n");
|
|
92
|
-
const totalLines = lines.length;
|
|
93
|
-
if (totalLines <= maxLines && totalBytes <= maxBytes) {
|
|
94
|
-
return {
|
|
95
|
-
content,
|
|
96
|
-
truncated: false,
|
|
97
|
-
truncatedBy: null,
|
|
98
|
-
totalLines,
|
|
99
|
-
totalBytes,
|
|
100
|
-
outputLines: totalLines,
|
|
101
|
-
outputBytes: totalBytes,
|
|
102
|
-
lastLinePartial: false,
|
|
103
|
-
firstLineExceedsLimit: false,
|
|
104
|
-
maxLines,
|
|
105
|
-
maxBytes,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
const outputLinesArr = [];
|
|
109
|
-
let outputBytesCount = 0;
|
|
110
|
-
let truncatedBy = "lines";
|
|
111
|
-
let lastLinePartial = false;
|
|
112
|
-
for (let i = lines.length - 1; i >= 0 && outputLinesArr.length < maxLines; i--) {
|
|
113
|
-
const line = lines[i];
|
|
114
|
-
const lineBytes = Buffer.byteLength(line, "utf-8") + (outputLinesArr.length > 0 ? 1 : 0);
|
|
115
|
-
if (outputBytesCount + lineBytes > maxBytes) {
|
|
116
|
-
truncatedBy = "bytes";
|
|
117
|
-
if (outputLinesArr.length === 0) {
|
|
118
|
-
const truncatedLine = truncateStringToBytesFromEnd(line, maxBytes);
|
|
119
|
-
outputLinesArr.unshift(truncatedLine);
|
|
120
|
-
outputBytesCount = Buffer.byteLength(truncatedLine, "utf-8");
|
|
121
|
-
lastLinePartial = true;
|
|
122
|
-
}
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
outputLinesArr.unshift(line);
|
|
126
|
-
outputBytesCount += lineBytes;
|
|
127
|
-
}
|
|
128
|
-
if (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {
|
|
129
|
-
truncatedBy = "lines";
|
|
130
|
-
}
|
|
131
|
-
const outputContent = outputLinesArr.join("\n");
|
|
132
|
-
const finalOutputBytes = Buffer.byteLength(outputContent, "utf-8");
|
|
133
|
-
return {
|
|
134
|
-
content: outputContent,
|
|
135
|
-
truncated: true,
|
|
136
|
-
truncatedBy,
|
|
137
|
-
totalLines,
|
|
138
|
-
totalBytes,
|
|
139
|
-
outputLines: outputLinesArr.length,
|
|
140
|
-
outputBytes: finalOutputBytes,
|
|
141
|
-
lastLinePartial,
|
|
142
|
-
firstLineExceedsLimit: false,
|
|
143
|
-
maxLines,
|
|
144
|
-
maxBytes,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
function truncateStringToBytesFromEnd(str, maxBytes) {
|
|
148
|
-
const buf = Buffer.from(str, "utf-8");
|
|
149
|
-
if (buf.length <= maxBytes) {
|
|
150
|
-
return str;
|
|
151
|
-
}
|
|
152
|
-
let start = buf.length - maxBytes;
|
|
153
|
-
while (start < buf.length && (buf[start] & 0xc0) === 0x80) {
|
|
154
|
-
start++;
|
|
155
|
-
}
|
|
156
|
-
return buf.slice(start).toString("utf-8");
|
|
157
|
-
}
|
|
158
|
-
export function truncateLine(line, maxChars = GREP_MAX_LINE_LENGTH) {
|
|
159
|
-
if (line.length <= maxChars) {
|
|
160
|
-
return { text: line, wasTruncated: false };
|
|
161
|
-
}
|
|
162
|
-
return { text: `${line.slice(0, maxChars)}... [truncated]`, wasTruncated: true };
|
|
163
|
-
}
|
|
164
|
-
//# sourceMappingURL=truncate.js.map
|
package/dist/tools/write.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
-
import { type Static } from "@sinclair/typebox";
|
|
3
|
-
declare const writeSchema: import("@sinclair/typebox").TObject<{
|
|
4
|
-
path: import("@sinclair/typebox").TString;
|
|
5
|
-
content: import("@sinclair/typebox").TString;
|
|
6
|
-
}>;
|
|
7
|
-
export type WriteToolInput = Static<typeof writeSchema>;
|
|
8
|
-
export interface WriteOperations {
|
|
9
|
-
writeFile: (absolutePath: string, content: string) => Promise<void>;
|
|
10
|
-
mkdir: (dir: string) => Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export interface WriteToolOptions {
|
|
13
|
-
operations?: WriteOperations;
|
|
14
|
-
}
|
|
15
|
-
export declare function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema>;
|
|
16
|
-
export declare const writeTool: AgentTool<import("@sinclair/typebox").TObject<{
|
|
17
|
-
path: import("@sinclair/typebox").TString;
|
|
18
|
-
content: import("@sinclair/typebox").TString;
|
|
19
|
-
}>, any>;
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=write.d.ts.map
|
package/dist/tools/write.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Type } from "@sinclair/typebox";
|
|
2
|
-
import { mkdir as fsMkdir, writeFile as fsWriteFile } from "fs/promises";
|
|
3
|
-
import { dirname } from "path";
|
|
4
|
-
import { resolveToCwd, validatePathWithinCwd } from "./path-utils.js";
|
|
5
|
-
const writeSchema = Type.Object({
|
|
6
|
-
path: Type.String({ description: "Path to the file to write (relative or absolute)" }),
|
|
7
|
-
content: Type.String({ description: "Content to write to the file" }),
|
|
8
|
-
});
|
|
9
|
-
const defaultWriteOperations = {
|
|
10
|
-
writeFile: (path, content) => fsWriteFile(path, content, "utf-8"),
|
|
11
|
-
mkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => { }),
|
|
12
|
-
};
|
|
13
|
-
export function createWriteTool(cwd, options) {
|
|
14
|
-
const ops = options?.operations ?? defaultWriteOperations;
|
|
15
|
-
return {
|
|
16
|
-
name: "write",
|
|
17
|
-
label: "write",
|
|
18
|
-
description: "Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.",
|
|
19
|
-
parameters: writeSchema,
|
|
20
|
-
execute: async (_toolCallId, { path, content }, signal) => {
|
|
21
|
-
const absolutePath = resolveToCwd(path, cwd);
|
|
22
|
-
validatePathWithinCwd(absolutePath, cwd);
|
|
23
|
-
const dir = dirname(absolutePath);
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
if (signal?.aborted) {
|
|
26
|
-
reject(new Error("Operation aborted"));
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
let aborted = false;
|
|
30
|
-
const onAbort = () => {
|
|
31
|
-
aborted = true;
|
|
32
|
-
reject(new Error("Operation aborted"));
|
|
33
|
-
};
|
|
34
|
-
if (signal)
|
|
35
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
36
|
-
void (async () => {
|
|
37
|
-
try {
|
|
38
|
-
await ops.mkdir(dir);
|
|
39
|
-
if (aborted)
|
|
40
|
-
return;
|
|
41
|
-
await ops.writeFile(absolutePath, content);
|
|
42
|
-
if (aborted)
|
|
43
|
-
return;
|
|
44
|
-
if (signal)
|
|
45
|
-
signal.removeEventListener("abort", onAbort);
|
|
46
|
-
resolve({
|
|
47
|
-
content: [
|
|
48
|
-
{ type: "text", text: `Successfully wrote ${content.length} bytes to ${path}` },
|
|
49
|
-
],
|
|
50
|
-
details: undefined,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
if (signal)
|
|
55
|
-
signal.removeEventListener("abort", onAbort);
|
|
56
|
-
if (!aborted)
|
|
57
|
-
reject(error);
|
|
58
|
-
}
|
|
59
|
-
})();
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
export const writeTool = createWriteTool(process.cwd());
|
|
65
|
-
//# sourceMappingURL=write.js.map
|