engine7 7.1.82 → 7.1.83
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/cli.mjs +312 -274
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -105,7 +105,7 @@ async function pollRegistration(domain, deviceCode, interval, deadline, onLog, s
|
|
|
105
105
|
if (res.client_id && res.client_secret) {
|
|
106
106
|
return {
|
|
107
107
|
appId: res.client_id,
|
|
108
|
-
appSecret:
|
|
108
|
+
appSecret: res.client_secret,
|
|
109
109
|
openId: res.user_info?.open_id,
|
|
110
110
|
domain: currentDomain
|
|
111
111
|
};
|
|
@@ -138,13 +138,13 @@ async function registerFeishuApp(options = {}) {
|
|
|
138
138
|
options.onQrCode?.(qrUrl);
|
|
139
139
|
log(`\u8BF7\u7528\u98DE\u4E66 App \u626B\u63CF\u4E8C\u7EF4\u7801\uFF08${expireIn}\u79D2\u540E\u8FC7\u671F\uFF09...`);
|
|
140
140
|
const deadline = Date.now() + Math.min(expireIn, timeoutSec) * 1e3;
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
143
|
-
log(`\u2705 \u6CE8\u518C\u6210\u529F\uFF01App ID: ${
|
|
141
|
+
const result = await pollRegistration(domain, deviceCode, interval, deadline, log, options.signal);
|
|
142
|
+
if (result) {
|
|
143
|
+
log(`\u2705 \u6CE8\u518C\u6210\u529F\uFF01App ID: ${result.appId}`);
|
|
144
144
|
} else {
|
|
145
145
|
log("\u23F0 \u4E8C\u7EF4\u7801\u5DF2\u8FC7\u671F");
|
|
146
146
|
}
|
|
147
|
-
return
|
|
147
|
+
return result;
|
|
148
148
|
}
|
|
149
149
|
function sleep(ms) {
|
|
150
150
|
return new Promise((resolve11) => setTimeout(resolve11, ms));
|
|
@@ -407,20 +407,20 @@ function formatForWechat(content) {
|
|
|
407
407
|
const m = l.match(/^#{1,4}\s+(.*)/);
|
|
408
408
|
return m ? `\u3010${m[1].trim()}\u3011` : l;
|
|
409
409
|
});
|
|
410
|
-
const
|
|
410
|
+
const result = [];
|
|
411
411
|
for (const line of lines) {
|
|
412
412
|
if (line.trim().startsWith("|") && line.trim().endsWith("|")) {
|
|
413
413
|
if (/^\|[\s:-]+\|$/.test(line.trim())) continue;
|
|
414
414
|
const cells = line.trim().slice(1, -1).split("|").map((c) => c.trim());
|
|
415
415
|
if (cells.every((c) => /^[-:]+$/.test(c))) continue;
|
|
416
|
-
|
|
416
|
+
result.push(`\u2022 ${cells.join(" | ")}`);
|
|
417
417
|
} else {
|
|
418
|
-
|
|
418
|
+
result.push(line);
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
421
|
const out = [];
|
|
422
422
|
let prevBlank = false;
|
|
423
|
-
for (const l of
|
|
423
|
+
for (const l of result) {
|
|
424
424
|
if (!l.trim() && prevBlank) continue;
|
|
425
425
|
out.push(l);
|
|
426
426
|
prevBlank = !l.trim();
|
|
@@ -3017,12 +3017,12 @@ var init_openai_provider = __esm({
|
|
|
3017
3017
|
}, "openai", this.config.proxy);
|
|
3018
3018
|
let response;
|
|
3019
3019
|
while (true) {
|
|
3020
|
-
const
|
|
3021
|
-
if (
|
|
3022
|
-
response =
|
|
3020
|
+
const result = await retryGen.next();
|
|
3021
|
+
if (result.done) {
|
|
3022
|
+
response = result.value;
|
|
3023
3023
|
break;
|
|
3024
3024
|
}
|
|
3025
|
-
const { type: _retryType, ...retryFields } =
|
|
3025
|
+
const { type: _retryType, ...retryFields } = result.value;
|
|
3026
3026
|
yield { type: "api_retry", ...retryFields };
|
|
3027
3027
|
}
|
|
3028
3028
|
if (!response.ok) {
|
|
@@ -3386,12 +3386,12 @@ var init_anthropic_provider = __esm({
|
|
|
3386
3386
|
}, "anthropic", this.config.proxy);
|
|
3387
3387
|
let response;
|
|
3388
3388
|
while (true) {
|
|
3389
|
-
const
|
|
3390
|
-
if (
|
|
3391
|
-
response =
|
|
3389
|
+
const result = await retryGen.next();
|
|
3390
|
+
if (result.done) {
|
|
3391
|
+
response = result.value;
|
|
3392
3392
|
break;
|
|
3393
3393
|
}
|
|
3394
|
-
const { type: _retryType, ...retryFields } =
|
|
3394
|
+
const { type: _retryType, ...retryFields } = result.value;
|
|
3395
3395
|
yield { type: "api_retry", ...retryFields };
|
|
3396
3396
|
}
|
|
3397
3397
|
if (!response.ok) {
|
|
@@ -3755,12 +3755,12 @@ var init_gemini_provider = __esm({
|
|
|
3755
3755
|
}, "gemini", this.config.proxy);
|
|
3756
3756
|
let response;
|
|
3757
3757
|
while (true) {
|
|
3758
|
-
const
|
|
3759
|
-
if (
|
|
3760
|
-
response =
|
|
3758
|
+
const result = await retryGen.next();
|
|
3759
|
+
if (result.done) {
|
|
3760
|
+
response = result.value;
|
|
3761
3761
|
break;
|
|
3762
3762
|
}
|
|
3763
|
-
const { type: _retryType, ...retryFields } =
|
|
3763
|
+
const { type: _retryType, ...retryFields } = result.value;
|
|
3764
3764
|
yield { type: "api_retry", ...retryFields };
|
|
3765
3765
|
}
|
|
3766
3766
|
if (!response.ok) {
|
|
@@ -4094,21 +4094,21 @@ function parseHookOutput(stdout) {
|
|
|
4094
4094
|
}
|
|
4095
4095
|
function processHookJSONOutput(params) {
|
|
4096
4096
|
const { json, command, hookEvent, stdout, stderr, exitCode, durationMs } = params;
|
|
4097
|
-
const
|
|
4097
|
+
const result = {};
|
|
4098
4098
|
if (json.continue === false) {
|
|
4099
|
-
|
|
4099
|
+
result.preventContinuation = true;
|
|
4100
4100
|
if (json.stopReason) {
|
|
4101
|
-
|
|
4101
|
+
result.stopReason = json.stopReason;
|
|
4102
4102
|
}
|
|
4103
4103
|
}
|
|
4104
4104
|
if (json.decision) {
|
|
4105
4105
|
switch (json.decision) {
|
|
4106
4106
|
case "approve":
|
|
4107
|
-
|
|
4107
|
+
result.permissionBehavior = "allow";
|
|
4108
4108
|
break;
|
|
4109
4109
|
case "block":
|
|
4110
|
-
|
|
4111
|
-
|
|
4110
|
+
result.permissionBehavior = "deny";
|
|
4111
|
+
result.blockingError = {
|
|
4112
4112
|
blockingError: json.reason || "Blocked by hook",
|
|
4113
4113
|
command
|
|
4114
4114
|
};
|
|
@@ -4116,41 +4116,41 @@ function processHookJSONOutput(params) {
|
|
|
4116
4116
|
}
|
|
4117
4117
|
}
|
|
4118
4118
|
if (json.systemMessage) {
|
|
4119
|
-
|
|
4119
|
+
result.message = `[hook] ${json.systemMessage}`;
|
|
4120
4120
|
}
|
|
4121
4121
|
if (json.hookSpecificOutput) {
|
|
4122
4122
|
const hso = json.hookSpecificOutput;
|
|
4123
4123
|
if ("permissionDecision" in hso && hso.permissionDecision) {
|
|
4124
4124
|
switch (hso.permissionDecision) {
|
|
4125
4125
|
case "allow":
|
|
4126
|
-
|
|
4126
|
+
result.permissionBehavior = "allow";
|
|
4127
4127
|
break;
|
|
4128
4128
|
case "deny":
|
|
4129
|
-
|
|
4129
|
+
result.permissionBehavior = "deny";
|
|
4130
4130
|
break;
|
|
4131
4131
|
case "ask":
|
|
4132
|
-
|
|
4132
|
+
result.permissionBehavior = "ask";
|
|
4133
4133
|
break;
|
|
4134
4134
|
}
|
|
4135
4135
|
if ("permissionDecisionReason" in hso) {
|
|
4136
|
-
|
|
4136
|
+
result.hookPermissionDecisionReason = hso.permissionDecisionReason;
|
|
4137
4137
|
}
|
|
4138
4138
|
if ("updatedInput" in hso && hso.updatedInput) {
|
|
4139
|
-
|
|
4139
|
+
result.updatedInput = hso.updatedInput;
|
|
4140
4140
|
}
|
|
4141
4141
|
}
|
|
4142
4142
|
if ("additionalContext" in hso && hso.additionalContext) {
|
|
4143
|
-
|
|
4143
|
+
result.additionalContext = hso.additionalContext;
|
|
4144
4144
|
}
|
|
4145
4145
|
if ("initialUserMessage" in hso && hso.initialUserMessage) {
|
|
4146
|
-
|
|
4146
|
+
result.initialUserMessage = hso.initialUserMessage;
|
|
4147
4147
|
}
|
|
4148
4148
|
}
|
|
4149
|
-
if (!
|
|
4149
|
+
if (!result.blockingError) {
|
|
4150
4150
|
const elapsed = durationMs ? ` (${durationMs}ms)` : "";
|
|
4151
|
-
|
|
4151
|
+
result.message = result.message || `[hook:${hookEvent}] success${elapsed}`;
|
|
4152
4152
|
}
|
|
4153
|
-
return
|
|
4153
|
+
return result;
|
|
4154
4154
|
}
|
|
4155
4155
|
async function execCommandHook(hook, hookEvent, hookName, jsonInput, signal, hookId, ctx) {
|
|
4156
4156
|
const hookTimeoutMs = hook.timeout ? hook.timeout * 1e3 : TOOL_HOOK_EXECUTION_TIMEOUT_MS;
|
|
@@ -4256,17 +4256,17 @@ async function executeOneHook(hook, hookEvent, hookName, hookInput, toolUseID, s
|
|
|
4256
4256
|
};
|
|
4257
4257
|
}
|
|
4258
4258
|
const jsonInput = JSON.stringify(hookInput);
|
|
4259
|
-
const
|
|
4259
|
+
const result = await execCommandHook(hook, hookEvent, hookName, jsonInput, signal, hookId, ctx);
|
|
4260
4260
|
const durationMs = Date.now() - startMs;
|
|
4261
|
-
if (
|
|
4261
|
+
if (result.aborted) {
|
|
4262
4262
|
return {
|
|
4263
4263
|
outcome: "cancelled",
|
|
4264
4264
|
message: `[hook:${hookEvent}] cancelled`,
|
|
4265
4265
|
hook
|
|
4266
4266
|
};
|
|
4267
4267
|
}
|
|
4268
|
-
if (
|
|
4269
|
-
const blockingError =
|
|
4268
|
+
if (result.status === 2) {
|
|
4269
|
+
const blockingError = result.stderr || result.stdout || "Blocked by hook";
|
|
4270
4270
|
return {
|
|
4271
4271
|
outcome: "blocking",
|
|
4272
4272
|
blockingError: { blockingError, command: hook.command },
|
|
@@ -4274,22 +4274,22 @@ async function executeOneHook(hook, hookEvent, hookName, hookInput, toolUseID, s
|
|
|
4274
4274
|
hook
|
|
4275
4275
|
};
|
|
4276
4276
|
}
|
|
4277
|
-
if (
|
|
4277
|
+
if (result.status !== 0) {
|
|
4278
4278
|
return {
|
|
4279
4279
|
outcome: "non_blocking_error",
|
|
4280
|
-
message: `[hook:${hookEvent}] error (exit ${
|
|
4280
|
+
message: `[hook:${hookEvent}] error (exit ${result.status}): ${result.stderr || result.stdout}`,
|
|
4281
4281
|
hook
|
|
4282
4282
|
};
|
|
4283
4283
|
}
|
|
4284
|
-
const parsed = parseHookOutput(
|
|
4284
|
+
const parsed = parseHookOutput(result.stdout);
|
|
4285
4285
|
if (parsed.json && isSyncHookJSONOutput(parsed.json)) {
|
|
4286
4286
|
const processed = processHookJSONOutput({
|
|
4287
4287
|
json: parsed.json,
|
|
4288
4288
|
command: hook.command,
|
|
4289
4289
|
hookEvent,
|
|
4290
|
-
stdout:
|
|
4291
|
-
stderr:
|
|
4292
|
-
exitCode:
|
|
4290
|
+
stdout: result.stdout,
|
|
4291
|
+
stderr: result.stderr,
|
|
4292
|
+
exitCode: result.status,
|
|
4293
4293
|
durationMs
|
|
4294
4294
|
});
|
|
4295
4295
|
return {
|
|
@@ -4298,7 +4298,7 @@ async function executeOneHook(hook, hookEvent, hookName, hookInput, toolUseID, s
|
|
|
4298
4298
|
hook
|
|
4299
4299
|
};
|
|
4300
4300
|
}
|
|
4301
|
-
const textOutput = parsed.plainText ||
|
|
4301
|
+
const textOutput = parsed.plainText || result.stdout || "";
|
|
4302
4302
|
if (textOutput && (hookEvent === "UserPromptSubmit" || hookEvent === "SessionStart")) {
|
|
4303
4303
|
return {
|
|
4304
4304
|
outcome: "success",
|
|
@@ -4325,31 +4325,31 @@ function aggregateResults(results) {
|
|
|
4325
4325
|
additionalContexts: []
|
|
4326
4326
|
};
|
|
4327
4327
|
let hasBlocking = false;
|
|
4328
|
-
for (const
|
|
4329
|
-
if (
|
|
4330
|
-
aggregated.blockingError =
|
|
4328
|
+
for (const result of results) {
|
|
4329
|
+
if (result.blockingError) {
|
|
4330
|
+
aggregated.blockingError = result.blockingError;
|
|
4331
4331
|
hasBlocking = true;
|
|
4332
4332
|
}
|
|
4333
|
-
if (
|
|
4333
|
+
if (result.preventContinuation) {
|
|
4334
4334
|
aggregated.preventContinuation = true;
|
|
4335
4335
|
}
|
|
4336
|
-
if (
|
|
4337
|
-
aggregated.stopReason =
|
|
4336
|
+
if (result.stopReason) {
|
|
4337
|
+
aggregated.stopReason = result.stopReason;
|
|
4338
4338
|
}
|
|
4339
|
-
if (
|
|
4340
|
-
aggregated.permissionBehavior =
|
|
4339
|
+
if (result.permissionBehavior) {
|
|
4340
|
+
aggregated.permissionBehavior = result.permissionBehavior;
|
|
4341
4341
|
}
|
|
4342
|
-
if (
|
|
4343
|
-
aggregated.additionalContexts.push(
|
|
4342
|
+
if (result.additionalContext) {
|
|
4343
|
+
aggregated.additionalContexts.push(result.additionalContext);
|
|
4344
4344
|
}
|
|
4345
|
-
if (
|
|
4346
|
-
aggregated.initialUserMessage =
|
|
4345
|
+
if (result.initialUserMessage) {
|
|
4346
|
+
aggregated.initialUserMessage = result.initialUserMessage;
|
|
4347
4347
|
}
|
|
4348
|
-
if (
|
|
4349
|
-
aggregated.updatedInput =
|
|
4348
|
+
if (result.updatedInput) {
|
|
4349
|
+
aggregated.updatedInput = result.updatedInput;
|
|
4350
4350
|
}
|
|
4351
|
-
if (
|
|
4352
|
-
aggregated.message =
|
|
4351
|
+
if (result.message && !result.blockingError) {
|
|
4352
|
+
aggregated.message = result.message;
|
|
4353
4353
|
}
|
|
4354
4354
|
}
|
|
4355
4355
|
if (aggregated.additionalContexts.length === 0) {
|
|
@@ -4606,9 +4606,9 @@ async function executeOne(tc, ctx, signal) {
|
|
|
4606
4606
|
if (preResult.updatedInput) {
|
|
4607
4607
|
args = { ...args, ...preResult.updatedInput };
|
|
4608
4608
|
}
|
|
4609
|
-
const
|
|
4610
|
-
await executePostToolUseHooks(tc.function.name, args,
|
|
4611
|
-
return { call: tc, result
|
|
4609
|
+
const result = await tool.handler(args, ctx, signal);
|
|
4610
|
+
await executePostToolUseHooks(tc.function.name, args, result.content, hookCtx, signal);
|
|
4611
|
+
return { call: tc, result, summary: null };
|
|
4612
4612
|
} catch (err) {
|
|
4613
4613
|
await executePostToolUseFailureHooks(tc.function.name, args, err.message, hookCtx, signal);
|
|
4614
4614
|
return { call: tc, result: { content: `Tool error: ${err.message}`, isError: true }, summary: null };
|
|
@@ -5388,7 +5388,7 @@ function maybeTimeBasedMicrocompact(messages, gapThresholdMinutes = TIME_BASED_M
|
|
|
5388
5388
|
const clearSet = new Set(compactableToolCallIds.filter((id) => !keepSet.has(id)));
|
|
5389
5389
|
if (clearSet.size === 0) return null;
|
|
5390
5390
|
let tokensSaved = 0;
|
|
5391
|
-
const
|
|
5391
|
+
const result = messages.map((msg2) => {
|
|
5392
5392
|
if (msg2.role !== "tool") return msg2;
|
|
5393
5393
|
if (!msg2.tool_call_id || !clearSet.has(msg2.tool_call_id)) return msg2;
|
|
5394
5394
|
if (msg2.content === TIME_BASED_MC_CLEARED_MESSAGE) return msg2;
|
|
@@ -5401,7 +5401,7 @@ function maybeTimeBasedMicrocompact(messages, gapThresholdMinutes = TIME_BASED_M
|
|
|
5401
5401
|
if (tokensSaved === 0) return null;
|
|
5402
5402
|
const clearedIds = [...clearSet].map((id) => id.slice(0, 8)).join(",");
|
|
5403
5403
|
compactLog(TAG2, `Cleared ${clearSet.size} old tool results (~${tokensSaved} tokens), kept last ${keepSet.size} (cleared IDs: ${clearedIds})`);
|
|
5404
|
-
return { messages:
|
|
5404
|
+
return { messages: result, tokensSaved };
|
|
5405
5405
|
}
|
|
5406
5406
|
function microcompactMessages(messages) {
|
|
5407
5407
|
const toolMsgCount = messages.filter((m) => m.role === "tool").length;
|
|
@@ -5484,10 +5484,10 @@ function smartCompressToolResult(content, essentialFields, sizeLimit) {
|
|
|
5484
5484
|
}
|
|
5485
5485
|
}
|
|
5486
5486
|
if (mini.length > 0) {
|
|
5487
|
-
const
|
|
5488
|
-
if (
|
|
5487
|
+
const result = JSON.stringify(mini, null, 0);
|
|
5488
|
+
if (result.length < content.length * 0.3) {
|
|
5489
5489
|
return `[Extracted ${mini.length}/${data.length} items]
|
|
5490
|
-
${
|
|
5490
|
+
${result}`;
|
|
5491
5491
|
}
|
|
5492
5492
|
}
|
|
5493
5493
|
}
|
|
@@ -5551,7 +5551,7 @@ function splitByUserTurns(messages) {
|
|
|
5551
5551
|
function step1_smartExtract(messages, essentialFields) {
|
|
5552
5552
|
let compressed = 0;
|
|
5553
5553
|
const largeToolResults = [];
|
|
5554
|
-
const
|
|
5554
|
+
const result = messages.map((m) => {
|
|
5555
5555
|
if (m.role === "tool" && typeof m.content === "string" && m.content.length > TOOL_SIZE_LIMIT) {
|
|
5556
5556
|
const originalLen = m.content.length;
|
|
5557
5557
|
largeToolResults.push(`tool_call_id=${m.tool_call_id?.slice(0, 8)}... ${originalLen}chars`);
|
|
@@ -5567,7 +5567,7 @@ function step1_smartExtract(messages, essentialFields) {
|
|
|
5567
5567
|
if (largeToolResults.length > 0 && compressed === 0) {
|
|
5568
5568
|
compactLog(TAG3, `Step 1 smartExtract: found ${largeToolResults.length} large tool results but none could be compressed`);
|
|
5569
5569
|
}
|
|
5570
|
-
return { messages:
|
|
5570
|
+
return { messages: result, compressed };
|
|
5571
5571
|
}
|
|
5572
5572
|
function step2_compressOldTurns(messages, maxTokens, toolResultMode = "minimal") {
|
|
5573
5573
|
const { system, turns } = splitByUserTurns(messages);
|
|
@@ -5616,7 +5616,7 @@ function step2_compressOldTurns(messages, maxTokens, toolResultMode = "minimal")
|
|
|
5616
5616
|
function step3_truncateLarge(messages) {
|
|
5617
5617
|
let truncated = 0;
|
|
5618
5618
|
const details = [];
|
|
5619
|
-
const
|
|
5619
|
+
const result = messages.map((m) => {
|
|
5620
5620
|
if (m.role === "tool" && typeof m.content === "string" && m.content.length > TOOL_SIZE_LIMIT) {
|
|
5621
5621
|
const originalLen = m.content.length;
|
|
5622
5622
|
truncated++;
|
|
@@ -5631,7 +5631,7 @@ function step3_truncateLarge(messages) {
|
|
|
5631
5631
|
if (truncated > 0) {
|
|
5632
5632
|
compactLog(TAG3, `Step 3 truncateLarge: ${truncated} tool results truncated (${details.join("; ")})`);
|
|
5633
5633
|
}
|
|
5634
|
-
return { messages:
|
|
5634
|
+
return { messages: result, truncated };
|
|
5635
5635
|
}
|
|
5636
5636
|
function step4_fifoDelete(messages, maxTokens) {
|
|
5637
5637
|
if (estimateMessageTokens(messages) <= maxTokens) {
|
|
@@ -5725,7 +5725,7 @@ var init_ruleCompact = __esm({
|
|
|
5725
5725
|
// src/compact/autoCompact.ts
|
|
5726
5726
|
function stripImageBlocks(messages) {
|
|
5727
5727
|
let stripped = 0;
|
|
5728
|
-
const
|
|
5728
|
+
const result = messages.map((m) => {
|
|
5729
5729
|
if (isAttachmentMessage(m) || typeof m.content === "string" || !m.content) return m;
|
|
5730
5730
|
const filtered = m.content.filter((b) => {
|
|
5731
5731
|
if (b.type === "image") {
|
|
@@ -5738,7 +5738,7 @@ function stripImageBlocks(messages) {
|
|
|
5738
5738
|
if (filtered.length === 1 && filtered[0].type === "text") return { ...m, content: filtered[0].text };
|
|
5739
5739
|
return { ...m, content: filtered };
|
|
5740
5740
|
});
|
|
5741
|
-
return { messages:
|
|
5741
|
+
return { messages: result, stripped };
|
|
5742
5742
|
}
|
|
5743
5743
|
function getEffectiveContextWindowSize(config) {
|
|
5744
5744
|
const contextWindow = config.contextWindow || DEFAULT_COMPACT_CONFIG.contextWindow;
|
|
@@ -5757,9 +5757,9 @@ function shouldAutoCompact(messages, config) {
|
|
|
5757
5757
|
}
|
|
5758
5758
|
const tokenCount = estimateMessageTokens(messages);
|
|
5759
5759
|
const threshold = getAutoCompactThreshold(config);
|
|
5760
|
-
const
|
|
5761
|
-
compactLog(TAG4, `tokens=${tokenCount} threshold=${threshold} triggered=${
|
|
5762
|
-
return
|
|
5760
|
+
const result = tokenCount >= threshold;
|
|
5761
|
+
compactLog(TAG4, `tokens=${tokenCount} threshold=${threshold} triggered=${result}`);
|
|
5762
|
+
return result;
|
|
5763
5763
|
}
|
|
5764
5764
|
async function autoCompactIfNeeded(messages, config, tracking, provider, model, signal, hookCtx) {
|
|
5765
5765
|
if (config.enabled === false) {
|
|
@@ -5956,17 +5956,17 @@ function getBackgroundUsageNote() {
|
|
|
5956
5956
|
return "You can use the `run_in_background` parameter to run the command in the background. Only use this if you don't need the result immediately and are OK being notified when the command completes later. You do not need to check the output right away - you'll be notified when it finishes. You do not need to use '&' at the end of the command when using this parameter.";
|
|
5957
5957
|
}
|
|
5958
5958
|
function prependBullets2(items) {
|
|
5959
|
-
const
|
|
5959
|
+
const result = [];
|
|
5960
5960
|
for (const item of items) {
|
|
5961
5961
|
if (Array.isArray(item)) {
|
|
5962
5962
|
for (const sub of item) {
|
|
5963
|
-
|
|
5963
|
+
result.push(` - ${sub}`);
|
|
5964
5964
|
}
|
|
5965
5965
|
} else {
|
|
5966
|
-
|
|
5966
|
+
result.push(`- ${item}`);
|
|
5967
5967
|
}
|
|
5968
5968
|
}
|
|
5969
|
-
return
|
|
5969
|
+
return result;
|
|
5970
5970
|
}
|
|
5971
5971
|
function getExecPrompt() {
|
|
5972
5972
|
const toolPreferenceItems = [
|
|
@@ -6054,17 +6054,17 @@ function isDestructiveCommand(command) {
|
|
|
6054
6054
|
return DESTRUCTIVE_PATTERNS.some((p) => p.test(trimmed));
|
|
6055
6055
|
}
|
|
6056
6056
|
function sanitizeEnv(env) {
|
|
6057
|
-
const
|
|
6057
|
+
const result = {};
|
|
6058
6058
|
for (const [k, v] of Object.entries(env)) {
|
|
6059
6059
|
if (ENV_ALLOW_KEYS.includes(k)) {
|
|
6060
|
-
|
|
6060
|
+
result[k] = v;
|
|
6061
6061
|
continue;
|
|
6062
6062
|
}
|
|
6063
6063
|
if (!BLOCKED_ENV_KEYS.some((b) => k.toUpperCase().includes(b))) {
|
|
6064
|
-
|
|
6064
|
+
result[k] = v;
|
|
6065
6065
|
}
|
|
6066
6066
|
}
|
|
6067
|
-
return
|
|
6067
|
+
return result;
|
|
6068
6068
|
}
|
|
6069
6069
|
var DANGEROUS_COMMANDS, DESTRUCTIVE_PATTERNS, BLOCKED_ENV_KEYS, ENV_ALLOW_KEYS;
|
|
6070
6070
|
var init_bashSecurity = __esm({
|
|
@@ -6185,12 +6185,12 @@ function findShell() {
|
|
|
6185
6185
|
return cachedShell;
|
|
6186
6186
|
}
|
|
6187
6187
|
try {
|
|
6188
|
-
const
|
|
6188
|
+
const result = execSync("where.exe bash", {
|
|
6189
6189
|
encoding: "utf-8",
|
|
6190
6190
|
timeout: 5e3,
|
|
6191
6191
|
stdio: ["ignore", "pipe", "ignore"]
|
|
6192
6192
|
});
|
|
6193
|
-
const candidates =
|
|
6193
|
+
const candidates = result.trim().split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
|
|
6194
6194
|
const nonWsl = candidates.find((p) => !isWslBash(p));
|
|
6195
6195
|
if (nonWsl && fs7.existsSync(nonWsl)) {
|
|
6196
6196
|
cachedShell = { shell: nonWsl, args: ["-c"] };
|
|
@@ -7590,7 +7590,7 @@ var init_query = __esm({
|
|
|
7590
7590
|
type: "status",
|
|
7591
7591
|
text: `\u{1F9F9} Compacting context (${currentMessages.length} messages) so I can continue without losing history...`
|
|
7592
7592
|
};
|
|
7593
|
-
const
|
|
7593
|
+
const result = await autoCompactIfNeeded(
|
|
7594
7594
|
currentMessages,
|
|
7595
7595
|
this.compactConfig,
|
|
7596
7596
|
this.autoCompactTracking,
|
|
@@ -7604,25 +7604,25 @@ var init_query = __esm({
|
|
|
7604
7604
|
cwd: context.workspace || process.env.ENGINE_WORKSPACE || ""
|
|
7605
7605
|
} : void 0
|
|
7606
7606
|
);
|
|
7607
|
-
if (
|
|
7608
|
-
currentMessages =
|
|
7607
|
+
if (result.wasCompacted) {
|
|
7608
|
+
currentMessages = result.messages;
|
|
7609
7609
|
this.autoCompactTracking.compacted = true;
|
|
7610
|
-
this.autoCompactTracking.consecutiveFailures =
|
|
7611
|
-
console.log(`${this.logPrefix} Post-compact: ${currentMessages.length} messages, failures=${
|
|
7612
|
-
if (
|
|
7610
|
+
this.autoCompactTracking.consecutiveFailures = result.consecutiveFailures;
|
|
7611
|
+
console.log(`${this.logPrefix} Post-compact: ${currentMessages.length} messages, failures=${result.consecutiveFailures}`);
|
|
7612
|
+
if (result.compactionResult) {
|
|
7613
7613
|
yield {
|
|
7614
7614
|
type: "compact",
|
|
7615
|
-
preTokens:
|
|
7616
|
-
postTokens:
|
|
7615
|
+
preTokens: result.compactionResult.preCompactTokenCount,
|
|
7616
|
+
postTokens: result.compactionResult.postCompactTokenCount,
|
|
7617
7617
|
messages: currentMessages
|
|
7618
7618
|
};
|
|
7619
7619
|
yield {
|
|
7620
7620
|
type: "status",
|
|
7621
|
-
text: `\u2705 Context compacted (${
|
|
7621
|
+
text: `\u2705 Context compacted (${result.compactionResult.preCompactTokenCount.toLocaleString()} \u2192 ${result.compactionResult.postCompactTokenCount.toLocaleString()} tokens). Continuing from where I left off.`
|
|
7622
7622
|
};
|
|
7623
7623
|
}
|
|
7624
7624
|
} else {
|
|
7625
|
-
this.autoCompactTracking.consecutiveFailures =
|
|
7625
|
+
this.autoCompactTracking.consecutiveFailures = result.consecutiveFailures;
|
|
7626
7626
|
}
|
|
7627
7627
|
this.pendingFlushTurns = 0;
|
|
7628
7628
|
}
|
|
@@ -8693,13 +8693,13 @@ function recoverOrphanedParallelToolResults(allEntries, chain, byUuid, seen) {
|
|
|
8693
8693
|
}
|
|
8694
8694
|
if (recoveredCount === 0) return chain;
|
|
8695
8695
|
console.log(`[reader] Recovered ${recoveredCount} orphaned parallel tool results`);
|
|
8696
|
-
const
|
|
8696
|
+
const result = [];
|
|
8697
8697
|
for (const m of chain) {
|
|
8698
|
-
|
|
8698
|
+
result.push(m);
|
|
8699
8699
|
const toInsert = inserts.get(m.uuid);
|
|
8700
|
-
if (toInsert)
|
|
8700
|
+
if (toInsert) result.push(...toInsert);
|
|
8701
8701
|
}
|
|
8702
|
-
return
|
|
8702
|
+
return result;
|
|
8703
8703
|
}
|
|
8704
8704
|
async function readSessionHistory(filePath) {
|
|
8705
8705
|
const stat4 = fs11.statSync(filePath);
|
|
@@ -8824,18 +8824,18 @@ function entryToSessionMessage(entry) {
|
|
|
8824
8824
|
if (block.thinkingSignature) thinkingSig = block.thinkingSignature;
|
|
8825
8825
|
}
|
|
8826
8826
|
}
|
|
8827
|
-
const
|
|
8827
|
+
const result = {
|
|
8828
8828
|
role: "assistant",
|
|
8829
8829
|
content: textContent,
|
|
8830
8830
|
timestamp: entry.timestamp,
|
|
8831
8831
|
_raw: entry.raw
|
|
8832
8832
|
};
|
|
8833
|
-
if (thinkingContent)
|
|
8834
|
-
if (thinkingSig)
|
|
8833
|
+
if (thinkingContent) result.reasoning_content = thinkingContent;
|
|
8834
|
+
if (thinkingSig) result.thinking_signature = thinkingSig;
|
|
8835
8835
|
if (toolCalls.length > 0) {
|
|
8836
|
-
|
|
8836
|
+
result.tool_calls = toolCalls;
|
|
8837
8837
|
}
|
|
8838
|
-
return
|
|
8838
|
+
return result;
|
|
8839
8839
|
} else if (role === "toolResult") {
|
|
8840
8840
|
const text = extractText2(m.content);
|
|
8841
8841
|
return {
|
|
@@ -9629,9 +9629,9 @@ ${items.join("\n")}` };
|
|
|
9629
9629
|
let content;
|
|
9630
9630
|
let encoding;
|
|
9631
9631
|
try {
|
|
9632
|
-
const
|
|
9633
|
-
content =
|
|
9634
|
-
encoding =
|
|
9632
|
+
const result2 = readFileContent(filePath);
|
|
9633
|
+
content = result2.content;
|
|
9634
|
+
encoding = result2.encoding;
|
|
9635
9635
|
} catch (e) {
|
|
9636
9636
|
return { content: e.message, isError: true };
|
|
9637
9637
|
}
|
|
@@ -9648,7 +9648,7 @@ ${items.join("\n")}` };
|
|
|
9648
9648
|
const mtime = new Date(stat4.mtimeMs).toLocaleString();
|
|
9649
9649
|
const info = encoding !== "utf8" ? `[${encoding}] ` : "";
|
|
9650
9650
|
const header = `${info}${filePath} (${totalLines} \u884C, ${stat4.size} bytes, \u4FEE\u6539: ${mtime})`;
|
|
9651
|
-
const
|
|
9651
|
+
const result = [
|
|
9652
9652
|
header,
|
|
9653
9653
|
"\u2500".repeat(60),
|
|
9654
9654
|
numbered.join("\n"),
|
|
@@ -9657,7 +9657,7 @@ ${items.join("\n")}` };
|
|
|
9657
9657
|
].join("\n");
|
|
9658
9658
|
return { content: loopWarning ? `${loopWarning}
|
|
9659
9659
|
|
|
9660
|
-
${
|
|
9660
|
+
${result}` : result };
|
|
9661
9661
|
},
|
|
9662
9662
|
isConcurrencySafe: () => true,
|
|
9663
9663
|
isReadOnly: () => true
|
|
@@ -9869,19 +9869,19 @@ function isOpeningContext(chars, index) {
|
|
|
9869
9869
|
}
|
|
9870
9870
|
function applyCurlyDoubleQuotes(str) {
|
|
9871
9871
|
const chars = [...str];
|
|
9872
|
-
const
|
|
9872
|
+
const result = [];
|
|
9873
9873
|
for (let i = 0; i < chars.length; i++) {
|
|
9874
9874
|
if (chars[i] === '"') {
|
|
9875
|
-
|
|
9875
|
+
result.push(isOpeningContext(chars, i) ? LEFT_DOUBLE_CURLY : RIGHT_DOUBLE_CURLY);
|
|
9876
9876
|
} else {
|
|
9877
|
-
|
|
9877
|
+
result.push(chars[i]);
|
|
9878
9878
|
}
|
|
9879
9879
|
}
|
|
9880
|
-
return
|
|
9880
|
+
return result.join("");
|
|
9881
9881
|
}
|
|
9882
9882
|
function applyCurlySingleQuotes(str) {
|
|
9883
9883
|
const chars = [...str];
|
|
9884
|
-
const
|
|
9884
|
+
const result = [];
|
|
9885
9885
|
for (let i = 0; i < chars.length; i++) {
|
|
9886
9886
|
if (chars[i] === "'") {
|
|
9887
9887
|
const prev = i > 0 ? chars[i - 1] : void 0;
|
|
@@ -9889,25 +9889,25 @@ function applyCurlySingleQuotes(str) {
|
|
|
9889
9889
|
const prevIsLetter = prev !== void 0 && /\p{L}/u.test(prev);
|
|
9890
9890
|
const nextIsLetter = next !== void 0 && /\p{L}/u.test(next);
|
|
9891
9891
|
if (prevIsLetter && nextIsLetter) {
|
|
9892
|
-
|
|
9892
|
+
result.push(RIGHT_SINGLE_CURLY);
|
|
9893
9893
|
} else {
|
|
9894
|
-
|
|
9894
|
+
result.push(isOpeningContext(chars, i) ? LEFT_SINGLE_CURLY : RIGHT_SINGLE_CURLY);
|
|
9895
9895
|
}
|
|
9896
9896
|
} else {
|
|
9897
|
-
|
|
9897
|
+
result.push(chars[i]);
|
|
9898
9898
|
}
|
|
9899
9899
|
}
|
|
9900
|
-
return
|
|
9900
|
+
return result.join("");
|
|
9901
9901
|
}
|
|
9902
9902
|
function preserveQuoteStyle(oldString, actualOldString, newString) {
|
|
9903
9903
|
if (oldString === actualOldString) return newString;
|
|
9904
9904
|
const hasDouble = actualOldString.includes(LEFT_DOUBLE_CURLY) || actualOldString.includes(RIGHT_DOUBLE_CURLY);
|
|
9905
9905
|
const hasSingle = actualOldString.includes(LEFT_SINGLE_CURLY) || actualOldString.includes(RIGHT_SINGLE_CURLY);
|
|
9906
9906
|
if (!hasDouble && !hasSingle) return newString;
|
|
9907
|
-
let
|
|
9908
|
-
if (hasDouble)
|
|
9909
|
-
if (hasSingle)
|
|
9910
|
-
return
|
|
9907
|
+
let result = newString;
|
|
9908
|
+
if (hasDouble) result = applyCurlyDoubleQuotes(result);
|
|
9909
|
+
if (hasSingle) result = applyCurlySingleQuotes(result);
|
|
9910
|
+
return result;
|
|
9911
9911
|
}
|
|
9912
9912
|
function applyEditToFile(originalContent, oldString, newString, replaceAll = false) {
|
|
9913
9913
|
const f = replaceAll ? (content, search2, replace) => content.replaceAll(search2, () => replace) : (content, search2, replace) => content.replace(search2, () => replace);
|
|
@@ -9930,23 +9930,23 @@ function generateEditDiff(fileContent, actualOldString, actualNewString, context
|
|
|
9930
9930
|
const oldLines = actualOldString.split(/\r?\n/);
|
|
9931
9931
|
const newLines = actualNewString.split(/\r?\n/);
|
|
9932
9932
|
const fileLines = fileContent.split(/\r?\n/);
|
|
9933
|
-
const
|
|
9933
|
+
const result = [];
|
|
9934
9934
|
const ctxStart = Math.max(0, startLine - contextLines);
|
|
9935
9935
|
for (let i = ctxStart; i < startLine; i++) {
|
|
9936
|
-
|
|
9936
|
+
result.push(` ${fileLines[i] ?? ""}`);
|
|
9937
9937
|
}
|
|
9938
9938
|
for (let i = 0; i < oldLines.length; i++) {
|
|
9939
|
-
|
|
9939
|
+
result.push(`-${oldLines[i]}`);
|
|
9940
9940
|
}
|
|
9941
9941
|
for (let i = 0; i < newLines.length; i++) {
|
|
9942
|
-
|
|
9942
|
+
result.push(`+${newLines[i]}`);
|
|
9943
9943
|
}
|
|
9944
9944
|
const afterStart = startLine + oldLines.length;
|
|
9945
9945
|
const afterEnd = Math.min(fileLines.length, afterStart + contextLines);
|
|
9946
9946
|
for (let i = afterStart; i < afterEnd; i++) {
|
|
9947
|
-
|
|
9947
|
+
result.push(` ${fileLines[i] ?? ""}`);
|
|
9948
9948
|
}
|
|
9949
|
-
return
|
|
9949
|
+
return result.join("\n");
|
|
9950
9950
|
}
|
|
9951
9951
|
var LEFT_SINGLE_CURLY, RIGHT_SINGLE_CURLY, LEFT_DOUBLE_CURLY, RIGHT_DOUBLE_CURLY, MAX_EDIT_FILE_SIZE;
|
|
9952
9952
|
var init_edit = __esm({
|
|
@@ -10333,19 +10333,19 @@ var init_grep = __esm({
|
|
|
10333
10333
|
rgArgs.push("--glob", p);
|
|
10334
10334
|
}
|
|
10335
10335
|
}
|
|
10336
|
-
const
|
|
10337
|
-
if (
|
|
10336
|
+
const result = await ripGrep(rgArgs, searchPath);
|
|
10337
|
+
if (result.timedOut) {
|
|
10338
10338
|
return {
|
|
10339
10339
|
content: `\u641C\u7D22\u8D85\u65F6\uFF08${RG_TIMEOUT_MS / 1e3}\u79D2\uFF09\u3002\u5C1D\u8BD5\u7F29\u5C0F\u641C\u7D22\u8303\u56F4\u6216\u4F7F\u7528\u66F4\u5177\u4F53\u7684 pattern\u3002`,
|
|
10340
10340
|
isError: true
|
|
10341
10341
|
};
|
|
10342
10342
|
}
|
|
10343
|
-
if (
|
|
10343
|
+
if (result.lines.length === 0) {
|
|
10344
10344
|
return { content: "No files found" };
|
|
10345
10345
|
}
|
|
10346
10346
|
const cwd = ctx.workspace;
|
|
10347
10347
|
if (outputMode === "content") {
|
|
10348
|
-
const { items: limited2, appliedLimit: appliedLimit2 } = applyHeadLimit(
|
|
10348
|
+
const { items: limited2, appliedLimit: appliedLimit2 } = applyHeadLimit(result.lines, headLimit, offset);
|
|
10349
10349
|
const finalLines = limited2.map((line) => {
|
|
10350
10350
|
const colonIdx = line.indexOf(":");
|
|
10351
10351
|
if (colonIdx > 0) {
|
|
@@ -10363,7 +10363,7 @@ var init_grep = __esm({
|
|
|
10363
10363
|
return { content: content + suffix2 };
|
|
10364
10364
|
}
|
|
10365
10365
|
if (outputMode === "count") {
|
|
10366
|
-
const { items: limited2, appliedLimit: appliedLimit2 } = applyHeadLimit(
|
|
10366
|
+
const { items: limited2, appliedLimit: appliedLimit2 } = applyHeadLimit(result.lines, headLimit, offset);
|
|
10367
10367
|
const finalLines = limited2.map((line) => {
|
|
10368
10368
|
const colonIdx = line.lastIndexOf(":");
|
|
10369
10369
|
if (colonIdx > 0) {
|
|
@@ -10385,7 +10385,7 @@ var init_grep = __esm({
|
|
|
10385
10385
|
Found ${totalMatches} total occurrences across ${limited2.length} files.${limitInfo2 ? ` with pagination = ${limitInfo2}` : ""}`;
|
|
10386
10386
|
return { content: content + summary };
|
|
10387
10387
|
}
|
|
10388
|
-
const { items: limited, appliedLimit } = applyHeadLimit(
|
|
10388
|
+
const { items: limited, appliedLimit } = applyHeadLimit(result.lines, headLimit, offset);
|
|
10389
10389
|
const filenames = limited.map((line) => {
|
|
10390
10390
|
const colonIdx = line.indexOf(":");
|
|
10391
10391
|
const fpath = colonIdx > 0 ? line.substring(0, colonIdx) : line;
|
|
@@ -10939,7 +10939,7 @@ async function runAgent(opts) {
|
|
|
10939
10939
|
console.warn(`[agent:${agentId}] No visualRegistry in context, cannot bind Discord channel for "${visualName}"`);
|
|
10940
10940
|
}
|
|
10941
10941
|
}
|
|
10942
|
-
let
|
|
10942
|
+
let result = "";
|
|
10943
10943
|
let toolUseCount = 0;
|
|
10944
10944
|
try {
|
|
10945
10945
|
for await (const chunk of subEngine.query(messages, runAbort.signal, opts.context)) {
|
|
@@ -10970,12 +10970,12 @@ async function runAgent(opts) {
|
|
|
10970
10970
|
}
|
|
10971
10971
|
}
|
|
10972
10972
|
if (chunk.type === "text" && chunk.text) {
|
|
10973
|
-
|
|
10973
|
+
result += chunk.text;
|
|
10974
10974
|
}
|
|
10975
10975
|
if (chunk.type === "result") {
|
|
10976
10976
|
const resultContent = chunk.content;
|
|
10977
10977
|
if (resultContent) {
|
|
10978
|
-
|
|
10978
|
+
result = resultContent;
|
|
10979
10979
|
}
|
|
10980
10980
|
}
|
|
10981
10981
|
}
|
|
@@ -10983,11 +10983,11 @@ async function runAgent(opts) {
|
|
|
10983
10983
|
agentRegistry.unregister(agentId);
|
|
10984
10984
|
}
|
|
10985
10985
|
const durationMs = Date.now() - startTime;
|
|
10986
|
-
console.log(`[agent:${agentId}] ${agentDef.agentType} completed in ${durationMs}ms, ${toolUseCount} tools, ${
|
|
10986
|
+
console.log(`[agent:${agentId}] ${agentDef.agentType} completed in ${durationMs}ms, ${toolUseCount} tools, ${result.length} chars`);
|
|
10987
10987
|
return {
|
|
10988
10988
|
agentId,
|
|
10989
10989
|
agentType: agentDef.agentType,
|
|
10990
|
-
content:
|
|
10990
|
+
content: result || "(no output from agent)",
|
|
10991
10991
|
totalToolUseCount: toolUseCount,
|
|
10992
10992
|
totalDurationMs: durationMs
|
|
10993
10993
|
};
|
|
@@ -12133,7 +12133,7 @@ var init_AgentTool = __esm({
|
|
|
12133
12133
|
console.log(`[AgentTool] Background requested but running synchronously (headless limitation)`);
|
|
12134
12134
|
}
|
|
12135
12135
|
try {
|
|
12136
|
-
const
|
|
12136
|
+
const result = await runAgent({
|
|
12137
12137
|
prompt,
|
|
12138
12138
|
description,
|
|
12139
12139
|
subagentType,
|
|
@@ -12150,9 +12150,9 @@ var init_AgentTool = __esm({
|
|
|
12150
12150
|
// visual 系统用这个 name 创建频道
|
|
12151
12151
|
});
|
|
12152
12152
|
const parts = [
|
|
12153
|
-
|
|
12153
|
+
result.content,
|
|
12154
12154
|
"",
|
|
12155
|
-
`[Agent: ${
|
|
12155
|
+
`[Agent: ${result.agentType}, ${result.totalDurationMs}ms, ${result.totalToolUseCount} tool uses]`
|
|
12156
12156
|
];
|
|
12157
12157
|
visualEmitter?.emitAgentDone(agentLabel);
|
|
12158
12158
|
return {
|
|
@@ -12949,7 +12949,7 @@ var init_my_eyes = __esm({
|
|
|
12949
12949
|
]
|
|
12950
12950
|
};
|
|
12951
12951
|
try {
|
|
12952
|
-
let
|
|
12952
|
+
let result = "";
|
|
12953
12953
|
const stream = provider.streamChat({
|
|
12954
12954
|
model: modelId,
|
|
12955
12955
|
messages: [userMsg],
|
|
@@ -12959,13 +12959,13 @@ var init_my_eyes = __esm({
|
|
|
12959
12959
|
});
|
|
12960
12960
|
for await (const chunk of stream) {
|
|
12961
12961
|
if (chunk.type === "text" && chunk.text) {
|
|
12962
|
-
|
|
12962
|
+
result += chunk.text;
|
|
12963
12963
|
}
|
|
12964
12964
|
}
|
|
12965
|
-
if (!
|
|
12965
|
+
if (!result.trim()) {
|
|
12966
12966
|
return { content: "Image analysis returned empty.", isError: true };
|
|
12967
12967
|
}
|
|
12968
|
-
return { content:
|
|
12968
|
+
return { content: result };
|
|
12969
12969
|
} catch (e) {
|
|
12970
12970
|
return { content: `Image analysis failed: ${e.message}`, isError: true };
|
|
12971
12971
|
}
|
|
@@ -14343,18 +14343,18 @@ function parseDuration(s) {
|
|
|
14343
14343
|
}
|
|
14344
14344
|
function expandDates(input) {
|
|
14345
14345
|
const parts = input.split(",").map((s) => s.trim()).filter(Boolean);
|
|
14346
|
-
const
|
|
14346
|
+
const result = [];
|
|
14347
14347
|
for (const part of parts) {
|
|
14348
14348
|
const range = parseDateRange(part);
|
|
14349
14349
|
if (range && range.dEnd > range.dStart) {
|
|
14350
14350
|
for (let d = range.dStart; d <= range.dEnd; d++) {
|
|
14351
|
-
|
|
14351
|
+
result.push(`${range.month}/${d}`);
|
|
14352
14352
|
}
|
|
14353
14353
|
} else {
|
|
14354
|
-
|
|
14354
|
+
result.push(part);
|
|
14355
14355
|
}
|
|
14356
14356
|
}
|
|
14357
|
-
return
|
|
14357
|
+
return result;
|
|
14358
14358
|
}
|
|
14359
14359
|
function timeToMin(t) {
|
|
14360
14360
|
const [hh, mm] = t.split(":").map(Number);
|
|
@@ -14557,16 +14557,16 @@ function addBatch(db2, args) {
|
|
|
14557
14557
|
).run(args.event, dateStr, args.time, args.time, durationMin, remindMin, remindAt, 0, nowIso(), args.channel || null, args.channelTarget || null);
|
|
14558
14558
|
ok.push(`#${r.lastInsertRowid} ${dateStr}`);
|
|
14559
14559
|
}
|
|
14560
|
-
let
|
|
14561
|
-
if (skipped.length > 0)
|
|
14562
|
-
|
|
14560
|
+
let result = `\u2705 \u6210\u529F ${ok.length} \u6761`;
|
|
14561
|
+
if (skipped.length > 0) result += `\uFF0C\u26A0\uFE0F \u51B2\u7A81\u8DF3\u8FC7 ${skipped.length} \u6761`;
|
|
14562
|
+
result += `
|
|
14563
14563
|
${ok.map((s) => ` ${s}`).join("\n")}`;
|
|
14564
14564
|
if (skipped.length > 0) {
|
|
14565
|
-
|
|
14565
|
+
result += `
|
|
14566
14566
|
\u51B2\u7A81\u8BE6\u60C5\uFF1A
|
|
14567
14567
|
${skipped.map((s) => ` ${s}`).join("\n")}`;
|
|
14568
14568
|
}
|
|
14569
|
-
return
|
|
14569
|
+
return result;
|
|
14570
14570
|
}
|
|
14571
14571
|
function addTask(db2, args) {
|
|
14572
14572
|
const { dateStr, timeExact, event: event2, docPath } = args;
|
|
@@ -14807,7 +14807,7 @@ var init_calendar = __esm({
|
|
|
14807
14807
|
if (!action) return { content: "Error: action is required", isError: true };
|
|
14808
14808
|
try {
|
|
14809
14809
|
const db2 = openDb(ctx.workspace);
|
|
14810
|
-
let
|
|
14810
|
+
let result;
|
|
14811
14811
|
let isAddTask = false;
|
|
14812
14812
|
if (action === "add") {
|
|
14813
14813
|
const event2 = args.event?.trim();
|
|
@@ -14816,22 +14816,22 @@ var init_calendar = __esm({
|
|
|
14816
14816
|
const repeat = args.repeat || (args.weekly ? "weekly" : "once");
|
|
14817
14817
|
if (repeat === "daily" || repeat === "weekdays") {
|
|
14818
14818
|
if (!args.time) return { content: "Error: add daily/weekdays needs time (e.g. 23:00)", isError: true };
|
|
14819
|
-
|
|
14819
|
+
result = addDaily(db2, { time: args.time, event: event2, repeatType: repeat, remind, channel: ctx.channel, channelTarget: ctx.channelTarget });
|
|
14820
14820
|
} else if (repeat === "weekly") {
|
|
14821
14821
|
const day = args.day;
|
|
14822
14822
|
if (!day) return { content: "Error: add weekly needs day", isError: true };
|
|
14823
|
-
|
|
14823
|
+
result = addWeekly(db2, { day, event: event2, time: args.time, duration: args.duration, remind, channel: ctx.channel, channelTarget: ctx.channelTarget });
|
|
14824
14824
|
} else {
|
|
14825
14825
|
const date = args.date?.trim();
|
|
14826
14826
|
if (!date) return { content: "Error: add once needs date (e.g. 5/26)", isError: true };
|
|
14827
|
-
|
|
14827
|
+
result = addDate(db2, { dateStr: date, event: event2, time: args.time, duration: args.duration, remind, channel: ctx.channel, channelTarget: ctx.channelTarget });
|
|
14828
14828
|
}
|
|
14829
14829
|
} else if (action === "add-batch") {
|
|
14830
14830
|
const event2 = args.event?.trim();
|
|
14831
14831
|
const datesInput = args.dates?.trim();
|
|
14832
14832
|
if (!event2) return { content: "Error: add-batch needs event", isError: true };
|
|
14833
14833
|
if (!datesInput) return { content: 'Error: add-batch needs dates (e.g. "7/2,7/4,7/6-7/10")', isError: true };
|
|
14834
|
-
|
|
14834
|
+
result = addBatch(db2, { datesInput, event: event2, time: args.time, duration: args.duration, remind: args.remind, channel: ctx.channel, channelTarget: ctx.channelTarget });
|
|
14835
14835
|
} else if (action === "add-task") {
|
|
14836
14836
|
isAddTask = true;
|
|
14837
14837
|
const event2 = args.event?.trim();
|
|
@@ -14842,60 +14842,60 @@ var init_calendar = __esm({
|
|
|
14842
14842
|
if (!date) return { content: "Error: add-task needs date (e.g. 7/5)", isError: true };
|
|
14843
14843
|
if (!timeExact || !timeExact.includes(":")) return { content: "Error: add-task needs time_exact (HH:MM, e.g. 14:00)", isError: true };
|
|
14844
14844
|
if (!docPath) return { content: "\u274C \u521B\u5EFA\u5931\u8D25\uFF1Aadd-task \u5FC5\u987B\u4F20 doc_path\u3002\n\u6CA1\u6709\u6587\u6863\u652F\u6491\u7684 task \u4E0D\u662F\u5408\u683C\u7684 task\u3002\n\u8BF7\u5148\u5728 docs/todo/ \u4E0B\u521B\u5EFA\u6587\u6863\uFF08\u547D\u540D\uFF1AYYYY-MM-DD_\u4E3B\u9898.md \u6216 \u4EFB\u52A1\u540D.md\uFF09\uFF0C\u7136\u540E\u4F20 doc_path \u53C2\u6570\u3002", isError: true };
|
|
14845
|
-
|
|
14845
|
+
result = addTask(db2, { dateStr: date, timeExact, event: event2, remind: args.remind, channel: ctx.channel, channelTarget: ctx.channelTarget, docPath });
|
|
14846
14846
|
} else if (action === "reschedule") {
|
|
14847
14847
|
if (args.id == null) return { content: "Error: reschedule needs id", isError: true };
|
|
14848
14848
|
const date = args.date?.trim();
|
|
14849
14849
|
const timeExact = args.time_exact?.trim();
|
|
14850
14850
|
if (!date) return { content: "Error: reschedule needs date (e.g. 7/10)", isError: true };
|
|
14851
14851
|
if (!timeExact || !timeExact.includes(":")) return { content: "Error: reschedule needs time_exact (HH:MM)", isError: true };
|
|
14852
|
-
|
|
14852
|
+
result = reschedule(db2, { id: args.id, dateStr: date, timeExact, remind: args.remind });
|
|
14853
14853
|
} else if (action === "link-doc") {
|
|
14854
14854
|
if (args.id == null) return { content: "Error: link-doc needs id", isError: true };
|
|
14855
14855
|
const docPath = args.doc_path?.trim();
|
|
14856
14856
|
if (!docPath) return { content: "Error: link-doc needs doc_path", isError: true };
|
|
14857
|
-
|
|
14857
|
+
result = linkDoc(db2, args.id, docPath);
|
|
14858
14858
|
} else if (action === "find-doc") {
|
|
14859
14859
|
if (args.id == null) return { content: "Error: find-doc needs id", isError: true };
|
|
14860
|
-
|
|
14860
|
+
result = findDoc(db2, args.id);
|
|
14861
14861
|
} else if (action === "list") {
|
|
14862
|
-
|
|
14862
|
+
result = list(db2, { all: !!args.all });
|
|
14863
14863
|
} else if (action === "done") {
|
|
14864
14864
|
if (args.id == null) return { content: "Error: done needs id", isError: true };
|
|
14865
|
-
|
|
14865
|
+
result = done(db2, args.id);
|
|
14866
14866
|
} else if (action === "pending") {
|
|
14867
|
-
|
|
14867
|
+
result = pending(db2);
|
|
14868
14868
|
} else if (action === "search") {
|
|
14869
14869
|
const kw = args.event?.trim();
|
|
14870
14870
|
if (!kw) return { content: "Error: search needs keyword (event field)", isError: true };
|
|
14871
|
-
|
|
14871
|
+
result = search(db2, kw);
|
|
14872
14872
|
} else if (action === "archive") {
|
|
14873
14873
|
if (args.id == null) return { content: "Error: archive needs id", isError: true };
|
|
14874
|
-
|
|
14874
|
+
result = archive(db2, args.id);
|
|
14875
14875
|
} else if (action === "delete") {
|
|
14876
14876
|
if (args.id == null) return { content: "Error: delete needs id", isError: true };
|
|
14877
|
-
|
|
14877
|
+
result = archive(db2, args.id);
|
|
14878
14878
|
} else if (action === "cleanup") {
|
|
14879
|
-
|
|
14879
|
+
result = cleanup(db2);
|
|
14880
14880
|
} else if (action === "stats") {
|
|
14881
|
-
|
|
14881
|
+
result = stats(db2);
|
|
14882
14882
|
} else {
|
|
14883
14883
|
return { content: `Error: unknown action '${action}'`, isError: true };
|
|
14884
14884
|
}
|
|
14885
14885
|
db2.close();
|
|
14886
|
-
const isFailed =
|
|
14886
|
+
const isFailed = result.startsWith("\u274C") || result.includes("Error") || result.includes("\u7528\u6CD5");
|
|
14887
14887
|
if (isAddTask && !isFailed) {
|
|
14888
14888
|
const { enqueueNotification: enqueueNotification2, buildCalendarNotification: buildCalendarNotification2 } = await Promise.resolve().then(() => (init_task_manager(), task_manager_exports));
|
|
14889
14889
|
const sessionId = ctx.sessionId || "main";
|
|
14890
14890
|
const channel = ctx.channel;
|
|
14891
14891
|
const channelTarget = ctx.channelTarget;
|
|
14892
14892
|
if (!channel || !channelTarget) {
|
|
14893
|
-
return { content:
|
|
14893
|
+
return { content: result };
|
|
14894
14894
|
}
|
|
14895
|
-
const notif = buildCalendarNotification2("task-created", [
|
|
14895
|
+
const notif = buildCalendarNotification2("task-created", [result + "\n\n\u8BF7\u6309\u4EE5\u4E0B\u6B65\u9AA4\u540C\u6B65\uFF1A\n1. \u5148\u62C6 Phase\uFF08\u5217\u51FA\u5B50\u4EFB\u52A1\uFF0C\u6807 - [ ] / - [~] / - [!] \u72B6\u6001\uFF09\u2014 \u4E0D\u62C6 Phase \u76F4\u63A5\u5E72\u6D3B = 3-Strike \u7B2C1\u6B21\n2. \u540C\u6B65\u5230 SESSION-STATE.md\uFF08- [~] \u4EFB\u52A1\u540D \u2014 started M/D HH:MM\uFF09\n3. \u7528\u4EFB\u52A1\u7BA1\u7406\u5DE5\u5177\u8DDF\u8E2A\uFF08\u5982 TodoWrite\uFF09\n4. \u5927\u4EFB\u52A1\u5199 docs/todo/YYYY-MM-DD_\u4E3B\u9898.md\uFF08\u80CC\u666F+\u65B9\u6848+\u9A8C\u8BC1\u6807\u51C6\uFF09\n5. \u5B8C\u6210\u540E\uFF1ASESSION-STATE \u6807 - [x] + calendar done <id>"]);
|
|
14896
14896
|
enqueueNotification2(notif, { sessionId, channel, channelTarget });
|
|
14897
14897
|
}
|
|
14898
|
-
return { content:
|
|
14898
|
+
return { content: result };
|
|
14899
14899
|
} catch (e) {
|
|
14900
14900
|
return { content: `Calendar ${action} failed: ${e.message}`, isError: true };
|
|
14901
14901
|
}
|
|
@@ -15195,10 +15195,10 @@ var init_TodoWriteTool = __esm({
|
|
|
15195
15195
|
const allDone = todos.length > 0 && todos.every((t) => t.status === "completed");
|
|
15196
15196
|
const newTodos = allDone ? [] : todos;
|
|
15197
15197
|
saveTodos(sessionId, newTodos);
|
|
15198
|
-
let
|
|
15198
|
+
let result = "Todos have been successfully. Ensure that you use the todo list to track your progress. Please proceed with the current task as applicable";
|
|
15199
15199
|
if (allDone && todos.length >= 3) {
|
|
15200
15200
|
}
|
|
15201
|
-
return { content:
|
|
15201
|
+
return { content: result };
|
|
15202
15202
|
},
|
|
15203
15203
|
isReadOnly: () => false,
|
|
15204
15204
|
isConcurrencySafe: () => false
|
|
@@ -17026,16 +17026,16 @@ var init_task_output = __esm({
|
|
|
17026
17026
|
}
|
|
17027
17027
|
let task = initialTask;
|
|
17028
17028
|
if (block && (task.status === "running" || task.status === "pending")) {
|
|
17029
|
-
const
|
|
17030
|
-
if (!
|
|
17029
|
+
const result2 = await waitForTaskCompletion(taskId, timeout, signal);
|
|
17030
|
+
if (!result2) {
|
|
17031
17031
|
return { content: `Task ${taskId} was aborted or not found`, isError: true };
|
|
17032
17032
|
}
|
|
17033
|
-
task =
|
|
17033
|
+
task = result2;
|
|
17034
17034
|
}
|
|
17035
17035
|
const output = getTaskOutput(taskId);
|
|
17036
17036
|
const truncated = output.length > 5e4 ? output.slice(0, 5e4) + "\n...[output truncated]" : output;
|
|
17037
17037
|
const retrievalStatus = !block && (task.status === "running" || task.status === "pending") ? "not_ready" : block && (task.status === "running" || task.status === "pending") ? "timeout" : "success";
|
|
17038
|
-
const
|
|
17038
|
+
const result = {
|
|
17039
17039
|
retrieval_status: retrievalStatus,
|
|
17040
17040
|
task: {
|
|
17041
17041
|
task_id: task.id,
|
|
@@ -17047,7 +17047,7 @@ var init_task_output = __esm({
|
|
|
17047
17047
|
}
|
|
17048
17048
|
};
|
|
17049
17049
|
return {
|
|
17050
|
-
content: JSON.stringify(
|
|
17050
|
+
content: JSON.stringify(result, null, 2)
|
|
17051
17051
|
};
|
|
17052
17052
|
},
|
|
17053
17053
|
isConcurrencySafe: () => true,
|
|
@@ -17195,7 +17195,7 @@ var init_reply_blocklist = __esm({
|
|
|
17195
17195
|
const workspace = ctx.workspace || process.env.ENGINE_WORKSPACE || ".";
|
|
17196
17196
|
const stripIds = ctx?.channelConfig?.discord?.stripMentionIds || [];
|
|
17197
17197
|
ensureLoaded(workspace, stripIds);
|
|
17198
|
-
let
|
|
17198
|
+
let result;
|
|
17199
17199
|
switch (action) {
|
|
17200
17200
|
case "list": {
|
|
17201
17201
|
const lines = ["**\u81EA\u52A8\u56DE\u590D\u5C4F\u853D\u5217\u8868\uFF1A**"];
|
|
@@ -17209,14 +17209,14 @@ var init_reply_blocklist = __esm({
|
|
|
17209
17209
|
lines.push(` - \`${id}\``);
|
|
17210
17210
|
}
|
|
17211
17211
|
}
|
|
17212
|
-
|
|
17212
|
+
result = { content: lines.join("\n") };
|
|
17213
17213
|
break;
|
|
17214
17214
|
}
|
|
17215
17215
|
case "block_all": {
|
|
17216
17216
|
state.blockAll = true;
|
|
17217
17217
|
save(workspace);
|
|
17218
17218
|
console.log(`[reply-blocklist] Block ALL enabled`);
|
|
17219
|
-
|
|
17219
|
+
result = { content: '\u{1F6AB} \u5DF2\u5C4F\u853D\u6240\u6709\u4EBA\u7684\u81EA\u52A8\u56DE\u590D\u3002\u7528 action="unblock_all" \u89E3\u9664\u3002' };
|
|
17220
17220
|
break;
|
|
17221
17221
|
}
|
|
17222
17222
|
case "unblock_all": {
|
|
@@ -17224,7 +17224,7 @@ var init_reply_blocklist = __esm({
|
|
|
17224
17224
|
state.blockedUserIds = [];
|
|
17225
17225
|
save(workspace);
|
|
17226
17226
|
console.log(`[reply-blocklist] Block ALL disabled, list cleared`);
|
|
17227
|
-
|
|
17227
|
+
result = { content: "\u2705 \u5DF2\u89E3\u9664\u6240\u6709\u4EBA\u5C4F\u853D\uFF0C\u6E05\u7A7A\u5C4F\u853D\u5217\u8868\u3002" };
|
|
17228
17228
|
break;
|
|
17229
17229
|
}
|
|
17230
17230
|
case "add": {
|
|
@@ -17241,7 +17241,7 @@ var init_reply_blocklist = __esm({
|
|
|
17241
17241
|
}
|
|
17242
17242
|
save(workspace);
|
|
17243
17243
|
console.log(`[reply-blocklist] Added ${added} user(s): ${ids.join(", ")}`);
|
|
17244
|
-
|
|
17244
|
+
result = { content: `\u2705 \u5DF2\u5C4F\u853D ${added} \u4EBA\uFF08\u5171 ${state.blockedUserIds.length} \u4EBA\uFF09\u3002\u5C4F\u853D\u5217\u8868\uFF1A${state.blockedUserIds.join(", ")}` };
|
|
17245
17245
|
break;
|
|
17246
17246
|
}
|
|
17247
17247
|
case "remove": {
|
|
@@ -17254,11 +17254,11 @@ var init_reply_blocklist = __esm({
|
|
|
17254
17254
|
const removed = before - state.blockedUserIds.length;
|
|
17255
17255
|
save(workspace);
|
|
17256
17256
|
console.log(`[reply-blocklist] Removed ${removed} user(s)`);
|
|
17257
|
-
|
|
17257
|
+
result = { content: `\u2705 \u5DF2\u79FB\u9664 ${removed} \u4EBA\uFF08\u5269 ${state.blockedUserIds.length} \u4EBA\uFF09\u3002` };
|
|
17258
17258
|
break;
|
|
17259
17259
|
}
|
|
17260
17260
|
default:
|
|
17261
|
-
|
|
17261
|
+
result = { content: `Error: \u672A\u77E5\u64CD\u4F5C "${action}"`, isError: true };
|
|
17262
17262
|
}
|
|
17263
17263
|
const adapters = globalThis.__channelAdapters;
|
|
17264
17264
|
if (adapters) {
|
|
@@ -17267,7 +17267,7 @@ var init_reply_blocklist = __esm({
|
|
|
17267
17267
|
discordAdapter.addStripMentionIds(state.blockedUserIds);
|
|
17268
17268
|
}
|
|
17269
17269
|
}
|
|
17270
|
-
return
|
|
17270
|
+
return result;
|
|
17271
17271
|
},
|
|
17272
17272
|
isConcurrencySafe: () => true,
|
|
17273
17273
|
isReadOnly: () => false
|
|
@@ -17749,9 +17749,9 @@ Select up to ${topK} most relevant (return their 1-indexed numbers as JSON {"sel
|
|
|
17749
17749
|
const parsed = JSON.parse(jsonMatch[0]);
|
|
17750
17750
|
if (parsed.selected && Array.isArray(parsed.selected)) {
|
|
17751
17751
|
const indices = parsed.selected.filter((n) => n >= 1 && n <= candidates.length).map((n) => n - 1);
|
|
17752
|
-
const
|
|
17753
|
-
console.log(`[memdir] rerank: ${model} selected ${
|
|
17754
|
-
return
|
|
17752
|
+
const result = indices.map((i) => candidates[i]);
|
|
17753
|
+
console.log(`[memdir] rerank: ${model} selected ${result.length}/${candidates.length} candidates (indices: ${indices.map((i) => i + 1).join(",")})`);
|
|
17754
|
+
return result.slice(0, topK);
|
|
17755
17755
|
}
|
|
17756
17756
|
} catch {
|
|
17757
17757
|
}
|
|
@@ -17977,7 +17977,7 @@ async function findRelevantMemoriesEveros(query, _memoryDir, alreadySurfaced = /
|
|
|
17977
17977
|
} else {
|
|
17978
17978
|
}
|
|
17979
17979
|
}
|
|
17980
|
-
const
|
|
17980
|
+
const result = [];
|
|
17981
17981
|
const seenSubjects = /* @__PURE__ */ new Set();
|
|
17982
17982
|
for (const ep of episodes) {
|
|
17983
17983
|
if (ep.score < minScore) continue;
|
|
@@ -17987,7 +17987,7 @@ async function findRelevantMemoriesEveros(query, _memoryDir, alreadySurfaced = /
|
|
|
17987
17987
|
if (surfacedSubjects.has(subject)) continue;
|
|
17988
17988
|
if (seenSubjects.has(subject)) continue;
|
|
17989
17989
|
seenSubjects.add(subject);
|
|
17990
|
-
|
|
17990
|
+
result.push({
|
|
17991
17991
|
path: virtualPath,
|
|
17992
17992
|
mtimeMs: ep.timestamp ? new Date(ep.timestamp).getTime() : Date.now(),
|
|
17993
17993
|
content: `### ${ep.subject}
|
|
@@ -17995,10 +17995,10 @@ async function findRelevantMemoriesEveros(query, _memoryDir, alreadySurfaced = /
|
|
|
17995
17995
|
${ep.episode || ep.summary}`,
|
|
17996
17996
|
header: formatEverosHeader(ep)
|
|
17997
17997
|
});
|
|
17998
|
-
if (
|
|
17998
|
+
if (result.length >= topK) break;
|
|
17999
17999
|
}
|
|
18000
|
-
console.log(`[memdir] everos recall: returning ${
|
|
18001
|
-
return
|
|
18000
|
+
console.log(`[memdir] everos recall: returning ${result.length} memories (after dedup)`);
|
|
18001
|
+
return result;
|
|
18002
18002
|
} catch (e) {
|
|
18003
18003
|
const ms = Date.now() - t0;
|
|
18004
18004
|
console.warn(`[memdir] everos recall: error after ${ms}ms: ${e?.message ?? e}`);
|
|
@@ -18455,10 +18455,10 @@ ${conversationText}`
|
|
|
18455
18455
|
channelManager: null
|
|
18456
18456
|
};
|
|
18457
18457
|
let toolCount = 0;
|
|
18458
|
-
let
|
|
18458
|
+
let result = "";
|
|
18459
18459
|
for await (const chunk of extractEngine.query(extractMessages, void 0, toolContext)) {
|
|
18460
18460
|
if (chunk.type === "text" && chunk.text) {
|
|
18461
|
-
|
|
18461
|
+
result += chunk.text;
|
|
18462
18462
|
}
|
|
18463
18463
|
if (chunk.type === "tool_call") {
|
|
18464
18464
|
toolCount++;
|
|
@@ -18469,7 +18469,7 @@ ${conversationText}`
|
|
|
18469
18469
|
persistState(workspace);
|
|
18470
18470
|
const duration = Date.now() - startTime;
|
|
18471
18471
|
console.log(
|
|
18472
|
-
`[memory] extractMemories finished in ${duration}ms \u2014 ${toolCount} tools used, ${
|
|
18472
|
+
`[memory] extractMemories finished in ${duration}ms \u2014 ${toolCount} tools used, ${result.length} chars`
|
|
18473
18473
|
);
|
|
18474
18474
|
} catch (error) {
|
|
18475
18475
|
console.warn(
|
|
@@ -18884,18 +18884,18 @@ function truncateSessionMemoryForCompact(content) {
|
|
|
18884
18884
|
let wasTruncated = false;
|
|
18885
18885
|
for (const line of lines) {
|
|
18886
18886
|
if (line.startsWith("# ")) {
|
|
18887
|
-
const
|
|
18888
|
-
outputLines.push(...
|
|
18889
|
-
wasTruncated = wasTruncated ||
|
|
18887
|
+
const result2 = flushSessionSection(currentSectionHeader, currentSectionLines, maxCharsPerSection);
|
|
18888
|
+
outputLines.push(...result2.lines);
|
|
18889
|
+
wasTruncated = wasTruncated || result2.wasTruncated;
|
|
18890
18890
|
currentSectionHeader = line;
|
|
18891
18891
|
currentSectionLines = [];
|
|
18892
18892
|
} else {
|
|
18893
18893
|
currentSectionLines.push(line);
|
|
18894
18894
|
}
|
|
18895
18895
|
}
|
|
18896
|
-
const
|
|
18897
|
-
outputLines.push(...
|
|
18898
|
-
wasTruncated = wasTruncated ||
|
|
18896
|
+
const result = flushSessionSection(currentSectionHeader, currentSectionLines, maxCharsPerSection);
|
|
18897
|
+
outputLines.push(...result.lines);
|
|
18898
|
+
wasTruncated = wasTruncated || result.wasTruncated;
|
|
18899
18899
|
return { truncatedContent: outputLines.join("\n"), wasTruncated };
|
|
18900
18900
|
}
|
|
18901
18901
|
function flushSessionSection(sectionHeader, sectionLines, maxCharsPerSection) {
|
|
@@ -19082,10 +19082,10 @@ ${messages.filter((m) => m.role === "user" || m.role === "assistant").slice(-20)
|
|
|
19082
19082
|
channelManager: null
|
|
19083
19083
|
};
|
|
19084
19084
|
let toolCount = 0;
|
|
19085
|
-
let
|
|
19085
|
+
let result = "";
|
|
19086
19086
|
for await (const chunk of extractEngine.query(extractMessages, void 0, toolContext)) {
|
|
19087
19087
|
if (chunk.type === "text" && chunk.text) {
|
|
19088
|
-
|
|
19088
|
+
result += chunk.text;
|
|
19089
19089
|
}
|
|
19090
19090
|
if (chunk.type === "tool_call") {
|
|
19091
19091
|
toolCount++;
|
|
@@ -19094,7 +19094,7 @@ ${messages.filter((m) => m.role === "user" || m.role === "assistant").slice(-20)
|
|
|
19094
19094
|
recordExtractionTokenCount(roughTokenCountEstimation5(
|
|
19095
19095
|
messages.map((m) => typeof m.content === "string" ? m.content : "").join("")
|
|
19096
19096
|
));
|
|
19097
|
-
console.log(`[sessionMemory] extraction complete: ${toolCount} edits applied, ${
|
|
19097
|
+
console.log(`[sessionMemory] extraction complete: ${toolCount} edits applied, ${result.length} chars`);
|
|
19098
19098
|
return {
|
|
19099
19099
|
fired: true,
|
|
19100
19100
|
summary: `Applied ${toolCount} edits to session notes`
|
|
@@ -19477,23 +19477,23 @@ ${sessionIds.map((id) => `- ${id}`).join("\n")}`;
|
|
|
19477
19477
|
workspace,
|
|
19478
19478
|
channelManager: null
|
|
19479
19479
|
};
|
|
19480
|
-
let
|
|
19480
|
+
let result = "";
|
|
19481
19481
|
let turnCount = 0;
|
|
19482
19482
|
dlog("dream query START");
|
|
19483
19483
|
for await (const chunk of dreamEngine.query(messages, void 0, toolContext)) {
|
|
19484
19484
|
if (chunk.type === "text") {
|
|
19485
|
-
|
|
19485
|
+
result += chunk.text || "";
|
|
19486
19486
|
}
|
|
19487
19487
|
if (chunk.type === "tool_call") {
|
|
19488
19488
|
turnCount++;
|
|
19489
19489
|
dlog(`dream turn ${turnCount}: tool_call`);
|
|
19490
19490
|
}
|
|
19491
19491
|
}
|
|
19492
|
-
dlog(`dream query DONE \u2014 ${turnCount} tool_calls, result=${
|
|
19492
|
+
dlog(`dream query DONE \u2014 ${turnCount} tool_calls, result=${result.length} chars`);
|
|
19493
19493
|
await recordConsolidation(memoryDir);
|
|
19494
19494
|
dlog(`recordConsolidation OK \u2014 wrote .consolidate-lock`);
|
|
19495
19495
|
console.log(`[autoDream] completed \u2014 reviewed ${sessionIds.length} sessions`);
|
|
19496
|
-
return { fired: true, summary:
|
|
19496
|
+
return { fired: true, summary: result.slice(0, 500) };
|
|
19497
19497
|
} catch (e) {
|
|
19498
19498
|
const err = e;
|
|
19499
19499
|
dlog(`CATCH failed: ${err.message}
|
|
@@ -20268,11 +20268,11 @@ ${text}` : text });
|
|
|
20268
20268
|
toolOverride: void 0,
|
|
20269
20269
|
disableThinking: extractP?.disableThinking ?? true
|
|
20270
20270
|
});
|
|
20271
|
-
executeAutoDream2().then((
|
|
20272
|
-
if (
|
|
20273
|
-
console.log(`[autoDream] completed: ${
|
|
20271
|
+
executeAutoDream2().then((result) => {
|
|
20272
|
+
if (result.fired) {
|
|
20273
|
+
console.log(`[autoDream] completed: ${result.summary?.slice(0, 200)}`);
|
|
20274
20274
|
} else {
|
|
20275
|
-
console.log(`[autoDream] not fired: ${
|
|
20275
|
+
console.log(`[autoDream] not fired: ${result.reason}`);
|
|
20276
20276
|
}
|
|
20277
20277
|
}).catch((err) => {
|
|
20278
20278
|
console.warn(`[handle-query] AutoDream error: ${err.message}`);
|
|
@@ -20656,10 +20656,10 @@ function emitInit(sessionId, model) {
|
|
|
20656
20656
|
session_id: sessionId
|
|
20657
20657
|
});
|
|
20658
20658
|
}
|
|
20659
|
-
function emitTurn(
|
|
20659
|
+
function emitTurn(result, model) {
|
|
20660
20660
|
const content = [];
|
|
20661
|
-
if (
|
|
20662
|
-
content.push({ type: "text", text:
|
|
20661
|
+
if (result.thinking) content.push({ type: "thinking", text: result.thinking });
|
|
20662
|
+
content.push({ type: "text", text: result.text });
|
|
20663
20663
|
writeLine({
|
|
20664
20664
|
type: "assistant",
|
|
20665
20665
|
message: {
|
|
@@ -20672,25 +20672,25 @@ function emitTurn(result2, model) {
|
|
|
20672
20672
|
usage: { input_tokens: 0, output_tokens: 0 }
|
|
20673
20673
|
},
|
|
20674
20674
|
uuid: randomUUID9(),
|
|
20675
|
-
session_id:
|
|
20675
|
+
session_id: result.sessionId
|
|
20676
20676
|
});
|
|
20677
20677
|
writeLine({
|
|
20678
20678
|
type: "result",
|
|
20679
|
-
subtype:
|
|
20680
|
-
is_error: !
|
|
20681
|
-
...
|
|
20682
|
-
duration_ms:
|
|
20683
|
-
duration_api_ms:
|
|
20684
|
-
num_turns:
|
|
20685
|
-
result:
|
|
20679
|
+
subtype: result.ok ? "success" : "error_during_execution",
|
|
20680
|
+
is_error: !result.ok,
|
|
20681
|
+
...result.terminalReason ? { terminal_reason: result.terminalReason } : {},
|
|
20682
|
+
duration_ms: result.durationMs,
|
|
20683
|
+
duration_api_ms: result.durationMs,
|
|
20684
|
+
num_turns: result.numTurns,
|
|
20685
|
+
result: result.text,
|
|
20686
20686
|
stop_reason: "end_turn",
|
|
20687
20687
|
total_cost_usd: 0,
|
|
20688
20688
|
usage: { input_tokens: 0, output_tokens: 0 },
|
|
20689
20689
|
modelUsage: {},
|
|
20690
20690
|
permission_denials: [],
|
|
20691
|
-
errors:
|
|
20691
|
+
errors: result.errors,
|
|
20692
20692
|
uuid: randomUUID9(),
|
|
20693
|
-
session_id:
|
|
20693
|
+
session_id: result.sessionId
|
|
20694
20694
|
});
|
|
20695
20695
|
}
|
|
20696
20696
|
async function doCcRun(argv) {
|
|
@@ -20778,9 +20778,9 @@ async function doCcRun(argv) {
|
|
|
20778
20778
|
process.stderr.write("cc-run: \u6CA1\u6536\u5230 prompt\uFF08-p \u6216 stdin user message \u5747\u4E3A\u7A7A\uFF09\n");
|
|
20779
20779
|
return 1;
|
|
20780
20780
|
}
|
|
20781
|
-
let
|
|
20781
|
+
let result;
|
|
20782
20782
|
try {
|
|
20783
|
-
|
|
20783
|
+
result = await runQuery(args);
|
|
20784
20784
|
} catch (e) {
|
|
20785
20785
|
const errMsg = String(e?.message || e);
|
|
20786
20786
|
process.stderr.write(`cc-run: ${errMsg}
|
|
@@ -20803,10 +20803,10 @@ async function doCcRun(argv) {
|
|
|
20803
20803
|
return 1;
|
|
20804
20804
|
}
|
|
20805
20805
|
if (args.outputFormat === "stream-json") {
|
|
20806
|
-
emitTurn(
|
|
20806
|
+
emitTurn(result, model);
|
|
20807
20807
|
await flushStdout();
|
|
20808
20808
|
} else {
|
|
20809
|
-
process.stdout.write(
|
|
20809
|
+
process.stdout.write(result.text.endsWith("\n") ? result.text : result.text + "\n");
|
|
20810
20810
|
await flushStdout();
|
|
20811
20811
|
}
|
|
20812
20812
|
return 0;
|
|
@@ -20829,6 +20829,8 @@ __export(cli_travel_exports, {
|
|
|
20829
20829
|
doExport: () => doExport,
|
|
20830
20830
|
doImport: () => doImport,
|
|
20831
20831
|
loadTravelConfig: () => loadTravelConfig,
|
|
20832
|
+
parseImportArgs: () => parseImportArgs,
|
|
20833
|
+
resolveArchiveForTest: () => resolveArchiveForTest,
|
|
20832
20834
|
saveTravelConfig: () => saveTravelConfig
|
|
20833
20835
|
});
|
|
20834
20836
|
import * as path29 from "node:path";
|
|
@@ -20847,26 +20849,26 @@ function saveTravelConfig(cfg) {
|
|
|
20847
20849
|
fs27.writeFileSync(CONFIG_PATH, JSON.stringify(cfg, null, 2));
|
|
20848
20850
|
}
|
|
20849
20851
|
function sanitizeContent(content, dirs) {
|
|
20850
|
-
let
|
|
20852
|
+
let result = content;
|
|
20851
20853
|
for (const { placeholder, getOriginal } of PATH_PLACEHOLDERS) {
|
|
20852
20854
|
const original = getOriginal(dirs);
|
|
20853
20855
|
if (original) {
|
|
20854
|
-
|
|
20855
|
-
|
|
20856
|
-
|
|
20856
|
+
result = result.split(original).join(placeholder);
|
|
20857
|
+
result = result.split(original.replace(/\//g, "\\")).join(placeholder);
|
|
20858
|
+
result = result.split(original.replace(/\//g, "\\\\")).join(placeholder);
|
|
20857
20859
|
}
|
|
20858
20860
|
}
|
|
20859
|
-
return
|
|
20861
|
+
return result;
|
|
20860
20862
|
}
|
|
20861
20863
|
function restoreContent(content, dirs) {
|
|
20862
|
-
let
|
|
20864
|
+
let result = content;
|
|
20863
20865
|
for (const { placeholder, getOriginal } of PATH_PLACEHOLDERS) {
|
|
20864
20866
|
const target = getOriginal(dirs);
|
|
20865
20867
|
if (target) {
|
|
20866
|
-
|
|
20868
|
+
result = result.split(placeholder).join(target);
|
|
20867
20869
|
}
|
|
20868
20870
|
}
|
|
20869
|
-
return
|
|
20871
|
+
return result;
|
|
20870
20872
|
}
|
|
20871
20873
|
function isTextFile(filePath) {
|
|
20872
20874
|
const ext = path29.extname(filePath).toLowerCase();
|
|
@@ -21133,21 +21135,55 @@ async function doExport(opts) {
|
|
|
21133
21135
|
}
|
|
21134
21136
|
await uploadToGitHub(cfg, archiveFile, agentName, version, manifest);
|
|
21135
21137
|
}
|
|
21138
|
+
function parseImportArgs(args) {
|
|
21139
|
+
let stateDir = "";
|
|
21140
|
+
let agentName = "";
|
|
21141
|
+
let version = "";
|
|
21142
|
+
let archiveFile = "";
|
|
21143
|
+
let dryRun2 = false;
|
|
21144
|
+
for (let i = 0; i < args.length; i++) {
|
|
21145
|
+
if (args[i] === "--state-dir" && args[i + 1]) stateDir = args[++i];
|
|
21146
|
+
else if (args[i] === "--agent" && args[i + 1]) agentName = args[++i];
|
|
21147
|
+
else if (args[i] === "--version" && args[i + 1]) version = args[++i];
|
|
21148
|
+
else if (args[i] === "--file" && args[i + 1]) archiveFile = args[++i];
|
|
21149
|
+
else if (args[i] === "--dry-run") dryRun2 = true;
|
|
21150
|
+
}
|
|
21151
|
+
if (!stateDir) throw new Error("import \u9700\u8981 --state-dir <path>");
|
|
21152
|
+
if (!agentName) agentName = path29.basename(stateDir);
|
|
21153
|
+
return { stateDir, agentName, version, archiveFile, dryRun: dryRun2 };
|
|
21154
|
+
}
|
|
21155
|
+
async function resolveArchiveForTest(opts) {
|
|
21156
|
+
if (opts.archiveFile) {
|
|
21157
|
+
if (!fs27.existsSync(opts.archiveFile)) {
|
|
21158
|
+
throw new Error(`\u672C\u5730\u5305\u4E0D\u5B58\u5728: ${opts.archiveFile}`);
|
|
21159
|
+
}
|
|
21160
|
+
return opts.archiveFile;
|
|
21161
|
+
}
|
|
21162
|
+
return opts.downloadFallback();
|
|
21163
|
+
}
|
|
21136
21164
|
async function doImport(opts) {
|
|
21137
|
-
const { agentName, stateDir, version, dryRun: dryRun2 } = opts;
|
|
21165
|
+
const { agentName, stateDir, version, archiveFile, dryRun: dryRun2 } = opts;
|
|
21138
21166
|
console.log(`\u{1F4E5} engine7 import`);
|
|
21139
21167
|
console.log(` agent: ${agentName}`);
|
|
21140
21168
|
console.log(` target: ${stateDir}`);
|
|
21141
|
-
const cfg = loadTravelConfig();
|
|
21142
|
-
if (!cfg || !cfg.githubToken) {
|
|
21143
|
-
console.error(`\u274C \u672A\u914D\u7F6E GitHub\uFF0C\u65E0\u6CD5\u4E0B\u8F7D`);
|
|
21144
|
-
console.error(` \u914D\u7F6E: \u7F16\u8F91 ${CONFIG_PATH}`);
|
|
21145
|
-
process.exit(1);
|
|
21146
|
-
}
|
|
21147
21169
|
const tmpDir = path29.join(os4.tmpdir(), `engine7-import-${agentName}-${Date.now()}`);
|
|
21148
21170
|
fs27.mkdirSync(tmpDir, { recursive: true });
|
|
21149
|
-
const
|
|
21150
|
-
|
|
21171
|
+
const resolved = await resolveArchiveForTest({
|
|
21172
|
+
archiveFile: archiveFile || "",
|
|
21173
|
+
tmpDir,
|
|
21174
|
+
downloadFallback: async () => {
|
|
21175
|
+
const cfg = loadTravelConfig();
|
|
21176
|
+
if (!cfg || !cfg.githubToken) {
|
|
21177
|
+
console.error(`\u274C \u672A\u914D\u7F6E GitHub\uFF0C\u65E0\u6CD5\u4E0B\u8F7D`);
|
|
21178
|
+
console.error(` \u914D\u7F6E: \u7F16\u8F91 ${CONFIG_PATH}`);
|
|
21179
|
+
console.error(` \u6216\u7528 --file <\u672C\u5730\u5305.tar.gz> \u79BB\u7EBF\u5BFC\u5165`);
|
|
21180
|
+
process.exit(1);
|
|
21181
|
+
}
|
|
21182
|
+
return downloadFromGitHub(cfg, agentName, version, tmpDir);
|
|
21183
|
+
}
|
|
21184
|
+
});
|
|
21185
|
+
const finalArchive = resolved;
|
|
21186
|
+
console.log(`\u2705 \u5305\u5C31\u7EEA: ${finalArchive}`);
|
|
21151
21187
|
if (dryRun2) {
|
|
21152
21188
|
console.log(`
|
|
21153
21189
|
[DRY RUN] \u53EA\u4E0B\u8F7D\u4E0D\u6062\u590D`);
|
|
@@ -21155,7 +21191,7 @@ async function doImport(opts) {
|
|
|
21155
21191
|
}
|
|
21156
21192
|
console.log(`\u{1F4C2} \u89E3\u5305\u4E2D...`);
|
|
21157
21193
|
const tarExe = process.platform === "win32" ? "C:\\Windows\\System32\\tar.exe" : "tar";
|
|
21158
|
-
execSync2(`"${tarExe}" -xzf "${
|
|
21194
|
+
execSync2(`"${tarExe}" -xzf "${finalArchive}" -C "${tmpDir}"`, { stdio: "pipe" });
|
|
21159
21195
|
const stagingDir = path29.join(tmpDir, agentName);
|
|
21160
21196
|
const manifestPath = path29.join(stagingDir, "manifest.json");
|
|
21161
21197
|
if (!fs27.existsSync(manifestPath)) {
|
|
@@ -21798,7 +21834,7 @@ async function configureFeishu(rl, v) {
|
|
|
21798
21834
|
const feishuMode = await ask(rl, "\u9009\u62E9 (1/2)", "1");
|
|
21799
21835
|
if (feishuMode === "1") {
|
|
21800
21836
|
console.log("\n\u{1F4DD} \u6B63\u5728\u751F\u6210\u98DE\u4E66\u4E8C\u7EF4\u7801...\n");
|
|
21801
|
-
const
|
|
21837
|
+
const result = await registerFeishuApp({
|
|
21802
21838
|
onLog: (msg2) => console.log(` ${msg2}`),
|
|
21803
21839
|
onQrCode: async (url) => {
|
|
21804
21840
|
try {
|
|
@@ -21812,14 +21848,14 @@ async function configureFeishu(rl, v) {
|
|
|
21812
21848
|
}
|
|
21813
21849
|
}
|
|
21814
21850
|
});
|
|
21815
|
-
if (
|
|
21816
|
-
v.feishuAppId =
|
|
21817
|
-
v.feishuAppSecret =
|
|
21818
|
-
v.feishuOpenId =
|
|
21851
|
+
if (result) {
|
|
21852
|
+
v.feishuAppId = result.appId;
|
|
21853
|
+
v.feishuAppSecret = result.appSecret;
|
|
21854
|
+
v.feishuOpenId = result.openId || "";
|
|
21819
21855
|
console.log(`
|
|
21820
|
-
\u2705 App ID: ${
|
|
21821
|
-
console.log(` \u2705 App Secret: ${
|
|
21822
|
-
if (
|
|
21856
|
+
\u2705 App ID: ${result.appId}`);
|
|
21857
|
+
console.log(` \u2705 App Secret: ${result.appSecret.slice(0, 6)}...`);
|
|
21858
|
+
if (result.openId) console.log(` \u2705 Open ID: ${result.openId}`);
|
|
21823
21859
|
} else {
|
|
21824
21860
|
console.log("\n \u26A0\uFE0F \u626B\u7801\u8D85\u65F6\u6216\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u8F93\u5165");
|
|
21825
21861
|
v.feishuAppId = await ask(rl, "\u98DE\u4E66 App ID");
|
|
@@ -22281,7 +22317,7 @@ async function main() {
|
|
|
22281
22317
|
console.log("\u{1F527} \u98DE\u4E66\u626B\u7801\u63A5\u5165...");
|
|
22282
22318
|
const { registerFeishuApp: registerFeishuApp2 } = await Promise.resolve().then(() => (init_feishu_quick_register(), feishu_quick_register_exports));
|
|
22283
22319
|
const { renderQrTerminal: renderQrTerminal2 } = await Promise.resolve().then(() => (init_qr_render(), qr_render_exports));
|
|
22284
|
-
const
|
|
22320
|
+
const result = await registerFeishuApp2({
|
|
22285
22321
|
onLog: (msg2) => console.log(` ${msg2}`),
|
|
22286
22322
|
onQrCode: async (url) => {
|
|
22287
22323
|
try {
|
|
@@ -22293,7 +22329,7 @@ async function main() {
|
|
|
22293
22329
|
}
|
|
22294
22330
|
}
|
|
22295
22331
|
});
|
|
22296
|
-
if (!
|
|
22332
|
+
if (!result) {
|
|
22297
22333
|
console.error("\u274C \u626B\u7801\u8D85\u65F6\u6216\u5931\u8D25");
|
|
22298
22334
|
process.exit(1);
|
|
22299
22335
|
}
|
|
@@ -22316,13 +22352,13 @@ async function main() {
|
|
|
22316
22352
|
if (configFile2 && fs28.existsSync(configFile2)) {
|
|
22317
22353
|
const j = JSON.parse(fs28.readFileSync(configFile2, "utf8"));
|
|
22318
22354
|
j.channels = j.channels || {};
|
|
22319
|
-
j.channels.feishu = { enabled: true, appId:
|
|
22355
|
+
j.channels.feishu = { enabled: true, appId: result.appId, appSecret: result.appSecret, connectionMode: "websocket", dmPolicy: "pairing", groupPolicy: "open" };
|
|
22320
22356
|
fs28.writeFileSync(configFile2, JSON.stringify(j, null, 2), "utf8");
|
|
22321
22357
|
console.log("\u2705 \u98DE\u4E66\u901A\u9053\u5DF2\u5199\u5165: " + configFile2);
|
|
22322
22358
|
console.log("\u91CD\u542F\u751F\u6548: engine7 restart");
|
|
22323
22359
|
} else {
|
|
22324
22360
|
console.log("\u26A0\uFE0F \u6CA1\u627E\u5230 config\uFF0C\u624B\u52A8\u52A0\uFF1A");
|
|
22325
|
-
console.log(JSON.stringify({ feishu: { enabled: true, appId:
|
|
22361
|
+
console.log(JSON.stringify({ feishu: { enabled: true, appId: result.appId, appSecret: result.appSecret, connectionMode: "websocket", dmPolicy: "pairing", groupPolicy: "open" } }, null, 2));
|
|
22326
22362
|
}
|
|
22327
22363
|
process.exit(0);
|
|
22328
22364
|
}
|
|
@@ -22406,11 +22442,13 @@ async function main() {
|
|
|
22406
22442
|
let importStateDir = "";
|
|
22407
22443
|
let agentName = "";
|
|
22408
22444
|
let version = "";
|
|
22445
|
+
let archiveFile = "";
|
|
22409
22446
|
let dryRun2 = false;
|
|
22410
22447
|
for (let i = 1; i < args.length; i++) {
|
|
22411
22448
|
if (args[i] === "--state-dir" && args[i + 1]) importStateDir = args[++i];
|
|
22412
22449
|
else if (args[i] === "--agent" && args[i + 1]) agentName = args[++i];
|
|
22413
22450
|
else if (args[i] === "--version" && args[i + 1]) version = args[++i];
|
|
22451
|
+
else if (args[i] === "--file" && args[i + 1]) archiveFile = args[++i];
|
|
22414
22452
|
else if (args[i] === "--dry-run") dryRun2 = true;
|
|
22415
22453
|
}
|
|
22416
22454
|
if (!importStateDir) {
|
|
@@ -22418,7 +22456,7 @@ async function main() {
|
|
|
22418
22456
|
process.exit(1);
|
|
22419
22457
|
}
|
|
22420
22458
|
if (!agentName) agentName = path30.basename(importStateDir);
|
|
22421
|
-
await doImport2({ agentName, stateDir: importStateDir, version, dryRun: dryRun2 });
|
|
22459
|
+
await doImport2({ agentName, stateDir: importStateDir, version, archiveFile: archiveFile || void 0, dryRun: dryRun2 });
|
|
22422
22460
|
process.exit(0);
|
|
22423
22461
|
}
|
|
22424
22462
|
if (subcommand === "start" || subcommand === "restart") {
|