A local-first multi-agent app development platform, built on PenguinHarness
feat(web): 更新拉不到 GitHub 时,可以让 Adelie 自己排查并把新版本下下来
lmlihengb371edcabbf3
diff --git a/packages/web/src/components/account/update-modal.tsx b/packages/web/src/components/account/update-modal.tsxindex 4e16b418..1cb51843 100644--- a/packages/web/src/components/account/update-modal.tsx+++ b/packages/web/src/components/account/update-modal.tsx@@ -9,15 +9,20 @@* (with "background" — closing never cancels; the row keeps reporting and the outcome* toasts), then "restart and update" once the release is ready. Failures show the* backend's own text — the update command's output tail, the shell's updater message —- * and offer a retry; an install form that cannot update itself says why.+ * and offer a retry; an install form that cannot update itself says why. A failure that is+ * the host being unable to reach GitHub offers one thing more: the hand-off to an Agent+ * that can diagnose the network and fetch the release itself (lib/update-troubleshoot.ts).** The flow and the actions live in `use-update-flow.ts`; this file only renders.*/import type { ReactNode } from "react";import { Button, Link, Modal, ProgressBar, Spinner } from "@adelie/ui";+import { pickDefaultAgent, useAiBridge } from "../../features/ai-create";import { S } from "../../lib/strings";import { stripAnsi } from "../../lib/strip-ansi";import { toneInk } from "../../lib/tone";+import { buildUpdateTroubleshootPrompt, unreachableDownload } from "../../lib/update-troubleshoot";+import { useProject } from "../../state/project";import type { UpdateFlow, UpdateMode } from "../../lib/update-flow";import {checkForUpdates,@@ -33,13 +38,14 @@ const RELEASES_URL = "https://github.com/lmliheng/Adelie/releases";export function UpdateModal() {useUpdateFlowOwner();const { mode, flow, modalOpen, currentVersion } = useUpdateFlow();+ const openTroubleshoot = useTroubleshootOffer(flow);if (mode === "none") return null;return (<Modalopen={modalOpen}title={S.update.title}onClose={closeUpdateModal}- footer={<Footer mode={mode} flow={flow} />}+ footer={<Footer mode={mode} flow={flow} openTroubleshoot={openTroubleshoot} />}><div className="space-y-3">{currentVersion !== null && (@@ -47,13 +53,42 @@ export function UpdateModal() {{S.update.currentVersion(currentVersion)}</p>)}- <Body mode={mode} flow={flow} />+ <Body mode={mode} flow={flow} openTroubleshoot={openTroubleshoot} /></div></Modal>);}-function Body({ mode, flow }: { mode: UpdateMode; flow: UpdateFlow }): ReactNode {+/**+ * The hand-off offer on a failed download, or null when there is nothing to hand over. Decided once+ * in the modal because both halves render it: the body explains what it costs, the footer's button+ * performs it. The Agent is the Project's default one (pickDefaultAgent's own reasoning — it carries+ * the preinstalled library), and a Project with no agents offers nothing to send the prompt to.+ *+ * Clicking writes the prompt into a new chat's draft and closes this modal; nothing is sent until+ * the user presses Send there (see features/ai-create/ai-bridge.ts).+ */+function useTroubleshootOffer(flow: UpdateFlow): (() => void) | null {+ const { openAiChat } = useAiBridge();+ const { agents } = useProject();+ if (flow.kind !== "error" || !unreachableDownload(flow)) return null;+ const agentId = pickDefaultAgent(agents)?.agentId ?? null;+ if (agentId === null) return null;+ return () => {+ openAiChat({ agentId, text: buildUpdateTroubleshootPrompt(flow) });+ closeUpdateModal();+ };+}++function Body({+ mode,+ flow,+ openTroubleshoot,+}: {+ mode: UpdateMode;+ flow: UpdateFlow;+ openTroubleshoot: (() => void) | null;+}): ReactNode {switch (flow.kind) {case "unknown":case "checking":@@ -133,6 +168,9 @@ function Body({ mode, flow }: { mode: UpdateMode; flow: UpdateFlow }): ReactNode</p>{flow.message !== null && <p className="text-sm">{flow.message}</p>}{flow.detail !== null && <OutputTail text={flow.detail} />}+ {openTroubleshoot !== null && (+ <p className="text-sm text-gray-600 dark:text-gray-400">{S.update.troubleshootHint}</p>+ )}</>);case "unsupported":@@ -156,7 +194,15 @@ function Body({ mode, flow }: { mode: UpdateMode; flow: UpdateFlow }): ReactNode}}-function Footer({ mode, flow }: { mode: UpdateMode; flow: UpdateFlow }): ReactNode {+function Footer({+ mode,+ flow,+ openTroubleshoot,+}: {+ mode: UpdateMode;+ flow: UpdateFlow;+ openTroubleshoot: (() => void) | null;+}): ReactNode {const close = (<Button size="sm" onClick={closeUpdateModal}>{S.common.close}@@ -211,6 +257,11 @@ function Footer({ mode, flow }: { mode: UpdateMode; flow: UpdateFlow }): ReactNoreturn (<>{close}+ {openTroubleshoot !== null && (+ <Button size="sm" onClick={openTroubleshoot}>+ {S.update.troubleshootAction}+ </Button>+ )}<Buttonsize="sm"variant="primary"diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex 0fb4a486..4643c281 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -1027,6 +1027,39 @@ export const en: Strings = {restartingBodyClient: "The app is about to restart.",failed: "Update failed",retry: "Retry",+ /**+ * The escape hatch on a download that could not reach GitHub (lib/update-troubleshoot.ts):+ * some hosts cannot get to GitHub at all, and no retry from that host changes it. The button+ * opens a new chat with the prompt below; the hint says what it costs before it is pressed,+ * because the model call is the user's own.+ */+ troubleshootAction: "Have Adelie diagnose and download",+ troubleshootHint:+ "This needs a model configured on the Models page: the Agent does the diagnosing with it, and those calls are billed like any other. Opening it starts a new conversation with the steps written out — sending it is your call.",+ /** The prompt's first line; `version` is the release the run was fetching (null when the backend named none). */+ troubleshootPromptLead: (version: string | null) =>+ "The automatic Adelie update failed: it could not reach GitHub to download the installer. Please diagnose this host's network and get the new version installed if you can.\n" ++ `Target release: ${+ version !== null+ ? `v${version}`+ : "unknown — check https://github.com/lmliheng/Adelie/releases/latest first"+ }`,+ /** The failed run's own text, quoted into the prompt under this label. */+ troubleshootPromptClip: (output: string) => `The failed run's output:\n${output}`,+ /** The fixed instruction tail: what to diagnose, where the assets live, and what not to touch. */+ troubleshootPromptTail: (version: string | null) =>+ [+ "Work through this in order and report honestly what each step did:",+ "1. Find where the connection dies: use curl to probe this host's reach to GitHub (https://api.github.com/repos/lmliheng/Adelie/releases/latest and https://github.com), and say whether DNS, a proxy or TLS is what fails — with the commands and their raw output.",+ "2. Fetch the assets over a route that works:",+ ` https://github.com/lmliheng/Adelie/releases/download/${+ version !== null ? `v${version}` : "<tag>"+ }/`,+ " holds install.sh, the per-platform bundles (penguin-linux-x64.tar.gz and friends) and a .sha256 for each. If the direct route is blocked, go through a mirror you can reach (a prefix in front of github.com) and download into a temporary directory.",+ "3. Verify the bundle's sha256 against its .sha256 file, then install with the downloaded install.sh into the existing install directory (~/.adelie by default, or whatever PENGUIN_INSTALL_DIR names) and confirm with penguin --version.",+ "4. Do not touch the data directory ~/.adelie/data: the installer replaces only bin/lib/web/node.",+ "5. Write the conclusion: what was unreachable, which route worked, which version got installed — and if it did not work, exactly where it stopped and what is missing.",+ ].join("\n"),/** Why this install cannot update itself. */unsupportedDev: "A dev run does not update itself",unsupportedNonAppImage:diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex aff530cb..0a9c47b8 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -1083,6 +1083,39 @@ export const zh = {restartingBodyClient: "应用即将重启。",failed: "更新失败",retry: "重试",+ /**+ * The escape hatch on a download that could not reach GitHub (lib/update-troubleshoot.ts):+ * some hosts cannot get to GitHub at all, and no retry from that host changes it. The button+ * opens a new chat with the prompt below; the hint says what it costs before it is pressed,+ * because the model call is the user's own.+ */+ troubleshootAction: "让 Adelie 排查并下载",+ troubleshootHint:+ "需要先在「模型」页配好一个模型:这次排查由它完成,并按用量产生调用开销。点开会新建一个对话并写好排查步骤,是否发送由你决定。",+ /** The prompt's first line; `version` is the release the run was fetching (null when the backend named none). */+ troubleshootPromptLead: (version: string | null) =>+ "自动更新 Adelie 失败:下载 GitHub 上的安装包时没能连上。请排查这台主机的网络,并尽量把新版本装好。\n" ++ `目标版本:${+ version !== null+ ? `v${version}`+ : "不确定,请先查 https://github.com/lmliheng/Adelie/releases/latest 再看"+ }`,+ /** The failed run's own text, quoted into the prompt under this label. */+ troubleshootPromptClip: (output: string) => `失败输出:\n${output}`,+ /** The fixed instruction tail: what to diagnose, where the assets live, and what not to touch. */+ troubleshootPromptTail: (version: string | null) =>+ [+ "请按顺序做完,并如实报告每一步的结果:",+ "1. 先定位断在哪一步:用 curl 查本机到 GitHub 的连通性(https://api.github.com/repos/lmliheng/Adelie/releases/latest 和 https://github.com),看 DNS、代理、TLS 分别成不成,把命令与原始输出列出来。",+ "2. 换一条能走通的通路把资产取回来:",+ ` https://github.com/lmliheng/Adelie/releases/download/${+ version !== null ? `v${version}` : "<版本 tag>"+ }/`,+ " 下有 install.sh、各平台安装包(形如 penguin-linux-x64.tar.gz)与各自的 .sha256,直连不通时可借道可用镜像(给 github.com 加镜像前缀),下载到临时目录。",+ "3. 校验安装包的 sha256 与 .sha256 文件一致后,用下载下来的 install.sh 装到现有安装目录(默认 ~/.adelie,或 PENGUIN_INSTALL_DIR 指向的目录),装完用 penguin --version 确认。",+ "4. 数据目录 ~/.adelie/data 不要动:安装器只替换 bin/lib/web/node。",+ "5. 结论写清楚:哪里不通、走了哪条通路、装成了哪个版本;没成功就说明卡在哪一步、还差什么。",+ ].join("\n"),/** Why this install cannot update itself. */unsupportedDev: "开发运行不支持自更新",unsupportedNonAppImage: "Linux 上只有 AppImage 版本支持自更新——包安装请通过包管理器更新",diff --git a/packages/web/src/lib/update-flow.ts b/packages/web/src/lib/update-flow.tsindex 8ab72fdd..de0da8b9 100644--- a/packages/web/src/lib/update-flow.ts+++ b/packages/web/src/lib/update-flow.ts@@ -63,8 +63,18 @@ export type UpdateFlow =/** Downloaded (client) or installed (release): a restart runs it. `manual` = nothing can restart this process; the user does it by hand. */| { kind: "ready"; version: string | null; restart: "auto" | "manual" }| { kind: "restarting"; version: string | null }- /** `detail` is the backend's own text (the update command's output tail); `retry` names the step that failed. */- | { kind: "error"; message: string | null; detail: string | null; retry: "check" | "download" }+ /**+ * `detail` is the backend's own text (the update command's output tail); `retry` names the step+ * that failed. `version` is the release the failed run was fetching — named by whatever the step+ * failed on, null when nothing did (the hand-off prompt quotes it; see update-troubleshoot.ts).+ */+ | {+ kind: "error";+ message: string | null;+ detail: string | null;+ retry: "check" | "download";+ version: string | null;+ }| { kind: "unsupported"; reason: UpdateUnsupported };/** What the page itself has in flight, beside the backend snapshots. */@@ -135,6 +145,9 @@ export function releaseFlow(i: ReleaseInputs, local: FlowLocal): UpdateFlow {message: null,detail: result.output === "" ? null : result.output,retry: "download",+ // The run the job was carrying out; the offered release is the fallback for a job whose+ // target was never named.+ version: i.job?.targetVersion ?? offered,};}if (local.checking) return { kind: "checking" };@@ -144,7 +157,7 @@ export function releaseFlow(i: ReleaseInputs, local: FlowLocal): UpdateFlow {case "disabled":return { kind: "disabled" };case "failed":- return { kind: "error", message: null, detail: null, retry: "check" };+ return { kind: "error", message: null, detail: null, retry: "check", version: null };case "found":return {kind: "available",@@ -199,7 +212,15 @@ export function clientFlow(status: DesktopUpdateStatus | null, local: FlowLocal)case "error":return local.checking? { kind: "checking" }- : { kind: "error", message: status.message ?? null, detail: null, retry: "check" };+ : {+ kind: "error",+ message: status.message ?? null,+ detail: null,+ retry: "check",+ // The shell carries the version of the release it was working on, whether the failed+ // step was the lookup or the download.+ version: status.version ?? null,+ };default:return local.checking ? { kind: "checking" } : { kind: "unknown" };}diff --git a/packages/web/src/lib/update-troubleshoot.ts b/packages/web/src/lib/update-troubleshoot.tsnew file mode 100644index 00000000..e7ce6156--- /dev/null+++ b/packages/web/src/lib/update-troubleshoot.ts@@ -0,0 +1,96 @@+/**+ * The escape hatch on a download that could not reach GitHub: hand the run to an Agent.+ *+ * Retrying is the whole answer for a flaky moment, and the update modal offers it. It is no+ * answer at all for a host that cannot get to GitHub — a blocked or proxied network, a DNS that+ * answers with a captive portal — where the same request from the same host fails the same way+ * every time, and the user is left reading the Releases page in a browser that cannot open it+ * either. An Agent can do what the updater cannot: probe where the connection dies, fetch the+ * release through whatever route its own tools reach, verify it against the published checksum+ * and install it.+ *+ * What that costs is why the modal says so before the button is pressed: the diagnosis runs on a+ * model the user configured, and the calls are billed like any other. Nothing is submitted from+ * here either — the prompt is written into a new chat's draft (the AI bridge), and sending it+ * stays the user's own action.+ */+import { S } from "./strings";+import { stripAnsi } from "./strip-ansi";+import type { UpdateFlow } from "./update-flow";++/** A failed run, as the flow carries it (either backend). */+export type UpdateFailure = Extract<UpdateFlow, { kind: "error" }>;++/**+ * What "this host cannot reach GitHub" looks like in each backend's own words.+ *+ * - The CLI's fragments are its English i18n strings (`packages/cli/src/i18n.ts`, `update.*`):+ * `services/update-job.ts` spawns it with ADELIE_LANG=en, and this web UI ships in the same+ * install, so the strings can never come from a different release than this code.+ * - curl's own errno text rides along in the run's output tail, and is the most direct evidence+ * of where the connection stopped.+ * - The desktop shell reports its updater's message instead (`packages/desktop/src/updater.ts`,+ * `Could not download the update.`), with Electron's net error inside it.+ *+ * Matched case-insensitively against message and output tail together. A failure none of these+ * describe (a bad signature, a refused install, an admin-only refusal) gets no offer: it is not+ * something a network diagnosis would fix.+ */+export const UNREACHABLE_MARKERS = [+ "could not download the installer from",+ "could not reach ",+ "check your network and retry.",+ // The release lookup answered with something that was not GitHub's API — a captive portal or a+ // proxy interstitial, which is exactly the host that needs the hand-off.+ "lookup returned an unexpected response",+ "could not resolve host",+ "failed to connect to",+ "connection timed out",+ "operation timed out",+ "ssl connect error",+ "socket hang up",+ "could not download the update.",+ "net::err_",+ "err_connection",+ "err_timed_out",+ "err_internet_disconnected",+ "etimedout",+ "enotfound",+];++/**+ * How much of the run's output is quoted into the prompt. The job keeps a 64KB tail; the failure+ * is its last lines, and the composer is not a log viewer — the Agent can re-run the command+ * itself, so a truncated quote is information, not a loss. Only the end is kept (that is where+ * the CLI prints why it gave up) and the cut is marked.+ */+export const PROMPT_OUTPUT_MAX = 2000;++/** Whether this failure is the host being unable to reach GitHub (see UNREACHABLE_MARKERS). */+export function unreachableDownload(failure: UpdateFailure): boolean {+ const text = `${failure.message ?? ""}\n${failure.detail ?? ""}`.toLowerCase();+ return UNREACHABLE_MARKERS.some((marker) => text.includes(marker));+}++/** The run's own text for the prompt: ANSI stripped (the job's output may be coloured), tail kept, cut marked. */+function quoteOutput(failure: UpdateFailure): string {+ const text = stripAnsi(failure.detail ?? failure.message ?? "").trim();+ if (text.length <= PROMPT_OUTPUT_MAX) return text;+ return `…\n${text.slice(text.length - PROMPT_OUTPUT_MAX)}`;+}++/**+ * The prompt the chat is prefilled with: what failed and against which release, the run's own+ * output, then the fixed steps (`S.update.troubleshootPrompt*` — what to diagnose, where the+ * assets live, what not to touch).+ */+export function buildUpdateTroubleshootPrompt(failure: UpdateFailure): string {+ const output = quoteOutput(failure);+ return [+ S.update.troubleshootPromptLead(failure.version),+ output === "" ? "" : S.update.troubleshootPromptClip(output),+ S.update.troubleshootPromptTail(failure.version),+ ]+ .filter((part) => part !== "")+ .join("\n\n");+}diff --git a/packages/web/test/update-badges.test.ts b/packages/web/test/update-badges.test.tsindex c55cdeb6..941dee98 100644--- a/packages/web/test/update-badges.test.ts+++ b/packages/web/test/update-badges.test.ts@@ -44,7 +44,7 @@ describe("softwareUpdate", () => {expect(softwareUpdate({ kind: "up-to-date", version: "0.2.9" })).toBeNull();expect(softwareUpdate({ kind: "disabled" })).toBeNull();expect(- softwareUpdate({ kind: "error", message: null, detail: null, retry: "check" }),+ softwareUpdate({ kind: "error", message: null, detail: null, retry: "check", version: null }),).toBeNull();expect(softwareUpdate({ kind: "unsupported", reason: { code: "dev" } })).toBeNull();expect(softwareUpdate({ kind: "restarting", version: "0.3.0" })).toBeNull();diff --git a/packages/web/test/update-flow.test.ts b/packages/web/test/update-flow.test.tsindex 9ee6c713..3f5ef1b1 100644--- a/packages/web/test/update-flow.test.ts+++ b/packages/web/test/update-flow.test.ts@@ -145,6 +145,8 @@ describe("releaseFlow (an ordinary server)", () => {message: null,detail: "Upgrade failed; the previous install was left in place.",retry: "download",+ // The release the run was fetching — the hand-off prompt quotes it (update-troubleshoot.ts).+ version: "0.3.0",});});@@ -216,11 +218,14 @@ describe("clientFlow (the desktop shell's own window)", () => {});it("carries the shell's own failure text, and names why a form cannot update itself", () => {- expect(clientFlow(shell({ state: "error", message: "sha512 mismatch" }), NO_LOCAL)).toEqual({+ expect(+ clientFlow(shell({ state: "error", message: "sha512 mismatch", version: "0.3.0" }), NO_LOCAL),+ ).toEqual({kind: "error",message: "sha512 mismatch",detail: null,retry: "check",+ version: "0.3.0",});expect(clientFlow(shell({ state: "unsupported", reason: "linux-not-appimage" }), NO_LOCAL),@@ -236,9 +241,9 @@ describe("opensWithCheck", () => {it("checks on opening when nothing is known, the answer is 'current', or the last check failed", () => {expect(opensWithCheck({ kind: "unknown" })).toBe(true);expect(opensWithCheck({ kind: "up-to-date", version: "0.2.9" })).toBe(true);- expect(opensWithCheck({ kind: "error", message: null, detail: null, retry: "check" })).toBe(- true,- );+ expect(+ opensWithCheck({ kind: "error", message: null, detail: null, retry: "check", version: null }),+ ).toBe(true);});it("does not disturb an offer, a download, a ready build, or a failed download", () => {@@ -249,9 +254,15 @@ describe("opensWithCheck", () => {opensWithCheck({ kind: "downloading", version: "0.3.0", percent: 10, phase: null }),).toBe(false);expect(opensWithCheck({ kind: "ready", version: "0.3.0", restart: "auto" })).toBe(false);- expect(opensWithCheck({ kind: "error", message: null, detail: "x", retry: "download" })).toBe(- false,- );+ expect(+ opensWithCheck({+ kind: "error",+ message: null,+ detail: "x",+ retry: "download",+ version: "0.3.0",+ }),+ ).toBe(false);});});diff --git a/packages/web/test/update-troubleshoot.test.ts b/packages/web/test/update-troubleshoot.test.tsnew file mode 100644index 00000000..2709c02d--- /dev/null+++ b/packages/web/test/update-troubleshoot.test.ts@@ -0,0 +1,142 @@+/**+ * update-troubleshoot.ts: which update failures get the hand-off to an Agent, and what the+ * prompt it writes into the chat says.+ *+ * What matters to a user: the offer appears for a host that cannot reach GitHub (and not for a+ * failure a network diagnosis would not fix), the prompt names the release and quotes the run's+ * own output rather than paraphrasing it, and it carries the steps — diagnose, fetch over a+ * route that works, verify, install, leave the data directory alone — in whichever language is+ * active.+ */+import { afterEach, describe, expect, it } from "vitest";+import { S, setActiveStrings, zh } from "../src/lib/strings";+import { en } from "../src/lib/strings-en";+import {+ PROMPT_OUTPUT_MAX,+ buildUpdateTroubleshootPrompt,+ unreachableDownload,+} from "../src/lib/update-troubleshoot";+import type { UpdateFailure } from "../src/lib/update-troubleshoot";++afterEach(() => setActiveStrings(zh));++const failure = (over: Partial<UpdateFailure> = {}): UpdateFailure => ({+ kind: "error",+ message: null,+ detail: null,+ retry: "download",+ version: "0.5.8",+ ...over,+});++describe("unreachableDownload", () => {+ it("recognizes the CLI giving up on the download", () => {+ expect(+ unreachableDownload(+ failure({+ detail:+ "Downloading penguin-linux-x64.tar.gz from GitHub ...\n" ++ "curl: (7) Failed to connect to github.com port 443 after 21075 ms: Couldn't connect to server\n" ++ "Could not download the installer from GitHub. Check your network and retry.",+ }),+ ),+ ).toBe(true);+ });++ it("recognizes the shell's own updater failure", () => {+ expect(+ unreachableDownload(failure({ message: "Could not download the update.", retry: "check" })),+ ).toBe(true);+ expect(+ unreachableDownload(failure({ message: "net::ERR_CONNECTION_TIMED_OUT", retry: "download" })),+ ).toBe(true);+ });++ it("recognizes a lookup answered by something that was not GitHub", () => {+ expect(+ unreachableDownload(+ failure({+ retry: "check",+ detail:+ "The GitHub release lookup returned an unexpected response with no usable version tag.",+ }),+ ),+ ).toBe(true);+ });++ it("stays quiet for failures no network diagnosis would fix", () => {+ // A downloaded bundle that failed its checksum, a refused layout, a failed check with nothing+ // to hand over, and the CLI's Windows refusal.+ expect(unreachableDownload(failure({ message: "sha512 mismatch" }))).toBe(false);+ expect(+ unreachableDownload(+ failure({ detail: "Cannot tell how this penguin was installed (running from /x)..." }),+ ),+ ).toBe(false);+ expect(unreachableDownload(failure({ retry: "check" }))).toBe(false);+ expect(unreachableDownload(failure({ message: "Could not check for updates." }))).toBe(false);+ expect(+ unreachableDownload(+ failure({ detail: "The official installer is a POSIX shell script and does not run" }),+ ),+ ).toBe(false);+ });+});++describe("buildUpdateTroubleshootPrompt", () => {+ it("names the release, quotes the run's output, and ends with the steps", () => {+ const output = "curl: (6) Could not resolve host: github.com";+ const prompt = buildUpdateTroubleshootPrompt(failure({ detail: output }));+ expect(prompt).toContain(S.update.troubleshootPromptLead("0.5.8"));+ expect(prompt).toContain(S.update.troubleshootPromptClip(output));+ expect(prompt.endsWith(S.update.troubleshootPromptTail("0.5.8"))).toBe(true);+ // The steps carry the release's own download directory, so the Agent does not have to guess it.+ expect(prompt).toContain("/releases/download/v0.5.8/");+ // And the one thing it must not touch.+ expect(prompt).toContain("~/.adelie/data");+ });++ it("falls back to the shell's message when there is no output tail", () => {+ const prompt = buildUpdateTroubleshootPrompt(+ failure({ message: "Could not download the update.", retry: "check" }),+ );+ // The shell reports one sentence and no output; that sentence is what gets quoted.+ expect(prompt).toContain(S.update.troubleshootPromptClip("Could not download the update."));+ expect(prompt.startsWith(S.update.troubleshootPromptLead("0.5.8"))).toBe(true);+ });++ it("leaves the output block out entirely when neither backend named anything", () => {+ const prompt = buildUpdateTroubleshootPrompt(failure());+ expect(prompt).toBe(+ `${S.update.troubleshootPromptLead("0.5.8")}\n\n${S.update.troubleshootPromptTail("0.5.8")}`,+ );+ });++ it("asks for the latest release when the backend named no version", () => {+ const prompt = buildUpdateTroubleshootPrompt(failure({ version: null, detail: "x" }));+ expect(prompt).toContain(S.update.troubleshootPromptLead(null));+ expect(prompt).toContain(S.update.troubleshootPromptTail(null));+ expect(prompt).not.toContain("/releases/download/v");+ });++ it("strips the job's colour and keeps the end of an over-long output, marked as cut", () => {+ const long = `\u001b[36m${"x".repeat(PROMPT_OUTPUT_MAX + 500)}\u001b[0m at the end`;+ const prompt = buildUpdateTroubleshootPrompt(failure({ detail: long }));+ expect(prompt).not.toContain("\u001b");+ // The head is dropped (the CLI prints why it gave up last) and the cut is visible.+ expect(prompt).not.toContain("x".repeat(PROMPT_OUTPUT_MAX + 1));+ expect(prompt).toContain("…");+ expect(prompt).toContain("at the end");+ });++ it("follows the active dictionary", () => {+ for (const dict of [en, zh]) {+ setActiveStrings(dict);+ expect(buildUpdateTroubleshootPrompt(failure({ detail: "boom" }))).toBe(+ `${dict.update.troubleshootPromptLead("0.5.8")}\n\n${dict.update.troubleshootPromptClip(+ "boom",+ )}\n\n${dict.update.troubleshootPromptTail("0.5.8")}`,+ );+ }+ });+});