Repository navigation
fix: workspace review decision toasts survive "Sync now"; publish refusals carry a code #1751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,22 +496,23 @@ 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [SUGGESTION]: refusals outside Only errors from |
||
| else process.stderr.write(message + EOL) | ||
| process.exitCode = 1 | ||
| } | ||
| // A failure before or after the publish (opening the project, reading its skills, disposing it) reaches the same | ||
| // 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) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Record decisions as shown only after displaying them. Line 456 persists the decision key before this call queues the decision. If the plugin reloads during the 300 ms window, cleanup discards the queue. The replacement plugin then skips the decision because its key is already persisted. The user never sees the decision. Keep pending keys separate from displayed keys. Persist displayed keys when the batch is shown, and retain the original project and scope for that update.
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| // `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<Shown, "kind" | "public_id" | "status">) => `${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" | ||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [🔵 LOW] Nested ternary expressions are not allowed as they reduce code readability. Please refactor this logic to use an Suggested change:
Suggested change
|
||||||||||||||||||||||||||||||
| const did: Record<string, string> = { 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) | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [SUGGESTION]:
|
||||||||||||||||||||||||||||||
| 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) | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [SUGGESTION]: a batch names the oldest decisions, not the newest
Suggested change
|
||||||||||||||||||||||||||||||
| 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, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+573
to
+577
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [🟠 MEDIUM] If the batch of decisions consists entirely of events that independently resolve to an 'info' variant (e.g., retiring multiple rules), this logic will incorrectly default to Suggested change:
Suggested change
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /** 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<typeof setTimeout> | undefined | ||||||||||||||||||||||||||||||
| let lastShown = Number.NEGATIVE_INFINITY | ||||||||||||||||||||||||||||||
| const flush = () => { | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [SUGGESTION]:
|
||||||||||||||||||||||||||||||
| timer = undefined | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||
| const toast = combinedToast(queue.splice(0)) | ||||||||||||||||||||||||||||||
| if (!toast) return | ||||||||||||||||||||||||||||||
| lastShown = now() | ||||||||||||||||||||||||||||||
| show(toast) | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep sync problems visible when a decision is pending. If a decision arrives at t=50 ms and sync fails at t=100 ms, the error toast appears first. At t=350 ms, this call replaces the error with the decision toast. The 8000 ms error is visible for only 250 ms. The sync warning branches have the same problem. Coordinate pending decisions with sync problems. For example, flush pending decisions before displaying the problem, or include both messages in one toast. The PR objective requires sync problems to remain visible.
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| 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<TuiPluginApi, ReturnType<typeof decisionToaster>>() | ||||||||||||||||||||||||||||||
| /** 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) | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The one-time Prompt for AI agents |
||||||||||||||||||||||||||||||
| 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) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The new JSON contract still omits
codefor known CLI refusals such as built-in and personal skills. Add stable codes for these early refusal paths (and document the vocabulary) so machine clients can distinguish them from unexpected publish failures.Prompt for AI agents