Adds packages/atomcode (@magpie-community/opencode-atomcode-auth 0.3.0), an AtomGit CodingPlan provider: browser OAuth and AtomCode CLI sign-in (~/.atomcode/auth.toml), signed requests to AtomGit's own gateway, per-account models and quota, daily claim, a loopback-only diagnostics page, and OpenCode 1.x/2.x entries. Registry and README entries added. By LILEOO.
Reviewed at c57b099fff4689c0198c1c6414f04b27614b4092. The last blocking point (an inline TOML comment on a known line went into the uid and was written back) is fixed: values end at an unquoted #, quoted/escaped/literal strings keep their #, and a rewritten line keeps its comment.
Run on a separate test machine (Bun 1.4.2, sandbox HOME):
- PR head merged onto origin/main 24da52b8: bun scripts/check.mjs exit 0 (atomcode ok); whole-repo bun test 6103 pass, 0 fail. origin/main alone: 5942 pass, 0 fail.
- packages/atomcode at the head: bun test 161 pass; node --test test/*.test.mjs 161 pass.
- The new auth-file test against 55ff272's auth-file.mjs: red (1 fail), green at the head.
- Probe: the review's file (id = "123456" # c) parses to uid 123456 and renders back as id = "123456" # c; also #c with no space, CRLF with a tab before #, "1#2", and a literal-string id all round-trip to the same uid. At 55ff272 each gave a uid with the comment in it.
Not tried: a real AtomGit account. A [user] header with a trailing comment is refused ("no user id"), not corrupted; the CLI never writes one. First npm version needs an owner publish; until then magpie installs it from the dist branch.
61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
// Magpie settings pages cannot fetch (`connect-src 'none'`). This bridge page
|
|
// therefore only carries theme/options to the loopback diagnostics page.
|
|
(async () => {
|
|
const fallbackPort = 3478;
|
|
const said = document.getElementById("said");
|
|
let port = fallbackPort;
|
|
let theme = "";
|
|
let lang = "";
|
|
let tokens = null;
|
|
let service = "";
|
|
|
|
try {
|
|
const ready = await window.magpie?.ready;
|
|
if (typeof ready?.dark === "boolean") theme = ready.dark ? "dark" : "light";
|
|
if (typeof ready?.lang === "string") lang = ready.lang;
|
|
if (ready?.tokens && typeof ready.tokens === "object") tokens = ready.tokens;
|
|
} catch {}
|
|
try {
|
|
if (typeof window.magpie?.service === "string") service = window.magpie.service;
|
|
} catch {}
|
|
try {
|
|
const options = await window.magpie?.options?.get?.();
|
|
const configured = Number(options?.diagnosticsPort);
|
|
if (Number.isInteger(configured) && configured >= 1024 && configured <= 65535) {
|
|
port = configured;
|
|
}
|
|
} catch {}
|
|
|
|
const query = new URLSearchParams();
|
|
if (theme) query.set("theme", theme);
|
|
if (lang) query.set("lang", lang);
|
|
const slim = {};
|
|
for (const [key, value] of Object.entries(tokens || {})) {
|
|
const text = String(value ?? "").trim();
|
|
if (text) slim[key] = text;
|
|
}
|
|
if (Object.keys(slim).length) {
|
|
try {
|
|
query.set("tokens", btoa(unescape(encodeURIComponent(JSON.stringify(slim)))));
|
|
} catch {}
|
|
}
|
|
|
|
const suffix = query.toString();
|
|
if (service) {
|
|
location.replace(service + (suffix ? "?" + suffix : ""));
|
|
return;
|
|
}
|
|
|
|
const target = "http://127.0.0.1:" + port + "/" + (suffix ? "?" + suffix : "");
|
|
const loopback = /^(?:127(?:\.\d+){3}|localhost|\[::1\])$/i.test(location.hostname);
|
|
if (!loopback && location.protocol !== "file:") {
|
|
if (said) {
|
|
said.textContent =
|
|
"诊断服务只监听运行 magpie 的电脑。请在这台电脑上使用 SSH 端口转发:" +
|
|
"ssh -N -L " + port + ":127.0.0.1:" + port + " <user>@" + location.hostname;
|
|
}
|
|
return;
|
|
}
|
|
location.replace(target);
|
|
})();
|