@evomap/evolver-cli 2.0.33 → 2.0.34
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/atp.js +6 -1
- package/dist/autoexec.d.ts +2 -6
- package/dist/autoexec.js +18 -17
- package/dist/distillObserver.js +21 -7
- package/dist/distillPrimitives.d.ts +39 -6
- package/dist/distillPrimitives.js +293 -75
- package/dist/index.js +153 -21
- package/dist/lifecycleBootstrapTransaction.js +123 -8
- package/dist/materialPackage.d.ts +4 -0
- package/dist/materialPackage.js +30 -9
- package/dist/materialSnapshot.d.ts +3 -0
- package/dist/materialSnapshot.js +49 -3
- package/dist/migrate/oauthImport.js +4 -1
- package/dist/setupHooks.js +121 -2
- package/dist/setupHooksLifecycle.d.ts +73 -0
- package/dist/setupHooksLifecycle.js +448 -0
- package/package.json +7 -7
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
//
|
|
2
|
-
// `evolver ingest --distill` and the live distillObserver reuse ONE copy (no forked distill logic). Zero behavior
|
|
3
|
-
// change vs the inline version: same tokens, same step drafting, same candidate shape. No I/O — the caller parses
|
|
4
|
-
// the session into turns + extracts signals; this turns them into a draft GeneCandidate (or null when too thin).
|
|
1
|
+
// ingest、observer 和 material package 共用的确定性起草器;只提取原文,不执行命令或调用模型。
|
|
5
2
|
import { algo, hub } from '@evomap/evolver-core';
|
|
6
3
|
// Map a strong signal's free-text to a SHORT, matchable token (so a gene's signals_match stays a few
|
|
7
4
|
// keywords, not a dumped error blob). Deterministic + testable; unknown errors fall back to the tool name only.
|
|
@@ -57,73 +54,271 @@ export function signalTokens(sigs) {
|
|
|
57
54
|
}
|
|
58
55
|
return [...set].slice(0, 8);
|
|
59
56
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
const MAX_STRATEGY_STEPS = 6;
|
|
58
|
+
const MAX_STEP_CHARS = 200;
|
|
59
|
+
// 仅用于保留物理版面;不扩展下方Markdown fence、段落或切句语法,也不替换字符。
|
|
60
|
+
const LAYOUT_LINE_BREAK = /[\r\n\u2028\u2029]/u;
|
|
61
|
+
const PREFIXED_SINGLE_QUOTE = /(?:^|[^\p{L}\p{N}_])(?:[rubf]|br|rb|fr|rf)$/iu;
|
|
62
|
+
function* textUnits(text) {
|
|
63
|
+
let start = 0;
|
|
64
|
+
let quote = '';
|
|
65
|
+
let fence = '';
|
|
66
|
+
const brackets = [];
|
|
67
|
+
const emit = (end, complete = true) => {
|
|
68
|
+
let first = start;
|
|
69
|
+
let firstLineStart = start;
|
|
70
|
+
let startsLine = start === 0 || LAYOUT_LINE_BREAK.test(text[start - 1]);
|
|
71
|
+
while (first < end && /\s/u.test(text[first])) {
|
|
72
|
+
if (LAYOUT_LINE_BREAK.test(text[first])) {
|
|
73
|
+
firstLineStart = first + 1;
|
|
74
|
+
startsLine = true;
|
|
75
|
+
}
|
|
76
|
+
first++;
|
|
77
|
+
}
|
|
78
|
+
let last = end;
|
|
79
|
+
while (last > first && /\s/u.test(text[last - 1]))
|
|
80
|
+
last--;
|
|
81
|
+
// 多行单元保留首行缩进;只剔除段落分隔,不改变代码各行的相对层级。
|
|
82
|
+
if (startsLine && LAYOUT_LINE_BREAK.test(text.slice(first, last)))
|
|
83
|
+
first = firstLineStart;
|
|
84
|
+
start = end;
|
|
85
|
+
return { start: first, end: last, complete };
|
|
86
|
+
};
|
|
87
|
+
for (let index = 0; index < text.length; index++) {
|
|
88
|
+
const char = text[index];
|
|
89
|
+
// fenced block 按整块保留,代码中的标点、空行和字符串不参与句子切分。
|
|
90
|
+
if (index === 0 || text[index - 1] === '\n' || text[index - 1] === '\r') {
|
|
91
|
+
const marker = /^[ \t]{0,3}(`{3,}|~{3,})[^\r\n]*/.exec(text.slice(index));
|
|
92
|
+
if (marker && !quote) {
|
|
93
|
+
const delimiter = marker[1];
|
|
94
|
+
if (!fence)
|
|
95
|
+
fence = delimiter;
|
|
96
|
+
else if (delimiter[0] === fence[0] && delimiter.length >= fence.length && marker[0].trim() === delimiter) {
|
|
97
|
+
fence = '';
|
|
98
|
+
yield emit(index + marker[0].length);
|
|
99
|
+
}
|
|
100
|
+
index += marker[0].length - 1;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (fence)
|
|
105
|
+
continue;
|
|
106
|
+
if (quote) {
|
|
107
|
+
if (char === '\\') {
|
|
108
|
+
index++;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (text.startsWith(quote, index)) {
|
|
112
|
+
index += quote.length - 1;
|
|
113
|
+
quote = '';
|
|
114
|
+
}
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (char === '`') {
|
|
118
|
+
quote = /^`+/.exec(text.slice(index))[0];
|
|
119
|
+
index += quote.length - 1;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
// 常见Python字符串前缀是quote的一部分;普通英文单词内的apostrophe仍不是字符串起点。
|
|
123
|
+
const prefixedQuote = char === "'" && PREFIXED_SINGLE_QUOTE.test(text.slice(Math.max(0, index - 4), index));
|
|
124
|
+
if (char === '"' || char === '“' || char === '‘'
|
|
125
|
+
|| (char === "'" && (prefixedQuote || !/[\p{L}\p{N}]/u.test(text[index - 1] ?? '')))) {
|
|
126
|
+
quote = char === '“' ? '”' : char === '‘' ? '’' : char;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if ('([{'.includes(char))
|
|
130
|
+
brackets.push(char);
|
|
131
|
+
else if (')]}'.includes(char) && brackets.length > 0) {
|
|
132
|
+
if ('([{'.indexOf(brackets.at(-1)) === ')]}'.indexOf(char))
|
|
133
|
+
brackets.pop();
|
|
134
|
+
}
|
|
135
|
+
if (brackets.length > 0)
|
|
136
|
+
continue;
|
|
137
|
+
const next = text.slice(index + 1);
|
|
138
|
+
const listMarker = char === '.' && /^\s*\d{1,3}$/.test(text.slice(start, index));
|
|
139
|
+
// A standalone '.' or '..' is a directory operand, not prose punctuation.
|
|
140
|
+
// Inspect only the token boundary; executable names do not define sentence grammar.
|
|
141
|
+
const dotStart = text[index - 1] === '.' ? index - 1 : index;
|
|
142
|
+
const directoryOperand = char === '.' && (dotStart === 0 || /\s/u.test(text[dotStart - 1]));
|
|
143
|
+
const sentenceEnd = /[。!?]/u.test(char)
|
|
144
|
+
|| (!listMarker && !directoryOperand && /[.!?]/u.test(char) && (next === '' || /^(?:\s|[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}])/u.test(next)));
|
|
145
|
+
const lineEnd = char === '\n' || (char === '\r' && text[index + 1] !== '\n');
|
|
146
|
+
const paragraphEnd = lineEnd && /^(?:[ \t]*(?:\r\n?|\n)|[ \t]*(?:[-*+] |\d+[.)] |Exit code:))/i.test(next);
|
|
147
|
+
if (sentenceEnd || paragraphEnd)
|
|
148
|
+
yield emit(index + 1);
|
|
149
|
+
}
|
|
150
|
+
if (start < text.length)
|
|
151
|
+
yield emit(text.length, quote === '' && fence === '' && brackets.length === 0);
|
|
70
152
|
}
|
|
71
|
-
/** Narration openers ("let me take a look / check / see …") — the agent saying it will go inspect. */
|
|
72
153
|
const NARRATION_OPENER = /^(let me (take a (closer )?)?look|let me (check|see|inspect|investigate)|i'?ll (take a look|check|look|see)|let'?s (take a )?(look|see)|now,? let me (look|check|see))\b/i;
|
|
73
|
-
/** Reusable substance: a named cause, a decision/action verb, or a concrete code target (path / `code`). A turn
|
|
74
|
-
* that opens with narration is dropped ONLY when it has none of these — so "let me check … the root cause is X,
|
|
75
|
-
* fix by Y" keeps its substantive remainder rather than being discarded for its opener. */
|
|
76
154
|
const HAS_SUBSTANCE = /\b(because|so that|root cause|the (issue|bug|problem|fix|error)|fix(ed|es|ing)?|add(ed|ing)?|remov(e|ed|ing)|delet(e|ed|ing)|chang(e|ed|ing)?|updat(e|ed|ing)?|replac(e|ed|ing)?|renam(e|ed|ing)?|implement(ed|ing)?|revert(ed)?|switch(ed|ing)?|configur(e|ed|ing)?|install(ed|ing)?|return(s|ed)?|throw(s|n)?|catch|wrap(ped)?|guard|import(ed|s)?|export(ed|s)?|re-?run|retry|set\s)\b/i;
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
155
|
+
const ACTION = /\b(use[ds]?|using|run|running|ran|read|open|write|render|call|preserv(e|ed)|reproduc(e|ed)|check|verify)\b|修复|修正|原因|根因|导致|添加|删除|替换|改为|改用|采用|设置|使用|读取|写入|打开|运行|重新|配置|检查|調べ|設定|変更|接続|수정|설정|변경|조사|원인/i;
|
|
156
|
+
const CAUSE_OR_FIX = /\b(root cause|because|fix(?:ed|es|ing)?)\b|根因|修复|原因|修正|원인|수정/i;
|
|
157
|
+
const CODE_TARGET = /`|(?:[\w/-]+\.[a-z]{2,5}\b)|(?:--[\w-]+(?:=|\s))|(?:\b[\w_]+\s*=)/i;
|
|
158
|
+
const COMPLETION = /\b(all correct|done|complete[ds]?|fixed|success(?:ful|fully)?|passed|verified|resolved)\b|全部完成|所有.*通过|全部通过|均通过|已经完成|已完成|成功|完了|완료/i;
|
|
159
|
+
const REUSABLE_WORKFLOW = /\b(reusable|repeatable|workflow|playbook|runbook|procedure|recipe)\b|复用|工作流|可重用/i;
|
|
160
|
+
const GENERIC_COMPLETION_WORDS = /\b(i|we|it|the|a|an|all|everything|has|have|been|is|are|was|were|and|now|already|fully|successfully|issue|issues|problem|problems|task|tasks|work|tests?|checks?|validation|done|completed?|finished|fixed|resolved|passed|verified)\b/gi;
|
|
161
|
+
const GENERIC_COMPLETION_CJK = /所有|全部|已经|已|问题|错误|任务|工作|测试|验证|检查|均|都|通过|修复|解决|完成|成功|了/g;
|
|
162
|
+
// These tokens are for classification only; extraction keeps the original text and offsets.
|
|
163
|
+
// Quoted filenames/code remain atoms, so punctuation and conjunctions inside them cannot
|
|
164
|
+
// masquerade as clause boundaries or verbs. The source unit has already passed textUnits.
|
|
165
|
+
const CLAUSE_TOKENS = /(`+)[\s\S]*?\1|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|“[^”]*”|‘[^’]*’|[^\s,;,;]+|[,;,;]/gu;
|
|
166
|
+
const NOMINAL_START = /^(?:the|this|that|these|those|my|our|your|their|its|an?)$/i;
|
|
167
|
+
const FILENAME_SUBJECT = /^[\p{L}\p{N}_./\\: -]+\.[A-Za-z0-9]{1,8}$/u;
|
|
168
|
+
const FINITE_AUXILIARY = /^(?:is|are|was|were|has|have|had)$/i;
|
|
169
|
+
/** 文件引用本身不是操作;带参数的命令、赋值及调用不能落入这个分类。 */
|
|
170
|
+
function isFilenameAtom(value, allowQuotedSpaces = false) {
|
|
171
|
+
const token = value.trim().replace(/[.!?]$/u, '');
|
|
172
|
+
const quoted = /^(`+|["'])(.*)\1$/u.exec(token);
|
|
173
|
+
const curved = /^“(.*)”$|^‘(.*)’$/u.exec(token);
|
|
174
|
+
const inner = quoted?.[2] ?? curved?.[1] ?? curved?.[2];
|
|
175
|
+
const atom = inner ?? token;
|
|
176
|
+
// 多词引号内容也可能是完整命令;仅在已有完成谓语的主语位置允许带空格文件名。
|
|
177
|
+
if (/\s/u.test(atom) && !(allowQuotedSpaces && inner !== undefined))
|
|
178
|
+
return false;
|
|
179
|
+
return FILENAME_SUBJECT.test(atom);
|
|
180
|
+
}
|
|
181
|
+
function isCjkResultOnly(words, clause) {
|
|
182
|
+
// Aspect markers inside quoted code/filenames are data, not result predicates.
|
|
183
|
+
const visible = words.map(word => /^[`"'“‘]/u.test(word) ? ' '.repeat(word.length) : word).join(' ');
|
|
184
|
+
const aspect = /已(?:经)?/u.exec(visible);
|
|
185
|
+
if (!aspect)
|
|
186
|
+
return false;
|
|
187
|
+
const predicate = clause.slice(aspect.index + aspect[0].length)
|
|
188
|
+
.replace(GENERIC_COMPLETION_CJK, '').replace(/[\s\p{P}]/gu, '');
|
|
189
|
+
if (predicate)
|
|
190
|
+
return false;
|
|
191
|
+
// A filename or a generic result noun is not an operation. Keep specific verbs
|
|
192
|
+
// and causes before the result marker (e.g. changing the encoding before finishing).
|
|
193
|
+
const subject = visible.slice(0, aspect.index).replace(GENERIC_COMPLETION_CJK, '')
|
|
194
|
+
.replace(new RegExp(CODE_TARGET.source, 'gi'), '');
|
|
195
|
+
return !HAS_SUBSTANCE.test(subject) && !ACTION.test(subject);
|
|
86
196
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
197
|
+
function completionPredicates(text) {
|
|
198
|
+
const clauses = [[]];
|
|
199
|
+
for (const token of text.match(CLAUSE_TOKENS) ?? []) {
|
|
200
|
+
if (/^(?:and|but|[,;,;])$/i.test(token))
|
|
201
|
+
clauses.push([]);
|
|
202
|
+
else
|
|
203
|
+
clauses[clauses.length - 1].push(token);
|
|
204
|
+
}
|
|
205
|
+
return clauses.map(words => {
|
|
206
|
+
const clause = words.join(' ');
|
|
207
|
+
if (isCjkResultOnly(words, clause))
|
|
208
|
+
return '';
|
|
209
|
+
const subject = words[0] ?? '';
|
|
210
|
+
const filenameSubject = isFilenameAtom(subject, true);
|
|
211
|
+
if (!NOMINAL_START.test(subject) && !filenameSubject)
|
|
212
|
+
return clause;
|
|
213
|
+
const auxiliary = words.findIndex(word => FINITE_AUXILIARY.test(word));
|
|
214
|
+
// A simple active completion has no auxiliary; retain its verb in the predicate.
|
|
215
|
+
const predicateStart = auxiliary >= 0 ? auxiliary + 1
|
|
216
|
+
: words.findIndex(word => filenameSubject
|
|
217
|
+
? /^(?:complete[ds]?|fixed|resolved|passed|verified)[.!?]?$/i.test(word)
|
|
218
|
+
: /^complete[ds]?[.!?]?$/i.test(word));
|
|
219
|
+
if (predicateStart < 0)
|
|
220
|
+
return clause;
|
|
221
|
+
const predicate = words.slice(predicateStart).join(' ');
|
|
222
|
+
// Remove a result's subject, never an informative cause or an operative predicate.
|
|
223
|
+
// Perfect active/passive clauses share their finite auxiliary boundary.
|
|
224
|
+
return COMPLETION.test(predicate) ? predicate : clause;
|
|
225
|
+
}).join(' ');
|
|
226
|
+
}
|
|
227
|
+
function hasActionableContent(text) {
|
|
228
|
+
if (text.trim().length < 4 || /^[a-z]+[.!?]?$/i.test(text.trim()) || isFilenameAtom(text))
|
|
229
|
+
return false;
|
|
230
|
+
const completion = COMPLETION.test(text);
|
|
231
|
+
const actionText = completion || text.includes('已') ? completionPredicates(text) : text;
|
|
232
|
+
const withoutCompletion = actionText.replace(GENERIC_COMPLETION_WORDS, '').replace(GENERIC_COMPLETION_CJK, '').replace(/[\s\d.,!?;:,。!?;:、-]/gu, '');
|
|
233
|
+
if (withoutCompletion.length === 0)
|
|
89
234
|
return false;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
235
|
+
if (NARRATION_OPENER.test(text) && !CAUSE_OR_FIX.test(text))
|
|
236
|
+
return false;
|
|
237
|
+
const action = HAS_SUBSTANCE.test(actionText) || ACTION.test(actionText);
|
|
238
|
+
if (completion && !action)
|
|
239
|
+
return false;
|
|
240
|
+
return action || CODE_TARGET.test(actionText);
|
|
95
241
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return raw;
|
|
102
|
-
return narrationRemainder(raw) ?? raw;
|
|
242
|
+
function hasTruncatedSnapshotText(turn) {
|
|
243
|
+
if (!turn.metadata || typeof turn.metadata !== 'object')
|
|
244
|
+
return false;
|
|
245
|
+
const snapshot = turn.metadata['evolverMaterialSnapshot'];
|
|
246
|
+
return !!snapshot && typeof snapshot === 'object' && snapshot['textTruncated'] === true;
|
|
103
247
|
}
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
* the capped step leads with the fix). NOT fabricated: real transcript excerpts; the gene lands UNPROVEN and is
|
|
108
|
-
* curated by `review` + pruned by the cycle, so a noisy draft self-corrects. */
|
|
109
|
-
export function draftStrategy(turns) {
|
|
110
|
-
const steps = [];
|
|
248
|
+
/** 最多六个完整且已脱敏的操作单元。拒绝信息只含位置/原因/计数,不保存秘密原文。 */
|
|
249
|
+
export function draftStrategyWithEvidence(turns, toolWorkflowsOnly = false) {
|
|
250
|
+
const selected = [];
|
|
111
251
|
const seen = new Set();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (isNarrationOnly(raw))
|
|
119
|
-
continue; // "let me look around" with no cause/action — not a strategy
|
|
120
|
-
const step = trimToBoundary(dropNarrationOpener(raw));
|
|
121
|
-
if (seen.has(step))
|
|
252
|
+
const diagnostics = {
|
|
253
|
+
status: 'insufficient', reason: 'no_actionable_units', evidence: [], rejected: [],
|
|
254
|
+
omitted: { nonActionable: 0, duplicate: 0, overBudget: 0, incomplete: 0, sourceTruncated: 0, capacity: 0 },
|
|
255
|
+
};
|
|
256
|
+
for (const [turnIndex, turn] of turns.entries()) {
|
|
257
|
+
if (turn.isMeta || (toolWorkflowsOnly ? turn.role !== 'tool' : turn.role !== 'assistant'))
|
|
122
258
|
continue;
|
|
123
|
-
|
|
124
|
-
|
|
259
|
+
const fields = toolWorkflowsOnly ? ['text', 'toolResult'] : ['text'];
|
|
260
|
+
for (const field of fields) {
|
|
261
|
+
const raw = turn[field] ?? '';
|
|
262
|
+
for (const unit of textUnits(raw)) {
|
|
263
|
+
const source = { turnIndex, field, start: unit.start, end: unit.end };
|
|
264
|
+
const original = raw.slice(unit.start, unit.end);
|
|
265
|
+
if (field === 'text' && hasTruncatedSnapshotText(turn) && unit.end === raw.trimEnd().length && original.length > 0) {
|
|
266
|
+
diagnostics.omitted.sourceTruncated++;
|
|
267
|
+
diagnostics.rejected.push({ ...source, reason: 'source_truncated' });
|
|
268
|
+
if (diagnostics.rejected.length > MAX_STRATEGY_STEPS)
|
|
269
|
+
diagnostics.rejected.shift();
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (!hasActionableContent(original) || (toolWorkflowsOnly && !REUSABLE_WORKFLOW.test(original))) {
|
|
273
|
+
diagnostics.omitted.nonActionable++;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
const text = hub.redactString(original);
|
|
277
|
+
if (!unit.complete || original.length > MAX_STEP_CHARS || text.length > MAX_STEP_CHARS) {
|
|
278
|
+
const reason = unit.complete ? 'unit_too_long' : 'incomplete_unit';
|
|
279
|
+
if (unit.complete)
|
|
280
|
+
diagnostics.omitted.overBudget++;
|
|
281
|
+
else
|
|
282
|
+
diagnostics.omitted.incomplete++;
|
|
283
|
+
diagnostics.rejected.push({ ...source, reason });
|
|
284
|
+
if (diagnostics.rejected.length > MAX_STRATEGY_STEPS)
|
|
285
|
+
diagnostics.rejected.shift();
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (!hasActionableContent(text)) {
|
|
289
|
+
diagnostics.omitted.nonActionable++;
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
const key = text.replace(/\r\n/g, '\n');
|
|
293
|
+
if (seen.has(key)) {
|
|
294
|
+
diagnostics.omitted.duplicate++;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
seen.add(key);
|
|
298
|
+
selected.push({ text, source });
|
|
299
|
+
if (selected.length > MAX_STRATEGY_STEPS) {
|
|
300
|
+
selected.shift();
|
|
301
|
+
diagnostics.omitted.capacity++;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
125
305
|
}
|
|
126
|
-
|
|
306
|
+
diagnostics.evidence = selected.map((step) => step.source);
|
|
307
|
+
if (selected.length > 0) {
|
|
308
|
+
diagnostics.status = 'ready';
|
|
309
|
+
diagnostics.reason = 'complete_units';
|
|
310
|
+
}
|
|
311
|
+
else if (diagnostics.omitted.sourceTruncated > 0)
|
|
312
|
+
diagnostics.reason = 'source_truncated';
|
|
313
|
+
else if (diagnostics.omitted.incomplete > 0)
|
|
314
|
+
diagnostics.reason = 'incomplete_unit';
|
|
315
|
+
else if (diagnostics.omitted.overBudget > 0)
|
|
316
|
+
diagnostics.reason = 'unit_too_long';
|
|
317
|
+
return { strategy: selected.map((step) => step.text), diagnostics };
|
|
318
|
+
}
|
|
319
|
+
/** 兼容旧调用方;实际入口使用带位置和不足原因的同一实现。 */
|
|
320
|
+
export function draftStrategy(turns) {
|
|
321
|
+
return draftStrategyWithEvidence(turns).strategy;
|
|
127
322
|
}
|
|
128
323
|
const GENERIC_SUCCESS_TOPICS = new Set([
|
|
129
324
|
'added', 'adjusted', 'assistant', 'change', 'changed', 'changes', 'command', 'commands', 'complete',
|
|
@@ -143,8 +338,20 @@ function successTopicSignals(strategy) {
|
|
|
143
338
|
* (already extracted by the caller) to avoid a second extraction pass.
|
|
144
339
|
*/
|
|
145
340
|
export function draftGeneCandidate(turns, sigs, agent) {
|
|
341
|
+
return assessGeneDraft(turns, sigs, agent).candidate;
|
|
342
|
+
}
|
|
343
|
+
/** 共享 caller 的实际入口;diagnostics 不进入 Gene 内容或 asset_id。 */
|
|
344
|
+
export function assessGeneDraft(turns, sigs, agent) {
|
|
146
345
|
const signals_match = signalTokens(sigs);
|
|
147
|
-
|
|
346
|
+
let drafted = draftStrategyWithEvidence(turns);
|
|
347
|
+
const strategy = drafted.strategy;
|
|
348
|
+
const finish = (candidate, reason) => ({
|
|
349
|
+
candidate,
|
|
350
|
+
diagnostics: {
|
|
351
|
+
...drafted.diagnostics,
|
|
352
|
+
...(!candidate ? { status: 'insufficient', reason: reason ?? drafted.diagnostics.reason } : {}),
|
|
353
|
+
},
|
|
354
|
+
});
|
|
148
355
|
const hadVerifiedSuccess = sigs.some((s) => s.strength === 'success' && !s.needsAnalysis);
|
|
149
356
|
const hasTerminalVerifiedSuccess = signals_match.includes('verified-success');
|
|
150
357
|
// 当只有成功信号(没有错误信号)时,走 innovate 路径而非 repair (#578):
|
|
@@ -153,7 +360,7 @@ export function draftGeneCandidate(turns, sigs, agent) {
|
|
|
153
360
|
if (signals_match.length === 0 || strategy.length === 0 || !hasStrongError) {
|
|
154
361
|
// Do not let the capability sniffer resurrect a success that a later unresolved outcome already superseded.
|
|
155
362
|
if (hadVerifiedSuccess && !hasTerminalVerifiedSuccess && !hasStrongError)
|
|
156
|
-
return null;
|
|
363
|
+
return finish(null, 'no_eligible_signal');
|
|
157
364
|
const hit = algo.sniffConversationCapabilities(turns)[0];
|
|
158
365
|
if (!hit) {
|
|
159
366
|
// Sniffer 也未命中:如果有 success 信号和 strategy(仅当 hasStrongError 为 false 才走到这里且 signals_match 非空),
|
|
@@ -163,25 +370,36 @@ export function draftGeneCandidate(turns, sigs, agent) {
|
|
|
163
370
|
// Generic runner + success tokens are not a reusable capability identity. Let the optional transcript-LLM
|
|
164
371
|
// path handle prose that has no safe discriminating topic instead of storing one global shell-success gene.
|
|
165
372
|
if (topics.length === 0)
|
|
166
|
-
return null;
|
|
373
|
+
return finish(null, 'no_discriminating_topic');
|
|
167
374
|
const successSignals = [...new Set([...signals_match, ...topics])].slice(0, 8);
|
|
168
|
-
return {
|
|
375
|
+
return finish({
|
|
169
376
|
category: 'innovate',
|
|
170
377
|
signals_match: successSignals,
|
|
171
378
|
strategy,
|
|
172
379
|
summary: `Auto-drafted from ${agent} session (UNPROVEN — curate via review): ${topics.slice(0, 3).join(', ')}`,
|
|
173
380
|
generation_meta: { source: 'distilled' },
|
|
174
|
-
};
|
|
381
|
+
});
|
|
175
382
|
}
|
|
176
|
-
return null;
|
|
383
|
+
return finish(null, strategy.length > 0 ? 'no_eligible_signal' : undefined);
|
|
177
384
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
385
|
+
// sniffer 仍负责资格/信号,不使用它按前缀裁剪的 evidence 作为策略。
|
|
386
|
+
// 仅在没有助手操作且已命中真实 workflow 时保留旧的 tool-only 回退。
|
|
387
|
+
if (strategy.length === 0) {
|
|
388
|
+
const fallback = draftStrategyWithEvidence(turns, true);
|
|
389
|
+
if (fallback.strategy.length > 0 || fallback.diagnostics.rejected.length > 0) {
|
|
390
|
+
for (const key of Object.keys(drafted.diagnostics.omitted)) {
|
|
391
|
+
fallback.diagnostics.omitted[key] += drafted.diagnostics.omitted[key];
|
|
392
|
+
}
|
|
393
|
+
fallback.diagnostics.rejected = [...drafted.diagnostics.rejected, ...fallback.diagnostics.rejected].slice(-MAX_STRATEGY_STEPS);
|
|
394
|
+
drafted = fallback;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (drafted.strategy.length === 0)
|
|
398
|
+
return finish(null);
|
|
399
|
+
return finish({
|
|
182
400
|
category: 'innovate',
|
|
183
401
|
signals_match: hit.signals,
|
|
184
|
-
strategy:
|
|
402
|
+
strategy: drafted.strategy,
|
|
185
403
|
summary: `Auto-drafted verified capability from ${agent} session (UNPROVEN — curate via review): ${hit.summary}`,
|
|
186
404
|
preconditions: [
|
|
187
405
|
'A live agent conversation explicitly described a reusable capability.',
|
|
@@ -189,9 +407,9 @@ export function draftGeneCandidate(turns, sigs, agent) {
|
|
|
189
407
|
],
|
|
190
408
|
validation: ['node --version'],
|
|
191
409
|
generation_meta: { source: 'distilled' },
|
|
192
|
-
};
|
|
410
|
+
});
|
|
193
411
|
}
|
|
194
|
-
return {
|
|
412
|
+
return finish({
|
|
195
413
|
category: 'repair',
|
|
196
414
|
signals_match,
|
|
197
415
|
strategy,
|
|
@@ -200,7 +418,7 @@ export function draftGeneCandidate(turns, sigs, agent) {
|
|
|
200
418
|
// trajectory → `distilled` per V1 #302 classifyProvenance. Tagged so future governance/selection can grade it
|
|
201
419
|
// apart from evolved (solve→fail→mutate→pass) and manual (human-taught) genes.
|
|
202
420
|
generation_meta: { source: 'distilled' },
|
|
203
|
-
};
|
|
421
|
+
});
|
|
204
422
|
}
|
|
205
423
|
// Signals injected by the fallback itself, plus generic command runners, carry no domain identity. Including them
|
|
206
424
|
// in Jaccard makes unrelated capabilities (for example GitHub vs Playwright) look 60% identical even though their
|