dsh-vscode-mode 0.19.2 → 0.20.0
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/README.md +6 -4
- package/lib/client.js +3868 -3486
- package/lib/client.js.map +1 -1
- package/lib/index.js +535 -42
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/archiveDb.ts +8 -8
- package/src/capture.ts +2 -2
- package/src/client/state/diffSummary.ts +30 -0
- package/src/client/state/reviewFeed.ts +60 -0
- package/src/client/ui/ConversationDiffDock.ts +9 -10
- package/src/client/ui/DiffBadge.ts +8 -6
- package/src/client/ui/DiffBox.ts +18 -0
- package/src/client/ui/DiffLauncher.ts +21 -5
- package/src/client/ui/EditorView.ts +17 -5
- package/src/client/ui/OfficialReview.ts +93 -0
- package/src/index.ts +3 -0
- package/src/model.ts +7 -3
- package/src/officialCapture.ts +199 -0
- package/src/reviewDb.ts +214 -0
- package/src/reviewRpc.ts +33 -0
- package/src/rpc.ts +14 -18
- package/src/shared/review.ts +91 -0
- package/src/shared/rpc.ts +7 -0
- package/src/store.ts +2 -2
package/lib/index.js
CHANGED
|
@@ -1209,11 +1209,14 @@ function fileMaxBatch(records, path) {
|
|
|
1209
1209
|
for (const r of records.values()) if (r.path === path && Number.isInteger(r.batch) && r.batch > m) m = r.batch;
|
|
1210
1210
|
return m;
|
|
1211
1211
|
}
|
|
1212
|
-
/**
|
|
1212
|
+
/** @public @author ddj 2026年10月26号 @param map Legacy records. @param max Cache target, never a pending retention limit. */
|
|
1213
1213
|
function prune(map, max = 200) {
|
|
1214
1214
|
if (map.size <= max) return;
|
|
1215
|
-
const sorted = [...map.values()].sort((a, b) => a.at < b.at ? -1 : 1);
|
|
1216
|
-
for (
|
|
1215
|
+
const sorted = [...map.values()].filter((record) => record.archived && recordResolved(record)).sort((a, b) => a.at < b.at ? -1 : 1);
|
|
1216
|
+
for (const record of sorted) {
|
|
1217
|
+
if (map.size <= max) break;
|
|
1218
|
+
map.delete(record.callId);
|
|
1219
|
+
}
|
|
1217
1220
|
}
|
|
1218
1221
|
/**
|
|
1219
1222
|
* 归档条目构造(一条批次一条)。
|
|
@@ -1926,7 +1929,7 @@ function dbFor(cwd) {
|
|
|
1926
1929
|
db.exec("CREATE TABLE IF NOT EXISTS metadata (name TEXT PRIMARY KEY, value TEXT NOT NULL)");
|
|
1927
1930
|
const version = db.prepare("SELECT value FROM metadata WHERE name='schema'").get();
|
|
1928
1931
|
const workspace = db.prepare("SELECT value FROM metadata WHERE name='cwd'").get();
|
|
1929
|
-
if (version && version.value !== "2" && version.value !== "3" || workspace && workspace.value !== cwd) throw new Error("归档数据库 schema/工作区不匹配");
|
|
1932
|
+
if (version && version.value !== "2" && version.value !== "3" && version.value !== "4" || workspace && workspace.value !== cwd) throw new Error("归档数据库 schema/工作区不匹配");
|
|
1930
1933
|
if (!!version !== !!workspace) throw new Error("归档数据库元数据不完整");
|
|
1931
1934
|
if (!version) {
|
|
1932
1935
|
if (db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name<>'metadata' LIMIT 1").get()) throw new Error("归档数据库缺失元数据且已有数据表");
|
|
@@ -1962,7 +1965,7 @@ function dbFor(cwd) {
|
|
|
1962
1965
|
throw error;
|
|
1963
1966
|
}
|
|
1964
1967
|
}
|
|
1965
|
-
if (version
|
|
1968
|
+
if (version && (version.value === "3" || version.value === "4")) {
|
|
1966
1969
|
const active = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='active_records'").get();
|
|
1967
1970
|
const source = db.prepare("SELECT value FROM metadata WHERE name='active_source'").get();
|
|
1968
1971
|
if (!active || !source) throw new Error("活跃记录数据库元数据不完整");
|
|
@@ -1984,7 +1987,8 @@ function dbFor(cwd) {
|
|
|
1984
1987
|
*/
|
|
1985
1988
|
async function migrateActive(cwd, source, confirm) {
|
|
1986
1989
|
const db = dbFor(cwd);
|
|
1987
|
-
|
|
1990
|
+
const version = String(db.prepare("SELECT value FROM metadata WHERE name='schema'").get().value);
|
|
1991
|
+
if (version === "3" || version === "4") return readActive(cwd);
|
|
1988
1992
|
const digest = source === null ? "absent" : createHash("sha256").update(source).digest("hex");
|
|
1989
1993
|
let recs = {};
|
|
1990
1994
|
if (source !== null) {
|
|
@@ -2026,7 +2030,7 @@ async function migrateActive(cwd, source, confirm) {
|
|
|
2026
2030
|
* @returns 迁移完成返回 true
|
|
2027
2031
|
*/
|
|
2028
2032
|
function activeReady(cwd) {
|
|
2029
|
-
return dbFor(cwd).prepare("SELECT value FROM metadata WHERE name='schema'").get().value
|
|
2033
|
+
return ["3", "4"].includes(String(dbFor(cwd).prepare("SELECT value FROM metadata WHERE name='schema'").get().value));
|
|
2030
2034
|
}
|
|
2031
2035
|
/**
|
|
2032
2036
|
* 对旧文件原文核对迁移标记,旧 Host 若继续写旧 sidecar 则拒绝启用新活跃库。
|
|
@@ -2048,7 +2052,7 @@ function checkActiveSource(cwd, source) {
|
|
|
2048
2052
|
*/
|
|
2049
2053
|
function readActive(cwd) {
|
|
2050
2054
|
const db = dbFor(cwd);
|
|
2051
|
-
if (
|
|
2055
|
+
if (!activeReady(cwd)) throw new Error("工作区活跃记录未迁移");
|
|
2052
2056
|
const recs = db.prepare("SELECT payload FROM active_records ORDER BY rowid").all().map((row) => JSON.parse(String(row.payload)));
|
|
2053
2057
|
return new Map(recs.map((rec) => [rec.callId, rec]));
|
|
2054
2058
|
}
|
|
@@ -2062,7 +2066,7 @@ function readActive(cwd) {
|
|
|
2062
2066
|
*/
|
|
2063
2067
|
function commitActive(cwd, changes, entries = []) {
|
|
2064
2068
|
const db = dbFor(cwd);
|
|
2065
|
-
if (
|
|
2069
|
+
if (!activeReady(cwd)) throw new Error("工作区活跃记录未迁移");
|
|
2066
2070
|
const upsert = db.prepare(`INSERT INTO active_records(call_id,payload,path,archived,pending,at) VALUES(?,?,?,?,?,?)
|
|
2067
2071
|
ON CONFLICT(call_id) DO UPDATE SET payload=excluded.payload,path=excluded.path,
|
|
2068
2072
|
archived=excluded.archived,pending=excluded.pending,at=excluded.at`);
|
|
@@ -2090,7 +2094,7 @@ function commitActive(cwd, changes, entries = []) {
|
|
|
2090
2094
|
*/
|
|
2091
2095
|
function activeSummary(cwd) {
|
|
2092
2096
|
const db = dbFor(cwd);
|
|
2093
|
-
if (
|
|
2097
|
+
if (!activeReady(cwd)) throw new Error("工作区活跃记录未迁移");
|
|
2094
2098
|
return {
|
|
2095
2099
|
active: Number(db.prepare("SELECT count(*) AS n FROM active_records WHERE archived=0").get().n),
|
|
2096
2100
|
pendingByFile: db.prepare("SELECT path, sum(pending) AS pending FROM active_records WHERE archived=0 AND pending>0 GROUP BY path ORDER BY pending DESC").all().map((row) => ({
|
|
@@ -2534,10 +2538,16 @@ async function readForCache(ctx, session, cache, path) {
|
|
|
2534
2538
|
*/
|
|
2535
2539
|
async function recordIsStale(ctx, session, cache, rec) {
|
|
2536
2540
|
if (rec.superseded === true) return true;
|
|
2537
|
-
if (!Array.isArray(rec.hunks) || !rec.hunks.length)
|
|
2541
|
+
if (!Array.isArray(rec.hunks) || !rec.hunks.length) {
|
|
2542
|
+
rec.conflict = true;
|
|
2543
|
+
return false;
|
|
2544
|
+
}
|
|
2538
2545
|
const state = await readForCache(ctx, session, cache, rec.path);
|
|
2539
2546
|
if (state.kind === "unavailable") return false;
|
|
2540
|
-
if (state.kind === "missing")
|
|
2547
|
+
if (state.kind === "missing") {
|
|
2548
|
+
rec.conflict = true;
|
|
2549
|
+
return false;
|
|
2550
|
+
}
|
|
2541
2551
|
if (rec.create === true) return false;
|
|
2542
2552
|
const pending = rec.hunks.map((_, idx) => ({
|
|
2543
2553
|
idx,
|
|
@@ -6968,7 +6978,7 @@ function buildLocalRecord(exec, args, result) {
|
|
|
6968
6978
|
if (typeof path !== "string" || !path) return null;
|
|
6969
6979
|
const before = value && typeof value.before === "string" ? value.before : null;
|
|
6970
6980
|
const after = value && typeof value.after === "string" ? value.after : typeof args.content === "string" ? args.content : null;
|
|
6971
|
-
const create = exec.name === "write" &&
|
|
6981
|
+
const create = exec.name === "write" && value?.operation === "create";
|
|
6972
6982
|
const callHunk = exec.name === "edit" && typeof args.old_string === "string" && typeof args.new_string === "string" ? {
|
|
6973
6983
|
oldText: args.old_string,
|
|
6974
6984
|
newText: args.new_string
|
|
@@ -7170,6 +7180,458 @@ async function captureToolResult(ctx, registry, exec, result) {
|
|
|
7170
7180
|
}
|
|
7171
7181
|
}
|
|
7172
7182
|
//#endregion
|
|
7183
|
+
//#region src/reviewDb.ts
|
|
7184
|
+
/** Official history shares the archive connection, but never the legacy callId namespace. @author ddj 2026年10月26号 */
|
|
7185
|
+
/** @public @author ddj 2026年10月26号 @param cwd Migrated workspace. @returns Schema4 connection; DDL and version change roll back together. */
|
|
7186
|
+
function reviewDb(cwd) {
|
|
7187
|
+
if (!activeReady(cwd)) throw new Error("官方审查要求先完成活跃库迁移");
|
|
7188
|
+
const db = dbFor(cwd);
|
|
7189
|
+
if (db.prepare("SELECT value FROM metadata WHERE name='schema'").get().value === "4") return db;
|
|
7190
|
+
db.exec("BEGIN IMMEDIATE");
|
|
7191
|
+
try {
|
|
7192
|
+
db.exec(`CREATE TABLE review_snapshots (
|
|
7193
|
+
session_id TEXT NOT NULL, turn INTEGER NOT NULL, seq INTEGER NOT NULL,
|
|
7194
|
+
payload TEXT NOT NULL, digest TEXT NOT NULL, current INTEGER NOT NULL DEFAULT 1,
|
|
7195
|
+
PRIMARY KEY(session_id,turn,seq));
|
|
7196
|
+
CREATE TABLE review_files (
|
|
7197
|
+
id TEXT PRIMARY KEY, session_id TEXT NOT NULL, turn INTEGER NOT NULL, seq INTEGER NOT NULL,
|
|
7198
|
+
identity TEXT NOT NULL, summary TEXT NOT NULL, diff TEXT NOT NULL,
|
|
7199
|
+
decision TEXT NOT NULL DEFAULT 'pending', revision INTEGER NOT NULL DEFAULT 0,
|
|
7200
|
+
current INTEGER NOT NULL DEFAULT 1);
|
|
7201
|
+
CREATE INDEX review_pending ON review_files(current,decision,id);
|
|
7202
|
+
CREATE INDEX review_turn ON review_files(session_id,turn,seq);
|
|
7203
|
+
CREATE TABLE review_capture (
|
|
7204
|
+
session_id TEXT NOT NULL, turn INTEGER NOT NULL, seq INTEGER NOT NULL,
|
|
7205
|
+
state TEXT NOT NULL, error TEXT, PRIMARY KEY(session_id,turn,seq));
|
|
7206
|
+
CREATE TABLE review_ops (
|
|
7207
|
+
operation_id TEXT PRIMARY KEY, request TEXT NOT NULL, state TEXT NOT NULL, result TEXT,
|
|
7208
|
+
evidence TEXT);
|
|
7209
|
+
UPDATE metadata SET value='4' WHERE name='schema';`);
|
|
7210
|
+
db.exec("COMMIT");
|
|
7211
|
+
} catch (error) {
|
|
7212
|
+
if (db.isTransaction) db.exec("ROLLBACK");
|
|
7213
|
+
throw error;
|
|
7214
|
+
}
|
|
7215
|
+
return db;
|
|
7216
|
+
}
|
|
7217
|
+
/** @private @author ddj 2026年10月26号 @param text Canonical serialized input. @returns Collision-resistant identity. */
|
|
7218
|
+
function digest(text) {
|
|
7219
|
+
return createHash("sha256").update(text).digest("hex");
|
|
7220
|
+
}
|
|
7221
|
+
/** @public @author ddj 2026年10月26号 @param cwd Workspace. @param snapshot Complete staged event. @returns False for late versions; commits facts, pointers and capture state atomically. */
|
|
7222
|
+
function saveSnapshot(cwd, snapshot) {
|
|
7223
|
+
const db = reviewDb(cwd);
|
|
7224
|
+
const { sessionId, turn, seq } = snapshot;
|
|
7225
|
+
if (snapshot.summary.cwd !== cwd || snapshot.summary.turn !== turn || snapshot.files.length !== snapshot.summary.files.length) throw new Error("官方采集不完整");
|
|
7226
|
+
if (new Set(snapshot.files.map((file) => file.identity)).size !== snapshot.files.length) throw new Error("官方文件身份重复");
|
|
7227
|
+
const hash = digest(JSON.stringify({
|
|
7228
|
+
...snapshot,
|
|
7229
|
+
capturedAt: ""
|
|
7230
|
+
}));
|
|
7231
|
+
db.exec("BEGIN IMMEDIATE");
|
|
7232
|
+
try {
|
|
7233
|
+
const prior = db.prepare("SELECT digest FROM review_snapshots WHERE session_id=? AND turn=? AND seq=?").get(sessionId, turn, seq);
|
|
7234
|
+
if (prior && prior.digest !== hash) throw new Error("同一官方事件的内容发生变化");
|
|
7235
|
+
const latest = db.prepare("SELECT MAX(seq) AS seq FROM review_snapshots WHERE session_id=? AND turn=?").get(sessionId, turn);
|
|
7236
|
+
if (prior || typeof latest.seq === "number" && latest.seq > seq) {
|
|
7237
|
+
db.exec("COMMIT");
|
|
7238
|
+
return false;
|
|
7239
|
+
}
|
|
7240
|
+
insertSnapshot(db, snapshot, hash);
|
|
7241
|
+
db.prepare("INSERT INTO review_capture VALUES(?,?,?,'complete',NULL) ON CONFLICT(session_id,turn,seq) DO UPDATE SET state='complete',error=NULL").run(sessionId, turn, seq);
|
|
7242
|
+
db.exec("COMMIT");
|
|
7243
|
+
return true;
|
|
7244
|
+
} catch (error) {
|
|
7245
|
+
if (db.isTransaction) db.exec("ROLLBACK");
|
|
7246
|
+
throw error;
|
|
7247
|
+
}
|
|
7248
|
+
}
|
|
7249
|
+
/** @public @author ddj 2026年10月27号 @param cwd Workspace. @param resolvePath Backend path adapter. @returns Repairs only historical object-string identities; preserves IDs, decisions and immutable official facts. @throws Resolution or concurrent payload changes. */
|
|
7250
|
+
async function repairPaths(cwd, resolvePath) {
|
|
7251
|
+
const db = reviewDb(cwd);
|
|
7252
|
+
const broken = db.prepare(`SELECT DISTINCT s.* FROM review_snapshots s JOIN review_files f
|
|
7253
|
+
USING(session_id,turn,seq) WHERE f.identity='[object Object]'`).all();
|
|
7254
|
+
for (const row of broken) {
|
|
7255
|
+
const snapshot = JSON.parse(String(row.payload));
|
|
7256
|
+
for (const file of snapshot.files) {
|
|
7257
|
+
if (file.identity !== "[object Object]") continue;
|
|
7258
|
+
file.identity = await resolvePath(snapshot.summary.cwd, file.diff.path);
|
|
7259
|
+
if (!file.identity || file.identity === "[object Object]") throw new Error("官方文件路径修复失败");
|
|
7260
|
+
}
|
|
7261
|
+
if (new Set(snapshot.files.map((file) => file.identity)).size !== snapshot.files.length) throw new Error("官方文件身份重复");
|
|
7262
|
+
db.exec("BEGIN IMMEDIATE");
|
|
7263
|
+
try {
|
|
7264
|
+
if (db.prepare("SELECT payload FROM review_snapshots WHERE session_id=? AND turn=? AND seq=?").get(snapshot.sessionId, snapshot.turn, snapshot.seq)?.payload === row.payload) {
|
|
7265
|
+
for (const file of snapshot.files) db.prepare(`UPDATE review_files SET identity=? WHERE session_id=? AND turn=? AND seq=?
|
|
7266
|
+
AND identity='[object Object]' AND json_extract(diff,'$.path')=?`).run(file.identity, snapshot.sessionId, snapshot.turn, snapshot.seq, file.diff.path);
|
|
7267
|
+
db.prepare("UPDATE review_snapshots SET payload=?,digest=? WHERE session_id=? AND turn=? AND seq=?").run(JSON.stringify(snapshot), digest(JSON.stringify({
|
|
7268
|
+
...snapshot,
|
|
7269
|
+
capturedAt: ""
|
|
7270
|
+
})), snapshot.sessionId, snapshot.turn, snapshot.seq);
|
|
7271
|
+
}
|
|
7272
|
+
db.exec("COMMIT");
|
|
7273
|
+
} catch (error) {
|
|
7274
|
+
if (db.isTransaction) db.exec("ROLLBACK");
|
|
7275
|
+
throw error;
|
|
7276
|
+
}
|
|
7277
|
+
}
|
|
7278
|
+
}
|
|
7279
|
+
/** @private @author ddj 2026年10月26号 @param db Transaction. @param snapshot Source payload. @param hash Source digest. */
|
|
7280
|
+
function insertSnapshot(db, snapshot, hash) {
|
|
7281
|
+
const { sessionId, turn, seq } = snapshot;
|
|
7282
|
+
const previous = db.prepare("SELECT identity,diff,decision FROM review_files WHERE session_id=? AND turn=? AND current=1").all(sessionId, turn);
|
|
7283
|
+
db.prepare("UPDATE review_snapshots SET current=0 WHERE session_id=? AND turn=?").run(sessionId, turn);
|
|
7284
|
+
db.prepare("UPDATE review_files SET current=0 WHERE session_id=? AND turn=?").run(sessionId, turn);
|
|
7285
|
+
db.prepare("INSERT INTO review_snapshots VALUES(?,?,?,?,?,1)").run(sessionId, turn, seq, JSON.stringify(snapshot), hash);
|
|
7286
|
+
const insert = db.prepare("INSERT INTO review_files VALUES(?,?,?,?,?,?,?,?,0,1)");
|
|
7287
|
+
for (const [index, file] of snapshot.files.entries()) {
|
|
7288
|
+
const encoded = JSON.stringify(file.diff);
|
|
7289
|
+
const unchanged = previous.find((item) => item.identity === file.identity && item.diff === encoded);
|
|
7290
|
+
const id = digest(JSON.stringify([
|
|
7291
|
+
sessionId,
|
|
7292
|
+
turn,
|
|
7293
|
+
seq,
|
|
7294
|
+
file.identity
|
|
7295
|
+
]));
|
|
7296
|
+
insert.run(id, sessionId, turn, seq, file.identity, JSON.stringify(snapshot.summary.files[index]), encoded, unchanged?.decision ?? "pending");
|
|
7297
|
+
}
|
|
7298
|
+
}
|
|
7299
|
+
/** @public @author ddj 2026年10月26号 @param cwd Workspace. @param gap Announced event identity. @param state Durable inbox or explicit failure. */
|
|
7300
|
+
function captureState(cwd, gap, state) {
|
|
7301
|
+
reviewDb(cwd).prepare(`INSERT INTO review_capture VALUES(?,?,?,?,?) ON CONFLICT(session_id,turn,seq)
|
|
7302
|
+
DO UPDATE SET state=excluded.state,error=excluded.error WHERE review_capture.state<>'complete'`).run(gap.sessionId, gap.turn, gap.seq, state, gap.error);
|
|
7303
|
+
}
|
|
7304
|
+
/** @private @author ddj 2026年10月26号 @param row File and state. @returns Wire-safe summary without hunks. */
|
|
7305
|
+
function itemOf(row) {
|
|
7306
|
+
const summary = JSON.parse(String(row.summary));
|
|
7307
|
+
const kind = row.kind ?? JSON.parse(String(row.diff)).kind;
|
|
7308
|
+
return {
|
|
7309
|
+
id: String(row.id),
|
|
7310
|
+
sessionId: String(row.session_id),
|
|
7311
|
+
turn: Number(row.turn),
|
|
7312
|
+
seq: Number(row.seq),
|
|
7313
|
+
...summary,
|
|
7314
|
+
currentPath: String(row.identity),
|
|
7315
|
+
kind,
|
|
7316
|
+
decision: row.decision,
|
|
7317
|
+
revision: Number(row.revision),
|
|
7318
|
+
current: row.current === 1
|
|
7319
|
+
};
|
|
7320
|
+
}
|
|
7321
|
+
/** @public @author ddj 2026年10月26号 @param cwd Workspace. @param cursor Page offset. @param history Include withdrawn/decided history. @returns Bounded metadata page; pending across all source sessions/turns. */
|
|
7322
|
+
function reviewPage(cwd, cursor = 0, history = false, path) {
|
|
7323
|
+
const db = reviewDb(cwd);
|
|
7324
|
+
const offset = Number.isSafeInteger(cursor) && cursor >= 0 ? cursor : 0;
|
|
7325
|
+
const conditions = history ? [] : ["current=1 AND decision='pending'"];
|
|
7326
|
+
if (path !== void 0) conditions.push("identity=?");
|
|
7327
|
+
const clause = conditions.length ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
7328
|
+
const parameters = path === void 0 ? [offset] : [path, offset];
|
|
7329
|
+
const rows = db.prepare(`SELECT id,session_id,turn,seq,identity,summary,decision,revision,current,
|
|
7330
|
+
json_extract(diff,'$.kind') AS kind FROM review_files ${clause} ORDER BY rowid DESC LIMIT 51 OFFSET ?`).all(...parameters);
|
|
7331
|
+
const count = db.prepare("SELECT COUNT(*) AS n FROM review_files WHERE current=1 AND decision='pending'").get();
|
|
7332
|
+
const gaps = db.prepare("SELECT * FROM review_capture WHERE state<>'complete' ORDER BY seq DESC LIMIT 50").all();
|
|
7333
|
+
const capped = db.prepare(`SELECT session_id,turn,seq,json_extract(payload,'$.summary.total') AS total,
|
|
7334
|
+
json_array_length(payload,'$.summary.files') AS listed FROM review_snapshots WHERE current=1
|
|
7335
|
+
AND json_extract(payload,'$.summary.total')>json_array_length(payload,'$.summary.files') LIMIT 50`).all();
|
|
7336
|
+
const files = db.prepare(`SELECT identity,MIN(json_extract(summary,'$.display')) AS label,COUNT(*) AS n
|
|
7337
|
+
FROM review_files WHERE current=1 AND decision='pending' GROUP BY identity ORDER BY identity`).all();
|
|
7338
|
+
const covered = db.prepare("SELECT DISTINCT identity FROM review_files").all();
|
|
7339
|
+
return {
|
|
7340
|
+
overview: {
|
|
7341
|
+
files: files.map((row) => ({
|
|
7342
|
+
sourceKind: "official",
|
|
7343
|
+
path: String(row.identity),
|
|
7344
|
+
label: String(row.label),
|
|
7345
|
+
pending: Number(row.n)
|
|
7346
|
+
})),
|
|
7347
|
+
coveredPaths: covered.map((row) => String(row.identity))
|
|
7348
|
+
},
|
|
7349
|
+
items: rows.slice(0, 50).map(itemOf),
|
|
7350
|
+
pending: Number(count.n),
|
|
7351
|
+
nextCursor: rows.length > 50 ? offset + 50 : null,
|
|
7352
|
+
gaps: [...gaps.map((row) => ({
|
|
7353
|
+
sessionId: String(row.session_id),
|
|
7354
|
+
turn: Number(row.turn),
|
|
7355
|
+
seq: Number(row.seq),
|
|
7356
|
+
error: String(row.error || "采集中或上次采集被中断")
|
|
7357
|
+
})), ...capped.map((row) => ({
|
|
7358
|
+
sessionId: String(row.session_id),
|
|
7359
|
+
turn: Number(row.turn),
|
|
7360
|
+
seq: Number(row.seq),
|
|
7361
|
+
error: `官方列表已截断:总计 ${row.total} 个文件,仅提供 ${row.listed} 个`
|
|
7362
|
+
}))]
|
|
7363
|
+
};
|
|
7364
|
+
}
|
|
7365
|
+
/** @public @author ddj 2026年10月26号 @param cwd Migrated workspace. @param path Legacy write target. @returns Whether any official version owns the file, including decided history. */
|
|
7366
|
+
function hasOfficial(cwd, path) {
|
|
7367
|
+
const db = dbFor(cwd);
|
|
7368
|
+
if (!db.prepare("SELECT 1 FROM sqlite_master WHERE name='review_files' AND type='table'").get()) return false;
|
|
7369
|
+
if (/^[A-Za-z]:[\\/]/.test(path)) return !!db.prepare("SELECT 1 FROM review_files WHERE lower(replace(identity,char(92),'/'))=? LIMIT 1").get(path.replace(/\\/g, "/").toLowerCase());
|
|
7370
|
+
return !!db.prepare("SELECT 1 FROM review_files WHERE identity=? LIMIT 1").get(path);
|
|
7371
|
+
}
|
|
7372
|
+
/** @public @author ddj 2026年10月26号 @param cwd Workspace. @param id Immutable file identity. @returns Historical patch, not a reconstruction from disk. */
|
|
7373
|
+
function reviewDetail(cwd, id) {
|
|
7374
|
+
const row = reviewDb(cwd).prepare(`SELECT f.*,json_extract(s.payload,'$.capturedAt') AS captured_at FROM review_files f JOIN review_snapshots s
|
|
7375
|
+
USING(session_id,turn,seq) WHERE f.id=?`).get(id);
|
|
7376
|
+
if (!row) return null;
|
|
7377
|
+
return {
|
|
7378
|
+
item: itemOf(row),
|
|
7379
|
+
diff: JSON.parse(String(row.diff)),
|
|
7380
|
+
capturedAt: String(row.captured_at),
|
|
7381
|
+
capability: {
|
|
7382
|
+
keep: row.current === 1 && row.decision === "pending",
|
|
7383
|
+
undo: false,
|
|
7384
|
+
reason: "官方仅提供差异块,缺少可验证的历史全文及原始字节;拒绝写回已禁用。可标记已审或打开当前文件继续编辑。"
|
|
7385
|
+
}
|
|
7386
|
+
};
|
|
7387
|
+
}
|
|
7388
|
+
/** @public @author ddj 2026年10月26号 @param cwd Workspace. @param request Frozen identity/revision. @returns Idempotent decision; rejection never guesses a target. */
|
|
7389
|
+
function decideReview(cwd, request) {
|
|
7390
|
+
const db = reviewDb(cwd);
|
|
7391
|
+
const encoded = JSON.stringify(request);
|
|
7392
|
+
if (!request.operationId || request.operationId.length > 128) throw new Error("operationId 无效");
|
|
7393
|
+
db.exec("BEGIN IMMEDIATE");
|
|
7394
|
+
try {
|
|
7395
|
+
const previous = db.prepare("SELECT request,result FROM review_ops WHERE operation_id=?").get(request.operationId);
|
|
7396
|
+
if (previous) {
|
|
7397
|
+
if (previous.request !== encoded) throw new Error("operationId 已用于其他请求");
|
|
7398
|
+
db.exec("COMMIT");
|
|
7399
|
+
return JSON.parse(String(previous.result));
|
|
7400
|
+
}
|
|
7401
|
+
if (request.decision !== "accepted") throw new Error("缺少可信全文证据,禁止拒绝写回");
|
|
7402
|
+
if (db.prepare(`UPDATE review_files SET decision='accepted',revision=revision+1
|
|
7403
|
+
WHERE id=? AND seq=? AND revision=? AND current=1 AND decision='pending'`).run(request.id, request.seq, request.revision).changes !== 1) throw new Error("审查版本冲突,请刷新后重试");
|
|
7404
|
+
const result = { revision: request.revision + 1 };
|
|
7405
|
+
db.prepare("INSERT INTO review_ops VALUES(?,?,'committed',?,NULL)").run(request.operationId, encoded, JSON.stringify(result));
|
|
7406
|
+
db.exec("COMMIT");
|
|
7407
|
+
return result;
|
|
7408
|
+
} catch (error) {
|
|
7409
|
+
if (db.isTransaction) db.exec("ROLLBACK");
|
|
7410
|
+
throw error;
|
|
7411
|
+
}
|
|
7412
|
+
}
|
|
7413
|
+
//#endregion
|
|
7414
|
+
//#region src/officialCapture.ts
|
|
7415
|
+
/** Deferred official-event collection; no private snapshot access. @author ddj 2026年10月26号 */
|
|
7416
|
+
/** @public @author ddj 2026年10月26号 @param deps Official source and workspace adapters. @returns Bounded collector with cancellation and deferred event reads. */
|
|
7417
|
+
function createCollector(deps) {
|
|
7418
|
+
const waiting = [];
|
|
7419
|
+
const pending = /* @__PURE__ */ new Set();
|
|
7420
|
+
const controller = new AbortController();
|
|
7421
|
+
let active = 0;
|
|
7422
|
+
let stopped = false;
|
|
7423
|
+
const running = /* @__PURE__ */ new Set();
|
|
7424
|
+
const tasks = /* @__PURE__ */ new Set();
|
|
7425
|
+
/** @private @author ddj 2026年10月26号 @param ms Delay; aborted on unload. @returns Deferred completion, not synchronous observer work. */
|
|
7426
|
+
function pause(ms) {
|
|
7427
|
+
return new Promise((resolve) => {
|
|
7428
|
+
/** @private @author ddj 2026年10月26号 Release both timer and listener. */
|
|
7429
|
+
function finish() {
|
|
7430
|
+
clearTimeout(timer);
|
|
7431
|
+
controller.signal.removeEventListener("abort", finish);
|
|
7432
|
+
resolve();
|
|
7433
|
+
}
|
|
7434
|
+
const timer = setTimeout(finish, ms);
|
|
7435
|
+
controller.signal.addEventListener("abort", finish, { once: true });
|
|
7436
|
+
if (stopped) finish();
|
|
7437
|
+
});
|
|
7438
|
+
}
|
|
7439
|
+
/** @private @author ddj 2026年10月26号 @param task Source identity. @returns Complete payload staged before one database transaction. */
|
|
7440
|
+
async function collect(task) {
|
|
7441
|
+
await pause(0);
|
|
7442
|
+
if (stopped) return;
|
|
7443
|
+
const source = deps.source();
|
|
7444
|
+
if (!source) throw new Error("官方 workspaceChanges 服务不可用");
|
|
7445
|
+
let summary;
|
|
7446
|
+
for (let attempt = 0; attempt < 4 && !stopped; attempt++) {
|
|
7447
|
+
summary = source.summary(task.sessionId, task.seq);
|
|
7448
|
+
if (summary) break;
|
|
7449
|
+
await pause(deps.retryMs ?? 100);
|
|
7450
|
+
}
|
|
7451
|
+
if (!summary || stopped) throw new Error("官方事件已公告,但 summary 已失效或尚不可用");
|
|
7452
|
+
summary = structuredClone(summary);
|
|
7453
|
+
if (summary.turn !== task.turn) throw new Error("官方 summary 轮次与事件不一致");
|
|
7454
|
+
task.cwd = summary.cwd;
|
|
7455
|
+
await deps.prepare(summary.cwd);
|
|
7456
|
+
if (stopped) return;
|
|
7457
|
+
deps.state(summary.cwd, {
|
|
7458
|
+
...task,
|
|
7459
|
+
error: ""
|
|
7460
|
+
}, "queued");
|
|
7461
|
+
try {
|
|
7462
|
+
const files = [];
|
|
7463
|
+
for (const [index, file] of summary.files.entries()) {
|
|
7464
|
+
if (stopped) return;
|
|
7465
|
+
const diff = await readDiff(source, task, index, AbortSignal.any([controller.signal, AbortSignal.timeout(deps.timeoutMs ?? 1e4)]));
|
|
7466
|
+
if (!diff || diff.path !== file.path || diff.display !== file.display) throw new Error("官方文件差异缺失或身份不一致");
|
|
7467
|
+
const identity = await deps.identity(summary.cwd, file.path);
|
|
7468
|
+
files.push({
|
|
7469
|
+
identity,
|
|
7470
|
+
diff: structuredClone(diff)
|
|
7471
|
+
});
|
|
7472
|
+
}
|
|
7473
|
+
if (!stopped) deps.persist(summary.cwd, {
|
|
7474
|
+
...task,
|
|
7475
|
+
sourceKind: "official",
|
|
7476
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7477
|
+
summary,
|
|
7478
|
+
files
|
|
7479
|
+
});
|
|
7480
|
+
} catch (error) {
|
|
7481
|
+
if (!stopped) deps.state(summary.cwd, {
|
|
7482
|
+
...task,
|
|
7483
|
+
error: String(error)
|
|
7484
|
+
}, "gap");
|
|
7485
|
+
throw error;
|
|
7486
|
+
}
|
|
7487
|
+
}
|
|
7488
|
+
/** @private @author ddj 2026年10月26号 Starts at most two independent event reads, with each event's file reads serial. */
|
|
7489
|
+
function drain() {
|
|
7490
|
+
while (!stopped && active < 2 && waiting.length) {
|
|
7491
|
+
const index = waiting.findIndex((task) => !running.has(JSON.stringify([task.sessionId, task.turn])));
|
|
7492
|
+
if (index < 0) break;
|
|
7493
|
+
const task = waiting.splice(index, 1)[0];
|
|
7494
|
+
const key = JSON.stringify([
|
|
7495
|
+
task.sessionId,
|
|
7496
|
+
task.turn,
|
|
7497
|
+
task.seq
|
|
7498
|
+
]);
|
|
7499
|
+
const turnKey = JSON.stringify([task.sessionId, task.turn]);
|
|
7500
|
+
active++;
|
|
7501
|
+
running.add(turnKey);
|
|
7502
|
+
const work = collect(task).catch(async (error) => {
|
|
7503
|
+
deps.report(`官方差异采集 ${key}: ${String(error)}`);
|
|
7504
|
+
if (!stopped && task.cwd) try {
|
|
7505
|
+
await deps.prepare(task.cwd);
|
|
7506
|
+
if (!stopped) deps.state(task.cwd, {
|
|
7507
|
+
...task,
|
|
7508
|
+
error: String(error)
|
|
7509
|
+
}, "gap");
|
|
7510
|
+
} catch (failure) {
|
|
7511
|
+
deps.report(`官方缺口落盘失败: ${String(failure)}`);
|
|
7512
|
+
}
|
|
7513
|
+
}).finally(() => {
|
|
7514
|
+
active--;
|
|
7515
|
+
pending.delete(key);
|
|
7516
|
+
running.delete(turnKey);
|
|
7517
|
+
tasks.delete(work);
|
|
7518
|
+
drain();
|
|
7519
|
+
});
|
|
7520
|
+
tasks.add(work);
|
|
7521
|
+
}
|
|
7522
|
+
}
|
|
7523
|
+
/** @public @author ddj 2026年10月26号 @param session Source session. @param event Published event; inherited fork events are excluded. */
|
|
7524
|
+
function enqueue(session, event) {
|
|
7525
|
+
if (stopped || event.type !== "workspace/changes" || !Number.isSafeInteger(event.data?.turn) || !Number.isSafeInteger(event.seq) || event.seq < (session.inheritedEventCount ?? 0)) return;
|
|
7526
|
+
const task = {
|
|
7527
|
+
sessionId: session.id,
|
|
7528
|
+
turn: event.data.turn,
|
|
7529
|
+
seq: event.seq,
|
|
7530
|
+
cwd: session.header?.cwd
|
|
7531
|
+
};
|
|
7532
|
+
const key = JSON.stringify([
|
|
7533
|
+
task.sessionId,
|
|
7534
|
+
task.turn,
|
|
7535
|
+
task.seq
|
|
7536
|
+
]);
|
|
7537
|
+
if (pending.has(key)) return;
|
|
7538
|
+
pending.add(key);
|
|
7539
|
+
waiting.push(task);
|
|
7540
|
+
drain();
|
|
7541
|
+
}
|
|
7542
|
+
/** @public @author ddj 2026年10月26号 @returns Bounded durability checkpoint including work queued while active tasks finish. */
|
|
7543
|
+
async function flush() {
|
|
7544
|
+
const deadline = Date.now() + (deps.timeoutMs ?? 1e4);
|
|
7545
|
+
while (tasks.size && !stopped && Date.now() < deadline) {
|
|
7546
|
+
let timer;
|
|
7547
|
+
await Promise.race([Promise.all([...tasks]), new Promise((resolve) => {
|
|
7548
|
+
timer = setTimeout(resolve, Math.max(1, deadline - Date.now()));
|
|
7549
|
+
})]);
|
|
7550
|
+
clearTimeout(timer);
|
|
7551
|
+
}
|
|
7552
|
+
}
|
|
7553
|
+
/** @public @author ddj 2026年10月26号 @returns Bounded drain, then cancel timers and reads; incomplete staging cannot publish. */
|
|
7554
|
+
async function dispose() {
|
|
7555
|
+
await flush();
|
|
7556
|
+
stopped = true;
|
|
7557
|
+
controller.abort();
|
|
7558
|
+
waiting.length = 0;
|
|
7559
|
+
pending.clear();
|
|
7560
|
+
}
|
|
7561
|
+
return {
|
|
7562
|
+
enqueue,
|
|
7563
|
+
flush,
|
|
7564
|
+
dispose
|
|
7565
|
+
};
|
|
7566
|
+
}
|
|
7567
|
+
/** @private @author ddj 2026年10月26号 @param source Public service. @param task Event. @param index File position. @param signal Cancellation/deadline. @returns A read bounded even if an adapter ignores abort. */
|
|
7568
|
+
async function readDiff(source, task, index, signal) {
|
|
7569
|
+
return new Promise((resolve, reject) => {
|
|
7570
|
+
/** @private @author ddj 2026年10月26号 Propagate timeout or unload. */
|
|
7571
|
+
function aborted() {
|
|
7572
|
+
reject(signal.reason);
|
|
7573
|
+
}
|
|
7574
|
+
signal.addEventListener("abort", aborted, { once: true });
|
|
7575
|
+
if (signal.aborted) {
|
|
7576
|
+
aborted();
|
|
7577
|
+
return;
|
|
7578
|
+
}
|
|
7579
|
+
Promise.resolve().then(() => source.diff(task.sessionId, task.seq, index, signal)).then(resolve, reject).finally(() => signal.removeEventListener("abort", aborted));
|
|
7580
|
+
});
|
|
7581
|
+
}
|
|
7582
|
+
/** @public @author ddj 2026年10月26号 @param ctx Host lifecycle owner; services remain optional for older Hosts. */
|
|
7583
|
+
function installCapture(ctx) {
|
|
7584
|
+
const collector = createCollector({
|
|
7585
|
+
source: () => ctx.get("workspaceChanges"),
|
|
7586
|
+
prepare: async (cwd) => {
|
|
7587
|
+
await loadBucket(ctx, cwd);
|
|
7588
|
+
await repairPaths(cwd, resolvePath);
|
|
7589
|
+
},
|
|
7590
|
+
identity: resolvePath,
|
|
7591
|
+
persist: saveSnapshot,
|
|
7592
|
+
state: captureState,
|
|
7593
|
+
report: (message) => log.warn(message)
|
|
7594
|
+
});
|
|
7595
|
+
ctx.on("session/event", collector.enqueue);
|
|
7596
|
+
ctx.on("session/created", backfill);
|
|
7597
|
+
ctx.on("session/flush", collector.flush);
|
|
7598
|
+
for (const session of ctx.get("sessions").list()) backfill(session);
|
|
7599
|
+
return collector.dispose;
|
|
7600
|
+
/** @private @author ddj 2026年10月27号 @param cwd Source workspace. @param path Official relative path. @returns Backend-owned process path; never stringify opaque targets. @throws Invalid backend path. */
|
|
7601
|
+
async function resolvePath(cwd, path) {
|
|
7602
|
+
const fs = ctx.get("fs");
|
|
7603
|
+
const target = await fs.resolve(path, { cwd });
|
|
7604
|
+
const processPath = fs.processPath(target);
|
|
7605
|
+
if (typeof processPath !== "string" || !processPath || processPath === "[object Object]") throw new Error("官方文件路径解析失败");
|
|
7606
|
+
return processPath;
|
|
7607
|
+
}
|
|
7608
|
+
/** @private @author ddj 2026年10月26号 @param session Live session. Only public async reads, excluding inherited records. */
|
|
7609
|
+
async function backfill(session) {
|
|
7610
|
+
const query = ctx.get("sessionQuery");
|
|
7611
|
+
if (!query?.listEvents || !query?.readEvent) {
|
|
7612
|
+
log.warn("官方历史补采不可用:缺少 sessionQuery;后续实时事件仍会采集");
|
|
7613
|
+
return;
|
|
7614
|
+
}
|
|
7615
|
+
try {
|
|
7616
|
+
if (session.header?.cwd) {
|
|
7617
|
+
await loadBucket(ctx, session.header.cwd);
|
|
7618
|
+
await repairPaths(session.header.cwd, resolvePath);
|
|
7619
|
+
}
|
|
7620
|
+
const events = await query.listEvents(session.id);
|
|
7621
|
+
for (const event of events) {
|
|
7622
|
+
if (event.type !== "workspace/changes" || event.seq < (session.inheritedEventCount ?? 0)) continue;
|
|
7623
|
+
const window = await query.readEvent({
|
|
7624
|
+
sessionId: session.id,
|
|
7625
|
+
seq: event.seq
|
|
7626
|
+
});
|
|
7627
|
+
collector.enqueue(session, window.target);
|
|
7628
|
+
}
|
|
7629
|
+
} catch (error) {
|
|
7630
|
+
log.warn("官方历史补采失败:" + String(error));
|
|
7631
|
+
}
|
|
7632
|
+
}
|
|
7633
|
+
}
|
|
7634
|
+
//#endregion
|
|
7173
7635
|
//#region src/search/query.ts
|
|
7174
7636
|
/**
|
|
7175
7637
|
* 规范化用户搜索文本。
|
|
@@ -12111,6 +12573,43 @@ function decodePage(bytes, info, offset, pendingCR, args, identity, signCursor)
|
|
|
12111
12573
|
};
|
|
12112
12574
|
}
|
|
12113
12575
|
//#endregion
|
|
12576
|
+
//#region src/reviewRpc.ts
|
|
12577
|
+
/** @public @author ddj 2026年10月26号 @param ctx Host. @param registry Workspace cache. @returns Handlers resolving workspace from the live authenticated session, never caller cwd. */
|
|
12578
|
+
function reviewHandlers(ctx, registry) {
|
|
12579
|
+
/** @private @author ddj 2026年10月26号 @param sessionId Request scope. @returns Migrated workspace, or explicit failure without fallback. */
|
|
12580
|
+
async function workspace(sessionId) {
|
|
12581
|
+
const session = sessionOf(ctx, sessionId);
|
|
12582
|
+
const cwd = cwdOfSession(ctx, session);
|
|
12583
|
+
if (!session || !cwd) throw new Error("会话不存在或没有工作区");
|
|
12584
|
+
await bucketOf(registry, ctx, cwd);
|
|
12585
|
+
return cwd;
|
|
12586
|
+
}
|
|
12587
|
+
return {
|
|
12588
|
+
"edrv.review.list": async (args) => {
|
|
12589
|
+
return {
|
|
12590
|
+
ok: true,
|
|
12591
|
+
page: reviewPage(await workspace(args.sessionId), args.cursor, args.history, args.path)
|
|
12592
|
+
};
|
|
12593
|
+
},
|
|
12594
|
+
"edrv.review.detail": async (args) => {
|
|
12595
|
+
const detail = reviewDetail(await workspace(args.sessionId), args.id);
|
|
12596
|
+
return detail ? {
|
|
12597
|
+
ok: true,
|
|
12598
|
+
detail
|
|
12599
|
+
} : {
|
|
12600
|
+
ok: false,
|
|
12601
|
+
error: "官方审查记录不存在"
|
|
12602
|
+
};
|
|
12603
|
+
},
|
|
12604
|
+
"edrv.review.decide": async (args) => {
|
|
12605
|
+
return {
|
|
12606
|
+
ok: true,
|
|
12607
|
+
...decideReview(await workspace(args.sessionId), args)
|
|
12608
|
+
};
|
|
12609
|
+
}
|
|
12610
|
+
};
|
|
12611
|
+
}
|
|
12612
|
+
//#endregion
|
|
12114
12613
|
//#region src/rpc.ts
|
|
12115
12614
|
/** Process-local cursor signer; reads must stay on the Host filesystem capability. */
|
|
12116
12615
|
const readTextPage = createTextPages();
|
|
@@ -12264,22 +12763,6 @@ function isStaleVersion(error) {
|
|
|
12264
12763
|
*/
|
|
12265
12764
|
async function afterManualSave(ctx, registry, sc, path) {
|
|
12266
12765
|
invalidateIndex(ctx, sc.cwd, path);
|
|
12267
|
-
const bucket = await bucketOf(registry, ctx, sc.cwd);
|
|
12268
|
-
let changed = false;
|
|
12269
|
-
for (const rec of bucket.values()) if (rec.path === path && rec.superseded !== true) {
|
|
12270
|
-
rec.superseded = true;
|
|
12271
|
-
rec.at = (/* @__PURE__ */ new Date()).toISOString();
|
|
12272
|
-
changed = true;
|
|
12273
|
-
}
|
|
12274
|
-
if (changed) {
|
|
12275
|
-
const done = [];
|
|
12276
|
-
for (const rec of bucket.values()) if (rec.path === path && rec.superseded) done.push(rec);
|
|
12277
|
-
if (done.length) await archiveRecords(ctx, sc.session, sc.cwd, bucket, done, "被手动编辑覆盖");
|
|
12278
|
-
else await saveBucket(ctx, sc.cwd, bucket, sc.session, {
|
|
12279
|
-
upserts: [...bucket.values()].filter((rec) => rec.path === path),
|
|
12280
|
-
removed: []
|
|
12281
|
-
});
|
|
12282
|
-
}
|
|
12283
12766
|
}
|
|
12284
12767
|
/**
|
|
12285
12768
|
* 批量决策核心:一次会话/桶解析 + 逐项处理 + 统一落盘(accept/reject 单条与 decideBatch 共用)。
|
|
@@ -12313,6 +12796,14 @@ async function applyDecisions(ctx, session, cwd, bucket, items) {
|
|
|
12313
12796
|
});
|
|
12314
12797
|
continue;
|
|
12315
12798
|
}
|
|
12799
|
+
if (hasOfficial(cwd, record.path)) {
|
|
12800
|
+
results.push({
|
|
12801
|
+
callId: item.callId,
|
|
12802
|
+
ok: false,
|
|
12803
|
+
error: "该文件已有官方审查记录;旧工具记录禁止决策或回滚,请使用官方审查入口"
|
|
12804
|
+
});
|
|
12805
|
+
continue;
|
|
12806
|
+
}
|
|
12316
12807
|
if (record.archived) {
|
|
12317
12808
|
results.push({
|
|
12318
12809
|
callId: item.callId,
|
|
@@ -12333,7 +12824,6 @@ async function applyDecisions(ctx, session, cwd, bucket, items) {
|
|
|
12333
12824
|
});
|
|
12334
12825
|
continue;
|
|
12335
12826
|
}
|
|
12336
|
-
let revertedStale = false;
|
|
12337
12827
|
if (item.decision === "rejected" && !alreadyDone) {
|
|
12338
12828
|
const scope = item.scope ?? "call";
|
|
12339
12829
|
const hunkIndex = scope === "hunk" ? item.hunkIndex ?? -1 : -1;
|
|
@@ -12397,8 +12887,8 @@ async function applyDecisions(ctx, session, cwd, bucket, items) {
|
|
|
12397
12887
|
if (traceId && !grouped.has(index)) revertMs += performance.now() - revertStart;
|
|
12398
12888
|
grouped.delete(index);
|
|
12399
12889
|
try {
|
|
12400
|
-
if (outcome.ok
|
|
12401
|
-
else if (outcome.error === "找不到该差异块" || outcome.error === "回滚失败:文件不存在" || outcome.error === "回滚失败:文件过大,无法安全定位") clearRevertState(cwd, record.callId, scope, hunkIndex);
|
|
12890
|
+
if (outcome.ok) setRevertState(cwd, record.callId, scope, hunkIndex, "applied");
|
|
12891
|
+
else if (outcome.stale === true || outcome.error === "找不到该差异块" || outcome.error === "回滚失败:文件不存在" || outcome.error === "回滚失败:文件过大,无法安全定位") clearRevertState(cwd, record.callId, scope, hunkIndex);
|
|
12402
12892
|
} catch (error) {
|
|
12403
12893
|
results.push({
|
|
12404
12894
|
callId: item.callId,
|
|
@@ -12408,15 +12898,12 @@ async function applyDecisions(ctx, session, cwd, bucket, items) {
|
|
|
12408
12898
|
continue;
|
|
12409
12899
|
}
|
|
12410
12900
|
if (!outcome.ok) {
|
|
12411
|
-
|
|
12412
|
-
|
|
12413
|
-
|
|
12414
|
-
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
continue;
|
|
12418
|
-
}
|
|
12419
|
-
revertedStale = true;
|
|
12901
|
+
results.push({
|
|
12902
|
+
callId: item.callId,
|
|
12903
|
+
ok: false,
|
|
12904
|
+
error: outcome.error || "差异已偏移,未修改文件,保留待处理"
|
|
12905
|
+
});
|
|
12906
|
+
continue;
|
|
12420
12907
|
}
|
|
12421
12908
|
}
|
|
12422
12909
|
const wasResolved = recordResolved(record);
|
|
@@ -12429,7 +12916,6 @@ async function applyDecisions(ctx, session, cwd, bucket, items) {
|
|
|
12429
12916
|
ok: true,
|
|
12430
12917
|
record: recView(record, ws)
|
|
12431
12918
|
};
|
|
12432
|
-
if (revertedStale) result.stale = true;
|
|
12433
12919
|
results.push(result);
|
|
12434
12920
|
}
|
|
12435
12921
|
const decisionMs = traceId ? performance.now() - started : 0;
|
|
@@ -12616,6 +13102,7 @@ function buildHandlers(ctx, registry, searcher = newSearcher(ctx), contentSearch
|
|
|
12616
13102
|
...aiHandlers ?? {},
|
|
12617
13103
|
...svnHandlers ?? {},
|
|
12618
13104
|
...dapHandlers ?? {},
|
|
13105
|
+
...reviewHandlers(ctx, registry),
|
|
12619
13106
|
"edrv.list": async (args) => {
|
|
12620
13107
|
const start = performance.now();
|
|
12621
13108
|
let staleMs = 0;
|
|
@@ -13195,6 +13682,10 @@ function buildHandlers(ctx, registry, searcher = newSearcher(ctx), contentSearch
|
|
|
13195
13682
|
};
|
|
13196
13683
|
const batch = args.batch;
|
|
13197
13684
|
const bucket = await bucketOf(registry, ctx, sc.cwd);
|
|
13685
|
+
if (hasOfficial(sc.cwd, args.path)) return {
|
|
13686
|
+
ok: false,
|
|
13687
|
+
error: "该文件已有官方审查记录,禁止使用旧版批次回滚覆盖当前文件"
|
|
13688
|
+
};
|
|
13198
13689
|
try {
|
|
13199
13690
|
let affected = [];
|
|
13200
13691
|
let beforeRec = null;
|
|
@@ -24758,6 +25249,7 @@ function createRuntime(ctx, config) {
|
|
|
24758
25249
|
* @param runtime Managers created by this instance.
|
|
24759
25250
|
*/
|
|
24760
25251
|
function attachRuntime(ctx, runtime) {
|
|
25252
|
+
const stopCapture = installCapture(ctx);
|
|
24761
25253
|
/** @author ddj 2026年09月28号 @param exec Tool execution. @param result Tool result. */
|
|
24762
25254
|
function onResult(exec, result) {
|
|
24763
25255
|
captureToolResult(ctx, runtime.registry, exec, result);
|
|
@@ -24775,6 +25267,7 @@ function attachRuntime(ctx, runtime) {
|
|
|
24775
25267
|
}
|
|
24776
25268
|
/** @author ddj 2026年09月28号 Release every manager even if another cleanup rejects. */
|
|
24777
25269
|
async function cleanup() {
|
|
25270
|
+
await stopCapture();
|
|
24778
25271
|
runtime.fileVersions.dispose();
|
|
24779
25272
|
closeArchiveDbs();
|
|
24780
25273
|
disposeAllServers();
|