@kitman-sh/cli 0.14.9 → 0.15.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/dist/{chunk-cwdrhsvk.js → chunk-0ws25xvg.js} +2 -2
- package/dist/{chunk-mgjer6c7.js → chunk-39ykbhq8.js} +3 -3
- package/dist/{chunk-y9x0yv20.js → chunk-3n99j4z0.js} +456 -219
- package/dist/{chunk-vt8aqeby.js → chunk-3ns4sbfb.js} +1 -1
- package/dist/{chunk-h7qv6nzc.js → chunk-4x7a1qkj.js} +7 -7
- package/dist/{chunk-vjt0d9zj.js → chunk-4zc1g45m.js} +7 -7
- package/dist/{chunk-0x5r7h2g.js → chunk-58hehm8d.js} +1123 -105
- package/dist/{chunk-c80dvhxf.js → chunk-5hkdgzh4.js} +1 -6
- package/dist/{chunk-dd7wknyk.js → chunk-8393zths.js} +1500 -113
- package/dist/{chunk-qb9jft1r.js → chunk-8wpg3rph.js} +2 -2
- package/dist/{chunk-enmtmq63.js → chunk-b16qxawc.js} +1 -1
- package/dist/chunk-cf1hxp43.js +3080 -0
- package/dist/chunk-csxxwscf.js +39 -0
- package/dist/{chunk-ftre6ndb.js → chunk-djp6t2g6.js} +6 -6
- package/dist/{chunk-wttgq85b.js → chunk-dx792s4w.js} +1396 -41
- package/dist/{chunk-b2yy07ag.js → chunk-fv2zpgh0.js} +7 -7
- package/dist/{chunk-93xj74qp.js → chunk-fzaecdgv.js} +3 -3
- package/dist/{chunk-2r4jy82z.js → chunk-k2wd9r6t.js} +4 -4
- package/dist/chunk-mrkrt2hg.js +4345 -0
- package/dist/{chunk-6qygqj10.js → chunk-qkt77rtj.js} +6 -6
- package/dist/{chunk-cpss81fx.js → chunk-rt0qfdtg.js} +13 -5
- package/dist/{chunk-czmbgsqr.js → chunk-snwjv2sd.js} +656 -39
- package/dist/{chunk-bmwf2ea5.js → chunk-vg78dz3w.js} +85 -26
- package/dist/{chunk-jsb61dsk.js → chunk-vq7caqt2.js} +1814 -116
- package/dist/{chunk-axr8avvs.js → chunk-wfz64h9p.js} +4 -4
- package/dist/{chunk-e3c15bgw.js → chunk-xx711t5r.js} +4 -4
- package/dist/index.js +4 -4
- package/package.json +2 -1
- package/dist/chunk-3hdjd2c3.js +0 -1192
- package/dist/chunk-qvyqfm54.js +0 -526
|
@@ -0,0 +1,4345 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
isString,
|
|
4
|
+
isObject,
|
|
5
|
+
hasProperty,
|
|
6
|
+
isTagged,
|
|
7
|
+
Reference,
|
|
8
|
+
all3,
|
|
9
|
+
forEach,
|
|
10
|
+
succeed6,
|
|
11
|
+
gen,
|
|
12
|
+
fail7,
|
|
13
|
+
flatMap3,
|
|
14
|
+
map9,
|
|
15
|
+
catchTags,
|
|
16
|
+
mapError2,
|
|
17
|
+
orDie,
|
|
18
|
+
ignore,
|
|
19
|
+
orElseSucceed,
|
|
20
|
+
filter3,
|
|
21
|
+
provide3,
|
|
22
|
+
scoped,
|
|
23
|
+
acquireRelease,
|
|
24
|
+
encode2,
|
|
25
|
+
decodeUnknownEffect2,
|
|
26
|
+
decodeEffect,
|
|
27
|
+
optionalKey,
|
|
28
|
+
Null,
|
|
29
|
+
String4,
|
|
30
|
+
Struct,
|
|
31
|
+
Record,
|
|
32
|
+
Union,
|
|
33
|
+
fromJsonString,
|
|
34
|
+
TaggedError2,
|
|
35
|
+
toCodecJson,
|
|
36
|
+
Json,
|
|
37
|
+
encodePrettyJsonString
|
|
38
|
+
} from "./chunk-dx792s4w.js";
|
|
39
|
+
import {
|
|
40
|
+
SecureRandom,
|
|
41
|
+
layerWebCrypto,
|
|
42
|
+
canonicalJson,
|
|
43
|
+
endsFailing,
|
|
44
|
+
anyFailure,
|
|
45
|
+
goesOn,
|
|
46
|
+
digestSha256,
|
|
47
|
+
schemaBodyJson,
|
|
48
|
+
filterStatusOk,
|
|
49
|
+
get2,
|
|
50
|
+
layer4,
|
|
51
|
+
AgentDeclaration,
|
|
52
|
+
KitDeclarations,
|
|
53
|
+
kitmanMcpServer,
|
|
54
|
+
RunnerRpcProtocolVersion
|
|
55
|
+
} from "./chunk-8393zths.js";
|
|
56
|
+
import {
|
|
57
|
+
decodeText,
|
|
58
|
+
mkString,
|
|
59
|
+
FileSystem,
|
|
60
|
+
Path,
|
|
61
|
+
withDefault,
|
|
62
|
+
String2
|
|
63
|
+
} from "./chunk-vg78dz3w.js";
|
|
64
|
+
import {
|
|
65
|
+
Packument,
|
|
66
|
+
tarballMatches
|
|
67
|
+
} from "./chunk-4x7a1qkj.js";
|
|
68
|
+
import"./chunk-5hkdgzh4.js";
|
|
69
|
+
import {
|
|
70
|
+
stepDefinedTwice,
|
|
71
|
+
hostSteps,
|
|
72
|
+
exports_activities,
|
|
73
|
+
describeFlag,
|
|
74
|
+
Described
|
|
75
|
+
} from "./chunk-cf1hxp43.js";
|
|
76
|
+
import"./chunk-rt0qfdtg.js";
|
|
77
|
+
import"./chunk-csxxwscf.js";
|
|
78
|
+
import {
|
|
79
|
+
ChildProcessSpawner,
|
|
80
|
+
make3
|
|
81
|
+
} from "./chunk-k2wd9r6t.js";
|
|
82
|
+
import"./chunk-djp6t2g6.js";
|
|
83
|
+
|
|
84
|
+
// packages/sdk/src/build/outline/graph.ts
|
|
85
|
+
import {
|
|
86
|
+
parseSync,
|
|
87
|
+
visitorKeys
|
|
88
|
+
} from "oxc-parser";
|
|
89
|
+
|
|
90
|
+
// packages/sdk/src/build/outline/lent.ts
|
|
91
|
+
var named = { name: 0 };
|
|
92
|
+
var hostStepFunctions = hostSteps.map((step) => step.id).filter((id) => (id in exports_activities));
|
|
93
|
+
var lentSteps = new Map(Object.entries({
|
|
94
|
+
agentWorkAs: { name: 1, agent: 2 },
|
|
95
|
+
syncBase: { name: 0, agent: 1 },
|
|
96
|
+
applyChange: { name: 0, agent: 1 },
|
|
97
|
+
ask: named,
|
|
98
|
+
suggestVerification: named,
|
|
99
|
+
waitFor: named,
|
|
100
|
+
verify: named,
|
|
101
|
+
...Object.fromEntries(hostStepFunctions.map((id) => [id, named])),
|
|
102
|
+
pipelineMoved: named,
|
|
103
|
+
claim: named,
|
|
104
|
+
letGo: named,
|
|
105
|
+
runDeploy: named,
|
|
106
|
+
measure: named,
|
|
107
|
+
resolveRevisions: named,
|
|
108
|
+
versions: named,
|
|
109
|
+
command: named,
|
|
110
|
+
compare: named
|
|
111
|
+
}));
|
|
112
|
+
var sdkForms = {
|
|
113
|
+
call: "call",
|
|
114
|
+
step: "step",
|
|
115
|
+
agent: "agent",
|
|
116
|
+
first: "first",
|
|
117
|
+
defineLoop: "defineLoop",
|
|
118
|
+
defineKit: "defineKit"
|
|
119
|
+
};
|
|
120
|
+
var isSdk = (specifier) => specifier === "@kitman-sh/sdk" || specifier.startsWith("@kitman-sh/sdk/");
|
|
121
|
+
|
|
122
|
+
// packages/sdk/src/build/outline/graph.ts
|
|
123
|
+
var isNode = (value) => isObject(value) && hasProperty(value, "type") && isString(value.type);
|
|
124
|
+
var childKeys = new Map;
|
|
125
|
+
var knownChildren = new WeakMap;
|
|
126
|
+
var childrenOf = (node) => {
|
|
127
|
+
const known = knownChildren.get(node) ?? readChildren(node);
|
|
128
|
+
knownChildren.set(node, known);
|
|
129
|
+
return known;
|
|
130
|
+
};
|
|
131
|
+
var readChildren = (node) => {
|
|
132
|
+
const children = [];
|
|
133
|
+
const keys = childKeys.get(node.type) ?? new Set(visitorKeys[node.type] ?? []);
|
|
134
|
+
childKeys.set(node.type, keys);
|
|
135
|
+
for (const [key, value] of Object.entries(node)) {
|
|
136
|
+
if (!keys.has(key))
|
|
137
|
+
continue;
|
|
138
|
+
if (Array.isArray(value)) {
|
|
139
|
+
for (const item of value)
|
|
140
|
+
if (isNode(item))
|
|
141
|
+
children.push(item);
|
|
142
|
+
} else if (isNode(value))
|
|
143
|
+
children.push(value);
|
|
144
|
+
}
|
|
145
|
+
return children;
|
|
146
|
+
};
|
|
147
|
+
var lineStartsOf = (source) => {
|
|
148
|
+
const starts = [0];
|
|
149
|
+
for (let index = 0;index < source.length; index++)
|
|
150
|
+
if (source[index] === `
|
|
151
|
+
`)
|
|
152
|
+
starts.push(index + 1);
|
|
153
|
+
return starts;
|
|
154
|
+
};
|
|
155
|
+
var located = (module, node) => {
|
|
156
|
+
let low = 0;
|
|
157
|
+
let high = module.lineStarts.length - 1;
|
|
158
|
+
while (low < high) {
|
|
159
|
+
const middle = Math.ceil((low + high) / 2);
|
|
160
|
+
if ((module.lineStarts[middle] ?? 0) <= node.start)
|
|
161
|
+
low = middle;
|
|
162
|
+
else
|
|
163
|
+
high = middle - 1;
|
|
164
|
+
}
|
|
165
|
+
return `${module.display}:${low + 1}`;
|
|
166
|
+
};
|
|
167
|
+
var maxText = 200;
|
|
168
|
+
var textOf = (module, node) => {
|
|
169
|
+
const text = module.source.slice(node.start, node.end).replaceAll(/\s+/gu, " ").trim();
|
|
170
|
+
return text.length > maxText ? `${text.slice(0, maxText - 1)}\u2026` : text;
|
|
171
|
+
};
|
|
172
|
+
var moduleName = (node) => node.type === "Literal" && isString(node.value) ? node.value : node.type === "Identifier" ? node.name : "";
|
|
173
|
+
var patternNames = (pattern, path = []) => {
|
|
174
|
+
switch (pattern.type) {
|
|
175
|
+
case "Identifier":
|
|
176
|
+
return [{ name: pattern.name, path }];
|
|
177
|
+
case "AssignmentPattern":
|
|
178
|
+
return patternNames(pattern.left, path);
|
|
179
|
+
case "RestElement":
|
|
180
|
+
return patternNames(pattern.argument, [...path, "..."]);
|
|
181
|
+
case "ObjectPattern":
|
|
182
|
+
return pattern.properties.flatMap((property) => property.type === "RestElement" ? patternNames(property.argument, [...path, "..."]) : patternNames(property.value, [...path, property.computed ? "[computed]" : moduleName(property.key)]));
|
|
183
|
+
case "ArrayPattern":
|
|
184
|
+
return pattern.elements.flatMap((element, index) => element === null ? [] : patternNames(element, [...path, String(index)]));
|
|
185
|
+
case "TSParameterProperty":
|
|
186
|
+
return patternNames(pattern.parameter, path);
|
|
187
|
+
default:
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var declareStatement = (module, bindings, statement) => {
|
|
192
|
+
const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration : statement;
|
|
193
|
+
if (declaration === null)
|
|
194
|
+
return;
|
|
195
|
+
switch (declaration.type) {
|
|
196
|
+
case "VariableDeclaration":
|
|
197
|
+
for (const declarator of declaration.declarations)
|
|
198
|
+
for (const { name, path } of patternNames(declarator.id))
|
|
199
|
+
bindings.set(name, path.length === 0 ? { kind: "declarator", module, declarator } : { kind: "destructured", module, declarator, path });
|
|
200
|
+
return;
|
|
201
|
+
case "FunctionDeclaration":
|
|
202
|
+
if (declaration.id !== null)
|
|
203
|
+
bindings.set(declaration.id.name, { kind: "function", module, node: declaration });
|
|
204
|
+
return;
|
|
205
|
+
case "ClassDeclaration":
|
|
206
|
+
if (declaration.id !== null)
|
|
207
|
+
bindings.set(declaration.id.name, { kind: "class", module, node: declaration });
|
|
208
|
+
return;
|
|
209
|
+
case "ImportDeclaration": {
|
|
210
|
+
if (declaration.importKind === "type")
|
|
211
|
+
return;
|
|
212
|
+
const target = module.targets.get(declaration.source.value) ?? {
|
|
213
|
+
kind: "external",
|
|
214
|
+
specifier: declaration.source.value
|
|
215
|
+
};
|
|
216
|
+
for (const specifier of declaration.specifiers) {
|
|
217
|
+
if (specifier.type === "ImportSpecifier" && specifier.importKind === "type")
|
|
218
|
+
continue;
|
|
219
|
+
const imported = specifier.type === "ImportSpecifier" ? moduleName(specifier.imported) : { ImportDefaultSpecifier: "default", ImportNamespaceSpecifier: "*" }[specifier.type];
|
|
220
|
+
bindings.set(specifier.local.name, { kind: "import", module, target, imported });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
var scopeOf = (module, node) => {
|
|
226
|
+
const known = module.scopes.get(node);
|
|
227
|
+
if (known !== undefined)
|
|
228
|
+
return known;
|
|
229
|
+
const bindings = new Map;
|
|
230
|
+
switch (node.type) {
|
|
231
|
+
case "Program":
|
|
232
|
+
case "BlockStatement":
|
|
233
|
+
case "StaticBlock":
|
|
234
|
+
for (const statement of node.body)
|
|
235
|
+
declareStatement(module, bindings, statement);
|
|
236
|
+
break;
|
|
237
|
+
case "SwitchStatement":
|
|
238
|
+
for (const branch of node.cases)
|
|
239
|
+
for (const statement of branch.consequent)
|
|
240
|
+
declareStatement(module, bindings, statement);
|
|
241
|
+
break;
|
|
242
|
+
case "FunctionDeclaration":
|
|
243
|
+
case "FunctionExpression":
|
|
244
|
+
case "ArrowFunctionExpression":
|
|
245
|
+
node.params.forEach((param, index) => {
|
|
246
|
+
const fallback = param.type === "AssignmentPattern" ? param.right : undefined;
|
|
247
|
+
for (const { name, path } of patternNames(param))
|
|
248
|
+
bindings.set(name, { kind: "param", module, fn: node, index, path, fallback });
|
|
249
|
+
});
|
|
250
|
+
if (node.type === "FunctionExpression" && node.id !== null)
|
|
251
|
+
bindings.set(node.id.name, { kind: "function", module, node });
|
|
252
|
+
break;
|
|
253
|
+
case "ForStatement":
|
|
254
|
+
case "ForOfStatement":
|
|
255
|
+
case "ForInStatement": {
|
|
256
|
+
const declaration = node.type === "ForStatement" ? node.init : node.left;
|
|
257
|
+
if (declaration?.type === "VariableDeclaration")
|
|
258
|
+
for (const declarator of declaration.declarations)
|
|
259
|
+
for (const { name } of patternNames(declarator.id))
|
|
260
|
+
bindings.set(name, node.type === "ForStatement" ? { kind: "declarator", module, declarator } : { kind: "other" });
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case "CatchClause":
|
|
264
|
+
if (node.param !== null)
|
|
265
|
+
for (const { name } of patternNames(node.param))
|
|
266
|
+
bindings.set(name, { kind: "other" });
|
|
267
|
+
break;
|
|
268
|
+
case "ClassExpression":
|
|
269
|
+
if (node.id !== null)
|
|
270
|
+
bindings.set(node.id.name, { kind: "class", module, node });
|
|
271
|
+
break;
|
|
272
|
+
default:
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
module.scopes.set(node, bindings);
|
|
276
|
+
return bindings;
|
|
277
|
+
};
|
|
278
|
+
var lookup = (module, name, at) => {
|
|
279
|
+
for (let node = at;node !== undefined; node = module.parents.get(node)) {
|
|
280
|
+
const binding = scopeOf(module, node)?.get(name);
|
|
281
|
+
if (binding !== undefined)
|
|
282
|
+
return binding;
|
|
283
|
+
}
|
|
284
|
+
return;
|
|
285
|
+
};
|
|
286
|
+
var enclosingFunction = (module, node) => {
|
|
287
|
+
for (let at = module.parents.get(node);at !== undefined; at = module.parents.get(at))
|
|
288
|
+
if (at.type === "FunctionDeclaration" || at.type === "FunctionExpression" || at.type === "ArrowFunctionExpression")
|
|
289
|
+
return at;
|
|
290
|
+
return;
|
|
291
|
+
};
|
|
292
|
+
var indexExports = (module) => {
|
|
293
|
+
for (const statement of module.program.body) {
|
|
294
|
+
if (statement.type === "ExportDefaultDeclaration") {
|
|
295
|
+
module.exports.set("default", { kind: "default", node: statement.declaration });
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (statement.type === "ExportAllDeclaration") {
|
|
299
|
+
if (statement.exportKind === "type")
|
|
300
|
+
continue;
|
|
301
|
+
const target = module.targets.get(statement.source.value) ?? {
|
|
302
|
+
kind: "external",
|
|
303
|
+
specifier: statement.source.value
|
|
304
|
+
};
|
|
305
|
+
if (statement.exported === null)
|
|
306
|
+
module.stars.push(target);
|
|
307
|
+
else
|
|
308
|
+
module.exports.set(moduleName(statement.exported), { kind: "reexport", target, imported: "*" });
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (statement.type !== "ExportNamedDeclaration" || statement.exportKind === "type")
|
|
312
|
+
continue;
|
|
313
|
+
if (statement.declaration !== null) {
|
|
314
|
+
const names = new Map;
|
|
315
|
+
declareStatement(module, names, statement);
|
|
316
|
+
for (const name of names.keys())
|
|
317
|
+
module.exports.set(name, { kind: "local", name });
|
|
318
|
+
}
|
|
319
|
+
const source = statement.source;
|
|
320
|
+
for (const specifier of statement.specifiers) {
|
|
321
|
+
if (specifier.exportKind === "type")
|
|
322
|
+
continue;
|
|
323
|
+
const exported = moduleName(specifier.exported);
|
|
324
|
+
const local = moduleName(specifier.local);
|
|
325
|
+
module.exports.set(exported, source === null ? { kind: "local", name: local } : {
|
|
326
|
+
kind: "reexport",
|
|
327
|
+
target: module.targets.get(source.value) ?? { kind: "external", specifier: source.value },
|
|
328
|
+
imported: local
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
var indexParents = (parents, root) => {
|
|
334
|
+
const pending = [root];
|
|
335
|
+
for (let node = pending.pop();node !== undefined; node = pending.pop())
|
|
336
|
+
for (const child of childrenOf(node)) {
|
|
337
|
+
parents.set(child, node);
|
|
338
|
+
pending.push(child);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
var specifiersOf = (program) => program.body.flatMap((statement) => (statement.type === "ImportDeclaration" || statement.type === "ExportAllDeclaration" || statement.type === "ExportNamedDeclaration" && statement.source !== null) && (statement.type === "ImportDeclaration" ? statement.importKind : statement.exportKind) !== "type" && statement.source !== null ? [statement.source.value] : []);
|
|
342
|
+
var parse = (path, source) => parseSync(path, source, { sourceType: "module", lang: "ts", preserveParens: false }).program;
|
|
343
|
+
var indexModule = (path, display, owner, source, program, targets) => {
|
|
344
|
+
const parents = new WeakMap;
|
|
345
|
+
indexParents(parents, program);
|
|
346
|
+
const module = {
|
|
347
|
+
path,
|
|
348
|
+
display,
|
|
349
|
+
...owner,
|
|
350
|
+
source,
|
|
351
|
+
program,
|
|
352
|
+
targets,
|
|
353
|
+
parents,
|
|
354
|
+
lineStarts: lineStartsOf(source),
|
|
355
|
+
scopes: new WeakMap,
|
|
356
|
+
exports: new Map,
|
|
357
|
+
stars: [],
|
|
358
|
+
assignments: undefined
|
|
359
|
+
};
|
|
360
|
+
indexExports(module);
|
|
361
|
+
return module;
|
|
362
|
+
};
|
|
363
|
+
var tsExtensions = ["", ".ts", ".tsx", "/index.ts", "/index.tsx"];
|
|
364
|
+
var external = (specifier) => isSdk(specifier) ? { kind: "sdk" } : { kind: "external", specifier };
|
|
365
|
+
var splitSpecifier = (specifier) => {
|
|
366
|
+
const parts = specifier.split("/");
|
|
367
|
+
const length = specifier.startsWith("@") ? 2 : 1;
|
|
368
|
+
return { name: parts.slice(0, length).join("/"), subpath: [".", ...parts.slice(length)].join("/") };
|
|
369
|
+
};
|
|
370
|
+
var ExportsField = Union([
|
|
371
|
+
String4,
|
|
372
|
+
Record(String4, Union([String4, Record(String4, Json), Null]))
|
|
373
|
+
]);
|
|
374
|
+
var PackageManifest = fromJsonString(Struct({
|
|
375
|
+
name: optionalKey(String4),
|
|
376
|
+
version: optionalKey(String4),
|
|
377
|
+
main: optionalKey(String4),
|
|
378
|
+
exports: optionalKey(ExportsField)
|
|
379
|
+
}));
|
|
380
|
+
var exportedFile = (manifest, subpath) => {
|
|
381
|
+
const exports = manifest.exports;
|
|
382
|
+
if (exports === undefined)
|
|
383
|
+
return subpath === "." ? manifest.main ?? "kitman.config.ts" : subpath;
|
|
384
|
+
if (isString(exports))
|
|
385
|
+
return subpath === "." ? exports : undefined;
|
|
386
|
+
const entry = Object.keys(exports).some((key) => key.startsWith(".")) ? exports[subpath] : subpath === "." ? exports : undefined;
|
|
387
|
+
if (entry === undefined || entry === null)
|
|
388
|
+
return;
|
|
389
|
+
if (isString(entry))
|
|
390
|
+
return entry;
|
|
391
|
+
for (const condition of ["bun", "import", "default", "types"]) {
|
|
392
|
+
const chosen = entry[condition];
|
|
393
|
+
if (isString(chosen))
|
|
394
|
+
return chosen;
|
|
395
|
+
}
|
|
396
|
+
return;
|
|
397
|
+
};
|
|
398
|
+
var loadGraph = (root) => gen(function* () {
|
|
399
|
+
const fs = yield* FileSystem;
|
|
400
|
+
const path = yield* Path;
|
|
401
|
+
const rootReal = yield* fs.realPath(root);
|
|
402
|
+
const modules = new Map;
|
|
403
|
+
const packages = new Map;
|
|
404
|
+
const isFile = (file) => fs.stat(file).pipe(map9((info) => info.type === "File"), orElseSucceed(() => false));
|
|
405
|
+
const readManifest = (directory) => fs.readFileString(path.join(directory, "package.json")).pipe(flatMap3(decodeEffect(PackageManifest)), orElseSucceed(() => {
|
|
406
|
+
return;
|
|
407
|
+
}));
|
|
408
|
+
const packageOf = (file) => gen(function* () {
|
|
409
|
+
for (let at = path.dirname(file);; at = path.dirname(at)) {
|
|
410
|
+
if (packages.has(at))
|
|
411
|
+
return packages.get(at);
|
|
412
|
+
if (yield* isFile(path.join(at, "package.json"))) {
|
|
413
|
+
const manifest = yield* readManifest(at);
|
|
414
|
+
const found = { directory: at, name: manifest?.name ?? path.basename(at), version: manifest?.version };
|
|
415
|
+
packages.set(at, found);
|
|
416
|
+
return found;
|
|
417
|
+
}
|
|
418
|
+
if (path.dirname(at) === at)
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
const displayOf = (file) => gen(function* () {
|
|
423
|
+
const owner = yield* packageOf(file);
|
|
424
|
+
if (owner === undefined)
|
|
425
|
+
return file;
|
|
426
|
+
const inPackage = path.relative(owner.directory, file).split(path.sep).join("/");
|
|
427
|
+
return owner.directory === rootReal ? inPackage : `${owner.name}/${inPackage}`;
|
|
428
|
+
});
|
|
429
|
+
const fileAt = (base) => gen(function* () {
|
|
430
|
+
for (const extension of tsExtensions) {
|
|
431
|
+
const candidate = `${base}${extension}`;
|
|
432
|
+
if (yield* isFile(candidate))
|
|
433
|
+
return yield* fs.realPath(candidate);
|
|
434
|
+
}
|
|
435
|
+
if (base.endsWith(".js") && (yield* isFile(`${base.slice(0, -3)}.ts`)))
|
|
436
|
+
return yield* fs.realPath(`${base.slice(0, -3)}.ts`);
|
|
437
|
+
return;
|
|
438
|
+
});
|
|
439
|
+
const installed = (from, specifier, kitOnly) => gen(function* () {
|
|
440
|
+
const { name, subpath } = splitSpecifier(specifier);
|
|
441
|
+
for (let at = path.dirname(from);; at = path.dirname(at)) {
|
|
442
|
+
const candidate = path.join(at, "node_modules", name);
|
|
443
|
+
if (yield* isFile(path.join(candidate, "package.json"))) {
|
|
444
|
+
if (kitOnly && !(yield* isFile(path.join(candidate, "kitman.config.ts"))))
|
|
445
|
+
return;
|
|
446
|
+
const manifest = yield* readManifest(candidate);
|
|
447
|
+
const file = manifest === undefined ? undefined : exportedFile(manifest, subpath);
|
|
448
|
+
return file === undefined ? undefined : yield* fileAt(path.join(candidate, file));
|
|
449
|
+
}
|
|
450
|
+
if (path.dirname(at) === at)
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
const targetOf = (from, specifier) => gen(function* () {
|
|
455
|
+
if (specifier.startsWith(".") || specifier.startsWith("/")) {
|
|
456
|
+
const file = yield* fileAt(path.resolve(path.dirname(from), specifier));
|
|
457
|
+
return file === undefined ? external(specifier) : { kind: "file", path: file };
|
|
458
|
+
}
|
|
459
|
+
if (isSdk(specifier)) {
|
|
460
|
+
const file = yield* installed(from, specifier, false);
|
|
461
|
+
return { kind: "sdk", ...file === undefined ? undefined : { path: file } };
|
|
462
|
+
}
|
|
463
|
+
const file = yield* installed(from, specifier, true);
|
|
464
|
+
return file === undefined ? external(specifier) : { kind: "file", path: file };
|
|
465
|
+
});
|
|
466
|
+
const entry = yield* fs.realPath(path.join(root, "kitman.config.ts"));
|
|
467
|
+
const pending = [entry];
|
|
468
|
+
for (let file = pending.pop();file !== undefined; file = pending.pop()) {
|
|
469
|
+
if (modules.has(file))
|
|
470
|
+
continue;
|
|
471
|
+
const source = yield* fs.readFileString(file);
|
|
472
|
+
const program = parse(file, source);
|
|
473
|
+
const targets = new Map;
|
|
474
|
+
for (const specifier of specifiersOf(program)) {
|
|
475
|
+
if (targets.has(specifier))
|
|
476
|
+
continue;
|
|
477
|
+
const target = yield* targetOf(file, specifier);
|
|
478
|
+
targets.set(specifier, target);
|
|
479
|
+
if (target.kind !== "external" && target.path !== undefined && !modules.has(target.path))
|
|
480
|
+
pending.push(target.path);
|
|
481
|
+
}
|
|
482
|
+
const owner = yield* packageOf(file);
|
|
483
|
+
modules.set(file, indexModule(file, yield* displayOf(file), { kit: owner?.name, version: owner?.version, sdk: owner !== undefined && isSdk(owner.name) }, source, program, targets));
|
|
484
|
+
}
|
|
485
|
+
return { modules, entry };
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
// packages/sdk/src/build/outline/sdk-steps.generated.ts
|
|
489
|
+
var sdkSteps = {
|
|
490
|
+
green: {
|
|
491
|
+
names: [
|
|
492
|
+
"green"
|
|
493
|
+
],
|
|
494
|
+
outline: [
|
|
495
|
+
{
|
|
496
|
+
kind: "step",
|
|
497
|
+
step: "pipelineStatus",
|
|
498
|
+
names: [
|
|
499
|
+
"pipeline"
|
|
500
|
+
],
|
|
501
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:62"
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
kind: "repeat",
|
|
505
|
+
label: "for (let look = 1; ; look++)",
|
|
506
|
+
nodes: [
|
|
507
|
+
{
|
|
508
|
+
kind: "branch",
|
|
509
|
+
paths: [
|
|
510
|
+
{
|
|
511
|
+
label: "pipeline.status === 'success'",
|
|
512
|
+
nodes: [
|
|
513
|
+
{
|
|
514
|
+
kind: "end",
|
|
515
|
+
statuses: [
|
|
516
|
+
"Green"
|
|
517
|
+
],
|
|
518
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:68"
|
|
519
|
+
}
|
|
520
|
+
]
|
|
521
|
+
}
|
|
522
|
+
],
|
|
523
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:68"
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
kind: "branch",
|
|
527
|
+
paths: [
|
|
528
|
+
{
|
|
529
|
+
label: "pipeline.status === 'failed'",
|
|
530
|
+
nodes: [
|
|
531
|
+
{
|
|
532
|
+
kind: "end",
|
|
533
|
+
failure: "PipelineFailed",
|
|
534
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:71"
|
|
535
|
+
}
|
|
536
|
+
]
|
|
537
|
+
}
|
|
538
|
+
],
|
|
539
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:70"
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
kind: "branch",
|
|
543
|
+
paths: [
|
|
544
|
+
{
|
|
545
|
+
label: "pipeline.status === 'canceled'",
|
|
546
|
+
nodes: [
|
|
547
|
+
{
|
|
548
|
+
kind: "end",
|
|
549
|
+
failure: "PipelineCanceled",
|
|
550
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:78"
|
|
551
|
+
}
|
|
552
|
+
]
|
|
553
|
+
}
|
|
554
|
+
],
|
|
555
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:78"
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
kind: "branch",
|
|
559
|
+
paths: [
|
|
560
|
+
{
|
|
561
|
+
label: "looks !== undefined && look > looks",
|
|
562
|
+
nodes: [
|
|
563
|
+
{
|
|
564
|
+
kind: "end",
|
|
565
|
+
statuses: [
|
|
566
|
+
"Pending"
|
|
567
|
+
],
|
|
568
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:80"
|
|
569
|
+
}
|
|
570
|
+
]
|
|
571
|
+
}
|
|
572
|
+
],
|
|
573
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:80"
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
kind: "branch",
|
|
577
|
+
paths: [
|
|
578
|
+
{
|
|
579
|
+
label: "pipeline.status === 'none' && checks !== undefined && ranAt.has(head)",
|
|
580
|
+
nodes: [
|
|
581
|
+
{
|
|
582
|
+
kind: "end",
|
|
583
|
+
failure: "PipelineNotRun",
|
|
584
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:85"
|
|
585
|
+
}
|
|
586
|
+
]
|
|
587
|
+
}
|
|
588
|
+
],
|
|
589
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:84"
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
kind: "branch",
|
|
593
|
+
paths: [
|
|
594
|
+
{
|
|
595
|
+
label: "pipeline.status === 'none' && checks !== undefined",
|
|
596
|
+
nodes: [
|
|
597
|
+
{
|
|
598
|
+
kind: "branch",
|
|
599
|
+
on: "failure",
|
|
600
|
+
nodes: [
|
|
601
|
+
{
|
|
602
|
+
kind: "step",
|
|
603
|
+
step: "verify",
|
|
604
|
+
names: [
|
|
605
|
+
"runner:${look}"
|
|
606
|
+
],
|
|
607
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:91"
|
|
608
|
+
}
|
|
609
|
+
],
|
|
610
|
+
paths: [
|
|
611
|
+
{
|
|
612
|
+
label: "StepFailed",
|
|
613
|
+
nodes: [
|
|
614
|
+
{
|
|
615
|
+
kind: "end",
|
|
616
|
+
failure: "PipelineNotRun",
|
|
617
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:92"
|
|
618
|
+
}
|
|
619
|
+
]
|
|
620
|
+
}
|
|
621
|
+
],
|
|
622
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:92"
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
kind: "step",
|
|
626
|
+
step: "reportPipeline",
|
|
627
|
+
names: [
|
|
628
|
+
"report:${look}"
|
|
629
|
+
],
|
|
630
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:94"
|
|
631
|
+
}
|
|
632
|
+
]
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
label: "else",
|
|
636
|
+
nodes: [
|
|
637
|
+
{
|
|
638
|
+
kind: "step",
|
|
639
|
+
step: "pipelineMoved",
|
|
640
|
+
names: [
|
|
641
|
+
"moved:${look}"
|
|
642
|
+
],
|
|
643
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:95"
|
|
644
|
+
}
|
|
645
|
+
]
|
|
646
|
+
}
|
|
647
|
+
],
|
|
648
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:87"
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
kind: "step",
|
|
652
|
+
step: "pipelineStatus",
|
|
653
|
+
names: [
|
|
654
|
+
"pipeline:${look}"
|
|
655
|
+
],
|
|
656
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:97"
|
|
657
|
+
}
|
|
658
|
+
],
|
|
659
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:65"
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
kind: "end",
|
|
663
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:99"
|
|
664
|
+
}
|
|
665
|
+
]
|
|
666
|
+
},
|
|
667
|
+
integrated: {
|
|
668
|
+
names: [
|
|
669
|
+
"integrated"
|
|
670
|
+
],
|
|
671
|
+
outline: [
|
|
672
|
+
{
|
|
673
|
+
kind: "step",
|
|
674
|
+
step: "integrationBranch",
|
|
675
|
+
names: [
|
|
676
|
+
"head"
|
|
677
|
+
],
|
|
678
|
+
at: "@kitman-sh/sdk/src/loop/integrated.ts:14"
|
|
679
|
+
}
|
|
680
|
+
]
|
|
681
|
+
},
|
|
682
|
+
landed: {
|
|
683
|
+
names: [
|
|
684
|
+
"landed"
|
|
685
|
+
],
|
|
686
|
+
outline: [
|
|
687
|
+
{
|
|
688
|
+
kind: "step",
|
|
689
|
+
step: "pipelineStatus",
|
|
690
|
+
names: [
|
|
691
|
+
"pipeline"
|
|
692
|
+
],
|
|
693
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:125"
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
kind: "branch",
|
|
697
|
+
paths: [
|
|
698
|
+
{
|
|
699
|
+
label: "disagreement !== undefined",
|
|
700
|
+
nodes: [
|
|
701
|
+
{
|
|
702
|
+
kind: "end",
|
|
703
|
+
failure: "MergeRefused",
|
|
704
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:224"
|
|
705
|
+
}
|
|
706
|
+
]
|
|
707
|
+
}
|
|
708
|
+
],
|
|
709
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:224"
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
kind: "step",
|
|
713
|
+
step: "green",
|
|
714
|
+
names: [
|
|
715
|
+
"green"
|
|
716
|
+
],
|
|
717
|
+
defined: true,
|
|
718
|
+
outline: [
|
|
719
|
+
{
|
|
720
|
+
kind: "step",
|
|
721
|
+
step: "pipelineStatus",
|
|
722
|
+
names: [
|
|
723
|
+
"pipeline"
|
|
724
|
+
],
|
|
725
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:62"
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
kind: "repeat",
|
|
729
|
+
label: "for (let look = 1; ; look++)",
|
|
730
|
+
nodes: [
|
|
731
|
+
{
|
|
732
|
+
kind: "branch",
|
|
733
|
+
paths: [
|
|
734
|
+
{
|
|
735
|
+
label: "pipeline.status === 'success'",
|
|
736
|
+
nodes: [
|
|
737
|
+
{
|
|
738
|
+
kind: "end",
|
|
739
|
+
statuses: [
|
|
740
|
+
"Green"
|
|
741
|
+
],
|
|
742
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:68"
|
|
743
|
+
}
|
|
744
|
+
]
|
|
745
|
+
}
|
|
746
|
+
],
|
|
747
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:68"
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
kind: "branch",
|
|
751
|
+
paths: [
|
|
752
|
+
{
|
|
753
|
+
label: "pipeline.status === 'failed'",
|
|
754
|
+
nodes: [
|
|
755
|
+
{
|
|
756
|
+
kind: "end",
|
|
757
|
+
failure: "PipelineFailed",
|
|
758
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:71"
|
|
759
|
+
}
|
|
760
|
+
]
|
|
761
|
+
}
|
|
762
|
+
],
|
|
763
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:70"
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
kind: "branch",
|
|
767
|
+
paths: [
|
|
768
|
+
{
|
|
769
|
+
label: "pipeline.status === 'canceled'",
|
|
770
|
+
nodes: [
|
|
771
|
+
{
|
|
772
|
+
kind: "end",
|
|
773
|
+
failure: "PipelineCanceled",
|
|
774
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:78"
|
|
775
|
+
}
|
|
776
|
+
]
|
|
777
|
+
}
|
|
778
|
+
],
|
|
779
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:78"
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
kind: "branch",
|
|
783
|
+
paths: [
|
|
784
|
+
{
|
|
785
|
+
label: "looks !== undefined && look > looks",
|
|
786
|
+
nodes: [
|
|
787
|
+
{
|
|
788
|
+
kind: "end",
|
|
789
|
+
statuses: [
|
|
790
|
+
"Pending"
|
|
791
|
+
],
|
|
792
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:80"
|
|
793
|
+
}
|
|
794
|
+
]
|
|
795
|
+
}
|
|
796
|
+
],
|
|
797
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:80"
|
|
798
|
+
},
|
|
799
|
+
{
|
|
800
|
+
kind: "branch",
|
|
801
|
+
paths: [
|
|
802
|
+
{
|
|
803
|
+
label: "pipeline.status === 'none' && checks !== undefined && ranAt.has(head)",
|
|
804
|
+
nodes: [
|
|
805
|
+
{
|
|
806
|
+
kind: "end",
|
|
807
|
+
failure: "PipelineNotRun",
|
|
808
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:85"
|
|
809
|
+
}
|
|
810
|
+
]
|
|
811
|
+
}
|
|
812
|
+
],
|
|
813
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:84"
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
kind: "branch",
|
|
817
|
+
paths: [
|
|
818
|
+
{
|
|
819
|
+
label: "pipeline.status === 'none' && checks !== undefined",
|
|
820
|
+
nodes: [
|
|
821
|
+
{
|
|
822
|
+
kind: "branch",
|
|
823
|
+
on: "failure",
|
|
824
|
+
nodes: [
|
|
825
|
+
{
|
|
826
|
+
kind: "step",
|
|
827
|
+
step: "verify",
|
|
828
|
+
names: [
|
|
829
|
+
"runner:${look}"
|
|
830
|
+
],
|
|
831
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:91"
|
|
832
|
+
}
|
|
833
|
+
],
|
|
834
|
+
paths: [
|
|
835
|
+
{
|
|
836
|
+
label: "StepFailed",
|
|
837
|
+
nodes: [
|
|
838
|
+
{
|
|
839
|
+
kind: "end",
|
|
840
|
+
failure: "PipelineNotRun",
|
|
841
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:92"
|
|
842
|
+
}
|
|
843
|
+
]
|
|
844
|
+
}
|
|
845
|
+
],
|
|
846
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:92"
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
kind: "step",
|
|
850
|
+
step: "reportPipeline",
|
|
851
|
+
names: [
|
|
852
|
+
"report:${look}"
|
|
853
|
+
],
|
|
854
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:94"
|
|
855
|
+
}
|
|
856
|
+
]
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
label: "else",
|
|
860
|
+
nodes: [
|
|
861
|
+
{
|
|
862
|
+
kind: "step",
|
|
863
|
+
step: "pipelineMoved",
|
|
864
|
+
names: [
|
|
865
|
+
"moved:${look}"
|
|
866
|
+
],
|
|
867
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:95"
|
|
868
|
+
}
|
|
869
|
+
]
|
|
870
|
+
}
|
|
871
|
+
],
|
|
872
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:87"
|
|
873
|
+
},
|
|
874
|
+
{
|
|
875
|
+
kind: "step",
|
|
876
|
+
step: "pipelineStatus",
|
|
877
|
+
names: [
|
|
878
|
+
"pipeline:${look}"
|
|
879
|
+
],
|
|
880
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:97"
|
|
881
|
+
}
|
|
882
|
+
],
|
|
883
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:65"
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
kind: "end",
|
|
887
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:99"
|
|
888
|
+
}
|
|
889
|
+
],
|
|
890
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:117"
|
|
891
|
+
},
|
|
892
|
+
{
|
|
893
|
+
kind: "branch",
|
|
894
|
+
paths: [
|
|
895
|
+
{
|
|
896
|
+
label: "Predicate.isTagged(result, 'Green')",
|
|
897
|
+
nodes: []
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
label: "else",
|
|
901
|
+
nodes: [
|
|
902
|
+
{
|
|
903
|
+
kind: "end",
|
|
904
|
+
failure: "MergeRefused",
|
|
905
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:121"
|
|
906
|
+
}
|
|
907
|
+
]
|
|
908
|
+
}
|
|
909
|
+
],
|
|
910
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:118"
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
kind: "runtime",
|
|
914
|
+
label: "approve",
|
|
915
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:109"
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
kind: "branch",
|
|
919
|
+
on: "failure",
|
|
920
|
+
nodes: [
|
|
921
|
+
{
|
|
922
|
+
kind: "step",
|
|
923
|
+
step: "claim",
|
|
924
|
+
names: [
|
|
925
|
+
"turn"
|
|
926
|
+
],
|
|
927
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:137"
|
|
928
|
+
}
|
|
929
|
+
],
|
|
930
|
+
paths: [
|
|
931
|
+
{
|
|
932
|
+
label: "StepFailed",
|
|
933
|
+
nodes: [
|
|
934
|
+
{
|
|
935
|
+
kind: "end",
|
|
936
|
+
failure: "MergeRefused",
|
|
937
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:138"
|
|
938
|
+
}
|
|
939
|
+
]
|
|
940
|
+
}
|
|
941
|
+
],
|
|
942
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:138"
|
|
943
|
+
},
|
|
944
|
+
{
|
|
945
|
+
kind: "repeat",
|
|
946
|
+
label: "for (let round = 1; ; round++)",
|
|
947
|
+
nodes: [
|
|
948
|
+
{
|
|
949
|
+
kind: "step",
|
|
950
|
+
step: "mergeChangeRequest",
|
|
951
|
+
names: [
|
|
952
|
+
"merge",
|
|
953
|
+
"merge:${round}"
|
|
954
|
+
],
|
|
955
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:142"
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
kind: "branch",
|
|
959
|
+
paths: [
|
|
960
|
+
{
|
|
961
|
+
label: "merged.status === 'merged'",
|
|
962
|
+
nodes: [
|
|
963
|
+
{
|
|
964
|
+
kind: "end",
|
|
965
|
+
statuses: [
|
|
966
|
+
"Merged"
|
|
967
|
+
],
|
|
968
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:144"
|
|
969
|
+
}
|
|
970
|
+
]
|
|
971
|
+
}
|
|
972
|
+
],
|
|
973
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:144"
|
|
974
|
+
},
|
|
975
|
+
{
|
|
976
|
+
kind: "branch",
|
|
977
|
+
paths: [
|
|
978
|
+
{
|
|
979
|
+
label: "merged.status === 'moved'",
|
|
980
|
+
nodes: [
|
|
981
|
+
{
|
|
982
|
+
kind: "end",
|
|
983
|
+
failure: "MergeRefused",
|
|
984
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:147"
|
|
985
|
+
}
|
|
986
|
+
]
|
|
987
|
+
}
|
|
988
|
+
],
|
|
989
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:146"
|
|
990
|
+
},
|
|
991
|
+
{
|
|
992
|
+
kind: "branch",
|
|
993
|
+
paths: [
|
|
994
|
+
{
|
|
995
|
+
label: "merged.reason === 'not_ready'",
|
|
996
|
+
nodes: [
|
|
997
|
+
{
|
|
998
|
+
kind: "end",
|
|
999
|
+
failure: "MergeRefused",
|
|
1000
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:153"
|
|
1001
|
+
}
|
|
1002
|
+
]
|
|
1003
|
+
}
|
|
1004
|
+
],
|
|
1005
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:152"
|
|
1006
|
+
},
|
|
1007
|
+
{
|
|
1008
|
+
kind: "branch",
|
|
1009
|
+
paths: [
|
|
1010
|
+
{
|
|
1011
|
+
label: "!catchUp",
|
|
1012
|
+
nodes: [
|
|
1013
|
+
{
|
|
1014
|
+
kind: "end",
|
|
1015
|
+
failure: "MergeRefused",
|
|
1016
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:156"
|
|
1017
|
+
}
|
|
1018
|
+
]
|
|
1019
|
+
}
|
|
1020
|
+
],
|
|
1021
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:155"
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
kind: "step",
|
|
1025
|
+
step: "level",
|
|
1026
|
+
names: [
|
|
1027
|
+
"level"
|
|
1028
|
+
],
|
|
1029
|
+
defined: true,
|
|
1030
|
+
outline: [
|
|
1031
|
+
{
|
|
1032
|
+
kind: "step",
|
|
1033
|
+
step: "syncBase",
|
|
1034
|
+
names: [
|
|
1035
|
+
"sync"
|
|
1036
|
+
],
|
|
1037
|
+
runtime: true,
|
|
1038
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:83"
|
|
1039
|
+
},
|
|
1040
|
+
{
|
|
1041
|
+
kind: "branch",
|
|
1042
|
+
paths: [
|
|
1043
|
+
{
|
|
1044
|
+
label: "synced.status === 'conflict'",
|
|
1045
|
+
nodes: [
|
|
1046
|
+
{
|
|
1047
|
+
kind: "end",
|
|
1048
|
+
failure: "Conflict",
|
|
1049
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:85"
|
|
1050
|
+
}
|
|
1051
|
+
]
|
|
1052
|
+
}
|
|
1053
|
+
],
|
|
1054
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:85"
|
|
1055
|
+
},
|
|
1056
|
+
{
|
|
1057
|
+
kind: "branch",
|
|
1058
|
+
paths: [
|
|
1059
|
+
{
|
|
1060
|
+
label: "synced.status === 'up_to_date'",
|
|
1061
|
+
nodes: [
|
|
1062
|
+
{
|
|
1063
|
+
kind: "end",
|
|
1064
|
+
statuses: [
|
|
1065
|
+
"Level"
|
|
1066
|
+
],
|
|
1067
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:87"
|
|
1068
|
+
}
|
|
1069
|
+
]
|
|
1070
|
+
}
|
|
1071
|
+
],
|
|
1072
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:87"
|
|
1073
|
+
},
|
|
1074
|
+
{
|
|
1075
|
+
kind: "branch",
|
|
1076
|
+
paths: [
|
|
1077
|
+
{
|
|
1078
|
+
label: "caught === undefined",
|
|
1079
|
+
nodes: [
|
|
1080
|
+
{
|
|
1081
|
+
kind: "end",
|
|
1082
|
+
statuses: [
|
|
1083
|
+
"CaughtUp"
|
|
1084
|
+
],
|
|
1085
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:91"
|
|
1086
|
+
}
|
|
1087
|
+
]
|
|
1088
|
+
}
|
|
1089
|
+
],
|
|
1090
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:90"
|
|
1091
|
+
},
|
|
1092
|
+
{
|
|
1093
|
+
kind: "branch",
|
|
1094
|
+
paths: [
|
|
1095
|
+
{
|
|
1096
|
+
label: "verdict.kind === 'changed'",
|
|
1097
|
+
nodes: [
|
|
1098
|
+
{
|
|
1099
|
+
kind: "end",
|
|
1100
|
+
statuses: [
|
|
1101
|
+
"CaughtUp"
|
|
1102
|
+
],
|
|
1103
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:102"
|
|
1104
|
+
}
|
|
1105
|
+
]
|
|
1106
|
+
}
|
|
1107
|
+
],
|
|
1108
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:101"
|
|
1109
|
+
},
|
|
1110
|
+
{
|
|
1111
|
+
kind: "branch",
|
|
1112
|
+
paths: [
|
|
1113
|
+
{
|
|
1114
|
+
label: "files.length > 0",
|
|
1115
|
+
nodes: [
|
|
1116
|
+
{
|
|
1117
|
+
kind: "end",
|
|
1118
|
+
statuses: [
|
|
1119
|
+
"CaughtUp"
|
|
1120
|
+
],
|
|
1121
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:111"
|
|
1122
|
+
}
|
|
1123
|
+
]
|
|
1124
|
+
}
|
|
1125
|
+
],
|
|
1126
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:111"
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
kind: "branch",
|
|
1130
|
+
on: "failure",
|
|
1131
|
+
nodes: [
|
|
1132
|
+
{
|
|
1133
|
+
kind: "step",
|
|
1134
|
+
step: "approveChangeRequest",
|
|
1135
|
+
names: [
|
|
1136
|
+
"carry"
|
|
1137
|
+
],
|
|
1138
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:113"
|
|
1139
|
+
}
|
|
1140
|
+
],
|
|
1141
|
+
paths: [
|
|
1142
|
+
{
|
|
1143
|
+
label: "StepFailed",
|
|
1144
|
+
nodes: []
|
|
1145
|
+
}
|
|
1146
|
+
],
|
|
1147
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:119"
|
|
1148
|
+
},
|
|
1149
|
+
{
|
|
1150
|
+
kind: "end",
|
|
1151
|
+
statuses: [
|
|
1152
|
+
"CaughtUp"
|
|
1153
|
+
],
|
|
1154
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:122"
|
|
1155
|
+
}
|
|
1156
|
+
],
|
|
1157
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:161"
|
|
1158
|
+
},
|
|
1159
|
+
{
|
|
1160
|
+
kind: "branch",
|
|
1161
|
+
paths: [
|
|
1162
|
+
{
|
|
1163
|
+
label: "Predicate.isTagged(synced, 'Level')",
|
|
1164
|
+
nodes: [
|
|
1165
|
+
{
|
|
1166
|
+
kind: "end",
|
|
1167
|
+
failure: "MergeRefused",
|
|
1168
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:164"
|
|
1169
|
+
}
|
|
1170
|
+
]
|
|
1171
|
+
}
|
|
1172
|
+
],
|
|
1173
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:163"
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
kind: "branch",
|
|
1177
|
+
paths: [
|
|
1178
|
+
{
|
|
1179
|
+
label: "head !== undefined",
|
|
1180
|
+
nodes: [
|
|
1181
|
+
{
|
|
1182
|
+
kind: "branch",
|
|
1183
|
+
on: "failure",
|
|
1184
|
+
nodes: [
|
|
1185
|
+
{
|
|
1186
|
+
kind: "step",
|
|
1187
|
+
step: "waitFor",
|
|
1188
|
+
names: [
|
|
1189
|
+
"pushed",
|
|
1190
|
+
"pushed:${round}"
|
|
1191
|
+
],
|
|
1192
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:249"
|
|
1193
|
+
}
|
|
1194
|
+
],
|
|
1195
|
+
paths: [
|
|
1196
|
+
{
|
|
1197
|
+
label: "WaitTimedOut",
|
|
1198
|
+
nodes: []
|
|
1199
|
+
}
|
|
1200
|
+
],
|
|
1201
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:250"
|
|
1202
|
+
}
|
|
1203
|
+
]
|
|
1204
|
+
}
|
|
1205
|
+
],
|
|
1206
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:248"
|
|
1207
|
+
},
|
|
1208
|
+
{
|
|
1209
|
+
kind: "step",
|
|
1210
|
+
step: "pipelineStatus",
|
|
1211
|
+
names: [
|
|
1212
|
+
"shown:1",
|
|
1213
|
+
"shown:${round}:1"
|
|
1214
|
+
],
|
|
1215
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:253"
|
|
1216
|
+
},
|
|
1217
|
+
{
|
|
1218
|
+
kind: "repeat",
|
|
1219
|
+
label: "for (let look = 1; !shows(shown); look++)",
|
|
1220
|
+
nodes: [
|
|
1221
|
+
{
|
|
1222
|
+
kind: "branch",
|
|
1223
|
+
on: "failure",
|
|
1224
|
+
nodes: [
|
|
1225
|
+
{
|
|
1226
|
+
kind: "step",
|
|
1227
|
+
step: "waitFor",
|
|
1228
|
+
names: [
|
|
1229
|
+
"pushed-again:${look}",
|
|
1230
|
+
"pushed-again:${round}:${look}"
|
|
1231
|
+
],
|
|
1232
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:259",
|
|
1233
|
+
afterReturn: true
|
|
1234
|
+
}
|
|
1235
|
+
],
|
|
1236
|
+
paths: [
|
|
1237
|
+
{
|
|
1238
|
+
label: "WaitTimedOut",
|
|
1239
|
+
nodes: []
|
|
1240
|
+
}
|
|
1241
|
+
],
|
|
1242
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:264"
|
|
1243
|
+
},
|
|
1244
|
+
{
|
|
1245
|
+
kind: "step",
|
|
1246
|
+
step: "pipelineStatus",
|
|
1247
|
+
names: [
|
|
1248
|
+
"shown:${look + 1}",
|
|
1249
|
+
"shown:${round}:${look + 1}"
|
|
1250
|
+
],
|
|
1251
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:266",
|
|
1252
|
+
afterReturn: true
|
|
1253
|
+
}
|
|
1254
|
+
],
|
|
1255
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:255"
|
|
1256
|
+
},
|
|
1257
|
+
{
|
|
1258
|
+
kind: "branch",
|
|
1259
|
+
paths: [
|
|
1260
|
+
{
|
|
1261
|
+
label: "'stale' in showed",
|
|
1262
|
+
nodes: [
|
|
1263
|
+
{
|
|
1264
|
+
kind: "end",
|
|
1265
|
+
failure: "MergeRefused",
|
|
1266
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:172"
|
|
1267
|
+
}
|
|
1268
|
+
]
|
|
1269
|
+
}
|
|
1270
|
+
],
|
|
1271
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:171"
|
|
1272
|
+
},
|
|
1273
|
+
{
|
|
1274
|
+
kind: "runtime",
|
|
1275
|
+
label: "approve",
|
|
1276
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:109"
|
|
1277
|
+
},
|
|
1278
|
+
{
|
|
1279
|
+
kind: "step",
|
|
1280
|
+
step: "green",
|
|
1281
|
+
names: [
|
|
1282
|
+
"green"
|
|
1283
|
+
],
|
|
1284
|
+
defined: true,
|
|
1285
|
+
outline: [
|
|
1286
|
+
{
|
|
1287
|
+
kind: "step",
|
|
1288
|
+
step: "pipelineStatus",
|
|
1289
|
+
names: [
|
|
1290
|
+
"pipeline"
|
|
1291
|
+
],
|
|
1292
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:62"
|
|
1293
|
+
},
|
|
1294
|
+
{
|
|
1295
|
+
kind: "repeat",
|
|
1296
|
+
label: "for (let look = 1; ; look++)",
|
|
1297
|
+
nodes: [
|
|
1298
|
+
{
|
|
1299
|
+
kind: "branch",
|
|
1300
|
+
paths: [
|
|
1301
|
+
{
|
|
1302
|
+
label: "pipeline.status === 'success'",
|
|
1303
|
+
nodes: [
|
|
1304
|
+
{
|
|
1305
|
+
kind: "end",
|
|
1306
|
+
statuses: [
|
|
1307
|
+
"Green"
|
|
1308
|
+
],
|
|
1309
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:68"
|
|
1310
|
+
}
|
|
1311
|
+
]
|
|
1312
|
+
}
|
|
1313
|
+
],
|
|
1314
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:68"
|
|
1315
|
+
},
|
|
1316
|
+
{
|
|
1317
|
+
kind: "branch",
|
|
1318
|
+
paths: [
|
|
1319
|
+
{
|
|
1320
|
+
label: "pipeline.status === 'failed'",
|
|
1321
|
+
nodes: [
|
|
1322
|
+
{
|
|
1323
|
+
kind: "end",
|
|
1324
|
+
failure: "PipelineFailed",
|
|
1325
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:71"
|
|
1326
|
+
}
|
|
1327
|
+
]
|
|
1328
|
+
}
|
|
1329
|
+
],
|
|
1330
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:70"
|
|
1331
|
+
},
|
|
1332
|
+
{
|
|
1333
|
+
kind: "branch",
|
|
1334
|
+
paths: [
|
|
1335
|
+
{
|
|
1336
|
+
label: "pipeline.status === 'canceled'",
|
|
1337
|
+
nodes: [
|
|
1338
|
+
{
|
|
1339
|
+
kind: "end",
|
|
1340
|
+
failure: "PipelineCanceled",
|
|
1341
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:78"
|
|
1342
|
+
}
|
|
1343
|
+
]
|
|
1344
|
+
}
|
|
1345
|
+
],
|
|
1346
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:78"
|
|
1347
|
+
},
|
|
1348
|
+
{
|
|
1349
|
+
kind: "branch",
|
|
1350
|
+
paths: [
|
|
1351
|
+
{
|
|
1352
|
+
label: "looks !== undefined && look > looks",
|
|
1353
|
+
nodes: [
|
|
1354
|
+
{
|
|
1355
|
+
kind: "end",
|
|
1356
|
+
statuses: [
|
|
1357
|
+
"Pending"
|
|
1358
|
+
],
|
|
1359
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:80"
|
|
1360
|
+
}
|
|
1361
|
+
]
|
|
1362
|
+
}
|
|
1363
|
+
],
|
|
1364
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:80"
|
|
1365
|
+
},
|
|
1366
|
+
{
|
|
1367
|
+
kind: "branch",
|
|
1368
|
+
paths: [
|
|
1369
|
+
{
|
|
1370
|
+
label: "pipeline.status === 'none' && checks !== undefined && ranAt.has(head)",
|
|
1371
|
+
nodes: [
|
|
1372
|
+
{
|
|
1373
|
+
kind: "end",
|
|
1374
|
+
failure: "PipelineNotRun",
|
|
1375
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:85"
|
|
1376
|
+
}
|
|
1377
|
+
]
|
|
1378
|
+
}
|
|
1379
|
+
],
|
|
1380
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:84"
|
|
1381
|
+
},
|
|
1382
|
+
{
|
|
1383
|
+
kind: "branch",
|
|
1384
|
+
paths: [
|
|
1385
|
+
{
|
|
1386
|
+
label: "pipeline.status === 'none' && checks !== undefined",
|
|
1387
|
+
nodes: [
|
|
1388
|
+
{
|
|
1389
|
+
kind: "branch",
|
|
1390
|
+
on: "failure",
|
|
1391
|
+
nodes: [
|
|
1392
|
+
{
|
|
1393
|
+
kind: "step",
|
|
1394
|
+
step: "verify",
|
|
1395
|
+
names: [
|
|
1396
|
+
"runner:${look}"
|
|
1397
|
+
],
|
|
1398
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:91"
|
|
1399
|
+
}
|
|
1400
|
+
],
|
|
1401
|
+
paths: [
|
|
1402
|
+
{
|
|
1403
|
+
label: "StepFailed",
|
|
1404
|
+
nodes: [
|
|
1405
|
+
{
|
|
1406
|
+
kind: "end",
|
|
1407
|
+
failure: "PipelineNotRun",
|
|
1408
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:92"
|
|
1409
|
+
}
|
|
1410
|
+
]
|
|
1411
|
+
}
|
|
1412
|
+
],
|
|
1413
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:92"
|
|
1414
|
+
},
|
|
1415
|
+
{
|
|
1416
|
+
kind: "step",
|
|
1417
|
+
step: "reportPipeline",
|
|
1418
|
+
names: [
|
|
1419
|
+
"report:${look}"
|
|
1420
|
+
],
|
|
1421
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:94"
|
|
1422
|
+
}
|
|
1423
|
+
]
|
|
1424
|
+
},
|
|
1425
|
+
{
|
|
1426
|
+
label: "else",
|
|
1427
|
+
nodes: [
|
|
1428
|
+
{
|
|
1429
|
+
kind: "step",
|
|
1430
|
+
step: "pipelineMoved",
|
|
1431
|
+
names: [
|
|
1432
|
+
"moved:${look}"
|
|
1433
|
+
],
|
|
1434
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:95"
|
|
1435
|
+
}
|
|
1436
|
+
]
|
|
1437
|
+
}
|
|
1438
|
+
],
|
|
1439
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:87"
|
|
1440
|
+
},
|
|
1441
|
+
{
|
|
1442
|
+
kind: "step",
|
|
1443
|
+
step: "pipelineStatus",
|
|
1444
|
+
names: [
|
|
1445
|
+
"pipeline:${look}"
|
|
1446
|
+
],
|
|
1447
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:97"
|
|
1448
|
+
}
|
|
1449
|
+
],
|
|
1450
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:65"
|
|
1451
|
+
},
|
|
1452
|
+
{
|
|
1453
|
+
kind: "end",
|
|
1454
|
+
at: "@kitman-sh/sdk/src/loop/green.ts:99"
|
|
1455
|
+
}
|
|
1456
|
+
],
|
|
1457
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:117"
|
|
1458
|
+
},
|
|
1459
|
+
{
|
|
1460
|
+
kind: "branch",
|
|
1461
|
+
paths: [
|
|
1462
|
+
{
|
|
1463
|
+
label: "Predicate.isTagged(result, 'Green')",
|
|
1464
|
+
nodes: []
|
|
1465
|
+
},
|
|
1466
|
+
{
|
|
1467
|
+
label: "else",
|
|
1468
|
+
nodes: [
|
|
1469
|
+
{
|
|
1470
|
+
kind: "end",
|
|
1471
|
+
failure: "MergeRefused",
|
|
1472
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:121"
|
|
1473
|
+
}
|
|
1474
|
+
]
|
|
1475
|
+
}
|
|
1476
|
+
],
|
|
1477
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:118"
|
|
1478
|
+
},
|
|
1479
|
+
{
|
|
1480
|
+
kind: "branch",
|
|
1481
|
+
paths: [
|
|
1482
|
+
{
|
|
1483
|
+
label: "passed.head !== head",
|
|
1484
|
+
nodes: [
|
|
1485
|
+
{
|
|
1486
|
+
kind: "end",
|
|
1487
|
+
failure: "MergeRefused",
|
|
1488
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:198"
|
|
1489
|
+
}
|
|
1490
|
+
]
|
|
1491
|
+
}
|
|
1492
|
+
],
|
|
1493
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:197"
|
|
1494
|
+
}
|
|
1495
|
+
],
|
|
1496
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:141"
|
|
1497
|
+
},
|
|
1498
|
+
{
|
|
1499
|
+
kind: "end",
|
|
1500
|
+
at: "@kitman-sh/sdk/src/loop/landed.ts:203"
|
|
1501
|
+
}
|
|
1502
|
+
]
|
|
1503
|
+
},
|
|
1504
|
+
leftForPickup: {
|
|
1505
|
+
names: [
|
|
1506
|
+
"leftForPickup"
|
|
1507
|
+
],
|
|
1508
|
+
outline: [
|
|
1509
|
+
{
|
|
1510
|
+
kind: "step",
|
|
1511
|
+
step: "createTasks",
|
|
1512
|
+
names: [
|
|
1513
|
+
"release-tasks"
|
|
1514
|
+
],
|
|
1515
|
+
at: "@kitman-sh/sdk/src/loop/left-for-pickup.ts:15"
|
|
1516
|
+
}
|
|
1517
|
+
]
|
|
1518
|
+
},
|
|
1519
|
+
level: {
|
|
1520
|
+
names: [
|
|
1521
|
+
"level"
|
|
1522
|
+
],
|
|
1523
|
+
outline: [
|
|
1524
|
+
{
|
|
1525
|
+
kind: "step",
|
|
1526
|
+
step: "syncBase",
|
|
1527
|
+
names: [
|
|
1528
|
+
"sync"
|
|
1529
|
+
],
|
|
1530
|
+
runtime: true,
|
|
1531
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:83"
|
|
1532
|
+
},
|
|
1533
|
+
{
|
|
1534
|
+
kind: "branch",
|
|
1535
|
+
paths: [
|
|
1536
|
+
{
|
|
1537
|
+
label: "synced.status === 'conflict'",
|
|
1538
|
+
nodes: [
|
|
1539
|
+
{
|
|
1540
|
+
kind: "end",
|
|
1541
|
+
failure: "Conflict",
|
|
1542
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:85"
|
|
1543
|
+
}
|
|
1544
|
+
]
|
|
1545
|
+
}
|
|
1546
|
+
],
|
|
1547
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:85"
|
|
1548
|
+
},
|
|
1549
|
+
{
|
|
1550
|
+
kind: "branch",
|
|
1551
|
+
paths: [
|
|
1552
|
+
{
|
|
1553
|
+
label: "synced.status === 'up_to_date'",
|
|
1554
|
+
nodes: [
|
|
1555
|
+
{
|
|
1556
|
+
kind: "end",
|
|
1557
|
+
statuses: [
|
|
1558
|
+
"Level"
|
|
1559
|
+
],
|
|
1560
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:87"
|
|
1561
|
+
}
|
|
1562
|
+
]
|
|
1563
|
+
}
|
|
1564
|
+
],
|
|
1565
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:87"
|
|
1566
|
+
},
|
|
1567
|
+
{
|
|
1568
|
+
kind: "branch",
|
|
1569
|
+
paths: [
|
|
1570
|
+
{
|
|
1571
|
+
label: "caught === undefined",
|
|
1572
|
+
nodes: [
|
|
1573
|
+
{
|
|
1574
|
+
kind: "end",
|
|
1575
|
+
statuses: [
|
|
1576
|
+
"CaughtUp"
|
|
1577
|
+
],
|
|
1578
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:91"
|
|
1579
|
+
}
|
|
1580
|
+
]
|
|
1581
|
+
}
|
|
1582
|
+
],
|
|
1583
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:90"
|
|
1584
|
+
},
|
|
1585
|
+
{
|
|
1586
|
+
kind: "branch",
|
|
1587
|
+
paths: [
|
|
1588
|
+
{
|
|
1589
|
+
label: "verdict.kind === 'changed'",
|
|
1590
|
+
nodes: [
|
|
1591
|
+
{
|
|
1592
|
+
kind: "end",
|
|
1593
|
+
statuses: [
|
|
1594
|
+
"CaughtUp"
|
|
1595
|
+
],
|
|
1596
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:102"
|
|
1597
|
+
}
|
|
1598
|
+
]
|
|
1599
|
+
}
|
|
1600
|
+
],
|
|
1601
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:101"
|
|
1602
|
+
},
|
|
1603
|
+
{
|
|
1604
|
+
kind: "branch",
|
|
1605
|
+
paths: [
|
|
1606
|
+
{
|
|
1607
|
+
label: "files.length > 0",
|
|
1608
|
+
nodes: [
|
|
1609
|
+
{
|
|
1610
|
+
kind: "end",
|
|
1611
|
+
statuses: [
|
|
1612
|
+
"CaughtUp"
|
|
1613
|
+
],
|
|
1614
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:111"
|
|
1615
|
+
}
|
|
1616
|
+
]
|
|
1617
|
+
}
|
|
1618
|
+
],
|
|
1619
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:111"
|
|
1620
|
+
},
|
|
1621
|
+
{
|
|
1622
|
+
kind: "branch",
|
|
1623
|
+
on: "failure",
|
|
1624
|
+
nodes: [
|
|
1625
|
+
{
|
|
1626
|
+
kind: "step",
|
|
1627
|
+
step: "approveChangeRequest",
|
|
1628
|
+
names: [
|
|
1629
|
+
"carry"
|
|
1630
|
+
],
|
|
1631
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:113"
|
|
1632
|
+
}
|
|
1633
|
+
],
|
|
1634
|
+
paths: [
|
|
1635
|
+
{
|
|
1636
|
+
label: "StepFailed",
|
|
1637
|
+
nodes: []
|
|
1638
|
+
}
|
|
1639
|
+
],
|
|
1640
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:119"
|
|
1641
|
+
},
|
|
1642
|
+
{
|
|
1643
|
+
kind: "end",
|
|
1644
|
+
statuses: [
|
|
1645
|
+
"CaughtUp"
|
|
1646
|
+
],
|
|
1647
|
+
at: "@kitman-sh/sdk/src/loop/level.ts:122"
|
|
1648
|
+
}
|
|
1649
|
+
]
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
|
|
1653
|
+
// packages/sdk/src/build/outline/read.ts
|
|
1654
|
+
var moduleFrame = { fn: undefined, args: [], caller: undefined, parent: undefined };
|
|
1655
|
+
var unknown = { kind: "unknown" };
|
|
1656
|
+
var noResults = { values: [], unknown: false };
|
|
1657
|
+
var emptyResults = { values: [{ kind: "empty" }], unknown: false };
|
|
1658
|
+
var unknownResults = { values: [], unknown: true };
|
|
1659
|
+
var union = (all) => ({
|
|
1660
|
+
values: all.flatMap((results) => results.values),
|
|
1661
|
+
unknown: all.some((results) => results.unknown)
|
|
1662
|
+
});
|
|
1663
|
+
var isEmpty = (result) => result.kind === "empty";
|
|
1664
|
+
var notEmpty = (results) => ({
|
|
1665
|
+
...results,
|
|
1666
|
+
values: results.values.filter((result) => !isEmpty(result))
|
|
1667
|
+
});
|
|
1668
|
+
var checked = (results) => ({
|
|
1669
|
+
...results,
|
|
1670
|
+
values: results.values.map((result) => ({ ...result, checked: true }))
|
|
1671
|
+
});
|
|
1672
|
+
var maxDepth = 40;
|
|
1673
|
+
var maxPatterns = 16;
|
|
1674
|
+
var maxInlined = 24;
|
|
1675
|
+
var effectMethods = {
|
|
1676
|
+
repeats: new Set(["repeat", "retry", "repeatOrElse", "retryOrElse", "schedule"]),
|
|
1677
|
+
catches: new Set(["catch", "catchAll", "catchCause", "catchAllCause", "catchIf", "catchSome", "orElse"]),
|
|
1678
|
+
taps: new Set(["tapError", "tapErrorTag", "tapErrorCause"]),
|
|
1679
|
+
takes: new Set(["either", "exit", "ignore", "ignoreCause", "isFailure", "isSuccess", "option", "result"]),
|
|
1680
|
+
matches: new Set(["match", "matchCause", "matchCauseEager", "matchEager"]),
|
|
1681
|
+
effectMatches: new Set(["matchEffect", "matchCauseEffect", "matchCauseEffectEager"]),
|
|
1682
|
+
keeps: new Set([
|
|
1683
|
+
"annotateLogs",
|
|
1684
|
+
"annotateSpans",
|
|
1685
|
+
"delay",
|
|
1686
|
+
"ensuring",
|
|
1687
|
+
"interruptible",
|
|
1688
|
+
"mapError",
|
|
1689
|
+
"mapErrorCause",
|
|
1690
|
+
"onError",
|
|
1691
|
+
"onExit",
|
|
1692
|
+
"onInterrupt",
|
|
1693
|
+
"orDie",
|
|
1694
|
+
"provide",
|
|
1695
|
+
"provideContext",
|
|
1696
|
+
"provideService",
|
|
1697
|
+
"provideServiceEffect",
|
|
1698
|
+
"retry",
|
|
1699
|
+
"scoped",
|
|
1700
|
+
"tap",
|
|
1701
|
+
"tapCause",
|
|
1702
|
+
"tapDefect",
|
|
1703
|
+
"tapError",
|
|
1704
|
+
"tapErrorCause",
|
|
1705
|
+
"tapErrorTag",
|
|
1706
|
+
"timeout",
|
|
1707
|
+
"uninterruptible",
|
|
1708
|
+
"withLogSpan",
|
|
1709
|
+
"withSpan"
|
|
1710
|
+
]),
|
|
1711
|
+
chains: new Set(["flatMap", "andThen", "tap", "zipRight"]),
|
|
1712
|
+
thunks: new Set(["suspend", "sync", "promise", "tryPromise", "try"])
|
|
1713
|
+
};
|
|
1714
|
+
var arrayMethods = new Set(["map", "flatMap", "forEach"]);
|
|
1715
|
+
var totalCatches = new Set(["catch", "catchAll", "catchCause", "catchAllCause", "orElse"]);
|
|
1716
|
+
var mapChildren = (node, map) => {
|
|
1717
|
+
switch (node.kind) {
|
|
1718
|
+
case "branch":
|
|
1719
|
+
return {
|
|
1720
|
+
...node,
|
|
1721
|
+
...node.nodes === undefined ? undefined : { nodes: map(node.nodes) },
|
|
1722
|
+
paths: node.paths.map((path) => ({ ...path, nodes: map(path.nodes) }))
|
|
1723
|
+
};
|
|
1724
|
+
case "all":
|
|
1725
|
+
case "first":
|
|
1726
|
+
return copiedFirst(node, { ...node, paths: node.paths.map((path) => ({ ...path, nodes: map(path.nodes) })) });
|
|
1727
|
+
case "repeat":
|
|
1728
|
+
case "many":
|
|
1729
|
+
return { ...node, nodes: map(node.nodes) };
|
|
1730
|
+
default:
|
|
1731
|
+
return node;
|
|
1732
|
+
}
|
|
1733
|
+
};
|
|
1734
|
+
var childLists = (node) => {
|
|
1735
|
+
switch (node.kind) {
|
|
1736
|
+
case "branch":
|
|
1737
|
+
return [node.nodes ?? [], ...node.paths.map((path) => path.nodes)];
|
|
1738
|
+
case "all":
|
|
1739
|
+
case "first":
|
|
1740
|
+
return node.paths.map((path) => path.nodes);
|
|
1741
|
+
case "repeat":
|
|
1742
|
+
case "many":
|
|
1743
|
+
return [node.nodes];
|
|
1744
|
+
default:
|
|
1745
|
+
return [];
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
var calledFirst = new WeakMap;
|
|
1749
|
+
var copiedFirst = (node, copy) => {
|
|
1750
|
+
const call = calledFirst.get(node);
|
|
1751
|
+
if (call !== undefined)
|
|
1752
|
+
calledFirst.set(copy, call);
|
|
1753
|
+
return copy;
|
|
1754
|
+
};
|
|
1755
|
+
var hasEnd = (nodes) => nodes.some((node) => node.kind === "end" && node.caught !== true || childLists(node).some(hasEnd));
|
|
1756
|
+
var namesGiven = (node) => [
|
|
1757
|
+
...node.kind === "first" ? node.as ?? [] : [],
|
|
1758
|
+
...childLists(node).flatMap((list) => list.flatMap(namesGiven))
|
|
1759
|
+
];
|
|
1760
|
+
var holdsEnd = (node, which) => node.kind === "end" ? which(node) : childLists(node).some((list) => list.some((inner) => holdsEnd(inner, which)));
|
|
1761
|
+
var isFunction = (node) => node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration";
|
|
1762
|
+
var unwrap = (node) => {
|
|
1763
|
+
let at = node;
|
|
1764
|
+
while (at.type === "TSAsExpression" || at.type === "TSSatisfiesExpression" || at.type === "TSNonNullExpression" || at.type === "TSTypeAssertion" || at.type === "TSInstantiationExpression" || at.type === "ParenthesizedExpression" || at.type === "ChainExpression")
|
|
1765
|
+
at = at.expression;
|
|
1766
|
+
return at;
|
|
1767
|
+
};
|
|
1768
|
+
var stringLiteral = (node) => {
|
|
1769
|
+
const at = node === undefined ? undefined : unwrap(node);
|
|
1770
|
+
if (at?.type === "Literal" && isString(at.value))
|
|
1771
|
+
return at.value;
|
|
1772
|
+
return at?.type === "TemplateLiteral" && at.expressions.length === 0 ? at.quasis[0]?.value.cooked ?? undefined : undefined;
|
|
1773
|
+
};
|
|
1774
|
+
var keyName = (key, computed) => {
|
|
1775
|
+
if (!computed && key.type === "Identifier")
|
|
1776
|
+
return key.name;
|
|
1777
|
+
return stringLiteral(key);
|
|
1778
|
+
};
|
|
1779
|
+
var memberName = (node) => node.type === "MemberExpression" ? node.computed ? stringLiteral(node.property) : node.property.type === "Identifier" ? node.property.name : undefined : undefined;
|
|
1780
|
+
var returnsOf = (() => {
|
|
1781
|
+
const cache = new WeakMap;
|
|
1782
|
+
return (fn) => {
|
|
1783
|
+
const known = cache.get(fn);
|
|
1784
|
+
if (known !== undefined)
|
|
1785
|
+
return known;
|
|
1786
|
+
const body = fn.body;
|
|
1787
|
+
if (body === null)
|
|
1788
|
+
return [];
|
|
1789
|
+
if (body.type !== "BlockStatement")
|
|
1790
|
+
return [body];
|
|
1791
|
+
const found = [];
|
|
1792
|
+
const pending = [body];
|
|
1793
|
+
for (let node = pending.pop();node !== undefined; node = pending.pop()) {
|
|
1794
|
+
if (node.type === "ReturnStatement" && node.argument !== null)
|
|
1795
|
+
found.push(node.argument);
|
|
1796
|
+
for (const child of childrenOf(node))
|
|
1797
|
+
if (!isFunction(child))
|
|
1798
|
+
pending.push(child);
|
|
1799
|
+
}
|
|
1800
|
+
const ordered = found.toSorted((a, b) => a.start - b.start);
|
|
1801
|
+
cache.set(fn, ordered);
|
|
1802
|
+
return ordered;
|
|
1803
|
+
};
|
|
1804
|
+
})();
|
|
1805
|
+
var cached = (read) => {
|
|
1806
|
+
const known = new WeakMap;
|
|
1807
|
+
return (node) => {
|
|
1808
|
+
const found = known.get(node) ?? read(node);
|
|
1809
|
+
known.set(node, found);
|
|
1810
|
+
return found;
|
|
1811
|
+
};
|
|
1812
|
+
};
|
|
1813
|
+
var returnsNothing = cached((fn) => {
|
|
1814
|
+
const pending = fn.body === null ? [] : [fn.body];
|
|
1815
|
+
for (let node = pending.pop();node !== undefined; node = pending.pop()) {
|
|
1816
|
+
if (node.type === "ReturnStatement" && node.argument === null)
|
|
1817
|
+
return true;
|
|
1818
|
+
for (const child of childrenOf(node))
|
|
1819
|
+
if (!isFunction(child))
|
|
1820
|
+
pending.push(child);
|
|
1821
|
+
}
|
|
1822
|
+
return false;
|
|
1823
|
+
});
|
|
1824
|
+
var returnsIn = cached((node) => {
|
|
1825
|
+
const pending = [node];
|
|
1826
|
+
for (let found = pending.pop();found !== undefined; found = pending.pop()) {
|
|
1827
|
+
if (found.type === "ReturnStatement")
|
|
1828
|
+
return true;
|
|
1829
|
+
for (const child of childrenOf(found))
|
|
1830
|
+
if (!isFunction(child))
|
|
1831
|
+
pending.push(child);
|
|
1832
|
+
}
|
|
1833
|
+
return false;
|
|
1834
|
+
});
|
|
1835
|
+
var afterReturn = (nodes) => nodes.map((node) => {
|
|
1836
|
+
const paths = (of) => of.map((path) => ({ ...path, nodes: afterReturn(path.nodes) }));
|
|
1837
|
+
switch (node.kind) {
|
|
1838
|
+
case "step":
|
|
1839
|
+
case "call":
|
|
1840
|
+
return { ...node, afterReturn: true };
|
|
1841
|
+
case "end":
|
|
1842
|
+
return endsFailing(node) ? { ...node, afterReturn: true } : node;
|
|
1843
|
+
case "branch":
|
|
1844
|
+
return {
|
|
1845
|
+
...node,
|
|
1846
|
+
...node.nodes === undefined ? undefined : { nodes: afterReturn(node.nodes) },
|
|
1847
|
+
paths: paths(node.paths)
|
|
1848
|
+
};
|
|
1849
|
+
case "all":
|
|
1850
|
+
case "first":
|
|
1851
|
+
return { ...node, paths: paths(node.paths) };
|
|
1852
|
+
case "repeat":
|
|
1853
|
+
case "many":
|
|
1854
|
+
return { ...node, nodes: afterReturn(node.nodes) };
|
|
1855
|
+
case "runtime":
|
|
1856
|
+
return node;
|
|
1857
|
+
}
|
|
1858
|
+
});
|
|
1859
|
+
var isLoop = (node) => node.type === "WhileStatement" || node.type === "DoWhileStatement" || node.type === "ForStatement" || node.type === "ForOfStatement" || node.type === "ForInStatement";
|
|
1860
|
+
var breaksOut = (node) => {
|
|
1861
|
+
if (node.type === "BreakStatement")
|
|
1862
|
+
return true;
|
|
1863
|
+
if (isFunction(node))
|
|
1864
|
+
return false;
|
|
1865
|
+
const inner = node.type === "SwitchStatement" || isLoop(node);
|
|
1866
|
+
return childrenOf(node).some((child) => inner ? breaksFurther(child) : breaksOut(child));
|
|
1867
|
+
};
|
|
1868
|
+
var breaksFurther = (node) => node.type === "BreakStatement" ? node.label !== null : !isFunction(node) && childrenOf(node).some(breaksFurther);
|
|
1869
|
+
var isOptional = (node) => {
|
|
1870
|
+
if (node.type === "MemberExpression")
|
|
1871
|
+
return node.optional || isOptional(node.object);
|
|
1872
|
+
if (node.type === "CallExpression")
|
|
1873
|
+
return node.optional || isOptional(node.callee);
|
|
1874
|
+
return node.type === "TSNonNullExpression" && isOptional(node.expression);
|
|
1875
|
+
};
|
|
1876
|
+
var leaves = cached((node) => leavesBy(node, true, true));
|
|
1877
|
+
var leavesBy = (node, breaks, continues) => {
|
|
1878
|
+
if (isFunction(node))
|
|
1879
|
+
return false;
|
|
1880
|
+
if (node.type === "ReturnStatement" || node.type === "ThrowStatement")
|
|
1881
|
+
return true;
|
|
1882
|
+
if (node.type === "BreakStatement")
|
|
1883
|
+
return breaks || node.label !== null;
|
|
1884
|
+
if (node.type === "ContinueStatement")
|
|
1885
|
+
return continues || node.label !== null;
|
|
1886
|
+
const loop = isLoop(node);
|
|
1887
|
+
return childrenOf(node).some((child) => leavesBy(child, breaks && !loop && node.type !== "SwitchStatement", continues && !loop));
|
|
1888
|
+
};
|
|
1889
|
+
var reads = (module, test, binding, seen = new Set) => {
|
|
1890
|
+
if (test.type === "Identifier") {
|
|
1891
|
+
const found = lookup(module, test.name, test);
|
|
1892
|
+
if (found === binding)
|
|
1893
|
+
return true;
|
|
1894
|
+
if (found?.kind !== "declarator" || found.declarator.init === null || seen.has(found))
|
|
1895
|
+
return false;
|
|
1896
|
+
if (found.declarator.init.type === "YieldExpression")
|
|
1897
|
+
return false;
|
|
1898
|
+
seen.add(found);
|
|
1899
|
+
return reads(module, found.declarator.init, binding, seen);
|
|
1900
|
+
}
|
|
1901
|
+
if (test.type === "MemberExpression" && !test.computed)
|
|
1902
|
+
return reads(module, test.object, binding, seen);
|
|
1903
|
+
return childrenOf(test).some((child) => reads(module, child, binding, seen));
|
|
1904
|
+
};
|
|
1905
|
+
var readsChecked = (module, node) => {
|
|
1906
|
+
let name = unwrap(node);
|
|
1907
|
+
while (name.type === "MemberExpression")
|
|
1908
|
+
name = unwrap(name.object);
|
|
1909
|
+
const binding = name.type === "Identifier" ? lookup(module, name.name, name) : undefined;
|
|
1910
|
+
if (binding === undefined)
|
|
1911
|
+
return false;
|
|
1912
|
+
const tests = (test) => test !== null && reads(module, test, binding);
|
|
1913
|
+
const leftBefore = (statements, at) => statements.slice(0, Math.max(statements.indexOf(at), 0)).some((statement) => statement.type === "IfStatement" && tests(statement.test) && leaves(statement) || statement.type === "SwitchStatement" && tests(statement.discriminant) && leaves(statement));
|
|
1914
|
+
let at = node;
|
|
1915
|
+
for (let parent = module.parents.get(at);parent !== undefined; parent = module.parents.get(at)) {
|
|
1916
|
+
switch (parent.type) {
|
|
1917
|
+
case "IfStatement":
|
|
1918
|
+
case "ConditionalExpression":
|
|
1919
|
+
case "WhileStatement":
|
|
1920
|
+
case "ForStatement":
|
|
1921
|
+
if (at !== parent.test && tests(parent.test))
|
|
1922
|
+
return true;
|
|
1923
|
+
break;
|
|
1924
|
+
case "LogicalExpression":
|
|
1925
|
+
if (at === parent.right && tests(parent.left))
|
|
1926
|
+
return true;
|
|
1927
|
+
break;
|
|
1928
|
+
case "SwitchStatement":
|
|
1929
|
+
if (at !== parent.discriminant && tests(parent.discriminant))
|
|
1930
|
+
return true;
|
|
1931
|
+
break;
|
|
1932
|
+
case "SwitchCase":
|
|
1933
|
+
if (leftBefore(parent.consequent, at) || at !== parent.test && tests(parent.test))
|
|
1934
|
+
return true;
|
|
1935
|
+
break;
|
|
1936
|
+
case "BlockStatement":
|
|
1937
|
+
case "Program":
|
|
1938
|
+
if (leftBefore(parent.body, at))
|
|
1939
|
+
return true;
|
|
1940
|
+
break;
|
|
1941
|
+
default:
|
|
1942
|
+
break;
|
|
1943
|
+
}
|
|
1944
|
+
at = parent;
|
|
1945
|
+
}
|
|
1946
|
+
return false;
|
|
1947
|
+
};
|
|
1948
|
+
var dedupe = (values) => [...new Set(values)];
|
|
1949
|
+
var sdkNames = new Set([...lentSteps.keys(), ...Object.values(sdkForms)]);
|
|
1950
|
+
var outlineReader = (graph, sdkSteps2 = new Map(Object.entries(sdkSteps))) => {
|
|
1951
|
+
const tapEnds = new WeakMap;
|
|
1952
|
+
const defined = new WeakMap;
|
|
1953
|
+
const definingNow = new Set;
|
|
1954
|
+
const endingNow = new Set;
|
|
1955
|
+
const checkedNames = new WeakMap;
|
|
1956
|
+
const isChecked = (module, node) => {
|
|
1957
|
+
const found = checkedNames.get(node) ?? readsChecked(module, node);
|
|
1958
|
+
checkedNames.set(node, found);
|
|
1959
|
+
return found;
|
|
1960
|
+
};
|
|
1961
|
+
const moduleAt = (path) => graph.modules.get(path);
|
|
1962
|
+
const frameOf = (frame, fn) => {
|
|
1963
|
+
for (let at = frame;at !== undefined; at = at.parent)
|
|
1964
|
+
if (at.fn === fn)
|
|
1965
|
+
return at;
|
|
1966
|
+
return;
|
|
1967
|
+
};
|
|
1968
|
+
const frameFor = (module, node, frame) => {
|
|
1969
|
+
const fn = enclosingFunction(module, node);
|
|
1970
|
+
if (fn === undefined)
|
|
1971
|
+
return moduleFrame;
|
|
1972
|
+
return frameOf(frame, fn) ?? { fn, args: [], caller: undefined, parent: undefined };
|
|
1973
|
+
};
|
|
1974
|
+
const callFrame = (fn, call, caller) => ({
|
|
1975
|
+
fn: fn.fn,
|
|
1976
|
+
args: call.arguments,
|
|
1977
|
+
caller,
|
|
1978
|
+
parent: fn.place.frame
|
|
1979
|
+
});
|
|
1980
|
+
const unboundFrame = (fn) => ({
|
|
1981
|
+
fn: fn.fn,
|
|
1982
|
+
args: [],
|
|
1983
|
+
caller: undefined,
|
|
1984
|
+
parent: fn.place.frame
|
|
1985
|
+
});
|
|
1986
|
+
const assignmentsOf = (module, declarator) => {
|
|
1987
|
+
if (module.assignments === undefined) {
|
|
1988
|
+
const assignments = new WeakMap;
|
|
1989
|
+
const pending = [module.program];
|
|
1990
|
+
for (let node = pending.pop();node !== undefined; node = pending.pop()) {
|
|
1991
|
+
if (node.type === "AssignmentExpression" && node.operator === "=" && node.left.type === "Identifier") {
|
|
1992
|
+
const binding = lookup(module, node.left.name, node);
|
|
1993
|
+
if (binding?.kind === "declarator")
|
|
1994
|
+
assignments.set(binding.declarator, [...assignments.get(binding.declarator) ?? [], node.right]);
|
|
1995
|
+
}
|
|
1996
|
+
pending.push(...childrenOf(node));
|
|
1997
|
+
}
|
|
1998
|
+
module.assignments = assignments;
|
|
1999
|
+
}
|
|
2000
|
+
return (module.assignments.get(declarator) ?? []).toSorted((a, b) => a.start - b.start);
|
|
2001
|
+
};
|
|
2002
|
+
const onlyYielded = new WeakMap;
|
|
2003
|
+
const readWhereYielded = (module, declarator) => {
|
|
2004
|
+
let found = onlyYielded.get(module);
|
|
2005
|
+
if (found === undefined) {
|
|
2006
|
+
const uses = new Map;
|
|
2007
|
+
const pending = [module.program];
|
|
2008
|
+
const above = (node) => node === undefined ? undefined : module.parents.get(node);
|
|
2009
|
+
for (let node = pending.pop();node !== undefined; node = pending.pop()) {
|
|
2010
|
+
pending.push(...childrenOf(node));
|
|
2011
|
+
if (node.type !== "Identifier")
|
|
2012
|
+
continue;
|
|
2013
|
+
const parent = above(node);
|
|
2014
|
+
const call = above(parent);
|
|
2015
|
+
const yielded = above(call);
|
|
2016
|
+
const namesOnly = parent?.type === "MemberExpression" && parent.property === node && !parent.computed || parent?.type === "Property" && parent.key === node && !parent.computed && !parent.shorthand;
|
|
2017
|
+
if (!namesOnly) {
|
|
2018
|
+
const binding = lookup(module, node.name, node);
|
|
2019
|
+
if (binding?.kind === "declarator" && binding.declarator.id !== node) {
|
|
2020
|
+
const isYield = (at, argument) => at?.type === "YieldExpression" && at.delegate && at.argument === argument;
|
|
2021
|
+
const piped = parent?.type === "MemberExpression" && parent.object === node && memberName(parent) === "pipe" && call?.type === "CallExpression" && call.callee === parent && isYield(yielded, call);
|
|
2022
|
+
uses.set(binding.declarator, (uses.get(binding.declarator) ?? true) && (isYield(parent, node) || piped));
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
found = new WeakSet;
|
|
2027
|
+
for (const [bound, yieldedOnly] of uses) {
|
|
2028
|
+
const init = bound.init === null ? undefined : unwrap(bound.init);
|
|
2029
|
+
if (yieldedOnly && init !== undefined && init.type === "CallExpression" && bound.id.type === "Identifier")
|
|
2030
|
+
found.add(bound);
|
|
2031
|
+
}
|
|
2032
|
+
onlyYielded.set(module, found);
|
|
2033
|
+
}
|
|
2034
|
+
return found.has(declarator);
|
|
2035
|
+
};
|
|
2036
|
+
const readingNow = new Set;
|
|
2037
|
+
const exportedDeclarator = (module, name, depth) => {
|
|
2038
|
+
if (depth > maxDepth)
|
|
2039
|
+
return;
|
|
2040
|
+
const entry = module.exports.get(name);
|
|
2041
|
+
if (entry === undefined) {
|
|
2042
|
+
for (const target of module.stars) {
|
|
2043
|
+
const found = target.kind === "file" ? importedDeclarator(target, name, depth + 1) : undefined;
|
|
2044
|
+
if (found !== undefined)
|
|
2045
|
+
return found;
|
|
2046
|
+
}
|
|
2047
|
+
return;
|
|
2048
|
+
}
|
|
2049
|
+
switch (entry.kind) {
|
|
2050
|
+
case "local": {
|
|
2051
|
+
const binding = lookup(module, entry.name, module.program);
|
|
2052
|
+
if (binding?.kind === "declarator")
|
|
2053
|
+
return { module: binding.module, declarator: binding.declarator };
|
|
2054
|
+
return binding?.kind === "import" ? importedDeclarator(binding.target, binding.imported, depth + 1) : undefined;
|
|
2055
|
+
}
|
|
2056
|
+
case "reexport":
|
|
2057
|
+
return importedDeclarator(entry.target, entry.imported, depth + 1);
|
|
2058
|
+
default:
|
|
2059
|
+
return;
|
|
2060
|
+
}
|
|
2061
|
+
};
|
|
2062
|
+
const importedDeclarator = (target, imported, depth) => {
|
|
2063
|
+
const module = target.kind === "file" && imported !== "*" ? moduleAt(target.path) : undefined;
|
|
2064
|
+
return module === undefined ? undefined : exportedDeclarator(module, imported, depth);
|
|
2065
|
+
};
|
|
2066
|
+
const declaratorOf = (binding) => binding?.kind === "declarator" ? { module: binding.module, declarator: binding.declarator } : undefined;
|
|
2067
|
+
const yieldedName = (identifier, walk) => {
|
|
2068
|
+
if (identifier.type !== "Identifier")
|
|
2069
|
+
return [];
|
|
2070
|
+
const binding = lookup(walk.place.module, identifier.name, identifier);
|
|
2071
|
+
if (binding?.kind === "param") {
|
|
2072
|
+
const arg = binding.path.length === 0 ? argumentOf(binding, walk.place.frame) : undefined;
|
|
2073
|
+
const passed = arg === undefined ? undefined : unwrap(arg.node);
|
|
2074
|
+
return arg !== undefined && passed?.type === "Identifier" ? yieldedName(passed, { ...walk, place: arg.place }) : [];
|
|
2075
|
+
}
|
|
2076
|
+
const bound = binding?.kind === "import" ? importedDeclarator(binding.target, binding.imported, 0) : declaratorOf(binding);
|
|
2077
|
+
if (bound === undefined || bound.declarator.init === null || readingNow.has(bound.declarator))
|
|
2078
|
+
return [];
|
|
2079
|
+
const { module, declarator } = bound;
|
|
2080
|
+
const atModule = enclosingFunction(module, declarator) === undefined;
|
|
2081
|
+
if (!atModule && !readWhereYielded(module, declarator))
|
|
2082
|
+
return [];
|
|
2083
|
+
if (atModule && assignmentsOf(module, declarator).length > 0)
|
|
2084
|
+
return [
|
|
2085
|
+
{ kind: "runtime", label: textOf(walk.place.module, identifier), at: located(walk.place.module, identifier) }
|
|
2086
|
+
];
|
|
2087
|
+
readingNow.add(declarator);
|
|
2088
|
+
try {
|
|
2089
|
+
return walkExpression(declarator.init, { ...walk, place: { module, frame: atModule ? moduleFrame : frameFor(module, declarator, walk.place.frame) } }, true);
|
|
2090
|
+
} finally {
|
|
2091
|
+
readingNow.delete(declarator);
|
|
2092
|
+
}
|
|
2093
|
+
};
|
|
2094
|
+
const sdkExport = (module, name, depth) => {
|
|
2095
|
+
if (name === "*")
|
|
2096
|
+
return { kind: "sdk", name, module };
|
|
2097
|
+
if (sdkNames.has(name))
|
|
2098
|
+
return { kind: "sdk", name };
|
|
2099
|
+
const value = module === undefined ? unknown : resolveExport(module, name, depth);
|
|
2100
|
+
if (value.kind === "defined")
|
|
2101
|
+
return value;
|
|
2102
|
+
const indexed = sdkSteps2.get(name);
|
|
2103
|
+
return indexed === undefined ? { kind: "sdk", name } : { kind: "indexed", name, step: indexed };
|
|
2104
|
+
};
|
|
2105
|
+
const sdkModule = (target) => target.path === undefined ? undefined : moduleAt(target.path);
|
|
2106
|
+
const resolveExport = (module, name, depth) => {
|
|
2107
|
+
if (depth > maxDepth)
|
|
2108
|
+
return unknown;
|
|
2109
|
+
if (module.sdk && sdkNames.has(name))
|
|
2110
|
+
return { kind: "sdk", name };
|
|
2111
|
+
const entry = module.exports.get(name);
|
|
2112
|
+
if (entry === undefined) {
|
|
2113
|
+
for (const target of module.stars) {
|
|
2114
|
+
if (target.kind === "sdk")
|
|
2115
|
+
return sdkExport(sdkModule(target), name, depth + 1);
|
|
2116
|
+
if (target.kind !== "file")
|
|
2117
|
+
continue;
|
|
2118
|
+
const starred = moduleAt(target.path);
|
|
2119
|
+
const value = starred === undefined ? unknown : resolveExport(starred, name, depth + 1);
|
|
2120
|
+
if (value.kind !== "unknown")
|
|
2121
|
+
return value;
|
|
2122
|
+
}
|
|
2123
|
+
return unknown;
|
|
2124
|
+
}
|
|
2125
|
+
switch (entry.kind) {
|
|
2126
|
+
case "local": {
|
|
2127
|
+
const binding = lookup(module, entry.name, module.program);
|
|
2128
|
+
return binding === undefined ? unknown : valueOfBinding(binding, { module, frame: moduleFrame }, depth + 1);
|
|
2129
|
+
}
|
|
2130
|
+
case "default":
|
|
2131
|
+
if (entry.node.type === "FunctionDeclaration")
|
|
2132
|
+
return { kind: "fn", fn: entry.node, place: { module, frame: moduleFrame } };
|
|
2133
|
+
if (entry.node.type === "ClassDeclaration")
|
|
2134
|
+
return { kind: "class", node: entry.node, module };
|
|
2135
|
+
return resolveValue(entry.node, { module, frame: moduleFrame }, depth + 1);
|
|
2136
|
+
case "reexport":
|
|
2137
|
+
return importedValue(entry.target, entry.imported, depth + 1);
|
|
2138
|
+
}
|
|
2139
|
+
};
|
|
2140
|
+
const importedValue = (target, imported, depth) => {
|
|
2141
|
+
if (target.kind === "sdk")
|
|
2142
|
+
return sdkExport(sdkModule(target), imported, depth);
|
|
2143
|
+
if (target.kind === "external")
|
|
2144
|
+
return { kind: "external", specifier: target.specifier, path: imported === "*" ? [] : [imported] };
|
|
2145
|
+
const module = moduleAt(target.path);
|
|
2146
|
+
if (module === undefined)
|
|
2147
|
+
return unknown;
|
|
2148
|
+
return imported === "*" ? { kind: "namespace", module } : resolveExport(module, imported, depth);
|
|
2149
|
+
};
|
|
2150
|
+
const argumentOf = (binding, frame) => {
|
|
2151
|
+
const bound = frameOf(frame, binding.fn);
|
|
2152
|
+
if (bound?.caller === undefined)
|
|
2153
|
+
return;
|
|
2154
|
+
const spread = bound.args.slice(0, binding.index + 1).some((arg) => arg.type === "SpreadElement");
|
|
2155
|
+
if (spread)
|
|
2156
|
+
return;
|
|
2157
|
+
const arg = bound.args[binding.index];
|
|
2158
|
+
if (arg !== undefined)
|
|
2159
|
+
return { node: arg, place: bound.caller };
|
|
2160
|
+
return binding.fallback === undefined ? undefined : { node: binding.fallback, place: { module: binding.module, frame: bound } };
|
|
2161
|
+
};
|
|
2162
|
+
const valueOfBinding = (binding, place, depth) => {
|
|
2163
|
+
switch (binding.kind) {
|
|
2164
|
+
case "import":
|
|
2165
|
+
return importedValue(binding.target, binding.imported, depth);
|
|
2166
|
+
case "declarator":
|
|
2167
|
+
return binding.declarator.init === null ? unknown : resolveValue(binding.declarator.init, { module: binding.module, frame: frameFor(binding.module, binding.declarator, place.frame) }, depth + 1);
|
|
2168
|
+
case "function":
|
|
2169
|
+
return {
|
|
2170
|
+
kind: "fn",
|
|
2171
|
+
fn: binding.node,
|
|
2172
|
+
place: { module: binding.module, frame: frameFor(binding.module, binding.node, place.frame) }
|
|
2173
|
+
};
|
|
2174
|
+
case "class":
|
|
2175
|
+
return { kind: "class", node: binding.node, module: binding.module };
|
|
2176
|
+
case "param": {
|
|
2177
|
+
const arg = argumentOf(binding, place.frame);
|
|
2178
|
+
if (arg === undefined)
|
|
2179
|
+
return unknown;
|
|
2180
|
+
let value = resolveValue(arg.node, arg.place, depth + 1);
|
|
2181
|
+
for (const key of binding.path)
|
|
2182
|
+
value = memberOf(value, key, depth + 1);
|
|
2183
|
+
return value;
|
|
2184
|
+
}
|
|
2185
|
+
default:
|
|
2186
|
+
return unknown;
|
|
2187
|
+
}
|
|
2188
|
+
};
|
|
2189
|
+
const propertyOf = (value, key, depth) => {
|
|
2190
|
+
if (value.kind !== "node" || depth > maxDepth)
|
|
2191
|
+
return;
|
|
2192
|
+
const object = unwrap(value.node);
|
|
2193
|
+
if (object.type !== "ObjectExpression")
|
|
2194
|
+
return;
|
|
2195
|
+
for (const property of object.properties.toReversed()) {
|
|
2196
|
+
if (property.type === "SpreadElement") {
|
|
2197
|
+
const found = propertyOf(resolveValue(property.argument, value.place, depth + 1), key, depth + 1);
|
|
2198
|
+
if (found !== undefined)
|
|
2199
|
+
return found;
|
|
2200
|
+
continue;
|
|
2201
|
+
}
|
|
2202
|
+
if (keyName(property.key, property.computed) === key)
|
|
2203
|
+
return { node: property.value, place: value.place };
|
|
2204
|
+
}
|
|
2205
|
+
return;
|
|
2206
|
+
};
|
|
2207
|
+
const memberOf = (value, key, depth) => {
|
|
2208
|
+
switch (value.kind) {
|
|
2209
|
+
case "sdk":
|
|
2210
|
+
return value.name === "*" ? sdkExport(value.module, key, depth + 1) : { kind: "service" };
|
|
2211
|
+
case "external":
|
|
2212
|
+
return { ...value, path: [...value.path, key] };
|
|
2213
|
+
case "namespace":
|
|
2214
|
+
return resolveExport(value.module, key, depth + 1);
|
|
2215
|
+
case "service":
|
|
2216
|
+
return { kind: "service" };
|
|
2217
|
+
case "node": {
|
|
2218
|
+
const found = propertyOf(value, key, depth);
|
|
2219
|
+
return found === undefined ? unknown : resolveValue(found.node, found.place, depth + 1);
|
|
2220
|
+
}
|
|
2221
|
+
default:
|
|
2222
|
+
return unknown;
|
|
2223
|
+
}
|
|
2224
|
+
};
|
|
2225
|
+
const resolveValue = (raw, place, depth = 0) => {
|
|
2226
|
+
if (depth > maxDepth)
|
|
2227
|
+
return unknown;
|
|
2228
|
+
const node = unwrap(raw);
|
|
2229
|
+
switch (node.type) {
|
|
2230
|
+
case "Identifier": {
|
|
2231
|
+
if (node.name === "undefined")
|
|
2232
|
+
return { kind: "node", node, place };
|
|
2233
|
+
const binding = lookup(place.module, node.name, node);
|
|
2234
|
+
return binding === undefined ? unknown : valueOfBinding(binding, place, depth);
|
|
2235
|
+
}
|
|
2236
|
+
case "MemberExpression": {
|
|
2237
|
+
const key = memberName(node);
|
|
2238
|
+
return key === undefined ? unknown : memberOf(resolveValue(node.object, place, depth + 1), key, depth);
|
|
2239
|
+
}
|
|
2240
|
+
case "CallExpression": {
|
|
2241
|
+
const callee = resolveValue(node.callee, place, depth + 1);
|
|
2242
|
+
switch (callee.kind) {
|
|
2243
|
+
case "sdk": {
|
|
2244
|
+
const first = node.arguments[0];
|
|
2245
|
+
if (callee.name === sdkForms.agent)
|
|
2246
|
+
return { kind: "agent", role: literalName(first, place) };
|
|
2247
|
+
if (callee.name === sdkForms.step)
|
|
2248
|
+
return {
|
|
2249
|
+
kind: "defined",
|
|
2250
|
+
call: node,
|
|
2251
|
+
place,
|
|
2252
|
+
name: literalName(first, place) ?? (first === undefined ? "${\u2026}" : textOf(place.module, first)),
|
|
2253
|
+
names: namesOf(first, place)
|
|
2254
|
+
};
|
|
2255
|
+
if ((callee.name === sdkForms.defineLoop || callee.name === sdkForms.defineKit) && first !== undefined)
|
|
2256
|
+
return resolveValue(first, place, depth + 1);
|
|
2257
|
+
return { kind: "service" };
|
|
2258
|
+
}
|
|
2259
|
+
case "external":
|
|
2260
|
+
return { ...callee, path: [...callee.path, "()"] };
|
|
2261
|
+
case "fn": {
|
|
2262
|
+
const frame = callFrame(callee, node, place);
|
|
2263
|
+
for (const returned of returnsOf(callee.fn)) {
|
|
2264
|
+
const value = resolveValue(returned, { module: callee.place.module, frame }, depth + 1);
|
|
2265
|
+
if (value.kind !== "unknown")
|
|
2266
|
+
return value;
|
|
2267
|
+
}
|
|
2268
|
+
return unknown;
|
|
2269
|
+
}
|
|
2270
|
+
default:
|
|
2271
|
+
return unknown;
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
case "ArrowFunctionExpression":
|
|
2275
|
+
case "FunctionExpression":
|
|
2276
|
+
return { kind: "fn", fn: node, place };
|
|
2277
|
+
case "ClassExpression":
|
|
2278
|
+
return { kind: "class", node, module: place.module };
|
|
2279
|
+
case "YieldExpression": {
|
|
2280
|
+
if (!node.delegate || node.argument === null)
|
|
2281
|
+
return unknown;
|
|
2282
|
+
const yielded = resolveValue(node.argument, place, depth + 1);
|
|
2283
|
+
return yielded.kind === "class" || yielded.kind === "sdk" && !lentSteps.has(yielded.name) ? { kind: "service" } : unknown;
|
|
2284
|
+
}
|
|
2285
|
+
default:
|
|
2286
|
+
return { kind: "node", node, place };
|
|
2287
|
+
}
|
|
2288
|
+
};
|
|
2289
|
+
const definitionsOf = (identifier, place, depth) => {
|
|
2290
|
+
if (identifier.type !== "Identifier")
|
|
2291
|
+
return;
|
|
2292
|
+
const binding = lookup(place.module, identifier.name, identifier);
|
|
2293
|
+
switch (binding?.kind) {
|
|
2294
|
+
case "declarator": {
|
|
2295
|
+
const at = { module: binding.module, frame: frameFor(binding.module, binding.declarator, place.frame) };
|
|
2296
|
+
return [
|
|
2297
|
+
...binding.declarator.init === null ? [] : [{ node: binding.declarator.init, place: at }],
|
|
2298
|
+
...assignmentsOf(binding.module, binding.declarator).map((node) => ({
|
|
2299
|
+
node,
|
|
2300
|
+
place: { module: binding.module, frame: frameFor(binding.module, node, place.frame) }
|
|
2301
|
+
}))
|
|
2302
|
+
];
|
|
2303
|
+
}
|
|
2304
|
+
case "param": {
|
|
2305
|
+
const arg = argumentOf(binding, place.frame);
|
|
2306
|
+
if (arg === undefined)
|
|
2307
|
+
return;
|
|
2308
|
+
if (binding.path.length === 0)
|
|
2309
|
+
return [arg];
|
|
2310
|
+
let found = arg;
|
|
2311
|
+
for (const key of binding.path)
|
|
2312
|
+
found = found === undefined ? undefined : propertyOf(resolveValue(found.node, found.place, depth + 1), key, depth + 1);
|
|
2313
|
+
return found === undefined ? undefined : [found];
|
|
2314
|
+
}
|
|
2315
|
+
case "import": {
|
|
2316
|
+
const value = valueOfBinding(binding, place, depth + 1);
|
|
2317
|
+
return value.kind === "node" ? [{ node: value.node, place: value.place }] : undefined;
|
|
2318
|
+
}
|
|
2319
|
+
default:
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
};
|
|
2323
|
+
const patternsOf = (raw, place, depth = 0) => {
|
|
2324
|
+
if (depth > maxDepth)
|
|
2325
|
+
return;
|
|
2326
|
+
const node = unwrap(raw);
|
|
2327
|
+
const literal = stringLiteral(node);
|
|
2328
|
+
if (literal !== undefined)
|
|
2329
|
+
return [literal];
|
|
2330
|
+
const asWritten = (part) => [`\${${textOf(place.module, part)}}`];
|
|
2331
|
+
const orRaw = (part) => patternsOf(part, place, depth + 1) ?? asWritten(part);
|
|
2332
|
+
const capped = (names) => {
|
|
2333
|
+
const distinct = dedupe(names);
|
|
2334
|
+
return distinct.length > maxPatterns ? asWritten(node) : distinct;
|
|
2335
|
+
};
|
|
2336
|
+
switch (node.type) {
|
|
2337
|
+
case "TemplateLiteral": {
|
|
2338
|
+
let combined = [node.quasis[0]?.value.raw ?? ""];
|
|
2339
|
+
node.expressions.forEach((part, index) => {
|
|
2340
|
+
const parts = orRaw(part);
|
|
2341
|
+
const tail = node.quasis[index + 1]?.value.raw ?? "";
|
|
2342
|
+
const chosen = combined.length * parts.length > maxPatterns ? asWritten(part) : parts;
|
|
2343
|
+
combined = combined.flatMap((head) => chosen.map((middle) => `${head}${middle}${tail}`));
|
|
2344
|
+
});
|
|
2345
|
+
return combined;
|
|
2346
|
+
}
|
|
2347
|
+
case "ConditionalExpression":
|
|
2348
|
+
return capped([...orRaw(node.consequent), ...orRaw(node.alternate)]);
|
|
2349
|
+
case "LogicalExpression":
|
|
2350
|
+
return node.operator === "&&" ? patternsOf(node.right, place, depth + 1) : capped([...orRaw(node.left), ...orRaw(node.right)]);
|
|
2351
|
+
case "BinaryExpression": {
|
|
2352
|
+
if (node.operator !== "+")
|
|
2353
|
+
return;
|
|
2354
|
+
const left = patternsOf(node.left, place, depth + 1);
|
|
2355
|
+
const right = patternsOf(node.right, place, depth + 1);
|
|
2356
|
+
if (left === undefined && right === undefined)
|
|
2357
|
+
return;
|
|
2358
|
+
return capped((left ?? orRaw(node.left)).flatMap((head) => (right ?? orRaw(node.right)).map((tail) => `${head}${tail}`)));
|
|
2359
|
+
}
|
|
2360
|
+
case "Identifier": {
|
|
2361
|
+
const definitions = definitionsOf(node, place, depth);
|
|
2362
|
+
if (definitions === undefined || definitions.length === 0)
|
|
2363
|
+
return;
|
|
2364
|
+
const all = definitions.map((definition) => patternsOf(definition.node, definition.place, depth + 1));
|
|
2365
|
+
return all.some((patterns) => patterns === undefined) ? undefined : capped(all.flatMap((patterns) => patterns ?? []));
|
|
2366
|
+
}
|
|
2367
|
+
case "CallExpression": {
|
|
2368
|
+
const callee = resolveValue(node.callee, place, depth + 1);
|
|
2369
|
+
if (callee.kind !== "fn")
|
|
2370
|
+
return;
|
|
2371
|
+
const frame = callFrame(callee, node, place);
|
|
2372
|
+
const all = returnsOf(callee.fn).map((returned) => patternsOf(returned, { module: callee.place.module, frame }, depth + 1));
|
|
2373
|
+
return all.length === 0 || all.some((patterns) => patterns === undefined) ? undefined : capped(all.flatMap((patterns) => patterns ?? []));
|
|
2374
|
+
}
|
|
2375
|
+
default:
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2378
|
+
};
|
|
2379
|
+
const namesOf = (node, place) => node === undefined ? ["${\u2026}"] : patternsOf(node, place) ?? [`\${${textOf(place.module, node)}}`];
|
|
2380
|
+
const literalName = (node, place) => {
|
|
2381
|
+
const names = node === undefined ? undefined : patternsOf(node, place);
|
|
2382
|
+
return names?.length === 1 && names[0] !== undefined && !names[0].includes("${") ? names[0] : undefined;
|
|
2383
|
+
};
|
|
2384
|
+
const classTag = (node) => {
|
|
2385
|
+
for (let at = node.superClass;at?.type === "CallExpression"; at = unwrap(at.callee)) {
|
|
2386
|
+
const tag = stringLiteral(at.arguments[0]);
|
|
2387
|
+
if (tag !== undefined)
|
|
2388
|
+
return tag;
|
|
2389
|
+
}
|
|
2390
|
+
return node.id?.name;
|
|
2391
|
+
};
|
|
2392
|
+
const tagOf = (node, place) => {
|
|
2393
|
+
const at = unwrap(node);
|
|
2394
|
+
if (at.type !== "NewExpression")
|
|
2395
|
+
return;
|
|
2396
|
+
const made = resolveValue(at.callee, place);
|
|
2397
|
+
if (made.kind === "class")
|
|
2398
|
+
return classTag(made.node);
|
|
2399
|
+
if (made.kind === "sdk")
|
|
2400
|
+
return made.name;
|
|
2401
|
+
if (made.kind === "external")
|
|
2402
|
+
return made.path.at(-1);
|
|
2403
|
+
return textOf(place.module, at.callee);
|
|
2404
|
+
};
|
|
2405
|
+
const goesOn2 = (node, place, depth) => {
|
|
2406
|
+
switch (node?.type) {
|
|
2407
|
+
case "ReturnStatement":
|
|
2408
|
+
case "ThrowStatement":
|
|
2409
|
+
case "ContinueStatement":
|
|
2410
|
+
return false;
|
|
2411
|
+
case "BlockStatement":
|
|
2412
|
+
return node.body.toReversed().every((statement) => goesOn2(statement, place, depth));
|
|
2413
|
+
case "IfStatement":
|
|
2414
|
+
return node.alternate === null || goesOn2(node.consequent, place, depth) || goesOn2(node.alternate, place, depth);
|
|
2415
|
+
case "SwitchStatement":
|
|
2416
|
+
return node.cases.length === 0 || node.cases.some((branch) => branch.consequent.some(breaksOut)) || !node.cases.at(-1)?.consequent.some((statement) => !goesOn2(statement, place, depth));
|
|
2417
|
+
case "TryStatement":
|
|
2418
|
+
return (node.finalizer === null || goesOn2(node.finalizer, place, depth)) && (goesOn2(node.block, place, depth) || node.handler !== null && goesOn2(node.handler.body, place, depth));
|
|
2419
|
+
case "WhileStatement":
|
|
2420
|
+
case "DoWhileStatement":
|
|
2421
|
+
return !(node.test.type === "Literal" && node.test.value === true) || breaksOut(node.body);
|
|
2422
|
+
case "ForStatement":
|
|
2423
|
+
return node.test !== null || breaksOut(node.body);
|
|
2424
|
+
case "ExpressionStatement": {
|
|
2425
|
+
if (node.expression.type !== "YieldExpression")
|
|
2426
|
+
return true;
|
|
2427
|
+
const { values, unknown: unresolved } = resultsOf(node.expression, place, depth + 1);
|
|
2428
|
+
return unresolved || values.length > 0;
|
|
2429
|
+
}
|
|
2430
|
+
default:
|
|
2431
|
+
return true;
|
|
2432
|
+
}
|
|
2433
|
+
};
|
|
2434
|
+
const returnedResults = (fn, place, depth, seen = new Set) => {
|
|
2435
|
+
const returned = union(returnsOf(fn).map((node) => resultsOf(node, place, depth + 1, seen)));
|
|
2436
|
+
return returnsNothing(fn) || endsWithout(fn, place, depth) ? union([returned, emptyResults]) : returned;
|
|
2437
|
+
};
|
|
2438
|
+
const endsWithout = (fn, place, depth) => {
|
|
2439
|
+
if (fn.body?.type !== "BlockStatement")
|
|
2440
|
+
return false;
|
|
2441
|
+
if (endingNow.has(fn))
|
|
2442
|
+
return true;
|
|
2443
|
+
endingNow.add(fn);
|
|
2444
|
+
const ends = goesOn2(fn.body, place, depth + 1);
|
|
2445
|
+
endingNow.delete(fn);
|
|
2446
|
+
return ends;
|
|
2447
|
+
};
|
|
2448
|
+
const callbackReturns = (raw, place, depth) => {
|
|
2449
|
+
if (raw === undefined)
|
|
2450
|
+
return unknownResults;
|
|
2451
|
+
const callback = resolveValue(raw, place, depth + 1);
|
|
2452
|
+
if (callback.kind !== "fn")
|
|
2453
|
+
return resultsOf(raw, place, depth + 1);
|
|
2454
|
+
return returnedResults(callback.fn, { module: callback.place.module, frame: unboundFrame(callback) }, depth);
|
|
2455
|
+
};
|
|
2456
|
+
const effectResults = (name, call, place, depth) => {
|
|
2457
|
+
const [first, second] = call.arguments;
|
|
2458
|
+
if (name === "succeed")
|
|
2459
|
+
return first === undefined ? emptyResults : resultsOf(first, place, depth + 1);
|
|
2460
|
+
if (name === "gen")
|
|
2461
|
+
return callbackReturns(call.arguments.at(-1), place, depth);
|
|
2462
|
+
if (name === "fail" || name === "die" || name === "dieMessage")
|
|
2463
|
+
return noResults;
|
|
2464
|
+
if ((name === "map" || effectMethods.chains.has(name)) && second !== undefined && first !== undefined)
|
|
2465
|
+
return callbackReturns(second, place, depth);
|
|
2466
|
+
return unknownResults;
|
|
2467
|
+
};
|
|
2468
|
+
const pipeResults = (call, object, place, depth) => {
|
|
2469
|
+
let results = resultsOf(object, place, depth + 1);
|
|
2470
|
+
for (const raw of call.arguments) {
|
|
2471
|
+
const op = unwrap(raw);
|
|
2472
|
+
if (op.type !== "CallExpression")
|
|
2473
|
+
continue;
|
|
2474
|
+
const name = effectName(resolveValue(op.callee, place, depth + 1));
|
|
2475
|
+
if (name === undefined)
|
|
2476
|
+
continue;
|
|
2477
|
+
if (name === "map" || name === "flatMap" || name === "andThen")
|
|
2478
|
+
results = callbackReturns(op.arguments[0], place, depth);
|
|
2479
|
+
else if (name === "catchTag")
|
|
2480
|
+
results = union([results, callbackReturns(op.arguments.at(-1), place, depth)]);
|
|
2481
|
+
else if (name === "catchTags") {
|
|
2482
|
+
const handlers = unwrap(op.arguments[0] ?? op);
|
|
2483
|
+
if (handlers.type === "ObjectExpression")
|
|
2484
|
+
results = union([
|
|
2485
|
+
results,
|
|
2486
|
+
...handlers.properties.map((property) => property.type === "Property" ? callbackReturns(property.value, place, depth) : unknownResults)
|
|
2487
|
+
]);
|
|
2488
|
+
} else if (effectMethods.catches.has(name))
|
|
2489
|
+
results = union([results, callbackReturns(op.arguments.at(-1), place, depth)]);
|
|
2490
|
+
}
|
|
2491
|
+
return results;
|
|
2492
|
+
};
|
|
2493
|
+
const externalResults = (value) => {
|
|
2494
|
+
switch (effectName(value)) {
|
|
2495
|
+
case "void":
|
|
2496
|
+
case "undefined":
|
|
2497
|
+
return emptyResults;
|
|
2498
|
+
case "never":
|
|
2499
|
+
case "interrupt":
|
|
2500
|
+
return noResults;
|
|
2501
|
+
default:
|
|
2502
|
+
return unknownResults;
|
|
2503
|
+
}
|
|
2504
|
+
};
|
|
2505
|
+
const resultsOf = (raw, place, depth = 0, seen = new Set) => {
|
|
2506
|
+
if (depth > maxDepth || seen.has(raw))
|
|
2507
|
+
return unknownResults;
|
|
2508
|
+
const node = unwrap(raw);
|
|
2509
|
+
const next = new Set(seen).add(raw);
|
|
2510
|
+
const literal = stringLiteral(node);
|
|
2511
|
+
if (literal !== undefined)
|
|
2512
|
+
return { values: [{ kind: "string", value: literal }], unknown: false };
|
|
2513
|
+
switch (node.type) {
|
|
2514
|
+
case "TemplateLiteral":
|
|
2515
|
+
return { values: (patternsOf(node, place) ?? []).map((value) => ({ kind: "string", value })), unknown: false };
|
|
2516
|
+
case "Literal":
|
|
2517
|
+
return node.raw === "null" ? emptyResults : unknownResults;
|
|
2518
|
+
case "ObjectExpression":
|
|
2519
|
+
return { values: [{ kind: "object", node, place }], unknown: false };
|
|
2520
|
+
case "ConditionalExpression":
|
|
2521
|
+
return union([
|
|
2522
|
+
resultsOf(node.consequent, place, depth + 1, next),
|
|
2523
|
+
resultsOf(node.alternate, place, depth + 1, next)
|
|
2524
|
+
]);
|
|
2525
|
+
case "LogicalExpression":
|
|
2526
|
+
return node.operator === "&&" ? union([emptyResults, resultsOf(node.right, place, depth + 1, next)]) : union([
|
|
2527
|
+
notEmpty(resultsOf(node.left, place, depth + 1, next)),
|
|
2528
|
+
resultsOf(node.right, place, depth + 1, next)
|
|
2529
|
+
]);
|
|
2530
|
+
case "NewExpression": {
|
|
2531
|
+
const tag = tagOf(node, place);
|
|
2532
|
+
return tag === undefined ? unknownResults : { values: [{ kind: "tag", tag }], unknown: false };
|
|
2533
|
+
}
|
|
2534
|
+
case "YieldExpression":
|
|
2535
|
+
if (node.delegate && node.argument !== null && unwrap(node.argument).type === "NewExpression")
|
|
2536
|
+
return noResults;
|
|
2537
|
+
return node.argument === null ? unknownResults : resultsOf(node.argument, place, depth + 1, next);
|
|
2538
|
+
case "AwaitExpression":
|
|
2539
|
+
return node.argument === null ? unknownResults : resultsOf(node.argument, place, depth + 1, next);
|
|
2540
|
+
case "Identifier": {
|
|
2541
|
+
if (node.name === "undefined")
|
|
2542
|
+
return emptyResults;
|
|
2543
|
+
const definitions = definitionsOf(node, place, depth);
|
|
2544
|
+
if (definitions === undefined)
|
|
2545
|
+
return unknownResults;
|
|
2546
|
+
const held = union(definitions.map((definition) => resultsOf(definition.node, definition.place, depth + 1, next)));
|
|
2547
|
+
return isChecked(place.module, node) ? checked(held) : held;
|
|
2548
|
+
}
|
|
2549
|
+
case "CallExpression": {
|
|
2550
|
+
const callee = unwrap(node.callee);
|
|
2551
|
+
if (callee.type === "MemberExpression" && memberName(callee) === "pipe")
|
|
2552
|
+
return pipeResults(node, callee.object, place, depth);
|
|
2553
|
+
const value = resolveValue(callee, place, depth + 1);
|
|
2554
|
+
const name = effectName(value);
|
|
2555
|
+
if (name !== undefined)
|
|
2556
|
+
return effectResults(name, node, place, depth);
|
|
2557
|
+
if (value.kind !== "fn")
|
|
2558
|
+
return unknownResults;
|
|
2559
|
+
const frame = callFrame(value, node, place);
|
|
2560
|
+
return returnedResults(value.fn, { module: value.place.module, frame }, depth, next);
|
|
2561
|
+
}
|
|
2562
|
+
case "MemberExpression": {
|
|
2563
|
+
const value = resolveValue(node, place, depth + 1);
|
|
2564
|
+
if (value.kind === "external")
|
|
2565
|
+
return externalResults(value);
|
|
2566
|
+
const key = memberName(node);
|
|
2567
|
+
const objects = resultsOf(node.object, place, depth + 1, next);
|
|
2568
|
+
const read = union([
|
|
2569
|
+
{ values: [], unknown: objects.unknown },
|
|
2570
|
+
...objects.values.map((object) => {
|
|
2571
|
+
if (isEmpty(object))
|
|
2572
|
+
return isOptional(node) ? { values: [object], unknown: false } : noResults;
|
|
2573
|
+
if (object.kind !== "object")
|
|
2574
|
+
return unknownResults;
|
|
2575
|
+
if (key !== undefined) {
|
|
2576
|
+
const found = propertyOf({ kind: "node", node: object.node, place: object.place }, key, depth + 1);
|
|
2577
|
+
return found === undefined ? unknownResults : resultsOf(found.node, found.place, depth + 1, next);
|
|
2578
|
+
}
|
|
2579
|
+
return union(object.node.properties.map((property) => property.type === "Property" ? resultsOf(property.value, object.place, depth + 1, next) : unknownResults));
|
|
2580
|
+
})
|
|
2581
|
+
]);
|
|
2582
|
+
return isChecked(place.module, node) ? checked(read) : read;
|
|
2583
|
+
}
|
|
2584
|
+
default:
|
|
2585
|
+
return unknownResults;
|
|
2586
|
+
}
|
|
2587
|
+
};
|
|
2588
|
+
const holdsNothing = {
|
|
2589
|
+
calls: new Set,
|
|
2590
|
+
direct: new Set,
|
|
2591
|
+
names: new Set,
|
|
2592
|
+
other: false,
|
|
2593
|
+
orElse: false,
|
|
2594
|
+
unresolved: false
|
|
2595
|
+
};
|
|
2596
|
+
const holdsOther = { ...holdsNothing, other: true };
|
|
2597
|
+
const holdsUnresolved = { ...holdsNothing, unresolved: true };
|
|
2598
|
+
const holdsAny = (all) => ({
|
|
2599
|
+
calls: new Set(all.flatMap((held) => [...held.calls])),
|
|
2600
|
+
direct: new Set(all.flatMap((held) => [...held.direct])),
|
|
2601
|
+
names: new Set(all.flatMap((held) => [...held.names])),
|
|
2602
|
+
other: all.some((held) => held.other),
|
|
2603
|
+
orElse: all.some((held) => held.orElse),
|
|
2604
|
+
unresolved: all.some((held) => held.unresolved)
|
|
2605
|
+
});
|
|
2606
|
+
const holdingNow = new Set;
|
|
2607
|
+
const holdsOrElse = (held, others) => {
|
|
2608
|
+
const all = holdsAny([held, ...others]);
|
|
2609
|
+
return held.calls.size === 0 ? all : {
|
|
2610
|
+
...all,
|
|
2611
|
+
other: held.other,
|
|
2612
|
+
unresolved: held.unresolved,
|
|
2613
|
+
orElse: all.orElse || others.some(({ other, unresolved }) => other || unresolved)
|
|
2614
|
+
};
|
|
2615
|
+
};
|
|
2616
|
+
const maxHeld = 500;
|
|
2617
|
+
let heldLeft = 0;
|
|
2618
|
+
const holding = (raw, place) => {
|
|
2619
|
+
heldLeft = maxHeld;
|
|
2620
|
+
return heldBy(raw, place, 0);
|
|
2621
|
+
};
|
|
2622
|
+
const holdsWinner = ({ calls, other, unresolved }) => calls.size > 0 && !other && !unresolved;
|
|
2623
|
+
const bindingName = (name, module, node) => `${name}@${located(module, node)}`;
|
|
2624
|
+
const nameOfBinding = (binding, name) => bindingName(name, binding.module, binding.declarator);
|
|
2625
|
+
const nameFirsts = (nodes, target, value, place, name = target.type === "Identifier" ? target.name : "") => {
|
|
2626
|
+
const binding = lookup(place.module, name, target);
|
|
2627
|
+
const held = holding(value, place);
|
|
2628
|
+
if (binding?.kind !== "declarator" && binding?.kind !== "destructured" || !holdsWinner(held))
|
|
2629
|
+
return [...nodes];
|
|
2630
|
+
const as = nameOfBinding(binding, name);
|
|
2631
|
+
const named = (inner) => inner.map((node) => {
|
|
2632
|
+
const call = calledFirst.get(node);
|
|
2633
|
+
return node.kind === "first" && call !== undefined && held.direct.has(call) ? copiedFirst(node, { ...node, as: dedupe([...node.as ?? [], as]) }) : mapChildren(node, named);
|
|
2634
|
+
});
|
|
2635
|
+
const holdsGiven = (node) => holdsNamed(node, as) || [...held.names].some((name) => holdsNamed(node, name));
|
|
2636
|
+
const given = (node) => {
|
|
2637
|
+
if (node.kind !== "branch" || !holdsGiven(node))
|
|
2638
|
+
return [];
|
|
2639
|
+
if (node.nodes !== undefined)
|
|
2640
|
+
return [...held.names, ...held.direct.size > 0 ? [as] : []];
|
|
2641
|
+
return held.names.has(as) ? [] : [as];
|
|
2642
|
+
};
|
|
2643
|
+
return named(nodes).map((node) => {
|
|
2644
|
+
const names = given(node);
|
|
2645
|
+
return names.length === 0 || node.kind !== "branch" ? node : { ...node, gives: dedupe([...node.gives ?? [], ...names]) };
|
|
2646
|
+
});
|
|
2647
|
+
};
|
|
2648
|
+
const holdsNamed = (node, as) => node.kind === "first" && node.as?.includes(as) === true || childLists(node).some((list) => list.some((inner) => holdsNamed(inner, as)));
|
|
2649
|
+
const boundEachRound = (body, module) => {
|
|
2650
|
+
const found = [];
|
|
2651
|
+
const pending = [body];
|
|
2652
|
+
for (let node = pending.pop();node !== undefined; node = pending.pop()) {
|
|
2653
|
+
if (node.type === "VariableDeclarator")
|
|
2654
|
+
for (const { name } of patternNames(node.id))
|
|
2655
|
+
found.push(bindingName(name, module, node));
|
|
2656
|
+
for (const child of childrenOf(node))
|
|
2657
|
+
if (!isFunction(child))
|
|
2658
|
+
pending.push(child);
|
|
2659
|
+
}
|
|
2660
|
+
for (const statement of body.type === "BlockStatement" ? body.body : [body]) {
|
|
2661
|
+
const written = statement.type === "ExpressionStatement" ? unwrap(statement.expression) : undefined;
|
|
2662
|
+
if (written?.type !== "AssignmentExpression" || written.left.type !== "Identifier")
|
|
2663
|
+
continue;
|
|
2664
|
+
const binding = lookup(module, written.left.name, written.left);
|
|
2665
|
+
if (binding?.kind === "declarator")
|
|
2666
|
+
found.push(nameOfBinding(binding, written.left.name));
|
|
2667
|
+
}
|
|
2668
|
+
return found;
|
|
2669
|
+
};
|
|
2670
|
+
const testedIn = (conditions, place) => {
|
|
2671
|
+
const tested = new Map;
|
|
2672
|
+
const pending = [...conditions];
|
|
2673
|
+
for (let node = pending.pop();node !== undefined; node = pending.pop()) {
|
|
2674
|
+
const object = node.type === "MemberExpression" && memberName(node) === "_tag" ? unwrap(node.object) : undefined;
|
|
2675
|
+
const isTag = node.type === "Identifier" && node.name === "_tag";
|
|
2676
|
+
const subject = object?.type === "Identifier" ? object : isTag ? node : undefined;
|
|
2677
|
+
if (subject?.type === "Identifier") {
|
|
2678
|
+
const held = holding(subject, place);
|
|
2679
|
+
const before = tested.get(subject.name);
|
|
2680
|
+
tested.set(subject.name, before === undefined ? held : holdsAny([before, held]));
|
|
2681
|
+
}
|
|
2682
|
+
for (const child of childrenOf(node))
|
|
2683
|
+
if (node.type !== "MemberExpression" || node.computed || child !== node.property)
|
|
2684
|
+
pending.push(child);
|
|
2685
|
+
}
|
|
2686
|
+
const read = [...tested].filter(([, { unresolved }]) => !unresolved);
|
|
2687
|
+
const orElse = read.flatMap(([name, held]) => held.orElse && holdsWinner(held) ? [name] : []);
|
|
2688
|
+
return read.length === 0 ? undefined : {
|
|
2689
|
+
tested: Object.fromEntries(read.map(([name, held]) => [name, holdsWinner(held) ? [...held.names] : []])),
|
|
2690
|
+
...orElse.length === 0 ? undefined : { orElse }
|
|
2691
|
+
};
|
|
2692
|
+
};
|
|
2693
|
+
const heldBy = (raw, place, depth) => {
|
|
2694
|
+
heldLeft -= 1;
|
|
2695
|
+
if (depth > maxDepth || heldLeft < 0)
|
|
2696
|
+
return holdsOther;
|
|
2697
|
+
const node = unwrap(raw);
|
|
2698
|
+
switch (node.type) {
|
|
2699
|
+
case "YieldExpression":
|
|
2700
|
+
case "AwaitExpression":
|
|
2701
|
+
return node.argument === null || unwrap(node.argument).type === "NewExpression" ? holdsNothing : heldByRunning(heldBy(node.argument, place, depth + 1));
|
|
2702
|
+
case "Literal":
|
|
2703
|
+
return holdsNothing;
|
|
2704
|
+
case "ConditionalExpression":
|
|
2705
|
+
return holdsAny([heldBy(node.consequent, place, depth + 1), heldBy(node.alternate, place, depth + 1)]);
|
|
2706
|
+
case "LogicalExpression":
|
|
2707
|
+
return node.operator === "&&" ? heldBy(node.right, place, depth + 1) : holdsOrElse(heldBy(node.left, place, depth + 1), [heldBy(node.right, place, depth + 1)]);
|
|
2708
|
+
case "ObjectExpression": {
|
|
2709
|
+
const tagged = node.properties.findLast((property) => property.type === "SpreadElement" || [undefined, "_tag"].includes(keyName(property.key, property.computed)));
|
|
2710
|
+
return tagged?.type === "SpreadElement" ? heldBy(tagged.argument, place, depth + 1) : holdsOther;
|
|
2711
|
+
}
|
|
2712
|
+
case "AssignmentExpression":
|
|
2713
|
+
return node.operator === "=" ? heldBy(node.right, place, depth + 1) : holdsOther;
|
|
2714
|
+
case "Identifier":
|
|
2715
|
+
return node.name === "undefined" ? holdsNothing : heldByName(node, place, depth + 1);
|
|
2716
|
+
case "MemberExpression":
|
|
2717
|
+
return ["void", "undefined", "never"].includes(effectName(resolveValue(node, place)) ?? "") ? holdsNothing : holdsOther;
|
|
2718
|
+
case "CallExpression":
|
|
2719
|
+
return heldByCall(node, place, depth);
|
|
2720
|
+
default:
|
|
2721
|
+
return holdsOther;
|
|
2722
|
+
}
|
|
2723
|
+
};
|
|
2724
|
+
const heldByRunning = (held) => ({ ...held, direct: held.calls });
|
|
2725
|
+
const heldByCall = (call, place, depth) => {
|
|
2726
|
+
const callee = unwrap(call.callee);
|
|
2727
|
+
const [first] = call.arguments;
|
|
2728
|
+
if (callee.type === "MemberExpression" && memberName(callee) === "pipe")
|
|
2729
|
+
return call.arguments.reduce((held, raw) => {
|
|
2730
|
+
const op = unwrap(raw);
|
|
2731
|
+
const isCall = op.type === "CallExpression";
|
|
2732
|
+
const name = effectName(resolveValue(isCall ? op.callee : op, place));
|
|
2733
|
+
return heldThrough(held, name, isCall ? op.arguments : [], place, depth);
|
|
2734
|
+
}, heldBy(callee.object, place, depth + 1));
|
|
2735
|
+
const value = resolveValue(callee, place);
|
|
2736
|
+
if (value.kind === "sdk" && value.name === sdkForms.first)
|
|
2737
|
+
return { ...holdsNothing, calls: new Set([call]), direct: new Set([call]) };
|
|
2738
|
+
if (value.kind === "fn")
|
|
2739
|
+
return heldByReturns(value.fn, { module: value.place.module, frame: callFrame(value, call, place) }, depth);
|
|
2740
|
+
const name = effectName(value);
|
|
2741
|
+
if (name === "gen")
|
|
2742
|
+
return heldByCallback(call.arguments.at(-1), place, depth);
|
|
2743
|
+
if (name === "suspend" || name === "sync")
|
|
2744
|
+
return heldByCallback(first, place, depth);
|
|
2745
|
+
if (name === "fail" || name === "die")
|
|
2746
|
+
return holdsNothing;
|
|
2747
|
+
if (name === "succeed")
|
|
2748
|
+
return first === undefined ? holdsNothing : heldBy(first, place, depth + 1);
|
|
2749
|
+
return first === undefined ? holdsOther : heldThrough(heldBy(first, place, depth + 1), name, call.arguments.slice(1), place, depth);
|
|
2750
|
+
};
|
|
2751
|
+
const heldThrough = (held, name, args, place, depth) => {
|
|
2752
|
+
if (name === undefined)
|
|
2753
|
+
return holdsOther;
|
|
2754
|
+
if (effectMethods.keeps.has(name))
|
|
2755
|
+
return held;
|
|
2756
|
+
if (name === "catchTags") {
|
|
2757
|
+
const handlers = args[0] === undefined ? undefined : unwrap(args[0]);
|
|
2758
|
+
return handlers?.type === "ObjectExpression" ? holdsOrElse(held, handlers.properties.map((property) => property.type === "Property" ? heldByCallback(property.value, place, depth) : holdsOther)) : holdsOther;
|
|
2759
|
+
}
|
|
2760
|
+
if (name === "catchTag" || name === "orElseSucceed" || effectMethods.catches.has(name))
|
|
2761
|
+
return holdsOrElse(held, [heldByCallback(args.at(-1), place, depth)]);
|
|
2762
|
+
if (effectMethods.matches.has(name) || effectMethods.effectMatches.has(name)) {
|
|
2763
|
+
const options = args[0] === undefined ? unknown : resolveValue(args[0], place);
|
|
2764
|
+
const onSuccess = propertyOf(options, "onSuccess", 0);
|
|
2765
|
+
const onFailure = propertyOf(options, "onFailure", 0);
|
|
2766
|
+
return onSuccess === undefined || onFailure === undefined ? holdsOther : holdsOrElse(heldByCallback(onSuccess.node, onSuccess.place, depth, held), [
|
|
2767
|
+
heldByCallback(onFailure.node, onFailure.place, depth)
|
|
2768
|
+
]);
|
|
2769
|
+
}
|
|
2770
|
+
if (name === "as")
|
|
2771
|
+
return args[0] === undefined ? holdsOther : heldBy(args[0], place, depth + 1);
|
|
2772
|
+
if (name === "asVoid")
|
|
2773
|
+
return holdsNothing;
|
|
2774
|
+
return ["map", "flatMap", "andThen", "zipRight"].includes(name) ? heldByCallback(args[0], place, depth, held) : holdsOther;
|
|
2775
|
+
};
|
|
2776
|
+
const givenTo = new Map;
|
|
2777
|
+
const heldByCallback = (raw, place, depth, given) => {
|
|
2778
|
+
if (raw === undefined)
|
|
2779
|
+
return holdsOther;
|
|
2780
|
+
const callback = resolveValue(raw, place);
|
|
2781
|
+
if (callback.kind !== "fn")
|
|
2782
|
+
return given !== undefined && effectName(callback) === "succeed" ? given : heldBy(raw, place, depth + 1);
|
|
2783
|
+
if (given === undefined || givenTo.has(callback.fn))
|
|
2784
|
+
return heldByReturns(callback.fn, { module: callback.place.module, frame: unboundFrame(callback) }, depth);
|
|
2785
|
+
givenTo.set(callback.fn, given);
|
|
2786
|
+
const held = heldByReturns(callback.fn, { module: callback.place.module, frame: unboundFrame(callback) }, depth);
|
|
2787
|
+
givenTo.delete(callback.fn);
|
|
2788
|
+
return held;
|
|
2789
|
+
};
|
|
2790
|
+
const heldByReturns = (fn, place, depth) => {
|
|
2791
|
+
if (holdingNow.has(fn))
|
|
2792
|
+
return holdsOther;
|
|
2793
|
+
holdingNow.add(fn);
|
|
2794
|
+
const held = holdsAny(returnsOf(fn).map((node) => heldBy(node, place, depth + 1)));
|
|
2795
|
+
holdingNow.delete(fn);
|
|
2796
|
+
return { ...held, direct: held.calls, names: new Set };
|
|
2797
|
+
};
|
|
2798
|
+
const heldByName = (identifier, place, depth) => {
|
|
2799
|
+
const binding = lookup(place.module, identifier.name, identifier);
|
|
2800
|
+
switch (binding?.kind) {
|
|
2801
|
+
case "declarator":
|
|
2802
|
+
case "destructured": {
|
|
2803
|
+
if (binding.kind === "destructured" && binding.path.join(".") !== "_tag")
|
|
2804
|
+
return holdsUnresolved;
|
|
2805
|
+
if (holdingNow.has(identifier))
|
|
2806
|
+
return holdsNothing;
|
|
2807
|
+
holdingNow.add(identifier);
|
|
2808
|
+
const reaching = writesReaching(binding, identifier).map((write) => {
|
|
2809
|
+
const { value, first } = write;
|
|
2810
|
+
const heldThere = () => {
|
|
2811
|
+
if (value === undefined)
|
|
2812
|
+
return holdsOther;
|
|
2813
|
+
if (value === null)
|
|
2814
|
+
return first ? holdsNothing : holdsOther;
|
|
2815
|
+
const at = { module: binding.module, frame: frameFor(binding.module, value, place.frame) };
|
|
2816
|
+
const held = heldBy(value, at, depth + 1);
|
|
2817
|
+
return first || held.calls.size > 0 ? held : holdsOther;
|
|
2818
|
+
};
|
|
2819
|
+
return { write, held: heldThere() };
|
|
2820
|
+
});
|
|
2821
|
+
holdingNow.delete(identifier);
|
|
2822
|
+
const settling = reaching.filter(({ held }) => held.calls.size > 0);
|
|
2823
|
+
const isCaught = ({ write, held }) => {
|
|
2824
|
+
const around = held.calls.size > 0 ? [] : ancestorsOf(binding.module, write.node);
|
|
2825
|
+
const clause = around.find((at) => at.type === "CatchClause");
|
|
2826
|
+
const statement = clause === undefined ? undefined : around[around.indexOf(clause) + 1];
|
|
2827
|
+
return statement?.type === "TryStatement" && settling.every(({ write: { node } }) => statement.block.start <= node.start && node.end <= statement.block.end);
|
|
2828
|
+
};
|
|
2829
|
+
const held = holdsOrElse(holdsAny(reaching.filter((other) => !isCaught(other)).map((other) => other.held)), reaching.filter(isCaught).map((other) => other.held));
|
|
2830
|
+
return {
|
|
2831
|
+
...held,
|
|
2832
|
+
direct: new Set,
|
|
2833
|
+
names: new Set([...held.names, ...held.direct.size > 0 ? [nameOfBinding(binding, identifier.name)] : []])
|
|
2834
|
+
};
|
|
2835
|
+
}
|
|
2836
|
+
case "param": {
|
|
2837
|
+
if (frameOf(place.frame, binding.fn)?.caller === undefined) {
|
|
2838
|
+
const given = binding.index === 0 && binding.path.length === 0 ? givenTo.get(binding.fn) : undefined;
|
|
2839
|
+
return given === undefined || writesOf(binding).length > 0 ? holdsUnresolved : given;
|
|
2840
|
+
}
|
|
2841
|
+
const arg = binding.path.length === 0 && writesOf(binding).length === 0 ? argumentOf(binding, place.frame) : undefined;
|
|
2842
|
+
const given = arg === undefined ? undefined : unwrap(arg.node);
|
|
2843
|
+
if (arg === undefined || given === undefined)
|
|
2844
|
+
return holdsOther;
|
|
2845
|
+
return given.type === "Identifier" ? heldBy(given, arg.place, depth + 1) : holdsUnresolved;
|
|
2846
|
+
}
|
|
2847
|
+
case undefined:
|
|
2848
|
+
return holdsUnresolved;
|
|
2849
|
+
default:
|
|
2850
|
+
return holdsOther;
|
|
2851
|
+
}
|
|
2852
|
+
};
|
|
2853
|
+
const writes = new WeakMap;
|
|
2854
|
+
const withWrittenMembers = new WeakSet;
|
|
2855
|
+
const memberRoot = (target) => {
|
|
2856
|
+
let at = unwrap(target);
|
|
2857
|
+
if (at.type !== "MemberExpression")
|
|
2858
|
+
return;
|
|
2859
|
+
while (at.type === "MemberExpression")
|
|
2860
|
+
at = unwrap(at.object);
|
|
2861
|
+
return at.type === "Identifier" ? at : undefined;
|
|
2862
|
+
};
|
|
2863
|
+
const writesOf = (binding) => {
|
|
2864
|
+
const { module } = binding;
|
|
2865
|
+
const known = writes.get(module);
|
|
2866
|
+
if (known !== undefined)
|
|
2867
|
+
return known.get(binding) ?? [];
|
|
2868
|
+
const found = new Map;
|
|
2869
|
+
const add = (target, write) => {
|
|
2870
|
+
const object = memberRoot(target);
|
|
2871
|
+
if (object !== undefined) {
|
|
2872
|
+
const changed = lookup(module, object.name, object);
|
|
2873
|
+
if (changed !== undefined)
|
|
2874
|
+
withWrittenMembers.add(changed);
|
|
2875
|
+
}
|
|
2876
|
+
for (const { name } of patternNames(target)) {
|
|
2877
|
+
const written = lookup(module, name, target);
|
|
2878
|
+
if (written !== undefined)
|
|
2879
|
+
found.set(written, [...found.get(written) ?? [], write]);
|
|
2880
|
+
}
|
|
2881
|
+
};
|
|
2882
|
+
const pending = [module.program];
|
|
2883
|
+
for (let node = pending.pop();node !== undefined; node = pending.pop()) {
|
|
2884
|
+
if (node.type === "AssignmentExpression")
|
|
2885
|
+
add(node.left, {
|
|
2886
|
+
node,
|
|
2887
|
+
value: node.left.type === "Identifier" && node.operator === "=" ? node.right : undefined,
|
|
2888
|
+
replaces: node.operator === "="
|
|
2889
|
+
});
|
|
2890
|
+
else if (node.type === "UpdateExpression")
|
|
2891
|
+
add(node.argument, { node, value: undefined, replaces: true });
|
|
2892
|
+
else if ((node.type === "ForOfStatement" || node.type === "ForInStatement") && node.left.type !== "VariableDeclaration")
|
|
2893
|
+
add(node.left, { node: node.left, value: undefined, replaces: false });
|
|
2894
|
+
pending.push(...childrenOf(node));
|
|
2895
|
+
}
|
|
2896
|
+
for (const written of found.values())
|
|
2897
|
+
written.sort((a, b) => a.node.start - b.node.start);
|
|
2898
|
+
writes.set(module, found);
|
|
2899
|
+
return found.get(binding) ?? [];
|
|
2900
|
+
};
|
|
2901
|
+
const ancestorsOf = (module, node) => {
|
|
2902
|
+
const found = [];
|
|
2903
|
+
for (let at = module.parents.get(node);at !== undefined; at = module.parents.get(at))
|
|
2904
|
+
found.push(at);
|
|
2905
|
+
return found;
|
|
2906
|
+
};
|
|
2907
|
+
const writesReaching = (binding, read) => {
|
|
2908
|
+
const { module, declarator } = binding;
|
|
2909
|
+
const around = ancestorsOf(module, read);
|
|
2910
|
+
const fn = enclosingFunction(module, read);
|
|
2911
|
+
const declared = { node: declarator, value: declarator.init, replaces: true };
|
|
2912
|
+
const all = [declared, ...writesOf(binding)];
|
|
2913
|
+
const isBefore = ({ node }) => node.end <= read.start;
|
|
2914
|
+
const isHere = ({ node }) => enclosingFunction(module, node) === fn;
|
|
2915
|
+
const surelyRan = ({ node }) => {
|
|
2916
|
+
const statement = ancestorsOf(module, node).find((at) => at.type !== "ExpressionStatement" && at.type !== "VariableDeclaration");
|
|
2917
|
+
return statement !== undefined && around.includes(statement);
|
|
2918
|
+
};
|
|
2919
|
+
const latest = all.findLast((write) => write.replaces && isBefore(write) && isHere(write) && surelyRan(write));
|
|
2920
|
+
if (latest === undefined)
|
|
2921
|
+
return all.map((write) => ({ ...write, first: write === declared }));
|
|
2922
|
+
const isBeside = ({ node }) => {
|
|
2923
|
+
const other = new Set(ancestorsOf(module, node));
|
|
2924
|
+
const branch = around.find((at) => other.has(at));
|
|
2925
|
+
if (branch?.type !== "IfStatement" && branch?.type !== "ConditionalExpression")
|
|
2926
|
+
return false;
|
|
2927
|
+
const sides = [branch.consequent, branch.alternate].filter((side) => side !== null);
|
|
2928
|
+
const sideOf = (at) => sides.find((side) => side.start <= at.start && at.end <= side.end);
|
|
2929
|
+
return sideOf(node) !== sideOf(read) && sideOf(node) !== undefined && sideOf(read) !== undefined;
|
|
2930
|
+
};
|
|
2931
|
+
const roundsAfter = around.filter((at) => isLoop(at) && at.start > latest.node.start);
|
|
2932
|
+
return all.flatMap((write) => {
|
|
2933
|
+
const isBetween = write.node.start >= latest.node.end && isBefore(write) && !isBeside(write);
|
|
2934
|
+
const isReached = write === latest || write !== declared && !isHere(write) || isBetween || roundsAfter.some((loop) => loop.start <= write.node.start && write.node.end <= loop.end);
|
|
2935
|
+
return isReached ? [{ ...write, first: write === latest }] : [];
|
|
2936
|
+
});
|
|
2937
|
+
};
|
|
2938
|
+
const statusesOfObject = (object, depth) => {
|
|
2939
|
+
let provider;
|
|
2940
|
+
for (const property of object.node.properties) {
|
|
2941
|
+
if (property.type === "SpreadElement") {
|
|
2942
|
+
const spread = statusesOf(resultsOf(property.argument, object.place, depth + 1), depth + 1);
|
|
2943
|
+
if (spread.statuses.length > 0 || spread.unknown)
|
|
2944
|
+
provider = () => spread;
|
|
2945
|
+
continue;
|
|
2946
|
+
}
|
|
2947
|
+
const key = keyName(property.key, property.computed);
|
|
2948
|
+
if (key === "status" || key === "_tag") {
|
|
2949
|
+
const value = property.value;
|
|
2950
|
+
provider = () => {
|
|
2951
|
+
const results = resultsOf(value, object.place, depth + 1);
|
|
2952
|
+
return {
|
|
2953
|
+
statuses: results.values.flatMap((result) => result.kind === "string" ? [result.value] : []),
|
|
2954
|
+
unknown: results.unknown || results.values.some((result) => result.kind !== "string" && result.checked !== true)
|
|
2955
|
+
};
|
|
2956
|
+
};
|
|
2957
|
+
}
|
|
2958
|
+
}
|
|
2959
|
+
return provider?.();
|
|
2960
|
+
};
|
|
2961
|
+
const statusesOf = (results, depth = 0) => {
|
|
2962
|
+
const statuses = [];
|
|
2963
|
+
let unresolved = results.unknown;
|
|
2964
|
+
let unnamed = false;
|
|
2965
|
+
for (const result of results.values) {
|
|
2966
|
+
if (result.kind === "tag") {
|
|
2967
|
+
statuses.push(result.tag);
|
|
2968
|
+
continue;
|
|
2969
|
+
}
|
|
2970
|
+
const found = result.kind === "object" ? statusesOfObject(result, depth) : undefined;
|
|
2971
|
+
if (found === undefined) {
|
|
2972
|
+
unnamed ||= result.checked !== true;
|
|
2973
|
+
continue;
|
|
2974
|
+
}
|
|
2975
|
+
statuses.push(...found.statuses);
|
|
2976
|
+
unresolved ||= found.unknown;
|
|
2977
|
+
}
|
|
2978
|
+
return { statuses: dedupe(statuses), unknown: unresolved || unnamed && statuses.length > 0 };
|
|
2979
|
+
};
|
|
2980
|
+
const endOf = (node, place, at) => node === null ? { kind: "end", at } : endOfResults(resultsOf(node, place), at);
|
|
2981
|
+
const endOfResults = (results, at) => {
|
|
2982
|
+
const { statuses, unknown: unresolved } = statusesOf(results);
|
|
2983
|
+
return {
|
|
2984
|
+
kind: "end",
|
|
2985
|
+
...statuses.length === 0 ? undefined : { statuses },
|
|
2986
|
+
...unresolved ? { runtime: true } : undefined,
|
|
2987
|
+
at
|
|
2988
|
+
};
|
|
2989
|
+
};
|
|
2990
|
+
const effectName = (value) => {
|
|
2991
|
+
if (value.kind !== "external")
|
|
2992
|
+
return;
|
|
2993
|
+
if (value.specifier === "effect/Effect" && value.path.length === 1)
|
|
2994
|
+
return value.path[0];
|
|
2995
|
+
return value.specifier === "effect" && value.path.length === 2 && value.path[0] === "Effect" ? value.path[1] : undefined;
|
|
2996
|
+
};
|
|
2997
|
+
const inner = (walk) => walk.top ? { ...walk, top: false } : walk;
|
|
2998
|
+
const failureEnd = (made, walk) => {
|
|
2999
|
+
const at = unwrap(made);
|
|
3000
|
+
const tag = tagOf(at, walk.place);
|
|
3001
|
+
const args = at.type === "NewExpression" ? walkArguments(at.arguments, walk) : [];
|
|
3002
|
+
return [
|
|
3003
|
+
...args,
|
|
3004
|
+
{ kind: "end", ...tag === undefined ? { fails: true } : { failure: tag }, at: located(walk.place.module, at) }
|
|
3005
|
+
];
|
|
3006
|
+
};
|
|
3007
|
+
const walkArguments = (args, walk) => args.flatMap((arg) => isFunction(unwrap(arg)) ? [] : walkExpression(arg, inner(walk), false));
|
|
3008
|
+
const unread = (fn, walk) => ({
|
|
3009
|
+
kind: "runtime",
|
|
3010
|
+
label: walk.stack.includes(fn.fn) ? "the same code again, by recursion" : "code nested too deep to read",
|
|
3011
|
+
at: located(fn.place.module, fn.fn)
|
|
3012
|
+
});
|
|
3013
|
+
const endingEffect = (returned, walk, at) => {
|
|
3014
|
+
const reached = { value: false };
|
|
3015
|
+
const nodes = walkExpression(returned, { ...walk, endsByEffect: false, top: true, reached }, true);
|
|
3016
|
+
const last = nodes.at(-1);
|
|
3017
|
+
if (reached.value || last?.kind === "end" && endsFailing(last))
|
|
3018
|
+
return nodes;
|
|
3019
|
+
return [...nodes, endOf(returned, walk.place, at)];
|
|
3020
|
+
};
|
|
3021
|
+
const endingFunction = (fn, frame, walk) => {
|
|
3022
|
+
if (walk.stack.includes(fn.fn) || walk.stack.length > maxInlined)
|
|
3023
|
+
return [unread(fn, walk)];
|
|
3024
|
+
const place = { module: fn.place.module, frame };
|
|
3025
|
+
const body = fn.fn.body;
|
|
3026
|
+
const within = {
|
|
3027
|
+
...walk,
|
|
3028
|
+
place,
|
|
3029
|
+
ends: false,
|
|
3030
|
+
endsByEffect: true,
|
|
3031
|
+
returnsYielded: true,
|
|
3032
|
+
top: false,
|
|
3033
|
+
stack: [...walk.stack, fn.fn]
|
|
3034
|
+
};
|
|
3035
|
+
if (body === null)
|
|
3036
|
+
return [];
|
|
3037
|
+
return body.type === "BlockStatement" ? walkStatements(body.body, within) : endingEffect(body, within, located(place.module, body));
|
|
3038
|
+
};
|
|
3039
|
+
const walkFunction = (fn, frame, walk, options) => {
|
|
3040
|
+
if (walk.stack.includes(fn.fn) || walk.stack.length > maxInlined)
|
|
3041
|
+
return [unread(fn, walk)];
|
|
3042
|
+
const place = { module: fn.place.module, frame };
|
|
3043
|
+
const body = fn.fn.body;
|
|
3044
|
+
const within = {
|
|
3045
|
+
...walk,
|
|
3046
|
+
place,
|
|
3047
|
+
ends: options.ends,
|
|
3048
|
+
endsByEffect: false,
|
|
3049
|
+
returnsYielded: !fn.fn.generator && options.yielded,
|
|
3050
|
+
top: options.top ?? false,
|
|
3051
|
+
stack: [...walk.stack, fn.fn]
|
|
3052
|
+
};
|
|
3053
|
+
if (body === null)
|
|
3054
|
+
return [];
|
|
3055
|
+
if (body.type !== "BlockStatement")
|
|
3056
|
+
return walkExpression(body, within, options.yielded);
|
|
3057
|
+
const nodes = walkStatements(body.body, within);
|
|
3058
|
+
const last = body.body.at(-1);
|
|
3059
|
+
if (options.ends && last?.type !== "ReturnStatement" && last?.type !== "ThrowStatement")
|
|
3060
|
+
nodes.push({ kind: "end", at: located(place.module, { ...body, start: body.end - 1 }) });
|
|
3061
|
+
return nodes;
|
|
3062
|
+
};
|
|
3063
|
+
const walkCallback = (raw, walk, yielded, ending = false) => {
|
|
3064
|
+
if (raw === undefined)
|
|
3065
|
+
return [];
|
|
3066
|
+
const callback = resolveValue(raw, walk.place);
|
|
3067
|
+
if (callback.kind !== "fn")
|
|
3068
|
+
return isFunction(unwrap(raw)) ? [] : walkExpression(raw, inner(walk), yielded);
|
|
3069
|
+
return ending ? endingFunction(callback, unboundFrame(callback), walk) : walkFunction(callback, unboundFrame(callback), walk, { ends: false, yielded });
|
|
3070
|
+
};
|
|
3071
|
+
const tapPaths = (name, args, walk, at) => {
|
|
3072
|
+
const tags = name === "tapErrorTag" ? literalTags(args) : undefined;
|
|
3073
|
+
return failurePaths(name === "tapErrorTag" ? "catchTag" : "catch", args, walk, false).map((path) => {
|
|
3074
|
+
const end = {
|
|
3075
|
+
kind: "end",
|
|
3076
|
+
...tags === undefined ? { fails: true } : { failure: tags.join(" | ") },
|
|
3077
|
+
at
|
|
3078
|
+
};
|
|
3079
|
+
tapEnds.set(end, new Set);
|
|
3080
|
+
return { ...path, nodes: [...path.nodes, end] };
|
|
3081
|
+
});
|
|
3082
|
+
};
|
|
3083
|
+
const literalTags = (args) => {
|
|
3084
|
+
const tags = args.slice(0, -1).flatMap((arg) => {
|
|
3085
|
+
const at = unwrap(arg);
|
|
3086
|
+
return at.type === "ArrayExpression" ? at.elements : [at];
|
|
3087
|
+
});
|
|
3088
|
+
const literals = tags.flatMap((tag) => {
|
|
3089
|
+
const literal = tag === null ? undefined : stringLiteral(tag);
|
|
3090
|
+
return literal === undefined ? [] : [literal];
|
|
3091
|
+
});
|
|
3092
|
+
return literals.length > 0 && literals.length === tags.length ? literals : undefined;
|
|
3093
|
+
};
|
|
3094
|
+
const caughtBy = (name, args) => {
|
|
3095
|
+
if (name === "catchTag")
|
|
3096
|
+
return literalTags(args) ?? [];
|
|
3097
|
+
if (name === "catchTags") {
|
|
3098
|
+
const handlers = args[0] === undefined ? undefined : unwrap(args[0]);
|
|
3099
|
+
return handlers?.type === "ObjectExpression" ? handlers.properties.flatMap((property) => {
|
|
3100
|
+
const key = property.type === "Property" ? keyName(property.key, property.computed) : undefined;
|
|
3101
|
+
return key === undefined ? [] : [key];
|
|
3102
|
+
}) : [];
|
|
3103
|
+
}
|
|
3104
|
+
return totalCatches.has(name) ? "all" : [];
|
|
3105
|
+
};
|
|
3106
|
+
const markCaughtTaps = (nodes, caught) => nodes.map((node) => {
|
|
3107
|
+
const caughtSoFar = tapEnds.get(node);
|
|
3108
|
+
if (caughtSoFar === undefined || node.kind !== "end")
|
|
3109
|
+
return mapChildren(node, (children) => markCaughtTaps(children, caught));
|
|
3110
|
+
if (caught !== "all")
|
|
3111
|
+
for (const tag of caught)
|
|
3112
|
+
caughtSoFar.add(tag);
|
|
3113
|
+
const catches = caught === "all" || node.failure !== undefined && node.failure.split(" | ").every((tag) => caughtSoFar.has(tag));
|
|
3114
|
+
return catches ? { ...node, caught: true } : node;
|
|
3115
|
+
});
|
|
3116
|
+
const failurePaths = (name, args, walk, ending) => {
|
|
3117
|
+
if (name === "catchTag") {
|
|
3118
|
+
const tags = args.slice(0, -1).flatMap((arg) => {
|
|
3119
|
+
const at = unwrap(arg);
|
|
3120
|
+
return at.type === "ArrayExpression" ? at.elements.flatMap((element) => element === null ? [] : [element]) : [at];
|
|
3121
|
+
});
|
|
3122
|
+
return [
|
|
3123
|
+
{
|
|
3124
|
+
label: tags.map((tag) => stringLiteral(tag) ?? textOf(walk.place.module, tag)).join(" | "),
|
|
3125
|
+
nodes: walkCallback(args.at(-1), walk, true, ending)
|
|
3126
|
+
}
|
|
3127
|
+
];
|
|
3128
|
+
}
|
|
3129
|
+
if (name === "catchTags") {
|
|
3130
|
+
const handlers = args[0] === undefined ? undefined : unwrap(args[0]);
|
|
3131
|
+
if (handlers?.type !== "ObjectExpression")
|
|
3132
|
+
return [];
|
|
3133
|
+
return handlers.properties.flatMap((property) => property.type === "Property" ? [
|
|
3134
|
+
{
|
|
3135
|
+
label: keyName(property.key, property.computed) ?? textOf(walk.place.module, property.key),
|
|
3136
|
+
nodes: walkCallback(property.value, walk, true, ending)
|
|
3137
|
+
}
|
|
3138
|
+
] : []);
|
|
3139
|
+
}
|
|
3140
|
+
return [
|
|
3141
|
+
{
|
|
3142
|
+
label: name === "catchIf" || name === "catchSome" ? "some failures" : anyFailure,
|
|
3143
|
+
nodes: walkCallback(args.at(-1), walk, true, ending)
|
|
3144
|
+
}
|
|
3145
|
+
];
|
|
3146
|
+
};
|
|
3147
|
+
const failureBranch = (tried, paths, at) => tried.length === 0 && paths.every((path) => path.nodes.length === 0) ? [] : [{ kind: "branch", on: "failure", nodes: tried, paths, at }];
|
|
3148
|
+
const endsOrWraps = (raw, walk) => {
|
|
3149
|
+
const op = unwrap(raw);
|
|
3150
|
+
const name = effectName(resolveValue(op.type === "CallExpression" ? op.callee : op, walk.place));
|
|
3151
|
+
return name !== undefined && (isFailureHandler(name) || isRecovery(name) || effectMethods.repeats.has(name));
|
|
3152
|
+
};
|
|
3153
|
+
const isFailureHandler = (name) => name === "catchTag" || name === "catchTags" || effectMethods.catches.has(name) || effectMethods.taps.has(name);
|
|
3154
|
+
const handled = (name, tried, args, walk, at, ending) => effectMethods.taps.has(name) ? failureBranch(tried, tapPaths(name, args, walk, at), at) : failureBranch(markCaughtTaps(tried, caughtBy(name, args)), failurePaths(name, args, walk, ending), at);
|
|
3155
|
+
const isRecovery = (name) => name === "orElseSucceed" || effectMethods.takes.has(name) || effectMethods.matches.has(name) || effectMethods.effectMatches.has(name);
|
|
3156
|
+
const withoutReturns = (nodes) => {
|
|
3157
|
+
let returned = false;
|
|
3158
|
+
return nodes.flatMap((node) => {
|
|
3159
|
+
const after = returned;
|
|
3160
|
+
const holdsReturn = holdsEnd(node, (end) => !endsFailing(end));
|
|
3161
|
+
returned ||= holdsReturn;
|
|
3162
|
+
if (node.kind === "end" && !endsFailing(node))
|
|
3163
|
+
return [];
|
|
3164
|
+
const kept = mapChildren(node, withoutReturns);
|
|
3165
|
+
const lists = childLists(kept);
|
|
3166
|
+
if (lists.length > 0 && kept.kind !== "first" && lists.every((list) => list.length === 0))
|
|
3167
|
+
return [];
|
|
3168
|
+
return after ? afterReturn([kept]) : [kept];
|
|
3169
|
+
});
|
|
3170
|
+
};
|
|
3171
|
+
const recovered = (name, tried, args, walk, at, ending) => {
|
|
3172
|
+
const handled = markCaughtTaps(tried, "all");
|
|
3173
|
+
if (name === "orElseSucceed")
|
|
3174
|
+
return failureBranch(handled, [{ label: goesOn, nodes: walkCallback(args[0], walk, false, ending) }], at);
|
|
3175
|
+
const options = args[0] === undefined ? unknown : resolveValue(args[0], walk.place);
|
|
3176
|
+
const isEffect = effectMethods.effectMatches.has(name);
|
|
3177
|
+
const replaced = ending ? withoutReturns(handled) : handled;
|
|
3178
|
+
if (effectMethods.takes.has(name) || options.kind !== "node")
|
|
3179
|
+
return [
|
|
3180
|
+
...failureBranch(replaced, [{ label: goesOn, nodes: [] }], at),
|
|
3181
|
+
...ending ? [endOfResults(takenResults(name), at)] : []
|
|
3182
|
+
];
|
|
3183
|
+
const written = (key) => propertyOf(options, key, 0);
|
|
3184
|
+
const callback = (key) => {
|
|
3185
|
+
const found = written(key);
|
|
3186
|
+
const within = found === undefined ? walk : { ...walk, place: found.place };
|
|
3187
|
+
const nodes = walkCallback(found?.node, within, isEffect, ending);
|
|
3188
|
+
return ending && !hasEnd(nodes) ? [...nodes, endOfResults(callbackReturns(found?.node, within.place, 0), at)] : nodes;
|
|
3189
|
+
};
|
|
3190
|
+
const onSuccess = callback("onSuccess");
|
|
3191
|
+
const handsOn = ending && onSuccess.every((node) => node.kind === "end" && node.runtime === true && node.statuses === undefined);
|
|
3192
|
+
const onFailure = { label: "onFailure", nodes: callback("onFailure") };
|
|
3193
|
+
const successFirst = (written("onSuccess")?.node.start ?? Infinity) < (written("onFailure")?.node.start ?? Infinity);
|
|
3194
|
+
if (onSuccess.length === 0 || handsOn)
|
|
3195
|
+
return failureBranch(handsOn ? handled : replaced, [onFailure], at);
|
|
3196
|
+
const success = { label: "onSuccess", on: "success", nodes: onSuccess };
|
|
3197
|
+
return failureBranch(replaced, successFirst ? [success, onFailure] : [onFailure, success], at);
|
|
3198
|
+
};
|
|
3199
|
+
const takenResults = (name) => name === "ignore" || name === "ignoreCause" ? emptyResults : unknownResults;
|
|
3200
|
+
const beforeEnds = (nodes, extra, all, replaced) => nodes.flatMap((node) => {
|
|
3201
|
+
if (node.kind !== "end")
|
|
3202
|
+
return [mapChildren(node, (children) => beforeEnds(children, extra, all, replaced))];
|
|
3203
|
+
if (node.caught === true)
|
|
3204
|
+
return [node];
|
|
3205
|
+
if (endsFailing(node))
|
|
3206
|
+
return all ? [...extra, node] : [node];
|
|
3207
|
+
return [...extra, replaced ?? node];
|
|
3208
|
+
});
|
|
3209
|
+
const replacingEnd = (results, at) => {
|
|
3210
|
+
const end = endOfResults(results, at);
|
|
3211
|
+
return end.kind === "end" && end.statuses !== undefined && end.runtime !== true ? end : undefined;
|
|
3212
|
+
};
|
|
3213
|
+
const resultReplacers = new Set(["map", "as", "flatMap", "andThen"]);
|
|
3214
|
+
const afterRun = (raw, walk, prior) => {
|
|
3215
|
+
const extra = walkOperator(raw, walk, [], false);
|
|
3216
|
+
const op = unwrap(raw);
|
|
3217
|
+
const name = op.type === "CallExpression" ? effectName(resolveValue(op.callee, walk.place)) : undefined;
|
|
3218
|
+
const replaced = op.type === "CallExpression" && name !== undefined && resultReplacers.has(name) ? replacingEnd(callbackReturns(op.arguments[0], walk.place, 0), located(walk.place.module, op)) : undefined;
|
|
3219
|
+
if (extra.length === 0 && replaced === undefined)
|
|
3220
|
+
return prior;
|
|
3221
|
+
return hasEnd(prior) ? beforeEnds(prior, extra, name === "ensuring", replaced) : [...prior, ...extra];
|
|
3222
|
+
};
|
|
3223
|
+
const walkOperator = (raw, walk, prior, ending) => {
|
|
3224
|
+
const op = unwrap(raw);
|
|
3225
|
+
if (op.type !== "CallExpression") {
|
|
3226
|
+
const name = effectName(resolveValue(op, walk.place));
|
|
3227
|
+
if (name?.startsWith("fork") === true)
|
|
3228
|
+
forks += 1;
|
|
3229
|
+
return name !== undefined && effectMethods.takes.has(name) ? recovered(name, prior, [], walk, located(walk.place.module, op), ending) : prior;
|
|
3230
|
+
}
|
|
3231
|
+
const name = effectName(resolveValue(op.callee, walk.place));
|
|
3232
|
+
const at = located(walk.place.module, op);
|
|
3233
|
+
if (name === undefined)
|
|
3234
|
+
return [...prior, ...generic(op, walk)];
|
|
3235
|
+
if (name.startsWith("fork"))
|
|
3236
|
+
forks += 1;
|
|
3237
|
+
if (effectMethods.repeats.has(name))
|
|
3238
|
+
return prior.length === 0 ? [] : [{ kind: "repeat", label: textOf(walk.place.module, op), nodes: prior, at }];
|
|
3239
|
+
if (isFailureHandler(name))
|
|
3240
|
+
return handled(name, prior, op.arguments, walk, at, ending);
|
|
3241
|
+
if (isRecovery(name))
|
|
3242
|
+
return recovered(name, prior, op.arguments, walk, at, ending);
|
|
3243
|
+
if (name === "map")
|
|
3244
|
+
return [...prior, ...walkCallback(op.arguments[0], walk, false)];
|
|
3245
|
+
if (effectMethods.chains.has(name))
|
|
3246
|
+
return [...prior, ...walkCallback(op.arguments[0], walk, true)];
|
|
3247
|
+
return [...prior, ...generic(op, walk)];
|
|
3248
|
+
};
|
|
3249
|
+
const generic = (call, walk) => {
|
|
3250
|
+
const callee = unwrap(call.callee);
|
|
3251
|
+
const nodes = [];
|
|
3252
|
+
if (callee.type === "MemberExpression")
|
|
3253
|
+
nodes.push(...walkExpression(callee.object, inner(walk), false));
|
|
3254
|
+
if (callee.type === "CallExpression")
|
|
3255
|
+
nodes.push(...walkExpression(callee, inner(walk), false));
|
|
3256
|
+
const callbacks = [];
|
|
3257
|
+
for (const raw of call.arguments) {
|
|
3258
|
+
const arg = unwrap(raw);
|
|
3259
|
+
if (isFunction(arg)) {
|
|
3260
|
+
callbacks.push({ label: `#${callbacks.length + 1}`, nodes: walkCallback(arg, walk, false) });
|
|
3261
|
+
continue;
|
|
3262
|
+
}
|
|
3263
|
+
if (arg.type === "ObjectExpression") {
|
|
3264
|
+
for (const property of arg.properties)
|
|
3265
|
+
if (property.type === "Property" && isFunction(unwrap(property.value)))
|
|
3266
|
+
callbacks.push({
|
|
3267
|
+
label: keyName(property.key, property.computed) ?? textOf(walk.place.module, property.key),
|
|
3268
|
+
nodes: walkCallback(property.value, walk, false)
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
nodes.push(...walkExpression(arg, inner(walk), false));
|
|
3272
|
+
}
|
|
3273
|
+
const reached = callbacks.filter((path) => path.nodes.length > 0);
|
|
3274
|
+
const method = memberName(callee);
|
|
3275
|
+
const at = located(walk.place.module, call);
|
|
3276
|
+
if (reached.length === 1 && callee.type === "MemberExpression" && method !== undefined && arrayMethods.has(method))
|
|
3277
|
+
return [
|
|
3278
|
+
...nodes,
|
|
3279
|
+
{
|
|
3280
|
+
kind: "many",
|
|
3281
|
+
label: `${textOf(walk.place.module, callee.object)}.${method}`,
|
|
3282
|
+
nodes: reached[0]?.nodes ?? [],
|
|
3283
|
+
at
|
|
3284
|
+
}
|
|
3285
|
+
];
|
|
3286
|
+
if (reached.length === 1)
|
|
3287
|
+
return [...nodes, ...reached[0]?.nodes ?? []];
|
|
3288
|
+
return reached.length === 0 ? nodes : [...nodes, { kind: "branch", paths: reached, at }];
|
|
3289
|
+
};
|
|
3290
|
+
const definedOutline = (step, walk) => {
|
|
3291
|
+
const known = defined.get(step.call);
|
|
3292
|
+
if (known !== undefined)
|
|
3293
|
+
return known;
|
|
3294
|
+
if (definingNow.has(step.call))
|
|
3295
|
+
return [];
|
|
3296
|
+
definingNow.add(step.call);
|
|
3297
|
+
const options = step.call.arguments[1];
|
|
3298
|
+
const run = options === undefined ? undefined : propertyOf(resolveValue(options, step.place), "run", 0);
|
|
3299
|
+
const fn = run === undefined ? unknown : resolveValue(run.node, run.place);
|
|
3300
|
+
const outline = fn.kind === "fn" ? walkFunction(fn, unboundFrame(fn), { ...walk, stack: [], reached: { value: false } }, { ends: false, yielded: true, top: true }) : [{ kind: "runtime", label: `${step.name}'s run`, at: located(step.place.module, step.call) }];
|
|
3301
|
+
definingNow.delete(step.call);
|
|
3302
|
+
defined.set(step.call, outline);
|
|
3303
|
+
return outline;
|
|
3304
|
+
};
|
|
3305
|
+
const agentOf = (raw, place) => {
|
|
3306
|
+
const option = raw === undefined ? undefined : propertyOf(resolveValue(raw, place), "agent", 0);
|
|
3307
|
+
const role = option === undefined ? undefined : literalName(option.node, option.place);
|
|
3308
|
+
return role === undefined ? { runtime: true } : { agent: role };
|
|
3309
|
+
};
|
|
3310
|
+
const lentStep = (name, lent, call, walk) => ({
|
|
3311
|
+
kind: "step",
|
|
3312
|
+
step: name,
|
|
3313
|
+
names: namesOf(call.arguments[lent.name], walk.place),
|
|
3314
|
+
...lent.agent === undefined ? undefined : agentOf(call.arguments[lent.agent], walk.place),
|
|
3315
|
+
at: located(walk.place.module, call)
|
|
3316
|
+
});
|
|
3317
|
+
const childRun = (call, walk) => {
|
|
3318
|
+
const loop = call.arguments[1] === undefined ? undefined : propertyOf(resolveValue(call.arguments[1], walk.place), "id", 0);
|
|
3319
|
+
const id = loop === undefined ? undefined : literalName(loop.node, loop.place);
|
|
3320
|
+
return {
|
|
3321
|
+
kind: "call",
|
|
3322
|
+
names: namesOf(call.arguments[0], walk.place),
|
|
3323
|
+
...id === undefined ? { runtime: true } : { loop: id },
|
|
3324
|
+
at: located(walk.place.module, call)
|
|
3325
|
+
};
|
|
3326
|
+
};
|
|
3327
|
+
const alternatives = (call, walk) => {
|
|
3328
|
+
const [name, entries] = call.arguments;
|
|
3329
|
+
const resolved = entries === undefined ? undefined : unwrap(entries);
|
|
3330
|
+
const paths = resolved?.type === "ObjectExpression" ? sideBySide(resolved, walk) : entries === undefined ? [] : [{ label: textOf(walk.place.module, entries), nodes: walkExpression(entries, inner(walk), true) }];
|
|
3331
|
+
const node = {
|
|
3332
|
+
kind: "first",
|
|
3333
|
+
names: namesOf(name, walk.place),
|
|
3334
|
+
paths: paths ?? [],
|
|
3335
|
+
at: located(walk.place.module, call)
|
|
3336
|
+
};
|
|
3337
|
+
calledFirst.set(node, call);
|
|
3338
|
+
return [node];
|
|
3339
|
+
};
|
|
3340
|
+
const sideBySide = (all, walk) => {
|
|
3341
|
+
if (all.type === "ArrayExpression")
|
|
3342
|
+
return all.elements.flatMap((element, index) => element === null ? [] : [{ label: `#${index + 1}`, nodes: walkExpression(element, inner(walk), true) }]);
|
|
3343
|
+
if (all.type !== "ObjectExpression")
|
|
3344
|
+
return;
|
|
3345
|
+
return all.properties.map((property, index) => property.type === "Property" ? {
|
|
3346
|
+
label: keyName(property.key, property.computed) ?? `#${index + 1}`,
|
|
3347
|
+
nodes: walkExpression(property.value, inner(walk), true)
|
|
3348
|
+
} : { label: "...", nodes: walkExpression(property.argument, inner(walk), true) });
|
|
3349
|
+
};
|
|
3350
|
+
const isConstant = (node, place) => {
|
|
3351
|
+
const at = unwrap(node);
|
|
3352
|
+
if (at.type !== "Identifier")
|
|
3353
|
+
return true;
|
|
3354
|
+
const binding = lookup(place.module, at.name, at);
|
|
3355
|
+
return binding === undefined || binding.kind === "other" || writesOf(binding).length === 0 && !withWrittenMembers.has(binding);
|
|
3356
|
+
};
|
|
3357
|
+
const inSequence = (options, place) => {
|
|
3358
|
+
const sequential = { sequential: true };
|
|
3359
|
+
if (options === undefined)
|
|
3360
|
+
return sequential;
|
|
3361
|
+
const value = isConstant(options, place) ? resolveValue(options, place) : unknown;
|
|
3362
|
+
const object = value.kind === "node" ? unwrap(value.node) : undefined;
|
|
3363
|
+
if (object?.type !== "ObjectExpression")
|
|
3364
|
+
return;
|
|
3365
|
+
const concurrency = propertyOf(value, "concurrency", 0);
|
|
3366
|
+
if (concurrency === undefined)
|
|
3367
|
+
return object.properties.every((property) => property.type === "Property" && !property.computed) ? sequential : undefined;
|
|
3368
|
+
const isGivenOnce = isConstant(concurrency.node, concurrency.place);
|
|
3369
|
+
const given = isGivenOnce ? resolveValue(concurrency.node, concurrency.place) : unknown;
|
|
3370
|
+
const at = given.kind === "node" ? unwrap(given.node) : undefined;
|
|
3371
|
+
return at?.type === "Literal" && at.value === 1 ? sequential : undefined;
|
|
3372
|
+
};
|
|
3373
|
+
let forks = 0;
|
|
3374
|
+
const readInOrder = (order, read) => {
|
|
3375
|
+
const before = forks;
|
|
3376
|
+
const nodes = read();
|
|
3377
|
+
return { nodes, order: forks === before ? order : undefined };
|
|
3378
|
+
};
|
|
3379
|
+
const allOf = (items, isMapped, label, order, at) => {
|
|
3380
|
+
const last = items.at(-1);
|
|
3381
|
+
if (last?.kind === "many") {
|
|
3382
|
+
if (isMapped)
|
|
3383
|
+
return [...items.slice(0, -1), { ...last, label, ...order, at }];
|
|
3384
|
+
if (items.length === 1)
|
|
3385
|
+
return [{ ...last, label, at }];
|
|
3386
|
+
}
|
|
3387
|
+
return last === undefined ? [] : [{ kind: "many", label, nodes: items, at }];
|
|
3388
|
+
};
|
|
3389
|
+
const effectCall = (name, call, walk, yielded) => {
|
|
3390
|
+
const args = call.arguments;
|
|
3391
|
+
const [first, second] = args;
|
|
3392
|
+
const at = located(walk.place.module, call);
|
|
3393
|
+
const module = walk.place.module;
|
|
3394
|
+
if (name === "gen") {
|
|
3395
|
+
const body = args.at(-1);
|
|
3396
|
+
const fn = body === undefined ? unknown : resolveValue(body, walk.place);
|
|
3397
|
+
if (fn.kind !== "fn")
|
|
3398
|
+
return [];
|
|
3399
|
+
const ends = walk.top;
|
|
3400
|
+
if (ends)
|
|
3401
|
+
walk.reached.value = true;
|
|
3402
|
+
return walkFunction(fn, unboundFrame(fn), walk, { ends, yielded: false });
|
|
3403
|
+
}
|
|
3404
|
+
if (name === "forEach") {
|
|
3405
|
+
if (first === undefined)
|
|
3406
|
+
return [];
|
|
3407
|
+
const items = second === undefined ? [] : walkExpression(first, inner(walk), false);
|
|
3408
|
+
const label = second === undefined ? "Effect.forEach" : `Effect.forEach(${textOf(module, first)})`;
|
|
3409
|
+
const { nodes: body, order } = readInOrder(second === undefined ? undefined : inSequence(args[2], walk.place), () => walkCallback(second ?? first, walk, true));
|
|
3410
|
+
return body.length === 0 ? items : [...items, { kind: "many", label, ...order, nodes: body, at }];
|
|
3411
|
+
}
|
|
3412
|
+
if (name.startsWith("fork"))
|
|
3413
|
+
forks += 1;
|
|
3414
|
+
if (name === "all" && first !== undefined) {
|
|
3415
|
+
const all = unwrap(first);
|
|
3416
|
+
const given = inSequence(second, walk.place);
|
|
3417
|
+
const { nodes: paths, order } = readInOrder(given, () => sideBySide(all, walk));
|
|
3418
|
+
if (paths !== undefined)
|
|
3419
|
+
return paths.every((path) => path.nodes.length === 0) ? [] : [{ kind: "all", ...order, paths, at }];
|
|
3420
|
+
const method = all.type === "CallExpression" ? memberName(unwrap(all.callee)) ?? "" : "";
|
|
3421
|
+
const { nodes: items, order: ofItems } = readInOrder(given, () => walkExpression(first, inner(walk), !arrayMethods.has(method)));
|
|
3422
|
+
return allOf(items, method === "map", `Effect.all(${textOf(module, first)})`, ofItems, at);
|
|
3423
|
+
}
|
|
3424
|
+
if (effectMethods.repeats.has(name) && first !== undefined && second !== undefined) {
|
|
3425
|
+
const body = walkExpression(first, walk, true);
|
|
3426
|
+
return body.length === 0 ? [] : [{ kind: "repeat", label: `Effect.${name}(${textOf(module, second)})`, nodes: body, at }];
|
|
3427
|
+
}
|
|
3428
|
+
if ((name === "catchTag" || name === "tapErrorTag") && args.length >= 3 || name !== "catchTag" && name !== "tapErrorTag" && isFailureHandler(name) && args.length >= 2) {
|
|
3429
|
+
const reachedBefore = walk.reached.value;
|
|
3430
|
+
const tried = walkExpression(first, walk, true);
|
|
3431
|
+
const ending = walk.top && !reachedBefore && walk.reached.value;
|
|
3432
|
+
return handled(name, tried, args.slice(1), walk, at, ending);
|
|
3433
|
+
}
|
|
3434
|
+
if ((name === "map" || effectMethods.chains.has(name)) && first !== undefined && second !== undefined)
|
|
3435
|
+
return [...walkExpression(first, inner(walk), true), ...walkCallback(second, walk, name !== "map")];
|
|
3436
|
+
if (name === "fail" && first !== undefined)
|
|
3437
|
+
return unwrap(first).type === "NewExpression" ? failureEnd(first, walk) : [...walkExpression(first, inner(walk), false), { kind: "end", fails: true, at }];
|
|
3438
|
+
if (effectMethods.thunks.has(name))
|
|
3439
|
+
return walkCallback(first, walk, name === "suspend" && yielded);
|
|
3440
|
+
if (isRecovery(name) && first !== undefined) {
|
|
3441
|
+
const reachedBefore = walk.reached.value;
|
|
3442
|
+
const tried = walkExpression(first, walk, true);
|
|
3443
|
+
const ending = walk.top && !reachedBefore && walk.reached.value;
|
|
3444
|
+
return recovered(name, tried, args.slice(1), inner(walk), at, ending);
|
|
3445
|
+
}
|
|
3446
|
+
if (name === "if" && first !== undefined && second !== undefined) {
|
|
3447
|
+
const onTrue = propertyOf(resolveValue(second, walk.place), "onTrue", 0);
|
|
3448
|
+
const onFalse = propertyOf(resolveValue(second, walk.place), "onFalse", 0);
|
|
3449
|
+
const paths = [
|
|
3450
|
+
{ label: textOf(module, first), nodes: onTrue === undefined ? [] : walkCallback(onTrue.node, walk, true) },
|
|
3451
|
+
{ label: "else", nodes: onFalse === undefined ? [] : walkCallback(onFalse.node, walk, true) }
|
|
3452
|
+
];
|
|
3453
|
+
return [
|
|
3454
|
+
...walkExpression(first, inner(walk), false),
|
|
3455
|
+
...paths.every((path) => path.nodes.length === 0) ? [] : [{ kind: "branch", ...testedIn([first], walk.place), paths, at }]
|
|
3456
|
+
];
|
|
3457
|
+
}
|
|
3458
|
+
return generic(call, walk);
|
|
3459
|
+
};
|
|
3460
|
+
const walkCall = (call, walk, yielded) => {
|
|
3461
|
+
const callee = unwrap(call.callee);
|
|
3462
|
+
const place = walk.place;
|
|
3463
|
+
if (callee.type === "MemberExpression" && memberName(callee) === "pipe") {
|
|
3464
|
+
const reachedBefore = walk.reached.value;
|
|
3465
|
+
let nodes = walkExpression(callee.object, walk, yielded);
|
|
3466
|
+
const ending = walk.top && !reachedBefore && walk.reached.value;
|
|
3467
|
+
for (const op of call.arguments)
|
|
3468
|
+
nodes = ending && !endsOrWraps(op, walk) ? afterRun(op, inner(walk), nodes) : walkOperator(op, inner(walk), nodes, ending);
|
|
3469
|
+
return nodes;
|
|
3470
|
+
}
|
|
3471
|
+
const value = resolveValue(callee, place);
|
|
3472
|
+
switch (value.kind) {
|
|
3473
|
+
case "sdk": {
|
|
3474
|
+
const lent = lentSteps.get(value.name);
|
|
3475
|
+
if (lent !== undefined)
|
|
3476
|
+
return [...walkArguments(call.arguments, walk), lentStep(value.name, lent, call, walk)];
|
|
3477
|
+
if (value.name === sdkForms.call)
|
|
3478
|
+
return [...walkArguments(call.arguments, walk), childRun(call, walk)];
|
|
3479
|
+
if (value.name === sdkForms.first)
|
|
3480
|
+
return alternatives(call, walk);
|
|
3481
|
+
if (Object.values(sdkForms).includes(value.name))
|
|
3482
|
+
return [];
|
|
3483
|
+
const nodes = generic(call, walk);
|
|
3484
|
+
return yielded ? [...nodes, { kind: "runtime", label: textOf(place.module, callee), at: located(place.module, call) }] : nodes;
|
|
3485
|
+
}
|
|
3486
|
+
case "defined":
|
|
3487
|
+
return [
|
|
3488
|
+
...walkArguments(call.arguments, walk),
|
|
3489
|
+
{
|
|
3490
|
+
kind: "step",
|
|
3491
|
+
step: value.name,
|
|
3492
|
+
names: value.names,
|
|
3493
|
+
defined: true,
|
|
3494
|
+
outline: definedOutline(value, walk),
|
|
3495
|
+
at: located(place.module, call)
|
|
3496
|
+
}
|
|
3497
|
+
];
|
|
3498
|
+
case "indexed":
|
|
3499
|
+
return [
|
|
3500
|
+
...walkArguments(call.arguments, walk),
|
|
3501
|
+
{
|
|
3502
|
+
kind: "step",
|
|
3503
|
+
step: value.name,
|
|
3504
|
+
names: value.step.names,
|
|
3505
|
+
defined: true,
|
|
3506
|
+
outline: value.step.outline,
|
|
3507
|
+
at: located(place.module, call)
|
|
3508
|
+
}
|
|
3509
|
+
];
|
|
3510
|
+
case "agent":
|
|
3511
|
+
return [
|
|
3512
|
+
...walkArguments(call.arguments, walk),
|
|
3513
|
+
{
|
|
3514
|
+
kind: "step",
|
|
3515
|
+
step: sdkForms.agent,
|
|
3516
|
+
names: namesOf(call.arguments[0], place),
|
|
3517
|
+
...value.role === undefined ? { runtime: true } : { agent: value.role },
|
|
3518
|
+
at: located(place.module, call)
|
|
3519
|
+
}
|
|
3520
|
+
];
|
|
3521
|
+
case "external": {
|
|
3522
|
+
const name = effectName(value);
|
|
3523
|
+
return name === undefined ? generic(call, walk) : effectCall(name, call, walk, yielded);
|
|
3524
|
+
}
|
|
3525
|
+
case "fn": {
|
|
3526
|
+
const args = walkArguments(call.arguments, walk);
|
|
3527
|
+
if (walk.stack.includes(value.fn))
|
|
3528
|
+
return [
|
|
3529
|
+
...args,
|
|
3530
|
+
{
|
|
3531
|
+
kind: "runtime",
|
|
3532
|
+
label: `${textOf(place.module, callee)} again, by recursion`,
|
|
3533
|
+
at: located(place.module, call)
|
|
3534
|
+
}
|
|
3535
|
+
];
|
|
3536
|
+
return [
|
|
3537
|
+
...args,
|
|
3538
|
+
...walkFunction(value, callFrame(value, call, place), inner(walk), { ends: false, yielded, top: walk.top })
|
|
3539
|
+
];
|
|
3540
|
+
}
|
|
3541
|
+
default: {
|
|
3542
|
+
const nodes = generic(call, walk);
|
|
3543
|
+
return yielded && (value.kind === "unknown" || value.kind === "service") ? [...nodes, { kind: "runtime", label: textOf(place.module, callee), at: located(place.module, call) }] : nodes;
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
};
|
|
3547
|
+
const walkExpression = (raw, walk, yielded) => {
|
|
3548
|
+
if (raw === null || raw === undefined)
|
|
3549
|
+
return [];
|
|
3550
|
+
const node = unwrap(raw);
|
|
3551
|
+
const within = inner(walk);
|
|
3552
|
+
switch (node.type) {
|
|
3553
|
+
case "YieldExpression": {
|
|
3554
|
+
if (node.argument === null)
|
|
3555
|
+
return [];
|
|
3556
|
+
if (node.delegate && unwrap(node.argument).type === "NewExpression")
|
|
3557
|
+
return failureEnd(node.argument, walk);
|
|
3558
|
+
return walkExpression(node.argument, walk, node.delegate);
|
|
3559
|
+
}
|
|
3560
|
+
case "AwaitExpression":
|
|
3561
|
+
return walkExpression(node.argument, walk, yielded);
|
|
3562
|
+
case "CallExpression":
|
|
3563
|
+
return walkCall(node, walk, yielded);
|
|
3564
|
+
case "NewExpression":
|
|
3565
|
+
return walkArguments(node.arguments, walk);
|
|
3566
|
+
case "ConditionalExpression": {
|
|
3567
|
+
const test = walkExpression(node.test, within, false);
|
|
3568
|
+
const consequent = walkExpression(node.consequent, walk, yielded);
|
|
3569
|
+
const alternate = walkExpression(node.alternate, walk, yielded);
|
|
3570
|
+
if (consequent.length === 0 && alternate.length === 0)
|
|
3571
|
+
return test;
|
|
3572
|
+
return [
|
|
3573
|
+
...test,
|
|
3574
|
+
{
|
|
3575
|
+
kind: "branch",
|
|
3576
|
+
...testedIn([node.test], walk.place),
|
|
3577
|
+
paths: [
|
|
3578
|
+
{ label: textOf(walk.place.module, node.test), nodes: consequent },
|
|
3579
|
+
{ label: "else", nodes: alternate }
|
|
3580
|
+
],
|
|
3581
|
+
at: located(walk.place.module, node)
|
|
3582
|
+
}
|
|
3583
|
+
];
|
|
3584
|
+
}
|
|
3585
|
+
case "LogicalExpression":
|
|
3586
|
+
case "BinaryExpression":
|
|
3587
|
+
return [...walkExpression(node.left, within, false), ...walkExpression(node.right, within, false)];
|
|
3588
|
+
case "AssignmentExpression": {
|
|
3589
|
+
const nodes = walkExpression(node.right, within, false);
|
|
3590
|
+
return node.left.type === "Identifier" ? nameFirsts(nodes, node.left, node.right, walk.place) : nodes;
|
|
3591
|
+
}
|
|
3592
|
+
case "UnaryExpression":
|
|
3593
|
+
case "UpdateExpression":
|
|
3594
|
+
case "SpreadElement":
|
|
3595
|
+
return walkExpression(node.argument, within, false);
|
|
3596
|
+
case "ArrayExpression":
|
|
3597
|
+
return node.elements.flatMap((element) => walkExpression(element, within, false));
|
|
3598
|
+
case "ObjectExpression":
|
|
3599
|
+
return node.properties.flatMap((property) => property.type === "SpreadElement" ? walkExpression(property.argument, within, false) : isFunction(unwrap(property.value)) ? [] : walkExpression(property.value, within, false));
|
|
3600
|
+
case "TemplateLiteral":
|
|
3601
|
+
return node.expressions.flatMap((part) => walkExpression(part, within, false));
|
|
3602
|
+
case "TaggedTemplateExpression":
|
|
3603
|
+
return node.quasi.expressions.flatMap((part) => walkExpression(part, within, false));
|
|
3604
|
+
case "MemberExpression":
|
|
3605
|
+
return [
|
|
3606
|
+
...walkExpression(node.object, within, false),
|
|
3607
|
+
...node.computed ? walkExpression(node.property, within, false) : []
|
|
3608
|
+
];
|
|
3609
|
+
case "SequenceExpression":
|
|
3610
|
+
return node.expressions.flatMap((part) => walkExpression(part, within, false));
|
|
3611
|
+
case "Identifier":
|
|
3612
|
+
return yielded ? yieldedName(node, walk) : [];
|
|
3613
|
+
default:
|
|
3614
|
+
return [];
|
|
3615
|
+
}
|
|
3616
|
+
};
|
|
3617
|
+
const loopLabel = (node, module) => {
|
|
3618
|
+
switch (node.type) {
|
|
3619
|
+
case "ForStatement":
|
|
3620
|
+
return `for (${node.init === null ? "" : textOf(module, node.init)}; ${node.test === null ? "" : textOf(module, node.test)}; ${node.update === null ? "" : textOf(module, node.update)})`;
|
|
3621
|
+
case "ForOfStatement":
|
|
3622
|
+
return `for (${textOf(module, node.left)} of ${textOf(module, node.right)})`;
|
|
3623
|
+
case "ForInStatement":
|
|
3624
|
+
return `for (${textOf(module, node.left)} in ${textOf(module, node.right)})`;
|
|
3625
|
+
case "WhileStatement":
|
|
3626
|
+
return `while (${textOf(module, node.test)})`;
|
|
3627
|
+
case "DoWhileStatement":
|
|
3628
|
+
return `do \u2026 while (${textOf(module, node.test)})`;
|
|
3629
|
+
default:
|
|
3630
|
+
return textOf(module, node);
|
|
3631
|
+
}
|
|
3632
|
+
};
|
|
3633
|
+
const walkStatements = (statements, walk) => {
|
|
3634
|
+
let returned = false;
|
|
3635
|
+
return statements.flatMap((statement) => {
|
|
3636
|
+
const nodes = walkStatement(statement, walk);
|
|
3637
|
+
const marked = returned && !walk.ends && !walk.endsByEffect ? afterReturn(nodes) : nodes;
|
|
3638
|
+
returned ||= statement.type !== "ReturnStatement" && returnsIn(statement);
|
|
3639
|
+
return marked;
|
|
3640
|
+
});
|
|
3641
|
+
};
|
|
3642
|
+
const walkStatement = (statement, walk) => {
|
|
3643
|
+
const module = walk.place.module;
|
|
3644
|
+
const at = located(module, statement);
|
|
3645
|
+
switch (statement.type) {
|
|
3646
|
+
case "ExpressionStatement":
|
|
3647
|
+
return walkExpression(statement.expression, walk, false);
|
|
3648
|
+
case "VariableDeclaration":
|
|
3649
|
+
return statement.declarations.flatMap((declarator) => {
|
|
3650
|
+
if (readWhereYielded(module, declarator))
|
|
3651
|
+
return [];
|
|
3652
|
+
const nodes = walkExpression(declarator.init, inner(walk), false);
|
|
3653
|
+
return declarator.init === null ? nodes : patternNames(declarator.id).reduce((named, { name, path }) => path.every((key) => key === "_tag") ? nameFirsts(named, declarator.id, declarator.init ?? declarator.id, walk.place, name) : named, nodes);
|
|
3654
|
+
});
|
|
3655
|
+
case "ReturnStatement": {
|
|
3656
|
+
if (walk.endsByEffect)
|
|
3657
|
+
return statement.argument === null ? [{ kind: "end", at }] : endingEffect(statement.argument, walk, at);
|
|
3658
|
+
const nodes = walkExpression(statement.argument, walk, walk.returnsYielded);
|
|
3659
|
+
if (!walk.ends)
|
|
3660
|
+
return nodes;
|
|
3661
|
+
const last = nodes.at(-1);
|
|
3662
|
+
if (last?.kind === "end" && endsFailing(last))
|
|
3663
|
+
return nodes;
|
|
3664
|
+
return [...nodes, endOf(statement.argument, walk.place, at)];
|
|
3665
|
+
}
|
|
3666
|
+
case "IfStatement": {
|
|
3667
|
+
const test = walkExpression(statement.test, inner(walk), false);
|
|
3668
|
+
const paths = [];
|
|
3669
|
+
const conditions = [];
|
|
3670
|
+
let current = statement;
|
|
3671
|
+
while (current?.type === "IfStatement") {
|
|
3672
|
+
const condition = current.test;
|
|
3673
|
+
conditions.push(condition);
|
|
3674
|
+
const consequent = walkStatement(current.consequent, walk);
|
|
3675
|
+
paths.push({
|
|
3676
|
+
label: textOf(module, condition),
|
|
3677
|
+
nodes: current === statement ? consequent : [...walkExpression(condition, inner(walk), false), ...consequent]
|
|
3678
|
+
});
|
|
3679
|
+
current = current.alternate;
|
|
3680
|
+
}
|
|
3681
|
+
if (current !== null)
|
|
3682
|
+
paths.push({ label: "else", nodes: walkStatement(current, walk) });
|
|
3683
|
+
return paths.every((path) => path.nodes.length === 0) ? test : [...test, { kind: "branch", ...testedIn(conditions, walk.place), paths, at }];
|
|
3684
|
+
}
|
|
3685
|
+
case "SwitchStatement": {
|
|
3686
|
+
const test = walkExpression(statement.discriminant, inner(walk), false);
|
|
3687
|
+
const subject = textOf(module, statement.discriminant);
|
|
3688
|
+
const paths = [];
|
|
3689
|
+
let labels = [];
|
|
3690
|
+
for (const branch of statement.cases) {
|
|
3691
|
+
labels.push(branch.test === null ? "default" : `${subject} is ${textOf(module, branch.test)}`);
|
|
3692
|
+
if (branch.consequent.length === 0)
|
|
3693
|
+
continue;
|
|
3694
|
+
paths.push({ label: labels.join(" or "), nodes: walkStatements(branch.consequent, walk) });
|
|
3695
|
+
labels = [];
|
|
3696
|
+
}
|
|
3697
|
+
return paths.every((path) => path.nodes.length === 0) ? test : [...test, { kind: "branch", ...testedIn([statement.discriminant], walk.place), paths, at }];
|
|
3698
|
+
}
|
|
3699
|
+
case "ForStatement":
|
|
3700
|
+
case "ForOfStatement":
|
|
3701
|
+
case "ForInStatement":
|
|
3702
|
+
case "WhileStatement":
|
|
3703
|
+
case "DoWhileStatement": {
|
|
3704
|
+
const before = statement.type === "ForOfStatement" || statement.type === "ForInStatement" ? walkExpression(statement.right, inner(walk), false) : statement.type === "ForStatement" && statement.init !== null ? statement.init.type === "VariableDeclaration" ? walkStatement(statement.init, walk) : walkExpression(statement.init, inner(walk), false) : [];
|
|
3705
|
+
const test = statement.type === "ForOfStatement" || statement.type === "ForInStatement" ? [] : walkExpression(statement.test, inner(walk), false);
|
|
3706
|
+
const body = [...test, ...walkStatement(statement.body, walk)];
|
|
3707
|
+
const named = new Set(body.flatMap(namesGiven));
|
|
3708
|
+
const binds = dedupe(boundEachRound(statement.body, module).filter((name) => named.has(name)));
|
|
3709
|
+
return body.length === 0 ? before : [
|
|
3710
|
+
...before,
|
|
3711
|
+
{
|
|
3712
|
+
kind: "repeat",
|
|
3713
|
+
label: loopLabel(statement, module),
|
|
3714
|
+
...binds.length === 0 ? undefined : { binds },
|
|
3715
|
+
nodes: body,
|
|
3716
|
+
at
|
|
3717
|
+
}
|
|
3718
|
+
];
|
|
3719
|
+
}
|
|
3720
|
+
case "BlockStatement":
|
|
3721
|
+
return walkStatements(statement.body, walk);
|
|
3722
|
+
case "TryStatement": {
|
|
3723
|
+
const tried = walkStatements(statement.block.body, walk);
|
|
3724
|
+
const caught = statement.handler === null ? [] : walkStatements(statement.handler.body.body, walk);
|
|
3725
|
+
const settled = statement.finalizer === null ? [] : walkStatements(statement.finalizer.body, walk);
|
|
3726
|
+
if (caught.length === 0)
|
|
3727
|
+
return [...tried, ...settled];
|
|
3728
|
+
return [...failureBranch(tried, [{ label: "catch", nodes: caught }], at), ...settled];
|
|
3729
|
+
}
|
|
3730
|
+
case "LabeledStatement":
|
|
3731
|
+
return walkStatement(statement.body, walk);
|
|
3732
|
+
case "ThrowStatement":
|
|
3733
|
+
return walkExpression(statement.argument, inner(walk), false);
|
|
3734
|
+
default:
|
|
3735
|
+
return [];
|
|
3736
|
+
}
|
|
3737
|
+
};
|
|
3738
|
+
const runOutline = (run) => {
|
|
3739
|
+
const frame = unboundFrame(run);
|
|
3740
|
+
return endingFunction(run, frame, {
|
|
3741
|
+
place: { module: run.place.module, frame },
|
|
3742
|
+
ends: false,
|
|
3743
|
+
endsByEffect: false,
|
|
3744
|
+
returnsYielded: true,
|
|
3745
|
+
top: true,
|
|
3746
|
+
reached: { value: false },
|
|
3747
|
+
stack: []
|
|
3748
|
+
});
|
|
3749
|
+
};
|
|
3750
|
+
const listOf = (found, depth = 0, missed = { value: false }) => {
|
|
3751
|
+
if (found === undefined)
|
|
3752
|
+
return [];
|
|
3753
|
+
const value = depth > maxDepth ? unknown : resolveValue(found.node, found.place);
|
|
3754
|
+
const list = value.kind === "node" ? unwrap(value.node) : undefined;
|
|
3755
|
+
if (value.kind !== "node" || list?.type !== "ArrayExpression") {
|
|
3756
|
+
missed.value = true;
|
|
3757
|
+
return [];
|
|
3758
|
+
}
|
|
3759
|
+
return list.elements.flatMap((element) => {
|
|
3760
|
+
if (element === null)
|
|
3761
|
+
return [];
|
|
3762
|
+
return element.type === "SpreadElement" ? listOf({ node: element.argument, place: value.place }, depth + 1, missed) : [{ node: element, place: value.place }];
|
|
3763
|
+
});
|
|
3764
|
+
};
|
|
3765
|
+
const kitsOf = (kit, seen) => {
|
|
3766
|
+
if (kit.kind !== "node" || seen.has(kit.node))
|
|
3767
|
+
return [];
|
|
3768
|
+
seen.add(kit.node);
|
|
3769
|
+
const listed = propertyOf(kit, "loops", 0);
|
|
3770
|
+
const loops = new Map;
|
|
3771
|
+
for (const { node, place } of listOf(listed)) {
|
|
3772
|
+
const definition = resolveValue(node, place);
|
|
3773
|
+
const idNode = propertyOf(definition, "id", 0);
|
|
3774
|
+
const id = idNode === undefined ? undefined : literalName(idNode.node, idNode.place);
|
|
3775
|
+
if (id === undefined || loops.has(id))
|
|
3776
|
+
continue;
|
|
3777
|
+
const runNode = propertyOf(definition, "run", 0);
|
|
3778
|
+
const run = runNode === undefined ? unknown : resolveValue(runNode.node, runNode.place);
|
|
3779
|
+
loops.set(id, run.kind === "fn" ? runOutline(run) : [{ kind: "runtime", label: `${id}'s run`, at: located(place.module, node) }]);
|
|
3780
|
+
}
|
|
3781
|
+
const extended = propertyOf(kit, "extends", 0);
|
|
3782
|
+
const missed = { value: false };
|
|
3783
|
+
const extendedKits = listOf(extended, 0, missed).map(({ node, place }) => {
|
|
3784
|
+
const value = resolveValue(node, place);
|
|
3785
|
+
if (value.kind !== "node")
|
|
3786
|
+
missed.value = true;
|
|
3787
|
+
return value;
|
|
3788
|
+
});
|
|
3789
|
+
const own = {
|
|
3790
|
+
kit: kit.place.module.kit,
|
|
3791
|
+
version: kit.place.module.version,
|
|
3792
|
+
at: located(listed?.place.module ?? kit.place.module, listed?.node ?? kit.node),
|
|
3793
|
+
extendsAt: located(extended?.place.module ?? kit.place.module, extended?.node ?? kit.node),
|
|
3794
|
+
extendsUnread: missed.value,
|
|
3795
|
+
loops
|
|
3796
|
+
};
|
|
3797
|
+
return [own, ...extendedKits.flatMap((value) => kitsOf(value, seen))];
|
|
3798
|
+
};
|
|
3799
|
+
const kits = () => {
|
|
3800
|
+
const entry = moduleAt(graph.entry);
|
|
3801
|
+
return entry === undefined ? [] : kitsOf(resolveExport(entry, "default", 0), new Set);
|
|
3802
|
+
};
|
|
3803
|
+
return {
|
|
3804
|
+
kits,
|
|
3805
|
+
loops: () => {
|
|
3806
|
+
const outlines = new Map;
|
|
3807
|
+
for (const kit of kits())
|
|
3808
|
+
for (const [id, outline] of kit.loops)
|
|
3809
|
+
if (!outlines.has(id))
|
|
3810
|
+
outlines.set(id, outline);
|
|
3811
|
+
return outlines;
|
|
3812
|
+
}
|
|
3813
|
+
};
|
|
3814
|
+
};
|
|
3815
|
+
var readLoopOutlines = (graph) => outlineReader(graph).loops();
|
|
3816
|
+
var readKitOutlines = (graph) => outlineReader(graph).kits();
|
|
3817
|
+
|
|
3818
|
+
// packages/sdk/src/build/outline/index.ts
|
|
3819
|
+
class AgentUndeclared extends TaggedError2()("AgentUndeclared", {
|
|
3820
|
+
loop: String4,
|
|
3821
|
+
agent: String4,
|
|
3822
|
+
at: String4
|
|
3823
|
+
}) {
|
|
3824
|
+
get message() {
|
|
3825
|
+
return `Loop "${this.loop}" runs an agent Step as "${this.agent}" at ${this.at}, which its agents do not declare; add "${this.agent}" to the Loop's agents or call an agent it declares`;
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3828
|
+
|
|
3829
|
+
class OutlineUnread extends TaggedError2()("OutlineUnread", { reason: String4 }) {
|
|
3830
|
+
get message() {
|
|
3831
|
+
return `The Kit's Loops do not read for their outlines: ${this.reason}`;
|
|
3832
|
+
}
|
|
3833
|
+
}
|
|
3834
|
+
var readGraph = (root, read) => loadGraph(root).pipe(map9(read), mapError2((error) => new OutlineUnread({ reason: error.message })));
|
|
3835
|
+
var readOutlines = (root) => readGraph(root, readLoopOutlines);
|
|
3836
|
+
var readKitsOutlines = (root) => readGraph(root, readKitOutlines);
|
|
3837
|
+
var outlineSteps = (outline) => outline.flatMap((node) => {
|
|
3838
|
+
switch (node.kind) {
|
|
3839
|
+
case "step":
|
|
3840
|
+
return [node, ...outlineSteps(node.outline ?? [])];
|
|
3841
|
+
case "branch":
|
|
3842
|
+
return [...outlineSteps(node.nodes ?? []), ...node.paths.flatMap((path) => outlineSteps(path.nodes))];
|
|
3843
|
+
case "all":
|
|
3844
|
+
case "first":
|
|
3845
|
+
return node.paths.flatMap((path) => outlineSteps(path.nodes));
|
|
3846
|
+
case "repeat":
|
|
3847
|
+
case "many":
|
|
3848
|
+
return outlineSteps(node.nodes);
|
|
3849
|
+
default:
|
|
3850
|
+
return [];
|
|
3851
|
+
}
|
|
3852
|
+
});
|
|
3853
|
+
var undeclaredAgent = (loop, outline, agents) => {
|
|
3854
|
+
const step = outlineSteps(outline).find((found) => found.agent !== undefined && !Object.hasOwn(agents, found.agent));
|
|
3855
|
+
return step?.agent === undefined ? undefined : new AgentUndeclared({ loop, agent: step.agent, at: step.at });
|
|
3856
|
+
};
|
|
3857
|
+
// packages/sdk/src/build/index.ts
|
|
3858
|
+
class DependencyInstallFailed extends TaggedError2()("DependencyInstallFailed", {
|
|
3859
|
+
reason: String4
|
|
3860
|
+
}) {
|
|
3861
|
+
get message() {
|
|
3862
|
+
return `Dependencies do not install from the lockfile: ${this.reason}`;
|
|
3863
|
+
}
|
|
3864
|
+
}
|
|
3865
|
+
|
|
3866
|
+
class BundleFailed extends TaggedError2()("BundleFailed", { reason: String4 }) {
|
|
3867
|
+
get message() {
|
|
3868
|
+
return `The Kit does not bundle: ${this.reason}`;
|
|
3869
|
+
}
|
|
3870
|
+
}
|
|
3871
|
+
|
|
3872
|
+
class DeclarationsInvalid extends TaggedError2()("DeclarationsInvalid", {
|
|
3873
|
+
reason: String4
|
|
3874
|
+
}) {
|
|
3875
|
+
get message() {
|
|
3876
|
+
return `The Kit's declarations are invalid: ${this.reason}`;
|
|
3877
|
+
}
|
|
3878
|
+
}
|
|
3879
|
+
|
|
3880
|
+
class SourceFetchFailed extends TaggedError2()("SourceFetchFailed", {
|
|
3881
|
+
reason: String4
|
|
3882
|
+
}) {
|
|
3883
|
+
get message() {
|
|
3884
|
+
return `A setup source does not fetch: ${this.reason}`;
|
|
3885
|
+
}
|
|
3886
|
+
}
|
|
3887
|
+
var RepositoryText = Union([String4, Struct({ file: String4 })]);
|
|
3888
|
+
var ConfigAgents = Record(String4, Struct({
|
|
3889
|
+
...AgentDeclaration.fields,
|
|
3890
|
+
instructions: optionalKey(RepositoryText)
|
|
3891
|
+
}));
|
|
3892
|
+
var run = (command, args, cwd) => gen(function* () {
|
|
3893
|
+
const spawner = yield* ChildProcessSpawner;
|
|
3894
|
+
const handle = yield* spawner.spawn(make3(command, args, { cwd, stdin: "ignore" }));
|
|
3895
|
+
const [stdout, stderr, exitCode] = yield* all3([
|
|
3896
|
+
mkString(decodeText(handle.stdout)),
|
|
3897
|
+
mkString(decodeText(handle.stderr)),
|
|
3898
|
+
handle.exitCode
|
|
3899
|
+
], { concurrency: 3 });
|
|
3900
|
+
return { stdout, stderr, ok: exitCode === 0 };
|
|
3901
|
+
}).pipe(scoped);
|
|
3902
|
+
var failure = (result) => (result.stderr.trim() || result.stdout.trim()).slice(-2000);
|
|
3903
|
+
var provenance = (directory) => gen(function* () {
|
|
3904
|
+
const git = (...args) => run("git", args, directory).pipe(map9((result) => result.ok ? result.stdout.trim() : undefined), orElseSucceed(() => {
|
|
3905
|
+
return;
|
|
3906
|
+
}));
|
|
3907
|
+
const repository = yield* git("remote", "get-url", "origin");
|
|
3908
|
+
const commit = yield* git("rev-parse", "HEAD");
|
|
3909
|
+
const status = yield* git("status", "--porcelain");
|
|
3910
|
+
return {
|
|
3911
|
+
...repository ? { repository } : undefined,
|
|
3912
|
+
...commit ? { commit } : undefined,
|
|
3913
|
+
clean: commit !== undefined && status === ""
|
|
3914
|
+
};
|
|
3915
|
+
});
|
|
3916
|
+
var inKit = (directory, file, what) => gen(function* () {
|
|
3917
|
+
const path = yield* Path;
|
|
3918
|
+
const resolved = path.resolve(directory, file);
|
|
3919
|
+
if (path.relative(directory, resolved).startsWith(".."))
|
|
3920
|
+
return yield* new DeclarationsInvalid({ reason: `${what} ${file} is outside the Kit` });
|
|
3921
|
+
return resolved;
|
|
3922
|
+
});
|
|
3923
|
+
var readText = (directory, text, what) => gen(function* () {
|
|
3924
|
+
if (isString(text))
|
|
3925
|
+
return text;
|
|
3926
|
+
const fs = yield* FileSystem;
|
|
3927
|
+
const file = yield* inKit(directory, text.file, what);
|
|
3928
|
+
return yield* fs.readFileString(file).pipe(mapError2(() => new DeclarationsInvalid({ reason: `${what} ${text.file} does not read` })));
|
|
3929
|
+
});
|
|
3930
|
+
var readAgents = (directory, agents) => forEach(Object.entries(agents), ([id, { instructions, ...agent }]) => instructions === undefined ? succeed6([id, agent]) : map9(readText(directory, instructions, `Agent "${id}" instructions`), (text) => [id, { ...agent, instructions: text.trim() }])).pipe(map9(Object.fromEntries));
|
|
3931
|
+
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
3932
|
+
var setupFile = (bytes) => {
|
|
3933
|
+
try {
|
|
3934
|
+
const text = utf8.decode(bytes);
|
|
3935
|
+
return text.includes("\x00") ? { base64: encode2(bytes) } : { utf8: text };
|
|
3936
|
+
} catch {
|
|
3937
|
+
return { base64: encode2(bytes) };
|
|
3938
|
+
}
|
|
3939
|
+
};
|
|
3940
|
+
var confined = (boundary, file, what) => gen(function* () {
|
|
3941
|
+
const fs = yield* FileSystem;
|
|
3942
|
+
const path = yield* Path;
|
|
3943
|
+
const unreadable = () => new DeclarationsInvalid({ reason: `${what} does not read` });
|
|
3944
|
+
const real = yield* fs.realPath(path.join(boundary, file)).pipe(mapError2(unreadable));
|
|
3945
|
+
if (path.relative(yield* fs.realPath(boundary).pipe(mapError2(unreadable)), real).startsWith(".."))
|
|
3946
|
+
return yield* new DeclarationsInvalid({ reason: `${what}: ${file} links outside its source` });
|
|
3947
|
+
return real;
|
|
3948
|
+
});
|
|
3949
|
+
var readTree = (root, what, fetched = false) => gen(function* () {
|
|
3950
|
+
const fs = yield* FileSystem;
|
|
3951
|
+
const path = yield* Path;
|
|
3952
|
+
const unreadable = () => new DeclarationsInvalid({ reason: `${what} does not read` });
|
|
3953
|
+
const entries = yield* fs.readDirectory(root, { recursive: true }).pipe(mapError2(unreadable));
|
|
3954
|
+
const files = {};
|
|
3955
|
+
for (const entry of entries.toSorted()) {
|
|
3956
|
+
const relative = entry.split(path.sep).join("/");
|
|
3957
|
+
if (relative === ".git" || relative.startsWith(".git/"))
|
|
3958
|
+
continue;
|
|
3959
|
+
const file = fetched ? yield* confined(root, entry, what) : path.join(root, entry);
|
|
3960
|
+
if ((yield* fs.stat(file).pipe(mapError2(unreadable))).type !== "File")
|
|
3961
|
+
continue;
|
|
3962
|
+
files[relative] = yield* fs.readFile(file).pipe(mapError2(unreadable));
|
|
3963
|
+
}
|
|
3964
|
+
return files;
|
|
3965
|
+
});
|
|
3966
|
+
var licenseFiles = ["LICENSE", "LICENSE.md", "LICENSE.txt", "COPYING"];
|
|
3967
|
+
var fetchedTree = (root, path, what) => gen(function* () {
|
|
3968
|
+
const fs = yield* FileSystem;
|
|
3969
|
+
const paths = yield* Path;
|
|
3970
|
+
const tree = yield* readTree(path === undefined ? root : yield* confined(root, path, what), what, true);
|
|
3971
|
+
if (path === undefined)
|
|
3972
|
+
return tree;
|
|
3973
|
+
for (const license of licenseFiles)
|
|
3974
|
+
if (tree[license] === undefined && (yield* fs.exists(paths.join(root, license))))
|
|
3975
|
+
return { ...tree, [license]: yield* fs.readFile(yield* confined(root, license, what)).pipe(orDie) };
|
|
3976
|
+
return tree;
|
|
3977
|
+
});
|
|
3978
|
+
var GitSourceLocation = Reference("kitman/sdk/build/GitSourceLocation", { defaultValue: () => (declared) => declared });
|
|
3979
|
+
var fetchGit = (declared, what) => gen(function* () {
|
|
3980
|
+
const fs = yield* FileSystem;
|
|
3981
|
+
const { url, ref } = (yield* GitSourceLocation)(declared);
|
|
3982
|
+
const checkout = yield* fs.makeTempDirectoryScoped({ prefix: "kitman-git-" });
|
|
3983
|
+
for (const args of [
|
|
3984
|
+
["init", "--quiet"],
|
|
3985
|
+
["fetch", "--quiet", "--depth", "1", "--", url, ref ?? "HEAD"],
|
|
3986
|
+
["checkout", "--quiet", "FETCH_HEAD"]
|
|
3987
|
+
]) {
|
|
3988
|
+
const result = yield* run("git", args, checkout);
|
|
3989
|
+
if (!result.ok)
|
|
3990
|
+
return yield* new SourceFetchFailed({
|
|
3991
|
+
reason: `${what}: git ${url}${ref === undefined ? "" : ` at ${ref}`}: ${failure(result)}`
|
|
3992
|
+
});
|
|
3993
|
+
}
|
|
3994
|
+
return checkout;
|
|
3995
|
+
});
|
|
3996
|
+
var fetchNpm = (name, wanted, what) => gen(function* () {
|
|
3997
|
+
const fs = yield* FileSystem;
|
|
3998
|
+
const path = yield* Path;
|
|
3999
|
+
const registry = yield* String2("NPM_CONFIG_REGISTRY").pipe(withDefault("https://registry.npmjs.org"), orDie);
|
|
4000
|
+
const failed = (reason) => new SourceFetchFailed({ reason: `${what}: npm ${name}@${wanted}: ${reason}` });
|
|
4001
|
+
const packument = yield* get2(`${registry.replace(/\/+$/, "")}/${name.replace("/", "%2F")}`).pipe(flatMap3(filterStatusOk), flatMap3(schemaBodyJson(Packument)), mapError2((error) => failed(error.message)));
|
|
4002
|
+
const dist = packument.versions[packument["dist-tags"][wanted] ?? wanted]?.dist;
|
|
4003
|
+
if (dist === undefined)
|
|
4004
|
+
return yield* failed("npm has no such version or dist-tag");
|
|
4005
|
+
const tarball = yield* get2(dist.tarball).pipe(flatMap3(filterStatusOk), flatMap3((response) => response.arrayBuffer), map9((buffer) => new Uint8Array(buffer)), mapError2((error) => failed(error.message)));
|
|
4006
|
+
if (!tarballMatches(tarball, dist))
|
|
4007
|
+
return yield* failed(`the tarball does not match its integrity ${dist.integrity ?? `sha1 ${dist.shasum}`}`);
|
|
4008
|
+
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "kitman-npm-" });
|
|
4009
|
+
yield* fs.writeFile(path.join(directory, "package.tgz"), tarball).pipe(orDie);
|
|
4010
|
+
const extracted = yield* run("tar", ["-xzf", "package.tgz"], directory);
|
|
4011
|
+
if (!extracted.ok)
|
|
4012
|
+
return yield* failed(`the tarball does not extract: ${failure(extracted)}`);
|
|
4013
|
+
return yield* confined(directory, "package", what);
|
|
4014
|
+
}).pipe(provide3(layer4));
|
|
4015
|
+
var sourceTree = (directory, source, what, checkouts) => gen(function* () {
|
|
4016
|
+
switch (source.kind) {
|
|
4017
|
+
case "local_path":
|
|
4018
|
+
return yield* readTree(yield* inKit(directory, source.path, what), what);
|
|
4019
|
+
case "git": {
|
|
4020
|
+
const key = `${source.url}#${source.ref ?? ""}`;
|
|
4021
|
+
const checkout = checkouts.get(key) ?? (yield* fetchGit({ url: source.url, ref: source.ref }, what));
|
|
4022
|
+
checkouts.set(key, checkout);
|
|
4023
|
+
return yield* fetchedTree(checkout, "path" in source ? source.path : undefined, what);
|
|
4024
|
+
}
|
|
4025
|
+
case "package":
|
|
4026
|
+
return yield* fetchedTree(yield* fetchNpm(source.packageName, source.version ?? "latest", what), "path" in source ? source.path : undefined, what);
|
|
4027
|
+
default:
|
|
4028
|
+
return yield* new DeclarationsInvalid({
|
|
4029
|
+
reason: `${what} comes from a ${source.kind} source, which a build cannot copy in; use a local path, git or npm`
|
|
4030
|
+
});
|
|
4031
|
+
}
|
|
4032
|
+
});
|
|
4033
|
+
var setupArchive = (directory, kit, setup, checkouts) => gen(function* () {
|
|
4034
|
+
const fs = yield* FileSystem;
|
|
4035
|
+
const files = {};
|
|
4036
|
+
const place = (prefix, tree) => {
|
|
4037
|
+
for (const [file, bytes] of Object.entries(tree))
|
|
4038
|
+
files[`${prefix}/${file}`] = setupFile(bytes);
|
|
4039
|
+
return { kind: "local_path", path: prefix };
|
|
4040
|
+
};
|
|
4041
|
+
if (setup.instructions !== undefined) {
|
|
4042
|
+
const what = `Kit ${kit} instructions`;
|
|
4043
|
+
const file = yield* inKit(directory, setup.instructions, what);
|
|
4044
|
+
files["instructions.md"] = setupFile(yield* fs.readFile(file).pipe(mapError2(() => new DeclarationsInvalid({ reason: `${what} do not read` }))));
|
|
4045
|
+
}
|
|
4046
|
+
const skills = setup.skills === undefined ? undefined : yield* forEach(setup.skills, (skill) => map9(sourceTree(directory, skill.source, `Kit ${kit} skill ${skill.name}`, checkouts), (tree) => ({
|
|
4047
|
+
...skill,
|
|
4048
|
+
source: place(`skills/${skill.name}`, tree)
|
|
4049
|
+
})));
|
|
4050
|
+
const plugins = setup.plugins === undefined ? undefined : yield* forEach(setup.plugins, (plugin) => map9(sourceTree(directory, plugin.sources[0], `Kit ${kit} plugin ${plugin.name}`, checkouts), (tree) => ({
|
|
4051
|
+
...plugin,
|
|
4052
|
+
sources: [place(`plugins/${plugin.name}`, tree)]
|
|
4053
|
+
})));
|
|
4054
|
+
const archive = {
|
|
4055
|
+
setup: {
|
|
4056
|
+
...setup,
|
|
4057
|
+
...setup.instructions === undefined ? undefined : { instructions: "instructions.md" },
|
|
4058
|
+
...skills === undefined ? undefined : { skills },
|
|
4059
|
+
...plugins === undefined ? undefined : { plugins }
|
|
4060
|
+
},
|
|
4061
|
+
files
|
|
4062
|
+
};
|
|
4063
|
+
const bytes = new TextEncoder().encode(canonicalJson(archive));
|
|
4064
|
+
return { digest: digestSha256(bytes, "hex"), archive: bytes };
|
|
4065
|
+
});
|
|
4066
|
+
var PackageJson = fromJsonString(Struct({
|
|
4067
|
+
name: String4,
|
|
4068
|
+
version: optionalKey(String4),
|
|
4069
|
+
dependencies: optionalKey(Record(String4, String4))
|
|
4070
|
+
}));
|
|
4071
|
+
var readPackageJson = (directory) => gen(function* () {
|
|
4072
|
+
const fs = yield* FileSystem;
|
|
4073
|
+
const path = yield* Path;
|
|
4074
|
+
return yield* fs.readFileString(path.join(directory, "package.json")).pipe(flatMap3(decodeEffect(PackageJson)), mapError2(() => new DeclarationsInvalid({ reason: `${directory}/package.json has no name` })));
|
|
4075
|
+
});
|
|
4076
|
+
var identityOf = (manifest) => ({
|
|
4077
|
+
name: manifest.name,
|
|
4078
|
+
version: manifest.version ?? "0.0.0"
|
|
4079
|
+
});
|
|
4080
|
+
var installedPackage = (name, directory) => gen(function* () {
|
|
4081
|
+
const fs = yield* FileSystem;
|
|
4082
|
+
const path = yield* Path;
|
|
4083
|
+
for (let at = directory;; at = path.dirname(at)) {
|
|
4084
|
+
const candidate = path.join(at, "node_modules", name);
|
|
4085
|
+
if (yield* fs.exists(path.join(candidate, "package.json")))
|
|
4086
|
+
return yield* fs.realPath(candidate);
|
|
4087
|
+
if (path.dirname(at) === at)
|
|
4088
|
+
return;
|
|
4089
|
+
}
|
|
4090
|
+
});
|
|
4091
|
+
var importedFile = (file, specifier) => gen(function* () {
|
|
4092
|
+
const fs = yield* FileSystem;
|
|
4093
|
+
const path = yield* Path;
|
|
4094
|
+
const target = path.resolve(path.dirname(file), specifier);
|
|
4095
|
+
for (const candidate of [target, `${target}.ts`, path.join(target, "kitman.config.ts")])
|
|
4096
|
+
if (yield* fs.stat(candidate).pipe(map9((info) => info.type === "File"), orElseSucceed(() => false)))
|
|
4097
|
+
return candidate;
|
|
4098
|
+
return;
|
|
4099
|
+
});
|
|
4100
|
+
var packageDirectory = (file) => gen(function* () {
|
|
4101
|
+
const fs = yield* FileSystem;
|
|
4102
|
+
const path = yield* Path;
|
|
4103
|
+
for (let at = path.dirname(file);; at = path.dirname(at)) {
|
|
4104
|
+
if (yield* fs.exists(path.join(at, "package.json")).pipe(orElseSucceed(() => false)))
|
|
4105
|
+
return at;
|
|
4106
|
+
if (path.dirname(at) === at)
|
|
4107
|
+
return;
|
|
4108
|
+
}
|
|
4109
|
+
});
|
|
4110
|
+
var kitModules = (root) => gen(function* () {
|
|
4111
|
+
const fs = yield* FileSystem;
|
|
4112
|
+
const path = yield* Path;
|
|
4113
|
+
const found = [];
|
|
4114
|
+
const visited = new Set;
|
|
4115
|
+
const packages = new Set([root]);
|
|
4116
|
+
const known = (directory) => packages.has(directory);
|
|
4117
|
+
const visitPackage = (directory) => gen(function* () {
|
|
4118
|
+
for (const name of Object.keys((yield* readPackageJson(directory)).dependencies ?? {})) {
|
|
4119
|
+
const installed = yield* installedPackage(name, directory).pipe(orElseSucceed(() => {
|
|
4120
|
+
return;
|
|
4121
|
+
}));
|
|
4122
|
+
const module = installed === undefined ? undefined : path.join(installed, "kitman.config.ts");
|
|
4123
|
+
if (installed === undefined || module === undefined || known(installed))
|
|
4124
|
+
continue;
|
|
4125
|
+
if (!(yield* fs.exists(module).pipe(orElseSucceed(() => false))))
|
|
4126
|
+
continue;
|
|
4127
|
+
packages.add(installed);
|
|
4128
|
+
found.push({ directory: installed, module, identity: identityOf(yield* readPackageJson(installed)) });
|
|
4129
|
+
yield* visitPackage(installed);
|
|
4130
|
+
yield* visitImports(module);
|
|
4131
|
+
}
|
|
4132
|
+
});
|
|
4133
|
+
const visitImports = (file) => gen(function* () {
|
|
4134
|
+
if (visited.has(file))
|
|
4135
|
+
return;
|
|
4136
|
+
visited.add(file);
|
|
4137
|
+
const transpiled = yield* run("bun", ["build", "--no-bundle", file], root).pipe(map9((result) => result.ok ? result.stdout : ""), orElseSucceed(() => ""));
|
|
4138
|
+
for (const [, specifier] of transpiled.matchAll(/\b(?:from|import)\s*"(\.{1,2}\/[^"]+)"/gu)) {
|
|
4139
|
+
const module = specifier === undefined ? undefined : yield* importedFile(file, specifier);
|
|
4140
|
+
if (module === undefined || visited.has(module))
|
|
4141
|
+
continue;
|
|
4142
|
+
const directory = yield* packageDirectory(module);
|
|
4143
|
+
if (directory !== undefined && directory !== root) {
|
|
4144
|
+
found.push({ directory, module, identity: identityOf(yield* readPackageJson(directory)) });
|
|
4145
|
+
if (!known(directory)) {
|
|
4146
|
+
packages.add(directory);
|
|
4147
|
+
yield* visitPackage(directory);
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
4150
|
+
yield* visitImports(module);
|
|
4151
|
+
}
|
|
4152
|
+
});
|
|
4153
|
+
yield* visitPackage(root);
|
|
4154
|
+
yield* visitImports(path.join(root, "kitman.config.ts"));
|
|
4155
|
+
return found;
|
|
4156
|
+
});
|
|
4157
|
+
var ownSteps = (root, steps) => gen(function* () {
|
|
4158
|
+
const fs = yield* FileSystem;
|
|
4159
|
+
const path = yield* Path;
|
|
4160
|
+
const rootPackage = yield* fs.realPath(root);
|
|
4161
|
+
return yield* filter3(steps, (step) => step.definedAt === undefined ? succeed6(true) : fs.realPath(path.resolve(root, step.definedAt.replace(/:\d+:\d+$/u, "").replace(/^file:\/\//u, ""))).pipe(flatMap3(packageDirectory), map9((directory) => directory === rootPackage), orElseSucceed(() => false)));
|
|
4162
|
+
});
|
|
4163
|
+
var buildEntry = (identity, modules) => [
|
|
4164
|
+
"import config from './kitman.config.ts'",
|
|
4165
|
+
"import { runKit } from '@kitman-sh/sdk/program'",
|
|
4166
|
+
...modules.map((kit, index) => `import * as kit${index} from ${JSON.stringify(kit.module)}`),
|
|
4167
|
+
"",
|
|
4168
|
+
`runKit(config, ${JSON.stringify(identity)}, [${modules.map((kit, index) => `[kit${index}.default, ${JSON.stringify(kit.identity)}]`).join(", ")}])`,
|
|
4169
|
+
""
|
|
4170
|
+
].join(`
|
|
4171
|
+
`);
|
|
4172
|
+
var renamedKey = (declarations, what, from, to) => {
|
|
4173
|
+
const key = Object.keys(declarations ?? {}).find((key) => hasProperty(declarations?.[key], from));
|
|
4174
|
+
return key === undefined ? undefined : new DeclarationsInvalid({ reason: `${what} "${key}" names \`${from}\`, which is now \`${to}\`` });
|
|
4175
|
+
};
|
|
4176
|
+
var resolveNames = (names) => {
|
|
4177
|
+
const winners = new Map;
|
|
4178
|
+
const overrides = [];
|
|
4179
|
+
for (const named of names) {
|
|
4180
|
+
const key = `${named.what}\x00${named.name}`;
|
|
4181
|
+
const winner = winners.get(key);
|
|
4182
|
+
if (winner === undefined)
|
|
4183
|
+
winners.set(key, named.kit);
|
|
4184
|
+
else if (winner === named.kit)
|
|
4185
|
+
return new DeclarationsInvalid({ reason: `Kit ${named.kit} names ${named.what} ${named.name} twice` });
|
|
4186
|
+
else
|
|
4187
|
+
overrides.push({ what: named.what, name: named.name, winner, replaced: named.kit });
|
|
4188
|
+
}
|
|
4189
|
+
return { wins: (named) => winners.get(`${named.what}\x00${named.name}`) === named.kit, overrides };
|
|
4190
|
+
};
|
|
4191
|
+
var buildKit = (directory, options = {}) => gen(function* () {
|
|
4192
|
+
const fs = yield* FileSystem;
|
|
4193
|
+
const path = yield* Path;
|
|
4194
|
+
const root = path.resolve(directory);
|
|
4195
|
+
const source = yield* provenance(root);
|
|
4196
|
+
const identity = { ...identityOf(yield* readPackageJson(root)), ...options };
|
|
4197
|
+
const installed = yield* run("bun", ["install", "--frozen-lockfile", "--ignore-scripts"], root).pipe(mapError2((error) => new DependencyInstallFailed({ reason: error.message })));
|
|
4198
|
+
if (!installed.ok)
|
|
4199
|
+
return yield* new DependencyInstallFailed({ reason: failure(installed) });
|
|
4200
|
+
const packages = yield* kitModules(root);
|
|
4201
|
+
const id = yield* SecureRandom.pipe(flatMap3((random) => random.uuidV4()), provide3(layerWebCrypto));
|
|
4202
|
+
const entryName = `.kitman-build-entry-${id}.ts`;
|
|
4203
|
+
const entry = path.join(root, entryName);
|
|
4204
|
+
yield* acquireRelease(fs.writeFileString(entry, buildEntry(identity, packages)), () => ignore(fs.remove(entry)));
|
|
4205
|
+
const out = yield* fs.makeTempDirectoryScoped({ prefix: "kitman-kit-" });
|
|
4206
|
+
const bundleFile = path.join(out, "bundle.js");
|
|
4207
|
+
const bundled = yield* run("bun", ["build", entry, "--target=bun", "--format=esm", "--outfile", bundleFile], root);
|
|
4208
|
+
if (!bundled.ok)
|
|
4209
|
+
return yield* failure(bundled).includes('"defineConfig"') ? new DeclarationsInvalid({
|
|
4210
|
+
reason: "defineConfig is now defineKit; import defineKit from @kitman-sh/sdk/loop"
|
|
4211
|
+
}) : new BundleFailed({ reason: failure(bundled) });
|
|
4212
|
+
const described = yield* run("bun", [bundleFile, describeFlag], out);
|
|
4213
|
+
if (!described.ok)
|
|
4214
|
+
return yield* new BundleFailed({ reason: `the bundle does not load: ${failure(described)}` });
|
|
4215
|
+
const result = yield* decodeEffect(fromJsonString(toCodecJson(Described)))(described.stdout).pipe(mapError2((error) => new BundleFailed({ reason: `the bundle described itself wrongly: ${error.message}` })));
|
|
4216
|
+
if (isTagged(result, "Refused"))
|
|
4217
|
+
return yield* result.error;
|
|
4218
|
+
const [own] = result.kits;
|
|
4219
|
+
if (own === undefined)
|
|
4220
|
+
return yield* new BundleFailed({ reason: "the bundle described no Kit" });
|
|
4221
|
+
const renamed = renamedKey(own.schedules, "Schedule", "project", "team") ?? renamedKey(own.schedules, "Schedule", "codebase", "team");
|
|
4222
|
+
if (renamed !== undefined)
|
|
4223
|
+
return yield* renamed;
|
|
4224
|
+
const directories = new Map([
|
|
4225
|
+
[`${identity.name}@${identity.version}`, root],
|
|
4226
|
+
...packages.map((kit) => [`${kit.identity.name}@${kit.identity.version}`, kit.directory])
|
|
4227
|
+
]);
|
|
4228
|
+
const kits = yield* forEach(result.kits, (kit) => gen(function* () {
|
|
4229
|
+
const at = directories.get(`${kit.name}@${kit.version}`) ?? root;
|
|
4230
|
+
const invalid = (error) => new DeclarationsInvalid({ reason: `Kit ${kit.name}: ${error.message}` });
|
|
4231
|
+
const agents = yield* decodeUnknownEffect2(ConfigAgents)(kit.agents).pipe(mapError2(invalid));
|
|
4232
|
+
return { ...kit, directory: at, agents: yield* readAgents(at, agents), setup: kit.setup ?? {} };
|
|
4233
|
+
}));
|
|
4234
|
+
const steps = yield* ownSteps(root, result.steps ?? []);
|
|
4235
|
+
const twice = stepDefinedTwice(steps);
|
|
4236
|
+
if (twice !== undefined)
|
|
4237
|
+
return yield* twice;
|
|
4238
|
+
const named = kits.flatMap((kit) => [
|
|
4239
|
+
...kit.loops.map((loop) => ({ kit: kit.name, what: "Loop", name: loop.id })),
|
|
4240
|
+
...Object.keys(kit.agents).map((agent) => ({ kit: kit.name, what: "Agent", name: agent })),
|
|
4241
|
+
...(kit.setup.skills ?? []).map((skill) => ({ kit: kit.name, what: "skill", name: skill.name })),
|
|
4242
|
+
...(kit.setup.plugins ?? []).map((plugin) => ({ kit: kit.name, what: "plugin", name: plugin.name })),
|
|
4243
|
+
...(kit.setup.mcpServers ?? []).map((server) => ({ kit: kit.name, what: "MCP server", name: server.name }))
|
|
4244
|
+
]);
|
|
4245
|
+
const kitman = named.find((entry) => entry.what === "MCP server" && entry.name === kitmanMcpServer);
|
|
4246
|
+
if (kitman !== undefined)
|
|
4247
|
+
return yield* new DeclarationsInvalid({
|
|
4248
|
+
reason: `Kit ${kitman.kit} declares an MCP server named ${kitmanMcpServer}, which Kitman provides`
|
|
4249
|
+
});
|
|
4250
|
+
const names = resolveNames(named);
|
|
4251
|
+
if (isTagged(names, "DeclarationsInvalid"))
|
|
4252
|
+
return yield* names;
|
|
4253
|
+
const winning = kits.map((kit) => ({
|
|
4254
|
+
...kit,
|
|
4255
|
+
loops: kit.loops.filter((loop) => names.wins({ kit: kit.name, what: "Loop", name: loop.id })),
|
|
4256
|
+
agents: Object.fromEntries(Object.entries(kit.agents).filter(([agent]) => names.wins({ kit: kit.name, what: "Agent", name: agent })))
|
|
4257
|
+
}));
|
|
4258
|
+
const checkouts = new Map;
|
|
4259
|
+
const archives = yield* forEach(kits, (kit) => setupArchive(kit.directory, kit.name, kit.setup, checkouts));
|
|
4260
|
+
const carried = winning.map((kit, index) => ({
|
|
4261
|
+
name: kit.name,
|
|
4262
|
+
version: kit.version,
|
|
4263
|
+
setup: archives[index]?.digest ?? "",
|
|
4264
|
+
loops: kit.loops.map((loop) => loop.id),
|
|
4265
|
+
agents: Object.keys(kit.agents)
|
|
4266
|
+
}));
|
|
4267
|
+
const outlines = yield* readKitsOutlines(root);
|
|
4268
|
+
const readOf = (kit, index) => index === 0 ? outlines[0] : outlines.find((found) => found.kit === kit.name && (found.version ?? "0.0.0") === kit.version);
|
|
4269
|
+
const unreadExtends = (kit) => winning.map(readOf).find((read, index) => read?.extendsUnread === true && winning[index]?.extends?.some((named) => named.name === kit.name && named.version === kit.version) === true)?.extendsAt;
|
|
4270
|
+
const loops = winning.flatMap((kit, index) => {
|
|
4271
|
+
const read = readOf(kit, index);
|
|
4272
|
+
return kit.loops.map((loop) => ({
|
|
4273
|
+
...loop,
|
|
4274
|
+
outline: read?.loops.get(loop.id) ?? [
|
|
4275
|
+
{
|
|
4276
|
+
kind: "runtime",
|
|
4277
|
+
label: `the run of ${loop.id}, which ${kit.name}'s config does not list plainly`,
|
|
4278
|
+
at: read?.at ?? unreadExtends(kit) ?? (outlines.find((found) => found.extendsUnread) ?? outlines[0])?.extendsAt ?? "kitman.config.ts"
|
|
4279
|
+
}
|
|
4280
|
+
]
|
|
4281
|
+
}));
|
|
4282
|
+
});
|
|
4283
|
+
for (const loop of loops) {
|
|
4284
|
+
const undeclared = undeclaredAgent(loop.id, loop.outline, loop.agents);
|
|
4285
|
+
if (undeclared !== undefined)
|
|
4286
|
+
return yield* undeclared;
|
|
4287
|
+
}
|
|
4288
|
+
const declarations = yield* decodeUnknownEffect2(KitDeclarations)({
|
|
4289
|
+
loops,
|
|
4290
|
+
...steps.length === 0 ? undefined : { steps: steps.map(({ name, payload, success, error }) => ({ name, payload, success, error })) },
|
|
4291
|
+
agents: Object.assign({}, ...winning.map((kit) => kit.agents)),
|
|
4292
|
+
...own.schedules === undefined ? undefined : { schedules: own.schedules },
|
|
4293
|
+
carried
|
|
4294
|
+
}).pipe(mapError2((error) => new DeclarationsInvalid({ reason: error.message })));
|
|
4295
|
+
const bundle = yield* fs.readFileString(bundleFile).pipe(map9((text) => new TextEncoder().encode(text.replaceAll(entryName, ".kitman-build-entry.ts"))), mapError2((error) => new BundleFailed({ reason: error.message })));
|
|
4296
|
+
return {
|
|
4297
|
+
...identity,
|
|
4298
|
+
bundle,
|
|
4299
|
+
digest: digestSha256(bundle, "hex"),
|
|
4300
|
+
declarations,
|
|
4301
|
+
setupArchives: archives,
|
|
4302
|
+
protocolVersion: RunnerRpcProtocolVersion,
|
|
4303
|
+
provenance: source,
|
|
4304
|
+
overrides: names.overrides
|
|
4305
|
+
};
|
|
4306
|
+
}).pipe(scoped, catchTags({
|
|
4307
|
+
PlatformError: (error) => fail7(new BundleFailed({ reason: error.message }))
|
|
4308
|
+
}));
|
|
4309
|
+
var writeKit = (directory, built, out) => gen(function* () {
|
|
4310
|
+
const fs = yield* FileSystem;
|
|
4311
|
+
const path = yield* Path;
|
|
4312
|
+
const inKit = (file) => path.relative(directory, path.join(out, file));
|
|
4313
|
+
const setup = {};
|
|
4314
|
+
yield* fs.makeDirectory(path.join(out, "setup"), { recursive: true });
|
|
4315
|
+
yield* fs.writeFile(path.join(out, "bundle.js"), built.bundle);
|
|
4316
|
+
yield* fs.writeFileString(path.join(out, "declarations.json"), yield* encodePrettyJsonString(built.declarations));
|
|
4317
|
+
for (const { digest, archive } of built.setupArchives) {
|
|
4318
|
+
yield* fs.writeFile(path.join(out, "setup", `${digest}.json`), archive);
|
|
4319
|
+
setup[digest] = inKit(`setup/${digest}.json`);
|
|
4320
|
+
}
|
|
4321
|
+
const manifestPath = path.join(directory, "package.json");
|
|
4322
|
+
const manifest = yield* fs.readFileString(manifestPath).pipe(flatMap3(decodeEffect(fromJsonString(Record(String4, Json)))));
|
|
4323
|
+
const kitman = {
|
|
4324
|
+
bundle: inKit("bundle.js"),
|
|
4325
|
+
digest: built.digest,
|
|
4326
|
+
protocolVersion: built.protocolVersion,
|
|
4327
|
+
declarations: inKit("declarations.json"),
|
|
4328
|
+
setup
|
|
4329
|
+
};
|
|
4330
|
+
yield* fs.writeFileString(manifestPath, `${yield* encodePrettyJsonString({ ...manifest, kitman })}
|
|
4331
|
+
`);
|
|
4332
|
+
});
|
|
4333
|
+
export {
|
|
4334
|
+
AgentUndeclared,
|
|
4335
|
+
BundleFailed,
|
|
4336
|
+
DeclarationsInvalid,
|
|
4337
|
+
DependencyInstallFailed,
|
|
4338
|
+
GitSourceLocation,
|
|
4339
|
+
OutlineUnread,
|
|
4340
|
+
SourceFetchFailed,
|
|
4341
|
+
buildKit,
|
|
4342
|
+
readOutlines,
|
|
4343
|
+
sdkSteps,
|
|
4344
|
+
writeKit
|
|
4345
|
+
};
|