From 901b40f6ede19aa5ccfa6a1dab40e3cc6b73c88a Mon Sep 17 00:00:00 2001 From: Sarav Date: Mon, 16 Nov 2026 08:10:52 +0530 Subject: [PATCH] fix: workspace review decision toasts survive "Sync now"; publish refusals carry a code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - TUI: the TUI shows one toast at a time, and "Sync now" ended with its "Synced: …" summary, which replaced a skill or knowledge decision the sync had just announced. The decision was recorded as shown, so the person never saw "approved" or "rejected — reason". Decisions now go through one toaster per TUI: those arriving together are shown as one toast (five named, the rest counted), and "Sync now" skips its summary when a decision was shown, or is about to be, since it started. Problems (sync skipped, proposals kept queued) are still said. - `skill publish --json`: a refusal this command explains now carries its stable `code` (`review_disabled`, `too_many_requests`, …) next to `error`. - Docs: the `code` field. Found in an end-to-end run of workspace review against a local backend. Co-Authored-By: Claude Opus 5.5 --- docs/docs/configure/skills.md | 2 +- packages/opencode/src/cli/cmd/skill.ts | 19 ++- .../src/plugin/tui/altimate/rules.tsx | 119 ++++++++++++++++-- .../test/cli/tui/rules-requests.test.ts | 57 ++++++++- 4 files changed, 176 insertions(+), 21 deletions(-) diff --git a/docs/docs/configure/skills.md b/docs/docs/configure/skills.md index c79b11322a..b0ea413c35 100644 --- a/docs/docs/configure/skills.md +++ b/docs/docs/configure/skills.md @@ -207,7 +207,7 @@ altimate-code workspace review status # changes nothing on the server; --j - `Sent "" for review to `: you are a member of a workspace whose owner turned review on. The team gets the skill once the owner or an admin approves it in the Altimate web app; until then only you get your pending version. Approving and rejecting happen only in the web app. - `Already waiting for review` or `Already approved`: the same content was already submitted or approved, so nothing new was sent. -Requests sent from the CLI are recorded as such in the request's history. What the team gets is the exact version that was approved: editing the skill afterwards changes nothing for them until you run `skill publish` again, which submits the new version as an update. A member publishing to a workspace whose owner has review off is refused before anything is uploaded. If the skill uploads but cannot be sent (offline, an expired sign-in, too many open requests), the command says so and exits non-zero; running it again updates the uploaded skill and submits it. Against a workspace service without review, `skill publish` attaches the skill directly as before, which only the workspace owner can do. With `--json`, the output carries `ok`, the upload (`action`, `public_id`, `files`, `bytes`, `workspace_id`, `workspace_name`) and `review` with the service's `status`, `attached_directly`, `duplicate`, `owner_name` and `contribution` (`null` without review); every failure exits non-zero with `{"ok": false, "error": ...}`. +Requests sent from the CLI are recorded as such in the request's history. What the team gets is the exact version that was approved: editing the skill afterwards changes nothing for them until you run `skill publish` again, which submits the new version as an update. A member publishing to a workspace whose owner has review off is refused before anything is uploaded. If the skill uploads but cannot be sent (offline, an expired sign-in, too many open requests), the command says so and exits non-zero; running it again updates the uploaded skill and submits it. Against a workspace service without review, `skill publish` attaches the skill directly as before, which only the workspace owner can do. With `--json`, the output carries `ok`, the upload (`action`, `public_id`, `files`, `bytes`, `workspace_id`, `workspace_name`) and `review` with the service's `status`, `attached_directly`, `duplicate`, `owner_name` and `contribution` (`null` without review); every failure exits non-zero with `{"ok": false, "error": ...}`, plus a stable `code` when the command refused for a known reason (for example `review_disabled`, `too_many_requests`, `not_workspace_owner`, `bundle_too_large`). When the owner or an admin approves or rejects one of your requests that this client has seen pending (submitted from it, or listed by an earlier check), or one it has not seen that is decided after it began checking (sent from the web app or another machine), the TUI shows a notice once in each project linked to that workspace (with the reason for a rejection). Each altimate-code process with a linked project open checks at start and every 5 minutes (a server without review is asked again only after 6 hours) and keeps the 50 most recent decisions in your own state directory, so a decision that arrives while the TUI is closed or disconnected is shown when it next starts (as rule review notices are). The first time a TUI opens a project, decisions already kept are recorded without a notice; `workspace review status` lists them. `altimate-code workspace review status` lists your requests on the linked workspace (skills and knowledge bases): kind, name, status, whether it is new or an update, the reviewer and their reason, and `expired` for a request waiting longer than 14 days (it can still be approved). In the web app, or from `/rules` in the TUI (which lists your skill and knowledge requests under your rule proposals), you can withdraw a request that is still waiting and remove an approved skill or knowledge base of yours from the workspace; in the web app the owner or an admin can remove it too, with a reason. The VS Code extension does the same through `altimate-code serve` (`GET /altimate/workspace/requests`, `POST /altimate/workspace/requests/{id}/withdraw|remove`), and Claude Code and Codex sessions are told of decisions, and of your requests still waiting, when they start, whether or not team rules apply in the project. Each client (the TUI, the extension, Claude Code's and Codex's session start, Claude Code's toast) shows a decision once per account and workspace; the first time a client asks, decisions already kept are recorded as shown without a notice. `altimate-code workspace review decisions --json` answers them for plugins: newest first: `--unseen --host ` only those not given to that client yet, `--mark-seen` remembers them as given, `--claim` holds them for 5 minutes until `--ack …` says they were shown. `--unseen`, `--mark-seen`, `--claim` and `--ack` need `--host` (else `{"ok": false, "status": "host_required"}`). The command always prints one JSON object and exits 0, so a plugin can tell an older CLI from an answer. When the owner or an admin removes one of yours that this client has seen approved (or waiting; up to the 200 approved ones it tracks per workspace), the TUI shows that once too, with the reason; your own removal and withdrawal show nothing. `workspace review status` lists them as `withdrawn` and `removed from the workspace`. diff --git a/packages/opencode/src/cli/cmd/skill.ts b/packages/opencode/src/cli/cmd/skill.ts index 78869d40f1..c1f25a6219 100644 --- a/packages/opencode/src/cli/cmd/skill.ts +++ b/packages/opencode/src/cli/cmd/skill.ts @@ -12,7 +12,13 @@ import { Global } from "@/global" import { detectToolReferences, skillSource, isToolOnPath } from "./skill-helpers" // altimate_change start — telemetry for skill operations import { Telemetry } from "@/altimate/telemetry" -import { describePublish, explainPublishError, publishSkill, type PublishReport } from "@/altimate/workspace/skill-publish" +import { + describePublish, + explainPublishError, + publishErrorCode, + publishSkill, + type PublishReport, +} from "@/altimate/workspace/skill-publish" import { Flag } from "@opencode-ai/core/flag/flag" import { printable } from "@/altimate/rules/printable" // altimate_change end @@ -490,8 +496,9 @@ const SkillPublishCommand = cmd({ // altimate_change start — workspace review: every outcome goes through one writer, JSON or text, and every failure // exits non-zero const json = args.json === true - const fail = (message: string) => { - if (json) process.stdout.write(JSON.stringify({ ok: false, error: message }, null, 2) + EOL) + // `code`: the stable reason for a refusal this command explains (`review_disabled`, `too_many_requests`, …). + const fail = (message: string, code?: string) => { + if (json) process.stdout.write(JSON.stringify({ ok: false, error: message, ...(code ? { code } : {}) }, null, 2) + EOL) else process.stderr.write(message + EOL) process.exitCode = 1 } @@ -499,13 +506,13 @@ const SkillPublishCommand = cmd({ // writer, once: a result already written is not followed by a second one, but the command still exits non-zero. // Server text is made inert before it reaches the terminal. let written = false - const once = (message: string) => { + const once = (message: string, code?: string) => { if (written) { process.exitCode = 1 return } written = true - fail(printable(message)) + fail(printable(message), code) } // altimate_change end try { @@ -563,7 +570,7 @@ const SkillPublishCommand = cmd({ } catch {} } catch (err) { const known = explainPublishError(err) - once(known ?? `Publish failed: ${err instanceof Error ? err.message : String(err)}`) + once(known ?? `Publish failed: ${err instanceof Error ? err.message : String(err)}`, publishErrorCode(err) ?? undefined) } }) } catch (err) { diff --git a/packages/opencode/src/plugin/tui/altimate/rules.tsx b/packages/opencode/src/plugin/tui/altimate/rules.tsx index 46da86d6c4..5a1e37077d 100644 --- a/packages/opencode/src/plugin/tui/altimate/rules.tsx +++ b/packages/opencode/src/plugin/tui/altimate/rules.tsx @@ -454,7 +454,7 @@ function installCards(api: TuiPluginApi) { const key = shownKey(p) if (seen.has(key)) return api.kv.set(seenKey(), [...seen, key].slice(-200)) - if (!quiet) reviewToast(api, p) + if (!quiet) toasterOf(api).push(p) } // `live`: a decision that arrived as an event before the first replay. It is news even when the replay is the scope's // first, which records what was kept before it silently. @@ -505,6 +505,7 @@ function installCards(api: TuiPluginApi) { disposed = true if (leaseTimer) clearTimeout(leaseTimer) clearTimeout(startup) + disposeToaster(api) for (const off of offs.splice(0)) off() disposeEffects() }) @@ -516,23 +517,112 @@ type Shown = { public_id: string; text: string; status: string; reason?: string; /** How a decision is remembered as shown: rule and skill ids live in different id spaces. */ export const shownKey = (p: Pick) => `${p.kind ?? "rule"}:${p.public_id}:${p.status}` -function reviewToast(api: TuiPluginApi, raw: Shown) { - const p = { ...raw, text: printable(raw.text), reason: raw.reason && printable(raw.reason), reviewer: raw.reviewer && printable(raw.reviewer) } +type DecisionToast = { variant: "success" | "warning" | "info"; message: string; duration: number } + +const cleanShown = (raw: Shown): Shown => ({ + ...raw, + text: printable(raw.text), + reason: raw.reason && printable(raw.reason), + reviewer: raw.reviewer && printable(raw.reviewer), +}) +const quote = (text: string) => `"${text.length > 80 ? text.slice(0, 79) + "…" : text}"` +const isBad = (p: Shown) => p.status === "rejected" || (p.status === "retired" && p.kind !== undefined && p.kind !== "rule") + +/** The toast for one decision on the person's own rule, skill or knowledge request; none for a rule status this + * version does not show. */ +export function decisionToast(raw: Shown): DecisionToast | undefined { + const p = cleanShown(raw) const who = p.reviewer ? ` by ${p.reviewer}` : "" - const quoted = `"${p.text.length > 80 ? p.text.slice(0, 79) + "…" : p.text}"` + const quoted = quote(p.text) // A skill or knowledge base the person submitted to the workspace: `text` is its name. if (p.kind && p.kind !== "rule") { const what = p.kind === "skill" ? `Your skill ${quoted}` : `Your knowledge base ${quoted}` - if (p.status === "active") api.ui.toast({ variant: "success", message: `${what} was approved${who}. It now reaches the workspace.`, duration: 10000 }) - else if (p.status === "rejected") api.ui.toast({ variant: "warning", message: `${what} was rejected${who}${p.reason ? ` — ${p.reason}` : ""}`, duration: 15000 }) - else if (p.status === "retired") api.ui.toast({ variant: "warning", message: `${what} was removed from the workspace${who}${p.reason ? ` — ${p.reason}` : ""}`, duration: 15000 }) + if (p.status === "active") return { variant: "success", message: `${what} was approved${who}. It now reaches the workspace.`, duration: 10000 } + if (p.status === "rejected") return { variant: "warning", message: `${what} was rejected${who}${p.reason ? ` — ${p.reason}` : ""}`, duration: 15000 } + if (p.status === "retired") return { variant: "warning", message: `${what} was removed from the workspace${who}${p.reason ? ` — ${p.reason}` : ""}`, duration: 15000 } // A status this version does not know (a newer server) is still shown, not dropped. - else api.ui.toast({ variant: "info", message: `${what} is now ${printable(p.status)}${who}.`, duration: 10000 }) - return + return { variant: "info", message: `${what} is now ${printable(p.status)}${who}.`, duration: 10000 } } - if (p.status === "active") api.ui.toast({ variant: "success", message: `Your rule was approved${who}: ${quoted}. It now applies to the team.`, duration: 10000 }) - else if (p.status === "rejected") api.ui.toast({ variant: "warning", message: `Your rule was rejected${who}: ${quoted}${p.reason ? ` — ${p.reason}` : ""}`, duration: 15000 }) - else if (p.status === "retired") api.ui.toast({ variant: "info", message: `Retired${who}: ${quoted}`, duration: 10000 }) + if (p.status === "active") return { variant: "success", message: `Your rule was approved${who}: ${quoted}. It now applies to the team.`, duration: 10000 } + if (p.status === "rejected") return { variant: "warning", message: `Your rule was rejected${who}: ${quoted}${p.reason ? ` — ${p.reason}` : ""}`, duration: 15000 } + if (p.status === "retired") return { variant: "info", message: `Retired${who}: ${quoted}`, duration: 10000 } + return undefined +} + +/** How many decisions a combined toast names. */ +const COMBINED_NAMED = 5 + +/** One line of a combined toast. */ +function decisionLine(raw: Shown): string { + const p = cleanShown(raw) + const what = p.kind === "skill" ? "skill" : p.kind === "knowledge" ? "knowledge base" : "rule" + const did: Record = { active: "approved", rejected: "rejected", retired: p.kind && p.kind !== "rule" ? "removed" : "retired" } + const who = p.reviewer ? ` by ${p.reviewer}` : "" + const why = isBad(p) && p.reason ? ` — ${p.reason}` : "" + return `${what} ${quote(p.text)} ${did[p.status] ?? printable(p.status)}${who}${why}` +} + +/** The toast for decisions that arrived together. The TUI shows one toast at a time, so several are listed in one + * rather than each replacing the last; a warning when any of them is a rejection or a removal. */ +export function combinedToast(decisions: Shown[]): DecisionToast | undefined { + const shown = decisions.filter((d) => decisionToast(d) !== undefined) + if (shown.length <= 1) return shown[0] && decisionToast(shown[0]) + // A TUI closed for a while can replay many at once: a few are named, the rest counted (`/rules` lists them all). + const named = shown.slice(0, COMBINED_NAMED).map(decisionLine) + const more = shown.length - named.length + return { + variant: shown.some(isBad) ? "warning" : "success", + message: `${shown.length} decisions on your requests: ${named.join(" · ")}${more > 0 ? ` · and ${more} more (see /rules)` : ""}`, + duration: 15000, + } +} + +/** Decisions to toast, held for `windowMs` so the ones that arrive together are shown together. `shownSince` tells + * "Sync now" a decision was (or is about to be) shown since it started, so its summary does not replace it. */ +export function decisionToaster(show: (toast: DecisionToast) => void, windowMs = 300, now = () => Date.now()) { + let queue: Shown[] = [] + let timer: ReturnType | undefined + let lastShown = Number.NEGATIVE_INFINITY + const flush = () => { + timer = undefined + const toast = combinedToast(queue.splice(0)) + if (!toast) return + lastShown = now() + show(toast) + } + return { + push(decision: Shown) { + queue.push(decision) + if (timer === undefined) { + timer = setTimeout(flush, windowMs) + timer.unref?.() + } + }, + flush, + shownSince: (since: number) => queue.some((d) => decisionToast(d) !== undefined) || lastShown >= since, + dispose() { + if (timer !== undefined) clearTimeout(timer) + timer = undefined + queue = [] + }, + } +} + +const toasters = new WeakMap>() +/** This TUI's one decision toaster: shared by the notices and "Sync now". */ +function toasterOf(api: TuiPluginApi) { + let toaster = toasters.get(api) + if (!toaster) { + toaster = decisionToaster((toast) => api.ui.toast(toast)) + toasters.set(api, toaster) + } + return toaster +} + +/** Drops this TUI's toaster: nothing held is shown after the plugin goes away, and a later one starts fresh. */ +function disposeToaster(api: TuiPluginApi) { + toasters.get(api)?.dispose() + toasters.delete(api) } async function showMenu(api: TuiPluginApi) { @@ -611,10 +701,13 @@ async function showMenu(api: TuiPluginApi) { if (option.value === "sync" || option.value === "toggle" || option.value === "follow") api.ui.dialog.clear() if (option.value === "sync") { api.ui.toast({ variant: "info", message: "Syncing rules…", duration: 3000 }) + const started = Date.now() const report = await post<{ ok: boolean; error?: string; pull?: { ok: boolean; rules: number; pending: number; error?: string; notices: unknown[] }; push?: { sent: unknown[]; queued?: number; error?: string }; context?: { status: string; reason?: string } }>(api, "/altimate/rules/sync").catch(() => undefined) // A review notice from this pull is its own toast: the success summary would cover it, but a problem (proposals // kept queued, a failed pull) is still said. - const reviewed = !!report?.pull?.notices.length + // A skill or knowledge decision this sync found arrives as an event, not in `pull.notices`: the TUI shows one + // toast at a time, so the summary must not replace it either. + const reviewed = !!report?.pull?.notices.length || toasterOf(api).shownSince(started) if (report?.context && report.context.status !== "ready") api.ui.toast({ variant: "warning", message: `Rules sync skipped: ${printable(report.context.reason ?? report.context.status)}.`, duration: 8000 }) else if (report?.pull?.ok && report.push?.error) diff --git a/packages/opencode/test/cli/tui/rules-requests.test.ts b/packages/opencode/test/cli/tui/rules-requests.test.ts index 75a2a8b0b9..07a1887546 100644 --- a/packages/opencode/test/cli/tui/rules-requests.test.ts +++ b/packages/opencode/test/cli/tui/rules-requests.test.ts @@ -3,7 +3,7 @@ // The `/rules` menu's pure helpers: how a shown decision is remembered, and why the skill and knowledge part is missing // or short. import { describe, expect, test } from "bun:test" -import { requestsProblem, shownKey } from "../../../src/plugin/tui/altimate/rules" +import { combinedToast, decisionToast, decisionToaster, requestsProblem, shownKey } from "../../../src/plugin/tui/altimate/rules" describe("rules TUI", () => { test("a decision is remembered by kind, id and status: a rule and a skill with one id do not hide each other", () => { @@ -25,4 +25,59 @@ describe("rules TUI", () => { expect(requestsProblem({ ok: true, review_status: "not_linked" })).toBeUndefined() expect(requestsProblem({ ok: true, review_status: "unsupported" })).toBeUndefined() }) + + const approved = { kind: "skill" as const, public_id: "a", text: "cost-guard", status: "active", reviewer: "Olive" } + const rejected = { kind: "knowledge" as const, public_id: "b", text: "Glossary", status: "rejected", reviewer: "Olive", reason: "Too broad" } + + test("one decision reads as before; a rule status this version does not show makes no toast", () => { + expect(decisionToast(approved)).toEqual({ + variant: "success", + message: 'Your skill "cost-guard" was approved by Olive. It now reaches the workspace.', + duration: 10000, + }) + expect(decisionToast(rejected)?.message).toBe('Your knowledge base "Glossary" was rejected by Olive — Too broad') + expect(decisionToast({ public_id: "r", text: "x", status: "superseded" })).toBeUndefined() + expect(combinedToast([approved])).toEqual(decisionToast(approved)) + expect(combinedToast([])).toBeUndefined() + }) + + test("decisions that arrive together are one toast, a warning when any is a rejection or a removal", () => { + expect(combinedToast([approved, rejected])).toEqual({ + variant: "warning", + message: '2 decisions on your requests: skill "cost-guard" approved by Olive · knowledge base "Glossary" rejected by Olive — Too broad', + duration: 15000, + }) + const removed = { ...approved, public_id: "c", status: "retired", reason: "Old" } + expect(combinedToast([approved, removed])?.message).toContain('skill "cost-guard" removed by Olive — Old') + expect(combinedToast([approved, { ...approved, public_id: "d", text: "naming" }])?.variant).toBe("success") + // Many at once (a TUI that was closed): five are named, the rest counted. + const many = Array.from({ length: 8 }, (_, i) => ({ ...approved, public_id: `m${i}`, text: `skill-${i}` })) + const message = combinedToast(many)!.message + expect(message.startsWith("8 decisions on your requests: ")).toBe(true) + expect(message).toContain('skill "skill-4" approved') + expect(message).not.toContain("skill-5") + expect(message.endsWith(" · and 3 more (see /rules)")).toBe(true) + }) + + test("the toaster shows decisions held together once, and tells Sync now one was shown since it started", () => { + const shown: string[] = [] + let clock = 1000 + const toaster = decisionToaster((t) => shown.push(t.message), 60_000, () => clock) + expect(toaster.shownSince(0)).toBe(false) + toaster.push(approved) + toaster.push(rejected) + // Held, not yet shown: Sync now must still not cover it with its summary. + expect(toaster.shownSince(1000)).toBe(true) + toaster.flush() + expect(shown).toEqual([combinedToast([approved, rejected])!.message]) + expect(toaster.shownSince(1000)).toBe(true) + clock = 2000 + expect(toaster.shownSince(1500)).toBe(false) + // Only a status with no toast: nothing shown, nothing claimed. + toaster.push({ public_id: "r", text: "x", status: "superseded" }) + expect(toaster.shownSince(1500)).toBe(false) + toaster.flush() + expect(shown).toHaveLength(1) + toaster.dispose() + }) })