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.
- package/dist/bg-worker.mjs +122 -31
- package/dist/cc-desktop.mjs +48 -6
- package/dist/cli.mjs +3289 -2549
- package/dist/engine-startup.mjs +5939 -3315
- package/dist/main.mjs +5947 -3322
- package/dist/recall-worker.mjs +48 -13
- package/dist/topics-worker.mjs +62 -26
- package/dist/travel-gateway.mjs +113 -25
- package/dist/travel-host.mjs +881 -425
- package/dist/travel-oss-bundle-stream.mjs +12 -0
- package/dist/travel-pairing.mjs +113 -25
- package/dist/travel-sync-worker.mjs +12 -0
- package/dist/web-console.mjs +93 -98
- package/package.json +2 -2
package/dist/bg-worker.mjs
CHANGED
|
@@ -1315,7 +1315,9 @@ var tokenizer_exports = {};
|
|
|
1315
1315
|
__export(tokenizer_exports, {
|
|
1316
1316
|
DEFAULT_STOPWORDS: () => DEFAULT_STOPWORDS,
|
|
1317
1317
|
MIN_TOKEN_LENGTH: () => MIN_TOKEN_LENGTH,
|
|
1318
|
+
cjkBigrams: () => cjkBigrams,
|
|
1318
1319
|
tokenize: () => tokenize,
|
|
1320
|
+
tokenizeCjk: () => tokenizeCjk,
|
|
1319
1321
|
tokenizeToField: () => tokenizeToField
|
|
1320
1322
|
});
|
|
1321
1323
|
import { Jieba } from "@node-rs/jieba";
|
|
@@ -1338,6 +1340,16 @@ function tokenize(text2) {
|
|
|
1338
1340
|
function tokenizeToField(text2) {
|
|
1339
1341
|
return tokenize(text2).join(" ");
|
|
1340
1342
|
}
|
|
1343
|
+
function cjkBigrams(text2) {
|
|
1344
|
+
const out = [];
|
|
1345
|
+
for (const seg of String(text2 ?? "").match(/[\u4e00-\u9fff]{2,}/g) ?? []) {
|
|
1346
|
+
for (let i = 0; i + 1 < seg.length; i++) out.push(seg.slice(i, i + 2));
|
|
1347
|
+
}
|
|
1348
|
+
return out;
|
|
1349
|
+
}
|
|
1350
|
+
function tokenizeCjk(text2) {
|
|
1351
|
+
return [...tokenize(text2), ...cjkBigrams(text2)];
|
|
1352
|
+
}
|
|
1341
1353
|
var DEFAULT_STOPWORDS, MIN_TOKEN_LENGTH, jieba;
|
|
1342
1354
|
var init_tokenizer = __esm({
|
|
1343
1355
|
"src/mem7/core/tokenizer.ts"() {
|
|
@@ -10265,18 +10277,31 @@ function forgotten(b, path22) {
|
|
|
10265
10277
|
}
|
|
10266
10278
|
function openIndex(b, version) {
|
|
10267
10279
|
if (!b.stateDir || !b.topicsDir) return null;
|
|
10268
|
-
const root = topicsHistoryRoot(b);
|
|
10280
|
+
const root = topicsHistoryRoot(b), expectedRoot = resolve7(b.topicsDir);
|
|
10281
|
+
let selected = "", actualRoot;
|
|
10269
10282
|
try {
|
|
10270
|
-
|
|
10283
|
+
selected = version ?? readJson(join13(root, "current.json")).version;
|
|
10271
10284
|
if (!/^[a-f0-9-]{36}$/.test(selected)) throw new Error("INVALID_HISTORY_VERSION");
|
|
10272
10285
|
const db2 = new DatabaseSync7(unlinked(join13(root, selected, "history.db")), { readOnly: true });
|
|
10273
10286
|
const meta = db2.prepare("SELECT value FROM metadata WHERE key=?").get("binding");
|
|
10274
|
-
if (meta?.value !== canonical({ scope: topicsScope(b), root:
|
|
10287
|
+
if (meta?.value !== canonical({ scope: topicsScope(b), root: expectedRoot })) {
|
|
10288
|
+
try {
|
|
10289
|
+
actualRoot = String(JSON.parse(meta?.value ?? "{}").root ?? "") || void 0;
|
|
10290
|
+
} catch {
|
|
10291
|
+
actualRoot = meta?.value;
|
|
10292
|
+
}
|
|
10275
10293
|
db2.close();
|
|
10276
10294
|
throw new Error("HISTORY_SCOPE_MISMATCH");
|
|
10277
10295
|
}
|
|
10278
10296
|
return db2;
|
|
10279
|
-
} catch {
|
|
10297
|
+
} catch (error) {
|
|
10298
|
+
if (error instanceof Error && error.message === "HISTORY_SCOPE_MISMATCH") {
|
|
10299
|
+
const signature2 = `${expectedRoot}|${actualRoot ?? ""}`;
|
|
10300
|
+
if (!scopeMismatchWarned.has(signature2)) {
|
|
10301
|
+
scopeMismatchWarned.add(signature2);
|
|
10302
|
+
console.warn(`[topics-history] HISTORY_SCOPE_MISMATCH\uFF1A\u7D22\u5F15\u7ED1\u5B9A\u7684 topics \u6839\u76EE\u5F55\u4E0E\u5F53\u524D\u4E0D\u7B26\uFF0C\u5386\u53F2\u68C0\u7D22\u672C\u6B21\u4E3A\u7A7A\u4E14\u4E0D\u4F1A\u81EA\u6108\uFF08\u9700\u91CD\u5EFA\uFF09\u3002expected root=${expectedRoot} actual root=${actualRoot ?? "(unreadable)"} version=${selected} index=${join13(root, selected, "history.db")}`);
|
|
10303
|
+
}
|
|
10304
|
+
}
|
|
10280
10305
|
return null;
|
|
10281
10306
|
}
|
|
10282
10307
|
}
|
|
@@ -10470,15 +10495,15 @@ async function publishTopicsIndex(bundle, cleaned, b) {
|
|
|
10470
10495
|
const md = /(?:^|-)\d{2}-\d{2}$/.test(d.value) ? d.value.slice(-5) : void 0;
|
|
10471
10496
|
return [d.value, d.year?.toString() ?? "", ...md ? [md, `${Number(md.slice(0, 2))}\u6708${Number(md.slice(-2))}\u65E5`] : []];
|
|
10472
10497
|
});
|
|
10473
|
-
const terms =
|
|
10498
|
+
const terms = tokenizeCjk(`${paragraph}
|
|
10474
10499
|
${aliases.join(" ")}`);
|
|
10475
10500
|
documentTerms.push(...terms);
|
|
10476
|
-
search.run(id, [...
|
|
10501
|
+
search.run(id, [...tokenizeCjk(item.originalMetadata.title), ...terms].join(" "));
|
|
10477
10502
|
}
|
|
10478
10503
|
start = end;
|
|
10479
10504
|
}
|
|
10480
10505
|
}
|
|
10481
|
-
if (documentTerms.length) documentInsert.run(item.path, item.originalHash, [...
|
|
10506
|
+
if (documentTerms.length) documentInsert.run(item.path, item.originalHash, [...tokenizeCjk(item.originalMetadata.title), ...documentTerms].join(" "));
|
|
10482
10507
|
}
|
|
10483
10508
|
db2.exec("COMMIT");
|
|
10484
10509
|
if (db2.prepare("PRAGMA integrity_check").get().integrity_check !== "ok") throw new Error("HISTORY_INDEX_INVALID");
|
|
@@ -10499,7 +10524,7 @@ async function searchTopicsHistory(b, query, options = {}) {
|
|
|
10499
10524
|
const before = mem7StartDate(b);
|
|
10500
10525
|
const year = topicQueryYear(query, options);
|
|
10501
10526
|
const normalized = query.replace(/(?<!\d)(?:19|20)\d{2}\s*年?(?!\d)/g, "").replace(/去年|今年/g, "");
|
|
10502
|
-
const terms = [...new Set(
|
|
10527
|
+
const terms = [...new Set(tokenizeCjk(normalized))].slice(0, 24);
|
|
10503
10528
|
if (!terms.length && year !== void 0) terms.push(String(year));
|
|
10504
10529
|
if (!terms.length) return [];
|
|
10505
10530
|
const match = terms.map((term) => `"${term.replace(/"/g, '""')}"`).join(" OR ");
|
|
@@ -10510,7 +10535,7 @@ async function searchTopicsHistory(b, query, options = {}) {
|
|
|
10510
10535
|
for (const row of rows) {
|
|
10511
10536
|
const ref = JSON.parse(row.ref);
|
|
10512
10537
|
const words = terms.filter((term) => !/^\d+[年月日]?$/.test(term));
|
|
10513
|
-
if (words.length && !words.some((term) =>
|
|
10538
|
+
if (words.length && !words.some((term) => tokenizeCjk(row.body + " " + row.title).includes(term))) continue;
|
|
10514
10539
|
try {
|
|
10515
10540
|
const hit = getTopicHistory(b, ref, before);
|
|
10516
10541
|
if (!topicMatchesYear(hit.dates, year)) continue;
|
|
@@ -10553,7 +10578,7 @@ async function searchTopicsHistory(b, query, options = {}) {
|
|
|
10553
10578
|
db2.close();
|
|
10554
10579
|
}
|
|
10555
10580
|
}
|
|
10556
|
-
var topicsScope, key3, rootKey, refPath, refId, fallbackChecks, credential2;
|
|
10581
|
+
var topicsScope, key3, rootKey, refPath, refId, scopeMismatchWarned, fallbackChecks, credential2;
|
|
10557
10582
|
var init_topics_history = __esm({
|
|
10558
10583
|
"src/memory/topics-history/index.ts"() {
|
|
10559
10584
|
"use strict";
|
|
@@ -10568,6 +10593,7 @@ var init_topics_history = __esm({
|
|
|
10568
10593
|
rootKey = (b) => digest3(resolve7(b.topicsDir));
|
|
10569
10594
|
refPath = (ref) => `topics-history://${Buffer.from(canonical(ref)).toString("base64url")}`;
|
|
10570
10595
|
refId = (ref) => digest3(canonical(ref));
|
|
10596
|
+
scopeMismatchWarned = /* @__PURE__ */ new Set();
|
|
10571
10597
|
fallbackChecks = /* @__PURE__ */ new Map();
|
|
10572
10598
|
credential2 = /(?:api[_-]?key|password|secret|access[_-]?token)["']?\s*[:=]\s*["']?(?!YOUR_|PLACEHOLDER|\*|\[REDACTED\]|env:|\{\{)[\w/+.-]{10,}|-----BEGIN (?:RSA |OPENSSH |EC )?PRIVATE KEY-----|\bsk-[A-Za-z0-9_-]{20,}/i;
|
|
10573
10599
|
}
|
|
@@ -10611,6 +10637,8 @@ function attachmentToMessage(attachment) {
|
|
|
10611
10637
|
${attachment.notifications.join("\n\n")}`
|
|
10612
10638
|
)
|
|
10613
10639
|
};
|
|
10640
|
+
case "coldstart_hint":
|
|
10641
|
+
return { role: "user", content: wrapInSystemReminder(attachment.text) };
|
|
10614
10642
|
case "teammate_messages": {
|
|
10615
10643
|
const lines = attachment.messages.map(
|
|
10616
10644
|
(m) => m.summary ? `[From: ${m.from}] ${m.summary}
|
|
@@ -10807,6 +10835,10 @@ function parseAttachmentFromJsonl(raw) {
|
|
|
10807
10835
|
timestamp: raw.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
10808
10836
|
};
|
|
10809
10837
|
}
|
|
10838
|
+
case "coldstart_hint": {
|
|
10839
|
+
if (typeof attachment.text !== "string" || !attachment.text.trim()) return null;
|
|
10840
|
+
return { type: "attachment", attachment: { type: "coldstart_hint", text: attachment.text }, uuid: raw.uuid || randomUUID7(), timestamp: raw.timestamp || (/* @__PURE__ */ new Date()).toISOString() };
|
|
10841
|
+
}
|
|
10810
10842
|
case "mcp_instructions_delta":
|
|
10811
10843
|
case "task_notification":
|
|
10812
10844
|
case "teammate_messages": {
|
|
@@ -20899,7 +20931,8 @@ CREATE INDEX IF NOT EXISTS idx_proactive_decisions_created ON proactive_decision
|
|
|
20899
20931
|
this.noteCascade(id);
|
|
20900
20932
|
this.db.prepare(`UPDATE actions SET basis_state='dirty',action_version=action_version+1,
|
|
20901
20933
|
cancel_requested=CASE WHEN status='executing' THEN 1 ELSE cancel_requested END,
|
|
20902
|
-
status=CASE WHEN status='queued' THEN 'cancelled' ELSE status END
|
|
20934
|
+
status=CASE WHEN status='queued' THEN 'cancelled' ELSE status END,
|
|
20935
|
+
cancel_reason=COALESCE(cancel_reason, CASE WHEN status='queued' THEN 'graph_basis_changed' END)
|
|
20903
20936
|
WHERE intent_id=? AND status IN ('queued','executing')`).run(id);
|
|
20904
20937
|
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(), id);
|
|
20905
20938
|
pending2.push(...this.dependencies.children(scope, [{ kind: "node", id }]));
|
|
@@ -20984,11 +21017,12 @@ CREATE INDEX IF NOT EXISTS idx_proactive_decisions_created ON proactive_decision
|
|
|
20984
21017
|
a.note ?? null
|
|
20985
21018
|
);
|
|
20986
21019
|
}
|
|
20987
|
-
/** status='queued' AND scheduled_time<=now
|
|
20988
|
-
dueActions(now2, limit = 20) {
|
|
21020
|
+
/** status='queued' AND scheduled_time<=now,按时间升序。excludeIds:sweep 翻页绕开已看过的(守卫跳过的) */
|
|
21021
|
+
dueActions(now2, limit = 20, excludeIds = []) {
|
|
20989
21022
|
const rows = this.db.prepare(
|
|
20990
|
-
`SELECT * FROM actions WHERE status='queued' AND scheduled_time <= ?
|
|
20991
|
-
|
|
21023
|
+
`SELECT * FROM actions WHERE status='queued' AND scheduled_time <= ?
|
|
21024
|
+
AND id NOT IN (SELECT value FROM json_each(?)) ORDER BY scheduled_time ASC LIMIT ?`
|
|
21025
|
+
).all(now2, JSON.stringify(excludeIds), limit);
|
|
20992
21026
|
return rows.map(rowToAction);
|
|
20993
21027
|
}
|
|
20994
21028
|
/** queued 状态 action 的 intent_id 集合(去重) */
|
|
@@ -24695,6 +24729,10 @@ function isSameCommitment(a, b) {
|
|
|
24695
24729
|
if (y.length >= 4 && x.includes(y)) return true;
|
|
24696
24730
|
return false;
|
|
24697
24731
|
}
|
|
24732
|
+
function guardVerdict(value) {
|
|
24733
|
+
if (typeof value === "boolean") return { ok: value, reason: value ? "" : "GUARD_REJECTED" };
|
|
24734
|
+
return { ok: value.ok, reason: value.reason ?? (value.ok ? "" : "GUARD_REJECTED") };
|
|
24735
|
+
}
|
|
24698
24736
|
function actionPayload(a, now2, recentEvidence) {
|
|
24699
24737
|
let suggestedTask = null;
|
|
24700
24738
|
let scheduledLocal = null;
|
|
@@ -24740,7 +24778,7 @@ function actionPayload(a, now2, recentEvidence) {
|
|
|
24740
24778
|
_received_at: now2.toISOString()
|
|
24741
24779
|
};
|
|
24742
24780
|
}
|
|
24743
|
-
var BACKLOG_ALERT_RUNS, STALE_HINT_HOURS, DEFAULT_PROMPT, Sweep;
|
|
24781
|
+
var BACKLOG_ALERT_RUNS, STALE_HINT_HOURS, DEFAULT_PROMPT, TRANSIENT_GUARD_REASONS, DUE_PAGE_SIZE, DUE_MAX_PAGES, transientGuardLogged, Sweep;
|
|
24744
24782
|
var init_sweep = __esm({
|
|
24745
24783
|
"src/memory/proactive/sweep.ts"() {
|
|
24746
24784
|
"use strict";
|
|
@@ -24764,6 +24802,10 @@ var init_sweep = __esm({
|
|
|
24764
24802
|
\u62FF \`generated_at_local\` \u8DDF \`_received_at\` \u5BF9\u4E00\u4E0B\uFF1B\u518D\u8DDF calendar/goal \u91CC\u5DF2\u6709\u7684\u5BF9\u4E00\u904D\u3002
|
|
24765
24803
|
6. **urgency \u662F\u53C2\u8003**\uFF08urgent=\u51E0\u5C0F\u65F6/high=24h/medium=48h/low=\u4E00\u5468\uFF09\uFF0C\u6309\u5B9E\u9645\u60C5\u51B5\u5224\u65AD
|
|
24766
24804
|
7. \u51B3\u5B9A\u544A\u8BC9 TA \u65F6\u7528\u4F60\u81EA\u5DF1\u7684\u8BED\u6C14\u2014\u2014\u8FD9\u662F\u4F60\u7684\u4E3B\u52A8\u5173\u6000\uFF0C\u4E0D\u662F\u7CFB\u7EDF\u901A\u77E5`;
|
|
24805
|
+
TRANSIENT_GUARD_REASONS = /* @__PURE__ */ new Set(["MEMORY_GUARD_UNAVAILABLE", "ACTION_DELIVERY_UNKNOWN", "CALENDAR_DELIVERY_UNKNOWN", "MEMORY_SCHEMA_UNSUPPORTED", "EXECUTION_CONTEXT_INVALID"]);
|
|
24806
|
+
DUE_PAGE_SIZE = 20;
|
|
24807
|
+
DUE_MAX_PAGES = 5;
|
|
24808
|
+
transientGuardLogged = /* @__PURE__ */ new Set();
|
|
24767
24809
|
Sweep = class {
|
|
24768
24810
|
constructor(deps, intervalMs = 3e5) {
|
|
24769
24811
|
this.deps = deps;
|
|
@@ -24819,9 +24861,40 @@ var init_sweep = __esm({
|
|
|
24819
24861
|
console.warn(`[proactive] backlog alert failed: ${err.message}`);
|
|
24820
24862
|
}
|
|
24821
24863
|
}
|
|
24822
|
-
|
|
24823
|
-
|
|
24824
|
-
|
|
24864
|
+
const nowIso2 = now2.toISOString();
|
|
24865
|
+
const gatedItems = [];
|
|
24866
|
+
const gateOff = (a, reason) => {
|
|
24867
|
+
gatedItems.push({ id: a.id, title: a.title, reason, version: a.actionVersion });
|
|
24868
|
+
return false;
|
|
24869
|
+
};
|
|
24870
|
+
const seen = /* @__PURE__ */ new Set();
|
|
24871
|
+
let due = [];
|
|
24872
|
+
for (let page = 0; page < DUE_MAX_PAGES; page++) {
|
|
24873
|
+
const batch = this.deps.persist.dueActions(nowIso2, DUE_PAGE_SIZE, [...seen]);
|
|
24874
|
+
for (const action of batch) {
|
|
24875
|
+
seen.add(action.id);
|
|
24876
|
+
if (!this.deps.checkAction) {
|
|
24877
|
+
due.push(action);
|
|
24878
|
+
continue;
|
|
24879
|
+
}
|
|
24880
|
+
const verdict = guardVerdict(this.deps.checkAction(action));
|
|
24881
|
+
if (verdict.ok) {
|
|
24882
|
+
due.push(action);
|
|
24883
|
+
continue;
|
|
24884
|
+
}
|
|
24885
|
+
if (TRANSIENT_GUARD_REASONS.has(verdict.reason)) {
|
|
24886
|
+
const signature2 = `${action.id}:${verdict.reason}`;
|
|
24887
|
+
if (!transientGuardLogged.has(signature2)) {
|
|
24888
|
+
transientGuardLogged.add(signature2);
|
|
24889
|
+
console.log(`[proactive] \u6295\u9012\u524D\u5B88\u536B\u6682\u6001\u62D2\u7EDD\uFF0C\u672C\u8F6E\u8DF3\u8FC7\uFF1A\u300C${action.title.slice(0, 24)}\u300D${verdict.reason}`);
|
|
24890
|
+
}
|
|
24891
|
+
continue;
|
|
24892
|
+
}
|
|
24893
|
+
gateOff(action, `\u6295\u9012\u524D\u5B88\u536B\uFF1A${verdict.reason}`);
|
|
24894
|
+
}
|
|
24895
|
+
if (batch.length < DUE_PAGE_SIZE || due.length >= DUE_PAGE_SIZE) break;
|
|
24896
|
+
}
|
|
24897
|
+
if (due.length === 0 && gatedItems.length === 0) return 0;
|
|
24825
24898
|
const opportunityGroups = [];
|
|
24826
24899
|
for (const action of due.filter((item) => item.scopeId && item.provenance?.decisionType === "opportunity")) {
|
|
24827
24900
|
const matches2 = opportunityGroups.filter((group) => group.some((item) => item.scopeId === action.scopeId && isSameCommitment(item.title, action.title)));
|
|
@@ -24857,11 +24930,6 @@ var init_sweep = __esm({
|
|
|
24857
24930
|
}
|
|
24858
24931
|
console.log(`[proactive] R2: ${resolvedActions.length} due action(s) cancelled (intent resolved)`);
|
|
24859
24932
|
}
|
|
24860
|
-
const gatedItems = [];
|
|
24861
|
-
const gateOff = (a, reason) => {
|
|
24862
|
-
gatedItems.push({ id: a.id, title: a.title, reason, version: a.actionVersion });
|
|
24863
|
-
return false;
|
|
24864
|
-
};
|
|
24865
24933
|
const coveredTitles = this.deps.coveredTitles ?? [];
|
|
24866
24934
|
const coveredEvents = this.deps.coveredEvents ?? [];
|
|
24867
24935
|
if (coveredTitles.length > 0 || coveredEvents.length > 0) {
|
|
@@ -25259,6 +25327,19 @@ function findForesightFiles(everosRoot) {
|
|
|
25259
25327
|
walk(everosRoot, 0);
|
|
25260
25328
|
return files;
|
|
25261
25329
|
}
|
|
25330
|
+
function opportunityScheduledTime(now2, concrete) {
|
|
25331
|
+
const nowMs = now2.getTime();
|
|
25332
|
+
let closesAt = Number.POSITIVE_INFINITY;
|
|
25333
|
+
for (const ref of concrete) {
|
|
25334
|
+
if (ref.parentKind !== "scope") continue;
|
|
25335
|
+
const match = ref.parentId.match(/^valid-window:(-?\d+):(-?\d+)$/);
|
|
25336
|
+
if (!match) continue;
|
|
25337
|
+
closesAt = Math.min(closesAt, Number(match[2]));
|
|
25338
|
+
}
|
|
25339
|
+
if (!Number.isFinite(closesAt)) return new Date(nowMs + OPPORTUNITY_DELAY_MS);
|
|
25340
|
+
if (closesAt <= nowMs) return null;
|
|
25341
|
+
return new Date(Math.max(nowMs, Math.min(nowMs + OPPORTUNITY_DELAY_MS, closesAt - OPPORTUNITY_WINDOW_MARGIN_MS)));
|
|
25342
|
+
}
|
|
25262
25343
|
async function runOpportunityScan(deps) {
|
|
25263
25344
|
const { persist, now: now2 } = deps;
|
|
25264
25345
|
const captured = deps.memory && deps.memory.store.readTransaction(() => {
|
|
@@ -25503,7 +25584,7 @@ ${captured ? captured.actionEvidence.get(n.id) ?? `\u4EC5\u80CC\u666F\uFF0C\u4E0
|
|
|
25503
25584
|
intentId: id,
|
|
25504
25585
|
title: opportunity.title,
|
|
25505
25586
|
description: `[\u4E3B\u52A8\u5EFA\u8BAE\uFF0C\u5C5E\u4E8E\u63A8\u65AD] ${opportunity.description}`,
|
|
25506
|
-
scheduledTime: new Date(now2.getTime() +
|
|
25587
|
+
scheduledTime: (opportunityScheduledTime(now2, captured.concrete) ?? new Date(now2.getTime() + OPPORTUNITY_DELAY_MS)).toISOString(),
|
|
25507
25588
|
urgency: "low",
|
|
25508
25589
|
durationMinutes: 10,
|
|
25509
25590
|
calendarId: null,
|
|
@@ -25560,7 +25641,7 @@ ${captured ? captured.actionEvidence.get(n.id) ?? `\u4EC5\u80CC\u666F\uFF0C\u4E0
|
|
|
25560
25641
|
}
|
|
25561
25642
|
return enqueued;
|
|
25562
25643
|
}
|
|
25563
|
-
var OPPORTUNITY_SCAN_INTERVAL_MS, PROFILE_RE, foresightCache, FORESIGHT_CACHE_TTL_MS, FORESIGHT_TEXT_MAX, FS_MATCH_STOP;
|
|
25644
|
+
var OPPORTUNITY_SCAN_INTERVAL_MS, PROFILE_RE, foresightCache, FORESIGHT_CACHE_TTL_MS, FORESIGHT_TEXT_MAX, FS_MATCH_STOP, OPPORTUNITY_DELAY_MS, OPPORTUNITY_WINDOW_MARGIN_MS;
|
|
25564
25645
|
var init_opportunity = __esm({
|
|
25565
25646
|
"src/memory/proactive/opportunity.ts"() {
|
|
25566
25647
|
"use strict";
|
|
@@ -25590,6 +25671,8 @@ var init_opportunity = __esm({
|
|
|
25590
25671
|
FORESIGHT_CACHE_TTL_MS = 30 * 6e4;
|
|
25591
25672
|
FORESIGHT_TEXT_MAX = 150;
|
|
25592
25673
|
FS_MATCH_STOP = /* @__PURE__ */ new Set(["\u65F6\u5019", "\u4E1C\u897F", "\u73B0\u5728", "\u4ECA\u5929", "\u660E\u5929", "\u4EE5\u540E", "\u6700\u8FD1", "\u60C5\u51B5", "\u95EE\u9898", "\u4E8B\u60C5", "\u7EE7\u7EED", "\u5F00\u59CB", "\u51C6\u5907", "\u8FDB\u884C", "\u8003\u8651", "\u5B89\u6392", "\u76F8\u5173", "\u5982\u4E0B", "\u4EE5\u53CA", "\u7136\u540E", "\u6240\u4EE5", "\u4F46\u662F", "\u8FD9\u4E2A", "\u90A3\u4E2A", "\u4E00\u4E2A", "\u4EC0\u4E48", "\u600E\u4E48", "\u54B1\u4EEC", "\u4ED6\u4EEC", "\u81EA\u5DF1", "\u53EF\u4EE5", "\u6CA1\u6709", "\u5C31\u662F", "\u8FD8\u662F", "\u5DF2\u7ECF", "\u5982\u679C", "\u56E0\u4E3A", "\u8FD9\u6837", "\u90A3\u6837", "\u4E00\u4E0B", "\u7684\u8BDD", "\u4E0A\u53BB", "\u4E0B\u6765", "\u51FA\u6765", "\u77E5\u9053", "\u89C9\u5F97", "\u5E94\u8BE5", "\u53EF\u80FD"]);
|
|
25674
|
+
OPPORTUNITY_DELAY_MS = 30 * 6e4;
|
|
25675
|
+
OPPORTUNITY_WINDOW_MARGIN_MS = 10 * 6e4;
|
|
25593
25676
|
}
|
|
25594
25677
|
});
|
|
25595
25678
|
|
|
@@ -26744,6 +26827,11 @@ function getProxyDispatcher(value) {
|
|
|
26744
26827
|
const cached = dispatchers.get(raw);
|
|
26745
26828
|
if (cached) return cached;
|
|
26746
26829
|
const url = proxyAddress(raw);
|
|
26830
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
26831
|
+
throw new Error(
|
|
26832
|
+
`\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}`
|
|
26833
|
+
);
|
|
26834
|
+
}
|
|
26747
26835
|
const key5 = localProxyKey(url);
|
|
26748
26836
|
const dispatcher = key5 ? new AdaptiveProxyDispatcher(url.href, key5) : new ProxyAgent({ uri: url.href });
|
|
26749
26837
|
dispatchers.set(raw, dispatcher);
|
|
@@ -31582,8 +31670,8 @@ async function warmReadStore(stateDir2) {
|
|
|
31582
31670
|
const t0 = Date.now();
|
|
31583
31671
|
try {
|
|
31584
31672
|
const store = getReadStore(stateDir2);
|
|
31585
|
-
const { tokenize:
|
|
31586
|
-
|
|
31673
|
+
const { tokenize: tokenize3 } = await Promise.resolve().then(() => (init_tokenizer(), tokenizer_exports));
|
|
31674
|
+
tokenize3("");
|
|
31587
31675
|
const vs = store.vectorStore();
|
|
31588
31676
|
for (const kind of ["episode", "atomic_fact", "foresight", "agent_case", "agent_skill"]) {
|
|
31589
31677
|
try {
|
|
@@ -33935,11 +34023,12 @@ ${String(input.tool_output ?? "")}`
|
|
|
33935
34023
|
const pluginCalDb = this.calDb;
|
|
33936
34024
|
this.sweep = new Sweep({
|
|
33937
34025
|
persist: this.persist,
|
|
33938
|
-
|
|
34026
|
+
// 1201(#445):回整个判定(带 reason)——sweep 据此当场 cancelled 带原因,不再静默滤掉
|
|
34027
|
+
checkAction: (action) => !action.scopeId ? true : checkMemoryExecution(String(liveConfig.get("stateDir") ?? ""), workspace2, {
|
|
33939
34028
|
scopeId: action.scopeId,
|
|
33940
34029
|
basisRefs: action.basisRefs ?? [],
|
|
33941
34030
|
actionVersions: { [action.id]: action.actionVersion }
|
|
33942
|
-
})
|
|
34031
|
+
}),
|
|
33943
34032
|
promptFile: join40(workspace2, "prompts", "proactive.md"),
|
|
33944
34033
|
// 三个都走 getter **每轮现读** —— 热加载规则(config 改了立刻生效)+
|
|
33945
34034
|
// calendar 会变,都不能在 start() 时快照。
|
|
@@ -39689,7 +39778,9 @@ var init_tool_loading = __esm({
|
|
|
39689
39778
|
["gmail", ["\u90AE\u7BB1", "\u90AE\u4EF6"]],
|
|
39690
39779
|
["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"]],
|
|
39691
39780
|
["cc_ask", ["\u5C0FC", "\u684C\u9762CC", "Claude Code"]],
|
|
39692
|
-
["cc_progress", ["\u5C0FC", "\u684C\u9762CC", "Claude Code"]]
|
|
39781
|
+
["cc_progress", ["\u5C0FC", "\u684C\u9762CC", "Claude Code"]],
|
|
39782
|
+
["cc_new", ["\u5C0FC", "\u684C\u9762CC", "Claude Code", "\u65B0\u5EFA CC \u4F1A\u8BDD"]],
|
|
39783
|
+
["cc_stop", ["\u5C0FC", "\u684C\u9762CC", "Claude Code", "\u505C\u6B62 CC \u4EFB\u52A1"]]
|
|
39693
39784
|
]);
|
|
39694
39785
|
}
|
|
39695
39786
|
});
|
package/dist/cc-desktop.mjs
CHANGED
|
@@ -5,9 +5,12 @@ var __esm = (fn, res) => function __init() {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// src/cc-driver/long-http.ts
|
|
8
|
+
var CC_JOB_HEADER, isCcJobId;
|
|
8
9
|
var init_long_http = __esm({
|
|
9
10
|
"src/cc-driver/long-http.ts"() {
|
|
10
11
|
"use strict";
|
|
12
|
+
CC_JOB_HEADER = "x-engine7-cc-job-id";
|
|
13
|
+
isCcJobId = (value) => typeof value === "string" && /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/.test(value);
|
|
11
14
|
}
|
|
12
15
|
});
|
|
13
16
|
|
|
@@ -184,6 +187,7 @@ ${terminalText(job.prompt)}`;
|
|
|
184
187
|
options.writeInput(`\x1B[200~${prompt}\x1B[201~`);
|
|
185
188
|
enterTimer = setTimeout(() => {
|
|
186
189
|
if (closed || active !== job) return;
|
|
190
|
+
job.entered = true;
|
|
187
191
|
try {
|
|
188
192
|
options.writeInput("\r");
|
|
189
193
|
} catch (e) {
|
|
@@ -205,6 +209,30 @@ ${terminalText(job.prompt)}`;
|
|
|
205
209
|
unlockInput();
|
|
206
210
|
}
|
|
207
211
|
};
|
|
212
|
+
const stopJob = (id) => {
|
|
213
|
+
const index = queue.findIndex((job) => job.id === id);
|
|
214
|
+
const reason = failure("Desktop CC request cancelled (stop)", 499);
|
|
215
|
+
if (index >= 0) {
|
|
216
|
+
queue.splice(index, 1)[0].reject(reason);
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
if (active?.id !== id) return false;
|
|
220
|
+
if (active.entered && !active.submitted) {
|
|
221
|
+
active.stopRequested = true;
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
const submitted = active.submitted;
|
|
225
|
+
options.writeInput(submitted ? "\x1B" : "");
|
|
226
|
+
clearTimeout(enterTimer);
|
|
227
|
+
clearTimeout(ackTimer);
|
|
228
|
+
active.reject(reason);
|
|
229
|
+
active = void 0;
|
|
230
|
+
suspended = submitted;
|
|
231
|
+
endpoint.busy = submitted;
|
|
232
|
+
if (pasting) unlockInput();
|
|
233
|
+
pump();
|
|
234
|
+
return true;
|
|
235
|
+
};
|
|
208
236
|
const onHook = (input) => {
|
|
209
237
|
if (!input || typeof input.hook_event_name !== "string" || typeof input.session_id !== "string" || typeof input.cwd !== "string" || canonical(input.cwd) !== endpoint.workDir) throw failure("Invalid desktop hook identity", 400);
|
|
210
238
|
const event = input.hook_event_name;
|
|
@@ -228,7 +256,8 @@ ${terminalText(job.prompt)}`;
|
|
|
228
256
|
if (active && typeof input.prompt === "string" && input.prompt.startsWith(`[engine7_cc_ask:${active.id}] `)) {
|
|
229
257
|
active.submitted = true;
|
|
230
258
|
clearTimeout(ackTimer);
|
|
231
|
-
|
|
259
|
+
if (active.stopRequested) stopJob(active.id);
|
|
260
|
+
else unlockInput();
|
|
232
261
|
} else if (active) {
|
|
233
262
|
active.reject(failure("Desktop user changed the active turn"));
|
|
234
263
|
active = void 0;
|
|
@@ -264,7 +293,7 @@ ${terminalText(job.prompt)}`;
|
|
|
264
293
|
const server = createServer(async (req, res) => {
|
|
265
294
|
const reply = (status, value) => {
|
|
266
295
|
if (res.destroyed || res.writableEnded) return;
|
|
267
|
-
res.writeHead(status, { "content-type": "application/json" });
|
|
296
|
+
if (!res.headersSent) res.writeHead(status, { "content-type": "application/json" });
|
|
268
297
|
res.end(JSON.stringify(value));
|
|
269
298
|
};
|
|
270
299
|
const auth = String(req.headers.authorization || "");
|
|
@@ -278,13 +307,14 @@ ${terminalText(job.prompt)}`;
|
|
|
278
307
|
reply(200, { ...status, suspended, draft, queued: queue.length });
|
|
279
308
|
return;
|
|
280
309
|
}
|
|
281
|
-
if (req.method !== "POST" || !["/ask", "/hook", "/title"].includes(req.url || "")) {
|
|
310
|
+
if (req.method !== "POST" || !["/ask", "/submit", "/stop", "/hook", "/title"].includes(req.url || "")) {
|
|
282
311
|
reply(404, { error: "Not found" });
|
|
283
312
|
return;
|
|
284
313
|
}
|
|
314
|
+
const managed = req.url === "/submit";
|
|
285
315
|
let job;
|
|
286
316
|
const disconnect = () => {
|
|
287
|
-
if (!job || res.writableEnded) return;
|
|
317
|
+
if (managed || !job || res.writableEnded) return;
|
|
288
318
|
const index = queue.indexOf(job);
|
|
289
319
|
if (index >= 0) queue.splice(index, 1);
|
|
290
320
|
job.reject(failure("Caller disconnected; any submitted desktop turn continues", 499));
|
|
@@ -298,6 +328,11 @@ ${terminalText(job.prompt)}`;
|
|
|
298
328
|
return;
|
|
299
329
|
}
|
|
300
330
|
if (input?.instance !== endpoint.instance || input.sessionId !== endpoint.sessionId || typeof input.workDir !== "string" || canonical(input.workDir) !== endpoint.workDir) throw failure("Desktop identity/session changed");
|
|
331
|
+
if (req.url === "/stop") {
|
|
332
|
+
if (!isCcJobId(input.jobId)) throw failure("Invalid CC jobId", 400);
|
|
333
|
+
reply(200, { stopped: stopJob(input.jobId) });
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
301
336
|
if (req.url === "/title") {
|
|
302
337
|
const title2 = normalizeDesktopTitle(input.title);
|
|
303
338
|
const previous = endpoint.title;
|
|
@@ -316,11 +351,18 @@ ${terminalText(job.prompt)}`;
|
|
|
316
351
|
throw failure("prompt and source required", 400);
|
|
317
352
|
}
|
|
318
353
|
if (queue.length >= 32) throw failure("Desktop queue full", 429);
|
|
354
|
+
if (managed && !isCcJobId(input.jobId)) throw failure("Invalid CC jobId", 400);
|
|
355
|
+
const id = managed ? input.jobId : randomUUID();
|
|
356
|
+
if (active?.id === id || queue.some((item) => item.id === id)) throw failure("CC job already exists");
|
|
319
357
|
const result = new Promise((resolve, reject) => {
|
|
320
|
-
job = { id
|
|
358
|
+
job = { id, prompt: input.prompt, source: input.source, sessionId: input.sessionId, submitted: false, resolve, reject };
|
|
321
359
|
queue.push(job);
|
|
322
360
|
});
|
|
323
|
-
if (res.destroyed)
|
|
361
|
+
if (managed && !res.destroyed) {
|
|
362
|
+
res.writeHead(200, { "content-type": "application/json", [CC_JOB_HEADER]: id });
|
|
363
|
+
res.flushHeaders();
|
|
364
|
+
}
|
|
365
|
+
if (res.destroyed && !managed) disconnect();
|
|
324
366
|
else pump();
|
|
325
367
|
reply(200, await result);
|
|
326
368
|
} catch (error) {
|