@andares/pi-toolkits 1.0.2 → 1.2.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/CHANGELOG.md +21 -0
- package/README.md +65 -1
- package/README.zh-CN.md +58 -1
- package/package.json +7 -4
- package/src/features/keep/constants.ts +44 -0
- package/src/features/keep/format.ts +77 -0
- package/src/features/keep/index.ts +409 -0
- package/src/features/keep/keep.test.ts +955 -0
- package/src/features/keep/ledger.ts +340 -0
- package/src/features/keep/picker.ts +257 -0
- package/src/features/keep/store.ts +271 -0
- package/src/features/review-page/assets/index-CrDwcsqI.css +1 -0
- package/src/features/review-page/assets/index-DYxi32gA.js +1 -0
- package/src/features/{spec → review-page}/assets/index.html +2 -2
- package/src/features/{spec → review-page}/blocks.test.ts +17 -0
- package/src/features/{spec → review-page}/blocks.ts +9 -0
- package/src/features/review-page/headings.test.ts +44 -0
- package/src/features/review-page/headings.ts +67 -0
- package/src/features/spec/assets.test.ts +2 -2
- package/src/features/spec/diff.test.ts +1 -1
- package/src/features/spec/diff.ts +1 -1
- package/src/features/spec/feedback.test.ts +1 -1
- package/src/features/spec/feedback.ts +1 -1
- package/src/features/spec/index.test.ts +121 -0
- package/src/features/spec/index.ts +82 -23
- package/src/features/spec/server.test.ts +65 -2
- package/src/features/spec/server.ts +29 -5
- package/src/features/spec/store.ts +1 -1
- package/src/features/talk/index.test.ts +230 -0
- package/src/features/talk/index.ts +241 -0
- package/src/features/talk/message.test.ts +212 -0
- package/src/features/talk/message.ts +152 -0
- package/src/features/talk/reply.test.ts +116 -0
- package/src/features/talk/reply.ts +92 -0
- package/src/features/talk/sections.test.ts +39 -0
- package/src/features/talk/sections.ts +44 -0
- package/src/features/talk/server.test.ts +247 -0
- package/src/features/talk/server.ts +211 -0
- package/src/features/uat/ledger.ts +13 -62
- package/src/index.ts +7 -0
- package/src/lib/event-ledger.ts +112 -0
- package/src/features/spec/assets/index-CdTerMvN.css +0 -1
- package/src/features/spec/assets/index-Dv52AIjX.js +0 -1
- /package/src/features/{spec → review-page}/render.test.ts +0 -0
- /package/src/features/{spec → review-page}/render.ts +0 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* talk server — the reply-annotation page, served from inside pi.
|
|
3
|
+
*
|
|
4
|
+
* Same contract as the spec review (`/ask-spec`), minus the things a snapshot
|
|
5
|
+
* does not have: no revisions, no diff, no decision. The page pulls
|
|
6
|
+
* `/api/state`, writes notes and the composer draft back as the operator types,
|
|
7
|
+
* and `POST /api/continue` ends the round.
|
|
8
|
+
*
|
|
9
|
+
* One snapshot accepts exactly one Continue. After it, every write route answers
|
|
10
|
+
* 409 and the port closes: the page is a tab the operator opened, so a second
|
|
11
|
+
* submit from a stale tab must not deliver a second message into the session.
|
|
12
|
+
*
|
|
13
|
+
* The HTTP shell (token, Host allowlist, Origin refusal, port walk, static
|
|
14
|
+
* files, SSE) lives in `src/lib/web-review.ts`.
|
|
15
|
+
*/
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { blockLabel, type Block } from "../review-page/blocks.js";
|
|
18
|
+
import type { Heading } from "../review-page/headings.js";
|
|
19
|
+
import { renderBlockHtml } from "../review-page/render.js";
|
|
20
|
+
import { bindHost, isWsl, urlHost } from "../../lib/opener.js";
|
|
21
|
+
import { startWebServer, type WebServerHandle } from "../../lib/web-review.js";
|
|
22
|
+
|
|
23
|
+
/** The one reply being annotated. Lives in memory; a session switch drops it. */
|
|
24
|
+
export interface TalkSession {
|
|
25
|
+
text: string;
|
|
26
|
+
blocks: Block[];
|
|
27
|
+
headings: Heading[];
|
|
28
|
+
model?: string;
|
|
29
|
+
at: string;
|
|
30
|
+
/** Session entry id, rechecked when Continue actually arrives. */
|
|
31
|
+
entryId: string;
|
|
32
|
+
fingerprint: string;
|
|
33
|
+
/** blockId → note. One note per block by design. */
|
|
34
|
+
notes: Record<string, string>;
|
|
35
|
+
/** Composer text — kept server-side so a page refresh does not erase it. */
|
|
36
|
+
draft: string;
|
|
37
|
+
sent: boolean;
|
|
38
|
+
/** False when compaction pushed the reply out of the model's context. */
|
|
39
|
+
inContext: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface TalkStateItem {
|
|
43
|
+
id: string;
|
|
44
|
+
kind: Block["kind"];
|
|
45
|
+
html: string;
|
|
46
|
+
label: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface TalkStatePayload {
|
|
50
|
+
mode: "talk";
|
|
51
|
+
reply: { model?: string; at: string; chars: number };
|
|
52
|
+
items: TalkStateItem[];
|
|
53
|
+
headings: Heading[];
|
|
54
|
+
notes: Record<string, string>;
|
|
55
|
+
draft: string;
|
|
56
|
+
sent: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Everything except the rendered HTML, which needs the renderer. */
|
|
60
|
+
export function buildTalkState(session: TalkSession): TalkStatePayload {
|
|
61
|
+
return {
|
|
62
|
+
mode: "talk",
|
|
63
|
+
reply: { model: session.model, at: session.at, chars: session.text.length },
|
|
64
|
+
items: session.blocks.map((block) => ({
|
|
65
|
+
id: block.id,
|
|
66
|
+
kind: block.kind,
|
|
67
|
+
html: "",
|
|
68
|
+
label: blockLabel(block),
|
|
69
|
+
})),
|
|
70
|
+
headings: session.headings,
|
|
71
|
+
notes: { ...session.notes },
|
|
72
|
+
draft: session.draft,
|
|
73
|
+
sent: session.sent,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Keep only notes that point at a block of this reply.
|
|
79
|
+
*
|
|
80
|
+
* A page left open across a refresh can post ids the new reply does not have;
|
|
81
|
+
* forwarding those would put a quote-less note in front of the model.
|
|
82
|
+
*/
|
|
83
|
+
export function sanitizeNotes(input: unknown, blocks: readonly Block[]): Record<string, string> {
|
|
84
|
+
const known = new Set<string>();
|
|
85
|
+
for (const block of blocks) {
|
|
86
|
+
if (block.kind !== "heading") known.add(block.id);
|
|
87
|
+
}
|
|
88
|
+
const raw = (input ?? {}) as Record<string, unknown>;
|
|
89
|
+
const notes: Record<string, string> = {};
|
|
90
|
+
for (const [id, value] of Object.entries(raw)) {
|
|
91
|
+
if (!known.has(id)) continue;
|
|
92
|
+
if (typeof value !== "string") continue;
|
|
93
|
+
const text = value.trim();
|
|
94
|
+
if (text === "") continue;
|
|
95
|
+
notes[id] = value;
|
|
96
|
+
}
|
|
97
|
+
return notes;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const MAX_DRAFT = 200_000;
|
|
101
|
+
|
|
102
|
+
export interface StartTalkServerOptions {
|
|
103
|
+
session: TalkSession;
|
|
104
|
+
/** Directory with the built UI. Defaults to the shared review-page assets. */
|
|
105
|
+
assetsDir?: string;
|
|
106
|
+
portStart?: number;
|
|
107
|
+
portAttempts?: number;
|
|
108
|
+
/** Milliseconds between Continue and the port closing. */
|
|
109
|
+
closeDelayMs?: number;
|
|
110
|
+
render?: (block: Pick<Block, "kind" | "text">) => string;
|
|
111
|
+
/** Fired once, as soon as Continue is accepted. */
|
|
112
|
+
onContinue?: (result: { notes: Record<string, string>; message: string }) => void;
|
|
113
|
+
onNotes?: (result: { notes: Record<string, string>; draft: string }) => void;
|
|
114
|
+
bindHost?: string;
|
|
115
|
+
urlHost?: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface TalkServerHandle {
|
|
119
|
+
url: string;
|
|
120
|
+
port: number;
|
|
121
|
+
token: string;
|
|
122
|
+
close: () => Promise<void>;
|
|
123
|
+
broadcast: (event: string, data: unknown) => void;
|
|
124
|
+
/** False once Continue was accepted or `close()` ran. */
|
|
125
|
+
active: () => boolean;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function startTalkServer(
|
|
129
|
+
options: StartTalkServerOptions,
|
|
130
|
+
): Promise<TalkServerHandle> {
|
|
131
|
+
const assetsDir =
|
|
132
|
+
options.assetsDir ?? fileURLToPath(new URL("../review-page/assets/", import.meta.url));
|
|
133
|
+
const render = options.render ?? renderBlockHtml;
|
|
134
|
+
const closeDelayMs = options.closeDelayMs ?? 1200;
|
|
135
|
+
let closing = false;
|
|
136
|
+
let closed = false;
|
|
137
|
+
let handle: WebServerHandle | undefined;
|
|
138
|
+
|
|
139
|
+
const closeHandle = async (): Promise<void> => {
|
|
140
|
+
if (closed) return;
|
|
141
|
+
closed = true;
|
|
142
|
+
closing = true;
|
|
143
|
+
await handle?.close();
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const server = await startWebServer({
|
|
147
|
+
assetsDir,
|
|
148
|
+
portStart: options.portStart ?? 3501,
|
|
149
|
+
portAttempts: options.portAttempts,
|
|
150
|
+
bindHost: options.bindHost ?? bindHost(isWsl()),
|
|
151
|
+
urlHost: options.urlHost ?? urlHost(isWsl()),
|
|
152
|
+
routes: async (ctx) => {
|
|
153
|
+
if (ctx.url.pathname === "/api/state" && ctx.req.method === "GET") {
|
|
154
|
+
const state = buildTalkState(options.session);
|
|
155
|
+
const html = new Map<string, string>();
|
|
156
|
+
for (const block of options.session.blocks) html.set(block.id, render(block));
|
|
157
|
+
ctx.json({
|
|
158
|
+
...state,
|
|
159
|
+
items: state.items.map((item) => ({ ...item, html: html.get(item.id) ?? "" })),
|
|
160
|
+
});
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (ctx.url.pathname === "/api/notes" && ctx.req.method === "POST") {
|
|
165
|
+
if (closing || options.session.sent) {
|
|
166
|
+
ctx.json({ error: "this reply has already been sent" }, 409);
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
const body = (await ctx.readBody()) as { notes?: unknown; draft?: unknown };
|
|
170
|
+
const notes = sanitizeNotes(body.notes, options.session.blocks);
|
|
171
|
+
const draft = typeof body.draft === "string" ? body.draft.slice(0, MAX_DRAFT) : "";
|
|
172
|
+
options.session.notes = notes;
|
|
173
|
+
options.session.draft = draft;
|
|
174
|
+
options.onNotes?.({ notes, draft });
|
|
175
|
+
ctx.json({ ok: true });
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (ctx.url.pathname === "/api/continue" && ctx.req.method === "POST") {
|
|
180
|
+
if (closing || options.session.sent) {
|
|
181
|
+
ctx.json({ error: "this reply has already been sent" }, 409);
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
const body = (await ctx.readBody()) as { notes?: unknown; message?: unknown };
|
|
185
|
+
const notes = sanitizeNotes(body.notes, options.session.blocks);
|
|
186
|
+
const message = typeof body.message === "string" ? body.message.slice(0, MAX_DRAFT) : "";
|
|
187
|
+
options.session.notes = notes;
|
|
188
|
+
options.session.draft = message;
|
|
189
|
+
options.session.sent = true;
|
|
190
|
+
closing = true;
|
|
191
|
+
ctx.json({ ok: true });
|
|
192
|
+
ctx.broadcast("sent", { at: new Date().toISOString() });
|
|
193
|
+
options.onContinue?.({ notes, message });
|
|
194
|
+
setTimeout(() => void closeHandle(), closeDelayMs).unref();
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return false;
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
handle = server;
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
url: server.url,
|
|
205
|
+
port: server.port,
|
|
206
|
+
token: server.token,
|
|
207
|
+
close: closeHandle,
|
|
208
|
+
broadcast: server.broadcast,
|
|
209
|
+
active: () => !closing && !closed,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
@@ -16,17 +16,13 @@
|
|
|
16
16
|
* never called `record_change` still gets a correct (if less informative)
|
|
17
17
|
* acceptance queue.
|
|
18
18
|
*/
|
|
19
|
+
import { join } from "node:path";
|
|
19
20
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
readFileSync,
|
|
26
|
-
readSync,
|
|
27
|
-
statSync,
|
|
28
|
-
} from "node:fs";
|
|
29
|
-
import { dirname, join } from "node:path";
|
|
21
|
+
appendLedgerLine,
|
|
22
|
+
newLedgerEventId,
|
|
23
|
+
parseLedgerLines,
|
|
24
|
+
readLedgerLines,
|
|
25
|
+
} from "../../lib/event-ledger.js";
|
|
30
26
|
import type { RecordEntry } from "./records.js";
|
|
31
27
|
|
|
32
28
|
export const LEDGER_VERSION = 1;
|
|
@@ -179,61 +175,21 @@ export function ledgerPath(root: string): string {
|
|
|
179
175
|
|
|
180
176
|
/** Monotonic-enough id: time plus 6 random base36 chars. */
|
|
181
177
|
export function newEventId(now: Date = new Date()): string {
|
|
182
|
-
|
|
183
|
-
return `e-${now.getTime().toString(36)}-${random}`;
|
|
178
|
+
return newLedgerEventId(now);
|
|
184
179
|
}
|
|
185
180
|
|
|
186
181
|
/**
|
|
187
|
-
* Append one event. The
|
|
188
|
-
*
|
|
189
|
-
*
|
|
182
|
+
* Append one event. The line boundary is repaired by the shared ledger helper:
|
|
183
|
+
* an interrupted write must not glue two JSON objects into one line, which
|
|
184
|
+
* would silently drop both on read.
|
|
190
185
|
*/
|
|
191
186
|
export function appendEvent(file: string, event: UatEvent): void {
|
|
192
|
-
|
|
193
|
-
const line = JSON.stringify(event);
|
|
194
|
-
if (existsSync(file) && statSync(file).size > 0 && !endsWithNewline(file)) {
|
|
195
|
-
appendFileSync(file, `\n${line}\n`, "utf8");
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
appendFileSync(file, `${line}\n`, "utf8");
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function endsWithNewline(file: string): boolean {
|
|
202
|
-
const fd = openSync(file, "r");
|
|
203
|
-
try {
|
|
204
|
-
const size = statSync(file).size;
|
|
205
|
-
const buffer = Buffer.alloc(1);
|
|
206
|
-
readSync(fd, buffer, 0, 1, size - 1);
|
|
207
|
-
return buffer[0] === 0x0a;
|
|
208
|
-
} finally {
|
|
209
|
-
closeSync(fd);
|
|
210
|
-
}
|
|
187
|
+
appendLedgerLine(file, event);
|
|
211
188
|
}
|
|
212
189
|
|
|
213
190
|
/** Parse the stream, skipping malformed lines and duplicate ids. */
|
|
214
191
|
export function parseEvents(raw: string): { events: UatEvent[]; skipped: number } {
|
|
215
|
-
|
|
216
|
-
const seen = new Set<string>();
|
|
217
|
-
let skipped = 0;
|
|
218
|
-
for (const line of raw.split("\n")) {
|
|
219
|
-
const trimmed = line.trim();
|
|
220
|
-
if (trimmed === "") continue;
|
|
221
|
-
let parsed: unknown;
|
|
222
|
-
try {
|
|
223
|
-
parsed = JSON.parse(trimmed);
|
|
224
|
-
} catch {
|
|
225
|
-
skipped += 1;
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
if (!isEvent(parsed)) {
|
|
229
|
-
skipped += 1;
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
if (seen.has(parsed.id)) continue;
|
|
233
|
-
seen.add(parsed.id);
|
|
234
|
-
events.push(parsed);
|
|
235
|
-
}
|
|
236
|
-
return { events, skipped };
|
|
192
|
+
return parseLedgerLines(raw, isEvent);
|
|
237
193
|
}
|
|
238
194
|
|
|
239
195
|
function isEvent(value: unknown): value is UatEvent {
|
|
@@ -298,12 +254,7 @@ function isEvent(value: unknown): value is UatEvent {
|
|
|
298
254
|
}
|
|
299
255
|
|
|
300
256
|
export function readEvents(file: string): { events: UatEvent[]; skipped: number } {
|
|
301
|
-
|
|
302
|
-
try {
|
|
303
|
-
return parseEvents(readFileSync(file, "utf8"));
|
|
304
|
-
} catch {
|
|
305
|
-
return { events: [], skipped: 1 };
|
|
306
|
-
}
|
|
257
|
+
return readLedgerLines(file, isEvent);
|
|
307
258
|
}
|
|
308
259
|
|
|
309
260
|
/** Latest candidate metadata per report id (last write wins). */
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* - init — agent memory framework install / adoption (/ask-init)
|
|
16
16
|
* - uat — acceptance ledger and browser page (/ask-uat, record_change)
|
|
17
17
|
* - quit-guard — quit watchdog: force-exit when pi's shutdown hangs (/quit-guard)
|
|
18
|
+
* - keep — session backlog: keep-quit / keep-load / keep-drop
|
|
18
19
|
* - whats-new — automatic release notes on the first start after an upgrade
|
|
19
20
|
*
|
|
20
21
|
* `ask` and `permission` are independent gates on one bus: each answers its own
|
|
@@ -29,11 +30,13 @@ import { registerAutostart } from "./features/autostart/index.js";
|
|
|
29
30
|
import { registerCompact } from "./features/compact/index.js";
|
|
30
31
|
import { registerFavorites } from "./features/favorites/index.js";
|
|
31
32
|
import { registerInit } from "./features/init/index.js";
|
|
33
|
+
import { registerKeep } from "./features/keep/index.js";
|
|
32
34
|
import { registerPermission } from "./features/permission/index.js";
|
|
33
35
|
import { registerSpec } from "./features/spec/index.js";
|
|
34
36
|
import { registerQuitGuard } from "./features/quit-guard/index.js";
|
|
35
37
|
import { registerReview } from "./features/review/index.js";
|
|
36
38
|
import { registerStash } from "./features/stash/index.js";
|
|
39
|
+
import { registerTalk } from "./features/talk/index.js";
|
|
37
40
|
import { registerUat } from "./features/uat/index.js";
|
|
38
41
|
import { registerWhatsNew } from "./features/whats-new/index.js";
|
|
39
42
|
|
|
@@ -54,9 +57,13 @@ export default function piToolkits(pi: ExtensionAPI): void {
|
|
|
54
57
|
registerCompact(pi);
|
|
55
58
|
registerFavorites(pi);
|
|
56
59
|
registerInit(pi);
|
|
60
|
+
registerKeep(pi);
|
|
57
61
|
registerQuitGuard(pi);
|
|
58
62
|
registerReview(pi);
|
|
59
63
|
registerStash(pi);
|
|
64
|
+
// Not a phase: no tools, no gates, no prompt banner. Registered after the
|
|
65
|
+
// phases so it never competes with their `before_agent_start` assertions.
|
|
66
|
+
registerTalk(pi);
|
|
60
67
|
// UAT registers after spec so its `before_agent_start` re-assertion runs last
|
|
61
68
|
// and can add `record_change` to whatever tool set spec installed.
|
|
62
69
|
registerUat(pi);
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append-only event ledger — the mechanics two features share.
|
|
3
|
+
*
|
|
4
|
+
* Both the acceptance ledger (`.agents/uat/ledger.jsonl`) and the keep ledger
|
|
5
|
+
* (`<agent-dir>/pi-toolkits-keep/keep.jsonl`) are the same shape: one JSON
|
|
6
|
+
* object per line, deduplicated by `id`, read whole and folded into state by a
|
|
7
|
+
* pure function. Three properties are load-bearing in both places:
|
|
8
|
+
*
|
|
9
|
+
* - appends never rewrite the file, so two processes can add lines at the
|
|
10
|
+
* same time without a lock;
|
|
11
|
+
* - a reader tolerates a malformed or half-written line instead of failing
|
|
12
|
+
* the whole stream;
|
|
13
|
+
* - the line boundary is repaired on append — an interrupted write must not
|
|
14
|
+
* glue two JSON objects into one unparseable line, which would silently
|
|
15
|
+
* drop both records.
|
|
16
|
+
*
|
|
17
|
+
* Only the mechanics live here. Each feature owns its event vocabulary and its
|
|
18
|
+
* validator.
|
|
19
|
+
*/
|
|
20
|
+
import {
|
|
21
|
+
appendFileSync,
|
|
22
|
+
closeSync,
|
|
23
|
+
existsSync,
|
|
24
|
+
mkdirSync,
|
|
25
|
+
openSync,
|
|
26
|
+
readFileSync,
|
|
27
|
+
readSync,
|
|
28
|
+
statSync,
|
|
29
|
+
} from "node:fs";
|
|
30
|
+
import { dirname } from "node:path";
|
|
31
|
+
|
|
32
|
+
/** Fields every ledger event carries. */
|
|
33
|
+
export interface LedgerEventBase {
|
|
34
|
+
readonly v: number;
|
|
35
|
+
readonly id: string;
|
|
36
|
+
readonly ts: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Monotonic-enough id: time plus 6 random base36 chars. */
|
|
40
|
+
export function newLedgerEventId(now: Date = new Date()): string {
|
|
41
|
+
const random = Math.random().toString(36).slice(2, 8).padEnd(6, "0");
|
|
42
|
+
return `e-${now.getTime().toString(36)}-${random}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Append one event. The file always ends with a newline: if a previous write
|
|
47
|
+
* was interrupted mid-line, this repairs the boundary instead of gluing two
|
|
48
|
+
* JSON objects together.
|
|
49
|
+
*/
|
|
50
|
+
export function appendLedgerLine(file: string, event: unknown): void {
|
|
51
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
52
|
+
const line = JSON.stringify(event);
|
|
53
|
+
if (existsSync(file) && statSync(file).size > 0 && !endsWithNewline(file)) {
|
|
54
|
+
appendFileSync(file, `\n${line}\n`, "utf8");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
appendFileSync(file, `${line}\n`, "utf8");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function endsWithNewline(file: string): boolean {
|
|
61
|
+
const fd = openSync(file, "r");
|
|
62
|
+
try {
|
|
63
|
+
const size = statSync(file).size;
|
|
64
|
+
const buffer = Buffer.alloc(1);
|
|
65
|
+
readSync(fd, buffer, 0, 1, size - 1);
|
|
66
|
+
return buffer[0] === 0x0a;
|
|
67
|
+
} finally {
|
|
68
|
+
closeSync(fd);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Parse the stream, skipping malformed lines and duplicate ids. */
|
|
73
|
+
export function parseLedgerLines<T extends LedgerEventBase>(
|
|
74
|
+
raw: string,
|
|
75
|
+
isEvent: (value: unknown) => value is T,
|
|
76
|
+
): { events: T[]; skipped: number } {
|
|
77
|
+
const events: T[] = [];
|
|
78
|
+
const seen = new Set<string>();
|
|
79
|
+
let skipped = 0;
|
|
80
|
+
for (const line of raw.split("\n")) {
|
|
81
|
+
const trimmed = line.trim();
|
|
82
|
+
if (trimmed === "") continue;
|
|
83
|
+
let parsed: unknown;
|
|
84
|
+
try {
|
|
85
|
+
parsed = JSON.parse(trimmed);
|
|
86
|
+
} catch {
|
|
87
|
+
skipped += 1;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (!isEvent(parsed)) {
|
|
91
|
+
skipped += 1;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (seen.has(parsed.id)) continue;
|
|
95
|
+
seen.add(parsed.id);
|
|
96
|
+
events.push(parsed);
|
|
97
|
+
}
|
|
98
|
+
return { events, skipped };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Read and parse a ledger file. A missing or unreadable file is empty. */
|
|
102
|
+
export function readLedgerLines<T extends LedgerEventBase>(
|
|
103
|
+
file: string,
|
|
104
|
+
isEvent: (value: unknown) => value is T,
|
|
105
|
+
): { events: T[]; skipped: number } {
|
|
106
|
+
if (!existsSync(file)) return { events: [], skipped: 0 };
|
|
107
|
+
try {
|
|
108
|
+
return parseLedgerLines(readFileSync(file, "utf8"), isEvent);
|
|
109
|
+
} catch {
|
|
110
|
+
return { events: [], skipped: 1 };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
:root{--paper:#fdf9f5;--paper-deep:#f4e7e2;--surface:#fffdfb;--surface-muted:#f6e9e2;--border:#ead8d1;--ink:#2b1a24;--muted:#8a7280;--brand:#e0446b;--brand-2:#f2704f;--accent:#7c5cfc;--success:#0f8a6a;--warning:#c97a15;--danger:#d23b4e;--tint-success:#e7f4ef;--tint-warning:#fbf0dc;--tint-accent:#ede8ff;--tint-danger:#fbe9ea;--tint-blush:#fdf0ec;--tint-paper:#f8ede8;--shadow:0 10px 32px #471b2712;--shadow-soft:0 18px 50px #471b2724;--serif:"P052", "Palatino Linotype", Palatino, "Iowan Old Style", Georgia, "Noto Serif", "Songti SC", serif;--sans:"Ubuntu Sans", "Noto Sans", "Droid Sans Fallback", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;--mono:"Noto Sans Mono", ui-monospace, SFMono-Regular, Menlo, monospace;--lightningcss-light:initial;--lightningcss-dark: ;color-scheme:light}*{box-sizing:border-box}body{min-height:100vh;color:var(--ink);font:15px/1.65 var(--sans);background:radial-gradient(680px 680px at 108% -6%, #f8b7ad8c, transparent 68%), radial-gradient(620px 620px at -10% 38%, #cbb9ff59, transparent 70%), radial-gradient(460px 460px at 106% 82%, #ffc7a857, transparent 70%), linear-gradient(180deg, var(--paper), var(--paper-deep));background-attachment:fixed;margin:0}.page{max-width:1440px;margin:0 auto;padding:0 140px 150px}.topbar{border-bottom:1px solid #c8a69c8c;padding:26px 0 18px}.masthead{justify-content:space-between;align-items:center;gap:16px;display:flex}.brand{align-items:center;gap:12px;display:flex}.brand-mark{width:32px;height:32px;color:var(--surface);background:linear-gradient(135deg, var(--brand), var(--brand-2));border-radius:10px;place-items:center;display:grid;box-shadow:0 6px 16px #e0446b59}.brand-mark svg{width:17px;height:17px}.eyebrow{letter-spacing:2.2px;text-transform:uppercase;color:var(--muted);font-size:10px;font-weight:700;line-height:1.2;display:inline-block}.top-actions{align-items:center;gap:10px;display:flex}.title-block{margin-top:18px}h1{font-family:var(--serif);letter-spacing:-.8px;color:var(--ink);overflow-wrap:anywhere;margin:0;font-size:clamp(38px,4.2vw,52px);font-weight:400;line-height:1.05}.meta{color:var(--muted);flex-wrap:wrap;align-items:center;gap:10px;margin-top:12px;font-size:12.5px;display:flex}.meta-path{text-overflow:ellipsis;white-space:nowrap;max-width:360px;font-family:var(--mono);font-size:12px;overflow:hidden}.meta-dot{background:#d9c6c0;border-radius:50%;flex:none;width:4px;height:4px}.meta-changed{color:var(--brand);font-weight:600}.readonly{border:1px solid var(--warning);color:var(--warning);border-radius:999px;padding:1px 8px;font-size:11px;line-height:1.5}.history{flex-wrap:wrap;align-items:center;gap:8px;margin-top:22px;display:flex}.history-label{margin-right:4px}.history-summary{color:var(--muted);margin-left:auto;font-size:11.5px}button{font:inherit;cursor:pointer}button:disabled{opacity:.45;cursor:not-allowed}.ghost{border:1px solid var(--border);height:34px;color:var(--ink);background:#fffdfbb8;border-radius:999px;justify-content:center;align-items:center;padding:0 14px;font-size:12.5px;transition:border-color .15s,background .15s;display:inline-flex}.ghost:hover:not(:disabled){background:var(--surface);border-color:#ddbfb5}.ghost:focus-visible,.chip:focus-visible,.add:focus-visible,.rail-note:focus-visible,.btn-feedback:focus-visible,.btn-approve:focus-visible,.primary:focus-visible,.link:focus-visible,.remove:focus-visible{outline:2px solid var(--brand);outline-offset:2px}.lang{min-width:52px}.link{color:var(--brand);font-size:inherit;background:0 0;border:none;padding:0;font-weight:600;text-decoration:underline}.chip{border:1px solid var(--border);height:30px;color:var(--muted);font-family:var(--mono);background:#fffdfb99;border-radius:999px;align-items:center;gap:6px;padding:0 12px;font-size:12px;transition:border-color .15s,background .15s,color .15s;display:inline-flex}.chip:hover{color:var(--ink);border-color:#ddbfb5}.chip.active{background:linear-gradient(100deg, var(--brand), var(--brand-2));color:var(--surface);border-color:#0000;box-shadow:0 6px 14px #e0446b52}.chip-changed{color:var(--warning);font-size:11px}.chip.active .chip-changed{color:#fffdfbd1}.layout{grid-template-columns:minmax(0,748px) 364px;align-items:start;gap:48px;padding-top:28px;display:grid}.reading{flex-direction:column;gap:14px;display:flex}.rail{flex-direction:column;gap:18px;display:flex}.error{color:#8e2433;background:#fbe9ead9;border:1px solid #d23b4e66;border-radius:14px;margin-bottom:14px;padding:12px 16px;font-size:13px}.banner{color:#7a4a0e;background:#fbf0dccc;border:1px solid #c97a1559;border-radius:14px;justify-content:space-between;align-items:center;gap:12px;padding:10px 14px;font-size:12.5px;display:flex}.done{border:1px solid var(--border);background:var(--surface);box-shadow:var(--shadow);border-radius:16px;padding:18px}.done-title{font-family:var(--serif);font-size:20px;line-height:1.3}.done-hint{color:var(--muted);margin-top:4px;font-size:13px}.empty{border:1px dashed var(--border);color:var(--muted);text-align:center;background:#fffdfb99;border-radius:16px;margin:0;padding:22px}.collapsed{border:1px solid var(--border);height:44px;color:var(--muted);background:#fff9f5b3;border-radius:12px;justify-content:center;align-items:center;gap:8px;font-size:12px;display:flex}.global-card{border:1px solid var(--border);background:var(--surface);box-shadow:var(--shadow);border-radius:16px;flex-direction:column;gap:12px;padding:18px 22px;scroll-margin-top:24px;display:flex}.global-head{align-items:center;gap:10px;display:flex}.global-head .add{margin-left:auto}.global-count{background:var(--tint-blush);color:#b72847;border-radius:999px;justify-content:center;align-items:center;min-width:22px;height:20px;padding:0 8px;font-size:11px;font-weight:700;display:inline-flex}.blocks{flex-direction:column;gap:14px;display:flex}.block{border:1px solid var(--border);background:var(--surface);box-shadow:var(--shadow);border-radius:16px;scroll-margin-top:24px;overflow:hidden}.block-bar{width:100%;height:3px}.bar-added{background:linear-gradient(90deg, var(--success), #0f8a6a00)}.bar-modified{background:linear-gradient(90deg, var(--warning), #c97a1500)}.bar-moved{background:linear-gradient(90deg, var(--accent), #7c5cfc00)}.bar-removed{background:linear-gradient(90deg, var(--danger), #d23b4e00)}.bar-unchanged{background:linear-gradient(90deg,#ead8d1e6,#ead8d100)}.block-inner{flex-direction:column;gap:12px;padding:18px 22px 20px;display:flex}.block.is-removed .block-body{opacity:.68}.block-head{align-items:center;gap:10px;min-height:24px;display:flex}.badge{letter-spacing:1.1px;text-transform:uppercase;white-space:nowrap;border-radius:999px;align-items:center;gap:6px;height:22px;padding:0 9px;font-size:10px;font-weight:700;line-height:1;display:inline-flex}.badge .dot{width:5px;height:5px}.badge-added{background:var(--tint-success);color:var(--success)}.badge-modified{background:var(--tint-warning);color:var(--warning)}.badge-moved{background:var(--tint-accent);color:var(--accent)}.badge-removed{background:var(--tint-danger);color:var(--danger)}.badge-unchanged{background:var(--surface-muted);color:var(--muted)}.dot{border-radius:50%;flex:none;width:6px;height:6px;display:inline-block}.badge .dot-added,.dot-added{background:var(--success)}.badge .dot-modified,.dot-modified{background:var(--warning)}.badge .dot-moved,.dot-moved{background:var(--accent)}.badge .dot-removed,.dot-removed{background:var(--danger)}.badge-unchanged .dot{background:var(--muted)}.rail-row .dot-removed{background:#d9c6c0}.dot-change,.dot-brand{background:var(--brand)}.dot-suggest{background:var(--accent)}.dot-question{background:var(--muted)}.block-id{font-family:var(--mono);color:var(--muted);font-size:10.5px;line-height:1}.add{color:var(--muted);background:0 0;border:none;border-radius:8px;margin-left:auto;padding:4px 6px;font-size:11.5px;transition:color .15s,background .15s}.add:hover{background:var(--tint-blush);color:var(--brand)}.block-body{color:var(--ink);overflow-wrap:anywhere;font-size:15px;line-height:1.65}.block-body>:first-child{margin-top:0}.block-body>:last-child{margin-bottom:0}.block-body p{margin:0 0 12px}.block-body h1,.block-body h2,.block-body h3,.block-body h4{font-family:var(--serif);letter-spacing:-.2px;color:var(--ink);margin:8px 0 10px;font-weight:400;line-height:1.25}.block-body h1{font-size:26px}.block-body h2{font-size:23px}.block-body h3{font-size:19px}.block-body h4{font-size:16px}.block-body ul,.block-body ol{margin:0 0 12px;padding-left:22px}.block-body li{margin:4px 0}.block-body code{color:#a9304a;font-family:var(--mono);background:#f1e4de;border-radius:5px;padding:1px 5px;font-size:.9em}.block-body pre{color:#ffe9e2;font-family:var(--mono);background:#2a1a22;border-radius:12px;margin:0 0 12px;padding:14px 16px;font-size:12.5px;line-height:1.6;overflow:auto}.block-body pre code{color:inherit;font-size:inherit;background:0 0;padding:0}.block-body a{color:var(--brand);text-underline-offset:2px;text-decoration:underline}.block-body blockquote{border-left:3px solid var(--border);color:var(--muted);margin:0 0 12px;padding-left:12px}.block-body table{border-collapse:collapse;width:100%;margin:0 0 12px;font-size:13.5px}.block-body th,.block-body td{border:1px solid var(--border);text-align:left;padding:6px 8px}.block-body th{background:var(--surface-muted);font-weight:600}.block-body hr{border:none;border-top:1px solid var(--border);margin:16px 0}.note{background:var(--tint-blush);border:1px solid #f3d3c8;border-radius:12px;align-items:flex-start;gap:10px;padding:11px 12px;font-size:13px;line-height:1.5;display:flex}.note-suggest{background:#f4f0ff;border-color:#dcd2f5}.note-question{border-color:var(--border);background:#f7f1ed}.note-verdict{letter-spacing:1px;text-transform:uppercase;white-space:nowrap;border-radius:999px;flex:none;padding:4px 8px;font-size:9.5px;font-weight:700;line-height:1}.verdict-change{color:#b72847;background:#f8dde2}.verdict-suggest{color:#5b3fc9;background:#ede8ff}.verdict-question{color:#7a5a4c;background:#efe4de}.note-text{white-space:pre-wrap;overflow-wrap:anywhere;flex:1;min-width:0}.remove{color:var(--muted);background:0 0;border:none;padding:0 0 0 4px;font-size:11.5px}.remove:hover{color:var(--danger)}.editor{background:#fffbf8;border:1px solid #ebcbc1;border-radius:14px;flex-direction:column;gap:10px;padding:14px;display:flex}.verdicts{flex-wrap:wrap;align-items:center;gap:8px;display:flex}.verdicts label{border:1px solid var(--border);height:28px;color:var(--muted);cursor:pointer;border-radius:999px;align-items:center;padding:0 12px;font-size:11.5px;transition:border-color .15s,background .15s,color .15s;display:inline-flex;position:relative}.verdicts label input{opacity:0;pointer-events:none;position:absolute}.verdicts label.active{background:var(--brand);color:var(--surface);border-color:#0000;font-weight:600}.editor textarea{resize:vertical;border:1px solid var(--border);background:var(--surface);width:100%;min-height:62px;color:var(--ink);font:inherit;border-radius:10px;outline:none;padding:10px 12px;font-size:13px;line-height:1.5}.editor textarea:focus{border-color:var(--brand);box-shadow:0 0 0 3px #e0446b1f}.editor-actions{justify-content:flex-end;align-items:center;gap:10px;display:flex}.primary{background:linear-gradient(100deg, var(--brand), var(--brand-2));height:32px;color:var(--surface);border:none;border-radius:999px;padding:0 16px;font-size:12px;font-weight:600}.rail-card{border:1px solid var(--border);background:var(--surface);box-shadow:var(--shadow);border-radius:16px;flex-direction:column;gap:12px;padding:20px;display:flex}.rail-big{align-items:flex-end;gap:10px;display:flex}.rail-number{font-family:var(--serif);color:var(--brand);font-size:50px;line-height:1}.rail-caption{color:var(--ink);flex-direction:column;gap:2px;padding-bottom:6px;font-size:12.5px;display:flex}.rail-caption .muted{color:var(--muted);font-size:11px}.rail-breakdown{flex-direction:column;gap:2px;display:flex}.rail-row{height:22px;color:var(--muted);align-items:center;gap:8px;font-size:12.5px;display:flex}.rail-row>span:nth-child(2){text-transform:capitalize}.rail-row b{color:var(--ink);margin-left:auto;font-weight:600}.rail-head{justify-content:space-between;align-items:center;gap:10px;display:flex}.rail-badge{background:var(--tint-blush);color:#b72847;border-radius:999px;justify-content:center;align-items:center;min-width:22px;height:20px;padding:0 8px;font-size:11px;font-weight:700;display:inline-flex}.rail-notes{flex-direction:column;gap:4px;display:flex}.rail-note{text-align:left;background:0 0;border:none;border-radius:10px;align-items:flex-start;gap:8px;width:100%;padding:8px;display:flex}.rail-note:hover{background:#fbf3ee}.rail-note .dot{margin-top:5px}.rail-note-body{flex-direction:column;gap:2px;min-width:0;display:flex}.rail-note-label{color:var(--muted);letter-spacing:.8px;text-transform:uppercase;white-space:nowrap;text-overflow:ellipsis;font-size:10px;overflow:hidden}.rail-note-text{color:var(--ink);-webkit-line-clamp:2;-webkit-box-orient:vertical;font-size:12.5px;line-height:1.45;display:-webkit-box;overflow:hidden}.rail-empty{color:var(--muted);margin:0;font-size:12.5px;line-height:1.5}.footer{z-index:30;width:min(1232px,100vw - 48px);min-height:76px;box-shadow:var(--shadow-soft);-webkit-backdrop-filter:blur(18px);backdrop-filter:blur(18px);background:#fffdfbf0;border:1px solid #ebd8d1;border-radius:24px;grid-template-columns:1fr auto 1fr;align-items:center;gap:16px;padding:14px 24px;display:grid;position:fixed;bottom:18px;left:50%;transform:translate(-50%)}.footer-left,.footer-actions{align-items:center;gap:10px;display:flex}.footer-actions{justify-self:end}.footer-center{justify-self:center}.notes-count{background:var(--tint-paper);height:30px;color:var(--muted);white-space:nowrap;border-radius:999px;align-items:center;gap:8px;padding:0 12px;font-size:12px;font-weight:600;display:inline-flex}.notes-count .dot{width:7px;height:7px}.btn-feedback{background:var(--surface);color:#a9304a;border:1px solid #e7c9c1;border-radius:999px;height:44px;padding:0 20px;font-size:13px;font-weight:600;transition:background .15s,border-color .15s}.btn-feedback:hover:not(:disabled){background:#fff7f4;border-color:#d9a99c}.btn-approve{background:linear-gradient(100deg, var(--brand), var(--brand-2));height:44px;color:var(--surface);border:none;border-radius:999px;justify-content:center;align-items:center;gap:8px;padding:0 22px;font-size:13px;font-weight:600;transition:filter .15s,box-shadow .15s;display:inline-flex;box-shadow:0 8px 20px #e0446b61}.btn-approve:hover:not(:disabled){filter:brightness(1.03)}.btn-approve svg{width:15px;height:15px}@media (max-width:1200px){.page{padding:0 64px 150px}.layout{grid-template-columns:minmax(0,1fr) 332px;gap:32px}}@media (max-width:1040px){.page{padding:0 40px 150px}.layout{grid-template-columns:minmax(0,1fr)}}@media (max-width:800px){.history-summary{display:none}.footer{border-radius:20px;grid-template-columns:1fr;gap:8px;padding:12px}.footer-left{flex-wrap:wrap;order:1}.footer-center{order:2;justify-self:start}.footer-actions{order:3;justify-self:stretch}.footer-actions .btn-feedback,.footer-actions .btn-approve{flex:1}}@media (max-width:720px){.page{padding:0 20px 220px}.topbar{padding-top:20px}.block-inner{padding:14px 16px 16px}.global-card{padding:14px 16px}.meta-path{max-width:100%}.footer{width:calc(100vw - 24px);bottom:10px}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return t(this.context.count)},getNextContextId(){return t(this.context.count++)}};function t(t){let n=String(t),r=n.length-1;return e.context.id+(r?String.fromCharCode(96+r):``)+n}function n(t){e.context=t}var r=(e,t)=>e===t,i=Symbol(`solid-track`),a={equals:r},o=null,s=P,c=1,l=2,u={owned:null,cleanups:null,context:null,owner:null},d=null,f=null,p=null,m=null,h=null,g=0;function _(e,t){let n=p,r=d,i=e.length===0,a=t===void 0?r:t,o=i?u:{owned:null,cleanups:null,context:a?a.context:null,owner:a},s=i?e:()=>e(v(o));d=o,p=null;try{return M(s,!0)}finally{p=n,d=r}}function v(e){return()=>S(()=>L(e))}function y(e,t){t=t?Object.assign({},a,t):a;let n={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0};return[D.bind(n),e=>(typeof e==`function`&&(e=f&&f.running&&f.sources.has(n)?e(n.tValue):e(n.value)),O(n,e))]}function b(e,t,n){k(A(e,t,!1,c))}function ee(e,t,n){s=ie;let r=A(e,t,!1,c),i=E&&T(E);i&&(r.suspense=i),(!n||!n.render)&&(r.user=!0),h?h.push(r):k(r)}function x(e,t,n){n=n?Object.assign({},a,n):a;let r=A(e,t,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,k(r),D.bind(r)}function S(e){if(p===null)return e();let t=p;p=null;try{return e()}finally{p=t}}function te(e){ee(()=>S(e))}function ne(e){return d===null||(d.cleanups===null?d.cleanups=[e]:d.cleanups.push(e)),e}var[C,w]=y(!1);function T(e){let t;return d&&d.context&&(t=d.context[e.id])!==void 0?t:e.defaultValue}var E;function D(){let e=f&&f.running;if(this.sources&&(e?this.tState:this.state)){if((e?this.tState:this.state)===c)k(this);else{let e=m;m=null,M(()=>F(this),!1),m=e}}if(p){let e=this.observers;if(!e||e[e.length-1]!==p){let t=e?e.length:0;p.sources?(p.sources.push(this),p.sourceSlots.push(t)):(p.sources=[this],p.sourceSlots=[t]),e?(e.push(p),this.observerSlots.push(p.sources.length-1)):(this.observers=[p],this.observerSlots=[p.sources.length-1])}}return e&&f.sources.has(this)?this.tValue:this.value}function O(e,t,n){let r=f&&f.running&&f.sources.has(e)?e.tValue:e.value;if(!e.comparator||!e.comparator(r,t)){if(f){let r=f.running;(r||!n&&f.sources.has(e))&&(f.sources.add(e),e.tValue=t),r||(e.value=t)}else e.value=t;e.observers&&e.observers.length&&M(()=>{for(let t=0;t<e.observers.length;t+=1){let n=e.observers[t],r=f&&f.running;r&&f.disposed.has(n)||((r?!n.tState:!n.state)&&(n.pure?m.push(n):h.push(n),n.observers&&I(n)),r?n.tState=c:n.state=c)}if(m.length>1e6)throw m=[],Error()},!1)}return t}function k(e){if(!e.fn)return;L(e);let t=g;re(e,f&&f.running&&f.sources.has(e)?e.tValue:e.value,t),f&&!f.running&&f.sources.has(e)&&queueMicrotask(()=>{M(()=>{f&&(f.running=!0),p=d=e,re(e,e.tValue,t),p=d=null},!1)})}function re(e,t,n){let r,i=d,a=p;p=d=e;try{r=e.fn(t)}catch(t){return e.pure&&(f&&f.running?(e.tState=c,e.tOwned&&e.tOwned.forEach(L),e.tOwned=void 0):(e.state=c,e.owned&&e.owned.forEach(L),e.owned=null)),e.updatedAt=n+1,z(t)}finally{p=a,d=i}(!e.updatedAt||e.updatedAt<=n)&&(e.updatedAt!=null&&`observers`in e?O(e,r,!0):f&&f.running&&e.pure?(f.sources.has(e)||(e.value=r),f.sources.add(e),e.tValue=r):e.value=r,e.updatedAt=n)}function A(e,t,n,r=c,i){let a={fn:e,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:d,context:d?d.context:null,pure:n};return f&&f.running&&(a.state=0,a.tState=r),d===null||d!==u&&(f&&f.running&&d.pure?d.tOwned?d.tOwned.push(a):d.tOwned=[a]:d.owned?d.owned.push(a):d.owned=[a]),a}function j(e){let t=f&&f.running;if((t?e.tState:e.state)===0)return;if((t?e.tState:e.state)===l)return F(e);if(e.suspense&&S(e.suspense.inFallback))return e.suspense.effects.push(e);let n=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<g);){if(t&&f.disposed.has(e))return;(t?e.tState:e.state)&&n.push(e)}for(let r=n.length-1;r>=0;r--){if(e=n[r],t){let t=e,i=n[r+1];for(;(t=t.owner)&&t!==i;)if(f.disposed.has(t))return}if((t?e.tState:e.state)===c)k(e);else if((t?e.tState:e.state)===l){let t=m;m=null,M(()=>F(e,n[0]),!1),m=t}}}function M(e,t){if(m)return e();let n=!1;t||(m=[]),h?n=!0:h=[],g++;try{let t=e();return N(n),t}catch(e){n||(h=null),m=null,z(e)}}function N(e){if(m&&=(P(m),null),e)return;let t;if(f){if(!f.promises.size&&!f.queue.size){let e=f.sources,n=f.disposed;h.push.apply(h,f.effects),t=f.resolve;for(let e of h)`tState`in e&&(e.state=e.tState),delete e.tState;f=null,M(()=>{for(let e of n)L(e);for(let t of e){if(t.value=t.tValue,t.owned)for(let e=0,n=t.owned.length;e<n;e++)L(t.owned[e]);t.tOwned&&(t.owned=t.tOwned),delete t.tValue,delete t.tOwned,t.tState=0}w(!1)},!1)}else if(f.running){f.running=!1,f.effects.push.apply(f.effects,h),h=null,w(!0);return}}let n=h;h=null,n.length&&M(()=>s(n),!1),t&&t()}function P(e){for(let t=0;t<e.length;t++)j(e[t])}function ie(t){let r,i=0;for(r=0;r<t.length;r++){let e=t[r];e.user?t[i++]=e:j(e)}if(e.context){if(e.count){e.effects||=[],e.effects.push(...t.slice(0,i));return}n()}for(e.effects&&(e.done||!e.count)&&(t=[...e.effects,...t],i+=e.effects.length,delete e.effects),r=0;r<i;r++)j(t[r])}function F(e,t){let n=f&&f.running;n?e.tState=0:e.state=0;for(let r=0;r<e.sources.length;r+=1){let i=e.sources[r];if(i.sources){let e=n?i.tState:i.state;e===c?i!==t&&(!i.updatedAt||i.updatedAt<g)&&j(i):e===l&&F(i,t)}}}function I(e){let t=f&&f.running;for(let n=0;n<e.observers.length;n+=1){let r=e.observers[n];(t?!r.tState:!r.state)&&(t?r.tState=l:r.state=l,r.pure?m.push(r):h.push(r),r.observers&&I(r))}}function L(e){let t;if(e.sources)for(;e.sources.length;){let t=e.sources.pop(),n=e.sourceSlots.pop(),r=t.observers;if(r&&r.length){let e=r.pop(),i=t.observerSlots.pop();n<r.length&&(e.sourceSlots[i]=n,r[n]=e,t.observerSlots[n]=i)}}if(e.tOwned){for(t=e.tOwned.length-1;t>=0;t--)L(e.tOwned[t]);delete e.tOwned}if(f&&f.running&&e.pure)R(e,!0);else if(e.owned){for(t=e.owned.length-1;t>=0;t--)L(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}f&&f.running?e.tState=0:e.state=0}function R(e,t){if(t||(e.tState=0,f.disposed.add(e)),e.owned)for(let t=0;t<e.owned.length;t++)R(e.owned[t])}function ae(e){return e instanceof Error?e:Error(typeof e==`string`?e:`Unknown error`,{cause:e})}function oe(e,t,n){try{for(let n of t)n(e)}catch(e){z(e,n&&n.owner||null)}}function z(e,t=d){let n=o&&t&&t.context&&t.context[o],r=ae(e);if(!n)throw r;h?h.push({fn(){oe(r,n,t)},state:c}):oe(r,n,t)}var se=Symbol(`fallback`);function ce(e){for(let t=0;t<e.length;t++)e[t]()}function le(e,t,n={}){let r=[],a=[],o=[],s=0,c=t.length>1?[]:null;return ne(()=>ce(o)),()=>{let l=e()||[],u=l.length,d,f;return l[i],S(()=>{let e,t,i,m,h,g,v,y,b;if(u===0)s!==0&&(ce(o),o=[],r=[],a=[],s=0,c&&=[]),n.fallback&&(r=[se],a[0]=_(e=>(o[0]=e,n.fallback())),s=1);else if(s===0){for(a=Array(u),f=0;f<u;f++)r[f]=l[f],a[f]=_(p);s=u}else{for(i=Array(u),m=Array(u),c&&(h=Array(u)),g=0,v=Math.min(s,u);g<v&&r[g]===l[g];g++);for(v=s-1,y=u-1;v>=g&&y>=g&&r[v]===l[y];v--,y--)i[y]=a[v],m[y]=o[v],c&&(h[y]=c[v]);for(e=new Map,t=Array(y+1),f=y;f>=g;f--)b=l[f],d=e.get(b),t[f]=d===void 0?-1:d,e.set(b,f);for(d=g;d<=v;d++)b=r[d],f=e.get(b),f!==void 0&&f!==-1?(i[f]=a[d],m[f]=o[d],c&&(h[f]=c[d]),f=t[f],e.set(b,f)):o[d]();for(f=g;f<u;f++)f in i?(a[f]=i[f],o[f]=m[f],c&&(c[f]=h[f],c[f](f))):a[f]=_(p);a=a.slice(0,s=u),r=l.slice(0)}return a});function p(e){if(o[f]=e,c){let[e,n]=y(f);return c[f]=n,t(l[f],e)}return t(l[f])}}}function B(e,t){return S(()=>e(t||{}))}var ue=e=>`Stale read from <${e}>.`;function V(e){let t=`fallback`in e&&{fallback:()=>e.fallback};return x(le(()=>e.each,e.children,t||void 0))}function H(e){let t=e.keyed,n=x(()=>e.when,void 0,void 0),r=t?n:x(n,void 0,{equals:(e,t)=>!e==!t});return x(()=>{let i=r();if(i){let a=e.children;return typeof a==`function`&&a.length>0?S(()=>a(t?i:()=>{if(!S(r))throw ue(`Show`);return n()})):a}return e.fallback},void 0,void 0)}var U=e=>x(()=>e());function de(e,t,n){let r=n.length,i=t.length,a=r,o=0,s=0,c=t[i-1].nextSibling,l=null;for(;o<i||s<a;){if(t[o]===n[s]){o++,s++;continue}for(;t[i-1]===n[a-1];)i--,a--;if(i===o){let t=a<r?s?n[s-1].nextSibling:n[a-s]:c;for(;s<a;)e.insertBefore(n[s++],t)}else if(a===s)for(;o<i;)(!l||!l.has(t[o]))&&t[o].remove(),o++;else if(t[o]===n[a-1]&&n[s]===t[i-1]){let r=t[--i].nextSibling;e.insertBefore(n[s++],t[o++].nextSibling),e.insertBefore(n[--a],r),t[i]=n[a]}else{if(!l){l=new Map;let e=s;for(;e<a;)l.set(n[e],e++)}let r=l.get(t[o]);if(r!=null){if(s<r&&r<a){let c=o,u=1,d;for(;++c<i&&c<a&&(d=l.get(t[c]))!=null&&d===r+u;)u++;if(u>r-s){let i=t[o];for(;s<r;)e.insertBefore(n[s++],i)}else e.replaceChild(n[s++],t[o++])}else o++}else t[o++].remove()}}}var fe=`_$DX_DELEGATE`;function pe(e,t,n,r={}){let i;return _(r=>{i=r,t===document?e():q(t,e(),!n&&t.firstChild?null:void 0,n)},r.owner),()=>{i(),t.textContent=``}}function W(e,t,n,r){let i,a=()=>{let t=r?document.createElementNS(`http://www.w3.org/1998/Math/MathML`,`template`):document.createElement(`template`);return t.innerHTML=e,n?t.content.firstChild.firstChild:r?t.firstChild:t.content.firstChild},o=t?()=>S(()=>document.importNode(i||=a(),!0)):()=>(i||=a()).cloneNode(!0);return o.cloneNode=o,o}function me(e,t=window.document){let n=t[fe]||(t[fe]=new Set);for(let r=0,i=e.length;r<i;r++){let i=e[r];n.has(i)||(n.add(i),t.addEventListener(i,_e))}}function he(e,t,n){J(e)||(n==null?e.removeAttribute(t):e.setAttribute(t,n))}function G(e,t){J(e)||(t==null?e.removeAttribute(`class`):e.className=t)}function K(e,t,n,r){if(r)Array.isArray(n)?(e[`$$${t}`]=n[0],e[`$$${t}Data`]=n[1]):e[`$$${t}`]=n;else if(Array.isArray(n)){let r=n[0];e.addEventListener(t,n[0]=t=>r.call(e,n[1],t))}else e.addEventListener(t,n,typeof n!=`function`&&n)}function ge(e,t,n={}){let r=Object.keys(t||{}),i=Object.keys(n),a,o;for(a=0,o=i.length;a<o;a++){let r=i[a];!r||r===`undefined`||t[r]||(Y(e,r,!1),delete n[r])}for(a=0,o=r.length;a<o;a++){let i=r[a],o=!!t[i];!i||i===`undefined`||n[i]===o||!o||(Y(e,i,!0),n[i]=o)}return n}function q(e,t,n,r){if(n!==void 0&&!r&&(r=[]),typeof t!=`function`)return X(e,t,r,n);b(r=>X(e,t(),r,n),r)}function J(t){return!!e.context&&!e.done&&(!t||t.isConnected)}function Y(e,t,n){let r=t.trim().split(/\s+/);for(let t=0,i=r.length;t<i;t++)e.classList.toggle(r[t],n)}function _e(t){if(e.registry&&e.events&&e.events.find(([e,n])=>n===t))return;let n=t.target,r=`$$${t.type}`,i=t.target,a=t.currentTarget,o=e=>Object.defineProperty(t,"target",{configurable:!0,value:e}),s=()=>{let e=n[r];if(e&&!n.disabled){let i=n[`${r}Data`];if(i===void 0?e.call(n,t):e.call(n,i,t),t.cancelBubble)return}return n.host&&typeof n.host!=`string`&&!n.host._$host&&n.contains(t.target)&&o(n.host),!0},c=()=>{for(;s()&&(n=n._$host||n.parentNode||n.host););};Object.defineProperty(t,"currentTarget",{configurable:!0,get(){return n||document}}),e.registry&&!e.done&&(e.done=_$HY.done=!0);try{if(t.composedPath){let e=t.composedPath();o(e[0]);for(let t=0;t<e.length-2&&(n=e[t],s());t++){if(n._$host){n=n._$host,c();break}if(n.parentNode===a)break}}else c();o(i)}finally{t=n=null}}function X(e,t,n,r,i){let a=J(e);if(a){!n&&(n=[...e.childNodes]);let t=[];for(let e=0;e<n.length;e++){let r=n[e];r.nodeType===8&&r.data.slice(0,2)===`!$`?r.remove():t.push(r)}n=t}for(;typeof n==`function`;)n=n();if(t===n)return n;let o=typeof t,s=r!==void 0;if(e=s&&n[0]&&n[0].parentNode||e,o===`string`||o===`number`){if(a||o===`number`&&(t=t.toString(),t===n))return n;if(s){let i=n[0];i&&i.nodeType===3?i.data!==t&&(i.data=t):i=document.createTextNode(t),n=Q(e,n,r,i)}else n=n!==``&&typeof n==`string`?e.firstChild.data=t:e.textContent=t}else if(t==null||o===`boolean`){if(a)return n;n=Q(e,n,r)}else if(o===`function`)return b(()=>{let i=t();for(;typeof i==`function`;)i=i();n=X(e,i,n,r)}),()=>n;else if(Array.isArray(t)){let o=[],c=n&&Array.isArray(n);if(Z(o,t,n,i))return b(()=>n=X(e,o,n,r,!0)),()=>n;if(a){if(!o.length)return n;if(r===void 0)return n=[...e.childNodes];let t=o[0];if(t.parentNode!==e)return n;let i=[t];for(;(t=t.nextSibling)!==r;)i.push(t);return n=i}if(o.length===0){if(n=Q(e,n,r),s)return n}else c?n.length===0?ve(e,o,r):de(e,n,o):(n&&Q(e),ve(e,o));n=o}else if(t.nodeType){if(a&&t.parentNode)return n=s?[t]:t;if(Array.isArray(n)){if(s)return n=Q(e,n,r,t);Q(e,n,null,t)}else n==null||n===``||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t}return n}function Z(e,t,n,r){let i=!1;for(let a=0,o=t.length;a<o;a++){let o=t[a],s=n&&n[e.length],c;if(o!=null&&o!==!0&&o!==!1){if((c=typeof o)==`object`&&o.nodeType)e.push(o);else if(Array.isArray(o))i=Z(e,o,s)||i;else if(c===`function`){if(r){for(;typeof o==`function`;)o=o();i=Z(e,Array.isArray(o)?o:[o],Array.isArray(s)?s:[s])||i}else e.push(o),i=!0}else{let t=String(o);s&&s.nodeType===3&&s.data===t?e.push(s):e.push(document.createTextNode(t))}}}return i}function ve(e,t,n=null){for(let r=0,i=t.length;r<i;r++)e.insertBefore(t[r],n)}function Q(e,t,n,r){if(n===void 0)return e.textContent=``;let i=r||document.createTextNode(``);if(t.length){let r=!1;for(let a=t.length-1;a>=0;a--){let o=t[a];if(i!==o){let t=o.parentNode===e;!r&&!a?t?e.replaceChild(i,o):e.insertBefore(i,n):t&&o.remove()}else r=!0}}else e.insertBefore(i,n);return[i]}var ye=new URLSearchParams(window.location.search).get(`t`)??``;async function be(e,t={}){let n=await fetch(e,{...t,headers:{...t.body?{"content-type":`application/json`}:{},"x-plan-token":ye,...t.headers??{}}});if(!n.ok)throw Error(`${t.method??`GET`} ${e} → HTTP ${n.status}`);return await n.json()}function xe(e){return be(e===void 0?`/api/state`:`/api/state?version=${e}`)}function Se(e,t){return be(`/api/annotate`,{method:`POST`,body:JSON.stringify({version:e,annotations:t})})}function Ce(e,t){return be(`/api/decide`,{method:`POST`,body:JSON.stringify({action:e,version:t})})}function we(e){try{return JSON.parse(e.data)}catch{return}}function Te(e){let t=new EventSource(`/api/events?t=${encodeURIComponent(ye)}`);return t.addEventListener(`revision`,t=>{let n=we(t);n&&e.onRevision(n.version)}),t.addEventListener(`annotations`,()=>e.onAnnotations()),t.addEventListener(`decided`,t=>{let n=we(t);n&&e.onDecided(n)}),()=>t.close()}var Ee=`spec:lang`,De=`plan:lang`;function Oe(){let e=localStorage.getItem(Ee)??localStorage.getItem(De);return e===`en`||e===`zh`?e:navigator.language.toLowerCase().startsWith(`zh`)?`zh`:`en`}function ke(e){localStorage.setItem(Ee,e)}var Ae={en:{title:`Spec review`,version:`v{version} of {total}`,changed:`{count} blocks changed`,changedOne:`1 block changed`,noChange:`no changes`,showAll:`Show unchanged`,onlyChanged:`Only changed`,approve:`Approve spec`,deny:`Send feedback`,globalNotes:`Global notes`,globalNotesTitle:`Global notes`,notePlaceholder:`What should change here?`,addNote:`Add note`,save:`Save note`,cancel:`Cancel`,remove:`Remove`,verdictChange:`must change`,verdictSuggest:`suggest`,verdictQuestion:`question`,history:`History`,historySummary:`{count} blocks`,historySummaryOne:`1 block`,back:`Back to latest`,viewingOld:`Read-only: you are viewing v{v}`,readOnly:`Read-only`,approved:`Spec approved`,denied:`Feedback sent`,closing:`Closing this tab…`,closeHint:`You can close this tab now.`,status_unchanged:`unchanged`,status_moved:`moved`,status_modified:`modified`,status_added:`new`,status_removed:`removed`,unchangedHidden:`{count} unchanged blocks hidden`,unchangedHiddenOne:`1 unchanged block hidden`,error:`Something went wrong: {message}`,emptySpec:`This spec is empty.`,noteCount:`{count} notes`,noteCountOne:`1 note`,thisRevision:`This revision`,blocksChanged:`blocks changed`,ofTotal:`of {total} in the spec`,annotations:`Annotations`,noNotesYet:`No notes yet — annotate a block to see it here.`},zh:{title:`规格评审`,version:`第 {version} / {total} 版`,changed:`{count} 处改动`,changedOne:`1 处改动`,noChange:`无改动`,showAll:`显示未变块`,onlyChanged:`只看改动`,approve:`批准规格`,deny:`提交意见`,globalNotes:`全局批注`,globalNotesTitle:`全局批注`,notePlaceholder:`这里应该怎么改?`,addNote:`添加批注`,save:`保存批注`,cancel:`取消`,remove:`删除`,verdictChange:`必须改`,verdictSuggest:`建议`,verdictQuestion:`疑问`,history:`历史`,historySummary:`{count} 块`,historySummaryOne:`1 块`,back:`回到最新版`,viewingOld:`只读:正在查看第 {v} 版`,readOnly:`只读`,approved:`规格已批准`,denied:`意见已提交`,closing:`正在关闭标签页…`,closeHint:`现在可以关闭这个标签页了。`,status_unchanged:`未变`,status_moved:`位置移动`,status_modified:`已修改`,status_added:`新增`,status_removed:`已删除`,unchangedHidden:`隐藏了 {count} 个未变块`,unchangedHiddenOne:`隐藏了 1 个未变块`,error:`出错了:{message}`,emptySpec:`spec 是空的。`,noteCount:`{count} 条批注`,noteCountOne:`1 条批注`,thisRevision:`本版`,blocksChanged:`处改动`,ofTotal:`共 {total} 块`,annotations:`批注`,noNotesYet:`还没有批注——在段落上写一条就会出现在这里。`}};function je(e,t,n={}){return(Ae[e][t]??t).replace(/\{(\w+)\}/g,(e,t)=>String(n[t]??`{${t}}`))}var Me=W(`<span class=readonly>`),Ne=W(`<div class=error>`),Pe=W(`<div class=banner><span></span><button class=link>`),Fe=W(`<div class=done><div class=done-title></div><div class=done-hint>`),Ie=W(`<button class=add>+ `),Le=W(`<section id=global-notes class=global-card><div class=global-head><span class=eyebrow></span><span class=global-count>`),Re=W(`<p class=empty>`),ze=W(`<div class=collapsed><span></span><button class=link>`),Be=W(`<div class=rail-notes>`),Ve=W(`<button class=ghost>`),He=W(`<div class=page><header class=topbar><div class=masthead><div class=brand><span class=brand-mark aria-hidden=true><svg viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=1.8><path d="M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8L12 3z"></path><path d="M18.5 15.5l.7 2 2 .7-2 .7-.7 2-.7-2-2-.7 2-.7.7-2z"></path></svg></span><span class=eyebrow></span></div><div class=top-actions><button class="ghost lang"></button></div></div><div class=title-block><h1></h1><div class=meta><span class=meta-path></span><span class=meta-dot aria-hidden=true></span><span class=meta-version></span><span class=meta-dot aria-hidden=true></span><span class=meta-changed></span></div></div><div class=history><span class="eyebrow history-label"></span><span class=history-summary></span></div></header><div class=layout><main class=reading><div class=blocks></div></main><aside class=rail><section class=rail-card><span class=eyebrow></span><div class=rail-big><span class=rail-number></span><div class=rail-caption><span></span><span class=muted></span></div></div><div class=rail-breakdown><div class=rail-row><span class="dot dot-added"aria-hidden=true></span><span></span><b></b></div><div class=rail-row><span class="dot dot-modified"aria-hidden=true></span><span></span><b></b></div><div class=rail-row><span class="dot dot-moved"aria-hidden=true></span><span></span><b></b></div><div class=rail-row><span class="dot dot-removed"aria-hidden=true></span><span></span><b></b></div></div></section><section class=rail-card><div class=rail-head><span class=eyebrow></span><span class=rail-badge></span></div></section></aside></div><footer class=footer><div class=footer-left><button class=ghost> (<!>)</button></div><div class=footer-center><span class=notes-count><span class="dot dot-brand"aria-hidden=true></span></span></div><div class=footer-actions><button class=btn-feedback></button><button class=btn-approve><span></span><svg viewBox="0 0 24 24"fill=none stroke=currentColor stroke-width=2 aria-hidden=true><path d="M5 12h14M13 6l6 6-6 6">`),Ue=W(`<span class=chip-changed>+`),We=W(`<button class=chip><span class=chip-n>v`),Ge=W(`<button class=remove>`),Ke=W(`<div><span></span><span class=note-text>`),qe=W(`<article class=block><div aria-hidden=true></div><div class=block-inner><div class=block-head><span><span aria-hidden=true></span></span><span class=block-id></span></div><div class=block-body>`),Je=W(`<p class=rail-empty>`),Ye=W(`<button class=rail-note><span aria-hidden=true></span><span class=rail-note-body><span class=rail-note-label></span><span class=rail-note-text>`),Xe=W(`<div class=editor><div class=verdicts></div><textarea></textarea><div class=editor-actions><button class=ghost></button><button class=primary>`),Ze=W(`<label><input type=radio name=verdict>`);function Qe(){let[e,t]=y(Oe()),[n,r]=y(),[i,a]=y(),[o,s]=y(),[c,l]=y(),[u,d]=y(!1),[f,p]=y(),[m,h]=y(``),[g,_]=y(`change`),[v,S]=y(!1),C=(t,n)=>je(e(),t,n);async function w(e){try{let t=await xe(e);r(t),s(void 0),l(t.decided&&t.decision?t.decision.action:void 0)}catch(e){s(e instanceof Error?e.message:String(e))}}te(()=>{w(),ne(Te({onRevision:()=>{i()===void 0&&w()},onAnnotations:()=>{i()===void 0&&w()},onDecided:e=>l(e.action)}))}),ee(()=>{let e=n()?.slug;document.title=e?`${C(`title`)} — ${e}`:C(`title`)});let T=x(()=>n()?.items??[]),E=x(()=>T().filter(e=>e.status!==`unchanged`).length),D=x(()=>!u()&&E()>0),O=x(()=>D()?T().filter(e=>e.status===`unchanged`).length:0),k=x(()=>D()?T().filter(e=>e.status!==`unchanged`):T()),re=x(()=>n()?.history[0]?.n??n()?.version),A=x(()=>{let e=n();return e!==void 0&&e.version!==re()}),j=x(()=>{let e={unchanged:0,moved:0,modified:0,added:0,removed:0};for(let t of T())e[t.status]+=1;return e}),M=x(()=>[...n()?.history??[]].reverse()),N=x(()=>n()?.annotations.global??[]),P=x(()=>f()!==void 0&&f().blockId===void 0),ie=x(()=>N().length>0||P()),F=e=>n()?.annotations.blocks.find(t=>t.blockId===e)?.annotations??[],I=x(()=>{let e=n()?.annotations;if(!e)return 0;let t=e.blocks.reduce((e,t)=>e+t.annotations.length,0);return e.global.length+t}),L=x(()=>{let e=n();if(!e)return[];let t=new Map(e.items.map(e=>[e.id,e.label])),r=e.annotations.global.map((e,t)=>({key:`global-${t}`,label:C(`globalNotesTitle`),annotation:e}));for(let n of e.annotations.blocks){let e=t.get(n.blockId)??n.blockId;n.annotations.forEach((t,i)=>{r.push({key:`${n.blockId}-${i}`,blockId:n.blockId,label:e,annotation:t})})}return r});async function R(e){let t=n();if(!t)return;let i={...t,annotations:e};r(i);try{await Se(t.version,e)}catch(e){s(e instanceof Error?e.message:String(e)),await w(t.version)}}async function ae(e){let t=m().trim();if(t===``)return;let r=n();if(!r)return;let i={verdict:g(),comment:t},a;if(e===void 0)a={...r.annotations,global:[...r.annotations.global,i]};else{let t=r.annotations.blocks.slice(),n=t.findIndex(t=>t.blockId===e);n===-1?t.push({blockId:e,annotations:[i]}):t[n]={...t[n],annotations:[...t[n].annotations,i]},a={...r.annotations,blocks:t}}p(void 0),h(``),await R(a)}async function oe(e,t){let r=n();if(!r)return;let i;i=e===void 0?{...r.annotations,global:r.annotations.global.filter((e,n)=>n!==t)}:{...r.annotations,blocks:r.annotations.blocks.map(n=>n.blockId===e?{...n,annotations:n.annotations.filter((e,n)=>n!==t)}:n).filter(e=>e.annotations.length>0)},await R(i)}function z(){!A()&&!P()&&(p({blockId:void 0}),h(``),_(`change`)),requestAnimationFrame(()=>{document.getElementById(`global-notes`)?.scrollIntoView({behavior:`smooth`,block:`start`})})}function se(){if(!A()){if(P()){p(void 0);return}z()}}function ce(e){if(e.blockId===void 0){z();return}let t=e.blockId;k().some(e=>e.id===t)||d(!0),requestAnimationFrame(()=>{document.getElementById(`block-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})})}async function le(e){let t=n();if(t)try{await Ce(e,t.version),l(e),window.close(),setTimeout(()=>S(!0),300)}catch(e){s(e instanceof Error?e.message:String(e))}}let ue=e=>`badge badge-${e}`,de=e=>`verdict${e[0].toUpperCase()}${e.slice(1)}`,fe=e=>`note-verdict verdict-${e}`;return(()=>{var r=He(),s=r.firstChild,l=s.firstChild,y=l.firstChild,ee=y.firstChild.nextSibling,x=y.nextSibling.firstChild,S=l.nextSibling,te=S.firstChild,ne=te.nextSibling,D=ne.firstChild,R=D.nextSibling.nextSibling,z=R.nextSibling.nextSibling,pe=S.nextSibling,W=pe.firstChild,me=W.nextSibling,K=s.nextSibling,J=K.firstChild,Y=J.firstChild,_e=J.nextSibling.firstChild,X=_e.firstChild,Z=X.nextSibling,ve=Z.firstChild,Q=ve.nextSibling.firstChild,ye=Q.nextSibling,be=Z.nextSibling.firstChild,xe=be.firstChild.nextSibling,Se=xe.nextSibling,Ce=be.nextSibling,we=Ce.firstChild.nextSibling,Te=we.nextSibling,Ee=Ce.nextSibling,De=Ee.firstChild.nextSibling,Oe=De.nextSibling,Ae=Ee.nextSibling.firstChild.nextSibling,je=Ae.nextSibling,Xe=_e.nextSibling,Ze=Xe.firstChild.firstChild,Qe=Ze.nextSibling,et=K.nextSibling.firstChild,$=et.firstChild,tt=$.firstChild,nt=tt.nextSibling;nt.nextSibling;var rt=et.nextSibling,it=rt.firstChild;it.firstChild;var at=rt.nextSibling.firstChild,ot=at.nextSibling,st=ot.firstChild;return q(ee,()=>C(`title`)),x.$$click=()=>{let n=e()===`en`?`zh`:`en`;t(n),ke(n)},q(x,()=>e()===`en`?`中文`:`EN`),q(te,()=>n()?.slug??`spec`),q(D,()=>n()?.source??`specs/spec.md`),q(R,()=>C(`version`,{version:n()?.version??0,total:n()?.totalVersions??0})),q(z,(()=>{var e=U(()=>E()>0);return()=>e()?C(E()===1?`changedOne`:`changed`,{count:E()}):C(`noChange`)})()),q(ne,B(H,{get when(){return A()},get children(){var e=Me();return q(e,()=>C(`readOnly`)),e}}),null),q(W,()=>C(`history`)),q(pe,B(V,{get each(){return M()},children:e=>(()=>{var t=We(),r=t.firstChild;return r.firstChild,t.$$click=()=>{e.n===re()?(a(void 0),w()):(a(e.n),w(e.n))},q(r,()=>e.n,null),q(t,B(H,{get when(){return e.changed>0},get children(){var t=Ue();return t.firstChild,q(t,()=>e.changed,null),t}}),null),b(()=>t.classList.toggle(`active`,e.n===n()?.version)),t})()}),me),q(me,()=>C(T().length===1?`historySummaryOne`:`historySummary`,{count:T().length})),q(r,B(H,{get when(){return o()},get children(){var e=Ne();return q(e,()=>C(`error`,{message:o()??``})),e}}),K),q(J,B(H,{get when(){return A()},get children(){var e=Pe(),t=e.firstChild,r=t.nextSibling;return q(t,()=>C(`viewingOld`,{v:i()??n()?.version??0})),r.$$click=()=>{a(void 0),w()},q(r,()=>C(`back`)),e}}),Y),q(J,B(H,{get when(){return c()},get children(){var e=Fe(),t=e.firstChild,n=t.nextSibling;return q(t,(()=>{var e=U(()=>c()===`approve`);return()=>e()?C(`approved`):C(`denied`)})()),q(n,(()=>{var e=U(()=>!!v());return()=>e()?C(`closeHint`):C(`closing`)})()),e}}),Y),q(J,B(H,{get when(){return ie()},get children(){var e=Le(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return q(n,()=>C(`globalNotesTitle`)),q(r,()=>N().length),q(t,B(H,{get when(){return U(()=>!A())()&&!P()},get children(){var e=Ie();return e.firstChild,e.$$click=()=>{p({blockId:void 0}),h(``),_(`change`)},q(e,()=>C(`addNote`),null),e}}),null),q(e,B(V,{get each(){return N()},children:(e,t)=>(()=>{var n=Ke(),r=n.firstChild,i=r.nextSibling;return q(r,()=>C(de(e.verdict))),q(i,()=>e.comment),q(n,B(H,{get when(){return!A()},get children(){var e=Ge();return e.$$click=()=>void oe(void 0,t()),q(e,()=>C(`remove`)),e}}),null),b(t=>{var i=`note note-${e.verdict}`,a=fe(e.verdict);return i!==t.e&&G(n,t.e=i),a!==t.t&&G(r,t.t=a),t},{e:void 0,t:void 0}),n})()}),null),q(e,B(H,{get when(){return U(()=>!!P())()&&!A()},get children(){return B($e,{draft:m,setDraft:h,verdict:g,setVerdict:_,onSave:()=>void ae(void 0),onCancel:()=>p(void 0),t:C})}}),null),e}}),Y),q(J,B(H,{get when(){return U(()=>!!n())()&&n().items.length===0},get children(){var e=Re();return q(e,()=>C(`emptySpec`)),e}}),Y),q(J,B(H,{get when(){return O()>0},get children(){var e=ze(),t=e.firstChild,n=t.nextSibling;return q(t,()=>C(O()===1?`unchangedHiddenOne`:`unchangedHidden`,{count:O()})),n.$$click=()=>d(!0),q(n,()=>C(`showAll`)),e}}),Y),q(Y,B(V,{get each(){return k()},children:e=>(()=>{var t=qe(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.firstChild,o=a.firstChild,s=a.nextSibling,c=i.nextSibling;return q(a,()=>C(`status_${e.status}`),null),q(s,()=>e.id),q(i,B(H,{get when(){return!A()},get children(){var t=Ie();return t.firstChild,t.$$click=()=>{p({blockId:e.id}),h(``),_(`change`)},q(t,()=>C(`addNote`),null),t}}),null),q(r,B(V,{get each(){return F(e.id)},children:(t,n)=>(()=>{var r=Ke(),i=r.firstChild,a=i.nextSibling;return q(i,()=>C(de(t.verdict))),q(a,()=>t.comment),q(r,B(H,{get when(){return!A()},get children(){var t=Ge();return t.$$click=()=>void oe(e.id,n()),q(t,()=>C(`remove`)),t}}),null),b(e=>{var n=`note note-${t.verdict}`,a=fe(t.verdict);return n!==e.e&&G(r,e.e=n),a!==e.t&&G(i,e.t=a),e},{e:void 0,t:void 0}),r})()}),null),q(r,B(H,{get when(){return U(()=>f()?.blockId===e.id)()&&!A()},get children(){return B($e,{draft:m,setDraft:h,verdict:g,setVerdict:_,onSave:()=>void ae(e.id),onCancel:()=>p(void 0),t:C})}}),null),b(r=>{var i=`block-${e.id}`,s={[`is-`+e.status]:!0},l=`block-bar bar-${e.status}`,u=ue(e.status),d=`dot dot-${e.status}`,f=e.html;return i!==r.e&&he(t,`id`,r.e=i),r.t=ge(t,s,r.t),l!==r.a&&G(n,r.a=l),u!==r.o&&G(a,r.o=u),d!==r.i&&G(o,r.i=d),f!==r.n&&(c.innerHTML=r.n=f),r},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),t})()})),q(X,()=>C(`thisRevision`)),q(ve,E),q(Q,()=>C(`blocksChanged`)),q(ye,()=>C(`ofTotal`,{total:T().length})),q(xe,()=>C(`status_added`)),q(Se,()=>j().added),q(we,()=>C(`status_modified`)),q(Te,()=>j().modified),q(De,()=>C(`status_moved`)),q(Oe,()=>j().moved),q(Ae,()=>C(`status_removed`)),q(je,()=>j().removed),q(Ze,()=>C(`annotations`)),q(Qe,I),q(Xe,B(H,{get when(){return L().length>0},get fallback(){return(()=>{var e=Je();return q(e,()=>C(`noNotesYet`)),e})()},get children(){var e=Be();return q(e,B(V,{get each(){return L()},children:e=>(()=>{var t=Ye(),n=t.firstChild,r=n.nextSibling.firstChild,i=r.nextSibling;return t.$$click=()=>ce(e),q(r,()=>e.label),q(i,()=>e.annotation.comment),b(()=>G(n,`dot dot-${e.annotation.verdict}`)),t})()})),e}}),null),q(et,B(H,{get when(){return E()>0},get children(){var e=Ve();return e.$$click=()=>d(!u()),q(e,(()=>{var e=U(()=>!!u());return()=>e()?C(`onlyChanged`):C(`showAll`)})()),e}}),$),$.$$click=se,q($,()=>C(`globalNotes`),tt),q($,()=>N().length,nt),q(it,()=>C(I()===1?`noteCountOne`:`noteCount`,{count:I()}),null),at.$$click=()=>void le(`deny`),q(at,()=>C(`deny`)),ot.$$click=()=>void le(`approve`),q(st,()=>C(`approve`)),b(e=>{var t=A(),n=A()||c()!==void 0,r=A()||c()!==void 0;return t!==e.e&&($.disabled=e.e=t),n!==e.t&&(at.disabled=e.t=n),r!==e.a&&(ot.disabled=e.a=r),e},{e:void 0,t:void 0,a:void 0}),r})()}function $e(e){return(()=>{var t=Xe(),n=t.firstChild,r=n.nextSibling,i=r.nextSibling.firstChild,a=i.nextSibling;return q(n,B(V,{each:[`change`,`suggest`,`question`],children:t=>(()=>{var n=Ze(),r=n.firstChild;return r.addEventListener(`change`,()=>e.setVerdict(t)),q(n,()=>e.t(`verdict${t[0].toUpperCase()}${t.slice(1)}`),null),b(()=>n.classList.toggle(`active`,e.verdict()===t)),b(()=>r.checked=e.verdict()===t),n})()})),r.$$input=t=>e.setDraft(t.currentTarget.value),K(i,`click`,e.onCancel,!0),q(i,()=>e.t(`cancel`)),K(a,`click`,e.onSave,!0),q(a,()=>e.t(`save`)),b(t=>{var n=e.t(`notePlaceholder`),i=e.draft().trim()===``;return n!==t.e&&he(r,`placeholder`,t.e=n),i!==t.t&&(a.disabled=t.t=i),t},{e:void 0,t:void 0}),b(()=>r.value=e.draft()),t})()}me([`click`,`input`]);var et=document.getElementById(`root`);et&&pe(()=>B(Qe,{}),et);
|
|
File without changes
|
|
File without changes
|