engine7 7.1.148 → 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 +263 -67
- package/dist/cc-desktop.mjs +48 -6
- package/dist/cli.mjs +4890 -3323
- package/dist/engine-startup.mjs +7296 -4302
- package/dist/main.mjs +7309 -4306
- package/dist/recall-worker.mjs +183 -42
- package/dist/topics-worker.mjs +185 -54
- package/dist/travel-gateway.mjs +378 -125
- package/dist/travel-host.mjs +944 -472
- package/dist/travel-node.mjs +2 -3
- package/dist/travel-oss-bundle-stream.mjs +13 -1
- package/dist/travel-pairing.mjs +384 -131
- package/dist/travel-sync-worker.mjs +235 -114
- package/dist/web-console.mjs +390 -147
- package/package.json +2 -2
package/dist/travel-host.mjs
CHANGED
|
@@ -5334,7 +5334,7 @@ var init_recovery_deletion = __esm({
|
|
|
5334
5334
|
add(table, row) {
|
|
5335
5335
|
this.affected = void 0;
|
|
5336
5336
|
const { owners, parents } = this.links(table, row);
|
|
5337
|
-
for (const parent of parents) for (const
|
|
5337
|
+
for (const parent of parents) for (const owner2 of owners) this.edge(parent, owner2);
|
|
5338
5338
|
if (table === "memory_artifact_publications") {
|
|
5339
5339
|
const medium = text(row, "medium"), path37 = text(row, "path"), physicalId = text(row, "physical_id"), kind = text(row, "kind");
|
|
5340
5340
|
const identity3 = medium === "markdown" && path37 ? "file:mem7/" + path37 : medium === "vector" && physicalId && kind ? "vector:" + kind + "/rows/" + createHash12("sha256").update(physicalId).digest("hex") + ".arrow" : void 0;
|
|
@@ -6023,16 +6023,15 @@ function stripInjectedContext(text2) {
|
|
|
6023
6023
|
function escapeRegExp(s) {
|
|
6024
6024
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6025
6025
|
}
|
|
6026
|
-
var
|
|
6026
|
+
var SYSTEM_REMINDER_BLOCK, INJECT_SECTION_HEADS, KNOWN_INJECTED_TEXT, INJECTED_LINE_PREFIXES, XML_BLOCK;
|
|
6027
6027
|
var init_strip_injected = __esm({
|
|
6028
6028
|
"src/messages/strip-injected.ts"() {
|
|
6029
6029
|
"use strict";
|
|
6030
|
-
SKILL_GATE_HINT_PREFIX = "\u8FD9\u6761\u6D88\u606F\u662F\u5F00\u53D1\u4EFB\u52A1";
|
|
6031
6030
|
SYSTEM_REMINDER_BLOCK = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
6032
6031
|
INJECT_SECTION_HEADS = /^(本轮对话|当前情绪状态|当前模式)/;
|
|
6033
6032
|
KNOWN_INJECTED_TEXT = [
|
|
6034
|
-
|
|
6035
|
-
// skill-gate
|
|
6033
|
+
"\u8FD9\u6761\u6D88\u606F\u662F\u5F00\u53D1\u4EFB\u52A1",
|
|
6034
|
+
// 旧版 skill-gate 提示前缀,兼容未打标签的历史
|
|
6036
6035
|
"\u5F00\u53D1\u4EFB\u52A1\u8DEF\u6807\uFF0C\u6309\u573A\u666F\u5BF9\u53F7\u5165\u5EA7",
|
|
6037
6036
|
// skill-gate hint(0912 老文案,历史 JSONL 兼容)
|
|
6038
6037
|
"\u3010\u5B9A\u65F6\u5FC3\u8DF3\u3011\u8BF7 read HEARTBEAT.md"
|
|
@@ -8113,6 +8112,8 @@ function attachmentToMessage(attachment) {
|
|
|
8113
8112
|
${attachment.notifications.join("\n\n")}`
|
|
8114
8113
|
)
|
|
8115
8114
|
};
|
|
8115
|
+
case "coldstart_hint":
|
|
8116
|
+
return { role: "user", content: wrapInSystemReminder(attachment.text) };
|
|
8116
8117
|
case "teammate_messages": {
|
|
8117
8118
|
const lines = attachment.messages.map(
|
|
8118
8119
|
(m) => m.summary ? `[From: ${m.from}] ${m.summary}
|
|
@@ -10762,32 +10763,32 @@ CREATE TABLE IF NOT EXISTS cluster_members (
|
|
|
10762
10763
|
return { built: !hasStats, ms: Date.now() - started };
|
|
10763
10764
|
}
|
|
10764
10765
|
async close() {
|
|
10765
|
-
const
|
|
10766
|
+
const errors2 = [];
|
|
10766
10767
|
try {
|
|
10767
10768
|
this.capture?.close();
|
|
10768
10769
|
} catch (error) {
|
|
10769
|
-
|
|
10770
|
+
errors2.push(error);
|
|
10770
10771
|
}
|
|
10771
10772
|
try {
|
|
10772
10773
|
this.db.close();
|
|
10773
10774
|
} catch (error) {
|
|
10774
|
-
|
|
10775
|
+
errors2.push(error);
|
|
10775
10776
|
}
|
|
10776
10777
|
try {
|
|
10777
10778
|
await this.vectors?.close();
|
|
10778
10779
|
} catch (error) {
|
|
10779
|
-
|
|
10780
|
+
errors2.push(error);
|
|
10780
10781
|
} finally {
|
|
10781
10782
|
this.vectors = null;
|
|
10782
10783
|
}
|
|
10783
10784
|
try {
|
|
10784
10785
|
this.releaseRuntimeWriter?.();
|
|
10785
10786
|
} catch (error) {
|
|
10786
|
-
|
|
10787
|
+
errors2.push(error);
|
|
10787
10788
|
} finally {
|
|
10788
10789
|
this.releaseRuntimeWriter = void 0;
|
|
10789
10790
|
}
|
|
10790
|
-
if (
|
|
10791
|
+
if (errors2.length) throw new AggregateError(errors2, "MEM7_CLOSE_FAILED");
|
|
10791
10792
|
}
|
|
10792
10793
|
// ── memcell 账本 ──────────────────────────────────────────
|
|
10793
10794
|
insertMemcell(cell) {
|
|
@@ -12003,11 +12004,11 @@ ${e.outcome}
|
|
|
12003
12004
|
const out = [];
|
|
12004
12005
|
const usersDir = join16(this.root, "users");
|
|
12005
12006
|
if (!existsSync6(usersDir)) return out;
|
|
12006
|
-
for (const
|
|
12007
|
-
if (!
|
|
12008
|
-
if (scope &&
|
|
12009
|
-
if (!scope && this.tombstones.anyForOwner(
|
|
12010
|
-
const dir = join16(usersDir,
|
|
12007
|
+
for (const owner2 of readdirSync2(usersDir, { withFileTypes: true })) {
|
|
12008
|
+
if (!owner2.isDirectory()) continue;
|
|
12009
|
+
if (scope && owner2.name !== scope.ownerId) continue;
|
|
12010
|
+
if (!scope && this.tombstones.anyForOwner(owner2.name)) continue;
|
|
12011
|
+
const dir = join16(usersDir, owner2.name, ".foresights");
|
|
12011
12012
|
if (!existsSync6(dir)) continue;
|
|
12012
12013
|
for (const f of readdirSync2(dir)) {
|
|
12013
12014
|
if (!/^foresight-\d{4}-\d{2}-\d{2}\.md$/.test(f)) continue;
|
|
@@ -12031,7 +12032,7 @@ ${e.outcome}
|
|
|
12031
12032
|
if (!end || !start || !text2) continue;
|
|
12032
12033
|
if (end < today) continue;
|
|
12033
12034
|
out.push({
|
|
12034
|
-
ownerId:
|
|
12035
|
+
ownerId: owner2.name,
|
|
12035
12036
|
...scope ? { entryId, version: this.dependencies.version(scope, "foresight", entryId) } : {},
|
|
12036
12037
|
startDate: start,
|
|
12037
12038
|
endDate: end,
|
|
@@ -13609,10 +13610,10 @@ function projectReadSnapshots(messages, context, options = {}) {
|
|
|
13609
13610
|
const returned = new Set(messages.flatMap((m) => "role" in m && m.role === "tool" && m.tool_call_id ? [m.tool_call_id] : []));
|
|
13610
13611
|
const protectedImage = unobservedImageIndex(messages);
|
|
13611
13612
|
let turnStart = 0;
|
|
13612
|
-
let
|
|
13613
|
+
let finished2 = false;
|
|
13613
13614
|
let unresolved = false;
|
|
13614
13615
|
const finishTurn = (end) => {
|
|
13615
|
-
if ((
|
|
13616
|
+
if ((finished2 || options.includeLastTurn) && !unresolved) completed.fill(1, turnStart, end);
|
|
13616
13617
|
};
|
|
13617
13618
|
for (let i = 0; i < messages.length; i++) {
|
|
13618
13619
|
const message = messages[i];
|
|
@@ -13620,9 +13621,9 @@ function projectReadSnapshots(messages, context, options = {}) {
|
|
|
13620
13621
|
if (message.role === "user") {
|
|
13621
13622
|
finishTurn(i);
|
|
13622
13623
|
turnStart = i;
|
|
13623
|
-
|
|
13624
|
+
finished2 = false;
|
|
13624
13625
|
unresolved = false;
|
|
13625
|
-
} else if (message.role === "assistant" && !message.tool_calls?.length && message.content)
|
|
13626
|
+
} else if (message.role === "assistant" && !message.tool_calls?.length && message.content) finished2 = true;
|
|
13626
13627
|
if (message.tool_calls?.some((call) => !returned.has(call.id))) unresolved = true;
|
|
13627
13628
|
}
|
|
13628
13629
|
finishTurn(messages.length);
|
|
@@ -14812,6 +14813,251 @@ ${filenames.join("\n")}${truncatedNote}`
|
|
|
14812
14813
|
}
|
|
14813
14814
|
});
|
|
14814
14815
|
|
|
14816
|
+
// src/tools/cc-ask-jobs.ts
|
|
14817
|
+
import { randomUUID as randomUUID12 } from "node:crypto";
|
|
14818
|
+
async function runCcAskJob(options) {
|
|
14819
|
+
const { ctx, target, mode, timeoutMs, signal, run, stop } = options;
|
|
14820
|
+
if (signal?.aborted) return { content: "CC \u8BF7\u6C42\u5DF2\u53D6\u6D88\uFF0C\u5C1A\u672A\u6295\u9012\u3002", isError: true };
|
|
14821
|
+
const jobId = randomUUID12();
|
|
14822
|
+
const job = { owner: owner(ctx), target, status: "accepted", stop: () => stop(jobId) };
|
|
14823
|
+
const transport = new AbortController();
|
|
14824
|
+
const timer = setTimeout(() => transport.abort(new Error("\u672A\u6536\u5230 CC \u5165\u961F\u56DE\u6267\uFF0C\u4EFB\u52A1\u53EF\u80FD\u5DF2\u9001\u8FBE\uFF0C\u8BF7\u5148\u67E5\u770B\u76EE\u6807\u4F1A\u8BDD\u3002")), ACCEPT_TIMEOUT_MS);
|
|
14825
|
+
let accept;
|
|
14826
|
+
let rejectAcceptance;
|
|
14827
|
+
const accepted = new Promise((resolve47, reject) => {
|
|
14828
|
+
accept = resolve47;
|
|
14829
|
+
rejectAcceptance = reject;
|
|
14830
|
+
});
|
|
14831
|
+
const onAccepted = () => {
|
|
14832
|
+
clearTimeout(timer);
|
|
14833
|
+
jobs.set(jobId, job);
|
|
14834
|
+
accept();
|
|
14835
|
+
};
|
|
14836
|
+
const result = Promise.resolve().then(() => run({ jobId, onAccepted }, transport.signal)).catch((error) => {
|
|
14837
|
+
rejectAcceptance(error);
|
|
14838
|
+
return { content: `CC \u6295\u9012\u6216\u7ED3\u679C\u8BFB\u53D6\u5931\u8D25\uFF1A${describeError(error)}`, isError: true };
|
|
14839
|
+
}).then((output) => {
|
|
14840
|
+
clearTimeout(timer);
|
|
14841
|
+
if (!jobs.has(jobId)) rejectAcceptance(new Error(output.isError ? output.content : "CC \u672A\u786E\u8BA4\u4EFB\u52A1\u5165\u961F\u3002"));
|
|
14842
|
+
else {
|
|
14843
|
+
job.status = output.isError ? job.status === "stopping" ? "stopped" : "failed" : "completed";
|
|
14844
|
+
job.result = output;
|
|
14845
|
+
job.stop = void 0;
|
|
14846
|
+
finished.add(jobId);
|
|
14847
|
+
if (finished.size > MAX_FINISHED) {
|
|
14848
|
+
const oldest = finished.values().next().value;
|
|
14849
|
+
jobs.delete(oldest);
|
|
14850
|
+
finished.delete(oldest);
|
|
14851
|
+
}
|
|
14852
|
+
}
|
|
14853
|
+
return output;
|
|
14854
|
+
});
|
|
14855
|
+
try {
|
|
14856
|
+
await accepted;
|
|
14857
|
+
} catch (error) {
|
|
14858
|
+
return { content: describeError(error), isError: true };
|
|
14859
|
+
}
|
|
14860
|
+
const receipt2 = (status) => ({
|
|
14861
|
+
content: JSON.stringify({ jobId, status, target: target.key, workDir: target.workDir, sessionId: target.sessionId }),
|
|
14862
|
+
isError: false
|
|
14863
|
+
});
|
|
14864
|
+
if (mode === "async") return receipt2("accepted");
|
|
14865
|
+
const waitSignals = [signal, ctx.yieldSignal].filter((item) => !!item);
|
|
14866
|
+
let endWait;
|
|
14867
|
+
const waiting = new Promise((resolve47) => {
|
|
14868
|
+
endWait = resolve47;
|
|
14869
|
+
});
|
|
14870
|
+
const cancelWait = () => {
|
|
14871
|
+
if (signal?.aborted && signal.reason !== "interrupt") {
|
|
14872
|
+
endWait(requestStop(jobId, job));
|
|
14873
|
+
} else {
|
|
14874
|
+
endWait(receipt2("waiting_yielded"));
|
|
14875
|
+
}
|
|
14876
|
+
};
|
|
14877
|
+
if (waitSignals.some((item) => item.aborted)) cancelWait();
|
|
14878
|
+
else for (const item of waitSignals) item.addEventListener("abort", cancelWait, { once: true });
|
|
14879
|
+
const waitTimer = timeoutMs > 0 ? setTimeout(() => endWait(receipt2("waiting_timed_out")), timeoutMs) : void 0;
|
|
14880
|
+
try {
|
|
14881
|
+
return await Promise.race([result, waiting]);
|
|
14882
|
+
} finally {
|
|
14883
|
+
clearTimeout(waitTimer);
|
|
14884
|
+
for (const item of waitSignals) item.removeEventListener("abort", cancelWait);
|
|
14885
|
+
}
|
|
14886
|
+
}
|
|
14887
|
+
function jobFor(id2, ctx) {
|
|
14888
|
+
const job = typeof id2 === "string" ? jobs.get(id2) : void 0;
|
|
14889
|
+
return job?.owner === owner(ctx) ? job : void 0;
|
|
14890
|
+
}
|
|
14891
|
+
function ccAskJobProgress(id2, ctx, readSession) {
|
|
14892
|
+
const job = jobFor(id2, ctx);
|
|
14893
|
+
if (!job) return { content: "\u5F53\u524D\u4F1A\u8BDD\u6CA1\u6709\u627E\u5230\u8FD9\u4E2A CC \u4EFB\u52A1\u3002", isError: true };
|
|
14894
|
+
const sessionRecent = job.stop ? readSession(job.target) : void 0;
|
|
14895
|
+
return { content: JSON.stringify({
|
|
14896
|
+
jobId: id2,
|
|
14897
|
+
target: job.target.key,
|
|
14898
|
+
workDir: job.target.workDir,
|
|
14899
|
+
sessionId: job.target.sessionId,
|
|
14900
|
+
status: job.status,
|
|
14901
|
+
sessionRecent,
|
|
14902
|
+
result: job.result?.content
|
|
14903
|
+
}) };
|
|
14904
|
+
}
|
|
14905
|
+
async function requestStop(id2, job) {
|
|
14906
|
+
if (!job.stop || job.status === "stopping") return { content: JSON.stringify({ jobId: id2, status: job.status }) };
|
|
14907
|
+
job.status = "stopping";
|
|
14908
|
+
try {
|
|
14909
|
+
if (await job.stop()) return { content: JSON.stringify({ jobId: id2, status: "stop_requested" }), isError: false };
|
|
14910
|
+
if (job.status === "stopping") job.status = "accepted";
|
|
14911
|
+
if (!job.stop) return { content: JSON.stringify({ jobId: id2, status: job.status }) };
|
|
14912
|
+
return { content: `CC \u672A\u786E\u8BA4\u505C\u6B62\u4EFB\u52A1 ${id2}\uFF0C\u53EF\u7528 cc_progress({jobId}) \u67E5\u770B\u3002`, isError: true };
|
|
14913
|
+
} catch (error) {
|
|
14914
|
+
if (job.status === "stopping") job.status = "accepted";
|
|
14915
|
+
return { content: `\u505C\u6B62 CC \u5931\u8D25\uFF1A${describeError(error)}`, isError: true };
|
|
14916
|
+
}
|
|
14917
|
+
}
|
|
14918
|
+
async function stopCcAskJob(id2, ctx) {
|
|
14919
|
+
const job = jobFor(id2, ctx);
|
|
14920
|
+
return job ? requestStop(String(id2), job) : { content: "\u5F53\u524D\u4F1A\u8BDD\u6CA1\u6709\u627E\u5230\u8FD9\u4E2A CC \u4EFB\u52A1\u3002", isError: true };
|
|
14921
|
+
}
|
|
14922
|
+
var jobs, finished, MAX_FINISHED, ACCEPT_TIMEOUT_MS, owner, describeError;
|
|
14923
|
+
var init_cc_ask_jobs = __esm({
|
|
14924
|
+
"src/tools/cc-ask-jobs.ts"() {
|
|
14925
|
+
"use strict";
|
|
14926
|
+
jobs = /* @__PURE__ */ new Map();
|
|
14927
|
+
finished = /* @__PURE__ */ new Set();
|
|
14928
|
+
MAX_FINISHED = 100;
|
|
14929
|
+
ACCEPT_TIMEOUT_MS = 1e4;
|
|
14930
|
+
owner = (ctx) => JSON.stringify([ctx.stateDir || ctx.workspace, ctx.sessionId || ctx.channel]);
|
|
14931
|
+
describeError = (error) => error instanceof Error ? error.message : String(error);
|
|
14932
|
+
}
|
|
14933
|
+
});
|
|
14934
|
+
|
|
14935
|
+
// src/cc-driver/peer-tunnel.ts
|
|
14936
|
+
import { execFile as execFile3, spawn } from "node:child_process";
|
|
14937
|
+
import { promisify as promisify3 } from "node:util";
|
|
14938
|
+
var exec2, validSshHost;
|
|
14939
|
+
var init_peer_tunnel = __esm({
|
|
14940
|
+
"src/cc-driver/peer-tunnel.ts"() {
|
|
14941
|
+
"use strict";
|
|
14942
|
+
exec2 = promisify3(execFile3);
|
|
14943
|
+
validSshHost = (name) => typeof name === "string" && /^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,62}$/.test(name);
|
|
14944
|
+
}
|
|
14945
|
+
});
|
|
14946
|
+
|
|
14947
|
+
// src/tools/cc-peer.ts
|
|
14948
|
+
import { execFile as execFile4 } from "node:child_process";
|
|
14949
|
+
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
14950
|
+
import { setTimeout as delay2 } from "node:timers/promises";
|
|
14951
|
+
function resolvePeer(alias) {
|
|
14952
|
+
const targets = peerConfig()?.targets;
|
|
14953
|
+
if (!validAlias(alias) || !targets || !Object.hasOwn(targets, alias) || !validSshHost(targets[alias])) {
|
|
14954
|
+
throw new Error(`\u8FDC\u7A0B CC \u76EE\u6807\u672A\u914D\u7F6E\uFF1A${alias}`);
|
|
14955
|
+
}
|
|
14956
|
+
return { alias, host: targets[alias] };
|
|
14957
|
+
}
|
|
14958
|
+
function selectCcPeer(target, useDefault = true) {
|
|
14959
|
+
if (typeof target === "string" && target.startsWith("remote:")) return resolvePeer(target.slice(7));
|
|
14960
|
+
const configured = peerConfig()?.default;
|
|
14961
|
+
if (!target && useDefault && configured) return resolvePeer(configured);
|
|
14962
|
+
return void 0;
|
|
14963
|
+
}
|
|
14964
|
+
function parsePeerJob(id2) {
|
|
14965
|
+
if (typeof id2 !== "string" || !id2.startsWith("remote:")) return void 0;
|
|
14966
|
+
const [alias, jobId, extra] = id2.slice(7).split(":");
|
|
14967
|
+
if (extra !== void 0 || !jobId) throw new Error("\u8FDC\u7A0B CC \u4EFB\u52A1 ID \u65E0\u6548");
|
|
14968
|
+
return { peer: resolvePeer(alias), jobId };
|
|
14969
|
+
}
|
|
14970
|
+
function callPeer(peer, ctx, input, signal) {
|
|
14971
|
+
return new Promise((resolve47, reject) => {
|
|
14972
|
+
const child = execFile4("/usr/bin/ssh", [
|
|
14973
|
+
"-T",
|
|
14974
|
+
"-o",
|
|
14975
|
+
"BatchMode=yes",
|
|
14976
|
+
"-o",
|
|
14977
|
+
"ConnectTimeout=4",
|
|
14978
|
+
"-o",
|
|
14979
|
+
"StrictHostKeyChecking=yes",
|
|
14980
|
+
"-o",
|
|
14981
|
+
"ClearAllForwardings=yes",
|
|
14982
|
+
peer.host,
|
|
14983
|
+
"cc-peer"
|
|
14984
|
+
], { timeout: 8e3, maxBuffer: 160 * 1024, signal }, (error, stdout) => {
|
|
14985
|
+
if (error) {
|
|
14986
|
+
reject(new Error("\u8FDC\u7A0B CC \u94FE\u8DEF\u4E0D\u53EF\u7528\u6216\u672A\u786E\u8BA4\u56DE\u6267"));
|
|
14987
|
+
return;
|
|
14988
|
+
}
|
|
14989
|
+
try {
|
|
14990
|
+
const reply = JSON.parse(stdout);
|
|
14991
|
+
if (!reply || typeof reply !== "object") throw new Error("\u8FDC\u7A0B CC \u56DE\u6267\u683C\u5F0F\u65E0\u6548");
|
|
14992
|
+
if (reply.error) throw new Error(reply.error);
|
|
14993
|
+
resolve47(reply);
|
|
14994
|
+
} catch (cause) {
|
|
14995
|
+
reject(cause);
|
|
14996
|
+
}
|
|
14997
|
+
});
|
|
14998
|
+
child.stdin?.on("error", () => {
|
|
14999
|
+
});
|
|
15000
|
+
child.stdin?.end(JSON.stringify({ ...input, conversation: String(ctx.sessionId ?? ctx.channel ?? "default") }));
|
|
15001
|
+
});
|
|
15002
|
+
}
|
|
15003
|
+
async function askRemoteCc(peer, args, ctx, timeoutMs, signal) {
|
|
15004
|
+
const id2 = requestId(args.requestId);
|
|
15005
|
+
let receipt2;
|
|
15006
|
+
try {
|
|
15007
|
+
receipt2 = await callPeer(peer, ctx, { op: "submit", prompt: args.prompt, workDir: args.workDir, requestId: id2 }, signal);
|
|
15008
|
+
} catch (error) {
|
|
15009
|
+
return { content: `${error.message}\u3002\u672C\u6B21 requestId ${id2}\uFF0C\u9700\u8981\u6838\u5B9E\u6216\u91CD\u8BD5\u65F6\u6CBF\u7528\u8BE5 ID\u3002`, isError: true };
|
|
15010
|
+
}
|
|
15011
|
+
if (args.mode === "async" || !receipt2.jobId || !["accepted", "running", "stopping"].includes(receipt2.status ?? "")) return format(peer, receipt2);
|
|
15012
|
+
const deadline = timeoutMs > 0 ? AbortSignal.timeout(Math.min(Math.ceil(timeoutMs), 2147483647)) : void 0;
|
|
15013
|
+
const wait = AbortSignal.any([deadline, signal, ctx.yieldSignal].filter((item) => !!item));
|
|
15014
|
+
try {
|
|
15015
|
+
while (true) {
|
|
15016
|
+
await delay2(2e3, void 0, { signal: wait });
|
|
15017
|
+
const update = await callPeer(peer, ctx, { op: "progress", jobId: receipt2.jobId, includeTranscript: false }, wait);
|
|
15018
|
+
if (update.status === "completed") return { content: update.result || "" };
|
|
15019
|
+
if (!["accepted", "running", "stopping"].includes(update.status ?? "")) return format(peer, update);
|
|
15020
|
+
}
|
|
15021
|
+
} catch {
|
|
15022
|
+
return format(peer, { ...receipt2, status: deadline?.aborted ? "waiting_timed_out" : wait.aborted ? "waiting_yielded" : "waiting_disconnected" });
|
|
15023
|
+
}
|
|
15024
|
+
}
|
|
15025
|
+
async function observeRemoteCc(op, args, ctx, signal) {
|
|
15026
|
+
try {
|
|
15027
|
+
const job = parsePeerJob(args.jobId);
|
|
15028
|
+
if (job) return format(job.peer, await callPeer(job.peer, ctx, { op, jobId: job.jobId }, signal));
|
|
15029
|
+
if (op !== "progress" || args.jobId !== void 0) return void 0;
|
|
15030
|
+
const peer = selectCcPeer(args.target, !args.workDir && args.view !== "sessions");
|
|
15031
|
+
return peer ? format(peer, await callPeer(peer, ctx, { op }, signal)) : void 0;
|
|
15032
|
+
} catch (error) {
|
|
15033
|
+
return asError(error);
|
|
15034
|
+
}
|
|
15035
|
+
}
|
|
15036
|
+
async function newRemoteCc(peer, args, ctx, signal) {
|
|
15037
|
+
const id2 = requestId(args.requestId);
|
|
15038
|
+
try {
|
|
15039
|
+
return format(peer, await callPeer(peer, ctx, { op: "new", requestId: id2, workDir: args.workDir }, signal));
|
|
15040
|
+
} catch (error) {
|
|
15041
|
+
return { content: `${error.message}\u3002\u672C\u6B21 requestId ${id2}\uFF0C\u9700\u8981\u91CD\u8BD5\u65F6\u6CBF\u7528\u8BE5 ID\u3002`, isError: true };
|
|
15042
|
+
}
|
|
15043
|
+
}
|
|
15044
|
+
var validAlias, peerConfig, asError, format, requestId;
|
|
15045
|
+
var init_cc_peer = __esm({
|
|
15046
|
+
"src/tools/cc-peer.ts"() {
|
|
15047
|
+
"use strict";
|
|
15048
|
+
init_live();
|
|
15049
|
+
init_peer_tunnel();
|
|
15050
|
+
validAlias = (s) => /^[a-z0-9_-]{1,32}$/.test(s);
|
|
15051
|
+
peerConfig = () => liveConfig.get("channels.ccDriver.remoteTargets");
|
|
15052
|
+
asError = (error) => ({ content: error.message, isError: true });
|
|
15053
|
+
format = (peer, reply) => ({
|
|
15054
|
+
content: JSON.stringify({ ...reply, target: `remote:${peer.alias}`, ...reply.jobId ? { jobId: `remote:${peer.alias}:${reply.jobId}` } : {} }),
|
|
15055
|
+
isError: ["failed", "rejected", "stopped", "unknown"].includes(reply.status ?? "")
|
|
15056
|
+
});
|
|
15057
|
+
requestId = (arg) => typeof arg === "string" ? arg : `${Date.now()}:${randomUUID13()}`;
|
|
15058
|
+
}
|
|
15059
|
+
});
|
|
15060
|
+
|
|
14815
15061
|
// src/cc-driver/project-sessions.ts
|
|
14816
15062
|
import fs8 from "node:fs";
|
|
14817
15063
|
import os from "node:os";
|
|
@@ -15078,15 +15324,63 @@ var init_project_sessions = __esm({
|
|
|
15078
15324
|
}
|
|
15079
15325
|
});
|
|
15080
15326
|
|
|
15327
|
+
// src/cc-driver/progress-transcript.ts
|
|
15328
|
+
function extractBlocks(content) {
|
|
15329
|
+
if (typeof content === "string") return [{ type: "text", text: content }];
|
|
15330
|
+
if (Array.isArray(content)) return content;
|
|
15331
|
+
return [];
|
|
15332
|
+
}
|
|
15333
|
+
function snippet(text2, max = 220) {
|
|
15334
|
+
const t = text2.replace(/\s+/g, " ").trim();
|
|
15335
|
+
return t.length > max ? t.slice(0, max) + "\u2026" : t;
|
|
15336
|
+
}
|
|
15337
|
+
function summarizeTranscript(file2) {
|
|
15338
|
+
const lines = tailSessionLines(file2, 65536);
|
|
15339
|
+
const recent = [];
|
|
15340
|
+
let lastTs = "";
|
|
15341
|
+
for (let i = lines.length - 1; i >= 0 && recent.length < 8; i--) {
|
|
15342
|
+
let entry;
|
|
15343
|
+
try {
|
|
15344
|
+
entry = JSON.parse(lines[i]);
|
|
15345
|
+
} catch {
|
|
15346
|
+
continue;
|
|
15347
|
+
}
|
|
15348
|
+
if (entry.type !== "user" && entry.type !== "assistant") continue;
|
|
15349
|
+
if (!lastTs && entry.timestamp) lastTs = entry.timestamp;
|
|
15350
|
+
const blocks = extractBlocks(entry.message?.content);
|
|
15351
|
+
for (const b of blocks) {
|
|
15352
|
+
if (entry.type === "user" && b.type === "text" && b.text && !b.text.includes("tool_result")) {
|
|
15353
|
+
recent.push(`\u{1F464} ${snippet(b.text)}`);
|
|
15354
|
+
} else if (entry.type === "assistant" && b.type === "text" && b.text) {
|
|
15355
|
+
recent.push(`\u{1F916} ${snippet(b.text)}`);
|
|
15356
|
+
} else if (entry.type === "assistant" && b.type === "tool_use" && b.name) {
|
|
15357
|
+
recent.push(`\u{1F527} ${b.name}`);
|
|
15358
|
+
}
|
|
15359
|
+
}
|
|
15360
|
+
}
|
|
15361
|
+
recent.reverse();
|
|
15362
|
+
return { recent, lastTs };
|
|
15363
|
+
}
|
|
15364
|
+
var init_progress_transcript = __esm({
|
|
15365
|
+
"src/cc-driver/progress-transcript.ts"() {
|
|
15366
|
+
"use strict";
|
|
15367
|
+
init_project_sessions();
|
|
15368
|
+
}
|
|
15369
|
+
});
|
|
15370
|
+
|
|
15081
15371
|
// src/cc-driver/long-http.ts
|
|
15082
15372
|
import { request } from "node:http";
|
|
15083
|
-
function longPostJson(url, body, headers = {}, signal) {
|
|
15373
|
+
function longPostJson(url, body, headers = {}, signal, acknowledgment) {
|
|
15084
15374
|
const data = Buffer.from(JSON.stringify(body));
|
|
15085
15375
|
return new Promise((resolve47, reject) => {
|
|
15086
15376
|
const req = request(url, { method: "POST", headers: { ...headers, "Content-Length": String(data.byteLength) } }, (res) => {
|
|
15377
|
+
if (acknowledgment && res.statusCode === 200 && res.headers[CC_JOB_HEADER] === acknowledgment.jobId) acknowledgment.onAccepted();
|
|
15087
15378
|
const chunks = [];
|
|
15088
15379
|
res.on("data", (chunk) => chunks.push(chunk));
|
|
15089
|
-
res.on("error",
|
|
15380
|
+
res.on("error", (err) => {
|
|
15381
|
+
cleanup();
|
|
15382
|
+
reject(err);
|
|
15383
|
+
});
|
|
15090
15384
|
res.on("end", () => {
|
|
15091
15385
|
cleanup();
|
|
15092
15386
|
const text2 = Buffer.concat(chunks).toString("utf8");
|
|
@@ -15118,9 +15412,11 @@ function longPostJson(url, body, headers = {}, signal) {
|
|
|
15118
15412
|
req.end(data);
|
|
15119
15413
|
});
|
|
15120
15414
|
}
|
|
15415
|
+
var CC_JOB_HEADER;
|
|
15121
15416
|
var init_long_http = __esm({
|
|
15122
15417
|
"src/cc-driver/long-http.ts"() {
|
|
15123
15418
|
"use strict";
|
|
15419
|
+
CC_JOB_HEADER = "x-engine7-cc-job-id";
|
|
15124
15420
|
}
|
|
15125
15421
|
});
|
|
15126
15422
|
|
|
@@ -15174,19 +15470,31 @@ async function findDesktopTargets(workDir, sessionId) {
|
|
|
15174
15470
|
}
|
|
15175
15471
|
return targets;
|
|
15176
15472
|
}
|
|
15177
|
-
async function askDesktop(target, prompt, source, signal) {
|
|
15473
|
+
async function askDesktop(target, prompt, source, signal, acknowledgment) {
|
|
15474
|
+
const endpoint2 = acknowledgment ? "submit" : "ask";
|
|
15178
15475
|
const { status, json: result } = await longPostJson(
|
|
15179
|
-
`http://127.0.0.1:${target.port}
|
|
15180
|
-
{ prompt, source, sessionId: target.sessionId, instance: target.instance, workDir: target.workDir },
|
|
15476
|
+
`http://127.0.0.1:${target.port}/${endpoint2}`,
|
|
15477
|
+
{ prompt, source, jobId: acknowledgment?.jobId, sessionId: target.sessionId, instance: target.instance, workDir: target.workDir },
|
|
15181
15478
|
{ authorization: `Bearer ${target.token}` },
|
|
15182
|
-
signal
|
|
15479
|
+
signal,
|
|
15480
|
+
acknowledgment
|
|
15183
15481
|
);
|
|
15184
|
-
if (status !== 200) throw failure(result?.error || `Desktop CC HTTP ${status}`, status);
|
|
15482
|
+
if (status !== 200 || result?.error) throw failure(result?.error || `Desktop CC HTTP ${status}`, status);
|
|
15185
15483
|
if (result.sessionId !== target.sessionId || typeof result.text !== "string" || typeof result.isError !== "boolean") {
|
|
15186
15484
|
throw failure("Desktop CC returned an invalid result");
|
|
15187
15485
|
}
|
|
15188
15486
|
return result;
|
|
15189
15487
|
}
|
|
15488
|
+
async function stopDesktopJob(target, jobId) {
|
|
15489
|
+
const { status, json } = await longPostJson(
|
|
15490
|
+
`http://127.0.0.1:${target.port}/stop`,
|
|
15491
|
+
{ jobId, sessionId: target.sessionId, instance: target.instance, workDir: target.workDir },
|
|
15492
|
+
{ authorization: `Bearer ${target.token}` },
|
|
15493
|
+
AbortSignal.timeout(5e3)
|
|
15494
|
+
);
|
|
15495
|
+
if (status !== 200) throw failure(json?.error || `Desktop CC HTTP ${status}`, status);
|
|
15496
|
+
return json?.stopped === true;
|
|
15497
|
+
}
|
|
15190
15498
|
var registryDir, canonical3, failure, alive;
|
|
15191
15499
|
var init_desktop = __esm({
|
|
15192
15500
|
"src/cc-driver/desktop.ts"() {
|
|
@@ -15287,8 +15595,8 @@ var init_session_activity = __esm({
|
|
|
15287
15595
|
import fs10 from "node:fs";
|
|
15288
15596
|
import os3 from "node:os";
|
|
15289
15597
|
import path12 from "node:path";
|
|
15290
|
-
import { execFile as
|
|
15291
|
-
import { promisify as
|
|
15598
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
15599
|
+
import { promisify as promisify4 } from "node:util";
|
|
15292
15600
|
async function listOpenCcSessions(workDir) {
|
|
15293
15601
|
const configDir = process.env.CLAUDE_CONFIG_DIR || path12.join(os3.homedir(), ".claude");
|
|
15294
15602
|
const dir = path12.join(configDir, "sessions");
|
|
@@ -15358,7 +15666,7 @@ var init_open_sessions = __esm({
|
|
|
15358
15666
|
init_desktop();
|
|
15359
15667
|
init_project_sessions();
|
|
15360
15668
|
init_session_activity();
|
|
15361
|
-
execFileAsync =
|
|
15669
|
+
execFileAsync = promisify4(execFile5);
|
|
15362
15670
|
uuid = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i;
|
|
15363
15671
|
canonical4 = (dir) => {
|
|
15364
15672
|
try {
|
|
@@ -16928,6 +17236,7 @@ var init_driver = __esm({
|
|
|
16928
17236
|
revision = 0;
|
|
16929
17237
|
idleWaiters = [];
|
|
16930
17238
|
abort = null;
|
|
17239
|
+
activeJob;
|
|
16931
17240
|
/** 当前流式 chunk 的 steer 口(仅用户消息路径开;外部 ask/桌面路径为 null) */
|
|
16932
17241
|
feeder = null;
|
|
16933
17242
|
sessionId = null;
|
|
@@ -16972,13 +17281,17 @@ var init_driver = __esm({
|
|
|
16972
17281
|
void this.drain();
|
|
16973
17282
|
}
|
|
16974
17283
|
/** External callers use the same FIFO; they never answer a pending permission card. */
|
|
16975
|
-
ask(prompt, source, expectedSessionId, signal) {
|
|
16976
|
-
|
|
16977
|
-
|
|
16978
|
-
|
|
16979
|
-
if (this.
|
|
16980
|
-
if (
|
|
16981
|
-
|
|
17284
|
+
async ask(prompt, source, expectedSessionId, signal) {
|
|
17285
|
+
return this.submit(prompt, source, expectedSessionId, signal);
|
|
17286
|
+
}
|
|
17287
|
+
submit(prompt, source, expectedSessionId, signal, id2, onSession) {
|
|
17288
|
+
if (this.closed) throw requestError("CC binding is stopping", 503);
|
|
17289
|
+
if (!prompt.trim()) throw requestError("prompt is required", 400);
|
|
17290
|
+
if (signal?.aborted) throw requestError("CC request cancelled", 499);
|
|
17291
|
+
if (this.sessionId !== expectedSessionId) throw requestError("CC session changed; select the current binding again");
|
|
17292
|
+
if (id2 && (this.activeJob?.id === id2 || this.queue.some((job2) => job2.id === id2))) throw requestError("CC job already exists");
|
|
17293
|
+
if (this.queue.length >= MAX_QUEUE) throw requestError("CC queue is full", 429);
|
|
17294
|
+
const job = { id: id2, prompt: prompt.trim(), source, expectedSessionId, expectedRevision: id2 ? this.revision : void 0, signal, onSession };
|
|
16982
17295
|
const cancel = () => {
|
|
16983
17296
|
const index = this.queue.indexOf(job);
|
|
16984
17297
|
if (index >= 0) {
|
|
@@ -16993,7 +17306,16 @@ var init_driver = __esm({
|
|
|
16993
17306
|
signal?.addEventListener("abort", cancel, { once: true });
|
|
16994
17307
|
void this.drain();
|
|
16995
17308
|
});
|
|
16996
|
-
return pending.finally(() => signal
|
|
17309
|
+
return signal ? pending.finally(() => signal.removeEventListener("abort", cancel)) : pending;
|
|
17310
|
+
}
|
|
17311
|
+
stopJob(id2) {
|
|
17312
|
+
const index = this.queue.findIndex((job) => job.id === id2);
|
|
17313
|
+
if (index >= 0) {
|
|
17314
|
+
this.queue.splice(index, 1)[0].reject?.(requestError("CC request cancelled (stop)", 499));
|
|
17315
|
+
return true;
|
|
17316
|
+
}
|
|
17317
|
+
if (this.activeJob?.id === id2) return this.activeJob.stop?.() ?? false;
|
|
17318
|
+
return false;
|
|
16997
17319
|
}
|
|
16998
17320
|
/** Reload/stop must not leave the old hub executing queued work. */
|
|
16999
17321
|
shutdown() {
|
|
@@ -17019,6 +17341,9 @@ var init_driver = __esm({
|
|
|
17019
17341
|
stop() {
|
|
17020
17342
|
this.abort?.abort();
|
|
17021
17343
|
}
|
|
17344
|
+
get queued() {
|
|
17345
|
+
return this.queue.length;
|
|
17346
|
+
}
|
|
17022
17347
|
get busy() {
|
|
17023
17348
|
return this.draining;
|
|
17024
17349
|
}
|
|
@@ -17032,15 +17357,17 @@ var init_driver = __esm({
|
|
|
17032
17357
|
await this.predecessor;
|
|
17033
17358
|
while (!this.closed && this.queue.length > 0) {
|
|
17034
17359
|
const job = this.queue.shift();
|
|
17360
|
+
this.activeJob = job;
|
|
17035
17361
|
try {
|
|
17036
17362
|
if (job.signal?.aborted) throw requestError("CC request cancelled", 499);
|
|
17037
|
-
|
|
17363
|
+
const changed = job.expectedRevision !== void 0 ? job.expectedRevision !== this.revision : job.expectedSessionId !== void 0 && job.expectedSessionId !== this.sessionId;
|
|
17364
|
+
if (changed) {
|
|
17038
17365
|
throw requestError("CC session changed while this request was queued");
|
|
17039
17366
|
}
|
|
17040
17367
|
if (job.source) {
|
|
17041
17368
|
const prompt = `[cc_ask from ${job.source.replace(/[\r\n]/g, " ").slice(0, 160)}]
|
|
17042
17369
|
${job.prompt}`;
|
|
17043
|
-
const result = await this.runTurn(prompt, job.signal, true);
|
|
17370
|
+
const result = await this.runTurn(prompt, job.signal, true, job);
|
|
17044
17371
|
job.resolve?.(result);
|
|
17045
17372
|
} else {
|
|
17046
17373
|
await this.runStreaming(job);
|
|
@@ -17049,6 +17376,8 @@ ${job.prompt}`;
|
|
|
17049
17376
|
job.reject?.(err);
|
|
17050
17377
|
console.error(`[cc-driver] turn \u5931\u8D25 key=${this.key}: ${err?.stack || err}`);
|
|
17051
17378
|
await this.sendText(`[cc-driver] \u8FD9\u6B21\u4EFB\u52A1\u5931\u8D25\uFF1A${err?.message || String(err)}`);
|
|
17379
|
+
} finally {
|
|
17380
|
+
this.activeJob = void 0;
|
|
17052
17381
|
}
|
|
17053
17382
|
}
|
|
17054
17383
|
} finally {
|
|
@@ -17056,12 +17385,24 @@ ${job.prompt}`;
|
|
|
17056
17385
|
for (const resolve47 of this.idleWaiters.splice(0)) resolve47();
|
|
17057
17386
|
}
|
|
17058
17387
|
}
|
|
17059
|
-
async runTurn(prompt, signal, external = false) {
|
|
17388
|
+
async runTurn(prompt, signal, external = false, job) {
|
|
17060
17389
|
const ac = new AbortController();
|
|
17061
17390
|
this.abort = ac;
|
|
17391
|
+
if (job?.id) job.stop = () => {
|
|
17392
|
+
ac.abort();
|
|
17393
|
+
return true;
|
|
17394
|
+
};
|
|
17062
17395
|
const resumedFrom = this.sessionId;
|
|
17063
17396
|
const revision = this.revision;
|
|
17064
17397
|
let turnSessionId = resumedFrom;
|
|
17398
|
+
const observeSession = (id2) => {
|
|
17399
|
+
try {
|
|
17400
|
+
job?.onSession?.(id2);
|
|
17401
|
+
} catch (error) {
|
|
17402
|
+
console.error("[cc-driver] task session update failed:", error.message);
|
|
17403
|
+
}
|
|
17404
|
+
};
|
|
17405
|
+
observeSession(turnSessionId);
|
|
17065
17406
|
const cancel = () => ac.abort();
|
|
17066
17407
|
signal?.addEventListener("abort", cancel, { once: true });
|
|
17067
17408
|
if (signal?.aborted) ac.abort();
|
|
@@ -17085,13 +17426,31 @@ ${job.prompt}`;
|
|
|
17085
17426
|
const acc = this.makeStreamAccumulator();
|
|
17086
17427
|
try {
|
|
17087
17428
|
const desktops = resumedFrom ? await findDesktopTargets(this.workDir, resumedFrom) : [];
|
|
17429
|
+
ac.signal.throwIfAborted();
|
|
17088
17430
|
if (desktops.length > 1) throw new Error("Multiple desktop writers claim this CC session; close the duplicate");
|
|
17089
17431
|
if (desktops[0]) {
|
|
17090
|
-
const
|
|
17432
|
+
const desktop = desktops[0];
|
|
17433
|
+
let result2;
|
|
17434
|
+
if (job?.id) {
|
|
17435
|
+
const jobId = job.id;
|
|
17436
|
+
let acknowledge;
|
|
17437
|
+
const accepted = new Promise((resolve47) => {
|
|
17438
|
+
acknowledge = resolve47;
|
|
17439
|
+
});
|
|
17440
|
+
job.stop = async () => await accepted && stopDesktopJob(desktop, jobId);
|
|
17441
|
+
try {
|
|
17442
|
+
result2 = await askDesktop(desktop, prompt, this.key, ac.signal, { jobId, onAccepted: () => acknowledge(true) });
|
|
17443
|
+
} finally {
|
|
17444
|
+
acknowledge(false);
|
|
17445
|
+
}
|
|
17446
|
+
} else {
|
|
17447
|
+
result2 = await askDesktop(desktop, prompt, this.key, ac.signal);
|
|
17448
|
+
}
|
|
17091
17449
|
finalText = result2.text;
|
|
17092
17450
|
isError = result2.isError;
|
|
17093
17451
|
gotResult = true;
|
|
17094
17452
|
turnSessionId = result2.sessionId;
|
|
17453
|
+
observeSession(turnSessionId);
|
|
17095
17454
|
if (this.revision === revision) this.sessionId = result2.sessionId;
|
|
17096
17455
|
} else {
|
|
17097
17456
|
if (resumedFrom && nativeSessionOwners(resumedFrom).length) {
|
|
@@ -17104,6 +17463,7 @@ ${job.prompt}`;
|
|
|
17104
17463
|
const mb = total ? `\u7EA6 ${Math.round(total / 1024 / 1024)}M` : "\u7EA6 350M";
|
|
17105
17464
|
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`);
|
|
17106
17465
|
});
|
|
17466
|
+
ac.signal.throwIfAborted();
|
|
17107
17467
|
const stream = query({
|
|
17108
17468
|
prompt,
|
|
17109
17469
|
options: {
|
|
@@ -17146,6 +17506,7 @@ ${job.prompt}`;
|
|
|
17146
17506
|
const r = msg2;
|
|
17147
17507
|
if (r.session_id) {
|
|
17148
17508
|
turnSessionId = r.session_id;
|
|
17509
|
+
observeSession(turnSessionId);
|
|
17149
17510
|
if (this.revision === revision) this.sessionId = r.session_id;
|
|
17150
17511
|
}
|
|
17151
17512
|
isError = r.is_error === true;
|
|
@@ -17156,6 +17517,7 @@ ${job.prompt}`;
|
|
|
17156
17517
|
const sid = msg2.session_id;
|
|
17157
17518
|
if (sid) {
|
|
17158
17519
|
turnSessionId = sid;
|
|
17520
|
+
observeSession(turnSessionId);
|
|
17159
17521
|
if (this.revision === revision) this.sessionId = sid;
|
|
17160
17522
|
}
|
|
17161
17523
|
} else {
|
|
@@ -17165,6 +17527,7 @@ ${job.prompt}`;
|
|
|
17165
17527
|
}
|
|
17166
17528
|
if (turnSessionId && gotResult && this.revision === revision) this.map.switchTo(this.key, turnSessionId, this.workDir);
|
|
17167
17529
|
} finally {
|
|
17530
|
+
if (job) job.stop = void 0;
|
|
17168
17531
|
this.abort = null;
|
|
17169
17532
|
signal?.removeEventListener("abort", cancel);
|
|
17170
17533
|
}
|
|
@@ -17590,29 +17953,32 @@ async function findBoundCcTargets(workDir, key3) {
|
|
|
17590
17953
|
}));
|
|
17591
17954
|
return lists.flat();
|
|
17592
17955
|
}
|
|
17593
|
-
async function askBoundCc(target, prompt, source, signal) {
|
|
17956
|
+
async function askBoundCc(target, prompt, source, signal, acknowledgment) {
|
|
17957
|
+
const endpoint2 = acknowledgment ? "submit" : "ask";
|
|
17594
17958
|
const { status, json: result } = await longPostJson(
|
|
17595
|
-
`http://127.0.0.1:${target.endpoint.port}/api/cc-driver
|
|
17959
|
+
`http://127.0.0.1:${target.endpoint.port}/api/cc-driver/${endpoint2}`,
|
|
17596
17960
|
{
|
|
17597
17961
|
key: target.key,
|
|
17598
17962
|
workDir: target.workDir,
|
|
17599
17963
|
prompt,
|
|
17600
17964
|
source,
|
|
17965
|
+
jobId: acknowledgment?.jobId,
|
|
17601
17966
|
expectedSessionId: target.sessionId,
|
|
17602
17967
|
expectedPid: target.endpoint.pid,
|
|
17603
17968
|
expectedStateDir: target.endpoint.stateDir
|
|
17604
17969
|
},
|
|
17605
17970
|
{ "x-engine-console": "1" },
|
|
17606
|
-
signal
|
|
17971
|
+
signal,
|
|
17972
|
+
acknowledgment
|
|
17607
17973
|
);
|
|
17608
|
-
if (status !== 200) throw new Error(result?.error || `CC hub handoff failed (HTTP ${status})`);
|
|
17974
|
+
if (status !== 200 || result?.error) throw new Error(result?.error || `CC hub handoff failed (HTTP ${status})`);
|
|
17609
17975
|
if (typeof result.text !== "string" || typeof result.isError !== "boolean" || result.sessionId !== null && typeof result.sessionId !== "string") throw new Error("CC hub returned an invalid result");
|
|
17610
17976
|
return result;
|
|
17611
17977
|
}
|
|
17612
|
-
async function stopBoundCc(target) {
|
|
17978
|
+
async function stopBoundCc(target, jobId) {
|
|
17613
17979
|
const { status, json } = await longPostJson(
|
|
17614
17980
|
`http://127.0.0.1:${target.endpoint.port}/api/cc-driver/stop`,
|
|
17615
|
-
{ key: target.key, workDir: target.workDir, expectedPid: target.endpoint.pid, expectedStateDir: target.endpoint.stateDir },
|
|
17981
|
+
{ key: target.key, workDir: target.workDir, jobId, expectedPid: target.endpoint.pid, expectedStateDir: target.endpoint.stateDir },
|
|
17616
17982
|
{ "x-engine-console": "1" },
|
|
17617
17983
|
AbortSignal.timeout(5e3)
|
|
17618
17984
|
);
|
|
@@ -17721,9 +18087,9 @@ __export(router_exports, {
|
|
|
17721
18087
|
import { existsSync as existsSync16 } from "node:fs";
|
|
17722
18088
|
function autoBindHit(inbound) {
|
|
17723
18089
|
if (inbound.channel !== "feishu" || inbound.channelType !== "dm") return null;
|
|
17724
|
-
const
|
|
18090
|
+
const owner2 = liveConfig.get("channels.feishu.ownerOpenId");
|
|
17725
18091
|
const workDir = liveConfig.get("channels.ccDriver.autoBind.workDir");
|
|
17726
|
-
if (!
|
|
18092
|
+
if (!owner2 || !workDir || inbound.from !== owner2) return null;
|
|
17727
18093
|
const cur = liveConfig.get("channels.ccDriver");
|
|
17728
18094
|
if (cur?.enabled === false) return null;
|
|
17729
18095
|
if ((cur?.bindings ?? []).length > 0) return null;
|
|
@@ -17842,11 +18208,6 @@ var init_router = __esm({
|
|
|
17842
18208
|
// src/tools/cc-progress.ts
|
|
17843
18209
|
var cc_progress_exports = {};
|
|
17844
18210
|
import path16 from "node:path";
|
|
17845
|
-
function extractBlocks(content) {
|
|
17846
|
-
if (typeof content === "string") return [{ type: "text", text: content }];
|
|
17847
|
-
if (Array.isArray(content)) return content;
|
|
17848
|
-
return [];
|
|
17849
|
-
}
|
|
17850
18211
|
function fmtTime(ts) {
|
|
17851
18212
|
if (!ts) return "?";
|
|
17852
18213
|
const d = new Date(ts);
|
|
@@ -17856,33 +18217,44 @@ function fmtTime(ts) {
|
|
|
17856
18217
|
if (diff < 3600) return `${Math.floor(diff / 60)}\u5206\u949F\u524D`;
|
|
17857
18218
|
return d.toLocaleString("zh-CN", { hour12: false });
|
|
17858
18219
|
}
|
|
17859
|
-
function snippet(text2, max = 220) {
|
|
17860
|
-
const t = text2.replace(/\s+/g, " ").trim();
|
|
17861
|
-
return t.length > max ? t.slice(0, max) + "\u2026" : t;
|
|
17862
|
-
}
|
|
17863
18220
|
var init_cc_progress = __esm({
|
|
17864
18221
|
"src/tools/cc-progress.ts"() {
|
|
17865
18222
|
"use strict";
|
|
17866
18223
|
init_registry();
|
|
18224
|
+
init_cc_ask_jobs();
|
|
18225
|
+
init_cc_peer();
|
|
17867
18226
|
init_project_sessions();
|
|
18227
|
+
init_progress_transcript();
|
|
17868
18228
|
init_open_sessions();
|
|
17869
18229
|
registry.register({
|
|
17870
18230
|
name: "cc_progress",
|
|
17871
|
-
description: `Read-only Claude Code discovery and progress. For "\u684C\u9762\u6709\u54EA\u4E9B CC / \u54EA\u4E2A session \u5F00\u7740 / \u770B\u4E0B\u684C\u9762 CC", use view="sessions": lists ALL live native interactive sessions plus Engine7 desktop bridges, with full UUID, project, PID, terminal and connection status. Ordinary claude sessions are visible even without cc-desktop
|
|
18231
|
+
description: `Read-only Claude Code discovery and progress. Use jobId from a cc_ask receipt for that task's status and final answer. For "\u684C\u9762\u6709\u54EA\u4E9B CC / \u54EA\u4E2A session \u5F00\u7740 / \u770B\u4E0B\u684C\u9762 CC", use view="sessions": lists ALL live native interactive sessions plus Engine7 desktop bridges, with full UUID, project, PID, terminal and connection status. Ordinary claude sessions are visible even without cc-desktop. No arguments also lists sessions. workDir optionally filters the inventory. Use view="progress" with workDir to inspect the latest project transcript (workDir alone retains this behavior). Only sessions marked \u53EF\u6295\u9012 accept cc_ask in the existing process. If the user's context identifies a target select it yourself; otherwise ask which session.`,
|
|
17872
18232
|
schema: {
|
|
17873
18233
|
type: "object",
|
|
17874
18234
|
properties: {
|
|
17875
18235
|
view: { type: "string", enum: ["sessions", "progress"], description: "sessions = \u5217\u51FA\u6240\u6709\u6253\u5F00\u7684\u539F\u751F\uFF0F\u5DF2\u63A5\u5165\u4F1A\u8BDD\uFF1Bprogress = \u8BFB\u53D6\u9879\u76EE\u6700\u65B0\u5386\u53F2\u3002\u7701\u7565\u4E14\u65E0 workDir \u65F6\u9ED8\u8BA4 sessions" },
|
|
17876
|
-
workDir: { type: "string", description: "CC \u9879\u76EE\u7EDD\u5BF9\u8DEF\u5F84\u3002sessions \u6A21\u5F0F\u7701\u7565\u5219\u67E5\u672C\u673A\u6240\u6709\u9879\u76EE\uFF1Bprogress \u6A21\u5F0F\u7528\u4E8E\u9009\u62E9\u5386\u53F2\u8BB0\u5F55" }
|
|
18236
|
+
workDir: { type: "string", description: "CC \u9879\u76EE\u7EDD\u5BF9\u8DEF\u5F84\u3002sessions \u6A21\u5F0F\u7701\u7565\u5219\u67E5\u672C\u673A\u6240\u6709\u9879\u76EE\uFF1Bprogress \u6A21\u5F0F\u7528\u4E8E\u9009\u62E9\u5386\u53F2\u8BB0\u5F55" },
|
|
18237
|
+
target: { type: "string", description: "remote:\u5DF2\u914D\u7F6E\u7684 CC \u522B\u540D\uFF0C\u7528\u4E8E\u67E5\u8FDC\u7A0B\u7ED1\u5B9A\u72B6\u6001\u3002" },
|
|
18238
|
+
jobId: { type: "string", description: "cc_ask \u56DE\u6267\u4E2D\u7684\u4EFB\u52A1 ID\uFF0C\u7528\u4E8E\u67E5\u770B\u8BE5\u4EFB\u52A1\u7684\u72B6\u6001\u548C\u7ED3\u679C\u3002" }
|
|
17877
18239
|
},
|
|
17878
18240
|
required: []
|
|
17879
18241
|
},
|
|
17880
|
-
handler: async (args, ctx) => {
|
|
18242
|
+
handler: async (args, ctx, signal) => {
|
|
18243
|
+
const remote = await observeRemoteCc("progress", args, ctx, signal);
|
|
18244
|
+
if (remote) return remote;
|
|
18245
|
+
if (args.jobId !== void 0) return ccAskJobProgress(args.jobId, ctx, ({ workDir: workDir2, sessionId }) => {
|
|
18246
|
+
if (!sessionId || !/^[a-zA-Z0-9_-]+$/.test(sessionId)) return void 0;
|
|
18247
|
+
try {
|
|
18248
|
+
return summarizeTranscript(path16.join(projectDirFor(workDir2), `${sessionId}.jsonl`)).recent;
|
|
18249
|
+
} catch {
|
|
18250
|
+
return void 0;
|
|
18251
|
+
}
|
|
18252
|
+
});
|
|
17881
18253
|
let workDir = typeof args.workDir === "string" && args.workDir.trim() ? args.workDir.trim() : "";
|
|
17882
18254
|
if (args.view !== void 0 && !["sessions", "progress"].includes(args.view)) return { content: "view \u9700\u8981 sessions \u6216 progress\u3002", isError: true };
|
|
17883
18255
|
if (args.view === "sessions" || !args.view && !workDir) {
|
|
17884
18256
|
const { sessions: sessions3, warning } = await listOpenCcSessions(workDir || void 0);
|
|
17885
|
-
const
|
|
18257
|
+
const lines = sessions3.map((s, i) => {
|
|
17886
18258
|
const status = s.connection === "ready" ? `\u5DF2\u63A5\u5165\uFF0C\u53EF\u6295\u9012${s.busy ? "\uFF08\u5FD9\uFF0C\u6D88\u606F\u6392\u961F\uFF09" : ""}` : s.connection === "starting" ? "\u5DF2\u63A5\u5165\uFF0C\u5C1A\u672A\u5C31\u7EEA" : s.connection === "unknown" ? "\u63A5\u5165\u72B6\u6001\u672A\u77E5" : "\u672A\u63A5\u5165\uFF08\u53EA\u8BFB\u53EF\u89C1\uFF09";
|
|
17887
18259
|
const activity = s.lastActiveAt === void 0 ? "\u672A\u77E5" : `${new Date(s.lastActiveAt).toISOString()}\uFF08${fmtTime(new Date(s.lastActiveAt).toISOString())}\uFF0C\u65E5\u5FD7\u5199\u5165\uFF09`;
|
|
17888
18260
|
return `${i + 1}. ${s.sessionId}
|
|
@@ -17895,7 +18267,7 @@ var init_cc_progress = __esm({
|
|
|
17895
18267
|
return { content: [
|
|
17896
18268
|
sessions3.length ? `\u5F53\u524D\u53D1\u73B0 ${sessions3.length} \u4E2A\u6253\u5F00\u7684 CC \u4F1A\u8BDD\uFF1A` : "\u5F53\u524D\u6CA1\u6709\u53D1\u73B0\u5DF2\u767B\u8BB0\u4E14\u8FDB\u7A0B\u5B58\u6D3B\u7684\u4EA4\u4E92 CC \u4F1A\u8BDD\u3002",
|
|
17897
18269
|
warning,
|
|
17898
|
-
...
|
|
18270
|
+
...lines,
|
|
17899
18271
|
"\u4F1A\u8BDD\u6E05\u5355\u5305\u542B\u666E\u901A claude \u4E0E\u5DF2\u63A5\u5165\u7684 cc-desktop\uFF1B\u4E0D\u4EE3\u8868\u7A97\u53E3\u662F\u5426\u5728\u5C4F\u5E55\u524D\u53F0\u3002\u6700\u540E\u6D3B\u8DC3\u662F\u65E5\u5FD7\u5199\u5165\u65F6\u95F4\uFF0C\u957F\u671F\u65E0\u5199\u5165\u4E0D\u80FD\u5355\u72EC\u5224\u65AD\u6302\u6B7B\uFF0C\u8FDB\u7A0B\u5B58\u6D3B\u53E6\u5217\u3002\u672A\u63A5\u5165\u4F1A\u8BDD\u53EF\u4EE5\u53D1\u73B0\uFF0C\u4F46\u9700\u9996\u6B21\u7528 cc-desktop \u6062\u590D\u540E\u624D\u80FD\u5411\u539F\u8FDB\u7A0B\u53D1\u6D88\u606F\u3002\u672C\u6B21\u53EA\u8BFB\u67E5\u8BE2\uFF0C\u6CA1\u6709\u53D1\u9001\u6D88\u606F\u6216\u5207\u6362\u7ED1\u5B9A\u3002"
|
|
17900
18272
|
].filter(Boolean).join("\n") };
|
|
17901
18273
|
}
|
|
@@ -17916,30 +18288,7 @@ ${dirs.join("\n")}`, isError: true };
|
|
|
17916
18288
|
return { content: `${workDir} \u4E0B\u6CA1\u6709\u627E\u5230\u4EFB\u4F55 CC \u4F1A\u8BDD\u8BB0\u5F55\uFF08~/.claude/projects \u91CC\u6CA1\u6709\u8FD9\u4E2A\u76EE\u5F55\u7684\u4F1A\u8BDD\uFF09`, isError: true };
|
|
17917
18289
|
}
|
|
17918
18290
|
const latest = sessions2[0];
|
|
17919
|
-
const
|
|
17920
|
-
const recent = [];
|
|
17921
|
-
let lastTs = "";
|
|
17922
|
-
for (let i = lines.length - 1; i >= 0 && recent.length < 8; i--) {
|
|
17923
|
-
let entry;
|
|
17924
|
-
try {
|
|
17925
|
-
entry = JSON.parse(lines[i]);
|
|
17926
|
-
} catch {
|
|
17927
|
-
continue;
|
|
17928
|
-
}
|
|
17929
|
-
if (entry.type !== "user" && entry.type !== "assistant") continue;
|
|
17930
|
-
if (!lastTs && entry.timestamp) lastTs = entry.timestamp;
|
|
17931
|
-
const blocks = extractBlocks(entry.message?.content);
|
|
17932
|
-
for (const b of blocks) {
|
|
17933
|
-
if (entry.type === "user" && b.type === "text" && b.text && !b.text.includes("tool_result")) {
|
|
17934
|
-
recent.push(`\u{1F464} ${snippet(b.text)}`);
|
|
17935
|
-
} else if (entry.type === "assistant" && b.type === "text" && b.text) {
|
|
17936
|
-
recent.push(`\u{1F916} ${snippet(b.text)}`);
|
|
17937
|
-
} else if (entry.type === "assistant" && b.type === "tool_use" && b.name) {
|
|
17938
|
-
recent.push(`\u{1F527} ${b.name}`);
|
|
17939
|
-
}
|
|
17940
|
-
}
|
|
17941
|
-
}
|
|
17942
|
-
recent.reverse();
|
|
18291
|
+
const { recent, lastTs } = summarizeTranscript(latest.file);
|
|
17943
18292
|
const idleMs = Date.now() - latest.modifiedAt;
|
|
17944
18293
|
const state2 = idleMs < 3e4 ? "\u{1F7E2} \u6D3B\u8DC3\uFF08<30s \u5185\u6709\u5199\u5165\uFF09" : idleMs < 5 * 6e4 ? "\u{1F7E1} \u8FD1\u671F\u6709\u6D3B\u52A8" : "\u26AA \u7A7A\u95F2";
|
|
17945
18294
|
const out = [
|
|
@@ -17961,8 +18310,15 @@ var cc_ask_exports = {};
|
|
|
17961
18310
|
__export(cc_ask_exports, {
|
|
17962
18311
|
ccAskOnce: () => ccAskOnce
|
|
17963
18312
|
});
|
|
17964
|
-
import { existsSync as existsSync17 } from "node:fs";
|
|
18313
|
+
import { existsSync as existsSync17, realpathSync as realpathSync12, statSync as statSync7 } from "node:fs";
|
|
17965
18314
|
import path17 from "node:path";
|
|
18315
|
+
async function drainStandalone(directory2, queue) {
|
|
18316
|
+
while (queue.length) {
|
|
18317
|
+
await queue[0].run();
|
|
18318
|
+
queue.shift();
|
|
18319
|
+
}
|
|
18320
|
+
standaloneQueues.delete(directory2);
|
|
18321
|
+
}
|
|
17966
18322
|
async function ccAskOnce(prompt, workDir, timeoutMs = ccAskTimeoutMs()) {
|
|
17967
18323
|
const { query } = await loadOptionalModule("cc-runtime");
|
|
17968
18324
|
const ac = new AbortController();
|
|
@@ -17999,7 +18355,104 @@ async function ccAskOnce(prompt, workDir, timeoutMs = ccAskTimeoutMs()) {
|
|
|
17999
18355
|
if (!resultText.trim()) return { ok: false, text: "CC \u7ED3\u675F\u4F46\u6CA1\u6709\u4EA7\u51FA\u6587\u672C" + (isError ? "\uFF08\u51FA\u9519\uFF09" : ""), sessionId };
|
|
18000
18356
|
return { ok: !isError, text: resultText, sessionId };
|
|
18001
18357
|
}
|
|
18002
|
-
|
|
18358
|
+
async function runStandalone(args, ctx, prompt, workDir, resumeLatest, ac, onSession) {
|
|
18359
|
+
if (ac.signal.aborted) return standaloneStopped;
|
|
18360
|
+
const stateDir = typeof ctx.stateDir === "string" && ctx.stateDir ? ctx.stateDir : typeof ctx.workspace === "string" ? ctx.workspace : "";
|
|
18361
|
+
let store = null;
|
|
18362
|
+
if (stateDir) {
|
|
18363
|
+
try {
|
|
18364
|
+
store = new CcSessionMapStore(stateDir, path17.join("agents", "cc-ask", "session-map.json"));
|
|
18365
|
+
} catch {
|
|
18366
|
+
store = null;
|
|
18367
|
+
}
|
|
18368
|
+
}
|
|
18369
|
+
const mapKey = `ask:${String(ctx.sessionId ?? ctx.channel ?? "anon")}@${workDir}`;
|
|
18370
|
+
let sessionId;
|
|
18371
|
+
let resumedFrom = "";
|
|
18372
|
+
const forceNew = args.newSession === true;
|
|
18373
|
+
if (forceNew) {
|
|
18374
|
+
store?.clear(mapKey);
|
|
18375
|
+
} else if (resumeLatest) {
|
|
18376
|
+
const sessions2 = listProjectSessions(workDir, void 0, 3);
|
|
18377
|
+
const candidate = sessions2.find((s) => s.messageCount > 0);
|
|
18378
|
+
if (!candidate) return { content: `${workDir} \u4E0B\u6CA1\u6709\u53EF\u63A5\u7EED\u7684 CC \u4F1A\u8BDD\uFF08\u53BB\u6389 resumeLatest \u5F00\u65B0\u4F1A\u8BDD\uFF09`, isError: true };
|
|
18379
|
+
if (await checkActive(candidate.file, 300)) {
|
|
18380
|
+
return { content: `\u8BE5\u9879\u76EE\u6700\u65B0\u4F1A\u8BDD\u6B63\u88AB\u522B\u5904\u9A71\u52A8\uFF08\u25CFlive\uFF1A\u63A7\u5236\u53F0\u6216\u98DE\u4E66 hub\uFF09\u2014\u2014\u7B49\u5B83\u7A7A\u95F2\u518D\u63A5\u624B\uFF0C\u6216\u53BB\u6389 resumeLatest \u5F00\u65B0\u4F1A\u8BDD\u3002`, isError: true };
|
|
18381
|
+
}
|
|
18382
|
+
sessionId = candidate.id;
|
|
18383
|
+
resumedFrom = "latest";
|
|
18384
|
+
} else {
|
|
18385
|
+
const mapped = store?.get(mapKey);
|
|
18386
|
+
if (mapped?.sessionId) {
|
|
18387
|
+
const hit = listProjectSessions(workDir, void 0, 30).find((s) => s.id === mapped.sessionId);
|
|
18388
|
+
if (hit) {
|
|
18389
|
+
if (await isActiveConfirmed(hit.file, 2e3)) {
|
|
18390
|
+
return { content: `\u4F60\u4E0A\u6B21\u7684 CC \u4F1A\u8BDD\uFF08${mapped.sessionId.slice(0, 8)}\uFF09\u6B63\u88AB\u522B\u5904\u9A71\u52A8\uFF08\u25CFlive\uFF1A\u63A7\u5236\u53F0\u6216\u98DE\u4E66 hub\uFF09\u2014\u2014\u7B49\u5B83\u7A7A\u95F2\u518D cc_ask\uFF0C\u6216 newSession=true \u5F00\u65B0\u4F1A\u8BDD\u3002`, isError: true };
|
|
18391
|
+
}
|
|
18392
|
+
sessionId = mapped.sessionId;
|
|
18393
|
+
resumedFrom = "own";
|
|
18394
|
+
}
|
|
18395
|
+
}
|
|
18396
|
+
}
|
|
18397
|
+
if (!sessionId) {
|
|
18398
|
+
const sessions2 = listProjectSessions(workDir, void 0, 1);
|
|
18399
|
+
const latest = sessions2[0];
|
|
18400
|
+
if (latest && await checkActive(latest.file, 300)) {
|
|
18401
|
+
return { content: `\u8BE5\u9879\u76EE\u6709\u4F1A\u8BDD\u6B63\u88AB\u522B\u5904\u9A71\u52A8\uFF08\u25CFlive\uFF09\u2014\u2014\u4E3A\u907F\u514D CC \u62FF\u7740\u8FC7\u65F6\u4E0A\u4E0B\u6587\u5E72\u6D3B\uFF0C\u7A0D\u7B49\u5B83\u7A7A\u95F2\uFF0C\u6216\u6307\u5B9A\u5176\u4ED6 workDir\u3002`, isError: true };
|
|
18402
|
+
}
|
|
18403
|
+
}
|
|
18404
|
+
if (sessionId && (nativeSessionOwners(sessionId).length || (await findDesktopTargets(workDir, sessionId)).length)) {
|
|
18405
|
+
return { content: "\u8BE5 CC \u4F1A\u8BDD\u4ECD\u7531\u684C\u9762\u8FDB\u7A0B\u6301\u6709\uFF1B\u8BF7\u7528 sessionId \u6295\u9012\u5230 cc-desktop\uFF0C\u4E0D\u80FD\u53E6\u8D77\u72EC\u7ACB CLI \u5199\u5165\u3002", isError: true };
|
|
18406
|
+
}
|
|
18407
|
+
if (ac.signal.aborted) return standaloneStopped;
|
|
18408
|
+
if (sessionId) onSession(sessionId);
|
|
18409
|
+
const { query } = await loadOptionalModule("cc-runtime");
|
|
18410
|
+
if (ac.signal.aborted) return standaloneStopped;
|
|
18411
|
+
let resultText = "";
|
|
18412
|
+
let newSessionId;
|
|
18413
|
+
let isError = false;
|
|
18414
|
+
try {
|
|
18415
|
+
const stream = query({
|
|
18416
|
+
prompt,
|
|
18417
|
+
options: {
|
|
18418
|
+
abortController: ac,
|
|
18419
|
+
cwd: workDir,
|
|
18420
|
+
permissionMode: "bypassPermissions",
|
|
18421
|
+
...sessionId ? { resume: sessionId } : {},
|
|
18422
|
+
env: { CC_ASK_DEPTH: "1" }
|
|
18423
|
+
}
|
|
18424
|
+
});
|
|
18425
|
+
for await (const msg2 of stream) {
|
|
18426
|
+
if (msg2.parent_tool_use_id) continue;
|
|
18427
|
+
if (msg2.type === "system" && msg2.subtype === "init" && typeof msg2.session_id === "string") onSession(msg2.session_id);
|
|
18428
|
+
if (msg2.type === "result") {
|
|
18429
|
+
const r = msg2;
|
|
18430
|
+
resultText = typeof r.result === "string" ? r.result : "";
|
|
18431
|
+
isError = r.is_error === true;
|
|
18432
|
+
if (r.session_id) {
|
|
18433
|
+
newSessionId = r.session_id;
|
|
18434
|
+
onSession(r.session_id);
|
|
18435
|
+
}
|
|
18436
|
+
}
|
|
18437
|
+
}
|
|
18438
|
+
} catch (err) {
|
|
18439
|
+
if (ac.signal.aborted) return standaloneStopped;
|
|
18440
|
+
return { content: `CC \u9A71\u52A8\u5931\u8D25\uFF1A${err?.message ?? err}`, isError: true };
|
|
18441
|
+
}
|
|
18442
|
+
if (ac.signal.aborted) return standaloneStopped;
|
|
18443
|
+
const text2 = resultText.trim();
|
|
18444
|
+
if (!text2) return { content: "CC \u7ED3\u675F\u4F46\u6CA1\u6709\u4EA7\u51FA\u6587\u672C" + (isError ? "\uFF08\u51FA\u9519\uFF09" : ""), isError: true };
|
|
18445
|
+
if (newSessionId && store) {
|
|
18446
|
+
try {
|
|
18447
|
+
store.set(mapKey, newSessionId, workDir);
|
|
18448
|
+
} catch {
|
|
18449
|
+
}
|
|
18450
|
+
}
|
|
18451
|
+
const tail = resumedFrom === "own" ? `\uFF08\u63A5\u7EED\u4F60\u4E0A\u6B21\u7684\u4F1A\u8BDD ${newSessionId?.slice(0, 8)}\uFF0C\u4E4B\u524D cc_ask \u5F3A\u8C03\u8FC7\u7684\u8981\u6C42\u90FD\u5728\u4E0A\u4E0B\u6587\u91CC\uFF09` : newSessionId ? `\uFF08${resumedFrom === "latest" ? "\u63A5\u7EED\u9879\u76EE\u6700\u8FD1\u4F1A\u8BDD" : "\u65B0\u4F1A\u8BDD"} ${newSessionId.slice(0, 8)}\uFF0C\u5DF2\u8BB0\u4F4F\u2014\u2014\u540E\u7EED cc_ask \u81EA\u52A8\u63A5\u7EED\uFF1BnewSession=true \u53EF\u91CD\u5F00\uFF09` : "";
|
|
18452
|
+
return { content: `[CC @ ${workDir.split("/").pop()}] ${text2}${tail ? `
|
|
18453
|
+
${tail}` : ""}`, isError };
|
|
18454
|
+
}
|
|
18455
|
+
var standaloneQueues, MAX_STANDALONE_QUEUE, standaloneStopped, CC_ASK_TIMEOUT_MS, ccAskTimeoutMs;
|
|
18003
18456
|
var init_cc_ask = __esm({
|
|
18004
18457
|
"src/tools/cc-ask.ts"() {
|
|
18005
18458
|
"use strict";
|
|
@@ -18010,6 +18463,11 @@ var init_cc_ask = __esm({
|
|
|
18010
18463
|
init_handoff();
|
|
18011
18464
|
init_desktop();
|
|
18012
18465
|
init_dep_downloader();
|
|
18466
|
+
init_cc_ask_jobs();
|
|
18467
|
+
init_cc_peer();
|
|
18468
|
+
standaloneQueues = /* @__PURE__ */ new Map();
|
|
18469
|
+
MAX_STANDALONE_QUEUE = 6;
|
|
18470
|
+
standaloneStopped = { content: "CC \u4EFB\u52A1\u5DF2\u505C\u6B62\u3002", isError: true };
|
|
18013
18471
|
CC_ASK_TIMEOUT_MS = 9e5;
|
|
18014
18472
|
ccAskTimeoutMs = () => {
|
|
18015
18473
|
const v = Number(process.env.CC_ASK_TIMEOUT_MS);
|
|
@@ -18018,13 +18476,15 @@ var init_cc_ask = __esm({
|
|
|
18018
18476
|
};
|
|
18019
18477
|
registry.register({
|
|
18020
18478
|
name: "cc_ask",
|
|
18021
|
-
description: `
|
|
18479
|
+
description: `Send a task to Claude Code. mode=sync (default) waits for the answer; mode=async returns an accepted receipt with jobId once queued. A sync wait timeout (900s by default, CC_ASK_TIMEOUT_MS) returns jobId and the task continues. Use cc_progress({jobId}) to check status or read the answer and cc_stop({jobId}) to explicitly stop that task. Load either tool via ToolSearch if needed. sessionId selects the exact session; target selects desktop:UUID or channel:chatId. Without a selector, discover desktop sessions and channel bindings for workDir. If several differ, choose the session identified by the user's instructions or context, or ask if still ambiguous. With no binding use your own standalone CC session per workDir. newSession=true or resumeLatest=true selects standalone CLI and cannot combine with target/sessionId. Failed handoff never falls back.`,
|
|
18022
18480
|
schema: {
|
|
18023
18481
|
type: "object",
|
|
18024
18482
|
properties: {
|
|
18025
18483
|
prompt: { type: "string", description: "\u7ED9 CC \u7684\u4EFB\u52A1\u6307\u4EE4\uFF08\u9ED8\u8BA4\u8FDB\u5165\u9879\u76EE\u5DF2\u7ED1\u5B9A\u7684\u98DE\u4E66\uFF0F\u5FAE\u4FE1 CC \u5F53\u524D\u4F1A\u8BDD\uFF09" },
|
|
18484
|
+
mode: { type: "string", enum: ["sync", "async"], description: "sync \u7B49\u7B54\u6848\uFF08\u9ED8\u8BA4\uFF09\uFF1Basync \u7B49\u786E\u8BA4\u5165\u961F\u540E\u8FD4\u56DE jobId\u3002" },
|
|
18026
18485
|
workDir: { type: "string", description: "CC \u8DD1\u5728\u54EA\u4E2A\u9879\u76EE\u76EE\u5F55\uFF08\u7EDD\u5BF9\u8DEF\u5F84\uFF09\uFF0C\u4F8B\uFF1A/Users/chongzhang/work/engine7-devui" },
|
|
18027
|
-
target: { type: "string", description: "\u6307\u5B9A desktop:\u4F1A\u8BDDUUID \u6216
|
|
18486
|
+
target: { type: "string", description: "\u6307\u5B9A desktop:\u4F1A\u8BDDUUID\u3001channel:chatId \u6216 remote:\u5DF2\u914D\u7F6E\u7684\u8FDC\u7A0B CC \u522B\u540D" },
|
|
18487
|
+
requestId: { type: "string", description: "\u8FDC\u7A0B\u672A\u786E\u8BA4\u56DE\u6267\u65F6\u91CD\u8BD5\u53EF\u6CBF\u7528\u539F requestId\u3002" },
|
|
18028
18488
|
sessionId: { type: "string", description: "\u7CBE\u786E\u6307\u5B9A CC \u4F1A\u8BDD UUID\uFF1B\u684C\u9762\u987B\u901A\u8FC7 engine7 cc-desktop \u63A5\u5165\uFF0C\u4E0D\u4F1A\u53E6\u5F00\u8FDB\u7A0B\u5199\u5B83\u7684\u5386\u53F2" },
|
|
18029
18489
|
newSession: { type: "boolean", description: "true = \u4F7F\u7528\u72EC\u7ACB CLI \u5F3A\u5236\u5F00\u65B0\u4F1A\u8BDD\uFF0C\u4E0D\u8FDB\u5165\u98DE\u4E66\uFF0F\u5FAE\u4FE1\u7ED1\u5B9A\uFF08\u5FD8\u6389\u4E4B\u524D\u72EC\u7ACB cc_ask \u4E0A\u4E0B\u6587\uFF09" },
|
|
18030
18490
|
resumeLatest: { type: "boolean", description: "true = \u72EC\u7ACB CLI \u63A5\u7EED\u9879\u76EE\u6700\u8FD1\u975E\u6D3B\u8DC3\u4F1A\u8BDD\uFF1B\u9ED8\u8BA4\u4F18\u5148\u8FDB\u5165\u5F53\u524D CC \u7ED1\u5B9A\uFF0C\u65E0\u7ED1\u5B9A\u624D\u63A5\u7EED\u4F60\u81EA\u5DF1\u7684 cc_ask \u4F1A\u8BDD" }
|
|
@@ -18035,6 +18495,8 @@ var init_cc_ask = __esm({
|
|
|
18035
18495
|
const prompt = typeof args.prompt === "string" ? args.prompt.trim() : "";
|
|
18036
18496
|
let workDir = typeof args.workDir === "string" ? args.workDir.trim() : "";
|
|
18037
18497
|
const resumeLatest = args.resumeLatest === true;
|
|
18498
|
+
const mode = args.mode ?? "sync";
|
|
18499
|
+
if (mode !== "sync" && mode !== "async") return { content: "mode \u9700\u8981 sync \u6216 async\u3002", isError: true };
|
|
18038
18500
|
if (!prompt) return { content: "\u9700\u8981 prompt \u53C2\u6570", isError: true };
|
|
18039
18501
|
const depth = Number(process.env.CC_ASK_DEPTH ?? 0);
|
|
18040
18502
|
if (depth >= 1) return { content: `\u9012\u5F52\u4FDD\u62A4\uFF1A\u5F53\u524D\u5BF9\u8BDD\u672C\u8EAB\u662F CC \u9A71\u52A8\u7684\uFF08\u6DF1\u5EA6 ${depth}\uFF09\uFF0C\u4E0D\u518D\u53CD\u5411 cc-ask\u2014\u2014\u8BF7\u76F4\u63A5\u628A\u9700\u6C42\u544A\u8BC9\u5BF9\u65B9\u3002`, isError: true };
|
|
@@ -18044,6 +18506,15 @@ var init_cc_ask = __esm({
|
|
|
18044
18506
|
if ((targetKey || sessionIdArg) && (args.newSession === true || resumeLatest)) {
|
|
18045
18507
|
return { content: "target/sessionId \u6307\u5B9A\u5DF2\u6709\u4F1A\u8BDD\uFF0C\u4E0D\u80FD\u540C\u65F6\u4F7F\u7528\u72EC\u7ACB CLI \u7684 newSession/resumeLatest\u3002", isError: true };
|
|
18046
18508
|
}
|
|
18509
|
+
try {
|
|
18510
|
+
const peer = selectCcPeer(targetKey, !sessionIdArg && args.newSession !== true && !resumeLatest);
|
|
18511
|
+
if (peer) {
|
|
18512
|
+
if (sessionIdArg) return { content: "\u8FDC\u7A0B CC \u4F7F\u7528\u76EE\u6807\u7ED1\u5B9A\u7684\u4F1A\u8BDD\u3002", isError: true };
|
|
18513
|
+
return await askRemoteCc(peer, { ...args, prompt }, ctx, ccAskTimeoutMs(), signal);
|
|
18514
|
+
}
|
|
18515
|
+
} catch (error) {
|
|
18516
|
+
return { content: error.message, isError: true };
|
|
18517
|
+
}
|
|
18047
18518
|
if (args.newSession !== true && !resumeLatest) {
|
|
18048
18519
|
try {
|
|
18049
18520
|
const desktopKey = targetKey.startsWith("desktop:") ? targetKey.slice("desktop:".length) : "";
|
|
@@ -18058,51 +18529,40 @@ ${[...desktops, ...targets].map((t) => `${t.key} \u2192 ${t.workDir}`).join("\n"
|
|
|
18058
18529
|
}
|
|
18059
18530
|
if (desktops[0]) {
|
|
18060
18531
|
const desktop = desktops[0];
|
|
18061
|
-
const timeoutMs2 = ccAskTimeoutMs();
|
|
18062
|
-
const timeout = new AbortController();
|
|
18063
|
-
const timer2 = timeoutMs2 > 0 ? setTimeout(() => timeout.abort(), timeoutMs2) : void 0;
|
|
18064
|
-
const combined = signal ? AbortSignal.any([signal, timeout.signal]) : timeout.signal;
|
|
18065
18532
|
const caller = String(ctx.agentName || registry.config?.name || "agent");
|
|
18066
|
-
|
|
18067
|
-
|
|
18068
|
-
|
|
18069
|
-
|
|
18533
|
+
console.log(`[cc-ask] desktop target=${desktop.key} pid=${desktop.pid} caller=${String(ctx.sessionId || "").slice(0, 8)}`);
|
|
18534
|
+
return await runCcAskJob({
|
|
18535
|
+
ctx,
|
|
18536
|
+
target: desktop,
|
|
18537
|
+
mode,
|
|
18538
|
+
timeoutMs: ccAskTimeoutMs(),
|
|
18539
|
+
signal,
|
|
18540
|
+
stop: (id2) => stopDesktopJob(desktop, id2),
|
|
18541
|
+
run: async (ack, transport) => {
|
|
18542
|
+
const result = await askDesktop(desktop, prompt, caller, transport, ack);
|
|
18543
|
+
return { content: `[CC @ ${path17.basename(desktop.workDir)}] ${result.text}
|
|
18070
18544
|
\uFF08\u684C\u9762\u4F1A\u8BDD ${result.sessionId}\uFF0C\u5DF2\u5728\u6253\u5F00\u7684\u63A7\u5236\u53F0\u5185\u6267\u884C\uFF09`, isError: result.isError };
|
|
18071
|
-
|
|
18072
|
-
|
|
18073
|
-
throw error;
|
|
18074
|
-
} finally {
|
|
18075
|
-
clearTimeout(timer2);
|
|
18076
|
-
}
|
|
18545
|
+
}
|
|
18546
|
+
});
|
|
18077
18547
|
}
|
|
18078
|
-
const
|
|
18079
|
-
if (
|
|
18080
|
-
const timeoutMs2 = ccAskTimeoutMs();
|
|
18081
|
-
const timeout = new AbortController();
|
|
18082
|
-
const timer2 = timeoutMs2 > 0 ? setTimeout(() => timeout.abort(), timeoutMs2) : void 0;
|
|
18083
|
-
const combined = signal ? AbortSignal.any([signal, timeout.signal]) : timeout.signal;
|
|
18548
|
+
const target2 = targets[0];
|
|
18549
|
+
if (target2) {
|
|
18084
18550
|
const caller = String(ctx.agentName || registry.config?.mem7?.agentName || registry.config?.everos?.agentName || "agent");
|
|
18085
18551
|
const source = `${caller} @${ctx.channel || "unknown"} (${String(ctx.sessionId || "unknown").slice(0, 8)})`;
|
|
18086
|
-
console.log(`[cc-ask] handoff target=${
|
|
18087
|
-
|
|
18088
|
-
|
|
18089
|
-
|
|
18090
|
-
|
|
18091
|
-
|
|
18092
|
-
|
|
18093
|
-
|
|
18094
|
-
|
|
18095
|
-
|
|
18096
|
-
|
|
18097
|
-
|
|
18098
|
-
}
|
|
18099
|
-
return { content: stopped ? "CC \u7ED1\u5B9A\u8BF7\u6C42\u5DF2\u53D6\u6D88\uFF0C\u5E76\u5DF2\u901A\u77E5 CC \u505C\u6B62\u5F53\u524D\u4EFB\u52A1\u3002" : "CC \u7ED1\u5B9A\u8BF7\u6C42\u5DF2\u53D6\u6D88\uFF08\u505C\u6B62\u901A\u77E5\u672A\u9001\u8FBE\u2014\u2014\u5F53\u524D\u56DE\u5408\u53EF\u80FD\u4ECD\u5728\u7EE7\u7EED\uFF0C\u53EF\u7528 cc_progress \u67E5\u770B\u8FDB\u5C55\uFF09\u3002", isError: true };
|
|
18552
|
+
console.log(`[cc-ask] handoff target=${target2.key} resume=${target2.sessionId?.slice(0, 8) ?? "new"} hubPid=${target2.endpoint.pid} caller=${String(ctx.sessionId ?? "").slice(0, 8)}`);
|
|
18553
|
+
return await runCcAskJob({
|
|
18554
|
+
ctx,
|
|
18555
|
+
target: target2,
|
|
18556
|
+
mode,
|
|
18557
|
+
timeoutMs: ccAskTimeoutMs(),
|
|
18558
|
+
signal,
|
|
18559
|
+
stop: (id2) => stopBoundCc(target2, id2),
|
|
18560
|
+
run: async (ack, transport) => {
|
|
18561
|
+
const result = await askBoundCc(target2, prompt, source, transport, ack);
|
|
18562
|
+
return { content: `[CC @ ${path17.basename(target2.workDir)}] ${result.text}
|
|
18563
|
+
\uFF08\u5DF2\u8FDB\u5165 ${target2.key} \u7684 CC \u7ED1\u5B9A\u4F1A\u8BDD ${result.sessionId?.slice(0, 8) ?? "new"}\uFF0C\u98DE\u4E66\uFF0F\u5FAE\u4FE1\u540E\u7EED\u5BF9\u8BDD\u5171\u4EAB\u8FD9\u6BB5\u4E0A\u4E0B\u6587\uFF09`, isError: result.isError };
|
|
18100
18564
|
}
|
|
18101
|
-
|
|
18102
|
-
throw error;
|
|
18103
|
-
} finally {
|
|
18104
|
-
clearTimeout(timer2);
|
|
18105
|
-
}
|
|
18565
|
+
});
|
|
18106
18566
|
}
|
|
18107
18567
|
if (targetKey || sessionIdArg) return { content: `\u6CA1\u6709\u627E\u5230\u5F53\u524D\u63A5\u5165\u7684 CC \u76EE\u6807 ${targetKey || sessionIdArg}\u3002\u684C\u9762\u4F1A\u8BDD\u9700\u7528 engine7 cc-desktop --resume <UUID> \u6253\u5F00\u3002`, isError: true };
|
|
18108
18568
|
if (ccDriverRouter.hub?.bindings.some((b) => !workDir || b.workDir === workDir)) {
|
|
@@ -18120,107 +18580,88 @@ ${[...desktops, ...targets].map((t) => `${t.key} \u2192 ${t.workDir}`).join("\n"
|
|
|
18120
18580
|
${dirs.join("\n")}`, isError: true };
|
|
18121
18581
|
}
|
|
18122
18582
|
if (!workDir) {
|
|
18123
|
-
const recent = listCcProjects().
|
|
18124
|
-
if (recent
|
|
18125
|
-
workDir = recent
|
|
18583
|
+
const recent = listCcProjects().find((project) => project.workDir && existsSync17(project.workDir))?.workDir;
|
|
18584
|
+
if (!recent) return { content: "\u672C\u673A\u6CA1\u6709 CC \u4F1A\u8BDD\u8BB0\u5F55\uFF0C\u65E0\u6CD5\u63A8\u65AD\u5DE5\u4F5C\u76EE\u5F55\u2014\u2014\u8BF7\u6307\u5B9A workDir", isError: true };
|
|
18585
|
+
workDir = recent;
|
|
18126
18586
|
}
|
|
18127
18587
|
}
|
|
18128
|
-
|
|
18129
|
-
let store = null;
|
|
18130
|
-
if (stateDir) {
|
|
18131
|
-
try {
|
|
18132
|
-
store = new CcSessionMapStore(stateDir, path17.join("agents", "cc-ask", "session-map.json"));
|
|
18133
|
-
} catch {
|
|
18134
|
-
store = null;
|
|
18135
|
-
}
|
|
18136
|
-
}
|
|
18137
|
-
const mapKey = `ask:${String(ctx.sessionId ?? ctx.channel ?? "anon")}@${workDir}`;
|
|
18138
|
-
let sessionId;
|
|
18139
|
-
let resumedFrom = "";
|
|
18140
|
-
const forceNew = args.newSession === true;
|
|
18141
|
-
if (forceNew) {
|
|
18142
|
-
store?.clear(mapKey);
|
|
18143
|
-
} else if (resumeLatest) {
|
|
18144
|
-
const sessions2 = listProjectSessions(workDir, void 0, 3);
|
|
18145
|
-
const candidate = sessions2.find((s) => s.messageCount > 0);
|
|
18146
|
-
if (!candidate) return { content: `${workDir} \u4E0B\u6CA1\u6709\u53EF\u63A5\u7EED\u7684 CC \u4F1A\u8BDD\uFF08\u53BB\u6389 resumeLatest \u5F00\u65B0\u4F1A\u8BDD\uFF09`, isError: true };
|
|
18147
|
-
if (await checkActive(candidate.file, 300)) {
|
|
18148
|
-
return { content: `\u8BE5\u9879\u76EE\u6700\u65B0\u4F1A\u8BDD\u6B63\u88AB\u522B\u5904\u9A71\u52A8\uFF08\u25CFlive\uFF1A\u63A7\u5236\u53F0\u6216\u98DE\u4E66 hub\uFF09\u2014\u2014\u7B49\u5B83\u7A7A\u95F2\u518D\u63A5\u624B\uFF0C\u6216\u53BB\u6389 resumeLatest \u5F00\u65B0\u4F1A\u8BDD\u3002`, isError: true };
|
|
18149
|
-
}
|
|
18150
|
-
sessionId = candidate.id;
|
|
18151
|
-
resumedFrom = "latest";
|
|
18152
|
-
} else {
|
|
18153
|
-
const mapped = store?.get(mapKey);
|
|
18154
|
-
if (mapped?.sessionId) {
|
|
18155
|
-
const hit = listProjectSessions(workDir, void 0, 30).find((s) => s.id === mapped.sessionId);
|
|
18156
|
-
if (hit) {
|
|
18157
|
-
if (await isActiveConfirmed(hit.file, 2e3)) {
|
|
18158
|
-
return { content: `\u4F60\u4E0A\u6B21\u7684 CC \u4F1A\u8BDD\uFF08${mapped.sessionId.slice(0, 8)}\uFF09\u6B63\u88AB\u522B\u5904\u9A71\u52A8\uFF08\u25CFlive\uFF1A\u63A7\u5236\u53F0\u6216\u98DE\u4E66 hub\uFF09\u2014\u2014\u7B49\u5B83\u7A7A\u95F2\u518D cc_ask\uFF0C\u6216 newSession=true \u5F00\u65B0\u4F1A\u8BDD\u3002`, isError: true };
|
|
18159
|
-
}
|
|
18160
|
-
sessionId = mapped.sessionId;
|
|
18161
|
-
resumedFrom = "own";
|
|
18162
|
-
}
|
|
18163
|
-
}
|
|
18164
|
-
}
|
|
18165
|
-
if (!sessionId) {
|
|
18166
|
-
const sessions2 = listProjectSessions(workDir, void 0, 1);
|
|
18167
|
-
const latest = sessions2[0];
|
|
18168
|
-
if (latest && await checkActive(latest.file, 300)) {
|
|
18169
|
-
return { content: `\u8BE5\u9879\u76EE\u6709\u4F1A\u8BDD\u6B63\u88AB\u522B\u5904\u9A71\u52A8\uFF08\u25CFlive\uFF09\u2014\u2014\u4E3A\u907F\u514D CC \u62FF\u7740\u8FC7\u65F6\u4E0A\u4E0B\u6587\u5E72\u6D3B\uFF0C\u7A0D\u7B49\u5B83\u7A7A\u95F2\uFF0C\u6216\u6307\u5B9A\u5176\u4ED6 workDir\u3002`, isError: true };
|
|
18170
|
-
}
|
|
18171
|
-
}
|
|
18172
|
-
if (sessionId && (nativeSessionOwners(sessionId).length || (await findDesktopTargets(workDir, sessionId)).length)) {
|
|
18173
|
-
return { content: "\u8BE5 CC \u4F1A\u8BDD\u4ECD\u7531\u684C\u9762\u8FDB\u7A0B\u6301\u6709\uFF1B\u8BF7\u7528 sessionId \u6295\u9012\u5230 cc-desktop\uFF0C\u4E0D\u80FD\u53E6\u8D77\u72EC\u7ACB CLI \u5199\u5165\u3002", isError: true };
|
|
18174
|
-
}
|
|
18175
|
-
const timeoutMs = ccAskTimeoutMs();
|
|
18176
|
-
const timeoutText = timeoutMs > 0 ? `CC \u8D85\u65F6\uFF08>${Math.round(timeoutMs / 1e3)}s\uFF09\u88AB\u4E2D\u65AD\u2014\u2014\u4E0D\u662F\u88AB\u8C01\u6253\u65AD\uFF0C\u662F\u4EFB\u52A1\u8D85\u51FA cc_ask \u7684\u540C\u6B65\u7B49\u5F85\u4E0A\u9650\u3002\u628A\u4EFB\u52A1\u62C6\u5C0F\u518D\u95EE\uFF0C\u6216\u8D70\u6D88\u606F\u6E20\u9053\u5F02\u6B65\u6D3E\u7ED9 CC \u540E\u7528 cc_progress \u770B\u8FDB\u5C55\u3002` : "CC \u8BF7\u6C42\u5DF2\u53D6\u6D88\uFF08\u65E0\u8D85\u65F6\u4E0A\u9650\u6A21\u5F0F\u4E0B\u7531\u5916\u90E8\u4E2D\u65AD\uFF09\u3002";
|
|
18177
|
-
const { query } = await loadOptionalModule("cc-runtime");
|
|
18178
|
-
const ac = new AbortController();
|
|
18179
|
-
signal?.addEventListener("abort", () => ac.abort(), { once: true });
|
|
18180
|
-
const timer = timeoutMs > 0 ? setTimeout(() => ac.abort(), timeoutMs) : void 0;
|
|
18181
|
-
let resultText = "";
|
|
18182
|
-
let newSessionId;
|
|
18183
|
-
let isError = false;
|
|
18588
|
+
let directory2;
|
|
18184
18589
|
try {
|
|
18185
|
-
|
|
18186
|
-
|
|
18187
|
-
|
|
18188
|
-
|
|
18189
|
-
cwd: workDir,
|
|
18190
|
-
permissionMode: "bypassPermissions",
|
|
18191
|
-
...sessionId ? { resume: sessionId } : {},
|
|
18192
|
-
env: { CC_ASK_DEPTH: "1" }
|
|
18193
|
-
}
|
|
18194
|
-
});
|
|
18195
|
-
for await (const msg2 of stream) {
|
|
18196
|
-
if (msg2.parent_tool_use_id) continue;
|
|
18197
|
-
if (msg2.type === "result") {
|
|
18198
|
-
const r = msg2;
|
|
18199
|
-
resultText = typeof r.result === "string" ? r.result : "";
|
|
18200
|
-
isError = r.is_error === true;
|
|
18201
|
-
if (r.session_id) newSessionId = r.session_id;
|
|
18202
|
-
}
|
|
18203
|
-
}
|
|
18204
|
-
} catch (err) {
|
|
18205
|
-
clearTimeout(timer);
|
|
18206
|
-
if (ac.signal.aborted) return { content: timeoutText, isError: true };
|
|
18207
|
-
return { content: `CC \u9A71\u52A8\u5931\u8D25\uFF1A${err?.message ?? err}`, isError: true };
|
|
18208
|
-
}
|
|
18209
|
-
clearTimeout(timer);
|
|
18210
|
-
if (ac.signal.aborted) {
|
|
18211
|
-
return { content: timeoutText, isError: true };
|
|
18590
|
+
directory2 = realpathSync12(workDir);
|
|
18591
|
+
if (!statSync7(directory2).isDirectory()) throw new Error("not a directory");
|
|
18592
|
+
} catch {
|
|
18593
|
+
return { content: `CC \u5DE5\u4F5C\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${workDir}`, isError: true };
|
|
18212
18594
|
}
|
|
18213
|
-
const
|
|
18214
|
-
|
|
18215
|
-
|
|
18216
|
-
|
|
18217
|
-
|
|
18218
|
-
|
|
18595
|
+
const controller = new AbortController();
|
|
18596
|
+
const target = { key: directory2, workDir, sessionId: null };
|
|
18597
|
+
let queued;
|
|
18598
|
+
return runCcAskJob({
|
|
18599
|
+
ctx,
|
|
18600
|
+
target,
|
|
18601
|
+
mode,
|
|
18602
|
+
timeoutMs: ccAskTimeoutMs(),
|
|
18603
|
+
signal,
|
|
18604
|
+
stop: () => {
|
|
18605
|
+
controller.abort();
|
|
18606
|
+
const queue = standaloneQueues.get(directory2);
|
|
18607
|
+
const index = queue?.indexOf(queued) ?? -1;
|
|
18608
|
+
if (index > 0) queue.splice(index, 1)[0].finish(standaloneStopped);
|
|
18609
|
+
return index >= 0;
|
|
18610
|
+
},
|
|
18611
|
+
run: async (ack) => {
|
|
18612
|
+
const queue = standaloneQueues.get(directory2) ?? [];
|
|
18613
|
+
if (queue.length >= MAX_STANDALONE_QUEUE) throw new Error("CC \u9879\u76EE\u961F\u5217\u5DF2\u6EE1\u3002");
|
|
18614
|
+
const pending = new Promise((finish, reject) => {
|
|
18615
|
+
queued = { finish, run: async () => {
|
|
18616
|
+
try {
|
|
18617
|
+
finish(await runStandalone(args, ctx, prompt, workDir, resumeLatest, controller, (id2) => {
|
|
18618
|
+
target.sessionId = id2;
|
|
18619
|
+
}));
|
|
18620
|
+
} catch (error) {
|
|
18621
|
+
reject(error);
|
|
18622
|
+
}
|
|
18623
|
+
} };
|
|
18624
|
+
queue.push(queued);
|
|
18625
|
+
});
|
|
18626
|
+
ack.onAccepted();
|
|
18627
|
+
if (queue.length === 1) {
|
|
18628
|
+
standaloneQueues.set(directory2, queue);
|
|
18629
|
+
void Promise.resolve().then(() => drainStandalone(directory2, queue));
|
|
18630
|
+
}
|
|
18631
|
+
return pending;
|
|
18219
18632
|
}
|
|
18633
|
+
});
|
|
18634
|
+
}
|
|
18635
|
+
});
|
|
18636
|
+
registry.register({
|
|
18637
|
+
name: "cc_stop",
|
|
18638
|
+
description: "Explicitly stop one CC task from a cc_ask receipt by jobId. Removes that task if queued or interrupts it if running.",
|
|
18639
|
+
schema: {
|
|
18640
|
+
type: "object",
|
|
18641
|
+
properties: { jobId: { type: "string", description: "Job ID from the cc_ask receipt." } },
|
|
18642
|
+
required: ["jobId"]
|
|
18643
|
+
},
|
|
18644
|
+
handler: async (args, ctx, signal) => await observeRemoteCc("stop", args, ctx, signal) ?? stopCcAskJob(args.jobId, ctx)
|
|
18645
|
+
});
|
|
18646
|
+
registry.register({
|
|
18647
|
+
name: "cc_new",
|
|
18648
|
+
description: "Start a new conversation at the configured remote CC binding. The next CC message starts the new session.",
|
|
18649
|
+
schema: {
|
|
18650
|
+
type: "object",
|
|
18651
|
+
properties: {
|
|
18652
|
+
target: { type: "string", description: "remote:\u5DF2\u914D\u7F6E\u7684 CC \u522B\u540D\u3002\u7701\u7565\u4F7F\u7528\u9ED8\u8BA4\u76EE\u6807\u3002" },
|
|
18653
|
+
requestId: { type: "string", description: "\u672A\u786E\u8BA4\u56DE\u6267\u65F6\u91CD\u8BD5\u53EF\u4EE5\u6CBF\u7528\u539F requestId\u3002" }
|
|
18654
|
+
},
|
|
18655
|
+
required: []
|
|
18656
|
+
},
|
|
18657
|
+
handler: async (args, ctx, signal) => {
|
|
18658
|
+
try {
|
|
18659
|
+
const peer = selectCcPeer(args.target);
|
|
18660
|
+
if (peer) return await newRemoteCc(peer, args, ctx, signal);
|
|
18661
|
+
return { content: "\u672C\u673A\u7ED1\u5B9A\u4F1A\u8BDD\u53EF\u4EE5\u5728\u5BF9\u5E94\u804A\u5929\u8F93\u5165 /cc-new\u3002", isError: true };
|
|
18662
|
+
} catch (error) {
|
|
18663
|
+
return { content: error.message, isError: true };
|
|
18220
18664
|
}
|
|
18221
|
-
const tail = resumedFrom === "own" ? `\uFF08\u63A5\u7EED\u4F60\u4E0A\u6B21\u7684\u4F1A\u8BDD ${newSessionId?.slice(0, 8)}\uFF0C\u4E4B\u524D cc_ask \u5F3A\u8C03\u8FC7\u7684\u8981\u6C42\u90FD\u5728\u4E0A\u4E0B\u6587\u91CC\uFF09` : newSessionId ? `\uFF08${resumedFrom === "latest" ? "\u63A5\u7EED\u9879\u76EE\u6700\u8FD1\u4F1A\u8BDD" : "\u65B0\u4F1A\u8BDD"} ${newSessionId.slice(0, 8)}\uFF0C\u5DF2\u8BB0\u4F4F\u2014\u2014\u540E\u7EED cc_ask \u81EA\u52A8\u63A5\u7EED\uFF1BnewSession=true \u53EF\u91CD\u5F00\uFF09` : "";
|
|
18222
|
-
return { content: `[CC @ ${workDir.split("/").pop()}] ${text2}${tail ? `
|
|
18223
|
-
${tail}` : ""}`, isError };
|
|
18224
18665
|
}
|
|
18225
18666
|
});
|
|
18226
18667
|
}
|
|
@@ -18257,24 +18698,24 @@ CREATE INDEX idx_calendar_dispatch_scope ON calendar_dispatches(scope_id,event_i
|
|
|
18257
18698
|
// src/continuity/sqlite-write-capture.ts
|
|
18258
18699
|
function installSQLiteWriteCapture(db2, source) {
|
|
18259
18700
|
if (db2.isTransaction) throw new Error("REPLICATION_TRANSACTION_ALREADY_OPEN");
|
|
18260
|
-
const
|
|
18701
|
+
const exec4 = db2.exec, prepare = db2.prepare;
|
|
18261
18702
|
let active, failed = false, closed = false, reading = false;
|
|
18262
|
-
let
|
|
18703
|
+
let direct2;
|
|
18263
18704
|
const check = () => {
|
|
18264
18705
|
if (closed) throw new Error("REPLICATION_TRANSACTION_CLOSED");
|
|
18265
|
-
|
|
18706
|
+
direct2?.assertOpen();
|
|
18266
18707
|
};
|
|
18267
18708
|
const wrappedExec = function(sql) {
|
|
18268
18709
|
check();
|
|
18269
18710
|
const command2 = sql.trim().replace(/;$/, "").trim().toUpperCase();
|
|
18270
18711
|
if (command2 === "BEGIN IMMEDIATE" || command2 === "BEGIN IMMEDIATE TRANSACTION") {
|
|
18271
|
-
|
|
18712
|
+
exec4.call(db2, sql);
|
|
18272
18713
|
try {
|
|
18273
18714
|
active = source.beginCapture();
|
|
18274
18715
|
failed = false;
|
|
18275
18716
|
reading = false;
|
|
18276
18717
|
} catch (error) {
|
|
18277
|
-
|
|
18718
|
+
exec4.call(db2, "ROLLBACK");
|
|
18278
18719
|
throw error;
|
|
18279
18720
|
}
|
|
18280
18721
|
return;
|
|
@@ -18283,13 +18724,13 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
18283
18724
|
if (failed) throw new Error("REPLICATION_TRANSACTION_FAILED");
|
|
18284
18725
|
if (!active) {
|
|
18285
18726
|
if (!reading) throw new Error("REPLICATION_SQL_FORM_UNSUPPORTED");
|
|
18286
|
-
|
|
18727
|
+
exec4.call(db2, sql);
|
|
18287
18728
|
reading = false;
|
|
18288
18729
|
return;
|
|
18289
18730
|
}
|
|
18290
18731
|
try {
|
|
18291
18732
|
source.appendCapture(active);
|
|
18292
|
-
|
|
18733
|
+
exec4.call(db2, sql);
|
|
18293
18734
|
source.endCapture(active);
|
|
18294
18735
|
active = void 0;
|
|
18295
18736
|
} catch (error) {
|
|
@@ -18300,7 +18741,7 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
18300
18741
|
}
|
|
18301
18742
|
if (command2 === "ROLLBACK" || command2 === "ROLLBACK TRANSACTION") {
|
|
18302
18743
|
try {
|
|
18303
|
-
|
|
18744
|
+
exec4.call(db2, sql);
|
|
18304
18745
|
} finally {
|
|
18305
18746
|
if (!db2.isTransaction) reading = false;
|
|
18306
18747
|
if (active && !db2.isTransaction) {
|
|
@@ -18312,12 +18753,12 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
18312
18753
|
return;
|
|
18313
18754
|
}
|
|
18314
18755
|
if (command2 === "BEGIN" || command2 === "BEGIN TRANSACTION" || command2 === "BEGIN DEFERRED" || command2 === "BEGIN DEFERRED TRANSACTION") {
|
|
18315
|
-
|
|
18756
|
+
exec4.call(db2, sql);
|
|
18316
18757
|
reading = true;
|
|
18317
18758
|
return;
|
|
18318
18759
|
}
|
|
18319
18760
|
if (/^(?:SAVEPOINT|RELEASE(?: SAVEPOINT)?|ROLLBACK TO(?: SAVEPOINT)?) [A-Z_][A-Z0-9_]*$/.test(command2) && db2.isTransaction && !failed) {
|
|
18320
|
-
|
|
18761
|
+
exec4.call(db2, sql);
|
|
18321
18762
|
return;
|
|
18322
18763
|
}
|
|
18323
18764
|
throw new Error("REPLICATION_SQL_FORM_UNSUPPORTED");
|
|
@@ -18333,10 +18774,10 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
18333
18774
|
db2.prepare = checkedPrepare;
|
|
18334
18775
|
const transaction = (operation) => {
|
|
18335
18776
|
check();
|
|
18336
|
-
if (db2.isTransaction) return
|
|
18777
|
+
if (db2.isTransaction) return direct2.scope(operation);
|
|
18337
18778
|
db2.exec("BEGIN IMMEDIATE");
|
|
18338
18779
|
try {
|
|
18339
|
-
const result =
|
|
18780
|
+
const result = direct2.scope(operation);
|
|
18340
18781
|
if (result && typeof result.then === "function") throw new Error("REPLICATION_ASYNC_TRANSACTION");
|
|
18341
18782
|
db2.exec("COMMIT");
|
|
18342
18783
|
return result;
|
|
@@ -18345,21 +18786,21 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
18345
18786
|
throw error;
|
|
18346
18787
|
}
|
|
18347
18788
|
};
|
|
18348
|
-
|
|
18789
|
+
direct2 = installAutocommitCapture(db2, transaction);
|
|
18349
18790
|
return {
|
|
18350
18791
|
assertOpen: check,
|
|
18351
|
-
scope: (operation) =>
|
|
18792
|
+
scope: (operation) => direct2.scope(operation),
|
|
18352
18793
|
transaction,
|
|
18353
18794
|
close() {
|
|
18354
18795
|
if (closed) return;
|
|
18355
18796
|
if (active) {
|
|
18356
|
-
if (db2.isTransaction)
|
|
18797
|
+
if (db2.isTransaction) exec4.call(db2, "ROLLBACK");
|
|
18357
18798
|
source.endCapture(active);
|
|
18358
18799
|
active = void 0;
|
|
18359
18800
|
}
|
|
18360
|
-
|
|
18801
|
+
direct2.close();
|
|
18361
18802
|
db2.prepare = prepare;
|
|
18362
|
-
db2.exec =
|
|
18803
|
+
db2.exec = exec4;
|
|
18363
18804
|
closed = true;
|
|
18364
18805
|
}
|
|
18365
18806
|
};
|
|
@@ -18763,14 +19204,14 @@ var init_notification_state = __esm({
|
|
|
18763
19204
|
|
|
18764
19205
|
// src/travel/chunk-store.ts
|
|
18765
19206
|
import { gunzipSync as gunzipSync2, gzip as gzip2 } from "node:zlib";
|
|
18766
|
-
import { promisify as
|
|
19207
|
+
import { promisify as promisify5 } from "node:util";
|
|
18767
19208
|
var CHUNK_BYTES2, DATABASE_CHUNK_BYTES, compress2;
|
|
18768
19209
|
var init_chunk_store = __esm({
|
|
18769
19210
|
"src/travel/chunk-store.ts"() {
|
|
18770
19211
|
"use strict";
|
|
18771
19212
|
CHUNK_BYTES2 = 4 * 1024 * 1024;
|
|
18772
19213
|
DATABASE_CHUNK_BYTES = 64 * 1024;
|
|
18773
|
-
compress2 =
|
|
19214
|
+
compress2 = promisify5(gzip2);
|
|
18774
19215
|
}
|
|
18775
19216
|
});
|
|
18776
19217
|
|
|
@@ -18871,7 +19312,7 @@ var init_host_turn = __esm({
|
|
|
18871
19312
|
|
|
18872
19313
|
// src/tools/task-manager.ts
|
|
18873
19314
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
18874
|
-
import { spawn } from "node:child_process";
|
|
19315
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
18875
19316
|
import * as fs15 from "node:fs";
|
|
18876
19317
|
import * as path19 from "node:path";
|
|
18877
19318
|
function generateTaskId(type = "local_bash") {
|
|
@@ -19124,7 +19565,7 @@ function spawnBackgroundTask(opts) {
|
|
|
19124
19565
|
const outputPath = initTaskOutput(taskId);
|
|
19125
19566
|
const { shell, args: shellArgs } = findShell();
|
|
19126
19567
|
const outputFd = fs15.openSync(outputPath, "w");
|
|
19127
|
-
const child =
|
|
19568
|
+
const child = spawn2(shell, [...shellArgs, opts.command], {
|
|
19128
19569
|
cwd: opts.cwd,
|
|
19129
19570
|
env: opts.env || process.env,
|
|
19130
19571
|
stdio: ["ignore", outputFd, outputFd],
|
|
@@ -19188,10 +19629,10 @@ function trackBackgroundTask(opts, child, outputPath, startTime, taskId) {
|
|
|
19188
19629
|
});
|
|
19189
19630
|
}, SIZE_WATCHDOG_INTERVAL_MS);
|
|
19190
19631
|
sizeWatchdog.unref();
|
|
19191
|
-
let
|
|
19632
|
+
let finished2 = false;
|
|
19192
19633
|
const finish = (code, sig) => {
|
|
19193
|
-
if (
|
|
19194
|
-
|
|
19634
|
+
if (finished2) return;
|
|
19635
|
+
finished2 = true;
|
|
19195
19636
|
opts.queryAbortSignal?.removeEventListener("abort", onAbort);
|
|
19196
19637
|
clearTimeout(timer);
|
|
19197
19638
|
if (sizeWatchdog) clearInterval(sizeWatchdog);
|
|
@@ -19584,7 +20025,7 @@ __export(BashTool_exports, {
|
|
|
19584
20025
|
findShell: () => findShell,
|
|
19585
20026
|
killChild: () => killChild
|
|
19586
20027
|
});
|
|
19587
|
-
import { spawn as
|
|
20028
|
+
import { spawn as spawn3, execSync } from "node:child_process";
|
|
19588
20029
|
import * as fs16 from "node:fs";
|
|
19589
20030
|
import * as path20 from "node:path";
|
|
19590
20031
|
function isWslBash(p) {
|
|
@@ -19631,7 +20072,7 @@ function findShell() {
|
|
|
19631
20072
|
function killChild(child) {
|
|
19632
20073
|
if (child.pid) {
|
|
19633
20074
|
if (process.platform === "win32") {
|
|
19634
|
-
|
|
20075
|
+
spawn3("taskkill", ["/T", "/F", "/PID", String(child.pid)], {
|
|
19635
20076
|
stdio: "ignore",
|
|
19636
20077
|
detached: true,
|
|
19637
20078
|
windowsHide: true
|
|
@@ -19735,7 +20176,7 @@ For commands that are harder to parse at a glance (piped commands, obscure flags
|
|
|
19735
20176
|
}
|
|
19736
20177
|
return new Promise((resolve47) => {
|
|
19737
20178
|
const { shell, args: shellArgs } = findShell();
|
|
19738
|
-
const child =
|
|
20179
|
+
const child = spawn3(shell, [...shellArgs, command2], {
|
|
19739
20180
|
cwd,
|
|
19740
20181
|
env: sanitizeEnv(process.env),
|
|
19741
20182
|
stdio: ["ignore", outputHandle.fd, outputHandle.fd],
|
|
@@ -20518,13 +20959,15 @@ function beginSkillGate(sessionId) {
|
|
|
20518
20959
|
function isUserChannel(ch) {
|
|
20519
20960
|
return !!ch && USER_CHANNELS.has(ch);
|
|
20520
20961
|
}
|
|
20521
|
-
var USER_CHANNELS, loadedBySession, MAX_TRACKED_SESSIONS;
|
|
20962
|
+
var USER_CHANNELS, SKILL_CHANNELS, loadedBySession, MAX_TRACKED_SESSIONS;
|
|
20522
20963
|
var init_skill_gate = __esm({
|
|
20523
20964
|
"src/skills/skill-gate.ts"() {
|
|
20524
20965
|
"use strict";
|
|
20525
20966
|
init_strip_injected();
|
|
20967
|
+
init_writer();
|
|
20526
20968
|
init_cpu_router_scene();
|
|
20527
20969
|
USER_CHANNELS = /* @__PURE__ */ new Set(["discord", "feishu", "wechat", "telegram", "cli", "console", "voice-chat", "deskBuddy", "ccBridge"]);
|
|
20970
|
+
SKILL_CHANNELS = /* @__PURE__ */ new Set([...USER_CHANNELS, "chan7", "webhook"]);
|
|
20528
20971
|
loadedBySession = /* @__PURE__ */ new Map();
|
|
20529
20972
|
MAX_TRACKED_SESSIONS = 100;
|
|
20530
20973
|
}
|
|
@@ -20598,8 +21041,8 @@ var init_cpu_router_mode_hook = __esm({
|
|
|
20598
21041
|
});
|
|
20599
21042
|
|
|
20600
21043
|
// src/hooks/executor.ts
|
|
20601
|
-
import { spawn as
|
|
20602
|
-
import { randomUUID as
|
|
21044
|
+
import { spawn as spawn4 } from "child_process";
|
|
21045
|
+
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
20603
21046
|
import { basename as basename8 } from "node:path";
|
|
20604
21047
|
function assertHookAuthority(ctx, input) {
|
|
20605
21048
|
const tool = input?.tool_name;
|
|
@@ -20694,7 +21137,7 @@ async function execCommandHook(hook, hookEvent, hookName, jsonInput, signal, hoo
|
|
|
20694
21137
|
assertHostTurnCurrent();
|
|
20695
21138
|
assertHookAuthority(ctx);
|
|
20696
21139
|
beginHostTurnEffect();
|
|
20697
|
-
const child =
|
|
21140
|
+
const child = spawn4(command2, [], {
|
|
20698
21141
|
env: envVars,
|
|
20699
21142
|
cwd: ctx.cwd || ctx.workspace,
|
|
20700
21143
|
shell,
|
|
@@ -20710,7 +21153,7 @@ async function execCommandHook(hook, hookEvent, hookName, jsonInput, signal, hoo
|
|
|
20710
21153
|
if (stopping) return;
|
|
20711
21154
|
stopping = true;
|
|
20712
21155
|
if (isWindows && child.pid) {
|
|
20713
|
-
const killer =
|
|
21156
|
+
const killer = spawn4("taskkill", ["/PID", String(child.pid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
|
|
20714
21157
|
killer.on("error", () => {
|
|
20715
21158
|
try {
|
|
20716
21159
|
child.kill("SIGKILL");
|
|
@@ -20783,7 +21226,7 @@ async function execCommandHook(hook, hookEvent, hookName, jsonInput, signal, hoo
|
|
|
20783
21226
|
return { stdout, stderr, output, status: exitCode, aborted: timedOut || signal.aborted };
|
|
20784
21227
|
}
|
|
20785
21228
|
async function executeOneHook(hook, hookEvent, hookName, hookInput, toolUseID, signal, ctx) {
|
|
20786
|
-
const hookId =
|
|
21229
|
+
const hookId = randomUUID14();
|
|
20787
21230
|
const startMs = Date.now();
|
|
20788
21231
|
let callbackSignal;
|
|
20789
21232
|
assertHostTurnCurrent();
|
|
@@ -20977,14 +21420,14 @@ async function executeHooks(event2, hookInput, ctx, signal, matchQuery) {
|
|
|
20977
21420
|
if (abortSignal.aborted) {
|
|
20978
21421
|
return { additionalContexts: [] };
|
|
20979
21422
|
}
|
|
20980
|
-
const toolUseID =
|
|
21423
|
+
const toolUseID = randomUUID14();
|
|
20981
21424
|
if (event2 !== "UserPromptSubmit") {
|
|
20982
21425
|
return aggregateResults(await Promise.all(matchedHooks.map(({ hook }) => executeOneHook(hook, event2, hookName, hookInput, toolUseID, abortSignal, ctx))));
|
|
20983
21426
|
}
|
|
20984
21427
|
const batchStart = performance.now();
|
|
20985
21428
|
let slowestHook;
|
|
20986
21429
|
let slowestMs = -1;
|
|
20987
|
-
let
|
|
21430
|
+
let finished2 = 0;
|
|
20988
21431
|
let completed = false;
|
|
20989
21432
|
const timing = (data) => {
|
|
20990
21433
|
console.log(`[hook:timing] ${JSON.stringify({ event: event2, runId: toolUseID, sessionId: ctx.sessionId, ...data })}`);
|
|
@@ -21003,7 +21446,7 @@ async function executeHooks(event2, hookInput, ctx, signal, matchQuery) {
|
|
|
21003
21446
|
return result;
|
|
21004
21447
|
} finally {
|
|
21005
21448
|
const durationMs = Math.round(performance.now() - start);
|
|
21006
|
-
|
|
21449
|
+
finished2++;
|
|
21007
21450
|
if (durationMs > slowestMs) {
|
|
21008
21451
|
slowestMs = durationMs;
|
|
21009
21452
|
slowestHook = label;
|
|
@@ -21020,7 +21463,7 @@ async function executeHooks(event2, hookInput, ctx, signal, matchQuery) {
|
|
|
21020
21463
|
slowestHook,
|
|
21021
21464
|
slowestMs,
|
|
21022
21465
|
matched: matchedHooks.length,
|
|
21023
|
-
finished,
|
|
21466
|
+
finished: finished2,
|
|
21024
21467
|
completed,
|
|
21025
21468
|
aborted: abortSignal.aborted
|
|
21026
21469
|
});
|
|
@@ -21609,7 +22052,7 @@ var init_context_dump = __esm({
|
|
|
21609
22052
|
// src/core/steer-mailbox.ts
|
|
21610
22053
|
import * as fs21 from "node:fs";
|
|
21611
22054
|
import * as path25 from "node:path";
|
|
21612
|
-
import { createHash as createHash34, randomUUID as
|
|
22055
|
+
import { createHash as createHash34, randomUUID as randomUUID15 } from "node:crypto";
|
|
21613
22056
|
var MAX_FILE, MAX_PENDING, MAX_PENDING_BYTES, SteerMailbox;
|
|
21614
22057
|
var init_steer_mailbox = __esm({
|
|
21615
22058
|
"src/core/steer-mailbox.ts"() {
|
|
@@ -21661,7 +22104,7 @@ var init_steer_mailbox = __esm({
|
|
|
21661
22104
|
input.channelTarget ?? "",
|
|
21662
22105
|
input.sender ?? "",
|
|
21663
22106
|
input.messageId
|
|
21664
|
-
])).digest("hex") :
|
|
22107
|
+
])).digest("hex") : randomUUID15();
|
|
21665
22108
|
const previous = records.find((r) => r.id === id2);
|
|
21666
22109
|
if (previous) return { accepted: true, duplicate: true, input: previous };
|
|
21667
22110
|
const record = {
|
|
@@ -21733,7 +22176,7 @@ var init_steer_mailbox = __esm({
|
|
|
21733
22176
|
}
|
|
21734
22177
|
if (Buffer.byteLength(data) > MAX_FILE) throw new Error("Steer mailbox full");
|
|
21735
22178
|
fs21.mkdirSync(path25.dirname(this.path), { recursive: true });
|
|
21736
|
-
const temporary = `${this.path}.${
|
|
22179
|
+
const temporary = `${this.path}.${randomUUID15()}.tmp`;
|
|
21737
22180
|
try {
|
|
21738
22181
|
const fd = fs21.openSync(temporary, "wx", 384);
|
|
21739
22182
|
try {
|
|
@@ -23045,7 +23488,9 @@ var init_tool_loading = __esm({
|
|
|
23045
23488
|
["gmail", ["\u90AE\u7BB1", "\u90AE\u4EF6"]],
|
|
23046
23489
|
["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"]],
|
|
23047
23490
|
["cc_ask", ["\u5C0FC", "\u684C\u9762CC", "Claude Code"]],
|
|
23048
|
-
["cc_progress", ["\u5C0FC", "\u684C\u9762CC", "Claude Code"]]
|
|
23491
|
+
["cc_progress", ["\u5C0FC", "\u684C\u9762CC", "Claude Code"]],
|
|
23492
|
+
["cc_new", ["\u5C0FC", "\u684C\u9762CC", "Claude Code", "\u65B0\u5EFA CC \u4F1A\u8BDD"]],
|
|
23493
|
+
["cc_stop", ["\u5C0FC", "\u684C\u9762CC", "Claude Code", "\u505C\u6B62 CC \u4EFB\u52A1"]]
|
|
23049
23494
|
]);
|
|
23050
23495
|
}
|
|
23051
23496
|
});
|
|
@@ -23774,7 +24219,7 @@ var init_context_analyzer = __esm({
|
|
|
23774
24219
|
|
|
23775
24220
|
// src/core/query.ts
|
|
23776
24221
|
import { setTimeout as waitForRetry } from "node:timers/promises";
|
|
23777
|
-
import { randomUUID as
|
|
24222
|
+
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
23778
24223
|
function blockedToolCallsForOverride(calls, override) {
|
|
23779
24224
|
if (!override) return [];
|
|
23780
24225
|
const allowed = new Set(override.map((d) => d.function?.name).filter((n) => !!n));
|
|
@@ -24007,13 +24452,13 @@ var init_query = __esm({
|
|
|
24007
24452
|
this.modelRef = modelRef;
|
|
24008
24453
|
}
|
|
24009
24454
|
setProvider(provider) {
|
|
24010
|
-
for (const
|
|
24455
|
+
for (const owner2 of this.backgroundOwners) owner2.cancelAll();
|
|
24011
24456
|
this.modelGeneration++;
|
|
24012
24457
|
this.provider = provider;
|
|
24013
24458
|
}
|
|
24014
24459
|
/** 热加载:替换 model 字符串(doReloadConfig 切换 primary 后调用) */
|
|
24015
24460
|
setModel(model) {
|
|
24016
|
-
for (const
|
|
24461
|
+
for (const owner2 of this.backgroundOwners) owner2.cancelAll();
|
|
24017
24462
|
this.modelGeneration++;
|
|
24018
24463
|
this.options.model = model;
|
|
24019
24464
|
}
|
|
@@ -24052,7 +24497,7 @@ var init_query = __esm({
|
|
|
24052
24497
|
if (!this.steerQueryId) {
|
|
24053
24498
|
this.stopRequested = false;
|
|
24054
24499
|
this.cancellationReason = null;
|
|
24055
|
-
this.steerQueryId =
|
|
24500
|
+
this.steerQueryId = randomUUID16();
|
|
24056
24501
|
this.steerRoute = { channel: context?.channel ?? "console", channelTarget: context?.channelTarget };
|
|
24057
24502
|
}
|
|
24058
24503
|
const mailbox = this.steerMailbox;
|
|
@@ -24090,7 +24535,7 @@ var init_query = __esm({
|
|
|
24090
24535
|
this.compactConfig.systemOverheadTokens = overhead ?? this.compactConfig.systemOverheadTokens;
|
|
24091
24536
|
}
|
|
24092
24537
|
const activeSystemStable = perTurnSystemStable || this.resolveOpt(this.options.systemStable) || this.resolveOpt(this.options.systemPrompt);
|
|
24093
|
-
for (const m of messages) if ("role" in m && hasMedia(m) && !m.imageInput) m.imageInput = { id:
|
|
24538
|
+
for (const m of messages) if ("role" in m && hasMedia(m) && !m.imageInput) m.imageInput = { id: randomUUID16(), observed: hasImage(m) };
|
|
24094
24539
|
let currentMessages = [...messages];
|
|
24095
24540
|
const stopUserMessages = [];
|
|
24096
24541
|
const stopToolResults = [];
|
|
@@ -24628,13 +25073,13 @@ ${perTurnSystemDynamic}` : deferredHint || perTurnSystemDynamic;
|
|
|
24628
25073
|
yield { type: "error", error: `\u4E0A\u4E0B\u6587\u8D85\u51FA\u6A21\u578B\u7A97\u53E3\uFF08\u8F93\u5165 ${overflow.inputTokens} / \u7A97\u53E3 ${overflow.contextLimit}\uFF09\uFF0C\u9700\u8981\u538B\u7F29\u540E\u624D\u80FD\u7EE7\u7EED\u3002` };
|
|
24629
25074
|
return;
|
|
24630
25075
|
}
|
|
24631
|
-
const
|
|
25076
|
+
const delay4 = Math.min(1e3 * Math.pow(2, streamRetries), 16e3);
|
|
24632
25077
|
if (streamRetries < MAX_STREAM_RETRIES && !ac.signal.aborted) {
|
|
24633
|
-
console.log(`${this.logPrefix} Turn ${turnCount}: stream retry ${streamRetries + 1}/${MAX_STREAM_RETRIES}, delay=${
|
|
25078
|
+
console.log(`${this.logPrefix} Turn ${turnCount}: stream retry ${streamRetries + 1}/${MAX_STREAM_RETRIES}, delay=${delay4}ms`);
|
|
24634
25079
|
yield { type: "status", text: `\u26A0\uFE0F API error, retrying (${streamRetries + 1}/${MAX_STREAM_RETRIES})...` };
|
|
24635
25080
|
this.phase = "tools";
|
|
24636
25081
|
try {
|
|
24637
|
-
await waitForRetry(
|
|
25082
|
+
await waitForRetry(delay4, void 0, { signal: ac.signal });
|
|
24638
25083
|
} catch (error) {
|
|
24639
25084
|
if (!ac.signal.aborted) throw error;
|
|
24640
25085
|
}
|
|
@@ -24749,7 +25194,7 @@ ${perTurnSystemDynamic}` : deferredHint || perTurnSystemDynamic;
|
|
|
24749
25194
|
if (toolCalls.length === 0) {
|
|
24750
25195
|
const carryReply = () => {
|
|
24751
25196
|
if (!this.pendingSteers.some((input) => input.attachment)) return null;
|
|
24752
|
-
const replyId =
|
|
25197
|
+
const replyId = randomUUID16();
|
|
24753
25198
|
const reply = msg.assistant(textContent);
|
|
24754
25199
|
if (turnThinking) reply.reasoning_content = turnThinking;
|
|
24755
25200
|
if (turnThinkingSig) reply.thinking_signature = turnThinkingSig;
|
|
@@ -25092,7 +25537,7 @@ ${perTurnSystemDynamic}` : deferredHint || perTurnSystemDynamic;
|
|
|
25092
25537
|
this.activeRequestModel = null;
|
|
25093
25538
|
this.steerMailbox = new SteerMailbox(stateDir, sessionId);
|
|
25094
25539
|
this.steerRoute = route;
|
|
25095
|
-
this.steerQueryId =
|
|
25540
|
+
this.steerQueryId = randomUUID16();
|
|
25096
25541
|
return this.steerQueryId;
|
|
25097
25542
|
}
|
|
25098
25543
|
clearSteerDelivery(cancel = false) {
|
|
@@ -25139,7 +25584,7 @@ ${perTurnSystemDynamic}` : deferredHint || perTurnSystemDynamic;
|
|
|
25139
25584
|
...metadata4,
|
|
25140
25585
|
text: text2,
|
|
25141
25586
|
queryId: this.steerQueryId,
|
|
25142
|
-
id:
|
|
25587
|
+
id: randomUUID16(),
|
|
25143
25588
|
receivedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
25144
25589
|
status: "received"
|
|
25145
25590
|
} };
|
|
@@ -25456,7 +25901,7 @@ var init_builtInAgents = __esm({
|
|
|
25456
25901
|
});
|
|
25457
25902
|
|
|
25458
25903
|
// src/tools/AgentTool/forkSubagent.ts
|
|
25459
|
-
import { randomUUID as
|
|
25904
|
+
import { randomUUID as randomUUID17 } from "crypto";
|
|
25460
25905
|
function isForkSubagentEnabled() {
|
|
25461
25906
|
return true;
|
|
25462
25907
|
}
|
|
@@ -25495,7 +25940,7 @@ function buildForkedMessages(directive, parentMessages) {
|
|
|
25495
25940
|
type: "tool_result",
|
|
25496
25941
|
tool_use_id: block.id,
|
|
25497
25942
|
content: FORK_PLACEHOLDER_RESULT,
|
|
25498
|
-
id: `toolr_${
|
|
25943
|
+
id: `toolr_${randomUUID17().replace(/-/g, "").slice(0, 24)}`
|
|
25499
25944
|
}));
|
|
25500
25945
|
const toolResultMessage = msg_user(
|
|
25501
25946
|
buildChildMessage(directive),
|
|
@@ -27516,9 +27961,9 @@ async function handleBroadcast(content, summary2, ctx) {
|
|
|
27516
27961
|
async function handleShutdownRequest(targetName, reason, ctx) {
|
|
27517
27962
|
const teamName = getTeamName(ctx);
|
|
27518
27963
|
const senderName = getAgentName(ctx);
|
|
27519
|
-
const
|
|
27964
|
+
const requestId2 = generateRequestId("shutdown", targetName);
|
|
27520
27965
|
const shutdownMessage = createShutdownRequestMessage({
|
|
27521
|
-
requestId,
|
|
27966
|
+
requestId: requestId2,
|
|
27522
27967
|
from: senderName,
|
|
27523
27968
|
reason
|
|
27524
27969
|
});
|
|
@@ -27534,17 +27979,17 @@ async function handleShutdownRequest(targetName, reason, ctx) {
|
|
|
27534
27979
|
return {
|
|
27535
27980
|
content: JSON.stringify({
|
|
27536
27981
|
success: true,
|
|
27537
|
-
message: `Shutdown request sent to ${targetName}. Request ID: ${
|
|
27538
|
-
request_id:
|
|
27982
|
+
message: `Shutdown request sent to ${targetName}. Request ID: ${requestId2}`,
|
|
27983
|
+
request_id: requestId2,
|
|
27539
27984
|
target: targetName
|
|
27540
27985
|
})
|
|
27541
27986
|
};
|
|
27542
27987
|
}
|
|
27543
|
-
async function handleShutdownApproval(
|
|
27988
|
+
async function handleShutdownApproval(requestId2, ctx) {
|
|
27544
27989
|
const teamName = getTeamName(ctx);
|
|
27545
27990
|
const agentName = getAgentName(ctx);
|
|
27546
27991
|
const approvedMessage = createShutdownApprovedMessage({
|
|
27547
|
-
requestId,
|
|
27992
|
+
requestId: requestId2,
|
|
27548
27993
|
from: agentName
|
|
27549
27994
|
});
|
|
27550
27995
|
await writeToMailbox(
|
|
@@ -27563,15 +28008,15 @@ async function handleShutdownApproval(requestId, ctx) {
|
|
|
27563
28008
|
content: JSON.stringify({
|
|
27564
28009
|
success: true,
|
|
27565
28010
|
message: `Shutdown approved. Agent ${agentName} is now exiting.`,
|
|
27566
|
-
request_id:
|
|
28011
|
+
request_id: requestId2
|
|
27567
28012
|
})
|
|
27568
28013
|
};
|
|
27569
28014
|
}
|
|
27570
|
-
async function handleShutdownRejection(
|
|
28015
|
+
async function handleShutdownRejection(requestId2, reason, ctx) {
|
|
27571
28016
|
const teamName = getTeamName(ctx);
|
|
27572
28017
|
const agentName = getAgentName(ctx);
|
|
27573
28018
|
const rejectedMessage = createShutdownRejectedMessage({
|
|
27574
|
-
requestId,
|
|
28019
|
+
requestId: requestId2,
|
|
27575
28020
|
from: agentName,
|
|
27576
28021
|
reason
|
|
27577
28022
|
});
|
|
@@ -27588,7 +28033,7 @@ async function handleShutdownRejection(requestId, reason, ctx) {
|
|
|
27588
28033
|
content: JSON.stringify({
|
|
27589
28034
|
success: true,
|
|
27590
28035
|
message: `Shutdown rejected. Reason: "${reason}". Continuing to work.`,
|
|
27591
|
-
request_id:
|
|
28036
|
+
request_id: requestId2
|
|
27592
28037
|
})
|
|
27593
28038
|
};
|
|
27594
28039
|
}
|
|
@@ -28179,7 +28624,7 @@ function formatSkillsListing(skills, contextWindowTokens) {
|
|
|
28179
28624
|
function buildSkillToolPrompt() {
|
|
28180
28625
|
return `Execute a skill within the main conversation
|
|
28181
28626
|
|
|
28182
|
-
|
|
28627
|
+
Skills provide specialized capabilities and domain knowledge.
|
|
28183
28628
|
|
|
28184
28629
|
When users reference a "slash command" or "/<something>" (e.g., "/commit", "/review-pr"), they are referring to a skill. Use this tool to invoke it.
|
|
28185
28630
|
|
|
@@ -28193,16 +28638,13 @@ How to invoke:
|
|
|
28193
28638
|
|
|
28194
28639
|
Important:
|
|
28195
28640
|
- Available skills are listed in system-reminder messages in the conversation
|
|
28196
|
-
- When a skill matches the user's request, this is a BLOCKING REQUIREMENT: invoke the relevant Skill tool BEFORE generating any other response about the task
|
|
28197
|
-
- NEVER mention a skill without actually calling this tool
|
|
28198
28641
|
- Do not invoke a skill that is already running
|
|
28199
28642
|
- Do not use this tool for built-in CLI commands (like /help, /clear, etc.)
|
|
28200
28643
|
- If you see a <${COMMAND_NAME_TAG}> tag in the current conversation turn, the skill has ALREADY been loaded - follow the instructions directly instead of calling this tool again
|
|
28201
28644
|
`;
|
|
28202
28645
|
}
|
|
28203
|
-
function loadSkillContent(
|
|
28204
|
-
const
|
|
28205
|
-
const skillMdPath = entry?.location ? path29.join(skillsDirPath, entry.location.slice("skills/".length)) : path29.join(skillsDirPath, skillName, "SKILL.md");
|
|
28646
|
+
function loadSkillContent(skillsDir, skill) {
|
|
28647
|
+
const skillMdPath = skill.location ? path29.join(skillsDir, skill.location.slice("skills/".length)) : path29.join(skillsDir, skill.name, "SKILL.md");
|
|
28206
28648
|
if (!fs25.existsSync(skillMdPath)) return null;
|
|
28207
28649
|
const content = fs25.readFileSync(skillMdPath, "utf-8");
|
|
28208
28650
|
const dependencies2 = parseFrontmatter(content)["requires-tools"];
|
|
@@ -28225,6 +28667,13 @@ function registerSkillTool(skillsDir, skills, contextWindowTokens) {
|
|
|
28225
28667
|
skillsDirPath = skillsDir;
|
|
28226
28668
|
cachedSkills = skills;
|
|
28227
28669
|
cachedContextWindowTokens = contextWindowTokens;
|
|
28670
|
+
const groupedSkills = /* @__PURE__ */ new Map();
|
|
28671
|
+
for (const skill of skills) {
|
|
28672
|
+
const parts = skill.location?.split("/");
|
|
28673
|
+
if (!parts || parts[0] !== "skills" || parts.length < 4 || skill.name.includes(":")) continue;
|
|
28674
|
+
const qualifiedName = `${parts[1]}:${skill.name}`;
|
|
28675
|
+
if (!groupedSkills.has(qualifiedName)) groupedSkills.set(qualifiedName, skill);
|
|
28676
|
+
}
|
|
28228
28677
|
const descriptionText = buildSkillToolPrompt();
|
|
28229
28678
|
cachedListing = formatSkillsListing(cachedSkills, contextWindowTokens);
|
|
28230
28679
|
registry.register({
|
|
@@ -28246,12 +28695,12 @@ function registerSkillTool(skillsDir, skills, contextWindowTokens) {
|
|
|
28246
28695
|
return { content: "Invalid skill: empty name", isError: true };
|
|
28247
28696
|
}
|
|
28248
28697
|
const normalizedName = skillName.startsWith("/") ? skillName.substring(1) : skillName;
|
|
28249
|
-
const skill =
|
|
28698
|
+
const skill = skills.find((s) => s.name === normalizedName) ?? groupedSkills.get(normalizedName);
|
|
28250
28699
|
if (!skill) {
|
|
28251
|
-
const available =
|
|
28700
|
+
const available = skills.map((s) => s.name).join(", ");
|
|
28252
28701
|
return { content: `Unknown skill: ${normalizedName}. Available: ${available}`, isError: true };
|
|
28253
28702
|
}
|
|
28254
|
-
const content = loadSkillContent(
|
|
28703
|
+
const content = loadSkillContent(skillsDir, skill);
|
|
28255
28704
|
if (!content) {
|
|
28256
28705
|
return { content: `Skill file not found: ${normalizedName}`, isError: true };
|
|
28257
28706
|
}
|
|
@@ -28269,7 +28718,7 @@ ${loaded.content}
|
|
|
28269
28718
|
const argLine = skillArgs ? `
|
|
28270
28719
|
|
|
28271
28720
|
User arguments: ${skillArgs}` : "";
|
|
28272
|
-
return { content: `Skill "${
|
|
28721
|
+
return { content: `Skill "${skill.name}" loaded.${dependencyContent}
|
|
28273
28722
|
|
|
28274
28723
|
${content.content}${argLine}` };
|
|
28275
28724
|
},
|
|
@@ -28446,7 +28895,7 @@ var init_sources = __esm({
|
|
|
28446
28895
|
// src/installer/skill-install.ts
|
|
28447
28896
|
import * as fs28 from "node:fs";
|
|
28448
28897
|
import * as path32 from "node:path";
|
|
28449
|
-
import { exec as
|
|
28898
|
+
import { exec as exec3 } from "node:child_process";
|
|
28450
28899
|
function rescanSkills() {
|
|
28451
28900
|
const state2 = getSkillToolState();
|
|
28452
28901
|
if (!state2.skillsDirPath) {
|
|
@@ -28548,7 +28997,7 @@ function npmInstallDeps(skillDir) {
|
|
|
28548
28997
|
}
|
|
28549
28998
|
if (!hasDeps) return Promise.resolve(true);
|
|
28550
28999
|
return new Promise((resolve47) => {
|
|
28551
|
-
|
|
29000
|
+
exec3("npm install --omit=dev --no-audit --no-fund --ignore-scripts", {
|
|
28552
29001
|
cwd: skillDir,
|
|
28553
29002
|
timeout: 18e4,
|
|
28554
29003
|
windowsHide: true,
|
|
@@ -29848,6 +30297,18 @@ var init_registry2 = __esm({
|
|
|
29848
30297
|
effect: "hot",
|
|
29849
30298
|
internal: true
|
|
29850
30299
|
},
|
|
30300
|
+
// 1130 Gmail 冷启动:连接即触发 + 每日巡查,新装机默认开。model 为空走 topics.clean.model → extract → mem7 链(免费档自动退回主力模型)
|
|
30301
|
+
{ 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 },
|
|
30302
|
+
{ 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 },
|
|
30303
|
+
{
|
|
30304
|
+
path: "gmailColdstart.patrolHour",
|
|
30305
|
+
type: "number",
|
|
30306
|
+
group: "feature",
|
|
30307
|
+
label: "Gmail \u6BCF\u65E5\u5DE1\u67E5\u6574\u70B9\uFF080-23\uFF09",
|
|
30308
|
+
effect: "hot",
|
|
30309
|
+
internal: true,
|
|
30310
|
+
validate: (value2) => Number.isInteger(value2) && Number(value2) >= 0 && Number(value2) <= 23 ? null : "\u5DE1\u67E5\u6574\u70B9\u987B\u4E3A 0-23"
|
|
30311
|
+
},
|
|
29851
30312
|
{
|
|
29852
30313
|
path: "mem7.turnReadBudgetMs",
|
|
29853
30314
|
type: "number",
|
|
@@ -30560,12 +31021,23 @@ var init_provider = __esm({
|
|
|
30560
31021
|
}
|
|
30561
31022
|
});
|
|
30562
31023
|
|
|
31024
|
+
// src/services/adaptive-proxy.ts
|
|
31025
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
31026
|
+
import { Agent, Client, ProxyAgent, errors } from "undici";
|
|
31027
|
+
var direct;
|
|
31028
|
+
var init_adaptive_proxy = __esm({
|
|
31029
|
+
"src/services/adaptive-proxy.ts"() {
|
|
31030
|
+
"use strict";
|
|
31031
|
+
direct = new Agent();
|
|
31032
|
+
}
|
|
31033
|
+
});
|
|
31034
|
+
|
|
30563
31035
|
// src/services/withRetry.ts
|
|
30564
|
-
import { ProxyAgent } from "undici";
|
|
30565
31036
|
var FIRST_READ_TIMEOUT_MS, NO_PROGRESS_TIMEOUT_MS;
|
|
30566
31037
|
var init_withRetry = __esm({
|
|
30567
31038
|
"src/services/withRetry.ts"() {
|
|
30568
31039
|
"use strict";
|
|
31040
|
+
init_adaptive_proxy();
|
|
30569
31041
|
FIRST_READ_TIMEOUT_MS = parseInt(process.env.API_TIMEOUT_MS || "", 10) || 6e5;
|
|
30570
31042
|
NO_PROGRESS_TIMEOUT_MS = parseInt(process.env.STREAM_NO_PROGRESS_TIMEOUT_MS || "", 10) || 3e5;
|
|
30571
31043
|
}
|
|
@@ -31310,12 +31782,12 @@ var init_wx_query = __esm({
|
|
|
31310
31782
|
handler: async (args, _context) => {
|
|
31311
31783
|
const { findShell: findShell2 } = await Promise.resolve().then(() => (init_BashTool(), BashTool_exports));
|
|
31312
31784
|
const shell = findShell2();
|
|
31313
|
-
const { spawn:
|
|
31785
|
+
const { spawn: spawn9 } = await import("node:child_process");
|
|
31314
31786
|
const cmd = args.command.trim();
|
|
31315
31787
|
const timeout = args.timeout || 12e4;
|
|
31316
31788
|
const fullCmd = `${PYTHON} "${SCRIPT}" ${cmd.replace(/^python3\s+.*wx_query\.py\s*/, "")}`;
|
|
31317
31789
|
return new Promise((resolve47) => {
|
|
31318
|
-
const child =
|
|
31790
|
+
const child = spawn9(shell.shell, [...shell.args, fullCmd], {
|
|
31319
31791
|
timeout,
|
|
31320
31792
|
env: { ...process.env },
|
|
31321
31793
|
windowsHide: true
|
|
@@ -31356,14 +31828,14 @@ var init_wx_query = __esm({
|
|
|
31356
31828
|
init_publication_objects();
|
|
31357
31829
|
init_key_service_store();
|
|
31358
31830
|
import { DatabaseSync as DatabaseSync42 } from "node:sqlite";
|
|
31359
|
-
import { existsSync as existsSync42, readFileSync as readFileSync36, writeFileSync as writeFileSync42, renameSync as renameSync12, realpathSync as
|
|
31831
|
+
import { existsSync as existsSync42, readFileSync as readFileSync36, writeFileSync as writeFileSync42, renameSync as renameSync12, realpathSync as realpathSync31, openSync as openSync21, closeSync as closeSync20 } from "node:fs";
|
|
31360
31832
|
import { join as join73, resolve as resolve46 } from "node:path";
|
|
31361
31833
|
import { fileURLToPath as fileURLToPath9, pathToFileURL as pathToFileURL2 } from "node:url";
|
|
31362
|
-
import { spawn as
|
|
31834
|
+
import { spawn as spawn8 } from "node:child_process";
|
|
31363
31835
|
import { request as request8 } from "node:https";
|
|
31364
31836
|
|
|
31365
31837
|
// src/continuity/pairing-setup.ts
|
|
31366
|
-
import { existsSync as existsSync26, mkdirSync as mkdirSync24, readFileSync as readFileSync26, writeFileSync as writeFileSync23, readdirSync as readdirSync11, cpSync, realpathSync as
|
|
31838
|
+
import { existsSync as existsSync26, mkdirSync as mkdirSync24, readFileSync as readFileSync26, writeFileSync as writeFileSync23, readdirSync as readdirSync11, cpSync, realpathSync as realpathSync14, symlinkSync, lstatSync as lstatSync18 } from "node:fs";
|
|
31367
31839
|
import { join as join46 } from "node:path";
|
|
31368
31840
|
import { homedir as homedir3 } from "node:os";
|
|
31369
31841
|
import { randomBytes as randomBytes4, createHash as createHash36, X509Certificate } from "node:crypto";
|
|
@@ -33003,8 +33475,8 @@ var RuntimePublicationSource = class _RuntimePublicationSource {
|
|
|
33003
33475
|
}
|
|
33004
33476
|
}
|
|
33005
33477
|
if (!same2(this.db.prepare("SELECT sql FROM sqlite_master WHERE type='table' ORDER BY name").all().map((r) => String(r.sql)).sort(), [...schema2].sort()) || this.db.prepare("PRAGMA quick_check").get()?.quick_check !== "ok" || sender.prepare("SELECT sql FROM sqlite_master WHERE type='table'").get()?.sql !== senderSchema || sender.prepare("PRAGMA quick_check").get()?.quick_check !== "ok") throw new Error("RUNTIME_PUBLICATION_RECOVERY_REQUIRED");
|
|
33006
|
-
const binding = this.db.prepare("SELECT profile,layout FROM control WHERE id=1").get(),
|
|
33007
|
-
if (!binding || !
|
|
33478
|
+
const binding = this.db.prepare("SELECT profile,layout FROM control WHERE id=1").get(), owner2 = sender.prepare("SELECT profile,layout FROM sender WHERE id=1").get();
|
|
33479
|
+
if (!binding || !owner2 || !same2(binding, owner2) || binding.profile !== JSON.stringify(this.profile) || binding.layout !== this.layoutDigest)
|
|
33008
33480
|
throw new Error("RUNTIME_PUBLICATION_PROFILE_MISMATCH");
|
|
33009
33481
|
this.identities = [incarnation(this.file), incarnation(this.senderFile)];
|
|
33010
33482
|
const c = this.control(), rows = this.db.prepare("SELECT sequence,digest,parent_digest,state,bytes,object_count,object_cursor FROM publications ORDER BY sequence").all();
|
|
@@ -34211,7 +34683,7 @@ var builtInFeatures = [
|
|
|
34211
34683
|
id: "cc-driver",
|
|
34212
34684
|
name: "CC \u7EC8\u7AEF",
|
|
34213
34685
|
description: "\u9A71\u52A8\u672C\u673A claude CLI\uFF08cc_ask \u4F7F\u5524 / xiaoC_progress\u2192cc_progress \u65C1\u89C2\uFF09\u2014\u2014\u4E0E\u684C\u9762 CC \u540C\u547D\u540D\u7A7A\u95F4",
|
|
34214
|
-
requiredTools: ["cc_progress", "cc_ask"],
|
|
34686
|
+
requiredTools: ["cc_progress", "cc_ask", "cc_stop", "cc_new"],
|
|
34215
34687
|
setup: async () => {
|
|
34216
34688
|
await Promise.resolve().then(() => (init_cc_progress(), cc_progress_exports));
|
|
34217
34689
|
await Promise.resolve().then(() => (init_cc_ask(), cc_ask_exports));
|
|
@@ -34416,9 +34888,9 @@ var archivePairing = (directory2) => {
|
|
|
34416
34888
|
write(join46(directory2, "pairing-environment.json"), { dependenciesSha256: manifest.dependenciesSha256 });
|
|
34417
34889
|
};
|
|
34418
34890
|
async function preparePairingMaterial(input) {
|
|
34419
|
-
const hostStorage = input.hostStorage ?
|
|
34420
|
-
const engineDir =
|
|
34421
|
-
const environmentDir = input.environmentDir ?
|
|
34891
|
+
const hostStorage = input.hostStorage ? realpathSync14(input.hostStorage) : join46(homedir3(), ".engine7-travel-test/hosts");
|
|
34892
|
+
const engineDir = realpathSync14(input.engineDir), stateDir = realpathSync14(input.stateDir), configPath = realpathSync14(input.configPath);
|
|
34893
|
+
const environmentDir = input.environmentDir ? realpathSync14(input.environmentDir) : engineDir;
|
|
34422
34894
|
const pkg = JSON.parse(readFileSync26(join46(environmentDir, "package.json"), "utf8"));
|
|
34423
34895
|
if (input.environmentDir) {
|
|
34424
34896
|
const lock = JSON.parse(readFileSync26(join46(environmentDir, "package-lock.json"), "utf8"));
|
|
@@ -34428,7 +34900,7 @@ async function preparePairingMaterial(input) {
|
|
|
34428
34900
|
const config = JSON.parse(readFileSync26(configPath, "utf8"));
|
|
34429
34901
|
loadSecretsEnvForConfig(configPath);
|
|
34430
34902
|
const parsed = loadConfig(configPath);
|
|
34431
|
-
if (
|
|
34903
|
+
if (realpathSync14(parsed.stateDir) !== stateDir) throw new Error("TRAVEL_PAIRING_IDENTITY");
|
|
34432
34904
|
const companion = JSON.parse(readPrivateFile(join46(stateDir, ".continuity/travel-companion-id.json"), 16384).toString()).companionId;
|
|
34433
34905
|
const directory2 = join46(homedir3(), ".engine7-travel-test", "tasks", input.taskId);
|
|
34434
34906
|
mkdirSync24(join46(homedir3(), ".engine7-travel-test", "tasks"), { recursive: true, mode: 448 });
|
|
@@ -34461,7 +34933,7 @@ async function preparePairingMaterial(input) {
|
|
|
34461
34933
|
const effective = resolveSecrets(config);
|
|
34462
34934
|
const channels = Object.fromEntries(Object.entries(effective.channels ?? {}).filter(([name]) => name !== "emotion"));
|
|
34463
34935
|
for (const [name, block] of Object.entries(channels)) if (block.enabled && !["discord", "feishu", "wechat"].includes(name)) throw new Error("TRAVEL_CHANNEL_NOT_CONTROLLED");
|
|
34464
|
-
const layout = await describeInitialRuntimeLayout(stateDir,
|
|
34936
|
+
const layout = await describeInitialRuntimeLayout(stateDir, realpathSync14(parsed.workspace), "core");
|
|
34465
34937
|
preparePrivateDirectory(directory2);
|
|
34466
34938
|
const identity3 = { tenantId: "self-hosted-" + sha6(homedir3()).slice(0, 20), companionId: companion, seatId: input.taskId };
|
|
34467
34939
|
const tlsDirectory = join46(directory2, "tls");
|
|
@@ -34520,7 +34992,7 @@ async function preparePairingMaterial(input) {
|
|
|
34520
34992
|
identity: identity3,
|
|
34521
34993
|
hostStorage,
|
|
34522
34994
|
stateDir,
|
|
34523
|
-
workspace:
|
|
34995
|
+
workspace: realpathSync14(parsed.workspace),
|
|
34524
34996
|
configPath,
|
|
34525
34997
|
consolePort: parsed.api?.port ?? 16992,
|
|
34526
34998
|
engineDir,
|
|
@@ -34616,7 +35088,7 @@ function finalizePairingMaterial(material, binding) {
|
|
|
34616
35088
|
}
|
|
34617
35089
|
|
|
34618
35090
|
// src/continuity/initial-baseline-worker.ts
|
|
34619
|
-
import { spawn as
|
|
35091
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
34620
35092
|
import { existsSync as existsSync27, writeFileSync as writeFileSync24, unlinkSync as unlinkSync7 } from "node:fs";
|
|
34621
35093
|
import { join as join47 } from "node:path";
|
|
34622
35094
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
@@ -34627,7 +35099,7 @@ async function runInitialBaselineWorker(options, onProgress, assertCurrent) {
|
|
|
34627
35099
|
writeFileSync24(config, JSON.stringify(options), { mode: 384, flag: "wx", flush: true });
|
|
34628
35100
|
try {
|
|
34629
35101
|
await new Promise((done, reject) => {
|
|
34630
|
-
const child =
|
|
35102
|
+
const child = spawn5(process.execPath, [...entry.endsWith(".ts") ? ["--import", "tsx"] : [], entry, "--config", config], { stdio: ["ignore", "pipe", "pipe", "ipc"] });
|
|
34631
35103
|
let failure2, stderr = "";
|
|
34632
35104
|
child.stderr.on("data", (b) => {
|
|
34633
35105
|
stderr = (stderr + b).slice(-8192);
|
|
@@ -34683,11 +35155,11 @@ function publicPairingError(error) {
|
|
|
34683
35155
|
}
|
|
34684
35156
|
|
|
34685
35157
|
// src/continuity/node-main.ts
|
|
34686
|
-
import { readFileSync as readFileSync32, lstatSync as lstatSync29, realpathSync as
|
|
35158
|
+
import { readFileSync as readFileSync32, lstatSync as lstatSync29, realpathSync as realpathSync28 } from "node:fs";
|
|
34687
35159
|
import { DatabaseSync as DatabaseSync37 } from "node:sqlite";
|
|
34688
35160
|
import { isAbsolute as isAbsolute13, resolve as resolve41 } from "node:path";
|
|
34689
35161
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
34690
|
-
import { randomUUID as
|
|
35162
|
+
import { randomUUID as randomUUID24, createHash as createHash50 } from "node:crypto";
|
|
34691
35163
|
|
|
34692
35164
|
// src/continuity/node-agent.ts
|
|
34693
35165
|
import { DatabaseSync as DatabaseSync36 } from "node:sqlite";
|
|
@@ -34718,19 +35190,19 @@ function runtimeEngineConfig(original, stateDir, workspace) {
|
|
|
34718
35190
|
}
|
|
34719
35191
|
|
|
34720
35192
|
// src/continuity/node-agent.ts
|
|
34721
|
-
import { existsSync as existsSync38, lstatSync as lstatSync28, mkdirSync as mkdirSync31, readFileSync as readFileSync31, realpathSync as
|
|
35193
|
+
import { existsSync as existsSync38, lstatSync as lstatSync28, mkdirSync as mkdirSync31, readFileSync as readFileSync31, realpathSync as realpathSync27, writeFileSync as writeFileSync40 } from "node:fs";
|
|
34722
35194
|
import { isAbsolute as isAbsolute12, join as join70, resolve as resolve40 } from "node:path";
|
|
34723
|
-
import { createHash as createHash48, randomUUID as
|
|
35195
|
+
import { createHash as createHash48, randomUUID as randomUUID23 } from "node:crypto";
|
|
34724
35196
|
import { isIP as isIP2 } from "node:net";
|
|
34725
35197
|
|
|
34726
35198
|
// src/continuity/activation.ts
|
|
34727
35199
|
import { DatabaseSync as DatabaseSync23 } from "node:sqlite";
|
|
34728
|
-
import { constants as constants12, existsSync as existsSync32, mkdirSync as mkdirSync25, realpathSync as
|
|
35200
|
+
import { constants as constants12, existsSync as existsSync32, mkdirSync as mkdirSync25, realpathSync as realpathSync18, unlinkSync as unlinkSync12, writeFileSync as writeFileSync29 } from "node:fs";
|
|
34729
35201
|
import { lstat as lstat4, mkdir as mkdir4, readdir as readdir2 } from "node:fs/promises";
|
|
34730
35202
|
|
|
34731
35203
|
// src/continuity/activation-database-worker.ts
|
|
34732
|
-
import { spawn as
|
|
34733
|
-
import { existsSync as existsSync28, writeFileSync as writeFileSync25, unlinkSync as unlinkSync8, statSync as
|
|
35204
|
+
import { spawn as spawn6 } from "node:child_process";
|
|
35205
|
+
import { existsSync as existsSync28, writeFileSync as writeFileSync25, unlinkSync as unlinkSync8, statSync as statSync13 } from "node:fs";
|
|
34734
35206
|
import { join as join49 } from "node:path";
|
|
34735
35207
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
34736
35208
|
|
|
@@ -34786,7 +35258,7 @@ function initializeActivationDatabase(file2, raw) {
|
|
|
34786
35258
|
// src/continuity/activation-database-worker.ts
|
|
34787
35259
|
async function runActivationDatabaseWorker(root, file2, binding, assertCurrent) {
|
|
34788
35260
|
assertCurrent();
|
|
34789
|
-
if (
|
|
35261
|
+
if (statSync13(file2).size < 16 * 1024 * 1024) {
|
|
34790
35262
|
initializeActivationDatabase(file2, binding);
|
|
34791
35263
|
assertCurrent();
|
|
34792
35264
|
return;
|
|
@@ -34796,7 +35268,7 @@ async function runActivationDatabaseWorker(root, file2, binding, assertCurrent)
|
|
|
34796
35268
|
writeFileSync25(config, JSON.stringify({ root, file: file2, binding }), { mode: 384, flag: "wx", flush: true });
|
|
34797
35269
|
try {
|
|
34798
35270
|
await new Promise((done, reject) => {
|
|
34799
|
-
const child =
|
|
35271
|
+
const child = spawn6(process.execPath, [...entry.endsWith(".ts") ? ["--import", "tsx"] : [], entry, "--config", config], { stdio: ["ignore", "pipe", "pipe"] });
|
|
34800
35272
|
let failure2, stderr = "";
|
|
34801
35273
|
child.stderr.on("data", (b) => {
|
|
34802
35274
|
stderr = (stderr + b).slice(-8192);
|
|
@@ -34835,7 +35307,7 @@ init_key_service_store();
|
|
|
34835
35307
|
|
|
34836
35308
|
// src/continuity/generation-integrity.ts
|
|
34837
35309
|
import { createHash as createHash37 } from "node:crypto";
|
|
34838
|
-
import { constants as constants11, closeSync as closeSync17, fstatSync as fstatSync7, lstatSync as lstatSync19, openSync as openSync18, readSync as readSync6, readdirSync as readdirSync12, realpathSync as
|
|
35310
|
+
import { constants as constants11, closeSync as closeSync17, fstatSync as fstatSync7, lstatSync as lstatSync19, openSync as openSync18, readSync as readSync6, readdirSync as readdirSync12, realpathSync as realpathSync15 } from "node:fs";
|
|
34839
35311
|
import { join as join50, resolve as resolve28 } from "node:path";
|
|
34840
35312
|
import { open as open5 } from "node:fs/promises";
|
|
34841
35313
|
var recentSeals = /* @__PURE__ */ new Map();
|
|
@@ -34847,7 +35319,7 @@ function rememberSeal(root, integrity, files) {
|
|
|
34847
35319
|
var metadata2 = (stat3) => [stat3.dev, stat3.ino, stat3.size, stat3.mode, stat3.mtimeNs, stat3.ctimeNs].join(":");
|
|
34848
35320
|
function generationFiles(root) {
|
|
34849
35321
|
const files = [];
|
|
34850
|
-
if (
|
|
35322
|
+
if (realpathSync15(root) !== root) throw new Error("TRAVEL_GENERATION_INTEGRITY");
|
|
34851
35323
|
const visit = (path37) => {
|
|
34852
35324
|
if (path37 === ".runtime-publication-receipt.json") return;
|
|
34853
35325
|
const file2 = join50(root, path37), stat3 = lstatSync19(file2, { bigint: true });
|
|
@@ -34928,14 +35400,14 @@ async function verifyRuntimeGenerationIntegrityAsync(directory2, expected) {
|
|
|
34928
35400
|
// src/continuity/recovery-deletion-visibility.ts
|
|
34929
35401
|
init_key_service_store();
|
|
34930
35402
|
import { DatabaseSync as DatabaseSync22 } from "node:sqlite";
|
|
34931
|
-
import { createHash as createHash40, randomUUID as
|
|
34932
|
-
import { existsSync as existsSync31, realpathSync as
|
|
35403
|
+
import { createHash as createHash40, randomUUID as randomUUID19 } from "node:crypto";
|
|
35404
|
+
import { existsSync as existsSync31, realpathSync as realpathSync17, renameSync as renameSync11, unlinkSync as unlinkSync11, writeFileSync as writeFileSync28 } from "node:fs";
|
|
34933
35405
|
import { join as join53, resolve as resolve30 } from "node:path";
|
|
34934
35406
|
|
|
34935
35407
|
// src/continuity/recovery-deletion-overlay.ts
|
|
34936
35408
|
import { DatabaseSync as DatabaseSync21 } from "node:sqlite";
|
|
34937
|
-
import { createHash as createHash39, randomUUID as
|
|
34938
|
-
import { existsSync as existsSync30, realpathSync as
|
|
35409
|
+
import { createHash as createHash39, randomUUID as randomUUID18 } from "node:crypto";
|
|
35410
|
+
import { existsSync as existsSync30, realpathSync as realpathSync16, renameSync as renameSync10, unlinkSync as unlinkSync10, writeFileSync as writeFileSync27 } from "node:fs";
|
|
34939
35411
|
import { dirname as dirname21, join as join52, resolve as resolve29 } from "node:path";
|
|
34940
35412
|
init_key_service_store();
|
|
34941
35413
|
init_recovery_deletion_sources();
|
|
@@ -35041,7 +35513,7 @@ async function cleanRecoveryDeletionRuntimeCopies(options) {
|
|
|
35041
35513
|
if (++scanned > 1e6 || bytes > 64 * 1024 * 1024) throw new Error("RECOVERY_DEPENDENCY_BUDGET");
|
|
35042
35514
|
if (jsonBlocked(parse(payload))) blockedCells.add(String(row.id));
|
|
35043
35515
|
}
|
|
35044
|
-
const
|
|
35516
|
+
const jobs2 = [];
|
|
35045
35517
|
for (const row of memory.prepare("SELECT * FROM ome_jobs").iterate()) {
|
|
35046
35518
|
if (++scanned > 1e6) throw new Error("RECOVERY_DEPENDENCY_BUDGET");
|
|
35047
35519
|
let input = String(row.payload);
|
|
@@ -35058,12 +35530,12 @@ async function cleanRecoveryDeletionRuntimeCopies(options) {
|
|
|
35058
35530
|
if (bytes > 64 * 1024 * 1024) throw new Error("RECOVERY_DEPENDENCY_BUDGET");
|
|
35059
35531
|
const payload = parse(input), result = row.result_json === null ? void 0 : parse(String(row.result_json));
|
|
35060
35532
|
const scope = scopeKey(payload?.scope ?? payload?.basis?.scope) ?? (typeof payload?.scopeId === "string" ? payload.scopeId : void 0) ?? (typeof row.scope_id === "string" && !row.scope_id.startsWith("resource:") ? row.scope_id : void 0);
|
|
35061
|
-
if (jsonBlocked(payload, scope) || jsonBlocked(result, scope))
|
|
35533
|
+
if (jsonBlocked(payload, scope) || jsonBlocked(result, scope)) jobs2.push({ row, input });
|
|
35062
35534
|
}
|
|
35063
35535
|
const removedSources = sources.filter((row) => blocked2(String(row.scope_id), String(row.source_id)));
|
|
35064
35536
|
if (removedSources.some((row) => row.interpretation_status !== "deleted")) throw new Error("RECOVERY_OVERLAY_SOURCE_PROVENANCE");
|
|
35065
35537
|
options.transaction(() => {
|
|
35066
|
-
for (const { row, input } of
|
|
35538
|
+
for (const { row, input } of jobs2) {
|
|
35067
35539
|
memory.prepare(`UPDATE ome_jobs SET payload='{}',payload_archive=NULL,result_json=NULL,
|
|
35068
35540
|
retained_input_hash=COALESCE(retained_input_hash,?),retained_input_version=COALESCE(retained_input_version,input_version),
|
|
35069
35541
|
payload_pruned_at=COALESCE(payload_pruned_at,?),result_pruned_at=COALESCE(result_pruned_at,?),
|
|
@@ -35276,7 +35748,7 @@ async function cleanRecoveryDeletionRuntimeCopies(options) {
|
|
|
35276
35748
|
return {
|
|
35277
35749
|
format: "engine7-recovery-runtime-copy-cleanup-v6",
|
|
35278
35750
|
sources: removedSources.length,
|
|
35279
|
-
jobs:
|
|
35751
|
+
jobs: jobs2.length,
|
|
35280
35752
|
sessionEvents,
|
|
35281
35753
|
intakeRecords,
|
|
35282
35754
|
debugCaches,
|
|
@@ -35294,7 +35766,7 @@ var evidenceRow = (row) => Object.fromEntries(Object.entries(row).map(([key3, va
|
|
|
35294
35766
|
var applyRecoveryDeletionRuntimeCopies = (options) => deletionOverlay(options, true);
|
|
35295
35767
|
async function deletionOverlay(options, runtimeCopies) {
|
|
35296
35768
|
const manifest = normalizePublication(options.manifest), root = resolve29(options.snapshot), digest7 = publicationDigest(manifest);
|
|
35297
|
-
if (root !== options.snapshot ||
|
|
35769
|
+
if (root !== options.snapshot || realpathSync16(root) !== root || existsSync30(join52(root, ".travel-active.json"))) throw new Error("RECOVERY_OVERLAY_ISOLATION_REQUIRED");
|
|
35298
35770
|
const guard = JSON.parse(readPrivateFile(join52(root, ".travel-restored.json"), 1024 * 1024).toString());
|
|
35299
35771
|
if (guard.activationAllowed !== false) throw new Error("RECOVERY_OVERLAY_ISOLATION_REQUIRED");
|
|
35300
35772
|
if (!same4(manifest.profile.identity, { tenantId: options.principal.tenantId, companionId: options.principal.companionId, seatId: options.principal.seatId })) throw new Error("RECOVERY_IDENTITY_MISMATCH");
|
|
@@ -35337,15 +35809,15 @@ async function deletionOverlay(options, runtimeCopies) {
|
|
|
35337
35809
|
if (floor <= manifest.deletionWatermark) throw new Error("RECOVERY_OVERLAY_NOT_REQUIRED");
|
|
35338
35810
|
const handles = [], databases = /* @__PURE__ */ new Map();
|
|
35339
35811
|
const closeHandles = () => {
|
|
35340
|
-
const
|
|
35812
|
+
const errors2 = [];
|
|
35341
35813
|
while (handles.length) {
|
|
35342
35814
|
try {
|
|
35343
35815
|
handles.pop().close();
|
|
35344
35816
|
} catch (error) {
|
|
35345
|
-
|
|
35817
|
+
errors2.push(error);
|
|
35346
35818
|
}
|
|
35347
35819
|
}
|
|
35348
|
-
if (
|
|
35820
|
+
if (errors2.length) throw new AggregateError(errors2, "RECOVERY_OVERLAY_CLOSE_FAILED");
|
|
35349
35821
|
};
|
|
35350
35822
|
let memory, capture2 = false;
|
|
35351
35823
|
try {
|
|
@@ -35500,7 +35972,7 @@ async function deletionOverlay(options, runtimeCopies) {
|
|
|
35500
35972
|
remaining: ["runtime copy visibility and queue cleanup", "normal activation"]
|
|
35501
35973
|
};
|
|
35502
35974
|
const next = { ...original, originalIntegrity: original.originalIntegrity ?? original.integrity, deletionOverlay: proof, integrity: runtimeGenerationIntegrity(root) };
|
|
35503
|
-
const temporary = join52(root, ".runtime-publication-receipt-" +
|
|
35975
|
+
const temporary = join52(root, ".runtime-publication-receipt-" + randomUUID18());
|
|
35504
35976
|
try {
|
|
35505
35977
|
writeFileSync27(temporary, JSON.stringify(next), { mode: 384, flag: "wx", flush: true });
|
|
35506
35978
|
await check();
|
|
@@ -35520,10 +35992,10 @@ async function deletionOverlay(options, runtimeCopies) {
|
|
|
35520
35992
|
init_schema_migrations();
|
|
35521
35993
|
var same5 = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
35522
35994
|
var sha9 = (value2) => createHash40("sha256").update(value2).digest("hex");
|
|
35523
|
-
var
|
|
35995
|
+
var format2 = "engine7-current-h-deletion-visibility-v1";
|
|
35524
35996
|
function receipt(options) {
|
|
35525
35997
|
const root = resolve30(options.snapshot);
|
|
35526
|
-
if (root !== options.snapshot ||
|
|
35998
|
+
if (root !== options.snapshot || realpathSync17(root) !== root || existsSync31(join53(root, ".travel-active.json")) || JSON.parse(readPrivateFile(join53(root, ".travel-restored.json"), 1024 * 1024).toString()).activationAllowed !== false)
|
|
35527
35999
|
throw new Error("RECOVERY_OVERLAY_ISOLATION_REQUIRED");
|
|
35528
36000
|
return JSON.parse(readPrivateFile(join53(root, ".runtime-publication-receipt.json"), 4 * 1024 * 1024).toString());
|
|
35529
36001
|
}
|
|
@@ -35575,7 +36047,7 @@ async function completeCurrentHDeletionVisibility(options) {
|
|
|
35575
36047
|
validateAuxiliaryState(options);
|
|
35576
36048
|
verifyRuntimeGenerationIntegrity(options.snapshot, next.integrity);
|
|
35577
36049
|
const proof = {
|
|
35578
|
-
format,
|
|
36050
|
+
format: format2,
|
|
35579
36051
|
originalDigest: publicationDigest(options.manifest),
|
|
35580
36052
|
deletionWatermark: floor,
|
|
35581
36053
|
logDigest: overlay.logDigest,
|
|
@@ -35584,7 +36056,7 @@ async function completeCurrentHDeletionVisibility(options) {
|
|
|
35584
36056
|
originalIntegrityDigest: sha9(JSON.stringify(next.originalIntegrity)),
|
|
35585
36057
|
activationAllowed: false
|
|
35586
36058
|
};
|
|
35587
|
-
const file2 = join53(options.snapshot, ".runtime-publication-receipt.json"), temporary = join53(options.snapshot, ".runtime-publication-receipt-" +
|
|
36059
|
+
const file2 = join53(options.snapshot, ".runtime-publication-receipt.json"), temporary = join53(options.snapshot, ".runtime-publication-receipt-" + randomUUID19());
|
|
35588
36060
|
try {
|
|
35589
36061
|
writeFileSync28(temporary, JSON.stringify({ ...next, deletionVisibility: proof }), { mode: 384, flag: "wx", flush: true });
|
|
35590
36062
|
await check();
|
|
@@ -35601,7 +36073,7 @@ async function verifyCurrentHDeletionVisibilityAsync(options) {
|
|
|
35601
36073
|
const check = await currentHDeletionCheckAsync(options.manifest, options), floor = await check(), original = receipt(options), proof = original.deletionVisibility;
|
|
35602
36074
|
const overlay = original.deletionOverlay, digest7 = publicationDigest(options.manifest);
|
|
35603
36075
|
const logDigest = sha9(JSON.stringify(await options.authority.deletionsSince(options.principal, 0)));
|
|
35604
|
-
if (original.format !== "engine7-runtime-publication-restore-v1" || original.activationAllowed !== false || original.receipt?.state !== "PUBLISHED" || original.receipt.digest !== digest7 || original.receipt.sequence !== options.manifest.sequence || original.receipt.deletionWatermark !== options.manifest.deletionWatermark || !same5(original.profile, options.manifest.profile) || !same5(original.databases, options.manifest.databases) || proof?.format !==
|
|
36076
|
+
if (original.format !== "engine7-runtime-publication-restore-v1" || original.activationAllowed !== false || original.receipt?.state !== "PUBLISHED" || original.receipt.digest !== digest7 || original.receipt.sequence !== options.manifest.sequence || original.receipt.deletionWatermark !== options.manifest.deletionWatermark || !same5(original.profile, options.manifest.profile) || !same5(original.databases, options.manifest.databases) || proof?.format !== format2 || proof.activationAllowed !== false || proof.originalDigest !== digest7 || proof.deletionWatermark !== floor || proof.logDigest !== logDigest || !same5(proof.layout, options.layout) || proof.integrityDigest !== sha9(JSON.stringify(original.integrity)) || !original.originalIntegrity || proof.originalIntegrityDigest !== sha9(JSON.stringify(original.originalIntegrity)) || overlay?.originalDigest !== digest7 || overlay.deletionWatermark !== floor || overlay.logDigest !== logDigest || overlay.activationAllowed !== false || overlay.state !== "QUARANTINED" || overlay.runtimeCopies?.format !== "engine7-recovery-runtime-copy-cleanup-v6")
|
|
35605
36077
|
throw new Error("RECOVERY_VISIBILITY_PROOF");
|
|
35606
36078
|
verifyRuntimeGenerationIntegrity(options.snapshot, original.integrity);
|
|
35607
36079
|
const sealed = sha9(JSON.stringify(original));
|
|
@@ -35731,7 +36203,7 @@ async function activateRuntimeGeneration(options) {
|
|
|
35731
36203
|
};
|
|
35732
36204
|
await checkDeletion();
|
|
35733
36205
|
if (!await (options.verifyDirectory ?? verifyRuntimeDirectory)(dirname22(destination))) throw new Error("TRAVEL_ACTIVATION_DIRECTORY");
|
|
35734
|
-
if (
|
|
36206
|
+
if (realpathSync18(snapshot) !== snapshot || realpathSync18(dirname22(destination)) !== dirname22(destination) || existsSync32(destination)) throw new Error("TRAVEL_ACTIVATION_NEW_DIRECTORY_REQUIRED");
|
|
35735
36207
|
const proof = JSON.parse(readPrivateFile(join54(snapshot, ".runtime-publication-receipt.json"), 4 * 1024 * 1024).toString());
|
|
35736
36208
|
if (proof.format !== "engine7-runtime-publication-restore-v1" || !same6(proof.profile, manifest.profile) || proof.receipt?.digest !== digest7 || proof.receipt?.sequence !== manifest.sequence || proof.receipt?.state !== "PUBLISHED" || proof.activationAllowed !== false || !same6(proof.databases, manifest.databases)) throw new Error("TRAVEL_ACTIVATION_RECEIPT");
|
|
35737
36209
|
await verifyRuntimeGenerationIntegrityAsync(snapshot, proof.integrity);
|
|
@@ -35808,9 +36280,9 @@ init_publication_objects();
|
|
|
35808
36280
|
init_key_service_store();
|
|
35809
36281
|
import { fork } from "node:child_process";
|
|
35810
36282
|
import { DatabaseSync as DatabaseSync24 } from "node:sqlite";
|
|
35811
|
-
import { closeSync as closeSync18, lstatSync as lstatSync20, openSync as openSync19, readFileSync as readFileSync29, realpathSync as
|
|
36283
|
+
import { closeSync as closeSync18, lstatSync as lstatSync20, openSync as openSync19, readFileSync as readFileSync29, realpathSync as realpathSync19 } from "node:fs";
|
|
35812
36284
|
import { isAbsolute as isAbsolute7, join as join55 } from "node:path";
|
|
35813
|
-
import { createHash as createHash41, randomUUID as
|
|
36285
|
+
import { createHash as createHash41, randomUUID as randomUUID20 } from "node:crypto";
|
|
35814
36286
|
|
|
35815
36287
|
// src/continuity/engine-control.ts
|
|
35816
36288
|
init_runtime_authority();
|
|
@@ -35822,7 +36294,7 @@ function travelProcessBinding(stateDir) {
|
|
|
35822
36294
|
}
|
|
35823
36295
|
|
|
35824
36296
|
// src/continuity/node-process.ts
|
|
35825
|
-
var
|
|
36297
|
+
var format3 = "engine7-travel-process-v1";
|
|
35826
36298
|
var systemEnvironment = /* @__PURE__ */ new Set([
|
|
35827
36299
|
"PATH",
|
|
35828
36300
|
"PATHEXT",
|
|
@@ -35924,7 +36396,7 @@ var SupervisedRuntimeProcess = class {
|
|
|
35924
36396
|
if (retired && (!recovery || continuation?.state !== "SUSPENDED" || continuation.entry_hash !== this.options.entrySha256 || continuation.authority_boot_id !== permit.authorityBootId)) throw new Error("TRAVEL_PROCESS_GENERATION_RETIRED");
|
|
35925
36397
|
if (recovery && !retired) throw new Error("TRAVEL_PROCESS_GENERATION_RETIRED");
|
|
35926
36398
|
const info = lstatSync20(this.options.entry);
|
|
35927
|
-
if (!info.isFile() || info.isSymbolicLink() || info.size > 64 * 1024 * 1024 ||
|
|
36399
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size > 64 * 1024 * 1024 || realpathSync19(this.options.entry) !== this.options.entry || createHash41("sha256").update(readFileSync29(this.options.entry)).digest("hex") !== this.options.entrySha256) throw new Error("TRAVEL_PROCESS_BUILD");
|
|
35928
36400
|
let environment;
|
|
35929
36401
|
try {
|
|
35930
36402
|
environment = supervisedRuntimeEnvironment(JSON.parse(readPrivateFile(this.options.configFile, 1024 * 1024).toString()), process.env, this.options.environmentNames);
|
|
@@ -35936,7 +36408,7 @@ var SupervisedRuntimeProcess = class {
|
|
|
35936
36408
|
this.expectedAuthorityBootId = permit.authorityBootId;
|
|
35937
36409
|
this.expected = binding;
|
|
35938
36410
|
this.plannedExit = false;
|
|
35939
|
-
const log = join55(this.options.directory, "engine-" +
|
|
36411
|
+
const log = join55(this.options.directory, "engine-" + randomUUID20() + ".log"), fd = openSync19(log, "wx", 384);
|
|
35940
36412
|
let child;
|
|
35941
36413
|
try {
|
|
35942
36414
|
child = fork(this.options.entry, [this.options.configFile], {
|
|
@@ -35961,7 +36433,7 @@ var SupervisedRuntimeProcess = class {
|
|
|
35961
36433
|
child.once("error", fail2);
|
|
35962
36434
|
child.once("exit", fail2);
|
|
35963
36435
|
child.on("message", (message) => {
|
|
35964
|
-
if (message?.format !==
|
|
36436
|
+
if (message?.format !== format3 || JSON.stringify(message.binding) !== JSON.stringify(binding)) return;
|
|
35965
36437
|
if (message.type === "ready") {
|
|
35966
36438
|
clearTimeout(timer);
|
|
35967
36439
|
resolve47();
|
|
@@ -36002,14 +36474,14 @@ var SupervisedRuntimeProcess = class {
|
|
|
36002
36474
|
}
|
|
36003
36475
|
request(action, fields3 = {}) {
|
|
36004
36476
|
if (!this.child?.connected) return Promise.reject(new Error("TRAVEL_PROCESS_EXITED"));
|
|
36005
|
-
const nonce =
|
|
36477
|
+
const nonce = randomUUID20(), child = this.child;
|
|
36006
36478
|
return new Promise((resolve47, reject) => {
|
|
36007
36479
|
const timer = setTimeout(() => {
|
|
36008
36480
|
this.pending.delete(nonce);
|
|
36009
36481
|
reject(new Error("TRAVEL_PROCESS_TIMEOUT"));
|
|
36010
36482
|
}, action === "status" ? Math.min(this.timeout, 5e3) : this.timeout);
|
|
36011
36483
|
this.pending.set(nonce, { resolve: resolve47, reject, timer });
|
|
36012
|
-
child.send?.({ format:
|
|
36484
|
+
child.send?.({ format: format3, type: "request", nonce, binding: this.expected, action, ...fields3 }, (error) => {
|
|
36013
36485
|
if (error) {
|
|
36014
36486
|
clearTimeout(timer);
|
|
36015
36487
|
this.pending.delete(nonce);
|
|
@@ -36113,7 +36585,7 @@ import { join as join57, resolve as resolve33 } from "node:path";
|
|
|
36113
36585
|
|
|
36114
36586
|
// src/continuity/publication-files.ts
|
|
36115
36587
|
import { DatabaseSync as DatabaseSync25 } from "node:sqlite";
|
|
36116
|
-
import { lstatSync as lstatSync21, readdirSync as readdirSync13, realpathSync as
|
|
36588
|
+
import { lstatSync as lstatSync21, readdirSync as readdirSync13, realpathSync as realpathSync20, mkdirSync as mkdirSync26, writeFileSync as writeFileSync30, chmodSync as chmodSync7, openSync as openSync20, closeSync as closeSync19, fsyncSync as fsyncSync11 } from "node:fs";
|
|
36117
36589
|
import { join as join56, resolve as resolve32, dirname as dirname23 } from "node:path";
|
|
36118
36590
|
async function restorePublication(options) {
|
|
36119
36591
|
const { receiver } = options, status = await receiver.status(false);
|
|
@@ -36121,7 +36593,7 @@ async function restorePublication(options) {
|
|
|
36121
36593
|
const manifest = await receiver.manifest(status.published.sequence);
|
|
36122
36594
|
if (JSON.stringify(Object.keys(options.databases).sort()) !== JSON.stringify(manifest.profile.databaseIds)) throw new Error("PUBLICATION_INCOMPLETE_DATABASES");
|
|
36123
36595
|
const destination = resolve32(options.destination);
|
|
36124
|
-
if (
|
|
36596
|
+
if (realpathSync20(dirname23(destination)) !== dirname23(destination)) throw new Error("SYMLINK_REFUSED");
|
|
36125
36597
|
if (isWithin(receiver.objects.directory, destination) || isWithin(destination, receiver.objects.directory)) throw new Error("PUBLICATION_OVERLAPPING_PATHS");
|
|
36126
36598
|
try {
|
|
36127
36599
|
mkdirSync26(destination, { mode: 448 });
|
|
@@ -36264,7 +36736,7 @@ import { join as join59 } from "node:path";
|
|
|
36264
36736
|
init_key_service_store();
|
|
36265
36737
|
init_publication_objects();
|
|
36266
36738
|
import { DatabaseSync as DatabaseSync27 } from "node:sqlite";
|
|
36267
|
-
import { existsSync as existsSync33, lstatSync as lstatSync22, realpathSync as
|
|
36739
|
+
import { existsSync as existsSync33, lstatSync as lstatSync22, realpathSync as realpathSync21 } from "node:fs";
|
|
36268
36740
|
import { createHash as createHash42 } from "node:crypto";
|
|
36269
36741
|
import { isAbsolute as isAbsolute8, join as join58, resolve as resolve34 } from "node:path";
|
|
36270
36742
|
init_sqlite_replication();
|
|
@@ -36276,7 +36748,7 @@ async function openRuntimeGenerationSource(options) {
|
|
|
36276
36748
|
for (const path37 of [options.stateDir, options.dataDirectory]) if (!isAbsolute8(path37) || resolve34(path37) !== path37) throw new Error("TRAVEL_SOURCE_PATH");
|
|
36277
36749
|
const stateDir = options.stateDir, dataDirectory = options.dataDirectory;
|
|
36278
36750
|
assertPrivateDirectory(stateDir);
|
|
36279
|
-
if (
|
|
36751
|
+
if (realpathSync21(stateDir) !== stateDir || realpathSync21(join58(dataDirectory, "..")) !== resolve34(dataDirectory, "..") || isWithin(stateDir, dataDirectory) || isWithin(dataDirectory, stateDir) || isWithin(stateDir, options.objects.directory)) throw new Error("TRAVEL_SOURCE_PATH");
|
|
36280
36752
|
if (options.mode !== "LIVE" && options.mode !== "SEALED") throw new Error("TRAVEL_SOURCE_MODE");
|
|
36281
36753
|
if (existsSync33(join58(stateDir, ".travel-restored.json"))) throw new Error("TRAVEL_ACTIVATION_REQUIRED");
|
|
36282
36754
|
const receipt2 = JSON.parse(readPrivateFile(join58(stateDir, ".travel-active.json"), 4 * 1024 * 1024).toString());
|
|
@@ -36297,7 +36769,7 @@ async function openRuntimeGenerationSource(options) {
|
|
|
36297
36769
|
}
|
|
36298
36770
|
const workspace = join58(stateDir, layout.trees[workspaceTree.id]);
|
|
36299
36771
|
assertPrivateDirectory(workspace);
|
|
36300
|
-
if (workspace === stateDir || !isWithin(stateDir, workspace) ||
|
|
36772
|
+
if (workspace === stateDir || !isWithin(stateDir, workspace) || realpathSync21(workspace) !== workspace) throw new Error("TRAVEL_SOURCE_LAYOUT");
|
|
36301
36773
|
const handles = {}, databases = {}, writableDatabases = {};
|
|
36302
36774
|
const releases2 = [], sessionDirectories = [], sessionTrees = [];
|
|
36303
36775
|
const registeredRoots = /* @__PURE__ */ new Set();
|
|
@@ -36323,7 +36795,7 @@ async function openRuntimeGenerationSource(options) {
|
|
|
36323
36795
|
const path37 = layout.databases[id2];
|
|
36324
36796
|
validatePublicationPath(path37);
|
|
36325
36797
|
const file2 = join58(stateDir, path37), place = sqliteStoreLocation(file2), info = lstatSync22(file2);
|
|
36326
|
-
if (!place || !isWithin(stateDir, place.stateDir) || !info.isFile() || info.isSymbolicLink() ||
|
|
36798
|
+
if (!place || !isWithin(stateDir, place.stateDir) || !info.isFile() || info.isSymbolicLink() || realpathSync21(file2) !== file2 || process.platform !== "win32" && (info.mode & 63 || info.uid !== process.getuid())) throw new Error("TRAVEL_SOURCE_LAYOUT");
|
|
36327
36799
|
const db2 = new DatabaseSync27(file2, { readOnly: options.mode === "SEALED", allowExtension: options.mode === "LIVE" && place.component === "legacy-memory" });
|
|
36328
36800
|
handles[id2] = db2;
|
|
36329
36801
|
const schema5 = readSchemaVersion(db2), registration = readSQLiteStoreRegistration(place), actual = readSQLiteReplicationSource(db2);
|
|
@@ -36543,11 +37015,11 @@ function startTravelHeartbeatReporting(options) {
|
|
|
36543
37015
|
preparePrivateDirectory(options.directory);
|
|
36544
37016
|
const ownerFile = join60(options.directory, "heartbeat-owner.sqlite");
|
|
36545
37017
|
preparePrivateDatabase(ownerFile);
|
|
36546
|
-
const
|
|
37018
|
+
const owner2 = new DatabaseSync28(ownerFile);
|
|
36547
37019
|
try {
|
|
36548
|
-
|
|
37020
|
+
owner2.exec("CREATE TABLE IF NOT EXISTS owner(id INTEGER PRIMARY KEY);BEGIN IMMEDIATE");
|
|
36549
37021
|
} catch {
|
|
36550
|
-
|
|
37022
|
+
owner2.close();
|
|
36551
37023
|
throw new Error("TRAVEL_REPORTING_BUSY");
|
|
36552
37024
|
}
|
|
36553
37025
|
let db2;
|
|
@@ -36559,7 +37031,7 @@ function startTravelHeartbeatReporting(options) {
|
|
|
36559
37031
|
if (db2.prepare("PRAGMA quick_check").get()?.quick_check !== "ok") throw new Error("TRAVEL_REPORTING_RECOVERY_REQUIRED");
|
|
36560
37032
|
db2.prepare("INSERT OR IGNORE INTO sequences VALUES(?,?,0)").run(options.nodeId, options.bootId);
|
|
36561
37033
|
} catch (error) {
|
|
36562
|
-
|
|
37034
|
+
owner2.close();
|
|
36563
37035
|
throw error;
|
|
36564
37036
|
}
|
|
36565
37037
|
let stopped = false, registered = false, active, stopping, timer, lastError = null, deadline = clock2();
|
|
@@ -36670,7 +37142,7 @@ function startTravelHeartbeatReporting(options) {
|
|
|
36670
37142
|
await active;
|
|
36671
37143
|
} finally {
|
|
36672
37144
|
db2.close();
|
|
36673
|
-
|
|
37145
|
+
owner2.close();
|
|
36674
37146
|
}
|
|
36675
37147
|
})();
|
|
36676
37148
|
return stopping;
|
|
@@ -36683,7 +37155,7 @@ init_key_service_store();
|
|
|
36683
37155
|
|
|
36684
37156
|
// src/continuity/recovery-archive-restore.ts
|
|
36685
37157
|
import { DatabaseSync as DatabaseSync29 } from "node:sqlite";
|
|
36686
|
-
import { mkdirSync as mkdirSync28, writeFileSync as writeFileSync32, realpathSync as
|
|
37158
|
+
import { mkdirSync as mkdirSync28, writeFileSync as writeFileSync32, realpathSync as realpathSync22 } from "node:fs";
|
|
36687
37159
|
import { dirname as dirname24, join as join61, resolve as resolve35 } from "node:path";
|
|
36688
37160
|
init_sqlite_replication();
|
|
36689
37161
|
async function restoreRecoveryArchive(options) {
|
|
@@ -36701,7 +37173,7 @@ async function restoreOriginal(options, original, currentHCheck) {
|
|
|
36701
37173
|
const verify4 = async () => currentHCheck ? currentHCheck() : await checkRecoveryDeletionAsync(manifest, options.deletionWatermark, floor);
|
|
36702
37174
|
floor = await verify4();
|
|
36703
37175
|
const destination = resolve35(options.destination);
|
|
36704
|
-
if (
|
|
37176
|
+
if (realpathSync22(dirname24(destination)) !== dirname24(destination)) throw new Error("SYMLINK_REFUSED");
|
|
36705
37177
|
for (const root of [objects.directory, options.archive.directory]) if (isWithin(root, destination) || isWithin(destination, root)) throw new Error("RECOVERY_OVERLAPPING_PATHS");
|
|
36706
37178
|
try {
|
|
36707
37179
|
mkdirSync28(destination, { mode: 448 });
|
|
@@ -36779,7 +37251,7 @@ import { DatabaseSync as DatabaseSync30 } from "node:sqlite";
|
|
|
36779
37251
|
import { existsSync as existsSync34, lstatSync as lstatSync23, writeFileSync as writeFileSync33 } from "node:fs";
|
|
36780
37252
|
import { join as join62 } from "node:path";
|
|
36781
37253
|
var zero = "0".repeat(64);
|
|
36782
|
-
var
|
|
37254
|
+
var format4 = "engine7-runtime-checkpoint-control-v1";
|
|
36783
37255
|
var hash7 = (value2) => typeof value2 === "string" && /^[a-f0-9]{64}$/.test(value2);
|
|
36784
37256
|
var natural3 = (value2) => typeof value2 === "number" && Number.isSafeInteger(value2) && value2 >= 0;
|
|
36785
37257
|
var incarnation3 = (file2) => {
|
|
@@ -36796,9 +37268,9 @@ var RuntimeCheckpointControl = class {
|
|
|
36796
37268
|
this.files = ["checkpoints.json", "checkpoint-owner.sqlite", "checkpoints.sqlite"].map((file2) => join62(options.directory, file2));
|
|
36797
37269
|
const presence = this.files.map(existsSync34), fresh = presence.every((value2) => !value2);
|
|
36798
37270
|
if (fresh && options.initialize !== true || !fresh && !presence.every(Boolean)) throw new Error("TRAVEL_CHECKPOINT_RECOVERY_REQUIRED");
|
|
36799
|
-
if (fresh) writeFileSync33(this.files[0], JSON.stringify({ format:
|
|
37271
|
+
if (fresh) writeFileSync33(this.files[0], JSON.stringify({ format: format4, binding: this.binding }), { mode: 384, flag: "wx", flush: true });
|
|
36800
37272
|
const marker = JSON.parse(readPrivateFile(this.files[0], 65536).toString());
|
|
36801
|
-
if (marker.format !==
|
|
37273
|
+
if (marker.format !== format4 || marker.binding !== this.binding || Object.keys(marker).length !== 2) throw new Error("TRAVEL_CHECKPOINT_IDENTITY");
|
|
36802
37274
|
preparePrivateDatabase(this.files[1]);
|
|
36803
37275
|
this.owner = new DatabaseSync30(this.files[1]);
|
|
36804
37276
|
try {
|
|
@@ -36883,7 +37355,7 @@ var RuntimeCheckpointControl = class {
|
|
|
36883
37355
|
};
|
|
36884
37356
|
|
|
36885
37357
|
// src/continuity/recovery-archive-transfer.ts
|
|
36886
|
-
import { Agent, createServer as createServer2, request as request3 } from "node:https";
|
|
37358
|
+
import { Agent as Agent2, createServer as createServer2, request as request3 } from "node:https";
|
|
36887
37359
|
import { gzipSync, gunzipSync as gunzipSync4, createGunzip, brotliCompressSync, brotliDecompressSync, createBrotliCompress, createBrotliDecompress, constants as constants13 } from "node:zlib";
|
|
36888
37360
|
import { pipeline } from "node:stream";
|
|
36889
37361
|
import { pipeline as pipelineAsync } from "node:stream/promises";
|
|
@@ -37292,7 +37764,7 @@ var RecoveryArchiveClient = class {
|
|
|
37292
37764
|
this.timeout = options.timeoutMs ?? 15e3;
|
|
37293
37765
|
if (!Number.isSafeInteger(this.timeout) || this.timeout < 1 || this.timeout > 6e4) throw new Error("RECOVERY_TRANSFER_CONFIG");
|
|
37294
37766
|
this.key = Buffer.from(options.key);
|
|
37295
|
-
this.agent = new
|
|
37767
|
+
this.agent = new Agent2({ ca: options.ca, cert: options.cert, key: this.key, minVersion: "TLSv1.3", rejectUnauthorized: true, keepAlive: true, maxSockets: 2 });
|
|
37296
37768
|
}
|
|
37297
37769
|
call(input, maximum, archiveDigest) {
|
|
37298
37770
|
if (this.closed) return Promise.reject(new Error("RECOVERY_TRANSFER_CLOSED"));
|
|
@@ -37772,13 +38244,13 @@ async function transferRecoveryArchive(options) {
|
|
|
37772
38244
|
init_publication_objects();
|
|
37773
38245
|
init_key_service_store();
|
|
37774
38246
|
import { DatabaseSync as DatabaseSync32 } from "node:sqlite";
|
|
37775
|
-
import { existsSync as existsSync36, lstatSync as lstatSync25, realpathSync as
|
|
38247
|
+
import { existsSync as existsSync36, lstatSync as lstatSync25, realpathSync as realpathSync24, writeFileSync as writeFileSync35 } from "node:fs";
|
|
37776
38248
|
import { isAbsolute as isAbsolute10, join as join64, resolve as resolve37 } from "node:path";
|
|
37777
|
-
import { randomUUID as
|
|
38249
|
+
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
37778
38250
|
|
|
37779
38251
|
// src/continuity/runtime-replica-seed.ts
|
|
37780
38252
|
import { DatabaseSync as DatabaseSync31 } from "node:sqlite";
|
|
37781
|
-
import { existsSync as existsSync35, writeFileSync as writeFileSync34, realpathSync as
|
|
38253
|
+
import { existsSync as existsSync35, writeFileSync as writeFileSync34, realpathSync as realpathSync23, lstatSync as lstatSync24 } from "node:fs";
|
|
37782
38254
|
import { dirname as dirname25, isAbsolute as isAbsolute9, join as join63, resolve as resolve36 } from "node:path";
|
|
37783
38255
|
init_publication_objects();
|
|
37784
38256
|
init_sqlite_replication();
|
|
@@ -37788,14 +38260,14 @@ function acquireReplicaOwner(directory2, initialize2 = false) {
|
|
|
37788
38260
|
const file2 = join63(directory2, "replica-owner.sqlite");
|
|
37789
38261
|
if (!initialize2 && !existsSync35(file2)) throw new Error("TRAVEL_REPLICA_RECOVERY_REQUIRED");
|
|
37790
38262
|
preparePrivateDatabase(file2);
|
|
37791
|
-
const
|
|
38263
|
+
const owner2 = new DatabaseSync31(file2);
|
|
37792
38264
|
try {
|
|
37793
|
-
if (initialize2)
|
|
37794
|
-
if (
|
|
37795
|
-
|
|
37796
|
-
return
|
|
38265
|
+
if (initialize2) owner2.exec("CREATE TABLE owner(id INTEGER PRIMARY KEY)");
|
|
38266
|
+
if (owner2.prepare("PRAGMA quick_check").get()?.quick_check !== "ok" || !owner2.prepare("SELECT 1 FROM sqlite_master WHERE name='owner' AND type='table'").get()) throw new Error("TRAVEL_REPLICA_RECOVERY_REQUIRED");
|
|
38267
|
+
owner2.exec("PRAGMA busy_timeout=0;BEGIN IMMEDIATE");
|
|
38268
|
+
return owner2;
|
|
37797
38269
|
} catch (error) {
|
|
37798
|
-
|
|
38270
|
+
owner2.close();
|
|
37799
38271
|
if (error.code === "ERR_SQLITE_ERROR" && /locked|busy/i.test(error.message)) throw new Error("TRAVEL_REPLICA_BUSY");
|
|
37800
38272
|
throw error;
|
|
37801
38273
|
}
|
|
@@ -37816,14 +38288,14 @@ async function seedRuntimeReplica(options) {
|
|
|
37816
38288
|
if (status.buildManifestId !== manifest.profile.buildManifestId) throw new Error("TRAVEL_REPLICA_BUILD");
|
|
37817
38289
|
};
|
|
37818
38290
|
await check();
|
|
37819
|
-
for (const path37 of [options.destination, options.dataDirectory]) if (!isAbsolute9(path37) || resolve36(path37) !== path37 ||
|
|
38291
|
+
for (const path37 of [options.destination, options.dataDirectory]) if (!isAbsolute9(path37) || resolve36(path37) !== path37 || realpathSync23(dirname25(path37)) !== dirname25(path37)) throw new Error("TRAVEL_REPLICA_PATH");
|
|
37820
38292
|
if (existsSync35(destination) || existsSync35(dataDirectory) || isWithin(destination, dataDirectory) || isWithin(dataDirectory, destination)) throw new Error("TRAVEL_REPLICA_NEW_DIRECTORY_REQUIRED");
|
|
37821
38293
|
for (const path37 of [destination, dataDirectory]) for (const root of [options.objects.directory, options.archive.directory, options.archive.objects.directory]) if (isWithin(root, path37) || isWithin(path37, root)) throw new Error("TRAVEL_REPLICA_PATH");
|
|
37822
38294
|
if (!await (options.verifyDirectory ?? verifyRuntimeDirectory)(dirname25(destination))) throw new Error("TRAVEL_REPLICA_DIRECTORY");
|
|
37823
38295
|
await check();
|
|
37824
38296
|
preparePrivateDirectory(dataDirectory);
|
|
37825
38297
|
const databases = {}, replicas = {};
|
|
37826
|
-
let receiver,
|
|
38298
|
+
let receiver, owner2, closed = false;
|
|
37827
38299
|
const close = () => {
|
|
37828
38300
|
if (closed) return;
|
|
37829
38301
|
closed = true;
|
|
@@ -37831,11 +38303,11 @@ async function seedRuntimeReplica(options) {
|
|
|
37831
38303
|
receiver?.close();
|
|
37832
38304
|
for (const db2 of Object.values(databases)) db2.close();
|
|
37833
38305
|
} finally {
|
|
37834
|
-
|
|
38306
|
+
owner2?.close();
|
|
37835
38307
|
}
|
|
37836
38308
|
};
|
|
37837
38309
|
try {
|
|
37838
|
-
|
|
38310
|
+
owner2 = acquireReplicaOwner(dataDirectory, true);
|
|
37839
38311
|
await restoreRecoveryArchive({ archive: options.archive, id: options.id, destination, deletionWatermark: options.deletionWatermark, verifyDatabases: false });
|
|
37840
38312
|
const refs2 = /* @__PURE__ */ new Map();
|
|
37841
38313
|
for (const content of [...manifest.trees.flatMap((tree) => tree.files.map((file2) => file2.content)), ...entry.databases.map((db2) => db2.content)]) for (const ref of content.chunks) refs2.set(ref.sha256, ref);
|
|
@@ -37892,7 +38364,7 @@ async function openSeededRuntimeReplica(options) {
|
|
|
37892
38364
|
for (const path37 of [options.destination, options.dataDirectory]) {
|
|
37893
38365
|
if (!isAbsolute9(path37) || resolve36(path37) !== path37) throw new Error("TRAVEL_REPLICA_PATH");
|
|
37894
38366
|
assertPrivateDirectory(path37);
|
|
37895
|
-
if (
|
|
38367
|
+
if (realpathSync23(path37) !== path37) throw new Error("TRAVEL_REPLICA_PATH");
|
|
37896
38368
|
}
|
|
37897
38369
|
if (isWithin(options.destination, options.dataDirectory) || isWithin(options.dataDirectory, options.destination)) throw new Error("TRAVEL_REPLICA_PATH");
|
|
37898
38370
|
for (const path37 of [options.destination, options.dataDirectory]) for (const root of [options.objects.directory, options.archive.directory, options.archive.objects.directory]) if (isWithin(root, path37) || isWithin(path37, root)) throw new Error("TRAVEL_REPLICA_PATH");
|
|
@@ -37908,7 +38380,7 @@ async function openSeededRuntimeReplica(options) {
|
|
|
37908
38380
|
};
|
|
37909
38381
|
floor();
|
|
37910
38382
|
if (!await (options.verifyDirectory ?? verifyRuntimeDirectory)(dirname25(options.destination))) throw new Error("TRAVEL_REPLICA_DIRECTORY");
|
|
37911
|
-
const
|
|
38383
|
+
const owner2 = acquireReplicaOwner(options.dataDirectory), databases = {}, replicas = {};
|
|
37912
38384
|
let receiver, closed = false;
|
|
37913
38385
|
const close = () => {
|
|
37914
38386
|
if (closed) return;
|
|
@@ -37917,7 +38389,7 @@ async function openSeededRuntimeReplica(options) {
|
|
|
37917
38389
|
receiver?.close();
|
|
37918
38390
|
for (const db2 of Object.values(databases)) db2.close();
|
|
37919
38391
|
} finally {
|
|
37920
|
-
|
|
38392
|
+
owner2.close();
|
|
37921
38393
|
}
|
|
37922
38394
|
};
|
|
37923
38395
|
try {
|
|
@@ -37933,7 +38405,7 @@ async function openSeededRuntimeReplica(options) {
|
|
|
37933
38405
|
const file2 = join63(options.destination, "databases", d.databaseId + ".sqlite");
|
|
37934
38406
|
if (!existsSync35(file2)) throw new Error("TRAVEL_REPLICA_RECOVERY_REQUIRED");
|
|
37935
38407
|
const stat3 = lstatSync24(file2);
|
|
37936
|
-
if (!stat3.isFile() || stat3.isSymbolicLink() ||
|
|
38408
|
+
if (!stat3.isFile() || stat3.isSymbolicLink() || realpathSync23(file2) !== file2 || process.platform !== "win32" && (stat3.uid !== process.getuid() || stat3.mode & 63)) throw new Error("TRAVEL_REPLICA_PATH");
|
|
37937
38409
|
const probe = new DatabaseSync31(file2, { readOnly: true }), binding = normalizeBinding({ ...profile.identity, databaseId: d.databaseId, baselineId: profile.baselineId, epoch: profile.epoch });
|
|
37938
38410
|
let component, version;
|
|
37939
38411
|
try {
|
|
@@ -37978,7 +38450,7 @@ var RuntimeReplicaRepository = class _RuntimeReplicaRepository {
|
|
|
37978
38450
|
this.options = options;
|
|
37979
38451
|
if (!validId2(options.nodeId) || !isAbsolute10(options.directory) || resolve37(options.directory) !== options.directory || !isAbsolute10(options.generationsDirectory) || resolve37(options.generationsDirectory) !== options.generationsDirectory || isWithin(options.directory, options.generationsDirectory) || isWithin(options.generationsDirectory, options.directory)) throw new Error("TRAVEL_REPLICA_PATH");
|
|
37980
38452
|
assertPrivateDirectory(options.generationsDirectory);
|
|
37981
|
-
if (
|
|
38453
|
+
if (realpathSync24(options.generationsDirectory) !== options.generationsDirectory) throw new Error("TRAVEL_REPLICA_PATH");
|
|
37982
38454
|
preparePrivateDirectory(options.directory);
|
|
37983
38455
|
this.files = ["replicas.json", "replicas-owner.sqlite", "replicas.sqlite"].map((name) => join64(options.directory, name));
|
|
37984
38456
|
const presence = this.files.map(existsSync36), fresh = presence.every((value2) => !value2);
|
|
@@ -38111,7 +38583,7 @@ var RuntimeReplicaRepository = class _RuntimeReplicaRepository {
|
|
|
38111
38583
|
}
|
|
38112
38584
|
if (row && row.state !== "PREPARING") throw new Error("TRAVEL_REPLICA_RECOVERY_REQUIRED");
|
|
38113
38585
|
preparePrivateDirectory(join64(this.options.directory, "receivers"));
|
|
38114
|
-
const attempt =
|
|
38586
|
+
const attempt = randomUUID21(), destination = join64(this.options.generationsDirectory, "replica-" + attempt), dataDirectory = join64(this.options.directory, "receivers", "replica-" + attempt);
|
|
38115
38587
|
this.db.exec("BEGIN IMMEDIATE");
|
|
38116
38588
|
try {
|
|
38117
38589
|
if (row) this.db.prepare("UPDATE attempts SET state='FAILED' WHERE id=? AND state='PREPARING'").run(row.attempt_id);
|
|
@@ -38190,7 +38662,7 @@ var RuntimeReplicaRepository = class _RuntimeReplicaRepository {
|
|
|
38190
38662
|
import { createServer as createServer4 } from "node:https";
|
|
38191
38663
|
|
|
38192
38664
|
// src/continuity/publication-transport.ts
|
|
38193
|
-
import { createServer as createServer3, request as request4, Agent as
|
|
38665
|
+
import { createServer as createServer3, request as request4, Agent as Agent3 } from "node:https";
|
|
38194
38666
|
import { createHash as createHash43 } from "node:crypto";
|
|
38195
38667
|
init_publication_objects();
|
|
38196
38668
|
var BODY_LIMIT = PUBLICATION_MANIFEST_BYTES + 65536;
|
|
@@ -38393,7 +38865,7 @@ async function createTravelNodeDataServer(options) {
|
|
|
38393
38865
|
init_store();
|
|
38394
38866
|
init_schema_migrations();
|
|
38395
38867
|
import { DatabaseSync as DatabaseSync35 } from "node:sqlite";
|
|
38396
|
-
import { lstatSync as lstatSync27, realpathSync as
|
|
38868
|
+
import { lstatSync as lstatSync27, realpathSync as realpathSync26 } from "node:fs";
|
|
38397
38869
|
import { isAbsolute as isAbsolute11, join as join68, resolve as resolve39 } from "node:path";
|
|
38398
38870
|
|
|
38399
38871
|
// src/continuity/recovery-admission.ts
|
|
@@ -38805,8 +39277,8 @@ function nativeReferences(db2, table, row, common, branch, scopeProof, originalB
|
|
|
38805
39277
|
const entity = db2.prepare("SELECT kind FROM entities WHERE scope_id=? AND entity_id=? AND state='active'").get(scope, payload.entityId);
|
|
38806
39278
|
if (!entity) return false;
|
|
38807
39279
|
if (payload.provenance === "host_identity") {
|
|
38808
|
-
const
|
|
38809
|
-
if (entity.kind !== "agent" || !["assistant-actor", "scope-agent"].includes(text2("namespace") ?? "") || text2("namespace") === "scope-agent" && text2("external_id") !==
|
|
39280
|
+
const owner2 = db2.prepare("SELECT app_id FROM memory_scopes WHERE scope_id=?").get(scope);
|
|
39281
|
+
if (entity.kind !== "agent" || !["assistant-actor", "scope-agent"].includes(text2("namespace") ?? "") || text2("namespace") === "scope-agent" && text2("external_id") !== owner2?.app_id) return false;
|
|
38810
39282
|
} else {
|
|
38811
39283
|
const source = db2.prepare("SELECT * FROM memory_sources WHERE scope_id=? AND source_id=? AND interpretation_status<>'deleted'").get(scope, payload.sourceId);
|
|
38812
39284
|
if (!source || db2.prepare("SELECT 1 FROM memory_sources WHERE scope_id=? AND origin_key=? AND source_version>?").get(scope, source.origin_key, source.source_version)) return false;
|
|
@@ -38839,8 +39311,8 @@ function nativeReferences(db2, table, row, common, branch, scopeProof, originalB
|
|
|
38839
39311
|
if (table === "memory_artifact_generations") {
|
|
38840
39312
|
try {
|
|
38841
39313
|
const result = JSON.parse(text2("result_json") ?? "");
|
|
38842
|
-
const
|
|
38843
|
-
if (!
|
|
39314
|
+
const owner2 = db2.prepare("SELECT owner_id,app_id,project_id FROM memory_scopes WHERE scope_id=?").get(scope);
|
|
39315
|
+
if (!owner2 || !same10(result.basis?.scope, { ownerId: owner2.owner_id, appId: owner2.app_id, projectId: owner2.project_id })) return false;
|
|
38844
39316
|
refs2 = result.basis.dependencies;
|
|
38845
39317
|
} catch {
|
|
38846
39318
|
return false;
|
|
@@ -39042,9 +39514,9 @@ function projectNative(db2, branch, table, original, baseline, current2, archive
|
|
|
39042
39514
|
map("artifact_job", JSON.stringify([decode(row.kind), decode(row.artifact_id), Number(decode(row.version))]), original.version, () => BigInt(generation.job_id));
|
|
39043
39515
|
}
|
|
39044
39516
|
const kind = String(decode(row.kind)), id2 = String(decode(row.artifact_id)), version = Number(decode(row.version));
|
|
39045
|
-
const
|
|
39517
|
+
const owner2 = db2.prepare("SELECT owner_id,app_id,project_id FROM memory_scopes WHERE scope_id=?").get(scope);
|
|
39046
39518
|
const refs2 = JSON.parse(String(decode(row.dependencies_json)));
|
|
39047
|
-
recordArtifactBasis(db2, { ownerId: String(
|
|
39519
|
+
recordArtifactBasis(db2, { ownerId: String(owner2.owner_id), appId: String(owner2.app_id), projectId: String(owner2.project_id) }, kind, id2, version, refs2);
|
|
39048
39520
|
row.history_id = history("artifact.publication", JSON.stringify([kind, id2, version, String(decode(row.medium))]), { kind, id: id2, version, medium: decode(row.medium), digest: decode(row.digest) });
|
|
39049
39521
|
}
|
|
39050
39522
|
return row;
|
|
@@ -39694,8 +40166,8 @@ async function admitRecoveryArchives(options) {
|
|
|
39694
40166
|
}
|
|
39695
40167
|
|
|
39696
40168
|
// src/continuity/recovery-artifact-projection.ts
|
|
39697
|
-
import { createHash as createHash46, randomUUID as
|
|
39698
|
-
import { existsSync as existsSync37, linkSync, lstatSync as lstatSync26, mkdirSync as mkdirSync29, readFileSync as readFileSync30, realpathSync as
|
|
40169
|
+
import { createHash as createHash46, randomUUID as randomUUID22 } from "node:crypto";
|
|
40170
|
+
import { existsSync as existsSync37, linkSync, lstatSync as lstatSync26, mkdirSync as mkdirSync29, readFileSync as readFileSync30, realpathSync as realpathSync25, unlinkSync as unlinkSync13, writeFileSync as writeFileSync38 } from "node:fs";
|
|
39699
40171
|
import { dirname as dirname26, join as join67, resolve as resolve38 } from "node:path";
|
|
39700
40172
|
import { createRequire as createRequire9 } from "node:module";
|
|
39701
40173
|
init_runtime_authority();
|
|
@@ -39703,7 +40175,7 @@ init_dependencies();
|
|
|
39703
40175
|
var sha10 = (bytes) => createHash46("sha256").update(bytes).digest("hex");
|
|
39704
40176
|
var require5 = createRequire9(import.meta.url);
|
|
39705
40177
|
function privateParents(root, path37) {
|
|
39706
|
-
if (
|
|
40178
|
+
if (realpathSync25(root) !== root) throw new Error("RECOVERY_PROJECTION_UNSAFE_PATH");
|
|
39707
40179
|
const visit = (directory2) => {
|
|
39708
40180
|
if (!isWithin(root, directory2)) throw new Error("RECOVERY_PROJECTION_UNSAFE_PATH");
|
|
39709
40181
|
if (directory2 !== root) visit(dirname26(directory2));
|
|
@@ -39742,11 +40214,11 @@ async function projectRecoveryArtifacts(options) {
|
|
|
39742
40214
|
const verifyArtifact = (scopeId2, kind, id2, version) => {
|
|
39743
40215
|
active();
|
|
39744
40216
|
if (!memory) throw new Error("RECOVERY_ARTIFACT_DEPENDENCY_PENDING");
|
|
39745
|
-
const
|
|
39746
|
-
if (!
|
|
40217
|
+
const owner2 = memory.prepare("SELECT owner_id,app_id,project_id FROM memory_scopes WHERE scope_id=?").get(scopeId2);
|
|
40218
|
+
if (!owner2) throw new Error("RECOVERY_ARTIFACT_DEPENDENCY_PENDING");
|
|
39747
40219
|
const dependencies2 = new MemoryDependencies(memory, (operation) => operation(), (operation) => operation());
|
|
39748
40220
|
try {
|
|
39749
|
-
dependencies2.assertCurrent({ ownerId: String(
|
|
40221
|
+
dependencies2.assertCurrent({ ownerId: String(owner2.owner_id), appId: String(owner2.app_id), projectId: String(owner2.project_id) }, kind, id2, version);
|
|
39750
40222
|
} catch {
|
|
39751
40223
|
throw new Error("RECOVERY_ARTIFACT_DEPENDENCY_PENDING");
|
|
39752
40224
|
}
|
|
@@ -39816,7 +40288,7 @@ async function projectRecoveryArtifacts(options) {
|
|
|
39816
40288
|
commit();
|
|
39817
40289
|
continue;
|
|
39818
40290
|
}
|
|
39819
|
-
const temporary = join67(dirname26(path37), ".recovery-" +
|
|
40291
|
+
const temporary = join67(dirname26(path37), ".recovery-" + randomUUID22()), original = Buffer.from(body);
|
|
39820
40292
|
writeFileSync38(temporary, original, { mode: local.mode, flag: "wx", flush: true });
|
|
39821
40293
|
let created = false;
|
|
39822
40294
|
try {
|
|
@@ -39938,7 +40410,7 @@ function policies(version) {
|
|
|
39938
40410
|
async function admitNormalRecoveryArchives(options) {
|
|
39939
40411
|
if (options.policyUpgrade !== void 0 && options.policyUpgrade !== "normal-v1") throw new Error("RECOVERY_INVALID_RESOLUTION");
|
|
39940
40412
|
const stateDir = options.stateDir;
|
|
39941
|
-
if (!isAbsolute11(stateDir) || resolve39(stateDir) !== stateDir ||
|
|
40413
|
+
if (!isAbsolute11(stateDir) || resolve39(stateDir) !== stateDir || realpathSync26(stateDir) !== stateDir || typeof options.withSafeBoundary !== "function") throw new Error("RECOVERY_CURRENT_LAYOUT");
|
|
39942
40414
|
assertPrivateDirectory(stateDir);
|
|
39943
40415
|
const runtime = runtimeAuthorityFor(stateDir);
|
|
39944
40416
|
if (!runtime) throw new Error("RECOVERY_AUTHORITY_BARRIER");
|
|
@@ -39957,7 +40429,7 @@ async function admitNormalRecoveryArchives(options) {
|
|
|
39957
40429
|
for (const id2 of profile.databaseIds) {
|
|
39958
40430
|
validatePublicationPath(layout.databases[id2]);
|
|
39959
40431
|
const file2 = join68(stateDir, layout.databases[id2]), place = sqliteStoreLocation(file2), stat3 = lstatSync27(file2);
|
|
39960
|
-
if (!place || !stat3.isFile() || stat3.isSymbolicLink() ||
|
|
40432
|
+
if (!place || !stat3.isFile() || stat3.isSymbolicLink() || realpathSync26(file2) !== file2 || process.platform !== "win32" && (stat3.uid !== process.getuid() || stat3.mode & 63)) throw new Error("RECOVERY_CURRENT_LAYOUT");
|
|
39961
40433
|
if (place.component === "mem7") {
|
|
39962
40434
|
if (id2 !== "memory" || memory || place.stateDir !== stateDir) throw new Error("RECOVERY_CURRENT_LAYOUT");
|
|
39963
40435
|
memory = new Mem7Store(stateDir);
|
|
@@ -40003,27 +40475,27 @@ async function admitNormalRecoveryArchives(options) {
|
|
|
40003
40475
|
failure2 = error;
|
|
40004
40476
|
throw error;
|
|
40005
40477
|
} finally {
|
|
40006
|
-
const
|
|
40478
|
+
const errors2 = [];
|
|
40007
40479
|
try {
|
|
40008
40480
|
await memory?.close();
|
|
40009
40481
|
} catch (error) {
|
|
40010
|
-
|
|
40482
|
+
errors2.push(error);
|
|
40011
40483
|
}
|
|
40012
40484
|
for (const db2 of handles.reverse()) {
|
|
40013
40485
|
try {
|
|
40014
40486
|
db2.close();
|
|
40015
40487
|
} catch (error) {
|
|
40016
|
-
|
|
40488
|
+
errors2.push(error);
|
|
40017
40489
|
}
|
|
40018
40490
|
}
|
|
40019
40491
|
for (const release of releases2.reverse()) {
|
|
40020
40492
|
try {
|
|
40021
40493
|
release();
|
|
40022
40494
|
} catch (error) {
|
|
40023
|
-
|
|
40495
|
+
errors2.push(error);
|
|
40024
40496
|
}
|
|
40025
40497
|
}
|
|
40026
|
-
if (
|
|
40498
|
+
if (errors2.length) throw new AggregateError(failure2 === void 0 ? errors2 : [failure2, ...errors2], "RECOVERY_CURRENT_CLOSE_FAILED");
|
|
40027
40499
|
}
|
|
40028
40500
|
});
|
|
40029
40501
|
}
|
|
@@ -40120,7 +40592,7 @@ var TravelNodeAgent = class _TravelNodeAgent {
|
|
|
40120
40592
|
for (const path37 of [options.directory, options.generationsDirectory, options.build.entry, options.dataBuild.entry]) if (!isAbsolute12(path37) || resolve40(path37) !== path37) throw new Error("TRAVEL_NODE_PATH");
|
|
40121
40593
|
if (options.dataIntervalMs !== void 0 && (!Number.isSafeInteger(options.dataIntervalMs) || options.dataIntervalMs < 250 || options.dataIntervalMs > 6e4)) throw new Error("TRAVEL_DATA_CONFIG");
|
|
40122
40594
|
assertPrivateDirectory(options.generationsDirectory);
|
|
40123
|
-
if (
|
|
40595
|
+
if (realpathSync27(options.generationsDirectory) !== options.generationsDirectory || isWithin(options.directory, options.generationsDirectory) || isWithin(options.generationsDirectory, options.directory)) throw new Error("TRAVEL_NODE_PATH");
|
|
40124
40596
|
if (!Array.isArray(options.allowedTools) || options.allowedTools.length > 1024 || options.allowedTools.some((tool) => !/^\w[\w.:-]{0,127}$/.test(tool))) throw new Error("TRAVEL_NODE_CAPABILITIES");
|
|
40125
40597
|
validateTravelChannelConfiguration(options.engineConfig.channels);
|
|
40126
40598
|
this.checkBuild();
|
|
@@ -40263,7 +40735,7 @@ var TravelNodeAgent = class _TravelNodeAgent {
|
|
|
40263
40735
|
checkBuild() {
|
|
40264
40736
|
for (const b of [this.options.build, this.options.dataBuild]) {
|
|
40265
40737
|
const info = lstatSync28(b.entry);
|
|
40266
|
-
if (!/^[a-f0-9]{64}$/.test(b.sha256) || !info.isFile() || info.isSymbolicLink() || info.size > 64 * 1024 * 1024 ||
|
|
40738
|
+
if (!/^[a-f0-9]{64}$/.test(b.sha256) || !info.isFile() || info.isSymbolicLink() || info.size > 64 * 1024 * 1024 || realpathSync27(b.entry) !== b.entry || hash10(readFileSync31(b.entry)) !== b.sha256) throw new Error("TRAVEL_NODE_BUILD");
|
|
40267
40739
|
}
|
|
40268
40740
|
}
|
|
40269
40741
|
assertKey() {
|
|
@@ -40449,7 +40921,7 @@ var TravelNodeAgent = class _TravelNodeAgent {
|
|
|
40449
40921
|
const directory2 = join70(this.options.directory, "data", "objects"), file2 = join70(directory2, "catalog.sqlite");
|
|
40450
40922
|
assertPrivateDirectory(directory2);
|
|
40451
40923
|
assertPrivateDirectory(join70(directory2, "chunks"));
|
|
40452
|
-
if (
|
|
40924
|
+
if (realpathSync27(directory2) !== directory2 || !existsSync38(file2)) throw new Error("TRAVEL_NODE_RECOVERY_REQUIRED");
|
|
40453
40925
|
const stat3 = lstatSync28(file2, { bigint: true });
|
|
40454
40926
|
if (!stat3.isFile() || stat3.isSymbolicLink()) throw new Error("TRAVEL_NODE_RECOVERY_REQUIRED");
|
|
40455
40927
|
const db2 = new DatabaseSync36(file2, { readOnly: true });
|
|
@@ -40662,14 +41134,14 @@ var TravelNodeAgent = class _TravelNodeAgent {
|
|
|
40662
41134
|
const prior = this.db.prepare("SELECT snapshot FROM preparations WHERE digest=?").get(digest7);
|
|
40663
41135
|
if (prior) {
|
|
40664
41136
|
const snapshot2 = String(prior.snapshot);
|
|
40665
|
-
if (!isWithin(this.options.generationsDirectory, snapshot2) ||
|
|
41137
|
+
if (!isWithin(this.options.generationsDirectory, snapshot2) || realpathSync27(snapshot2) !== snapshot2) throw new Error("TRAVEL_NODE_PATH");
|
|
40666
41138
|
const receipt2 = JSON.parse(readPrivateFile(join70(snapshot2, ".runtime-publication-receipt.json"), 4 * 1024 * 1024).toString());
|
|
40667
41139
|
if (receipt2.receipt?.digest !== digest7) throw new Error("TRAVEL_NODE_CHECKPOINT");
|
|
40668
41140
|
await verifyRuntimeGenerationIntegrityAsync(snapshot2, receipt2.integrity);
|
|
40669
41141
|
validateRuntimeActivationSnapshot(snapshot2, manifest, locations);
|
|
40670
41142
|
return { snapshot: snapshot2, manifest };
|
|
40671
41143
|
}
|
|
40672
|
-
const snapshot = join70(this.options.generationsDirectory, "snapshot-" +
|
|
41144
|
+
const snapshot = join70(this.options.generationsDirectory, "snapshot-" + randomUUID23());
|
|
40673
41145
|
await restoreRuntimePublication({ receiver, databases, destination: snapshot, sequence: manifest.sequence });
|
|
40674
41146
|
validateRuntimeActivationSnapshot(snapshot, manifest, locations);
|
|
40675
41147
|
this.db.prepare("INSERT INTO preparations VALUES(?,?)").run(digest7, snapshot);
|
|
@@ -40694,7 +41166,7 @@ var TravelNodeAgent = class _TravelNodeAgent {
|
|
|
40694
41166
|
const prior = this.db.prepare("SELECT * FROM common_preparations WHERE digest=?").get(digest7);
|
|
40695
41167
|
if (prior) {
|
|
40696
41168
|
const snapshot2 = String(prior.snapshot);
|
|
40697
|
-
if (prior.archive_digest !== entry.receipt.digest || !isWithin(this.options.generationsDirectory, snapshot2) ||
|
|
41169
|
+
if (prior.archive_digest !== entry.receipt.digest || !isWithin(this.options.generationsDirectory, snapshot2) || realpathSync27(snapshot2) !== snapshot2) throw new Error("TRAVEL_NODE_RECOVERY_REQUIRED");
|
|
40698
41170
|
const proof = JSON.parse(readPrivateFile(join70(snapshot2, ".runtime-publication-receipt.json"), 4 * 1024 * 1024).toString());
|
|
40699
41171
|
if (proof.recoveryArchive?.id !== entry.id || proof.recoveryArchive?.digest !== entry.receipt.digest || !same12(proof.receipt, entry.publication) || !same12(proof.profile, manifest.profile)) throw new Error("TRAVEL_NODE_RECOVERY_REQUIRED");
|
|
40700
41172
|
await verifyRuntimeGenerationIntegrityAsync(snapshot2, proof.integrity);
|
|
@@ -40702,7 +41174,7 @@ var TravelNodeAgent = class _TravelNodeAgent {
|
|
|
40702
41174
|
await check();
|
|
40703
41175
|
return { snapshot: snapshot2, manifest };
|
|
40704
41176
|
}
|
|
40705
|
-
const snapshot = join70(this.options.generationsDirectory, "snapshot-" +
|
|
41177
|
+
const snapshot = join70(this.options.generationsDirectory, "snapshot-" + randomUUID23());
|
|
40706
41178
|
await restoreRecoveryArchive({ archive: this.archive, id: entry.id, destination: snapshot, deletionWatermark: check, verifyDatabases: false });
|
|
40707
41179
|
validateRuntimeActivationSnapshot(snapshot, manifest, locations);
|
|
40708
41180
|
await check();
|
|
@@ -40733,14 +41205,14 @@ var TravelNodeAgent = class _TravelNodeAgent {
|
|
|
40733
41205
|
const prior = this.db.prepare("SELECT * FROM common_preparations WHERE digest=?").get(digest7);
|
|
40734
41206
|
if (prior) {
|
|
40735
41207
|
const snapshot2 = String(prior.snapshot);
|
|
40736
|
-
if (!isWithin(this.options.generationsDirectory, snapshot2) ||
|
|
41208
|
+
if (!isWithin(this.options.generationsDirectory, snapshot2) || realpathSync27(snapshot2) !== snapshot2 || prior.archive_digest !== entry.receipt.digest) throw new Error("TRAVEL_NODE_RECOVERY_REQUIRED");
|
|
40737
41209
|
const proof2 = JSON.parse(readPrivateFile(join70(snapshot2, ".runtime-publication-receipt.json"), 4 * 1024 * 1024).toString());
|
|
40738
41210
|
if (proof2.deletionVisibility?.deletionWatermark === this.keyWatermark) {
|
|
40739
41211
|
const deletionWatermark = await (await verifyCurrentHDeletionVisibilityAsync({ snapshot: snapshot2, manifest, layout: this.options.layout, gateway: this.options.gateway, ...control2 }))();
|
|
40740
41212
|
return { snapshot: snapshot2, manifest, deletionWatermark };
|
|
40741
41213
|
}
|
|
40742
41214
|
}
|
|
40743
|
-
const snapshot = join70(this.options.generationsDirectory, "snapshot-" +
|
|
41215
|
+
const snapshot = join70(this.options.generationsDirectory, "snapshot-" + randomUUID23());
|
|
40744
41216
|
await restoreCurrentHForDeletion({ archive: this.archive, id: id2, destination: snapshot, ...control2 });
|
|
40745
41217
|
writeFileSync40(join70(snapshot, ".runtime-publication-receipt.json"), JSON.stringify({
|
|
40746
41218
|
format: "engine7-runtime-publication-restore-v1",
|
|
@@ -41132,7 +41604,7 @@ var TravelNodeAgent = class _TravelNodeAgent {
|
|
|
41132
41604
|
});
|
|
41133
41605
|
}
|
|
41134
41606
|
assertActive();
|
|
41135
|
-
const destination = join70(this.options.generationsDirectory, "runtime-" +
|
|
41607
|
+
const destination = join70(this.options.generationsDirectory, "runtime-" + randomUUID23()), baselineId = "node-" + randomUUID23();
|
|
41136
41608
|
this.db.prepare("INSERT INTO generations VALUES(?,?,?,?,?)").run(binding, destination, digest7, "{}", "ACTIVATING");
|
|
41137
41609
|
try {
|
|
41138
41610
|
const activation = await activateRuntimeGeneration({
|
|
@@ -41386,12 +41858,12 @@ var TravelNodeAgent = class _TravelNodeAgent {
|
|
|
41386
41858
|
this.db.prepare("INSERT INTO recovery_jobs VALUES(?,?,?,?,?,?,?,'PREPARED',NULL)").run(binding, receipt2.digest, common.id, local.id, remote.id, JSON.stringify(manifests), this.keyWatermark);
|
|
41387
41859
|
}
|
|
41388
41860
|
}
|
|
41389
|
-
const
|
|
41390
|
-
if (
|
|
41391
|
-
if (
|
|
41861
|
+
const jobs2 = this.db.prepare("SELECT * FROM recovery_jobs WHERE binding=? ORDER BY local_digest").all(binding);
|
|
41862
|
+
if (jobs2.some((job) => job.deletion_watermark !== this.keyWatermark)) throw new Error("RECOVERY_DELETION_BARRIER");
|
|
41863
|
+
if (jobs2.some((job) => job.state !== "DONE")) {
|
|
41392
41864
|
trace("normal-admission");
|
|
41393
41865
|
await this.withNormalRecoveryBoundary(async () => {
|
|
41394
|
-
for (const job of
|
|
41866
|
+
for (const job of jobs2) {
|
|
41395
41867
|
if (job.state === "DONE") continue;
|
|
41396
41868
|
await check();
|
|
41397
41869
|
const result = await admitNormalRecoveryArchives({
|
|
@@ -41900,7 +42372,7 @@ var RemoteTravelNodeAuthority = class _RemoteTravelNodeAuthority extends RemoteT
|
|
|
41900
42372
|
};
|
|
41901
42373
|
|
|
41902
42374
|
// src/continuity/authority-client.ts
|
|
41903
|
-
import { Agent as
|
|
42375
|
+
import { Agent as Agent4, request as request5 } from "node:https";
|
|
41904
42376
|
var publicErrors = /* @__PURE__ */ new Set([
|
|
41905
42377
|
"TRAVEL_HEARTBEAT_REPLAY",
|
|
41906
42378
|
"TRAVEL_BOOT_MISMATCH",
|
|
@@ -41937,8 +42409,8 @@ var TravelReportClient = class {
|
|
|
41937
42409
|
if (!Number.isSafeInteger(this.timeout) || this.timeout < 1 || this.timeout > 6e4) throw new Error("TRAVEL_CONTROL_INVALID_CONFIG");
|
|
41938
42410
|
this.key = options.key ? Buffer.from(options.key) : void 0;
|
|
41939
42411
|
const tls2 = { ca: options.ca, cert: options.cert, key: this.key, minVersion: "TLSv1.3", rejectUnauthorized: true, maxSockets: 1 };
|
|
41940
|
-
this.agent = new
|
|
41941
|
-
this.mutationAgent = new
|
|
42412
|
+
this.agent = new Agent4({ ...tls2, keepAlive: true });
|
|
42413
|
+
this.mutationAgent = new Agent4({ ...tls2, keepAlive: false });
|
|
41942
42414
|
}
|
|
41943
42415
|
agent;
|
|
41944
42416
|
mutationAgent;
|
|
@@ -42127,7 +42599,7 @@ var TravelManagementClient = class extends TravelReportClient {
|
|
|
42127
42599
|
};
|
|
42128
42600
|
|
|
42129
42601
|
// src/continuity/gateway-server.ts
|
|
42130
|
-
import { Agent as
|
|
42602
|
+
import { Agent as Agent5, createServer as createServer5, request as request6 } from "node:https";
|
|
42131
42603
|
var prefix = "/travel/gateway/v1/";
|
|
42132
42604
|
var requestLimit2 = 24 * 1024 * 1024;
|
|
42133
42605
|
var responseLimit = 48 * 1024 * 1024;
|
|
@@ -42172,7 +42644,7 @@ var TravelGatewayClient = class {
|
|
|
42172
42644
|
this.timeout = options.timeoutMs ?? 15e3;
|
|
42173
42645
|
if (!Number.isSafeInteger(this.timeout) || this.timeout < 1 || this.timeout > 6e4) throw new Error("TRAVEL_GATEWAY_INVALID_TIMEOUT");
|
|
42174
42646
|
this.key = Buffer.from(options.key);
|
|
42175
|
-
this.agent = new
|
|
42647
|
+
this.agent = new Agent5({ ca: options.ca, cert: options.cert, key: this.key, minVersion: "TLSv1.3", rejectUnauthorized: true, keepAlive: true, maxSockets: 4 });
|
|
42176
42648
|
}
|
|
42177
42649
|
async call(action, input, retryStale = true, deadline = performance.now() + this.timeout) {
|
|
42178
42650
|
const body = Buffer.from(JSON.stringify(input));
|
|
@@ -42295,7 +42767,7 @@ var TravelGatewayClient = class {
|
|
|
42295
42767
|
};
|
|
42296
42768
|
|
|
42297
42769
|
// src/continuity/node-supervisor-client.ts
|
|
42298
|
-
import { Agent as
|
|
42770
|
+
import { Agent as Agent6, request as request7 } from "node:https";
|
|
42299
42771
|
|
|
42300
42772
|
// src/continuity/node-supervisor-protocol.ts
|
|
42301
42773
|
var nodeSupervisorPath = "/travel/node/v1";
|
|
@@ -42385,7 +42857,7 @@ var RemoteTravelNodeSupervisor = class {
|
|
|
42385
42857
|
this.timeout = options.timeoutMs ?? 18e4;
|
|
42386
42858
|
if (!Number.isSafeInteger(this.timeout) || this.timeout < 1 || this.timeout > 6e5) throw new Error("TRAVEL_NODE_CLIENT_CONFIG");
|
|
42387
42859
|
this.key = Buffer.from(options.key);
|
|
42388
|
-
const agent = () => new
|
|
42860
|
+
const agent = () => new Agent6({ ca: options.ca, cert: options.cert, key: this.key, minVersion: "TLSv1.3", rejectUnauthorized: true, keepAlive: true, maxSockets: 1 });
|
|
42389
42861
|
this.agents = { observe: agent(), permit: agent(), operation: agent(), stop: agent() };
|
|
42390
42862
|
}
|
|
42391
42863
|
principal;
|
|
@@ -42726,7 +43198,7 @@ async function startTravelNodeService(input) {
|
|
|
42726
43198
|
if (!nodeSupervisorRecord(input) || !nodeSupervisorRecord(input.principal) || !nodeSupervisorRecord(input.peer) || !nodeSupervisorRecord(input.control) || !nodeSupervisorRecord(input.management) || !nodeSupervisorRecord(input.data) || Object.hasOwn(input, "authorityDir")) throw new Error("TRAVEL_NODE_CONFIG");
|
|
42727
43199
|
const config = input;
|
|
42728
43200
|
assertPrivateDirectory(path34(config.generationsDirectory));
|
|
42729
|
-
const bootId2 = config.bootId ??
|
|
43201
|
+
const bootId2 = config.bootId ?? randomUUID24();
|
|
42730
43202
|
if (!nodeSupervisorId(bootId2)) throw new Error("TRAVEL_NODE_IDENTITY");
|
|
42731
43203
|
const serverTls = tls(config.tls), clientTls = tls(config.clientTls ?? config.tls);
|
|
42732
43204
|
const clients = [];
|
|
@@ -42826,7 +43298,7 @@ async function startTravelNodeService(input) {
|
|
|
42826
43298
|
if (JSON.stringify(Object.keys(config.initialReplica.databases).sort()) !== JSON.stringify(profile.databaseIds)) throw new Error("TRAVEL_NODE_REPLICA_NOT_READY");
|
|
42827
43299
|
for (const id2 of profile.databaseIds) {
|
|
42828
43300
|
const file2 = path34(config.initialReplica.databases[id2]), stat3 = lstatSync29(file2);
|
|
42829
|
-
if (!stat3.isFile() || stat3.isSymbolicLink() ||
|
|
43301
|
+
if (!stat3.isFile() || stat3.isSymbolicLink() || realpathSync28(file2) !== file2 || process.platform !== "win32" && (stat3.uid !== process.getuid() || stat3.mode & 63)) throw new Error("TRAVEL_NODE_PATH");
|
|
42830
43302
|
const db2 = new DatabaseSync37(file2, { allowExtension: id2 === "legacy" });
|
|
42831
43303
|
replicaHandles.push(db2);
|
|
42832
43304
|
databases[id2] = db2;
|
|
@@ -43116,12 +43588,12 @@ async function waitForPidGone(pid, timeoutMs = 5e3) {
|
|
|
43116
43588
|
import { readFileSync as readFileSync35, existsSync as existsSync41 } from "node:fs";
|
|
43117
43589
|
import { isAbsolute as isAbsolute17, resolve as resolve45 } from "node:path";
|
|
43118
43590
|
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
43119
|
-
import { execFile as
|
|
43120
|
-
import { promisify as
|
|
43591
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
43592
|
+
import { promisify as promisify6 } from "node:util";
|
|
43121
43593
|
import { createHash as createHash55 } from "node:crypto";
|
|
43122
43594
|
|
|
43123
43595
|
// src/continuity/user-seat-resource.ts
|
|
43124
|
-
import { spawn as
|
|
43596
|
+
import { spawn as spawn7 } from "node:child_process";
|
|
43125
43597
|
import { createHash as createHash51 } from "node:crypto";
|
|
43126
43598
|
import { isAbsolute as isAbsolute14, resolve as resolve42 } from "node:path";
|
|
43127
43599
|
var UserSeatResource = class {
|
|
@@ -43137,7 +43609,7 @@ var UserSeatResource = class {
|
|
|
43137
43609
|
identity;
|
|
43138
43610
|
call(action, input) {
|
|
43139
43611
|
return new Promise((done, reject) => {
|
|
43140
|
-
const child =
|
|
43612
|
+
const child = spawn7("/usr/bin/sudo", ["-n", "/usr/sbin/runuser", "-u", this.config.runAs.user, "--", this.config.runAs.node, this.config.runAs.entry, action, "--config", this.config.runAs.configFile], { stdio: ["pipe", "pipe", "pipe"] });
|
|
43141
43613
|
const chunks = [];
|
|
43142
43614
|
let bytes = 0, stderr = "";
|
|
43143
43615
|
const timer = setTimeout(() => child.kill("SIGKILL"), 12e4);
|
|
@@ -43185,7 +43657,7 @@ init_key_service_store();
|
|
|
43185
43657
|
import { DatabaseSync as DatabaseSync39 } from "node:sqlite";
|
|
43186
43658
|
import { createHash as createHash52 } from "node:crypto";
|
|
43187
43659
|
import { existsSync as existsSync39 } from "node:fs";
|
|
43188
|
-
import { accessSync, constants as constants14, lstatSync as lstatSync30, readdirSync as readdirSync15, readFileSync as readFileSync33, readlinkSync, realpathSync as
|
|
43660
|
+
import { accessSync, constants as constants14, lstatSync as lstatSync30, readdirSync as readdirSync15, readFileSync as readFileSync33, readlinkSync, realpathSync as realpathSync29, rmSync as rmSync7 } from "node:fs";
|
|
43189
43661
|
import { dirname as dirname27, isAbsolute as isAbsolute15, join as join71, resolve as resolve43, relative as relative15 } from "node:path";
|
|
43190
43662
|
var identity = (value2) => JSON.stringify([value2.tenantId, value2.companionId, value2.seatId]);
|
|
43191
43663
|
var sha11 = (value2) => createHash52("sha256").update(value2).digest("hex");
|
|
@@ -43200,7 +43672,7 @@ var LocalSeatResource = class {
|
|
|
43200
43672
|
check() {
|
|
43201
43673
|
if (!existsSync39(this.path)) return false;
|
|
43202
43674
|
const stat3 = lstatSync30(this.path);
|
|
43203
|
-
if (!stat3.isDirectory() || stat3.isSymbolicLink() ||
|
|
43675
|
+
if (!stat3.isDirectory() || stat3.isSymbolicLink() || realpathSync29(this.path) !== this.path || process.platform !== "win32" && stat3.uid !== process.getuid()) throw new Error("TRAVEL_RETIREMENT_PATH");
|
|
43204
43676
|
if (identity(JSON.parse(readPrivateFile(join71(this.path, ".travel-seat-resource.json"), 65536).toString())) !== identity(this.identity)) throw new Error("TRAVEL_RETIREMENT_IDENTITY");
|
|
43205
43677
|
return true;
|
|
43206
43678
|
}
|
|
@@ -43353,7 +43825,7 @@ var TravelRetirement = class {
|
|
|
43353
43825
|
|
|
43354
43826
|
// src/continuity/local-exit.ts
|
|
43355
43827
|
init_runtime_lock();
|
|
43356
|
-
import { cpSync as cpSync2, existsSync as existsSync40, mkdirSync as mkdirSync32, readFileSync as readFileSync34, readdirSync as readdirSync16, realpathSync as
|
|
43828
|
+
import { cpSync as cpSync2, existsSync as existsSync40, mkdirSync as mkdirSync32, readFileSync as readFileSync34, readdirSync as readdirSync16, realpathSync as realpathSync30, rmSync as rmSync8, writeFileSync as writeFileSync41 } from "node:fs";
|
|
43357
43829
|
import { DatabaseSync as DatabaseSync41 } from "node:sqlite";
|
|
43358
43830
|
import { isAbsolute as isAbsolute16, join as join72, dirname as dirname29, resolve as resolve44 } from "node:path";
|
|
43359
43831
|
import { createHash as createHash54, verify as verify3 } from "node:crypto";
|
|
@@ -43460,14 +43932,14 @@ function detachReplication(directory2) {
|
|
|
43460
43932
|
}
|
|
43461
43933
|
async function createOrdinaryLocalRecovery(options) {
|
|
43462
43934
|
const source = resolve44(options.stateDir), destination = resolve44(options.destination);
|
|
43463
|
-
if (!isAbsolute16(options.destination) || source !== options.stateDir || destination !== options.destination ||
|
|
43935
|
+
if (!isAbsolute16(options.destination) || source !== options.stateDir || destination !== options.destination || realpathSync30(source) !== source || destination === source || destination.startsWith(source + "/") || source.startsWith(destination + "/") || realpathSync30(dirname29(destination)) !== dirname29(destination)) throw new Error("TRAVEL_EXIT_PATH");
|
|
43464
43936
|
const activation = JSON.parse(readFileSync34(join72(source, ".travel-active.json"), "utf8")), permit = activation.permit, { signature: signature2, ...signed } = permit;
|
|
43465
43937
|
if (activation.format !== "engine7-runtime-activation-v1" || identity2(activation.identity) !== identity2(options.identity) || identity2(permit) !== identity2(options.identity) || permit.nodeId !== options.localNodeId || activation.nodeId !== options.localNodeId || !verify3(null, Buffer.from(JSON.stringify(signed)), options.publicKey, Buffer.from(signature2, "base64")) || identity2(options.dedupeReceipt.identity) !== identity2(options.identity) || options.dedupeReceipt.checkpointDigest !== options.checkpointDigest || options.dedupeReceipt.deletionWatermark !== permit.deletionWatermark) throw new Error("TRAVEL_EXIT_RECOVERY_REQUIRED");
|
|
43466
43938
|
return withCheckpointLock(source, async () => {
|
|
43467
43939
|
if (!options.authority || !options.principal || options.authority.publicKey !== options.publicKey) throw new Error("TRAVEL_EXIT_RECOVERY_REQUIRED");
|
|
43468
43940
|
const proof = await verifyStoppedLocalExitProof({ ...options, stateDir: source });
|
|
43469
43941
|
if (existsSync40(destination)) {
|
|
43470
|
-
if (
|
|
43942
|
+
if (realpathSync30(destination) !== destination) throw new Error("TRAVEL_EXIT_PATH");
|
|
43471
43943
|
let receipt2;
|
|
43472
43944
|
try {
|
|
43473
43945
|
receipt2 = JSON.parse(readPrivateFile(join72(destination, ".continuity/travel-exit-receipt.json"), 65536).toString());
|
|
@@ -43515,7 +43987,7 @@ async function createOrdinaryLocalRecovery(options) {
|
|
|
43515
43987
|
// src/continuity/retirement-main.ts
|
|
43516
43988
|
init_key_service_store();
|
|
43517
43989
|
init_key_service_store();
|
|
43518
|
-
var command =
|
|
43990
|
+
var command = promisify6(execFile6);
|
|
43519
43991
|
var sha14 = (value2) => createHash55("sha256").update(value2).digest("hex");
|
|
43520
43992
|
var path36 = (value2) => {
|
|
43521
43993
|
if (typeof value2 !== "string" || !isAbsolute17(value2) || resolve45(value2) !== value2) throw new Error("TRAVEL_RETIREMENT_PATH");
|
|
@@ -43590,7 +44062,7 @@ if (process.argv[1] && /[\\/](retirement-main\.ts|travel-retire\.mjs)$/.test(fil
|
|
|
43590
44062
|
}
|
|
43591
44063
|
|
|
43592
44064
|
// src/continuity/pairing-host.ts
|
|
43593
|
-
import { randomUUID as
|
|
44065
|
+
import { randomUUID as randomUUID25 } from "node:crypto";
|
|
43594
44066
|
async function startInitialPairingRuntime(node, authority, digest7, assertInitial) {
|
|
43595
44067
|
const started = performance.now(), trace = (phase) => {
|
|
43596
44068
|
if (process.env.ENGINE7_TRAVEL_TRACE === "1") process.stderr.write("[travel-initial-runtime] " + JSON.stringify({ phase, elapsedMs: Math.round(performance.now() - started) }) + "\n");
|
|
@@ -43609,7 +44081,7 @@ async function startInitialPairingRuntime(node, authority, digest7, assertInitia
|
|
|
43609
44081
|
}
|
|
43610
44082
|
function readManagedPairingHostConfig(stateDir, binding) {
|
|
43611
44083
|
const config = JSON.parse(readPrivateFile(binding.hostConfig, 65536).toString());
|
|
43612
|
-
if (binding.version !== 1 ||
|
|
44084
|
+
if (binding.version !== 1 || realpathSync31(config.stateDir) !== realpathSync31(stateDir) || JSON.stringify(binding.identity) !== JSON.stringify(config.identity)) throw new Error("TRAVEL_PAIRING_IDENTITY");
|
|
43613
44085
|
return config;
|
|
43614
44086
|
}
|
|
43615
44087
|
async function pauseInitialPairingIngress(state2, ingress, pair) {
|
|
@@ -43650,7 +44122,7 @@ function initialPairingSnapshot(options) {
|
|
|
43650
44122
|
};
|
|
43651
44123
|
}
|
|
43652
44124
|
var write2 = (file2, value2) => writeFileSync42(file2, JSON.stringify(value2), { mode: 384, flush: true });
|
|
43653
|
-
var
|
|
44125
|
+
var delay3 = (ms) => new Promise((done) => setTimeout(done, ms));
|
|
43654
44126
|
function rpc(url, tls2, token, body, timeout = 6e5) {
|
|
43655
44127
|
return new Promise((done, reject) => {
|
|
43656
44128
|
const req = request8(url, { method: "POST", ...tls2, minVersion: "TLSv1.3", headers: { Authorization: "Bearer " + token, "Content-Type": "application/json" } }, (res) => {
|
|
@@ -43676,7 +44148,7 @@ function rpc(url, tls2, token, body, timeout = 6e5) {
|
|
|
43676
44148
|
req.end(JSON.stringify(body));
|
|
43677
44149
|
});
|
|
43678
44150
|
}
|
|
43679
|
-
function startPairingRelays(material, spawnRelay =
|
|
44151
|
+
function startPairingRelays(material, spawnRelay = spawn8) {
|
|
43680
44152
|
const directory2 = material.directory, ports = material.ports;
|
|
43681
44153
|
let stopped = false;
|
|
43682
44154
|
const lanes = [{ name: "control", forward: ["authority", "gateway", "key", "pairing", "cloudManagement", "console", "cloudApi"], reverse: ["localManagement"] }, { name: "data", forward: ["cloudData"], reverse: ["localData"] }];
|
|
@@ -43716,11 +44188,11 @@ async function startPairingHost(material, startRelays = startPairingRelays) {
|
|
|
43716
44188
|
if (JSON.stringify(binding.identity) !== JSON.stringify(material.identity)) throw new Error("TRAVEL_PAIRING_IDENTITY");
|
|
43717
44189
|
const ownerFile = join73(directory2, "host-owner.sqlite");
|
|
43718
44190
|
preparePrivateDatabase(ownerFile);
|
|
43719
|
-
const
|
|
44191
|
+
const owner2 = new DatabaseSync42(ownerFile);
|
|
43720
44192
|
try {
|
|
43721
|
-
|
|
44193
|
+
owner2.exec("CREATE TABLE IF NOT EXISTS owner(id INTEGER PRIMARY KEY);BEGIN IMMEDIATE");
|
|
43722
44194
|
} catch {
|
|
43723
|
-
|
|
44195
|
+
owner2.close();
|
|
43724
44196
|
throw new Error("TRAVEL_PAIRING_BUSY");
|
|
43725
44197
|
}
|
|
43726
44198
|
const lifecycleFile = join73(directory2, "lifecycle.json");
|
|
@@ -43783,7 +44255,7 @@ async function startPairingHost(material, startRelays = startPairingRelays) {
|
|
|
43783
44255
|
if (!stoppedOrdinary || stopped || sourcePid() !== null) return;
|
|
43784
44256
|
const log = openSync21(join73(directory2, "ordinary-resumed.log"), "a", 384);
|
|
43785
44257
|
try {
|
|
43786
|
-
const child =
|
|
44258
|
+
const child = spawn8(process.execPath, [join73(material.engineDir, "dist/main.mjs"), "--engine-config", material.configPath], { cwd: material.stateDir, detached: true, stdio: ["ignore", log, log] });
|
|
43787
44259
|
await new Promise((done, reject) => {
|
|
43788
44260
|
child.once("spawn", done);
|
|
43789
44261
|
child.once("error", reject);
|
|
@@ -43811,7 +44283,7 @@ async function startPairingHost(material, startRelays = startPairingRelays) {
|
|
|
43811
44283
|
break;
|
|
43812
44284
|
} catch (error) {
|
|
43813
44285
|
if (attempt >= 30 || !["busy", "not_ready", "service_unavailable"].includes(error.message)) throw error;
|
|
43814
|
-
await
|
|
44286
|
+
await delay3(1e3);
|
|
43815
44287
|
}
|
|
43816
44288
|
}
|
|
43817
44289
|
lifecycle.state = "MANAGED";
|
|
@@ -43845,13 +44317,13 @@ async function startPairingHost(material, startRelays = startPairingRelays) {
|
|
|
43845
44317
|
save();
|
|
43846
44318
|
const baselineDir = join73(directory2, "first-baseline");
|
|
43847
44319
|
if (lifecycle.recapture && existsSync42(join73(baselineDir, "ready.json"))) {
|
|
43848
|
-
renameSync12(baselineDir, join73(directory2, "unused-baseline-" +
|
|
44320
|
+
renameSync12(baselineDir, join73(directory2, "unused-baseline-" + randomUUID25()));
|
|
43849
44321
|
delete lifecycle.recapture;
|
|
43850
44322
|
save();
|
|
43851
44323
|
}
|
|
43852
44324
|
let baseline;
|
|
43853
44325
|
if (!existsSync42(join73(baselineDir, "ready.json"))) {
|
|
43854
|
-
if (existsSync42(baselineDir)) renameSync12(baselineDir, join73(directory2, "failed-baseline-" +
|
|
44326
|
+
if (existsSync42(baselineDir)) renameSync12(baselineDir, join73(directory2, "failed-baseline-" + randomUUID25()));
|
|
43855
44327
|
const key3 = readPrivateFile(join73(directory2, "data.key"), 32);
|
|
43856
44328
|
let lastProgressSave = 0, lastPhase = "";
|
|
43857
44329
|
try {
|
|
@@ -43894,7 +44366,7 @@ async function startPairingHost(material, startRelays = startPairingRelays) {
|
|
|
43894
44366
|
if (current2.activeNodeId !== null) {
|
|
43895
44367
|
for (let attempt = 0; !(await authority.status()).expired; attempt++) {
|
|
43896
44368
|
if (attempt >= 120) throw new Error("TRAVEL_INITIAL_SOURCE_RUNNING");
|
|
43897
|
-
await
|
|
44369
|
+
await delay3(500);
|
|
43898
44370
|
}
|
|
43899
44371
|
}
|
|
43900
44372
|
await startInitialPairingRuntime(localService.node, { acquire: (ready) => {
|
|
@@ -43921,8 +44393,8 @@ async function startPairingHost(material, startRelays = startPairingRelays) {
|
|
|
43921
44393
|
save();
|
|
43922
44394
|
process.stderr.write(JSON.stringify({ state: lifecycle.state, ...failure2, stack: error instanceof Error ? error.stack?.split("\n").slice(1, 7) : [] }) + "\n");
|
|
43923
44395
|
};
|
|
43924
|
-
const startInitial = (
|
|
43925
|
-
if (
|
|
44396
|
+
const startInitial = (requestId2) => {
|
|
44397
|
+
if (requestId2 !== lifecycle.requestId) throw new Error("invalid_request");
|
|
43926
44398
|
if (!pendingInitial) return;
|
|
43927
44399
|
pendingInitial = false;
|
|
43928
44400
|
initial ??= initialize2().catch(recordInitialFailure).finally(() => {
|
|
@@ -43965,14 +44437,14 @@ async function startPairingHost(material, startRelays = startPairingRelays) {
|
|
|
43965
44437
|
lifecycle.automatic = action === "auto_on";
|
|
43966
44438
|
save();
|
|
43967
44439
|
} else if (action === "to_cloud" || action === "sync") {
|
|
43968
|
-
const target = action === "sync" ? "local" : "cloud",
|
|
43969
|
-
if (!
|
|
43970
|
-
if (lifecycle.requestId && (lifecycle.requestId !==
|
|
44440
|
+
const target = action === "sync" ? "local" : "cloud", requestId2 = action === "sync" ? lifecycle.requestId ?? randomUUID25() : payload?.requestId;
|
|
44441
|
+
if (!requestId2 || !/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(requestId2)) throw new Error("invalid_request");
|
|
44442
|
+
if (lifecycle.requestId && (lifecycle.requestId !== requestId2 || (lifecycle.target ?? "cloud") !== target)) throw new Error("busy");
|
|
43971
44443
|
if (!lifecycle.requestId) {
|
|
43972
44444
|
lifecycle.state = "STARTING";
|
|
43973
44445
|
lifecycle.startedAt = Date.now();
|
|
43974
44446
|
}
|
|
43975
|
-
lifecycle.requestId =
|
|
44447
|
+
lifecycle.requestId = requestId2;
|
|
43976
44448
|
lifecycle.target = target;
|
|
43977
44449
|
delete lifecycle.error;
|
|
43978
44450
|
save();
|
|
@@ -43991,7 +44463,7 @@ async function startPairingHost(material, startRelays = startPairingRelays) {
|
|
|
43991
44463
|
break;
|
|
43992
44464
|
} catch (error) {
|
|
43993
44465
|
if (attempt >= 20) throw error;
|
|
43994
|
-
await
|
|
44466
|
+
await delay3(500);
|
|
43995
44467
|
}
|
|
43996
44468
|
}
|
|
43997
44469
|
if (lifecycle.state === "PAIRED") await pauseInitialPairingIngress(lifecycle.state, gatewayIngress, pair);
|
|
@@ -43999,7 +44471,7 @@ async function startPairingHost(material, startRelays = startPairingRelays) {
|
|
|
43999
44471
|
for (let attempt = 0; ; attempt++) {
|
|
44000
44472
|
if ((await cloudClient.observe()).connected) break;
|
|
44001
44473
|
if (attempt >= 30) throw new Error("TRAVEL_PAIRING_HEALTH");
|
|
44002
|
-
await
|
|
44474
|
+
await delay3(500);
|
|
44003
44475
|
}
|
|
44004
44476
|
hostServer = createTravelConsoleServer({ manager: { execute }, identity: material.identity, token: consoleToken, startInitial, cert: readFileSync36(join73(directory2, "tls/local-server.pem")), key: readPrivateFile(join73(directory2, "tls/local-server.key"), 65536) });
|
|
44005
44477
|
await new Promise((done, reject) => {
|
|
@@ -44036,7 +44508,7 @@ async function startPairingHost(material, startRelays = startPairingRelays) {
|
|
|
44036
44508
|
localClient.close();
|
|
44037
44509
|
cloudClient.close();
|
|
44038
44510
|
authority.close();
|
|
44039
|
-
|
|
44511
|
+
owner2.close();
|
|
44040
44512
|
tls2.key.fill(0);
|
|
44041
44513
|
}
|
|
44042
44514
|
};
|
|
@@ -44051,7 +44523,7 @@ async function startPairingHost(material, startRelays = startPairingRelays) {
|
|
|
44051
44523
|
localClient.close();
|
|
44052
44524
|
cloudClient.close();
|
|
44053
44525
|
authority.close();
|
|
44054
|
-
|
|
44526
|
+
owner2.close();
|
|
44055
44527
|
tls2.key.fill(0);
|
|
44056
44528
|
}
|
|
44057
44529
|
throw error;
|