poe-code 3.0.220 → 3.0.222
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/README.md +8 -0
- package/dist/cli/commands/harness.js +107 -15
- package/dist/cli/commands/harness.js.map +1 -1
- package/dist/index.js +821 -84
- package/dist/index.js.map +3 -3
- package/dist/providers/claude-code.js.map +1 -1
- package/dist/providers/codex.js.map +1 -1
- package/dist/providers/goose.js.map +1 -1
- package/dist/providers/kimi.js.map +1 -1
- package/dist/providers/opencode.js.map +1 -1
- package/dist/providers/poe-agent.js.map +2 -2
- package/package.json +4 -2
- package/packages/design-system/dist/prompts/index.d.ts +1 -1
- package/packages/design-system/dist/prompts/index.js +3 -2
- package/packages/memory/dist/index.js.map +1 -1
- package/scripts/postinstall-sync-skills.mjs +31 -0
package/dist/index.js
CHANGED
|
@@ -9154,6 +9154,7 @@ function formatElapsed2(ms) {
|
|
|
9154
9154
|
}
|
|
9155
9155
|
async function withSpinner(options) {
|
|
9156
9156
|
const { message: message2, fn, stopMessage, subtext } = options;
|
|
9157
|
+
const readMessage = () => typeof message2 === "function" ? message2() : message2;
|
|
9157
9158
|
if (resolveOutputFormat() === "json") {
|
|
9158
9159
|
const result = await fn();
|
|
9159
9160
|
const sub = subtext ? subtext(result) : void 0;
|
|
@@ -9182,9 +9183,9 @@ async function withSpinner(options) {
|
|
|
9182
9183
|
}
|
|
9183
9184
|
const s = spinner();
|
|
9184
9185
|
const start = Date.now();
|
|
9185
|
-
s.start(
|
|
9186
|
+
s.start(readMessage());
|
|
9186
9187
|
const timer = setInterval(() => {
|
|
9187
|
-
s.message(`${
|
|
9188
|
+
s.message(`${readMessage()} [${formatElapsed2(Date.now() - start)}]`);
|
|
9188
9189
|
}, 1e3);
|
|
9189
9190
|
try {
|
|
9190
9191
|
const result = await fn();
|
|
@@ -56998,31 +56999,16 @@ function formatCommandRows(group, scope, casing, globalLongOptionFlags) {
|
|
|
56998
56999
|
description: child.description ?? ""
|
|
56999
57000
|
}));
|
|
57000
57001
|
}
|
|
57001
|
-
function
|
|
57002
|
-
const
|
|
57002
|
+
function formatGlobalOptionsLine(ctx) {
|
|
57003
|
+
const flags = [];
|
|
57003
57004
|
if (ctx.presetsEnabled) {
|
|
57004
|
-
|
|
57005
|
-
flags: "--preset <path>",
|
|
57006
|
-
description: "Load parameter defaults from a JSON file"
|
|
57007
|
-
});
|
|
57005
|
+
flags.push("--preset <path>");
|
|
57008
57006
|
}
|
|
57009
|
-
|
|
57010
|
-
{
|
|
57011
|
-
flags: "--yes",
|
|
57012
|
-
description: "Accept defaults, skip prompts"
|
|
57013
|
-
},
|
|
57014
|
-
{
|
|
57015
|
-
flags: "--output <format>",
|
|
57016
|
-
description: "Output format: rich, md, json."
|
|
57017
|
-
}
|
|
57018
|
-
);
|
|
57007
|
+
flags.push("--yes", "--output <format>");
|
|
57019
57008
|
if (ctx.showVersion) {
|
|
57020
|
-
|
|
57021
|
-
flags: "--version",
|
|
57022
|
-
description: "Show version"
|
|
57023
|
-
});
|
|
57009
|
+
flags.push("--version");
|
|
57024
57010
|
}
|
|
57025
|
-
return
|
|
57011
|
+
return `${text.section("Options:")} ${flags.join(" ")}`;
|
|
57026
57012
|
}
|
|
57027
57013
|
function collectSchemaGlobalFieldRows(group, scope, casing, globalLongOptionFlags) {
|
|
57028
57014
|
const seen = /* @__PURE__ */ new Map();
|
|
@@ -57079,12 +57065,22 @@ function renderGroupHelp(group, breadcrumb, scope, casing, globalOptions, rootUs
|
|
|
57079
57065
|
${formatHelpCommandList(commandRows)}`);
|
|
57080
57066
|
}
|
|
57081
57067
|
if (isRoot) {
|
|
57082
|
-
const
|
|
57083
|
-
|
|
57084
|
-
|
|
57085
|
-
|
|
57086
|
-
|
|
57087
|
-
|
|
57068
|
+
const schemaGlobalRows = collectSchemaGlobalFieldRows(
|
|
57069
|
+
group,
|
|
57070
|
+
scope,
|
|
57071
|
+
casing,
|
|
57072
|
+
globalLongOptionFlags
|
|
57073
|
+
);
|
|
57074
|
+
const builtInLine = formatGlobalOptionsLine(globalOptions);
|
|
57075
|
+
if (schemaGlobalRows.length > 0) {
|
|
57076
|
+
sections.push(
|
|
57077
|
+
`${text.sectionHeader("Options")}
|
|
57078
|
+
${formatHelpOptionList(schemaGlobalRows)}
|
|
57079
|
+
${builtInLine}`
|
|
57080
|
+
);
|
|
57081
|
+
} else {
|
|
57082
|
+
sections.push(builtInLine);
|
|
57083
|
+
}
|
|
57088
57084
|
}
|
|
57089
57085
|
return renderHelpDocument({
|
|
57090
57086
|
breadcrumb,
|
|
@@ -57251,25 +57247,35 @@ function createNodeCommand(node, casing, globalLongOptionFlags, execute2, preset
|
|
|
57251
57247
|
return group;
|
|
57252
57248
|
}
|
|
57253
57249
|
function addGlobalOptions(command, presetsEnabled) {
|
|
57250
|
+
const options = [];
|
|
57254
57251
|
if (presetsEnabled) {
|
|
57255
|
-
|
|
57252
|
+
options.push(new Option("--preset <path>", "Load parameter defaults from a JSON file."));
|
|
57256
57253
|
}
|
|
57257
|
-
|
|
57258
|
-
|
|
57259
|
-
|
|
57260
|
-
|
|
57261
|
-
|
|
57262
|
-
|
|
57263
|
-
|
|
57264
|
-
|
|
57265
|
-
|
|
57266
|
-
|
|
57267
|
-
|
|
57268
|
-
|
|
57269
|
-
|
|
57270
|
-
|
|
57254
|
+
options.push(new Option("--yes", "Accept defaults and skip prompts."));
|
|
57255
|
+
options.push(
|
|
57256
|
+
new Option("--output <format>", "Output format.").argParser((value) => {
|
|
57257
|
+
if (value === "rich" || value === "md" || value === "json") {
|
|
57258
|
+
return value;
|
|
57259
|
+
}
|
|
57260
|
+
if (value === "markdown") {
|
|
57261
|
+
return "md";
|
|
57262
|
+
}
|
|
57263
|
+
throw new InvalidArgumentError(
|
|
57264
|
+
formatInvalidEnumMessage("--output", value, ["rich", "md", "markdown", "json"], {
|
|
57265
|
+
candidates: ["rich", "markdown", "json"],
|
|
57266
|
+
threshold: 3
|
|
57267
|
+
})
|
|
57268
|
+
);
|
|
57269
|
+
})
|
|
57270
|
+
);
|
|
57271
|
+
options.push(
|
|
57271
57272
|
new Option("--debug [mode]", "Print stack traces for unexpected errors.").preset("trim").argParser(parseDebugStackMode)
|
|
57272
|
-
)
|
|
57273
|
+
);
|
|
57274
|
+
options.push(new Option("--verbose", "Print detailed runtime diagnostics."));
|
|
57275
|
+
for (const option of options) {
|
|
57276
|
+
option.hideHelp(true);
|
|
57277
|
+
command.addOption(option);
|
|
57278
|
+
}
|
|
57273
57279
|
}
|
|
57274
57280
|
function parseDebugStackMode(value) {
|
|
57275
57281
|
if (value === true || value === "trim") {
|
|
@@ -57309,6 +57315,9 @@ function formatResolvedValue(value) {
|
|
|
57309
57315
|
}
|
|
57310
57316
|
return JSON.stringify(value);
|
|
57311
57317
|
}
|
|
57318
|
+
function fieldPromptLabel(field) {
|
|
57319
|
+
return field.positionalIndex === void 0 ? field.optionFlag : `<${field.displayPath}>`;
|
|
57320
|
+
}
|
|
57312
57321
|
async function promptForField(field) {
|
|
57313
57322
|
const schema2 = field.schema;
|
|
57314
57323
|
if (schema2.kind === "enum") {
|
|
@@ -57317,7 +57326,7 @@ async function promptForField(field) {
|
|
|
57317
57326
|
value
|
|
57318
57327
|
}));
|
|
57319
57328
|
const selected = await select2({
|
|
57320
|
-
message: field.description ?? field
|
|
57329
|
+
message: field.description ?? fieldPromptLabel(field),
|
|
57321
57330
|
options,
|
|
57322
57331
|
initialValue: field.hasDefault ? field.defaultValue : void 0
|
|
57323
57332
|
});
|
|
@@ -57329,7 +57338,7 @@ async function promptForField(field) {
|
|
|
57329
57338
|
}
|
|
57330
57339
|
if (field.schema.kind === "boolean") {
|
|
57331
57340
|
const selected = await confirm2({
|
|
57332
|
-
message: field
|
|
57341
|
+
message: fieldPromptLabel(field),
|
|
57333
57342
|
initialValue: field.hasDefault ? Boolean(field.defaultValue) : void 0
|
|
57334
57343
|
});
|
|
57335
57344
|
if (isCancel(selected)) {
|
|
@@ -57339,7 +57348,7 @@ async function promptForField(field) {
|
|
|
57339
57348
|
return selected;
|
|
57340
57349
|
}
|
|
57341
57350
|
const entered = await text3({
|
|
57342
|
-
message: field
|
|
57351
|
+
message: fieldPromptLabel(field),
|
|
57343
57352
|
initialValue: field.hasDefault && field.defaultValue !== void 0 ? formatResolvedValue(field.defaultValue) : void 0
|
|
57344
57353
|
});
|
|
57345
57354
|
if (isCancel(entered)) {
|
|
@@ -70879,6 +70888,29 @@ function isImportMetaReference(node) {
|
|
|
70879
70888
|
}
|
|
70880
70889
|
return node.type === "MemberExpression" && (isImportMetaReference(node.object) || node.computed && isImportMetaReference(node.property));
|
|
70881
70890
|
}
|
|
70891
|
+
function isAssignmentOperator(value) {
|
|
70892
|
+
switch (value) {
|
|
70893
|
+
case "=":
|
|
70894
|
+
case "+=":
|
|
70895
|
+
case "-=":
|
|
70896
|
+
case "*=":
|
|
70897
|
+
case "/=":
|
|
70898
|
+
case "%=":
|
|
70899
|
+
case "**=":
|
|
70900
|
+
case "&=":
|
|
70901
|
+
case "|=":
|
|
70902
|
+
case "^=":
|
|
70903
|
+
case "<<=":
|
|
70904
|
+
case ">>=":
|
|
70905
|
+
case ">>>=":
|
|
70906
|
+
case "&&=":
|
|
70907
|
+
case "||=":
|
|
70908
|
+
case "??=":
|
|
70909
|
+
return true;
|
|
70910
|
+
default:
|
|
70911
|
+
return false;
|
|
70912
|
+
}
|
|
70913
|
+
}
|
|
70882
70914
|
function createNumericLiteral(token) {
|
|
70883
70915
|
return {
|
|
70884
70916
|
type: "NumericLiteral",
|
|
@@ -71404,14 +71436,15 @@ var init_parser3 = __esm({
|
|
|
71404
71436
|
};
|
|
71405
71437
|
}
|
|
71406
71438
|
const left = this.parseConditionalExpression();
|
|
71407
|
-
|
|
71439
|
+
const operator = this.consumeAssignmentOperator();
|
|
71440
|
+
if (operator === void 0) {
|
|
71408
71441
|
return left;
|
|
71409
71442
|
}
|
|
71410
71443
|
const right = this.parseAssignmentExpression();
|
|
71411
71444
|
return {
|
|
71412
71445
|
node: {
|
|
71413
71446
|
type: "AssignmentExpression",
|
|
71414
|
-
operator
|
|
71447
|
+
operator,
|
|
71415
71448
|
left: this.toAssignmentTarget(left.node),
|
|
71416
71449
|
right: right.node,
|
|
71417
71450
|
span: createSpan2(left.node.span.start, right.node.span.end)
|
|
@@ -73130,6 +73163,14 @@ var init_parser3 = __esm({
|
|
|
73130
73163
|
this.index += 1;
|
|
73131
73164
|
return token;
|
|
73132
73165
|
}
|
|
73166
|
+
consumeAssignmentOperator() {
|
|
73167
|
+
const token = this.currentToken();
|
|
73168
|
+
if (token.type !== "punctuator" || !isAssignmentOperator(token.value)) {
|
|
73169
|
+
return void 0;
|
|
73170
|
+
}
|
|
73171
|
+
this.index += 1;
|
|
73172
|
+
return token.value;
|
|
73173
|
+
}
|
|
73133
73174
|
expectPunctuator(value) {
|
|
73134
73175
|
const token = this.currentToken();
|
|
73135
73176
|
if (token.type !== "punctuator" || token.value !== value) {
|
|
@@ -74380,7 +74421,10 @@ var init_AS002 = __esm({
|
|
|
74380
74421
|
|
|
74381
74422
|
// packages/agent-script/src/lint/rules/AS003.ts
|
|
74382
74423
|
function AS003(source, options = {}) {
|
|
74383
|
-
return new AS003Scanner(
|
|
74424
|
+
return new AS003Scanner(
|
|
74425
|
+
options.filename ?? "<input>",
|
|
74426
|
+
/* @__PURE__ */ new Set([...DEFAULT_ALLOWED_GLOBALS, ...options.allowedGlobals ?? []])
|
|
74427
|
+
).scan(source);
|
|
74384
74428
|
}
|
|
74385
74429
|
function formatNearMatchMessage(names) {
|
|
74386
74430
|
if (names.length === 1) {
|
|
@@ -74413,16 +74457,31 @@ function getLevenshteinDistance2(left, right) {
|
|
|
74413
74457
|
}
|
|
74414
74458
|
return previous[right.length];
|
|
74415
74459
|
}
|
|
74416
|
-
var AS003Scanner;
|
|
74460
|
+
var DEFAULT_ALLOWED_GLOBALS, AS003Scanner;
|
|
74417
74461
|
var init_AS003 = __esm({
|
|
74418
74462
|
"packages/agent-script/src/lint/rules/AS003.ts"() {
|
|
74419
74463
|
"use strict";
|
|
74420
74464
|
init_parser3();
|
|
74465
|
+
DEFAULT_ALLOWED_GLOBALS = [
|
|
74466
|
+
"Array",
|
|
74467
|
+
"Boolean",
|
|
74468
|
+
"Error",
|
|
74469
|
+
"JSON",
|
|
74470
|
+
"Math",
|
|
74471
|
+
"Number",
|
|
74472
|
+
"Object",
|
|
74473
|
+
"Promise",
|
|
74474
|
+
"String",
|
|
74475
|
+
"TypeError",
|
|
74476
|
+
"console"
|
|
74477
|
+
];
|
|
74421
74478
|
AS003Scanner = class {
|
|
74422
|
-
constructor(filename) {
|
|
74479
|
+
constructor(filename, allowedGlobals) {
|
|
74423
74480
|
this.filename = filename;
|
|
74481
|
+
this.allowedGlobals = allowedGlobals;
|
|
74424
74482
|
}
|
|
74425
74483
|
filename;
|
|
74484
|
+
allowedGlobals;
|
|
74426
74485
|
diagnostics = [];
|
|
74427
74486
|
scopes = [];
|
|
74428
74487
|
scan(source) {
|
|
@@ -74780,8 +74839,11 @@ var init_AS003 = __esm({
|
|
|
74780
74839
|
if (this.resolveBinding(node.name) !== void 0) {
|
|
74781
74840
|
return;
|
|
74782
74841
|
}
|
|
74842
|
+
if (this.allowedGlobals.has(node.name)) {
|
|
74843
|
+
return;
|
|
74844
|
+
}
|
|
74783
74845
|
const visibleNames = this.collectVisibleNames();
|
|
74784
|
-
const nearMatches = visibleNames.map((name) => ({ distance: getLevenshteinDistance2(node.name, name), name })).filter((entry) => entry.distance <= 2).sort((left, right) => left.distance - right.distance || left.name.localeCompare(right.name)).map((entry) => entry.name);
|
|
74846
|
+
const nearMatches = this.collectSuggestionNames(visibleNames).map((name) => ({ distance: getLevenshteinDistance2(node.name, name), name })).filter((entry) => entry.distance <= 2).sort((left, right) => left.distance - right.distance || left.name.localeCompare(right.name)).map((entry) => entry.name);
|
|
74785
74847
|
const message2 = nearMatches.length > 0 ? `Unknown identifier '${node.name}'. ${formatNearMatchMessage(nearMatches)}` : `Unknown identifier '${node.name}'. ${formatVisibleNamesMessage(visibleNames)}`;
|
|
74786
74848
|
this.diagnostics.push({
|
|
74787
74849
|
code: "AS003",
|
|
@@ -74820,6 +74882,10 @@ var init_AS003 = __esm({
|
|
|
74820
74882
|
}
|
|
74821
74883
|
return [...names].sort((left, right) => left.localeCompare(right));
|
|
74822
74884
|
}
|
|
74885
|
+
collectSuggestionNames(visibleNames) {
|
|
74886
|
+
const names = /* @__PURE__ */ new Set([...visibleNames, ...this.allowedGlobals]);
|
|
74887
|
+
return [...names].sort((left, right) => left.localeCompare(right));
|
|
74888
|
+
}
|
|
74823
74889
|
collectModuleBindings(body) {
|
|
74824
74890
|
const bindings = [];
|
|
74825
74891
|
for (const statement of body) {
|
|
@@ -80989,12 +81055,138 @@ async function evaluateObjectExpression(node, context) {
|
|
|
80989
81055
|
value: object
|
|
80990
81056
|
};
|
|
80991
81057
|
}
|
|
81058
|
+
async function evaluateTemplateLiteral(node, context) {
|
|
81059
|
+
let value = context.budget.allocateString(node.quasis[0]?.value.cooked ?? "");
|
|
81060
|
+
for (let index = 0; index < node.expressions.length; index += 1) {
|
|
81061
|
+
const expression = await evaluateNode(node.expressions[index], context);
|
|
81062
|
+
if (expression.kind !== "normal") {
|
|
81063
|
+
return expression;
|
|
81064
|
+
}
|
|
81065
|
+
const expressionText = context.budget.allocateString(String(expression.value));
|
|
81066
|
+
value = context.budget.allocateString(value + expressionText);
|
|
81067
|
+
const quasiText = context.budget.allocateString(node.quasis[index + 1]?.value.cooked ?? "");
|
|
81068
|
+
value = context.budget.allocateString(value + quasiText);
|
|
81069
|
+
}
|
|
81070
|
+
return {
|
|
81071
|
+
kind: "normal",
|
|
81072
|
+
hasValue: true,
|
|
81073
|
+
value
|
|
81074
|
+
};
|
|
81075
|
+
}
|
|
80992
81076
|
async function evaluateArrowFunction(node, context) {
|
|
80993
81077
|
return evaluateArrowFunctionExpression(node, context, evaluateNode);
|
|
80994
81078
|
}
|
|
80995
81079
|
async function evaluateAwait(node, context) {
|
|
80996
81080
|
return evaluateAwaitExpression(node, context, evaluateNode);
|
|
80997
81081
|
}
|
|
81082
|
+
async function evaluateBinaryExpression(node, context) {
|
|
81083
|
+
const left = await evaluateNode(node.left, context);
|
|
81084
|
+
if (left.kind !== "normal") {
|
|
81085
|
+
return left;
|
|
81086
|
+
}
|
|
81087
|
+
const right = await evaluateNode(node.right, context);
|
|
81088
|
+
if (right.kind !== "normal") {
|
|
81089
|
+
return right;
|
|
81090
|
+
}
|
|
81091
|
+
const value = applyBinaryOperator(node, left.value, right.value, context);
|
|
81092
|
+
return {
|
|
81093
|
+
kind: "normal",
|
|
81094
|
+
hasValue: true,
|
|
81095
|
+
value
|
|
81096
|
+
};
|
|
81097
|
+
}
|
|
81098
|
+
async function evaluateAssignmentExpression(node, context) {
|
|
81099
|
+
if (node.left.type === "MemberExpression") {
|
|
81100
|
+
throw new Error("member-target assignment is not supported");
|
|
81101
|
+
}
|
|
81102
|
+
if (node.left.type !== "Identifier") {
|
|
81103
|
+
return {
|
|
81104
|
+
kind: "error",
|
|
81105
|
+
error: createError(
|
|
81106
|
+
"UNSUPPORTED_NODE",
|
|
81107
|
+
node,
|
|
81108
|
+
`Unsupported assignment target '${node.left.type}'.`
|
|
81109
|
+
)
|
|
81110
|
+
};
|
|
81111
|
+
}
|
|
81112
|
+
const binding = context.scope.lookup(node.left.name);
|
|
81113
|
+
if (!binding.found) {
|
|
81114
|
+
return {
|
|
81115
|
+
kind: "error",
|
|
81116
|
+
error: createError(
|
|
81117
|
+
"UNBOUND_IDENTIFIER",
|
|
81118
|
+
node.left,
|
|
81119
|
+
`Identifier '${node.left.name}' is not defined.`
|
|
81120
|
+
)
|
|
81121
|
+
};
|
|
81122
|
+
}
|
|
81123
|
+
if (binding.kind === "const") {
|
|
81124
|
+
throw new Error(`Cannot assign to const '${node.left.name}'`);
|
|
81125
|
+
}
|
|
81126
|
+
if (node.operator === "&&=" && !isTruthy(binding.value)) {
|
|
81127
|
+
return {
|
|
81128
|
+
kind: "normal",
|
|
81129
|
+
hasValue: true,
|
|
81130
|
+
value: binding.value
|
|
81131
|
+
};
|
|
81132
|
+
}
|
|
81133
|
+
if (node.operator === "||=" && isTruthy(binding.value)) {
|
|
81134
|
+
return {
|
|
81135
|
+
kind: "normal",
|
|
81136
|
+
hasValue: true,
|
|
81137
|
+
value: binding.value
|
|
81138
|
+
};
|
|
81139
|
+
}
|
|
81140
|
+
if (node.operator === "??=" && binding.value !== null && binding.value !== void 0) {
|
|
81141
|
+
return {
|
|
81142
|
+
kind: "normal",
|
|
81143
|
+
hasValue: true,
|
|
81144
|
+
value: binding.value
|
|
81145
|
+
};
|
|
81146
|
+
}
|
|
81147
|
+
const right = await evaluateNode(node.right, context);
|
|
81148
|
+
if (right.kind !== "normal") {
|
|
81149
|
+
return right;
|
|
81150
|
+
}
|
|
81151
|
+
const value = node.operator === "=" || node.operator === "&&=" || node.operator === "||=" || node.operator === "??=" ? right.value : applyCompoundAssignmentOperator(node.operator, binding.value, right.value, context);
|
|
81152
|
+
context.scope.assign(node.left.name, value);
|
|
81153
|
+
return {
|
|
81154
|
+
kind: "normal",
|
|
81155
|
+
hasValue: true,
|
|
81156
|
+
value
|
|
81157
|
+
};
|
|
81158
|
+
}
|
|
81159
|
+
async function evaluateLogicalExpression(node, context) {
|
|
81160
|
+
const left = await evaluateNode(node.left, context);
|
|
81161
|
+
if (left.kind !== "normal") {
|
|
81162
|
+
return left;
|
|
81163
|
+
}
|
|
81164
|
+
switch (node.operator) {
|
|
81165
|
+
case "&&":
|
|
81166
|
+
if (!isTruthy(left.value)) {
|
|
81167
|
+
return left;
|
|
81168
|
+
}
|
|
81169
|
+
break;
|
|
81170
|
+
case "||":
|
|
81171
|
+
if (isTruthy(left.value)) {
|
|
81172
|
+
return left;
|
|
81173
|
+
}
|
|
81174
|
+
break;
|
|
81175
|
+
case "??":
|
|
81176
|
+
if (left.value !== null && left.value !== void 0) {
|
|
81177
|
+
return left;
|
|
81178
|
+
}
|
|
81179
|
+
break;
|
|
81180
|
+
}
|
|
81181
|
+
return evaluateNode(node.right, context);
|
|
81182
|
+
}
|
|
81183
|
+
async function evaluateConditionalExpression(node, context) {
|
|
81184
|
+
const test = await evaluateNode(node.test, context);
|
|
81185
|
+
if (test.kind !== "normal") {
|
|
81186
|
+
return test;
|
|
81187
|
+
}
|
|
81188
|
+
return evaluateNode(isTruthy(test.value) ? node.consequent : node.alternate, context);
|
|
81189
|
+
}
|
|
80998
81190
|
async function evaluateIdentifier(node, context) {
|
|
80999
81191
|
const binding = context.scope.lookup(node.name);
|
|
81000
81192
|
if (!binding.found) {
|
|
@@ -81033,9 +81225,6 @@ async function evaluateExportNamedDeclaration(node, context) {
|
|
|
81033
81225
|
}
|
|
81034
81226
|
async function evaluateVariableDeclaration(node, context) {
|
|
81035
81227
|
for (const declarator of node.declarations) {
|
|
81036
|
-
if (declarator.id.type !== "Identifier") {
|
|
81037
|
-
throw new TypeError(`Unsupported variable declaration pattern '${declarator.id.type}'.`);
|
|
81038
|
-
}
|
|
81039
81228
|
const value = declarator.init === void 0 ? {
|
|
81040
81229
|
kind: "normal",
|
|
81041
81230
|
hasValue: true,
|
|
@@ -81044,7 +81233,10 @@ async function evaluateVariableDeclaration(node, context) {
|
|
|
81044
81233
|
if (value.kind !== "normal") {
|
|
81045
81234
|
return value;
|
|
81046
81235
|
}
|
|
81047
|
-
|
|
81236
|
+
const binding = await bindDeclarationPattern(declarator.id, value.value, node.kind, context);
|
|
81237
|
+
if (!binding.ok) {
|
|
81238
|
+
return binding.result;
|
|
81239
|
+
}
|
|
81048
81240
|
}
|
|
81049
81241
|
return {
|
|
81050
81242
|
kind: "normal",
|
|
@@ -81052,6 +81244,107 @@ async function evaluateVariableDeclaration(node, context) {
|
|
|
81052
81244
|
value: void 0
|
|
81053
81245
|
};
|
|
81054
81246
|
}
|
|
81247
|
+
async function bindDeclarationPattern(pattern, value, kind, context) {
|
|
81248
|
+
switch (pattern.type) {
|
|
81249
|
+
case "Identifier":
|
|
81250
|
+
context.scope.declare(pattern.name, kind, value);
|
|
81251
|
+
return { ok: true };
|
|
81252
|
+
case "MemberExpression":
|
|
81253
|
+
throw new TypeError("Destructuring declarations cannot bind to member expressions.");
|
|
81254
|
+
case "AssignmentPattern":
|
|
81255
|
+
return bindDeclarationAssignmentPattern(pattern, value, kind, context);
|
|
81256
|
+
case "ArrayPattern":
|
|
81257
|
+
return bindDeclarationArrayPattern(pattern, value, kind, context);
|
|
81258
|
+
case "ObjectPattern":
|
|
81259
|
+
return bindDeclarationObjectPattern(pattern, value, kind, context);
|
|
81260
|
+
case "RestElement":
|
|
81261
|
+
return bindDeclarationPattern(pattern.argument, value, kind, context);
|
|
81262
|
+
}
|
|
81263
|
+
}
|
|
81264
|
+
async function bindDeclarationAssignmentPattern(pattern, value, kind, context) {
|
|
81265
|
+
if (value !== void 0) {
|
|
81266
|
+
return bindDeclarationPattern(pattern.left, value, kind, context);
|
|
81267
|
+
}
|
|
81268
|
+
const defaultValue = await evaluateNode(pattern.right, context);
|
|
81269
|
+
if (defaultValue.kind !== "normal") {
|
|
81270
|
+
return {
|
|
81271
|
+
ok: false,
|
|
81272
|
+
result: defaultValue
|
|
81273
|
+
};
|
|
81274
|
+
}
|
|
81275
|
+
return bindDeclarationPattern(pattern.left, defaultValue.value, kind, context);
|
|
81276
|
+
}
|
|
81277
|
+
async function bindDeclarationArrayPattern(pattern, value, kind, context) {
|
|
81278
|
+
if (!Array.isArray(value)) {
|
|
81279
|
+
throw new TypeError("Array destructuring declarations require an array value.");
|
|
81280
|
+
}
|
|
81281
|
+
for (let index = 0; index < pattern.elements.length; index += 1) {
|
|
81282
|
+
const element = pattern.elements[index];
|
|
81283
|
+
if (element === null) {
|
|
81284
|
+
continue;
|
|
81285
|
+
}
|
|
81286
|
+
const elementValue = element.type === "RestElement" ? value.slice(index) : value[index];
|
|
81287
|
+
const binding = await bindDeclarationPattern(element, elementValue, kind, context);
|
|
81288
|
+
if (!binding.ok) {
|
|
81289
|
+
return binding;
|
|
81290
|
+
}
|
|
81291
|
+
}
|
|
81292
|
+
return { ok: true };
|
|
81293
|
+
}
|
|
81294
|
+
async function bindDeclarationObjectPattern(pattern, value, kind, context) {
|
|
81295
|
+
if (typeof value !== "object" || value === null) {
|
|
81296
|
+
throw new TypeError("Object destructuring declarations require a non-null object value.");
|
|
81297
|
+
}
|
|
81298
|
+
const excludedKeys = /* @__PURE__ */ new Set();
|
|
81299
|
+
for (const property of pattern.properties) {
|
|
81300
|
+
if (property.type === "RestElement") {
|
|
81301
|
+
const binding2 = await bindDeclarationPattern(
|
|
81302
|
+
property,
|
|
81303
|
+
copyObjectRestValue(value, excludedKeys),
|
|
81304
|
+
kind,
|
|
81305
|
+
context
|
|
81306
|
+
);
|
|
81307
|
+
if (!binding2.ok) {
|
|
81308
|
+
return binding2;
|
|
81309
|
+
}
|
|
81310
|
+
continue;
|
|
81311
|
+
}
|
|
81312
|
+
const key2 = await evaluateDeclarationPatternKey(property, context);
|
|
81313
|
+
if (!key2.ok) {
|
|
81314
|
+
return key2;
|
|
81315
|
+
}
|
|
81316
|
+
excludedKeys.add(String(key2.value));
|
|
81317
|
+
const binding = await bindDeclarationPattern(
|
|
81318
|
+
property.value,
|
|
81319
|
+
value[key2.value],
|
|
81320
|
+
kind,
|
|
81321
|
+
context
|
|
81322
|
+
);
|
|
81323
|
+
if (!binding.ok) {
|
|
81324
|
+
return binding;
|
|
81325
|
+
}
|
|
81326
|
+
}
|
|
81327
|
+
return { ok: true };
|
|
81328
|
+
}
|
|
81329
|
+
async function evaluateDeclarationPatternKey(property, context) {
|
|
81330
|
+
if (!property.computed) {
|
|
81331
|
+
return {
|
|
81332
|
+
ok: true,
|
|
81333
|
+
value: getStaticPropertyName(property.key)
|
|
81334
|
+
};
|
|
81335
|
+
}
|
|
81336
|
+
return evaluateMemberProperty(property.key, context);
|
|
81337
|
+
}
|
|
81338
|
+
function copyObjectRestValue(value, excludedKeys) {
|
|
81339
|
+
const rest = /* @__PURE__ */ Object.create(null);
|
|
81340
|
+
for (const [key2, entryValue] of Object.entries(value)) {
|
|
81341
|
+
if (excludedKeys.has(key2)) {
|
|
81342
|
+
continue;
|
|
81343
|
+
}
|
|
81344
|
+
defineSandboxProperty(rest, key2, entryValue);
|
|
81345
|
+
}
|
|
81346
|
+
return rest;
|
|
81347
|
+
}
|
|
81055
81348
|
async function evaluateBlockStatement(node, context) {
|
|
81056
81349
|
for (const statement of node.body) {
|
|
81057
81350
|
const result = await evaluateNode(statement, context);
|
|
@@ -81065,6 +81358,144 @@ async function evaluateBlockStatement(node, context) {
|
|
|
81065
81358
|
value: void 0
|
|
81066
81359
|
};
|
|
81067
81360
|
}
|
|
81361
|
+
async function evaluateIfStatement(node, context) {
|
|
81362
|
+
const test = await evaluateNode(node.test, context);
|
|
81363
|
+
if (test.kind !== "normal") {
|
|
81364
|
+
return test;
|
|
81365
|
+
}
|
|
81366
|
+
const branch = isTruthy(test.value) ? node.consequent : node.alternate;
|
|
81367
|
+
if (branch === void 0) {
|
|
81368
|
+
return {
|
|
81369
|
+
kind: "normal",
|
|
81370
|
+
hasValue: false,
|
|
81371
|
+
value: void 0
|
|
81372
|
+
};
|
|
81373
|
+
}
|
|
81374
|
+
return evaluateNode(branch, context);
|
|
81375
|
+
}
|
|
81376
|
+
async function evaluateForOfStatement(node, context) {
|
|
81377
|
+
const iterable = await evaluateNode(node.right, context);
|
|
81378
|
+
if (iterable.kind !== "normal") {
|
|
81379
|
+
return iterable;
|
|
81380
|
+
}
|
|
81381
|
+
if (!Array.isArray(iterable.value)) {
|
|
81382
|
+
throw new TypeError(`${String(iterable.value)} is not a supported iterable`);
|
|
81383
|
+
}
|
|
81384
|
+
for (const entry of iterable.value) {
|
|
81385
|
+
const scope = context.scope.child();
|
|
81386
|
+
bindForOfLoopVariable(node.left, entry, scope);
|
|
81387
|
+
const result = await evaluateNode(node.body, {
|
|
81388
|
+
...context,
|
|
81389
|
+
scope
|
|
81390
|
+
});
|
|
81391
|
+
if (result.kind === "break") {
|
|
81392
|
+
return {
|
|
81393
|
+
kind: "normal",
|
|
81394
|
+
hasValue: false,
|
|
81395
|
+
value: void 0
|
|
81396
|
+
};
|
|
81397
|
+
}
|
|
81398
|
+
if (result.kind === "continue") {
|
|
81399
|
+
continue;
|
|
81400
|
+
}
|
|
81401
|
+
if (result.kind !== "normal") {
|
|
81402
|
+
return result;
|
|
81403
|
+
}
|
|
81404
|
+
}
|
|
81405
|
+
return {
|
|
81406
|
+
kind: "normal",
|
|
81407
|
+
hasValue: false,
|
|
81408
|
+
value: void 0
|
|
81409
|
+
};
|
|
81410
|
+
}
|
|
81411
|
+
async function evaluateForStatement(node, context) {
|
|
81412
|
+
const loopContext = {
|
|
81413
|
+
...context,
|
|
81414
|
+
scope: context.scope.child()
|
|
81415
|
+
};
|
|
81416
|
+
if (node.init !== void 0) {
|
|
81417
|
+
const init = await evaluateNode(node.init, loopContext);
|
|
81418
|
+
if (init.kind !== "normal") {
|
|
81419
|
+
return init;
|
|
81420
|
+
}
|
|
81421
|
+
}
|
|
81422
|
+
while (true) {
|
|
81423
|
+
context.budget.visitNode();
|
|
81424
|
+
context.stats.nodeVisits += 1;
|
|
81425
|
+
if (node.test !== void 0) {
|
|
81426
|
+
const test = await evaluateNode(node.test, loopContext);
|
|
81427
|
+
if (test.kind !== "normal") {
|
|
81428
|
+
return test;
|
|
81429
|
+
}
|
|
81430
|
+
if (!isTruthy(test.value)) {
|
|
81431
|
+
return {
|
|
81432
|
+
kind: "normal",
|
|
81433
|
+
hasValue: false,
|
|
81434
|
+
value: void 0
|
|
81435
|
+
};
|
|
81436
|
+
}
|
|
81437
|
+
}
|
|
81438
|
+
const result = await evaluateNode(node.body, loopContext);
|
|
81439
|
+
if (result.kind === "break") {
|
|
81440
|
+
return {
|
|
81441
|
+
kind: "normal",
|
|
81442
|
+
hasValue: false,
|
|
81443
|
+
value: void 0
|
|
81444
|
+
};
|
|
81445
|
+
}
|
|
81446
|
+
if (result.kind !== "normal" && result.kind !== "continue") {
|
|
81447
|
+
return result;
|
|
81448
|
+
}
|
|
81449
|
+
if (node.update !== void 0) {
|
|
81450
|
+
const update = await evaluateNode(node.update, loopContext);
|
|
81451
|
+
if (update.kind !== "normal") {
|
|
81452
|
+
return update;
|
|
81453
|
+
}
|
|
81454
|
+
}
|
|
81455
|
+
}
|
|
81456
|
+
}
|
|
81457
|
+
async function evaluateWhileStatement(node, context) {
|
|
81458
|
+
while (true) {
|
|
81459
|
+
const test = await evaluateNode(node.test, context);
|
|
81460
|
+
if (test.kind !== "normal") {
|
|
81461
|
+
return test;
|
|
81462
|
+
}
|
|
81463
|
+
if (!isTruthy(test.value)) {
|
|
81464
|
+
return {
|
|
81465
|
+
kind: "normal",
|
|
81466
|
+
hasValue: false,
|
|
81467
|
+
value: void 0
|
|
81468
|
+
};
|
|
81469
|
+
}
|
|
81470
|
+
const result = await evaluateNode(node.body, context);
|
|
81471
|
+
if (result.kind === "break") {
|
|
81472
|
+
return {
|
|
81473
|
+
kind: "normal",
|
|
81474
|
+
hasValue: false,
|
|
81475
|
+
value: void 0
|
|
81476
|
+
};
|
|
81477
|
+
}
|
|
81478
|
+
if (result.kind === "continue") {
|
|
81479
|
+
continue;
|
|
81480
|
+
}
|
|
81481
|
+
if (result.kind !== "normal") {
|
|
81482
|
+
return result;
|
|
81483
|
+
}
|
|
81484
|
+
}
|
|
81485
|
+
}
|
|
81486
|
+
function bindForOfLoopVariable(left, value, scope) {
|
|
81487
|
+
if (left.type !== "VariableDeclaration") {
|
|
81488
|
+
throw new TypeError(`Unsupported for...of left-hand side '${left.type}'.`);
|
|
81489
|
+
}
|
|
81490
|
+
const [declarator] = left.declarations;
|
|
81491
|
+
if (left.declarations.length !== 1 || declarator === void 0) {
|
|
81492
|
+
throw new TypeError("for...of declarations must include exactly one declarator.");
|
|
81493
|
+
}
|
|
81494
|
+
if (declarator.id.type !== "Identifier") {
|
|
81495
|
+
throw new TypeError(`Unsupported for...of declaration pattern '${declarator.id.type}'.`);
|
|
81496
|
+
}
|
|
81497
|
+
scope.declare(declarator.id.name, left.kind, value);
|
|
81498
|
+
}
|
|
81068
81499
|
async function evaluateExpressionStatement(node, context) {
|
|
81069
81500
|
return evaluateNode(node.expression, context);
|
|
81070
81501
|
}
|
|
@@ -81376,6 +81807,99 @@ function applyUnaryOperator(operator, value) {
|
|
|
81376
81807
|
return ~value;
|
|
81377
81808
|
}
|
|
81378
81809
|
}
|
|
81810
|
+
function isTruthy(value) {
|
|
81811
|
+
return applyUnaryOperator("!", value) === false;
|
|
81812
|
+
}
|
|
81813
|
+
function applyBinaryOperator(node, left, right, context) {
|
|
81814
|
+
switch (node.operator) {
|
|
81815
|
+
case "+":
|
|
81816
|
+
return applyAdditionOperator(left, right, context);
|
|
81817
|
+
case "-":
|
|
81818
|
+
return Number(left) - Number(right);
|
|
81819
|
+
case "*":
|
|
81820
|
+
return Number(left) * Number(right);
|
|
81821
|
+
case "/":
|
|
81822
|
+
return Number(left) / Number(right);
|
|
81823
|
+
case "%":
|
|
81824
|
+
return Number(left) % Number(right);
|
|
81825
|
+
case "**":
|
|
81826
|
+
return Number(left) ** Number(right);
|
|
81827
|
+
case "<":
|
|
81828
|
+
return compareLessThan(left, right);
|
|
81829
|
+
case "<=":
|
|
81830
|
+
return compareLessThanOrEqual(left, right);
|
|
81831
|
+
case ">":
|
|
81832
|
+
return compareGreaterThan(left, right);
|
|
81833
|
+
case ">=":
|
|
81834
|
+
return compareGreaterThanOrEqual(left, right);
|
|
81835
|
+
case "===":
|
|
81836
|
+
case "==":
|
|
81837
|
+
return left === right;
|
|
81838
|
+
case "!==":
|
|
81839
|
+
case "!=":
|
|
81840
|
+
return left !== right;
|
|
81841
|
+
case "&":
|
|
81842
|
+
return Number(left) & Number(right);
|
|
81843
|
+
case "|":
|
|
81844
|
+
return Number(left) | Number(right);
|
|
81845
|
+
case "^":
|
|
81846
|
+
return Number(left) ^ Number(right);
|
|
81847
|
+
case "<<":
|
|
81848
|
+
return Number(left) << Number(right);
|
|
81849
|
+
case ">>":
|
|
81850
|
+
return Number(left) >> Number(right);
|
|
81851
|
+
case ">>>":
|
|
81852
|
+
return Number(left) >>> Number(right);
|
|
81853
|
+
case "in":
|
|
81854
|
+
throw createError("UNSUPPORTED_NODE", node, "Binary operator 'in' is not supported.");
|
|
81855
|
+
}
|
|
81856
|
+
}
|
|
81857
|
+
function applyCompoundAssignmentOperator(operator, left, right, context) {
|
|
81858
|
+
switch (operator) {
|
|
81859
|
+
case "+=":
|
|
81860
|
+
return applyAdditionOperator(left, right, context);
|
|
81861
|
+
case "-=":
|
|
81862
|
+
return Number(left) - Number(right);
|
|
81863
|
+
case "*=":
|
|
81864
|
+
return Number(left) * Number(right);
|
|
81865
|
+
case "/=":
|
|
81866
|
+
return Number(left) / Number(right);
|
|
81867
|
+
case "%=":
|
|
81868
|
+
return Number(left) % Number(right);
|
|
81869
|
+
case "**=":
|
|
81870
|
+
return Number(left) ** Number(right);
|
|
81871
|
+
case "&=":
|
|
81872
|
+
return Number(left) & Number(right);
|
|
81873
|
+
case "|=":
|
|
81874
|
+
return Number(left) | Number(right);
|
|
81875
|
+
case "^=":
|
|
81876
|
+
return Number(left) ^ Number(right);
|
|
81877
|
+
case "<<=":
|
|
81878
|
+
return Number(left) << Number(right);
|
|
81879
|
+
case ">>=":
|
|
81880
|
+
return Number(left) >> Number(right);
|
|
81881
|
+
case ">>>=":
|
|
81882
|
+
return Number(left) >>> Number(right);
|
|
81883
|
+
}
|
|
81884
|
+
}
|
|
81885
|
+
function applyAdditionOperator(left, right, context) {
|
|
81886
|
+
if (typeof left === "string" || typeof right === "string") {
|
|
81887
|
+
return context.budget.allocateString(String(left) + String(right));
|
|
81888
|
+
}
|
|
81889
|
+
return Number(left) + Number(right);
|
|
81890
|
+
}
|
|
81891
|
+
function compareLessThan(left, right) {
|
|
81892
|
+
return typeof left === "string" && typeof right === "string" ? left < right : Number(left) < Number(right);
|
|
81893
|
+
}
|
|
81894
|
+
function compareLessThanOrEqual(left, right) {
|
|
81895
|
+
return typeof left === "string" && typeof right === "string" ? left <= right : Number(left) <= Number(right);
|
|
81896
|
+
}
|
|
81897
|
+
function compareGreaterThan(left, right) {
|
|
81898
|
+
return typeof left === "string" && typeof right === "string" ? left > right : Number(left) > Number(right);
|
|
81899
|
+
}
|
|
81900
|
+
function compareGreaterThanOrEqual(left, right) {
|
|
81901
|
+
return typeof left === "string" && typeof right === "string" ? left >= right : Number(left) >= Number(right);
|
|
81902
|
+
}
|
|
81379
81903
|
function isIndexableSandboxValue(value) {
|
|
81380
81904
|
return Array.isArray(value) || isPlainSandboxObject(value);
|
|
81381
81905
|
}
|
|
@@ -81504,15 +82028,37 @@ async function evaluateObjectSpread(node, context) {
|
|
|
81504
82028
|
result: value
|
|
81505
82029
|
};
|
|
81506
82030
|
}
|
|
81507
|
-
if (
|
|
81508
|
-
throw new TypeError("
|
|
82031
|
+
if (Array.isArray(value.value)) {
|
|
82032
|
+
throw new TypeError("Cannot spread array into object literal.");
|
|
82033
|
+
}
|
|
82034
|
+
if (!isPlainSandboxObject(value.value)) {
|
|
82035
|
+
throw new TypeError(
|
|
82036
|
+
`Cannot spread ${describeObjectSpreadValue(value.value)} into object literal.`
|
|
82037
|
+
);
|
|
81509
82038
|
}
|
|
81510
82039
|
const spreadValue = value.value;
|
|
82040
|
+
const keys = Object.keys(spreadValue);
|
|
82041
|
+
context.budget.allocateArrayLength(keys.length);
|
|
81511
82042
|
return {
|
|
81512
82043
|
ok: true,
|
|
81513
|
-
value:
|
|
82044
|
+
value: keys.map((key2) => [key2, spreadValue[key2]])
|
|
81514
82045
|
};
|
|
81515
82046
|
}
|
|
82047
|
+
function describeObjectSpreadValue(value) {
|
|
82048
|
+
if (value === null) {
|
|
82049
|
+
return "null";
|
|
82050
|
+
}
|
|
82051
|
+
if (value === void 0) {
|
|
82052
|
+
return "undefined";
|
|
82053
|
+
}
|
|
82054
|
+
if (isSandboxClosure(value)) {
|
|
82055
|
+
return "function";
|
|
82056
|
+
}
|
|
82057
|
+
if (isSandboxPromise(value)) {
|
|
82058
|
+
return "promise";
|
|
82059
|
+
}
|
|
82060
|
+
return typeof value;
|
|
82061
|
+
}
|
|
81516
82062
|
function defineSandboxProperty(target, key2, value) {
|
|
81517
82063
|
Object.defineProperty(target, key2, {
|
|
81518
82064
|
configurable: true,
|
|
@@ -81559,16 +82105,23 @@ var init_interpreter = __esm({
|
|
|
81559
82105
|
init_scope();
|
|
81560
82106
|
dispatchTable = {
|
|
81561
82107
|
ArrayExpression: evaluateArrayExpression,
|
|
82108
|
+
AssignmentExpression: evaluateAssignmentExpression,
|
|
81562
82109
|
ArrowFunctionExpression: evaluateArrowFunction,
|
|
81563
82110
|
AwaitExpression: evaluateAwait,
|
|
82111
|
+
BinaryExpression: evaluateBinaryExpression,
|
|
81564
82112
|
BlockStatement: evaluateBlockStatement,
|
|
81565
82113
|
BooleanLiteral: evaluatePrimitiveLiteral,
|
|
81566
82114
|
CallExpression: evaluateCallExpression,
|
|
82115
|
+
ConditionalExpression: evaluateConditionalExpression,
|
|
81567
82116
|
ContinueStatement: evaluateContinueStatement,
|
|
81568
82117
|
ExportDefaultDeclaration: evaluateExportDefaultDeclaration,
|
|
81569
82118
|
ExportNamedDeclaration: evaluateExportNamedDeclaration,
|
|
81570
82119
|
ExpressionStatement: evaluateExpressionStatement,
|
|
82120
|
+
ForOfStatement: evaluateForOfStatement,
|
|
82121
|
+
ForStatement: evaluateForStatement,
|
|
82122
|
+
IfStatement: evaluateIfStatement,
|
|
81571
82123
|
Identifier: evaluateIdentifier,
|
|
82124
|
+
LogicalExpression: evaluateLogicalExpression,
|
|
81572
82125
|
MemberExpression: evaluateMemberExpression,
|
|
81573
82126
|
MetaProperty: evaluateMetaProperty,
|
|
81574
82127
|
NullLiteral: evaluatePrimitiveLiteral,
|
|
@@ -81577,10 +82130,12 @@ var init_interpreter = __esm({
|
|
|
81577
82130
|
BreakStatement: evaluateBreakStatement,
|
|
81578
82131
|
ReturnStatement: evaluateReturnStatement,
|
|
81579
82132
|
StringLiteral: evaluatePrimitiveLiteral,
|
|
82133
|
+
TemplateLiteral: evaluateTemplateLiteral,
|
|
81580
82134
|
ThrowStatement: evaluateThrowStatement2,
|
|
81581
82135
|
TryStatement: evaluateTryStatement2,
|
|
81582
82136
|
UnaryExpression: evaluateUnaryExpression,
|
|
81583
82137
|
VariableDeclaration: evaluateVariableDeclaration,
|
|
82138
|
+
WhileStatement: evaluateWhileStatement,
|
|
81584
82139
|
UndefinedLiteral: evaluatePrimitiveLiteral
|
|
81585
82140
|
};
|
|
81586
82141
|
}
|
|
@@ -85315,6 +85870,7 @@ var init_git2 = __esm({
|
|
|
85315
85870
|
// packages/agent-script/src/modules/harness.ts
|
|
85316
85871
|
function makeHarnessModule(frontmatter, meta) {
|
|
85317
85872
|
const copiedFrontmatter = copyHarnessValue(frontmatter);
|
|
85873
|
+
const constraints = readConstraints(copiedFrontmatter);
|
|
85318
85874
|
return {
|
|
85319
85875
|
tasks: copyHarnessValue(copiedFrontmatter.tasks),
|
|
85320
85876
|
agents: copyHarnessValue(copiedFrontmatter.agents),
|
|
@@ -85323,12 +85879,40 @@ function makeHarnessModule(frontmatter, meta) {
|
|
|
85323
85879
|
version: copyHarnessValue(meta.version),
|
|
85324
85880
|
filepath: meta.filepath,
|
|
85325
85881
|
frontmatter: copiedFrontmatter
|
|
85326
|
-
}
|
|
85882
|
+
},
|
|
85883
|
+
applyConstraints: (prompt) => applyConstraints(prompt, constraints)
|
|
85327
85884
|
};
|
|
85328
85885
|
}
|
|
85329
85886
|
function copyHarnessValue(value) {
|
|
85330
85887
|
return deepCopyToSandbox(value);
|
|
85331
85888
|
}
|
|
85889
|
+
function readConstraints(frontmatter) {
|
|
85890
|
+
const constraints = /* @__PURE__ */ new Set();
|
|
85891
|
+
appendConstraintValues(constraints, frontmatter.principles);
|
|
85892
|
+
appendConstraintValues(constraints, frontmatter.constraints);
|
|
85893
|
+
return [...constraints];
|
|
85894
|
+
}
|
|
85895
|
+
function appendConstraintValues(constraints, value) {
|
|
85896
|
+
if (!Array.isArray(value)) {
|
|
85897
|
+
return;
|
|
85898
|
+
}
|
|
85899
|
+
for (const item of value) {
|
|
85900
|
+
if (typeof item !== "string") {
|
|
85901
|
+
throw new Error("constraints/principles must be strings");
|
|
85902
|
+
}
|
|
85903
|
+
constraints.add(item);
|
|
85904
|
+
}
|
|
85905
|
+
}
|
|
85906
|
+
function applyConstraints(prompt, constraints) {
|
|
85907
|
+
if (constraints.length === 0) {
|
|
85908
|
+
return prompt;
|
|
85909
|
+
}
|
|
85910
|
+
const preamble = `CONSTRAINTS (hard rules, honor all):
|
|
85911
|
+
${constraints.map((constraint) => `- ${constraint}`).join("\n")}`;
|
|
85912
|
+
return prompt.length === 0 ? preamble : `${preamble}
|
|
85913
|
+
|
|
85914
|
+
${prompt}`;
|
|
85915
|
+
}
|
|
85332
85916
|
var init_harness = __esm({
|
|
85333
85917
|
"packages/agent-script/src/modules/harness.ts"() {
|
|
85334
85918
|
"use strict";
|
|
@@ -85546,7 +86130,11 @@ async function extractSchema(ajsSource, ajsPath) {
|
|
|
85546
86130
|
);
|
|
85547
86131
|
const result = await evaluateSchemaInitializer(initializerSource, ajsPath);
|
|
85548
86132
|
if (!result.ok) {
|
|
85549
|
-
throwSchemaInitializerError(
|
|
86133
|
+
throwSchemaInitializerError(
|
|
86134
|
+
ajsPath,
|
|
86135
|
+
result.error,
|
|
86136
|
+
findPriorOuterSchemaBinding(module, initializer.span.start.offset, result.error)
|
|
86137
|
+
);
|
|
85550
86138
|
}
|
|
85551
86139
|
return await deepCopyFromSandbox(result.returnValue);
|
|
85552
86140
|
}
|
|
@@ -85563,13 +86151,62 @@ async function evaluateSchemaInitializer(initializerSource, ajsPath) {
|
|
|
85563
86151
|
throwSchemaInitializerError(ajsPath, error3);
|
|
85564
86152
|
}
|
|
85565
86153
|
}
|
|
85566
|
-
function throwSchemaInitializerError(ajsPath, cause) {
|
|
86154
|
+
function throwSchemaInitializerError(ajsPath, cause, outerSchemaBindingName) {
|
|
86155
|
+
if (outerSchemaBindingName !== void 0) {
|
|
86156
|
+
throw new Error(
|
|
86157
|
+
`Failed to evaluate schema initializer in ${ajsPath}: schema initializer is evaluated in isolation; outer const '${outerSchemaBindingName}' is not in scope. Inline the value or move it into the schema literal.`,
|
|
86158
|
+
{ cause }
|
|
86159
|
+
);
|
|
86160
|
+
}
|
|
85567
86161
|
const detail = readErrorMessage2(cause);
|
|
85568
86162
|
throw new Error(
|
|
85569
86163
|
`Failed to evaluate schema initializer in ${ajsPath}: schema initializer must be pure; only "schema" module imports allowed. ${detail}`,
|
|
85570
86164
|
{ cause }
|
|
85571
86165
|
);
|
|
85572
86166
|
}
|
|
86167
|
+
function findPriorOuterSchemaBinding(module, initializerStartOffset, cause) {
|
|
86168
|
+
const unboundName = readUnboundIdentifierName(cause);
|
|
86169
|
+
if (unboundName === void 0) {
|
|
86170
|
+
return void 0;
|
|
86171
|
+
}
|
|
86172
|
+
return collectPriorTopLevelBindings(module, initializerStartOffset).has(unboundName) ? unboundName : void 0;
|
|
86173
|
+
}
|
|
86174
|
+
function collectPriorTopLevelBindings(module, initializerStartOffset) {
|
|
86175
|
+
const bindingNames = /* @__PURE__ */ new Set();
|
|
86176
|
+
for (const statement of module.body) {
|
|
86177
|
+
const declaration = readVariableDeclaration(statement);
|
|
86178
|
+
if (declaration === void 0 || declaration.kind !== "const" && declaration.kind !== "let") {
|
|
86179
|
+
continue;
|
|
86180
|
+
}
|
|
86181
|
+
for (const declarator of declaration.declarations) {
|
|
86182
|
+
if (declarator.id.type === "Identifier" && declarator.id.span.start.offset < initializerStartOffset) {
|
|
86183
|
+
bindingNames.add(declarator.id.name);
|
|
86184
|
+
}
|
|
86185
|
+
}
|
|
86186
|
+
}
|
|
86187
|
+
return bindingNames;
|
|
86188
|
+
}
|
|
86189
|
+
function readVariableDeclaration(statement) {
|
|
86190
|
+
if (statement.type === "VariableDeclaration") {
|
|
86191
|
+
return statement;
|
|
86192
|
+
}
|
|
86193
|
+
if (statement.type === "ExportNamedDeclaration") {
|
|
86194
|
+
return statement.declaration;
|
|
86195
|
+
}
|
|
86196
|
+
return void 0;
|
|
86197
|
+
}
|
|
86198
|
+
function readUnboundIdentifierName(error3) {
|
|
86199
|
+
if (typeof error3 !== "object" || error3 === null || !("code" in error3) || error3.code !== "UNBOUND_IDENTIFIER") {
|
|
86200
|
+
return void 0;
|
|
86201
|
+
}
|
|
86202
|
+
const message2 = readErrorMessage2(error3);
|
|
86203
|
+
const prefix = "Identifier '";
|
|
86204
|
+
if (!message2.startsWith(prefix)) {
|
|
86205
|
+
return void 0;
|
|
86206
|
+
}
|
|
86207
|
+
const nameEnd = message2.indexOf("'", prefix.length);
|
|
86208
|
+
return nameEnd === -1 ? void 0 : message2.slice(prefix.length, nameEnd);
|
|
86209
|
+
}
|
|
85573
86210
|
function readErrorMessage2(error3) {
|
|
85574
86211
|
if (error3 instanceof Error) {
|
|
85575
86212
|
return error3.message;
|
|
@@ -85770,17 +86407,24 @@ async function runHarnessPair(mdPath, options) {
|
|
|
85770
86407
|
body
|
|
85771
86408
|
};
|
|
85772
86409
|
const snapshotPath = resolveSnapshotPath(pair.mdPath, options.snapshotPath);
|
|
86410
|
+
const shouldResume = options.resume ?? true;
|
|
86411
|
+
if (!shouldResume) {
|
|
86412
|
+
await cleanupCompletedSnapshot(snapshotPath);
|
|
86413
|
+
}
|
|
85773
86414
|
const hostCallReplay = await createHostCallReplay(snapshotPath);
|
|
85774
|
-
const modules = withSchemaModule(
|
|
86415
|
+
const modules = withSchemaModule(
|
|
86416
|
+
hostCallReplay.wrapModules(options.modulesFor(validated, meta))
|
|
86417
|
+
);
|
|
85775
86418
|
throwOnLintErrors([
|
|
85776
86419
|
...lint(ajsSource, {
|
|
85777
86420
|
allowedExportNames: ["schema"],
|
|
86421
|
+
allowedGlobals: options.allowedGlobals,
|
|
85778
86422
|
filename: pair.ajsPath,
|
|
85779
86423
|
modules: createLintModules(modules)
|
|
85780
86424
|
}),
|
|
85781
86425
|
...missingDefaultExportDiagnostics(ajsSource, pair.ajsPath)
|
|
85782
86426
|
]);
|
|
85783
|
-
const snapshot2 = await readSnapshot(snapshotPath);
|
|
86427
|
+
const snapshot2 = shouldResume ? await readSnapshot(snapshotPath) : void 0;
|
|
85784
86428
|
let result;
|
|
85785
86429
|
try {
|
|
85786
86430
|
result = await run(ajsSource, {
|
|
@@ -85825,7 +86469,9 @@ function throwOnLintErrors(diagnostics) {
|
|
|
85825
86469
|
}
|
|
85826
86470
|
function missingDefaultExportDiagnostics(source, filename) {
|
|
85827
86471
|
const module = parseModule(source, filename);
|
|
85828
|
-
const hasDefaultExport = module.body.some(
|
|
86472
|
+
const hasDefaultExport = module.body.some(
|
|
86473
|
+
(statement) => statement.type === "ExportDefaultDeclaration"
|
|
86474
|
+
);
|
|
85829
86475
|
if (hasDefaultExport) {
|
|
85830
86476
|
return [];
|
|
85831
86477
|
}
|
|
@@ -85985,7 +86631,9 @@ function isPromiseLike5(value) {
|
|
|
85985
86631
|
function createLintModules(modules) {
|
|
85986
86632
|
const entries = modules instanceof Map ? [...modules.entries()] : Object.entries(modules);
|
|
85987
86633
|
return new Map(
|
|
85988
|
-
entries.map(
|
|
86634
|
+
entries.map(
|
|
86635
|
+
([moduleName, moduleExports]) => [moduleName, listModuleExports(moduleExports)]
|
|
86636
|
+
)
|
|
85989
86637
|
);
|
|
85990
86638
|
}
|
|
85991
86639
|
function listModuleExports(moduleExports) {
|
|
@@ -86056,6 +86704,7 @@ import { fileURLToPath as fileURLToPath14 } from "node:url";
|
|
|
86056
86704
|
function listBuiltinTemplates() {
|
|
86057
86705
|
return [
|
|
86058
86706
|
template("ralph-demo"),
|
|
86707
|
+
template("coverage-demo"),
|
|
86059
86708
|
template("experiment-demo"),
|
|
86060
86709
|
template("pipeline-demo"),
|
|
86061
86710
|
template("superintendent-demo")
|
|
@@ -86094,7 +86743,7 @@ import path111 from "node:path";
|
|
|
86094
86743
|
import { readFile as readFile47 } from "node:fs/promises";
|
|
86095
86744
|
function registerHarnessCommand(program, container) {
|
|
86096
86745
|
const harness = program.command("harness").description("Run and manage agent harness pairs.");
|
|
86097
|
-
harness.command("run").description("Run a harness pair.").argument("[md-path]", "Path to the harness .md file").option("-y, --yes", "Accept defaults without prompting.").action(async (mdPath, options) => {
|
|
86746
|
+
harness.command("run").description("Run a harness pair.").argument("[md-path]", "Path to the harness .md file").option("--snapshot-path <path>", "File to write/read harness snapshots.").option("--resume", "Resume from the snapshot file when it exists.").option("-y, --yes", "Accept defaults without prompting.").action(async (mdPath, options) => {
|
|
86098
86747
|
await executeHarnessRun(program, container, mdPath, options);
|
|
86099
86748
|
});
|
|
86100
86749
|
harness.command("new").description("Scaffold a harness pair from a built-in template.").argument("<kind>", "Built-in template kind").argument("<basename>", "New harness basename").option("--dir <path>", "Output directory for the harness pair").option("-y, --yes", "Accept defaults without prompting.").action(async (kind, basename4, options) => {
|
|
@@ -86108,16 +86757,113 @@ async function executeHarnessRun(program, container, mdPath, options) {
|
|
|
86108
86757
|
const flags = resolveHarnessFlags(program, options.yes);
|
|
86109
86758
|
const resources = createExecutionResources(container, flags, "harness:run");
|
|
86110
86759
|
const selectedPath = mdPath ? path111.resolve(container.env.cwd, mdPath) : (await resolveDiscoveredHarness(container, flags.assumeYes)).mdPath;
|
|
86760
|
+
const snapshotPath = resolveRunSnapshotPath(container, selectedPath, options.snapshotPath);
|
|
86761
|
+
await prepareHarnessSnapshot(container, selectedPath, snapshotPath, Boolean(options.resume));
|
|
86111
86762
|
resources.logger.intro("harness run");
|
|
86763
|
+
const baseMessage = `Running ${formatDisplayPath2(container, selectedPath)}`;
|
|
86764
|
+
const progress = createSnapshotProgressReader(container, snapshotPath);
|
|
86112
86765
|
const result = await withSpinner({
|
|
86113
|
-
message:
|
|
86766
|
+
message: () => formatRunMessage(baseMessage, progress.current()),
|
|
86114
86767
|
fn: () => runHarnessPair(selectedPath, {
|
|
86115
|
-
modulesFor: (frontmatter, meta) => createHarnessModules(container, frontmatter, meta)
|
|
86768
|
+
modulesFor: (frontmatter, meta) => createHarnessModules(container, frontmatter, meta),
|
|
86769
|
+
resume: Boolean(options.resume),
|
|
86770
|
+
snapshotPath
|
|
86116
86771
|
}),
|
|
86117
86772
|
stopMessage: () => `Ran ${formatDisplayPath2(container, selectedPath)}`
|
|
86118
86773
|
});
|
|
86119
86774
|
resources.logger.info(JSON.stringify(result, null, 2));
|
|
86120
86775
|
}
|
|
86776
|
+
function resolveRunSnapshotPath(container, mdPath, snapshotPath) {
|
|
86777
|
+
if (snapshotPath !== void 0) {
|
|
86778
|
+
return path111.resolve(container.env.cwd, snapshotPath);
|
|
86779
|
+
}
|
|
86780
|
+
const basename4 = path111.basename(mdPath, path111.extname(mdPath));
|
|
86781
|
+
return path111.join(container.env.cwd, ".poe-code", "harnesses", basename4, "snapshot.json");
|
|
86782
|
+
}
|
|
86783
|
+
async function prepareHarnessSnapshot(container, mdPath, snapshotPath, resumeRequested) {
|
|
86784
|
+
const snapshotExists = await pathExists10(container, snapshotPath);
|
|
86785
|
+
if (!resumeRequested) {
|
|
86786
|
+
return;
|
|
86787
|
+
}
|
|
86788
|
+
if (!snapshotExists) {
|
|
86789
|
+
return;
|
|
86790
|
+
}
|
|
86791
|
+
const [snapshotSource, scriptSource] = await Promise.all([
|
|
86792
|
+
container.fs.readFile(snapshotPath, "utf8"),
|
|
86793
|
+
container.fs.readFile(resolveAjsPath(mdPath), "utf8")
|
|
86794
|
+
]);
|
|
86795
|
+
try {
|
|
86796
|
+
restore(JSON.parse(snapshotSource), { source: scriptSource });
|
|
86797
|
+
} catch (error3) {
|
|
86798
|
+
if (error3 instanceof Error && error3.message.includes("source changed since snapshot was taken")) {
|
|
86799
|
+
throw new ValidationError(
|
|
86800
|
+
`Cannot resume harness from ${formatDisplayPath2(container, snapshotPath)}: source changed since the snapshot was taken. The .ajs script was edited; start a fresh run without --resume to discard the old snapshot.`
|
|
86801
|
+
);
|
|
86802
|
+
}
|
|
86803
|
+
throw error3;
|
|
86804
|
+
}
|
|
86805
|
+
}
|
|
86806
|
+
function createSnapshotProgressReader(container, snapshotPath) {
|
|
86807
|
+
let progress;
|
|
86808
|
+
let lastReadStartedAt = 0;
|
|
86809
|
+
return {
|
|
86810
|
+
current() {
|
|
86811
|
+
const now = Date.now();
|
|
86812
|
+
if (now - lastReadStartedAt > 750) {
|
|
86813
|
+
lastReadStartedAt = now;
|
|
86814
|
+
void readSnapshotProgress(container, snapshotPath).then((next) => {
|
|
86815
|
+
if (next !== void 0) {
|
|
86816
|
+
progress = next;
|
|
86817
|
+
}
|
|
86818
|
+
});
|
|
86819
|
+
}
|
|
86820
|
+
return progress;
|
|
86821
|
+
}
|
|
86822
|
+
};
|
|
86823
|
+
}
|
|
86824
|
+
async function readSnapshotProgress(container, snapshotPath) {
|
|
86825
|
+
try {
|
|
86826
|
+
const parsed = JSON.parse(await container.fs.readFile(snapshotPath, "utf8"));
|
|
86827
|
+
const step2 = readSnapshotStep(parsed);
|
|
86828
|
+
return step2 === void 0 ? void 0 : `step ${step2}`;
|
|
86829
|
+
} catch {
|
|
86830
|
+
return void 0;
|
|
86831
|
+
}
|
|
86832
|
+
}
|
|
86833
|
+
function readSnapshotStep(snapshot2) {
|
|
86834
|
+
if (typeof snapshot2 !== "object" || snapshot2 === null) {
|
|
86835
|
+
return void 0;
|
|
86836
|
+
}
|
|
86837
|
+
const record = snapshot2;
|
|
86838
|
+
for (const key2 of ["step", "currentStep", "currentAstNodeId"]) {
|
|
86839
|
+
const value = record[key2];
|
|
86840
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
86841
|
+
return value;
|
|
86842
|
+
}
|
|
86843
|
+
}
|
|
86844
|
+
return void 0;
|
|
86845
|
+
}
|
|
86846
|
+
function formatRunMessage(baseMessage, progress) {
|
|
86847
|
+
return progress === void 0 ? baseMessage : `${baseMessage} (${progress})`;
|
|
86848
|
+
}
|
|
86849
|
+
function resolveAjsPath(mdPath) {
|
|
86850
|
+
const parsed = path111.parse(mdPath);
|
|
86851
|
+
return path111.join(parsed.dir, `${parsed.name}.ajs`);
|
|
86852
|
+
}
|
|
86853
|
+
async function pathExists10(container, targetPath) {
|
|
86854
|
+
try {
|
|
86855
|
+
await container.fs.stat(targetPath);
|
|
86856
|
+
return true;
|
|
86857
|
+
} catch (error3) {
|
|
86858
|
+
if (hasErrorCode7(error3, "ENOENT")) {
|
|
86859
|
+
return false;
|
|
86860
|
+
}
|
|
86861
|
+
throw error3;
|
|
86862
|
+
}
|
|
86863
|
+
}
|
|
86864
|
+
function hasErrorCode7(error3, code) {
|
|
86865
|
+
return typeof error3 === "object" && error3 !== null && "code" in error3 && error3.code === code;
|
|
86866
|
+
}
|
|
86121
86867
|
async function executeHarnessNew(program, container, kind, basename4, options) {
|
|
86122
86868
|
const flags = resolveHarnessFlags(program, options.yes);
|
|
86123
86869
|
const resources = createExecutionResources(container, flags, "harness:new");
|
|
@@ -86263,17 +87009,6 @@ async function assertFilesDoNotExist(container, filePaths) {
|
|
|
86263
87009
|
}
|
|
86264
87010
|
}
|
|
86265
87011
|
}
|
|
86266
|
-
async function pathExists10(container, filePath) {
|
|
86267
|
-
try {
|
|
86268
|
-
await container.fs.stat(filePath);
|
|
86269
|
-
return true;
|
|
86270
|
-
} catch (error3) {
|
|
86271
|
-
if (error3 && typeof error3 === "object" && "code" in error3 && error3.code === "ENOENT") {
|
|
86272
|
-
return false;
|
|
86273
|
-
}
|
|
86274
|
-
throw error3;
|
|
86275
|
-
}
|
|
86276
|
-
}
|
|
86277
87012
|
function createHarnessModules(container, frontmatter, meta) {
|
|
86278
87013
|
const harnessMeta = {
|
|
86279
87014
|
kind: meta.kind,
|
|
@@ -86688,7 +87423,7 @@ var init_package2 = __esm({
|
|
|
86688
87423
|
"package.json"() {
|
|
86689
87424
|
package_default2 = {
|
|
86690
87425
|
name: "poe-code",
|
|
86691
|
-
version: "3.0.
|
|
87426
|
+
version: "3.0.222",
|
|
86692
87427
|
description: "CLI tool to configure Poe API for developer workflows.",
|
|
86693
87428
|
type: "module",
|
|
86694
87429
|
main: "./dist/index.js",
|
|
@@ -86763,7 +87498,8 @@ var init_package2 = __esm({
|
|
|
86763
87498
|
"codegen:plan-schemas": "tsx scripts/generate-plan-schemas.ts",
|
|
86764
87499
|
"codegen:harness-schemas": "tsx scripts/generate-harness-schemas.ts",
|
|
86765
87500
|
"smoke:toolcraft-standalone": "node scripts/verify-toolcraft-standalone.mjs",
|
|
86766
|
-
"sync-skills": "tsx scripts/sync-skills.ts"
|
|
87501
|
+
"sync-skills": "tsx scripts/sync-skills.ts",
|
|
87502
|
+
postinstall: "node scripts/postinstall-sync-skills.mjs"
|
|
86767
87503
|
},
|
|
86768
87504
|
bin: {
|
|
86769
87505
|
poe: "dist/bin.cjs",
|
|
@@ -86784,6 +87520,7 @@ var init_package2 = __esm({
|
|
|
86784
87520
|
"packages/config-mutations/dist",
|
|
86785
87521
|
"packages/design-system/dist",
|
|
86786
87522
|
"packages/memory/dist",
|
|
87523
|
+
"scripts/postinstall-sync-skills.mjs",
|
|
86787
87524
|
"packages/superintendent/dist",
|
|
86788
87525
|
"packages/tiny-stdio-mcp-server/dist"
|
|
86789
87526
|
],
|