@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.
Files changed (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -0
  3. package/package.json +13 -9
  4. package/src/accounting/format.ts +4 -3
  5. package/src/accounting/spent.ts +128 -0
  6. package/src/accounting/summary.ts +40 -32
  7. package/src/agent-cli/cli.ts +35 -22
  8. package/src/agent-cli/client.ts +1 -27
  9. package/src/allowance-command.ts +8 -10
  10. package/src/attempt-ending.ts +5 -7
  11. package/src/attempt-output.ts +15 -32
  12. package/src/attempt-view.ts +34 -33
  13. package/src/author-typebox.ts +13 -0
  14. package/src/client/checks.ts +94 -0
  15. package/src/client/exported.ts +17 -0
  16. package/src/client/index.ts +122 -0
  17. package/src/client/locate.ts +34 -0
  18. package/src/client/published.ts +3 -0
  19. package/src/client/runs.ts +337 -0
  20. package/src/command-line.ts +64 -0
  21. package/src/commands.ts +7 -1
  22. package/src/control-plane.ts +41 -11
  23. package/src/coordinator-prompt.ts +4 -3
  24. package/src/coordinator-socket.ts +41 -33
  25. package/src/deadlines.ts +40 -7
  26. package/src/decisions/directory.ts +51 -40
  27. package/src/decisions/fake.ts +1 -1
  28. package/src/decisions/openrouter.ts +4 -2
  29. package/src/decisions/seam.ts +4 -4
  30. package/src/display-path.ts +3 -3
  31. package/src/duration.ts +43 -27
  32. package/src/emit-command.ts +88 -58
  33. package/src/emit.ts +254 -56
  34. package/src/event-ids.ts +31 -0
  35. package/src/files.ts +44 -4
  36. package/src/hand-over.ts +150 -0
  37. package/src/help/allowance.txt +4 -3
  38. package/src/help/emit.txt +18 -6
  39. package/src/help/inbox.txt +6 -4
  40. package/src/help/logs.txt +9 -6
  41. package/src/help/open.txt +29 -0
  42. package/src/help/reply.txt +6 -8
  43. package/src/help/run.txt +30 -11
  44. package/src/help/runs.txt +4 -2
  45. package/src/help/tick.txt +9 -4
  46. package/src/herdr-placement.ts +3 -33
  47. package/src/herdr-run-session.ts +7 -15
  48. package/src/herdr-workspace-marks.ts +7 -17
  49. package/src/holder-command.ts +56 -133
  50. package/src/in-lines.ts +28 -0
  51. package/src/inbox-command.ts +40 -57
  52. package/src/index.ts +1 -1
  53. package/src/init-command.ts +8 -17
  54. package/src/init-template/hello/workflow.test.ts.template +3 -3
  55. package/src/init-template/hello/workflow.ts.template +5 -4
  56. package/src/jsonl.ts +10 -6
  57. package/src/keep-alive.ts +15 -12
  58. package/src/logs-command.ts +128 -47
  59. package/src/message-operation.ts +6 -3
  60. package/src/messaging/limits.ts +4 -4
  61. package/src/messaging/messaging.ts +31 -28
  62. package/src/messaging/routes.ts +1 -1
  63. package/src/messaging/text.ts +9 -7
  64. package/src/open-command.ts +770 -0
  65. package/src/operation-events.ts +4 -6
  66. package/src/operation-liveness.ts +19 -4
  67. package/src/operator-cli.ts +224 -94
  68. package/src/operator-runtime.ts +29 -7
  69. package/src/ops.ts +270 -0
  70. package/src/pane-layout.ts +105 -59
  71. package/src/progress-view.ts +10 -10
  72. package/src/project-engine.ts +79 -0
  73. package/src/projects.ts +13 -2
  74. package/src/refusals.ts +119 -0
  75. package/src/result-slots.ts +11 -31
  76. package/src/result-validation.ts +2 -2
  77. package/src/run-command.ts +45 -28
  78. package/src/run-commands.ts +43 -115
  79. package/src/run-event-log.ts +1 -1
  80. package/src/run-lines.ts +159 -0
  81. package/src/run-lock.ts +57 -1
  82. package/src/{stage-plan.ts → run-policy/stage-plan.ts} +46 -42
  83. package/src/run-policy/stages.ts +113 -0
  84. package/src/run-policy/waits.ts +452 -0
  85. package/src/run-prepare.ts +205 -43
  86. package/src/run-read.ts +109 -41
  87. package/src/run-state.ts +170 -50
  88. package/src/run-text.ts +54 -0
  89. package/src/run-unreachable.ts +18 -0
  90. package/src/run-usage.ts +18 -12
  91. package/src/run-view.ts +81 -17
  92. package/src/runs-command.ts +83 -63
  93. package/src/runs.ts +310 -212
  94. package/src/sandbox-homes.ts +65 -13
  95. package/src/sandboxes.ts +182 -28
  96. package/src/session-lines.ts +93 -0
  97. package/src/skills/run-skills.ts +8 -1
  98. package/src/sources.ts +28 -29
  99. package/src/spend.ts +333 -0
  100. package/src/stage-ledger.ts +119 -131
  101. package/src/stop-crashed.ts +6 -5
  102. package/src/stopped.ts +4 -4
  103. package/src/test-command.ts +36 -14
  104. package/src/testing/operation-events.ts +3 -23
  105. package/src/testing.ts +73 -26
  106. package/src/tick-command.ts +145 -15
  107. package/src/tools.ts +25 -16
  108. package/src/turn-ends.ts +37 -0
  109. package/src/waits.ts +651 -0
  110. package/src/wake.ts +84 -54
  111. package/src/workflow-loader.ts +54 -4
  112. package/src/workflow-runner.ts +805 -580
  113. package/src/workflow-test-preload.ts +4 -1
  114. package/src/workflow-testing/coordinators.ts +3 -3
  115. package/src/workflow-testing/fake-client.ts +387 -0
  116. package/src/workflow-testing/host.ts +121 -53
  117. package/src/workflow-testing/index.ts +33 -842
  118. package/src/workflow-testing/run-test.ts +1128 -0
  119. package/src/workflow-testing/script.ts +74 -45
  120. package/src/hold-run-lock.fixture.ts +0 -8
  121. package/src/mailbox.ts +0 -990
  122. package/src/workflow-testing/coordinator.typecheck.ts +0 -54
  123. 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" });