@loomwork/scaffold 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +54 -2
- package/dist/codegen.d.ts +23 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +62 -0
- package/dist/codegen.js.map +1 -0
- package/dist/emit.d.ts +18 -0
- package/dist/emit.d.ts.map +1 -0
- package/dist/emit.js +74 -0
- package/dist/emit.js.map +1 -0
- package/dist/flowTemplates.d.ts +23 -0
- package/dist/flowTemplates.d.ts.map +1 -0
- package/dist/flowTemplates.js +348 -0
- package/dist/flowTemplates.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/names.d.ts +16 -0
- package/dist/names.d.ts.map +1 -0
- package/dist/names.js +45 -0
- package/dist/names.js.map +1 -0
- package/dist/plugin.d.ts +45 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +1819 -0
- package/dist/plugin.js.map +1 -0
- package/dist/templates.d.ts +42 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +536 -0
- package/dist/templates.js.map +1 -0
- package/package.json +48 -3
- package/src/codegen.ts +69 -0
- package/src/emit.ts +72 -0
- package/src/flowTemplates.ts +353 -0
- package/src/index.ts +30 -0
- package/src/names.ts +43 -0
- package/src/plugin.ts +1920 -0
- package/src/templates.ts +566 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @loomwork/scaffold — the templates and generators behind `loom new`, `loom gen` and `create-loom-app`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Pure functions that return file contents as strings: single constructs (a flow, tool, agent, skill,
|
|
4
|
+
schedule, memory, projection or sentinel), a whole app skeleton, a plugin package for a chosen seam, and
|
|
5
|
+
the static registration module `loom.gen.ts`. They write nothing to disk; the CLI and `create-loom-app`
|
|
6
|
+
do that. This is tooling that other tools build on, so most apps never import it. Use it when you build
|
|
7
|
+
your own generator and want the same output and escaping rules.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { generateRegistration, newFiles } from "@loomwork/scaffold";
|
|
11
|
+
|
|
12
|
+
// What `loom new flow greet --template approval` would write, as { path, content } pairs:
|
|
13
|
+
const files = newFiles("flow", "greet", "approval");
|
|
14
|
+
// -> app/flows/greet/flow.ts and app/flows/greet/flow.test.ts
|
|
15
|
+
|
|
16
|
+
// What `loom gen` writes: static imports of every discovered module, for defineConfig.
|
|
17
|
+
const registration = generateRegistration(["./flows/greet/flow"], ["./agents/triage"]);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Surface
|
|
21
|
+
|
|
22
|
+
- **Constructs.** `newFile(kind, name, template?)` and `newFiles(...)` route to the individual
|
|
23
|
+
generators (`flowFile`, `toolFile`, `agentFile`, `sentinelFile`, `flowTestFile`). A flow `template` is
|
|
24
|
+
one of `FLOW_TEMPLATES`: `echo`, `approval`, `timer` or `saga`.
|
|
25
|
+
- **Whole app.** `appFiles(appName)` returns the file map `create-loom-app` writes.
|
|
26
|
+
- **Registration.** `generateRegistration(flowPaths, agentPaths?, toolPaths?, skillPaths?,
|
|
27
|
+
schedulePaths?, memoryPaths?, projectionPaths?)` returns the text of `loom.gen.ts`.
|
|
28
|
+
- **Plugins.** `pluginFiles(seamKey, name, { firstParty })`, `pluginNextSteps`, `listSeams` and
|
|
29
|
+
`SEAM_KEYS` back `loom plugin new`.
|
|
30
|
+
- **Names and escaping.** `pascal`, `pascalIdent`, `kebab`, `constructNameProblem`, `isValidPackageName`,
|
|
31
|
+
and the emit helpers `tsStringLiteral`, `commentText`, `blockCommentText`, `templateLiteralText`,
|
|
32
|
+
`markdownText` and `hasUnsafeChars`.
|
|
33
|
+
|
|
34
|
+
## Behaviour that surprises people
|
|
35
|
+
|
|
36
|
+
- **The registration is static on purpose.** `loom.gen.ts` imports modules at build time, so the set of
|
|
37
|
+
flows is the same on every resume and on every remote worker, rather than found at run time.
|
|
38
|
+
- **Names are validated before they reach generated code.** `pascalIdent` throws for a name that does not
|
|
39
|
+
derive a plain ASCII identifier, `constructNameProblem` rejects paths and `..`, and `pluginFiles`
|
|
40
|
+
rejects a name with a slash, dot or leading hyphen.
|
|
41
|
+
- **Generated text is escaped at the sink.** Intent text can come from a model, so the emit helpers
|
|
42
|
+
exist to be the only way such text enters generated source. They escape or replace control, bidi and
|
|
43
|
+
zero-width characters, and `hasUnsafeChars` lets a caller refuse them instead.
|
|
44
|
+
|
|
45
|
+
## Status / See also
|
|
46
|
+
|
|
47
|
+
Unpublished for now: inside this repo use `workspace:*`; from a sibling checkout use a `link:` override
|
|
48
|
+
(see [AGENTS.md](../../AGENTS.md)).
|
|
49
|
+
|
|
50
|
+
- [ADR 0011](../../docs/adr/0011-folder-convention-codegen.md): the folder convention these follow;
|
|
51
|
+
[docs/plugins.md](../../docs/plugins.md): plugin authoring.
|
|
52
|
+
- CLI: `loom new`, `loom gen`, `loom plugin new` ([docs/usage-cli.md](../../docs/usage-cli.md)).
|
|
53
|
+
- API reference: section "`@loomwork/scaffold` — codegen & templates" in
|
|
54
|
+
[docs/api-reference.org](../../docs/api-reference.org).
|
|
55
|
+
- Guides: [docs/user-guide.md](../../docs/user-guide.md), [docs/README.md](../../docs/README.md).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** kebab/snake/space → PascalCase, for deriving export names. */
|
|
2
|
+
export declare function pascal(name: string): string;
|
|
3
|
+
/** kebab/snake/space → camelCase, for deriving a valid function identifier. */
|
|
4
|
+
export declare function camel(name: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* {@link pascal}, asserted to be a plain ASCII identifier. The template functions put it into
|
|
7
|
+
* generated source as an export name, so a name whose derivation is not an identifier
|
|
8
|
+
* (`a"; x(); //`, a leading digit) throws instead of producing code.
|
|
9
|
+
*/
|
|
10
|
+
export declare function pascalIdent(name: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Generate the text of `loom.gen.ts` — a static module that imports the discovered
|
|
13
|
+
* flow / agent / tool / skill / schedule / memory modules and re-exports them as
|
|
14
|
+
* `flowModules` / `agentModules` / `toolModules` / `skillModules` / `scheduleModules`
|
|
15
|
+
* / `memoryModules`, for `defineConfig({ ...all six })`.
|
|
16
|
+
*
|
|
17
|
+
* This is the replay-safe form of "auto-wire from the filesystem": the imports are
|
|
18
|
+
* STATIC (fixed at build time by `loom gen`), so the set is identical on every
|
|
19
|
+
* resume / remote worker. Each `*Paths` is module specifiers relative to the
|
|
20
|
+
* generated file (extension-less), e.g. `./flows/greet/flow`, `./agents/triage`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function generateRegistration(flowPaths: string[], agentPaths?: string[], toolPaths?: string[], skillPaths?: string[], schedulePaths?: string[], memoryPaths?: string[], projectionPaths?: string[]): string;
|
|
23
|
+
//# sourceMappingURL=codegen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAEA,iEAAiE;AACjE,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM3C;AAED,+EAA+E;AAC/E,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG1C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQhD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EAAE,EACnB,UAAU,GAAE,MAAM,EAAO,EACzB,SAAS,GAAE,MAAM,EAAO,EACxB,UAAU,GAAE,MAAM,EAAO,EACzB,aAAa,GAAE,MAAM,EAAO,EAC5B,WAAW,GAAE,MAAM,EAAO,EAC1B,eAAe,GAAE,MAAM,EAAO,GAC7B,MAAM,CAiBR"}
|
package/dist/codegen.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pascal = pascal;
|
|
4
|
+
exports.camel = camel;
|
|
5
|
+
exports.pascalIdent = pascalIdent;
|
|
6
|
+
exports.generateRegistration = generateRegistration;
|
|
7
|
+
const emit_1 = require("./emit");
|
|
8
|
+
/** kebab/snake/space → PascalCase, for deriving export names. */
|
|
9
|
+
function pascal(name) {
|
|
10
|
+
return name
|
|
11
|
+
.split(/[-_\s]+/)
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
14
|
+
.join("");
|
|
15
|
+
}
|
|
16
|
+
/** kebab/snake/space → camelCase, for deriving a valid function identifier. */
|
|
17
|
+
function camel(name) {
|
|
18
|
+
const p = pascal(name);
|
|
19
|
+
return p.charAt(0).toLowerCase() + p.slice(1);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* {@link pascal}, asserted to be a plain ASCII identifier. The template functions put it into
|
|
23
|
+
* generated source as an export name, so a name whose derivation is not an identifier
|
|
24
|
+
* (`a"; x(); //`, a leading digit) throws instead of producing code.
|
|
25
|
+
*/
|
|
26
|
+
function pascalIdent(name) {
|
|
27
|
+
const p = pascal(name);
|
|
28
|
+
if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(p)) {
|
|
29
|
+
throw new Error(`scaffold: ${JSON.stringify(name)} does not derive a valid identifier (got ${JSON.stringify(p)}); use lowercase kebab-case starting with a letter`);
|
|
30
|
+
}
|
|
31
|
+
return p;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Generate the text of `loom.gen.ts` — a static module that imports the discovered
|
|
35
|
+
* flow / agent / tool / skill / schedule / memory modules and re-exports them as
|
|
36
|
+
* `flowModules` / `agentModules` / `toolModules` / `skillModules` / `scheduleModules`
|
|
37
|
+
* / `memoryModules`, for `defineConfig({ ...all six })`.
|
|
38
|
+
*
|
|
39
|
+
* This is the replay-safe form of "auto-wire from the filesystem": the imports are
|
|
40
|
+
* STATIC (fixed at build time by `loom gen`), so the set is identical on every
|
|
41
|
+
* resume / remote worker. Each `*Paths` is module specifiers relative to the
|
|
42
|
+
* generated file (extension-less), e.g. `./flows/greet/flow`, `./agents/triage`.
|
|
43
|
+
*/
|
|
44
|
+
function generateRegistration(flowPaths, agentPaths = [], toolPaths = [], skillPaths = [], schedulePaths = [], memoryPaths = [], projectionPaths = []) {
|
|
45
|
+
const group = (paths, prefix, exportName) => {
|
|
46
|
+
const imports = paths.map((p, i) => `import * as ${prefix}${i} from ${(0, emit_1.tsStringLiteral)(p)};`);
|
|
47
|
+
const refs = paths.map((_, i) => `${prefix}${i}`).join(", ");
|
|
48
|
+
return [...imports, "", `export const ${exportName} = [${refs}];`, ""];
|
|
49
|
+
};
|
|
50
|
+
return [
|
|
51
|
+
"// AUTO-GENERATED by `loom gen`. Do not edit by hand.",
|
|
52
|
+
"// Static modules for defineConfig — flows/agents/tools/skills/schedules/memories/projections.",
|
|
53
|
+
...group(flowPaths, "_f", "flowModules"),
|
|
54
|
+
...group(agentPaths, "_a", "agentModules"),
|
|
55
|
+
...group(toolPaths, "_t", "toolModules"),
|
|
56
|
+
...group(skillPaths, "_s", "skillModules"),
|
|
57
|
+
...group(schedulePaths, "_sc", "scheduleModules"),
|
|
58
|
+
...group(memoryPaths, "_m", "memoryModules"),
|
|
59
|
+
...group(projectionPaths, "_p", "projectionModules"),
|
|
60
|
+
].join("\n");
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=codegen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":";;AAGA,wBAMC;AAGD,sBAGC;AAOD,kCAQC;AAaD,oDAyBC;AApED,iCAAyC;AAEzC,iEAAiE;AACjE,SAAgB,MAAM,CAAC,IAAY;IACjC,OAAO,IAAI;SACR,KAAK,CAAC,SAAS,CAAC;SAChB,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAClD,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,+EAA+E;AAC/E,SAAgB,KAAK,CAAC,IAAY;IAChC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACH,SAAgB,WAAW,CAAC,IAAY;IACtC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CACb,aAAa,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4CAA4C,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,oDAAoD,CACnJ,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,oBAAo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18 @@
|
|
|
1
|
+
/** Does `s` contain any character that must never reach generated source or a plan field? */
|
|
2
|
+
export declare function hasUnsafeChars(s: string): boolean;
|
|
3
|
+
/** Text for a single-line `// ...` comment: every unsafe character becomes a space. */
|
|
4
|
+
export declare function commentText(s: string): string;
|
|
5
|
+
/** Text for a block comment: single-line as above, and a comment delimiter can never appear. */
|
|
6
|
+
export declare function blockCommentText(s: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* A complete, quoted TypeScript string literal. `JSON.stringify` escapes quotes,
|
|
9
|
+
* backslashes, C0 controls and lone surrogates; every other unsafe character (U+2028/2029,
|
|
10
|
+
* bidi, zero-width, tag characters, ...) is escaped explicitly - astral ones as a surrogate
|
|
11
|
+
* pair - so the literal is inert and reads the same in every editor.
|
|
12
|
+
*/
|
|
13
|
+
export declare function tsStringLiteral(s: string): string;
|
|
14
|
+
/** The CONTENT (no surrounding backticks) of a template literal: `\`, backtick and `${` escaped. */
|
|
15
|
+
export declare function templateLiteralText(s: string): string;
|
|
16
|
+
/** One line of markdown prose: no line breaks, and markup/HTML metacharacters neutralised. */
|
|
17
|
+
export declare function markdownText(s: string): string;
|
|
18
|
+
//# sourceMappingURL=emit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../src/emit.ts"],"names":[],"mappings":"AAsBA,6FAA6F;AAC7F,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEjD;AAWD,uFAAuF;AACvF,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,gGAAgG;AAChG,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,oGAAoG;AACpG,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAMrD;AAED,8FAA8F;AAC9F,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAK9C"}
|
package/dist/emit.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ── Escaping for every place a generator interpolates a spec- or model-derived string ──
|
|
3
|
+
//
|
|
4
|
+
// The ChangeSpec is produced by a MODEL (appgen-model) or by free-form user text
|
|
5
|
+
// (parseIntent), so every string in it is untrusted. Generated TypeScript lives in the
|
|
6
|
+
// user's project, which makes any unescaped interpolation a code-injection channel
|
|
7
|
+
// (a newline ends a `//` comment, `*/` ends a block comment, `"` ends a string literal,
|
|
8
|
+
// `${` opens a template substitution). These helpers are the ONLY sanctioned way to put
|
|
9
|
+
// such text into generated source; defence is at the sink, whatever the validators did.
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.hasUnsafeChars = hasUnsafeChars;
|
|
12
|
+
exports.commentText = commentText;
|
|
13
|
+
exports.blockCommentText = blockCommentText;
|
|
14
|
+
exports.tsStringLiteral = tsStringLiteral;
|
|
15
|
+
exports.templateLiteralText = templateLiteralText;
|
|
16
|
+
exports.markdownText = markdownText;
|
|
17
|
+
/**
|
|
18
|
+
* Every character that must never reach generated source or a plan field raw: C0/DEL/C1
|
|
19
|
+
* controls (Cc), ALL format characters (Cf: soft hyphen, zero-width and bidi marks and
|
|
20
|
+
* overrides and isolates, BOM, interlinear annotation FFF9-FFFB, the Unicode "tag"
|
|
21
|
+
* characters U+E0000-E007F used for ASCII smuggling, musical-notation formatting
|
|
22
|
+
* U+1D173-1D17A), line and paragraph separators (Zl, Zp), lone surrogates (Cs), the
|
|
23
|
+
* combining grapheme joiner U+034F (a Mn that renders as nothing) and the unassigned
|
|
24
|
+
* U+2065 inside the bidi block. The `u` flag is what makes the astral ranges match.
|
|
25
|
+
*/
|
|
26
|
+
const UNSAFE_SOURCE = "[\\p{Cc}\\p{Cf}\\p{Zl}\\p{Zp}\\p{Cs}\\u034f\\u2065]";
|
|
27
|
+
const UNSAFE_CHARS = new RegExp(UNSAFE_SOURCE, "gu");
|
|
28
|
+
const UNSAFE_ONE = new RegExp(UNSAFE_SOURCE, "u");
|
|
29
|
+
/** Does `s` contain any character that must never reach generated source or a plan field? */
|
|
30
|
+
function hasUnsafeChars(s) {
|
|
31
|
+
return UNSAFE_ONE.test(s);
|
|
32
|
+
}
|
|
33
|
+
/** `\uXXXX` for a BMP code point, a `\uD8xx\uDCxx` surrogate pair for an astral one. */
|
|
34
|
+
function unicodeEscape(c) {
|
|
35
|
+
const cp = c.codePointAt(0) ?? 0;
|
|
36
|
+
const u = (n) => `\\u${n.toString(16).padStart(4, "0")}`;
|
|
37
|
+
if (cp <= 0xffff)
|
|
38
|
+
return u(cp);
|
|
39
|
+
const v = cp - 0x10000;
|
|
40
|
+
return u(0xd800 + (v >> 10)) + u(0xdc00 + (v & 0x3ff));
|
|
41
|
+
}
|
|
42
|
+
/** Text for a single-line `// ...` comment: every unsafe character becomes a space. */
|
|
43
|
+
function commentText(s) {
|
|
44
|
+
return s.replace(UNSAFE_CHARS, " ");
|
|
45
|
+
}
|
|
46
|
+
/** Text for a block comment: single-line as above, and a comment delimiter can never appear. */
|
|
47
|
+
function blockCommentText(s) {
|
|
48
|
+
return commentText(s).replace(/\*\//g, "* /").replace(/\/\*/g, "/ *");
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A complete, quoted TypeScript string literal. `JSON.stringify` escapes quotes,
|
|
52
|
+
* backslashes, C0 controls and lone surrogates; every other unsafe character (U+2028/2029,
|
|
53
|
+
* bidi, zero-width, tag characters, ...) is escaped explicitly - astral ones as a surrogate
|
|
54
|
+
* pair - so the literal is inert and reads the same in every editor.
|
|
55
|
+
*/
|
|
56
|
+
function tsStringLiteral(s) {
|
|
57
|
+
return JSON.stringify(s).replace(UNSAFE_CHARS, unicodeEscape);
|
|
58
|
+
}
|
|
59
|
+
/** The CONTENT (no surrounding backticks) of a template literal: `\`, backtick and `${` escaped. */
|
|
60
|
+
function templateLiteralText(s) {
|
|
61
|
+
return tsStringLiteral(s)
|
|
62
|
+
.slice(1, -1)
|
|
63
|
+
.replace(/\\"/g, '"')
|
|
64
|
+
.replace(/`/g, "\\`")
|
|
65
|
+
.replace(/\$\{/g, "\\${");
|
|
66
|
+
}
|
|
67
|
+
/** One line of markdown prose: no line breaks, and markup/HTML metacharacters neutralised. */
|
|
68
|
+
function markdownText(s) {
|
|
69
|
+
return commentText(s)
|
|
70
|
+
.replace(/\s+/g, " ")
|
|
71
|
+
.trim()
|
|
72
|
+
.replace(/[\\`*_{}[\]<>#|!&~]/g, (c) => `\\${c}`);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=emit.js.map
|
package/dist/emit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../src/emit.ts"],"names":[],"mappings":";AAAA,0FAA0F;AAC1F,EAAE;AACF,iFAAiF;AACjF,uFAAuF;AACvF,mFAAmF;AACnF,wFAAwF;AACxF,wFAAwF;AACxF,wFAAwF;;AAgBxF,wCAEC;AAYD,kCAEC;AAGD,4CAEC;AAQD,0CAEC;AAGD,kDAMC;AAGD,oCAKC;AA9DD;;;;;;;;GAQG;AACH,MAAM,aAAa,GAAG,qDAAqD,CAAC;AAC5E,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AACrD,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;AAElD,6FAA6F;AAC7F,SAAgB,cAAc,CAAC,CAAS;IACtC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED,wFAAwF;AACxF,SAAS,aAAa,CAAC,CAAS;IAC9B,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACj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AAC,CAAC,CAAC;SAClB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE;SACN,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const FLOW_TEMPLATES: readonly ["echo", "approval", "timer", "saga"];
|
|
2
|
+
export type FlowTemplate = (typeof FLOW_TEMPLATES)[number];
|
|
3
|
+
export declare function isFlowTemplate(value: string): value is FlowTemplate;
|
|
4
|
+
/** Suspend on a typed resume gate (`resumeSchemas`), with a 24h expiry. */
|
|
5
|
+
export declare function approvalFlowFile(name: string): string;
|
|
6
|
+
export declare function approvalTestFile(name: string): string;
|
|
7
|
+
/** A durable `ctx.sleep` between two steps. */
|
|
8
|
+
export declare function timerFlowFile(name: string): string;
|
|
9
|
+
export declare function timerTestFile(name: string): string;
|
|
10
|
+
/** reserve -> charge -> ship with a compensator per forward step (`@loomwork/saga` `withSaga`). */
|
|
11
|
+
export declare function sagaFlowFile(name: string): string;
|
|
12
|
+
export declare function sagaTestFile(name: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* What a developer must still do by hand after `loom new flow <name> --template <t>` - printed by
|
|
15
|
+
* the CLI, because the templates cannot edit the app's own config.
|
|
16
|
+
*/
|
|
17
|
+
export declare function templateNotes(template: FlowTemplate, name: string): string[];
|
|
18
|
+
/** The flow + test contents for a non-echo template. */
|
|
19
|
+
export declare function templateFiles(template: Exclude<FlowTemplate, "echo">, name: string): {
|
|
20
|
+
flow: string;
|
|
21
|
+
test: string;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=flowTemplates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flowTemplates.d.ts","sourceRoot":"","sources":["../src/flowTemplates.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,cAAc,gDAAiD,CAAC;AAC7E,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3D,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,YAAY,CAEnE;AAID,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAwDrD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAwCrD;AAID,+CAA+C;AAC/C,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAuClD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgClD;AAID,mGAAmG;AACnG,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA2DjD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAoDjD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAkB5E;AAED,wDAAwD;AACxD,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,EACvC,IAAI,EAAE,MAAM,GACX;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAShC"}
|