@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
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
autoCancelStaleApprovalRequests,
|
|
3
3
|
timeoutExpiredApprovalRequests,
|
|
4
4
|
} from "../be/approval-sweeps";
|
|
5
|
+
import { deleteExpiredConnectorCodes } from "../be/connector-codes";
|
|
5
6
|
import {
|
|
6
7
|
assignUnassignedTaskPending,
|
|
7
8
|
backfillSupersedeTaskResumeTaskId,
|
|
@@ -68,7 +69,7 @@ import {
|
|
|
68
69
|
REBOOT_RETRY_PIN_TAG,
|
|
69
70
|
resolveLeadOnlyRecoveryAssignment,
|
|
70
71
|
} from "../tasks/worker-follow-up";
|
|
71
|
-
import type
|
|
72
|
+
import { type AgentTask, TERMINAL_TASK_STATUSES } from "../types";
|
|
72
73
|
import { isEnvFlagEnabled } from "../utils/env-flag";
|
|
73
74
|
import { isMultiRuntimeEnabled } from "../utils/multi-runtime";
|
|
74
75
|
import { scrubSecrets } from "../utils/secret-scrubber";
|
|
@@ -288,6 +289,7 @@ export interface HeartbeatFindings {
|
|
|
288
289
|
abandonedDraftTasks: number;
|
|
289
290
|
approvalAutoCancelled: number;
|
|
290
291
|
approvalTimedOut: number;
|
|
292
|
+
connectorCodes: number;
|
|
291
293
|
};
|
|
292
294
|
}
|
|
293
295
|
|
|
@@ -368,6 +370,7 @@ export async function codeLevelTriage(): Promise<HeartbeatFindings> {
|
|
|
368
370
|
abandonedDraftTasks: 0,
|
|
369
371
|
approvalAutoCancelled: 0,
|
|
370
372
|
approvalTimedOut: 0,
|
|
373
|
+
connectorCodes: 0,
|
|
371
374
|
},
|
|
372
375
|
};
|
|
373
376
|
|
|
@@ -880,9 +883,9 @@ export async function runRebootSweep(): Promise<void> {
|
|
|
880
883
|
const existingRetry = await getDbClient().get<{ id: string }>(
|
|
881
884
|
`SELECT id FROM agent_tasks
|
|
882
885
|
WHERE parentTaskId = ?
|
|
883
|
-
AND status NOT IN (
|
|
886
|
+
AND status NOT IN (${TERMINAL_TASK_STATUSES.map(() => "?").join(", ")})
|
|
884
887
|
LIMIT 1`,
|
|
885
|
-
[task.id],
|
|
888
|
+
[task.id, ...TERMINAL_TASK_STATUSES],
|
|
886
889
|
);
|
|
887
890
|
|
|
888
891
|
if (!existingRetry) {
|
|
@@ -1389,6 +1392,12 @@ async function cleanupStaleResources(findings: HeartbeatFindings): Promise<void>
|
|
|
1389
1392
|
console.error("[heartbeat] approval auto-cancel sweep failed:", err);
|
|
1390
1393
|
findings.staleCleanup.approvalAutoCancelled = 0;
|
|
1391
1394
|
}
|
|
1395
|
+
try {
|
|
1396
|
+
findings.staleCleanup.connectorCodes = await deleteExpiredConnectorCodes();
|
|
1397
|
+
} catch (err) {
|
|
1398
|
+
console.error("[heartbeat] connector code cleanup failed:", err);
|
|
1399
|
+
findings.staleCleanup.connectorCodes = 0;
|
|
1400
|
+
}
|
|
1392
1401
|
}
|
|
1393
1402
|
|
|
1394
1403
|
// ============================================================================
|
|
@@ -1625,9 +1634,9 @@ export async function checkHeartbeatChecklist(): Promise<void> {
|
|
|
1625
1634
|
`SELECT id FROM agent_tasks
|
|
1626
1635
|
WHERE agentId = ?
|
|
1627
1636
|
AND taskType = 'heartbeat-checklist'
|
|
1628
|
-
AND status NOT IN (
|
|
1637
|
+
AND status NOT IN (${TERMINAL_TASK_STATUSES.map(() => "?").join(", ")})
|
|
1629
1638
|
LIMIT 1`,
|
|
1630
|
-
[lead.id],
|
|
1639
|
+
[lead.id, ...TERMINAL_TASK_STATUSES],
|
|
1631
1640
|
);
|
|
1632
1641
|
if (existing) return;
|
|
1633
1642
|
|
|
@@ -1691,6 +1700,7 @@ export async function runHeartbeatSweep(): Promise<void> {
|
|
|
1691
1700
|
abandonedDraftTasks: 0,
|
|
1692
1701
|
approvalAutoCancelled: 0,
|
|
1693
1702
|
approvalTimedOut: 0,
|
|
1703
|
+
connectorCodes: 0,
|
|
1694
1704
|
},
|
|
1695
1705
|
};
|
|
1696
1706
|
// Expiry runs even on a cleanup-only tick: an idle agent whose runtime
|
|
@@ -1762,6 +1772,7 @@ function logFindings(findings: HeartbeatFindings): void {
|
|
|
1762
1772
|
abandonedDraftTasks,
|
|
1763
1773
|
approvalAutoCancelled,
|
|
1764
1774
|
approvalTimedOut,
|
|
1775
|
+
connectorCodes,
|
|
1765
1776
|
} = findings.staleCleanup;
|
|
1766
1777
|
const totalCleanup =
|
|
1767
1778
|
sessions +
|
|
@@ -1770,7 +1781,8 @@ function logFindings(findings: HeartbeatFindings): void {
|
|
|
1770
1781
|
inboxProcessing +
|
|
1771
1782
|
workflowRuns +
|
|
1772
1783
|
approvalAutoCancelled +
|
|
1773
|
-
approvalTimedOut
|
|
1784
|
+
approvalTimedOut +
|
|
1785
|
+
connectorCodes;
|
|
1774
1786
|
if (totalCleanup > 0) {
|
|
1775
1787
|
parts.push(`stale_cleanup=${totalCleanup}`);
|
|
1776
1788
|
}
|
|
@@ -1858,9 +1870,9 @@ export async function createBootTriageTask(): Promise<void> {
|
|
|
1858
1870
|
`SELECT id FROM agent_tasks
|
|
1859
1871
|
WHERE agentId = ?
|
|
1860
1872
|
AND taskType = 'boot-triage'
|
|
1861
|
-
AND status NOT IN (
|
|
1873
|
+
AND status NOT IN (${TERMINAL_TASK_STATUSES.map(() => "?").join(", ")})
|
|
1862
1874
|
LIMIT 1`,
|
|
1863
|
-
[lead.id],
|
|
1875
|
+
[lead.id, ...TERMINAL_TASK_STATUSES],
|
|
1864
1876
|
);
|
|
1865
1877
|
if (existing) return;
|
|
1866
1878
|
|
|
@@ -859,7 +859,7 @@ function parseWithState(
|
|
|
859
859
|
}
|
|
860
860
|
|
|
861
861
|
const BLOCK_ADVICE =
|
|
862
|
-
"Paraphrase the motivation ('a maintainer asked for X') and link only public sources (Fixes #N, a public PR or issue).
|
|
862
|
+
"Paraphrase the motivation ('a maintainer asked for X') and link only public sources (Fixes #N, a public PR or issue). Task, session, agent-fs and Slack permalinks go only under '## Swarm provenance'. Bare Slack ids, ts values and private-chat quotes are blocked everywhere.";
|
|
863
863
|
|
|
864
864
|
/** Check a shell command. Returns a block reason, or null to allow. */
|
|
865
865
|
export async function checkGhPrCommand(
|
package/src/http/agents.ts
CHANGED
|
@@ -689,6 +689,7 @@ async function approvalCancelPrincipal(
|
|
|
689
689
|
const rawAgentId = req.headers["x-agent-id"];
|
|
690
690
|
const agentId =
|
|
691
691
|
auth?.kind === "agent" ? auth.agentId : Array.isArray(rawAgentId) ? rawAgentId[0] : rawAgentId;
|
|
692
|
+
if (auth?.kind === "guest") return { principal: { kind: "guest" }, resolvedBy: null };
|
|
692
693
|
if (agentId) {
|
|
693
694
|
const agent = await getAgentById(agentId);
|
|
694
695
|
return {
|
package/src/http/apps.ts
CHANGED
|
@@ -671,6 +671,9 @@ async function authorizeApp(
|
|
|
671
671
|
} else if (auth?.kind === "user") {
|
|
672
672
|
principal = { kind: "user", userId: auth.userId };
|
|
673
673
|
actor = `user:${auth.userId}`;
|
|
674
|
+
} else if (auth?.kind === "guest") {
|
|
675
|
+
principal = { kind: "guest" };
|
|
676
|
+
actor = "guest";
|
|
674
677
|
} else {
|
|
675
678
|
const agent = myAgentId ? await getAgentById(myAgentId) : null;
|
|
676
679
|
principal = { kind: "agent", agentId: myAgentId ?? "", isLead: agent?.isLead ?? false };
|
package/src/http/auth.ts
CHANGED
|
@@ -45,7 +45,10 @@ export async function resolveHttpRequestAuth(
|
|
|
45
45
|
if (!isActiveUser(user)) return null;
|
|
46
46
|
return { kind: "user", userId: user.id, user, page };
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
if (payload.op) {
|
|
49
|
+
return { kind: "operator", fingerprint: fingerprintApiKey(bearer), page };
|
|
50
|
+
}
|
|
51
|
+
return { kind: "guest", page };
|
|
49
52
|
}
|
|
50
53
|
return { kind: "operator", fingerprint: fingerprintApiKey(bearer) };
|
|
51
54
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { decryptSecret, encryptSecret, getEncryptionKey } from "../be/crypto";
|
|
4
|
-
import { getDbClient,
|
|
4
|
+
import { getDbClient, upsertSwarmConfig } from "../be/db";
|
|
5
|
+
import { getCodexDeviceFlow, upsertCodexDeviceFlow } from "../be/db/codex-oauth-device-flows";
|
|
5
6
|
import { updateOnboardingAiFromCodexDevice } from "../be/onboarding";
|
|
6
7
|
import {
|
|
7
8
|
CODEX_DEVICE_VERIFICATION_URL,
|
|
@@ -17,7 +18,6 @@ import { ensureConfigAdmin } from "./config";
|
|
|
17
18
|
import { route } from "./route-def";
|
|
18
19
|
import { jsonError } from "./utils";
|
|
19
20
|
|
|
20
|
-
const FLOW_NAMESPACE = "codex-oauth-device";
|
|
21
21
|
const FLOW_TTL_MS = 15 * 60 * 1_000;
|
|
22
22
|
const POLL_LEASE_MS = 45_000;
|
|
23
23
|
|
|
@@ -85,10 +85,10 @@ function registerFlowSecrets(state: FlowState): void {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
async function readFlow(flowId: string): Promise<FlowState | null> {
|
|
88
|
-
const entry = await
|
|
89
|
-
if (!entry
|
|
88
|
+
const entry = await getCodexDeviceFlow(flowId);
|
|
89
|
+
if (!entry) return null;
|
|
90
90
|
try {
|
|
91
|
-
const plaintext = decryptSecret(entry.
|
|
91
|
+
const plaintext = decryptSecret(entry.state, getEncryptionKey());
|
|
92
92
|
const parsed = FlowStateSchema.safeParse(JSON.parse(plaintext));
|
|
93
93
|
if (!parsed.success) return null;
|
|
94
94
|
registerFlowSecrets(parsed.data);
|
|
@@ -99,11 +99,9 @@ async function readFlow(flowId: string): Promise<FlowState | null> {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
async function writeFlow(flowId: string, state: FlowState): Promise<void> {
|
|
102
|
-
await
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
value: encryptSecret(JSON.stringify(state), getEncryptionKey()),
|
|
106
|
-
valueType: "string",
|
|
102
|
+
await upsertCodexDeviceFlow({
|
|
103
|
+
flowId,
|
|
104
|
+
state: encryptSecret(JSON.stringify(state), getEncryptionKey()),
|
|
107
105
|
expiresAt: state.expiresAt,
|
|
108
106
|
});
|
|
109
107
|
}
|
|
@@ -29,8 +29,8 @@ import { deriveCodexKeySuffix } from "../providers/codex-oauth/auth-json.js";
|
|
|
29
29
|
import { getValidCodexOAuth, loadAllCodexOAuthSlots } from "../providers/codex-oauth/storage.js";
|
|
30
30
|
import { getApiKey } from "../utils/api-key";
|
|
31
31
|
import { CODEX_AUTH_WATCH_NAMESPACE, codexAuthBenchMarkerKey } from "../utils/codex-auth-failure";
|
|
32
|
+
import { getMcpBaseUrl } from "../utils/constants";
|
|
32
33
|
import { route } from "./route-def";
|
|
33
|
-
import { deriveApiBaseUrl } from "./utils";
|
|
34
34
|
|
|
35
35
|
/** ~weekly refresh cadence, comfortably inside OpenAI's ~8-day staleness window given the 10-day TTL. */
|
|
36
36
|
const KEEP_WARM_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
@@ -80,7 +80,7 @@ export async function handleCodexOAuthKeepWarm(
|
|
|
80
80
|
const parsed = await keepWarmRoute.parse(req, res, pathSegments, new URLSearchParams());
|
|
81
81
|
if (!parsed) return true;
|
|
82
82
|
|
|
83
|
-
const apiUrl =
|
|
83
|
+
const apiUrl = getMcpBaseUrl();
|
|
84
84
|
const apiKey = getApiKey();
|
|
85
85
|
const slots = await loadAllCodexOAuthSlots(apiUrl, apiKey);
|
|
86
86
|
const results: SlotOutcome[] = [];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getResolvedConfig } from "../be/db";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Look up a config value by key. Falls back to `process.env` when no
|
|
5
|
+
* swarm_config row exists — mirrors the resolution order used elsewhere
|
|
6
|
+
* (see `loadGlobalConfigsIntoEnv`).
|
|
7
|
+
*
|
|
8
|
+
* Returns the trimmed value or `null` if unset/empty.
|
|
9
|
+
*/
|
|
10
|
+
export async function resolveConfigValue(key: string): Promise<string | null> {
|
|
11
|
+
const configs = await getResolvedConfig();
|
|
12
|
+
// The setup CLI persists keys in lowercase (e.g. `managed_agent_id`) while
|
|
13
|
+
// the docker-entrypoint hydrates env vars in uppercase (`MANAGED_AGENT_ID`).
|
|
14
|
+
// Look up both variants so this endpoint works against either shape.
|
|
15
|
+
const variants = [key, key.toLowerCase(), key.toUpperCase()];
|
|
16
|
+
for (const variant of variants) {
|
|
17
|
+
const row = configs.find((c) => c.key === variant);
|
|
18
|
+
if (row && typeof row.value === "string" && row.value.length > 0) {
|
|
19
|
+
return row.value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// Env fallback — the row may not exist if the operator deployed via env
|
|
23
|
+
// file rather than swarm_config.
|
|
24
|
+
const envValue = process.env[key];
|
|
25
|
+
if (envValue && envValue.length > 0) return envValue;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Public, browser-facing API origin with swarm_config precedence. The dashboard
|
|
31
|
+
* (`GET /api/integrations/mcp-user-config`) and the connector-code route both
|
|
32
|
+
* read it, so they always agree.
|
|
33
|
+
*/
|
|
34
|
+
export async function resolveMcpBaseUrl(): Promise<string> {
|
|
35
|
+
// Browser-facing connect URLs: prefer the public ingress origin
|
|
36
|
+
// (PUBLIC_MCP_BASE_URL) over the internal MCP_BASE_URL so split deployments
|
|
37
|
+
// (Helm) surface a host the user's browser can actually reach. Both honor the
|
|
38
|
+
// swarm_config → env resolution order. Falls back to the localhost dev base.
|
|
39
|
+
const configured =
|
|
40
|
+
(await resolveConfigValue("PUBLIC_MCP_BASE_URL")) ?? (await resolveConfigValue("MCP_BASE_URL"));
|
|
41
|
+
const fallback = `http://localhost:${process.env.PORT || "3013"}`;
|
|
42
|
+
return (configured || fallback).replace(/\/+$/, "");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Dashboard origin with swarm_config precedence (`APP_URL`, then the
|
|
47
|
+
* deprecated `DASHBOARD_URL`). Both accept a comma-separated list; the first
|
|
48
|
+
* entry wins, matching `getAppUrl`. Returns null when neither is set, so
|
|
49
|
+
* callers can omit it instead of guessing the hosted default.
|
|
50
|
+
*/
|
|
51
|
+
export async function resolveAppUrl(): Promise<string | null> {
|
|
52
|
+
const configured =
|
|
53
|
+
(await resolveConfigValue("APP_URL")) ?? (await resolveConfigValue("DASHBOARD_URL"));
|
|
54
|
+
const first = configured
|
|
55
|
+
?.split(",")
|
|
56
|
+
.map((value) => value.trim().replace(/\/+$/, ""))
|
|
57
|
+
.find(Boolean);
|
|
58
|
+
return first || null;
|
|
59
|
+
}
|
package/src/http/config.ts
CHANGED
|
@@ -64,6 +64,7 @@ async function requestMayReadSecrets(req: IncomingMessage): Promise<boolean> {
|
|
|
64
64
|
source: "http",
|
|
65
65
|
}).allow;
|
|
66
66
|
}
|
|
67
|
+
if (auth?.kind === "guest") return false;
|
|
67
68
|
// Preserve legacy reads without a user or session-token principal.
|
|
68
69
|
if (auth?.kind !== "user") return true;
|
|
69
70
|
if (!isRbacEnabled()) return true;
|
|
@@ -102,6 +103,10 @@ export async function ensureConfigAdmin(
|
|
|
102
103
|
): Promise<boolean> {
|
|
103
104
|
const auth = getRequestAuth(req);
|
|
104
105
|
if (auth?.kind === "operator" || auth?.kind === "user") return true;
|
|
106
|
+
if (auth?.kind === "guest") {
|
|
107
|
+
jsonError(res, "Forbidden", 403);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
105
110
|
const agentId = auth?.kind === "agent" ? auth.agentId : singleHeader(req, "x-agent-id");
|
|
106
111
|
const agent = agentId ? await getAgentById(agentId) : undefined;
|
|
107
112
|
const decision = can({
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
import { getDb, resolveSqliteVecExtensionPath } from "../be/db";
|
|
38
38
|
import type { DbQueryResult } from "./db-query-shared";
|
|
39
39
|
import {
|
|
40
|
+
assertNoDeniedTables,
|
|
40
41
|
assertSingleStatement,
|
|
41
42
|
DbQueryConcurrencyCapError,
|
|
42
43
|
DbQueryTimeoutError,
|
|
@@ -203,6 +204,8 @@ export async function executeReadOnlyQueryBounded(
|
|
|
203
204
|
maxRows?: number,
|
|
204
205
|
): Promise<DbQueryResult> {
|
|
205
206
|
assertSingleStatement(sql);
|
|
207
|
+
// The child opens its own connection, so the parent checks the program first.
|
|
208
|
+
assertNoDeniedTables(sql);
|
|
206
209
|
acquireBoundedQuerySlot();
|
|
207
210
|
|
|
208
211
|
try {
|
|
@@ -56,6 +56,111 @@ export function assertSingleStatement(sql: string): void {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Tables whose rows are credentials: OAuth tokens and client secrets, PKCE
|
|
61
|
+
* verifiers, API and session token hashes, encrypted script-API bearers, and
|
|
62
|
+
* encrypted Codex device-login state.
|
|
63
|
+
* `db-query` is open to every authenticated agent, so it refuses any query
|
|
64
|
+
* that reads one of these, however the table is reached (alias, CTE, view,
|
|
65
|
+
* subquery, join or covering index). `swarm_config` stays readable: its
|
|
66
|
+
* secret values are ciphertext and agents query its non-secret keys.
|
|
67
|
+
*/
|
|
68
|
+
export const DB_QUERY_DENIED_TABLES: ReadonlySet<string> = new Set([
|
|
69
|
+
"oauth_authorizations",
|
|
70
|
+
"oauth_apps",
|
|
71
|
+
"oauth_pending",
|
|
72
|
+
"user_tokens",
|
|
73
|
+
"session_tokens",
|
|
74
|
+
"script_apis",
|
|
75
|
+
"codex_oauth_device_flows",
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
/** Thrown when a query would read a table in {@link DB_QUERY_DENIED_TABLES}. */
|
|
79
|
+
export class DbQueryDeniedTableError extends Error {
|
|
80
|
+
constructor(readonly tables: string[]) {
|
|
81
|
+
super(
|
|
82
|
+
`db-query cannot read ${tables.join(", ")}: ${tables.length === 1 ? "this table holds" : "these tables hold"} credentials. ` +
|
|
83
|
+
"Use the dedicated OAuth, token or config tools instead.",
|
|
84
|
+
);
|
|
85
|
+
this.name = "DbQueryDeniedTableError";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Bytecode opcodes whose p2 is the root page of the b-tree they open. */
|
|
90
|
+
const CURSOR_OPEN_OPCODES = new Set(["OpenRead", "ReopenIdx", "OpenWrite"]);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Open a read-only connection to the swarm database. User SQL is never
|
|
94
|
+
* prepared on the writable application connection. In-memory databases have
|
|
95
|
+
* no file to reopen, so they get a read-only snapshot instead.
|
|
96
|
+
*/
|
|
97
|
+
function openReadOnlyReader(): Database {
|
|
98
|
+
const database = getDb();
|
|
99
|
+
const reader =
|
|
100
|
+
!database.filename || database.filename === ":memory:"
|
|
101
|
+
? Database.deserialize(database.serialize(), { readonly: true })
|
|
102
|
+
: new Database(database.filename, { readonly: true });
|
|
103
|
+
const vecExtensionPath = resolveSqliteVecExtensionPath();
|
|
104
|
+
if (vecExtensionPath) {
|
|
105
|
+
try {
|
|
106
|
+
reader.loadExtension(vecExtensionPath);
|
|
107
|
+
} catch {
|
|
108
|
+
// Match the bounded path: only vec queries require the extension.
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return reader;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Reject `sql` if it reads a denied table. Works on the compiled program, not
|
|
116
|
+
* the SQL text: `EXPLAIN` lists every b-tree the statement opens by root page,
|
|
117
|
+
* and `sqlite_master` maps root pages (tables and their indexes) back to a
|
|
118
|
+
* table name. Views, CTEs and subqueries are already expanded in the program,
|
|
119
|
+
* so no SQL parsing is needed. A user `EXPLAIN ...` returns bytecode, never
|
|
120
|
+
* row data, so it is allowed as is.
|
|
121
|
+
*/
|
|
122
|
+
export function assertNoDeniedTables(sql: string, reader?: Database): void {
|
|
123
|
+
const statement = stripTrailingSemicolon(sql);
|
|
124
|
+
if (/^explain\b/i.test(stripLeadingComments(statement))) return;
|
|
125
|
+
|
|
126
|
+
const db = reader ?? openReadOnlyReader();
|
|
127
|
+
try {
|
|
128
|
+
const rootPages = new Map<number, string>();
|
|
129
|
+
for (const row of db
|
|
130
|
+
.query("SELECT rootpage, tbl_name FROM main.sqlite_master WHERE rootpage > 0")
|
|
131
|
+
.all() as Array<{ rootpage: number; tbl_name: string }>) {
|
|
132
|
+
rootPages.set(row.rootpage, row.tbl_name.toLowerCase());
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
using program = db.prepare(`EXPLAIN ${statement}`);
|
|
136
|
+
const denied = new Set<string>();
|
|
137
|
+
for (const op of program.all() as Array<{ opcode: string; p2: number; p3: number }>) {
|
|
138
|
+
// p3 is the schema index: 0 = main. Credential tables only live there.
|
|
139
|
+
if (!CURSOR_OPEN_OPCODES.has(op.opcode) || op.p3 !== 0) continue;
|
|
140
|
+
const table = rootPages.get(op.p2);
|
|
141
|
+
if (table && DB_QUERY_DENIED_TABLES.has(table)) denied.add(table);
|
|
142
|
+
}
|
|
143
|
+
if (denied.size > 0) throw new DbQueryDeniedTableError([...denied].sort());
|
|
144
|
+
} finally {
|
|
145
|
+
if (!reader) db.close();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function stripLeadingComments(sql: string): string {
|
|
150
|
+
let rest = sql.trimStart();
|
|
151
|
+
for (;;) {
|
|
152
|
+
if (rest.startsWith("--")) {
|
|
153
|
+
const end = rest.indexOf("\n");
|
|
154
|
+
rest = end === -1 ? "" : rest.slice(end + 1).trimStart();
|
|
155
|
+
} else if (rest.startsWith("/*")) {
|
|
156
|
+
const end = rest.indexOf("*/");
|
|
157
|
+
rest = end === -1 ? "" : rest.slice(end + 2).trimStart();
|
|
158
|
+
} else {
|
|
159
|
+
return rest;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
59
164
|
/**
|
|
60
165
|
* Execute a read-only SQL query against the swarm database, synchronously,
|
|
61
166
|
* on the caller's own thread.
|
|
@@ -72,22 +177,9 @@ export function executeReadOnlyQuery(
|
|
|
72
177
|
maxRows?: number,
|
|
73
178
|
): DbQueryResult {
|
|
74
179
|
assertSingleStatement(sql);
|
|
75
|
-
const
|
|
76
|
-
// Never prepare user SQL on the writable application connection. In-memory
|
|
77
|
-
// databases have no file to reopen, so query a read-only snapshot instead.
|
|
78
|
-
const reader =
|
|
79
|
-
!database.filename || database.filename === ":memory:"
|
|
80
|
-
? Database.deserialize(database.serialize(), { readonly: true })
|
|
81
|
-
: new Database(database.filename, { readonly: true });
|
|
180
|
+
const reader = openReadOnlyReader();
|
|
82
181
|
try {
|
|
83
|
-
|
|
84
|
-
if (vecExtensionPath) {
|
|
85
|
-
try {
|
|
86
|
-
reader.loadExtension(vecExtensionPath);
|
|
87
|
-
} catch {
|
|
88
|
-
// Match the bounded path: only vec queries require the extension.
|
|
89
|
-
}
|
|
90
|
-
}
|
|
182
|
+
assertNoDeniedTables(sql, reader);
|
|
91
183
|
using stmt = reader.prepare(sql);
|
|
92
184
|
|
|
93
185
|
// Require a result set; SQLite readonly mode is the write barrier.
|
package/src/http/db-query.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { scrubObject } from "../utils/secret-scrubber";
|
|
3
4
|
import { executeReadOnlyQueryBounded } from "./db-query-bounded";
|
|
4
5
|
import {
|
|
5
6
|
assertSingleStatement,
|
|
@@ -18,7 +19,10 @@ import { json, jsonError } from "./utils";
|
|
|
18
19
|
|
|
19
20
|
export type { DbQueryResult } from "./db-query-shared";
|
|
20
21
|
export {
|
|
22
|
+
assertNoDeniedTables,
|
|
21
23
|
assertSingleStatement,
|
|
24
|
+
DB_QUERY_DENIED_TABLES,
|
|
25
|
+
DbQueryDeniedTableError,
|
|
22
26
|
executeReadOnlyQuery,
|
|
23
27
|
getDbQueryHttpBudgetMs,
|
|
24
28
|
getDbQueryHttpMaxRows,
|
|
@@ -104,7 +108,9 @@ const dbQueryRoute = route({
|
|
|
104
108
|
rowLimit: z.number().nullable(),
|
|
105
109
|
}),
|
|
106
110
|
},
|
|
107
|
-
400: {
|
|
111
|
+
400: {
|
|
112
|
+
description: "Invalid or disallowed SQL, including queries that read credential tables",
|
|
113
|
+
},
|
|
108
114
|
408: { description: "Query exceeded its wall-clock budget and was terminated" },
|
|
109
115
|
429: { description: "Too many concurrent bounded db-query executions; retry shortly" },
|
|
110
116
|
},
|
|
@@ -131,7 +137,9 @@ export async function handleDbQuery(
|
|
|
131
137
|
getDbQueryHttpBudgetMs(),
|
|
132
138
|
getDbQueryHttpMaxRows(),
|
|
133
139
|
);
|
|
134
|
-
|
|
140
|
+
// Rows can hold secrets pasted into free text (task output, logs, events).
|
|
141
|
+
// The MCP tool gets this from the registrar; the HTTP route does it here.
|
|
142
|
+
dbQueryRoute.respond(res, 200, scrubObject(result));
|
|
135
143
|
} catch (err: unknown) {
|
|
136
144
|
if (err instanceof DbQueryConcurrencyCapError) {
|
|
137
145
|
// Machine-readable code + Retry-After so a caller can back off instead
|
package/src/http/extensions.ts
CHANGED
|
@@ -411,6 +411,7 @@ async function extensionPrincipal(
|
|
|
411
411
|
const auth = getRequestAuth(req);
|
|
412
412
|
if (auth?.kind === "operator") return { kind: "operator" };
|
|
413
413
|
if (auth?.kind === "user") return { kind: "user", userId: auth.userId };
|
|
414
|
+
if (auth?.kind === "guest") return { kind: "guest" };
|
|
414
415
|
return { kind: "agent", agentId: "", isLead: false };
|
|
415
416
|
}
|
|
416
417
|
|
package/src/http/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
stopAuditWriter,
|
|
27
27
|
} from "../be/rbac-audit";
|
|
28
28
|
import { startScratchScriptGc, stopScratchScriptGc } from "../be/scripts/retention";
|
|
29
|
+
import { loadSecretRegistry } from "../be/secret-registry";
|
|
29
30
|
import { seedLegacyCapabilitiesConfig } from "../be/seed-capabilities";
|
|
30
31
|
import {
|
|
31
32
|
loadEnabledExtensions,
|
|
@@ -589,6 +590,22 @@ try {
|
|
|
589
590
|
}
|
|
590
591
|
warnIfCorsAllowsAnyOrigin();
|
|
591
592
|
|
|
593
|
+
// Register every stored secret (config secrets of all scopes, OAuth and MCP
|
|
594
|
+
// OAuth credentials, script API tokens) with the scrubber before listen, so
|
|
595
|
+
// egress and the boot retro-sweep below can redact values not touched since
|
|
596
|
+
// the last restart. Non-fatal: a decrypt failure only loses redaction coverage.
|
|
597
|
+
try {
|
|
598
|
+
const loaded = await loadSecretRegistry();
|
|
599
|
+
console.log(
|
|
600
|
+
`[secret-registry] registered config=${loaded.config} oauth=${loaded.oauth} scriptApi=${loaded.scriptApi} failed=${loaded.failed}`,
|
|
601
|
+
);
|
|
602
|
+
} catch (err) {
|
|
603
|
+
console.error(
|
|
604
|
+
"[secret-registry] load failed (non-fatal):",
|
|
605
|
+
scrubSecrets(err instanceof Error ? err.message : String(err)),
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
|
|
592
609
|
// Upgrade seed: explicit CAPABILITIES env values that predate capability
|
|
593
610
|
// gating get the previously always-registered groups backfilled into a
|
|
594
611
|
// global swarm_config row (operator-editable; skipped when a row exists).
|
|
@@ -809,13 +826,13 @@ httpServer
|
|
|
809
826
|
console.error("[boot-reembed-scripts] startup backfill failed (non-fatal):", err);
|
|
810
827
|
});
|
|
811
828
|
|
|
812
|
-
//
|
|
813
|
-
//
|
|
814
|
-
// Idempotent, tracked via seed_state.
|
|
815
|
-
import("../be/boot-scrub-
|
|
816
|
-
.then(({
|
|
829
|
+
// Versioned retro-sweep: once per SCRUBBER_RULES_VERSION, redact stored
|
|
830
|
+
// rows (logs, tasks, memory, events, workflow steps) that pre-date the
|
|
831
|
+
// current scrubber rules. Idempotent and resumable, tracked via seed_state.
|
|
832
|
+
import("../be/boot-scrub-sweep")
|
|
833
|
+
.then(({ runBootScrubSweep }) => runBootScrubSweep())
|
|
817
834
|
.catch((err) => {
|
|
818
|
-
console.error("[boot-scrub-
|
|
835
|
+
console.error("[boot-scrub-sweep] startup scrub failed (non-fatal):", err);
|
|
819
836
|
});
|
|
820
837
|
})
|
|
821
838
|
.on("error", (err) => {
|
package/src/http/integrations.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
2
|
import Anthropic from "@anthropic-ai/sdk";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { getResolvedConfig } from "../be/db";
|
|
5
4
|
import { buildSlackManifest } from "../slack/manifest";
|
|
5
|
+
import { resolveConfigValue, resolveMcpBaseUrl } from "./config-values";
|
|
6
6
|
import { route } from "./route-def";
|
|
7
7
|
|
|
8
8
|
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
@@ -96,43 +96,6 @@ const slackManifestRoute = route({
|
|
|
96
96
|
|
|
97
97
|
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
98
98
|
|
|
99
|
-
/**
|
|
100
|
-
* Look up a config value by key. Falls back to `process.env` when no
|
|
101
|
-
* swarm_config row exists — mirrors the resolution order used elsewhere
|
|
102
|
-
* (see `loadGlobalConfigsIntoEnv`).
|
|
103
|
-
*
|
|
104
|
-
* Returns the trimmed value or `null` if unset/empty.
|
|
105
|
-
*/
|
|
106
|
-
async function resolveConfigValue(key: string): Promise<string | null> {
|
|
107
|
-
const configs = await getResolvedConfig();
|
|
108
|
-
// The setup CLI persists keys in lowercase (e.g. `managed_agent_id`) while
|
|
109
|
-
// the docker-entrypoint hydrates env vars in uppercase (`MANAGED_AGENT_ID`).
|
|
110
|
-
// Look up both variants so this endpoint works against either shape.
|
|
111
|
-
const variants = [key, key.toLowerCase(), key.toUpperCase()];
|
|
112
|
-
for (const variant of variants) {
|
|
113
|
-
const row = configs.find((c) => c.key === variant);
|
|
114
|
-
if (row && typeof row.value === "string" && row.value.length > 0) {
|
|
115
|
-
return row.value;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// Env fallback — the row may not exist if the operator deployed via env
|
|
119
|
-
// file rather than swarm_config.
|
|
120
|
-
const envValue = process.env[key];
|
|
121
|
-
if (envValue && envValue.length > 0) return envValue;
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function resolveMcpBaseUrl(): Promise<string> {
|
|
126
|
-
// Browser-facing connect URLs: prefer the public ingress origin
|
|
127
|
-
// (PUBLIC_MCP_BASE_URL) over the internal MCP_BASE_URL so split deployments
|
|
128
|
-
// (Helm) surface a host the user's browser can actually reach. Both honor the
|
|
129
|
-
// swarm_config → env resolution order. Falls back to the localhost dev base.
|
|
130
|
-
const configured =
|
|
131
|
-
(await resolveConfigValue("PUBLIC_MCP_BASE_URL")) ?? (await resolveConfigValue("MCP_BASE_URL"));
|
|
132
|
-
const fallback = `http://localhost:${process.env.PORT || "3013"}`;
|
|
133
|
-
return (configured || fallback).replace(/\/+$/, "");
|
|
134
|
-
}
|
|
135
|
-
|
|
136
99
|
// ─── Public handler factory ──────────────────────────────────────────────────
|
|
137
100
|
|
|
138
101
|
/**
|