From 4503fcf0fce59c5d635d7aa02f4cc652e0ba175c Mon Sep 17 00:00:00 2001 From: RemilioNubilio <275382225+RemilioNubilio@users.noreply.github.com> Date: Wed, 2 Sep 2026 16:49:16 -0400 Subject: [PATCH 01/12] Custom engine (issue #209): OpenAI-compatible endpoints through the Codex provider passthrough Ported onto main after #218 and the engineBin refactor: the registry's binary lookup goes through engineBin.ts (custom resolves the codex binary), customEngineStatus reuses detectCli as its binary probe, and the panel's custom tab (hidden until the host announces a saved endpoint config), engine mark and slash guards live in the panel modules with jsdom coverage; the bundle is regenerated. --- packages/core/src/account/customEngineAuth.ts | 131 +++++++++++ packages/core/src/account/customEngineMeta.ts | 10 + packages/core/src/account/sessionLog.ts | 5 +- packages/core/src/account/store.ts | 2 +- packages/core/src/chat/modelOptions.ts | 21 +- packages/core/src/chat/session.ts | 40 ++-- packages/core/src/chat/slashCommands.ts | 12 +- packages/core/src/chat/ui/panel.jsdom.spec.ts | 91 ++++++++ packages/core/src/chat/ui/panel/composer.ts | 22 +- packages/core/src/chat/ui/panel/engine.ts | 44 +++- packages/core/src/chat/ui/panel/main.ts | 15 +- packages/core/src/chat/ui/panel/paging.ts | 8 +- packages/core/src/chat/ui/panel/slash.ts | 2 + packages/core/src/chat/ui/panel/state.ts | 1 + packages/core/src/chat/ui/panel/turns.ts | 17 +- packages/core/src/chat/ui/webview.ts | 9 + packages/core/src/index.ts | 21 +- packages/core/src/runtime/approval/channel.ts | 4 +- packages/core/src/runtime/contract.ts | 11 +- .../core/src/runtime/customEngine.spec.ts | 52 +++++ packages/core/src/runtime/engineInstall.ts | 8 +- packages/core/src/runtime/engineRegistry.ts | 45 ++++ packages/core/src/runtime/index.ts | 35 ++- packages/core/src/runtime/spawn.ts | 75 ++++++- packages/core/test/fixtures/panel/contract.ts | 1 + packages/core/test/fixtures/panel/inbound.ts | 1 + surfaces/cli/src/app.tsx | 51 +++-- surfaces/cli/src/commands.ts | 2 +- surfaces/cli/src/components/Footer.tsx | 6 +- surfaces/cli/src/components/Header.tsx | 8 +- surfaces/cli/src/components/Message.tsx | 2 +- surfaces/cli/src/components/WelcomePanel.tsx | 9 +- surfaces/cli/src/hooks/useChat.ts | 23 +- surfaces/cli/src/models.ts | 10 + surfaces/cli/src/prefs.ts | 23 +- surfaces/cli/src/views/Chat.tsx | 67 ++++-- surfaces/cli/src/views/LoginGate.tsx | 206 +++++++++++++++++- surfaces/cli/src/views/ModelPicker.tsx | 3 +- surfaces/cli/src/views/Onboarding.tsx | 42 ++-- surfaces/localhost/src/index.ts | 60 ++++- surfaces/vscode/src/extension.ts | 40 +++- surfaces/webview/src/App.tsx | 6 +- surfaces/webview/src/chat/Composer.tsx | 59 +++-- surfaces/webview/src/chat/Sessions.tsx | 120 +++++++++- surfaces/webview/src/state/store.tsx | 43 +++- surfaces/webview/src/transport/protocol.ts | 16 +- 46 files changed, 1290 insertions(+), 189 deletions(-) create mode 100644 packages/core/src/account/customEngineAuth.ts create mode 100644 packages/core/src/account/customEngineMeta.ts create mode 100644 packages/core/src/runtime/customEngine.spec.ts create mode 100644 packages/core/src/runtime/engineRegistry.ts diff --git a/packages/core/src/account/customEngineAuth.ts b/packages/core/src/account/customEngineAuth.ts new file mode 100644 index 00000000..04d8780b --- /dev/null +++ b/packages/core/src/account/customEngineAuth.ts @@ -0,0 +1,131 @@ +// Custom engine config, device-local. Mirrors saveCodexApiKey: the endpoint config +// (base URL + API key + model) lives in tokens/custom-engine.json with 0o600 perms, +// per device, never synced. spawn.ts turns it into -c model_providers overrides on +// the codex binary; the key rides the CUSTOM_ENGINE_API_KEY env var, never argv. + +import { readFile, writeFile, rm } from "node:fs/promises"; +import { tokenFile, tokensDir, ensureDir } from "../core/paths.js"; +import { engineBinary } from "../runtime/engineRegistry.js"; +import { detectCli, type CliReport } from "../runtime/detect.js"; + +export interface CustomEngineConfig { + baseUrl: string; + apiKey: string; + model: string; + presetId: string; + label?: string; +} + +export interface CustomEnginePreset { + id: string; + label: string; + baseUrl: string; + defaultModel: string; +} + +// Starting points so connecting is a pick + key paste instead of a URL hunt. Only "manual" +// (a loopback endpoint) and "lmstudio" have carried a real turn; the hosted entries are the +// advertised base URLs and must speak the Responses wire to work through codex. "manual" is the escape hatch: any endpoint, all fields typed by hand. +// A defaultModel of "" does NOT mean the endpoint picks one: saveCustomEngineConfig +// rejects a blank model, so the connect form must require a model id for those presets. +export const CUSTOM_ENGINE_PRESETS: CustomEnginePreset[] = [ + { id: "deepseek", label: "DeepSeek", baseUrl: "https://api.deepseek.com/v1", defaultModel: "deepseek-chat" }, + { id: "qwen", label: "Qwen", baseUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1", defaultModel: "qwen-max" }, + { id: "glm", label: "GLM", baseUrl: "https://open.bigmodel.cn/api/paas/v4", defaultModel: "glm-4-plus" }, + { id: "kimi", label: "Kimi", baseUrl: "https://api.moonshot.cn/v1", defaultModel: "kimi-k2" }, + { id: "ollama", label: "Ollama", baseUrl: "http://localhost:11434/v1", defaultModel: "" }, + { id: "lmstudio", label: "LM Studio", baseUrl: "http://localhost:1234/v1", defaultModel: "" }, + { id: "openrouter", label: "OpenRouter", baseUrl: "https://openrouter.ai/api/v1", defaultModel: "" }, + { id: "manual", label: "Manual", baseUrl: "", defaultModel: "" }, +]; + +// Connect-UI warning copy lives in the browser-safe leaf (customEngineMeta) so the +// SPA form can import it without this file's node:fs dependency; re-exported here so +// node hosts keep one import site for everything custom-engine. +export { CUSTOM_ENGINE_EGRESS_WARNING, CUSTOM_ENGINE_TOOL_WARNING } from "./customEngineMeta.js"; + +const PROVIDER = "custom-engine"; + +// The base URL rides codex argv as a -c override, where ps can read it, so anything +// secret-shaped is stripped before it is stored: userinfo (user:pass@) and the query +// string. The trailing slash is trimmed so the same endpoint always stores one form. +function normalizeBaseUrl(raw: string): string { + let url: URL; + try { + url = new URL(raw.trim()); + } catch { + throw new Error(`The custom engine base URL is not a valid URL: ${raw.trim() || "(empty)"}`); + } + if (url.protocol !== "http:" && url.protocol !== "https:") { + throw new Error(`The custom engine base URL must be http or https, got "${url.protocol.slice(0, -1)}".`); + } + // origin + pathname drops userinfo, query, and fragment in one move. + return (url.origin + url.pathname).replace(/\/+$/, ""); +} + +export async function saveCustomEngineConfig(cfg: CustomEngineConfig): Promise { + // Reject a blank model at the door, not only at spawn (customProviderFlags), so a + // bad config never even reaches disk. + if (!cfg.model.trim()) { + throw new Error("The custom engine needs a model id; codex would otherwise silently use its own default model."); + } + const normalized: CustomEngineConfig = { ...cfg, baseUrl: normalizeBaseUrl(cfg.baseUrl), model: cfg.model.trim() }; + await ensureDir(tokensDir()); + const path = tokenFile(PROVIDER); + // Unlink before write so the new file is always created with 0o600: if the file + // already existed with looser permissions a plain writeFile would not downgrade them. + await rm(path, { force: true }); + await writeFile(path, JSON.stringify(normalized), { mode: 0o600 }); +} + +export async function loadCustomEngineConfig(): Promise { + try { + const data = JSON.parse(await readFile(tokenFile(PROVIDER), "utf8")) as CustomEngineConfig; + return data.baseUrl ? data : null; + } catch { + return null; + } +} + +export async function clearCustomEngineConfig(): Promise { + await rm(tokenFile(PROVIDER), { force: true }); +} + +export async function hasCustomEngine(): Promise { + return (await loadCustomEngineConfig()) !== null; +} + +export interface CustomEngineStatus { + binaryOk: boolean; // the codex binary (custom's passthrough) is on this machine + configured: boolean; // an endpoint config is saved + ready: boolean; // both: a custom session can actually spawn +} + +// One readiness answer for every host, instead of each surface re-deriving +// "codex present AND config saved" on its own. Pass a CliReport when one is already +// in hand; without one detectCli runs, the same probe behind every host's engine +// status line (it resolves the binary through engineBin.ts, so a GUI-launched host +// without a shell PATH still finds it), so binaryOk mirrors whether a custom spawn +// could actually start. +export async function customEngineStatus(report?: CliReport): Promise { + const binaryOk = (report ?? await detectCli())[engineBinary("custom")] !== "missing"; + const configured = await hasCustomEngine(); + return { binaryOk, configured, ready: binaryOk && configured }; +} + +// Masked view for the UI: endpoint host + last 4 chars of the key, rest dotted (like +// maskedHeliusKey). null when no config is stored; a keyless local endpoint shows +// just the host. The full key never leaves the host as plain text. +export async function maskedCustomEngine(): Promise { + const cfg = await loadCustomEngineConfig(); + if (!cfg) return null; + let host = cfg.baseUrl; + try { + host = new URL(cfg.baseUrl).host; + } catch { + // not a parseable URL: show the raw value + } + if (!cfg.apiKey) return host; + const tail = cfg.apiKey.slice(-4); + return `${host} · ${cfg.apiKey.length <= 4 ? tail : "••••" + tail}`; +} diff --git a/packages/core/src/account/customEngineMeta.ts b/packages/core/src/account/customEngineMeta.ts new file mode 100644 index 00000000..a0f979a1 --- /dev/null +++ b/packages/core/src/account/customEngineMeta.ts @@ -0,0 +1,10 @@ +// Custom engine warning copy, split from customEngineAuth because that file needs +// node:fs while the SPA connect form must render these strings verbatim from a +// browser bundle. This leaf stays node-free (like engineRegistry) so every surface +// reads the one definition instead of hardcoding drifting copies. + +// Shown verbatim by any connect UI before a custom endpoint is saved. +export const CUSTOM_ENGINE_EGRESS_WARNING = + "Custom engines send your prompts, files, and tool output to the endpoint you configure. Only connect endpoints you trust with that data."; +export const CUSTOM_ENGINE_TOOL_WARNING = + "The endpoint must speak the OpenAI Responses API with tool calling (codex 0.146 dropped the chat completions wire); plain chat endpoints need a translator in front."; diff --git a/packages/core/src/account/sessionLog.ts b/packages/core/src/account/sessionLog.ts index 7388e191..6fc81afb 100644 --- a/packages/core/src/account/sessionLog.ts +++ b/packages/core/src/account/sessionLog.ts @@ -6,6 +6,7 @@ // This file is the single source of the storage format — change it here only. import type { ChatMessage, CanonicalSession } from "../runtime/contract.js"; +import { coerceEngineKey, type EngineKey } from "../runtime/engineRegistry.js"; import { encryptForWallet, decryptForWallet, type SessionKey } from "../core/crypto.js"; // A log record: either session meta (first line) or one chat message. @@ -45,7 +46,7 @@ export async function decodeLog( if (!text) return null; let sessionId = ""; - let cli: "claude" | "codex" = "claude"; + let cli: EngineKey = "claude"; let title = ""; let ts = 0; let lastDevice: { id: string; label: string } | undefined = undefined; @@ -59,7 +60,7 @@ export async function decodeLog( const rec = JSON.parse(new TextDecoder().decode(plain)) as LogRecord; if (rec.kind === "meta") { sessionId = rec.sessionId; - cli = rec.cli as "claude" | "codex"; + cli = coerceEngineKey(rec.cli); // unknown cli strings read as codex-like title = rec.title; ts = rec.ts; lastDevice = rec.lastDevice; diff --git a/packages/core/src/account/store.ts b/packages/core/src/account/store.ts index c261adc5..48be255d 100644 --- a/packages/core/src/account/store.ts +++ b/packages/core/src/account/store.ts @@ -31,7 +31,7 @@ const PERF = !!process.env.AGENTNET_PERF; function toSessionMeta( sessionId: string, title: string, - cli: "claude" | "codex", + cli: SessionMeta["cli"], ts: number, lastDevice?: SessionMeta["lastDevice"], model?: string, diff --git a/packages/core/src/chat/modelOptions.ts b/packages/core/src/chat/modelOptions.ts index c62a915f..635b78f5 100644 --- a/packages/core/src/chat/modelOptions.ts +++ b/packages/core/src/chat/modelOptions.ts @@ -1,4 +1,6 @@ -export type EngineKey = "claude" | "codex"; +import type { EngineKey } from "../runtime/engineRegistry.js"; + +export type { EngineKey } from "../runtime/engineRegistry.js"; export type ChatModelOption = { value?: string; @@ -48,8 +50,25 @@ export const CHAT_MODEL_OPTIONS: Record = { description: "General GPT model · exact value: gpt-5.5", }, ], + // The custom engine has no catalog: its one model is whatever the saved endpoint + // config names, which lives on the host side. Surfaces build the entry with + // customModelOption from the stored config and push it over their live channel. + custom: [], }; +// Picker entry for the configured custom-endpoint model. Empty only for a legacy +// config saved before saveCustomEngineConfig required a model id; spawn rejects +// those configs, so an empty list here matches an engine that cannot run. +export function customModelOption(model: string, label?: string): ChatModelOption[] { + if (!model) return []; + return [{ + value: model, + chipLabel: model, + label: model, + description: (label ? label + " · " : "") + "configured endpoint model", + }]; +} + export function findChatModelOption(cli: EngineKey, model?: string): ChatModelOption | undefined { const opts = CHAT_MODEL_OPTIONS[cli]; return opts.find((opt) => (opt.value ?? "default") === (model ?? "default")); diff --git a/packages/core/src/chat/session.ts b/packages/core/src/chat/session.ts index e8012f7f..c4da58c1 100644 --- a/packages/core/src/chat/session.ts +++ b/packages/core/src/chat/session.ts @@ -16,7 +16,9 @@ import type { ApprovalChannel } from "../runtime/approval/channel.js"; import type { SkillCard, MarketRequest } from "./marketMessages.js"; import { access, writeFile } from "node:fs/promises"; import { join } from "node:path"; -import type { ChatModelOption } from "./modelOptions.js"; +import { customModelOption, type ChatModelOption } from "./modelOptions.js"; +import { loadCustomEngineConfig, customEngineStatus } from "../account/customEngineAuth.js"; +import { ENGINE_KEYS, ENGINE_REGISTRY, type EngineKey } from "../runtime/engineRegistry.js"; // Format a token count with thousands separators (e.g. 167000 → "167,000") for the // /context breakdown notice. @@ -126,7 +128,7 @@ export interface ChatEnv { rpcStatus?(): Promise; // Optional model catalog override from the host. VSCode uses this for Codex so the // picker can show the actual models exposed by the logged-in app-server account. - modelOptions?(cli: "claude" | "codex"): Promise; + modelOptions?(cli: EngineKey): Promise; // OPTIONAL multi-tab guard: vscode can open the same session in two panels (two // tabs writing one log races), so it claims a session before opening and yields // false to abort if another panel already holds it. One-socket surfaces (server, @@ -184,11 +186,11 @@ async function exists(path: string): Promise { } } -async function initInstructionsFile(cli: "claude" | "codex", cwd: string): Promise<{ file: string; created: boolean }> { - const file = cli === "codex" ? "AGENTS.md" : "CLAUDE.md"; +async function initInstructionsFile(cli: EngineKey, cwd: string): Promise<{ file: string; created: boolean }> { + const file = ENGINE_REGISTRY[cli].memoryFile; const path = join(cwd, file); if (await exists(path)) return { file, created: false }; - const tool = cli === "codex" ? "Codex" : "Claude Code"; + const tool = cli === "claude" ? "Claude Code" : "Codex"; await writeFile(path, [ `# ${file}`, "", @@ -241,11 +243,12 @@ export function createChatSession( lastUsage?: number; lastWindow?: number; }; - const slots: Record<"claude" | "codex", Slot> = { + const slots: Record = { claude: { handle: null, parked: new Set(), mode: "acceptEdits", restage: null }, codex: { handle: null, parked: new Set(), mode: "auto", restage: null }, + custom: { handle: null, parked: new Set(), mode: "auto", restage: null }, }; - let cli: "claude" | "codex" = "claude"; // which tab is showing + let cli: EngineKey = "claude"; // which tab is showing const slot = () => slots[cli]; // Handles with a turn in flight (set in ensureHandle when a turn starts, cleared in @@ -260,7 +263,7 @@ export function createChatSession( // onTurnEnd awaits it to write the matching `ended` mark, and only that turn's. const turnMarks = new Map>(); - function isVisibleHandle(forCli: "claude" | "codex", h: SessionHandle): boolean { + function isVisibleHandle(forCli: EngineKey, h: SessionHandle): boolean { return cli === forCli && slots[forCli].handle === h; } @@ -297,7 +300,7 @@ export function createChatSession( // background reply doesn't bleed into the other tab's log). The message already // carries its own .cli (stamped by the runtime), so the UI badges the real engine // per-message — correct even for a cross-CLI session. - function wire(forCli: "claude" | "codex", h: SessionHandle) { + function wire(forCli: EngineKey, h: SessionHandle) { h.onMessage((msg) => { if (isVisibleHandle(forCli, h)) transport.send({ type: "message", msg }); }); // nft skill firing cue; local plaintext skills are filtered in runtime/index. h.onSkill((skill) => { @@ -503,7 +506,7 @@ export function createChatSession( transport.send({ type: "skillShopping", on }); } - async function pushModelOptions(forCli: "claude" | "codex") { + async function pushModelOptions(forCli: EngineKey) { if (!env.modelOptions) return; const options = await env.modelOptions(forCli).catch(() => null); // Empty/failed probe → leave the webview on its static baseline (listClaudeModelOptions @@ -553,6 +556,15 @@ export function createChatSession( // only pushed codex, so a fresh claude session never received its dynamic list and // kept showing the static baseline. Switching engines pushes the other side. void pushModelOptions(cli); + // The custom tab ships hidden; a modelOptions push for "custom" is the signal + // that the custom engine is USABLE, so it is gated on customEngineStatus (config + // saved AND codex binary present). A config without the binary would reveal a + // tab that can only die with a raw spawn error. + void (async () => { + if (!(await customEngineStatus()).ready) return; + const cfg = await loadCustomEngineConfig(); + if (cfg) transport.send({ type: "modelOptions", cli: "custom", options: customModelOption(cfg.model, cfg.label || ENGINE_REGISTRY.custom.label) }); + })().catch(() => {}); // install the wallet's owned skills so they're present + discoverable this // session (issue #17). Fire-and-forget: a chain hiccup must not delay the chat; // refresh the panel once it lands. @@ -584,7 +596,7 @@ export function createChatSession( // you on an empty screen. We show a loading flash, hand the session to the new // slot, and repaint — the next send resumes it (history re-injected into the // new cli). If nothing was open, just switch to a blank chat as before. - if ((m.cli === "claude" || m.cli === "codex") && m.cli !== cli) { + if (ENGINE_KEYS.includes(m.cli) && m.cli !== cli) { const carry = slot().pendingId; // the session the OLD engine was showing cli = m.cli; void pushModelOptions(cli); @@ -704,7 +716,7 @@ export function createChatSession( // have per-category token data from the engines, so we report the totals we do have. if (command === "context") { const s = slot(); - const window = s.lastWindow ?? (cli === "codex" ? 256_000 : 200_000); + const window = s.lastWindow ?? (cli === "claude" ? 200_000 : 256_000); if (s.lastUsage === undefined) { transport.send({ type: "notice", text: `Context: 0 / ${fmtTok(window)} tokens. Send a message to measure usage.` }); break; @@ -754,7 +766,7 @@ export function createChatSession( if (typeof m.sessionId === "string") { await rt.deleteSession(m.sessionId); // if the deleted one is open in either slot, clear that slot - for (const k of ["claude", "codex"] as const) { + for (const k of ENGINE_KEYS) { const s = slots[k]; if (m.sessionId === (s.handle?.sessionId ?? s.pendingId)) { if (s.handle) stopHandle(s, s.handle); @@ -1041,7 +1053,7 @@ export function createChatSession( return { stop() { - for (const s of [slots.claude, slots.codex]) { + for (const s of Object.values(slots)) { if (s.handle) stopHandle(s, s.handle); for (const h of [...s.parked]) stopHandle(s, h); } diff --git a/packages/core/src/chat/slashCommands.ts b/packages/core/src/chat/slashCommands.ts index 73c79aef..f9fd6209 100644 --- a/packages/core/src/chat/slashCommands.ts +++ b/packages/core/src/chat/slashCommands.ts @@ -1,4 +1,6 @@ -export type SlashEngine = "claude" | "codex"; +import type { EngineKey } from "../runtime/engineRegistry.js"; + +export type SlashEngine = EngineKey; export interface SlashCommandSpec { name: string; @@ -9,10 +11,14 @@ export interface SlashCommandSpec { const both = ["claude", "codex"] as SlashEngine[]; +// The custom engine runs through the codex binary, so it speaks every codex command. +const withCustom = (c: SlashCommandSpec): SlashCommandSpec => + c.engines.includes("codex") ? { ...c, engines: [...c.engines, "custom"] } : c; + // Curated from the public Claude Code commands reference and Codex CLI/IDE slash // command references. AgentNet-local commands are included where this surface owns // the behavior instead of the native CLI. -export const CHAT_SLASH_COMMANDS: SlashCommandSpec[] = [ +export const CHAT_SLASH_COMMANDS: SlashCommandSpec[] = ([ { name: "login", desc: "sign in to the active engine", engines: both, args: "[code]" }, { name: "logout", desc: "sign out of the active engine", engines: both }, { name: "new", desc: "start a fresh chat", engines: both }, @@ -139,4 +145,4 @@ export const CHAT_SLASH_COMMANDS: SlashCommandSpec[] = [ { name: "quit", desc: "exit the native CLI session", engines: ["codex"] }, { name: "debug-config", desc: "inspect Codex config layers", engines: ["codex"] }, { name: "title", desc: "configure terminal title fields", engines: ["codex"] }, -]; +] as SlashCommandSpec[]).map(withCustom); diff --git a/packages/core/src/chat/ui/panel.jsdom.spec.ts b/packages/core/src/chat/ui/panel.jsdom.spec.ts index 6a1ebadc..5f3b0197 100644 --- a/packages/core/src/chat/ui/panel.jsdom.spec.ts +++ b/packages/core/src/chat/ui/panel.jsdom.spec.ts @@ -317,6 +317,97 @@ describe("panel.jsdom: rate-limit gauge", () => { }); }); +describe("panel.jsdom: custom engine tab (issue #209)", () => { + const CUSTOM_TAB = '#engineTabs .etab[data-cli="custom"]'; + const run = (p: Page, command: string) => { + const input = p.$("#input") as HTMLTextAreaElement; + input.value = command; + p.key(input, "Enter"); + }; + + it("ships hidden, refuses /engine custom without a config, and appears once the host announces one", () => { + const p = boot(); + p.host({ type: "cliStatus", claude: "ok", codex: "ok" }); + expect(p.$(CUSTOM_TAB)!.style.display).toBe("none"); + const before = p.posted.length; + run(p, "/engine custom"); + expect(p.types().slice(before)).toEqual([]); + expect(p.$("#log")!.textContent).toContain("Custom engine is not configured"); + expect(p.$("#composer")!.dataset.cli).toBe("claude"); + + p.host({ type: "customEngine", masked: "127.0.0.1:11667", presets: [] }); + expect(p.$(CUSTOM_TAB)!.style.display).toBe(""); + const input = p.$("#input") as HTMLTextAreaElement; + input.value = "/engine"; + p.fire(input, "input"); + expect(p.$$("#slashMenu .slashOpt .cmd").map((e) => e.textContent)).toContain("custom"); + input.value = ""; // close the menu: an open menu makes Enter complete, not send + p.fire(input, "input"); + + const at = p.posted.length; + run(p, "/engine custom"); + expect(p.types().slice(at)).toEqual(["platform", "model", "mode", "effort"]); + expect(p.posted[at]).toEqual({ type: "platform", cli: "custom" }); + expect(p.posted[at + 2]).toEqual({ type: "mode", mode: "auto" }); // codex's modes, shared + expect(p.$("#composer")!.dataset.cli).toBe("custom"); + expect(p.errors).toEqual([]); + }); + + it("reveals the tab on custom modelOptions and shows the configured model on the chip", () => { + const p = boot(); + p.host({ type: "cliStatus", claude: "ok", codex: "ok" }); + p.host({ type: "modelOptions", cli: "custom", options: [{ value: "mock-model", chipLabel: "mock-model", label: "mock-model" }] }); + expect(p.$(CUSTOM_TAB)!.style.display).toBe(""); + run(p, "/engine custom"); + expect(p.$("#modelLabel")!.textContent).toBe("mock-model"); + expect(p.errors).toEqual([]); + }); + + it("keeps /login and /logout away from the host on the custom tab: it has no account", () => { + const p = boot(); + p.host({ type: "cliStatus", claude: "ok", codex: "ok" }); + p.host({ type: "customEngine", masked: "127.0.0.1:11667", presets: [] }); + run(p, "/engine custom"); + const at = p.posted.length; + run(p, "/login"); + run(p, "/logout"); + run(p, "/logout custom"); + expect(p.types().slice(at)).toEqual([]); + expect(p.$("#log")!.textContent).toContain("Custom endpoints have no login"); + expect(p.errors).toEqual([]); + }); + + it("a null customEngine while on the tab hides it and lands the user on codex", () => { + const p = boot(); + p.host({ type: "cliStatus", claude: "ok", codex: "ok" }); + p.host({ type: "customEngine", masked: "127.0.0.1:11667", presets: [] }); + run(p, "/engine custom"); + const at = p.posted.length; + p.host({ type: "customEngine", masked: null, presets: [] }); + expect(p.$(CUSTOM_TAB)!.style.display).toBe("none"); + expect(p.$("#composer")!.dataset.cli).toBe("codex"); + expect(p.posted[at]).toEqual({ type: "platform", cli: "codex" }); + expect(p.$("#log")!.textContent).toContain("Custom engine was removed"); + expect(p.errors).toEqual([]); + }); + + it("marks a custom reply as custom and an unknown persisted cli as codex, live and on older pages", () => { + const p = boot(); + p.host({ type: "message", msg: { role: "user", text: "q" } }); + p.host({ type: "message", msg: { role: "assistant", cli: "custom", text: "from the endpoint" } }); + expect(p.$("#log .node.assistant.custom .msg")!.textContent).toContain("from the endpoint"); + p.host({ type: "message", msg: { role: "assistant", cli: "future-engine", text: "from a newer build" } }); + p.host({ type: "older", messages: [ + { role: "user", text: "older q" }, + { role: "assistant", cli: "future-engine", text: "older a" }, + ], hasMore: false, cursor: null }); + // the unknown cli never reaches the class list: both nodes carry the codex mark instead + expect(p.$$("#log .node.assistant.codex .msg").map((e) => e.textContent!.trim())).toEqual(["older a", "from a newer build"]); + expect(p.$$('#log .node[class*="future-engine"]')).toEqual([]); + expect(p.errors).toEqual([]); + }); +}); + describe("panel.jsdom: streaming", () => { it("replaces the live bubble on each cumulative partial and finalizes exactly one assistant bubble", async () => { const p = boot(); diff --git a/packages/core/src/chat/ui/panel/composer.ts b/packages/core/src/chat/ui/panel/composer.ts index c1ba35ed..9db3b54a 100644 --- a/packages/core/src/chat/ui/panel/composer.ts +++ b/packages/core/src/chat/ui/panel/composer.ts @@ -141,6 +141,12 @@ export function send() { switch (cmd) { case 'login': { const target = (arg === 'claude' || arg === 'codex') ? arg : S.cli; + // The custom engine signs in by saving an endpoint config, not an account login; + // falling through would start a Codex device auth the user never asked for. + if (target === 'custom') { + renderNotice('Custom endpoints have no login. Connect one from the AgentNet app settings.'); + input.value = ''; return; + } if (target === 'claude' && arg && arg !== 'claude' && arg !== 'codex') { vscode.postMessage({ type: 'claudeAuthCode', code: arg }); renderNotice('Submitted Claude sign-in code.'); @@ -151,7 +157,13 @@ export function send() { input.value = ''; return; } case 'logout': { - const target = (arg === 'claude' || arg === 'codex') ? arg : S.cli; + const target = (arg === 'claude' || arg === 'codex' || arg === 'custom') ? arg : S.cli; + // Custom holds no account: logoutEngine resolves to the codex BINARY, so forwarding + // it would sign the user out of their real Codex login. + if (target === 'custom') { + renderNotice('Custom endpoints have no login to sign out of. Remove the endpoint from the AgentNet app settings.'); + input.value = ''; return; + } vscode.postMessage({ type: 'logoutEngine', cli: target }); renderNotice('Signing out of ' + (target === 'claude' ? 'Claude' : 'Codex') + '...'); input.value = ''; return; @@ -196,7 +208,13 @@ export function send() { input.value = ''; return; } case 'engine': - if (arg === 'claude' || arg === 'codex') selectTab(arg); + // No saved endpoint config: this panel has no connect form, so switching would land + // on a tab that cannot spawn. Point at where the config lives instead. + if (arg === 'custom' && !S.customEngineOn) { + renderNotice('Custom engine is not configured. Connect it from the AgentNet app settings.'); + input.value = ''; return; + } + if (arg === 'claude' || arg === 'codex' || arg === 'custom') selectTab(arg); input.value = ''; return; case 'model': if (arg) { modelByCli[S.cli] = arg; fillModels(); vscode.postMessage({ type: 'model', model: arg }); } diff --git a/packages/core/src/chat/ui/panel/engine.ts b/packages/core/src/chat/ui/panel/engine.ts index e45be985..06c0dd23 100644 --- a/packages/core/src/chat/ui/panel/engine.ts +++ b/packages/core/src/chat/ui/panel/engine.ts @@ -22,6 +22,13 @@ export const modelValue = (opt) => (opt && opt.value) ? opt.value : 'default'; // sandbox+approval preset (mapped host-side in spawn). Like MODELS this is just a // wrapper label table — when a CLI changes its modes, only this list needs editing. // English labels mirror what each CLI calls these modes natively. +// The custom engine runs through the codex binary, so codex's sandbox modes are its modes: +// one list, referenced twice, instead of a copy that could drift. +const CODEX_MODES = [ + { value: 'readonly', label: 'Read only', title: 'Read-only sandbox; ask before edits, commands, network' }, + { value: 'auto', label: 'Auto accept', title: 'Auto-accept edits + run inside the workspace; approve on failure (default)' }, + { value: 'full', label: 'Full access', title: 'Full disk + network access, never ask (use with care)' }, +]; export const MODES = { claude: [ { value: 'default', label: 'Ask edits', title: 'Ask before each file edit (default)' }, @@ -29,11 +36,8 @@ export const MODES = { { value: 'plan', label: 'Plan', title: 'Plan mode: read-only until you approve the plan' }, { value: 'bypassPermissions', label: 'Bypass', title: 'Bypass all permission prompts (--dangerously-skip-permissions). Auto-runs every command, edit, and on-chain spend. Use with care.' }, ], - codex: [ - { value: 'readonly', label: 'Read only', title: 'Read-only sandbox; ask before edits, commands, network' }, - { value: 'auto', label: 'Auto accept', title: 'Auto-accept edits + run inside the workspace; approve on failure (default)' }, - { value: 'full', label: 'Full access', title: 'Full disk + network access, never ask (use with care)' }, - ], + codex: CODEX_MODES, + custom: CODEX_MODES, }; // reasoning effort levels (applies to both engines; labels mirror CLI EffortPicker) export const EFFORTS = [ @@ -47,9 +51,9 @@ export const EFFORTS = [ // remember the chosen mode + model + effort per engine so switching tabs restores them. // model starts null (not 'default') so currentModel() falls to the first real model and // the chip shows its actual name (e.g. "Opus 4.8") instead of an opaque "default". -export const modeByCli = { claude: 'acceptEdits', codex: 'auto' }; -export const modelByCli = { claude: null, codex: null }; -export const effortByCli = { claude: 'default', codex: 'default' }; +export const modeByCli = { claude: 'acceptEdits', codex: 'auto', custom: 'auto' }; +export const modelByCli = { claude: null, codex: null, custom: null }; +export const effortByCli = { claude: 'default', codex: 'default', custom: 'default' }; // ---- platform tabs + model picker (chip + popover, mirroring the mode picker) ---- export function currentModel() { @@ -177,8 +181,30 @@ export function openModeMenu() { placeMenuAbove(modeMenu, modeBtn.getBoundingClientRect()); } export function currentEffort() { return effortByCli[S.cli] || 'default'; } +// The custom tab (issue #209) ships hidden in the shell: this panel has no connect form, so +// the tab only appears once the host announces a saved endpoint config (customEngine, or +// the custom modelOptions that exist only with a config). +export function showCustomTab() { + S.customEngineOn = true; + const t = tabs.find((t) => t.dataset.cli === 'custom'); + if (t) t.style.display = ''; +} +// The endpoint config is gone (cleared host-side, or never existed): hide the tab. If the +// user was ON it, land them on the codex tab, because a custom session can no longer +// spawn; selectTab also surfaces codex's own sign-in state if needed. +export function hideCustomTab() { + S.customEngineOn = false; + const t = tabs.find((t) => t.dataset.cli === 'custom'); + if (t) t.style.display = 'none'; + if (S.cli === 'custom') { + renderNotice('Custom engine was removed. Switched to the Codex tab.'); + selectTab('codex'); + } +} export function setTab(next) { - if (next !== 'claude' && next !== 'codex') return; + if (next !== 'claude' && next !== 'codex' && next !== 'custom') return; + // the host only lands here with a config, so an active-but-hidden tab cannot happen + if (next === 'custom') showCustomTab(); S.cli = next; tabs.forEach(t => t.classList.toggle('active', t.dataset.cli === S.cli)); composer.dataset.cli = S.cli; // tints the input (claude=orange/codex=green) diff --git a/packages/core/src/chat/ui/panel/main.ts b/packages/core/src/chat/ui/panel/main.ts index b7bcf407..06a87462 100644 --- a/packages/core/src/chat/ui/panel/main.ts +++ b/packages/core/src/chat/ui/panel/main.ts @@ -9,7 +9,7 @@ import { log, approvalDock } from "./dom.js"; import { escapeHtml } from "./markdown.js"; import { syncWatermark, renderNotice, renderEngineBanner, renderLimitMeter, setCtxTokens, clearCtx, copyAction, renderEngineMissing, renderStatus, showLoading, hideLoading, wireShell } from "./shell.js"; import { wireSlash } from "./slash.js"; -import { CODEX_UPDATE_CMD, applyModelOptions, setTab, wireEngine } from "./engine.js"; +import { CODEX_UPDATE_CMD, applyModelOptions, hideCustomTab, setTab, showCustomTab, wireEngine } from "./engine.js"; import "./format.js"; import "./turns.js"; import { dismissApproval, renderApproval } from "./approval.js"; @@ -57,7 +57,12 @@ window.addEventListener('message', (event) => { else if (m.type === 'loading') showLoading(); else if (m.type === 'clear') { log.innerHTML = ''; approvalDock.innerHTML = ''; clearCtx(); syncComposerLock(); S.streaming = null; S.openBash = null; S.tailTurn = null; S.headTurn = null; hideTyping(); hideActivity(); resetPaging(); syncWatermark(); hideLoading(); } else if (m.type === 'turnEnd') { hideTyping(); hideActivity(); } - else if (m.type === 'modelOptions') { applyModelOptions(m.cli, m.options); } + else if (m.type === 'modelOptions') { + // options for "custom" only exist once an endpoint config is saved, so their arrival + // doubles as the reveal signal for the hidden tab + if (m.cli === 'custom') showCustomTab(); + applyModelOptions(m.cli, m.options); + } else if (m.type === 'usage') { // per-chat context tokens — the secondary chip, revealed by clicking the usage gauge setCtxTokens(m.contextTokens); @@ -335,6 +340,12 @@ window.addEventListener('message', (event) => { } } else if (m.type === 'platform') setTab(m.cli); // extension switched CLI (e.g. on session open) + else if (m.type === 'customEngine') { + // The host's masked config summary doubles as the tab gate: non-null (a key tail, or a + // bare host for keyless local endpoints) means a saved endpoint exists. + if (m.masked != null) showCustomTab(); + else hideCustomTab(); + } else if (m.type === 'cliStatus') { const previousStatus = S.cliReport?.[S.cli]; S.cliReport = { claude: m.claude, codex: m.codex }; diff --git a/packages/core/src/chat/ui/panel/paging.ts b/packages/core/src/chat/ui/panel/paging.ts index 5e11a1ae..22d7a013 100644 --- a/packages/core/src/chat/ui/panel/paging.ts +++ b/packages/core/src/chat/ui/panel/paging.ts @@ -7,7 +7,7 @@ import { vscode } from "./host.js"; import { log } from "./dom.js"; import { renderMd } from "./markdown.js"; import { nearBottom, updateJump } from "./shell.js"; -import { addFooter, addMsgCopy, makeUtext, renderToolInto } from "./turns.js"; +import { ENGINE_BADGE, addFooter, addMsgCopy, engineMark, makeUtext, renderToolInto } from "./turns.js"; import { userImagesEl } from "./composer.js"; // ---- scroll-to-top → load older page ---- @@ -28,8 +28,8 @@ export function prependOlder(messages) { const head = document.createElement('div'); head.className = 'turnHead'; head.innerHTML = '>'; head.appendChild(makeUtext(userText)); - if (badge) { const b = document.createElement('span'); b.className = 'badge ' + badge; - b.textContent = badge === 'codex' ? 'codex · gpt' : 'claude'; head.appendChild(b); } + if (badge) { const b = document.createElement('span'); b.className = 'badge ' + engineMark(badge); + b.textContent = ENGINE_BADGE[engineMark(badge)]; head.appendChild(b); } const imgEl = userImagesEl(imageCount ? { count: imageCount } : undefined); if (imgEl) head.appendChild(imgEl); const b = document.createElement('div'); b.className = 'turnBody'; @@ -46,7 +46,7 @@ export function prependOlder(messages) { const sb = document.createElement('div'); sb.className = 'summaryBody'; sb.textContent = m.text; n.appendChild(sb); continue; } - const n = node(m.role + (m.role === 'assistant' && m.cli ? ' ' + m.cli : '')); + const n = node(m.role + (m.role === 'assistant' && m.cli ? ' ' + engineMark(m.cli) : '')); const el = document.createElement('div'); el.className = 'msg ' + m.role; if (m.role === 'assistant') renderMd(el, m.text); else { el.textContent = m.text; el.dataset.md = m.text; } n.appendChild(el); diff --git a/packages/core/src/chat/ui/panel/slash.ts b/packages/core/src/chat/ui/panel/slash.ts index 45a0b6f3..cb11d648 100644 --- a/packages/core/src/chat/ui/panel/slash.ts +++ b/packages/core/src/chat/ui/panel/slash.ts @@ -41,6 +41,8 @@ export function renderSlashMenu() { { name: 'claude', desc: 'switch to Claude engine', insert: '/engine claude' }, { name: 'codex', desc: 'switch to Codex engine', insert: '/engine codex' } ]; + // custom is offered only once the host says an endpoint config exists + if (S.customEngineOn) options.push({ name: 'custom', desc: 'switch to Custom engine', insert: '/engine custom' }); } // 2. Model options if (!subCmd) { diff --git a/packages/core/src/chat/ui/panel/state.ts b/packages/core/src/chat/ui/panel/state.ts index cb2fa83f..a5199c07 100644 --- a/packages/core/src/chat/ui/panel/state.ts +++ b/packages/core/src/chat/ui/panel/state.ts @@ -26,6 +26,7 @@ export const S = { // ---- engine.ts ---- cli: 'claude', cliReport: null as any, + customEngineOn: false, // a saved custom-endpoint config exists (host-announced) // ---- turns.ts ---- tailTurn: null as any, // the turn new (bottom) replies attach to headTurn: null as any, // the turn prepended (top, older) replies attach to diff --git a/packages/core/src/chat/ui/panel/turns.ts b/packages/core/src/chat/ui/panel/turns.ts index eccb6a00..7281ba12 100644 --- a/packages/core/src/chat/ui/panel/turns.ts +++ b/packages/core/src/chat/ui/panel/turns.ts @@ -32,14 +32,19 @@ export function makeUtext(userText) { } return wrap; } +// Engine badge text per persisted cli. Old logs can carry a cli this build does not know; +// those engines ran the codex passthrough, so their marks fall back to codex (mirrors +// core's coerceEngineKey). +export const ENGINE_BADGE = { claude: 'claude', codex: 'codex · gpt', custom: 'custom' }; +export const engineMark = (c) => ENGINE_BADGE[c] ? c : 'codex'; export function startTurn(userText, badgeCli, imageInfo) { const turn = document.createElement('div'); turn.className = 'turn'; const head = document.createElement('div'); head.className = 'turnHead'; head.innerHTML = '>'; const ut = makeUtext(userText); head.appendChild(ut); - if (badgeCli) { const b = document.createElement('span'); b.className = 'badge ' + badgeCli; - b.textContent = badgeCli === 'codex' ? 'codex · gpt' : 'claude'; head.appendChild(b); } + if (badgeCli) { const b = document.createElement('span'); b.className = 'badge ' + engineMark(badgeCli); + b.textContent = ENGINE_BADGE[engineMark(badgeCli)]; head.appendChild(b); } // Thumbnails go INSIDE the text column, below the text — not as a flex sibling of it in // turnHead. As a sibling they competed with .utext for the row's width, so two 168px // images starved the text down to a one-character-per-line vertical sliver. insertBefore @@ -61,8 +66,8 @@ export function startTurnTop(userText, badgeCli) { const head = document.createElement('div'); head.className = 'turnHead'; head.innerHTML = '>'; head.appendChild(makeUtext(userText)); - if (badgeCli) { const b = document.createElement('span'); b.className = 'badge ' + badgeCli; - b.textContent = badgeCli === 'codex' ? 'codex · gpt' : 'claude'; head.appendChild(b); } + if (badgeCli) { const b = document.createElement('span'); b.className = 'badge ' + engineMark(badgeCli); + b.textContent = ENGINE_BADGE[engineMark(badgeCli)]; head.appendChild(b); } const body = document.createElement('div'); body.className = 'turnBody'; turn.appendChild(head); turn.appendChild(body); log.insertBefore(turn, log.firstChild); @@ -95,8 +100,8 @@ export function appendNode(el, dir) { // prepend=true → goes on the prepended (older) head turn; else the bottom tail turn. export function bubble(role, prepend, badgeCli) { const node = document.createElement('div'); - // the engine class (claude/codex) tints the timeline dot into an engine mark - node.className = 'node ' + role + (badgeCli ? ' ' + badgeCli : ''); + // the engine class (claude/codex/custom) tints the timeline dot into an engine mark + node.className = 'node ' + role + (badgeCli ? ' ' + engineMark(badgeCli) : ''); const el = document.createElement('div'); el.className = 'msg ' + role; node.appendChild(el); diff --git a/packages/core/src/chat/ui/webview.ts b/packages/core/src/chat/ui/webview.ts index 8107dbd3..0d49bf4f 100644 --- a/packages/core/src/chat/ui/webview.ts +++ b/packages/core/src/chat/ui/webview.ts @@ -280,6 +280,7 @@ export function chatHtml(): string { /* engine accent for the unread state — keyed off data-cli, same source the send button uses */ #jumpBtn[data-cli="claude"] { --eng: var(--claude); } #jumpBtn[data-cli="codex"] { --eng: var(--an-green); } + #jumpBtn[data-cli="custom"] { --eng: var(--an-violet); } /* when there's a NEW message while scrolled up: outline + icon glow in the engine accent (claude=orange / codex=green), background stays black/white per theme. */ #jumpBtn.hasNew { color: var(--eng); border-color: color-mix(in srgb, var(--eng) 88%, transparent); @@ -340,6 +341,9 @@ export function chatHtml(): string { box-shadow: 0 0 0 3px var(--an-green-dim); } .node.assistant.claude::before { background: var(--claude); border-color: var(--claude); box-shadow: 0 0 0 3px rgba(233,136,58,0.16); } + /* custom rides the codex binary but marks its replies violet so they don't read as codex */ + .node.assistant.custom::before { background: var(--an-violet); border-color: var(--an-violet); + box-shadow: 0 0 0 3px var(--an-violet-dim); } .node.thinking::before { background: transparent; } .msg { white-space: pre-wrap; line-height: 1.55; font-size: 0.95em; overflow-wrap: anywhere; } /* rendered markdown inside an assistant message: tame the default browser margins @@ -631,6 +635,7 @@ export function chatHtml(): string { .badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; } .badge.claude { color: #e9883a; border-color: #e9883a44; background: #e9883a14; } .badge.codex { color: var(--an-green); border-color: var(--an-green-line); background: var(--an-green-dim); } + .badge.custom { color: var(--an-violet); border-color: var(--an-violet-line); background: var(--an-violet-dim); } /* ── COMPOSER: engine folder-tabs + input + controls ───────────────────── The engine (claude/codex) is chosen by FOLDER TABS at the top-right of the @@ -642,6 +647,7 @@ export function chatHtml(): string { /* per-engine accent: a single var the composer themes off of */ #composer { --eng: var(--an-green); --engSoft: var(--an-green-dim); --engLine: var(--an-green-line); } #composer[data-cli="claude"] { --eng: var(--claude); --engSoft: rgba(233,136,58,0.12); --engLine: rgba(233,136,58,0.45); } + #composer[data-cli="custom"] { --eng: var(--an-violet); --engSoft: var(--an-violet-dim); --engLine: var(--an-violet-line); } /* composer top row: skills (left) ←→ engine tabs (right) */ #composerTop { display: flex; align-items: flex-end; justify-content: space-between; } @@ -1058,6 +1064,7 @@ export function chatHtml(): string { .etab .ed { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.5; } .etab[data-cli="claude"] { color: var(--claude); } .etab[data-cli="codex"] { color: var(--an-green); } + .etab[data-cli="custom"] { color: var(--an-violet); } /* the ACTIVE tab pops forward: full opacity, raised, merged into the input box */ .etab.active { opacity: 1; background: var(--an-bg-2); border-color: var(--engLine); border-bottom: 1px solid var(--an-bg-2); top: 2px; z-index: 2; font-weight: 600; } @@ -1976,6 +1983,8 @@ export function chatHtml(): string {
claude
codex
+ +
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 5b2a7d14..7ee0b0d1 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -102,6 +102,10 @@ export { export type { SkillOrigin, ClassifiedSkill, SkillManifest, NftSkillRecord } from "./skill-market/registry.js"; export { createRuntime } from "./runtime/index.js"; +export { CUSTOM_ENGINE_KEYLESS_PLACEHOLDER } from "./runtime/spawn.js"; +// engine behavior registry: claude/codex/custom descriptors + the coercion helpers +export { ENGINE_KEYS, ENGINE_REGISTRY, engineBinary, coerceEngineKey, messageBinary } from "./runtime/engineRegistry.js"; +export type { EngineDescriptor } from "./runtime/engineRegistry.js"; export { detectCli } from "./runtime/detect.js"; export { resolveEngineBin } from "./runtime/engineBin.js"; export { ENGINE_INSTALL_COMMAND, ENGINE_UPDATE_COMMAND, CODEX_UPDATE_COMMAND, NODE_REQUIRED_MESSAGE, NODE_DOWNLOAD_URL } from "./runtime/engineInstall.js"; @@ -140,6 +144,21 @@ export { logoutCodex, } from "./account/codexAuth.js"; export type { CodexLogin } from "./account/codexAuth.js"; +// custom engine (issue #209): endpoint config store + presets + connect-UI copy. +// customEngineStatus is the one readiness answer (binary + config) every host uses +// instead of re-deriving it from detectCli + hasCustomEngine. +export { + saveCustomEngineConfig, + loadCustomEngineConfig, + clearCustomEngineConfig, + hasCustomEngine, + maskedCustomEngine, + customEngineStatus, + CUSTOM_ENGINE_PRESETS, + CUSTOM_ENGINE_EGRESS_WARNING, + CUSTOM_ENGINE_TOOL_WARNING, +} from "./account/customEngineAuth.js"; +export type { CustomEngineConfig, CustomEnginePreset, CustomEngineStatus } from "./account/customEngineAuth.js"; export { initialize, isInitialized, @@ -187,7 +206,7 @@ export { autoApprove, withTimeout } from "./runtime/approval/channel.js"; export { createChatSession } from "./chat/session.js"; export type { ChatTransport, ChatEnv } from "./chat/session.js"; export { TransportApprovalChannel } from "./chat/approvalChannel.js"; -export { CHAT_MODEL_OPTIONS, findChatModelOption } from "./chat/modelOptions.js"; +export { CHAT_MODEL_OPTIONS, findChatModelOption, customModelOption } from "./chat/modelOptions.js"; export type { ChatModelOption, EngineKey } from "./chat/modelOptions.js"; export { CHAT_SLASH_COMMANDS } from "./chat/slashCommands.js"; export type { SlashCommandSpec, SlashEngine } from "./chat/slashCommands.js"; diff --git a/packages/core/src/runtime/approval/channel.ts b/packages/core/src/runtime/approval/channel.ts index a4805d14..8bcd7f75 100644 --- a/packages/core/src/runtime/approval/channel.ts +++ b/packages/core/src/runtime/approval/channel.ts @@ -7,6 +7,8 @@ // This is deliberately CLI/SDK-neutral (no claude/codex types leak in) so the same // request can be rendered on any surface and answered from anywhere. +import type { EngineKey } from "../engineRegistry.js"; + // A multiple-choice question (claude's AskUserQuestion): one or more questions, each with // options the user picks from. NOT a yes/no permission — the user's CHOICE becomes the // tool result, so the decision carries `answers` rather than just allow/deny. @@ -34,7 +36,7 @@ export interface ApprovalQuestionResponse { // parsing input. export interface ApprovalRequest { id: string; // unique per request; the decision must echo it back - cli: "claude" | "codex"; + cli: EngineKey; sessionId: string; // canonical session this belongs to tool: string; // tool name as the engine reports it (Bash, Edit, Write…) kind: "bash" | "edit" | "write" | "read" | "question" | "plan" | "other"; diff --git a/packages/core/src/runtime/contract.ts b/packages/core/src/runtime/contract.ts index 7dabd997..41e5de66 100644 --- a/packages/core/src/runtime/contract.ts +++ b/packages/core/src/runtime/contract.ts @@ -14,6 +14,7 @@ // (Phantom, Ledger, a local Keypair, mobile wallet) can satisfy it. import type { WalletSigner } from "@iqlabs-official/solana-sdk/utils"; import type { ApprovalChannel } from "./approval/channel.js"; +import type { EngineKey } from "./engineRegistry.js"; import type { MarketEvent } from "../chat/marketMessages.js"; export interface Wallet extends WalletSigner { @@ -75,7 +76,7 @@ export interface ChatMessage { // which CLI produced this message. Stored per-message so a session continued // across CLIs renders each turn with the RIGHT engine badge — independent of // which tab is currently open. Optional for back-compat with older logs. - cli?: "claude" | "codex"; + cli?: EngineKey; // For role:"tool" — structured action so the UI can render it nicely (a bash // block, a diff, a file op) instead of opaque text. `text` still holds a short // human summary for fallback/older readers. All fields optional per tool kind. @@ -136,7 +137,7 @@ export interface RateLimitInfo { // ── a running session (the handle the UI drives) ──────── export interface SessionHandle { readonly sessionId: string; // from the CLI's system/init - readonly cli: "claude" | "codex"; + readonly cli: EngineKey; send(userText: string, images?: ImageInput[]): void; // user input (+ attached images) → CLI runSlashCommand?(command: string, arg?: string): void; // native CLI slash command, not a chat turn onMessage(cb: (msg: ChatMessage) => void): void; // CLI output (UI renders) @@ -165,7 +166,7 @@ export interface AgentRuntime { // spawn claude/codex and start a session. Pass sessionId to resume an old one. // The runtime auto-saves (encrypt → storage) on every turn end — the UI does nothing. startSession(opts: { - cli: "claude" | "codex"; + cli: EngineKey; cwd: string; sessionId?: string; // present = resume, absent = new model?: string; @@ -254,7 +255,7 @@ export interface PageResult { export interface SessionMeta { sessionId: string; title: string; // derived (e.g. first user line) - cli: "claude" | "codex"; + cli: EngineKey; ts: number; // last updated lastDevice?: { id: string; label: string }; // the model/effort the session last ran with (absent = engine default), so a @@ -266,7 +267,7 @@ export interface SessionMeta { // what gets encrypted to storage (CLI-neutral, so codex↔claude + cross-device) export interface CanonicalSession { sessionId: string; - cli: "claude" | "codex"; + cli: EngineKey; title: string; messages: ChatMessage[]; ts: number; diff --git a/packages/core/src/runtime/customEngine.spec.ts b/packages/core/src/runtime/customEngine.spec.ts new file mode 100644 index 00000000..29157a22 --- /dev/null +++ b/packages/core/src/runtime/customEngine.spec.ts @@ -0,0 +1,52 @@ +// Custom engine (issue #209) safety rails. Each of these is a silent-failure class: +// a missing config would run stock codex on the user's OpenAI account, a phantom +// env_key handling protects keyless local endpoints, and a blank model makes codex quietly use +// its own global default model. Pin all three to throw or emit correctly. +import { describe, it, expect } from "vitest"; +import { spawnCli, customProviderFlags } from "./spawn.js"; +import { saveCustomEngineConfig, type CustomEngineConfig } from "../account/customEngineAuth.js"; + +const NOT_CONFIGURED = "Custom engine is not configured. Connect an endpoint before starting a custom session."; +const NEEDS_MODEL = "The custom engine needs a model id; codex would otherwise silently use its own default model."; + +const cfg = (over: Partial = {}): CustomEngineConfig => ({ + baseUrl: "http://localhost:11434/v1", + apiKey: "", + model: "llama3", + presetId: "ollama", + ...over, +}); + +describe("runtime/spawn — custom engine gates", () => { + it("spawnCli throws loudly on a custom spawn with no config (never silently runs stock codex)", () => { + expect(() => spawnCli({ cli: "custom", cwd: "/tmp" })).toThrow(NOT_CONFIGURED); + }); + + it("customProviderFlags declares env_key even keyless: without it codex sends the user's own ChatGPT token to the endpoint", () => { + const flags = customProviderFlags(cfg()); + expect(flags).toContain(`model_providers.custom.env_key=${JSON.stringify("CUSTOM_ENGINE_API_KEY")}`); + }); + + it("customProviderFlags emits env_key when a key is configured", () => { + const flags = customProviderFlags(cfg({ apiKey: "sk-test" })); + expect(flags).toContain(`model_providers.custom.env_key=${JSON.stringify("CUSTOM_ENGINE_API_KEY")}`); + // the key itself must never ride argv + expect(flags.join(" ")).not.toContain("sk-test"); + }); + + it("customProviderFlags throws on a blank model instead of letting codex pick its default", () => { + expect(() => customProviderFlags(cfg({ model: "" }))).toThrow(NEEDS_MODEL); + }); +}); + +describe("account/customEngineAuth — saveCustomEngineConfig validation", () => { + it("rejects a blank model before anything reaches disk", async () => { + await expect(saveCustomEngineConfig(cfg({ model: "" }))).rejects.toThrow(NEEDS_MODEL); + await expect(saveCustomEngineConfig(cfg({ model: " " }))).rejects.toThrow(NEEDS_MODEL); + }); + + it("rejects a base URL that is not http(s)", async () => { + await expect(saveCustomEngineConfig(cfg({ baseUrl: "not a url" }))).rejects.toThrow(/not a valid URL/); + await expect(saveCustomEngineConfig(cfg({ baseUrl: "ftp://host/v1" }))).rejects.toThrow(/must be http or https/); + }); +}); diff --git a/packages/core/src/runtime/engineInstall.ts b/packages/core/src/runtime/engineInstall.ts index 08f0c721..92606a94 100644 --- a/packages/core/src/runtime/engineInstall.ts +++ b/packages/core/src/runtime/engineInstall.ts @@ -4,20 +4,24 @@ // // Pure data on purpose: browser surfaces (webview) import this module directly, so it // must stay free of node imports (detect.ts, which reports the statuses, is node-only). +import type { EngineKey } from "./engineRegistry.js"; + export const NODE_REQUIRED_MESSAGE = "This engine is installed, but Node.js is missing. Install Node.js, restart AgentNet, then retry."; export const NODE_DOWNLOAD_URL = "https://nodejs.org/en/download"; -export const ENGINE_INSTALL_COMMAND: Record<"claude" | "codex", string> = { +export const ENGINE_INSTALL_COMMAND: Record = { codex: "npm install -g @openai/codex", claude: "npm install -g @anthropic-ai/claude-code", + custom: "npm install -g @openai/codex", // custom runs through the codex binary }; // Official npm update command per engine, the same channel as the install commands. // updateEngine in engineVersions.ts runs it only for a missing engine; an installed engine // updates itself. -export const ENGINE_UPDATE_COMMAND: Record<"claude" | "codex", string> = { +export const ENGINE_UPDATE_COMMAND: Record = { codex: "npm install -g @openai/codex@latest", claude: "npm install -g @anthropic-ai/claude-code@latest", + custom: "npm install -g @openai/codex@latest", // custom runs through the codex binary }; // An outdated codex silently hides new models (its models cache uses fields the old diff --git a/packages/core/src/runtime/engineRegistry.ts b/packages/core/src/runtime/engineRegistry.ts new file mode 100644 index 00000000..8c13e5cf --- /dev/null +++ b/packages/core/src/runtime/engineRegistry.ts @@ -0,0 +1,45 @@ +// One behavior registry for every engine. "custom" (issue #209) is an OpenAI-compatible +// endpoint driven through the codex binary via provider overrides, so most call sites +// only need the descriptor's `binary` to know how to treat it. Pure data on purpose: +// browser surfaces import this transitively (modelOptions), so keep it free of node +// imports, like engineInstall.ts. + +export type EngineKey = "claude" | "codex" | "custom"; + +// key names the row it sits in, binary drives engine dispatch, label names the +// engine where a surface needs a display name, memoryFile picks the native +// project-instructions file. loginKind and modelSource used to live here too but +// nothing ever read them, so they are gone (CODE-RULES: no dead data). +export interface EngineDescriptor { + key: EngineKey; + label: string; + binary: "claude" | "codex"; // which CLI process actually runs + memoryFile: "CLAUDE.md" | "AGENTS.md"; // native project-instructions file +} + +export const ENGINE_REGISTRY: Record = { + claude: { key: "claude", label: "Claude", binary: "claude", memoryFile: "CLAUDE.md" }, + codex: { key: "codex", label: "Codex", binary: "codex", memoryFile: "AGENTS.md" }, + custom: { key: "custom", label: "Custom", binary: "codex", memoryFile: "AGENTS.md" }, +}; + +export const ENGINE_KEYS = Object.keys(ENGINE_REGISTRY) as EngineKey[]; + +export function engineBinary(key: EngineKey): "claude" | "codex" { + return ENGINE_REGISTRY[key].binary; +} + +// Persisted logs may carry a cli string this build doesn't know (a newer engine, or a +// hand-edited log). Unknown strings behave like codex - the passthrough binary - so +// readers keep working instead of crashing on the union. +export function coerceEngineKey(cli: string): EngineKey { + return (ENGINE_KEYS as string[]).includes(cli) ? (cli as EngineKey) : "codex"; +} + +// Hosts receive `cli` as an untrusted message field, but installs, updates and +// sign-outs act on the BINARY, so "custom" (and any unknown or non-string value) +// resolves through the registry to the CLI process it runs on. One derivation for +// every host instead of a copy in each message handler. +export function messageBinary(cli: unknown): "claude" | "codex" { + return engineBinary(coerceEngineKey(typeof cli === "string" ? cli : "claude")); +} diff --git a/packages/core/src/runtime/index.ts b/packages/core/src/runtime/index.ts index b21c8ad4..bbbc4b03 100644 --- a/packages/core/src/runtime/index.ts +++ b/packages/core/src/runtime/index.ts @@ -22,6 +22,8 @@ import { readSkillManifest, skillOrigin, type SkillManifest } from "../skill-mar import { slugifyName } from "../skill-market/ingest/convert.js"; import { resolveRpcUrl, hasDasRpc, loadGithubToken } from "../core/rpc.js"; import { getCodexApiKey } from "../account/codexAuth.js"; +import { loadCustomEngineConfig } from "../account/customEngineAuth.js"; +import { engineBinary, type EngineKey } from "./engineRegistry.js"; import type { ApprovalChannel, ApprovalRequest } from "./approval/channel.js"; import type { AgentRuntime, @@ -59,7 +61,7 @@ function nftSkillActivation(name: string, manifest: SkillManifest): SkillActivat // surface has bundled the standalone entry and points AGENTNET_MCP_STDIO at it. Trading // (buy/publish) stays Claude-only until Codex's MCP-tool approval is routed to the card. async function buildPassiveSpawn( - cli: "claude" | "codex", + cli: EngineKey, wallet: Wallet, onMarketEvent?: (e: import("../chat/marketMessages.js").MarketEvent) => void, ): Promise<{ mcpServers?: Record; allowedTools?: string[]; codexMcp?: { name: string; command: string; args: string[] } }> { @@ -82,7 +84,8 @@ async function buildPassiveSpawn( // Codex (Phase 1): a separate `node ` stdio MCP server, read-only. Needs the // surface to have bundled the entry (AGENTNET_MCP_STDIO) AND a readable catalog (DAS). - if (cli === "codex") { + // Custom rides the codex binary, so it takes the codex path here too. + if (engineBinary(cli) === "codex") { const entry = process.env.AGENTNET_MCP_STDIO; if (!entry || !(await hasDasRpc())) return {}; // command = "node" (PATH-resolved by codex when it spawns the server), NOT @@ -132,13 +135,17 @@ export function createRuntime( return { async startSession(opts): Promise { const device = await getDeviceProfile(); + // Everything that speaks to the CLI process itself (resume jsonl, memory files, + // MCP wiring) keys on the BINARY, so "custom" behaves exactly like codex there + // while opts.cli stays the persisted engine identity. + const binary = engineBinary(opts.cli); // RESUME: opts.sessionId is the CANONICAL id. Rewrite its history into the // target cli's native jsonl and resume under the NATIVE id (claude/codex only // accept their own ids) — this is what lets a session cross between CLIs. // FRESH: no sessionId; the cli mints its own, which becomes the canonical id. const resuming = !!opts.sessionId; const resumeResult = resuming - ? await prepareResume(store, opts.cli, opts.cwd, opts.sessionId!, opts.ephemeral) + ? await prepareResume(store, binary, opts.cwd, opts.sessionId!, opts.ephemeral) : undefined; const nativeId = resumeResult?.nativeId; @@ -163,19 +170,19 @@ export function createRuntime( // effort — a memory/storage hiccup must not block starting the session. let enabledSkills: string[] | undefined; try { - await memory.injectAtStart(opts.cli, opts.cwd); + await memory.injectAtStart(binary, opts.cwd); // Soul rides the same best-effort inject: a stored persona lands in the CLI's // global instruction file (fenced block); no soul stored → no-op. - await injectSoulNative(opts.cli, souls); + await injectSoulNative(binary, souls); // After memory is written, refresh the managed "your skills" line so the agent // passively knows which skills are installed (no system-prompt nudge, no RPC). // Must run AFTER injectAtStart, which regenerates MEMORY.md / AGENTS.md. - const skills = await updateSkillsSection(opts.cli, opts.cwd); - if (opts.cli === "claude" && skills.length) enabledSkills = skills.map((s) => s.name); + const skills = await updateSkillsSection(binary, opts.cwd); + if (binary === "claude" && skills.length) enabledSkills = skills.map((s) => s.name); // Same managed-block machinery: on a surface that hands back browser links (gated on // AGENTNET_PREVIEW_HINT inside), tell the agent to serve web apps on a loopback port // and reply with the http://localhost:PORT link; elsewhere the block self-removes. - await updatePreviewSection(opts.cli, opts.cwd); + await updatePreviewSection(binary, opts.cwd); } catch (e) { console.warn("[memory] inject failed:", e); } @@ -192,6 +199,14 @@ export function createRuntime( // per-session approval channel (each panel passes its own) wins; fall back to // the runtime-level default channel. const apiKey = opts.apiKey || (opts.cli === "codex" ? (await getCodexApiKey().catch(() => undefined)) ?? undefined : undefined); + // Custom engine (issue #209): hand the saved endpoint config to spawn, which turns + // it into -c model_providers overrides + CUSTOM_ENGINE_API_KEY on the codex binary. + // A missing config must fail LOUDLY: swallowing it into undefined would spawn stock + // codex, silently sending the user's prompts to their own OpenAI account. + const custom = opts.cli === "custom" ? (await loadCustomEngineConfig().catch(() => null)) ?? undefined : undefined; + if (opts.cli === "custom" && !custom) { + throw new Error("Custom engine is not configured. Connect an endpoint before starting a custom session."); + } // Hand the configured GitHub token to the agent so its git can clone/push private repos // (e.g. on mobile, where the proot guest has no credentials). spawn.ts turns it into a // github.com-scoped, process-scoped credential helper — the user's global git is untouched. @@ -204,7 +219,7 @@ export function createRuntime( const stamped = channel && { request: (req: ApprovalRequest) => channel.request({ ...req, sessionId: opts.sessionId || req.sessionId }), }; - const cli = spawnCli({ ...opts, sessionId: nativeId, reinject: resumeResult?.reinject, approval: stamped, apiKey, githubToken, enabledSkills, ...passive }); + const cli = spawnCli({ ...opts, sessionId: nativeId, reinject: resumeResult?.reinject, approval: stamped, apiKey, custom, githubToken, enabledSkills, ...passive }); // Storage key stays the CANONICAL id while resuming; the cli's emitted (native) // id must NOT overwrite it, or appended turns land in the wrong log. @@ -272,7 +287,7 @@ export function createRuntime( }); // Capture any memory Claude wrote this turn back to Drive (stock Codex never // writes memory, so only Claude is captured). Fire-and-forget; best effort. - if (opts.cli === "claude") { + if (binary === "claude") { void memory.captureFromClaude(opts.cwd).catch((e) => console.warn("[memory] capture failed:", e), ); diff --git a/packages/core/src/runtime/spawn.ts b/packages/core/src/runtime/spawn.ts index aaf18b52..93af2053 100644 --- a/packages/core/src/runtime/spawn.ts +++ b/packages/core/src/runtime/spawn.ts @@ -34,6 +34,8 @@ import type { import { autoApprove } from "./approval/channel.js"; import { resolveEngineBin } from "./engineBin.js"; import { spawnEngine as spawn, spawnClaudeProcess } from "./engineProcess.js"; +import { engineBinary, type EngineKey } from "./engineRegistry.js"; +import type { CustomEngineConfig } from "../account/customEngineAuth.js"; // Loosely-typed view of AskUserQuestion's raw input (the SDK hands us `unknown`-ish data). type ApprovalQuestionInput = { @@ -86,7 +88,7 @@ export interface Engine { } export interface SpawnOpts { - cli: "claude" | "codex"; + cli: EngineKey; cwd: string; sessionId?: string; // NATIVE resume id (inject/prepareResume resolved it already) // codex: called when thread/resume of sessionId is rejected. Returns a fresh native id @@ -111,6 +113,10 @@ export interface SpawnOpts { codexMcp?: { name: string; command: string; args: string[] }; stream?: boolean; // emit partial assistant deltas (claude includePartialMessages) apiKey?: string; // Stage 1 Codex API Key + // Custom engine (issue #209): the saved endpoint config. Turned into -c + // model_providers overrides on the codex binary (customProviderFlags); the key + // rides CUSTOM_ENGINE_API_KEY in the child env, never argv. + custom?: CustomEngineConfig; githubToken?: string; // configured GitHub PAT, injected into the agent's git env (see gitCredentialEnv) ephemeral?: boolean; // If true, disable tools / auto-deny approvals effort?: "low" | "medium" | "high" | "xhigh" | "max"; @@ -170,7 +176,15 @@ function codexSandbox(mode: string | undefined, envSandbox: string | undefined): } export function spawnCli(opts: SpawnOpts): Engine { - return opts.cli === "claude" ? claudeEngine(opts) : codexEngine(opts); + // Last gate against silent egress: a "custom" spawn without its endpoint config + // would run stock codex against the user's own OpenAI login. The runtime throws + // earlier too (startSession); this catches any caller that skips it. + if (opts.cli === "custom" && !opts.custom) { + throw new Error("Custom engine is not configured. Connect an endpoint before starting a custom session."); + } + // Registry-driven: the descriptor's binary picks the engine implementation, so + // "custom" runs through codexEngine (a provider passthrough, see opts.custom). + return engineBinary(opts.cli) === "claude" ? claudeEngine(opts) : codexEngine(opts); } // Coalesce partial assistant/thinking snapshots to ~frame rate. Partials arrive at token @@ -229,8 +243,8 @@ function callbacks() { // Codex carries the authoritative `modelContextWindow` per turn (we prefer it when // present); Claude's SDK exposes no window field, so we fall back to the published // model limit. Keep in sync with the constants the surfaces used to hardcode. -function defaultWindow(cli: "claude" | "codex", _model?: string): number { - return cli === "codex" ? 256_000 : 200_000; +function defaultWindow(cli: EngineKey, _model?: string): number { + return cli === "claude" ? 200_000 : 256_000; } function loadPersistentWhitelist(): Set { @@ -538,6 +552,37 @@ export function codexMcpFlags(m: { name: string; command: string; args: string[] ]; } +// Build the `-c model_providers.custom.*` overrides that point the codex binary at a +// custom OpenAI-compatible endpoint (issue #209). Same process-scoped mechanism as +// codexMcpFlags; the API key stays out of argv (env_key names CUSTOM_ENGINE_API_KEY, +// which codexEngine sets in the child env). Keyless endpoints (ollama/lmstudio) get +// no env_key at all, so codex sends unauthenticated requests instead of tripping over +// an env var that was never set. +export function customProviderFlags(cfg: CustomEngineConfig): string[] { + // With no model override codex quietly falls back to its own global default model + // name, which the endpoint almost certainly does not serve. saveCustomEngineConfig + // already rejects a blank model; this guards configs saved before that rule. + if (!cfg.model) { + throw new Error("The custom engine needs a model id; codex would otherwise silently use its own default model."); + } + return [ + "-c", `model_providers.custom.name=${JSON.stringify(cfg.label ?? cfg.presetId)}`, + "-c", `model_providers.custom.base_url=${JSON.stringify(cfg.baseUrl)}`, + // env_key is ALWAYS declared, even keyless: without it codex falls back to its + // own login and sends the user's real ChatGPT bearer token to the custom + // endpoint (verified live against a logging endpoint). A keyless config gets + // the harmless placeholder below instead of the user's identity. + "-c", `model_providers.custom.env_key=${JSON.stringify("CUSTOM_ENGINE_API_KEY")}`, + "-c", `model_provider=${JSON.stringify("custom")}`, + "-c", `model=${JSON.stringify(cfg.model)}`, + ]; +} + +// What a keyless custom endpoint receives as its bearer value. Codex refuses an +// empty env var and, with no env_key at all, substitutes the user's own ChatGPT +// token, so keyless MUST mean "harmless constant", never "codex decides". +export const CUSTOM_ENGINE_KEYLESS_PLACEHOLDER = "keyless"; + // ── codex: app-server JSON-RPC over stdio. Spawns `codex app-server --stdio` // and processes requests and notifications, routing approvals to the ApprovalChannel. function codexEngine(opts: SpawnOpts): Engine { @@ -567,6 +612,13 @@ function codexEngine(opts: SpawnOpts): Engine { if (opts.apiKey) { childEnv.OPENAI_API_KEY = opts.apiKey; } + // Always set for a custom spawn: the saved key when there is one, else the + // keyless placeholder. Leaving the var unset or empty makes codex substitute + // the user's own ChatGPT bearer token on requests to the custom endpoint, + // which is exactly the credential egress a custom slot must never cause. + if (opts.custom) { + childEnv.CUSTOM_ENGINE_API_KEY = opts.custom.apiKey || CUSTOM_ENGINE_KEYLESS_PLACEHOLDER; + } const mcpFlags = opts.codexMcp ? codexMcpFlags(opts.codexMcp) : []; const codexArgs = ["app-server", "--stdio"]; if (childEnv.AGENTNET_CODEX_DISABLE_PLUGINS === "1") { @@ -575,6 +627,7 @@ function codexEngine(opts: SpawnOpts): Engine { codexArgs.push("--disable", "plugins"); } codexArgs.push(...mcpFlags); + if (opts.custom) codexArgs.push(...customProviderFlags(opts.custom)); const child = spawn(codexPath, codexArgs, { env: childEnv, stdio: ["pipe", "pipe", "pipe"], @@ -843,7 +896,9 @@ function codexEngine(opts: SpawnOpts): Engine { if (params.command) { cmdStr = Array.isArray(params.command) ? params.command.join(" ") : String(params.command); } - const req = toApprovalRequest("codex", sessionId, "Bash", { command: cmdStr }, params.cwd); + // opts.cli, not a hardcoded "codex": the custom engine rides this same path and + // its approval cards must badge as "custom". + const req = toApprovalRequest(opts.cli, sessionId, "Bash", { command: cmdStr }, params.cwd); const key = `bash:${cmdStr}`; if (allowed.has(key)) return sendResponse(msg.id, { decision: verbs.always }); const decision = await approval.request(req); @@ -869,7 +924,7 @@ function codexEngine(opts: SpawnOpts): Engine { } } - const req = toApprovalRequest("codex", sessionId, tool, { file_path: filePath }, opts.cwd); + const req = toApprovalRequest(opts.cli, sessionId, tool, { file_path: filePath }, opts.cwd); if (diff) req.diff = diff; const key = `${tool}:${filePath}`; @@ -879,7 +934,7 @@ function codexEngine(opts: SpawnOpts): Engine { if (decision.outcome === "deny") deliverDenyReason(decision.reason); } else { const pathStr = params.grantRoot || ""; - const req = toApprovalRequest("codex", sessionId, "Edit", { file_path: pathStr }, opts.cwd); + const req = toApprovalRequest(opts.cli, sessionId, "Edit", { file_path: pathStr }, opts.cwd); req.title = `Allow file changes under ${pathStr || "workspace"}`; if (params.reason) { req.title += ` (${params.reason})`; @@ -892,7 +947,7 @@ function codexEngine(opts: SpawnOpts): Engine { if (decision.outcome === "deny") deliverDenyReason(decision.reason); } } else if (msg.method === "item/permissions/requestApproval") { - const req = toApprovalRequest("codex", sessionId, "Permissions", { reason: params.reason }, opts.cwd); + const req = toApprovalRequest(opts.cli, sessionId, "Permissions", { reason: params.reason }, opts.cwd); req.title = `Grant permissions: ${params.reason || "sandbox access"}`; const decision = await approval.request(req); @@ -918,7 +973,7 @@ function codexEngine(opts: SpawnOpts): Engine { ); const req: ApprovalRequest = { id: randomId(), - cli: "codex", + cli: opts.cli, sessionId, tool: "request_user_input", kind: "question", @@ -1144,7 +1199,7 @@ function codexEngine(opts: SpawnOpts): Engine { // Build a neutral ApprovalRequest from a raw tool name + input (claude tools, or a // codex turn). `kind`/fields let a surface render a good card without re-parsing. function toApprovalRequest( - cli: "claude" | "codex", + cli: EngineKey, sessionId: string, tool: string, input: Record, diff --git a/packages/core/test/fixtures/panel/contract.ts b/packages/core/test/fixtures/panel/contract.ts index 2b011baf..5fbc0f2a 100644 --- a/packages/core/test/fixtures/panel/contract.ts +++ b/packages/core/test/fixtures/panel/contract.ts @@ -99,6 +99,7 @@ export const PANEL_INBOUND_TYPES: string[] = [ "publishProgress", "publishResult", "platform", + "customEngine", "cliStatus", "engineUpdate", "claudeLoginUrl", diff --git a/packages/core/test/fixtures/panel/inbound.ts b/packages/core/test/fixtures/panel/inbound.ts index 31ad83aa..ec1b10ba 100644 --- a/packages/core/test/fixtures/panel/inbound.ts +++ b/packages/core/test/fixtures/panel/inbound.ts @@ -44,6 +44,7 @@ export const PANEL_INBOUND_PAYLOADS: Array<{ type: string } & Record + e === "custom" + ? rep.codex !== "missing" && (await hasCustomEngine()) + : rep[e] === "ok"; + // savedPrefs.lastCli is already coerced by readPrefs, so eff is always a + // registry key even when the prefs file was hand-edited. const eff = options.cli ?? savedPrefs.lastCli ?? "claude"; - const other: "claude" | "codex" = eff === "claude" ? "codex" : "claude"; - if (rep[eff] === "ok") { + // custom never joins the silent fallback scan: auto-routing a claude/codex + // user onto a third-party endpoint would send their prompts and files + // somewhere they never opted into. It boots only when it was ALREADY the + // chosen engine (flag or lastCli) and its config exists; otherwise the + // fallback stays claude/codex, or the login gate shows, as before custom. + const others = ENGINE_KEYS.filter((k) => k !== eff && k !== "custom"); + let fallback: EngineKey | undefined; + if (!options.cli) { + for (const k of others) { + if (await usable(k)) { fallback = k; break; } + } + } + if (await usable(eff)) { await go(addr, wallet); - } else if (!options.cli && rep[other] === "ok") { - setPrefs((p) => ({ ...p, lastCli: other })); - void savePrefs({ lastCli: other }); + } else if (fallback) { + setPrefs((p) => ({ ...p, lastCli: fallback })); + void savePrefs({ lastCli: fallback }); await go(addr, wallet); } else { loginDone.current = (rep2, logged) => { @@ -159,14 +178,16 @@ export function App({ options }: { options: AppOptions }) { } void go(addr, wallet); }; - setLoginPrefer(rep[eff] === "missing" && rep[other] !== "missing" ? other : eff); + // preselect the wanted engine unless its binary is missing while another's isn't. + const alt = others.find((k) => rep[engineBinary(k)] !== "missing"); + setLoginPrefer(rep[engineBinary(eff)] === "missing" && alt ? alt : eff); setPhase("login"); } } else { if (!alive) return; set(3, { status: "ok", label: "storage: pick on next screen", detail: "PICK NEXT" }); setPhase("onboard"); - onboardFinish.current = async (engine: "claude" | "codex", cfg?: StorageConfig) => { + onboardFinish.current = async (engine: EngineKey, cfg?: StorageConfig) => { if (cfg) await chooseStorage(cfg); await savePrefs({ onboarded: true, lastCli: engine }); await go(addr, wallet, !!cfg && cfg.kind !== "local"); @@ -185,10 +206,10 @@ export function App({ options }: { options: AppOptions }) { }, []); // set by the boot effect so Onboarding can finish with the live wallet in scope. - const onboardFinish = React.useRef<(engine: "claude" | "codex", cfg?: StorageConfig) => void>(() => {}); + const onboardFinish = React.useRef<(engine: EngineKey, cfg?: StorageConfig) => void>(() => {}); // login-gate continuation + which engine its picker should preselect. - const loginDone = React.useRef<(rep: CliReport, logged?: "claude" | "codex") => void>(() => {}); - const [loginPrefer, setLoginPrefer] = useState<"claude" | "codex">("claude"); + const loginDone = React.useRef<(rep: CliReport, logged?: EngineKey) => void>(() => {}); + const [loginPrefer, setLoginPrefer] = useState("claude"); if (phase === "error") { return ( @@ -226,7 +247,7 @@ export function App({ options }: { options: AppOptions }) { const effective: AppOptions = { ...options, cli: effectiveCli, - model: options.model ?? sessionModel ?? (effectiveCli === "codex" ? prefs.lastModelCodex : prefs.lastModelClaude), + model: options.model ?? sessionModel ?? prefs[LAST_MODEL_PREF[effectiveCli]], effort: options.effort ?? resumed?.effort ?? prefs.lastEffort, resume: options.resume ?? (options.continue ? prefs.lastSessionId : undefined), }; diff --git a/surfaces/cli/src/commands.ts b/surfaces/cli/src/commands.ts index b2d21e4a..c5420962 100644 --- a/surfaces/cli/src/commands.ts +++ b/surfaces/cli/src/commands.ts @@ -20,7 +20,7 @@ export const SLASH_COMMANDS: SlashCmd[] = [ { name: "compact", desc: "compact the conversation context" }, { name: "clear", desc: "clear the on-screen transcript" }, { name: "copy", desc: "copy the last reply to the clipboard" }, - { name: "engine", desc: "switch engine (carries session)", args: "claude|codex" }, + { name: "engine", desc: "switch engine (carries session)", args: "claude|codex|custom" }, { name: "model", desc: "change model", args: "" }, { name: "models", desc: "pick a model from a menu" }, // levels live in the desc, not args: "/effort low|medium|high|xhigh|max" is wider than diff --git a/surfaces/cli/src/components/Footer.tsx b/surfaces/cli/src/components/Footer.tsx index ec5f69ef..899323b3 100644 --- a/surfaces/cli/src/components/Footer.tsx +++ b/surfaces/cli/src/components/Footer.tsx @@ -1,5 +1,6 @@ import React from "react"; import { Box, Text } from "ink"; +import type { EngineKey } from "@iqlabs-official/agent-sdk"; import { colors } from "../theme.js"; // Bottom hint row — left: keyboard shortcuts, right: engine + model pill. @@ -11,7 +12,7 @@ export function Footer({ model, busy, }: { - cli: "claude" | "codex"; + cli: EngineKey; model?: string; busy: boolean; }) { @@ -50,7 +51,8 @@ export function Footer({ {"● "} - {cli.toUpperCase()} + {/* custom wears the theme's violet accent so the pill says which brain answers */} + {cli.toUpperCase()} · {modelLabel} diff --git a/surfaces/cli/src/components/Header.tsx b/surfaces/cli/src/components/Header.tsx index 213ba381..572f729e 100644 --- a/surfaces/cli/src/components/Header.tsx +++ b/surfaces/cli/src/components/Header.tsx @@ -1,5 +1,6 @@ import React from "react"; import { Box, Text } from "ink"; +import type { EngineKey } from "@iqlabs-official/agent-sdk"; import { colors } from "../theme.js"; import { basename } from "node:path"; @@ -18,13 +19,14 @@ export function Header({ cwd, version = "0.1.0", }: { - cli: "claude" | "codex"; + cli: EngineKey; model?: string; cwd: string; version?: string; }) { - const tint = cli === "codex" ? colors.codex : colors.claude; - const modelLabel = model ?? (cli === "claude" ? "claude sonnet" : "codex"); + // custom wears the theme's violet accent; claude/codex stay monochrome bone. + const tint = cli === "custom" ? colors.iqViolet : cli === "codex" ? colors.codex : colors.claude; + const modelLabel = model ?? (cli === "claude" ? "claude sonnet" : cli); return ( diff --git a/surfaces/cli/src/components/Message.tsx b/surfaces/cli/src/components/Message.tsx index a5930ce7..5809673c 100644 --- a/surfaces/cli/src/components/Message.tsx +++ b/surfaces/cli/src/components/Message.tsx @@ -125,7 +125,7 @@ export function Message({ msg, live }: { msg: ChatMessage; live?: boolean }) { } // assistant - const who = msg.cli === "codex" ? "codex" : "claude"; + const who = msg.cli === "custom" ? "custom" : msg.cli === "codex" ? "codex" : "claude"; return ( diff --git a/surfaces/cli/src/components/WelcomePanel.tsx b/surfaces/cli/src/components/WelcomePanel.tsx index e81e211b..b1bd8fc1 100644 --- a/surfaces/cli/src/components/WelcomePanel.tsx +++ b/surfaces/cli/src/components/WelcomePanel.tsx @@ -1,6 +1,6 @@ import React from "react"; import { Box, Text, useInput } from "ink"; -import { HELIUS_QUICKSTART_URL } from "@iqlabs-official/agent-sdk"; +import { HELIUS_QUICKSTART_URL, type EngineKey } from "@iqlabs-official/agent-sdk"; import { colors, glyph, rule, tag } from "../theme.js"; import { displayWidth, truncateStart, truncateEnd } from "../format.js"; @@ -36,12 +36,14 @@ function Band({ label, value, dim, + tint, focused, }: { width: number; label: string; value: string; dim?: boolean; + tint?: string; // accent for the value (the engine band's custom violet); dim wins focused: boolean; }) { const left = ` ${tag(label)}`; @@ -57,7 +59,7 @@ function Band({ return ( {left} - {fitted + " "} + {fitted + " "} ); } @@ -120,7 +122,7 @@ export function WelcomePanel({ }: { walletAddr: string; cloud: { kind: string; account?: string } | null; - engine: "claude" | "codex"; + engine: EngineKey; heliusMasked: string | null; skills: OwnedSkill[] | null; passive?: string[]; @@ -223,6 +225,7 @@ export function WelcomePanel({ width={bandW} label="engine" value={engine.toUpperCase()} + tint={engine === "custom" ? colors.iqViolet : undefined} focused={active && focus === 2} />, keyInput !== null ? ( diff --git a/surfaces/cli/src/hooks/useChat.ts b/surfaces/cli/src/hooks/useChat.ts index cd4802b0..7d60218e 100644 --- a/surfaces/cli/src/hooks/useChat.ts +++ b/surfaces/cli/src/hooks/useChat.ts @@ -8,8 +8,8 @@ import type { SkillActivation, } from "@iqlabs-official/agent-sdk/runtime/contract"; import type { ApprovalChannel } from "@iqlabs-official/agent-sdk/runtime/approval/channel"; -import type { ChatModelOption } from "@iqlabs-official/agent-sdk"; -import { readPrefs, savePrefs, type EffortLevel } from "../prefs.js"; +import type { ChatModelOption, EngineKey } from "@iqlabs-official/agent-sdk"; +import { readPrefs, savePrefs, LAST_MODEL_PREF, type EffortLevel } from "../prefs.js"; import { loadModelOptions, MODELS } from "../models.js"; // What the status band should CALL the current model. `model` is undefined whenever the @@ -19,12 +19,11 @@ import { loadModelOptions, MODELS } from "../models.js"; // CLI's "default" entry with its real name, e.g. "Opus 4.8"), so resolve through it. // The static baseline answers synchronously so the band never flashes a placeholder; // the live probe upgrades it once the installed CLI reports its real catalog. -function labelFor(cli: Engine, model: string | undefined, catalog: ChatModelOption[]): string | undefined { +function labelFor(model: string | undefined, catalog: ChatModelOption[]): string | undefined { const chosen = model ? catalog.find((o) => o.value === model) : catalog[0]; return chosen?.chipLabel ?? model; } -export type Engine = "claude" | "codex"; export type { EffortLevel }; // What a /more actually did. "exhausted" = no page to fetch (no cursor, or history fully @@ -40,7 +39,7 @@ export type LoadOlderResult = // resume — the runtime re-injects history into the new cli on the next send). export function useChat( runtime: AgentRuntime, - opts: { cli: Engine; model?: string; effort?: EffortLevel; cwd: string; resume?: string; approval?: ApprovalChannel }, + opts: { cli: EngineKey; model?: string; effort?: EffortLevel; cwd: string; resume?: string; approval?: ApprovalChannel }, ) { const [messages, setMessages] = useState([]); // null = the first listSessions has not settled (the WelcomePanel null-means-loading @@ -50,7 +49,7 @@ export function useChat( const [sessions, setSessions] = useState(null); const [sessionsError, setSessionsError] = useState(null); const [busy, setBusy] = useState(false); - const [cli, setCli] = useState(opts.cli); + const [cli, setCli] = useState(opts.cli); const [model, setModel] = useState(opts.model); const [effort, setEffort] = useState(opts.effort); const [pendingId, setPendingId] = useState(opts.resume); @@ -73,16 +72,16 @@ export function useChat( const [turnError, setTurnError] = useState(null); const [firingSkill, setFiringSkill] = useState(null); const [modelLabel, setModelLabel] = useState(() => - labelFor(opts.cli, opts.model, MODELS[opts.cli]), + labelFor(opts.model, MODELS[opts.cli]), ); // Re-resolve the display name whenever the engine or the override changes. useEffect(() => { let live = true; - setModelLabel(labelFor(cli, model, MODELS[cli])); // instant, from the static baseline + setModelLabel(labelFor(model, MODELS[cli])); // instant, from the static baseline void loadModelOptions(cli) .then((catalog) => { - if (live) setModelLabel(labelFor(cli, model, catalog)); + if (live) setModelLabel(labelFor(model, catalog)); }) .catch(() => { /* probe failed — the baseline label already on screen is the right fallback */ @@ -339,7 +338,7 @@ export function useChat( }, [dropHandle]); const switchEngine = useCallback( - (next: Engine) => { + (next: EngineKey) => { if (next === cliRef.current) return; dropHandle(); setCli(next); @@ -349,7 +348,7 @@ export function useChat( // a model id is engine-specific (claude's "sonnet" is a 400 on codex's API and vice // versa) — load whatever the NEW engine last used (or its own default) instead of // carrying over the previous engine's model string. - void readPrefs().then((p) => setModel(next === "codex" ? p.lastModelCodex : p.lastModelClaude)); + void readPrefs().then((p) => setModel(p[LAST_MODEL_PREF[next]])); }, [dropHandle], ); @@ -360,7 +359,7 @@ export function useChat( setModel(m); setContextTokens(undefined); setContextWindow(undefined); - void savePrefs(cliRef.current === "codex" ? { lastModelCodex: m } : { lastModelClaude: m }); + void savePrefs({ [LAST_MODEL_PREF[cliRef.current]]: m }); }, [dropHandle], ); diff --git a/surfaces/cli/src/models.ts b/surfaces/cli/src/models.ts index 531c0b6f..10d25990 100644 --- a/surfaces/cli/src/models.ts +++ b/surfaces/cli/src/models.ts @@ -1,7 +1,9 @@ import { CHAT_MODEL_OPTIONS, + customModelOption, listClaudeModelOptions, listCodexModelOptions, + loadCustomEngineConfig, type ChatModelOption, type EngineKey, } from "@iqlabs-official/agent-sdk"; @@ -15,6 +17,14 @@ export const MODELS = CHAT_MODEL_OPTIONS; const cache = new Map>(); export function loadModelOptions(cli: EngineKey): Promise { + // The custom catalog is whatever model the saved endpoint config names. Re-read every + // time (a tiny local json) instead of caching, so a reconnect with a different model + // shows up without relaunching; empty when no model is set (endpoint default). + if (cli === "custom") { + return loadCustomEngineConfig().then((cfg) => + cfg ? customModelOption(cfg.model, cfg.label) : MODELS.custom, + ); + } let cached = cache.get(cli); if (!cached) { const probe = diff --git a/surfaces/cli/src/prefs.ts b/surfaces/cli/src/prefs.ts index c794f963..9df356d6 100644 --- a/surfaces/cli/src/prefs.ts +++ b/surfaces/cli/src/prefs.ts @@ -2,6 +2,7 @@ import { readFile, writeFile, mkdir } from "node:fs/promises"; import { readFileSync } from "node:fs"; import { homedir } from "node:os"; import { join, dirname } from "node:path"; +import { coerceEngineKey, type EngineKey } from "@iqlabs-official/agent-sdk"; // Small CLI-local prefs file (separate from core's storage config). Remembers that the // user finished first-run setup — so we DON'T re-onboard every launch (the "local only" @@ -11,21 +12,37 @@ export type EffortLevel = "low" | "medium" | "high" | "xhigh" | "max"; export interface Prefs { onboarded?: boolean; - lastCli?: "claude" | "codex"; + lastCli?: EngineKey; // per-engine: a claude model id (e.g. "sonnet") is meaningless to codex's API and vice // versa, so each engine remembers its own last model rather than sharing one field. lastModelClaude?: string; lastModelCodex?: string; + lastModelCustom?: string; lastSessionId?: string; lastEffort?: EffortLevel; calm?: boolean; // remembered animation preference } +// Which per-engine field holds an engine's last model: one lookup shared by the read +// side (restore on switch/launch) and the write side (remember on change). +export const LAST_MODEL_PREF = { + claude: "lastModelClaude", + codex: "lastModelCodex", + custom: "lastModelCustom", +} as const satisfies Record; + const prefsFile = () => join(homedir(), ".agentnet", "cli.json"); +// The prefs file is hand-editable and may have been written by a newer build, so lastCli +// can hold a string outside this build's EngineKey union. Coercing it on every read path +// keeps registry lookups downstream (engineBinary, LAST_MODEL_PREF) from crashing boot. +function coerceRead(p: Prefs): Prefs { + return p.lastCli ? { ...p, lastCli: coerceEngineKey(p.lastCli) } : p; +} + export async function readPrefs(): Promise { try { - return JSON.parse(await readFile(prefsFile(), "utf8")) as Prefs; + return coerceRead(JSON.parse(await readFile(prefsFile(), "utf8")) as Prefs); } catch { return {}; } @@ -34,7 +51,7 @@ export async function readPrefs(): Promise { // sync read for the launch path (DelightProvider needs the calm flag before first render). export function readPrefsSync(): Prefs { try { - return JSON.parse(readFileSync(prefsFile(), "utf8")) as Prefs; + return coerceRead(JSON.parse(readFileSync(prefsFile(), "utf8")) as Prefs); } catch { return {}; } diff --git a/surfaces/cli/src/views/Chat.tsx b/surfaces/cli/src/views/Chat.tsx index e78e6b38..9a468416 100644 --- a/surfaces/cli/src/views/Chat.tsx +++ b/surfaces/cli/src/views/Chat.tsx @@ -11,7 +11,7 @@ import type { import type { AppOptions } from "../app.js"; import type { InkApprovalChannel } from "../InkApprovalChannel.js"; import { SLASH_COMMANDS } from "../commands.js"; -import { useChat, type Engine } from "../hooks/useChat.js"; +import { useChat } from "../hooks/useChat.js"; import { useFrameLoop } from "../hooks/useFrameLoop.js"; import { getStorageInfo, @@ -31,6 +31,11 @@ import { ENGINE_INSTALL_COMMAND, NODE_REQUIRED_MESSAGE, NODE_DOWNLOAD_URL, + ENGINE_KEYS, + engineBinary, + hasCustomEngine, + maskedCustomEngine, + type EngineKey, } from "@iqlabs-official/agent-sdk"; import { Select, TextInput } from "@inkjs/ui"; import open from "open"; @@ -333,6 +338,9 @@ export function Chat({ const [market, setMarket] = useState> | null>(null); // installed skill slugs (dir names) — drives the market's "owned" badge. const [installed, setInstalled] = useState([]); + // whether a custom-engine endpoint config is saved on this device; the engine cycle + // offers "custom" only when it is (connecting one flips this via the login gate). + const [customReady, setCustomReady] = useState(false); // bundled/built-in skills present on disk (skill-shopping, make-skill) — split out of the // installed set so the panel can list them plainly, apart from owned NFT skills. const passive = useMemo(() => installed.filter((s) => BUNDLED_SKILLS.includes(s)), [installed]); @@ -340,6 +348,7 @@ export function Chat({ void getStorageInfo().then((info) => setCloud(info ?? null)); void maskedHeliusKey().then(setHeliusMasked); void hasDasRpc().then(setDasReady); + void hasCustomEngine().then(setCustomReady); // owned-skills needs a DAS RPC; best-effort, leave empty on failure. setSkills(null); void ownedSkills(address).then(setSkills).catch(() => setSkills([])); @@ -816,16 +825,33 @@ export function Chat({ // Switch engines only when the target is actually usable — a missing engine gets the // official install command, a logged-out one gets the inline login gate. Both call // sites (panel toggle, /engine) funnel through here so the guard can't be bypassed. - const [engineLogin, setEngineLogin] = useState<{ target: Engine; report: CliReport } | null>(null); - function requestEngine(next: Engine) { - void detectCli().then((rep) => { - if (rep[next] === "ok") { + // "custom" runs through the codex binary and is signed in once an endpoint config is + // saved, so its no-login state routes to the same gate, which shows the connect form. + const [engineLogin, setEngineLogin] = useState<{ target: EngineKey; report: CliReport } | null>(null); + function requestEngine(next: EngineKey) { + void detectCli().then(async (rep) => { + const status = + next === "custom" + ? rep.codex === "missing" ? "missing" : (await hasCustomEngine()) ? "ok" : "no-login" + : rep[next]; + if (status === "ok") { + if (next === "custom" && chat.cli === "custom") { + // re-picking the engine already in use is a manage request, not a switch: + // the gate is the one place a configured endpoint can be reconfigured or + // removed (the stored key cannot be shown back for in-place editing). + setEngineLogin({ target: next, report: rep }); + return; + } chat.switchEngine(next); setNotice(`switched to ${next} (session carries over)`); - } else if (rep[next] === "node-missing") { + } else if (status === "node-missing") { setNotice(`${NODE_REQUIRED_MESSAGE} ${NODE_DOWNLOAD_URL}`); - } else if (rep[next] === "missing") { - setNotice(`${next} is not installed · run: ${ENGINE_INSTALL_COMMAND[next]}`); + } else if (status === "missing") { + setNotice( + next === "custom" + ? `custom engines run through the codex binary · run: ${ENGINE_INSTALL_COMMAND.custom}` + : `${next} is not installed · run: ${ENGINE_INSTALL_COMMAND[next]}`, + ); } else { setEngineLogin({ target: next, report: rep }); } @@ -836,7 +862,9 @@ export function Chat({ // storage picker; wallet copies the address; github is not wired yet. function editPanelField(field: PanelField) { if (field === "engine") { - requestEngine(chat.cli === "claude" ? "codex" : "claude"); + // cycle claude -> codex -> custom; custom joins only once an endpoint is connected. + const order = customReady ? ENGINE_KEYS : ENGINE_KEYS.filter((k) => k !== "custom"); + requestEngine(order[(order.indexOf(chat.cli) + 1) % order.length]); setPanelFocused(false); return; } @@ -1006,9 +1034,9 @@ export function Chat({ setNotice("fresh session... say hi"); return; case "engine": - if (arg === "claude" || arg === "codex") { - requestEngine(arg as Engine); - } else setNotice("usage: /engine claude|codex"); + if ((ENGINE_KEYS as string[]).includes(arg)) { + requestEngine(arg as EngineKey); + } else setNotice("usage: /engine claude|codex|custom"); return; case "model": if (!arg) { @@ -1073,7 +1101,7 @@ export function Chat({ return; } case "context": { - const win = chat.contextWindow ?? (chat.cli === "codex" ? 256_000 : 200_000); + const win = chat.contextWindow ?? (engineBinary(chat.cli) === "codex" ? 256_000 : 200_000); if (chat.contextTokens === undefined) { setNotice(`Context: 0 / ${win.toLocaleString()} tokens. Send a message to measure usage.`); return; @@ -1174,11 +1202,15 @@ export function Chat({ const key = await getCodexApiKey(); lines.push(`engine codex`); lines.push(`auth ${key ? "API key" : "ChatGPT plan (device auth)"}`); + } else if (chat.cli === "custom") { + lines.push(`engine custom`); + lines.push(`auth ${(await maskedCustomEngine()) ?? "not configured"}`); + lines.push(`manage /engine custom to reconfigure or remove the endpoint`); } else { lines.push(`engine claude`); lines.push(`auth subscription`); } - const win = chat.contextWindow ?? (chat.cli === "codex" ? 256_000 : 200_000); + const win = chat.contextWindow ?? (engineBinary(chat.cli) === "codex" ? 256_000 : 200_000); const used = chat.contextTokens ?? Math.round(chat.messages.reduce((n, m) => n + m.text.length, 0) / 4); lines.push(`model ${chat.model ?? "default"}`); lines.push(`ctx used ${used.toLocaleString()} / ${win.toLocaleString()} tokens`); @@ -1227,7 +1259,7 @@ export function Chat({ const mood: Mood = eggMood ?? (pendingApproval ? "tool" : chat.busy ? "thinking" : idle ? "sleeping" : "idle"); // context-left: prefer the engine's REAL per-turn usage; before the first turn reports, // fall back to a rough chars/4 estimate so the meter isn't blank. - const WINDOW = chat.contextWindow ?? (chat.cli === "codex" ? 256_000 : 200_000); + const WINDOW = chat.contextWindow ?? (engineBinary(chat.cli) === "codex" ? 256_000 : 200_000); // Only fall back to char-count estimate when there are actual messages — otherwise // the bar shows 0/200k on every fresh session which is meaningless noise. const usedTokens = @@ -1294,7 +1326,7 @@ export function Chat({ {`effort ${chat.effort ?? "default"}`} {`cwd ${cwd}`} - {"/engine claude|codex · /model · /models · /effort · /efforts to change"} + {"/engine claude|codex|custom · /model · /models · /effort · /efforts to change"} Esc / Enter close @@ -1430,6 +1462,9 @@ export function Chat({ prefer={engineLogin.target} onDone={(_rep, logged) => { setEngineLogin(null); + // re-check instead of trusting `logged`: the gate can also have removed or + // replaced the custom config, and the engine cycle must reflect that. + void hasCustomEngine().then(setCustomReady); if (logged) { chat.switchEngine(logged); setNotice(`switched to ${logged} (session carries over)`); diff --git a/surfaces/cli/src/views/LoginGate.tsx b/surfaces/cli/src/views/LoginGate.tsx index c9b4cdad..903cbc4d 100644 --- a/surfaces/cli/src/views/LoginGate.tsx +++ b/surfaces/cli/src/views/LoginGate.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useRef, useState } from "react"; import { Box, Text, useInput } from "ink"; -import { Select, TextInput } from "@inkjs/ui"; +import { PasswordInput, Select, TextInput } from "@inkjs/ui"; import open from "open"; import { detectCli, @@ -12,6 +12,14 @@ import { ENGINE_INSTALL_COMMAND, NODE_REQUIRED_MESSAGE, NODE_DOWNLOAD_URL, + CUSTOM_ENGINE_PRESETS, + CUSTOM_ENGINE_EGRESS_WARNING, + CUSTOM_ENGINE_TOOL_WARNING, + saveCustomEngineConfig, + clearCustomEngineConfig, + maskedCustomEngine, + type CustomEnginePreset, + type EngineKey, type CliReport, type CliStatus, type ClaudeLogin, @@ -19,7 +27,7 @@ import { } from "@iqlabs-official/agent-sdk"; import { colors, glyph } from "../theme.js"; -type Step = "pick" | "claude" | "codex"; +type Step = "pick" | "claude" | "codex" | "custom" | "customManage" | "customRemove"; function statusText(s: CliStatus): { text: string; color: string } { if (s === "ok") return { text: `${glyph.ok} logged in`, color: colors.ok }; @@ -28,29 +36,133 @@ function statusText(s: CliStatus): { text: string; color: string } { return { text: "not installed", color: colors.err }; } +// Connect form for a custom OpenAI-compatible endpoint (issue #209): preset pick, then +// base URL, API key, and model, saved to the device-local config store. One flow shared +// by the login gate and first-run onboarding, so the copy and fields can never drift. +// `replacing` marks a reconfigure of an existing endpoint: the stored key can never be +// shown back, so the form warns that saving replaces the whole config, key included. +export function CustomEngineForm({ onSaved, replacing }: { onSaved: () => void; replacing?: boolean }) { + const [stage, setStage] = useState<"preset" | "baseUrl" | "key" | "model">("preset"); + const [preset, setPreset] = useState(CUSTOM_ENGINE_PRESETS[0]); + const [baseUrl, setBaseUrl] = useState(""); + const [apiKey, setApiKey] = useState(""); + const [err, setErr] = useState(null); + + function submitModel(model: string) { + void saveCustomEngineConfig({ + baseUrl, + apiKey, + model, + presetId: preset.id, + label: preset.label, + }) + .then(onSaved) + .catch((e: unknown) => setErr(e instanceof Error ? e.message : String(e))); + } + + return ( + + {CUSTOM_ENGINE_EGRESS_WARNING} + {CUSTOM_ENGINE_TOOL_WARNING} + {replacing ? ( + saving replaces the current endpoint, key included. The saved key cannot be shown back, so enter it again. + ) : null} + {stage === "preset" && ( + + pick an endpoint: + { if (v === "skip") void finish(); - else pick(v as "claude" | "codex"); + else pick(v as EngineKey); }} /> @@ -193,6 +337,50 @@ export function LoginGate({ ); } + if (step === "customManage") { + return ( + + custom engine + configured: {customMasked} + + )} + {step === "customConfig" && ( + + connect a custom engine + setStep("storage")} /> + + )} + {step === "codexApiKey" && ( Enter your OpenAI API Key: - diff --git a/surfaces/localhost/src/index.ts b/surfaces/localhost/src/index.ts index 445eba9a..fb71decd 100644 --- a/surfaces/localhost/src/index.ts +++ b/surfaces/localhost/src/index.ts @@ -43,6 +43,13 @@ import { startCodexLogin, markCodexConnected, saveCodexApiKey, + saveCustomEngineConfig, + loadCustomEngineConfig, + clearCustomEngineConfig, + maskedCustomEngine, + CUSTOM_ENGINE_PRESETS, + customModelOption, + messageBinary, logoutClaude, logoutCodex, getEngineVersions, @@ -537,6 +544,12 @@ async function pushCliStatus(c: Client) { c.send({ type: "cliStatus", claude: cli.claude, codex: cli.codex }); } +// Masked custom-engine summary + core's preset catalog (issue #209). The raw key/URL +// stay host-side; the UI only ever sees this view. +async function pushCustomEngine(c: Client) { + c.send({ type: "customEngine", masked: await maskedCustomEngine(), presets: CUSTOM_ENGINE_PRESETS }); +} + // Engines with an npm update in flight — a second tap must not start a parallel install. const enginesUpdating = new Set<"claude" | "codex">(); @@ -606,8 +619,36 @@ function attachAuthHandlers(c: Client) { c.send({ type: "codexLoginStatus", status: "error", error: (e as Error).message }); } return; + case "getCustomEngine": + await pushCustomEngine(c); + return; + case "saveCustomEngine": + if (typeof m.baseUrl !== "string" || !m.baseUrl.trim()) return; + try { + await saveCustomEngineConfig({ + baseUrl: m.baseUrl.trim(), + apiKey: typeof m.apiKey === "string" ? m.apiKey.trim() : "", + model: typeof m.model === "string" ? m.model.trim() : "", + presetId: typeof m.presetId === "string" && m.presetId ? m.presetId : "manual", + label: typeof m.label === "string" && m.label ? m.label : undefined, + }); + c.send({ type: "toast", text: "Custom engine saved." }); + await pushCustomEngine(c); + } catch (e) { + c.send({ type: "toast", text: `Custom engine save failed: ${(e as Error).message}` }); + } + return; + case "clearCustomEngine": + try { + await clearCustomEngineConfig(); + c.send({ type: "toast", text: "Custom engine removed." }); + await pushCustomEngine(c); + } catch (e) { + c.send({ type: "toast", text: `Custom engine remove failed: ${(e as Error).message}` }); + } + return; case "logoutEngine": { - const engine = m.cli === "codex" ? "codex" : "claude"; + const engine = messageBinary(m.cli); try { if (engine === "codex") await logoutCodex(); else await logoutClaude(); @@ -626,7 +667,7 @@ function attachAuthHandlers(c: Client) { // engine is missing, host-side on the user's tap. // No browser, no link — see engineVersions.ts for why. One update at a time per // engine; the UI disables its button on "running". - const engine = m.cli === "codex" ? "codex" : "claude"; + const engine = messageBinary(m.cli); if (enginesUpdating.has(engine)) return; enginesUpdating.add(engine); c.send({ type: "engineUpdateStatus", cli: engine, status: "running" }); @@ -1082,11 +1123,15 @@ function attachChat(id: string, c: Client, rt: AgentRuntime) { approval, // Live model catalog from the installed CLI (same auth, no extra cost); the picker // falls back to the static baseline when the probe returns null. Cached per engine so - // the subprocess spins up once, not on every picker open. + // the subprocess spins up once, not on every picker open. The custom engine has no + // probe: its one model is whatever the stored endpoint config names (uncached, so a + // re-save shows up on the next picker open). modelOptions: async (cli) => - cli === "codex" - ? await (codexModelOptionsPromise ??= listCodexModelOptions().then((r) => r.options).catch(() => null)) - : await (claudeModelOptionsPromise ??= listClaudeModelOptions(process.cwd()).catch(() => null)), + cli === "custom" + ? await loadCustomEngineConfig().then((cfg) => (cfg ? customModelOption(cfg.model, cfg.label) : null)).catch(() => null) + : cli === "codex" + ? await (codexModelOptionsPromise ??= listCodexModelOptions().then((r) => r.options).catch(() => null)) + : await (claudeModelOptionsPromise ??= listClaudeModelOptions(process.cwd()).catch(() => null)), walletAddress: () => walletAddress, storageInfo: async () => ({ info: await getStorageInfo(), options: STORAGE_OPTIONS, googleCredsConfigured: await hasGoogleCreds() }), connectCloud: async (cfg) => { @@ -1129,6 +1174,9 @@ function attachChat(id: string, c: Client, rt: AgentRuntime) { c.send({ type: "init", defaultPath: null, cloudKind: null, hasWallet: !!walletAddress }); c.send({ type: "wallet", address: walletAddress }); await pushCliStatus(c); + // The composer shows the custom chip only when a config exists, so its state + // must land at boot, not just when AI Connections opens. + await pushCustomEngine(c); } }); attachMarketHandlers(c); diff --git a/surfaces/vscode/src/extension.ts b/surfaces/vscode/src/extension.ts index 43961e05..dd7d2ebc 100644 --- a/surfaces/vscode/src/extension.ts +++ b/surfaces/vscode/src/extension.ts @@ -26,6 +26,13 @@ import { markClaudeConnected, startCodexLogin, markCodexConnected, + loadCustomEngineConfig, + clearCustomEngineConfig, + maskedCustomEngine, + customEngineStatus, + CUSTOM_ENGINE_PRESETS, + customModelOption, + messageBinary, logoutClaude, logoutCodex, marketplaceEnv, @@ -213,6 +220,15 @@ async function pushCliStatus(transport: WebviewTransport) { // so a new chat does not re-surface the banner. Reset naturally on the next VS Code restart. const engineUpdateDismissed = new Set<"claude" | "codex">(); +// Masked custom-engine summary + core's preset catalog (issue #209). The raw key/URL +// stay host-side; the webview only ever sees this view. The chat panel uses `masked` +// as its custom-tab gate and has no connect form, so a null rides out unless a custom +// session could actually spawn (binary + config, core's one readiness answer). +async function pushCustomEngine(transport: WebviewTransport) { + const status = await customEngineStatus(); + transport.send({ type: "customEngine", masked: status.ready ? await maskedCustomEngine() : null, presets: CUSTOM_ENGINE_PRESETS }); +} + // After an install was launched from the notice button, re-check until the engine stops // reporting "missing" (bounded: ~5 min), then push the fresh status so the webview moves // on to the sign-in guidance by itself. One watcher per engine; a second click reuses it. @@ -239,9 +255,25 @@ function attachAuthHandlers(transport: WebviewTransport) { transport.onRecv(async (m: any) => { switch (m?.type) { case "ready": + await pushCliStatus(transport); + // The chat panel shows the custom tab only while a config exists (it handles + // the customEngine push both ways), so its state must land at boot too. The + // panel carries no connect form in this spike, so the host handles no + // getCustomEngine/saveCustomEngine: connecting happens in the AgentNet app. + await pushCustomEngine(transport); + return; case "getCliStatus": await pushCliStatus(transport); return; + case "clearCustomEngine": + try { + await clearCustomEngineConfig(); + transport.send({ type: "toast", text: "Custom engine removed." }); + await pushCustomEngine(transport); + } catch (e) { + transport.send({ type: "toast", text: `Custom engine remove failed: ${errorMessage(e)}` }); + } + return; case "startClaudeLogin": try { claudeLogin?.cancel(); @@ -306,7 +338,7 @@ function attachAuthHandlers(transport: WebviewTransport) { // background: the user consented via the notice button, sees the exact command, // and can watch or abort it. After an install, poll detectCli until the engine // shows up so the webview flips from "missing" without a manual reload. - const engine = m.cli === "codex" ? "codex" : "claude"; + const engine = messageBinary(m.cli); const command = m.update ? CODEX_UPDATE_COMMAND : ENGINE_INSTALL_COMMAND[engine]; const term = vscode.window.createTerminal(`AgentNet: ${m.update ? "update" : "install"} ${engine}`); term.show(); @@ -318,7 +350,7 @@ function attachAuthHandlers(transport: WebviewTransport) { if (m.cli === "claude" || m.cli === "codex") engineUpdateDismissed.add(m.cli); return; case "logoutEngine": { - const engine = m.cli === "codex" ? "codex" : "claude"; + const engine = messageBinary(m.cli); try { if (engine === "codex") await logoutCodex(); else await logoutClaude(); @@ -651,7 +683,9 @@ async function openChat(context: vscode.ExtensionContext, column = vscode.ViewCo approval, claimSession, modelOptions: async (cli) => - cli === "codex" ? (await codexModelOptionsPromise)?.options ?? null : await claudeModelOptionsPromise, + cli === "custom" + ? await loadCustomEngineConfig().then((cfg) => (cfg ? customModelOption(cfg.model, cfg.label) : null)).catch(() => null) + : cli === "codex" ? (await codexModelOptionsPromise)?.options ?? null : await claudeModelOptionsPromise, searchSkills: async (query, kind) => (await marketPromise).searchSkills(query, kind), getSkillDetail: async (mint) => (await marketPromise).getSkillDetail(mint), // local SKILL.md body for the equipped-skill popup (mint-less skills); without this diff --git a/surfaces/webview/src/App.tsx b/surfaces/webview/src/App.tsx index c1a467a9..16363e01 100644 --- a/surfaces/webview/src/App.tsx +++ b/surfaces/webview/src/App.tsx @@ -24,9 +24,10 @@ import { haptics } from "./haptics"; // connecting → opening SSE stream / sent `ready`, waiting for init|sessions // claudeAuth → connect the Claude subscription; dismissable back to chat // codexAuth → device-auth (open URL, enter code); dismissable back to chat +// customAuth → AI Connections endpoint form (custom has no account login); dismissable // chat → runtime ready → the tab shell export function App() { - const { state, getClientId, send, closeMarket, clearCelebrate } = useStore(); + const { state, getClientId, send, closeMarket, clearCelebrate, dismissAuth } = useStore(); useVisualViewportVars(); useKeyboardChrome(); @@ -138,6 +139,9 @@ export function App() { {(state.phase === "connecting" || state.phase === "restoring") && } {state.phase === "claudeAuth" && } {state.phase === "codexAuth" && } + {/* custom engine's "sign-in" is the AI Connections endpoint form, so the phase + mounts Sessions straight on that screen instead of a device-auth flow. */} + {state.phase === "customAuth" && } {state.phase === "chat" && }
diff --git a/surfaces/webview/src/chat/Composer.tsx b/surfaces/webview/src/chat/Composer.tsx index d42e65e5..e7b20b30 100644 --- a/surfaces/webview/src/chat/Composer.tsx +++ b/surfaces/webview/src/chat/Composer.tsx @@ -1,5 +1,5 @@ import { useEffect, useRef, useState } from "react"; -import { useStore, isApprovalForView } from "../state/store"; +import { useStore, isApprovalForView, engineStatus } from "../state/store"; import { enqueueLiveImages } from "./liveImages"; import type { Cli, ImageInput } from "../transport/protocol"; import { AttachIcon } from "../icons"; @@ -160,6 +160,14 @@ const EFFORTS = [ { value: "max", label: "max" }, ]; +// Codex's modes serve the custom engine too: custom IS the codex binary pointed at +// another endpoint, so its sandbox/approval chips are identical. +const CODEX_MODES = [ + { value: "readonly", label: "Read only", title: "Read-only sandbox; ask before edits, commands, network" }, + { value: "auto", label: "Auto accept", title: "Auto-accept edits + run inside the workspace; approve on failure (default)" }, + { value: "full", label: "Full access", title: "Full disk + network access, never ask (use with care)" }, +]; + const MODES: Record = { // Kept in the SAME order + wording as the VSCode surface (webview.ts) so the modes read // identically everywhere — the SDK's native permission-mode order. @@ -169,11 +177,16 @@ const MODES: Record = { { value: "plan", label: "Plan", title: "Plan mode: read-only until you approve the plan" }, { value: "bypassPermissions", label: "Bypass", title: "Bypass all permission prompts (--dangerously-skip-permissions). Auto-runs every command, edit, and on-chain spend. Use with care." }, ], - codex: [ - { value: "readonly", label: "Read only", title: "Read-only sandbox; ask before edits, commands, network" }, - { value: "auto", label: "Auto accept", title: "Auto-accept edits + run inside the workspace; approve on failure (default)" }, - { value: "full", label: "Full access", title: "Full disk + network access, never ask (use with care)" }, - ], + codex: CODEX_MODES, + custom: CODEX_MODES, +}; + +// The active engine tints the composer border + chip (claude = orange, codex = green, +// custom = violet) so the input itself shows which platform you're talking to. +const ENGINE_ACCENTS: Record = { + claude: "var(--claude)", + codex: "var(--an-green)", + custom: "var(--an-violet)", }; function slashCommandsForCli(cli: Cli): { name: string; desc: string; insert: string }[] { @@ -235,9 +248,9 @@ export function Composer() { // the first real model when `model` isn't in the list (initial, or after a live upgrade). const models = toModelRows(state.modelCatalog[state.cli]); const selectedModel = models.some((m) => m.value === model) ? model : (models[0]?.value ?? "default"); - // The active engine tints the composer border (claude = orange, codex = green) so the - // input itself shows which platform you're talking to — vscode's folder-tab idea. - const engineAccent = state.cli === "claude" ? "var(--claude)" : "var(--an-green)"; + const engineAccent = ENGINE_ACCENTS[state.cli]; + // The custom chip appears only once the host reports a stored endpoint config. + const engines: Cli[] = state.customEngine?.masked ? ["claude", "codex", "custom"] : ["claude", "codex"]; // Voice dictation via the platform Web Speech API (Android WebView / Chrome support it). // Interim results stream into the textarea; a second tap stops. Silent no-op if absent. @@ -283,7 +296,7 @@ export function Composer() { // Tapping it opens the login screen; everything else in the app stays reachable. No // report yet (boot) counts as unlocked so the composer doesn't flash locked for // signed-in users. - const engineLocked = !!state.cliReport && state.cliReport[state.cli] !== "ok"; + const engineLocked = !!state.cliReport && engineStatus(state, state.cli) !== "ok"; const [slashIdx, setSlashIdx] = useState(0); const [suppressSlash, setSuppressSlash] = useState(false); @@ -302,7 +315,8 @@ export function Composer() { const prefix = (m[1] || '').toLowerCase(); const options = [ { name: 'claude', desc: 'switch to Claude engine', insert: '/engine claude' }, - { name: 'codex', desc: 'switch to Codex engine', insert: '/engine codex' } + { name: 'codex', desc: 'switch to Codex engine', insert: '/engine codex' }, + ...(state.customEngine?.masked ? [{ name: 'custom', desc: 'switch to your custom endpoint', insert: '/engine custom' }] : []) ]; activeMatches = options.filter(opt => opt.name.toLowerCase().startsWith(prefix)); } @@ -454,7 +468,7 @@ export function Composer() { setText(""); return; } case "engine": - if (arg === "claude" || arg === "codex") switchEngine(arg); + if (arg === "claude" || arg === "codex" || arg === "custom") switchEngine(arg); setText(""); return; case "model": if (arg) send({ type: "model", model: arg }); @@ -466,13 +480,26 @@ export function Composer() { if (arg) { setEffort(arg); send({ type: "effort", effort: arg === "default" ? undefined : arg }); } setText(""); return; case "login": { - const target = arg === "claude" || arg === "codex" ? arg : state.cli; + // Only the two binaries hold accounts. On the custom engine, "signing in" + // means saving an endpoint config, so point at the form instead of starting + // a Codex device auth the user never asked for. + if (state.cli === "custom" && arg !== "claude" && arg !== "codex") { + setSlashNotice("Custom endpoints have no login. Connect one under Settings, AI Connections."); + setText(""); return; + } + const target = arg === "claude" || arg === "codex" ? arg : state.cli === "claude" ? "claude" : "codex"; if (target === "claude" && arg && arg !== "claude" && arg !== "codex") send({ type: "claudeAuthCode", code: arg }); else send({ type: target === "claude" ? "startClaudeLogin" : "startCodexLogin" }); setText(""); return; } case "logout": { - const target = arg === "claude" || arg === "codex" ? arg : state.cli; + // Same guard: falling through would resolve custom to the codex BINARY and + // sign the user out of their real Codex account. + if (state.cli === "custom" && arg !== "claude" && arg !== "codex") { + setSlashNotice("Custom endpoints have no login to sign out of. Remove the endpoint under Settings, AI Connections."); + setText(""); return; + } + const target = arg === "claude" || arg === "codex" ? arg : state.cli === "claude" ? "claude" : "codex"; send({ type: "logoutEngine", cli: target }); setText(""); return; } @@ -540,9 +567,9 @@ export function Composer() { live in the popover so the bar stays clean on a phone) */}
- {(["claude", "codex"] as Cli[]).map((c) => { + {engines.map((c) => { const on = state.cli === c; - const accent = c === "claude" ? "var(--claude)" : "var(--an-green)"; + const accent = ENGINE_ACCENTS[c]; return ( + )} + +
+ {open && ( +
+ {presets.length > 0 && ( +
+ {presets.map((p) => ( + + ))} +
+ )} + setBaseUrl(e.target.value)} placeholder="Base URL, https://..." className={inputCls} /> + setApiKey(e.target.value)} type="password" placeholder="API key (leave blank for local endpoints)" className={inputCls} /> + setModel(e.target.value)} placeholder="Model id (required)" className={inputCls} /> +

+ {CUSTOM_ENGINE_EGRESS_WARNING} +

+

+ {CUSTOM_ENGINE_TOOL_WARNING} +

+ {masked && ( +

+ Saving replaces the stored endpoint. The saved key is only ever shown masked, so re-enter it if the endpoint needs one. +

+ )} + +
+ )} + + ); +} + type SettingsMode = "list" | "configure" | "wallet" | "connect" | "gdrive" | "custom" | "helius" | "github" | "engines" | "language"; // The server runs on the host this page came from, so its OS decides whether an @@ -163,7 +276,7 @@ export function Sessions({ const { storage, cloudSync, googleLoginUrl, googleLoginError } = state; const online = useOnline(); // Which engines hold live credentials — drives the AI Connections menu (row subtitle + sub-screen). - const connectedEngines = (["claude", "codex"] as const).filter((c) => state.cliReport?.[c] === "ok"); + const connectedEngines = (["claude", "codex", "custom"] as Cli[]).filter((c) => engineStatus(state, c) === "ok"); const rootMode: SettingsMode = settingsRoot ? "configure" : "list"; const [settingsMode, setSettingsMode] = useState(initialMode ?? rootMode); @@ -183,6 +296,8 @@ export function Sessions({ // no boot-time check — this is the only send site. useEffect(() => { if (settingsMode === "engines" && !state.engineVersions) send({ type: "getEngineVersions" }); + // Same on-demand rule for the custom-engine summary; the host re-pushes after save/clear. + if (settingsMode === "engines" && !state.customEngine) send({ type: "getCustomEngine" }); // eslint-disable-next-line react-hooks/exhaustive-deps }, [settingsMode]); const [showManualCode, setShowManualCode] = useState(false); @@ -769,6 +884,7 @@ export function Sessions({
); })} +

{t(M.engines.note)}

diff --git a/surfaces/webview/src/state/store.tsx b/surfaces/webview/src/state/store.tsx index de46979b..0f13fc23 100644 --- a/surfaces/webview/src/state/store.tsx +++ b/surfaces/webview/src/state/store.tsx @@ -22,6 +22,7 @@ import type { ChatMessage, Cli, ClientMessage, + CustomEnginePreset, EngineVersionInfo, ImageInput, ServerMessage, @@ -55,6 +56,7 @@ export interface State { | "restoring" // Android cold boot: attempting a silent Keystore reconnect (shows Splash, not the signup screen) | "claudeAuth" | "codexAuth" + | "customAuth" // custom engine picked with no saved endpoint: the AI Connections form, not a login | "chat"; // market overlay (accessible from chat phase via "Markets" button) marketOpen: boolean; @@ -92,7 +94,11 @@ export interface State { googleLoginError: string | null; // per-engine install/login status from the post-wallet `cliStatus` event, kept so the // engine picker can show a live badge next to each choice (null until it arrives). + // "custom" is derived from customEngine + the codex binary report (see engineStatus). cliReport: { claude: EngineStatus; codex: EngineStatus } | null; + // custom engine (issue #209): the host's masked config summary (null = none stored) + // plus core's preset catalog for the connect form. null until the host pushes it. + customEngine: { masked: string | null; presets: CustomEnginePreset[] } | null; // Fetched once per session, on first open of AI Connections (server re-pushes after an // update). Never polled — see the getEngineVersions send site. engineVersions: { claude: EngineVersionInfo; codex: EngineVersionInfo } | null; @@ -162,12 +168,23 @@ export function isApprovalForView(a: { sessionId?: string }, activeSessionId?: s return !a.sessionId || !activeSessionId || a.sessionId === activeSessionId; } +// Per-engine readiness, custom included. Custom rides the codex binary with its own +// stored key, so it has no login probe: the codex binary must be installed, and a saved +// endpoint config is its sign-in ("no-login" until one exists). undefined = no report yet. +export function engineStatus(state: State, cli: Cli): EngineStatus | undefined { + if (!state.cliReport) return undefined; + if (cli !== "custom") return state.cliReport[cli]; + if (state.cliReport.codex === "missing" || state.cliReport.codex === "node-missing") return state.cliReport.codex; + return state.customEngine?.masked != null ? "ok" : "no-login"; +} + export const initialState: State = { rateLimits: {}, phase: "connecting", walletAddress: null, cli: "claude", cliReport: null, + customEngine: null, engineVersions: null, engineUpdating: {}, claudeLoginUrl: null, @@ -216,7 +233,7 @@ export const initialState: State = { publishKind: null, firingSkills: [], currentModel: undefined, - modelCatalog: { claude: CHAT_MODEL_OPTIONS.claude, codex: CHAT_MODEL_OPTIONS.codex }, + modelCatalog: { claude: CHAT_MODEL_OPTIONS.claude, codex: CHAT_MODEL_OPTIONS.codex, custom: CHAT_MODEL_OPTIONS.custom }, queuePending: 0, agents: [], agentProfile: null, @@ -231,6 +248,7 @@ export const initialState: State = { modeByCli: { claude: "acceptEdits", codex: "auto", + custom: "auto", }, }; @@ -326,8 +344,12 @@ export function reducer(state: State, ev: Action): State { // wait (the action requests getCliStatus). ok -> chat; otherwise (no-login or // missing) -> the engine's own auth screen handles sign-in / install. if (!state.cliReport) return state; - const status = state.cliReport[ev.cli]; + const status = engineStatus(state, ev.cli); if (status === "ok") return { ...state, cli: ev.cli, phase: "chat" }; + // custom has no account login: its "sign-in" is a saved endpoint config, so it + // routes to the AI Connections form. Sending it to the Codex device auth (as it + // once did) looped users through a login that could never make custom ready. + if (ev.cli === "custom") return { ...state, cli: ev.cli, phase: "customAuth" }; return { ...state, cli: ev.cli, phase: ev.cli === "claude" ? "claudeAuth" : "codexAuth" }; } case "__switchEngine": @@ -355,6 +377,15 @@ export function reducer(state: State, ev: Action): State { // Authentication is progressive too. Stay in chat until a send or explicit engine // switch asks selectEngine() to route to the matching login surface. return { ...state, cliReport: { claude: ev.claude, codex: ev.codex } }; + case "customEngine": + // A non-null masked summary while sitting on the customAuth form means the + // endpoint just got saved (or already existed): custom is usable, drop into chat + // on it, mirroring the claude/codex "login done" routing. + return { + ...state, + customEngine: { masked: ev.masked, presets: ev.presets }, + phase: state.phase === "customAuth" && ev.masked != null ? "chat" : state.phase, + }; case "engineVersions": return { ...state, engineVersions: { claude: ev.claude, codex: ev.codex } }; case "engineUpdateStatus": @@ -507,7 +538,7 @@ export function reducer(state: State, ev: Action): State { return { ...state, toast: ev.text }; case "status": { const s = ev.status; - const win = state.contextWindow ?? (s.cli === "codex" ? 256_000 : 200_000); + const win = state.contextWindow ?? (s.cli === "claude" ? 200_000 : 256_000); const fmtK = (n: number) => n >= 1000 ? Math.round(n / 1000) + "k" : String(n); const ctx = s.contextTokens === undefined ? "" @@ -884,7 +915,7 @@ export function StoreProvider({ children }: { children: ReactNode }) { const actions = useMemo(() => { const selectEngine = (cli: Cli) => { const st = stateRef.current; - const status = st.cliReport?.[cli]; + const status = engineStatus(st, cli); raw({ type: "__selectEngine", cli }); if (!st.cliReport) { void transportRef.current?.post({ type: "getCliStatus" }); @@ -903,7 +934,7 @@ export function StoreProvider({ children }: { children: ReactNode }) { void transportRef.current?.post({ type: "getCliStatus" }); return; } - if (st.cliReport[cli] === "ok" && st.phase === "chat") { + if (engineStatus(st, cli) === "ok" && st.phase === "chat") { void transportRef.current?.post({ type: "platform", cli }); } }; @@ -914,7 +945,7 @@ export function StoreProvider({ children }: { children: ReactNode }) { return; } if (msg.type === "send") { - if (!st.cliReport || st.cliReport[st.cli] !== "ok") { + if (engineStatus(st, st.cli) !== "ok") { selectEngine(st.cli); return; } diff --git a/surfaces/webview/src/transport/protocol.ts b/surfaces/webview/src/transport/protocol.ts index 031ec48e..b95686a8 100644 --- a/surfaces/webview/src/transport/protocol.ts +++ b/surfaces/webview/src/transport/protocol.ts @@ -6,11 +6,13 @@ // Market types are defined once in packages/core and re-exported here so every surface // that imports from this file gets compile-time checking on the market message contract. -export type { SkillCard, SkillDetail, MarketRequest, MarketEvent, RpcStatus, AgentProfile, Reputation } from "@iqlabs-official/agent-sdk"; +export type { SkillCard, SkillDetail, MarketRequest, MarketEvent, RpcStatus, AgentProfile, Reputation, CustomEnginePreset } from "@iqlabs-official/agent-sdk"; // ── shared payload shapes ── -export type Cli = "claude" | "codex"; +// Mirrors core's EngineKey: "custom" is an OpenAI-compatible endpoint run through the +// codex binary (issue #209), configured host-side via the customEngine messages below. +export type Cli = "claude" | "codex" | "custom"; // Version report for one engine: installed comes from the binary, latest from the npm // registry. Requested on demand only (opening AI Connections), never polled. @@ -140,6 +142,12 @@ export type ClientMessage = | { type: "startCodexLogin" } | { type: "cancelCodexLogin" } | { type: "submitCodexApiKey"; key: string } + // custom engine (issue #209): read/save/clear the host-stored endpoint config. + // The API key only travels UI→host on save; the host answers with `customEngine` + // (masked summary + the preset catalog), never the raw key. + | { type: "getCustomEngine" } + | { type: "saveCustomEngine"; baseUrl: string; apiKey: string; model: string; presetId: string; label?: string } + | { type: "clearCustomEngine" } | { type: "logoutEngine"; cli?: Cli } | { type: "startGoogleLogin" } | { type: "googleAuthCode"; code: string } @@ -246,6 +254,10 @@ export type ServerMessage = // codex device-auth: server streams the URL + one-time code; CLI auto-polls (no code submittal). | { type: "codexLoginChallenge"; url: string; code: string } | { type: "codexLoginStatus"; status: "done" | "error"; error?: string } + // custom engine state: masked = endpoint host + dotted key tail (null = no config + // stored). Presets ride along like STORAGE_OPTIONS so the connect form's picker + // shares core's one catalog. Pushed on ready and after save/clear. + | { type: "customEngine"; masked: string | null; presets: import("@iqlabs-official/agent-sdk").CustomEnginePreset[] } | { type: "googleLoginUrl"; url: string } | { type: "googleLoginStatus"; status: "done" | "error"; error?: string } // result of saving user-supplied Google OAuth client credentials (setGoogleCredentials). From a5c6c9430c03307903b5ec05757fc65125fb9bab Mon Sep 17 00:00:00 2001 From: RemilioNubilio <275382225+RemilioNubilio@users.noreply.github.com> Date: Sat, 5 Sep 2026 18:06:56 -0400 Subject: [PATCH 02/12] fix: validate custom engine settings Reject whitespace-only model ids at save time, keep invalid-URL errors from echoing the pasted input (it can contain a key), and correct the keyless-auth comments. The approval policy change that shipped alongside this in the spike now lives in #221 and is not part of this commit. --- packages/core/src/account/customEngineAuth.ts | 2 +- packages/core/src/account/customEngineMeta.ts | 2 +- .../core/src/runtime/customEngine.spec.ts | 16 +++++++++--- packages/core/src/runtime/spawn.ts | 26 +++++++------------ 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/packages/core/src/account/customEngineAuth.ts b/packages/core/src/account/customEngineAuth.ts index 04d8780b..affef357 100644 --- a/packages/core/src/account/customEngineAuth.ts +++ b/packages/core/src/account/customEngineAuth.ts @@ -54,7 +54,7 @@ function normalizeBaseUrl(raw: string): string { try { url = new URL(raw.trim()); } catch { - throw new Error(`The custom engine base URL is not a valid URL: ${raw.trim() || "(empty)"}`); + throw new Error("The custom engine base URL is not a valid URL."); } if (url.protocol !== "http:" && url.protocol !== "https:") { throw new Error(`The custom engine base URL must be http or https, got "${url.protocol.slice(0, -1)}".`); diff --git a/packages/core/src/account/customEngineMeta.ts b/packages/core/src/account/customEngineMeta.ts index a0f979a1..33737bab 100644 --- a/packages/core/src/account/customEngineMeta.ts +++ b/packages/core/src/account/customEngineMeta.ts @@ -7,4 +7,4 @@ export const CUSTOM_ENGINE_EGRESS_WARNING = "Custom engines send your prompts, files, and tool output to the endpoint you configure. Only connect endpoints you trust with that data."; export const CUSTOM_ENGINE_TOOL_WARNING = - "The endpoint must speak the OpenAI Responses API with tool calling (codex 0.146 dropped the chat completions wire); plain chat endpoints need a translator in front."; + "The endpoint and selected model must support the OpenAI Responses API and tool calling. Chat Completions-only endpoints need a compatible adapter."; diff --git a/packages/core/src/runtime/customEngine.spec.ts b/packages/core/src/runtime/customEngine.spec.ts index 29157a22..40e648c0 100644 --- a/packages/core/src/runtime/customEngine.spec.ts +++ b/packages/core/src/runtime/customEngine.spec.ts @@ -1,6 +1,6 @@ // Custom engine (issue #209) safety rails. Each of these is a silent-failure class: -// a missing config would run stock codex on the user's OpenAI account, a phantom -// env_key handling protects keyless local endpoints, and a blank model makes codex quietly use +// a missing config would run stock codex on the user's OpenAI account, +// explicit env_key handling isolates custom credentials, and a blank model makes codex quietly use // its own global default model. Pin all three to throw or emit correctly. import { describe, it, expect } from "vitest"; import { spawnCli, customProviderFlags } from "./spawn.js"; @@ -22,7 +22,7 @@ describe("runtime/spawn — custom engine gates", () => { expect(() => spawnCli({ cli: "custom", cwd: "/tmp" })).toThrow(NOT_CONFIGURED); }); - it("customProviderFlags declares env_key even keyless: without it codex sends the user's own ChatGPT token to the endpoint", () => { + it("customProviderFlags declares an explicit credential even for keyless endpoints", () => { const flags = customProviderFlags(cfg()); expect(flags).toContain(`model_providers.custom.env_key=${JSON.stringify("CUSTOM_ENGINE_API_KEY")}`); }); @@ -36,6 +36,11 @@ describe("runtime/spawn — custom engine gates", () => { it("customProviderFlags throws on a blank model instead of letting codex pick its default", () => { expect(() => customProviderFlags(cfg({ model: "" }))).toThrow(NEEDS_MODEL); + expect(() => customProviderFlags(cfg({ model: " " }))).toThrow(NEEDS_MODEL); + }); + + it("trims legacy model values before sending them to the endpoint", () => { + expect(customProviderFlags(cfg({ model: " llama3 " }))).toContain('model="llama3"'); }); }); @@ -49,4 +54,9 @@ describe("account/customEngineAuth — saveCustomEngineConfig validation", () => await expect(saveCustomEngineConfig(cfg({ baseUrl: "not a url" }))).rejects.toThrow(/not a valid URL/); await expect(saveCustomEngineConfig(cfg({ baseUrl: "ftp://host/v1" }))).rejects.toThrow(/must be http or https/); }); + + it("does not echo credentials from an invalid URL into a surfaced error", async () => { + await expect(saveCustomEngineConfig(cfg({ baseUrl: "http://[invalid]?key=synthetic-secret-209" }))) + .rejects.toThrow(/^The custom engine base URL is not a valid URL\.$/); + }); }); diff --git a/packages/core/src/runtime/spawn.ts b/packages/core/src/runtime/spawn.ts index 93af2053..1c250dc6 100644 --- a/packages/core/src/runtime/spawn.ts +++ b/packages/core/src/runtime/spawn.ts @@ -555,32 +555,28 @@ export function codexMcpFlags(m: { name: string; command: string; args: string[] // Build the `-c model_providers.custom.*` overrides that point the codex binary at a // custom OpenAI-compatible endpoint (issue #209). Same process-scoped mechanism as // codexMcpFlags; the API key stays out of argv (env_key names CUSTOM_ENGINE_API_KEY, -// which codexEngine sets in the child env). Keyless endpoints (ollama/lmstudio) get -// no env_key at all, so codex sends unauthenticated requests instead of tripping over -// an env var that was never set. +// which codexEngine sets in the child env). Keyless endpoints receive the harmless +// placeholder below so authentication stays explicit and independent of stock login. export function customProviderFlags(cfg: CustomEngineConfig): string[] { // With no model override codex quietly falls back to its own global default model // name, which the endpoint almost certainly does not serve. saveCustomEngineConfig // already rejects a blank model; this guards configs saved before that rule. - if (!cfg.model) { + if (!cfg.model.trim()) { throw new Error("The custom engine needs a model id; codex would otherwise silently use its own default model."); } return [ "-c", `model_providers.custom.name=${JSON.stringify(cfg.label ?? cfg.presetId)}`, "-c", `model_providers.custom.base_url=${JSON.stringify(cfg.baseUrl)}`, - // env_key is ALWAYS declared, even keyless: without it codex falls back to its - // own login and sends the user's real ChatGPT bearer token to the custom - // endpoint (verified live against a logging endpoint). A keyless config gets - // the harmless placeholder below instead of the user's identity. + // Always select the custom credential, including the keyless placeholder, + // rather than relying on version-dependent default authentication behavior. "-c", `model_providers.custom.env_key=${JSON.stringify("CUSTOM_ENGINE_API_KEY")}`, "-c", `model_provider=${JSON.stringify("custom")}`, - "-c", `model=${JSON.stringify(cfg.model)}`, + "-c", `model=${JSON.stringify(cfg.model.trim())}`, ]; } -// What a keyless custom endpoint receives as its bearer value. Codex refuses an -// empty env var and, with no env_key at all, substitutes the user's own ChatGPT -// token, so keyless MUST mean "harmless constant", never "codex decides". +// What a keyless custom endpoint receives as its bearer value. Keep the declared +// credential nonempty without borrowing the user's stock Codex credentials. export const CUSTOM_ENGINE_KEYLESS_PLACEHOLDER = "keyless"; // ── codex: app-server JSON-RPC over stdio. Spawns `codex app-server --stdio` @@ -601,7 +597,7 @@ function codexEngine(opts: SpawnOpts): Engine { // Make the codex mode chips real: derive the approval policy + sandbox from opts.mode. // A mode change restages the session (session.ts), so the next spawn picks these up. // When the OS sandbox is FORCED by env (Android proot can't run bubblewrap → danger-full-access), - // a non-"full" mode must NOT weaken to on-failure: the sandbox isn't really constraining there, so + // a non-"full" mode must retain approval requests: the sandbox isn't really constraining there, so // the approval gate is the only real control and must keep asking. Only "full" opts out. Desktop // (no env override) uses the mode's own policy. const codexApproval = sandbox @@ -613,9 +609,7 @@ function codexEngine(opts: SpawnOpts): Engine { childEnv.OPENAI_API_KEY = opts.apiKey; } // Always set for a custom spawn: the saved key when there is one, else the - // keyless placeholder. Leaving the var unset or empty makes codex substitute - // the user's own ChatGPT bearer token on requests to the custom endpoint, - // which is exactly the credential egress a custom slot must never cause. + // keyless placeholder. Do not leave authentication to the user's stock login. if (opts.custom) { childEnv.CUSTOM_ENGINE_API_KEY = opts.custom.apiKey || CUSTOM_ENGINE_KEYLESS_PLACEHOLDER; } From 9e4b123edf158c47d8239b421e88ff26bbdde143 Mon Sep 17 00:00:00 2001 From: remilio nubilio Date: Mon, 7 Sep 2026 14:49:01 -0400 Subject: [PATCH 03/12] Custom engine: one status derivation for every host and surface customEngineStatus answers in CliReport's own vocabulary (missing, no-login, ok) so the CLI, the VS Code host and the chat session stop re-deriving "codex present AND config saved" each on their own; the unread binaryOk/configured fields and the unused keyless-placeholder export are gone, and the VS Code host reuses the boot probe instead of running a second one. --- packages/core/src/account/customEngineAuth.ts | 29 ++++++++----------- packages/core/src/chat/session.ts | 2 +- packages/core/src/index.ts | 7 ++--- .../core/src/runtime/customEngine.spec.ts | 4 +-- packages/core/src/runtime/engineRegistry.ts | 3 +- surfaces/cli/src/app.tsx | 10 +++---- surfaces/cli/src/views/Chat.tsx | 6 ++-- surfaces/cli/src/views/LoginGate.tsx | 16 ++++++---- surfaces/vscode/src/extension.ts | 19 +++++++----- 9 files changed, 48 insertions(+), 48 deletions(-) diff --git a/packages/core/src/account/customEngineAuth.ts b/packages/core/src/account/customEngineAuth.ts index affef357..6ca4e424 100644 --- a/packages/core/src/account/customEngineAuth.ts +++ b/packages/core/src/account/customEngineAuth.ts @@ -6,7 +6,7 @@ import { readFile, writeFile, rm } from "node:fs/promises"; import { tokenFile, tokensDir, ensureDir } from "../core/paths.js"; import { engineBinary } from "../runtime/engineRegistry.js"; -import { detectCli, type CliReport } from "../runtime/detect.js"; +import { detectCli, type CliReport, type CliStatus } from "../runtime/detect.js"; export interface CustomEngineConfig { baseUrl: string; @@ -95,22 +95,17 @@ export async function hasCustomEngine(): Promise { return (await loadCustomEngineConfig()) !== null; } -export interface CustomEngineStatus { - binaryOk: boolean; // the codex binary (custom's passthrough) is on this machine - configured: boolean; // an endpoint config is saved - ready: boolean; // both: a custom session can actually spawn -} - -// One readiness answer for every host, instead of each surface re-deriving -// "codex present AND config saved" on its own. Pass a CliReport when one is already -// in hand; without one detectCli runs, the same probe behind every host's engine -// status line (it resolves the binary through engineBin.ts, so a GUI-launched host -// without a shell PATH still finds it), so binaryOk mirrors whether a custom spawn -// could actually start. -export async function customEngineStatus(report?: CliReport): Promise { - const binaryOk = (report ?? await detectCli())[engineBinary("custom")] !== "missing"; - const configured = await hasCustomEngine(); - return { binaryOk, configured, ready: binaryOk && configured }; +// The custom engine's status in CliReport's own vocabulary, so a custom row reads like the +// claude and codex rows everywhere: "missing" = no codex binary (custom runs through it), +// "no-login" = the binary is there but no endpoint is saved (the saved config IS its +// sign-in), "ok" = a custom session can actually spawn. One derivation for every host +// and surface instead of each re-deriving "codex present AND config saved". Pass a +// CliReport when one is already in hand; without one detectCli runs, the same probe +// behind every engine status line (it resolves the binary through engineBin.ts, so a +// GUI-launched host without a shell PATH still finds it). +export async function customEngineStatus(report?: CliReport): Promise { + if ((report ?? await detectCli())[engineBinary("custom")] === "missing") return "missing"; + return (await hasCustomEngine()) ? "ok" : "no-login"; } // Masked view for the UI: endpoint host + last 4 chars of the key, rest dotted (like diff --git a/packages/core/src/chat/session.ts b/packages/core/src/chat/session.ts index c4da58c1..556ff099 100644 --- a/packages/core/src/chat/session.ts +++ b/packages/core/src/chat/session.ts @@ -561,7 +561,7 @@ export function createChatSession( // saved AND codex binary present). A config without the binary would reveal a // tab that can only die with a raw spawn error. void (async () => { - if (!(await customEngineStatus()).ready) return; + if ((await customEngineStatus()) !== "ok") return; const cfg = await loadCustomEngineConfig(); if (cfg) transport.send({ type: "modelOptions", cli: "custom", options: customModelOption(cfg.model, cfg.label || ENGINE_REGISTRY.custom.label) }); })().catch(() => {}); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 7ee0b0d1..ea78aedb 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -102,7 +102,6 @@ export { export type { SkillOrigin, ClassifiedSkill, SkillManifest, NftSkillRecord } from "./skill-market/registry.js"; export { createRuntime } from "./runtime/index.js"; -export { CUSTOM_ENGINE_KEYLESS_PLACEHOLDER } from "./runtime/spawn.js"; // engine behavior registry: claude/codex/custom descriptors + the coercion helpers export { ENGINE_KEYS, ENGINE_REGISTRY, engineBinary, coerceEngineKey, messageBinary } from "./runtime/engineRegistry.js"; export type { EngineDescriptor } from "./runtime/engineRegistry.js"; @@ -145,8 +144,8 @@ export { } from "./account/codexAuth.js"; export type { CodexLogin } from "./account/codexAuth.js"; // custom engine (issue #209): endpoint config store + presets + connect-UI copy. -// customEngineStatus is the one readiness answer (binary + config) every host uses -// instead of re-deriving it from detectCli + hasCustomEngine. +// customEngineStatus is the one readiness answer (binary + config, in CliStatus terms) +// every host and surface uses instead of re-deriving it from detectCli + hasCustomEngine. export { saveCustomEngineConfig, loadCustomEngineConfig, @@ -158,7 +157,7 @@ export { CUSTOM_ENGINE_EGRESS_WARNING, CUSTOM_ENGINE_TOOL_WARNING, } from "./account/customEngineAuth.js"; -export type { CustomEngineConfig, CustomEnginePreset, CustomEngineStatus } from "./account/customEngineAuth.js"; +export type { CustomEngineConfig, CustomEnginePreset } from "./account/customEngineAuth.js"; export { initialize, isInitialized, diff --git a/packages/core/src/runtime/customEngine.spec.ts b/packages/core/src/runtime/customEngine.spec.ts index 40e648c0..42bf1fed 100644 --- a/packages/core/src/runtime/customEngine.spec.ts +++ b/packages/core/src/runtime/customEngine.spec.ts @@ -17,7 +17,7 @@ const cfg = (over: Partial = {}): CustomEngineConfig => ({ ...over, }); -describe("runtime/spawn — custom engine gates", () => { +describe("runtime/spawn: custom engine gates", () => { it("spawnCli throws loudly on a custom spawn with no config (never silently runs stock codex)", () => { expect(() => spawnCli({ cli: "custom", cwd: "/tmp" })).toThrow(NOT_CONFIGURED); }); @@ -44,7 +44,7 @@ describe("runtime/spawn — custom engine gates", () => { }); }); -describe("account/customEngineAuth — saveCustomEngineConfig validation", () => { +describe("account/customEngineAuth: saveCustomEngineConfig validation", () => { it("rejects a blank model before anything reaches disk", async () => { await expect(saveCustomEngineConfig(cfg({ model: "" }))).rejects.toThrow(NEEDS_MODEL); await expect(saveCustomEngineConfig(cfg({ model: " " }))).rejects.toThrow(NEEDS_MODEL); diff --git a/packages/core/src/runtime/engineRegistry.ts b/packages/core/src/runtime/engineRegistry.ts index 8c13e5cf..5b5754b3 100644 --- a/packages/core/src/runtime/engineRegistry.ts +++ b/packages/core/src/runtime/engineRegistry.ts @@ -8,8 +8,7 @@ export type EngineKey = "claude" | "codex" | "custom"; // key names the row it sits in, binary drives engine dispatch, label names the // engine where a surface needs a display name, memoryFile picks the native -// project-instructions file. loginKind and modelSource used to live here too but -// nothing ever read them, so they are gone (CODE-RULES: no dead data). +// project-instructions file. Only fields something reads live here. export interface EngineDescriptor { key: EngineKey; label: string; diff --git a/surfaces/cli/src/app.tsx b/surfaces/cli/src/app.tsx index a0f3445e..75deade6 100644 --- a/surfaces/cli/src/app.tsx +++ b/surfaces/cli/src/app.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState } from "react"; import { Box, Text, useApp, useInput } from "ink"; import type { AgentRuntime, SessionMeta } from "@iqlabs-official/agent-sdk/runtime/contract"; -import { autoApprove, hasCustomEngine, ENGINE_KEYS, engineBinary, type EngineKey, type StorageConfig, type CliReport } from "@iqlabs-official/agent-sdk"; +import { autoApprove, customEngineStatus, ENGINE_KEYS, engineBinary, type EngineKey, type StorageConfig, type CliReport } from "@iqlabs-official/agent-sdk"; import type { CloudStatus } from "@iqlabs-official/agent-sdk/account/storage/mirror"; import { InkApprovalChannel } from "./InkApprovalChannel.js"; import { Banner } from "./components/Banner.js"; @@ -142,12 +142,10 @@ export function App({ options }: { options: AppOptions }) { // back to ANOTHER engine that is (start with what works, no gate), and // only gate on the login screen when nothing is usable. An explicit --cli // flag skips the silent fallback: the user asked for that engine, so gate. - // custom is usable once the codex binary (which it runs through) exists and - // an endpoint config is saved; its login state lives outside CliReport. + // custom's status lives outside CliReport (its sign-in is a saved endpoint + // config), so core answers it in the same vocabulary. const usable = async (e: EngineKey) => - e === "custom" - ? rep.codex !== "missing" && (await hasCustomEngine()) - : rep[e] === "ok"; + (e === "custom" ? await customEngineStatus(rep) : rep[e]) === "ok"; // savedPrefs.lastCli is already coerced by readPrefs, so eff is always a // registry key even when the prefs file was hand-edited. const eff = options.cli ?? savedPrefs.lastCli ?? "claude"; diff --git a/surfaces/cli/src/views/Chat.tsx b/surfaces/cli/src/views/Chat.tsx index 9a468416..25d082d0 100644 --- a/surfaces/cli/src/views/Chat.tsx +++ b/surfaces/cli/src/views/Chat.tsx @@ -33,6 +33,7 @@ import { NODE_DOWNLOAD_URL, ENGINE_KEYS, engineBinary, + customEngineStatus, hasCustomEngine, maskedCustomEngine, type EngineKey, @@ -830,10 +831,7 @@ export function Chat({ const [engineLogin, setEngineLogin] = useState<{ target: EngineKey; report: CliReport } | null>(null); function requestEngine(next: EngineKey) { void detectCli().then(async (rep) => { - const status = - next === "custom" - ? rep.codex === "missing" ? "missing" : (await hasCustomEngine()) ? "ok" : "no-login" - : rep[next]; + const status = next === "custom" ? await customEngineStatus(rep) : rep[next]; if (status === "ok") { if (next === "custom" && chat.cli === "custom") { // re-picking the engine already in use is a manage request, not a switch: diff --git a/surfaces/cli/src/views/LoginGate.tsx b/surfaces/cli/src/views/LoginGate.tsx index 903cbc4d..1dd4dd5f 100644 --- a/surfaces/cli/src/views/LoginGate.tsx +++ b/surfaces/cli/src/views/LoginGate.tsx @@ -17,6 +17,7 @@ import { CUSTOM_ENGINE_TOOL_WARNING, saveCustomEngineConfig, clearCustomEngineConfig, + customEngineStatus, maskedCustomEngine, type CustomEnginePreset, type EngineKey, @@ -152,11 +153,14 @@ export function LoginGate({ const [codexCode, setCodexCode] = useState(""); const [waiting, setWaiting] = useState(false); // masked view of the saved custom endpoint (host + dotted key tail); null when no - // config exists, which doubles as the configured/not-configured flag. + // config exists, which doubles as the configured/not-configured flag. The status row + // comes from core's one derivation, in the same vocabulary as the claude/codex rows. const [customMasked, setCustomMasked] = useState(null); + const [customStatus, setCustomStatus] = useState("no-login"); useEffect(() => { void maskedCustomEngine().then(setCustomMasked); - }, []); + void customEngineStatus(report).then(setCustomStatus); + }, [report]); const customConfigured = customMasked !== null; const claudeRef = useRef(null); const codexRef = useRef(null); @@ -186,8 +190,9 @@ export function LoginGate({ // recovered once the file is gone, so a stray Enter must not be able to delete it. useInput((input) => { if (input !== "y" && input !== "Y") return; - void clearCustomEngineConfig().then(() => { + void clearCustomEngineConfig().then(async () => { setCustomMasked(null); + setCustomStatus(await customEngineStatus(report)); setStep("pick"); }); }, { isActive: step === "customRemove" }); @@ -290,10 +295,11 @@ export function LoginGate({ const claudeS = statusText(report.claude); const codexS = statusText(report.codex); + // custom's "no-login" is "no endpoint saved": the config is its sign-in. const customS = - report.codex === "missing" + customStatus === "missing" ? { text: "needs the codex binary", color: colors.err } - : customConfigured + : customStatus === "ok" ? { text: `${glyph.ok} configured`, color: colors.ok } : { text: "not configured", color: colors.warn }; diff --git a/surfaces/vscode/src/extension.ts b/surfaces/vscode/src/extension.ts index dd7d2ebc..d6266583 100644 --- a/surfaces/vscode/src/extension.ts +++ b/surfaces/vscode/src/extension.ts @@ -33,6 +33,7 @@ import { CUSTOM_ENGINE_PRESETS, customModelOption, messageBinary, + type CliReport, logoutClaude, logoutCodex, marketplaceEnv, @@ -210,9 +211,12 @@ function errorMessage(e: unknown): string { return e instanceof Error ? e.message : String(e); } -async function pushCliStatus(transport: WebviewTransport) { +// Returns the report so a caller that needs it next (the custom-engine push at boot) does +// not pay for a second probe. +async function pushCliStatus(transport: WebviewTransport): Promise { const cli = await detectCli(); transport.send({ type: "cliStatus", claude: cli.claude, codex: cli.codex }); + return cli; } // Engines whose "out of date" banner the user dismissed. Session-scoped (module-level, so @@ -224,9 +228,9 @@ const engineUpdateDismissed = new Set<"claude" | "codex">(); // stay host-side; the webview only ever sees this view. The chat panel uses `masked` // as its custom-tab gate and has no connect form, so a null rides out unless a custom // session could actually spawn (binary + config, core's one readiness answer). -async function pushCustomEngine(transport: WebviewTransport) { - const status = await customEngineStatus(); - transport.send({ type: "customEngine", masked: status.ready ? await maskedCustomEngine() : null, presets: CUSTOM_ENGINE_PRESETS }); +async function pushCustomEngine(transport: WebviewTransport, report?: CliReport) { + const ready = (await customEngineStatus(report)) === "ok"; + transport.send({ type: "customEngine", masked: ready ? await maskedCustomEngine() : null, presets: CUSTOM_ENGINE_PRESETS }); } // After an install was launched from the notice button, re-check until the engine stops @@ -254,14 +258,15 @@ function watchEngineInstall(transport: WebviewTransport, engine: "claude" | "cod function attachAuthHandlers(transport: WebviewTransport) { transport.onRecv(async (m: any) => { switch (m?.type) { - case "ready": - await pushCliStatus(transport); + case "ready": { // The chat panel shows the custom tab only while a config exists (it handles // the customEngine push both ways), so its state must land at boot too. The // panel carries no connect form in this spike, so the host handles no // getCustomEngine/saveCustomEngine: connecting happens in the AgentNet app. - await pushCustomEngine(transport); + const report = await pushCliStatus(transport); + await pushCustomEngine(transport, report); return; + } case "getCliStatus": await pushCliStatus(transport); return; From dfc8fa6d543bcb64e0c6ffb9c331f639acad3b5c Mon Sep 17 00:00:00 2001 From: NubsCarson <192162056+NubsCarson@users.noreply.github.com> Date: Mon, 14 Sep 2026 01:15:13 -0400 Subject: [PATCH 04/12] custom engine: pin provider when starting or resuming threads --- packages/core/src/runtime/codex-approvals.spec.ts | 10 ++++++++-- packages/core/src/runtime/spawn.ts | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/core/src/runtime/codex-approvals.spec.ts b/packages/core/src/runtime/codex-approvals.spec.ts index f28f8a11..b88d70ba 100644 --- a/packages/core/src/runtime/codex-approvals.spec.ts +++ b/packages/core/src/runtime/codex-approvals.spec.ts @@ -16,7 +16,12 @@ afterEach(() => { // Exercise the production engine through its JSON-RPC boundary. Only the child // transport is simulated; no Codex process, model request or wallet is involved. -describe.each([undefined, "existing-thread"])("Codex approvals (session %s)", (sessionId) => { +describe.each([ + { cli: "codex", sessionId: undefined }, + { cli: "codex", sessionId: "existing-thread" }, + { cli: "custom", sessionId: undefined }, + { cli: "custom", sessionId: "existing-thread" }, +] as const)("Codex approvals ($cli, session $sessionId)", ({ cli, sessionId }) => { it.each([ { mode: "auto", override: "", policy: "on-request", sandbox: "workspace-write" }, { mode: "readonly", override: "", policy: "on-request", sandbox: "read-only" }, @@ -54,7 +59,7 @@ describe.each([undefined, "existing-thread"])("Codex approvals (session %s)", (s }, }); vi.mocked(spawn).mockReturnValue(child as unknown as ReturnType); - const engine = spawnCli({ cli: "codex", cwd: process.cwd(), mode, sessionId }); + const engine = spawnCli({ cli, cwd: process.cwd(), mode, sessionId, ...(cli === "custom" ? { custom: { baseUrl: "http://127.0.0.1:11669/v1", model: "mock-model", apiKey: "", presetId: "manual" } } : {}) }); const opened = vi.fn(); engine.onSessionId(opened); try { @@ -64,6 +69,7 @@ describe.each([undefined, "existing-thread"])("Codex approvals (session %s)", (s ]); expect(requests[1].params).toMatchObject({ approvalPolicy: policy, approvalsReviewer: "user" }); expect(requests[1].params.sandbox).toBe(sandbox); + expect(requests[1].params.modelProvider).toBe(cli === "custom" ? "custom" : undefined); } finally { engine.stop?.(); } diff --git a/packages/core/src/runtime/spawn.ts b/packages/core/src/runtime/spawn.ts index 1c250dc6..bcd683bb 100644 --- a/packages/core/src/runtime/spawn.ts +++ b/packages/core/src/runtime/spawn.ts @@ -1022,6 +1022,7 @@ function codexEngine(opts: SpawnOpts): Engine { const startThread = async () => { const res = await sendRequest("thread/start", { model: opts.model, + ...(opts.custom ? { modelProvider: "custom" } : {}), cwd: opts.cwd, approvalPolicy: codexApproval, approvalsReviewer: "user", From 3f8362596274dbd81d00f7acb5e29090ba27b1a3 Mon Sep 17 00:00:00 2001 From: NubsCarson <192162056+NubsCarson@users.noreply.github.com> Date: Mon, 14 Sep 2026 02:11:04 -0400 Subject: [PATCH 05/12] custom engine: trim unverified presets and unused panel handlers --- packages/core/src/account/customEngineAuth.ts | 13 ++----------- surfaces/cli/src/index.tsx | 2 +- surfaces/cli/src/views/LoginGate.tsx | 3 ++- surfaces/vscode/src/extension.ts | 15 ++------------- 4 files changed, 7 insertions(+), 26 deletions(-) diff --git a/packages/core/src/account/customEngineAuth.ts b/packages/core/src/account/customEngineAuth.ts index 6ca4e424..5427a902 100644 --- a/packages/core/src/account/customEngineAuth.ts +++ b/packages/core/src/account/customEngineAuth.ts @@ -23,18 +23,9 @@ export interface CustomEnginePreset { defaultModel: string; } -// Starting points so connecting is a pick + key paste instead of a URL hunt. Only "manual" -// (a loopback endpoint) and "lmstudio" have carried a real turn; the hosted entries are the -// advertised base URLs and must speak the Responses wire to work through codex. "manual" is the escape hatch: any endpoint, all fields typed by hand. -// A defaultModel of "" does NOT mean the endpoint picks one: saveCustomEngineConfig -// rejects a blank model, so the connect form must require a model id for those presets. +// OpenRouter has been exercised through the Responses API. Other compatible local +// or hosted endpoints can be configured manually without implying provider support. export const CUSTOM_ENGINE_PRESETS: CustomEnginePreset[] = [ - { id: "deepseek", label: "DeepSeek", baseUrl: "https://api.deepseek.com/v1", defaultModel: "deepseek-chat" }, - { id: "qwen", label: "Qwen", baseUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1", defaultModel: "qwen-max" }, - { id: "glm", label: "GLM", baseUrl: "https://open.bigmodel.cn/api/paas/v4", defaultModel: "glm-4-plus" }, - { id: "kimi", label: "Kimi", baseUrl: "https://api.moonshot.cn/v1", defaultModel: "kimi-k2" }, - { id: "ollama", label: "Ollama", baseUrl: "http://localhost:11434/v1", defaultModel: "" }, - { id: "lmstudio", label: "LM Studio", baseUrl: "http://localhost:1234/v1", defaultModel: "" }, { id: "openrouter", label: "OpenRouter", baseUrl: "https://openrouter.ai/api/v1", defaultModel: "" }, { id: "manual", label: "Manual", baseUrl: "", defaultModel: "" }, ]; diff --git a/surfaces/cli/src/index.tsx b/surfaces/cli/src/index.tsx index 2d65005f..cff69334 100644 --- a/surfaces/cli/src/index.tsx +++ b/surfaces/cli/src/index.tsx @@ -82,7 +82,7 @@ program .description("AgentNet: a playful, wallet-synced terminal for claude/codex") .version("0.1.7") .option("--calm", "disable animations (also honors NO_COLOR / non-TTY)") - .option("--cli ", "start on claude or codex (default: last used)") + .option("--cli ", "start on claude, codex, or custom (default: last used)") .option("--cwd ", "working directory for the agent") .option("--keypair ", "Solana keypair file (default: ~/.config/solana/id.json)") .option("--model ", "model to use") diff --git a/surfaces/cli/src/views/LoginGate.tsx b/surfaces/cli/src/views/LoginGate.tsx index 1dd4dd5f..857be0e1 100644 --- a/surfaces/cli/src/views/LoginGate.tsx +++ b/surfaces/cli/src/views/LoginGate.tsx @@ -4,6 +4,7 @@ import { PasswordInput, Select, TextInput } from "@inkjs/ui"; import open from "open"; import { detectCli, + engineBinary, resolveEngineBin, startClaudeLogin, startCodexLogin, @@ -273,7 +274,7 @@ export function LoginGate({ } if (engine === "custom") { // custom rides the codex binary; the config store is its login. - if (report.codex === "missing") { + if (report[engineBinary(engine)] === "missing") { setErr(`custom engines run through the codex binary · run: ${ENGINE_INSTALL_COMMAND.custom}`); return; } diff --git a/surfaces/vscode/src/extension.ts b/surfaces/vscode/src/extension.ts index d6266583..47a02271 100644 --- a/surfaces/vscode/src/extension.ts +++ b/surfaces/vscode/src/extension.ts @@ -27,10 +27,8 @@ import { startCodexLogin, markCodexConnected, loadCustomEngineConfig, - clearCustomEngineConfig, maskedCustomEngine, customEngineStatus, - CUSTOM_ENGINE_PRESETS, customModelOption, messageBinary, type CliReport, @@ -230,7 +228,7 @@ const engineUpdateDismissed = new Set<"claude" | "codex">(); // session could actually spawn (binary + config, core's one readiness answer). async function pushCustomEngine(transport: WebviewTransport, report?: CliReport) { const ready = (await customEngineStatus(report)) === "ok"; - transport.send({ type: "customEngine", masked: ready ? await maskedCustomEngine() : null, presets: CUSTOM_ENGINE_PRESETS }); + transport.send({ type: "customEngine", masked: ready ? await maskedCustomEngine() : null }); } // After an install was launched from the notice button, re-check until the engine stops @@ -261,7 +259,7 @@ function attachAuthHandlers(transport: WebviewTransport) { case "ready": { // The chat panel shows the custom tab only while a config exists (it handles // the customEngine push both ways), so its state must land at boot too. The - // panel carries no connect form in this spike, so the host handles no + // panel carries no connect form, so the host handles no // getCustomEngine/saveCustomEngine: connecting happens in the AgentNet app. const report = await pushCliStatus(transport); await pushCustomEngine(transport, report); @@ -270,15 +268,6 @@ function attachAuthHandlers(transport: WebviewTransport) { case "getCliStatus": await pushCliStatus(transport); return; - case "clearCustomEngine": - try { - await clearCustomEngineConfig(); - transport.send({ type: "toast", text: "Custom engine removed." }); - await pushCustomEngine(transport); - } catch (e) { - transport.send({ type: "toast", text: `Custom engine remove failed: ${errorMessage(e)}` }); - } - return; case "startClaudeLogin": try { claudeLogin?.cancel(); From 828011a5754aae74da8aefb58b5eaf872596c58e Mon Sep 17 00:00:00 2001 From: NubsCarson <192162056+NubsCarson@users.noreply.github.com> Date: Mon, 14 Sep 2026 02:11:04 -0400 Subject: [PATCH 06/12] core: handle Codex MCP consent and current context usage --- .../core/src/runtime/codex-approvals.spec.ts | 36 +++++++++++++++++-- packages/core/src/runtime/spawn.ts | 28 ++++++++++++--- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/packages/core/src/runtime/codex-approvals.spec.ts b/packages/core/src/runtime/codex-approvals.spec.ts index b88d70ba..b534917e 100644 --- a/packages/core/src/runtime/codex-approvals.spec.ts +++ b/packages/core/src/runtime/codex-approvals.spec.ts @@ -21,7 +21,7 @@ describe.each([ { cli: "codex", sessionId: "existing-thread" }, { cli: "custom", sessionId: undefined }, { cli: "custom", sessionId: "existing-thread" }, -] as const)("Codex approvals ($cli, session $sessionId)", ({ cli, sessionId }) => { +] as const)("Codex startup and usage ($cli, session $sessionId)", ({ cli, sessionId }) => { it.each([ { mode: "auto", override: "", policy: "on-request", sandbox: "workspace-write" }, { mode: "readonly", override: "", policy: "on-request", sandbox: "read-only" }, @@ -59,7 +59,10 @@ describe.each([ }, }); vi.mocked(spawn).mockReturnValue(child as unknown as ReturnType); - const engine = spawnCli({ cli, cwd: process.cwd(), mode, sessionId, ...(cli === "custom" ? { custom: { baseUrl: "http://127.0.0.1:11669/v1", model: "mock-model", apiKey: "", presetId: "manual" } } : {}) }); + const approve = vi.fn(async () => ({ outcome: "once" as "once" | "deny" | "always" })); + const engine = spawnCli({ approval: { request: approve }, cli, cwd: process.cwd(), mode, sessionId, ...(cli === "custom" ? { custom: { baseUrl: "http://127.0.0.1:11669/v1", model: "mock-model", apiKey: "", presetId: "manual" } } : {}) }); + const usage = vi.fn(); + engine.onUsage(usage); const opened = vi.fn(); engine.onSessionId(opened); try { @@ -70,6 +73,35 @@ describe.each([ expect(requests[1].params).toMatchObject({ approvalPolicy: policy, approvalsReviewer: "user" }); expect(requests[1].params.sandbox).toBe(sandbox); expect(requests[1].params.modelProvider).toBe(cli === "custom" ? "custom" : undefined); + // A second turn adds to billed totals, not to current context occupancy. + for (const [total, last] of [[40000, 20000], [60000, 21000], [61000, 1000]]) { + stdout.write(JSON.stringify({ method: "thread/tokenUsage/updated", params: { + tokenUsage: { total: { totalTokens: total }, last: { totalTokens: last }, modelContextWindow: 32000 }, + } }) + "\n"); + expect(usage).toHaveBeenLastCalledWith(last, 32000); + } + for (const [id, outcome] of (["once", "deny", "always"] as const).entries()) { + approve.mockResolvedValueOnce({ outcome }); + stdout.write(JSON.stringify({ id: 100 + id, method: "mcpServer/elicitation/request", params: { + threadId: sessionId ?? "new-thread", serverName: "qa_fixture", mode: "form", + message: "Allow fixture read?", requestedSchema: { type: "object", properties: {} }, + _meta: { codex_approval_kind: "mcp_tool_call", tool_params: {}, persist: ["session", "always"] }, + } }) + "\n"); + await vi.waitFor(() => expect(requests.find(r => r.id === 100 + id)).toMatchObject({ result: { + action: outcome === "deny" ? "decline" : "accept", + content: outcome === "deny" ? null : {}, + _meta: outcome === "always" ? { persist: "always" } : null, + } })); + expect(approve).toHaveBeenLastCalledWith(expect.objectContaining({ cli, title: "Allow fixture read?" })); + } + approve.mockClear(); + stdout.write(JSON.stringify({ id: 200, method: "mcpServer/elicitation/request", params: { + serverName: "qa_fixture", mode: "form", message: "Enter a value", + requestedSchema: { type: "object", properties: { value: { type: "string" } } }, + _meta: { codex_approval_kind: "mcp_tool_call" }, + } }) + "\n"); + await vi.waitFor(() => expect(requests.find(r => r.id === 200)).toMatchObject({ error: { code: -32602 } })); + expect(approve).not.toHaveBeenCalled(); } finally { engine.stop?.(); } diff --git a/packages/core/src/runtime/spawn.ts b/packages/core/src/runtime/spawn.ts index bcd683bb..dab05f05 100644 --- a/packages/core/src/runtime/spawn.ts +++ b/packages/core/src/runtime/spawn.ts @@ -577,7 +577,7 @@ export function customProviderFlags(cfg: CustomEngineConfig): string[] { // What a keyless custom endpoint receives as its bearer value. Keep the declared // credential nonempty without borrowing the user's stock Codex credentials. -export const CUSTOM_ENGINE_KEYLESS_PLACEHOLDER = "keyless"; +const CUSTOM_ENGINE_KEYLESS_PLACEHOLDER = "keyless"; // ── codex: app-server JSON-RPC over stdio. Spawns `codex app-server --stdio` // and processes requests and notifications, routing approvals to the ApprovalChannel. @@ -796,13 +796,13 @@ function codexEngine(opts: SpawnOpts): Engine { } } } else if (msg.method === "thread/tokenUsage/updated") { - // Authoritative usage notification: carries the running total AND the real model - // context window. Prefer it over the turn/completed estimate when present. + // The last request measures current context. The running total includes previous + // turns and must not be shown as context occupancy. const tu = params?.tokenUsage; if (tu) { if (typeof tu.modelContextWindow === "number") knownWindow = tu.modelContextWindow; - const total = tu.total?.totalTokens; - if (typeof total === "number") cb.emitUsage(total, knownWindow); + const last = tu.last?.totalTokens; + if (typeof last === "number") cb.emitUsage(last, knownWindow); } } else if (msg.method === "thread/compacted") { // history was condensed to reclaim context — fire the compaction cue. The following @@ -940,6 +940,24 @@ function codexEngine(opts: SpawnOpts): Engine { sendResponse(msg.id, { decision: codexDecisionVerb(decision, key, ITEM_VERBS) }); if (decision.outcome === "deny") deliverDenyReason(decision.reason); } + } else if (msg.method === "mcpServer/elicitation/request") { + // Codex uses an empty form for MCP tool consent. Other elicitation forms + // need structured user input and cannot be treated as a yes/no approval. + const schema = params.requestedSchema; + if (params.mode !== "form" || params._meta?.codex_approval_kind !== "mcp_tool_call" + || schema?.type !== "object" || Object.keys(schema.properties ?? {}).length || schema.required?.length) { + sendError(msg.id, { code: -32602, message: "This MCP input form is not supported." }); + return; + } + const req = toApprovalRequest(opts.cli, sessionId, `MCP ${params.serverName}`, params._meta.tool_params ?? {}); + req.title = params.message; + const decision = await approval.request(req); + sendResponse(msg.id, { + action: decision.outcome === "deny" ? "decline" : "accept", + content: decision.outcome === "deny" ? null : {}, + _meta: decision.outcome === "always" && params._meta.persist?.includes("always") ? { persist: "always" } : null, + }); + if (decision.outcome === "deny") deliverDenyReason(decision.reason); } else if (msg.method === "item/permissions/requestApproval") { const req = toApprovalRequest(opts.cli, sessionId, "Permissions", { reason: params.reason }, opts.cwd); req.title = `Grant permissions: ${params.reason || "sandbox access"}`; From 3f70bfe2415fcceec3ae773c1fb88b0428a269e7 Mon Sep 17 00:00:00 2001 From: NubsCarson <192162056+NubsCarson@users.noreply.github.com> Date: Mon, 14 Sep 2026 02:16:14 -0400 Subject: [PATCH 07/12] custom engine: wrap the Settings connection description --- surfaces/webview/src/chat/Sessions.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/surfaces/webview/src/chat/Sessions.tsx b/surfaces/webview/src/chat/Sessions.tsx index bc9ee718..849d8099 100644 --- a/surfaces/webview/src/chat/Sessions.tsx +++ b/surfaces/webview/src/chat/Sessions.tsx @@ -179,7 +179,7 @@ function CustomEngineRow() { custom - + {masked ? `${t(M.storagePicker.connected)} · ${masked}` : "Bring your own OpenAI-compatible endpoint"} From 79aaa1bb110cf72a3ee95a057b63a6ef5bfa7b31 Mon Sep 17 00:00:00 2001 From: NubsCarson <192162056+NubsCarson@users.noreply.github.com> Date: Mon, 14 Sep 2026 02:57:11 -0400 Subject: [PATCH 08/12] custom engine: show context count without an unverified limit --- packages/core/src/runtime/spawn.ts | 1 + surfaces/webview/src/chat/Composer.tsx | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/core/src/runtime/spawn.ts b/packages/core/src/runtime/spawn.ts index dab05f05..c06070ba 100644 --- a/packages/core/src/runtime/spawn.ts +++ b/packages/core/src/runtime/spawn.ts @@ -1019,6 +1019,7 @@ function codexEngine(opts: SpawnOpts): Engine { try { await sendRequest("thread/resume", { threadId, + ...(opts.custom ? { modelProvider: "custom" } : {}), model: opts.model, cwd: opts.cwd, approvalPolicy: codexApproval, diff --git a/surfaces/webview/src/chat/Composer.tsx b/surfaces/webview/src/chat/Composer.tsx index e7b20b30..86ab3671 100644 --- a/surfaces/webview/src/chat/Composer.tsx +++ b/surfaces/webview/src/chat/Composer.tsx @@ -13,7 +13,7 @@ import { CHAT_SLASH_COMMANDS } from "@iqlabs-official/agent-sdk/chat/slashComman // Tapping it opens a small readout of the numbers behind the ring: the title // tooltip only exists for mouse hover, which touch (and most desktop users) // never see. -function CtxDot({ tokens, window: win, compacting }: { tokens: number; window: number; compacting?: boolean }) { +function CtxDot({ tokens, window: win, compacting }: { tokens: number; window?: number; compacting?: boolean }) { const [open, setOpen] = useState(false); const rootRef = useRef(null); // Tap-away closes: listen only while open, the same pattern the pickers use. @@ -25,7 +25,7 @@ function CtxDot({ tokens, window: win, compacting }: { tokens: number; window: n document.addEventListener("pointerdown", close); return () => document.removeEventListener("pointerdown", close); }, [open]); - const frac = Math.min(1, tokens / win); + const frac = win ? Math.min(1, tokens / win) : 0; const pct = Math.round(frac * 100); const color = compacting ? "var(--an-orange, #f80)" @@ -36,8 +36,8 @@ function CtxDot({ tokens, window: win, compacting }: { tokens: number; window: n return ( {open && (
COMPACTING…
) : ( <> -
{tokens.toLocaleString()} / {win.toLocaleString()} tk
+
{tokens.toLocaleString()}{win ? ` / ${win.toLocaleString()} tk` : " context tokens"}
- {pct}% - used · compacts near full + {win ? <>{pct}%used · compacts near full : Engine-reported · model limit unverified}
)} @@ -63,10 +62,10 @@ function CtxDot({ tokens, window: win, compacting }: { tokens: number; window: n aria-label="Context usage" aria-expanded={open} onClick={() => setOpen((v) => !v)} - className="flex items-center active:opacity-80" + className="flex min-h-8 min-w-8 items-center justify-center active:opacity-80" style={{ background: "none", border: 0, padding: 0 }} > - + {!win && !compacting ? {fmtK(tokens)} ctx : - + } {compacting && }
@@ -599,7 +598,7 @@ export function Composer() { )} {(state.contextTokens !== undefined || state.isCompacting) && (() => { const tokens = state.contextTokens ?? 0; - const win = state.contextWindow ?? (state.cli === "codex" ? 256_000 : 200_000); + const win = state.cli === "custom" ? undefined : state.contextWindow ?? (state.cli === "codex" ? 256_000 : 200_000); return ; })()} {queueCount > 0 && ( From c5fc85aae3538b8359fb1b5c4b982e5c70774f02 Mon Sep 17 00:00:00 2001 From: NubsCarson <192162056+NubsCarson@users.noreply.github.com> Date: Mon, 14 Sep 2026 11:13:14 -0400 Subject: [PATCH 09/12] Revert "webview: prevent focus from scrolling the tab pager" This reverts commit be3165337dcee47abb104b1c55dfef68f0c5ea05. --- surfaces/webview/src/index.css | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/surfaces/webview/src/index.css b/surfaces/webview/src/index.css index f19078c5..e2ca0892 100644 --- a/surfaces/webview/src/index.css +++ b/surfaces/webview/src/index.css @@ -1150,8 +1150,7 @@ body { position: relative; flex: 1; min-height: 0; - /* The pager moves by transform. Focus must not scroll its four-page track. */ - overflow: clip; + overflow: hidden; } .an-shell-panels::after { content: ""; From c08a7ebb9f6ec66705a60f1993b2d93efab45fae Mon Sep 17 00:00:00 2001 From: NubsCarson <192162056+NubsCarson@users.noreply.github.com> Date: Mon, 14 Sep 2026 14:31:58 -0400 Subject: [PATCH 10/12] fix: preserve custom readiness across runtime status updates --- packages/core/src/account/customEngineAuth.ts | 3 ++- packages/core/src/chat/ui/panel.jsdom.spec.ts | 15 +++++++++++++++ packages/core/src/chat/ui/panel/engine.ts | 5 +++-- packages/core/src/chat/ui/panel/main.ts | 7 ++++--- packages/core/src/chat/ui/panel/shell.ts | 3 ++- packages/core/src/runtime/customEngine.spec.ts | 7 ++++++- packages/core/test/webview-custom-status.spec.js | 8 ++++++++ surfaces/cli/src/views/Chat.tsx | 2 ++ surfaces/cli/src/views/LoginGate.tsx | 4 +++- surfaces/cli/src/views/Onboarding.tsx | 2 +- surfaces/webview/src/chat/Sessions.tsx | 4 +++- surfaces/webview/src/state/store.tsx | 3 ++- 12 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 packages/core/test/webview-custom-status.spec.js diff --git a/packages/core/src/account/customEngineAuth.ts b/packages/core/src/account/customEngineAuth.ts index 5427a902..39fdbdfa 100644 --- a/packages/core/src/account/customEngineAuth.ts +++ b/packages/core/src/account/customEngineAuth.ts @@ -95,7 +95,8 @@ export async function hasCustomEngine(): Promise { // behind every engine status line (it resolves the binary through engineBin.ts, so a // GUI-launched host without a shell PATH still finds it). export async function customEngineStatus(report?: CliReport): Promise { - if ((report ?? await detectCli())[engineBinary("custom")] === "missing") return "missing"; + const status = (report ?? await detectCli())[engineBinary("custom")]; + if (status === "missing" || status === "node-missing") return status; return (await hasCustomEngine()) ? "ok" : "no-login"; } diff --git a/packages/core/src/chat/ui/panel.jsdom.spec.ts b/packages/core/src/chat/ui/panel.jsdom.spec.ts index 5f3b0197..8fa54bb8 100644 --- a/packages/core/src/chat/ui/panel.jsdom.spec.ts +++ b/packages/core/src/chat/ui/panel.jsdom.spec.ts @@ -325,6 +325,21 @@ describe("panel.jsdom: custom engine tab (issue #209)", () => { p.key(input, "Enter"); }; + it("gates Custom on its runtime without requiring Codex sign-in", () => { + const p = boot(); + p.host({ type: "customEngine", masked: "fixture.invalid", presets: [] }); + p.host({ type: "cliStatus", claude: "ok", codex: "node-missing" }); + const before = p.posted.length; + p.$(CUSTOM_TAB)!.click(); + expect(p.types().slice(before)).not.toContain("platform"); + expect(p.$("#log")!.textContent).toContain("Node.js is missing"); + p.host({ type: "platform", cli: "claude" }); + p.host({ type: "cliStatus", claude: "ok", codex: "no-login" }); + p.$(CUSTOM_TAB)!.click(); + expect(p.posted).toContainEqual({ type: "platform", cli: "custom" }); + expect(p.errors).toEqual([]); + }); + it("ships hidden, refuses /engine custom without a config, and appears once the host announces one", () => { const p = boot(); p.host({ type: "cliStatus", claude: "ok", codex: "ok" }); diff --git a/packages/core/src/chat/ui/panel/engine.ts b/packages/core/src/chat/ui/panel/engine.ts index 06c0dd23..5ad66478 100644 --- a/packages/core/src/chat/ui/panel/engine.ts +++ b/packages/core/src/chat/ui/panel/engine.ts @@ -3,6 +3,7 @@ // modules in dependency order, and main.ts calls the wire functions in the legacy order so // listener registration and boot posts keep their sequence. import { S } from "./state.js"; +import { engineBinary } from "../../../runtime/engineRegistry.js"; import { CHAT_MODEL_OPTIONS } from "../../modelOptions.js"; import { CODEX_UPDATE_COMMAND, ENGINE_INSTALL_COMMAND } from "../../../runtime/engineInstall.js"; import { vscode } from "./host.js"; @@ -217,12 +218,12 @@ export function setTab(next) { export function selectTab(next) { if (next === S.cli) return; setTab(next); - const status = S.cliReport && S.cliReport[next]; + const status = S.cliReport && S.cliReport[engineBinary(next)]; if (status === 'missing' || status === 'node-missing') { renderEngineMissing(next); return; } - if (status === 'no-login') { + if (status === 'no-login' && next !== 'custom') { renderNotice((next === 'claude' ? 'Claude' : 'Codex') + ' is not signed in. Type /login to connect it.'); return; } diff --git a/packages/core/src/chat/ui/panel/main.ts b/packages/core/src/chat/ui/panel/main.ts index 06a87462..ab2cd2cb 100644 --- a/packages/core/src/chat/ui/panel/main.ts +++ b/packages/core/src/chat/ui/panel/main.ts @@ -5,6 +5,7 @@ // the bundle keeps every module at its legacy section position, which keeps the artifact diffable. import { vscode } from "./host.js"; import { S } from "./state.js"; +import { messageBinary } from "../../../runtime/engineRegistry.js"; import { log, approvalDock } from "./dom.js"; import { escapeHtml } from "./markdown.js"; import { syncWatermark, renderNotice, renderEngineBanner, renderLimitMeter, setCtxTokens, clearCtx, copyAction, renderEngineMissing, renderStatus, showLoading, hideLoading, wireShell } from "./shell.js"; @@ -347,10 +348,10 @@ window.addEventListener('message', (event) => { else hideCustomTab(); } else if (m.type === 'cliStatus') { - const previousStatus = S.cliReport?.[S.cli]; + const previousStatus = S.cliReport?.[messageBinary(S.cli)]; S.cliReport = { claude: m.claude, codex: m.codex }; - const status = S.cliReport[S.cli]; - if (status === 'no-login') renderNotice((S.cli === 'claude' ? 'Claude' : 'Codex') + ' is not signed in. Type /login to connect it.'); + const status = S.cliReport[messageBinary(S.cli)]; + if (status === 'no-login' && S.cli !== 'custom') renderNotice((S.cli === 'claude' ? 'Claude' : 'Codex') + ' is not signed in. Type /login to connect it.'); else if (status === 'missing' || status === 'node-missing') renderEngineMissing(S.cli); else if (status === 'ok' && previousStatus === 'node-missing') renderNotice((S.cli === 'claude' ? 'Claude' : 'Codex') + ' is ready.'); } diff --git a/packages/core/src/chat/ui/panel/shell.ts b/packages/core/src/chat/ui/panel/shell.ts index bcc2b69e..a90add7e 100644 --- a/packages/core/src/chat/ui/panel/shell.ts +++ b/packages/core/src/chat/ui/panel/shell.ts @@ -3,6 +3,7 @@ // modules in dependency order, and main.ts calls the wire functions in the legacy order so // listener registration and boot posts keep their sequence. import { S } from "./state.js"; +import { engineBinary } from "../../../runtime/engineRegistry.js"; // The core table directly: engine.ts imports this module, so no alias lives there. import { ENGINE_INSTALL_COMMAND, NODE_REQUIRED_MESSAGE, NODE_DOWNLOAD_URL } from "../../../runtime/engineInstall.js"; import { vscode } from "./host.js"; @@ -79,7 +80,7 @@ export function renderEngineBanner(text, actions, dismissKey) { // Missing engine: show how to get it instead of a dead-end "not installed" line. // "Install in terminal" runs the command visibly host-side (user watches it run). export function renderEngineMissing(which) { - if (S.cliReport?.[which] === 'node-missing') { + if (S.cliReport?.[engineBinary(which)] === 'node-missing') { renderActionNotice(NODE_REQUIRED_MESSAGE, [ ['Get Node.js', () => window.open(NODE_DOWNLOAD_URL, '_blank', 'noopener,noreferrer')], ['Check again', () => vscode.postMessage({ type: 'getCliStatus' })], diff --git a/packages/core/src/runtime/customEngine.spec.ts b/packages/core/src/runtime/customEngine.spec.ts index 42bf1fed..fd0db3c6 100644 --- a/packages/core/src/runtime/customEngine.spec.ts +++ b/packages/core/src/runtime/customEngine.spec.ts @@ -4,7 +4,7 @@ // its own global default model. Pin all three to throw or emit correctly. import { describe, it, expect } from "vitest"; import { spawnCli, customProviderFlags } from "./spawn.js"; -import { saveCustomEngineConfig, type CustomEngineConfig } from "../account/customEngineAuth.js"; +import { saveCustomEngineConfig, customEngineStatus, type CustomEngineConfig } from "../account/customEngineAuth.js"; const NOT_CONFIGURED = "Custom engine is not configured. Connect an endpoint before starting a custom session."; const NEEDS_MODEL = "The custom engine needs a model id; codex would otherwise silently use its own default model."; @@ -60,3 +60,8 @@ describe("account/customEngineAuth: saveCustomEngineConfig validation", () => { .rejects.toThrow(/^The custom engine base URL is not a valid URL\.$/); }); }); + + +it("reports a missing Node runtime before reading custom credentials", async () => { + expect(await customEngineStatus({ claude: "ok", codex: "node-missing" })).toBe("node-missing"); +}); diff --git a/packages/core/test/webview-custom-status.spec.js b/packages/core/test/webview-custom-status.spec.js new file mode 100644 index 00000000..40c0d674 --- /dev/null +++ b/packages/core/test/webview-custom-status.spec.js @@ -0,0 +1,8 @@ +import { expect, it } from "vitest"; +import { engineStatus } from "../../../surfaces/webview/src/state/store"; + +it("Custom inherits missing runtime status but not Codex login requirements", () => { + const state = { customEngine: { masked: "fixture.invalid" }, cliReport: { claude: "ok", codex: "node-missing" } }; + expect(engineStatus(state, "custom")).toBe("node-missing"); + expect(engineStatus({ ...state, cliReport: { claude: "ok", codex: "no-login" } }, "custom")).toBe("ok"); +}); diff --git a/surfaces/cli/src/views/Chat.tsx b/surfaces/cli/src/views/Chat.tsx index 25d082d0..4c338eb8 100644 --- a/surfaces/cli/src/views/Chat.tsx +++ b/surfaces/cli/src/views/Chat.tsx @@ -37,6 +37,8 @@ import { hasCustomEngine, maskedCustomEngine, type EngineKey, + NODE_REQUIRED_MESSAGE, + NODE_DOWNLOAD_URL, } from "@iqlabs-official/agent-sdk"; import { Select, TextInput } from "@inkjs/ui"; import open from "open"; diff --git a/surfaces/cli/src/views/LoginGate.tsx b/surfaces/cli/src/views/LoginGate.tsx index 857be0e1..5384eefb 100644 --- a/surfaces/cli/src/views/LoginGate.tsx +++ b/surfaces/cli/src/views/LoginGate.tsx @@ -22,6 +22,8 @@ import { maskedCustomEngine, type CustomEnginePreset, type EngineKey, + NODE_REQUIRED_MESSAGE, + NODE_DOWNLOAD_URL, type CliReport, type CliStatus, type ClaudeLogin, @@ -268,7 +270,7 @@ export function LoginGate({ }, [step]); function pick(engine: EngineKey) { - if (report[engine === "custom" ? "codex" : engine] === "node-missing") { + if (report[engineBinary(engine)] === "node-missing") { setErr(`${NODE_REQUIRED_MESSAGE} ${NODE_DOWNLOAD_URL}`); return; } diff --git a/surfaces/cli/src/views/Onboarding.tsx b/surfaces/cli/src/views/Onboarding.tsx index 958d045f..63017b8e 100644 --- a/surfaces/cli/src/views/Onboarding.tsx +++ b/surfaces/cli/src/views/Onboarding.tsx @@ -123,7 +123,7 @@ export function Onboarding({ const [installErr, setInstallErr] = useState(null); function runInstall() { - if (rep[engine] === "node-missing") return; + if (rep[engineBinary(engine)] === "node-missing") return; setInstalling(true); setInstallErr(null); setInstallLog([]); diff --git a/surfaces/webview/src/chat/Sessions.tsx b/surfaces/webview/src/chat/Sessions.tsx index 849d8099..50f040a2 100644 --- a/surfaces/webview/src/chat/Sessions.tsx +++ b/surfaces/webview/src/chat/Sessions.tsx @@ -6,6 +6,7 @@ import { IqLogo, AgentIcon, LockIcon, SkillIcon } from "../icons"; import { useOnline } from "../layoutEffects"; import agentnetWordmark from "../assets/agentnet.png"; import { haptics } from "../haptics"; +import { EngineMissingNotice } from "../onboarding/EngineMissingNotice"; // wifi-off mark for the offline states (no emoji; inline SVG per the design rules). function WifiOffIcon({ className, style }: { className?: string; style?: CSSProperties }) { @@ -180,7 +181,7 @@ function CustomEngineRow() { custom - {masked ? `${t(M.storagePicker.connected)} · ${masked}` : "Bring your own OpenAI-compatible endpoint"} + {engineStatus(state, "custom") === "node-missing" ? "Node.js required" : masked ? `${t(M.storagePicker.connected)} · ${masked}` : "Bring your own OpenAI-compatible endpoint"} {masked && ( @@ -200,6 +201,7 @@ function CustomEngineRow() { {masked ? "Edit" : t(M.engines.connect)} + {open && (
{presets.length > 0 && ( diff --git a/surfaces/webview/src/state/store.tsx b/surfaces/webview/src/state/store.tsx index 0f13fc23..5a7165b0 100644 --- a/surfaces/webview/src/state/store.tsx +++ b/surfaces/webview/src/state/store.tsx @@ -174,7 +174,8 @@ export function isApprovalForView(a: { sessionId?: string }, activeSessionId?: s export function engineStatus(state: State, cli: Cli): EngineStatus | undefined { if (!state.cliReport) return undefined; if (cli !== "custom") return state.cliReport[cli]; - if (state.cliReport.codex === "missing" || state.cliReport.codex === "node-missing") return state.cliReport.codex; + const status = state.cliReport.codex; + if (status === "missing" || status === "node-missing") return status; return state.customEngine?.masked != null ? "ok" : "no-login"; } From f3cbe833478951e4bccf3dae37ad54880b2f9e1b Mon Sep 17 00:00:00 2001 From: NubsCarson <192162056+NubsCarson@users.noreply.github.com> Date: Mon, 14 Sep 2026 23:48:53 -0400 Subject: [PATCH 11/12] fix: keep custom context capacity unknown across interfaces --- packages/core/src/chat/contextNotice.spec.ts | 11 ++++++++ packages/core/src/chat/contextNotice.ts | 23 +++++++++++++++ packages/core/src/chat/session.spec.ts | 20 ++++++++++++- packages/core/src/chat/session.ts | 27 ++---------------- .../core/src/runtime/codex-approvals.spec.ts | 6 +++- packages/core/src/runtime/spawn.ts | 4 +-- .../core/test/webview-custom-status.spec.js | 13 ++++++++- surfaces/cli/src/components/StatusLine.tsx | 5 ++-- surfaces/cli/src/views/Chat.tsx | 28 ++++++------------- surfaces/webview/src/state/store.tsx | 6 ++-- 10 files changed, 89 insertions(+), 54 deletions(-) create mode 100644 packages/core/src/chat/contextNotice.spec.ts create mode 100644 packages/core/src/chat/contextNotice.ts diff --git a/packages/core/src/chat/contextNotice.spec.ts b/packages/core/src/chat/contextNotice.spec.ts new file mode 100644 index 00000000..a0530d0d --- /dev/null +++ b/packages/core/src/chat/contextNotice.spec.ts @@ -0,0 +1,11 @@ +import { expect, it } from "vitest"; +import { contextNotice } from "./contextNotice.js"; + +it("retains the standard engine breakdown and supplied window", () => { + expect(contextNotice("claude", 10000, 100000)).toContain("10,000 / 100,000 (10%)"); + expect(contextNotice("codex")).toContain("256,000"); +}); +it("Custom never presents a Codex fallback as provider capacity", () => { + expect(contextNotice("custom", 12000, 256000)).toBe("Context (custom): 12,000 tokens used. Provider context limit unknown."); + expect(contextNotice("custom")).toContain("usage not reported yet"); +}); diff --git a/packages/core/src/chat/contextNotice.ts b/packages/core/src/chat/contextNotice.ts new file mode 100644 index 00000000..f0ae4219 --- /dev/null +++ b/packages/core/src/chat/contextNotice.ts @@ -0,0 +1,23 @@ +import type { EngineKey } from "../runtime/engineRegistry.js"; + +// Shared by the terminal and host-dispatched /context command. +export function contextNotice(cli: EngineKey, used?: number, reportedWindow?: number): string { + const fmt = (n: number) => Math.round(n).toLocaleString("en-US"); + // Custom runs through Codex, whose reported window may be its own fallback. + // It is not evidence of the configured provider's capacity or compaction policy. + if (cli === "custom") { + return used === undefined + ? "Context: usage not reported yet. Provider context limit unknown." + : `Context (custom): ${fmt(used)} tokens used. Provider context limit unknown.`; + } + const window = reportedWindow ?? (cli === "claude" ? 200_000 : 256_000); + if (used === undefined) return `Context: 0 / ${fmt(window)} tokens. Send a message to measure usage.`; + const free = Math.max(0, window - used); + const pct = Math.round((used / window) * 100); + const threshold = Math.max(0, window - 33_000); + const tpct = Math.round((threshold / window) * 100); + return `Context window (${cli})\n` + + ` used ${fmt(used)} / ${fmt(window)} (${pct}%)\n` + + ` free ${fmt(free)}\n` + + ` auto-compact at ~${fmt(threshold)} (${tpct}%)`; +} diff --git a/packages/core/src/chat/session.spec.ts b/packages/core/src/chat/session.spec.ts index f9cc206c..751b0877 100644 --- a/packages/core/src/chat/session.spec.ts +++ b/packages/core/src/chat/session.spec.ts @@ -9,7 +9,7 @@ import { mkdtemp, readFile, rm } from "node:fs/promises"; import { join } from "node:path"; import { tmpdir } from "node:os"; -function fakeHandle(id: string, cli: "claude" | "codex") { +function fakeHandle(id: string, cli: "claude" | "codex" | "custom") { const usageCbs: Array<(n: number, window?: number) => void> = []; const compactCbs: Array<() => void> = []; const msgCbs: Array<(msg: any) => void> = []; @@ -674,3 +674,21 @@ describe("chat/session — feed anchor re-prime after a bumping blog comment (is expect(getBlogFeed).toHaveBeenCalledWith(undefined, "latest", true); }); }); + +describe("Custom context reporting", () => { + it("never derives provider capacity or compaction from a Codex window", async () => { + const { handles, fromUI, transport, chat } = harness(); + try { + fromUI({ type: "platform", cli: "custom" }); + fromUI({ type: "slashCommand", command: "context" }); + await flush(); + expect(transport.send).toHaveBeenCalledWith({ type: "notice", text: "Context: usage not reported yet. Provider context limit unknown." }); + fromUI({ type: "send", text: "fixture" }); + await flush(); + handles[0].emitUsage(12000, 256000); + fromUI({ type: "slashCommand", command: "context" }); + await flush(); + expect(transport.send).toHaveBeenCalledWith({ type: "notice", text: "Context (custom): 12,000 tokens used. Provider context limit unknown." }); + } finally { chat.stop(); } + }); +}); diff --git a/packages/core/src/chat/session.ts b/packages/core/src/chat/session.ts index 556ff099..48295e34 100644 --- a/packages/core/src/chat/session.ts +++ b/packages/core/src/chat/session.ts @@ -20,11 +20,7 @@ import { customModelOption, type ChatModelOption } from "./modelOptions.js"; import { loadCustomEngineConfig, customEngineStatus } from "../account/customEngineAuth.js"; import { ENGINE_KEYS, ENGINE_REGISTRY, type EngineKey } from "../runtime/engineRegistry.js"; -// Format a token count with thousands separators (e.g. 167000 → "167,000") for the -// /context breakdown notice. -function fmtTok(n: number): string { - return Math.round(n).toLocaleString("en-US"); -} +import { contextNotice } from "./contextNotice.js"; // The two-way pipe to ONE chat UI (one panel / one socket). Messages both ways are // flat {type, ...} JSON — the same shape the webview already speaks. @@ -716,26 +712,7 @@ export function createChatSession( // have per-category token data from the engines, so we report the totals we do have. if (command === "context") { const s = slot(); - const window = s.lastWindow ?? (cli === "claude" ? 200_000 : 256_000); - if (s.lastUsage === undefined) { - transport.send({ type: "notice", text: `Context: 0 / ${fmtTok(window)} tokens. Send a message to measure usage.` }); - break; - } - const used = s.lastUsage; - const free = Math.max(0, window - used); - const pct = Math.round((used / window) * 100); - // auto-compact reserve: ~20k for the model's reply + ~13k summary headroom, - // matching Claude Code's effectiveWindow − 13k formula. - const threshold = Math.max(0, window - 33_000); - const tpct = Math.round((threshold / window) * 100); - transport.send({ - type: "notice", - text: - `Context window (${cli})\n` + - ` used ${fmtTok(used)} / ${fmtTok(window)} (${pct}%)\n` + - ` free ${fmtTok(free)}\n` + - ` auto-compact at ~${fmtTok(threshold)} (${tpct}%)`, - }); + transport.send({ type: "notice", text: contextNotice(cli, s.lastUsage, s.lastWindow) }); break; } if (command === "resume") { diff --git a/packages/core/src/runtime/codex-approvals.spec.ts b/packages/core/src/runtime/codex-approvals.spec.ts index b534917e..ac46a740 100644 --- a/packages/core/src/runtime/codex-approvals.spec.ts +++ b/packages/core/src/runtime/codex-approvals.spec.ts @@ -73,12 +73,16 @@ describe.each([ expect(requests[1].params).toMatchObject({ approvalPolicy: policy, approvalsReviewer: "user" }); expect(requests[1].params.sandbox).toBe(sandbox); expect(requests[1].params.modelProvider).toBe(cli === "custom" ? "custom" : undefined); + stdout.write(JSON.stringify({ method: "thread/tokenUsage/updated", params: { + tokenUsage: { last: { totalTokens: 1000 } }, + } }) + "\n"); + expect(usage).toHaveBeenLastCalledWith(1000, cli === "custom" ? undefined : 256000); // A second turn adds to billed totals, not to current context occupancy. for (const [total, last] of [[40000, 20000], [60000, 21000], [61000, 1000]]) { stdout.write(JSON.stringify({ method: "thread/tokenUsage/updated", params: { tokenUsage: { total: { totalTokens: total }, last: { totalTokens: last }, modelContextWindow: 32000 }, } }) + "\n"); - expect(usage).toHaveBeenLastCalledWith(last, 32000); + expect(usage).toHaveBeenLastCalledWith(last, cli === "custom" ? undefined : 32000); } for (const [id, outcome] of (["once", "deny", "always"] as const).entries()) { approve.mockResolvedValueOnce({ outcome }); diff --git a/packages/core/src/runtime/spawn.ts b/packages/core/src/runtime/spawn.ts index c06070ba..1fac5707 100644 --- a/packages/core/src/runtime/spawn.ts +++ b/packages/core/src/runtime/spawn.ts @@ -585,7 +585,7 @@ function codexEngine(opts: SpawnOpts): Engine { const cb = callbacks(); // last known context-window size (tokens). Seeded with the model default; replaced by // the real modelContextWindow the moment the server reports it in a usage notification. - let knownWindow = defaultWindow("codex", opts.model); + let knownWindow = opts.cli === "custom" ? undefined : defaultWindow("codex", opts.model); const approval = opts.approval ?? autoApprove(); const codexPath = resolveEngineBin("codex"); @@ -800,7 +800,7 @@ function codexEngine(opts: SpawnOpts): Engine { // turns and must not be shown as context occupancy. const tu = params?.tokenUsage; if (tu) { - if (typeof tu.modelContextWindow === "number") knownWindow = tu.modelContextWindow; + if (opts.cli !== "custom" && typeof tu.modelContextWindow === "number") knownWindow = tu.modelContextWindow; const last = tu.last?.totalTokens; if (typeof last === "number") cb.emitUsage(last, knownWindow); } diff --git a/packages/core/test/webview-custom-status.spec.js b/packages/core/test/webview-custom-status.spec.js index 40c0d674..82d4ac65 100644 --- a/packages/core/test/webview-custom-status.spec.js +++ b/packages/core/test/webview-custom-status.spec.js @@ -1,8 +1,19 @@ import { expect, it } from "vitest"; -import { engineStatus } from "../../../surfaces/webview/src/state/store"; +import { engineStatus, reducer } from "../../../surfaces/webview/src/state/store"; it("Custom inherits missing runtime status but not Codex login requirements", () => { const state = { customEngine: { masked: "fixture.invalid" }, cliReport: { claude: "ok", codex: "node-missing" } }; expect(engineStatus(state, "custom")).toBe("node-missing"); expect(engineStatus({ ...state, cliReport: { claude: "ok", codex: "no-login" } }, "custom")).toBe("ok"); }); + +it("Custom status reports tokens without a provider limit, including stale window state", () => { + const state = { contextWindow: 256000 }; + const result = reducer(state, { type: "status", status: { cli: "custom", contextTokens: 12000, contextWindow: 256000 } }); + expect(result.toast).toContain("ctx 12k tokens (provider limit unknown)"); + expect(result.toast).not.toMatch(/256|%/); +}); +it("status uses the reporting engine's window rather than the visible engine's stale window", () => { + const result = reducer({ contextWindow: 256000 }, { type: "status", status: { cli: "claude", contextTokens: 10000, contextWindow: 100000 } }); + expect(result.toast).toContain("ctx 10k / 100k (10%)"); +}); diff --git a/surfaces/cli/src/components/StatusLine.tsx b/surfaces/cli/src/components/StatusLine.tsx index 81277a8f..c9252b38 100644 --- a/surfaces/cli/src/components/StatusLine.tsx +++ b/surfaces/cli/src/components/StatusLine.tsx @@ -43,6 +43,7 @@ export function StatusLine({ const usedFrac = ctx ?? 0; const tokenLabel = ctxTokens !== undefined && ctxWindow !== undefined ? `${fmtK(ctxTokens)}/${fmtK(ctxWindow)}` + : ctxTokens !== undefined ? `${fmtK(ctxTokens)} tokens` : ctx !== undefined ? `${Math.round(usedFrac * 100)}%` : ""; // Still exactly one row: the frame is fixed height, so a wrap here shifts every band @@ -62,9 +63,9 @@ export function StatusLine({ {status} - {ctx !== undefined ? ( + {tokenLabel ? ( - + {ctx !== undefined && } {tokenLabel} ) : null} diff --git a/surfaces/cli/src/views/Chat.tsx b/surfaces/cli/src/views/Chat.tsx index 4c338eb8..980561bd 100644 --- a/surfaces/cli/src/views/Chat.tsx +++ b/surfaces/cli/src/views/Chat.tsx @@ -1,3 +1,4 @@ +import { contextNotice } from "@iqlabs-official/agent-sdk/chat/contextNotice"; import React, { useEffect, useMemo, useRef, useState, useCallback } from "react"; import { Box, Text, Static, useApp, useInput, useStdout } from "ink"; import type { AgentRuntime, Wallet, ChatMessage, SkillActivation } from "@iqlabs-official/agent-sdk/runtime/contract"; @@ -1101,22 +1102,7 @@ export function Chat({ return; } case "context": { - const win = chat.contextWindow ?? (engineBinary(chat.cli) === "codex" ? 256_000 : 200_000); - if (chat.contextTokens === undefined) { - setNotice(`Context: 0 / ${win.toLocaleString()} tokens. Send a message to measure usage.`); - return; - } - const used = chat.contextTokens; - const free = Math.max(0, win - used); - const pct = Math.round((used / win) * 100); - const threshold = Math.max(0, win - 33_000); - const tpct = Math.round((threshold / win) * 100); - setNotice( - `Context window (${chat.cli})\n` + - ` used ${used.toLocaleString()} / ${win.toLocaleString()} (${pct}%)\n` + - ` free ${free.toLocaleString()}\n` + - ` auto-compact at ~${threshold.toLocaleString()} (${tpct}%)` - ); + setNotice(contextNotice(chat.cli, chat.contextTokens, chat.contextWindow)); return; } case "wallet": @@ -1213,7 +1199,9 @@ export function Chat({ const win = chat.contextWindow ?? (engineBinary(chat.cli) === "codex" ? 256_000 : 200_000); const used = chat.contextTokens ?? Math.round(chat.messages.reduce((n, m) => n + m.text.length, 0) / 4); lines.push(`model ${chat.model ?? "default"}`); - lines.push(`ctx used ${used.toLocaleString()} / ${win.toLocaleString()} tokens`); + lines.push(chat.cli === "custom" + ? `ctx used ${chat.contextTokens === undefined ? "not reported" : chat.contextTokens.toLocaleString() + " tokens"} (provider limit unknown)` + : `ctx used ${used.toLocaleString()} / ${win.toLocaleString()} tokens`); setAccountLines(lines); setShowAccount(true); })(); @@ -1259,15 +1247,15 @@ export function Chat({ const mood: Mood = eggMood ?? (pendingApproval ? "tool" : chat.busy ? "thinking" : idle ? "sleeping" : "idle"); // context-left: prefer the engine's REAL per-turn usage; before the first turn reports, // fall back to a rough chars/4 estimate so the meter isn't blank. - const WINDOW = chat.contextWindow ?? (engineBinary(chat.cli) === "codex" ? 256_000 : 200_000); + const WINDOW = chat.cli === "custom" ? undefined : chat.contextWindow ?? (engineBinary(chat.cli) === "codex" ? 256_000 : 200_000); // Only fall back to char-count estimate when there are actual messages — otherwise // the bar shows 0/200k on every fresh session which is meaningless noise. const usedTokens = chat.contextTokens ?? - (chat.messages.length > 0 + (chat.cli !== "custom" && chat.messages.length > 0 ? chat.messages.reduce((n, m) => n + m.text.length, 0) / 4 : undefined); - const usedFrac = usedTokens !== undefined ? Math.min(1, usedTokens / WINDOW) : undefined; + const usedFrac = usedTokens !== undefined && WINDOW !== undefined ? Math.min(1, usedTokens / WINDOW) : undefined; const ctxReal = chat.contextTokens !== undefined; // An approval that arrives while the user is on ANOTHER screen must not be invisible. diff --git a/surfaces/webview/src/state/store.tsx b/surfaces/webview/src/state/store.tsx index 5a7165b0..ac9dd530 100644 --- a/surfaces/webview/src/state/store.tsx +++ b/surfaces/webview/src/state/store.tsx @@ -539,11 +539,13 @@ export function reducer(state: State, ev: Action): State { return { ...state, toast: ev.text }; case "status": { const s = ev.status; - const win = state.contextWindow ?? (s.cli === "claude" ? 200_000 : 256_000); + const win = s.contextWindow ?? (s.cli === "claude" ? 200_000 : 256_000); const fmtK = (n: number) => n >= 1000 ? Math.round(n / 1000) + "k" : String(n); const ctx = s.contextTokens === undefined ? "" - : `, ctx ${fmtK(s.contextTokens)} / ${fmtK(win)} (${Math.round((s.contextTokens / win) * 100)}%)`; + : s.cli === "custom" + ? `, ctx ${fmtK(s.contextTokens)} tokens (provider limit unknown)` + : `, ctx ${fmtK(s.contextTokens)} / ${fmtK(win)} (${Math.round((s.contextTokens / win) * 100)}%)`; return { ...state, toast: `${s.cli}: model ${s.model ?? "default"}, mode ${s.mode ?? "default"}, effort ${s.effort ?? "default"}${ctx}`, From f855fbb3ee334b390fb2574cdd04c9edf65cbe09 Mon Sep 17 00:00:00 2001 From: NubsCarson <192162056+NubsCarson@users.noreply.github.com> Date: Wed, 16 Sep 2026 22:23:21 -0400 Subject: [PATCH 12/12] build: regenerate custom panel after upstream integration --- packages/core/src/chat/ui/panel.generated.ts | 2 +- surfaces/cli/src/views/Chat.tsx | 2 -- surfaces/cli/src/views/LoginGate.tsx | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/core/src/chat/ui/panel.generated.ts b/packages/core/src/chat/ui/panel.generated.ts index 5fbb9352..e4b69c71 100644 --- a/packages/core/src/chat/ui/panel.generated.ts +++ b/packages/core/src/chat/ui/panel.generated.ts @@ -1,2 +1,2 @@ // AUTO-GENERATED by scripts/buildPanel.ts from src/chat/ui/panel/ -- DO NOT EDIT; re-run pnpm build:panel -export const PANEL_SCRIPT = "\"use strict\";\n(() => {\n // src/chat/ui/panel/host.ts\n var vscode = typeof acquireVsCodeApi === \"function\" ? acquireVsCodeApi() : (() => {\n let clientId = null;\n const outbox = [];\n function post(s) {\n fetch(\"/rpc?client=\" + encodeURIComponent(clientId), {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: s\n }).catch(() => {\n });\n }\n function open(url) {\n const es = new EventSource(url);\n es.addEventListener(\"client\", (e) => {\n const id = JSON.parse(e.data).client;\n if (clientId === null) {\n clientId = id;\n es.close();\n open(\"/events?client=\" + encodeURIComponent(id));\n for (const m of outbox.splice(0)) post(m);\n }\n });\n es.onmessage = (e) => window.dispatchEvent(new MessageEvent(\"message\", { data: JSON.parse(e.data) }));\n }\n open(\"/events\");\n return {\n postMessage: (obj) => {\n const s = JSON.stringify(obj);\n if (clientId !== null) post(s);\n else outbox.push(s);\n }\n };\n })();\n function uiGet(k) {\n try {\n const s = vscode.getState && vscode.getState();\n return s ? s[k] : void 0;\n } catch (e) {\n return void 0;\n }\n }\n function uiSet(k, v) {\n try {\n if (!vscode.setState) return;\n const s = vscode.getState && vscode.getState() || {};\n s[k] = v;\n vscode.setState(s);\n } catch (e) {\n }\n }\n\n // src/chat/ui/panel/state.ts\n var S = {\n // ---- shell.ts ----\n stick: true,\n hasNew: false,\n // new content arrived while scrolled up → light the button in the engine accent\n streaming: null,\n // bubble currently being streamed into\n streamRaf: 0,\n // rAF handle: coalesces live-markdown renders to one paint/frame\n streamTimer: 0,\n // trailing timer that defers the next render to the cadence boundary\n lastStreamRender: 0,\n // when the live bubble was last re-rendered\n // ---- sessions.ts ----\n allSessions: [],\n // last sessions payload from extension\n cloudListState: \"none\",\n // cloud health of that payload's union (ok/reauth/transient/none)\n activeId: null,\n expanded: false,\n // \"모두 보기\" toggled?\n // ---- slash.ts ----\n slashIdx: 0,\n suppressSlash: false,\n activeSlashMatches: [],\n // ---- engine.ts ----\n cli: \"claude\",\n cliReport: null,\n // ---- turns.ts ----\n tailTurn: null,\n // the turn new (bottom) replies attach to\n headTurn: null,\n // the turn prepended (top, older) replies attach to\n openBash: null,\n // a bash card awaiting its output (claude's split result)\n // ---- composer.ts ----\n typingEl: null,\n busy: false,\n attached: [],\n pendingSentImages: [],\n growRaf: 0,\n // ---- storage.ts ----\n storageOptions: [],\n cloudConnected: false,\n cloudKind: \"\",\n // which backend is connected, so a reauth prompt can reconnect the right one\n // ---- publish.ts ----\n pubKind: \"skill\",\n pubBodyConfirmed: false,\n // ---- feed.ts ----\n currentProfileWallet: null,\n agentsTab: \"feed\",\n // persists across view switches, same as profileTab\n feedSort: \"active\",\n // ACTIVE = lastActivityTime, LATEST = createdAt\n feedPosts: null,\n // null = never loaded (skeletons), [] = settled empty\n currentFeedPost: null,\n // the post open in the reader\n feedLastSage: false,\n // whether the comment in flight was sage (skips the fresh re-read)\n feedReplyTo: null,\n // id of the comment being answered (mobile CommentThreadList idiom)\n fabModalEl: null,\n // ---- quotes.ts ----\n quoteCards: {},\n // postId -> [placeholder card elements] awaiting the reply\n quoteSeen: {},\n // postId -> true once carded in the current render pass\n quoteSlots: 0,\n // unique refs carded in the current render pass\n // ---- agents.ts ----\n lastAgents: [],\n recentlyPosted: [],\n // [{ wallet, note, ts }]\n pendingPost: null,\n // { wallet, text, gitLink, self } - stashed at submit for agentNoteResult\n postFeedback: null,\n // { wallet, text, ok, ts } - survives the immediate profile re-render\n profileTab: \"agent\",\n // ---- profile.ts ----\n repoModalEl: null,\n // ---- skills.ts ----\n ownedSkills: [],\n skillMints: {},\n // slug/name -> mint for bought NFT skills (reuse market detail)\n workflowMintSet: /* @__PURE__ */ new Set(),\n // owned mints that are workflows (excluded from the workflow picker)\n disposedMints: {},\n // slug -> mint for un-pinned skills (greyed in the panel)\n disposedMintSet: /* @__PURE__ */ new Set(),\n // the mints above, for isDisposed() detail checks\n // ---- market.ts ----\n lastMarketResults: [],\n // last search results, kept to re-render on owned-list change\n currentKind: \"skill\",\n // active tab: Skills | Workflows\n currentDetail: null,\n // { id, type } of the open detail - for comments refresh\n hideOwnedMarket: void 0,\n mktSort: void 0,\n skillModalOpen: false,\n skillModalBuyBtn: null,\n skillModalName: null,\n skillModalMint: null,\n skillDocOpen: false,\n currentDetailName: null,\n detailBuyBtn: null,\n // ---- overlays.ts ----\n celebTimer: null,\n solLamports: null,\n // last known balance (lamports); null = unknown/failed\n buyErrTimer: null,\n dasReady: false,\n rpcNetwork: \"devnet\",\n // drives explorer-link cluster (set from rpcStatus)\n pick: 0,\n // rotate so the verb feels alive\n actTimer: null,\n firingTimer: null,\n // ---- wallet.ts ----\n myWalletAddress: null,\n // tracked so openWalletPage can showProfile(own)\n // ---- paging.ts ----\n pageCursor: null,\n // cursor for the NEXT older page (null = none / at start)\n hasMore: false,\n // older pages exist?\n loadingOlder: false,\n lastOlderCursor: null\n // last cursor we asked for; never auto-request the same one twice\n };\n\n // src/chat/ui/panel/dom.ts\n var log = document.getElementById(\"log\");\n var mainEl = document.getElementById(\"main\");\n var loadingEl = document.getElementById(\"loading\");\n var jumpBtn = document.getElementById(\"jumpBtn\");\n var input = document.getElementById(\"input\");\n var sessList = document.getElementById(\"sessList\");\n var showAll = document.getElementById(\"showAll\");\n var emptyEl = document.getElementById(\"empty\");\n var modelBtn = document.getElementById(\"modelBtn\");\n var modelMenu = document.getElementById(\"modelMenu\");\n var modelLabel = document.getElementById(\"modelLabel\");\n var composer = document.getElementById(\"composer\");\n var modeBtn = document.getElementById(\"modeBtn\");\n var modeMenu = document.getElementById(\"modeMenu\");\n var modeLabel = document.getElementById(\"modeLabel\");\n var modeEffortTag = document.getElementById(\"modeEffortTag\");\n var ctxMeter = document.getElementById(\"ctxMeter\");\n var limitMeter = document.getElementById(\"limitMeter\");\n var approvalDock = document.getElementById(\"approvalDock\");\n var engineBanner = document.getElementById(\"engineBanner\");\n var slashMenu = document.getElementById(\"slashMenu\");\n var tabs = Array.from(document.querySelectorAll(\".etab\"));\n\n // src/chat/ui/panel/markdown.ts\n var MD_OK = !!(window.marked && window.DOMPurify);\n if (MD_OK) window.marked.setOptions({ breaks: true, gfm: true });\n var COPY_ICON = '';\n var CHECK_ICON = '';\n function copyText(text, done) {\n if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(text).then(done, () => {\n });\n else {\n const ta = document.createElement(\"textarea\");\n ta.value = text;\n document.body.appendChild(ta);\n ta.select();\n try {\n document.execCommand(\"copy\");\n done();\n } catch (e2) {\n }\n document.body.removeChild(ta);\n }\n }\n function addPreCopyButtons(root) {\n const pres = root.querySelectorAll(\"pre\");\n for (let i = 0; i < pres.length; i++) {\n const pre = pres[i];\n if (!pre.parentNode || pre.parentNode.classList && pre.parentNode.classList.contains(\"preWrap\")) continue;\n const wrap = document.createElement(\"div\");\n wrap.className = \"preWrap\";\n pre.parentNode.insertBefore(wrap, pre);\n wrap.appendChild(pre);\n const btn = document.createElement(\"button\");\n btn.className = \"preCopy\";\n btn.title = \"Copy code\";\n btn.innerHTML = COPY_ICON;\n btn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n const code = pre.querySelector(\"code\");\n copyText((code || pre).textContent || \"\", () => {\n btn.classList.add(\"done\");\n btn.innerHTML = CHECK_ICON;\n setTimeout(() => {\n btn.classList.remove(\"done\");\n btn.innerHTML = COPY_ICON;\n }, 1200);\n });\n });\n wrap.appendChild(btn);\n }\n }\n function addInlineCopy(root) {\n const codes = root.querySelectorAll(\"code\");\n for (let i = 0; i < codes.length; i++) {\n const code = codes[i];\n if (code.closest(\"pre\") || code.closest(\"a\") || code.classList.contains(\"inlineCopy\")) continue;\n code.classList.add(\"inlineCopy\");\n code.title = \"Click to copy\";\n code.addEventListener(\"click\", () => {\n const sel = window.getSelection();\n if (sel && !sel.isCollapsed) return;\n copyText(code.textContent || \"\", () => {\n code.classList.add(\"done\");\n setTimeout(() => code.classList.remove(\"done\"), 1200);\n });\n });\n }\n }\n function renderMd(el, text) {\n el.dataset.md = text;\n el._mdDone = null;\n el._mdTail = null;\n el._mdTailRaw = null;\n if (!MD_OK) {\n el.textContent = text;\n return;\n }\n try {\n el.innerHTML = window.DOMPurify.sanitize(window.marked.parse(text));\n addPreCopyButtons(el);\n addInlineCopy(el);\n } catch (e) {\n el.textContent = text;\n }\n }\n function renderMdStreaming(el, text) {\n el.dataset.md = text;\n if (!MD_OK) {\n el.textContent = text;\n return;\n }\n try {\n const tokens = window.marked.lexer(text);\n const stable = Math.max(0, tokens.length - 1);\n let done = el._mdDone;\n let ok = !!done && done.length <= stable;\n for (let i = 0; ok && i < done.length; i++) if (tokens[i].raw !== done[i]) ok = false;\n if (!ok) {\n el.innerHTML = \"\";\n el._mdDone = done = [];\n el._mdTail = null;\n el._mdTailRaw = null;\n }\n if (!el._mdTail) {\n el._mdTail = document.createElement(\"div\");\n el._mdTail.className = \"mdChunk\";\n el._mdTailRaw = null;\n el.appendChild(el._mdTail);\n }\n for (let i = done.length; i < stable; i++) {\n const div = document.createElement(\"div\");\n div.className = \"mdChunk\";\n div.innerHTML = window.DOMPurify.sanitize(window.marked.parse(tokens[i].raw));\n addPreCopyButtons(div);\n addInlineCopy(div);\n el.insertBefore(div, el._mdTail);\n done.push(tokens[i].raw);\n }\n const tailRaw = stable < tokens.length ? tokens[stable].raw : \"\";\n if (tailRaw !== el._mdTailRaw) {\n el._mdTail.innerHTML = window.DOMPurify.sanitize(window.marked.parse(tailRaw));\n addPreCopyButtons(el._mdTail);\n addInlineCopy(el._mdTail);\n el._mdTailRaw = tailRaw;\n }\n } catch (e) {\n el.textContent = text;\n el._mdDone = null;\n el._mdTail = null;\n el._mdTailRaw = null;\n }\n }\n function escapeHtml(s) {\n const d = document.createElement(\"div\");\n d.textContent = s;\n return d.innerHTML;\n }\n\n // src/runtime/engineInstall.ts\n var NODE_REQUIRED_MESSAGE = \"This engine is installed, but Node.js is missing. Install Node.js, restart AgentNet, then retry.\";\n var NODE_DOWNLOAD_URL = \"https://nodejs.org/en/download\";\n var ENGINE_INSTALL_COMMAND = {\n codex: \"npm install -g @openai/codex\",\n claude: \"npm install -g @anthropic-ai/claude-code\"\n };\n var CODEX_UPDATE_COMMAND = \"codex update\";\n\n // src/chat/slashCommands.ts\n var both = [\"claude\", \"codex\"];\n var CHAT_SLASH_COMMANDS = [\n { name: \"login\", desc: \"sign in to the active engine\", engines: both, args: \"[code]\" },\n { name: \"logout\", desc: \"sign out of the active engine\", engines: both },\n { name: \"new\", desc: \"start a fresh chat\", engines: both },\n { name: \"clear\", desc: \"clear context and start fresh\", engines: both, args: \"[name]\" },\n { name: \"compact\", desc: \"summarize the conversation to free context\", engines: both, args: \"[instructions]\" },\n { name: \"status\", desc: \"show session, model, context, and account status\", engines: both },\n { name: \"resume\", desc: \"resume a saved conversation\", engines: both, args: \"[session]\" },\n { name: \"diff\", desc: \"show working-tree changes\", engines: [\"claude\", \"codex\"] },\n { name: \"permissions\", desc: \"manage tool permission rules\", engines: both, args: \"[mode]\" },\n { name: \"init\", desc: \"create project instructions\", engines: both },\n { name: \"review\", desc: \"review local changes or a PR\", engines: both, args: \"[target]\" },\n { name: \"mcp\", desc: \"manage or list MCP servers\", engines: both, args: \"[subcommand]\" },\n { name: \"skills\", desc: \"list or refresh available skills\", engines: both },\n { name: \"usage\", desc: \"show usage, limits, or token activity\", engines: both },\n { name: \"cost\", desc: \"alias for usage/status\", engines: both },\n { name: \"stats\", desc: \"alias for usage\", engines: [\"claude\"] },\n { name: \"copy\", desc: \"copy the latest assistant response\", engines: both, args: \"[N]\" },\n { name: \"engine\", desc: \"switch AgentNet engine\", engines: both, args: \"claude|codex\" },\n { name: \"model\", desc: \"switch the active model\", engines: both, args: \"[model]\" },\n { name: \"mode\", desc: \"change AgentNet permission mode\", engines: both, args: \"[mode]\" },\n { name: \"effort\", desc: \"set reasoning effort\", engines: both, args: \"[level]\" },\n { name: \"help\", desc: \"show slash commands\", engines: both },\n // Claude Code commands and bundled skills.\n { name: \"add-dir\", desc: \"grant file access to another directory\", engines: [\"claude\"], args: \"\" },\n { name: \"advisor\", desc: \"enable or disable advisor model guidance\", engines: [\"claude\"], args: \"[model|off]\" },\n { name: \"agents\", desc: \"manage agent configurations and background agents\", engines: [\"claude\"] },\n { name: \"autofix-pr\", desc: \"start a cloud session to fix PR feedback\", engines: [\"claude\"], args: \"[prompt]\" },\n { name: \"background\", desc: \"detach the current session to keep running\", engines: [\"claude\"], args: \"[prompt]\" },\n { name: \"batch\", desc: \"orchestrate large changes across worktrees\", engines: [\"claude\"], args: \"\" },\n { name: \"branch\", desc: \"fork the conversation into a branch\", engines: [\"claude\"], args: \"[name]\" },\n { name: \"btw\", desc: \"ask a side question without bloating history\", engines: both, args: \"\" },\n { name: \"cd\", desc: \"move the session to another working directory\", engines: [\"claude\"], args: \"\" },\n { name: \"chrome\", desc: \"configure Claude Chrome integration\", engines: [\"claude\"] },\n { name: \"claude-api\", desc: \"load Claude API guidance or migration help\", engines: [\"claude\"], args: \"[migrate|managed-agents-onboard]\" },\n { name: \"code-review\", desc: \"review changes and optionally apply fixes\", engines: [\"claude\"], args: \"[effort] [--fix] [target]\" },\n { name: \"color\", desc: \"set the prompt bar color\", engines: [\"claude\"], args: \"[color|default]\" },\n { name: \"config\", desc: \"open or update Claude settings\", engines: [\"claude\"], args: \"[key=value ...]\" },\n { name: \"context\", desc: \"visualize current context usage\", engines: [\"claude\"], args: \"[all]\" },\n { name: \"debug\", desc: \"enable debug logging and diagnose an issue\", engines: [\"claude\"], args: \"[description]\" },\n { name: \"deep-research\", desc: \"run a cited multi-search research workflow\", engines: [\"claude\"], args: \"\" },\n { name: \"desktop\", desc: \"continue in Claude Code Desktop\", engines: [\"claude\"] },\n { name: \"doctor\", desc: \"diagnose installation and runtime issues\", engines: [\"claude\"] },\n { name: \"exit\", desc: \"exit or detach the native CLI session\", engines: both },\n { name: \"export\", desc: \"export the conversation as text\", engines: [\"claude\"], args: \"[filename]\" },\n { name: \"fast\", desc: \"toggle fast mode when available\", engines: both, args: \"[on|off|status]\" },\n { name: \"feedback\", desc: \"send feedback with optional logs\", engines: both, args: \"[report]\" },\n { name: \"fewer-permission-prompts\", desc: \"suggest permission allowlist rules\", engines: [\"claude\"] },\n { name: \"focus\", desc: \"toggle Claude focus view\", engines: [\"claude\"] },\n { name: \"fork\", desc: \"fork work into a subagent or new thread\", engines: both, args: \"\" },\n { name: \"goal\", desc: \"set, view, pause, resume, or clear a goal\", engines: both, args: \"[condition|clear]\" },\n { name: \"heapdump\", desc: \"write a heap snapshot for diagnostics\", engines: [\"claude\"] },\n { name: \"hooks\", desc: \"view and manage lifecycle hooks\", engines: both },\n { name: \"ide\", desc: \"manage IDE integration or include IDE context\", engines: both },\n { name: \"insights\", desc: \"generate a Claude Code usage report\", engines: [\"claude\"] },\n { name: \"install-github-app\", desc: \"set up Claude GitHub Actions\", engines: [\"claude\"] },\n { name: \"install-slack-app\", desc: \"install the Claude Slack app\", engines: [\"claude\"] },\n { name: \"keybindings\", desc: \"open Claude keybindings\", engines: [\"claude\"] },\n { name: \"loop\", desc: \"run a prompt repeatedly\", engines: [\"claude\"], args: \"[interval] [prompt]\" },\n { name: \"memory\", desc: \"edit Claude memory files\", engines: [\"claude\"] },\n { name: \"mobile\", desc: \"show mobile app QR code\", engines: [\"claude\"] },\n { name: \"passes\", desc: \"share a free Claude Code week if eligible\", engines: [\"claude\"] },\n { name: \"plan\", desc: \"enter plan mode\", engines: both, args: \"[description]\" },\n { name: \"plugin\", desc: \"manage Claude plugins\", engines: [\"claude\"], args: \"[subcommand]\" },\n { name: \"powerup\", desc: \"open Claude Code feature lessons\", engines: [\"claude\"] },\n { name: \"privacy-settings\", desc: \"view privacy settings\", engines: [\"claude\"] },\n { name: \"radio\", desc: \"open Claude FM\", engines: [\"claude\"] },\n { name: \"recap\", desc: \"generate a one-line session recap\", engines: [\"claude\"] },\n { name: \"release-notes\", desc: \"view Claude Code release notes\", engines: [\"claude\"] },\n { name: \"reload-plugins\", desc: \"reload active plugins\", engines: [\"claude\"], args: \"[--force]\" },\n { name: \"reload-skills\", desc: \"rescan skills and command directories\", engines: [\"claude\"] },\n { name: \"remote-control\", desc: \"enable remote control\", engines: [\"claude\"] },\n { name: \"remote-env\", desc: \"choose cloud agent environment\", engines: [\"claude\"] },\n { name: \"rename\", desc: \"rename the current session\", engines: [\"claude\"], args: \"[name]\" },\n { name: \"rewind\", desc: \"rewind to a checkpoint\", engines: [\"claude\"] },\n { name: \"run\", desc: \"launch and inspect your app\", engines: [\"claude\"] },\n { name: \"run-skill-generator\", desc: \"teach /run and /verify how to run this app\", engines: [\"claude\"] },\n { name: \"sandbox\", desc: \"toggle Claude sandbox mode\", engines: [\"claude\"] },\n { name: \"schedule\", desc: \"create or manage routines\", engines: [\"claude\"], args: \"[description]\" },\n { name: \"security-review\", desc: \"review pending changes for security risks\", engines: [\"claude\"] },\n { name: \"setup-bedrock\", desc: \"configure Amazon Bedrock auth\", engines: [\"claude\"] },\n { name: \"setup-vertex\", desc: \"configure Google Vertex auth\", engines: [\"claude\"] },\n { name: \"simplify\", desc: \"review and simplify changed code\", engines: [\"claude\"], args: \"[target]\" },\n { name: \"statusline\", desc: \"configure status line fields\", engines: both },\n { name: \"stickers\", desc: \"order Claude Code stickers\", engines: [\"claude\"] },\n { name: \"stop\", desc: \"stop background work\", engines: both },\n { name: \"tasks\", desc: \"view background tasks\", engines: [\"claude\"] },\n { name: \"team-onboarding\", desc: \"generate a team onboarding guide\", engines: [\"claude\"] },\n { name: \"teleport\", desc: \"pull a web session into terminal\", engines: [\"claude\"] },\n { name: \"terminal-setup\", desc: \"configure terminal keybindings\", engines: [\"claude\"] },\n { name: \"theme\", desc: \"choose a theme\", engines: both },\n { name: \"tui\", desc: \"switch Claude terminal renderer\", engines: [\"claude\"], args: \"[default|fullscreen]\" },\n { name: \"ultraplan\", desc: \"draft an ultra plan\", engines: [\"claude\"], args: \"\" },\n { name: \"ultrareview\", desc: \"run a deep cloud review\", engines: [\"claude\"], args: \"[PR]\" },\n { name: \"upgrade\", desc: \"open Claude plan upgrade\", engines: [\"claude\"] },\n { name: \"usage-credits\", desc: \"configure Claude usage credits\", engines: [\"claude\"] },\n { name: \"verify\", desc: \"verify an app change by running it\", engines: [\"claude\"] },\n { name: \"voice\", desc: \"toggle Claude voice dictation\", engines: [\"claude\"], args: \"[hold|tap|off]\" },\n { name: \"web-setup\", desc: \"connect GitHub for Claude Code web\", engines: [\"claude\"] },\n { name: \"workflows\", desc: \"view workflow progress\", engines: [\"claude\"] },\n // Codex CLI and IDE extension commands.\n { name: \"auto-context\", desc: \"toggle IDE auto context\", engines: [\"codex\"] },\n { name: \"cloud\", desc: \"switch to Codex cloud mode\", engines: [\"codex\"] },\n { name: \"cloud-environment\", desc: \"choose Codex cloud environment\", engines: [\"codex\"] },\n { name: \"local\", desc: \"switch to local Codex mode\", engines: [\"codex\"] },\n { name: \"keymap\", desc: \"remap TUI shortcuts\", engines: [\"codex\"] },\n { name: \"vim\", desc: \"toggle Vim composer mode\", engines: [\"codex\"] },\n { name: \"sandbox-add-read-dir\", desc: \"grant sandbox read access to a directory\", engines: [\"codex\"], args: \"\" },\n { name: \"agent\", desc: \"switch active agent thread\", engines: [\"codex\"] },\n { name: \"apps\", desc: \"browse app connectors\", engines: [\"codex\"] },\n { name: \"plugins\", desc: \"browse installed and discoverable plugins\", engines: [\"codex\"] },\n { name: \"archive\", desc: \"archive the current Codex session\", engines: [\"codex\"] },\n { name: \"delete\", desc: \"delete the current Codex session\", engines: [\"codex\"] },\n { name: \"experimental\", desc: \"toggle experimental Codex features\", engines: [\"codex\"] },\n { name: \"approve\", desc: \"approve one retry of an auto-review denial\", engines: [\"codex\"] },\n { name: \"memories\", desc: \"configure Codex memories\", engines: [\"codex\"] },\n { name: \"import\", desc: \"import external agent configuration\", engines: [\"codex\"] },\n { name: \"mention\", desc: \"attach a file or folder to the conversation\", engines: [\"codex\"], args: \"\" },\n { name: \"personality\", desc: \"choose Codex response style\", engines: [\"codex\"] },\n { name: \"ps\", desc: \"show background terminals\", engines: [\"codex\"] },\n { name: \"side\", desc: \"start an ephemeral side conversation\", engines: [\"codex\"], args: \"\" },\n { name: \"raw\", desc: \"toggle raw scrollback mode\", engines: [\"codex\"] },\n { name: \"quit\", desc: \"exit the native CLI session\", engines: [\"codex\"] },\n { name: \"debug-config\", desc: \"inspect Codex config layers\", engines: [\"codex\"] },\n { name: \"title\", desc: \"configure terminal title fields\", engines: [\"codex\"] }\n ];\n\n // src/chat/modelOptions.ts\n var CHAT_MODEL_OPTIONS = {\n claude: [\n {\n value: \"opus\",\n chipLabel: \"Opus 5\",\n label: \"Opus 5\",\n description: \"Most capable · Claude alias: opus\"\n },\n {\n value: \"sonnet\",\n chipLabel: \"Sonnet 5\",\n label: \"Sonnet 5\",\n description: \"Balanced · Claude alias: sonnet\"\n },\n {\n value: \"haiku\",\n chipLabel: \"Haiku 4.5\",\n label: \"Haiku 4.5\",\n description: \"Fastest · Claude alias: haiku\"\n }\n ],\n codex: [\n {\n value: \"gpt-5.5-codex\",\n chipLabel: \"GPT-5.5 Codex\",\n label: \"GPT-5.5 Codex\",\n description: \"Coding-tuned · exact value: gpt-5.5-codex\"\n },\n {\n value: \"gpt-5.5\",\n chipLabel: \"GPT-5.5\",\n label: \"GPT-5.5\",\n description: \"General GPT model · exact value: gpt-5.5\"\n }\n ]\n };\n\n // src/chat/ui/avatar.ts\n var AVATAR_SVG = ``;\n var AVATAR_CLASSES = [\"clothes\", \"eyes\", \"line\", \"face_acc\"];\n var SKIN = \"cls-2\";\n function hashSeed(v) {\n let h = 2166136261;\n for (let i = 0; i < v.length; i++) {\n h ^= v.charCodeAt(i);\n h = Math.imul(h, 16777619);\n }\n return h >>> 0;\n }\n function rng(seed) {\n let s = hashSeed(seed || \"default\") || 439041101;\n return () => {\n s ^= s << 13;\n s ^= s >>> 17;\n s ^= s << 5;\n return (s >>> 0) / 4294967296;\n };\n }\n function avatarSvg(seed) {\n const r = rng(seed || \"default\");\n const pal = {};\n pal[SKIN] = r() > 0.5 ? \"#111111\" : \"#f6d9c8\";\n for (const c of AVATAR_CLASSES) {\n const hue = Math.floor(r() * 360), sat = 50 + Math.floor(r() * 35), lig = 35 + Math.floor(r() * 25);\n pal[c] = \"hsl(\" + hue + \",\" + sat + \"%,\" + lig + \"%)\";\n }\n pal[\"eyes\"] = pal[SKIN] === \"#111111\" ? \"hsl(\" + Math.floor(r() * 360) + \",80%,75%)\" : \"#222222\";\n let svg = AVATAR_SVG;\n const ds = svg.indexOf(\"\");\n if (de > ds) svg = svg.slice(0, ds) + svg.slice(de + 8);\n }\n for (const c of [...AVATAR_CLASSES, SKIN]) {\n const token = 'class=\"' + c + '\"', repl = 'fill=\"' + pal[c] + '\"';\n let i;\n while ((i = svg.indexOf(token)) >= 0) {\n svg = svg.slice(0, i) + repl + svg.slice(i + token.length);\n }\n }\n return svg;\n }\n\n // src/chat/ui/panel/format.ts\n function rel(ts) {\n const s = Math.max(0, (Date.now() - ts) / 1e3);\n if (s < 60) return \"방금\";\n const m = s / 60;\n if (m < 60) return Math.floor(m) + \"분\";\n const h = m / 60;\n if (h < 24) return Math.floor(h) + \"시간\";\n const d = h / 24;\n if (d < 30) return Math.floor(d) + \"일\";\n const mo = d / 30;\n if (mo < 12) return Math.floor(mo) + \"개월\";\n return Math.floor(mo / 12) + \"년\";\n }\n function looksOnChain(v) {\n const s = (v || \"\").trim();\n if (!s) return false;\n if (/^https?:/i.test(s)) return false;\n if (/\\.(png|jpe?g|gif|webp|svg)$/i.test(s)) return false;\n return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(s);\n }\n function fmtNoteDate(n) {\n const ms = n.__blockTime ? n.__blockTime * 1e3 : n.timestamp || 0;\n if (!ms) return \"\";\n try {\n return new Date(ms).toLocaleDateString(void 0, { month: \"short\", day: \"numeric\", year: \"numeric\" });\n } catch {\n return \"\";\n }\n }\n function explorerTxUrl(sig) {\n const u = \"https://explorer.solana.com/tx/\" + encodeURIComponent(sig);\n return S.rpcNetwork === \"mainnet\" ? u : u + \"?cluster=\" + encodeURIComponent(S.rpcNetwork);\n }\n function fdAgo(ms) {\n if (!ms) return \"\";\n const s = Math.max(1, Math.floor((Date.now() - ms) / 1e3));\n if (s < 60) return s + \"s\";\n const m = Math.floor(s / 60);\n if (m < 60) return m + \"m\";\n const h = Math.floor(m / 60);\n if (h < 24) return h + \"h\";\n const d = Math.floor(h / 24);\n if (d < 7) return d + \"d\";\n return Math.floor(d / 7) + \"w\";\n }\n function feedImgUrl(v) {\n return v && /^https?:\\/\\//i.test(v) ? v : null;\n }\n function agShort(w) {\n return w.slice(0, 6) + \"...\" + w.slice(-4);\n }\n function pad2(n) {\n return n < 10 ? \"0\" + n : String(n);\n }\n function splitSkillDoc(text) {\n text = text || \"\";\n const m = text.match(/^---\\r?\\n[\\s\\S]*?\\r?\\n---\\r?\\n?/);\n return (m ? text.slice(m[0].length) : text).trim();\n }\n function fmtSol(lamports) {\n if (lamports == null) return null;\n const sol = lamports / 1e9;\n const s = sol < 1 ? sol.toFixed(4) : sol.toFixed(3);\n return s.replace(/\\.?0+$/, \"\") + \" SOL\";\n }\n function fmtPrice(price) {\n if (price == null) return null;\n const n = Number(price);\n if (!Number.isFinite(n)) return null;\n return n === 0 ? \"Free\" : fmtSol(n);\n }\n function netBadge(network) {\n const n = network === \"mainnet\" ? \"mainnet\" : \"devnet\";\n return '' + n + \"\";\n }\n function short(a) {\n return a && a.length > 10 ? a.slice(0, 4) + \"..\" + a.slice(-3) : a;\n }\n\n // src/chat/ui/panel/skeleton.ts\n function skSd(n) {\n let s = \"\";\n for (let i = 0; i < n; i++) s += '
';\n return s;\n }\n function skAc(n) {\n let s = \"\";\n for (let i = 0; i < n; i++) s += '
';\n return s;\n }\n var skId = '
';\n function skFd(n) {\n let s = \"\";\n for (let i = 0; i < n; i++) s += '
';\n return s;\n }\n\n // src/chat/ui/panel/publish.ts\n var pubImage = document.getElementById(\"pubImage\");\n var pubImageBadge = document.getElementById(\"pubImageBadge\");\n var pubSubmit = document.getElementById(\"pubSubmit\");\n var pubError = document.getElementById(\"pubError\");\n var pubFormEl = document.getElementById(\"pubForm\");\n var pubTextWrap = document.getElementById(\"pubTextWrap\");\n var pubReqWrap = document.getElementById(\"pubReqWrap\");\n var pubReqEl = document.getElementById(\"pubReq\");\n var pubReqCountEl = document.getElementById(\"pubReqCount\");\n var pubReqSel = {};\n function chosenReqMints() {\n return Object.keys(pubReqSel).filter((m) => pubReqSel[m]);\n }\n function updatePubReqCount() {\n const c = chosenReqMints().length;\n pubReqCountEl.textContent = c ? c + \" selected\" + (c > 16 ? \": max 16, deselect some\" : \"\") : \"\";\n }\n function renderPubReq() {\n const owned = S.ownedSkills.filter((n) => !!S.skillMints[n] && !S.workflowMintSet.has(S.skillMints[n]));\n if (!owned.length) {\n pubReqEl.innerHTML = `
You don't own any skills yet. Buy at least one before publishing a workflow.
`;\n pubReqCountEl.textContent = \"\";\n return;\n }\n pubReqEl.innerHTML = \"\";\n for (const n of owned) {\n const mint = S.skillMints[n];\n const lab = document.createElement(\"label\");\n const cb = document.createElement(\"input\");\n cb.type = \"checkbox\";\n cb.value = mint;\n cb.checked = !!pubReqSel[mint];\n cb.addEventListener(\"change\", () => {\n pubReqSel[mint] = cb.checked;\n updatePubReqCount();\n });\n const span = document.createElement(\"span\");\n span.textContent = n;\n lab.appendChild(cb);\n lab.appendChild(span);\n pubReqEl.appendChild(lab);\n }\n updatePubReqCount();\n }\n function setPubKind(k) {\n S.pubKind = k === \"workflow\" ? \"workflow\" : \"skill\";\n S.pubBodyConfirmed = false;\n const wf = S.pubKind === \"workflow\";\n for (const b of document.querySelectorAll(\".pubKind button\")) b.classList.toggle(\"on\", b.getAttribute(\"data-k\") === S.pubKind);\n pubFormEl.classList.toggle(\"wf\", wf);\n pubTextWrap.style.display = wf ? \"none\" : \"\";\n pubReqWrap.style.display = wf ? \"\" : \"none\";\n document.getElementById(\"pubFormHead\").innerHTML = \"FORM // PUBLISH \" + (wf ? \"WORKFLOW\" : \"SKILL\") + \"\";\n document.getElementById(\"pubViewTitle\").textContent = wf ? \"Make a workflow\" : \"Make a skill\";\n document.getElementById(\"pubViewDesc\").textContent = wf ? \"Bundle skills you own into one workflow. Buyers must hold every skill it requires to unlock it.\" : \"Publish a skill others can buy. It mints a soulbound NFT and the body is stored on-chain.\";\n if (!pubSubmit.disabled) pubSubmit.textContent = wf ? \"Publish workflow\" : \"Publish skill\";\n if (wf) renderPubReq();\n }\n function openPublish(kind) {\n setPubKind(kind);\n showView(\"publish\");\n }\n function wirePublish() {\n for (const b of document.querySelectorAll(\".pubKind button\")) b.addEventListener(\"click\", () => setPubKind(b.getAttribute(\"data-k\")));\n pubImage.addEventListener(\"input\", () => {\n pubImageBadge.style.display = looksOnChain(pubImage.value) ? \"inline-block\" : \"none\";\n });\n document.getElementById(\"pubText\").addEventListener(\"input\", () => {\n S.pubBodyConfirmed = false;\n });\n pubSubmit.addEventListener(\"click\", () => {\n const name = document.getElementById(\"pubName\").value.trim();\n const description = document.getElementById(\"pubDesc\").value.trim();\n const priceSol = document.getElementById(\"pubPrice\").value.trim();\n const category = document.getElementById(\"pubCategory\").value.trim();\n const hashtags = document.getElementById(\"pubHashtags\").value.split(\",\").map((h) => h.trim()).filter(Boolean);\n const image = pubImage.value.trim();\n pubError.style.display = \"none\";\n const fail = (msg2) => {\n pubError.textContent = msg2;\n pubError.style.display = \"block\";\n };\n if (!name) return fail(\"Name is required.\");\n if (!description) return fail(\"Description is required.\");\n let text;\n let reqMints = [];\n if (S.pubKind === \"workflow\") {\n reqMints = chosenReqMints().filter((m) => !S.workflowMintSet.has(m));\n if (!reqMints.length) return fail(\"Pick at least one skill this workflow requires.\");\n if (reqMints.length > 16) return fail(\"A workflow can require at most 16 skills.\");\n const fm = [\n \"---\",\n \"name: \" + name,\n \"description: \" + description.replace(/\\s*\\n\\s*/g, \" \"),\n \"type: workflow\",\n \"requiredSkills: [\" + reqMints.join(\", \") + \"]\"\n ];\n if (category) fm.push(\"category: \" + category);\n if (hashtags.length) fm.push(\"hashtags: [\" + hashtags.join(\", \") + \"]\");\n text = fm.concat([\"---\", \"\", \"# \" + name, \"\", description, \"\"]).join(\"\\n\");\n } else {\n text = document.getElementById(\"pubText\").value.trim();\n if (!text) return fail(\"Skill text is required.\");\n const body = text.replace(/^---[\\s\\S]*?\\n---\\s*/, \"\").trim();\n if (body.length < 20 && !S.pubBodyConfirmed) {\n S.pubBodyConfirmed = true;\n return fail(\"This publishes PERMANENTLY and cannot be deleted; the body looks empty or very short. Click Publish again to submit anyway.\");\n }\n }\n if (!priceSol) return fail(\"Enter a price in SOL (use 0 for free).\");\n if (!/^\\d+(\\.\\d+)?$/.test(priceSol)) return fail(\"Price must be a number in SOL (e.g. 0.1).\");\n pubSubmit.disabled = true;\n pubSubmit.textContent = \"Publishing…\";\n const msg = {\n type: \"publishSkill\",\n name,\n description,\n text,\n priceSol,\n category: category || void 0,\n hashtags: hashtags.length ? hashtags : void 0,\n image: image || void 0\n };\n if (S.pubKind === \"workflow\") {\n msg.kind = \"workflow\";\n msg.requiredSkills = reqMints;\n }\n vscode.postMessage(msg);\n });\n }\n\n // src/chat/ui/icons.ts\n var WAND_SVG = '';\n var LAYERS_SVG = '';\n\n // src/chat/ui/iqlogo.ts\n var IQ_LOGO_SVG = ' ';\n\n // src/links/github.ts\n var SAFE_EXTERNAL_PROTOCOLS = /* @__PURE__ */ new Set([\"https:\", \"http:\", \"git:\"]);\n function safeExternalUrl(raw) {\n if (!raw) return null;\n try {\n const url = new URL(raw);\n if (!SAFE_EXTERNAL_PROTOCOLS.has(url.protocol)) return null;\n return url.href;\n } catch {\n return null;\n }\n }\n function parseGithubLink(raw) {\n const href = safeExternalUrl(raw);\n if (!href) return null;\n let url;\n try {\n url = new URL(href);\n } catch {\n return null;\n }\n const host = url.hostname.toLowerCase();\n if (host !== \"github.com\" && host !== \"www.github.com\") return null;\n const parts = url.pathname.split(\"/\").filter(Boolean);\n if (parts.length < 2) return null;\n const [owner, repo, section, value, ...rest] = parts;\n const repoName = repo.replace(/\\.git$/i, \"\");\n const repoFullName = `${owner}/${repoName}`;\n if (!section) {\n return {\n kind: \"repo\",\n href,\n owner,\n repo: repoName,\n label: repoFullName,\n meta: \"GitHub repository\"\n };\n }\n if (section === \"pull\" && value && /^\\d+$/.test(value)) {\n return {\n kind: \"pull\",\n href,\n owner,\n repo: repoName,\n number: value,\n label: `${repoFullName} #${value}`,\n meta: \"GitHub pull request\"\n };\n }\n if (section === \"commit\" && value && /^[0-9a-f]{7,40}$/i.test(value)) {\n return {\n kind: \"commit\",\n href,\n owner,\n repo: repoName,\n sha: value,\n label: `${repoFullName}@${value.slice(0, 7)}`,\n meta: \"GitHub commit\"\n };\n }\n if (section === \"blob\" && value && rest.length > 0) {\n const path = rest.join(\"/\");\n return {\n kind: \"blob\",\n href,\n owner,\n repo: repoName,\n path,\n label: path,\n meta: repoFullName\n };\n }\n return null;\n }\n\n // src/chat/ui/panel/tiers.ts\n var AG_SEG = 12;\n var AG_TIERS = [\n { name: \"Legendary\", min: 250 },\n { name: \"Gold\", min: 60 },\n { name: \"Silver\", min: 15 },\n { name: \"Bronze\", min: 3 }\n ];\n function agStarTier(stars) {\n return AG_TIERS.find((t) => stars >= t.min) || null;\n }\n function agNextTierMin(stars) {\n const asc = AG_TIERS.slice().sort((a, b) => a.min - b.min);\n const up = asc.find((t) => t.min > stars);\n return up ? up.min : asc[asc.length - 1].min;\n }\n function agAccent(wallet) {\n return \"hsl(\" + hashSeed(wallet || \"default\") % 360 + \" 46% 62%)\";\n }\n var PROF_TIERS = [{ name: \"Bronze\", min: 3 }, { name: \"Silver\", min: 15 }, { name: \"Gold\", min: 60 }, { name: \"Legendary\", min: 250 }];\n var TIER_COLOR = { Bronze: \"var(--an-tier-bronze)\", Silver: \"var(--an-tier-silver)\", Gold: \"var(--an-tier-gold)\", Legendary: \"var(--an-tier-legendary)\" };\n var PROF_SEG = 15;\n function profTierInfo(stars) {\n let cur = null, next = null;\n for (const t of PROF_TIERS) {\n if (stars >= t.min) cur = t;\n else {\n next = t;\n break;\n }\n }\n return { cur, next };\n }\n var PROF_REPO_TIERS = [\n { min: 250, color: \"#86c4cf\", from: \"#131a1b\", to: \"#0d1011\", empty: \"#1e2628\" },\n { min: 50, color: \"#d8c074\", from: \"#1a1813\", to: \"#100f0d\", empty: \"#2a2618\" },\n { min: 10, color: \"#b8c0cc\", from: \"#161719\", to: \"#0e0f10\", empty: \"#26282c\" },\n { min: 3, color: \"#b8895a\", from: \"#1a1613\", to: \"#100f0e\", empty: \"#2a2420\" }\n ];\n var PROF_REPO_BASE = { color: \"#9a9a9a\", from: \"#1a1a1d\", to: \"#0d0d0e\", empty: \"#33333a\" };\n function profRepoTier(stars) {\n return PROF_REPO_TIERS.find((t) => stars >= t.min) || PROF_REPO_BASE;\n }\n function profRepoFill(stars) {\n const next = [3, 10, 50, 250].find((t) => stars < t);\n if (!next) return 10;\n return Math.max(0, Math.min(10, Math.round(stars / next * 10)));\n }\n\n // src/chat/ui/panel/agents.ts\n function agentCardEl(agent, self) {\n const stars = agent.stars || 0;\n const tier = agStarTier(stars);\n const isMax = tier && tier.name === \"Legendary\";\n const denom = agNextTierMin(stars);\n const filled = Math.max(0, Math.min(AG_SEG, Math.round(stars / denom * AG_SEG)));\n const tierName = (tier ? tier.name : \"Unranked\").toUpperCase();\n const created = agent.skillsPublished || 0;\n const copies = agent.totalSupply || 0;\n const earnedSol = agent.totalEarned ? Number(agent.totalEarned) / 1e9 : 0;\n const earned = earnedSol >= 100 ? earnedSol.toFixed(0) : earnedSol.toFixed(2);\n const sig = 34 + agent.wallet.charCodeAt(2) % 6 * 11;\n let segs = \"\";\n for (let i = 0; i < AG_SEG; i++) segs += '';\n const btn = document.createElement(\"button\");\n btn.className = \"an-ac\" + (self ? \" is-self\" : \"\");\n btn.style.setProperty(\"--accent\", agAccent(agent.wallet));\n btn.innerHTML = '
>' + agShort(agent.wallet).toUpperCase() + \"_AGENT\" + (self ? ' // YOU' : \"\") + 'SIGNAL
エージェント
' + agent.wallet.slice(0, 6).toUpperCase() + '
アクセス / ACCESS
' + tierName + '
' + avatarSvg(agent.wallet) + '
— RANKING —
STARS' + segs + '' + (isMax ? stars : stars + \"/\" + denom) + '
CREATED
' + created + '
COPIES
' + copies + '
>EARNED ' + earned + '◎
';\n btn.addEventListener(\"click\", () => showProfile(agent.wallet));\n return btn;\n }\n function renderAgents(agents) {\n S.lastAgents = agents || [];\n const selfEl = document.getElementById(\"agentsSelf\");\n if (selfEl) {\n selfEl.innerHTML = \"\";\n if (S.myWalletAddress) {\n const selfRep = S.lastAgents.find((a) => a.wallet === S.myWalletAddress) || { wallet: S.myWalletAddress, skillsPublished: 0, totalSupply: 0, notesReceived: 0, updatedAt: 0 };\n selfEl.appendChild(agentCardEl(selfRep, true));\n }\n }\n const search = document.getElementById(\"agentSearch\");\n if (search && !search._wired) {\n search._wired = true;\n search.addEventListener(\"input\", renderAgentsList);\n }\n renderAgentsList();\n }\n function renderAgentsList() {\n const el = document.getElementById(\"agentsList\");\n if (!el) return;\n const searchEl = document.getElementById(\"agentSearch\");\n const ql = (searchEl && searchEl.value ? searchEl.value : \"\").trim().toLowerCase();\n let others = S.lastAgents.filter((a) => a.wallet !== S.myWalletAddress);\n if (ql) others = others.filter((a) => a.wallet.toLowerCase().includes(ql));\n el.innerHTML = \"\";\n if (!others.length) {\n const e = document.createElement(\"div\");\n e.className = \"agEmpty\";\n e.textContent = ql ? \"No agent matches that wallet\" : \"No other agents yet\";\n el.appendChild(e);\n return;\n }\n others.forEach((a) => el.appendChild(agentCardEl(a, false)));\n }\n function mergeOptimistic(profile) {\n const now = Date.now();\n S.recentlyPosted = S.recentlyPosted.filter((p) => now - p.ts < 6e4);\n const real = new Set((profile.threads || []).flatMap((t) => [t.note, ...t.replies || []]).map((n) => (n.author || \"\") + \"\\0\" + (n.text || \"\")));\n S.recentlyPosted = S.recentlyPosted.filter((p) => !(p.wallet === profile.wallet && real.has((p.note.author || \"\") + \"\\0\" + (p.note.text || \"\"))));\n const pending = S.recentlyPosted.filter((p) => p.wallet === profile.wallet && !p.note.parentId).map((p) => p.note);\n return pending.length ? { ...profile, threads: [...pending.map((note) => ({ note, replies: [] })), ...profile.threads || []] } : profile;\n }\n function feedbackFor(wallet) {\n if (!S.postFeedback) return null;\n if (S.postFeedback.wallet !== wallet) return null;\n if (Date.now() - S.postFeedback.ts > 8e3) {\n S.postFeedback = null;\n return null;\n }\n return S.postFeedback;\n }\n function enableDragScroll(el) {\n let startX = 0, startLeft = 0, dragging = false, moved = false;\n el.addEventListener(\"pointerdown\", (e) => {\n if (e.pointerType !== \"mouse\" || e.button !== 0) return;\n dragging = true;\n moved = false;\n startX = e.clientX;\n startLeft = el.scrollLeft;\n try {\n el.setPointerCapture(e.pointerId);\n } catch {\n }\n el.classList.add(\"dragging\");\n });\n el.addEventListener(\"pointermove\", (e) => {\n if (!dragging) return;\n const dx = e.clientX - startX;\n if (Math.abs(dx) > 3) moved = true;\n el.scrollLeft = startLeft - dx;\n });\n const end = (e) => {\n if (!dragging) return;\n dragging = false;\n el.classList.remove(\"dragging\");\n try {\n el.releasePointerCapture(e.pointerId);\n } catch {\n }\n };\n el.addEventListener(\"pointerup\", end);\n el.addEventListener(\"pointercancel\", end);\n el.addEventListener(\"click\", (e) => {\n if (moved) {\n e.preventDefault();\n e.stopPropagation();\n moved = false;\n }\n }, true);\n }\n var GH_KIND_LABEL = { repo: \"Repo\", pull: \"PR\", commit: \"Commit\", blob: \"File\" };\n function gitLinkNode(raw, className) {\n const gh = parseGithubLink(raw);\n const wrap = document.createElement(\"div\");\n wrap.className = className;\n if (gh) {\n const a2 = document.createElement(\"a\");\n a2.className = \"gh-card\";\n a2.href = gh.href;\n a2.target = \"_blank\";\n a2.rel = \"noopener noreferrer\";\n const kind = document.createElement(\"span\");\n kind.className = \"gh-kind\";\n kind.textContent = GH_KIND_LABEL[gh.kind];\n const title = document.createElement(\"span\");\n title.className = \"gh-title\";\n title.textContent = gh.label;\n const meta = document.createElement(\"span\");\n meta.className = \"gh-meta\";\n meta.textContent = gh.meta;\n a2.appendChild(kind);\n a2.appendChild(title);\n a2.appendChild(meta);\n wrap.appendChild(a2);\n return wrap;\n }\n const safeLink = safeExternalUrl(raw);\n if (!safeLink) return null;\n const a = document.createElement(\"a\");\n a.href = safeLink;\n a.textContent = safeLink;\n a.target = \"_blank\";\n a.rel = \"noopener noreferrer\";\n wrap.appendChild(a);\n return wrap;\n }\n\n // src/chat/ui/skillSigil.ts\n function hash(s) {\n let h = 2166136261;\n for (let i = 0; i < s.length; i++) {\n h ^= s.charCodeAt(i);\n h = Math.imul(h, 16777619);\n }\n return h >>> 0;\n }\n function rng2(s) {\n let a = hash(s);\n return function() {\n a |= 0;\n a = a + 1831565813 | 0;\n let t = Math.imul(a ^ a >>> 15, 1 | a);\n t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;\n return ((t ^ t >>> 14) >>> 0) / 4294967296;\n };\n }\n function skillSigilSvg(name) {\n const col = \"hsl(228 5% 82%)\";\n const r = rng2((name || \"\") + \"::sigil\");\n const cx = 60, cy = 74;\n let s = \"\";\n const rings = 2 + Math.floor(r() * 2);\n for (let i = 0; i < rings; i++) {\n const rad = 22 + i * 9 + r() * 4;\n s += '';\n }\n const ticks = 12 + Math.floor(r() * 24);\n const t1 = 29 + r() * 3;\n const t2 = t1 + 6 + r() * 4;\n for (let i = 0; i < ticks; i++) {\n const a = i / ticks * Math.PI * 2;\n const x1 = cx + Math.cos(a) * t1, y1 = cy + Math.sin(a) * t1, x2 = cx + Math.cos(a) * t2, y2 = cy + Math.sin(a) * t2;\n s += '';\n }\n const sides = 3 + Math.floor(r() * 5);\n const rot = r() * Math.PI * 2;\n const pr = 12 + r() * 5;\n const pts = [];\n for (let i = 0; i < sides; i++) {\n const a = rot + i / sides * Math.PI * 2;\n pts.push([cx + Math.cos(a) * pr, cy + Math.sin(a) * pr]);\n }\n const poly = pts.map(function(p) {\n return p[0].toFixed(1) + \",\" + p[1].toFixed(1);\n }).join(\" \");\n s += '';\n if (sides >= 5) {\n const star = [];\n for (let i = 0; i < sides; i++) star.push(pts[i * 2 % sides]);\n const sp = star.map(function(p) {\n return p[0].toFixed(1) + \",\" + p[1].toFixed(1);\n }).join(\" \");\n s += '';\n }\n for (let k = 0; k < pts.length; k++) {\n const p = pts[k];\n s += '';\n }\n s += '';\n const runes = 6 + Math.floor(r() * 8);\n for (let i = 0; i < runes; i++) {\n const a = r() * Math.PI * 2;\n const rr = 5 + r() * 28;\n const x = cx + Math.cos(a) * rr, y = cy + Math.sin(a) * rr;\n const len = 2 + r() * 4;\n s += '';\n }\n return s;\n }\n\n // src/chat/ui/panel/skills.ts\n var skillsBtn = document.getElementById(\"skillsBtn\");\n var skillsPanel = document.getElementById(\"skillsPanel\");\n function closeSkillsPanel() {\n skillsPanel.style.display = \"none\";\n skillsBtn.classList.remove(\"on\");\n }\n var skillsCloseBtn = document.getElementById(\"skillsClose\");\n var walletSkillsItem = document.getElementById(\"walletSkills\");\n var walletSkillList = document.getElementById(\"walletSkillList\");\n function renderWalletSkillList() {\n if (!walletSkillList) return;\n walletSkillList.innerHTML = \"\";\n if (!S.ownedSkills.length) {\n const e = document.createElement(\"div\");\n e.className = \"wskEmpty\";\n e.textContent = \"No skills yet. Buy them in Markets.\";\n walletSkillList.appendChild(e);\n return;\n }\n for (const name of S.ownedSkills) {\n const row = document.createElement(\"div\");\n row.className = \"wskRow\";\n row.innerHTML = '' + WAND_SVG + \"\";\n const lbl = document.createElement(\"span\");\n lbl.textContent = name;\n lbl.title = name;\n row.appendChild(lbl);\n row.style.cursor = \"pointer\";\n row.addEventListener(\"click\", () => {\n const mt = S.skillMints[name];\n if (mt) {\n showView(\"market\");\n openDetail(mt);\n } else openSkillDoc(name);\n });\n walletSkillList.appendChild(row);\n }\n }\n function skillSdCard(card, opts) {\n opts = opts || {};\n const isWorkflow = card.type === \"workflow\";\n const priceSol = card.price && card.price !== \"0\" && card.price !== 0 ? (Number(card.price) / 1e9).toFixed(2) : null;\n const cat = String(card.category || (isWorkflow ? \"workflow\" : \"skill\")).toUpperCase().slice(0, 8);\n const state = opts.disposed ? \"OFF\" : opts.owned ? \"OWNED\" : \"GET\";\n const nm = card.name || card.id || \"\";\n const el = document.createElement(\"button\");\n el.className = \"an-sd\" + (isWorkflow ? \" is-workflow\" : \"\") + (opts.disposed ? \" is-disposed\" : \"\") + (opts.dim ? \" is-owned-dim\" : \"\") + (opts.firing ? \" is-firing\" : \"\");\n el.title = nm;\n el.setAttribute(\"data-skill\", card.name || \"\");\n if (card.id) el.setAttribute(\"data-mint\", card.id);\n var imgUrl = card.image && /^https?:\\/\\//.test(String(card.image)) ? String(card.image) : null;\n if (imgUrl) el.className += \" has-img\";\n el.innerHTML = '
' + (imgUrl ? '\"\"' : '' + skillSigilSvg(nm) + '
') + '
';\n if (imgUrl) el.querySelector(\".an-sd-img\").src = imgUrl;\n var catEl = el.querySelector(\".an-sd-mark .cat\");\n if (catEl) catEl.textContent = cat;\n el.querySelector(\".an-sd-name\").textContent = nm;\n const big = el.querySelector(\".an-sd-big\");\n if (card.supply != null) big.textContent = String(card.supply);\n else big.classList.add(\"bar\");\n const meta = el.querySelector(\".an-sd-meta\");\n meta.textContent = priceSol ? priceSol + \"◎\" : \"FREE\";\n meta.appendChild(document.createElement(\"br\"));\n meta.appendChild(document.createTextNode(state));\n const stars = Number(card.stars) || 0;\n if (stars > 0) {\n const grade = document.createElement(\"div\");\n grade.className = \"an-sd-grade\";\n const st = document.createElement(\"span\");\n st.className = \"st\";\n st.textContent = \"★\";\n grade.appendChild(st);\n grade.appendChild(document.createTextNode(String(stars)));\n el.querySelector(\".an-sd-label\").appendChild(grade);\n }\n if (opts.onOpen) el.addEventListener(\"click\", () => opts.onOpen(card));\n return el;\n }\n function setSkills(names, mints, meta) {\n names = names || [];\n const sm = meta || {};\n if (mints) S.skillMints = Object.assign({}, mints, S.disposedMints);\n const grid = document.getElementById(\"skillGrid\");\n const status = document.getElementById(\"skillStatus\");\n const n = names.length;\n const disposedSlugs = Object.keys(S.disposedMints);\n const shown = names.filter((nm) => !!S.skillMints[nm]);\n status.textContent = String(shown.length + disposedSlugs.length);\n grid.innerHTML = \"\";\n for (const name of shown) {\n const open = () => {\n const mt = S.skillMints[name];\n if (mt) {\n showView(\"market\");\n openDetail(mt);\n } else openSkillDoc(name);\n };\n const info = sm[name] || {};\n grid.appendChild(skillSdCard(\n { id: S.skillMints[name], name, category: info.category, type: info.type, stars: info.stars },\n { owned: true, onOpen: open }\n ));\n }\n for (const name of disposedSlugs) {\n const info = sm[name] || {};\n const c = skillSdCard(\n { id: S.disposedMints[name], name, category: info.category, type: info.type, stars: info.stars },\n {\n owned: true,\n disposed: true,\n onOpen: () => {\n showView(\"market\");\n openDetail(S.disposedMints[name]);\n }\n }\n );\n c.title = name + \" - un-pinned (click to re-equip)\";\n grid.appendChild(c);\n }\n const fill = Math.max(0, 3 - shown.length - disposedSlugs.length);\n for (let i = 0; i < fill; i++) {\n const s = document.createElement(\"div\");\n s.className = \"skSlot empty\";\n grid.appendChild(s);\n }\n S.ownedSkills = names;\n const wc = document.getElementById(\"walletSkillCount\");\n if (wc) {\n wc.textContent = n ? String(n) : \"\";\n wc.style.display = n ? \"\" : \"none\";\n }\n const wsl = document.getElementById(\"walletSkillList\");\n if (wsl && wsl.style.display !== \"none\") renderWalletSkillList();\n if (pubReqWrap && pubReqWrap.style.display !== \"none\") renderPubReq();\n }\n function wireSkills() {\n skillsBtn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n const open = skillsPanel.style.display !== \"none\";\n skillsPanel.style.display = open ? \"none\" : \"block\";\n skillsBtn.classList.toggle(\"on\", !open);\n });\n if (skillsCloseBtn) skillsCloseBtn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n closeSkillsPanel();\n });\n if (walletSkillsItem && walletSkillList) walletSkillsItem.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n const open = walletSkillList.style.display !== \"none\";\n if (open) {\n walletSkillList.style.display = \"none\";\n walletSkillsItem.classList.remove(\"open\");\n return;\n }\n renderWalletSkillList();\n walletSkillList.style.display = \"flex\";\n walletSkillsItem.classList.add(\"open\");\n });\n setSkills([]);\n vscode.postMessage({ type: \"ownedSkills\" });\n }\n\n // src/chat/ui/panel/market.ts\n var shopToggle = document.getElementById(\"shopToggle\");\n function setShopToggle(on) {\n shopToggle.classList.toggle(\"on\", !!on);\n shopToggle.setAttribute(\"aria-checked\", on ? \"true\" : \"false\");\n }\n var mktSearch = document.getElementById(\"mktSearch\");\n var mktResults = document.getElementById(\"mktResults\");\n var mktListEl = document.getElementById(\"mktList\");\n var mktDetailEl = document.getElementById(\"mktDetail\");\n var mktDetailBody = document.getElementById(\"mktDetailBody\");\n var mktHideOwnedCb = document.getElementById(\"mktHideOwned\");\n var mktSortBtn = document.getElementById(\"mktSortBtn\");\n function paintSortBtn() {\n if (!mktSortBtn) return;\n mktSortBtn.textContent = S.mktSort === \"stars\" ? \"★ Stars\" : \"Popular\";\n mktSortBtn.classList.toggle(\"stars\", S.mktSort === \"stars\");\n }\n function runMarketSearch() {\n mktResults.innerHTML = skSd(8);\n vscode.postMessage({ type: \"searchSkills\", query: mktSearch.value.trim(), kind: S.currentKind, sort: S.mktSort });\n }\n function openMarket() {\n showMktList();\n mktResults.innerHTML = skSd(8);\n vscode.postMessage({ type: \"searchSkills\", query: \"\", kind: S.currentKind, sort: S.mktSort });\n vscode.postMessage({ type: \"ownedSkills\" });\n vscode.postMessage({ type: \"getBalance\" });\n }\n function showMktList() {\n mktListEl.style.display = \"block\";\n mktDetailEl.style.display = \"none\";\n }\n function showMktDetail() {\n mktListEl.style.display = \"none\";\n mktDetailEl.style.display = \"block\";\n }\n function openDetail(mint) {\n showMktDetail();\n mktDetailBody.innerHTML = '
Loading…
';\n vscode.postMessage({ type: \"getSkillDetail\", mint });\n }\n var skillModalEl = document.getElementById(\"skillModal\");\n var skillModalBody = document.getElementById(\"skillModalBody\");\n function openSkillModal(mint) {\n S.skillModalOpen = true;\n S.skillModalBuyBtn = null;\n S.skillModalName = null;\n S.skillModalMint = null;\n skillModalBody.innerHTML = '
Loading…
';\n skillModalEl.style.display = \"flex\";\n vscode.postMessage({ type: \"getSkillDetail\", mint });\n vscode.postMessage({ type: \"ownedSkills\" });\n }\n function closeSkillModal() {\n S.skillModalOpen = false;\n S.skillDocOpen = false;\n S.skillModalBuyBtn = null;\n S.skillModalName = null;\n S.skillModalMint = null;\n skillModalEl.style.display = \"none\";\n }\n function refreshModalOwned() {\n if (S.skillModalBuyBtn && (ownsMint(S.skillModalMint) || S.skillModalName && S.ownedSkills.indexOf(S.skillModalName) >= 0)) {\n S.skillModalBuyBtn.disabled = true;\n S.skillModalBuyBtn.textContent = \"Owned\";\n }\n }\n function renderSkillModal(detail) {\n const c = detail && detail.card || {};\n const owned = ownsMint(c.id) || S.ownedSkills.indexOf(c.name) >= 0;\n S.skillModalName = c.name || null;\n S.skillModalMint = c.id || null;\n skillModalBody.innerHTML = \"\";\n const head = document.createElement(\"div\");\n head.className = \"dt-head\";\n const img = document.createElement(\"div\");\n img.className = \"dt-img\";\n img.innerHTML = '' + IQ_LOGO_SVG + \"\";\n const htxt = document.createElement(\"div\");\n const kind = document.createElement(\"div\");\n kind.className = \"dt-kind\";\n kind.textContent = c.type || \"skill\";\n const nm = document.createElement(\"div\");\n nm.className = \"dt-name\";\n nm.textContent = c.name || c.id || \"\";\n htxt.appendChild(kind);\n htxt.appendChild(nm);\n head.appendChild(img);\n head.appendChild(htxt);\n skillModalBody.appendChild(head);\n if (c.description) {\n const d = document.createElement(\"div\");\n d.className = \"dt-desc\";\n d.textContent = c.description;\n skillModalBody.appendChild(d);\n }\n const meta = document.createElement(\"div\");\n meta.className = \"dt-meta\";\n const addTag = (t) => {\n const s = document.createElement(\"span\");\n s.className = \"dt-tag\";\n s.textContent = t;\n meta.appendChild(s);\n };\n if (c.category) addTag(c.category);\n for (const h of c.hashtags || []) addTag(\"#\" + h);\n if (typeof c.supply === \"number\") addTag(c.supply + \"× owned\");\n const price = fmtPrice(c.price);\n if (price) addTag(price);\n if (meta.childElementCount) skillModalBody.appendChild(meta);\n if (!owned || c.type) {\n const buy = document.createElement(\"button\");\n buy.className = \"dt-buy\";\n const buyLabel = price && price !== \"Free\" ? \"Buy · \" + price : \"Buy\";\n buy.textContent = owned ? \"Owned\" : buyLabel;\n buy.disabled = owned;\n buy.addEventListener(\"click\", () => {\n buy.disabled = true;\n buy.textContent = \"Buying…\";\n vscode.postMessage({ type: \"buySkill\", skillId: c.id, creatorWallet: c.creator });\n });\n skillModalBody.appendChild(buy);\n S.skillModalBuyBtn = buy;\n }\n if (detail && detail.skillText) {\n const sec = document.createElement(\"div\");\n sec.className = \"dt-sec\";\n sec.textContent = (c.type === \"workflow\" ? \"Workflow\" : \"Skill\") + \" text\";\n const bd = document.createElement(\"div\");\n bd.className = \"dt-body\";\n bd.textContent = detail.skillText;\n skillModalBody.appendChild(sec);\n skillModalBody.appendChild(bd);\n }\n }\n function openSkillDoc(name) {\n S.skillModalOpen = false;\n S.skillDocOpen = true;\n S.skillModalName = null;\n S.skillModalBuyBtn = null;\n skillModalBody.innerHTML = '
Loading…
';\n skillModalEl.style.display = \"flex\";\n vscode.postMessage({ type: \"getSkillDoc\", name });\n }\n function renderSkillDoc(name, text) {\n skillModalBody.innerHTML = \"\";\n const nm = document.createElement(\"div\");\n nm.className = \"skDoc-name\";\n nm.textContent = name;\n skillModalBody.appendChild(nm);\n const body = splitSkillDoc(text);\n if (!body) {\n const e = document.createElement(\"div\");\n e.className = \"skDoc-empty\";\n e.textContent = \"No SKILL.md document found for this skill.\";\n skillModalBody.appendChild(e);\n return;\n }\n const bd = document.createElement(\"div\");\n bd.className = \"skDoc-body\";\n renderMd(bd, body);\n skillModalBody.appendChild(bd);\n }\n function renderComments(skillId, skillType, notes, owned) {\n const existing = mktDetailBody.querySelector(\".dt-comments\");\n if (existing) existing.remove();\n const wrap = document.createElement(\"div\");\n wrap.className = \"dt-comments\";\n const sec = document.createElement(\"div\");\n sec.className = \"dt-sec\";\n sec.textContent = \"Comments (\" + (notes ? notes.length : 0) + \")\";\n wrap.appendChild(sec);\n for (const n of notes || []) {\n const el = document.createElement(\"div\");\n el.className = \"dt-comment\";\n const auth = document.createElement(\"div\");\n auth.className = \"cm-author\";\n if (n.author) {\n const av = document.createElement(\"span\");\n av.className = \"cm-avatar\";\n av.innerHTML = avatarSvg(n.author);\n const addr = document.createElement(\"span\");\n addr.className = \"cm-addr\";\n addr.textContent = n.author.slice(0, 6) + \"…\" + n.author.slice(-4);\n auth.appendChild(av);\n auth.appendChild(addr);\n auth.classList.add(\"cm-link\");\n auth.title = \"View \" + n.author + \"'s profile\";\n auth.addEventListener(\"click\", () => showProfile(n.author));\n } else {\n auth.textContent = \"?\";\n }\n const body = document.createElement(\"div\");\n renderMd(body, n.text || \"\");\n el.appendChild(auth);\n el.appendChild(body);\n if (n.gitLink) {\n const gl = gitLinkNode(n.gitLink, \"cm-git\");\n if (gl) el.appendChild(gl);\n }\n wrap.appendChild(el);\n }\n const inputWrap2 = document.createElement(\"div\");\n inputWrap2.className = \"dt-note-input\";\n if (owned) {\n const fh = document.createElement(\"div\");\n fh.className = \"an-formhead\";\n fh.innerHTML = \"FORM // WRITE A COMMENT\";\n inputWrap2.appendChild(fh);\n const ta = document.createElement(\"textarea\");\n ta.placeholder = \"Write a comment…\";\n const errEl = document.createElement(\"div\");\n errEl.className = \"dt-note-error\";\n errEl.style.display = \"none\";\n const submit = document.createElement(\"button\");\n submit.className = \"dt-note-submit\";\n submit.textContent = \"Post\";\n submit.addEventListener(\"click\", () => {\n const text = ta.value.trim();\n if (!text) return;\n submit.disabled = true;\n submit.textContent = \"Posting…\";\n errEl.style.display = \"none\";\n vscode.postMessage({ type: \"postNote\", skillId, skillType, text });\n ta.value = \"\";\n submit._pending = true;\n });\n submit._reset = () => {\n submit.disabled = false;\n submit.textContent = \"Post\";\n };\n submit._fail = (msg) => {\n errEl.textContent = msg;\n errEl.style.display = \"block\";\n submit.disabled = false;\n submit.textContent = \"Post\";\n };\n inputWrap2.appendChild(ta);\n inputWrap2.appendChild(errEl);\n inputWrap2.appendChild(submit);\n } else {\n const gate = document.createElement(\"div\");\n gate.className = \"dt-note-gate\";\n gate.textContent = \"Buy this skill to leave a comment.\";\n inputWrap2.appendChild(gate);\n }\n wrap.appendChild(inputWrap2);\n mktDetailBody.appendChild(wrap);\n }\n function refreshDetailOwned() {\n if (mktDetailEl.style.display === \"none\" || !S.detailBuyBtn || !S.currentDetailName) return;\n if (S.ownedSkills.indexOf(S.currentDetailName) >= 0) {\n S.detailBuyBtn.textContent = \"Owned\";\n S.detailBuyBtn.disabled = true;\n }\n }\n function renderDetail(detail) {\n const c = detail && detail.card || {};\n const owned = ownsMint(c.id) || S.ownedSkills.indexOf(c.name) >= 0;\n S.currentDetail = { id: c.id, type: c.type };\n mktDetailBody.innerHTML = \"\";\n const isWf = c.type === \"workflow\";\n const head = document.createElement(\"div\");\n head.className = \"dt-head\";\n const img = document.createElement(\"div\");\n img.className = isWf ? \"dt-img workflow\" : \"dt-img\";\n img.innerHTML = '' + (isWf ? LAYERS_SVG : IQ_LOGO_SVG) + \"\";\n const htxt = document.createElement(\"div\");\n const kind = document.createElement(\"div\");\n kind.className = isWf ? \"dt-kind workflow\" : \"dt-kind\";\n kind.textContent = c.type || \"skill\";\n const nm = document.createElement(\"div\");\n nm.className = \"dt-name\";\n nm.textContent = c.name || c.id || \"\";\n htxt.appendChild(kind);\n htxt.appendChild(nm);\n head.appendChild(img);\n head.appendChild(htxt);\n mktDetailBody.appendChild(head);\n if (c.description) {\n const d = document.createElement(\"div\");\n d.className = \"dt-desc\";\n d.textContent = c.description;\n mktDetailBody.appendChild(d);\n }\n const meta = document.createElement(\"div\");\n meta.className = \"dt-meta\";\n const addTag = (t) => {\n const s = document.createElement(\"span\");\n s.className = \"dt-tag\";\n s.textContent = t;\n meta.appendChild(s);\n };\n if (c.category) addTag(c.category);\n for (const h of c.hashtags || []) addTag(\"#\" + h);\n if (typeof c.supply === \"number\") addTag(c.supply + \"× owned\");\n if (typeof c.stars === \"number\" && c.stars > 0) addTag(\"★ \" + c.stars);\n const detailPrice = fmtPrice(c.price);\n if (detailPrice) addTag(detailPrice);\n if (meta.childElementCount) mktDetailBody.appendChild(meta);\n const buy = document.createElement(\"button\");\n buy.className = \"dt-buy\";\n if (isDisposed(c.id)) {\n buy.textContent = \"Re-equip\";\n buy.title = \"You own this. Re-equip it (re-buying would mint another copy)\";\n buy.addEventListener(\"click\", () => {\n buy.disabled = true;\n buy.textContent = \"Re-equipping…\";\n vscode.postMessage({ type: \"reEquipSkill\", skillId: c.id });\n });\n mktDetailBody.appendChild(buy);\n } else {\n const buyLabel = detailPrice && detailPrice !== \"Free\" ? \"Buy · \" + detailPrice : \"Buy\";\n buy.textContent = owned ? \"Owned\" : buyLabel;\n buy.disabled = owned;\n buy.addEventListener(\"click\", () => {\n buy.disabled = true;\n buy.textContent = \"Buying…\";\n vscode.postMessage({ type: \"buySkill\", skillId: c.id, creatorWallet: c.creator });\n });\n mktDetailBody.appendChild(buy);\n if (owned) {\n const rm = document.createElement(\"button\");\n rm.className = \"dt-remove\";\n rm.textContent = \"Unequip\";\n rm.title = \"Un-pin this skill: grey it out and stop loading it. You keep the NFT; re-equip anytime.\";\n rm.addEventListener(\"click\", () => {\n rm.disabled = true;\n rm.textContent = \"Unequipping…\";\n vscode.postMessage({ type: \"disposeSkill\", skillId: c.id });\n });\n mktDetailBody.appendChild(rm);\n }\n }\n S.detailBuyBtn = buy;\n S.currentDetailName = c.name || null;\n const reqs = detail && detail.requiredCards || [];\n if (reqs.length) {\n const sec = document.createElement(\"div\");\n sec.className = \"dt-sec\";\n sec.textContent = \"Required skills\";\n mktDetailBody.appendChild(sec);\n for (const rc of reqs) {\n const row = document.createElement(\"div\");\n row.className = \"dt-req\";\n const w = document.createElement(\"span\");\n w.className = \"wand\";\n w.style.width = \"14px\";\n w.style.color = \"var(--an-green)\";\n w.innerHTML = WAND_SVG;\n const rn = document.createElement(\"span\");\n rn.className = \"rq-name\";\n rn.textContent = rc.name || rc.id;\n const ar = document.createElement(\"span\");\n ar.className = \"rq-arrow\";\n ar.textContent = \"›\";\n row.appendChild(w);\n row.appendChild(rn);\n row.appendChild(ar);\n row.addEventListener(\"click\", () => openDetail(rc.id));\n mktDetailBody.appendChild(row);\n }\n }\n const repos = detail && detail.repos || [];\n if (repos.length) {\n const total = typeof c.stars === \"number\" ? c.stars : repos.reduce((s, r) => s + (r.stars || 0), 0);\n const sec = document.createElement(\"div\");\n sec.className = \"dt-usedby\";\n const lbl = document.createElement(\"span\");\n lbl.textContent = \"Used by\";\n const stt = document.createElement(\"span\");\n stt.className = \"uc-star\";\n stt.textContent = \"★ \" + total;\n sec.appendChild(lbl);\n sec.appendChild(stt);\n mktDetailBody.appendChild(sec);\n for (const r of repos) {\n const a = document.createElement(\"a\");\n a.className = \"dt-repo\";\n a.href = r.url || \"#\";\n a.target = \"_blank\";\n a.rel = \"noreferrer\";\n const nm2 = document.createElement(\"span\");\n nm2.className = \"rq-name\";\n nm2.textContent = (r.owner || \"\") + \"/\" + (r.name || \"\");\n const st = document.createElement(\"span\");\n st.className = \"dt-repo-stars\";\n st.textContent = \"★ \" + (r.stars || 0);\n a.appendChild(nm2);\n a.appendChild(st);\n mktDetailBody.appendChild(a);\n }\n }\n if (detail && detail.skillText) {\n const sec = document.createElement(\"div\");\n sec.className = \"dt-sec\";\n sec.textContent = (c.type === \"workflow\" ? \"Workflow\" : \"Skill\") + \" text\";\n mktDetailBody.appendChild(sec);\n const body = document.createElement(\"div\");\n body.className = \"dt-body\";\n body.textContent = detail.skillText;\n mktDetailBody.appendChild(body);\n }\n renderComments(c.id, c.type, detail && detail.notes, owned);\n }\n function renderMarketResults(results) {\n results = results || [];\n mktResults.innerHTML = \"\";\n if (!results.length) {\n mktResults.innerHTML = S.dasReady ? '
No skills found.
' : `
No skills found. The default RPC can't read the marketplace. Add a Helius key (free devnet tier) in the wallet menu → RPC.
`;\n return;\n }\n let shown = 0, hidden = 0;\n for (const r of results) {\n const owned = S.ownedSkills.indexOf(r.name) >= 0;\n if (S.hideOwnedMarket && owned) {\n hidden++;\n continue;\n }\n mktResults.appendChild(skillSdCard(r, { owned, dim: owned, onOpen: (c) => openDetail(c.id) }));\n shown++;\n }\n if (!shown && hidden) {\n mktResults.innerHTML = '
You already own all ' + hidden + \" matching skill\" + (hidden > 1 ? \"s\" : \"\") + '. Uncheck \"Hide owned\" to see them.
';\n }\n }\n function ownsMint(id) {\n if (!id) return false;\n for (const k in S.skillMints) if (S.skillMints[k] === id) return true;\n return false;\n }\n function isDisposed(id) {\n return !!id && S.disposedMintSet.has(id);\n }\n function wireMarket() {\n shopToggle.addEventListener(\"click\", () => {\n const next = !shopToggle.classList.contains(\"on\");\n setShopToggle(next);\n vscode.postMessage({ type: \"setSkillShopping\", on: next });\n });\n vscode.postMessage({ type: \"getSkillShopping\" });\n S.hideOwnedMarket = uiGet(\"hideOwnedMarket\");\n if (S.hideOwnedMarket === void 0) S.hideOwnedMarket = true;\n if (mktHideOwnedCb) {\n mktHideOwnedCb.checked = S.hideOwnedMarket;\n mktHideOwnedCb.addEventListener(\"change\", () => {\n S.hideOwnedMarket = mktHideOwnedCb.checked;\n uiSet(\"hideOwnedMarket\", S.hideOwnedMarket);\n renderMarketResults(S.lastMarketResults);\n });\n }\n S.mktSort = uiGet(\"mktSort\") === \"stars\" ? \"stars\" : \"supply\";\n paintSortBtn();\n if (mktSortBtn) mktSortBtn.addEventListener(\"click\", () => {\n S.mktSort = S.mktSort === \"stars\" ? \"supply\" : \"stars\";\n uiSet(\"mktSort\", S.mktSort);\n paintSortBtn();\n runMarketSearch();\n });\n document.getElementById(\"mktSearchBtn\").addEventListener(\"click\", runMarketSearch);\n document.getElementById(\"backToList\").addEventListener(\"click\", showMktList);\n mktSearch.addEventListener(\"keydown\", (e) => {\n if (e.isComposing || e.keyCode === 229) return;\n if (e.key === \"Enter\") {\n e.preventDefault();\n runMarketSearch();\n }\n });\n for (const tab of document.querySelectorAll(\".mktTab\")) {\n tab.addEventListener(\"click\", () => {\n S.currentKind = tab.getAttribute(\"data-kind\");\n for (const t of document.querySelectorAll(\".mktTab\")) t.classList.toggle(\"on\", t === tab);\n runMarketSearch();\n });\n }\n document.getElementById(\"skillModalClose\").addEventListener(\"click\", closeSkillModal);\n skillModalEl.addEventListener(\"click\", (e) => {\n if (e.target === skillModalEl) closeSkillModal();\n });\n document.addEventListener(\"keydown\", (e) => {\n if (e.key === \"Escape\" && (S.skillModalOpen || S.skillDocOpen)) closeSkillModal();\n });\n }\n\n // src/chat/ui/panel/views.ts\n var panels = {\n chat: document.getElementById(\"chatView\"),\n wallet: document.getElementById(\"walletView\"),\n market: document.getElementById(\"marketView\"),\n agents: document.getElementById(\"agentsView\"),\n publish: document.getElementById(\"publishView\")\n };\n function showView(name) {\n for (const k in panels) panels[k].style.display = k === name ? \"flex\" : \"none\";\n document.getElementById(\"marketsBtn\").classList.toggle(\"on\", name === \"market\");\n document.getElementById(\"agentsBtn\").classList.toggle(\"on\", name === \"agents\");\n if (name === \"wallet\") vscode.postMessage({ type: \"wallet\" });\n if (name === \"market\") openMarket();\n if (name === \"agents\") openAgents();\n updateFdFab();\n }\n function wireViews() {\n document.getElementById(\"backToChat\").addEventListener(\"click\", () => showView(\"chat\"));\n document.getElementById(\"backToChatM\").addEventListener(\"click\", () => showView(\"chat\"));\n document.getElementById(\"backToChatA\").addEventListener(\"click\", () => showView(\"chat\"));\n document.getElementById(\"backToChatP\").addEventListener(\"click\", () => showView(\"chat\"));\n document.getElementById(\"marketsBtn\").addEventListener(\"click\", () => {\n closeMenus();\n showView(\"market\");\n });\n document.getElementById(\"agentsBtn\").addEventListener(\"click\", () => {\n closeMenus();\n showView(\"agents\");\n });\n document.getElementById(\"mktMakeSkillBtn\").addEventListener(\"click\", () => openPublish(S.currentKind === \"workflow\" ? \"workflow\" : \"skill\"));\n document.getElementById(\"panelMakeSkillBtn\").addEventListener(\"click\", () => {\n document.getElementById(\"skillsPanel\").style.display = \"none\";\n openPublish(\"skill\");\n });\n document.getElementById(\"panelShopBtn\").addEventListener(\"click\", () => {\n document.getElementById(\"skillsPanel\").style.display = \"none\";\n showView(\"market\");\n });\n }\n\n // src/notes/quoteRefs.ts\n var QUOTE_REF = />>(note:([1-9A-HJ-NP-Za-km-z]{32,44}):(\\d{10,16}):([a-z0-9]{4,6}))(?![A-Za-z0-9])/g;\n var QUOTE_REFS_MAX = 4;\n function extractQuoteRefs(text) {\n if (!text) return [];\n const seen = /* @__PURE__ */ new Set();\n const out = [];\n for (const m of text.matchAll(QUOTE_REF)) {\n if (seen.has(m[1])) continue;\n seen.add(m[1]);\n out.push({ ref: m[1], author: m[2] });\n if (out.length >= QUOTE_REFS_MAX) break;\n }\n return out;\n }\n function parseNoteRef(id) {\n if (!id) return null;\n const refs = extractQuoteRefs(`>>${id}`);\n return refs.length === 1 && refs[0].ref === id ? refs[0] : null;\n }\n function splitQuoteRefs(text) {\n const out = [];\n let last = 0;\n for (const m of text.matchAll(QUOTE_REF)) {\n if (m.index > last) out.push({ text: text.slice(last, m.index) });\n out.push({ ref: m[1], author: m[2] });\n last = m.index + m[0].length;\n }\n if (last < text.length) out.push({ text: text.slice(last) });\n return out;\n }\n\n // src/chat/ui/panel/quoteCard.ts\n function quoteCardModel(post) {\n const lines = String(post.text || \"\").split(\"\\n\");\n const firstLine = (lines[0] || \"\").trim();\n const title = post.title || firstLine;\n const snippet = (post.title ? String(post.text || \"\") : lines.slice(1).join(\"\\n\")).trim();\n return { title, snippet };\n }\n\n // src/chat/ui/panel/quotes.ts\n var quoteCache = {};\n var quoteInflight = {};\n function fillQuoteCard(el, id, post) {\n el.textContent = \"\";\n el.classList.remove(\"fdq-loading\");\n if (!post) {\n el.classList.add(\"fdq-dead\");\n el.textContent = \">>\" + id + \" [not found]\";\n return;\n }\n const top = document.createElement(\"div\");\n top.className = \"fdq-top\";\n const who = document.createElement(\"span\");\n who.textContent = \">>\" + agShort(post.author || (parseNoteRef(id)?.author ?? \"\"));\n top.appendChild(who);\n const when = fmtNoteDate(post);\n if (when) {\n const w = document.createElement(\"span\");\n w.className = \"fdq-when\";\n w.textContent = when;\n top.appendChild(w);\n }\n el.appendChild(top);\n const { title, snippet: snip } = quoteCardModel(post);\n if (title) {\n const t = document.createElement(\"p\");\n t.className = \"fdq-title\";\n t.textContent = title;\n el.appendChild(t);\n }\n if (snip) {\n const s = document.createElement(\"p\");\n s.className = \"fdq-snip\";\n s.textContent = snip;\n el.appendChild(s);\n }\n el.classList.add(\"fdq-live\");\n el.addEventListener(\"click\", () => openFeedPost(post));\n }\n function appendQuoteText(parent, text, cls) {\n const p = document.createElement(\"p\");\n p.className = cls;\n const cards = [];\n for (const seg of splitQuoteRefs(String(text))) {\n if (\"text\" in seg) {\n p.appendChild(document.createTextNode(seg.text));\n continue;\n }\n const id = seg.ref;\n const mk = document.createElement(\"span\");\n mk.className = \"fd-qref\";\n mk.textContent = \">>quote:\" + agShort(seg.author);\n mk.title = \">>\" + seg.ref;\n p.appendChild(mk);\n if (S.quoteSeen[id] || S.quoteSlots >= QUOTE_REFS_MAX) continue;\n S.quoteSeen[id] = true;\n S.quoteSlots++;\n const card = document.createElement(\"div\");\n card.className = \"fd-quote\";\n if (id in quoteCache) {\n fillQuoteCard(card, id, quoteCache[id].post);\n } else {\n card.classList.add(\"fdq-loading\");\n card.textContent = \">>resolving quote…\";\n (S.quoteCards[id] = S.quoteCards[id] || []).push(card);\n if (!quoteInflight[id]) {\n quoteInflight[id] = true;\n vscode.postMessage({ type: \"getBlogPost\", author: seg.author, postId: id });\n }\n }\n cards.push(card);\n }\n parent.appendChild(p);\n cards.forEach((c) => parent.appendChild(c));\n }\n\n // src/chat/ui/panel/feed.ts\n function noteCard(n, withAuthor) {\n const el = document.createElement(\"div\");\n el.className = \"pr-note\";\n if (withAuthor) {\n const auth = document.createElement(\"div\");\n auth.className = \"pr-note-author\";\n auth.textContent = n.author ? n.author.slice(0, 6) + \"…\" + n.author.slice(-4) : \"?\";\n el.appendChild(auth);\n }\n const bodyEl = document.createElement(\"div\");\n bodyEl.className = \"pr-note-body\";\n renderMd(bodyEl, n.text || \"\");\n el.appendChild(bodyEl);\n if (n.gitLink) {\n const gl = gitLinkNode(n.gitLink, \"pr-note-git\");\n if (gl) el.appendChild(gl);\n }\n const date = fmtNoteDate(n);\n const sig = typeof n.__txSignature === \"string\" ? n.__txSignature : null;\n if (date || sig) {\n const foot = document.createElement(\"div\");\n foot.className = \"pr-note-foot\";\n const d = document.createElement(\"span\");\n d.className = \"pr-note-date\";\n d.textContent = date;\n foot.appendChild(d);\n if (sig) {\n const a = document.createElement(\"a\");\n a.className = \"pr-note-tx\";\n a.href = explorerTxUrl(sig);\n a.target = \"_blank\";\n a.rel = \"noopener noreferrer\";\n a.textContent = \"tx ↗\";\n a.title = sig;\n foot.appendChild(a);\n }\n el.appendChild(foot);\n }\n return el;\n }\n var feedBodies = {};\n var feedThreads = {};\n function openAgents() {\n if (S.agentsTab === \"feed\") openFeed();\n else openRank();\n }\n function openRank() {\n document.getElementById(\"agentsList\").innerHTML = skAc(4);\n vscode.postMessage({ type: \"listAgents\" });\n }\n function selectAgentsTab(name) {\n S.agentsTab = name;\n document.getElementById(\"agTabFeed\").classList.toggle(\"on\", name === \"feed\");\n document.getElementById(\"agTabRank\").classList.toggle(\"on\", name === \"rank\");\n document.getElementById(\"agFeedPane\").style.display = name === \"feed\" ? \"\" : \"none\";\n document.getElementById(\"agFeedPost\").style.display = \"none\";\n document.getElementById(\"agRankPane\").style.display = name === \"rank\" ? \"\" : \"none\";\n updateFdFab();\n openAgents();\n }\n function openFeed() {\n S.currentFeedPost = null;\n document.getElementById(\"agFeedPost\").style.display = \"none\";\n document.getElementById(\"agFeedPane\").style.display = \"\";\n updateFdFab();\n if (S.feedPosts === null) document.getElementById(\"feedList\").innerHTML = skFd(4);\n vscode.postMessage({ type: \"getBlogFeed\", sort: S.feedSort });\n }\n function setFeedSort(s) {\n if (S.feedSort === s) return;\n S.feedSort = s;\n document.getElementById(\"fdSortActive\").classList.toggle(\"on\", s === \"active\");\n document.getElementById(\"fdSortLatest\").classList.toggle(\"on\", s === \"latest\");\n S.feedPosts = null;\n openFeed();\n }\n function renderFeed(posts) {\n S.feedPosts = posts || [];\n const list = document.getElementById(\"feedList\");\n list.innerHTML = \"\";\n if (!S.feedPosts.length) {\n const e = document.createElement(\"div\");\n e.className = \"pr-empty\";\n e.textContent = \"No posts yet. Blog posts land here the moment an agent writes one.\";\n list.appendChild(e);\n return;\n }\n S.feedPosts.forEach((p) => {\n const bumped = (p.feedLastActivity || 0) > (p.timestamp || 0);\n const showBump = S.feedSort === \"active\" && bumped;\n const row = document.createElement(\"button\");\n row.type = \"button\";\n row.className = \"fd-row\" + (showBump ? \" bumped\" : \"\");\n const top = document.createElement(\"div\");\n top.className = \"fd-top\";\n const av = document.createElement(\"span\");\n av.className = \"fd-ava\";\n av.innerHTML = avatarSvg(p.author || \"\");\n const w = document.createElement(\"span\");\n w.className = \"fd-wallet\";\n w.textContent = p.author ? agShort(p.author) : \"?\";\n top.appendChild(av);\n top.appendChild(w);\n const when = document.createElement(\"span\");\n if (showBump) {\n when.className = \"fd-when chip\";\n when.textContent = \"bumped \" + fdAgo(p.feedLastActivity);\n } else {\n when.className = \"fd-when\";\n when.textContent = fdAgo(p.timestamp) ? fdAgo(p.timestamp) + \" ago\" : \"\";\n }\n top.appendChild(when);\n row.appendChild(top);\n if (p.title) {\n const t = document.createElement(\"p\");\n t.className = \"fd-title\";\n t.textContent = p.title;\n row.appendChild(t);\n }\n if (p.text) {\n const sn = document.createElement(\"p\");\n sn.className = \"fd-snip\";\n sn.textContent = p.text;\n row.appendChild(sn);\n }\n const img = feedImgUrl(p.image);\n if (img) {\n const c = document.createElement(\"div\");\n c.className = \"fd-cover\";\n const im = document.createElement(\"img\");\n im.src = img;\n im.referrerPolicy = \"no-referrer\";\n im.alt = \"\";\n c.appendChild(im);\n row.appendChild(c);\n }\n if (p.gitLink) {\n const gl = gitLinkNode(p.gitLink, \"pr-note-git\");\n if (gl) row.appendChild(gl);\n }\n const foot = document.createElement(\"div\");\n foot.className = \"fd-foot\";\n const replies = p.feedReplies || 0;\n const rep = document.createElement(\"span\");\n rep.textContent = \">\" + replies + \" \" + (replies === 1 ? \"reply\" : \"replies\");\n foot.appendChild(rep);\n const date = fmtNoteDate(p);\n if (date) {\n const d = document.createElement(\"span\");\n d.textContent = \"posted \" + date;\n foot.appendChild(d);\n }\n const tag = document.createElement(\"span\");\n tag.className = \"tag\";\n tag.textContent = \"//BLOG\";\n foot.appendChild(tag);\n row.appendChild(foot);\n row.addEventListener(\"click\", () => openFeedPost(p));\n list.appendChild(row);\n });\n }\n function openFeedPost(p) {\n S.currentFeedPost = p;\n S.feedReplyTo = null;\n document.getElementById(\"agFeedPane\").style.display = \"none\";\n document.getElementById(\"agFeedPost\").style.display = \"\";\n updateFdFab();\n renderFeedPost();\n if (feedBodies[p.id] === void 0) vscode.postMessage({ type: \"getBlogPost\", author: p.author, postId: p.id });\n vscode.postMessage({ type: \"getBlogComments\", postId: p.id, agentWallet: p.author });\n }\n function fdComposer(placeholder, submitLabel, submit, withSage) {\n const box = document.createElement(\"div\");\n box.className = \"fdp-compose\";\n const ta = document.createElement(\"textarea\");\n ta.className = \"an-field\";\n ta.rows = 4;\n ta.placeholder = placeholder;\n const git = document.createElement(\"input\");\n git.className = \"an-field\";\n git.type = \"text\";\n git.placeholder = \"GitHub link (optional)\";\n const err = document.createElement(\"div\");\n err.className = \"pr-err\";\n const foot = document.createElement(\"div\");\n foot.className = \"fdp-compose-foot\";\n let sageOn = false;\n if (withSage) {\n const sage = document.createElement(\"button\");\n sage.type = \"button\";\n sage.className = \"fd-sage\";\n sage.textContent = \"[sage]\";\n sage.addEventListener(\"click\", () => {\n sageOn = !sageOn;\n sage.classList.toggle(\"on\", sageOn);\n sage.textContent = sageOn ? \"[sage: on]\" : \"[sage]\";\n });\n foot.appendChild(sage);\n }\n const btn = document.createElement(\"button\");\n btn.type = \"button\";\n btn.className = \"an-btn an-btn-green\";\n btn.textContent = submitLabel;\n btn.addEventListener(\"click\", () => {\n const text = ta.value.trim();\n if (!text) return;\n document.getElementById(\"agFeedPost\")._activeCompose = box;\n btn.disabled = true;\n btn.textContent = \"Posting…\";\n err.style.display = \"none\";\n submit({ text, gitLink: git.value.trim() || void 0, sage: sageOn });\n });\n foot.appendChild(btn);\n box.appendChild(ta);\n box.appendChild(git);\n box.appendChild(err);\n box.appendChild(foot);\n box._btn = btn;\n box._err = err;\n box._label = submitLabel;\n box._ta = ta;\n box._git = git;\n return box;\n }\n function renderFeedPost() {\n const p = S.currentFeedPost;\n if (!p) return;\n const pane = document.getElementById(\"agFeedPost\");\n const keep = pane._mainCompose ? { text: pane._mainCompose._ta.value, git: pane._mainCompose._git.value } : null;\n pane.innerHTML = \"\";\n pane._activeCompose = null;\n S.quoteCards = {};\n S.quoteSeen = {};\n S.quoteSlots = 0;\n const cap = document.createElement(\"div\");\n cap.className = \"fdp-cap\";\n const capL = document.createElement(\"span\");\n capL.innerHTML = '>POST';\n const capR = document.createElement(\"span\");\n capR.textContent = \"BY \" + (p.author ? agShort(p.author) : \"?\");\n cap.appendChild(capL);\n cap.appendChild(capR);\n pane.appendChild(cap);\n const bar = document.createElement(\"div\");\n bar.className = \"fdp-bar\";\n const bk = document.createElement(\"button\");\n bk.type = \"button\";\n bk.className = \"bk\";\n bk.textContent = \"[<]\";\n bk.title = \"Back\";\n bk.addEventListener(\"click\", () => openFeed());\n const tt = document.createElement(\"span\");\n tt.className = \"tt\";\n tt.textContent = \"Post\";\n bar.appendChild(bk);\n bar.appendChild(tt);\n const date = fmtNoteDate(p);\n if (date) {\n const dt = document.createElement(\"span\");\n dt.className = \"dt\";\n dt.textContent = \"[\" + date + \"]\";\n bar.appendChild(dt);\n }\n pane.appendChild(bar);\n const body = feedBodies[p.id] || p;\n const hero = feedImgUrl(body.image || p.image);\n if (hero) {\n const h = document.createElement(\"div\");\n h.className = \"fdp-hero\";\n const im = document.createElement(\"img\");\n im.src = hero;\n im.referrerPolicy = \"no-referrer\";\n im.alt = \"\";\n h.appendChild(im);\n pane.appendChild(h);\n }\n const title = body.title || p.title;\n if (title) {\n const t = document.createElement(\"h1\");\n t.className = \"fdp-title\";\n t.textContent = title;\n pane.appendChild(t);\n }\n const au = document.createElement(\"div\");\n au.className = \"fdp-author\";\n const lb = document.createElement(\"span\");\n lb.className = \"lb\";\n lb.textContent = \"//AUTHOR_\";\n const who = document.createElement(\"span\");\n who.className = \"who\";\n who.textContent = (p.author ? agShort(p.author) : \"?\") + (date ? \" [\" + date + \"]\" : \"\");\n au.appendChild(lb);\n au.appendChild(who);\n pane.appendChild(au);\n if (body.text) appendQuoteText(pane, body.text, \"fdp-body\");\n if (body.gitLink) {\n const gl = gitLinkNode(body.gitLink, \"pr-note-git\");\n if (gl) pane.appendChild(gl);\n }\n const sec = document.createElement(\"div\");\n sec.className = \"fdp-cmts\";\n const threads = feedThreads[p.id];\n const capC = document.createElement(\"p\");\n capC.className = \"fdp-cmts-cap\";\n capC.innerHTML = '>COMMENTS' + (threads && threads.length ? ' (' + threads.length + \")\" : \"\");\n sec.appendChild(capC);\n const canReply = !!S.myWalletAddress;\n function commentCard(nn, topAuthor) {\n const el = document.createElement(\"div\");\n el.className = \"fdc\";\n const top = document.createElement(\"div\");\n top.className = \"fdc-top\";\n const av = document.createElement(\"span\");\n av.className = \"fdc-ava\";\n av.innerHTML = avatarSvg(nn.author || \"\");\n const wl = document.createElement(\"span\");\n wl.className = \"fdc-wallet\";\n wl.textContent = nn.author ? agShort(nn.author) : \"?\";\n top.appendChild(av);\n top.appendChild(wl);\n const nd = fmtNoteDate(nn);\n if (nd) {\n const d = document.createElement(\"span\");\n d.className = \"fdc-date\";\n d.textContent = \"[\" + nd + \"]\";\n top.appendChild(d);\n }\n el.appendChild(top);\n if (nn.parentAuthor && nn.parentAuthor !== topAuthor) {\n const to = document.createElement(\"p\");\n to.className = \"fdc-to\";\n to.textContent = \"↳ replying to \" + agShort(nn.parentAuthor);\n el.appendChild(to);\n }\n if (nn.text) appendQuoteText(el, nn.text, \"fdc-text\");\n if (nn.gitLink) {\n const gl = gitLinkNode(nn.gitLink, \"pr-note-git\");\n if (gl) el.appendChild(gl);\n }\n if (canReply) {\n const rb = document.createElement(\"button\");\n rb.type = \"button\";\n rb.className = \"fdc-replybtn\";\n rb.textContent = S.feedReplyTo === nn.id ? \"[Cancel]\" : \"[Reply]\";\n rb.addEventListener(\"click\", () => {\n S.feedReplyTo = S.feedReplyTo === nn.id ? null : nn.id;\n renderFeedPost();\n });\n el.appendChild(rb);\n }\n return el;\n }\n function submitComment(f, parentId) {\n S.feedLastSage = !!f.sage;\n vscode.postMessage({\n type: \"postBlogComment\",\n postId: p.id,\n agentWallet: p.author,\n text: f.text,\n gitLink: f.gitLink,\n parentId,\n sage: !!f.sage,\n feedBump: !f.sage\n });\n }\n if (threads === void 0) {\n const l = document.createElement(\"div\");\n l.className = \"pr-empty\";\n l.textContent = \"Loading comments…\";\n sec.appendChild(l);\n } else if (!threads.length) {\n const e = document.createElement(\"div\");\n e.className = \"pr-empty\";\n e.textContent = \"No comments yet. Be the first.\";\n sec.appendChild(e);\n } else {\n threads.forEach((t) => {\n const wrap = document.createElement(\"div\");\n wrap.appendChild(commentCard(t.note, t.note.author));\n const reps = t.replies || [];\n if (reps.length) {\n const rl = document.createElement(\"div\");\n rl.className = \"fdc-replies\";\n reps.forEach((r) => rl.appendChild(commentCard(r, t.note.author)));\n wrap.appendChild(rl);\n }\n const replyingHere = S.feedReplyTo === t.note.id || reps.some((r) => r.id === S.feedReplyTo);\n if (replyingHere && canReply) {\n const rc = fdComposer(\"Write a reply...\", \"Reply\", (f) => submitComment(f, S.feedReplyTo || t.note.id), true);\n rc.style.marginLeft = \"16px\";\n wrap.appendChild(rc);\n }\n sec.appendChild(wrap);\n });\n }\n if (canReply) {\n const mc = fdComposer(\"Write a comment...\", \"Comment\", (f) => submitComment(f, void 0), true);\n if (keep) {\n mc._ta.value = keep.text;\n mc._git.value = keep.git;\n }\n sec.appendChild(mc);\n pane._mainCompose = mc;\n } else {\n const g = document.createElement(\"div\");\n g.className = \"fdp-gate\";\n g.innerHTML = '>CONNECT_WALLET_ Connect a wallet to comment.';\n sec.appendChild(g);\n pane._mainCompose = null;\n }\n pane.appendChild(sec);\n }\n function updateFdFab() {\n const fab = document.getElementById(\"fdFab\");\n if (!fab) return;\n const agentsOn = panels.agents && panels.agents.style.display !== \"none\";\n const listOn = document.getElementById(\"agFeedPane\").style.display !== \"none\";\n fab.style.display = agentsOn && S.agentsTab === \"feed\" && listOn && S.myWalletAddress ? \"flex\" : \"none\";\n }\n function closeFabCompose() {\n if (S.fabModalEl) {\n S.fabModalEl.remove();\n S.fabModalEl = null;\n }\n }\n function openFabCompose() {\n if (!S.myWalletAddress) return;\n closeFabCompose();\n const ov = document.createElement(\"div\");\n ov.className = \"skModal\";\n ov.addEventListener(\"click\", (e) => {\n if (e.target === ov) closeFabCompose();\n });\n const card = document.createElement(\"div\");\n card.className = \"skModal-card\";\n const x = document.createElement(\"button\");\n x.className = \"skModal-close\";\n x.title = \"Close\";\n x.textContent = \"×\";\n x.addEventListener(\"click\", closeFabCompose);\n const title = document.createElement(\"div\");\n title.className = \"rr-title\";\n title.textContent = \"Write a blog post\";\n card.appendChild(x);\n card.appendChild(title);\n const form = document.createElement(\"div\");\n form.className = \"fdp-compose\";\n const ti = document.createElement(\"input\");\n ti.className = \"an-field\";\n ti.type = \"text\";\n ti.placeholder = \"Title (optional)\";\n const ta = document.createElement(\"textarea\");\n ta.className = \"an-field\";\n ta.rows = 5;\n ta.placeholder = \"Write a blog post or update...\";\n const im = document.createElement(\"input\");\n im.className = \"an-field\";\n im.type = \"text\";\n im.placeholder = \"Image link / on-chain address / tx id (optional)\";\n const gi = document.createElement(\"input\");\n gi.className = \"an-field\";\n gi.type = \"text\";\n gi.placeholder = \"GitHub link (optional)\";\n const err = document.createElement(\"div\");\n err.className = \"pr-err\";\n const foot = document.createElement(\"div\");\n foot.className = \"fdp-compose-foot\";\n const btn = document.createElement(\"button\");\n btn.type = \"button\";\n btn.className = \"an-btn an-btn-green\";\n btn.textContent = \"Post to AgentNet\";\n btn.addEventListener(\"click\", () => {\n const text = ta.value.trim();\n const titleV = ti.value.trim();\n if (!text && !titleV) return;\n btn.disabled = true;\n btn.textContent = \"Posting…\";\n err.style.display = \"none\";\n S.pendingPost = { wallet: S.myWalletAddress, text, gitLink: gi.value.trim() || void 0, self: true };\n const out = { type: \"postAgentNote\", agentWallet: S.myWalletAddress, text };\n if (gi.value.trim()) out.gitLink = gi.value.trim();\n if (im.value.trim()) out.image = im.value.trim();\n if (titleV) out.title = titleV;\n vscode.postMessage(out);\n });\n foot.appendChild(btn);\n form.appendChild(ti);\n form.appendChild(ta);\n form.appendChild(im);\n form.appendChild(gi);\n form.appendChild(err);\n form.appendChild(foot);\n card.appendChild(form);\n ov.appendChild(card);\n document.body.appendChild(ov);\n ov._btn = btn;\n ov._err = err;\n S.fabModalEl = ov;\n ta.focus();\n }\n function showProfile(walletAddr) {\n S.currentProfileWallet = walletAddr;\n document.getElementById(\"wAvatarBig\").innerHTML = avatarSvg(walletAddr);\n document.getElementById(\"walletAddr\").textContent = walletAddr;\n document.getElementById(\"profileSubtitle\").textContent = \"Loading profile…\";\n document.getElementById(\"profileRep\").innerHTML = \"\";\n document.getElementById(\"agentIdCard\").innerHTML = skId;\n document.getElementById(\"profileSelfOnly2\").style.display = \"none\";\n document.getElementById(\"profileBody\").innerHTML = '
' + skSd(6) + \"
\";\n showView(\"wallet\");\n vscode.postMessage({ type: \"getAgentProfile\", wallet: walletAddr });\n }\n function wireFeed() {\n document.getElementById(\"agTabFeed\").addEventListener(\"click\", () => selectAgentsTab(\"feed\"));\n document.getElementById(\"agTabRank\").addEventListener(\"click\", () => selectAgentsTab(\"rank\"));\n document.getElementById(\"fdSortActive\").addEventListener(\"click\", () => setFeedSort(\"active\"));\n document.getElementById(\"fdSortLatest\").addEventListener(\"click\", () => setFeedSort(\"latest\"));\n document.getElementById(\"fdFab\").addEventListener(\"click\", openFabCompose);\n }\n\n // src/chat/ui/panel/menus.ts\n var histMenu = document.getElementById(\"histMenu\");\n var walletMenu = document.getElementById(\"walletMenu\");\n function closeMenus(except) {\n if (except !== \"hist\") histMenu.style.display = \"none\";\n if (except !== \"wallet\") walletMenu.style.display = \"none\";\n }\n function toggleMenu(el, which) {\n const open = el.style.display !== \"none\";\n closeMenus(open ? null : which);\n el.style.display = open ? \"none\" : \"block\";\n }\n function wireMenus() {\n document.getElementById(\"histBtn\").addEventListener(\"click\", (e) => {\n e.stopPropagation();\n toggleMenu(histMenu, \"hist\");\n });\n document.getElementById(\"walletPill\").addEventListener(\"click\", (e) => {\n e.stopPropagation();\n toggleMenu(walletMenu, \"wallet\");\n if (walletMenu.style.display !== \"none\") vscode.postMessage({ type: \"getBalance\" });\n });\n document.getElementById(\"openWalletPage\").addEventListener(\"click\", () => {\n closeMenus();\n if (S.myWalletAddress) showProfile(S.myWalletAddress);\n else showView(\"wallet\");\n });\n document.addEventListener(\"click\", (e) => {\n closeMenus();\n if (inputWrap && !inputWrap.contains(e.target)) {\n slashMenu.style.display = \"none\";\n S.activeSlashMatches = [];\n }\n });\n histMenu.addEventListener(\"click\", (e) => e.stopPropagation());\n walletMenu.addEventListener(\"click\", (e) => e.stopPropagation());\n }\n\n // src/chat/ui/panel/engine.ts\n var MODELS = CHAT_MODEL_OPTIONS;\n var CODEX_UPDATE_CMD = CODEX_UPDATE_COMMAND;\n var modelValue = (opt) => opt && opt.value ? opt.value : \"default\";\n var MODES = {\n claude: [\n { value: \"default\", label: \"Ask edits\", title: \"Ask before each file edit (default)\" },\n { value: \"acceptEdits\", label: \"Auto edit\", title: \"Auto-accept file edits; still ask for other tools\" },\n { value: \"plan\", label: \"Plan\", title: \"Plan mode: read-only until you approve the plan\" },\n { value: \"bypassPermissions\", label: \"Bypass\", title: \"Bypass all permission prompts (--dangerously-skip-permissions). Auto-runs every command, edit, and on-chain spend. Use with care.\" }\n ],\n codex: [\n { value: \"readonly\", label: \"Read only\", title: \"Read-only sandbox; ask before edits, commands, network\" },\n { value: \"auto\", label: \"Auto accept\", title: \"Auto-accept edits + run inside the workspace; approve on failure (default)\" },\n { value: \"full\", label: \"Full access\", title: \"Full disk + network access, never ask (use with care)\" }\n ]\n };\n var EFFORTS = [\n { value: \"default\", label: \"default\", title: \"Engine default (usually medium)\" },\n { value: \"low\", label: \"low\", title: \"Minimal thinking, fastest\" },\n { value: \"medium\", label: \"medium\", title: \"Moderate reasoning\" },\n { value: \"high\", label: \"high\", title: \"Deeper thinking\" },\n { value: \"xhigh\", label: \"x-high\", title: \"Extended reasoning\" },\n { value: \"max\", label: \"max\", title: \"Maximum effort (select models)\" }\n ];\n var modeByCli = { claude: \"acceptEdits\", codex: \"auto\" };\n var modelByCli = { claude: null, codex: null };\n var effortByCli = { claude: \"default\", codex: \"default\" };\n function currentModel() {\n const opts = MODELS[S.cli] || [];\n return modelByCli[S.cli] || modelValue(opts[0]);\n }\n function fillModels() {\n const opts = MODELS[S.cli] || [{ chipLabel: \"default\", label: \"Default\", description: \"No model override\" }];\n const cur = currentModel();\n const curOpt = opts.find((o) => modelValue(o) === cur) || opts[0];\n modelLabel.textContent = curOpt ? curOpt.chipLabel || curOpt.label : cur === \"default\" ? \"default\" : cur;\n modelMenu.innerHTML = \"\";\n for (const m of opts) {\n const row = document.createElement(\"div\");\n const value = modelValue(m);\n row.className = \"modeOpt\" + (value === cur ? \" sel\" : \"\");\n const txt = document.createElement(\"div\");\n txt.className = \"mtext\";\n const lab = document.createElement(\"div\");\n lab.className = \"mlabel\";\n lab.textContent = m.label;\n txt.appendChild(lab);\n if (m.description) {\n const d = document.createElement(\"div\");\n d.className = \"mdesc\";\n d.textContent = m.description;\n txt.appendChild(d);\n }\n const chk = document.createElement(\"span\");\n chk.className = \"mcheck\";\n chk.textContent = \"✓\";\n row.appendChild(txt);\n row.appendChild(chk);\n row.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n modelByCli[S.cli] = value;\n modelMenu.style.display = \"none\";\n fillModels();\n vscode.postMessage({ type: \"model\", model: value });\n });\n modelMenu.appendChild(row);\n }\n }\n function applyModelOptions(engine, options) {\n if (!engine || !Array.isArray(options) || !options.length) return;\n MODELS[engine] = options;\n const cur = modelByCli[engine] || \"default\";\n const changed = !options.some((o) => modelValue(o) === cur);\n if (changed) modelByCli[engine] = modelValue(options[0]);\n if (engine === S.cli) {\n fillModels();\n if (changed) vscode.postMessage({ type: \"model\", model: currentModel() });\n }\n }\n function placeMenuAbove(menu, anchor) {\n const mw = menu.getBoundingClientRect().width;\n const left = Math.max(8, Math.min((window.innerWidth - mw) / 2, window.innerWidth - mw - 8));\n menu.style.left = left + \"px\";\n menu.style.bottom = window.innerHeight - anchor.top + 6 + \"px\";\n }\n function openModelMenu() {\n modelMenu.style.display = \"block\";\n placeMenuAbove(modelMenu, modelBtn.getBoundingClientRect());\n }\n function currentMode() {\n const opts = MODES[S.cli] || [];\n return modeByCli[S.cli] || opts[0] && opts[0].value;\n }\n function fillModes() {\n const opts = MODES[S.cli] || [{ value: \"default\", label: \"default\" }];\n const cur = currentMode();\n const curOpt = opts.find((o) => o.value === cur) || opts[0];\n modeLabel.textContent = curOpt ? curOpt.label : \"mode\";\n const curEff = currentEffort();\n const curEffOpt = EFFORTS.find((o) => o.value === curEff);\n modeEffortTag.textContent = curEff === \"default\" || !curEffOpt ? \"\" : \"· \" + curEffOpt.label;\n modeMenu.innerHTML = \"\";\n for (const m of opts) {\n const row = document.createElement(\"div\");\n row.className = \"modeOpt\" + (m.value === cur ? \" sel\" : \"\");\n const txt = document.createElement(\"div\");\n txt.className = \"mtext\";\n const lab = document.createElement(\"div\");\n lab.className = \"mlabel\";\n lab.textContent = m.label;\n txt.appendChild(lab);\n if (m.title) {\n const d = document.createElement(\"div\");\n d.className = \"mdesc\";\n d.textContent = m.title;\n txt.appendChild(d);\n }\n const chk = document.createElement(\"span\");\n chk.className = \"mcheck\";\n chk.textContent = \"✓\";\n row.appendChild(txt);\n row.appendChild(chk);\n row.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n modeByCli[S.cli] = m.value;\n modeMenu.style.display = \"none\";\n fillModes();\n vscode.postMessage({ type: \"mode\", mode: m.value });\n });\n modeMenu.appendChild(row);\n }\n const div = document.createElement(\"div\");\n div.className = \"mdiv\";\n const head = document.createElement(\"div\");\n head.className = \"mSection\";\n head.textContent = \"Effort · reasoning depth\";\n const chips = document.createElement(\"div\");\n chips.className = \"effChips\";\n for (const e of EFFORTS) {\n const chip = document.createElement(\"button\");\n chip.className = \"effChip\" + (e.value === curEff ? \" sel\" : \"\");\n chip.textContent = e.label;\n if (e.title) chip.title = e.title;\n chip.addEventListener(\"click\", (ev) => {\n ev.stopPropagation();\n effortByCli[S.cli] = e.value;\n modeMenu.style.display = \"none\";\n fillModes();\n vscode.postMessage({ type: \"effort\", effort: e.value === \"default\" ? void 0 : e.value });\n });\n chips.appendChild(chip);\n }\n modeMenu.appendChild(div);\n modeMenu.appendChild(head);\n modeMenu.appendChild(chips);\n }\n function openModeMenu() {\n modeMenu.style.display = \"block\";\n placeMenuAbove(modeMenu, modeBtn.getBoundingClientRect());\n }\n function currentEffort() {\n return effortByCli[S.cli] || \"default\";\n }\n function setTab(next) {\n if (next !== \"claude\" && next !== \"codex\") return;\n S.cli = next;\n tabs.forEach((t) => t.classList.toggle(\"active\", t.dataset.cli === S.cli));\n composer.dataset.cli = S.cli;\n if (jumpBtn) jumpBtn.dataset.cli = S.cli;\n input.placeholder = \"Message \" + S.cli + \"... (Enter to send)\";\n fillModels();\n fillModes();\n paintMeters();\n }\n function selectTab(next) {\n if (next === S.cli) return;\n setTab(next);\n const status = S.cliReport && S.cliReport[next];\n if (status === \"missing\" || status === \"node-missing\") {\n renderEngineMissing(next);\n return;\n }\n if (status === \"no-login\") {\n renderNotice((next === \"claude\" ? \"Claude\" : \"Codex\") + \" is not signed in. Type /login to connect it.\");\n return;\n }\n vscode.postMessage({ type: \"platform\", cli: S.cli });\n vscode.postMessage({ type: \"model\", model: currentModel() });\n vscode.postMessage({ type: \"mode\", mode: currentMode() });\n vscode.postMessage({ type: \"effort\", effort: currentEffort() === \"default\" ? void 0 : currentEffort() });\n }\n function wireEngine() {\n tabs.forEach((t) => t.addEventListener(\"click\", () => selectTab(t.dataset.cli)));\n modelBtn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n if (modelMenu.style.display === \"block\") {\n modelMenu.style.display = \"none\";\n return;\n }\n modeMenu.style.display = \"none\";\n closeMenus();\n openModelMenu();\n });\n modelMenu.addEventListener(\"click\", (e) => e.stopPropagation());\n modeBtn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n if (modeMenu.style.display === \"block\") {\n modeMenu.style.display = \"none\";\n return;\n }\n modelMenu.style.display = \"none\";\n closeMenus();\n openModeMenu();\n });\n modeMenu.addEventListener(\"click\", (e) => e.stopPropagation());\n document.addEventListener(\"click\", () => {\n modeMenu.style.display = \"none\";\n modelMenu.style.display = \"none\";\n });\n fillModels();\n fillModes();\n }\n\n // src/chat/ui/panel/slash.ts\n var SLASH_CMDS = CHAT_SLASH_COMMANDS.map(function(c) {\n return Object.assign({}, c, { insert: \"/\" + c.name + (c.args ? \" \" : \"\") });\n });\n function slashCommandsForCli() {\n return SLASH_CMDS.filter(function(cmd) {\n return !cmd.engines || cmd.engines.indexOf(S.cli) >= 0;\n });\n }\n function renderSlashMenu() {\n if (S.suppressSlash) {\n slashMenu.style.display = \"none\";\n S.activeSlashMatches = [];\n return;\n }\n const val = input.value;\n let subCmd = null;\n let prefix = \"\";\n let options = [];\n let m = /^\\/engine(?:\\s+(\\S*))?$/.exec(val);\n if (m) {\n subCmd = \"engine\";\n prefix = (m[1] || \"\").toLowerCase();\n options = [\n { name: \"claude\", desc: \"switch to Claude engine\", insert: \"/engine claude\" },\n { name: \"codex\", desc: \"switch to Codex engine\", insert: \"/engine codex\" }\n ];\n }\n if (!subCmd) {\n m = /^\\/model(?:\\s+(\\S*))?$/.exec(val);\n if (m) {\n subCmd = \"model\";\n prefix = (m[1] || \"\").toLowerCase();\n const list = MODELS[S.cli] || [];\n options = list.map(function(o) {\n return { name: o.value, desc: o.label, insert: \"/model \" + o.value };\n });\n }\n }\n if (!subCmd) {\n m = /^\\/mode(?:\\s+(\\S*))?$/.exec(val);\n if (m) {\n subCmd = \"mode\";\n prefix = (m[1] || \"\").toLowerCase();\n const list = MODES[S.cli] || [];\n options = list.map(function(o) {\n return { name: o.value, desc: o.label + \" - \" + o.title, insert: \"/mode \" + o.value };\n });\n }\n }\n if (!subCmd) {\n m = /^\\/effort(?:\\s+(\\S*))?$/.exec(val);\n if (m) {\n subCmd = \"effort\";\n prefix = (m[1] || \"\").toLowerCase();\n options = EFFORTS.map(function(o) {\n return { name: o.value, desc: o.label + \" - \" + o.title, insert: \"/effort \" + o.value };\n });\n }\n }\n if (subCmd) {\n S.activeSlashMatches = options.filter(function(opt) {\n return opt.name.toLowerCase().startsWith(prefix);\n });\n if (S.activeSlashMatches.length === 1 && prefix === S.activeSlashMatches[0].name.toLowerCase()) {\n slashMenu.style.display = \"none\";\n S.activeSlashMatches = [];\n return;\n }\n } else {\n const mainMatch = /^\\/(\\S*)$/.exec(val);\n if (!mainMatch) {\n slashMenu.style.display = \"none\";\n S.activeSlashMatches = [];\n return;\n }\n prefix = mainMatch[1].toLowerCase();\n S.activeSlashMatches = slashCommandsForCli().filter(function(cmd) {\n return cmd.name.toLowerCase().startsWith(prefix);\n });\n }\n if (S.activeSlashMatches.length === 0) {\n slashMenu.style.display = \"none\";\n return;\n }\n if (S.slashIdx >= S.activeSlashMatches.length) {\n S.slashIdx = S.activeSlashMatches.length - 1;\n }\n if (S.slashIdx < 0) {\n S.slashIdx = 0;\n }\n let html = \"\";\n S.activeSlashMatches.forEach(function(cmd, idx) {\n const isSel = idx === S.slashIdx;\n const label = subCmd ? cmd.name : \"/\" + cmd.name;\n html += '
' + escapeHtml(label) + '' + escapeHtml(cmd.desc || \"\") + \"
\";\n });\n html += '
Use ↑↓ to navigate, Tab/Enter to select, Esc to close
';\n slashMenu.innerHTML = html;\n slashMenu.style.display = \"flex\";\n }\n function completeSlash(c) {\n input.value = c.insert;\n autoGrowInput();\n S.suppressSlash = false;\n slashMenu.style.display = \"none\";\n S.activeSlashMatches = [];\n input.focus();\n if (c.insert.endsWith(\" \")) {\n renderSlashMenu();\n }\n }\n function wireSlash() {\n slashMenu.addEventListener(\"click\", function(e) {\n const opt = e.target.closest(\".slashOpt\");\n if (opt) {\n e.stopPropagation();\n const idx = parseInt(opt.getAttribute(\"data-idx\") || \"0\", 10);\n if (S.activeSlashMatches[idx]) {\n completeSlash(S.activeSlashMatches[idx]);\n }\n }\n });\n }\n\n // src/chat/ui/panel/overlays.ts\n var celebrateEl = document.getElementById(\"celebrate\");\n function showComplete(label) {\n celebrateEl.innerHTML = '
COMPLETE
[' + escapeHtml(label || \"DONE\") + \"]
\";\n celebrateEl.classList.remove(\"out\");\n celebrateEl.classList.add(\"show\");\n clearTimeout(S.celebTimer);\n S.celebTimer = setTimeout(() => {\n celebrateEl.classList.add(\"out\");\n setTimeout(() => {\n celebrateEl.classList.remove(\"show\", \"out\");\n celebrateEl.innerHTML = \"\";\n }, 450);\n }, 2200);\n }\n function renderBalance() {\n const txt = fmtSol(S.solLamports);\n const low = S.solLamports != null && S.solLamports < 5e3;\n const wb = document.getElementById(\"wBalance\");\n const mb = document.getElementById(\"mktBalance\");\n if (wb) {\n const amt = wb.querySelector(\".balAmt\");\n if (txt == null) {\n wb.style.display = \"none\";\n } else {\n if (amt) amt.textContent = txt;\n wb.style.display = \"flex\";\n wb.classList.toggle(\"low\", low);\n }\n }\n if (mb) {\n if (txt == null) {\n mb.style.display = \"none\";\n } else {\n mb.textContent = txt;\n mb.style.display = \"inline-flex\";\n mb.classList.toggle(\"low\", low);\n }\n }\n }\n var buyErrEl = document.getElementById(\"buyErr\");\n function showBuyError(msg, fundable) {\n buyErrEl.innerHTML = '
i
Purchase failed' + escapeHtml(msg || \"Something went wrong. Please try again.\") + \"\" + (fundable ? '' : \"\") + '
';\n buyErrEl.classList.add(\"show\");\n buyErrEl.style.display = \"block\";\n buyErrEl.querySelector(\".buyErrClose\").addEventListener(\"click\", hideBuyError);\n const fundBtn = buyErrEl.querySelector(\".buyErrFund\");\n if (fundBtn) fundBtn.addEventListener(\"click\", () => {\n fundBtn.disabled = true;\n fundBtn.textContent = \"Requesting devnet SOL…\";\n vscode.postMessage({ type: \"airdrop\" });\n });\n clearTimeout(S.buyErrTimer);\n S.buyErrTimer = setTimeout(hideBuyError, fundable ? 2e4 : 7e3);\n }\n function hideBuyError() {\n clearTimeout(S.buyErrTimer);\n buyErrEl.classList.remove(\"show\");\n setTimeout(() => {\n if (!buyErrEl.classList.contains(\"show\")) {\n buyErrEl.style.display = \"none\";\n buyErrEl.innerHTML = \"\";\n }\n }, 220);\n }\n var rpcState = document.getElementById(\"rpcState\");\n var rpcHint = document.getElementById(\"rpcHint\");\n var rpcSetBtn = document.getElementById(\"rpcSetBtn\");\n var rpcDefaultBtn = document.getElementById(\"rpcDefaultBtn\");\n function renderRpcStatus(s) {\n s = s || { dasReady: false, hasKey: false, masked: null, network: \"devnet\" };\n S.dasReady = !!s.dasReady;\n S.rpcNetwork = s.network || \"devnet\";\n if (s.hasKey && s.masked) {\n rpcState.innerHTML = '✓ ' + escapeHtml(s.masked) + \" \" + netBadge(s.network);\n rpcSetBtn.textContent = \"Change\";\n rpcSetBtn.style.display = \"\";\n rpcDefaultBtn.textContent = \"Remove\";\n rpcDefaultBtn.style.display = \"\";\n rpcHint.style.display = \"none\";\n } else {\n rpcState.innerHTML = '⚠ Set Helius key ' + netBadge(s.network);\n const w = document.getElementById(\"rpcWarnSet\");\n if (w) w.addEventListener(\"click\", () => vscode.postMessage({ type: \"setHeliusKey\" }));\n rpcSetBtn.style.display = \"none\";\n rpcDefaultBtn.style.display = \"none\";\n rpcHint.style.display = \"none\";\n }\n }\n var activityBar = document.getElementById(\"activityBar\");\n var activityText = document.getElementById(\"activityText\");\n var VERBS = { skill: [\"Casting\", \"Channeling\", \"Wielding\", \"Invoking\"] };\n function flashSkill(name, mint) {\n const v = VERBS.skill[S.pick++ % VERBS.skill.length];\n activityText.innerHTML = '' + v + \" \" + (name ? '' + escapeHtml(name) + \"\" : \"\");\n activityBar.classList.remove(\"out\");\n activityBar.style.display = \"flex\";\n clearTimeout(S.actTimer);\n const dwell = Math.min(4e3, 1600 + (name || \"\").length * 35);\n S.actTimer = setTimeout(() => {\n activityBar.classList.add(\"out\");\n setTimeout(() => {\n activityBar.style.display = \"none\";\n activityBar.classList.remove(\"out\");\n }, 250);\n }, dwell);\n lightSkillSlot(name, mint, dwell);\n }\n function lightSkillSlot(name, mint, dwell) {\n const grid = document.getElementById(\"skillGrid\");\n const panel = document.getElementById(\"skillsPanel\");\n const btn = document.getElementById(\"skillsBtn\");\n const clear = () => {\n grid.querySelectorAll(\".an-sd.is-firing\").forEach((s) => s.classList.remove(\"is-firing\"));\n panel.classList.remove(\"casting\");\n btn.classList.remove(\"casting\");\n };\n clear();\n grid.querySelectorAll(\".an-sd\").forEach((s) => {\n if (mint && s.getAttribute(\"data-mint\") === mint || s.getAttribute(\"data-skill\") === name) s.classList.add(\"is-firing\");\n });\n panel.classList.add(\"casting\");\n btn.classList.add(\"casting\");\n clearTimeout(S.firingTimer);\n S.firingTimer = setTimeout(clear, Math.max(dwell || 0, 1400));\n }\n function hideActivity() {\n clearTimeout(S.actTimer);\n activityBar.classList.remove(\"out\");\n activityBar.style.display = \"none\";\n }\n function wireOverlays() {\n celebrateEl.addEventListener(\"click\", () => {\n clearTimeout(S.celebTimer);\n celebrateEl.classList.remove(\"show\", \"out\");\n celebrateEl.innerHTML = \"\";\n });\n rpcSetBtn.addEventListener(\"click\", () => vscode.postMessage({ type: \"setHeliusKey\" }));\n rpcDefaultBtn.addEventListener(\"click\", () => vscode.postMessage({ type: \"useDefaultRpc\" }));\n vscode.postMessage({ type: \"getRpcStatus\" });\n }\n\n // src/chat/ui/panel/composer.ts\n function showTyping() {\n setBusy(true);\n if (S.typingEl) return;\n const node = document.createElement(\"div\");\n node.className = \"node typing\";\n node.innerHTML = '
' + S.cli + '
';\n tailBody().appendChild(node);\n stickToBottom();\n S.typingEl = node;\n }\n function hideTyping() {\n setBusy(false);\n if (S.typingEl) {\n S.typingEl.remove();\n S.typingEl = null;\n }\n }\n function setBusy(b) {\n if (S.busy === b) return;\n S.busy = b;\n const btn = document.getElementById(\"send\");\n if (!btn) return;\n const lbl = btn.querySelector(\".lbl\");\n if (lbl) lbl.textContent = b ? \"Stop\" : \"Send\";\n btn.title = b ? \"Stop\" : \"Send\";\n btn.setAttribute(\"aria-label\", b ? \"Stop\" : \"Send\");\n btn.classList.toggle(\"stopping\", b);\n }\n function interruptTurn() {\n vscode.postMessage({ type: \"interrupt\" });\n setBusy(false);\n hideTyping();\n }\n var sendBtn = document.getElementById(\"send\");\n function syncComposerLock() {\n const locked = approvalDock.childElementCount > 0;\n input.disabled = locked;\n if (sendBtn) sendBtn.disabled = locked;\n composer.classList.toggle(\"locked\", locked);\n input.placeholder = locked ? \"Answer the approval above to continue…\" : \"Message \" + (composer.dataset.cli || \"claude\") + \"... (Enter to send)\";\n }\n var attachStrip = document.getElementById(\"attachStrip\");\n var fileInput = document.getElementById(\"fileInput\");\n var attachBtn = document.getElementById(\"attachBtn\");\n var inputWrap = document.getElementById(\"inputWrap\");\n function renderAttachStrip() {\n attachStrip.innerHTML = \"\";\n attachStrip.style.display = S.attached.length ? \"flex\" : \"none\";\n S.attached.forEach((a, i) => {\n const t = document.createElement(\"div\");\n t.className = \"thumb\";\n const img = document.createElement(\"img\");\n img.src = a.dataUrl;\n img.alt = a.name || \"image\";\n const rm = document.createElement(\"button\");\n rm.className = \"rm\";\n rm.textContent = \"×\";\n rm.title = \"Remove\";\n rm.addEventListener(\"click\", () => {\n S.attached.splice(i, 1);\n renderAttachStrip();\n });\n t.appendChild(img);\n t.appendChild(rm);\n attachStrip.appendChild(t);\n });\n }\n function userImagesEl(info) {\n if (!info) return null;\n if (info.thumbs && info.thumbs.length) {\n const row = document.createElement(\"div\");\n row.className = \"msgImgs\";\n info.thumbs.forEach((u) => {\n const im = document.createElement(\"img\");\n im.src = u;\n row.appendChild(im);\n });\n return row;\n }\n if (info.count) {\n const chip = document.createElement(\"span\");\n chip.className = \"imgChip\";\n chip.innerHTML = '' + info.count + (info.count > 1 ? \" images\" : \" image\");\n return chip;\n }\n return null;\n }\n function addFiles(files) {\n for (const f of files) {\n if (!f.type || f.type.indexOf(\"image/\") !== 0) continue;\n const reader = new FileReader();\n reader.onload = () => {\n const dataUrl = String(reader.result || \"\");\n const comma = dataUrl.indexOf(\",\");\n if (comma < 0) return;\n S.attached.push({ dataUrl, mime: f.type, dataBase64: dataUrl.slice(comma + 1), name: f.name || \"pasted\" });\n renderAttachStrip();\n };\n reader.readAsDataURL(f);\n }\n }\n function send() {\n if (input.disabled) return;\n const text = input.value.trim();\n if (!text && !S.attached.length) return;\n if (text === \"/mockupskills\" || text.startsWith(\"/mockupskills \")) {\n const names = text.slice(\"/mockupskills\".length).trim().split(/\\s+/).filter(Boolean);\n setSkills(names);\n if (skillsPanel.style.display === \"none\") {\n skillsPanel.style.display = \"block\";\n skillsBtn.classList.add(\"on\");\n }\n input.value = \"\";\n return;\n }\n if (text === \"/mockskill\" || text.startsWith(\"/mockskill \")) {\n flashSkill(text.slice(\"/mockskill\".length).trim() || \"cleancode\", \"mock\");\n input.value = \"\";\n return;\n }\n if (text.startsWith(\"/\")) {\n const [cmd, ...rest] = text.slice(1).split(\" \");\n const arg = rest.join(\" \").trim();\n switch (cmd) {\n case \"login\": {\n const target = arg === \"claude\" || arg === \"codex\" ? arg : S.cli;\n if (target === \"claude\" && arg && arg !== \"claude\" && arg !== \"codex\") {\n vscode.postMessage({ type: \"claudeAuthCode\", code: arg });\n renderNotice(\"Submitted Claude sign-in code.\");\n } else {\n vscode.postMessage({ type: target === \"claude\" ? \"startClaudeLogin\" : \"startCodexLogin\" });\n renderNotice(\"Starting \" + (target === \"claude\" ? \"Claude\" : \"Codex\") + \" sign-in...\");\n }\n input.value = \"\";\n return;\n }\n case \"logout\": {\n const target = arg === \"claude\" || arg === \"codex\" ? arg : S.cli;\n vscode.postMessage({ type: \"logoutEngine\", cli: target });\n renderNotice(\"Signing out of \" + (target === \"claude\" ? \"Claude\" : \"Codex\") + \"...\");\n input.value = \"\";\n return;\n }\n case \"new\":\n vscode.postMessage({ type: \"new\" });\n input.value = \"\";\n return;\n case \"clear\":\n vscode.postMessage({ type: \"clear\" });\n input.value = \"\";\n return;\n case \"compact\":\n vscode.postMessage({ type: \"slashCommand\", command: \"compact\", arg });\n showTyping();\n input.value = \"\";\n return;\n case \"status\":\n vscode.postMessage({ type: \"slashCommand\", command: \"status\" });\n input.value = \"\";\n return;\n case \"resume\":\n vscode.postMessage({ type: \"slashCommand\", command: \"resume\" });\n input.value = \"\";\n return;\n case \"diff\":\n vscode.postMessage({ type: \"slashCommand\", command: \"diff\" });\n showTyping();\n input.value = \"\";\n return;\n case \"permissions\":\n if (arg) {\n modeByCli[S.cli] = arg;\n fillModes();\n vscode.postMessage({ type: \"mode\", mode: arg });\n } else vscode.postMessage({ type: \"slashCommand\", command: \"permissions\" });\n input.value = \"\";\n return;\n case \"init\":\n case \"skills\":\n case \"cost\":\n vscode.postMessage({ type: \"slashCommand\", command: cmd });\n input.value = \"\";\n return;\n case \"review\":\n case \"mcp\":\n vscode.postMessage({ type: \"slashCommand\", command: cmd, arg });\n showTyping();\n input.value = \"\";\n return;\n case \"copy\": {\n const last = Array.from(log.querySelectorAll(\".node.assistant .msg\")).pop();\n if (last && navigator.clipboard) navigator.clipboard.writeText(last.textContent || \"\").catch(() => {\n });\n input.value = \"\";\n return;\n }\n case \"engine\":\n if (arg === \"claude\" || arg === \"codex\") selectTab(arg);\n input.value = \"\";\n return;\n case \"model\":\n if (arg) {\n modelByCli[S.cli] = arg;\n fillModels();\n vscode.postMessage({ type: \"model\", model: arg });\n }\n input.value = \"\";\n return;\n case \"mode\":\n if (arg) {\n modeByCli[S.cli] = arg;\n fillModes();\n vscode.postMessage({ type: \"mode\", mode: arg });\n }\n input.value = \"\";\n return;\n case \"effort\":\n if (arg) {\n effortByCli[S.cli] = arg;\n fillModes();\n vscode.postMessage({ type: \"effort\", effort: arg === \"default\" ? void 0 : arg });\n }\n input.value = \"\";\n return;\n case \"help\": {\n const helpText = slashCommandsForCli().map(function(c) {\n return \"/\" + c.name + (c.args ? \" \" + c.args : \"\") + \" - \" + c.desc;\n }).join(\"\\n\");\n const pre = document.createElement(\"pre\");\n pre.style.cssText = \"margin:8px 0;padding:8px 12px;background:var(--an-bg-1);border-radius:6px;font-size:0.82em;opacity:0.8\";\n pre.textContent = helpText;\n log.appendChild(pre);\n syncWatermark();\n input.value = \"\";\n return;\n }\n default: {\n vscode.postMessage({ type: \"slashCommand\", command: cmd, arg });\n showTyping();\n input.value = \"\";\n return;\n }\n }\n }\n const activeStatus = S.cliReport && S.cliReport[S.cli];\n if (activeStatus === \"missing\") {\n renderEngineMissing(S.cli);\n return;\n }\n if (activeStatus === \"no-login\") {\n renderNotice((S.cli === \"claude\" ? \"Claude\" : \"Codex\") + \" is not signed in. Type /login to connect it.\");\n return;\n }\n const images = S.attached.map((a) => ({ mime: a.mime, dataBase64: a.dataBase64, name: a.name }));\n S.pendingSentImages = S.attached.map((a) => a.dataUrl);\n vscode.postMessage({ type: \"send\", text, images });\n S.attached = [];\n renderAttachStrip();\n input.value = \"\";\n input.style.height = \"auto\";\n showTyping();\n }\n function autoGrowInput() {\n if (S.growRaf) return;\n S.growRaf = requestAnimationFrame(() => {\n S.growRaf = 0;\n input.style.height = \"auto\";\n input.style.height = Math.min(input.scrollHeight, 220) + \"px\";\n });\n }\n function wireComposer() {\n attachBtn.addEventListener(\"click\", () => {\n if (!input.disabled) fileInput.click();\n });\n fileInput.addEventListener(\"change\", () => {\n addFiles(fileInput.files || []);\n fileInput.value = \"\";\n });\n input.addEventListener(\"paste\", (e) => {\n const items = e.clipboardData && e.clipboardData.items || [];\n const imgs = [];\n for (const it of items) {\n if (it.kind === \"file\" && it.type.indexOf(\"image/\") === 0) {\n const f = it.getAsFile();\n if (f) imgs.push(f);\n }\n }\n if (imgs.length) {\n e.preventDefault();\n addFiles(imgs);\n }\n });\n [\"dragenter\", \"dragover\"].forEach((ev) => inputWrap.addEventListener(ev, (e) => {\n if (e.dataTransfer && Array.from(e.dataTransfer.types || []).indexOf(\"Files\") >= 0) {\n e.preventDefault();\n inputWrap.classList.add(\"dragover\");\n }\n }));\n [\"dragleave\", \"drop\"].forEach((ev) => inputWrap.addEventListener(ev, (e) => {\n if (ev === \"drop\") {\n e.preventDefault();\n if (e.dataTransfer) addFiles(e.dataTransfer.files || []);\n }\n inputWrap.classList.remove(\"dragover\");\n }));\n document.getElementById(\"send\").addEventListener(\"click\", () => {\n S.busy ? interruptTurn() : send();\n });\n document.getElementById(\"newBtn\").addEventListener(\"click\", () => {\n vscode.postMessage({ type: \"new\" });\n closeMenus();\n });\n document.getElementById(\"newTabBtn\").addEventListener(\"click\", () => vscode.postMessage({ type: \"newTab\" }));\n input.addEventListener(\"keydown\", (e) => {\n if (e.isComposing || e.keyCode === 229) return;\n if (S.activeSlashMatches.length > 0) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n S.slashIdx = (S.slashIdx + 1) % S.activeSlashMatches.length;\n renderSlashMenu();\n return;\n }\n if (e.key === \"ArrowUp\") {\n e.preventDefault();\n S.slashIdx = (S.slashIdx - 1 + S.activeSlashMatches.length) % S.activeSlashMatches.length;\n renderSlashMenu();\n return;\n }\n if (e.key === \"Tab\" || e.key === \"Enter\") {\n e.preventDefault();\n if (S.activeSlashMatches[S.slashIdx]) {\n completeSlash(S.activeSlashMatches[S.slashIdx]);\n }\n return;\n }\n if (e.key === \"Escape\") {\n e.preventDefault();\n e.stopPropagation();\n S.suppressSlash = true;\n renderSlashMenu();\n return;\n }\n }\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n send();\n }\n if (e.key === \"Escape\" && S.busy) {\n e.preventDefault();\n interruptTurn();\n }\n });\n document.addEventListener(\"keydown\", (e) => {\n if (e.key === \"Escape\" && S.busy) {\n e.preventDefault();\n interruptTurn();\n }\n });\n input.addEventListener(\"input\", () => {\n autoGrowInput();\n S.suppressSlash = false;\n S.slashIdx = 0;\n renderSlashMenu();\n });\n }\n\n // src/chat/ui/panel/turns.ts\n function makeUtext(userText) {\n const wrap = document.createElement(\"div\");\n wrap.className = \"utextWrap\";\n const ut = document.createElement(\"div\");\n ut.className = \"utext\";\n ut.textContent = userText;\n wrap.appendChild(ut);\n const longMsg = userText.split(\"\\n\").length > 4 || userText.length > 280;\n if (longMsg) {\n wrap.classList.add(\"collapsed\");\n const tog = document.createElement(\"div\");\n tog.className = \"utextToggle\";\n tog.textContent = \"Show more\";\n tog.addEventListener(\"click\", () => {\n const exp = wrap.classList.toggle(\"expanded\");\n wrap.classList.toggle(\"collapsed\", !exp);\n tog.textContent = exp ? \"Show less\" : \"Show more\";\n });\n wrap.appendChild(tog);\n }\n return wrap;\n }\n function startTurn(userText, badgeCli, imageInfo) {\n const turn = document.createElement(\"div\");\n turn.className = \"turn\";\n const head = document.createElement(\"div\");\n head.className = \"turnHead\";\n head.innerHTML = '>';\n const ut = makeUtext(userText);\n head.appendChild(ut);\n if (badgeCli) {\n const b = document.createElement(\"span\");\n b.className = \"badge \" + badgeCli;\n b.textContent = badgeCli === \"codex\" ? \"codex · gpt\" : \"claude\";\n head.appendChild(b);\n }\n const imgEl = userImagesEl(imageInfo);\n if (imgEl) ut.insertBefore(imgEl, ut.querySelector(\".utextToggle\"));\n const body = document.createElement(\"div\");\n body.className = \"turnBody\";\n turn.appendChild(head);\n turn.appendChild(body);\n log.appendChild(turn);\n turn._body = body;\n S.tailTurn = turn;\n scrollToLatest();\n syncWatermark();\n return body;\n }\n function startTurnTop(userText, badgeCli) {\n const turn = document.createElement(\"div\");\n turn.className = \"turn\";\n const head = document.createElement(\"div\");\n head.className = \"turnHead\";\n head.innerHTML = '>';\n head.appendChild(makeUtext(userText));\n if (badgeCli) {\n const b = document.createElement(\"span\");\n b.className = \"badge \" + badgeCli;\n b.textContent = badgeCli === \"codex\" ? \"codex · gpt\" : \"claude\";\n head.appendChild(b);\n }\n const body = document.createElement(\"div\");\n body.className = \"turnBody\";\n turn.appendChild(head);\n turn.appendChild(body);\n log.insertBefore(turn, log.firstChild);\n turn._body = body;\n S.headTurn = turn;\n return body;\n }\n function tailBody() {\n if (S.tailTurn && S.tailTurn._body) return S.tailTurn._body;\n const turn = document.createElement(\"div\");\n turn.className = \"turn\";\n const body = document.createElement(\"div\");\n body.className = \"turnBody\";\n turn.appendChild(body);\n log.appendChild(turn);\n turn._body = body;\n S.tailTurn = turn;\n syncWatermark();\n return body;\n }\n function appendNode(el, dir) {\n const body = dir === \"head\" ? S.headTurn && S.headTurn._body || startTurnTop(\"\", void 0) : tailBody();\n body.appendChild(el);\n if (dir !== \"head\") stickToBottom();\n }\n function bubble(role, prepend, badgeCli) {\n const node = document.createElement(\"div\");\n node.className = \"node \" + role + (badgeCli ? \" \" + badgeCli : \"\");\n const el = document.createElement(\"div\");\n el.className = \"msg \" + role;\n node.appendChild(el);\n appendNode(node, prepend ? \"head\" : \"tail\");\n el._row = node;\n return el;\n }\n function clampBody(el, row, threshold) {\n if ((el.textContent || \"\").length <= threshold) return;\n el.classList.add(\"clamp\");\n const btn = document.createElement(\"button\");\n btn.className = \"moreBtn\";\n btn.textContent = \"show more\";\n btn.addEventListener(\"click\", () => {\n const on = el.classList.toggle(\"clamp\");\n btn.textContent = on ? \"show more\" : \"show less\";\n });\n row.appendChild(btn);\n }\n function renderSummary(text, prepend) {\n const node = document.createElement(\"div\");\n node.className = \"node summary\";\n const rule = document.createElement(\"div\");\n rule.className = \"compactRule\";\n rule.innerHTML = '
⌘ context compacted
';\n const body = document.createElement(\"div\");\n body.className = \"summaryBody\";\n body.textContent = text;\n node.appendChild(rule);\n node.appendChild(body);\n appendNode(node, prepend ? \"head\" : \"tail\");\n if (!prepend) clampBody(body, body, 400);\n }\n function addMsgCopy(row, el) {\n if (!row || row.querySelector(\":scope > .msgCopy\")) return;\n const btn = document.createElement(\"button\");\n btn.className = \"msgCopy\";\n btn.title = \"Copy message\";\n btn.innerHTML = COPY_ICON;\n btn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n copyText(el.dataset.md || el.textContent || \"\", () => {\n btn.classList.add(\"done\");\n btn.innerHTML = CHECK_ICON;\n setTimeout(() => {\n btn.classList.remove(\"done\");\n btn.innerHTML = COPY_ICON;\n }, 1200);\n });\n });\n row.appendChild(btn);\n }\n function addFooter(row, durationMs, model) {\n if (durationMs == null && !model) return;\n const f = document.createElement(\"div\");\n f.className = \"footer\";\n if (durationMs != null) {\n const s = durationMs / 1e3;\n f.appendChild(document.createTextNode(s < 60 ? s.toFixed(1) + \"s\" : Math.floor(s / 60) + \"m \" + Math.round(s % 60) + \"s\"));\n }\n if (model) {\n const m = document.createElement(\"span\");\n m.className = \"mdl\";\n m.textContent = model;\n f.appendChild(m);\n }\n row.appendChild(f);\n }\n function toolRow(prepend) {\n const row = document.createElement(\"div\");\n row.className = \"node tool\";\n appendNode(row, prepend ? \"head\" : \"tail\");\n return row;\n }\n var CHEV = '';\n function makeCollapsible(head, body, startOpen) {\n head.classList.add(\"clickable\");\n head.insertAdjacentHTML(\"afterbegin\", CHEV);\n const set = (open) => {\n head.classList.toggle(\"open\", open);\n body.hidden = !open;\n };\n set(startOpen);\n head.addEventListener(\"click\", () => set(body.hidden));\n }\n function setOutput(card, output, exitCode) {\n let out = card.querySelector(\".toolOut\");\n if (!out) {\n out = document.createElement(\"pre\");\n out.className = \"toolOut toolBody\";\n card.appendChild(out);\n makeCollapsible(card.querySelector(\".toolHead\"), out, false);\n }\n out.textContent = output;\n if (typeof exitCode === \"number\" && exitCode !== 0) card.classList.add(\"failed\");\n }\n function renderDiff(pre, diffText) {\n const lines = diffText.split(\"\\n\");\n const kind = lines.map((l) => l[0] === \"+\" ? \"add\" : l[0] === \"-\" ? \"del\" : \"ctx\");\n let added = 0, removed = 0;\n for (const k of kind) {\n if (k === \"add\") added++;\n else if (k === \"del\") removed++;\n }\n const CTX = 2;\n const keep = new Array(lines.length).fill(false);\n for (let i = 0; i < lines.length; i++) {\n if (kind[i] === \"ctx\") continue;\n for (let c = Math.max(0, i - CTX); c <= Math.min(lines.length - 1, i + CTX); c++) keep[c] = true;\n }\n let folding = false;\n for (let i = 0; i < lines.length; i++) {\n if (!keep[i]) {\n if (!folding) {\n folding = true;\n const f = document.createElement(\"div\");\n f.className = \"fold\";\n f.textContent = \"⋯\";\n pre.appendChild(f);\n }\n continue;\n }\n folding = false;\n const d = document.createElement(\"div\");\n d.className = kind[i];\n const sign = kind[i] === \"add\" ? \"+\" : kind[i] === \"del\" ? \"−\" : \"\";\n const text = lines[i].replace(/^[+\\-]/, \"\");\n d.innerHTML = '' + sign + \"\";\n d.appendChild(document.createTextNode(text || \" \"));\n pre.appendChild(d);\n }\n return { added, removed };\n }\n function renderToolInto(row, msg) {\n const t = msg.tool || {};\n if (t.command !== void 0) {\n const card = document.createElement(\"div\");\n card.className = \"toolCard bash\";\n const head = document.createElement(\"div\");\n head.className = \"toolHead\";\n head.innerHTML = '$';\n const cmd = document.createElement(\"span\");\n cmd.className = \"cmd\";\n cmd.textContent = t.command;\n head.appendChild(cmd);\n card.appendChild(head);\n if (t.output) setOutput(card, t.output, t.exitCode);\n row.appendChild(card);\n return t.output ? null : card;\n } else if (t.diff !== void 0) {\n const card = document.createElement(\"div\");\n card.className = \"toolCard diff\";\n const head = document.createElement(\"div\");\n head.className = \"toolHead\";\n head.innerHTML = '✎';\n const fn = document.createElement(\"span\");\n fn.className = \"file\";\n fn.textContent = t.file || \"edit\";\n head.appendChild(fn);\n card.appendChild(head);\n const pre = document.createElement(\"pre\");\n pre.className = \"diffBody toolBody\";\n const { added, removed } = renderDiff(pre, t.diff);\n const stat = document.createElement(\"span\");\n stat.className = \"stat\";\n stat.innerHTML = '+' + added + '−' + removed + \"\";\n head.appendChild(stat);\n card.appendChild(pre);\n makeCollapsible(head, pre, true);\n row.appendChild(card);\n } else {\n const card = document.createElement(\"div\");\n card.className = \"toolCard op\";\n const icon = t.name === \"Read\" ? '' : t.name === \"Write\" ? \"✎\" : \"•\";\n card.innerHTML = '' + icon + \"\";\n card.appendChild(document.createTextNode(msg.text || t.name || \"tool\"));\n row.appendChild(card);\n }\n return null;\n }\n function renderTool(msg, prepend) {\n const t = msg.tool || {};\n if (t.command === void 0 && t.diff === void 0 && t.output && S.openBash && !prepend) {\n setOutput(S.openBash, t.output, t.exitCode);\n S.openBash = null;\n return;\n }\n const row = toolRow(prepend);\n const awaiting = renderToolInto(row, msg);\n if (awaiting) S.openBash = awaiting;\n if (!prepend) {\n if (S.typingEl) tailBody().appendChild(S.typingEl);\n stickToBottom();\n }\n }\n\n // src/chat/ui/panel/shell.ts\n function syncWatermark() {\n mainEl.classList.toggle(\"hasMsgs\", log.childElementCount > 0);\n }\n function renderNotice(text) {\n const notice = document.createElement(\"div\");\n notice.style.cssText = \"padding:4px 12px;font-size:0.82em;opacity:0.65;white-space:pre-wrap\";\n notice.textContent = text;\n log.appendChild(notice);\n syncWatermark();\n stickToBottom();\n }\n function renderActionNotice(text, actions) {\n const notice = document.createElement(\"div\");\n notice.style.cssText = \"padding:4px 12px;font-size:0.82em;white-space:pre-wrap\";\n const body = document.createElement(\"div\");\n body.style.opacity = \"0.65\";\n body.textContent = text;\n const row = document.createElement(\"div\");\n row.style.cssText = \"display:flex;gap:6px;margin-top:6px\";\n for (const a of actions) {\n const btn = document.createElement(\"button\");\n btn.textContent = a[0];\n btn.style.cssText = \"padding:3px 10px;font-size:1em\";\n btn.addEventListener(\"click\", () => a[1](btn));\n row.appendChild(btn);\n }\n notice.appendChild(body);\n notice.appendChild(row);\n log.appendChild(notice);\n syncWatermark();\n stickToBottom();\n }\n function copyAction(command) {\n return [\"Copy command\", (btn) => {\n if (navigator.clipboard) navigator.clipboard.writeText(command).catch(() => {\n });\n btn.textContent = \"Copied\";\n }];\n }\n function renderEngineBanner(text, actions, dismissKey) {\n engineBanner.innerHTML = \"\";\n const body = document.createElement(\"div\");\n body.className = \"eb-body\";\n body.textContent = text;\n const row = document.createElement(\"div\");\n row.className = \"eb-actions\";\n for (const a of actions) {\n const btn = document.createElement(\"button\");\n btn.className = \"eb-btn\";\n btn.textContent = a[0];\n btn.addEventListener(\"click\", () => a[1](btn));\n row.appendChild(btn);\n }\n const close = document.createElement(\"button\");\n close.className = \"eb-close\";\n close.setAttribute(\"aria-label\", \"Dismiss\");\n close.textContent = \"×\";\n close.addEventListener(\"click\", () => {\n engineBanner.style.display = \"none\";\n engineBanner.innerHTML = \"\";\n vscode.postMessage({ type: \"dismissEngineUpdate\", cli: dismissKey });\n });\n engineBanner.appendChild(body);\n engineBanner.appendChild(row);\n engineBanner.appendChild(close);\n engineBanner.style.display = \"flex\";\n }\n function renderEngineMissing(which) {\n if (S.cliReport?.[which] === \"node-missing\") {\n renderActionNotice(NODE_REQUIRED_MESSAGE, [\n [\"Get Node.js\", () => window.open(NODE_DOWNLOAD_URL, \"_blank\", \"noopener,noreferrer\")],\n [\"Check again\", () => vscode.postMessage({ type: \"getCliStatus\" })]\n ]);\n return;\n }\n const name = which === \"claude\" ? \"Claude\" : \"Codex\";\n const command = ENGINE_INSTALL_COMMAND[which];\n renderActionNotice(\n name + \" is not installed. Install it, then sign in with /login.\\n$ \" + command,\n [\n [\"Install in terminal\", () => vscode.postMessage({ type: \"installEngine\", cli: which })],\n copyAction(command)\n ]\n );\n }\n function renderStatus(status) {\n const ctx = typeof status.contextTokens === \"number\" ? status.contextTokens >= 1e3 ? Math.round(status.contextTokens / 1e3) + \"k\" : String(status.contextTokens) : \"unknown\";\n const text = [\n \"engine: \" + status.cli,\n \"session: \" + (status.sessionId || \"(none)\"),\n \"model: \" + (status.model || \"default\"),\n \"mode: \" + (status.mode || \"default\"),\n \"effort: \" + (status.effort || \"default\"),\n \"context tokens: \" + ctx\n ].join(\"\\n\");\n const pre = document.createElement(\"pre\");\n pre.style.cssText = \"margin:8px 0;padding:8px 12px;background:var(--an-bg-1);border-radius:6px;font-size:0.82em;opacity:0.85;white-space:pre-wrap\";\n pre.textContent = text;\n log.appendChild(pre);\n syncWatermark();\n stickToBottom();\n }\n var LIMIT_WINDOW_LABEL = {\n five_hour: \"5-hour\",\n seven_day: \"weekly\",\n seven_day_opus: \"weekly Opus\",\n seven_day_sonnet: \"weekly Sonnet\",\n overage: \"overage\"\n };\n var ctxLabel = null;\n var usageByCli = { claude: null, codex: null };\n var usageExpanded = false;\n function renderLimitMeter(info) {\n const pct = typeof info.utilization === \"number\" ? info.utilization : usageByCli[info.cli]?.pct;\n if (pct === void 0) return;\n const warn = pct >= 80 || info.status === \"rejected\" || info.status === \"allowed_warning\";\n const windowLabel = LIMIT_WINDOW_LABEL[info.window || \"\"] || \"usage\";\n let resets = \"\";\n if (typeof info.resetsAt === \"number\" && info.resetsAt > 0) {\n resets = \" · resets \" + new Date(info.resetsAt).toLocaleTimeString([], { hour: \"2-digit\", minute: \"2-digit\" });\n }\n usageByCli[info.cli] = { pct, warn, title: \"Used \" + Math.round(pct) + \"% of your \" + windowLabel + \" limit\" + resets };\n paintMeters();\n }\n function setCtxTokens(contextTokens) {\n if (typeof contextTokens !== \"number\") return;\n ctxLabel = contextTokens >= 1e3 ? Math.round(contextTokens / 1e3) + \"k\" : String(contextTokens);\n paintMeters();\n }\n function clearCtx() {\n ctxLabel = null;\n usageExpanded = false;\n paintMeters();\n }\n function paintMeters() {\n const usage = usageByCli[S.cli];\n if (usage) {\n const fill = limitMeter.querySelector(\".lm-fill\");\n const pct = limitMeter.querySelector(\".lm-pct\");\n if (fill) fill.style.width = usage.pct + \"%\";\n if (pct) pct.textContent = Math.round(usage.pct) + \"%\";\n limitMeter.classList.toggle(\"warn\", usage.warn);\n limitMeter.title = usage.title + \" · click to show context tokens\";\n limitMeter.style.display = \"inline-flex\";\n } else {\n limitMeter.style.display = \"none\";\n }\n if (ctxLabel !== null && (usageExpanded || !usage)) {\n ctxMeter.textContent = \"ctx: \" + ctxLabel;\n ctxMeter.style.display = \"inline-flex\";\n } else {\n ctxMeter.style.display = \"none\";\n }\n }\n function nearBottom() {\n const d = log.scrollHeight - log.scrollTop - log.clientHeight;\n return d <= Math.max(180, log.clientHeight * 0.25);\n }\n function toBottomInstant() {\n const prev = log.style.scrollBehavior;\n log.style.scrollBehavior = \"auto\";\n log.scrollTop = log.scrollHeight;\n log.style.scrollBehavior = prev;\n }\n function updateJump() {\n if (!jumpBtn) return;\n if (S.stick) S.hasNew = false;\n jumpBtn.classList.toggle(\"show\", !S.stick);\n jumpBtn.classList.toggle(\"hasNew\", S.hasNew);\n }\n function stickToBottom() {\n if (S.stick) toBottomInstant();\n else S.hasNew = true;\n updateJump();\n }\n function scrollToLatest() {\n S.stick = true;\n S.hasNew = false;\n toBottomInstant();\n updateJump();\n }\n function showLoading() {\n loadingEl.style.display = \"flex\";\n }\n function hideLoading() {\n loadingEl.style.display = \"none\";\n }\n var STREAM_MD_MS = 300;\n function flushStreamRender() {\n S.streamRaf = 0;\n if (!S.streaming) return;\n S.lastStreamRender = Date.now();\n const raw = S.streaming.dataset.acc || \"\";\n if (S.streaming.dataset.role === \"assistant\") renderMdStreaming(S.streaming, raw);\n else {\n S.streaming.textContent = raw;\n S.streaming.dataset.md = raw;\n }\n if (S.typingEl) tailBody().appendChild(S.typingEl);\n stickToBottom();\n }\n function scheduleStreamRender() {\n if (S.streamRaf || S.streamTimer) return;\n const wait = STREAM_MD_MS - (Date.now() - S.lastStreamRender);\n if (wait <= 0) S.streamRaf = requestAnimationFrame(flushStreamRender);\n else S.streamTimer = setTimeout(() => {\n S.streamTimer = 0;\n if (!S.streamRaf) S.streamRaf = requestAnimationFrame(flushStreamRender);\n }, wait);\n }\n function cancelStreamRender() {\n if (S.streamRaf) {\n cancelAnimationFrame(S.streamRaf);\n S.streamRaf = 0;\n }\n if (S.streamTimer) {\n clearTimeout(S.streamTimer);\n S.streamTimer = 0;\n }\n }\n function wireShell() {\n if (jumpBtn) jumpBtn.addEventListener(\"click\", scrollToLatest);\n limitMeter.style.cursor = \"pointer\";\n limitMeter.addEventListener(\"click\", () => {\n usageExpanded = !usageExpanded;\n paintMeters();\n });\n }\n\n // src/chat/ui/panel/approval.ts\n function dismissApproval(id) {\n const cards = approvalDock.querySelectorAll(\"[data-approval-id]\");\n for (const c of cards) {\n if (c.dataset.approvalId === id) {\n c.remove();\n syncComposerLock();\n break;\n }\n }\n }\n function renderApproval(req) {\n const card = document.createElement(\"div\");\n card.className = \"approvalCard\";\n card.dataset.approvalId = req.id;\n const isPublish = /publish_skill/.test(req.tool || \"\") || /publish_skill/.test(req.title || \"\");\n const isBuy = /buy_skill/.test(req.tool || \"\") || /buy_skill/.test(req.title || \"\");\n const isForge = isPublish || isBuy;\n if (isForge) {\n card.classList.add(\"skillForge\");\n if (isBuy) card.classList.add(\"buyForge\");\n const stars = document.createElement(\"div\");\n stars.className = \"forgeStars\";\n for (let i = 0; i < 6; i++) {\n const s = document.createElement(\"span\");\n s.className = \"st\";\n s.innerHTML = '';\n s.style.left = 8 + Math.random() * 84 + \"%\";\n s.style.top = 12 + Math.random() * 70 + \"%\";\n s.style.animationDuration = 3.2 + Math.random() * 2.4 + \"s\";\n s.style.animationDelay = Math.random() * 3 + \"s\";\n s.style.fontSize = 7 + Math.random() * 5 + \"px\";\n stars.appendChild(s);\n }\n card.appendChild(stars);\n }\n if (req.kind === \"question\" && Array.isArray(req.questions) && req.questions.length) {\n const sel = {};\n const free = {};\n const total = req.questions.length;\n let step = 0;\n const hasAnswer = (qi) => {\n const typed = (free[qi] || \"\").trim();\n return typed.length > 0 || !!(sel[qi] && sel[qi].length);\n };\n const sendAll = () => {\n const questionResponses = req.questions.map((q, qi) => {\n const typed = (free[qi] || \"\").trim();\n return {\n question: q.question,\n questionId: q.id,\n selected: typed ? [] : sel[qi] || [],\n ...typed ? { text: typed } : {}\n };\n });\n vscode.postMessage({ type: \"approvalDecision\", id: req.id, outcome: \"once\", questionResponses });\n card.remove();\n syncComposerLock();\n };\n const renderStep = () => {\n card.innerHTML = \"\";\n const q = req.questions[step];\n let updateNext = () => {\n };\n let otherInput = null;\n if (total > 1) {\n const counter = document.createElement(\"div\");\n counter.className = \"qCount\";\n counter.textContent = step + 1 + \" / \" + total;\n card.appendChild(counter);\n }\n const block = document.createElement(\"div\");\n block.className = \"qBlock\";\n if (q.header) {\n const h = document.createElement(\"span\");\n h.className = \"qHeader\";\n h.textContent = q.header;\n block.appendChild(h);\n }\n const qt = document.createElement(\"div\");\n qt.className = \"qText\";\n qt.textContent = q.question;\n block.appendChild(qt);\n const opts = document.createElement(\"div\");\n opts.className = \"qOpts\";\n (q.options || []).forEach((opt) => {\n const b = document.createElement(\"button\");\n b.type = \"button\";\n b.className = \"qOpt\";\n if ((sel[step] || []).indexOf(opt.label) >= 0) b.classList.add(\"on\");\n const t = document.createElement(\"div\");\n t.className = \"qOptLabel\";\n t.textContent = opt.label;\n b.appendChild(t);\n if (opt.description) {\n const d = document.createElement(\"div\");\n d.className = \"qOptDesc\";\n d.textContent = opt.description;\n b.appendChild(d);\n }\n b.addEventListener(\"click\", () => {\n const cur = sel[step] || [];\n delete free[step];\n if (q.multiSelect) {\n sel[step] = cur.indexOf(opt.label) >= 0 ? cur.filter((l) => l !== opt.label) : cur.concat(opt.label);\n } else {\n sel[step] = cur[0] === opt.label ? [] : [opt.label];\n }\n Array.from(opts.children).forEach((c, i) => c.classList.toggle(\"on\", (sel[step] || []).indexOf((q.options[i] || {}).label) >= 0));\n if (otherInput) otherInput.value = \"\";\n updateNext();\n });\n opts.appendChild(b);\n });\n block.appendChild(opts);\n if (q.allowCustomInput) {\n const label = document.createElement(\"div\");\n label.className = \"qOtherLabel\";\n label.textContent = q.options && q.options.length ? \"Or type your own answer\" : \"Type your answer\";\n block.appendChild(label);\n otherInput = q.secret ? document.createElement(\"input\") : document.createElement(\"textarea\");\n otherInput.className = \"qOtherInput\";\n otherInput.placeholder = \"Type your answer…\";\n if (q.secret) otherInput.type = \"password\";\n else otherInput.rows = 3;\n if (free[step]) otherInput.value = free[step];\n otherInput.addEventListener(\"input\", () => {\n free[step] = otherInput.value;\n sel[step] = [];\n Array.from(opts.children).forEach((c) => c.classList.remove(\"on\"));\n updateNext();\n });\n block.appendChild(otherInput);\n }\n card.appendChild(block);\n const actions2 = document.createElement(\"div\");\n actions2.className = \"apActions\";\n if (step > 0) {\n const back = document.createElement(\"button\");\n back.className = \"apBtn always\";\n back.textContent = \"Back\";\n back.addEventListener(\"click\", () => {\n step -= 1;\n renderStep();\n });\n actions2.appendChild(back);\n }\n const next = document.createElement(\"button\");\n next.className = \"apBtn ok\";\n const last = step === total - 1;\n next.textContent = last ? \"Send\" : \"Next\";\n next.addEventListener(\"click\", () => {\n if (!hasAnswer(step)) return;\n if (last) sendAll();\n else {\n step += 1;\n renderStep();\n }\n });\n actions2.appendChild(next);\n card.appendChild(actions2);\n updateNext = () => {\n next.disabled = !hasAnswer(step);\n };\n updateNext();\n };\n renderStep();\n approvalDock.insertBefore(card, approvalDock.firstChild);\n syncComposerLock();\n return;\n }\n const isPlan = req.kind === \"plan\";\n const isDanger = req.risk === \"danger\";\n const head = document.createElement(\"div\");\n head.className = \"apHead\" + (isDanger ? \" apDanger\" : \"\");\n const glyphEl = document.createElement(\"span\");\n glyphEl.className = \"apk\";\n var skSvg = '';\n var rdSvg = '';\n glyphEl.innerHTML = req.kind === \"bash\" ? \"$\" : req.kind === \"read\" ? rdSvg : isPlan ? skSvg : isForge ? skSvg : \"✎\";\n head.appendChild(glyphEl);\n if (isDanger) {\n const warn = document.createElement(\"span\");\n warn.style.cssText = \"color:var(--vscode-errorForeground,#f44);font-weight:700;margin-right:4px\";\n warn.innerHTML = ' DANGER ·';\n head.appendChild(warn);\n }\n const ttl = document.createElement(\"span\");\n ttl.className = \"apTitle\";\n ttl.textContent = isPublish ? \"Forge skill: \" + (req.input && req.input.name || \"new skill\") : isBuy ? \"Buy skill\" + (req.input && req.input.name ? \": \" + req.input.name : \"\") : req.title || req.tool;\n head.appendChild(ttl);\n const tag = document.createElement(\"span\");\n tag.className = \"apTag\";\n tag.textContent = req.cli;\n head.appendChild(tag);\n card.appendChild(head);\n let commandInput = null;\n if (req.command) {\n const pre = document.createElement(\"pre\");\n pre.className = \"apBody\";\n pre.textContent = req.command;\n card.appendChild(pre);\n if (req.kind === \"bash\") {\n commandInput = document.createElement(\"textarea\");\n commandInput.className = \"apBody\";\n commandInput.style.cssText = \"display:none;width:100%;box-sizing:border-box;resize:vertical;font-family:monospace;font-size:0.85em;background:var(--an-bg-1);border:1px solid var(--eng);border-radius:4px;padding:6px;color:inherit\";\n commandInput.value = req.command;\n card.appendChild(commandInput);\n const PENCIL_SVG = '';\n const XMARK_SVG = '';\n const editBtn = document.createElement(\"button\");\n editBtn.className = \"apEdit\";\n editBtn.innerHTML = PENCIL_SVG;\n editBtn.title = \"Edit\";\n editBtn.setAttribute(\"aria-label\", \"Edit\");\n editBtn.addEventListener(\"click\", () => {\n const editing = commandInput.style.display !== \"none\";\n pre.style.display = editing ? \"\" : \"none\";\n commandInput.style.display = editing ? \"none\" : \"\";\n editBtn.innerHTML = editing ? PENCIL_SVG : XMARK_SVG;\n editBtn.title = editing ? \"Edit\" : \"Cancel\";\n });\n head.appendChild(editBtn);\n }\n } else if (req.plan) {\n const pre = document.createElement(\"pre\");\n pre.className = \"apBody planBody\";\n pre.textContent = req.plan;\n card.appendChild(pre);\n } else if (req.diff) {\n const pre = document.createElement(\"pre\");\n pre.className = \"apBody diffBody\";\n for (const ln of String(req.diff).split(\"\\n\")) {\n const d = document.createElement(\"div\");\n d.className = ln[0] === \"+\" ? \"add\" : ln[0] === \"-\" ? \"del\" : \"ctx\";\n d.textContent = ln;\n pre.appendChild(d);\n }\n card.appendChild(pre);\n } else if (req.file) {\n const f = document.createElement(\"div\");\n f.className = \"apBody\";\n f.textContent = req.file;\n card.appendChild(f);\n } else if (isPublish && req.input) {\n const box = document.createElement(\"div\");\n box.className = \"apBody forgeBody\";\n const nm = document.createElement(\"div\");\n nm.style.cssText = \"font-weight:600;font-size:1.02em\";\n nm.textContent = req.input.name || \"new skill\";\n box.appendChild(nm);\n if (req.input.description) {\n const d = document.createElement(\"div\");\n d.style.cssText = \"opacity:0.85;font-size:0.85em;margin-top:2px\";\n d.textContent = req.input.description;\n box.appendChild(d);\n }\n const priceSol = req.input.priceSol;\n const priceTxt = priceSol == null ? \"0.1 SOL\" : String(priceSol) === \"0\" ? \"free\" : priceSol + \" SOL\";\n const meta = document.createElement(\"div\");\n meta.style.cssText = \"margin-top:5px;font-size:0.8em;opacity:0.7\";\n meta.textContent = \"mint a soulbound NFT · price \" + priceTxt;\n box.appendChild(meta);\n card.appendChild(box);\n }\n const actions = document.createElement(\"div\");\n actions.className = \"apActions\";\n const decide = (outcome, extra) => {\n vscode.postMessage({ type: \"approvalDecision\", id: req.id, outcome, ...extra });\n card.remove();\n syncComposerLock();\n };\n const mk = (label, outcome, cls) => {\n const b = document.createElement(\"button\");\n b.className = \"apBtn \" + cls;\n b.textContent = label;\n b.addEventListener(\"click\", () => decide(outcome));\n return b;\n };\n if (isPlan) {\n actions.appendChild(mk(\"Approve plan\", \"once\", \"ok\"));\n actions.appendChild(mk(\"Keep planning\", \"deny\", \"no\"));\n } else {\n actions.appendChild(mk(\"Approve\", \"once\", \"ok\"));\n actions.appendChild(mk(\"Always\", \"always\", \"always\"));\n let approveEdited = null;\n if (req.kind === \"bash\" && commandInput) {\n approveEdited = document.createElement(\"button\");\n approveEdited.className = \"apBtn ok\";\n approveEdited.textContent = \"Approve edited\";\n approveEdited.style.display = \"none\";\n approveEdited.addEventListener(\"click\", () => {\n decide(\"once\", { updatedInput: { ...req.input ?? {}, command: commandInput.value } });\n });\n actions.appendChild(approveEdited);\n const editToggle = head.querySelector(\"button\");\n if (editToggle) {\n editToggle.addEventListener(\"click\", () => {\n const isEditing = commandInput.style.display !== \"none\";\n if (approveEdited) approveEdited.style.display = isEditing ? \"\" : \"none\";\n });\n }\n }\n const reasonRow = document.createElement(\"div\");\n reasonRow.style.cssText = \"display:none;gap:6px;margin-top:4px;align-items:center;flex-wrap:wrap\";\n const reasonInput = document.createElement(\"input\");\n reasonInput.type = \"text\";\n reasonInput.placeholder = \"Reason for denying (optional)\";\n reasonInput.style.cssText = \"flex:1;min-width:120px;background:var(--an-bg-1);border:1px solid var(--an-line);border-radius:4px;padding:4px 8px;font-size:0.82em;color:inherit;outline:none\";\n const confirmDeny = document.createElement(\"button\");\n confirmDeny.className = \"apBtn no\";\n confirmDeny.textContent = \"Deny\";\n confirmDeny.addEventListener(\"click\", () => decide(\"deny\", { reason: reasonInput.value.trim() || void 0 }));\n const cancelDeny = document.createElement(\"button\");\n cancelDeny.className = \"apBtn\";\n cancelDeny.textContent = \"↩\";\n cancelDeny.style.cssText = \"opacity:0.6\";\n cancelDeny.addEventListener(\"click\", () => {\n reasonRow.style.display = \"none\";\n });\n reasonRow.appendChild(reasonInput);\n reasonRow.appendChild(confirmDeny);\n reasonRow.appendChild(cancelDeny);\n const denyBtn = document.createElement(\"button\");\n denyBtn.className = \"apBtn no\";\n denyBtn.textContent = \"Deny\";\n denyBtn.addEventListener(\"click\", () => {\n reasonRow.style.display = \"flex\";\n reasonInput.focus();\n });\n actions.appendChild(denyBtn);\n card.appendChild(actions);\n card.appendChild(reasonRow);\n }\n if (isPlan) card.appendChild(actions);\n card.addEventListener(\"keydown\", (e) => {\n const btnsAll = Array.from(actions.querySelectorAll(\"button\"));\n const i = btnsAll.indexOf(document.activeElement);\n if (i < 0) return;\n if (e.key === \"ArrowRight\") {\n e.preventDefault();\n btnsAll[(i + 1) % btnsAll.length].focus();\n } else if (e.key === \"ArrowLeft\") {\n e.preventDefault();\n btnsAll[(i + btnsAll.length - 1) % btnsAll.length].focus();\n }\n });\n approvalDock.insertBefore(card, approvalDock.firstChild);\n syncComposerLock();\n if (document.hasFocus()) {\n const first = actions.querySelector(\"button\");\n if (first) first.focus();\n }\n }\n\n // src/chat/ui/panel/messages.ts\n function onMessage(msg) {\n if (msg.role === \"user\") {\n const info = S.pendingSentImages.length ? { thumbs: S.pendingSentImages.splice(0) } : msg.imageCount ? { count: msg.imageCount } : void 0;\n const body = startTurn(msg.text, void 0, info);\n if (S.typingEl) body.appendChild(S.typingEl);\n return;\n }\n if (msg.role === \"tool\") {\n renderTool(msg, false);\n return;\n }\n if (msg.role === \"summary\") {\n renderSummary(msg.text, false);\n return;\n }\n const badge = msg.role === \"assistant\" && msg.cli ? msg.cli : void 0;\n const asMd = (el, raw) => {\n if (msg.role === \"assistant\") renderMd(el, raw);\n else {\n el.textContent = raw;\n el.dataset.md = raw;\n }\n };\n if (msg.partial) {\n if (!S.streaming || S.streaming.dataset.role !== msg.role) {\n S.streaming = bubble(msg.role, false, badge);\n S.streaming.dataset.role = msg.role;\n S.streaming.dataset.acc = \"\";\n S.streaming.classList.add(\"cursor\");\n }\n S.streaming.dataset.acc = msg.text;\n scheduleStreamRender();\n return;\n } else {\n if (S.streaming && S.streaming.dataset.role === msg.role) {\n const prev = S.streaming.dataset.acc || \"\";\n const raw = msg.text.startsWith(prev) ? msg.text : prev + msg.text;\n S.streaming.classList.remove(\"cursor\");\n cancelStreamRender();\n asMd(S.streaming, raw);\n if (msg.role === \"assistant\") addMsgCopy(S.streaming._row, S.streaming);\n S.streaming = null;\n } else {\n const el = bubble(msg.role, false, badge);\n asMd(el, msg.text);\n if (msg.role === \"assistant\") {\n addFooter(el._row, msg.durationMs, msg.model);\n addMsgCopy(el._row, el);\n }\n }\n }\n if (S.typingEl) tailBody().appendChild(S.typingEl);\n stickToBottom();\n }\n\n // src/chat/ui/panel/sessions.ts\n var COLLAPSED = 5;\n function renderSessions() {\n sessList.innerHTML = \"\";\n if (S.cloudListState === \"reauth\" || S.cloudListState === \"transient\") {\n const warn = document.createElement(\"div\");\n warn.style.cssText = \"padding:4px 8px;font-size:11px;color:var(--vscode-editorWarning-foreground, #e5c07b);opacity:.9\";\n warn.textContent = S.cloudListState === \"reauth\" ? \"Cloud sync signed out. Showing this device only. Reconnect in Storage.\" : \"Cloud unreachable. Showing this device only.\";\n sessList.appendChild(warn);\n }\n emptyEl.style.display = S.allSessions.length ? \"none\" : \"block\";\n const shown = S.expanded ? S.allSessions : S.allSessions.slice(0, COLLAPSED);\n for (const s of shown) {\n const el = document.createElement(\"div\");\n el.className = \"sess\" + (s.sessionId === S.activeId ? \" active\" : \"\");\n const title = document.createElement(\"span\");\n title.className = \"title\";\n title.textContent = s.title || \"(untitled)\";\n const time = document.createElement(\"span\");\n time.className = \"time\";\n time.textContent = rel(s.ts);\n const del = document.createElement(\"span\");\n del.className = \"del\";\n del.textContent = \"✕\";\n del.title = \"Delete session\";\n del.onclick = (e) => {\n e.stopPropagation();\n vscode.postMessage({ type: \"delete\", sessionId: s.sessionId });\n };\n el.appendChild(title);\n el.appendChild(time);\n el.appendChild(del);\n el.onclick = () => {\n vscode.postMessage({ type: \"open\", sessionId: s.sessionId });\n closeMenus();\n };\n sessList.appendChild(el);\n }\n if (S.allSessions.length > COLLAPSED) {\n showAll.style.display = \"block\";\n showAll.textContent = S.expanded ? \"접기\" : \"모두 보기(\" + S.allSessions.length + \")\";\n } else {\n showAll.style.display = \"none\";\n }\n }\n function wireSessions() {\n showAll.addEventListener(\"click\", () => {\n S.expanded = !S.expanded;\n renderSessions();\n });\n }\n\n // src/chat/ui/panel/storage.ts\n var cloudState = document.getElementById(\"cloudState\");\n var cloudBtn = document.getElementById(\"cloudBtn\");\n function renderStorage(info, options) {\n S.storageOptions = options || S.storageOptions;\n S.cloudConnected = !!(info && info.connected);\n if (info && info.kind) S.cloudKind = info.kind;\n if (S.cloudConnected) {\n const label = info.kind === \"gdrive\" ? \"Google Drive\" : info.kind === \"icloud\" ? \"iCloud\" : info.kind === \"custom\" ? \"Cloud\" : info.kind;\n const linkable = info.kind === \"gdrive\";\n const acct = info.account ? ' (' + info.account + \")\" : \"\";\n cloudState.innerHTML = '●' + (linkable ? '' + label + \"\" : label) + acct;\n const link = document.getElementById(\"cloudLink\");\n if (link) link.addEventListener(\"click\", (e) => {\n e.preventDefault();\n vscode.postMessage({ type: \"openCloud\", kind: info.kind });\n });\n cloudBtn.textContent = \"disconnect\";\n } else {\n cloudState.innerHTML = '●No cloud';\n cloudBtn.textContent = \"connect\";\n }\n }\n function wireStorage() {\n cloudBtn.addEventListener(\"click\", () => {\n if (S.cloudConnected) {\n vscode.postMessage({ type: \"disconnectCloud\" });\n return;\n }\n vscode.postMessage({ type: \"pickCloud\" });\n });\n }\n\n // src/chat/ui/panel/profile.ts\n function renderAgentIdCard(profile) {\n const el = document.getElementById(\"agentIdCard\");\n if (!el) return;\n const wallet = profile.wallet;\n const rep = profile.reputation || {};\n const repoStars = (profile.verifiedRepos || []).reduce((s, r) => s + (r.stars || 0), 0);\n const ti = profTierInfo(repoStars);\n const curName = ti.cur && ti.cur.name || ti.next && ti.next.name || \"Bronze\";\n const tierColor = TIER_COLOR[curName] || \"var(--an-tier-bronze)\";\n const prevMin = ti.cur ? ti.cur.min : 0;\n const bandPct = ti.next ? Math.min(100, Math.max(0, (repoStars - prevMin) / (ti.next.min - prevMin) * 100)) : 100;\n const litSegs = Math.round(bandPct / 100 * PROF_SEG);\n const starsFrac = ti.next ? repoStars + \"/\" + ti.next.min : \"MAX\";\n const stats = [[\"CREATED\", pad2((profile.createdSkills || []).length)], [\"COPIES\", pad2(rep.totalSupply || 0)], [\"OWNED\", pad2((profile.ownedSkills || []).length)]];\n let statsHtml = \"\";\n stats.forEach((s) => {\n statsHtml += '
' + s[0] + '' + s[1] + \"
\";\n });\n let rungs = \"\";\n PROF_TIERS.forEach((t) => {\n const isCur = t.name === curName;\n const done = repoStars >= t.min && !isCur;\n rungs += '
' + t.name.toUpperCase() + \"
\";\n });\n let segs = \"\";\n for (let i = 0; i < PROF_SEG; i++) segs += '';\n el.innerHTML = '
AGENT
' + wallet.slice(0, 6) + '
…' + wallet.slice(-4) + \"
\" + (profile.self ? \"YOUR AGENT\" : \"AGENT PROFILE\") + '
' + avatarSvg(wallet) + 'ID//' + wallet.slice(0, 4) + '
' + statsHtml + '
TIER
' + rungs + '
STARS' + segs + '' + starsFrac + \"
\";\n }\n var GH_MARK_SVG = '';\n var FOLDER_BINARY = \"01010100101010100101001010101001010010110100101010010101001010010101001010010110101001010010100100101001010101001010\";\n function verifiedWorkHtml(profile) {\n const repos = (profile.verifiedRepos || []).slice().sort((a, b) => (b.stars || 0) - (a.stars || 0));\n if (!repos.length) return \"\";\n let cards = \"\";\n repos.forEach((r) => {\n const stars = r.stars || 0;\n const tier = profRepoTier(stars);\n const fill = profRepoFill(stars);\n let gauge = \"\";\n for (let i = 0; i < 10; i++) gauge += '';\n const url = (r.url || \"\").slice(0, 4) === \"http\" ? r.url : \"\";\n const open = url ? '' : '\");\n });\n return '
Verified work
' + cards + \"
\";\n }\n function closeRepoRegister() {\n if (S.repoModalEl) {\n S.repoModalEl.remove();\n S.repoModalEl = null;\n }\n }\n function openRepoRegister() {\n closeRepoRegister();\n const ov = document.createElement(\"div\");\n ov.className = \"skModal\";\n ov.id = \"repoModal\";\n ov.addEventListener(\"click\", (e) => {\n if (e.target === ov) closeRepoRegister();\n });\n const card = document.createElement(\"div\");\n card.className = \"skModal-card\";\n card.innerHTML = '
Register GitHub work
Loading…
';\n ov.appendChild(card);\n document.body.appendChild(ov);\n card.querySelector(\".skModal-close\").addEventListener(\"click\", closeRepoRegister);\n S.repoModalEl = ov;\n vscode.postMessage({ type: \"getGithubStatus\" });\n }\n function renderRepoModalBody(status) {\n if (!S.repoModalEl) return;\n const body = S.repoModalEl.querySelector(\".rr-body\");\n if (!body) return;\n body.innerHTML = \"\";\n if (!status || !status.hasToken) {\n const p = document.createElement(\"div\");\n p.className = \"rr-hint\";\n p.textContent = \"Add a GitHub token (repo scope) to register your work. Stored locally on this device, never synced.\";\n const inp = document.createElement(\"input\");\n inp.type = \"password\";\n inp.className = \"rr-input\";\n inp.placeholder = \"ghp_… (GitHub personal access token)\";\n const link = document.createElement(\"a\");\n link.className = \"rr-link\";\n link.href = \"https://github.com/settings/tokens/new?scopes=repo&description=AgentNet\";\n link.target = \"_blank\";\n link.rel = \"noopener noreferrer\";\n link.textContent = \"Create a token ↗\";\n const err = document.createElement(\"div\");\n err.className = \"rr-err\";\n const btn = document.createElement(\"button\");\n btn.className = \"rr-btn\";\n btn.textContent = \"Save token\";\n btn.addEventListener(\"click\", () => {\n const t = inp.value.trim();\n if (!t) return;\n btn.disabled = true;\n btn.textContent = \"Saving…\";\n err.style.display = \"none\";\n vscode.postMessage({ type: \"submitGithubToken\", token: t });\n });\n body.appendChild(p);\n body.appendChild(inp);\n body.appendChild(link);\n body.appendChild(err);\n body.appendChild(btn);\n } else {\n const p = document.createElement(\"div\");\n p.className = \"rr-hint\";\n p.textContent = \"Register a public GitHub repo as verified work\" + (status.masked ? \" (token \" + status.masked + \")\" : \"\") + \".\";\n const inp = document.createElement(\"input\");\n inp.type = \"text\";\n inp.className = \"rr-input\";\n inp.placeholder = \"owner/name or github.com URL\";\n body.appendChild(p);\n body.appendChild(inp);\n const owned = S.ownedSkills.filter((n) => !!S.skillMints[n]);\n const checks = [];\n if (owned.length) {\n const lbl = document.createElement(\"div\");\n lbl.className = \"rr-sublabel\";\n lbl.textContent = \"Link skills (optional)\";\n body.appendChild(lbl);\n const list = document.createElement(\"div\");\n list.className = \"rr-skills\";\n owned.forEach((n) => {\n const row = document.createElement(\"label\");\n row.className = \"rr-skill\";\n const cb = document.createElement(\"input\");\n cb.type = \"checkbox\";\n cb.value = S.skillMints[n];\n const nm = document.createElement(\"span\");\n nm.textContent = n;\n row.appendChild(cb);\n row.appendChild(nm);\n list.appendChild(row);\n checks.push(cb);\n });\n body.appendChild(list);\n }\n const err = document.createElement(\"div\");\n err.className = \"rr-err\";\n const btn = document.createElement(\"button\");\n btn.className = \"rr-btn\";\n btn.textContent = \"Register repo\";\n btn.addEventListener(\"click\", () => {\n const repo = inp.value.trim();\n if (!repo) {\n err.textContent = \"Enter a repo (owner/name).\";\n err.style.display = \"\";\n return;\n }\n const mints = checks.filter((c) => c.checked).map((c) => c.value);\n btn.disabled = true;\n btn.textContent = \"Registering…\";\n err.style.display = \"none\";\n vscode.postMessage({ type: \"registerWorkRepo\", repo, skillMints: mints });\n });\n body.appendChild(err);\n body.appendChild(btn);\n }\n }\n function renderProfile(profile) {\n profile = mergeOptimistic(profile);\n const self = profile.self;\n const wallet = profile.wallet;\n document.getElementById(\"profileSelfOnly2\").style.display = self ? \"\" : \"none\";\n renderAgentIdCard(profile);\n const body = document.getElementById(\"profileBody\");\n body.innerHTML = \"\";\n const tabs2 = document.createElement(\"div\");\n tabs2.className = \"pr-tabs\";\n const tabAgent = document.createElement(\"button\");\n tabAgent.className = \"pr-tab on\";\n tabAgent.innerHTML = '
Agent
エージェント
';\n const tabCommunity = document.createElement(\"button\");\n tabCommunity.className = \"pr-tab\";\n tabCommunity.innerHTML = '
Community
コミュニティ
';\n tabs2.appendChild(tabAgent);\n tabs2.appendChild(tabCommunity);\n body.appendChild(tabs2);\n const paneAgent = document.createElement(\"div\");\n const paneCommunity = document.createElement(\"div\");\n paneCommunity.style.display = \"none\";\n body.appendChild(paneAgent);\n body.appendChild(paneCommunity);\n function selectTab2(which) {\n const onAgent = which === \"agent\";\n S.profileTab = onAgent ? \"agent\" : \"community\";\n tabAgent.classList.toggle(\"on\", onAgent);\n tabCommunity.classList.toggle(\"on\", !onAgent);\n paneAgent.style.display = onAgent ? \"\" : \"none\";\n paneCommunity.style.display = onAgent ? \"none\" : \"\";\n }\n tabAgent.addEventListener(\"click\", () => selectTab2(\"agent\"));\n tabCommunity.addEventListener(\"click\", () => selectTab2(\"community\"));\n if (self) {\n const rr = document.createElement(\"button\");\n rr.className = \"pr-repo-add\";\n rr.textContent = \"+ Register GitHub work\";\n rr.addEventListener(\"click\", openRepoRegister);\n paneAgent.appendChild(rr);\n }\n const vwHtml = verifiedWorkHtml(profile);\n if (vwHtml) {\n const vw = document.createElement(\"div\");\n vw.innerHTML = vwHtml;\n paneAgent.appendChild(vw);\n }\n function skillCard(card) {\n const owned = self || S.ownedSkills.indexOf(card.name) >= 0;\n return skillSdCard(card, { owned, dim: owned && !self, onOpen: (c) => openSkillModal(c.id) });\n }\n if (profile.createdSkills.length) {\n const sec = document.createElement(\"div\");\n sec.className = \"pr-sec\";\n sec.textContent = \"Created skills\";\n paneAgent.appendChild(sec);\n if (!self) {\n const notOwned = profile.createdSkills.filter((c) => S.ownedSkills.indexOf(c.name) < 0).length;\n if (notOwned > 0) {\n const buyAll = document.createElement(\"button\");\n buyAll.className = \"pr-buyall\";\n buyAll.textContent = \"Buy all · \" + notOwned + \" not owned\";\n buyAll.addEventListener(\"click\", () => showBuyAllConfirm(profile));\n paneAgent.appendChild(buyAll);\n }\n }\n const cg = document.createElement(\"div\");\n cg.className = \"an-sd-grid\";\n profile.createdSkills.forEach((c) => cg.appendChild(skillCard(c)));\n paneAgent.appendChild(cg);\n }\n const ownedNotCreated = profile.ownedSkills.filter((o) => !profile.createdSkills.some((c) => c.id === o.id));\n if (ownedNotCreated.length) {\n const sec = document.createElement(\"div\");\n sec.className = \"pr-sec\";\n sec.textContent = \"Owned skills\";\n paneAgent.appendChild(sec);\n const og = document.createElement(\"div\");\n og.className = \"an-sd-grid\";\n ownedNotCreated.forEach((o) => og.appendChild(skillCard(o)));\n paneAgent.appendChild(og);\n }\n if (!profile.createdSkills.length && !ownedNotCreated.length && !vwHtml) {\n const e = document.createElement(\"div\");\n e.className = \"pr-empty\";\n e.textContent = \"No work or skills yet.\";\n paneAgent.appendChild(e);\n }\n const allThreads = profile.threads || [];\n const selfNotes = allThreads.filter((t) => t.note.isSelfNote).map((t) => t.note);\n if (selfNotes.length) {\n const sec = document.createElement(\"div\");\n sec.className = \"pr-sec\";\n sec.textContent = \"Blog\";\n paneCommunity.appendChild(sec);\n const blog = document.createElement(\"div\");\n blog.className = \"pr-blog\";\n blog.tabIndex = 0;\n blog.setAttribute(\"role\", \"list\");\n blog.setAttribute(\"aria-label\", \"Blog posts\");\n blog.addEventListener(\"keydown\", (e) => {\n if (e.key !== \"ArrowLeft\" && e.key !== \"ArrowRight\") return;\n e.preventDefault();\n blog.scrollBy({ left: e.key === \"ArrowRight\" ? 260 : -260, behavior: \"smooth\" });\n });\n selfNotes.forEach((n) => blog.appendChild(noteCard(n, false)));\n enableDragScroll(blog);\n paneCommunity.appendChild(blog);\n }\n {\n const canPost = self || !!profile.canComment;\n const feedback = feedbackFor(wallet);\n const sec = document.createElement(\"div\");\n sec.className = \"pr-sec\";\n sec.innerHTML = self ? \"FORM // POST TO BLOG\" : \"FORM // WRITE A COMMENT\";\n paneCommunity.appendChild(sec);\n const compose = document.createElement(\"div\");\n compose.className = \"pr-compose\";\n let titleInput = null;\n if (self) {\n titleInput = document.createElement(\"input\");\n titleInput.type = \"text\";\n titleInput.placeholder = \"Title (optional)\";\n }\n const ta = document.createElement(\"textarea\");\n ta.placeholder = self ? \"Write a blog post or update…\" : \"Share your experience with this agent…\";\n const imgInput = document.createElement(\"input\");\n imgInput.type = \"text\";\n imgInput.placeholder = \"Image link / on-chain address / tx id (optional)\";\n const gitInput = document.createElement(\"input\");\n gitInput.type = \"text\";\n gitInput.placeholder = \"GitHub / git URL (optional)\";\n const errEl = document.createElement(\"div\");\n errEl.className = \"pr-err\";\n if (feedback) {\n errEl.textContent = feedback.text;\n errEl.style.display = \"\";\n if (feedback.ok) errEl.classList.add(\"ok\");\n }\n const btn = document.createElement(\"button\");\n btn.textContent = self ? \"Post\" : \"Comment\";\n if (!canPost) {\n ta.disabled = true;\n gitInput.disabled = true;\n imgInput.disabled = true;\n btn.disabled = true;\n if (titleInput) titleInput.disabled = true;\n const hint = document.createElement(\"div\");\n hint.className = \"pr-hint\";\n hint.textContent = \"Own ≥1 of this agent’s skills to comment.\";\n compose.appendChild(hint);\n }\n btn.addEventListener(\"click\", () => {\n const text = ta.value.trim();\n if (!text) return;\n const gitLink = gitInput.value.trim() || void 0;\n const image = imgInput.value.trim() || void 0;\n const title = titleInput ? titleInput.value.trim() || void 0 : void 0;\n S.postFeedback = null;\n btn.disabled = true;\n btn.textContent = self ? \"Posting…\" : \"Commenting…\";\n errEl.style.display = \"none\";\n errEl.classList.remove(\"ok\");\n S.pendingPost = { wallet, text, gitLink, self };\n const out = { type: \"postAgentNote\", agentWallet: wallet, text, gitLink };\n if (image) out.image = image;\n if (title) out.title = title;\n vscode.postMessage(out);\n });\n if (titleInput) compose.appendChild(titleInput);\n compose.appendChild(ta);\n compose.appendChild(imgInput);\n compose.appendChild(gitInput);\n compose.appendChild(errEl);\n compose.appendChild(btn);\n paneCommunity.appendChild(compose);\n body._postBtn = btn;\n body._postErr = errEl;\n body._postLabel = self ? \"Post\" : \"Comment\";\n body._postTa = ta;\n body._postGit = gitInput;\n body._postImg = imgInput;\n body._postTitle = titleInput;\n }\n const canReply = self || !!profile.canComment;\n function attachReply(cardEl, parentId) {\n if (!canReply) return;\n const bar = document.createElement(\"div\");\n bar.className = \"pr-replybar\";\n const toggle = document.createElement(\"button\");\n toggle.className = \"pr-replybtn\";\n toggle.textContent = \"Reply\";\n bar.appendChild(toggle);\n cardEl.appendChild(bar);\n let box = null;\n toggle.addEventListener(\"click\", () => {\n if (box) {\n box.remove();\n box = null;\n toggle.textContent = \"Reply\";\n return;\n }\n toggle.textContent = \"Cancel\";\n box = document.createElement(\"div\");\n box.className = \"pr-compose pr-replycompose\";\n const ta = document.createElement(\"textarea\");\n ta.placeholder = \"Write a reply…\";\n const err = document.createElement(\"div\");\n err.className = \"pr-err\";\n const send2 = document.createElement(\"button\");\n send2.textContent = \"Reply\";\n send2.addEventListener(\"click\", () => {\n const text = ta.value.trim();\n if (!text) return;\n send2.disabled = true;\n send2.textContent = \"Replying…\";\n err.style.display = \"none\";\n S.pendingPost = { wallet, text, parentId, self };\n vscode.postMessage({ type: \"postAgentNote\", agentWallet: wallet, text, parentId });\n });\n box.appendChild(ta);\n box.appendChild(err);\n box.appendChild(send2);\n cardEl.appendChild(box);\n ta.focus();\n });\n }\n const commentThreads = allThreads.filter((t) => !t.note.isSelfNote);\n const commentCount = commentThreads.reduce((s, t) => s + 1 + (t.replies ? t.replies.length : 0), 0);\n if (commentThreads.length) {\n const sec = document.createElement(\"div\");\n sec.className = \"pr-sec\";\n sec.textContent = \"Comments (\" + commentCount + \")\";\n paneCommunity.appendChild(sec);\n commentThreads.forEach((t) => {\n const opCard = noteCard(t.note, true);\n attachReply(opCard, t.note.id);\n paneCommunity.appendChild(opCard);\n (t.replies || []).forEach((rep) => {\n const rc = noteCard(rep, true);\n rc.classList.add(\"pr-reply\");\n if (rep.parentAuthor) {\n const to = document.createElement(\"div\");\n to.className = \"pr-replyto\";\n to.textContent = \"↳ replying to \" + agShort(rep.parentAuthor);\n rc.insertBefore(to, rc.firstChild);\n }\n attachReply(rc, rep.id);\n paneCommunity.appendChild(rc);\n });\n });\n } else {\n const e = document.createElement(\"div\");\n e.className = \"pr-empty\";\n e.textContent = self ? \"No comments yet.\" : \"No comments yet. Be the first.\";\n paneCommunity.appendChild(e);\n }\n selectTab2(S.profileTab);\n }\n function showBuyAllConfirm(profile) {\n const notOwned = profile.createdSkills.filter((c) => S.ownedSkills.indexOf(c.name) < 0);\n if (!notOwned.length) return;\n const totalLamports = notOwned.reduce((acc, c) => acc + (c.price ? BigInt(c.price) : 0n), 0n);\n const totalSol = totalLamports > 0n ? (Number(totalLamports) / 1e9).toFixed(4) + \" SOL\" : \"free\";\n const body = document.getElementById(\"profileBody\");\n const existing = body.querySelector(\".pr-confirm\");\n if (existing) {\n existing.remove();\n return;\n }\n const confirm = document.createElement(\"div\");\n confirm.className = \"pr-confirm\";\n const h = document.createElement(\"div\");\n h.style.fontWeight = \"600\";\n h.textContent = \"Buy \" + notOwned.length + \" skill\" + (notOwned.length !== 1 ? \"s\" : \"\") + \" (\" + totalSol + \")\";\n const ul = document.createElement(\"ul\");\n notOwned.forEach((c) => {\n const li = document.createElement(\"li\");\n li.textContent = c.name || c.id;\n ul.appendChild(li);\n });\n const btns = document.createElement(\"div\");\n btns.className = \"confirm-btns\";\n const ok = document.createElement(\"button\");\n ok.className = \"pr-buyall\";\n ok.style.justifyContent = \"center\";\n ok.textContent = \"Confirm\";\n const cancel = document.createElement(\"button\");\n cancel.textContent = \"Cancel\";\n ok.addEventListener(\"click\", () => {\n ok.disabled = true;\n cancel.disabled = true;\n ok.textContent = \"Buying…\";\n vscode.postMessage({ type: \"buyAllSkills\", wallet: profile.wallet });\n });\n cancel.addEventListener(\"click\", () => confirm.remove());\n btns.appendChild(ok);\n btns.appendChild(cancel);\n confirm.appendChild(h);\n confirm.appendChild(ul);\n confirm.appendChild(btns);\n const buyAllBtn = body.querySelector(\".pr-buyall\");\n if (buyAllBtn && buyAllBtn.parentNode) buyAllBtn.parentNode.insertBefore(confirm, buyAllBtn.nextSibling);\n else body.appendChild(confirm);\n }\n\n // src/chat/ui/panel/wallet.ts\n function setWallet(address) {\n S.myWalletAddress = address || null;\n updateFdFab();\n const full = address || \"(not connected)\";\n document.getElementById(\"wAddr\").textContent = address ? short(address) : \"not connected\";\n const label = address ? short(address) : \"My Wallet\";\n document.getElementById(\"wName\").textContent = label;\n document.getElementById(\"wName2\").textContent = address ? \"My Wallet\" : \"My Wallet\";\n const svg = address ? avatarSvg(address) : \"\";\n document.getElementById(\"wAvatar\").innerHTML = svg;\n document.getElementById(\"wAvatar2\").innerHTML = svg;\n if (S.currentProfileWallet === null || S.currentProfileWallet === address) {\n document.getElementById(\"walletAddr\").textContent = full;\n document.getElementById(\"wAvatarBig\").innerHTML = svg;\n }\n }\n function renderCloudSync(status) {\n const el = document.getElementById(\"cloudSync\");\n if (!el) return;\n el.onclick = null;\n el.style.cursor = \"\";\n if (!status || !S.cloudConnected) {\n el.textContent = \"\";\n el.className = \"\";\n el.title = \"\";\n return;\n }\n if (status.ok) {\n el.textContent = \"✓\";\n el.className = \"ok\";\n el.title = \"Synced to Drive\";\n } else if (status.reason === \"reauth\") {\n el.textContent = \"⚠ reconnect\";\n el.className = \"err\";\n el.title = \"Cloud sign-in expired. Click to reconnect \" + (S.cloudKind === \"gdrive\" ? \"Google Drive\" : \"cloud\") + \".\";\n el.style.cursor = \"pointer\";\n el.onclick = () => vscode.postMessage({ type: \"reconnectCloud\", kind: S.cloudKind || \"gdrive\" });\n } else {\n el.textContent = \"⚠\";\n el.className = \"err\";\n el.title = \"Drive sync failed (auto-retrying): \" + (status.error || \"unknown\");\n }\n }\n function renderWalletStorage() {\n const el = document.getElementById(\"walletStorage\");\n if (!el) return;\n el.textContent = S.cloudConnected ? \"Local + cloud mirror (connected)\" : \"Local only (no cloud)\";\n }\n function wireWallet() {\n document.getElementById(\"disconnectWalletBtn\").addEventListener(\"click\", () => {\n vscode.postMessage({ type: \"disconnectWallet\" });\n });\n document.getElementById(\"walletDisconnect\").addEventListener(\"click\", () => {\n vscode.postMessage({ type: \"disconnectWallet\" });\n });\n }\n\n // src/chat/ui/panel/paging.ts\n function resetPaging() {\n S.pageCursor = null;\n S.hasMore = false;\n S.loadingOlder = false;\n S.lastOlderCursor = null;\n }\n function prependOlder(messages) {\n const before = log.scrollHeight;\n const realLog = log;\n const frag = document.createElement(\"div\");\n let body = null;\n const openTurn = (userText, badge, imageCount) => {\n const turn = document.createElement(\"div\");\n turn.className = \"turn\";\n const head = document.createElement(\"div\");\n head.className = \"turnHead\";\n head.innerHTML = '>';\n head.appendChild(makeUtext(userText));\n if (badge) {\n const b2 = document.createElement(\"span\");\n b2.className = \"badge \" + badge;\n b2.textContent = badge === \"codex\" ? \"codex · gpt\" : \"claude\";\n head.appendChild(b2);\n }\n const imgEl = userImagesEl(imageCount ? { count: imageCount } : void 0);\n if (imgEl) head.appendChild(imgEl);\n const b = document.createElement(\"div\");\n b.className = \"turnBody\";\n turn.appendChild(head);\n turn.appendChild(b);\n frag.appendChild(turn);\n return b;\n };\n const node = (cls) => {\n const n = document.createElement(\"div\");\n n.className = \"node \" + cls;\n (body || (body = openTurn(\"\", void 0))).appendChild(n);\n return n;\n };\n for (const m of messages) {\n if (m.role === \"user\") {\n body = openTurn(m.text, void 0, m.imageCount);\n continue;\n }\n if (m.role === \"tool\") {\n renderToolInto(node(\"tool\"), m);\n continue;\n }\n if (m.role === \"summary\") {\n const n2 = node(\"summary\");\n n2.innerHTML = '
⌘ context compacted
';\n const sb = document.createElement(\"div\");\n sb.className = \"summaryBody\";\n sb.textContent = m.text;\n n2.appendChild(sb);\n continue;\n }\n const n = node(m.role + (m.role === \"assistant\" && m.cli ? \" \" + m.cli : \"\"));\n const el = document.createElement(\"div\");\n el.className = \"msg \" + m.role;\n if (m.role === \"assistant\") renderMd(el, m.text);\n else {\n el.textContent = m.text;\n el.dataset.md = m.text;\n }\n n.appendChild(el);\n if (m.role === \"assistant\") {\n addFooter(n, m.durationMs, m.model);\n addMsgCopy(n, el);\n }\n }\n const prevBehavior = realLog.style.scrollBehavior;\n realLog.style.scrollBehavior = \"auto\";\n realLog.insertBefore(frag, realLog.firstChild);\n void realLog.offsetHeight;\n realLog.scrollTop += realLog.scrollHeight - before;\n realLog.style.scrollBehavior = prevBehavior;\n }\n function requestOlder() {\n if (S.hasMore && !S.loadingOlder && S.pageCursor !== null && S.pageCursor !== S.lastOlderCursor) {\n S.loadingOlder = true;\n S.lastOlderCursor = S.pageCursor;\n vscode.postMessage({ type: \"loadMore\", cursor: S.pageCursor });\n }\n }\n function maybeFillOlder() {\n if (log.scrollHeight <= log.clientHeight) requestOlder();\n }\n function wirePaging() {\n log.addEventListener(\"scroll\", () => {\n if (log.scrollTop < 600) requestOlder();\n S.stick = nearBottom();\n updateJump();\n });\n }\n\n // src/chat/ui/panel/main.ts\n wireShell();\n wireSlash();\n wireEngine();\n wireSessions();\n wireComposer();\n wireStorage();\n wireViews();\n wirePublish();\n wireFeed();\n wireMenus();\n wireSkills();\n wireMarket();\n wireOverlays();\n wireWallet();\n wirePaging();\n window.addEventListener(\"message\", (event) => {\n const m = event.data;\n if (m.type === \"message\") onMessage(m.msg);\n else if (m.type === \"sessions\") {\n S.allSessions = m.list || [];\n S.cloudListState = m.cloud || \"none\";\n S.activeId = m.activeId;\n renderSessions();\n } else if (m.type === \"notice\") renderNotice(m.text || \"\");\n else if (m.type === \"status\") renderStatus(m.status || {});\n else if (m.type === \"loading\") showLoading();\n else if (m.type === \"clear\") {\n log.innerHTML = \"\";\n approvalDock.innerHTML = \"\";\n clearCtx();\n syncComposerLock();\n S.streaming = null;\n S.openBash = null;\n S.tailTurn = null;\n S.headTurn = null;\n hideTyping();\n hideActivity();\n resetPaging();\n syncWatermark();\n hideLoading();\n } else if (m.type === \"turnEnd\") {\n hideTyping();\n hideActivity();\n } else if (m.type === \"modelOptions\") {\n applyModelOptions(m.cli, m.options);\n } else if (m.type === \"usage\") {\n setCtxTokens(m.contextTokens);\n } else if (m.type === \"rateLimit\") {\n renderLimitMeter({ cli: m.cli, utilization: m.utilization, window: m.window, resetsAt: m.resetsAt, status: m.status });\n } else if (m.type === \"skillActive\" && m.origin === \"nft\" && m.mint) flashSkill(m.name, m.mint);\n else if (m.type === \"rpcStatus\") renderRpcStatus(m.status);\n else if (m.type === \"skillShopping\") setShopToggle(m.on);\n else if (m.type === \"searchResults\") {\n S.lastMarketResults = m.results || [];\n renderMarketResults(m.results);\n } else if (m.type === \"searchError\") {\n const msg = \"Search failed: \" + escapeHtml(m.message || \"unknown\");\n mktResults.innerHTML = '
' + msg + \"
\";\n if (S.currentProfileWallet) {\n document.getElementById(\"agentIdCard\").innerHTML = '
Could not load profile.
';\n document.getElementById(\"profileBody\").innerHTML = '
' + msg + \"
\";\n }\n } else if (m.type === \"skillDetail\") {\n if (S.skillModalOpen) renderSkillModal(m.detail);\n else renderDetail(m.detail);\n } else if (m.type === \"skillDoc\") {\n if (S.skillDocOpen) renderSkillDoc(m.name, m.text);\n } else if (m.type === \"postNoteResult\") {\n const submit = mktDetailBody.querySelector(\".dt-note-submit\");\n if (submit) {\n m.ok ? submit._reset && submit._reset() : submit._fail && submit._fail(m.error || \"Post failed\");\n }\n } else if (m.type === \"notes\" && S.currentDetail && m.skillId === S.currentDetail.id) {\n const owned = ownsMint(S.currentDetail.id) || S.ownedSkills.indexOf(S.currentDetailName) >= 0;\n renderComments(S.currentDetail.id, S.currentDetail.type, m.notes, owned);\n } else if (m.type === \"ownedSkills\") {\n S.disposedMints = m.disposedMints || {};\n S.disposedMintSet = new Set(Object.values(S.disposedMints));\n S.workflowMintSet = new Set(m.workflowMints || []);\n setSkills(m.names || [], m.mints || {}, m.meta || {});\n if (panels.market.style.display !== \"none\") renderMarketResults(S.lastMarketResults);\n refreshDetailOwned();\n refreshModalOwned();\n } else if (m.type === \"buyResult\") {\n if (m.ok) {\n showComplete(S.currentDetail && S.currentDetail.type === \"workflow\" ? \"WORKFLOW PURCHASED\" : \"SKILL PURCHASED\");\n vscode.postMessage({ type: \"getBalance\" });\n } else {\n showBuyError(m.error, m.code === \"insufficient_funds\" && S.rpcNetwork !== \"mainnet\");\n if (S.detailBuyBtn) {\n S.detailBuyBtn.disabled = false;\n S.detailBuyBtn.textContent = \"Buy\";\n }\n if (S.skillModalBuyBtn) {\n S.skillModalBuyBtn.disabled = false;\n S.skillModalBuyBtn.textContent = \"Buy\";\n }\n renderMarketResults(S.lastMarketResults);\n }\n } else if (m.type === \"airdropResult\") {\n if (m.ok) {\n renderNotice(\"Funded. Try the purchase again.\");\n vscode.postMessage({ type: \"getBalance\" });\n hideBuyError();\n } else {\n renderNotice(\"Get SOL failed: \" + (m.error || \"unknown\"));\n const fb = buyErrEl.querySelector(\".buyErrFund\");\n if (fb) {\n fb.disabled = false;\n fb.textContent = \"Get devnet SOL\";\n }\n }\n } else if (m.type === \"githubStatus\") {\n renderRepoModalBody(m);\n } else if (m.type === \"workRepoRegistered\") {\n if (m.ok) {\n showComplete(\"GITHUB REGISTERED\");\n closeRepoRegister();\n if (S.currentProfileWallet) vscode.postMessage({ type: \"getAgentProfile\", wallet: S.currentProfileWallet });\n } else if (S.repoModalEl) {\n const b = S.repoModalEl.querySelector(\".rr-body\");\n const err = b && b.querySelector(\".rr-err\");\n const btn = b && b.querySelector(\".rr-btn\");\n if (err) {\n err.textContent = m.error || \"Registration failed.\";\n err.style.display = \"\";\n }\n if (btn) {\n btn.disabled = false;\n btn.textContent = \"Register repo\";\n }\n }\n } else if (m.type === \"disposeResult\") {\n if (m.ok) {\n if (S.currentDetail) openDetail(S.currentDetail.id);\n } else {\n showBuyError(m.error || \"Unequip failed\");\n const rm = mktDetailBody.querySelector(\".dt-remove\");\n if (rm) {\n rm.disabled = false;\n rm.textContent = \"Unequip\";\n }\n }\n } else if (m.type === \"reEquipResult\") {\n if (m.ok) {\n if (S.currentDetail) openDetail(S.currentDetail.id);\n } else {\n showBuyError(m.error || \"Re-equip failed\");\n if (S.detailBuyBtn) {\n S.detailBuyBtn.disabled = false;\n S.detailBuyBtn.textContent = \"Re-equip\";\n }\n }\n } else if (m.type === \"agents\") renderAgents(m.agents);\n else if (m.type === \"agentProfile\") renderProfile(m.profile);\n else if (m.type === \"blogFeed\") renderFeed(m.posts);\n else if (m.type === \"blogPost\") {\n const wasQuote = !!quoteInflight[m.postId];\n if (wasQuote) {\n delete quoteInflight[m.postId];\n if (m.post) quoteCache[m.postId] = { post: m.post };\n }\n if (m.post) {\n feedBodies[m.postId] = m.post;\n if (S.currentFeedPost && S.currentFeedPost.id === m.postId) renderFeedPost();\n }\n if (wasQuote) {\n const els = S.quoteCards[m.postId] || [];\n delete S.quoteCards[m.postId];\n els.forEach((el) => fillQuoteCard(el, m.postId, m.post || null));\n }\n } else if (m.type === \"blogComments\") {\n feedThreads[m.postId] = m.threads || [];\n if (S.currentFeedPost && S.currentFeedPost.id === m.postId) renderFeedPost();\n } else if (m.type === \"blogCommentResult\") {\n const pane = document.getElementById(\"agFeedPost\");\n if (pane && S.currentFeedPost && S.currentFeedPost.id === m.postId) {\n if (m.ok) {\n if (pane._mainCompose) {\n pane._mainCompose._ta.value = \"\";\n pane._mainCompose._git.value = \"\";\n pane._mainCompose._btn.disabled = false;\n pane._mainCompose._btn.textContent = pane._mainCompose._label;\n }\n S.feedReplyTo = null;\n vscode.postMessage({ type: \"getBlogFeed\", sort: S.feedSort, fresh: !S.feedLastSage });\n } else {\n const box = pane._activeCompose || pane._mainCompose;\n if (box) {\n box._btn.disabled = false;\n box._btn.textContent = box._label;\n box._err.textContent = m.error || \"Comment failed\";\n box._err.style.display = \"\";\n }\n }\n }\n } else if (m.type === \"buyAllResult\") {\n const confirm = document.getElementById(\"profileBody\") && document.getElementById(\"profileBody\").querySelector(\".pr-confirm\");\n if (confirm) confirm.remove();\n if (m.bought > 0) {\n showComplete(m.bought === 1 ? \"SKILL PURCHASED\" : m.bought + \" SKILLS PURCHASED\");\n vscode.postMessage({ type: \"getBalance\" });\n if (m.failed > 0) showBuyError(m.failed + \" of \" + (m.bought + m.failed) + \" purchase(s) failed\");\n } else if (!m.ok || m.failed > 0) {\n showBuyError(m.error || (m.failed > 0 ? m.failed + \" purchase(s) failed\" : \"Purchase failed\"));\n }\n if (m.ok && S.currentProfileWallet) {\n vscode.postMessage({ type: \"getAgentProfile\", wallet: S.currentProfileWallet });\n vscode.postMessage({ type: \"ownedSkills\" });\n }\n } else if (m.type === \"agentNoteResult\") {\n const body = document.getElementById(\"profileBody\");\n const label = body && body._postLabel || \"Post\";\n if (!m.ok) {\n S.pendingPost = null;\n S.postFeedback = { wallet: m.agentWallet, text: m.error || \"Post failed\", ok: false, ts: Date.now() };\n if (body && body._postBtn) {\n body._postBtn.disabled = false;\n body._postBtn.textContent = label;\n if (body._postErr) {\n body._postErr.textContent = m.error || \"Post failed\";\n body._postErr.style.display = \"\";\n body._postErr.classList.remove(\"ok\");\n }\n }\n if (S.fabModalEl) {\n S.fabModalEl._btn.disabled = false;\n S.fabModalEl._btn.textContent = \"Post to AgentNet\";\n S.fabModalEl._err.textContent = m.error || \"Post failed\";\n S.fabModalEl._err.style.display = \"\";\n }\n } else {\n if (S.fabModalEl) {\n closeFabCompose();\n S.feedPosts = null;\n document.getElementById(\"feedList\").innerHTML = skFd(4);\n vscode.postMessage({ type: \"getBlogFeed\", sort: S.feedSort, fresh: true });\n }\n if (S.pendingPost) {\n S.recentlyPosted.push({\n wallet: S.pendingPost.wallet,\n ts: Date.now(),\n // author must be OUR wallet (the writer), not the profile owner's\n // (pendingPost.wallet): mergeOptimistic dedupes the ghost against the real\n // on-chain note by author+text, and the real note's author is the writer:\n // a profile-owner author only matches on self-posts, so comments on OTHER\n // agents rendered twice once the chain read caught up.\n note: { author: S.myWalletAddress || S.pendingPost.wallet, text: S.pendingPost.text, gitLink: S.pendingPost.gitLink, isSelfNote: S.pendingPost.self, parentId: S.pendingPost.parentId, timestamp: Date.now() }\n });\n S.pendingPost = null;\n }\n S.postFeedback = {\n wallet: m.agentWallet,\n text: label === \"Post\" ? \"Posted to blog.\" : \"Comment posted.\",\n ok: true,\n ts: Date.now()\n };\n showComplete(label === \"Post\" ? \"POST PUBLISHED\" : \"COMMENT POSTED\");\n if (body && body._postBtn) {\n body._postBtn.disabled = false;\n body._postBtn.textContent = label;\n if (body._postTa) body._postTa.value = \"\";\n if (body._postGit) body._postGit.value = \"\";\n if (body._postImg) body._postImg.value = \"\";\n if (body._postTitle) body._postTitle.value = \"\";\n if (body._postErr) {\n body._postErr.textContent = label === \"Post\" ? \"Posted to blog.\" : \"Comment posted.\";\n body._postErr.style.display = \"\";\n body._postErr.classList.add(\"ok\");\n }\n }\n }\n } else if (m.type === \"balance\") {\n S.solLamports = m.lamports;\n renderBalance();\n } else if (m.type === \"publishProgress\") {\n const phaseLabel = m.phase === \"store\" ? \"Storing on-chain\" : m.phase === \"mint\" ? \"Minting the NFT\" : \"Listing for sale\";\n pubSubmit.textContent = \"Publishing… \" + (m.total ? m.signed + \"/\" + m.total + \" signed · \" : \"\") + phaseLabel;\n } else if (m.type === \"publishResult\") {\n pubSubmit.disabled = false;\n pubSubmit.textContent = S.pubKind === \"workflow\" ? \"Publish workflow\" : \"Publish skill\";\n if (m.ok) {\n const nm = document.getElementById(\"pubName\").value.trim();\n [\"pubName\", \"pubDesc\", \"pubCategory\", \"pubHashtags\", \"pubImage\", \"pubText\"].forEach((id) => {\n document.getElementById(id).value = \"\";\n });\n document.getElementById(\"pubPrice\").value = \"0.1\";\n pubImageBadge.style.display = \"none\";\n for (const k in pubReqSel) delete pubReqSel[k];\n const wasWorkflow = S.pubKind === \"workflow\";\n setPubKind(\"skill\");\n showComplete(wasWorkflow ? \"WORKFLOW BUILT\" : \"SKILL CREATED\");\n showView(\"market\");\n } else {\n pubError.textContent = m.error || \"Publish failed.\";\n pubError.style.display = \"block\";\n }\n } else if (m.type === \"platform\") setTab(m.cli);\n else if (m.type === \"cliStatus\") {\n const previousStatus = S.cliReport?.[S.cli];\n S.cliReport = { claude: m.claude, codex: m.codex };\n const status = S.cliReport[S.cli];\n if (status === \"no-login\") renderNotice((S.cli === \"claude\" ? \"Claude\" : \"Codex\") + \" is not signed in. Type /login to connect it.\");\n else if (status === \"missing\" || status === \"node-missing\") renderEngineMissing(S.cli);\n else if (status === \"ok\" && previousStatus === \"node-missing\") renderNotice((S.cli === \"claude\" ? \"Claude\" : \"Codex\") + \" is ready.\");\n } else if (m.type === \"engineUpdate\" && m.cli === \"codex\") {\n renderEngineBanner(\n \"Codex is out of date, so new models are hidden. Update it, then reload this window.\",\n [\n [\"Update in terminal\", () => vscode.postMessage({ type: \"installEngine\", cli: \"codex\", update: true })],\n copyAction(CODEX_UPDATE_CMD)\n ],\n \"codex\"\n );\n } else if (m.type === \"claudeLoginUrl\") {\n renderNotice(\"Claude sign-in opened. If the browser did not open, visit:\\n\" + m.url + \"\\nAfter approving, paste the returned code with /login .\");\n } else if (m.type === \"claudeLoginStatus\") {\n if (m.status === \"done\") {\n S.cliReport = Object.assign({}, S.cliReport || {}, { claude: \"ok\" });\n renderNotice(\"Claude sign-in complete.\");\n if (S.cli === \"claude\") vscode.postMessage({ type: \"platform\", cli: \"claude\" });\n } else {\n renderNotice(\"Claude sign-in failed: \" + (m.error || \"Login was not completed.\"));\n }\n } else if (m.type === \"codexLoginChallenge\") {\n renderNotice(\"Codex sign-in opened. If the browser did not open, visit:\\n\" + m.url + \"\\nEnter this one-time code on the page: \" + m.code);\n } else if (m.type === \"codexLoginStatus\") {\n if (m.status === \"done\") {\n S.cliReport = Object.assign({}, S.cliReport || {}, { codex: \"ok\" });\n renderNotice(\"Codex sign-in complete.\");\n if (S.cli === \"codex\") vscode.postMessage({ type: \"platform\", cli: \"codex\" });\n } else {\n renderNotice(\"Codex sign-in failed: \" + (m.error || \"Login was not completed.\"));\n }\n } else if (m.type === \"toast\") renderNotice(m.text || \"\");\n else if (m.type === \"openUrl\" && m.url) window.open(m.url, \"_blank\", \"noopener,noreferrer\");\n else if (m.type === \"storage\") {\n renderStorage(m.info, m.options);\n renderWalletStorage();\n } else if (m.type === \"cloudSync\") renderCloudSync(m.status);\n else if (m.type === \"wallet\") setWallet(m.address);\n else if (m.type === \"page\") {\n hideLoading();\n S.hasMore = m.hasMore;\n S.pageCursor = m.cursor;\n maybeFillOlder();\n } else if (m.type === \"older\") {\n prependOlder(m.messages || []);\n S.hasMore = m.hasMore;\n S.pageCursor = m.cursor;\n S.loadingOlder = false;\n maybeFillOlder();\n } else if (m.type === \"approval\") renderApproval(m.req);\n else if (m.type === \"approvalDismiss\") dismissApproval(m.id);\n });\n vscode.postMessage({ type: \"ready\" });\n vscode.postMessage({ type: \"wallet\" });\n vscode.postMessage({ type: \"getBalance\" });\n})();\n"; +export const PANEL_SCRIPT = "\"use strict\";\n(() => {\n // src/chat/ui/panel/host.ts\n var vscode = typeof acquireVsCodeApi === \"function\" ? acquireVsCodeApi() : (() => {\n let clientId = null;\n const outbox = [];\n function post(s) {\n fetch(\"/rpc?client=\" + encodeURIComponent(clientId), {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: s\n }).catch(() => {\n });\n }\n function open(url) {\n const es = new EventSource(url);\n es.addEventListener(\"client\", (e) => {\n const id = JSON.parse(e.data).client;\n if (clientId === null) {\n clientId = id;\n es.close();\n open(\"/events?client=\" + encodeURIComponent(id));\n for (const m of outbox.splice(0)) post(m);\n }\n });\n es.onmessage = (e) => window.dispatchEvent(new MessageEvent(\"message\", { data: JSON.parse(e.data) }));\n }\n open(\"/events\");\n return {\n postMessage: (obj) => {\n const s = JSON.stringify(obj);\n if (clientId !== null) post(s);\n else outbox.push(s);\n }\n };\n })();\n function uiGet(k) {\n try {\n const s = vscode.getState && vscode.getState();\n return s ? s[k] : void 0;\n } catch (e) {\n return void 0;\n }\n }\n function uiSet(k, v) {\n try {\n if (!vscode.setState) return;\n const s = vscode.getState && vscode.getState() || {};\n s[k] = v;\n vscode.setState(s);\n } catch (e) {\n }\n }\n\n // src/chat/ui/panel/state.ts\n var S = {\n // ---- shell.ts ----\n stick: true,\n hasNew: false,\n // new content arrived while scrolled up → light the button in the engine accent\n streaming: null,\n // bubble currently being streamed into\n streamRaf: 0,\n // rAF handle: coalesces live-markdown renders to one paint/frame\n streamTimer: 0,\n // trailing timer that defers the next render to the cadence boundary\n lastStreamRender: 0,\n // when the live bubble was last re-rendered\n // ---- sessions.ts ----\n allSessions: [],\n // last sessions payload from extension\n cloudListState: \"none\",\n // cloud health of that payload's union (ok/reauth/transient/none)\n activeId: null,\n expanded: false,\n // \"모두 보기\" toggled?\n // ---- slash.ts ----\n slashIdx: 0,\n suppressSlash: false,\n activeSlashMatches: [],\n // ---- engine.ts ----\n cli: \"claude\",\n cliReport: null,\n customEngineOn: false,\n // a saved custom-endpoint config exists (host-announced)\n // ---- turns.ts ----\n tailTurn: null,\n // the turn new (bottom) replies attach to\n headTurn: null,\n // the turn prepended (top, older) replies attach to\n openBash: null,\n // a bash card awaiting its output (claude's split result)\n // ---- composer.ts ----\n typingEl: null,\n busy: false,\n attached: [],\n pendingSentImages: [],\n growRaf: 0,\n // ---- storage.ts ----\n storageOptions: [],\n cloudConnected: false,\n cloudKind: \"\",\n // which backend is connected, so a reauth prompt can reconnect the right one\n // ---- publish.ts ----\n pubKind: \"skill\",\n pubBodyConfirmed: false,\n // ---- feed.ts ----\n currentProfileWallet: null,\n agentsTab: \"feed\",\n // persists across view switches, same as profileTab\n feedSort: \"active\",\n // ACTIVE = lastActivityTime, LATEST = createdAt\n feedPosts: null,\n // null = never loaded (skeletons), [] = settled empty\n currentFeedPost: null,\n // the post open in the reader\n feedLastSage: false,\n // whether the comment in flight was sage (skips the fresh re-read)\n feedReplyTo: null,\n // id of the comment being answered (mobile CommentThreadList idiom)\n fabModalEl: null,\n // ---- quotes.ts ----\n quoteCards: {},\n // postId -> [placeholder card elements] awaiting the reply\n quoteSeen: {},\n // postId -> true once carded in the current render pass\n quoteSlots: 0,\n // unique refs carded in the current render pass\n // ---- agents.ts ----\n lastAgents: [],\n recentlyPosted: [],\n // [{ wallet, note, ts }]\n pendingPost: null,\n // { wallet, text, gitLink, self } - stashed at submit for agentNoteResult\n postFeedback: null,\n // { wallet, text, ok, ts } - survives the immediate profile re-render\n profileTab: \"agent\",\n // ---- profile.ts ----\n repoModalEl: null,\n // ---- skills.ts ----\n ownedSkills: [],\n skillMints: {},\n // slug/name -> mint for bought NFT skills (reuse market detail)\n workflowMintSet: /* @__PURE__ */ new Set(),\n // owned mints that are workflows (excluded from the workflow picker)\n disposedMints: {},\n // slug -> mint for un-pinned skills (greyed in the panel)\n disposedMintSet: /* @__PURE__ */ new Set(),\n // the mints above, for isDisposed() detail checks\n // ---- market.ts ----\n lastMarketResults: [],\n // last search results, kept to re-render on owned-list change\n currentKind: \"skill\",\n // active tab: Skills | Workflows\n currentDetail: null,\n // { id, type } of the open detail - for comments refresh\n hideOwnedMarket: void 0,\n mktSort: void 0,\n skillModalOpen: false,\n skillModalBuyBtn: null,\n skillModalName: null,\n skillModalMint: null,\n skillDocOpen: false,\n currentDetailName: null,\n detailBuyBtn: null,\n // ---- overlays.ts ----\n celebTimer: null,\n solLamports: null,\n // last known balance (lamports); null = unknown/failed\n buyErrTimer: null,\n dasReady: false,\n rpcNetwork: \"devnet\",\n // drives explorer-link cluster (set from rpcStatus)\n pick: 0,\n // rotate so the verb feels alive\n actTimer: null,\n firingTimer: null,\n // ---- wallet.ts ----\n myWalletAddress: null,\n // tracked so openWalletPage can showProfile(own)\n // ---- paging.ts ----\n pageCursor: null,\n // cursor for the NEXT older page (null = none / at start)\n hasMore: false,\n // older pages exist?\n loadingOlder: false,\n lastOlderCursor: null\n // last cursor we asked for; never auto-request the same one twice\n };\n\n // src/runtime/engineRegistry.ts\n var ENGINE_REGISTRY = {\n claude: { key: \"claude\", label: \"Claude\", binary: \"claude\", memoryFile: \"CLAUDE.md\" },\n codex: { key: \"codex\", label: \"Codex\", binary: \"codex\", memoryFile: \"AGENTS.md\" },\n custom: { key: \"custom\", label: \"Custom\", binary: \"codex\", memoryFile: \"AGENTS.md\" }\n };\n var ENGINE_KEYS = Object.keys(ENGINE_REGISTRY);\n function engineBinary(key) {\n return ENGINE_REGISTRY[key].binary;\n }\n function coerceEngineKey(cli) {\n return ENGINE_KEYS.includes(cli) ? cli : \"codex\";\n }\n function messageBinary(cli) {\n return engineBinary(coerceEngineKey(typeof cli === \"string\" ? cli : \"claude\"));\n }\n\n // src/chat/ui/panel/dom.ts\n var log = document.getElementById(\"log\");\n var mainEl = document.getElementById(\"main\");\n var loadingEl = document.getElementById(\"loading\");\n var jumpBtn = document.getElementById(\"jumpBtn\");\n var input = document.getElementById(\"input\");\n var sessList = document.getElementById(\"sessList\");\n var showAll = document.getElementById(\"showAll\");\n var emptyEl = document.getElementById(\"empty\");\n var modelBtn = document.getElementById(\"modelBtn\");\n var modelMenu = document.getElementById(\"modelMenu\");\n var modelLabel = document.getElementById(\"modelLabel\");\n var composer = document.getElementById(\"composer\");\n var modeBtn = document.getElementById(\"modeBtn\");\n var modeMenu = document.getElementById(\"modeMenu\");\n var modeLabel = document.getElementById(\"modeLabel\");\n var modeEffortTag = document.getElementById(\"modeEffortTag\");\n var ctxMeter = document.getElementById(\"ctxMeter\");\n var limitMeter = document.getElementById(\"limitMeter\");\n var approvalDock = document.getElementById(\"approvalDock\");\n var engineBanner = document.getElementById(\"engineBanner\");\n var slashMenu = document.getElementById(\"slashMenu\");\n var tabs = Array.from(document.querySelectorAll(\".etab\"));\n\n // src/chat/ui/panel/markdown.ts\n var MD_OK = !!(window.marked && window.DOMPurify);\n if (MD_OK) window.marked.setOptions({ breaks: true, gfm: true });\n var COPY_ICON = '';\n var CHECK_ICON = '';\n function copyText(text, done) {\n if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(text).then(done, () => {\n });\n else {\n const ta = document.createElement(\"textarea\");\n ta.value = text;\n document.body.appendChild(ta);\n ta.select();\n try {\n document.execCommand(\"copy\");\n done();\n } catch (e2) {\n }\n document.body.removeChild(ta);\n }\n }\n function addPreCopyButtons(root) {\n const pres = root.querySelectorAll(\"pre\");\n for (let i = 0; i < pres.length; i++) {\n const pre = pres[i];\n if (!pre.parentNode || pre.parentNode.classList && pre.parentNode.classList.contains(\"preWrap\")) continue;\n const wrap = document.createElement(\"div\");\n wrap.className = \"preWrap\";\n pre.parentNode.insertBefore(wrap, pre);\n wrap.appendChild(pre);\n const btn = document.createElement(\"button\");\n btn.className = \"preCopy\";\n btn.title = \"Copy code\";\n btn.innerHTML = COPY_ICON;\n btn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n const code = pre.querySelector(\"code\");\n copyText((code || pre).textContent || \"\", () => {\n btn.classList.add(\"done\");\n btn.innerHTML = CHECK_ICON;\n setTimeout(() => {\n btn.classList.remove(\"done\");\n btn.innerHTML = COPY_ICON;\n }, 1200);\n });\n });\n wrap.appendChild(btn);\n }\n }\n function addInlineCopy(root) {\n const codes = root.querySelectorAll(\"code\");\n for (let i = 0; i < codes.length; i++) {\n const code = codes[i];\n if (code.closest(\"pre\") || code.closest(\"a\") || code.classList.contains(\"inlineCopy\")) continue;\n code.classList.add(\"inlineCopy\");\n code.title = \"Click to copy\";\n code.addEventListener(\"click\", () => {\n const sel = window.getSelection();\n if (sel && !sel.isCollapsed) return;\n copyText(code.textContent || \"\", () => {\n code.classList.add(\"done\");\n setTimeout(() => code.classList.remove(\"done\"), 1200);\n });\n });\n }\n }\n function renderMd(el, text) {\n el.dataset.md = text;\n el._mdDone = null;\n el._mdTail = null;\n el._mdTailRaw = null;\n if (!MD_OK) {\n el.textContent = text;\n return;\n }\n try {\n el.innerHTML = window.DOMPurify.sanitize(window.marked.parse(text));\n addPreCopyButtons(el);\n addInlineCopy(el);\n } catch (e) {\n el.textContent = text;\n }\n }\n function renderMdStreaming(el, text) {\n el.dataset.md = text;\n if (!MD_OK) {\n el.textContent = text;\n return;\n }\n try {\n const tokens = window.marked.lexer(text);\n const stable = Math.max(0, tokens.length - 1);\n let done = el._mdDone;\n let ok = !!done && done.length <= stable;\n for (let i = 0; ok && i < done.length; i++) if (tokens[i].raw !== done[i]) ok = false;\n if (!ok) {\n el.innerHTML = \"\";\n el._mdDone = done = [];\n el._mdTail = null;\n el._mdTailRaw = null;\n }\n if (!el._mdTail) {\n el._mdTail = document.createElement(\"div\");\n el._mdTail.className = \"mdChunk\";\n el._mdTailRaw = null;\n el.appendChild(el._mdTail);\n }\n for (let i = done.length; i < stable; i++) {\n const div = document.createElement(\"div\");\n div.className = \"mdChunk\";\n div.innerHTML = window.DOMPurify.sanitize(window.marked.parse(tokens[i].raw));\n addPreCopyButtons(div);\n addInlineCopy(div);\n el.insertBefore(div, el._mdTail);\n done.push(tokens[i].raw);\n }\n const tailRaw = stable < tokens.length ? tokens[stable].raw : \"\";\n if (tailRaw !== el._mdTailRaw) {\n el._mdTail.innerHTML = window.DOMPurify.sanitize(window.marked.parse(tailRaw));\n addPreCopyButtons(el._mdTail);\n addInlineCopy(el._mdTail);\n el._mdTailRaw = tailRaw;\n }\n } catch (e) {\n el.textContent = text;\n el._mdDone = null;\n el._mdTail = null;\n el._mdTailRaw = null;\n }\n }\n function escapeHtml(s) {\n const d = document.createElement(\"div\");\n d.textContent = s;\n return d.innerHTML;\n }\n\n // src/runtime/engineInstall.ts\n var NODE_REQUIRED_MESSAGE = \"This engine is installed, but Node.js is missing. Install Node.js, restart AgentNet, then retry.\";\n var NODE_DOWNLOAD_URL = \"https://nodejs.org/en/download\";\n var ENGINE_INSTALL_COMMAND = {\n codex: \"npm install -g @openai/codex\",\n claude: \"npm install -g @anthropic-ai/claude-code\",\n custom: \"npm install -g @openai/codex\"\n // custom runs through the codex binary\n };\n var CODEX_UPDATE_COMMAND = \"codex update\";\n\n // src/chat/slashCommands.ts\n var both = [\"claude\", \"codex\"];\n var withCustom = (c) => c.engines.includes(\"codex\") ? { ...c, engines: [...c.engines, \"custom\"] } : c;\n var CHAT_SLASH_COMMANDS = [\n { name: \"login\", desc: \"sign in to the active engine\", engines: both, args: \"[code]\" },\n { name: \"logout\", desc: \"sign out of the active engine\", engines: both },\n { name: \"new\", desc: \"start a fresh chat\", engines: both },\n { name: \"clear\", desc: \"clear context and start fresh\", engines: both, args: \"[name]\" },\n { name: \"compact\", desc: \"summarize the conversation to free context\", engines: both, args: \"[instructions]\" },\n { name: \"status\", desc: \"show session, model, context, and account status\", engines: both },\n { name: \"resume\", desc: \"resume a saved conversation\", engines: both, args: \"[session]\" },\n { name: \"diff\", desc: \"show working-tree changes\", engines: [\"claude\", \"codex\"] },\n { name: \"permissions\", desc: \"manage tool permission rules\", engines: both, args: \"[mode]\" },\n { name: \"init\", desc: \"create project instructions\", engines: both },\n { name: \"review\", desc: \"review local changes or a PR\", engines: both, args: \"[target]\" },\n { name: \"mcp\", desc: \"manage or list MCP servers\", engines: both, args: \"[subcommand]\" },\n { name: \"skills\", desc: \"list or refresh available skills\", engines: both },\n { name: \"usage\", desc: \"show usage, limits, or token activity\", engines: both },\n { name: \"cost\", desc: \"alias for usage/status\", engines: both },\n { name: \"stats\", desc: \"alias for usage\", engines: [\"claude\"] },\n { name: \"copy\", desc: \"copy the latest assistant response\", engines: both, args: \"[N]\" },\n { name: \"engine\", desc: \"switch AgentNet engine\", engines: both, args: \"claude|codex\" },\n { name: \"model\", desc: \"switch the active model\", engines: both, args: \"[model]\" },\n { name: \"mode\", desc: \"change AgentNet permission mode\", engines: both, args: \"[mode]\" },\n { name: \"effort\", desc: \"set reasoning effort\", engines: both, args: \"[level]\" },\n { name: \"help\", desc: \"show slash commands\", engines: both },\n // Claude Code commands and bundled skills.\n { name: \"add-dir\", desc: \"grant file access to another directory\", engines: [\"claude\"], args: \"\" },\n { name: \"advisor\", desc: \"enable or disable advisor model guidance\", engines: [\"claude\"], args: \"[model|off]\" },\n { name: \"agents\", desc: \"manage agent configurations and background agents\", engines: [\"claude\"] },\n { name: \"autofix-pr\", desc: \"start a cloud session to fix PR feedback\", engines: [\"claude\"], args: \"[prompt]\" },\n { name: \"background\", desc: \"detach the current session to keep running\", engines: [\"claude\"], args: \"[prompt]\" },\n { name: \"batch\", desc: \"orchestrate large changes across worktrees\", engines: [\"claude\"], args: \"\" },\n { name: \"branch\", desc: \"fork the conversation into a branch\", engines: [\"claude\"], args: \"[name]\" },\n { name: \"btw\", desc: \"ask a side question without bloating history\", engines: both, args: \"\" },\n { name: \"cd\", desc: \"move the session to another working directory\", engines: [\"claude\"], args: \"\" },\n { name: \"chrome\", desc: \"configure Claude Chrome integration\", engines: [\"claude\"] },\n { name: \"claude-api\", desc: \"load Claude API guidance or migration help\", engines: [\"claude\"], args: \"[migrate|managed-agents-onboard]\" },\n { name: \"code-review\", desc: \"review changes and optionally apply fixes\", engines: [\"claude\"], args: \"[effort] [--fix] [target]\" },\n { name: \"color\", desc: \"set the prompt bar color\", engines: [\"claude\"], args: \"[color|default]\" },\n { name: \"config\", desc: \"open or update Claude settings\", engines: [\"claude\"], args: \"[key=value ...]\" },\n { name: \"context\", desc: \"visualize current context usage\", engines: [\"claude\"], args: \"[all]\" },\n { name: \"debug\", desc: \"enable debug logging and diagnose an issue\", engines: [\"claude\"], args: \"[description]\" },\n { name: \"deep-research\", desc: \"run a cited multi-search research workflow\", engines: [\"claude\"], args: \"\" },\n { name: \"desktop\", desc: \"continue in Claude Code Desktop\", engines: [\"claude\"] },\n { name: \"doctor\", desc: \"diagnose installation and runtime issues\", engines: [\"claude\"] },\n { name: \"exit\", desc: \"exit or detach the native CLI session\", engines: both },\n { name: \"export\", desc: \"export the conversation as text\", engines: [\"claude\"], args: \"[filename]\" },\n { name: \"fast\", desc: \"toggle fast mode when available\", engines: both, args: \"[on|off|status]\" },\n { name: \"feedback\", desc: \"send feedback with optional logs\", engines: both, args: \"[report]\" },\n { name: \"fewer-permission-prompts\", desc: \"suggest permission allowlist rules\", engines: [\"claude\"] },\n { name: \"focus\", desc: \"toggle Claude focus view\", engines: [\"claude\"] },\n { name: \"fork\", desc: \"fork work into a subagent or new thread\", engines: both, args: \"\" },\n { name: \"goal\", desc: \"set, view, pause, resume, or clear a goal\", engines: both, args: \"[condition|clear]\" },\n { name: \"heapdump\", desc: \"write a heap snapshot for diagnostics\", engines: [\"claude\"] },\n { name: \"hooks\", desc: \"view and manage lifecycle hooks\", engines: both },\n { name: \"ide\", desc: \"manage IDE integration or include IDE context\", engines: both },\n { name: \"insights\", desc: \"generate a Claude Code usage report\", engines: [\"claude\"] },\n { name: \"install-github-app\", desc: \"set up Claude GitHub Actions\", engines: [\"claude\"] },\n { name: \"install-slack-app\", desc: \"install the Claude Slack app\", engines: [\"claude\"] },\n { name: \"keybindings\", desc: \"open Claude keybindings\", engines: [\"claude\"] },\n { name: \"loop\", desc: \"run a prompt repeatedly\", engines: [\"claude\"], args: \"[interval] [prompt]\" },\n { name: \"memory\", desc: \"edit Claude memory files\", engines: [\"claude\"] },\n { name: \"mobile\", desc: \"show mobile app QR code\", engines: [\"claude\"] },\n { name: \"passes\", desc: \"share a free Claude Code week if eligible\", engines: [\"claude\"] },\n { name: \"plan\", desc: \"enter plan mode\", engines: both, args: \"[description]\" },\n { name: \"plugin\", desc: \"manage Claude plugins\", engines: [\"claude\"], args: \"[subcommand]\" },\n { name: \"powerup\", desc: \"open Claude Code feature lessons\", engines: [\"claude\"] },\n { name: \"privacy-settings\", desc: \"view privacy settings\", engines: [\"claude\"] },\n { name: \"radio\", desc: \"open Claude FM\", engines: [\"claude\"] },\n { name: \"recap\", desc: \"generate a one-line session recap\", engines: [\"claude\"] },\n { name: \"release-notes\", desc: \"view Claude Code release notes\", engines: [\"claude\"] },\n { name: \"reload-plugins\", desc: \"reload active plugins\", engines: [\"claude\"], args: \"[--force]\" },\n { name: \"reload-skills\", desc: \"rescan skills and command directories\", engines: [\"claude\"] },\n { name: \"remote-control\", desc: \"enable remote control\", engines: [\"claude\"] },\n { name: \"remote-env\", desc: \"choose cloud agent environment\", engines: [\"claude\"] },\n { name: \"rename\", desc: \"rename the current session\", engines: [\"claude\"], args: \"[name]\" },\n { name: \"rewind\", desc: \"rewind to a checkpoint\", engines: [\"claude\"] },\n { name: \"run\", desc: \"launch and inspect your app\", engines: [\"claude\"] },\n { name: \"run-skill-generator\", desc: \"teach /run and /verify how to run this app\", engines: [\"claude\"] },\n { name: \"sandbox\", desc: \"toggle Claude sandbox mode\", engines: [\"claude\"] },\n { name: \"schedule\", desc: \"create or manage routines\", engines: [\"claude\"], args: \"[description]\" },\n { name: \"security-review\", desc: \"review pending changes for security risks\", engines: [\"claude\"] },\n { name: \"setup-bedrock\", desc: \"configure Amazon Bedrock auth\", engines: [\"claude\"] },\n { name: \"setup-vertex\", desc: \"configure Google Vertex auth\", engines: [\"claude\"] },\n { name: \"simplify\", desc: \"review and simplify changed code\", engines: [\"claude\"], args: \"[target]\" },\n { name: \"statusline\", desc: \"configure status line fields\", engines: both },\n { name: \"stickers\", desc: \"order Claude Code stickers\", engines: [\"claude\"] },\n { name: \"stop\", desc: \"stop background work\", engines: both },\n { name: \"tasks\", desc: \"view background tasks\", engines: [\"claude\"] },\n { name: \"team-onboarding\", desc: \"generate a team onboarding guide\", engines: [\"claude\"] },\n { name: \"teleport\", desc: \"pull a web session into terminal\", engines: [\"claude\"] },\n { name: \"terminal-setup\", desc: \"configure terminal keybindings\", engines: [\"claude\"] },\n { name: \"theme\", desc: \"choose a theme\", engines: both },\n { name: \"tui\", desc: \"switch Claude terminal renderer\", engines: [\"claude\"], args: \"[default|fullscreen]\" },\n { name: \"ultraplan\", desc: \"draft an ultra plan\", engines: [\"claude\"], args: \"\" },\n { name: \"ultrareview\", desc: \"run a deep cloud review\", engines: [\"claude\"], args: \"[PR]\" },\n { name: \"upgrade\", desc: \"open Claude plan upgrade\", engines: [\"claude\"] },\n { name: \"usage-credits\", desc: \"configure Claude usage credits\", engines: [\"claude\"] },\n { name: \"verify\", desc: \"verify an app change by running it\", engines: [\"claude\"] },\n { name: \"voice\", desc: \"toggle Claude voice dictation\", engines: [\"claude\"], args: \"[hold|tap|off]\" },\n { name: \"web-setup\", desc: \"connect GitHub for Claude Code web\", engines: [\"claude\"] },\n { name: \"workflows\", desc: \"view workflow progress\", engines: [\"claude\"] },\n // Codex CLI and IDE extension commands.\n { name: \"auto-context\", desc: \"toggle IDE auto context\", engines: [\"codex\"] },\n { name: \"cloud\", desc: \"switch to Codex cloud mode\", engines: [\"codex\"] },\n { name: \"cloud-environment\", desc: \"choose Codex cloud environment\", engines: [\"codex\"] },\n { name: \"local\", desc: \"switch to local Codex mode\", engines: [\"codex\"] },\n { name: \"keymap\", desc: \"remap TUI shortcuts\", engines: [\"codex\"] },\n { name: \"vim\", desc: \"toggle Vim composer mode\", engines: [\"codex\"] },\n { name: \"sandbox-add-read-dir\", desc: \"grant sandbox read access to a directory\", engines: [\"codex\"], args: \"\" },\n { name: \"agent\", desc: \"switch active agent thread\", engines: [\"codex\"] },\n { name: \"apps\", desc: \"browse app connectors\", engines: [\"codex\"] },\n { name: \"plugins\", desc: \"browse installed and discoverable plugins\", engines: [\"codex\"] },\n { name: \"archive\", desc: \"archive the current Codex session\", engines: [\"codex\"] },\n { name: \"delete\", desc: \"delete the current Codex session\", engines: [\"codex\"] },\n { name: \"experimental\", desc: \"toggle experimental Codex features\", engines: [\"codex\"] },\n { name: \"approve\", desc: \"approve one retry of an auto-review denial\", engines: [\"codex\"] },\n { name: \"memories\", desc: \"configure Codex memories\", engines: [\"codex\"] },\n { name: \"import\", desc: \"import external agent configuration\", engines: [\"codex\"] },\n { name: \"mention\", desc: \"attach a file or folder to the conversation\", engines: [\"codex\"], args: \"\" },\n { name: \"personality\", desc: \"choose Codex response style\", engines: [\"codex\"] },\n { name: \"ps\", desc: \"show background terminals\", engines: [\"codex\"] },\n { name: \"side\", desc: \"start an ephemeral side conversation\", engines: [\"codex\"], args: \"\" },\n { name: \"raw\", desc: \"toggle raw scrollback mode\", engines: [\"codex\"] },\n { name: \"quit\", desc: \"exit the native CLI session\", engines: [\"codex\"] },\n { name: \"debug-config\", desc: \"inspect Codex config layers\", engines: [\"codex\"] },\n { name: \"title\", desc: \"configure terminal title fields\", engines: [\"codex\"] }\n ].map(withCustom);\n\n // src/chat/modelOptions.ts\n var CHAT_MODEL_OPTIONS = {\n claude: [\n {\n value: \"opus\",\n chipLabel: \"Opus 5\",\n label: \"Opus 5\",\n description: \"Most capable · Claude alias: opus\"\n },\n {\n value: \"sonnet\",\n chipLabel: \"Sonnet 5\",\n label: \"Sonnet 5\",\n description: \"Balanced · Claude alias: sonnet\"\n },\n {\n value: \"haiku\",\n chipLabel: \"Haiku 4.5\",\n label: \"Haiku 4.5\",\n description: \"Fastest · Claude alias: haiku\"\n }\n ],\n codex: [\n {\n value: \"gpt-5.5-codex\",\n chipLabel: \"GPT-5.5 Codex\",\n label: \"GPT-5.5 Codex\",\n description: \"Coding-tuned · exact value: gpt-5.5-codex\"\n },\n {\n value: \"gpt-5.5\",\n chipLabel: \"GPT-5.5\",\n label: \"GPT-5.5\",\n description: \"General GPT model · exact value: gpt-5.5\"\n }\n ],\n // The custom engine has no catalog: its one model is whatever the saved endpoint\n // config names, which lives on the host side. Surfaces build the entry with\n // customModelOption from the stored config and push it over their live channel.\n custom: []\n };\n\n // src/chat/ui/avatar.ts\n var AVATAR_SVG = ``;\n var AVATAR_CLASSES = [\"clothes\", \"eyes\", \"line\", \"face_acc\"];\n var SKIN = \"cls-2\";\n function hashSeed(v) {\n let h = 2166136261;\n for (let i = 0; i < v.length; i++) {\n h ^= v.charCodeAt(i);\n h = Math.imul(h, 16777619);\n }\n return h >>> 0;\n }\n function rng(seed) {\n let s = hashSeed(seed || \"default\") || 439041101;\n return () => {\n s ^= s << 13;\n s ^= s >>> 17;\n s ^= s << 5;\n return (s >>> 0) / 4294967296;\n };\n }\n function avatarSvg(seed) {\n const r = rng(seed || \"default\");\n const pal = {};\n pal[SKIN] = r() > 0.5 ? \"#111111\" : \"#f6d9c8\";\n for (const c of AVATAR_CLASSES) {\n const hue = Math.floor(r() * 360), sat = 50 + Math.floor(r() * 35), lig = 35 + Math.floor(r() * 25);\n pal[c] = \"hsl(\" + hue + \",\" + sat + \"%,\" + lig + \"%)\";\n }\n pal[\"eyes\"] = pal[SKIN] === \"#111111\" ? \"hsl(\" + Math.floor(r() * 360) + \",80%,75%)\" : \"#222222\";\n let svg = AVATAR_SVG;\n const ds = svg.indexOf(\"\");\n if (de > ds) svg = svg.slice(0, ds) + svg.slice(de + 8);\n }\n for (const c of [...AVATAR_CLASSES, SKIN]) {\n const token = 'class=\"' + c + '\"', repl = 'fill=\"' + pal[c] + '\"';\n let i;\n while ((i = svg.indexOf(token)) >= 0) {\n svg = svg.slice(0, i) + repl + svg.slice(i + token.length);\n }\n }\n return svg;\n }\n\n // src/chat/ui/panel/format.ts\n function rel(ts) {\n const s = Math.max(0, (Date.now() - ts) / 1e3);\n if (s < 60) return \"방금\";\n const m = s / 60;\n if (m < 60) return Math.floor(m) + \"분\";\n const h = m / 60;\n if (h < 24) return Math.floor(h) + \"시간\";\n const d = h / 24;\n if (d < 30) return Math.floor(d) + \"일\";\n const mo = d / 30;\n if (mo < 12) return Math.floor(mo) + \"개월\";\n return Math.floor(mo / 12) + \"년\";\n }\n function looksOnChain(v) {\n const s = (v || \"\").trim();\n if (!s) return false;\n if (/^https?:/i.test(s)) return false;\n if (/\\.(png|jpe?g|gif|webp|svg)$/i.test(s)) return false;\n return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(s);\n }\n function fmtNoteDate(n) {\n const ms = n.__blockTime ? n.__blockTime * 1e3 : n.timestamp || 0;\n if (!ms) return \"\";\n try {\n return new Date(ms).toLocaleDateString(void 0, { month: \"short\", day: \"numeric\", year: \"numeric\" });\n } catch {\n return \"\";\n }\n }\n function explorerTxUrl(sig) {\n const u = \"https://explorer.solana.com/tx/\" + encodeURIComponent(sig);\n return S.rpcNetwork === \"mainnet\" ? u : u + \"?cluster=\" + encodeURIComponent(S.rpcNetwork);\n }\n function fdAgo(ms) {\n if (!ms) return \"\";\n const s = Math.max(1, Math.floor((Date.now() - ms) / 1e3));\n if (s < 60) return s + \"s\";\n const m = Math.floor(s / 60);\n if (m < 60) return m + \"m\";\n const h = Math.floor(m / 60);\n if (h < 24) return h + \"h\";\n const d = Math.floor(h / 24);\n if (d < 7) return d + \"d\";\n return Math.floor(d / 7) + \"w\";\n }\n function feedImgUrl(v) {\n return v && /^https?:\\/\\//i.test(v) ? v : null;\n }\n function agShort(w) {\n return w.slice(0, 6) + \"...\" + w.slice(-4);\n }\n function pad2(n) {\n return n < 10 ? \"0\" + n : String(n);\n }\n function splitSkillDoc(text) {\n text = text || \"\";\n const m = text.match(/^---\\r?\\n[\\s\\S]*?\\r?\\n---\\r?\\n?/);\n return (m ? text.slice(m[0].length) : text).trim();\n }\n function fmtSol(lamports) {\n if (lamports == null) return null;\n const sol = lamports / 1e9;\n const s = sol < 1 ? sol.toFixed(4) : sol.toFixed(3);\n return s.replace(/\\.?0+$/, \"\") + \" SOL\";\n }\n function fmtPrice(price) {\n if (price == null) return null;\n const n = Number(price);\n if (!Number.isFinite(n)) return null;\n return n === 0 ? \"Free\" : fmtSol(n);\n }\n function netBadge(network) {\n const n = network === \"mainnet\" ? \"mainnet\" : \"devnet\";\n return '' + n + \"\";\n }\n function short(a) {\n return a && a.length > 10 ? a.slice(0, 4) + \"..\" + a.slice(-3) : a;\n }\n\n // src/chat/ui/panel/skeleton.ts\n function skSd(n) {\n let s = \"\";\n for (let i = 0; i < n; i++) s += '
';\n return s;\n }\n function skAc(n) {\n let s = \"\";\n for (let i = 0; i < n; i++) s += '
';\n return s;\n }\n var skId = '
';\n function skFd(n) {\n let s = \"\";\n for (let i = 0; i < n; i++) s += '
';\n return s;\n }\n\n // src/chat/ui/panel/publish.ts\n var pubImage = document.getElementById(\"pubImage\");\n var pubImageBadge = document.getElementById(\"pubImageBadge\");\n var pubSubmit = document.getElementById(\"pubSubmit\");\n var pubError = document.getElementById(\"pubError\");\n var pubFormEl = document.getElementById(\"pubForm\");\n var pubTextWrap = document.getElementById(\"pubTextWrap\");\n var pubReqWrap = document.getElementById(\"pubReqWrap\");\n var pubReqEl = document.getElementById(\"pubReq\");\n var pubReqCountEl = document.getElementById(\"pubReqCount\");\n var pubReqSel = {};\n function chosenReqMints() {\n return Object.keys(pubReqSel).filter((m) => pubReqSel[m]);\n }\n function updatePubReqCount() {\n const c = chosenReqMints().length;\n pubReqCountEl.textContent = c ? c + \" selected\" + (c > 16 ? \": max 16, deselect some\" : \"\") : \"\";\n }\n function renderPubReq() {\n const owned = S.ownedSkills.filter((n) => !!S.skillMints[n] && !S.workflowMintSet.has(S.skillMints[n]));\n if (!owned.length) {\n pubReqEl.innerHTML = `
You don't own any skills yet. Buy at least one before publishing a workflow.
`;\n pubReqCountEl.textContent = \"\";\n return;\n }\n pubReqEl.innerHTML = \"\";\n for (const n of owned) {\n const mint = S.skillMints[n];\n const lab = document.createElement(\"label\");\n const cb = document.createElement(\"input\");\n cb.type = \"checkbox\";\n cb.value = mint;\n cb.checked = !!pubReqSel[mint];\n cb.addEventListener(\"change\", () => {\n pubReqSel[mint] = cb.checked;\n updatePubReqCount();\n });\n const span = document.createElement(\"span\");\n span.textContent = n;\n lab.appendChild(cb);\n lab.appendChild(span);\n pubReqEl.appendChild(lab);\n }\n updatePubReqCount();\n }\n function setPubKind(k) {\n S.pubKind = k === \"workflow\" ? \"workflow\" : \"skill\";\n S.pubBodyConfirmed = false;\n const wf = S.pubKind === \"workflow\";\n for (const b of document.querySelectorAll(\".pubKind button\")) b.classList.toggle(\"on\", b.getAttribute(\"data-k\") === S.pubKind);\n pubFormEl.classList.toggle(\"wf\", wf);\n pubTextWrap.style.display = wf ? \"none\" : \"\";\n pubReqWrap.style.display = wf ? \"\" : \"none\";\n document.getElementById(\"pubFormHead\").innerHTML = \"FORM // PUBLISH \" + (wf ? \"WORKFLOW\" : \"SKILL\") + \"\";\n document.getElementById(\"pubViewTitle\").textContent = wf ? \"Make a workflow\" : \"Make a skill\";\n document.getElementById(\"pubViewDesc\").textContent = wf ? \"Bundle skills you own into one workflow. Buyers must hold every skill it requires to unlock it.\" : \"Publish a skill others can buy. It mints a soulbound NFT and the body is stored on-chain.\";\n if (!pubSubmit.disabled) pubSubmit.textContent = wf ? \"Publish workflow\" : \"Publish skill\";\n if (wf) renderPubReq();\n }\n function openPublish(kind) {\n setPubKind(kind);\n showView(\"publish\");\n }\n function wirePublish() {\n for (const b of document.querySelectorAll(\".pubKind button\")) b.addEventListener(\"click\", () => setPubKind(b.getAttribute(\"data-k\")));\n pubImage.addEventListener(\"input\", () => {\n pubImageBadge.style.display = looksOnChain(pubImage.value) ? \"inline-block\" : \"none\";\n });\n document.getElementById(\"pubText\").addEventListener(\"input\", () => {\n S.pubBodyConfirmed = false;\n });\n pubSubmit.addEventListener(\"click\", () => {\n const name = document.getElementById(\"pubName\").value.trim();\n const description = document.getElementById(\"pubDesc\").value.trim();\n const priceSol = document.getElementById(\"pubPrice\").value.trim();\n const category = document.getElementById(\"pubCategory\").value.trim();\n const hashtags = document.getElementById(\"pubHashtags\").value.split(\",\").map((h) => h.trim()).filter(Boolean);\n const image = pubImage.value.trim();\n pubError.style.display = \"none\";\n const fail = (msg2) => {\n pubError.textContent = msg2;\n pubError.style.display = \"block\";\n };\n if (!name) return fail(\"Name is required.\");\n if (!description) return fail(\"Description is required.\");\n let text;\n let reqMints = [];\n if (S.pubKind === \"workflow\") {\n reqMints = chosenReqMints().filter((m) => !S.workflowMintSet.has(m));\n if (!reqMints.length) return fail(\"Pick at least one skill this workflow requires.\");\n if (reqMints.length > 16) return fail(\"A workflow can require at most 16 skills.\");\n const fm = [\n \"---\",\n \"name: \" + name,\n \"description: \" + description.replace(/\\s*\\n\\s*/g, \" \"),\n \"type: workflow\",\n \"requiredSkills: [\" + reqMints.join(\", \") + \"]\"\n ];\n if (category) fm.push(\"category: \" + category);\n if (hashtags.length) fm.push(\"hashtags: [\" + hashtags.join(\", \") + \"]\");\n text = fm.concat([\"---\", \"\", \"# \" + name, \"\", description, \"\"]).join(\"\\n\");\n } else {\n text = document.getElementById(\"pubText\").value.trim();\n if (!text) return fail(\"Skill text is required.\");\n const body = text.replace(/^---[\\s\\S]*?\\n---\\s*/, \"\").trim();\n if (body.length < 20 && !S.pubBodyConfirmed) {\n S.pubBodyConfirmed = true;\n return fail(\"This publishes PERMANENTLY and cannot be deleted; the body looks empty or very short. Click Publish again to submit anyway.\");\n }\n }\n if (!priceSol) return fail(\"Enter a price in SOL (use 0 for free).\");\n if (!/^\\d+(\\.\\d+)?$/.test(priceSol)) return fail(\"Price must be a number in SOL (e.g. 0.1).\");\n pubSubmit.disabled = true;\n pubSubmit.textContent = \"Publishing…\";\n const msg = {\n type: \"publishSkill\",\n name,\n description,\n text,\n priceSol,\n category: category || void 0,\n hashtags: hashtags.length ? hashtags : void 0,\n image: image || void 0\n };\n if (S.pubKind === \"workflow\") {\n msg.kind = \"workflow\";\n msg.requiredSkills = reqMints;\n }\n vscode.postMessage(msg);\n });\n }\n\n // src/chat/ui/icons.ts\n var WAND_SVG = '';\n var LAYERS_SVG = '';\n\n // src/chat/ui/iqlogo.ts\n var IQ_LOGO_SVG = ' ';\n\n // src/links/github.ts\n var SAFE_EXTERNAL_PROTOCOLS = /* @__PURE__ */ new Set([\"https:\", \"http:\", \"git:\"]);\n function safeExternalUrl(raw) {\n if (!raw) return null;\n try {\n const url = new URL(raw);\n if (!SAFE_EXTERNAL_PROTOCOLS.has(url.protocol)) return null;\n return url.href;\n } catch {\n return null;\n }\n }\n function parseGithubLink(raw) {\n const href = safeExternalUrl(raw);\n if (!href) return null;\n let url;\n try {\n url = new URL(href);\n } catch {\n return null;\n }\n const host = url.hostname.toLowerCase();\n if (host !== \"github.com\" && host !== \"www.github.com\") return null;\n const parts = url.pathname.split(\"/\").filter(Boolean);\n if (parts.length < 2) return null;\n const [owner, repo, section, value, ...rest] = parts;\n const repoName = repo.replace(/\\.git$/i, \"\");\n const repoFullName = `${owner}/${repoName}`;\n if (!section) {\n return {\n kind: \"repo\",\n href,\n owner,\n repo: repoName,\n label: repoFullName,\n meta: \"GitHub repository\"\n };\n }\n if (section === \"pull\" && value && /^\\d+$/.test(value)) {\n return {\n kind: \"pull\",\n href,\n owner,\n repo: repoName,\n number: value,\n label: `${repoFullName} #${value}`,\n meta: \"GitHub pull request\"\n };\n }\n if (section === \"commit\" && value && /^[0-9a-f]{7,40}$/i.test(value)) {\n return {\n kind: \"commit\",\n href,\n owner,\n repo: repoName,\n sha: value,\n label: `${repoFullName}@${value.slice(0, 7)}`,\n meta: \"GitHub commit\"\n };\n }\n if (section === \"blob\" && value && rest.length > 0) {\n const path = rest.join(\"/\");\n return {\n kind: \"blob\",\n href,\n owner,\n repo: repoName,\n path,\n label: path,\n meta: repoFullName\n };\n }\n return null;\n }\n\n // src/chat/ui/panel/tiers.ts\n var AG_SEG = 12;\n var AG_TIERS = [\n { name: \"Legendary\", min: 250 },\n { name: \"Gold\", min: 60 },\n { name: \"Silver\", min: 15 },\n { name: \"Bronze\", min: 3 }\n ];\n function agStarTier(stars) {\n return AG_TIERS.find((t) => stars >= t.min) || null;\n }\n function agNextTierMin(stars) {\n const asc = AG_TIERS.slice().sort((a, b) => a.min - b.min);\n const up = asc.find((t) => t.min > stars);\n return up ? up.min : asc[asc.length - 1].min;\n }\n function agAccent(wallet) {\n return \"hsl(\" + hashSeed(wallet || \"default\") % 360 + \" 46% 62%)\";\n }\n var PROF_TIERS = [{ name: \"Bronze\", min: 3 }, { name: \"Silver\", min: 15 }, { name: \"Gold\", min: 60 }, { name: \"Legendary\", min: 250 }];\n var TIER_COLOR = { Bronze: \"var(--an-tier-bronze)\", Silver: \"var(--an-tier-silver)\", Gold: \"var(--an-tier-gold)\", Legendary: \"var(--an-tier-legendary)\" };\n var PROF_SEG = 15;\n function profTierInfo(stars) {\n let cur = null, next = null;\n for (const t of PROF_TIERS) {\n if (stars >= t.min) cur = t;\n else {\n next = t;\n break;\n }\n }\n return { cur, next };\n }\n var PROF_REPO_TIERS = [\n { min: 250, color: \"#86c4cf\", from: \"#131a1b\", to: \"#0d1011\", empty: \"#1e2628\" },\n { min: 50, color: \"#d8c074\", from: \"#1a1813\", to: \"#100f0d\", empty: \"#2a2618\" },\n { min: 10, color: \"#b8c0cc\", from: \"#161719\", to: \"#0e0f10\", empty: \"#26282c\" },\n { min: 3, color: \"#b8895a\", from: \"#1a1613\", to: \"#100f0e\", empty: \"#2a2420\" }\n ];\n var PROF_REPO_BASE = { color: \"#9a9a9a\", from: \"#1a1a1d\", to: \"#0d0d0e\", empty: \"#33333a\" };\n function profRepoTier(stars) {\n return PROF_REPO_TIERS.find((t) => stars >= t.min) || PROF_REPO_BASE;\n }\n function profRepoFill(stars) {\n const next = [3, 10, 50, 250].find((t) => stars < t);\n if (!next) return 10;\n return Math.max(0, Math.min(10, Math.round(stars / next * 10)));\n }\n\n // src/chat/ui/panel/agents.ts\n function agentCardEl(agent, self) {\n const stars = agent.stars || 0;\n const tier = agStarTier(stars);\n const isMax = tier && tier.name === \"Legendary\";\n const denom = agNextTierMin(stars);\n const filled = Math.max(0, Math.min(AG_SEG, Math.round(stars / denom * AG_SEG)));\n const tierName = (tier ? tier.name : \"Unranked\").toUpperCase();\n const created = agent.skillsPublished || 0;\n const copies = agent.totalSupply || 0;\n const earnedSol = agent.totalEarned ? Number(agent.totalEarned) / 1e9 : 0;\n const earned = earnedSol >= 100 ? earnedSol.toFixed(0) : earnedSol.toFixed(2);\n const sig = 34 + agent.wallet.charCodeAt(2) % 6 * 11;\n let segs = \"\";\n for (let i = 0; i < AG_SEG; i++) segs += '';\n const btn = document.createElement(\"button\");\n btn.className = \"an-ac\" + (self ? \" is-self\" : \"\");\n btn.style.setProperty(\"--accent\", agAccent(agent.wallet));\n btn.innerHTML = '
>' + agShort(agent.wallet).toUpperCase() + \"_AGENT\" + (self ? ' // YOU' : \"\") + 'SIGNAL
エージェント
' + agent.wallet.slice(0, 6).toUpperCase() + '
アクセス / ACCESS
' + tierName + '
' + avatarSvg(agent.wallet) + '
— RANKING —
STARS' + segs + '' + (isMax ? stars : stars + \"/\" + denom) + '
CREATED
' + created + '
COPIES
' + copies + '
>EARNED ' + earned + '◎
';\n btn.addEventListener(\"click\", () => showProfile(agent.wallet));\n return btn;\n }\n function renderAgents(agents) {\n S.lastAgents = agents || [];\n const selfEl = document.getElementById(\"agentsSelf\");\n if (selfEl) {\n selfEl.innerHTML = \"\";\n if (S.myWalletAddress) {\n const selfRep = S.lastAgents.find((a) => a.wallet === S.myWalletAddress) || { wallet: S.myWalletAddress, skillsPublished: 0, totalSupply: 0, notesReceived: 0, updatedAt: 0 };\n selfEl.appendChild(agentCardEl(selfRep, true));\n }\n }\n const search = document.getElementById(\"agentSearch\");\n if (search && !search._wired) {\n search._wired = true;\n search.addEventListener(\"input\", renderAgentsList);\n }\n renderAgentsList();\n }\n function renderAgentsList() {\n const el = document.getElementById(\"agentsList\");\n if (!el) return;\n const searchEl = document.getElementById(\"agentSearch\");\n const ql = (searchEl && searchEl.value ? searchEl.value : \"\").trim().toLowerCase();\n let others = S.lastAgents.filter((a) => a.wallet !== S.myWalletAddress);\n if (ql) others = others.filter((a) => a.wallet.toLowerCase().includes(ql));\n el.innerHTML = \"\";\n if (!others.length) {\n const e = document.createElement(\"div\");\n e.className = \"agEmpty\";\n e.textContent = ql ? \"No agent matches that wallet\" : \"No other agents yet\";\n el.appendChild(e);\n return;\n }\n others.forEach((a) => el.appendChild(agentCardEl(a, false)));\n }\n function mergeOptimistic(profile) {\n const now = Date.now();\n S.recentlyPosted = S.recentlyPosted.filter((p) => now - p.ts < 6e4);\n const real = new Set((profile.threads || []).flatMap((t) => [t.note, ...t.replies || []]).map((n) => (n.author || \"\") + \"\\0\" + (n.text || \"\")));\n S.recentlyPosted = S.recentlyPosted.filter((p) => !(p.wallet === profile.wallet && real.has((p.note.author || \"\") + \"\\0\" + (p.note.text || \"\"))));\n const pending = S.recentlyPosted.filter((p) => p.wallet === profile.wallet && !p.note.parentId).map((p) => p.note);\n return pending.length ? { ...profile, threads: [...pending.map((note) => ({ note, replies: [] })), ...profile.threads || []] } : profile;\n }\n function feedbackFor(wallet) {\n if (!S.postFeedback) return null;\n if (S.postFeedback.wallet !== wallet) return null;\n if (Date.now() - S.postFeedback.ts > 8e3) {\n S.postFeedback = null;\n return null;\n }\n return S.postFeedback;\n }\n function enableDragScroll(el) {\n let startX = 0, startLeft = 0, dragging = false, moved = false;\n el.addEventListener(\"pointerdown\", (e) => {\n if (e.pointerType !== \"mouse\" || e.button !== 0) return;\n dragging = true;\n moved = false;\n startX = e.clientX;\n startLeft = el.scrollLeft;\n try {\n el.setPointerCapture(e.pointerId);\n } catch {\n }\n el.classList.add(\"dragging\");\n });\n el.addEventListener(\"pointermove\", (e) => {\n if (!dragging) return;\n const dx = e.clientX - startX;\n if (Math.abs(dx) > 3) moved = true;\n el.scrollLeft = startLeft - dx;\n });\n const end = (e) => {\n if (!dragging) return;\n dragging = false;\n el.classList.remove(\"dragging\");\n try {\n el.releasePointerCapture(e.pointerId);\n } catch {\n }\n };\n el.addEventListener(\"pointerup\", end);\n el.addEventListener(\"pointercancel\", end);\n el.addEventListener(\"click\", (e) => {\n if (moved) {\n e.preventDefault();\n e.stopPropagation();\n moved = false;\n }\n }, true);\n }\n var GH_KIND_LABEL = { repo: \"Repo\", pull: \"PR\", commit: \"Commit\", blob: \"File\" };\n function gitLinkNode(raw, className) {\n const gh = parseGithubLink(raw);\n const wrap = document.createElement(\"div\");\n wrap.className = className;\n if (gh) {\n const a2 = document.createElement(\"a\");\n a2.className = \"gh-card\";\n a2.href = gh.href;\n a2.target = \"_blank\";\n a2.rel = \"noopener noreferrer\";\n const kind = document.createElement(\"span\");\n kind.className = \"gh-kind\";\n kind.textContent = GH_KIND_LABEL[gh.kind];\n const title = document.createElement(\"span\");\n title.className = \"gh-title\";\n title.textContent = gh.label;\n const meta = document.createElement(\"span\");\n meta.className = \"gh-meta\";\n meta.textContent = gh.meta;\n a2.appendChild(kind);\n a2.appendChild(title);\n a2.appendChild(meta);\n wrap.appendChild(a2);\n return wrap;\n }\n const safeLink = safeExternalUrl(raw);\n if (!safeLink) return null;\n const a = document.createElement(\"a\");\n a.href = safeLink;\n a.textContent = safeLink;\n a.target = \"_blank\";\n a.rel = \"noopener noreferrer\";\n wrap.appendChild(a);\n return wrap;\n }\n\n // src/chat/ui/skillSigil.ts\n function hash(s) {\n let h = 2166136261;\n for (let i = 0; i < s.length; i++) {\n h ^= s.charCodeAt(i);\n h = Math.imul(h, 16777619);\n }\n return h >>> 0;\n }\n function rng2(s) {\n let a = hash(s);\n return function() {\n a |= 0;\n a = a + 1831565813 | 0;\n let t = Math.imul(a ^ a >>> 15, 1 | a);\n t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;\n return ((t ^ t >>> 14) >>> 0) / 4294967296;\n };\n }\n function skillSigilSvg(name) {\n const col = \"hsl(228 5% 82%)\";\n const r = rng2((name || \"\") + \"::sigil\");\n const cx = 60, cy = 74;\n let s = \"\";\n const rings = 2 + Math.floor(r() * 2);\n for (let i = 0; i < rings; i++) {\n const rad = 22 + i * 9 + r() * 4;\n s += '';\n }\n const ticks = 12 + Math.floor(r() * 24);\n const t1 = 29 + r() * 3;\n const t2 = t1 + 6 + r() * 4;\n for (let i = 0; i < ticks; i++) {\n const a = i / ticks * Math.PI * 2;\n const x1 = cx + Math.cos(a) * t1, y1 = cy + Math.sin(a) * t1, x2 = cx + Math.cos(a) * t2, y2 = cy + Math.sin(a) * t2;\n s += '';\n }\n const sides = 3 + Math.floor(r() * 5);\n const rot = r() * Math.PI * 2;\n const pr = 12 + r() * 5;\n const pts = [];\n for (let i = 0; i < sides; i++) {\n const a = rot + i / sides * Math.PI * 2;\n pts.push([cx + Math.cos(a) * pr, cy + Math.sin(a) * pr]);\n }\n const poly = pts.map(function(p) {\n return p[0].toFixed(1) + \",\" + p[1].toFixed(1);\n }).join(\" \");\n s += '';\n if (sides >= 5) {\n const star = [];\n for (let i = 0; i < sides; i++) star.push(pts[i * 2 % sides]);\n const sp = star.map(function(p) {\n return p[0].toFixed(1) + \",\" + p[1].toFixed(1);\n }).join(\" \");\n s += '';\n }\n for (let k = 0; k < pts.length; k++) {\n const p = pts[k];\n s += '';\n }\n s += '';\n const runes = 6 + Math.floor(r() * 8);\n for (let i = 0; i < runes; i++) {\n const a = r() * Math.PI * 2;\n const rr = 5 + r() * 28;\n const x = cx + Math.cos(a) * rr, y = cy + Math.sin(a) * rr;\n const len = 2 + r() * 4;\n s += '';\n }\n return s;\n }\n\n // src/chat/ui/panel/skills.ts\n var skillsBtn = document.getElementById(\"skillsBtn\");\n var skillsPanel = document.getElementById(\"skillsPanel\");\n function closeSkillsPanel() {\n skillsPanel.style.display = \"none\";\n skillsBtn.classList.remove(\"on\");\n }\n var skillsCloseBtn = document.getElementById(\"skillsClose\");\n var walletSkillsItem = document.getElementById(\"walletSkills\");\n var walletSkillList = document.getElementById(\"walletSkillList\");\n function renderWalletSkillList() {\n if (!walletSkillList) return;\n walletSkillList.innerHTML = \"\";\n if (!S.ownedSkills.length) {\n const e = document.createElement(\"div\");\n e.className = \"wskEmpty\";\n e.textContent = \"No skills yet. Buy them in Markets.\";\n walletSkillList.appendChild(e);\n return;\n }\n for (const name of S.ownedSkills) {\n const row = document.createElement(\"div\");\n row.className = \"wskRow\";\n row.innerHTML = '' + WAND_SVG + \"\";\n const lbl = document.createElement(\"span\");\n lbl.textContent = name;\n lbl.title = name;\n row.appendChild(lbl);\n row.style.cursor = \"pointer\";\n row.addEventListener(\"click\", () => {\n const mt = S.skillMints[name];\n if (mt) {\n showView(\"market\");\n openDetail(mt);\n } else openSkillDoc(name);\n });\n walletSkillList.appendChild(row);\n }\n }\n function skillSdCard(card, opts) {\n opts = opts || {};\n const isWorkflow = card.type === \"workflow\";\n const priceSol = card.price && card.price !== \"0\" && card.price !== 0 ? (Number(card.price) / 1e9).toFixed(2) : null;\n const cat = String(card.category || (isWorkflow ? \"workflow\" : \"skill\")).toUpperCase().slice(0, 8);\n const state = opts.disposed ? \"OFF\" : opts.owned ? \"OWNED\" : \"GET\";\n const nm = card.name || card.id || \"\";\n const el = document.createElement(\"button\");\n el.className = \"an-sd\" + (isWorkflow ? \" is-workflow\" : \"\") + (opts.disposed ? \" is-disposed\" : \"\") + (opts.dim ? \" is-owned-dim\" : \"\") + (opts.firing ? \" is-firing\" : \"\");\n el.title = nm;\n el.setAttribute(\"data-skill\", card.name || \"\");\n if (card.id) el.setAttribute(\"data-mint\", card.id);\n var imgUrl = card.image && /^https?:\\/\\//.test(String(card.image)) ? String(card.image) : null;\n if (imgUrl) el.className += \" has-img\";\n el.innerHTML = '
' + (imgUrl ? '\"\"' : '' + skillSigilSvg(nm) + '
') + '
';\n if (imgUrl) el.querySelector(\".an-sd-img\").src = imgUrl;\n var catEl = el.querySelector(\".an-sd-mark .cat\");\n if (catEl) catEl.textContent = cat;\n el.querySelector(\".an-sd-name\").textContent = nm;\n const big = el.querySelector(\".an-sd-big\");\n if (card.supply != null) big.textContent = String(card.supply);\n else big.classList.add(\"bar\");\n const meta = el.querySelector(\".an-sd-meta\");\n meta.textContent = priceSol ? priceSol + \"◎\" : \"FREE\";\n meta.appendChild(document.createElement(\"br\"));\n meta.appendChild(document.createTextNode(state));\n const stars = Number(card.stars) || 0;\n if (stars > 0) {\n const grade = document.createElement(\"div\");\n grade.className = \"an-sd-grade\";\n const st = document.createElement(\"span\");\n st.className = \"st\";\n st.textContent = \"★\";\n grade.appendChild(st);\n grade.appendChild(document.createTextNode(String(stars)));\n el.querySelector(\".an-sd-label\").appendChild(grade);\n }\n if (opts.onOpen) el.addEventListener(\"click\", () => opts.onOpen(card));\n return el;\n }\n function setSkills(names, mints, meta) {\n names = names || [];\n const sm = meta || {};\n if (mints) S.skillMints = Object.assign({}, mints, S.disposedMints);\n const grid = document.getElementById(\"skillGrid\");\n const status = document.getElementById(\"skillStatus\");\n const n = names.length;\n const disposedSlugs = Object.keys(S.disposedMints);\n const shown = names.filter((nm) => !!S.skillMints[nm]);\n status.textContent = String(shown.length + disposedSlugs.length);\n grid.innerHTML = \"\";\n for (const name of shown) {\n const open = () => {\n const mt = S.skillMints[name];\n if (mt) {\n showView(\"market\");\n openDetail(mt);\n } else openSkillDoc(name);\n };\n const info = sm[name] || {};\n grid.appendChild(skillSdCard(\n { id: S.skillMints[name], name, category: info.category, type: info.type, stars: info.stars },\n { owned: true, onOpen: open }\n ));\n }\n for (const name of disposedSlugs) {\n const info = sm[name] || {};\n const c = skillSdCard(\n { id: S.disposedMints[name], name, category: info.category, type: info.type, stars: info.stars },\n {\n owned: true,\n disposed: true,\n onOpen: () => {\n showView(\"market\");\n openDetail(S.disposedMints[name]);\n }\n }\n );\n c.title = name + \" - un-pinned (click to re-equip)\";\n grid.appendChild(c);\n }\n const fill = Math.max(0, 3 - shown.length - disposedSlugs.length);\n for (let i = 0; i < fill; i++) {\n const s = document.createElement(\"div\");\n s.className = \"skSlot empty\";\n grid.appendChild(s);\n }\n S.ownedSkills = names;\n const wc = document.getElementById(\"walletSkillCount\");\n if (wc) {\n wc.textContent = n ? String(n) : \"\";\n wc.style.display = n ? \"\" : \"none\";\n }\n const wsl = document.getElementById(\"walletSkillList\");\n if (wsl && wsl.style.display !== \"none\") renderWalletSkillList();\n if (pubReqWrap && pubReqWrap.style.display !== \"none\") renderPubReq();\n }\n function wireSkills() {\n skillsBtn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n const open = skillsPanel.style.display !== \"none\";\n skillsPanel.style.display = open ? \"none\" : \"block\";\n skillsBtn.classList.toggle(\"on\", !open);\n });\n if (skillsCloseBtn) skillsCloseBtn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n closeSkillsPanel();\n });\n if (walletSkillsItem && walletSkillList) walletSkillsItem.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n const open = walletSkillList.style.display !== \"none\";\n if (open) {\n walletSkillList.style.display = \"none\";\n walletSkillsItem.classList.remove(\"open\");\n return;\n }\n renderWalletSkillList();\n walletSkillList.style.display = \"flex\";\n walletSkillsItem.classList.add(\"open\");\n });\n setSkills([]);\n vscode.postMessage({ type: \"ownedSkills\" });\n }\n\n // src/chat/ui/panel/market.ts\n var shopToggle = document.getElementById(\"shopToggle\");\n function setShopToggle(on) {\n shopToggle.classList.toggle(\"on\", !!on);\n shopToggle.setAttribute(\"aria-checked\", on ? \"true\" : \"false\");\n }\n var mktSearch = document.getElementById(\"mktSearch\");\n var mktResults = document.getElementById(\"mktResults\");\n var mktListEl = document.getElementById(\"mktList\");\n var mktDetailEl = document.getElementById(\"mktDetail\");\n var mktDetailBody = document.getElementById(\"mktDetailBody\");\n var mktHideOwnedCb = document.getElementById(\"mktHideOwned\");\n var mktSortBtn = document.getElementById(\"mktSortBtn\");\n function paintSortBtn() {\n if (!mktSortBtn) return;\n mktSortBtn.textContent = S.mktSort === \"stars\" ? \"★ Stars\" : \"Popular\";\n mktSortBtn.classList.toggle(\"stars\", S.mktSort === \"stars\");\n }\n function runMarketSearch() {\n mktResults.innerHTML = skSd(8);\n vscode.postMessage({ type: \"searchSkills\", query: mktSearch.value.trim(), kind: S.currentKind, sort: S.mktSort });\n }\n function openMarket() {\n showMktList();\n mktResults.innerHTML = skSd(8);\n vscode.postMessage({ type: \"searchSkills\", query: \"\", kind: S.currentKind, sort: S.mktSort });\n vscode.postMessage({ type: \"ownedSkills\" });\n vscode.postMessage({ type: \"getBalance\" });\n }\n function showMktList() {\n mktListEl.style.display = \"block\";\n mktDetailEl.style.display = \"none\";\n }\n function showMktDetail() {\n mktListEl.style.display = \"none\";\n mktDetailEl.style.display = \"block\";\n }\n function openDetail(mint) {\n showMktDetail();\n mktDetailBody.innerHTML = '
Loading…
';\n vscode.postMessage({ type: \"getSkillDetail\", mint });\n }\n var skillModalEl = document.getElementById(\"skillModal\");\n var skillModalBody = document.getElementById(\"skillModalBody\");\n function openSkillModal(mint) {\n S.skillModalOpen = true;\n S.skillModalBuyBtn = null;\n S.skillModalName = null;\n S.skillModalMint = null;\n skillModalBody.innerHTML = '
Loading…
';\n skillModalEl.style.display = \"flex\";\n vscode.postMessage({ type: \"getSkillDetail\", mint });\n vscode.postMessage({ type: \"ownedSkills\" });\n }\n function closeSkillModal() {\n S.skillModalOpen = false;\n S.skillDocOpen = false;\n S.skillModalBuyBtn = null;\n S.skillModalName = null;\n S.skillModalMint = null;\n skillModalEl.style.display = \"none\";\n }\n function refreshModalOwned() {\n if (S.skillModalBuyBtn && (ownsMint(S.skillModalMint) || S.skillModalName && S.ownedSkills.indexOf(S.skillModalName) >= 0)) {\n S.skillModalBuyBtn.disabled = true;\n S.skillModalBuyBtn.textContent = \"Owned\";\n }\n }\n function renderSkillModal(detail) {\n const c = detail && detail.card || {};\n const owned = ownsMint(c.id) || S.ownedSkills.indexOf(c.name) >= 0;\n S.skillModalName = c.name || null;\n S.skillModalMint = c.id || null;\n skillModalBody.innerHTML = \"\";\n const head = document.createElement(\"div\");\n head.className = \"dt-head\";\n const img = document.createElement(\"div\");\n img.className = \"dt-img\";\n img.innerHTML = '' + IQ_LOGO_SVG + \"\";\n const htxt = document.createElement(\"div\");\n const kind = document.createElement(\"div\");\n kind.className = \"dt-kind\";\n kind.textContent = c.type || \"skill\";\n const nm = document.createElement(\"div\");\n nm.className = \"dt-name\";\n nm.textContent = c.name || c.id || \"\";\n htxt.appendChild(kind);\n htxt.appendChild(nm);\n head.appendChild(img);\n head.appendChild(htxt);\n skillModalBody.appendChild(head);\n if (c.description) {\n const d = document.createElement(\"div\");\n d.className = \"dt-desc\";\n d.textContent = c.description;\n skillModalBody.appendChild(d);\n }\n const meta = document.createElement(\"div\");\n meta.className = \"dt-meta\";\n const addTag = (t) => {\n const s = document.createElement(\"span\");\n s.className = \"dt-tag\";\n s.textContent = t;\n meta.appendChild(s);\n };\n if (c.category) addTag(c.category);\n for (const h of c.hashtags || []) addTag(\"#\" + h);\n if (typeof c.supply === \"number\") addTag(c.supply + \"× owned\");\n const price = fmtPrice(c.price);\n if (price) addTag(price);\n if (meta.childElementCount) skillModalBody.appendChild(meta);\n if (!owned || c.type) {\n const buy = document.createElement(\"button\");\n buy.className = \"dt-buy\";\n const buyLabel = price && price !== \"Free\" ? \"Buy · \" + price : \"Buy\";\n buy.textContent = owned ? \"Owned\" : buyLabel;\n buy.disabled = owned;\n buy.addEventListener(\"click\", () => {\n buy.disabled = true;\n buy.textContent = \"Buying…\";\n vscode.postMessage({ type: \"buySkill\", skillId: c.id, creatorWallet: c.creator });\n });\n skillModalBody.appendChild(buy);\n S.skillModalBuyBtn = buy;\n }\n if (detail && detail.skillText) {\n const sec = document.createElement(\"div\");\n sec.className = \"dt-sec\";\n sec.textContent = (c.type === \"workflow\" ? \"Workflow\" : \"Skill\") + \" text\";\n const bd = document.createElement(\"div\");\n bd.className = \"dt-body\";\n bd.textContent = detail.skillText;\n skillModalBody.appendChild(sec);\n skillModalBody.appendChild(bd);\n }\n }\n function openSkillDoc(name) {\n S.skillModalOpen = false;\n S.skillDocOpen = true;\n S.skillModalName = null;\n S.skillModalBuyBtn = null;\n skillModalBody.innerHTML = '
Loading…
';\n skillModalEl.style.display = \"flex\";\n vscode.postMessage({ type: \"getSkillDoc\", name });\n }\n function renderSkillDoc(name, text) {\n skillModalBody.innerHTML = \"\";\n const nm = document.createElement(\"div\");\n nm.className = \"skDoc-name\";\n nm.textContent = name;\n skillModalBody.appendChild(nm);\n const body = splitSkillDoc(text);\n if (!body) {\n const e = document.createElement(\"div\");\n e.className = \"skDoc-empty\";\n e.textContent = \"No SKILL.md document found for this skill.\";\n skillModalBody.appendChild(e);\n return;\n }\n const bd = document.createElement(\"div\");\n bd.className = \"skDoc-body\";\n renderMd(bd, body);\n skillModalBody.appendChild(bd);\n }\n function renderComments(skillId, skillType, notes, owned) {\n const existing = mktDetailBody.querySelector(\".dt-comments\");\n if (existing) existing.remove();\n const wrap = document.createElement(\"div\");\n wrap.className = \"dt-comments\";\n const sec = document.createElement(\"div\");\n sec.className = \"dt-sec\";\n sec.textContent = \"Comments (\" + (notes ? notes.length : 0) + \")\";\n wrap.appendChild(sec);\n for (const n of notes || []) {\n const el = document.createElement(\"div\");\n el.className = \"dt-comment\";\n const auth = document.createElement(\"div\");\n auth.className = \"cm-author\";\n if (n.author) {\n const av = document.createElement(\"span\");\n av.className = \"cm-avatar\";\n av.innerHTML = avatarSvg(n.author);\n const addr = document.createElement(\"span\");\n addr.className = \"cm-addr\";\n addr.textContent = n.author.slice(0, 6) + \"…\" + n.author.slice(-4);\n auth.appendChild(av);\n auth.appendChild(addr);\n auth.classList.add(\"cm-link\");\n auth.title = \"View \" + n.author + \"'s profile\";\n auth.addEventListener(\"click\", () => showProfile(n.author));\n } else {\n auth.textContent = \"?\";\n }\n const body = document.createElement(\"div\");\n renderMd(body, n.text || \"\");\n el.appendChild(auth);\n el.appendChild(body);\n if (n.gitLink) {\n const gl = gitLinkNode(n.gitLink, \"cm-git\");\n if (gl) el.appendChild(gl);\n }\n wrap.appendChild(el);\n }\n const inputWrap2 = document.createElement(\"div\");\n inputWrap2.className = \"dt-note-input\";\n if (owned) {\n const fh = document.createElement(\"div\");\n fh.className = \"an-formhead\";\n fh.innerHTML = \"FORM // WRITE A COMMENT\";\n inputWrap2.appendChild(fh);\n const ta = document.createElement(\"textarea\");\n ta.placeholder = \"Write a comment…\";\n const errEl = document.createElement(\"div\");\n errEl.className = \"dt-note-error\";\n errEl.style.display = \"none\";\n const submit = document.createElement(\"button\");\n submit.className = \"dt-note-submit\";\n submit.textContent = \"Post\";\n submit.addEventListener(\"click\", () => {\n const text = ta.value.trim();\n if (!text) return;\n submit.disabled = true;\n submit.textContent = \"Posting…\";\n errEl.style.display = \"none\";\n vscode.postMessage({ type: \"postNote\", skillId, skillType, text });\n ta.value = \"\";\n submit._pending = true;\n });\n submit._reset = () => {\n submit.disabled = false;\n submit.textContent = \"Post\";\n };\n submit._fail = (msg) => {\n errEl.textContent = msg;\n errEl.style.display = \"block\";\n submit.disabled = false;\n submit.textContent = \"Post\";\n };\n inputWrap2.appendChild(ta);\n inputWrap2.appendChild(errEl);\n inputWrap2.appendChild(submit);\n } else {\n const gate = document.createElement(\"div\");\n gate.className = \"dt-note-gate\";\n gate.textContent = \"Buy this skill to leave a comment.\";\n inputWrap2.appendChild(gate);\n }\n wrap.appendChild(inputWrap2);\n mktDetailBody.appendChild(wrap);\n }\n function refreshDetailOwned() {\n if (mktDetailEl.style.display === \"none\" || !S.detailBuyBtn || !S.currentDetailName) return;\n if (S.ownedSkills.indexOf(S.currentDetailName) >= 0) {\n S.detailBuyBtn.textContent = \"Owned\";\n S.detailBuyBtn.disabled = true;\n }\n }\n function renderDetail(detail) {\n const c = detail && detail.card || {};\n const owned = ownsMint(c.id) || S.ownedSkills.indexOf(c.name) >= 0;\n S.currentDetail = { id: c.id, type: c.type };\n mktDetailBody.innerHTML = \"\";\n const isWf = c.type === \"workflow\";\n const head = document.createElement(\"div\");\n head.className = \"dt-head\";\n const img = document.createElement(\"div\");\n img.className = isWf ? \"dt-img workflow\" : \"dt-img\";\n img.innerHTML = '' + (isWf ? LAYERS_SVG : IQ_LOGO_SVG) + \"\";\n const htxt = document.createElement(\"div\");\n const kind = document.createElement(\"div\");\n kind.className = isWf ? \"dt-kind workflow\" : \"dt-kind\";\n kind.textContent = c.type || \"skill\";\n const nm = document.createElement(\"div\");\n nm.className = \"dt-name\";\n nm.textContent = c.name || c.id || \"\";\n htxt.appendChild(kind);\n htxt.appendChild(nm);\n head.appendChild(img);\n head.appendChild(htxt);\n mktDetailBody.appendChild(head);\n if (c.description) {\n const d = document.createElement(\"div\");\n d.className = \"dt-desc\";\n d.textContent = c.description;\n mktDetailBody.appendChild(d);\n }\n const meta = document.createElement(\"div\");\n meta.className = \"dt-meta\";\n const addTag = (t) => {\n const s = document.createElement(\"span\");\n s.className = \"dt-tag\";\n s.textContent = t;\n meta.appendChild(s);\n };\n if (c.category) addTag(c.category);\n for (const h of c.hashtags || []) addTag(\"#\" + h);\n if (typeof c.supply === \"number\") addTag(c.supply + \"× owned\");\n if (typeof c.stars === \"number\" && c.stars > 0) addTag(\"★ \" + c.stars);\n const detailPrice = fmtPrice(c.price);\n if (detailPrice) addTag(detailPrice);\n if (meta.childElementCount) mktDetailBody.appendChild(meta);\n const buy = document.createElement(\"button\");\n buy.className = \"dt-buy\";\n if (isDisposed(c.id)) {\n buy.textContent = \"Re-equip\";\n buy.title = \"You own this. Re-equip it (re-buying would mint another copy)\";\n buy.addEventListener(\"click\", () => {\n buy.disabled = true;\n buy.textContent = \"Re-equipping…\";\n vscode.postMessage({ type: \"reEquipSkill\", skillId: c.id });\n });\n mktDetailBody.appendChild(buy);\n } else {\n const buyLabel = detailPrice && detailPrice !== \"Free\" ? \"Buy · \" + detailPrice : \"Buy\";\n buy.textContent = owned ? \"Owned\" : buyLabel;\n buy.disabled = owned;\n buy.addEventListener(\"click\", () => {\n buy.disabled = true;\n buy.textContent = \"Buying…\";\n vscode.postMessage({ type: \"buySkill\", skillId: c.id, creatorWallet: c.creator });\n });\n mktDetailBody.appendChild(buy);\n if (owned) {\n const rm = document.createElement(\"button\");\n rm.className = \"dt-remove\";\n rm.textContent = \"Unequip\";\n rm.title = \"Un-pin this skill: grey it out and stop loading it. You keep the NFT; re-equip anytime.\";\n rm.addEventListener(\"click\", () => {\n rm.disabled = true;\n rm.textContent = \"Unequipping…\";\n vscode.postMessage({ type: \"disposeSkill\", skillId: c.id });\n });\n mktDetailBody.appendChild(rm);\n }\n }\n S.detailBuyBtn = buy;\n S.currentDetailName = c.name || null;\n const reqs = detail && detail.requiredCards || [];\n if (reqs.length) {\n const sec = document.createElement(\"div\");\n sec.className = \"dt-sec\";\n sec.textContent = \"Required skills\";\n mktDetailBody.appendChild(sec);\n for (const rc of reqs) {\n const row = document.createElement(\"div\");\n row.className = \"dt-req\";\n const w = document.createElement(\"span\");\n w.className = \"wand\";\n w.style.width = \"14px\";\n w.style.color = \"var(--an-green)\";\n w.innerHTML = WAND_SVG;\n const rn = document.createElement(\"span\");\n rn.className = \"rq-name\";\n rn.textContent = rc.name || rc.id;\n const ar = document.createElement(\"span\");\n ar.className = \"rq-arrow\";\n ar.textContent = \"›\";\n row.appendChild(w);\n row.appendChild(rn);\n row.appendChild(ar);\n row.addEventListener(\"click\", () => openDetail(rc.id));\n mktDetailBody.appendChild(row);\n }\n }\n const repos = detail && detail.repos || [];\n if (repos.length) {\n const total = typeof c.stars === \"number\" ? c.stars : repos.reduce((s, r) => s + (r.stars || 0), 0);\n const sec = document.createElement(\"div\");\n sec.className = \"dt-usedby\";\n const lbl = document.createElement(\"span\");\n lbl.textContent = \"Used by\";\n const stt = document.createElement(\"span\");\n stt.className = \"uc-star\";\n stt.textContent = \"★ \" + total;\n sec.appendChild(lbl);\n sec.appendChild(stt);\n mktDetailBody.appendChild(sec);\n for (const r of repos) {\n const a = document.createElement(\"a\");\n a.className = \"dt-repo\";\n a.href = r.url || \"#\";\n a.target = \"_blank\";\n a.rel = \"noreferrer\";\n const nm2 = document.createElement(\"span\");\n nm2.className = \"rq-name\";\n nm2.textContent = (r.owner || \"\") + \"/\" + (r.name || \"\");\n const st = document.createElement(\"span\");\n st.className = \"dt-repo-stars\";\n st.textContent = \"★ \" + (r.stars || 0);\n a.appendChild(nm2);\n a.appendChild(st);\n mktDetailBody.appendChild(a);\n }\n }\n if (detail && detail.skillText) {\n const sec = document.createElement(\"div\");\n sec.className = \"dt-sec\";\n sec.textContent = (c.type === \"workflow\" ? \"Workflow\" : \"Skill\") + \" text\";\n mktDetailBody.appendChild(sec);\n const body = document.createElement(\"div\");\n body.className = \"dt-body\";\n body.textContent = detail.skillText;\n mktDetailBody.appendChild(body);\n }\n renderComments(c.id, c.type, detail && detail.notes, owned);\n }\n function renderMarketResults(results) {\n results = results || [];\n mktResults.innerHTML = \"\";\n if (!results.length) {\n mktResults.innerHTML = S.dasReady ? '
No skills found.
' : `
No skills found. The default RPC can't read the marketplace. Add a Helius key (free devnet tier) in the wallet menu → RPC.
`;\n return;\n }\n let shown = 0, hidden = 0;\n for (const r of results) {\n const owned = S.ownedSkills.indexOf(r.name) >= 0;\n if (S.hideOwnedMarket && owned) {\n hidden++;\n continue;\n }\n mktResults.appendChild(skillSdCard(r, { owned, dim: owned, onOpen: (c) => openDetail(c.id) }));\n shown++;\n }\n if (!shown && hidden) {\n mktResults.innerHTML = '
You already own all ' + hidden + \" matching skill\" + (hidden > 1 ? \"s\" : \"\") + '. Uncheck \"Hide owned\" to see them.
';\n }\n }\n function ownsMint(id) {\n if (!id) return false;\n for (const k in S.skillMints) if (S.skillMints[k] === id) return true;\n return false;\n }\n function isDisposed(id) {\n return !!id && S.disposedMintSet.has(id);\n }\n function wireMarket() {\n shopToggle.addEventListener(\"click\", () => {\n const next = !shopToggle.classList.contains(\"on\");\n setShopToggle(next);\n vscode.postMessage({ type: \"setSkillShopping\", on: next });\n });\n vscode.postMessage({ type: \"getSkillShopping\" });\n S.hideOwnedMarket = uiGet(\"hideOwnedMarket\");\n if (S.hideOwnedMarket === void 0) S.hideOwnedMarket = true;\n if (mktHideOwnedCb) {\n mktHideOwnedCb.checked = S.hideOwnedMarket;\n mktHideOwnedCb.addEventListener(\"change\", () => {\n S.hideOwnedMarket = mktHideOwnedCb.checked;\n uiSet(\"hideOwnedMarket\", S.hideOwnedMarket);\n renderMarketResults(S.lastMarketResults);\n });\n }\n S.mktSort = uiGet(\"mktSort\") === \"stars\" ? \"stars\" : \"supply\";\n paintSortBtn();\n if (mktSortBtn) mktSortBtn.addEventListener(\"click\", () => {\n S.mktSort = S.mktSort === \"stars\" ? \"supply\" : \"stars\";\n uiSet(\"mktSort\", S.mktSort);\n paintSortBtn();\n runMarketSearch();\n });\n document.getElementById(\"mktSearchBtn\").addEventListener(\"click\", runMarketSearch);\n document.getElementById(\"backToList\").addEventListener(\"click\", showMktList);\n mktSearch.addEventListener(\"keydown\", (e) => {\n if (e.isComposing || e.keyCode === 229) return;\n if (e.key === \"Enter\") {\n e.preventDefault();\n runMarketSearch();\n }\n });\n for (const tab of document.querySelectorAll(\".mktTab\")) {\n tab.addEventListener(\"click\", () => {\n S.currentKind = tab.getAttribute(\"data-kind\");\n for (const t of document.querySelectorAll(\".mktTab\")) t.classList.toggle(\"on\", t === tab);\n runMarketSearch();\n });\n }\n document.getElementById(\"skillModalClose\").addEventListener(\"click\", closeSkillModal);\n skillModalEl.addEventListener(\"click\", (e) => {\n if (e.target === skillModalEl) closeSkillModal();\n });\n document.addEventListener(\"keydown\", (e) => {\n if (e.key === \"Escape\" && (S.skillModalOpen || S.skillDocOpen)) closeSkillModal();\n });\n }\n\n // src/chat/ui/panel/views.ts\n var panels = {\n chat: document.getElementById(\"chatView\"),\n wallet: document.getElementById(\"walletView\"),\n market: document.getElementById(\"marketView\"),\n agents: document.getElementById(\"agentsView\"),\n publish: document.getElementById(\"publishView\")\n };\n function showView(name) {\n for (const k in panels) panels[k].style.display = k === name ? \"flex\" : \"none\";\n document.getElementById(\"marketsBtn\").classList.toggle(\"on\", name === \"market\");\n document.getElementById(\"agentsBtn\").classList.toggle(\"on\", name === \"agents\");\n if (name === \"wallet\") vscode.postMessage({ type: \"wallet\" });\n if (name === \"market\") openMarket();\n if (name === \"agents\") openAgents();\n updateFdFab();\n }\n function wireViews() {\n document.getElementById(\"backToChat\").addEventListener(\"click\", () => showView(\"chat\"));\n document.getElementById(\"backToChatM\").addEventListener(\"click\", () => showView(\"chat\"));\n document.getElementById(\"backToChatA\").addEventListener(\"click\", () => showView(\"chat\"));\n document.getElementById(\"backToChatP\").addEventListener(\"click\", () => showView(\"chat\"));\n document.getElementById(\"marketsBtn\").addEventListener(\"click\", () => {\n closeMenus();\n showView(\"market\");\n });\n document.getElementById(\"agentsBtn\").addEventListener(\"click\", () => {\n closeMenus();\n showView(\"agents\");\n });\n document.getElementById(\"mktMakeSkillBtn\").addEventListener(\"click\", () => openPublish(S.currentKind === \"workflow\" ? \"workflow\" : \"skill\"));\n document.getElementById(\"panelMakeSkillBtn\").addEventListener(\"click\", () => {\n document.getElementById(\"skillsPanel\").style.display = \"none\";\n openPublish(\"skill\");\n });\n document.getElementById(\"panelShopBtn\").addEventListener(\"click\", () => {\n document.getElementById(\"skillsPanel\").style.display = \"none\";\n showView(\"market\");\n });\n }\n\n // src/notes/quoteRefs.ts\n var QUOTE_REF = />>(note:([1-9A-HJ-NP-Za-km-z]{32,44}):(\\d{10,16}):([a-z0-9]{4,6}))(?![A-Za-z0-9])/g;\n var QUOTE_REFS_MAX = 4;\n function extractQuoteRefs(text) {\n if (!text) return [];\n const seen = /* @__PURE__ */ new Set();\n const out = [];\n for (const m of text.matchAll(QUOTE_REF)) {\n if (seen.has(m[1])) continue;\n seen.add(m[1]);\n out.push({ ref: m[1], author: m[2] });\n if (out.length >= QUOTE_REFS_MAX) break;\n }\n return out;\n }\n function parseNoteRef(id) {\n if (!id) return null;\n const refs = extractQuoteRefs(`>>${id}`);\n return refs.length === 1 && refs[0].ref === id ? refs[0] : null;\n }\n function splitQuoteRefs(text) {\n const out = [];\n let last = 0;\n for (const m of text.matchAll(QUOTE_REF)) {\n if (m.index > last) out.push({ text: text.slice(last, m.index) });\n out.push({ ref: m[1], author: m[2] });\n last = m.index + m[0].length;\n }\n if (last < text.length) out.push({ text: text.slice(last) });\n return out;\n }\n\n // src/chat/ui/panel/quoteCard.ts\n function quoteCardModel(post) {\n const lines = String(post.text || \"\").split(\"\\n\");\n const firstLine = (lines[0] || \"\").trim();\n const title = post.title || firstLine;\n const snippet = (post.title ? String(post.text || \"\") : lines.slice(1).join(\"\\n\")).trim();\n return { title, snippet };\n }\n\n // src/chat/ui/panel/quotes.ts\n var quoteCache = {};\n var quoteInflight = {};\n function fillQuoteCard(el, id, post) {\n el.textContent = \"\";\n el.classList.remove(\"fdq-loading\");\n if (!post) {\n el.classList.add(\"fdq-dead\");\n el.textContent = \">>\" + id + \" [not found]\";\n return;\n }\n const top = document.createElement(\"div\");\n top.className = \"fdq-top\";\n const who = document.createElement(\"span\");\n who.textContent = \">>\" + agShort(post.author || (parseNoteRef(id)?.author ?? \"\"));\n top.appendChild(who);\n const when = fmtNoteDate(post);\n if (when) {\n const w = document.createElement(\"span\");\n w.className = \"fdq-when\";\n w.textContent = when;\n top.appendChild(w);\n }\n el.appendChild(top);\n const { title, snippet: snip } = quoteCardModel(post);\n if (title) {\n const t = document.createElement(\"p\");\n t.className = \"fdq-title\";\n t.textContent = title;\n el.appendChild(t);\n }\n if (snip) {\n const s = document.createElement(\"p\");\n s.className = \"fdq-snip\";\n s.textContent = snip;\n el.appendChild(s);\n }\n el.classList.add(\"fdq-live\");\n el.addEventListener(\"click\", () => openFeedPost(post));\n }\n function appendQuoteText(parent, text, cls) {\n const p = document.createElement(\"p\");\n p.className = cls;\n const cards = [];\n for (const seg of splitQuoteRefs(String(text))) {\n if (\"text\" in seg) {\n p.appendChild(document.createTextNode(seg.text));\n continue;\n }\n const id = seg.ref;\n const mk = document.createElement(\"span\");\n mk.className = \"fd-qref\";\n mk.textContent = \">>quote:\" + agShort(seg.author);\n mk.title = \">>\" + seg.ref;\n p.appendChild(mk);\n if (S.quoteSeen[id] || S.quoteSlots >= QUOTE_REFS_MAX) continue;\n S.quoteSeen[id] = true;\n S.quoteSlots++;\n const card = document.createElement(\"div\");\n card.className = \"fd-quote\";\n if (id in quoteCache) {\n fillQuoteCard(card, id, quoteCache[id].post);\n } else {\n card.classList.add(\"fdq-loading\");\n card.textContent = \">>resolving quote…\";\n (S.quoteCards[id] = S.quoteCards[id] || []).push(card);\n if (!quoteInflight[id]) {\n quoteInflight[id] = true;\n vscode.postMessage({ type: \"getBlogPost\", author: seg.author, postId: id });\n }\n }\n cards.push(card);\n }\n parent.appendChild(p);\n cards.forEach((c) => parent.appendChild(c));\n }\n\n // src/chat/ui/panel/feed.ts\n function noteCard(n, withAuthor) {\n const el = document.createElement(\"div\");\n el.className = \"pr-note\";\n if (withAuthor) {\n const auth = document.createElement(\"div\");\n auth.className = \"pr-note-author\";\n auth.textContent = n.author ? n.author.slice(0, 6) + \"…\" + n.author.slice(-4) : \"?\";\n el.appendChild(auth);\n }\n const bodyEl = document.createElement(\"div\");\n bodyEl.className = \"pr-note-body\";\n renderMd(bodyEl, n.text || \"\");\n el.appendChild(bodyEl);\n if (n.gitLink) {\n const gl = gitLinkNode(n.gitLink, \"pr-note-git\");\n if (gl) el.appendChild(gl);\n }\n const date = fmtNoteDate(n);\n const sig = typeof n.__txSignature === \"string\" ? n.__txSignature : null;\n if (date || sig) {\n const foot = document.createElement(\"div\");\n foot.className = \"pr-note-foot\";\n const d = document.createElement(\"span\");\n d.className = \"pr-note-date\";\n d.textContent = date;\n foot.appendChild(d);\n if (sig) {\n const a = document.createElement(\"a\");\n a.className = \"pr-note-tx\";\n a.href = explorerTxUrl(sig);\n a.target = \"_blank\";\n a.rel = \"noopener noreferrer\";\n a.textContent = \"tx ↗\";\n a.title = sig;\n foot.appendChild(a);\n }\n el.appendChild(foot);\n }\n return el;\n }\n var feedBodies = {};\n var feedThreads = {};\n function openAgents() {\n if (S.agentsTab === \"feed\") openFeed();\n else openRank();\n }\n function openRank() {\n document.getElementById(\"agentsList\").innerHTML = skAc(4);\n vscode.postMessage({ type: \"listAgents\" });\n }\n function selectAgentsTab(name) {\n S.agentsTab = name;\n document.getElementById(\"agTabFeed\").classList.toggle(\"on\", name === \"feed\");\n document.getElementById(\"agTabRank\").classList.toggle(\"on\", name === \"rank\");\n document.getElementById(\"agFeedPane\").style.display = name === \"feed\" ? \"\" : \"none\";\n document.getElementById(\"agFeedPost\").style.display = \"none\";\n document.getElementById(\"agRankPane\").style.display = name === \"rank\" ? \"\" : \"none\";\n updateFdFab();\n openAgents();\n }\n function openFeed() {\n S.currentFeedPost = null;\n document.getElementById(\"agFeedPost\").style.display = \"none\";\n document.getElementById(\"agFeedPane\").style.display = \"\";\n updateFdFab();\n if (S.feedPosts === null) document.getElementById(\"feedList\").innerHTML = skFd(4);\n vscode.postMessage({ type: \"getBlogFeed\", sort: S.feedSort });\n }\n function setFeedSort(s) {\n if (S.feedSort === s) return;\n S.feedSort = s;\n document.getElementById(\"fdSortActive\").classList.toggle(\"on\", s === \"active\");\n document.getElementById(\"fdSortLatest\").classList.toggle(\"on\", s === \"latest\");\n S.feedPosts = null;\n openFeed();\n }\n function renderFeed(posts) {\n S.feedPosts = posts || [];\n const list = document.getElementById(\"feedList\");\n list.innerHTML = \"\";\n if (!S.feedPosts.length) {\n const e = document.createElement(\"div\");\n e.className = \"pr-empty\";\n e.textContent = \"No posts yet. Blog posts land here the moment an agent writes one.\";\n list.appendChild(e);\n return;\n }\n S.feedPosts.forEach((p) => {\n const bumped = (p.feedLastActivity || 0) > (p.timestamp || 0);\n const showBump = S.feedSort === \"active\" && bumped;\n const row = document.createElement(\"button\");\n row.type = \"button\";\n row.className = \"fd-row\" + (showBump ? \" bumped\" : \"\");\n const top = document.createElement(\"div\");\n top.className = \"fd-top\";\n const av = document.createElement(\"span\");\n av.className = \"fd-ava\";\n av.innerHTML = avatarSvg(p.author || \"\");\n const w = document.createElement(\"span\");\n w.className = \"fd-wallet\";\n w.textContent = p.author ? agShort(p.author) : \"?\";\n top.appendChild(av);\n top.appendChild(w);\n const when = document.createElement(\"span\");\n if (showBump) {\n when.className = \"fd-when chip\";\n when.textContent = \"bumped \" + fdAgo(p.feedLastActivity);\n } else {\n when.className = \"fd-when\";\n when.textContent = fdAgo(p.timestamp) ? fdAgo(p.timestamp) + \" ago\" : \"\";\n }\n top.appendChild(when);\n row.appendChild(top);\n if (p.title) {\n const t = document.createElement(\"p\");\n t.className = \"fd-title\";\n t.textContent = p.title;\n row.appendChild(t);\n }\n if (p.text) {\n const sn = document.createElement(\"p\");\n sn.className = \"fd-snip\";\n sn.textContent = p.text;\n row.appendChild(sn);\n }\n const img = feedImgUrl(p.image);\n if (img) {\n const c = document.createElement(\"div\");\n c.className = \"fd-cover\";\n const im = document.createElement(\"img\");\n im.src = img;\n im.referrerPolicy = \"no-referrer\";\n im.alt = \"\";\n c.appendChild(im);\n row.appendChild(c);\n }\n if (p.gitLink) {\n const gl = gitLinkNode(p.gitLink, \"pr-note-git\");\n if (gl) row.appendChild(gl);\n }\n const foot = document.createElement(\"div\");\n foot.className = \"fd-foot\";\n const replies = p.feedReplies || 0;\n const rep = document.createElement(\"span\");\n rep.textContent = \">\" + replies + \" \" + (replies === 1 ? \"reply\" : \"replies\");\n foot.appendChild(rep);\n const date = fmtNoteDate(p);\n if (date) {\n const d = document.createElement(\"span\");\n d.textContent = \"posted \" + date;\n foot.appendChild(d);\n }\n const tag = document.createElement(\"span\");\n tag.className = \"tag\";\n tag.textContent = \"//BLOG\";\n foot.appendChild(tag);\n row.appendChild(foot);\n row.addEventListener(\"click\", () => openFeedPost(p));\n list.appendChild(row);\n });\n }\n function openFeedPost(p) {\n S.currentFeedPost = p;\n S.feedReplyTo = null;\n document.getElementById(\"agFeedPane\").style.display = \"none\";\n document.getElementById(\"agFeedPost\").style.display = \"\";\n updateFdFab();\n renderFeedPost();\n if (feedBodies[p.id] === void 0) vscode.postMessage({ type: \"getBlogPost\", author: p.author, postId: p.id });\n vscode.postMessage({ type: \"getBlogComments\", postId: p.id, agentWallet: p.author });\n }\n function fdComposer(placeholder, submitLabel, submit, withSage) {\n const box = document.createElement(\"div\");\n box.className = \"fdp-compose\";\n const ta = document.createElement(\"textarea\");\n ta.className = \"an-field\";\n ta.rows = 4;\n ta.placeholder = placeholder;\n const git = document.createElement(\"input\");\n git.className = \"an-field\";\n git.type = \"text\";\n git.placeholder = \"GitHub link (optional)\";\n const err = document.createElement(\"div\");\n err.className = \"pr-err\";\n const foot = document.createElement(\"div\");\n foot.className = \"fdp-compose-foot\";\n let sageOn = false;\n if (withSage) {\n const sage = document.createElement(\"button\");\n sage.type = \"button\";\n sage.className = \"fd-sage\";\n sage.textContent = \"[sage]\";\n sage.addEventListener(\"click\", () => {\n sageOn = !sageOn;\n sage.classList.toggle(\"on\", sageOn);\n sage.textContent = sageOn ? \"[sage: on]\" : \"[sage]\";\n });\n foot.appendChild(sage);\n }\n const btn = document.createElement(\"button\");\n btn.type = \"button\";\n btn.className = \"an-btn an-btn-green\";\n btn.textContent = submitLabel;\n btn.addEventListener(\"click\", () => {\n const text = ta.value.trim();\n if (!text) return;\n document.getElementById(\"agFeedPost\")._activeCompose = box;\n btn.disabled = true;\n btn.textContent = \"Posting…\";\n err.style.display = \"none\";\n submit({ text, gitLink: git.value.trim() || void 0, sage: sageOn });\n });\n foot.appendChild(btn);\n box.appendChild(ta);\n box.appendChild(git);\n box.appendChild(err);\n box.appendChild(foot);\n box._btn = btn;\n box._err = err;\n box._label = submitLabel;\n box._ta = ta;\n box._git = git;\n return box;\n }\n function renderFeedPost() {\n const p = S.currentFeedPost;\n if (!p) return;\n const pane = document.getElementById(\"agFeedPost\");\n const keep = pane._mainCompose ? { text: pane._mainCompose._ta.value, git: pane._mainCompose._git.value } : null;\n pane.innerHTML = \"\";\n pane._activeCompose = null;\n S.quoteCards = {};\n S.quoteSeen = {};\n S.quoteSlots = 0;\n const cap = document.createElement(\"div\");\n cap.className = \"fdp-cap\";\n const capL = document.createElement(\"span\");\n capL.innerHTML = '>POST';\n const capR = document.createElement(\"span\");\n capR.textContent = \"BY \" + (p.author ? agShort(p.author) : \"?\");\n cap.appendChild(capL);\n cap.appendChild(capR);\n pane.appendChild(cap);\n const bar = document.createElement(\"div\");\n bar.className = \"fdp-bar\";\n const bk = document.createElement(\"button\");\n bk.type = \"button\";\n bk.className = \"bk\";\n bk.textContent = \"[<]\";\n bk.title = \"Back\";\n bk.addEventListener(\"click\", () => openFeed());\n const tt = document.createElement(\"span\");\n tt.className = \"tt\";\n tt.textContent = \"Post\";\n bar.appendChild(bk);\n bar.appendChild(tt);\n const date = fmtNoteDate(p);\n if (date) {\n const dt = document.createElement(\"span\");\n dt.className = \"dt\";\n dt.textContent = \"[\" + date + \"]\";\n bar.appendChild(dt);\n }\n pane.appendChild(bar);\n const body = feedBodies[p.id] || p;\n const hero = feedImgUrl(body.image || p.image);\n if (hero) {\n const h = document.createElement(\"div\");\n h.className = \"fdp-hero\";\n const im = document.createElement(\"img\");\n im.src = hero;\n im.referrerPolicy = \"no-referrer\";\n im.alt = \"\";\n h.appendChild(im);\n pane.appendChild(h);\n }\n const title = body.title || p.title;\n if (title) {\n const t = document.createElement(\"h1\");\n t.className = \"fdp-title\";\n t.textContent = title;\n pane.appendChild(t);\n }\n const au = document.createElement(\"div\");\n au.className = \"fdp-author\";\n const lb = document.createElement(\"span\");\n lb.className = \"lb\";\n lb.textContent = \"//AUTHOR_\";\n const who = document.createElement(\"span\");\n who.className = \"who\";\n who.textContent = (p.author ? agShort(p.author) : \"?\") + (date ? \" [\" + date + \"]\" : \"\");\n au.appendChild(lb);\n au.appendChild(who);\n pane.appendChild(au);\n if (body.text) appendQuoteText(pane, body.text, \"fdp-body\");\n if (body.gitLink) {\n const gl = gitLinkNode(body.gitLink, \"pr-note-git\");\n if (gl) pane.appendChild(gl);\n }\n const sec = document.createElement(\"div\");\n sec.className = \"fdp-cmts\";\n const threads = feedThreads[p.id];\n const capC = document.createElement(\"p\");\n capC.className = \"fdp-cmts-cap\";\n capC.innerHTML = '>COMMENTS' + (threads && threads.length ? ' (' + threads.length + \")\" : \"\");\n sec.appendChild(capC);\n const canReply = !!S.myWalletAddress;\n function commentCard(nn, topAuthor) {\n const el = document.createElement(\"div\");\n el.className = \"fdc\";\n const top = document.createElement(\"div\");\n top.className = \"fdc-top\";\n const av = document.createElement(\"span\");\n av.className = \"fdc-ava\";\n av.innerHTML = avatarSvg(nn.author || \"\");\n const wl = document.createElement(\"span\");\n wl.className = \"fdc-wallet\";\n wl.textContent = nn.author ? agShort(nn.author) : \"?\";\n top.appendChild(av);\n top.appendChild(wl);\n const nd = fmtNoteDate(nn);\n if (nd) {\n const d = document.createElement(\"span\");\n d.className = \"fdc-date\";\n d.textContent = \"[\" + nd + \"]\";\n top.appendChild(d);\n }\n el.appendChild(top);\n if (nn.parentAuthor && nn.parentAuthor !== topAuthor) {\n const to = document.createElement(\"p\");\n to.className = \"fdc-to\";\n to.textContent = \"↳ replying to \" + agShort(nn.parentAuthor);\n el.appendChild(to);\n }\n if (nn.text) appendQuoteText(el, nn.text, \"fdc-text\");\n if (nn.gitLink) {\n const gl = gitLinkNode(nn.gitLink, \"pr-note-git\");\n if (gl) el.appendChild(gl);\n }\n if (canReply) {\n const rb = document.createElement(\"button\");\n rb.type = \"button\";\n rb.className = \"fdc-replybtn\";\n rb.textContent = S.feedReplyTo === nn.id ? \"[Cancel]\" : \"[Reply]\";\n rb.addEventListener(\"click\", () => {\n S.feedReplyTo = S.feedReplyTo === nn.id ? null : nn.id;\n renderFeedPost();\n });\n el.appendChild(rb);\n }\n return el;\n }\n function submitComment(f, parentId) {\n S.feedLastSage = !!f.sage;\n vscode.postMessage({\n type: \"postBlogComment\",\n postId: p.id,\n agentWallet: p.author,\n text: f.text,\n gitLink: f.gitLink,\n parentId,\n sage: !!f.sage,\n feedBump: !f.sage\n });\n }\n if (threads === void 0) {\n const l = document.createElement(\"div\");\n l.className = \"pr-empty\";\n l.textContent = \"Loading comments…\";\n sec.appendChild(l);\n } else if (!threads.length) {\n const e = document.createElement(\"div\");\n e.className = \"pr-empty\";\n e.textContent = \"No comments yet. Be the first.\";\n sec.appendChild(e);\n } else {\n threads.forEach((t) => {\n const wrap = document.createElement(\"div\");\n wrap.appendChild(commentCard(t.note, t.note.author));\n const reps = t.replies || [];\n if (reps.length) {\n const rl = document.createElement(\"div\");\n rl.className = \"fdc-replies\";\n reps.forEach((r) => rl.appendChild(commentCard(r, t.note.author)));\n wrap.appendChild(rl);\n }\n const replyingHere = S.feedReplyTo === t.note.id || reps.some((r) => r.id === S.feedReplyTo);\n if (replyingHere && canReply) {\n const rc = fdComposer(\"Write a reply...\", \"Reply\", (f) => submitComment(f, S.feedReplyTo || t.note.id), true);\n rc.style.marginLeft = \"16px\";\n wrap.appendChild(rc);\n }\n sec.appendChild(wrap);\n });\n }\n if (canReply) {\n const mc = fdComposer(\"Write a comment...\", \"Comment\", (f) => submitComment(f, void 0), true);\n if (keep) {\n mc._ta.value = keep.text;\n mc._git.value = keep.git;\n }\n sec.appendChild(mc);\n pane._mainCompose = mc;\n } else {\n const g = document.createElement(\"div\");\n g.className = \"fdp-gate\";\n g.innerHTML = '>CONNECT_WALLET_ Connect a wallet to comment.';\n sec.appendChild(g);\n pane._mainCompose = null;\n }\n pane.appendChild(sec);\n }\n function updateFdFab() {\n const fab = document.getElementById(\"fdFab\");\n if (!fab) return;\n const agentsOn = panels.agents && panels.agents.style.display !== \"none\";\n const listOn = document.getElementById(\"agFeedPane\").style.display !== \"none\";\n fab.style.display = agentsOn && S.agentsTab === \"feed\" && listOn && S.myWalletAddress ? \"flex\" : \"none\";\n }\n function closeFabCompose() {\n if (S.fabModalEl) {\n S.fabModalEl.remove();\n S.fabModalEl = null;\n }\n }\n function openFabCompose() {\n if (!S.myWalletAddress) return;\n closeFabCompose();\n const ov = document.createElement(\"div\");\n ov.className = \"skModal\";\n ov.addEventListener(\"click\", (e) => {\n if (e.target === ov) closeFabCompose();\n });\n const card = document.createElement(\"div\");\n card.className = \"skModal-card\";\n const x = document.createElement(\"button\");\n x.className = \"skModal-close\";\n x.title = \"Close\";\n x.textContent = \"×\";\n x.addEventListener(\"click\", closeFabCompose);\n const title = document.createElement(\"div\");\n title.className = \"rr-title\";\n title.textContent = \"Write a blog post\";\n card.appendChild(x);\n card.appendChild(title);\n const form = document.createElement(\"div\");\n form.className = \"fdp-compose\";\n const ti = document.createElement(\"input\");\n ti.className = \"an-field\";\n ti.type = \"text\";\n ti.placeholder = \"Title (optional)\";\n const ta = document.createElement(\"textarea\");\n ta.className = \"an-field\";\n ta.rows = 5;\n ta.placeholder = \"Write a blog post or update...\";\n const im = document.createElement(\"input\");\n im.className = \"an-field\";\n im.type = \"text\";\n im.placeholder = \"Image link / on-chain address / tx id (optional)\";\n const gi = document.createElement(\"input\");\n gi.className = \"an-field\";\n gi.type = \"text\";\n gi.placeholder = \"GitHub link (optional)\";\n const err = document.createElement(\"div\");\n err.className = \"pr-err\";\n const foot = document.createElement(\"div\");\n foot.className = \"fdp-compose-foot\";\n const btn = document.createElement(\"button\");\n btn.type = \"button\";\n btn.className = \"an-btn an-btn-green\";\n btn.textContent = \"Post to AgentNet\";\n btn.addEventListener(\"click\", () => {\n const text = ta.value.trim();\n const titleV = ti.value.trim();\n if (!text && !titleV) return;\n btn.disabled = true;\n btn.textContent = \"Posting…\";\n err.style.display = \"none\";\n S.pendingPost = { wallet: S.myWalletAddress, text, gitLink: gi.value.trim() || void 0, self: true };\n const out = { type: \"postAgentNote\", agentWallet: S.myWalletAddress, text };\n if (gi.value.trim()) out.gitLink = gi.value.trim();\n if (im.value.trim()) out.image = im.value.trim();\n if (titleV) out.title = titleV;\n vscode.postMessage(out);\n });\n foot.appendChild(btn);\n form.appendChild(ti);\n form.appendChild(ta);\n form.appendChild(im);\n form.appendChild(gi);\n form.appendChild(err);\n form.appendChild(foot);\n card.appendChild(form);\n ov.appendChild(card);\n document.body.appendChild(ov);\n ov._btn = btn;\n ov._err = err;\n S.fabModalEl = ov;\n ta.focus();\n }\n function showProfile(walletAddr) {\n S.currentProfileWallet = walletAddr;\n document.getElementById(\"wAvatarBig\").innerHTML = avatarSvg(walletAddr);\n document.getElementById(\"walletAddr\").textContent = walletAddr;\n document.getElementById(\"profileSubtitle\").textContent = \"Loading profile…\";\n document.getElementById(\"profileRep\").innerHTML = \"\";\n document.getElementById(\"agentIdCard\").innerHTML = skId;\n document.getElementById(\"profileSelfOnly2\").style.display = \"none\";\n document.getElementById(\"profileBody\").innerHTML = '
' + skSd(6) + \"
\";\n showView(\"wallet\");\n vscode.postMessage({ type: \"getAgentProfile\", wallet: walletAddr });\n }\n function wireFeed() {\n document.getElementById(\"agTabFeed\").addEventListener(\"click\", () => selectAgentsTab(\"feed\"));\n document.getElementById(\"agTabRank\").addEventListener(\"click\", () => selectAgentsTab(\"rank\"));\n document.getElementById(\"fdSortActive\").addEventListener(\"click\", () => setFeedSort(\"active\"));\n document.getElementById(\"fdSortLatest\").addEventListener(\"click\", () => setFeedSort(\"latest\"));\n document.getElementById(\"fdFab\").addEventListener(\"click\", openFabCompose);\n }\n\n // src/chat/ui/panel/menus.ts\n var histMenu = document.getElementById(\"histMenu\");\n var walletMenu = document.getElementById(\"walletMenu\");\n function closeMenus(except) {\n if (except !== \"hist\") histMenu.style.display = \"none\";\n if (except !== \"wallet\") walletMenu.style.display = \"none\";\n }\n function toggleMenu(el, which) {\n const open = el.style.display !== \"none\";\n closeMenus(open ? null : which);\n el.style.display = open ? \"none\" : \"block\";\n }\n function wireMenus() {\n document.getElementById(\"histBtn\").addEventListener(\"click\", (e) => {\n e.stopPropagation();\n toggleMenu(histMenu, \"hist\");\n });\n document.getElementById(\"walletPill\").addEventListener(\"click\", (e) => {\n e.stopPropagation();\n toggleMenu(walletMenu, \"wallet\");\n if (walletMenu.style.display !== \"none\") vscode.postMessage({ type: \"getBalance\" });\n });\n document.getElementById(\"openWalletPage\").addEventListener(\"click\", () => {\n closeMenus();\n if (S.myWalletAddress) showProfile(S.myWalletAddress);\n else showView(\"wallet\");\n });\n document.addEventListener(\"click\", (e) => {\n closeMenus();\n if (inputWrap && !inputWrap.contains(e.target)) {\n slashMenu.style.display = \"none\";\n S.activeSlashMatches = [];\n }\n });\n histMenu.addEventListener(\"click\", (e) => e.stopPropagation());\n walletMenu.addEventListener(\"click\", (e) => e.stopPropagation());\n }\n\n // src/chat/ui/panel/engine.ts\n var MODELS = CHAT_MODEL_OPTIONS;\n var CODEX_UPDATE_CMD = CODEX_UPDATE_COMMAND;\n var modelValue = (opt) => opt && opt.value ? opt.value : \"default\";\n var CODEX_MODES = [\n { value: \"readonly\", label: \"Read only\", title: \"Read-only sandbox; ask before edits, commands, network\" },\n { value: \"auto\", label: \"Auto accept\", title: \"Auto-accept edits + run inside the workspace; approve on failure (default)\" },\n { value: \"full\", label: \"Full access\", title: \"Full disk + network access, never ask (use with care)\" }\n ];\n var MODES = {\n claude: [\n { value: \"default\", label: \"Ask edits\", title: \"Ask before each file edit (default)\" },\n { value: \"acceptEdits\", label: \"Auto edit\", title: \"Auto-accept file edits; still ask for other tools\" },\n { value: \"plan\", label: \"Plan\", title: \"Plan mode: read-only until you approve the plan\" },\n { value: \"bypassPermissions\", label: \"Bypass\", title: \"Bypass all permission prompts (--dangerously-skip-permissions). Auto-runs every command, edit, and on-chain spend. Use with care.\" }\n ],\n codex: CODEX_MODES,\n custom: CODEX_MODES\n };\n var EFFORTS = [\n { value: \"default\", label: \"default\", title: \"Engine default (usually medium)\" },\n { value: \"low\", label: \"low\", title: \"Minimal thinking, fastest\" },\n { value: \"medium\", label: \"medium\", title: \"Moderate reasoning\" },\n { value: \"high\", label: \"high\", title: \"Deeper thinking\" },\n { value: \"xhigh\", label: \"x-high\", title: \"Extended reasoning\" },\n { value: \"max\", label: \"max\", title: \"Maximum effort (select models)\" }\n ];\n var modeByCli = { claude: \"acceptEdits\", codex: \"auto\", custom: \"auto\" };\n var modelByCli = { claude: null, codex: null, custom: null };\n var effortByCli = { claude: \"default\", codex: \"default\", custom: \"default\" };\n function currentModel() {\n const opts = MODELS[S.cli] || [];\n return modelByCli[S.cli] || modelValue(opts[0]);\n }\n function fillModels() {\n const opts = MODELS[S.cli] || [{ chipLabel: \"default\", label: \"Default\", description: \"No model override\" }];\n const cur = currentModel();\n const curOpt = opts.find((o) => modelValue(o) === cur) || opts[0];\n modelLabel.textContent = curOpt ? curOpt.chipLabel || curOpt.label : cur === \"default\" ? \"default\" : cur;\n modelMenu.innerHTML = \"\";\n for (const m of opts) {\n const row = document.createElement(\"div\");\n const value = modelValue(m);\n row.className = \"modeOpt\" + (value === cur ? \" sel\" : \"\");\n const txt = document.createElement(\"div\");\n txt.className = \"mtext\";\n const lab = document.createElement(\"div\");\n lab.className = \"mlabel\";\n lab.textContent = m.label;\n txt.appendChild(lab);\n if (m.description) {\n const d = document.createElement(\"div\");\n d.className = \"mdesc\";\n d.textContent = m.description;\n txt.appendChild(d);\n }\n const chk = document.createElement(\"span\");\n chk.className = \"mcheck\";\n chk.textContent = \"✓\";\n row.appendChild(txt);\n row.appendChild(chk);\n row.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n modelByCli[S.cli] = value;\n modelMenu.style.display = \"none\";\n fillModels();\n vscode.postMessage({ type: \"model\", model: value });\n });\n modelMenu.appendChild(row);\n }\n }\n function applyModelOptions(engine, options) {\n if (!engine || !Array.isArray(options) || !options.length) return;\n MODELS[engine] = options;\n const cur = modelByCli[engine] || \"default\";\n const changed = !options.some((o) => modelValue(o) === cur);\n if (changed) modelByCli[engine] = modelValue(options[0]);\n if (engine === S.cli) {\n fillModels();\n if (changed) vscode.postMessage({ type: \"model\", model: currentModel() });\n }\n }\n function placeMenuAbove(menu, anchor) {\n const mw = menu.getBoundingClientRect().width;\n const left = Math.max(8, Math.min((window.innerWidth - mw) / 2, window.innerWidth - mw - 8));\n menu.style.left = left + \"px\";\n menu.style.bottom = window.innerHeight - anchor.top + 6 + \"px\";\n }\n function openModelMenu() {\n modelMenu.style.display = \"block\";\n placeMenuAbove(modelMenu, modelBtn.getBoundingClientRect());\n }\n function currentMode() {\n const opts = MODES[S.cli] || [];\n return modeByCli[S.cli] || opts[0] && opts[0].value;\n }\n function fillModes() {\n const opts = MODES[S.cli] || [{ value: \"default\", label: \"default\" }];\n const cur = currentMode();\n const curOpt = opts.find((o) => o.value === cur) || opts[0];\n modeLabel.textContent = curOpt ? curOpt.label : \"mode\";\n const curEff = currentEffort();\n const curEffOpt = EFFORTS.find((o) => o.value === curEff);\n modeEffortTag.textContent = curEff === \"default\" || !curEffOpt ? \"\" : \"· \" + curEffOpt.label;\n modeMenu.innerHTML = \"\";\n for (const m of opts) {\n const row = document.createElement(\"div\");\n row.className = \"modeOpt\" + (m.value === cur ? \" sel\" : \"\");\n const txt = document.createElement(\"div\");\n txt.className = \"mtext\";\n const lab = document.createElement(\"div\");\n lab.className = \"mlabel\";\n lab.textContent = m.label;\n txt.appendChild(lab);\n if (m.title) {\n const d = document.createElement(\"div\");\n d.className = \"mdesc\";\n d.textContent = m.title;\n txt.appendChild(d);\n }\n const chk = document.createElement(\"span\");\n chk.className = \"mcheck\";\n chk.textContent = \"✓\";\n row.appendChild(txt);\n row.appendChild(chk);\n row.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n modeByCli[S.cli] = m.value;\n modeMenu.style.display = \"none\";\n fillModes();\n vscode.postMessage({ type: \"mode\", mode: m.value });\n });\n modeMenu.appendChild(row);\n }\n const div = document.createElement(\"div\");\n div.className = \"mdiv\";\n const head = document.createElement(\"div\");\n head.className = \"mSection\";\n head.textContent = \"Effort · reasoning depth\";\n const chips = document.createElement(\"div\");\n chips.className = \"effChips\";\n for (const e of EFFORTS) {\n const chip = document.createElement(\"button\");\n chip.className = \"effChip\" + (e.value === curEff ? \" sel\" : \"\");\n chip.textContent = e.label;\n if (e.title) chip.title = e.title;\n chip.addEventListener(\"click\", (ev) => {\n ev.stopPropagation();\n effortByCli[S.cli] = e.value;\n modeMenu.style.display = \"none\";\n fillModes();\n vscode.postMessage({ type: \"effort\", effort: e.value === \"default\" ? void 0 : e.value });\n });\n chips.appendChild(chip);\n }\n modeMenu.appendChild(div);\n modeMenu.appendChild(head);\n modeMenu.appendChild(chips);\n }\n function openModeMenu() {\n modeMenu.style.display = \"block\";\n placeMenuAbove(modeMenu, modeBtn.getBoundingClientRect());\n }\n function currentEffort() {\n return effortByCli[S.cli] || \"default\";\n }\n function showCustomTab() {\n S.customEngineOn = true;\n const t = tabs.find((t2) => t2.dataset.cli === \"custom\");\n if (t) t.style.display = \"\";\n }\n function hideCustomTab() {\n S.customEngineOn = false;\n const t = tabs.find((t2) => t2.dataset.cli === \"custom\");\n if (t) t.style.display = \"none\";\n if (S.cli === \"custom\") {\n renderNotice(\"Custom engine was removed. Switched to the Codex tab.\");\n selectTab(\"codex\");\n }\n }\n function setTab(next) {\n if (next !== \"claude\" && next !== \"codex\" && next !== \"custom\") return;\n if (next === \"custom\") showCustomTab();\n S.cli = next;\n tabs.forEach((t) => t.classList.toggle(\"active\", t.dataset.cli === S.cli));\n composer.dataset.cli = S.cli;\n if (jumpBtn) jumpBtn.dataset.cli = S.cli;\n input.placeholder = \"Message \" + S.cli + \"... (Enter to send)\";\n fillModels();\n fillModes();\n paintMeters();\n }\n function selectTab(next) {\n if (next === S.cli) return;\n setTab(next);\n const status = S.cliReport && S.cliReport[engineBinary(next)];\n if (status === \"missing\" || status === \"node-missing\") {\n renderEngineMissing(next);\n return;\n }\n if (status === \"no-login\" && next !== \"custom\") {\n renderNotice((next === \"claude\" ? \"Claude\" : \"Codex\") + \" is not signed in. Type /login to connect it.\");\n return;\n }\n vscode.postMessage({ type: \"platform\", cli: S.cli });\n vscode.postMessage({ type: \"model\", model: currentModel() });\n vscode.postMessage({ type: \"mode\", mode: currentMode() });\n vscode.postMessage({ type: \"effort\", effort: currentEffort() === \"default\" ? void 0 : currentEffort() });\n }\n function wireEngine() {\n tabs.forEach((t) => t.addEventListener(\"click\", () => selectTab(t.dataset.cli)));\n modelBtn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n if (modelMenu.style.display === \"block\") {\n modelMenu.style.display = \"none\";\n return;\n }\n modeMenu.style.display = \"none\";\n closeMenus();\n openModelMenu();\n });\n modelMenu.addEventListener(\"click\", (e) => e.stopPropagation());\n modeBtn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n if (modeMenu.style.display === \"block\") {\n modeMenu.style.display = \"none\";\n return;\n }\n modelMenu.style.display = \"none\";\n closeMenus();\n openModeMenu();\n });\n modeMenu.addEventListener(\"click\", (e) => e.stopPropagation());\n document.addEventListener(\"click\", () => {\n modeMenu.style.display = \"none\";\n modelMenu.style.display = \"none\";\n });\n fillModels();\n fillModes();\n }\n\n // src/chat/ui/panel/slash.ts\n var SLASH_CMDS = CHAT_SLASH_COMMANDS.map(function(c) {\n return Object.assign({}, c, { insert: \"/\" + c.name + (c.args ? \" \" : \"\") });\n });\n function slashCommandsForCli() {\n return SLASH_CMDS.filter(function(cmd) {\n return !cmd.engines || cmd.engines.indexOf(S.cli) >= 0;\n });\n }\n function renderSlashMenu() {\n if (S.suppressSlash) {\n slashMenu.style.display = \"none\";\n S.activeSlashMatches = [];\n return;\n }\n const val = input.value;\n let subCmd = null;\n let prefix = \"\";\n let options = [];\n let m = /^\\/engine(?:\\s+(\\S*))?$/.exec(val);\n if (m) {\n subCmd = \"engine\";\n prefix = (m[1] || \"\").toLowerCase();\n options = [\n { name: \"claude\", desc: \"switch to Claude engine\", insert: \"/engine claude\" },\n { name: \"codex\", desc: \"switch to Codex engine\", insert: \"/engine codex\" }\n ];\n if (S.customEngineOn) options.push({ name: \"custom\", desc: \"switch to Custom engine\", insert: \"/engine custom\" });\n }\n if (!subCmd) {\n m = /^\\/model(?:\\s+(\\S*))?$/.exec(val);\n if (m) {\n subCmd = \"model\";\n prefix = (m[1] || \"\").toLowerCase();\n const list = MODELS[S.cli] || [];\n options = list.map(function(o) {\n return { name: o.value, desc: o.label, insert: \"/model \" + o.value };\n });\n }\n }\n if (!subCmd) {\n m = /^\\/mode(?:\\s+(\\S*))?$/.exec(val);\n if (m) {\n subCmd = \"mode\";\n prefix = (m[1] || \"\").toLowerCase();\n const list = MODES[S.cli] || [];\n options = list.map(function(o) {\n return { name: o.value, desc: o.label + \" - \" + o.title, insert: \"/mode \" + o.value };\n });\n }\n }\n if (!subCmd) {\n m = /^\\/effort(?:\\s+(\\S*))?$/.exec(val);\n if (m) {\n subCmd = \"effort\";\n prefix = (m[1] || \"\").toLowerCase();\n options = EFFORTS.map(function(o) {\n return { name: o.value, desc: o.label + \" - \" + o.title, insert: \"/effort \" + o.value };\n });\n }\n }\n if (subCmd) {\n S.activeSlashMatches = options.filter(function(opt) {\n return opt.name.toLowerCase().startsWith(prefix);\n });\n if (S.activeSlashMatches.length === 1 && prefix === S.activeSlashMatches[0].name.toLowerCase()) {\n slashMenu.style.display = \"none\";\n S.activeSlashMatches = [];\n return;\n }\n } else {\n const mainMatch = /^\\/(\\S*)$/.exec(val);\n if (!mainMatch) {\n slashMenu.style.display = \"none\";\n S.activeSlashMatches = [];\n return;\n }\n prefix = mainMatch[1].toLowerCase();\n S.activeSlashMatches = slashCommandsForCli().filter(function(cmd) {\n return cmd.name.toLowerCase().startsWith(prefix);\n });\n }\n if (S.activeSlashMatches.length === 0) {\n slashMenu.style.display = \"none\";\n return;\n }\n if (S.slashIdx >= S.activeSlashMatches.length) {\n S.slashIdx = S.activeSlashMatches.length - 1;\n }\n if (S.slashIdx < 0) {\n S.slashIdx = 0;\n }\n let html = \"\";\n S.activeSlashMatches.forEach(function(cmd, idx) {\n const isSel = idx === S.slashIdx;\n const label = subCmd ? cmd.name : \"/\" + cmd.name;\n html += '
' + escapeHtml(label) + '' + escapeHtml(cmd.desc || \"\") + \"
\";\n });\n html += '
Use ↑↓ to navigate, Tab/Enter to select, Esc to close
';\n slashMenu.innerHTML = html;\n slashMenu.style.display = \"flex\";\n }\n function completeSlash(c) {\n input.value = c.insert;\n autoGrowInput();\n S.suppressSlash = false;\n slashMenu.style.display = \"none\";\n S.activeSlashMatches = [];\n input.focus();\n if (c.insert.endsWith(\" \")) {\n renderSlashMenu();\n }\n }\n function wireSlash() {\n slashMenu.addEventListener(\"click\", function(e) {\n const opt = e.target.closest(\".slashOpt\");\n if (opt) {\n e.stopPropagation();\n const idx = parseInt(opt.getAttribute(\"data-idx\") || \"0\", 10);\n if (S.activeSlashMatches[idx]) {\n completeSlash(S.activeSlashMatches[idx]);\n }\n }\n });\n }\n\n // src/chat/ui/panel/overlays.ts\n var celebrateEl = document.getElementById(\"celebrate\");\n function showComplete(label) {\n celebrateEl.innerHTML = '
COMPLETE
[' + escapeHtml(label || \"DONE\") + \"]
\";\n celebrateEl.classList.remove(\"out\");\n celebrateEl.classList.add(\"show\");\n clearTimeout(S.celebTimer);\n S.celebTimer = setTimeout(() => {\n celebrateEl.classList.add(\"out\");\n setTimeout(() => {\n celebrateEl.classList.remove(\"show\", \"out\");\n celebrateEl.innerHTML = \"\";\n }, 450);\n }, 2200);\n }\n function renderBalance() {\n const txt = fmtSol(S.solLamports);\n const low = S.solLamports != null && S.solLamports < 5e3;\n const wb = document.getElementById(\"wBalance\");\n const mb = document.getElementById(\"mktBalance\");\n if (wb) {\n const amt = wb.querySelector(\".balAmt\");\n if (txt == null) {\n wb.style.display = \"none\";\n } else {\n if (amt) amt.textContent = txt;\n wb.style.display = \"flex\";\n wb.classList.toggle(\"low\", low);\n }\n }\n if (mb) {\n if (txt == null) {\n mb.style.display = \"none\";\n } else {\n mb.textContent = txt;\n mb.style.display = \"inline-flex\";\n mb.classList.toggle(\"low\", low);\n }\n }\n }\n var buyErrEl = document.getElementById(\"buyErr\");\n function showBuyError(msg, fundable) {\n buyErrEl.innerHTML = '
i
Purchase failed' + escapeHtml(msg || \"Something went wrong. Please try again.\") + \"\" + (fundable ? '' : \"\") + '
';\n buyErrEl.classList.add(\"show\");\n buyErrEl.style.display = \"block\";\n buyErrEl.querySelector(\".buyErrClose\").addEventListener(\"click\", hideBuyError);\n const fundBtn = buyErrEl.querySelector(\".buyErrFund\");\n if (fundBtn) fundBtn.addEventListener(\"click\", () => {\n fundBtn.disabled = true;\n fundBtn.textContent = \"Requesting devnet SOL…\";\n vscode.postMessage({ type: \"airdrop\" });\n });\n clearTimeout(S.buyErrTimer);\n S.buyErrTimer = setTimeout(hideBuyError, fundable ? 2e4 : 7e3);\n }\n function hideBuyError() {\n clearTimeout(S.buyErrTimer);\n buyErrEl.classList.remove(\"show\");\n setTimeout(() => {\n if (!buyErrEl.classList.contains(\"show\")) {\n buyErrEl.style.display = \"none\";\n buyErrEl.innerHTML = \"\";\n }\n }, 220);\n }\n var rpcState = document.getElementById(\"rpcState\");\n var rpcHint = document.getElementById(\"rpcHint\");\n var rpcSetBtn = document.getElementById(\"rpcSetBtn\");\n var rpcDefaultBtn = document.getElementById(\"rpcDefaultBtn\");\n function renderRpcStatus(s) {\n s = s || { dasReady: false, hasKey: false, masked: null, network: \"devnet\" };\n S.dasReady = !!s.dasReady;\n S.rpcNetwork = s.network || \"devnet\";\n if (s.hasKey && s.masked) {\n rpcState.innerHTML = '✓ ' + escapeHtml(s.masked) + \" \" + netBadge(s.network);\n rpcSetBtn.textContent = \"Change\";\n rpcSetBtn.style.display = \"\";\n rpcDefaultBtn.textContent = \"Remove\";\n rpcDefaultBtn.style.display = \"\";\n rpcHint.style.display = \"none\";\n } else {\n rpcState.innerHTML = '⚠ Set Helius key ' + netBadge(s.network);\n const w = document.getElementById(\"rpcWarnSet\");\n if (w) w.addEventListener(\"click\", () => vscode.postMessage({ type: \"setHeliusKey\" }));\n rpcSetBtn.style.display = \"none\";\n rpcDefaultBtn.style.display = \"none\";\n rpcHint.style.display = \"none\";\n }\n }\n var activityBar = document.getElementById(\"activityBar\");\n var activityText = document.getElementById(\"activityText\");\n var VERBS = { skill: [\"Casting\", \"Channeling\", \"Wielding\", \"Invoking\"] };\n function flashSkill(name, mint) {\n const v = VERBS.skill[S.pick++ % VERBS.skill.length];\n activityText.innerHTML = '' + v + \" \" + (name ? '' + escapeHtml(name) + \"\" : \"\");\n activityBar.classList.remove(\"out\");\n activityBar.style.display = \"flex\";\n clearTimeout(S.actTimer);\n const dwell = Math.min(4e3, 1600 + (name || \"\").length * 35);\n S.actTimer = setTimeout(() => {\n activityBar.classList.add(\"out\");\n setTimeout(() => {\n activityBar.style.display = \"none\";\n activityBar.classList.remove(\"out\");\n }, 250);\n }, dwell);\n lightSkillSlot(name, mint, dwell);\n }\n function lightSkillSlot(name, mint, dwell) {\n const grid = document.getElementById(\"skillGrid\");\n const panel = document.getElementById(\"skillsPanel\");\n const btn = document.getElementById(\"skillsBtn\");\n const clear = () => {\n grid.querySelectorAll(\".an-sd.is-firing\").forEach((s) => s.classList.remove(\"is-firing\"));\n panel.classList.remove(\"casting\");\n btn.classList.remove(\"casting\");\n };\n clear();\n grid.querySelectorAll(\".an-sd\").forEach((s) => {\n if (mint && s.getAttribute(\"data-mint\") === mint || s.getAttribute(\"data-skill\") === name) s.classList.add(\"is-firing\");\n });\n panel.classList.add(\"casting\");\n btn.classList.add(\"casting\");\n clearTimeout(S.firingTimer);\n S.firingTimer = setTimeout(clear, Math.max(dwell || 0, 1400));\n }\n function hideActivity() {\n clearTimeout(S.actTimer);\n activityBar.classList.remove(\"out\");\n activityBar.style.display = \"none\";\n }\n function wireOverlays() {\n celebrateEl.addEventListener(\"click\", () => {\n clearTimeout(S.celebTimer);\n celebrateEl.classList.remove(\"show\", \"out\");\n celebrateEl.innerHTML = \"\";\n });\n rpcSetBtn.addEventListener(\"click\", () => vscode.postMessage({ type: \"setHeliusKey\" }));\n rpcDefaultBtn.addEventListener(\"click\", () => vscode.postMessage({ type: \"useDefaultRpc\" }));\n vscode.postMessage({ type: \"getRpcStatus\" });\n }\n\n // src/chat/ui/panel/composer.ts\n function showTyping() {\n setBusy(true);\n if (S.typingEl) return;\n const node = document.createElement(\"div\");\n node.className = \"node typing\";\n node.innerHTML = '
' + S.cli + '
';\n tailBody().appendChild(node);\n stickToBottom();\n S.typingEl = node;\n }\n function hideTyping() {\n setBusy(false);\n if (S.typingEl) {\n S.typingEl.remove();\n S.typingEl = null;\n }\n }\n function setBusy(b) {\n if (S.busy === b) return;\n S.busy = b;\n const btn = document.getElementById(\"send\");\n if (!btn) return;\n const lbl = btn.querySelector(\".lbl\");\n if (lbl) lbl.textContent = b ? \"Stop\" : \"Send\";\n btn.title = b ? \"Stop\" : \"Send\";\n btn.setAttribute(\"aria-label\", b ? \"Stop\" : \"Send\");\n btn.classList.toggle(\"stopping\", b);\n }\n function interruptTurn() {\n vscode.postMessage({ type: \"interrupt\" });\n setBusy(false);\n hideTyping();\n }\n var sendBtn = document.getElementById(\"send\");\n function syncComposerLock() {\n const locked = approvalDock.childElementCount > 0;\n input.disabled = locked;\n if (sendBtn) sendBtn.disabled = locked;\n composer.classList.toggle(\"locked\", locked);\n input.placeholder = locked ? \"Answer the approval above to continue…\" : \"Message \" + (composer.dataset.cli || \"claude\") + \"... (Enter to send)\";\n }\n var attachStrip = document.getElementById(\"attachStrip\");\n var fileInput = document.getElementById(\"fileInput\");\n var attachBtn = document.getElementById(\"attachBtn\");\n var inputWrap = document.getElementById(\"inputWrap\");\n function renderAttachStrip() {\n attachStrip.innerHTML = \"\";\n attachStrip.style.display = S.attached.length ? \"flex\" : \"none\";\n S.attached.forEach((a, i) => {\n const t = document.createElement(\"div\");\n t.className = \"thumb\";\n const img = document.createElement(\"img\");\n img.src = a.dataUrl;\n img.alt = a.name || \"image\";\n const rm = document.createElement(\"button\");\n rm.className = \"rm\";\n rm.textContent = \"×\";\n rm.title = \"Remove\";\n rm.addEventListener(\"click\", () => {\n S.attached.splice(i, 1);\n renderAttachStrip();\n });\n t.appendChild(img);\n t.appendChild(rm);\n attachStrip.appendChild(t);\n });\n }\n function userImagesEl(info) {\n if (!info) return null;\n if (info.thumbs && info.thumbs.length) {\n const row = document.createElement(\"div\");\n row.className = \"msgImgs\";\n info.thumbs.forEach((u) => {\n const im = document.createElement(\"img\");\n im.src = u;\n row.appendChild(im);\n });\n return row;\n }\n if (info.count) {\n const chip = document.createElement(\"span\");\n chip.className = \"imgChip\";\n chip.innerHTML = '' + info.count + (info.count > 1 ? \" images\" : \" image\");\n return chip;\n }\n return null;\n }\n function addFiles(files) {\n for (const f of files) {\n if (!f.type || f.type.indexOf(\"image/\") !== 0) continue;\n const reader = new FileReader();\n reader.onload = () => {\n const dataUrl = String(reader.result || \"\");\n const comma = dataUrl.indexOf(\",\");\n if (comma < 0) return;\n S.attached.push({ dataUrl, mime: f.type, dataBase64: dataUrl.slice(comma + 1), name: f.name || \"pasted\" });\n renderAttachStrip();\n };\n reader.readAsDataURL(f);\n }\n }\n function send() {\n if (input.disabled) return;\n const text = input.value.trim();\n if (!text && !S.attached.length) return;\n if (text === \"/mockupskills\" || text.startsWith(\"/mockupskills \")) {\n const names = text.slice(\"/mockupskills\".length).trim().split(/\\s+/).filter(Boolean);\n setSkills(names);\n if (skillsPanel.style.display === \"none\") {\n skillsPanel.style.display = \"block\";\n skillsBtn.classList.add(\"on\");\n }\n input.value = \"\";\n return;\n }\n if (text === \"/mockskill\" || text.startsWith(\"/mockskill \")) {\n flashSkill(text.slice(\"/mockskill\".length).trim() || \"cleancode\", \"mock\");\n input.value = \"\";\n return;\n }\n if (text.startsWith(\"/\")) {\n const [cmd, ...rest] = text.slice(1).split(\" \");\n const arg = rest.join(\" \").trim();\n switch (cmd) {\n case \"login\": {\n const target = arg === \"claude\" || arg === \"codex\" ? arg : S.cli;\n if (target === \"custom\") {\n renderNotice(\"Custom endpoints have no login. Connect one from the AgentNet app settings.\");\n input.value = \"\";\n return;\n }\n if (target === \"claude\" && arg && arg !== \"claude\" && arg !== \"codex\") {\n vscode.postMessage({ type: \"claudeAuthCode\", code: arg });\n renderNotice(\"Submitted Claude sign-in code.\");\n } else {\n vscode.postMessage({ type: target === \"claude\" ? \"startClaudeLogin\" : \"startCodexLogin\" });\n renderNotice(\"Starting \" + (target === \"claude\" ? \"Claude\" : \"Codex\") + \" sign-in...\");\n }\n input.value = \"\";\n return;\n }\n case \"logout\": {\n const target = arg === \"claude\" || arg === \"codex\" || arg === \"custom\" ? arg : S.cli;\n if (target === \"custom\") {\n renderNotice(\"Custom endpoints have no login to sign out of. Remove the endpoint from the AgentNet app settings.\");\n input.value = \"\";\n return;\n }\n vscode.postMessage({ type: \"logoutEngine\", cli: target });\n renderNotice(\"Signing out of \" + (target === \"claude\" ? \"Claude\" : \"Codex\") + \"...\");\n input.value = \"\";\n return;\n }\n case \"new\":\n vscode.postMessage({ type: \"new\" });\n input.value = \"\";\n return;\n case \"clear\":\n vscode.postMessage({ type: \"clear\" });\n input.value = \"\";\n return;\n case \"compact\":\n vscode.postMessage({ type: \"slashCommand\", command: \"compact\", arg });\n showTyping();\n input.value = \"\";\n return;\n case \"status\":\n vscode.postMessage({ type: \"slashCommand\", command: \"status\" });\n input.value = \"\";\n return;\n case \"resume\":\n vscode.postMessage({ type: \"slashCommand\", command: \"resume\" });\n input.value = \"\";\n return;\n case \"diff\":\n vscode.postMessage({ type: \"slashCommand\", command: \"diff\" });\n showTyping();\n input.value = \"\";\n return;\n case \"permissions\":\n if (arg) {\n modeByCli[S.cli] = arg;\n fillModes();\n vscode.postMessage({ type: \"mode\", mode: arg });\n } else vscode.postMessage({ type: \"slashCommand\", command: \"permissions\" });\n input.value = \"\";\n return;\n case \"init\":\n case \"skills\":\n case \"cost\":\n vscode.postMessage({ type: \"slashCommand\", command: cmd });\n input.value = \"\";\n return;\n case \"review\":\n case \"mcp\":\n vscode.postMessage({ type: \"slashCommand\", command: cmd, arg });\n showTyping();\n input.value = \"\";\n return;\n case \"copy\": {\n const last = Array.from(log.querySelectorAll(\".node.assistant .msg\")).pop();\n if (last && navigator.clipboard) navigator.clipboard.writeText(last.textContent || \"\").catch(() => {\n });\n input.value = \"\";\n return;\n }\n case \"engine\":\n if (arg === \"custom\" && !S.customEngineOn) {\n renderNotice(\"Custom engine is not configured. Connect it from the AgentNet app settings.\");\n input.value = \"\";\n return;\n }\n if (arg === \"claude\" || arg === \"codex\" || arg === \"custom\") selectTab(arg);\n input.value = \"\";\n return;\n case \"model\":\n if (arg) {\n modelByCli[S.cli] = arg;\n fillModels();\n vscode.postMessage({ type: \"model\", model: arg });\n }\n input.value = \"\";\n return;\n case \"mode\":\n if (arg) {\n modeByCli[S.cli] = arg;\n fillModes();\n vscode.postMessage({ type: \"mode\", mode: arg });\n }\n input.value = \"\";\n return;\n case \"effort\":\n if (arg) {\n effortByCli[S.cli] = arg;\n fillModes();\n vscode.postMessage({ type: \"effort\", effort: arg === \"default\" ? void 0 : arg });\n }\n input.value = \"\";\n return;\n case \"help\": {\n const helpText = slashCommandsForCli().map(function(c) {\n return \"/\" + c.name + (c.args ? \" \" + c.args : \"\") + \" - \" + c.desc;\n }).join(\"\\n\");\n const pre = document.createElement(\"pre\");\n pre.style.cssText = \"margin:8px 0;padding:8px 12px;background:var(--an-bg-1);border-radius:6px;font-size:0.82em;opacity:0.8\";\n pre.textContent = helpText;\n log.appendChild(pre);\n syncWatermark();\n input.value = \"\";\n return;\n }\n default: {\n vscode.postMessage({ type: \"slashCommand\", command: cmd, arg });\n showTyping();\n input.value = \"\";\n return;\n }\n }\n }\n const activeStatus = S.cliReport && S.cliReport[S.cli];\n if (activeStatus === \"missing\") {\n renderEngineMissing(S.cli);\n return;\n }\n if (activeStatus === \"no-login\") {\n renderNotice((S.cli === \"claude\" ? \"Claude\" : \"Codex\") + \" is not signed in. Type /login to connect it.\");\n return;\n }\n const images = S.attached.map((a) => ({ mime: a.mime, dataBase64: a.dataBase64, name: a.name }));\n S.pendingSentImages = S.attached.map((a) => a.dataUrl);\n vscode.postMessage({ type: \"send\", text, images });\n S.attached = [];\n renderAttachStrip();\n input.value = \"\";\n input.style.height = \"auto\";\n showTyping();\n }\n function autoGrowInput() {\n if (S.growRaf) return;\n S.growRaf = requestAnimationFrame(() => {\n S.growRaf = 0;\n input.style.height = \"auto\";\n input.style.height = Math.min(input.scrollHeight, 220) + \"px\";\n });\n }\n function wireComposer() {\n attachBtn.addEventListener(\"click\", () => {\n if (!input.disabled) fileInput.click();\n });\n fileInput.addEventListener(\"change\", () => {\n addFiles(fileInput.files || []);\n fileInput.value = \"\";\n });\n input.addEventListener(\"paste\", (e) => {\n const items = e.clipboardData && e.clipboardData.items || [];\n const imgs = [];\n for (const it of items) {\n if (it.kind === \"file\" && it.type.indexOf(\"image/\") === 0) {\n const f = it.getAsFile();\n if (f) imgs.push(f);\n }\n }\n if (imgs.length) {\n e.preventDefault();\n addFiles(imgs);\n }\n });\n [\"dragenter\", \"dragover\"].forEach((ev) => inputWrap.addEventListener(ev, (e) => {\n if (e.dataTransfer && Array.from(e.dataTransfer.types || []).indexOf(\"Files\") >= 0) {\n e.preventDefault();\n inputWrap.classList.add(\"dragover\");\n }\n }));\n [\"dragleave\", \"drop\"].forEach((ev) => inputWrap.addEventListener(ev, (e) => {\n if (ev === \"drop\") {\n e.preventDefault();\n if (e.dataTransfer) addFiles(e.dataTransfer.files || []);\n }\n inputWrap.classList.remove(\"dragover\");\n }));\n document.getElementById(\"send\").addEventListener(\"click\", () => {\n S.busy ? interruptTurn() : send();\n });\n document.getElementById(\"newBtn\").addEventListener(\"click\", () => {\n vscode.postMessage({ type: \"new\" });\n closeMenus();\n });\n document.getElementById(\"newTabBtn\").addEventListener(\"click\", () => vscode.postMessage({ type: \"newTab\" }));\n input.addEventListener(\"keydown\", (e) => {\n if (e.isComposing || e.keyCode === 229) return;\n if (S.activeSlashMatches.length > 0) {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n S.slashIdx = (S.slashIdx + 1) % S.activeSlashMatches.length;\n renderSlashMenu();\n return;\n }\n if (e.key === \"ArrowUp\") {\n e.preventDefault();\n S.slashIdx = (S.slashIdx - 1 + S.activeSlashMatches.length) % S.activeSlashMatches.length;\n renderSlashMenu();\n return;\n }\n if (e.key === \"Tab\" || e.key === \"Enter\") {\n e.preventDefault();\n if (S.activeSlashMatches[S.slashIdx]) {\n completeSlash(S.activeSlashMatches[S.slashIdx]);\n }\n return;\n }\n if (e.key === \"Escape\") {\n e.preventDefault();\n e.stopPropagation();\n S.suppressSlash = true;\n renderSlashMenu();\n return;\n }\n }\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n send();\n }\n if (e.key === \"Escape\" && S.busy) {\n e.preventDefault();\n interruptTurn();\n }\n });\n document.addEventListener(\"keydown\", (e) => {\n if (e.key === \"Escape\" && S.busy) {\n e.preventDefault();\n interruptTurn();\n }\n });\n input.addEventListener(\"input\", () => {\n autoGrowInput();\n S.suppressSlash = false;\n S.slashIdx = 0;\n renderSlashMenu();\n });\n }\n\n // src/chat/ui/panel/turns.ts\n function makeUtext(userText) {\n const wrap = document.createElement(\"div\");\n wrap.className = \"utextWrap\";\n const ut = document.createElement(\"div\");\n ut.className = \"utext\";\n ut.textContent = userText;\n wrap.appendChild(ut);\n const longMsg = userText.split(\"\\n\").length > 4 || userText.length > 280;\n if (longMsg) {\n wrap.classList.add(\"collapsed\");\n const tog = document.createElement(\"div\");\n tog.className = \"utextToggle\";\n tog.textContent = \"Show more\";\n tog.addEventListener(\"click\", () => {\n const exp = wrap.classList.toggle(\"expanded\");\n wrap.classList.toggle(\"collapsed\", !exp);\n tog.textContent = exp ? \"Show less\" : \"Show more\";\n });\n wrap.appendChild(tog);\n }\n return wrap;\n }\n var ENGINE_BADGE = { claude: \"claude\", codex: \"codex · gpt\", custom: \"custom\" };\n var engineMark = (c) => ENGINE_BADGE[c] ? c : \"codex\";\n function startTurn(userText, badgeCli, imageInfo) {\n const turn = document.createElement(\"div\");\n turn.className = \"turn\";\n const head = document.createElement(\"div\");\n head.className = \"turnHead\";\n head.innerHTML = '>';\n const ut = makeUtext(userText);\n head.appendChild(ut);\n if (badgeCli) {\n const b = document.createElement(\"span\");\n b.className = \"badge \" + engineMark(badgeCli);\n b.textContent = ENGINE_BADGE[engineMark(badgeCli)];\n head.appendChild(b);\n }\n const imgEl = userImagesEl(imageInfo);\n if (imgEl) ut.insertBefore(imgEl, ut.querySelector(\".utextToggle\"));\n const body = document.createElement(\"div\");\n body.className = \"turnBody\";\n turn.appendChild(head);\n turn.appendChild(body);\n log.appendChild(turn);\n turn._body = body;\n S.tailTurn = turn;\n scrollToLatest();\n syncWatermark();\n return body;\n }\n function startTurnTop(userText, badgeCli) {\n const turn = document.createElement(\"div\");\n turn.className = \"turn\";\n const head = document.createElement(\"div\");\n head.className = \"turnHead\";\n head.innerHTML = '>';\n head.appendChild(makeUtext(userText));\n if (badgeCli) {\n const b = document.createElement(\"span\");\n b.className = \"badge \" + engineMark(badgeCli);\n b.textContent = ENGINE_BADGE[engineMark(badgeCli)];\n head.appendChild(b);\n }\n const body = document.createElement(\"div\");\n body.className = \"turnBody\";\n turn.appendChild(head);\n turn.appendChild(body);\n log.insertBefore(turn, log.firstChild);\n turn._body = body;\n S.headTurn = turn;\n return body;\n }\n function tailBody() {\n if (S.tailTurn && S.tailTurn._body) return S.tailTurn._body;\n const turn = document.createElement(\"div\");\n turn.className = \"turn\";\n const body = document.createElement(\"div\");\n body.className = \"turnBody\";\n turn.appendChild(body);\n log.appendChild(turn);\n turn._body = body;\n S.tailTurn = turn;\n syncWatermark();\n return body;\n }\n function appendNode(el, dir) {\n const body = dir === \"head\" ? S.headTurn && S.headTurn._body || startTurnTop(\"\", void 0) : tailBody();\n body.appendChild(el);\n if (dir !== \"head\") stickToBottom();\n }\n function bubble(role, prepend, badgeCli) {\n const node = document.createElement(\"div\");\n node.className = \"node \" + role + (badgeCli ? \" \" + engineMark(badgeCli) : \"\");\n const el = document.createElement(\"div\");\n el.className = \"msg \" + role;\n node.appendChild(el);\n appendNode(node, prepend ? \"head\" : \"tail\");\n el._row = node;\n return el;\n }\n function clampBody(el, row, threshold) {\n if ((el.textContent || \"\").length <= threshold) return;\n el.classList.add(\"clamp\");\n const btn = document.createElement(\"button\");\n btn.className = \"moreBtn\";\n btn.textContent = \"show more\";\n btn.addEventListener(\"click\", () => {\n const on = el.classList.toggle(\"clamp\");\n btn.textContent = on ? \"show more\" : \"show less\";\n });\n row.appendChild(btn);\n }\n function renderSummary(text, prepend) {\n const node = document.createElement(\"div\");\n node.className = \"node summary\";\n const rule = document.createElement(\"div\");\n rule.className = \"compactRule\";\n rule.innerHTML = '
⌘ context compacted
';\n const body = document.createElement(\"div\");\n body.className = \"summaryBody\";\n body.textContent = text;\n node.appendChild(rule);\n node.appendChild(body);\n appendNode(node, prepend ? \"head\" : \"tail\");\n if (!prepend) clampBody(body, body, 400);\n }\n function addMsgCopy(row, el) {\n if (!row || row.querySelector(\":scope > .msgCopy\")) return;\n const btn = document.createElement(\"button\");\n btn.className = \"msgCopy\";\n btn.title = \"Copy message\";\n btn.innerHTML = COPY_ICON;\n btn.addEventListener(\"click\", (e) => {\n e.stopPropagation();\n copyText(el.dataset.md || el.textContent || \"\", () => {\n btn.classList.add(\"done\");\n btn.innerHTML = CHECK_ICON;\n setTimeout(() => {\n btn.classList.remove(\"done\");\n btn.innerHTML = COPY_ICON;\n }, 1200);\n });\n });\n row.appendChild(btn);\n }\n function addFooter(row, durationMs, model) {\n if (durationMs == null && !model) return;\n const f = document.createElement(\"div\");\n f.className = \"footer\";\n if (durationMs != null) {\n const s = durationMs / 1e3;\n f.appendChild(document.createTextNode(s < 60 ? s.toFixed(1) + \"s\" : Math.floor(s / 60) + \"m \" + Math.round(s % 60) + \"s\"));\n }\n if (model) {\n const m = document.createElement(\"span\");\n m.className = \"mdl\";\n m.textContent = model;\n f.appendChild(m);\n }\n row.appendChild(f);\n }\n function toolRow(prepend) {\n const row = document.createElement(\"div\");\n row.className = \"node tool\";\n appendNode(row, prepend ? \"head\" : \"tail\");\n return row;\n }\n var CHEV = '';\n function makeCollapsible(head, body, startOpen) {\n head.classList.add(\"clickable\");\n head.insertAdjacentHTML(\"afterbegin\", CHEV);\n const set = (open) => {\n head.classList.toggle(\"open\", open);\n body.hidden = !open;\n };\n set(startOpen);\n head.addEventListener(\"click\", () => set(body.hidden));\n }\n function setOutput(card, output, exitCode) {\n let out = card.querySelector(\".toolOut\");\n if (!out) {\n out = document.createElement(\"pre\");\n out.className = \"toolOut toolBody\";\n card.appendChild(out);\n makeCollapsible(card.querySelector(\".toolHead\"), out, false);\n }\n out.textContent = output;\n if (typeof exitCode === \"number\" && exitCode !== 0) card.classList.add(\"failed\");\n }\n function renderDiff(pre, diffText) {\n const lines = diffText.split(\"\\n\");\n const kind = lines.map((l) => l[0] === \"+\" ? \"add\" : l[0] === \"-\" ? \"del\" : \"ctx\");\n let added = 0, removed = 0;\n for (const k of kind) {\n if (k === \"add\") added++;\n else if (k === \"del\") removed++;\n }\n const CTX = 2;\n const keep = new Array(lines.length).fill(false);\n for (let i = 0; i < lines.length; i++) {\n if (kind[i] === \"ctx\") continue;\n for (let c = Math.max(0, i - CTX); c <= Math.min(lines.length - 1, i + CTX); c++) keep[c] = true;\n }\n let folding = false;\n for (let i = 0; i < lines.length; i++) {\n if (!keep[i]) {\n if (!folding) {\n folding = true;\n const f = document.createElement(\"div\");\n f.className = \"fold\";\n f.textContent = \"⋯\";\n pre.appendChild(f);\n }\n continue;\n }\n folding = false;\n const d = document.createElement(\"div\");\n d.className = kind[i];\n const sign = kind[i] === \"add\" ? \"+\" : kind[i] === \"del\" ? \"−\" : \"\";\n const text = lines[i].replace(/^[+\\-]/, \"\");\n d.innerHTML = '' + sign + \"\";\n d.appendChild(document.createTextNode(text || \" \"));\n pre.appendChild(d);\n }\n return { added, removed };\n }\n function renderToolInto(row, msg) {\n const t = msg.tool || {};\n if (t.command !== void 0) {\n const card = document.createElement(\"div\");\n card.className = \"toolCard bash\";\n const head = document.createElement(\"div\");\n head.className = \"toolHead\";\n head.innerHTML = '$';\n const cmd = document.createElement(\"span\");\n cmd.className = \"cmd\";\n cmd.textContent = t.command;\n head.appendChild(cmd);\n card.appendChild(head);\n if (t.output) setOutput(card, t.output, t.exitCode);\n row.appendChild(card);\n return t.output ? null : card;\n } else if (t.diff !== void 0) {\n const card = document.createElement(\"div\");\n card.className = \"toolCard diff\";\n const head = document.createElement(\"div\");\n head.className = \"toolHead\";\n head.innerHTML = '✎';\n const fn = document.createElement(\"span\");\n fn.className = \"file\";\n fn.textContent = t.file || \"edit\";\n head.appendChild(fn);\n card.appendChild(head);\n const pre = document.createElement(\"pre\");\n pre.className = \"diffBody toolBody\";\n const { added, removed } = renderDiff(pre, t.diff);\n const stat = document.createElement(\"span\");\n stat.className = \"stat\";\n stat.innerHTML = '+' + added + '−' + removed + \"\";\n head.appendChild(stat);\n card.appendChild(pre);\n makeCollapsible(head, pre, true);\n row.appendChild(card);\n } else {\n const card = document.createElement(\"div\");\n card.className = \"toolCard op\";\n const icon = t.name === \"Read\" ? '' : t.name === \"Write\" ? \"✎\" : \"•\";\n card.innerHTML = '' + icon + \"\";\n card.appendChild(document.createTextNode(msg.text || t.name || \"tool\"));\n row.appendChild(card);\n }\n return null;\n }\n function renderTool(msg, prepend) {\n const t = msg.tool || {};\n if (t.command === void 0 && t.diff === void 0 && t.output && S.openBash && !prepend) {\n setOutput(S.openBash, t.output, t.exitCode);\n S.openBash = null;\n return;\n }\n const row = toolRow(prepend);\n const awaiting = renderToolInto(row, msg);\n if (awaiting) S.openBash = awaiting;\n if (!prepend) {\n if (S.typingEl) tailBody().appendChild(S.typingEl);\n stickToBottom();\n }\n }\n\n // src/chat/ui/panel/shell.ts\n function syncWatermark() {\n mainEl.classList.toggle(\"hasMsgs\", log.childElementCount > 0);\n }\n function renderNotice(text) {\n const notice = document.createElement(\"div\");\n notice.style.cssText = \"padding:4px 12px;font-size:0.82em;opacity:0.65;white-space:pre-wrap\";\n notice.textContent = text;\n log.appendChild(notice);\n syncWatermark();\n stickToBottom();\n }\n function renderActionNotice(text, actions) {\n const notice = document.createElement(\"div\");\n notice.style.cssText = \"padding:4px 12px;font-size:0.82em;white-space:pre-wrap\";\n const body = document.createElement(\"div\");\n body.style.opacity = \"0.65\";\n body.textContent = text;\n const row = document.createElement(\"div\");\n row.style.cssText = \"display:flex;gap:6px;margin-top:6px\";\n for (const a of actions) {\n const btn = document.createElement(\"button\");\n btn.textContent = a[0];\n btn.style.cssText = \"padding:3px 10px;font-size:1em\";\n btn.addEventListener(\"click\", () => a[1](btn));\n row.appendChild(btn);\n }\n notice.appendChild(body);\n notice.appendChild(row);\n log.appendChild(notice);\n syncWatermark();\n stickToBottom();\n }\n function copyAction(command) {\n return [\"Copy command\", (btn) => {\n if (navigator.clipboard) navigator.clipboard.writeText(command).catch(() => {\n });\n btn.textContent = \"Copied\";\n }];\n }\n function renderEngineBanner(text, actions, dismissKey) {\n engineBanner.innerHTML = \"\";\n const body = document.createElement(\"div\");\n body.className = \"eb-body\";\n body.textContent = text;\n const row = document.createElement(\"div\");\n row.className = \"eb-actions\";\n for (const a of actions) {\n const btn = document.createElement(\"button\");\n btn.className = \"eb-btn\";\n btn.textContent = a[0];\n btn.addEventListener(\"click\", () => a[1](btn));\n row.appendChild(btn);\n }\n const close = document.createElement(\"button\");\n close.className = \"eb-close\";\n close.setAttribute(\"aria-label\", \"Dismiss\");\n close.textContent = \"×\";\n close.addEventListener(\"click\", () => {\n engineBanner.style.display = \"none\";\n engineBanner.innerHTML = \"\";\n vscode.postMessage({ type: \"dismissEngineUpdate\", cli: dismissKey });\n });\n engineBanner.appendChild(body);\n engineBanner.appendChild(row);\n engineBanner.appendChild(close);\n engineBanner.style.display = \"flex\";\n }\n function renderEngineMissing(which) {\n if (S.cliReport?.[engineBinary(which)] === \"node-missing\") {\n renderActionNotice(NODE_REQUIRED_MESSAGE, [\n [\"Get Node.js\", () => window.open(NODE_DOWNLOAD_URL, \"_blank\", \"noopener,noreferrer\")],\n [\"Check again\", () => vscode.postMessage({ type: \"getCliStatus\" })]\n ]);\n return;\n }\n const name = which === \"claude\" ? \"Claude\" : \"Codex\";\n const command = ENGINE_INSTALL_COMMAND[which];\n renderActionNotice(\n name + \" is not installed. Install it, then sign in with /login.\\n$ \" + command,\n [\n [\"Install in terminal\", () => vscode.postMessage({ type: \"installEngine\", cli: which })],\n copyAction(command)\n ]\n );\n }\n function renderStatus(status) {\n const ctx = typeof status.contextTokens === \"number\" ? status.contextTokens >= 1e3 ? Math.round(status.contextTokens / 1e3) + \"k\" : String(status.contextTokens) : \"unknown\";\n const text = [\n \"engine: \" + status.cli,\n \"session: \" + (status.sessionId || \"(none)\"),\n \"model: \" + (status.model || \"default\"),\n \"mode: \" + (status.mode || \"default\"),\n \"effort: \" + (status.effort || \"default\"),\n \"context tokens: \" + ctx\n ].join(\"\\n\");\n const pre = document.createElement(\"pre\");\n pre.style.cssText = \"margin:8px 0;padding:8px 12px;background:var(--an-bg-1);border-radius:6px;font-size:0.82em;opacity:0.85;white-space:pre-wrap\";\n pre.textContent = text;\n log.appendChild(pre);\n syncWatermark();\n stickToBottom();\n }\n var LIMIT_WINDOW_LABEL = {\n five_hour: \"5-hour\",\n seven_day: \"weekly\",\n seven_day_opus: \"weekly Opus\",\n seven_day_sonnet: \"weekly Sonnet\",\n overage: \"overage\"\n };\n var ctxLabel = null;\n var usageByCli = { claude: null, codex: null };\n var usageExpanded = false;\n function renderLimitMeter(info) {\n const pct = typeof info.utilization === \"number\" ? info.utilization : usageByCli[info.cli]?.pct;\n if (pct === void 0) return;\n const warn = pct >= 80 || info.status === \"rejected\" || info.status === \"allowed_warning\";\n const windowLabel = LIMIT_WINDOW_LABEL[info.window || \"\"] || \"usage\";\n let resets = \"\";\n if (typeof info.resetsAt === \"number\" && info.resetsAt > 0) {\n resets = \" · resets \" + new Date(info.resetsAt).toLocaleTimeString([], { hour: \"2-digit\", minute: \"2-digit\" });\n }\n usageByCli[info.cli] = { pct, warn, title: \"Used \" + Math.round(pct) + \"% of your \" + windowLabel + \" limit\" + resets };\n paintMeters();\n }\n function setCtxTokens(contextTokens) {\n if (typeof contextTokens !== \"number\") return;\n ctxLabel = contextTokens >= 1e3 ? Math.round(contextTokens / 1e3) + \"k\" : String(contextTokens);\n paintMeters();\n }\n function clearCtx() {\n ctxLabel = null;\n usageExpanded = false;\n paintMeters();\n }\n function paintMeters() {\n const usage = usageByCli[S.cli];\n if (usage) {\n const fill = limitMeter.querySelector(\".lm-fill\");\n const pct = limitMeter.querySelector(\".lm-pct\");\n if (fill) fill.style.width = usage.pct + \"%\";\n if (pct) pct.textContent = Math.round(usage.pct) + \"%\";\n limitMeter.classList.toggle(\"warn\", usage.warn);\n limitMeter.title = usage.title + \" · click to show context tokens\";\n limitMeter.style.display = \"inline-flex\";\n } else {\n limitMeter.style.display = \"none\";\n }\n if (ctxLabel !== null && (usageExpanded || !usage)) {\n ctxMeter.textContent = \"ctx: \" + ctxLabel;\n ctxMeter.style.display = \"inline-flex\";\n } else {\n ctxMeter.style.display = \"none\";\n }\n }\n function nearBottom() {\n const d = log.scrollHeight - log.scrollTop - log.clientHeight;\n return d <= Math.max(180, log.clientHeight * 0.25);\n }\n function toBottomInstant() {\n const prev = log.style.scrollBehavior;\n log.style.scrollBehavior = \"auto\";\n log.scrollTop = log.scrollHeight;\n log.style.scrollBehavior = prev;\n }\n function updateJump() {\n if (!jumpBtn) return;\n if (S.stick) S.hasNew = false;\n jumpBtn.classList.toggle(\"show\", !S.stick);\n jumpBtn.classList.toggle(\"hasNew\", S.hasNew);\n }\n function stickToBottom() {\n if (S.stick) toBottomInstant();\n else S.hasNew = true;\n updateJump();\n }\n function scrollToLatest() {\n S.stick = true;\n S.hasNew = false;\n toBottomInstant();\n updateJump();\n }\n function showLoading() {\n loadingEl.style.display = \"flex\";\n }\n function hideLoading() {\n loadingEl.style.display = \"none\";\n }\n var STREAM_MD_MS = 300;\n function flushStreamRender() {\n S.streamRaf = 0;\n if (!S.streaming) return;\n S.lastStreamRender = Date.now();\n const raw = S.streaming.dataset.acc || \"\";\n if (S.streaming.dataset.role === \"assistant\") renderMdStreaming(S.streaming, raw);\n else {\n S.streaming.textContent = raw;\n S.streaming.dataset.md = raw;\n }\n if (S.typingEl) tailBody().appendChild(S.typingEl);\n stickToBottom();\n }\n function scheduleStreamRender() {\n if (S.streamRaf || S.streamTimer) return;\n const wait = STREAM_MD_MS - (Date.now() - S.lastStreamRender);\n if (wait <= 0) S.streamRaf = requestAnimationFrame(flushStreamRender);\n else S.streamTimer = setTimeout(() => {\n S.streamTimer = 0;\n if (!S.streamRaf) S.streamRaf = requestAnimationFrame(flushStreamRender);\n }, wait);\n }\n function cancelStreamRender() {\n if (S.streamRaf) {\n cancelAnimationFrame(S.streamRaf);\n S.streamRaf = 0;\n }\n if (S.streamTimer) {\n clearTimeout(S.streamTimer);\n S.streamTimer = 0;\n }\n }\n function wireShell() {\n if (jumpBtn) jumpBtn.addEventListener(\"click\", scrollToLatest);\n limitMeter.style.cursor = \"pointer\";\n limitMeter.addEventListener(\"click\", () => {\n usageExpanded = !usageExpanded;\n paintMeters();\n });\n }\n\n // src/chat/ui/panel/approval.ts\n function dismissApproval(id) {\n const cards = approvalDock.querySelectorAll(\"[data-approval-id]\");\n for (const c of cards) {\n if (c.dataset.approvalId === id) {\n c.remove();\n syncComposerLock();\n break;\n }\n }\n }\n function renderApproval(req) {\n const card = document.createElement(\"div\");\n card.className = \"approvalCard\";\n card.dataset.approvalId = req.id;\n const isPublish = /publish_skill/.test(req.tool || \"\") || /publish_skill/.test(req.title || \"\");\n const isBuy = /buy_skill/.test(req.tool || \"\") || /buy_skill/.test(req.title || \"\");\n const isForge = isPublish || isBuy;\n if (isForge) {\n card.classList.add(\"skillForge\");\n if (isBuy) card.classList.add(\"buyForge\");\n const stars = document.createElement(\"div\");\n stars.className = \"forgeStars\";\n for (let i = 0; i < 6; i++) {\n const s = document.createElement(\"span\");\n s.className = \"st\";\n s.innerHTML = '';\n s.style.left = 8 + Math.random() * 84 + \"%\";\n s.style.top = 12 + Math.random() * 70 + \"%\";\n s.style.animationDuration = 3.2 + Math.random() * 2.4 + \"s\";\n s.style.animationDelay = Math.random() * 3 + \"s\";\n s.style.fontSize = 7 + Math.random() * 5 + \"px\";\n stars.appendChild(s);\n }\n card.appendChild(stars);\n }\n if (req.kind === \"question\" && Array.isArray(req.questions) && req.questions.length) {\n const sel = {};\n const free = {};\n const total = req.questions.length;\n let step = 0;\n const hasAnswer = (qi) => {\n const typed = (free[qi] || \"\").trim();\n return typed.length > 0 || !!(sel[qi] && sel[qi].length);\n };\n const sendAll = () => {\n const questionResponses = req.questions.map((q, qi) => {\n const typed = (free[qi] || \"\").trim();\n return {\n question: q.question,\n questionId: q.id,\n selected: typed ? [] : sel[qi] || [],\n ...typed ? { text: typed } : {}\n };\n });\n vscode.postMessage({ type: \"approvalDecision\", id: req.id, outcome: \"once\", questionResponses });\n card.remove();\n syncComposerLock();\n };\n const renderStep = () => {\n card.innerHTML = \"\";\n const q = req.questions[step];\n let updateNext = () => {\n };\n let otherInput = null;\n if (total > 1) {\n const counter = document.createElement(\"div\");\n counter.className = \"qCount\";\n counter.textContent = step + 1 + \" / \" + total;\n card.appendChild(counter);\n }\n const block = document.createElement(\"div\");\n block.className = \"qBlock\";\n if (q.header) {\n const h = document.createElement(\"span\");\n h.className = \"qHeader\";\n h.textContent = q.header;\n block.appendChild(h);\n }\n const qt = document.createElement(\"div\");\n qt.className = \"qText\";\n qt.textContent = q.question;\n block.appendChild(qt);\n const opts = document.createElement(\"div\");\n opts.className = \"qOpts\";\n (q.options || []).forEach((opt) => {\n const b = document.createElement(\"button\");\n b.type = \"button\";\n b.className = \"qOpt\";\n if ((sel[step] || []).indexOf(opt.label) >= 0) b.classList.add(\"on\");\n const t = document.createElement(\"div\");\n t.className = \"qOptLabel\";\n t.textContent = opt.label;\n b.appendChild(t);\n if (opt.description) {\n const d = document.createElement(\"div\");\n d.className = \"qOptDesc\";\n d.textContent = opt.description;\n b.appendChild(d);\n }\n b.addEventListener(\"click\", () => {\n const cur = sel[step] || [];\n delete free[step];\n if (q.multiSelect) {\n sel[step] = cur.indexOf(opt.label) >= 0 ? cur.filter((l) => l !== opt.label) : cur.concat(opt.label);\n } else {\n sel[step] = cur[0] === opt.label ? [] : [opt.label];\n }\n Array.from(opts.children).forEach((c, i) => c.classList.toggle(\"on\", (sel[step] || []).indexOf((q.options[i] || {}).label) >= 0));\n if (otherInput) otherInput.value = \"\";\n updateNext();\n });\n opts.appendChild(b);\n });\n block.appendChild(opts);\n if (q.allowCustomInput) {\n const label = document.createElement(\"div\");\n label.className = \"qOtherLabel\";\n label.textContent = q.options && q.options.length ? \"Or type your own answer\" : \"Type your answer\";\n block.appendChild(label);\n otherInput = q.secret ? document.createElement(\"input\") : document.createElement(\"textarea\");\n otherInput.className = \"qOtherInput\";\n otherInput.placeholder = \"Type your answer…\";\n if (q.secret) otherInput.type = \"password\";\n else otherInput.rows = 3;\n if (free[step]) otherInput.value = free[step];\n otherInput.addEventListener(\"input\", () => {\n free[step] = otherInput.value;\n sel[step] = [];\n Array.from(opts.children).forEach((c) => c.classList.remove(\"on\"));\n updateNext();\n });\n block.appendChild(otherInput);\n }\n card.appendChild(block);\n const actions2 = document.createElement(\"div\");\n actions2.className = \"apActions\";\n if (step > 0) {\n const back = document.createElement(\"button\");\n back.className = \"apBtn always\";\n back.textContent = \"Back\";\n back.addEventListener(\"click\", () => {\n step -= 1;\n renderStep();\n });\n actions2.appendChild(back);\n }\n const next = document.createElement(\"button\");\n next.className = \"apBtn ok\";\n const last = step === total - 1;\n next.textContent = last ? \"Send\" : \"Next\";\n next.addEventListener(\"click\", () => {\n if (!hasAnswer(step)) return;\n if (last) sendAll();\n else {\n step += 1;\n renderStep();\n }\n });\n actions2.appendChild(next);\n card.appendChild(actions2);\n updateNext = () => {\n next.disabled = !hasAnswer(step);\n };\n updateNext();\n };\n renderStep();\n approvalDock.insertBefore(card, approvalDock.firstChild);\n syncComposerLock();\n return;\n }\n const isPlan = req.kind === \"plan\";\n const isDanger = req.risk === \"danger\";\n const head = document.createElement(\"div\");\n head.className = \"apHead\" + (isDanger ? \" apDanger\" : \"\");\n const glyphEl = document.createElement(\"span\");\n glyphEl.className = \"apk\";\n var skSvg = '';\n var rdSvg = '';\n glyphEl.innerHTML = req.kind === \"bash\" ? \"$\" : req.kind === \"read\" ? rdSvg : isPlan ? skSvg : isForge ? skSvg : \"✎\";\n head.appendChild(glyphEl);\n if (isDanger) {\n const warn = document.createElement(\"span\");\n warn.style.cssText = \"color:var(--vscode-errorForeground,#f44);font-weight:700;margin-right:4px\";\n warn.innerHTML = ' DANGER ·';\n head.appendChild(warn);\n }\n const ttl = document.createElement(\"span\");\n ttl.className = \"apTitle\";\n ttl.textContent = isPublish ? \"Forge skill: \" + (req.input && req.input.name || \"new skill\") : isBuy ? \"Buy skill\" + (req.input && req.input.name ? \": \" + req.input.name : \"\") : req.title || req.tool;\n head.appendChild(ttl);\n const tag = document.createElement(\"span\");\n tag.className = \"apTag\";\n tag.textContent = req.cli;\n head.appendChild(tag);\n card.appendChild(head);\n let commandInput = null;\n if (req.command) {\n const pre = document.createElement(\"pre\");\n pre.className = \"apBody\";\n pre.textContent = req.command;\n card.appendChild(pre);\n if (req.kind === \"bash\") {\n commandInput = document.createElement(\"textarea\");\n commandInput.className = \"apBody\";\n commandInput.style.cssText = \"display:none;width:100%;box-sizing:border-box;resize:vertical;font-family:monospace;font-size:0.85em;background:var(--an-bg-1);border:1px solid var(--eng);border-radius:4px;padding:6px;color:inherit\";\n commandInput.value = req.command;\n card.appendChild(commandInput);\n const PENCIL_SVG = '';\n const XMARK_SVG = '';\n const editBtn = document.createElement(\"button\");\n editBtn.className = \"apEdit\";\n editBtn.innerHTML = PENCIL_SVG;\n editBtn.title = \"Edit\";\n editBtn.setAttribute(\"aria-label\", \"Edit\");\n editBtn.addEventListener(\"click\", () => {\n const editing = commandInput.style.display !== \"none\";\n pre.style.display = editing ? \"\" : \"none\";\n commandInput.style.display = editing ? \"none\" : \"\";\n editBtn.innerHTML = editing ? PENCIL_SVG : XMARK_SVG;\n editBtn.title = editing ? \"Edit\" : \"Cancel\";\n });\n head.appendChild(editBtn);\n }\n } else if (req.plan) {\n const pre = document.createElement(\"pre\");\n pre.className = \"apBody planBody\";\n pre.textContent = req.plan;\n card.appendChild(pre);\n } else if (req.diff) {\n const pre = document.createElement(\"pre\");\n pre.className = \"apBody diffBody\";\n for (const ln of String(req.diff).split(\"\\n\")) {\n const d = document.createElement(\"div\");\n d.className = ln[0] === \"+\" ? \"add\" : ln[0] === \"-\" ? \"del\" : \"ctx\";\n d.textContent = ln;\n pre.appendChild(d);\n }\n card.appendChild(pre);\n } else if (req.file) {\n const f = document.createElement(\"div\");\n f.className = \"apBody\";\n f.textContent = req.file;\n card.appendChild(f);\n } else if (isPublish && req.input) {\n const box = document.createElement(\"div\");\n box.className = \"apBody forgeBody\";\n const nm = document.createElement(\"div\");\n nm.style.cssText = \"font-weight:600;font-size:1.02em\";\n nm.textContent = req.input.name || \"new skill\";\n box.appendChild(nm);\n if (req.input.description) {\n const d = document.createElement(\"div\");\n d.style.cssText = \"opacity:0.85;font-size:0.85em;margin-top:2px\";\n d.textContent = req.input.description;\n box.appendChild(d);\n }\n const priceSol = req.input.priceSol;\n const priceTxt = priceSol == null ? \"0.1 SOL\" : String(priceSol) === \"0\" ? \"free\" : priceSol + \" SOL\";\n const meta = document.createElement(\"div\");\n meta.style.cssText = \"margin-top:5px;font-size:0.8em;opacity:0.7\";\n meta.textContent = \"mint a soulbound NFT · price \" + priceTxt;\n box.appendChild(meta);\n card.appendChild(box);\n }\n const actions = document.createElement(\"div\");\n actions.className = \"apActions\";\n const decide = (outcome, extra) => {\n vscode.postMessage({ type: \"approvalDecision\", id: req.id, outcome, ...extra });\n card.remove();\n syncComposerLock();\n };\n const mk = (label, outcome, cls) => {\n const b = document.createElement(\"button\");\n b.className = \"apBtn \" + cls;\n b.textContent = label;\n b.addEventListener(\"click\", () => decide(outcome));\n return b;\n };\n if (isPlan) {\n actions.appendChild(mk(\"Approve plan\", \"once\", \"ok\"));\n actions.appendChild(mk(\"Keep planning\", \"deny\", \"no\"));\n } else {\n actions.appendChild(mk(\"Approve\", \"once\", \"ok\"));\n actions.appendChild(mk(\"Always\", \"always\", \"always\"));\n let approveEdited = null;\n if (req.kind === \"bash\" && commandInput) {\n approveEdited = document.createElement(\"button\");\n approveEdited.className = \"apBtn ok\";\n approveEdited.textContent = \"Approve edited\";\n approveEdited.style.display = \"none\";\n approveEdited.addEventListener(\"click\", () => {\n decide(\"once\", { updatedInput: { ...req.input ?? {}, command: commandInput.value } });\n });\n actions.appendChild(approveEdited);\n const editToggle = head.querySelector(\"button\");\n if (editToggle) {\n editToggle.addEventListener(\"click\", () => {\n const isEditing = commandInput.style.display !== \"none\";\n if (approveEdited) approveEdited.style.display = isEditing ? \"\" : \"none\";\n });\n }\n }\n const reasonRow = document.createElement(\"div\");\n reasonRow.style.cssText = \"display:none;gap:6px;margin-top:4px;align-items:center;flex-wrap:wrap\";\n const reasonInput = document.createElement(\"input\");\n reasonInput.type = \"text\";\n reasonInput.placeholder = \"Reason for denying (optional)\";\n reasonInput.style.cssText = \"flex:1;min-width:120px;background:var(--an-bg-1);border:1px solid var(--an-line);border-radius:4px;padding:4px 8px;font-size:0.82em;color:inherit;outline:none\";\n const confirmDeny = document.createElement(\"button\");\n confirmDeny.className = \"apBtn no\";\n confirmDeny.textContent = \"Deny\";\n confirmDeny.addEventListener(\"click\", () => decide(\"deny\", { reason: reasonInput.value.trim() || void 0 }));\n const cancelDeny = document.createElement(\"button\");\n cancelDeny.className = \"apBtn\";\n cancelDeny.textContent = \"↩\";\n cancelDeny.style.cssText = \"opacity:0.6\";\n cancelDeny.addEventListener(\"click\", () => {\n reasonRow.style.display = \"none\";\n });\n reasonRow.appendChild(reasonInput);\n reasonRow.appendChild(confirmDeny);\n reasonRow.appendChild(cancelDeny);\n const denyBtn = document.createElement(\"button\");\n denyBtn.className = \"apBtn no\";\n denyBtn.textContent = \"Deny\";\n denyBtn.addEventListener(\"click\", () => {\n reasonRow.style.display = \"flex\";\n reasonInput.focus();\n });\n actions.appendChild(denyBtn);\n card.appendChild(actions);\n card.appendChild(reasonRow);\n }\n if (isPlan) card.appendChild(actions);\n card.addEventListener(\"keydown\", (e) => {\n const btnsAll = Array.from(actions.querySelectorAll(\"button\"));\n const i = btnsAll.indexOf(document.activeElement);\n if (i < 0) return;\n if (e.key === \"ArrowRight\") {\n e.preventDefault();\n btnsAll[(i + 1) % btnsAll.length].focus();\n } else if (e.key === \"ArrowLeft\") {\n e.preventDefault();\n btnsAll[(i + btnsAll.length - 1) % btnsAll.length].focus();\n }\n });\n approvalDock.insertBefore(card, approvalDock.firstChild);\n syncComposerLock();\n if (document.hasFocus()) {\n const first = actions.querySelector(\"button\");\n if (first) first.focus();\n }\n }\n\n // src/chat/ui/panel/messages.ts\n function onMessage(msg) {\n if (msg.role === \"user\") {\n const info = S.pendingSentImages.length ? { thumbs: S.pendingSentImages.splice(0) } : msg.imageCount ? { count: msg.imageCount } : void 0;\n const body = startTurn(msg.text, void 0, info);\n if (S.typingEl) body.appendChild(S.typingEl);\n return;\n }\n if (msg.role === \"tool\") {\n renderTool(msg, false);\n return;\n }\n if (msg.role === \"summary\") {\n renderSummary(msg.text, false);\n return;\n }\n const badge = msg.role === \"assistant\" && msg.cli ? msg.cli : void 0;\n const asMd = (el, raw) => {\n if (msg.role === \"assistant\") renderMd(el, raw);\n else {\n el.textContent = raw;\n el.dataset.md = raw;\n }\n };\n if (msg.partial) {\n if (!S.streaming || S.streaming.dataset.role !== msg.role) {\n S.streaming = bubble(msg.role, false, badge);\n S.streaming.dataset.role = msg.role;\n S.streaming.dataset.acc = \"\";\n S.streaming.classList.add(\"cursor\");\n }\n S.streaming.dataset.acc = msg.text;\n scheduleStreamRender();\n return;\n } else {\n if (S.streaming && S.streaming.dataset.role === msg.role) {\n const prev = S.streaming.dataset.acc || \"\";\n const raw = msg.text.startsWith(prev) ? msg.text : prev + msg.text;\n S.streaming.classList.remove(\"cursor\");\n cancelStreamRender();\n asMd(S.streaming, raw);\n if (msg.role === \"assistant\") addMsgCopy(S.streaming._row, S.streaming);\n S.streaming = null;\n } else {\n const el = bubble(msg.role, false, badge);\n asMd(el, msg.text);\n if (msg.role === \"assistant\") {\n addFooter(el._row, msg.durationMs, msg.model);\n addMsgCopy(el._row, el);\n }\n }\n }\n if (S.typingEl) tailBody().appendChild(S.typingEl);\n stickToBottom();\n }\n\n // src/chat/ui/panel/sessions.ts\n var COLLAPSED = 5;\n function renderSessions() {\n sessList.innerHTML = \"\";\n if (S.cloudListState === \"reauth\" || S.cloudListState === \"transient\") {\n const warn = document.createElement(\"div\");\n warn.style.cssText = \"padding:4px 8px;font-size:11px;color:var(--vscode-editorWarning-foreground, #e5c07b);opacity:.9\";\n warn.textContent = S.cloudListState === \"reauth\" ? \"Cloud sync signed out. Showing this device only. Reconnect in Storage.\" : \"Cloud unreachable. Showing this device only.\";\n sessList.appendChild(warn);\n }\n emptyEl.style.display = S.allSessions.length ? \"none\" : \"block\";\n const shown = S.expanded ? S.allSessions : S.allSessions.slice(0, COLLAPSED);\n for (const s of shown) {\n const el = document.createElement(\"div\");\n el.className = \"sess\" + (s.sessionId === S.activeId ? \" active\" : \"\");\n const title = document.createElement(\"span\");\n title.className = \"title\";\n title.textContent = s.title || \"(untitled)\";\n const time = document.createElement(\"span\");\n time.className = \"time\";\n time.textContent = rel(s.ts);\n const del = document.createElement(\"span\");\n del.className = \"del\";\n del.textContent = \"✕\";\n del.title = \"Delete session\";\n del.onclick = (e) => {\n e.stopPropagation();\n vscode.postMessage({ type: \"delete\", sessionId: s.sessionId });\n };\n el.appendChild(title);\n el.appendChild(time);\n el.appendChild(del);\n el.onclick = () => {\n vscode.postMessage({ type: \"open\", sessionId: s.sessionId });\n closeMenus();\n };\n sessList.appendChild(el);\n }\n if (S.allSessions.length > COLLAPSED) {\n showAll.style.display = \"block\";\n showAll.textContent = S.expanded ? \"접기\" : \"모두 보기(\" + S.allSessions.length + \")\";\n } else {\n showAll.style.display = \"none\";\n }\n }\n function wireSessions() {\n showAll.addEventListener(\"click\", () => {\n S.expanded = !S.expanded;\n renderSessions();\n });\n }\n\n // src/chat/ui/panel/storage.ts\n var cloudState = document.getElementById(\"cloudState\");\n var cloudBtn = document.getElementById(\"cloudBtn\");\n function renderStorage(info, options) {\n S.storageOptions = options || S.storageOptions;\n S.cloudConnected = !!(info && info.connected);\n if (info && info.kind) S.cloudKind = info.kind;\n if (S.cloudConnected) {\n const label = info.kind === \"gdrive\" ? \"Google Drive\" : info.kind === \"icloud\" ? \"iCloud\" : info.kind === \"custom\" ? \"Cloud\" : info.kind;\n const linkable = info.kind === \"gdrive\";\n const acct = info.account ? ' (' + info.account + \")\" : \"\";\n cloudState.innerHTML = '●' + (linkable ? '' + label + \"\" : label) + acct;\n const link = document.getElementById(\"cloudLink\");\n if (link) link.addEventListener(\"click\", (e) => {\n e.preventDefault();\n vscode.postMessage({ type: \"openCloud\", kind: info.kind });\n });\n cloudBtn.textContent = \"disconnect\";\n } else {\n cloudState.innerHTML = '●No cloud';\n cloudBtn.textContent = \"connect\";\n }\n }\n function wireStorage() {\n cloudBtn.addEventListener(\"click\", () => {\n if (S.cloudConnected) {\n vscode.postMessage({ type: \"disconnectCloud\" });\n return;\n }\n vscode.postMessage({ type: \"pickCloud\" });\n });\n }\n\n // src/chat/ui/panel/profile.ts\n function renderAgentIdCard(profile) {\n const el = document.getElementById(\"agentIdCard\");\n if (!el) return;\n const wallet = profile.wallet;\n const rep = profile.reputation || {};\n const repoStars = (profile.verifiedRepos || []).reduce((s, r) => s + (r.stars || 0), 0);\n const ti = profTierInfo(repoStars);\n const curName = ti.cur && ti.cur.name || ti.next && ti.next.name || \"Bronze\";\n const tierColor = TIER_COLOR[curName] || \"var(--an-tier-bronze)\";\n const prevMin = ti.cur ? ti.cur.min : 0;\n const bandPct = ti.next ? Math.min(100, Math.max(0, (repoStars - prevMin) / (ti.next.min - prevMin) * 100)) : 100;\n const litSegs = Math.round(bandPct / 100 * PROF_SEG);\n const starsFrac = ti.next ? repoStars + \"/\" + ti.next.min : \"MAX\";\n const stats = [[\"CREATED\", pad2((profile.createdSkills || []).length)], [\"COPIES\", pad2(rep.totalSupply || 0)], [\"OWNED\", pad2((profile.ownedSkills || []).length)]];\n let statsHtml = \"\";\n stats.forEach((s) => {\n statsHtml += '
' + s[0] + '' + s[1] + \"
\";\n });\n let rungs = \"\";\n PROF_TIERS.forEach((t) => {\n const isCur = t.name === curName;\n const done = repoStars >= t.min && !isCur;\n rungs += '
' + t.name.toUpperCase() + \"
\";\n });\n let segs = \"\";\n for (let i = 0; i < PROF_SEG; i++) segs += '';\n el.innerHTML = '
AGENT
' + wallet.slice(0, 6) + '
…' + wallet.slice(-4) + \"
\" + (profile.self ? \"YOUR AGENT\" : \"AGENT PROFILE\") + '
' + avatarSvg(wallet) + 'ID//' + wallet.slice(0, 4) + '
' + statsHtml + '
TIER
' + rungs + '
STARS' + segs + '' + starsFrac + \"
\";\n }\n var GH_MARK_SVG = '';\n var FOLDER_BINARY = \"01010100101010100101001010101001010010110100101010010101001010010101001010010110101001010010100100101001010101001010\";\n function verifiedWorkHtml(profile) {\n const repos = (profile.verifiedRepos || []).slice().sort((a, b) => (b.stars || 0) - (a.stars || 0));\n if (!repos.length) return \"\";\n let cards = \"\";\n repos.forEach((r) => {\n const stars = r.stars || 0;\n const tier = profRepoTier(stars);\n const fill = profRepoFill(stars);\n let gauge = \"\";\n for (let i = 0; i < 10; i++) gauge += '';\n const url = (r.url || \"\").slice(0, 4) === \"http\" ? r.url : \"\";\n const open = url ? '' : '\");\n });\n return '
Verified work
' + cards + \"
\";\n }\n function closeRepoRegister() {\n if (S.repoModalEl) {\n S.repoModalEl.remove();\n S.repoModalEl = null;\n }\n }\n function openRepoRegister() {\n closeRepoRegister();\n const ov = document.createElement(\"div\");\n ov.className = \"skModal\";\n ov.id = \"repoModal\";\n ov.addEventListener(\"click\", (e) => {\n if (e.target === ov) closeRepoRegister();\n });\n const card = document.createElement(\"div\");\n card.className = \"skModal-card\";\n card.innerHTML = '
Register GitHub work
Loading…
';\n ov.appendChild(card);\n document.body.appendChild(ov);\n card.querySelector(\".skModal-close\").addEventListener(\"click\", closeRepoRegister);\n S.repoModalEl = ov;\n vscode.postMessage({ type: \"getGithubStatus\" });\n }\n function renderRepoModalBody(status) {\n if (!S.repoModalEl) return;\n const body = S.repoModalEl.querySelector(\".rr-body\");\n if (!body) return;\n body.innerHTML = \"\";\n if (!status || !status.hasToken) {\n const p = document.createElement(\"div\");\n p.className = \"rr-hint\";\n p.textContent = \"Add a GitHub token (repo scope) to register your work. Stored locally on this device, never synced.\";\n const inp = document.createElement(\"input\");\n inp.type = \"password\";\n inp.className = \"rr-input\";\n inp.placeholder = \"ghp_… (GitHub personal access token)\";\n const link = document.createElement(\"a\");\n link.className = \"rr-link\";\n link.href = \"https://github.com/settings/tokens/new?scopes=repo&description=AgentNet\";\n link.target = \"_blank\";\n link.rel = \"noopener noreferrer\";\n link.textContent = \"Create a token ↗\";\n const err = document.createElement(\"div\");\n err.className = \"rr-err\";\n const btn = document.createElement(\"button\");\n btn.className = \"rr-btn\";\n btn.textContent = \"Save token\";\n btn.addEventListener(\"click\", () => {\n const t = inp.value.trim();\n if (!t) return;\n btn.disabled = true;\n btn.textContent = \"Saving…\";\n err.style.display = \"none\";\n vscode.postMessage({ type: \"submitGithubToken\", token: t });\n });\n body.appendChild(p);\n body.appendChild(inp);\n body.appendChild(link);\n body.appendChild(err);\n body.appendChild(btn);\n } else {\n const p = document.createElement(\"div\");\n p.className = \"rr-hint\";\n p.textContent = \"Register a public GitHub repo as verified work\" + (status.masked ? \" (token \" + status.masked + \")\" : \"\") + \".\";\n const inp = document.createElement(\"input\");\n inp.type = \"text\";\n inp.className = \"rr-input\";\n inp.placeholder = \"owner/name or github.com URL\";\n body.appendChild(p);\n body.appendChild(inp);\n const owned = S.ownedSkills.filter((n) => !!S.skillMints[n]);\n const checks = [];\n if (owned.length) {\n const lbl = document.createElement(\"div\");\n lbl.className = \"rr-sublabel\";\n lbl.textContent = \"Link skills (optional)\";\n body.appendChild(lbl);\n const list = document.createElement(\"div\");\n list.className = \"rr-skills\";\n owned.forEach((n) => {\n const row = document.createElement(\"label\");\n row.className = \"rr-skill\";\n const cb = document.createElement(\"input\");\n cb.type = \"checkbox\";\n cb.value = S.skillMints[n];\n const nm = document.createElement(\"span\");\n nm.textContent = n;\n row.appendChild(cb);\n row.appendChild(nm);\n list.appendChild(row);\n checks.push(cb);\n });\n body.appendChild(list);\n }\n const err = document.createElement(\"div\");\n err.className = \"rr-err\";\n const btn = document.createElement(\"button\");\n btn.className = \"rr-btn\";\n btn.textContent = \"Register repo\";\n btn.addEventListener(\"click\", () => {\n const repo = inp.value.trim();\n if (!repo) {\n err.textContent = \"Enter a repo (owner/name).\";\n err.style.display = \"\";\n return;\n }\n const mints = checks.filter((c) => c.checked).map((c) => c.value);\n btn.disabled = true;\n btn.textContent = \"Registering…\";\n err.style.display = \"none\";\n vscode.postMessage({ type: \"registerWorkRepo\", repo, skillMints: mints });\n });\n body.appendChild(err);\n body.appendChild(btn);\n }\n }\n function renderProfile(profile) {\n profile = mergeOptimistic(profile);\n const self = profile.self;\n const wallet = profile.wallet;\n document.getElementById(\"profileSelfOnly2\").style.display = self ? \"\" : \"none\";\n renderAgentIdCard(profile);\n const body = document.getElementById(\"profileBody\");\n body.innerHTML = \"\";\n const tabs2 = document.createElement(\"div\");\n tabs2.className = \"pr-tabs\";\n const tabAgent = document.createElement(\"button\");\n tabAgent.className = \"pr-tab on\";\n tabAgent.innerHTML = '
Agent
エージェント
';\n const tabCommunity = document.createElement(\"button\");\n tabCommunity.className = \"pr-tab\";\n tabCommunity.innerHTML = '
Community
コミュニティ
';\n tabs2.appendChild(tabAgent);\n tabs2.appendChild(tabCommunity);\n body.appendChild(tabs2);\n const paneAgent = document.createElement(\"div\");\n const paneCommunity = document.createElement(\"div\");\n paneCommunity.style.display = \"none\";\n body.appendChild(paneAgent);\n body.appendChild(paneCommunity);\n function selectTab2(which) {\n const onAgent = which === \"agent\";\n S.profileTab = onAgent ? \"agent\" : \"community\";\n tabAgent.classList.toggle(\"on\", onAgent);\n tabCommunity.classList.toggle(\"on\", !onAgent);\n paneAgent.style.display = onAgent ? \"\" : \"none\";\n paneCommunity.style.display = onAgent ? \"none\" : \"\";\n }\n tabAgent.addEventListener(\"click\", () => selectTab2(\"agent\"));\n tabCommunity.addEventListener(\"click\", () => selectTab2(\"community\"));\n if (self) {\n const rr = document.createElement(\"button\");\n rr.className = \"pr-repo-add\";\n rr.textContent = \"+ Register GitHub work\";\n rr.addEventListener(\"click\", openRepoRegister);\n paneAgent.appendChild(rr);\n }\n const vwHtml = verifiedWorkHtml(profile);\n if (vwHtml) {\n const vw = document.createElement(\"div\");\n vw.innerHTML = vwHtml;\n paneAgent.appendChild(vw);\n }\n function skillCard(card) {\n const owned = self || S.ownedSkills.indexOf(card.name) >= 0;\n return skillSdCard(card, { owned, dim: owned && !self, onOpen: (c) => openSkillModal(c.id) });\n }\n if (profile.createdSkills.length) {\n const sec = document.createElement(\"div\");\n sec.className = \"pr-sec\";\n sec.textContent = \"Created skills\";\n paneAgent.appendChild(sec);\n if (!self) {\n const notOwned = profile.createdSkills.filter((c) => S.ownedSkills.indexOf(c.name) < 0).length;\n if (notOwned > 0) {\n const buyAll = document.createElement(\"button\");\n buyAll.className = \"pr-buyall\";\n buyAll.textContent = \"Buy all · \" + notOwned + \" not owned\";\n buyAll.addEventListener(\"click\", () => showBuyAllConfirm(profile));\n paneAgent.appendChild(buyAll);\n }\n }\n const cg = document.createElement(\"div\");\n cg.className = \"an-sd-grid\";\n profile.createdSkills.forEach((c) => cg.appendChild(skillCard(c)));\n paneAgent.appendChild(cg);\n }\n const ownedNotCreated = profile.ownedSkills.filter((o) => !profile.createdSkills.some((c) => c.id === o.id));\n if (ownedNotCreated.length) {\n const sec = document.createElement(\"div\");\n sec.className = \"pr-sec\";\n sec.textContent = \"Owned skills\";\n paneAgent.appendChild(sec);\n const og = document.createElement(\"div\");\n og.className = \"an-sd-grid\";\n ownedNotCreated.forEach((o) => og.appendChild(skillCard(o)));\n paneAgent.appendChild(og);\n }\n if (!profile.createdSkills.length && !ownedNotCreated.length && !vwHtml) {\n const e = document.createElement(\"div\");\n e.className = \"pr-empty\";\n e.textContent = \"No work or skills yet.\";\n paneAgent.appendChild(e);\n }\n const allThreads = profile.threads || [];\n const selfNotes = allThreads.filter((t) => t.note.isSelfNote).map((t) => t.note);\n if (selfNotes.length) {\n const sec = document.createElement(\"div\");\n sec.className = \"pr-sec\";\n sec.textContent = \"Blog\";\n paneCommunity.appendChild(sec);\n const blog = document.createElement(\"div\");\n blog.className = \"pr-blog\";\n blog.tabIndex = 0;\n blog.setAttribute(\"role\", \"list\");\n blog.setAttribute(\"aria-label\", \"Blog posts\");\n blog.addEventListener(\"keydown\", (e) => {\n if (e.key !== \"ArrowLeft\" && e.key !== \"ArrowRight\") return;\n e.preventDefault();\n blog.scrollBy({ left: e.key === \"ArrowRight\" ? 260 : -260, behavior: \"smooth\" });\n });\n selfNotes.forEach((n) => blog.appendChild(noteCard(n, false)));\n enableDragScroll(blog);\n paneCommunity.appendChild(blog);\n }\n {\n const canPost = self || !!profile.canComment;\n const feedback = feedbackFor(wallet);\n const sec = document.createElement(\"div\");\n sec.className = \"pr-sec\";\n sec.innerHTML = self ? \"FORM // POST TO BLOG\" : \"FORM // WRITE A COMMENT\";\n paneCommunity.appendChild(sec);\n const compose = document.createElement(\"div\");\n compose.className = \"pr-compose\";\n let titleInput = null;\n if (self) {\n titleInput = document.createElement(\"input\");\n titleInput.type = \"text\";\n titleInput.placeholder = \"Title (optional)\";\n }\n const ta = document.createElement(\"textarea\");\n ta.placeholder = self ? \"Write a blog post or update…\" : \"Share your experience with this agent…\";\n const imgInput = document.createElement(\"input\");\n imgInput.type = \"text\";\n imgInput.placeholder = \"Image link / on-chain address / tx id (optional)\";\n const gitInput = document.createElement(\"input\");\n gitInput.type = \"text\";\n gitInput.placeholder = \"GitHub / git URL (optional)\";\n const errEl = document.createElement(\"div\");\n errEl.className = \"pr-err\";\n if (feedback) {\n errEl.textContent = feedback.text;\n errEl.style.display = \"\";\n if (feedback.ok) errEl.classList.add(\"ok\");\n }\n const btn = document.createElement(\"button\");\n btn.textContent = self ? \"Post\" : \"Comment\";\n if (!canPost) {\n ta.disabled = true;\n gitInput.disabled = true;\n imgInput.disabled = true;\n btn.disabled = true;\n if (titleInput) titleInput.disabled = true;\n const hint = document.createElement(\"div\");\n hint.className = \"pr-hint\";\n hint.textContent = \"Own ≥1 of this agent’s skills to comment.\";\n compose.appendChild(hint);\n }\n btn.addEventListener(\"click\", () => {\n const text = ta.value.trim();\n if (!text) return;\n const gitLink = gitInput.value.trim() || void 0;\n const image = imgInput.value.trim() || void 0;\n const title = titleInput ? titleInput.value.trim() || void 0 : void 0;\n S.postFeedback = null;\n btn.disabled = true;\n btn.textContent = self ? \"Posting…\" : \"Commenting…\";\n errEl.style.display = \"none\";\n errEl.classList.remove(\"ok\");\n S.pendingPost = { wallet, text, gitLink, self };\n const out = { type: \"postAgentNote\", agentWallet: wallet, text, gitLink };\n if (image) out.image = image;\n if (title) out.title = title;\n vscode.postMessage(out);\n });\n if (titleInput) compose.appendChild(titleInput);\n compose.appendChild(ta);\n compose.appendChild(imgInput);\n compose.appendChild(gitInput);\n compose.appendChild(errEl);\n compose.appendChild(btn);\n paneCommunity.appendChild(compose);\n body._postBtn = btn;\n body._postErr = errEl;\n body._postLabel = self ? \"Post\" : \"Comment\";\n body._postTa = ta;\n body._postGit = gitInput;\n body._postImg = imgInput;\n body._postTitle = titleInput;\n }\n const canReply = self || !!profile.canComment;\n function attachReply(cardEl, parentId) {\n if (!canReply) return;\n const bar = document.createElement(\"div\");\n bar.className = \"pr-replybar\";\n const toggle = document.createElement(\"button\");\n toggle.className = \"pr-replybtn\";\n toggle.textContent = \"Reply\";\n bar.appendChild(toggle);\n cardEl.appendChild(bar);\n let box = null;\n toggle.addEventListener(\"click\", () => {\n if (box) {\n box.remove();\n box = null;\n toggle.textContent = \"Reply\";\n return;\n }\n toggle.textContent = \"Cancel\";\n box = document.createElement(\"div\");\n box.className = \"pr-compose pr-replycompose\";\n const ta = document.createElement(\"textarea\");\n ta.placeholder = \"Write a reply…\";\n const err = document.createElement(\"div\");\n err.className = \"pr-err\";\n const send2 = document.createElement(\"button\");\n send2.textContent = \"Reply\";\n send2.addEventListener(\"click\", () => {\n const text = ta.value.trim();\n if (!text) return;\n send2.disabled = true;\n send2.textContent = \"Replying…\";\n err.style.display = \"none\";\n S.pendingPost = { wallet, text, parentId, self };\n vscode.postMessage({ type: \"postAgentNote\", agentWallet: wallet, text, parentId });\n });\n box.appendChild(ta);\n box.appendChild(err);\n box.appendChild(send2);\n cardEl.appendChild(box);\n ta.focus();\n });\n }\n const commentThreads = allThreads.filter((t) => !t.note.isSelfNote);\n const commentCount = commentThreads.reduce((s, t) => s + 1 + (t.replies ? t.replies.length : 0), 0);\n if (commentThreads.length) {\n const sec = document.createElement(\"div\");\n sec.className = \"pr-sec\";\n sec.textContent = \"Comments (\" + commentCount + \")\";\n paneCommunity.appendChild(sec);\n commentThreads.forEach((t) => {\n const opCard = noteCard(t.note, true);\n attachReply(opCard, t.note.id);\n paneCommunity.appendChild(opCard);\n (t.replies || []).forEach((rep) => {\n const rc = noteCard(rep, true);\n rc.classList.add(\"pr-reply\");\n if (rep.parentAuthor) {\n const to = document.createElement(\"div\");\n to.className = \"pr-replyto\";\n to.textContent = \"↳ replying to \" + agShort(rep.parentAuthor);\n rc.insertBefore(to, rc.firstChild);\n }\n attachReply(rc, rep.id);\n paneCommunity.appendChild(rc);\n });\n });\n } else {\n const e = document.createElement(\"div\");\n e.className = \"pr-empty\";\n e.textContent = self ? \"No comments yet.\" : \"No comments yet. Be the first.\";\n paneCommunity.appendChild(e);\n }\n selectTab2(S.profileTab);\n }\n function showBuyAllConfirm(profile) {\n const notOwned = profile.createdSkills.filter((c) => S.ownedSkills.indexOf(c.name) < 0);\n if (!notOwned.length) return;\n const totalLamports = notOwned.reduce((acc, c) => acc + (c.price ? BigInt(c.price) : 0n), 0n);\n const totalSol = totalLamports > 0n ? (Number(totalLamports) / 1e9).toFixed(4) + \" SOL\" : \"free\";\n const body = document.getElementById(\"profileBody\");\n const existing = body.querySelector(\".pr-confirm\");\n if (existing) {\n existing.remove();\n return;\n }\n const confirm = document.createElement(\"div\");\n confirm.className = \"pr-confirm\";\n const h = document.createElement(\"div\");\n h.style.fontWeight = \"600\";\n h.textContent = \"Buy \" + notOwned.length + \" skill\" + (notOwned.length !== 1 ? \"s\" : \"\") + \" (\" + totalSol + \")\";\n const ul = document.createElement(\"ul\");\n notOwned.forEach((c) => {\n const li = document.createElement(\"li\");\n li.textContent = c.name || c.id;\n ul.appendChild(li);\n });\n const btns = document.createElement(\"div\");\n btns.className = \"confirm-btns\";\n const ok = document.createElement(\"button\");\n ok.className = \"pr-buyall\";\n ok.style.justifyContent = \"center\";\n ok.textContent = \"Confirm\";\n const cancel = document.createElement(\"button\");\n cancel.textContent = \"Cancel\";\n ok.addEventListener(\"click\", () => {\n ok.disabled = true;\n cancel.disabled = true;\n ok.textContent = \"Buying…\";\n vscode.postMessage({ type: \"buyAllSkills\", wallet: profile.wallet });\n });\n cancel.addEventListener(\"click\", () => confirm.remove());\n btns.appendChild(ok);\n btns.appendChild(cancel);\n confirm.appendChild(h);\n confirm.appendChild(ul);\n confirm.appendChild(btns);\n const buyAllBtn = body.querySelector(\".pr-buyall\");\n if (buyAllBtn && buyAllBtn.parentNode) buyAllBtn.parentNode.insertBefore(confirm, buyAllBtn.nextSibling);\n else body.appendChild(confirm);\n }\n\n // src/chat/ui/panel/wallet.ts\n function setWallet(address) {\n S.myWalletAddress = address || null;\n updateFdFab();\n const full = address || \"(not connected)\";\n document.getElementById(\"wAddr\").textContent = address ? short(address) : \"not connected\";\n const label = address ? short(address) : \"My Wallet\";\n document.getElementById(\"wName\").textContent = label;\n document.getElementById(\"wName2\").textContent = address ? \"My Wallet\" : \"My Wallet\";\n const svg = address ? avatarSvg(address) : \"\";\n document.getElementById(\"wAvatar\").innerHTML = svg;\n document.getElementById(\"wAvatar2\").innerHTML = svg;\n if (S.currentProfileWallet === null || S.currentProfileWallet === address) {\n document.getElementById(\"walletAddr\").textContent = full;\n document.getElementById(\"wAvatarBig\").innerHTML = svg;\n }\n }\n function renderCloudSync(status) {\n const el = document.getElementById(\"cloudSync\");\n if (!el) return;\n el.onclick = null;\n el.style.cursor = \"\";\n if (!status || !S.cloudConnected) {\n el.textContent = \"\";\n el.className = \"\";\n el.title = \"\";\n return;\n }\n if (status.ok) {\n el.textContent = \"✓\";\n el.className = \"ok\";\n el.title = \"Synced to Drive\";\n } else if (status.reason === \"reauth\") {\n el.textContent = \"⚠ reconnect\";\n el.className = \"err\";\n el.title = \"Cloud sign-in expired. Click to reconnect \" + (S.cloudKind === \"gdrive\" ? \"Google Drive\" : \"cloud\") + \".\";\n el.style.cursor = \"pointer\";\n el.onclick = () => vscode.postMessage({ type: \"reconnectCloud\", kind: S.cloudKind || \"gdrive\" });\n } else {\n el.textContent = \"⚠\";\n el.className = \"err\";\n el.title = \"Drive sync failed (auto-retrying): \" + (status.error || \"unknown\");\n }\n }\n function renderWalletStorage() {\n const el = document.getElementById(\"walletStorage\");\n if (!el) return;\n el.textContent = S.cloudConnected ? \"Local + cloud mirror (connected)\" : \"Local only (no cloud)\";\n }\n function wireWallet() {\n document.getElementById(\"disconnectWalletBtn\").addEventListener(\"click\", () => {\n vscode.postMessage({ type: \"disconnectWallet\" });\n });\n document.getElementById(\"walletDisconnect\").addEventListener(\"click\", () => {\n vscode.postMessage({ type: \"disconnectWallet\" });\n });\n }\n\n // src/chat/ui/panel/paging.ts\n function resetPaging() {\n S.pageCursor = null;\n S.hasMore = false;\n S.loadingOlder = false;\n S.lastOlderCursor = null;\n }\n function prependOlder(messages) {\n const before = log.scrollHeight;\n const realLog = log;\n const frag = document.createElement(\"div\");\n let body = null;\n const openTurn = (userText, badge, imageCount) => {\n const turn = document.createElement(\"div\");\n turn.className = \"turn\";\n const head = document.createElement(\"div\");\n head.className = \"turnHead\";\n head.innerHTML = '>';\n head.appendChild(makeUtext(userText));\n if (badge) {\n const b2 = document.createElement(\"span\");\n b2.className = \"badge \" + engineMark(badge);\n b2.textContent = ENGINE_BADGE[engineMark(badge)];\n head.appendChild(b2);\n }\n const imgEl = userImagesEl(imageCount ? { count: imageCount } : void 0);\n if (imgEl) head.appendChild(imgEl);\n const b = document.createElement(\"div\");\n b.className = \"turnBody\";\n turn.appendChild(head);\n turn.appendChild(b);\n frag.appendChild(turn);\n return b;\n };\n const node = (cls) => {\n const n = document.createElement(\"div\");\n n.className = \"node \" + cls;\n (body || (body = openTurn(\"\", void 0))).appendChild(n);\n return n;\n };\n for (const m of messages) {\n if (m.role === \"user\") {\n body = openTurn(m.text, void 0, m.imageCount);\n continue;\n }\n if (m.role === \"tool\") {\n renderToolInto(node(\"tool\"), m);\n continue;\n }\n if (m.role === \"summary\") {\n const n2 = node(\"summary\");\n n2.innerHTML = '
⌘ context compacted
';\n const sb = document.createElement(\"div\");\n sb.className = \"summaryBody\";\n sb.textContent = m.text;\n n2.appendChild(sb);\n continue;\n }\n const n = node(m.role + (m.role === \"assistant\" && m.cli ? \" \" + engineMark(m.cli) : \"\"));\n const el = document.createElement(\"div\");\n el.className = \"msg \" + m.role;\n if (m.role === \"assistant\") renderMd(el, m.text);\n else {\n el.textContent = m.text;\n el.dataset.md = m.text;\n }\n n.appendChild(el);\n if (m.role === \"assistant\") {\n addFooter(n, m.durationMs, m.model);\n addMsgCopy(n, el);\n }\n }\n const prevBehavior = realLog.style.scrollBehavior;\n realLog.style.scrollBehavior = \"auto\";\n realLog.insertBefore(frag, realLog.firstChild);\n void realLog.offsetHeight;\n realLog.scrollTop += realLog.scrollHeight - before;\n realLog.style.scrollBehavior = prevBehavior;\n }\n function requestOlder() {\n if (S.hasMore && !S.loadingOlder && S.pageCursor !== null && S.pageCursor !== S.lastOlderCursor) {\n S.loadingOlder = true;\n S.lastOlderCursor = S.pageCursor;\n vscode.postMessage({ type: \"loadMore\", cursor: S.pageCursor });\n }\n }\n function maybeFillOlder() {\n if (log.scrollHeight <= log.clientHeight) requestOlder();\n }\n function wirePaging() {\n log.addEventListener(\"scroll\", () => {\n if (log.scrollTop < 600) requestOlder();\n S.stick = nearBottom();\n updateJump();\n });\n }\n\n // src/chat/ui/panel/main.ts\n wireShell();\n wireSlash();\n wireEngine();\n wireSessions();\n wireComposer();\n wireStorage();\n wireViews();\n wirePublish();\n wireFeed();\n wireMenus();\n wireSkills();\n wireMarket();\n wireOverlays();\n wireWallet();\n wirePaging();\n window.addEventListener(\"message\", (event) => {\n const m = event.data;\n if (m.type === \"message\") onMessage(m.msg);\n else if (m.type === \"sessions\") {\n S.allSessions = m.list || [];\n S.cloudListState = m.cloud || \"none\";\n S.activeId = m.activeId;\n renderSessions();\n } else if (m.type === \"notice\") renderNotice(m.text || \"\");\n else if (m.type === \"status\") renderStatus(m.status || {});\n else if (m.type === \"loading\") showLoading();\n else if (m.type === \"clear\") {\n log.innerHTML = \"\";\n approvalDock.innerHTML = \"\";\n clearCtx();\n syncComposerLock();\n S.streaming = null;\n S.openBash = null;\n S.tailTurn = null;\n S.headTurn = null;\n hideTyping();\n hideActivity();\n resetPaging();\n syncWatermark();\n hideLoading();\n } else if (m.type === \"turnEnd\") {\n hideTyping();\n hideActivity();\n } else if (m.type === \"modelOptions\") {\n if (m.cli === \"custom\") showCustomTab();\n applyModelOptions(m.cli, m.options);\n } else if (m.type === \"usage\") {\n setCtxTokens(m.contextTokens);\n } else if (m.type === \"rateLimit\") {\n renderLimitMeter({ cli: m.cli, utilization: m.utilization, window: m.window, resetsAt: m.resetsAt, status: m.status });\n } else if (m.type === \"skillActive\" && m.origin === \"nft\" && m.mint) flashSkill(m.name, m.mint);\n else if (m.type === \"rpcStatus\") renderRpcStatus(m.status);\n else if (m.type === \"skillShopping\") setShopToggle(m.on);\n else if (m.type === \"searchResults\") {\n S.lastMarketResults = m.results || [];\n renderMarketResults(m.results);\n } else if (m.type === \"searchError\") {\n const msg = \"Search failed: \" + escapeHtml(m.message || \"unknown\");\n mktResults.innerHTML = '
' + msg + \"
\";\n if (S.currentProfileWallet) {\n document.getElementById(\"agentIdCard\").innerHTML = '
Could not load profile.
';\n document.getElementById(\"profileBody\").innerHTML = '
' + msg + \"
\";\n }\n } else if (m.type === \"skillDetail\") {\n if (S.skillModalOpen) renderSkillModal(m.detail);\n else renderDetail(m.detail);\n } else if (m.type === \"skillDoc\") {\n if (S.skillDocOpen) renderSkillDoc(m.name, m.text);\n } else if (m.type === \"postNoteResult\") {\n const submit = mktDetailBody.querySelector(\".dt-note-submit\");\n if (submit) {\n m.ok ? submit._reset && submit._reset() : submit._fail && submit._fail(m.error || \"Post failed\");\n }\n } else if (m.type === \"notes\" && S.currentDetail && m.skillId === S.currentDetail.id) {\n const owned = ownsMint(S.currentDetail.id) || S.ownedSkills.indexOf(S.currentDetailName) >= 0;\n renderComments(S.currentDetail.id, S.currentDetail.type, m.notes, owned);\n } else if (m.type === \"ownedSkills\") {\n S.disposedMints = m.disposedMints || {};\n S.disposedMintSet = new Set(Object.values(S.disposedMints));\n S.workflowMintSet = new Set(m.workflowMints || []);\n setSkills(m.names || [], m.mints || {}, m.meta || {});\n if (panels.market.style.display !== \"none\") renderMarketResults(S.lastMarketResults);\n refreshDetailOwned();\n refreshModalOwned();\n } else if (m.type === \"buyResult\") {\n if (m.ok) {\n showComplete(S.currentDetail && S.currentDetail.type === \"workflow\" ? \"WORKFLOW PURCHASED\" : \"SKILL PURCHASED\");\n vscode.postMessage({ type: \"getBalance\" });\n } else {\n showBuyError(m.error, m.code === \"insufficient_funds\" && S.rpcNetwork !== \"mainnet\");\n if (S.detailBuyBtn) {\n S.detailBuyBtn.disabled = false;\n S.detailBuyBtn.textContent = \"Buy\";\n }\n if (S.skillModalBuyBtn) {\n S.skillModalBuyBtn.disabled = false;\n S.skillModalBuyBtn.textContent = \"Buy\";\n }\n renderMarketResults(S.lastMarketResults);\n }\n } else if (m.type === \"airdropResult\") {\n if (m.ok) {\n renderNotice(\"Funded. Try the purchase again.\");\n vscode.postMessage({ type: \"getBalance\" });\n hideBuyError();\n } else {\n renderNotice(\"Get SOL failed: \" + (m.error || \"unknown\"));\n const fb = buyErrEl.querySelector(\".buyErrFund\");\n if (fb) {\n fb.disabled = false;\n fb.textContent = \"Get devnet SOL\";\n }\n }\n } else if (m.type === \"githubStatus\") {\n renderRepoModalBody(m);\n } else if (m.type === \"workRepoRegistered\") {\n if (m.ok) {\n showComplete(\"GITHUB REGISTERED\");\n closeRepoRegister();\n if (S.currentProfileWallet) vscode.postMessage({ type: \"getAgentProfile\", wallet: S.currentProfileWallet });\n } else if (S.repoModalEl) {\n const b = S.repoModalEl.querySelector(\".rr-body\");\n const err = b && b.querySelector(\".rr-err\");\n const btn = b && b.querySelector(\".rr-btn\");\n if (err) {\n err.textContent = m.error || \"Registration failed.\";\n err.style.display = \"\";\n }\n if (btn) {\n btn.disabled = false;\n btn.textContent = \"Register repo\";\n }\n }\n } else if (m.type === \"disposeResult\") {\n if (m.ok) {\n if (S.currentDetail) openDetail(S.currentDetail.id);\n } else {\n showBuyError(m.error || \"Unequip failed\");\n const rm = mktDetailBody.querySelector(\".dt-remove\");\n if (rm) {\n rm.disabled = false;\n rm.textContent = \"Unequip\";\n }\n }\n } else if (m.type === \"reEquipResult\") {\n if (m.ok) {\n if (S.currentDetail) openDetail(S.currentDetail.id);\n } else {\n showBuyError(m.error || \"Re-equip failed\");\n if (S.detailBuyBtn) {\n S.detailBuyBtn.disabled = false;\n S.detailBuyBtn.textContent = \"Re-equip\";\n }\n }\n } else if (m.type === \"agents\") renderAgents(m.agents);\n else if (m.type === \"agentProfile\") renderProfile(m.profile);\n else if (m.type === \"blogFeed\") renderFeed(m.posts);\n else if (m.type === \"blogPost\") {\n const wasQuote = !!quoteInflight[m.postId];\n if (wasQuote) {\n delete quoteInflight[m.postId];\n if (m.post) quoteCache[m.postId] = { post: m.post };\n }\n if (m.post) {\n feedBodies[m.postId] = m.post;\n if (S.currentFeedPost && S.currentFeedPost.id === m.postId) renderFeedPost();\n }\n if (wasQuote) {\n const els = S.quoteCards[m.postId] || [];\n delete S.quoteCards[m.postId];\n els.forEach((el) => fillQuoteCard(el, m.postId, m.post || null));\n }\n } else if (m.type === \"blogComments\") {\n feedThreads[m.postId] = m.threads || [];\n if (S.currentFeedPost && S.currentFeedPost.id === m.postId) renderFeedPost();\n } else if (m.type === \"blogCommentResult\") {\n const pane = document.getElementById(\"agFeedPost\");\n if (pane && S.currentFeedPost && S.currentFeedPost.id === m.postId) {\n if (m.ok) {\n if (pane._mainCompose) {\n pane._mainCompose._ta.value = \"\";\n pane._mainCompose._git.value = \"\";\n pane._mainCompose._btn.disabled = false;\n pane._mainCompose._btn.textContent = pane._mainCompose._label;\n }\n S.feedReplyTo = null;\n vscode.postMessage({ type: \"getBlogFeed\", sort: S.feedSort, fresh: !S.feedLastSage });\n } else {\n const box = pane._activeCompose || pane._mainCompose;\n if (box) {\n box._btn.disabled = false;\n box._btn.textContent = box._label;\n box._err.textContent = m.error || \"Comment failed\";\n box._err.style.display = \"\";\n }\n }\n }\n } else if (m.type === \"buyAllResult\") {\n const confirm = document.getElementById(\"profileBody\") && document.getElementById(\"profileBody\").querySelector(\".pr-confirm\");\n if (confirm) confirm.remove();\n if (m.bought > 0) {\n showComplete(m.bought === 1 ? \"SKILL PURCHASED\" : m.bought + \" SKILLS PURCHASED\");\n vscode.postMessage({ type: \"getBalance\" });\n if (m.failed > 0) showBuyError(m.failed + \" of \" + (m.bought + m.failed) + \" purchase(s) failed\");\n } else if (!m.ok || m.failed > 0) {\n showBuyError(m.error || (m.failed > 0 ? m.failed + \" purchase(s) failed\" : \"Purchase failed\"));\n }\n if (m.ok && S.currentProfileWallet) {\n vscode.postMessage({ type: \"getAgentProfile\", wallet: S.currentProfileWallet });\n vscode.postMessage({ type: \"ownedSkills\" });\n }\n } else if (m.type === \"agentNoteResult\") {\n const body = document.getElementById(\"profileBody\");\n const label = body && body._postLabel || \"Post\";\n if (!m.ok) {\n S.pendingPost = null;\n S.postFeedback = { wallet: m.agentWallet, text: m.error || \"Post failed\", ok: false, ts: Date.now() };\n if (body && body._postBtn) {\n body._postBtn.disabled = false;\n body._postBtn.textContent = label;\n if (body._postErr) {\n body._postErr.textContent = m.error || \"Post failed\";\n body._postErr.style.display = \"\";\n body._postErr.classList.remove(\"ok\");\n }\n }\n if (S.fabModalEl) {\n S.fabModalEl._btn.disabled = false;\n S.fabModalEl._btn.textContent = \"Post to AgentNet\";\n S.fabModalEl._err.textContent = m.error || \"Post failed\";\n S.fabModalEl._err.style.display = \"\";\n }\n } else {\n if (S.fabModalEl) {\n closeFabCompose();\n S.feedPosts = null;\n document.getElementById(\"feedList\").innerHTML = skFd(4);\n vscode.postMessage({ type: \"getBlogFeed\", sort: S.feedSort, fresh: true });\n }\n if (S.pendingPost) {\n S.recentlyPosted.push({\n wallet: S.pendingPost.wallet,\n ts: Date.now(),\n // author must be OUR wallet (the writer), not the profile owner's\n // (pendingPost.wallet): mergeOptimistic dedupes the ghost against the real\n // on-chain note by author+text, and the real note's author is the writer:\n // a profile-owner author only matches on self-posts, so comments on OTHER\n // agents rendered twice once the chain read caught up.\n note: { author: S.myWalletAddress || S.pendingPost.wallet, text: S.pendingPost.text, gitLink: S.pendingPost.gitLink, isSelfNote: S.pendingPost.self, parentId: S.pendingPost.parentId, timestamp: Date.now() }\n });\n S.pendingPost = null;\n }\n S.postFeedback = {\n wallet: m.agentWallet,\n text: label === \"Post\" ? \"Posted to blog.\" : \"Comment posted.\",\n ok: true,\n ts: Date.now()\n };\n showComplete(label === \"Post\" ? \"POST PUBLISHED\" : \"COMMENT POSTED\");\n if (body && body._postBtn) {\n body._postBtn.disabled = false;\n body._postBtn.textContent = label;\n if (body._postTa) body._postTa.value = \"\";\n if (body._postGit) body._postGit.value = \"\";\n if (body._postImg) body._postImg.value = \"\";\n if (body._postTitle) body._postTitle.value = \"\";\n if (body._postErr) {\n body._postErr.textContent = label === \"Post\" ? \"Posted to blog.\" : \"Comment posted.\";\n body._postErr.style.display = \"\";\n body._postErr.classList.add(\"ok\");\n }\n }\n }\n } else if (m.type === \"balance\") {\n S.solLamports = m.lamports;\n renderBalance();\n } else if (m.type === \"publishProgress\") {\n const phaseLabel = m.phase === \"store\" ? \"Storing on-chain\" : m.phase === \"mint\" ? \"Minting the NFT\" : \"Listing for sale\";\n pubSubmit.textContent = \"Publishing… \" + (m.total ? m.signed + \"/\" + m.total + \" signed · \" : \"\") + phaseLabel;\n } else if (m.type === \"publishResult\") {\n pubSubmit.disabled = false;\n pubSubmit.textContent = S.pubKind === \"workflow\" ? \"Publish workflow\" : \"Publish skill\";\n if (m.ok) {\n const nm = document.getElementById(\"pubName\").value.trim();\n [\"pubName\", \"pubDesc\", \"pubCategory\", \"pubHashtags\", \"pubImage\", \"pubText\"].forEach((id) => {\n document.getElementById(id).value = \"\";\n });\n document.getElementById(\"pubPrice\").value = \"0.1\";\n pubImageBadge.style.display = \"none\";\n for (const k in pubReqSel) delete pubReqSel[k];\n const wasWorkflow = S.pubKind === \"workflow\";\n setPubKind(\"skill\");\n showComplete(wasWorkflow ? \"WORKFLOW BUILT\" : \"SKILL CREATED\");\n showView(\"market\");\n } else {\n pubError.textContent = m.error || \"Publish failed.\";\n pubError.style.display = \"block\";\n }\n } else if (m.type === \"platform\") setTab(m.cli);\n else if (m.type === \"customEngine\") {\n if (m.masked != null) showCustomTab();\n else hideCustomTab();\n } else if (m.type === \"cliStatus\") {\n const previousStatus = S.cliReport?.[messageBinary(S.cli)];\n S.cliReport = { claude: m.claude, codex: m.codex };\n const status = S.cliReport[messageBinary(S.cli)];\n if (status === \"no-login\" && S.cli !== \"custom\") renderNotice((S.cli === \"claude\" ? \"Claude\" : \"Codex\") + \" is not signed in. Type /login to connect it.\");\n else if (status === \"missing\" || status === \"node-missing\") renderEngineMissing(S.cli);\n else if (status === \"ok\" && previousStatus === \"node-missing\") renderNotice((S.cli === \"claude\" ? \"Claude\" : \"Codex\") + \" is ready.\");\n } else if (m.type === \"engineUpdate\" && m.cli === \"codex\") {\n renderEngineBanner(\n \"Codex is out of date, so new models are hidden. Update it, then reload this window.\",\n [\n [\"Update in terminal\", () => vscode.postMessage({ type: \"installEngine\", cli: \"codex\", update: true })],\n copyAction(CODEX_UPDATE_CMD)\n ],\n \"codex\"\n );\n } else if (m.type === \"claudeLoginUrl\") {\n renderNotice(\"Claude sign-in opened. If the browser did not open, visit:\\n\" + m.url + \"\\nAfter approving, paste the returned code with /login .\");\n } else if (m.type === \"claudeLoginStatus\") {\n if (m.status === \"done\") {\n S.cliReport = Object.assign({}, S.cliReport || {}, { claude: \"ok\" });\n renderNotice(\"Claude sign-in complete.\");\n if (S.cli === \"claude\") vscode.postMessage({ type: \"platform\", cli: \"claude\" });\n } else {\n renderNotice(\"Claude sign-in failed: \" + (m.error || \"Login was not completed.\"));\n }\n } else if (m.type === \"codexLoginChallenge\") {\n renderNotice(\"Codex sign-in opened. If the browser did not open, visit:\\n\" + m.url + \"\\nEnter this one-time code on the page: \" + m.code);\n } else if (m.type === \"codexLoginStatus\") {\n if (m.status === \"done\") {\n S.cliReport = Object.assign({}, S.cliReport || {}, { codex: \"ok\" });\n renderNotice(\"Codex sign-in complete.\");\n if (S.cli === \"codex\") vscode.postMessage({ type: \"platform\", cli: \"codex\" });\n } else {\n renderNotice(\"Codex sign-in failed: \" + (m.error || \"Login was not completed.\"));\n }\n } else if (m.type === \"toast\") renderNotice(m.text || \"\");\n else if (m.type === \"openUrl\" && m.url) window.open(m.url, \"_blank\", \"noopener,noreferrer\");\n else if (m.type === \"storage\") {\n renderStorage(m.info, m.options);\n renderWalletStorage();\n } else if (m.type === \"cloudSync\") renderCloudSync(m.status);\n else if (m.type === \"wallet\") setWallet(m.address);\n else if (m.type === \"page\") {\n hideLoading();\n S.hasMore = m.hasMore;\n S.pageCursor = m.cursor;\n maybeFillOlder();\n } else if (m.type === \"older\") {\n prependOlder(m.messages || []);\n S.hasMore = m.hasMore;\n S.pageCursor = m.cursor;\n S.loadingOlder = false;\n maybeFillOlder();\n } else if (m.type === \"approval\") renderApproval(m.req);\n else if (m.type === \"approvalDismiss\") dismissApproval(m.id);\n });\n vscode.postMessage({ type: \"ready\" });\n vscode.postMessage({ type: \"wallet\" });\n vscode.postMessage({ type: \"getBalance\" });\n})();\n"; diff --git a/surfaces/cli/src/views/Chat.tsx b/surfaces/cli/src/views/Chat.tsx index 980561bd..29e422f9 100644 --- a/surfaces/cli/src/views/Chat.tsx +++ b/surfaces/cli/src/views/Chat.tsx @@ -38,8 +38,6 @@ import { hasCustomEngine, maskedCustomEngine, type EngineKey, - NODE_REQUIRED_MESSAGE, - NODE_DOWNLOAD_URL, } from "@iqlabs-official/agent-sdk"; import { Select, TextInput } from "@inkjs/ui"; import open from "open"; diff --git a/surfaces/cli/src/views/LoginGate.tsx b/surfaces/cli/src/views/LoginGate.tsx index 5384eefb..19f8b451 100644 --- a/surfaces/cli/src/views/LoginGate.tsx +++ b/surfaces/cli/src/views/LoginGate.tsx @@ -22,8 +22,6 @@ import { maskedCustomEngine, type CustomEnginePreset, type EngineKey, - NODE_REQUIRED_MESSAGE, - NODE_DOWNLOAD_URL, type CliReport, type CliStatus, type ClaudeLogin,