engine7 7.1.149 → 7.1.150

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.
@@ -1666,6 +1666,18 @@ var init_registry = __esm({
1666
1666
  effect: "hot",
1667
1667
  internal: true
1668
1668
  },
1669
+ // 1130 Gmail 冷启动:连接即触发 + 每日巡查,新装机默认开。model 为空走 topics.clean.model → extract → mem7 链(免费档自动退回主力模型)
1670
+ { path: "gmailColdstart.enabled", type: "boolean", group: "feature", label: "Gmail \u51B7\u542F\u52A8\uFF08\u8FDE\u63A5\u540E\u81EA\u52A8\u8BFB\u5386\u53F2\u8BA4\u4EBA\uFF09", effect: "hot", internal: true },
1671
+ { path: "gmailColdstart.model", type: "string", group: "model", label: "Gmail \u51B7\u542F\u52A8\u63D0\u70BC\u6A21\u578B\uFF08\u7A7A=\u6CBF\u7528\u8BB0\u5FC6\u63D0\u53D6\u6A21\u578B\uFF0C\u514D\u8D39\u6863\u81EA\u52A8\u9000\u56DE\u4E3B\u529B\uFF09", effect: "hot", internal: true },
1672
+ {
1673
+ path: "gmailColdstart.patrolHour",
1674
+ type: "number",
1675
+ group: "feature",
1676
+ label: "Gmail \u6BCF\u65E5\u5DE1\u67E5\u6574\u70B9\uFF080-23\uFF09",
1677
+ effect: "hot",
1678
+ internal: true,
1679
+ validate: (value) => Number.isInteger(value) && Number(value) >= 0 && Number(value) <= 23 ? null : "\u5DE1\u67E5\u6574\u70B9\u987B\u4E3A 0-23"
1680
+ },
1669
1681
  {
1670
1682
  path: "mem7.turnReadBudgetMs",
1671
1683
  type: "number",
@@ -8333,6 +8333,8 @@ function attachmentToMessage(attachment) {
8333
8333
  ${attachment.notifications.join("\n\n")}`
8334
8334
  )
8335
8335
  };
8336
+ case "coldstart_hint":
8337
+ return { role: "user", content: wrapInSystemReminder(attachment.text) };
8336
8338
  case "teammate_messages": {
8337
8339
  const lines = attachment.messages.map(
8338
8340
  (m) => m.summary ? `[From: ${m.from}] ${m.summary}
@@ -13454,13 +13456,17 @@ var init_session_map = __esm({
13454
13456
 
13455
13457
  // src/cc-driver/long-http.ts
13456
13458
  import { request as request3 } from "node:http";
13457
- function longPostJson(url, body, headers = {}, signal) {
13459
+ function longPostJson(url, body, headers = {}, signal, acknowledgment) {
13458
13460
  const data = Buffer.from(JSON.stringify(body));
13459
13461
  return new Promise((resolve13, reject) => {
13460
13462
  const req = request3(url, { method: "POST", headers: { ...headers, "Content-Length": String(data.byteLength) } }, (res) => {
13463
+ if (acknowledgment && res.statusCode === 200 && res.headers[CC_JOB_HEADER] === acknowledgment.jobId) acknowledgment.onAccepted();
13461
13464
  const chunks = [];
13462
13465
  res.on("data", (chunk) => chunks.push(chunk));
13463
- res.on("error", reject);
13466
+ res.on("error", (err) => {
13467
+ cleanup();
13468
+ reject(err);
13469
+ });
13464
13470
  res.on("end", () => {
13465
13471
  cleanup();
13466
13472
  const text2 = Buffer.concat(chunks).toString("utf8");
@@ -13492,9 +13498,11 @@ function longPostJson(url, body, headers = {}, signal) {
13492
13498
  req.end(data);
13493
13499
  });
13494
13500
  }
13501
+ var CC_JOB_HEADER;
13495
13502
  var init_long_http = __esm({
13496
13503
  "src/cc-driver/long-http.ts"() {
13497
13504
  "use strict";
13505
+ CC_JOB_HEADER = "x-engine7-cc-job-id";
13498
13506
  }
13499
13507
  });
13500
13508
 
@@ -13548,19 +13556,31 @@ async function findDesktopTargets(workDir, sessionId) {
13548
13556
  }
13549
13557
  return targets;
13550
13558
  }
13551
- async function askDesktop(target, prompt, source, signal) {
13559
+ async function askDesktop(target, prompt, source, signal, acknowledgment) {
13560
+ const endpoint = acknowledgment ? "submit" : "ask";
13552
13561
  const { status, json: result } = await longPostJson(
13553
- `http://127.0.0.1:${target.port}/ask`,
13554
- { prompt, source, sessionId: target.sessionId, instance: target.instance, workDir: target.workDir },
13562
+ `http://127.0.0.1:${target.port}/${endpoint}`,
13563
+ { prompt, source, jobId: acknowledgment?.jobId, sessionId: target.sessionId, instance: target.instance, workDir: target.workDir },
13555
13564
  { authorization: `Bearer ${target.token}` },
13556
- signal
13565
+ signal,
13566
+ acknowledgment
13557
13567
  );
13558
- if (status !== 200) throw failure(result?.error || `Desktop CC HTTP ${status}`, status);
13568
+ if (status !== 200 || result?.error) throw failure(result?.error || `Desktop CC HTTP ${status}`, status);
13559
13569
  if (result.sessionId !== target.sessionId || typeof result.text !== "string" || typeof result.isError !== "boolean") {
13560
13570
  throw failure("Desktop CC returned an invalid result");
13561
13571
  }
13562
13572
  return result;
13563
13573
  }
13574
+ async function stopDesktopJob(target, jobId) {
13575
+ const { status, json } = await longPostJson(
13576
+ `http://127.0.0.1:${target.port}/stop`,
13577
+ { jobId, sessionId: target.sessionId, instance: target.instance, workDir: target.workDir },
13578
+ { authorization: `Bearer ${target.token}` },
13579
+ AbortSignal.timeout(5e3)
13580
+ );
13581
+ if (status !== 200) throw failure(json?.error || `Desktop CC HTTP ${status}`, status);
13582
+ return json?.stopped === true;
13583
+ }
13564
13584
  var registryDir, canonical2, failure, alive;
13565
13585
  var init_desktop = __esm({
13566
13586
  "src/cc-driver/desktop.ts"() {
@@ -14008,6 +14028,7 @@ var init_driver = __esm({
14008
14028
  revision = 0;
14009
14029
  idleWaiters = [];
14010
14030
  abort = null;
14031
+ activeJob;
14011
14032
  /** 当前流式 chunk 的 steer 口(仅用户消息路径开;外部 ask/桌面路径为 null) */
14012
14033
  feeder = null;
14013
14034
  sessionId = null;
@@ -14052,13 +14073,17 @@ var init_driver = __esm({
14052
14073
  void this.drain();
14053
14074
  }
14054
14075
  /** External callers use the same FIFO; they never answer a pending permission card. */
14055
- ask(prompt, source, expectedSessionId, signal) {
14056
- if (this.closed) return Promise.reject(requestError("CC binding is stopping", 503));
14057
- if (!prompt.trim()) return Promise.reject(requestError("prompt is required", 400));
14058
- if (signal?.aborted) return Promise.reject(requestError("CC request cancelled", 499));
14059
- if (this.sessionId !== expectedSessionId) return Promise.reject(requestError("CC session changed; select the current binding again"));
14060
- if (this.queue.length >= MAX_QUEUE) return Promise.reject(requestError("CC queue is full", 429));
14061
- const job = { prompt: prompt.trim(), source, expectedSessionId, signal };
14076
+ async ask(prompt, source, expectedSessionId, signal) {
14077
+ return this.submit(prompt, source, expectedSessionId, signal);
14078
+ }
14079
+ submit(prompt, source, expectedSessionId, signal, id3, onSession) {
14080
+ if (this.closed) throw requestError("CC binding is stopping", 503);
14081
+ if (!prompt.trim()) throw requestError("prompt is required", 400);
14082
+ if (signal?.aborted) throw requestError("CC request cancelled", 499);
14083
+ if (this.sessionId !== expectedSessionId) throw requestError("CC session changed; select the current binding again");
14084
+ if (id3 && (this.activeJob?.id === id3 || this.queue.some((job2) => job2.id === id3))) throw requestError("CC job already exists");
14085
+ if (this.queue.length >= MAX_QUEUE) throw requestError("CC queue is full", 429);
14086
+ const job = { id: id3, prompt: prompt.trim(), source, expectedSessionId, expectedRevision: id3 ? this.revision : void 0, signal, onSession };
14062
14087
  const cancel = () => {
14063
14088
  const index = this.queue.indexOf(job);
14064
14089
  if (index >= 0) {
@@ -14073,7 +14098,16 @@ var init_driver = __esm({
14073
14098
  signal?.addEventListener("abort", cancel, { once: true });
14074
14099
  void this.drain();
14075
14100
  });
14076
- return pending.finally(() => signal?.removeEventListener("abort", cancel));
14101
+ return signal ? pending.finally(() => signal.removeEventListener("abort", cancel)) : pending;
14102
+ }
14103
+ stopJob(id3) {
14104
+ const index = this.queue.findIndex((job) => job.id === id3);
14105
+ if (index >= 0) {
14106
+ this.queue.splice(index, 1)[0].reject?.(requestError("CC request cancelled (stop)", 499));
14107
+ return true;
14108
+ }
14109
+ if (this.activeJob?.id === id3) return this.activeJob.stop?.() ?? false;
14110
+ return false;
14077
14111
  }
14078
14112
  /** Reload/stop must not leave the old hub executing queued work. */
14079
14113
  shutdown() {
@@ -14099,6 +14133,9 @@ var init_driver = __esm({
14099
14133
  stop() {
14100
14134
  this.abort?.abort();
14101
14135
  }
14136
+ get queued() {
14137
+ return this.queue.length;
14138
+ }
14102
14139
  get busy() {
14103
14140
  return this.draining;
14104
14141
  }
@@ -14112,15 +14149,17 @@ var init_driver = __esm({
14112
14149
  await this.predecessor;
14113
14150
  while (!this.closed && this.queue.length > 0) {
14114
14151
  const job = this.queue.shift();
14152
+ this.activeJob = job;
14115
14153
  try {
14116
14154
  if (job.signal?.aborted) throw requestError("CC request cancelled", 499);
14117
- if (job.expectedSessionId !== void 0 && job.expectedSessionId !== this.sessionId) {
14155
+ const changed = job.expectedRevision !== void 0 ? job.expectedRevision !== this.revision : job.expectedSessionId !== void 0 && job.expectedSessionId !== this.sessionId;
14156
+ if (changed) {
14118
14157
  throw requestError("CC session changed while this request was queued");
14119
14158
  }
14120
14159
  if (job.source) {
14121
14160
  const prompt = `[cc_ask from ${job.source.replace(/[\r\n]/g, " ").slice(0, 160)}]
14122
14161
  ${job.prompt}`;
14123
- const result = await this.runTurn(prompt, job.signal, true);
14162
+ const result = await this.runTurn(prompt, job.signal, true, job);
14124
14163
  job.resolve?.(result);
14125
14164
  } else {
14126
14165
  await this.runStreaming(job);
@@ -14129,6 +14168,8 @@ ${job.prompt}`;
14129
14168
  job.reject?.(err);
14130
14169
  console.error(`[cc-driver] turn \u5931\u8D25 key=${this.key}: ${err?.stack || err}`);
14131
14170
  await this.sendText(`[cc-driver] \u8FD9\u6B21\u4EFB\u52A1\u5931\u8D25\uFF1A${err?.message || String(err)}`);
14171
+ } finally {
14172
+ this.activeJob = void 0;
14132
14173
  }
14133
14174
  }
14134
14175
  } finally {
@@ -14136,12 +14177,24 @@ ${job.prompt}`;
14136
14177
  for (const resolve13 of this.idleWaiters.splice(0)) resolve13();
14137
14178
  }
14138
14179
  }
14139
- async runTurn(prompt, signal, external = false) {
14180
+ async runTurn(prompt, signal, external = false, job) {
14140
14181
  const ac = new AbortController();
14141
14182
  this.abort = ac;
14183
+ if (job?.id) job.stop = () => {
14184
+ ac.abort();
14185
+ return true;
14186
+ };
14142
14187
  const resumedFrom = this.sessionId;
14143
14188
  const revision = this.revision;
14144
14189
  let turnSessionId = resumedFrom;
14190
+ const observeSession = (id3) => {
14191
+ try {
14192
+ job?.onSession?.(id3);
14193
+ } catch (error) {
14194
+ console.error("[cc-driver] task session update failed:", error.message);
14195
+ }
14196
+ };
14197
+ observeSession(turnSessionId);
14145
14198
  const cancel = () => ac.abort();
14146
14199
  signal?.addEventListener("abort", cancel, { once: true });
14147
14200
  if (signal?.aborted) ac.abort();
@@ -14165,13 +14218,31 @@ ${job.prompt}`;
14165
14218
  const acc = this.makeStreamAccumulator();
14166
14219
  try {
14167
14220
  const desktops = resumedFrom ? await findDesktopTargets(this.workDir, resumedFrom) : [];
14221
+ ac.signal.throwIfAborted();
14168
14222
  if (desktops.length > 1) throw new Error("Multiple desktop writers claim this CC session; close the duplicate");
14169
14223
  if (desktops[0]) {
14170
- const result2 = await askDesktop(desktops[0], prompt, this.key, ac.signal);
14224
+ const desktop = desktops[0];
14225
+ let result2;
14226
+ if (job?.id) {
14227
+ const jobId = job.id;
14228
+ let acknowledge;
14229
+ const accepted = new Promise((resolve13) => {
14230
+ acknowledge = resolve13;
14231
+ });
14232
+ job.stop = async () => await accepted && stopDesktopJob(desktop, jobId);
14233
+ try {
14234
+ result2 = await askDesktop(desktop, prompt, this.key, ac.signal, { jobId, onAccepted: () => acknowledge(true) });
14235
+ } finally {
14236
+ acknowledge(false);
14237
+ }
14238
+ } else {
14239
+ result2 = await askDesktop(desktop, prompt, this.key, ac.signal);
14240
+ }
14171
14241
  finalText = result2.text;
14172
14242
  isError = result2.isError;
14173
14243
  gotResult = true;
14174
14244
  turnSessionId = result2.sessionId;
14245
+ observeSession(turnSessionId);
14175
14246
  if (this.revision === revision) this.sessionId = result2.sessionId;
14176
14247
  } else {
14177
14248
  if (resumedFrom && nativeSessionOwners(resumedFrom).length) {
@@ -14184,6 +14255,7 @@ ${job.prompt}`;
14184
14255
  const mb = total ? `\u7EA6 ${Math.round(total / 1024 / 1024)}M` : "\u7EA6 350M";
14185
14256
  void this.sendText(`[cc-driver] \u9996\u6B21\u4F7F\u7528\uFF1A\u6B63\u5728\u4E0B\u8F7D ${label}\uFF08${mb}\uFF0C\u53EA\u6B64\u4E00\u6B21\uFF09\uFF0C\u5B8C\u6210\u540E\u81EA\u52A8\u7EE7\u7EED\u2026`);
14186
14257
  });
14258
+ ac.signal.throwIfAborted();
14187
14259
  const stream = query({
14188
14260
  prompt,
14189
14261
  options: {
@@ -14226,6 +14298,7 @@ ${job.prompt}`;
14226
14298
  const r = msg2;
14227
14299
  if (r.session_id) {
14228
14300
  turnSessionId = r.session_id;
14301
+ observeSession(turnSessionId);
14229
14302
  if (this.revision === revision) this.sessionId = r.session_id;
14230
14303
  }
14231
14304
  isError = r.is_error === true;
@@ -14236,6 +14309,7 @@ ${job.prompt}`;
14236
14309
  const sid = msg2.session_id;
14237
14310
  if (sid) {
14238
14311
  turnSessionId = sid;
14312
+ observeSession(turnSessionId);
14239
14313
  if (this.revision === revision) this.sessionId = sid;
14240
14314
  }
14241
14315
  } else {
@@ -14245,6 +14319,7 @@ ${job.prompt}`;
14245
14319
  }
14246
14320
  if (turnSessionId && gotResult && this.revision === revision) this.map.switchTo(this.key, turnSessionId, this.workDir);
14247
14321
  } finally {
14322
+ if (job) job.stop = void 0;
14248
14323
  this.abort = null;
14249
14324
  signal?.removeEventListener("abort", cancel);
14250
14325
  }
@@ -14888,6 +14963,11 @@ function getProxyDispatcher(value) {
14888
14963
  const cached2 = dispatchers.get(raw);
14889
14964
  if (cached2) return cached2;
14890
14965
  const url = proxyAddress(raw);
14966
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
14967
+ throw new Error(
14968
+ `\u4E0D\u652F\u6301\u7684\u4EE3\u7406\u534F\u8BAE ${url.protocol}\uFF08\u4EC5 http/https \u53EF\u76F4\u63A5\u4F7F\u7528\uFF1Bsocks5 \u7B49\u8BF7\u5148\u8F6C\u6210 http \u4EE3\u7406\uFF0C\u5982 gost/privoxy\uFF09\uFF1A${raw}`
14969
+ );
14970
+ }
14891
14971
  const key4 = localProxyKey(url);
14892
14972
  const dispatcher = key4 ? new AdaptiveProxyDispatcher(url.href, key4) : new ProxyAgent({ uri: url.href });
14893
14973
  dispatchers.set(raw, dispatcher);
@@ -16997,7 +17077,8 @@ CREATE INDEX IF NOT EXISTS idx_proactive_decisions_created ON proactive_decision
16997
17077
  this.noteCascade(id3);
16998
17078
  this.db.prepare(`UPDATE actions SET basis_state='dirty',action_version=action_version+1,
16999
17079
  cancel_requested=CASE WHEN status='executing' THEN 1 ELSE cancel_requested END,
17000
- status=CASE WHEN status='queued' THEN 'cancelled' ELSE status END
17080
+ status=CASE WHEN status='queued' THEN 'cancelled' ELSE status END,
17081
+ cancel_reason=COALESCE(cancel_reason, CASE WHEN status='queued' THEN 'graph_basis_changed' END)
17001
17082
  WHERE intent_id=? AND status IN ('queued','executing')`).run(id3);
17002
17083
  this.db.prepare("UPDATE intent_runs SET state='stale',reason_code='graph_basis_changed',finished_at=? WHERE intent_id=? AND state='running'").run(Date.now(), id3);
17003
17084
  pending.push(...this.dependencies.children(scope, [{ kind: "node", id: id3 }]));
@@ -17082,11 +17163,12 @@ CREATE INDEX IF NOT EXISTS idx_proactive_decisions_created ON proactive_decision
17082
17163
  a.note ?? null
17083
17164
  );
17084
17165
  }
17085
- /** status='queued' AND scheduled_time<=now,按时间升序 */
17086
- dueActions(now2, limit2 = 20) {
17166
+ /** status='queued' AND scheduled_time<=now,按时间升序。excludeIds:sweep 翻页绕开已看过的(守卫跳过的) */
17167
+ dueActions(now2, limit2 = 20, excludeIds = []) {
17087
17168
  const rows = this.db.prepare(
17088
- `SELECT * FROM actions WHERE status='queued' AND scheduled_time <= ? ORDER BY scheduled_time ASC LIMIT ?`
17089
- ).all(now2, limit2);
17169
+ `SELECT * FROM actions WHERE status='queued' AND scheduled_time <= ?
17170
+ AND id NOT IN (SELECT value FROM json_each(?)) ORDER BY scheduled_time ASC LIMIT ?`
17171
+ ).all(now2, JSON.stringify(excludeIds), limit2);
17090
17172
  return rows.map(rowToAction);
17091
17173
  }
17092
17174
  /** queued 状态 action 的 intent_id 集合(去重) */
@@ -22293,6 +22375,10 @@ var FeishuAdapter = class _FeishuAdapter {
22293
22375
  }
22294
22376
  }
22295
22377
  }
22378
+ /** 公开上传入口(1130 gmail 连接卡片等业务卡用):委托 _uploadImage。 */
22379
+ async uploadImage(buffer, filename) {
22380
+ return this._uploadImage(buffer, filename);
22381
+ }
22296
22382
  async _uploadImage(buffer, filename) {
22297
22383
  const token = await this._getTenantToken();
22298
22384
  const resp = await fetch("https://open.feishu.cn/open-apis/im/v1/images", {
@@ -29938,7 +30024,9 @@ var SEARCH_ALIASES = /* @__PURE__ */ new Map([
29938
30024
  ["gmail", ["\u90AE\u7BB1", "\u90AE\u4EF6"]],
29939
30025
  ["device_data", ["\u8BBE\u5907\u8D44\u6599", "\u65E5\u5386", "\u63D0\u9192\u4E8B\u9879", "\u901A\u8BAF\u5F55", "\u8054\u7CFB\u4EBA", "\u5907\u5FD8\u5F55", "\u7167\u7247", "\u5065\u5EB7"]],
29940
30026
  ["cc_ask", ["\u5C0FC", "\u684C\u9762CC", "Claude Code"]],
29941
- ["cc_progress", ["\u5C0FC", "\u684C\u9762CC", "Claude Code"]]
30027
+ ["cc_progress", ["\u5C0FC", "\u684C\u9762CC", "Claude Code"]],
30028
+ ["cc_new", ["\u5C0FC", "\u684C\u9762CC", "Claude Code", "\u65B0\u5EFA CC \u4F1A\u8BDD"]],
30029
+ ["cc_stop", ["\u5C0FC", "\u684C\u9762CC", "Claude Code", "\u505C\u6B62 CC \u4EFB\u52A1"]]
29942
30030
  ]);
29943
30031
  function toolSearchAliases(name) {
29944
30032
  return SEARCH_ALIASES.get(name) ?? [];
@@ -2098,6 +2098,18 @@ var init_registry = __esm({
2098
2098
  effect: "hot",
2099
2099
  internal: true
2100
2100
  },
2101
+ // 1130 Gmail 冷启动:连接即触发 + 每日巡查,新装机默认开。model 为空走 topics.clean.model → extract → mem7 链(免费档自动退回主力模型)
2102
+ { path: "gmailColdstart.enabled", type: "boolean", group: "feature", label: "Gmail \u51B7\u542F\u52A8\uFF08\u8FDE\u63A5\u540E\u81EA\u52A8\u8BFB\u5386\u53F2\u8BA4\u4EBA\uFF09", effect: "hot", internal: true },
2103
+ { path: "gmailColdstart.model", type: "string", group: "model", label: "Gmail \u51B7\u542F\u52A8\u63D0\u70BC\u6A21\u578B\uFF08\u7A7A=\u6CBF\u7528\u8BB0\u5FC6\u63D0\u53D6\u6A21\u578B\uFF0C\u514D\u8D39\u6863\u81EA\u52A8\u9000\u56DE\u4E3B\u529B\uFF09", effect: "hot", internal: true },
2104
+ {
2105
+ path: "gmailColdstart.patrolHour",
2106
+ type: "number",
2107
+ group: "feature",
2108
+ label: "Gmail \u6BCF\u65E5\u5DE1\u67E5\u6574\u70B9\uFF080-23\uFF09",
2109
+ effect: "hot",
2110
+ internal: true,
2111
+ validate: (value) => Number.isInteger(value) && Number(value) >= 0 && Number(value) <= 23 ? null : "\u5DE1\u67E5\u6574\u70B9\u987B\u4E3A 0-23"
2112
+ },
2101
2113
  {
2102
2114
  path: "mem7.turnReadBudgetMs",
2103
2115
  type: "number",