dsh-agent-enhancer 0.3.20 → 0.3.21

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/lib/index.js CHANGED
@@ -2010,6 +2010,56 @@ var PlaywrightDriver = class {
2010
2010
  const ref = Number(raw);
2011
2011
  return Number.isFinite(ref) ? ref : null;
2012
2012
  }
2013
+ /**
2014
+ * Role, accessible name and a readable CSS path for a ref, so a repair can
2015
+ * record how the control was found this time. Best-effort: a stale ref or a
2016
+ * detached node yields an empty selector rather than failing the tool call.
2017
+ */
2018
+ async refInfo(ref) {
2019
+ const page = this.page;
2020
+ if (page === null || page.isClosed()) return null;
2021
+ const record2 = this.tabs.ref(this.tabIdFor(page), ref);
2022
+ if (record2 === void 0) return null;
2023
+ const selector = await page.evaluate(({ wanted, attr }) => {
2024
+ const element = document.querySelector(`[${attr}="${wanted}"]`);
2025
+ if (element === null) return "";
2026
+ const escaped = (value) => typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(value) : value.replace(/[^a-zA-Z0-9_-]/gu, "\\$&");
2027
+ const quote = (value) => `"${value.replace(/"/gu, '\\"')}"`;
2028
+ if (element.id !== "") return `#${escaped(element.id)}`;
2029
+ const parts = [];
2030
+ let cursor = element;
2031
+ for (let depth = 0; depth < 6 && cursor !== null; depth += 1) {
2032
+ const node = cursor;
2033
+ const tag = node.tagName.toLowerCase();
2034
+ const testId = node.getAttribute("data-testid");
2035
+ if (testId !== null && testId !== "") {
2036
+ parts.unshift(`${tag}[data-testid=${quote(testId)}]`);
2037
+ break;
2038
+ }
2039
+ const name2 = node.getAttribute("name");
2040
+ if (name2 !== null && name2 !== "" && /^(input|select|textarea|button|form)$/u.test(tag)) {
2041
+ parts.unshift(`${tag}[name=${quote(name2)}]`);
2042
+ break;
2043
+ }
2044
+ let part = tag;
2045
+ const parent = node.parentElement;
2046
+ if (parent !== null) {
2047
+ const sameTag = Array.from(parent.children).filter((child) => child.tagName === node.tagName);
2048
+ if (sameTag.length > 1) part += `:nth-of-type(${sameTag.indexOf(node) + 1})`;
2049
+ }
2050
+ parts.unshift(part);
2051
+ if (node === document.body) break;
2052
+ cursor = parent;
2053
+ }
2054
+ return parts.join(" > ").slice(0, 240);
2055
+ }, { wanted: String(ref), attr: PLAYWRIGHT_REF_ATTR }).catch(() => "");
2056
+ return {
2057
+ role: record2.role,
2058
+ name: record2.name,
2059
+ selector,
2060
+ href: record2.href
2061
+ };
2062
+ }
2013
2063
  async press(key) {
2014
2064
  const page = await this.requirePage();
2015
2065
  await page.keyboard.press(key);
@@ -2945,10 +2995,235 @@ async function replayDemoSteps(driver, steps, options = {}) {
2945
2995
  // src/host/browser-agent/demo-recipes.ts
2946
2996
  import { mkdirSync as mkdirSync2, readFileSync, writeFileSync } from "node:fs";
2947
2997
  import { dirname } from "node:path";
2998
+
2999
+ // src/host/browser-agent/demo-heal.ts
3000
+ var REPAIR_WINDOW_MS = 10 * 6e4;
3001
+ var MAX_OBSERVED = 30;
3002
+ var MAX_INSERTED = 8;
3003
+ function stepFromObservation(action) {
3004
+ switch (action.kind) {
3005
+ case "navigate":
3006
+ return action.url === void 0 || action.url === "" ? null : { kind: "navigate", at: action.at, url: action.url };
3007
+ case "click":
3008
+ return action.name === void 0 || action.name === "" ? null : {
3009
+ kind: "click",
3010
+ at: action.at,
3011
+ role: action.role ?? "button",
3012
+ name: action.name,
3013
+ selector: action.selector ?? ""
3014
+ };
3015
+ case "fill":
3016
+ return action.name === void 0 || action.name === "" || (action.value ?? "") === "" ? null : {
3017
+ kind: "fill",
3018
+ at: action.at,
3019
+ role: action.role ?? "textbox",
3020
+ name: action.name,
3021
+ selector: action.selector ?? "",
3022
+ field: action.field ?? action.name,
3023
+ value: action.value ?? "",
3024
+ masked: false
3025
+ };
3026
+ case "press":
3027
+ return action.key === void 0 || action.key === "" ? null : { kind: "press", at: action.at, key: action.key, selector: action.selector ?? "" };
3028
+ default: {
3029
+ const exhaustive = action.kind;
3030
+ return exhaustive;
3031
+ }
3032
+ }
3033
+ }
3034
+ function retarget(step, action) {
3035
+ if (step.kind !== action.kind) return null;
3036
+ const site = {
3037
+ ...step.tabId === void 0 ? {} : { tabId: step.tabId },
3038
+ ...step.tabUrl === void 0 ? {} : { tabUrl: step.tabUrl }
3039
+ };
3040
+ switch (step.kind) {
3041
+ case "navigate":
3042
+ return { ...step, url: action.url ?? step.url };
3043
+ case "click":
3044
+ return {
3045
+ kind: "click",
3046
+ at: step.at,
3047
+ role: action.role ?? step.role,
3048
+ name: action.name ?? step.name,
3049
+ selector: action.selector ?? step.selector,
3050
+ ...site
3051
+ };
3052
+ case "fill":
3053
+ return {
3054
+ kind: "fill",
3055
+ at: step.at,
3056
+ role: action.role ?? step.role,
3057
+ name: action.name ?? step.name,
3058
+ selector: action.selector ?? step.selector,
3059
+ field: action.field ?? step.field,
3060
+ value: step.value,
3061
+ masked: step.masked,
3062
+ ...step.checked === void 0 ? {} : { checked: step.checked },
3063
+ ...site
3064
+ };
3065
+ case "press":
3066
+ return {
3067
+ kind: "press",
3068
+ at: step.at,
3069
+ key: step.key,
3070
+ selector: action.selector ?? step.selector,
3071
+ ...site
3072
+ };
3073
+ default: {
3074
+ const exhaustive = step;
3075
+ return exhaustive;
3076
+ }
3077
+ }
3078
+ }
3079
+ function pickObserved(step, observed) {
3080
+ const compatible = [];
3081
+ observed.forEach((action, index) => {
3082
+ if (action.kind !== step.kind) return;
3083
+ if (step.kind !== "navigate" && (action.name ?? "") === "") return;
3084
+ if (step.kind === "fill" && (action.value ?? "") === "") return;
3085
+ compatible.push({ action, index });
3086
+ });
3087
+ if (compatible.length === 0) return -1;
3088
+ if (step.kind === "navigate") return compatible[0].index;
3089
+ const wanted = step.kind === "press" ? "" : normalizeControlName(step.name);
3090
+ if (wanted !== "") {
3091
+ const similar = compatible.find(({ action }) => {
3092
+ const candidate = normalizeControlName(action.name ?? "");
3093
+ if (candidate === "") return false;
3094
+ if (candidate.length < 2 || wanted.length < 2) return candidate === wanted;
3095
+ return candidate.includes(wanted) || wanted.includes(candidate);
3096
+ });
3097
+ if (similar !== void 0) return similar.index;
3098
+ }
3099
+ return compatible[0].index;
3100
+ }
3101
+ function buildHealProposal(input) {
3102
+ const step = input.steps[input.failedIndex];
3103
+ if (step === void 0) return null;
3104
+ if (step.kind === "fill" && step.masked) return null;
3105
+ const matchAt = pickObserved(step, input.observed);
3106
+ if (matchAt < 0) return null;
3107
+ const action = input.observed[matchAt];
3108
+ const replacement = retarget(step, action);
3109
+ if (replacement === null) return null;
3110
+ const unchanged = step.kind === "navigate" ? replacement.kind === "navigate" && step.url === replacement.url : step.kind === "press" ? replacement.kind === "press" && step.selector === replacement.selector : "name" in replacement && "name" in step && normalizeControlName(step.name) === normalizeControlName(replacement.name) && step.role === replacement.role;
3111
+ if (unchanged) return null;
3112
+ const inserted = [];
3113
+ for (const entry of input.observed.slice(0, matchAt)) {
3114
+ if (inserted.length >= MAX_INSERTED) break;
3115
+ const built = stepFromObservation(entry);
3116
+ if (built !== null) inserted.push(built);
3117
+ }
3118
+ const sanitizedInserted = sanitizeDemoSteps(inserted);
3119
+ if (sanitizedInserted.some((entry) => entry.kind === "fill" && entry.masked)) return null;
3120
+ const sanitizedReplacement = sanitizeDemoSteps([replacement])[0] ?? replacement;
3121
+ if (sanitizedReplacement.kind === "fill" && sanitizedReplacement.masked) return null;
3122
+ return {
3123
+ id: input.id ?? `h-${input.now.toString(36)}`,
3124
+ at: input.now,
3125
+ failedAt: input.failedIndex + 1,
3126
+ reason: input.reason.slice(0, 500),
3127
+ inserted: sanitizedInserted,
3128
+ replacement: sanitizedReplacement
3129
+ };
3130
+ }
3131
+ function sameIdentity(a, b) {
3132
+ if (a.kind !== b.kind) return false;
3133
+ if (a.kind === "navigate" && b.kind === "navigate") return a.url === b.url;
3134
+ if (a.kind === "press" && b.kind === "press") return a.key === b.key;
3135
+ if ("name" in a && "name" in b) {
3136
+ return normalizeControlName(a.name) === normalizeControlName(b.name) && a.role === b.role;
3137
+ }
3138
+ return false;
3139
+ }
3140
+ function applyHealProposal(steps, proposal) {
3141
+ const at = proposal.failedAt - 1;
3142
+ if (at < 0 || at >= steps.length) return [...steps];
3143
+ return [
3144
+ ...steps.slice(0, at),
3145
+ ...proposal.inserted,
3146
+ proposal.replacement,
3147
+ ...steps.slice(at + 1)
3148
+ ];
3149
+ }
3150
+ function describeHealProposal(proposal) {
3151
+ const lines = [
3152
+ `step ${proposal.failedAt} now uses ${describeDemoStep(proposal.replacement)}`
3153
+ ];
3154
+ if (proposal.inserted.length > 0) {
3155
+ lines.push(`+${proposal.inserted.length} step(s) before it: ${proposal.inserted.map(describeDemoStep).join("; ")}`);
3156
+ }
3157
+ return lines;
3158
+ }
3159
+ function createRepairHooks(input) {
3160
+ const clock = input.now ?? Date.now;
3161
+ return {
3162
+ active: () => input.tracker.active,
3163
+ begin: (target) => {
3164
+ input.tracker.begin(target);
3165
+ },
3166
+ observe: (action) => {
3167
+ input.tracker.observe(action);
3168
+ },
3169
+ commit: () => {
3170
+ const pending = input.tracker.take();
3171
+ if (pending === null || input.store === void 0) return null;
3172
+ const recipe = input.store.get(pending.target.recipeId);
3173
+ if (recipe === void 0) return null;
3174
+ const current = recipe.steps[pending.target.index];
3175
+ if (current === void 0 || !sameIdentity(current, pending.target.step)) return null;
3176
+ const proposal = buildHealProposal({
3177
+ steps: recipe.steps,
3178
+ failedIndex: pending.target.index,
3179
+ reason: pending.target.reason,
3180
+ observed: pending.observed,
3181
+ now: clock()
3182
+ });
3183
+ if (proposal === null) return null;
3184
+ if (!input.store.recordHeal({ id: recipe.id, proposal }).ok) return null;
3185
+ return {
3186
+ recipeId: recipe.id,
3187
+ recipeName: recipe.name,
3188
+ failedAt: proposal.failedAt,
3189
+ lines: describeHealProposal(proposal)
3190
+ };
3191
+ }
3192
+ };
3193
+ }
3194
+ var DemoRepairTracker = class {
3195
+ pending = null;
3196
+ begin(target) {
3197
+ this.pending = {
3198
+ target: { ...target, at: target.at ?? Date.now() },
3199
+ observed: []
3200
+ };
3201
+ }
3202
+ observe(action) {
3203
+ const pending = this.pending;
3204
+ if (pending === null) return;
3205
+ if (action.at - pending.target.at > REPAIR_WINDOW_MS) return;
3206
+ if (pending.target.tabId !== void 0 && action.tabId !== void 0 && pending.target.tabId !== action.tabId) return;
3207
+ if (pending.observed.length >= MAX_OBSERVED) return;
3208
+ pending.observed.push(action);
3209
+ }
3210
+ /** Hand back the target and what happened, and stop tracking. */
3211
+ take() {
3212
+ const pending = this.pending;
3213
+ this.pending = null;
3214
+ return pending === null ? null : { target: pending.target, observed: [...pending.observed] };
3215
+ }
3216
+ get active() {
3217
+ return this.pending !== null;
3218
+ }
3219
+ };
3220
+
3221
+ // src/host/browser-agent/demo-recipes.ts
2948
3222
  var MAX_RECIPES = 20;
2949
3223
  var MAX_RECIPE_NAME = 60;
2950
3224
  var MAX_RECIPE_STEPS = 200;
2951
- var FILE_VERSION = 1;
3225
+ var MAX_HISTORY = 5;
3226
+ var FILE_VERSION = 2;
2952
3227
  function metaOf(recipe) {
2953
3228
  return {
2954
3229
  id: recipe.id,
@@ -2956,9 +3231,18 @@ function metaOf(recipe) {
2956
3231
  createdAt: recipe.createdAt,
2957
3232
  updatedAt: recipe.updatedAt,
2958
3233
  steps: recipe.steps.length,
2959
- variables: recipe.variables
3234
+ variables: recipe.variables,
3235
+ rev: recipe.rev,
3236
+ history: recipe.history.length,
3237
+ ...recipe.pendingHeal === void 0 ? {} : { pendingHeal: recipe.pendingHeal }
2960
3238
  };
2961
3239
  }
3240
+ function nextVersion(recipe, source, now) {
3241
+ return [
3242
+ ...recipe.history,
3243
+ { rev: recipe.rev, at: now, source, steps: recipe.steps, variables: recipe.variables }
3244
+ ].slice(-MAX_HISTORY);
3245
+ }
2962
3246
  var VAR_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
2963
3247
  var VAR_TOKEN = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
2964
3248
  function applyRecipeVars(steps, values) {
@@ -2986,6 +3270,41 @@ function sanitizeVariables(raw) {
2986
3270
  return typeof name2 === "string" && VAR_NAME.test(name2);
2987
3271
  }).map((variable) => ({ name: variable.name, default: String(variable.default ?? "").slice(0, 500) }));
2988
3272
  }
3273
+ function sanitizeHistory(raw) {
3274
+ if (!Array.isArray(raw)) return [];
3275
+ const versions = [];
3276
+ for (const value of raw) {
3277
+ if (value === null || typeof value !== "object") continue;
3278
+ const entry = value;
3279
+ const steps = sanitizeRecipeSteps(entry.steps);
3280
+ if (steps.length === 0) continue;
3281
+ versions.push({
3282
+ rev: Number.isFinite(entry.rev) && (entry.rev ?? 0) > 0 ? Number(entry.rev) : 1,
3283
+ at: Number.isFinite(entry.at) ? Number(entry.at) : 0,
3284
+ source: entry.source === "parameterize" || entry.source === "heal" || entry.source === "rollback" ? entry.source : "save",
3285
+ steps,
3286
+ variables: sanitizeVariables(entry.variables)
3287
+ });
3288
+ }
3289
+ return versions.slice(-MAX_HISTORY);
3290
+ }
3291
+ function sanitizeProposal(raw) {
3292
+ if (raw === null || typeof raw !== "object") return void 0;
3293
+ const entry = raw;
3294
+ if (typeof entry.id !== "string" || entry.id === "") return void 0;
3295
+ const failedAt = Number(entry.failedAt);
3296
+ if (!Number.isInteger(failedAt) || failedAt < 1) return void 0;
3297
+ const replacement = sanitizeRecipeSteps(entry.replacement === void 0 ? [] : [entry.replacement])[0];
3298
+ if (replacement === void 0) return void 0;
3299
+ return {
3300
+ id: entry.id,
3301
+ at: Number.isFinite(entry.at) ? Number(entry.at) : 0,
3302
+ failedAt,
3303
+ reason: typeof entry.reason === "string" ? entry.reason.slice(0, 500) : "",
3304
+ inserted: sanitizeRecipeSteps(entry.inserted ?? []),
3305
+ replacement
3306
+ };
3307
+ }
2989
3308
  function isStep(value) {
2990
3309
  if (value === null || typeof value !== "object") return false;
2991
3310
  const kind = value.kind;
@@ -3023,7 +3342,15 @@ var DemoRecipeStore = class {
3023
3342
  const existing = recipes.find((recipe) => recipe.name.toLowerCase() === name2.toLowerCase());
3024
3343
  let saved;
3025
3344
  if (existing !== void 0) {
3026
- saved = { ...existing, name: name2, steps, updatedAt: now };
3345
+ const { pendingHeal: _answered, ...rest } = existing;
3346
+ saved = {
3347
+ ...rest,
3348
+ name: name2,
3349
+ steps,
3350
+ updatedAt: now,
3351
+ rev: existing.rev + 1,
3352
+ history: nextVersion(existing, "save", now)
3353
+ };
3027
3354
  } else {
3028
3355
  if (recipes.length >= MAX_RECIPES) {
3029
3356
  return { ok: false, error: `\u6700\u591A\u4FDD\u5B58 ${MAX_RECIPES} \u4E2A\u6D41\u7A0B\uFF0C\u5148\u5220\u6389\u4E00\u4E2A` };
@@ -3034,7 +3361,9 @@ var DemoRecipeStore = class {
3034
3361
  createdAt: now,
3035
3362
  updatedAt: now,
3036
3363
  steps,
3037
- variables: []
3364
+ variables: [],
3365
+ rev: 1,
3366
+ history: []
3038
3367
  };
3039
3368
  }
3040
3369
  const next = existing === void 0 ? [...recipes, saved] : recipes.map((recipe) => recipe.id === saved.id ? saved : recipe);
@@ -3089,29 +3418,107 @@ var DemoRecipeStore = class {
3089
3418
  (entry, index) => index === input.index && entry.kind === "fill" ? { ...entry, value: token } : entry
3090
3419
  );
3091
3420
  const variables = [...current.variables, { name: name2, default: step.value.slice(0, 500) }];
3092
- const next = { ...current, steps, variables, updatedAt: input.now ?? Date.now() };
3421
+ const now = input.now ?? Date.now();
3422
+ const { pendingHeal: _stale, ...rest } = current;
3423
+ const next = {
3424
+ ...rest,
3425
+ steps,
3426
+ variables,
3427
+ updatedAt: now,
3428
+ rev: current.rev + 1,
3429
+ history: nextVersion(current, "parameterize", now)
3430
+ };
3431
+ this.write(recipes.map((recipe) => recipe.id === current.id ? next : recipe));
3432
+ return { ok: true, recipe: metaOf(next) };
3433
+ }
3434
+ /** Store a repair for the user to accept; it never touches the steps by itself. */
3435
+ recordHeal(input) {
3436
+ const recipes = this.read();
3437
+ const current = recipes.find((recipe) => recipe.id === input.id);
3438
+ if (current === void 0) return { ok: false, error: "\u6D41\u7A0B\u4E0D\u5B58\u5728" };
3439
+ const next = { ...current, pendingHeal: input.proposal };
3440
+ this.write(recipes.map((recipe) => recipe.id === current.id ? next : recipe));
3441
+ return { ok: true, recipe: metaOf(next) };
3442
+ }
3443
+ /**
3444
+ * Accept or drop a pending repair. Accepting is the only path that rewrites
3445
+ * the flow, and it keeps the previous content one click away.
3446
+ */
3447
+ resolveHeal(input) {
3448
+ const now = input.now ?? Date.now();
3449
+ const recipes = this.read();
3450
+ const current = recipes.find((recipe) => recipe.id === input.id);
3451
+ if (current === void 0) return { ok: false, error: "\u6D41\u7A0B\u4E0D\u5B58\u5728" };
3452
+ const proposal = current.pendingHeal;
3453
+ if (proposal === void 0) return { ok: false, error: "\u8FD9\u4E2A\u6D41\u7A0B\u6CA1\u6709\u5F85\u786E\u8BA4\u7684\u4FEE\u590D" };
3454
+ const { pendingHeal: _resolved, ...rest } = current;
3455
+ if (!input.accept) {
3456
+ this.write(recipes.map((recipe) => recipe.id === current.id ? rest : recipe));
3457
+ return { ok: true, recipe: metaOf(rest) };
3458
+ }
3459
+ const steps = sanitizeRecipeSteps(applyHealProposal(current.steps, proposal));
3460
+ const next = {
3461
+ ...rest,
3462
+ steps,
3463
+ updatedAt: now,
3464
+ rev: current.rev + 1,
3465
+ history: nextVersion(current, "heal", now)
3466
+ };
3467
+ this.write(recipes.map((recipe) => recipe.id === current.id ? next : recipe));
3468
+ return { ok: true, recipe: metaOf(next) };
3469
+ }
3470
+ /** Restore the newest past version; the safety net for a wrong repair. */
3471
+ rollback(input) {
3472
+ const now = input.now ?? Date.now();
3473
+ const recipes = this.read();
3474
+ const current = recipes.find((recipe) => recipe.id === input.id);
3475
+ if (current === void 0) return { ok: false, error: "\u6D41\u7A0B\u4E0D\u5B58\u5728" };
3476
+ const previous = current.history[current.history.length - 1];
3477
+ if (previous === void 0) return { ok: false, error: "\u6CA1\u6709\u53EF\u64A4\u9500\u7684\u7248\u672C" };
3478
+ const { pendingHeal: _stale, ...rest } = current;
3479
+ const next = {
3480
+ ...rest,
3481
+ steps: previous.steps,
3482
+ variables: previous.variables,
3483
+ updatedAt: now,
3484
+ rev: current.rev + 1,
3485
+ history: current.history.slice(0, -1)
3486
+ };
3093
3487
  this.write(recipes.map((recipe) => recipe.id === current.id ? next : recipe));
3094
3488
  return { ok: true, recipe: metaOf(next) };
3095
3489
  }
3490
+ revisionTick = 0;
3491
+ /** Bumped on every write; the sidebar polls this instead of the whole list. */
3492
+ revision() {
3493
+ return this.revisionTick;
3494
+ }
3096
3495
  read() {
3097
3496
  if (this.filePath === null) return this.memory;
3098
3497
  try {
3099
3498
  const parsed = JSON.parse(readFileSync(this.filePath, "utf8"));
3100
- if (parsed.version !== FILE_VERSION || !Array.isArray(parsed.recipes)) return [];
3499
+ if (parsed.version !== 1 && parsed.version !== FILE_VERSION || !Array.isArray(parsed.recipes)) return [];
3101
3500
  return parsed.recipes.filter((recipe) => {
3102
3501
  if (recipe === null || typeof recipe !== "object") return false;
3103
3502
  if (typeof recipe.id !== "string" || typeof recipe.name !== "string") return false;
3104
3503
  return typeof recipe.createdAt === "number" && typeof recipe.updatedAt === "number";
3105
- }).map((recipe) => ({
3106
- ...recipe,
3107
- steps: sanitizeRecipeSteps(recipe.steps),
3108
- variables: sanitizeVariables(recipe.variables)
3109
- })).filter((recipe) => recipe.steps.length > 0).slice(0, MAX_RECIPES);
3504
+ }).map((recipe) => {
3505
+ const { pendingHeal: rawProposal, ...rest } = recipe;
3506
+ const proposal = sanitizeProposal(rawProposal);
3507
+ return {
3508
+ ...rest,
3509
+ steps: sanitizeRecipeSteps(recipe.steps),
3510
+ variables: sanitizeVariables(recipe.variables),
3511
+ rev: Number.isFinite(recipe.rev) && recipe.rev > 0 ? recipe.rev : 1,
3512
+ history: sanitizeHistory(recipe.history),
3513
+ ...proposal === void 0 ? {} : { pendingHeal: proposal }
3514
+ };
3515
+ }).filter((recipe) => recipe.steps.length > 0).slice(0, MAX_RECIPES);
3110
3516
  } catch {
3111
3517
  return [];
3112
3518
  }
3113
3519
  }
3114
3520
  write(recipes) {
3521
+ this.revisionTick += 1;
3115
3522
  if (this.filePath === null) {
3116
3523
  this.memory = [...recipes];
3117
3524
  return;
@@ -3238,6 +3645,26 @@ function driverOf(options) {
3238
3645
  const value = options.driver;
3239
3646
  return typeof value === "function" ? value() : value;
3240
3647
  }
3648
+ async function captureRefEvidence(options, ref) {
3649
+ if (options.repair?.active() !== true) return null;
3650
+ const driver = driverOf(options);
3651
+ if (typeof driver.refInfo !== "function") return null;
3652
+ const info = await driver.refInfo(ref).catch(() => null);
3653
+ if (info === null) return null;
3654
+ return { role: info.role, name: info.name, selector: info.selector };
3655
+ }
3656
+ function recordRepair(options, evidence, kind, extra = {}) {
3657
+ if (options.repair?.active() !== true) return;
3658
+ options.repair.observe({
3659
+ kind,
3660
+ at: Date.now(),
3661
+ ...evidence === null ? {} : evidence,
3662
+ ...evidence === null || kind !== "fill" ? {} : { field: evidence.name },
3663
+ ...extra.value === void 0 ? {} : { value: extra.value },
3664
+ ...extra.url === void 0 ? {} : { url: extra.url },
3665
+ ...extra.tabId === void 0 ? {} : { tabId: extra.tabId }
3666
+ });
3667
+ }
3241
3668
  function pickEnum(value, allowed, field) {
3242
3669
  if (value === void 0 || value === null || value === "") return void 0;
3243
3670
  const text3 = String(value).trim().toLowerCase();
@@ -3661,6 +4088,15 @@ function registerBrowserTools(ctx, options) {
3661
4088
  outcome: "ok"
3662
4089
  });
3663
4090
  options.onMutation?.({ sessionId, tool: "browser_navigate", url: result.url });
4091
+ if (options.repair?.active() === true) {
4092
+ const tabId = options.sessions.tabOf(sessionId);
4093
+ options.repair.observe({
4094
+ kind: "navigate",
4095
+ at: Date.now(),
4096
+ url: result.url,
4097
+ ...tabId === void 0 ? {} : { tabId }
4098
+ });
4099
+ }
3664
4100
  return [
3665
4101
  newTab ? "opened_new_tab" : "navigated",
3666
4102
  `url: ${result.url}`,
@@ -3706,6 +4142,7 @@ function registerBrowserTools(ctx, options) {
3706
4142
  url = void 0;
3707
4143
  }
3708
4144
  requireFreshRef(sessionId, ref, "browser_click");
4145
+ const repairEvidence = await captureRefEvidence(options, ref);
3709
4146
  if (options.sessions.isDeadClickRef(sessionId, ref)) {
3710
4147
  throw new Error(
3711
4148
  `click_blocked: ref ${ref} already failed with no navigation. Do NOT browser_click it again. browser_navigate to a content URL, or browser_snapshot and use a ref that lists href=.`
@@ -3744,6 +4181,10 @@ function registerBrowserTools(ctx, options) {
3744
4181
  warning = navigated ? "Click was a no-op; host auto-navigated to a name-matched document link." : "Host tried name-matched auto-navigate after dead click but pathname still unchanged.";
3745
4182
  }
3746
4183
  }
4184
+ recordRepair(options, repairEvidence, "click", {
4185
+ url: result.url,
4186
+ tabId: options.sessions.tabOf(sessionId)
4187
+ });
3747
4188
  options.sessions.clearLastRefs(sessionId);
3748
4189
  if (!navigated) {
3749
4190
  options.sessions.markDeadClickRef(sessionId, ref);
@@ -3827,6 +4268,7 @@ function registerBrowserTools(ctx, options) {
3827
4268
  url = void 0;
3828
4269
  }
3829
4270
  requireFreshRef(sessionId, ref, "browser_type");
4271
+ const repairEvidence = await captureRefEvidence(options, ref);
3830
4272
  await requireMutation(exec, "browser_type", `Type into ref ${ref}: ${maskTypeSummary(text3)}`, url, ref);
3831
4273
  try {
3832
4274
  const result = await runBridge(() => driverOf(options).type(ref, text3));
@@ -3840,6 +4282,11 @@ function registerBrowserTools(ctx, options) {
3840
4282
  outcome: "ok"
3841
4283
  });
3842
4284
  options.onMutation?.({ sessionId, tool: "browser_type", url: result.url });
4285
+ recordRepair(options, repairEvidence, "fill", {
4286
+ value: text3,
4287
+ url: result.url,
4288
+ tabId: options.sessions.tabOf(sessionId)
4289
+ });
3843
4290
  return `typed into ref ${ref}
3844
4291
  url: ${result.url}
3845
4292
  title: ${result.title}
@@ -4333,17 +4780,25 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
4333
4780
  )));
4334
4781
  disposers.push(ctx.tools.register(textTool(
4335
4782
  "browser_demo_recipes",
4336
- 'List or run a flow the user saved from a demonstration (right sidebar \u2192 \u6F14\u793A\u5F55\u5236 \u2192 \u4FDD\u5B58\u4E3A\u6D41\u7A0B). Use it when the user names a saved flow ("\u8DD1\u4E00\u4E0B\u300C\u5468\u62A5\u5BFC\u51FA\u300D\u6D41\u7A0B") or asks which flows exist. Running replays the recorded steps in the dedicated browser; it asks for approval once and stops at a masked secret or a control that is gone, exactly like browser_demonstrate replay.',
4783
+ 'List, run, or repair a flow the user saved from a demonstration (right sidebar \u2192 \u6F14\u793A\u5F55\u5236 \u2192 \u4FDD\u5B58\u4E3A\u6D41\u7A0B). Use it when the user names a saved flow ("\u8DD1\u4E00\u4E0B\u300C\u5468\u62A5\u5BFC\u51FA\u300D\u6D41\u7A0B") or asks which flows exist. Running replays the recorded steps in the dedicated browser; it asks for approval once and stops at a masked secret or a control that is gone, exactly like browser_demonstrate replay. When it stops because a control changed, finish the remaining steps yourself, then call action=heal so the user can keep the fix.',
4337
4784
  {
4338
4785
  action: {
4339
4786
  type: "string",
4340
4787
  required: true,
4341
- description: '"list" to show saved flows, "run" to replay one.'
4788
+ description: '"list" to show saved flows, "run" to replay one, "heal" to offer the fix you just worked out.'
4342
4789
  },
4343
4790
  name: {
4344
4791
  type: "string",
4345
4792
  description: "Flow name for action=run. Case-insensitive; a unique part of the name is enough."
4346
4793
  },
4794
+ id: {
4795
+ type: "string",
4796
+ description: "Flow id for action=heal; omit to use the flow that just stopped."
4797
+ },
4798
+ accept: {
4799
+ type: "boolean",
4800
+ description: "action=heal: apply the repair to the saved flow now (the user asked to remember it). Default false: offer it in the sidebar."
4801
+ },
4347
4802
  vars: {
4348
4803
  type: "object",
4349
4804
  additionalProperties: true,
@@ -4358,16 +4813,62 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
4358
4813
  const action = String(args.action ?? "").trim().toLowerCase();
4359
4814
  const rows = store.list();
4360
4815
  if (action === "list") {
4361
- if (rows.length === 0) {
4816
+ options.repair?.commit();
4817
+ const afterCommit = store.list();
4818
+ if (afterCommit.length === 0) {
4362
4819
  return "saved flows: 0\nAction: none yet \u2014 the user can record a demonstration and save it in the sidebar, then retry.";
4363
4820
  }
4364
4821
  return [
4365
- `saved flows: ${rows.length}`,
4366
- ...rows.map((row) => `- ${row.name} (${row.steps} step(s)${row.variables.length === 0 ? "" : `; vars: ${row.variables.map((variable) => variable.name).join(", ")}`})`),
4822
+ `saved flows: ${afterCommit.length}`,
4823
+ ...afterCommit.map((row) => {
4824
+ const vars = row.variables.length === 0 ? "" : `; vars: ${row.variables.map((variable) => variable.name).join(", ")}`;
4825
+ const heal = row.pendingHeal === void 0 ? "" : `; repair waiting: step ${row.pendingHeal.failedAt}`;
4826
+ return `- ${row.name} (${row.steps} step(s)${vars}${heal})`;
4827
+ }),
4367
4828
  'Action: run one with browser_demo_recipes { action: "run", name: "<name>" }.'
4368
4829
  ].join("\n");
4369
4830
  }
4370
- if (action !== "run") throw new Error('action must be "list" or "run"');
4831
+ if (action === "heal") {
4832
+ const committed = options.repair?.commit() ?? null;
4833
+ const id = String(args.id ?? committed?.recipeId ?? "").trim();
4834
+ if (id === "") {
4835
+ return "nothing to remember: no saved flow stopped recently, so there is no repair to store.";
4836
+ }
4837
+ if (args.accept !== true) {
4838
+ const row = store.list().find((candidate) => candidate.id === id);
4839
+ const proposal = row?.pendingHeal;
4840
+ if (committed === null && proposal === void 0) {
4841
+ return `nothing to remember: no repair for "${row?.name ?? id}" \u2014 the flow either ran clean or the difference was not a moved control.`;
4842
+ }
4843
+ options.sessions.record({
4844
+ sessionId: sessionIdOf(exec),
4845
+ tool: "browser_demo_recipe",
4846
+ summary: `Offered a repair for saved flow "${row?.name ?? id}"`,
4847
+ outcome: "ok"
4848
+ });
4849
+ return [
4850
+ `saved flow: ${row?.name ?? id} \u2014 repair offered`,
4851
+ ...committed === null ? [] : committed.lines.map((line) => `- ${line}`),
4852
+ "Action: tell the user you worked around a changed control and that they can accept the fix in the sidebar (\u6F14\u793A\u5F55\u5236 \u2192 this flow). Do not claim the flow itself was updated."
4853
+ ].join("\n");
4854
+ }
4855
+ const resolved = store.resolveHeal({ id, accept: true });
4856
+ if (!resolved.ok) {
4857
+ return `nothing to remember: ${resolved.error}`;
4858
+ }
4859
+ options.sessions.record({
4860
+ sessionId: sessionIdOf(exec),
4861
+ tool: "browser_demo_recipe",
4862
+ summary: `Applied a repair for saved flow "${resolved.recipe.name}"`,
4863
+ outcome: "ok"
4864
+ });
4865
+ return [
4866
+ `saved flow: ${resolved.recipe.name} \u2014 repair applied`,
4867
+ ...committed === null ? [] : committed.lines.map((line) => `- ${line}`),
4868
+ "Action: the flow now uses the control you found. Tell the user it should work next time, and that the previous version can be restored in the sidebar."
4869
+ ].join("\n");
4870
+ }
4871
+ if (action !== "run") throw new Error('action must be "list", "run" or "heal"');
4371
4872
  const wanted = String(args.name ?? "").trim();
4372
4873
  if (wanted === "") throw new Error("name is required for action=run");
4373
4874
  const exact = rows.find((row) => row.name.toLowerCase() === wanted.toLowerCase());
@@ -4378,6 +4879,7 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
4378
4879
  }
4379
4880
  const recipe = store.get(meta.id);
4380
4881
  if (recipe === void 0) throw new Error("The saved flow disappeared; list again.");
4882
+ options.repair?.commit();
4381
4883
  const provided = args.vars !== null && typeof args.vars === "object" ? Object.fromEntries(Object.entries(args.vars).filter(([, value]) => typeof value === "string").map(([key, value]) => [key, String(value)])) : {};
4382
4884
  const defaults = {};
4383
4885
  for (const variable of recipe.variables) defaults[variable.name] = variable.default;
@@ -4399,6 +4901,22 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
4399
4901
  );
4400
4902
  const outcome = await replayDemoSteps(driverOf(options), replaySteps);
4401
4903
  const ranAll = outcome.status === "done";
4904
+ if (!ranAll) {
4905
+ const failedStep = recipe.steps[outcome.performed];
4906
+ const isSecret = /masked|secret field/i.test(outcome.reason) || failedStep !== void 0 && failedStep.kind === "fill" && failedStep.masked;
4907
+ if (!isSecret && failedStep !== void 0 && options.repair !== void 0) {
4908
+ const tabId = options.sessions.tabOf(sessionId);
4909
+ options.repair.begin({
4910
+ recipeId: recipe.id,
4911
+ recipeName: recipe.name,
4912
+ index: outcome.performed,
4913
+ step: failedStep,
4914
+ reason: outcome.reason,
4915
+ ...tabId === void 0 ? {} : { tabId },
4916
+ ...outcome.url === void 0 ? {} : { tabUrl: outcome.url }
4917
+ });
4918
+ }
4919
+ }
4402
4920
  options.sessions.record({
4403
4921
  sessionId,
4404
4922
  tool: "browser_demo_recipes",
@@ -4422,7 +4940,7 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
4422
4940
  ...outcome.lines,
4423
4941
  `stopped at step ${outcome.performed + 1}: ${outcome.reason}`,
4424
4942
  ...pending,
4425
- "Action: the replay stopped; the page is whatever the last ok step left behind. Continue with browser_snapshot + click/type, or browser_ask_user for a secret. Do not claim the flow finished."
4943
+ 'Action: the replay stopped; the page is whatever the last ok step left behind. Continue with browser_snapshot + click/type, or browser_ask_user for a secret. Do not claim the flow finished. If a control had moved and you worked around it, finish the job and then call browser_demo_recipes { action: "heal" } so the user can keep that fix.'
4426
4944
  ].join("\n");
4427
4945
  }
4428
4946
  )));
@@ -4514,6 +5032,11 @@ function installBrowserAgent(ctx, options) {
4514
5032
  const tabScope = new TabScopeStore();
4515
5033
  const recipes = options.recipes;
4516
5034
  let lastDemoSteps = [];
5035
+ const repairTracker = new DemoRepairTracker();
5036
+ const repairHooks = createRepairHooks({
5037
+ tracker: repairTracker,
5038
+ ...recipes === void 0 ? {} : { store: recipes }
5039
+ });
4517
5040
  let availabilityCache = null;
4518
5041
  const browserAvailability = () => {
4519
5042
  if (availabilityCache !== null) return availabilityCache;
@@ -4637,6 +5160,7 @@ function installBrowserAgent(ctx, options) {
4637
5160
  lastDemoSteps = steps;
4638
5161
  },
4639
5162
  ...recipes === void 0 ? {} : { recipes },
5163
+ repair: repairHooks,
4640
5164
  diagnosis: diagnoseNow,
4641
5165
  // Gate on settings only — `active` flips false during driver align and
4642
5166
  // must not make browser_* look "disabled" mid-turn.
@@ -4852,9 +5376,13 @@ function installBrowserAgent(ctx, options) {
4852
5376
  lastDemonstrationSteps() {
4853
5377
  return lastDemoSteps.length;
4854
5378
  },
5379
+ recipesRevision() {
5380
+ return recipes?.revision() ?? 0;
5381
+ },
4855
5382
  async demoRecipes(input) {
4856
5383
  if (!options.enabled()) return { ok: false, error: "Browser agent disabled" };
4857
5384
  if (recipes === void 0) return { ok: false, error: "recipe store unavailable" };
5385
+ repairHooks.commit();
4858
5386
  if (input.action === "list") {
4859
5387
  return { ok: true, recipes: recipes.list() };
4860
5388
  }
@@ -4910,8 +5438,36 @@ function installBrowserAgent(ctx, options) {
4910
5438
  });
4911
5439
  return { ok: true, recipe: renamed.recipe, recipes: recipes.list() };
4912
5440
  }
5441
+ if (input.action === "heal") {
5442
+ const resolved = recipes.resolveHeal({ id: input.id ?? "", accept: input.accept === true });
5443
+ if (!resolved.ok) return { ok: false, error: resolved.error, recipes: recipes.list() };
5444
+ sessions.record({
5445
+ sessionId: "sidebar",
5446
+ tool: "browser_demo_recipe",
5447
+ summary: `${input.accept === true ? "Applied" : "Dismissed"} a repair for "${resolved.recipe.name}"`,
5448
+ outcome: "ok"
5449
+ });
5450
+ return {
5451
+ ok: true,
5452
+ healed: input.accept === true,
5453
+ recipe: resolved.recipe,
5454
+ recipes: recipes.list()
5455
+ };
5456
+ }
5457
+ if (input.action === "rollback") {
5458
+ const restored = recipes.rollback({ id: input.id ?? "" });
5459
+ if (!restored.ok) return { ok: false, error: restored.error, recipes: recipes.list() };
5460
+ sessions.record({
5461
+ sessionId: "sidebar",
5462
+ tool: "browser_demo_recipe",
5463
+ summary: `Restored the previous version of "${restored.recipe.name}"`,
5464
+ outcome: "ok"
5465
+ });
5466
+ return { ok: true, recipe: restored.recipe, recipes: recipes.list() };
5467
+ }
4913
5468
  const recipe = recipes.get(input.id ?? "");
4914
5469
  if (recipe === void 0) return { ok: false, error: "\u6D41\u7A0B\u4E0D\u5B58\u5728", recipes: recipes.list() };
5470
+ repairHooks.commit();
4915
5471
  const defaults = {};
4916
5472
  for (const variable of recipe.variables) defaults[variable.name] = variable.default;
4917
5473
  const values = { ...defaults, ...input.vars ?? {} };
@@ -4937,6 +5493,19 @@ function installBrowserAgent(ctx, options) {
4937
5493
  pending: [...steps]
4938
5494
  }));
4939
5495
  const ranAll = outcome.status === "done";
5496
+ if (!ranAll) {
5497
+ const failedStep = recipe.steps[outcome.performed];
5498
+ const isSecret = /masked|secret field/i.test(outcome.reason) || failedStep !== void 0 && failedStep.kind === "fill" && failedStep.masked;
5499
+ if (!isSecret && failedStep !== void 0) {
5500
+ repairTracker.begin({
5501
+ recipeId: recipe.id,
5502
+ recipeName: recipe.name,
5503
+ index: outcome.performed,
5504
+ step: failedStep,
5505
+ reason: outcome.reason
5506
+ });
5507
+ }
5508
+ }
4940
5509
  sessions.record({
4941
5510
  sessionId: "sidebar",
4942
5511
  tool: "browser_demo_recipe",
@@ -17119,7 +17688,9 @@ var browserAgentSnapshotSchema = z4.strictObject({
17119
17688
  enabled: z4.boolean(),
17120
17689
  recording: z4.boolean(),
17121
17690
  /** Steps from the last finished recording, whoever stopped it. */
17122
- lastSteps: z4.number().int()
17691
+ lastSteps: z4.number().int(),
17692
+ /** Bumped when a saved flow changes; the panel re-reads the list on change. */
17693
+ recipesVersion: z4.number().int()
17123
17694
  }),
17124
17695
  tabConflict: browserAgentTabConflictSchema.nullable(),
17125
17696
  needsHuman: browserAgentNeedsHumanSchema.nullable(),
@@ -17173,13 +17744,30 @@ var demoRecipeVariableSchema = z4.strictObject({
17173
17744
  name: z4.string().min(1),
17174
17745
  default: z4.string()
17175
17746
  });
17747
+ var demoRecipeHealSchema = z4.strictObject({
17748
+ id: z4.string().min(1),
17749
+ /** 1-based step the replay stopped at. */
17750
+ failedAt: z4.number().int().min(1),
17751
+ kind: z4.enum(["navigate", "click", "fill", "press"]),
17752
+ /** The control's name (URL for navigate, key for press). */
17753
+ label: z4.string(),
17754
+ /** Steps the agent had to add before it (a cookie banner…). */
17755
+ inserted: z4.number().int().min(0),
17756
+ reason: z4.string()
17757
+ });
17176
17758
  var demoRecipeMetaSchema = z4.strictObject({
17177
17759
  id: z4.string().min(1),
17178
17760
  name: z4.string().min(1),
17179
17761
  createdAt: z4.number(),
17180
17762
  updatedAt: z4.number(),
17181
17763
  steps: z4.number().int(),
17182
- variables: z4.array(demoRecipeVariableSchema)
17764
+ variables: z4.array(demoRecipeVariableSchema),
17765
+ /** Content revision; grows with every accepted change. */
17766
+ rev: z4.number().int(),
17767
+ /** How many previous versions can be restored. */
17768
+ history: z4.number().int(),
17769
+ /** A repair worked out by the agent, waiting for the user. */
17770
+ pendingHeal: demoRecipeHealSchema.optional()
17183
17771
  });
17184
17772
  var demoRecipeStepSchema = z4.strictObject({
17185
17773
  index: z4.number().int(),
@@ -17199,7 +17787,9 @@ var browserAgentDemoRecipesRequestSchema = z4.discriminatedUnion("action", [
17199
17787
  z4.strictObject({ action: z4.literal("delete"), id: z4.string().min(1) }),
17200
17788
  z4.strictObject({ action: z4.literal("steps"), id: z4.string().min(1) }),
17201
17789
  z4.strictObject({ action: z4.literal("rename"), id: z4.string().min(1), name: z4.string() }),
17202
- z4.strictObject({ action: z4.literal("parameterize"), id: z4.string().min(1), index: z4.number().int().min(0), name: z4.string() })
17790
+ z4.strictObject({ action: z4.literal("parameterize"), id: z4.string().min(1), index: z4.number().int().min(0), name: z4.string() }),
17791
+ z4.strictObject({ action: z4.literal("heal"), id: z4.string().min(1), accept: z4.boolean() }),
17792
+ z4.strictObject({ action: z4.literal("rollback"), id: z4.string().min(1) })
17203
17793
  ]);
17204
17794
  var browserAgentDemoRecipesRequestCodec = codec(
17205
17795
  "dsh-agent-enhancer#BrowserAgentDemoRecipesRequest",
@@ -17213,6 +17803,8 @@ var browserAgentDemoRecipesResultSchema = z4.strictObject({
17213
17803
  lines: z4.array(z4.string()).optional(),
17214
17804
  /** Step metadata for action=steps (index + what the row can do). */
17215
17805
  steps: z4.array(demoRecipeStepSchema).optional(),
17806
+ /** True when a repair was applied (action=heal with accept). */
17807
+ healed: z4.boolean().optional(),
17216
17808
  /** 1-based step where a replay stopped. */
17217
17809
  stoppedAt: z4.number().int().optional(),
17218
17810
  reason: z4.string().optional(),
@@ -18973,7 +19565,8 @@ var AgentEnhancerService = class extends TypertRemoteService {
18973
19565
  demo: {
18974
19566
  enabled: settings.demonstrate,
18975
19567
  recording: this.browserAgent?.demoActive() === true,
18976
- lastSteps: this.browserAgent?.lastDemonstrationSteps() ?? 0
19568
+ lastSteps: this.browserAgent?.lastDemonstrationSteps() ?? 0,
19569
+ recipesVersion: this.browserAgent?.recipesRevision() ?? 0
18977
19570
  },
18978
19571
  diagnosis: diag ?? {
18979
19572
  code: settings.enabled ? "idle" : "disabled",
@@ -19697,17 +20290,35 @@ var AgentEnhancerService = class extends TypertRemoteService {
19697
20290
  ..."name" in request ? { name: request.name } : {},
19698
20291
  ..."id" in request ? { id: request.id } : {},
19699
20292
  ..."index" in request ? { index: request.index } : {},
20293
+ ..."accept" in request && request.accept !== void 0 ? { accept: request.accept } : {},
19700
20294
  ..."vars" in request && request.vars !== void 0 ? { vars: request.vars } : {}
19701
20295
  });
19702
20296
  const meta = (recipe) => ({
19703
- ...recipe,
19704
- variables: recipe.variables.map((variable) => ({ ...variable }))
20297
+ id: recipe.id,
20298
+ name: recipe.name,
20299
+ createdAt: recipe.createdAt,
20300
+ updatedAt: recipe.updatedAt,
20301
+ steps: recipe.steps,
20302
+ variables: recipe.variables.map((variable) => ({ ...variable })),
20303
+ rev: recipe.rev,
20304
+ history: recipe.history,
20305
+ ...recipe.pendingHeal === void 0 ? {} : {
20306
+ pendingHeal: {
20307
+ id: recipe.pendingHeal.id,
20308
+ failedAt: recipe.pendingHeal.failedAt,
20309
+ kind: recipe.pendingHeal.replacement.kind,
20310
+ label: recipe.pendingHeal.replacement.kind === "navigate" ? recipe.pendingHeal.replacement.url : recipe.pendingHeal.replacement.kind === "press" ? recipe.pendingHeal.replacement.key : recipe.pendingHeal.replacement.name,
20311
+ inserted: recipe.pendingHeal.inserted.length,
20312
+ reason: recipe.pendingHeal.reason
20313
+ }
20314
+ }
19705
20315
  });
19706
20316
  return {
19707
20317
  ok: result.ok,
19708
20318
  ...result.recipes === void 0 ? {} : { recipes: result.recipes.map(meta) },
19709
20319
  ...result.recipe === void 0 ? {} : { recipe: meta(result.recipe) },
19710
20320
  ...result.lines === void 0 ? {} : { lines: [...result.lines] },
20321
+ ...result.healed === void 0 ? {} : { healed: result.healed },
19711
20322
  ...result.steps === void 0 ? {} : { steps: result.steps.map((step) => ({ ...step })) },
19712
20323
  ...result.stoppedAt === void 0 ? {} : { stoppedAt: result.stoppedAt },
19713
20324
  ...result.reason === void 0 ? {} : { reason: result.reason },