@agentswf/engine 0.1.0-beta.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +16 -0
- package/package.json +13 -9
- package/src/accounting/format.ts +4 -3
- package/src/accounting/spent.ts +128 -0
- package/src/accounting/summary.ts +40 -32
- package/src/agent-cli/cli.ts +35 -22
- package/src/agent-cli/client.ts +1 -27
- package/src/allowance-command.ts +8 -10
- package/src/attempt-ending.ts +5 -7
- package/src/attempt-output.ts +15 -32
- package/src/attempt-view.ts +34 -33
- package/src/author-typebox.ts +13 -0
- package/src/client/checks.ts +94 -0
- package/src/client/exported.ts +17 -0
- package/src/client/index.ts +122 -0
- package/src/client/locate.ts +34 -0
- package/src/client/published.ts +3 -0
- package/src/client/runs.ts +337 -0
- package/src/command-line.ts +64 -0
- package/src/commands.ts +7 -1
- package/src/control-plane.ts +41 -11
- package/src/coordinator-prompt.ts +4 -3
- package/src/coordinator-socket.ts +41 -33
- package/src/deadlines.ts +40 -7
- package/src/decisions/directory.ts +51 -40
- package/src/decisions/fake.ts +1 -1
- package/src/decisions/openrouter.ts +4 -2
- package/src/decisions/seam.ts +4 -4
- package/src/display-path.ts +3 -3
- package/src/duration.ts +43 -27
- package/src/emit-command.ts +88 -58
- package/src/emit.ts +254 -56
- package/src/event-ids.ts +31 -0
- package/src/files.ts +44 -4
- package/src/hand-over.ts +150 -0
- package/src/help/allowance.txt +4 -3
- package/src/help/emit.txt +18 -6
- package/src/help/inbox.txt +6 -4
- package/src/help/logs.txt +9 -6
- package/src/help/open.txt +29 -0
- package/src/help/reply.txt +6 -8
- package/src/help/run.txt +30 -11
- package/src/help/runs.txt +4 -2
- package/src/help/tick.txt +9 -4
- package/src/herdr-placement.ts +3 -33
- package/src/herdr-run-session.ts +7 -15
- package/src/herdr-workspace-marks.ts +7 -17
- package/src/holder-command.ts +56 -133
- package/src/in-lines.ts +28 -0
- package/src/inbox-command.ts +40 -57
- package/src/index.ts +1 -1
- package/src/init-command.ts +8 -17
- package/src/init-template/hello/workflow.test.ts.template +3 -3
- package/src/init-template/hello/workflow.ts.template +5 -4
- package/src/jsonl.ts +10 -6
- package/src/keep-alive.ts +15 -12
- package/src/logs-command.ts +128 -47
- package/src/message-operation.ts +6 -3
- package/src/messaging/limits.ts +4 -4
- package/src/messaging/messaging.ts +31 -28
- package/src/messaging/routes.ts +1 -1
- package/src/messaging/text.ts +9 -7
- package/src/open-command.ts +770 -0
- package/src/operation-events.ts +4 -6
- package/src/operation-liveness.ts +19 -4
- package/src/operator-cli.ts +224 -94
- package/src/operator-runtime.ts +29 -7
- package/src/ops.ts +270 -0
- package/src/pane-layout.ts +105 -59
- package/src/progress-view.ts +10 -10
- package/src/project-engine.ts +79 -0
- package/src/projects.ts +13 -2
- package/src/refusals.ts +119 -0
- package/src/result-slots.ts +11 -31
- package/src/result-validation.ts +2 -2
- package/src/run-command.ts +45 -28
- package/src/run-commands.ts +43 -115
- package/src/run-event-log.ts +1 -1
- package/src/run-lines.ts +159 -0
- package/src/run-lock.ts +57 -1
- package/src/{stage-plan.ts → run-policy/stage-plan.ts} +46 -42
- package/src/run-policy/stages.ts +113 -0
- package/src/run-policy/waits.ts +452 -0
- package/src/run-prepare.ts +205 -43
- package/src/run-read.ts +109 -41
- package/src/run-state.ts +170 -50
- package/src/run-text.ts +54 -0
- package/src/run-unreachable.ts +18 -0
- package/src/run-usage.ts +18 -12
- package/src/run-view.ts +81 -17
- package/src/runs-command.ts +83 -63
- package/src/runs.ts +310 -212
- package/src/sandbox-homes.ts +65 -13
- package/src/sandboxes.ts +182 -28
- package/src/session-lines.ts +93 -0
- package/src/skills/run-skills.ts +8 -1
- package/src/sources.ts +28 -29
- package/src/spend.ts +333 -0
- package/src/stage-ledger.ts +119 -131
- package/src/stop-crashed.ts +6 -5
- package/src/stopped.ts +4 -4
- package/src/test-command.ts +36 -14
- package/src/testing/operation-events.ts +3 -23
- package/src/testing.ts +73 -26
- package/src/tick-command.ts +145 -15
- package/src/tools.ts +25 -16
- package/src/turn-ends.ts +37 -0
- package/src/waits.ts +651 -0
- package/src/wake.ts +84 -54
- package/src/workflow-loader.ts +54 -4
- package/src/workflow-runner.ts +805 -580
- package/src/workflow-test-preload.ts +4 -1
- package/src/workflow-testing/coordinators.ts +3 -3
- package/src/workflow-testing/fake-client.ts +387 -0
- package/src/workflow-testing/host.ts +121 -53
- package/src/workflow-testing/index.ts +33 -842
- package/src/workflow-testing/run-test.ts +1128 -0
- package/src/workflow-testing/script.ts +74 -45
- package/src/hold-run-lock.fixture.ts +0 -8
- package/src/mailbox.ts +0 -990
- package/src/workflow-testing/coordinator.typecheck.ts +0 -54
- package/src/workflow-testing/workflow-testing.typecheck.ts +0 -64
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Checked by `tsc --noEmit`, never run: story 032's workflow and its test, as an author writes them.
|
|
2
|
-
import type {
|
|
3
|
-
ParticipantRef,
|
|
4
|
-
WorkflowContext,
|
|
5
|
-
WorkflowDefinition,
|
|
6
|
-
} from "@agentswf/contract/workflow";
|
|
7
|
-
import { answer, type ParticipantScript, testWorkflow } from ".";
|
|
8
|
-
|
|
9
|
-
declare const runtime: string;
|
|
10
|
-
|
|
11
|
-
const investigate: WorkflowDefinition<null, string> = {
|
|
12
|
-
meta: { name: "investigate", description: "watches checkout-api" },
|
|
13
|
-
async run(wf: WorkflowContext) {
|
|
14
|
-
const investigator = await wf.agents.open({ key: "investigator", runtime });
|
|
15
|
-
const coordinator: ParticipantRef = await wf.participants.connect({
|
|
16
|
-
key: "coordinator",
|
|
17
|
-
labels: { audience: "operator" },
|
|
18
|
-
});
|
|
19
|
-
await wf.messages.allow({
|
|
20
|
-
between: [investigator, coordinator],
|
|
21
|
-
purpose: "report findings that hold up; ask when the logs can't settle it",
|
|
22
|
-
timeoutMs: 2 * 60 * 60_000,
|
|
23
|
-
});
|
|
24
|
-
const { outcome } = await investigator.run({ prompt: "Check the checkout-api logs." });
|
|
25
|
-
await coordinator.release("investigation done");
|
|
26
|
-
// A run has no deadline unless `awf run --timeout` gives it one.
|
|
27
|
-
const left = wf.deadline ? wf.deadline.unixMilliseconds - Date.now() : undefined;
|
|
28
|
-
return outcome.answered ? `${outcome.value} (${left ?? "no"} ms left)` : outcome.kind;
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export async function story(): Promise<string> {
|
|
33
|
-
const run = await testWorkflow(investigate, null, {
|
|
34
|
-
agents: { investigator: [answer("…")] },
|
|
35
|
-
participants: {
|
|
36
|
-
coordinator: (event) =>
|
|
37
|
-
event.kind === "message" && event.asks
|
|
38
|
-
? event.reply("Keep two, and link them.")
|
|
39
|
-
: undefined,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
return run.value;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const sendsFirst: ParticipantScript = async (event) => {
|
|
46
|
-
if (event.kind !== "route") return;
|
|
47
|
-
const sent = await event.send("Also check the 09:12 deploy.");
|
|
48
|
-
if (sent.code !== "delivered") throw new Error(sent.code);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export async function refused(wf: WorkflowContext): Promise<void> {
|
|
52
|
-
// @ts-expect-error bindingPath is gone: the socket's place is fixed.
|
|
53
|
-
await wf.participants.connect({ key: "coordinator", bindingPath: "/tmp/x" });
|
|
54
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// Checked by `tsc --noEmit`, never run: each wrong answer is refused where it is written.
|
|
2
|
-
import { defineWorkflow, type OutputSchema } from "@agentswf/contract/workflow";
|
|
3
|
-
import Type from "typebox";
|
|
4
|
-
import { answer, reply, type Script, testWorkflow } from ".";
|
|
5
|
-
|
|
6
|
-
const VERDICT = Type.Union([
|
|
7
|
-
Type.Object({ kind: Type.Literal("ready"), summary: Type.String() }),
|
|
8
|
-
Type.Object({ kind: Type.Literal("changes-requested"), feedback: Type.Array(Type.String()) }),
|
|
9
|
-
]);
|
|
10
|
-
/** A schema from another library, typed by the author surface's carrier. */
|
|
11
|
-
const CARRIED = { type: "object" } as OutputSchema<{ count: number }>;
|
|
12
|
-
|
|
13
|
-
export const valid: Script[] = [
|
|
14
|
-
answer(VERDICT, { kind: "ready", summary: "ok" }),
|
|
15
|
-
answer(VERDICT, (turn) =>
|
|
16
|
-
turn.n === 1
|
|
17
|
-
? { kind: "changes-requested", feedback: ["more"] }
|
|
18
|
-
: { kind: "ready", summary: "ok" },
|
|
19
|
-
),
|
|
20
|
-
answer(VERDICT, async (turn) => (turn.nudge ? reply.failed() : { kind: "ready", summary: "" })),
|
|
21
|
-
answer(CARRIED, { count: 1 }),
|
|
22
|
-
answer(CARRIED, () => ({ count: 2 })),
|
|
23
|
-
answer("text"),
|
|
24
|
-
answer((turn) => `turn ${turn.n}`),
|
|
25
|
-
reply.silent(),
|
|
26
|
-
[answer(VERDICT, { kind: "ready", summary: "ok" }), reply.hang(), answer("done")],
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
export const invalid: Script[] = [
|
|
30
|
-
// @ts-expect-error a missing field
|
|
31
|
-
answer(VERDICT, { kind: "ready" }),
|
|
32
|
-
// @ts-expect-error a kind the union doesn't have
|
|
33
|
-
answer(VERDICT, { kind: "approved", summary: "ok" }),
|
|
34
|
-
// @ts-expect-error an extra field
|
|
35
|
-
answer(VERDICT, { kind: "ready", summary: "ok", extra: 1 }),
|
|
36
|
-
// @ts-expect-error a function's literal must be one of the union's
|
|
37
|
-
answer(VERDICT, () => ({ kind: "approved", summary: "ok" })),
|
|
38
|
-
// @ts-expect-error the carrier's type
|
|
39
|
-
answer(CARRIED, { count: "one" }),
|
|
40
|
-
// @ts-expect-error a reply is a script entry of its own, not an answer's value
|
|
41
|
-
answer(VERDICT, reply.silent()),
|
|
42
|
-
// @ts-expect-error text answers a turn with no schema
|
|
43
|
-
answer(42),
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
// @ts-expect-error raw JSON where a script expects answer(…)
|
|
47
|
-
export const raw: Script = { kind: "ready", summary: "ok" };
|
|
48
|
-
|
|
49
|
-
const withEvents = defineWorkflow({
|
|
50
|
-
meta: { name: "w", description: "w" },
|
|
51
|
-
file: import.meta.path,
|
|
52
|
-
events: { ping: { type: "object" } as OutputSchema<{ n: number }> },
|
|
53
|
-
run: async (wf) => (await wf.receive()).length,
|
|
54
|
-
});
|
|
55
|
-
export const tested = () => testWorkflow(withEvents, { id: "k" });
|
|
56
|
-
// @ts-expect-error a workflow with events is tested from { id, event? }, never its args
|
|
57
|
-
export const byArgs = () => testWorkflow(withEvents, null);
|
|
58
|
-
const plain = defineWorkflow({
|
|
59
|
-
meta: { name: "p", description: "p" },
|
|
60
|
-
prepare: ({ argv }) => ({ n: argv.length }),
|
|
61
|
-
run: async (_wf, args) => args.n,
|
|
62
|
-
});
|
|
63
|
-
// @ts-expect-error a workflow without events is tested from its args, not { id }
|
|
64
|
-
export const byOptions = () => testWorkflow(plain, { id: "k" });
|