fix(runtime): preserve model capacity history and cache evidence with resumable file proposals
This commit is contained in:
@@ -19,6 +19,8 @@ export function modelSnapshot(config) {
|
||||
return {
|
||||
mode: config.mode, baseUrl: config.baseUrl, model: config.model,
|
||||
contextLimit: config.contextLimit, maxOutputTokens: config.maxOutputTokens,
|
||||
...(config.capacityMode ? { capacityMode: config.capacityMode } : {}),
|
||||
...(config.historyPolicy ? { historyPolicy: config.historyPolicy } : {}),
|
||||
configRevision: config.configRevision ?? 1,
|
||||
...modelWaitSettings(config),
|
||||
...modelIdentitySettings(config),
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
export const fileDraftToolDefinitions = [
|
||||
{ type: 'function', function: { name: 'propose_file_chunk', description: '长文件不能一次完整输出时,分多轮追加完整文本片段。首次offset=0;后续必须使用回执draft_id/next_offset/draft_sha256作为draft_id/offset/expected_sha256。每段按本次输出额度拆小,最后一段complete=true才创建一个完整待审提案;此前片段不能应用或交付。不修改项目文件,不接收截断JSON。', parameters: {
|
||||
type: 'object', additionalProperties: false, required: ['path', 'content', 'reason', 'offset', 'complete'], properties: {
|
||||
path: { type: 'string' }, content: { type: 'string' }, reason: { type: 'string' }, offset: { type: 'integer', minimum: 0 }, complete: { type: 'boolean' },
|
||||
draft_id: { type: 'string' }, expected_sha256: { type: 'string', pattern: '^[a-f0-9]{64}$' },
|
||||
base_sha256: { type: ['string', 'null'], description: '首次核对原文件SHA;新文件为null。分段过程中基线不变。' },
|
||||
},
|
||||
} } },
|
||||
{ type: 'function', function: { name: 'discard_file_draft', description: '明确放弃当前Task的未完成分段文件草稿。需要原draft_id/draft_sha256与原因;原片段和失败保留,不更改项目文件。', parameters: {
|
||||
type: 'object', additionalProperties: false, required: ['draft_id', 'expected_sha256', 'reason'], properties: {
|
||||
draft_id: { type: 'string' }, expected_sha256: { type: 'string', pattern: '^[a-f0-9]{64}$' }, reason: { type: 'string' },
|
||||
},
|
||||
} } },
|
||||
];
|
||||
@@ -0,0 +1,4 @@
|
||||
export const DEFAULT_MODEL_CAPACITY: Readonly<{ contextLimit: number; maxOutputTokens: number }>;
|
||||
export const CAPACITY_RANGES: Readonly<Record<'contextLimit' | 'maxOutputTokens', number[]>>;
|
||||
export function capacitySettings(input?: { contextLimit?: number; maxOutputTokens?: number }, previous?: { contextLimit?: number; maxOutputTokens?: number }): { contextLimit: number; maxOutputTokens: number };
|
||||
export function capacityMode(value?: string): 'model' | 'manual';
|
||||
@@ -0,0 +1,24 @@
|
||||
// Editable fallbacks for upstreams that do not publish capacity. These values
|
||||
// are not verified model capabilities or ceilings on larger models.
|
||||
export const DEFAULT_MODEL_CAPACITY = Object.freeze({ contextLimit: 128000, maxOutputTokens: 16384 });
|
||||
export const CAPACITY_RANGES = Object.freeze({ contextLimit: [1000, Number.MAX_SAFE_INTEGER], maxOutputTokens: [256, Number.MAX_SAFE_INTEGER] });
|
||||
|
||||
export function capacitySettings(input = {}, previous = DEFAULT_MODEL_CAPACITY) {
|
||||
return Object.fromEntries(Object.entries(CAPACITY_RANGES).map(([key, [min, max]]) => {
|
||||
const value = input[key] ?? previous[key] ?? DEFAULT_MODEL_CAPACITY[key];
|
||||
if (!Number.isSafeInteger(value) || value < min || value > max) throw Object.assign(new Error(key + ' 需要不小于 ' + min + ' 的安全整数,请核对模型实际容量。'), { status: 400 });
|
||||
return [key, value];
|
||||
}));
|
||||
}
|
||||
|
||||
export function capacityMode(value = 'manual') {
|
||||
if (!['model', 'manual'].includes(value)) throw Object.assign(new Error('请选择按模型容量或手动限制。'), { status: 400 });
|
||||
return value;
|
||||
}
|
||||
|
||||
export function routedCapacity(config, members) {
|
||||
const mode = capacityMode(config.capacityMode);
|
||||
return Object.fromEntries(Object.keys(DEFAULT_MODEL_CAPACITY).map(key => [key,
|
||||
mode === 'model' && key === 'maxOutputTokens' ? Math.max(...members.map(member => member[key]))
|
||||
: Math.min(...members.map(member => member[key]), ...(mode === 'manual' ? [config[key]] : []))]));
|
||||
}
|
||||
@@ -34,10 +34,11 @@ function wireBody(config, messages, tools) {
|
||||
|
||||
export function completionBody(config, messages, tools) {
|
||||
const members = config.modelRouting?.members;
|
||||
if (members?.some(member => member.protocol && member.protocol !== 'chat-completions' || member.streaming === true || member.nativeParameters || member.outputTokenField)) {
|
||||
if (members?.length && (config.capacityMode === 'model' || members.some(member => member.protocol && member.protocol !== 'chat-completions' || member.streaming === true || member.nativeParameters || member.outputTokenField))) {
|
||||
return { schema: 1, kind: 'model-route-plan', messages, variants: members.map(member => ({ connectionId: member.id,
|
||||
protocol: modelProtocol(member.protocol), body: wireBody({ ...config, ...member, nativeParameters: member.nativeParameters ?? {}, outputTokenField: member.outputTokenField,
|
||||
modelConnectionId: member.id, modelCredentialRevision: member.credentialRevision, maxOutputTokens: config.maxOutputTokens }, messages, tools) })) };
|
||||
modelConnectionId: member.id, modelCredentialRevision: member.credentialRevision,
|
||||
maxOutputTokens: config.capacityMode === 'model' ? member.maxOutputTokens : config.maxOutputTokens }, messages, tools) })) };
|
||||
}
|
||||
return wireBody(config, messages, tools);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Task intent is retained independently of short follow-ups and system actions.
|
||||
import { changeRequirement, requestedFilePaths, negatedFileAction } from './file-intent.mjs';
|
||||
export const isContinuation = content => /^(?:请)?(?:继续(?:完成|执行|开发|原任务|这个任务)?|接着(?:完成|执行)?|continue(?:\s+(?:the\s+)?(?:task|work))?)[。.!!\s]*$/i.test(String(content).trim());
|
||||
const skipChecks = /无需(?:任何)?(?:测试|工程检查)|不(?:需要|用|要)?(?:进行|做|运行|执行)?(?:任何)?(?:测试|工程检查)|\b(?:no (?:tests?|checks?)(?: needed|required)?|without (?:running )?(?:tests?|checks?)|(?:do not|don't|never) (?:[^.,;!?\n]{1,60}\s+(?:or|nor)\s+)?(?:run|execute) (?:tests?|checks?))\b/i;
|
||||
const requireChecks = /(?:运行|执行|通过|修复|补充|添加).{0,12}(?:测试|工程检查)|\b(?:run|pass|fix|add)\b.{0,24}\b(?:tests?|checks?)\b/i;
|
||||
|
||||
export function isDiagnosticQuestion(content) {
|
||||
const text = String(content).trim();
|
||||
@@ -19,8 +21,8 @@ export function taskContract(task, lookup = () => null) {
|
||||
original = previous;
|
||||
}
|
||||
const goal = original.contract?.goal ?? original.goal;
|
||||
const skip = /无需(?:任何)?(?:测试|工程检查)|不(?:需要|用|要)?(?:进行|做|运行|执行)?(?:任何)?(?:测试|工程检查)|\b(?:no (?:tests?|checks?)(?: needed|required)?|without (?:running )?(?:tests?|checks?)|(?:do not|don't|never) (?:run|execute) (?:tests?|checks?))\b/i.test(goal);
|
||||
const required = !skip && /(?:运行|执行|通过|修复|补充|添加).{0,12}(?:测试|工程检查)|\b(?:run|pass|fix|add)\b.{0,24}\b(?:tests?|checks?)\b/i.test(goal);
|
||||
const skip = skipChecks.test(goal);
|
||||
const required = !skip && requireChecks.test(goal);
|
||||
const file = hasFileDeliveryRequest(goal);
|
||||
return { schemaVersion: 1, goal, kind: file ? 'file' : 'general', checks: skip ? 'skip' : required ? 'required' : 'unspecified',
|
||||
...(original.id !== task.id ? { inheritedFromTaskId: original.id } : {}) };
|
||||
@@ -41,8 +43,8 @@ export function updateTaskContract(task, instruction) {
|
||||
const current = taskContract(task);
|
||||
if (hasFileDeliveryRequest(instruction)) current.kind = 'file';
|
||||
// Only an explicit new user instruction changes the check policy.
|
||||
if (/无需(?:任何)?测试|不(?:需要|用|要)(?:进行|做|运行)?测试|\b(?:no tests?|without (?:running )?tests?)\b/i.test(instruction)) current.checks = 'skip';
|
||||
else if (/(?:运行|执行|通过|修复|补充|添加).{0,12}(?:测试|工程检查)|\b(?:run|pass|fix|add)\b.{0,24}\b(?:tests?|checks?)\b/i.test(instruction)) current.checks = 'required';
|
||||
if (skipChecks.test(instruction)) current.checks = 'skip';
|
||||
else if (requireChecks.test(instruction)) current.checks = 'required';
|
||||
task.contract = current;
|
||||
task.constraints = (task.constraints ?? []).filter(value => value !== '用户明确要求无需测试;不得自动扩大为工程测试任务。');
|
||||
if (current.checks === 'skip') task.constraints.push('用户明确要求无需测试;不得自动扩大为工程测试任务。');
|
||||
|
||||
@@ -3,7 +3,7 @@ import { isId, accountedTokens, emptyUsage } from './execution.mjs';
|
||||
import { selectedEngineInput } from './engine-execution.mjs';
|
||||
|
||||
export const WORKER_TOOLS = new Set(['diagnose_environment','plan_environment','prepare_environment','inspect_session', 'inspect_project', 'index_project', 'query_code', 'read_artifact',
|
||||
'list_files', 'read_file', 'search_files', 'propose_file', 'propose_patch', 'prepare_change_set', 'plan_checks', 'run_checks']);
|
||||
'list_files', 'read_file', 'search_files', 'propose_file', 'propose_patch', 'propose_file_chunk', 'discard_file_draft', 'prepare_change_set', 'plan_checks', 'run_checks']);
|
||||
export const COLLABORATION_ACTIVE = new Set(['preparing', 'starting', 'running', 'stopping', 'collecting', 'merge_preparing', 'reconciling']);
|
||||
export const COLLABORATION_CLOSED = new Set(['completed', 'discarded', 'resolved_external']);
|
||||
export const workerConflict = message => Object.assign(new Error(message), { status: 409 });
|
||||
@@ -109,7 +109,7 @@ export function assertWorkerTool(store, session, tool, args) {
|
||||
const worker = workerForSession(store, session);
|
||||
if (!worker) return;
|
||||
if (!WORKER_TOOLS.has(tool)) throw workerConflict('受限子任务不开放这个工具:' + tool);
|
||||
if (tool === 'propose_file' || tool === 'propose_patch') assertWorkerWriteScope(store, session, args.path);
|
||||
if (tool === 'propose_file' || tool === 'propose_patch' || tool === 'propose_file_chunk') assertWorkerWriteScope(store, session, args.path);
|
||||
}
|
||||
export function assertWorkersResolved(store, projectId, { recoveryTaskId = null } = {}) {
|
||||
const group = [...(store.core.collaboration?.values() ?? [])].find(value => value.requiresVerification
|
||||
|
||||
Reference in New Issue
Block a user