@desplega.ai/agent-swarm 1.161.0 → 1.162.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 +3 -2
- package/dist/{acp-adapter-xx489vvb.js → acp-adapter-74m73ae9.js} +1 -1
- package/dist/{actions-ykjkn0m9.js → actions-4sr14gnt.js} +34 -31
- package/dist/{anthropic-messages-5qx80j9k.js → anthropic-messages-8xxrzky9.js} +22 -26
- package/dist/{app-0hdqa4k1.js → app-pt68fbwp.js} +13 -11
- package/dist/{artifact-3v5t9jtg.js → artifact-fey7dvj9.js} +3 -2
- package/dist/{assistant-am2g5g8a.js → assistant-cv3jytks.js} +37 -34
- package/dist/{azure-openai-responses-fszbkp0e.js → azure-openai-responses-f5cqsyj8.js} +15 -10
- package/dist/{boot-reembed-xy9t7avg.js → boot-reembed-4ht4gqth.js} +13 -11
- package/dist/{boot-reembed-gt5gjkt4.js → boot-reembed-nxpcvpj9.js} +12 -10
- package/dist/{boot-scrub-logs-9x0985y5.js → boot-scrub-logs-k93kyw8k.js} +9 -7
- package/dist/{boot-seeds-trv0d4vg.js → boot-seeds-1skcrs0e.js} +13 -10
- package/dist/{claude-adapter-jb6e1e54.js → claude-adapter-r5g0tzge.js} +23 -20
- package/dist/{claude-managed-setup-d1q9hv2b.js → claude-managed-setup-pkyrgshb.js} +3 -2
- package/dist/{claude-sdk-session-zga700s2.js → claude-sdk-session-jxyxnrwd.js} +5565 -5512
- package/dist/{cli-we0q7t0e.js → cli-2zy95vhm.js} +137 -64
- package/dist/{cli-35pj2yva.js → cli-4cwxn7gp.js} +38 -11
- package/dist/{cli-ad4qxm6j.js → cli-4dcpaefp.js} +2 -2
- package/dist/{cli-82c1pacn.js → cli-4x0csdjq.js} +71 -37
- package/dist/{cli-sqm3r5ps.js → cli-5bcd7sfy.js} +14 -18
- package/dist/{cli-d56tgd45.js → cli-5k6k8ta3.js} +2 -2
- package/dist/{cli-1er0rhz8.js → cli-5xhpb3kv.js} +15 -15
- package/dist/{cli-yrg7c73k.js → cli-7af8yhav.js} +10 -183
- package/dist/{cli-r6fsxc76.js → cli-7tre70zp.js} +513 -961
- package/dist/{cli-bh7jed3k.js → cli-8ev9xqnx.js} +34 -18
- package/dist/cli-bsky8g7w.js +449 -0
- package/dist/{cli-hn04t9db.js → cli-cebmgwsc.js} +14 -10
- package/dist/{cli-cfkrztza.js → cli-cvatsam7.js} +2 -2
- package/dist/{cli-2658f6at.js → cli-cvk6yzw5.js} +6 -8
- package/dist/{cli-ptr8h7kp.js → cli-eg0b3p0k.js} +5 -218
- package/dist/{cli-zb6xbk61.js → cli-g739zqzt.js} +4 -4
- package/dist/{cli-dv6cdjs2.js → cli-gd4favx9.js} +28 -7
- package/dist/{cli-5p3x4zna.js → cli-gpqpmns7.js} +2 -2
- package/dist/{cli-5nbmpy8w.js → cli-hb5c2x5y.js} +1 -1
- package/dist/{cli-jpf7e1zq.js → cli-hmsw1gpy.js} +3 -3
- package/dist/{cli-1cz0c18q.js → cli-jf7wmv1r.js} +2521 -733
- package/dist/{cli-qwsnmjdd.js → cli-jxs2ygaw.js} +168 -61
- package/dist/cli-kdkwd3yr.js +615 -0
- package/dist/{cli-hgmnf38m.js → cli-kh04eqwe.js} +1 -1
- package/dist/{cli-0383bp7f.js → cli-kp42yek0.js} +425 -90
- package/dist/{cli-ybgv4kw2.js → cli-mbssg1xv.js} +9 -2
- package/dist/{cli-jsp14b6c.js → cli-mzfth0bp.js} +38 -1
- package/dist/{cli-8g6mc14k.js → cli-nq7yqw7b.js} +16 -5
- package/dist/{cli-ee8bc46j.js → cli-nt8hecg9.js} +33 -32
- package/dist/{cli-9s68w752.js → cli-p0r8sxj5.js} +1 -1
- package/dist/{cli-58e8yr0d.js → cli-pkd6s2wy.js} +4 -2
- package/dist/{cli-17xpf7cm.js → cli-q24re23n.js} +6 -4
- package/dist/cli-qjjvzwzd.js +222 -0
- package/dist/cli-qrgt5bqf.js +189 -0
- package/dist/{cli-et8m9xsv.js → cli-rfjw9jw2.js} +22 -10
- package/dist/{cli-798vkbks.js → cli-rj0gqwwp.js} +2 -2
- package/dist/{cli-121ph74b.js → cli-rnyzn44p.js} +1 -1
- package/dist/{cli-vnnz5ncg.js → cli-s3hwpt9v.js} +95 -16
- package/dist/{cli-7119ja3w.js → cli-sptrj5f5.js} +2 -2
- package/dist/{cli-a8c82p2t.js → cli-sqvfa090.js} +13 -6
- package/dist/{cli-phfg8vy8.js → cli-swfmp1fx.js} +26 -26
- package/dist/{cli-nsdxtcbg.js → cli-tcen9p5w.js} +8 -5
- package/dist/{cli-9m03pzga.js → cli-vc9bp061.js} +5 -5
- package/dist/{cli-rtx9dygp.js → cli-vxe6qa4h.js} +1 -1
- package/dist/{cli-ecfxwnyb.js → cli-vy3ed88x.js} +1 -1
- package/dist/{cli-0c7ata9h.js → cli-vyqs9ya8.js} +6 -6
- package/dist/cli-wbvnn6tk.js +861 -0
- package/dist/{cli-kgd3p0bm.js → cli-wjgs5wxe.js} +6 -6
- package/dist/cli-wxkkd0e0.js +33 -0
- package/dist/{cli-akfj32vj.js → cli-xqpk3rp7.js} +5 -4
- package/dist/cli-zp38xvtm.js +9487 -0
- package/dist/{cli-3zc55ctx.js → cli-zvhd3f64.js} +2 -2
- package/dist/{cli-ze1d3wzv.js → cli-zxqx25nz.js} +5 -5
- package/dist/cli.js +32 -25
- package/dist/{cloudflare-workers-ai-system-one-k6fbxw9d.js → cloudflare-workers-ai-system-one-k8ddqjkq.js} +8 -6
- package/dist/{codex-adapter-04v97vep.js → codex-adapter-esvmnhn7.js} +13 -13
- package/dist/{codex-hook-20me6byw.js → codex-hook-m73jmqgx.js} +19 -3
- package/dist/{codex-session-runner-ax69mqq3.js → codex-session-runner-ban9excr.js} +13 -13
- package/dist/{commands-18gy08n1.js → commands-75413p2n.js} +9 -7
- package/dist/{db-d2pvjpyt.js → db-7f5pecwg.js} +11 -7
- package/dist/{dispatcher-8wbwyzjg.js → dispatcher-fh9at8nz.js} +33 -30
- package/dist/{dsh-adapter-ysqk9snv.js → dsh-adapter-wpze65d4.js} +3 -3
- package/dist/{e2b-esmt1r16.js → e2b-gjgdjp91.js} +10 -9
- package/dist/{pi-logo-animation-e9a0t68z.js → easter-egg-3d-3w5c2n4c.js} +122 -68
- package/dist/{execute-cmagrbrz.js → execute-f50wg9nh.js} +29 -6
- package/dist/{google-generative-ai-k6n5nbpp.js → google-generative-ai-jxxpnegy.js} +2 -2
- package/dist/{google-vertex-44xxtcvp.js → google-vertex-x7q1angm.js} +5 -5
- package/dist/{handlers-6b69m5kp.js → handlers-w13787bb.js} +36 -33
- package/dist/{hook-srnkt0hb.js → hook-46g1jrvx.js} +28 -15
- package/dist/{hook-k3mydf2n.js → hook-4tpts2ry.js} +20 -17
- package/dist/{http-hrf80ca1.js → http-19pzbfrt.js} +964 -176
- package/dist/{index-9rxdvj6w.js → index-8fd4dm4h.js} +34 -31
- package/dist/{index-1asbaj62.js → index-dqmp15bq.js} +35 -32
- package/dist/{index-45evq4ee.js → index-qb4q1y3e.js} +33 -30
- package/dist/{index-k4nj18qs.js → index-s75wc4wd.js} +12 -10
- package/dist/{index-xmevk2b9.js → index-scptvdxg.js} +27 -25
- package/dist/{keepalive-sfdz6ksp.js → keepalive-xa5ts9cd.js} +11 -9
- package/dist/{lead-ej91e9hw.js → lead-qp4xkvjq.js} +45 -41
- package/dist/{maintenance-80dnd7ke.js → maintenance-rm5885hm.js} +13 -11
- package/dist/{mistral-conversations-pc3ntnxt.js → mistral-conversations-rw7fbt22.js} +4 -4
- package/dist/{node-a5e00qhp.js → node-8zkdq42h.js} +834 -833
- package/dist/{oauth-refresh-sweep-m1etk2mx.js → oauth-refresh-sweep-1csdfebf.js} +10 -8
- package/dist/{onboard-0q8sdfqc.js → onboard-r6b78cs4.js} +10 -10
- package/dist/{openai-codex-responses-n7n683p2.js → openai-codex-responses-efvrgrq3.js} +4 -4
- package/dist/{openai-completions-jpaj5g2b.js → openai-completions-bbbrrz4z.js} +12 -8
- package/dist/{openai-responses-9a3nme9j.js → openai-responses-9jjyrcm1.js} +15 -10
- package/dist/{opencode-adapter-4wcgmvgf.js → opencode-adapter-kb3g6pkf.js} +2 -2
- package/dist/{otel-impl-hnqm9mxq.js → otel-impl-0y9knpky.js} +5 -5
- package/dist/{pi-mono-adapter-d6sqm9wr.js → pi-mono-adapter-z6s1bme2.js} +100 -19
- package/dist/{pricing-refresh-y60z64pm.js → pricing-refresh-mth26tgp.js} +11 -9
- package/dist/{rbac-roles-8pa0754b.js → rbac-roles-kwntb23q.js} +13 -9
- package/dist/rbac-roles-vpk4ebm8.js +45 -0
- package/dist/{registry-v5wytg0s.js → registry-km6t1jd2.js} +1 -1
- package/dist/{render-v2-418s1vj7.js → render-v2-hcm7h00y.js} +13 -11
- package/dist/{runtime-3pknc168.js → runtime-vfjsfsc5.js} +4 -4
- package/dist/{setup-yghdkj4x.js → setup-hbyzd65h.js} +2 -2
- package/dist/{virtual-modules-jcceevt5.js → virtual-modules-9bv7ry91.js} +9 -8
- package/dist/{work-objects-j1sz20v9.js → work-objects-m09sxnhe.js} +36 -33
- package/dist/{worker-d4gcvkjt.js → worker-0h35rvk4.js} +45 -41
- package/openapi.json +491 -12
- package/package.json +13 -6
- package/src/be/api-drain.ts +184 -0
- package/src/be/db/tasks/read.ts +31 -6
- package/src/be/db/tasks/write.ts +5 -4
- package/src/be/db.ts +42 -18
- package/src/be/memory/link-resolver.ts +29 -3
- package/src/be/migrations/192_favorites_agent_fs_path.sql +36 -0
- package/src/be/onboarding.ts +7 -1
- package/src/be/seed-prompt-templates.ts +1 -0
- package/src/be/swarm-config-guard.ts +35 -16
- package/src/be/task-citations.ts +11 -5
- package/src/be/users.ts +3 -0
- package/src/cli.tsx +3 -2
- package/src/comb/agent-fs.ts +39 -0
- package/src/comb/config.ts +37 -0
- package/src/comb/markers.ts +37 -0
- package/src/comb/review-batch.ts +486 -0
- package/src/comb/templates.ts +88 -0
- package/src/commands/context-preamble.ts +4 -1
- package/src/commands/hook.ts +2 -1
- package/src/commands/runner.ts +262 -68
- package/src/commands/templates.ts +10 -0
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/fs/agent-fs-provider.ts +106 -2
- package/src/heartbeat/heartbeat.ts +4 -0
- package/src/hooks/codex-hook.ts +25 -1
- package/src/hooks/hook.ts +13 -0
- package/src/hooks/pr-body-guard.ts +983 -0
- package/src/http/all-routes.ts +1 -0
- package/src/http/assets.ts +5 -17
- package/src/http/comb.ts +131 -0
- package/src/http/core.ts +2 -1
- package/src/http/fs.ts +9 -17
- package/src/http/index.ts +23 -9
- package/src/http/onboarding.ts +21 -2
- package/src/http/poll.ts +30 -3
- package/src/http/realtime.ts +62 -0
- package/src/http/request-principal.ts +22 -0
- package/src/http/status.ts +34 -2
- package/src/kv-reserved-namespaces.ts +10 -5
- package/src/providers/dsh-adapter.ts +1 -1
- package/src/providers/pi-mono-adapter.ts +123 -0
- package/src/rbac/legacy-policy.ts +1 -0
- package/src/rbac/permissions.ts +4 -0
- package/src/realtime/auth.ts +63 -1
- package/src/realtime/tickets.ts +52 -0
- package/src/realtime/transport.ts +51 -22
- package/src/scripts-runtime/types/swarm-extension.d.ts +3 -1
- package/src/telemetry-context.ts +175 -0
- package/src/telemetry-contract/EVENTS.md +81 -0
- package/src/telemetry-contract/SOURCE.json +9 -0
- package/src/telemetry-contract/catalog.json +1335 -0
- package/src/telemetry-contract/index.ts +60 -0
- package/src/telemetry-contract/types.gen.ts +1971 -0
- package/src/telemetry-identity.ts +129 -0
- package/src/telemetry-snapshot.ts +211 -0
- package/src/telemetry-trigger.ts +125 -0
- package/src/telemetry-types.typetest.ts +40 -0
- package/src/telemetry.ts +271 -67
- package/src/tests/api-drain-e2e.test.ts +249 -0
- package/src/tests/api-drain-worker-e2e.test.ts +216 -0
- package/src/tests/api-drain.test.ts +351 -0
- package/src/tests/comb-config-guard.test.ts +38 -0
- package/src/tests/comb-links.test.ts +162 -0
- package/src/tests/comb-markers.test.ts +68 -0
- package/src/tests/comb-review-batch.test.ts +770 -0
- package/src/tests/comb-status.test.ts +152 -0
- package/src/tests/db-task-read-contract.test.ts +2 -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/dsh-adapter.test.ts +1 -1
- package/src/tests/favorites-agent-fs-path.test.ts +226 -0
- package/src/tests/memory-link-resolver.test.ts +34 -0
- package/src/tests/onboarding.test.ts +108 -0
- package/src/tests/pi-mono-adapter.test.ts +265 -2
- package/src/tests/pr-body-leaks.test.ts +789 -0
- package/src/tests/preload.ts +8 -0
- package/src/tests/rbac-engine.test.ts +19 -0
- package/src/tests/realtime-room-auth.test.ts +104 -1
- package/src/tests/realtime-tickets.test.ts +74 -0
- package/src/tests/realtime-transport.test.ts +131 -4
- package/src/tests/runner-api-drain.test.ts +301 -0
- package/src/tests/runner-fallback-output.test.ts +61 -0
- package/src/tests/runner-fenced-json-output.test.ts +178 -0
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/send-task-requested-by.test.ts +133 -15
- package/src/tests/task-lifecycle-telemetry.test.ts +8 -3
- package/src/tests/telemetry-context.test.ts +314 -0
- package/src/tests/telemetry-init.test.ts +51 -19
- package/src/tests/telemetry-snapshot.test.ts +229 -0
- package/src/tests/telemetry-trigger.test.ts +200 -0
- package/src/tests/template-registry-helpers.ts +1 -0
- package/src/tests/workflow-agent-task-retry.test.ts +363 -0
- package/src/tests/workflow-definition-telemetry.test.ts +4 -4
- package/src/tools/poll-task.ts +20 -1
- package/src/tools/send-task.ts +9 -1
- package/src/tools/task-action.ts +11 -0
- package/src/types.ts +2 -1
- package/src/utils/api-drain.ts +24 -0
- package/src/utils/constants.ts +57 -16
- package/src/utils/pr-body-leaks.ts +172 -0
- package/src/utils/task-attachment-links.ts +14 -8
- package/src/workflows/recovery.ts +26 -1
- package/src/workflows/resume.ts +31 -4
- package/src/workflows/task-step-routing.ts +75 -2
- package/tsconfig.json +3 -0
- package/dist/cli-tjf4cn8z.js +0 -9119
- package/dist/cli-tsk3nz8a.js +0 -582
- package/dist/{cli-t6v2ah3r.js → cli-twrh04ap.js} +3 -3
|
@@ -2,6 +2,7 @@ import { afterAll, afterEach, beforeAll, describe, expect, spyOn, test } from "b
|
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import * as piCodingAgent from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { configureHttpResolver, resetHttpResolver } from "../prompts/resolver";
|
|
5
6
|
import {
|
|
6
7
|
createPiRuntimeAuth,
|
|
7
8
|
extractPiAssistantText,
|
|
@@ -695,13 +696,24 @@ function autoRetryEnd(success: boolean, finalError?: string): AgentSessionEvent
|
|
|
695
696
|
* exception to catch at the agent-swarm layer.
|
|
696
697
|
*/
|
|
697
698
|
function makeMockAgentSession(opts: {
|
|
699
|
+
/** Events replayed by the first `prompt()` call. */
|
|
698
700
|
events?: AgentSessionEvent[];
|
|
701
|
+
/** Events replayed per `prompt()` call (index = call number); wins over `events`. */
|
|
702
|
+
turns?: AgentSessionEvent[][];
|
|
703
|
+
/** Text of every `prompt()` call, in order. */
|
|
704
|
+
promptCalls?: string[];
|
|
705
|
+
/** Zero-based `prompt()` call that throws instead of replaying events. */
|
|
706
|
+
throwOnCall?: number;
|
|
707
|
+
/** The first `prompt()` call waits for this before replaying events. */
|
|
708
|
+
holdFirstPrompt?: Promise<void>;
|
|
699
709
|
throwError?: string;
|
|
700
710
|
steerCalls?: string[];
|
|
701
711
|
followUpCalls?: string[];
|
|
702
712
|
steeringError?: string;
|
|
703
713
|
}): AgentSession {
|
|
704
714
|
const listeners: Array<(event: AgentSessionEvent) => void> = [];
|
|
715
|
+
const scripts = opts.turns ?? [opts.events ?? []];
|
|
716
|
+
let promptIndex = 0;
|
|
705
717
|
return {
|
|
706
718
|
sessionId: "mock-session-id",
|
|
707
719
|
isStreaming: false,
|
|
@@ -713,8 +725,12 @@ function makeMockAgentSession(opts: {
|
|
|
713
725
|
if (idx >= 0) listeners.splice(idx, 1);
|
|
714
726
|
};
|
|
715
727
|
},
|
|
716
|
-
async prompt() {
|
|
717
|
-
|
|
728
|
+
async prompt(text: string) {
|
|
729
|
+
const call = promptIndex++;
|
|
730
|
+
opts.promptCalls?.push(text);
|
|
731
|
+
if (call === 0) await opts.holdFirstPrompt;
|
|
732
|
+
if (opts.throwOnCall === call) throw new Error("prompt rejected");
|
|
733
|
+
for (const event of scripts[call] ?? []) {
|
|
718
734
|
for (const l of listeners) l(event);
|
|
719
735
|
}
|
|
720
736
|
if (opts.throwError) throw new Error(opts.throwError);
|
|
@@ -765,6 +781,253 @@ async function runWithEvents(events: AgentSessionEvent[]): Promise<{
|
|
|
765
781
|
return { events: emitted, result };
|
|
766
782
|
}
|
|
767
783
|
|
|
784
|
+
describe("PiMonoSession — empty final turn reprompt", () => {
|
|
785
|
+
const STORE_PROGRESS_OUTPUT = '{"result":"ok"}';
|
|
786
|
+
// Pi's thinking block; the text is a canary that must never reach a log line.
|
|
787
|
+
const THINKING_CANARY = "private-reasoning-canary";
|
|
788
|
+
|
|
789
|
+
function assistantEnd(
|
|
790
|
+
content: unknown[],
|
|
791
|
+
stopReason = "stop",
|
|
792
|
+
usage?: { output: number },
|
|
793
|
+
): AgentSessionEvent {
|
|
794
|
+
return {
|
|
795
|
+
type: "message_end",
|
|
796
|
+
message: { role: "assistant", content, stopReason, ...(usage ? { usage } : {}) },
|
|
797
|
+
} as unknown as AgentSessionEvent;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
const thinkingOnly = () => assistantEnd([{ type: "thinking", thinking: THINKING_CANARY }]);
|
|
801
|
+
const emptyContent = () => assistantEnd([]);
|
|
802
|
+
|
|
803
|
+
function toolStart(toolCallId: string, toolName: string, args: unknown): AgentSessionEvent {
|
|
804
|
+
return { type: "tool_execution_start", toolCallId, toolName, args } as AgentSessionEvent;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
function toolEnd(toolCallId: string, toolName: string, isError = false): AgentSessionEvent {
|
|
808
|
+
return {
|
|
809
|
+
type: "tool_execution_end",
|
|
810
|
+
toolCallId,
|
|
811
|
+
toolName,
|
|
812
|
+
result: {},
|
|
813
|
+
isError,
|
|
814
|
+
} as AgentSessionEvent;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
async function runTurns(
|
|
818
|
+
turns: AgentSessionEvent[][],
|
|
819
|
+
extra: { throwOnCall?: number } = {},
|
|
820
|
+
): Promise<{ events: ProviderEvent[]; result: ProviderResult; promptCalls: string[] }> {
|
|
821
|
+
const promptCalls: string[] = [];
|
|
822
|
+
const logFile = join(
|
|
823
|
+
tmpLogDir,
|
|
824
|
+
`reprompt-${Date.now()}-${Math.random().toString(36).slice(2)}.log`,
|
|
825
|
+
);
|
|
826
|
+
const session = new PiMonoSession(
|
|
827
|
+
makeMockAgentSession({ turns, promptCalls, ...extra }),
|
|
828
|
+
makeSessionConfig(logFile),
|
|
829
|
+
false,
|
|
830
|
+
);
|
|
831
|
+
const events: ProviderEvent[] = [];
|
|
832
|
+
session.onEvent((e) => events.push(e));
|
|
833
|
+
const result = await session.waitForCompletion();
|
|
834
|
+
return { events, result, promptCalls };
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
const stderrLines = (events: ProviderEvent[]) =>
|
|
838
|
+
events.flatMap((e) => (e.type === "raw_stderr" ? [e.content] : []));
|
|
839
|
+
|
|
840
|
+
// The final turn carries only a thinking block, or nothing at all. pi ends the
|
|
841
|
+
// session cleanly on both, which left a schema-bound task without a result.
|
|
842
|
+
test.each([
|
|
843
|
+
["a thinking-only", thinkingOnly],
|
|
844
|
+
["an empty-content", emptyContent],
|
|
845
|
+
])("%s final turn gets exactly one reprompt and output comes from the second turn", async (_, firstTurn) => {
|
|
846
|
+
const { result, promptCalls } = await runTurns([
|
|
847
|
+
[firstTurn()],
|
|
848
|
+
[successMessageEnd(STORE_PROGRESS_OUTPUT)],
|
|
849
|
+
]);
|
|
850
|
+
expect(promptCalls).toHaveLength(2);
|
|
851
|
+
expect(promptCalls[0]).toBe("test prompt");
|
|
852
|
+
expect(promptCalls[1]).toContain("no text and no tool call");
|
|
853
|
+
expect(promptCalls[1]).toContain("store-progress");
|
|
854
|
+
expect(result.isError).toBe(false);
|
|
855
|
+
expect(result.exitCode).toBe(0);
|
|
856
|
+
expect(result.output).toBe(STORE_PROGRESS_OUTPUT);
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
test("an empty turn that follows tool calls is reprompted too", async () => {
|
|
860
|
+
const { result, promptCalls } = await runTurns([
|
|
861
|
+
[
|
|
862
|
+
assistantEnd([{ type: "toolCall", id: "t1", name: "get-task-details", arguments: {} }]),
|
|
863
|
+
toolStart("t1", "get-task-details", {}),
|
|
864
|
+
toolEnd("t1", "get-task-details"),
|
|
865
|
+
assistantEnd([{ type: "toolCall", id: "t2", name: "memory-search", arguments: {} }]),
|
|
866
|
+
toolStart("t2", "memory-search", {}),
|
|
867
|
+
toolEnd("t2", "memory-search"),
|
|
868
|
+
thinkingOnly(),
|
|
869
|
+
],
|
|
870
|
+
[successMessageEnd(STORE_PROGRESS_OUTPUT)],
|
|
871
|
+
]);
|
|
872
|
+
expect(promptCalls).toHaveLength(2);
|
|
873
|
+
expect(result.output).toBe(STORE_PROGRESS_OUTPUT);
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
test("an empty final turn leaves a diagnostic with stopReason and block types, never content", async () => {
|
|
877
|
+
const { events } = await runTurns([
|
|
878
|
+
[assistantEnd([{ type: "thinking", thinking: THINKING_CANARY }], "stop", { output: 365 })],
|
|
879
|
+
[successMessageEnd(STORE_PROGRESS_OUTPUT)],
|
|
880
|
+
]);
|
|
881
|
+
const diagnostic = stderrLines(events).find((l) => l.includes("no text and no tool call ("));
|
|
882
|
+
expect(diagnostic).toContain("stopReason=stop");
|
|
883
|
+
expect(diagnostic).toContain("content=[thinking]");
|
|
884
|
+
expect(diagnostic).toContain("outputTokens=365");
|
|
885
|
+
expect(stderrLines(events).join("")).not.toContain(THINKING_CANARY);
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
test("a normal final text turn is not reprompted and emits no empty-turn diagnostic", async () => {
|
|
889
|
+
const { events, result, promptCalls } = await runTurns([[successMessageEnd("All done")]]);
|
|
890
|
+
expect(promptCalls).toEqual(["test prompt"]);
|
|
891
|
+
expect(result.output).toBe("All done");
|
|
892
|
+
expect(stderrLines(events)).toEqual([]);
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
test("a second empty turn after the reprompt is not reprompted again", async () => {
|
|
896
|
+
const { result, promptCalls } = await runTurns([
|
|
897
|
+
[thinkingOnly()],
|
|
898
|
+
[emptyContent()],
|
|
899
|
+
[thinkingOnly()],
|
|
900
|
+
]);
|
|
901
|
+
expect(promptCalls).toHaveLength(2);
|
|
902
|
+
expect(result.exitCode).toBe(0);
|
|
903
|
+
expect(result.output).toBeUndefined();
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
// The reprompt asks for a store-progress call; after a terminal one has
|
|
907
|
+
// succeeded the task is already finished, so another turn is wasted at best.
|
|
908
|
+
test.each([
|
|
909
|
+
"completed",
|
|
910
|
+
"failed",
|
|
911
|
+
])("no reprompt after a successful terminal store-progress call (status %s)", async (status) => {
|
|
912
|
+
const { promptCalls } = await runTurns([
|
|
913
|
+
[
|
|
914
|
+
toolStart("sp", "store-progress", { status }),
|
|
915
|
+
toolEnd("sp", "store-progress"),
|
|
916
|
+
emptyContent(),
|
|
917
|
+
],
|
|
918
|
+
]);
|
|
919
|
+
expect(promptCalls).toHaveLength(1);
|
|
920
|
+
});
|
|
921
|
+
|
|
922
|
+
test.each([
|
|
923
|
+
["a progress-only call", { status: "in_progress" }, false],
|
|
924
|
+
["a terminal call the server rejected", { status: "completed" }, true],
|
|
925
|
+
])("still reprompts after %s", async (_, args, isError) => {
|
|
926
|
+
const { promptCalls } = await runTurns([
|
|
927
|
+
[
|
|
928
|
+
toolStart("sp", "store-progress", args),
|
|
929
|
+
toolEnd("sp", "store-progress", isError),
|
|
930
|
+
emptyContent(),
|
|
931
|
+
],
|
|
932
|
+
[successMessageEnd(STORE_PROGRESS_OUTPUT)],
|
|
933
|
+
]);
|
|
934
|
+
expect(promptCalls).toHaveLength(2);
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
test("a final turn that ends in a tool call is not reprompted", async () => {
|
|
938
|
+
const { promptCalls } = await runTurns([
|
|
939
|
+
[
|
|
940
|
+
assistantEnd(
|
|
941
|
+
[{ type: "toolCall", id: "t1", name: "store-progress", arguments: {} }],
|
|
942
|
+
"toolUse",
|
|
943
|
+
),
|
|
944
|
+
],
|
|
945
|
+
]);
|
|
946
|
+
expect(promptCalls).toHaveLength(1);
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
test("an errored final turn fails the session without a reprompt", async () => {
|
|
950
|
+
const { result, promptCalls } = await runTurns([
|
|
951
|
+
[errorMessageEnd("provider returned error: 503")],
|
|
952
|
+
]);
|
|
953
|
+
expect(promptCalls).toHaveLength(1);
|
|
954
|
+
expect(result.isError).toBe(true);
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
test("an aborted final turn is not reprompted", async () => {
|
|
958
|
+
const { promptCalls } = await runTurns([[assistantEnd([], "aborted")]]);
|
|
959
|
+
expect(promptCalls).toHaveLength(1);
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
test("abort() before the final turn lands suppresses the reprompt", async () => {
|
|
963
|
+
let release = () => {};
|
|
964
|
+
const gate = new Promise<void>((resolve) => {
|
|
965
|
+
release = resolve;
|
|
966
|
+
});
|
|
967
|
+
const promptCalls: string[] = [];
|
|
968
|
+
const session = new PiMonoSession(
|
|
969
|
+
makeMockAgentSession({ turns: [[emptyContent()]], promptCalls, holdFirstPrompt: gate }),
|
|
970
|
+
makeSessionConfig(join(tmpLogDir, `reprompt-abort-${Date.now()}.log`)),
|
|
971
|
+
false,
|
|
972
|
+
);
|
|
973
|
+
await session.abort();
|
|
974
|
+
release();
|
|
975
|
+
await session.waitForCompletion();
|
|
976
|
+
expect(promptCalls).toHaveLength(1);
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
// Workers render the nudge template over HTTP. abort() can land while that
|
|
980
|
+
// request is pending, after the first guard check and before prompt().
|
|
981
|
+
test("abort() while the reprompt template is rendering does not start a new turn", async () => {
|
|
982
|
+
let releaseRender = () => {};
|
|
983
|
+
const renderGate = new Promise<void>((resolve) => {
|
|
984
|
+
releaseRender = resolve;
|
|
985
|
+
});
|
|
986
|
+
let renderStarted = () => {};
|
|
987
|
+
const renderRequested = new Promise<void>((resolve) => {
|
|
988
|
+
renderStarted = resolve;
|
|
989
|
+
});
|
|
990
|
+
const realFetch = globalThis.fetch;
|
|
991
|
+
const fetchSpy = spyOn(globalThis, "fetch").mockImplementation((async (
|
|
992
|
+
input: Parameters<typeof fetch>[0],
|
|
993
|
+
init?: Parameters<typeof fetch>[1],
|
|
994
|
+
) => {
|
|
995
|
+
if (!String(input).endsWith("/api/prompt-templates/render")) return realFetch(input, init);
|
|
996
|
+
renderStarted();
|
|
997
|
+
await renderGate;
|
|
998
|
+
return Response.json({ text: "Please call store-progress.", skipped: false, unresolved: [] });
|
|
999
|
+
}) as unknown as typeof fetch);
|
|
1000
|
+
configureHttpResolver("http://resolver.test", "test-key");
|
|
1001
|
+
try {
|
|
1002
|
+
const promptCalls: string[] = [];
|
|
1003
|
+
const session = new PiMonoSession(
|
|
1004
|
+
makeMockAgentSession({ turns: [[emptyContent()]], promptCalls }),
|
|
1005
|
+
makeSessionConfig(join(tmpLogDir, `reprompt-abort-render-${Date.now()}.log`)),
|
|
1006
|
+
false,
|
|
1007
|
+
);
|
|
1008
|
+
const events: ProviderEvent[] = [];
|
|
1009
|
+
session.onEvent((e) => events.push(e));
|
|
1010
|
+
await renderRequested;
|
|
1011
|
+
await session.abort();
|
|
1012
|
+
releaseRender();
|
|
1013
|
+
await session.waitForCompletion();
|
|
1014
|
+
expect(promptCalls).toHaveLength(1);
|
|
1015
|
+
expect(stderrLines(events).some((l) => l.includes("sending one reprompt"))).toBe(false);
|
|
1016
|
+
} finally {
|
|
1017
|
+
resetHttpResolver();
|
|
1018
|
+
fetchSpy.mockRestore();
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
test("a rejected reprompt keeps the original outcome instead of failing the session", async () => {
|
|
1023
|
+
const { events, result, promptCalls } = await runTurns([[thinkingOnly()]], { throwOnCall: 1 });
|
|
1024
|
+
expect(promptCalls).toHaveLength(2);
|
|
1025
|
+
expect(result.isError).toBe(false);
|
|
1026
|
+
expect(result.exitCode).toBe(0);
|
|
1027
|
+
expect(stderrLines(events).some((l) => l.includes("empty-turn reprompt failed"))).toBe(true);
|
|
1028
|
+
});
|
|
1029
|
+
});
|
|
1030
|
+
|
|
768
1031
|
describe("PiMonoSession.deliverSteering", () => {
|
|
769
1032
|
test("steer mode calls the native steer API", async () => {
|
|
770
1033
|
const steerCalls: string[] = [];
|