@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,48 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { copyFile, mkdir } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { resolveInWorkspace } from "../files/workspace-path.js";
|
|
5
|
+
// A message's files that aren't images (plan 08 §8.1, ADR 0018, 1 to 4): each is copied into the workspace folder under
|
|
6
|
+
// `attachments/`, where the agent opens it with its file commands, and the message's text names them. Nothing is
|
|
7
|
+
// overwritten: a name that exists gets `-2`, `-3`, … before its extension.
|
|
8
|
+
const folderName = 'attachments';
|
|
9
|
+
const isTaken = (error) => error instanceof Error && 'code' in error && error.code === 'EEXIST';
|
|
10
|
+
/** A file's name as it is saved: its base name, with only letters, digits, space, and `._-()` kept. */
|
|
11
|
+
export function safeName(name) {
|
|
12
|
+
const base = name.split(/[\\/]/).at(-1) ?? '';
|
|
13
|
+
const safe = base.replace(/[^\p{L}\p{N} ._()-]/gu, '_').trim();
|
|
14
|
+
return safe === '' || safe === '.' || safe === '..' ? 'file' : safe;
|
|
15
|
+
}
|
|
16
|
+
async function copyUnder(source, folder, name) {
|
|
17
|
+
const { name: stem, ext } = path.parse(name);
|
|
18
|
+
for (let count = 1;; count += 1) {
|
|
19
|
+
const candidate = count === 1 ? name : `${stem}-${count}${ext}`;
|
|
20
|
+
try {
|
|
21
|
+
await copyFile(source, path.join(folder, candidate), constants.COPYFILE_EXCL);
|
|
22
|
+
return candidate;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (!isTaken(error))
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Saves the files into the workspace folder and gives their paths in it; a user upload leaves the kernel's files. */
|
|
31
|
+
export async function saveAttachments(ctx, files) {
|
|
32
|
+
if (files.length === 0)
|
|
33
|
+
return [];
|
|
34
|
+
const folder = await resolveInWorkspace(ctx.job.workspace.path, folderName);
|
|
35
|
+
await mkdir(folder, { recursive: true });
|
|
36
|
+
const saved = [];
|
|
37
|
+
for (const file of files) {
|
|
38
|
+
saved.push(`${folderName}/${await copyUnder(await ctx.files.path(file.id), folder, safeName(file.name))}`);
|
|
39
|
+
if (file.owner.kind === 'user')
|
|
40
|
+
await ctx.files.unlink(file.id);
|
|
41
|
+
}
|
|
42
|
+
return saved;
|
|
43
|
+
}
|
|
44
|
+
/** The message's text with its saved files named at its end. */
|
|
45
|
+
export function withAttachments(text, saved) {
|
|
46
|
+
return saved.length === 0 ? text : `${text}\n\nAttached files:\n${saved.map((file) => `- ${file}`).join('\n')}`;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=attachments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachments.js","sourceRoot":"","sources":["../../src/messages/attachments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,wHAAwH;AACxH,iHAAiH;AACjH,2EAA2E;AAE3E,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC,MAAM,OAAO,GAAG,CAAC,KAAc,EAAW,EAAE,CAAC,KAA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E,KAAsB;IACpE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAC5E,MAAM,KAAK,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,CAAC,IAAI,CAAC,GAAG,UAAU,IAAI,MAAM,SAAS,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;QAC3G,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM;YAAE,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,KAAwB;IACpE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,wBAAwB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Ctx, File, Stored } from '@kvman/sdk';
|
|
2
|
+
import type { SessionDoc, Source } from '../schemas/records.ts';
|
|
3
|
+
/** A message's files: its images, which the session's model must take (ADR 0009, 103), and every other file (ADR 0018, 2). */
|
|
4
|
+
export declare function sortedFiles(ctx: Ctx, session: Stored<SessionDoc>, fileIds: readonly string[]): Promise<{
|
|
5
|
+
images: File[];
|
|
6
|
+
others: File[];
|
|
7
|
+
}>;
|
|
8
|
+
export type Incoming = {
|
|
9
|
+
text: string;
|
|
10
|
+
fileIds: readonly string[];
|
|
11
|
+
source: Source;
|
|
12
|
+
mayStart: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function receiveMessage(ctx: Ctx, session: Stored<SessionDoc>, incoming: Incoming): Promise<void>;
|
|
15
|
+
//# sourceMappingURL=receive-message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receive-message.d.ts","sourceRoot":"","sources":["../../src/messages/receive-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAIpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAehE,8HAA8H;AAC9H,wBAAsB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAAC,MAAM,EAAE,IAAI,EAAE,CAAA;CAAE,CAAC,CAKhJ;AAED,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAEvG,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B7G"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { dismissedText } from "../connectors/ask.js";
|
|
2
|
+
import { reportInterrupted } from "../jobs/process-report.js";
|
|
3
|
+
import { invalid } from "../problems.js";
|
|
4
|
+
import { now } from "../sessions/session-lookup.js";
|
|
5
|
+
import { txRecords } from "../store/collections.js";
|
|
6
|
+
import { appendMessage, userContent } from "../turns/history.js";
|
|
7
|
+
import { modelInfo } from "../turns/model-info.js";
|
|
8
|
+
import { heldText } from "../turns/resolve.js";
|
|
9
|
+
import { beginTurn, openTurn, queueStep } from "../turns/start-turn.js";
|
|
10
|
+
import { saveAttachments, withAttachments } from "./attachments.js";
|
|
11
|
+
// A message from the person or an extension (plan 08 §8.1): on an idle session it starts a turn; on a running one it
|
|
12
|
+
// waits for the step's results; on a waiting one it dismisses the pending questions and denies the approvals, and the
|
|
13
|
+
// next step runs once no subagent is left to wait for (ADR 0009, 90).
|
|
14
|
+
const imageTypes = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp']);
|
|
15
|
+
/** A message's files: its images, which the session's model must take (ADR 0009, 103), and every other file (ADR 0018, 2). */
|
|
16
|
+
export async function sortedFiles(ctx, session, fileIds) {
|
|
17
|
+
const files = await Promise.all(fileIds.map((fileId) => ctx.files.get(fileId)));
|
|
18
|
+
const images = files.filter((file) => imageTypes.has(file.type));
|
|
19
|
+
if (images.length > 0 && (await modelInfo(ctx, session.model))?.images !== true)
|
|
20
|
+
throw invalid(`The model ${session.model ?? '(none)'} doesn't take images.`, { model: session.model });
|
|
21
|
+
return { images, others: files.filter((file) => !imageTypes.has(file.type)) };
|
|
22
|
+
}
|
|
23
|
+
export async function receiveMessage(ctx, session, incoming) {
|
|
24
|
+
await reportInterrupted(ctx, session.id);
|
|
25
|
+
const { images, others } = await sortedFiles(ctx, session, incoming.fileIds);
|
|
26
|
+
const text = withAttachments(incoming.text, await saveAttachments(ctx, others));
|
|
27
|
+
const files = images.length === 0 ? { fileIds: null, fileNames: null } : { fileIds: images.map((file) => file.id), fileNames: images.map((file) => file.name) };
|
|
28
|
+
const next = await ctx.store.transaction((tx) => {
|
|
29
|
+
const store = txRecords(tx);
|
|
30
|
+
const fresh = store.sessions.get(session.id) ?? session;
|
|
31
|
+
if (fresh.status === 'idle') {
|
|
32
|
+
if (fresh.autoTitle && fresh.title === '')
|
|
33
|
+
store.sessions.update(fresh.id, { title: incoming.text.slice(0, 60) });
|
|
34
|
+
appendMessage(store, fresh, { kind: 'user', content: userContent(text), source: incoming.source, ...files });
|
|
35
|
+
return incoming.mayStart ? { start: openTurn(store, fresh) } : {};
|
|
36
|
+
}
|
|
37
|
+
store.queued.insert({ sessionId: fresh.id, source: incoming.source, text, ...files, createdAt: now() });
|
|
38
|
+
const turn = fresh.turnId === null ? undefined : store.turns.get(fresh.turnId);
|
|
39
|
+
if (fresh.status === 'running' || !incoming.mayStart || turn === undefined)
|
|
40
|
+
return {};
|
|
41
|
+
const dismissed = turn.pending.filter((item) => item.questionId !== null);
|
|
42
|
+
const results = dismissed.map((item) => {
|
|
43
|
+
const question = item.questionId === null ? undefined : store.questions.get(item.questionId);
|
|
44
|
+
if (question !== undefined)
|
|
45
|
+
store.questions.delete(question.id);
|
|
46
|
+
return heldText(item.toolCallId, dismissedText(question?.kind ?? 'text'), true);
|
|
47
|
+
});
|
|
48
|
+
const pending = turn.pending.filter((item) => item.questionId === null);
|
|
49
|
+
store.turns.update(turn.id, { pending, results: [...turn.results, ...results] });
|
|
50
|
+
if (pending.length > 0)
|
|
51
|
+
return {};
|
|
52
|
+
store.sessions.update(fresh.id, { status: 'running', updatedAt: now() });
|
|
53
|
+
return { resume: turn.id };
|
|
54
|
+
});
|
|
55
|
+
if (next.start !== undefined)
|
|
56
|
+
await beginTurn(ctx, session.id, next.start, true);
|
|
57
|
+
if (next.resume !== undefined)
|
|
58
|
+
await queueStep(ctx, session.id, next.resume, true);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=receive-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receive-message.js","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AAI,CAAC,KAAK,KAAK,SAAS;QAAE,MAAM,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACjF,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;QAAE,MAAM,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-messages.d.ts","sourceRoot":"","sources":["../../src/messages/register-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAazC,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAmD/C"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { z } from '@kvman/sdk';
|
|
2
|
+
import { fromSessionHandler } from "../registry/session-points.js";
|
|
3
|
+
import { findSession, ownSession, userOnly } from "../sessions/session-lookup.js";
|
|
4
|
+
import { messageSchema, messageView, queuedView } from "../sessions/session-view.js";
|
|
5
|
+
import { records, txRecords } from "../store/collections.js";
|
|
6
|
+
import { appendMessage } from "../turns/history.js";
|
|
7
|
+
import { newestMessages } from "../turns/message-blocks.js";
|
|
8
|
+
import { receiveMessage } from "./receive-message.js";
|
|
9
|
+
// Messages (plan 08 §8.6): the person's `message.send`, extensions' `message.inject`, display-only notes, and the list.
|
|
10
|
+
const sendSchema = z.object({ sessionId: z.string(), text: z.string().min(1), fileIds: z.array(z.string()).exactOptional() });
|
|
11
|
+
export function registerMessages(ctx) {
|
|
12
|
+
ctx.registerCommand('kvcoder.message.send', {
|
|
13
|
+
description: "Sends the person's message: it starts a turn, steers the running one, or answers a waiting one.",
|
|
14
|
+
input: sendSchema,
|
|
15
|
+
output: z.object({}),
|
|
16
|
+
public: true,
|
|
17
|
+
retries: 0,
|
|
18
|
+
handle: async ({ sessionId, text, fileIds }) => {
|
|
19
|
+
userOnly(ctx, 'kvcoder.message.send');
|
|
20
|
+
await receiveMessage(ctx, await ownSession(ctx, sessionId), { text, fileIds: fileIds ?? [], source: { kind: 'user' }, mayStart: true });
|
|
21
|
+
return {};
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
ctx.registerCommand('kvcoder.message.inject', {
|
|
25
|
+
description: "Adds an extension's message to a session, as the person's message would be, marked as the extension's.",
|
|
26
|
+
input: sendSchema,
|
|
27
|
+
output: z.object({}),
|
|
28
|
+
public: true,
|
|
29
|
+
retries: 0,
|
|
30
|
+
handle: async ({ sessionId, text, fileIds }) => {
|
|
31
|
+
const caller = ctx.job.caller;
|
|
32
|
+
const source = caller.kind === 'extension' ? { kind: 'extension', name: caller.name } : { kind: 'user' };
|
|
33
|
+
const session = await ownSession(ctx, sessionId);
|
|
34
|
+
await receiveMessage(ctx, session, { text, fileIds: fileIds ?? [], source, mayStart: !(await fromSessionHandler(ctx)) });
|
|
35
|
+
return {};
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
ctx.registerCommand('kvcoder.note.add', {
|
|
39
|
+
description: 'Adds a display-only note to a session; it never reaches the model and never starts a turn.',
|
|
40
|
+
input: z.object({ sessionId: z.string(), key: z.string().min(1), params: z.record(z.string(), z.json()).exactOptional() }),
|
|
41
|
+
output: z.object({}),
|
|
42
|
+
public: true,
|
|
43
|
+
handle: async ({ sessionId, key, params }) => {
|
|
44
|
+
const session = await ownSession(ctx, sessionId);
|
|
45
|
+
await ctx.store.transaction((tx) => appendMessage(txRecords(tx), session, { kind: 'note', content: { key, ...(params === undefined ? {} : { params }) } }));
|
|
46
|
+
return {};
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
ctx.registerQuery('kvcoder.message.list', {
|
|
50
|
+
description: "Lists a session's newest messages in order, the count of older ones, and the messages waiting for the step.",
|
|
51
|
+
input: z.object({ sessionId: z.string(), limit: z.number().int().positive().max(1000) }),
|
|
52
|
+
output: z.object({ messages: z.array(messageSchema), omitted: z.number().int() }),
|
|
53
|
+
public: true,
|
|
54
|
+
handle: async ({ sessionId, limit }) => {
|
|
55
|
+
const session = await findSession(ctx, sessionId);
|
|
56
|
+
const store = records(ctx.store);
|
|
57
|
+
const newest = await newestMessages(ctx, sessionId, limit, session.nextSeq);
|
|
58
|
+
const queued = await store.queued.find({ sessionId }, { limit: 1000 });
|
|
59
|
+
return { messages: [...newest.map(messageView), ...queued.map(queuedView)], omitted: (await store.messages.count({ sessionId })) - newest.length };
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=register-messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-messages.js","sourceRoot":"","sources":["../../src/messages/register-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAY,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,wHAAwH;AAExH,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,E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AC,MAAM,EAAE,CAAC;QACrJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ProblemError, type Json } from '@kvman/sdk';
|
|
2
|
+
/** A `VALIDATION_FAILED` Problem to throw. */
|
|
3
|
+
export declare function invalid(message: string, params?: Record<string, Json>): ProblemError;
|
|
4
|
+
/** A `TOO_LARGE` Problem to throw. */
|
|
5
|
+
export declare function tooLarge(message: string, limit: number): ProblemError;
|
|
6
|
+
/** A `NOT_FOUND` Problem to throw. */
|
|
7
|
+
export declare function notFound(message: string, params?: Record<string, Json>): ProblemError;
|
|
8
|
+
//# sourceMappingURL=problems.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problems.d.ts","sourceRoot":"","sources":["../src/problems.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAErD,8CAA8C;AAC9C,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAM,GAAG,YAAY,CAExF;AAED,sCAAsC;AACtC,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAErE;AAED,sCAAsC;AACtC,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAM,GAAG,YAAY,CAEzF"}
|
package/dist/problems.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ProblemError } from '@kvman/sdk';
|
|
2
|
+
/** A `VALIDATION_FAILED` Problem to throw. */
|
|
3
|
+
export function invalid(message, params = {}) {
|
|
4
|
+
return new ProblemError({ code: 'VALIDATION_FAILED', message, params });
|
|
5
|
+
}
|
|
6
|
+
/** A `TOO_LARGE` Problem to throw. */
|
|
7
|
+
export function tooLarge(message, limit) {
|
|
8
|
+
return new ProblemError({ code: 'TOO_LARGE', message, params: { limit } });
|
|
9
|
+
}
|
|
10
|
+
/** A `NOT_FOUND` Problem to throw. */
|
|
11
|
+
export function notFound(message, params = {}) {
|
|
12
|
+
return new ProblemError({ code: 'NOT_FOUND', message, params });
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=problems.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problems.js","sourceRoot":"","sources":["../src/problems.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAa,MAAM,YAAY,CAAC;AAErD,8CAA8C;AAC9C,MAAM,UAAU,OAAO,CAAC,OAAe,EAAE,SAA+B,EAAE;IACxE,OAAO,IAAI,YAAY,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,QAAQ,CAAC,OAAe,EAAE,KAAa;IACrD,OAAO,IAAI,YAAY,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AAC7E,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,QAAQ,CAAC,OAAe,EAAE,SAA+B,EAAE;IACzE,OAAO,IAAI,YAAY,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Section } from '../registry/register-sections.ts';
|
|
2
|
+
import { type Role } from './working-method.ts';
|
|
3
|
+
export type PromptInput = {
|
|
4
|
+
/** The lead of a chat, or a worker's subagent: each has its own identity and working method (ADR 0022, 3). */
|
|
5
|
+
role: Role;
|
|
6
|
+
workspacePath: string;
|
|
7
|
+
platform: NodeJS.Platform;
|
|
8
|
+
shell: 'bash' | 'powershell';
|
|
9
|
+
language: string;
|
|
10
|
+
sections: readonly Section[];
|
|
11
|
+
/** The worker a subagent runs for: its instructions follow the sections (ADR 0021, 8). */
|
|
12
|
+
worker?: {
|
|
13
|
+
name: string;
|
|
14
|
+
instructions: string;
|
|
15
|
+
};
|
|
16
|
+
connectors: readonly {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
commands: readonly string[];
|
|
20
|
+
signatures?: readonly string[];
|
|
21
|
+
}[];
|
|
22
|
+
};
|
|
23
|
+
export type BuiltPrompt = {
|
|
24
|
+
prompt: string;
|
|
25
|
+
included: ReadonlySet<Section>;
|
|
26
|
+
left: readonly Section[];
|
|
27
|
+
};
|
|
28
|
+
export declare function buildPrompt(input: PromptInput): BuiltPrompt;
|
|
29
|
+
//# sourceMappingURL=build-prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-prompt.d.ts","sourceRoot":"","sources":["../../src/prompt/build-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAEhE,OAAO,EAA+B,KAAK,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAK7E,MAAM,MAAM,WAAW,GAAG;IACxB,8GAA8G;IAC9G,IAAI,EAAE,IAAI,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,0FAA0F;IAC1F,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,UAAU,EAAE,SAAS;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,EAAE,CAAC;CAC3H,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAAC,IAAI,EAAE,SAAS,OAAO,EAAE,CAAA;CAAE,CAAC;AAqDvG,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAM3D"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { sectionsLimit } from "../registry/register-sections.js";
|
|
2
|
+
import { identityLine, workingMethod } from "./working-method.js";
|
|
3
|
+
const systems = { linux: 'Linux', darwin: 'macOS', win32: 'Windows' };
|
|
4
|
+
function languageName(code) {
|
|
5
|
+
const name = new Intl.DisplayNames(['en'], { type: 'language' }).of(code);
|
|
6
|
+
return name === undefined || name === code ? code : `${name} (${code})`;
|
|
7
|
+
}
|
|
8
|
+
// The base prompt (ADR 0009, 163 and 166; ADR 0011, 1; ADR 0022): who the agent is, its one tool, connectors, and how it works.
|
|
9
|
+
function basePrompt(input) {
|
|
10
|
+
const shell = input.shell === 'bash' ? 'bash' : 'PowerShell';
|
|
11
|
+
const identity = [
|
|
12
|
+
identityLine(input.role, `in the folder ${input.workspacePath} on ${systems[input.platform] ?? input.platform}`),
|
|
13
|
+
`Reply in ${languageName(input.language)} unless the person writes in another language.`,
|
|
14
|
+
].join('\n');
|
|
15
|
+
const tool = 'Your one tool is run: it runs one command of a connector, as { description, connector, command, payload }. description is one sentence for the person, saying what the call does. Below, `fs write` means the connector fs and its command write.';
|
|
16
|
+
const connectors = `Connectors are the only way you act. When a connector other than shell covers a task, use it instead of a shell line: it checks its input, returns structured results, and is shown to the person. Use shell only for what no other connector does. Every connector has the command help. A command listed below with its payload needs no help call; for any other command, or for what a field means, call the connector's help with { "command": "<name>" } before the first use. \`shell exec\`, \`fs write\`, \`fs edit\`, and \`mcp call\` take risky, which you always send: true when the call could lose, damage, change, or send something that isn't your own work or reaches outside the workspace folder, and the person is then asked first; false otherwise, such as for a tool that only reads. Each \`shell exec\` starts in the workspace folder, so cd doesn't carry over to the next call; the shell is ${shell}.`;
|
|
17
|
+
return [identity, tool, connectors, workingMethod(input.role)].join('\n\n');
|
|
18
|
+
}
|
|
19
|
+
// A connector's entry: its owner's description, then its commands, which kvcoder adds (ADR 0009, 164; ADR 0011, 3). A
|
|
20
|
+
// built-in's entry is one line per command with its payload's signature (ADR 0012, 1 and 14); `help`'s payload is `{ command? }`.
|
|
21
|
+
function connectorLine(connector) {
|
|
22
|
+
const description = /[.!?)]$/.test(connector.description.trimEnd()) ? connector.description.trimEnd() : `${connector.description.trimEnd()}.`;
|
|
23
|
+
if (connector.signatures === undefined)
|
|
24
|
+
return `- ${connector.name}: ${description} Commands: ${[...connector.commands, 'help'].join(', ')}.`;
|
|
25
|
+
const signatures = connector.signatures;
|
|
26
|
+
const names = [...connector.commands, 'help'];
|
|
27
|
+
const width = Math.max(...names.map((name) => name.length));
|
|
28
|
+
const rows = connector.commands.map((name, index) => {
|
|
29
|
+
const signature = signatures[index];
|
|
30
|
+
if (signature === undefined)
|
|
31
|
+
throw new Error(`The connector ${connector.name} has no signature for the command ${name}.`);
|
|
32
|
+
return ` ${name.padEnd(width)} ${signature}`;
|
|
33
|
+
});
|
|
34
|
+
rows.push(` ${'help'.padEnd(width)} { command? }`);
|
|
35
|
+
return [`- ${connector.name}: ${description}`, ...rows].join('\n');
|
|
36
|
+
}
|
|
37
|
+
function keptSections(sections) {
|
|
38
|
+
const kept = [];
|
|
39
|
+
const left = [];
|
|
40
|
+
let total = 0;
|
|
41
|
+
for (const section of sections) {
|
|
42
|
+
if (total + section.size > sectionsLimit) {
|
|
43
|
+
left.push(section);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
total += section.size;
|
|
47
|
+
kept.push(section);
|
|
48
|
+
}
|
|
49
|
+
return { kept, left };
|
|
50
|
+
}
|
|
51
|
+
export function buildPrompt(input) {
|
|
52
|
+
const { kept, left } = keptSections(input.sections);
|
|
53
|
+
const parts = [basePrompt(input), ...kept.map((section) => `## ${section.title}\n${section.content}`)];
|
|
54
|
+
if (input.worker !== undefined && input.worker.instructions !== '')
|
|
55
|
+
parts.push(`## Worker: ${input.worker.name}\n${input.worker.instructions}`);
|
|
56
|
+
if (input.connectors.length > 0)
|
|
57
|
+
parts.push(['## Connectors', ...input.connectors.map(connectorLine)].join('\n'));
|
|
58
|
+
return { prompt: parts.join('\n\n'), included: new Set(kept), left };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=build-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-prompt.js","sourceRoot":"","sources":["../../src/prompt/build-prompt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAa,MAAM,qBAAqB,CAAC;AAoB7E,MAAM,OAAO,GAA6C,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAEhH,SAAS,YAAY,CAAC,IAAY;IAChC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAC1E,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,IAAI,GAAG,CAAC;AAC1E,CAAC;AAED,gIAAgI;AAChI,SAAS,UAAU,CAAC,KAAkB;IACpC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAA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AC;IACpD,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACvG,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,CAAC,YAAY,KAAK,EAAE;QAAE,KAAK,CAAC,IAAI,CAAC,cAAc,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IAChJ,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAClH,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-prompt.d.ts","sourceRoot":"","sources":["../../src/prompt/register-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAMzC,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAsB7C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from '@kvman/sdk';
|
|
2
|
+
import { findSession } from "../sessions/session-lookup.js";
|
|
3
|
+
import { sessionTools } from "./session-prompt.js";
|
|
4
|
+
// `kvcoder.prompt.get` (plan 08 §8.6): the exact system prompt a session's next step sends, with each section's owner,
|
|
5
|
+
// reach, and size for the conversation's Prompt tab (ADR 0009, 104).
|
|
6
|
+
export function registerPrompt(ctx) {
|
|
7
|
+
ctx.registerQuery('kvcoder.prompt.get', {
|
|
8
|
+
description: "Gives the exact system prompt of a session's next step, and its sections.",
|
|
9
|
+
input: z.object({ sessionId: z.string() }),
|
|
10
|
+
output: z.object({
|
|
11
|
+
prompt: z.string(),
|
|
12
|
+
sections: z.array(z.object({ id: z.string(), title: z.string(), owner: z.string(), reach: z.enum(['global', 'workspace', 'session']), size: z.number(), included: z.boolean() })),
|
|
13
|
+
}),
|
|
14
|
+
public: true,
|
|
15
|
+
handle: async ({ sessionId }) => {
|
|
16
|
+
const tools = await sessionTools(ctx, await findSession(ctx, sessionId));
|
|
17
|
+
const sections = [...tools.built.included, ...tools.built.left].map((section) => ({
|
|
18
|
+
id: section.id,
|
|
19
|
+
title: section.title,
|
|
20
|
+
owner: section.owner,
|
|
21
|
+
reach: section.global ? 'global' : section.sessionId === null ? 'workspace' : 'session',
|
|
22
|
+
size: section.size,
|
|
23
|
+
included: tools.built.included.has(section),
|
|
24
|
+
}));
|
|
25
|
+
return { prompt: tools.built.prompt, sections };
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=register-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-prompt.js","sourceRoot":"","sources":["../../src/prompt/register-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAY,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,uHAAuH;AACvH,qEAAqE;AACrE,MAAM,UAAU,cAAc,CAAC,GAAQ;IACrC,GAAG,CAAC,aAAa,CAAC,oBAAoB,EAAE;QACtC,WAAW,EAAE,2EAA2E;QACxF,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,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CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;aAC5C,CAAC,CAAC,CAAC;YACJ,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;QAClD,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Ctx, type Stored } from '@kvman/sdk';
|
|
2
|
+
import type { ShellCommand } from '../calls/shell-command.ts';
|
|
3
|
+
import { type ConnectorRow } from '../registry/register-connectors.ts';
|
|
4
|
+
import type { SessionDoc } from '../schemas/records.ts';
|
|
5
|
+
import { type BuiltPrompt } from './build-prompt.ts';
|
|
6
|
+
/** A connector the session's agent can call: its entry in the prompt's index and in the `run` tool's enum. */
|
|
7
|
+
export type ListedConnector = {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
commands: string[];
|
|
11
|
+
signatures?: readonly string[];
|
|
12
|
+
};
|
|
13
|
+
export type SessionTools = {
|
|
14
|
+
built: BuiltPrompt;
|
|
15
|
+
shell: ShellCommand;
|
|
16
|
+
/** Every registered connector of the run, callable or not. */
|
|
17
|
+
connectors: ConnectorRow[];
|
|
18
|
+
/** The connectors the session may call, in the prompt's order. */
|
|
19
|
+
listed: ListedConnector[];
|
|
20
|
+
/** The names that are turned off (ADR 0014, 7). */
|
|
21
|
+
disabled: ReadonlySet<string>;
|
|
22
|
+
};
|
|
23
|
+
export declare function sessionTools(ctx: Ctx, session: Stored<SessionDoc>): Promise<SessionTools>;
|
|
24
|
+
//# sourceMappingURL=session-prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-prompt.d.ts","sourceRoot":"","sources":["../../src/prompt/session-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,GAAG,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAO9D,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAGzF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOlE,8GAA8G;AAC9G,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAExH,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,EAAE,YAAY,CAAC;IACpB,8DAA8D;IAC9D,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,kEAAkE;IAClE,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,mDAAmD;IACnD,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC/B,CAAC;AASF,wBAAsB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CA4B/F"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from '@kvman/sdk';
|
|
2
|
+
import { builtinDescriptions, builtinSignatures, commandsOf } from "../connectors/builtin-connectors.js";
|
|
3
|
+
import { shellFor } from "../calls/shell-program.js";
|
|
4
|
+
import { builtinConnectors } from "../connector-call.js";
|
|
5
|
+
import { delegateIndexDescription } from "../connectors/delegate.js";
|
|
6
|
+
import { mcpIndexDescription } from "../connectors/mcp.js";
|
|
7
|
+
import { availableWorkers } from "../delegate/workers.js";
|
|
8
|
+
import { mcpServers } from "../mcp/servers.js";
|
|
9
|
+
import { activeConnectors } from "../registry/register-connectors.js";
|
|
10
|
+
import { disabledConnectors } from "../register-settings.js";
|
|
11
|
+
import { sectionsFor } from "../registry/register-sections.js";
|
|
12
|
+
import { buildPrompt } from "./build-prompt.js";
|
|
13
|
+
// The connector names a session may use: none that is turned off (ADR 0014, 7), and for a subagent only its worker's (ADR 0021, 24).
|
|
14
|
+
function allowedNames(session, connectors, disabled) {
|
|
15
|
+
const names = [...builtinConnectors, ...connectors.map((connector) => connector.name)].filter((name) => !disabled.has(name));
|
|
16
|
+
if (session.parentId === null)
|
|
17
|
+
return new Set(names);
|
|
18
|
+
return new Set(names.filter((name) => name === 'ask' || (name !== 'delegate' && (session.connectors === null || session.connectors.includes(name)))));
|
|
19
|
+
}
|
|
20
|
+
export async function sessionTools(ctx, session) {
|
|
21
|
+
const shell = await shellFor(ctx);
|
|
22
|
+
const connectors = await activeConnectors(ctx);
|
|
23
|
+
const disabled = await disabledConnectors(ctx);
|
|
24
|
+
const allowed = allowedNames(session, connectors, disabled);
|
|
25
|
+
const passed = new Set((session.checks ?? []).filter((check) => check.passed).map((check) => check.name));
|
|
26
|
+
const servers = await mcpServers(ctx);
|
|
27
|
+
const workers = await availableWorkers(ctx, session.checks);
|
|
28
|
+
const descriptions = { ...builtinDescriptions(shell.kind), delegate: delegateIndexDescription(workers), mcp: mcpIndexDescription(servers) };
|
|
29
|
+
const present = { mcp: servers.length > 0, delegate: workers.length > 0 };
|
|
30
|
+
const listed = [
|
|
31
|
+
...builtinConnectors.filter((name) => allowed.has(name) && present[name] !== false).map((name) => ({ name, description: descriptions[name], commands: Object.keys(commandsOf(name)), signatures: builtinSignatures[name] })),
|
|
32
|
+
...connectors
|
|
33
|
+
.filter((connector) => allowed.has(connector.name) && (connector.kind === 'commands' || passed.has(connector.name)))
|
|
34
|
+
.map((connector) => ({ name: connector.name, description: connector.description, commands: connector.commands?.map((command) => command.name) ?? ['exec'] })),
|
|
35
|
+
];
|
|
36
|
+
const built = buildPrompt({
|
|
37
|
+
role: session.parentId === null ? 'lead' : 'worker',
|
|
38
|
+
workspacePath: ctx.job.workspace.path,
|
|
39
|
+
platform: process.platform,
|
|
40
|
+
shell: shell.kind,
|
|
41
|
+
language: z.string().parse(await ctx.settings.get('kernel.language')),
|
|
42
|
+
sections: await sectionsFor(ctx, session.id),
|
|
43
|
+
...(session.worker === null ? {} : { worker: session.worker }),
|
|
44
|
+
connectors: listed,
|
|
45
|
+
});
|
|
46
|
+
for (const section of built.left)
|
|
47
|
+
ctx.log.warn('A section was left out of a prompt past 64 KB of sections.', { owner: section.owner, id: section.id });
|
|
48
|
+
return { built, shell, connectors, listed, disabled };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=session-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-prompt.js","sourceRoot":"","sources":["../../src/prompt/session-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAyB,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAEzG,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAqB,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;AAqBlE,qIAAqI;AACrI,SAAS,YAAY,CAAC,OAAmB,EAAE,UAAmC,EAAE,QAA6B;IAC3G,MA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AAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;KAChK,CAAC;IACF,MAAM,KAAK,GAAG,WAAW,CAAC;QACxB,IAAI,EAAE,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ;QACnD,aAAa,EAAE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI;QACrC,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,KAAK,CAAC,IAAI;QACjB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACrE,QAAQ,EAAE,MAAM,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;QAC5C,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QAC9D,UAAU,EAAE,MAAM;KACnB,CAAC,CAAC;IACH,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,IAAI;QAAE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,4DAA4D,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IACvJ,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Who reads the prompt: the agent of a chat, or the subagent of one of its workers. */
|
|
2
|
+
export type Role = 'lead' | 'worker';
|
|
3
|
+
/** The first line of the prompt: who the agent is, and where it works. */
|
|
4
|
+
export declare function identityLine(role: Role, place: string): string;
|
|
5
|
+
/** The "How you work" block of a role. */
|
|
6
|
+
export declare function workingMethod(role: Role): string;
|
|
7
|
+
//# sourceMappingURL=working-method.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"working-method.d.ts","sourceRoot":"","sources":["../../src/prompt/working-method.ts"],"names":[],"mappings":"AAGA,wFAAwF;AACxF,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,QAAQ,CAAC;AA4CrC,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG9D;AAED,0CAA0C;AAC1C,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEhD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// How the agent works (plan 08 §8.2; ADR 0022, 2 to 4): the lead of a chat decides, plans, executes, and delegates; a
|
|
2
|
+
// worker does the one task it was given. Both end with the same rules, the call-or-final-answer rule last.
|
|
3
|
+
const evidence = 'Decide from evidence: every decision and every claim rests on something you read, ran, or were told. When you report a result, say what you checked and what you didn\'t.';
|
|
4
|
+
const simplest = "Use the simplest practical way that follows the project's conventions and sound engineering practice, and don't add what wasn't asked.";
|
|
5
|
+
const together = 'The calls of one reply run at the same time, so put independent calls (reads, searches, separate files, separate workers) in one reply, and calls that depend on each other in separate replies.';
|
|
6
|
+
const artifacts = 'Show the person anything long to read or see (a plan, a report, a design, an HTML page) in an artifact, not in a reply.';
|
|
7
|
+
const asking = 'To put a question to the person (a choice, a yes or no, a free answer), call `ask`.';
|
|
8
|
+
const checked = "Before you say that something runs or works, check it the way the person would: run it, request its address, or run its test; if you couldn't, say what is unchecked. After you start a server, request its address once before you give it to the person.";
|
|
9
|
+
const short = 'Keep replies short: say what you did and what is left.';
|
|
10
|
+
const callOrFinalAnswer = 'Say what you are about to do in the same reply as the call that does it, and never make a call that does nothing, such as `true`, just to keep going. A reply with no tool call is your final answer and ends the turn: when work remains, your reply must contain the call that does the next piece. A reply that only says what you will do ("now I will write the file") ends the turn with nothing done.';
|
|
11
|
+
const leadMethod = [
|
|
12
|
+
'How you work. You are the one who decides: connectors and workers are how you act, and the result is yours. Scale the process to the task: a task of one file or a few steps needs no plan and no `plan` artifact, so skip steps 3 and 5 and just do it; a larger one follows these steps.',
|
|
13
|
+
"1. Understand. Look for facts before you decide anything: read the request, then the files, config, and tests, and `docs get` where there is a guide. Work out what the person needs, not only what they typed. Never assume or invent names, paths, APIs, or behavior; when you can't find a fact, say so or ask.",
|
|
14
|
+
"2. Clarify. If the request is unclear, contradicts itself or the code, or leaves out something that changes the result, ask: put each question in its own `ask` call, with all the calls in one reply, and use `ask choice` whenever you offer options, your recommended one first. Don't ask what looking would answer.",
|
|
15
|
+
'3. Plan. Write the plan as the artifact `plan`: the goal, the steps in order as a checklist (☐ to do, ☑ done), what each step uses (a connector from the list below, a worker), which steps can run at the same time, and how you will check each one. Plan only with the connectors and workers you have. Write it in the same reply as your first call. For a large, ambiguous, or risky task, call `ask confirm` on the plan before you start.',
|
|
16
|
+
"4. Execute. Work through the steps, running the independent ones together. Make the smallest change for each step, check it with the project's own check or tests, fix a failure at its cause, and tick the step off with `artifact edit`. Write each file in its own call, with `fs write`. If the facts change, change the plan.",
|
|
17
|
+
'5. Delegate. Hand a separate, self-contained part to a worker of the `delegate` connector when a specialist view or parallel work is worth it; its entry lists the workers and what each is for. Several `delegate run` calls in one reply run in parallel. Brief the worker with the goal, the facts it needs, its limits, and what to return. Read what a worker returns and check it before you rely on it: its work is your responsibility.',
|
|
18
|
+
"6. Finish. The work is done when it is ready for production: it does what was asked, it handles the errors and edge cases that will happen, it follows the project's conventions, its checks and tests pass, and nothing unfinished or temporary is left behind.",
|
|
19
|
+
evidence,
|
|
20
|
+
simplest,
|
|
21
|
+
together,
|
|
22
|
+
artifacts,
|
|
23
|
+
asking,
|
|
24
|
+
checked,
|
|
25
|
+
short,
|
|
26
|
+
callOrFinalAnswer,
|
|
27
|
+
].join('\n');
|
|
28
|
+
const workerMethod = [
|
|
29
|
+
"How you work. Do the task you were given and return the result; don't re-plan it or widen it, and ask the person only if you are blocked.",
|
|
30
|
+
"1. Understand. Read the task, then the files, config, and tests it touches. Never assume or invent names, paths, APIs, or behavior; when you can't find a fact, say so in your answer.",
|
|
31
|
+
"2. Do it. Make the smallest change that does the task, check it with the project's own check or tests, and fix a failure at its cause. Write each file in its own call, with `fs write`.",
|
|
32
|
+
'3. Return. Your last reply is the result the lead agent reads: what you did or found, the evidence for it, and what is unchecked or left.',
|
|
33
|
+
evidence,
|
|
34
|
+
simplest,
|
|
35
|
+
together,
|
|
36
|
+
artifacts,
|
|
37
|
+
asking,
|
|
38
|
+
checked,
|
|
39
|
+
callOrFinalAnswer,
|
|
40
|
+
].join('\n');
|
|
41
|
+
/** The first line of the prompt: who the agent is, and where it works. */
|
|
42
|
+
export function identityLine(role, place) {
|
|
43
|
+
if (role === 'lead')
|
|
44
|
+
return `You are kvman Coder, the lead engineer on this work: a software engineer with long, deep experience who owns the outcome. You understand the request, decide, plan, and execute it, ${place}.`;
|
|
45
|
+
return `You are kvman Coder, working on one task that the lead agent gave you, ${place}: a software engineer with long, deep experience.`;
|
|
46
|
+
}
|
|
47
|
+
/** The "How you work" block of a role. */
|
|
48
|
+
export function workingMethod(role) {
|
|
49
|
+
return role === 'lead' ? leadMethod : workerMethod;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=working-method.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"working-method.js","sourceRoot":"","sources":["../../src/prompt/working-method.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,2GAA2G;AAK3G,MAAM,QAAQ,GAAG,2KAA2K,CAAC;AAC7L,MAAM,QAAQ,GAAG,wIAAwI,CAAC;AAC1J,MAAM,QAAQ,GAAG,kMAAkM,CAAC;AACpN,MAAM,SAAS,GAAG,yHAAyH,CAAC;AAC5I,MAAM,MAAM,GA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