@prompd/core 0.5.3 → 0.5.4

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/index.js CHANGED
@@ -5067,6 +5067,817 @@ function forkJoinId(file, parallelId) {
5067
5067
  return file.edges.find((e) => members.has(e.source) && e.targetHandle?.startsWith("input-"))?.target;
5068
5068
  }
5069
5069
 
5070
- export { AnthropicFormatter, BUILTIN_COMMAND_EXECUTABLES, CODE_EXTENSIONS, CONTENT_TYPES, CodeGenerationStage, CompilationContext, CompilationError, CompilationStage, CompilerPipeline, DEFAULT_MAX_CONCURRENCY, DEFAULT_SECURITY_CONFIG, DOCKABLE_HANDLES, DOCKABLE_NODE_TYPES, DependencyResolutionStage, EXTENSION_TO_LANGUAGE, EXTENSION_TO_LANGUAGE_ALIASES, HybridFileSystem, LexicalAnalysisStage, MEMORY_OPERATIONS_BY_MODE, MarkdownFormatter, MemoryFileSystem, MemoryPackageResolver, OpenAIFormatter, PACKAGE_TYPE_DIRS, PROMPD_EXTENSIONS, ParseError, PrompdCompiler, PrompdError, PrompdLoader, PrompdParser, SectionOverrideProcessor, SecurityError, SemanticAnalysisStage, TOOL_DEPLOY_DIRS, TemplateProcessingStage, VALID_PACKAGE_TYPES, ValidationError, basenamePosix, compile, createCoreStages, createEmptyWorkflow, createPrompdEnvironment, createWorkflowNode, dirnamePosix, extname, extractPdpkg, forkJoinId, getContentType, getExecutionOrder, getInstallDirForType, getLanguageAliasesForExtension, getLanguageForExtension, installPackage, isAbsolutePosix, isPrompdFile, isValidPackageReference, isValidPackageType, joinPosix, mergeBranchResults, needsFrontmatterProtection, normalizePosix, parsePackageReference, parsePackageReferenceWithPath, parseWorkflow, resolvePackageFile, resolvePosix, runBranches, serializeWorkflow, stripFilePath, traceForkBranches, uninstallPackage, validateWorkflow, validateWorkflowQuick };
5070
+ // src/lib/expression.ts
5071
+ var BRANDED = /* @__PURE__ */ new WeakSet();
5072
+ var ExpressionError = class _ExpressionError extends Error {
5073
+ constructor(message, construct, position) {
5074
+ super(message);
5075
+ this.name = "ExpressionError";
5076
+ this.construct = construct;
5077
+ this.position = position;
5078
+ if (new.target === _ExpressionError) {
5079
+ BRANDED.add(this);
5080
+ Object.freeze(this);
5081
+ }
5082
+ }
5083
+ };
5084
+ function isOwnExpressionError(e) {
5085
+ return typeof e === "object" && e !== null && BRANDED.has(e);
5086
+ }
5087
+ function ownDataField(o, key) {
5088
+ const d = Object.getOwnPropertyDescriptor(o, key);
5089
+ return d && "value" in d ? d.value : void 0;
5090
+ }
5091
+ function expressionErrorFields(e) {
5092
+ if (e === null || typeof e !== "object") return null;
5093
+ try {
5094
+ if (ownDataField(e, "name") !== "ExpressionError") return null;
5095
+ const construct = ownDataField(e, "construct");
5096
+ const position = ownDataField(e, "position");
5097
+ if (typeof construct !== "string" || typeof position !== "number") return null;
5098
+ const message = ownDataField(e, "message");
5099
+ return { construct, position, message: typeof message === "string" ? message : "" };
5100
+ } catch {
5101
+ return null;
5102
+ }
5103
+ }
5104
+ function ownMessage(e) {
5105
+ if (e === null || typeof e !== "object") return "unknown error";
5106
+ try {
5107
+ const m = ownDataField(e, "message");
5108
+ return typeof m === "string" ? m : "unknown error";
5109
+ } catch {
5110
+ return "unknown error";
5111
+ }
5112
+ }
5113
+ function isExpressionError(e) {
5114
+ return isOwnExpressionError(e) || expressionErrorFields(e) !== null;
5115
+ }
5116
+ var MAX_EXPRESSION_LENGTH = 2e3;
5117
+ var MAX_EXPRESSION_DEPTH = 64;
5118
+ var BLOCKED_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
5119
+ var STRING_METHODS = /* @__PURE__ */ new Set([
5120
+ "includes",
5121
+ "startsWith",
5122
+ "endsWith",
5123
+ "toLowerCase",
5124
+ "toUpperCase",
5125
+ "trim",
5126
+ "indexOf",
5127
+ "slice"
5128
+ ]);
5129
+ var ARRAY_METHODS = /* @__PURE__ */ new Set(["includes", "indexOf", "join", "slice"]);
5130
+ var KEYWORD_CONSTRUCTS = /* @__PURE__ */ new Map([
5131
+ ["new", "'new'"],
5132
+ ["typeof", "'typeof'"],
5133
+ ["void", "'void'"],
5134
+ ["delete", "'delete'"],
5135
+ ["in", "the 'in' operator"],
5136
+ ["instanceof", "'instanceof'"],
5137
+ ["function", "a function expression"],
5138
+ ["class", "a class expression"],
5139
+ ["this", "'this'"],
5140
+ ["await", "'await'"],
5141
+ ["yield", "'yield'"],
5142
+ ["import", "'import'"],
5143
+ ["super", "'super'"],
5144
+ ["let", "a declaration"],
5145
+ ["var", "a declaration"],
5146
+ ["const", "a declaration"],
5147
+ ["return", "a statement"]
5148
+ ]);
5149
+ var ASSIGNMENT_OPS = ["=", "+=", "-=", "*=", "/=", "%=", "**=", "&=", "|=", "^=", "<<=", ">>=", ">>>=", "&&=", "||=", "??="];
5150
+ var OP_CONSTRUCTS = new Map([
5151
+ ...ASSIGNMENT_OPS.map((o) => [o, "assignment"]),
5152
+ ["=>", "an arrow function"],
5153
+ ["++", "increment/decrement"],
5154
+ ["--", "increment/decrement"],
5155
+ ["&", "a bitwise operator"],
5156
+ ["|", "a bitwise operator"],
5157
+ ["^", "a bitwise operator"],
5158
+ ["~", "a bitwise operator"],
5159
+ ["<<", "a bitwise operator"],
5160
+ [">>", "a bitwise operator"],
5161
+ [">>>", "a bitwise operator"],
5162
+ ["**", "the exponent operator"],
5163
+ [",", "the comma operator"],
5164
+ [";", "a statement separator"],
5165
+ ["...", "spread"]
5166
+ ]);
5167
+ var OPS = [
5168
+ ...ASSIGNMENT_OPS,
5169
+ "...",
5170
+ "===",
5171
+ "!==",
5172
+ ">>>",
5173
+ "=>",
5174
+ "**",
5175
+ "?.",
5176
+ "??",
5177
+ "==",
5178
+ "!=",
5179
+ "<=",
5180
+ ">=",
5181
+ "&&",
5182
+ "||",
5183
+ "++",
5184
+ "--",
5185
+ "<<",
5186
+ ">>",
5187
+ "(",
5188
+ ")",
5189
+ "[",
5190
+ "]",
5191
+ "{",
5192
+ "}",
5193
+ ",",
5194
+ ":",
5195
+ ".",
5196
+ "?",
5197
+ "!",
5198
+ "+",
5199
+ "-",
5200
+ "*",
5201
+ "/",
5202
+ "%",
5203
+ "<",
5204
+ ">",
5205
+ "&",
5206
+ "|",
5207
+ "^",
5208
+ "~",
5209
+ ";"
5210
+ ].sort((a, b) => b.length - a.length);
5211
+ function disallowed(construct, position) {
5212
+ return new ExpressionError(`${construct} is not allowed in a workflow expression`, construct, position);
5213
+ }
5214
+ function syntax(message, position) {
5215
+ return new ExpressionError(message, "syntax error", position);
5216
+ }
5217
+ function describeExpressionFailure(kind, label, e) {
5218
+ const f = expressionErrorFields(e);
5219
+ if (!f) return `${kind} on "${label}" has an invalid expression: ${ownMessage(e)}.`;
5220
+ return f.construct === "syntax error" || f.construct === "evaluation error" ? `${kind} on "${label}" has an invalid expression: ${f.message} (position ${f.position}).` : `${kind} on "${label}" can't run: ${f.construct}, which workflow expressions can't do (position ${f.position}).`;
5221
+ }
5222
+ var SIMPLE_ESCAPES = /* @__PURE__ */ new Map([
5223
+ ["n", "\n"],
5224
+ ["t", " "],
5225
+ ["r", "\r"],
5226
+ ["b", "\b"],
5227
+ ["f", "\f"],
5228
+ ["v", "\v"],
5229
+ ["0", "\0"]
5230
+ ]);
5231
+ function readString(src, start) {
5232
+ const q = src[start];
5233
+ let out = "";
5234
+ let i = start + 1;
5235
+ while (i < src.length) {
5236
+ const c = src[i];
5237
+ if (c === q) return [out, i + 1];
5238
+ if (c === "\n") break;
5239
+ if (c === "\\") {
5240
+ const n = src[i + 1];
5241
+ if (n === void 0) break;
5242
+ const simple = SIMPLE_ESCAPES.get(n);
5243
+ if (simple !== void 0) {
5244
+ out += simple;
5245
+ i += 2;
5246
+ continue;
5247
+ }
5248
+ if (n === "x" || n === "u") {
5249
+ const len = n === "x" ? 2 : 4;
5250
+ const hex = src.slice(i + 2, i + 2 + len);
5251
+ if (!new RegExp(`^[0-9a-fA-F]{${len}}$`).test(hex)) throw syntax("invalid escape sequence", i);
5252
+ out += String.fromCharCode(parseInt(hex, 16));
5253
+ i += 2 + len;
5254
+ continue;
5255
+ }
5256
+ out += n;
5257
+ i += 2;
5258
+ continue;
5259
+ }
5260
+ out += c;
5261
+ i++;
5262
+ }
5263
+ throw syntax("unterminated string", start);
5264
+ }
5265
+ function tokenize(src) {
5266
+ const toks = [];
5267
+ let i = 0;
5268
+ while (i < src.length) {
5269
+ const c = src[i];
5270
+ if (/\s/.test(c)) {
5271
+ i++;
5272
+ continue;
5273
+ }
5274
+ if (c === "`") throw disallowed("a template literal", i);
5275
+ if (c === '"' || c === "'") {
5276
+ const [s, next] = readString(src, i);
5277
+ toks.push({ t: "str", v: s, p: i });
5278
+ i = next;
5279
+ continue;
5280
+ }
5281
+ if (/[0-9]/.test(c) || c === "." && /[0-9]/.test(src[i + 1] ?? "")) {
5282
+ const m = /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/.exec(src.slice(i));
5283
+ if (!m) throw syntax("invalid number", i);
5284
+ toks.push({ t: "num", v: Number(m[0]), p: i });
5285
+ i += m[0].length;
5286
+ if (/[A-Za-z_$0-9]/.test(src[i] ?? "")) throw syntax("invalid number", i);
5287
+ continue;
5288
+ }
5289
+ if (/[A-Za-z_$]/.test(c)) {
5290
+ const m = /^[A-Za-z_$][\w$]*/.exec(src.slice(i));
5291
+ const name = m ? m[0] : c;
5292
+ toks.push({ t: "id", v: name, p: i });
5293
+ i += name.length;
5294
+ continue;
5295
+ }
5296
+ const op = OPS.find((o) => src.startsWith(o, i) && !(o === "?." && /[0-9]/.test(src[i + 2] ?? "")));
5297
+ if (!op) throw syntax(`unexpected character '${c}'`, i);
5298
+ toks.push({ t: "op", v: op, p: i });
5299
+ i += op.length;
5300
+ }
5301
+ toks.push({ t: "eof", p: src.length });
5302
+ return toks;
5303
+ }
5304
+ var Parser = class {
5305
+ constructor(toks) {
5306
+ this.toks = toks;
5307
+ this.i = 0;
5308
+ this.depth = 0;
5309
+ }
5310
+ parseAll() {
5311
+ const n = this.expr();
5312
+ const t = this.peek();
5313
+ if (t.t !== "eof") throw this.unexpected(t);
5314
+ return n;
5315
+ }
5316
+ peek() {
5317
+ return this.toks[this.i];
5318
+ }
5319
+ next() {
5320
+ return this.toks[this.i++];
5321
+ }
5322
+ isOp(v) {
5323
+ const t = this.peek();
5324
+ return t.t === "op" && t.v === v;
5325
+ }
5326
+ eatOp(v) {
5327
+ if (this.isOp(v)) {
5328
+ this.i++;
5329
+ return true;
5330
+ }
5331
+ return false;
5332
+ }
5333
+ expectOp(v) {
5334
+ if (!this.eatOp(v)) throw this.unexpected(this.peek());
5335
+ }
5336
+ enter(p) {
5337
+ if (++this.depth > MAX_EXPRESSION_DEPTH) throw disallowed(`nesting deeper than ${MAX_EXPRESSION_DEPTH} levels`, p);
5338
+ }
5339
+ leave() {
5340
+ this.depth--;
5341
+ }
5342
+ unexpected(t) {
5343
+ if (t.t === "eof") return syntax("unexpected end of expression", t.p);
5344
+ if (t.t === "id") {
5345
+ const kw = KEYWORD_CONSTRUCTS.get(t.v);
5346
+ return kw ? disallowed(kw, t.p) : syntax(`unexpected '${t.v}'`, t.p);
5347
+ }
5348
+ if (t.t !== "op") return syntax("unexpected value", t.p);
5349
+ const c = OP_CONSTRUCTS.get(t.v);
5350
+ return c ? disallowed(c, t.p) : syntax(`unexpected '${t.v}'`, t.p);
5351
+ }
5352
+ expr() {
5353
+ this.enter(this.peek().p);
5354
+ try {
5355
+ return this.conditional();
5356
+ } finally {
5357
+ this.leave();
5358
+ }
5359
+ }
5360
+ conditional() {
5361
+ const test = this.nullish();
5362
+ if (!this.eatOp("?")) return test;
5363
+ const yes = this.expr();
5364
+ this.expectOp(":");
5365
+ const no = this.expr();
5366
+ return { k: "cond", test, yes, no };
5367
+ }
5368
+ binaryLevel(ops, nextLevel) {
5369
+ let l = nextLevel();
5370
+ for (; ; ) {
5371
+ const t = this.peek();
5372
+ if (t.t !== "op" || !ops.includes(t.v)) return l;
5373
+ this.i++;
5374
+ l = { k: "bin", op: t.v, l, r: nextLevel(), p: t.p };
5375
+ }
5376
+ }
5377
+ nullish() {
5378
+ return this.binaryLevel(["??"], () => this.or());
5379
+ }
5380
+ or() {
5381
+ return this.binaryLevel(["||"], () => this.and());
5382
+ }
5383
+ and() {
5384
+ return this.binaryLevel(["&&"], () => this.equality());
5385
+ }
5386
+ equality() {
5387
+ return this.binaryLevel(["==", "!=", "===", "!=="], () => this.relational());
5388
+ }
5389
+ relational() {
5390
+ return this.binaryLevel(["<", "<=", ">", ">="], () => this.additive());
5391
+ }
5392
+ additive() {
5393
+ return this.binaryLevel(["+", "-"], () => this.multiplicative());
5394
+ }
5395
+ multiplicative() {
5396
+ return this.binaryLevel(["*", "/", "%"], () => this.unary());
5397
+ }
5398
+ unary() {
5399
+ const t = this.peek();
5400
+ if (t.t === "op" && (t.v === "!" || t.v === "-" || t.v === "+")) {
5401
+ this.i++;
5402
+ this.enter(t.p);
5403
+ try {
5404
+ return { k: "unary", op: t.v, arg: this.unary(), p: t.p };
5405
+ } finally {
5406
+ this.leave();
5407
+ }
5408
+ }
5409
+ if (t.t === "op" && (t.v === "++" || t.v === "--" || t.v === "~")) throw this.unexpected(t);
5410
+ return this.postfix();
5411
+ }
5412
+ postfix() {
5413
+ let n = this.primary();
5414
+ for (; ; ) {
5415
+ const t = this.peek();
5416
+ if (t.t !== "op") return n;
5417
+ if (t.v === "." || t.v === "?.") {
5418
+ this.i++;
5419
+ const optional = t.v === "?.";
5420
+ if (optional && this.isOp("(")) throw disallowed("an optional call", t.p);
5421
+ if (optional && this.eatOp("[")) {
5422
+ const prop = this.computedKey(t.p);
5423
+ n = { k: "member", obj: n, prop, optional: true, p: t.p };
5424
+ continue;
5425
+ }
5426
+ const name = this.next();
5427
+ if (name.t !== "id") throw syntax("expected a property name", name.p);
5428
+ if (BLOCKED_KEYS.has(name.v)) throw disallowed(`access to ${name.v}`, name.p);
5429
+ n = { k: "member", obj: n, prop: name.v, optional, p: name.p };
5430
+ continue;
5431
+ }
5432
+ if (t.v === "[") {
5433
+ this.i++;
5434
+ n = { k: "member", obj: n, prop: this.computedKey(t.p), optional: false, p: t.p };
5435
+ continue;
5436
+ }
5437
+ if (t.v === "(") {
5438
+ if (n.k === "member" && typeof n.prop === "string" && !n.paren) {
5439
+ if (!STRING_METHODS.has(n.prop) && !ARRAY_METHODS.has(n.prop)) throw disallowed(`call to ${n.prop}`, t.p);
5440
+ this.i++;
5441
+ n = { k: "call", recv: n.obj, name: n.prop, args: this.args(), optional: n.optional, p: t.p };
5442
+ continue;
5443
+ }
5444
+ if (n.k === "id") throw disallowed(`call to ${n.name}`, t.p);
5445
+ if (n.k === "member" && typeof n.prop !== "string" && !n.paren) throw disallowed("a computed method call", t.p);
5446
+ throw disallowed("a function call", t.p);
5447
+ }
5448
+ if (t.v === "++" || t.v === "--") throw this.unexpected(t);
5449
+ return n;
5450
+ }
5451
+ }
5452
+ /** `[expr]` after `[` or `?.[`; a literal blocked key is rejected here, a computed one at evaluation. */
5453
+ computedKey(p) {
5454
+ const prop = this.expr();
5455
+ this.expectOp("]");
5456
+ if (prop.k === "lit" && typeof prop.v === "string" && BLOCKED_KEYS.has(prop.v)) throw disallowed(`access to ${prop.v}`, p);
5457
+ return prop;
5458
+ }
5459
+ args() {
5460
+ const out = [];
5461
+ if (this.eatOp(")")) return out;
5462
+ for (; ; ) {
5463
+ if (this.isOp("...")) throw disallowed("spread", this.peek().p);
5464
+ out.push(this.expr());
5465
+ if (this.eatOp(")")) return out;
5466
+ this.expectOp(",");
5467
+ }
5468
+ }
5469
+ primary() {
5470
+ const t = this.next();
5471
+ if (t.t === "num" || t.t === "str") return { k: "lit", v: t.v };
5472
+ if (t.t === "id") {
5473
+ if (t.v === "true") return { k: "lit", v: true };
5474
+ if (t.v === "false") return { k: "lit", v: false };
5475
+ if (t.v === "null") return { k: "lit", v: null };
5476
+ if (t.v === "undefined") return { k: "lit", v: void 0 };
5477
+ const kw = KEYWORD_CONSTRUCTS.get(t.v);
5478
+ if (kw) throw disallowed(kw, t.p);
5479
+ if (this.isOp("=>")) throw disallowed("an arrow function", this.peek().p);
5480
+ return { k: "id", name: t.v, p: t.p };
5481
+ }
5482
+ if (t.t === "eof") throw syntax("unexpected end of expression", t.p);
5483
+ if (t.t === "op") {
5484
+ if (t.v === "(") {
5485
+ if (this.isOp(")")) throw disallowed("an arrow function", t.p);
5486
+ const inner = this.expr();
5487
+ this.expectOp(")");
5488
+ if (this.isOp("=>")) throw disallowed("an arrow function", this.peek().p);
5489
+ return inner.k === "member" || inner.k === "call" ? { ...inner, paren: true } : inner;
5490
+ }
5491
+ if (t.v === "[") {
5492
+ const items = [];
5493
+ if (this.eatOp("]")) return { k: "arr", items };
5494
+ for (; ; ) {
5495
+ if (this.isOp("...")) throw disallowed("spread", this.peek().p);
5496
+ items.push(this.expr());
5497
+ if (this.eatOp("]")) return { k: "arr", items };
5498
+ this.expectOp(",");
5499
+ }
5500
+ }
5501
+ if (t.v === "{") return this.objectLiteral();
5502
+ if (t.v === "/") throw disallowed("a regex literal", t.p);
5503
+ }
5504
+ throw this.unexpected(t);
5505
+ }
5506
+ objectLiteral() {
5507
+ const props = [];
5508
+ if (this.eatOp("}")) return { k: "obj", props };
5509
+ for (; ; ) {
5510
+ const k = this.next();
5511
+ if (k.t === "op" && k.v === "...") throw disallowed("spread", k.p);
5512
+ if (k.t === "op" && k.v === "[") throw disallowed("a computed key", k.p);
5513
+ if (k.t !== "id" && k.t !== "str") throw syntax("expected a property name", k.p);
5514
+ if (BLOCKED_KEYS.has(k.v)) throw disallowed(`access to ${k.v}`, k.p);
5515
+ this.expectOp(":");
5516
+ props.push({ key: k.v, value: this.expr() });
5517
+ if (this.eatOp("}")) return { k: "obj", props };
5518
+ this.expectOp(",");
5519
+ }
5520
+ }
5521
+ };
5522
+ function stripWrapper(expr) {
5523
+ const t = expr.trim();
5524
+ return t.startsWith("{{") && t.endsWith("}}") ? t.slice(2, -2).trim() : t;
5525
+ }
5526
+ function parseExpression(expr) {
5527
+ const src = stripWrapper(expr);
5528
+ if (src.length > MAX_EXPRESSION_LENGTH) {
5529
+ throw disallowed(`an expression longer than ${MAX_EXPRESSION_LENGTH} characters`, MAX_EXPRESSION_LENGTH);
5530
+ }
5531
+ if (!src) throw syntax("empty expression", 0);
5532
+ return new Parser(tokenize(src)).parseAll();
5533
+ }
5534
+ function validateExpression(expr) {
5535
+ try {
5536
+ parseExpression(expr);
5537
+ return null;
5538
+ } catch (e) {
5539
+ if (isExpressionError(e)) return e;
5540
+ throw e;
5541
+ }
5542
+ }
5543
+ var SHORT = /* @__PURE__ */ Symbol("optional-chain-short-circuit");
5544
+ function ownData(obj, key) {
5545
+ const d = Object.getOwnPropertyDescriptor(obj, key);
5546
+ if (!d || !("value" in d)) return void 0;
5547
+ return typeof d.value === "function" ? void 0 : d.value;
5548
+ }
5549
+ function isCanonicalIndex(key) {
5550
+ const n = Number(key);
5551
+ return Number.isInteger(n) && n >= 0 && String(n) === key;
5552
+ }
5553
+ function isPlainObject(o) {
5554
+ const proto = Object.getPrototypeOf(o);
5555
+ return proto === Object.prototype || proto === null;
5556
+ }
5557
+ function isPlainArray(o) {
5558
+ return Array.isArray(o) && Object.getPrototypeOf(o) === Array.prototype;
5559
+ }
5560
+ function dataValue(v) {
5561
+ if (typeof v === "function") return void 0;
5562
+ if (v === null || typeof v !== "object") return v;
5563
+ return isPlainArray(v) || isPlainObject(v) ? v : void 0;
5564
+ }
5565
+ function readProp(obj, key, p, options) {
5566
+ if (BLOCKED_KEYS.has(key)) throw disallowed(`access to ${key}`, p);
5567
+ return dataValue(readOwnMember(obj, key, options));
5568
+ }
5569
+ var MAX_JSON_NAV_LENGTH = 1e6;
5570
+ function stripCodeFence(s) {
5571
+ const open = s.indexOf("```");
5572
+ if (open === -1) return s;
5573
+ const close = s.indexOf("```", open + 3);
5574
+ if (close === -1) return s;
5575
+ const inner = s.slice(open + 3, close);
5576
+ return inner.startsWith("json") ? inner.slice(4) : inner;
5577
+ }
5578
+ function parseJsonFromString(s) {
5579
+ if (s.length > MAX_JSON_NAV_LENGTH) return void 0;
5580
+ const text = stripCodeFence(s).trim();
5581
+ if (!text) return void 0;
5582
+ try {
5583
+ return JSON.parse(text);
5584
+ } catch {
5585
+ return void 0;
5586
+ }
5587
+ }
5588
+ function readOwnMember(obj, key, options) {
5589
+ if (typeof obj === "string") {
5590
+ if (key === "length") return obj.length;
5591
+ if (isCanonicalIndex(key)) {
5592
+ return Number(key) < obj.length ? obj.charAt(Number(key)) : void 0;
5593
+ }
5594
+ if (options?.parseJsonStrings) {
5595
+ const parsed = parseJsonFromString(obj);
5596
+ if (parsed !== null && typeof parsed === "object" && (isPlainArray(parsed) || isPlainObject(parsed))) {
5597
+ return readOwnMember(parsed, key, options);
5598
+ }
5599
+ }
5600
+ return void 0;
5601
+ }
5602
+ if (obj === null || typeof obj !== "object") return void 0;
5603
+ if (isPlainArray(obj)) return key === "length" ? ownIndexLength(obj) : ownData(obj, key);
5604
+ if (isPlainObject(obj)) return ownData(obj, key);
5605
+ return void 0;
5606
+ }
5607
+ function describeType(v) {
5608
+ if (v === null) return "null";
5609
+ if (v === void 0) return "undefined";
5610
+ if (Array.isArray(v)) return "an array";
5611
+ const t = typeof v;
5612
+ return t === "object" ? "an object" : `a ${t}`;
5613
+ }
5614
+ function prim(v, p, what) {
5615
+ if (v === null) return v;
5616
+ const t = typeof v;
5617
+ if (t === "object" || t === "function" || t === "symbol") {
5618
+ throw new ExpressionError(`${what} needs a plain value, not ${describeType(v)}`, "evaluation error", p);
5619
+ }
5620
+ return v;
5621
+ }
5622
+ function propKey(v, p) {
5623
+ const pv = prim(v, p, "a computed property key");
5624
+ return typeof pv === "string" ? pv : String(pv);
5625
+ }
5626
+ function ownIndexLength(a) {
5627
+ const d = Object.getOwnPropertyDescriptor(a, "length");
5628
+ if (!d || !("value" in d)) return 0;
5629
+ const v = d.value;
5630
+ return typeof v === "number" && Number.isSafeInteger(v) && v >= 0 ? v : 0;
5631
+ }
5632
+ var MAX_ARRAY_SCAN = 1e6;
5633
+ function scanLength(a, name, p) {
5634
+ const len = ownIndexLength(a);
5635
+ if (len > MAX_ARRAY_SCAN) {
5636
+ throw new ExpressionError(
5637
+ `${name} on an array longer than ${MAX_ARRAY_SCAN} elements is not allowed in a workflow expression`,
5638
+ "evaluation error",
5639
+ p
5640
+ );
5641
+ }
5642
+ return len;
5643
+ }
5644
+ function ownIndexDescriptor(a, i) {
5645
+ return Object.getOwnPropertyDescriptor(a, String(i));
5646
+ }
5647
+ function ownIndex(a, i) {
5648
+ const d = ownIndexDescriptor(a, i);
5649
+ return d && "value" in d ? d.value : void 0;
5650
+ }
5651
+ function toIntegerOrInfinity(v) {
5652
+ const n = Number(v);
5653
+ if (Number.isNaN(n) || n === 0) return 0;
5654
+ if (!Number.isFinite(n)) return n;
5655
+ const t = Math.trunc(n);
5656
+ return t === 0 ? 0 : t;
5657
+ }
5658
+ function sameValueZero(x, y) {
5659
+ return x === y || typeof x === "number" && typeof y === "number" && Number.isNaN(x) && Number.isNaN(y);
5660
+ }
5661
+ function arraySlice(a, args, p) {
5662
+ const startArg = args.length > 0 ? prim(args[0], p, "a slice argument") : void 0;
5663
+ const endArg = args.length > 1 ? prim(args[1], p, "a slice argument") : void 0;
5664
+ const len = scanLength(a, "slice", p);
5665
+ const relStart = startArg === void 0 ? 0 : toIntegerOrInfinity(startArg);
5666
+ const k = relStart < 0 ? Math.max(len + relStart, 0) : Math.min(relStart, len);
5667
+ const relEnd = endArg === void 0 ? len : toIntegerOrInfinity(endArg);
5668
+ const final = relEnd < 0 ? Math.max(len + relEnd, 0) : Math.min(relEnd, len);
5669
+ const count = Math.max(final - k, 0);
5670
+ const out = [];
5671
+ for (let j = 0; j < count; j++) out.push(dataValue(ownIndex(a, k + j)));
5672
+ return out;
5673
+ }
5674
+ function arrayJoin(a, args, p) {
5675
+ const sepArg = args.length > 0 ? prim(args[0], p, "the join separator") : void 0;
5676
+ const sep = sepArg === void 0 ? "," : String(sepArg);
5677
+ const len = scanLength(a, "join", p);
5678
+ const parts = [];
5679
+ for (let i = 0; i < len; i++) {
5680
+ const e = ownIndex(a, i);
5681
+ if (e === void 0 || e === null) {
5682
+ parts.push("");
5683
+ continue;
5684
+ }
5685
+ parts.push(String(prim(e, p, "an array element passed to join")));
5686
+ }
5687
+ return parts.join(sep);
5688
+ }
5689
+ function arrayIncludes(a, args, p) {
5690
+ const search = args[0];
5691
+ const fromArg = args.length > 1 ? prim(args[1], p, "a fromIndex argument") : void 0;
5692
+ const len = scanLength(a, "includes", p);
5693
+ const rel = fromArg === void 0 ? 0 : toIntegerOrInfinity(fromArg);
5694
+ const from = rel < 0 ? Math.max(len + rel, 0) : rel;
5695
+ for (let i = from; i < len; i++) {
5696
+ if (sameValueZero(ownIndex(a, i), search)) return true;
5697
+ }
5698
+ return false;
5699
+ }
5700
+ function arrayIndexOf(a, args, p) {
5701
+ const search = args[0];
5702
+ const fromArg = args.length > 1 ? prim(args[1], p, "a fromIndex argument") : void 0;
5703
+ const len = scanLength(a, "indexOf", p);
5704
+ const rel = fromArg === void 0 ? 0 : toIntegerOrInfinity(fromArg);
5705
+ const from = rel < 0 ? Math.max(len + rel, 0) : rel;
5706
+ for (let i = from; i < len; i++) {
5707
+ const d = ownIndexDescriptor(a, i);
5708
+ if (d === void 0) continue;
5709
+ if (("value" in d ? d.value : void 0) === search) return i;
5710
+ }
5711
+ return -1;
5712
+ }
5713
+ function looseEq(l, r) {
5714
+ const lRef = l !== null && (typeof l === "object" || typeof l === "function");
5715
+ const rRef = r !== null && (typeof r === "object" || typeof r === "function");
5716
+ if (lRef || rRef) return l === r;
5717
+ return l == r;
5718
+ }
5719
+ function callMethod(recv, name, args, p) {
5720
+ if (typeof recv === "string" && STRING_METHODS.has(name)) {
5721
+ const fn = Reflect.get(String.prototype, name);
5722
+ if (typeof fn === "function") {
5723
+ const primArgs = args.map((a) => prim(a, p, `an argument to ${name}`));
5724
+ return Reflect.apply(fn, recv, primArgs);
5725
+ }
5726
+ }
5727
+ if (Array.isArray(recv) && Object.getPrototypeOf(recv) === Array.prototype && ARRAY_METHODS.has(name)) {
5728
+ if (name === "join") return arrayJoin(recv, args, p);
5729
+ if (name === "slice") return arraySlice(recv, args, p);
5730
+ if (name === "includes") return arrayIncludes(recv, args, p);
5731
+ if (name === "indexOf") return arrayIndexOf(recv, args, p);
5732
+ }
5733
+ const msg = `call to ${name} on ${describeType(recv)}`;
5734
+ if (STRING_METHODS.has(name) || ARRAY_METHODS.has(name)) {
5735
+ throw new ExpressionError(`${msg} is not allowed in a workflow expression`, "evaluation error", p);
5736
+ }
5737
+ throw disallowed(msg, p);
5738
+ }
5739
+ function toNum(v) {
5740
+ return typeof v === "number" ? v : Number(v);
5741
+ }
5742
+ function missingOperand(p) {
5743
+ return new ExpressionError(
5744
+ "arithmetic on a missing value (a hyphenated name like a-b is subtraction; read it as nodes['a-b'])",
5745
+ "evaluation error",
5746
+ p
5747
+ );
5748
+ }
5749
+ function arithOperand(v, p, what) {
5750
+ const pv = prim(v, p, what);
5751
+ if (pv === void 0) throw missingOperand(p);
5752
+ return pv;
5753
+ }
5754
+ var Evaluator = class {
5755
+ constructor(scope, options = {}) {
5756
+ this.scope = scope;
5757
+ this.options = options;
5758
+ }
5759
+ run(n) {
5760
+ return this.val(n);
5761
+ }
5762
+ val(n) {
5763
+ const v = this.ev(n);
5764
+ return v === SHORT ? void 0 : v;
5765
+ }
5766
+ /** The object side of a member or call. Continues an optional chain (SHORT
5767
+ * propagates) unless the object was parenthesized, which ends the chain. */
5768
+ chain(n) {
5769
+ return (n.k === "member" || n.k === "call") && !n.paren ? this.ev(n) : this.val(n);
5770
+ }
5771
+ ev(n) {
5772
+ switch (n.k) {
5773
+ case "lit":
5774
+ return n.v;
5775
+ case "id":
5776
+ return dataValue(ownData(this.scope, n.name));
5777
+ case "arr":
5778
+ return n.items.map((x) => this.val(x));
5779
+ case "obj": {
5780
+ const o = {};
5781
+ for (const pr of n.props) o[pr.key] = this.val(pr.value);
5782
+ return o;
5783
+ }
5784
+ case "member": {
5785
+ const o = this.chain(n.obj);
5786
+ if (o === SHORT) return SHORT;
5787
+ if (n.optional && (o === null || o === void 0)) return SHORT;
5788
+ const key = typeof n.prop === "string" ? n.prop : propKey(this.val(n.prop), n.p);
5789
+ return readProp(o, key, n.p, this.options);
5790
+ }
5791
+ case "call": {
5792
+ const r = this.chain(n.recv);
5793
+ if (r === SHORT) return SHORT;
5794
+ if (n.optional && (r === null || r === void 0)) return SHORT;
5795
+ return callMethod(r, n.name, n.args.map((a) => this.val(a)), n.p);
5796
+ }
5797
+ case "unary": {
5798
+ const v = this.val(n.arg);
5799
+ if (n.op === "!") return !v;
5800
+ const pv = prim(v, n.p, `unary '${n.op}'`);
5801
+ return n.op === "-" ? -toNum(pv) : toNum(pv);
5802
+ }
5803
+ case "cond":
5804
+ return this.val(n.test) ? this.val(n.yes) : this.val(n.no);
5805
+ case "bin":
5806
+ return this.bin(n);
5807
+ }
5808
+ }
5809
+ bin(n) {
5810
+ if (n.op === "&&") {
5811
+ const l2 = this.val(n.l);
5812
+ return l2 ? this.val(n.r) : l2;
5813
+ }
5814
+ if (n.op === "||") {
5815
+ const l2 = this.val(n.l);
5816
+ return l2 ? l2 : this.val(n.r);
5817
+ }
5818
+ if (n.op === "??") {
5819
+ const l2 = this.val(n.l);
5820
+ return l2 === null || l2 === void 0 ? this.val(n.r) : l2;
5821
+ }
5822
+ const l = this.val(n.l);
5823
+ const r = this.val(n.r);
5824
+ switch (n.op) {
5825
+ case "+": {
5826
+ const lp = prim(l, n.p, "'+'");
5827
+ const rp = prim(r, n.p, "'+'");
5828
+ if (typeof lp === "string" || typeof rp === "string") return String(lp) + String(rp);
5829
+ if (lp === void 0 || rp === void 0) throw missingOperand(n.p);
5830
+ return toNum(lp) + toNum(rp);
5831
+ }
5832
+ case "-":
5833
+ return toNum(arithOperand(l, n.p, "'-'")) - toNum(arithOperand(r, n.p, "'-'"));
5834
+ case "*":
5835
+ return toNum(arithOperand(l, n.p, "'*'")) * toNum(arithOperand(r, n.p, "'*'"));
5836
+ case "/":
5837
+ return toNum(arithOperand(l, n.p, "'/'")) / toNum(arithOperand(r, n.p, "'/'"));
5838
+ case "%":
5839
+ return toNum(arithOperand(l, n.p, "'%'")) % toNum(arithOperand(r, n.p, "'%'"));
5840
+ case "==":
5841
+ return looseEq(l, r);
5842
+ case "!=":
5843
+ return !looseEq(l, r);
5844
+ case "===":
5845
+ return l === r;
5846
+ case "!==":
5847
+ return l !== r;
5848
+ case "<":
5849
+ return prim(l, n.p, "'<'") < prim(r, n.p, "'<'");
5850
+ case "<=":
5851
+ return prim(l, n.p, "'<='") <= prim(r, n.p, "'<='");
5852
+ case ">":
5853
+ return prim(l, n.p, "'>'") > prim(r, n.p, "'>'");
5854
+ case ">=":
5855
+ return prim(l, n.p, "'>='") >= prim(r, n.p, "'>='");
5856
+ default:
5857
+ throw syntax(`unknown operator '${n.op}'`, 0);
5858
+ }
5859
+ }
5860
+ };
5861
+ function thrownDetail(e) {
5862
+ if (e === null || typeof e !== "object" && typeof e !== "function") return String(e);
5863
+ const d = Object.getOwnPropertyDescriptor(e, "message");
5864
+ return d && "value" in d && typeof d.value === "string" ? d.value : "unknown error";
5865
+ }
5866
+ function evaluateExpression(expr, scope, options) {
5867
+ const ast = parseExpression(expr);
5868
+ try {
5869
+ return new Evaluator(scope, options).run(ast);
5870
+ } catch (e) {
5871
+ if (isOwnExpressionError(e)) throw e;
5872
+ let detail = "unknown error";
5873
+ try {
5874
+ detail = thrownDetail(e);
5875
+ } catch {
5876
+ }
5877
+ throw new ExpressionError(`the expression could not be evaluated: ${detail}`, "evaluation error", 0);
5878
+ }
5879
+ }
5880
+
5881
+ export { AnthropicFormatter, BUILTIN_COMMAND_EXECUTABLES, CODE_EXTENSIONS, CONTENT_TYPES, CodeGenerationStage, CompilationContext, CompilationError, CompilationStage, CompilerPipeline, DEFAULT_MAX_CONCURRENCY, DEFAULT_SECURITY_CONFIG, DOCKABLE_HANDLES, DOCKABLE_NODE_TYPES, DependencyResolutionStage, EXTENSION_TO_LANGUAGE, EXTENSION_TO_LANGUAGE_ALIASES, ExpressionError, HybridFileSystem, LexicalAnalysisStage, MAX_ARRAY_SCAN, MAX_EXPRESSION_DEPTH, MAX_EXPRESSION_LENGTH, MAX_JSON_NAV_LENGTH, MEMORY_OPERATIONS_BY_MODE, MarkdownFormatter, MemoryFileSystem, MemoryPackageResolver, OpenAIFormatter, PACKAGE_TYPE_DIRS, PROMPD_EXTENSIONS, ParseError, PrompdCompiler, PrompdError, PrompdLoader, PrompdParser, SectionOverrideProcessor, SecurityError, SemanticAnalysisStage, TOOL_DEPLOY_DIRS, TemplateProcessingStage, VALID_PACKAGE_TYPES, ValidationError, basenamePosix, compile, createCoreStages, createEmptyWorkflow, createPrompdEnvironment, createWorkflowNode, describeExpressionFailure, dirnamePosix, evaluateExpression, extname, extractPdpkg, forkJoinId, getContentType, getExecutionOrder, getInstallDirForType, getLanguageAliasesForExtension, getLanguageForExtension, installPackage, isAbsolutePosix, isExpressionError, isPrompdFile, isValidPackageReference, isValidPackageType, joinPosix, mergeBranchResults, needsFrontmatterProtection, normalizePosix, parsePackageReference, parsePackageReferenceWithPath, parseWorkflow, resolvePackageFile, resolvePosix, runBranches, serializeWorkflow, stripFilePath, traceForkBranches, uninstallPackage, validateExpression, validateWorkflow, validateWorkflowQuick };
5071
5882
  //# sourceMappingURL=index.js.map
5072
5883
  //# sourceMappingURL=index.js.map