lua-cli 3.30.0 → 3.32.1

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 (62) hide show
  1. package/dist/api-exports.d.ts +1096 -41
  2. package/dist/api-exports.js +5544 -137
  3. package/dist/api-exports.js.map +1 -1
  4. package/dist/index.js +21255 -8412
  5. package/dist/index.js.map +1 -1
  6. package/dist/voice/test/index.d.ts +4 -4
  7. package/dist/workflow-builder.d.ts +800 -0
  8. package/dist/workflow-builder.js +6273 -0
  9. package/dist/workflow-builder.js.map +1 -0
  10. package/docs/API_INDEX.md +2 -0
  11. package/docs/README.md +27 -9
  12. package/docs/api/Jobs.md +10 -10
  13. package/docs/api/LuaWorkflow.md +89 -0
  14. package/docs/api/Workflows.md +111 -0
  15. package/docs/workflows/approvals.md +41 -0
  16. package/docs/workflows/artefacts-and-datasets.md +19 -0
  17. package/docs/workflows/coding-harness.md +12 -0
  18. package/docs/workflows/compliance-gates.md +16 -0
  19. package/docs/workflows/connections-in-coding-turns.md +10 -0
  20. package/docs/workflows/correlation-keys.md +11 -0
  21. package/docs/workflows/env-overlays.md +12 -0
  22. package/docs/workflows/evidence-bundles.md +11 -0
  23. package/docs/workflows/exports.md +5 -0
  24. package/docs/workflows/external-content-and-toolscope.md +11 -0
  25. package/docs/workflows/git-credentials.md +32 -0
  26. package/docs/workflows/goals.md +46 -0
  27. package/docs/workflows/knowledge-bindings.md +13 -0
  28. package/docs/workflows/limits.md +11 -0
  29. package/docs/workflows/long-steps-and-checkpoints.md +13 -0
  30. package/docs/workflows/migrating-cloud-tasks.md +9 -0
  31. package/docs/workflows/migrating-runs.md +13 -0
  32. package/docs/workflows/output-visibility.md +9 -0
  33. package/docs/workflows/per-item-approvals.md +9 -0
  34. package/docs/workflows/private-network-sources.md +12 -0
  35. package/docs/workflows/recovery.md +32 -0
  36. package/docs/workflows/replay-local.md +35 -0
  37. package/docs/workflows/reply-channels.md +11 -0
  38. package/docs/workflows/retention-and-archival.md +82 -0
  39. package/docs/workflows/roles.md +12 -0
  40. package/docs/workflows/schedules.md +26 -0
  41. package/docs/workflows/script-form.md +50 -0
  42. package/docs/workflows/testing-offline.md +49 -0
  43. package/docs/workflows/workspace-backends.md +11 -0
  44. package/docs/workflows/workspaces-and-long-steps.md +29 -0
  45. package/package.json +8 -3
  46. package/scripts/run-api-extractor.mjs +1 -1
  47. package/template/.gitignore +2 -0
  48. package/template/examples/workflows/CLAUDE.md +27 -0
  49. package/template/examples/workflows/adversarial-verify.workflow.script.js +48 -0
  50. package/template/examples/workflows/github-review.webhook.ts +19 -0
  51. package/template/examples/workflows/linear-ready.trigger.ts +21 -0
  52. package/template/examples/workflows/outreach.ts +55 -0
  53. package/template/examples/workflows/pr-review-round.ts +75 -0
  54. package/template/examples/workflows/provision-tenant.ts +35 -0
  55. package/template/examples/workflows/refund-approval.ts +57 -0
  56. package/template/examples/workflows/research-brief.ts +42 -0
  57. package/template/examples/workflows/reviewed-brief.ts +19 -0
  58. package/template/examples/workflows/support-triage.ts +81 -0
  59. package/template/examples/workflows/ticket-to-pr.ts +137 -0
  60. package/template/examples/workflows/vendor-invoices.ts +83 -0
  61. package/template/lua.skill.yaml +1 -0
  62. package/template/package.json +1 -1
@@ -0,0 +1,137 @@
1
+ // Linear label -> clone -> parallel worktree arms -> merge -> tests -> PR -> review loop -> approval -> merge.
2
+ // From workflows-spec 03 §3.2 (f) (WF-215 / WF-223 — the spec is normative). LUA-635: `openPr` is placed by `.then(openPr)` on
3
+ // both test outcomes — the listing's `otherwise: 'openPr'` named a `.then(createStep)` placement, which never declares an id
4
+ // (03 §3.2.0); a string arm names an agentStep / specialistStep / toolStep / map / workflow declaration. `mergeGate.title` is a
5
+ // plain string — the grammar is `title: string` (03 §3.1) and bindings ride `details`.
6
+ // src/workflows/ticket-to-pr.ts — Linear label → clone → parallel worktree arms → merge → test suite → PR → review loop → approval → merge
7
+ import { z } from 'zod';
8
+ import { createStep, createWorkflow, step, fromInit, fromStep, template, eq, lit } from 'lua-cli';
9
+ import { prReviewRound } from './pr-review-round';
10
+
11
+ const runTests = createStep({
12
+ id: 'runTests',
13
+ inputSchema: z.any(),
14
+ outputSchema: z.object({ passed: z.boolean(), summary: z.string() }),
15
+ tier: 'job',
16
+ workspace: { mount: 'rw' },
17
+ timeoutSeconds: 3600,
18
+ jobResources: 'large', // a 15–40 min monorepo suite fits one 4 h segment (D19-r1); up to 86 400 s is legal since D19-r2 — see §3.2 (h) for a step that crosses the segment boundary
19
+ async execute({ workspace, log }) {
20
+ const r = await $`cd ${workspace!.path} && npm ci && npm test -- --maxWorkers=2`.nothrow(); // untracked node_modules were rebuilt on restore (05 §5.17.5, E12); `--maxWorkers=2` keeps a mongodb-memory-server-per-file suite inside `large`'s 8 GiB — over it the container is OOM-killed and the step fails `job_oom_killed` (customer fault, 05 §5.17.4; §3.12 note)
21
+ log(r.stdout.slice(-4000));
22
+ return { passed: r.exitCode === 0, summary: r.stdout.slice(-2000) };
23
+ },
24
+ });
25
+
26
+ const openPr = createStep({
27
+ id: 'openPr',
28
+ inputSchema: z.object({ ticketId: z.string(), title: z.string() }),
29
+ outputSchema: z.object({ prNumber: z.number(), url: z.string() }),
30
+ tier: 'job',
31
+ workspace: { mount: 'ro' },
32
+ sideEffects: 'external',
33
+ onError: 'park', // a PR is an external effect: a platform fault PARKS (06 §6.3.5); `gh` is idempotent on the branch anyway
34
+ async execute({ workspace, inputData, runId }) {
35
+ const out =
36
+ await $`cd ${workspace!.path} && gh pr create --fill --title ${inputData.title} --body ${`Closes ${inputData.ticketId}\n\n<!-- lua-run:${runId} -->`}`; // the run id in the PR body is what the GitHub webhook uses to route review signals (§3.7)
37
+ const url = out.stdout.trim();
38
+ return { prNumber: Number(url.split('/').pop()), url };
39
+ },
40
+ });
41
+
42
+ const mergePr = createStep({
43
+ id: 'mergePr',
44
+ inputSchema: z.object({ approved: z.boolean(), input: z.object({ prNumber: z.number() }) }),
45
+ outputSchema: z.object({ merged: z.boolean() }),
46
+ tier: 'job',
47
+ workspace: { mount: 'ro' },
48
+ jobTools: ['gh'],
49
+ sideEffects: 'external',
50
+ onError: 'park', // `jobTools:['gh']` is what mints GH_TOKEN for a code step (11 §11.5.6: pull_requests:write + contents:write + issues:read, repo-scoped — merge is a contents write on GitHub)
51
+ async execute({ workspace, inputData }) {
52
+ if (!inputData.approved) return { merged: false };
53
+ await $`cd ${workspace!.path} && gh pr merge ${inputData.input.prNumber} --squash --delete-branch`; // succeeds only if the base branch's ruleset lets the App merge — human-only-merge orgs keep contents:write off the App (11 T21)
54
+ return { merged: true };
55
+ },
56
+ });
57
+
58
+ export const ticketToPr = createWorkflow({
59
+ name: 'ticket-to-pr',
60
+ description:
61
+ 'Linear label → implement/tests/docs in parallel worktrees → merge → test suite → PR → review rounds → approval → merge',
62
+ inputSchema: z.object({
63
+ ticketId: z.string(),
64
+ title: z.string(),
65
+ spec: z.string(),
66
+ repo: z.string(),
67
+ baseRef: z.string().default('main'),
68
+ }),
69
+ outputSchema: z.object({ merged: z.boolean(), prUrl: z.string().optional(), rounds: z.number() }),
70
+ connections: [{ key: 'github', integrationType: 'github', required: true }], // the GitHub connection this workflow acts through, declared ONCE by key — resolved on the owner agent at run time (an agent-scoped GitHub connection first, then org-scoped; LUA-623), so the same definition runs on any agent: no frozen connection id in source, no per-agent build
71
+ workspace: {
72
+ kind: 'git',
73
+ repo: template('${initData.repo}'),
74
+ ref: template('${initData.baseRef}'),
75
+ credentialsRef: 'github',
76
+ sizeGb: 20,
77
+ verify: 'npm test',
78
+ }, // `credentialsRef` names the declared key above; an undeclared key fails `lua compile` / `lua push` with connection-key-undeclared
79
+ budget: { maxCredits: 400, maxDurationSeconds: 21 * 24 * 3600 }, // review rounds may wait a week each. Job seconds (wall, claim → terminal) worst case: 7200+5400+1800 arms + 3600 merge + 3600 tests + 3600 fixTests + 3600 openPr + 8 × (7200+600) rounds + 3600 merge ≈ 94 800 s — fits the org default maxJobSecondsPerRun 172 800 (48 h) with margin; the push-time `job-seconds-exceed-cap` BLOCKER (10 §10.7.6) refuses this file on an org that lowered the cap below the sum, and prints the R23 raise path. Declare `maxJobSeconds` explicitly only to narrow.
80
+ })
81
+ .parallel(['implement', 'writeTests', 'updateDocs'], { merge: { strategy: 'rebase', onConflict: 'agent' } }) // three coding turns on three clone volumes + branches; the merge row rebases them onto the run branch and lets one resolver turn fix conflicts (05 §5.17.5)
82
+ .agentStep('implement', {
83
+ agentId: 'swe-implementer',
84
+ tier: 'job',
85
+ workspace: { mount: 'rw', isolation: 'worktree' },
86
+ timeoutSeconds: 7200,
87
+ prompt: template(
88
+ 'Implement ${initData.spec} for ticket ${initData.ticketId}. Do not touch tests or docs; commit as you go.'
89
+ ),
90
+ toolScope: { jobTools: ['shell', 'read', 'write', 'edit', 'glob', 'grep', 'git'] },
91
+ })
92
+ .agentStep('writeTests', {
93
+ agentId: 'swe-tester',
94
+ tier: 'job',
95
+ workspace: { mount: 'rw', isolation: 'worktree' },
96
+ timeoutSeconds: 5400,
97
+ prompt: template(
98
+ 'Write tests for the behaviour described in ${initData.spec}; they may fail until implementation lands. Only touch test files.'
99
+ ),
100
+ })
101
+ .agentStep('updateDocs', {
102
+ agentId: 'swe-writer',
103
+ tier: 'job',
104
+ workspace: { mount: 'rw', isolation: 'worktree' },
105
+ timeoutSeconds: 1800,
106
+ jobResources: 'small',
107
+ prompt: template('Update docs/ for ${initData.spec}. Only touch markdown files.'),
108
+ })
109
+ .then(runTests) // shared mount, sequential — the merged run branch
110
+ .switch([[eq(step('runTests').path('passed'), lit(false)), 'fixTests']]) // red ⇒ one fix turn (placed inside this arm by the string ref below); green falls through — no `otherwise`, `openPr` follows either way
111
+ .agentStep('fixTests', {
112
+ agentId: 'swe-implementer',
113
+ tier: 'job',
114
+ workspace: { mount: 'rw' },
115
+ timeoutSeconds: 3600,
116
+ prompt: template(
117
+ 'The test suite failed:\n${stepResults.runTests.summary}\nFix the code (not the tests unless they are wrong) and re-run `npm test` until green.'
118
+ ),
119
+ })
120
+ .then(openPr)
121
+ .dowhile('reviewRound', eq(step('reviewRound').path('state'), lit('changes_requested')), { maxIterations: 8 }) // ≤ 8 review rounds (the SWE_REVIEW_MAX_ROUNDS lesson)
122
+ .workflow(
123
+ 'reviewRound',
124
+ prReviewRound,
125
+ { prNumber: fromStep('openPr', 'prNumber'), repo: fromInit('repo') },
126
+ { workspace: 'inherit' }
127
+ ) // declared here, placed as the loop body by the string ref above; each round is a child run on the SAME workspace; the parent's PVC is released while a round waits for the webhook (E12)
128
+ .approval('mergeGate', {
129
+ title: 'Merge the PR?',
130
+ details: template('Merge ${stepResults.openPr.url} into ${initData.baseRef}?'),
131
+ approver: { role: 'eng-lead' },
132
+ excludeInitiator: true,
133
+ timeoutHours: 72,
134
+ onTimeout: 'deny',
135
+ })
136
+ .then(mergePr)
137
+ .commit();
@@ -0,0 +1,83 @@
1
+ // Per-item review with an env overlay, a restricted output pane and a slack reply (Cluster K).
2
+ // From workflows-spec 03 §3.2 (j) (WF-215 / WF-223 — the spec is normative). LUA-635: the approval `title` is a plain string
3
+ // (03 §3.1 `approval(id, { title: string; details?: TemplateBinding })`); the listing's `template(…)` title moved into `details`.
4
+ // The listing's `.foreach('pay', 'payInvoice', …)` is not the builder's `foreach(step, opts)` (03 §3.1) and declared no `payInvoice`
5
+ // anywhere — the body is the `payInvoice` code step below.
6
+ import { z } from 'zod';
7
+ import { createStep, createWorkflow, env, fromInit, fromKnowledge, fromStep, template } from 'lua-cli';
8
+
9
+ const invoiceSchema = z.object({
10
+ vendorId: z.string(),
11
+ approverEmail: z.string().email(),
12
+ amount: z.number(),
13
+ pdf: z.object({ __artefactRef: z.string() }),
14
+ });
15
+
16
+ const loadInvoices = createStep({
17
+ id: 'loadInvoices',
18
+ inputSchema: z.object({ batchId: z.string() }),
19
+ outputSchema: z.object({ invoices: z.array(invoiceSchema) }),
20
+ async execute(ctx) {
21
+ const src = await ctx.artefacts.get(ctx.inputData.batchId); // B40: a multi-GB NDJSON batch — page it, never buffer it
22
+ const invoices = [];
23
+ for (let offset = 0; ; offset += 1000) {
24
+ const page = await src.rows({ offset, limit: 1000 });
25
+ invoices.push(...page.rows);
26
+ if (page.nextOffset == null) break;
27
+ }
28
+ return { invoices };
29
+ },
30
+ });
31
+
32
+ const payInvoice = createStep({
33
+ id: 'payInvoice',
34
+ inputSchema: invoiceSchema,
35
+ outputSchema: z.object({ vendorId: z.string(), paid: z.boolean() }),
36
+ sideEffects: 'external',
37
+ onError: 'park', // a payment is an external effect: a platform-fault reclaim PARKS it, never auto-retries (06 §6.3.5)
38
+ async execute({ inputData: inv, once }) {
39
+ // one approved row per iteration — the foreach body receives the raw item
40
+ await once(`pay:${inv.vendorId}:${inv.amount}`, () =>
41
+ Payments.transfer({ vendorId: inv.vendorId, amount: inv.amount })
42
+ ); // exactly-once per {occurrenceId, key}; `Payments` stands for your payment rail
43
+ return { vendorId: inv.vendorId, paid: true };
44
+ },
45
+ });
46
+
47
+ export const vendorInvoices = createWorkflow({
48
+ name: 'vendor-invoices',
49
+ inputSchema: z.object({ batchId: z.string() }),
50
+ outputVisibility: { roles: ['finance', 'org-admin'] }, // B44: invoice payloads are readable by finance only; owner bypass on (default)
51
+ schedule: { cron: '0 6 * * 1-5', timezone: env.template('FINANCE_TZ') }, // B33: one file, per-env timezone resolved at push
52
+ scheduleInput: { batchId: 'latest' }, // the 06:00 run reads the standing `latest` batch alias; a required input without a `scheduleInput` is `schedule-input-required`, a publish blocker. An ad-hoc run passes its own batch id
53
+ })
54
+ .then(loadInvoices, { batchId: fromInit('batchId') })
55
+ .agentStep('policyCheck', {
56
+ agentId: env.template('FINANCE_AGENT_ID'), // B33: staging and prod route to different sub-agents; same graphHash
57
+ prompt: template('Flag any invoice that breaks policy.\n${knowledge.policy}\n${stepResults.loadInvoices.invoices}'),
58
+ outputSchema: z.object({ flagged: z.array(z.string()) }),
59
+ input: {
60
+ policy: fromKnowledge({
61
+ source: 'connection',
62
+ connectionId: env.template('FINANCE_DRIVE_CONNECTION'),
63
+ query: 'vendor payment policy',
64
+ maxChars: 6000,
65
+ }),
66
+ }, // B41
67
+ toolScope: { connectionIds: [] },
68
+ }) // tainted by the connection knowledge ⇒ `toolScope` mandatory (P1-16); the knowledge connection is added by the compiler's overlay pass
69
+ .approval('reviewInvoices', {
70
+ title: 'Vendor invoices to review',
71
+ details: template(
72
+ '${stepResults.loadInvoices.invoices.length} invoices; flagged: ${stepResults.policyCheck.flagged}'
73
+ ),
74
+ approver: { role: 'finance' },
75
+ itemsPath: 'invoices',
76
+ itemApprover: { fromItem: 'approverEmail' }, // B20: every invoice goes to ITS approver; the parent link is the finance role's overview
77
+ itemTimeout: { timeoutHours: 48 },
78
+ editable: true,
79
+ editablePaths: ['invoices[*].amount'],
80
+ timeoutHours: 96,
81
+ })
82
+ .foreach(payInvoice, { items: fromStep('reviewInvoices', 'items'), concurrency: 4 }) // `foreach(step, opts)`: consumes `resumeData.items[]` — approved rows only
83
+ .commit();
@@ -6,6 +6,7 @@ agent:
6
6
  skills: []
7
7
  webhooks: []
8
8
  jobs: []
9
+ workflows: []
9
10
  preprocessors: []
10
11
  postprocessors: []
11
12
  mcpServers: []
@@ -20,7 +20,7 @@
20
20
  "inquirer": "^12.9.6",
21
21
  "stripe": "^17.5.0",
22
22
  "js-yaml": "^4.1.0",
23
- "lua-cli": "^3.30.0",
23
+ "lua-cli": "^3.32.1",
24
24
  "openai": "^5.23.0",
25
25
  "uuid": "^13.0.0",
26
26
  "zod": "^3.24.1"