@desplega.ai/agent-swarm 1.164.1 → 1.166.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/README.md +1 -1
- package/dist/acp-adapter-yzfxn8vj.js +23 -0
- package/dist/{actions-hp2h32dx.js → actions-qz3m692w.js} +24 -28
- package/dist/{amp-adapter-zfd7djyx.js → amp-adapter-j1xbmsqz.js} +7 -7
- package/dist/{app-w2d26h4f.js → app-43vrdmv8.js} +9 -10
- package/dist/{assistant-45pc4en7.js → assistant-ertffmka.js} +25 -29
- package/dist/{boot-reembed-k1q2s4fc.js → boot-reembed-998jtpdg.js} +12 -15
- package/dist/{boot-reembed-6rhcpsjf.js → boot-reembed-s7k7c6v2.js} +13 -15
- package/dist/boot-scrub-sweep-nepsk4t1.js +211 -0
- package/dist/{boot-seeds-ex93edx7.js → boot-seeds-vvzs1zhk.js} +12 -12
- package/dist/{claude-adapter-hcxd0szm.js → claude-adapter-2zvmekrp.js} +15 -17
- package/dist/{claude-managed-adapter-fz7xps2r.js → claude-managed-adapter-s49wbk8t.js} +5 -5
- package/dist/{claude-managed-setup-xx6f15h9.js → claude-managed-setup-cvhqq8qn.js} +4 -4
- package/dist/{claude-sdk-session-6nb9raem.js → claude-sdk-session-kkbxtw5q.js} +2624 -2606
- package/dist/{cli-etbrt8x1.js → cli-0nhdwxd5.js} +4 -4
- package/dist/{cli-jeefgppq.js → cli-0qjcsxgz.js} +7 -7
- package/dist/{cli-6behs2bt.js → cli-32bca7nr.js} +1 -1
- package/dist/{cli-gt8v96qx.js → cli-3ddybbbx.js} +4 -4
- package/dist/{acp-adapter-rxvek4ym.js → cli-3qn4r334.js} +317 -35
- package/dist/{cli-1d3w4xm3.js → cli-4r1sjfc4.js} +14 -6
- package/dist/{cli-691f2rxm.js → cli-66zh26sp.js} +68 -16
- package/dist/{cli-et8wdyqh.js → cli-68r1j4sg.js} +9 -9
- package/dist/{cli-xb7kyanp.js → cli-8kgvmkak.js} +3 -3
- package/dist/{cli-fdpkw8vk.js → cli-8t229cmr.js} +8 -8
- package/dist/{cli-gc54qc0p.js → cli-aqcey741.js} +1 -1
- package/dist/{cli-4q4cmr4t.js → cli-cpfmqz3n.js} +8 -8
- package/dist/{cli-a9bw0xxt.js → cli-df56tqdw.js} +997 -408
- package/dist/{cli-n7h1kqpf.js → cli-dmtrxqhg.js} +6 -1
- package/dist/{cli-xfb7333f.js → cli-dw2q9f7g.js} +5 -5
- package/dist/{cli-4drstbb9.js → cli-ecknp7p1.js} +81 -23
- package/dist/{cli-v0pvvhfq.js → cli-efnd2kce.js} +36 -1
- package/dist/{cli-1wetf34q.js → cli-f2n17zhp.js} +1 -1
- package/dist/{cli-2c8eky5y.js → cli-feh3dkah.js} +1 -1
- package/dist/cli-fn697bnt.js +126 -0
- package/dist/{cli-v5pr2fgt.js → cli-gt8azyet.js} +3 -3
- package/dist/{cli-dbszf3rw.js → cli-h3x613ze.js} +4 -4
- package/dist/{cli-nwhb8y2e.js → cli-hf5s9pgf.js} +1 -1
- package/dist/cli-j2jbr8af.js +516 -0
- package/dist/{cli-agjzafns.js → cli-jhm6hzjn.js} +593 -10
- package/dist/{cli-j0tmc908.js → cli-jvj6a0cv.js} +484 -477
- package/dist/{cli-xxz89c2n.js → cli-mb75wpxf.js} +1 -1
- package/dist/{cli-07s39g1n.js → cli-mv2520nm.js} +1 -1
- package/dist/{cli-v90vfwyb.js → cli-mwegs4af.js} +5 -5
- package/dist/{cli-bz1gbac9.js → cli-p4ztb80h.js} +2 -2
- package/dist/{cli-1wd1n2ya.js → cli-rfphkzh5.js} +1 -1
- package/dist/{cli-976r1zqx.js → cli-rggdq8wq.js} +5 -5
- package/dist/{cli-3ajw5v5v.js → cli-rsy933yz.js} +6 -6
- package/dist/{cli-yj790e19.js → cli-tadfgd0t.js} +8 -1
- package/dist/{cli-cn53e7vc.js → cli-ttbsse3f.js} +6 -1
- package/dist/{cli-dyqsrqcf.js → cli-v2a8x45d.js} +4 -4
- package/dist/{cli-wbvnn6tk.js → cli-v6vv7dy8.js} +91 -9
- package/dist/{cli-z2ap2c0c.js → cli-vzc73wet.js} +90 -55
- package/dist/cli-wt7ccy4r.js +2654 -0
- package/dist/{cli-4cn19jvn.js → cli-x7kpr72a.js} +3 -3
- package/dist/{cli-003785v9.js → cli-xvc3q9br.js} +1 -1
- package/dist/{cli-v0e7jpr5.js → cli-xvdgasgy.js} +13 -4
- package/dist/{cli-asqeg4ve.js → cli-y59h2pk9.js} +2 -2
- package/dist/{cli-0wn3ypqv.js → cli-yshaazs1.js} +14121 -3478
- package/dist/{cli-wg8yjqtw.js → cli-ysnyhws9.js} +16 -3
- package/dist/cli-zp67qg5x.js +92 -0
- package/dist/{cli-g3qgrzck.js → cli-zsh093hk.js} +71 -3
- package/dist/{cli-ma3zvh39.js → cli-zy7vwsne.js} +6066 -5829
- package/dist/cli.js +79 -26
- package/dist/{codex-adapter-pcxdn10v.js → codex-adapter-dw1wxqt8.js} +10 -10
- package/dist/{codex-hook-b1fb7c2k.js → codex-hook-d2rkvf39.js} +1 -1
- package/dist/{codex-login-059nm145.js → codex-login-terbdsqq.js} +2 -2
- package/dist/{codex-session-runner-xzwwddp8.js → codex-session-runner-3cgb8y1g.js} +10 -10
- package/dist/{commands-98at8mkn.js → commands-mhxam6z2.js} +9 -9
- package/dist/{cursor-adapter-dkg6qnkp.js → cursor-adapter-2qda3st7.js} +6 -6
- package/dist/{db-01g8wtvw.js → db-sjks418k.js} +11 -9
- package/dist/{devin-adapter-qmttt2fz.js → devin-adapter-bffjj5n4.js} +2 -2
- package/dist/{dispatcher-nn2k1wxd.js → dispatcher-1es759rn.js} +22 -26
- package/dist/{dsh-adapter-w4d4vwdq.js → dsh-adapter-bek4cyw9.js} +6 -6
- package/dist/{e2b-9e4g2hvt.js → e2b-nd50eccg.js} +1 -1
- package/dist/{event-bus-z7v2t26e.js → event-bus-vnfthafg.js} +2 -2
- package/dist/grok-adapter-ar9cw9jg.js +29 -0
- package/dist/{handlers-b0kqsbg8.js → handlers-1gkbhktr.js} +25 -29
- package/dist/{hook-sap7v1aj.js → hook-ds2zxq9v.js} +16 -18
- package/dist/{hook-pz50gqep.js → hook-vxa3tcsy.js} +10 -12
- package/dist/{http-ncr8rmd0.js → http-3h21z9md.js} +679 -227
- package/dist/{index-c4aqcyz1.js → index-9b65j1m5.js} +11 -11
- package/dist/{index-r46s01nq.js → index-bn6cy8ps.js} +22 -26
- package/dist/{index-38kqdt3e.js → index-dkfxpkmm.js} +23 -27
- package/dist/{index-630kj5vd.js → index-f8xnqrye.js} +55 -43
- package/dist/{index-fdk1t4d6.js → index-n0rxa4ca.js} +11962 -9900
- package/dist/{index-9nrj7797.js → index-n99fycq7.js} +22 -26
- package/dist/{keepalive-31613r2h.js → keepalive-3xspa9jw.js} +14 -11
- package/dist/{lead-mx59tr5s.js → lead-6qphc124.js} +43 -43
- package/dist/{maintenance-55ff39ca.js → maintenance-0teem1bb.js} +10 -12
- package/dist/{node-f0ykebbv.js → node-9sg7ajby.js} +25 -7
- package/dist/{oauth-refresh-sweep-anma954w.js → oauth-refresh-sweep-sh9q25xp.js} +13 -10
- package/dist/{onboard-b2fy8ftb.js → onboard-54qmnqxe.js} +4 -3
- package/dist/{opencode-adapter-p1s92tmy.js → opencode-adapter-wjfa2wvd.js} +6 -6
- package/dist/{otel-impl-9brvt7xv.js → otel-impl-ycqzp2a1.js} +2 -2
- package/dist/{pi-mono-adapter-kz4rrwvd.js → pi-mono-adapter-e77e9zst.js} +6 -6
- package/dist/{pricing-refresh-7w8mbmva.js → pricing-refresh-atnkngqs.js} +10 -10
- package/dist/{rbac-roles-ejp7qwvb.js → rbac-roles-9pjphh9q.js} +10 -10
- package/dist/{rbac-roles-nhk4r7bc.js → rbac-roles-j78wdksm.js} +10 -10
- package/dist/{render-v2-2gzt8skq.js → render-v2-pxjs49fx.js} +9 -10
- package/dist/{setup-5et8t412.js → setup-ymej0xtx.js} +2 -2
- package/dist/{work-objects-tb0er7qa.js → work-objects-3nh4ymzb.js} +26 -30
- package/dist/{worker-62cv075d.js → worker-qa9fkz5s.js} +43 -43
- package/dist/{x-vbxb31jr.js → x-ma4gnfgy.js} +2 -2
- package/openapi.json +457 -31
- package/package.json +14 -6
- package/plugin/commands/create-pr.md +7 -1
- package/plugin/pi-skills/create-pr/SKILL.md +7 -1
- package/src/agentmail/app.ts +5 -4
- package/src/be/automation-preflight.ts +11 -9
- package/src/be/boot-scrub-sweep.ts +302 -0
- package/src/be/connector-codes.ts +81 -0
- package/src/be/crypto/key-bootstrap.ts +1 -1
- package/src/be/db/approvals.ts +15 -1
- package/src/be/db/codex-oauth-device-flows.ts +40 -0
- package/src/be/db/config-secrets.ts +31 -0
- package/src/be/db/runtime.ts +4 -0
- package/src/be/db/script-runs.ts +15 -0
- package/src/be/db/tasks/write.ts +1 -1
- package/src/be/db-queries/mcp-oauth.ts +5 -0
- package/src/be/db-queries/oauth.ts +77 -0
- package/src/be/db.ts +162 -59
- package/src/be/events.ts +17 -1
- package/src/be/memory/index-content.ts +2 -2
- package/src/be/memory/providers/sqlite-store.ts +63 -11
- package/src/be/memory/types.ts +14 -0
- package/src/be/migrations/197_connector_codes.sql +23 -0
- package/src/be/migrations/198_permission_audit_guest.sql +33 -0
- package/src/be/migrations/200_backfill_auto_memory_expiry.sql +20 -0
- package/src/be/migrations/201_workflow_replay_columns.sql +10 -0
- package/src/be/migrations/202_codex_oauth_device_flows.sql +24 -0
- package/src/be/model-tier-resolution.ts +2 -1
- package/src/be/model-validation.ts +1 -1
- package/src/be/pricing-normalize.ts +3 -0
- package/src/be/rbac-audit.ts +2 -1
- package/src/be/scripts/db.ts +28 -4
- package/src/be/scripts/source-secrets.ts +37 -0
- package/src/be/scripts/typecheck.ts +23 -2
- package/src/be/scrub-json.ts +32 -0
- package/src/be/sealed-json.ts +59 -0
- package/src/be/secret-registry.ts +131 -0
- package/src/be/seed-pricing.ts +14 -0
- package/src/be/users.ts +7 -1
- package/src/be/workflow-replay.ts +77 -0
- package/src/cli.tsx +7 -0
- package/src/commands/provider-credentials.ts +46 -8
- package/src/commands/runner.ts +2 -10
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/github/app.ts +4 -4
- package/src/heartbeat/heartbeat.ts +20 -8
- package/src/hooks/pr-body-guard.ts +1 -1
- package/src/http/agents.ts +1 -0
- package/src/http/approval-requests.ts +1 -0
- package/src/http/apps.ts +3 -0
- package/src/http/auth.ts +4 -1
- package/src/http/codex-oauth-device.ts +8 -10
- package/src/http/codex-oauth-keep-warm.ts +2 -2
- package/src/http/config-values.ts +59 -0
- package/src/http/config.ts +5 -0
- package/src/http/db-query-bounded.ts +3 -0
- package/src/http/db-query-shared.ts +107 -15
- package/src/http/db-query.ts +10 -2
- package/src/http/extensions.ts +1 -0
- package/src/http/index.ts +23 -6
- package/src/http/integrations.ts +1 -38
- package/src/http/ip-rate-limit.ts +82 -0
- package/src/http/kv.ts +38 -4
- package/src/http/mcp-servers.ts +1 -0
- package/src/http/memory.ts +9 -0
- package/src/http/models-catalog.ts +2 -0
- package/src/http/operator-actor.ts +4 -0
- package/src/http/page-proxy.ts +22 -0
- package/src/http/pages.ts +4 -2
- package/src/http/realtime.ts +1 -1
- package/src/http/request-principal.ts +14 -1
- package/src/http/script-connections.ts +8 -0
- package/src/http/script-runs.ts +12 -4
- package/src/http/scripts.ts +15 -0
- package/src/http/session-cost-recompute.ts +3 -2
- package/src/http/tasks.ts +9 -0
- package/src/http/users.ts +226 -0
- package/src/http/workflows.ts +3 -2
- package/src/http.ts +1 -0
- package/src/integrations/kapso/client.ts +3 -1
- package/src/jira/app.ts +2 -2
- package/src/kv-view.ts +324 -0
- package/src/linear/app.ts +2 -2
- package/src/oauth/mcp-wrapper.ts +1 -1
- package/src/prompts/memories.ts +42 -1
- package/src/providers/acp-adapter.ts +85 -24
- package/src/providers/acp-target-catalog.ts +54 -1
- package/src/providers/acp-targets.ts +358 -4
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/cursor-adapter.ts +1 -1
- package/src/providers/grok-adapter.ts +186 -0
- package/src/providers/index.ts +5 -1
- package/src/providers/pricing-sources.md +6 -0
- package/src/providers/reasoning-effort.ts +17 -1
- package/src/providers/types.ts +2 -1
- package/src/rbac/can.ts +4 -3
- package/src/rbac/legacy-policy.ts +3 -3
- package/src/rbac/types.ts +6 -0
- package/src/script-workflows/supervisor.ts +11 -2
- package/src/scripts-runtime/eval-harness.ts +2 -12
- package/src/scripts-runtime/executors/quickjs-bundle.ts +152 -0
- package/src/scripts-runtime/executors/quickjs-prelude.ts +285 -0
- package/src/scripts-runtime/executors/quickjs-runner.ts +580 -0
- package/src/scripts-runtime/executors/quickjs-worker.ts +81 -0
- package/src/scripts-runtime/executors/quickjs.ts +196 -0
- package/src/scripts-runtime/executors/registry.ts +2 -0
- package/src/scripts-runtime/executors/sourcemap.ts +79 -0
- package/src/scripts-runtime/script-error-hints.ts +14 -0
- package/src/scripts-runtime/swarm-sdk.ts +9 -2
- package/src/scripts-runtime/types/stdlib.d.ts +27 -8
- package/src/scripts-runtime/types/swarm-extension.d.ts +3 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +27 -8
- package/src/server-user.ts +2 -20
- package/src/server.ts +3 -1
- package/src/slack/app.ts +4 -0
- package/src/slack/config.ts +3 -1
- package/src/slack/egress-scrub.ts +87 -0
- package/src/tests/acp-adapter.test.ts +191 -2
- package/src/tests/boot-scrub-sweep.test.ts +390 -0
- package/src/tests/budget-user-scope.test.ts +7 -21
- package/src/tests/check-pr-body.test.ts +149 -6
- package/src/tests/check-text-columns.test.ts +145 -0
- package/src/tests/claude-adapter-binary.test.ts +1 -1
- package/src/tests/claude-sdk-process.fixture.ts +13 -2
- package/src/tests/codex-oauth-device.test.ts +23 -37
- package/src/tests/codex-oauth-keep-warm.test.ts +29 -0
- package/src/tests/console-scrub.test.ts +141 -0
- package/src/tests/credential-check.test.ts +90 -0
- package/src/tests/db-query-denylist.test.ts +202 -0
- package/src/tests/db-task-read-contract.test.ts +1 -0
- package/src/tests/db-task-write-contract.test.ts +1 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/entrypoint-acp-target-binary.test.ts +44 -1
- package/src/tests/events-scrub.test.ts +88 -0
- package/src/tests/explicit-model-validation.test.ts +81 -0
- package/src/tests/extensions-pre-task.test.ts +33 -1
- package/src/tests/fixtures/grok/acp-updates-recorded.jsonl +53 -0
- package/src/tests/fixtures/grok/prompt-response-meta.json +36 -0
- package/src/tests/fixtures/secret-corpus.ts +320 -0
- package/src/tests/grok-adapter.test.ts +647 -0
- package/src/tests/heartbeat-checklist.test.ts +44 -0
- package/src/tests/integration-disable-flags.test.ts +156 -0
- package/src/tests/kv-http.test.ts +34 -0
- package/src/tests/kv-tool.test.ts +274 -1
- package/src/tests/kv-view.test.ts +147 -0
- package/src/tests/mcp-user-route.test.ts +257 -15
- package/src/tests/memory-injection-outcome.test.ts +143 -0
- package/src/tests/model-tier-resolution.test.ts +76 -3
- package/src/tests/page-guest-session.test.ts +424 -0
- package/src/tests/page-proxy.test.ts +1 -1
- package/src/tests/page-viewer-auth.test.ts +22 -1
- package/src/tests/pr-body-leaks.test.ts +157 -2
- package/src/tests/preload.ts +10 -0
- package/src/tests/provider-registration.test.ts +3 -1
- package/src/tests/rbac-audit.test.ts +32 -0
- package/src/tests/rbac-mcp-admission-e2e.test.ts +4 -62
- package/src/tests/script-connections.test.ts +9 -0
- package/src/tests/script-executor-conformance.test.ts +3 -0
- package/src/tests/script-executor-quickjs.test.ts +442 -0
- package/src/tests/script-executor-registry.test.ts +6 -1
- package/src/tests/script-runs-http.test.ts +126 -1
- package/src/tests/script-runs-scrub.test.ts +275 -0
- package/src/tests/scripts-http.test.ts +82 -1
- package/src/tests/scripts-mcp-e2e.test.ts +42 -6
- package/src/tests/scripts-runtime.test.ts +37 -0
- package/src/tests/scrubbed-text-12e.test.ts +289 -0
- package/src/tests/sealed-key-guard.test.ts +166 -0
- package/src/tests/secret-canary-sweep.test.ts +958 -0
- package/src/tests/secret-registry.test.ts +355 -0
- package/src/tests/secret-rules.test.ts +230 -0
- package/src/tests/secret-scrubber.test.ts +317 -1
- package/src/tests/session-costs-golden.test.ts +17 -0
- package/src/tests/slack-egress-scrub.test.ts +216 -0
- package/src/tests/swarm-tool-result-gate.test.ts +143 -30
- package/src/tests/task-tools-ctx.test.ts +3 -0
- package/src/tests/user-token-routes.test.ts +342 -3
- package/src/tests/workflow-replay.test.ts +518 -0
- package/src/tests/workflow-scrub.test.ts +242 -0
- package/src/tests/workflow-system-one-decision-providers.test.ts +737 -0
- package/src/tools/db-query.ts +1 -1
- package/src/tools/inject-learning.ts +1 -1
- package/src/tools/kv/kv-get.ts +136 -6
- package/src/tools/send-task.ts +61 -17
- package/src/tools/utils.ts +186 -43
- package/src/tools/workflows/get-workflow-run.ts +3 -2
- package/src/types.ts +16 -1
- package/src/utils/console-scrub-install.ts +5 -0
- package/src/utils/console-scrub.ts +57 -0
- package/src/utils/credentials.ts +8 -0
- package/src/utils/page-session.ts +6 -2
- package/src/utils/pr-body-leaks.ts +149 -10
- package/src/utils/request-auth-context.ts +2 -0
- package/src/utils/secret-rules.generated.ts +2055 -0
- package/src/utils/secret-scrubber.ts +662 -36
- package/src/workflows/engine.ts +39 -4
- package/src/workflows/executors/notify.ts +6 -1
- package/src/workflows/executors/system-one-decision.ts +31 -12
- package/src/workflows/executors/system-one-openai-wire.ts +168 -0
- package/src/workflows/executors/system-one-providers.ts +112 -11
- package/src/workflows/executors/system-one-wire.ts +79 -0
- package/src/workflows/recovery.ts +10 -1
- package/src/workflows/resume.ts +62 -3
- package/src/workflows/retry-poller.ts +3 -0
- package/templates/ai-toolbox.manifest.json +2 -2
- package/templates/skills/agent-browser/SKILL.md +5 -5
- package/templates/skills/agent-browser/config.json +1 -1
- package/templates/skills/agent-browser/content.md +4 -4
- package/templates/skills/artifacts/content.md +17 -7
- package/templates/skills/jira-interaction/config.json +1 -1
- package/templates/skills/jira-interaction/content.md +56 -205
- package/templates/skills/linear-interaction/config.json +1 -1
- package/templates/skills/linear-interaction/content.md +31 -50
- package/templates/skills/pages/content.md +8 -4
- package/templates/skills/qa/content.md +2 -2
- package/templates/skills/workflow-iterate/content.md +4 -4
- package/tsconfig.json +3 -3
- package/dist/boot-scrub-logs-t8xg7wd7.js +0 -99
- package/dist/cli-0a7r5331.js +0 -168
- package/dist/cli-93rxw9yd.js +0 -951
- package/dist/cli-cvk6yzw5.js +0 -40
- package/dist/cli-dgnj0zcc.js +0 -40
- package/dist/cli-qt5wzq6v.js +0 -256
- package/dist/cli-v7fqehqd.js +0 -9281
- package/dist/cli-vbr859rz.js +0 -572
- package/src/be/boot-scrub-logs.ts +0 -132
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { QuickJSWorkerMessage, QuickJSWorkerRequest } from "./quickjs-worker";
|
|
2
|
+
import type { ExecutorInput, ExecutorOutput, ScriptExecutor, ScriptExecutorError } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Opt-in executor (`SCRIPT_EXECUTOR=quickjs`) that evaluates scripts in
|
|
6
|
+
* QuickJS compiled to WASM, inside a small pool of worker threads. There is
|
|
7
|
+
* no process spawn per run, so a short script costs about a millisecond
|
|
8
|
+
* instead of the native floor (~10 ms on Linux, ~35 ms on macOS).
|
|
9
|
+
*
|
|
10
|
+
* The sandbox has no filesystem, no process APIs, and no network except the
|
|
11
|
+
* host calls that the quickjs runner exposes (ctx.swarm, ctx.api, ctx.mcp,
|
|
12
|
+
* fetch). Every value crosses as JSON. See quickjs-runner.ts for the limits.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// Each worker keeps one QuickJS WASM module (~25 ms to load) and runs one job
|
|
16
|
+
// at a time. Jobs beyond the pool size wait in a queue.
|
|
17
|
+
const POOL_SIZE = 4;
|
|
18
|
+
// The worker enforces the wall clock itself. This margin only catches a
|
|
19
|
+
// worker that stopped answering, for example a host call that never settles.
|
|
20
|
+
const UNRESPONSIVE_GRACE_MS = 5_000;
|
|
21
|
+
// A worker's WASM memory keeps the peak of its largest job (up to memoryMb).
|
|
22
|
+
// Recycle a worker that grew past this, so idle workers stay small.
|
|
23
|
+
const RECYCLE_WASM_HEAP_BYTES = 64 * 1024 * 1024;
|
|
24
|
+
|
|
25
|
+
type Slot = { worker: Worker; ready: Promise<void>; busy: boolean };
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* In the compiled API binary every module's `import.meta.url` is the binary
|
|
29
|
+
* itself, and the extra worker entrypoint lives at its path relative to the
|
|
30
|
+
* entrypoints' common root (`src/`). See the Dockerfile compile step.
|
|
31
|
+
*/
|
|
32
|
+
function workerSpecifier(): string {
|
|
33
|
+
if (import.meta.url.includes("/$bunfs/")) return "./scripts-runtime/executors/quickjs-worker.ts";
|
|
34
|
+
return new URL("./quickjs-worker.ts", import.meta.url).href;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function emptyOutput(error: ScriptExecutorError, stderr = ""): ExecutorOutput {
|
|
38
|
+
return {
|
|
39
|
+
result: undefined,
|
|
40
|
+
stdout: "",
|
|
41
|
+
stderr,
|
|
42
|
+
truncated: { stdout: false, stderr: false },
|
|
43
|
+
durationMs: 0,
|
|
44
|
+
exitCode: 1,
|
|
45
|
+
error,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class QuickJSWorkerPool {
|
|
50
|
+
private readonly slots: Slot[] = [];
|
|
51
|
+
private readonly waiters: Array<(slot: Slot) => void> = [];
|
|
52
|
+
|
|
53
|
+
constructor(private readonly size: number) {}
|
|
54
|
+
|
|
55
|
+
private spawn(): Slot {
|
|
56
|
+
const worker = new Worker(workerSpecifier());
|
|
57
|
+
// Idle workers must not keep the API process (or a test run) alive.
|
|
58
|
+
(worker as Worker & { unref?: () => void }).unref?.();
|
|
59
|
+
const ready = new Promise<void>((resolve, reject) => {
|
|
60
|
+
const onMessage = (event: MessageEvent<QuickJSWorkerMessage>) => {
|
|
61
|
+
if (event.data.type === "ready") resolve();
|
|
62
|
+
else if (event.data.type === "fatal" && event.data.id === undefined) {
|
|
63
|
+
reject(new Error(event.data.message));
|
|
64
|
+
} else return;
|
|
65
|
+
worker.removeEventListener("message", onMessage);
|
|
66
|
+
};
|
|
67
|
+
worker.addEventListener("message", onMessage);
|
|
68
|
+
worker.addEventListener("error", (event) => reject(new Error(event.message)), { once: true });
|
|
69
|
+
});
|
|
70
|
+
// A failed boot is reported to the job that waits on `ready`.
|
|
71
|
+
ready.catch(() => {});
|
|
72
|
+
const slot: Slot = { worker, ready, busy: true };
|
|
73
|
+
this.slots.push(slot);
|
|
74
|
+
return slot;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
acquire(): Promise<Slot> {
|
|
78
|
+
const idle = this.slots.find((slot) => !slot.busy);
|
|
79
|
+
if (idle) {
|
|
80
|
+
idle.busy = true;
|
|
81
|
+
return Promise.resolve(idle);
|
|
82
|
+
}
|
|
83
|
+
if (this.slots.length < this.size) return Promise.resolve(this.spawn());
|
|
84
|
+
return new Promise((resolve) => this.waiters.push(resolve));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
release(slot: Slot): void {
|
|
88
|
+
const waiter = this.waiters.shift();
|
|
89
|
+
if (waiter) waiter(slot);
|
|
90
|
+
else slot.busy = false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Terminate a worker that is in an unknown state and hand its place to a waiter. */
|
|
94
|
+
get workerCount(): number {
|
|
95
|
+
return this.slots.length;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
discard(slot: Slot): void {
|
|
99
|
+
slot.worker.terminate();
|
|
100
|
+
const index = this.slots.indexOf(slot);
|
|
101
|
+
if (index !== -1) this.slots.splice(index, 1);
|
|
102
|
+
const waiter = this.waiters.shift();
|
|
103
|
+
if (waiter) waiter(this.spawn());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let sharedPool: QuickJSWorkerPool | undefined;
|
|
108
|
+
|
|
109
|
+
/** Number of live workers in the shared pool. For tests and diagnostics. */
|
|
110
|
+
export function quickJSWorkerCount(): number {
|
|
111
|
+
return sharedPool?.workerCount ?? 0;
|
|
112
|
+
}
|
|
113
|
+
let requestSeq = 0;
|
|
114
|
+
|
|
115
|
+
export class QuickJSScriptExecutor implements ScriptExecutor {
|
|
116
|
+
readonly name = "quickjs";
|
|
117
|
+
|
|
118
|
+
async run(input: ExecutorInput): Promise<ExecutorOutput> {
|
|
119
|
+
if (input.fsMode === "workspace-rw") {
|
|
120
|
+
return emptyOutput("executor_error", "workspace-rw not supported by quickjs executor");
|
|
121
|
+
}
|
|
122
|
+
if (input.signal?.aborted) return emptyOutput("killed");
|
|
123
|
+
|
|
124
|
+
sharedPool ??= new QuickJSWorkerPool(POOL_SIZE);
|
|
125
|
+
const pool = sharedPool;
|
|
126
|
+
const slot = await pool.acquire();
|
|
127
|
+
if (input.signal?.aborted) {
|
|
128
|
+
pool.release(slot);
|
|
129
|
+
return emptyOutput("killed");
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
await slot.ready;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
pool.discard(slot);
|
|
135
|
+
return emptyOutput(
|
|
136
|
+
"executor_error",
|
|
137
|
+
`quickjs worker failed to start: ${error instanceof Error ? error.message : String(error)}`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const id = ++requestSeq;
|
|
142
|
+
const start = performance.now();
|
|
143
|
+
return await new Promise<ExecutorOutput>((resolve) => {
|
|
144
|
+
let settled = false;
|
|
145
|
+
const settle = (output: ExecutorOutput, healthy: boolean) => {
|
|
146
|
+
if (settled) return;
|
|
147
|
+
settled = true;
|
|
148
|
+
clearTimeout(watchdog);
|
|
149
|
+
slot.worker.removeEventListener("message", onMessage);
|
|
150
|
+
slot.worker.removeEventListener("error", onError);
|
|
151
|
+
input.signal?.removeEventListener("abort", onAbort);
|
|
152
|
+
if (healthy) pool.release(slot);
|
|
153
|
+
else pool.discard(slot);
|
|
154
|
+
resolve(output);
|
|
155
|
+
};
|
|
156
|
+
const elapsed = () => Math.round(performance.now() - start);
|
|
157
|
+
const onMessage = (event: MessageEvent<QuickJSWorkerMessage>) => {
|
|
158
|
+
const message = event.data;
|
|
159
|
+
if (message.type === "result" && message.id === id) {
|
|
160
|
+
// Reuse the worker only if every host call settled and its memory stayed small.
|
|
161
|
+
const reusable =
|
|
162
|
+
message.leakedHostCalls === 0 &&
|
|
163
|
+
(message.wasmHeapBytes ?? 0) <= RECYCLE_WASM_HEAP_BYTES;
|
|
164
|
+
settle(message.output, reusable);
|
|
165
|
+
} else if (message.type === "fatal" && message.id === id) {
|
|
166
|
+
settle(
|
|
167
|
+
{ ...emptyOutput("executor_error", message.message), durationMs: elapsed() },
|
|
168
|
+
false,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const onError = (event: ErrorEvent) => {
|
|
173
|
+
settle({ ...emptyOutput("executor_error", event.message), durationMs: elapsed() }, false);
|
|
174
|
+
};
|
|
175
|
+
// Terminating the worker is the hard kill: it also stops a busy loop.
|
|
176
|
+
const onAbort = () => settle({ ...emptyOutput("killed"), durationMs: elapsed() }, false);
|
|
177
|
+
const watchdog = setTimeout(
|
|
178
|
+
() => settle({ ...emptyOutput("timeout"), exitCode: 124, durationMs: elapsed() }, false),
|
|
179
|
+
input.resources.wallClockMs + UNRESPONSIVE_GRACE_MS,
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
slot.worker.addEventListener("message", onMessage);
|
|
183
|
+
slot.worker.addEventListener("error", onError);
|
|
184
|
+
input.signal?.addEventListener("abort", onAbort, { once: true });
|
|
185
|
+
slot.worker.postMessage({
|
|
186
|
+
id,
|
|
187
|
+
job: {
|
|
188
|
+
source: input.source,
|
|
189
|
+
args: input.args,
|
|
190
|
+
configPayload: input.configPayload,
|
|
191
|
+
resources: input.resources,
|
|
192
|
+
},
|
|
193
|
+
} satisfies QuickJSWorkerRequest);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { NativeScriptExecutor } from "./native";
|
|
2
|
+
import { QuickJSScriptExecutor } from "./quickjs";
|
|
2
3
|
import type { ScriptExecutor } from "./types";
|
|
3
4
|
|
|
4
5
|
const EXECUTORS: Record<string, () => ScriptExecutor> = {
|
|
5
6
|
native: () => new NativeScriptExecutor(),
|
|
7
|
+
quickjs: () => new QuickJSScriptExecutor(),
|
|
6
8
|
};
|
|
7
9
|
|
|
8
10
|
export function getScriptExecutor(name = process.env.SCRIPT_EXECUTOR ?? "native"): ScriptExecutor {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal source map v3 reader for the quickjs executor. It maps a
|
|
3
|
+
* generated (line, column) back to the original source position so runtime
|
|
4
|
+
* errors point at the user's TypeScript, not at the bundled JavaScript.
|
|
5
|
+
*
|
|
6
|
+
* Lines and columns are 1-based on input and output, to match stack frames.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
type Segment = { genColumn: number; source: number; line: number; column: number };
|
|
10
|
+
|
|
11
|
+
export type OriginalPosition = { source: string; line: number; column: number };
|
|
12
|
+
|
|
13
|
+
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
14
|
+
const BASE64_INDEX = new Map([...BASE64].map((char, index) => [char, index]));
|
|
15
|
+
|
|
16
|
+
function decodeVlq(segment: string): number[] {
|
|
17
|
+
const values: number[] = [];
|
|
18
|
+
let value = 0;
|
|
19
|
+
let shift = 0;
|
|
20
|
+
for (const char of segment) {
|
|
21
|
+
const digit = BASE64_INDEX.get(char);
|
|
22
|
+
if (digit === undefined) throw new Error(`invalid source map VLQ character: ${char}`);
|
|
23
|
+
value += (digit & 31) << shift;
|
|
24
|
+
if (digit & 32) {
|
|
25
|
+
shift += 5;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const negative = value & 1;
|
|
29
|
+
value >>>= 1;
|
|
30
|
+
values.push(negative ? -value : value);
|
|
31
|
+
value = 0;
|
|
32
|
+
shift = 0;
|
|
33
|
+
}
|
|
34
|
+
return values;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class SourceMapReader {
|
|
38
|
+
private readonly sources: string[];
|
|
39
|
+
private readonly lines: Segment[][];
|
|
40
|
+
|
|
41
|
+
constructor(map: { sources: string[]; mappings: string }) {
|
|
42
|
+
this.sources = map.sources;
|
|
43
|
+
this.lines = [];
|
|
44
|
+
let source = 0;
|
|
45
|
+
let line = 0;
|
|
46
|
+
let column = 0;
|
|
47
|
+
for (const generatedLine of map.mappings.split(";")) {
|
|
48
|
+
const segments: Segment[] = [];
|
|
49
|
+
let genColumn = 0;
|
|
50
|
+
for (const raw of generatedLine.split(",")) {
|
|
51
|
+
if (!raw) continue;
|
|
52
|
+
const fields = decodeVlq(raw);
|
|
53
|
+
genColumn += fields[0] ?? 0;
|
|
54
|
+
if (fields.length < 4) continue;
|
|
55
|
+
source += fields[1] ?? 0;
|
|
56
|
+
line += fields[2] ?? 0;
|
|
57
|
+
column += fields[3] ?? 0;
|
|
58
|
+
segments.push({ genColumn, source, line, column });
|
|
59
|
+
}
|
|
60
|
+
this.lines.push(segments);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Look up the closest mapping at or before (line, column) on that line. */
|
|
65
|
+
originalPositionFor(line: number, column: number): OriginalPosition | undefined {
|
|
66
|
+
const segments = this.lines[line - 1];
|
|
67
|
+
if (!segments || segments.length === 0) return undefined;
|
|
68
|
+
let match: Segment | undefined;
|
|
69
|
+
for (const segment of segments) {
|
|
70
|
+
if (segment.genColumn > column - 1) break;
|
|
71
|
+
match = segment;
|
|
72
|
+
}
|
|
73
|
+
match ??= segments[0];
|
|
74
|
+
if (!match) return undefined;
|
|
75
|
+
const source = this.sources[match.source];
|
|
76
|
+
if (source === undefined) return undefined;
|
|
77
|
+
return { source, line: match.line + 1, column: match.column + 1 };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Matches runtime errors that look like a swapped/misused (args, ctx) signature,
|
|
2
|
+
// e.g. destructuring `ctx.api`/`ctx.kv`/`ctx.fetchJson`/`ctx.log` off `undefined`/`null`
|
|
3
|
+
// because the script read them off `args` instead.
|
|
4
|
+
const CTX_UNDEFINED_ACCESS_RE = /cannot read propert(?:y|ies)(?: .*)? of (?:undefined|null)/i;
|
|
5
|
+
const CTX_MEMBER_RE = /\b(api|kv|fetchJson|log)\b/i;
|
|
6
|
+
const CTX_SIGNATURE_HINT =
|
|
7
|
+
"Hint: swarm scripts export default async function (args, ctx) — args comes first, ctx second.";
|
|
8
|
+
|
|
9
|
+
/** Shared by every script executor so structured errors carry the same hint. */
|
|
10
|
+
export function ctxSignatureHintFor(message: string): string | undefined {
|
|
11
|
+
return CTX_UNDEFINED_ACCESS_RE.test(message) && CTX_MEMBER_RE.test(message)
|
|
12
|
+
? CTX_SIGNATURE_HINT
|
|
13
|
+
: undefined;
|
|
14
|
+
}
|
|
@@ -138,8 +138,15 @@ function bridgeRequestFor(name: string, args: unknown): BridgeRequest | null {
|
|
|
138
138
|
|
|
139
139
|
// ── kv ──
|
|
140
140
|
case "kv_get":
|
|
141
|
-
case "kv_getOrNull":
|
|
142
|
-
|
|
141
|
+
case "kv_getOrNull": {
|
|
142
|
+
// Optional targeted read: dot path into a JSON value + offset/limit page.
|
|
143
|
+
const view = new URLSearchParams();
|
|
144
|
+
if (typeof body.path === "string") view.set("path", body.path);
|
|
145
|
+
if (typeof body.offset === "number") view.set("offset", String(body.offset));
|
|
146
|
+
if (typeof body.limit === "number") view.set("limit", String(body.limit));
|
|
147
|
+
const qs = view.toString();
|
|
148
|
+
return { method: "GET", path: qs ? `${kvPath(body)}?${qs}` : kvPath(body) };
|
|
149
|
+
}
|
|
143
150
|
case "kv_set":
|
|
144
151
|
return {
|
|
145
152
|
method: "PUT",
|
|
@@ -104,6 +104,26 @@ declare module "swarm-sdk" {
|
|
|
104
104
|
expiresAt: number | null;
|
|
105
105
|
createdAt: number;
|
|
106
106
|
updatedAt: number;
|
|
107
|
+
/** Present only on a path/offset/limit read. */
|
|
108
|
+
view?: KvView;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface KvViewArgs {
|
|
112
|
+
/** Dot path into the JSON value, e.g. "outcome.data.rows" or "rows.3". */
|
|
113
|
+
path?: string;
|
|
114
|
+
/** First array item / object key / string char. Default 0. */
|
|
115
|
+
offset?: number;
|
|
116
|
+
/** Max items / keys / chars. Unbounded in scripts. */
|
|
117
|
+
limit?: number;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface KvView {
|
|
121
|
+
path: string;
|
|
122
|
+
type: "object" | "array" | "string" | "number" | "boolean" | "null";
|
|
123
|
+
total?: number;
|
|
124
|
+
offset?: number;
|
|
125
|
+
returned?: number;
|
|
126
|
+
nextOffset?: number | null;
|
|
107
127
|
}
|
|
108
128
|
|
|
109
129
|
export interface KvSdkSuccess<T, TStatus extends number = 200> {
|
|
@@ -194,14 +214,13 @@ declare module "swarm-sdk" {
|
|
|
194
214
|
}): Promise<unknown>;
|
|
195
215
|
task_poll(args?: Record<string, unknown>): Promise<unknown>;
|
|
196
216
|
// --- kv ---
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
namespace?: string
|
|
200
|
-
|
|
201
|
-
kv_getOrNull<T = unknown>(
|
|
202
|
-
key: string;
|
|
203
|
-
|
|
204
|
-
}): Promise<KvEntry<T> | null>;
|
|
217
|
+
/** path/offset/limit return a view: `value` is the slice at a dot path (JSON strings count as JSON), paged over items/keys/chars; `view` describes it. */
|
|
218
|
+
kv_get<T = unknown>(
|
|
219
|
+
args: { key: string; namespace?: string } & KvViewArgs,
|
|
220
|
+
): Promise<KvSdkResponse<KvEntry<T>>>;
|
|
221
|
+
kv_getOrNull<T = unknown>(
|
|
222
|
+
args: { key: string; namespace?: string } & KvViewArgs,
|
|
223
|
+
): Promise<KvEntry<T> | null>;
|
|
205
224
|
kv_set<T>(
|
|
206
225
|
args: KvSetArgsBase & { value: T; valueType?: "json" },
|
|
207
226
|
): Promise<KvSdkResponse<KvEntry<T>>>;
|
|
@@ -93,6 +93,7 @@ declare module "swarm-extension" {
|
|
|
93
93
|
| "dsh"
|
|
94
94
|
| "amp"
|
|
95
95
|
| "cursor"
|
|
96
|
+
| "grok"
|
|
96
97
|
| undefined;
|
|
97
98
|
leadOnly?: boolean | undefined;
|
|
98
99
|
}
|
|
@@ -221,6 +222,7 @@ declare module "swarm-extension" {
|
|
|
221
222
|
| "dsh"
|
|
222
223
|
| "amp"
|
|
223
224
|
| "cursor"
|
|
225
|
+
| "grok"
|
|
224
226
|
| undefined;
|
|
225
227
|
providerMeta?: Record<string, unknown> | undefined;
|
|
226
228
|
harnessVariant?: string | undefined;
|
|
@@ -242,6 +244,7 @@ declare module "swarm-extension" {
|
|
|
242
244
|
| "dsh"
|
|
243
245
|
| "amp"
|
|
244
246
|
| "cursor"
|
|
247
|
+
| "grok"
|
|
245
248
|
| undefined;
|
|
246
249
|
leadOnly?: boolean | undefined;
|
|
247
250
|
}
|
|
@@ -86,6 +86,26 @@ declare module "swarm-sdk" {
|
|
|
86
86
|
expiresAt: number | null;
|
|
87
87
|
createdAt: number;
|
|
88
88
|
updatedAt: number;
|
|
89
|
+
/** Present only on a path/offset/limit read. */
|
|
90
|
+
view?: KvView;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface KvViewArgs {
|
|
94
|
+
/** Dot path into the JSON value, e.g. "outcome.data.rows" or "rows.3". */
|
|
95
|
+
path?: string;
|
|
96
|
+
/** First array item / object key / string char. Default 0. */
|
|
97
|
+
offset?: number;
|
|
98
|
+
/** Max items / keys / chars. Unbounded in scripts. */
|
|
99
|
+
limit?: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface KvView {
|
|
103
|
+
path: string;
|
|
104
|
+
type: "object" | "array" | "string" | "number" | "boolean" | "null";
|
|
105
|
+
total?: number;
|
|
106
|
+
offset?: number;
|
|
107
|
+
returned?: number;
|
|
108
|
+
nextOffset?: number | null;
|
|
89
109
|
}
|
|
90
110
|
|
|
91
111
|
export interface KvSdkSuccess<T, TStatus extends number = 200> {
|
|
@@ -176,14 +196,13 @@ declare module "swarm-sdk" {
|
|
|
176
196
|
}): Promise<unknown>;
|
|
177
197
|
task_poll(args?: Record<string, unknown>): Promise<unknown>;
|
|
178
198
|
// --- kv ---
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
namespace?: string
|
|
182
|
-
|
|
183
|
-
kv_getOrNull<T = unknown>(
|
|
184
|
-
key: string;
|
|
185
|
-
|
|
186
|
-
}): Promise<KvEntry<T> | null>;
|
|
199
|
+
/** path/offset/limit return a view: `value` is the slice at a dot path (JSON strings count as JSON), paged over items/keys/chars; `view` describes it. */
|
|
200
|
+
kv_get<T = unknown>(
|
|
201
|
+
args: { key: string; namespace?: string } & KvViewArgs,
|
|
202
|
+
): Promise<KvSdkResponse<KvEntry<T>>>;
|
|
203
|
+
kv_getOrNull<T = unknown>(
|
|
204
|
+
args: { key: string; namespace?: string } & KvViewArgs,
|
|
205
|
+
): Promise<KvEntry<T> | null>;
|
|
187
206
|
kv_set<T>(
|
|
188
207
|
args: KvSetArgsBase & { value: T; valueType?: "json" },
|
|
189
208
|
): Promise<KvSdkResponse<KvEntry<T>>>;
|
package/src/server-user.ts
CHANGED
|
@@ -27,11 +27,6 @@ import {
|
|
|
27
27
|
steerTaskOutputSchema,
|
|
28
28
|
steerTaskUserInputSchema,
|
|
29
29
|
} from "./tools/steer-task";
|
|
30
|
-
import {
|
|
31
|
-
taskActionHandler,
|
|
32
|
-
taskActionInputSchema,
|
|
33
|
-
taskActionOutputSchema,
|
|
34
|
-
} from "./tools/task-action";
|
|
35
30
|
import { userCtx } from "./tools/task-tool-ctx";
|
|
36
31
|
import { createToolRegistrar, type SwarmToolResult, toolErr } from "./tools/utils";
|
|
37
32
|
import { ModelTierSchema, type User } from "./types";
|
|
@@ -121,7 +116,7 @@ export function createUserServer(user: User): McpServer {
|
|
|
121
116
|
title: "Send a task",
|
|
122
117
|
annotations: { destructiveHint: false },
|
|
123
118
|
rbac: permission("task.create.own"),
|
|
124
|
-
description: "
|
|
119
|
+
description: "Sends a task from the authenticated user to the online Lead.",
|
|
125
120
|
inputSchema: userSendTaskInputSchema,
|
|
126
121
|
outputSchema: sendTaskOutputSchema,
|
|
127
122
|
};
|
|
@@ -129,11 +124,11 @@ export function createUserServer(user: User): McpServer {
|
|
|
129
124
|
const denied = await maybeDenyUserToolAdmission(user, "send-task", sendTaskConfig);
|
|
130
125
|
if (denied) return denied;
|
|
131
126
|
return sendTaskHandler(userCtx(user, info.sessionId), {
|
|
127
|
+
...args,
|
|
132
128
|
offerMode: false,
|
|
133
129
|
leadOnly: false,
|
|
134
130
|
allowDuplicate: false,
|
|
135
131
|
overrideSlackContext: false,
|
|
136
|
-
...args,
|
|
137
132
|
});
|
|
138
133
|
});
|
|
139
134
|
|
|
@@ -193,18 +188,5 @@ export function createUserServer(user: User): McpServer {
|
|
|
193
188
|
});
|
|
194
189
|
}
|
|
195
190
|
|
|
196
|
-
const taskActionConfig = {
|
|
197
|
-
title: "Task Pool Action",
|
|
198
|
-
description: "Move one of your tasks to or from backlog.",
|
|
199
|
-
rbac: permission("task.action.own"),
|
|
200
|
-
inputSchema: taskActionInputSchema,
|
|
201
|
-
outputSchema: taskActionOutputSchema,
|
|
202
|
-
};
|
|
203
|
-
registerTool("task-action", taskActionConfig, async (args, info, _meta) => {
|
|
204
|
-
const denied = await maybeDenyUserToolAdmission(user, "task-action", taskActionConfig);
|
|
205
|
-
if (denied) return denied;
|
|
206
|
-
return taskActionHandler(userCtx(user, info.sessionId), args);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
191
|
return server;
|
|
210
192
|
}
|
package/src/server.ts
CHANGED
|
@@ -392,7 +392,9 @@ export async function createServer(
|
|
|
392
392
|
registerResolveUserTool(server);
|
|
393
393
|
registerManageUserTool(server); // self-guards with lead check
|
|
394
394
|
|
|
395
|
-
// Debug tools
|
|
395
|
+
// Debug tools. Neither has a lead check: both are open to every
|
|
396
|
+
// authenticated agent. db-query refuses credential tables and its results
|
|
397
|
+
// are scrubbed; get-oauth-access-token returns tokens by design.
|
|
396
398
|
registerDbQueryTool(server);
|
|
397
399
|
registerGetOauthAccessTokenTool(server);
|
|
398
400
|
|
package/src/slack/app.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { App, LogLevel, SocketModeReceiver } from "@slack/bolt";
|
|
|
2
2
|
import { emitBuiltInIntegrationConnectedOnce, ensureSlackRenderV2Activation } from "../be/db";
|
|
3
3
|
import { getSlackConfiguration } from "./config";
|
|
4
4
|
import { type SlackConnectionState, setSlackConnectionState } from "./connection-state";
|
|
5
|
+
import { installSlackEgressScrub } from "./egress-scrub";
|
|
5
6
|
import { getSlackSocketModeBlockReason, SLACK_DEV_SOCKET_MODE_OPT_IN } from "./socket-mode-guard";
|
|
6
7
|
import { startTaskWatcher, stopTaskWatcher } from "./watcher";
|
|
7
8
|
|
|
@@ -76,6 +77,9 @@ export async function initSlackApp(): Promise<App | null> {
|
|
|
76
77
|
return null;
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
// Every client Bolt builds from here on scrubs outbound text.
|
|
81
|
+
installSlackEgressScrub();
|
|
82
|
+
|
|
79
83
|
// SLACK_API_URL points Bolt (Web API and apps.connections.open) at a mock Slack server for e2e tests.
|
|
80
84
|
const slackApiUrl = process.env.SLACK_API_URL;
|
|
81
85
|
const clientOptions = slackApiUrl ? { slackApiUrl } : undefined;
|
package/src/slack/config.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isEnvFlagEnabled } from "../utils/env-flag";
|
|
2
|
+
|
|
1
3
|
export const SLACK_MODES = ["socket", "http"] as const;
|
|
2
4
|
export type SlackMode = (typeof SLACK_MODES)[number];
|
|
3
5
|
|
|
@@ -17,7 +19,7 @@ export function getSlackConfiguration(env: NodeJS.ProcessEnv = process.env): Sla
|
|
|
17
19
|
if (mode === "http") missingCredentials.push("SLACK_SIGNING_SECRET");
|
|
18
20
|
|
|
19
21
|
return {
|
|
20
|
-
disabled:
|
|
22
|
+
disabled: isEnvFlagEnabled("SLACK_DISABLE", false, env),
|
|
21
23
|
mode,
|
|
22
24
|
missingCredentials: missingCredentials.filter((key) => !env[key]?.trim()),
|
|
23
25
|
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { webApi } from "@slack/bolt";
|
|
2
|
+
import { scrubObject, scrubSecrets } from "../utils/secret-scrubber";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Client-level secret scrub for every outbound Slack write.
|
|
6
|
+
*
|
|
7
|
+
* There is no shared Slack send function: tools, the watcher, the thread
|
|
8
|
+
* buffer and Bolt listeners each call `client.chat.*` directly. So the scrub
|
|
9
|
+
* sits on `WebClient` itself. `@slack/web-api` binds every method to
|
|
10
|
+
* `this.apiCall` at construction, so an instance-level override would be a
|
|
11
|
+
* no-op; patching the prototype before any client is built covers Bolt's
|
|
12
|
+
* `app.client` and the per-request clients it hands to listeners.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** Methods whose arguments carry user-visible text. */
|
|
16
|
+
const WRITE_METHODS = new Set([
|
|
17
|
+
"chat.postMessage",
|
|
18
|
+
"chat.postEphemeral",
|
|
19
|
+
"chat.update",
|
|
20
|
+
"chat.scheduleMessage",
|
|
21
|
+
"chat.meMessage",
|
|
22
|
+
"files.completeUploadExternal",
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
/** Argument fields that may carry free text (strings, Block Kit, JSON strings). */
|
|
26
|
+
const TEXT_FIELDS = ["text", "blocks", "attachments", "initial_comment", "title", "files"] as const;
|
|
27
|
+
|
|
28
|
+
type Args = Record<string, unknown>;
|
|
29
|
+
|
|
30
|
+
function scrubFields(args: Args, fields: readonly string[]): Args {
|
|
31
|
+
const out: Args = { ...args };
|
|
32
|
+
for (const field of fields) {
|
|
33
|
+
if (out[field] !== undefined) out[field] = scrubObject(out[field]);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Scrub the text-bearing fields of a Slack Web API write. Other methods pass through. */
|
|
39
|
+
function scrubSlackWriteArgs(method: string, args: Args | undefined): Args | undefined {
|
|
40
|
+
if (!args || !WRITE_METHODS.has(method)) return args;
|
|
41
|
+
return scrubFields(args, TEXT_FIELDS);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Scrub a `files.uploadV2` call. String `content` is text the bot is about to
|
|
46
|
+
* publish, so it is scrubbed; `file` (a path or a Buffer) is binary-safe and
|
|
47
|
+
* passes through byte-identical.
|
|
48
|
+
*/
|
|
49
|
+
function scrubSlackUploadArgs<T extends object>(options: T): T {
|
|
50
|
+
const out = scrubFields(options as Args, ["initial_comment", "title", "alt_text"]);
|
|
51
|
+
if (typeof out.content === "string") out.content = scrubSecrets(out.content);
|
|
52
|
+
if (Array.isArray(out.file_uploads)) {
|
|
53
|
+
out.file_uploads = out.file_uploads.map((upload: unknown) => {
|
|
54
|
+
if (!upload || typeof upload !== "object") return upload;
|
|
55
|
+
const entry = scrubFields(upload as Args, ["title", "alt_text"]);
|
|
56
|
+
if (typeof entry.content === "string") entry.content = scrubSecrets(entry.content);
|
|
57
|
+
return entry;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return out as T;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const INSTALLED = Symbol.for("agent-swarm.slack-egress-scrub");
|
|
64
|
+
|
|
65
|
+
type PatchableProto = {
|
|
66
|
+
apiCall: (method: string, options?: Args) => Promise<unknown>;
|
|
67
|
+
filesUploadV2: (options: object) => Promise<unknown>;
|
|
68
|
+
[INSTALLED]?: true;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Route every `WebClient` built after this call through the scrub. Idempotent.
|
|
73
|
+
* Call it before the Bolt `App` (and its receiver) are constructed.
|
|
74
|
+
*/
|
|
75
|
+
export function installSlackEgressScrub(): void {
|
|
76
|
+
const proto = webApi.WebClient.prototype as unknown as PatchableProto;
|
|
77
|
+
if (proto[INSTALLED]) return;
|
|
78
|
+
const originalApiCall = proto.apiCall;
|
|
79
|
+
const originalUpload = proto.filesUploadV2;
|
|
80
|
+
proto.apiCall = function (this: unknown, method: string, options?: Args) {
|
|
81
|
+
return originalApiCall.call(this, method, scrubSlackWriteArgs(method, options));
|
|
82
|
+
};
|
|
83
|
+
proto.filesUploadV2 = function (this: unknown, options: object) {
|
|
84
|
+
return originalUpload.call(this, scrubSlackUploadArgs(options));
|
|
85
|
+
};
|
|
86
|
+
proto[INSTALLED] = true;
|
|
87
|
+
}
|