@desplega.ai/agent-swarm 2.13.1 → 2.13.3
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-t2q6nsqv.js +17 -0
- package/dist/{acp-targets-n7vm5atw.js → acp-targets-k8xs4tj8.js} +7 -7
- package/dist/{actions-hq6wp9xv.js → actions-pg5fxjer.js} +25 -25
- package/dist/{agent-fs-provision-y0qc1rdd.js → agent-fs-provision-vbk3fppw.js} +4 -4
- package/dist/{amp-adapter-1qqs6h91.js → amp-adapter-adbhxsz9.js} +2 -2
- package/dist/{app-7m4z44rv.js → app-b267ggx1.js} +8 -8
- package/dist/{approval-notifications-8sr41gjx.js → approval-notifications-evc1a9z5.js} +9 -9
- package/dist/{assistant-hkczwfv6.js → assistant-wgz2ab84.js} +26 -26
- package/dist/{boot-args-schema-8025snev.js → boot-args-schema-6tpk28j4.js} +1 -1
- package/dist/{boot-reembed-15m87nr1.js → boot-reembed-ankp369c.js} +1 -1
- package/dist/{boot-reembed-4bbpxjh1.js → boot-reembed-r1zyvefv.js} +1 -1
- package/dist/{boot-scrub-sweep-eajr97e9.js → boot-scrub-sweep-cgb6r5bd.js} +2 -2
- package/dist/{boot-seeds-9cwy39jx.js → boot-seeds-bjceqg7b.js} +4 -4
- package/dist/{claude-adapter-g61wa4rt.js → claude-adapter-knztdnff.js} +9 -6
- package/dist/{claude-managed-adapter-znkk0prm.js → claude-managed-adapter-qwejzqkk.js} +3 -3
- package/dist/{claude-managed-setup-f1wndkr2.js → claude-managed-setup-0vgz4d1j.js} +4 -4
- package/dist/{claude-sdk-session-687xzf21.js → claude-sdk-session-c3g6dv0g.js} +11984 -11775
- package/dist/{cli-4mj5g29m.js → cli-0j4qmc80.js} +7 -7
- package/dist/{cli-fn8aj7gb.js → cli-1606qw3n.js} +98 -71
- package/dist/{cli-w41bvvms.js → cli-1gnf5c7x.js} +1 -1
- package/dist/{cli-aebswqmz.js → cli-1wew39p0.js} +15 -15
- package/dist/{cli-0fx95c06.js → cli-268b3dgn.js} +2 -2
- package/dist/cli-2ap1the6.js +11 -0
- package/dist/{cli-w6c6dj91.js → cli-4dyhzhpx.js} +1 -1
- package/dist/{cli-grcc2h2g.js → cli-55fqpd9q.js} +8 -8
- package/dist/{cli-p7g7wd9n.js → cli-61fzwtjk.js} +7 -7
- package/dist/{cli-zaate0rd.js → cli-61p7ty8d.js} +2 -2
- package/dist/{cli-cp0m07wb.js → cli-7fa6yv98.js} +2 -2
- package/dist/{cli-5v6b2am8.js → cli-7kv5d674.js} +7 -7
- package/dist/{cli-6r1dwegd.js → cli-80d5g0fa.js} +2 -2
- package/dist/{cli-0xwb7zpt.js → cli-88np9va3.js} +1 -1
- package/dist/{cli-1b5axkt1.js → cli-8m6gqnf1.js} +2 -2
- package/dist/{cli-0a336ze7.js → cli-8pnawt98.js} +3 -3
- package/dist/{cli-7ewre3dm.js → cli-8sayvj48.js} +2 -2
- package/dist/{cli-yeh3g1q6.js → cli-9gmkw6xn.js} +53 -32
- package/dist/{cli-h03j6je3.js → cli-a21cwm89.js} +2 -2
- package/dist/{cli-s6fhqbz1.js → cli-aytna2fm.js} +1 -1
- package/dist/{cli-84xtgbn6.js → cli-b0m3bg0f.js} +100 -2
- package/dist/{cli-mwxez0pz.js → cli-b768ek79.js} +1 -1
- package/dist/{cli-9xx36trj.js → cli-bh53ppqm.js} +2 -2
- package/dist/{cli-1carhg8g.js → cli-czeh7x13.js} +3 -3
- package/dist/{cli-cd9acnvd.js → cli-djwt4mtn.js} +71 -5
- package/dist/{cli-sfajkbd7.js → cli-dq30fq3q.js} +2 -2
- package/dist/{cli-a8ts6x1n.js → cli-dw43pnzp.js} +5 -5
- package/dist/{cli-h9bejmkf.js → cli-e4gx499y.js} +52 -29
- package/dist/{cli-t90k0phh.js → cli-ea367bdn.js} +32 -23
- package/dist/{cli-cmgdptmx.js → cli-ef590376.js} +29 -5
- package/dist/{cli-8rbkw18r.js → cli-fbmgpt72.js} +2 -2
- package/dist/{cli-tzzas8rb.js → cli-g4dhd3pr.js} +2 -2
- package/dist/{cli-snypfjgj.js → cli-gc715jrc.js} +1 -1
- package/dist/{cli-c0tyzt73.js → cli-gkjw33x5.js} +1 -1
- package/dist/{cli-z6m6xzxt.js → cli-grk77aen.js} +26 -5
- package/dist/{cli-hs3mqswp.js → cli-gxqwm3k3.js} +5 -5
- package/dist/{cli-4h90xaet.js → cli-h3drhntp.js} +1 -1
- package/dist/{cli-qn79645p.js → cli-h9d3sdnc.js} +1 -1
- package/dist/{cli-byxsctca.js → cli-hd2a204w.js} +6 -6
- package/dist/{cli-1dr5at77.js → cli-hhb8kbwd.js} +12 -12
- package/dist/{cli-zvpkrgsc.js → cli-hpxcfvdm.js} +3 -3
- package/dist/{cli-cqxwjb93.js → cli-hxj888w3.js} +1 -1
- package/dist/{cli-82j36f2m.js → cli-jjzxsk47.js} +9 -3
- package/dist/{cli-13t0smbk.js → cli-ka4tqjzd.js} +185 -58
- package/dist/{cli-jhtvt7gn.js → cli-kh973792.js} +3 -3
- package/dist/{cli-x5yb8zc8.js → cli-kwm1bek7.js} +1 -1
- package/dist/{cli-bjmq14k9.js → cli-mgr3gatr.js} +4 -4
- package/dist/{cli-c8kqmzzf.js → cli-nbawx3s0.js} +2 -2
- package/dist/{cli-04103ryh.js → cli-ppf9ap9n.js} +1 -1
- package/dist/{cli-dd57p1gd.js → cli-pzsedyb0.js} +4 -4
- package/dist/{cli-32xndx6b.js → cli-r6xnchva.js} +2 -2
- package/dist/{cli-4tbvndmm.js → cli-r8ddn0hf.js} +1 -1
- package/dist/{cli-y6qqbpwc.js → cli-snwz16eg.js} +1 -1
- package/dist/{cli-w24f3j49.js → cli-sy2ge2ye.js} +7 -6
- package/dist/{cli-3m8vqehw.js → cli-syqcny89.js} +3 -3
- package/dist/{cli-qx1dwrr5.js → cli-tjf1bh1v.js} +2 -2
- package/dist/{cli-xhkek467.js → cli-v1v49t36.js} +28 -2
- package/dist/{cli-cn6fpa1p.js → cli-v8rpjrnx.js} +1 -1
- package/dist/{cli-mmw2sjaf.js → cli-vgh5adn9.js} +5 -5
- package/dist/{cli-3zyme1wt.js → cli-w24741sm.js} +3 -3
- package/dist/{cli-gq6qhmrr.js → cli-wsnradtk.js} +3 -3
- package/dist/{cli-nk8swfpx.js → cli-wtffytm8.js} +3 -3
- package/dist/{cli-0m77n7ej.js → cli-xc8m5cjn.js} +54 -12
- package/dist/{cli-8cmjkbvj.js → cli-y0q92v4r.js} +2 -2
- package/dist/{cli-gedf48yw.js → cli-y754psdt.js} +4 -4
- package/dist/cli.js +19 -18
- package/dist/{codex-adapter-ysfg6ty3.js → codex-adapter-493vb8cv.js} +5 -5
- package/dist/{codex-hook-c0nvm30r.js → codex-hook-ej8hn6z5.js} +9 -2
- package/dist/{codex-session-runner-823scr6g.js → codex-session-runner-ps5m4z1g.js} +5 -5
- package/dist/{commands-5rbm07fz.js → commands-shktk0b8.js} +3 -3
- package/dist/{controllers-connect-34jzhfft.js → controllers-connect-yft057ws.js} +24 -24
- package/dist/core-nheayfgm.js +42 -0
- package/dist/{cursor-adapter-w1681kp1.js → cursor-adapter-8fpm4dng.js} +1 -1
- package/dist/{db-6bkgbfwk.js → db-0ezhdhz5.js} +3 -3
- package/dist/{db-hcj16x7z.js → db-84pz2w5c.js} +2 -2
- package/dist/{dispatcher-jgjqrfzv.js → dispatcher-h2rz69f6.js} +23 -23
- package/dist/{easter-egg-3d-w17nsny6.js → easter-egg-3d-m41ad78v.js} +1 -1
- package/dist/{embedding-space-v06fwy7b.js → embedding-space-yam9zwzj.js} +6 -6
- package/dist/{embeddings-g50dxea4.js → embeddings-g2be0y8q.js} +1 -1
- package/dist/{execute-1n36haw1.js → execute-hhdejgzf.js} +1 -1
- package/dist/{external-channel-43tv8pg6.js → external-channel-kjt2yzfj.js} +2 -2
- package/dist/fx-adapter-8g7xsp8q.js +20 -0
- package/dist/{grok-adapter-my5j8mdf.js → grok-adapter-ztk2zkz1.js} +9 -9
- package/dist/handlers-9ywssz71.js +41 -0
- package/dist/{heartbeat-sf3nk937.js → heartbeat-2e5jdexj.js} +25 -25
- package/dist/{hook-dqph1e05.js → hook-34s8cmgn.js} +9 -6
- package/dist/{hook-m1m9dm6w.js → hook-acg9saz7.js} +8 -5
- package/dist/{http-w0th1cz9.js → http-ra2zr2f8.js} +304 -111
- package/dist/{index-pb03vans.js → index-2z1z7qx6.js} +26 -26
- package/dist/{index-p2f5xg64.js → index-3j803vnb.js} +36259 -34299
- package/dist/index-6mgbdtv1.js +44 -0
- package/dist/{index-e8pz8qdg.js → index-7dgxveck.js} +2 -2
- package/dist/{index-gkpfgpg7.js → index-93bw5wds.js} +1 -1
- package/dist/{index-c0e8en64.js → index-9q42cr54.js} +1 -1
- package/dist/{index-ffba0z8q.js → index-9r4j0a60.js} +28 -18
- package/dist/index-hqdsn2t2.js +39 -0
- package/dist/{index-k8ajc0g0.js → index-maddg9ys.js} +1 -1
- package/dist/{index-y4vd4mhn.js → index-mbpxhc4w.js} +1 -1
- package/dist/index-rz8ve510.js +569 -0
- package/dist/index-st231bqv.js +40 -0
- package/dist/{index-ez823q84.js → index-ym9fgxad.js} +1 -1
- package/dist/{keepalive-2v06q2e8.js → keepalive-vjnnqbkm.js} +4 -4
- package/dist/lead-mk0xkth2.js +82 -0
- package/dist/{maintenance-vx7vjhhy.js → maintenance-px2g599e.js} +1 -1
- package/dist/{oauth-refresh-sweep-g06k4bza.js → oauth-refresh-sweep-nkykf09m.js} +3 -3
- package/dist/{object-webhooks-3dzdq4fm.js → object-webhooks-gt9xnq21.js} +7 -7
- package/dist/{onboard-232pazny.js → onboard-1f134p65.js} +3 -3
- package/dist/{opencode-adapter-t0paqbh8.js → opencode-adapter-94976yab.js} +6 -6
- package/dist/{otel-impl-kmpkyp4y.js → otel-impl-5d4p2fqs.js} +1 -1
- package/dist/{pending-x0z3vx1x.js → pending-vkk0vx6n.js} +24 -24
- package/dist/{pi-mono-adapter-7pmypn6d.js → pi-mono-adapter-cyzdv5er.js} +11 -11
- package/dist/{pricing-refresh-ytjmtyd7.js → pricing-refresh-jtmjwss9.js} +2 -2
- package/dist/{rbac-roles-xyaxekh3.js → rbac-roles-1fvmdyeb.js} +2 -2
- package/dist/{rbac-roles-fgm5mxr2.js → rbac-roles-yd1fgpsn.js} +3 -3
- package/dist/{render-v2-ws972g4r.js → render-v2-kb5s3vx4.js} +8 -8
- package/dist/{resume-m6mjzhkp.js → resume-z1vs44n5.js} +11 -11
- package/dist/{runtime-zzpc0c8a.js → runtime-gk6ct7r7.js} +1 -1
- package/dist/{session-access-vp35xs91.js → session-access-nz6nre4d.js} +5 -5
- package/dist/{session-source-backfill-p73e8zbe.js → session-source-backfill-wb60zjkd.js} +1 -1
- package/dist/{setup-r4kd7rxg.js → setup-2x8g8j4s.js} +1 -1
- package/dist/thread-buffer-d50rqpev.js +42 -0
- package/dist/{tree-visibility-07h2tbs2.js → tree-visibility-ts3z30kw.js} +2 -2
- package/dist/{user-merge-jobs-96vg9rpe.js → user-merge-jobs-zetg26e0.js} +3 -3
- package/dist/{virtual-modules-vgn3f2x4.js → virtual-modules-674fka8x.js} +3 -3
- package/dist/{work-objects-74hbcx3e.js → work-objects-w52yyjxm.js} +26 -26
- package/dist/worker-662x1vse.js +82 -0
- package/dist/{worker-follow-up-ezavwn5d.js → worker-follow-up-dyfxyjbj.js} +23 -23
- package/openapi.json +6 -2
- package/package.json +7 -6
- package/src/be/migrations/341_user_token_expiry.sql +4 -0
- package/src/be/scripts/run-credential.ts +55 -1
- package/src/be/scripts/typecheck.ts +4 -4
- package/src/be/scripts/user-code-mode.ts +160 -0
- package/src/be/users.ts +48 -7
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/runner.ts +62 -6
- package/src/hooks/codex-hook.ts +15 -4
- package/src/hooks/hook.ts +7 -0
- package/src/http/script-connection-proxy.ts +18 -6
- package/src/http/scripts.ts +2 -11
- package/src/http/session-cost-recompute.ts +3 -1
- package/src/http/session-data.ts +3 -0
- package/src/http/users.ts +1 -0
- package/src/integrations/chat-sdk/adapters.ts +29 -0
- package/src/integrations/chat-sdk/limits.ts +3 -0
- package/src/integrations/chat-sdk/rocketchat/README.md +8 -0
- package/src/integrations/chat-sdk/rocketchat/index.ts +790 -0
- package/src/integrations/chat-sdk/rocketchat/markdown.ts +210 -0
- package/src/integrations/chat-sdk/rocketchat/types.ts +249 -0
- package/src/integrations/chat-sdk/runtime.ts +11 -5
- package/src/integrations/chat-sdk/schema.ts +37 -3
- package/src/integrations/chat-sdk/status.ts +9 -0
- package/src/prompts/base-prompt.ts +1 -1
- package/src/prompts/session-templates.ts +1 -1
- package/src/providers/acp-targets.ts +2 -2
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/claude-adapter.ts +21 -1
- package/src/providers/claude-sdk-session.ts +22 -3
- package/src/providers/claude-session-events.ts +76 -1
- package/src/providers/cursor-adapter.ts +1 -1
- package/src/providers/fx-adapter.ts +2 -2
- package/src/providers/pricing-sources.md +3 -0
- package/src/providers/types.ts +13 -0
- package/src/rbac/legacy-policy.ts +1 -0
- package/src/rbac/permissions.ts +4 -0
- package/src/scripts-runtime/executors/native.ts +225 -67
- package/src/scripts-runtime/mcp-client.ts +2 -1
- package/src/scripts-runtime/swarm-sdk.ts +2 -1
- package/src/scripts-runtime/types/stdlib.d.ts +4 -4
- package/src/scripts-runtime/types/swarm-sdk.d.ts +4 -4
- package/src/server-user.ts +98 -0
- package/src/slack/render-v2.ts +27 -7
- package/src/tests/base-prompt.test.ts +6 -2
- package/src/tests/chat-sdk-rocketchat-vendored.test.ts +67 -0
- package/src/tests/chat-sdk-status-route.test.ts +13 -1
- package/src/tests/claude-adapter.test.ts +115 -0
- package/src/tests/codex-app-server.test.ts +4 -6
- package/src/tests/fixtures/fx/acp-updates-recorded.jsonl +1 -1
- package/src/tests/internal-ai/complete-structured.test.ts +105 -0
- package/src/tests/internal-ai/credentials.test.ts +149 -0
- package/src/tests/internal-ai/task-title.test.ts +78 -0
- package/src/tests/mcp-input-caps.test.ts +16 -11
- package/src/tests/mcp-user-route.test.ts +10 -1
- package/src/tests/runner-slot-reconcile.test.ts +102 -0
- package/src/tests/script-connections-mcp.test.ts +14 -10
- package/src/tests/script-connections-sql.test.ts +6 -2
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/slack-render-v2.test.ts +85 -0
- package/src/tools/script-common.ts +37 -22
- package/src/tools/script-query-types.ts +1 -1
- package/src/tools/script-run.ts +1 -1
- package/src/tools/script-search.ts +12 -10
- package/src/tools/utils.ts +7 -1
- package/src/types.ts +2 -1
- package/src/utils/internal-ai/complete-structured.ts +36 -5
- package/src/utils/internal-ai/credentials.ts +78 -2
- package/src/utils/internal-ai/models.ts +37 -1
- package/src/utils/internal-ai/task-title.ts +31 -1
- package/templates/skills/chat-sdk/content.md +2 -2
- package/templates/skills/swarm-docs/content.md +10 -0
- package/dist/acp-adapter-xtj40wd8.js +0 -17
- package/dist/core-kdehq26g.js +0 -42
- package/dist/fx-adapter-bvh05t4a.js +0 -20
- package/dist/handlers-wyymeeqh.js +0 -41
- package/dist/index-22khdtby.js +0 -44
- package/dist/index-np0582ac.js +0 -40
- package/dist/index-vgkrj1jt.js +0 -39
- package/dist/lead-55z813ng.js +0 -79
- package/dist/thread-buffer-cm2nzq6t.js +0 -42
- package/dist/worker-5pn2vzx6.js +0 -79
- /package/dist/{cli-m4ejz4nj.js → cli-cah298e5.js} +0 -0
package/src/commands/runner.ts
CHANGED
|
@@ -2894,6 +2894,11 @@ export interface RunningTask {
|
|
|
2894
2894
|
lastReconcileAt?: number;
|
|
2895
2895
|
/** When the runner asked the session to abort (cancel or reconcile). */
|
|
2896
2896
|
abortRequestedAt?: number;
|
|
2897
|
+
/**
|
|
2898
|
+
* When reconcile found the task terminal and ended the session's input
|
|
2899
|
+
* instead of aborting it, so its final cost report can still arrive.
|
|
2900
|
+
*/
|
|
2901
|
+
terminalGraceStartedAt?: number;
|
|
2897
2902
|
/**
|
|
2898
2903
|
* Terminal status the server already holds for this task, found by
|
|
2899
2904
|
* `reconcileActiveTasks` or set by an API-drain handoff. Completion then only
|
|
@@ -5630,6 +5635,20 @@ export async function spawnProviderProcess(
|
|
|
5630
5635
|
export const DEFAULT_TASK_RECONCILE_INTERVAL_MS = 30_000;
|
|
5631
5636
|
/** How long an aborted session gets to settle before the runner settles it. */
|
|
5632
5637
|
export const ABORT_SETTLE_GRACE_MS = 10_000;
|
|
5638
|
+
/**
|
|
5639
|
+
* How long a session whose task turned terminal server-side may finish its
|
|
5640
|
+
* turn (and emit its cost report) after its input closes, before the abort.
|
|
5641
|
+
*/
|
|
5642
|
+
export const DEFAULT_TERMINAL_TASK_GRACE_MS = 45_000;
|
|
5643
|
+
|
|
5644
|
+
/** `RUNNER_TERMINAL_TASK_GRACE_MS` (0 aborts at once), or the default when unset or invalid. */
|
|
5645
|
+
export function resolveTerminalTaskGraceMs(
|
|
5646
|
+
env: Record<string, string | undefined> = process.env,
|
|
5647
|
+
): number {
|
|
5648
|
+
const raw = env.RUNNER_TERMINAL_TASK_GRACE_MS;
|
|
5649
|
+
const value = raw === undefined || raw.trim() === "" ? Number.NaN : Number(raw);
|
|
5650
|
+
return Number.isFinite(value) && value >= 0 ? value : DEFAULT_TERMINAL_TASK_GRACE_MS;
|
|
5651
|
+
}
|
|
5633
5652
|
|
|
5634
5653
|
/** `RUNNER_TASK_RECONCILE_INTERVAL_MS`, or the default when unset or invalid. */
|
|
5635
5654
|
export function resolveTaskReconcileIntervalMs(
|
|
@@ -5648,6 +5667,8 @@ export interface ReconcileActiveTasksOptions {
|
|
|
5648
5667
|
fetchStatus: (taskId: string) => Promise<string | null>;
|
|
5649
5668
|
intervalMs: number;
|
|
5650
5669
|
abortGraceMs?: number;
|
|
5670
|
+
/** Grace after ending input for a server-terminal task; default `DEFAULT_TERMINAL_TASK_GRACE_MS`. */
|
|
5671
|
+
terminalGraceMs?: number;
|
|
5651
5672
|
now?: () => number;
|
|
5652
5673
|
/** In push mode, fetch cancellation only for these tasks. Abort settlement still runs. */
|
|
5653
5674
|
cancelTaskIds?: ReadonlySet<string>;
|
|
@@ -5730,7 +5751,10 @@ export async function handOffTasksForApiDrain(
|
|
|
5730
5751
|
* never settles cannot hold an execution slot forever:
|
|
5731
5752
|
* - a task the server cancelled gets its session aborted (every call);
|
|
5732
5753
|
* - every `intervalMs`, a task the server already holds as terminal (for
|
|
5733
|
-
* example failed by the heartbeat sweep) gets
|
|
5754
|
+
* example completed by its own agent, or failed by the heartbeat sweep) gets
|
|
5755
|
+
* its session aborted too. A session with `finishInput` first gets its input
|
|
5756
|
+
* closed and `terminalGraceMs` to end its turn, so Claude can still emit the
|
|
5757
|
+
* `result` that carries its cost;
|
|
5734
5758
|
* - a session that has not settled `abortGraceMs` after an abort is settled
|
|
5735
5759
|
* here, and `checkCompletedProcesses` frees the slot on its next pass.
|
|
5736
5760
|
* Exported for tests.
|
|
@@ -5742,6 +5766,7 @@ export async function reconcileActiveTasks(
|
|
|
5742
5766
|
): Promise<void> {
|
|
5743
5767
|
const now = opts.now ?? Date.now;
|
|
5744
5768
|
const graceMs = opts.abortGraceMs ?? ABORT_SETTLE_GRACE_MS;
|
|
5769
|
+
const terminalGraceMs = opts.terminalGraceMs ?? DEFAULT_TERMINAL_TASK_GRACE_MS;
|
|
5745
5770
|
|
|
5746
5771
|
// Each task touches only its own entry (plus an add to the shared
|
|
5747
5772
|
// cancelledSignaled set), and both API reads swallow their errors, so the
|
|
@@ -5766,21 +5791,50 @@ export async function reconcileActiveTasks(
|
|
|
5766
5791
|
}
|
|
5767
5792
|
}
|
|
5768
5793
|
|
|
5769
|
-
if (
|
|
5794
|
+
if (
|
|
5795
|
+
task.abortRequestedAt === undefined &&
|
|
5796
|
+
task.terminalGraceStartedAt === undefined &&
|
|
5797
|
+
opts.checkStatus !== false
|
|
5798
|
+
) {
|
|
5770
5799
|
const lastCheck = task.lastReconcileAt ?? task.startTime.getTime();
|
|
5771
5800
|
if (now() - lastCheck >= opts.intervalMs) {
|
|
5772
5801
|
task.lastReconcileAt = now();
|
|
5773
5802
|
const status = await opts.fetchStatus(taskId).catch(() => null);
|
|
5774
5803
|
if (status && isTerminalTaskStatus(status)) {
|
|
5775
|
-
console.warn(
|
|
5776
|
-
`[${role}] Task ${taskId.slice(0, 8)} is ${status} server-side but its session is still running — aborting it`,
|
|
5777
|
-
);
|
|
5778
5804
|
task.serverTerminalStatus = status;
|
|
5779
|
-
|
|
5805
|
+
// A cancel means stop now; the other terminal states let the turn end.
|
|
5806
|
+
if (task.session.finishInput && terminalGraceMs > 0 && status !== "cancelled") {
|
|
5807
|
+
console.warn(
|
|
5808
|
+
`[${role}] Task ${taskId.slice(0, 8)} is ${status} server-side but its session is still running — closing its input, abort in ${terminalGraceMs}ms`,
|
|
5809
|
+
);
|
|
5810
|
+
task.terminalGraceStartedAt = now();
|
|
5811
|
+
try {
|
|
5812
|
+
task.session.finishInput();
|
|
5813
|
+
} catch {
|
|
5814
|
+
// The abort below still runs when the grace ends.
|
|
5815
|
+
}
|
|
5816
|
+
} else {
|
|
5817
|
+
console.warn(
|
|
5818
|
+
`[${role}] Task ${taskId.slice(0, 8)} is ${status} server-side but its session is still running — aborting it`,
|
|
5819
|
+
);
|
|
5820
|
+
requestSessionAbort(task, `server task ${status}`, now());
|
|
5821
|
+
}
|
|
5780
5822
|
}
|
|
5781
5823
|
}
|
|
5782
5824
|
}
|
|
5783
5825
|
|
|
5826
|
+
if (
|
|
5827
|
+
task.terminalGraceStartedAt !== undefined &&
|
|
5828
|
+
task.abortRequestedAt === undefined &&
|
|
5829
|
+
task.result === null &&
|
|
5830
|
+
now() - task.terminalGraceStartedAt >= terminalGraceMs
|
|
5831
|
+
) {
|
|
5832
|
+
console.warn(
|
|
5833
|
+
`[${role}] Task ${taskId.slice(0, 8)} session did not end ${terminalGraceMs}ms after its input closed — aborting it`,
|
|
5834
|
+
);
|
|
5835
|
+
requestSessionAbort(task, `server task ${task.serverTerminalStatus}`, now());
|
|
5836
|
+
}
|
|
5837
|
+
|
|
5784
5838
|
if (
|
|
5785
5839
|
task.abortRequestedAt !== undefined &&
|
|
5786
5840
|
task.result === null &&
|
|
@@ -7550,6 +7604,7 @@ export async function runAgent(config: RunnerConfig, opts: RunnerOptions) {
|
|
|
7550
7604
|
let lastOrphanRecoveryAt = 0;
|
|
7551
7605
|
const ORPHAN_RECOVERY_INTERVAL_MS = 60_000;
|
|
7552
7606
|
const taskReconcileIntervalMs = resolveTaskReconcileIntervalMs();
|
|
7607
|
+
const terminalTaskGraceMs = resolveTerminalTaskGraceMs();
|
|
7553
7608
|
|
|
7554
7609
|
while (shouldRunDeliveryLoop(state.deliveryMode, shuttingDown)) {
|
|
7555
7610
|
const deliveryChecks = pushDelivery.checks(state.deliveryMode ?? "poll");
|
|
@@ -7663,6 +7718,7 @@ export async function runAgent(config: RunnerConfig, opts: RunnerOptions) {
|
|
|
7663
7718
|
isCancelled: (taskId) => fetchTaskCancelled(apiUrl, apiKey, agentId, taskId),
|
|
7664
7719
|
fetchStatus: (taskId) => fetchTaskStatus(apiUrl, apiKey, taskId),
|
|
7665
7720
|
intervalMs: taskReconcileIntervalMs,
|
|
7721
|
+
terminalGraceMs: terminalTaskGraceMs,
|
|
7666
7722
|
...taskReconciliation(deliveryChecks),
|
|
7667
7723
|
});
|
|
7668
7724
|
}
|
package/src/hooks/codex-hook.ts
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*
|
|
26
26
|
* Native tool calls (Bash, apply_patch) also go to `POST /api/tool-hooks`
|
|
27
27
|
* (`native-tool-hooks.ts`), so an extension with `toolSources: ["native"]`
|
|
28
|
-
* can observe, block (exit 2) or rewrite a Bash command (`updatedInput`).
|
|
28
|
+
* can observe, block (exit 2) or rewrite a Bash command or an apply_patch patch (`updatedInput`).
|
|
29
29
|
*
|
|
30
30
|
* One-shot guarantee: a message is included in hook output only after its
|
|
31
31
|
* `/delivered` POST succeeded, so a message is injected at most once. A
|
|
@@ -220,6 +220,12 @@ function nativeTargetOf(config: CodexHookConfig | null): NativeHookTarget | unde
|
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Codex tools whose `hookSpecificOutput.updatedInput` rewrite a real codex-cli 0.169.0 run applied
|
|
225
|
+
* (the rewritten patch, not the original, landed on disk). Re-check on a codex upgrade.
|
|
226
|
+
*/
|
|
227
|
+
const CODEX_REWRITABLE_TOOLS = new Set(["bash", "apply_patch"]);
|
|
228
|
+
|
|
223
229
|
export type CodexNativePre =
|
|
224
230
|
| { action: "continue" }
|
|
225
231
|
| { action: "block"; reason: string }
|
|
@@ -238,9 +244,14 @@ export async function codexNativePre(
|
|
|
238
244
|
if (msg.hook_event_name !== "PreToolUse" || !call || !target) return { action: "continue" };
|
|
239
245
|
const decision = await runNativePre(target, call, fetchImpl);
|
|
240
246
|
if (decision.action === "block") return decision;
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
247
|
+
if (decision.action === "modify") {
|
|
248
|
+
// A rewrite codex was never seen to apply fails closed, so it is never silently dropped.
|
|
249
|
+
if (!CODEX_REWRITABLE_TOOLS.has(call.tool)) {
|
|
250
|
+
return {
|
|
251
|
+
action: "block",
|
|
252
|
+
reason: `An extension rewrote this ${call.nativeTool} call, but codex cannot apply the rewrite in place. Retry with these arguments: ${JSON.stringify(decision.args)}`,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
244
255
|
// The rewrite is input the PreToolUse guards never saw: check the final command too.
|
|
245
256
|
const reason = await codexPreToolUseBlock(
|
|
246
257
|
{ ...msg, tool_input: decision.args },
|
package/src/hooks/hook.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
3
|
import pkg from "../../package.json";
|
|
4
|
+
// Side-effect import, FIRST: the Stop hook is the claude session-summary path,
|
|
5
|
+
// and this file is also a standalone entry (`bun src/hooks/hook.ts`) that does
|
|
6
|
+
// not pass through `src/cli.tsx`. A compiled worker binary resolves pi-ai's
|
|
7
|
+
// lazy Bedrock import only when the module has been wired statically, so without
|
|
8
|
+
// this the summarizer silently could not use Bedrock. No-op when running from
|
|
9
|
+
// node_modules.
|
|
10
|
+
import "../utils/internal-ai/register-bedrock.ts";
|
|
4
11
|
import {
|
|
5
12
|
buildRatingsFromLlm,
|
|
6
13
|
dedupeRetrievalsForRater,
|
|
@@ -4,7 +4,7 @@ import { getAgentById } from "@/be/db";
|
|
|
4
4
|
import { callMcpServerTool } from "@/be/mcp-proxy";
|
|
5
5
|
import { getScriptConnectionById } from "@/be/script-connections";
|
|
6
6
|
import { resolveSqlDsn, runReadOnlyQuery } from "@/be/sql-connections";
|
|
7
|
-
import { can } from "@/rbac";
|
|
7
|
+
import { can, type RbacPrincipal } from "@/rbac";
|
|
8
8
|
import { scrubSecrets } from "@/utils/secret-scrubber";
|
|
9
9
|
import { route } from "./route-def";
|
|
10
10
|
import { jsonError } from "./utils";
|
|
@@ -88,12 +88,23 @@ function connectionScopeMatches(
|
|
|
88
88
|
connection: { scope: string; scopeId: string | null },
|
|
89
89
|
agentId: string,
|
|
90
90
|
syntheticPrincipal: boolean,
|
|
91
|
+
principal: RbacPrincipal,
|
|
91
92
|
): boolean {
|
|
92
93
|
if (connection.scope === "global") return true;
|
|
93
94
|
if (connection.scope === "agent") return !syntheticPrincipal && connection.scopeId === agentId;
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
if (connection.scope === "repo")
|
|
95
|
+
// The proxy has no repo context to compare with scopeId, and a repo-scoped connection resolves
|
|
96
|
+
// repo secret rows. Require the same grant that reads those rows on /api/config/resolved.
|
|
97
|
+
if (connection.scope === "repo") {
|
|
98
|
+
return (
|
|
99
|
+
!syntheticPrincipal &&
|
|
100
|
+
can({
|
|
101
|
+
principal,
|
|
102
|
+
verb: "config.read.secrets",
|
|
103
|
+
resource: { kind: "none" },
|
|
104
|
+
source: "http",
|
|
105
|
+
}).allow
|
|
106
|
+
);
|
|
107
|
+
}
|
|
97
108
|
return false;
|
|
98
109
|
}
|
|
99
110
|
|
|
@@ -127,8 +138,9 @@ export async function handleScriptConnectionProxy(
|
|
|
127
138
|
return true;
|
|
128
139
|
}
|
|
129
140
|
|
|
141
|
+
const principal: RbacPrincipal = { kind: "agent", agentId, isLead: agent?.isLead ?? false };
|
|
130
142
|
const decision = can({
|
|
131
|
-
principal
|
|
143
|
+
principal,
|
|
132
144
|
verb: "script-connection.invoke",
|
|
133
145
|
resource: { kind: "none" },
|
|
134
146
|
source: "http",
|
|
@@ -151,7 +163,7 @@ export async function handleScriptConnectionProxy(
|
|
|
151
163
|
jsonError(res, `Script connection is not ${isSql ? "a SQL" : "an MCP"} connection`, 400);
|
|
152
164
|
return true;
|
|
153
165
|
}
|
|
154
|
-
if (!connectionScopeMatches(connection, agentId, syntheticPrincipal)) {
|
|
166
|
+
if (!connectionScopeMatches(connection, agentId, syntheticPrincipal, principal)) {
|
|
155
167
|
jsonError(res, "Script connection is not available to this agent", 403);
|
|
156
168
|
return true;
|
|
157
169
|
}
|
package/src/http/scripts.ts
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
scriptStdlibTypesWithGeneratedApis,
|
|
40
40
|
typecheckScript,
|
|
41
41
|
} from "../be/scripts/typecheck";
|
|
42
|
+
import { toScriptSearchResults } from "../be/scripts/user-code-mode";
|
|
42
43
|
import { can } from "../rbac";
|
|
43
44
|
import { isExecutorAllowedByDeployment } from "../scripts-runtime/executors/registry";
|
|
44
45
|
import { extractScriptSignature, type ScriptSignature } from "../scripts-runtime/extract-signature";
|
|
@@ -962,17 +963,7 @@ export async function handleScripts(
|
|
|
962
963
|
limit: parsed.body.limit,
|
|
963
964
|
});
|
|
964
965
|
|
|
965
|
-
searchRoute.respond(res, 200, {
|
|
966
|
-
results: matches.map(({ script, score }) => ({
|
|
967
|
-
name: script.name,
|
|
968
|
-
signature: JSON.parse(script.signatureJson),
|
|
969
|
-
argsJsonSchema: script.argsJsonSchema
|
|
970
|
-
? (JSON.parse(script.argsJsonSchema) as Record<string, unknown>)
|
|
971
|
-
: null,
|
|
972
|
-
description: script.description,
|
|
973
|
-
score,
|
|
974
|
-
})),
|
|
975
|
-
});
|
|
966
|
+
searchRoute.respond(res, 200, { results: toScriptSearchResults(matches) });
|
|
976
967
|
return true;
|
|
977
968
|
}
|
|
978
969
|
|
|
@@ -33,6 +33,8 @@ interface SessionCostRecomputeInput {
|
|
|
33
33
|
harnessCostUsd: number;
|
|
34
34
|
/** `harnessCostUsd` is the provider's bill, not a token estimate. */
|
|
35
35
|
harnessCostBilled?: boolean;
|
|
36
|
+
/** The token counts are a fallback sum, so a priced row is tagged `estimated`. */
|
|
37
|
+
estimated?: boolean;
|
|
36
38
|
inputTokens: number;
|
|
37
39
|
outputTokens: number;
|
|
38
40
|
cacheReadTokens: number;
|
|
@@ -278,7 +280,7 @@ export async function recomputeSessionCost(
|
|
|
278
280
|
|
|
279
281
|
return {
|
|
280
282
|
totalCostUsd: pricedCostUsd + sessionFeesUsd,
|
|
281
|
-
costSource: "pricing-table",
|
|
283
|
+
costSource: input.estimated ? "estimated" : "pricing-table",
|
|
282
284
|
modelBreakdown: modelUsageEntries ? pricedModels : undefined,
|
|
283
285
|
};
|
|
284
286
|
}
|
package/src/http/session-data.ts
CHANGED
|
@@ -202,6 +202,8 @@ const createSessionCostRoute = route({
|
|
|
202
202
|
// The adapter's totalCostUsd is the provider's bill (e.g. OpenRouter's
|
|
203
203
|
// `usage.cost`), so it wins over the pricing table.
|
|
204
204
|
harnessCostBilled: z.boolean().optional(),
|
|
205
|
+
// Token counts summed from per-message usage; the priced row is tagged `estimated`.
|
|
206
|
+
estimated: z.boolean().optional(),
|
|
205
207
|
taskId: z.string().optional(),
|
|
206
208
|
// Phase 3: non-negative — the recompute no longer clamps, so negative
|
|
207
209
|
// token counts must be rejected at the wire instead of pricing below $0.
|
|
@@ -451,6 +453,7 @@ export async function handleSessionData(
|
|
|
451
453
|
model,
|
|
452
454
|
harnessCostUsd: parsed.body.totalCostUsd,
|
|
453
455
|
harnessCostBilled: parsed.body.harnessCostBilled,
|
|
456
|
+
estimated: parsed.body.estimated,
|
|
454
457
|
inputTokens,
|
|
455
458
|
outputTokens,
|
|
456
459
|
cacheReadTokens: cachedInputTokens,
|
package/src/http/users.ts
CHANGED
|
@@ -15,12 +15,20 @@ import { getChatSdkTestHooks } from "./test-hooks";
|
|
|
15
15
|
* `CLIENT_SECRET`, `MANAGED_IDENTITY_CLIENT_ID`, `CLOUD`) are closed by the
|
|
16
16
|
* injection denylist in `getInjectableGlobalConfigs` (`src/be/db.ts`).
|
|
17
17
|
* Deployment env can still set them on purpose.
|
|
18
|
+
*
|
|
19
|
+
* Rocket.Chat is self-hosted and has no platform default, so its entry is ""
|
|
20
|
+
* and `CHAT_SDK_API_URL_OVERRIDES.rocketchat` carries the instance URL. The
|
|
21
|
+
* adapter rejects an empty one, which surfaces as an adapter health error.
|
|
18
22
|
*/
|
|
23
|
+
/** The bot name used when the operator set none. Chat requires one. */
|
|
24
|
+
export const DEFAULT_BOT_USER_NAME = "swarm";
|
|
25
|
+
|
|
19
26
|
const DEFAULT_API_URLS: Record<ChatSdkAdapterName, string> = {
|
|
20
27
|
telegram: "https://api.telegram.org",
|
|
21
28
|
slack: "https://slack.com/api/",
|
|
22
29
|
discord: "https://discord.com/api/v10",
|
|
23
30
|
teams: "",
|
|
31
|
+
rocketchat: "",
|
|
24
32
|
};
|
|
25
33
|
|
|
26
34
|
/**
|
|
@@ -124,6 +132,27 @@ export async function loadAdapter(
|
|
|
124
132
|
...(teamsToken ? { token: teamsToken } : {}),
|
|
125
133
|
} as Parameters<typeof createTeamsAdapter>[0]);
|
|
126
134
|
}
|
|
135
|
+
case "rocketchat": {
|
|
136
|
+
const { createRocketChatAdapter } = await import("./rocketchat");
|
|
137
|
+
// The adapter takes the instance as `baseUrl`, not `apiUrl`, and falls
|
|
138
|
+
// back to ROCKETCHAT_URL / ROCKETCHAT_TOKEN / ROCKETCHAT_USER_ID /
|
|
139
|
+
// ROCKETCHAT_WEBHOOK_TOKEN / ROCKETCHAT_BOT_USERNAME from `process.env`.
|
|
140
|
+
// Global swarm_config rows are injected into env, so every one of those
|
|
141
|
+
// is passed explicitly: an env fallback would let a config row redirect
|
|
142
|
+
// the bot token to another host. `baseUrl` comes from the env-only
|
|
143
|
+
// `CHAT_SDK_API_URL_OVERRIDES`, never from the adapter config.
|
|
144
|
+
const { apiUrl: _apiUrl, ...rest } = base;
|
|
145
|
+
return createRocketChatAdapter({
|
|
146
|
+
...rest,
|
|
147
|
+
baseUrl: apiUrl,
|
|
148
|
+
token: typeof config.token === "string" ? config.token : "",
|
|
149
|
+
botUserId: typeof config.botUserId === "string" ? config.botUserId : "",
|
|
150
|
+
webhookToken: typeof config.webhookToken === "string" ? config.webhookToken : "",
|
|
151
|
+
// Required by the schema: mention detection matches `@<userName>` in
|
|
152
|
+
// the text, and the REST API offers no way to look the name up.
|
|
153
|
+
userName: typeof config.userName === "string" ? config.userName : "",
|
|
154
|
+
} as Parameters<typeof createRocketChatAdapter>[0]);
|
|
155
|
+
}
|
|
127
156
|
}
|
|
128
157
|
}
|
|
129
158
|
|
|
@@ -10,6 +10,9 @@ const CHAT_MESSAGE_LIMITS: Record<string, number> = {
|
|
|
10
10
|
// guidance for one readable message and stays well under that cap.
|
|
11
11
|
slack: 4000,
|
|
12
12
|
teams: 20000,
|
|
13
|
+
// Rocket.Chat's `Message_MaxAllowedSize` default. An administrator can raise
|
|
14
|
+
// it per workspace; this stays at the default so a message is never refused.
|
|
15
|
+
rocketchat: 5000,
|
|
13
16
|
};
|
|
14
17
|
|
|
15
18
|
/** Used for an adapter without an entry: the smallest known limit. */
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Rocket.Chat adapter
|
|
2
|
+
|
|
3
|
+
The Chat SDK adapter for Rocket.Chat, kept in this repo so the integration adds no npm dependency.
|
|
4
|
+
|
|
5
|
+
- Files: `index.ts` (the adapter), `markdown.ts` (format conversion), `types.ts` (REST and webhook payload types).
|
|
6
|
+
- `adapters.ts` loads it with a dynamic `import("./rocketchat")`, so it loads only when the `rocketchat` adapter is configured.
|
|
7
|
+
- REST calls send `redirect: "error"`, so the auth header never follows a redirect. Configure the instance's final URL.
|
|
8
|
+
- The webhook token check compares SHA-256 digests with `timingSafeEqual`.
|