@zhongqian97-code/ecode 0.5.8 → 0.5.10

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 (2) hide show
  1. package/dist/index.js +955 -42
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3,11 +3,11 @@ const _ew=process.emitWarning.bind(process);process.emitWarning=function(w,...a)
3
3
 
4
4
  // src/index.ts
5
5
  import { createRequire } from "module";
6
- import { resolve as resolve4, dirname as dirname7 } from "path";
7
- import { fileURLToPath } from "url";
6
+ import { resolve as resolve5, dirname as dirname9 } from "path";
7
+ import { fileURLToPath as fileURLToPath2 } from "url";
8
8
  import React4 from "react";
9
9
  import { render } from "ink";
10
- import { readFileSync as readFileSync3 } from "fs";
10
+ import { readFileSync as readFileSync5 } from "fs";
11
11
 
12
12
  // src/config.ts
13
13
  import { existsSync, readFileSync } from "fs";
@@ -540,13 +540,13 @@ function classifyCommand(cmd, dangerPatterns, _depth = 0) {
540
540
  import { exec } from "child_process";
541
541
  var DEFAULT_TIMEOUT_MS = 3e4;
542
542
  function executeBash(cmd, timeoutMs = DEFAULT_TIMEOUT_MS) {
543
- return new Promise((resolve5) => {
543
+ return new Promise((resolve6) => {
544
544
  exec(cmd, { timeout: timeoutMs }, (err, stdout, stderr) => {
545
545
  if (err) {
546
546
  const exitCode = err.code ?? 1;
547
- resolve5({ stdout: stdout ?? "", stderr: stderr ?? "", exitCode });
547
+ resolve6({ stdout: stdout ?? "", stderr: stderr ?? "", exitCode });
548
548
  } else {
549
- resolve5({ stdout: stdout ?? "", stderr: stderr ?? "", exitCode: 0 });
549
+ resolve6({ stdout: stdout ?? "", stderr: stderr ?? "", exitCode: 0 });
550
550
  }
551
551
  });
552
552
  });
@@ -571,13 +571,13 @@ var READ_TOOL = {
571
571
  }
572
572
  };
573
573
  async function readFile2(params) {
574
- const { path: path9, offset = 0, limit } = params;
574
+ const { path: path11, offset = 0, limit } = params;
575
575
  let raw;
576
576
  try {
577
- raw = await fs.readFile(path9, "utf8");
577
+ raw = await fs.readFile(path11, "utf8");
578
578
  } catch (err) {
579
579
  const msg = err instanceof Error ? err.message : String(err);
580
- return `Error reading ${path9}: ${msg}`;
580
+ return `Error reading ${path11}: ${msg}`;
581
581
  }
582
582
  const lines = raw.split("\n");
583
583
  const sliced = limit !== void 0 ? lines.slice(offset, offset + limit) : lines.slice(offset);
@@ -633,28 +633,28 @@ var EDIT_TOOL = {
633
633
  }
634
634
  };
635
635
  async function editFile(params) {
636
- const { path: path9, old_string, new_string } = params;
636
+ const { path: path11, old_string, new_string } = params;
637
637
  let content;
638
638
  try {
639
- content = await fs3.readFile(path9, "utf8");
639
+ content = await fs3.readFile(path11, "utf8");
640
640
  } catch (err) {
641
641
  const msg = err instanceof Error ? err.message : String(err);
642
- return `Error reading ${path9}: ${msg}`;
642
+ return `Error reading ${path11}: ${msg}`;
643
643
  }
644
644
  const count = countOccurrences(content, old_string);
645
645
  if (count === 0) {
646
- return `Error: old_string not found in ${path9}`;
646
+ return `Error: old_string not found in ${path11}`;
647
647
  }
648
648
  if (count > 1) {
649
- return `Error: old_string appears ${count} times in ${path9} (ambiguous \u2014 add more context)`;
649
+ return `Error: old_string appears ${count} times in ${path11} (ambiguous \u2014 add more context)`;
650
650
  }
651
651
  const updated = content.replace(old_string, new_string);
652
652
  try {
653
- await fs3.writeFile(path9, updated, "utf8");
654
- return `Edited ${path9}`;
653
+ await fs3.writeFile(path11, updated, "utf8");
654
+ return `Edited ${path11}`;
655
655
  } catch (err) {
656
656
  const msg = err instanceof Error ? err.message : String(err);
657
- return `Error writing ${path9}: ${msg}`;
657
+ return `Error writing ${path11}: ${msg}`;
658
658
  }
659
659
  }
660
660
  function countOccurrences(haystack, needle) {
@@ -2169,8 +2169,8 @@ function parseMouseScroll(data) {
2169
2169
  }
2170
2170
 
2171
2171
  // src/ui/App.tsx
2172
- import { homedir as homedir2 } from "os";
2173
- import { join as join10 } from "path";
2172
+ import { homedir as homedir3 } from "os";
2173
+ import { join as join11 } from "path";
2174
2174
 
2175
2175
  // src/automation/store.ts
2176
2176
  import { readFile as readFile8, writeFile as writeFile5, mkdir as mkdir2 } from "fs/promises";
@@ -2268,11 +2268,17 @@ async function executeJob(job, config2) {
2268
2268
 
2269
2269
  // src/automation/goal/evaluator.ts
2270
2270
  function parseVerdict(response) {
2271
- const lower = response.toLowerCase();
2272
- if (lower.includes("not_done")) return "not_done";
2273
- if (lower.includes("blocked")) return "blocked";
2274
- if (lower.includes("done")) return "done";
2275
- return "not_done";
2271
+ const scan = (text) => {
2272
+ if (/\bnot_done\b/.test(text)) return "not_done";
2273
+ if (/\bblocked\b/.test(text) && !/\bnot\s+blocked\b/.test(text)) return "blocked";
2274
+ if (/\bdone\b/.test(text) && !/\bnot\s+done\b/.test(text)) return "done";
2275
+ return null;
2276
+ };
2277
+ const firstLine = (response.split("\n")[0] ?? "").trim().toLowerCase();
2278
+ const fromFirstLine = scan(firstLine);
2279
+ if (fromFirstLine !== null) return fromFirstLine;
2280
+ const fromFull = scan(response.toLowerCase());
2281
+ return fromFull ?? "not_done";
2276
2282
  }
2277
2283
  function buildPrompt(input) {
2278
2284
  return [
@@ -2492,6 +2498,15 @@ async function cmdLoop(args, deps) {
2492
2498
  intervalMs = parsed.intervalMs;
2493
2499
  prompt = trimmed.slice(spaceIdx + 1).trim();
2494
2500
  }
2501
+ } else {
2502
+ const parsed = parseInterval(trimmed);
2503
+ if (parsed !== null) {
2504
+ intervalMs = parsed.intervalMs;
2505
+ prompt = "";
2506
+ }
2507
+ }
2508
+ if (!prompt.trim()) {
2509
+ return "\u7528\u6CD5\uFF1A/loop [interval] <prompt>\uFF0C\u4F8B\u5982\uFF1A/loop 10m \u68C0\u67E5 deploy \u72B6\u6001";
2495
2510
  }
2496
2511
  const now = /* @__PURE__ */ new Date();
2497
2512
  const job = {
@@ -2542,6 +2557,9 @@ async function cmdUnloop(idOrPrefix, deps) {
2542
2557
  import { randomUUID as randomUUID3 } from "crypto";
2543
2558
  async function cmdGoal(args, deps) {
2544
2559
  const condition = args.trim();
2560
+ if (!condition) {
2561
+ return "\u7528\u6CD5\uFF1A/goal <\u76EE\u6807\u6761\u4EF6>\uFF0C\u4F8B\u5982\uFF1A/goal \u6240\u6709\u6D4B\u8BD5\u901A\u8FC7";
2562
+ }
2545
2563
  const now = /* @__PURE__ */ new Date();
2546
2564
  const job = {
2547
2565
  id: randomUUID3(),
@@ -2784,11 +2802,11 @@ var AutomationManager = class {
2784
2802
  job.id,
2785
2803
  `[goal ${job.id.slice(0, 8)}] \u7B2C ${job.activeTurnCount} \u8F6E\uFF1A\u5C1A\u672A\u5B8C\u6210\uFF0C\u7EE7\u7EED\u6267\u884C\u2026`
2786
2804
  );
2787
- await new Promise((resolve5) => {
2788
- const timer = setTimeout(resolve5, 5e3);
2805
+ await new Promise((resolve6) => {
2806
+ const timer = setTimeout(resolve6, 5e3);
2789
2807
  signal.addEventListener("abort", () => {
2790
2808
  clearTimeout(timer);
2791
- resolve5();
2809
+ resolve6();
2792
2810
  }, { once: true });
2793
2811
  });
2794
2812
  }
@@ -2874,6 +2892,801 @@ function generateTitle(firstUserMessage) {
2874
2892
  return oneLine.length > 50 ? oneLine.slice(0, 47) + "..." : oneLine;
2875
2893
  }
2876
2894
 
2895
+ // src/meta_skill/index.ts
2896
+ import * as fs11 from "fs";
2897
+ import * as path9 from "path";
2898
+ import { fileURLToPath } from "url";
2899
+
2900
+ // src/meta_skill/task-classifier.ts
2901
+ var RULES = {
2902
+ bugfix: [
2903
+ { pattern: /(?<!\w)(bug|fix|修复|修bug|defect|error|crash|exception|broken|fails?|失败|报错|崩溃|异常|问题|故障|incorrect|wrong|不对|不正确)(?!\w)/i, weight: 3 },
2904
+ { pattern: /(?<!\w)(debug|diagnose|诊断|定位|追踪|trace|reproduce|复现)(?!\w)/i, weight: 2 },
2905
+ { pattern: /(?<!\w)(regression|revert|回归|回滚)(?!\w)/i, weight: 1 }
2906
+ ],
2907
+ refactor: [
2908
+ { pattern: /(?<!\w)(refactor|重构|重写|rewrite|restructure|重新设计|clean ?up|清理|整理|simplify|简化|extract|提取|split|拆分)(?!\w)/i, weight: 3 },
2909
+ { pattern: /(?<!\w)(maintainability|可维护|readability|可读性|code smell|技术债|tech debt|coupling|耦合|cohesion|内聚)(?!\w)/i, weight: 2 },
2910
+ { pattern: /(?<!\w)(rename|move|organize|抽象|abstraction)(?!\w)/i, weight: 1 }
2911
+ ],
2912
+ "test-generation": [
2913
+ { pattern: /(?<!\w)(tests?|测试|specs?|单元测试|unit tests?|coverage|覆盖率|vitest|jest|mocha|e2e|integration)(?!\w)/i, weight: 3 },
2914
+ { pattern: /(?<!\w)(assert|验证|verify|tdd|red.green)(?!\w)/i, weight: 2 },
2915
+ { pattern: /(?<!\w)(mock|stub|fixture|测试用例|用例)(?!\w)/i, weight: 1 }
2916
+ ],
2917
+ "code-review": [
2918
+ { pattern: /(?<!\w)(review|审查|审阅|代码审查|audit|安全审计|inspect)(?!\w)/i, weight: 3 },
2919
+ { pattern: /(?<!\w)(quality|质量|best practice|最佳实践|standard|规范|convention|smell)(?!\w)/i, weight: 2 },
2920
+ { pattern: /(?<!\w)(feedback|意见|suggestion|建议|comment|注释)(?!\w)/i, weight: 1 }
2921
+ ],
2922
+ "code-reverse-design": [
2923
+ { pattern: /(?<!\w)(reverse|逆向|理解|understand|architecture|架构|design doc|设计文档|document|文档化|逆向工程)(?!\w)/i, weight: 3 },
2924
+ { pattern: /(?<!\w)(analyze|分析|explore|探索|overview|概览|structure|结构|module|模块|dependency|依赖)(?!\w)/i, weight: 2 },
2925
+ { pattern: /(?<!\w)(prd|需求|规格|diagram|图表|flowchart|流程图)(?!\w)/i, weight: 1 }
2926
+ ]
2927
+ };
2928
+ var PRIORITY = [
2929
+ "bugfix",
2930
+ "test-generation",
2931
+ "refactor",
2932
+ "code-review",
2933
+ "code-reverse-design"
2934
+ ];
2935
+ function classifyTask(goal, fallback = "code-review") {
2936
+ const scores = {
2937
+ bugfix: 0,
2938
+ refactor: 0,
2939
+ "test-generation": 0,
2940
+ "code-review": 0,
2941
+ "code-reverse-design": 0
2942
+ };
2943
+ for (const [type, rules] of Object.entries(RULES)) {
2944
+ for (const { pattern, weight } of rules) {
2945
+ if (pattern.test(goal)) {
2946
+ scores[type] += weight;
2947
+ }
2948
+ }
2949
+ }
2950
+ let bestType = fallback;
2951
+ let bestScore = 0;
2952
+ for (const type of PRIORITY) {
2953
+ const s = scores[type];
2954
+ if (s > bestScore) {
2955
+ bestScore = s;
2956
+ bestType = type;
2957
+ }
2958
+ }
2959
+ return bestType;
2960
+ }
2961
+ function isValidTaskType(value) {
2962
+ return ["bugfix", "refactor", "test-generation", "code-review", "code-reverse-design"].includes(value);
2963
+ }
2964
+
2965
+ // src/meta_skill/skill-survey.ts
2966
+ var BASELINE_MAP = {
2967
+ "bugfix": ["diagnose", "tdd"],
2968
+ "refactor": ["search-first", "plan", "improve-codebase-architecture"],
2969
+ "test-generation": ["tdd"],
2970
+ "code-review": ["zoom-out", "search-first", "security-review"],
2971
+ "code-reverse-design": ["zoom-out", "plan", "to-prd"]
2972
+ };
2973
+ function getBaselineSkills(taskType) {
2974
+ return [...BASELINE_MAP[taskType] ?? []];
2975
+ }
2976
+
2977
+ // src/meta_skill/workflow-extractor.ts
2978
+ var NUMBERED_HEADINGS_RE = /^#{1,4}\s+(?:Step\s+|Phase\s+)?(\d+)[.:\-–—\s]+(.+)$/gim;
2979
+ var NUMBERED_LIST_RE = /^\s*(\d+)\.\s+(.{10,})$/gm;
2980
+ var MAX_STEPS = 12;
2981
+ function extractWorkflowSteps(body) {
2982
+ if (!body.trim()) return [];
2983
+ const headingSteps = extractHeadingSteps(body);
2984
+ if (headingSteps.length >= 2) {
2985
+ return headingSteps.slice(0, MAX_STEPS);
2986
+ }
2987
+ const listSteps = extractListSteps(body);
2988
+ if (listSteps.length >= 2) {
2989
+ return listSteps.slice(0, MAX_STEPS);
2990
+ }
2991
+ return extractParagraphSteps(body);
2992
+ }
2993
+ function extractHeadingSteps(body) {
2994
+ const steps = [];
2995
+ let match;
2996
+ NUMBERED_HEADINGS_RE.lastIndex = 0;
2997
+ while ((match = NUMBERED_HEADINGS_RE.exec(body)) !== null) {
2998
+ const text = match[2]?.trim();
2999
+ if (text) steps.push(cleanStepText(text));
3000
+ }
3001
+ return steps;
3002
+ }
3003
+ function extractListSteps(body) {
3004
+ const steps = [];
3005
+ NUMBERED_LIST_RE.lastIndex = 0;
3006
+ let match;
3007
+ while ((match = NUMBERED_LIST_RE.exec(body)) !== null) {
3008
+ const text = match[2]?.trim();
3009
+ if (text) steps.push(cleanStepText(text));
3010
+ }
3011
+ return steps;
3012
+ }
3013
+ function extractParagraphSteps(body) {
3014
+ return body.split(/\n{2,}/).map((para) => para.trim().split("\n")[0]?.trim() ?? "").filter((line) => line.length > 10 && !line.startsWith("#")).slice(0, MAX_STEPS).map(cleanStepText);
3015
+ }
3016
+ function cleanStepText(text) {
3017
+ return text.replace(/\*{1,2}([^*]+)\*{1,2}/g, "$1").replace(/`([^`]+)`/g, "$1").replace(/\s+/g, " ").trim();
3018
+ }
3019
+
3020
+ // src/meta_skill/profile-store.ts
3021
+ var GPT4O = {
3022
+ model: "gpt-4o",
3023
+ traits: {
3024
+ instructionFollowing: "high",
3025
+ schemaDiscipline: "high",
3026
+ longContextStability: "high",
3027
+ multiStepStability: "high",
3028
+ hallucinationRisk: "low",
3029
+ selfCorrection: "high"
3030
+ },
3031
+ preferences: {
3032
+ promptStyle: "freeform",
3033
+ contextOrder: "goal-first",
3034
+ stepSize: "large",
3035
+ needsExamples: false,
3036
+ needsStopConditions: false
3037
+ },
3038
+ antiPatterns: [
3039
+ "\u8FC7\u5EA6\u7EA6\u675F\u8F93\u51FA\u683C\u5F0F\u4F1A\u6291\u5236\u63A8\u7406\u8D28\u91CF",
3040
+ "\u4E0D\u5FC5\u8981\u7684 chain-of-thought \u5F3A\u5236\u589E\u52A0 token \u6D88\u8017"
3041
+ ]
3042
+ };
3043
+ var GPT4O_MINI = {
3044
+ model: "gpt-4o-mini",
3045
+ traits: {
3046
+ instructionFollowing: "medium",
3047
+ schemaDiscipline: "medium",
3048
+ longContextStability: "medium",
3049
+ multiStepStability: "medium",
3050
+ hallucinationRisk: "medium",
3051
+ selfCorrection: "medium"
3052
+ },
3053
+ preferences: {
3054
+ promptStyle: "explicit-checklist",
3055
+ contextOrder: "goal-first",
3056
+ stepSize: "small",
3057
+ needsExamples: true,
3058
+ needsStopConditions: true
3059
+ },
3060
+ antiPatterns: [
3061
+ "\u5355\u6B21\u4F20\u5165\u8D85\u8FC7 10 \u4E2A\u6587\u4EF6\u5185\u5BB9\u5BB9\u6613\u4E22\u5931\u7EC6\u8282",
3062
+ "\u5F00\u653E\u5F0F\u4EFB\u52A1\u5BB9\u6613\u751F\u6210\u5197\u4F59\u5185\u5BB9"
3063
+ ]
3064
+ };
3065
+ var DEEPSEEK_CHAT = {
3066
+ model: "deepseek-chat",
3067
+ traits: {
3068
+ instructionFollowing: "high",
3069
+ schemaDiscipline: "medium",
3070
+ longContextStability: "medium",
3071
+ multiStepStability: "medium",
3072
+ hallucinationRisk: "medium",
3073
+ selfCorrection: "medium"
3074
+ },
3075
+ preferences: {
3076
+ promptStyle: "explicit-checklist",
3077
+ contextOrder: "goal-first",
3078
+ stepSize: "medium",
3079
+ needsExamples: true,
3080
+ needsStopConditions: false
3081
+ },
3082
+ antiPatterns: [
3083
+ "\u957F\u4E0A\u4E0B\u6587\uFF08>32K token\uFF09\u65F6\u8F93\u51FA\u7A33\u5B9A\u6027\u4E0B\u964D",
3084
+ "\u591A\u6B65\u590D\u6742\u63A8\u7406\u94FE\u4E2D\u9014\u5BB9\u6613\u504F\u79BB\u76EE\u6807"
3085
+ ]
3086
+ };
3087
+ var DEEPSEEK_REASONER = {
3088
+ model: "deepseek-reasoner",
3089
+ traits: {
3090
+ instructionFollowing: "high",
3091
+ schemaDiscipline: "medium",
3092
+ longContextStability: "medium",
3093
+ multiStepStability: "high",
3094
+ hallucinationRisk: "low",
3095
+ selfCorrection: "high"
3096
+ },
3097
+ preferences: {
3098
+ promptStyle: "freeform",
3099
+ contextOrder: "goal-first",
3100
+ stepSize: "large",
3101
+ needsExamples: false,
3102
+ needsStopConditions: false
3103
+ },
3104
+ antiPatterns: [
3105
+ "\u8FC7\u5EA6\u7EA6\u675F\u63A8\u7406\u6B65\u9AA4\u683C\u5F0F\u4F1A\u5E72\u6270\u5185\u90E8\u601D\u8003\u94FE",
3106
+ "\u4E0D\u9002\u5408\u7EAF\u68C0\u7D22\u7C7B\u4EFB\u52A1\uFF08\u63A8\u7406\u5F00\u9500\u8FDC\u5927\u4E8E\u6536\u76CA\uFF09"
3107
+ ]
3108
+ };
3109
+ var MINIMAX_M25 = {
3110
+ model: "MiniMax-M2.5",
3111
+ traits: {
3112
+ instructionFollowing: "medium",
3113
+ schemaDiscipline: "low",
3114
+ longContextStability: "high",
3115
+ // 百万 token 上下文
3116
+ multiStepStability: "medium",
3117
+ hallucinationRisk: "medium",
3118
+ selfCorrection: "low"
3119
+ },
3120
+ preferences: {
3121
+ promptStyle: "strict-template",
3122
+ contextOrder: "template-first",
3123
+ stepSize: "small",
3124
+ needsExamples: true,
3125
+ needsStopConditions: true
3126
+ },
3127
+ antiPatterns: [
3128
+ "\u81EA\u7531\u683C\u5F0F\u8F93\u51FA\u5BB9\u6613\u4EA7\u751F\u5197\u4F59\u6216\u683C\u5F0F\u6DF7\u4E71",
3129
+ "\u7F3A\u4E4F\u660E\u786E\u505C\u6B62\u6761\u4EF6\u65F6\u5BB9\u6613\u8FC7\u5EA6\u8F93\u51FA",
3130
+ "\u590D\u6742\u63A8\u7406\u94FE\u9700\u8981\u66F4\u7EC6\u7C92\u5EA6\u7684\u6B65\u9AA4\u62C6\u5206"
3131
+ ]
3132
+ };
3133
+ var MINIMAX_M25_HS = {
3134
+ ...MINIMAX_M25,
3135
+ model: "MiniMax-M2.5-highspeed"
3136
+ };
3137
+ var CLAUDE_SONNET = {
3138
+ model: "claude-sonnet-4-6",
3139
+ traits: {
3140
+ instructionFollowing: "high",
3141
+ schemaDiscipline: "high",
3142
+ longContextStability: "high",
3143
+ multiStepStability: "high",
3144
+ hallucinationRisk: "low",
3145
+ selfCorrection: "high"
3146
+ },
3147
+ preferences: {
3148
+ promptStyle: "freeform",
3149
+ contextOrder: "goal-first",
3150
+ stepSize: "large",
3151
+ needsExamples: false,
3152
+ needsStopConditions: false
3153
+ },
3154
+ antiPatterns: [
3155
+ "\u8FC7\u5EA6\u6307\u5B9A\u8F93\u51FA\u683C\u5F0F\u53EF\u80FD\u6291\u5236\u81EA\u7136\u63A8\u7406"
3156
+ ]
3157
+ };
3158
+ var CLAUDE_OPUS = {
3159
+ ...CLAUDE_SONNET,
3160
+ model: "claude-opus-4-7"
3161
+ };
3162
+ var CLAUDE_HAIKU = {
3163
+ model: "claude-haiku-4-5-20251001",
3164
+ traits: {
3165
+ instructionFollowing: "high",
3166
+ schemaDiscipline: "high",
3167
+ longContextStability: "high",
3168
+ multiStepStability: "medium",
3169
+ hallucinationRisk: "low",
3170
+ selfCorrection: "medium"
3171
+ },
3172
+ preferences: {
3173
+ promptStyle: "explicit-checklist",
3174
+ contextOrder: "goal-first",
3175
+ stepSize: "medium",
3176
+ needsExamples: false,
3177
+ needsStopConditions: false
3178
+ },
3179
+ antiPatterns: [
3180
+ "\u6DF1\u5EA6\u63A8\u7406\u4EFB\u52A1\u8D85\u51FA\u80FD\u529B\u8FB9\u754C\u65F6\u5E94 escalate \u5230 Sonnet/Opus"
3181
+ ]
3182
+ };
3183
+ var DEFAULT_PROFILE = {
3184
+ model: "unknown",
3185
+ traits: {
3186
+ instructionFollowing: "medium",
3187
+ schemaDiscipline: "medium",
3188
+ longContextStability: "medium",
3189
+ multiStepStability: "medium",
3190
+ hallucinationRisk: "medium",
3191
+ selfCorrection: "medium"
3192
+ },
3193
+ preferences: {
3194
+ promptStyle: "explicit-checklist",
3195
+ contextOrder: "goal-first",
3196
+ stepSize: "small",
3197
+ needsExamples: true,
3198
+ needsStopConditions: true
3199
+ },
3200
+ antiPatterns: []
3201
+ };
3202
+ var PROFILE_MAP = {
3203
+ "gpt-4o": GPT4O,
3204
+ "gpt-4o-mini": GPT4O_MINI,
3205
+ "deepseek-chat": DEEPSEEK_CHAT,
3206
+ "deepseek-reasoner": DEEPSEEK_REASONER,
3207
+ "MiniMax-M2.5": MINIMAX_M25,
3208
+ "MiniMax-M2.5-highspeed": MINIMAX_M25_HS,
3209
+ "claude-sonnet-4-6": CLAUDE_SONNET,
3210
+ "claude-opus-4-7": CLAUDE_OPUS,
3211
+ "claude-haiku-4-5-20251001": CLAUDE_HAIKU,
3212
+ // 历史别名
3213
+ "claude-3-5-sonnet-20241022": { ...CLAUDE_SONNET, model: "claude-3-5-sonnet-20241022" },
3214
+ "claude-3-5-haiku-20241022": { ...CLAUDE_HAIKU, model: "claude-3-5-haiku-20241022" }
3215
+ };
3216
+ function getModelProfile(modelName) {
3217
+ const exact = PROFILE_MAP[modelName];
3218
+ if (exact) return exact;
3219
+ for (const [key, profile] of Object.entries(PROFILE_MAP)) {
3220
+ if (modelName.startsWith(key) || key.startsWith(modelName)) {
3221
+ return { ...profile, model: modelName };
3222
+ }
3223
+ }
3224
+ return { ...DEFAULT_PROFILE, model: modelName };
3225
+ }
3226
+
3227
+ // src/meta_skill/recipe-resolver.ts
3228
+ function resolveInputStyle(promptStyle) {
3229
+ return promptStyle;
3230
+ }
3231
+ function resolveGranularity(stepSize) {
3232
+ switch (stepSize) {
3233
+ case "large":
3234
+ return "large-batch";
3235
+ case "small":
3236
+ return "stepwise";
3237
+ case "medium":
3238
+ default:
3239
+ return "file-level-first";
3240
+ }
3241
+ }
3242
+ function resolveOutputFormat(promptStyle) {
3243
+ switch (promptStyle) {
3244
+ case "strict-template":
3245
+ return "strict-template";
3246
+ case "explicit-checklist":
3247
+ return "template";
3248
+ case "freeform":
3249
+ default:
3250
+ return "freeform";
3251
+ }
3252
+ }
3253
+ function resolveContextStrategy(contextOrder) {
3254
+ switch (contextOrder) {
3255
+ case "goal-first":
3256
+ return "\u5148\u7ED9\u51FA\u4EFB\u52A1\u76EE\u6807\uFF0C\u518D\u9644\u4E0A\u4EE3\u7801\u6750\u6599\uFF0C\u6700\u540E\u7EA6\u675F\u8F93\u51FA\u683C\u5F0F";
3257
+ case "template-first":
3258
+ return "\u5148\u7ED9\u51FA\u8F93\u51FA\u6A21\u677F\uFF0C\u518D\u63CF\u8FF0\u4EFB\u52A1\uFF0C\u6700\u540E\u9644\u4E0A\u6750\u6599";
3259
+ default:
3260
+ return "\u5148\u9644\u4E0A\u6240\u6709\u76F8\u5173\u6750\u6599\uFF0C\u518D\u7ED9\u51FA\u4EFB\u52A1\u76EE\u6807";
3261
+ }
3262
+ }
3263
+ function resolveVerificationStyle(selfCorrection, hallucinationRisk) {
3264
+ if (selfCorrection === "high" && hallucinationRisk === "low") {
3265
+ return "\u81EA\u6821\u9A8C\uFF1A\u8981\u6C42\u6A21\u578B\u5217\u51FA\u7F6E\u4FE1\u5EA6\u4F4E\u7684\u7ED3\u8BBA";
3266
+ }
3267
+ if (hallucinationRisk === "high") {
3268
+ return "\u5F3A\u9A8C\u8BC1\uFF1A\u8981\u6C42\u5F15\u7528\u4EE3\u7801\u884C\u53F7\u4F5C\u4E3A\u6BCF\u6761\u7ED3\u8BBA\u7684\u8BC1\u636E";
3269
+ }
3270
+ return "\u8F7B\u9A8C\u8BC1\uFF1A\u8F93\u51FA\u7ED3\u8BBA\u540E\u7528\u793A\u4F8B\u4EE3\u7801\u7247\u6BB5\u786E\u8BA4";
3271
+ }
3272
+ function resolveFailureModes(profile, taskType) {
3273
+ const modes = [...profile.antiPatterns];
3274
+ if (profile.traits.longContextStability === "low" || profile.traits.longContextStability === "medium") {
3275
+ modes.push("\u957F\u4E0A\u4E0B\u6587\u65F6\u53EF\u80FD\u4E22\u5931\u65E9\u671F\u6307\u4EE4");
3276
+ }
3277
+ if (profile.traits.multiStepStability === "low") {
3278
+ modes.push("\u591A\u6B65\u63A8\u7406\u4E2D\u9014\u53EF\u80FD\u504F\u79BB\u76EE\u6807");
3279
+ }
3280
+ if (taskType === "bugfix") {
3281
+ modes.push("\u53EF\u80FD\u4FEE\u590D\u75C7\u72B6\u800C\u975E\u6839\u672C\u539F\u56E0");
3282
+ modes.push("\u5728\u7F3A\u4E4F\u5B8C\u6574\u4E0A\u4E0B\u6587\u65F6\u6613\u8BEF\u5224 bug \u6240\u5728\u4F4D\u7F6E");
3283
+ }
3284
+ if (taskType === "code-review") {
3285
+ modes.push("\u53EF\u80FD\u53EA\u5173\u6CE8\u4EE3\u7801\u98CE\u683C\u800C\u5FFD\u7565\u903B\u8F91\u7F3A\u9677");
3286
+ modes.push("\u5BF9\u590D\u6742\u4E1A\u52A1\u903B\u8F91\u7684\u8BC4\u5BA1\u6DF1\u5EA6\u4E0D\u8DB3");
3287
+ }
3288
+ return modes;
3289
+ }
3290
+ function resolveRepairStrategies(profile) {
3291
+ const strategies = [];
3292
+ if (profile.traits.multiStepStability === "low" || profile.traits.multiStepStability === "medium") {
3293
+ strategies.push("\u5C06\u4EFB\u52A1\u62C6\u5206\u4E3A\u66F4\u5C0F\u7684\u72EC\u7ACB\u6B65\u9AA4\u540E\u9010\u4E00\u91CD\u8BD5");
3294
+ }
3295
+ if (profile.traits.hallucinationRisk === "high") {
3296
+ strategies.push("\u8981\u6C42\u6A21\u578B\u5728\u91CD\u8BD5\u65F6\u4E3A\u6BCF\u6761\u7ED3\u8BBA\u9644\u4E0A\u4EE3\u7801\u884C\u53F7\u5F15\u7528");
3297
+ }
3298
+ if (profile.preferences.needsStopConditions) {
3299
+ strategies.push("\u5728\u91CD\u8BD5 prompt \u4E2D\u8865\u5145\u660E\u786E\u7684\u5B8C\u6210\u5224\u65AD\u6761\u4EF6\uFF0C\u907F\u514D\u6A21\u578B\u65E0\u9650\u5EF6\u4F38");
3300
+ }
3301
+ if (profile.traits.selfCorrection !== "high") {
3302
+ strategies.push("\u81EA\u52A8\u89E6\u53D1\u5916\u90E8 judge \u5BF9\u8F93\u51FA\u8FDB\u884C\u4E8C\u6B21\u6838\u9A8C\uFF0C\u518D\u51B3\u5B9A\u662F\u5426\u63A5\u53D7\u7ED3\u679C");
3303
+ }
3304
+ return strategies;
3305
+ }
3306
+ function resolveMaxRepeatedFailures(selfCorrection) {
3307
+ return selfCorrection === "high" ? 3 : 2;
3308
+ }
3309
+ function resolveRecipe(profile, taskType, baselineWorkflow, inheritedSkills) {
3310
+ return {
3311
+ model: profile.model,
3312
+ taskType,
3313
+ inheritedSkills,
3314
+ baselineWorkflow,
3315
+ inputStyle: resolveInputStyle(profile.preferences.promptStyle),
3316
+ contextStrategy: resolveContextStrategy(profile.preferences.contextOrder),
3317
+ granularity: resolveGranularity(profile.preferences.stepSize),
3318
+ outputContract: {
3319
+ format: resolveOutputFormat(profile.preferences.promptStyle),
3320
+ mustCiteEvidence: profile.traits.hallucinationRisk !== "low",
3321
+ mustListUncertainty: profile.traits.selfCorrection !== "high"
3322
+ },
3323
+ verificationStyle: resolveVerificationStyle(
3324
+ profile.traits.selfCorrection,
3325
+ profile.traits.hallucinationRisk
3326
+ ),
3327
+ failureModes: resolveFailureModes(profile, taskType),
3328
+ repairStrategies: resolveRepairStrategies(profile),
3329
+ escalationThreshold: {
3330
+ maxRepeatedFailures: resolveMaxRepeatedFailures(
3331
+ profile.traits.selfCorrection
3332
+ ),
3333
+ criticalFailures: [
3334
+ "\u8F93\u51FA\u4E3A\u7A7A",
3335
+ "\u65E0\u6CD5\u7406\u89E3\u4EFB\u52A1\u76EE\u6807",
3336
+ "\u5FAA\u73AF\u91CD\u590D\u76F8\u540C\u5185\u5BB9\u8D85\u8FC7 2 \u6B21"
3337
+ ]
3338
+ }
3339
+ };
3340
+ }
3341
+
3342
+ // src/meta_skill/policy-builder.ts
3343
+ function buildContextOrder(contextStrategy, granularity, constraints, paths) {
3344
+ const hasConstraints = Boolean(constraints && constraints.length > 0);
3345
+ const hasPaths = Boolean(paths && paths.length > 0);
3346
+ let order;
3347
+ if (contextStrategy.includes("\u5148\u7ED9\u51FA\u4EFB\u52A1\u76EE\u6807")) {
3348
+ order = ["\u4EFB\u52A1\u76EE\u6807"];
3349
+ if (hasConstraints) order.push("\u7EA6\u675F\u6761\u4EF6");
3350
+ if (hasPaths) order.push("\u4EE3\u7801\u6750\u6599");
3351
+ order.push("\u8F93\u51FA\u683C\u5F0F\u8981\u6C42");
3352
+ } else if (contextStrategy.includes("\u5148\u7ED9\u51FA\u8F93\u51FA\u6A21\u677F")) {
3353
+ order = ["\u8F93\u51FA\u683C\u5F0F\u8981\u6C42", "\u4EFB\u52A1\u76EE\u6807"];
3354
+ if (hasConstraints) order.push("\u7EA6\u675F\u6761\u4EF6");
3355
+ if (hasPaths) order.push("\u4EE3\u7801\u6750\u6599");
3356
+ } else {
3357
+ order = [];
3358
+ if (hasPaths) order.push("\u4EE3\u7801\u6750\u6599");
3359
+ order.push("\u4EFB\u52A1\u76EE\u6807");
3360
+ if (hasConstraints) order.push("\u7EA6\u675F\u6761\u4EF6");
3361
+ order.push("\u8F93\u51FA\u683C\u5F0F\u8981\u6C42");
3362
+ }
3363
+ if (granularity === "stepwise") {
3364
+ order = order.filter((item) => item !== "\u4EFB\u52A1\u76EE\u6807");
3365
+ order = ["\u4EFB\u52A1\u76EE\u6807", ...order];
3366
+ if (!order.includes("\u5DE5\u4F5C\u6D41\u6B65\u9AA4")) order.push("\u5DE5\u4F5C\u6D41\u6B65\u9AA4");
3367
+ order = order.filter((item) => item !== "\u8F93\u51FA\u683C\u5F0F\u8981\u6C42");
3368
+ order.push("\u8F93\u51FA\u683C\u5F0F\u8981\u6C42");
3369
+ }
3370
+ return order;
3371
+ }
3372
+ function resolveMaxMaterials(granularity) {
3373
+ const map = {
3374
+ "large-batch": 10,
3375
+ "file-level-first": 5,
3376
+ "small-batch": 3,
3377
+ stepwise: 2
3378
+ };
3379
+ return map[granularity];
3380
+ }
3381
+ function buildPolicy(recipe, input) {
3382
+ const maxSteps = input.runtimeContext?.budget?.maxSteps ?? 8;
3383
+ const stepPlan = recipe.baselineWorkflow.slice(0, maxSteps);
3384
+ const mode = stepPlan.length > 1 ? "multi_step" : "single_step";
3385
+ const order = buildContextOrder(
3386
+ recipe.contextStrategy,
3387
+ recipe.granularity,
3388
+ input.task.constraints,
3389
+ input.task.scope?.paths
3390
+ );
3391
+ const maxMaterialsPerStep = resolveMaxMaterials(recipe.granularity);
3392
+ return {
3393
+ mode,
3394
+ stepPlan,
3395
+ selectedSkills: recipe.inheritedSkills,
3396
+ contextPackaging: {
3397
+ order,
3398
+ maxMaterialsPerStep
3399
+ },
3400
+ outputContract: { ...recipe.outputContract },
3401
+ revisionPolicy: {
3402
+ maxRetries: recipe.escalationThreshold.maxRepeatedFailures,
3403
+ retryStyle: recipe.repairStrategies[0] ?? "\u7F29\u51CF\u8F93\u5165\u91CF\u540E\u91CD\u8BD5"
3404
+ },
3405
+ escalationPolicy: {
3406
+ escalateOn: recipe.escalationThreshold.criticalFailures
3407
+ }
3408
+ };
3409
+ }
3410
+
3411
+ // src/meta_skill/materializer.ts
3412
+ function buildTaskCard(policy, profile, input) {
3413
+ const taskType = input.task.type ?? "\uFF08\u672A\u6307\u5B9A\uFF0C\u5F85\u5206\u7C7B\uFF09";
3414
+ const modeLabel = policy.mode === "multi_step" ? "\u591A\u6B65\u6267\u884C" : "\u5355\u6B65\u6267\u884C";
3415
+ const lines = [
3416
+ `# \u4EFB\u52A1\u8BF4\u660E\u5361`,
3417
+ ``,
3418
+ `| \u5B57\u6BB5 | \u503C |`,
3419
+ `|------|-----|`,
3420
+ `| \u6A21\u578B | ${profile.model} |`,
3421
+ `| \u4EFB\u52A1\u7C7B\u578B | ${taskType} |`,
3422
+ `| \u6267\u884C\u6A21\u5F0F | ${modeLabel} |`,
3423
+ ``,
3424
+ `## \u76EE\u6807`,
3425
+ ``,
3426
+ input.task.goal,
3427
+ ``
3428
+ ];
3429
+ if (input.task.constraints && input.task.constraints.length > 0) {
3430
+ lines.push(`## \u7EA6\u675F`);
3431
+ lines.push(``);
3432
+ for (const c of input.task.constraints) {
3433
+ lines.push(`- ${c}`);
3434
+ }
3435
+ lines.push(``);
3436
+ }
3437
+ lines.push(`## \u9009\u7528 Skills`);
3438
+ lines.push(``);
3439
+ if (policy.selectedSkills.length > 0) {
3440
+ for (const skill of policy.selectedSkills) {
3441
+ lines.push(`- ${skill}`);
3442
+ }
3443
+ } else {
3444
+ lines.push(`- \uFF08\u65E0\uFF09`);
3445
+ }
3446
+ lines.push(``);
3447
+ lines.push(`## \u6267\u884C\u6B65\u9AA4`);
3448
+ lines.push(``);
3449
+ policy.stepPlan.forEach((step, idx) => {
3450
+ lines.push(`${idx + 1}. ${step}`);
3451
+ });
3452
+ lines.push(``);
3453
+ lines.push(`## \u8F93\u51FA\u8981\u6C42`);
3454
+ lines.push(``);
3455
+ lines.push(`- \u683C\u5F0F\uFF1A${policy.outputContract.format}`);
3456
+ if (policy.outputContract.mustCiteEvidence) {
3457
+ lines.push(`- \u5FC5\u987B\u5F15\u7528\u4EE3\u7801\u8BC1\u636E`);
3458
+ }
3459
+ if (policy.outputContract.mustListUncertainty) {
3460
+ lines.push(`- \u5FC5\u987B\u5217\u51FA\u4E0D\u786E\u5B9A\u9879`);
3461
+ }
3462
+ return lines.join("\n");
3463
+ }
3464
+ function buildStrictTemplateWorkerPrompt(policy, input) {
3465
+ const sections = [];
3466
+ sections.push(`\u3010\u4EFB\u52A1\u76EE\u6807\u3011
3467
+ ${input.task.goal}`);
3468
+ if (input.task.constraints && input.task.constraints.length > 0) {
3469
+ sections.push(
3470
+ `\u3010\u7EA6\u675F\u6761\u4EF6\u3011
3471
+ ${input.task.constraints.map((c) => `- ${c}`).join("\n")}`
3472
+ );
3473
+ }
3474
+ const stepsText = policy.stepPlan.map((step, i) => `${i + 1}. ${step}`).join("\n");
3475
+ sections.push(
3476
+ `\u3010\u6267\u884C\u6B65\u9AA4\u3011\uFF08\u5FC5\u987B\u6309\u5E8F\uFF0C\u4E0D\u5F97\u8DF3\u6B65\uFF09
3477
+ ${stepsText}`
3478
+ );
3479
+ const evidenceNote = policy.outputContract.mustCiteEvidence ? "\n- \u6BCF\u9879\u7ED3\u8BBA\u5FC5\u987B\u9644\u4EE3\u7801\u884C\u53F7\u6216\u539F\u6587\u5F15\u7528" : "";
3480
+ const uncertaintyNote = policy.outputContract.mustListUncertainty ? "\n- \u4E0D\u786E\u5B9A\u9879\u987B\u5355\u72EC\u5217\u51FA\uFF0C\u4E0D\u5F97\u6DF7\u5165\u7ED3\u8BBA" : "";
3481
+ sections.push(
3482
+ `\u3010\u8F93\u51FA\u683C\u5F0F\u3011
3483
+ \u683C\u5F0F\u8981\u6C42\uFF1A${policy.outputContract.format}${evidenceNote}${uncertaintyNote}`
3484
+ );
3485
+ sections.push(
3486
+ `\u3010\u505C\u6B62\u6761\u4EF6\u3011
3487
+ \u5B8C\u6210\u5168\u90E8\u6B65\u9AA4\u4E14\u8F93\u51FA\u6EE1\u8DB3\u683C\u5F0F\u8981\u6C42\u540E\u505C\u6B62\uFF0C\u4E0D\u5F97\u8FFD\u52A0\u989D\u5916\u5185\u5BB9\u3002`
3488
+ );
3489
+ return sections.join("\n\n");
3490
+ }
3491
+ function buildExplicitChecklistWorkerPrompt(policy, input) {
3492
+ const lines = [];
3493
+ lines.push(`## \u4EFB\u52A1\u76EE\u6807
3494
+
3495
+ ${input.task.goal}`);
3496
+ if (input.task.constraints && input.task.constraints.length > 0) {
3497
+ lines.push(
3498
+ `
3499
+ ## \u7EA6\u675F\u6761\u4EF6
3500
+
3501
+ ${input.task.constraints.map((c) => `- ${c}`).join("\n")}`
3502
+ );
3503
+ }
3504
+ lines.push(`
3505
+ ## \u6267\u884C\u6B65\u9AA4
3506
+ `);
3507
+ for (const step of policy.stepPlan) {
3508
+ lines.push(`- [ ] ${step}`);
3509
+ }
3510
+ lines.push(`
3511
+ ## \u8F93\u51FA\u683C\u5F0F
3512
+ `);
3513
+ lines.push(`- \u683C\u5F0F\uFF1A${policy.outputContract.format}`);
3514
+ if (policy.outputContract.mustCiteEvidence) {
3515
+ lines.push(`- \u6CE8\u610F\uFF1A\u6BCF\u9879\u7ED3\u8BBA\u987B\u9644\u4EE3\u7801\u8BC1\u636E\uFF08\u884C\u53F7\u6216\u539F\u6587\u7247\u6BB5\uFF09`);
3516
+ }
3517
+ return lines.join("\n");
3518
+ }
3519
+ function buildFreeformWorkerPrompt(policy, input) {
3520
+ const paragraphs = [];
3521
+ paragraphs.push(`\u8BF7\u5B8C\u6210\u4EE5\u4E0B\u4EFB\u52A1\uFF1A${input.task.goal}`);
3522
+ if (input.task.constraints && input.task.constraints.length > 0) {
3523
+ paragraphs.push(
3524
+ `\u6267\u884C\u65F6\u9700\u9075\u5B88\u4EE5\u4E0B\u7EA6\u675F\uFF1A${input.task.constraints.join("\uFF1B")}\u3002`
3525
+ );
3526
+ }
3527
+ paragraphs.push(
3528
+ `\u6267\u884C\u987A\u5E8F\u5982\u4E0B\uFF1A${policy.stepPlan.map((s, i) => `\uFF08${i + 1}\uFF09${s}`).join(" \u2192 ")}\u3002`
3529
+ );
3530
+ const evidencePart = policy.outputContract.mustCiteEvidence ? " \u6BCF\u9879\u7ED3\u8BBA\u9700\u9644\u5F15\u7528\u8BC1\u636E\u3002" : "";
3531
+ const uncertaintyPart = policy.outputContract.mustListUncertainty ? " \u4E0D\u786E\u5B9A\u4E4B\u5904\u8BF7\u5355\u72EC\u5217\u660E\u3002" : "";
3532
+ paragraphs.push(
3533
+ `\u8F93\u51FA\u683C\u5F0F\u4E3A ${policy.outputContract.format}\u3002${evidencePart}${uncertaintyPart}`
3534
+ );
3535
+ return paragraphs.join("\n\n");
3536
+ }
3537
+ function buildWorkerPrompt(policy, profile, input) {
3538
+ switch (profile.preferences.promptStyle) {
3539
+ case "strict-template":
3540
+ return buildStrictTemplateWorkerPrompt(policy, input);
3541
+ case "explicit-checklist":
3542
+ return buildExplicitChecklistWorkerPrompt(policy, input);
3543
+ case "freeform":
3544
+ default:
3545
+ return buildFreeformWorkerPrompt(policy, input);
3546
+ }
3547
+ }
3548
+ function buildJudgePrompt(policy, input) {
3549
+ const lines = [
3550
+ `# Judge \u8BC4\u4F30 Prompt`,
3551
+ ``,
3552
+ `\u4F60\u662F\u672C\u8F6E\u4EFB\u52A1\u7684\u9A8C\u8BC1\u65B9\u3002\u8BF7\u6309\u7167\u4EE5\u4E0B\u6E05\u5355\u9010\u9879\u6838\u67E5 worker \u7684\u8F93\u51FA\uFF0C\u7136\u540E\u7ED9\u51FA\u6700\u7EC8\u88C1\u5B9A\u3002`,
3553
+ ``,
3554
+ `## \u6838\u67E5\u6E05\u5355`,
3555
+ ``
3556
+ ];
3557
+ policy.stepPlan.forEach((step, idx) => {
3558
+ lines.push(`- [ ] \u6B65\u9AA4 ${idx + 1} \u5DF2\u5B8C\u6210\uFF1A${step}`);
3559
+ });
3560
+ if (policy.outputContract.mustCiteEvidence) {
3561
+ lines.push(`- [ ] \u6BCF\u9879\u7ED3\u8BBA\u5747\u9644\u6709\u4EE3\u7801\u8BC1\u636E\uFF08\u884C\u53F7\u6216\u539F\u6587\u5F15\u7528\uFF09`);
3562
+ }
3563
+ if (policy.outputContract.mustListUncertainty) {
3564
+ lines.push(`- [ ] \u4E0D\u786E\u5B9A\u9879\u5DF2\u5355\u72EC\u5217\u51FA\uFF0C\u672A\u6DF7\u5165\u7ED3\u8BBA`);
3565
+ }
3566
+ lines.push(
3567
+ `- [ ] \u8F93\u51FA\u683C\u5F0F\u7B26\u5408\u8981\u6C42\uFF08\u671F\u671B\u683C\u5F0F\uFF1A${policy.outputContract.format}\uFF09`
3568
+ );
3569
+ lines.push(``);
3570
+ lines.push(`## \u8BC4\u5206\u7EF4\u5EA6\uFF08\u5404\u7EF4\u5EA6 0\u201310 \u5206\uFF09`);
3571
+ lines.push(``);
3572
+ lines.push(`| \u7EF4\u5EA6 | \u5F97\u5206 | \u8BF4\u660E |`);
3573
+ lines.push(`|------|------|------|`);
3574
+ lines.push(`| \u5B8C\u6574\u6027 | \u2014 | \u6240\u6709\u6B65\u9AA4\u662F\u5426\u5168\u90E8\u5B8C\u6210 |`);
3575
+ lines.push(`| \u8BC1\u636E\u8D28\u91CF | \u2014 | \u5F15\u7528\u662F\u5426\u51C6\u786E\u4E14\u5145\u5206 |`);
3576
+ lines.push(`| \u683C\u5F0F\u89C4\u8303 | \u2014 | \u8F93\u51FA\u662F\u5426\u7B26\u5408\u6307\u5B9A\u683C\u5F0F |`);
3577
+ lines.push(``);
3578
+ lines.push(`## \u6700\u7EC8\u88C1\u5B9A`);
3579
+ lines.push(``);
3580
+ lines.push(`\u4ECE\u4EE5\u4E0B\u4E09\u9879\u4E2D\u9009\u62E9\u4E00\u9879\uFF1A`);
3581
+ lines.push(``);
3582
+ lines.push(`- **pass**\uFF1A\u6240\u6709\u6E05\u5355\u9879\u901A\u8FC7\uFF0C\u4E09\u4E2A\u7EF4\u5EA6\u5747 \u2265 7 \u5206`);
3583
+ lines.push(
3584
+ `- **revise**\uFF1A\u5B58\u5728\u53EF\u4FEE\u590D\u7684\u95EE\u9898\u3002\u8BF7\u5728\u88C1\u5B9A\u540E\u5217\u51FA\u5177\u4F53\u4FEE\u6539\u610F\u89C1\uFF0Cworker \u9700\u5728 ${policy.revisionPolicy.maxRetries} \u6B21\u5185\u5B8C\u6210\u4FEE\u6539\u3002\u4FEE\u590D\u7B56\u7565\uFF1A${policy.revisionPolicy.retryStyle}`
3585
+ );
3586
+ if (policy.escalationPolicy.escalateOn.length > 0) {
3587
+ const triggers = policy.escalationPolicy.escalateOn.join("\u3001");
3588
+ lines.push(
3589
+ `- **escalate**\uFF1A\u9047\u5230\u4EE5\u4E0B\u60C5\u5F62\u65F6\u5FC5\u987B\u5347\u7EA7\uFF0C\u4E0D\u5F97\u5C1D\u8BD5\u4FEE\u590D\uFF1A${triggers}`
3590
+ );
3591
+ } else {
3592
+ lines.push(`- **escalate**\uFF1A\u9047\u5230\u65E0\u6CD5\u901A\u8FC7\u91CD\u8BD5\u4FEE\u590D\u7684\u6839\u672C\u6027\u95EE\u9898\u65F6\u5347\u7EA7`);
3593
+ }
3594
+ lines.push(``);
3595
+ lines.push(`> \u88C1\u5B9A\u683C\u5F0F\uFF1A\u5728\u6587\u672B\u5355\u72EC\u4E00\u884C\u5199 \`verdict: pass\` / \`verdict: revise\` / \`verdict: escalate\`\u3002`);
3596
+ return lines.join("\n");
3597
+ }
3598
+ function materialize(policy, profile, input) {
3599
+ return {
3600
+ taskCard: buildTaskCard(policy, profile, input),
3601
+ workerPrompt: buildWorkerPrompt(policy, profile, input),
3602
+ judgePrompt: buildJudgePrompt(policy, input)
3603
+ };
3604
+ }
3605
+
3606
+ // src/meta_skill/learning-store.ts
3607
+ import * as fs10 from "fs";
3608
+ import * as path8 from "path";
3609
+ import * as os from "os";
3610
+ var STORE_PATH = path8.resolve(os.homedir(), ".ecode", "learning-records.jsonl");
3611
+
3612
+ // src/meta_skill/index.ts
3613
+ function resolveBuiltinSkillsDir() {
3614
+ try {
3615
+ let dir = path9.dirname(fileURLToPath(import.meta.url));
3616
+ for (let i = 0; i < 4; i++) {
3617
+ const candidate = path9.join(dir, "skills");
3618
+ if (fs11.existsSync(candidate) && fs11.statSync(candidate).isDirectory()) {
3619
+ return candidate;
3620
+ }
3621
+ const parent = path9.dirname(dir);
3622
+ if (parent === dir) break;
3623
+ dir = parent;
3624
+ }
3625
+ } catch {
3626
+ }
3627
+ return null;
3628
+ }
3629
+ function runMetaAlign(input) {
3630
+ const taskType = input.task.type && isValidTaskType(input.task.type) ? input.task.type : classifyTask(input.task.goal);
3631
+ const inheritedSkills = getBaselineSkills(taskType);
3632
+ const builtinSkillsDir2 = resolveBuiltinSkillsDir();
3633
+ const allSteps = [];
3634
+ for (const skillName of inheritedSkills) {
3635
+ const candidates = [];
3636
+ if (builtinSkillsDir2) {
3637
+ candidates.push(path9.join(builtinSkillsDir2, skillName, "SKILL.md"));
3638
+ candidates.push(path9.join(builtinSkillsDir2, skillName + ".md"));
3639
+ }
3640
+ candidates.push(path9.join(process.cwd(), "skills", skillName, "SKILL.md"));
3641
+ candidates.push(path9.join(process.cwd(), "skills", skillName + ".md"));
3642
+ let body = "";
3643
+ for (const p of candidates) {
3644
+ if (fs11.existsSync(p)) {
3645
+ body = fs11.readFileSync(p, { encoding: "utf-8" });
3646
+ break;
3647
+ }
3648
+ }
3649
+ const steps = extractWorkflowSteps(body);
3650
+ allSteps.push(...steps);
3651
+ }
3652
+ const baselineWorkflow = [...new Set(allSteps)].slice(0, 12);
3653
+ const profile = getModelProfile(input.model.name);
3654
+ const recipe = resolveRecipe(profile, taskType, baselineWorkflow, inheritedSkills);
3655
+ const policy = buildPolicy(recipe, input);
3656
+ const artifacts = materialize(policy, profile, input);
3657
+ const strengths = [];
3658
+ const weaknesses = [];
3659
+ const t = profile.traits;
3660
+ if (t.instructionFollowing === "high") strengths.push("\u6307\u4EE4\u8DDF\u968F\u80FD\u529B\u5F3A");
3661
+ else if (t.instructionFollowing === "low") weaknesses.push("\u6307\u4EE4\u8DDF\u968F\u80FD\u529B\u5F31");
3662
+ if (t.schemaDiscipline === "high") strengths.push("\u7ED3\u6784\u5316\u8F93\u51FA\u9075\u5B88\u7A0B\u5EA6\u9AD8");
3663
+ else if (t.schemaDiscipline === "low") weaknesses.push("\u7ED3\u6784\u5316\u8F93\u51FA\u9075\u5B88\u7A0B\u5EA6\u4F4E");
3664
+ if (t.longContextStability === "high") strengths.push("\u957F\u4E0A\u4E0B\u6587\u7A33\u5B9A\u6027\u597D");
3665
+ else if (t.longContextStability === "low") weaknesses.push("\u957F\u4E0A\u4E0B\u6587\u7A33\u5B9A\u6027\u5DEE");
3666
+ if (t.multiStepStability === "high") strengths.push("\u591A\u6B65\u63A8\u7406\u7A33\u5B9A");
3667
+ else if (t.multiStepStability === "low") weaknesses.push("\u591A\u6B65\u63A8\u7406\u7A33\u5B9A\u6027\u4F4E");
3668
+ if (t.hallucinationRisk === "low") strengths.push("\u5E7B\u89C9\u98CE\u9669\u4F4E");
3669
+ else if (t.hallucinationRisk === "high") weaknesses.push("\u5E7B\u89C9\u98CE\u9669\u9AD8");
3670
+ if (t.selfCorrection === "high") strengths.push("\u81EA\u6211\u7EA0\u9519\u80FD\u529B\u5F3A");
3671
+ else if (t.selfCorrection === "low") weaknesses.push("\u81EA\u6211\u7EA0\u9519\u80FD\u529B\u5F31");
3672
+ const modelProfileSummary = {
3673
+ strengths,
3674
+ weaknesses,
3675
+ promptStyle: profile.preferences.promptStyle
3676
+ };
3677
+ return {
3678
+ resolvedTaskType: taskType,
3679
+ modelProfileSummary,
3680
+ executionPolicy: policy,
3681
+ materializedArtifacts: artifacts,
3682
+ recipeCandidate: {
3683
+ model: recipe.model,
3684
+ taskType: recipe.taskType,
3685
+ inheritedSkills: recipe.inheritedSkills
3686
+ }
3687
+ };
3688
+ }
3689
+
2877
3690
  // src/ui/App.tsx
2878
3691
  import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
2879
3692
  async function handleAutomationCommand(input, manager, sessionContext) {
@@ -2897,6 +3710,95 @@ async function handleAutomationCommand(input, manager, sessionContext) {
2897
3710
  return null;
2898
3711
  }
2899
3712
  }
3713
+ function handleMetaAlignCommand(input) {
3714
+ if (!input.startsWith("/meta-align")) return null;
3715
+ const parts = input.slice("/meta-align".length).trim().split(/\s+/);
3716
+ if (parts.length === 0 || !parts[0]) {
3717
+ return [
3718
+ "**\u7528\u6CD5\uFF1A** `/meta-align <model> [task-type] [goal]`",
3719
+ "",
3720
+ "**\u793A\u4F8B\uFF1A**",
3721
+ "- `/meta-align gpt-4o bugfix \u4FEE\u590D\u767B\u5F55\u9875\u5D29\u6E83\u95EE\u9898`",
3722
+ "- `/meta-align MiniMax-M2.5 code-review`",
3723
+ "- `/meta-align deepseek-chat \u9006\u5411\u5206\u6790 src/ui \u76EE\u5F55\u7ED3\u6784`"
3724
+ ].join("\n");
3725
+ }
3726
+ const VALID_TASK_TYPES = /* @__PURE__ */ new Set([
3727
+ "bugfix",
3728
+ "refactor",
3729
+ "test-generation",
3730
+ "code-review",
3731
+ "code-reverse-design"
3732
+ ]);
3733
+ const model = parts[0];
3734
+ let taskType;
3735
+ let goalParts;
3736
+ if (parts.length >= 2 && VALID_TASK_TYPES.has(parts[1])) {
3737
+ taskType = parts[1];
3738
+ goalParts = parts.slice(2);
3739
+ } else {
3740
+ goalParts = parts.slice(1);
3741
+ }
3742
+ const goal = goalParts.join(" ") || `\u4F7F\u7528 ${model} \u5B8C\u6210\u4EFB\u52A1`;
3743
+ const alignInput = {
3744
+ model: { name: model },
3745
+ task: {
3746
+ type: taskType,
3747
+ goal
3748
+ }
3749
+ };
3750
+ try {
3751
+ const result = runMetaAlign(alignInput);
3752
+ return formatMetaAlignOutput(result, model);
3753
+ } catch (err) {
3754
+ return `**[meta-align \u9519\u8BEF]** ${String(err)}`;
3755
+ }
3756
+ }
3757
+ function formatMetaAlignOutput(result, model) {
3758
+ const { resolvedTaskType, modelProfileSummary, executionPolicy, materializedArtifacts } = result;
3759
+ const lines = [
3760
+ `## meta-align \u7ED3\u679C`,
3761
+ ``,
3762
+ `**\u6A21\u578B\uFF1A** ${model} `,
3763
+ `**\u4EFB\u52A1\u7C7B\u578B\uFF1A** ${resolvedTaskType} `,
3764
+ `**\u6267\u884C\u6A21\u5F0F\uFF1A** ${executionPolicy.mode === "multi_step" ? "\u591A\u6B65\u6267\u884C" : "\u5355\u6B65\u6267\u884C"}`,
3765
+ ``
3766
+ ];
3767
+ if (modelProfileSummary.strengths.length > 0) {
3768
+ lines.push(`### \u6A21\u578B\u4F18\u52BF`);
3769
+ for (const s of modelProfileSummary.strengths) lines.push(`- ${s}`);
3770
+ lines.push(``);
3771
+ }
3772
+ if (modelProfileSummary.weaknesses.length > 0) {
3773
+ lines.push(`### \u6A21\u578B\u5F31\u70B9`);
3774
+ for (const w of modelProfileSummary.weaknesses) lines.push(`- ${w}`);
3775
+ lines.push(``);
3776
+ }
3777
+ if (executionPolicy.selectedSkills.length > 0) {
3778
+ lines.push(`### \u9009\u7528 Skills`);
3779
+ for (const sk of executionPolicy.selectedSkills) lines.push(`- \`${sk}\``);
3780
+ lines.push(``);
3781
+ }
3782
+ if (executionPolicy.stepPlan.length > 0) {
3783
+ lines.push(`### \u6267\u884C\u6B65\u9AA4`);
3784
+ executionPolicy.stepPlan.forEach((step, i) => lines.push(`${i + 1}. ${step}`));
3785
+ lines.push(``);
3786
+ }
3787
+ lines.push(`### \u4E0A\u4E0B\u6587\u5C01\u88C5\u987A\u5E8F`);
3788
+ executionPolicy.contextPackaging.order.forEach((o, i) => lines.push(`${i + 1}. ${o}`));
3789
+ lines.push(``);
3790
+ lines.push(`### Worker Prompt`);
3791
+ lines.push(``);
3792
+ lines.push("```");
3793
+ lines.push(materializedArtifacts.workerPrompt);
3794
+ lines.push("```");
3795
+ lines.push(``);
3796
+ lines.push(
3797
+ `**Retry \u7B56\u7565\uFF1A** \u6700\u591A ${executionPolicy.revisionPolicy.maxRetries} \u6B21 `,
3798
+ `**Retry \u65B9\u5F0F\uFF1A** ${executionPolicy.revisionPolicy.retryStyle}`
3799
+ );
3800
+ return lines.join("\n");
3801
+ }
2900
3802
  function App({ config: config2, version: version2, autoMode: autoMode2 = false, registry: registry2, trustedSkillDirs: trustedSkillDirs2 = [], initialMessages: initialMessages2 = [], llmClient }) {
2901
3803
  const { stdout } = useStdout();
2902
3804
  const { stdin } = useStdin();
@@ -2930,7 +3832,7 @@ function App({ config: config2, version: version2, autoMode: autoMode2 = false,
2930
3832
  const pendingConfirmRef = useRef2(null);
2931
3833
  const abortControllerRef = useRef2(null);
2932
3834
  const llmRef = useRef2(llmClient ?? createProvider(resolveActiveProfile(config2)));
2933
- const automationDataDir = config2.logDir ? join10(config2.logDir, "automation") : join10(homedir2(), ".config", "ecode", "automation");
3835
+ const automationDataDir = config2.logDir ? join11(config2.logDir, "automation") : join11(homedir3(), ".config", "ecode", "automation");
2934
3836
  const automationManagerRef = useRef2(
2935
3837
  new AutomationManager({
2936
3838
  dataDir: automationDataDir,
@@ -3136,10 +4038,10 @@ function App({ config: config2, version: version2, autoMode: autoMode2 = false,
3136
4038
  }
3137
4039
  });
3138
4040
  const confirm = useCallback((prompt) => {
3139
- return new Promise((resolve5) => {
4041
+ return new Promise((resolve6) => {
3140
4042
  setStatus("awaiting_confirm");
3141
4043
  setConfirmPrompt(prompt);
3142
- pendingConfirmRef.current = { resolve: resolve5 };
4044
+ pendingConfirmRef.current = { resolve: resolve6 };
3143
4045
  });
3144
4046
  }, []);
3145
4047
  const runLlmLoop = useCallback(
@@ -3370,6 +4272,17 @@ function App({ config: config2, version: version2, autoMode: autoMode2 = false,
3370
4272
  return;
3371
4273
  }
3372
4274
  }
4275
+ {
4276
+ const metaAlignResult = handleMetaAlignCommand(trimmed);
4277
+ if (metaAlignResult !== null) {
4278
+ setMessages((prev) => [
4279
+ ...prev,
4280
+ { role: "user", content: trimmed },
4281
+ { role: "assistant", content: metaAlignResult }
4282
+ ]);
4283
+ return;
4284
+ }
4285
+ }
3373
4286
  if (registry2) {
3374
4287
  const skillResult = handleSkillInput(trimmed, registry2);
3375
4288
  if (skillResult.type === "error") {
@@ -3651,19 +4564,19 @@ async function runPipe(prompt, llm, out = process.stdout, systemPrompt) {
3651
4564
  }
3652
4565
  }
3653
4566
  function readStdin() {
3654
- return new Promise((resolve5, reject) => {
4567
+ return new Promise((resolve6, reject) => {
3655
4568
  let data = "";
3656
4569
  process.stdin.setEncoding("utf-8");
3657
4570
  process.stdin.on("data", (chunk) => {
3658
4571
  data += chunk;
3659
4572
  });
3660
- process.stdin.on("end", () => resolve5(data.trim()));
4573
+ process.stdin.on("end", () => resolve6(data.trim()));
3661
4574
  process.stdin.on("error", reject);
3662
4575
  });
3663
4576
  }
3664
4577
 
3665
4578
  // src/sessions/command.ts
3666
- import * as path8 from "path";
4579
+ import * as path10 from "path";
3667
4580
  function cmdSessionsList(logDir) {
3668
4581
  const sessions = listSessions(logDir);
3669
4582
  if (sessions.length === 0) return "(no sessions found)";
@@ -3685,13 +4598,13 @@ function cmdSessionsInspect(logDir, idOrPrefix) {
3685
4598
  function cmdSessionsReplay(logDir, idOrPrefix) {
3686
4599
  const session = findSession(logDir, idOrPrefix);
3687
4600
  if (!session) return `Session not found: ${idOrPrefix}`;
3688
- const logPath = path8.join(logDir, session.logFile);
4601
+ const logPath = path10.join(logDir, session.logFile);
3689
4602
  return `ecode --replay ${logPath}`;
3690
4603
  }
3691
4604
  function cmdSessionsFork(logDir, idOrPrefix, turn) {
3692
4605
  const session = findSession(logDir, idOrPrefix);
3693
4606
  if (!session) return `Session not found: ${idOrPrefix}`;
3694
- const logPath = path8.join(logDir, session.logFile);
4607
+ const logPath = path10.join(logDir, session.logFile);
3695
4608
  const turnStr = turn !== void 0 ? turn : session.turnCount;
3696
4609
  return `ecode --fork ${logPath}:${turnStr}`;
3697
4610
  }
@@ -3705,7 +4618,7 @@ function formatInspect(session, logDir) {
3705
4618
  `last active: ${new Date(session.lastActivity).toLocaleString()}`,
3706
4619
  `turns: ${session.turnCount}`,
3707
4620
  `tokens: ${session.totalTokens.toLocaleString()}`,
3708
- `log file: ${path8.join(logDir, session.logFile)}`
4621
+ `log file: ${path10.join(logDir, session.logFile)}`
3709
4622
  ].join("\n");
3710
4623
  }
3711
4624
 
@@ -3811,7 +4724,7 @@ if (!finalConfig.apiKey) {
3811
4724
  var initialMessages = [];
3812
4725
  if (replayFile) {
3813
4726
  try {
3814
- const raw = readFileSync3(replayFile, "utf-8");
4727
+ const raw = readFileSync5(replayFile, "utf-8");
3815
4728
  initialMessages = parseReplayLog(raw);
3816
4729
  } catch (err) {
3817
4730
  console.error(`Error reading replay file: ${err}`);
@@ -3819,17 +4732,17 @@ if (replayFile) {
3819
4732
  }
3820
4733
  } else if (forkSpec) {
3821
4734
  try {
3822
- const raw = readFileSync3(forkSpec.file, "utf-8");
4735
+ const raw = readFileSync5(forkSpec.file, "utf-8");
3823
4736
  initialMessages = truncateToTurn(parseReplayLog(raw), forkSpec.turn);
3824
4737
  } catch (err) {
3825
4738
  console.error(`Error reading fork file: ${err}`);
3826
4739
  process.exit(1);
3827
4740
  }
3828
4741
  }
3829
- var __dirname = dirname7(fileURLToPath(import.meta.url));
3830
- var builtinSkillsDir = resolve4(__dirname, "../skills");
3831
- var userSkillsDir = resolve4(process.env.HOME ?? "~", ".ecode/skills");
3832
- var projectSkillsDir = resolve4(process.cwd(), ".ecode/skills");
4742
+ var __dirname = dirname9(fileURLToPath2(import.meta.url));
4743
+ var builtinSkillsDir = resolve5(__dirname, "../skills");
4744
+ var userSkillsDir = resolve5(process.env.HOME ?? "~", ".ecode/skills");
4745
+ var projectSkillsDir = resolve5(process.cwd(), ".ecode/skills");
3833
4746
  var registry = new SkillRegistry();
3834
4747
  for (const dir of [builtinSkillsDir, userSkillsDir, projectSkillsDir]) {
3835
4748
  const skills = await loadSkillsFromDir(dir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhongqian97-code/ecode",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
4
4
  "description": "A minimal Claude Code clone with REPL interface and bash tool calling",
5
5
  "type": "module",
6
6
  "author": "zhongqian97-code",