@daluo/cli 0.1.2 → 0.1.4
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/BUILD-STAMP +1 -1
- package/dist/page.js +5 -5
- package/dist/run.js +1288 -864
- package/package.json +6 -4
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
|
-
|
|
2133
|
-
|
|
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,240 @@ 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-assistant.ts
|
|
2210
|
+
import { z as z4 } from "zod";
|
|
2211
|
+
var TextPartSchema, ToolCallPartSchema, ReasoningPartSchema, ContentPartSchema, LlmUsageSchema, MessageAssistantSchema;
|
|
2212
|
+
var init_schema_assistant = __esm({
|
|
2213
|
+
"packages/core/src/session/event/schema-assistant.ts"() {
|
|
2214
|
+
"use strict";
|
|
2215
|
+
init_schema_base();
|
|
2216
|
+
TextPartSchema = z4.object({
|
|
2217
|
+
type: z4.literal("text"),
|
|
2218
|
+
text: z4.string()
|
|
2219
|
+
});
|
|
2220
|
+
ToolCallPartSchema = z4.object({
|
|
2221
|
+
type: z4.literal("tool-call"),
|
|
2222
|
+
toolCallId: z4.string(),
|
|
2223
|
+
toolName: z4.string(),
|
|
2224
|
+
input: z4.unknown()
|
|
2225
|
+
});
|
|
2226
|
+
ReasoningPartSchema = z4.object({
|
|
2227
|
+
type: z4.literal("reasoning"),
|
|
2228
|
+
text: z4.string()
|
|
2229
|
+
});
|
|
2230
|
+
ContentPartSchema = z4.discriminatedUnion("type", [
|
|
2231
|
+
TextPartSchema,
|
|
2232
|
+
ToolCallPartSchema,
|
|
2233
|
+
ReasoningPartSchema
|
|
2234
|
+
]);
|
|
2235
|
+
LlmUsageSchema = z4.object({
|
|
2236
|
+
promptTokens: z4.number().int().nonnegative(),
|
|
2237
|
+
completionTokens: z4.number().int().nonnegative(),
|
|
2238
|
+
/** 缓存命中 token(`prompt_tokens_details.cached_tokens`):provider 未回则不写。 */
|
|
2239
|
+
cachedTokens: z4.number().int().nonnegative().optional(),
|
|
2240
|
+
/** 思维链占用的输出 token(`completion_tokens_details.reasoning_tokens`):含在 completionTokens 内。 */
|
|
2241
|
+
reasoningTokens: z4.number().int().nonnegative().optional()
|
|
2242
|
+
});
|
|
2243
|
+
MessageAssistantSchema = BaseEventSchema.extend({
|
|
2244
|
+
type: z4.literal("message/assistant"),
|
|
2245
|
+
content: z4.array(ContentPartSchema),
|
|
2246
|
+
usage: LlmUsageSchema.optional(),
|
|
2247
|
+
model: z4.string().min(1).optional(),
|
|
2248
|
+
/**
|
|
2249
|
+
* **这一轮请求的墙钟耗时**(GitHub issue #9):从「开始发请求」到「拿到完整响应」的毫秒数,
|
|
2250
|
+
* **含**进程内重试与流式聚合,**不含**工具执行与压缩/指纹那些本地步骤。
|
|
2251
|
+
*
|
|
2252
|
+
* 宿主此前只能拿相邻事件的 `ts` 相减猜「慢在模型还是慢在工具」——跨一次工具往返就误差很大
|
|
2253
|
+
* (工具的耗时不在模型账上,但会被算进去)。这个字段让「哪一轮慢」可测。
|
|
2254
|
+
*
|
|
2255
|
+
* 可选:旧日志没有它照读(与 `model` 同款演进方式);纯描述,不参与 fold、不进回传。
|
|
2256
|
+
*/
|
|
2257
|
+
durationMs: z4.number().int().nonnegative().optional(),
|
|
2258
|
+
/**
|
|
2259
|
+
* 上游的 `choices[0].finish_reason` **原样**(`stop` / `tool_calls` / `length` / `content_filter` …)。
|
|
2260
|
+
*
|
|
2261
|
+
* 为什么值得落日志:`length` 是「输出被截断」的**唯一直接信号**。真机踩过(issue #5 那次)
|
|
2262
|
+
* 模型吐的 tool-call 参数是坏 JSON,当时分不清「采样手抖」还是「被 max_tokens 截断」——
|
|
2263
|
+
* 前者重采样大概率就好,后者重采样还会截断,处置完全不同。
|
|
2264
|
+
*
|
|
2265
|
+
* 原样存而不是归一成枚举:各家取值不统一(`stop`/`end_turn`/`stop_sequence`…),本仓不猜。
|
|
2266
|
+
*/
|
|
2267
|
+
finishReason: z4.string().min(1).optional()
|
|
2268
|
+
});
|
|
2269
|
+
}
|
|
2270
|
+
});
|
|
2271
|
+
|
|
2272
|
+
// packages/core/src/session/event/schema.ts
|
|
2273
|
+
import { z as z5 } from "zod";
|
|
2274
|
+
function isTextPart(part) {
|
|
2275
|
+
return part.type === "text";
|
|
2276
|
+
}
|
|
2277
|
+
function isReasoningPart(part) {
|
|
2278
|
+
return part.type === "reasoning";
|
|
2279
|
+
}
|
|
2280
|
+
function isToolCallPart(part) {
|
|
2281
|
+
return part.type === "tool-call";
|
|
2282
|
+
}
|
|
2283
|
+
var SessionCreatedSchema, SessionImportedSchema, UserImageSchema, MessageUserSchema, ContextInjectedSchema, 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;
|
|
2284
|
+
var init_schema = __esm({
|
|
2285
|
+
"packages/core/src/session/event/schema.ts"() {
|
|
2286
|
+
"use strict";
|
|
2287
|
+
init_permission_schema();
|
|
2288
|
+
init_schema_base();
|
|
2289
|
+
init_schema_telemetry();
|
|
2290
|
+
init_schema_assistant();
|
|
2291
|
+
init_permission_schema();
|
|
2292
|
+
init_schema_telemetry();
|
|
2293
|
+
init_schema_assistant();
|
|
2166
2294
|
SessionCreatedSchema = BaseEventSchema.extend({
|
|
2167
|
-
type:
|
|
2168
|
-
forkedFrom:
|
|
2295
|
+
type: z5.literal("session/created"),
|
|
2296
|
+
forkedFrom: z5.object({
|
|
2169
2297
|
/** 源会话 sessionId(稳定身份;文件名只作人类可读的指路)。 */
|
|
2170
|
-
sessionId:
|
|
2298
|
+
sessionId: z5.string(),
|
|
2171
2299
|
/** 源日志文件名(basename)——供 CLI/呈现直接指路。 */
|
|
2172
|
-
file:
|
|
2300
|
+
file: z5.string(),
|
|
2173
2301
|
/** 切割点:新会话继承了源的 `[1..seq]` 前缀(seq 必须落在**回合边界**上)。 */
|
|
2174
|
-
seq:
|
|
2302
|
+
seq: z5.number().int().positive()
|
|
2175
2303
|
}).optional()
|
|
2176
2304
|
});
|
|
2177
2305
|
SessionImportedSchema = BaseEventSchema.extend({
|
|
2178
|
-
type:
|
|
2306
|
+
type: z5.literal("session/imported"),
|
|
2179
2307
|
/** 源文件 basename(人类可读指路;导入是「这一份源 → 这一份目标」)。 */
|
|
2180
|
-
file:
|
|
2308
|
+
file: z5.string().min(1),
|
|
2181
2309
|
/** 源格式(闭集:本仓支持的两家)。 */
|
|
2182
|
-
format:
|
|
2310
|
+
format: z5.enum(["claude", "codex"]),
|
|
2183
2311
|
/** 源会话 id(拿得到就给)。 */
|
|
2184
|
-
sourceSessionId:
|
|
2312
|
+
sourceSessionId: z5.string().min(1).optional(),
|
|
2185
2313
|
/** 已导入的**条目数**(游标)。 */
|
|
2186
|
-
entries:
|
|
2314
|
+
entries: z5.number().int().nonnegative(),
|
|
2187
2315
|
/** 已导入条目的 digest(sha256 前 16)——resync 时校验「已导入的那一段没被改过」。 */
|
|
2188
|
-
digest:
|
|
2189
|
-
});
|
|
2190
|
-
TextPartSchema = z2.object({
|
|
2191
|
-
type: z2.literal("text"),
|
|
2192
|
-
text: z2.string()
|
|
2193
|
-
});
|
|
2194
|
-
ToolCallPartSchema = z2.object({
|
|
2195
|
-
type: z2.literal("tool-call"),
|
|
2196
|
-
toolCallId: z2.string(),
|
|
2197
|
-
toolName: z2.string(),
|
|
2198
|
-
input: z2.unknown()
|
|
2316
|
+
digest: z5.string().min(1)
|
|
2199
2317
|
});
|
|
2200
|
-
|
|
2201
|
-
type: z2.literal("reasoning"),
|
|
2202
|
-
text: z2.string()
|
|
2203
|
-
});
|
|
2204
|
-
ContentPartSchema = z2.discriminatedUnion("type", [
|
|
2205
|
-
TextPartSchema,
|
|
2206
|
-
ToolCallPartSchema,
|
|
2207
|
-
ReasoningPartSchema
|
|
2208
|
-
]);
|
|
2209
|
-
UserImageSchema = z2.object({
|
|
2318
|
+
UserImageSchema = z5.object({
|
|
2210
2319
|
/** 落盘后的**绝对路径**(字节在 `.daluo/tool-results/user-images/`;文件被清掉时那次请求退回纯文本)。 */
|
|
2211
|
-
path:
|
|
2212
|
-
mediaType:
|
|
2213
|
-
bytes:
|
|
2320
|
+
path: z5.string(),
|
|
2321
|
+
mediaType: z5.string(),
|
|
2322
|
+
bytes: z5.number().int().nonnegative(),
|
|
2214
2323
|
/** 像素宽高(能读到才写:PNG/JPEG/GIF/WebP 四种头;读不出就省字段,**不编**)。 */
|
|
2215
|
-
width:
|
|
2216
|
-
height:
|
|
2324
|
+
width: z5.number().int().positive().optional(),
|
|
2325
|
+
height: z5.number().int().positive().optional()
|
|
2217
2326
|
});
|
|
2218
2327
|
MessageUserSchema = BaseEventSchema.extend({
|
|
2219
|
-
type:
|
|
2220
|
-
content:
|
|
2328
|
+
type: z5.literal("message/user"),
|
|
2329
|
+
content: z5.string(),
|
|
2221
2330
|
/** 用户随这条消息附上的图(刀72):**可选**(老日志照常解析);附不附由请求侧按视觉能力与上限定。 */
|
|
2222
|
-
images:
|
|
2331
|
+
images: z5.array(UserImageSchema).optional(),
|
|
2223
2332
|
/**
|
|
2224
2333
|
* 投递回执(spec/input-queue.md 决策 1):这条 user 消息来自哪条待发项(`inbox/queued` 的 id)。
|
|
2225
2334
|
* 它就是「**已投递**」这件事本身——`fold` 的 `pending = queued − removed − delivered` 据此收敛。
|
|
2226
2335
|
* 对齐 dsh 的 `rpcId`(客户端据此把本地提交回声退休),也与团队消息 queued/delivered 同构。
|
|
2227
2336
|
*/
|
|
2228
|
-
inboxId:
|
|
2337
|
+
inboxId: z5.string().optional()
|
|
2229
2338
|
});
|
|
2230
2339
|
ContextInjectedSchema = BaseEventSchema.extend({
|
|
2231
|
-
type:
|
|
2340
|
+
type: z5.literal("context/injected"),
|
|
2232
2341
|
/** 渲染后的块文本(含 `[context:<kind>]` 头)——**就是模型看到的那一段**,逐字存。 */
|
|
2233
|
-
content:
|
|
2234
|
-
});
|
|
2235
|
-
LlmUsageSchema = z2.object({
|
|
2236
|
-
promptTokens: z2.number().int().nonnegative(),
|
|
2237
|
-
completionTokens: z2.number().int().nonnegative(),
|
|
2238
|
-
/** 缓存命中 token(`prompt_tokens_details.cached_tokens`):provider 未回则不写。 */
|
|
2239
|
-
cachedTokens: z2.number().int().nonnegative().optional(),
|
|
2240
|
-
/** 思维链占用的输出 token(`completion_tokens_details.reasoning_tokens`):含在 completionTokens 内。 */
|
|
2241
|
-
reasoningTokens: z2.number().int().nonnegative().optional()
|
|
2242
|
-
});
|
|
2243
|
-
MessageAssistantSchema = BaseEventSchema.extend({
|
|
2244
|
-
type: z2.literal("message/assistant"),
|
|
2245
|
-
content: z2.array(ContentPartSchema),
|
|
2246
|
-
usage: LlmUsageSchema.optional(),
|
|
2247
|
-
model: z2.string().min(1).optional()
|
|
2342
|
+
content: z5.string()
|
|
2248
2343
|
});
|
|
2249
|
-
DeltaTextSchema =
|
|
2250
|
-
kind:
|
|
2251
|
-
text:
|
|
2344
|
+
DeltaTextSchema = z5.object({
|
|
2345
|
+
kind: z5.literal("text"),
|
|
2346
|
+
text: z5.string()
|
|
2252
2347
|
});
|
|
2253
|
-
DeltaToolCallSchema =
|
|
2254
|
-
kind:
|
|
2255
|
-
toolCallId:
|
|
2256
|
-
name:
|
|
2257
|
-
arguments:
|
|
2348
|
+
DeltaToolCallSchema = z5.object({
|
|
2349
|
+
kind: z5.literal("tool-call"),
|
|
2350
|
+
toolCallId: z5.string(),
|
|
2351
|
+
name: z5.string().optional(),
|
|
2352
|
+
arguments: z5.unknown().optional()
|
|
2258
2353
|
});
|
|
2259
|
-
DeltaSchema =
|
|
2354
|
+
DeltaSchema = z5.discriminatedUnion("kind", [DeltaTextSchema, DeltaToolCallSchema]);
|
|
2260
2355
|
AssistantDeltaSchema = BaseEventSchema.extend({
|
|
2261
|
-
type:
|
|
2356
|
+
type: z5.literal("assistant/delta"),
|
|
2262
2357
|
delta: DeltaSchema
|
|
2263
2358
|
});
|
|
2264
|
-
ToolResultImageSchema =
|
|
2359
|
+
ToolResultImageSchema = z5.object({
|
|
2265
2360
|
/** 图落盘的绝对路径(文件被清掉时那次请求退回纯文本,见演进节记的边界)。 */
|
|
2266
|
-
path:
|
|
2361
|
+
path: z5.string(),
|
|
2267
2362
|
/** 落盘时的 MIME(`image/png` 等)。 */
|
|
2268
|
-
mediaType:
|
|
2269
|
-
bytes:
|
|
2363
|
+
mediaType: z5.string(),
|
|
2364
|
+
bytes: z5.number().int().nonnegative()
|
|
2270
2365
|
});
|
|
2271
2366
|
ToolBatchSchema = BaseEventSchema.extend({
|
|
2272
|
-
type:
|
|
2367
|
+
type: z5.literal("tool/batch"),
|
|
2273
2368
|
/** 本批的调用 id(**顺序 = calls 顺序**;并发执行,不表示先后)。 */
|
|
2274
|
-
toolCallIds:
|
|
2369
|
+
toolCallIds: z5.array(z5.string()),
|
|
2275
2370
|
/** 批开跑的时刻(与各 `tool/result` 的 `ts` 一起看,就能分辨「真并发」与「排着跑」)。 */
|
|
2276
|
-
startedAt:
|
|
2277
|
-
ok:
|
|
2278
|
-
failed:
|
|
2371
|
+
startedAt: z5.string(),
|
|
2372
|
+
ok: z5.number().int().nonnegative(),
|
|
2373
|
+
failed: z5.number().int().nonnegative()
|
|
2279
2374
|
});
|
|
2280
2375
|
ToolResultSchema = BaseEventSchema.extend({
|
|
2281
|
-
type:
|
|
2282
|
-
toolCallId:
|
|
2283
|
-
output:
|
|
2376
|
+
type: z5.literal("tool/result"),
|
|
2377
|
+
toolCallId: z5.string(),
|
|
2378
|
+
output: z5.unknown(),
|
|
2284
2379
|
/**
|
|
2285
2380
|
* 这次结果带回的图像(可选)。**与 `output` 分开**:`output` 会过预算那一步(超限换 stub/省略),
|
|
2286
2381
|
* 图引用不该被预算改写——它是「图在哪」的事实。
|
|
2287
2382
|
*/
|
|
2288
|
-
images:
|
|
2383
|
+
images: z5.array(ToolResultImageSchema).optional(),
|
|
2289
2384
|
/**
|
|
2290
2385
|
* 呈现元数据(spec/session-event.md 演进节 + tool-registry.md):**工具自己**给出的人话标题
|
|
2291
2386
|
* (`present(input)` 的结果;纯函数 ⇒ 重放一致)。**可选**:没给就由呈现层从参数猜(老行为不破)。
|
|
2292
2387
|
*/
|
|
2293
|
-
present:
|
|
2388
|
+
present: z5.object({ title: z5.string(), kind: z5.string().optional() }).optional(),
|
|
2294
2389
|
/**
|
|
2295
2390
|
* **退出码语义**(演进 2026-09-21,spec/tools.md「退出码不是布尔」/ G2-20,bash 产出)。
|
|
2296
2391
|
*
|
|
@@ -2301,7 +2396,7 @@ var init_schema = __esm({
|
|
|
2301
2396
|
* `isGenuinePass`)。**存在即「否定退出码」**(真故障走 `{error}` 结果,不需要它)。
|
|
2302
2397
|
* 可选 ⇒ 既有事件零迁移;不喂 LLM(模型读的是 output 正文里的人话)。
|
|
2303
2398
|
*/
|
|
2304
|
-
exitSemantics:
|
|
2399
|
+
exitSemantics: z5.object({ code: z5.number().int(), label: z5.string() }).optional(),
|
|
2305
2400
|
/**
|
|
2306
2401
|
* **假绿证据**(演进 2026-09-22,spec/a2-plan-goal.md A2b-7 / G5-48,bash 产出)。
|
|
2307
2402
|
*
|
|
@@ -2311,13 +2406,13 @@ var init_schema = __esm({
|
|
|
2311
2406
|
* 而「这条命令自称零用例」是**判定事实**,挂在正文形状上会被冲掉。**存在即「没验到东西」**。
|
|
2312
2407
|
* 可选 ⇒ 既有事件零迁移;不喂 LLM。`unchanged` 同款分工,见 spec/repeat-reminder.md 决策 10。
|
|
2313
2408
|
*/
|
|
2314
|
-
falseGreen:
|
|
2315
|
-
unchanged:
|
|
2409
|
+
falseGreen: z5.object({ declaration: z5.string(), sample: z5.string() }).optional(),
|
|
2410
|
+
unchanged: z5.literal(true).optional()
|
|
2316
2411
|
// 等待自报(2026-10-22):工具说「世界没变,我在等」⇒ 重复门豁免
|
|
2317
2412
|
});
|
|
2318
2413
|
CompactionSummarySchema = BaseEventSchema.extend({
|
|
2319
|
-
type:
|
|
2320
|
-
summary:
|
|
2414
|
+
type: z5.literal("compaction/summary"),
|
|
2415
|
+
summary: z5.string(),
|
|
2321
2416
|
/**
|
|
2322
2417
|
* 这次摘要**是谁产的**(演进,`G1-43` 降级路径主动披露):
|
|
2323
2418
|
* `explicit`(调用方给的)· `llm`(LLM 产出)· `rule`(**没给** LLM 摘要,规则兜底——正常路径)
|
|
@@ -2327,9 +2422,9 @@ var init_schema = __esm({
|
|
|
2327
2422
|
* 复盘)就分不出「这次是坏掉了」还是「这次本来就没用 LLM」——那正是 `G10-25` 那条纪律
|
|
2328
2423
|
* (边界要用**可表达的类型**写出来,别靠旁路信号猜)。可选 ⇒ 既有日志零迁移。
|
|
2329
2424
|
*/
|
|
2330
|
-
summarySource:
|
|
2331
|
-
keepMessages:
|
|
2332
|
-
shadowedToolCallIds:
|
|
2425
|
+
summarySource: z5.enum(["explicit", "llm", "rule", "rule-degraded"]).optional(),
|
|
2426
|
+
keepMessages: z5.number().int().nonnegative(),
|
|
2427
|
+
shadowedToolCallIds: z5.array(z5.string()),
|
|
2333
2428
|
/**
|
|
2334
2429
|
* 压缩后**重注的文件**(演进,`spec/compaction.md` 演进:P0-2「谁重新注入」的显式清单)。
|
|
2335
2430
|
*
|
|
@@ -2339,191 +2434,161 @@ var init_schema = __esm({
|
|
|
2339
2434
|
* **本仓不照抄它的数值**且换成字符口径,理由见 `compaction.ts` 的预算常量注释。
|
|
2340
2435
|
* 可选 ⇒ 既有事件零迁移。
|
|
2341
2436
|
*/
|
|
2342
|
-
attachments:
|
|
2437
|
+
attachments: z5.array(z5.object({ path: z5.string(), content: z5.string(), truncated: z5.boolean() })).optional(),
|
|
2343
2438
|
/** 想重注但没重注的文件 + 原因(**如实记账**:模型看不到就得知道为什么,对齐本仓「不静默降级」)。 */
|
|
2344
|
-
attachmentsSkipped:
|
|
2439
|
+
attachmentsSkipped: z5.array(z5.object({ path: z5.string(), reason: z5.string() })).optional(),
|
|
2345
2440
|
/**
|
|
2346
2441
|
* 这次压缩**摘的是哪份源的哪一段**(演进,`spec/session-tree.md` 演进:`G3-15` 摘要到此的出处)。
|
|
2347
2442
|
*
|
|
2348
2443
|
* 「摘要到此」是在**新会话**里写一条压缩事件(前缀被摘要替代、之后原文照抄)——不留出处的话,
|
|
2349
2444
|
* 那份新会话说不清「这段摘要是从哪来的」,审计与人对账都无从下手。**可选** ⇒ 既有压缩零迁移。
|
|
2350
2445
|
*/
|
|
2351
|
-
summarizedSource:
|
|
2352
|
-
sessionId:
|
|
2353
|
-
file:
|
|
2446
|
+
summarizedSource: z5.object({
|
|
2447
|
+
sessionId: z5.string(),
|
|
2448
|
+
file: z5.string(),
|
|
2354
2449
|
/** 摘要覆盖源的 `[1..upToSeq]`。 */
|
|
2355
|
-
upToSeq:
|
|
2450
|
+
upToSeq: z5.number().int().positive()
|
|
2356
2451
|
}).optional()
|
|
2357
2452
|
});
|
|
2358
2453
|
PromptSystemSchema = BaseEventSchema.extend({
|
|
2359
|
-
type:
|
|
2360
|
-
content:
|
|
2454
|
+
type: z5.literal("prompt/system"),
|
|
2455
|
+
content: z5.string(),
|
|
2361
2456
|
/**
|
|
2362
2457
|
* 这次请求**真发出去的工具名清单**(顺序 = 发送顺序;2026-09-21 加,对齐 dsh 的 `EpochHeader`)。
|
|
2363
2458
|
* 补的是一处审计缺口:从前日志只能看出发了哪份 system,看不出**这次用了哪套工具 schema**
|
|
2364
2459
|
* ——"为什么这轮它没调 X"查不出来;缓存侧也没法归因(schema 在 token 流前部,一变就从那里起全失效)。
|
|
2365
2460
|
* 可选(老日志没有这份字段,读到 undefined 即"未记录",不伪造)。
|
|
2366
2461
|
*/
|
|
2367
|
-
tools:
|
|
2462
|
+
tools: z5.array(z5.string()).optional(),
|
|
2368
2463
|
/** 工具 schema 全文的指纹(`fileHash(JSON.stringify(tools))`)——**逐字节**判断"这套 schema 换没换"。 */
|
|
2369
|
-
toolsFingerprint:
|
|
2464
|
+
toolsFingerprint: z5.string().optional(),
|
|
2370
2465
|
/** 工具定义 JSON 的**字符数**(读侧分项账用;只记长度不记全文;老日志无此字段 = 未记录,别当 0。由来见 `spec/token-meter.md` 演进「静态开销有了分项」)。 */
|
|
2371
|
-
toolsChars:
|
|
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()
|
|
2466
|
+
toolsChars: z5.number().int().nonnegative().optional()
|
|
2402
2467
|
});
|
|
2403
2468
|
MemoryExtractSchema = BaseEventSchema.extend({
|
|
2404
|
-
type:
|
|
2469
|
+
type: z5.literal("memory/extract"),
|
|
2405
2470
|
/** 过闸并入账的 key。 */
|
|
2406
|
-
admitted:
|
|
2471
|
+
admitted: z5.array(z5.string()),
|
|
2407
2472
|
/** 被拒的候选与理由(**理由要能被人看见**,不是丢掉)。 */
|
|
2408
|
-
rejected:
|
|
2473
|
+
rejected: z5.array(z5.object({ key: z5.string(), reason: z5.string() })),
|
|
2409
2474
|
/** 走取代链的 key(可选)。 */
|
|
2410
|
-
superseded:
|
|
2475
|
+
superseded: z5.array(z5.string()).optional(),
|
|
2411
2476
|
/** true = LLM 输出不可解析 ⇒ **fail-closed 一条没写**(与「判完都拒了」区分开);`error` 是另一种失败:
|
|
2412
2477
|
* 提取那次 LLM 调用**自己抛错**(网络/HTTP/超时)——「解析不出来」与「没拿到输出」日志里要分得开。 */
|
|
2413
|
-
failedClosed:
|
|
2414
|
-
error:
|
|
2478
|
+
failedClosed: z5.boolean().optional(),
|
|
2479
|
+
error: z5.string().optional(),
|
|
2415
2480
|
/** 提取那次 LLM 调用的账(`P1-39` 步一):旁路调用此前完全没账 ⇒ `daluo usage` 系统性少算它;缺省 = provider 未回(不写 `{0,0}`:「没拿到」≠「用了 0」)。 */
|
|
2416
2481
|
usage: LlmUsageSchema.optional(),
|
|
2417
2482
|
/** 这次提取实际用的模型(与 `message/assistant.model` 同源命名)——它可以是独立的 `autoExtract.llm`。 */
|
|
2418
|
-
model:
|
|
2483
|
+
model: z5.string().min(1).optional()
|
|
2419
2484
|
});
|
|
2420
2485
|
CompactionReclaimSchema = BaseEventSchema.extend({
|
|
2421
|
-
type:
|
|
2486
|
+
type: z5.literal("compaction/reclaim"),
|
|
2422
2487
|
/** 候选是否替换了历史(false = 原样保留、等下个边界)。 */
|
|
2423
|
-
committed:
|
|
2488
|
+
committed: z5.boolean(),
|
|
2424
2489
|
/**
|
|
2425
2490
|
* 裁决原因(与 `reclaim-gate.ts` 的词表**同源**:3 个 skip + 2 个 commit + 1 个「冷却中没试」)。
|
|
2426
2491
|
* `cooling-down` = **连试都没试**(拒绝后要等历史又长了一层绝对地板才值得再付一次摘要调用)——
|
|
2427
2492
|
* 那一档没有候选,故下面的数字字段记的是**当时的历史规模**(`beforeTokens === afterTokens`)。
|
|
2428
2493
|
*/
|
|
2429
2494
|
// `reclaim-cache-cold`(G1-57):前缀缓存已冷 ⇒ 只守绝对地板就提交(相对地板是给「热前缀」设的)
|
|
2430
|
-
reason:
|
|
2431
|
-
beforeTokens:
|
|
2432
|
-
afterTokens:
|
|
2495
|
+
reason: z5.enum(["unchanged", "no-reclaim", "below-reclaim-floor", "cooling-down", "reclaim-above-floor", "reclaim-cache-cold", "forced"]),
|
|
2496
|
+
beforeTokens: z5.number().int().nonnegative(),
|
|
2497
|
+
afterTokens: z5.number().int().nonnegative(),
|
|
2433
2498
|
/** 原量 − 新量(**可以为负**:候选可能让输入变长)。 */
|
|
2434
|
-
reclaimedTokens:
|
|
2499
|
+
reclaimedTokens: z5.number().int(),
|
|
2435
2500
|
/** 回收 / 原量(没有回收时为 0)。 */
|
|
2436
|
-
reclaimRatio:
|
|
2501
|
+
reclaimRatio: z5.number().nonnegative(),
|
|
2437
2502
|
/** 候选与原文是否有实质差异(无差异的候选永远不该提交)。 */
|
|
2438
|
-
changed:
|
|
2503
|
+
changed: z5.boolean(),
|
|
2439
2504
|
/** 冷却门槛(只在 `reason: 'cooling-down'` 时有)——「长到这个规模才值得再试」。 */
|
|
2440
|
-
coolingUntilTokens:
|
|
2505
|
+
coolingUntilTokens: z5.number().int().nonnegative().optional()
|
|
2441
2506
|
});
|
|
2442
2507
|
SubagentStartSchema = BaseEventSchema.extend({
|
|
2443
|
-
type:
|
|
2444
|
-
subagentId:
|
|
2445
|
-
task:
|
|
2508
|
+
type: z5.literal("subagent/start"),
|
|
2509
|
+
subagentId: z5.string(),
|
|
2510
|
+
task: z5.string()
|
|
2446
2511
|
});
|
|
2447
2512
|
SubagentReportSchema = BaseEventSchema.extend({
|
|
2448
|
-
type:
|
|
2449
|
-
subagentId:
|
|
2450
|
-
result:
|
|
2513
|
+
type: z5.literal("subagent/report"),
|
|
2514
|
+
subagentId: z5.string(),
|
|
2515
|
+
result: z5.string()
|
|
2451
2516
|
});
|
|
2452
2517
|
VerifyVerdictSchema = BaseEventSchema.extend({
|
|
2453
|
-
type:
|
|
2518
|
+
type: z5.literal("verify/verdict"),
|
|
2454
2519
|
/** 验证者会话 id(`verify-<uuid>`)——与它的独立日志一一对应,可审计。 */
|
|
2455
|
-
verifierId:
|
|
2520
|
+
verifierId: z5.string(),
|
|
2456
2521
|
/** 被验证的主张原文(重放时能看到「当时验的到底是什么」)。 */
|
|
2457
|
-
claim:
|
|
2458
|
-
verdict:
|
|
2522
|
+
claim: z5.string(),
|
|
2523
|
+
verdict: z5.enum(["verified", "falsified", "inconclusive"]),
|
|
2459
2524
|
/** 验证主体:本次覆盖的产物(显式 `artifacts` ∪ 会话中最后改动的非文档文件)。 */
|
|
2460
|
-
artifacts:
|
|
2525
|
+
artifacts: z5.array(z5.string()),
|
|
2461
2526
|
/** 主体内容指纹(16 位十六进制)。**取不到就不写**——不伪造。 */
|
|
2462
|
-
subjectHash:
|
|
2527
|
+
subjectHash: z5.string().optional(),
|
|
2463
2528
|
/** true = 复用既有结论(主体指纹未变,本次**没有**重跑验证者)。 */
|
|
2464
|
-
reused:
|
|
2529
|
+
reused: z5.boolean().optional(),
|
|
2465
2530
|
/** 验证者实际跑了几轮(复用时不写——那次没跑)。 */
|
|
2466
|
-
turns:
|
|
2531
|
+
turns: z5.number().int().nonnegative().optional(),
|
|
2467
2532
|
usage: LlmUsageSchema.optional(),
|
|
2468
2533
|
/** 非正常结束的原因(如 `budget-turns` / `budget-time`);缺失 = 正常跑完。 */
|
|
2469
|
-
stopReason:
|
|
2534
|
+
stopReason: z5.string().optional(),
|
|
2470
2535
|
/** 验证者独立会话日志路径。 */
|
|
2471
|
-
logFile:
|
|
2536
|
+
logFile: z5.string()
|
|
2472
2537
|
});
|
|
2473
|
-
TodoSchema =
|
|
2474
|
-
id:
|
|
2475
|
-
content:
|
|
2476
|
-
status:
|
|
2538
|
+
TodoSchema = z5.object({
|
|
2539
|
+
id: z5.string(),
|
|
2540
|
+
content: z5.string(),
|
|
2541
|
+
status: z5.enum(["pending", "in_progress", "completed"])
|
|
2477
2542
|
});
|
|
2478
2543
|
TodoUpdateSchema = BaseEventSchema.extend({
|
|
2479
|
-
type:
|
|
2480
|
-
todos:
|
|
2544
|
+
type: z5.literal("todo/update"),
|
|
2545
|
+
todos: z5.array(TodoSchema)
|
|
2481
2546
|
});
|
|
2482
2547
|
PlanModeSchema = BaseEventSchema.extend({
|
|
2483
|
-
type:
|
|
2484
|
-
active:
|
|
2548
|
+
type: z5.literal("plan/mode"),
|
|
2549
|
+
active: z5.boolean()
|
|
2485
2550
|
});
|
|
2486
2551
|
PolicyProfileSchema = BaseEventSchema.extend({
|
|
2487
|
-
type:
|
|
2488
|
-
profile:
|
|
2552
|
+
type: z5.literal("policy/profile"),
|
|
2553
|
+
profile: z5.enum(["read-only", "workspace", "danger-full"]),
|
|
2489
2554
|
/** 谁改的(审计用;缺省 'user'——老日志/CLI 内部改动不必标注)。 */
|
|
2490
|
-
by:
|
|
2555
|
+
by: z5.enum(["user", "agent"]).optional()
|
|
2491
2556
|
});
|
|
2492
|
-
GoalSchema =
|
|
2493
|
-
goalId:
|
|
2494
|
-
objective:
|
|
2495
|
-
status:
|
|
2496
|
-
criteria:
|
|
2557
|
+
GoalSchema = z5.object({
|
|
2558
|
+
goalId: z5.string(),
|
|
2559
|
+
objective: z5.string(),
|
|
2560
|
+
status: z5.enum(["active", "completed", "blocked"]),
|
|
2561
|
+
criteria: z5.string().optional()
|
|
2497
2562
|
});
|
|
2498
2563
|
GoalSetSchema = BaseEventSchema.extend({
|
|
2499
|
-
type:
|
|
2500
|
-
goalId:
|
|
2501
|
-
objective:
|
|
2502
|
-
status:
|
|
2503
|
-
criteria:
|
|
2564
|
+
type: z5.literal("goal/set"),
|
|
2565
|
+
goalId: z5.string(),
|
|
2566
|
+
objective: z5.string(),
|
|
2567
|
+
status: z5.enum(["active", "completed", "blocked"]),
|
|
2568
|
+
criteria: z5.string().optional()
|
|
2504
2569
|
});
|
|
2505
|
-
WorkflowNodeSchema =
|
|
2506
|
-
id:
|
|
2507
|
-
task:
|
|
2508
|
-
tools:
|
|
2509
|
-
verify:
|
|
2570
|
+
WorkflowNodeSchema = z5.object({
|
|
2571
|
+
id: z5.string(),
|
|
2572
|
+
task: z5.string(),
|
|
2573
|
+
tools: z5.array(z5.string()).optional(),
|
|
2574
|
+
verify: z5.string().optional()
|
|
2510
2575
|
});
|
|
2511
2576
|
WorkflowStartSchema = BaseEventSchema.extend({
|
|
2512
|
-
type:
|
|
2513
|
-
workflowId:
|
|
2514
|
-
nodes:
|
|
2515
|
-
dependsOn:
|
|
2577
|
+
type: z5.literal("workflow/start"),
|
|
2578
|
+
workflowId: z5.string(),
|
|
2579
|
+
nodes: z5.array(WorkflowNodeSchema),
|
|
2580
|
+
dependsOn: z5.record(z5.string(), z5.array(z5.string()))
|
|
2516
2581
|
});
|
|
2517
2582
|
WorkflowEndSchema = BaseEventSchema.extend({
|
|
2518
|
-
type:
|
|
2519
|
-
workflowId:
|
|
2520
|
-
results:
|
|
2521
|
-
nodeId:
|
|
2522
|
-
status:
|
|
2523
|
-
result:
|
|
2583
|
+
type: z5.literal("workflow/end"),
|
|
2584
|
+
workflowId: z5.string(),
|
|
2585
|
+
results: z5.array(z5.object({
|
|
2586
|
+
nodeId: z5.string(),
|
|
2587
|
+
status: z5.enum(["completed", "failed", "skipped"]),
|
|
2588
|
+
result: z5.string().optional()
|
|
2524
2589
|
}))
|
|
2525
2590
|
});
|
|
2526
|
-
TeamMemberSchema =
|
|
2591
|
+
TeamMemberSchema = z5.object({
|
|
2527
2592
|
/**
|
|
2528
2593
|
* 成员**身份 id**(spec/agent-team.md 决策 20,对齐 dsh 的 live `Agent` 身份 + `senderId/targetId`)。
|
|
2529
2594
|
*
|
|
@@ -2532,227 +2597,227 @@ var init_schema = __esm({
|
|
|
2532
2597
|
* 故身份用单调不回收的 `mem-<n>`,名字退化为**可复用的显示标签**(仅活跃期唯一)。
|
|
2533
2598
|
* Lead 的保留 id 是 `lead`(`mem-` 前缀保证不撞)。
|
|
2534
2599
|
*/
|
|
2535
|
-
id:
|
|
2536
|
-
name:
|
|
2600
|
+
id: z5.string().min(1),
|
|
2601
|
+
name: z5.string().min(1),
|
|
2537
2602
|
/**
|
|
2538
2603
|
* 成员的**职责简述**(对齐 dsh `roster.ts:258` 的 `requiredText(description, 200)`)。
|
|
2539
2604
|
* 与任务一样是「标签 + 完整说明」两段式的成员侧:`name` 是短标识,`description` 说明它被派什么责。
|
|
2540
2605
|
* 契约给缺省 `''` 以兼容加字段前的旧事件;必填性在工具层强制(同 daluo 的输入校验约定)。
|
|
2541
2606
|
*/
|
|
2542
|
-
description:
|
|
2607
|
+
description: z5.string().default(""),
|
|
2543
2608
|
/**
|
|
2544
2609
|
* 成员会话的**上下文来源**(**不是模型供应商**——该字段曾名 `provider`,借用上游
|
|
2545
2610
|
* subagent 术语,与「模型 provider」撞义,2026-09-11 改名)。
|
|
2546
2611
|
* `fresh` = 全新上下文(当前唯一已实现行为)/ `fork` = 继承 Root 已完成轮次(未实现,暂等价 fresh)。
|
|
2547
2612
|
*/
|
|
2548
|
-
context:
|
|
2613
|
+
context: z5.enum(["fresh", "fork"]),
|
|
2549
2614
|
/**
|
|
2550
2615
|
* 成员种类(配额归属):`temp` = 临时员工(占 `maxMembers`)/ `seat` = 议会席位
|
|
2551
2616
|
* (占 `councilSeats` 独立配额)。两套配额互不挤占(用户定 A 方案)。
|
|
2552
2617
|
*/
|
|
2553
|
-
kind:
|
|
2554
|
-
phase:
|
|
2618
|
+
kind: z5.enum(["temp", "seat"]),
|
|
2619
|
+
phase: z5.enum(["provisioning", "active", "failed", "released"]),
|
|
2555
2620
|
/**
|
|
2556
2621
|
* 失败原因(仅 `phase: 'failed'` 有意义)——对齐 dsh `roster.ts:297,425`:
|
|
2557
2622
|
* 快照带 `error`,`list_agents` 的 diagnostics 据此可归因(否则只有「失败了」,
|
|
2558
2623
|
* 不知道是启动炸了还是 prompt 没落盘)。可选,故旧事件 parse 不受影响。
|
|
2559
2624
|
*/
|
|
2560
|
-
error:
|
|
2625
|
+
error: z5.string().optional()
|
|
2561
2626
|
});
|
|
2562
2627
|
TeamMemberCreateSchema = BaseEventSchema.extend({
|
|
2563
|
-
type:
|
|
2564
|
-
teamId:
|
|
2628
|
+
type: z5.literal("team/member"),
|
|
2629
|
+
teamId: z5.string(),
|
|
2565
2630
|
member: TeamMemberSchema
|
|
2566
2631
|
});
|
|
2567
|
-
TeamMessageSchema =
|
|
2568
|
-
id:
|
|
2569
|
-
senderId:
|
|
2570
|
-
senderName:
|
|
2571
|
-
targetId:
|
|
2572
|
-
targetName:
|
|
2573
|
-
content:
|
|
2632
|
+
TeamMessageSchema = z5.object({
|
|
2633
|
+
id: z5.string().min(1),
|
|
2634
|
+
senderId: z5.string().min(1),
|
|
2635
|
+
senderName: z5.string().min(1),
|
|
2636
|
+
targetId: z5.string().min(1),
|
|
2637
|
+
targetName: z5.string().min(1),
|
|
2638
|
+
content: z5.string()
|
|
2574
2639
|
});
|
|
2575
2640
|
TeamMessageQueuedSchema = BaseEventSchema.extend({
|
|
2576
|
-
type:
|
|
2577
|
-
teamId:
|
|
2641
|
+
type: z5.literal("team/message/queued"),
|
|
2642
|
+
teamId: z5.string(),
|
|
2578
2643
|
message: TeamMessageSchema
|
|
2579
2644
|
});
|
|
2580
2645
|
TeamMessageDeliveredSchema = BaseEventSchema.extend({
|
|
2581
|
-
type:
|
|
2582
|
-
teamId:
|
|
2583
|
-
messageId:
|
|
2584
|
-
targetId:
|
|
2646
|
+
type: z5.literal("team/message/delivered"),
|
|
2647
|
+
teamId: z5.string(),
|
|
2648
|
+
messageId: z5.string().min(1),
|
|
2649
|
+
targetId: z5.string().min(1)
|
|
2585
2650
|
});
|
|
2586
|
-
TeamTaskSchema =
|
|
2587
|
-
id:
|
|
2651
|
+
TeamTaskSchema = z5.object({
|
|
2652
|
+
id: z5.string().min(1),
|
|
2588
2653
|
/** 简短标题(dsh `requiredText(subject, 200)`)。 */
|
|
2589
|
-
subject:
|
|
2654
|
+
subject: z5.string(),
|
|
2590
2655
|
/**
|
|
2591
2656
|
* 完整细节 / 验收标准(dsh `requiredText(description, 16384)`)。
|
|
2592
2657
|
* daluo 与 dsh 的差别:**必填性在工具层强制**(daluo 的输入校验统一在工具层,如 subject);
|
|
2593
2658
|
* 契约给缺省 `''` 以兼容加字段前的旧事件。
|
|
2594
2659
|
*/
|
|
2595
|
-
description:
|
|
2596
|
-
status:
|
|
2660
|
+
description: z5.string().default(""),
|
|
2661
|
+
status: z5.enum(["pending", "in_progress", "completed", "deleted"]),
|
|
2597
2662
|
/** 认领者名字(未认领缺省)。 */
|
|
2598
|
-
ownerName:
|
|
2663
|
+
ownerName: z5.string().optional(),
|
|
2599
2664
|
/** 依赖的任务 id:全部 completed 才可 claim(DAG 边)。 */
|
|
2600
|
-
blockedBy:
|
|
2665
|
+
blockedBy: z5.array(z5.string()),
|
|
2601
2666
|
/**
|
|
2602
2667
|
* 任务级**写作用域**(spec/agent-team.md 决策 16,对齐 dsh `writeScope`):
|
|
2603
2668
|
* 该任务计划修改的文件/目录(**规范化相对路径**:无前导 `/`、无双斜杠、无 `.`/`..` 段)。
|
|
2604
2669
|
* 用于并行成员改同一片文件时的**重叠告警**(按路径段前缀判定,advisory 不阻塞)。
|
|
2605
2670
|
* 演进加入:缺省 `[]`(旧事件不带该字段 → parse 后视为未声明)。
|
|
2606
2671
|
*/
|
|
2607
|
-
writeScopes:
|
|
2672
|
+
writeScopes: z5.array(z5.string()).default([]),
|
|
2608
2673
|
/**
|
|
2609
2674
|
* 任务**义务**(spec/council.md 决策 13):本任务声称「完成后必须能通过」的核验命令
|
|
2610
2675
|
* (如 `npm run check`)。完成时服务会拿**回执里的证据**逐条比对(跑过且 exitCode=0),
|
|
2611
2676
|
* 比对不齐 → 拒绝完成。声明在**任务上**(而非议会条目上)——它要可核验、要跟任务同生命周期。
|
|
2612
2677
|
*/
|
|
2613
|
-
obligations:
|
|
2678
|
+
obligations: z5.array(z5.string()).default([]),
|
|
2614
2679
|
/**
|
|
2615
2680
|
* CAS 版本,**从 1 起**(对齐 dsh `task-board.ts:62` 的 `revision: 1` 与
|
|
2616
2681
|
* `projection.ts:265` 的「must begin at revision 1」)——0 是「还不存在」的味道,
|
|
2617
2682
|
* 与「已建」区分开。
|
|
2618
2683
|
*/
|
|
2619
|
-
revision:
|
|
2684
|
+
revision: z5.number().int().positive()
|
|
2620
2685
|
});
|
|
2621
2686
|
TeamTaskUpdateSchema = BaseEventSchema.extend({
|
|
2622
|
-
type:
|
|
2623
|
-
teamId:
|
|
2687
|
+
type: z5.literal("team/task"),
|
|
2688
|
+
teamId: z5.string(),
|
|
2624
2689
|
task: TeamTaskSchema
|
|
2625
2690
|
});
|
|
2626
|
-
TaskEvidenceSchema =
|
|
2691
|
+
TaskEvidenceSchema = z5.object({
|
|
2627
2692
|
/** 跑过的核验命令(与任务 obligations 逐条比对)。 */
|
|
2628
|
-
command:
|
|
2629
|
-
exitCode:
|
|
2693
|
+
command: z5.string().min(1),
|
|
2694
|
+
exitCode: z5.number().int(),
|
|
2630
2695
|
/** 输出摘要(可选;大输出留成员会话,不灌进事件)。 */
|
|
2631
|
-
output:
|
|
2696
|
+
output: z5.string().optional()
|
|
2632
2697
|
});
|
|
2633
|
-
TeamTaskResultSchema =
|
|
2634
|
-
taskId:
|
|
2635
|
-
status:
|
|
2698
|
+
TeamTaskResultSchema = z5.object({
|
|
2699
|
+
taskId: z5.string().min(1),
|
|
2700
|
+
status: z5.enum(["completed", "failed", "interrupted"]),
|
|
2636
2701
|
/** 结论文本(交付面——给 Lead/下一环读,不是全文)。 */
|
|
2637
|
-
summary:
|
|
2638
|
-
evidence:
|
|
2702
|
+
summary: z5.string(),
|
|
2703
|
+
evidence: z5.array(TaskEvidenceSchema).default([]),
|
|
2639
2704
|
/** 度量(对齐 claudecode:工具次数 / 耗时 / token)。 */
|
|
2640
|
-
metrics:
|
|
2641
|
-
toolUses:
|
|
2642
|
-
durationMs:
|
|
2643
|
-
tokens:
|
|
2705
|
+
metrics: z5.object({
|
|
2706
|
+
toolUses: z5.number().int().nonnegative(),
|
|
2707
|
+
durationMs: z5.number().int().nonnegative(),
|
|
2708
|
+
tokens: z5.number().int().nonnegative().optional()
|
|
2644
2709
|
}).optional(),
|
|
2645
2710
|
/** 失败原因(status='failed' 时有值)。 */
|
|
2646
|
-
error:
|
|
2711
|
+
error: z5.string().optional(),
|
|
2647
2712
|
/** 谁报的(成员身份 id,决策 20;Lead 为 `lead`)。 */
|
|
2648
|
-
by:
|
|
2713
|
+
by: z5.string().min(1)
|
|
2649
2714
|
});
|
|
2650
2715
|
TeamTaskResultEventSchema = BaseEventSchema.extend({
|
|
2651
|
-
type:
|
|
2652
|
-
teamId:
|
|
2716
|
+
type: z5.literal("team/task/result"),
|
|
2717
|
+
teamId: z5.string(),
|
|
2653
2718
|
result: TeamTaskResultSchema
|
|
2654
2719
|
});
|
|
2655
2720
|
SessionRenamedSchema = BaseEventSchema.extend({
|
|
2656
|
-
type:
|
|
2657
|
-
title:
|
|
2721
|
+
type: z5.literal("session/renamed"),
|
|
2722
|
+
title: z5.string().min(1),
|
|
2658
2723
|
/**
|
|
2659
2724
|
* 这个名字**谁起的**(`G3-41`)。缺省 = `'user'`(旧日志零迁移)——这一点很要紧:
|
|
2660
2725
|
* 「用户起的名字**永不被覆盖**」靠它判;把自动标题也写成不带标识的一条,日后就没法区分,
|
|
2661
2726
|
* 自动生成会把用户亲手改的名字覆盖掉。
|
|
2662
2727
|
*/
|
|
2663
|
-
source:
|
|
2728
|
+
source: z5.enum(["user", "auto"]).optional()
|
|
2664
2729
|
});
|
|
2665
2730
|
SessionModelChangedSchema = BaseEventSchema.extend({
|
|
2666
|
-
type:
|
|
2667
|
-
model:
|
|
2731
|
+
type: z5.literal("session/model-changed"),
|
|
2732
|
+
model: z5.string().min(1),
|
|
2668
2733
|
/** 提供方 id(`user-config` 的 `ProviderEntry.id`):**只存引用,不存 baseUrl/密钥**(会话日志可被分享/导入)。缺省 = 沿用当前提供方(老日志原样可读)。 */
|
|
2669
|
-
provider:
|
|
2734
|
+
provider: z5.string().min(1).optional()
|
|
2670
2735
|
});
|
|
2671
2736
|
WorkingDirectoryChangedSchema = BaseEventSchema.extend({
|
|
2672
|
-
type:
|
|
2673
|
-
cwd:
|
|
2737
|
+
type: z5.literal("working-directory/change"),
|
|
2738
|
+
cwd: z5.string().min(1)
|
|
2674
2739
|
});
|
|
2675
2740
|
SessionArchivedSchema = BaseEventSchema.extend({
|
|
2676
|
-
type:
|
|
2677
|
-
archived:
|
|
2741
|
+
type: z5.literal("session/archived"),
|
|
2742
|
+
archived: z5.boolean()
|
|
2678
2743
|
});
|
|
2679
2744
|
MAX_LABELS = 32;
|
|
2680
2745
|
MAX_LABEL_KEY_CHARS = 64;
|
|
2681
2746
|
MAX_LABEL_VALUE_CHARS = 256;
|
|
2682
2747
|
SessionLabelsSchema = BaseEventSchema.extend({
|
|
2683
|
-
type:
|
|
2748
|
+
type: z5.literal("session/labels"),
|
|
2684
2749
|
/** 关联标签(如 `{ record: 'ZHBD-0001' }`)。**整体替换**(last-wins);空对象 = 清空。 */
|
|
2685
|
-
labels:
|
|
2750
|
+
labels: z5.record(z5.string().max(MAX_LABEL_KEY_CHARS), z5.string().max(MAX_LABEL_VALUE_CHARS)).refine((l) => Object.keys(l).length <= MAX_LABELS, { message: `\u6807\u7B7E\u6700\u591A ${MAX_LABELS} \u6761` })
|
|
2686
2751
|
});
|
|
2687
2752
|
CommandRunSchema = BaseEventSchema.extend({
|
|
2688
|
-
type:
|
|
2753
|
+
type: z5.literal("command/run"),
|
|
2689
2754
|
/** 配对 id(`c-<uuid>`)——与 command/done 一一对应。 */
|
|
2690
|
-
commandId:
|
|
2691
|
-
name:
|
|
2755
|
+
commandId: z5.string(),
|
|
2756
|
+
name: z5.string(),
|
|
2692
2757
|
/** recordArgs:false 的命令不落此字段(敏感命令的面:不落日志 ≠ 执行时看不到)。 */
|
|
2693
|
-
args:
|
|
2758
|
+
args: z5.string().optional(),
|
|
2694
2759
|
/** 发起方(v1 只有用户输入行——模型侧发起是未来扩展位)。 */
|
|
2695
|
-
source:
|
|
2760
|
+
source: z5.literal("user")
|
|
2696
2761
|
});
|
|
2697
2762
|
CommandDoneSchema = BaseEventSchema.extend({
|
|
2698
|
-
type:
|
|
2699
|
-
commandId:
|
|
2700
|
-
outcome:
|
|
2701
|
-
kind:
|
|
2702
|
-
message:
|
|
2763
|
+
type: z5.literal("command/done"),
|
|
2764
|
+
commandId: z5.string(),
|
|
2765
|
+
outcome: z5.object({
|
|
2766
|
+
kind: z5.enum(["ok", "error"]),
|
|
2767
|
+
message: z5.string().optional()
|
|
2703
2768
|
})
|
|
2704
2769
|
});
|
|
2705
2770
|
InboxQueuedSchema = BaseEventSchema.extend({
|
|
2706
|
-
type:
|
|
2707
|
-
id:
|
|
2708
|
-
content:
|
|
2771
|
+
type: z5.literal("inbox/queued"),
|
|
2772
|
+
id: z5.string(),
|
|
2773
|
+
content: z5.string(),
|
|
2709
2774
|
/** `steering` = 下一轮 request 就带上(mid-turn steer);`queued` = 这一轮跑完当下一回合的输入。 */
|
|
2710
|
-
placement:
|
|
2775
|
+
placement: z5.enum(["queued", "steering"])
|
|
2711
2776
|
});
|
|
2712
2777
|
InboxEditedSchema = BaseEventSchema.extend({
|
|
2713
|
-
type:
|
|
2714
|
-
id:
|
|
2715
|
-
content:
|
|
2778
|
+
type: z5.literal("inbox/edited"),
|
|
2779
|
+
id: z5.string(),
|
|
2780
|
+
content: z5.string()
|
|
2716
2781
|
});
|
|
2717
2782
|
InboxRemovedSchema = BaseEventSchema.extend({
|
|
2718
|
-
type:
|
|
2719
|
-
id:
|
|
2783
|
+
type: z5.literal("inbox/removed"),
|
|
2784
|
+
id: z5.string()
|
|
2720
2785
|
});
|
|
2721
2786
|
InboxRequeuedSchema = BaseEventSchema.extend({
|
|
2722
|
-
type:
|
|
2723
|
-
id:
|
|
2724
|
-
placement:
|
|
2787
|
+
type: z5.literal("inbox/requeued"),
|
|
2788
|
+
id: z5.string(),
|
|
2789
|
+
placement: z5.enum(["queued", "steering"])
|
|
2725
2790
|
});
|
|
2726
|
-
AskOriginSchema =
|
|
2727
|
-
kind:
|
|
2791
|
+
AskOriginSchema = z5.object({
|
|
2792
|
+
kind: z5.enum(["subagent", "workflow-node", "teammate"]),
|
|
2728
2793
|
/** 子运行的身份:subagentId / `${workflowId}/${nodeId}` / 成员名。 */
|
|
2729
|
-
agentId:
|
|
2794
|
+
agentId: z5.string(),
|
|
2730
2795
|
/** 角色名(R9);角色没声明就不带。 */
|
|
2731
|
-
agentType:
|
|
2796
|
+
agentType: z5.string().optional(),
|
|
2732
2797
|
/** 派它干的那句话(子代理 task / workflow node task)。 */
|
|
2733
|
-
description:
|
|
2798
|
+
description: z5.string().optional(),
|
|
2734
2799
|
/** 子运行自己的 sessionId(通常等于 `agentId`;仍显式写,让消费方读它而不必反推)。 */
|
|
2735
|
-
childSessionId:
|
|
2736
|
-
parentSessionId:
|
|
2800
|
+
childSessionId: z5.string(),
|
|
2801
|
+
parentSessionId: z5.string(),
|
|
2737
2802
|
/** **哪一次调用**派的(dispatch 注入的 `input.toolCallId`);拿不到就不带。 */
|
|
2738
|
-
parentToolCallId:
|
|
2803
|
+
parentToolCallId: z5.string().optional()
|
|
2739
2804
|
});
|
|
2740
2805
|
AskRequestedSchema = BaseEventSchema.extend({
|
|
2741
|
-
type:
|
|
2742
|
-
id:
|
|
2743
|
-
kind:
|
|
2744
|
-
question:
|
|
2806
|
+
type: z5.literal("ask/requested"),
|
|
2807
|
+
id: z5.string(),
|
|
2808
|
+
kind: z5.enum(["permission", "question"]),
|
|
2809
|
+
question: z5.string(),
|
|
2745
2810
|
/** 结构化提问的候选(kind=question 时有意义)。 */
|
|
2746
|
-
options:
|
|
2811
|
+
options: z5.array(z5.object({ label: z5.string(), description: z5.string().optional() })).optional(),
|
|
2747
2812
|
/**
|
|
2748
2813
|
* 权限确认的选项(kind=permission 时有意义;`spec/permission-response.md` 决策 1)。
|
|
2749
2814
|
* **与上面的 `options` 是两个字段**(不是同一个字段的两种形状):旧 `options` 的语义与判据一字不动,
|
|
2750
2815
|
* 而两档的选项形状确实不同(提问是候选文案,确认是**带效果的按钮**)——
|
|
2751
2816
|
* 挤进一个 union 会让 permission 的选项以 question 的形状 parse 成功、静默丢掉 `effect`。
|
|
2752
2817
|
*/
|
|
2753
|
-
permissionOptions:
|
|
2818
|
+
permissionOptions: z5.array(PermissionOptionSchema).optional(),
|
|
2754
2819
|
/** 这次确认是否允许「改后批准」(应答带改写后的输入,且必须重过 policy)。 */
|
|
2755
|
-
allowModify:
|
|
2820
|
+
allowModify: z5.boolean().optional(),
|
|
2756
2821
|
/**
|
|
2757
2822
|
* 被确认的**工具输入**(kind=permission 时有意义;`spec/permission-response.md`)。
|
|
2758
2823
|
*
|
|
@@ -2760,14 +2825,14 @@ var init_schema = __esm({
|
|
|
2760
2825
|
* **早就把同一份 input 落在同一个日志文件里**了。而没有它,呈现方**没法预填「要改什么」**,
|
|
2761
2826
|
* 「改后批准」在 UI 上就只剩一个让人手写 JSON 的输入框。
|
|
2762
2827
|
*/
|
|
2763
|
-
input:
|
|
2764
|
-
multiSelect:
|
|
2828
|
+
input: z5.unknown().optional(),
|
|
2829
|
+
multiSelect: z5.boolean().optional(),
|
|
2765
2830
|
/**
|
|
2766
2831
|
* 这次确认的风险档(kind=permission 时有意义;`spec/permission-response.md` 演进 S-03)——
|
|
2767
2832
|
* **请求方声明**(闭集逐字对齐参考 `zcode-protocol/index.ts:930`)。呈现方按它分层、
|
|
2768
2833
|
* 审计按它检索;旧事件没有它 = 「请求方没声明」,按无档呈现(**不猜**)。
|
|
2769
2834
|
*/
|
|
2770
|
-
riskLevel:
|
|
2835
|
+
riskLevel: z5.enum(["low", "medium", "high", "critical"]).optional(),
|
|
2771
2836
|
/**
|
|
2772
2837
|
* 这次确认的**来源**(`spec/permission-provenance.md`):子代理 / workflow node / 团队成员发起的
|
|
2773
2838
|
* 请求带它。旧事件没有它 = 主代理自己的询问(**不猜**——「没声明来源」与「来源非法」是两种失败,
|
|
@@ -2775,64 +2840,64 @@ var init_schema = __esm({
|
|
|
2775
2840
|
*/
|
|
2776
2841
|
origin: AskOriginSchema.optional(),
|
|
2777
2842
|
/** 触发它的工具名(呈现时用来标「批准什么」)。 */
|
|
2778
|
-
toolName:
|
|
2843
|
+
toolName: z5.string().optional(),
|
|
2779
2844
|
/** 等待截止(ISO);超时即按拒绝收尾(fail-safe 不破)。 */
|
|
2780
|
-
expiresAt:
|
|
2845
|
+
expiresAt: z5.string().optional()
|
|
2781
2846
|
});
|
|
2782
2847
|
AskAnsweredSchema = BaseEventSchema.extend({
|
|
2783
|
-
type:
|
|
2784
|
-
id:
|
|
2848
|
+
type: z5.literal("ask/answered"),
|
|
2849
|
+
id: z5.string(),
|
|
2785
2850
|
/** kind=permission:是否放行。 */
|
|
2786
|
-
allow:
|
|
2851
|
+
allow: z5.boolean().optional(),
|
|
2787
2852
|
/**
|
|
2788
2853
|
* 回了**哪个按钮**(`ask/requested.permissionOptions` 里的 `optionId`;`spec/permission-response.md`)。
|
|
2789
2854
|
* 刻意用 `z.string()` 而不是同一份 enum:**认不出的 id 要在解析那一层拒**,
|
|
2790
2855
|
* 让 schema 拒会把整条已落盘事件判成违规(`asks.failures`),把「客户端答错了」记成「日志坏了」。
|
|
2791
2856
|
*/
|
|
2792
|
-
optionId:
|
|
2857
|
+
optionId: z5.string().optional(),
|
|
2793
2858
|
/**
|
|
2794
2859
|
* 改后批准:**改写后的输入**——审计要的就是它(「这次批准到底批了什么」)。
|
|
2795
2860
|
* 冲突命令的批准记录里能读到真跑的那条命令,靠的就是这个字段。
|
|
2796
2861
|
*/
|
|
2797
|
-
modifiedInput:
|
|
2862
|
+
modifiedInput: z5.unknown().optional(),
|
|
2798
2863
|
/** kind=question:自由文本答案 + 选中的 label。 */
|
|
2799
|
-
answer:
|
|
2800
|
-
selected:
|
|
2864
|
+
answer: z5.string().optional(),
|
|
2865
|
+
selected: z5.array(z5.string()).optional(),
|
|
2801
2866
|
/** 为什么结束:用户答 / `timeout`(有人等、等超了)/ `abandoned`(等的人已经没了,见 `session/stale-asks.ts`)/ 无通道。 */
|
|
2802
|
-
reason:
|
|
2867
|
+
reason: z5.enum(["user", "timeout", "abandoned"]).optional()
|
|
2803
2868
|
});
|
|
2804
2869
|
GoalClearedSchema = BaseEventSchema.extend({
|
|
2805
|
-
type:
|
|
2870
|
+
type: z5.literal("goal/cleared"),
|
|
2806
2871
|
/** 被清掉的那个目标 id(防「清错了目标」——fold 只在与当前目标一致时生效)。 */
|
|
2807
|
-
goalId:
|
|
2872
|
+
goalId: z5.string()
|
|
2808
2873
|
});
|
|
2809
2874
|
FeedbackRecordedSchema = BaseEventSchema.extend({
|
|
2810
|
-
type:
|
|
2811
|
-
id:
|
|
2875
|
+
type: z5.literal("feedback/recorded"),
|
|
2876
|
+
id: z5.string(),
|
|
2812
2877
|
/** message = 针对某一条消息(要 messageSeq + rating);session = 针对整会话(要 note 或 category)。 */
|
|
2813
|
-
kind:
|
|
2814
|
-
rating:
|
|
2878
|
+
kind: z5.enum(["message", "session"]),
|
|
2879
|
+
rating: z5.enum(["positive", "negative"]).optional(),
|
|
2815
2880
|
/** 指向 `message/user|assistant` 的 seq(kind=message 时必填——值校验在 fold/助手层)。 */
|
|
2816
|
-
messageSeq:
|
|
2817
|
-
category:
|
|
2818
|
-
note:
|
|
2881
|
+
messageSeq: z5.number().int().optional(),
|
|
2882
|
+
category: z5.string().optional(),
|
|
2883
|
+
note: z5.string().optional()
|
|
2819
2884
|
});
|
|
2820
2885
|
FeedbackRetractedSchema = BaseEventSchema.extend({
|
|
2821
|
-
type:
|
|
2822
|
-
id:
|
|
2886
|
+
type: z5.literal("feedback/retracted"),
|
|
2887
|
+
id: z5.string()
|
|
2823
2888
|
});
|
|
2824
2889
|
SessionBranchSummarySchema = BaseEventSchema.extend({
|
|
2825
|
-
type:
|
|
2890
|
+
type: z5.literal("session/branch-summary"),
|
|
2826
2891
|
/** 摘要正文。空是写入方 bug —— schema 层 fail loud(同 `session/renamed` 的 title 非空)。 */
|
|
2827
|
-
summary:
|
|
2892
|
+
summary: z5.string().min(1),
|
|
2828
2893
|
/** 被放弃路径的出处:源会话 id / 源日志文件名 / **从哪个 seq 之后开始**(= fork 的切割点)。 */
|
|
2829
|
-
abandoned:
|
|
2830
|
-
sessionId:
|
|
2831
|
-
file:
|
|
2832
|
-
fromSeq:
|
|
2894
|
+
abandoned: z5.object({
|
|
2895
|
+
sessionId: z5.string(),
|
|
2896
|
+
file: z5.string(),
|
|
2897
|
+
fromSeq: z5.number().int().positive()
|
|
2833
2898
|
})
|
|
2834
2899
|
});
|
|
2835
|
-
SessionEvent =
|
|
2900
|
+
SessionEvent = z5.discriminatedUnion("type", [
|
|
2836
2901
|
SessionCreatedSchema,
|
|
2837
2902
|
SessionImportedSchema,
|
|
2838
2903
|
/** 分支摘要(演进,spec/session-tree.md 决策 2):fork 时带过来的「被放弃路径」摘要。 */
|
|
@@ -2855,6 +2920,7 @@ var init_schema = __esm({
|
|
|
2855
2920
|
PolicyProfileSchema,
|
|
2856
2921
|
PromptSystemSchema,
|
|
2857
2922
|
PromptCacheBreakSchema,
|
|
2923
|
+
ContextReportSchema,
|
|
2858
2924
|
MemoryExtractSchema,
|
|
2859
2925
|
CompactionReclaimSchema,
|
|
2860
2926
|
SubagentStartSchema,
|
|
@@ -4143,7 +4209,7 @@ var init_scrub = __esm({
|
|
|
4143
4209
|
// packages/core/src/memory/memory.ts
|
|
4144
4210
|
import { mkdir as mkdir3, open as open3, stat as stat3, unlink as unlink3 } from "node:fs/promises";
|
|
4145
4211
|
import { dirname as dirname3 } from "node:path";
|
|
4146
|
-
import { z as
|
|
4212
|
+
import { z as z6 } from "zod";
|
|
4147
4213
|
function describeOrigin(origin) {
|
|
4148
4214
|
if (origin === void 0) return "\u65E0\u6765\u6E90";
|
|
4149
4215
|
if (origin.kind === "user") return "\u7528\u6237\u5F53\u9762\u8981\u6C42";
|
|
@@ -4311,41 +4377,41 @@ var init_memory = __esm({
|
|
|
4311
4377
|
DEFAULT_MEMORY_SOURCE = "manual";
|
|
4312
4378
|
USER_ORIGIN = { kind: "user" };
|
|
4313
4379
|
EXTERNAL_ORIGIN = { kind: "external" };
|
|
4314
|
-
MemoryOriginSchema =
|
|
4315
|
-
|
|
4316
|
-
|
|
4380
|
+
MemoryOriginSchema = z6.discriminatedUnion("kind", [
|
|
4381
|
+
z6.object({ kind: z6.literal("session"), sessionId: z6.string().min(1), seq: z6.number().int().positive() }),
|
|
4382
|
+
z6.object({ kind: z6.literal("user") }),
|
|
4317
4383
|
// 外部客户端转达(无会话上下文,如 MCP 入口):**不是**「用户当面要求」,单独一种来源(自审修正)
|
|
4318
|
-
|
|
4384
|
+
z6.object({ kind: z6.literal("external") })
|
|
4319
4385
|
]);
|
|
4320
4386
|
\u673A\u5668\u6E20\u9053 = ["auto", "dream", "consolidation"];
|
|
4321
|
-
MemoryWriteSchema =
|
|
4322
|
-
seq:
|
|
4323
|
-
ts:
|
|
4324
|
-
type:
|
|
4325
|
-
key:
|
|
4326
|
-
content:
|
|
4327
|
-
memoryType:
|
|
4328
|
-
confidence:
|
|
4329
|
-
source:
|
|
4330
|
-
validFrom:
|
|
4331
|
-
validTo:
|
|
4332
|
-
supersededBy:
|
|
4333
|
-
invalidatedAt:
|
|
4334
|
-
invalidatedReason:
|
|
4387
|
+
MemoryWriteSchema = z6.object({
|
|
4388
|
+
seq: z6.number().int().positive(),
|
|
4389
|
+
ts: z6.string(),
|
|
4390
|
+
type: z6.literal("memory/write"),
|
|
4391
|
+
key: z6.string().min(1, "memory/write key \u4E0D\u80FD\u4E3A\u7A7A"),
|
|
4392
|
+
content: z6.string().min(1, "memory/write content \u4E0D\u80FD\u4E3A\u7A7A"),
|
|
4393
|
+
memoryType: z6.enum(MEMORY_TYPES).optional(),
|
|
4394
|
+
confidence: z6.number().min(0).max(1).optional(),
|
|
4395
|
+
source: z6.enum(MEMORY_SOURCES).optional(),
|
|
4396
|
+
validFrom: z6.number().optional(),
|
|
4397
|
+
validTo: z6.number().optional(),
|
|
4398
|
+
supersededBy: z6.string().optional(),
|
|
4399
|
+
invalidatedAt: z6.number().optional(),
|
|
4400
|
+
invalidatedReason: z6.enum(["resolved", "forgotten"]).optional(),
|
|
4335
4401
|
/** 来源(G4-19):可选 ⇒ 既有事件零迁移;**写入 API 必填**(闸在 `remember` 里)。 */
|
|
4336
4402
|
origin: MemoryOriginSchema.optional()
|
|
4337
4403
|
});
|
|
4338
|
-
MemoryInvalidateSchema =
|
|
4339
|
-
seq:
|
|
4340
|
-
ts:
|
|
4341
|
-
type:
|
|
4342
|
-
key:
|
|
4343
|
-
reason:
|
|
4404
|
+
MemoryInvalidateSchema = z6.object({
|
|
4405
|
+
seq: z6.number().int().positive(),
|
|
4406
|
+
ts: z6.string(),
|
|
4407
|
+
type: z6.literal("memory/invalidate"),
|
|
4408
|
+
key: z6.string().min(1, "memory/invalidate key \u4E0D\u80FD\u4E3A\u7A7A"),
|
|
4409
|
+
reason: z6.enum(["resolved", "forgotten"]),
|
|
4344
4410
|
/** 取代链(可选):这条记忆被哪个 key 取代——`isCurrentFact` 据此把旧叶子判非 current。 */
|
|
4345
|
-
supersededBy:
|
|
4346
|
-
invalidatedAt:
|
|
4411
|
+
supersededBy: z6.string().min(1).optional(),
|
|
4412
|
+
invalidatedAt: z6.number()
|
|
4347
4413
|
});
|
|
4348
|
-
MemoryEvent =
|
|
4414
|
+
MemoryEvent = z6.discriminatedUnion("type", [MemoryWriteSchema, MemoryInvalidateSchema]);
|
|
4349
4415
|
MAX_MEMORY_CONTENT_CHARS = 2e3;
|
|
4350
4416
|
\u9501\u540E\u7F00 = ".lock";
|
|
4351
4417
|
\u9648\u65E7\u9501Ms = 1e4;
|
|
@@ -4995,8 +5061,9 @@ var init_search_index = __esm({
|
|
|
4995
5061
|
});
|
|
4996
5062
|
|
|
4997
5063
|
// packages/core/src/session/project-paths.ts
|
|
5064
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
4998
5065
|
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2 } from "node:fs";
|
|
4999
|
-
import { join as join5 } from "node:path";
|
|
5066
|
+
import { basename as basename4, isAbsolute, join as join5 } from "node:path";
|
|
5000
5067
|
function daluoDirOf(cwd, opts = {}) {
|
|
5001
5068
|
const dir = join5(cwd, ".daluo");
|
|
5002
5069
|
if (opts.create !== false) mkdirSync(dir, { recursive: true });
|
|
@@ -5067,8 +5134,19 @@ function toolResultsDirOf(cwd, opts = {}) {
|
|
|
5067
5134
|
if (opts.create !== false) mkdirSync(dir, { recursive: true });
|
|
5068
5135
|
return dir;
|
|
5069
5136
|
}
|
|
5070
|
-
function
|
|
5071
|
-
|
|
5137
|
+
function resolveSnapshotDir(env) {
|
|
5138
|
+
const raw = (env[SNAPSHOT_DIR_ENV] ?? "").trim();
|
|
5139
|
+
return raw === "" ? void 0 : raw;
|
|
5140
|
+
}
|
|
5141
|
+
function workspaceKeyOf(cwd) {
|
|
5142
|
+
const \u7EDD\u5BF9 = isAbsolute(cwd) ? cwd : join5(process.cwd(), cwd);
|
|
5143
|
+
const \u540D = basename4(\u7EDD\u5BF9).replace(/[^\w.-]+/g, "-") || "workspace";
|
|
5144
|
+
return `${\u540D}-${createHash2("sha1").update(\u7EDD\u5BF9).digest("hex").slice(0, 8)}`;
|
|
5145
|
+
}
|
|
5146
|
+
function shadowGitDirOf(cwd, snapshotDir) {
|
|
5147
|
+
if (snapshotDir === void 0 || snapshotDir === "") return join5(cwd, ".daluo", "snapshots", "shadow.git");
|
|
5148
|
+
const \u6839 = isAbsolute(snapshotDir) ? snapshotDir : join5(cwd, snapshotDir);
|
|
5149
|
+
return join5(\u6839, workspaceKeyOf(cwd), "shadow.git");
|
|
5072
5150
|
}
|
|
5073
5151
|
function worktreesDirOf(cwd) {
|
|
5074
5152
|
return join5(cwd, ".daluo", "worktrees");
|
|
@@ -5081,6 +5159,7 @@ function resolveSessionIndex(cwd, env) {
|
|
|
5081
5159
|
}
|
|
5082
5160
|
return new SessionIndex(sessionIndexFileOf(cwd));
|
|
5083
5161
|
}
|
|
5162
|
+
var SNAPSHOT_DIR_ENV;
|
|
5084
5163
|
var init_project_paths = __esm({
|
|
5085
5164
|
"packages/core/src/session/project-paths.ts"() {
|
|
5086
5165
|
"use strict";
|
|
@@ -5089,6 +5168,7 @@ var init_project_paths = __esm({
|
|
|
5089
5168
|
init_authorization();
|
|
5090
5169
|
init_memory();
|
|
5091
5170
|
init_search_index();
|
|
5171
|
+
SNAPSHOT_DIR_ENV = "DALUO_SNAPSHOT_DIR";
|
|
5092
5172
|
}
|
|
5093
5173
|
});
|
|
5094
5174
|
|
|
@@ -5206,6 +5286,13 @@ var init_settings_schema = __esm({
|
|
|
5206
5286
|
\u679A\u4E3E: ["on", "off"],
|
|
5207
5287
|
\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
5288
|
},
|
|
5289
|
+
// ---- LLM(spec/llm-transport.md 演进「response_format 开关」;**不进项目级白名单**)----
|
|
5290
|
+
{
|
|
5291
|
+
\u952E: "llm.responseFormat",
|
|
5292
|
+
\u7C7B\u578B: "enum",
|
|
5293
|
+
\u679A\u4E3E: ["off", "structured", "always"],
|
|
5294
|
+
\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"
|
|
5295
|
+
},
|
|
5209
5296
|
// ---- 授权 / 记忆 ----
|
|
5210
5297
|
{
|
|
5211
5298
|
\u952E: "permission.readRoots",
|
|
@@ -5354,7 +5441,15 @@ function \u9879\u76EE\u7EA7\u5FFD\u7565\u63D0\u793A(\u88AB\u5FFD\u75652) {
|
|
|
5354
5441
|
const \u952E = \u88AB\u5FFD\u75652.join(" / ");
|
|
5355
5442
|
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
5443
|
}
|
|
5357
|
-
|
|
5444
|
+
function \u9876\u5C42\u9519\u4F4D\u952E(settings) {
|
|
5445
|
+
return Object.keys(settings.extra).filter((\u952E) => \u8BBE\u7F6E\u767B\u8BB0\u952E\u96C6.has(\u952E)).sort();
|
|
5446
|
+
}
|
|
5447
|
+
function \u9876\u5C42\u9519\u4F4D\u63D0\u793A(settings) {
|
|
5448
|
+
const \u952Es = \u9876\u5C42\u9519\u4F4D\u952E(settings);
|
|
5449
|
+
if (\u952Es.length === 0) return void 0;
|
|
5450
|
+
return `settings.json \u91CC\u6709 ${\u952Es.length} \u4E2A\u952E\u5199\u5728\u4E86\u9876\u5C42\u3001\u4E0D\u4F1A\u751F\u6548\uFF1A${\u952Es.join(" / ")}\uFF08\u9876\u5C42\u53EA\u8BA4 version \u4E0E values\uFF0C\u8BBE\u7F6E\u8981\u5199\u8FDB values \u4E0B\uFF1A{"version": 1, "values": {"permission.rules": [...]}}\u2014\u2014\u5168\u8868\u89C1 spec/settings.md\uFF09`;
|
|
5451
|
+
}
|
|
5452
|
+
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, \u8BBE\u7F6E\u767B\u8BB0\u952E\u96C6;
|
|
5358
5453
|
var init_settings = __esm({
|
|
5359
5454
|
"packages/core/src/settings/settings.ts"() {
|
|
5360
5455
|
"use strict";
|
|
@@ -5385,11 +5480,13 @@ var init_settings = __esm({
|
|
|
5385
5480
|
SETTING_COMPACTION_RESERVE_OUTPUT_TOKENS = "compaction.reserveOutputTokens";
|
|
5386
5481
|
SETTING_COMPACTION_BUFFER_TOKENS = "compaction.bufferTokens";
|
|
5387
5482
|
SETTING_COMPACTION_LLM_SUMMARY = "compaction.llmSummary";
|
|
5483
|
+
SETTING_LLM_RESPONSE_FORMAT = "llm.responseFormat";
|
|
5388
5484
|
COMPACTION_KEEP_MESSAGES_MIN = 3;
|
|
5389
5485
|
COMPACTION_TOKENS_MIN = 1e3;
|
|
5390
5486
|
UI_FONT_SIZE_MIN = 12;
|
|
5391
5487
|
UI_FONT_SIZE_MAX = 18;
|
|
5392
5488
|
UI_FONT_SIZE_DEFAULT = 14;
|
|
5489
|
+
\u8BBE\u7F6E\u767B\u8BB0\u952E\u96C6 = new Set(\u8BBE\u7F6E\u9879\u4EEC.map((\u9879) => \u9879.\u952E));
|
|
5393
5490
|
}
|
|
5394
5491
|
});
|
|
5395
5492
|
|
|
@@ -6613,7 +6710,7 @@ var init_sanitize = __esm({
|
|
|
6613
6710
|
// packages/core/src/terminal/rc.ts
|
|
6614
6711
|
import { mkdtemp, writeFile as writeFile2 } from "node:fs/promises";
|
|
6615
6712
|
import { homedir as homedir2, tmpdir as tmpdir2 } from "node:os";
|
|
6616
|
-
import { basename as
|
|
6713
|
+
import { basename as basename5, join as join7 } from "node:path";
|
|
6617
6714
|
function markerSnippet(dialect, pty = false) {
|
|
6618
6715
|
const printf = `printf '\\033]${PROMPT_MARKER_PREFIX}\\007'`;
|
|
6619
6716
|
if (dialect === "zsh") {
|
|
@@ -6651,7 +6748,7 @@ function rcContent(input) {
|
|
|
6651
6748
|
async function prepareShellLaunch(input) {
|
|
6652
6749
|
const platform = input.platform ?? process.platform;
|
|
6653
6750
|
const \u58F0\u660E = (input.shell ?? (typeof input.env.SHELL === "string" ? input.env.SHELL : "")).replace(/\/+$/, "");
|
|
6654
|
-
const \u58F0\u660E\u7684 =
|
|
6751
|
+
const \u58F0\u660E\u7684 = basename5(\u58F0\u660E);
|
|
6655
6752
|
const dialect = \u58F0\u660E\u7684 === "zsh" ? "zsh" : "bash";
|
|
6656
6753
|
const shell = platform === "win32" ? "bash.exe" : \u58F0\u660E.startsWith("/") ? \u58F0\u660E : \u58F0\u660E\u7684 === "zsh" || \u58F0\u660E\u7684 === "bash" ? `/bin/${\u58F0\u660E\u7684}` : "/bin/bash";
|
|
6657
6754
|
const home = input.env.HOME ?? homedir2();
|
|
@@ -7381,9 +7478,9 @@ var init_team_write_scope = __esm({
|
|
|
7381
7478
|
});
|
|
7382
7479
|
|
|
7383
7480
|
// packages/core/src/agent/content-hash.ts
|
|
7384
|
-
import { createHash as
|
|
7481
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
7385
7482
|
function fileHash(content) {
|
|
7386
|
-
return
|
|
7483
|
+
return createHash3("sha256").update(content).digest("hex").slice(0, 16);
|
|
7387
7484
|
}
|
|
7388
7485
|
var init_content_hash = __esm({
|
|
7389
7486
|
"packages/core/src/agent/content-hash.ts"() {
|
|
@@ -7789,8 +7886,11 @@ function bufferFromEnv(env) {
|
|
|
7789
7886
|
}
|
|
7790
7887
|
return n;
|
|
7791
7888
|
}
|
|
7889
|
+
function contextWindowOf(budget) {
|
|
7890
|
+
return budget.contextWindowTokens ?? DEFAULT_CONTEXT_WINDOW_TOKENS;
|
|
7891
|
+
}
|
|
7792
7892
|
function contextThresholdTokens(budget) {
|
|
7793
|
-
const window = budget
|
|
7893
|
+
const window = contextWindowOf(budget);
|
|
7794
7894
|
const reserve = budget.reserveOutputTokens ?? 2e4;
|
|
7795
7895
|
const buffer = budget.bufferTokens ?? 13e3;
|
|
7796
7896
|
const effective = Math.max(window - reserve, 0);
|
|
@@ -8669,6 +8769,8 @@ function foldEvent(state, event) {
|
|
|
8669
8769
|
return state;
|
|
8670
8770
|
case "compaction/reclaim":
|
|
8671
8771
|
return state;
|
|
8772
|
+
case "context/report":
|
|
8773
|
+
return state;
|
|
8672
8774
|
case "prompt/cache-break":
|
|
8673
8775
|
return state;
|
|
8674
8776
|
case "subagent/start":
|
|
@@ -9145,7 +9247,7 @@ var init_branch_summary = __esm({
|
|
|
9145
9247
|
});
|
|
9146
9248
|
|
|
9147
9249
|
// packages/core/src/session/lifecycle.ts
|
|
9148
|
-
import { basename as
|
|
9250
|
+
import { basename as basename6 } from "node:path";
|
|
9149
9251
|
function nextSeq(log) {
|
|
9150
9252
|
return log.nextSeq();
|
|
9151
9253
|
}
|
|
@@ -9242,7 +9344,7 @@ async function summarizeUpToSession(opts) {
|
|
|
9242
9344
|
if (await fileIdentity(opts.newFile) !== void 0) {
|
|
9243
9345
|
throw new LifecycleUserError(`summarizeUpToSession: \u76EE\u6807\u6587\u4EF6 "${opts.newFile}" \u5DF2\u5B58\u5728\uFF08\u4E0D\u8986\u76D6\u65E2\u6709\u4F1A\u8BDD\uFF09`);
|
|
9244
9346
|
}
|
|
9245
|
-
const sessionId =
|
|
9347
|
+
const sessionId = basename6(opts.newFile).replace(/\.jsonl$/, "");
|
|
9246
9348
|
if (sessionId === "") throw new LifecycleUserError(`summarizeUpToSession: \u76EE\u6807\u6587\u4EF6\u540D\u65E0\u6CD5\u4F5C\u4E3A\u4F1A\u8BDD id\uFF1A${opts.newFile}`);
|
|
9247
9349
|
const shadowed = [];
|
|
9248
9350
|
for (const e of events) {
|
|
@@ -9262,7 +9364,7 @@ async function summarizeUpToSession(opts) {
|
|
|
9262
9364
|
summary,
|
|
9263
9365
|
keepMessages: 0,
|
|
9264
9366
|
shadowedToolCallIds: shadowed,
|
|
9265
|
-
summarizedSource: { sessionId: first.sessionId, file:
|
|
9367
|
+
summarizedSource: { sessionId: first.sessionId, file: basename6(opts.sourceFile), upToSeq: opts.upToSeq }
|
|
9266
9368
|
},
|
|
9267
9369
|
...tail
|
|
9268
9370
|
]);
|
|
@@ -9298,7 +9400,7 @@ async function forkSession(opts) {
|
|
|
9298
9400
|
if (await fileIdentity(opts.newFile) !== void 0) {
|
|
9299
9401
|
throw new LifecycleUserError(`forkSession: \u76EE\u6807\u6587\u4EF6 "${opts.newFile}" \u5DF2\u5B58\u5728\uFF08fork \u4E0D\u8986\u76D6\u65E2\u6709\u4F1A\u8BDD\uFF09`);
|
|
9300
9402
|
}
|
|
9301
|
-
const sessionId =
|
|
9403
|
+
const sessionId = basename6(opts.newFile).replace(/\.jsonl$/, "");
|
|
9302
9404
|
if (sessionId === "") {
|
|
9303
9405
|
throw new LifecycleUserError(`forkSession: \u76EE\u6807\u6587\u4EF6\u540D\u65E0\u6CD5\u4F5C\u4E3A\u4F1A\u8BDD id\uFF1A${opts.newFile}`);
|
|
9304
9406
|
}
|
|
@@ -9307,7 +9409,7 @@ async function forkSession(opts) {
|
|
|
9307
9409
|
seq: 1,
|
|
9308
9410
|
ts: opts.now ? opts.now() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
9309
9411
|
type: "session/created",
|
|
9310
|
-
forkedFrom: { file:
|
|
9412
|
+
forkedFrom: { file: basename6(opts.sourceFile), seq: atSeq, sessionId: first.sessionId }
|
|
9311
9413
|
};
|
|
9312
9414
|
const records = await loadRawRecords(opts.sourceFile);
|
|
9313
9415
|
const copied = records.filter((record) => {
|
|
@@ -9324,7 +9426,7 @@ async function forkSession(opts) {
|
|
|
9324
9426
|
ts: opts.now ? opts.now() : (/* @__PURE__ */ new Date()).toISOString(),
|
|
9325
9427
|
type: "session/branch-summary",
|
|
9326
9428
|
summary,
|
|
9327
|
-
abandoned: { sessionId: first.sessionId, file:
|
|
9429
|
+
abandoned: { sessionId: first.sessionId, file: basename6(opts.sourceFile), fromSeq: atSeq }
|
|
9328
9430
|
}] : [];
|
|
9329
9431
|
await appendEvents(opts.newFile, [created, ...copied, ...trailing]);
|
|
9330
9432
|
return EventLog.restore(opts.newFile);
|
|
@@ -9383,6 +9485,250 @@ var init_builtin_commands = __esm({
|
|
|
9383
9485
|
}
|
|
9384
9486
|
});
|
|
9385
9487
|
|
|
9488
|
+
// packages/core/src/workspace/keyed-serial.ts
|
|
9489
|
+
function byKey(key, \u4EFB\u52A1) {
|
|
9490
|
+
const \u524D\u4E00\u4E2A = \u94FE.get(key) ?? Promise.resolve();
|
|
9491
|
+
const \u672C\u6B21 = \u524D\u4E00\u4E2A.then(\u4EFB\u52A1, \u4EFB\u52A1);
|
|
9492
|
+
const \u5C3E\u5DF4 = \u672C\u6B21.then(
|
|
9493
|
+
() => void 0,
|
|
9494
|
+
() => void 0
|
|
9495
|
+
);
|
|
9496
|
+
\u94FE.set(key, \u5C3E\u5DF4);
|
|
9497
|
+
const \u56DE\u6536 = () => {
|
|
9498
|
+
if (\u94FE.get(key) === \u5C3E\u5DF4) \u94FE.delete(key);
|
|
9499
|
+
};
|
|
9500
|
+
void \u672C\u6B21.then(\u56DE\u6536, \u56DE\u6536);
|
|
9501
|
+
return \u672C\u6B21;
|
|
9502
|
+
}
|
|
9503
|
+
var \u94FE;
|
|
9504
|
+
var init_keyed_serial = __esm({
|
|
9505
|
+
"packages/core/src/workspace/keyed-serial.ts"() {
|
|
9506
|
+
"use strict";
|
|
9507
|
+
\u94FE = /* @__PURE__ */ new Map();
|
|
9508
|
+
}
|
|
9509
|
+
});
|
|
9510
|
+
|
|
9511
|
+
// packages/core/src/workspace/dir-size.ts
|
|
9512
|
+
import { readdir as readdir4, stat as stat6 } from "node:fs/promises";
|
|
9513
|
+
import { join as join9 } from "node:path";
|
|
9514
|
+
async function directoryBytes(dir) {
|
|
9515
|
+
let entries;
|
|
9516
|
+
try {
|
|
9517
|
+
entries = await readdir4(dir, { withFileTypes: true });
|
|
9518
|
+
} catch {
|
|
9519
|
+
return 0;
|
|
9520
|
+
}
|
|
9521
|
+
let total = 0;
|
|
9522
|
+
for (const entry of entries) {
|
|
9523
|
+
const path = join9(dir, entry.name);
|
|
9524
|
+
if (entry.isDirectory()) total += await directoryBytes(path);
|
|
9525
|
+
else if (entry.isFile()) {
|
|
9526
|
+
try {
|
|
9527
|
+
total += (await stat6(path)).size;
|
|
9528
|
+
} catch {
|
|
9529
|
+
}
|
|
9530
|
+
}
|
|
9531
|
+
}
|
|
9532
|
+
return total;
|
|
9533
|
+
}
|
|
9534
|
+
function formatBytes(n) {
|
|
9535
|
+
if (n < 1024) return `${n} B`;
|
|
9536
|
+
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
|
|
9537
|
+
if (n < 1024 * 1024 * 1024) return `${(n / 1024 / 1024).toFixed(1)} MB`;
|
|
9538
|
+
return `${(n / 1024 / 1024 / 1024).toFixed(1)} GB`;
|
|
9539
|
+
}
|
|
9540
|
+
var init_dir_size = __esm({
|
|
9541
|
+
"packages/core/src/workspace/dir-size.ts"() {
|
|
9542
|
+
"use strict";
|
|
9543
|
+
}
|
|
9544
|
+
});
|
|
9545
|
+
|
|
9546
|
+
// packages/core/src/workspace/snapshot.ts
|
|
9547
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
9548
|
+
import { mkdir as mkdir6, stat as stat7 } from "node:fs/promises";
|
|
9549
|
+
import { join as join10 } from "node:path";
|
|
9550
|
+
function checkpointLabelWithSeq(label, seq) {
|
|
9551
|
+
return `${label} #seq=${seq}`;
|
|
9552
|
+
}
|
|
9553
|
+
function checkpointSeqOf(label) {
|
|
9554
|
+
const m = /(?:^|\s)#seq=(\d+)\s*$/.exec(label);
|
|
9555
|
+
return m === null ? void 0 : Number(m[1]);
|
|
9556
|
+
}
|
|
9557
|
+
function checkpointLabelOf(label) {
|
|
9558
|
+
return label.replace(/\s+#seq=\d+\s*$/, "");
|
|
9559
|
+
}
|
|
9560
|
+
async function runGit(args, opts) {
|
|
9561
|
+
return new Promise((resolve16) => {
|
|
9562
|
+
execFile2(
|
|
9563
|
+
"git",
|
|
9564
|
+
[...args],
|
|
9565
|
+
{ cwd: opts.cwd, timeout: SNAPSHOT_GIT_TIMEOUT_MS, maxBuffer: 8 * 1024 * 1024, ...opts.env ? { env: opts.env } : {} },
|
|
9566
|
+
(error, stdout, stderr) => {
|
|
9567
|
+
try {
|
|
9568
|
+
resolve16({
|
|
9569
|
+
ok: error === null,
|
|
9570
|
+
stdout: String(stdout ?? ""),
|
|
9571
|
+
stderr: String(stderr ?? "") || (error === null ? "" : error.message)
|
|
9572
|
+
});
|
|
9573
|
+
} catch (unexpected) {
|
|
9574
|
+
resolve16({ ok: false, stdout: "", stderr: `git \u8C03\u7528\u5F02\u5E38\uFF1A${unexpected instanceof Error ? unexpected.message : String(unexpected)}` });
|
|
9575
|
+
}
|
|
9576
|
+
}
|
|
9577
|
+
);
|
|
9578
|
+
});
|
|
9579
|
+
}
|
|
9580
|
+
function \u5F71\u5B50\u76EE\u5F55(cwd, env) {
|
|
9581
|
+
return shadowGitDirOf(cwd, resolveSnapshotDir(env ?? process.env));
|
|
9582
|
+
}
|
|
9583
|
+
function shadowArgs(cwd, env, rest) {
|
|
9584
|
+
return [
|
|
9585
|
+
`--git-dir=${\u5F71\u5B50\u76EE\u5F55(cwd, env)}`,
|
|
9586
|
+
`--work-tree=${cwd}`,
|
|
9587
|
+
// 身份与环境隔离:不读用户 git config 的 hook/签名,也不因缺 user.name 而失败
|
|
9588
|
+
"-c",
|
|
9589
|
+
"user.name=daluo",
|
|
9590
|
+
"-c",
|
|
9591
|
+
"user.email=daluo@localhost",
|
|
9592
|
+
"-c",
|
|
9593
|
+
"commit.gpgsign=false",
|
|
9594
|
+
"-c",
|
|
9595
|
+
"core.hooksPath=/dev/null",
|
|
9596
|
+
...rest
|
|
9597
|
+
];
|
|
9598
|
+
}
|
|
9599
|
+
async function ensureShadowRepo(cwd, env) {
|
|
9600
|
+
try {
|
|
9601
|
+
await mkdir6(\u5F71\u5B50\u76EE\u5F55(cwd, env), { recursive: true });
|
|
9602
|
+
} catch (error) {
|
|
9603
|
+
return `\u65E0\u6CD5\u521B\u5EFA\u5F71\u5B50\u4ED3\u5E93\u76EE\u5F55\uFF1A${error instanceof Error ? error.message : String(error)}`;
|
|
9604
|
+
}
|
|
9605
|
+
const init = await runGit([`--git-dir=${\u5F71\u5B50\u76EE\u5F55(cwd, env)}`, "init", "--quiet"], { cwd, ...env ? { env } : {} });
|
|
9606
|
+
return init.ok ? void 0 : `git init \u5931\u8D25\uFF1A${init.stderr.trim()}`;
|
|
9607
|
+
}
|
|
9608
|
+
async function createCheckpointLocked(input) {
|
|
9609
|
+
const { cwd } = input;
|
|
9610
|
+
const label = input.seq === void 0 ? input.label : checkpointLabelWithSeq(input.label, input.seq);
|
|
9611
|
+
const env = input.env;
|
|
9612
|
+
const cap = input.maxFileBytes ?? SNAPSHOT_MAX_FILE_BYTES;
|
|
9613
|
+
if (input.paths !== void 0 && input.paths.length === 0) {
|
|
9614
|
+
return { ok: true, unchanged: true, files: 0 };
|
|
9615
|
+
}
|
|
9616
|
+
const repoProblem = await ensureShadowRepo(cwd, env);
|
|
9617
|
+
if (repoProblem !== void 0) return { ok: false, reason: repoProblem };
|
|
9618
|
+
const skipped = [];
|
|
9619
|
+
const scope = input.paths === void 0 || input.paths.length === 0 ? ["."] : [...input.paths];
|
|
9620
|
+
const listed = await runGit(
|
|
9621
|
+
shadowArgs(cwd, env, ["ls-files", "-o", "-m", "-z", "--exclude-standard", "--", ...scope, ":(exclude).daluo"]),
|
|
9622
|
+
{ cwd, ...env ? { env } : {} }
|
|
9623
|
+
);
|
|
9624
|
+
if (!listed.ok) return { ok: false, reason: `\u904D\u5386\u6587\u4EF6\u5931\u8D25\uFF1A${listed.stderr.trim()}` };
|
|
9625
|
+
const candidates = listed.stdout.split("\0").filter((p) => p !== "");
|
|
9626
|
+
const oversize = [];
|
|
9627
|
+
for (const path of candidates) {
|
|
9628
|
+
const size = await fileSizeBytes(join10(cwd, path));
|
|
9629
|
+
if (size !== void 0 && size > cap) {
|
|
9630
|
+
oversize.push(path);
|
|
9631
|
+
skipped.push({ path, reason: `${(size / 1024 / 1024).toFixed(1)} MB \u8D85\u8FC7\u4E0A\u9650 ${(cap / 1024 / 1024).toFixed(1)} MB` });
|
|
9632
|
+
}
|
|
9633
|
+
}
|
|
9634
|
+
const excludes = [...oversize.map((p) => `:(exclude)${p}`), ":(exclude).daluo"];
|
|
9635
|
+
const add = await runGit(shadowArgs(cwd, env, ["add", "-A", "--", ...scope, ...excludes]), { cwd, ...env ? { env } : {} });
|
|
9636
|
+
if (!add.ok) return { ok: false, reason: `git add \u5931\u8D25\uFF1A${add.stderr.trim()}`, ...skipped.length ? { skipped } : {} };
|
|
9637
|
+
const staged = await runGit(shadowArgs(cwd, env, ["diff", "--cached", "--name-only", "-z"]), { cwd, ...env ? { env } : {} });
|
|
9638
|
+
if (!staged.ok) return { ok: false, reason: `git diff \u5931\u8D25\uFF1A${staged.stderr.trim()}`, ...skipped.length ? { skipped } : {} };
|
|
9639
|
+
const stagedFiles = staged.stdout.split("\0").filter((p) => p !== "");
|
|
9640
|
+
if (stagedFiles.length === 0) {
|
|
9641
|
+
return { ok: true, unchanged: true, files: 0, ...skipped.length ? { skipped } : {} };
|
|
9642
|
+
}
|
|
9643
|
+
const commit2 = await runGit(shadowArgs(cwd, env, ["commit", "--quiet", "-m", label]), { cwd, ...env ? { env } : {} });
|
|
9644
|
+
if (!commit2.ok) return { ok: false, reason: `git commit \u5931\u8D25\uFF1A${commit2.stderr.trim()}`, ...skipped.length ? { skipped } : {} };
|
|
9645
|
+
const hash = await runGit(shadowArgs(cwd, env, ["rev-parse", "HEAD"]), { cwd, ...env ? { env } : {} });
|
|
9646
|
+
return {
|
|
9647
|
+
ok: true,
|
|
9648
|
+
...hash.ok ? { checkpoint: hash.stdout.trim() } : {},
|
|
9649
|
+
files: stagedFiles.length,
|
|
9650
|
+
...skipped.length ? { skipped } : {}
|
|
9651
|
+
};
|
|
9652
|
+
}
|
|
9653
|
+
async function snapshotCost(input) {
|
|
9654
|
+
const { cwd } = input;
|
|
9655
|
+
const env = input.env;
|
|
9656
|
+
const shadow = \u5F71\u5B50\u76EE\u5F55(cwd, env);
|
|
9657
|
+
const count = await runGit(
|
|
9658
|
+
[`--git-dir=${shadow}`, "rev-list", "--count", "HEAD"],
|
|
9659
|
+
{ cwd, ...env ? { env } : {} }
|
|
9660
|
+
);
|
|
9661
|
+
const bytes = await directoryBytes(shadow);
|
|
9662
|
+
if (!count.ok) {
|
|
9663
|
+
return { ok: false, checkpoints: 0, bytes, reason: count.stderr.trim() || "\u8FD8\u6CA1\u6709\u5FEB\u7167\uFF08\u5F71\u5B50\u4ED3\u5E93\u4E0D\u5B58\u5728\u6216\u6CA1\u6709\u63D0\u4EA4\uFF09" };
|
|
9664
|
+
}
|
|
9665
|
+
const checkpoints = Number.parseInt(count.stdout.trim(), 10);
|
|
9666
|
+
return { ok: true, checkpoints: Number.isInteger(checkpoints) ? checkpoints : 0, bytes };
|
|
9667
|
+
}
|
|
9668
|
+
async function fileSizeBytes(path) {
|
|
9669
|
+
try {
|
|
9670
|
+
return (await stat7(path)).size;
|
|
9671
|
+
} catch {
|
|
9672
|
+
return void 0;
|
|
9673
|
+
}
|
|
9674
|
+
}
|
|
9675
|
+
async function listCheckpoints(input) {
|
|
9676
|
+
const { cwd, env } = input;
|
|
9677
|
+
const dir = \u5F71\u5B50\u76EE\u5F55(cwd, env);
|
|
9678
|
+
const limit = input.limit ?? 50;
|
|
9679
|
+
const withFiles = input.withFiles === true;
|
|
9680
|
+
const log = await runGit(
|
|
9681
|
+
shadowArgs(cwd, env, [
|
|
9682
|
+
"log",
|
|
9683
|
+
`-n${limit}`,
|
|
9684
|
+
...withFiles ? ["--numstat"] : [],
|
|
9685
|
+
"--format=%x01%H%x09%cI%x09%s"
|
|
9686
|
+
]),
|
|
9687
|
+
{ cwd, ...env ? { env } : {} }
|
|
9688
|
+
);
|
|
9689
|
+
if (!log.ok) return { ok: false, checkpoints: [], dir, reason: log.stderr.trim() || "\u65E0\u5FEB\u7167\u6216 git \u4E0D\u53EF\u7528" };
|
|
9690
|
+
const checkpoints = [];
|
|
9691
|
+
for (const line of log.stdout.split("\n")) {
|
|
9692
|
+
if (line.trim() === "") continue;
|
|
9693
|
+
if (line.startsWith("")) {
|
|
9694
|
+
const [hash = "", ts = "", ...rest] = line.slice(1).split(" ");
|
|
9695
|
+
const label = rest.join(" ");
|
|
9696
|
+
const seq = checkpointSeqOf(label);
|
|
9697
|
+
checkpoints.push({ hash, ts, label, ...seq !== void 0 ? { seq } : {}, ...withFiles ? { files: 0 } : {} });
|
|
9698
|
+
continue;
|
|
9699
|
+
}
|
|
9700
|
+
const \u5F53\u524D = checkpoints[checkpoints.length - 1];
|
|
9701
|
+
if (withFiles && \u5F53\u524D !== void 0) \u5F53\u524D.files = (\u5F53\u524D.files ?? 0) + 1;
|
|
9702
|
+
}
|
|
9703
|
+
return { ok: true, checkpoints, dir };
|
|
9704
|
+
}
|
|
9705
|
+
async function restoreCheckpointLocked(input) {
|
|
9706
|
+
const { cwd, checkpoint, env } = input;
|
|
9707
|
+
const target = input.path === void 0 || input.path === "" ? "." : input.path;
|
|
9708
|
+
const out = await runGit(
|
|
9709
|
+
shadowArgs(cwd, env, ["checkout", checkpoint, "--", target]),
|
|
9710
|
+
{ cwd, ...env ? { env } : {} }
|
|
9711
|
+
);
|
|
9712
|
+
return out.ok ? { ok: true, restored: target } : { ok: false, reason: `\u6062\u590D\u5931\u8D25\uFF1A${out.stderr.trim()}` };
|
|
9713
|
+
}
|
|
9714
|
+
function createCheckpoint(input) {
|
|
9715
|
+
return byKey(\u5F71\u5B50\u76EE\u5F55(input.cwd, input.env), () => createCheckpointLocked(input));
|
|
9716
|
+
}
|
|
9717
|
+
function restoreCheckpoint(input) {
|
|
9718
|
+
return byKey(\u5F71\u5B50\u76EE\u5F55(input.cwd, input.env), () => restoreCheckpointLocked(input));
|
|
9719
|
+
}
|
|
9720
|
+
var SNAPSHOT_MAX_FILE_BYTES, SNAPSHOT_GIT_TIMEOUT_MS;
|
|
9721
|
+
var init_snapshot = __esm({
|
|
9722
|
+
"packages/core/src/workspace/snapshot.ts"() {
|
|
9723
|
+
"use strict";
|
|
9724
|
+
init_project_paths();
|
|
9725
|
+
init_keyed_serial();
|
|
9726
|
+
init_dir_size();
|
|
9727
|
+
SNAPSHOT_MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
9728
|
+
SNAPSHOT_GIT_TIMEOUT_MS = 2e4;
|
|
9729
|
+
}
|
|
9730
|
+
});
|
|
9731
|
+
|
|
9386
9732
|
// packages/core/src/session/scheduler/scheduler.ts
|
|
9387
9733
|
var MAX_STEPS, Scheduler;
|
|
9388
9734
|
var init_scheduler = __esm({
|
|
@@ -9639,9 +9985,9 @@ var init_token_estimator = __esm({
|
|
|
9639
9985
|
});
|
|
9640
9986
|
|
|
9641
9987
|
// packages/core/src/session/working-directory.ts
|
|
9642
|
-
import { realpath, stat as
|
|
9988
|
+
import { realpath, stat as stat8 } from "node:fs/promises";
|
|
9643
9989
|
import { realpathSync as realpathSync2 } from "node:fs";
|
|
9644
|
-
import { isAbsolute, resolve, sep } from "node:path";
|
|
9990
|
+
import { isAbsolute as isAbsolute2, resolve, sep } from "node:path";
|
|
9645
9991
|
function \u5728\u754C\u5185(\u6839, \u7EDD\u5BF9) {
|
|
9646
9992
|
const \u754C = resolve(\u6839);
|
|
9647
9993
|
const p = resolve(\u7EDD\u5BF9);
|
|
@@ -9657,7 +10003,7 @@ function \u771F\u8EAB\u5728\u754C\u5185(\u6839, \u7EDD\u5BF9) {
|
|
|
9657
10003
|
function \u6267\u884C\u57FA\u70B9(\u5019\u9009, \u8FB9\u754C\u6839) {
|
|
9658
10004
|
const \u754C = resolve(\u8FB9\u754C\u6839);
|
|
9659
10005
|
if (\u5019\u9009 === void 0 || \u5019\u9009 === "") return \u754C;
|
|
9660
|
-
const \u7EDD\u5BF9 =
|
|
10006
|
+
const \u7EDD\u5BF9 = isAbsolute2(\u5019\u9009) ? resolve(\u5019\u9009) : resolve(\u754C, \u5019\u9009);
|
|
9661
10007
|
if (\u5728\u754C\u5185(\u754C, \u7EDD\u5BF9)) return \u7EDD\u5BF9;
|
|
9662
10008
|
return \u771F\u8EAB\u5728\u754C\u5185(\u754C, \u7EDD\u5BF9) ? \u7EDD\u5BF9 : \u754C;
|
|
9663
10009
|
}
|
|
@@ -9668,7 +10014,7 @@ function \u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55(state, \u8D77\u70B9\u68392) {
|
|
|
9668
10014
|
}
|
|
9669
10015
|
async function \u76EE\u5F55\u8FD8\u5728(\u8DEF\u5F84) {
|
|
9670
10016
|
try {
|
|
9671
|
-
return (await
|
|
10017
|
+
return (await stat8(\u8DEF\u5F84)).isDirectory();
|
|
9672
10018
|
} catch {
|
|
9673
10019
|
return false;
|
|
9674
10020
|
}
|
|
@@ -9676,7 +10022,7 @@ async function \u76EE\u5F55\u8FD8\u5728(\u8DEF\u5F84) {
|
|
|
9676
10022
|
async function \u6821\u9A8C\u5F85\u5207\u76EE\u5F55(\u76EE\u6807, \u8FB9\u754C\u6839, \u57FA\u51C6) {
|
|
9677
10023
|
const \u6E90 = typeof \u76EE\u6807 === "string" ? \u76EE\u6807.trim() : "";
|
|
9678
10024
|
if (\u6E90 === "") return { kind: "error", message: "working_directory: set \u9700\u8981 path\uFF08\u8981\u5207\u5230\u7684\u76EE\u5F55\uFF09" };
|
|
9679
|
-
const \u5019\u9009 =
|
|
10025
|
+
const \u5019\u9009 = isAbsolute2(\u6E90) ? resolve(\u6E90) : resolve(\u57FA\u51C6, \u6E90);
|
|
9680
10026
|
if (\u5728\u754C\u5185(\u8FB9\u754C\u6839, \u5019\u9009) === false && \u771F\u8EAB\u5728\u754C\u5185(\u8FB9\u754C\u6839, \u5019\u9009) === false) {
|
|
9681
10027
|
return {
|
|
9682
10028
|
kind: "error",
|
|
@@ -9685,7 +10031,7 @@ async function \u6821\u9A8C\u5F85\u5207\u76EE\u5F55(\u76EE\u6807, \u8FB9\u754C\u
|
|
|
9685
10031
|
}
|
|
9686
10032
|
let \u771F\u8EAB;
|
|
9687
10033
|
try {
|
|
9688
|
-
const st = await
|
|
10034
|
+
const st = await stat8(\u5019\u9009);
|
|
9689
10035
|
if (st.isDirectory() === false) {
|
|
9690
10036
|
return { kind: "error", message: `working_directory: \u4E0D\u662F\u76EE\u5F55\uFF08${\u5019\u9009}\uFF09\u2014\u2014\u5207\u76EE\u5F55\u7684\u76EE\u6807\u5FC5\u987B\u662F\u76EE\u5F55` };
|
|
9691
10037
|
}
|
|
@@ -9756,7 +10102,7 @@ var init_essence_gate = __esm({
|
|
|
9756
10102
|
});
|
|
9757
10103
|
|
|
9758
10104
|
// packages/core/src/agent/file-gate.ts
|
|
9759
|
-
import { stat as
|
|
10105
|
+
import { stat as stat9 } from "node:fs/promises";
|
|
9760
10106
|
function \u65B0\u5EFA\u4F1A\u8BDD\u6587\u4EF6\u6001() {
|
|
9761
10107
|
return { readSet: /* @__PURE__ */ new Set(), fileState: /* @__PURE__ */ new Map() };
|
|
9762
10108
|
}
|
|
@@ -9777,7 +10123,7 @@ function \u53D6\u4F1A\u8BDD\u6587\u4EF6\u6001(\u4F1A\u8BDD\u952E) {
|
|
|
9777
10123
|
}
|
|
9778
10124
|
async function statMtimeMs(path) {
|
|
9779
10125
|
try {
|
|
9780
|
-
return (await
|
|
10126
|
+
return (await stat9(path)).mtimeMs;
|
|
9781
10127
|
} catch (error) {
|
|
9782
10128
|
const code = error.code;
|
|
9783
10129
|
if (code === "ENOENT") return null;
|
|
@@ -9786,7 +10132,7 @@ async function statMtimeMs(path) {
|
|
|
9786
10132
|
}
|
|
9787
10133
|
async function statPath(path) {
|
|
9788
10134
|
try {
|
|
9789
|
-
const st = await
|
|
10135
|
+
const st = await stat9(path);
|
|
9790
10136
|
return { mtimeMs: st.mtimeMs, isFile: st.isFile() };
|
|
9791
10137
|
} catch (error) {
|
|
9792
10138
|
const code = error.code;
|
|
@@ -11136,6 +11482,11 @@ function isContextOverflowError(err) {
|
|
|
11136
11482
|
function classifyLlmError(err) {
|
|
11137
11483
|
if (err instanceof LlmTimeoutError) return { category: "timeout", retryable: false, capacity: false };
|
|
11138
11484
|
if (err instanceof LlmStreamError) return { category: "stream-error", retryable: false, capacity: false };
|
|
11485
|
+
if (err instanceof LlmToolArgsError) {
|
|
11486
|
+
if (err.finishReason === "length") return { category: "truncated", retryable: false, capacity: false };
|
|
11487
|
+
return { category: "model-output", retryable: true, capacity: false };
|
|
11488
|
+
}
|
|
11489
|
+
if (err instanceof LlmResponseFormatError) return { category: "fatal", retryable: false, capacity: false };
|
|
11139
11490
|
if (isAbortError(err)) return { category: "aborted", retryable: false, capacity: false };
|
|
11140
11491
|
if (err instanceof LlmHttpError) {
|
|
11141
11492
|
if (isContextOverflowError(err)) {
|
|
@@ -11153,12 +11504,12 @@ function isRetryableError(err) {
|
|
|
11153
11504
|
return classifyLlmError(err).retryable;
|
|
11154
11505
|
}
|
|
11155
11506
|
function isLlmError(err) {
|
|
11156
|
-
return err instanceof LlmHttpError || err instanceof LlmTimeoutError || err instanceof LlmStreamError || isAbortError(err);
|
|
11507
|
+
return err instanceof LlmHttpError || err instanceof LlmTimeoutError || err instanceof LlmStreamError || err instanceof LlmToolArgsError || err instanceof LlmResponseFormatError || isAbortError(err);
|
|
11157
11508
|
}
|
|
11158
11509
|
function isCapacityError(err) {
|
|
11159
11510
|
return classifyLlmError(err).capacity;
|
|
11160
11511
|
}
|
|
11161
|
-
var RETRYABLE_STATUS, OVERLOADED_BODY, LlmStreamError, LlmHttpError, LlmTimeoutError, CONTEXT_OVERFLOW_PATTERNS, OVERFLOW_STATUS, EMPTY_BODY_RE;
|
|
11512
|
+
var RETRYABLE_STATUS, OVERLOADED_BODY, LlmStreamError, LlmToolArgsError, LlmResponseFormatError, LlmHttpError, LlmTimeoutError, CONTEXT_OVERFLOW_PATTERNS, OVERFLOW_STATUS, EMPTY_BODY_RE;
|
|
11162
11513
|
var init_error_classify = __esm({
|
|
11163
11514
|
"packages/core/src/llm/error-classify.ts"() {
|
|
11164
11515
|
"use strict";
|
|
@@ -11173,6 +11524,30 @@ var init_error_classify = __esm({
|
|
|
11173
11524
|
this.code = code;
|
|
11174
11525
|
}
|
|
11175
11526
|
};
|
|
11527
|
+
LlmToolArgsError = class extends Error {
|
|
11528
|
+
/** 出问题的工具名(可读提示要用;**不带参数原文**——它可能几百字,别让它进日志/终端)。 */
|
|
11529
|
+
toolName;
|
|
11530
|
+
/**
|
|
11531
|
+
* 上游给的 `finish_reason`(GitHub issue #9)。**`length` 是分水岭**:它说明这次输出是被
|
|
11532
|
+
* `max_tokens` 截断的 —— 同样的配置重采样还会再截断,而 `stop`/`tool_calls` 下的坏 JSON
|
|
11533
|
+
* 才是「采样手抖、重采样大概率就好」。不带它就只能把两种混成同一档。
|
|
11534
|
+
*/
|
|
11535
|
+
finishReason;
|
|
11536
|
+
constructor(message, toolName, finishReason) {
|
|
11537
|
+
super(message);
|
|
11538
|
+
this.name = "LlmToolArgsError";
|
|
11539
|
+
this.toolName = toolName;
|
|
11540
|
+
this.finishReason = finishReason;
|
|
11541
|
+
}
|
|
11542
|
+
};
|
|
11543
|
+
LlmResponseFormatError = class extends Error {
|
|
11544
|
+
constructor() {
|
|
11545
|
+
super(
|
|
11546
|
+
'\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'
|
|
11547
|
+
);
|
|
11548
|
+
this.name = "LlmResponseFormatError";
|
|
11549
|
+
}
|
|
11550
|
+
};
|
|
11176
11551
|
LlmHttpError = class extends Error {
|
|
11177
11552
|
status;
|
|
11178
11553
|
retryAfterMs;
|
|
@@ -11252,13 +11627,13 @@ var init_cache_breakpoint = __esm({
|
|
|
11252
11627
|
// packages/core/src/agent/project-docs.ts
|
|
11253
11628
|
import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
|
|
11254
11629
|
import { homedir as homedir3 } from "node:os";
|
|
11255
|
-
import { join as
|
|
11630
|
+
import { join as join11 } from "node:path";
|
|
11256
11631
|
function projectDocCandidates(input) {
|
|
11257
11632
|
const home = input.home ?? homedir3();
|
|
11258
11633
|
return [
|
|
11259
|
-
{ path:
|
|
11260
|
-
{ path:
|
|
11261
|
-
{ path:
|
|
11634
|
+
{ path: join11(home, ".claude", "CLAUDE.md"), source: "user" },
|
|
11635
|
+
{ path: join11(input.cwd, "AGENTS.md"), source: "project-agents" },
|
|
11636
|
+
{ path: join11(input.cwd, "CLAUDE.md"), source: "project-claude" }
|
|
11262
11637
|
];
|
|
11263
11638
|
}
|
|
11264
11639
|
function projectDocsDisabled(env) {
|
|
@@ -11568,7 +11943,7 @@ var init_auto_recall_query = __esm({
|
|
|
11568
11943
|
});
|
|
11569
11944
|
|
|
11570
11945
|
// packages/core/src/agent/request-step.ts
|
|
11571
|
-
import { join as
|
|
11946
|
+
import { join as join12 } from "node:path";
|
|
11572
11947
|
function \u8D77\u70B9\u6839(ctx) {
|
|
11573
11948
|
return ctx.workspace?.cwd;
|
|
11574
11949
|
}
|
|
@@ -11724,7 +12099,7 @@ function createRequestStep(config = {}) {
|
|
|
11724
12099
|
if (ctx.extraSystem && ctx.extraSystem.trim() !== "") parts.push(contextNotePart(ctx.extraSystem));
|
|
11725
12100
|
if (log.state.planMode) {
|
|
11726
12101
|
const planTurns = planTurnsSinceEnter(log.snapshot(), true);
|
|
11727
|
-
const planFile = ctx.workspace?.cwd ?
|
|
12102
|
+
const planFile = ctx.workspace?.cwd ? join12(\u8D77\u70B9\u6839(ctx) ?? ctx.workspace.cwd, ".daluo", "plans", `${log.state.sessionId ?? "session"}.md`).replaceAll("\\", "/") : void 0;
|
|
11728
12103
|
parts.push({
|
|
11729
12104
|
kind: "plan-mode",
|
|
11730
12105
|
text: `\u5F53\u524D\u5904\u4E8E\u8BA1\u5212\u6A21\u5F0F\uFF1A\u53EA\u8BFB\u63A2\u7D22\uFF08${READ_FILE}/${GREP}/${GLOB}/${LSP}\uFF09\uFF0C\u4E0D\u5199\u6587\u4EF6\u4E0D\u6539\u4EE3\u7801\u3002` + (planFile ? `
|
|
@@ -11757,6 +12132,7 @@ function createRequestStep(config = {}) {
|
|
|
11757
12132
|
}
|
|
11758
12133
|
chatMessages = await buildMessages();
|
|
11759
12134
|
const budget = ctx.compactBudget;
|
|
12135
|
+
let \u672C\u8F6E\u538B\u7F29\u6570 = 0;
|
|
11760
12136
|
if (budget && llm) {
|
|
11761
12137
|
const threshold = contextThresholdTokens(budget);
|
|
11762
12138
|
const estTokens = (chars) => ctx.tokenEstimator ? ctx.tokenEstimator.estimateChars(chars) : estimateTokens(chars);
|
|
@@ -11787,6 +12163,20 @@ function createRequestStep(config = {}) {
|
|
|
11787
12163
|
estimateChars: estTokens
|
|
11788
12164
|
});
|
|
11789
12165
|
let account = \u8D26();
|
|
12166
|
+
if (account.tokens > threshold * CONTEXT_WARN_RATIO) {
|
|
12167
|
+
const \u5386\u53F2 = log.state.messages.filter((m) => m.role === "user" && m.source === "context").map((m) => m.content);
|
|
12168
|
+
if (shouldInjectContext(\u5386\u53F2, CONTEXT_WARN_BLOCK)) {
|
|
12169
|
+
await log.append({
|
|
12170
|
+
sessionId: log.state.sessionId ?? "",
|
|
12171
|
+
seq: log.nextSeq(),
|
|
12172
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12173
|
+
type: "context/injected",
|
|
12174
|
+
content: CONTEXT_WARN_BLOCK
|
|
12175
|
+
});
|
|
12176
|
+
chatMessages = await buildMessages();
|
|
12177
|
+
account = \u8D26();
|
|
12178
|
+
}
|
|
12179
|
+
}
|
|
11790
12180
|
while (compacted < MAX_COMPACTIONS && account.tokens > threshold) {
|
|
11791
12181
|
const verdict = await compactOnce(log, {
|
|
11792
12182
|
keepMessages: keepForBudget(budget.keepMessages),
|
|
@@ -11801,6 +12191,7 @@ function createRequestStep(config = {}) {
|
|
|
11801
12191
|
account = \u8D26();
|
|
11802
12192
|
}
|
|
11803
12193
|
if (compacted > 0) resetMemoryAfterCompaction(ctx.memorySession);
|
|
12194
|
+
\u672C\u8F6E\u538B\u7F29\u6570 = compacted;
|
|
11804
12195
|
}
|
|
11805
12196
|
const fingerprint = measureSync(
|
|
11806
12197
|
"fingerprintPrompt",
|
|
@@ -11829,6 +12220,8 @@ function createRequestStep(config = {}) {
|
|
|
11829
12220
|
const \u534F\u8BAE\u8FDD\u89C4 = \u8BF7\u6C42\u534F\u8BAE\u8FDD\u89C4(chatMessages);
|
|
11830
12221
|
if (\u534F\u8BAE\u8FDD\u89C4 !== void 0) throw new Error(`\u8BF7\u6C42\u534F\u8BAE\u81EA\u8BC1\u5931\u8D25\uFF08\u5F62\u72B6\u8FDD\u53CD provider \u534F\u8BAE\uFF09\uFF1A${\u534F\u8BAE\u8FDD\u89C4}`);
|
|
11831
12222
|
const \u53D1\u9001\u6D88\u606F = \u5E26\u65AD\u70B9 ? withCacheBreakpoint(chatMessages) : chatMessages;
|
|
12223
|
+
const \u8BF7\u6C42\u8D77 = Date.now();
|
|
12224
|
+
let \u8BF7\u6C42\u8017\u65F6Ms = 0;
|
|
11832
12225
|
let response;
|
|
11833
12226
|
try {
|
|
11834
12227
|
if (ctx.useStream && typeof llm.completeStream === "function") {
|
|
@@ -11847,6 +12240,7 @@ function createRequestStep(config = {}) {
|
|
|
11847
12240
|
...ctx.signal ? { signal: ctx.signal } : {}
|
|
11848
12241
|
});
|
|
11849
12242
|
}
|
|
12243
|
+
\u8BF7\u6C42\u8017\u65F6Ms = Date.now() - \u8BF7\u6C42\u8D77;
|
|
11850
12244
|
if (ctx.budgetState && response.usage) {
|
|
11851
12245
|
ctx.budgetState.tokens += response.usage.promptTokens + response.usage.completionTokens;
|
|
11852
12246
|
ctx.budgetState.promptTokens = (ctx.budgetState.promptTokens ?? 0) + response.usage.promptTokens;
|
|
@@ -11878,6 +12272,20 @@ function createRequestStep(config = {}) {
|
|
|
11878
12272
|
});
|
|
11879
12273
|
}
|
|
11880
12274
|
recordCacheRead(sessionId, response.usage?.cachedTokens);
|
|
12275
|
+
if (response.usage !== void 0) {
|
|
12276
|
+
const \u9884\u7B97 = ctx.compactBudget;
|
|
12277
|
+
await log.append({
|
|
12278
|
+
sessionId,
|
|
12279
|
+
seq: log.nextSeq(),
|
|
12280
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12281
|
+
type: "context/report",
|
|
12282
|
+
// 纯遥测(不进 fold)⇒ 旧版跳过即可,不必抬日志格式版本头
|
|
12283
|
+
ignorable: true,
|
|
12284
|
+
tokens: response.usage.promptTokens,
|
|
12285
|
+
...\u9884\u7B97 === void 0 ? {} : { window: contextWindowOf(\u9884\u7B97), threshold: contextThresholdTokens(\u9884\u7B97) },
|
|
12286
|
+
...\u672C\u8F6E\u538B\u7F29\u6570 > 0 ? { compactions: \u672C\u8F6E\u538B\u7F29\u6570 } : {}
|
|
12287
|
+
});
|
|
12288
|
+
}
|
|
11881
12289
|
if (ctx.tokenEstimator && response.usage?.promptTokens) {
|
|
11882
12290
|
const chars = request.messages.reduce((s, m) => s + chatMessageChars(m), 0);
|
|
11883
12291
|
ctx.tokenEstimator.observe(chars, response.usage.promptTokens);
|
|
@@ -11905,7 +12313,12 @@ function createRequestStep(config = {}) {
|
|
|
11905
12313
|
try {
|
|
11906
12314
|
input = JSON.parse(tc.arguments);
|
|
11907
12315
|
} catch {
|
|
11908
|
-
|
|
12316
|
+
const \u539F\u6587 = tc.arguments.length > 200 ? `${tc.arguments.slice(0, 200)}\u2026\uFF08\u5171 ${tc.arguments.length} \u5B57\u7B26\uFF09` : tc.arguments;
|
|
12317
|
+
throw new LlmToolArgsError(
|
|
12318
|
+
`request step: tool_calls arguments \u975E JSON\uFF08name=${tc.name}\uFF09\uFF1A${\u539F\u6587}`,
|
|
12319
|
+
tc.name,
|
|
12320
|
+
response.finishReason === "" ? void 0 : response.finishReason
|
|
12321
|
+
);
|
|
11909
12322
|
}
|
|
11910
12323
|
return { type: "tool-call", toolCallId: tc.id, toolName: tc.name, input };
|
|
11911
12324
|
});
|
|
@@ -11924,7 +12337,10 @@ function createRequestStep(config = {}) {
|
|
|
11924
12337
|
// 模型身份进日志(G8-30 第 1 段):记**当轮实际发的 model**(含 before/request 改写)。
|
|
11925
12338
|
model: request.model,
|
|
11926
12339
|
// 真实 usage 落日志(spec/session-event.md 演进节):provider 未回则缺省不写
|
|
11927
|
-
...response.usage ? { usage: { ...response.usage } } : {}
|
|
12340
|
+
...response.usage ? { usage: { ...response.usage } } : {},
|
|
12341
|
+
// 耗时与上游 finish_reason(issue #9):空串 = provider 没回,**不写**(不编 'stop')
|
|
12342
|
+
durationMs: \u8BF7\u6C42\u8017\u65F6Ms,
|
|
12343
|
+
...response.finishReason !== "" ? { finishReason: response.finishReason } : {}
|
|
11928
12344
|
});
|
|
11929
12345
|
return { next: "tool-dispatch" };
|
|
11930
12346
|
}
|
|
@@ -11940,7 +12356,11 @@ function createRequestStep(config = {}) {
|
|
|
11940
12356
|
],
|
|
11941
12357
|
// 模型身份进日志(G8-30 第 1 段):同工具轮,记当轮实际用的 model。
|
|
11942
12358
|
model: request.model,
|
|
11943
|
-
...response.usage ? { usage: { ...response.usage } } : {}
|
|
12359
|
+
...response.usage ? { usage: { ...response.usage } } : {},
|
|
12360
|
+
// 耗时与 finish_reason(issue #9):与工具轮同口径。`length` 在这里意味着**正文被截断**
|
|
12361
|
+
// (此前这条是静默成功:宿主只看到「答完了」,看不出答案是半截)。
|
|
12362
|
+
durationMs: \u8BF7\u6C42\u8017\u65F6Ms,
|
|
12363
|
+
...response.finishReason !== "" ? { finishReason: response.finishReason } : {}
|
|
11944
12364
|
});
|
|
11945
12365
|
return { next: textNext };
|
|
11946
12366
|
}
|
|
@@ -11957,7 +12377,7 @@ function commitmentReminders(events, threshold = DEFAULT_BROKEN_TURNS) {
|
|
|
11957
12377
|
const \u5DF2\u6CE8\u5165 = events.filter((e) => e.type === "context/injected").map((e) => e.content);
|
|
11958
12378
|
return ops.filter((op) => !\u5DF2\u6CE8\u5165.some((content) => content.includes(describeBroken(op))));
|
|
11959
12379
|
}
|
|
11960
|
-
var AGENT_SYSTEM_PROMPT2;
|
|
12380
|
+
var CONTEXT_WARN_RATIO, CONTEXT_WARN_BLOCK, AGENT_SYSTEM_PROMPT2;
|
|
11961
12381
|
var init_request_step = __esm({
|
|
11962
12382
|
"packages/core/src/agent/request-step.ts"() {
|
|
11963
12383
|
"use strict";
|
|
@@ -11983,6 +12403,8 @@ var init_request_step = __esm({
|
|
|
11983
12403
|
init_working_directory();
|
|
11984
12404
|
init_system_prompt();
|
|
11985
12405
|
init_system_prompt();
|
|
12406
|
+
CONTEXT_WARN_RATIO = 0.9;
|
|
12407
|
+
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
12408
|
AGENT_SYSTEM_PROMPT2 = assembleSystemPrompt({});
|
|
11987
12409
|
}
|
|
11988
12410
|
});
|
|
@@ -12077,11 +12499,11 @@ var init_inbox = __esm({
|
|
|
12077
12499
|
});
|
|
12078
12500
|
|
|
12079
12501
|
// packages/core/src/agent/bash-escape.ts
|
|
12080
|
-
import { basename as
|
|
12502
|
+
import { basename as basename7, dirname as dirname6, isAbsolute as isAbsolute3, join as join13, relative, resolve as resolve2, sep as sep2 } from "node:path";
|
|
12081
12503
|
import { realpathSync as realpathSync3 } from "node:fs";
|
|
12082
12504
|
function withinByString(base, abs) {
|
|
12083
12505
|
const rel = relative(base, abs);
|
|
12084
|
-
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep2}`) && !
|
|
12506
|
+
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep2}`) && !isAbsolute3(rel);
|
|
12085
12507
|
}
|
|
12086
12508
|
function canonicalize2(path) {
|
|
12087
12509
|
let head = resolve2(path);
|
|
@@ -12089,18 +12511,18 @@ function canonicalize2(path) {
|
|
|
12089
12511
|
for (; ; ) {
|
|
12090
12512
|
try {
|
|
12091
12513
|
const real = realpathSync3(head);
|
|
12092
|
-
return tail.length === 0 ? real :
|
|
12514
|
+
return tail.length === 0 ? real : join13(real, ...tail.reverse());
|
|
12093
12515
|
} catch {
|
|
12094
12516
|
const parent = dirname6(head);
|
|
12095
12517
|
if (parent === head) return void 0;
|
|
12096
|
-
tail.push(
|
|
12518
|
+
tail.push(basename7(head));
|
|
12097
12519
|
head = parent;
|
|
12098
12520
|
}
|
|
12099
12521
|
}
|
|
12100
12522
|
}
|
|
12101
12523
|
function isWithinDir(dir, target) {
|
|
12102
12524
|
const base = resolve2(dir);
|
|
12103
|
-
const abs =
|
|
12525
|
+
const abs = isAbsolute3(target) ? resolve2(target) : resolve2(base, target);
|
|
12104
12526
|
const realBase = canonicalize2(base);
|
|
12105
12527
|
const realAbs = canonicalize2(abs);
|
|
12106
12528
|
if (realBase !== void 0 && realAbs !== void 0) return withinByString(realBase, realAbs);
|
|
@@ -12212,7 +12634,7 @@ function inspectBashEscape(command, cwd, allowedRoots) {
|
|
|
12212
12634
|
if (DYNAMIC.test(rawTarget)) return { kind: "ambiguous", detail: `${program} \u76EE\u6807\u542B\u53D8\u91CF/\u547D\u4EE4\u66FF\u6362\uFF1A${rawTarget}` };
|
|
12213
12635
|
if (rawTarget.startsWith("~")) return { kind: "escape", detail: `${program} \u76EE\u6807\u4E3A\u5BB6\u76EE\u5F55\uFF1A${rawTarget}` };
|
|
12214
12636
|
const target = normalizeBashPath(rawTarget);
|
|
12215
|
-
if (
|
|
12637
|
+
if (isAbsolute3(target) || target.split(/[/\\]/).includes("..")) {
|
|
12216
12638
|
if (!\u5728\u5185(target)) {
|
|
12217
12639
|
return { kind: "escape", detail: `${program} \u76EE\u6807\u5728 cwd \u5916\uFF1A${rawTarget}\uFF08\u89E3\u6790\u4E3A ${resolve2(cwd, target)}\uFF09` };
|
|
12218
12640
|
}
|
|
@@ -12220,7 +12642,7 @@ function inspectBashEscape(command, cwd, allowedRoots) {
|
|
|
12220
12642
|
continue;
|
|
12221
12643
|
}
|
|
12222
12644
|
const programPath = normalizeBashPath(program);
|
|
12223
|
-
if (
|
|
12645
|
+
if (isAbsolute3(programPath) || programPath.startsWith("~")) {
|
|
12224
12646
|
if (!\u5728\u5185(programPath)) {
|
|
12225
12647
|
return { kind: "escape", detail: `\u7A0B\u5E8F\u5728 cwd \u5916\uFF1A${program}\uFF08\u89E3\u6790\u4E3A ${resolve2(cwd, programPath)}\uFF09` };
|
|
12226
12648
|
}
|
|
@@ -12315,7 +12737,7 @@ var init_bash_rules = __esm({
|
|
|
12315
12737
|
});
|
|
12316
12738
|
|
|
12317
12739
|
// packages/core/src/agent/permission-rules.ts
|
|
12318
|
-
import { isAbsolute as
|
|
12740
|
+
import { isAbsolute as isAbsolute4, resolve as resolve3 } from "node:path";
|
|
12319
12741
|
function \u89E3\u6790\u6743\u9650\u89C4\u5219(\u503C) {
|
|
12320
12742
|
if (!Array.isArray(\u503C)) return [];
|
|
12321
12743
|
const out = [];
|
|
@@ -12378,8 +12800,8 @@ function \u5355\u6761\u547D\u4E2D(rule, \u4E8B\u5B9E) {
|
|
|
12378
12800
|
if (\u4E8B\u5B9E.meta?.pathScoped === true) {
|
|
12379
12801
|
const \u8DEF\u5F84s = \u63D0\u53D6\u8DEF\u5F84(\u4E8B\u5B9E.input);
|
|
12380
12802
|
if (\u8DEF\u5F84s.length === 0) return false;
|
|
12381
|
-
const \u6839 =
|
|
12382
|
-
return \u8DEF\u5F84s.every((p) => isWithinDir(\u6839,
|
|
12803
|
+
const \u6839 = isAbsolute4(rule.prefix) ? rule.prefix : resolve3(\u4E8B\u5B9E.\u57FA\u70B9, rule.prefix);
|
|
12804
|
+
return \u8DEF\u5F84s.every((p) => isWithinDir(\u6839, isAbsolute4(p) ? p : resolve3(\u4E8B\u5B9E.\u57FA\u70B9, p)));
|
|
12383
12805
|
}
|
|
12384
12806
|
return false;
|
|
12385
12807
|
}
|
|
@@ -12588,21 +13010,21 @@ var init_session_files = __esm({
|
|
|
12588
13010
|
});
|
|
12589
13011
|
|
|
12590
13012
|
// packages/core/src/agent/tool-schema.ts
|
|
12591
|
-
import { z as
|
|
13013
|
+
import { z as z7 } from "zod";
|
|
12592
13014
|
function propertyToZod(prop) {
|
|
12593
13015
|
switch (prop.type) {
|
|
12594
13016
|
case "string":
|
|
12595
|
-
return
|
|
13017
|
+
return z7.string();
|
|
12596
13018
|
case "number": {
|
|
12597
|
-
let schema =
|
|
13019
|
+
let schema = z7.number();
|
|
12598
13020
|
if (typeof prop.minimum === "number") schema = schema.min(prop.minimum);
|
|
12599
13021
|
if (typeof prop.maximum === "number") schema = schema.max(prop.maximum);
|
|
12600
13022
|
return schema;
|
|
12601
13023
|
}
|
|
12602
13024
|
case "boolean":
|
|
12603
|
-
return
|
|
13025
|
+
return z7.boolean();
|
|
12604
13026
|
default:
|
|
12605
|
-
return
|
|
13027
|
+
return z7.unknown();
|
|
12606
13028
|
}
|
|
12607
13029
|
}
|
|
12608
13030
|
function parametersToZod(parameters) {
|
|
@@ -12612,7 +13034,7 @@ function parametersToZod(parameters) {
|
|
|
12612
13034
|
for (const [key, prop] of Object.entries(properties)) {
|
|
12613
13035
|
shape[key] = required.includes(key) ? propertyToZod(prop) : propertyToZod(prop).optional();
|
|
12614
13036
|
}
|
|
12615
|
-
return
|
|
13037
|
+
return z7.object(shape).passthrough();
|
|
12616
13038
|
}
|
|
12617
13039
|
var init_tool_schema = __esm({
|
|
12618
13040
|
"packages/core/src/agent/tool-schema.ts"() {
|
|
@@ -12620,230 +13042,6 @@ var init_tool_schema = __esm({
|
|
|
12620
13042
|
}
|
|
12621
13043
|
});
|
|
12622
13044
|
|
|
12623
|
-
// packages/core/src/workspace/keyed-serial.ts
|
|
12624
|
-
function byKey(key, \u4EFB\u52A1) {
|
|
12625
|
-
const \u524D\u4E00\u4E2A = \u94FE.get(key) ?? Promise.resolve();
|
|
12626
|
-
const \u672C\u6B21 = \u524D\u4E00\u4E2A.then(\u4EFB\u52A1, \u4EFB\u52A1);
|
|
12627
|
-
const \u5C3E\u5DF4 = \u672C\u6B21.then(
|
|
12628
|
-
() => void 0,
|
|
12629
|
-
() => void 0
|
|
12630
|
-
);
|
|
12631
|
-
\u94FE.set(key, \u5C3E\u5DF4);
|
|
12632
|
-
const \u56DE\u6536 = () => {
|
|
12633
|
-
if (\u94FE.get(key) === \u5C3E\u5DF4) \u94FE.delete(key);
|
|
12634
|
-
};
|
|
12635
|
-
void \u672C\u6B21.then(\u56DE\u6536, \u56DE\u6536);
|
|
12636
|
-
return \u672C\u6B21;
|
|
12637
|
-
}
|
|
12638
|
-
var \u94FE;
|
|
12639
|
-
var init_keyed_serial = __esm({
|
|
12640
|
-
"packages/core/src/workspace/keyed-serial.ts"() {
|
|
12641
|
-
"use strict";
|
|
12642
|
-
\u94FE = /* @__PURE__ */ new Map();
|
|
12643
|
-
}
|
|
12644
|
-
});
|
|
12645
|
-
|
|
12646
|
-
// packages/core/src/workspace/dir-size.ts
|
|
12647
|
-
import { readdir as readdir4, stat as stat8 } from "node:fs/promises";
|
|
12648
|
-
import { join as join12 } from "node:path";
|
|
12649
|
-
async function directoryBytes(dir) {
|
|
12650
|
-
let entries;
|
|
12651
|
-
try {
|
|
12652
|
-
entries = await readdir4(dir, { withFileTypes: true });
|
|
12653
|
-
} catch {
|
|
12654
|
-
return 0;
|
|
12655
|
-
}
|
|
12656
|
-
let total = 0;
|
|
12657
|
-
for (const entry of entries) {
|
|
12658
|
-
const path = join12(dir, entry.name);
|
|
12659
|
-
if (entry.isDirectory()) total += await directoryBytes(path);
|
|
12660
|
-
else if (entry.isFile()) {
|
|
12661
|
-
try {
|
|
12662
|
-
total += (await stat8(path)).size;
|
|
12663
|
-
} catch {
|
|
12664
|
-
}
|
|
12665
|
-
}
|
|
12666
|
-
}
|
|
12667
|
-
return total;
|
|
12668
|
-
}
|
|
12669
|
-
function formatBytes(n) {
|
|
12670
|
-
if (n < 1024) return `${n} B`;
|
|
12671
|
-
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
|
|
12672
|
-
if (n < 1024 * 1024 * 1024) return `${(n / 1024 / 1024).toFixed(1)} MB`;
|
|
12673
|
-
return `${(n / 1024 / 1024 / 1024).toFixed(1)} GB`;
|
|
12674
|
-
}
|
|
12675
|
-
var init_dir_size = __esm({
|
|
12676
|
-
"packages/core/src/workspace/dir-size.ts"() {
|
|
12677
|
-
"use strict";
|
|
12678
|
-
}
|
|
12679
|
-
});
|
|
12680
|
-
|
|
12681
|
-
// packages/core/src/workspace/snapshot.ts
|
|
12682
|
-
import { execFile as execFile2 } from "node:child_process";
|
|
12683
|
-
import { mkdir as mkdir6, stat as stat9 } from "node:fs/promises";
|
|
12684
|
-
import { join as join13 } from "node:path";
|
|
12685
|
-
function checkpointLabelWithSeq(label, seq) {
|
|
12686
|
-
return `${label} #seq=${seq}`;
|
|
12687
|
-
}
|
|
12688
|
-
function checkpointSeqOf(label) {
|
|
12689
|
-
const m = /(?:^|\s)#seq=(\d+)\s*$/.exec(label);
|
|
12690
|
-
return m === null ? void 0 : Number(m[1]);
|
|
12691
|
-
}
|
|
12692
|
-
async function runGit(args, opts) {
|
|
12693
|
-
return new Promise((resolve16) => {
|
|
12694
|
-
execFile2(
|
|
12695
|
-
"git",
|
|
12696
|
-
[...args],
|
|
12697
|
-
{ cwd: opts.cwd, timeout: SNAPSHOT_GIT_TIMEOUT_MS, maxBuffer: 8 * 1024 * 1024, ...opts.env ? { env: opts.env } : {} },
|
|
12698
|
-
(error, stdout, stderr) => {
|
|
12699
|
-
try {
|
|
12700
|
-
resolve16({
|
|
12701
|
-
ok: error === null,
|
|
12702
|
-
stdout: String(stdout ?? ""),
|
|
12703
|
-
stderr: String(stderr ?? "") || (error === null ? "" : error.message)
|
|
12704
|
-
});
|
|
12705
|
-
} catch (unexpected) {
|
|
12706
|
-
resolve16({ ok: false, stdout: "", stderr: `git \u8C03\u7528\u5F02\u5E38\uFF1A${unexpected instanceof Error ? unexpected.message : String(unexpected)}` });
|
|
12707
|
-
}
|
|
12708
|
-
}
|
|
12709
|
-
);
|
|
12710
|
-
});
|
|
12711
|
-
}
|
|
12712
|
-
function shadowArgs(cwd, rest) {
|
|
12713
|
-
return [
|
|
12714
|
-
`--git-dir=${shadowGitDirOf(cwd)}`,
|
|
12715
|
-
`--work-tree=${cwd}`,
|
|
12716
|
-
// 身份与环境隔离:不读用户 git config 的 hook/签名,也不因缺 user.name 而失败
|
|
12717
|
-
"-c",
|
|
12718
|
-
"user.name=daluo",
|
|
12719
|
-
"-c",
|
|
12720
|
-
"user.email=daluo@localhost",
|
|
12721
|
-
"-c",
|
|
12722
|
-
"commit.gpgsign=false",
|
|
12723
|
-
"-c",
|
|
12724
|
-
"core.hooksPath=/dev/null",
|
|
12725
|
-
...rest
|
|
12726
|
-
];
|
|
12727
|
-
}
|
|
12728
|
-
async function ensureShadowRepo(cwd, env) {
|
|
12729
|
-
try {
|
|
12730
|
-
await mkdir6(shadowGitDirOf(cwd), { recursive: true });
|
|
12731
|
-
} catch (error) {
|
|
12732
|
-
return `\u65E0\u6CD5\u521B\u5EFA\u5F71\u5B50\u4ED3\u5E93\u76EE\u5F55\uFF1A${error instanceof Error ? error.message : String(error)}`;
|
|
12733
|
-
}
|
|
12734
|
-
const init = await runGit([`--git-dir=${shadowGitDirOf(cwd)}`, "init", "--quiet"], { cwd, ...env ? { env } : {} });
|
|
12735
|
-
return init.ok ? void 0 : `git init \u5931\u8D25\uFF1A${init.stderr.trim()}`;
|
|
12736
|
-
}
|
|
12737
|
-
async function createCheckpointLocked(input) {
|
|
12738
|
-
const { cwd } = input;
|
|
12739
|
-
const label = input.seq === void 0 ? input.label : checkpointLabelWithSeq(input.label, input.seq);
|
|
12740
|
-
const env = input.env;
|
|
12741
|
-
const cap = input.maxFileBytes ?? SNAPSHOT_MAX_FILE_BYTES;
|
|
12742
|
-
if (input.paths !== void 0 && input.paths.length === 0) {
|
|
12743
|
-
return { ok: true, unchanged: true, files: 0 };
|
|
12744
|
-
}
|
|
12745
|
-
const repoProblem = await ensureShadowRepo(cwd, env);
|
|
12746
|
-
if (repoProblem !== void 0) return { ok: false, reason: repoProblem };
|
|
12747
|
-
const skipped = [];
|
|
12748
|
-
const scope = input.paths === void 0 || input.paths.length === 0 ? ["."] : [...input.paths];
|
|
12749
|
-
const listed = await runGit(
|
|
12750
|
-
shadowArgs(cwd, ["ls-files", "-o", "-m", "-z", "--exclude-standard", "--", ...scope, ":(exclude).daluo"]),
|
|
12751
|
-
{ cwd, ...env ? { env } : {} }
|
|
12752
|
-
);
|
|
12753
|
-
if (!listed.ok) return { ok: false, reason: `\u904D\u5386\u6587\u4EF6\u5931\u8D25\uFF1A${listed.stderr.trim()}` };
|
|
12754
|
-
const candidates = listed.stdout.split("\0").filter((p) => p !== "");
|
|
12755
|
-
const oversize = [];
|
|
12756
|
-
for (const path of candidates) {
|
|
12757
|
-
const size = await fileSizeBytes(join13(cwd, path));
|
|
12758
|
-
if (size !== void 0 && size > cap) {
|
|
12759
|
-
oversize.push(path);
|
|
12760
|
-
skipped.push({ path, reason: `${(size / 1024 / 1024).toFixed(1)} MB \u8D85\u8FC7\u4E0A\u9650 ${(cap / 1024 / 1024).toFixed(1)} MB` });
|
|
12761
|
-
}
|
|
12762
|
-
}
|
|
12763
|
-
const excludes = [...oversize.map((p) => `:(exclude)${p}`), ":(exclude).daluo"];
|
|
12764
|
-
const add = await runGit(shadowArgs(cwd, ["add", "-A", "--", ...scope, ...excludes]), { cwd, ...env ? { env } : {} });
|
|
12765
|
-
if (!add.ok) return { ok: false, reason: `git add \u5931\u8D25\uFF1A${add.stderr.trim()}`, ...skipped.length ? { skipped } : {} };
|
|
12766
|
-
const staged = await runGit(shadowArgs(cwd, ["diff", "--cached", "--name-only", "-z"]), { cwd, ...env ? { env } : {} });
|
|
12767
|
-
if (!staged.ok) return { ok: false, reason: `git diff \u5931\u8D25\uFF1A${staged.stderr.trim()}`, ...skipped.length ? { skipped } : {} };
|
|
12768
|
-
const stagedFiles = staged.stdout.split("\0").filter((p) => p !== "");
|
|
12769
|
-
if (stagedFiles.length === 0) {
|
|
12770
|
-
return { ok: true, unchanged: true, files: 0, ...skipped.length ? { skipped } : {} };
|
|
12771
|
-
}
|
|
12772
|
-
const commit2 = await runGit(shadowArgs(cwd, ["commit", "--quiet", "-m", label]), { cwd, ...env ? { env } : {} });
|
|
12773
|
-
if (!commit2.ok) return { ok: false, reason: `git commit \u5931\u8D25\uFF1A${commit2.stderr.trim()}`, ...skipped.length ? { skipped } : {} };
|
|
12774
|
-
const hash = await runGit(shadowArgs(cwd, ["rev-parse", "HEAD"]), { cwd, ...env ? { env } : {} });
|
|
12775
|
-
return {
|
|
12776
|
-
ok: true,
|
|
12777
|
-
...hash.ok ? { checkpoint: hash.stdout.trim() } : {},
|
|
12778
|
-
files: stagedFiles.length,
|
|
12779
|
-
...skipped.length ? { skipped } : {}
|
|
12780
|
-
};
|
|
12781
|
-
}
|
|
12782
|
-
async function snapshotCost(input) {
|
|
12783
|
-
const { cwd } = input;
|
|
12784
|
-
const env = input.env;
|
|
12785
|
-
const shadow = shadowGitDirOf(cwd);
|
|
12786
|
-
const count = await runGit(
|
|
12787
|
-
[`--git-dir=${shadow}`, "rev-list", "--count", "HEAD"],
|
|
12788
|
-
{ cwd, ...env ? { env } : {} }
|
|
12789
|
-
);
|
|
12790
|
-
const bytes = await directoryBytes(shadow);
|
|
12791
|
-
if (!count.ok) {
|
|
12792
|
-
return { ok: false, checkpoints: 0, bytes, reason: count.stderr.trim() || "\u8FD8\u6CA1\u6709\u5FEB\u7167\uFF08\u5F71\u5B50\u4ED3\u5E93\u4E0D\u5B58\u5728\u6216\u6CA1\u6709\u63D0\u4EA4\uFF09" };
|
|
12793
|
-
}
|
|
12794
|
-
const checkpoints = Number.parseInt(count.stdout.trim(), 10);
|
|
12795
|
-
return { ok: true, checkpoints: Number.isInteger(checkpoints) ? checkpoints : 0, bytes };
|
|
12796
|
-
}
|
|
12797
|
-
async function fileSizeBytes(path) {
|
|
12798
|
-
try {
|
|
12799
|
-
return (await stat9(path)).size;
|
|
12800
|
-
} catch {
|
|
12801
|
-
return void 0;
|
|
12802
|
-
}
|
|
12803
|
-
}
|
|
12804
|
-
async function listCheckpoints(input) {
|
|
12805
|
-
const { cwd, env } = input;
|
|
12806
|
-
const limit = input.limit ?? 50;
|
|
12807
|
-
const log = await runGit(
|
|
12808
|
-
shadowArgs(cwd, ["log", `-n${limit}`, "--format=%H%x09%cI%x09%s"]),
|
|
12809
|
-
{ cwd, ...env ? { env } : {} }
|
|
12810
|
-
);
|
|
12811
|
-
if (!log.ok) return { ok: false, checkpoints: [], reason: log.stderr.trim() || "\u65E0\u5FEB\u7167\u6216 git \u4E0D\u53EF\u7528" };
|
|
12812
|
-
const checkpoints = log.stdout.split("\n").filter((l) => l.trim() !== "").map((line) => {
|
|
12813
|
-
const [hash = "", ts = "", ...rest] = line.split(" ");
|
|
12814
|
-
const label = rest.join(" ");
|
|
12815
|
-
const seq = checkpointSeqOf(label);
|
|
12816
|
-
return { hash, ts, label, ...seq !== void 0 ? { seq } : {} };
|
|
12817
|
-
});
|
|
12818
|
-
return { ok: true, checkpoints };
|
|
12819
|
-
}
|
|
12820
|
-
async function restoreCheckpointLocked(input) {
|
|
12821
|
-
const { cwd, checkpoint, env } = input;
|
|
12822
|
-
const target = input.path === void 0 || input.path === "" ? "." : input.path;
|
|
12823
|
-
const out = await runGit(
|
|
12824
|
-
shadowArgs(cwd, ["checkout", checkpoint, "--", target]),
|
|
12825
|
-
{ cwd, ...env ? { env } : {} }
|
|
12826
|
-
);
|
|
12827
|
-
return out.ok ? { ok: true, restored: target } : { ok: false, reason: `\u6062\u590D\u5931\u8D25\uFF1A${out.stderr.trim()}` };
|
|
12828
|
-
}
|
|
12829
|
-
function createCheckpoint(input) {
|
|
12830
|
-
return byKey(shadowGitDirOf(input.cwd), () => createCheckpointLocked(input));
|
|
12831
|
-
}
|
|
12832
|
-
function restoreCheckpoint(input) {
|
|
12833
|
-
return byKey(shadowGitDirOf(input.cwd), () => restoreCheckpointLocked(input));
|
|
12834
|
-
}
|
|
12835
|
-
var SNAPSHOT_MAX_FILE_BYTES, SNAPSHOT_GIT_TIMEOUT_MS;
|
|
12836
|
-
var init_snapshot = __esm({
|
|
12837
|
-
"packages/core/src/workspace/snapshot.ts"() {
|
|
12838
|
-
"use strict";
|
|
12839
|
-
init_project_paths();
|
|
12840
|
-
init_keyed_serial();
|
|
12841
|
-
init_dir_size();
|
|
12842
|
-
SNAPSHOT_MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
12843
|
-
SNAPSHOT_GIT_TIMEOUT_MS = 2e4;
|
|
12844
|
-
}
|
|
12845
|
-
});
|
|
12846
|
-
|
|
12847
13045
|
// packages/core/src/workspace/mutation-checkpoint.ts
|
|
12848
13046
|
function snapshotEnabled(env) {
|
|
12849
13047
|
return (env["DALUO_SNAPSHOT"] ?? "").trim().toLowerCase() !== SNAPSHOT_OFF;
|
|
@@ -14405,7 +14603,7 @@ var init_async_agent = __esm({
|
|
|
14405
14603
|
// packages/core/src/workspace/worktree.ts
|
|
14406
14604
|
import { execFile as execFile3 } from "node:child_process";
|
|
14407
14605
|
import { existsSync as existsSync9, mkdirSync as mkdirSync3, realpathSync as realpathSync4 } from "node:fs";
|
|
14408
|
-
import { basename as
|
|
14606
|
+
import { basename as basename8, dirname as dirname7, join as join16 } from "node:path";
|
|
14409
14607
|
import { promisify as promisify2 } from "node:util";
|
|
14410
14608
|
async function git2(cwd, args, timeoutMs) {
|
|
14411
14609
|
try {
|
|
@@ -14450,7 +14648,7 @@ function canonical(path) {
|
|
|
14450
14648
|
return realpathSync4(path);
|
|
14451
14649
|
} catch {
|
|
14452
14650
|
const parent = dirname7(path);
|
|
14453
|
-
return parent === path ? path : join16(canonical(parent),
|
|
14651
|
+
return parent === path ? path : join16(canonical(parent), basename8(path));
|
|
14454
14652
|
}
|
|
14455
14653
|
}
|
|
14456
14654
|
async function registeredPaths(cwd, timeoutMs) {
|
|
@@ -14507,7 +14705,7 @@ async function listWorktrees(input) {
|
|
|
14507
14705
|
if (path === void 0) return;
|
|
14508
14706
|
const here = canonical(path);
|
|
14509
14707
|
if (here === root || here.startsWith(root + "/")) {
|
|
14510
|
-
worktrees.push({ name:
|
|
14708
|
+
worktrees.push({ name: basename8(here), path: join16(worktreesDirOf(input.cwd), basename8(here)), head });
|
|
14511
14709
|
}
|
|
14512
14710
|
path = void 0;
|
|
14513
14711
|
head = "";
|
|
@@ -14785,6 +14983,47 @@ var init_retry = __esm({
|
|
|
14785
14983
|
}
|
|
14786
14984
|
});
|
|
14787
14985
|
|
|
14986
|
+
// packages/core/src/llm/generation.ts
|
|
14987
|
+
function mergeGeneration(call, fromConfig) {
|
|
14988
|
+
if (call === void 0 && fromConfig === void 0) return void 0;
|
|
14989
|
+
const maxTokens = call?.maxTokens ?? fromConfig?.maxTokens;
|
|
14990
|
+
const temperature = call?.temperature ?? fromConfig?.temperature;
|
|
14991
|
+
const out = {};
|
|
14992
|
+
if (maxTokens !== void 0) out.maxTokens = maxTokens;
|
|
14993
|
+
if (temperature !== void 0) out.temperature = temperature;
|
|
14994
|
+
if (call?.toolChoice !== void 0) out.toolChoice = call.toolChoice;
|
|
14995
|
+
if (call?.responseFormat !== void 0) out.responseFormat = call.responseFormat;
|
|
14996
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
14997
|
+
}
|
|
14998
|
+
function generationBodyKeys(params) {
|
|
14999
|
+
if (params === void 0) return {};
|
|
15000
|
+
return {
|
|
15001
|
+
...params.maxTokens !== void 0 ? { max_tokens: params.maxTokens } : {},
|
|
15002
|
+
...params.temperature !== void 0 ? { temperature: params.temperature } : {},
|
|
15003
|
+
...params.toolChoice !== void 0 ? { tool_choice: params.toolChoice } : {}
|
|
15004
|
+
};
|
|
15005
|
+
}
|
|
15006
|
+
function resolveResponseFormat(mode, callLevel) {
|
|
15007
|
+
if (mode === void 0 || mode === "off") return void 0;
|
|
15008
|
+
if (mode === "always") return "json_object";
|
|
15009
|
+
return callLevel;
|
|
15010
|
+
}
|
|
15011
|
+
function messagesMentionJson(messages) {
|
|
15012
|
+
const \u547D\u4E2D = (s) => typeof s === "string" && /json/i.test(s);
|
|
15013
|
+
for (const m of messages) {
|
|
15014
|
+
if (typeof m.content === "string" && \u547D\u4E2D(m.content)) return true;
|
|
15015
|
+
if (Array.isArray(m.content) && m.content.some((p) => \u547D\u4E2D(p.text))) return true;
|
|
15016
|
+
const calls = m.tool_calls;
|
|
15017
|
+
if (calls?.some((c) => \u547D\u4E2D(c.function.arguments)) === true) return true;
|
|
15018
|
+
}
|
|
15019
|
+
return false;
|
|
15020
|
+
}
|
|
15021
|
+
var init_generation = __esm({
|
|
15022
|
+
"packages/core/src/llm/generation.ts"() {
|
|
15023
|
+
"use strict";
|
|
15024
|
+
}
|
|
15025
|
+
});
|
|
15026
|
+
|
|
14788
15027
|
// packages/core/src/llm/client.ts
|
|
14789
15028
|
function parseUsage(raw) {
|
|
14790
15029
|
if (!raw || raw.prompt_tokens === void 0 && raw.completion_tokens === void 0) return void 0;
|
|
@@ -14823,30 +15062,15 @@ function parseRetryAfterMs(retryAfter, retryAfterMs = null, now = Date.now()) {
|
|
|
14823
15062
|
function isCapacityError2(err) {
|
|
14824
15063
|
return classifyLlmError(err).capacity;
|
|
14825
15064
|
}
|
|
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
15065
|
var LLM_FIRST_BYTE_TIMEOUT_MS, LLM_STREAM_IDLE_MS, DEFAULT_MAX_RETRIES, LlmClient;
|
|
14845
15066
|
var init_client = __esm({
|
|
14846
15067
|
"packages/core/src/llm/client.ts"() {
|
|
14847
15068
|
"use strict";
|
|
14848
15069
|
init_retry();
|
|
14849
15070
|
init_error_classify();
|
|
15071
|
+
init_error_classify();
|
|
15072
|
+
init_generation();
|
|
15073
|
+
init_generation();
|
|
14850
15074
|
LLM_FIRST_BYTE_TIMEOUT_MS = 12e4;
|
|
14851
15075
|
LLM_STREAM_IDLE_MS = 9e4;
|
|
14852
15076
|
DEFAULT_MAX_RETRIES = 2;
|
|
@@ -15180,6 +15404,11 @@ var init_client = __esm({
|
|
|
15180
15404
|
const signal = options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
15181
15405
|
try {
|
|
15182
15406
|
const url = `${this.config.baseUrl.replace(/\/+$/, "")}/chat/completions`;
|
|
15407
|
+
const \u751F\u6210 = mergeGeneration(options, this.config.generation);
|
|
15408
|
+
const \u751F\u6548Format = resolveResponseFormat(this.config.responseFormatMode, \u751F\u6210?.responseFormat);
|
|
15409
|
+
if (\u751F\u6548Format !== void 0 && !messagesMentionJson(messages)) {
|
|
15410
|
+
throw new LlmResponseFormatError();
|
|
15411
|
+
}
|
|
15183
15412
|
const response = await this.doFetch(url, {
|
|
15184
15413
|
method: "POST",
|
|
15185
15414
|
headers: {
|
|
@@ -15193,7 +15422,9 @@ var init_client = __esm({
|
|
|
15193
15422
|
...options.tools && options.tools.length > 0 ? { tools: [...options.tools] } : {},
|
|
15194
15423
|
// 生成参数(G7-03 演进节):**只写设过的键**——`temperature: 0` 有意义,不能被真值判断吞掉。
|
|
15195
15424
|
// 「没说要」与「要 0」在线上是两种语义(同 `parseUsage` 的「缺省项不写」纪律)。
|
|
15196
|
-
...generationBodyKeys(
|
|
15425
|
+
...generationBodyKeys(\u751F\u6210),
|
|
15426
|
+
// 结构化输出(2026-10-22 演进节):只在**生效档**要它时才出现这个键 ⇒ 缺省请求体逐字节不变。
|
|
15427
|
+
...\u751F\u6548Format !== void 0 ? { response_format: { type: \u751F\u6548Format } } : {},
|
|
15197
15428
|
// 流式 usage(G1-26 / D§2.3):不写 `stream_options.include_usage` ⇒ 流式路径 promptTokens
|
|
15198
15429
|
// **静默缺失** ⇒ token 账与压缩预算的实测源、`tokenEstimator` 自校准全没了(只剩估算)。
|
|
15199
15430
|
...options.stream && this.config.streamIncludeUsage !== false ? { stream_options: { include_usage: true } } : {}
|
|
@@ -17445,7 +17676,15 @@ async function completeStructured(llm, messages, opts) {
|
|
|
17445
17676
|
];
|
|
17446
17677
|
const response = await llm.complete(\u672C\u8F6E, {
|
|
17447
17678
|
...opts.model !== void 0 ? { model: opts.model } : {},
|
|
17448
|
-
...opts.signal !== void 0 ? { signal: opts.signal } : {}
|
|
17679
|
+
...opts.signal !== void 0 ? { signal: opts.signal } : {},
|
|
17680
|
+
/**
|
|
17681
|
+
* **调用级要求**(`spec/llm-transport.md` 演进「response_format 开关」):上面这段活本来就是
|
|
17682
|
+
* 「给我合法 JSON」,所以这里说「我这次要结构化」是名副其实的。
|
|
17683
|
+
*
|
|
17684
|
+
* 但**发不发由配置定**(`resolveResponseFormat`):`off` 一律不发(用户说关就关)、
|
|
17685
|
+
* `structured` 才采用这个要求、`always` 全部发。调用方不该也无法绕开用户的总开关。
|
|
17686
|
+
*/
|
|
17687
|
+
responseFormat: "json_object"
|
|
17449
17688
|
});
|
|
17450
17689
|
const \u89E3 = parseStructured(response.content, opts.schema);
|
|
17451
17690
|
if (\u89E3.ok) return { value: \u89E3.value, response };
|
|
@@ -17506,7 +17745,7 @@ var init_structured = __esm({
|
|
|
17506
17745
|
});
|
|
17507
17746
|
|
|
17508
17747
|
// packages/core/src/agent/auto-memory.ts
|
|
17509
|
-
import { z as
|
|
17748
|
+
import { z as z8 } from "zod";
|
|
17510
17749
|
function messagesToText(messages) {
|
|
17511
17750
|
const lines = [];
|
|
17512
17751
|
for (const m of messages) {
|
|
@@ -17556,7 +17795,7 @@ function buildExtractPrompt(messages, existingFacts) {
|
|
|
17556
17795
|
].join("\n");
|
|
17557
17796
|
}
|
|
17558
17797
|
function parseExtracted(text2) {
|
|
17559
|
-
const \u6570\u7EC4 = parseStructured(text2,
|
|
17798
|
+
const \u6570\u7EC4 = parseStructured(text2, z8.array(z8.unknown()));
|
|
17560
17799
|
if (!\u6570\u7EC4.ok) return [];
|
|
17561
17800
|
const out = [];
|
|
17562
17801
|
for (const item of \u6570\u7EC4.value) {
|
|
@@ -17577,7 +17816,10 @@ function parseExtracted(text2) {
|
|
|
17577
17816
|
}
|
|
17578
17817
|
async function extractMemories(input) {
|
|
17579
17818
|
const prompt = buildExtractPrompt(input.messages, input.existingFacts);
|
|
17580
|
-
const res = await input.llm.complete([{ role: "user", content: prompt }],
|
|
17819
|
+
const res = await input.llm.complete([{ role: "user", content: prompt }], {
|
|
17820
|
+
...input.signal ? { signal: input.signal } : {},
|
|
17821
|
+
responseFormat: "json_object"
|
|
17822
|
+
});
|
|
17581
17823
|
return {
|
|
17582
17824
|
memories: parseExtracted(res.content),
|
|
17583
17825
|
...res.usage === void 0 ? {} : { usage: res.usage },
|
|
@@ -17605,17 +17847,17 @@ var init_auto_memory = __esm({
|
|
|
17605
17847
|
"use strict";
|
|
17606
17848
|
init_structured();
|
|
17607
17849
|
init_memory();
|
|
17608
|
-
MEMORY_ITEM =
|
|
17609
|
-
key:
|
|
17610
|
-
content:
|
|
17611
|
-
memoryType:
|
|
17612
|
-
confidence:
|
|
17850
|
+
MEMORY_ITEM = z8.object({
|
|
17851
|
+
key: z8.string().trim().min(1),
|
|
17852
|
+
content: z8.string().trim().min(1),
|
|
17853
|
+
memoryType: z8.enum(MEMORY_TYPES).optional(),
|
|
17854
|
+
confidence: z8.number().min(0).max(1).catch(0.5).optional(),
|
|
17613
17855
|
// 准入闸要的裁决字段(G4-01):坏值逐项兜底(`.catch`)而不是一票否决整条——
|
|
17614
17856
|
// 缺 `action` 按 `admit` 处理(宁可交给结构性硬闸判,也不在这里静默丢)。
|
|
17615
|
-
action:
|
|
17616
|
-
transferableTo:
|
|
17617
|
-
supersedesKey:
|
|
17618
|
-
reason:
|
|
17857
|
+
action: z8.enum(["admit", "reject", "supersede"]).catch("admit").optional(),
|
|
17858
|
+
transferableTo: z8.array(z8.string()).catch([]).optional(),
|
|
17859
|
+
supersedesKey: z8.string().optional(),
|
|
17860
|
+
reason: z8.string().optional()
|
|
17619
17861
|
});
|
|
17620
17862
|
}
|
|
17621
17863
|
});
|
|
@@ -18773,7 +19015,7 @@ ${unread.map((x) => `- \u6765\u81EA ${x.senderName}\uFF1A${x.content}`).join("\n
|
|
|
18773
19015
|
});
|
|
18774
19016
|
|
|
18775
19017
|
// packages/core/src/agent/team/peer.ts
|
|
18776
|
-
import { createHash as
|
|
19018
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
18777
19019
|
import { mkdirSync as mkdirSync6 } from "node:fs";
|
|
18778
19020
|
import { dirname as dirname9, join as join21, resolve as resolve6 } from "node:path";
|
|
18779
19021
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
@@ -18788,7 +19030,7 @@ function peersBaseDir() {
|
|
|
18788
19030
|
return peersDirOverride ?? PEERS_DIR;
|
|
18789
19031
|
}
|
|
18790
19032
|
function projectKeyOf(projectDir) {
|
|
18791
|
-
return
|
|
19033
|
+
return createHash4("sha1").update(resolve6(projectDir)).digest("hex").slice(0, 12);
|
|
18792
19034
|
}
|
|
18793
19035
|
function tempPeersDirIn(projectDir) {
|
|
18794
19036
|
return join21(peersBaseDir(), projectKeyOf(projectDir));
|
|
@@ -19658,7 +19900,7 @@ var init_limits = __esm({
|
|
|
19658
19900
|
});
|
|
19659
19901
|
|
|
19660
19902
|
// packages/core/src/agent/council/plan.ts
|
|
19661
|
-
import { z as
|
|
19903
|
+
import { z as z9 } from "zod";
|
|
19662
19904
|
function stableConflictKey(left, right) {
|
|
19663
19905
|
const [a, b] = [left, right].slice().sort();
|
|
19664
19906
|
let h4 = 2166136261;
|
|
@@ -19803,46 +20045,46 @@ var PlanItemSchema, SeatRiskSchema, SeatChallengeSchema, SeatAlternativeSchema,
|
|
|
19803
20045
|
var init_plan2 = __esm({
|
|
19804
20046
|
"packages/core/src/agent/council/plan.ts"() {
|
|
19805
20047
|
"use strict";
|
|
19806
|
-
PlanItemSchema =
|
|
19807
|
-
id:
|
|
19808
|
-
title:
|
|
19809
|
-
detail:
|
|
20048
|
+
PlanItemSchema = z9.object({
|
|
20049
|
+
id: z9.string(),
|
|
20050
|
+
title: z9.string(),
|
|
20051
|
+
detail: z9.string(),
|
|
19810
20052
|
/** 涉及文件(席位用只读工具定位后结构化输出)。 */
|
|
19811
|
-
files:
|
|
20053
|
+
files: z9.array(z9.string()).optional()
|
|
19812
20054
|
});
|
|
19813
|
-
SeatRiskSchema =
|
|
19814
|
-
claim:
|
|
19815
|
-
severity:
|
|
19816
|
-
mitigation:
|
|
20055
|
+
SeatRiskSchema = z9.object({
|
|
20056
|
+
claim: z9.string(),
|
|
20057
|
+
severity: z9.enum(["low", "medium", "high"]),
|
|
20058
|
+
mitigation: z9.string(),
|
|
19817
20059
|
/** 关联条目 id;缺省 = 泛化风险(不参与 id 相关性匹配)。 */
|
|
19818
|
-
itemId:
|
|
20060
|
+
itemId: z9.string().optional()
|
|
19819
20061
|
});
|
|
19820
|
-
SeatChallengeSchema =
|
|
19821
|
-
text:
|
|
20062
|
+
SeatChallengeSchema = z9.object({
|
|
20063
|
+
text: z9.string(),
|
|
19822
20064
|
/** blocking = 否决级:未化解前拒绝产出可执行计划。缺省 advisory。 */
|
|
19823
|
-
severity:
|
|
20065
|
+
severity: z9.enum(["advisory", "blocking"]).optional(),
|
|
19824
20066
|
/** 针对的条目 id;缺省 = 全局质疑。 */
|
|
19825
|
-
itemId:
|
|
20067
|
+
itemId: z9.string().optional()
|
|
19826
20068
|
});
|
|
19827
|
-
SeatAlternativeSchema =
|
|
19828
|
-
proposal:
|
|
19829
|
-
recommend:
|
|
19830
|
-
rationale:
|
|
19831
|
-
targetItemId:
|
|
20069
|
+
SeatAlternativeSchema = z9.object({
|
|
20070
|
+
proposal: z9.string(),
|
|
20071
|
+
recommend: z9.boolean(),
|
|
20072
|
+
rationale: z9.string(),
|
|
20073
|
+
targetItemId: z9.string().optional()
|
|
19832
20074
|
});
|
|
19833
|
-
SeatContributionSchema =
|
|
19834
|
-
authority:
|
|
19835
|
-
summary:
|
|
19836
|
-
additions:
|
|
19837
|
-
risks:
|
|
19838
|
-
challenges:
|
|
19839
|
-
alternatives:
|
|
20075
|
+
SeatContributionSchema = z9.object({
|
|
20076
|
+
authority: z9.string().min(1),
|
|
20077
|
+
summary: z9.string(),
|
|
20078
|
+
additions: z9.array(PlanItemSchema).default([]),
|
|
20079
|
+
risks: z9.array(SeatRiskSchema).default([]),
|
|
20080
|
+
challenges: z9.array(SeatChallengeSchema).default([]),
|
|
20081
|
+
alternatives: z9.array(SeatAlternativeSchema).default([])
|
|
19840
20082
|
});
|
|
19841
20083
|
}
|
|
19842
20084
|
});
|
|
19843
20085
|
|
|
19844
20086
|
// packages/core/src/agent/council/tools.ts
|
|
19845
|
-
import { z as
|
|
20087
|
+
import { z as z10 } from "zod";
|
|
19846
20088
|
async function runCouncil(service, opts, compact) {
|
|
19847
20089
|
const { objective, draft, seats, maxRounds, timeoutMs, caller } = opts;
|
|
19848
20090
|
const isSeatEstablished = (authority) => service.listMemberViews().some((m) => m.name === authority);
|
|
@@ -20325,12 +20567,12 @@ var init_tools2 = __esm({
|
|
|
20325
20567
|
}
|
|
20326
20568
|
};
|
|
20327
20569
|
COMPILE_SUBJECT_MAX = 200;
|
|
20328
|
-
RebuttalsSchema =
|
|
20329
|
-
rebuttals:
|
|
20330
|
-
|
|
20331
|
-
conflictKey:
|
|
20332
|
-
stance:
|
|
20333
|
-
argument:
|
|
20570
|
+
RebuttalsSchema = z10.object({
|
|
20571
|
+
rebuttals: z10.array(
|
|
20572
|
+
z10.object({
|
|
20573
|
+
conflictKey: z10.string(),
|
|
20574
|
+
stance: z10.enum(["concede", "hold", "revise"]),
|
|
20575
|
+
argument: z10.string()
|
|
20334
20576
|
})
|
|
20335
20577
|
)
|
|
20336
20578
|
});
|
|
@@ -21222,7 +21464,7 @@ var init_run_registry = __esm({
|
|
|
21222
21464
|
});
|
|
21223
21465
|
|
|
21224
21466
|
// packages/core/src/llm/env.ts
|
|
21225
|
-
import { z as
|
|
21467
|
+
import { z as z11 } from "zod";
|
|
21226
21468
|
function parseVisionModels(raw) {
|
|
21227
21469
|
const out = {};
|
|
21228
21470
|
if (raw.trim() === "") return out;
|
|
@@ -21258,22 +21500,22 @@ var EnvSchema, MAX_CHARS_PER_TOKEN, DEFAULT_CHARS_PER_TOKEN;
|
|
|
21258
21500
|
var init_env = __esm({
|
|
21259
21501
|
"packages/core/src/llm/env.ts"() {
|
|
21260
21502
|
"use strict";
|
|
21261
|
-
EnvSchema =
|
|
21262
|
-
DALUO_LLM_BASE_URL:
|
|
21263
|
-
DALUO_LLM_API_KEY:
|
|
21264
|
-
DALUO_LLM_MODEL:
|
|
21503
|
+
EnvSchema = z11.object({
|
|
21504
|
+
DALUO_LLM_BASE_URL: z11.string().url(),
|
|
21505
|
+
DALUO_LLM_API_KEY: z11.string().min(1),
|
|
21506
|
+
DALUO_LLM_MODEL: z11.string().min(1),
|
|
21265
21507
|
// 可选旋钮:单请求最大重试次数(0=只试 1 次);模型 fallback 链(逗号分隔)
|
|
21266
|
-
DALUO_LLM_MAX_RETRIES:
|
|
21267
|
-
DALUO_LLM_FALLBACK_MODELS:
|
|
21508
|
+
DALUO_LLM_MAX_RETRIES: z11.coerce.number().int().min(0).max(20).optional(),
|
|
21509
|
+
DALUO_LLM_FALLBACK_MODELS: z11.string().optional(),
|
|
21268
21510
|
// 可选旋钮:单请求**首字节**超时 ms(spec/llm-transport.md 明写「默认如 120s,可配」——
|
|
21269
21511
|
// 此前只有构造函数入参,产品入口从不传,于是 env 根本配不了)。慢端点 / 超大上下文下
|
|
21270
21512
|
// 120s 首字节不够:实测 20 万 token 级上下文写产物的那次请求被 120s 掐死(前面读了 16 分钟全白烧)。
|
|
21271
|
-
DALUO_LLM_TIMEOUT_MS:
|
|
21513
|
+
DALUO_LLM_TIMEOUT_MS: z11.coerce.number().int().min(1e3).optional(),
|
|
21272
21514
|
// **模型的上下文窗口**(token)——**由客户在配置 provider 时声明**(2026-09-15 用户裁定)。
|
|
21273
21515
|
// 为什么不下一个产品默认值:窗口是「模型/提供商」的属性,随 provider 而变;替客户猜(无论猜 64k 还是 1M)
|
|
21274
21516
|
// 都会在某个组合上错——猜小则每轮压缩(实测活锁:阈值仅 31k → 200 轮零产出),猜大则撞窗口 400。
|
|
21275
21517
|
// 未声明时按仓库既有保守默认(`DEFAULT_CONTEXT_WINDOW_TOKENS = 128k`)压缩,见 session/context-budget.ts。
|
|
21276
|
-
DALUO_LLM_CONTEXT_WINDOW_TOKENS:
|
|
21518
|
+
DALUO_LLM_CONTEXT_WINDOW_TOKENS: z11.coerce.number().int().min(1e3).optional(),
|
|
21277
21519
|
/**
|
|
21278
21520
|
* **模型支持图像输入吗(兜底层)**——同 `DALUO_LLM_CONTEXT_WINDOW_TOKENS`:由客户在配置 provider 时声明。
|
|
21279
21521
|
* 为什么不下一个「大概支持」的默认值:视觉是模型/提供商的属性,替客户猜会在某个组合上错
|
|
@@ -21282,24 +21524,24 @@ var init_env = __esm({
|
|
|
21282
21524
|
* 语义(2026-09-20 演进):这是**兜底**;**模型级声明走 `DALUO_LLM_VISION_MODELS`**(解析点在
|
|
21283
21525
|
* `LlmClient.supportsVision`:模型条目 ?? 这里兜底——换模型即换能力位,不用重解析 env)。
|
|
21284
21526
|
*/
|
|
21285
|
-
DALUO_LLM_VISION:
|
|
21527
|
+
DALUO_LLM_VISION: z11.enum(["1", "0", "true", "false", "on", "off"]).optional(),
|
|
21286
21528
|
/**
|
|
21287
21529
|
* **每模型视觉能力表**:`模型=1|0` 逗号分隔(cli 由提供方条目的 `models[].vision` 生成)。
|
|
21288
21530
|
* 坏格式 fail loud(loadLlmConfig 抛)——能力位是权限级声明,宽容解析会把「写错了」悄悄变成「没声明」。
|
|
21289
21531
|
*/
|
|
21290
|
-
DALUO_LLM_VISION_MODELS:
|
|
21532
|
+
DALUO_LLM_VISION_MODELS: z11.string().optional(),
|
|
21291
21533
|
/**
|
|
21292
21534
|
* **每模型 token 密度表**:`模型=值` 逗号分隔(cli 由提供方条目的 `models[].charsPerToken` 生成)。
|
|
21293
21535
|
* 坏格式 fail loud(`loadLlmConfig` 抛)——密度影响压缩阈值,宽容解析会把「写错了」悄悄变成「没声明」。
|
|
21294
21536
|
*/
|
|
21295
|
-
DALUO_LLM_CHARS_PER_TOKEN_MODELS:
|
|
21537
|
+
DALUO_LLM_CHARS_PER_TOKEN_MODELS: z11.string().optional(),
|
|
21296
21538
|
/**
|
|
21297
21539
|
* **token 密度兜底**:1 个 token 约等于多少字符(`spec/token-meter.md`,`P1-28`)。
|
|
21298
21540
|
* 为什么要有它:仓库缺省是 4 字符/token,对中文**低估** ⇒ 中文长会话压缩触发偏晚。
|
|
21299
21541
|
* 中文密集的模型可以在这里(或提供方/模型条目里)声明真实密度。
|
|
21300
21542
|
* 区间 (0, 64]:0 / 负 / 荒谬大值 fail loud,不给「悄悄夹到合法区间」的魔法。
|
|
21301
21543
|
*/
|
|
21302
|
-
DALUO_LLM_CHARS_PER_TOKEN:
|
|
21544
|
+
DALUO_LLM_CHARS_PER_TOKEN: z11.coerce.number().gt(0).max(64).optional(),
|
|
21303
21545
|
/**
|
|
21304
21546
|
* **流式请求要不要 `stream_options.include_usage`**(缺省要)——`DALUO_LLM_STREAM_USAGE=0` 关。
|
|
21305
21547
|
*
|
|
@@ -21308,7 +21550,7 @@ var init_env = __esm({
|
|
|
21308
21550
|
* 为什么留这个关:有的自建网关对未知字段直接 400——**端点脾气不该由代码猜**(不做「400 就自动不写」
|
|
21309
21551
|
* 那种魔法:它会让「字段被拒」与「端点坏了」表现为同一种故障),给一个显式开关。
|
|
21310
21552
|
*/
|
|
21311
|
-
DALUO_LLM_STREAM_USAGE:
|
|
21553
|
+
DALUO_LLM_STREAM_USAGE: z11.enum(["0", "1", "false", "true", "off", "on"]).optional(),
|
|
21312
21554
|
/**
|
|
21313
21555
|
* **生成参数**(spec/llm-transport.md「请求体生成参数」演进节,`G7-03`):输出长度上限与温度。
|
|
21314
21556
|
*
|
|
@@ -21317,8 +21559,25 @@ var init_env = __esm({
|
|
|
21317
21559
|
* 非法值 fail loud(zod 直接拒)——不给「悄悄夹到合法区间」的魔法:那会把「配置写错了」
|
|
21318
21560
|
* 变成「行为莫名其妙」。
|
|
21319
21561
|
*/
|
|
21320
|
-
DALUO_LLM_MAX_TOKENS:
|
|
21321
|
-
DALUO_LLM_TEMPERATURE:
|
|
21562
|
+
DALUO_LLM_MAX_TOKENS: z11.coerce.number().int().min(1).optional(),
|
|
21563
|
+
DALUO_LLM_TEMPERATURE: z11.coerce.number().min(0).max(2).optional(),
|
|
21564
|
+
/**
|
|
21565
|
+
* **结构化输出开关**(`response_format`,`spec/llm-transport.md` 演进「`response_format` 开关」,2026-10-22)。
|
|
21566
|
+
*
|
|
21567
|
+
* 三档,缺省 `off`(一个字节都不发——与改动前逐字等价):
|
|
21568
|
+
* - `off`:不发。**总开关**:即使调用级显式要求也不发(用户说关就关)。
|
|
21569
|
+
* - `structured`:只给**显式要求结构化**的调用发(`completeStructured`:guardian / auto-memory /
|
|
21570
|
+
* council 席位)。主循环不受影响 ⇒ 助手正文仍是人话。
|
|
21571
|
+
* - `always`:所有请求都发。**代价如实记**:`content` 会被上游强制成 JSON,于是纯文本轮的回答
|
|
21572
|
+
* 在会话里就是一段 JSON 串(工具轮不受影响:照常返回 `tool_calls`)。
|
|
21573
|
+
*
|
|
21574
|
+
* **为什么做成开关而不是默认开**:①上游(DeepSeek 系)要求 prompt 里必须出现 `json` 字样,
|
|
21575
|
+
* 否则直接 400——这是**调用方的 prompt 责任**,不能由我们在 system 里硬塞一句(那是污染缓存前缀);
|
|
21576
|
+
* ②实测(2026-10-22,同一网关 24 次带 tools 的请求)不带这个参数时工具参数**零破坏**,
|
|
21577
|
+
* 没有基线失败可修 ⇒ 默认开等于为一个测不出收益的东西改所有会话的请求体;
|
|
21578
|
+
* ③它有已知副作用(空 `content` 概率、正文变 JSON),必须由知道代价的人开。
|
|
21579
|
+
*/
|
|
21580
|
+
DALUO_LLM_RESPONSE_FORMAT: z11.enum(["off", "structured", "always"]).optional()
|
|
21322
21581
|
}).transform((env) => {
|
|
21323
21582
|
const out = {
|
|
21324
21583
|
baseUrl: env.DALUO_LLM_BASE_URL,
|
|
@@ -21339,6 +21598,7 @@ var init_env = __esm({
|
|
|
21339
21598
|
if (env.DALUO_LLM_MAX_TOKENS !== void 0) generation.maxTokens = env.DALUO_LLM_MAX_TOKENS;
|
|
21340
21599
|
if (env.DALUO_LLM_TEMPERATURE !== void 0) generation.temperature = env.DALUO_LLM_TEMPERATURE;
|
|
21341
21600
|
if (Object.keys(generation).length > 0) out.generation = generation;
|
|
21601
|
+
if (env.DALUO_LLM_RESPONSE_FORMAT !== void 0) out.responseFormatMode = env.DALUO_LLM_RESPONSE_FORMAT;
|
|
21342
21602
|
const fallback = (env.DALUO_LLM_FALLBACK_MODELS ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
21343
21603
|
if (fallback.length > 0) out.fallbackModels = fallback;
|
|
21344
21604
|
return out;
|
|
@@ -21729,7 +21989,7 @@ var init_read_file = __esm({
|
|
|
21729
21989
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
21730
21990
|
import { realpathSync as realpathSync6 } from "node:fs";
|
|
21731
21991
|
import { mkdir as mkdir8, readdir as readdir6, rename as rename3, stat as stat12, unlink as unlink6, writeFile as writeFile5 } from "node:fs/promises";
|
|
21732
|
-
import { basename as
|
|
21992
|
+
import { basename as basename9, dirname as dirname10, join as join23, resolve as resolve7 } from "node:path";
|
|
21733
21993
|
function \u662F\u81EA\u5BB6tmp(\u540D\u5B57, \u76EE\u6807\u540D) {
|
|
21734
21994
|
const \u524D\u7F00 = `${\u76EE\u6807\u540D}.`;
|
|
21735
21995
|
if (!\u540D\u5B57.startsWith(\u524D\u7F00)) return false;
|
|
@@ -21741,7 +22001,7 @@ function \u89C4\u8303\u6027\u8DEF\u5F84(path) {
|
|
|
21741
22001
|
return realpathSync6(\u7EDD\u5BF9);
|
|
21742
22002
|
} catch {
|
|
21743
22003
|
try {
|
|
21744
|
-
return join23(realpathSync6(dirname10(\u7EDD\u5BF9)),
|
|
22004
|
+
return join23(realpathSync6(dirname10(\u7EDD\u5BF9)), basename9(\u7EDD\u5BF9));
|
|
21745
22005
|
} catch {
|
|
21746
22006
|
return \u7EDD\u5BF9;
|
|
21747
22007
|
}
|
|
@@ -21749,7 +22009,7 @@ function \u89C4\u8303\u6027\u8DEF\u5F84(path) {
|
|
|
21749
22009
|
}
|
|
21750
22010
|
async function \u6E05\u8001tmp(path) {
|
|
21751
22011
|
const \u76EE\u5F55 = dirname10(path);
|
|
21752
|
-
const \u76EE\u6807\u540D =
|
|
22012
|
+
const \u76EE\u6807\u540D = basename9(path);
|
|
21753
22013
|
let \u540D\u5B57s;
|
|
21754
22014
|
try {
|
|
21755
22015
|
\u540D\u5B57s = await readdir6(\u76EE\u5F55);
|
|
@@ -22153,7 +22413,7 @@ var init_multiedit = __esm({
|
|
|
22153
22413
|
// packages/core/src/agent/tools/grep-glob.ts
|
|
22154
22414
|
import { execFile as execFile5 } from "node:child_process";
|
|
22155
22415
|
import { promisify as promisify4 } from "node:util";
|
|
22156
|
-
import { basename as
|
|
22416
|
+
import { basename as basename10, join as join24, relative as relative2, resolve as resolve8, isAbsolute as isAbsolute5 } from "node:path";
|
|
22157
22417
|
import { readdir as readdir7, readFile as readFile10, stat as stat13 } from "node:fs/promises";
|
|
22158
22418
|
async function hasRg() {
|
|
22159
22419
|
if (rgProbe !== void 0) return !!await rgProbe();
|
|
@@ -22257,7 +22517,7 @@ function matchGlob(relPosix, pattern) {
|
|
|
22257
22517
|
compiled = { re: new RegExp("^" + globBody(pat) + "$"), basenameOnly };
|
|
22258
22518
|
globReCache.set(key, compiled);
|
|
22259
22519
|
}
|
|
22260
|
-
return compiled.re.test(compiled.basenameOnly ?
|
|
22520
|
+
return compiled.re.test(compiled.basenameOnly ? basename10(relPosix) : relPosix);
|
|
22261
22521
|
}
|
|
22262
22522
|
async function nodeGlob(root, pattern, excludes) {
|
|
22263
22523
|
const deadline = Date.now() + SEARCH_TIMEOUT_MS;
|
|
@@ -22507,7 +22767,7 @@ var init_grep_glob = __esm({
|
|
|
22507
22767
|
sandbox
|
|
22508
22768
|
);
|
|
22509
22769
|
all = stdout.split("\n").filter((l) => l.trim()).map((l) => {
|
|
22510
|
-
const abs =
|
|
22770
|
+
const abs = isAbsolute5(l) ? l : resolve8(searchPath, l);
|
|
22511
22771
|
return relative2(searchPath, abs).replaceAll("\\", "/");
|
|
22512
22772
|
}).reverse();
|
|
22513
22773
|
} else {
|
|
@@ -23023,7 +23283,7 @@ var init_memory2 = __esm({
|
|
|
23023
23283
|
|
|
23024
23284
|
// packages/core/src/lsp/client.ts
|
|
23025
23285
|
import { spawn as spawn4 } from "node:child_process";
|
|
23026
|
-
import { basename as
|
|
23286
|
+
import { basename as basename11 } from "node:path";
|
|
23027
23287
|
import { pathToFileURL } from "node:url";
|
|
23028
23288
|
function \u5934\u5C3E\u5206\u9694(buf) {
|
|
23029
23289
|
const \u53CC = buf.indexOf("\r\n\r\n");
|
|
@@ -23079,7 +23339,7 @@ var init_client2 = __esm({
|
|
|
23079
23339
|
get workspaceFolders() {
|
|
23080
23340
|
const dir = this.cfg.cwd;
|
|
23081
23341
|
if (!dir) return [];
|
|
23082
|
-
return [{ uri: pathToFileURL(dir).href, name:
|
|
23342
|
+
return [{ uri: pathToFileURL(dir).href, name: basename11(dir) || dir }];
|
|
23083
23343
|
}
|
|
23084
23344
|
/**
|
|
23085
23345
|
* 应答 server→client 的**请求**(带 id 且带 method)。
|
|
@@ -23768,7 +24028,7 @@ var init_manager = __esm({
|
|
|
23768
24028
|
});
|
|
23769
24029
|
|
|
23770
24030
|
// packages/core/src/lsp/env.ts
|
|
23771
|
-
import { z as
|
|
24031
|
+
import { z as z12 } from "zod";
|
|
23772
24032
|
function parseLspServersEnv(env) {
|
|
23773
24033
|
const raw = env.DALUO_LSP_SERVERS;
|
|
23774
24034
|
if (raw === void 0 || raw.trim() === "") return void 0;
|
|
@@ -23794,18 +24054,18 @@ var LspServerConfigSchema;
|
|
|
23794
24054
|
var init_env2 = __esm({
|
|
23795
24055
|
"packages/core/src/lsp/env.ts"() {
|
|
23796
24056
|
"use strict";
|
|
23797
|
-
LspServerConfigSchema =
|
|
23798
|
-
command:
|
|
23799
|
-
args:
|
|
23800
|
-
extensions:
|
|
24057
|
+
LspServerConfigSchema = z12.object({
|
|
24058
|
+
command: z12.string().min(1),
|
|
24059
|
+
args: z12.array(z12.string()).optional(),
|
|
24060
|
+
extensions: z12.array(z12.string()).optional(),
|
|
23801
24061
|
/**
|
|
23802
24062
|
* `G2-60`:这三个字段 `LspServerConfig` **一直声明着**(client 也一直用:spawn 的 cwd/env、
|
|
23803
24063
|
* 单请求超时缺省),但**解析器不认** —— zod 的缺省行为是丢掉未知键,于是用户写进
|
|
23804
24064
|
* `DALUO_LSP_SERVERS` 的 `cwd` / `env` / `timeoutMs` 被**静默丢弃**(配置写着不生效,最难查)。
|
|
23805
24065
|
*/
|
|
23806
|
-
cwd:
|
|
23807
|
-
env:
|
|
23808
|
-
timeoutMs:
|
|
24066
|
+
cwd: z12.string().min(1).optional(),
|
|
24067
|
+
env: z12.record(z12.string(), z12.string()).optional(),
|
|
24068
|
+
timeoutMs: z12.number().int().positive().optional()
|
|
23809
24069
|
});
|
|
23810
24070
|
}
|
|
23811
24071
|
});
|
|
@@ -24592,7 +24852,12 @@ function createTerminalTool(config) {
|
|
|
24592
24852
|
}
|
|
24593
24853
|
if (action === "open") {
|
|
24594
24854
|
if (loadPty() === null) {
|
|
24595
|
-
return {
|
|
24855
|
+
return {
|
|
24856
|
+
kind: "error",
|
|
24857
|
+
// 「没装」最常见的原因是**瘦安装**(`--omit=optional`):那是有意为之、不是故障,
|
|
24858
|
+
// 所以把话说到「怎么拿回来」,而不是让用户去猜原生依赖为什么缺。
|
|
24859
|
+
message: "\u672C\u673A\u62FF\u4E0D\u5230 node-pty\uFF08\u539F\u751F\u4F9D\u8D56\u6CA1\u88C5\u6216\u5B89\u88C5\u811A\u672C\u88AB\u62E6\uFF09\u21D2 \u7EC8\u7AEF\u5DE5\u5177\u4E0D\u53EF\u7528\uFF1B\u6709\u754C\u547D\u4EE4\u8BF7\u7528 bash\u3002\u82E5\u5B89\u88C5\u65F6\u7528\u4E86 --omit=optional\uFF08\u7626\u5B89\u88C5\uFF09\uFF0C\u91CD\u88C5\u65F6\u4E0D\u5E26\u5B83\u5373\u53EF\uFF08npm i -g @daluo/cli\uFF09\u3002"
|
|
24860
|
+
};
|
|
24596
24861
|
}
|
|
24597
24862
|
if (owned.size >= 8) return { kind: "error", message: `\u5DF2\u7ECF\u5F00\u7740 ${owned.size} \u4E2A\u4F1A\u8BDD\uFF08\u4E0A\u9650 8\uFF09\uFF1A\u5148 close \u6389\u4E0D\u7528\u7684` };
|
|
24598
24863
|
const sandboxWs = typeof injected.sandbox?.workspace === "string" ? injected.sandbox.workspace : injected.cwd ?? config.cwd;
|
|
@@ -24786,7 +25051,7 @@ var init_git_commit = __esm({
|
|
|
24786
25051
|
|
|
24787
25052
|
// packages/core/src/computer-use/cua-driver.ts
|
|
24788
25053
|
import { execFile as execFile7 } from "node:child_process";
|
|
24789
|
-
import { createHash as
|
|
25054
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
24790
25055
|
import { readFile as readFile12 } from "node:fs/promises";
|
|
24791
25056
|
import { promisify as promisify6 } from "node:util";
|
|
24792
25057
|
function parseAllowedApps(env) {
|
|
@@ -24804,7 +25069,7 @@ function parseCodesignOutput(stderr) {
|
|
|
24804
25069
|
if (identifier === void 0 || identifier === "" || cdhash === void 0 || cdhash === "") return void 0;
|
|
24805
25070
|
const teamRaw = field("TeamIdentifier");
|
|
24806
25071
|
const team = teamRaw === void 0 || teamRaw === "not set" ? "" : teamRaw;
|
|
24807
|
-
return
|
|
25072
|
+
return createHash5("sha256").update(`${identifier}
|
|
24808
25073
|
${team}
|
|
24809
25074
|
${cdhash}`).digest("hex");
|
|
24810
25075
|
}
|
|
@@ -25103,7 +25368,9 @@ async function createComputerUseAssembly(input) {
|
|
|
25103
25368
|
}
|
|
25104
25369
|
const handle = await loadCuaDriver();
|
|
25105
25370
|
if (handle === null) {
|
|
25106
|
-
throw new Error(
|
|
25371
|
+
throw new Error(
|
|
25372
|
+
`${COMPUTER_USE_ENV}=cua-driver \u4F46\u539F\u751F\u4F9D\u8D56 @trycua/cua-driver \u52A0\u8F7D\u5931\u8D25\uFF08\u6CA1\u88C5\uFF1F\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\uFF1F\uFF09\u2014\u2014\u82E5\u5B89\u88C5\u65F6\u7528\u4E86 --omit=optional\uFF08\u7626\u5B89\u88C5\uFF09\u5C31\u4F1A\u8FD9\u6837\uFF1A\u91CD\u88C5\u65F6\u4E0D\u5E26\u5B83\u5373\u53EF\uFF08npm i -g @daluo/cli\uFF09\u3002`
|
|
25373
|
+
);
|
|
25107
25374
|
}
|
|
25108
25375
|
const decls = await listCuaTools(handle.driver);
|
|
25109
25376
|
const allowedAppsFile = input.allowedAppsFile;
|
|
@@ -25839,7 +26106,7 @@ var init_bash_command_scan = __esm({
|
|
|
25839
26106
|
});
|
|
25840
26107
|
|
|
25841
26108
|
// packages/core/src/agent/policy.ts
|
|
25842
|
-
import { resolve as resolve9, isAbsolute as
|
|
26109
|
+
import { resolve as resolve9, isAbsolute as isAbsolute6, join as join29, sep as sep3, dirname as dirname11 } from "node:path";
|
|
25843
26110
|
function \u53EA\u8BFB\u767D\u540D\u5355(config) {
|
|
25844
26111
|
const extra = config.extraReadOnlyPrograms;
|
|
25845
26112
|
if (extra === void 0 || extra.length === 0) return SAFE_READONLY_PROGRAMS;
|
|
@@ -26076,7 +26343,7 @@ function createPolicy(config) {
|
|
|
26076
26343
|
const \u53EA\u8BFB\u5DE5\u5177 = exec2.meta?.readOnly === true;
|
|
26077
26344
|
const \u53EF\u53CA\u6839 = \u53EA\u8BFB\u5DE5\u5177 ? [config.cwd, ...config.readOnlyRoots ?? []] : [config.cwd];
|
|
26078
26345
|
for (const path of paths) {
|
|
26079
|
-
const \u7EDD\u5BF9 = path === void 0 || path === "" ||
|
|
26346
|
+
const \u7EDD\u5BF9 = path === void 0 || path === "" || isAbsolute6(path) ? path : resolve9(\u57FA\u70B9, path);
|
|
26080
26347
|
if (\u7EDD\u5BF9 !== void 0 && \u7EDD\u5BF9 !== "" && !\u53EF\u53CA\u6839.some((\u6839) => isWithinDir(\u6839, \u7EDD\u5BF9))) {
|
|
26081
26348
|
const \u8BF4\u660E = \u53EA\u8BFB\u5DE5\u5177 && (config.readOnlyRoots?.length ?? 0) > 0 ? "\uFF08\u53EA\u8BFB\u767D\u540D\u5355\u91CC\u4E5F\u6CA1\u6709\u5B83\uFF09" : "";
|
|
26082
26349
|
if (!\u53EA\u8BFB\u5DE5\u5177) return { kind: "deny", reason: `\u8DEF\u5F84\u5728\u5141\u8BB8\u7684\u5DE5\u4F5C\u76EE\u5F55\u4E4B\u5916\uFF1A${\u7EDD\u5BF9}${\u8BF4\u660E}` };
|
|
@@ -26105,7 +26372,7 @@ function createPolicy(config) {
|
|
|
26105
26372
|
}
|
|
26106
26373
|
}
|
|
26107
26374
|
for (const path of paths) {
|
|
26108
|
-
const abs =
|
|
26375
|
+
const abs = isAbsolute6(path) ? path : resolve9(\u57FA\u70B9, path);
|
|
26109
26376
|
for (const ap of askPaths) {
|
|
26110
26377
|
if (abs === resolve9(config.cwd, ap) || abs.startsWith(resolve9(config.cwd, ap) + sep3)) {
|
|
26111
26378
|
return \u95EE(`${exec2.toolName} ${ap} \u9700\u7528\u6237\u786E\u8BA4\uFF08\u8DEF\u5F84 ${abs}\uFF09`, input, { \u53EF\u4F1A\u8BDD\u8BB0\u5FC6: true, \u98CE\u9669\u6863: "medium" });
|
|
@@ -26113,7 +26380,7 @@ function createPolicy(config) {
|
|
|
26113
26380
|
}
|
|
26114
26381
|
}
|
|
26115
26382
|
const singlePath = typeof input.path === "string" ? input.path : "";
|
|
26116
|
-
if (singlePath && !
|
|
26383
|
+
if (singlePath && !isAbsolute6(singlePath)) {
|
|
26117
26384
|
return {
|
|
26118
26385
|
kind: "allow",
|
|
26119
26386
|
input: {
|
|
@@ -26180,7 +26447,7 @@ var init_policy = __esm({
|
|
|
26180
26447
|
// packages/core/src/skill/fs-provider.ts
|
|
26181
26448
|
import { readdir as readdir8, readFile as readFile13 } from "node:fs/promises";
|
|
26182
26449
|
import { homedir as homedir4 } from "node:os";
|
|
26183
|
-
import { join as join30, delimiter as delimiter2, isAbsolute as
|
|
26450
|
+
import { join as join30, delimiter as delimiter2, isAbsolute as isAbsolute7 } from "node:path";
|
|
26184
26451
|
function unquote(v) {
|
|
26185
26452
|
const t = v.trim();
|
|
26186
26453
|
if (t.length >= 2 && (t.startsWith('"') && t.endsWith('"') || t.startsWith("'") && t.endsWith("'"))) {
|
|
@@ -26282,7 +26549,7 @@ function parseSkillMd(content, dirName) {
|
|
|
26282
26549
|
function skillRootsFromEnv(env) {
|
|
26283
26550
|
const raw = env[SKILL_ROOTS_ENV];
|
|
26284
26551
|
if (raw === void 0 || raw.trim() === "") return [];
|
|
26285
|
-
return raw.split(delimiter2).map((s) => s.trim()).filter((s) => s !== "" &&
|
|
26552
|
+
return raw.split(delimiter2).map((s) => s.trim()).filter((s) => s !== "" && isAbsolute7(s)).map((dir) => ({ dir, source: "env" }));
|
|
26286
26553
|
}
|
|
26287
26554
|
var FRONTMATTER_RE, BLOCK_SCALAR_RE, SKILL_ROOTS_ENV, FileSystemSkillProvider;
|
|
26288
26555
|
var init_fs_provider = __esm({
|
|
@@ -26596,7 +26863,7 @@ var init_goal_mode = __esm({
|
|
|
26596
26863
|
});
|
|
26597
26864
|
|
|
26598
26865
|
// packages/core/src/plugin/loader.ts
|
|
26599
|
-
import { isAbsolute as
|
|
26866
|
+
import { isAbsolute as isAbsolute8 } from "node:path";
|
|
26600
26867
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
26601
26868
|
function describeRow(row) {
|
|
26602
26869
|
if (row.state === "active") return `${row.id} (${row.source})\uFF1A\u5DF2\u88C5\u8F7D`;
|
|
@@ -26618,7 +26885,7 @@ function entryProblem(entry) {
|
|
|
26618
26885
|
}
|
|
26619
26886
|
function resolveEntrySpecifier(name, baseUrl) {
|
|
26620
26887
|
if (name.startsWith(".")) return new URL(name, baseUrl).href;
|
|
26621
|
-
if (
|
|
26888
|
+
if (isAbsolute8(name)) return pathToFileURL2(name).href;
|
|
26622
26889
|
return name;
|
|
26623
26890
|
}
|
|
26624
26891
|
async function \u7B49\u5019\u843D\u5B9A(p, deadlineMs) {
|
|
@@ -26736,7 +27003,7 @@ ${lines.join("\n")}`);
|
|
|
26736
27003
|
// packages/core/src/plugin/config.ts
|
|
26737
27004
|
import { existsSync as existsSync11 } from "node:fs";
|
|
26738
27005
|
import { homedir as homedir5 } from "node:os";
|
|
26739
|
-
import { dirname as dirname12, isAbsolute as
|
|
27006
|
+
import { dirname as dirname12, isAbsolute as isAbsolute9, join as join31, resolve as resolve10 } from "node:path";
|
|
26740
27007
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
26741
27008
|
async function resolvePluginConfig(input) {
|
|
26742
27009
|
const { cwd, env } = input;
|
|
@@ -26745,7 +27012,7 @@ async function resolvePluginConfig(input) {
|
|
|
26745
27012
|
const explicit = env[PLUGINS_FILE_ENV]?.trim();
|
|
26746
27013
|
let filePath;
|
|
26747
27014
|
if (explicit !== void 0 && explicit !== "") {
|
|
26748
|
-
filePath =
|
|
27015
|
+
filePath = isAbsolute9(explicit) ? explicit : resolve10(cwd, explicit);
|
|
26749
27016
|
if (!existsSync11(filePath)) throw new Error(`\u63D2\u4EF6\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${filePath}\uFF08\u6765\u81EA ${PLUGINS_FILE_ENV}\uFF09`);
|
|
26750
27017
|
} else {
|
|
26751
27018
|
const candidates = [
|
|
@@ -26803,7 +27070,7 @@ var init_config = __esm({
|
|
|
26803
27070
|
// packages/core/src/agent/guardian.ts
|
|
26804
27071
|
import { readFile as readFile14 } from "node:fs/promises";
|
|
26805
27072
|
import { resolve as resolve11 } from "node:path";
|
|
26806
|
-
import { z as
|
|
27073
|
+
import { z as z13 } from "zod";
|
|
26807
27074
|
function isHighRiskTool(toolName) {
|
|
26808
27075
|
return toolName === EDIT || toolName === WRITE_FILE || toolName === MULTIEDIT || toolName === BASH;
|
|
26809
27076
|
}
|
|
@@ -26821,7 +27088,10 @@ function reviewPrompt(toolName, input) {
|
|
|
26821
27088
|
].join("\n");
|
|
26822
27089
|
}
|
|
26823
27090
|
async function guardianReview(llm, toolName, input) {
|
|
26824
|
-
const res = await llm.complete([{ role: "user", content: reviewPrompt(toolName, input) }], {
|
|
27091
|
+
const res = await llm.complete([{ role: "user", content: reviewPrompt(toolName, input) }], {
|
|
27092
|
+
temperature: 0,
|
|
27093
|
+
responseFormat: "json_object"
|
|
27094
|
+
});
|
|
26825
27095
|
const \u89E3 = parseStructured(res.content, GUARDIAN_VERDICT);
|
|
26826
27096
|
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
27097
|
const { outcome, reason } = \u89E3.value;
|
|
@@ -26914,9 +27184,9 @@ var init_guardian = __esm({
|
|
|
26914
27184
|
"use strict";
|
|
26915
27185
|
init_structured();
|
|
26916
27186
|
init_names2();
|
|
26917
|
-
GUARDIAN_VERDICT =
|
|
26918
|
-
outcome:
|
|
26919
|
-
reason:
|
|
27187
|
+
GUARDIAN_VERDICT = z13.object({
|
|
27188
|
+
outcome: z13.enum(["approve", "deny", "review"]),
|
|
27189
|
+
reason: z13.string().optional()
|
|
26920
27190
|
});
|
|
26921
27191
|
CircuitBreaker = class {
|
|
26922
27192
|
failures = 0;
|
|
@@ -27249,6 +27519,7 @@ var init_src3 = __esm({
|
|
|
27249
27519
|
init_event_log();
|
|
27250
27520
|
init_jsonl();
|
|
27251
27521
|
init_project_paths();
|
|
27522
|
+
init_snapshot();
|
|
27252
27523
|
init_runner();
|
|
27253
27524
|
init_system_prompt();
|
|
27254
27525
|
init_subagent();
|
|
@@ -27400,9 +27671,9 @@ var init_ports = __esm({
|
|
|
27400
27671
|
});
|
|
27401
27672
|
|
|
27402
27673
|
// packages/core/src/session/external-import.ts
|
|
27403
|
-
import { createHash as
|
|
27674
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
27404
27675
|
import { readFile as readFile15 } from "node:fs/promises";
|
|
27405
|
-
import { basename as
|
|
27676
|
+
import { basename as basename12 } from "node:path";
|
|
27406
27677
|
function textOf(part) {
|
|
27407
27678
|
const t = part["type"];
|
|
27408
27679
|
if (t !== "text" && t !== "input_text" && t !== "output_text") return void 0;
|
|
@@ -27612,7 +27883,7 @@ function parseExternalSession(text2, format) {
|
|
|
27612
27883
|
return \u7528 === "claude" ? parseClaudeSession(text2) : parseCodexSession(text2);
|
|
27613
27884
|
}
|
|
27614
27885
|
function externalEntriesDigest(entries) {
|
|
27615
|
-
return
|
|
27886
|
+
return createHash6("sha256").update(JSON.stringify(entries), "utf8").digest("hex").slice(0, 16);
|
|
27616
27887
|
}
|
|
27617
27888
|
async function importExternalSession(opts) {
|
|
27618
27889
|
let text2;
|
|
@@ -27632,9 +27903,9 @@ async function importExternalSession(opts) {
|
|
|
27632
27903
|
}
|
|
27633
27904
|
const digest = externalEntriesDigest(parsed.entries);
|
|
27634
27905
|
const now = opts.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
|
|
27635
|
-
const \u6E90basename =
|
|
27906
|
+
const \u6E90basename = basename12(opts.sourceFile);
|
|
27636
27907
|
if (await fileIdentity(opts.targetFile) === void 0) {
|
|
27637
|
-
const sessionId2 = opts.sessionId ??
|
|
27908
|
+
const sessionId2 = opts.sessionId ?? basename12(opts.targetFile).replace(/\.jsonl$/, "");
|
|
27638
27909
|
if (sessionId2 === "") throw new LifecycleUserError(`importExternalSession: \u76EE\u6807\u6587\u4EF6\u540D\u65E0\u6CD5\u4F5C\u4E3A\u4F1A\u8BDD id\uFF1A${opts.targetFile}`);
|
|
27639
27910
|
const ts2 = now();
|
|
27640
27911
|
const events = [
|
|
@@ -27669,7 +27940,7 @@ async function importExternalSession(opts) {
|
|
|
27669
27940
|
const prev = log.state.importedFrom;
|
|
27670
27941
|
if (prev === void 0) {
|
|
27671
27942
|
throw new LifecycleUserError(
|
|
27672
|
-
`importExternalSession: \u76EE\u6807\u4F1A\u8BDD "${
|
|
27943
|
+
`importExternalSession: \u76EE\u6807\u4F1A\u8BDD "${basename12(opts.targetFile)}" \u4E0D\u662F\u5BFC\u5165\u6765\u7684\uFF08\u6CA1\u6709 session/imported\uFF09\u2014\u2014\u8981\u5BFC\u5165\u5230\u5B83\u8BF7\u53E6\u7ED9\u4E00\u4E2A\u76EE\u6807\u6587\u4EF6\u540D\uFF08\u672C\u4ED3\u4E0D\u5F80\u81EA\u5DF1\u7684\u4F1A\u8BDD\u91CC\u585E\u5916\u90E8\u5386\u53F2\uFF09`
|
|
27673
27944
|
);
|
|
27674
27945
|
}
|
|
27675
27946
|
if (prev.file !== \u6E90basename) {
|
|
@@ -28369,7 +28640,7 @@ var init_shared_snapshot = __esm({
|
|
|
28369
28640
|
|
|
28370
28641
|
// packages/core/src/session/lessons.ts
|
|
28371
28642
|
import { readdir as readdir10, stat as stat15 } from "node:fs/promises";
|
|
28372
|
-
import { basename as
|
|
28643
|
+
import { basename as basename13, join as join34 } from "node:path";
|
|
28373
28644
|
function \u5931\u8D25\u7B7E\u540D(error) {
|
|
28374
28645
|
const \u9996\u884C = error.split("\n")[0] ?? "";
|
|
28375
28646
|
return \u9996\u884C.trim().replace(/(?:\/[\w.\-+@%]+){2,}\/?/g, "<path>").replace(/[0-9a-f]{6,}/gi, "<hash>").replace(/\d+/g, "<n>").slice(0, 80);
|
|
@@ -28461,7 +28732,7 @@ async function mineLessons(dir, opts = {}) {
|
|
|
28461
28732
|
for (const { file } of entries) {
|
|
28462
28733
|
try {
|
|
28463
28734
|
const events = await loadEvents(file);
|
|
28464
|
-
\u5168\u90E8.push(...\u626B\u4E00\u4E2A\u4F1A\u8BDD(events,
|
|
28735
|
+
\u5168\u90E8.push(...\u626B\u4E00\u4E2A\u4F1A\u8BDD(events, basename13(file)));
|
|
28465
28736
|
} catch {
|
|
28466
28737
|
skipped += 1;
|
|
28467
28738
|
}
|
|
@@ -28500,8 +28771,8 @@ var init_lessons = __esm({
|
|
|
28500
28771
|
// packages/core/src/workspace/workspace.ts
|
|
28501
28772
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
28502
28773
|
import { realpath as realpath2, stat as stat16 } from "node:fs/promises";
|
|
28503
|
-
import { basename as
|
|
28504
|
-
import { z as
|
|
28774
|
+
import { basename as basename14 } from "node:path";
|
|
28775
|
+
import { z as z14 } from "zod";
|
|
28505
28776
|
function emptyRegistry() {
|
|
28506
28777
|
return { workspaces: [], unregistered: [], failures: [] };
|
|
28507
28778
|
}
|
|
@@ -28605,34 +28876,34 @@ var init_workspace = __esm({
|
|
|
28605
28876
|
"use strict";
|
|
28606
28877
|
init_log_io();
|
|
28607
28878
|
BaseSchema = {
|
|
28608
|
-
seq:
|
|
28609
|
-
ts:
|
|
28879
|
+
seq: z14.number().int().positive(),
|
|
28880
|
+
ts: z14.string()
|
|
28610
28881
|
};
|
|
28611
|
-
CreatedSchema =
|
|
28882
|
+
CreatedSchema = z14.object({
|
|
28612
28883
|
...BaseSchema,
|
|
28613
|
-
type:
|
|
28614
|
-
workspaceId:
|
|
28615
|
-
root:
|
|
28616
|
-
title:
|
|
28884
|
+
type: z14.literal("workspace/created"),
|
|
28885
|
+
workspaceId: z14.string(),
|
|
28886
|
+
root: z14.string(),
|
|
28887
|
+
title: z14.string()
|
|
28617
28888
|
});
|
|
28618
|
-
RenamedSchema =
|
|
28889
|
+
RenamedSchema = z14.object({
|
|
28619
28890
|
...BaseSchema,
|
|
28620
|
-
type:
|
|
28621
|
-
workspaceId:
|
|
28622
|
-
title:
|
|
28891
|
+
type: z14.literal("workspace/renamed"),
|
|
28892
|
+
workspaceId: z14.string(),
|
|
28893
|
+
title: z14.string()
|
|
28623
28894
|
});
|
|
28624
|
-
UnregisteredSchema =
|
|
28895
|
+
UnregisteredSchema = z14.object({
|
|
28625
28896
|
...BaseSchema,
|
|
28626
|
-
type:
|
|
28627
|
-
workspaceId:
|
|
28897
|
+
type: z14.literal("workspace/unregistered"),
|
|
28898
|
+
workspaceId: z14.string()
|
|
28628
28899
|
});
|
|
28629
|
-
ReorderedSchema =
|
|
28900
|
+
ReorderedSchema = z14.object({
|
|
28630
28901
|
...BaseSchema,
|
|
28631
|
-
type:
|
|
28632
|
-
workspaceId:
|
|
28633
|
-
before:
|
|
28902
|
+
type: z14.literal("workspace/reordered"),
|
|
28903
|
+
workspaceId: z14.string(),
|
|
28904
|
+
before: z14.string().optional()
|
|
28634
28905
|
});
|
|
28635
|
-
WorkspaceEvent =
|
|
28906
|
+
WorkspaceEvent = z14.discriminatedUnion("type", [
|
|
28636
28907
|
CreatedSchema,
|
|
28637
28908
|
RenamedSchema,
|
|
28638
28909
|
UnregisteredSchema,
|
|
@@ -28675,7 +28946,7 @@ var init_workspace = __esm({
|
|
|
28675
28946
|
const root = await resolveExistingDir(input.root);
|
|
28676
28947
|
const existing = findWorkspaceByRoot(this.current, root);
|
|
28677
28948
|
if (existing) return { workspaceId: existing.workspaceId, root, title: existing.title, created: false };
|
|
28678
|
-
const title = (input.title ??
|
|
28949
|
+
const title = (input.title ?? basename14(root)).trim();
|
|
28679
28950
|
const workspaceId = newWorkspaceId((id) => findWorkspaceById(this.current, id) !== void 0);
|
|
28680
28951
|
await this.append(this.nextEvent({ type: "workspace/created", workspaceId, root, title }));
|
|
28681
28952
|
return { workspaceId, root, title, created: true };
|
|
@@ -28735,7 +29006,7 @@ var init_workspace = __esm({
|
|
|
28735
29006
|
|
|
28736
29007
|
// packages/core/src/workspace/watch.ts
|
|
28737
29008
|
import { readdirSync, statSync as statSync3, watch as fsWatch } from "node:fs";
|
|
28738
|
-
import { basename as
|
|
29009
|
+
import { basename as basename15, join as join35, sep as sep4 } from "node:path";
|
|
28739
29010
|
function \u88AB\u5FFD\u7565(\u76F8\u5BF9\u8DEF\u5F84, \u5FFD\u7565\u6E05\u5355) {
|
|
28740
29011
|
if (\u76F8\u5BF9\u8DEF\u5F84 === "") return false;
|
|
28741
29012
|
const \u6BB5\u4EEC = \u76F8\u5BF9\u8DEF\u5F84.split("/");
|
|
@@ -28751,7 +29022,7 @@ function \u8F6Cposix(\u8DEF\u5F84) {
|
|
|
28751
29022
|
}
|
|
28752
29023
|
function \u771F\u5B9E\u76D1\u542C(\u6839, \u6536\u5230, \u5FFD\u7565) {
|
|
28753
29024
|
try {
|
|
28754
|
-
const \u6839\u540D =
|
|
29025
|
+
const \u6839\u540D = basename15(\u6839);
|
|
28755
29026
|
const w = fsWatch(\u6839, { recursive: true, persistent: false }, (_\u4E8B\u4EF6, \u540D) => {
|
|
28756
29027
|
const \u76F8\u5BF9 = \u540D === null || \u540D === void 0 ? "" : \u8F6Cposix(String(\u540D));
|
|
28757
29028
|
if (\u76F8\u5BF9 === \u6839\u540D) return;
|
|
@@ -30026,6 +30297,8 @@ __export(internal_exports, {
|
|
|
30026
30297
|
COMPACTION_WARN_MARK: () => COMPACTION_WARN_MARK,
|
|
30027
30298
|
COMPLETION_GUARD_STEP_ID: () => COMPLETION_GUARD_STEP_ID,
|
|
30028
30299
|
COMPUTER_USE_PROMPT: () => COMPUTER_USE_PROMPT,
|
|
30300
|
+
CONTEXT_WARN_BLOCK: () => CONTEXT_WARN_BLOCK,
|
|
30301
|
+
CONTEXT_WARN_RATIO: () => CONTEXT_WARN_RATIO,
|
|
30029
30302
|
CORRECTION_PREFIX: () => CORRECTION_PREFIX,
|
|
30030
30303
|
COUNCIL_KEEP_MESSAGES: () => COUNCIL_KEEP_MESSAGES,
|
|
30031
30304
|
CUA_TOOL_PREFIX: () => CUA_TOOL_PREFIX,
|
|
@@ -30038,6 +30311,7 @@ __export(internal_exports, {
|
|
|
30038
30311
|
ContentPartSchema: () => ContentPartSchema,
|
|
30039
30312
|
Context: () => Context,
|
|
30040
30313
|
ContextInjectedSchema: () => ContextInjectedSchema,
|
|
30314
|
+
ContextReportSchema: () => ContextReportSchema,
|
|
30041
30315
|
DALUO_FORMAT_VERSION: () => DALUO_FORMAT_VERSION,
|
|
30042
30316
|
DECLARE_UNVERIFIABLE: () => DECLARE_UNVERIFIABLE,
|
|
30043
30317
|
DEFAULT_ARGUMENTS_PREVIEW_CHARS: () => DEFAULT_ARGUMENTS_PREVIEW_CHARS,
|
|
@@ -30108,9 +30382,11 @@ __export(internal_exports, {
|
|
|
30108
30382
|
LifecycleUserError: () => LifecycleUserError,
|
|
30109
30383
|
LlmClient: () => LlmClient,
|
|
30110
30384
|
LlmHttpError: () => LlmHttpError,
|
|
30385
|
+
LlmResponseFormatError: () => LlmResponseFormatError,
|
|
30111
30386
|
LlmStreamError: () => LlmStreamError,
|
|
30112
30387
|
LlmStructuredError: () => LlmStructuredError,
|
|
30113
30388
|
LlmTimeoutError: () => LlmTimeoutError,
|
|
30389
|
+
LlmToolArgsError: () => LlmToolArgsError,
|
|
30114
30390
|
LlmUsageSchema: () => LlmUsageSchema,
|
|
30115
30391
|
LspServer: () => LspServer,
|
|
30116
30392
|
LspServerManager: () => LspServerManager,
|
|
@@ -30211,6 +30487,7 @@ __export(internal_exports, {
|
|
|
30211
30487
|
SETTING_COMPACTION_KEEP_TOKENS: () => SETTING_COMPACTION_KEEP_TOKENS,
|
|
30212
30488
|
SETTING_COMPACTION_LLM_SUMMARY: () => SETTING_COMPACTION_LLM_SUMMARY,
|
|
30213
30489
|
SETTING_COMPACTION_RESERVE_OUTPUT_TOKENS: () => SETTING_COMPACTION_RESERVE_OUTPUT_TOKENS,
|
|
30490
|
+
SETTING_LLM_RESPONSE_FORMAT: () => SETTING_LLM_RESPONSE_FORMAT,
|
|
30214
30491
|
SETTING_MODELS_KNOWN: () => SETTING_MODELS_KNOWN,
|
|
30215
30492
|
SETTING_MODEL_DEFAULT: () => SETTING_MODEL_DEFAULT,
|
|
30216
30493
|
SETTING_PERMISSION_READ_ONLY_PROGRAMS: () => SETTING_PERMISSION_READ_ONLY_PROGRAMS,
|
|
@@ -30232,6 +30509,7 @@ __export(internal_exports, {
|
|
|
30232
30509
|
SKILL_ROOTS_ENV: () => SKILL_ROOTS_ENV,
|
|
30233
30510
|
SKILL_TOOL_NAME: () => SKILL_TOOL_NAME,
|
|
30234
30511
|
SLOW_OP_DEFAULT_THRESHOLD_MS: () => SLOW_OP_DEFAULT_THRESHOLD_MS,
|
|
30512
|
+
SNAPSHOT_DIR_ENV: () => SNAPSHOT_DIR_ENV,
|
|
30235
30513
|
SNAPSHOT_GIT_TIMEOUT_MS: () => SNAPSHOT_GIT_TIMEOUT_MS,
|
|
30236
30514
|
SNAPSHOT_MAX_FILE_BYTES: () => SNAPSHOT_MAX_FILE_BYTES,
|
|
30237
30515
|
SPAWN_TEAMMATE: () => SPAWN_TEAMMATE,
|
|
@@ -30380,6 +30658,7 @@ __export(internal_exports, {
|
|
|
30380
30658
|
charsPerTokenForModel: () => charsPerTokenForModel,
|
|
30381
30659
|
charsPerTokenOf: () => charsPerTokenOf,
|
|
30382
30660
|
chatMessageChars: () => chatMessageChars,
|
|
30661
|
+
checkpointLabelOf: () => checkpointLabelOf,
|
|
30383
30662
|
checkpointLabelWithSeq: () => checkpointLabelWithSeq,
|
|
30384
30663
|
checkpointSeqOf: () => checkpointSeqOf,
|
|
30385
30664
|
childCompactBudget: () => childCompactBudget,
|
|
@@ -30408,6 +30687,7 @@ __export(internal_exports, {
|
|
|
30408
30687
|
connectMcpServer: () => connectMcpServer,
|
|
30409
30688
|
contextAnchorTokens: () => contextAnchorTokens,
|
|
30410
30689
|
contextThresholdTokens: () => contextThresholdTokens,
|
|
30690
|
+
contextWindowOf: () => contextWindowOf,
|
|
30411
30691
|
controlledTerminalEnv: () => controlledTerminalEnv,
|
|
30412
30692
|
cosineSimilarity: () => cosineSimilarity,
|
|
30413
30693
|
costForEvents: () => costForEvents,
|
|
@@ -30611,6 +30891,7 @@ __export(internal_exports, {
|
|
|
30611
30891
|
memoryTarget: () => memoryTarget,
|
|
30612
30892
|
mergeGeneration: () => mergeGeneration,
|
|
30613
30893
|
mergeTools: () => mergeTools,
|
|
30894
|
+
messagesMentionJson: () => messagesMentionJson,
|
|
30614
30895
|
mineLessons: () => mineLessons,
|
|
30615
30896
|
multieditTool: () => multieditTool,
|
|
30616
30897
|
nextPendingInput: () => nextPendingInput,
|
|
@@ -30722,7 +31003,9 @@ __export(internal_exports, {
|
|
|
30722
31003
|
resolvePermissionAnswer: () => resolvePermissionAnswer,
|
|
30723
31004
|
resolvePluginConfig: () => resolvePluginConfig,
|
|
30724
31005
|
resolvePublicHost: () => resolvePublicHost,
|
|
31006
|
+
resolveResponseFormat: () => resolveResponseFormat,
|
|
30725
31007
|
resolveSessionIndex: () => resolveSessionIndex,
|
|
31008
|
+
resolveSnapshotDir: () => resolveSnapshotDir,
|
|
30726
31009
|
resolveSubagentRoles: () => resolveSubagentRoles,
|
|
30727
31010
|
restoreCheckpoint: () => restoreCheckpoint,
|
|
30728
31011
|
restoreMemoryStores: () => restoreMemoryStores,
|
|
@@ -30809,6 +31092,7 @@ __export(internal_exports, {
|
|
|
30809
31092
|
versionHeaderLine: () => versionHeaderLine,
|
|
30810
31093
|
warnSummaryDegraded: () => warnSummaryDegraded,
|
|
30811
31094
|
windowTokensForModel: () => windowTokensForModel,
|
|
31095
|
+
workspaceKeyOf: () => workspaceKeyOf,
|
|
30812
31096
|
worktreeDiskUsage: () => worktreeDiskUsage,
|
|
30813
31097
|
worktreesDirOf: () => worktreesDirOf,
|
|
30814
31098
|
writeFileTool: () => writeFileTool,
|
|
@@ -30883,6 +31167,8 @@ __export(internal_exports, {
|
|
|
30883
31167
|
\u8F6Cposix: () => \u8F6Cposix,
|
|
30884
31168
|
\u8FDB\u7A0B\u72B6\u6001: () => \u8FDB\u7A0B\u72B6\u6001,
|
|
30885
31169
|
\u906E\u853D\u68C0\u6D4B: () => \u906E\u853D\u68C0\u6D4B,
|
|
31170
|
+
\u9876\u5C42\u9519\u4F4D\u63D0\u793A: () => \u9876\u5C42\u9519\u4F4D\u63D0\u793A,
|
|
31171
|
+
\u9876\u5C42\u9519\u4F4D\u952E: () => \u9876\u5C42\u9519\u4F4D\u952E,
|
|
30886
31172
|
\u9879\u76EE\u7EA7\u5FFD\u7565\u63D0\u793A: () => \u9879\u76EE\u7EA7\u5FFD\u7565\u63D0\u793A
|
|
30887
31173
|
});
|
|
30888
31174
|
var init_internal = __esm({
|
|
@@ -31080,6 +31366,12 @@ async function resolveLlmEnv(input) {
|
|
|
31080
31366
|
const temperature = input.processEnv.DALUO_LLM_TEMPERATURE ?? dotenv.DALUO_LLM_TEMPERATURE;
|
|
31081
31367
|
if (maxTokens !== void 0) out.DALUO_LLM_MAX_TOKENS = maxTokens;
|
|
31082
31368
|
if (temperature !== void 0) out.DALUO_LLM_TEMPERATURE = temperature;
|
|
31369
|
+
const \u8BBE\u7F6E\u91CC\u7684\u6863 = stringSetting(
|
|
31370
|
+
loadSettingsSync2(globalSettingsFile(configHome, { create: false })),
|
|
31371
|
+
SETTING_LLM_RESPONSE_FORMAT
|
|
31372
|
+
);
|
|
31373
|
+
const responseFormat = \u8BBE\u7F6E\u91CC\u7684\u6863 ?? input.processEnv.DALUO_LLM_RESPONSE_FORMAT ?? dotenv.DALUO_LLM_RESPONSE_FORMAT;
|
|
31374
|
+
if (responseFormat !== void 0) out.DALUO_LLM_RESPONSE_FORMAT = responseFormat;
|
|
31083
31375
|
return out;
|
|
31084
31376
|
}
|
|
31085
31377
|
var init_user_config2 = __esm({
|
|
@@ -31232,7 +31524,7 @@ var init_usage2 = __esm({
|
|
|
31232
31524
|
// packages/cli/src/cli-shared.ts
|
|
31233
31525
|
import { existsSync as existsSync15, readFileSync as readFileSync11, statSync as statSync4 } from "node:fs";
|
|
31234
31526
|
import "node:os";
|
|
31235
|
-
import { isAbsolute as
|
|
31527
|
+
import { isAbsolute as isAbsolute10, join as join38, resolve as resolve12 } from "node:path";
|
|
31236
31528
|
import { createInterface } from "node:readline/promises";
|
|
31237
31529
|
function loadDotEnv(file) {
|
|
31238
31530
|
const out = {};
|
|
@@ -31455,7 +31747,7 @@ async function setupSession(input) {
|
|
|
31455
31747
|
readRoots: () => [...\u53EF\u8BFB\u6839],
|
|
31456
31748
|
readRootsWithSource: () => \u53EF\u8BFB\u6839.map((dir) => ({ dir, from: [...\u6839\u6765\u6E90.get(dir) ?? []] })),
|
|
31457
31749
|
allowReadRoot: async (dir, opts) => {
|
|
31458
|
-
if (!
|
|
31750
|
+
if (!isAbsolute10(dir)) throw new Error(`\u8981\u7EDD\u5BF9\u8DEF\u5F84\uFF1A${dir}\uFF08\u5148 pwd \u62FF\u5230\u5B8C\u6574\u8DEF\u5F84\u518D\u7C98\u8FC7\u6765\uFF09`);
|
|
31459
31751
|
const \u7EDD\u5BF9 = resolve12(dir);
|
|
31460
31752
|
if (!existsSync15(\u7EDD\u5BF9)) throw new Error(`\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${\u7EDD\u5BF9}`);
|
|
31461
31753
|
if (!statSync4(\u7EDD\u5BF9).isDirectory()) throw new Error(`\u4E0D\u662F\u76EE\u5F55\uFF1A${\u7EDD\u5BF9}`);
|
|
@@ -31529,6 +31821,11 @@ async function setupSession(input) {
|
|
|
31529
31821
|
autoTitle: env.DALUO_SESSION_AUTO_TITLE === "1"
|
|
31530
31822
|
};
|
|
31531
31823
|
}
|
|
31824
|
+
function \u8BBE\u7F6E\u9519\u4F4D\u51FA\u58F0(err, configHome) {
|
|
31825
|
+
const \u6587\u4EF6 = globalSettingsFile(configHome, { create: false });
|
|
31826
|
+
const \u63D0\u793A = \u9876\u5C42\u9519\u4F4D\u63D0\u793A(loadSettingsSync2(\u6587\u4EF6));
|
|
31827
|
+
if (\u63D0\u793A !== void 0) err(`daluo: ${\u63D0\u793A}`);
|
|
31828
|
+
}
|
|
31532
31829
|
var init_cli_shared = __esm({
|
|
31533
31830
|
"packages/cli/src/cli-shared.ts"() {
|
|
31534
31831
|
"use strict";
|
|
@@ -31543,7 +31840,7 @@ var init_cli_shared = __esm({
|
|
|
31543
31840
|
});
|
|
31544
31841
|
|
|
31545
31842
|
// packages/cli/src/args.ts
|
|
31546
|
-
import { isAbsolute as
|
|
31843
|
+
import { isAbsolute as isAbsolute11, join as join39 } from "node:path";
|
|
31547
31844
|
function parseCliArgs(argv, opts = {}) {
|
|
31548
31845
|
const valueOptions = opts.valueOptions === void 0 ? VALUE_OPTIONS : new Set(opts.valueOptions);
|
|
31549
31846
|
const [command, ...rest] = argv;
|
|
@@ -31578,7 +31875,7 @@ function missingValueError(parsed, flag) {
|
|
|
31578
31875
|
return `--${flag} \u7F3A\u503C\uFF08\u8981\u7701\u7565\u5C31\u6574\u4E2A\u53BB\u6389 --${flag}\uFF09`;
|
|
31579
31876
|
}
|
|
31580
31877
|
function resolveResumeTarget(target, cwd) {
|
|
31581
|
-
if (
|
|
31878
|
+
if (isAbsolute11(target) || target.includes("/") || target.includes("\\")) return target;
|
|
31582
31879
|
return join39(sessionsDirOf(cwd), target);
|
|
31583
31880
|
}
|
|
31584
31881
|
var VALUE_OPTIONS;
|
|
@@ -31627,8 +31924,10 @@ function enableSlowProbe(env = process.env) {
|
|
|
31627
31924
|
function debugLine(event) {
|
|
31628
31925
|
switch (event.type) {
|
|
31629
31926
|
case "message/assistant": {
|
|
31630
|
-
const { usage, model } = event;
|
|
31631
|
-
if (usage === void 0 && model === void 0
|
|
31927
|
+
const { usage, model, durationMs, finishReason } = event;
|
|
31928
|
+
if (usage === void 0 && model === void 0 && durationMs === void 0 && finishReason === void 0) {
|
|
31929
|
+
return void 0;
|
|
31930
|
+
}
|
|
31632
31931
|
const bits = [`#${event.seq}`];
|
|
31633
31932
|
if (model !== void 0) bits.push(`model ${model}`);
|
|
31634
31933
|
if (usage !== void 0) {
|
|
@@ -31636,6 +31935,8 @@ function debugLine(event) {
|
|
|
31636
31935
|
bits.push(`prompt ${usage.promptTokens}${\u7F13\u5B58}`, `completion ${usage.completionTokens}`);
|
|
31637
31936
|
if (usage.reasoningTokens !== void 0) bits.push(`reasoning ${usage.reasoningTokens}`);
|
|
31638
31937
|
}
|
|
31938
|
+
if (durationMs !== void 0) bits.push(`duration ${durationMs}ms`);
|
|
31939
|
+
if (finishReason !== void 0) bits.push(`finish ${finishReason}`);
|
|
31639
31940
|
return bits.join(" \xB7 ");
|
|
31640
31941
|
}
|
|
31641
31942
|
case "session/model-changed":
|
|
@@ -31661,7 +31962,7 @@ var init_debug_channel = __esm({
|
|
|
31661
31962
|
// packages/cli/src/resume.ts
|
|
31662
31963
|
import { execFile as execFile8 } from "node:child_process";
|
|
31663
31964
|
import { existsSync as existsSync16 } from "node:fs";
|
|
31664
|
-
import { isAbsolute as
|
|
31965
|
+
import { isAbsolute as isAbsolute12, join as join40 } from "node:path";
|
|
31665
31966
|
import { promisify as promisify7 } from "node:util";
|
|
31666
31967
|
async function sameRepoWorktrees(cwd) {
|
|
31667
31968
|
try {
|
|
@@ -31680,7 +31981,7 @@ async function registeredProjectRoots() {
|
|
|
31680
31981
|
}
|
|
31681
31982
|
}
|
|
31682
31983
|
async function resolveResumeAcrossWorktrees(raw, cwd) {
|
|
31683
|
-
const explicit =
|
|
31984
|
+
const explicit = isAbsolute12(raw) || raw.includes("/") || raw.includes("\\");
|
|
31684
31985
|
const base = resolveResumeTarget(raw, cwd);
|
|
31685
31986
|
if (explicit) return { file: raw };
|
|
31686
31987
|
if (existsSync16(base)) return { file: base };
|
|
@@ -31995,7 +32296,7 @@ __export(log_exports, {
|
|
|
31995
32296
|
\u8F7D\u8377\u6458\u8981: () => \u8F7D\u8377\u6458\u8981
|
|
31996
32297
|
});
|
|
31997
32298
|
import { stat as stat18, readdir as readdir13, readFile as readFile17 } from "node:fs/promises";
|
|
31998
|
-
import { basename as
|
|
32299
|
+
import { basename as basename16, join as join42 } from "node:path";
|
|
31999
32300
|
function logUsage() {
|
|
32000
32301
|
return `\u7528\u6CD5: daluo log [<\u4F1A\u8BDD\u6587\u4EF6>] [--lines <N>]
|
|
32001
32302
|
\u4ECE\u4F1A\u8BDD\u65E5\u5FD7**\u5C3E\u90E8**\u8BFB\u6700\u8FD1 N \u6761\u4E8B\u4EF6\uFF08\u7F3A\u7701 ${DEFAULT_LOG_LINES} \u6761\u3001\u7F3A\u7701\u53D6\u5F53\u524D\u76EE\u5F55\u6700\u8FD1\u7684\u4F1A\u8BDD\uFF09\u3002
|
|
@@ -32104,10 +32405,10 @@ async function runLogCommand(argv, io) {
|
|
|
32104
32405
|
return EXIT.corrupt;
|
|
32105
32406
|
}
|
|
32106
32407
|
if (notes.length === 0) {
|
|
32107
|
-
io.out(`${
|
|
32408
|
+
io.out(`${basename16(file)} \xB7 \u65E0\u4FEE\u590D\u8BB0\u5F55`);
|
|
32108
32409
|
return EXIT.ok;
|
|
32109
32410
|
}
|
|
32110
|
-
io.out(`${
|
|
32411
|
+
io.out(`${basename16(file)} \xB7 \u4FEE\u590D\u8D26 ${notes.length} \u6761`);
|
|
32111
32412
|
for (const n of notes) io.out(`${n.at} ${n.kind} \u7B2C ${n.line} \u884C \u4E22\u6389 ${n.droppedBytes} \u5B57\u8282 ${n.reason}`);
|
|
32112
32413
|
return EXIT.ok;
|
|
32113
32414
|
}
|
|
@@ -32135,7 +32436,7 @@ async function runLogCommand(argv, io) {
|
|
|
32135
32436
|
io.err(`daluo log: ${error instanceof Error ? error.message : String(error)}`);
|
|
32136
32437
|
return EXIT.corrupt;
|
|
32137
32438
|
}
|
|
32138
|
-
io.out(`${
|
|
32439
|
+
io.out(`${basename16(file)} \xB7 \u6700\u8FD1 ${events.length} \u6761`);
|
|
32139
32440
|
if (events.length === 0) {
|
|
32140
32441
|
io.out("\uFF08\u8BE5\u7A97\u53E3\u5185\u6CA1\u6709\u4E8B\u4EF6\uFF09");
|
|
32141
32442
|
return EXIT.ok;
|
|
@@ -32167,9 +32468,12 @@ __export(doctor_exports, {
|
|
|
32167
32468
|
compareSemver: () => compareSemver,
|
|
32168
32469
|
doctorUsage: () => doctorUsage,
|
|
32169
32470
|
resolveDoctorContext: () => resolveDoctorContext,
|
|
32170
|
-
runDoctorCommand: () => runDoctorCommand
|
|
32471
|
+
runDoctorCommand: () => runDoctorCommand,
|
|
32472
|
+
\u68C0\u67E5\u53EF\u9009\u4F9D\u8D56: () => \u68C0\u67E5\u53EF\u9009\u4F9D\u8D56
|
|
32171
32473
|
});
|
|
32172
32474
|
import { existsSync as existsSync17, readdirSync as readdirSync2, readFileSync as readFileSync12, statSync as statSync5 } from "node:fs";
|
|
32475
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
32476
|
+
import { fileURLToPath } from "node:url";
|
|
32173
32477
|
function resolveDoctorContext(io) {
|
|
32174
32478
|
const processEnv = io.processEnv ?? process.env;
|
|
32175
32479
|
return {
|
|
@@ -32264,8 +32568,48 @@ async function collectChecks(ctx) {
|
|
|
32264
32568
|
status: \u5168\u90E8.length === 0 ? "ok" : \u7F3A\u7684.length > 0 ? "warn" : "ok",
|
|
32265
32569
|
detail: \u5168\u90E8.length === 0 ? `\u6CA1\u6709\u53EF\u7528\u7684\u8BED\u8A00\u670D\u52A1\u5668\uFF08\u663E\u5F0F\u914D\u7F6E 0 \u6761\u3001\u81EA\u52A8\u63A2\u6D4B 0 \u6761${lspDetectEnabled(ctx.processEnv) ? "" : "\uFF1BDALUO_LSP_DETECT=0 \u5DF2\u5173\u6389\u63A2\u6D4B"}\uFF09` : `${\u5168\u90E8.length} \u6761\uFF08\u663E\u5F0F ${\u663E\u5F0F?.length ?? 0} + \u63A2\u6D4B ${\u63A2\u6D4B.length}\uFF09\uFF1A` + \u5168\u90E8.map((c) => `${c.command}${\u547D\u4EE4\u5728\u8DEF\u5F84(c.command, ctx.processEnv) === void 0 ? "\uFF08**\u4E0D\u5728 PATH \u4E0A**\uFF09" : ""}`).join("\u3001")
|
|
32266
32570
|
});
|
|
32571
|
+
checks.push(\u68C0\u67E5\u53EF\u9009\u4F9D\u8D56());
|
|
32267
32572
|
return checks;
|
|
32268
32573
|
}
|
|
32574
|
+
function \u53EF\u9009\u4F9D\u8D56\u540D() {
|
|
32575
|
+
try {
|
|
32576
|
+
const \u6587\u4EF6 = fileURLToPath(new URL("../package.json", import.meta.url));
|
|
32577
|
+
const j = JSON.parse(readFileSync12(\u6587\u4EF6, "utf8"));
|
|
32578
|
+
return Object.keys(j.optionalDependencies ?? {});
|
|
32579
|
+
} catch {
|
|
32580
|
+
return void 0;
|
|
32581
|
+
}
|
|
32582
|
+
}
|
|
32583
|
+
function \u68C0\u67E5\u53EF\u9009\u4F9D\u8D56(input = {}) {
|
|
32584
|
+
const \u540D\u4EEC = input.\u540D === null ? void 0 : input.\u540D ?? \u53EF\u9009\u4F9D\u8D56\u540D();
|
|
32585
|
+
if (\u540D\u4EEC === void 0) {
|
|
32586
|
+
return { id: "optional-deps", status: "warn", detail: "\u8BFB\u4E0D\u5230\u5305\u6E05\u5355\uFF08package.json \u4E0D\u5728\u9884\u671F\u4F4D\u7F6E\uFF09\u21D2 \u65E0\u4ECE\u5224\u65AD\u53EF\u9009\u4F9D\u8D56\u88C5\u6CA1\u88C5" };
|
|
32587
|
+
}
|
|
32588
|
+
if (\u540D\u4EEC.length === 0) return { id: "optional-deps", status: "ok", detail: "\u8FD9\u4E2A\u5305\u6CA1\u6709\u53EF\u9009\u4F9D\u8D56" };
|
|
32589
|
+
const \u63A2 = input.\u63A2 ?? \u80FD\u89E3\u6790;
|
|
32590
|
+
const require2 = createRequire2(import.meta.url);
|
|
32591
|
+
const \u7F3A = \u540D\u4EEC.filter((\u540D) => !\u63A2(\u540D));
|
|
32592
|
+
if (\u7F3A.length === 0) return { id: "optional-deps", status: "ok", detail: `${\u540D\u4EEC.join(" / ")} \u90FD\u5728` };
|
|
32593
|
+
return {
|
|
32594
|
+
id: "optional-deps",
|
|
32595
|
+
status: "warn",
|
|
32596
|
+
detail: `\u672A\u5B89\u88C5\uFF1A${\u7F3A.join("\u3001")}\uFF08headless \u7528 --omit=optional \u88C5\u5C31\u662F\u8FD9\u6837\uFF1APTY \u9000\u5316\u6210\u7BA1\u9053\u6863\u3001computer-use \u4E0D\u53EF\u7528\uFF1B\u8981\u8FD9\u4E24\u9879\u5C31\u91CD\u88C5\u4E0D\u5E26 --omit=optional\uFF09`
|
|
32597
|
+
};
|
|
32598
|
+
}
|
|
32599
|
+
function \u80FD\u89E3\u6790(\u540D) {
|
|
32600
|
+
const require2 = createRequire2(import.meta.url);
|
|
32601
|
+
try {
|
|
32602
|
+
require2.resolve(\u540D);
|
|
32603
|
+
return true;
|
|
32604
|
+
} catch {
|
|
32605
|
+
}
|
|
32606
|
+
try {
|
|
32607
|
+
import.meta.resolve(\u540D);
|
|
32608
|
+
return true;
|
|
32609
|
+
} catch {
|
|
32610
|
+
return false;
|
|
32611
|
+
}
|
|
32612
|
+
}
|
|
32269
32613
|
function collectLogLocations(ctx) {
|
|
32270
32614
|
const \u8868 = [
|
|
32271
32615
|
{ kind: "session", label: "session", path: sessionsDirOf(ctx.cwd) },
|
|
@@ -32277,7 +32621,7 @@ function collectLogLocations(ctx) {
|
|
|
32277
32621
|
return \u8868.map((l) => ({ ...l, exists: existsSync17(l.path) }));
|
|
32278
32622
|
}
|
|
32279
32623
|
function doctorUsage() {
|
|
32280
|
-
return "\u7528\u6CD5: daluo doctor\n \u73AF\u5883\u5065\u5EB7\u68C0\u67E5 + \u65E5\u5FD7\u843D\u70B9\uFF08**\u53EA\u8BFB**\uFF1A\u4E0D\u5EFA\u76EE\u5F55\u3001\u4E0D\u5199\u6587\u4EF6\uFF1B**\u65E0\u53C2\u6570**\uFF09\u3002\n \u68C0\u67E5 node / config-dir / sessions-dir / settings / llm-credentials / sandbox / lsp \
|
|
32624
|
+
return "\u7528\u6CD5: daluo doctor\n \u73AF\u5883\u5065\u5EB7\u68C0\u67E5 + \u65E5\u5FD7\u843D\u70B9\uFF08**\u53EA\u8BFB**\uFF1A\u4E0D\u5EFA\u76EE\u5F55\u3001\u4E0D\u5199\u6587\u4EF6\uFF1B**\u65E0\u53C2\u6570**\uFF09\u3002\n \u68C0\u67E5 node / config-dir / sessions-dir / settings / llm-credentials / sandbox / lsp / optional-deps \u516B\u9879\uFF0C\u5E76\u5217\u5168\u90E8\u65E5\u5FD7\u843D\u70B9\u3002\n \u4EFB\u4E00 `fail` \u21D2 \u9000\u51FA\u7801 1\uFF1B`warn`\uFF08\u672A\u914D\u51ED\u8BC1 / \u65E0\u6C99\u7BB1\u540E\u7AEF\uFF09\u4E0D\u5F71\u54CD\u9000\u51FA\u7801\u3002\n";
|
|
32281
32625
|
}
|
|
32282
32626
|
async function runDoctorCommand(argv, io) {
|
|
32283
32627
|
const parsed = parseCliArgs(argv);
|
|
@@ -33043,7 +33387,7 @@ __export(session_exports, {
|
|
|
33043
33387
|
sessionUsage: () => sessionUsage
|
|
33044
33388
|
});
|
|
33045
33389
|
import { existsSync as existsSync18 } from "node:fs";
|
|
33046
|
-
import { basename as
|
|
33390
|
+
import { basename as basename17 } from "node:path";
|
|
33047
33391
|
function originSuffix(node) {
|
|
33048
33392
|
return node.forkedFrom === void 0 ? "" : ` \u2190 ${node.forkedFrom.file}@${node.forkedFrom.seq}`;
|
|
33049
33393
|
}
|
|
@@ -33135,7 +33479,7 @@ async function runSessionCommand(argv, io) {
|
|
|
33135
33479
|
newFile,
|
|
33136
33480
|
...branchSummary !== void 0 ? { branchSummary } : {}
|
|
33137
33481
|
});
|
|
33138
|
-
const name =
|
|
33482
|
+
const name = basename17(newFile);
|
|
33139
33483
|
io.out(`\u5DF2\u5206\u53C9\uFF1A${target}${atSeq !== void 0 ? `\uFF08\u622A\u81F3 seq ${atSeq}\uFF09` : "\uFF08\u6574\u4E2A\u4F1A\u8BDD\uFF09"} \u2192 ${name}`);
|
|
33140
33484
|
if (branchSummary !== void 0) io.out(`\u5DF2\u6CE8\u5165\u88AB\u653E\u5F03\u8DEF\u5F84\u6458\u8981\uFF08${branchSummary.length} \u5B57\u7B26\uFF09`);
|
|
33141
33485
|
io.out(`\u7EED\u8DD1\uFF1Adaluo chat --resume ${name}`);
|
|
@@ -33171,7 +33515,7 @@ async function runSessionCommand(argv, io) {
|
|
|
33171
33515
|
while (existsSync18(newFile)) newFile = makeNewSessionLogFile(io.cwd, ts += 1);
|
|
33172
33516
|
const r = await summarizeUpToSession({ sourceFile, upToSeq: toSeq, newFile });
|
|
33173
33517
|
io.out(`\u5DF2\u6458\u8981\u5230\u6B64\uFF1A\u6E90 seq 1..${toSeq} \u6458\u6210 ${r.summaryChars} \u5B57\u7B26\uFF1B\u4E4B\u540E\u7684\u539F\u6587\u7167\u6284\uFF08${r.keptMessages} \u6761\u6D88\u606F\uFF09`);
|
|
33174
|
-
const name =
|
|
33518
|
+
const name = basename17(newFile);
|
|
33175
33519
|
io.out(`\u65B0\u4F1A\u8BDD\uFF1A${name}`);
|
|
33176
33520
|
io.out(`\u7EED\u8DD1\uFF1Adaluo chat --resume ${name}`);
|
|
33177
33521
|
io.out(`\u6E90\u4F1A\u8BDD\u672A\u52A8\uFF08\u60F3\u63A5\u7740\u539F\u6765\u7684\u8DEF\u8D70\uFF1Adaluo chat --resume ${target}\uFF09`);
|
|
@@ -33221,7 +33565,7 @@ async function runSessionCommand(argv, io) {
|
|
|
33221
33565
|
if (r.skipped.length > 0) {
|
|
33222
33566
|
io.out(`\u8DF3\u8FC7 ${r.skipped.reduce((n, s) => n + s.count, 0)} \u6761\uFF08\u5916\u90E8\u683C\u5F0F\u91CC\u672C\u4ED3\u4E0D\u6620\u5C04\u7684\u4E1C\u897F\uFF09\uFF1A` + r.skipped.map((s) => `${s.kind}\xD7${s.count}`).join("\u3001"));
|
|
33223
33567
|
}
|
|
33224
|
-
const name =
|
|
33568
|
+
const name = basename17(targetFile);
|
|
33225
33569
|
io.out(`\u76EE\u6807\u4F1A\u8BDD\uFF1A${name}`);
|
|
33226
33570
|
io.out(`\u7EED\u8DD1\uFF1Adaluo chat --resume ${name}`);
|
|
33227
33571
|
return 0;
|
|
@@ -33244,7 +33588,7 @@ async function runSessionCommand(argv, io) {
|
|
|
33244
33588
|
io.err(`daluo session decompress: ${r2.reason}`);
|
|
33245
33589
|
return EXIT.input;
|
|
33246
33590
|
}
|
|
33247
|
-
io.out(`\u5DF2\u89E3\u538B\uFF1A${
|
|
33591
|
+
io.out(`\u5DF2\u89E3\u538B\uFF1A${basename17(r2.out)}\uFF08${r2.bytesBefore} \u2192 ${r2.bytesAfter} \u5B57\u8282\uFF1B\u73B0\u5728\u53EF\u4EE5 --resume \u7EED\u8DD1\uFF09`);
|
|
33248
33592
|
return 0;
|
|
33249
33593
|
}
|
|
33250
33594
|
const log = await EventLog.restore(sourceFile);
|
|
@@ -33258,8 +33602,8 @@ async function runSessionCommand(argv, io) {
|
|
|
33258
33602
|
return EXIT.input;
|
|
33259
33603
|
}
|
|
33260
33604
|
const \u7701 = r.bytesBefore === 0 ? 0 : Math.round((1 - r.bytesAfter / r.bytesBefore) * 100);
|
|
33261
|
-
io.out(`\u5DF2\u538B\u7F29\uFF1A${
|
|
33262
|
-
io.out(`\u8BFB\u4FA7\u6309\u540E\u7F00\u81EA\u52A8\u89E3\u7801\uFF08\`daluo log\` / \`ls\` / \`usage\` \u7167\u65E7\uFF09\uFF1B\u8981\u7EED\u8DD1\u5148 \`daluo session decompress ${
|
|
33605
|
+
io.out(`\u5DF2\u538B\u7F29\uFF1A${basename17(r.out)}\uFF08${r.bytesBefore} \u2192 ${r.bytesAfter} \u5B57\u8282\uFF0C\u7701 ${\u7701}%\uFF09`);
|
|
33606
|
+
io.out(`\u8BFB\u4FA7\u6309\u540E\u7F00\u81EA\u52A8\u89E3\u7801\uFF08\`daluo log\` / \`ls\` / \`usage\` \u7167\u65E7\uFF09\uFF1B\u8981\u7EED\u8DD1\u5148 \`daluo session decompress ${basename17(r.out)}\``);
|
|
33263
33607
|
return 0;
|
|
33264
33608
|
}
|
|
33265
33609
|
case "revert": {
|
|
@@ -33322,7 +33666,7 @@ async function runSessionCommand(argv, io) {
|
|
|
33322
33666
|
} else {
|
|
33323
33667
|
io.out(`\u6587\u4EF6\u672A\u52A8\uFF1A${r.fileRestoreSkipped ?? "\u6CA1\u6709\u53EF\u7528\u7684\u5FEB\u7167"}`);
|
|
33324
33668
|
}
|
|
33325
|
-
const name =
|
|
33669
|
+
const name = basename17(newFile);
|
|
33326
33670
|
io.out(`\u5BF9\u8BDD\u5DF2\u56DE\u5230 seq ${toSeq}\uFF1A${target} \u2192 ${name}`);
|
|
33327
33671
|
io.out(`\u7EED\u8DD1\uFF1Adaluo chat --resume ${name}`);
|
|
33328
33672
|
if (r.reproposed.length > 0) {
|
|
@@ -33371,11 +33715,11 @@ async function runSessionCommand(argv, io) {
|
|
|
33371
33715
|
return EXIT.input;
|
|
33372
33716
|
}
|
|
33373
33717
|
const metas = await listSessions(sessionsDirOf(io.cwd), { includeArchived: true, indexFile: sessionIndexFileOf(io.cwd) });
|
|
33374
|
-
const self = metas.find((m) => m.file ===
|
|
33718
|
+
const self = metas.find((m) => m.file === basename17(file));
|
|
33375
33719
|
const forest = sessionTree(metas);
|
|
33376
33720
|
const node = self?.sessionId !== void 0 ? findNode(forest, self.sessionId) : void 0;
|
|
33377
33721
|
if (node === void 0) {
|
|
33378
|
-
io.out(`${
|
|
33722
|
+
io.out(`${basename17(file)}\uFF08\u672A\u80FD\u5728\u4F1A\u8BDD\u96C6\u5408\u91CC\u5B9A\u4F4D\uFF0C\u65E0\u6CD5\u7ED9\u51FA\u8840\u7F18\uFF09`);
|
|
33379
33723
|
return 0;
|
|
33380
33724
|
}
|
|
33381
33725
|
if (sub === "children") {
|
|
@@ -33431,11 +33775,21 @@ __export(rewind_exports, {
|
|
|
33431
33775
|
rewindUsage: () => rewindUsage,
|
|
33432
33776
|
runRewindCommand: () => runRewindCommand
|
|
33433
33777
|
});
|
|
33778
|
+
import { relative as relative3 } from "node:path";
|
|
33434
33779
|
function rewindUsage() {
|
|
33435
|
-
return "\u7528\u6CD5: daluo rewind <\u5B50\u547D\u4EE4>\n daluo rewind ls \u5217\u51FA\u672C\u5DE5\u4F5C\u533A\u7684\u6587\u4EF6\u5FEB\u7167\uFF08\u65B0 \u2192 \u65E7\uFF09\n daluo rewind to <hash> \u56DE\u5230\u67D0\u4E2A\u5FEB\u7167\uFF08\u6574\u6811\uFF09\n daluo rewind to <hash> --path <p> \u53EA\u6062\u590D\u90A3\u4E00\u4E2A\u8DEF\u5F84\uFF08\u5176\u4F59\u6539\u52A8\u4FDD\u7559\uFF09\n\n\uFF08\u4E0D\u5E26\u5B50\u547D\u4EE4 = ls\uFF0C\u6700\u5E38\u7528\u7684\u90A3\u4E2A\u3002\uFF09\n\u5FEB\u7167\u662F**\u5F71\u5B50 git \u4ED3\u5E93**\uFF08`.daluo/snapshots/`\uFF09\u2014\u2014\u4E0D\u78B0\u4F60\u7684 `.git`\u3002\nagent \u6BCF\u6B21\u6539\u6587\u4EF6**\u4E4B\u524D**\u90FD\u4F1A\u81EA\u52A8\u6253\u4E00\u4E2A\u70B9\uFF08`DALUO_SNAPSHOT=off` \u53EF\u5173\uFF09\u3002\n**\u4EE3\u4EF7**\uFF1A\u6BCF\u6B21\u6253\u70B9\u90FD\u5728\u5F71\u5B50\u4ED3\u5E93\u91CC\u63D0\u4EA4\u4E00\u6B21 \u2014\u2014 \u5927\u4ED3\u91CC\u4F1A\u5360\u78C1\u76D8\u3001\u4E5F\u53EF\u80FD\u62D6\u6162\uFF1B`ls` \u4F1A\u62A5\u51FA\u5F53\u524D\u6761\u6570\u4E0E\u4F53\u79EF\u3002\n";
|
|
33780
|
+
return "\u7528\u6CD5: daluo rewind <\u5B50\u547D\u4EE4>\n daluo rewind ls \u5217\u51FA\u672C\u5DE5\u4F5C\u533A\u7684\u6587\u4EF6\u5FEB\u7167\uFF08\u65B0 \u2192 \u65E7\uFF09\n daluo rewind to <hash> \u56DE\u5230\u67D0\u4E2A\u5FEB\u7167\uFF08\u6574\u6811\uFF09\n daluo rewind to <hash> --path <p> \u53EA\u6062\u590D\u90A3\u4E00\u4E2A\u8DEF\u5F84\uFF08\u5176\u4F59\u6539\u52A8\u4FDD\u7559\uFF09\n\n\uFF08\u4E0D\u5E26\u5B50\u547D\u4EE4 = ls\uFF0C\u6700\u5E38\u7528\u7684\u90A3\u4E2A\u3002\uFF09\n \u9009\u9879\uFF1A--json \u673A\u5668\u53EF\u8BFB\u8F93\u51FA\uFF08\u5355\u884C JSON\uFF1B\u7ED9\u9762\u677F/\u811A\u672C\u7528\uFF09\n --snapshot-dir <dir> \u7528\u8FD9\u4E2A\u5F71\u5B50\u4ED3\u5E93\u76EE\u5F55\uFF08\u7F3A\u7701 `.daluo/snapshots/`\uFF1B\n \u76F8\u5BF9\u8DEF\u5F84\u6309\u5F53\u524D\u76EE\u5F55\u89E3\u6790\uFF09\n\u5FEB\u7167\u662F**\u5F71\u5B50 git \u4ED3\u5E93**\uFF08`.daluo/snapshots/`\uFF09\u2014\u2014\u4E0D\u78B0\u4F60\u7684 `.git`\u3002\nagent \u6BCF\u6B21\u6539\u6587\u4EF6**\u4E4B\u524D**\u90FD\u4F1A\u81EA\u52A8\u6253\u4E00\u4E2A\u70B9\uFF08`DALUO_SNAPSHOT=off` \u53EF\u5173\uFF09\u3002\n**\u4EE3\u4EF7**\uFF1A\u6BCF\u6B21\u6253\u70B9\u90FD\u5728\u5F71\u5B50\u4ED3\u5E93\u91CC\u63D0\u4EA4\u4E00\u6B21 \u2014\u2014 \u5927\u4ED3\u91CC\u4F1A\u5360\u78C1\u76D8\u3001\u4E5F\u53EF\u80FD\u62D6\u6162\uFF1B`ls` \u4F1A\u62A5\u51FA\u5F53\u524D\u6761\u6570\u4E0E\u4F53\u79EF\u3002\n";
|
|
33781
|
+
}
|
|
33782
|
+
function \u5FEB\u7167env(snapshotDir) {
|
|
33783
|
+
return snapshotDir === void 0 ? void 0 : { ...process.env, DALUO_SNAPSHOT_DIR: snapshotDir };
|
|
33784
|
+
}
|
|
33785
|
+
function \u663E\u793A\u8DEF\u5F84(cwd, dir) {
|
|
33786
|
+
const \u76F8\u5BF9 = relative3(cwd, dir);
|
|
33787
|
+
return \u76F8\u5BF9 === "" || \u76F8\u5BF9.startsWith("..") ? dir : \u76F8\u5BF9;
|
|
33436
33788
|
}
|
|
33437
33789
|
async function runRewindCommand(argv, io) {
|
|
33438
|
-
const { command, positional, options, missingValues } = parseCliArgs(argv, {
|
|
33790
|
+
const { command, positional, options, flags, missingValues } = parseCliArgs(argv, {
|
|
33791
|
+
valueOptions: ["path", "snapshot-dir"]
|
|
33792
|
+
});
|
|
33439
33793
|
if (missingValues.size > 0) {
|
|
33440
33794
|
io.err(`daluo rewind: --${[...missingValues][0]} \u540E\u9762\u7F3A\u5C11\u503C`);
|
|
33441
33795
|
io.err(rewindUsage());
|
|
@@ -33463,33 +33817,66 @@ async function runRewindCommand(argv, io) {
|
|
|
33463
33817
|
io.err(rewindUsage());
|
|
33464
33818
|
return EXIT.input;
|
|
33465
33819
|
}
|
|
33820
|
+
const json3 = flags.has("json");
|
|
33821
|
+
if (json3 && to !== void 0) {
|
|
33822
|
+
io.err("daluo rewind: --json \u53EA\u7528\u4E8E\u5217\u8868\uFF08`daluo rewind ls --json`\uFF09\uFF1B`to` \u7684\u8F93\u51FA\u662F\u7ED9\u4EBA\u770B\u7684\u4E00\u53E5\u8BDD");
|
|
33823
|
+
return EXIT.input;
|
|
33824
|
+
}
|
|
33466
33825
|
if (path !== void 0 && to === void 0) {
|
|
33467
33826
|
io.err("daluo rewind: --path \u53EA\u80FD\u8DDF\u7740 `to <hash>` \u7528\uFF08\u5B83\u6307\u7684\u662F\u300C\u90A3\u4E2A\u5FEB\u7167\u91CC\u7684\u54EA\u4E2A\u6587\u4EF6\u300D\uFF09");
|
|
33468
33827
|
io.err(rewindUsage());
|
|
33469
33828
|
return EXIT.input;
|
|
33470
33829
|
}
|
|
33471
33830
|
if (to === void 0) {
|
|
33472
|
-
const
|
|
33831
|
+
const env2 = \u5FEB\u7167env(options.get("snapshot-dir"));
|
|
33832
|
+
const listed = await listCheckpoints({ cwd: io.cwd, withFiles: json3, ...env2 !== void 0 ? { env: env2 } : {} });
|
|
33473
33833
|
if (!listed.ok) {
|
|
33834
|
+
if (json3) {
|
|
33835
|
+
io.out(JSON.stringify({ ok: false, reason: listed.reason ?? "\u5F71\u5B50\u4ED3\u5E93\u4E0D\u5B58\u5728", dir: listed.dir, snapshots: [] }));
|
|
33836
|
+
return EXIT.input;
|
|
33837
|
+
}
|
|
33474
33838
|
io.err(`daluo rewind: \u8FD8\u6CA1\u6709\u5FEB\u7167\uFF08${listed.reason ?? "\u5F71\u5B50\u4ED3\u5E93\u4E0D\u5B58\u5728"}\uFF09`);
|
|
33475
33839
|
return EXIT.input;
|
|
33476
33840
|
}
|
|
33841
|
+
if (json3) {
|
|
33842
|
+
const cost2 = await snapshotCost({ cwd: io.cwd, ...env2 !== void 0 ? { env: env2 } : {} });
|
|
33843
|
+
io.out(JSON.stringify({
|
|
33844
|
+
ok: true,
|
|
33845
|
+
dir: listed.dir,
|
|
33846
|
+
total: { checkpoints: cost2.checkpoints, bytes: cost2.bytes },
|
|
33847
|
+
snapshots: listed.checkpoints.map((c) => ({
|
|
33848
|
+
hash: c.hash,
|
|
33849
|
+
at: c.ts,
|
|
33850
|
+
// 干净标签(位置在下面的 seq 字段里,不重复打)
|
|
33851
|
+
label: checkpointLabelOf(c.label),
|
|
33852
|
+
...c.seq !== void 0 ? { seq: c.seq } : {},
|
|
33853
|
+
...c.files !== void 0 ? { files: c.files } : {}
|
|
33854
|
+
}))
|
|
33855
|
+
}));
|
|
33856
|
+
return 0;
|
|
33857
|
+
}
|
|
33477
33858
|
if (listed.checkpoints.length === 0) {
|
|
33478
33859
|
io.out("\uFF08\u8FD8\u6CA1\u6709\u5FEB\u7167\uFF09");
|
|
33479
33860
|
return 0;
|
|
33480
33861
|
}
|
|
33481
33862
|
for (const c of listed.checkpoints) {
|
|
33482
|
-
io.out(`${short(c.hash)} ${c.ts} ${c.label}${c.seq !== void 0 ? ` \u2190 \u4F1A\u8BDD seq ${c.seq}` : ""}`);
|
|
33863
|
+
io.out(`${short(c.hash)} ${c.ts} ${checkpointLabelOf(c.label)}${c.seq !== void 0 ? ` \u2190 \u4F1A\u8BDD seq ${c.seq}` : ""}`);
|
|
33483
33864
|
}
|
|
33484
33865
|
io.out("");
|
|
33485
33866
|
io.out("\u56DE\u5230\u67D0\u4E2A\u5FEB\u7167\uFF1Adaluo rewind to <hash> \uFF08\u53EA\u56DE\u67D0\u4E00\u4E2A\u6587\u4EF6\uFF1A\u518D\u52A0 --path <\u8DEF\u5F84>\uFF09");
|
|
33486
33867
|
io.out("\u8FDE\u540C\u5BF9\u8BDD\u4E00\u8D77\u56DE\u5230\u90A3\u6761\u6D88\u606F\uFF1Adaluo session revert <\u4F1A\u8BDD\u6587\u4EF6> --to <seq>");
|
|
33487
|
-
const cost = await snapshotCost({ cwd: io.cwd });
|
|
33488
|
-
io.out(`\u5F71\u5B50\u4ED3\u5E93\uFF1A${cost.checkpoints} \u4E2A\u5FEB\u7167 / ${formatBytes(cost.bytes)}\uFF08.
|
|
33868
|
+
const cost = await snapshotCost({ cwd: io.cwd, ...env2 !== void 0 ? { env: env2 } : {} });
|
|
33869
|
+
io.out(`\u5F71\u5B50\u4ED3\u5E93\uFF1A${cost.checkpoints} \u4E2A\u5FEB\u7167 / ${formatBytes(cost.bytes)}\uFF08${\u663E\u793A\u8DEF\u5F84(io.cwd, listed.dir)}\uFF09`);
|
|
33489
33870
|
io.out("\uFF08\u5927\u4ED3\u91CC agent \u6BCF\u6539\u4E00\u6B21\u6587\u4EF6\u90FD\u4F1A\u6253\u70B9\uFF1A\u5360\u78C1\u76D8\u3001\u4E5F\u53EF\u80FD\u62D6\u6162\uFF1B\u4E0D\u8981\u5C31\u628A\u73AF\u5883\u53D8\u91CF DALUO_SNAPSHOT \u8BBE\u6210 off\uFF09");
|
|
33490
33871
|
return 0;
|
|
33491
33872
|
}
|
|
33492
|
-
const
|
|
33873
|
+
const env = \u5FEB\u7167env(options.get("snapshot-dir"));
|
|
33874
|
+
const back = await restoreCheckpoint({
|
|
33875
|
+
cwd: io.cwd,
|
|
33876
|
+
checkpoint: to,
|
|
33877
|
+
...path !== void 0 ? { path } : {},
|
|
33878
|
+
...env !== void 0 ? { env } : {}
|
|
33879
|
+
});
|
|
33493
33880
|
if (!back.ok) {
|
|
33494
33881
|
io.err(`daluo rewind: \u56DE\u9000\u5931\u8D25\uFF08${back.reason ?? "\u672A\u77E5\u539F\u56E0"}\uFF09`);
|
|
33495
33882
|
io.err("\uFF08\u5148 `daluo rewind ls` \u770B\u4E00\u773C\u53EF\u7528\u7684\u5FEB\u7167 hash\uFF1Bhash \u6253\u9519\u4E5F\u4F1A\u8D70\u8FD9\u6761\uFF09");
|
|
@@ -33694,7 +34081,7 @@ var init_gc2 = __esm({
|
|
|
33694
34081
|
});
|
|
33695
34082
|
|
|
33696
34083
|
// packages/cli/src/mcp-agent.ts
|
|
33697
|
-
import { basename as
|
|
34084
|
+
import { basename as basename18, resolve as resolve14 } from "node:path";
|
|
33698
34085
|
function runAgentCompactBudget(env) {
|
|
33699
34086
|
return sessionCompactBudget(loadLlmConfig(env).contextWindowTokens, env);
|
|
33700
34087
|
}
|
|
@@ -33751,7 +34138,7 @@ function createRunAgentTool(deps) {
|
|
|
33751
34138
|
const mcp = deps.ctx;
|
|
33752
34139
|
const result = await new AgentRunner().run({
|
|
33753
34140
|
prompt,
|
|
33754
|
-
sessionId:
|
|
34141
|
+
sessionId: basename18(logFile, ".jsonl"),
|
|
33755
34142
|
logFile,
|
|
33756
34143
|
llm,
|
|
33757
34144
|
decision: deps.decision,
|
|
@@ -34254,6 +34641,8 @@ async function chatMain(argv) {
|
|
|
34254
34641
|
const ts = Date.now();
|
|
34255
34642
|
const isNew = !resume;
|
|
34256
34643
|
const sessionId = isNew ? `s-${ts}` : resume;
|
|
34644
|
+
\u8BBE\u7F6E\u9519\u4F4D\u51FA\u58F0((line) => process.stderr.write(`${line}
|
|
34645
|
+
`));
|
|
34257
34646
|
const s = await setupSession({ cwd, sessionId, confirm: ask.confirm, cuaAsk: ask.askQuestion });
|
|
34258
34647
|
const { llm, decision, memory, assembly } = s;
|
|
34259
34648
|
const memorySession = { injected: /* @__PURE__ */ new Set(), used: 0 };
|
|
@@ -34349,7 +34738,7 @@ var init_chat = __esm({
|
|
|
34349
34738
|
import { spawn as spawn6 } from "node:child_process";
|
|
34350
34739
|
import { readdir as readdir14 } from "node:fs/promises";
|
|
34351
34740
|
import { homedir as homedir8 } from "node:os";
|
|
34352
|
-
import { basename as
|
|
34741
|
+
import { basename as basename19, join as join45 } from "node:path";
|
|
34353
34742
|
function scrubbedEnv(parent = process.env) {
|
|
34354
34743
|
const env = {};
|
|
34355
34744
|
for (const [key, value] of Object.entries(parent)) {
|
|
@@ -34386,7 +34775,7 @@ async function listApplications(roots) {
|
|
|
34386
34775
|
} catch {
|
|
34387
34776
|
continue;
|
|
34388
34777
|
}
|
|
34389
|
-
for (const entry of entries) names.add(
|
|
34778
|
+
for (const entry of entries) names.add(basename19(entry, ".app"));
|
|
34390
34779
|
const dirs = [];
|
|
34391
34780
|
try {
|
|
34392
34781
|
for (const child of await readdir14(root, { withFileTypes: true })) {
|
|
@@ -34397,7 +34786,7 @@ async function listApplications(roots) {
|
|
|
34397
34786
|
}
|
|
34398
34787
|
for (const dir of dirs) {
|
|
34399
34788
|
try {
|
|
34400
|
-
for (const entry of (await readdir14(dir)).filter((n) => n.endsWith(".app"))) names.add(
|
|
34789
|
+
for (const entry of (await readdir14(dir)).filter((n) => n.endsWith(".app"))) names.add(basename19(entry, ".app"));
|
|
34401
34790
|
} catch {
|
|
34402
34791
|
continue;
|
|
34403
34792
|
}
|
|
@@ -34614,7 +35003,7 @@ var init_error_codes = __esm({
|
|
|
34614
35003
|
|
|
34615
35004
|
// packages/server/src/static.ts
|
|
34616
35005
|
import { open as open4, realpath as realpath4, stat as stat20 } from "node:fs/promises";
|
|
34617
|
-
import { extname as extname3, isAbsolute as
|
|
35006
|
+
import { extname as extname3, isAbsolute as isAbsolute13, join as join46, sep as sep5 } from "node:path";
|
|
34618
35007
|
function mimeOf(fileName) {
|
|
34619
35008
|
return MIME_BY_EXT[extname3(fileName).toLowerCase()] ?? DEFAULT_STATIC_MIME;
|
|
34620
35009
|
}
|
|
@@ -34689,7 +35078,7 @@ async function tryRealpath(path) {
|
|
|
34689
35078
|
}
|
|
34690
35079
|
}
|
|
34691
35080
|
async function resolveStaticTarget(mount, subPath) {
|
|
34692
|
-
if (!
|
|
35081
|
+
if (!isAbsolute13(mount.dir)) return { ok: false, status: 500, \u539F\u56E0: `\u6302\u8F7D\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84\uFF1A${mount.dir}` };
|
|
34693
35082
|
const \u95E8 = staticSubPath(subPath);
|
|
34694
35083
|
if (!\u95E8.ok) return { ok: false, status: 400, \u539F\u56E0: \u95E8.\u539F\u56E0 };
|
|
34695
35084
|
const \u6839 = mount.dir;
|
|
@@ -35160,10 +35549,10 @@ var init_theme = __esm({
|
|
|
35160
35549
|
|
|
35161
35550
|
// packages/server/src/events.ts
|
|
35162
35551
|
import { closeSync, existsSync as existsSync22, openSync, readSync, realpathSync as realpathSync7, statSync as statSync6 } from "node:fs";
|
|
35163
|
-
import { basename as
|
|
35552
|
+
import { basename as basename20, join as join48, sep as sep6 } from "node:path";
|
|
35164
35553
|
function resolveSessionFile2(sessionsDir, name) {
|
|
35165
35554
|
if (name.trim() === "") throw new Error("session \u5FC5\u586B\uFF08\u4F1A\u8BDD\u6587\u4EF6\u540D\uFF0C\u5F62\u5982 s-123.jsonl\uFF09");
|
|
35166
|
-
if (name !==
|
|
35555
|
+
if (name !== basename20(name)) throw new Error(`session \u53EA\u80FD\u662F\u6587\u4EF6\u540D\uFF08\u4E0D\u542B\u8DEF\u5F84\u5206\u9694\u7B26\uFF09\uFF1A${name}`);
|
|
35167
35556
|
if (!\u662F\u4F1A\u8BDD\u65E5\u5FD7\u540D(name)) throw new Error(`session \u5FC5\u987B\u662F .jsonl\uFF1A${name}`);
|
|
35168
35557
|
const file = join48(sessionsDir, name);
|
|
35169
35558
|
if (!isWithinDir(sessionsDir, file)) throw new Error(`session \u8D8A\u754C\uFF1A${name}`);
|
|
@@ -35512,7 +35901,7 @@ var init_files = __esm({
|
|
|
35512
35901
|
// packages/server/src/project.ts
|
|
35513
35902
|
import { readdir as readdir16, realpath as realpath6, stat as stat22 } from "node:fs/promises";
|
|
35514
35903
|
import { homedir as homedir9 } from "node:os";
|
|
35515
|
-
import { basename as
|
|
35904
|
+
import { basename as basename21, dirname as dirname16, join as join50, sep as sep8 } from "node:path";
|
|
35516
35905
|
async function realpathOrUndefined(path) {
|
|
35517
35906
|
try {
|
|
35518
35907
|
return await realpath6(path);
|
|
@@ -35590,7 +35979,7 @@ async function listChildDirs(roots, path) {
|
|
|
35590
35979
|
};
|
|
35591
35980
|
}
|
|
35592
35981
|
function projectNameOf(root) {
|
|
35593
|
-
return
|
|
35982
|
+
return basename21(root) || root;
|
|
35594
35983
|
}
|
|
35595
35984
|
var MAX_DIRS;
|
|
35596
35985
|
var init_project = __esm({
|
|
@@ -35964,7 +36353,7 @@ import { Readable } from "node:stream";
|
|
|
35964
36353
|
import { createReadStream, existsSync as existsSync23, mkdirSync as mkdirSync12, readdirSync as readdirSync3 } from "node:fs";
|
|
35965
36354
|
import { rm as rm3 } from "node:fs/promises";
|
|
35966
36355
|
import { stat as stat23, writeFile as writeFile7 } from "node:fs/promises";
|
|
35967
|
-
import { join as join52, basename as
|
|
36356
|
+
import { join as join52, basename as basename22, sep as sep9 } from "node:path";
|
|
35968
36357
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
35969
36358
|
import { randomBytes as randomBytes8 } from "node:crypto";
|
|
35970
36359
|
import { homedir as homedir10 } from "node:os";
|
|
@@ -35976,7 +36365,7 @@ function json(status, body, headers = {}) {
|
|
|
35976
36365
|
}
|
|
35977
36366
|
function safeUploadName(raw) {
|
|
35978
36367
|
const flat = raw.replace(/\\/gu, "/");
|
|
35979
|
-
const name =
|
|
36368
|
+
const name = basename22(flat).replace(/[\u0000-\u001f\u007f]/gu, "").trim();
|
|
35980
36369
|
if (name === "" || name === "." || name === "..") {
|
|
35981
36370
|
throw new Error(`\u6587\u4EF6\u540D\u4E0D\u53EF\u7528\uFF1A${JSON.stringify(raw)}`);
|
|
35982
36371
|
}
|
|
@@ -36572,7 +36961,7 @@ function createDaluoFetch(opts) {
|
|
|
36572
36961
|
});
|
|
36573
36962
|
return json(200, {
|
|
36574
36963
|
reply: result.reply,
|
|
36575
|
-
logFile:
|
|
36964
|
+
logFile: basename22(result.logFile),
|
|
36576
36965
|
...abort.signal.aborted ? { interrupted: true } : {}
|
|
36577
36966
|
});
|
|
36578
36967
|
} catch (error) {
|
|
@@ -36710,15 +37099,15 @@ function createDaluoFetch(opts) {
|
|
|
36710
37099
|
const ext = dot > 0 ? uploadName.slice(dot) : "";
|
|
36711
37100
|
target = join52(dir, `${stem}-${suffix}${ext}`);
|
|
36712
37101
|
}
|
|
36713
|
-
const
|
|
37102
|
+
const relative4 = `.daluo/${UPLOADS_SUBDIR}/${basename22(target)}`;
|
|
36714
37103
|
if (!isWithinDir(activeRoot, target)) {
|
|
36715
37104
|
return json(400, { error: "\u4E0A\u4F20\u76EE\u6807\u8D8A\u754C", code: "outside-workspace" }, NOSNIFF);
|
|
36716
37105
|
}
|
|
36717
37106
|
await writeFile7(target, bytes);
|
|
36718
37107
|
const textLike = looksLikeText(bytes);
|
|
36719
37108
|
return json(200, {
|
|
36720
|
-
name:
|
|
36721
|
-
path:
|
|
37109
|
+
name: basename22(target),
|
|
37110
|
+
path: relative4,
|
|
36722
37111
|
bytes: bytes.length,
|
|
36723
37112
|
textLike,
|
|
36724
37113
|
// 如实说清两种结局:非文本落盘了但**模型拿不到内容**(读面只回文本)
|
|
@@ -37487,7 +37876,7 @@ function createDaluoFetch(opts) {
|
|
|
37487
37876
|
const { url } = ctx;
|
|
37488
37877
|
let \u4F1A\u8BDD\u540D;
|
|
37489
37878
|
try {
|
|
37490
|
-
\u4F1A\u8BDD\u540D =
|
|
37879
|
+
\u4F1A\u8BDD\u540D = basename22(resolveSessionFile2(sessionsDirOf2(activeRoot), url.searchParams.get("session") ?? ""));
|
|
37491
37880
|
} catch (error) {
|
|
37492
37881
|
return json(400, { error: error instanceof Error ? error.message : String(error), code: "bad-request" });
|
|
37493
37882
|
}
|
|
@@ -38565,7 +38954,7 @@ data: ${JSON.stringify({ kind: "change", event: e })}
|
|
|
38565
38954
|
const nextFrom = lastSeq !== null && lastSeq < total ? lastSeq + 1 : null;
|
|
38566
38955
|
const prevFrom = firstSeq !== null && firstSeq > 1 ? firstSeq : null;
|
|
38567
38956
|
return json(200, {
|
|
38568
|
-
session:
|
|
38957
|
+
session: basename22(file),
|
|
38569
38958
|
events: window,
|
|
38570
38959
|
firstSeq,
|
|
38571
38960
|
lastSeq,
|
|
@@ -38849,7 +39238,7 @@ data: ${JSON.stringify({ kind: "change", event: e })}
|
|
|
38849
39238
|
newFile: makeNewSessionLogFile(activeRoot, Date.now()),
|
|
38850
39239
|
...req.at === void 0 ? {} : { atSeq: req.at }
|
|
38851
39240
|
});
|
|
38852
|
-
return json(200, { session:
|
|
39241
|
+
return json(200, { session: basename22(forked.file), forkedFrom: req.session, ...req.at === void 0 ? {} : { at: req.at } }, NOSNIFF);
|
|
38853
39242
|
} catch (error) {
|
|
38854
39243
|
if (error instanceof LifecycleUserError) return json(400, { error: error.message, code: "bad-request" });
|
|
38855
39244
|
return json(500, { error: error instanceof Error ? error.message : String(error), code: "internal" });
|
|
@@ -39110,7 +39499,7 @@ data: ${JSON.stringify({ kind: "change", event: e })}
|
|
|
39110
39499
|
headers: {
|
|
39111
39500
|
"content-type": "application/x-ndjson; charset=utf-8",
|
|
39112
39501
|
// 浏览器有了它才会当下载而不是当页面渲染
|
|
39113
|
-
"content-disposition": `attachment; filename="${
|
|
39502
|
+
"content-disposition": `attachment; filename="${basename22(exportFile)}"`,
|
|
39114
39503
|
"content-length": String(\u4F53\u79EF),
|
|
39115
39504
|
// 这两条在**成功**的时候也要有(脚本两端读同一组头,不必分叉)
|
|
39116
39505
|
"x-daluo-bytes": String(\u4F53\u79EF),
|
|
@@ -41052,7 +41441,7 @@ var init_editor = __esm({
|
|
|
41052
41441
|
// packages/cli/src/tui/paste-image.ts
|
|
41053
41442
|
import { execFile as execFile9 } from "node:child_process";
|
|
41054
41443
|
import { mkdir as mkdir10, readFile as readFile19, stat as stat24, writeFile as writeFile8 } from "node:fs/promises";
|
|
41055
|
-
import { extname as extname4, isAbsolute as
|
|
41444
|
+
import { extname as extname4, isAbsolute as isAbsolute14, join as join53, resolve as resolve15 } from "node:path";
|
|
41056
41445
|
import { promisify as promisify8 } from "node:util";
|
|
41057
41446
|
function \u8BA4\u56FE\u7247\u7C7B\u578B(bytes) {
|
|
41058
41447
|
const b = bytes;
|
|
@@ -41137,7 +41526,7 @@ function \u56FE\u7247\u63CF\u8FF0(\u56FE) {
|
|
|
41137
41526
|
async function \u8BA4\u7C98\u8D34\u7684\u56FE\u7247\u8DEF\u5F84(text2) {
|
|
41138
41527
|
const t = text2.trim().replace(/^file:\/\//, "");
|
|
41139
41528
|
if (t === "" || /\s/.test(t)) return void 0;
|
|
41140
|
-
if (!
|
|
41529
|
+
if (!isAbsolute14(t)) return void 0;
|
|
41141
41530
|
const path = resolve15(t);
|
|
41142
41531
|
try {
|
|
41143
41532
|
if (!(await stat24(path)).isFile()) return void 0;
|
|
@@ -41638,7 +42027,7 @@ function mentionAt(text2, col) {
|
|
|
41638
42027
|
if (before && /[A-Za-z0-9_]/.test(before)) return null;
|
|
41639
42028
|
return { start, query: text2.slice(start + 1, at) };
|
|
41640
42029
|
}
|
|
41641
|
-
function
|
|
42030
|
+
function basename23(p) {
|
|
41642
42031
|
const i = p.lastIndexOf("/");
|
|
41643
42032
|
return i < 0 ? p : p.slice(i + 1);
|
|
41644
42033
|
}
|
|
@@ -41649,7 +42038,7 @@ function rankPaths(paths, query, limit) {
|
|
|
41649
42038
|
const lower = p.toLowerCase();
|
|
41650
42039
|
let tier;
|
|
41651
42040
|
if (!q) tier = 0;
|
|
41652
|
-
else if (
|
|
42041
|
+
else if (basename23(lower).startsWith(q)) tier = 0;
|
|
41653
42042
|
else if (lower.startsWith(q)) tier = 1;
|
|
41654
42043
|
else if (lower.includes(q)) tier = 2;
|
|
41655
42044
|
else continue;
|
|
@@ -45200,10 +45589,10 @@ var init_resume2 = __esm({
|
|
|
45200
45589
|
|
|
45201
45590
|
// packages/cli/src/tui/export.ts
|
|
45202
45591
|
import { mkdir as mkdir11, writeFile as writeFile10 } from "node:fs/promises";
|
|
45203
|
-
import { basename as
|
|
45592
|
+
import { basename as basename24, dirname as dirname18, isAbsolute as isAbsolute15, join as join56 } from "node:path";
|
|
45204
45593
|
function \u5BFC\u51FA\u6587\u4EF6\u540D(\u65E5\u5FD7, now) {
|
|
45205
45594
|
const \u65F6\u523B = now.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
|
|
45206
|
-
return `${
|
|
45595
|
+
return `${basename24(\u65E5\u5FD7).replace(/\.jsonl$/, "")}-${\u65F6\u523B}.md`;
|
|
45207
45596
|
}
|
|
45208
45597
|
function \u6709\u5BF9\u8BDD(\u4E8B\u4EF6) {
|
|
45209
45598
|
return \u4E8B\u4EF6.some((e) => e.type === "message/user" || e.type === "message/assistant");
|
|
@@ -45341,7 +45730,7 @@ async function \u843D\u5BFC\u51FA(\u7D20\u67502, \u9009\u9879) {
|
|
|
45341
45730
|
return { ok: false, error: "\u8FD9\u4E2A\u4F1A\u8BDD\u8FD8\u6CA1\u6709\u53EF\u5BFC\u51FA\u7684\u5185\u5BB9\uFF08\u4E00\u53E5\u5BF9\u8BDD\u90FD\u6CA1\u6709\uFF09\u2014\u2014\u5148\u8BF4\u4E00\u53E5\uFF0C\u518D\u6765\u5BFC\u51FA\uFF08\u7A7A\u58F3\u6587\u4EF6\u4E0D\u7B97\u5BFC\u51FA\u6210\u529F\uFF09" };
|
|
45342
45731
|
}
|
|
45343
45732
|
const \u7ED9\u7684 = \u9009\u9879.\u8DEF\u5F84?.trim() ?? "";
|
|
45344
|
-
const \u8DEF\u5F84 = \u7ED9\u7684 === "" ? join56(\u7D20\u67502.cwd, ".daluo", "exports", \u5BFC\u51FA\u6587\u4EF6\u540D(\u7D20\u67502.\u65E5\u5FD7, \u9009\u9879.now)) :
|
|
45733
|
+
const \u8DEF\u5F84 = \u7ED9\u7684 === "" ? join56(\u7D20\u67502.cwd, ".daluo", "exports", \u5BFC\u51FA\u6587\u4EF6\u540D(\u7D20\u67502.\u65E5\u5FD7, \u9009\u9879.now)) : isAbsolute15(\u7ED9\u7684) ? \u7ED9\u7684 : join56(\u7D20\u67502.cwd, \u7ED9\u7684);
|
|
45345
45734
|
const \u6587\u672C = \u8F6C\u5199\u4F1A\u8BDD(\u7D20\u67502, \u9009\u9879.now);
|
|
45346
45735
|
const r = await \u5199(\u8DEF\u5F84, \u6587\u672C);
|
|
45347
45736
|
if (!r.ok) return { ok: false, error: r.error };
|
|
@@ -46305,12 +46694,15 @@ async function tuiChat(argv) {
|
|
|
46305
46694
|
const { unmount } = render(
|
|
46306
46695
|
createTuiApp({
|
|
46307
46696
|
meta: { model: \u4F1A\u8BDD\u9009\u62E9, plan: s.planMode, compact: s.compact, version: cliVersion() },
|
|
46308
|
-
//
|
|
46309
|
-
// ①
|
|
46310
|
-
//
|
|
46697
|
+
// 起手要说出口的话(三条,判据都是「**你写的东西没生效**」):
|
|
46698
|
+
// ① 设置**写错层级**(`spec/settings.md` 演进「顶层错位」):写在顶层的 permission.rules
|
|
46699
|
+
// 文件在、规则一条不生效,症状(配了却被拒)离原因隔着整条策略链——比②更彻底,故排第一;
|
|
46700
|
+
// ② 项目级设置里被忽略的键(`spec/settings.md` 作用域缺口段前置②)——不静默;
|
|
46701
|
+
// ③ 被别的规则整个覆盖的权限规则(`P1-08`)——「你写的这条 allow 永远不会生效」,
|
|
46311
46702
|
// 此前屏上任何地方都不说(用户以为写好了、实际还在被问)。只报**完全遮蔽**那条:
|
|
46312
46703
|
// 部分遮蔽是「这个工具没全免问」,进面板看得到就行,不该每次启动都拦一句。
|
|
46313
46704
|
bootNotices: [
|
|
46705
|
+
\u9876\u5C42\u9519\u4F4D\u63D0\u793A(loadSettingsSync2(settingsFile)),
|
|
46314
46706
|
\u9879\u76EE\u7EA7\u5FFD\u7565\u63D0\u793A(s.projectSettings.\u88AB\u5FFD\u7565),
|
|
46315
46707
|
\u906E\u853D\u63D0\u793A(s.permissionShadows())
|
|
46316
46708
|
].filter((x) => x !== void 0),
|
|
@@ -46436,6 +46828,12 @@ var HOST_RETRYABLE = {
|
|
|
46436
46828
|
usage: false,
|
|
46437
46829
|
unknown: false,
|
|
46438
46830
|
"rate-limit": true,
|
|
46831
|
+
// 模型吐坏 JSON:重新采样(同一 prompt 再跑一次)大概率正常 ⇒ 与 network/timeout 同侧。
|
|
46832
|
+
// 注意它**不是** `unknown`:unknown 保守取 false(不知道就不敢自动重试),这条是知道该怎么办。
|
|
46833
|
+
"model-output": true,
|
|
46834
|
+
// 输出被截断(finish_reason=length):换个时刻重跑**同样配置**会在同一个位置再断一次
|
|
46835
|
+
// —— 要改的是输出上限(maxTokens)或让它分段,不是重试。所以与 model-output 相反。
|
|
46836
|
+
truncated: false,
|
|
46439
46837
|
auth: false
|
|
46440
46838
|
};
|
|
46441
46839
|
function zodIssuesToUserMessage(error) {
|
|
@@ -46483,6 +46881,13 @@ function classifyKind(error) {
|
|
|
46483
46881
|
if (error instanceof CliUsageError) {
|
|
46484
46882
|
return { kind: "usage", exitCode: EXIT.input };
|
|
46485
46883
|
}
|
|
46884
|
+
if (error instanceof LlmResponseFormatError) {
|
|
46885
|
+
return {
|
|
46886
|
+
kind: "config",
|
|
46887
|
+
exitCode: EXIT.config,
|
|
46888
|
+
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"
|
|
46889
|
+
};
|
|
46890
|
+
}
|
|
46486
46891
|
if (text2.includes("DALUO_LLM_")) {
|
|
46487
46892
|
const userMessage = zodIssuesToUserMessage(error);
|
|
46488
46893
|
return {
|
|
@@ -46511,6 +46916,23 @@ function classifyKind(error) {
|
|
|
46511
46916
|
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
46917
|
};
|
|
46513
46918
|
}
|
|
46919
|
+
if (\u5224\u51B3?.category === "truncated") {
|
|
46920
|
+
const \u5DE5\u5177 = error instanceof LlmToolArgsError && error.toolName !== void 0 ? `\uFF08\u5DE5\u5177 ${error.toolName} \u7684\u53C2\u6570\u4E0D\u5B8C\u6574\uFF09` : "";
|
|
46921
|
+
return {
|
|
46922
|
+
kind: "truncated",
|
|
46923
|
+
exitCode: EXIT.error,
|
|
46924
|
+
message: `\u6A21\u578B\u8F93\u51FA\u88AB max_tokens \u622A\u65AD${\u5DE5\u5177}`,
|
|
46925
|
+
hint: "\u8F93\u51FA\u5230\u4E0A\u9650\u5C31\u65AD\u4E86\uFF1A\u8C03\u5927\u8F93\u51FA\u4E0A\u9650\uFF08\u8BBE\u7F6E llm.maxTokens \u6216 DALUO_LLM_MAX_TOKENS\uFF09\uFF0C\u6216\u8BA9\u5B83\u5206\u6BB5\u8F93\u51FA\uFF1B\u540C\u914D\u7F6E\u91CD\u8DD1\u5927\u6982\u7387\u8FD8\u4F1A\u5728\u540C\u4E00\u4E2A\u4F4D\u7F6E\u622A\u65AD\u3002"
|
|
46926
|
+
};
|
|
46927
|
+
}
|
|
46928
|
+
if (error instanceof LlmToolArgsError) {
|
|
46929
|
+
return {
|
|
46930
|
+
kind: "model-output",
|
|
46931
|
+
exitCode: EXIT.error,
|
|
46932
|
+
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`}`,
|
|
46933
|
+
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"
|
|
46934
|
+
};
|
|
46935
|
+
}
|
|
46514
46936
|
if (\u5224\u51B3?.category === "rate-limit") {
|
|
46515
46937
|
return {
|
|
46516
46938
|
kind: "rate-limit",
|
|
@@ -46852,6 +47274,8 @@ async function main() {
|
|
|
46852
47274
|
if (resumeLog && !existsSync26(resumeLog)) {
|
|
46853
47275
|
throw new Error(`daluo run: --resume \u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${resumeLog}`);
|
|
46854
47276
|
}
|
|
47277
|
+
\u8BBE\u7F6E\u9519\u4F4D\u51FA\u58F0((line) => process.stderr.write(`${line}
|
|
47278
|
+
`));
|
|
46855
47279
|
const s = await setupSession({
|
|
46856
47280
|
cwd: process.cwd(),
|
|
46857
47281
|
sessionId: `s-${Date.now()}`,
|