@refrainai/cli 0.4.1 → 0.4.3

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.
Files changed (83) hide show
  1. package/dist/{ai-model-FM6GWCID.js → ai-model-DP5PKGM6.js} +2 -2
  2. package/dist/{chunk-IGFCYKHC.js → chunk-5CKPPEYP.js} +262 -305
  3. package/dist/chunk-5CKPPEYP.js.map +1 -0
  4. package/dist/{chunk-7UCVPKD4.js → chunk-6FGCPMBU.js} +34 -74
  5. package/dist/chunk-6FGCPMBU.js.map +1 -0
  6. package/dist/{chunk-2BVDAJZT.js → chunk-A5X2VF5G.js} +9 -6
  7. package/dist/chunk-A5X2VF5G.js.map +1 -0
  8. package/dist/{chunk-H47NWH7N.js → chunk-AOCGSFRM.js} +611 -73
  9. package/dist/chunk-AOCGSFRM.js.map +1 -0
  10. package/dist/{chunk-CLYJHKPY.js → chunk-CMWLFQXD.js} +43 -42
  11. package/dist/chunk-CMWLFQXD.js.map +1 -0
  12. package/dist/chunk-GC7I5SGK.js +1146 -0
  13. package/dist/chunk-GC7I5SGK.js.map +1 -0
  14. package/dist/{chunk-WEYR56ZN.js → chunk-HHRHHFSK.js} +4 -4
  15. package/dist/chunk-IGJNT457.js +30 -0
  16. package/dist/chunk-IGJNT457.js.map +1 -0
  17. package/dist/{chunk-UGPXCQY3.js → chunk-KFNW4XR2.js} +13 -4
  18. package/dist/chunk-KFNW4XR2.js.map +1 -0
  19. package/dist/{chunk-RT664YIO.js → chunk-LZDZGI4M.js} +3 -1
  20. package/dist/chunk-LZDZGI4M.js.map +1 -0
  21. package/dist/{chunk-RYIJPYM3.js → chunk-MYITSQYV.js} +25 -8
  22. package/dist/chunk-MYITSQYV.js.map +1 -0
  23. package/dist/chunk-NRKZJVPE.js +74 -0
  24. package/dist/chunk-NRKZJVPE.js.map +1 -0
  25. package/dist/chunk-RBZK7T76.js +349 -0
  26. package/dist/chunk-RBZK7T76.js.map +1 -0
  27. package/dist/{chunk-HQDXLWAY.js → chunk-SDV3X5UN.js} +2 -2
  28. package/dist/{chunk-Z33FCOTZ.js → chunk-VVXNFUPL.js} +4 -2
  29. package/dist/chunk-VVXNFUPL.js.map +1 -0
  30. package/dist/chunk-YTVEYQGA.js +64 -0
  31. package/dist/chunk-YTVEYQGA.js.map +1 -0
  32. package/dist/{chunk-DJVUITRB.js → chunk-ZEBQWBEU.js} +898 -1135
  33. package/dist/chunk-ZEBQWBEU.js.map +1 -0
  34. package/dist/cli.js +5 -5
  35. package/dist/{compose-MTSIJY5D.js → compose-AVX5RU67.js} +9 -7
  36. package/dist/{compose-MTSIJY5D.js.map → compose-AVX5RU67.js.map} +1 -1
  37. package/dist/extraction-prompt-VDCKIFLB.js +17 -0
  38. package/dist/extraction-prompt-VDCKIFLB.js.map +1 -0
  39. package/dist/{fix-runbook-ZSBOTLC2.js → fix-runbook-6L5ZMA5G.js} +12 -10
  40. package/dist/{fix-runbook-ZSBOTLC2.js.map → fix-runbook-6L5ZMA5G.js.map} +1 -1
  41. package/dist/prompts-AGUYYIOM.js +13 -0
  42. package/dist/runbook-builder-2ZLE2AEO.js +11 -0
  43. package/dist/{runbook-data-helpers-KRR2SH76.js → runbook-data-helpers-5UAO65TZ.js} +3 -3
  44. package/dist/{runbook-executor-K7T6RJWJ.js → runbook-executor-OJXJTN6A.js} +41 -444
  45. package/dist/runbook-executor-OJXJTN6A.js.map +1 -0
  46. package/dist/{runbook-generator-MPXJBQ5N.js → runbook-generator-UIHWBEYC.js} +61 -136
  47. package/dist/runbook-generator-UIHWBEYC.js.map +1 -0
  48. package/dist/{runbook-schema-3T6TP3JJ.js → runbook-schema-X7DW725O.js} +2 -2
  49. package/dist/runbook-store-S24PXIHD.js +11 -0
  50. package/dist/{schema-5G6UQSPT.js → schema-XFSD5EWN.js} +2 -2
  51. package/dist/{server-AG3LXQBI.js → server-MULT5ZWG.js} +1176 -128
  52. package/dist/server-MULT5ZWG.js.map +1 -0
  53. package/dist/{tenant-ai-config-QPFEJUVJ.js → tenant-ai-config-4NHKRW7O.js} +4 -4
  54. package/dist/tenant-ai-config-4NHKRW7O.js.map +1 -0
  55. package/dist/yaml-patcher-GOCLYKZZ.js +18 -0
  56. package/dist/yaml-patcher-GOCLYKZZ.js.map +1 -0
  57. package/package.json +3 -2
  58. package/dist/chunk-2BVDAJZT.js.map +0 -1
  59. package/dist/chunk-7UCVPKD4.js.map +0 -1
  60. package/dist/chunk-CLYJHKPY.js.map +0 -1
  61. package/dist/chunk-DJVUITRB.js.map +0 -1
  62. package/dist/chunk-H47NWH7N.js.map +0 -1
  63. package/dist/chunk-IGFCYKHC.js.map +0 -1
  64. package/dist/chunk-RT664YIO.js.map +0 -1
  65. package/dist/chunk-RYIJPYM3.js.map +0 -1
  66. package/dist/chunk-UGPXCQY3.js.map +0 -1
  67. package/dist/chunk-VPK2MQAZ.js +0 -589
  68. package/dist/chunk-VPK2MQAZ.js.map +0 -1
  69. package/dist/chunk-Z33FCOTZ.js.map +0 -1
  70. package/dist/runbook-executor-K7T6RJWJ.js.map +0 -1
  71. package/dist/runbook-generator-MPXJBQ5N.js.map +0 -1
  72. package/dist/runbook-store-G5GUOWRR.js +0 -11
  73. package/dist/server-AG3LXQBI.js.map +0 -1
  74. package/dist/yaml-patcher-VGUS2JGH.js +0 -15
  75. /package/dist/{ai-model-FM6GWCID.js.map → ai-model-DP5PKGM6.js.map} +0 -0
  76. /package/dist/{chunk-WEYR56ZN.js.map → chunk-HHRHHFSK.js.map} +0 -0
  77. /package/dist/{chunk-HQDXLWAY.js.map → chunk-SDV3X5UN.js.map} +0 -0
  78. /package/dist/{runbook-data-helpers-KRR2SH76.js.map → prompts-AGUYYIOM.js.map} +0 -0
  79. /package/dist/{runbook-schema-3T6TP3JJ.js.map → runbook-builder-2ZLE2AEO.js.map} +0 -0
  80. /package/dist/{runbook-store-G5GUOWRR.js.map → runbook-data-helpers-5UAO65TZ.js.map} +0 -0
  81. /package/dist/{schema-5G6UQSPT.js.map → runbook-schema-X7DW725O.js.map} +0 -0
  82. /package/dist/{tenant-ai-config-QPFEJUVJ.js.map → runbook-store-S24PXIHD.js.map} +0 -0
  83. /package/dist/{yaml-patcher-VGUS2JGH.js.map → schema-XFSD5EWN.js.map} +0 -0
@@ -3,45 +3,65 @@ import {
3
3
  AgentBrowser,
4
4
  NoopLogger,
5
5
  NoopSpinner,
6
- buildFallbackMessages,
7
- buildSelectorMessages,
8
- buildSuggestionUserPrompt,
9
- buildVisionMessages,
10
6
  classifyFailure,
11
- countElements,
12
7
  createDebugLogger,
13
- findElementInSnapshot,
8
+ formatAiMetricsSection,
9
+ formatAiSelectorQualityFromSteps,
10
+ formatAiSelectorQualityIssues,
11
+ formatDebugLogSections,
14
12
  formatDuration,
13
+ formatFailureCategoryDistribution,
14
+ formatPerformanceBottlenecks,
15
+ formatRecoveryEffectiveness,
16
+ formatRecoveryEffectivenessFromTelemetry,
17
+ formatRetryDistribution,
18
+ formatRuntimeEnvironment,
19
+ formatSelectorResolutionStats,
20
+ formatSelectorResolutionStatsFromTelemetry,
15
21
  getRecoveryHint,
16
- getSuggestionSystemPrompt,
17
- parseAllElements,
18
22
  parseAndAppendToMemory,
23
+ readDebugLog,
24
+ renderOptionsMarkdown,
19
25
  sanitizeBrowserError,
20
26
  sleep
21
- } from "./chunk-DJVUITRB.js";
22
- import {
23
- filterSnapshot
24
- } from "./chunk-XMFCXPYU.js";
27
+ } from "./chunk-ZEBQWBEU.js";
25
28
  import {
26
29
  resolveTemplate
27
30
  } from "./chunk-D5SI2PHK.js";
28
31
  import {
29
32
  formatRiskHint,
30
- getLocale,
31
33
  log,
32
34
  note,
33
35
  promptConfirm,
34
36
  promptSelect,
35
- promptText,
36
- t,
37
- tf
38
- } from "./chunk-7UCVPKD4.js";
37
+ promptText
38
+ } from "./chunk-NRKZJVPE.js";
39
39
  import {
40
40
  getActiveMetricsCollector,
41
41
  getModel,
42
42
  trackedGenerateObject,
43
43
  withAIRetry
44
- } from "./chunk-UGPXCQY3.js";
44
+ } from "./chunk-KFNW4XR2.js";
45
+ import {
46
+ filterSnapshot
47
+ } from "./chunk-XMFCXPYU.js";
48
+ import {
49
+ countElements,
50
+ findElementInSnapshot,
51
+ parseAllElements
52
+ } from "./chunk-YTVEYQGA.js";
53
+ import {
54
+ buildFallbackMessages,
55
+ buildSelectorMessages,
56
+ buildSuggestionUserPrompt,
57
+ buildVisionMessages,
58
+ getSuggestionSystemPrompt
59
+ } from "./chunk-GC7I5SGK.js";
60
+ import {
61
+ getLocale,
62
+ t,
63
+ tf
64
+ } from "./chunk-6FGCPMBU.js";
45
65
 
46
66
  // src/runbook-executor/types.ts
47
67
  var SELF_HEAL_DEFAULTS = {
@@ -1526,6 +1546,9 @@ function toNumber(val) {
1526
1546
  return Number.isNaN(n) ? 0 : n;
1527
1547
  }
1528
1548
 
1549
+ // src/runbook-executor/executor.ts
1550
+ import { z as z5 } from "zod";
1551
+
1529
1552
  // src/context/snapshot-cache.ts
1530
1553
  import { createHash as createHash4 } from "crypto";
1531
1554
  var SnapshotCache = class {
@@ -2049,13 +2072,19 @@ async function execute(config, runbook, opts) {
2049
2072
  step: step.ordinal,
2050
2073
  data: { error: rawErrorMsg }
2051
2074
  });
2075
+ const actionFailureCategory = classifyFailure({
2076
+ error: rawErrorMsg,
2077
+ selectorResolved: true,
2078
+ actionExecuted: true
2079
+ });
2052
2080
  results.push({
2053
2081
  ordinal: step.ordinal,
2054
2082
  description: step.description,
2055
2083
  actionType: step.action.type,
2056
2084
  status: "failed",
2057
2085
  durationMs: Date.now() - start,
2058
- error: errorMsg
2086
+ error: errorMsg,
2087
+ failureCategory: actionFailureCategory
2059
2088
  });
2060
2089
  await opts.onStepFailed?.(step.ordinal, errorMsg).catch(() => {
2061
2090
  });
@@ -2617,43 +2646,105 @@ async function executeStep(browser, step, runbook, config, opts, debugLogger, lo
2617
2646
  }
2618
2647
  if (step.action.type === "extract") {
2619
2648
  const script = opts.store.resolveTemplate(step.action.script ?? step.action.value ?? "");
2620
- if (!script) {
2621
- return { status: "failed", durationMs: Date.now() - start, error: "extract requires script or value" };
2622
- }
2623
- logger.step(`Extract: executing script`);
2624
- debugLogger.log({
2625
- phase: "executor",
2626
- event: "extract",
2627
- step: step.ordinal,
2628
- data: { script: script.slice(0, 200) }
2629
- });
2630
- const result = await browser.evaluate(script);
2631
- const isArray = Array.isArray(result);
2632
- const stringifyApplied = typeof result !== "string" && result !== null && result !== void 0;
2633
- const resultStr = result === null || result === void 0 ? "" : typeof result === "string" ? result : JSON.stringify(result);
2634
- debugLogger.log({
2635
- phase: "executor",
2636
- event: "extract_result",
2637
- step: step.ordinal,
2638
- data: {
2639
- resultType: result === null ? "null" : typeof result,
2640
- isArray,
2641
- arrayLength: isArray ? result.length : void 0,
2642
- resultPreview: resultStr.slice(0, 200),
2643
- storedLength: resultStr.length,
2644
- stringifyApplied
2645
- }
2646
- });
2647
- if (resultStr === "") {
2648
- logger.warn("Extract returned empty result");
2649
+ if (script) {
2650
+ logger.step(`Extract: executing script`);
2649
2651
  debugLogger.log({
2650
2652
  phase: "executor",
2651
- event: "extract_empty_result",
2653
+ event: "extract",
2652
2654
  step: step.ordinal,
2653
2655
  data: { script: script.slice(0, 200) }
2654
2656
  });
2657
+ const result = await browser.evaluate(script);
2658
+ const isArray = Array.isArray(result);
2659
+ const stringifyApplied = typeof result !== "string" && result !== null && result !== void 0;
2660
+ const resultStr = result === null || result === void 0 ? "" : typeof result === "string" ? result : JSON.stringify(result);
2661
+ debugLogger.log({
2662
+ phase: "executor",
2663
+ event: "extract_result",
2664
+ step: step.ordinal,
2665
+ data: {
2666
+ resultType: result === null ? "null" : typeof result,
2667
+ isArray,
2668
+ arrayLength: isArray ? result.length : void 0,
2669
+ resultPreview: resultStr.slice(0, 200),
2670
+ storedLength: resultStr.length,
2671
+ stringifyApplied
2672
+ }
2673
+ });
2674
+ if (resultStr === "") {
2675
+ logger.warn("Extract returned empty result");
2676
+ debugLogger.log({
2677
+ phase: "executor",
2678
+ event: "extract_empty_result",
2679
+ step: step.ordinal,
2680
+ data: { script: script.slice(0, 200) }
2681
+ });
2682
+ }
2683
+ return { status: "success", durationMs: Date.now() - start, extractedData: resultStr };
2684
+ }
2685
+ if (step.action.extractPrompt) {
2686
+ const prompt = opts.store.resolveTemplate(step.action.extractPrompt);
2687
+ logger.step(`Extract: AI extraction`);
2688
+ debugLogger.log({
2689
+ phase: "executor",
2690
+ event: "extract",
2691
+ step: step.ordinal,
2692
+ data: { extractPrompt: prompt.slice(0, 200) }
2693
+ });
2694
+ const snapshot = await browser.snapshot();
2695
+ const extractSchema = z5.object({ data: z5.string() });
2696
+ const model = opts.aiProvider ? opts.aiProvider.getModel("extraction") : getModel("extraction");
2697
+ const { EXTRACT_SYSTEM_PROMPT } = await import("./extraction-prompt-VDCKIFLB.js");
2698
+ const goalContext = runbook.metadata?.goal ? `
2699
+
2700
+ \u62BD\u51FA\u306E\u76EE\u6A19:
2701
+ ${runbook.metadata.goal}` : "";
2702
+ const aiResult2 = await trackedGenerateObject("extraction", {
2703
+ model,
2704
+ system: EXTRACT_SYSTEM_PROMPT,
2705
+ prompt: `${prompt}${goalContext}
2706
+
2707
+ \u30B9\u30CA\u30C3\u30D7\u30B7\u30E7\u30C3\u30C8:
2708
+ ${snapshot}`,
2709
+ schema: extractSchema,
2710
+ temperature: 0
2711
+ });
2712
+ const resultStr = aiResult2.object?.data ?? "";
2713
+ debugLogger.log({
2714
+ phase: "executor",
2715
+ event: "extract_result",
2716
+ step: step.ordinal,
2717
+ data: {
2718
+ resultType: "string (AI)",
2719
+ resultPreview: resultStr.slice(0, 200),
2720
+ storedLength: resultStr.length
2721
+ }
2722
+ });
2723
+ if (resultStr === "") {
2724
+ logger.warn("Extract (AI) returned empty result");
2725
+ debugLogger.log({
2726
+ phase: "executor",
2727
+ event: "extract_empty_result",
2728
+ step: step.ordinal,
2729
+ data: { extractPrompt: prompt.slice(0, 200) }
2730
+ });
2731
+ }
2732
+ return { status: "success", durationMs: Date.now() - start, extractedData: resultStr };
2655
2733
  }
2656
- return { status: "success", durationMs: Date.now() - start, extractedData: resultStr };
2734
+ return {
2735
+ status: "failed",
2736
+ durationMs: Date.now() - start,
2737
+ error: "extract requires script, extractPrompt, or value",
2738
+ diagnostics: {
2739
+ stepAction: {
2740
+ type: step.action.type,
2741
+ value: step.action.value,
2742
+ script: step.action.script,
2743
+ extractPrompt: step.action.extractPrompt
2744
+ },
2745
+ recoveryHint: "extract \u30B9\u30C6\u30C3\u30D7\u306B script\uFF08JavaScript\uFF09\u307E\u305F\u306F extractPrompt\uFF08AI\u62BD\u51FA\u30D7\u30ED\u30F3\u30D7\u30C8\uFF09\u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044"
2746
+ }
2747
+ };
2657
2748
  }
2658
2749
  if (step.action.type === "export") {
2659
2750
  if (!opts.dataStore) {
@@ -2762,6 +2853,7 @@ async function executeStep(browser, step, runbook, config, opts, debugLogger, lo
2762
2853
  let lastAiResponseText = "";
2763
2854
  let lastAiPrompt = "";
2764
2855
  let attempts = 0;
2856
+ const resolvedDescription = opts.store.resolveTemplate(step.description);
2765
2857
  const failureHistory = [];
2766
2858
  const retryDetails = [];
2767
2859
  let cachedRefUsed = false;
@@ -2962,11 +3054,11 @@ async function executeStep(browser, step, runbook, config, opts, debugLogger, lo
2962
3054
  opts.store.set("extractedData", skillResult.extractedData);
2963
3055
  }
2964
3056
  const filteredSnap = skillResult?.snapshot ?? (snapshotCache ? snapshotCache.getFiltered(lastSnapshot) : lastSnapshot);
2965
- const relevantContext = contextChunker ? contextChunker.selectRelevant(step.description, step.url) : config.contextMarkdown;
3057
+ const relevantContext = contextChunker ? contextChunker.selectRelevant(resolvedDescription, step.url) : config.contextMarkdown;
2966
3058
  const detailed = await resolveWithAIDetailed(
2967
3059
  filteredSnap,
2968
3060
  step.action.selector,
2969
- step.description,
3061
+ resolvedDescription,
2970
3062
  step.url,
2971
3063
  relevantContext,
2972
3064
  debugLogger,
@@ -3014,11 +3106,11 @@ async function executeStep(browser, step, runbook, config, opts, debugLogger, lo
3014
3106
  opts.store.set("extractedData", scrollSkillResult.extractedData);
3015
3107
  }
3016
3108
  const filteredScrollSnap = scrollSkillResult?.snapshot ?? (snapshotCache ? snapshotCache.getFiltered(scrolledSnapshot) : scrolledSnapshot);
3017
- const relevantCtx = contextChunker ? contextChunker.selectRelevant(step.description, step.url) : config.contextMarkdown;
3109
+ const relevantCtx = contextChunker ? contextChunker.selectRelevant(resolvedDescription, step.url) : config.contextMarkdown;
3018
3110
  const recoveryResult = await resolveWithAIDetailed(
3019
3111
  filteredScrollSnap,
3020
3112
  step.action.selector,
3021
- step.description,
3113
+ resolvedDescription,
3022
3114
  step.url,
3023
3115
  relevantCtx,
3024
3116
  debugLogger,
@@ -3066,7 +3158,7 @@ async function executeStep(browser, step, runbook, config, opts, debugLogger, lo
3066
3158
  imageBuffer,
3067
3159
  annotations,
3068
3160
  step.action.selector,
3069
- step.description,
3161
+ resolvedDescription,
3070
3162
  step.url,
3071
3163
  failureHistory,
3072
3164
  debugLogger,
@@ -3108,10 +3200,10 @@ async function executeStep(browser, step, runbook, config, opts, debugLogger, lo
3108
3200
  data: { failureHistory }
3109
3201
  });
3110
3202
  logger.warn("Attempting agent fallback...");
3111
- const fallbackContext = contextChunker ? contextChunker.selectRelevant(step.description, step.url) : config.contextMarkdown;
3203
+ const fallbackContext = contextChunker ? contextChunker.selectRelevant(resolvedDescription, step.url) : config.contextMarkdown;
3112
3204
  const fallbackResult = await runGoalAgent(
3113
3205
  browser,
3114
- { description: step.description, action: step.action },
3206
+ { description: resolvedDescription, action: step.action },
3115
3207
  failureHistory,
3116
3208
  fallbackContext,
3117
3209
  debugLogger,
@@ -3432,9 +3524,9 @@ function countSnapshotElements(snapshot) {
3432
3524
  }
3433
3525
 
3434
3526
  // src/runbook-executor/input-collector.ts
3435
- import { z as z5 } from "zod";
3436
- var contextValuesSchema = z5.object({
3437
- values: z5.record(z5.string(), z5.string()).describe("\u5909\u6570\u540D\u2192\u62BD\u51FA\u5024\u306E\u30DE\u30C3\u30D7")
3527
+ import { z as z6 } from "zod";
3528
+ var contextValuesSchema = z6.object({
3529
+ values: z6.record(z6.string(), z6.string()).describe("\u5909\u6570\u540D\u2192\u62BD\u51FA\u5024\u306E\u30DE\u30C3\u30D7")
3438
3530
  });
3439
3531
  var CONTEXT_EXTRACTION_SYSTEM_PROMPT = [
3440
3532
  "\u4EE5\u4E0B\u306E\u5909\u6570\u30EA\u30B9\u30C8\u3068 context markdown \u304C\u4E0E\u3048\u3089\u308C\u307E\u3059\u3002",
@@ -3606,6 +3698,25 @@ async function planExecution(runbook, config) {
3606
3698
  log.info(tf("planner.extractedFromContext", { count: coreResult.contextExtractedKeys.size }));
3607
3699
  }
3608
3700
  const captureVarNames = new Set(coreResult.captureVars);
3701
+ if (!config.skipConfirmation) {
3702
+ const promptVarsToEdit = Object.entries(variables).filter(
3703
+ ([name, def]) => def.source === "prompt" && !coreResult.unresolvedDataVars.includes(name) && !captureVarNames.has(name)
3704
+ );
3705
+ if (promptVarsToEdit.length > 0) {
3706
+ log.step(t("planner.promptVariables"));
3707
+ for (const [name, def] of promptVarsToEdit) {
3708
+ const currentValue = coreResult.values.get(name) ?? def.value ?? "";
3709
+ const answer = await promptText(
3710
+ def.description ?? name,
3711
+ {
3712
+ initialValue: currentValue,
3713
+ placeholder: def.value || t("planner.placeholder")
3714
+ }
3715
+ );
3716
+ coreResult.values.set(name, answer.trim());
3717
+ }
3718
+ }
3719
+ }
3609
3720
  const stillUnresolved = Object.entries(variables).filter(
3610
3721
  ([name, def]) => !coreResult.values.has(name) && !coreResult.unresolvedDataVars.includes(name) && !captureVarNames.has(name) && def.required !== false
3611
3722
  );
@@ -4056,20 +4167,20 @@ function parseIntEnv(key) {
4056
4167
  }
4057
4168
 
4058
4169
  // src/runbook-executor/self-heal-analyzer.ts
4059
- import { z as z6 } from "zod";
4060
- var suggestionSchema = z6.array(
4061
- z6.object({
4062
- stepOrdinal: z6.number().describe("\u5931\u6557\u3057\u305F\u30B9\u30C6\u30C3\u30D7\u306E ordinal"),
4063
- stepDescription: z6.string().describe("\u30B9\u30C6\u30C3\u30D7\u306E\u8AAC\u660E"),
4064
- error: z6.string().describe("\u5931\u6557\u30A8\u30E9\u30FC\u306E\u8981\u7D04"),
4065
- runbookFix: z6.string().describe(
4170
+ import { z as z7 } from "zod";
4171
+ var suggestionSchema = z7.array(
4172
+ z7.object({
4173
+ stepOrdinal: z7.number().describe("\u5931\u6557\u3057\u305F\u30B9\u30C6\u30C3\u30D7\u306E ordinal"),
4174
+ stepDescription: z7.string().describe("\u30B9\u30C6\u30C3\u30D7\u306E\u8AAC\u660E"),
4175
+ error: z7.string().describe("\u5931\u6557\u30A8\u30E9\u30FC\u306E\u8981\u7D04"),
4176
+ runbookFix: z7.string().describe(
4066
4177
  "\u624B\u9806\u66F8\uFF08YAML\uFF09\u3078\u306E\u4FEE\u6B63\u63D0\u6848: \u30BB\u30EC\u30AF\u30BF\u5909\u66F4\u3001\u30B9\u30C6\u30C3\u30D7\u8FFD\u52A0/\u524A\u9664\u3001\u30A2\u30AF\u30B7\u30E7\u30F3\u5024\u306E\u66F4\u65B0\u306A\u3069"
4067
4178
  ),
4068
- contextFix: z6.string().describe(
4179
+ contextFix: z7.string().describe(
4069
4180
  "\u30B3\u30F3\u30C6\u30AD\u30B9\u30C8\uFF08markdown\uFF09\u3078\u306E\u4FEE\u6B63\u63D0\u6848: \u30DA\u30FC\u30B8\u69CB\u9020\u5909\u66F4\u306E\u8A18\u8F09\u3001\u524D\u63D0\u6761\u4EF6\u306E\u8FFD\u52A0\u306A\u3069\u3002context \u672A\u63D0\u4F9B\u6642\u306F\u7A7A\u6587\u5B57"
4070
4181
  ),
4071
- severity: z6.enum(["error", "warning"]).describe("error: \u5B9F\u884C\u4E0D\u53EF\u3001warning: \u4E0D\u5B89\u5B9A"),
4072
- failureCategory: z6.enum([
4182
+ severity: z7.enum(["error", "warning"]).describe("error: \u5B9F\u884C\u4E0D\u53EF\u3001warning: \u4E0D\u5B89\u5B9A"),
4183
+ failureCategory: z7.enum([
4073
4184
  "element_not_found",
4074
4185
  "element_stale",
4075
4186
  "page_structure_changed",
@@ -4077,7 +4188,7 @@ var suggestionSchema = z6.array(
4077
4188
  "action_failed",
4078
4189
  "unknown"
4079
4190
  ]).optional().describe("\u30A8\u30E9\u30FC\u5206\u985E\u30AB\u30C6\u30B4\u30EA"),
4080
- suggestedStrategy: z6.string().optional().describe("\u30AB\u30C6\u30B4\u30EA\u306B\u57FA\u3065\u304F\u63A8\u5968\u5BFE\u5FDC")
4191
+ suggestedStrategy: z7.string().optional().describe("\u30AB\u30C6\u30B4\u30EA\u306B\u57FA\u3065\u304F\u63A8\u5968\u5BFE\u5FDC")
4081
4192
  })
4082
4193
  );
4083
4194
  async function analyzeDebugResult(report, runbook, retryWarningThreshold, contextMarkdown, aiProvider) {
@@ -4152,6 +4263,432 @@ ${retryInfo}${categoryInfo}`;
4152
4263
  }
4153
4264
  }
4154
4265
 
4266
+ // src/runbook-executor/report-generator.ts
4267
+ function formatStepResult(step, indent) {
4268
+ const lines = [];
4269
+ const duration = `${step.durationMs}ms`;
4270
+ if (step.conditionSkipped) {
4271
+ lines.push(`${indent}${step.ordinal}. [SKIPPED] ${step.description} (condition skipped)`);
4272
+ return lines;
4273
+ }
4274
+ if (step.branchMatch !== void 0) {
4275
+ const tag2 = step.status === "success" ? "DONE" : step.status === "skipped" ? "SKIPPED" : "FAILED";
4276
+ lines.push(`${indent}${step.ordinal}. [${tag2}] ${step.description} (branch: ${step.branchMatch || "no match"}, ${duration})`);
4277
+ if (step.subStepResults) {
4278
+ for (const subResults of step.subStepResults) {
4279
+ for (const sub of subResults) {
4280
+ lines.push(...formatStepResult(sub, `${indent} `));
4281
+ }
4282
+ }
4283
+ }
4284
+ return lines;
4285
+ }
4286
+ if (step.loopIterations !== void 0) {
4287
+ const tag2 = step.status === "success" ? "DONE" : "FAILED";
4288
+ const iterLabel = step.forEachItemCount !== void 0 ? `forEach: ${step.forEachItemCount} items` : `${step.loopIterations} iterations`;
4289
+ lines.push(`${indent}${step.ordinal}. [${tag2}] ${step.description} (${iterLabel}, ${duration})`);
4290
+ if (step.subStepResults) {
4291
+ for (let i = 0; i < step.subStepResults.length; i++) {
4292
+ lines.push(`${indent} iteration ${i}:`);
4293
+ for (const sub of step.subStepResults[i]) {
4294
+ lines.push(...formatStepResult(sub, `${indent} `));
4295
+ }
4296
+ }
4297
+ }
4298
+ return lines;
4299
+ }
4300
+ const tag = step.status === "success" ? "DONE" : step.status === "failed" ? "FAILED" : "SKIPPED";
4301
+ const errorInfo = step.status === "failed" && step.error ? ` \u2014 Error: ${step.error}` : "";
4302
+ const category = step.failureCategory ? ` [${step.failureCategory}]` : "";
4303
+ const retry = step.retryCount ? ` (retries: ${step.retryCount})` : "";
4304
+ let resolveInfo = "";
4305
+ if (step.resolveMethod) {
4306
+ resolveInfo = ` [resolved: ${step.resolveMethod}]`;
4307
+ if (step.resolveMethod === "deterministic" && step.deterministicMatchType) {
4308
+ const confStr = step.deterministicConfidence != null ? `, conf: ${step.deterministicConfidence.toFixed(2)}` : "";
4309
+ resolveInfo += ` (match: ${step.deterministicMatchType}${confStr})`;
4310
+ }
4311
+ }
4312
+ lines.push(`${indent}${step.ordinal}. [${tag}] ${step.description} (${duration})${resolveInfo}${errorInfo}${category}${retry}`);
4313
+ return lines;
4314
+ }
4315
+ function formatDiagnostics(diag, stepOrdinal) {
4316
+ const lines = [];
4317
+ lines.push(`### Step #${stepOrdinal} \u2014 Diagnostics`);
4318
+ lines.push("");
4319
+ if (diag.stepAction) {
4320
+ lines.push(`**Step Action**: type=${diag.stepAction.type}`);
4321
+ if (diag.stepAction.value) lines.push(`- value: ${diag.stepAction.value}`);
4322
+ if (diag.stepAction.script) lines.push(`- script: ${diag.stepAction.script.slice(0, 200)}`);
4323
+ if (diag.stepAction.extractPrompt) lines.push(`- extractPrompt: ${diag.stepAction.extractPrompt.slice(0, 200)}`);
4324
+ if (diag.stepAction.url) lines.push(`- url: ${diag.stepAction.url}`);
4325
+ if (diag.stepAction.selector) {
4326
+ lines.push("- selector:");
4327
+ lines.push("```json");
4328
+ lines.push(JSON.stringify(diag.stepAction.selector, null, 2));
4329
+ lines.push("```");
4330
+ }
4331
+ lines.push("");
4332
+ }
4333
+ if (diag.stepUrl) {
4334
+ lines.push(`**Step URL**: ${diag.stepUrl}`);
4335
+ lines.push("");
4336
+ }
4337
+ if (diag.recoveryHint) {
4338
+ lines.push(`**Recovery Hint**: ${diag.recoveryHint}`);
4339
+ lines.push("");
4340
+ }
4341
+ if (diag.executionStrategy) {
4342
+ const s = diag.executionStrategy;
4343
+ lines.push(`**Execution Strategy**: maxRetries=${s.maxRetries}, changeTimeouts=[${s.changeTimeouts.join(",")}]ms, finalRetryStabilize=${s.finalRetryStabilizeMs}ms, domStability=${s.domStabilityMs}ms`);
4344
+ lines.push("");
4345
+ }
4346
+ if (diag.deterministicResolveResult) {
4347
+ lines.push(`**Deterministic Resolve**: ${diag.deterministicResolveResult}`);
4348
+ lines.push("");
4349
+ }
4350
+ if (diag.failureHistory && diag.failureHistory.length > 0) {
4351
+ lines.push("**Failure History**:");
4352
+ for (const f of diag.failureHistory) {
4353
+ lines.push(`- ${f}`);
4354
+ }
4355
+ lines.push("");
4356
+ }
4357
+ if (diag.validationWarnings && diag.validationWarnings.length > 0) {
4358
+ lines.push("**Validation Warnings**:");
4359
+ for (const w of diag.validationWarnings) {
4360
+ lines.push(`- ${w}`);
4361
+ }
4362
+ lines.push("");
4363
+ }
4364
+ if (diag.validationErrors && diag.validationErrors.length > 0) {
4365
+ lines.push("**Validation Errors**:");
4366
+ for (const e of diag.validationErrors) {
4367
+ lines.push(`- ${e}`);
4368
+ }
4369
+ lines.push("");
4370
+ }
4371
+ if (diag.visionFallbackResult) {
4372
+ const vf = diag.visionFallbackResult;
4373
+ lines.push(`**Vision Fallback**: annotations=${vf.annotationCount}, success=${vf.success}`);
4374
+ lines.push(`- Reasoning: ${vf.reasoning}`);
4375
+ lines.push("");
4376
+ }
4377
+ if (diag.agentFallbackResult) {
4378
+ const fb = diag.agentFallbackResult;
4379
+ lines.push(`**Agent Fallback**: strategy=${fb.strategy}, success=${fb.success}`);
4380
+ lines.push(`- Analysis: ${fb.analysis}`);
4381
+ lines.push(`- Reasoning: ${fb.reasoning}`);
4382
+ lines.push("");
4383
+ }
4384
+ if (diag.lastAiResponseText) {
4385
+ lines.push("**Last AI Response**:");
4386
+ lines.push("```json");
4387
+ lines.push(diag.lastAiResponseText);
4388
+ lines.push("```");
4389
+ lines.push("");
4390
+ }
4391
+ if (diag.lastSnapshotPreview) {
4392
+ lines.push("**Last Snapshot Preview** (truncated):");
4393
+ lines.push("```");
4394
+ lines.push(diag.lastSnapshotPreview);
4395
+ lines.push("```");
4396
+ lines.push("");
4397
+ }
4398
+ return lines;
4399
+ }
4400
+ function formatRetryDetails(retryDetails, stepOrdinal) {
4401
+ if (!retryDetails || retryDetails.length === 0) return [];
4402
+ const lines = [];
4403
+ lines.push(`### Step #${stepOrdinal} \u2014 Retry Details`);
4404
+ lines.push("");
4405
+ for (const detail of retryDetails) {
4406
+ lines.push(`#### Attempt ${detail.attempt}`);
4407
+ lines.push(`- Snapshot changed: ${detail.snapshotChanged}`);
4408
+ lines.push(`- Element count: ${detail.snapshotElementCount}`);
4409
+ lines.push(`- Failure reason: ${detail.failureReason}`);
4410
+ if (detail.aiReasoning) {
4411
+ lines.push(`- AI reasoning: ${detail.aiReasoning}`);
4412
+ }
4413
+ if (detail.aiResponse) {
4414
+ lines.push("- AI response:");
4415
+ lines.push("```json");
4416
+ lines.push(detail.aiResponse);
4417
+ lines.push("```");
4418
+ }
4419
+ if (detail.aiPrompt) {
4420
+ lines.push("");
4421
+ lines.push("<details>");
4422
+ lines.push(`<summary>AI Prompt (attempt ${detail.attempt})</summary>`);
4423
+ lines.push("");
4424
+ lines.push("```");
4425
+ lines.push(detail.aiPrompt);
4426
+ lines.push("```");
4427
+ lines.push("</details>");
4428
+ }
4429
+ if (detail.snapshotPreview) {
4430
+ lines.push("");
4431
+ lines.push("<details>");
4432
+ lines.push(`<summary>Snapshot Preview (attempt ${detail.attempt}, truncated)</summary>`);
4433
+ lines.push("");
4434
+ lines.push("```");
4435
+ lines.push(detail.snapshotPreview);
4436
+ lines.push("```");
4437
+ lines.push("</details>");
4438
+ }
4439
+ lines.push("");
4440
+ }
4441
+ return lines;
4442
+ }
4443
+ function formatAiAgentSummary(failedSteps, input) {
4444
+ const lines = [];
4445
+ lines.push("## AI Agent Summary");
4446
+ lines.push("");
4447
+ lines.push("\u4EE5\u4E0B\u306F AI \u30A8\u30FC\u30B8\u30A7\u30F3\u30C8\u304C\u5373\u5EA7\u306B\u4FEE\u6B63\u30A2\u30AF\u30B7\u30E7\u30F3\u3092\u53D6\u308B\u305F\u3081\u306E\u69CB\u9020\u5316\u60C5\u5831\u3067\u3059\u3002");
4448
+ lines.push("");
4449
+ lines.push("### \u5931\u6557\u30B9\u30C6\u30C3\u30D7\u3068\u4FEE\u6B63\u6307\u793A");
4450
+ lines.push("");
4451
+ for (const step of failedSteps) {
4452
+ lines.push(`#### Step #${step.ordinal}: ${step.description}`);
4453
+ lines.push("");
4454
+ lines.push(`- **\u30A8\u30E9\u30FC**: ${step.error ?? "Unknown"}`);
4455
+ if (step.failureCategory) {
4456
+ lines.push(`- **\u5206\u985E**: \`${step.failureCategory}\``);
4457
+ lines.push(`- **\u63A8\u5968\u5BFE\u5FDC**: ${getRecoveryHint(step.failureCategory)}`);
4458
+ }
4459
+ if (step.retryCount !== void 0 && step.retryCount > 0) {
4460
+ lines.push(`- **\u30EA\u30C8\u30E9\u30A4\u56DE\u6570**: ${step.retryCount}`);
4461
+ }
4462
+ if (step.diagnostics) {
4463
+ const diag = step.diagnostics;
4464
+ if (diag.stepAction?.selector) {
4465
+ lines.push(`- **\u73FE\u5728\u306E\u30BB\u30EC\u30AF\u30BF**:`);
4466
+ lines.push(" ```json");
4467
+ lines.push(` ${JSON.stringify(diag.stepAction.selector)}`);
4468
+ lines.push(" ```");
4469
+ }
4470
+ if (diag.lastSnapshotPreview) {
4471
+ lines.push(`- **\u6700\u7D42\u30B9\u30CA\u30C3\u30D7\u30B7\u30E7\u30C3\u30C8**:`);
4472
+ lines.push(" <details>");
4473
+ lines.push(" <summary>\u30B9\u30CA\u30C3\u30D7\u30B7\u30E7\u30C3\u30C8\u5168\u6587\u3092\u8868\u793A</summary>");
4474
+ lines.push("");
4475
+ lines.push(" ```");
4476
+ lines.push(` ${diag.lastSnapshotPreview}`);
4477
+ lines.push(" ```");
4478
+ lines.push(" </details>");
4479
+ }
4480
+ if (diag.visionFallbackResult) {
4481
+ lines.push(`- **Vision Fallback \u7D50\u679C**: annotations=${diag.visionFallbackResult.annotationCount}, success=${diag.visionFallbackResult.success}`);
4482
+ lines.push(` - \u7406\u7531: ${diag.visionFallbackResult.reasoning}`);
4483
+ }
4484
+ if (diag.agentFallbackResult) {
4485
+ lines.push(`- **Agent Fallback \u7D50\u679C**: strategy=${diag.agentFallbackResult.strategy}, success=${diag.agentFallbackResult.success}`);
4486
+ lines.push(` - \u5206\u6790: ${diag.agentFallbackResult.analysis}`);
4487
+ }
4488
+ }
4489
+ if (input.selfHealSuggestions) {
4490
+ const suggestion = input.selfHealSuggestions.find(
4491
+ (s) => s.stepOrdinal === step.ordinal
4492
+ );
4493
+ if (suggestion) {
4494
+ if (suggestion.runbookFix) {
4495
+ lines.push(`- **YAML \u4FEE\u6B63\u63D0\u6848**: ${suggestion.runbookFix}`);
4496
+ }
4497
+ if (suggestion.contextFix) {
4498
+ lines.push(`- **Context \u4FEE\u6B63\u63D0\u6848**: ${suggestion.contextFix}`);
4499
+ }
4500
+ if (suggestion.suggestedStrategy) {
4501
+ lines.push(`- **\u63A8\u5968\u6226\u7565**: ${suggestion.suggestedStrategy}`);
4502
+ }
4503
+ }
4504
+ }
4505
+ lines.push("");
4506
+ }
4507
+ lines.push("### \u4FEE\u6B63\u5BFE\u8C61\u30D5\u30A1\u30A4\u30EB");
4508
+ lines.push("");
4509
+ lines.push(`- \`${input.runbookPath}\` (Steps: ${failedSteps.map((s) => `#${s.ordinal}`).join(", ")})`);
4510
+ lines.push("");
4511
+ lines.push("### \u4FEE\u6B63\u5F8C\u306E\u691C\u8A3C\u30B3\u30DE\u30F3\u30C9");
4512
+ lines.push("");
4513
+ lines.push("```bash");
4514
+ lines.push(`pnpm execute -- --runbook ${input.runbookPath} --self-heal`);
4515
+ lines.push("```");
4516
+ lines.push("");
4517
+ return lines;
4518
+ }
4519
+ function formatSystemInsights(report, debugEntries, telemetryStats) {
4520
+ const lines = [];
4521
+ lines.push("## System Insights");
4522
+ lines.push("");
4523
+ lines.push("> refrain \u306E\u6A5F\u80FD\u6539\u5584\u30FB\u30D0\u30B0\u4FEE\u6B63\u306E\u305F\u3081\u306E\u5206\u6790\u60C5\u5831");
4524
+ lines.push("");
4525
+ const allSteps = flattenSteps(report.steps);
4526
+ lines.push(...formatRuntimeEnvironment());
4527
+ if (report.aiMetrics && report.aiMetrics.totalCalls > 0) {
4528
+ lines.push(...formatAiMetricsSection(report.aiMetrics));
4529
+ }
4530
+ if (debugEntries.length > 0) {
4531
+ lines.push(...formatSelectorResolutionStats(debugEntries, allSteps));
4532
+ lines.push(...formatRetryDistribution(allSteps));
4533
+ const failedSteps = allSteps.filter((s) => s.status === "failed");
4534
+ lines.push(...formatFailureCategoryDistribution(failedSteps));
4535
+ lines.push(...formatRecoveryEffectiveness(debugEntries, allSteps));
4536
+ lines.push(...formatPerformanceBottlenecks(allSteps));
4537
+ lines.push(...formatAiSelectorQualityIssues(debugEntries));
4538
+ } else if (telemetryStats) {
4539
+ lines.push(...formatSelectorResolutionStatsFromTelemetry(telemetryStats, allSteps));
4540
+ lines.push(...formatRetryDistribution(allSteps));
4541
+ const failedSteps = allSteps.filter((s) => s.status === "failed");
4542
+ lines.push(...formatFailureCategoryDistribution(failedSteps));
4543
+ lines.push(...formatRecoveryEffectivenessFromTelemetry(telemetryStats, allSteps));
4544
+ lines.push(...formatPerformanceBottlenecks(allSteps));
4545
+ lines.push(...formatAiSelectorQualityFromSteps(allSteps));
4546
+ } else {
4547
+ lines.push(...formatRetryDistribution(allSteps));
4548
+ const failedSteps = allSteps.filter((s) => s.status === "failed");
4549
+ lines.push(...formatFailureCategoryDistribution(failedSteps));
4550
+ lines.push(...formatPerformanceBottlenecks(allSteps));
4551
+ }
4552
+ return lines;
4553
+ }
4554
+ function flattenSteps(steps) {
4555
+ const result = [];
4556
+ for (const step of steps) {
4557
+ result.push(step);
4558
+ if (step.subStepResults) {
4559
+ for (const iteration of step.subStepResults) {
4560
+ result.push(...flattenSteps(iteration));
4561
+ }
4562
+ }
4563
+ }
4564
+ return result;
4565
+ }
4566
+ async function generateExecutionReportFile(input) {
4567
+ const { report } = input;
4568
+ const lines = [];
4569
+ lines.push("# Execution Report");
4570
+ lines.push("");
4571
+ lines.push("## Session Info");
4572
+ lines.push(`- **Date**: ${(/* @__PURE__ */ new Date()).toISOString()}`);
4573
+ lines.push(`- **Runbook**: ${report.runbookTitle}`);
4574
+ lines.push(`- **Runbook Path**: ${input.runbookPath}`);
4575
+ lines.push(`- **Start URL**: ${report.startUrl}`);
4576
+ const outcome = report.aborted ? "Aborted" : report.failed > 0 ? "Failed" : input.errorMessage ? "Error" : "Success";
4577
+ lines.push(`- **Outcome**: ${outcome}`);
4578
+ lines.push("");
4579
+ if (input.cliOptions && input.cliOptions.length > 0) {
4580
+ lines.push("## Executor CLI Options");
4581
+ lines.push(...renderOptionsMarkdown(input.cliOptions));
4582
+ lines.push("");
4583
+ }
4584
+ if (input.generationContext) {
4585
+ const gc = input.generationContext;
4586
+ lines.push("## Generation Context");
4587
+ lines.push(`- **Goal**: ${gc.goal}`);
4588
+ lines.push(`- **Start URL**: ${gc.startUrl}`);
4589
+ lines.push(`- **Goal Achieved (at generation)**: ${gc.goalAchieved}`);
4590
+ lines.push(`- **Generated At**: ${gc.generatedAt}`);
4591
+ lines.push(`- **Total Steps (generated)**: ${gc.totalSteps}`);
4592
+ if (gc.notes) {
4593
+ lines.push("- **Notes**:");
4594
+ for (const line of gc.notes.split("\n")) {
4595
+ lines.push(` > ${line}`);
4596
+ }
4597
+ }
4598
+ lines.push("");
4599
+ }
4600
+ if (input.errorMessage) {
4601
+ lines.push("## Error Details");
4602
+ lines.push("```");
4603
+ lines.push(input.errorMessage);
4604
+ lines.push("```");
4605
+ lines.push("");
4606
+ }
4607
+ lines.push("## Execution Summary");
4608
+ lines.push(`- **Total Steps**: ${report.totalSteps}`);
4609
+ lines.push(`- **Executed**: ${report.executed}`);
4610
+ lines.push(`- **Succeeded**: ${report.succeeded}`);
4611
+ lines.push(`- **Failed**: ${report.failed}`);
4612
+ lines.push(`- **Skipped**: ${report.skipped}`);
4613
+ lines.push(`- **Aborted**: ${report.aborted}`);
4614
+ lines.push(`- **Duration**: ${report.totalDurationMs}ms`);
4615
+ lines.push("");
4616
+ const allFlatSteps = flattenSteps(report.steps);
4617
+ const extractSteps = allFlatSteps.filter((s) => s.actionType === "extract");
4618
+ if (extractSteps.length > 0) {
4619
+ const extractFailures = extractSteps.filter((s) => s.status === "failed");
4620
+ const extractEmpty = extractSteps.filter(
4621
+ (s) => s.status === "success" && (!s.extractedData || s.extractedData === "")
4622
+ );
4623
+ const extractSuccess = extractSteps.filter(
4624
+ (s) => s.status === "success" && s.extractedData && s.extractedData !== ""
4625
+ );
4626
+ lines.push("## Extract Summary");
4627
+ lines.push("");
4628
+ lines.push(`- **Total extract steps**: ${extractSteps.length}`);
4629
+ lines.push(`- **Succeeded (with data)**: ${extractSuccess.length}`);
4630
+ lines.push(`- **Succeeded (empty result)**: ${extractEmpty.length}`);
4631
+ lines.push(`- **Failed**: ${extractFailures.length}`);
4632
+ lines.push("");
4633
+ if (extractFailures.length > 0) {
4634
+ lines.push("### Extract Failures");
4635
+ lines.push("");
4636
+ for (const step of extractFailures) {
4637
+ lines.push(`- **Step #${step.ordinal}** (${step.description}): ${step.error ?? "Unknown"}`);
4638
+ }
4639
+ lines.push("");
4640
+ }
4641
+ if (extractEmpty.length > 0) {
4642
+ lines.push("### Extract Empty Results (Warning)");
4643
+ lines.push("");
4644
+ for (const step of extractEmpty) {
4645
+ lines.push(`- **Step #${step.ordinal}** (${step.description}): Script executed but returned empty`);
4646
+ }
4647
+ lines.push("");
4648
+ }
4649
+ }
4650
+ if (report.steps.length > 0) {
4651
+ lines.push("## Step Results");
4652
+ for (const step of report.steps) {
4653
+ lines.push(...formatStepResult(step, ""));
4654
+ }
4655
+ lines.push("");
4656
+ }
4657
+ const failedSteps = report.steps.filter((s) => s.status === "failed");
4658
+ if (failedSteps.length > 0) {
4659
+ lines.push("## Failed Step Diagnostics");
4660
+ lines.push("");
4661
+ for (const step of failedSteps) {
4662
+ if (step.retryDetails && step.retryDetails.length > 0) {
4663
+ lines.push(...formatRetryDetails(step.retryDetails, step.ordinal));
4664
+ }
4665
+ if (step.diagnostics) {
4666
+ lines.push(...formatDiagnostics(step.diagnostics, step.ordinal));
4667
+ }
4668
+ if (!step.diagnostics && (!step.retryDetails || step.retryDetails.length === 0)) {
4669
+ lines.push(`### Step #${step.ordinal} \u2014 Error Info`);
4670
+ lines.push("");
4671
+ lines.push(`**Error**: ${step.error ?? "Unknown"}`);
4672
+ if (step.failureCategory) {
4673
+ lines.push(`**Category**: ${step.failureCategory}`);
4674
+ }
4675
+ lines.push("");
4676
+ }
4677
+ }
4678
+ }
4679
+ if (failedSteps.length > 0) {
4680
+ lines.push(...formatAiAgentSummary(failedSteps, input));
4681
+ }
4682
+ const debugEntries = input.debugLogPath ? await readDebugLog(input.debugLogPath) : [];
4683
+ lines.push(...formatSystemInsights(report, debugEntries, input.telemetryStats));
4684
+ const failedOrdinals = new Set(failedSteps.map((s) => s.ordinal));
4685
+ lines.push(...formatDebugLogSections(debugEntries, {
4686
+ showFailedStepEvents: true,
4687
+ failedOrdinals
4688
+ }));
4689
+ return lines.join("\n");
4690
+ }
4691
+
4155
4692
  // src/messaging/cards.ts
4156
4693
  import {
4157
4694
  Card,
@@ -4422,6 +4959,7 @@ export {
4422
4959
  buildNotificationCard,
4423
4960
  buildDebugNotificationCard,
4424
4961
  buildGenerateNotificationCard,
4425
- analyzeDebugResult
4962
+ analyzeDebugResult,
4963
+ generateExecutionReportFile
4426
4964
  };
4427
- //# sourceMappingURL=chunk-H47NWH7N.js.map
4965
+ //# sourceMappingURL=chunk-AOCGSFRM.js.map