@kvman/kvcoder 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/api.d.ts +386 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +2 -0
- package/dist/api.js.map +1 -0
- package/dist/artifacts/artifact-format.d.ts +9 -0
- package/dist/artifacts/artifact-format.d.ts.map +1 -0
- package/dist/artifacts/artifact-format.js +32 -0
- package/dist/artifacts/artifact-format.js.map +1 -0
- package/dist/artifacts/artifact-records.d.ts +12 -0
- package/dist/artifacts/artifact-records.d.ts.map +1 -0
- package/dist/artifacts/artifact-records.js +17 -0
- package/dist/artifacts/artifact-records.js.map +1 -0
- package/dist/artifacts/register-artifacts.d.ts +3 -0
- package/dist/artifacts/register-artifacts.d.ts.map +1 -0
- package/dist/artifacts/register-artifacts.js +37 -0
- package/dist/artifacts/register-artifacts.js.map +1 -0
- package/dist/calls/binary-checks.d.ts +8 -0
- package/dist/calls/binary-checks.d.ts.map +1 -0
- package/dist/calls/binary-checks.js +12 -0
- package/dist/calls/binary-checks.js.map +1 -0
- package/dist/calls/connector-help.d.ts +3 -0
- package/dist/calls/connector-help.d.ts.map +1 -0
- package/dist/calls/connector-help.js +73 -0
- package/dist/calls/connector-help.js.map +1 -0
- package/dist/calls/help-text.d.ts +19 -0
- package/dist/calls/help-text.d.ts.map +1 -0
- package/dist/calls/help-text.js +22 -0
- package/dist/calls/help-text.js.map +1 -0
- package/dist/calls/line-run.d.ts +33 -0
- package/dist/calls/line-run.d.ts.map +1 -0
- package/dist/calls/line-run.js +56 -0
- package/dist/calls/line-run.js.map +1 -0
- package/dist/calls/run-shell.d.ts +12 -0
- package/dist/calls/run-shell.d.ts.map +1 -0
- package/dist/calls/run-shell.js +88 -0
- package/dist/calls/run-shell.js.map +1 -0
- package/dist/calls/run-tool.d.ts +49 -0
- package/dist/calls/run-tool.d.ts.map +1 -0
- package/dist/calls/run-tool.js +66 -0
- package/dist/calls/run-tool.js.map +1 -0
- package/dist/calls/shell-command.d.ts +25 -0
- package/dist/calls/shell-command.d.ts.map +1 -0
- package/dist/calls/shell-command.js +31 -0
- package/dist/calls/shell-command.js.map +1 -0
- package/dist/calls/shell-program.d.ts +5 -0
- package/dist/calls/shell-program.d.ts.map +1 -0
- package/dist/calls/shell-program.js +8 -0
- package/dist/calls/shell-program.js.map +1 -0
- package/dist/connector-call.d.ts +66 -0
- package/dist/connector-call.d.ts.map +1 -0
- package/dist/connector-call.js +133 -0
- package/dist/connector-call.js.map +1 -0
- package/dist/connectors/artifact.d.ts +51 -0
- package/dist/connectors/artifact.d.ts.map +1 -0
- package/dist/connectors/artifact.js +101 -0
- package/dist/connectors/artifact.js.map +1 -0
- package/dist/connectors/ask.d.ts +58 -0
- package/dist/connectors/ask.d.ts.map +1 -0
- package/dist/connectors/ask.js +85 -0
- package/dist/connectors/ask.js.map +1 -0
- package/dist/connectors/background.d.ts +29 -0
- package/dist/connectors/background.d.ts.map +1 -0
- package/dist/connectors/background.js +56 -0
- package/dist/connectors/background.js.map +1 -0
- package/dist/connectors/binary.d.ts +5 -0
- package/dist/connectors/binary.d.ts.map +1 -0
- package/dist/connectors/binary.js +27 -0
- package/dist/connectors/binary.js.map +1 -0
- package/dist/connectors/builtin-connectors.d.ts +217 -0
- package/dist/connectors/builtin-connectors.d.ts.map +1 -0
- package/dist/connectors/builtin-connectors.js +49 -0
- package/dist/connectors/builtin-connectors.js.map +1 -0
- package/dist/connectors/connector-command.d.ts +26 -0
- package/dist/connectors/connector-command.d.ts.map +1 -0
- package/dist/connectors/connector-command.js +17 -0
- package/dist/connectors/connector-command.js.map +1 -0
- package/dist/connectors/delegate.d.ts +32 -0
- package/dist/connectors/delegate.d.ts.map +1 -0
- package/dist/connectors/delegate.js +82 -0
- package/dist/connectors/delegate.js.map +1 -0
- package/dist/connectors/fs.d.ts +60 -0
- package/dist/connectors/fs.d.ts.map +1 -0
- package/dist/connectors/fs.js +132 -0
- package/dist/connectors/fs.js.map +1 -0
- package/dist/connectors/mcp.d.ts +37 -0
- package/dist/connectors/mcp.d.ts.map +1 -0
- package/dist/connectors/mcp.js +69 -0
- package/dist/connectors/mcp.js.map +1 -0
- package/dist/connectors/payload-fields.d.ts +9 -0
- package/dist/connectors/payload-fields.d.ts.map +1 -0
- package/dist/connectors/payload-fields.js +13 -0
- package/dist/connectors/payload-fields.js.map +1 -0
- package/dist/connectors/shell.d.ts +19 -0
- package/dist/connectors/shell.d.ts.map +1 -0
- package/dist/connectors/shell.js +22 -0
- package/dist/connectors/shell.js.map +1 -0
- package/dist/delay.d.ts +3 -0
- package/dist/delay.d.ts.map +1 -0
- package/dist/delay.js +11 -0
- package/dist/delay.js.map +1 -0
- package/dist/delegate/approved-run.d.ts +13 -0
- package/dist/delegate/approved-run.d.ts.map +1 -0
- package/dist/delegate/approved-run.js +54 -0
- package/dist/delegate/approved-run.js.map +1 -0
- package/dist/delegate/programs.d.ts +32 -0
- package/dist/delegate/programs.d.ts.map +1 -0
- package/dist/delegate/programs.js +67 -0
- package/dist/delegate/programs.js.map +1 -0
- package/dist/delegate/register-worker-run.d.ts +9 -0
- package/dist/delegate/register-worker-run.d.ts.map +1 -0
- package/dist/delegate/register-worker-run.js +70 -0
- package/dist/delegate/register-worker-run.js.map +1 -0
- package/dist/delegate/run-program.d.ts +9 -0
- package/dist/delegate/run-program.d.ts.map +1 -0
- package/dist/delegate/run-program.js +59 -0
- package/dist/delegate/run-program.js.map +1 -0
- package/dist/delegate/runs.d.ts +27 -0
- package/dist/delegate/runs.d.ts.map +1 -0
- package/dist/delegate/runs.js +68 -0
- package/dist/delegate/runs.js.map +1 -0
- package/dist/delegate/workers.d.ts +266 -0
- package/dist/delegate/workers.d.ts.map +1 -0
- package/dist/delegate/workers.js +80 -0
- package/dist/delegate/workers.js.map +1 -0
- package/dist/docs.d.ts +14 -0
- package/dist/docs.d.ts.map +1 -0
- package/dist/docs.js +59 -0
- package/dist/docs.js.map +1 -0
- package/dist/files/edit-text.d.ts +13 -0
- package/dist/files/edit-text.d.ts.map +1 -0
- package/dist/files/edit-text.js +46 -0
- package/dist/files/edit-text.js.map +1 -0
- package/dist/files/file-queue.d.ts +3 -0
- package/dist/files/file-queue.d.ts.map +1 -0
- package/dist/files/file-queue.js +17 -0
- package/dist/files/file-queue.js.map +1 -0
- package/dist/files/list-entries.d.ts +14 -0
- package/dist/files/list-entries.d.ts.map +1 -0
- package/dist/files/list-entries.js +40 -0
- package/dist/files/list-entries.js.map +1 -0
- package/dist/files/read-file.d.ts +17 -0
- package/dist/files/read-file.d.ts.map +1 -0
- package/dist/files/read-file.js +53 -0
- package/dist/files/read-file.js.map +1 -0
- package/dist/files/search-text.d.ts +14 -0
- package/dist/files/search-text.d.ts.map +1 -0
- package/dist/files/search-text.js +62 -0
- package/dist/files/search-text.js.map +1 -0
- package/dist/files/workspace-path.d.ts +5 -0
- package/dist/files/workspace-path.d.ts.map +1 -0
- package/dist/files/workspace-path.js +37 -0
- package/dist/files/workspace-path.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs/job-rows.d.ts +24 -0
- package/dist/jobs/job-rows.d.ts.map +1 -0
- package/dist/jobs/job-rows.js +74 -0
- package/dist/jobs/job-rows.js.map +1 -0
- package/dist/jobs/process-handlers.d.ts +8 -0
- package/dist/jobs/process-handlers.d.ts.map +1 -0
- package/dist/jobs/process-handlers.js +43 -0
- package/dist/jobs/process-handlers.js.map +1 -0
- package/dist/jobs/process-records.d.ts +15 -0
- package/dist/jobs/process-records.d.ts.map +1 -0
- package/dist/jobs/process-records.js +30 -0
- package/dist/jobs/process-records.js.map +1 -0
- package/dist/jobs/process-report.d.ts +8 -0
- package/dist/jobs/process-report.d.ts.map +1 -0
- package/dist/jobs/process-report.js +44 -0
- package/dist/jobs/process-report.js.map +1 -0
- package/dist/jobs/process-run.d.ts +26 -0
- package/dist/jobs/process-run.d.ts.map +1 -0
- package/dist/jobs/process-run.js +70 -0
- package/dist/jobs/process-run.js.map +1 -0
- package/dist/jobs/process-text.d.ts +5 -0
- package/dist/jobs/process-text.d.ts.map +1 -0
- package/dist/jobs/process-text.js +11 -0
- package/dist/jobs/process-text.js.map +1 -0
- package/dist/jobs/register-jobs.d.ts +3 -0
- package/dist/jobs/register-jobs.d.ts.map +1 -0
- package/dist/jobs/register-jobs.js +61 -0
- package/dist/jobs/register-jobs.js.map +1 -0
- package/dist/mcp/command-transport.d.ts +17 -0
- package/dist/mcp/command-transport.d.ts.map +1 -0
- package/dist/mcp/command-transport.js +60 -0
- package/dist/mcp/command-transport.js.map +1 -0
- package/dist/mcp/connect.d.ts +12 -0
- package/dist/mcp/connect.d.ts.map +1 -0
- package/dist/mcp/connect.js +54 -0
- package/dist/mcp/connect.js.map +1 -0
- package/dist/mcp/oauth-provider.d.ts +25 -0
- package/dist/mcp/oauth-provider.d.ts.map +1 -0
- package/dist/mcp/oauth-provider.js +59 -0
- package/dist/mcp/oauth-provider.js.map +1 -0
- package/dist/mcp/register-mcp.d.ts +3 -0
- package/dist/mcp/register-mcp.d.ts.map +1 -0
- package/dist/mcp/register-mcp.js +61 -0
- package/dist/mcp/register-mcp.js.map +1 -0
- package/dist/mcp/secrets.d.ts +7 -0
- package/dist/mcp/secrets.d.ts.map +1 -0
- package/dist/mcp/secrets.js +20 -0
- package/dist/mcp/secrets.js.map +1 -0
- package/dist/mcp/servers.d.ts +33 -0
- package/dist/mcp/servers.d.ts.map +1 -0
- package/dist/mcp/servers.js +31 -0
- package/dist/mcp/servers.js.map +1 -0
- package/dist/mcp/sign-in-record.d.ts +10 -0
- package/dist/mcp/sign-in-record.d.ts.map +1 -0
- package/dist/mcp/sign-in-record.js +4 -0
- package/dist/mcp/sign-in-record.js.map +1 -0
- package/dist/mcp/sign-in.d.ts +12 -0
- package/dist/mcp/sign-in.d.ts.map +1 -0
- package/dist/mcp/sign-in.js +75 -0
- package/dist/mcp/sign-in.js.map +1 -0
- package/dist/mcp/tools.d.ts +19 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +31 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/messages/attachments.d.ts +8 -0
- package/dist/messages/attachments.d.ts.map +1 -0
- package/dist/messages/attachments.js +48 -0
- package/dist/messages/attachments.js.map +1 -0
- package/dist/messages/receive-message.d.ts +15 -0
- package/dist/messages/receive-message.d.ts.map +1 -0
- package/dist/messages/receive-message.js +60 -0
- package/dist/messages/receive-message.js.map +1 -0
- package/dist/messages/register-messages.d.ts +3 -0
- package/dist/messages/register-messages.d.ts.map +1 -0
- package/dist/messages/register-messages.js +63 -0
- package/dist/messages/register-messages.js.map +1 -0
- package/dist/problems.d.ts +8 -0
- package/dist/problems.d.ts.map +1 -0
- package/dist/problems.js +14 -0
- package/dist/problems.js.map +1 -0
- package/dist/prompt/build-prompt.d.ts +29 -0
- package/dist/prompt/build-prompt.d.ts.map +1 -0
- package/dist/prompt/build-prompt.js +60 -0
- package/dist/prompt/build-prompt.js.map +1 -0
- package/dist/prompt/register-prompt.d.ts +3 -0
- package/dist/prompt/register-prompt.d.ts.map +1 -0
- package/dist/prompt/register-prompt.js +29 -0
- package/dist/prompt/register-prompt.js.map +1 -0
- package/dist/prompt/session-prompt.d.ts +24 -0
- package/dist/prompt/session-prompt.d.ts.map +1 -0
- package/dist/prompt/session-prompt.js +50 -0
- package/dist/prompt/session-prompt.js.map +1 -0
- package/dist/prompt/working-method.d.ts +7 -0
- package/dist/prompt/working-method.d.ts.map +1 -0
- package/dist/prompt/working-method.js +51 -0
- package/dist/prompt/working-method.js.map +1 -0
- package/dist/register-settings.d.ts +142 -0
- package/dist/register-settings.d.ts.map +1 -0
- package/dist/register-settings.js +51 -0
- package/dist/register-settings.js.map +1 -0
- package/dist/registry/loaded.d.ts +32 -0
- package/dist/registry/loaded.d.ts.map +1 -0
- package/dist/registry/loaded.js +41 -0
- package/dist/registry/loaded.js.map +1 -0
- package/dist/registry/register-connectors.d.ts +32 -0
- package/dist/registry/register-connectors.d.ts.map +1 -0
- package/dist/registry/register-connectors.js +126 -0
- package/dist/registry/register-connectors.js.map +1 -0
- package/dist/registry/register-sections.d.ts +18 -0
- package/dist/registry/register-sections.d.ts.map +1 -0
- package/dist/registry/register-sections.js +99 -0
- package/dist/registry/register-sections.js.map +1 -0
- package/dist/registry/session-points.d.ts +11 -0
- package/dist/registry/session-points.d.ts.map +1 -0
- package/dist/registry/session-points.js +89 -0
- package/dist/registry/session-points.js.map +1 -0
- package/dist/result-text.d.ts +11 -0
- package/dist/result-text.d.ts.map +1 -0
- package/dist/result-text.js +21 -0
- package/dist/result-text.js.map +1 -0
- package/dist/schemas/records.d.ts +357 -0
- package/dist/schemas/records.d.ts.map +1 -0
- package/dist/schemas/records.js +159 -0
- package/dist/schemas/records.js.map +1 -0
- package/dist/schemas/registry.d.ts +160 -0
- package/dist/schemas/registry.d.ts.map +1 -0
- package/dist/schemas/registry.js +37 -0
- package/dist/schemas/registry.js.map +1 -0
- package/dist/sessions/new-session.d.ts +6 -0
- package/dist/sessions/new-session.d.ts.map +1 -0
- package/dist/sessions/new-session.js +52 -0
- package/dist/sessions/new-session.js.map +1 -0
- package/dist/sessions/register-fork-export.d.ts +5 -0
- package/dist/sessions/register-fork-export.d.ts.map +1 -0
- package/dist/sessions/register-fork-export.js +62 -0
- package/dist/sessions/register-fork-export.js.map +1 -0
- package/dist/sessions/register-lifecycle.d.ts +3 -0
- package/dist/sessions/register-lifecycle.d.ts.map +1 -0
- package/dist/sessions/register-lifecycle.js +59 -0
- package/dist/sessions/register-lifecycle.js.map +1 -0
- package/dist/sessions/register-sessions.d.ts +3 -0
- package/dist/sessions/register-sessions.d.ts.map +1 -0
- package/dist/sessions/register-sessions.js +93 -0
- package/dist/sessions/register-sessions.js.map +1 -0
- package/dist/sessions/session-lookup.d.ts +10 -0
- package/dist/sessions/session-lookup.d.ts.map +1 -0
- package/dist/sessions/session-lookup.js +25 -0
- package/dist/sessions/session-lookup.js.map +1 -0
- package/dist/sessions/session-view.d.ts +118 -0
- package/dist/sessions/session-view.d.ts.map +1 -0
- package/dist/sessions/session-view.js +105 -0
- package/dist/sessions/session-view.js.map +1 -0
- package/dist/store/collections.d.ts +471 -0
- package/dist/store/collections.d.ts.map +1 -0
- package/dist/store/collections.js +46 -0
- package/dist/store/collections.js.map +1 -0
- package/dist/turns/background.d.ts +6 -0
- package/dist/turns/background.d.ts.map +1 -0
- package/dist/turns/background.js +27 -0
- package/dist/turns/background.js.map +1 -0
- package/dist/turns/cancel-turn.d.ts +3 -0
- package/dist/turns/cancel-turn.d.ts.map +1 -0
- package/dist/turns/cancel-turn.js +31 -0
- package/dist/turns/cancel-turn.js.map +1 -0
- package/dist/turns/compaction.d.ts +12 -0
- package/dist/turns/compaction.d.ts.map +1 -0
- package/dist/turns/compaction.js +55 -0
- package/dist/turns/compaction.js.map +1 -0
- package/dist/turns/end-turn.d.ts +15 -0
- package/dist/turns/end-turn.d.ts.map +1 -0
- package/dist/turns/end-turn.js +67 -0
- package/dist/turns/end-turn.js.map +1 -0
- package/dist/turns/history.d.ts +28 -0
- package/dist/turns/history.d.ts.map +1 -0
- package/dist/turns/history.js +47 -0
- package/dist/turns/history.js.map +1 -0
- package/dist/turns/lost-reply.d.ts +31 -0
- package/dist/turns/lost-reply.d.ts.map +1 -0
- package/dist/turns/lost-reply.js +43 -0
- package/dist/turns/lost-reply.js.map +1 -0
- package/dist/turns/message-blocks.d.ts +9 -0
- package/dist/turns/message-blocks.d.ts.map +1 -0
- package/dist/turns/message-blocks.js +25 -0
- package/dist/turns/message-blocks.js.map +1 -0
- package/dist/turns/model-context.d.ts +81 -0
- package/dist/turns/model-context.d.ts.map +1 -0
- package/dist/turns/model-context.js +46 -0
- package/dist/turns/model-context.js.map +1 -0
- package/dist/turns/model-info.d.ts +7 -0
- package/dist/turns/model-info.d.ts.map +1 -0
- package/dist/turns/model-info.js +10 -0
- package/dist/turns/model-info.js.map +1 -0
- package/dist/turns/model-retry.d.ts +3 -0
- package/dist/turns/model-retry.d.ts.map +1 -0
- package/dist/turns/model-retry.js +23 -0
- package/dist/turns/model-retry.js.map +1 -0
- package/dist/turns/register-interruptions.d.ts +3 -0
- package/dist/turns/register-interruptions.d.ts.map +1 -0
- package/dist/turns/register-interruptions.js +31 -0
- package/dist/turns/register-interruptions.js.map +1 -0
- package/dist/turns/register-turns.d.ts +3 -0
- package/dist/turns/register-turns.d.ts.map +1 -0
- package/dist/turns/register-turns.js +66 -0
- package/dist/turns/register-turns.js.map +1 -0
- package/dist/turns/resolve.d.ts +7 -0
- package/dist/turns/resolve.d.ts.map +1 -0
- package/dist/turns/resolve.js +29 -0
- package/dist/turns/resolve.js.map +1 -0
- package/dist/turns/run-calls.d.ts +34 -0
- package/dist/turns/run-calls.d.ts.map +1 -0
- package/dist/turns/run-calls.js +99 -0
- package/dist/turns/run-calls.js.map +1 -0
- package/dist/turns/run-command.d.ts +26 -0
- package/dist/turns/run-command.d.ts.map +1 -0
- package/dist/turns/run-command.js +118 -0
- package/dist/turns/run-command.js.map +1 -0
- package/dist/turns/settle-calls.d.ts +17 -0
- package/dist/turns/settle-calls.d.ts.map +1 -0
- package/dist/turns/settle-calls.js +98 -0
- package/dist/turns/settle-calls.js.map +1 -0
- package/dist/turns/start-turn.d.ts +87 -0
- package/dist/turns/start-turn.d.ts.map +1 -0
- package/dist/turns/start-turn.js +40 -0
- package/dist/turns/start-turn.js.map +1 -0
- package/dist/turns/step.d.ts +8 -0
- package/dist/turns/step.d.ts.map +1 -0
- package/dist/turns/step.js +168 -0
- package/dist/turns/step.js.map +1 -0
- package/dist/ui/register-ui.d.ts +3 -0
- package/dist/ui/register-ui.d.ts.map +1 -0
- package/dist/ui/register-ui.js +75 -0
- package/dist/ui/register-ui.js.map +1 -0
- package/dist/web/components/call.css +2 -0
- package/dist/web/components/call.js +386 -0
- package/dist/web/components/connectors.css +2 -0
- package/dist/web/components/connectors.js +2403 -0
- package/dist/web/components/conversation.css +2 -0
- package/dist/web/components/conversation.js +4319 -0
- package/dist/web/components/mcp-sign-in.css +2 -0
- package/dist/web/components/mcp-sign-in.js +265 -0
- package/dist/web/components/model.css +2 -0
- package/dist/web/components/model.js +545 -0
- package/dist/web/components/question.css +2 -0
- package/dist/web/components/question.js +321 -0
- package/dist/web/components/sessions.css +2 -0
- package/dist/web/components/sessions.js +264 -0
- package/docs/connectors.md +86 -0
- package/docs/sections.md +27 -0
- package/locales/ar.json +418 -0
- package/locales/en.json +418 -0
- package/package.json +70 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { z } from '@kvman/sdk';
|
|
4
|
+
import { applyEdits } from "../files/edit-text.js";
|
|
5
|
+
import { listEntries } from "../files/list-entries.js";
|
|
6
|
+
import { readLines } from "../files/read-file.js";
|
|
7
|
+
import { searchText } from "../files/search-text.js";
|
|
8
|
+
import { resolveInWorkspace } from "../files/workspace-path.js";
|
|
9
|
+
import { invalid, notFound } from "../problems.js";
|
|
10
|
+
import { callInput } from "./connector-command.js";
|
|
11
|
+
import { edits, risky } from "./payload-fields.js";
|
|
12
|
+
// The `fs` connector (plan 08 §8.5, ADR 0009, 157 to 160; ADR 0011, 8): `read`, `list`, and `search` look inside the
|
|
13
|
+
// workspace folder; `write` creates or replaces a file and `edit` replaces text in one, after the approval the shell's
|
|
14
|
+
// calls get. The step runs the changes to one file one after another.
|
|
15
|
+
/** What the prompt's index says the connector is for. */
|
|
16
|
+
export const fsDescription = 'Read, list, search, create, and change files in the workspace folder. Use it instead of cat, ls, grep, or shell redirection: read a file before you edit it, write for a new file or a full rewrite, one file per call, and edit for exact text replacements in an existing file.';
|
|
17
|
+
const filePath = (what) => z.string().min(1).describe(`${what}, relative to the workspace folder, or absolute inside it.`);
|
|
18
|
+
const payloads = {
|
|
19
|
+
read: z.strictObject({
|
|
20
|
+
path: filePath('The file to read'),
|
|
21
|
+
fromLine: z.number().int().min(1).describe('The first line to return, counting from 1. The default is 1.').exactOptional(),
|
|
22
|
+
lines: z.number().int().min(1).max(2000).describe('How many lines to return: 2000 by default, which is also the most.').exactOptional(),
|
|
23
|
+
}),
|
|
24
|
+
list: z.strictObject({ path: z.string().describe('The folder to list, relative to the workspace folder, or absolute inside it; the workspace folder when left out or empty.').exactOptional() }),
|
|
25
|
+
search: z.strictObject({
|
|
26
|
+
pattern: z.string().min(1).describe('A JavaScript regular expression, matched against each line, case-sensitive.'),
|
|
27
|
+
path: z.string().describe('The file or folder to search, relative to the workspace folder, or absolute inside it; the workspace folder when left out or empty.').exactOptional(),
|
|
28
|
+
}),
|
|
29
|
+
write: z.strictObject({ path: filePath('The file to create or replace'), content: z.string().describe('The whole content of the file.'), risky }),
|
|
30
|
+
edit: z.strictObject({ path: filePath('The existing text file to change'), edits, risky }),
|
|
31
|
+
};
|
|
32
|
+
export const fsCommands = {
|
|
33
|
+
read: { registration: 'kvcoder.fs.file.get', description: 'Reads lines of a text file.', payload: payloads.read, asks: false, bounded: true },
|
|
34
|
+
list: { registration: 'kvcoder.fs.entry.list', description: 'Lists the files and folders of one folder.', payload: payloads.list, asks: false, bounded: true },
|
|
35
|
+
search: { registration: 'kvcoder.fs.text.search', description: 'Finds the lines that match a regular expression, in a file or under a folder.', payload: payloads.search, asks: false, bounded: true },
|
|
36
|
+
write: { registration: 'kvcoder.fs.write', description: 'Creates a file and its parent folders, or replaces the file.', payload: payloads.write, asks: true },
|
|
37
|
+
edit: { registration: 'kvcoder.fs.edit', description: 'Replaces exact pieces of text in an existing file; if one replacement fails, nothing is written.', payload: payloads.edit, asks: true },
|
|
38
|
+
};
|
|
39
|
+
const strictText = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
40
|
+
const missing = (error) => error instanceof Error && 'code' in error && error.code === 'ENOENT';
|
|
41
|
+
// The file system's own refusals (a folder in the way, no permission) are the model's to read and fix.
|
|
42
|
+
const refusedByFileSystem = (error) => error instanceof Error && 'code' in error && typeof error.code === 'string' && /^E[A-Z]+$/.test(error.code);
|
|
43
|
+
async function asProblems(run) {
|
|
44
|
+
try {
|
|
45
|
+
return await run();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (refusedByFileSystem(error))
|
|
49
|
+
throw invalid(error.message);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function statOrUndefined(target) {
|
|
54
|
+
try {
|
|
55
|
+
return await stat(target);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (missing(error))
|
|
59
|
+
return undefined;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function readText(target, requested) {
|
|
64
|
+
let bytes;
|
|
65
|
+
try {
|
|
66
|
+
bytes = await readFile(target);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
throw missing(error) ? notFound(`${requested} doesn't exist.`, { path: requested }) : error;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return strictText.decode(bytes);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
throw invalid(`${requested} isn't valid UTF-8 text, so it isn't edited.`, { path: requested });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function writeTo(ctx, input) {
|
|
79
|
+
const target = await resolveInWorkspace(ctx.job.workspace.path, input.path);
|
|
80
|
+
const existing = await statOrUndefined(target);
|
|
81
|
+
if (existing?.isDirectory() === true)
|
|
82
|
+
throw invalid(`${input.path} is a folder.`, { path: input.path });
|
|
83
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
84
|
+
ctx.job.signal.throwIfAborted();
|
|
85
|
+
await writeFile(target, input.content, 'utf8');
|
|
86
|
+
return { path: input.path, created: existing === undefined, bytes: Buffer.byteLength(input.content) };
|
|
87
|
+
}
|
|
88
|
+
async function editIn(ctx, input) {
|
|
89
|
+
const target = await resolveInWorkspace(ctx.job.workspace.path, input.path);
|
|
90
|
+
const edited = applyEdits(await readText(target, input.path), input.edits);
|
|
91
|
+
ctx.job.signal.throwIfAborted();
|
|
92
|
+
await writeFile(target, edited.text, 'utf8');
|
|
93
|
+
return { path: input.path, replacements: edited.replacements, firstChangedLine: edited.firstChangedLine };
|
|
94
|
+
}
|
|
95
|
+
const commands = fsCommands;
|
|
96
|
+
export function registerFsConnector(ctx) {
|
|
97
|
+
ctx.registerQuery('kvcoder.fs.file.get', {
|
|
98
|
+
description: commands.read.description,
|
|
99
|
+
input: callInput(payloads.read),
|
|
100
|
+
output: z.object({ path: z.string(), fromLine: z.number().int(), totalLines: z.number().int(), content: z.string() }),
|
|
101
|
+
handle: ({ payload }) => asProblems(() => readLines(ctx.job.workspace.path, payload)),
|
|
102
|
+
});
|
|
103
|
+
ctx.registerQuery('kvcoder.fs.entry.list', {
|
|
104
|
+
description: commands.list.description,
|
|
105
|
+
input: callInput(payloads.list),
|
|
106
|
+
output: z.object({ path: z.string(), entries: z.array(z.object({ name: z.string(), kind: z.enum(['file', 'folder']), bytes: z.number().int() })), truncated: z.boolean() }),
|
|
107
|
+
handle: ({ payload }) => asProblems(() => listEntries(ctx.job.workspace.path, payload)),
|
|
108
|
+
});
|
|
109
|
+
ctx.registerQuery('kvcoder.fs.text.search', {
|
|
110
|
+
description: commands.search.description,
|
|
111
|
+
input: callInput(payloads.search),
|
|
112
|
+
output: z.object({ matches: z.array(z.object({ path: z.string(), line: z.number().int(), text: z.string() })), truncated: z.boolean() }),
|
|
113
|
+
handle: ({ payload }) => asProblems(() => searchText(ctx.job.workspace.path, payload, ctx.job.signal)),
|
|
114
|
+
});
|
|
115
|
+
ctx.registerCommand('kvcoder.fs.write', {
|
|
116
|
+
description: commands.write.description,
|
|
117
|
+
input: callInput(payloads.write),
|
|
118
|
+
output: z.object({ path: z.string(), created: z.boolean(), bytes: z.number().int() }),
|
|
119
|
+
retries: 0,
|
|
120
|
+
maxInputBytes: 33_554_432,
|
|
121
|
+
handle: ({ payload }) => asProblems(() => writeTo(ctx, payload)),
|
|
122
|
+
});
|
|
123
|
+
ctx.registerCommand('kvcoder.fs.edit', {
|
|
124
|
+
description: commands.edit.description,
|
|
125
|
+
input: callInput(payloads.edit),
|
|
126
|
+
output: z.object({ path: z.string(), replacements: z.number().int(), firstChangedLine: z.number().int() }),
|
|
127
|
+
retries: 0,
|
|
128
|
+
maxInputBytes: 33_554_432,
|
|
129
|
+
handle: ({ payload }) => asProblems(() => editIn(ctx, payload)),
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/connectors/fs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAY,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAyB,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEnD,qHAAqH;AACrH,uHAAuH;AACvH,sEAAsE;AAEtE,yDAAyD;AACzD,MAAM,CAAC,MAAM,aAAa,GACxB,mRAAmR,CA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AK,CAAC;QAChC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC;QACrF,OAAO,EAAE,CAAC;QACV,aAAa,EAAE,UAAU;QACzB,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KACjE,CAAC,CAAC;IACH,GAAG,CAAC,eAAe,CAAC,iBAAiB,EAAE;QACrC,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;QACtC,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC/B,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC;QAC1G,OAAO,EAAE,CAAC;QACV,aAAa,EAAE,UAAU;QACzB,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KAChE,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z, type Ctx } from '@kvman/sdk';
|
|
2
|
+
import { type McpServer } from '../mcp/servers.ts';
|
|
3
|
+
/** What the prompt's index says the connector is for; the session's entry adds its servers. */
|
|
4
|
+
export declare const mcpDescription = "Tools from the MCP servers the person added. Call tools with { \"server\" } to see what a server offers, and with { \"server\", \"tool\" } to see a tool's arguments, before the first time you call it.";
|
|
5
|
+
/** The connector's description with the workspace's servers, as the prompt's index shows it. */
|
|
6
|
+
export declare function mcpIndexDescription(servers: readonly McpServer[]): string;
|
|
7
|
+
export declare const mcpCommands: {
|
|
8
|
+
tools: {
|
|
9
|
+
registration: string;
|
|
10
|
+
description: string;
|
|
11
|
+
payload: z.ZodObject<{
|
|
12
|
+
server: z.ZodString;
|
|
13
|
+
tool: z.ZodExactOptional<z.ZodString>;
|
|
14
|
+
}, z.core.$strict>;
|
|
15
|
+
asks: false;
|
|
16
|
+
};
|
|
17
|
+
call: {
|
|
18
|
+
registration: string;
|
|
19
|
+
description: string;
|
|
20
|
+
payload: z.ZodObject<{
|
|
21
|
+
server: z.ZodString;
|
|
22
|
+
tool: z.ZodString;
|
|
23
|
+
arguments: z.ZodExactOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
|
|
24
|
+
timeoutMs: z.ZodExactOptional<z.ZodNumber>;
|
|
25
|
+
risky: z.ZodBoolean;
|
|
26
|
+
}, z.core.$strict>;
|
|
27
|
+
asks: true;
|
|
28
|
+
result: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** What `kvcoder.mcp.tool.call` gives: the tool's text, and whether the tool says it failed. */
|
|
32
|
+
export declare const mcpCallSchema: z.ZodObject<{
|
|
33
|
+
text: z.ZodString;
|
|
34
|
+
isError: z.ZodBoolean;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
export declare function registerMcpConnector(ctx: Ctx): void;
|
|
37
|
+
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/connectors/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAS9D,+FAA+F;AAC/F,eAAO,MAAM,cAAc,6MAC4K,CAAC;AAExM,gGAAgG;AAChG,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,SAAS,EAAE,GAAG,MAAM,CAEzE;AAgBD,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;CAGoB,CAAC;AAE7C,gGAAgG;AAChG,eAAO,MAAM,aAAa;;;iBAAuD,CAAC;AAQlF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CA6BnD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from '@kvman/sdk';
|
|
2
|
+
import { callTimeout } from "../calls/shell-command.js";
|
|
3
|
+
import { mcpServer } from "../mcp/servers.js";
|
|
4
|
+
import { listTools, resultText, toolNamed } from "../mcp/tools.js";
|
|
5
|
+
import { callInput } from "./connector-command.js";
|
|
6
|
+
import { timeoutMs } from "./payload-fields.js";
|
|
7
|
+
// The `mcp` connector (plan 08 §8.5, ADR 0020, 3, 7, and 10): the tools of the MCP servers the person added. `tools`
|
|
8
|
+
// lists a server's tools or gives one tool's arguments; `call` runs a tool, after the person's approval when it is risky.
|
|
9
|
+
// The MCP client is loaded by the first call that connects, so a kvman with no server doesn't keep it in memory.
|
|
10
|
+
/** What the prompt's index says the connector is for; the session's entry adds its servers. */
|
|
11
|
+
export const mcpDescription = 'Tools from the MCP servers the person added. Call tools with { "server" } to see what a server offers, and with { "server", "tool" } to see a tool\'s arguments, before the first time you call it.';
|
|
12
|
+
/** The connector's description with the workspace's servers, as the prompt's index shows it. */
|
|
13
|
+
export function mcpIndexDescription(servers) {
|
|
14
|
+
return `${mcpDescription} Servers: ${servers.map((server) => `${server.name} (${server.description.replace(/[.\s]+$/, '')})`).join(', ')}.`;
|
|
15
|
+
}
|
|
16
|
+
const server = z.string().min(1).describe('The MCP server, by the name the system prompt lists.');
|
|
17
|
+
const risky = z.boolean().describe('true when the tool could change, delete, or send something that isn\'t your own work: creating or closing an issue, sending a message, writing to a database. The person is asked first. false for a tool that only reads.');
|
|
18
|
+
const payloads = {
|
|
19
|
+
tools: z.strictObject({ server, tool: z.string().min(1).describe("One tool to describe with its arguments' JSON Schema; every tool's name and description when left out.").exactOptional() }),
|
|
20
|
+
call: z.strictObject({
|
|
21
|
+
server,
|
|
22
|
+
tool: z.string().min(1).describe('The tool to call, by its name from tools.'),
|
|
23
|
+
arguments: z.record(z.string(), z.json()).describe("The tool's arguments, as its JSON Schema from tools asks; leave it out for a tool that takes none.").exactOptional(),
|
|
24
|
+
timeoutMs,
|
|
25
|
+
risky,
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
export const mcpCommands = {
|
|
29
|
+
tools: { registration: 'kvcoder.mcp.tool.describe', description: "Lists an MCP server's tools, or gives one tool's description and arguments.", payload: payloads.tools, asks: false },
|
|
30
|
+
call: { registration: 'kvcoder.mcp.tool.call', description: "Calls one tool of an MCP server and returns the tool's text.", payload: payloads.call, asks: true, result: "the tool's text." },
|
|
31
|
+
};
|
|
32
|
+
/** What `kvcoder.mcp.tool.call` gives: the tool's text, and whether the tool says it failed. */
|
|
33
|
+
export const mcpCallSchema = z.object({ text: z.string(), isError: z.boolean() });
|
|
34
|
+
const toolRowSchema = z.object({ name: z.string(), description: z.string() });
|
|
35
|
+
const describeOutput = z.union([z.object({ server: z.string(), tools: z.array(toolRowSchema) }), toolRowSchema.extend({ server: z.string(), arguments: z.json() })]);
|
|
36
|
+
// The jobs may run for the call's longest timeout, with room to report it.
|
|
37
|
+
const jobOptions = { retries: 0, timeoutMs: 660_000 };
|
|
38
|
+
export function registerMcpConnector(ctx) {
|
|
39
|
+
ctx.registerCommand('kvcoder.mcp.tool.describe', {
|
|
40
|
+
description: mcpCommands.tools.description,
|
|
41
|
+
input: callInput(payloads.tools),
|
|
42
|
+
output: describeOutput,
|
|
43
|
+
...jobOptions,
|
|
44
|
+
handle: async ({ payload }) => {
|
|
45
|
+
const found = await mcpServer(ctx, payload.server);
|
|
46
|
+
const { withServer } = await import("../mcp/connect.js");
|
|
47
|
+
const tools = await withServer(ctx, found, callTimeout(undefined), listTools);
|
|
48
|
+
if (payload.tool === undefined)
|
|
49
|
+
return { server: found.name, tools: tools.map((tool) => ({ name: tool.name, description: tool.description ?? '' })) };
|
|
50
|
+
const tool = toolNamed(found.name, tools, payload.tool);
|
|
51
|
+
return { server: found.name, name: tool.name, description: tool.description ?? '', arguments: tool.inputSchema };
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
ctx.registerCommand('kvcoder.mcp.tool.call', {
|
|
55
|
+
description: mcpCommands.call.description,
|
|
56
|
+
input: callInput(payloads.call),
|
|
57
|
+
output: mcpCallSchema,
|
|
58
|
+
...jobOptions,
|
|
59
|
+
handle: async ({ payload }) => {
|
|
60
|
+
const found = await mcpServer(ctx, payload.server);
|
|
61
|
+
const { withServer } = await import("../mcp/connect.js");
|
|
62
|
+
return withServer(ctx, found, callTimeout(payload.timeoutMs), async (connection) => {
|
|
63
|
+
toolNamed(found.name, await listTools(connection), payload.tool);
|
|
64
|
+
return resultText(await connection.client.callTool({ name: payload.tool, arguments: payload.arguments ?? {} }, undefined, connection.request));
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/connectors/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAY,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAkB,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAyB,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEh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,EAAE,EAAE,EAAE;YAC5B,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YACnD,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;YACzD,OAAO,UAAU,CAAC,GAAG,EAAE,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;gBACjF,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,SAAS,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;gBACjE,OAAO,UAAU,CAAC,MAAM,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;YACjJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from '@kvman/sdk';
|
|
2
|
+
export declare const risky: z.ZodBoolean;
|
|
3
|
+
export declare const background: z.ZodExactOptional<z.ZodBoolean>;
|
|
4
|
+
export declare const timeoutMs: z.ZodExactOptional<z.ZodNumber>;
|
|
5
|
+
export declare const edits: z.ZodArray<z.ZodObject<{
|
|
6
|
+
oldText: z.ZodString;
|
|
7
|
+
newText: z.ZodString;
|
|
8
|
+
}, z.core.$strict>>;
|
|
9
|
+
//# sourceMappingURL=payload-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload-fields.d.ts","sourceRoot":"","sources":["../../src/connectors/payload-fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,YAAY,CAAC;AAK/B,eAAO,MAAM,KAAK,cAEoQ,CAAC;AAEvR,eAAO,MAAM,UAAU,kCAAsK,CAAC;AAE9L,eAAO,MAAM,SAAS,iCAAqK,CAAC;AAE5L,eAAO,MAAM,KAAK;;;mBAGsG,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from '@kvman/sdk';
|
|
2
|
+
// The payload fields several connectors share (plan 08 §8.3 and §8.5). Every field has a description, since `help`
|
|
3
|
+
// shows these schemas to the model (ADR 0011, 10).
|
|
4
|
+
export const risky = z
|
|
5
|
+
.boolean()
|
|
6
|
+
.describe("true when this could lose or damage something that isn't your own work, or reaches outside the workspace folder: deleting or overwriting files you didn't create, sudo, a global install, git push --force or reset --hard. The person is asked first. Otherwise false.");
|
|
7
|
+
export const background = z.boolean().describe('true keeps a server or any long-running command running after the call returns; follow it up with the background connector.').exactOptional();
|
|
8
|
+
export const timeoutMs = z.number().int().positive().describe('How long the command may run, in milliseconds: 120000 by default, at most 600000. Ignored with background.').exactOptional();
|
|
9
|
+
export const edits = z
|
|
10
|
+
.array(z.strictObject({ oldText: z.string().describe('The exact text to replace, as it is now, whitespace and line breaks included. It must occur once.'), newText: z.string().describe('The text that replaces it.') }))
|
|
11
|
+
.min(1)
|
|
12
|
+
.describe('The replacements, applied together. They must not overlap; put several changes to one target in one call.');
|
|
13
|
+
//# sourceMappingURL=payload-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload-fields.js","sourceRoot":"","sources":["../../src/connectors/payload-fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,YAAY,CAAC;AAE/B,mHAAmH;AACnH,mDAAmD;AAEnD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC;KACnB,OAAO,EAAE;KACT,QAAQ,CAAC,yQAAyQ,CAAC,CAAC;AAEvR,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,6HAA6H,CAAC,CAAC,aAAa,EAAE,CAAC;AAE9L,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,4GAA4G,CAAC,CAAC,aAAa,EAAE,CAAC;AAE5L,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC;KACnB,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,mGAAmG,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC,EAAE,CAAC,CAAC;KACxN,GAAG,CAAC,CAAC,CAAC;KACN,QAAQ,CAAC,2GAA2G,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z, type Ctx } from '@kvman/sdk';
|
|
2
|
+
/** What the prompt's index says the connector is for; it names the shell this run uses. */
|
|
3
|
+
export declare const shellDescription: (shell: "bash" | "powershell") => string;
|
|
4
|
+
export declare const shellCommands: {
|
|
5
|
+
exec: {
|
|
6
|
+
registration: string;
|
|
7
|
+
description: string;
|
|
8
|
+
payload: z.ZodObject<{
|
|
9
|
+
line: z.ZodString;
|
|
10
|
+
background: z.ZodExactOptional<z.ZodBoolean>;
|
|
11
|
+
timeoutMs: z.ZodExactOptional<z.ZodNumber>;
|
|
12
|
+
risky: z.ZodBoolean;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
asks: true;
|
|
15
|
+
result: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare function registerShellConnector(ctx: Ctx): void;
|
|
19
|
+
//# sourceMappingURL=shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/connectors/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAQzC,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,GAAG,YAAY,KAAG,MAC0Q,CAAC;AAI3U,eAAO,MAAM,aAAa;;;;;;;;;;;;;CAEkB,CAAC;AAE7C,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAQrD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from '@kvman/sdk';
|
|
2
|
+
import { lineRunOptions, lineRunSchema, runLine } from "../calls/line-run.js";
|
|
3
|
+
import { lineCallInput, lineResult } from "./connector-command.js";
|
|
4
|
+
import { background, risky, timeoutMs } from "./payload-fields.js";
|
|
5
|
+
// The `shell` connector (plan 08 §8.3, ADR 0011, 2): `exec` runs one whole line in the real shell, in the workspace
|
|
6
|
+
// folder, after the person's approval when the call is risky.
|
|
7
|
+
/** What the prompt's index says the connector is for; it names the shell this run uses. */
|
|
8
|
+
export const shellDescription = (shell) => `Run a line in the real shell (${shell === 'bash' ? 'bash' : 'PowerShell'}) in the workspace folder: build, test, install, or anything no other connector covers. Set background to true for a server or any command that keeps running; to show the person an app you started, give its address to artifact write with the format url.`;
|
|
9
|
+
const execPayload = z.strictObject({ line: z.string().min(1).describe('The whole shell line to run, with any pipes, &&, or redirection.'), background, timeoutMs, risky });
|
|
10
|
+
export const shellCommands = {
|
|
11
|
+
exec: { registration: 'kvcoder.shell.run', description: 'Runs one line in the real shell, in the workspace folder.', payload: execPayload, asks: true, result: lineResult },
|
|
12
|
+
};
|
|
13
|
+
export function registerShellConnector(ctx) {
|
|
14
|
+
ctx.registerCommand('kvcoder.shell.run', {
|
|
15
|
+
description: shellCommands.exec.description,
|
|
16
|
+
input: lineCallInput(execPayload),
|
|
17
|
+
output: lineRunSchema,
|
|
18
|
+
...lineRunOptions,
|
|
19
|
+
handle: ({ sessionId, description, payload }) => runLine(ctx, { sessionId, description }, payload.line, payload),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+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M,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;KACjH,CAAC,CAAC;AACL,CAAC"}
|
package/dist/delay.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,wBAAgB,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ9E"}
|
package/dist/delay.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Waits `milliseconds`, or less when `signal` aborts; the caller checks the signal afterwards. */
|
|
2
|
+
export function delay(milliseconds, signal) {
|
|
3
|
+
return new Promise((resolve) => {
|
|
4
|
+
const timer = setTimeout(resolve, milliseconds);
|
|
5
|
+
signal.addEventListener('abort', () => {
|
|
6
|
+
clearTimeout(timer);
|
|
7
|
+
resolve();
|
|
8
|
+
}, { once: true });
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=delay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delay.js","sourceRoot":"","sources":["../src/delay.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,MAAM,UAAU,KAAK,CAAC,YAAoB,EAAE,MAAmB;IAC7D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAChD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YACpC,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,EAAE,CAAC;QACZ,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Ctx } from '@kvman/sdk';
|
|
2
|
+
import type { RunCallDoc } from '../schemas/records.ts';
|
|
3
|
+
type Approved = {
|
|
4
|
+
sessionId: string;
|
|
5
|
+
toolCallId: string;
|
|
6
|
+
call: RunCallDoc;
|
|
7
|
+
};
|
|
8
|
+
/** Whether an approved call is a worker's run, which never runs as a held call does. */
|
|
9
|
+
export declare const isDelegateRun: (call: RunCallDoc) => boolean;
|
|
10
|
+
/** Starts the run of an approved call; resolves to the next step's job id when the call got its result at once and nothing else is pending. */
|
|
11
|
+
export declare function startApprovedRun(ctx: Ctx, approved: Approved): Promise<string | null>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=approved-run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approved-run.d.ts","sourceRoot":"","sources":["../../src/delegate/approved-run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAIpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAUxD,KAAK,QAAQ,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAE5E,wFAAwF;AACxF,eAAO,MAAM,aAAa,GAAI,MAAM,UAAU,KAAG,OAAkE,CAAC;AAOpH,+IAA+I;AAC/I,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiC3F"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ProblemError } from '@kvman/sdk';
|
|
2
|
+
import { delegateRunSchema } from "../connectors/delegate.js";
|
|
3
|
+
import { errorOutput } from "../connector-call.js";
|
|
4
|
+
import { firePoint } from "../registry/session-points.js";
|
|
5
|
+
import { records, txRecords } from "../store/collections.js";
|
|
6
|
+
import { heldText, resolvePending } from "../turns/resolve.js";
|
|
7
|
+
import { createRun, dropRun, launchRun } from "./runs.js";
|
|
8
|
+
import { availableWorker, isProgram } from "./workers.js";
|
|
9
|
+
/** Whether an approved call is a worker's run, which never runs as a held call does. */
|
|
10
|
+
export const isDelegateRun = (call) => call.connector === 'delegate' && call.command === 'run';
|
|
11
|
+
async function refuse(ctx, approved, error) {
|
|
12
|
+
if (!(error instanceof ProblemError))
|
|
13
|
+
throw error;
|
|
14
|
+
return resolvePending(ctx, approved.sessionId, approved.toolCallId, heldText(approved.toolCallId, errorOutput(error.problem).output, true), false);
|
|
15
|
+
}
|
|
16
|
+
/** Starts the run of an approved call; resolves to the next step's job id when the call got its result at once and nothing else is pending. */
|
|
17
|
+
export async function startApprovedRun(ctx, approved) {
|
|
18
|
+
const { sessionId, toolCallId, call } = approved;
|
|
19
|
+
const payload = delegateRunSchema.parse(call.payload);
|
|
20
|
+
const session = await records(ctx.store).sessions.get(sessionId);
|
|
21
|
+
let worker;
|
|
22
|
+
try {
|
|
23
|
+
worker = await availableWorker(ctx, session?.checks ?? null, payload.worker);
|
|
24
|
+
if (!isProgram(worker))
|
|
25
|
+
throw new ProblemError({ code: 'VALIDATION_FAILED', message: `The worker ${worker.name} changed while the call waited. Make the call again.`, params: { worker: worker.name } });
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return refuse(ctx, approved, error);
|
|
29
|
+
}
|
|
30
|
+
const background = payload.background === true;
|
|
31
|
+
const run = await createRun(ctx, sessionId, worker, { description: call.description, task: payload.task }, background ? null : toolCallId);
|
|
32
|
+
if (background) {
|
|
33
|
+
await launchRun(ctx, run.id);
|
|
34
|
+
const text = `started ${run.id}`;
|
|
35
|
+
return resolvePending(ctx, sessionId, toolCallId, { toolCallId, text, isError: false, run: null, details: { description: call.description, connector: call.connector, command: call.command, output: text, durationMs: 0 } }, false);
|
|
36
|
+
}
|
|
37
|
+
const waiting = await ctx.store.transaction((tx) => {
|
|
38
|
+
const store = txRecords(tx);
|
|
39
|
+
const current = store.sessions.get(sessionId);
|
|
40
|
+
const turn = current === undefined || current.turnId === null ? undefined : store.turns.get(current.turnId);
|
|
41
|
+
if (turn === undefined || !turn.pending.some((item) => item.toolCallId === toolCallId))
|
|
42
|
+
return false;
|
|
43
|
+
store.turns.update(turn.id, { pending: turn.pending.map((item) => (item.toolCallId === toolCallId ? { toolCallId, kind: 'worker', questionId: null, question: null, childSessionId: null, runId: run.id } : item)) });
|
|
44
|
+
return true;
|
|
45
|
+
});
|
|
46
|
+
if (!waiting) {
|
|
47
|
+
await dropRun(ctx, run);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
await launchRun(ctx, run.id);
|
|
51
|
+
await firePoint(ctx, 'kvcoder.session.waiting', { sessionId, kind: 'worker' });
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=approved-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approved-run.js","sourceRoot":"","sources":["../../src/delegate/approved-run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAY,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,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5
|
+
};
|
|
6
|
+
/** The command line that runs `task` with a worker. */
|
|
7
|
+
export declare function commandLine(worker: ProgramWorker, task: string): CommandLine;
|
|
8
|
+
/** The command line that checks a kind's program is installed (ADR 0021, 37). */
|
|
9
|
+
export declare const checkCommand: (kind: ProgramWorker["kind"]) => CommandLine;
|
|
10
|
+
/** A program's answer from its standard output, and the reasons it gave for a failure. */
|
|
11
|
+
export declare function answerOf(kind: ProgramWorker['kind'], stdout: string): {
|
|
12
|
+
answer: string;
|
|
13
|
+
reasons: string[];
|
|
14
|
+
};
|
|
15
|
+
/** How a program's run ended. */
|
|
16
|
+
export type ProgramEnd = {
|
|
17
|
+
stdout: string;
|
|
18
|
+
stderr: string;
|
|
19
|
+
exitCode: number | null;
|
|
20
|
+
timedOut: boolean;
|
|
21
|
+
startError: string | null;
|
|
22
|
+
};
|
|
23
|
+
/** What a run returns to the model, and whether it is an error (ADR 0021, 32). */
|
|
24
|
+
export declare function runResult(worker: {
|
|
25
|
+
name: string;
|
|
26
|
+
kind: ProgramWorker['kind'];
|
|
27
|
+
timeoutMs: number;
|
|
28
|
+
}, end: ProgramEnd): {
|
|
29
|
+
text: string;
|
|
30
|
+
isError: boolean;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=programs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"programs.d.ts","sourceRoot":"","sources":["../../src/delegate/programs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAKlD,MAAM,MAAM,WAAW,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAI9D,uDAAuD;AACvD,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAW5E;AAED,iFAAiF;AACjF,eAAO,MAAM,YAAY,GAAI,MAAM,aAAa,CAAC,MAAM,CAAC,KAAG,WAAuD,CAAC;AAgCnH,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAE3G;AAED,iCAAiC;AACjC,MAAM,MAAM,UAAU,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEnI,kFAAkF;AAClF,wBAAgB,SAAS,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,EAAE,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAMvJ"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from '@kvman/sdk';
|
|
2
|
+
import { truncate } from "../result-text.js";
|
|
3
|
+
const option = (name, value) => (value === null ? [] : [name, value]);
|
|
4
|
+
/** The command line that runs `task` with a worker. */
|
|
5
|
+
export function commandLine(worker, task) {
|
|
6
|
+
if (worker.kind === 'opencode') {
|
|
7
|
+
const text = worker.instructions === '' ? task : `${worker.instructions}\n\n${task}`;
|
|
8
|
+
return { command: 'opencode', args: ['run', '--format', 'json', ...option('--model', worker.model), ...option('--agent', worker.agent), ...(worker.autoApprove ? ['--auto'] : []), '--', text] };
|
|
9
|
+
}
|
|
10
|
+
const instructions = option('--append-system-prompt', worker.instructions === '' ? null : worker.instructions);
|
|
11
|
+
if (worker.kind === 'pi') {
|
|
12
|
+
const tools = option('--tools', worker.tools === null ? null : worker.tools.join(','));
|
|
13
|
+
return { command: 'pi', args: ['-p', ...option('--model', worker.model), ...option('--thinking', worker.thinking), ...tools, ...instructions, '--', task] };
|
|
14
|
+
}
|
|
15
|
+
return { command: 'claude', args: ['-p', '--permission-mode', worker.permissionMode, ...option('--model', worker.model), ...option('--effort', worker.effort), ...instructions, '--', task] };
|
|
16
|
+
}
|
|
17
|
+
/** The command line that checks a kind's program is installed (ADR 0021, 37). */
|
|
18
|
+
export const checkCommand = (kind) => ({ command: kind, args: ['--version'] });
|
|
19
|
+
const eventSchema = z.object({ type: z.string(), part: z.object({ text: z.string().exactOptional() }).exactOptional(), error: z.object({ message: z.string().exactOptional() }).exactOptional() });
|
|
20
|
+
function eventOf(line) {
|
|
21
|
+
if (!line.trimStart().startsWith('{'))
|
|
22
|
+
return undefined;
|
|
23
|
+
let value;
|
|
24
|
+
try {
|
|
25
|
+
value = JSON.parse(line);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (error instanceof SyntaxError)
|
|
29
|
+
return undefined;
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
const parsed = eventSchema.safeParse(value);
|
|
33
|
+
return parsed.success ? parsed.data : undefined;
|
|
34
|
+
}
|
|
35
|
+
// opencode prints one JSON event per line: the answer is the text after the last tool call, and an error event's
|
|
36
|
+
// message is a reason. A line that isn't an event is ignored.
|
|
37
|
+
function opencodeAnswer(stdout) {
|
|
38
|
+
let texts = [];
|
|
39
|
+
const reasons = [];
|
|
40
|
+
for (const line of stdout.split('\n')) {
|
|
41
|
+
const event = eventOf(line);
|
|
42
|
+
if (event === undefined)
|
|
43
|
+
continue;
|
|
44
|
+
if (event.type === 'tool_use')
|
|
45
|
+
texts = [];
|
|
46
|
+
else if (event.type === 'text' && event.part?.text !== undefined)
|
|
47
|
+
texts.push(event.part.text);
|
|
48
|
+
else if (event.type === 'error' && event.error?.message !== undefined)
|
|
49
|
+
reasons.push(event.error.message);
|
|
50
|
+
}
|
|
51
|
+
return { answer: texts.join('\n\n').trim(), reasons };
|
|
52
|
+
}
|
|
53
|
+
/** A program's answer from its standard output, and the reasons it gave for a failure. */
|
|
54
|
+
export function answerOf(kind, stdout) {
|
|
55
|
+
return kind === 'opencode' ? opencodeAnswer(stdout) : { answer: stdout.trim(), reasons: [] };
|
|
56
|
+
}
|
|
57
|
+
/** What a run returns to the model, and whether it is an error (ADR 0021, 32). */
|
|
58
|
+
export function runResult(worker, end) {
|
|
59
|
+
if (end.startError !== null)
|
|
60
|
+
return { text: `${worker.name} could not start: ${end.startError}`, isError: true };
|
|
61
|
+
const { answer, reasons } = answerOf(worker.kind, end.stdout);
|
|
62
|
+
if (!end.timedOut && end.exitCode === 0)
|
|
63
|
+
return answer === '' ? { text: `${worker.name} returned no answer`, isError: true } : { text: truncate(answer), isError: false };
|
|
64
|
+
const first = end.timedOut ? `${worker.name} timed out after ${Math.round(worker.timeoutMs / 1000)} s` : `${worker.name} exited with code ${String(end.exitCode)}`;
|
|
65
|
+
return { text: truncate([first, ...reasons, end.stderr.trim(), answer].filter((part) => part !== '').join('\n')), isError: true };
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=programs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"programs.js","sourceRoot":"","sources":["../../src/delegate/programs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAQ7C,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,KAAoB,EAAY,EAAE,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAEvG,uDAAuD;AACvD,MAAM,UAAU,WAAW,CAAC,MAAqB,EAAE,IAAY;IAC7D,IAAI,MAAM,CAAC,IAAI,KAA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+
export declare function runLost(ctx: Ctx, jobId: string, code: string): Promise<void>;
|
|
3
|
+
/** The checks of the workspace's program workers, as a session keeps them (ADR 0021, 37). */
|
|
4
|
+
export declare function workerChecks(ctx: Ctx): Promise<{
|
|
5
|
+
name: string;
|
|
6
|
+
passed: boolean;
|
|
7
|
+
}[]>;
|
|
8
|
+
export declare function registerWorkerRun(ctx: Ctx): void;
|
|
9
|
+
//# sourceMappingURL=register-worker-run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-worker-run.d.ts","sourceRoot":"","sources":["../../src/delegate/register-worker-run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAiBzC,wBAAsB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAelF;AAED,6FAA6F;AAC7F,wBAAsB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CAGzF;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CA8BhD"}
|