@zhongqian97-code/ecode 0.5.7 → 0.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +915 -37
- 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
|
|
6
|
+
import { resolve as resolve6, dirname as dirname8 } from "path";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
8
|
import React4 from "react";
|
|
9
9
|
import { render } from "ink";
|
|
10
|
-
import { readFileSync as
|
|
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((
|
|
543
|
+
return new Promise((resolve7) => {
|
|
544
544
|
exec(cmd, { timeout: timeoutMs }, (err, stdout, stderr) => {
|
|
545
545
|
if (err) {
|
|
546
546
|
const exitCode = err.code ?? 1;
|
|
547
|
-
|
|
547
|
+
resolve7({ stdout: stdout ?? "", stderr: stderr ?? "", exitCode });
|
|
548
548
|
} else {
|
|
549
|
-
|
|
549
|
+
resolve7({ 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:
|
|
574
|
+
const { path: path11, offset = 0, limit } = params;
|
|
575
575
|
let raw;
|
|
576
576
|
try {
|
|
577
|
-
raw = await fs.readFile(
|
|
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 ${
|
|
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:
|
|
636
|
+
const { path: path11, old_string, new_string } = params;
|
|
637
637
|
let content;
|
|
638
638
|
try {
|
|
639
|
-
content = await fs3.readFile(
|
|
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 ${
|
|
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 ${
|
|
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 ${
|
|
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(
|
|
654
|
-
return `Edited ${
|
|
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 ${
|
|
657
|
+
return `Error writing ${path11}: ${msg}`;
|
|
658
658
|
}
|
|
659
659
|
}
|
|
660
660
|
function countOccurrences(haystack, needle) {
|
|
@@ -1910,11 +1910,18 @@ var Input = forwardRef(function Input2({ isActive, onSubmit, onChange, placehold
|
|
|
1910
1910
|
}
|
|
1911
1911
|
const before = line.slice(0, cursorCol);
|
|
1912
1912
|
const after = line.slice(cursorCol);
|
|
1913
|
+
if (after.length > 0) {
|
|
1914
|
+
return /* @__PURE__ */ jsxs3(Box3, { children: [
|
|
1915
|
+
/* @__PURE__ */ jsx3(Text3, { color: "cyan", children: prefix }),
|
|
1916
|
+
/* @__PURE__ */ jsx3(Text3, { children: before }),
|
|
1917
|
+
/* @__PURE__ */ jsx3(Text3, { inverse: true, children: after[0] }),
|
|
1918
|
+
/* @__PURE__ */ jsx3(Text3, { children: after.slice(1) })
|
|
1919
|
+
] }, idx);
|
|
1920
|
+
}
|
|
1913
1921
|
return /* @__PURE__ */ jsxs3(Box3, { children: [
|
|
1914
1922
|
/* @__PURE__ */ jsx3(Text3, { color: "cyan", children: prefix }),
|
|
1915
1923
|
/* @__PURE__ */ jsx3(Text3, { children: before }),
|
|
1916
|
-
/* @__PURE__ */ jsx3(Text3, { color: "cyan", children: CURSOR_CHAR })
|
|
1917
|
-
/* @__PURE__ */ jsx3(Text3, { children: after })
|
|
1924
|
+
/* @__PURE__ */ jsx3(Text3, { color: "cyan", children: CURSOR_CHAR })
|
|
1918
1925
|
] }, idx);
|
|
1919
1926
|
}) });
|
|
1920
1927
|
};
|
|
@@ -2162,7 +2169,7 @@ function parseMouseScroll(data) {
|
|
|
2162
2169
|
}
|
|
2163
2170
|
|
|
2164
2171
|
// src/ui/App.tsx
|
|
2165
|
-
import { homedir as
|
|
2172
|
+
import { homedir as homedir3 } from "os";
|
|
2166
2173
|
import { join as join10 } from "path";
|
|
2167
2174
|
|
|
2168
2175
|
// src/automation/store.ts
|
|
@@ -2777,11 +2784,11 @@ var AutomationManager = class {
|
|
|
2777
2784
|
job.id,
|
|
2778
2785
|
`[goal ${job.id.slice(0, 8)}] \u7B2C ${job.activeTurnCount} \u8F6E\uFF1A\u5C1A\u672A\u5B8C\u6210\uFF0C\u7EE7\u7EED\u6267\u884C\u2026`
|
|
2779
2786
|
);
|
|
2780
|
-
await new Promise((
|
|
2781
|
-
const timer = setTimeout(
|
|
2787
|
+
await new Promise((resolve7) => {
|
|
2788
|
+
const timer = setTimeout(resolve7, 5e3);
|
|
2782
2789
|
signal.addEventListener("abort", () => {
|
|
2783
2790
|
clearTimeout(timer);
|
|
2784
|
-
|
|
2791
|
+
resolve7();
|
|
2785
2792
|
}, { once: true });
|
|
2786
2793
|
});
|
|
2787
2794
|
}
|
|
@@ -2867,6 +2874,777 @@ function generateTitle(firstUserMessage) {
|
|
|
2867
2874
|
return oneLine.length > 50 ? oneLine.slice(0, 47) + "..." : oneLine;
|
|
2868
2875
|
}
|
|
2869
2876
|
|
|
2877
|
+
// src/meta_skill/index.ts
|
|
2878
|
+
import * as fs11 from "fs";
|
|
2879
|
+
import * as path9 from "path";
|
|
2880
|
+
|
|
2881
|
+
// src/meta_skill/task-classifier.ts
|
|
2882
|
+
var RULES = {
|
|
2883
|
+
bugfix: [
|
|
2884
|
+
{ pattern: /(?<!\w)(bug|fix|修复|修bug|defect|error|crash|exception|broken|fails?|失败|报错|崩溃|异常|问题|故障|incorrect|wrong|不对|不正确)(?!\w)/i, weight: 3 },
|
|
2885
|
+
{ pattern: /(?<!\w)(debug|diagnose|诊断|定位|追踪|trace|reproduce|复现)(?!\w)/i, weight: 2 },
|
|
2886
|
+
{ pattern: /(?<!\w)(regression|revert|回归|回滚)(?!\w)/i, weight: 1 }
|
|
2887
|
+
],
|
|
2888
|
+
refactor: [
|
|
2889
|
+
{ pattern: /(?<!\w)(refactor|重构|重写|rewrite|restructure|重新设计|clean ?up|清理|整理|simplify|简化|extract|提取|split|拆分)(?!\w)/i, weight: 3 },
|
|
2890
|
+
{ pattern: /(?<!\w)(maintainability|可维护|readability|可读性|code smell|技术债|tech debt|coupling|耦合|cohesion|内聚)(?!\w)/i, weight: 2 },
|
|
2891
|
+
{ pattern: /(?<!\w)(rename|move|organize|抽象|abstraction)(?!\w)/i, weight: 1 }
|
|
2892
|
+
],
|
|
2893
|
+
"test-generation": [
|
|
2894
|
+
{ pattern: /(?<!\w)(tests?|测试|specs?|单元测试|unit tests?|coverage|覆盖率|vitest|jest|mocha|e2e|integration)(?!\w)/i, weight: 3 },
|
|
2895
|
+
{ pattern: /(?<!\w)(assert|验证|verify|tdd|red.green)(?!\w)/i, weight: 2 },
|
|
2896
|
+
{ pattern: /(?<!\w)(mock|stub|fixture|测试用例|用例)(?!\w)/i, weight: 1 }
|
|
2897
|
+
],
|
|
2898
|
+
"code-review": [
|
|
2899
|
+
{ pattern: /(?<!\w)(review|审查|审阅|代码审查|audit|安全审计|inspect)(?!\w)/i, weight: 3 },
|
|
2900
|
+
{ pattern: /(?<!\w)(quality|质量|best practice|最佳实践|standard|规范|convention|smell)(?!\w)/i, weight: 2 },
|
|
2901
|
+
{ pattern: /(?<!\w)(feedback|意见|suggestion|建议|comment|注释)(?!\w)/i, weight: 1 }
|
|
2902
|
+
],
|
|
2903
|
+
"code-reverse-design": [
|
|
2904
|
+
{ pattern: /(?<!\w)(reverse|逆向|理解|understand|architecture|架构|design doc|设计文档|document|文档化|逆向工程)(?!\w)/i, weight: 3 },
|
|
2905
|
+
{ pattern: /(?<!\w)(analyze|分析|explore|探索|overview|概览|structure|结构|module|模块|dependency|依赖)(?!\w)/i, weight: 2 },
|
|
2906
|
+
{ pattern: /(?<!\w)(prd|需求|规格|diagram|图表|flowchart|流程图)(?!\w)/i, weight: 1 }
|
|
2907
|
+
]
|
|
2908
|
+
};
|
|
2909
|
+
var PRIORITY = [
|
|
2910
|
+
"bugfix",
|
|
2911
|
+
"test-generation",
|
|
2912
|
+
"refactor",
|
|
2913
|
+
"code-review",
|
|
2914
|
+
"code-reverse-design"
|
|
2915
|
+
];
|
|
2916
|
+
function classifyTask(goal, fallback = "code-review") {
|
|
2917
|
+
const scores = {
|
|
2918
|
+
bugfix: 0,
|
|
2919
|
+
refactor: 0,
|
|
2920
|
+
"test-generation": 0,
|
|
2921
|
+
"code-review": 0,
|
|
2922
|
+
"code-reverse-design": 0
|
|
2923
|
+
};
|
|
2924
|
+
for (const [type, rules] of Object.entries(RULES)) {
|
|
2925
|
+
for (const { pattern, weight } of rules) {
|
|
2926
|
+
if (pattern.test(goal)) {
|
|
2927
|
+
scores[type] += weight;
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
let bestType = fallback;
|
|
2932
|
+
let bestScore = 0;
|
|
2933
|
+
for (const type of PRIORITY) {
|
|
2934
|
+
const s = scores[type];
|
|
2935
|
+
if (s > bestScore) {
|
|
2936
|
+
bestScore = s;
|
|
2937
|
+
bestType = type;
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
return bestType;
|
|
2941
|
+
}
|
|
2942
|
+
function isValidTaskType(value) {
|
|
2943
|
+
return ["bugfix", "refactor", "test-generation", "code-review", "code-reverse-design"].includes(value);
|
|
2944
|
+
}
|
|
2945
|
+
|
|
2946
|
+
// src/meta_skill/skill-survey.ts
|
|
2947
|
+
var BASELINE_MAP = {
|
|
2948
|
+
"bugfix": ["diagnose", "tdd"],
|
|
2949
|
+
"refactor": ["search-first", "plan", "improve-codebase-architecture"],
|
|
2950
|
+
"test-generation": ["tdd"],
|
|
2951
|
+
"code-review": ["zoom-out", "search-first", "security-review"],
|
|
2952
|
+
"code-reverse-design": ["zoom-out", "plan", "to-prd"]
|
|
2953
|
+
};
|
|
2954
|
+
function getBaselineSkills(taskType) {
|
|
2955
|
+
return [...BASELINE_MAP[taskType] ?? []];
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
// src/meta_skill/workflow-extractor.ts
|
|
2959
|
+
var NUMBERED_HEADINGS_RE = /^#{1,4}\s+(?:Step\s+|Phase\s+)?(\d+)[.:\-–—\s]+(.+)$/gim;
|
|
2960
|
+
var NUMBERED_LIST_RE = /^\s*(\d+)\.\s+(.{10,})$/gm;
|
|
2961
|
+
var MAX_STEPS = 12;
|
|
2962
|
+
function extractWorkflowSteps(body) {
|
|
2963
|
+
if (!body.trim()) return [];
|
|
2964
|
+
const headingSteps = extractHeadingSteps(body);
|
|
2965
|
+
if (headingSteps.length >= 2) {
|
|
2966
|
+
return headingSteps.slice(0, MAX_STEPS);
|
|
2967
|
+
}
|
|
2968
|
+
const listSteps = extractListSteps(body);
|
|
2969
|
+
if (listSteps.length >= 2) {
|
|
2970
|
+
return listSteps.slice(0, MAX_STEPS);
|
|
2971
|
+
}
|
|
2972
|
+
return extractParagraphSteps(body);
|
|
2973
|
+
}
|
|
2974
|
+
function extractHeadingSteps(body) {
|
|
2975
|
+
const steps = [];
|
|
2976
|
+
let match;
|
|
2977
|
+
NUMBERED_HEADINGS_RE.lastIndex = 0;
|
|
2978
|
+
while ((match = NUMBERED_HEADINGS_RE.exec(body)) !== null) {
|
|
2979
|
+
const text = match[2]?.trim();
|
|
2980
|
+
if (text) steps.push(cleanStepText(text));
|
|
2981
|
+
}
|
|
2982
|
+
return steps;
|
|
2983
|
+
}
|
|
2984
|
+
function extractListSteps(body) {
|
|
2985
|
+
const steps = [];
|
|
2986
|
+
NUMBERED_LIST_RE.lastIndex = 0;
|
|
2987
|
+
let match;
|
|
2988
|
+
while ((match = NUMBERED_LIST_RE.exec(body)) !== null) {
|
|
2989
|
+
const text = match[2]?.trim();
|
|
2990
|
+
if (text) steps.push(cleanStepText(text));
|
|
2991
|
+
}
|
|
2992
|
+
return steps;
|
|
2993
|
+
}
|
|
2994
|
+
function extractParagraphSteps(body) {
|
|
2995
|
+
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);
|
|
2996
|
+
}
|
|
2997
|
+
function cleanStepText(text) {
|
|
2998
|
+
return text.replace(/\*{1,2}([^*]+)\*{1,2}/g, "$1").replace(/`([^`]+)`/g, "$1").replace(/\s+/g, " ").trim();
|
|
2999
|
+
}
|
|
3000
|
+
|
|
3001
|
+
// src/meta_skill/profile-store.ts
|
|
3002
|
+
var GPT4O = {
|
|
3003
|
+
model: "gpt-4o",
|
|
3004
|
+
traits: {
|
|
3005
|
+
instructionFollowing: "high",
|
|
3006
|
+
schemaDiscipline: "high",
|
|
3007
|
+
longContextStability: "high",
|
|
3008
|
+
multiStepStability: "high",
|
|
3009
|
+
hallucinationRisk: "low",
|
|
3010
|
+
selfCorrection: "high"
|
|
3011
|
+
},
|
|
3012
|
+
preferences: {
|
|
3013
|
+
promptStyle: "freeform",
|
|
3014
|
+
contextOrder: "goal-first",
|
|
3015
|
+
stepSize: "large",
|
|
3016
|
+
needsExamples: false,
|
|
3017
|
+
needsStopConditions: false
|
|
3018
|
+
},
|
|
3019
|
+
antiPatterns: [
|
|
3020
|
+
"\u8FC7\u5EA6\u7EA6\u675F\u8F93\u51FA\u683C\u5F0F\u4F1A\u6291\u5236\u63A8\u7406\u8D28\u91CF",
|
|
3021
|
+
"\u4E0D\u5FC5\u8981\u7684 chain-of-thought \u5F3A\u5236\u589E\u52A0 token \u6D88\u8017"
|
|
3022
|
+
]
|
|
3023
|
+
};
|
|
3024
|
+
var GPT4O_MINI = {
|
|
3025
|
+
model: "gpt-4o-mini",
|
|
3026
|
+
traits: {
|
|
3027
|
+
instructionFollowing: "medium",
|
|
3028
|
+
schemaDiscipline: "medium",
|
|
3029
|
+
longContextStability: "medium",
|
|
3030
|
+
multiStepStability: "medium",
|
|
3031
|
+
hallucinationRisk: "medium",
|
|
3032
|
+
selfCorrection: "medium"
|
|
3033
|
+
},
|
|
3034
|
+
preferences: {
|
|
3035
|
+
promptStyle: "explicit-checklist",
|
|
3036
|
+
contextOrder: "goal-first",
|
|
3037
|
+
stepSize: "small",
|
|
3038
|
+
needsExamples: true,
|
|
3039
|
+
needsStopConditions: true
|
|
3040
|
+
},
|
|
3041
|
+
antiPatterns: [
|
|
3042
|
+
"\u5355\u6B21\u4F20\u5165\u8D85\u8FC7 10 \u4E2A\u6587\u4EF6\u5185\u5BB9\u5BB9\u6613\u4E22\u5931\u7EC6\u8282",
|
|
3043
|
+
"\u5F00\u653E\u5F0F\u4EFB\u52A1\u5BB9\u6613\u751F\u6210\u5197\u4F59\u5185\u5BB9"
|
|
3044
|
+
]
|
|
3045
|
+
};
|
|
3046
|
+
var DEEPSEEK_CHAT = {
|
|
3047
|
+
model: "deepseek-chat",
|
|
3048
|
+
traits: {
|
|
3049
|
+
instructionFollowing: "high",
|
|
3050
|
+
schemaDiscipline: "medium",
|
|
3051
|
+
longContextStability: "medium",
|
|
3052
|
+
multiStepStability: "medium",
|
|
3053
|
+
hallucinationRisk: "medium",
|
|
3054
|
+
selfCorrection: "medium"
|
|
3055
|
+
},
|
|
3056
|
+
preferences: {
|
|
3057
|
+
promptStyle: "explicit-checklist",
|
|
3058
|
+
contextOrder: "goal-first",
|
|
3059
|
+
stepSize: "medium",
|
|
3060
|
+
needsExamples: true,
|
|
3061
|
+
needsStopConditions: false
|
|
3062
|
+
},
|
|
3063
|
+
antiPatterns: [
|
|
3064
|
+
"\u957F\u4E0A\u4E0B\u6587\uFF08>32K token\uFF09\u65F6\u8F93\u51FA\u7A33\u5B9A\u6027\u4E0B\u964D",
|
|
3065
|
+
"\u591A\u6B65\u590D\u6742\u63A8\u7406\u94FE\u4E2D\u9014\u5BB9\u6613\u504F\u79BB\u76EE\u6807"
|
|
3066
|
+
]
|
|
3067
|
+
};
|
|
3068
|
+
var DEEPSEEK_REASONER = {
|
|
3069
|
+
model: "deepseek-reasoner",
|
|
3070
|
+
traits: {
|
|
3071
|
+
instructionFollowing: "high",
|
|
3072
|
+
schemaDiscipline: "medium",
|
|
3073
|
+
longContextStability: "medium",
|
|
3074
|
+
multiStepStability: "high",
|
|
3075
|
+
hallucinationRisk: "low",
|
|
3076
|
+
selfCorrection: "high"
|
|
3077
|
+
},
|
|
3078
|
+
preferences: {
|
|
3079
|
+
promptStyle: "freeform",
|
|
3080
|
+
contextOrder: "goal-first",
|
|
3081
|
+
stepSize: "large",
|
|
3082
|
+
needsExamples: false,
|
|
3083
|
+
needsStopConditions: false
|
|
3084
|
+
},
|
|
3085
|
+
antiPatterns: [
|
|
3086
|
+
"\u8FC7\u5EA6\u7EA6\u675F\u63A8\u7406\u6B65\u9AA4\u683C\u5F0F\u4F1A\u5E72\u6270\u5185\u90E8\u601D\u8003\u94FE",
|
|
3087
|
+
"\u4E0D\u9002\u5408\u7EAF\u68C0\u7D22\u7C7B\u4EFB\u52A1\uFF08\u63A8\u7406\u5F00\u9500\u8FDC\u5927\u4E8E\u6536\u76CA\uFF09"
|
|
3088
|
+
]
|
|
3089
|
+
};
|
|
3090
|
+
var MINIMAX_M25 = {
|
|
3091
|
+
model: "MiniMax-M2.5",
|
|
3092
|
+
traits: {
|
|
3093
|
+
instructionFollowing: "medium",
|
|
3094
|
+
schemaDiscipline: "low",
|
|
3095
|
+
longContextStability: "high",
|
|
3096
|
+
// 百万 token 上下文
|
|
3097
|
+
multiStepStability: "medium",
|
|
3098
|
+
hallucinationRisk: "medium",
|
|
3099
|
+
selfCorrection: "low"
|
|
3100
|
+
},
|
|
3101
|
+
preferences: {
|
|
3102
|
+
promptStyle: "strict-template",
|
|
3103
|
+
contextOrder: "template-first",
|
|
3104
|
+
stepSize: "small",
|
|
3105
|
+
needsExamples: true,
|
|
3106
|
+
needsStopConditions: true
|
|
3107
|
+
},
|
|
3108
|
+
antiPatterns: [
|
|
3109
|
+
"\u81EA\u7531\u683C\u5F0F\u8F93\u51FA\u5BB9\u6613\u4EA7\u751F\u5197\u4F59\u6216\u683C\u5F0F\u6DF7\u4E71",
|
|
3110
|
+
"\u7F3A\u4E4F\u660E\u786E\u505C\u6B62\u6761\u4EF6\u65F6\u5BB9\u6613\u8FC7\u5EA6\u8F93\u51FA",
|
|
3111
|
+
"\u590D\u6742\u63A8\u7406\u94FE\u9700\u8981\u66F4\u7EC6\u7C92\u5EA6\u7684\u6B65\u9AA4\u62C6\u5206"
|
|
3112
|
+
]
|
|
3113
|
+
};
|
|
3114
|
+
var MINIMAX_M25_HS = {
|
|
3115
|
+
...MINIMAX_M25,
|
|
3116
|
+
model: "MiniMax-M2.5-highspeed"
|
|
3117
|
+
};
|
|
3118
|
+
var CLAUDE_SONNET = {
|
|
3119
|
+
model: "claude-sonnet-4-6",
|
|
3120
|
+
traits: {
|
|
3121
|
+
instructionFollowing: "high",
|
|
3122
|
+
schemaDiscipline: "high",
|
|
3123
|
+
longContextStability: "high",
|
|
3124
|
+
multiStepStability: "high",
|
|
3125
|
+
hallucinationRisk: "low",
|
|
3126
|
+
selfCorrection: "high"
|
|
3127
|
+
},
|
|
3128
|
+
preferences: {
|
|
3129
|
+
promptStyle: "freeform",
|
|
3130
|
+
contextOrder: "goal-first",
|
|
3131
|
+
stepSize: "large",
|
|
3132
|
+
needsExamples: false,
|
|
3133
|
+
needsStopConditions: false
|
|
3134
|
+
},
|
|
3135
|
+
antiPatterns: [
|
|
3136
|
+
"\u8FC7\u5EA6\u6307\u5B9A\u8F93\u51FA\u683C\u5F0F\u53EF\u80FD\u6291\u5236\u81EA\u7136\u63A8\u7406"
|
|
3137
|
+
]
|
|
3138
|
+
};
|
|
3139
|
+
var CLAUDE_OPUS = {
|
|
3140
|
+
...CLAUDE_SONNET,
|
|
3141
|
+
model: "claude-opus-4-7"
|
|
3142
|
+
};
|
|
3143
|
+
var CLAUDE_HAIKU = {
|
|
3144
|
+
model: "claude-haiku-4-5-20251001",
|
|
3145
|
+
traits: {
|
|
3146
|
+
instructionFollowing: "high",
|
|
3147
|
+
schemaDiscipline: "high",
|
|
3148
|
+
longContextStability: "high",
|
|
3149
|
+
multiStepStability: "medium",
|
|
3150
|
+
hallucinationRisk: "low",
|
|
3151
|
+
selfCorrection: "medium"
|
|
3152
|
+
},
|
|
3153
|
+
preferences: {
|
|
3154
|
+
promptStyle: "explicit-checklist",
|
|
3155
|
+
contextOrder: "goal-first",
|
|
3156
|
+
stepSize: "medium",
|
|
3157
|
+
needsExamples: false,
|
|
3158
|
+
needsStopConditions: false
|
|
3159
|
+
},
|
|
3160
|
+
antiPatterns: [
|
|
3161
|
+
"\u6DF1\u5EA6\u63A8\u7406\u4EFB\u52A1\u8D85\u51FA\u80FD\u529B\u8FB9\u754C\u65F6\u5E94 escalate \u5230 Sonnet/Opus"
|
|
3162
|
+
]
|
|
3163
|
+
};
|
|
3164
|
+
var DEFAULT_PROFILE = {
|
|
3165
|
+
model: "unknown",
|
|
3166
|
+
traits: {
|
|
3167
|
+
instructionFollowing: "medium",
|
|
3168
|
+
schemaDiscipline: "medium",
|
|
3169
|
+
longContextStability: "medium",
|
|
3170
|
+
multiStepStability: "medium",
|
|
3171
|
+
hallucinationRisk: "medium",
|
|
3172
|
+
selfCorrection: "medium"
|
|
3173
|
+
},
|
|
3174
|
+
preferences: {
|
|
3175
|
+
promptStyle: "explicit-checklist",
|
|
3176
|
+
contextOrder: "goal-first",
|
|
3177
|
+
stepSize: "small",
|
|
3178
|
+
needsExamples: true,
|
|
3179
|
+
needsStopConditions: true
|
|
3180
|
+
},
|
|
3181
|
+
antiPatterns: []
|
|
3182
|
+
};
|
|
3183
|
+
var PROFILE_MAP = {
|
|
3184
|
+
"gpt-4o": GPT4O,
|
|
3185
|
+
"gpt-4o-mini": GPT4O_MINI,
|
|
3186
|
+
"deepseek-chat": DEEPSEEK_CHAT,
|
|
3187
|
+
"deepseek-reasoner": DEEPSEEK_REASONER,
|
|
3188
|
+
"MiniMax-M2.5": MINIMAX_M25,
|
|
3189
|
+
"MiniMax-M2.5-highspeed": MINIMAX_M25_HS,
|
|
3190
|
+
"claude-sonnet-4-6": CLAUDE_SONNET,
|
|
3191
|
+
"claude-opus-4-7": CLAUDE_OPUS,
|
|
3192
|
+
"claude-haiku-4-5-20251001": CLAUDE_HAIKU,
|
|
3193
|
+
// 历史别名
|
|
3194
|
+
"claude-3-5-sonnet-20241022": { ...CLAUDE_SONNET, model: "claude-3-5-sonnet-20241022" },
|
|
3195
|
+
"claude-3-5-haiku-20241022": { ...CLAUDE_HAIKU, model: "claude-3-5-haiku-20241022" }
|
|
3196
|
+
};
|
|
3197
|
+
function getModelProfile(modelName) {
|
|
3198
|
+
const exact = PROFILE_MAP[modelName];
|
|
3199
|
+
if (exact) return exact;
|
|
3200
|
+
for (const [key, profile] of Object.entries(PROFILE_MAP)) {
|
|
3201
|
+
if (modelName.startsWith(key) || key.startsWith(modelName)) {
|
|
3202
|
+
return { ...profile, model: modelName };
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
return { ...DEFAULT_PROFILE, model: modelName };
|
|
3206
|
+
}
|
|
3207
|
+
|
|
3208
|
+
// src/meta_skill/recipe-resolver.ts
|
|
3209
|
+
function resolveInputStyle(promptStyle) {
|
|
3210
|
+
return promptStyle;
|
|
3211
|
+
}
|
|
3212
|
+
function resolveGranularity(stepSize) {
|
|
3213
|
+
switch (stepSize) {
|
|
3214
|
+
case "large":
|
|
3215
|
+
return "large-batch";
|
|
3216
|
+
case "small":
|
|
3217
|
+
return "stepwise";
|
|
3218
|
+
case "medium":
|
|
3219
|
+
default:
|
|
3220
|
+
return "file-level-first";
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
function resolveOutputFormat(promptStyle) {
|
|
3224
|
+
switch (promptStyle) {
|
|
3225
|
+
case "strict-template":
|
|
3226
|
+
return "strict-template";
|
|
3227
|
+
case "explicit-checklist":
|
|
3228
|
+
return "template";
|
|
3229
|
+
case "freeform":
|
|
3230
|
+
default:
|
|
3231
|
+
return "freeform";
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
function resolveContextStrategy(contextOrder) {
|
|
3235
|
+
switch (contextOrder) {
|
|
3236
|
+
case "goal-first":
|
|
3237
|
+
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";
|
|
3238
|
+
case "template-first":
|
|
3239
|
+
return "\u5148\u7ED9\u51FA\u8F93\u51FA\u6A21\u677F\uFF0C\u518D\u63CF\u8FF0\u4EFB\u52A1\uFF0C\u6700\u540E\u9644\u4E0A\u6750\u6599";
|
|
3240
|
+
default:
|
|
3241
|
+
return "\u5148\u9644\u4E0A\u6240\u6709\u76F8\u5173\u6750\u6599\uFF0C\u518D\u7ED9\u51FA\u4EFB\u52A1\u76EE\u6807";
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
function resolveVerificationStyle(selfCorrection, hallucinationRisk) {
|
|
3245
|
+
if (selfCorrection === "high" && hallucinationRisk === "low") {
|
|
3246
|
+
return "\u81EA\u6821\u9A8C\uFF1A\u8981\u6C42\u6A21\u578B\u5217\u51FA\u7F6E\u4FE1\u5EA6\u4F4E\u7684\u7ED3\u8BBA";
|
|
3247
|
+
}
|
|
3248
|
+
if (hallucinationRisk === "high") {
|
|
3249
|
+
return "\u5F3A\u9A8C\u8BC1\uFF1A\u8981\u6C42\u5F15\u7528\u4EE3\u7801\u884C\u53F7\u4F5C\u4E3A\u6BCF\u6761\u7ED3\u8BBA\u7684\u8BC1\u636E";
|
|
3250
|
+
}
|
|
3251
|
+
return "\u8F7B\u9A8C\u8BC1\uFF1A\u8F93\u51FA\u7ED3\u8BBA\u540E\u7528\u793A\u4F8B\u4EE3\u7801\u7247\u6BB5\u786E\u8BA4";
|
|
3252
|
+
}
|
|
3253
|
+
function resolveFailureModes(profile, taskType) {
|
|
3254
|
+
const modes = [...profile.antiPatterns];
|
|
3255
|
+
if (profile.traits.longContextStability === "low" || profile.traits.longContextStability === "medium") {
|
|
3256
|
+
modes.push("\u957F\u4E0A\u4E0B\u6587\u65F6\u53EF\u80FD\u4E22\u5931\u65E9\u671F\u6307\u4EE4");
|
|
3257
|
+
}
|
|
3258
|
+
if (profile.traits.multiStepStability === "low") {
|
|
3259
|
+
modes.push("\u591A\u6B65\u63A8\u7406\u4E2D\u9014\u53EF\u80FD\u504F\u79BB\u76EE\u6807");
|
|
3260
|
+
}
|
|
3261
|
+
if (taskType === "bugfix") {
|
|
3262
|
+
modes.push("\u53EF\u80FD\u4FEE\u590D\u75C7\u72B6\u800C\u975E\u6839\u672C\u539F\u56E0");
|
|
3263
|
+
modes.push("\u5728\u7F3A\u4E4F\u5B8C\u6574\u4E0A\u4E0B\u6587\u65F6\u6613\u8BEF\u5224 bug \u6240\u5728\u4F4D\u7F6E");
|
|
3264
|
+
}
|
|
3265
|
+
if (taskType === "code-review") {
|
|
3266
|
+
modes.push("\u53EF\u80FD\u53EA\u5173\u6CE8\u4EE3\u7801\u98CE\u683C\u800C\u5FFD\u7565\u903B\u8F91\u7F3A\u9677");
|
|
3267
|
+
modes.push("\u5BF9\u590D\u6742\u4E1A\u52A1\u903B\u8F91\u7684\u8BC4\u5BA1\u6DF1\u5EA6\u4E0D\u8DB3");
|
|
3268
|
+
}
|
|
3269
|
+
return modes;
|
|
3270
|
+
}
|
|
3271
|
+
function resolveRepairStrategies(profile) {
|
|
3272
|
+
const strategies = [];
|
|
3273
|
+
if (profile.traits.multiStepStability === "low" || profile.traits.multiStepStability === "medium") {
|
|
3274
|
+
strategies.push("\u5C06\u4EFB\u52A1\u62C6\u5206\u4E3A\u66F4\u5C0F\u7684\u72EC\u7ACB\u6B65\u9AA4\u540E\u9010\u4E00\u91CD\u8BD5");
|
|
3275
|
+
}
|
|
3276
|
+
if (profile.traits.hallucinationRisk === "high") {
|
|
3277
|
+
strategies.push("\u8981\u6C42\u6A21\u578B\u5728\u91CD\u8BD5\u65F6\u4E3A\u6BCF\u6761\u7ED3\u8BBA\u9644\u4E0A\u4EE3\u7801\u884C\u53F7\u5F15\u7528");
|
|
3278
|
+
}
|
|
3279
|
+
if (profile.preferences.needsStopConditions) {
|
|
3280
|
+
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");
|
|
3281
|
+
}
|
|
3282
|
+
if (profile.traits.selfCorrection !== "high") {
|
|
3283
|
+
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");
|
|
3284
|
+
}
|
|
3285
|
+
return strategies;
|
|
3286
|
+
}
|
|
3287
|
+
function resolveMaxRepeatedFailures(selfCorrection) {
|
|
3288
|
+
return selfCorrection === "high" ? 3 : 2;
|
|
3289
|
+
}
|
|
3290
|
+
function resolveRecipe(profile, taskType, baselineWorkflow, inheritedSkills) {
|
|
3291
|
+
return {
|
|
3292
|
+
model: profile.model,
|
|
3293
|
+
taskType,
|
|
3294
|
+
inheritedSkills,
|
|
3295
|
+
baselineWorkflow,
|
|
3296
|
+
inputStyle: resolveInputStyle(profile.preferences.promptStyle),
|
|
3297
|
+
contextStrategy: resolveContextStrategy(profile.preferences.contextOrder),
|
|
3298
|
+
granularity: resolveGranularity(profile.preferences.stepSize),
|
|
3299
|
+
outputContract: {
|
|
3300
|
+
format: resolveOutputFormat(profile.preferences.promptStyle),
|
|
3301
|
+
mustCiteEvidence: profile.traits.hallucinationRisk !== "low",
|
|
3302
|
+
mustListUncertainty: profile.traits.selfCorrection !== "high"
|
|
3303
|
+
},
|
|
3304
|
+
verificationStyle: resolveVerificationStyle(
|
|
3305
|
+
profile.traits.selfCorrection,
|
|
3306
|
+
profile.traits.hallucinationRisk
|
|
3307
|
+
),
|
|
3308
|
+
failureModes: resolveFailureModes(profile, taskType),
|
|
3309
|
+
repairStrategies: resolveRepairStrategies(profile),
|
|
3310
|
+
escalationThreshold: {
|
|
3311
|
+
maxRepeatedFailures: resolveMaxRepeatedFailures(
|
|
3312
|
+
profile.traits.selfCorrection
|
|
3313
|
+
),
|
|
3314
|
+
criticalFailures: [
|
|
3315
|
+
"\u8F93\u51FA\u4E3A\u7A7A",
|
|
3316
|
+
"\u65E0\u6CD5\u7406\u89E3\u4EFB\u52A1\u76EE\u6807",
|
|
3317
|
+
"\u5FAA\u73AF\u91CD\u590D\u76F8\u540C\u5185\u5BB9\u8D85\u8FC7 2 \u6B21"
|
|
3318
|
+
]
|
|
3319
|
+
}
|
|
3320
|
+
};
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
// src/meta_skill/policy-builder.ts
|
|
3324
|
+
function buildContextOrder(contextStrategy, granularity, constraints, paths) {
|
|
3325
|
+
const hasConstraints = Boolean(constraints && constraints.length > 0);
|
|
3326
|
+
const hasPaths = Boolean(paths && paths.length > 0);
|
|
3327
|
+
let order;
|
|
3328
|
+
if (contextStrategy.includes("\u5148\u7ED9\u51FA\u4EFB\u52A1\u76EE\u6807")) {
|
|
3329
|
+
order = ["\u4EFB\u52A1\u76EE\u6807"];
|
|
3330
|
+
if (hasConstraints) order.push("\u7EA6\u675F\u6761\u4EF6");
|
|
3331
|
+
if (hasPaths) order.push("\u4EE3\u7801\u6750\u6599");
|
|
3332
|
+
order.push("\u8F93\u51FA\u683C\u5F0F\u8981\u6C42");
|
|
3333
|
+
} else if (contextStrategy.includes("\u5148\u7ED9\u51FA\u8F93\u51FA\u6A21\u677F")) {
|
|
3334
|
+
order = ["\u8F93\u51FA\u683C\u5F0F\u8981\u6C42", "\u4EFB\u52A1\u76EE\u6807"];
|
|
3335
|
+
if (hasConstraints) order.push("\u7EA6\u675F\u6761\u4EF6");
|
|
3336
|
+
if (hasPaths) order.push("\u4EE3\u7801\u6750\u6599");
|
|
3337
|
+
} else {
|
|
3338
|
+
order = [];
|
|
3339
|
+
if (hasPaths) order.push("\u4EE3\u7801\u6750\u6599");
|
|
3340
|
+
order.push("\u4EFB\u52A1\u76EE\u6807");
|
|
3341
|
+
if (hasConstraints) order.push("\u7EA6\u675F\u6761\u4EF6");
|
|
3342
|
+
order.push("\u8F93\u51FA\u683C\u5F0F\u8981\u6C42");
|
|
3343
|
+
}
|
|
3344
|
+
if (granularity === "stepwise") {
|
|
3345
|
+
order = order.filter((item) => item !== "\u4EFB\u52A1\u76EE\u6807");
|
|
3346
|
+
order = ["\u4EFB\u52A1\u76EE\u6807", ...order];
|
|
3347
|
+
if (!order.includes("\u5DE5\u4F5C\u6D41\u6B65\u9AA4")) order.push("\u5DE5\u4F5C\u6D41\u6B65\u9AA4");
|
|
3348
|
+
order = order.filter((item) => item !== "\u8F93\u51FA\u683C\u5F0F\u8981\u6C42");
|
|
3349
|
+
order.push("\u8F93\u51FA\u683C\u5F0F\u8981\u6C42");
|
|
3350
|
+
}
|
|
3351
|
+
return order;
|
|
3352
|
+
}
|
|
3353
|
+
function resolveMaxMaterials(granularity) {
|
|
3354
|
+
const map = {
|
|
3355
|
+
"large-batch": 10,
|
|
3356
|
+
"file-level-first": 5,
|
|
3357
|
+
"small-batch": 3,
|
|
3358
|
+
stepwise: 2
|
|
3359
|
+
};
|
|
3360
|
+
return map[granularity];
|
|
3361
|
+
}
|
|
3362
|
+
function buildPolicy(recipe, input) {
|
|
3363
|
+
const maxSteps = input.runtimeContext?.budget?.maxSteps ?? 8;
|
|
3364
|
+
const stepPlan = recipe.baselineWorkflow.slice(0, maxSteps);
|
|
3365
|
+
const mode = stepPlan.length > 1 ? "multi_step" : "single_step";
|
|
3366
|
+
const order = buildContextOrder(
|
|
3367
|
+
recipe.contextStrategy,
|
|
3368
|
+
recipe.granularity,
|
|
3369
|
+
input.task.constraints,
|
|
3370
|
+
input.task.scope?.paths
|
|
3371
|
+
);
|
|
3372
|
+
const maxMaterialsPerStep = resolveMaxMaterials(recipe.granularity);
|
|
3373
|
+
return {
|
|
3374
|
+
mode,
|
|
3375
|
+
stepPlan,
|
|
3376
|
+
selectedSkills: recipe.inheritedSkills,
|
|
3377
|
+
contextPackaging: {
|
|
3378
|
+
order,
|
|
3379
|
+
maxMaterialsPerStep
|
|
3380
|
+
},
|
|
3381
|
+
outputContract: { ...recipe.outputContract },
|
|
3382
|
+
revisionPolicy: {
|
|
3383
|
+
maxRetries: recipe.escalationThreshold.maxRepeatedFailures,
|
|
3384
|
+
retryStyle: recipe.repairStrategies[0] ?? "\u7F29\u51CF\u8F93\u5165\u91CF\u540E\u91CD\u8BD5"
|
|
3385
|
+
},
|
|
3386
|
+
escalationPolicy: {
|
|
3387
|
+
escalateOn: recipe.escalationThreshold.criticalFailures
|
|
3388
|
+
}
|
|
3389
|
+
};
|
|
3390
|
+
}
|
|
3391
|
+
|
|
3392
|
+
// src/meta_skill/materializer.ts
|
|
3393
|
+
function buildTaskCard(policy, profile, input) {
|
|
3394
|
+
const taskType = input.task.type ?? "\uFF08\u672A\u6307\u5B9A\uFF0C\u5F85\u5206\u7C7B\uFF09";
|
|
3395
|
+
const modeLabel = policy.mode === "multi_step" ? "\u591A\u6B65\u6267\u884C" : "\u5355\u6B65\u6267\u884C";
|
|
3396
|
+
const lines = [
|
|
3397
|
+
`# \u4EFB\u52A1\u8BF4\u660E\u5361`,
|
|
3398
|
+
``,
|
|
3399
|
+
`| \u5B57\u6BB5 | \u503C |`,
|
|
3400
|
+
`|------|-----|`,
|
|
3401
|
+
`| \u6A21\u578B | ${profile.model} |`,
|
|
3402
|
+
`| \u4EFB\u52A1\u7C7B\u578B | ${taskType} |`,
|
|
3403
|
+
`| \u6267\u884C\u6A21\u5F0F | ${modeLabel} |`,
|
|
3404
|
+
``,
|
|
3405
|
+
`## \u76EE\u6807`,
|
|
3406
|
+
``,
|
|
3407
|
+
input.task.goal,
|
|
3408
|
+
``
|
|
3409
|
+
];
|
|
3410
|
+
if (input.task.constraints && input.task.constraints.length > 0) {
|
|
3411
|
+
lines.push(`## \u7EA6\u675F`);
|
|
3412
|
+
lines.push(``);
|
|
3413
|
+
for (const c of input.task.constraints) {
|
|
3414
|
+
lines.push(`- ${c}`);
|
|
3415
|
+
}
|
|
3416
|
+
lines.push(``);
|
|
3417
|
+
}
|
|
3418
|
+
lines.push(`## \u9009\u7528 Skills`);
|
|
3419
|
+
lines.push(``);
|
|
3420
|
+
if (policy.selectedSkills.length > 0) {
|
|
3421
|
+
for (const skill of policy.selectedSkills) {
|
|
3422
|
+
lines.push(`- ${skill}`);
|
|
3423
|
+
}
|
|
3424
|
+
} else {
|
|
3425
|
+
lines.push(`- \uFF08\u65E0\uFF09`);
|
|
3426
|
+
}
|
|
3427
|
+
lines.push(``);
|
|
3428
|
+
lines.push(`## \u6267\u884C\u6B65\u9AA4`);
|
|
3429
|
+
lines.push(``);
|
|
3430
|
+
policy.stepPlan.forEach((step, idx) => {
|
|
3431
|
+
lines.push(`${idx + 1}. ${step}`);
|
|
3432
|
+
});
|
|
3433
|
+
lines.push(``);
|
|
3434
|
+
lines.push(`## \u8F93\u51FA\u8981\u6C42`);
|
|
3435
|
+
lines.push(``);
|
|
3436
|
+
lines.push(`- \u683C\u5F0F\uFF1A${policy.outputContract.format}`);
|
|
3437
|
+
if (policy.outputContract.mustCiteEvidence) {
|
|
3438
|
+
lines.push(`- \u5FC5\u987B\u5F15\u7528\u4EE3\u7801\u8BC1\u636E`);
|
|
3439
|
+
}
|
|
3440
|
+
if (policy.outputContract.mustListUncertainty) {
|
|
3441
|
+
lines.push(`- \u5FC5\u987B\u5217\u51FA\u4E0D\u786E\u5B9A\u9879`);
|
|
3442
|
+
}
|
|
3443
|
+
return lines.join("\n");
|
|
3444
|
+
}
|
|
3445
|
+
function buildStrictTemplateWorkerPrompt(policy, input) {
|
|
3446
|
+
const sections = [];
|
|
3447
|
+
sections.push(`\u3010\u4EFB\u52A1\u76EE\u6807\u3011
|
|
3448
|
+
${input.task.goal}`);
|
|
3449
|
+
if (input.task.constraints && input.task.constraints.length > 0) {
|
|
3450
|
+
sections.push(
|
|
3451
|
+
`\u3010\u7EA6\u675F\u6761\u4EF6\u3011
|
|
3452
|
+
${input.task.constraints.map((c) => `- ${c}`).join("\n")}`
|
|
3453
|
+
);
|
|
3454
|
+
}
|
|
3455
|
+
const stepsText = policy.stepPlan.map((step, i) => `${i + 1}. ${step}`).join("\n");
|
|
3456
|
+
sections.push(
|
|
3457
|
+
`\u3010\u6267\u884C\u6B65\u9AA4\u3011\uFF08\u5FC5\u987B\u6309\u5E8F\uFF0C\u4E0D\u5F97\u8DF3\u6B65\uFF09
|
|
3458
|
+
${stepsText}`
|
|
3459
|
+
);
|
|
3460
|
+
const evidenceNote = policy.outputContract.mustCiteEvidence ? "\n- \u6BCF\u9879\u7ED3\u8BBA\u5FC5\u987B\u9644\u4EE3\u7801\u884C\u53F7\u6216\u539F\u6587\u5F15\u7528" : "";
|
|
3461
|
+
const uncertaintyNote = policy.outputContract.mustListUncertainty ? "\n- \u4E0D\u786E\u5B9A\u9879\u987B\u5355\u72EC\u5217\u51FA\uFF0C\u4E0D\u5F97\u6DF7\u5165\u7ED3\u8BBA" : "";
|
|
3462
|
+
sections.push(
|
|
3463
|
+
`\u3010\u8F93\u51FA\u683C\u5F0F\u3011
|
|
3464
|
+
\u683C\u5F0F\u8981\u6C42\uFF1A${policy.outputContract.format}${evidenceNote}${uncertaintyNote}`
|
|
3465
|
+
);
|
|
3466
|
+
sections.push(
|
|
3467
|
+
`\u3010\u505C\u6B62\u6761\u4EF6\u3011
|
|
3468
|
+
\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`
|
|
3469
|
+
);
|
|
3470
|
+
return sections.join("\n\n");
|
|
3471
|
+
}
|
|
3472
|
+
function buildExplicitChecklistWorkerPrompt(policy, input) {
|
|
3473
|
+
const lines = [];
|
|
3474
|
+
lines.push(`## \u4EFB\u52A1\u76EE\u6807
|
|
3475
|
+
|
|
3476
|
+
${input.task.goal}`);
|
|
3477
|
+
if (input.task.constraints && input.task.constraints.length > 0) {
|
|
3478
|
+
lines.push(
|
|
3479
|
+
`
|
|
3480
|
+
## \u7EA6\u675F\u6761\u4EF6
|
|
3481
|
+
|
|
3482
|
+
${input.task.constraints.map((c) => `- ${c}`).join("\n")}`
|
|
3483
|
+
);
|
|
3484
|
+
}
|
|
3485
|
+
lines.push(`
|
|
3486
|
+
## \u6267\u884C\u6B65\u9AA4
|
|
3487
|
+
`);
|
|
3488
|
+
for (const step of policy.stepPlan) {
|
|
3489
|
+
lines.push(`- [ ] ${step}`);
|
|
3490
|
+
}
|
|
3491
|
+
lines.push(`
|
|
3492
|
+
## \u8F93\u51FA\u683C\u5F0F
|
|
3493
|
+
`);
|
|
3494
|
+
lines.push(`- \u683C\u5F0F\uFF1A${policy.outputContract.format}`);
|
|
3495
|
+
if (policy.outputContract.mustCiteEvidence) {
|
|
3496
|
+
lines.push(`- \u6CE8\u610F\uFF1A\u6BCF\u9879\u7ED3\u8BBA\u987B\u9644\u4EE3\u7801\u8BC1\u636E\uFF08\u884C\u53F7\u6216\u539F\u6587\u7247\u6BB5\uFF09`);
|
|
3497
|
+
}
|
|
3498
|
+
return lines.join("\n");
|
|
3499
|
+
}
|
|
3500
|
+
function buildFreeformWorkerPrompt(policy, input) {
|
|
3501
|
+
const paragraphs = [];
|
|
3502
|
+
paragraphs.push(`\u8BF7\u5B8C\u6210\u4EE5\u4E0B\u4EFB\u52A1\uFF1A${input.task.goal}`);
|
|
3503
|
+
if (input.task.constraints && input.task.constraints.length > 0) {
|
|
3504
|
+
paragraphs.push(
|
|
3505
|
+
`\u6267\u884C\u65F6\u9700\u9075\u5B88\u4EE5\u4E0B\u7EA6\u675F\uFF1A${input.task.constraints.join("\uFF1B")}\u3002`
|
|
3506
|
+
);
|
|
3507
|
+
}
|
|
3508
|
+
paragraphs.push(
|
|
3509
|
+
`\u6267\u884C\u987A\u5E8F\u5982\u4E0B\uFF1A${policy.stepPlan.map((s, i) => `\uFF08${i + 1}\uFF09${s}`).join(" \u2192 ")}\u3002`
|
|
3510
|
+
);
|
|
3511
|
+
const evidencePart = policy.outputContract.mustCiteEvidence ? " \u6BCF\u9879\u7ED3\u8BBA\u9700\u9644\u5F15\u7528\u8BC1\u636E\u3002" : "";
|
|
3512
|
+
const uncertaintyPart = policy.outputContract.mustListUncertainty ? " \u4E0D\u786E\u5B9A\u4E4B\u5904\u8BF7\u5355\u72EC\u5217\u660E\u3002" : "";
|
|
3513
|
+
paragraphs.push(
|
|
3514
|
+
`\u8F93\u51FA\u683C\u5F0F\u4E3A ${policy.outputContract.format}\u3002${evidencePart}${uncertaintyPart}`
|
|
3515
|
+
);
|
|
3516
|
+
return paragraphs.join("\n\n");
|
|
3517
|
+
}
|
|
3518
|
+
function buildWorkerPrompt(policy, profile, input) {
|
|
3519
|
+
switch (profile.preferences.promptStyle) {
|
|
3520
|
+
case "strict-template":
|
|
3521
|
+
return buildStrictTemplateWorkerPrompt(policy, input);
|
|
3522
|
+
case "explicit-checklist":
|
|
3523
|
+
return buildExplicitChecklistWorkerPrompt(policy, input);
|
|
3524
|
+
case "freeform":
|
|
3525
|
+
default:
|
|
3526
|
+
return buildFreeformWorkerPrompt(policy, input);
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
function buildJudgePrompt(policy, input) {
|
|
3530
|
+
const lines = [
|
|
3531
|
+
`# Judge \u8BC4\u4F30 Prompt`,
|
|
3532
|
+
``,
|
|
3533
|
+
`\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`,
|
|
3534
|
+
``,
|
|
3535
|
+
`## \u6838\u67E5\u6E05\u5355`,
|
|
3536
|
+
``
|
|
3537
|
+
];
|
|
3538
|
+
policy.stepPlan.forEach((step, idx) => {
|
|
3539
|
+
lines.push(`- [ ] \u6B65\u9AA4 ${idx + 1} \u5DF2\u5B8C\u6210\uFF1A${step}`);
|
|
3540
|
+
});
|
|
3541
|
+
if (policy.outputContract.mustCiteEvidence) {
|
|
3542
|
+
lines.push(`- [ ] \u6BCF\u9879\u7ED3\u8BBA\u5747\u9644\u6709\u4EE3\u7801\u8BC1\u636E\uFF08\u884C\u53F7\u6216\u539F\u6587\u5F15\u7528\uFF09`);
|
|
3543
|
+
}
|
|
3544
|
+
if (policy.outputContract.mustListUncertainty) {
|
|
3545
|
+
lines.push(`- [ ] \u4E0D\u786E\u5B9A\u9879\u5DF2\u5355\u72EC\u5217\u51FA\uFF0C\u672A\u6DF7\u5165\u7ED3\u8BBA`);
|
|
3546
|
+
}
|
|
3547
|
+
lines.push(
|
|
3548
|
+
`- [ ] \u8F93\u51FA\u683C\u5F0F\u7B26\u5408\u8981\u6C42\uFF08\u671F\u671B\u683C\u5F0F\uFF1A${policy.outputContract.format}\uFF09`
|
|
3549
|
+
);
|
|
3550
|
+
lines.push(``);
|
|
3551
|
+
lines.push(`## \u8BC4\u5206\u7EF4\u5EA6\uFF08\u5404\u7EF4\u5EA6 0\u201310 \u5206\uFF09`);
|
|
3552
|
+
lines.push(``);
|
|
3553
|
+
lines.push(`| \u7EF4\u5EA6 | \u5F97\u5206 | \u8BF4\u660E |`);
|
|
3554
|
+
lines.push(`|------|------|------|`);
|
|
3555
|
+
lines.push(`| \u5B8C\u6574\u6027 | \u2014 | \u6240\u6709\u6B65\u9AA4\u662F\u5426\u5168\u90E8\u5B8C\u6210 |`);
|
|
3556
|
+
lines.push(`| \u8BC1\u636E\u8D28\u91CF | \u2014 | \u5F15\u7528\u662F\u5426\u51C6\u786E\u4E14\u5145\u5206 |`);
|
|
3557
|
+
lines.push(`| \u683C\u5F0F\u89C4\u8303 | \u2014 | \u8F93\u51FA\u662F\u5426\u7B26\u5408\u6307\u5B9A\u683C\u5F0F |`);
|
|
3558
|
+
lines.push(``);
|
|
3559
|
+
lines.push(`## \u6700\u7EC8\u88C1\u5B9A`);
|
|
3560
|
+
lines.push(``);
|
|
3561
|
+
lines.push(`\u4ECE\u4EE5\u4E0B\u4E09\u9879\u4E2D\u9009\u62E9\u4E00\u9879\uFF1A`);
|
|
3562
|
+
lines.push(``);
|
|
3563
|
+
lines.push(`- **pass**\uFF1A\u6240\u6709\u6E05\u5355\u9879\u901A\u8FC7\uFF0C\u4E09\u4E2A\u7EF4\u5EA6\u5747 \u2265 7 \u5206`);
|
|
3564
|
+
lines.push(
|
|
3565
|
+
`- **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}`
|
|
3566
|
+
);
|
|
3567
|
+
if (policy.escalationPolicy.escalateOn.length > 0) {
|
|
3568
|
+
const triggers = policy.escalationPolicy.escalateOn.join("\u3001");
|
|
3569
|
+
lines.push(
|
|
3570
|
+
`- **escalate**\uFF1A\u9047\u5230\u4EE5\u4E0B\u60C5\u5F62\u65F6\u5FC5\u987B\u5347\u7EA7\uFF0C\u4E0D\u5F97\u5C1D\u8BD5\u4FEE\u590D\uFF1A${triggers}`
|
|
3571
|
+
);
|
|
3572
|
+
} else {
|
|
3573
|
+
lines.push(`- **escalate**\uFF1A\u9047\u5230\u65E0\u6CD5\u901A\u8FC7\u91CD\u8BD5\u4FEE\u590D\u7684\u6839\u672C\u6027\u95EE\u9898\u65F6\u5347\u7EA7`);
|
|
3574
|
+
}
|
|
3575
|
+
lines.push(``);
|
|
3576
|
+
lines.push(`> \u88C1\u5B9A\u683C\u5F0F\uFF1A\u5728\u6587\u672B\u5355\u72EC\u4E00\u884C\u5199 \`verdict: pass\` / \`verdict: revise\` / \`verdict: escalate\`\u3002`);
|
|
3577
|
+
return lines.join("\n");
|
|
3578
|
+
}
|
|
3579
|
+
function materialize(policy, profile, input) {
|
|
3580
|
+
return {
|
|
3581
|
+
taskCard: buildTaskCard(policy, profile, input),
|
|
3582
|
+
workerPrompt: buildWorkerPrompt(policy, profile, input),
|
|
3583
|
+
judgePrompt: buildJudgePrompt(policy, input)
|
|
3584
|
+
};
|
|
3585
|
+
}
|
|
3586
|
+
|
|
3587
|
+
// src/meta_skill/learning-store.ts
|
|
3588
|
+
import * as fs10 from "fs";
|
|
3589
|
+
import * as path8 from "path";
|
|
3590
|
+
import * as os from "os";
|
|
3591
|
+
var STORE_PATH = path8.resolve(os.homedir(), ".ecode", "learning-records.jsonl");
|
|
3592
|
+
|
|
3593
|
+
// src/meta_skill/index.ts
|
|
3594
|
+
function runMetaAlign(input) {
|
|
3595
|
+
const taskType = input.task.type && isValidTaskType(input.task.type) ? input.task.type : classifyTask(input.task.goal);
|
|
3596
|
+
const inheritedSkills = getBaselineSkills(taskType);
|
|
3597
|
+
const allSteps = [];
|
|
3598
|
+
for (const skillName of inheritedSkills) {
|
|
3599
|
+
const primaryPath = path9.resolve(process.cwd(), "skills", skillName, "SKILL.md");
|
|
3600
|
+
const fallbackPath = path9.resolve(process.cwd(), "skills", skillName + ".md");
|
|
3601
|
+
let body = "";
|
|
3602
|
+
if (fs11.existsSync(primaryPath)) {
|
|
3603
|
+
body = fs11.readFileSync(primaryPath, { encoding: "utf-8" });
|
|
3604
|
+
} else if (fs11.existsSync(fallbackPath)) {
|
|
3605
|
+
body = fs11.readFileSync(fallbackPath, { encoding: "utf-8" });
|
|
3606
|
+
}
|
|
3607
|
+
const steps = extractWorkflowSteps(body);
|
|
3608
|
+
allSteps.push(...steps);
|
|
3609
|
+
}
|
|
3610
|
+
const baselineWorkflow = [...new Set(allSteps)].slice(0, 12);
|
|
3611
|
+
const profile = getModelProfile(input.model.name);
|
|
3612
|
+
const recipe = resolveRecipe(profile, taskType, baselineWorkflow, inheritedSkills);
|
|
3613
|
+
const policy = buildPolicy(recipe, input);
|
|
3614
|
+
const artifacts = materialize(policy, profile, input);
|
|
3615
|
+
const strengths = [];
|
|
3616
|
+
const weaknesses = [];
|
|
3617
|
+
const t = profile.traits;
|
|
3618
|
+
if (t.instructionFollowing === "high") strengths.push("\u6307\u4EE4\u8DDF\u968F\u80FD\u529B\u5F3A");
|
|
3619
|
+
else if (t.instructionFollowing === "low") weaknesses.push("\u6307\u4EE4\u8DDF\u968F\u80FD\u529B\u5F31");
|
|
3620
|
+
if (t.schemaDiscipline === "high") strengths.push("\u7ED3\u6784\u5316\u8F93\u51FA\u9075\u5B88\u7A0B\u5EA6\u9AD8");
|
|
3621
|
+
else if (t.schemaDiscipline === "low") weaknesses.push("\u7ED3\u6784\u5316\u8F93\u51FA\u9075\u5B88\u7A0B\u5EA6\u4F4E");
|
|
3622
|
+
if (t.longContextStability === "high") strengths.push("\u957F\u4E0A\u4E0B\u6587\u7A33\u5B9A\u6027\u597D");
|
|
3623
|
+
else if (t.longContextStability === "low") weaknesses.push("\u957F\u4E0A\u4E0B\u6587\u7A33\u5B9A\u6027\u5DEE");
|
|
3624
|
+
if (t.multiStepStability === "high") strengths.push("\u591A\u6B65\u63A8\u7406\u7A33\u5B9A");
|
|
3625
|
+
else if (t.multiStepStability === "low") weaknesses.push("\u591A\u6B65\u63A8\u7406\u7A33\u5B9A\u6027\u4F4E");
|
|
3626
|
+
if (t.hallucinationRisk === "low") strengths.push("\u5E7B\u89C9\u98CE\u9669\u4F4E");
|
|
3627
|
+
else if (t.hallucinationRisk === "high") weaknesses.push("\u5E7B\u89C9\u98CE\u9669\u9AD8");
|
|
3628
|
+
if (t.selfCorrection === "high") strengths.push("\u81EA\u6211\u7EA0\u9519\u80FD\u529B\u5F3A");
|
|
3629
|
+
else if (t.selfCorrection === "low") weaknesses.push("\u81EA\u6211\u7EA0\u9519\u80FD\u529B\u5F31");
|
|
3630
|
+
const modelProfileSummary = {
|
|
3631
|
+
strengths,
|
|
3632
|
+
weaknesses,
|
|
3633
|
+
promptStyle: profile.preferences.promptStyle
|
|
3634
|
+
};
|
|
3635
|
+
return {
|
|
3636
|
+
resolvedTaskType: taskType,
|
|
3637
|
+
modelProfileSummary,
|
|
3638
|
+
executionPolicy: policy,
|
|
3639
|
+
materializedArtifacts: artifacts,
|
|
3640
|
+
recipeCandidate: {
|
|
3641
|
+
model: recipe.model,
|
|
3642
|
+
taskType: recipe.taskType,
|
|
3643
|
+
inheritedSkills: recipe.inheritedSkills
|
|
3644
|
+
}
|
|
3645
|
+
};
|
|
3646
|
+
}
|
|
3647
|
+
|
|
2870
3648
|
// src/ui/App.tsx
|
|
2871
3649
|
import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2872
3650
|
async function handleAutomationCommand(input, manager, sessionContext) {
|
|
@@ -2890,6 +3668,95 @@ async function handleAutomationCommand(input, manager, sessionContext) {
|
|
|
2890
3668
|
return null;
|
|
2891
3669
|
}
|
|
2892
3670
|
}
|
|
3671
|
+
function handleMetaAlignCommand(input) {
|
|
3672
|
+
if (!input.startsWith("/meta-align")) return null;
|
|
3673
|
+
const parts = input.slice("/meta-align".length).trim().split(/\s+/);
|
|
3674
|
+
if (parts.length === 0 || !parts[0]) {
|
|
3675
|
+
return [
|
|
3676
|
+
"**\u7528\u6CD5\uFF1A** `/meta-align <model> [task-type] [goal]`",
|
|
3677
|
+
"",
|
|
3678
|
+
"**\u793A\u4F8B\uFF1A**",
|
|
3679
|
+
"- `/meta-align gpt-4o bugfix \u4FEE\u590D\u767B\u5F55\u9875\u5D29\u6E83\u95EE\u9898`",
|
|
3680
|
+
"- `/meta-align MiniMax-M2.5 code-review`",
|
|
3681
|
+
"- `/meta-align deepseek-chat \u9006\u5411\u5206\u6790 src/ui \u76EE\u5F55\u7ED3\u6784`"
|
|
3682
|
+
].join("\n");
|
|
3683
|
+
}
|
|
3684
|
+
const VALID_TASK_TYPES = /* @__PURE__ */ new Set([
|
|
3685
|
+
"bugfix",
|
|
3686
|
+
"refactor",
|
|
3687
|
+
"test-generation",
|
|
3688
|
+
"code-review",
|
|
3689
|
+
"code-reverse-design"
|
|
3690
|
+
]);
|
|
3691
|
+
const model = parts[0];
|
|
3692
|
+
let taskType;
|
|
3693
|
+
let goalParts;
|
|
3694
|
+
if (parts.length >= 2 && VALID_TASK_TYPES.has(parts[1])) {
|
|
3695
|
+
taskType = parts[1];
|
|
3696
|
+
goalParts = parts.slice(2);
|
|
3697
|
+
} else {
|
|
3698
|
+
goalParts = parts.slice(1);
|
|
3699
|
+
}
|
|
3700
|
+
const goal = goalParts.join(" ") || `\u4F7F\u7528 ${model} \u5B8C\u6210\u4EFB\u52A1`;
|
|
3701
|
+
const alignInput = {
|
|
3702
|
+
model: { name: model },
|
|
3703
|
+
task: {
|
|
3704
|
+
type: taskType,
|
|
3705
|
+
goal
|
|
3706
|
+
}
|
|
3707
|
+
};
|
|
3708
|
+
try {
|
|
3709
|
+
const result = runMetaAlign(alignInput);
|
|
3710
|
+
return formatMetaAlignOutput(result, model);
|
|
3711
|
+
} catch (err) {
|
|
3712
|
+
return `**[meta-align \u9519\u8BEF]** ${String(err)}`;
|
|
3713
|
+
}
|
|
3714
|
+
}
|
|
3715
|
+
function formatMetaAlignOutput(result, model) {
|
|
3716
|
+
const { resolvedTaskType, modelProfileSummary, executionPolicy, materializedArtifacts } = result;
|
|
3717
|
+
const lines = [
|
|
3718
|
+
`## meta-align \u7ED3\u679C`,
|
|
3719
|
+
``,
|
|
3720
|
+
`**\u6A21\u578B\uFF1A** ${model} `,
|
|
3721
|
+
`**\u4EFB\u52A1\u7C7B\u578B\uFF1A** ${resolvedTaskType} `,
|
|
3722
|
+
`**\u6267\u884C\u6A21\u5F0F\uFF1A** ${executionPolicy.mode === "multi_step" ? "\u591A\u6B65\u6267\u884C" : "\u5355\u6B65\u6267\u884C"}`,
|
|
3723
|
+
``
|
|
3724
|
+
];
|
|
3725
|
+
if (modelProfileSummary.strengths.length > 0) {
|
|
3726
|
+
lines.push(`### \u6A21\u578B\u4F18\u52BF`);
|
|
3727
|
+
for (const s of modelProfileSummary.strengths) lines.push(`- ${s}`);
|
|
3728
|
+
lines.push(``);
|
|
3729
|
+
}
|
|
3730
|
+
if (modelProfileSummary.weaknesses.length > 0) {
|
|
3731
|
+
lines.push(`### \u6A21\u578B\u5F31\u70B9`);
|
|
3732
|
+
for (const w of modelProfileSummary.weaknesses) lines.push(`- ${w}`);
|
|
3733
|
+
lines.push(``);
|
|
3734
|
+
}
|
|
3735
|
+
if (executionPolicy.selectedSkills.length > 0) {
|
|
3736
|
+
lines.push(`### \u9009\u7528 Skills`);
|
|
3737
|
+
for (const sk of executionPolicy.selectedSkills) lines.push(`- \`${sk}\``);
|
|
3738
|
+
lines.push(``);
|
|
3739
|
+
}
|
|
3740
|
+
if (executionPolicy.stepPlan.length > 0) {
|
|
3741
|
+
lines.push(`### \u6267\u884C\u6B65\u9AA4`);
|
|
3742
|
+
executionPolicy.stepPlan.forEach((step, i) => lines.push(`${i + 1}. ${step}`));
|
|
3743
|
+
lines.push(``);
|
|
3744
|
+
}
|
|
3745
|
+
lines.push(`### \u4E0A\u4E0B\u6587\u5C01\u88C5\u987A\u5E8F`);
|
|
3746
|
+
executionPolicy.contextPackaging.order.forEach((o, i) => lines.push(`${i + 1}. ${o}`));
|
|
3747
|
+
lines.push(``);
|
|
3748
|
+
lines.push(`### Worker Prompt`);
|
|
3749
|
+
lines.push(``);
|
|
3750
|
+
lines.push("```");
|
|
3751
|
+
lines.push(materializedArtifacts.workerPrompt);
|
|
3752
|
+
lines.push("```");
|
|
3753
|
+
lines.push(``);
|
|
3754
|
+
lines.push(
|
|
3755
|
+
`**Retry \u7B56\u7565\uFF1A** \u6700\u591A ${executionPolicy.revisionPolicy.maxRetries} \u6B21 `,
|
|
3756
|
+
`**Retry \u65B9\u5F0F\uFF1A** ${executionPolicy.revisionPolicy.retryStyle}`
|
|
3757
|
+
);
|
|
3758
|
+
return lines.join("\n");
|
|
3759
|
+
}
|
|
2893
3760
|
function App({ config: config2, version: version2, autoMode: autoMode2 = false, registry: registry2, trustedSkillDirs: trustedSkillDirs2 = [], initialMessages: initialMessages2 = [], llmClient }) {
|
|
2894
3761
|
const { stdout } = useStdout();
|
|
2895
3762
|
const { stdin } = useStdin();
|
|
@@ -2923,7 +3790,7 @@ function App({ config: config2, version: version2, autoMode: autoMode2 = false,
|
|
|
2923
3790
|
const pendingConfirmRef = useRef2(null);
|
|
2924
3791
|
const abortControllerRef = useRef2(null);
|
|
2925
3792
|
const llmRef = useRef2(llmClient ?? createProvider(resolveActiveProfile(config2)));
|
|
2926
|
-
const automationDataDir = config2.logDir ? join10(config2.logDir, "automation") : join10(
|
|
3793
|
+
const automationDataDir = config2.logDir ? join10(config2.logDir, "automation") : join10(homedir3(), ".config", "ecode", "automation");
|
|
2927
3794
|
const automationManagerRef = useRef2(
|
|
2928
3795
|
new AutomationManager({
|
|
2929
3796
|
dataDir: automationDataDir,
|
|
@@ -3129,10 +3996,10 @@ function App({ config: config2, version: version2, autoMode: autoMode2 = false,
|
|
|
3129
3996
|
}
|
|
3130
3997
|
});
|
|
3131
3998
|
const confirm = useCallback((prompt) => {
|
|
3132
|
-
return new Promise((
|
|
3999
|
+
return new Promise((resolve7) => {
|
|
3133
4000
|
setStatus("awaiting_confirm");
|
|
3134
4001
|
setConfirmPrompt(prompt);
|
|
3135
|
-
pendingConfirmRef.current = { resolve:
|
|
4002
|
+
pendingConfirmRef.current = { resolve: resolve7 };
|
|
3136
4003
|
});
|
|
3137
4004
|
}, []);
|
|
3138
4005
|
const runLlmLoop = useCallback(
|
|
@@ -3363,6 +4230,17 @@ function App({ config: config2, version: version2, autoMode: autoMode2 = false,
|
|
|
3363
4230
|
return;
|
|
3364
4231
|
}
|
|
3365
4232
|
}
|
|
4233
|
+
{
|
|
4234
|
+
const metaAlignResult = handleMetaAlignCommand(trimmed);
|
|
4235
|
+
if (metaAlignResult !== null) {
|
|
4236
|
+
setMessages((prev) => [
|
|
4237
|
+
...prev,
|
|
4238
|
+
{ role: "user", content: trimmed },
|
|
4239
|
+
{ role: "assistant", content: metaAlignResult }
|
|
4240
|
+
]);
|
|
4241
|
+
return;
|
|
4242
|
+
}
|
|
4243
|
+
}
|
|
3366
4244
|
if (registry2) {
|
|
3367
4245
|
const skillResult = handleSkillInput(trimmed, registry2);
|
|
3368
4246
|
if (skillResult.type === "error") {
|
|
@@ -3644,19 +4522,19 @@ async function runPipe(prompt, llm, out = process.stdout, systemPrompt) {
|
|
|
3644
4522
|
}
|
|
3645
4523
|
}
|
|
3646
4524
|
function readStdin() {
|
|
3647
|
-
return new Promise((
|
|
4525
|
+
return new Promise((resolve7, reject) => {
|
|
3648
4526
|
let data = "";
|
|
3649
4527
|
process.stdin.setEncoding("utf-8");
|
|
3650
4528
|
process.stdin.on("data", (chunk) => {
|
|
3651
4529
|
data += chunk;
|
|
3652
4530
|
});
|
|
3653
|
-
process.stdin.on("end", () =>
|
|
4531
|
+
process.stdin.on("end", () => resolve7(data.trim()));
|
|
3654
4532
|
process.stdin.on("error", reject);
|
|
3655
4533
|
});
|
|
3656
4534
|
}
|
|
3657
4535
|
|
|
3658
4536
|
// src/sessions/command.ts
|
|
3659
|
-
import * as
|
|
4537
|
+
import * as path10 from "path";
|
|
3660
4538
|
function cmdSessionsList(logDir) {
|
|
3661
4539
|
const sessions = listSessions(logDir);
|
|
3662
4540
|
if (sessions.length === 0) return "(no sessions found)";
|
|
@@ -3678,13 +4556,13 @@ function cmdSessionsInspect(logDir, idOrPrefix) {
|
|
|
3678
4556
|
function cmdSessionsReplay(logDir, idOrPrefix) {
|
|
3679
4557
|
const session = findSession(logDir, idOrPrefix);
|
|
3680
4558
|
if (!session) return `Session not found: ${idOrPrefix}`;
|
|
3681
|
-
const logPath =
|
|
4559
|
+
const logPath = path10.join(logDir, session.logFile);
|
|
3682
4560
|
return `ecode --replay ${logPath}`;
|
|
3683
4561
|
}
|
|
3684
4562
|
function cmdSessionsFork(logDir, idOrPrefix, turn) {
|
|
3685
4563
|
const session = findSession(logDir, idOrPrefix);
|
|
3686
4564
|
if (!session) return `Session not found: ${idOrPrefix}`;
|
|
3687
|
-
const logPath =
|
|
4565
|
+
const logPath = path10.join(logDir, session.logFile);
|
|
3688
4566
|
const turnStr = turn !== void 0 ? turn : session.turnCount;
|
|
3689
4567
|
return `ecode --fork ${logPath}:${turnStr}`;
|
|
3690
4568
|
}
|
|
@@ -3698,7 +4576,7 @@ function formatInspect(session, logDir) {
|
|
|
3698
4576
|
`last active: ${new Date(session.lastActivity).toLocaleString()}`,
|
|
3699
4577
|
`turns: ${session.turnCount}`,
|
|
3700
4578
|
`tokens: ${session.totalTokens.toLocaleString()}`,
|
|
3701
|
-
`log file: ${
|
|
4579
|
+
`log file: ${path10.join(logDir, session.logFile)}`
|
|
3702
4580
|
].join("\n");
|
|
3703
4581
|
}
|
|
3704
4582
|
|
|
@@ -3804,7 +4682,7 @@ if (!finalConfig.apiKey) {
|
|
|
3804
4682
|
var initialMessages = [];
|
|
3805
4683
|
if (replayFile) {
|
|
3806
4684
|
try {
|
|
3807
|
-
const raw =
|
|
4685
|
+
const raw = readFileSync5(replayFile, "utf-8");
|
|
3808
4686
|
initialMessages = parseReplayLog(raw);
|
|
3809
4687
|
} catch (err) {
|
|
3810
4688
|
console.error(`Error reading replay file: ${err}`);
|
|
@@ -3812,17 +4690,17 @@ if (replayFile) {
|
|
|
3812
4690
|
}
|
|
3813
4691
|
} else if (forkSpec) {
|
|
3814
4692
|
try {
|
|
3815
|
-
const raw =
|
|
4693
|
+
const raw = readFileSync5(forkSpec.file, "utf-8");
|
|
3816
4694
|
initialMessages = truncateToTurn(parseReplayLog(raw), forkSpec.turn);
|
|
3817
4695
|
} catch (err) {
|
|
3818
4696
|
console.error(`Error reading fork file: ${err}`);
|
|
3819
4697
|
process.exit(1);
|
|
3820
4698
|
}
|
|
3821
4699
|
}
|
|
3822
|
-
var __dirname =
|
|
3823
|
-
var builtinSkillsDir =
|
|
3824
|
-
var userSkillsDir =
|
|
3825
|
-
var projectSkillsDir =
|
|
4700
|
+
var __dirname = dirname8(fileURLToPath(import.meta.url));
|
|
4701
|
+
var builtinSkillsDir = resolve6(__dirname, "../skills");
|
|
4702
|
+
var userSkillsDir = resolve6(process.env.HOME ?? "~", ".ecode/skills");
|
|
4703
|
+
var projectSkillsDir = resolve6(process.cwd(), ".ecode/skills");
|
|
3826
4704
|
var registry = new SkillRegistry();
|
|
3827
4705
|
for (const dir of [builtinSkillsDir, userSkillsDir, projectSkillsDir]) {
|
|
3828
4706
|
const skills = await loadSkillsFromDir(dir);
|