@siglo/cli 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ECOSYSTEM.md +85 -0
- package/LICENSE +21 -0
- package/README.md +480 -2
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +304 -0
- package/dist/bin.js.map +1 -0
- package/dist/index.d.ts +112 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +319 -0
- package/dist/index.js.map +1 -0
- package/dist/step-templates.d.ts +24 -0
- package/dist/step-templates.d.ts.map +1 -0
- package/dist/step-templates.js +83 -0
- package/dist/step-templates.js.map +1 -0
- package/package.json +56 -4
package/ECOSYSTEM.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Ecosystem step generation
|
|
2
|
+
|
|
3
|
+
Use `siglo generate step <name> --type=<type>` from your project directory.
|
|
4
|
+
Names may be identifiers or kebab-case. Generation rejects invalid options and
|
|
5
|
+
existing step or test files; it never merges into an existing file.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
siglo generate step callStripe --type=http --url=https://api.stripe.com/v1/charges
|
|
9
|
+
siglo generate step verifyStripeWebhook --type=crypto --provider=stripe
|
|
10
|
+
siglo generate step managerApproval --type=notification --channel=slack --interactive=true
|
|
11
|
+
siglo generate step triageTicket --type=ai --provider=anthropic --model=YOUR_MODEL_ID
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The default remains the generic step and Mocha/Chai test. Ecosystem templates
|
|
15
|
+
export a `create<Name>Step` factory so tests can supply adapters, transports or
|
|
16
|
+
secret resolvers. Generated filenames retain the existing lowercase convention.
|
|
17
|
+
Options use `--key=value`; interactive prompting is not implemented.
|
|
18
|
+
|
|
19
|
+
## Consumer dependencies
|
|
20
|
+
|
|
21
|
+
Use Node.js `^22.13.0 || >=24`, TypeScript 5.7+, `tsx`, and `@types/node`.
|
|
22
|
+
Install `@siglo/core` and the package selected by the template (`@siglo/http`,
|
|
23
|
+
`@siglo/crypto`, `@siglo/notifications`, or `@siglo/ai`) as runtime dependencies.
|
|
24
|
+
Tests import each package's testing subpath; no separate mock package is needed.
|
|
25
|
+
The crypto test uses Node's built-in HMAC implementation: crypto has no testing
|
|
26
|
+
subpath. The HTTP and AI templates contain a concrete Standard Schema validator
|
|
27
|
+
and require no third-party validator. If replacing it with Zod, install Zod as a
|
|
28
|
+
runtime dependency. Generic templates additionally require Mocha, Chai, and their
|
|
29
|
+
types as development dependencies.
|
|
30
|
+
|
|
31
|
+
Run ecosystem tests serially because the HTTP testing utility replaces global
|
|
32
|
+
fetch:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
node --import tsx --test --test-concurrency=1 src/steps/*.step.test.ts
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Run generic tests with `mocha -r tsx 'src/steps/*.step.test.ts'`. Do not mix the
|
|
39
|
+
two runner conventions in a single invocation. Compile generated files with
|
|
40
|
+
`tsc --noEmit` using Node16 module resolution, ES2022 target, and esModuleInterop.
|
|
41
|
+
|
|
42
|
+
## Runtime wiring
|
|
43
|
+
|
|
44
|
+
HTTP uses a static URL and POST with sample request and response validators.
|
|
45
|
+
Change the sample body and validators to your API contract. Static URLs declare
|
|
46
|
+
the hostname automatically; a URL resolver must explicitly declare permitted
|
|
47
|
+
hosts using `.allowNetwork([...])`. Tests install core network interceptors
|
|
48
|
+
before replacing fetch, restore fetch in `finally`, and reject unmatched calls.
|
|
49
|
+
The mock covers fetch only; it does not isolate other transports.
|
|
50
|
+
|
|
51
|
+
Webhook factories resolve `WEBHOOK_SECRET` at runtime, or accept an injected
|
|
52
|
+
resolver. Pass raw request bytes/string and signature headers. Never parse and
|
|
53
|
+
re-serialize the body before verification. Tests sign a synthetic body locally
|
|
54
|
+
and verify rejection after tampering. Supported providers are Stripe, GitHub,
|
|
55
|
+
Shopify, Slack, Svix, and generic HMAC.
|
|
56
|
+
|
|
57
|
+
AI factories accept an optional adapter inside the model configuration. Supply
|
|
58
|
+
a provider-supported model ID and configure that provider's credentials in the
|
|
59
|
+
application. Tests inject `MockAiProvider`, validate structured data, and assert
|
|
60
|
+
`result.data`. Supported generated providers are OpenAI, Anthropic, Gemini and
|
|
61
|
+
Ollama; custom adapters remain available through the package API.
|
|
62
|
+
|
|
63
|
+
Notification factories require an explicit transport. For example:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { SlackTransport, ResendTransport } from '@siglo/notifications';
|
|
67
|
+
const slack = new SlackTransport({ apiKey: process.env.SLACK_TOKEN! });
|
|
68
|
+
const email = new ResendTransport({
|
|
69
|
+
apiKey: process.env.RESEND_API_KEY!, from: 'workflow@example.com',
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For Discord use `DiscordTransport`; for SMS use `TwilioTransport` with the provider's configuration; for push use
|
|
74
|
+
`PushWebhookTransport` or implement the `NotificationTransport` interface. Replace the generated example recipient.
|
|
75
|
+
The factory supplies transport host declarations to the runtime. Tests use
|
|
76
|
+
`MockNotificationTransport` and perform no delivery.
|
|
77
|
+
|
|
78
|
+
Approval generation is explicit and supports email and Slack. The generated
|
|
79
|
+
step dispatches signed actions; it does not itself suspend the workflow. In the
|
|
80
|
+
application, use a unique correlation key for each approval, register a durable
|
|
81
|
+
wait for the approved/rejected events, configure persistent workflow storage and
|
|
82
|
+
the notification dispatch/revocation stores, and expose the package's callback
|
|
83
|
+
handler with the same signing secret. Authorize the approver at that boundary.
|
|
84
|
+
Use an HTTPS callback URL and keep signing secrets in runtime configuration.
|
|
85
|
+
The generated test verifies action dispatch only, not durable resume or expiry.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Jerico de guzman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,481 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @siglo/cli Developer Tools & CLI Guide
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@siglo/cli` provides developer tooling, code scaffolding, static analysis, command-line inspection, architecture export, and regression testing utilities for `Siglo` workflows. It allows engineering teams to scaffold typed steps/workflows, visualize execution graphs, export to Mermaid/Graphviz/JSON, detect cyclic dependencies, inspect serialized checkpoints, and replay golden test fixtures in CI/CD pipelines.
|
|
4
|
+
|
|
5
|
+
See the [ecosystem generator cookbook](ECOSYSTEM.md) for HTTP, webhook, notification, and AI step templates and offline testing.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Overview
|
|
10
|
+
|
|
11
|
+
`@siglo/cli` operates both as an executable terminal tool (`Siglo`) and as a programmatic TypeScript library:
|
|
12
|
+
|
|
13
|
+
```mermaid
|
|
14
|
+
flowchart TD
|
|
15
|
+
CLI["@siglo/cli"] --> CLI_Term["Terminal Command Line"]
|
|
16
|
+
CLI --> CLI_API["Programmatic Node.js API"]
|
|
17
|
+
|
|
18
|
+
subgraph TerminalCommands["CLI Commands"]
|
|
19
|
+
C1["siglo init<br/>siglo generate workflow<br/>siglo generate step<br/>siglo visualize<br/>siglo export<br/>siglo validate<br/>siglo inspect<br/>siglo checkpoint<br/>siglo replay"]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
subgraph ProgrammaticAPI["Node.js API"]
|
|
23
|
+
A1["initProject()<br/>generateWorkflow()<br/>generateStep()<br/>visualizeWorkflow()<br/>exportWorkflow()<br/>validateWorkflow()<br/>inspectWorkflow()<br/>inspectCheckpoint()<br/>replayFixture()"]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
CLI_Term --> TerminalCommands
|
|
27
|
+
CLI_API --> ProgrammaticAPI
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 2. Installation
|
|
33
|
+
|
|
34
|
+
Install `@siglo/cli` locally in your project or globally:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Local development dependency (recommended)
|
|
38
|
+
npm install --save-dev @siglo/cli @siglo/testing @siglo/core tsx
|
|
39
|
+
|
|
40
|
+
# Or run directly via npx
|
|
41
|
+
npm exec --package=@siglo/cli -- siglo --help
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 3. Command Line Interface (CLI)
|
|
47
|
+
|
|
48
|
+
The CLI executable is `Siglo`.
|
|
49
|
+
|
|
50
|
+
### General Usage
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
Siglo <command> [arguments] [options]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Global Options:
|
|
57
|
+
- `--format=mermaid|text|dot|json`: Diagram representation or export format (default: `mermaid`).
|
|
58
|
+
- `--direction=TD|LR|TB`: Graph layout direction for Mermaid or DOT diagrams (default: `TD`).
|
|
59
|
+
- `--out=<file>`: Write output directly to a file instead of `stdout`.
|
|
60
|
+
- `--redact=key1,key2`: Comma-delimited list of sensitive context keys or node names to mask with `[REDACTED]`.
|
|
61
|
+
- `--help`, `-h`: Show CLI usage guide.
|
|
62
|
+
- `--version`, `-v`: Display CLI version.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### Command 1: `siglo init [dir]`
|
|
67
|
+
|
|
68
|
+
Scaffolds a clean starter project preconfigured with `Siglo`, `tsx`, modern TypeScript config, and a runnable workflow test.
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
siglo init ./services/order-orchestrator
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### Generated Files:
|
|
75
|
+
1. `package.json`: Contains scripts (`npm test`, `npm start`) and required dependencies.
|
|
76
|
+
2. `src/workflow.ts`: Example order processing pipeline with validation and payment steps.
|
|
77
|
+
3. `src/workflow.test.ts`: Automated test executing the workflow with assertions.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
### Command 2: `siglo generate workflow <name>`
|
|
82
|
+
|
|
83
|
+
Scaffolds a brand new typed workflow file and companion unit test powered by `@siglo/testing`.
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
siglo generate workflow order-processing
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Generated Files:
|
|
90
|
+
1. `src/workflows/order-processing.workflow.ts`: Strongly-typed input/output interfaces, steps, and default workflow export.
|
|
91
|
+
2. `src/workflows/order-processing.workflow.test.ts`: Test harness setup verifying end-to-end execution and step invocations.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
### Command 3: `siglo generate step <name>`
|
|
96
|
+
|
|
97
|
+
Scaffolds an isolated, strongly-typed `Step` module and companion unit test.
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
siglo generate step send-notification
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### Generated Files:
|
|
104
|
+
1. `src/steps/send-notification.step.ts`: Typed step module with input/output interfaces.
|
|
105
|
+
2. `src/steps/send-notification.step.test.ts`: Direct step execution test.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### Command 4: `siglo visualize <workflow-file> [options]`
|
|
110
|
+
|
|
111
|
+
Renders the workflow graph AST as either a Mermaid flowchart or an indented ASCII text hierarchy.
|
|
112
|
+
|
|
113
|
+
#### Mermaid Diagram (Default):
|
|
114
|
+
```bash
|
|
115
|
+
siglo visualize src/workflows/checkout.ts
|
|
116
|
+
```
|
|
117
|
+
*Output:*
|
|
118
|
+
```mermaid
|
|
119
|
+
flowchart TD
|
|
120
|
+
validateOrder["validateOrder (step)"]
|
|
121
|
+
chargePayment["chargePayment (step)"]
|
|
122
|
+
reserveInventory["reserveInventory (step)"]
|
|
123
|
+
validateOrder --> chargePayment
|
|
124
|
+
chargePayment --> reserveInventory
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### Text Diagram (`--format=text`):
|
|
128
|
+
```bash
|
|
129
|
+
siglo visualize src/workflows/checkout.ts --format=text
|
|
130
|
+
```
|
|
131
|
+
*Output:*
|
|
132
|
+
```text
|
|
133
|
+
Workflow Graph (total nodes: 3, edges: 2):
|
|
134
|
+
├── [step] validateOrder (validateOrder)
|
|
135
|
+
├── [step] chargePayment (chargePayment)
|
|
136
|
+
└── [step] reserveInventory (reserveInventory)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
### Command 5: `siglo export <workflow-file> [options]`
|
|
142
|
+
|
|
143
|
+
Exports the workflow topology graph directly to standard formats for architectural documentation, diagrams, or web visualization:
|
|
144
|
+
- `--format=mermaid`: Mermaid flowchart with policy badges (retries, timeouts, fallback).
|
|
145
|
+
- `--format=dot`: Graphviz DOT format compatible with Graphviz tools and PlantUML.
|
|
146
|
+
- `--format=json`: Comprehensive AST node/edge graph JSON.
|
|
147
|
+
- `--direction=TD|LR|TB`: Graph layout orientation (top-down, left-to-right).
|
|
148
|
+
- `--out=<file>`: Save result directly to a specified destination file.
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Export Mermaid diagram to file with Left-to-Right layout
|
|
152
|
+
siglo export src/workflows/order.workflow.ts --format=mermaid --direction=LR --out=docs/order-flow.mmd
|
|
153
|
+
|
|
154
|
+
# Export Graphviz DOT format
|
|
155
|
+
siglo export src/workflows/order.workflow.ts --format=dot --out=diagrams/order.dot
|
|
156
|
+
|
|
157
|
+
# Export raw JSON AST
|
|
158
|
+
siglo export src/workflows/order.workflow.ts --format=json --out=dist/order-ast.json
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
### Command 6: `siglo validate <workflow-file>`
|
|
164
|
+
|
|
165
|
+
Performs static analysis on the workflow graph AST without executing any step business logic:
|
|
166
|
+
- Detects cyclic dependencies.
|
|
167
|
+
- Identifies unreachable nodes or disconnected subgraphs.
|
|
168
|
+
- Verifies combinator structures (`parallel`, `branch`, `map`).
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
siglo validate src/workflows/loan-pipeline.ts
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
*Success Output:*
|
|
175
|
+
```text
|
|
176
|
+
✔ Workflow graph is valid (acyclic, reachable)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
*Failure Output (Exit Code 1):*
|
|
180
|
+
```text
|
|
181
|
+
✖ Workflow validation failed:
|
|
182
|
+
- Cycle detected between nodes 'processPayment' and 'retryPayment'
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
### Command 7: `siglo inspect <workflow-file> [options]`
|
|
188
|
+
|
|
189
|
+
Returns a detailed JSON telemetry summary of the workflow topology, node classifications, edge connections, and total complexity metrics.
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
siglo inspect src/workflows/settlement.ts --redact=taxId,secretKey
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
*Output:*
|
|
196
|
+
```json
|
|
197
|
+
{
|
|
198
|
+
"totalNodes": 4,
|
|
199
|
+
"edges": [
|
|
200
|
+
{ "from": "step1", "to": "step2" },
|
|
201
|
+
{ "from": "step2", "to": "step3" }
|
|
202
|
+
],
|
|
203
|
+
"nodes": [
|
|
204
|
+
{ "id": "step1", "name": "validateInput", "type": "step" },
|
|
205
|
+
{ "id": "step2", "name": "[REDACTED]", "type": "step" },
|
|
206
|
+
{ "id": "step3", "name": "persistAudit", "type": "step" }
|
|
207
|
+
],
|
|
208
|
+
"redactedFields": ["taxId", "secretKey"]
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
### Command 8: `siglo checkpoint <file> [options]`
|
|
215
|
+
|
|
216
|
+
Parses and validates a serialized checkpoint state JSON file (e.g., dumped from Redis or PostgreSQL during debugging), summarizing step chains and execution context while masking sensitive credentials.
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
siglo checkpoint ./logs/crash-checkpoint.json --redact=apiKey,password
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
*Output:*
|
|
223
|
+
```json
|
|
224
|
+
{
|
|
225
|
+
"stackId": "stack-8123-bba8",
|
|
226
|
+
"namespace": "tenant-enterprise",
|
|
227
|
+
"type": "flow",
|
|
228
|
+
"stepCount": 3,
|
|
229
|
+
"chains": ["validate", "charge", "notify"],
|
|
230
|
+
"contexts": {
|
|
231
|
+
"charge": {
|
|
232
|
+
"apiKey": "[REDACTED]",
|
|
233
|
+
"status": "APPROVED",
|
|
234
|
+
"amount": 250
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
### Command 9: `siglo replay <fixture> [workflow-file]`
|
|
243
|
+
|
|
244
|
+
Replays an end-to-end workflow execution using recorded inputs and validates that output values match golden expectations.
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
# Replay against default src/workflow.ts
|
|
248
|
+
siglo replay fixtures/order-regression.json
|
|
249
|
+
|
|
250
|
+
# Replay against explicit workflow module
|
|
251
|
+
siglo replay fixtures/order-regression.json src/workflows/order.workflow.ts
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
*Success Output:*
|
|
255
|
+
```text
|
|
256
|
+
✔ Replay passed in 14ms
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
*Regression Output (Exit Code 1):*
|
|
260
|
+
```text
|
|
261
|
+
✖ Replay failed with discrepancies: {
|
|
262
|
+
"total": {
|
|
263
|
+
"expected": 100,
|
|
264
|
+
"actual": 120
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## 4. Programmatic API Reference
|
|
272
|
+
|
|
273
|
+
Import programmatic utilities directly in your tests, scripts, and build pipelines:
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import {
|
|
277
|
+
initProject,
|
|
278
|
+
generateWorkflow,
|
|
279
|
+
generateStep,
|
|
280
|
+
visualizeWorkflow,
|
|
281
|
+
validateWorkflow,
|
|
282
|
+
inspectWorkflow,
|
|
283
|
+
inspectCheckpoint,
|
|
284
|
+
replayFixture,
|
|
285
|
+
exportWorkflow,
|
|
286
|
+
toMermaid,
|
|
287
|
+
toTextGraph,
|
|
288
|
+
ReplayFixture,
|
|
289
|
+
ReplayResult,
|
|
290
|
+
WorkflowVisualizationResult,
|
|
291
|
+
ExportWorkflowOptions
|
|
292
|
+
} from '@siglo/cli';
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
### `generateWorkflow(name, targetDir?)`
|
|
298
|
+
|
|
299
|
+
Generates typed workflow and test templates:
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
const { filePath, testPath } = generateWorkflow('payment-settlement');
|
|
303
|
+
console.log(`Generated: ${filePath} and ${testPath}`);
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
### `generateStep(name, targetDir?)`
|
|
309
|
+
|
|
310
|
+
Generates typed step and test templates:
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
const { filePath, testPath } = generateStep('audit-logger');
|
|
314
|
+
console.log(`Generated: ${filePath} and ${testPath}`);
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
### `exportWorkflow(workflow, options?)`
|
|
320
|
+
|
|
321
|
+
Exports a workflow to Mermaid, Graphviz DOT, or JSON format:
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
// Mermaid format with top-to-bottom layout
|
|
325
|
+
const mermaidDiagram = exportWorkflow(myWorkflow, {
|
|
326
|
+
format: 'mermaid',
|
|
327
|
+
direction: 'TD',
|
|
328
|
+
includeBadges: true
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
// Graphviz DOT format with left-to-right layout
|
|
332
|
+
const dotGraph = exportWorkflow(myWorkflow, {
|
|
333
|
+
format: 'dot',
|
|
334
|
+
direction: 'LR'
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// JSON AST format
|
|
338
|
+
const jsonAST = exportWorkflow(myWorkflow, {
|
|
339
|
+
format: 'json'
|
|
340
|
+
});
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
### `visualizeWorkflow(workflow)`
|
|
346
|
+
|
|
347
|
+
Generates both Mermaid and ASCII text representations of a workflow:
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
const result: WorkflowVisualizationResult = visualizeWorkflow(orderWorkflow);
|
|
351
|
+
|
|
352
|
+
console.log(result.mermaid); // Mermaid flowchart TD string
|
|
353
|
+
console.log(result.text); // ASCII text tree
|
|
354
|
+
console.log(result.nodeCount); // Total nodes in AST
|
|
355
|
+
console.log(result.hasCycles); // Boolean cycle indicator
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
### `validateWorkflow(workflow)`
|
|
361
|
+
|
|
362
|
+
Runs cycle detection and connectivity validation on the compiled graph:
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
const validation = validateWorkflow(myWorkflow);
|
|
366
|
+
|
|
367
|
+
if (!validation.valid) {
|
|
368
|
+
console.error('Validation errors:', validation.errors);
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
### `inspectWorkflow(workflow, options?)`
|
|
375
|
+
|
|
376
|
+
Analyzes graph structure and optionally redacts sensitive node names:
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
const inspection = inspectWorkflow(myWorkflow, {
|
|
380
|
+
redact: ['confidentialStep', 'authStep']
|
|
381
|
+
});
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
### `inspectCheckpoint(checkpoint, options?)`
|
|
387
|
+
|
|
388
|
+
Inspects a checkpoint object or JSON string, redacting specified context fields across all steps:
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
const summary = inspectCheckpoint(checkpointJsonString, {
|
|
392
|
+
redact: ['accessToken', 'cardToken']
|
|
393
|
+
});
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
### `replayFixture(workflow, fixture)`
|
|
399
|
+
|
|
400
|
+
Replays an end-to-end workflow against a recorded golden test fixture. Ideal for CI regression testing, schema evolution validation, and deterministic output verification.
|
|
401
|
+
|
|
402
|
+
#### TypeScript Interface:
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
export interface ReplayFixture {
|
|
406
|
+
name?: string;
|
|
407
|
+
version?: string;
|
|
408
|
+
initialParam: Record<string, any>;
|
|
409
|
+
expectedOutputs?: Record<string, any>;
|
|
410
|
+
checkpoints?: any[];
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export interface ReplayResult {
|
|
414
|
+
success: boolean;
|
|
415
|
+
durationMs: number;
|
|
416
|
+
finalContext: Record<string, any>;
|
|
417
|
+
diff?: Record<string, { expected: any; actual: any }>;
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## 5. Golden Fixture Testing in CI
|
|
424
|
+
|
|
425
|
+
Use `replayFixture` in your test suite to ensure that workflow refactoring preserves identical behavior and contract outputs:
|
|
426
|
+
|
|
427
|
+
### Step 1: Define Fixture File (`test/fixtures/pricing-fixture.json`)
|
|
428
|
+
|
|
429
|
+
```json
|
|
430
|
+
{
|
|
431
|
+
"name": "StandardTierPricing",
|
|
432
|
+
"version": "2.0.0",
|
|
433
|
+
"initialParam": {
|
|
434
|
+
"seats": 10,
|
|
435
|
+
"tier": "pro",
|
|
436
|
+
"annualDiscount": true
|
|
437
|
+
},
|
|
438
|
+
"expectedOutputs": {
|
|
439
|
+
"subtotal": 1200,
|
|
440
|
+
"discount": 240,
|
|
441
|
+
"total": 960,
|
|
442
|
+
"approved": true
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Step 2: Implement Test Runner (`test/pricing.test.ts`)
|
|
448
|
+
|
|
449
|
+
```typescript
|
|
450
|
+
import test from 'node:test';
|
|
451
|
+
import assert from 'node:assert/strict';
|
|
452
|
+
import * as path from 'path';
|
|
453
|
+
import { replayFixture } from '@siglo/cli';
|
|
454
|
+
import { pricingFlow } from '../src/workflows/pricingFlow';
|
|
455
|
+
|
|
456
|
+
test('Pricing Flow matches golden fixture expectations', async () => {
|
|
457
|
+
const fixturePath = path.resolve(__dirname, 'fixtures/pricing-fixture.json');
|
|
458
|
+
const result = await replayFixture(pricingFlow, fixturePath);
|
|
459
|
+
|
|
460
|
+
assert.equal(
|
|
461
|
+
result.success,
|
|
462
|
+
true,
|
|
463
|
+
`Workflow regression detected: ${JSON.stringify(result.diff, null, 2)}`
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
assert.ok(result.durationMs < 500, `Execution took ${result.durationMs}ms, exceeded 500ms budget`);
|
|
467
|
+
});
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
---
|
|
471
|
+
|
|
472
|
+
## 6. Workflow File Loading Mechanics
|
|
473
|
+
|
|
474
|
+
When `Siglo` loads a workflow file specified on the command line (e.g. `siglo visualize src/workflow.ts` or `siglo export src/workflow.ts`):
|
|
475
|
+
1. The file is dynamically imported using Node.js ES modules.
|
|
476
|
+
2. The loader checks exports in the following order:
|
|
477
|
+
- `export default flowInstance`
|
|
478
|
+
- `export const workflow = flowInstance`
|
|
479
|
+
- `export const pipeline = flowInstance`
|
|
480
|
+
- Any named export satisfying `isFlow` or containing a `run()` function.
|
|
481
|
+
- If the candidate is a zero-argument factory function (e.g., `export default () => flow(...)`), it is invoked automatically to construct the graph.
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|