Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ What EMRG does today — capabilities, not a changelog.
Foreground daemon: `python -m emrg`.

- Python: `uv run pytest tests/ -v` — re-count with `uv run --no-sync python3 scripts/check-doc-count.py --measure`. Import check: `uv run python -c "from emrg.client.app import run_client"`
GUI: `cd emrg/gui && npm test` (282: 107 daemon_client + 22 conn-manager + 7 integration + 7 nav-policy + 11 gui-state + 10 build-config + 10 config_fields + 16 boot-contract + 3 preload-api + 2 theme-guard + 2 image-hash + 8 switch-session + 19 atp_login + 4 gui-op-log + 9 theme-setting + 5 window-title + 4 frame-route + 12 browser-policy + 5 browser-wiring + 13 settings_store + 6 annotation-wiring) — syntax: `node --check main.js preload.js daemon_client.js`
Renderer: `cd emrg/gui/renderer && npm run typecheck && npm test` (1283: 5 snapshot-store + 13 utils + 3 ErrorBoundary + 2 App + 12 commands + 4 copywriting + 14 i18n + 33 markdown + 22 selection + 41 transcript + 11 conversationType + 4 MarkdownText + 65 TranscriptView + 22 history + 30 historyReplay + 8 userImages + 43 composer + 97 Composer + 14 sidebar + 32 workspaceView + 18 WorkspaceView + 10 dialog + 6 Dialog + 9 ConfirmDialog + 9 RenameDialog + 13 dialogLists + 3 HelpDialog + 9 MemoryDialog + 8 SkillsDialog + 8 openSession + 6 WelcomeDialog + 20 OpenSessionDialog + 14 NewSessionDialog + 7 rewind + 8 RewindDialog + 7 GithubDeviceDialog + 82 daemonBridge + 13 DaemonBridgeProvider + 69 Shell + 19 page + 51 EditorPanel + 25 DialogHost + 48 SettingsPanel + 18 TaskFormDialog + 5 RantDialog + 8 vendorMarkdown + 10 highlightTheme + 8 ApprovalDialog + 20 SandboxRootsDialog + 42 cockpit + 4 editorSelectionCascade + 9 fileTree + 24 FileTree + 5 contextMenu + 1 residue + 24 StatusBand + 24 UsageRanking + 9 usageRanking + 6 SearchOverlay + 5 ResizeHandle + 8 IconRail + 6 SessionColumn + 5 EmrgMark + 38 editorDoc + 27 CodeEditor + 26 annotation + 14 AnnotationMode)
GUI: `cd emrg/gui && npm test` (284: 107 daemon_client + 22 conn-manager + 7 integration + 7 nav-policy + 11 gui-state + 10 build-config + 10 config_fields + 16 boot-contract + 3 preload-api + 2 theme-guard + 2 image-hash + 8 switch-session + 19 atp_login + 4 gui-op-log + 9 theme-setting + 5 window-title + 4 frame-route + 12 browser-policy + 5 browser-wiring + 13 settings_store + 8 annotation-wiring) — syntax: `node --check main.js preload.js daemon_client.js`
Renderer: `cd emrg/gui/renderer && npm run typecheck && npm test` (1287: 5 snapshot-store + 13 utils + 3 ErrorBoundary + 2 App + 12 commands + 4 copywriting + 14 i18n + 33 markdown + 22 selection + 41 transcript + 11 conversationType + 4 MarkdownText + 65 TranscriptView + 22 history + 30 historyReplay + 8 userImages + 43 composer + 97 Composer + 14 sidebar + 32 workspaceView + 18 WorkspaceView + 10 dialog + 6 Dialog + 9 ConfirmDialog + 9 RenameDialog + 13 dialogLists + 3 HelpDialog + 9 MemoryDialog + 8 SkillsDialog + 8 openSession + 6 WelcomeDialog + 20 OpenSessionDialog + 14 NewSessionDialog + 7 rewind + 8 RewindDialog + 7 GithubDeviceDialog + 82 daemonBridge + 13 DaemonBridgeProvider + 69 Shell + 19 page + 51 EditorPanel + 25 DialogHost + 48 SettingsPanel + 18 TaskFormDialog + 5 RantDialog + 8 vendorMarkdown + 10 highlightTheme + 8 ApprovalDialog + 20 SandboxRootsDialog + 42 cockpit + 4 editorSelectionCascade + 9 fileTree + 24 FileTree + 5 contextMenu + 1 residue + 24 StatusBand + 24 UsageRanking + 9 usageRanking + 6 SearchOverlay + 5 ResizeHandle + 8 IconRail + 6 SessionColumn + 5 EmrgMark + 38 editorDoc + 27 CodeEditor + 30 annotation + 14 AnnotationMode)
- CI: pytest on ubuntu **and windows-2025**, the GUI suites, and an actionlint gate over `.github/workflows/`; re-trigger a dropped push with `scripts/re-trigger-ci.sh <branch>`, never an empty commit
- Merge gates, run before merging — `uv run --no-sync python3 scripts/check-vote-count.py` · `scripts/check-pr-base.py` · `scripts/check-merge-freshness.py` · `scripts/check-merge-order.py` · `scripts/check-merge-landing-diff.py` · `scripts/check-merge-pairs.py` / `scripts/check-merge-sequence.py` · `scripts/check-merge-tree-health.py` (the merged tree passes one guard) · `scripts/check-merge-plan-suite.py` — all under `uv run --no-sync python3`
- Post-merge audit: `uv run --no-sync python3 scripts/check-merge-landed.py <N>` (did it land the reviewed tree)
Expand Down
48 changes: 39 additions & 9 deletions emrg/gui/annotation-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
* strings. No node, no element, no selector to evaluate: the main process forwards it and the
* renderer composes the message with `composeMessage`.
*
* Selecting text is the whole gesture. A selection is wrapped in a `<mark>` in place, its
* containing block becomes the quote, and the element path becomes the address — the rendered
* words are not the source words, so the file and the element are what make the annotation
* locatable again. Marks are not reattached after the page reloads: this layer keeps no store, and
* an annotation that silently moved is worse than one that is gone.
* Selecting text is the whole gesture, and it is also the only one. A selection is wrapped in a
* `<mark>` in place, its containing block becomes the quote, and the element path becomes the
* address — the rendered words are not the source words, so the file and the element are what make
* the annotation locatable again. The panel is built once per document, so the close button hides
* it rather than taking it away, and the next selection brings it back with whatever was left
* unsent. Marks are not reattached after the page reloads: this layer keeps no store, and an
* annotation that silently moved is worse than one that is gone.
*/

const { ipcRenderer } = require("electron");
Expand Down Expand Up @@ -199,7 +201,22 @@ function main() {
ui.panel.style.width = `${box.w}px`;
ui.panel.style.height = `${box.h}px`;
};
place();

// Closing hides the panel; it does not destroy it. The panel is built once, when the document
// loads, so a close that took it out of the DOM would be a feature that works once per page
// load — the host closed it, selected another paragraph, and nothing came back. `show` puts it
// back where it was, pulled inside the viewport if the page was resized in between.
const show = () => {
const vp = viewport();
box.x = clamp(box.x, 0, Math.max(0, vp.w - box.w));
box.y = clamp(box.y, 0, Math.max(0, vp.h - box.h));
place();
ui.host.style.display = "";
};
const hide = () => {
ui.host.style.display = "none";
};
show();

const render = () => {
ui.count.textContent = items.length ? String(items.length) : "";
Expand Down Expand Up @@ -260,15 +277,25 @@ function main() {
const submit = () => {
const payload = items
.filter((i) => i.body.trim().length > 0)
.map((i) => ({ paragraph: i.paragraph, body: i.body.trim(), selector: i.selector }));
// `exact` travels with the block, not instead of it (host 2026-12-03T22:08): the container
// says which paragraph, and only the selected words say which part of it the annotation is
// about. Sending the block alone left the model reading a whole paragraph and guessing.
.map((i) => ({
exact: i.exact,
paragraph: i.paragraph,
body: i.body.trim(),
selector: i.selector,
}));
if (payload.length === 0) return;
ipcRenderer.send("emrg:pageAnnotate", { items: payload });
items.length = 0;
render();
ui.host.remove();
hide();
};
ui.send.addEventListener("click", submit);
ui.close.addEventListener("click", () => ui.host.remove());
// Closing keeps the annotations that have not been sent: their marks are still on the page, and
// a panel that threw them away would leave marks explaining nothing.
ui.close.addEventListener("click", hide);

// ── Moving and resizing: the panel belongs to the person dragging it ──
let drag = null;
Expand Down Expand Up @@ -347,6 +374,9 @@ function main() {
mark,
});
render();
// Selecting text is also how a closed panel comes back — it is the same gesture that makes
// an annotation, and the only gesture this layer offers.
show();
});
}

Expand Down
6 changes: 4 additions & 2 deletions emrg/gui/renderer/src/components/AnnotationMode.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const REPLY =
"<p>先把这个弹窗关掉</p><p>再回来处理那个弹窗的宽度,宽度不对会挡住校验</p>";

describe("annotating a reply", () => {
it("turns a selection into a card and sends the containing paragraph once", async () => {
it("turns a selection into a card and sends the paragraph with the words that were selected", async () => {
const sent: string[] = [];
render(<Harness html={REPLY} onSend={(text) => sent.push(text)} />);

Expand All @@ -133,8 +133,10 @@ describe("annotating a reply", () => {
fireEvent.change(body, { target: { value: "这个宽度不对" } });

fireEvent.click(screen.getByTestId("anno-send"));
// The blockquote is the container; `选中:` is the words (host 2026-12-03T22:08). Without the
// second line the model reads a whole paragraph and has to guess what the opinion is about.
expect(sent).toEqual([
"> 再回来处理那个弹窗的宽度,宽度不对会挡住校验\n\n这个宽度不对",
"> 再回来处理那个弹窗的宽度,宽度不对会挡住校验\n\n选中:弹窗\n\n这个宽度不对",
]);
});

Expand Down
3 changes: 3 additions & 0 deletions emrg/gui/renderer/src/components/AnnotationMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ export function AnnotationMode({ sid, root, messageKey, t, onSend, onClose }: An
// A stale anchor has no paragraph to quote any more, so the stored words travel instead —
// the reader then sees exactly what the annotation was attached to.
paragraph: stale.includes(a.id) ? a.exact : paragraphTextAt(root, a.start) || a.exact,
// The words themselves, so the blockquote is not the only thing saying what was meant
// (host 2026-12-03T22:08).
exact: a.exact,
body: a.body,
})),
);
Expand Down
18 changes: 15 additions & 3 deletions emrg/gui/renderer/src/components/Shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,26 @@ export function Shell() {
return emrg.onPageAnnotation((raw) => {
const data = raw as { file?: unknown; items?: unknown } | null;
const file = typeof data?.file === "string" ? data.file : "";
const rows: { paragraph: string; body: string; source?: string }[] = [];
const rows: { paragraph: string; body: string; exact?: string; source?: string }[] = [];
for (const entry of Array.isArray(data?.items) ? data.items : []) {
const item = entry as { paragraph?: unknown; body?: unknown; selector?: unknown };
const item = entry as {
paragraph?: unknown;
body?: unknown;
selector?: unknown;
exact?: unknown;
};
const paragraph = typeof item.paragraph === "string" ? item.paragraph : "";
const body = typeof item.body === "string" ? item.body : "";
const selector = typeof item.selector === "string" ? item.selector : "";
// The words the person picked, which the blockquote alone cannot say (host 2026-12-03T22:08).
const exact = typeof item.exact === "string" ? item.exact : "";
if (!paragraph || !body.trim()) continue;
rows.push({ paragraph, body, source: selector && file ? sourceLine(file, selector) : undefined });
rows.push({
exact,
paragraph,
body,
source: selector && file ? sourceLine(file, selector) : undefined,
});
}
const composed = composeMessage(rows);
if (!composed) return;
Expand Down
49 changes: 49 additions & 0 deletions emrg/gui/renderer/src/lib/annotation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,55 @@ describe("the sent message is CommonMark", () => {
]),
).toBe("1. > 甲\n\n 一\n\n2. > 乙\n\n 第一行\n 第二行");
});

it("names the words that were selected, between the quote and the annotation", () => {
// 宿主 2026-12-03T22:08:整段引文里看不出选中了哪几个字。
expect(
composeMessage([
{
exact: "本地",
paragraph: "专家的一切都从磁盘这几个目录来。前三个由档案决定,模板层与运行态同一套。",
body: "添加“本地”",
},
]),
).toBe(
"> 专家的一切都从磁盘这几个目录来。前三个由档案决定,模板层与运行态同一套。\n\n" +
"选中:本地\n\n" +
"添加“本地”",
);
});

it("keeps each annotation's selected words inside its own list item", () => {
expect(
composeMessage([
{ exact: "本地", paragraph: "一、档案决定目录", body: "加这个" },
{ exact: "capabilityType=EXPERT_SKILL 的那些", paragraph: "二、档案里的技能", body: "这三个字不要" },
]),
).toBe(
"1. > 一、档案决定目录\n\n 选中:本地\n\n 加这个\n\n" +
"2. > 二、档案里的技能\n\n 选中:capabilityType=EXPERT_SKILL 的那些\n\n 这三个字不要",
);
});

it("adds no selected-words line when the selection is the whole block, or unknown", () => {
// 选中整块:「选中:」只是把引文再抄一遍。
expect(composeMessage([{ exact: "整段文字", paragraph: "整段文字", body: "看这里" }])).toBe(
"> 整段文字\n\n看这里",
);
// 老 payload 没有 exact,输出与原来逐字相同。
expect(composeMessage([{ paragraph: "整段文字", body: "看这里" }])).toBe("> 整段文字\n\n看这里");
expect(composeMessage([{ exact: " ", paragraph: "整段文字", body: "看这里" }])).toBe(
"> 整段文字\n\n看这里",
);
});

it("keeps the file address after the selected words and the annotation", () => {
expect(
composeMessage([
{ exact: "本地", paragraph: "整段", body: "改这里", source: "`/a/b.html` · `body > p`" },
]),
).toBe("> 整段\n\n选中:本地\n\n改这里\n\n`/a/b.html` · `body > p`");
});
});

describe("a reply is keyed by its own text, per session", () => {
Expand Down
35 changes: 32 additions & 3 deletions emrg/gui/renderer/src/lib/annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,31 @@ function flatten(text: string): string {
return text.replace(/\s+/g, " ").trim();
}

/**
* The line that names the words the person selected, or `null` when it adds nothing.
*
* The block alone is not enough (host 2026-12-03T22:08). A screenshot of one real batch showed two
* annotations whose quoted paragraphs were both far longer than the selections: one had 「本地」
* picked out of a paragraph and the other 「capabilityType=EXPERT_SKILL 的那些」 out of a table
* cell, and the message the model received quoted the paragraphs and never mentioned the words. The
* opinion arrived attached to a block, with nothing saying which part of it was meant.
*
* So the words are sent as their own line rather than being marked inside the quote. Marking them
* would need the words to occur exactly once in the flattened block — a selection that crosses an
* element boundary flattens differently, and a word that repeats would be marked at the wrong
* place — and a wrong mark is worse than none. A separate line cannot be wrong about position
* because it does not claim one; the blockquote above it already says where to look.
*
* It is omitted when the selection is the whole block, and when the caller had no selection text
* at all (a payload from an older preload), so a message composed from blocks alone is unchanged.
*/
function selectedLineOf(item: { paragraph: string; exact?: string }): string | null {
const exact = (item.exact ?? "").replace(/\s+/g, " ").trim();
if (exact.length === 0) return null;
if (exact === item.paragraph.replace(/\s+/g, " ").trim()) return null;
return `选中:${exact}`;
}

/**
* The message a batch of annotations sends: CommonMark, in the shape a review comment already
* uses — the containing paragraph as a blockquote, a blank line, then what the person wrote.
Expand All @@ -274,7 +299,7 @@ function flatten(text: string): string {
* is the anchor, and its own words are the address.
*/
export function composeMessage(
items: readonly { paragraph: string; body: string; source?: string }[],
items: readonly { paragraph: string; body: string; exact?: string; source?: string }[],
): string {
const usable = items.filter((i) => i.body.trim().length > 0);
if (usable.length === 0) return "";
Expand All @@ -285,14 +310,18 @@ export function composeMessage(
};
if (usable.length === 1) {
const [only] = usable;
const selected = selectedLineOf(only);
const origin = only.source ? `\n\n${only.source}` : "";
return `${quoteOf(only.paragraph).join("\n")}\n\n${only.body.trim()}${origin}`;
const marked = selected ? `\n\n${selected}` : "";
return `${quoteOf(only.paragraph).join("\n")}${marked}\n\n${only.body.trim()}${origin}`;
}
return usable
.map((item, i) => {
const quote = quoteOf(item.paragraph);
const head = `${i + 1}. ${quote[0]}`;
const rest = quote.slice(1).map((l) => ` ${l}`);
const selected = selectedLineOf(item);
const marks = selected ? ["", ` ${selected}`] : [];
const body = item.body
.trim()
.split("\n")
Expand All @@ -301,7 +330,7 @@ export function composeMessage(
// useless to the reader without the file it came from, and leaving it out of the list item
// would put the address of the second page under the first one's opinion.
const origin = item.source ? ["", ` ${item.source}`] : [];
return [head, ...rest, "", ...body, ...origin].join("\n");
return [head, ...rest, ...marks, "", ...body, ...origin].join("\n");
})
.join("\n\n");
}
Expand Down
25 changes: 25 additions & 0 deletions emrg/gui/test/annotation-wiring.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,31 @@ test("the annotation preload hands the page nothing at all", () => {
assert.doesNotMatch(code, /window\.emrg\s*=/);
});

test("closing the panel hides it, so the next selection brings it back", () => {
// 宿主 2026-12-03T21:47:点关闭之后,再选文字就没有任何反应。原因是关闭把面板从文档里摘掉,
// 而面板只在文档加载时建一次——一个每个页面只能开一次的功能。关闭只能是隐藏。
const code = codeOnly(PAGE_PRELOAD);
assert.doesNotMatch(code, /ui\.host\.remove\(\)/, "关闭或发送都不得把面板摘出文档");
assert.match(code, /ui\.close\.addEventListener\("click", hide\)/, "关闭绑到隐藏");
assert.match(code, /style\.display = "none"/, "隐藏就是 display:none");
// 选字是这一层唯一的手势,也是把面板叫回来的那一个。
const selectAt = code.indexOf('document.addEventListener("mouseup"');
assert.ok(selectAt >= 0, "找不到选字处理处");
const tail = code.slice(selectAt);
assert.match(tail, /show\(\)/, "选字之后要把面板显示出来");
});

test("the words the person selected travel out of the page, not just the block around them", () => {
// 宿主 2026-12-03T22:08:整段引文里看不出选中了哪几个字——preload 采集了 `exact`,却在
// 组装 payload 时丢掉,于是消息里只有整段。这条线要两端都钉住,少一端就静默回退。
const submitAt = PAGE_PRELOAD.indexOf("const submit = ()");
assert.ok(submitAt >= 0, "找不到 submit");
const submit = PAGE_PRELOAD.slice(submitAt, submitAt + 900);
assert.match(submit, /exact:\s*i\.exact/, "preload 要把选中原文发出去");
assert.match(SHELL, /const exact = typeof item\.exact === "string"/, "Shell 要读 exact");
assert.match(SHELL, /rows\.push\(\{\s*\n?\s*exact,/, "Shell 要把 exact 交给组装函数");
});

test("the app subscribes once and the batch leaves through the composer", () => {
assert.match(APP_PRELOAD, /onPageAnnotation:/);
assert.match(APP_PRELOAD, /ipcRenderer\.on\("emrg:pageAnnotation"/);
Expand Down
Loading