@controllerai/cli 0.2.20 → 0.2.22

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 (79) hide show
  1. package/README.md +6 -3
  2. package/dist/api/client.js +5 -38
  3. package/dist/api/client.js.map +1 -1
  4. package/dist/commands/agent.js +169 -146
  5. package/dist/commands/agent.js.map +1 -1
  6. package/dist/commands/expr.js +10 -3
  7. package/dist/commands/expr.js.map +1 -1
  8. package/dist/commands/integration.js +30 -10
  9. package/dist/commands/integration.js.map +1 -1
  10. package/dist/commands/skills.js +1 -0
  11. package/dist/commands/skills.js.map +1 -1
  12. package/dist/commands/templateSetup.js +42 -0
  13. package/dist/commands/templateSetup.js.map +1 -0
  14. package/dist/commands/workflow.js +6 -7
  15. package/dist/commands/workflow.js.map +1 -1
  16. package/dist/errors.js +2 -5
  17. package/dist/errors.js.map +1 -1
  18. package/dist/index.js +2 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/permissionTool.js +1 -1
  21. package/dist/permissionTool.js.map +1 -1
  22. package/package.json +6 -4
  23. package/skills/controllerai-agents/SKILL.md +109 -26
  24. package/skills/controllerai-agents/references/instructions-and-versioning.md +32 -34
  25. package/skills/controllerai-ai-nodes/SKILL.md +83 -10
  26. package/skills/controllerai-ai-nodes/references/selection-and-testing.md +44 -26
  27. package/skills/controllerai-data/SKILL.md +106 -34
  28. package/skills/controllerai-data/references/data-rails.md +24 -26
  29. package/skills/controllerai-expressions/SKILL.md +82 -29
  30. package/skills/controllerai-expressions/references/dsl-and-recipes.md +42 -40
  31. package/skills/controllerai-flow-control/SKILL.md +104 -21
  32. package/skills/controllerai-flow-control/references/patterns.md +23 -60
  33. package/skills/controllerai-integration-actions/SKILL.md +89 -11
  34. package/skills/controllerai-node-config/SKILL.md +108 -18
  35. package/skills/controllerai-node-config/references/prop-and-readiness.md +28 -78
  36. package/skills/controllerai-runs/SKILL.md +82 -25
  37. package/skills/controllerai-runs/references/debugging.md +24 -22
  38. package/skills/controllerai-start/SKILL.md +63 -35
  39. package/skills/controllerai-start/references/mcp-tool-map.md +22 -21
  40. package/skills/controllerai-template-setup/SKILL.md +132 -0
  41. package/skills/controllerai-template-setup/agents/openai.yaml +4 -0
  42. package/skills/controllerai-triggers/SKILL.md +113 -16
  43. package/skills/controllerai-triggers/references/lifecycle.md +36 -48
  44. package/skills/controllerai-workflows/SKILL.md +105 -25
  45. package/skills/controllerai-workflows/references/command-map.md +20 -44
  46. package/skills/manifest.json +96 -136
  47. package/skills-mcp/controllerai-agents/SKILL.md +121 -0
  48. package/skills-mcp/controllerai-agents/references/instructions-and-versioning.md +76 -0
  49. package/skills-mcp/controllerai-ai-nodes/SKILL.md +91 -0
  50. package/skills-mcp/controllerai-ai-nodes/references/selection-and-testing.md +66 -0
  51. package/skills-mcp/controllerai-data/SKILL.md +116 -0
  52. package/skills-mcp/controllerai-data/references/data-rails.md +43 -0
  53. package/skills-mcp/controllerai-expressions/SKILL.md +97 -0
  54. package/skills-mcp/controllerai-expressions/references/dsl-and-recipes.md +136 -0
  55. package/skills-mcp/controllerai-flow-control/SKILL.md +112 -0
  56. package/skills-mcp/controllerai-flow-control/references/patterns.md +82 -0
  57. package/skills-mcp/controllerai-integration-actions/SKILL.md +90 -0
  58. package/skills-mcp/controllerai-node-config/SKILL.md +106 -0
  59. package/skills-mcp/controllerai-node-config/references/prop-and-readiness.md +49 -0
  60. package/skills-mcp/controllerai-runs/SKILL.md +87 -0
  61. package/skills-mcp/controllerai-runs/references/debugging.md +53 -0
  62. package/skills-mcp/controllerai-start/SKILL.md +82 -0
  63. package/skills-mcp/controllerai-start/references/mcp-tool-map.md +177 -0
  64. package/skills-mcp/controllerai-template-setup/SKILL.md +10 -0
  65. package/skills-mcp/controllerai-triggers/SKILL.md +109 -0
  66. package/skills-mcp/controllerai-triggers/references/lifecycle.md +59 -0
  67. package/skills-mcp/controllerai-workflows/SKILL.md +108 -0
  68. package/skills-mcp/controllerai-workflows/references/command-map.md +1 -0
  69. package/skills-mcp/manifest.json +200 -0
  70. package/skills/controllerai-agents/references/command-reference.md +0 -205
  71. package/skills/controllerai-ai-nodes/references/command-reference.md +0 -98
  72. package/skills/controllerai-data/references/command-reference.md +0 -177
  73. package/skills/controllerai-expressions/references/command-reference.md +0 -166
  74. package/skills/controllerai-flow-control/references/command-reference.md +0 -171
  75. package/skills/controllerai-integration-actions/references/command-reference.md +0 -118
  76. package/skills/controllerai-node-config/references/command-reference.md +0 -186
  77. package/skills/controllerai-runs/references/command-reference.md +0 -113
  78. package/skills/controllerai-triggers/references/command-reference.md +0 -215
  79. package/skills/controllerai-workflows/references/command-reference.md +0 -118
@@ -1,6 +1,7 @@
1
+ <!-- generated from .claude/skills by cli/scripts/render-skills.mjs; edit the source -->
1
2
  # Expression DSL and recipes
2
3
 
3
- The live compiler and `cai expr context`/`cai expr ops` are authoritative. These examples show structure, not names to copy blindly.
4
+ The live compiler, `cai expr context` and `cai expr ops` are authoritative. These examples show structure; take every binding, field and operation name from the context.
4
5
 
5
6
  ## Text template
6
7
 
@@ -8,36 +9,25 @@ The live compiler and `cai expr context`/`cai expr ops` are authoritative. These
8
9
  `Hello ${flow.firstName.trim()}, order ${inputs.order.id} is ready`
9
10
  ```
10
11
 
11
- Use the exact bindings and fields returned for the destination node.
12
-
13
12
  ## Text prefix
14
13
 
15
- When `.startsWith()` is unavailable, test a prefix with:
14
+ When `.startsWith()` is not advertised, test a prefix with a guarded split:
16
15
 
17
16
  ```js
18
17
  flow.subject.isNotEmpty() ? flow.subject.split("urgent")[0] === "" : false
19
18
  ```
20
19
 
21
- The typed conditional keeps empty text from matching. Replace the binding and prefix literal with exact values from context. Do not split on whitespace unless the requirement is first-word equality. Test punctuation immediately after the prefix, such as `urgent-alpha`, plus a near miss.
20
+ The guard keeps empty text from matching. Prefix matching is not first-word matching: do not split on whitespace unless first-word equality is the requirement, and test a value with punctuation right after the prefix (`urgent-alpha`) plus a near miss.
22
21
 
23
22
  ## HTTP JSON body
24
23
 
25
- An HTTP node's JSON/body prop is stored as JSON text. The expression language does not support object literals or `JSON.stringify`. Build the document as a template and insert complete JSON tokens:
24
+ A JSON body prop is JSON text. The language has no constructed object literals and no `JSON.stringify`, so build the document as a template of complete JSON tokens:
26
25
 
27
26
  ```js
28
27
  `{"message":${flow.name.jsonEncode()},"payload":${flow.user.stringify()}}`
29
28
  ```
30
29
 
31
- - Use `.jsonEncode()` for text or boolean values. It returns a JSON-safe token, including the quotes around text, so do not add another pair of quotes around `${...}`.
32
- - Use `.stringify()` for a custom object or list.
33
- - Keep JSON punctuation outside the interpolation and validate against the destination's exact prop before writing.
34
-
35
- ```bash
36
- cai expr validate <httpNodeId> --prop <jsonBodyProp> --js-file body-expression.js --json
37
- cai expr set <httpNodeId> --prop <jsonBodyProp> --js-file body-expression.js --json
38
- ```
39
-
40
- MCP: pass the file contents inline as `js`; the set call uses `node_prop_set`.
30
+ `.jsonEncode()` returns a JSON-safe token: quoted for text, bare `true`/`false` for a boolean, so never add a second pair of quotes. `.stringify()` serializes a custom object or list. Keep the JSON punctuation outside the interpolations and validate against the exact body prop before writing.
41
31
 
42
32
  ## Same-type fallback
43
33
 
@@ -47,7 +37,7 @@ flow.label ?? "unknown"
47
37
  flow.enabled ?? false
48
38
  ```
49
39
 
50
- Fallbacks must be same-type literals. `0` and `false` remain real values.
40
+ `0` and `false` are values; a fallback never replaces them.
51
41
 
52
42
  ## Boolean condition
53
43
 
@@ -56,7 +46,7 @@ flow.email.isNotEmpty()
56
46
  inputs.score >= 80
57
47
  ```
58
48
 
59
- Validate conditions with `--mode onlyWhen` and without a prop name.
49
+ Validate a condition with `--mode onlyWhen` and no prop name.
60
50
 
61
51
  ## Dates
62
52
 
@@ -65,23 +55,23 @@ inputs.createdAt.toDate() > now.plusDays(-7)
65
55
  inputs.createdAt.toDate().format("YYYY-MM-DD")
66
56
  ```
67
57
 
68
- Convert text to a date before date math. Use negative amounts to move backward.
58
+ Convert text to a date before date math; a negative amount moves backward. Use Moment format tokens, never JavaScript `Date` constructors or getters.
69
59
 
70
60
  ## Workflow records
71
61
 
72
- Filter immediately after `workflowData` so the engine can push supported predicates into storage:
62
+ Filter immediately after `workflowData` so supported predicates are pushed into storage, then sort by an advertised field:
73
63
 
74
64
  ```js
75
65
  workflowData("custom.lead")
76
66
  .filter(row => row.status === "active")
77
- .sortBy("created_at", "desc")
67
+ .sortBy("createdAt", "desc")
78
68
  ```
79
69
 
80
- The collection must exist on the current dev/live rail. A schema declaration alone does not guarantee active records.
70
+ The collection must exist on the current rail; a schema declaration alone does not put rows in it. Record identity fields are `id`, `createdAt`, `updatedAt`.
81
71
 
82
72
  ## Optional filter inputs
83
73
 
84
- Filters are fail-closed by default: a missing right-hand value matches no records. Use optional matching only when the user's requirement explicitly allows an omitted constraint:
74
+ An empty right-hand value is a real comparison: equality matches only empty fields, a negation or containment matches every row. Skip an omitted constraint only when the requirement allows it:
85
75
 
86
76
  ```js
87
77
  workflowData("custom.lead").filter(
@@ -90,45 +80,57 @@ workflowData("custom.lead").filter(
90
80
  )
91
81
  ```
92
82
 
93
- Test both supplied and omitted cases. With this option, null, omitted values, empty text and empty lists are skipped; zero and false remain real constraints. Optional OR filters preserve input order and duplicates, and return all rows when every branch is skipped. Use `.take(count)` and `.skip(offset)` for pagination.
83
+ With the option on, null, empty text and an empty list skip the constraint; `0`, `false`, whitespace and dates remain real constraints. Test the supplied and the omitted case.
84
+
85
+ ## List membership
86
+
87
+ For a list field such as tags, membership is a single element: `row.tags.includes(flow.tag)`. `filter`, `some`, `find` and `every` share the same predicate grammar; `map` projects fields rather than building objects.
88
+
89
+ ## Primitive lists
90
+
91
+ A predicate compares a field of the item, so `flow.weights.filter(w => w >= flow.threshold)` is rejected, and `w.value` on a number compiles as a missing field whose constraint is dropped, matching every item. Aggregate a primitive list with the advertised list operations (`.sum()`, `.count()`, `.max()`), and classify or count its items with a per-item loop whose body returns a flag:
92
+
93
+ ```js
94
+ inputs.runFlowOnList.filter(row => row.status === "completed").map(row => row.outputs).map(row => row.heavyFlag).sum()
95
+ ```
96
+
97
+ `.map()` picks one field per call, so nested picks are chained; the `status` filter keeps failed iterations out of the total.
94
98
 
95
99
  ## Loop item
96
100
 
97
- Where context exposes `item`, primitive lists use the item directly:
101
+ Where the context exposes `item`, a primitive list uses it directly:
98
102
 
99
103
  ```js
100
104
  item
101
105
  ```
102
106
 
103
- Object lists use an advertised field:
107
+ An object list uses an advertised field:
104
108
 
105
109
  ```js
106
110
  item.email
107
111
  ```
108
112
 
109
- Inside the child flow, the item arrives through a flow input and is referenced as `flow.<name>`, not `item`.
113
+ Inside the child flow the item arrives as a flow input and is `flow.<name>`, never `item`. A root routing node can read flow inputs directly; no producer node is needed to expose them.
110
114
 
111
115
  ## Loop output
112
116
 
113
- Run-on-list output is a list of iteration records. Child flow outputs live under `outputs`:
117
+ Run-on-list output is a list of iteration records; child outputs sit under `outputs`:
114
118
 
115
119
  ```js
116
120
  inputs.enrichEach[0].outputs.score
117
121
  ```
118
122
 
119
- Confirm the exact binding and field path in context.
123
+ Confirm the binding and the path in the context.
120
124
 
121
- ## Troubleshooting sequence
125
+ ## Troubleshooting order
122
126
 
123
- 1. `cai expr context <node> --prop <prop> --json`
124
- 2. Confirm the intended source is wired and its `sourceNodeId` is correct.
125
- 3. `cai expr validate ...`
126
- 4. `cai expr set ...`
127
- 5. `cai expr decompile ...`
128
- 6. `cai run node ... --json` for isolated destination configuration
129
- 7. `cai run flow <flowId> ... --json` when the expression consumes a wired upstream input
127
+ 1. `cai expr context <nodeId> --prop <propName> --json`
128
+ 2. Confirm the intended source is wired and its `sourceNodeId` is right.
129
+ 3. `cai expr validate <nodeId> --prop <propName> --js '<expression>' --json`
130
+ 4. `cai expr set <nodeId> --prop <propName> --js '<expression>' --json`
131
+ 5. `cai expr decompile <nodeId> --prop <propName> --json`
132
+ 6. `cai run node <nodeId> --inputs <values.json> --json` for the destination alone
133
+ 7. `cai run flow <flowId> --inputs <values.json> --json` when the expression consumes a wired input
130
134
  8. `cai exec node <nodeExecutionId> --full --json`
131
135
 
132
- MCP: step 4 uses `node_prop_set`; pass expression source and run inputs inline, and set `waitSeconds` on `run_node` or `run_flow` from 0 through 120.
133
-
134
- If compilation succeeds but runtime is null or partially empty, inspect `runScope`, the actual input value, and `resolvedConfigs`; do not keep rewriting syntax blindly. A node-only run cannot prove an `inputs.<name>` binding because it does not execute upstream nodes.
136
+ If compilation succeeds but the runtime value is empty or partial, inspect `runScope`, the actual input value and `resolvedConfigs` before touching the syntax again. A node-only run cannot prove an `inputs.<name>` binding because it does not execute upstream nodes.
@@ -1,39 +1,122 @@
1
1
  ---
2
2
  name: controllerai-flow-control
3
- description: Build Controller AI execution paths with conditions, routers, if/else branches, loops, joins and subflow calls. Use when a flow must validate, branch, iterate or reuse another flow.
3
+ description: Design and configure Controller AI execution paths with only-when guards, If/Else branches, Router routes, for-each loops, subflows, Join Paths and error handling. Use when work must skip, branch, fan out, iterate over a list, call another flow, converge, return a value, or continue after a failure without changing the user's intended semantics.
4
4
  ---
5
+ <!-- generated from .claude/skills by cli/scripts/render-skills.mjs; edit the source -->
5
6
 
6
- # Routing, loops and reusable flows
7
+ # Flow control
7
8
 
8
- Control-flow nodes decide which steps execute and how data moves between paths. Use conditions to validate requests, a router for named alternatives, a loop for each item in a list, and subflows for reusable behavior.
9
+ ## Use this when
9
10
 
10
- ## Choose the construct
11
+ - A flow must skip an action, choose one path, run every matching path, repeat work per item, call another flow, converge exclusive paths, return a value, or continue after a failure.
12
+ - A run shows an unexpected skip, a branch that never fires, an empty return, or a loop that stops early.
11
13
 
12
- - **Only when:** skip one node unless a condition holds.
13
- - **If/Else:** two paths, such as record found versus not found.
14
- - **Router:** several named routes, such as search modes or operation types.
15
- - **For each / Run Flow on List:** execute a body flow for each typed item and collect iteration results.
16
- - **Subflow:** call a reusable typed flow and map its inputs/outputs.
17
- - **Join paths:** deliberately reconcile active paths before a shared continuation.
14
+ Conditions are written with the expression discipline in `controllerai-expressions`; components are found and configured with `controllerai-node-config`; runs are read with `controllerai-runs`.
18
15
 
19
- Choose whether multiple matching routes should run or one alternative should win. Make invalid/missing-input paths return a clear result without performing the write. A skipped node is expected only if its condition and port explain why.
16
+ ## How it works
20
17
 
21
- ## Build branches
18
+ | Intent | Primitive | Runtime semantics |
19
+ | --- | --- | --- |
20
+ | Skip one action when a condition is false | node `only-when` | No alternate path; the node records `only_when_false`, downstream stays eligible |
21
+ | Choose exactly one path | If/Else | The first matching branch runs; Else is the mandatory last fallback |
22
+ | Run every matching path | Router | Conditions are independent; every matching route runs, possibly several |
23
+ | Do work for every list item | `flow for-each` loop | A typed body flow runs once per item, sequentially, under an item cap |
24
+ | Reuse a typed unit of work once | Run flow (subflow) | Explicit input and output mapping to another flow's contract |
25
+ | Continue after a failed action | continue-on-error / Error output | The error is captured, downstream sees null for that node, the run ends `completed_with_error` |
26
+ | One action after whichever exclusive path ran | Join Paths (`registry_flow-merge`) | `chooseActivePath` passes the single active input's value on; `passThrough` returns one field per connected input (blocked ones null) and suits fan-out that can overlap |
27
+ | Give a flow its return value | Return response (`registry_flow-return-response`) | Maps producer values into the declared outputs; without it an otherwise successful flow returns empty outputs |
22
28
 
23
- Inspect the router's current expression context, define a route condition, and connect the route output to its path. Conditions can use the flow's inputs and wired upstream data. Use the supported structured OR-of-AND condition groups for compound logic; do not assume ordinary JavaScript syntax is valid in every condition surface.
29
+ Skip reasons are the evidence: a false guard records `only_when_false`; a node on an untaken branch or an unmatched route records `upstream_skipped`. Choose the primitive by the semantics the caller and the tests need, never because a component was easier to find.
24
30
 
25
- A condition accepting a record requires a fetched record, not a fabricated object. Test both branches, including false/zero values and a missing record. Declare and populate the flow output on each intended return path.
31
+ A fresh If/Else ships with one blank `If` branch and an Else; the blank condition is a validation blocker until it is set. Router routes cannot be reordered because every match runs. Loops run sequentially with a cap that defaults to 500 items (1 to 10000); a list over the cap fails before any iteration, never truncates. `continueOnIterationError` on a loop node continues past a failed child iteration and cannot help when the list or mapping expression fails before any child starts; node-level continue-on-error on the loop node lets the parent flow continue past that failed loop with a null output, but repairs nothing and resumes no iteration. With `chooseActivePath`, zero active inputs stop the flow at the join unless `continueIfNoActivePath` is enabled, which passes null on. Setting a subflow's target synthesizes mapping props from the target's current inputs; when those inputs change, set the target again and remap. Deleting a flow removes its graph, contract, triggers and caller links; turning continue-on-error off deletes the node's Error output and its edges.
26
32
 
27
- ## Build loops
33
+ ## Rules
28
34
 
29
- Use the available for-each scaffolding operation to create the loop, body flow, typed item input and mappings together. It reduces the mistakes involved in assembling loop injection manually. Supply the list expression and exact source output when wiring an upstream list.
35
+ 1. **Guard the action that must skip with `only-when`; do not replace a node skip with If/Else.** A false guard does not stop downstream execution (the skipped node just yields no value), so guard downstream separately or branch when it must skip too.
36
+ 2. **Never invent a missing condition** from names, sample values or one observed run. Leave the branch blank, report the blocker and ask; a missing business rule is not yours to guess.
37
+ 3. **Update the blank default If branch before adding another branch.** Adding beside it leaves a blocker and a duplicate.
38
+ 4. **Order is behavior only for If/Else.** Put the most specific condition first, never write a complement condition for Else, and never simulate Router order by deleting routes or chaining descendants; leave a fan-out unchanged unless the user authorizes a redesign.
39
+ 5. **Build per-item work with `flow for-each`**, never by hand-assembling the injection and mapping pattern. Put the real work in the generated body flow and declare its outputs before consuming aggregate results. Continue past failed iterations only when partial completion is acceptable and the downstream logic handles failed iteration records.
40
+ 6. **Compound guards are supported**: a node guard takes one boolean expression or grouped conditions (inner list AND, outer list OR); a root `&&` or `||` inside one expression is not. Never weaken a rule to fit the grammar, and never probe a private API.
41
+ 7. **Fail missing comparisons closed** with a same-type boundary (`(flow.unitsLeft ?? 5) < 5`), and keep money paths blocking: charges, purchases, transfers and refunds never continue on error, and never enable continue-on-error just to make a run green.
42
+ 8. **Converge exclusive paths through Join Paths**; never wire several branches straight into an ordinary node and never duplicate the shared action.
43
+ 9. **A flow that returns data needs a Return response node** bound to declared outputs. Every Return writes every declared output, unbound ones as null, and a later Return (in execution order) overwrites an earlier one, so a partial Return can erase a value; design one Return per path unless merging is intended.
44
+ 10. **Read the branch list after every edit.** Warnings about missing conditions or unwired paths are blockers even when a run looks green.
30
45
 
31
- The body receives one item; it does not receive the whole original list implicitly. Custom-shaped items and real data-record items have different types. Loop output represents iteration results, so inspect its actual fields before mapping a final list.
46
+ ## Recipes
32
47
 
33
- For an uploaded CSV, a conversational agent can read rows and call a per-row flow. Use a native loop when the workflow already receives a typed list and deterministic iteration is desired.
48
+ ### Guard one action
34
49
 
35
- ## Verify paths
50
+ ```bash
51
+ cai expr context <nodeId> --json
52
+ cai expr validate <nodeId> --mode onlyWhen --js '<boolean expression>' --json
53
+ cai node only-when <nodeId> --js '<boolean expression>' --json
54
+ cai node only-when <nodeId> --groups-json '[["flow.email.isNotEmpty()","flow.units < 5"],["flow.override === true"]]' --json
55
+ ```
36
56
 
37
- Run one representative case per route and inspect node status, selected output ports, skipped reasons and final outputs. For writes, verify the same-environment record effects. A successful outer loop does not prove every iteration succeeded; surface row failures in the result.
57
+ Use `--clear` only when removing the guard is the user's intent.
38
58
 
39
- Examples and commands: [command reference](references/command-reference.md). Control-flow details: [patterns](references/patterns.md).
59
+ ### If/Else and Router
60
+
61
+ ```bash
62
+ cai branch list <controlNodeId> --json
63
+ cai branch update <controlNodeId> --route <defaultIfBranchId> --name "<meaning>" --js '<boolean expression>' --json
64
+ cai branch add <controlNodeId> --name "<meaning>" --js '<boolean expression>' --json
65
+ cai branch update <controlNodeId> --route <routeId> --condition-json '[["flow.email.isNotEmpty()","flow.units < 5"],["flow.override === true"]]' --json
66
+ cai branch connect <controlNodeId> --route <routeId> --to <targetNodeId> --flow <flowId> --json
67
+ cai branch reorder <ifElseNodeId> --order <conditionId1,conditionId2> --json
68
+ ```
69
+
70
+ Find the control component with `controllerai-node-config`, then read the branch IDs. Grouped conditions are OR of AND rows, each string compiled separately. Add an If branch only for another non-Else case; add a Router route for each intended independent match. Reorder lists every condition branch exactly once and omits Else, which stays last. Wire every returned route ID explicitly.
71
+
72
+ ### Loop over a list
73
+
74
+ ```bash
75
+ cai node get <listProducingNodeId> --json
76
+ cai flow for-each --flow <parentFlowId> --from <listProducingNodeId> --source-output <exactOutputId> --name "<item flow name>" --item-type <text|number|date|boolean|custom.type> --max-items <n> --json
77
+ cai node set <loopNodeId> --prop maxItems --value <n> --json
78
+ cai node set <loopNodeId> --prop continueOnIterationError --value true --json
79
+ ```
80
+
81
+ `--source-output` is the exact `outputs[].id` of the selected node, never a display name, and there is no first-output default (branch and error outputs included). When the whole output is the list, omit the list selectors; for a nested list use `--list-field` with the dot path below `.data`; reserve `--list-js` for an exact advanced expression whose shape you took from the context; the selection forms are mutually exclusive. `--item-field <id:type[:display]>` (repeatable) is only for creating a new `custom.*` item type; stored records use `dataRecord.custom.*`. Set the cap on purpose when the requirement differs from 500, decide `--continue-on-error` explicitly, then read the returned warnings and follow `nextSteps` in order; a list/item type mismatch means created but unverified. In mappings, `item` exists only where the context exposes it; inside the body flow the item is `flow.<itemInput>`; aggregate results are iteration records with child outputs under `outputs`.
82
+
83
+ For multiline or shell-sensitive list source, pass `--js-file <path|->` instead of `--list-js`.
84
+
85
+ ### Call another flow
86
+
87
+ ```bash
88
+ cai node set-flow <runFlowNodeId> --flow <calledFlowId> --json
89
+ cai node props <runFlowNodeId> --json
90
+ ```
91
+
92
+ Define the called flow's inputs and outputs first, add the Run flow component, set the target, then bind the generated mapping props with expressions.
93
+
94
+ ### Converge, return, handle errors
95
+
96
+ ```bash
97
+ cai node add --flow <flowId> --node registry_flow --key registry_flow-merge --name "Join paths" --json
98
+ cai node set <joinNodeId> --prop mode --value chooseActivePath --json
99
+ cai flow output add <bodyFlowId> --display "<output label>" --name <output_key> --type <type> --json
100
+ cai node add --flow <bodyFlowId> --node registry_flow --key registry_flow-return-response --name "Return <value>" --after <producerNodeId> --json
101
+ cai node continue-on-error <nodeId> --enable --json
102
+ cai node connect --flow <flowId> --from <nodeId> --to <handlerNodeId> --output error --json
103
+ ```
104
+
105
+ Join Paths: connect every type-compatible branch tail to it (all connected input types are checked, inactive paths included, which is why `pathDataType` is asked for once `chooseActivePath` reveals it), set `pathDataType` from the returned options, and place the shared action after it (`--after <joinNodeId>`, or connect the existing action). Return: declare the output first so its generated prop exists, add the exact component after the producer, then bind the prop through the expression setter. Error output wiring is optional; add it only when a failure needs explicit handling.
106
+
107
+ ## Verify
108
+
109
+ ```bash
110
+ cai branch list <controlNodeId> --json
111
+ cai workflow validate --json
112
+ cai run flow <flowId> --inputs <values.json> --json
113
+ cai exec tree <workflowExecutionId> --json
114
+ ```
115
+
116
+ Every branch has its intended condition and a wired target; If/Else order matches priority with Else last; Router fan-out is intentional where more than one condition can be true; the loop's item type and list expression compile against real data; the paths the task implies ran: true, false or Else, empty list, one item, several, over the cap, and the intended error path; the execution tree explains every `only_when_false` and `upstream_skipped` and shows no unexplained missing node; a loop's outer success is not proof for every item, so inspect iteration records and surface individual failures.
117
+
118
+ ## Report
119
+
120
+ Which primitive carries each decision and why, the tested paths with their outcomes, any rule you could not set because the business rule was missing, and any error-continuation you enabled and where.
121
+
122
+ Read [references/patterns.md](references/patterns.md) for the canonical shapes: guard, exclusive decision, fan-out, grouped conditions, per-item subflow, convergence, return, error path.
@@ -1,18 +1,19 @@
1
+ <!-- generated from .claude/skills by cli/scripts/render-skills.mjs; edit the source -->
1
2
  # Flow-control patterns
2
3
 
3
4
  ## Guard a side effect
4
5
 
5
- Use `only-when` when false should mean "skip this action" and nothing else:
6
+ `only-when` means "skip this action, nothing else":
6
7
 
7
8
  ```text
8
9
  Read record -> Send notification [only when status changed]
9
10
  ```
10
11
 
11
- Test both true and false. A false run should show an intentional skip reason.
12
+ Test true and false; the false run shows `only_when_false` on that node and downstream stays eligible.
12
13
 
13
14
  ## Exclusive decision
14
15
 
15
- Use If/Else when only one outcome must occur:
16
+ If/Else when exactly one outcome must occur:
16
17
 
17
18
  ```text
18
19
  Score -> If/Else
@@ -21,11 +22,11 @@ Score -> If/Else
21
22
  Else -> Record unknown
22
23
  ```
23
24
 
24
- Put the most specific/highest-priority conditions first. Never write a complement condition for Else.
25
+ Most specific condition first; Else is the fallback and never gets a complement condition.
25
26
 
26
27
  ## Independent fan-out
27
28
 
28
- Use Router when every applicable action should run:
29
+ Router when every applicable action should run:
29
30
 
30
31
  ```text
31
32
  New order -> Router
@@ -36,95 +37,57 @@ New order -> Router
36
37
 
37
38
  One order may take all three routes. If that is not acceptable, use If/Else.
38
39
 
39
- ## Grouped branch condition
40
+ ## Grouped conditions
40
41
 
41
- Only Router and If/Else branch commands accept grouped conditions. The outer rows are OR and the expressions within one row are AND:
42
+ Outer rows are OR, entries within a row are AND, and each string compiles on its own:
42
43
 
43
44
  ```bash
44
- cai branch update <controlNodeId> \
45
- --route <routeId> \
46
- --condition-json '[["flow.email.isNotEmpty()","flow.units < 5"],["flow.override === true"]]' \
47
- --json
45
+ cai node only-when <nodeId> --groups-json '[["flow.email.isNotEmpty()","flow.units < 5"],["flow.override === true"]]' --json
46
+ cai branch update <controlNodeId> --route <routeId> --condition-json '[["flow.email.isNotEmpty()","flow.units < 5"],["flow.override === true"]]' --json
48
47
  ```
49
48
 
50
- Each string must compile independently. Node `only-when` has no `--condition-json`; if exact compound node-only semantics are required, report the limitation instead of using a private API or weakening the guard.
51
-
52
49
  ## Per-item subflow
53
50
 
54
- Use `cai flow for-each` to create the item flow, typed item input, loop node, and list wiring atomically. First run `cai node get <sourceNodeId> --json`, choose the intended `outputs[]` entry, and pass its exact opaque `id` as `--source-output`; never pass its label or assume the first output. Omit list-selection flags when the whole selected output payload is a list; use `--list-field <nested.path>` for a list below `.data`; reserve `--list-js` for an exact advanced expression or `--js-file <path|->` for that expression in a UTF-8 file/stdin. The three selection forms are mutually exclusive.
55
-
56
- MCP: call `flow_for_each_scaffold` and pass expression source inline as `listJs`.
57
-
58
- The runtime limit defaults to 500 items and supports 1 through 10000. Use `--max-items` when the intended bound differs, then verify the returned read-back. Put meaningful work inside the generated body flow and declare body outputs before consuming aggregate results.
51
+ ```bash
52
+ cai node get <sourceNodeId> --json
53
+ cai flow for-each --flow <parentFlowId> --from <sourceNodeId> --source-output <exactOutputId> --name "<item flow name>" --item-type <type> --json
54
+ ```
59
55
 
60
- Decide explicitly whether one child-flow failure should stop the sequential loop. Use `--continue-on-error` only when partial completion is acceptable and downstream logic handles failed iteration records. It does not recover a list or mapping expression that fails before an iteration starts.
56
+ The scaffold creates the item flow, its typed item input, the loop node and the list wiring in one operation, then materializes the optional cap; a failure setting the cap does not roll the scaffold back. The body receives one item, not the whole list; a custom-shaped item and a stored record (`dataRecord.custom.*`) are different types. Continue past a failed iteration (`--continue-on-error`) only when partial completion is acceptable and the downstream logic handles failed iteration records (null outputs with a status and an error); it cannot rescue a list or mapping expression that fails before the child starts.
61
57
 
62
58
  ## Converge exclusive paths
63
59
 
64
- Initialize Join Paths and select its active-path mode:
65
-
66
60
  ```bash
67
- cai node init \
68
- --flow <flowId> \
69
- --node registry_flow \
70
- --key registry_flow-merge \
71
- --name "Join paths" \
72
- --json
61
+ cai node add --flow <flowId> --node registry_flow --key registry_flow-merge --name "Join paths" --json
73
62
  cai node set <joinNodeId> --prop mode --value chooseActivePath --json
74
63
  cai node props <joinNodeId> --json
75
- # If returned props require it:
76
64
  cai node set <joinNodeId> --prop pathDataType --value <returnedTypeValue> --json
77
65
  cai node connect --flow <flowId> --from <firstBranchTailNodeId> --to <joinNodeId> --json
78
66
  cai node connect --flow <flowId> --from <secondBranchTailNodeId> --to <joinNodeId> --json
79
- cai node init \
80
- --flow <flowId> \
81
- --node <sharedNodeSlug> \
82
- --key <sharedNodeKey> \
83
- --name "<shared action>" \
84
- --after <joinNodeId> \
85
- --json
67
+ cai node add --flow <flowId> --node <sharedNodeSlug> --key <sharedNodeKey> --name "<shared action>" --after <joinNodeId> --json
86
68
  ```
87
69
 
88
- Set `pathDataType` only when returned props require it, using an exact returned option. Repeat the branch-tail connection for every type-compatible exclusive path. If the shared action already exists, connect it after Join Paths instead of initializing a replacement. Do not connect several branches directly to an ordinary node or duplicate the action. `chooseActivePath` requires at most one active input, so do not use it after a Router whose routes can overlap. Run one test per branch and stop after all pass.
70
+ Set `pathDataType` from the returned options once `chooseActivePath` reveals it. Repeat the tail connection for every type-compatible exclusive path; if the shared action already exists, connect it after Join Paths instead of adding a replacement. `chooseActivePath` allows at most one active input and stops the flow when none is active unless `continueIfNoActivePath` is enabled (then it passes null); after a Router whose routes can overlap use `passThrough`, which returns one field per connected input with the blocked ones null. Run one test per branch and stop after all pass.
89
71
 
90
72
  ## Return a flow value
91
73
 
92
- Declare the output before the Return response node so its generated prop exists:
93
-
94
74
  ```bash
95
- cai flow output add <bodyFlowId> \
96
- --display "<output label>" \
97
- --name <output_key> \
98
- --type <type> \
99
- --json
100
- cai node init \
101
- --flow <bodyFlowId> \
102
- --node registry_flow \
103
- --key registry_flow-return-response \
104
- --name "Return <value>" \
105
- --after <producerNodeId> \
106
- --json
75
+ cai flow output add <bodyFlowId> --display "<output label>" --name <output_key> --type <type> --json
76
+ cai node add --flow <bodyFlowId> --node registry_flow --key registry_flow-return-response --name "Return <value>" --after <producerNodeId> --json
107
77
  cai node props <returnNodeId> --json
108
78
  cai expr context <returnNodeId> --prop <generatedOutputProp> --json
109
79
  cai expr set <returnNodeId> --prop <generatedOutputProp> --js '<producer binding>' --json
110
80
  ```
111
81
 
112
- Do not guess `registry_flow-return` or `registry_flow-response`. Run the body flow and verify its top-level output contains the promised value.
82
+ Declare the output before adding the Return node so its generated prop exists. Do not guess `registry_flow-return` or `registry_flow-response`. Run the body flow and check the promised top-level output. Populate the outputs on every intended return path, including the "nothing found" path, which should return a clear result without performing writes.
113
83
 
114
84
  ## Error path
115
85
 
116
- Continue-on-error is for steps whose failure must not block the main path — notifications, logging, optional enrichment. Enabling it captures the node's error, downstream nodes still execute (receiving null for the failed node's output), and the run ends `completed_with_error`:
86
+ Continue-on-error suits steps whose failure must not block the main path: notifications, logging, optional enrichment. The node's error is captured, downstream nodes run with null for its output, and the run ends `completed_with_error`.
117
87
 
118
88
  ```bash
119
89
  cai node continue-on-error <nodeId> --enable --json
120
- ```
121
-
122
- MCP: call `node_continue_on_error_set` with `enabled: true` or `enabled: false`.
123
-
124
- Wiring the Error output is OPTIONAL — add it when a failure needs explicit handling, not as a precondition:
125
-
126
- ```bash
127
90
  cai node connect --flow <flowId> --from <nodeId> --to <handlerNodeId> --output error --json
128
91
  ```
129
92
 
130
- Never enable continue-on-error on critical-path steps (validate → charge → confirm must fail fast), and never merely to make the parent execution green. Read back the setting after changing it.
93
+ Wiring the Error output is optional. Never enable continue-on-error on a critical path (validate, charge, confirm must fail fast) and never to make a parent run green. Read the setting back after changing it.
@@ -1,24 +1,102 @@
1
1
  ---
2
2
  name: controllerai-integration-actions
3
- description: Discover and attach ready integration actions directly to Controller AI agents, configure connections and dynamic properties, and verify external app operations. Use when one existing action satisfies an agent capability.
3
+ description: Discover, connect, attach, update and verify ready integration actions that a Controller AI agent calls directly. Use when an agent needs one existing app operation without a workflow, when choosing between a direct action and a workflow tool, or when changing an action's connection or per-run approval policy.
4
4
  ---
5
+ <!-- generated from .claude/skills by cli/scripts/render-skills.mjs; edit the source -->
5
6
 
6
- # Ready actions as agent tools
7
+ # Integration actions
7
8
 
8
- A ready integration action is one existing operation: search a service, read an object, create a record or send a message. Attach it directly to an agent when that operation is the capability. Use a workflow tool when you also need deterministic validation, multiple ordered steps, transformation, persistence or a reusable typed contract.
9
+ ## Use this when
9
10
 
10
- ## Discover and configure
11
+ - An agent needs one existing app operation: send one message, create one record, add one row, look something up.
12
+ - You must decide between attaching a ready action and building a workflow tool.
13
+ - An attached action needs another connection, a different approval policy, or proof that it runs.
11
14
 
12
- Search by the intended operation, inspect the matching integration, then read its exact action key and properties. Prefer capability evidence over a similar integration name. Native actions and external provider actions can have different authorization requirements.
15
+ Building the agent itself belongs to `controllerai-agents`; a workflow node for the same app belongs to `controllerai-node-config`.
13
16
 
14
- Select an existing matching connection and verify its identity. If a new connection is needed, return the connection URL and let the user complete provider authorization. Never request provider credentials in chat. An “active” stored connection still needs a representative action test to prove current authorization.
17
+ ## How it works
15
18
 
16
- Attach the action with its exact integration/action/connection and a description that tells the agent when to use it. Inspect configurable inputs and reload dependent options after selector changes. Choose the tool's runtime confirmation setting for the requested experience.
19
+ **A ready action is one operation.** The catalog exposes provider integration actions and native registry actions that an agent can call directly, without a workflow; a native action is attachable when the catalog marks it `agentAttachable`. Most native actions need no connection: they run on the platform's paid rails, bill the user's usage balance per call, and describe the charge in `usagePricingDescription`. A native action that does need authorization uses the platform connection flow, not Pipedream. Use a workflow tool instead when the capability needs several operations, transformation, branching, loops, durable state, a trigger, a custom typed contract, or reuse outside the agent. Never wrap a ready action whose contract already fits in a one-node workflow, and never replace deterministic orchestration with several independent direct actions.
17
20
 
18
- ## Verify the attached capability
21
+ **Identity is a pair.** An action is the exact integration slug plus its action key, as returned by discovery; a display label is not an identity, and a similar integration with a familiar name is not evidence of the capability. When the catalog says the action needs a connection, it binds to one whose `integration` matches that slug exactly.
19
22
 
20
- Read the saved tool list and test in a draft conversation. Inspect the chosen action, arguments, terminal result and intended external effect. A direct action does not create a workflow execution. For a failed or uncertain mutation, inspect external state before repeating it.
23
+ **Runtime.** The agent runtime configures the action's dynamic arguments when it invokes the action; nothing is preconfigured at attachment beyond identity, any required connection, description and approval policy. A direct action runs inline in the conversation and creates no workflow execution: the evidence is the persisted conversation, its action events with arguments and result, and the external effect.
21
24
 
22
- Connection rebinding, detachment or revocation can affect Live independently of publishing the agent. If the user requested release, publish the updated agent configuration after testing and verify a Live conversation. Do not publish merely because the draft is ready.
25
+ **Approval policy.** An attached action runs without a human approval step unless `requireConfirmation` is `true`; the default is no approval. When confirmation is on, the runtime pauses with a pending request that the user approves or denies with the exact arguments visible.
23
26
 
24
- Discovery, attachment, update and removal commands: [reference](references/command-reference.md).
27
+ **Slack approvals.** Approval requests can also go to Slack with `--slack-connection <connectionId>` and `--slack-channel <channelId>`. Routes are draft tool settings published with the agent like approval settings. Test conversations use the draft; live ones use the published version. Only the connection owner and configured approvers can answer in Slack; the app's approval card still works.
28
+
29
+ **Live bindings.** Publishing snapshots the action identity, description and approval policy into the agent version. When an action needs a connection, that connection and its authorization grant are live security bindings: rebinding redirects the published action immediately, and revocation, breakage or detachment stops it immediately without an agent publish. Detachment has the same immediate effect on a connectionless action, always removes the draft tool, and a later publish removes it from the published list. Confirmation is strictest-wins: tightening the grant to require confirmation blocks the published action at once until a publish carries the new policy, while relaxing it waits for the publish. Organization members use the published agent, never the draft; connected actions run through the owner's connected account and the organization's shared usage pool, while connectionless native actions use the platform's paid rails and bill that pool whoever invokes them.
30
+
31
+ ## Rules
32
+
33
+ 1. **Capture and reuse the exact identities**: integration slug, action key, connection ID when required, tool ID. Narrow the query or raise the result limit when more matches exist; never derive an identifier from a label.
34
+ 2. **A required missing connection is a handoff, not a substitution.** Keep the selected integration and action, give the user the platform authorization route, and stop the attachment there; never request provider credentials in chat. Never swap in `registry_http-http-request`: the HTTP node is never agent-attachable, so that substitution is impossible by construction. A raw endpoint the user mentions is context, not an instruction to hand-roll the call.
35
+ 3. **Decide the approval policy before attaching.** For an action that sends, posts, spends or deletes, choose `true` or explicitly tell the user it will run unattended; prefer confirmation for permission changes, irreversible writes or an ambiguous destination, and omit it for reads and low-risk reversible operations the user asked to run autonomously. Mention the confirmation choice in the report to the user.
36
+ 4. **Attach once.** Read the tool list before and after; the final list holds one intended direct attachment.
37
+ 5. **A stored active connection is not proof of authorization.** For an action that needs one, only a representative action test proves the provider still accepts it.
38
+ 6. **Verify what the request asked for, where it lives.** Discovery proves metadata; a blocked attachment proves the honest handoff and the independent work; an attachment proves the saved grant; only an authorized runtime test proves the external effect, and for that the action event, its arguments and result, and the external state are the evidence, never a reply that says it ran. Inspect the external state before repeating a failed or uncertain mutation.
39
+ 7. **Say whose account and balance run the action** before organization sharing: connected actions use the owner's account; connectionless native actions use the platform's paid rails; calls use the organization's shared usage balance regardless of caller.
40
+
41
+ ## Recipes
42
+
43
+ ### Discover
44
+
45
+ ```bash
46
+ cai integration search "<app or capability>" --agent-attachable --json
47
+ cai integration actions "<operation>" --integration <integrationSlug> --agent-attachable --json
48
+ cai integration action --integration <integrationSlug> --key <actionKey> --json
49
+ ```
50
+
51
+ `search` ranks integrations (`--actions` or `--events` narrows the kind); `actions` ranks actions across one or all integrations; `--agent-attachable` keeps results with attachable actions; `action` returns the static metadata and props of one exact action. Read `agentAttachable`, the exact props and, for native actions, whether a connection is needed and `usagePricingDescription` before choosing.
52
+
53
+ ### Select or request a connection
54
+
55
+ ```bash
56
+ cai connection list --integration <integrationSlug> --json
57
+ ```
58
+
59
+ Skip this step when the catalog says the native action needs no connection.
60
+
61
+ Use the active connection whose `integration` matches exactly. If none exists, `cai connection connect <integrationSlug> --no-open` returns the authorization URL: share it right away, and after the user finishes, list again and use the new ID.
62
+
63
+ ### Attach
64
+
65
+ ```bash
66
+ cai agent add-action <agentId> --integration <integrationSlug> --action <actionKey> --connection <connectionId> --description "Use when ..." --require-confirmation --json
67
+ cai agent add-action <agentId> --integration <integrationSlug> --action <actionKey> --description "Use when ..." --require-confirmation --json
68
+ cai agent tools <agentId> --json
69
+ ```
70
+
71
+ `--connection` is required exactly when the catalog says the action needs one and must be omitted otherwise. `--require-confirmation` sets the policy to `true`; omitting it keeps the `false` default.
72
+ The description tells the agent when to choose the tool. Read the saved grant back: `toolType`, integration, action key, any required connection, description and confirmation policy.
73
+
74
+ ### Update
75
+
76
+ ```bash
77
+ cai agent update-tool <agentId> --tool <toolId> --connection <connectionId> --json
78
+ cai agent update-tool <agentId> --tool <toolId> --require-confirmation --json
79
+ cai agent update-tool <agentId> --tool <toolId> --no-confirmation --json
80
+ cai agent update-tool <agentId> --tool <toolId> --description "<when to use it>" --json
81
+ ```
82
+
83
+ A connection change redirects a connected published action at once. A description change waits for the agent publish. A policy change is strictest-wins: turning confirmation on blocks the published action immediately until the next publish carries it, turning it off takes effect only at that publish.
84
+
85
+ ### Verify in a draft conversation
86
+
87
+ ```bash
88
+ cai agent test <agentId> --draft --message "<request that needs the action>" --json
89
+ cai agent conversation history <conversationId> --json
90
+ cai agent conversation approve <conversationId> --request <requestId> --json
91
+ cai agent conversation deny <conversationId> --request <requestId> --message "<reason>" --json
92
+ ```
93
+
94
+ `agent test` is a one-shot that opens a new conversation; when a follow-up or an approval is expected, create one draft conversation and send into it as in `controllerai-agents`. When confirmation is on, inspect the pending action and its exact arguments, then approve or deny in that same conversation and read the history for the terminal result. Direct actions do not create workflow execution IDs: never invent one.
95
+
96
+ ## Verify
97
+
98
+ For an attachment, the tool list shows exactly one intended direct attachment with the exact identities, any required connection, description and confirmation policy; for an authorized runtime test, the draft conversation history holds the action event, its arguments and its result, and the external effect was checked separately; for discovery alone, the exact metadata was read and nothing was changed. No wrapper workflow exists unless orchestration or reuse required it.
99
+
100
+ ## Report
101
+
102
+ Which action is attached to which agent, any connection and the confirmation choice, what the draft test proved, whose account or paid rail and usage balance the action will use, and what remains: a connection to authorize, a publish, or a live verification.