evolcore 0.0.40 → 0.0.41-test.0
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/CHANGELOG.md +45 -1
- package/bin/codex-managed-hook.mjs +11 -0
- package/bin/ec-safe-output.js +11 -1
- package/dist/agents/claude-runner.js +21 -106
- package/dist/agents/codex-runner.js +451 -231
- package/dist/agents/ecagent-runner.js +30 -11
- package/dist/agents/gemini-runner.js +26 -6
- package/dist/agents/runner-types.js +11 -3
- package/dist/aun/ability-device-routing.js +26 -0
- package/dist/aun/aid/client.js +1 -1
- package/dist/aun/group/identity.js +8 -0
- package/dist/aun/msg/managed-operation.js +4 -4
- package/dist/aun/msg/p2p.js +27 -7
- package/dist/aun/storage/download.js +30 -0
- package/dist/aun/storage/index.js +14 -6
- package/dist/channels/aun.js +33 -4
- package/dist/channels/daemon.js +24 -4
- package/dist/cli/agent-command.js +2 -0
- package/dist/cli/agent-create.js +98 -19
- package/dist/cli/agent.js +10 -3
- package/dist/cli/aun-commands.js +82 -22
- package/dist/cli/daemon-commands.js +19 -10
- package/dist/cli/index.js +1 -1
- package/dist/cli/restart-monitor.js +17 -0
- package/dist/cli/session-command.js +128 -13
- package/dist/cli/stats.js +60 -4
- package/dist/cli/trigger-command.js +2 -2
- package/dist/config/access-policy.js +2 -0
- package/dist/config/config-operation-service.js +17 -6
- package/dist/config/gateway-config.js +1 -1
- package/dist/config/peer-role-resolver.js +10 -8
- package/dist/core/agent-application-service.js +11 -1
- package/dist/core/agent-ipc-registration.js +4 -0
- package/dist/core/auth/agent-delegation.js +80 -5
- package/dist/core/auth/authorization-audit.js +20 -3
- package/dist/core/auth/operation-catalog.js +8 -0
- package/dist/core/command/agent-control.js +91 -12
- package/dist/core/command/command-handler.js +57 -46
- package/dist/core/command/connect-menu.js +23 -2
- package/dist/core/command/menu-catalog.js +1 -0
- package/dist/core/command/menu-handler.js +38 -101
- package/dist/core/command/menu-protocol.js +9 -2
- package/dist/core/command/role-menu.js +7 -6
- package/dist/core/command/slash-gate.js +13 -10
- package/dist/core/command/slash-handler.js +34 -98
- package/dist/core/event-catalog.js +15 -0
- package/dist/core/ipc-registration.js +18 -1
- package/dist/core/memory/consolidation-trigger.js +1 -1
- package/dist/core/message/aun-ipc-sender.js +26 -5
- package/dist/core/message/aun-request-registry.js +97 -3
- package/dist/core/message/im-renderer.js +4 -0
- package/dist/core/message/message-admission.js +8 -4
- package/dist/core/message/message-bridge.js +40 -6
- package/dist/core/message/message-log.js +55 -0
- package/dist/core/message/message-queue.js +5 -5
- package/dist/core/message/response-engine.js +310 -136
- package/dist/core/model/model-catalog.js +7 -6
- package/dist/core/ownership/owner-resolver.js +2 -2
- package/dist/core/permission/ec-command-parser.js +110 -5
- package/dist/core/permission/tool-policy.js +28 -7
- package/dist/core/session/session-capsule.js +197 -0
- package/dist/core/session/session-manager.js +148 -14
- package/dist/core/session/session-mapper.js +2 -0
- package/dist/index.js +3 -3
- package/dist/ipc.js +22 -8
- package/dist/stats/budget.js +1 -1
- package/dist/stats/db.js +15 -0
- package/dist/stats/index.js +2 -2
- package/dist/stats/price-resolver.js +304 -5
- package/dist/stats/query.js +82 -3
- package/dist/stats/writer.js +38 -5
- package/dist/trigger/feedback.js +18 -7
- package/dist/trigger/manager.js +20 -3
- package/dist/trigger/parser.js +6 -3
- package/dist/trigger/patch.js +1 -1
- package/dist/trigger/system-definitions.js +43 -7
- package/dist/trigger/validation.js +13 -5
- package/dist/utils/error-utils.js +14 -0
- package/dist/utils/npm-ops.js +2 -1
- package/dist/utils/package-version-info.js +1 -1
- package/dist/utils/upgrade-jobs.js +45 -5
- package/kits/docs/INDEX.md +1 -1
- package/kits/docs/aun/ABILITY_CALLING.md +20 -2
- package/kits/docs/evolcore/INDEX.md +2 -1
- package/kits/docs/evolcore/agent-create.md +3 -2
- package/kits/docs/evolcore/agent.md +1 -1
- package/kits/docs/evolcore/config.md +1 -1
- package/kits/docs/evolcore/event.md +1 -0
- package/kits/docs/evolcore/fs.md +5 -0
- package/kits/docs/evolcore/menu-protocol.md +32 -0
- package/kits/docs/evolcore/msg.md +17 -1
- package/kits/docs/evolcore/session.md +14 -0
- package/kits/schemas/agent-config.schema.13.json +15 -0
- package/kits/skills/aid-ability/SKILL.md +35 -6
- package/kits/templates/session-capsule/recovery.md +5 -0
- package/kits/templates/session-capsule/renew.md +5 -0
- package/kits/templates/system-fragments/bootstrap.md +6 -6
- package/kits/templates/system-fragments/channel.md +1 -1
- package/package.json +3 -3
- package/dist/stats/billing.js +0 -215
package/CHANGELOG.md
CHANGED
|
@@ -5,12 +5,56 @@
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
## 0.0.41 (2026-10-27)
|
|
9
|
+
|
|
10
|
+
### 会话与上下文
|
|
11
|
+
|
|
12
|
+
- 改进自动精简与话题 `/renew` 的上下文交接,保留目标、约束、已确认结果和待办。
|
|
13
|
+
- 完善 Claude Code、Codex、Gemini 和 ecagent 历史失效后的恢复;启动失败时保留交接摘要,避免重试时丢失上下文。
|
|
14
|
+
- 支持查询会话来源、交接摘要和底层会话关联。
|
|
15
|
+
- 调整 `/baseagent` 为设置新会话的默认基座,已有会话继续使用原基座。
|
|
16
|
+
- 修正非 GPT 模型的上下文占用计算,纳入输出及缓存用量。
|
|
17
|
+
|
|
18
|
+
### 模型与费用
|
|
19
|
+
|
|
20
|
+
- Claude Code、Codex、Gemini 和 ecagent 统一使用网关提供的官方价格、实际价格和汇率。
|
|
21
|
+
- 模型调用明细增加官方费用、网关费用及任务汇总,支持回填历史调用费用。
|
|
22
|
+
- 修正部分 Provider 的模型目录处理;模型菜单标注未验证模型,并避免重复选择当前模型。
|
|
23
|
+
|
|
24
|
+
### Agent 与联系人
|
|
25
|
+
|
|
26
|
+
- 补齐 App 创建与初始化 Agent 的入口,支持指定模型和推理强度。
|
|
27
|
+
- 支持原发起者恢复失败的初始化,并完善初始化进度和可用状态反馈。
|
|
28
|
+
- 新增外部联系开关和指定 AID 允许名单。
|
|
29
|
+
- 修复数字 AID 被误判为群而影响私聊角色识别的问题。
|
|
30
|
+
|
|
31
|
+
### AUN 消息与文件
|
|
32
|
+
|
|
33
|
+
- 能力调用支持指定目标设备,设备状态查询可收集多个在线设备的结果,并完善响应匹配与超时诊断。
|
|
34
|
+
- 保留原始消息明确指定的话题路由;跨话题复查创建失败时明确反馈,避免静默遗漏。
|
|
35
|
+
- 支持下载通过 AUN 分享的文件。
|
|
36
|
+
- 根据已验证的主体类型选择个人或群文件空间,并完善托管文件访问范围校验。
|
|
37
|
+
|
|
38
|
+
### 任务、权限与错误反馈
|
|
39
|
+
|
|
40
|
+
- 修复中断和任务收尾的竞态,避免旧任务的取消、超时或清理影响后续任务。
|
|
41
|
+
- 恢复 `/fa <任务>` 单次 Fullaccess 任务执行。
|
|
42
|
+
- 统一托管命令的解析与授权校验,完善受控输出和临时文件操作的处理。
|
|
43
|
+
- 完善 Trigger 超时重试、重试次数校验和旧配置迁移。
|
|
44
|
+
- 改进任务失败时的进度收尾与错误反馈,减少重复或遗漏通知;上游安全策略拒绝后不再自动重试。
|
|
45
|
+
|
|
46
|
+
### 升级与运维
|
|
47
|
+
|
|
48
|
+
- 完善 stable 自动升级检查,固定已确认的升级目标,并在执行和重启前检查自动升级开关。
|
|
49
|
+
- 改进 `ec status` 在 daemon 在线时的状态读取;会话状态补充 Fullaccess 开启状态和巡检周期。
|
|
50
|
+
- 修复 EC Web 被 npm 提升安装到全局目录后的包定位问题。
|
|
51
|
+
|
|
8
52
|
## 0.0.40 (2026-10-26)
|
|
9
53
|
|
|
10
54
|
### Ownership 与绑定
|
|
11
55
|
|
|
12
56
|
- 改进 AUN `/bind` 发起前的状态检查,已绑定、已有待处理请求或状态未确认时避免重复提交。
|
|
13
|
-
- 升级 AUN SDK 最低兼容版本至 `0.5.
|
|
57
|
+
- 升级 AUN SDK 最低兼容版本至 `0.5.26`,并使用 SDK 恢复和管理 Ownership 请求状态。
|
|
14
58
|
- 支持宿主 CLI 通过短连接查询、接受和拒绝 Ownership 邀约,并完善本机双身份绑定与共识校验。
|
|
15
59
|
- 修复 Agent 初始化期间 Owner 绑定竞态,并在初始化运行时补充 Owner 授权校验。
|
|
16
60
|
- Owner 状态暂时无法刷新时按暂态故障处理;绑定类敏感操作继续要求严格共识校验并提供刷新诊断。
|
|
@@ -204,6 +204,17 @@ async function main() {
|
|
|
204
204
|
}
|
|
205
205
|
if (result.ok === true && result.applicable === true && result.decision === 'allow') {
|
|
206
206
|
diagnostic('decision', { decision: 'allow' });
|
|
207
|
+
const updatedInput = result.updatedInput && typeof result.updatedInput === 'object'
|
|
208
|
+
? result.updatedInput : undefined;
|
|
209
|
+
if (updatedInput) {
|
|
210
|
+
process.stdout.write(JSON.stringify({
|
|
211
|
+
hookSpecificOutput: {
|
|
212
|
+
hookEventName: 'PreToolUse',
|
|
213
|
+
permissionDecision: 'allow',
|
|
214
|
+
updatedInput,
|
|
215
|
+
},
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
207
218
|
return;
|
|
208
219
|
}
|
|
209
220
|
deny(result.reason || 'EvolCore policy did not explicitly allow this tool call.', 'policy_denied');
|
package/bin/ec-safe-output.js
CHANGED
|
@@ -9,6 +9,9 @@ const EC_EXECUTABLES = new Set(['ec']);
|
|
|
9
9
|
const HOST_PROCESS_EXECUTABLES = new Set(['ps', 'pgrep', 'pidof', 'kill', 'pkill', 'killall']);
|
|
10
10
|
const IS_WINDOWS = process.platform === 'win32';
|
|
11
11
|
const HELPER_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const EXECUTION_SPEC_ENV = 'EVOLCORE_DELEGATED_EXECUTION_SPEC';
|
|
13
|
+
const TASK_DELEGATION_ENV = 'EVOLCORE_DELEGATION_TOKEN';
|
|
14
|
+
const CODEX_SESSION_TOKEN_ENV = 'EVOLCORE_CODEX_SESSION_TOKEN';
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* stdout filters this helper will spawn. This repeats the policy allowlist in
|
|
@@ -203,6 +206,7 @@ function decodePayload(encoded) {
|
|
|
203
206
|
// the filter's arguments and v2 carried a single `filterArgv`, so both are
|
|
204
207
|
// rejected rather than misread.
|
|
205
208
|
if (!value || value.v !== 3 || !Array.isArray(value.argv) || value.argv.some(arg => typeof arg !== 'string')) return null;
|
|
209
|
+
if (value.executionSpec !== undefined && (typeof value.executionSpec !== 'string' || value.executionSpec.length > 16 * 1024)) return null;
|
|
206
210
|
return value;
|
|
207
211
|
} catch {
|
|
208
212
|
return null;
|
|
@@ -432,7 +436,13 @@ if (filterProcess) filterProcess.stdout.on('data', writeLimited);
|
|
|
432
436
|
|
|
433
437
|
const child = spawn(childCommand.file, childCommand.args, {
|
|
434
438
|
cwd: paths.cwd,
|
|
435
|
-
env:
|
|
439
|
+
env: payload.executionSpec
|
|
440
|
+
? {
|
|
441
|
+
...process.env,
|
|
442
|
+
[EXECUTION_SPEC_ENV]: payload.executionSpec,
|
|
443
|
+
[CODEX_SESSION_TOKEN_ENV]: process.env[TASK_DELEGATION_ENV] || process.env[CODEX_SESSION_TOKEN_ENV] || '',
|
|
444
|
+
}
|
|
445
|
+
: process.env,
|
|
436
446
|
stdio: ['ignore', 'pipe', payload.mergeStderr ? 'pipe' : 'inherit'],
|
|
437
447
|
windowsHide: IS_WINDOWS,
|
|
438
448
|
});
|
|
@@ -33,8 +33,8 @@ import { buildClaudeUnixSocketAllowlist } from '../core/permission/unix-socket-p
|
|
|
33
33
|
import { auditToolInfrastructureFailure, auditToolPreflightDenial } from '../core/auth/authorization-audit.js';
|
|
34
34
|
import { getManagedTaskTempDir, isManagedSessionRuntimeDir } from '../cli/task-context.js';
|
|
35
35
|
import { unsettledInterruptError, withInterruptDeadline, hasTrustedFullAccessContext } from './runner-types.js';
|
|
36
|
-
import { resolveModelSpec } from '../stats/
|
|
37
|
-
import { contextTokensForUsage, usageForContext,
|
|
36
|
+
import { getGatewayPricing as getSharedGatewayPricing, resolveModelSpec } from '../stats/price-resolver.js';
|
|
37
|
+
import { contextTokensForUsage, usageForContext, realContextWindowForModel, autoCompactWindowForModel, sdkAutoCompactWindowForModel } from './runner-types.js';
|
|
38
38
|
import { hasContextWindowSuffix, stripContextWindowSuffix } from '../core/model/context-window-suffix.js';
|
|
39
39
|
const resolveModule = createRequire(import.meta.url);
|
|
40
40
|
const CLAUDE_INTERRUPT_TIMEOUT_MS = 5_000;
|
|
@@ -438,80 +438,9 @@ async function assertClaudeSettingSourcesHaveLiteralSandboxPaths(cwd, settingSou
|
|
|
438
438
|
}
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
|
-
// ──
|
|
442
|
-
//
|
|
443
|
-
//
|
|
444
|
-
const GATEWAY_PRICING_TTL_MS = 60 * 60 * 1000; // 1h
|
|
445
|
-
const gatewayPricingCache = new Map(); // key: baseUrl
|
|
446
|
-
const gatewayPricingInFlight = new Set(); // 去重并发刷新
|
|
447
|
-
/** 把 /v1/models 单个 model 的价格对象转为 PriceQuad(与 gateway-control 的 apiPricingToQuad 等价)。
|
|
448
|
-
* 单位假设:接口价与 model-prices.jsonl 同口径(USD per 1M token),不做换算。 */
|
|
449
|
-
function apiPricingToQuad(p) {
|
|
450
|
-
if (!p || typeof p !== 'object')
|
|
451
|
-
return undefined;
|
|
452
|
-
const n = (v) => (typeof v === 'number' && isFinite(v) ? v : undefined);
|
|
453
|
-
const quad = {
|
|
454
|
-
input: n(p.input),
|
|
455
|
-
output: n(p.output),
|
|
456
|
-
cache_read: n(p.cache_read),
|
|
457
|
-
cache_write: n(p.cache_write),
|
|
458
|
-
};
|
|
459
|
-
// 全空则视为无价
|
|
460
|
-
if (quad.input === undefined && quad.output === undefined
|
|
461
|
-
&& quad.cache_read === undefined && quad.cache_write === undefined)
|
|
462
|
-
return undefined;
|
|
463
|
-
return quad;
|
|
464
|
-
}
|
|
465
|
-
/** 拉取网关 /v1/models 的官方价(pricing) + 网关价(effective_pricing),写入 gatewayPricingCache。
|
|
466
|
-
* 失败静默——保持回退到本地价表 / official。 */
|
|
467
|
-
async function refreshGatewayPricing(baseUrl, apiKey, requestHeaders) {
|
|
468
|
-
if (gatewayPricingInFlight.has(baseUrl))
|
|
469
|
-
return;
|
|
470
|
-
gatewayPricingInFlight.add(baseUrl);
|
|
471
|
-
try {
|
|
472
|
-
const url = `${baseUrl.replace(/\/+$/, '')}/v1/models`;
|
|
473
|
-
const controller = new AbortController();
|
|
474
|
-
const timer = setTimeout(() => controller.abort(), 5000);
|
|
475
|
-
const resp = await fetch(url, {
|
|
476
|
-
signal: controller.signal,
|
|
477
|
-
headers: {
|
|
478
|
-
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
479
|
-
...requestHeaders,
|
|
480
|
-
},
|
|
481
|
-
});
|
|
482
|
-
clearTimeout(timer);
|
|
483
|
-
if (!resp.ok)
|
|
484
|
-
return;
|
|
485
|
-
const json = await resp.json();
|
|
486
|
-
const arr = Array.isArray(json?.data) ? json.data
|
|
487
|
-
: Array.isArray(json?.models) ? json.models : [];
|
|
488
|
-
const official = new Map();
|
|
489
|
-
const gateway = new Map();
|
|
490
|
-
for (const m of arr) {
|
|
491
|
-
const id = typeof m === 'string' ? m : (m?.id || m?.name || m?.model);
|
|
492
|
-
if (!id || typeof m !== 'object')
|
|
493
|
-
continue;
|
|
494
|
-
const off = apiPricingToQuad(m.pricing);
|
|
495
|
-
if (off)
|
|
496
|
-
official.set(id, off);
|
|
497
|
-
const gw = apiPricingToQuad(m.effective_pricing);
|
|
498
|
-
if (gw)
|
|
499
|
-
gateway.set(id, gw);
|
|
500
|
-
}
|
|
501
|
-
// 汇率:接口 usd_to_cny,缺失则留空(计费层默认用 7)
|
|
502
|
-
const usdToCny = (typeof json?.usd_to_cny === 'number' && json.usd_to_cny > 0) ? json.usd_to_cny : undefined;
|
|
503
|
-
if (official.size > 0 || gateway.size > 0) {
|
|
504
|
-
gatewayPricingCache.set(baseUrl, { cache: { official, gateway, usdToCny }, fetchedAt: Date.now() });
|
|
505
|
-
logger.info(`[AgentRunner] Refreshed gateway pricing from ${url}: official=${official.size} gateway=${gateway.size} usd_to_cny=${usdToCny ?? '(default 7)'}`);
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
catch {
|
|
509
|
-
// 网络/解析失败:保持回退,不打断查询
|
|
510
|
-
}
|
|
511
|
-
finally {
|
|
512
|
-
gatewayPricingInFlight.delete(baseUrl);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
441
|
+
// ── 网关价格缓存 ─────────────────────────────────────────────────────────────
|
|
442
|
+
// 价格获取、缓存与计费统一由 price-resolver.ts 管理,各基座共用一份缓存
|
|
443
|
+
// (按 baseUrl、1h TTL、stale-while-revalidate)。
|
|
515
444
|
/**
|
|
516
445
|
* 为支持 1M 上下文的模型追加 `[1m]` 后缀——仅在交给 SDK query() 时调用。
|
|
517
446
|
*
|
|
@@ -798,13 +727,7 @@ export class AgentRunner {
|
|
|
798
727
|
/** 返回当前网关 /v1/models 的价格缓存(1h TTL,stale-while-revalidate)。
|
|
799
728
|
* 缺失/过期时 fire-and-forget 触发刷新,本轮先返回旧值或 undefined(回退本地价表)。 */
|
|
800
729
|
getGatewayPricing() {
|
|
801
|
-
|
|
802
|
-
return undefined;
|
|
803
|
-
const entry = gatewayPricingCache.get(this.baseUrl);
|
|
804
|
-
if (!entry || Date.now() - entry.fetchedAt > GATEWAY_PRICING_TTL_MS) {
|
|
805
|
-
refreshGatewayPricing(this.baseUrl, this.apiKey, this.customHeaders); // 不 await,stale-while-revalidate
|
|
806
|
-
}
|
|
807
|
-
return entry?.cache;
|
|
730
|
+
return getSharedGatewayPricing(this.baseUrl, this.apiKey, this.customHeaders);
|
|
808
731
|
}
|
|
809
732
|
async resolveCapabilityRunOptions(projectPath) {
|
|
810
733
|
let agentConfig = this.agentConfig;
|
|
@@ -1912,10 +1835,8 @@ export class AgentRunner {
|
|
|
1912
1835
|
const cleanResult = typeof event.result === 'string'
|
|
1913
1836
|
? event.result.replace(/<thinking>[\s\S]*?<\/thinking>\s*/g, '').trim()
|
|
1914
1837
|
: event.result;
|
|
1915
|
-
//
|
|
1916
|
-
//
|
|
1917
|
-
// 非 Claude(DeepSeek/OpenAI 兼容):cache_read 是服务端 KV cache 不占上下文窗口,
|
|
1918
|
-
// input_tokens 本身就是完整的上下文输入量。
|
|
1838
|
+
// 非 GPT 的上下文占用 = 输入 + 输出 + 缓存创建 + 缓存读取。
|
|
1839
|
+
// GPT 沿用原有的输入口径,避免重复计算已包含在输入中的缓存。
|
|
1919
1840
|
const u = event.usage;
|
|
1920
1841
|
// Claude Code represents transport/API failures as a fresh
|
|
1921
1842
|
// `<synthetic>` assistant message. Its usage describes the failed
|
|
@@ -1930,8 +1851,7 @@ export class AgentRunner {
|
|
|
1930
1851
|
};
|
|
1931
1852
|
const terminalUsage = isSyntheticError ? syntheticUsage : u;
|
|
1932
1853
|
const effectiveModel = callModel ?? this.model;
|
|
1933
|
-
const
|
|
1934
|
-
const totalTokens = contextTokensForUsage(u, !!isClaudeModel);
|
|
1854
|
+
const totalTokens = contextTokensForUsage(u, effectiveModel);
|
|
1935
1855
|
const contextWindowTokens = resolvedContextWindow ?? realContextWindowForModel(sdkModel);
|
|
1936
1856
|
const autoCompactTokens = autoCompactWindowForModel(sdkModel);
|
|
1937
1857
|
const aggregateContextUsage = totalTokens > 0 ? {
|
|
@@ -1944,7 +1864,7 @@ export class AgentRunner {
|
|
|
1944
1864
|
} : undefined;
|
|
1945
1865
|
if (lastModelCall?.tokenUsage) {
|
|
1946
1866
|
const lastUsageForContext = usageForContext(lastModelCall.tokenUsage);
|
|
1947
|
-
const lastTotalTokens = contextTokensForUsage(lastUsageForContext,
|
|
1867
|
+
const lastTotalTokens = contextTokensForUsage(lastUsageForContext, effectiveModel);
|
|
1948
1868
|
lastModelCall = {
|
|
1949
1869
|
...lastModelCall,
|
|
1950
1870
|
contextUsage: lastTotalTokens > 0 ? {
|
|
@@ -1958,7 +1878,7 @@ export class AgentRunner {
|
|
|
1958
1878
|
};
|
|
1959
1879
|
}
|
|
1960
1880
|
const contextUsageForCall = (usage) => {
|
|
1961
|
-
const callTotalTokens = contextTokensForUsage(usageForContext(usage),
|
|
1881
|
+
const callTotalTokens = contextTokensForUsage(usageForContext(usage), effectiveModel);
|
|
1962
1882
|
return callTotalTokens > 0 ? {
|
|
1963
1883
|
totalTokens: callTotalTokens,
|
|
1964
1884
|
maxTokens: contextWindowTokens,
|
|
@@ -2151,10 +2071,7 @@ export class AgentRunner {
|
|
|
2151
2071
|
const runCatalog = await this.getModelCatalog();
|
|
2152
2072
|
if (this.baseUrl) {
|
|
2153
2073
|
// 顺带预热网关价格缓存(1h TTL),让本轮结束写库时已就绪
|
|
2154
|
-
|
|
2155
|
-
if (!pricing || (Date.now() - pricing.fetchedAt > GATEWAY_PRICING_TTL_MS)) {
|
|
2156
|
-
refreshGatewayPricing(this.baseUrl, this.apiKey, this.customHeaders);
|
|
2157
|
-
}
|
|
2074
|
+
void getSharedGatewayPricing(this.baseUrl, this.apiKey, this.customHeaders);
|
|
2158
2075
|
}
|
|
2159
2076
|
ensureDir(projectPath);
|
|
2160
2077
|
ensureDir(path.join(projectPath, '.claude'));
|
|
@@ -2217,13 +2134,16 @@ export class AgentRunner {
|
|
|
2217
2134
|
throw error;
|
|
2218
2135
|
}
|
|
2219
2136
|
logger.warn(`[AgentRunner] Invalid session file, starting new session`);
|
|
2137
|
+
if (modelOverride?.capsule) {
|
|
2138
|
+
const recovered = await modelOverride.capsule.recover(agentSessionId, prompt, systemPromptAppend);
|
|
2139
|
+
prompt = recovered.prompt;
|
|
2140
|
+
systemPromptAppend = recovered.systemPrompt;
|
|
2141
|
+
}
|
|
2142
|
+
else if (this.onSessionIdUpdate) {
|
|
2143
|
+
await this.onSessionIdUpdate(sessionId, '');
|
|
2144
|
+
}
|
|
2220
2145
|
agentSessionId = undefined;
|
|
2221
2146
|
this.activeSessions.delete(sessionId);
|
|
2222
|
-
if (this.onSessionIdUpdate) {
|
|
2223
|
-
void Promise.resolve(this.onSessionIdUpdate(sessionId, '')).catch(error => {
|
|
2224
|
-
logger.debug(`[AgentRunner] ignored empty session binding callback failure: ${error instanceof Error ? error.message : String(error)}`);
|
|
2225
|
-
});
|
|
2226
|
-
}
|
|
2227
2147
|
}
|
|
2228
2148
|
}
|
|
2229
2149
|
// PreCompact Hook - 在压缩开始时触发
|
|
@@ -3070,12 +2990,7 @@ export class AgentRunner {
|
|
|
3070
2990
|
logger.info('[AgentRunner] Creating query with images:', images.length, 'first image size:', images[0]?.data?.length ?? 0);
|
|
3071
2991
|
msgStream.push(prompt, images, inputId);
|
|
3072
2992
|
try {
|
|
3073
|
-
|
|
3074
|
-
// an unresumed Claude query for a bound topic would discover a second
|
|
3075
|
-
// backend and then fail activation with a binding conflict.
|
|
3076
|
-
sdkStream = topicBinding || recoverySessionId
|
|
3077
|
-
? createQuery(msgStream, agentSessionId, resumeAt)
|
|
3078
|
-
: createQuery(msgStream);
|
|
2993
|
+
sdkStream = createQuery(msgStream, agentSessionId, resumeAt);
|
|
3079
2994
|
}
|
|
3080
2995
|
catch (error) {
|
|
3081
2996
|
this.cleanupSandboxSettingsFile(sessionId, sandboxSettingsFile);
|