@flow-as-code/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +446 -0
  3. package/dist/aws.d.ts +28 -0
  4. package/dist/aws.d.ts.map +1 -0
  5. package/dist/aws.js +104 -0
  6. package/dist/aws.js.map +1 -0
  7. package/dist/bin.d.ts +3 -0
  8. package/dist/bin.d.ts.map +1 -0
  9. package/dist/bin.js +132 -0
  10. package/dist/bin.js.map +1 -0
  11. package/dist/bridge/exportFiles.d.ts +16 -0
  12. package/dist/bridge/exportFiles.d.ts.map +1 -0
  13. package/dist/bridge/exportFiles.js +95 -0
  14. package/dist/bridge/exportFiles.js.map +1 -0
  15. package/dist/bridge/pair.d.ts +103 -0
  16. package/dist/bridge/pair.d.ts.map +1 -0
  17. package/dist/bridge/pair.js +219 -0
  18. package/dist/bridge/pair.js.map +1 -0
  19. package/dist/bridge/protocol.d.ts +187 -0
  20. package/dist/bridge/protocol.d.ts.map +1 -0
  21. package/dist/bridge/protocol.js +132 -0
  22. package/dist/bridge/protocol.js.map +1 -0
  23. package/dist/bridge/server.d.ts +95 -0
  24. package/dist/bridge/server.d.ts.map +1 -0
  25. package/dist/bridge/server.js +669 -0
  26. package/dist/bridge/server.js.map +1 -0
  27. package/dist/cdk-scaffold.d.ts +16 -0
  28. package/dist/cdk-scaffold.d.ts.map +1 -0
  29. package/dist/cdk-scaffold.js +28 -0
  30. package/dist/cdk-scaffold.js.map +1 -0
  31. package/dist/codegen.d.ts +5 -0
  32. package/dist/codegen.d.ts.map +1 -0
  33. package/dist/codegen.js +27 -0
  34. package/dist/codegen.js.map +1 -0
  35. package/dist/diff.d.ts +33 -0
  36. package/dist/diff.d.ts.map +1 -0
  37. package/dist/diff.js +225 -0
  38. package/dist/diff.js.map +1 -0
  39. package/dist/docs.d.ts +46 -0
  40. package/dist/docs.d.ts.map +1 -0
  41. package/dist/docs.js +223 -0
  42. package/dist/docs.js.map +1 -0
  43. package/dist/emit.d.ts +8 -0
  44. package/dist/emit.d.ts.map +1 -0
  45. package/dist/emit.js +55 -0
  46. package/dist/emit.js.map +1 -0
  47. package/dist/errors.d.ts +12 -0
  48. package/dist/errors.d.ts.map +1 -0
  49. package/dist/errors.js +25 -0
  50. package/dist/errors.js.map +1 -0
  51. package/dist/export.d.ts +27 -0
  52. package/dist/export.d.ts.map +1 -0
  53. package/dist/export.js +126 -0
  54. package/dist/export.js.map +1 -0
  55. package/dist/index.d.ts +4 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +23 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/lint.d.ts +6 -0
  60. package/dist/lint.d.ts.map +1 -0
  61. package/dist/lint.js +31 -0
  62. package/dist/lint.js.map +1 -0
  63. package/dist/render.d.ts +6 -0
  64. package/dist/render.d.ts.map +1 -0
  65. package/dist/render.js +49 -0
  66. package/dist/render.js.map +1 -0
  67. package/dist/run.d.ts +13 -0
  68. package/dist/run.d.ts.map +1 -0
  69. package/dist/run.js +38 -0
  70. package/dist/run.js.map +1 -0
  71. package/dist/simulate.d.ts +35 -0
  72. package/dist/simulate.d.ts.map +1 -0
  73. package/dist/simulate.js +194 -0
  74. package/dist/simulate.js.map +1 -0
  75. package/dist/studio.d.ts +23 -0
  76. package/dist/studio.d.ts.map +1 -0
  77. package/dist/studio.js +120 -0
  78. package/dist/studio.js.map +1 -0
  79. package/dist/synth-resolve-hook.d.ts +19 -0
  80. package/dist/synth-resolve-hook.d.ts.map +1 -0
  81. package/dist/synth-resolve-hook.js +127 -0
  82. package/dist/synth-resolve-hook.js.map +1 -0
  83. package/dist/synth-runner.d.ts +12 -0
  84. package/dist/synth-runner.d.ts.map +1 -0
  85. package/dist/synth-runner.js +145 -0
  86. package/dist/synth-runner.js.map +1 -0
  87. package/dist/synth.d.ts +55 -0
  88. package/dist/synth.d.ts.map +1 -0
  89. package/dist/synth.js +327 -0
  90. package/dist/synth.js.map +1 -0
  91. package/dist/watch.d.ts +66 -0
  92. package/dist/watch.d.ts.map +1 -0
  93. package/dist/watch.js +293 -0
  94. package/dist/watch.js.map +1 -0
  95. package/package.json +85 -0
  96. package/schema/flowdoc-0.1.schema.json +669 -0
  97. package/schema/scenario-0.1.schema.json +318 -0
  98. package/src/aws.ts +149 -0
  99. package/src/bin.ts +179 -0
  100. package/src/bridge/exportFiles.ts +116 -0
  101. package/src/bridge/pair.ts +312 -0
  102. package/src/bridge/protocol.ts +289 -0
  103. package/src/bridge/server.ts +827 -0
  104. package/src/cdk-scaffold.ts +41 -0
  105. package/src/codegen.ts +36 -0
  106. package/src/diff.ts +279 -0
  107. package/src/docs.ts +249 -0
  108. package/src/emit.ts +69 -0
  109. package/src/errors.ts +27 -0
  110. package/src/export.ts +167 -0
  111. package/src/index.ts +27 -0
  112. package/src/lint.ts +42 -0
  113. package/src/render.ts +58 -0
  114. package/src/run.ts +42 -0
  115. package/src/simulate.ts +244 -0
  116. package/src/studio.ts +143 -0
  117. package/src/synth-resolve-hook.ts +152 -0
  118. package/src/synth-runner.ts +157 -0
  119. package/src/synth.ts +380 -0
  120. package/src/watch.ts +388 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 The flow-as-code Authors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,446 @@
1
+ # @flow-as-code/cli
2
+
3
+ Install with `npm i -D @flow-as-code/cli`. Apache-2.0, Node 22.12 or newer.
4
+ Installing it brings the other four, so `npx flow-cli` works straight away. [`examples/promote-across-environments/`](https://github.com/flow-as-code/flow-as-code/tree/main/examples/promote-across-environments)
5
+ is a worked run of `lint` and `emit` against one document and two environments.
6
+
7
+ <!-- src/cli.test.ts parses the first fenced block below and holds it to what
8
+ `flow-cli --help` prints, so keep it first and keep it untagged. -->
9
+
10
+ ```
11
+ flow-cli lint <dir-or-file> [--format text|json] rule set over the whole document set
12
+ flow-cli render <dir-or-file> --resources map.json standalone materialization
13
+ flow-cli codegen <doc.flowdoc.json> [--out <file.ts>] FlowDoc -> typed builder TS
14
+ flow-cli synth <file.flow.ts> [--out <dir>] TS -> FlowDoc (sandboxed child process)
15
+ flow-cli emit <dir> --target cdk|tf [--address-map refs.tfmap.json]
16
+ flow-cli diff <dir> --instance <arn> local FlowDocs vs the live instance
17
+ flow-cli export --instance <arn> [--out <dir>] [--no-codegen] [--on-error abort|collect]
18
+ flow-cli simulate <scenarios> --instance <arn> [--resource-map <file>] [--format junit|json] [--out <file>]
19
+ flow-cli studio [dir] [--port <port>] local visual editor, live sync both ways
20
+ ```
21
+
22
+ ## Availability
23
+
24
+ Every command above is wired, so `--help` is the complete surface; a test in
25
+ `src/cli.test.ts` holds `--help` and the usage block above to the same list.
26
+
27
+ | Command | Status | Notes |
28
+ | ---------- | --------- | -------------------------------------------------------------------------------- |
29
+ | `lint` | available | Whole set in one pass, so cross-document rules resolve module references |
30
+ | `codegen` | available | `@keep` comments in an existing output file survive regeneration |
31
+ | `synth` | available | Sandboxed child process; see below |
32
+ | `render` | available | Strict resource map; every unmapped token is listed at once |
33
+ | `emit` | available | `--target tf` writes `@flow-as-code/tf` output, `--target cdk` writes a scaffold |
34
+ | `export` | available | Live instance to FlowDoc pairs; collects failures by default |
35
+ | `simulate` | available | Scenario suite through the TestCase API, JUnit or JSON report |
36
+ | `diff` | available | Local documents against the live instance; exit 2 when it cannot tell |
37
+ | `studio` | available | Local bridge on 127.0.0.1 serving the studio, with live sync both ways |
38
+
39
+ Exit codes: 0 on success, 1 for a failure (a missing path, malformed JSON, a
40
+ schema-invalid document, an unmapped token, an unknown flag value, a lint
41
+ finding with error severity, a flow that could not be exported, a scenario that
42
+ did not pass, or a document that differs from the instance). `diff` alone also
43
+ uses 2, for an error in the comparison itself, so a script can tell "differs"
44
+ from "could not tell".
45
+
46
+ ## Importing it
47
+
48
+ The command lives in `dist/bin.js` and nothing else loads it, so importing the
49
+ package never parses argv or exits the host process. The package root is a
50
+ library entry, the union of the three subpaths:
51
+
52
+ ```ts
53
+ import { synthFile, createWatcher, startStudioServer } from "@flow-as-code/cli";
54
+ // or, narrower:
55
+ import { synthFile } from "@flow-as-code/cli/synth";
56
+ import { createWatcher } from "@flow-as-code/cli/watch";
57
+ import { startStudioServer } from "@flow-as-code/cli/bridge";
58
+ ```
59
+
60
+ `src/index.test.ts` imports the built root in a child process and fails if it
61
+ writes anything or exits, and holds the root's exports equal to the union of
62
+ the three subpaths.
63
+
64
+ ## Connecting to an instance
65
+
66
+ `export`, `simulate`, and `diff` take `--instance <arn>`, the instance ARN as
67
+ the console's account overview shows it
68
+ (https://docs.aws.amazon.com/connect/latest/adminguide/find-instance-arn.html).
69
+ Only an instance ARN is accepted: a bare instance id carries no Region, and a
70
+ resource ARN names the wrong thing.
71
+
72
+ The Region is read from the ARN. Nothing consults `AWS_REGION` or a profile's
73
+ region, so an instance in one Region is never addressed through a client
74
+ configured for another
75
+ (https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-region.html).
76
+
77
+ Credentials come from the AWS SDK's default provider chain: environment
78
+ variables, the shared config and credentials files with their profiles and SSO
79
+ sessions, web identity, and the container and instance metadata endpoints
80
+ (https://docs.aws.amazon.com/sdkref/latest/guide/standardized-credentials.html).
81
+ The CLI takes no credential flags and stores nothing. Pick a profile with
82
+ `AWS_PROFILE` as you would for the AWS CLI.
83
+
84
+ `@aws-sdk/client-connect` is an optional peer dependency, loaded only when one
85
+ of these three commands runs, so the offline commands do not pay for it. When
86
+ it is not installed the command exits 1 with one line naming the package and
87
+ the install command, no stack trace. An SDK that is installed but will not
88
+ load (a dependency of its own missing, a broken install) is a different
89
+ failure and is reported as `@aws-sdk/client-connect could not be loaded:` with
90
+ the loader's reason, since the install command is not the fix. `simulate` also
91
+ checks that the installed SDK exposes the TestCase operations, which are
92
+ recent, and names the version that has them all when it does not.
93
+
94
+ Every other command works with no SDK installed and makes no network calls.
95
+
96
+ ## Input and output conventions
97
+
98
+ `lint`, `render`, and `emit` take a directory or a single file. A directory
99
+ contributes every `*.flowdoc.json` in it, sorted by name, and is not walked
100
+ recursively. Every document is validated against `flowdoc-0.1.schema.json`, the
101
+ byte copy of `conformance/schema/flowdoc-0.1.schema.json` this package ships,
102
+ before any command looks at it, so a malformed document fails with its own path
103
+ named rather than deep inside an emitter.
104
+
105
+ `--out` defaults to the input directory for every command that writes, and
106
+ `codegen` names its file after the document (`appointment-line.flowdoc.json`
107
+ generates `appointment-line.flow.ts`), which is the inverse of what `synth`
108
+ writes.
109
+
110
+ ## lint
111
+
112
+ The whole document set goes to `@flow-as-code/core`'s lint in one call. Rules
113
+ receive the other documents alongside their own, and the ones that follow module
114
+ references cannot answer without them: `module-depth-5` on a single file reports
115
+ nothing, correctly, because depth is not computable from one document.
116
+
117
+ `--format json` prints the stable machine-readable report (a `summary` plus
118
+ `findings`) on stdout; the failure line goes to stderr, so the JSON stays clean
119
+ for a pipe. Exit status follows severity, not count: any `error` exits 1,
120
+ warnings alone exit 0.
121
+
122
+ Every document is schema-checked before any rule runs, so a document the schema
123
+ rejects never reaches the report. A literal ARN is the one violation that is
124
+ both a schema failure and a named rule, and the schema states it four ways per
125
+ field without ever saying "literal ARN", so it is reported once per offending
126
+ field as `no-literal-arn: "<field>" contains a literal ARN`. Schema errors the
127
+ ARN did not cause are still listed.
128
+
129
+ ## render
130
+
131
+ Materializes each document with `materializeWithMap` and writes
132
+ `<doc name>.json`. This is the one path where a literal ARN is the goal rather
133
+ than a mistake, so map values are not linted. Completeness is enforced: a token
134
+ with no entry in the map is fatal, and every missing token across every document
135
+ is printed in one run.
136
+
137
+ ## emit
138
+
139
+ `--target tf` is a thin wrapper over `@flow-as-code/tf`, writing exactly
140
+ the bytes the emitter returns and nothing of its own. `--address-map` is passed
141
+ through as `options.addressMap`; without one, unresolved references become the
142
+ emitter's loud `TODO_MISSING_ADDRESS_*` placeholders, which fail
143
+ `terraform validate` rather than deploying a broken flow.
144
+
145
+ `--target cdk` is not a code generator, because `@flow-as-code/cdk` is a
146
+ library: `FlowSet` reads the FlowDoc directory itself at synth time. What the
147
+ command writes is `flow-stack.ts`, a compiling scaffold that constructs a
148
+ `FlowSet` over the directory and declares a `TokenBinder` carrying one `TODO`
149
+ per reference type the documents actually use, with the referenced names listed.
150
+ Reference types the set does not use still get a method, because `TokenBinder`
151
+ requires them, but theirs throws instead of carrying a TODO. Module references
152
+ never appear: `FlowSet` resolves those itself against the modules it manages.
153
+ Re-running the command overwrites the file, so move or rename it once you have
154
+ filled it in.
155
+
156
+ The generator lives in `@flow-as-code/cdk/scaffold`, not here, because the
157
+ studio's CDK export button has to produce the same bytes and cannot import this
158
+ package (`@flow-as-code/cli` depends on `@flow-as-code/studio` for its built
159
+ assets). What stays here is the path arithmetic: turning `--out` and the
160
+ documents' directory into the relative `FLOW_DOCS` expression. The scaffold
161
+ resolves that expression against its own file (`new URL(..., import.meta.url)`),
162
+ so `cdk synth` works from the project root, where `cdk.json` normally lives, and
163
+ not only from the directory the scaffold was written to.
164
+
165
+ ## synth
166
+
167
+ `flow-cli synth <file.flow.ts> [--out <dir>]` evaluates a TypeScript builder
168
+ file and writes one `<flow.name>.flowdoc.json` per flow it exports, into
169
+ `--out` or, by default, next to the source file. A flow is any exported `Flow`
170
+ instance and the result of any exported zero-argument function that returns one.
171
+ Output is byte-stable (`@flow-as-code/core`'s canonical serializer) and carries
172
+ `meta.generator` (`cli@<version>`) and `meta.sourceHash` (`sha256:<hex>` of the
173
+ source file bytes).
174
+
175
+ A builder file does not need `@flow-as-code/core` installed beside it. The child
176
+ resolves that import normally first, so a copy in the file's own `node_modules`
177
+ wins; only when nothing resolves does it fall back to the copy flow-cli itself
178
+ is running against. That is what lets a folder holding nothing but FlowDocs and
179
+ the `.flow.ts` files `codegen` wrote next to them synth at all. The fallback
180
+ covers `@flow-as-code/core` and nothing else, so a builder file cannot reach the
181
+ rest of `@flow-as-code/cli`'s dependencies through it. A `.flow.ts` is also
182
+ treated as ESM when no `package.json` above it says otherwise, which is what
183
+ codegen emits and the only form that can import `@flow-as-code/core`.
184
+
185
+ The builder file never runs in the CLI process. It runs in a child node with
186
+ tsx registered via `--import`, a stripped environment (PATH plus a private
187
+ temp dir for tsx), and cwd pinned to the source directory. Where the runtime
188
+ has the stable `--permission` flag (Node 22.13+), Node's permission model is
189
+ enabled: file writes are denied everywhere except tsx's private temp dir (the
190
+ parent process writes the FlowDocs), and child processes are denied. File
191
+ reads are not jailed, and on Node 22/24 the permission model does not cover
192
+ network access at all; see the header comment in `src/synth.ts` for exactly
193
+ what is and is not enforced, with citations.
194
+
195
+ ## diff
196
+
197
+ `flow-cli diff <dir> --instance <arn>` answers whether what is checked in
198
+ matches what is deployed. Every `*.flowdoc.json` in `<dir>` is validated and
199
+ paired with the live flow or module of the same kind and name, where the live
200
+ name is the slug `export` derives from the console name. The live side goes
201
+ through the same exporter, so it carries tokens rather than ARNs, and the two
202
+ documents are compared as canonical JSON with `layout` and `meta` removed:
203
+ positions and provenance are not differences anyone deploys.
204
+
205
+ One line per local document, in path order, then a unified diff of the
206
+ canonical JSON under each changed one:
207
+
208
+ ```
209
+ flows/appointment-line.flowdoc.json: changed
210
+ --- local/flows/appointment-line.flowdoc.json
211
+ +++ live/appointment-line
212
+ @@ -13,7 +13,7 @@
213
+ ...
214
+ flows/recording-consent.flowdoc.json: unchanged
215
+ flows/callback-offer.flowdoc.json: missing-live
216
+ ```
217
+
218
+ Live flows with no local document are not reported. The same two states
219
+ always print the same bytes, so the output can be compared across runs.
220
+
221
+ A live flow that has never been published has no published content, so the
222
+ exporter reads its saved content through the `$SAVED` alias, the same way
223
+ `export` does. The line says so, `flows/draft-line.flowdoc.json: unchanged
224
+ ($SAVED)`, and a diff under it is labelled `+++ live/draft-line:$SAVED`.
225
+ Unchanged against a draft means the draft matches, not that anything is
226
+ deployed.
227
+
228
+ Exit 0 when nothing differs, 1 when any document is changed or has no live
229
+ counterpart, and 2 when the comparison itself failed: bad arguments (a missing
230
+ `--instance` or an unknown flag included, where every other command exits 1),
231
+ the SDK not installed, the instance unreadable, or a matched live flow the
232
+ exporter could not convert (that document prints as `error:` with the reason,
233
+ and the run still reports the rest).
234
+
235
+ ## export
236
+
237
+ `flow-cli export --instance <arn> [--out <dir>] [--no-codegen] [--on-error abort|collect]`
238
+ reads every flow and module in the instance and writes `<name>.flowdoc.json`
239
+ plus `<name>.flow.ts` for each into `--out`, which defaults to the working
240
+ directory and is created if needed. `--no-codegen` writes the documents only.
241
+ References come out as tokens, never ARNs, and the name is the slug the
242
+ exporter derives from the console name (`Appointment Line` becomes
243
+ `appointment-line`). A flow and a module that slug to the same name would
244
+ share a file name; the second one is reported as a failure rather than
245
+ overwriting the first.
246
+
247
+ Each pair is written the way `synth` and the studio write it: the document
248
+ carries `meta.sourceHash` of the generated source, so the watch engine sees an
249
+ exported pair as in sync, and an existing `<name>.flow.ts` is read first so
250
+ its `@keep` comments survive, as with `codegen`. A flow that has never been
251
+ published is read through the documented `$SAVED` alias and marked as such in
252
+ the summary.
253
+
254
+ stdout carries one line per document written and a closing count; stderr
255
+ carries the exporter's warnings (`warning: ...`, for content it had to skip or
256
+ could not fully represent) and one `failed: <name> (<arn>): <reason>` line per
257
+ flow it could not export.
258
+
259
+ ```
260
+ appointment-line (flow): appointment-line.flowdoc.json, appointment-line.flow.ts
261
+ recording-consent (module): recording-consent.flowdoc.json, recording-consent.flow.ts
262
+ Exported 2 of 3 to /work/flows
263
+ ```
264
+
265
+ `--on-error` defaults to `collect`, which writes everything that exported and
266
+ reports every failure at once. `abort` stops at the first failure and writes
267
+ nothing. The default is collect because a fresh instance always holds the
268
+ stock "Sample Lambda integration" flow, which calls a Lambda in an AWS-owned
269
+ account that the instance's Lambda list cannot return; that is an unknown-ARN
270
+ hard error by design (see the Export section of `packages/core/SPEC.md`),
271
+ and aborting on it would make a first export of any new instance write
272
+ nothing. Either mode exits 1 when any flow failed.
273
+
274
+ `--on-error` governs flows only. The inventory listing that precedes them
275
+ (flows, modules, queues, hours, prompts, Lambda functions, bots) fails in
276
+ either mode with the SDK's own message, an `AccessDeniedException` naming the
277
+ missing action for instance, and nothing is written.
278
+
279
+ ## simulate
280
+
281
+ `flow-cli simulate <scenarios> --instance <arn> [--resource-map <file>] [--format junit|json] [--out <file>]`
282
+ runs a scenario suite through the instance's TestCase operations
283
+ (https://docs.aws.amazon.com/connect/latest/adminguide/testing-simulation-execute-test-cases.html)
284
+ within the documented limits, 5 concurrent, 100 in flight, 5 minutes per
285
+ scenario, and writes a report.
286
+
287
+ `<scenarios>` is one scenario file, or a directory. A directory contributes
288
+ every `scenario.json` and `*.scenario.json` directly in it and one level down,
289
+ which is the layout of `conformance/simulate/` (one `scenario.json` per case
290
+ directory); other files are ignored.
291
+
292
+ Everything that can fail offline fails before the instance is touched, and
293
+ all at once. Every scenario is validated against `scenario-0.1.schema.json`,
294
+ the byte copy of `conformance/schema/scenario-0.1.schema.json` this package
295
+ ships, then against the cross-field rules the schema cannot express, and every
296
+ `${cdref:...}` token in the suite is resolved through `--resource-map`, a JSON
297
+ object from token to ARN in the same shape `render` takes. A suite with one
298
+ broken scenario or one unmapped token creates no test case.
299
+
300
+ The report goes to stdout, or to `--out`, in which case the path is printed
301
+ instead. `--format junit` (the default) is the `<testsuites>` document CI
302
+ systems ingest; `--format json` is the stable `flow-simulate-report/0.1`
303
+ document. Scenarios that did not pass are also described on stderr, one block
304
+ per scenario with the failed observations, so a CI log says why without
305
+ opening the report.
306
+
307
+ Exit 0 only when every scenario `PASSED`. `FAILED`, `TIMED_OUT` (the harness
308
+ stops the execution when the 5 minutes are up), `STOPPED`, and `ERRORED` (an
309
+ API error for that scenario) each exit 1, and the summary line says how many
310
+ of the suite did not pass.
311
+
312
+ ## watch (library)
313
+
314
+ `@flow-as-code/cli/watch` exports `createWatcher(dir)`, the engine
315
+ behind studio sync (A11). It watches one directory (non-recursive) and pairs
316
+ `<name>.flow.ts` with `<name>.flowdoc.json` by base name. On a ts change it
317
+ re-synths in the same sandboxed child and rewrites the doc, guarded by
318
+ `meta.sourceHash` (docs/01-flowdoc-spec.md, invariant 3): if the doc on disk
319
+ was edited externally since the watcher last wrote or observed it, and that
320
+ edit does not carry the previous ts content's hash, the pair is dirty on both
321
+ sides. The watcher then emits `conflict` and writes nothing. A pair that is
322
+ already diverged when the watcher starts also gets a `conflict` rather than
323
+ an overwrite.
324
+
325
+ The re-synth uses the same resolution rules `synth` documents above, so a
326
+ watched directory needs no `node_modules` of its own for the builder files in
327
+ it to resolve `@flow-as-code/core`.
328
+
329
+ Events: `synced {tsPath, docPath, name}`, `conflict {tsPath, docPath, name,
330
+ reason}`, `error {path, message}`, plus a `ready` convenience event after the
331
+ initial scan settles. A ts file whose flow names do not include the file's
332
+ base name syncs only when it exports exactly one flow; otherwise the watcher
333
+ emits `error` for that pair.
334
+
335
+ A change that leaves the builder file byte-identical to the last synced content
336
+ is normally silent (it is how the watcher recognizes its own writes), with one
337
+ exception: when the preceding change ended in `error`, the same no-op emits
338
+ `synced`. Undoing a broken edit is the ordinary way to fix one, and consumers
339
+ latch the error, so without that event the studio's out-of-sync badge outlived
340
+ the state it reported and cleared only on some later, unrelated edit.
341
+
342
+ `noteWrite(name, {tsContent, docContent})` records a pair another part of the
343
+ same process just wrote as the clean baseline, so the studio bridge's own
344
+ writes are not read back as external edits. Pass the exact bytes written, and
345
+ call it after both files are on disk.
346
+
347
+ ## studio
348
+
349
+ `flow-cli studio [dir] [--port <port>]` serves the visual editor over a
350
+ directory of FlowDocs and builder files, with live sync in both directions. It
351
+ prints the URL to open; `dir` defaults to the working directory and the port
352
+ defaults to a free one.
353
+
354
+ A document with no `<name>.flow.ts` beside it gets one written before the
355
+ server starts, and the command prints a line per file:
356
+
357
+ ```
358
+ wrote appointment-line.flow.ts from appointment-line.flowdoc.json
359
+ ```
360
+
361
+ That is the same `codegen` the canvas runs on save, so the bytes are the ones
362
+ the first save would have written, and the document is stamped with the
363
+ `meta.sourceHash` of the source just generated. Without it a directory holding
364
+ only documents (exported from an instance, copied out of `conformance/`, sent
365
+ by a colleague) had no builder file to edit, so the loop this command exists
366
+ for could not start there. An existing builder file is never overwritten. A
367
+ document `codegen` refuses is named and skipped, and the rest of the directory
368
+ still opens:
369
+
370
+ ```
371
+ skipped broken.flowdoc.json: broken.flowdoc.json is not a valid FlowDoc: ...
372
+ ```
373
+
374
+ A builder file the watcher cannot synth is reported on the same stream:
375
+
376
+ ```
377
+ error appointment-line.flow.ts: Evaluating /w/appointment-line.flow.ts threw: Transform failed with 1 error:
378
+ /w/appointment-line.flow.ts:101:16: ERROR: Unexpected ";"
379
+ ```
380
+
381
+ Stack frames inside `node_modules` and node's own internals are dropped from
382
+ that message. A transform failure carries ten frames of esbuild and stream
383
+ internals under a line that already names the file, line and column, and the
384
+ studio's badge shows only the first line for the same reason. Frames in files
385
+ you wrote survive, because a runtime throw inside a flow needs them. There is
386
+ no switch that restores the dropped frames. `node_modules` has to be a whole
387
+ path segment of the frame's own location for the frame to count as vendor code,
388
+ so a project under a directory called `node_modules-sandbox`, or a function
389
+ named `loadNodeModules`, keeps its frames.
390
+
391
+ A pair assembled by hand is a different case and still reports a conflict: the
392
+ document has to carry the `meta.sourceHash` of the source next to it, or the
393
+ watcher has no evidence the two ever agreed. `flow-cli synth <name>.flow.ts`
394
+ writes that stamp; removing the stale side works too.
395
+
396
+ The server binds `127.0.0.1` and only `127.0.0.1`. This process writes files
397
+ you own, so a bridge reachable from the network would be a remote file writer;
398
+ the bind address is not configurable for that reason. Binding loopback is not
399
+ by itself protection against DNS rebinding (a page on the internet can resolve
400
+ its own hostname to 127.0.0.1), so the `Host` header is checked as well and a
401
+ request addressed to anything else is refused. No CORS headers are sent, and
402
+ the server makes no outbound connections.
403
+
404
+ What it serves: the built studio assets from the installed
405
+ `@flow-as-code/studio` package, and a small JSON API under `/bridge`.
406
+ If the studio package is present but has not been built, the command says so
407
+ and names the build command.
408
+
409
+ The API is these six routes and nothing else; anything else under `/bridge`
410
+ answers 404 with the method and path it was given
411
+ (`src/bridge/server.ts`):
412
+
413
+ | Route | Method | What it does |
414
+ | ----------------------------- | ------ | ---------------------------------------------------- |
415
+ | `/bridge/info` | GET | Served directory, version, and the session token |
416
+ | `/bridge/docs` | GET | Names of the documents in the served directory |
417
+ | `/bridge/docs/<name>` | GET | One pair: the FlowDoc and its `<name>.flow.ts` |
418
+ | `/bridge/docs/<name>` | PUT | Save that pair; 409 when the pair diverged |
419
+ | `/bridge/docs/<name>/resolve` | POST | Settle a refused save by choosing a side |
420
+ | `/bridge/export` | POST | Write an emitted file map under the served directory |
421
+ | `/bridge/events?cursor=<n>` | GET | Long-polled watch events from `<n>` on |
422
+
423
+ Every request to `/bridge` and to the document itself carries the session
424
+ token, either as the `token` query parameter (which is how the printed URL
425
+ opens the page) or as the `x-flow-studio-token` header (which is how the page's
426
+ own calls send it). Subresources are served without one so the token never
427
+ appears in an asset URL. `src/bridge/forgery.test.ts` holds this contract,
428
+ along with the `Sec-Fetch-Site` and `Origin` checks described above.
429
+
430
+ `POST /bridge/export` is how the studio's export buttons reach disk: the studio
431
+ emits the file map (the same emitters this CLI's `emit` and `render` use) and
432
+ this process writes it under the served directory. Paths are checked against
433
+ the protocol's path rule and then again by resolving them and requiring the
434
+ result to be inside that directory. Nothing is paired and no event is
435
+ published: emitted terraform and CDK files are output, not documents.
436
+
437
+ Saving from the canvas writes both halves of the pair: the FlowDoc, and
438
+ `<name>.flow.ts` regenerated with `codegen`, passing the existing file so
439
+ `@keep` comments survive. The document is stamped with `meta.sourceHash` of
440
+ the source just written, which is what keeps the watcher from reading the
441
+ save as a divergence.
442
+
443
+ Conflicts are never merged. A save whose builder file has changed since the
444
+ document was generated from it is refused with 409 and both sides are offered
445
+ in the studio's dialog; so is a pair the watcher finds diverged on disk. Every
446
+ write stays refused until the choice is made.