@dev.fast/whiteboard 0.2.4-preview.20261009.108 → 0.2.5-preview.20261013.109
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/{account-alias-_1_7vROx.js → account-alias-D0hF0sKk.js} +2 -3
- package/dist/{agent-cli-BYMMEOlO.js → agent-cli-BBPxwUOd.js} +6 -6
- package/dist/agent-cli-YSuhE5X8.js +2 -0
- package/dist/{agent-client-B_b1GtUc.js → agent-client-P3J4y8Zn.js} +3 -3
- package/dist/{authoring-tools-CUJ_56bd.js → authoring-tools-D8WXsm_g.js} +11 -10
- package/dist/build-info.json +1 -1
- package/dist/{cli-gRGxkwc0.js → cli-C0ziP6hg.js} +1 -1
- package/dist/{cli-runner-CyBLX8Oj.js → cli-runner-C1gY-HAI.js} +16 -17
- package/dist/cli.js +1 -1
- package/dist/{client-BFClfQLO.js → client-DzcSt6pV.js} +63 -13
- package/dist/{desktop-discovery-C-Qz54wO.js → desktop-discovery-Ba3dD5Cn.js} +1 -1
- package/dist/{headless-host-wMPUx0Aj.js → headless-host-BHD_Vg5F.js} +4 -4
- package/dist/{local-data-BfAaQmqC.js → local-data-BlERtVm2.js} +342 -142
- package/dist/{mcp-BWp_kC0V.js → mcp-t7VN9R3k.js} +4 -4
- package/dist/{package-paths-B6-zxvIO.js → package-paths-B9PDoAl6.js} +1 -1
- package/dist/{process-error-telemetry-WjZ2FTnX.js → process-error-telemetry-C0swByfp.js} +169 -65
- package/dist/{profile-CviK33_F.js → profile-BsYDBr7t.js} +2 -2
- package/dist/profile-j97aRTS7.js +2 -0
- package/dist/{review-agent-traces-DNJFYzc8.js → review-home-paths-Y9mYWkCI.js} +2600 -62
- package/dist/{review-telemetry-DBy3eVCo.js → review-telemetry-CmM6tCbj.js} +2 -2
- package/dist/server/desktop-host.js +35 -46
- package/dist/{server-discovery-Dbzn3w6Z.js → server-discovery-ZVi8Ay8J.js} +1 -1
- package/dist/sharing/index.d.ts +47 -60
- package/dist/sharing/index.js +1 -1
- package/dist/{src-CmdiBL20.js → src-DiHP11l3.js} +11 -1
- package/dist/{stored-document-migration-BxZWQQjv.js → stored-document-migration-u4L_1VZa.js} +15 -36
- package/dist/{tool-failure-DJmTieh5.js → tool-failure-CJHBCHMh.js} +2 -2
- package/instructions/scratchpad.md +1 -1
- package/package.json +6 -5
- package/src/ask/agents.ts +6 -0
- package/src/ask/thread-state.ts +17 -1
- package/src/ask/thread.ts +116 -22
- package/src/ask/threads.ts +8 -2
- package/src/error-telemetry.ts +13 -9
- package/src/fixtures/blocks/tutorial.json +3 -40
- package/src/review-api/README.md +10 -7
- package/src/review-api/ask-history.ts +37 -0
- package/src/review-api/authoring-tools.ts +8 -5
- package/src/review-api/blocks/database_lens.ts +5 -0
- package/src/review-api/blocks/tutorial.ts +2 -18
- package/src/review-api/comparison-coverage.ts +198 -169
- package/src/review-api/component-reference.ts +1 -1
- package/src/review-api/document.ts +24 -10
- package/src/review-api/http.ts +267 -189
- package/src/review-api/local-data.ts +135 -40
- package/src/review-api/review-progress.ts +19 -9
- package/src/review-api/store-schema.ts +25 -1
- package/src/review-api/store.ts +165 -33
- package/src/review-api/workspaces.ts +14 -14
- package/src/review-api/worktree-events.ts +46 -0
- package/src/review-app.ts +1 -1
- package/src/review-info.ts +1 -1
- package/src/review-stack.ts +2 -2
- package/src/server/review-server-core.ts +25 -1
- package/src/server/structural-diff.ts +7 -7
- package/src/server/tutorial-service.ts +22 -46
- package/src/sharing/export.ts +1 -0
- package/src/sharing/import.ts +111 -26
- package/tutorial/document.json +27 -86
- package/tutorial/lenses.json +10 -0
- package/tutorial/runtime-manifest.json +2 -3
- package/tutorial/sample-service/src/database/drizzle-orm.d.ts +16 -0
- package/tutorial/sample-service/src/database/schema.ts +9 -10
- package/tutorial/sample-service/src/inventory/forklift-mood.ts +4 -0
- package/tutorial/sample-service/src/inventory/inventory-service.ts +18 -1
- package/tutorial/sample-service/src/inventory/warehouse-lore.ts +11 -0
- package/tutorial/sample-service/src/orders/order-service.ts +3 -2
- package/tutorial/sample-service/src/orders/order.ts +27 -5
- package/tutorial/sample-service/src/payments/fraud-vibes.ts +4 -0
- package/tutorial/sample-service/src/payments/payment-gateway.ts +19 -2
- package/tutorial/sample-service/src/payments/raccoon-ledger.ts +9 -0
- package/dist/agent-cli-BJ_SxT1P.js +0 -2
- package/dist/input-error-OLgB_h31.js +0 -11
- package/dist/profile-YLwWPRQp.js +0 -2
- package/dist/review-home-paths-6zZH-1c9.js +0 -2560
- package/dist/tutorial-trace-DrBvkaeL.js +0 -43
- package/src/tutorial-conversation.ts +0 -18
- package/tutorial/software-map.json +0 -139
- package/tutorial/trace.json +0 -20
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { _ as readFileAtCommit, b as resolveRevision, c as diffTrees, f as gitCommonDir, g as parseGitRemote, h as listTrackedFilesAtCommit, i as diff, l as diffWorkingTree, m as listCommitRange, n as createBlobBatchReader, o as diffFileSummariesTrees, p as jjRevisionIsConflicted, r as detectLocalVcs, s as diffFileSummariesWorkingTree, t as LocalVcsToolsMissingError, u as git, v as resolveRepoContext, y as resolveRepoContextSync } from "./src-
|
|
1
|
+
import { C as ReviewInputError, _ as readFileAtCommit, b as resolveRevision, c as diffTrees, f as gitCommonDir, g as parseGitRemote, h as listTrackedFilesAtCommit, i as diff, l as diffWorkingTree, m as listCommitRange, n as createBlobBatchReader, o as diffFileSummariesTrees, p as jjRevisionIsConflicted, r as detectLocalVcs, s as diffFileSummariesWorkingTree, t as LocalVcsToolsMissingError, u as git, v as resolveRepoContext, y as resolveRepoContextSync } from "./src-DiHP11l3.js";
|
|
2
2
|
import { c as jsonString, o as jsonObject, u as parseJsonText } from "./src-X9phtB2j.js";
|
|
3
3
|
import { _ as SCRATCHPAD_REVIEW_ID, b as structuralChangeCounts, g as ReviewSelectedDiffSchema, m as ReviewApiSelectionSourceSchema, y as decodeStructuralDiffEvent } from "./src-WCbabvdS.js";
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
4
|
+
import { s as safeStorageSegment } from "./review-home-paths-Y9mYWkCI.js";
|
|
5
|
+
import { $ as unionIntervals, A as applyLensEdit, C as resourceReferences, D as summarizeEdit, E as sourceReferences, F as checkSourcePath, I as fileLineRangeSchema, K as sourceAnchors, L as requireVisibleSource, N as lensSelections, O as checkReferences, P as SourceRangeError, Q as subtractIntervals, R as sliceSourceRange, S as resourceReference, X as intersectIntervals, Y as emptyCoverage, a as defineSoftwareMap, b as pinsSchema, c as traceSchema, d as applyEdit, et as updateCoverage, f as assignFreshIds, g as explicitPins, h as elements, i as SoftwareModelValidationError, j as lensEditSchema, l as textIncludesQuote, m as editSchema, n as migrateStoredDocument, p as documentSchema, q as coverageSchema, r as migrateStoredLenses, t as liftFileLenses, u as anchorPins, v as isUnit, w as reviewTargetSchema } from "./stored-document-migration-u4L_1VZa.js";
|
|
6
6
|
import { D as processIsAlive, O as withFileLock, P as writePrivateJsonAtomic } from "./s3-config-CAxhO9u_.js";
|
|
7
7
|
import { t as errorMessage } from "./error-message-OtiDonty.js";
|
|
8
|
-
import { s as safeStorageSegment } from "./review-home-paths-6zZH-1c9.js";
|
|
9
8
|
import { r as isMissingFileError } from "./fs-utils-BMPLt0cr.js";
|
|
10
9
|
import { createRequire } from "node:module";
|
|
11
10
|
import crypto, { createHash, randomUUID } from "node:crypto";
|
|
12
11
|
import { z } from "zod";
|
|
13
|
-
import { existsSync, realpathSync, rmSync,
|
|
12
|
+
import { existsSync, realpathSync, rmSync, statSync } from "node:fs";
|
|
14
13
|
import * as fs$1 from "node:fs/promises";
|
|
15
14
|
import { lstat, mkdir, readFile, readdir, realpath, rm, stat, writeFile } from "node:fs/promises";
|
|
16
15
|
import path, { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
@@ -425,9 +424,9 @@ async function* structuralDiff(input) {
|
|
|
425
424
|
case "merge-base": args.push(`${comparison.base}...${comparison.head}`);
|
|
426
425
|
}
|
|
427
426
|
args.push("--", ...input.paths ?? []);
|
|
428
|
-
const
|
|
429
|
-
const
|
|
430
|
-
const signal = AbortSignal.any([
|
|
427
|
+
const startupAbort = new AbortController();
|
|
428
|
+
const startup = setTimeout(() => startupAbort.abort(), 12e4);
|
|
429
|
+
const signal = AbortSignal.any([startupAbort.signal, input.signal]);
|
|
431
430
|
console.info(`[Review] structural diff: ${executable} ${args.join(" ")}`);
|
|
432
431
|
const child = spawn(executable, args, {
|
|
433
432
|
cwd: input.repositoryPath,
|
|
@@ -461,7 +460,6 @@ async function* structuralDiff(input) {
|
|
|
461
460
|
});
|
|
462
461
|
try {
|
|
463
462
|
for await (const line of lines) {
|
|
464
|
-
idle.refresh();
|
|
465
463
|
if (Buffer.byteLength(line) > 100663296) throw new Error("Structural diff record exceeded 96 MiB.");
|
|
466
464
|
if (!line.trim()) continue;
|
|
467
465
|
const event = decodeStructuralDiffEvent(line);
|
|
@@ -469,6 +467,7 @@ async function* structuralDiff(input) {
|
|
|
469
467
|
if (!started) {
|
|
470
468
|
if (event.type !== "start" || event.version !== 3) throw new Error("Unsupported diffr stream protocol.");
|
|
471
469
|
started = true;
|
|
470
|
+
clearTimeout(startup);
|
|
472
471
|
} else if (event.type === "complete") {
|
|
473
472
|
completed = true;
|
|
474
473
|
failed = event.failed;
|
|
@@ -484,7 +483,7 @@ async function* structuralDiff(input) {
|
|
|
484
483
|
const code = await exited;
|
|
485
484
|
if (code !== 0 && !(code === 2 && (failed > 0 || aborted !== void 0))) throw exitError(code);
|
|
486
485
|
} finally {
|
|
487
|
-
clearTimeout(
|
|
486
|
+
clearTimeout(startup);
|
|
488
487
|
lines.close();
|
|
489
488
|
if (child.exitCode === null) child.kill();
|
|
490
489
|
await exited.catch(() => {});
|
|
@@ -960,9 +959,9 @@ async function comparisonCoverage(data, reviewId, pins, mode, signal, publish) {
|
|
|
960
959
|
const fileSources = /* @__PURE__ */ new Map();
|
|
961
960
|
const alignments = /* @__PURE__ */ new Map();
|
|
962
961
|
const files = [];
|
|
963
|
-
|
|
962
|
+
for (const file of await data.changes(pins)) {
|
|
964
963
|
signal.throwIfAborted();
|
|
965
|
-
const patch = await data.changes(pins, file.path);
|
|
964
|
+
const patch = await data.changes(pins, file.path, file.previousPath);
|
|
966
965
|
const changed = emptyCoverage();
|
|
967
966
|
for (const hunk of parseUnifiedPatch(file.path, patch)) for (const line of hunk.lines) {
|
|
968
967
|
if (line.kind === "add") changed.head.push([line.newLine - 1, line.newLine]);
|
|
@@ -1001,80 +1000,75 @@ async function comparisonCoverage(data, reviewId, pins, mode, signal, publish) {
|
|
|
1001
1000
|
changed,
|
|
1002
1001
|
viewed: emptyCoverage()
|
|
1003
1002
|
});
|
|
1004
|
-
publish?.({
|
|
1003
|
+
if (mode === "textual") publish?.({
|
|
1004
|
+
counted: false,
|
|
1005
1005
|
files: [...files],
|
|
1006
1006
|
fileSources: new Map(fileSources),
|
|
1007
1007
|
alignments: new Map(alignments)
|
|
1008
1008
|
});
|
|
1009
1009
|
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1010
|
+
const coverage = {
|
|
1011
|
+
files,
|
|
1012
|
+
fileSources,
|
|
1013
|
+
alignments,
|
|
1014
|
+
counted: true
|
|
1015
|
+
};
|
|
1016
|
+
if (mode === "textual") return coverage;
|
|
1017
|
+
const unsupported = /* @__PURE__ */ new Set();
|
|
1018
|
+
const current = () => ({
|
|
1019
|
+
...coverage,
|
|
1020
|
+
files: coverage.files.filter((file) => !unsupported.has(file.path))
|
|
1021
|
+
});
|
|
1022
|
+
publish?.(current());
|
|
1023
|
+
const baseFiles = new Map(coverage.files.map((file, index) => [file.previousPath ?? file.path, index]));
|
|
1024
|
+
const headFiles = new Map(coverage.files.map((file, index) => [file.path, index]));
|
|
1025
|
+
const remaining = /* @__PURE__ */ new Set();
|
|
1026
|
+
for await (const event of data.structuralChanges({
|
|
1027
|
+
reviewId,
|
|
1028
|
+
pins,
|
|
1029
|
+
signal
|
|
1030
|
+
})) {
|
|
1031
|
+
if (event.type === "start") {
|
|
1032
|
+
for (const entry of event.files) remaining.add((entry.file.rhs ?? entry.file.lhs).path);
|
|
1033
|
+
if (!remaining.size) break;
|
|
1034
|
+
continue;
|
|
1035
|
+
}
|
|
1036
|
+
if (event.type === "complete" && (event.failed || event.aborted)) throw new Error(event.aborted?.message ?? "Structural coverage is incomplete.");
|
|
1037
|
+
if (event.type !== "file") continue;
|
|
1038
|
+
const path = (event.file.rhs ?? event.file.lhs).path;
|
|
1039
|
+
if (!remaining.delete(path)) throw new Error(`Unexpected structural result: ${path}`);
|
|
1040
|
+
const baseIndex = event.file.lhs && baseFiles.get(event.file.lhs.path);
|
|
1041
|
+
const headIndex = event.file.rhs && headFiles.get(event.file.rhs.path);
|
|
1042
|
+
if (event.error) {
|
|
1043
|
+
if (event.error.code !== "unsupported_file_type" && event.error.code !== "not_utf8") throw new Error(`Cannot count ${path}: ${event.error.message}`);
|
|
1044
|
+
for (const index of [baseIndex, headIndex]) if (index !== void 0) unsupported.add(coverage.files[index].path);
|
|
1045
|
+
} else if (event.diff.type === "text") {
|
|
1046
|
+
const diff = event.diff;
|
|
1047
|
+
const folded = foldedChanges(diff);
|
|
1048
|
+
for (const side of ["base", "head"]) {
|
|
1049
|
+
const source = side === "base" ? event.file.lhs : event.file.rhs;
|
|
1050
|
+
const index = source && (side === "base" ? baseFiles : headFiles).get(source.path);
|
|
1051
|
+
if (index === void 0) continue;
|
|
1052
|
+
const file = coverage.files[index];
|
|
1053
|
+
const visible = subtractIntervals(diff.structural_changes[side], folded[side]);
|
|
1054
|
+
coverage.files[index] = {
|
|
1055
|
+
...file,
|
|
1056
|
+
folded: {
|
|
1057
|
+
...file.folded ?? emptyCoverage(),
|
|
1058
|
+
[side]: subtractIntervals(file.changed[side], visible)
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1021
1061
|
}
|
|
1022
|
-
|
|
1023
|
-
if (
|
|
1024
|
-
|
|
1025
|
-
if (!remaining.delete(path)) throw new Error(`Unexpected structural result: ${path}`);
|
|
1026
|
-
if (event.error) {
|
|
1027
|
-
if (event.error.code !== "unsupported_file_type" && event.error.code !== "not_utf8") throw new Error(`Cannot count ${path}: ${event.error.message}`);
|
|
1028
|
-
if (!remaining.size) break;
|
|
1029
|
-
continue;
|
|
1062
|
+
const index = headIndex ?? baseIndex;
|
|
1063
|
+
if (index !== void 0) {
|
|
1064
|
+
if ((coverage.fileSources.get(coverage.files[index].path) ?? []).every((source) => source.file === (source.side === "base" ? event.file.lhs : event.file.rhs)?.path)) coverage.alignments = new Map(coverage.alignments).set(coverage.files[index].path, structuralRows(diff));
|
|
1030
1065
|
}
|
|
1031
|
-
const diff = event.diff;
|
|
1032
|
-
const previousPath = event.file.lhs?.path !== path ? event.file.lhs?.path : void 0;
|
|
1033
|
-
const base = diff.type === "text" ? diff.lhs?.text ?? null : null;
|
|
1034
|
-
const head = diff.type === "text" ? diff.rhs?.text ?? null : null;
|
|
1035
|
-
const fingerprint = hash([
|
|
1036
|
-
pins.repositoryId,
|
|
1037
|
-
base,
|
|
1038
|
-
head,
|
|
1039
|
-
...diff.type === "binary" ? [event.file.lhs?.oid ?? null, event.file.rhs?.oid ?? null] : []
|
|
1040
|
-
]);
|
|
1041
|
-
const sources = [];
|
|
1042
|
-
if (base !== null) sources.push({
|
|
1043
|
-
side: "base",
|
|
1044
|
-
file: event.file.lhs.path,
|
|
1045
|
-
fromLine: 1,
|
|
1046
|
-
toLine: base.split("\n").length
|
|
1047
|
-
});
|
|
1048
|
-
if (head !== null) sources.push({
|
|
1049
|
-
side: "head",
|
|
1050
|
-
file: path,
|
|
1051
|
-
fromLine: 1,
|
|
1052
|
-
toLine: head.split("\n").length
|
|
1053
|
-
});
|
|
1054
|
-
fileSources.set(path, sources);
|
|
1055
|
-
if (diff.type === "text") alignments.set(path, structuralRows(diff));
|
|
1056
|
-
files.push({
|
|
1057
|
-
path,
|
|
1058
|
-
previousPath,
|
|
1059
|
-
fingerprint,
|
|
1060
|
-
changed: diff.type === "text" ? diff.structural_changes : emptyCoverage(),
|
|
1061
|
-
folded: foldedChanges(diff),
|
|
1062
|
-
viewed: emptyCoverage()
|
|
1063
|
-
});
|
|
1064
|
-
publish?.({
|
|
1065
|
-
files: [...files],
|
|
1066
|
-
fileSources: new Map(fileSources),
|
|
1067
|
-
alignments: new Map(alignments)
|
|
1068
|
-
});
|
|
1069
|
-
if (!remaining.size) break;
|
|
1070
1066
|
}
|
|
1071
|
-
|
|
1067
|
+
publish?.(current());
|
|
1068
|
+
if (!remaining.size) break;
|
|
1072
1069
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
fileSources,
|
|
1076
|
-
alignments
|
|
1077
|
-
};
|
|
1070
|
+
if (remaining.size) throw new Error("Structural coverage is incomplete.");
|
|
1071
|
+
return current();
|
|
1078
1072
|
}
|
|
1079
1073
|
/**
|
|
1080
1074
|
* The changed lines diffr folds by default. A file it hides (lockfiles,
|
|
@@ -1839,6 +1833,11 @@ const askUsageSchema = z.object({
|
|
|
1839
1833
|
currency: z.string()
|
|
1840
1834
|
}).optional()
|
|
1841
1835
|
});
|
|
1836
|
+
/** A follow-up waiting for the turn under way to end. */
|
|
1837
|
+
const askQueuedSchema = z.object({
|
|
1838
|
+
id: z.string(),
|
|
1839
|
+
text: z.string()
|
|
1840
|
+
});
|
|
1842
1841
|
const statusSchema = z.enum([
|
|
1843
1842
|
"starting",
|
|
1844
1843
|
"running",
|
|
@@ -1875,7 +1874,10 @@ const askThreadStateSchema = z.object({
|
|
|
1875
1874
|
title: z.string(),
|
|
1876
1875
|
quote: z.string().optional()
|
|
1877
1876
|
}),
|
|
1878
|
-
entries: z.array(askEntrySchema)
|
|
1877
|
+
entries: z.array(askEntrySchema),
|
|
1878
|
+
/** Follow-ups asked while the agent answered, which it could not take
|
|
1879
|
+
* then: each goes as its own question once the turn ends. */
|
|
1880
|
+
queued: z.array(askQueuedSchema).optional()
|
|
1879
1881
|
});
|
|
1880
1882
|
/** One change to a thread. Answer text arrives as `append`, so a streamed
|
|
1881
1883
|
* token costs its own length, not the thread's. */
|
|
@@ -1890,6 +1892,8 @@ const askChangeSchema = z.discriminatedUnion("type", [
|
|
|
1890
1892
|
accepts: askAcceptsSchema.optional(),
|
|
1891
1893
|
usage: askUsageSchema.optional(),
|
|
1892
1894
|
title: z.string().optional(),
|
|
1895
|
+
/** Replaces the queue; empty clears it. */
|
|
1896
|
+
queued: z.array(askQueuedSchema).optional(),
|
|
1893
1897
|
/** `null` clears the error; absent leaves it. */
|
|
1894
1898
|
error: z.string().nullable().optional(),
|
|
1895
1899
|
/** `null` clears it; absent leaves it. */
|
|
@@ -1933,7 +1937,7 @@ z.union([z.object({
|
|
|
1933
1937
|
function applyAskChange(state, change) {
|
|
1934
1938
|
switch (change.type) {
|
|
1935
1939
|
case "set": {
|
|
1936
|
-
const { error: _error, signIn: _signIn, ...rest } = state;
|
|
1940
|
+
const { error: _error, signIn: _signIn, queued: _queued, ...rest } = state;
|
|
1937
1941
|
const next = {
|
|
1938
1942
|
...rest,
|
|
1939
1943
|
status: change.status ?? state.status,
|
|
@@ -1950,6 +1954,8 @@ function applyAskChange(state, change) {
|
|
|
1950
1954
|
if (usage) next.usage = usage;
|
|
1951
1955
|
const title = change.title ?? state.title;
|
|
1952
1956
|
if (title) next.title = title;
|
|
1957
|
+
const queued = change.queued ?? state.queued;
|
|
1958
|
+
if (queued?.length) next.queued = queued;
|
|
1953
1959
|
const error = change.error === void 0 ? state.error : change.error;
|
|
1954
1960
|
if (error) next.error = error;
|
|
1955
1961
|
const signIn = change.signIn === void 0 ? state.signIn : change.signIn;
|
|
@@ -2040,6 +2046,10 @@ const rowSchema = z.object({
|
|
|
2040
2046
|
* `reviews`, so there is no foreign key; deleting a review deletes its rows. */
|
|
2041
2047
|
var AskHistory = class {
|
|
2042
2048
|
db;
|
|
2049
|
+
externalWriteGuard;
|
|
2050
|
+
setExternalWriteGuard(guard) {
|
|
2051
|
+
this.externalWriteGuard = guard;
|
|
2052
|
+
}
|
|
2043
2053
|
constructor(db) {
|
|
2044
2054
|
this.db = db;
|
|
2045
2055
|
db.exec(`CREATE TABLE IF NOT EXISTS ask_conversations(
|
|
@@ -2062,25 +2072,42 @@ var AskHistory = class {
|
|
|
2062
2072
|
db.exec("CREATE TABLE IF NOT EXISTS ask_agent_offers(agent TEXT PRIMARY KEY, offer TEXT NOT NULL)");
|
|
2063
2073
|
db.exec("CREATE TABLE IF NOT EXISTS ask_agent_model_offers(agent TEXT NOT NULL, model TEXT NOT NULL, offer TEXT NOT NULL, PRIMARY KEY(agent, model))");
|
|
2064
2074
|
}
|
|
2075
|
+
assertWritable(reviewId) {
|
|
2076
|
+
if (reviewId.startsWith("shared-")) this.externalWriteGuard?.(reviewId);
|
|
2077
|
+
const row = this.db.prepare("SELECT deleted_at FROM review_attention WHERE review_id=?").get(reviewId);
|
|
2078
|
+
if (row?.deleted_at) throw new ReviewInputError(`This whiteboard was moved to Trash on ${new Date(String(row.deleted_at)).toLocaleDateString("en-US", {
|
|
2079
|
+
month: "short",
|
|
2080
|
+
day: "numeric"
|
|
2081
|
+
})}. Restore it with session_lifecycle({"sessionId":"${reviewId}","state":"active"}) to continue.`, 409);
|
|
2082
|
+
}
|
|
2083
|
+
assertThreadWritable(id) {
|
|
2084
|
+
const record = this.get(id);
|
|
2085
|
+
if (record) this.assertWritable(record.reviewId);
|
|
2086
|
+
}
|
|
2065
2087
|
save(record) {
|
|
2088
|
+
this.assertWritable(record.reviewId);
|
|
2066
2089
|
this.db.prepare(`INSERT OR REPLACE INTO ask_conversations(id,review_id,agent,session_id,version,head,cwd,selection,title,created_at,updated_at,bypass)
|
|
2067
2090
|
VALUES(?,?,?,?,?,?,?,?,?,?,?,?)`).run(record.id, record.reviewId, record.agent, record.sessionId, record.version, record.head, record.cwd, JSON.stringify(record.selection), record.title, record.createdAt, record.updatedAt, record.bypass ? 1 : 0);
|
|
2068
2091
|
}
|
|
2069
2092
|
/** Whether reopening the conversation bypasses permissions. */
|
|
2070
2093
|
setBypass(id, bypass) {
|
|
2094
|
+
this.assertThreadWritable(id);
|
|
2071
2095
|
this.db.prepare("UPDATE ask_conversations SET bypass=? WHERE id=?").run(bypass ? 1 : 0, id);
|
|
2072
2096
|
}
|
|
2073
2097
|
/** Points a conversation at a new session, when its agent could not
|
|
2074
2098
|
* reopen the one it had. */
|
|
2075
2099
|
updateSession(id, sessionId) {
|
|
2100
|
+
this.assertThreadWritable(id);
|
|
2076
2101
|
this.db.prepare("UPDATE ask_conversations SET session_id=? WHERE id=?").run(sessionId, id);
|
|
2077
2102
|
}
|
|
2078
2103
|
/** Keeps what the panel shows, so a reopen need not wait on the agent. */
|
|
2079
2104
|
saveEntries(id, entries) {
|
|
2105
|
+
this.assertThreadWritable(id);
|
|
2080
2106
|
this.db.prepare("UPDATE ask_conversations SET entries=? WHERE id=?").run(JSON.stringify(entries), id);
|
|
2081
2107
|
}
|
|
2082
2108
|
/** The agent's name for the conversation, which the list shows. */
|
|
2083
2109
|
rename(id, title) {
|
|
2110
|
+
this.assertThreadWritable(id);
|
|
2084
2111
|
this.db.prepare("UPDATE ask_conversations SET title=? WHERE id=?").run(title.slice(0, 200), id);
|
|
2085
2112
|
}
|
|
2086
2113
|
saveOffer(agent, offer) {
|
|
@@ -2100,6 +2127,7 @@ var AskHistory = class {
|
|
|
2100
2127
|
return row && askOfferSchema.safeParse(JSON.parse(row.offer)).data;
|
|
2101
2128
|
}
|
|
2102
2129
|
touch(id, at = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
2130
|
+
this.assertThreadWritable(id);
|
|
2103
2131
|
this.db.prepare("UPDATE ask_conversations SET updated_at=? WHERE id=?").run(at, id);
|
|
2104
2132
|
}
|
|
2105
2133
|
/** Newest first. */
|
|
@@ -2115,7 +2143,11 @@ var AskHistory = class {
|
|
|
2115
2143
|
const row = this.db.prepare("SELECT * FROM ask_conversations WHERE id=?").get(id);
|
|
2116
2144
|
return row ? rowSchema.parse(row) : void 0;
|
|
2117
2145
|
}
|
|
2146
|
+
removeReview(reviewId) {
|
|
2147
|
+
this.db.prepare("DELETE FROM ask_conversations WHERE review_id=?").run(reviewId);
|
|
2148
|
+
}
|
|
2118
2149
|
delete(id) {
|
|
2150
|
+
this.assertThreadWritable(id);
|
|
2119
2151
|
this.db.prepare("DELETE FROM ask_conversations WHERE id=?").run(id);
|
|
2120
2152
|
}
|
|
2121
2153
|
};
|
|
@@ -2153,7 +2185,7 @@ function initializeReviewStoreSchema(db) {
|
|
|
2153
2185
|
CREATE TABLE IF NOT EXISTS versions(review_id TEXT REFERENCES reviews(id), version INTEGER, snapshot TEXT NOT NULL,
|
|
2154
2186
|
PRIMARY KEY(review_id,version));
|
|
2155
2187
|
DROP TABLE IF EXISTS receipts;
|
|
2156
|
-
CREATE TABLE IF NOT EXISTS review_attention(review_id TEXT PRIMARY KEY REFERENCES reviews(id), viewed_at TEXT,
|
|
2188
|
+
CREATE TABLE IF NOT EXISTS review_attention(review_id TEXT PRIMARY KEY REFERENCES reviews(id), viewed_at TEXT, deleted_at TEXT);
|
|
2157
2189
|
CREATE TABLE IF NOT EXISTS repositories(id TEXT PRIMARY KEY, path TEXT NOT NULL UNIQUE, name TEXT NOT NULL);
|
|
2158
2190
|
CREATE TABLE IF NOT EXISTS resources(id TEXT PRIMARY KEY, repository_id TEXT NOT NULL REFERENCES repositories(id),
|
|
2159
2191
|
kind TEXT NOT NULL, mime_type TEXT NOT NULL, data BLOB NOT NULL);
|
|
@@ -2164,6 +2196,17 @@ function initializeReviewStoreSchema(db) {
|
|
|
2164
2196
|
CREATE TABLE IF NOT EXISTS server_identity(one INTEGER PRIMARY KEY CHECK(one=1), id TEXT NOT NULL);
|
|
2165
2197
|
DROP TABLE IF EXISTS authoring_drafts;
|
|
2166
2198
|
`);
|
|
2199
|
+
db.exec("BEGIN IMMEDIATE");
|
|
2200
|
+
try {
|
|
2201
|
+
if (db.prepare("PRAGMA table_info(review_attention)").all().some((column) => column.name === "dismissed_at")) {
|
|
2202
|
+
db.exec("ALTER TABLE review_attention RENAME COLUMN dismissed_at TO deleted_at");
|
|
2203
|
+
db.prepare("UPDATE review_attention SET deleted_at=? WHERE deleted_at IS NOT NULL").run((/* @__PURE__ */ new Date()).toISOString());
|
|
2204
|
+
}
|
|
2205
|
+
db.exec("COMMIT");
|
|
2206
|
+
} catch (error) {
|
|
2207
|
+
db.exec("ROLLBACK");
|
|
2208
|
+
throw error;
|
|
2209
|
+
}
|
|
2167
2210
|
}
|
|
2168
2211
|
//#endregion
|
|
2169
2212
|
//#region src/review-api/store.ts
|
|
@@ -2184,14 +2227,15 @@ const commandSchema = z.strictObject({ operation: z.discriminatedUnion("type", [
|
|
|
2184
2227
|
type: z.literal("delete"),
|
|
2185
2228
|
reviewId
|
|
2186
2229
|
}),
|
|
2230
|
+
z.strictObject({
|
|
2231
|
+
type: z.literal("lifecycle"),
|
|
2232
|
+
reviewId,
|
|
2233
|
+
state: z.enum(["active", "trash"])
|
|
2234
|
+
}),
|
|
2187
2235
|
z.strictObject({
|
|
2188
2236
|
type: z.literal("attention"),
|
|
2189
2237
|
reviewId,
|
|
2190
|
-
action: z.
|
|
2191
|
-
"view",
|
|
2192
|
-
"dismiss",
|
|
2193
|
-
"restore"
|
|
2194
|
-
])
|
|
2238
|
+
action: z.literal("view")
|
|
2195
2239
|
}),
|
|
2196
2240
|
z.strictObject({
|
|
2197
2241
|
type: z.literal("create"),
|
|
@@ -2249,6 +2293,7 @@ var ReviewStore = class {
|
|
|
2249
2293
|
liveSources = /* @__PURE__ */ new Map();
|
|
2250
2294
|
refreshTimer;
|
|
2251
2295
|
refreshSubscribers = 0;
|
|
2296
|
+
purgeTimer;
|
|
2252
2297
|
watchWorktrees() {
|
|
2253
2298
|
this.refreshSubscribers++;
|
|
2254
2299
|
this.refreshTimer ??= setInterval(() => {
|
|
@@ -2292,6 +2337,7 @@ var ReviewStore = class {
|
|
|
2292
2337
|
if (this.refreshPending) return this.refreshPending;
|
|
2293
2338
|
const run = this.pending.then(async () => {
|
|
2294
2339
|
for (const summary of this.list()) {
|
|
2340
|
+
if (summary.trashedAt) continue;
|
|
2295
2341
|
const snapshot = this.read(summary.reviewId, summary.version);
|
|
2296
2342
|
try {
|
|
2297
2343
|
const live = this.liveSources.get(summary.reviewId);
|
|
@@ -2332,6 +2378,7 @@ var ReviewStore = class {
|
|
|
2332
2378
|
externalChanges;
|
|
2333
2379
|
observedDataVersion;
|
|
2334
2380
|
observedVersions = /* @__PURE__ */ new Map();
|
|
2381
|
+
observedDeletions = /* @__PURE__ */ new Map();
|
|
2335
2382
|
subscribeCatalog(listener) {
|
|
2336
2383
|
this.catalogListeners.add(listener);
|
|
2337
2384
|
return () => {
|
|
@@ -2354,10 +2401,14 @@ var ReviewStore = class {
|
|
|
2354
2401
|
this.providers = providers;
|
|
2355
2402
|
this.db = new DatabaseSync(databasePath, { timeout: 5e3 });
|
|
2356
2403
|
initializeReviewStoreSchema(this.db);
|
|
2357
|
-
this.activity = new ReviewActivity(this.db, (id) => this.
|
|
2404
|
+
this.activity = new ReviewActivity(this.db, (id) => this.assertWritable(id));
|
|
2358
2405
|
this.askHistory = new AskHistory(this.db);
|
|
2406
|
+
this.purgeExpired();
|
|
2407
|
+
this.purgeTimer = setInterval(() => this.purgeExpired(), 6e4);
|
|
2408
|
+
this.purgeTimer.unref();
|
|
2359
2409
|
this.observedDataVersion = this.dataVersion();
|
|
2360
2410
|
this.observedVersions = this.currentVersions();
|
|
2411
|
+
this.observedDeletions = this.currentDeletions();
|
|
2361
2412
|
this.externalChanges = setInterval(() => this.refreshExternalChanges(), 250);
|
|
2362
2413
|
this.externalChanges.unref();
|
|
2363
2414
|
}
|
|
@@ -2367,17 +2418,29 @@ var ReviewStore = class {
|
|
|
2367
2418
|
currentVersions() {
|
|
2368
2419
|
return new Map(this.db.prepare("SELECT id,version FROM reviews").all().map((row) => [String(row.id), Number(row.version)]));
|
|
2369
2420
|
}
|
|
2421
|
+
currentDeletions() {
|
|
2422
|
+
return new Map(this.db.prepare("SELECT review_id,deleted_at FROM review_attention WHERE deleted_at IS NOT NULL").all().map((row) => [String(row.review_id), String(row.deleted_at)]));
|
|
2423
|
+
}
|
|
2370
2424
|
refreshExternalChanges() {
|
|
2371
2425
|
const version = this.dataVersion();
|
|
2372
2426
|
if (version === this.observedDataVersion) return;
|
|
2373
2427
|
this.observedDataVersion = version;
|
|
2374
2428
|
const current = this.currentVersions();
|
|
2375
2429
|
const previous = this.observedVersions;
|
|
2430
|
+
const deletions = this.currentDeletions();
|
|
2431
|
+
const previousDeletions = this.observedDeletions;
|
|
2432
|
+
this.observedDeletions = deletions;
|
|
2376
2433
|
this.observedVersions = current;
|
|
2377
2434
|
for (const [reviewId, savedVersion] of current) if (previous.get(reviewId) !== savedVersion) this.notify({
|
|
2378
2435
|
reviewId,
|
|
2379
2436
|
version: savedVersion
|
|
2380
2437
|
});
|
|
2438
|
+
else if (previousDeletions.get(reviewId) !== deletions.get(reviewId)) this.notify({
|
|
2439
|
+
reviewId,
|
|
2440
|
+
version: savedVersion,
|
|
2441
|
+
lifecycle: true,
|
|
2442
|
+
attention: true
|
|
2443
|
+
});
|
|
2381
2444
|
for (const [reviewId, savedVersion] of previous) if (!current.has(reviewId)) {
|
|
2382
2445
|
this.activity.deleted(reviewId);
|
|
2383
2446
|
this.notify({
|
|
@@ -2400,9 +2463,10 @@ var ReviewStore = class {
|
|
|
2400
2463
|
}]));
|
|
2401
2464
|
}
|
|
2402
2465
|
updateViewedCoverage(reviewId, files, viewed) {
|
|
2403
|
-
this.
|
|
2466
|
+
this.assertWritable(reviewId);
|
|
2404
2467
|
this.db.exec("BEGIN IMMEDIATE");
|
|
2405
2468
|
try {
|
|
2469
|
+
this.assertWritable(reviewId);
|
|
2406
2470
|
const current = this.viewedCoverage(reviewId);
|
|
2407
2471
|
for (const file of files) {
|
|
2408
2472
|
const previous = current.get(file.path);
|
|
@@ -2481,6 +2545,7 @@ var ReviewStore = class {
|
|
|
2481
2545
|
this.closing = true;
|
|
2482
2546
|
clearInterval(this.externalChanges);
|
|
2483
2547
|
clearInterval(this.refreshTimer);
|
|
2548
|
+
clearInterval(this.purgeTimer);
|
|
2484
2549
|
await this.pending;
|
|
2485
2550
|
this.listeners.clear();
|
|
2486
2551
|
this.catalogListeners.clear();
|
|
@@ -2506,6 +2571,53 @@ var ReviewStore = class {
|
|
|
2506
2571
|
assertExists(id) {
|
|
2507
2572
|
if (!this.db.prepare("SELECT 1 FROM reviews WHERE id=?").get(id)) throw new ReviewInputError("Review not found. If this is an old Whiteboard review, ask your agent to migrate your old Whiteboard reviews.", 404);
|
|
2508
2573
|
}
|
|
2574
|
+
assertWritable(id) {
|
|
2575
|
+
this.assertExists(id);
|
|
2576
|
+
const trashedAt = this.trashTime(id);
|
|
2577
|
+
if (trashedAt) throw new ReviewInputError(`This whiteboard was moved to Trash on ${new Date(trashedAt).toLocaleDateString("en-US", {
|
|
2578
|
+
month: "short",
|
|
2579
|
+
day: "numeric"
|
|
2580
|
+
})}. Restore it with session_lifecycle({"sessionId":"${id}","state":"active"}) to continue.`, 409);
|
|
2581
|
+
}
|
|
2582
|
+
trashTime(id) {
|
|
2583
|
+
const row = this.db.prepare("SELECT deleted_at FROM review_attention WHERE review_id=?").get(id);
|
|
2584
|
+
return row?.deleted_at ? String(row.deleted_at) : null;
|
|
2585
|
+
}
|
|
2586
|
+
removePermanently(id) {
|
|
2587
|
+
for (const table of [
|
|
2588
|
+
"ask_conversations",
|
|
2589
|
+
"authoring_presences",
|
|
2590
|
+
"review_coverage",
|
|
2591
|
+
"review_attention",
|
|
2592
|
+
"versions"
|
|
2593
|
+
]) this.db.prepare(`DELETE FROM ${table} WHERE review_id=?`).run(id);
|
|
2594
|
+
this.db.prepare("DELETE FROM reviews WHERE id=?").run(id);
|
|
2595
|
+
this.liveSources.delete(id);
|
|
2596
|
+
}
|
|
2597
|
+
purgeExpired() {
|
|
2598
|
+
const cutoff = (/* @__PURE__ */ new Date(Date.now() - 2592e6)).toISOString();
|
|
2599
|
+
const expired = [];
|
|
2600
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
2601
|
+
try {
|
|
2602
|
+
for (const row of this.db.prepare("SELECT review_id,version FROM review_attention JOIN reviews ON reviews.id=review_id WHERE deleted_at <= ?").all(cutoff)) {
|
|
2603
|
+
const reviewId = String(row.review_id);
|
|
2604
|
+
expired.push({
|
|
2605
|
+
reviewId,
|
|
2606
|
+
version: Number(row.version),
|
|
2607
|
+
deleted: true
|
|
2608
|
+
});
|
|
2609
|
+
this.removePermanently(reviewId);
|
|
2610
|
+
}
|
|
2611
|
+
this.db.exec("COMMIT");
|
|
2612
|
+
} catch (error) {
|
|
2613
|
+
this.db.exec("ROLLBACK");
|
|
2614
|
+
throw error;
|
|
2615
|
+
}
|
|
2616
|
+
for (const result of expired) {
|
|
2617
|
+
this.activity.deleted(result.reviewId);
|
|
2618
|
+
this.notify(result);
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2509
2621
|
read(id, version) {
|
|
2510
2622
|
const row = version === void 0 ? this.db.prepare("SELECT snapshot FROM versions JOIN reviews ON reviews.id=review_id AND reviews.version=versions.version WHERE reviews.id=?").get(id) : this.db.prepare("SELECT snapshot FROM versions WHERE review_id=? AND version=?").get(id, version);
|
|
2511
2623
|
if (!row) {
|
|
@@ -2524,7 +2636,11 @@ var ReviewStore = class {
|
|
|
2524
2636
|
head: snapshot.pins.head
|
|
2525
2637
|
};
|
|
2526
2638
|
const live = version === void 0 ? this.liveSources.get(id) : void 0;
|
|
2527
|
-
if (live?.version === snapshot.version) return
|
|
2639
|
+
if (live?.version === snapshot.version) return {
|
|
2640
|
+
...structuredClone(live),
|
|
2641
|
+
trashedAt: this.trashTime(id)
|
|
2642
|
+
};
|
|
2643
|
+
snapshot.trashedAt = this.trashTime(id);
|
|
2528
2644
|
return snapshot;
|
|
2529
2645
|
}
|
|
2530
2646
|
setDiffStats(pins, stats, mode = "structural") {
|
|
@@ -2548,7 +2664,7 @@ var ReviewStore = class {
|
|
|
2548
2664
|
summaries(mode, id) {
|
|
2549
2665
|
const reviews = this.db.prepare(`SELECT json_remove(versions.snapshot,'$.document') AS summary,
|
|
2550
2666
|
(SELECT json_extract(first.snapshot,'$.createdAt') FROM versions AS first WHERE first.review_id=reviews.id ORDER BY first.version LIMIT 1) AS first_created_at,
|
|
2551
|
-
review_attention.viewed_at, review_attention.
|
|
2667
|
+
review_attention.viewed_at, review_attention.deleted_at, repositories.name AS repository_name, repositories.path AS repository_path
|
|
2552
2668
|
FROM reviews
|
|
2553
2669
|
JOIN versions ON versions.review_id=reviews.id AND versions.version=reviews.version
|
|
2554
2670
|
LEFT JOIN review_attention ON review_attention.review_id=reviews.id
|
|
@@ -2572,7 +2688,7 @@ var ReviewStore = class {
|
|
|
2572
2688
|
repositoryGroup: row.repository_path ? this.repositoryGroup(String(row.repository_path)) : void 0,
|
|
2573
2689
|
repositoryName: row.repository_name ? String(row.repository_name) : summary.pins?.repositoryId ?? "",
|
|
2574
2690
|
viewedAt: row.viewed_at ? String(row.viewed_at) : null,
|
|
2575
|
-
|
|
2691
|
+
trashedAt: row.deleted_at ? String(row.deleted_at) : null,
|
|
2576
2692
|
working: this.activity.isWorking(summary.reviewId)
|
|
2577
2693
|
};
|
|
2578
2694
|
if (summary.kind === "scratchpad") listed.contents = this.scratchpadContents();
|
|
@@ -2629,6 +2745,8 @@ var ReviewStore = class {
|
|
|
2629
2745
|
pullRequest?.catch(() => {});
|
|
2630
2746
|
const run = this.pending.then(async () => {
|
|
2631
2747
|
const op = command.operation;
|
|
2748
|
+
this.purgeExpired();
|
|
2749
|
+
if (op.type !== "create" && op.type !== "delete" && op.type !== "lifecycle") this.assertWritable(op.reviewId);
|
|
2632
2750
|
if (op.type !== "create" && op.type !== "edit" && op.type !== "lens_edit" && op.type !== "restore" && this.read(op.reviewId).kind === "scratchpad") throw new ReviewInputError("The scratchpad has no lifecycle, title or pins of its own.", 409);
|
|
2633
2751
|
if (op.type === "create" && op.kind === "scratchpad") {
|
|
2634
2752
|
if (op.target) throw new ReviewInputError("A scratchpad has no target of its own.");
|
|
@@ -2647,39 +2765,37 @@ var ReviewStore = class {
|
|
|
2647
2765
|
if (found) return this.existingReview(found, others, resolvedTarget.pins);
|
|
2648
2766
|
}
|
|
2649
2767
|
if (op.type === "delete") {
|
|
2768
|
+
this.assertExists(op.reviewId);
|
|
2769
|
+
if (!this.trashTime(op.reviewId)) throw new ReviewInputError("Move this whiteboard to Trash before deleting it.", 409);
|
|
2650
2770
|
const result = {
|
|
2651
2771
|
reviewId: op.reviewId,
|
|
2652
2772
|
version: this.read(op.reviewId).version,
|
|
2653
2773
|
deleted: true
|
|
2654
2774
|
};
|
|
2655
|
-
this.commitCommand(result, () =>
|
|
2656
|
-
for (const table of [
|
|
2657
|
-
"ask_conversations",
|
|
2658
|
-
"authoring_presences",
|
|
2659
|
-
"review_coverage",
|
|
2660
|
-
"review_attention",
|
|
2661
|
-
"versions"
|
|
2662
|
-
]) this.db.prepare(`DELETE FROM ${table} WHERE review_id=?`).run(op.reviewId);
|
|
2663
|
-
this.db.prepare("DELETE FROM reviews WHERE id=?").run(op.reviewId);
|
|
2664
|
-
}, () => this.assertMutation(op.reviewId, result.version));
|
|
2775
|
+
this.commitCommand(result, () => this.removePermanently(op.reviewId), () => this.assertMutation(op.reviewId, result.version));
|
|
2665
2776
|
return result;
|
|
2666
2777
|
}
|
|
2667
|
-
if (op.type === "attention") {
|
|
2778
|
+
if (op.type === "attention" || op.type === "lifecycle") {
|
|
2668
2779
|
const result = {
|
|
2669
2780
|
reviewId: op.reviewId,
|
|
2670
2781
|
version: this.read(op.reviewId).version,
|
|
2671
|
-
attention: true
|
|
2782
|
+
attention: true,
|
|
2783
|
+
...op.type === "lifecycle" && { lifecycle: true }
|
|
2672
2784
|
};
|
|
2673
2785
|
this.commitCommand(result, () => {
|
|
2674
2786
|
this.db.prepare("INSERT OR IGNORE INTO review_attention(review_id) VALUES(?)").run(op.reviewId);
|
|
2675
|
-
if (op.
|
|
2676
|
-
else
|
|
2787
|
+
if (op.type === "attention") this.db.prepare("UPDATE review_attention SET viewed_at=? WHERE review_id=?").run((/* @__PURE__ */ new Date()).toISOString(), op.reviewId);
|
|
2788
|
+
else {
|
|
2789
|
+
const timestamp = op.state === "trash" ? (/* @__PURE__ */ new Date()).toISOString() : null;
|
|
2790
|
+
this.db.prepare("UPDATE review_attention SET deleted_at=CASE WHEN ? IS NULL THEN NULL ELSE COALESCE(deleted_at, ?) END WHERE review_id=?").run(timestamp, timestamp, op.reviewId);
|
|
2791
|
+
}
|
|
2677
2792
|
});
|
|
2678
2793
|
return result;
|
|
2679
2794
|
}
|
|
2680
2795
|
const id = op.type !== "create" ? op.reviewId : op.kind === "scratchpad" ? SCRATCHPAD_ID : randomUUID();
|
|
2681
2796
|
const previous = op.type === "create" ? void 0 : this.read(id);
|
|
2682
2797
|
let snapshot = op.type === "create" ? createdSnapshot(id, op, resolvedTarget, fromPullRequest?.title) : structuredClone(previous);
|
|
2798
|
+
delete snapshot.trashedAt;
|
|
2683
2799
|
delete snapshot.sourceUnavailable;
|
|
2684
2800
|
delete snapshot.lastEdit;
|
|
2685
2801
|
let nextId = previous ? Number(this.db.prepare("SELECT next_id FROM reviews WHERE id=?").get(id).next_id) : 0;
|
|
@@ -2768,7 +2884,10 @@ var ReviewStore = class {
|
|
|
2768
2884
|
this.commitCommand(result, () => {
|
|
2769
2885
|
this.db.prepare("INSERT INTO reviews(id,version,next_id) VALUES(?,?,?) ON CONFLICT(id) DO UPDATE SET version=excluded.version,next_id=excluded.next_id").run(id, snapshot.version, nextId);
|
|
2770
2886
|
this.db.prepare("INSERT INTO versions(review_id,version,snapshot) VALUES(?,?,?)").run(id, snapshot.version, JSON.stringify(snapshot));
|
|
2771
|
-
}, previous ? () =>
|
|
2887
|
+
}, previous ? () => {
|
|
2888
|
+
this.assertWritable(id);
|
|
2889
|
+
this.assertMutation(id, previous.version);
|
|
2890
|
+
} : void 0, op.type === "edit" || op.type === "lens_edit" ? {
|
|
2772
2891
|
surface: op.type === "edit" ? "document" : "lenses",
|
|
2773
2892
|
activityId: op.activityId,
|
|
2774
2893
|
owned: (owner) => {
|
|
@@ -2786,6 +2905,11 @@ var ReviewStore = class {
|
|
|
2786
2905
|
if (op.type !== "create" || op.kind || op.target || !op.pullRequestUrl) return void 0;
|
|
2787
2906
|
if (!this.providers.resolvePullRequest) return Promise.reject(new ReviewInputError("Pull request targets are unavailable."));
|
|
2788
2907
|
const [existing] = op.reuseExisting === false ? [] : this.reviewsForPullRequest(op.pullRequestUrl);
|
|
2908
|
+
if (existing) try {
|
|
2909
|
+
this.assertReusableReview(existing);
|
|
2910
|
+
} catch (error) {
|
|
2911
|
+
return Promise.reject(error);
|
|
2912
|
+
}
|
|
2789
2913
|
return this.providers.resolvePullRequest(op.pullRequestUrl, {
|
|
2790
2914
|
id: op.repositoryId,
|
|
2791
2915
|
preferred: existing && this.read(existing).pins?.repositoryId
|
|
@@ -2799,10 +2923,14 @@ var ReviewStore = class {
|
|
|
2799
2923
|
AND COALESCE(json_extract(versions.snapshot,'$.origin.tutorial'), 0) = 0
|
|
2800
2924
|
ORDER BY json_extract(versions.snapshot,'$.createdAt') DESC, reviews.rowid DESC`).all(pullRequestKey(url)).map((row) => String(row.id));
|
|
2801
2925
|
}
|
|
2926
|
+
assertReusableReview(reviewId) {
|
|
2927
|
+
if (this.trashTime(reviewId)) throw new ReviewInputError(`This PR's whiteboard is in Trash. Restore it to continue:\n\nsession_lifecycle({"sessionId":"${reviewId}","state":"active"})`, 409);
|
|
2928
|
+
}
|
|
2802
2929
|
/** The answer to a create that found its PR's review. Its target stays:
|
|
2803
2930
|
* moving it would silently point existing links at different code. */
|
|
2804
2931
|
existingReview(reviewId, others, requested) {
|
|
2805
2932
|
const snapshot = this.read(reviewId);
|
|
2933
|
+
this.assertReusableReview(reviewId);
|
|
2806
2934
|
const headMoved = snapshot.pins?.repositoryId !== requested.repositoryId || snapshot.pins?.head !== requested.head;
|
|
2807
2935
|
const working = this.activity.read(reviewId).activities ?? [];
|
|
2808
2936
|
return {
|
|
@@ -2848,16 +2976,16 @@ var ReviewStore = class {
|
|
|
2848
2976
|
notify(result) {
|
|
2849
2977
|
if (result.deleted) this.observedVersions.delete(result.reviewId);
|
|
2850
2978
|
else if (!result.attention) this.observedVersions.set(result.reviewId, result.version);
|
|
2851
|
-
if (!result.attention) for (const listener of this.listeners) try {
|
|
2979
|
+
if (!result.attention || result.lifecycle) for (const listener of this.listeners) try {
|
|
2852
2980
|
listener(result);
|
|
2853
2981
|
} catch {}
|
|
2854
2982
|
for (const listener of this.catalogListeners) try {
|
|
2855
2983
|
listener();
|
|
2856
2984
|
} catch {}
|
|
2857
2985
|
}
|
|
2858
|
-
/**
|
|
2859
|
-
|
|
2860
|
-
return this.db.prepare("SELECT review_id FROM review_attention WHERE
|
|
2986
|
+
/** Viewing a review in Trash does not restore it. */
|
|
2987
|
+
trashedIds() {
|
|
2988
|
+
return this.db.prepare("SELECT review_id FROM review_attention WHERE deleted_at IS NOT NULL").all().map((row) => String(row.review_id));
|
|
2861
2989
|
}
|
|
2862
2990
|
has(reviewId) {
|
|
2863
2991
|
return this.db.prepare("SELECT 1 FROM reviews WHERE id=?").get(reviewId) !== void 0;
|
|
@@ -2994,23 +3122,23 @@ var ReviewWorkspaces = class {
|
|
|
2994
3122
|
}
|
|
2995
3123
|
this.stop = store.subscribeCatalog(() => {
|
|
2996
3124
|
this.collect();
|
|
2997
|
-
this.
|
|
3125
|
+
this.releaseTrashed();
|
|
2998
3126
|
});
|
|
2999
3127
|
this.collect();
|
|
3000
|
-
this.
|
|
3128
|
+
this.releaseTrashed();
|
|
3001
3129
|
}
|
|
3002
|
-
|
|
3130
|
+
trashed;
|
|
3003
3131
|
releasing = /* @__PURE__ */ new Map();
|
|
3004
3132
|
/**
|
|
3005
|
-
* Frees a newly
|
|
3133
|
+
* Frees a newly trashed review's checkouts to save disk. The review itself
|
|
3006
3134
|
* stays; reopening it rebuilds them. Checkouts rebuilt by peeking at a
|
|
3007
|
-
*
|
|
3135
|
+
* trashed review are kept until the next startup or move to Trash, since
|
|
3008
3136
|
* the Desktop's canvas tabs and source windows may still show them.
|
|
3009
3137
|
*/
|
|
3010
|
-
|
|
3011
|
-
const
|
|
3012
|
-
const released = [...
|
|
3013
|
-
this.
|
|
3138
|
+
releaseTrashed() {
|
|
3139
|
+
const trashed = new Set(this.store.trashedIds());
|
|
3140
|
+
const released = [...trashed].filter((id) => !this.trashed?.has(id));
|
|
3141
|
+
this.trashed = trashed;
|
|
3014
3142
|
if (!released.length) return;
|
|
3015
3143
|
const repositories = this.repositoryDirs();
|
|
3016
3144
|
repositories.catch(() => void 0);
|
|
@@ -3034,7 +3162,7 @@ var ReviewWorkspaces = class {
|
|
|
3034
3162
|
await Promise.allSettled(requests);
|
|
3035
3163
|
await this.releaseCheckouts(reviewId, await repositories);
|
|
3036
3164
|
}).catch((error) => {
|
|
3037
|
-
console.error(`Could not free the pinned checkouts of
|
|
3165
|
+
console.error(`Could not free the pinned checkouts of trashed review ${reviewId}:`, error);
|
|
3038
3166
|
}).finally(() => {
|
|
3039
3167
|
if (this.releasing.get(reviewId) === done) this.releasing.delete(reviewId);
|
|
3040
3168
|
});
|
|
@@ -3042,7 +3170,7 @@ var ReviewWorkspaces = class {
|
|
|
3042
3170
|
this.cleanup = done;
|
|
3043
3171
|
}
|
|
3044
3172
|
async releaseCheckouts(reviewId, repositories) {
|
|
3045
|
-
if (!this.store.
|
|
3173
|
+
if (!this.store.trashedIds().includes(reviewId)) return;
|
|
3046
3174
|
const environments = this.all().filter((item) => item.reviewId === reviewId);
|
|
3047
3175
|
const checkouts = repositories.filter((repository) => existsSync(reviewManagedCheckoutRoot(repository, reviewId)));
|
|
3048
3176
|
if (!environments.length && !checkouts.length || !this.claim(reviewId)) return;
|
|
@@ -3358,7 +3486,43 @@ function rootEventMatters(name, tracked) {
|
|
|
3358
3486
|
if (file === ".git" || file.startsWith(".git/")) return false;
|
|
3359
3487
|
return !tracked || tracked.has(parent(file));
|
|
3360
3488
|
}
|
|
3489
|
+
/** A directory appearing at the edge of the tracked tree may be newly ignored. */
|
|
3490
|
+
function atTrackedEdge(name, tracked) {
|
|
3491
|
+
const file = normalize(name);
|
|
3492
|
+
return !!tracked && tracked.has(parent(file)) && !tracked.has(file);
|
|
3493
|
+
}
|
|
3494
|
+
/** Wholly ignored directories, so watchers can skip them. */
|
|
3495
|
+
async function ignoredDirectories(rootPath, gitDirectory) {
|
|
3496
|
+
try {
|
|
3497
|
+
const { stdout } = await exec$1("git", [
|
|
3498
|
+
"-C",
|
|
3499
|
+
rootPath,
|
|
3500
|
+
...gitDirectory ? [
|
|
3501
|
+
"--git-dir",
|
|
3502
|
+
gitDirectory,
|
|
3503
|
+
"--work-tree",
|
|
3504
|
+
rootPath
|
|
3505
|
+
] : [],
|
|
3506
|
+
"ls-files",
|
|
3507
|
+
"-z",
|
|
3508
|
+
"--others",
|
|
3509
|
+
"--ignored",
|
|
3510
|
+
"--exclude-standard",
|
|
3511
|
+
"--directory"
|
|
3512
|
+
], { maxBuffer: 33554432 });
|
|
3513
|
+
return stdout.split("\0").filter((entry) => entry.endsWith("/") && entry !== ".jj/").map((entry) => entry.slice(0, -1));
|
|
3514
|
+
} catch {
|
|
3515
|
+
return [];
|
|
3516
|
+
}
|
|
3517
|
+
}
|
|
3361
3518
|
const CHECKOUT_STATE = /^(?:index|[A-Z_]+|(?:rebase-merge|rebase-apply|sequencer|refs\/(?:bisect|worktree|rewritten))(?:\/.*)?)$/;
|
|
3519
|
+
/** Objects, reflogs, LFS objects and Review's own checkouts; never watched. */
|
|
3520
|
+
const INERT_GIT_PATHS = [
|
|
3521
|
+
"objects",
|
|
3522
|
+
"logs",
|
|
3523
|
+
"lfs",
|
|
3524
|
+
"dev-fast"
|
|
3525
|
+
];
|
|
3362
3526
|
/** Objects, reflogs, locks and other checkouts' state cannot change this one. */
|
|
3363
3527
|
function gitEventMatters(name, prefix) {
|
|
3364
3528
|
const file = normalize(name);
|
|
@@ -3770,7 +3934,7 @@ var LocalReviewData = class {
|
|
|
3770
3934
|
worktrees = /* @__PURE__ */ new Map();
|
|
3771
3935
|
forgetWorktree(repositoryId) {
|
|
3772
3936
|
const entry = this.worktrees.get(repositoryId);
|
|
3773
|
-
if (entry)
|
|
3937
|
+
if (entry) unwatch(entry);
|
|
3774
3938
|
this.worktrees.delete(repositoryId);
|
|
3775
3939
|
}
|
|
3776
3940
|
async worktreeState(repositoryId, vcs) {
|
|
@@ -3779,33 +3943,59 @@ var LocalReviewData = class {
|
|
|
3779
3943
|
entry = {
|
|
3780
3944
|
epoch: 0,
|
|
3781
3945
|
inspectedEpoch: -1,
|
|
3782
|
-
|
|
3946
|
+
subscriptions: /* @__PURE__ */ new Map(),
|
|
3783
3947
|
healthy: true,
|
|
3784
3948
|
forks: /* @__PURE__ */ new Map()
|
|
3785
3949
|
};
|
|
3786
3950
|
this.worktrees.set(repositoryId, entry);
|
|
3787
3951
|
const state = entry;
|
|
3952
|
+
const current = () => this.worktrees.get(repositoryId) === state;
|
|
3788
3953
|
const common = await gitCommonDir(vcs.rootPath);
|
|
3789
3954
|
const prefix = vcs.kind === "git" && common ? await gitDirectoryPrefix(vcs.rootPath, common) : null;
|
|
3790
|
-
const
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3955
|
+
const watch = async (root, ignore, matters) => {
|
|
3956
|
+
try {
|
|
3957
|
+
const subscription = await (this.options.subscribe ?? (await import("@parcel/watcher")).subscribe)(root, (error, events) => {
|
|
3958
|
+
if (error) {
|
|
3959
|
+
state.healthy = false;
|
|
3960
|
+
const failed = state.subscriptions.get(root);
|
|
3961
|
+
if (failed) release(failed);
|
|
3962
|
+
state.subscriptions.delete(root);
|
|
3963
|
+
} else if (events.map((event) => matters(path.relative(root, event.path), event)).includes(true)) state.epoch++;
|
|
3964
|
+
}, { ignore });
|
|
3965
|
+
if (!current()) return void release(subscription);
|
|
3966
|
+
const previous = state.subscriptions.get(root);
|
|
3967
|
+
state.subscriptions.set(root, subscription);
|
|
3968
|
+
if (previous) release(previous);
|
|
3969
|
+
} catch {
|
|
3799
3970
|
state.healthy = false;
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
state.
|
|
3806
|
-
|
|
3971
|
+
}
|
|
3972
|
+
};
|
|
3973
|
+
const rootIgnore = async () => [...common ? [".git"] : [], ...await ignoredDirectories(vcs.rootPath, vcs.kind === "jj" ? common ?? void 0 : void 0)].map((directory) => path.join(vcs.rootPath, directory));
|
|
3974
|
+
let ignored = await rootIgnore();
|
|
3975
|
+
const refreshIgnored = () => {
|
|
3976
|
+
clearTimeout(state.ignoring);
|
|
3977
|
+
state.ignoring = setTimeout(async () => {
|
|
3978
|
+
const next = await rootIgnore();
|
|
3979
|
+
if (!current() || next.join("\0") === ignored.join("\0")) return;
|
|
3980
|
+
ignored = next;
|
|
3981
|
+
const previous = state.subscriptions.get(vcs.rootPath);
|
|
3982
|
+
state.subscriptions.delete(vcs.rootPath);
|
|
3983
|
+
if (previous) await release(previous);
|
|
3984
|
+
await watch(vcs.rootPath, ignored, rootMatters);
|
|
3985
|
+
state.epoch++;
|
|
3986
|
+
}, 1e3);
|
|
3987
|
+
state.ignoring.unref();
|
|
3988
|
+
};
|
|
3989
|
+
const rootMatters = (name, event) => {
|
|
3990
|
+
if (path.basename(name) === ".gitignore" || event.type === "create" && atTrackedEdge(name, state.tracked) && statSync(event.path, { throwIfNoEntry: false })?.isDirectory()) refreshIgnored();
|
|
3991
|
+
return prefix === null || rootEventMatters(name, state.tracked);
|
|
3992
|
+
};
|
|
3993
|
+
await Promise.all([watch(vcs.rootPath, ignored, rootMatters), common && watch(common, INERT_GIT_PATHS.map((directory) => path.join(common, directory)), (name) => {
|
|
3994
|
+
if (name === path.join("info", "exclude")) refreshIgnored();
|
|
3995
|
+
return prefix === null || gitEventMatters(name, prefix);
|
|
3996
|
+
})]);
|
|
3807
3997
|
}
|
|
3808
|
-
if (entry.inspection && entry.inspectedEpoch === entry.epoch && entry.healthy && entry.
|
|
3998
|
+
if (entry.inspection && entry.inspectedEpoch === entry.epoch && entry.healthy && entry.subscriptions.size) return {
|
|
3809
3999
|
...entry.inspection,
|
|
3810
4000
|
forks: entry.forks
|
|
3811
4001
|
};
|
|
@@ -3828,7 +4018,7 @@ var LocalReviewData = class {
|
|
|
3828
4018
|
this.structuralComparisons.close();
|
|
3829
4019
|
this.closed = true;
|
|
3830
4020
|
await this.workspaceManager?.close();
|
|
3831
|
-
|
|
4021
|
+
await Promise.all([...this.worktrees.values()].map(unwatch));
|
|
3832
4022
|
this.worktrees.clear();
|
|
3833
4023
|
const readers = [...this.readers.values()];
|
|
3834
4024
|
this.readers.clear();
|
|
@@ -4221,6 +4411,7 @@ var LocalReviewData = class {
|
|
|
4221
4411
|
return {
|
|
4222
4412
|
pending: this.coveragePending(reviewId, pins, mode),
|
|
4223
4413
|
comparison: this.coverageCache.get(JSON.stringify([pins, mode])).partial ?? {
|
|
4414
|
+
counted: false,
|
|
4224
4415
|
files: [],
|
|
4225
4416
|
fileSources: /* @__PURE__ */ new Map(),
|
|
4226
4417
|
alignments: /* @__PURE__ */ new Map()
|
|
@@ -4272,10 +4463,11 @@ var LocalReviewData = class {
|
|
|
4272
4463
|
}
|
|
4273
4464
|
return entry.promise;
|
|
4274
4465
|
}
|
|
4275
|
-
async changes(pins, file) {
|
|
4466
|
+
async changes(pins, file, previousPath) {
|
|
4276
4467
|
if (file === void 0) return this.summaries(pins);
|
|
4277
4468
|
checkRelativePath(file);
|
|
4278
|
-
|
|
4469
|
+
if (previousPath) checkRelativePath(previousPath);
|
|
4470
|
+
return this.rawPatch(pins, { paths: previousPath ? [previousPath, file] : [file] });
|
|
4279
4471
|
}
|
|
4280
4472
|
async summaries(pins) {
|
|
4281
4473
|
if (pins.worktreeRevision) return diffFileSummariesWorkingTree(await this.worktreeInput(pins));
|
|
@@ -4451,6 +4643,14 @@ function inputError(run) {
|
|
|
4451
4643
|
throw error;
|
|
4452
4644
|
}
|
|
4453
4645
|
}
|
|
4646
|
+
async function unwatch(entry) {
|
|
4647
|
+
clearTimeout(entry.ignoring);
|
|
4648
|
+
const subscriptions = [...entry.subscriptions.values()];
|
|
4649
|
+
entry.subscriptions.clear();
|
|
4650
|
+
await Promise.all(subscriptions.map(release));
|
|
4651
|
+
}
|
|
4652
|
+
/** Linux fails to unwatch a directory that is already gone. */
|
|
4653
|
+
const release = (subscription) => subscription.unsubscribe().catch(() => {});
|
|
4454
4654
|
function openLocalReviewStore(databasePath, options = {}) {
|
|
4455
4655
|
const store = new ReviewStore(databasePath, {
|
|
4456
4656
|
projectSource: (snapshot, pins) => data.projectSource(snapshot, pins),
|