@addai/flows-mcp 0.5.0 → 1.0.0-rc.2
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/dist/bin/install.js +4 -2
- package/dist/bin/install.js.map +1 -1
- package/dist/client.d.ts +1 -0
- package/dist/client.js +1 -0
- package/dist/client.js.map +1 -1
- package/dist/index.js +20 -7
- package/dist/index.js.map +1 -1
- package/dist/layout.d.ts +26 -0
- package/dist/layout.js +54 -0
- package/dist/layout.js.map +1 -0
- package/dist/node-defaults.d.ts +1 -0
- package/dist/node-defaults.js +26 -0
- package/dist/node-defaults.js.map +1 -1
- package/dist/tools/custom-nodes.js +1 -4
- package/dist/tools/custom-nodes.js.map +1 -1
- package/dist/tools/discover.d.ts +9 -0
- package/dist/tools/discover.js +56 -0
- package/dist/tools/discover.js.map +1 -0
- package/dist/tools/edits.d.ts +12 -0
- package/dist/tools/edits.js +66 -0
- package/dist/tools/edits.js.map +1 -0
- package/dist/tools/flows.js +1 -5
- package/dist/tools/flows.js.map +1 -1
- package/dist/tools/nodes.js +1 -6
- package/dist/tools/nodes.js.map +1 -1
- package/dist/tools/preview.js +1 -6
- package/dist/tools/preview.js.map +1 -1
- package/dist/tools/test.d.ts +10 -0
- package/dist/tools/test.js +51 -0
- package/dist/tools/test.js.map +1 -0
- package/dist/tools/validate.d.ts +9 -0
- package/dist/tools/validate.js +50 -0
- package/dist/tools/validate.js.map +1 -0
- package/dist/tools/workspaces.d.ts +1 -1
- package/dist/tools/workspaces.js +4 -5
- package/dist/tools/workspaces.js.map +1 -1
- package/dist/v2-client.d.ts +65 -0
- package/dist/v2-client.js +179 -0
- package/dist/v2-client.js.map +1 -0
- package/package.json +1 -1
- package/skill/SKILL.md +64 -102
- package/skill/anti-patterns.md +106 -176
- package/skill/flow-semantics.md +142 -0
- package/skill/recipes.md +158 -267
- package/skill/version.txt +1 -1
- package/skill/node-cheatsheet.md +0 -37
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* McpV2Client — thin client for the new mcp-v2-api Supabase Edge Function.
|
|
3
|
+
*
|
|
4
|
+
* Reliability primitives:
|
|
5
|
+
* - structured errors (preserves trace_id, field_path, node_id)
|
|
6
|
+
* - retry with exponential backoff on idempotent verbs and 429s
|
|
7
|
+
* - ETag caching for catalog endpoints (per-session)
|
|
8
|
+
* - automatic Idempotency-Key on POST creation requests
|
|
9
|
+
* - per-flow ETag tracking for optimistic concurrency
|
|
10
|
+
*/
|
|
11
|
+
import { randomUUID, createHash } from 'crypto';
|
|
12
|
+
export class McpV2ApiError extends Error {
|
|
13
|
+
code;
|
|
14
|
+
status;
|
|
15
|
+
traceId;
|
|
16
|
+
fieldPath;
|
|
17
|
+
nodeId;
|
|
18
|
+
constructor(opts) {
|
|
19
|
+
super(opts.message);
|
|
20
|
+
this.name = 'McpV2ApiError';
|
|
21
|
+
this.code = opts.code;
|
|
22
|
+
this.status = opts.status;
|
|
23
|
+
this.traceId = opts.traceId ?? null;
|
|
24
|
+
this.fieldPath = opts.fieldPath ?? null;
|
|
25
|
+
this.nodeId = opts.nodeId ?? null;
|
|
26
|
+
}
|
|
27
|
+
static fromBody(body, status) {
|
|
28
|
+
const e = body?.error ?? {};
|
|
29
|
+
return new McpV2ApiError({
|
|
30
|
+
code: e.code ?? 'UNKNOWN_ERROR',
|
|
31
|
+
message: e.message ?? body?.message ?? 'Request failed',
|
|
32
|
+
status,
|
|
33
|
+
traceId: e.trace_id ?? null,
|
|
34
|
+
fieldPath: e.field_path ?? null,
|
|
35
|
+
nodeId: e.node_id ?? null,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const CACHEABLE_PREFIXES = [
|
|
40
|
+
'/v1/node-types',
|
|
41
|
+
'/v1/page-elements',
|
|
42
|
+
'/v1/operators',
|
|
43
|
+
'/v1/schema/',
|
|
44
|
+
'/v1/layout-config',
|
|
45
|
+
];
|
|
46
|
+
const IDEMPOTENT_METHODS = new Set(['GET', 'PUT', 'DELETE']);
|
|
47
|
+
export class McpV2Client {
|
|
48
|
+
apiKey;
|
|
49
|
+
baseUrl;
|
|
50
|
+
sessionId;
|
|
51
|
+
catalogCache = new Map();
|
|
52
|
+
flowEtags = new Map();
|
|
53
|
+
constructor(apiKey, baseUrl) {
|
|
54
|
+
this.apiKey = apiKey;
|
|
55
|
+
this.baseUrl = baseUrl.replace(/\/+$/, '');
|
|
56
|
+
this.sessionId = randomUUID();
|
|
57
|
+
}
|
|
58
|
+
get(path, opts = {}) {
|
|
59
|
+
return this.request('GET', path, undefined, opts);
|
|
60
|
+
}
|
|
61
|
+
post(path, body, opts = {}) {
|
|
62
|
+
return this.request('POST', path, body, opts);
|
|
63
|
+
}
|
|
64
|
+
put(path, body, opts = {}) {
|
|
65
|
+
return this.request('PUT', path, body, opts);
|
|
66
|
+
}
|
|
67
|
+
patch(path, body, opts = {}) {
|
|
68
|
+
return this.request('PATCH', path, body, opts);
|
|
69
|
+
}
|
|
70
|
+
delete(path, opts = {}) {
|
|
71
|
+
return this.request('DELETE', path, undefined, opts);
|
|
72
|
+
}
|
|
73
|
+
/** Manually record the ETag for a flow read (used by getFlow consumers). */
|
|
74
|
+
rememberFlowEtag(flowId, etag) {
|
|
75
|
+
if (flowId && etag)
|
|
76
|
+
this.flowEtags.set(flowId, etag);
|
|
77
|
+
}
|
|
78
|
+
/** Clear cached state for a flow (call after a 412 conflict). */
|
|
79
|
+
invalidateFlow(flowId) {
|
|
80
|
+
this.flowEtags.delete(flowId);
|
|
81
|
+
}
|
|
82
|
+
isCacheable(method, path) {
|
|
83
|
+
return method === 'GET' && CACHEABLE_PREFIXES.some((p) => path.startsWith(p));
|
|
84
|
+
}
|
|
85
|
+
extractFlowIdFromPath(path) {
|
|
86
|
+
const m = path.match(/^\/v1\/flows\/([^/?]+)/);
|
|
87
|
+
return m?.[1] ?? null;
|
|
88
|
+
}
|
|
89
|
+
deriveIdempotencyKey(method, path, body) {
|
|
90
|
+
const payload = JSON.stringify({ m: method, p: path, b: body ?? null });
|
|
91
|
+
const hash = createHash('sha256').update(`${this.sessionId}:${payload}`).digest('hex').slice(0, 32);
|
|
92
|
+
return `mcp_${hash}`;
|
|
93
|
+
}
|
|
94
|
+
async request(method, path, body, opts = {}) {
|
|
95
|
+
const headers = {
|
|
96
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
97
|
+
'Content-Type': 'application/json',
|
|
98
|
+
...(opts.headers ?? {}),
|
|
99
|
+
};
|
|
100
|
+
// ETag cache for catalog reads
|
|
101
|
+
let cachedEntry = null;
|
|
102
|
+
if (this.isCacheable(method, path)) {
|
|
103
|
+
cachedEntry = this.catalogCache.get(path) ?? null;
|
|
104
|
+
if (cachedEntry && !headers['If-None-Match']) {
|
|
105
|
+
headers['If-None-Match'] = cachedEntry.etag;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Auto If-Match for flow writes
|
|
109
|
+
if ((method === 'PUT' || method === 'PATCH' || method === 'DELETE') && !headers['If-Match']) {
|
|
110
|
+
const flowId = this.extractFlowIdFromPath(path);
|
|
111
|
+
const stored = flowId ? this.flowEtags.get(flowId) : null;
|
|
112
|
+
if (stored)
|
|
113
|
+
headers['If-Match'] = stored;
|
|
114
|
+
}
|
|
115
|
+
// Auto Idempotency-Key on creation requests
|
|
116
|
+
if (method === 'POST' && !headers['Idempotency-Key']) {
|
|
117
|
+
headers['Idempotency-Key'] = this.deriveIdempotencyKey(method, path, body);
|
|
118
|
+
}
|
|
119
|
+
const maxAttempts = IDEMPOTENT_METHODS.has(method) ? 3 : 1;
|
|
120
|
+
let lastErr;
|
|
121
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
122
|
+
try {
|
|
123
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
124
|
+
method,
|
|
125
|
+
headers,
|
|
126
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
127
|
+
});
|
|
128
|
+
// 304 — return cached body wrapped as a fresh response
|
|
129
|
+
if (res.status === 304 && cachedEntry) {
|
|
130
|
+
return cachedEntry.body;
|
|
131
|
+
}
|
|
132
|
+
// 412 conflict — clear flow etag so caller can re-fetch and retry
|
|
133
|
+
if (res.status === 412) {
|
|
134
|
+
const flowId = this.extractFlowIdFromPath(path);
|
|
135
|
+
if (flowId)
|
|
136
|
+
this.invalidateFlow(flowId);
|
|
137
|
+
}
|
|
138
|
+
const text = await res.text();
|
|
139
|
+
const parsed = text ? JSON.parse(text) : null;
|
|
140
|
+
if (!res.ok) {
|
|
141
|
+
const err = McpV2ApiError.fromBody(parsed, res.status);
|
|
142
|
+
if ((res.status >= 500 || res.status === 429) && attempt < maxAttempts) {
|
|
143
|
+
lastErr = err;
|
|
144
|
+
await new Promise((r) => setTimeout(r, 200 * Math.pow(2, attempt - 1)));
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
// Cache catalog reads
|
|
150
|
+
if (this.isCacheable(method, path)) {
|
|
151
|
+
const etag = res.headers.get('etag');
|
|
152
|
+
if (etag && parsed) {
|
|
153
|
+
this.catalogCache.set(path, { etag, body: parsed, storedAt: Date.now() });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Track ETag for subsequent flow writes
|
|
157
|
+
const flowId = this.extractFlowIdFromPath(path);
|
|
158
|
+
if (flowId && method === 'GET') {
|
|
159
|
+
const etag = res.headers.get('etag');
|
|
160
|
+
if (etag)
|
|
161
|
+
this.flowEtags.set(flowId, etag);
|
|
162
|
+
}
|
|
163
|
+
return parsed;
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
if (err instanceof McpV2ApiError)
|
|
167
|
+
throw err;
|
|
168
|
+
lastErr = err;
|
|
169
|
+
if (attempt < maxAttempts) {
|
|
170
|
+
await new Promise((r) => setTimeout(r, 200 * Math.pow(2, attempt - 1)));
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
throw lastErr;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=v2-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v2-client.js","sourceRoot":"","sources":["../src/v2-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAOhD,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtB,IAAI,CAAS;IACb,MAAM,CAAS;IACf,OAAO,CAAgB;IACvB,SAAS,CAAgB;IACzB,MAAM,CAAgB;IAEtC,YAAY,IAOX;QACC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAS,EAAE,MAAc;QACvC,MAAM,CAAC,GAAG,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,IAAI,aAAa,CAAC;YACvB,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,eAAe;YAC/B,OAAO,EAAE,CAAC,CAAC,OAAO,IAAI,IAAI,EAAE,OAAO,IAAI,gBAAgB;YACvD,MAAM;YACN,OAAO,EAAE,CAAC,CAAC,QAAQ,IAAI,IAAI;YAC3B,SAAS,EAAE,CAAC,CAAC,UAAU,IAAI,IAAI;YAC/B,M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GAAG,CAAC;gBAC5C,OAAO,GAAG,GAAG,CAAC;gBACd,IAAI,OAAO,GAAG,WAAW,EAAE,CAAC;oBAC1B,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;oBACxE,SAAS;gBACX,CAAC;gBACD,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC;QACD,MAAM,OAAO,CAAC;IAChB,CAAC;CACF"}
|
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED
|
@@ -1,116 +1,78 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: building-aiflows
|
|
3
|
-
description:
|
|
3
|
+
description: Build, test, and publish +Ai Flows automations. Use whenever the user wants to create or modify a flow. Loaded automatically when the @addai/flows-mcp MCP server is connected.
|
|
4
|
+
version: 2.0.0
|
|
4
5
|
---
|
|
5
6
|
|
|
6
|
-
# Building +Ai Flows
|
|
7
|
+
# Building +Ai Flows
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
You have access to the +Ai Flows MCP server. This skill teaches you how to use it to build production-quality flows.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
## Mental model
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
A flow is a **directed graph**: nodes connected by edges. Execution starts at a trigger node and follows edges until it reaches a terminator (goal or exit) or fails.
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
- **Nodes** do work — trigger an event, make an HTTP call, branch on a condition, send an email.
|
|
16
|
+
- **Edges** define order. Most nodes have one outgoing edge. **Branching nodes** (`if`, `switch`, `loop`, `review`, `splitTest`, `aiSwitch`) have multiple, distinguished by `sourceHandle`.
|
|
17
|
+
- **Variables** carry values between nodes via three distinct templating systems (see `flow-semantics.md`).
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
## The rigid workflow
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
Call `list_node_types()` once. Scan the returned `types` array to see what's available. Note which categories are relevant to the flow you're building.
|
|
21
|
+
You MUST follow this loop. Each step has a named tool.
|
|
20
22
|
|
|
21
|
-
### 2. Study each node type you'll use
|
|
22
|
-
For EVERY unique node type you plan to add, call `get_node_type_info(node_type)` FIRST. Read carefully:
|
|
23
|
-
- `defaultData` — the exact fields you need to set
|
|
24
|
-
- `handles.source` — for branching nodes, the allowed `source_handle` values
|
|
25
|
-
- `outputShape` — the fields you can reference downstream via `{{nodeId.field}}`
|
|
26
|
-
- `tips` — gotchas the registry has seen before
|
|
27
|
-
|
|
28
|
-
If it's a `page` node, also call `list_page_elements` and `get_page_element_info(element_type)` for each form element you'll use.
|
|
29
|
-
|
|
30
|
-
### 3. Scaffold the flow
|
|
31
23
|
```
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
1. DISCOVER → list_node_types, describe_node_type, list_custom_nodes, describe_custom_node
|
|
25
|
+
2. DESIGN → propose_flow (NL → draft) [optional]
|
|
26
|
+
3. BUILD → create_flow, add_nodes, connect_nodes, set_variable
|
|
27
|
+
4. VALIDATE → validate_flow ← MUST PASS BEFORE TESTING
|
|
28
|
+
5. TEST → test_node (per uncertain node), test_flow / dry_run (end-to-end)
|
|
29
|
+
6. DEBUG → diagnose_run, replay_run, tail_logs [if test fails]
|
|
30
|
+
7. PUBLISH → pre_publish_check, then publish_flow / canary_publish
|
|
34
31
|
```
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
- `
|
|
42
|
-
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
|
54
|
-
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
| `
|
|
59
|
-
|
|
|
60
|
-
| `
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
### 11. Publish
|
|
83
|
-
Only after step 9 returns `status: "completed"` with every node succeeding, call `publish_flow(flow_id)`.
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
## Red-flag thoughts (stop and course-correct)
|
|
88
|
-
|
|
89
|
-
| Thought | Reality |
|
|
90
|
-
|---------|---------|
|
|
91
|
-
| "I know this node type, skip `get_node_type_info`" | The registry has required fields and handle names you don't remember exactly. Call it. |
|
|
92
|
-
| "Simple flow, skip `validate_flow`" | Simple flows have silent handle mismatches and missing IDs. Validate every time. |
|
|
93
|
-
| "Tests take too long, user can test" | You own correctness. Test before claiming done. |
|
|
94
|
-
| "I'll use `{{trigger.body.x}}` in this code node, it's cleaner" | Code sandboxes don't expand templates. You'll get the literal string. Use `$("nodeId")`. |
|
|
95
|
-
| "preview_flow is redundant with add_nodes" | Preview catches errors without churning the canvas. Use it for the first batch at minimum. |
|
|
96
|
-
| "I'll fix the warnings later" | Warnings often point at real bugs (unknown variable, unreachable goal). Read them. |
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
## Three-system variable cheat sheet
|
|
101
|
-
|
|
102
|
-
| Where | Syntax | Example |
|
|
103
|
-
|-------|--------|---------|
|
|
104
|
-
| **Config fields** (URL, body, headers, conditions, element defaults) | `{{nodeId.field}}` or `{{Variables.varName}}` | `url: "https://api.x/{{abc-123.body.id}}"` |
|
|
105
|
-
| **Code node `code`** | `$("nodeId")` — returns that node's full output object | `const t = $("abc-123"); return { id: t.body.id }` |
|
|
106
|
-
| **Custom node code** | `inputs.keyName` (pre-resolved), `secrets.keyName` | `const key = secrets.api_key` |
|
|
107
|
-
|
|
108
|
-
**Never mix:** `$()` in a config field is an error. `{{}}` in code is a warning (it's a literal string, won't resolve).
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## See also
|
|
113
|
-
|
|
114
|
-
- `recipes.md` — 8 copy-paste working patterns
|
|
115
|
-
- `anti-patterns.md` — the specific wrong/right examples for the four failure modes
|
|
116
|
-
- `node-cheatsheet.md` — one-row-per-type quick reference
|
|
33
|
+
**You have not finished if you did not validate and test before publishing.**
|
|
34
|
+
|
|
35
|
+
## Five rules you must not break
|
|
36
|
+
|
|
37
|
+
1. **Never guess a node's config schema.** Call `describe_node_type(type)` first if you have not used this type in this session.
|
|
38
|
+
2. **Never assign random node positions.** Pass no `position` to `add_nodes` — it auto-places horizontally. Or call `autolayout` after.
|
|
39
|
+
3. **Never reuse `{{}}` syntax inside a code node.** Code nodes use `$("nodeId")`. Custom node code uses `inputs.x`. See `flow-semantics.md`.
|
|
40
|
+
4. **Never insert a `customNode` without `customVersionId`.** Custom nodes do not auto-update on publish — explicit version pinning is required.
|
|
41
|
+
5. **Never publish without `pre_publish_check`.** Even if validation passes.
|
|
42
|
+
|
|
43
|
+
## Tool-by-step quick reference
|
|
44
|
+
|
|
45
|
+
| Step | Tool | Purpose |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| Discover types | `list_node_types`, `describe_node_type` | What's available, what each node needs |
|
|
48
|
+
| Discover custom | `list_custom_nodes`, `describe_custom_node` | Workspace-specific reusable nodes |
|
|
49
|
+
| Discover layout | `get_layout_config` | Canonical h_spacing / v_spacing constants |
|
|
50
|
+
| Create flow | `create_flow` | New empty flow with trigger node |
|
|
51
|
+
| Add nodes | `add_nodes` | Insert nodes + edges; auto-positions horizontally |
|
|
52
|
+
| Connect | `connect_nodes`, `disconnect_nodes` | Atomic edge ops |
|
|
53
|
+
| Variables | `set_variable`, `list_variables`, `delete_variable` | Atomic per-name; no full flow rewrite |
|
|
54
|
+
| Lay out | `autolayout` | One-call horizontal cleanup |
|
|
55
|
+
| Validate | `validate_flow` | Server-authoritative; errors[] and warnings[] |
|
|
56
|
+
| Test node | `test_node` | Run one node in isolation |
|
|
57
|
+
| Test code | `test_custom_node_code` | Verify custom node code before save |
|
|
58
|
+
| Test flow | `test_flow`, `dry_run` | End-to-end; dry_run suppresses side effects |
|
|
59
|
+
| Debug | `diagnose_run`, `replay_run` (Phase 2), `tail_logs` (Phase 2) | One-call diagnostics; re-execute |
|
|
60
|
+
| Pre-publish | `pre_publish_check` (Phase 2) | Gate: validation + snapshot tests + secret scan |
|
|
61
|
+
| Publish | `publish_flow`, `canary_publish` (Phase 2) | Production rollout |
|
|
62
|
+
| Undo | `undo_last_operation` | Session-scoped stack |
|
|
63
|
+
| Safety | `confirm_intent` | Two-step destructive ops |
|
|
64
|
+
|
|
65
|
+
## How to handle uncertainty
|
|
66
|
+
|
|
67
|
+
If you don't know:
|
|
68
|
+
- **What a node does** → `describe_node_type(type)`. Don't guess.
|
|
69
|
+
- **What fields a custom node needs** → `describe_custom_node(custom_node_id)`. The schema is authoritative.
|
|
70
|
+
- **What a template reference will resolve to** → test the upstream node with `test_node` first.
|
|
71
|
+
- **Whether your config is valid** → `validate_flow`.
|
|
72
|
+
- **Why a run failed** → `diagnose_run(run_id)` (Phase 2). For now: `get_run` + `list_node_logs` + `get_node_output`.
|
|
73
|
+
|
|
74
|
+
Asking the human costs you a turn. The tools above usually answer the question faster than the human would.
|
|
75
|
+
|
|
76
|
+
## Now go
|
|
77
|
+
|
|
78
|
+
Start with `list_node_types`. Then read `flow-semantics.md` for variable systems and edge handles. Then read `recipes.md` for patterns. Then read `anti-patterns.md` to know what NOT to do.
|