diff --git a/internal/gui/api.go b/internal/gui/api.go index ffdb6ae85..627e0a83e 100644 --- a/internal/gui/api.go +++ b/internal/gui/api.go @@ -1135,6 +1135,7 @@ func Handler(w Windows, gw *gateway.Server) http.Handler { mux.Handle("/", devPage(revalidated(http.FileServer(http.FS(staticFS()))))) devRoutes(mux) pluginPageRoutes(mux, isWeb(w)) + feedbackRoutes(mux) // boot.js hands the page the saved language and theme before it paints: // they came only with the settings, so the tabs showed English first mux.HandleFunc("GET /boot.js", func(rw http.ResponseWriter, r *http.Request) { diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index dc8593e05..64d2b8108 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -20194,6 +20194,16 @@ function renderSettings() { repo.title = "github.com/yetone/magpie"; repo.onclick = () => api("open", { url: "https://github.com/yetone/magpie" }).catch(() => {}); row(t("Community"), t("questions, ideas and feedback, on Discord or GitHub"), "", join, repo); + // the facts that help a fix, copied (never put in the link), then the + // feedback post on X, to reply to there (River_WLan on X) + const report = el("button", "text", t("Open")); + report.onclick = async () => { + const f = await fetch("/api/feedback?surface=" + (web ? "browser" : "app")).then((r) => r.ok ? r.json() : null).catch(() => null); + if (!f) return status(t("Couldn't read the details to copy"), "err"); + await copy(f.text, "", report, t("Details copied. Paste them in your reply")); + api("open", { url: f.url }).catch(statusErr); + }; + row(t("Report a problem"), "", "", report); // magpie uninstall, from the app (Jevik_AI on X deleted magpie's folders // by hand and Codex kept pointing at a gateway that was gone). Never in a // browser: magpie web would be taken off the computer serving the page. diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 303df34cb..09003ec17 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -3380,6 +3380,7 @@ const I18N = { "Library brought in and written into the agents": "资源库已导入,并已写入各 agent", "{agent} couldn't get {what}: {error}": "{agent} 未能写入 {what}:{error}", "Website": "官网", "Open-source licenses": "开源许可", "the notices of the code and data magpie is built with": "magpie 所用代码和数据的许可声明", "downloads, docs and what's new": "下载、文档和更新内容", "Community": "社区", "questions, ideas and feedback, on Discord or GitHub": "提问、想法和反馈,Discord 或 GitHub 都可以", "Join Discord": "加入 Discord", + "Report a problem": "反馈问题", "Couldn't read the details to copy": "无法读取要复制的信息", "Details copied. Paste them in your reply": "信息已复制,请粘贴到你的回复里", "Copy": "复制", "Copied": "已复制", "Region": "区域", @@ -8501,6 +8502,7 @@ const I18N = { "Website": "官網", "Open-source licenses": "開源授權", "the notices of the code and data magpie is built with": "magpie 所用程式碼和資料的授權聲明", "downloads, docs and what's new": "下載、文件和更新內容", "Community": "社群", "questions, ideas and feedback, on Discord or GitHub": "提問、想法和反饋,Discord 或 GitHub 都可以", "Join Discord": "加入 Discord", + "Report a problem": "回報問題", "Couldn't read the details to copy": "無法讀取要複製的資訊", "Details copied. Paste them in your reply": "資訊已複製,請貼到你的回覆裡", "Copy": "複製", "Copied": "已複製", "Region": "區域", @@ -13623,6 +13625,7 @@ const I18N = { "Website": "公式サイト", "Open-source licenses": "オープンソースライセンス", "the notices of the code and data magpie is built with": "magpie が使用するコードとデータのライセンス表記", "downloads, docs and what's new": "ダウンロード、ドキュメント、更新内容", "Community": "コミュニティ", "questions, ideas and feedback, on Discord or GitHub": "質問、アイデア、フィードバックは Discord または GitHub で", "Join Discord": "Discord に参加", + "Report a problem": "問題を報告", "Couldn't read the details to copy": "コピーする情報を読み込めませんでした", "Details copied. Paste them in your reply": "情報をコピーしました。返信に貼り付けてください", "Copy": "コピー", "Copied": "コピーしました", "Region": "リージョン", @@ -18754,6 +18757,7 @@ const I18N = { "Website": "Website", "Open-source licenses": "Open-Source-Lizenzen", "the notices of the code and data magpie is built with": "die Lizenzhinweise des Codes und der Daten, mit denen magpie gebaut ist", "downloads, docs and what's new": "Downloads, Dokumentation und Neuigkeiten", "Community": "Community", "questions, ideas and feedback, on Discord or GitHub": "Fragen, Ideen und Feedback auf Discord oder GitHub", "Join Discord": "Discord beitreten", + "Report a problem": "Problem melden", "Couldn't read the details to copy": "Die Angaben zum Kopieren konnten nicht gelesen werden", "Details copied. Paste them in your reply": "Angaben kopiert. Fügen Sie sie in Ihre Antwort ein", "Copy": "Kopieren", "Copied": "Kopiert", "Region": "Region", diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.go index c3a1677d6..dc574effb 100644 --- a/internal/gui/core_budget_test.go +++ b/internal/gui/core_budget_test.go @@ -18,7 +18,7 @@ import ( // `git log -L` of this file. const ( appScriptBudget = 1_086_267 // app.js: 1,080,614 at 8016205e3, with the 5,653 of room it had - coreScriptBudget = 1_263_851 // every core script at 8016205e3, the old measure 682 over its cap there (#5918); +367 for the model test on a chosen account (tmr11235), no page left to move it to; +151 for the provider menu's "Only on this device" item and its four translations + coreScriptBudget = 1_264_309 // every core script at 8016205e3, the old measure 682 over its cap there (#5918); +367 for the model test on a chosen account (tmr11235), no page left to move it to; +151 for the provider menu's "Only on this device" item and its four translations; +458 for Settings › About's Report a problem row and its translations ) // codeBytes is how many bytes of b are code: its blank lines, its lines diff --git a/internal/gui/feedback.go b/internal/gui/feedback.go new file mode 100644 index 000000000..e4d0b29f9 --- /dev/null +++ b/internal/gui/feedback.go @@ -0,0 +1,74 @@ +package gui + +import ( + "context" + "net/http" + "os" + "regexp" + "runtime" + "strings" + "time" + + "github.com/yetone/magpie/internal/proc" +) + +// FeedbackURL is the post on X where users reply with feedback; Settings › +// About's Report a problem opens it after copying the facts below. +const FeedbackURL = "https://x.com/magpie_router/status/2119861020978188499" + +var osVersionRE = regexp.MustCompile(`\d+(\.\d+)+`) + +// osVersion names the system and its version: "macOS 26.2", "Windows +// 10.0.26100", "Ubuntu 24.04.1 LTS". Only what the system calls itself: +// no host, user or path. +func osVersion() string { + run := func(name string, args ...string) string { + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + out, _ := proc.CommandContext(ctx, name, args...).Output() + return osVersionRE.FindString(string(out)) + } + switch runtime.GOOS { + case "darwin": + return strings.TrimSpace("macOS " + run("/usr/bin/sw_vers", "-productVersion")) + case "windows": + v := run("cmd", "/c", "ver") // "Microsoft Windows [Version 10.0.26100.4652]" + if parts := strings.Split(v, "."); len(parts) > 3 { + v = strings.Join(parts[:3], ".") + } + return strings.TrimSpace("Windows " + v) + } + if b, err := os.ReadFile("/etc/os-release"); err == nil { + for _, l := range strings.Split(string(b), "\n") { + if v, ok := strings.CutPrefix(l, "PRETTY_NAME="); ok { + if v = strings.Trim(strings.TrimSpace(v), `"'`); v != "" { + return v + } + } + } + } + return "Linux" +} + +// diagnostics is the block a report starts with. It holds the version, the +// system, the architecture and where magpie is open, and never an account, +// a key, a path or a user name: the user pastes it into a public reply. +func diagnostics(surface string) string { + if surface != "browser" { + surface = "app" + } + return strings.Join([]string{ + "magpie " + Version, + "OS: " + osVersion(), + "Arch: " + runtime.GOARCH, + "Opened in: " + surface, + }, "\n") +} + +// feedbackRoutes serves the facts to copy and the post to open, from +// Settings › About. The block goes to the clipboard, never into a link. +func feedbackRoutes(mux *http.ServeMux) { + mux.HandleFunc("GET /api/feedback", func(rw http.ResponseWriter, r *http.Request) { + writeJSON(rw, map[string]string{"text": diagnostics(r.URL.Query().Get("surface")), "url": FeedbackURL}) + }) +} diff --git a/internal/gui/feedback_test.go b/internal/gui/feedback_test.go new file mode 100644 index 000000000..8249fcc37 --- /dev/null +++ b/internal/gui/feedback_test.go @@ -0,0 +1,49 @@ +package gui + +import ( + "encoding/json" + "net/http/httptest" + "os" + "runtime" + "strings" + "testing" +) + +// Report a problem copies the version, the system, the architecture and +// where magpie is open, and nothing that names the user: no home folder, +// user name or host. The post it opens carries no part of it in its link +// (River_WLan on X). +func TestFeedbackBlockHoldsNoPrivateFacts(t *testing.T) { + sandboxHome(t) + rec := httptest.NewRecorder() + webPageHandler(t, webHost{}, nil).ServeHTTP(rec, httptest.NewRequest("GET", "/api/feedback?surface=browser", nil)) + var got struct{ Text, URL string } + if rec.Code != 200 || json.Unmarshal(rec.Body.Bytes(), &got) != nil { + t.Fatalf("feedback: %d %s", rec.Code, rec.Body) + } + for _, want := range []string{"magpie " + Version, "OS: ", "Arch: " + runtime.GOARCH, "Opened in: browser"} { + if !strings.Contains(got.Text, want) { + t.Errorf("block lacks %q:\n%s", want, got.Text) + } + } + if got.URL != FeedbackURL || strings.ContainsAny(got.URL, "?#") { + t.Errorf("post link %q carries something", got.URL) + } + home, _ := os.UserHomeDir() + host, _ := os.Hostname() + for _, secret := range []string{home, host, os.Getenv("USER"), os.Getenv("USERNAME")} { + if secret != "" && strings.Contains(got.Text, secret) { + t.Errorf("block holds %q:\n%s", secret, got.Text) + } + } + if strings.Contains(osVersion(), "\n") || osVersion() == "" { + t.Errorf("os version %q", osVersion()) + } + if runtime.GOOS == "darwin" && !osVersionRE.MatchString(osVersion()) { + t.Errorf("macOS without its version, as a window launched from Finder has it: %q", osVersion()) + } + // anything but browser is the app's window + if !strings.Contains(diagnostics("../x"), "Opened in: app") { + t.Error("an unknown surface is not the app") + } +} diff --git a/internal/gui/tests/about-report.test.cjs b/internal/gui/tests/about-report.test.cjs new file mode 100644 index 000000000..4bddbf5ad --- /dev/null +++ b/internal/gui/tests/about-report.test.cjs @@ -0,0 +1,51 @@ +const assert = require("node:assert/strict"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); +const { fixture } = require("./fixtures/caller-keys.cjs"); +const { openPart } = require("./reader.cjs"); + +// Settings › About's Report a problem copies the version, the system and +// the architecture, says so, then opens the feedback post on X. What it +// copied is never in the link (River_WLan on X). +const words = { + en: ["Report a problem", "Details copied. Paste them in your reply"], + zh: ["反馈问题", "信息已复制,请粘贴到你的回复里"], + "zh-TW": ["回報問題", "資訊已複製,請貼到你的回覆裡"], + ja: ["問題を報告", "情報をコピーしました。返信に貼り付けてください"], + de: ["Problem melden", "Angaben kopiert. Fügen Sie sie in Ihre Antwort ein"], +}; +const block = "magpie 0.1.9\nOS: macOS 26.2\nArch: arm64\nOpened in: app"; +const post = "https://x.com/magpie_router/status/2119861020978188499"; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of Object.keys(words)) { + for (const width of [1100, 420]) { + test(`${engine} ${lang} ${width}: About reports a problem`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(6000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + const events = []; + await page.route("**/*", fixture(lang, "light", events)); + await page.route("**/api/feedback*", (r) => r.fulfill({ json: { text: block, url: post } })); + await page.route("**/api/open", (r) => { events.push({ action: "open", body: r.request().postDataJSON() }); return r.fulfill({ status: 204 }); }); + await page.goto("http://magpie.test/"); + await page.locator("#prefs").click(); + await openPart(page, "about"); + const row = page.locator("#about .row", { has: page.locator(".who", { hasText: words[lang][0] }) }); + await row.waitFor(); + await row.locator("button.text").click(); + await page.locator("#status", { hasText: words[lang][1] }).waitFor(); + assert.equal(events.find((e) => e.action === "clipboard").body.text, block); + const opened = events.find((e) => e.action === "open"); + assert.equal(opened.body.url, post); + assert.equal(opened.body.url.includes(encodeURIComponent("magpie 0.1.9")), false); + assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "About wider than the window"); + assert.deepEqual(errors, []); + }); + } + } +}