@daluo/cli 0.1.2 → 0.1.3

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/run.js CHANGED
@@ -2127,23 +2127,12 @@ var init_permission_schema = __esm({
2127
2127
  }
2128
2128
  });
2129
2129
 
2130
- // packages/core/src/session/event/schema.ts
2130
+ // packages/core/src/session/event/schema-base.ts
2131
2131
  import { z as z2 } from "zod";
2132
- function isTextPart(part) {
2133
- return part.type === "text";
2134
- }
2135
- function isReasoningPart(part) {
2136
- return part.type === "reasoning";
2137
- }
2138
- function isToolCallPart(part) {
2139
- return part.type === "tool-call";
2140
- }
2141
- var BaseEventSchema, SessionCreatedSchema, SessionImportedSchema, TextPartSchema, ToolCallPartSchema, ReasoningPartSchema, ContentPartSchema, UserImageSchema, MessageUserSchema, ContextInjectedSchema, LlmUsageSchema, MessageAssistantSchema, DeltaTextSchema, DeltaToolCallSchema, DeltaSchema, AssistantDeltaSchema, ToolResultImageSchema, ToolBatchSchema, ToolResultSchema, CompactionSummarySchema, PromptSystemSchema, PromptCacheBreakSchema, MemoryExtractSchema, CompactionReclaimSchema, SubagentStartSchema, SubagentReportSchema, VerifyVerdictSchema, TodoSchema, TodoUpdateSchema, PlanModeSchema, PolicyProfileSchema, GoalSchema, GoalSetSchema, WorkflowNodeSchema, WorkflowStartSchema, WorkflowEndSchema, TeamMemberSchema, TeamMemberCreateSchema, TeamMessageSchema, TeamMessageQueuedSchema, TeamMessageDeliveredSchema, TeamTaskSchema, TeamTaskUpdateSchema, TaskEvidenceSchema, TeamTaskResultSchema, TeamTaskResultEventSchema, SessionRenamedSchema, SessionModelChangedSchema, WorkingDirectoryChangedSchema, SessionArchivedSchema, MAX_LABELS, MAX_LABEL_KEY_CHARS, MAX_LABEL_VALUE_CHARS, SessionLabelsSchema, CommandRunSchema, CommandDoneSchema, InboxQueuedSchema, InboxEditedSchema, InboxRemovedSchema, InboxRequeuedSchema, AskOriginSchema, AskRequestedSchema, AskAnsweredSchema, GoalClearedSchema, FeedbackRecordedSchema, FeedbackRetractedSchema, SessionBranchSummarySchema, SessionEvent, SESSION_EVENT_TYPES;
2142
- var init_schema = __esm({
2143
- "packages/core/src/session/event/schema.ts"() {
2132
+ var BaseEventSchema;
2133
+ var init_schema_base = __esm({
2134
+ "packages/core/src/session/event/schema-base.ts"() {
2144
2135
  "use strict";
2145
- init_permission_schema();
2146
- init_permission_schema();
2147
2136
  BaseEventSchema = z2.object({
2148
2137
  sessionId: z2.string(),
2149
2138
  seq: z2.number().int().positive(),
@@ -2163,134 +2152,208 @@ var init_schema = __esm({
2163
2152
  */
2164
2153
  ignorable: z2.boolean().optional()
2165
2154
  });
2155
+ }
2156
+ });
2157
+
2158
+ // packages/core/src/session/event/schema-telemetry.ts
2159
+ import { z as z3 } from "zod";
2160
+ var PromptCacheBreakSchema, ContextReportSchema;
2161
+ var init_schema_telemetry = __esm({
2162
+ "packages/core/src/session/event/schema-telemetry.ts"() {
2163
+ "use strict";
2164
+ init_schema_base();
2165
+ PromptCacheBreakSchema = BaseEventSchema.extend({
2166
+ type: z3.literal("prompt/cache-break"),
2167
+ /** 断裂点(**解释**,不是判据 —— G1-54 之后触发看 `measured`)。**可以是空数组**:「我们没改任何东西,但命中真降了」正是最需要被记下来的那一种(TTL 过期 / 服务端侧变化)。 */
2168
+ findings: z3.array(
2169
+ z3.object({
2170
+ field: z3.enum(["system", "tools", "tool-schema", "model", "history-rewritten"]),
2171
+ /** 指纹或名字(正文按 `prevSystemSeq` 取)。 */
2172
+ before: z3.string(),
2173
+ after: z3.string(),
2174
+ /** 点名对象(工具名 / 增删清单)。 */
2175
+ detail: z3.string().optional()
2176
+ })
2177
+ ),
2178
+ /** 上一次 `prompt/system` 事件的 seq——复盘据此取回**原文**(前后两份都在日志里)。 */
2179
+ prevSystemSeq: z3.number().int().positive().optional(),
2180
+ /**
2181
+ * **实测**的命中下降(G1-54):两半都来自 provider 真回的 usage。**只有真降才写这条事件**,
2182
+ * 所以它从「可选」变成「正常路径上必有」;缺省只为兼容旧日志与「指纹制」时期写下的那批。
2183
+ */
2184
+ measured: z3.object({
2185
+ prevCacheRead: z3.number().int().nonnegative(),
2186
+ cacheRead: z3.number().int().nonnegative(),
2187
+ drop: z3.number().int().positive()
2188
+ }).optional(),
2189
+ /** 距上一条 assistant 消息的间隔(G1-55 时效维;无从得知则缺省,**不猜**)。 */
2190
+ sinceLastAssistantMs: z3.number().int().nonnegative().optional(),
2191
+ /** 这一次下降是**我们自己造的**(G1-56:紧随其后的压缩 / 回收),不是故障。 */
2192
+ expected: z3.boolean().optional(),
2193
+ expectedReason: z3.string().optional()
2194
+ });
2195
+ ContextReportSchema = BaseEventSchema.extend({
2196
+ type: z3.literal("context/report"),
2197
+ /** 本次请求实测 prompt token(此刻水位,**不是**累加)。 */
2198
+ tokens: z3.number().int().nonnegative(),
2199
+ /** 生效的上下文窗口(与压缩阈值同源)。未配预算 ⇒ 缺省不带(不猜)。 */
2200
+ window: z3.number().int().positive().optional(),
2201
+ /** 压缩触发阈值(tokens > threshold ⇒ 下一次请求前会压)。未配预算 ⇒ 缺省不带。 */
2202
+ threshold: z3.number().int().nonnegative().optional(),
2203
+ /** 本次请求**之前**这一轮压了几次(>0 ⇒ 宿主知道历史刚被重写过,水位不能与上一行直接比)。 */
2204
+ compactions: z3.number().int().positive().optional()
2205
+ });
2206
+ }
2207
+ });
2208
+
2209
+ // packages/core/src/session/event/schema.ts
2210
+ import { z as z4 } from "zod";
2211
+ function isTextPart(part) {
2212
+ return part.type === "text";
2213
+ }
2214
+ function isReasoningPart(part) {
2215
+ return part.type === "reasoning";
2216
+ }
2217
+ function isToolCallPart(part) {
2218
+ return part.type === "tool-call";
2219
+ }
2220
+ var SessionCreatedSchema, SessionImportedSchema, TextPartSchema, ToolCallPartSchema, ReasoningPartSchema, ContentPartSchema, UserImageSchema, MessageUserSchema, ContextInjectedSchema, LlmUsageSchema, MessageAssistantSchema, DeltaTextSchema, DeltaToolCallSchema, DeltaSchema, AssistantDeltaSchema, ToolResultImageSchema, ToolBatchSchema, ToolResultSchema, CompactionSummarySchema, PromptSystemSchema, MemoryExtractSchema, CompactionReclaimSchema, SubagentStartSchema, SubagentReportSchema, VerifyVerdictSchema, TodoSchema, TodoUpdateSchema, PlanModeSchema, PolicyProfileSchema, GoalSchema, GoalSetSchema, WorkflowNodeSchema, WorkflowStartSchema, WorkflowEndSchema, TeamMemberSchema, TeamMemberCreateSchema, TeamMessageSchema, TeamMessageQueuedSchema, TeamMessageDeliveredSchema, TeamTaskSchema, TeamTaskUpdateSchema, TaskEvidenceSchema, TeamTaskResultSchema, TeamTaskResultEventSchema, SessionRenamedSchema, SessionModelChangedSchema, WorkingDirectoryChangedSchema, SessionArchivedSchema, MAX_LABELS, MAX_LABEL_KEY_CHARS, MAX_LABEL_VALUE_CHARS, SessionLabelsSchema, CommandRunSchema, CommandDoneSchema, InboxQueuedSchema, InboxEditedSchema, InboxRemovedSchema, InboxRequeuedSchema, AskOriginSchema, AskRequestedSchema, AskAnsweredSchema, GoalClearedSchema, FeedbackRecordedSchema, FeedbackRetractedSchema, SessionBranchSummarySchema, SessionEvent, SESSION_EVENT_TYPES;
2221
+ var init_schema = __esm({
2222
+ "packages/core/src/session/event/schema.ts"() {
2223
+ "use strict";
2224
+ init_permission_schema();
2225
+ init_schema_base();
2226
+ init_schema_telemetry();
2227
+ init_permission_schema();
2228
+ init_schema_telemetry();
2166
2229
  SessionCreatedSchema = BaseEventSchema.extend({
2167
- type: z2.literal("session/created"),
2168
- forkedFrom: z2.object({
2230
+ type: z4.literal("session/created"),
2231
+ forkedFrom: z4.object({
2169
2232
  /** 源会话 sessionId(稳定身份;文件名只作人类可读的指路)。 */
2170
- sessionId: z2.string(),
2233
+ sessionId: z4.string(),
2171
2234
  /** 源日志文件名(basename)——供 CLI/呈现直接指路。 */
2172
- file: z2.string(),
2235
+ file: z4.string(),
2173
2236
  /** 切割点:新会话继承了源的 `[1..seq]` 前缀(seq 必须落在**回合边界**上)。 */
2174
- seq: z2.number().int().positive()
2237
+ seq: z4.number().int().positive()
2175
2238
  }).optional()
2176
2239
  });
2177
2240
  SessionImportedSchema = BaseEventSchema.extend({
2178
- type: z2.literal("session/imported"),
2241
+ type: z4.literal("session/imported"),
2179
2242
  /** 源文件 basename(人类可读指路;导入是「这一份源 → 这一份目标」)。 */
2180
- file: z2.string().min(1),
2243
+ file: z4.string().min(1),
2181
2244
  /** 源格式(闭集:本仓支持的两家)。 */
2182
- format: z2.enum(["claude", "codex"]),
2245
+ format: z4.enum(["claude", "codex"]),
2183
2246
  /** 源会话 id(拿得到就给)。 */
2184
- sourceSessionId: z2.string().min(1).optional(),
2247
+ sourceSessionId: z4.string().min(1).optional(),
2185
2248
  /** 已导入的**条目数**(游标)。 */
2186
- entries: z2.number().int().nonnegative(),
2249
+ entries: z4.number().int().nonnegative(),
2187
2250
  /** 已导入条目的 digest(sha256 前 16)——resync 时校验「已导入的那一段没被改过」。 */
2188
- digest: z2.string().min(1)
2251
+ digest: z4.string().min(1)
2189
2252
  });
2190
- TextPartSchema = z2.object({
2191
- type: z2.literal("text"),
2192
- text: z2.string()
2253
+ TextPartSchema = z4.object({
2254
+ type: z4.literal("text"),
2255
+ text: z4.string()
2193
2256
  });
2194
- ToolCallPartSchema = z2.object({
2195
- type: z2.literal("tool-call"),
2196
- toolCallId: z2.string(),
2197
- toolName: z2.string(),
2198
- input: z2.unknown()
2257
+ ToolCallPartSchema = z4.object({
2258
+ type: z4.literal("tool-call"),
2259
+ toolCallId: z4.string(),
2260
+ toolName: z4.string(),
2261
+ input: z4.unknown()
2199
2262
  });
2200
- ReasoningPartSchema = z2.object({
2201
- type: z2.literal("reasoning"),
2202
- text: z2.string()
2263
+ ReasoningPartSchema = z4.object({
2264
+ type: z4.literal("reasoning"),
2265
+ text: z4.string()
2203
2266
  });
2204
- ContentPartSchema = z2.discriminatedUnion("type", [
2267
+ ContentPartSchema = z4.discriminatedUnion("type", [
2205
2268
  TextPartSchema,
2206
2269
  ToolCallPartSchema,
2207
2270
  ReasoningPartSchema
2208
2271
  ]);
2209
- UserImageSchema = z2.object({
2272
+ UserImageSchema = z4.object({
2210
2273
  /** 落盘后的**绝对路径**(字节在 `.daluo/tool-results/user-images/`;文件被清掉时那次请求退回纯文本)。 */
2211
- path: z2.string(),
2212
- mediaType: z2.string(),
2213
- bytes: z2.number().int().nonnegative(),
2274
+ path: z4.string(),
2275
+ mediaType: z4.string(),
2276
+ bytes: z4.number().int().nonnegative(),
2214
2277
  /** 像素宽高(能读到才写:PNG/JPEG/GIF/WebP 四种头;读不出就省字段,**不编**)。 */
2215
- width: z2.number().int().positive().optional(),
2216
- height: z2.number().int().positive().optional()
2278
+ width: z4.number().int().positive().optional(),
2279
+ height: z4.number().int().positive().optional()
2217
2280
  });
2218
2281
  MessageUserSchema = BaseEventSchema.extend({
2219
- type: z2.literal("message/user"),
2220
- content: z2.string(),
2282
+ type: z4.literal("message/user"),
2283
+ content: z4.string(),
2221
2284
  /** 用户随这条消息附上的图(刀72):**可选**(老日志照常解析);附不附由请求侧按视觉能力与上限定。 */
2222
- images: z2.array(UserImageSchema).optional(),
2285
+ images: z4.array(UserImageSchema).optional(),
2223
2286
  /**
2224
2287
  * 投递回执(spec/input-queue.md 决策 1):这条 user 消息来自哪条待发项(`inbox/queued` 的 id)。
2225
2288
  * 它就是「**已投递**」这件事本身——`fold` 的 `pending = queued − removed − delivered` 据此收敛。
2226
2289
  * 对齐 dsh 的 `rpcId`(客户端据此把本地提交回声退休),也与团队消息 queued/delivered 同构。
2227
2290
  */
2228
- inboxId: z2.string().optional()
2291
+ inboxId: z4.string().optional()
2229
2292
  });
2230
2293
  ContextInjectedSchema = BaseEventSchema.extend({
2231
- type: z2.literal("context/injected"),
2294
+ type: z4.literal("context/injected"),
2232
2295
  /** 渲染后的块文本(含 `[context:<kind>]` 头)——**就是模型看到的那一段**,逐字存。 */
2233
- content: z2.string()
2296
+ content: z4.string()
2234
2297
  });
2235
- LlmUsageSchema = z2.object({
2236
- promptTokens: z2.number().int().nonnegative(),
2237
- completionTokens: z2.number().int().nonnegative(),
2298
+ LlmUsageSchema = z4.object({
2299
+ promptTokens: z4.number().int().nonnegative(),
2300
+ completionTokens: z4.number().int().nonnegative(),
2238
2301
  /** 缓存命中 token(`prompt_tokens_details.cached_tokens`):provider 未回则不写。 */
2239
- cachedTokens: z2.number().int().nonnegative().optional(),
2302
+ cachedTokens: z4.number().int().nonnegative().optional(),
2240
2303
  /** 思维链占用的输出 token(`completion_tokens_details.reasoning_tokens`):含在 completionTokens 内。 */
2241
- reasoningTokens: z2.number().int().nonnegative().optional()
2304
+ reasoningTokens: z4.number().int().nonnegative().optional()
2242
2305
  });
2243
2306
  MessageAssistantSchema = BaseEventSchema.extend({
2244
- type: z2.literal("message/assistant"),
2245
- content: z2.array(ContentPartSchema),
2307
+ type: z4.literal("message/assistant"),
2308
+ content: z4.array(ContentPartSchema),
2246
2309
  usage: LlmUsageSchema.optional(),
2247
- model: z2.string().min(1).optional()
2310
+ model: z4.string().min(1).optional()
2248
2311
  });
2249
- DeltaTextSchema = z2.object({
2250
- kind: z2.literal("text"),
2251
- text: z2.string()
2312
+ DeltaTextSchema = z4.object({
2313
+ kind: z4.literal("text"),
2314
+ text: z4.string()
2252
2315
  });
2253
- DeltaToolCallSchema = z2.object({
2254
- kind: z2.literal("tool-call"),
2255
- toolCallId: z2.string(),
2256
- name: z2.string().optional(),
2257
- arguments: z2.unknown().optional()
2316
+ DeltaToolCallSchema = z4.object({
2317
+ kind: z4.literal("tool-call"),
2318
+ toolCallId: z4.string(),
2319
+ name: z4.string().optional(),
2320
+ arguments: z4.unknown().optional()
2258
2321
  });
2259
- DeltaSchema = z2.discriminatedUnion("kind", [DeltaTextSchema, DeltaToolCallSchema]);
2322
+ DeltaSchema = z4.discriminatedUnion("kind", [DeltaTextSchema, DeltaToolCallSchema]);
2260
2323
  AssistantDeltaSchema = BaseEventSchema.extend({
2261
- type: z2.literal("assistant/delta"),
2324
+ type: z4.literal("assistant/delta"),
2262
2325
  delta: DeltaSchema
2263
2326
  });
2264
- ToolResultImageSchema = z2.object({
2327
+ ToolResultImageSchema = z4.object({
2265
2328
  /** 图落盘的绝对路径(文件被清掉时那次请求退回纯文本,见演进节记的边界)。 */
2266
- path: z2.string(),
2329
+ path: z4.string(),
2267
2330
  /** 落盘时的 MIME(`image/png` 等)。 */
2268
- mediaType: z2.string(),
2269
- bytes: z2.number().int().nonnegative()
2331
+ mediaType: z4.string(),
2332
+ bytes: z4.number().int().nonnegative()
2270
2333
  });
2271
2334
  ToolBatchSchema = BaseEventSchema.extend({
2272
- type: z2.literal("tool/batch"),
2335
+ type: z4.literal("tool/batch"),
2273
2336
  /** 本批的调用 id(**顺序 = calls 顺序**;并发执行,不表示先后)。 */
2274
- toolCallIds: z2.array(z2.string()),
2337
+ toolCallIds: z4.array(z4.string()),
2275
2338
  /** 批开跑的时刻(与各 `tool/result` 的 `ts` 一起看,就能分辨「真并发」与「排着跑」)。 */
2276
- startedAt: z2.string(),
2277
- ok: z2.number().int().nonnegative(),
2278
- failed: z2.number().int().nonnegative()
2339
+ startedAt: z4.string(),
2340
+ ok: z4.number().int().nonnegative(),
2341
+ failed: z4.number().int().nonnegative()
2279
2342
  });
2280
2343
  ToolResultSchema = BaseEventSchema.extend({
2281
- type: z2.literal("tool/result"),
2282
- toolCallId: z2.string(),
2283
- output: z2.unknown(),
2344
+ type: z4.literal("tool/result"),
2345
+ toolCallId: z4.string(),
2346
+ output: z4.unknown(),
2284
2347
  /**
2285
2348
  * 这次结果带回的图像(可选)。**与 `output` 分开**:`output` 会过预算那一步(超限换 stub/省略),
2286
2349
  * 图引用不该被预算改写——它是「图在哪」的事实。
2287
2350
  */
2288
- images: z2.array(ToolResultImageSchema).optional(),
2351
+ images: z4.array(ToolResultImageSchema).optional(),
2289
2352
  /**
2290
2353
  * 呈现元数据(spec/session-event.md 演进节 + tool-registry.md):**工具自己**给出的人话标题
2291
2354
  * (`present(input)` 的结果;纯函数 ⇒ 重放一致)。**可选**:没给就由呈现层从参数猜(老行为不破)。
2292
2355
  */
2293
- present: z2.object({ title: z2.string(), kind: z2.string().optional() }).optional(),
2356
+ present: z4.object({ title: z4.string(), kind: z4.string().optional() }).optional(),
2294
2357
  /**
2295
2358
  * **退出码语义**(演进 2026-09-21,spec/tools.md「退出码不是布尔」/ G2-20,bash 产出)。
2296
2359
  *
@@ -2301,7 +2364,7 @@ var init_schema = __esm({
2301
2364
  * `isGenuinePass`)。**存在即「否定退出码」**(真故障走 `{error}` 结果,不需要它)。
2302
2365
  * 可选 ⇒ 既有事件零迁移;不喂 LLM(模型读的是 output 正文里的人话)。
2303
2366
  */
2304
- exitSemantics: z2.object({ code: z2.number().int(), label: z2.string() }).optional(),
2367
+ exitSemantics: z4.object({ code: z4.number().int(), label: z4.string() }).optional(),
2305
2368
  /**
2306
2369
  * **假绿证据**(演进 2026-09-22,spec/a2-plan-goal.md A2b-7 / G5-48,bash 产出)。
2307
2370
  *
@@ -2311,13 +2374,13 @@ var init_schema = __esm({
2311
2374
  * 而「这条命令自称零用例」是**判定事实**,挂在正文形状上会被冲掉。**存在即「没验到东西」**。
2312
2375
  * 可选 ⇒ 既有事件零迁移;不喂 LLM。`unchanged` 同款分工,见 spec/repeat-reminder.md 决策 10。
2313
2376
  */
2314
- falseGreen: z2.object({ declaration: z2.string(), sample: z2.string() }).optional(),
2315
- unchanged: z2.literal(true).optional()
2377
+ falseGreen: z4.object({ declaration: z4.string(), sample: z4.string() }).optional(),
2378
+ unchanged: z4.literal(true).optional()
2316
2379
  // 等待自报(2026-10-22):工具说「世界没变,我在等」⇒ 重复门豁免
2317
2380
  });
2318
2381
  CompactionSummarySchema = BaseEventSchema.extend({
2319
- type: z2.literal("compaction/summary"),
2320
- summary: z2.string(),
2382
+ type: z4.literal("compaction/summary"),
2383
+ summary: z4.string(),
2321
2384
  /**
2322
2385
  * 这次摘要**是谁产的**(演进,`G1-43` 降级路径主动披露):
2323
2386
  * `explicit`(调用方给的)· `llm`(LLM 产出)· `rule`(**没给** LLM 摘要,规则兜底——正常路径)
@@ -2327,9 +2390,9 @@ var init_schema = __esm({
2327
2390
  * 复盘)就分不出「这次是坏掉了」还是「这次本来就没用 LLM」——那正是 `G10-25` 那条纪律
2328
2391
  * (边界要用**可表达的类型**写出来,别靠旁路信号猜)。可选 ⇒ 既有日志零迁移。
2329
2392
  */
2330
- summarySource: z2.enum(["explicit", "llm", "rule", "rule-degraded"]).optional(),
2331
- keepMessages: z2.number().int().nonnegative(),
2332
- shadowedToolCallIds: z2.array(z2.string()),
2393
+ summarySource: z4.enum(["explicit", "llm", "rule", "rule-degraded"]).optional(),
2394
+ keepMessages: z4.number().int().nonnegative(),
2395
+ shadowedToolCallIds: z4.array(z4.string()),
2333
2396
  /**
2334
2397
  * 压缩后**重注的文件**(演进,`spec/compaction.md` 演进:P0-2「谁重新注入」的显式清单)。
2335
2398
  *
@@ -2339,191 +2402,161 @@ var init_schema = __esm({
2339
2402
  * **本仓不照抄它的数值**且换成字符口径,理由见 `compaction.ts` 的预算常量注释。
2340
2403
  * 可选 ⇒ 既有事件零迁移。
2341
2404
  */
2342
- attachments: z2.array(z2.object({ path: z2.string(), content: z2.string(), truncated: z2.boolean() })).optional(),
2405
+ attachments: z4.array(z4.object({ path: z4.string(), content: z4.string(), truncated: z4.boolean() })).optional(),
2343
2406
  /** 想重注但没重注的文件 + 原因(**如实记账**:模型看不到就得知道为什么,对齐本仓「不静默降级」)。 */
2344
- attachmentsSkipped: z2.array(z2.object({ path: z2.string(), reason: z2.string() })).optional(),
2407
+ attachmentsSkipped: z4.array(z4.object({ path: z4.string(), reason: z4.string() })).optional(),
2345
2408
  /**
2346
2409
  * 这次压缩**摘的是哪份源的哪一段**(演进,`spec/session-tree.md` 演进:`G3-15` 摘要到此的出处)。
2347
2410
  *
2348
2411
  * 「摘要到此」是在**新会话**里写一条压缩事件(前缀被摘要替代、之后原文照抄)——不留出处的话,
2349
2412
  * 那份新会话说不清「这段摘要是从哪来的」,审计与人对账都无从下手。**可选** ⇒ 既有压缩零迁移。
2350
2413
  */
2351
- summarizedSource: z2.object({
2352
- sessionId: z2.string(),
2353
- file: z2.string(),
2414
+ summarizedSource: z4.object({
2415
+ sessionId: z4.string(),
2416
+ file: z4.string(),
2354
2417
  /** 摘要覆盖源的 `[1..upToSeq]`。 */
2355
- upToSeq: z2.number().int().positive()
2418
+ upToSeq: z4.number().int().positive()
2356
2419
  }).optional()
2357
2420
  });
2358
2421
  PromptSystemSchema = BaseEventSchema.extend({
2359
- type: z2.literal("prompt/system"),
2360
- content: z2.string(),
2422
+ type: z4.literal("prompt/system"),
2423
+ content: z4.string(),
2361
2424
  /**
2362
2425
  * 这次请求**真发出去的工具名清单**(顺序 = 发送顺序;2026-09-21 加,对齐 dsh 的 `EpochHeader`)。
2363
2426
  * 补的是一处审计缺口:从前日志只能看出发了哪份 system,看不出**这次用了哪套工具 schema**
2364
2427
  * ——"为什么这轮它没调 X"查不出来;缓存侧也没法归因(schema 在 token 流前部,一变就从那里起全失效)。
2365
2428
  * 可选(老日志没有这份字段,读到 undefined 即"未记录",不伪造)。
2366
2429
  */
2367
- tools: z2.array(z2.string()).optional(),
2430
+ tools: z4.array(z4.string()).optional(),
2368
2431
  /** 工具 schema 全文的指纹(`fileHash(JSON.stringify(tools))`)——**逐字节**判断"这套 schema 换没换"。 */
2369
- toolsFingerprint: z2.string().optional(),
2432
+ toolsFingerprint: z4.string().optional(),
2370
2433
  /** 工具定义 JSON 的**字符数**(读侧分项账用;只记长度不记全文;老日志无此字段 = 未记录,别当 0。由来见 `spec/token-meter.md` 演进「静态开销有了分项」)。 */
2371
- toolsChars: z2.number().int().nonnegative().optional()
2372
- });
2373
- PromptCacheBreakSchema = BaseEventSchema.extend({
2374
- type: z2.literal("prompt/cache-break"),
2375
- /** 断裂点(**解释**,不是判据 —— G1-54 之后触发看 `measured`)。**可以是空数组**:「我们没改任何东西,但命中真降了」正是最需要被记下来的那一种(TTL 过期 / 服务端侧变化)。 */
2376
- findings: z2.array(
2377
- z2.object({
2378
- field: z2.enum(["system", "tools", "tool-schema", "model", "history-rewritten"]),
2379
- /** 指纹或名字(正文按 `prevSystemSeq` 取)。 */
2380
- before: z2.string(),
2381
- after: z2.string(),
2382
- /** 点名对象(工具名 / 增删清单)。 */
2383
- detail: z2.string().optional()
2384
- })
2385
- ),
2386
- /** 上一次 `prompt/system` 事件的 seq——复盘据此取回**原文**(前后两份都在日志里)。 */
2387
- prevSystemSeq: z2.number().int().positive().optional(),
2388
- /**
2389
- * **实测**的命中下降(G1-54):两半都来自 provider 真回的 usage。**只有真降才写这条事件**,
2390
- * 所以它从「可选」变成「正常路径上必有」;缺省只为兼容旧日志与「指纹制」时期写下的那批。
2391
- */
2392
- measured: z2.object({
2393
- prevCacheRead: z2.number().int().nonnegative(),
2394
- cacheRead: z2.number().int().nonnegative(),
2395
- drop: z2.number().int().positive()
2396
- }).optional(),
2397
- /** 距上一条 assistant 消息的间隔(G1-55 时效维;无从得知则缺省,**不猜**)。 */
2398
- sinceLastAssistantMs: z2.number().int().nonnegative().optional(),
2399
- /** 这一次下降是**我们自己造的**(G1-56:紧随其后的压缩 / 回收),不是故障。 */
2400
- expected: z2.boolean().optional(),
2401
- expectedReason: z2.string().optional()
2434
+ toolsChars: z4.number().int().nonnegative().optional()
2402
2435
  });
2403
2436
  MemoryExtractSchema = BaseEventSchema.extend({
2404
- type: z2.literal("memory/extract"),
2437
+ type: z4.literal("memory/extract"),
2405
2438
  /** 过闸并入账的 key。 */
2406
- admitted: z2.array(z2.string()),
2439
+ admitted: z4.array(z4.string()),
2407
2440
  /** 被拒的候选与理由(**理由要能被人看见**,不是丢掉)。 */
2408
- rejected: z2.array(z2.object({ key: z2.string(), reason: z2.string() })),
2441
+ rejected: z4.array(z4.object({ key: z4.string(), reason: z4.string() })),
2409
2442
  /** 走取代链的 key(可选)。 */
2410
- superseded: z2.array(z2.string()).optional(),
2443
+ superseded: z4.array(z4.string()).optional(),
2411
2444
  /** true = LLM 输出不可解析 ⇒ **fail-closed 一条没写**(与「判完都拒了」区分开);`error` 是另一种失败:
2412
2445
  * 提取那次 LLM 调用**自己抛错**(网络/HTTP/超时)——「解析不出来」与「没拿到输出」日志里要分得开。 */
2413
- failedClosed: z2.boolean().optional(),
2414
- error: z2.string().optional(),
2446
+ failedClosed: z4.boolean().optional(),
2447
+ error: z4.string().optional(),
2415
2448
  /** 提取那次 LLM 调用的账(`P1-39` 步一):旁路调用此前完全没账 ⇒ `daluo usage` 系统性少算它;缺省 = provider 未回(不写 `{0,0}`:「没拿到」≠「用了 0」)。 */
2416
2449
  usage: LlmUsageSchema.optional(),
2417
2450
  /** 这次提取实际用的模型(与 `message/assistant.model` 同源命名)——它可以是独立的 `autoExtract.llm`。 */
2418
- model: z2.string().min(1).optional()
2451
+ model: z4.string().min(1).optional()
2419
2452
  });
2420
2453
  CompactionReclaimSchema = BaseEventSchema.extend({
2421
- type: z2.literal("compaction/reclaim"),
2454
+ type: z4.literal("compaction/reclaim"),
2422
2455
  /** 候选是否替换了历史(false = 原样保留、等下个边界)。 */
2423
- committed: z2.boolean(),
2456
+ committed: z4.boolean(),
2424
2457
  /**
2425
2458
  * 裁决原因(与 `reclaim-gate.ts` 的词表**同源**:3 个 skip + 2 个 commit + 1 个「冷却中没试」)。
2426
2459
  * `cooling-down` = **连试都没试**(拒绝后要等历史又长了一层绝对地板才值得再付一次摘要调用)——
2427
2460
  * 那一档没有候选,故下面的数字字段记的是**当时的历史规模**(`beforeTokens === afterTokens`)。
2428
2461
  */
2429
2462
  // `reclaim-cache-cold`(G1-57):前缀缓存已冷 ⇒ 只守绝对地板就提交(相对地板是给「热前缀」设的)
2430
- reason: z2.enum(["unchanged", "no-reclaim", "below-reclaim-floor", "cooling-down", "reclaim-above-floor", "reclaim-cache-cold", "forced"]),
2431
- beforeTokens: z2.number().int().nonnegative(),
2432
- afterTokens: z2.number().int().nonnegative(),
2463
+ reason: z4.enum(["unchanged", "no-reclaim", "below-reclaim-floor", "cooling-down", "reclaim-above-floor", "reclaim-cache-cold", "forced"]),
2464
+ beforeTokens: z4.number().int().nonnegative(),
2465
+ afterTokens: z4.number().int().nonnegative(),
2433
2466
  /** 原量 − 新量(**可以为负**:候选可能让输入变长)。 */
2434
- reclaimedTokens: z2.number().int(),
2467
+ reclaimedTokens: z4.number().int(),
2435
2468
  /** 回收 / 原量(没有回收时为 0)。 */
2436
- reclaimRatio: z2.number().nonnegative(),
2469
+ reclaimRatio: z4.number().nonnegative(),
2437
2470
  /** 候选与原文是否有实质差异(无差异的候选永远不该提交)。 */
2438
- changed: z2.boolean(),
2471
+ changed: z4.boolean(),
2439
2472
  /** 冷却门槛(只在 `reason: 'cooling-down'` 时有)——「长到这个规模才值得再试」。 */
2440
- coolingUntilTokens: z2.number().int().nonnegative().optional()
2473
+ coolingUntilTokens: z4.number().int().nonnegative().optional()
2441
2474
  });
2442
2475
  SubagentStartSchema = BaseEventSchema.extend({
2443
- type: z2.literal("subagent/start"),
2444
- subagentId: z2.string(),
2445
- task: z2.string()
2476
+ type: z4.literal("subagent/start"),
2477
+ subagentId: z4.string(),
2478
+ task: z4.string()
2446
2479
  });
2447
2480
  SubagentReportSchema = BaseEventSchema.extend({
2448
- type: z2.literal("subagent/report"),
2449
- subagentId: z2.string(),
2450
- result: z2.string()
2481
+ type: z4.literal("subagent/report"),
2482
+ subagentId: z4.string(),
2483
+ result: z4.string()
2451
2484
  });
2452
2485
  VerifyVerdictSchema = BaseEventSchema.extend({
2453
- type: z2.literal("verify/verdict"),
2486
+ type: z4.literal("verify/verdict"),
2454
2487
  /** 验证者会话 id(`verify-<uuid>`)——与它的独立日志一一对应,可审计。 */
2455
- verifierId: z2.string(),
2488
+ verifierId: z4.string(),
2456
2489
  /** 被验证的主张原文(重放时能看到「当时验的到底是什么」)。 */
2457
- claim: z2.string(),
2458
- verdict: z2.enum(["verified", "falsified", "inconclusive"]),
2490
+ claim: z4.string(),
2491
+ verdict: z4.enum(["verified", "falsified", "inconclusive"]),
2459
2492
  /** 验证主体:本次覆盖的产物(显式 `artifacts` ∪ 会话中最后改动的非文档文件)。 */
2460
- artifacts: z2.array(z2.string()),
2493
+ artifacts: z4.array(z4.string()),
2461
2494
  /** 主体内容指纹(16 位十六进制)。**取不到就不写**——不伪造。 */
2462
- subjectHash: z2.string().optional(),
2495
+ subjectHash: z4.string().optional(),
2463
2496
  /** true = 复用既有结论(主体指纹未变,本次**没有**重跑验证者)。 */
2464
- reused: z2.boolean().optional(),
2497
+ reused: z4.boolean().optional(),
2465
2498
  /** 验证者实际跑了几轮(复用时不写——那次没跑)。 */
2466
- turns: z2.number().int().nonnegative().optional(),
2499
+ turns: z4.number().int().nonnegative().optional(),
2467
2500
  usage: LlmUsageSchema.optional(),
2468
2501
  /** 非正常结束的原因(如 `budget-turns` / `budget-time`);缺失 = 正常跑完。 */
2469
- stopReason: z2.string().optional(),
2502
+ stopReason: z4.string().optional(),
2470
2503
  /** 验证者独立会话日志路径。 */
2471
- logFile: z2.string()
2504
+ logFile: z4.string()
2472
2505
  });
2473
- TodoSchema = z2.object({
2474
- id: z2.string(),
2475
- content: z2.string(),
2476
- status: z2.enum(["pending", "in_progress", "completed"])
2506
+ TodoSchema = z4.object({
2507
+ id: z4.string(),
2508
+ content: z4.string(),
2509
+ status: z4.enum(["pending", "in_progress", "completed"])
2477
2510
  });
2478
2511
  TodoUpdateSchema = BaseEventSchema.extend({
2479
- type: z2.literal("todo/update"),
2480
- todos: z2.array(TodoSchema)
2512
+ type: z4.literal("todo/update"),
2513
+ todos: z4.array(TodoSchema)
2481
2514
  });
2482
2515
  PlanModeSchema = BaseEventSchema.extend({
2483
- type: z2.literal("plan/mode"),
2484
- active: z2.boolean()
2516
+ type: z4.literal("plan/mode"),
2517
+ active: z4.boolean()
2485
2518
  });
2486
2519
  PolicyProfileSchema = BaseEventSchema.extend({
2487
- type: z2.literal("policy/profile"),
2488
- profile: z2.enum(["read-only", "workspace", "danger-full"]),
2520
+ type: z4.literal("policy/profile"),
2521
+ profile: z4.enum(["read-only", "workspace", "danger-full"]),
2489
2522
  /** 谁改的(审计用;缺省 'user'——老日志/CLI 内部改动不必标注)。 */
2490
- by: z2.enum(["user", "agent"]).optional()
2523
+ by: z4.enum(["user", "agent"]).optional()
2491
2524
  });
2492
- GoalSchema = z2.object({
2493
- goalId: z2.string(),
2494
- objective: z2.string(),
2495
- status: z2.enum(["active", "completed", "blocked"]),
2496
- criteria: z2.string().optional()
2525
+ GoalSchema = z4.object({
2526
+ goalId: z4.string(),
2527
+ objective: z4.string(),
2528
+ status: z4.enum(["active", "completed", "blocked"]),
2529
+ criteria: z4.string().optional()
2497
2530
  });
2498
2531
  GoalSetSchema = BaseEventSchema.extend({
2499
- type: z2.literal("goal/set"),
2500
- goalId: z2.string(),
2501
- objective: z2.string(),
2502
- status: z2.enum(["active", "completed", "blocked"]),
2503
- criteria: z2.string().optional()
2532
+ type: z4.literal("goal/set"),
2533
+ goalId: z4.string(),
2534
+ objective: z4.string(),
2535
+ status: z4.enum(["active", "completed", "blocked"]),
2536
+ criteria: z4.string().optional()
2504
2537
  });
2505
- WorkflowNodeSchema = z2.object({
2506
- id: z2.string(),
2507
- task: z2.string(),
2508
- tools: z2.array(z2.string()).optional(),
2509
- verify: z2.string().optional()
2538
+ WorkflowNodeSchema = z4.object({
2539
+ id: z4.string(),
2540
+ task: z4.string(),
2541
+ tools: z4.array(z4.string()).optional(),
2542
+ verify: z4.string().optional()
2510
2543
  });
2511
2544
  WorkflowStartSchema = BaseEventSchema.extend({
2512
- type: z2.literal("workflow/start"),
2513
- workflowId: z2.string(),
2514
- nodes: z2.array(WorkflowNodeSchema),
2515
- dependsOn: z2.record(z2.string(), z2.array(z2.string()))
2545
+ type: z4.literal("workflow/start"),
2546
+ workflowId: z4.string(),
2547
+ nodes: z4.array(WorkflowNodeSchema),
2548
+ dependsOn: z4.record(z4.string(), z4.array(z4.string()))
2516
2549
  });
2517
2550
  WorkflowEndSchema = BaseEventSchema.extend({
2518
- type: z2.literal("workflow/end"),
2519
- workflowId: z2.string(),
2520
- results: z2.array(z2.object({
2521
- nodeId: z2.string(),
2522
- status: z2.enum(["completed", "failed", "skipped"]),
2523
- result: z2.string().optional()
2551
+ type: z4.literal("workflow/end"),
2552
+ workflowId: z4.string(),
2553
+ results: z4.array(z4.object({
2554
+ nodeId: z4.string(),
2555
+ status: z4.enum(["completed", "failed", "skipped"]),
2556
+ result: z4.string().optional()
2524
2557
  }))
2525
2558
  });
2526
- TeamMemberSchema = z2.object({
2559
+ TeamMemberSchema = z4.object({
2527
2560
  /**
2528
2561
  * 成员**身份 id**(spec/agent-team.md 决策 20,对齐 dsh 的 live `Agent` 身份 + `senderId/targetId`)。
2529
2562
  *
@@ -2532,227 +2565,227 @@ var init_schema = __esm({
2532
2565
  * 故身份用单调不回收的 `mem-<n>`,名字退化为**可复用的显示标签**(仅活跃期唯一)。
2533
2566
  * Lead 的保留 id 是 `lead`(`mem-` 前缀保证不撞)。
2534
2567
  */
2535
- id: z2.string().min(1),
2536
- name: z2.string().min(1),
2568
+ id: z4.string().min(1),
2569
+ name: z4.string().min(1),
2537
2570
  /**
2538
2571
  * 成员的**职责简述**(对齐 dsh `roster.ts:258` 的 `requiredText(description, 200)`)。
2539
2572
  * 与任务一样是「标签 + 完整说明」两段式的成员侧:`name` 是短标识,`description` 说明它被派什么责。
2540
2573
  * 契约给缺省 `''` 以兼容加字段前的旧事件;必填性在工具层强制(同 daluo 的输入校验约定)。
2541
2574
  */
2542
- description: z2.string().default(""),
2575
+ description: z4.string().default(""),
2543
2576
  /**
2544
2577
  * 成员会话的**上下文来源**(**不是模型供应商**——该字段曾名 `provider`,借用上游
2545
2578
  * subagent 术语,与「模型 provider」撞义,2026-09-11 改名)。
2546
2579
  * `fresh` = 全新上下文(当前唯一已实现行为)/ `fork` = 继承 Root 已完成轮次(未实现,暂等价 fresh)。
2547
2580
  */
2548
- context: z2.enum(["fresh", "fork"]),
2581
+ context: z4.enum(["fresh", "fork"]),
2549
2582
  /**
2550
2583
  * 成员种类(配额归属):`temp` = 临时员工(占 `maxMembers`)/ `seat` = 议会席位
2551
2584
  * (占 `councilSeats` 独立配额)。两套配额互不挤占(用户定 A 方案)。
2552
2585
  */
2553
- kind: z2.enum(["temp", "seat"]),
2554
- phase: z2.enum(["provisioning", "active", "failed", "released"]),
2586
+ kind: z4.enum(["temp", "seat"]),
2587
+ phase: z4.enum(["provisioning", "active", "failed", "released"]),
2555
2588
  /**
2556
2589
  * 失败原因(仅 `phase: 'failed'` 有意义)——对齐 dsh `roster.ts:297,425`:
2557
2590
  * 快照带 `error`,`list_agents` 的 diagnostics 据此可归因(否则只有「失败了」,
2558
2591
  * 不知道是启动炸了还是 prompt 没落盘)。可选,故旧事件 parse 不受影响。
2559
2592
  */
2560
- error: z2.string().optional()
2593
+ error: z4.string().optional()
2561
2594
  });
2562
2595
  TeamMemberCreateSchema = BaseEventSchema.extend({
2563
- type: z2.literal("team/member"),
2564
- teamId: z2.string(),
2596
+ type: z4.literal("team/member"),
2597
+ teamId: z4.string(),
2565
2598
  member: TeamMemberSchema
2566
2599
  });
2567
- TeamMessageSchema = z2.object({
2568
- id: z2.string().min(1),
2569
- senderId: z2.string().min(1),
2570
- senderName: z2.string().min(1),
2571
- targetId: z2.string().min(1),
2572
- targetName: z2.string().min(1),
2573
- content: z2.string()
2600
+ TeamMessageSchema = z4.object({
2601
+ id: z4.string().min(1),
2602
+ senderId: z4.string().min(1),
2603
+ senderName: z4.string().min(1),
2604
+ targetId: z4.string().min(1),
2605
+ targetName: z4.string().min(1),
2606
+ content: z4.string()
2574
2607
  });
2575
2608
  TeamMessageQueuedSchema = BaseEventSchema.extend({
2576
- type: z2.literal("team/message/queued"),
2577
- teamId: z2.string(),
2609
+ type: z4.literal("team/message/queued"),
2610
+ teamId: z4.string(),
2578
2611
  message: TeamMessageSchema
2579
2612
  });
2580
2613
  TeamMessageDeliveredSchema = BaseEventSchema.extend({
2581
- type: z2.literal("team/message/delivered"),
2582
- teamId: z2.string(),
2583
- messageId: z2.string().min(1),
2584
- targetId: z2.string().min(1)
2614
+ type: z4.literal("team/message/delivered"),
2615
+ teamId: z4.string(),
2616
+ messageId: z4.string().min(1),
2617
+ targetId: z4.string().min(1)
2585
2618
  });
2586
- TeamTaskSchema = z2.object({
2587
- id: z2.string().min(1),
2619
+ TeamTaskSchema = z4.object({
2620
+ id: z4.string().min(1),
2588
2621
  /** 简短标题(dsh `requiredText(subject, 200)`)。 */
2589
- subject: z2.string(),
2622
+ subject: z4.string(),
2590
2623
  /**
2591
2624
  * 完整细节 / 验收标准(dsh `requiredText(description, 16384)`)。
2592
2625
  * daluo 与 dsh 的差别:**必填性在工具层强制**(daluo 的输入校验统一在工具层,如 subject);
2593
2626
  * 契约给缺省 `''` 以兼容加字段前的旧事件。
2594
2627
  */
2595
- description: z2.string().default(""),
2596
- status: z2.enum(["pending", "in_progress", "completed", "deleted"]),
2628
+ description: z4.string().default(""),
2629
+ status: z4.enum(["pending", "in_progress", "completed", "deleted"]),
2597
2630
  /** 认领者名字(未认领缺省)。 */
2598
- ownerName: z2.string().optional(),
2631
+ ownerName: z4.string().optional(),
2599
2632
  /** 依赖的任务 id:全部 completed 才可 claim(DAG 边)。 */
2600
- blockedBy: z2.array(z2.string()),
2633
+ blockedBy: z4.array(z4.string()),
2601
2634
  /**
2602
2635
  * 任务级**写作用域**(spec/agent-team.md 决策 16,对齐 dsh `writeScope`):
2603
2636
  * 该任务计划修改的文件/目录(**规范化相对路径**:无前导 `/`、无双斜杠、无 `.`/`..` 段)。
2604
2637
  * 用于并行成员改同一片文件时的**重叠告警**(按路径段前缀判定,advisory 不阻塞)。
2605
2638
  * 演进加入:缺省 `[]`(旧事件不带该字段 → parse 后视为未声明)。
2606
2639
  */
2607
- writeScopes: z2.array(z2.string()).default([]),
2640
+ writeScopes: z4.array(z4.string()).default([]),
2608
2641
  /**
2609
2642
  * 任务**义务**(spec/council.md 决策 13):本任务声称「完成后必须能通过」的核验命令
2610
2643
  * (如 `npm run check`)。完成时服务会拿**回执里的证据**逐条比对(跑过且 exitCode=0),
2611
2644
  * 比对不齐 → 拒绝完成。声明在**任务上**(而非议会条目上)——它要可核验、要跟任务同生命周期。
2612
2645
  */
2613
- obligations: z2.array(z2.string()).default([]),
2646
+ obligations: z4.array(z4.string()).default([]),
2614
2647
  /**
2615
2648
  * CAS 版本,**从 1 起**(对齐 dsh `task-board.ts:62` 的 `revision: 1` 与
2616
2649
  * `projection.ts:265` 的「must begin at revision 1」)——0 是「还不存在」的味道,
2617
2650
  * 与「已建」区分开。
2618
2651
  */
2619
- revision: z2.number().int().positive()
2652
+ revision: z4.number().int().positive()
2620
2653
  });
2621
2654
  TeamTaskUpdateSchema = BaseEventSchema.extend({
2622
- type: z2.literal("team/task"),
2623
- teamId: z2.string(),
2655
+ type: z4.literal("team/task"),
2656
+ teamId: z4.string(),
2624
2657
  task: TeamTaskSchema
2625
2658
  });
2626
- TaskEvidenceSchema = z2.object({
2659
+ TaskEvidenceSchema = z4.object({
2627
2660
  /** 跑过的核验命令(与任务 obligations 逐条比对)。 */
2628
- command: z2.string().min(1),
2629
- exitCode: z2.number().int(),
2661
+ command: z4.string().min(1),
2662
+ exitCode: z4.number().int(),
2630
2663
  /** 输出摘要(可选;大输出留成员会话,不灌进事件)。 */
2631
- output: z2.string().optional()
2664
+ output: z4.string().optional()
2632
2665
  });
2633
- TeamTaskResultSchema = z2.object({
2634
- taskId: z2.string().min(1),
2635
- status: z2.enum(["completed", "failed", "interrupted"]),
2666
+ TeamTaskResultSchema = z4.object({
2667
+ taskId: z4.string().min(1),
2668
+ status: z4.enum(["completed", "failed", "interrupted"]),
2636
2669
  /** 结论文本(交付面——给 Lead/下一环读,不是全文)。 */
2637
- summary: z2.string(),
2638
- evidence: z2.array(TaskEvidenceSchema).default([]),
2670
+ summary: z4.string(),
2671
+ evidence: z4.array(TaskEvidenceSchema).default([]),
2639
2672
  /** 度量(对齐 claudecode:工具次数 / 耗时 / token)。 */
2640
- metrics: z2.object({
2641
- toolUses: z2.number().int().nonnegative(),
2642
- durationMs: z2.number().int().nonnegative(),
2643
- tokens: z2.number().int().nonnegative().optional()
2673
+ metrics: z4.object({
2674
+ toolUses: z4.number().int().nonnegative(),
2675
+ durationMs: z4.number().int().nonnegative(),
2676
+ tokens: z4.number().int().nonnegative().optional()
2644
2677
  }).optional(),
2645
2678
  /** 失败原因(status='failed' 时有值)。 */
2646
- error: z2.string().optional(),
2679
+ error: z4.string().optional(),
2647
2680
  /** 谁报的(成员身份 id,决策 20;Lead 为 `lead`)。 */
2648
- by: z2.string().min(1)
2681
+ by: z4.string().min(1)
2649
2682
  });
2650
2683
  TeamTaskResultEventSchema = BaseEventSchema.extend({
2651
- type: z2.literal("team/task/result"),
2652
- teamId: z2.string(),
2684
+ type: z4.literal("team/task/result"),
2685
+ teamId: z4.string(),
2653
2686
  result: TeamTaskResultSchema
2654
2687
  });
2655
2688
  SessionRenamedSchema = BaseEventSchema.extend({
2656
- type: z2.literal("session/renamed"),
2657
- title: z2.string().min(1),
2689
+ type: z4.literal("session/renamed"),
2690
+ title: z4.string().min(1),
2658
2691
  /**
2659
2692
  * 这个名字**谁起的**(`G3-41`)。缺省 = `'user'`(旧日志零迁移)——这一点很要紧:
2660
2693
  * 「用户起的名字**永不被覆盖**」靠它判;把自动标题也写成不带标识的一条,日后就没法区分,
2661
2694
  * 自动生成会把用户亲手改的名字覆盖掉。
2662
2695
  */
2663
- source: z2.enum(["user", "auto"]).optional()
2696
+ source: z4.enum(["user", "auto"]).optional()
2664
2697
  });
2665
2698
  SessionModelChangedSchema = BaseEventSchema.extend({
2666
- type: z2.literal("session/model-changed"),
2667
- model: z2.string().min(1),
2699
+ type: z4.literal("session/model-changed"),
2700
+ model: z4.string().min(1),
2668
2701
  /** 提供方 id(`user-config` 的 `ProviderEntry.id`):**只存引用,不存 baseUrl/密钥**(会话日志可被分享/导入)。缺省 = 沿用当前提供方(老日志原样可读)。 */
2669
- provider: z2.string().min(1).optional()
2702
+ provider: z4.string().min(1).optional()
2670
2703
  });
2671
2704
  WorkingDirectoryChangedSchema = BaseEventSchema.extend({
2672
- type: z2.literal("working-directory/change"),
2673
- cwd: z2.string().min(1)
2705
+ type: z4.literal("working-directory/change"),
2706
+ cwd: z4.string().min(1)
2674
2707
  });
2675
2708
  SessionArchivedSchema = BaseEventSchema.extend({
2676
- type: z2.literal("session/archived"),
2677
- archived: z2.boolean()
2709
+ type: z4.literal("session/archived"),
2710
+ archived: z4.boolean()
2678
2711
  });
2679
2712
  MAX_LABELS = 32;
2680
2713
  MAX_LABEL_KEY_CHARS = 64;
2681
2714
  MAX_LABEL_VALUE_CHARS = 256;
2682
2715
  SessionLabelsSchema = BaseEventSchema.extend({
2683
- type: z2.literal("session/labels"),
2716
+ type: z4.literal("session/labels"),
2684
2717
  /** 关联标签(如 `{ record: 'ZHBD-0001' }`)。**整体替换**(last-wins);空对象 = 清空。 */
2685
- labels: z2.record(z2.string().max(MAX_LABEL_KEY_CHARS), z2.string().max(MAX_LABEL_VALUE_CHARS)).refine((l) => Object.keys(l).length <= MAX_LABELS, { message: `\u6807\u7B7E\u6700\u591A ${MAX_LABELS} \u6761` })
2718
+ labels: z4.record(z4.string().max(MAX_LABEL_KEY_CHARS), z4.string().max(MAX_LABEL_VALUE_CHARS)).refine((l) => Object.keys(l).length <= MAX_LABELS, { message: `\u6807\u7B7E\u6700\u591A ${MAX_LABELS} \u6761` })
2686
2719
  });
2687
2720
  CommandRunSchema = BaseEventSchema.extend({
2688
- type: z2.literal("command/run"),
2721
+ type: z4.literal("command/run"),
2689
2722
  /** 配对 id(`c-<uuid>`)——与 command/done 一一对应。 */
2690
- commandId: z2.string(),
2691
- name: z2.string(),
2723
+ commandId: z4.string(),
2724
+ name: z4.string(),
2692
2725
  /** recordArgs:false 的命令不落此字段(敏感命令的面:不落日志 ≠ 执行时看不到)。 */
2693
- args: z2.string().optional(),
2726
+ args: z4.string().optional(),
2694
2727
  /** 发起方(v1 只有用户输入行——模型侧发起是未来扩展位)。 */
2695
- source: z2.literal("user")
2728
+ source: z4.literal("user")
2696
2729
  });
2697
2730
  CommandDoneSchema = BaseEventSchema.extend({
2698
- type: z2.literal("command/done"),
2699
- commandId: z2.string(),
2700
- outcome: z2.object({
2701
- kind: z2.enum(["ok", "error"]),
2702
- message: z2.string().optional()
2731
+ type: z4.literal("command/done"),
2732
+ commandId: z4.string(),
2733
+ outcome: z4.object({
2734
+ kind: z4.enum(["ok", "error"]),
2735
+ message: z4.string().optional()
2703
2736
  })
2704
2737
  });
2705
2738
  InboxQueuedSchema = BaseEventSchema.extend({
2706
- type: z2.literal("inbox/queued"),
2707
- id: z2.string(),
2708
- content: z2.string(),
2739
+ type: z4.literal("inbox/queued"),
2740
+ id: z4.string(),
2741
+ content: z4.string(),
2709
2742
  /** `steering` = 下一轮 request 就带上(mid-turn steer);`queued` = 这一轮跑完当下一回合的输入。 */
2710
- placement: z2.enum(["queued", "steering"])
2743
+ placement: z4.enum(["queued", "steering"])
2711
2744
  });
2712
2745
  InboxEditedSchema = BaseEventSchema.extend({
2713
- type: z2.literal("inbox/edited"),
2714
- id: z2.string(),
2715
- content: z2.string()
2746
+ type: z4.literal("inbox/edited"),
2747
+ id: z4.string(),
2748
+ content: z4.string()
2716
2749
  });
2717
2750
  InboxRemovedSchema = BaseEventSchema.extend({
2718
- type: z2.literal("inbox/removed"),
2719
- id: z2.string()
2751
+ type: z4.literal("inbox/removed"),
2752
+ id: z4.string()
2720
2753
  });
2721
2754
  InboxRequeuedSchema = BaseEventSchema.extend({
2722
- type: z2.literal("inbox/requeued"),
2723
- id: z2.string(),
2724
- placement: z2.enum(["queued", "steering"])
2755
+ type: z4.literal("inbox/requeued"),
2756
+ id: z4.string(),
2757
+ placement: z4.enum(["queued", "steering"])
2725
2758
  });
2726
- AskOriginSchema = z2.object({
2727
- kind: z2.enum(["subagent", "workflow-node", "teammate"]),
2759
+ AskOriginSchema = z4.object({
2760
+ kind: z4.enum(["subagent", "workflow-node", "teammate"]),
2728
2761
  /** 子运行的身份:subagentId / `${workflowId}/${nodeId}` / 成员名。 */
2729
- agentId: z2.string(),
2762
+ agentId: z4.string(),
2730
2763
  /** 角色名(R9);角色没声明就不带。 */
2731
- agentType: z2.string().optional(),
2764
+ agentType: z4.string().optional(),
2732
2765
  /** 派它干的那句话(子代理 task / workflow node task)。 */
2733
- description: z2.string().optional(),
2766
+ description: z4.string().optional(),
2734
2767
  /** 子运行自己的 sessionId(通常等于 `agentId`;仍显式写,让消费方读它而不必反推)。 */
2735
- childSessionId: z2.string(),
2736
- parentSessionId: z2.string(),
2768
+ childSessionId: z4.string(),
2769
+ parentSessionId: z4.string(),
2737
2770
  /** **哪一次调用**派的(dispatch 注入的 `input.toolCallId`);拿不到就不带。 */
2738
- parentToolCallId: z2.string().optional()
2771
+ parentToolCallId: z4.string().optional()
2739
2772
  });
2740
2773
  AskRequestedSchema = BaseEventSchema.extend({
2741
- type: z2.literal("ask/requested"),
2742
- id: z2.string(),
2743
- kind: z2.enum(["permission", "question"]),
2744
- question: z2.string(),
2774
+ type: z4.literal("ask/requested"),
2775
+ id: z4.string(),
2776
+ kind: z4.enum(["permission", "question"]),
2777
+ question: z4.string(),
2745
2778
  /** 结构化提问的候选(kind=question 时有意义)。 */
2746
- options: z2.array(z2.object({ label: z2.string(), description: z2.string().optional() })).optional(),
2779
+ options: z4.array(z4.object({ label: z4.string(), description: z4.string().optional() })).optional(),
2747
2780
  /**
2748
2781
  * 权限确认的选项(kind=permission 时有意义;`spec/permission-response.md` 决策 1)。
2749
2782
  * **与上面的 `options` 是两个字段**(不是同一个字段的两种形状):旧 `options` 的语义与判据一字不动,
2750
2783
  * 而两档的选项形状确实不同(提问是候选文案,确认是**带效果的按钮**)——
2751
2784
  * 挤进一个 union 会让 permission 的选项以 question 的形状 parse 成功、静默丢掉 `effect`。
2752
2785
  */
2753
- permissionOptions: z2.array(PermissionOptionSchema).optional(),
2786
+ permissionOptions: z4.array(PermissionOptionSchema).optional(),
2754
2787
  /** 这次确认是否允许「改后批准」(应答带改写后的输入,且必须重过 policy)。 */
2755
- allowModify: z2.boolean().optional(),
2788
+ allowModify: z4.boolean().optional(),
2756
2789
  /**
2757
2790
  * 被确认的**工具输入**(kind=permission 时有意义;`spec/permission-response.md`)。
2758
2791
  *
@@ -2760,14 +2793,14 @@ var init_schema = __esm({
2760
2793
  * **早就把同一份 input 落在同一个日志文件里**了。而没有它,呈现方**没法预填「要改什么」**,
2761
2794
  * 「改后批准」在 UI 上就只剩一个让人手写 JSON 的输入框。
2762
2795
  */
2763
- input: z2.unknown().optional(),
2764
- multiSelect: z2.boolean().optional(),
2796
+ input: z4.unknown().optional(),
2797
+ multiSelect: z4.boolean().optional(),
2765
2798
  /**
2766
2799
  * 这次确认的风险档(kind=permission 时有意义;`spec/permission-response.md` 演进 S-03)——
2767
2800
  * **请求方声明**(闭集逐字对齐参考 `zcode-protocol/index.ts:930`)。呈现方按它分层、
2768
2801
  * 审计按它检索;旧事件没有它 = 「请求方没声明」,按无档呈现(**不猜**)。
2769
2802
  */
2770
- riskLevel: z2.enum(["low", "medium", "high", "critical"]).optional(),
2803
+ riskLevel: z4.enum(["low", "medium", "high", "critical"]).optional(),
2771
2804
  /**
2772
2805
  * 这次确认的**来源**(`spec/permission-provenance.md`):子代理 / workflow node / 团队成员发起的
2773
2806
  * 请求带它。旧事件没有它 = 主代理自己的询问(**不猜**——「没声明来源」与「来源非法」是两种失败,
@@ -2775,64 +2808,64 @@ var init_schema = __esm({
2775
2808
  */
2776
2809
  origin: AskOriginSchema.optional(),
2777
2810
  /** 触发它的工具名(呈现时用来标「批准什么」)。 */
2778
- toolName: z2.string().optional(),
2811
+ toolName: z4.string().optional(),
2779
2812
  /** 等待截止(ISO);超时即按拒绝收尾(fail-safe 不破)。 */
2780
- expiresAt: z2.string().optional()
2813
+ expiresAt: z4.string().optional()
2781
2814
  });
2782
2815
  AskAnsweredSchema = BaseEventSchema.extend({
2783
- type: z2.literal("ask/answered"),
2784
- id: z2.string(),
2816
+ type: z4.literal("ask/answered"),
2817
+ id: z4.string(),
2785
2818
  /** kind=permission:是否放行。 */
2786
- allow: z2.boolean().optional(),
2819
+ allow: z4.boolean().optional(),
2787
2820
  /**
2788
2821
  * 回了**哪个按钮**(`ask/requested.permissionOptions` 里的 `optionId`;`spec/permission-response.md`)。
2789
2822
  * 刻意用 `z.string()` 而不是同一份 enum:**认不出的 id 要在解析那一层拒**,
2790
2823
  * 让 schema 拒会把整条已落盘事件判成违规(`asks.failures`),把「客户端答错了」记成「日志坏了」。
2791
2824
  */
2792
- optionId: z2.string().optional(),
2825
+ optionId: z4.string().optional(),
2793
2826
  /**
2794
2827
  * 改后批准:**改写后的输入**——审计要的就是它(「这次批准到底批了什么」)。
2795
2828
  * 冲突命令的批准记录里能读到真跑的那条命令,靠的就是这个字段。
2796
2829
  */
2797
- modifiedInput: z2.unknown().optional(),
2830
+ modifiedInput: z4.unknown().optional(),
2798
2831
  /** kind=question:自由文本答案 + 选中的 label。 */
2799
- answer: z2.string().optional(),
2800
- selected: z2.array(z2.string()).optional(),
2832
+ answer: z4.string().optional(),
2833
+ selected: z4.array(z4.string()).optional(),
2801
2834
  /** 为什么结束:用户答 / `timeout`(有人等、等超了)/ `abandoned`(等的人已经没了,见 `session/stale-asks.ts`)/ 无通道。 */
2802
- reason: z2.enum(["user", "timeout", "abandoned"]).optional()
2835
+ reason: z4.enum(["user", "timeout", "abandoned"]).optional()
2803
2836
  });
2804
2837
  GoalClearedSchema = BaseEventSchema.extend({
2805
- type: z2.literal("goal/cleared"),
2838
+ type: z4.literal("goal/cleared"),
2806
2839
  /** 被清掉的那个目标 id(防「清错了目标」——fold 只在与当前目标一致时生效)。 */
2807
- goalId: z2.string()
2840
+ goalId: z4.string()
2808
2841
  });
2809
2842
  FeedbackRecordedSchema = BaseEventSchema.extend({
2810
- type: z2.literal("feedback/recorded"),
2811
- id: z2.string(),
2843
+ type: z4.literal("feedback/recorded"),
2844
+ id: z4.string(),
2812
2845
  /** message = 针对某一条消息(要 messageSeq + rating);session = 针对整会话(要 note 或 category)。 */
2813
- kind: z2.enum(["message", "session"]),
2814
- rating: z2.enum(["positive", "negative"]).optional(),
2846
+ kind: z4.enum(["message", "session"]),
2847
+ rating: z4.enum(["positive", "negative"]).optional(),
2815
2848
  /** 指向 `message/user|assistant` 的 seq(kind=message 时必填——值校验在 fold/助手层)。 */
2816
- messageSeq: z2.number().int().optional(),
2817
- category: z2.string().optional(),
2818
- note: z2.string().optional()
2849
+ messageSeq: z4.number().int().optional(),
2850
+ category: z4.string().optional(),
2851
+ note: z4.string().optional()
2819
2852
  });
2820
2853
  FeedbackRetractedSchema = BaseEventSchema.extend({
2821
- type: z2.literal("feedback/retracted"),
2822
- id: z2.string()
2854
+ type: z4.literal("feedback/retracted"),
2855
+ id: z4.string()
2823
2856
  });
2824
2857
  SessionBranchSummarySchema = BaseEventSchema.extend({
2825
- type: z2.literal("session/branch-summary"),
2858
+ type: z4.literal("session/branch-summary"),
2826
2859
  /** 摘要正文。空是写入方 bug —— schema 层 fail loud(同 `session/renamed` 的 title 非空)。 */
2827
- summary: z2.string().min(1),
2860
+ summary: z4.string().min(1),
2828
2861
  /** 被放弃路径的出处:源会话 id / 源日志文件名 / **从哪个 seq 之后开始**(= fork 的切割点)。 */
2829
- abandoned: z2.object({
2830
- sessionId: z2.string(),
2831
- file: z2.string(),
2832
- fromSeq: z2.number().int().positive()
2862
+ abandoned: z4.object({
2863
+ sessionId: z4.string(),
2864
+ file: z4.string(),
2865
+ fromSeq: z4.number().int().positive()
2833
2866
  })
2834
2867
  });
2835
- SessionEvent = z2.discriminatedUnion("type", [
2868
+ SessionEvent = z4.discriminatedUnion("type", [
2836
2869
  SessionCreatedSchema,
2837
2870
  SessionImportedSchema,
2838
2871
  /** 分支摘要(演进,spec/session-tree.md 决策 2):fork 时带过来的「被放弃路径」摘要。 */
@@ -2855,6 +2888,7 @@ var init_schema = __esm({
2855
2888
  PolicyProfileSchema,
2856
2889
  PromptSystemSchema,
2857
2890
  PromptCacheBreakSchema,
2891
+ ContextReportSchema,
2858
2892
  MemoryExtractSchema,
2859
2893
  CompactionReclaimSchema,
2860
2894
  SubagentStartSchema,
@@ -4143,7 +4177,7 @@ var init_scrub = __esm({
4143
4177
  // packages/core/src/memory/memory.ts
4144
4178
  import { mkdir as mkdir3, open as open3, stat as stat3, unlink as unlink3 } from "node:fs/promises";
4145
4179
  import { dirname as dirname3 } from "node:path";
4146
- import { z as z3 } from "zod";
4180
+ import { z as z5 } from "zod";
4147
4181
  function describeOrigin(origin) {
4148
4182
  if (origin === void 0) return "\u65E0\u6765\u6E90";
4149
4183
  if (origin.kind === "user") return "\u7528\u6237\u5F53\u9762\u8981\u6C42";
@@ -4311,41 +4345,41 @@ var init_memory = __esm({
4311
4345
  DEFAULT_MEMORY_SOURCE = "manual";
4312
4346
  USER_ORIGIN = { kind: "user" };
4313
4347
  EXTERNAL_ORIGIN = { kind: "external" };
4314
- MemoryOriginSchema = z3.discriminatedUnion("kind", [
4315
- z3.object({ kind: z3.literal("session"), sessionId: z3.string().min(1), seq: z3.number().int().positive() }),
4316
- z3.object({ kind: z3.literal("user") }),
4348
+ MemoryOriginSchema = z5.discriminatedUnion("kind", [
4349
+ z5.object({ kind: z5.literal("session"), sessionId: z5.string().min(1), seq: z5.number().int().positive() }),
4350
+ z5.object({ kind: z5.literal("user") }),
4317
4351
  // 外部客户端转达(无会话上下文,如 MCP 入口):**不是**「用户当面要求」,单独一种来源(自审修正)
4318
- z3.object({ kind: z3.literal("external") })
4352
+ z5.object({ kind: z5.literal("external") })
4319
4353
  ]);
4320
4354
  \u673A\u5668\u6E20\u9053 = ["auto", "dream", "consolidation"];
4321
- MemoryWriteSchema = z3.object({
4322
- seq: z3.number().int().positive(),
4323
- ts: z3.string(),
4324
- type: z3.literal("memory/write"),
4325
- key: z3.string().min(1, "memory/write key \u4E0D\u80FD\u4E3A\u7A7A"),
4326
- content: z3.string().min(1, "memory/write content \u4E0D\u80FD\u4E3A\u7A7A"),
4327
- memoryType: z3.enum(MEMORY_TYPES).optional(),
4328
- confidence: z3.number().min(0).max(1).optional(),
4329
- source: z3.enum(MEMORY_SOURCES).optional(),
4330
- validFrom: z3.number().optional(),
4331
- validTo: z3.number().optional(),
4332
- supersededBy: z3.string().optional(),
4333
- invalidatedAt: z3.number().optional(),
4334
- invalidatedReason: z3.enum(["resolved", "forgotten"]).optional(),
4355
+ MemoryWriteSchema = z5.object({
4356
+ seq: z5.number().int().positive(),
4357
+ ts: z5.string(),
4358
+ type: z5.literal("memory/write"),
4359
+ key: z5.string().min(1, "memory/write key \u4E0D\u80FD\u4E3A\u7A7A"),
4360
+ content: z5.string().min(1, "memory/write content \u4E0D\u80FD\u4E3A\u7A7A"),
4361
+ memoryType: z5.enum(MEMORY_TYPES).optional(),
4362
+ confidence: z5.number().min(0).max(1).optional(),
4363
+ source: z5.enum(MEMORY_SOURCES).optional(),
4364
+ validFrom: z5.number().optional(),
4365
+ validTo: z5.number().optional(),
4366
+ supersededBy: z5.string().optional(),
4367
+ invalidatedAt: z5.number().optional(),
4368
+ invalidatedReason: z5.enum(["resolved", "forgotten"]).optional(),
4335
4369
  /** 来源(G4-19):可选 ⇒ 既有事件零迁移;**写入 API 必填**(闸在 `remember` 里)。 */
4336
4370
  origin: MemoryOriginSchema.optional()
4337
4371
  });
4338
- MemoryInvalidateSchema = z3.object({
4339
- seq: z3.number().int().positive(),
4340
- ts: z3.string(),
4341
- type: z3.literal("memory/invalidate"),
4342
- key: z3.string().min(1, "memory/invalidate key \u4E0D\u80FD\u4E3A\u7A7A"),
4343
- reason: z3.enum(["resolved", "forgotten"]),
4372
+ MemoryInvalidateSchema = z5.object({
4373
+ seq: z5.number().int().positive(),
4374
+ ts: z5.string(),
4375
+ type: z5.literal("memory/invalidate"),
4376
+ key: z5.string().min(1, "memory/invalidate key \u4E0D\u80FD\u4E3A\u7A7A"),
4377
+ reason: z5.enum(["resolved", "forgotten"]),
4344
4378
  /** 取代链(可选):这条记忆被哪个 key 取代——`isCurrentFact` 据此把旧叶子判非 current。 */
4345
- supersededBy: z3.string().min(1).optional(),
4346
- invalidatedAt: z3.number()
4379
+ supersededBy: z5.string().min(1).optional(),
4380
+ invalidatedAt: z5.number()
4347
4381
  });
4348
- MemoryEvent = z3.discriminatedUnion("type", [MemoryWriteSchema, MemoryInvalidateSchema]);
4382
+ MemoryEvent = z5.discriminatedUnion("type", [MemoryWriteSchema, MemoryInvalidateSchema]);
4349
4383
  MAX_MEMORY_CONTENT_CHARS = 2e3;
4350
4384
  \u9501\u540E\u7F00 = ".lock";
4351
4385
  \u9648\u65E7\u9501Ms = 1e4;
@@ -5206,6 +5240,13 @@ var init_settings_schema = __esm({
5206
5240
  \u679A\u4E3E: ["on", "off"],
5207
5241
  \u8BF4\u660E: "\u81EA\u52A8\u538B\u7F29\u7684\u6458\u8981\u6765\u6E90\uFF08\u7F3A\u7701 `off` = \u89C4\u5219\u6458\u8981\uFF1B`on` = \u591A\u4E00\u6B21 LLM \u8C03\u7528\u6362\u53EF\u8BFB\u7684\u6458\u8981\uFF09"
5208
5242
  },
5243
+ // ---- LLM(spec/llm-transport.md 演进「response_format 开关」;**不进项目级白名单**)----
5244
+ {
5245
+ \u952E: "llm.responseFormat",
5246
+ \u7C7B\u578B: "enum",
5247
+ \u679A\u4E3E: ["off", "structured", "always"],
5248
+ \u8BF4\u660E: "\u7ED3\u6784\u5316\u8F93\u51FA\u5F00\u5173\uFF08\u7F3A\u7701 off = \u4E0D\u53D1 response_format\uFF09\uFF1Bstructured = \u53EA\u7ED9\u300C\u672C\u6765\u5C31\u8981 JSON\u300D\u7684\u65C1\u8DEF\u8C03\u7528\u53D1\uFF0Calways = \u6240\u6709\u8BF7\u6C42\u90FD\u53D1\uFF08\u52A9\u624B\u6B63\u6587\u4F1A\u53D8\u6210 JSON \u4E32\uFF09"
5249
+ },
5209
5250
  // ---- 授权 / 记忆 ----
5210
5251
  {
5211
5252
  \u952E: "permission.readRoots",
@@ -5354,7 +5395,7 @@ function \u9879\u76EE\u7EA7\u5FFD\u7565\u63D0\u793A(\u88AB\u5FFD\u75652) {
5354
5395
  const \u952E = \u88AB\u5FFD\u75652.join(" / ");
5355
5396
  return `\u672C\u4ED3 .daluo/settings.json \u91CC\u6709 ${\u88AB\u5FFD\u75652.length} \u4E2A\u952E\u4E0D\u8BA9\u9879\u76EE\u7EA7\u751F\u6548\uFF0C\u5DF2\u5FFD\u7565\uFF1A${\u952E}\uFF08\u53EA\u6709\u538B\u7F29\u9884\u7B97\u4E0E\u5916\u89C2\u7C7B\u8BBE\u7F6E\u80FD\u6309\u9879\u76EE\u8986\u76D6\u2014\u2014\u9879\u76EE\u7EA7\u6587\u4EF6\u968F\u4ED3\u5E93\u5206\u53D1\uFF0C\u653E\u5F00\u6743\u9650/\u7AEF\u70B9\u7C7B\u7B49\u4E8E\u8BA9\u4ED3\u5E93\u6539\u4F60\u7684\u5B89\u5168\u9762\uFF1B\u5168\u8868\u89C1 spec/settings.md\uFF09`;
5356
5397
  }
5357
- var SETTINGS_VERSION, SETTING_ACTIVE_WORKSPACE_ROOT, SETTING_MODEL_DEFAULT, SETTING_MODELS_KNOWN, SETTING_PRICING_MODELS, SETTING_PRICING_CURRENCY, SETTING_PICKER_ROOTS, SETTING_PERMISSION_READ_ROOTS, SETTING_PERMISSION_RULES, SETTING_PERMISSION_READ_ONLY_PROGRAMS, SETTING_UI_THEME, SETTING_UI_FONT_SIZE, SETTING_UI_SEND_WHILE_BUSY, SETTING_UI_PROCESS_DISPLAY, SETTING_UI_SESSION_ORDER, SETTING_UI_GOAL_MODE, SETTING_UI_VIM, SETTING_UI_SCALE, UI_SCALE_STEPS, SETTING_COMPACTION_KEEP_MESSAGES, SETTING_COMPACTION_KEEP_TOKENS, SETTING_COMPACTION_RESERVE_OUTPUT_TOKENS, SETTING_COMPACTION_BUFFER_TOKENS, SETTING_COMPACTION_LLM_SUMMARY, COMPACTION_KEEP_MESSAGES_MIN, COMPACTION_TOKENS_MIN, UI_FONT_SIZE_MIN, UI_FONT_SIZE_MAX, UI_FONT_SIZE_DEFAULT;
5398
+ var SETTINGS_VERSION, SETTING_ACTIVE_WORKSPACE_ROOT, SETTING_MODEL_DEFAULT, SETTING_MODELS_KNOWN, SETTING_PRICING_MODELS, SETTING_PRICING_CURRENCY, SETTING_PICKER_ROOTS, SETTING_PERMISSION_READ_ROOTS, SETTING_PERMISSION_RULES, SETTING_PERMISSION_READ_ONLY_PROGRAMS, SETTING_UI_THEME, SETTING_UI_FONT_SIZE, SETTING_UI_SEND_WHILE_BUSY, SETTING_UI_PROCESS_DISPLAY, SETTING_UI_SESSION_ORDER, SETTING_UI_GOAL_MODE, SETTING_UI_VIM, SETTING_UI_SCALE, UI_SCALE_STEPS, SETTING_COMPACTION_KEEP_MESSAGES, SETTING_COMPACTION_KEEP_TOKENS, SETTING_COMPACTION_RESERVE_OUTPUT_TOKENS, SETTING_COMPACTION_BUFFER_TOKENS, SETTING_COMPACTION_LLM_SUMMARY, SETTING_LLM_RESPONSE_FORMAT, COMPACTION_KEEP_MESSAGES_MIN, COMPACTION_TOKENS_MIN, UI_FONT_SIZE_MIN, UI_FONT_SIZE_MAX, UI_FONT_SIZE_DEFAULT;
5358
5399
  var init_settings = __esm({
5359
5400
  "packages/core/src/settings/settings.ts"() {
5360
5401
  "use strict";
@@ -5385,6 +5426,7 @@ var init_settings = __esm({
5385
5426
  SETTING_COMPACTION_RESERVE_OUTPUT_TOKENS = "compaction.reserveOutputTokens";
5386
5427
  SETTING_COMPACTION_BUFFER_TOKENS = "compaction.bufferTokens";
5387
5428
  SETTING_COMPACTION_LLM_SUMMARY = "compaction.llmSummary";
5429
+ SETTING_LLM_RESPONSE_FORMAT = "llm.responseFormat";
5388
5430
  COMPACTION_KEEP_MESSAGES_MIN = 3;
5389
5431
  COMPACTION_TOKENS_MIN = 1e3;
5390
5432
  UI_FONT_SIZE_MIN = 12;
@@ -7789,8 +7831,11 @@ function bufferFromEnv(env) {
7789
7831
  }
7790
7832
  return n;
7791
7833
  }
7834
+ function contextWindowOf(budget) {
7835
+ return budget.contextWindowTokens ?? DEFAULT_CONTEXT_WINDOW_TOKENS;
7836
+ }
7792
7837
  function contextThresholdTokens(budget) {
7793
- const window = budget.contextWindowTokens ?? DEFAULT_CONTEXT_WINDOW_TOKENS;
7838
+ const window = contextWindowOf(budget);
7794
7839
  const reserve = budget.reserveOutputTokens ?? 2e4;
7795
7840
  const buffer = budget.bufferTokens ?? 13e3;
7796
7841
  const effective = Math.max(window - reserve, 0);
@@ -8669,6 +8714,8 @@ function foldEvent(state, event) {
8669
8714
  return state;
8670
8715
  case "compaction/reclaim":
8671
8716
  return state;
8717
+ case "context/report":
8718
+ return state;
8672
8719
  case "prompt/cache-break":
8673
8720
  return state;
8674
8721
  case "subagent/start":
@@ -11136,6 +11183,8 @@ function isContextOverflowError(err) {
11136
11183
  function classifyLlmError(err) {
11137
11184
  if (err instanceof LlmTimeoutError) return { category: "timeout", retryable: false, capacity: false };
11138
11185
  if (err instanceof LlmStreamError) return { category: "stream-error", retryable: false, capacity: false };
11186
+ if (err instanceof LlmToolArgsError) return { category: "model-output", retryable: true, capacity: false };
11187
+ if (err instanceof LlmResponseFormatError) return { category: "fatal", retryable: false, capacity: false };
11139
11188
  if (isAbortError(err)) return { category: "aborted", retryable: false, capacity: false };
11140
11189
  if (err instanceof LlmHttpError) {
11141
11190
  if (isContextOverflowError(err)) {
@@ -11153,12 +11202,12 @@ function isRetryableError(err) {
11153
11202
  return classifyLlmError(err).retryable;
11154
11203
  }
11155
11204
  function isLlmError(err) {
11156
- return err instanceof LlmHttpError || err instanceof LlmTimeoutError || err instanceof LlmStreamError || isAbortError(err);
11205
+ return err instanceof LlmHttpError || err instanceof LlmTimeoutError || err instanceof LlmStreamError || err instanceof LlmToolArgsError || err instanceof LlmResponseFormatError || isAbortError(err);
11157
11206
  }
11158
11207
  function isCapacityError(err) {
11159
11208
  return classifyLlmError(err).capacity;
11160
11209
  }
11161
- var RETRYABLE_STATUS, OVERLOADED_BODY, LlmStreamError, LlmHttpError, LlmTimeoutError, CONTEXT_OVERFLOW_PATTERNS, OVERFLOW_STATUS, EMPTY_BODY_RE;
11210
+ var RETRYABLE_STATUS, OVERLOADED_BODY, LlmStreamError, LlmToolArgsError, LlmResponseFormatError, LlmHttpError, LlmTimeoutError, CONTEXT_OVERFLOW_PATTERNS, OVERFLOW_STATUS, EMPTY_BODY_RE;
11162
11211
  var init_error_classify = __esm({
11163
11212
  "packages/core/src/llm/error-classify.ts"() {
11164
11213
  "use strict";
@@ -11173,6 +11222,23 @@ var init_error_classify = __esm({
11173
11222
  this.code = code;
11174
11223
  }
11175
11224
  };
11225
+ LlmToolArgsError = class extends Error {
11226
+ /** 出问题的工具名(可读提示要用;**不带参数原文**——它可能几百字,别让它进日志/终端)。 */
11227
+ toolName;
11228
+ constructor(message, toolName) {
11229
+ super(message);
11230
+ this.name = "LlmToolArgsError";
11231
+ this.toolName = toolName;
11232
+ }
11233
+ };
11234
+ LlmResponseFormatError = class extends Error {
11235
+ constructor() {
11236
+ super(
11237
+ '\u5F00\u4E86\u7ED3\u6784\u5316\u8F93\u51FA\uFF08response_format\uFF09\uFF0C\u4F46\u8FD9\u6B21\u8BF7\u6C42\u7684 prompt \u91CC\u6CA1\u6709\u51FA\u73B0 "json" \u5B57\u6837\u2014\u2014\u4E0A\u6E38\u4F1A\u76F4\u63A5 400\u3002\u8BF7\u5728 prompt \u91CC\u8BF4\u660E\u5E0C\u671B\u7684 JSON \u5F62\u72B6\uFF0C\u6216\u628A DALUO_LLM_RESPONSE_FORMAT / \u8BBE\u7F6E llm.responseFormat \u8BBE\u56DE off\u3002'
11238
+ );
11239
+ this.name = "LlmResponseFormatError";
11240
+ }
11241
+ };
11176
11242
  LlmHttpError = class extends Error {
11177
11243
  status;
11178
11244
  retryAfterMs;
@@ -11757,6 +11823,7 @@ function createRequestStep(config = {}) {
11757
11823
  }
11758
11824
  chatMessages = await buildMessages();
11759
11825
  const budget = ctx.compactBudget;
11826
+ let \u672C\u8F6E\u538B\u7F29\u6570 = 0;
11760
11827
  if (budget && llm) {
11761
11828
  const threshold = contextThresholdTokens(budget);
11762
11829
  const estTokens = (chars) => ctx.tokenEstimator ? ctx.tokenEstimator.estimateChars(chars) : estimateTokens(chars);
@@ -11787,6 +11854,20 @@ function createRequestStep(config = {}) {
11787
11854
  estimateChars: estTokens
11788
11855
  });
11789
11856
  let account = \u8D26();
11857
+ if (account.tokens > threshold * CONTEXT_WARN_RATIO) {
11858
+ const \u5386\u53F2 = log.state.messages.filter((m) => m.role === "user" && m.source === "context").map((m) => m.content);
11859
+ if (shouldInjectContext(\u5386\u53F2, CONTEXT_WARN_BLOCK)) {
11860
+ await log.append({
11861
+ sessionId: log.state.sessionId ?? "",
11862
+ seq: log.nextSeq(),
11863
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
11864
+ type: "context/injected",
11865
+ content: CONTEXT_WARN_BLOCK
11866
+ });
11867
+ chatMessages = await buildMessages();
11868
+ account = \u8D26();
11869
+ }
11870
+ }
11790
11871
  while (compacted < MAX_COMPACTIONS && account.tokens > threshold) {
11791
11872
  const verdict = await compactOnce(log, {
11792
11873
  keepMessages: keepForBudget(budget.keepMessages),
@@ -11801,6 +11882,7 @@ function createRequestStep(config = {}) {
11801
11882
  account = \u8D26();
11802
11883
  }
11803
11884
  if (compacted > 0) resetMemoryAfterCompaction(ctx.memorySession);
11885
+ \u672C\u8F6E\u538B\u7F29\u6570 = compacted;
11804
11886
  }
11805
11887
  const fingerprint = measureSync(
11806
11888
  "fingerprintPrompt",
@@ -11878,6 +11960,20 @@ function createRequestStep(config = {}) {
11878
11960
  });
11879
11961
  }
11880
11962
  recordCacheRead(sessionId, response.usage?.cachedTokens);
11963
+ if (response.usage !== void 0) {
11964
+ const \u9884\u7B97 = ctx.compactBudget;
11965
+ await log.append({
11966
+ sessionId,
11967
+ seq: log.nextSeq(),
11968
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
11969
+ type: "context/report",
11970
+ // 纯遥测(不进 fold)⇒ 旧版跳过即可,不必抬日志格式版本头
11971
+ ignorable: true,
11972
+ tokens: response.usage.promptTokens,
11973
+ ...\u9884\u7B97 === void 0 ? {} : { window: contextWindowOf(\u9884\u7B97), threshold: contextThresholdTokens(\u9884\u7B97) },
11974
+ ...\u672C\u8F6E\u538B\u7F29\u6570 > 0 ? { compactions: \u672C\u8F6E\u538B\u7F29\u6570 } : {}
11975
+ });
11976
+ }
11881
11977
  if (ctx.tokenEstimator && response.usage?.promptTokens) {
11882
11978
  const chars = request.messages.reduce((s, m) => s + chatMessageChars(m), 0);
11883
11979
  ctx.tokenEstimator.observe(chars, response.usage.promptTokens);
@@ -11905,7 +12001,8 @@ function createRequestStep(config = {}) {
11905
12001
  try {
11906
12002
  input = JSON.parse(tc.arguments);
11907
12003
  } catch {
11908
- throw new Error(`request step: tool_calls arguments \u975E JSON\uFF08name=${tc.name}\uFF09\uFF1A${tc.arguments}`);
12004
+ const \u539F\u6587 = tc.arguments.length > 200 ? `${tc.arguments.slice(0, 200)}\u2026\uFF08\u5171 ${tc.arguments.length} \u5B57\u7B26\uFF09` : tc.arguments;
12005
+ throw new LlmToolArgsError(`request step: tool_calls arguments \u975E JSON\uFF08name=${tc.name}\uFF09\uFF1A${\u539F\u6587}`, tc.name);
11909
12006
  }
11910
12007
  return { type: "tool-call", toolCallId: tc.id, toolName: tc.name, input };
11911
12008
  });
@@ -11957,7 +12054,7 @@ function commitmentReminders(events, threshold = DEFAULT_BROKEN_TURNS) {
11957
12054
  const \u5DF2\u6CE8\u5165 = events.filter((e) => e.type === "context/injected").map((e) => e.content);
11958
12055
  return ops.filter((op) => !\u5DF2\u6CE8\u5165.some((content) => content.includes(describeBroken(op))));
11959
12056
  }
11960
- var AGENT_SYSTEM_PROMPT2;
12057
+ var CONTEXT_WARN_RATIO, CONTEXT_WARN_BLOCK, AGENT_SYSTEM_PROMPT2;
11961
12058
  var init_request_step = __esm({
11962
12059
  "packages/core/src/agent/request-step.ts"() {
11963
12060
  "use strict";
@@ -11983,6 +12080,8 @@ var init_request_step = __esm({
11983
12080
  init_working_directory();
11984
12081
  init_system_prompt();
11985
12082
  init_system_prompt();
12083
+ CONTEXT_WARN_RATIO = 0.9;
12084
+ CONTEXT_WARN_BLOCK = "[\u4E0A\u4E0B\u6587\u63A5\u8FD1\u4E0A\u9650] \u5386\u53F2\u5F88\u5FEB\u4F1A\u88AB\u538B\u7F29\uFF1A\u65E7\u6D88\u606F\u5C06\u88AB\u6458\u8981\u66FF\u6362\uFF0C\u7EC6\u8282\u4F1A\u4E22\u5931\u3002\u8BF7\u7ACB\u523B\u628A\u8FD8\u8981\u7528\u7684\u4E1C\u897F\u843D\u5230\u5916\u90E8\u2014\u2014\u628A\u7ED3\u8BBA\u3001\u5173\u952E\u6587\u4EF6\u8DEF\u5F84\u3001\u672A\u5B8C\u6210\u7684\u5F85\u529E\u5199\u8FDB\u56DE\u590D\u6216 todo \u5DE5\u5177\uFF0C\u4E0D\u8981\u8BA9\u91CD\u8981\u72B6\u6001\u53EA\u5B58\u5728\u4E8E\u5BF9\u8BDD\u5386\u53F2\u91CC\u3002";
11986
12085
  AGENT_SYSTEM_PROMPT2 = assembleSystemPrompt({});
11987
12086
  }
11988
12087
  });
@@ -12588,21 +12687,21 @@ var init_session_files = __esm({
12588
12687
  });
12589
12688
 
12590
12689
  // packages/core/src/agent/tool-schema.ts
12591
- import { z as z4 } from "zod";
12690
+ import { z as z6 } from "zod";
12592
12691
  function propertyToZod(prop) {
12593
12692
  switch (prop.type) {
12594
12693
  case "string":
12595
- return z4.string();
12694
+ return z6.string();
12596
12695
  case "number": {
12597
- let schema = z4.number();
12696
+ let schema = z6.number();
12598
12697
  if (typeof prop.minimum === "number") schema = schema.min(prop.minimum);
12599
12698
  if (typeof prop.maximum === "number") schema = schema.max(prop.maximum);
12600
12699
  return schema;
12601
12700
  }
12602
12701
  case "boolean":
12603
- return z4.boolean();
12702
+ return z6.boolean();
12604
12703
  default:
12605
- return z4.unknown();
12704
+ return z6.unknown();
12606
12705
  }
12607
12706
  }
12608
12707
  function parametersToZod(parameters) {
@@ -12612,7 +12711,7 @@ function parametersToZod(parameters) {
12612
12711
  for (const [key, prop] of Object.entries(properties)) {
12613
12712
  shape[key] = required.includes(key) ? propertyToZod(prop) : propertyToZod(prop).optional();
12614
12713
  }
12615
- return z4.object(shape).passthrough();
12714
+ return z6.object(shape).passthrough();
12616
12715
  }
12617
12716
  var init_tool_schema = __esm({
12618
12717
  "packages/core/src/agent/tool-schema.ts"() {
@@ -14785,6 +14884,47 @@ var init_retry = __esm({
14785
14884
  }
14786
14885
  });
14787
14886
 
14887
+ // packages/core/src/llm/generation.ts
14888
+ function mergeGeneration(call, fromConfig) {
14889
+ if (call === void 0 && fromConfig === void 0) return void 0;
14890
+ const maxTokens = call?.maxTokens ?? fromConfig?.maxTokens;
14891
+ const temperature = call?.temperature ?? fromConfig?.temperature;
14892
+ const out = {};
14893
+ if (maxTokens !== void 0) out.maxTokens = maxTokens;
14894
+ if (temperature !== void 0) out.temperature = temperature;
14895
+ if (call?.toolChoice !== void 0) out.toolChoice = call.toolChoice;
14896
+ if (call?.responseFormat !== void 0) out.responseFormat = call.responseFormat;
14897
+ return Object.keys(out).length > 0 ? out : void 0;
14898
+ }
14899
+ function generationBodyKeys(params) {
14900
+ if (params === void 0) return {};
14901
+ return {
14902
+ ...params.maxTokens !== void 0 ? { max_tokens: params.maxTokens } : {},
14903
+ ...params.temperature !== void 0 ? { temperature: params.temperature } : {},
14904
+ ...params.toolChoice !== void 0 ? { tool_choice: params.toolChoice } : {}
14905
+ };
14906
+ }
14907
+ function resolveResponseFormat(mode, callLevel) {
14908
+ if (mode === void 0 || mode === "off") return void 0;
14909
+ if (mode === "always") return "json_object";
14910
+ return callLevel;
14911
+ }
14912
+ function messagesMentionJson(messages) {
14913
+ const \u547D\u4E2D = (s) => typeof s === "string" && /json/i.test(s);
14914
+ for (const m of messages) {
14915
+ if (typeof m.content === "string" && \u547D\u4E2D(m.content)) return true;
14916
+ if (Array.isArray(m.content) && m.content.some((p) => \u547D\u4E2D(p.text))) return true;
14917
+ const calls = m.tool_calls;
14918
+ if (calls?.some((c) => \u547D\u4E2D(c.function.arguments)) === true) return true;
14919
+ }
14920
+ return false;
14921
+ }
14922
+ var init_generation = __esm({
14923
+ "packages/core/src/llm/generation.ts"() {
14924
+ "use strict";
14925
+ }
14926
+ });
14927
+
14788
14928
  // packages/core/src/llm/client.ts
14789
14929
  function parseUsage(raw) {
14790
14930
  if (!raw || raw.prompt_tokens === void 0 && raw.completion_tokens === void 0) return void 0;
@@ -14823,30 +14963,15 @@ function parseRetryAfterMs(retryAfter, retryAfterMs = null, now = Date.now()) {
14823
14963
  function isCapacityError2(err) {
14824
14964
  return classifyLlmError(err).capacity;
14825
14965
  }
14826
- function mergeGeneration(call, fromConfig) {
14827
- if (call === void 0 && fromConfig === void 0) return void 0;
14828
- const maxTokens = call?.maxTokens ?? fromConfig?.maxTokens;
14829
- const temperature = call?.temperature ?? fromConfig?.temperature;
14830
- const out = {};
14831
- if (maxTokens !== void 0) out.maxTokens = maxTokens;
14832
- if (temperature !== void 0) out.temperature = temperature;
14833
- if (call?.toolChoice !== void 0) out.toolChoice = call.toolChoice;
14834
- return Object.keys(out).length > 0 ? out : void 0;
14835
- }
14836
- function generationBodyKeys(params) {
14837
- if (params === void 0) return {};
14838
- return {
14839
- ...params.maxTokens !== void 0 ? { max_tokens: params.maxTokens } : {},
14840
- ...params.temperature !== void 0 ? { temperature: params.temperature } : {},
14841
- ...params.toolChoice !== void 0 ? { tool_choice: params.toolChoice } : {}
14842
- };
14843
- }
14844
14966
  var LLM_FIRST_BYTE_TIMEOUT_MS, LLM_STREAM_IDLE_MS, DEFAULT_MAX_RETRIES, LlmClient;
14845
14967
  var init_client = __esm({
14846
14968
  "packages/core/src/llm/client.ts"() {
14847
14969
  "use strict";
14848
14970
  init_retry();
14849
14971
  init_error_classify();
14972
+ init_error_classify();
14973
+ init_generation();
14974
+ init_generation();
14850
14975
  LLM_FIRST_BYTE_TIMEOUT_MS = 12e4;
14851
14976
  LLM_STREAM_IDLE_MS = 9e4;
14852
14977
  DEFAULT_MAX_RETRIES = 2;
@@ -15180,6 +15305,11 @@ var init_client = __esm({
15180
15305
  const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
15181
15306
  try {
15182
15307
  const url = `${this.config.baseUrl.replace(/\/+$/, "")}/chat/completions`;
15308
+ const \u751F\u6210 = mergeGeneration(options, this.config.generation);
15309
+ const \u751F\u6548Format = resolveResponseFormat(this.config.responseFormatMode, \u751F\u6210?.responseFormat);
15310
+ if (\u751F\u6548Format !== void 0 && !messagesMentionJson(messages)) {
15311
+ throw new LlmResponseFormatError();
15312
+ }
15183
15313
  const response = await this.doFetch(url, {
15184
15314
  method: "POST",
15185
15315
  headers: {
@@ -15193,7 +15323,9 @@ var init_client = __esm({
15193
15323
  ...options.tools && options.tools.length > 0 ? { tools: [...options.tools] } : {},
15194
15324
  // 生成参数(G7-03 演进节):**只写设过的键**——`temperature: 0` 有意义,不能被真值判断吞掉。
15195
15325
  // 「没说要」与「要 0」在线上是两种语义(同 `parseUsage` 的「缺省项不写」纪律)。
15196
- ...generationBodyKeys(mergeGeneration(options, this.config.generation)),
15326
+ ...generationBodyKeys(\u751F\u6210),
15327
+ // 结构化输出(2026-10-22 演进节):只在**生效档**要它时才出现这个键 ⇒ 缺省请求体逐字节不变。
15328
+ ...\u751F\u6548Format !== void 0 ? { response_format: { type: \u751F\u6548Format } } : {},
15197
15329
  // 流式 usage(G1-26 / D§2.3):不写 `stream_options.include_usage` ⇒ 流式路径 promptTokens
15198
15330
  // **静默缺失** ⇒ token 账与压缩预算的实测源、`tokenEstimator` 自校准全没了(只剩估算)。
15199
15331
  ...options.stream && this.config.streamIncludeUsage !== false ? { stream_options: { include_usage: true } } : {}
@@ -17445,7 +17577,15 @@ async function completeStructured(llm, messages, opts) {
17445
17577
  ];
17446
17578
  const response = await llm.complete(\u672C\u8F6E, {
17447
17579
  ...opts.model !== void 0 ? { model: opts.model } : {},
17448
- ...opts.signal !== void 0 ? { signal: opts.signal } : {}
17580
+ ...opts.signal !== void 0 ? { signal: opts.signal } : {},
17581
+ /**
17582
+ * **调用级要求**(`spec/llm-transport.md` 演进「response_format 开关」):上面这段活本来就是
17583
+ * 「给我合法 JSON」,所以这里说「我这次要结构化」是名副其实的。
17584
+ *
17585
+ * 但**发不发由配置定**(`resolveResponseFormat`):`off` 一律不发(用户说关就关)、
17586
+ * `structured` 才采用这个要求、`always` 全部发。调用方不该也无法绕开用户的总开关。
17587
+ */
17588
+ responseFormat: "json_object"
17449
17589
  });
17450
17590
  const \u89E3 = parseStructured(response.content, opts.schema);
17451
17591
  if (\u89E3.ok) return { value: \u89E3.value, response };
@@ -17506,7 +17646,7 @@ var init_structured = __esm({
17506
17646
  });
17507
17647
 
17508
17648
  // packages/core/src/agent/auto-memory.ts
17509
- import { z as z5 } from "zod";
17649
+ import { z as z7 } from "zod";
17510
17650
  function messagesToText(messages) {
17511
17651
  const lines = [];
17512
17652
  for (const m of messages) {
@@ -17556,7 +17696,7 @@ function buildExtractPrompt(messages, existingFacts) {
17556
17696
  ].join("\n");
17557
17697
  }
17558
17698
  function parseExtracted(text2) {
17559
- const \u6570\u7EC4 = parseStructured(text2, z5.array(z5.unknown()));
17699
+ const \u6570\u7EC4 = parseStructured(text2, z7.array(z7.unknown()));
17560
17700
  if (!\u6570\u7EC4.ok) return [];
17561
17701
  const out = [];
17562
17702
  for (const item of \u6570\u7EC4.value) {
@@ -17577,7 +17717,10 @@ function parseExtracted(text2) {
17577
17717
  }
17578
17718
  async function extractMemories(input) {
17579
17719
  const prompt = buildExtractPrompt(input.messages, input.existingFacts);
17580
- const res = await input.llm.complete([{ role: "user", content: prompt }], input.signal ? { signal: input.signal } : {});
17720
+ const res = await input.llm.complete([{ role: "user", content: prompt }], {
17721
+ ...input.signal ? { signal: input.signal } : {},
17722
+ responseFormat: "json_object"
17723
+ });
17581
17724
  return {
17582
17725
  memories: parseExtracted(res.content),
17583
17726
  ...res.usage === void 0 ? {} : { usage: res.usage },
@@ -17605,17 +17748,17 @@ var init_auto_memory = __esm({
17605
17748
  "use strict";
17606
17749
  init_structured();
17607
17750
  init_memory();
17608
- MEMORY_ITEM = z5.object({
17609
- key: z5.string().trim().min(1),
17610
- content: z5.string().trim().min(1),
17611
- memoryType: z5.enum(MEMORY_TYPES).optional(),
17612
- confidence: z5.number().min(0).max(1).catch(0.5).optional(),
17751
+ MEMORY_ITEM = z7.object({
17752
+ key: z7.string().trim().min(1),
17753
+ content: z7.string().trim().min(1),
17754
+ memoryType: z7.enum(MEMORY_TYPES).optional(),
17755
+ confidence: z7.number().min(0).max(1).catch(0.5).optional(),
17613
17756
  // 准入闸要的裁决字段(G4-01):坏值逐项兜底(`.catch`)而不是一票否决整条——
17614
17757
  // 缺 `action` 按 `admit` 处理(宁可交给结构性硬闸判,也不在这里静默丢)。
17615
- action: z5.enum(["admit", "reject", "supersede"]).catch("admit").optional(),
17616
- transferableTo: z5.array(z5.string()).catch([]).optional(),
17617
- supersedesKey: z5.string().optional(),
17618
- reason: z5.string().optional()
17758
+ action: z7.enum(["admit", "reject", "supersede"]).catch("admit").optional(),
17759
+ transferableTo: z7.array(z7.string()).catch([]).optional(),
17760
+ supersedesKey: z7.string().optional(),
17761
+ reason: z7.string().optional()
17619
17762
  });
17620
17763
  }
17621
17764
  });
@@ -19658,7 +19801,7 @@ var init_limits = __esm({
19658
19801
  });
19659
19802
 
19660
19803
  // packages/core/src/agent/council/plan.ts
19661
- import { z as z6 } from "zod";
19804
+ import { z as z8 } from "zod";
19662
19805
  function stableConflictKey(left, right) {
19663
19806
  const [a, b] = [left, right].slice().sort();
19664
19807
  let h4 = 2166136261;
@@ -19803,46 +19946,46 @@ var PlanItemSchema, SeatRiskSchema, SeatChallengeSchema, SeatAlternativeSchema,
19803
19946
  var init_plan2 = __esm({
19804
19947
  "packages/core/src/agent/council/plan.ts"() {
19805
19948
  "use strict";
19806
- PlanItemSchema = z6.object({
19807
- id: z6.string(),
19808
- title: z6.string(),
19809
- detail: z6.string(),
19949
+ PlanItemSchema = z8.object({
19950
+ id: z8.string(),
19951
+ title: z8.string(),
19952
+ detail: z8.string(),
19810
19953
  /** 涉及文件(席位用只读工具定位后结构化输出)。 */
19811
- files: z6.array(z6.string()).optional()
19954
+ files: z8.array(z8.string()).optional()
19812
19955
  });
19813
- SeatRiskSchema = z6.object({
19814
- claim: z6.string(),
19815
- severity: z6.enum(["low", "medium", "high"]),
19816
- mitigation: z6.string(),
19956
+ SeatRiskSchema = z8.object({
19957
+ claim: z8.string(),
19958
+ severity: z8.enum(["low", "medium", "high"]),
19959
+ mitigation: z8.string(),
19817
19960
  /** 关联条目 id;缺省 = 泛化风险(不参与 id 相关性匹配)。 */
19818
- itemId: z6.string().optional()
19961
+ itemId: z8.string().optional()
19819
19962
  });
19820
- SeatChallengeSchema = z6.object({
19821
- text: z6.string(),
19963
+ SeatChallengeSchema = z8.object({
19964
+ text: z8.string(),
19822
19965
  /** blocking = 否决级:未化解前拒绝产出可执行计划。缺省 advisory。 */
19823
- severity: z6.enum(["advisory", "blocking"]).optional(),
19966
+ severity: z8.enum(["advisory", "blocking"]).optional(),
19824
19967
  /** 针对的条目 id;缺省 = 全局质疑。 */
19825
- itemId: z6.string().optional()
19968
+ itemId: z8.string().optional()
19826
19969
  });
19827
- SeatAlternativeSchema = z6.object({
19828
- proposal: z6.string(),
19829
- recommend: z6.boolean(),
19830
- rationale: z6.string(),
19831
- targetItemId: z6.string().optional()
19970
+ SeatAlternativeSchema = z8.object({
19971
+ proposal: z8.string(),
19972
+ recommend: z8.boolean(),
19973
+ rationale: z8.string(),
19974
+ targetItemId: z8.string().optional()
19832
19975
  });
19833
- SeatContributionSchema = z6.object({
19834
- authority: z6.string().min(1),
19835
- summary: z6.string(),
19836
- additions: z6.array(PlanItemSchema).default([]),
19837
- risks: z6.array(SeatRiskSchema).default([]),
19838
- challenges: z6.array(SeatChallengeSchema).default([]),
19839
- alternatives: z6.array(SeatAlternativeSchema).default([])
19976
+ SeatContributionSchema = z8.object({
19977
+ authority: z8.string().min(1),
19978
+ summary: z8.string(),
19979
+ additions: z8.array(PlanItemSchema).default([]),
19980
+ risks: z8.array(SeatRiskSchema).default([]),
19981
+ challenges: z8.array(SeatChallengeSchema).default([]),
19982
+ alternatives: z8.array(SeatAlternativeSchema).default([])
19840
19983
  });
19841
19984
  }
19842
19985
  });
19843
19986
 
19844
19987
  // packages/core/src/agent/council/tools.ts
19845
- import { z as z7 } from "zod";
19988
+ import { z as z9 } from "zod";
19846
19989
  async function runCouncil(service, opts, compact) {
19847
19990
  const { objective, draft, seats, maxRounds, timeoutMs, caller } = opts;
19848
19991
  const isSeatEstablished = (authority) => service.listMemberViews().some((m) => m.name === authority);
@@ -20325,12 +20468,12 @@ var init_tools2 = __esm({
20325
20468
  }
20326
20469
  };
20327
20470
  COMPILE_SUBJECT_MAX = 200;
20328
- RebuttalsSchema = z7.object({
20329
- rebuttals: z7.array(
20330
- z7.object({
20331
- conflictKey: z7.string(),
20332
- stance: z7.enum(["concede", "hold", "revise"]),
20333
- argument: z7.string()
20471
+ RebuttalsSchema = z9.object({
20472
+ rebuttals: z9.array(
20473
+ z9.object({
20474
+ conflictKey: z9.string(),
20475
+ stance: z9.enum(["concede", "hold", "revise"]),
20476
+ argument: z9.string()
20334
20477
  })
20335
20478
  )
20336
20479
  });
@@ -21222,7 +21365,7 @@ var init_run_registry = __esm({
21222
21365
  });
21223
21366
 
21224
21367
  // packages/core/src/llm/env.ts
21225
- import { z as z8 } from "zod";
21368
+ import { z as z10 } from "zod";
21226
21369
  function parseVisionModels(raw) {
21227
21370
  const out = {};
21228
21371
  if (raw.trim() === "") return out;
@@ -21258,22 +21401,22 @@ var EnvSchema, MAX_CHARS_PER_TOKEN, DEFAULT_CHARS_PER_TOKEN;
21258
21401
  var init_env = __esm({
21259
21402
  "packages/core/src/llm/env.ts"() {
21260
21403
  "use strict";
21261
- EnvSchema = z8.object({
21262
- DALUO_LLM_BASE_URL: z8.string().url(),
21263
- DALUO_LLM_API_KEY: z8.string().min(1),
21264
- DALUO_LLM_MODEL: z8.string().min(1),
21404
+ EnvSchema = z10.object({
21405
+ DALUO_LLM_BASE_URL: z10.string().url(),
21406
+ DALUO_LLM_API_KEY: z10.string().min(1),
21407
+ DALUO_LLM_MODEL: z10.string().min(1),
21265
21408
  // 可选旋钮:单请求最大重试次数(0=只试 1 次);模型 fallback 链(逗号分隔)
21266
- DALUO_LLM_MAX_RETRIES: z8.coerce.number().int().min(0).max(20).optional(),
21267
- DALUO_LLM_FALLBACK_MODELS: z8.string().optional(),
21409
+ DALUO_LLM_MAX_RETRIES: z10.coerce.number().int().min(0).max(20).optional(),
21410
+ DALUO_LLM_FALLBACK_MODELS: z10.string().optional(),
21268
21411
  // 可选旋钮:单请求**首字节**超时 ms(spec/llm-transport.md 明写「默认如 120s,可配」——
21269
21412
  // 此前只有构造函数入参,产品入口从不传,于是 env 根本配不了)。慢端点 / 超大上下文下
21270
21413
  // 120s 首字节不够:实测 20 万 token 级上下文写产物的那次请求被 120s 掐死(前面读了 16 分钟全白烧)。
21271
- DALUO_LLM_TIMEOUT_MS: z8.coerce.number().int().min(1e3).optional(),
21414
+ DALUO_LLM_TIMEOUT_MS: z10.coerce.number().int().min(1e3).optional(),
21272
21415
  // **模型的上下文窗口**(token)——**由客户在配置 provider 时声明**(2026-09-15 用户裁定)。
21273
21416
  // 为什么不下一个产品默认值:窗口是「模型/提供商」的属性,随 provider 而变;替客户猜(无论猜 64k 还是 1M)
21274
21417
  // 都会在某个组合上错——猜小则每轮压缩(实测活锁:阈值仅 31k → 200 轮零产出),猜大则撞窗口 400。
21275
21418
  // 未声明时按仓库既有保守默认(`DEFAULT_CONTEXT_WINDOW_TOKENS = 128k`)压缩,见 session/context-budget.ts。
21276
- DALUO_LLM_CONTEXT_WINDOW_TOKENS: z8.coerce.number().int().min(1e3).optional(),
21419
+ DALUO_LLM_CONTEXT_WINDOW_TOKENS: z10.coerce.number().int().min(1e3).optional(),
21277
21420
  /**
21278
21421
  * **模型支持图像输入吗(兜底层)**——同 `DALUO_LLM_CONTEXT_WINDOW_TOKENS`:由客户在配置 provider 时声明。
21279
21422
  * 为什么不下一个「大概支持」的默认值:视觉是模型/提供商的属性,替客户猜会在某个组合上错
@@ -21282,24 +21425,24 @@ var init_env = __esm({
21282
21425
  * 语义(2026-09-20 演进):这是**兜底**;**模型级声明走 `DALUO_LLM_VISION_MODELS`**(解析点在
21283
21426
  * `LlmClient.supportsVision`:模型条目 ?? 这里兜底——换模型即换能力位,不用重解析 env)。
21284
21427
  */
21285
- DALUO_LLM_VISION: z8.enum(["1", "0", "true", "false", "on", "off"]).optional(),
21428
+ DALUO_LLM_VISION: z10.enum(["1", "0", "true", "false", "on", "off"]).optional(),
21286
21429
  /**
21287
21430
  * **每模型视觉能力表**:`模型=1|0` 逗号分隔(cli 由提供方条目的 `models[].vision` 生成)。
21288
21431
  * 坏格式 fail loud(loadLlmConfig 抛)——能力位是权限级声明,宽容解析会把「写错了」悄悄变成「没声明」。
21289
21432
  */
21290
- DALUO_LLM_VISION_MODELS: z8.string().optional(),
21433
+ DALUO_LLM_VISION_MODELS: z10.string().optional(),
21291
21434
  /**
21292
21435
  * **每模型 token 密度表**:`模型=值` 逗号分隔(cli 由提供方条目的 `models[].charsPerToken` 生成)。
21293
21436
  * 坏格式 fail loud(`loadLlmConfig` 抛)——密度影响压缩阈值,宽容解析会把「写错了」悄悄变成「没声明」。
21294
21437
  */
21295
- DALUO_LLM_CHARS_PER_TOKEN_MODELS: z8.string().optional(),
21438
+ DALUO_LLM_CHARS_PER_TOKEN_MODELS: z10.string().optional(),
21296
21439
  /**
21297
21440
  * **token 密度兜底**:1 个 token 约等于多少字符(`spec/token-meter.md`,`P1-28`)。
21298
21441
  * 为什么要有它:仓库缺省是 4 字符/token,对中文**低估** ⇒ 中文长会话压缩触发偏晚。
21299
21442
  * 中文密集的模型可以在这里(或提供方/模型条目里)声明真实密度。
21300
21443
  * 区间 (0, 64]:0 / 负 / 荒谬大值 fail loud,不给「悄悄夹到合法区间」的魔法。
21301
21444
  */
21302
- DALUO_LLM_CHARS_PER_TOKEN: z8.coerce.number().gt(0).max(64).optional(),
21445
+ DALUO_LLM_CHARS_PER_TOKEN: z10.coerce.number().gt(0).max(64).optional(),
21303
21446
  /**
21304
21447
  * **流式请求要不要 `stream_options.include_usage`**(缺省要)——`DALUO_LLM_STREAM_USAGE=0` 关。
21305
21448
  *
@@ -21308,7 +21451,7 @@ var init_env = __esm({
21308
21451
  * 为什么留这个关:有的自建网关对未知字段直接 400——**端点脾气不该由代码猜**(不做「400 就自动不写」
21309
21452
  * 那种魔法:它会让「字段被拒」与「端点坏了」表现为同一种故障),给一个显式开关。
21310
21453
  */
21311
- DALUO_LLM_STREAM_USAGE: z8.enum(["0", "1", "false", "true", "off", "on"]).optional(),
21454
+ DALUO_LLM_STREAM_USAGE: z10.enum(["0", "1", "false", "true", "off", "on"]).optional(),
21312
21455
  /**
21313
21456
  * **生成参数**(spec/llm-transport.md「请求体生成参数」演进节,`G7-03`):输出长度上限与温度。
21314
21457
  *
@@ -21317,8 +21460,25 @@ var init_env = __esm({
21317
21460
  * 非法值 fail loud(zod 直接拒)——不给「悄悄夹到合法区间」的魔法:那会把「配置写错了」
21318
21461
  * 变成「行为莫名其妙」。
21319
21462
  */
21320
- DALUO_LLM_MAX_TOKENS: z8.coerce.number().int().min(1).optional(),
21321
- DALUO_LLM_TEMPERATURE: z8.coerce.number().min(0).max(2).optional()
21463
+ DALUO_LLM_MAX_TOKENS: z10.coerce.number().int().min(1).optional(),
21464
+ DALUO_LLM_TEMPERATURE: z10.coerce.number().min(0).max(2).optional(),
21465
+ /**
21466
+ * **结构化输出开关**(`response_format`,`spec/llm-transport.md` 演进「`response_format` 开关」,2026-10-22)。
21467
+ *
21468
+ * 三档,缺省 `off`(一个字节都不发——与改动前逐字等价):
21469
+ * - `off`:不发。**总开关**:即使调用级显式要求也不发(用户说关就关)。
21470
+ * - `structured`:只给**显式要求结构化**的调用发(`completeStructured`:guardian / auto-memory /
21471
+ * council 席位)。主循环不受影响 ⇒ 助手正文仍是人话。
21472
+ * - `always`:所有请求都发。**代价如实记**:`content` 会被上游强制成 JSON,于是纯文本轮的回答
21473
+ * 在会话里就是一段 JSON 串(工具轮不受影响:照常返回 `tool_calls`)。
21474
+ *
21475
+ * **为什么做成开关而不是默认开**:①上游(DeepSeek 系)要求 prompt 里必须出现 `json` 字样,
21476
+ * 否则直接 400——这是**调用方的 prompt 责任**,不能由我们在 system 里硬塞一句(那是污染缓存前缀);
21477
+ * ②实测(2026-10-22,同一网关 24 次带 tools 的请求)不带这个参数时工具参数**零破坏**,
21478
+ * 没有基线失败可修 ⇒ 默认开等于为一个测不出收益的东西改所有会话的请求体;
21479
+ * ③它有已知副作用(空 `content` 概率、正文变 JSON),必须由知道代价的人开。
21480
+ */
21481
+ DALUO_LLM_RESPONSE_FORMAT: z10.enum(["off", "structured", "always"]).optional()
21322
21482
  }).transform((env) => {
21323
21483
  const out = {
21324
21484
  baseUrl: env.DALUO_LLM_BASE_URL,
@@ -21339,6 +21499,7 @@ var init_env = __esm({
21339
21499
  if (env.DALUO_LLM_MAX_TOKENS !== void 0) generation.maxTokens = env.DALUO_LLM_MAX_TOKENS;
21340
21500
  if (env.DALUO_LLM_TEMPERATURE !== void 0) generation.temperature = env.DALUO_LLM_TEMPERATURE;
21341
21501
  if (Object.keys(generation).length > 0) out.generation = generation;
21502
+ if (env.DALUO_LLM_RESPONSE_FORMAT !== void 0) out.responseFormatMode = env.DALUO_LLM_RESPONSE_FORMAT;
21342
21503
  const fallback = (env.DALUO_LLM_FALLBACK_MODELS ?? "").split(",").map((s) => s.trim()).filter(Boolean);
21343
21504
  if (fallback.length > 0) out.fallbackModels = fallback;
21344
21505
  return out;
@@ -23768,7 +23929,7 @@ var init_manager = __esm({
23768
23929
  });
23769
23930
 
23770
23931
  // packages/core/src/lsp/env.ts
23771
- import { z as z9 } from "zod";
23932
+ import { z as z11 } from "zod";
23772
23933
  function parseLspServersEnv(env) {
23773
23934
  const raw = env.DALUO_LSP_SERVERS;
23774
23935
  if (raw === void 0 || raw.trim() === "") return void 0;
@@ -23794,18 +23955,18 @@ var LspServerConfigSchema;
23794
23955
  var init_env2 = __esm({
23795
23956
  "packages/core/src/lsp/env.ts"() {
23796
23957
  "use strict";
23797
- LspServerConfigSchema = z9.object({
23798
- command: z9.string().min(1),
23799
- args: z9.array(z9.string()).optional(),
23800
- extensions: z9.array(z9.string()).optional(),
23958
+ LspServerConfigSchema = z11.object({
23959
+ command: z11.string().min(1),
23960
+ args: z11.array(z11.string()).optional(),
23961
+ extensions: z11.array(z11.string()).optional(),
23801
23962
  /**
23802
23963
  * `G2-60`:这三个字段 `LspServerConfig` **一直声明着**(client 也一直用:spawn 的 cwd/env、
23803
23964
  * 单请求超时缺省),但**解析器不认** —— zod 的缺省行为是丢掉未知键,于是用户写进
23804
23965
  * `DALUO_LSP_SERVERS` 的 `cwd` / `env` / `timeoutMs` 被**静默丢弃**(配置写着不生效,最难查)。
23805
23966
  */
23806
- cwd: z9.string().min(1).optional(),
23807
- env: z9.record(z9.string(), z9.string()).optional(),
23808
- timeoutMs: z9.number().int().positive().optional()
23967
+ cwd: z11.string().min(1).optional(),
23968
+ env: z11.record(z11.string(), z11.string()).optional(),
23969
+ timeoutMs: z11.number().int().positive().optional()
23809
23970
  });
23810
23971
  }
23811
23972
  });
@@ -26803,7 +26964,7 @@ var init_config = __esm({
26803
26964
  // packages/core/src/agent/guardian.ts
26804
26965
  import { readFile as readFile14 } from "node:fs/promises";
26805
26966
  import { resolve as resolve11 } from "node:path";
26806
- import { z as z10 } from "zod";
26967
+ import { z as z12 } from "zod";
26807
26968
  function isHighRiskTool(toolName) {
26808
26969
  return toolName === EDIT || toolName === WRITE_FILE || toolName === MULTIEDIT || toolName === BASH;
26809
26970
  }
@@ -26821,7 +26982,10 @@ function reviewPrompt(toolName, input) {
26821
26982
  ].join("\n");
26822
26983
  }
26823
26984
  async function guardianReview(llm, toolName, input) {
26824
- const res = await llm.complete([{ role: "user", content: reviewPrompt(toolName, input) }], { temperature: 0 });
26985
+ const res = await llm.complete([{ role: "user", content: reviewPrompt(toolName, input) }], {
26986
+ temperature: 0,
26987
+ responseFormat: "json_object"
26988
+ });
26825
26989
  const \u89E3 = parseStructured(res.content, GUARDIAN_VERDICT);
26826
26990
  if (!\u89E3.ok) return { outcome: "review", reasoning: `\u5BA1\u67E5\u7ED3\u8BBA\u4E0D\u53EF\u7528\uFF08${\u89E3.\u539F\u56E0}\uFF09\uFF0C\u8BF7\u4EBA\u5DE5\u786E\u8BA4` };
26827
26991
  const { outcome, reason } = \u89E3.value;
@@ -26914,9 +27078,9 @@ var init_guardian = __esm({
26914
27078
  "use strict";
26915
27079
  init_structured();
26916
27080
  init_names2();
26917
- GUARDIAN_VERDICT = z10.object({
26918
- outcome: z10.enum(["approve", "deny", "review"]),
26919
- reason: z10.string().optional()
27081
+ GUARDIAN_VERDICT = z12.object({
27082
+ outcome: z12.enum(["approve", "deny", "review"]),
27083
+ reason: z12.string().optional()
26920
27084
  });
26921
27085
  CircuitBreaker = class {
26922
27086
  failures = 0;
@@ -28501,7 +28665,7 @@ var init_lessons = __esm({
28501
28665
  import { randomBytes as randomBytes4 } from "node:crypto";
28502
28666
  import { realpath as realpath2, stat as stat16 } from "node:fs/promises";
28503
28667
  import { basename as basename13 } from "node:path";
28504
- import { z as z11 } from "zod";
28668
+ import { z as z13 } from "zod";
28505
28669
  function emptyRegistry() {
28506
28670
  return { workspaces: [], unregistered: [], failures: [] };
28507
28671
  }
@@ -28605,34 +28769,34 @@ var init_workspace = __esm({
28605
28769
  "use strict";
28606
28770
  init_log_io();
28607
28771
  BaseSchema = {
28608
- seq: z11.number().int().positive(),
28609
- ts: z11.string()
28772
+ seq: z13.number().int().positive(),
28773
+ ts: z13.string()
28610
28774
  };
28611
- CreatedSchema = z11.object({
28775
+ CreatedSchema = z13.object({
28612
28776
  ...BaseSchema,
28613
- type: z11.literal("workspace/created"),
28614
- workspaceId: z11.string(),
28615
- root: z11.string(),
28616
- title: z11.string()
28777
+ type: z13.literal("workspace/created"),
28778
+ workspaceId: z13.string(),
28779
+ root: z13.string(),
28780
+ title: z13.string()
28617
28781
  });
28618
- RenamedSchema = z11.object({
28782
+ RenamedSchema = z13.object({
28619
28783
  ...BaseSchema,
28620
- type: z11.literal("workspace/renamed"),
28621
- workspaceId: z11.string(),
28622
- title: z11.string()
28784
+ type: z13.literal("workspace/renamed"),
28785
+ workspaceId: z13.string(),
28786
+ title: z13.string()
28623
28787
  });
28624
- UnregisteredSchema = z11.object({
28788
+ UnregisteredSchema = z13.object({
28625
28789
  ...BaseSchema,
28626
- type: z11.literal("workspace/unregistered"),
28627
- workspaceId: z11.string()
28790
+ type: z13.literal("workspace/unregistered"),
28791
+ workspaceId: z13.string()
28628
28792
  });
28629
- ReorderedSchema = z11.object({
28793
+ ReorderedSchema = z13.object({
28630
28794
  ...BaseSchema,
28631
- type: z11.literal("workspace/reordered"),
28632
- workspaceId: z11.string(),
28633
- before: z11.string().optional()
28795
+ type: z13.literal("workspace/reordered"),
28796
+ workspaceId: z13.string(),
28797
+ before: z13.string().optional()
28634
28798
  });
28635
- WorkspaceEvent = z11.discriminatedUnion("type", [
28799
+ WorkspaceEvent = z13.discriminatedUnion("type", [
28636
28800
  CreatedSchema,
28637
28801
  RenamedSchema,
28638
28802
  UnregisteredSchema,
@@ -30026,6 +30190,8 @@ __export(internal_exports, {
30026
30190
  COMPACTION_WARN_MARK: () => COMPACTION_WARN_MARK,
30027
30191
  COMPLETION_GUARD_STEP_ID: () => COMPLETION_GUARD_STEP_ID,
30028
30192
  COMPUTER_USE_PROMPT: () => COMPUTER_USE_PROMPT,
30193
+ CONTEXT_WARN_BLOCK: () => CONTEXT_WARN_BLOCK,
30194
+ CONTEXT_WARN_RATIO: () => CONTEXT_WARN_RATIO,
30029
30195
  CORRECTION_PREFIX: () => CORRECTION_PREFIX,
30030
30196
  COUNCIL_KEEP_MESSAGES: () => COUNCIL_KEEP_MESSAGES,
30031
30197
  CUA_TOOL_PREFIX: () => CUA_TOOL_PREFIX,
@@ -30038,6 +30204,7 @@ __export(internal_exports, {
30038
30204
  ContentPartSchema: () => ContentPartSchema,
30039
30205
  Context: () => Context,
30040
30206
  ContextInjectedSchema: () => ContextInjectedSchema,
30207
+ ContextReportSchema: () => ContextReportSchema,
30041
30208
  DALUO_FORMAT_VERSION: () => DALUO_FORMAT_VERSION,
30042
30209
  DECLARE_UNVERIFIABLE: () => DECLARE_UNVERIFIABLE,
30043
30210
  DEFAULT_ARGUMENTS_PREVIEW_CHARS: () => DEFAULT_ARGUMENTS_PREVIEW_CHARS,
@@ -30108,9 +30275,11 @@ __export(internal_exports, {
30108
30275
  LifecycleUserError: () => LifecycleUserError,
30109
30276
  LlmClient: () => LlmClient,
30110
30277
  LlmHttpError: () => LlmHttpError,
30278
+ LlmResponseFormatError: () => LlmResponseFormatError,
30111
30279
  LlmStreamError: () => LlmStreamError,
30112
30280
  LlmStructuredError: () => LlmStructuredError,
30113
30281
  LlmTimeoutError: () => LlmTimeoutError,
30282
+ LlmToolArgsError: () => LlmToolArgsError,
30114
30283
  LlmUsageSchema: () => LlmUsageSchema,
30115
30284
  LspServer: () => LspServer,
30116
30285
  LspServerManager: () => LspServerManager,
@@ -30211,6 +30380,7 @@ __export(internal_exports, {
30211
30380
  SETTING_COMPACTION_KEEP_TOKENS: () => SETTING_COMPACTION_KEEP_TOKENS,
30212
30381
  SETTING_COMPACTION_LLM_SUMMARY: () => SETTING_COMPACTION_LLM_SUMMARY,
30213
30382
  SETTING_COMPACTION_RESERVE_OUTPUT_TOKENS: () => SETTING_COMPACTION_RESERVE_OUTPUT_TOKENS,
30383
+ SETTING_LLM_RESPONSE_FORMAT: () => SETTING_LLM_RESPONSE_FORMAT,
30214
30384
  SETTING_MODELS_KNOWN: () => SETTING_MODELS_KNOWN,
30215
30385
  SETTING_MODEL_DEFAULT: () => SETTING_MODEL_DEFAULT,
30216
30386
  SETTING_PERMISSION_READ_ONLY_PROGRAMS: () => SETTING_PERMISSION_READ_ONLY_PROGRAMS,
@@ -30408,6 +30578,7 @@ __export(internal_exports, {
30408
30578
  connectMcpServer: () => connectMcpServer,
30409
30579
  contextAnchorTokens: () => contextAnchorTokens,
30410
30580
  contextThresholdTokens: () => contextThresholdTokens,
30581
+ contextWindowOf: () => contextWindowOf,
30411
30582
  controlledTerminalEnv: () => controlledTerminalEnv,
30412
30583
  cosineSimilarity: () => cosineSimilarity,
30413
30584
  costForEvents: () => costForEvents,
@@ -30611,6 +30782,7 @@ __export(internal_exports, {
30611
30782
  memoryTarget: () => memoryTarget,
30612
30783
  mergeGeneration: () => mergeGeneration,
30613
30784
  mergeTools: () => mergeTools,
30785
+ messagesMentionJson: () => messagesMentionJson,
30614
30786
  mineLessons: () => mineLessons,
30615
30787
  multieditTool: () => multieditTool,
30616
30788
  nextPendingInput: () => nextPendingInput,
@@ -30722,6 +30894,7 @@ __export(internal_exports, {
30722
30894
  resolvePermissionAnswer: () => resolvePermissionAnswer,
30723
30895
  resolvePluginConfig: () => resolvePluginConfig,
30724
30896
  resolvePublicHost: () => resolvePublicHost,
30897
+ resolveResponseFormat: () => resolveResponseFormat,
30725
30898
  resolveSessionIndex: () => resolveSessionIndex,
30726
30899
  resolveSubagentRoles: () => resolveSubagentRoles,
30727
30900
  restoreCheckpoint: () => restoreCheckpoint,
@@ -31080,6 +31253,12 @@ async function resolveLlmEnv(input) {
31080
31253
  const temperature = input.processEnv.DALUO_LLM_TEMPERATURE ?? dotenv.DALUO_LLM_TEMPERATURE;
31081
31254
  if (maxTokens !== void 0) out.DALUO_LLM_MAX_TOKENS = maxTokens;
31082
31255
  if (temperature !== void 0) out.DALUO_LLM_TEMPERATURE = temperature;
31256
+ const \u8BBE\u7F6E\u91CC\u7684\u6863 = stringSetting(
31257
+ loadSettingsSync2(globalSettingsFile(configHome, { create: false })),
31258
+ SETTING_LLM_RESPONSE_FORMAT
31259
+ );
31260
+ const responseFormat = \u8BBE\u7F6E\u91CC\u7684\u6863 ?? input.processEnv.DALUO_LLM_RESPONSE_FORMAT ?? dotenv.DALUO_LLM_RESPONSE_FORMAT;
31261
+ if (responseFormat !== void 0) out.DALUO_LLM_RESPONSE_FORMAT = responseFormat;
31083
31262
  return out;
31084
31263
  }
31085
31264
  var init_user_config2 = __esm({
@@ -46436,6 +46615,9 @@ var HOST_RETRYABLE = {
46436
46615
  usage: false,
46437
46616
  unknown: false,
46438
46617
  "rate-limit": true,
46618
+ // 模型吐坏 JSON:重新采样(同一 prompt 再跑一次)大概率正常 ⇒ 与 network/timeout 同侧。
46619
+ // 注意它**不是** `unknown`:unknown 保守取 false(不知道就不敢自动重试),这条是知道该怎么办。
46620
+ "model-output": true,
46439
46621
  auth: false
46440
46622
  };
46441
46623
  function zodIssuesToUserMessage(error) {
@@ -46483,6 +46665,13 @@ function classifyKind(error) {
46483
46665
  if (error instanceof CliUsageError) {
46484
46666
  return { kind: "usage", exitCode: EXIT.input };
46485
46667
  }
46668
+ if (error instanceof LlmResponseFormatError) {
46669
+ return {
46670
+ kind: "config",
46671
+ exitCode: EXIT.config,
46672
+ hint: "\u628A DALUO_LLM_RESPONSE_FORMAT\uFF08\u6216\u8BBE\u7F6E llm.responseFormat\uFF09\u8BBE\u56DE off\uFF0C\u6216\u5728 prompt \u91CC\u8BF4\u660E\u5E0C\u671B\u7684 JSON \u5F62\u72B6\u3002"
46673
+ };
46674
+ }
46486
46675
  if (text2.includes("DALUO_LLM_")) {
46487
46676
  const userMessage = zodIssuesToUserMessage(error);
46488
46677
  return {
@@ -46511,6 +46700,14 @@ function classifyKind(error) {
46511
46700
  hint: "\u8BF7\u6C42\u8D85\u65F6\uFF0C\u53EF\u91CD\u8BD5\u3002\u82E5\u6301\u7EED\u8D85\u65F6\uFF0C\u68C0\u67E5\u7F51\u7EDC\u5230 DALUO_LLM_BASE_URL \u7684\u8FDE\u901A\u6027\u3002"
46512
46701
  };
46513
46702
  }
46703
+ if (error instanceof LlmToolArgsError) {
46704
+ return {
46705
+ kind: "model-output",
46706
+ exitCode: EXIT.error,
46707
+ message: `\u6A21\u578B\u8F93\u51FA\u7684\u5DE5\u5177\u53C2\u6570\u4E0D\u662F\u5408\u6CD5 JSON${error.toolName === void 0 ? "" : `\uFF08\u5DE5\u5177 ${error.toolName}\uFF09`}`,
46708
+ hint: "\u6A21\u578B\u91C7\u6837\u5F02\u5E38\uFF08\u5DE5\u5177\u53C2\u6570\u88AB\u622A\u65AD/\u4E0D\u5408\u6CD5\uFF09\uFF1A\u91CD\u8DD1\u4E00\u6B21\u901A\u5E38\u5C31\u597D\uFF1B\u957F\u53C2\u6570\u5DE5\u5177\u5EFA\u8BAE\u7F29\u77ED\u5355\u6B21\u53C2\u6570\uFF0C\u6216\u6362\u66F4\u7A33\u7684\u6A21\u578B\u3002"
46709
+ };
46710
+ }
46514
46711
  if (\u5224\u51B3?.category === "rate-limit") {
46515
46712
  return {
46516
46713
  kind: "rate-limit",