Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Tighten skill switch cards after review

AdityaUmale8028f745dda4
diff --git a/server/index.test.ts b/server/index.test.ts
index b7c5b0c003..d59cf47939 100644
--- a/server/index.test.ts
+++ b/server/index.test.ts
@@ -11892,7 +11892,7 @@ describe("harness HTTP API", () => {
await api("POST", `/api/bots/${bot.id}/interrupt`);
await api("DELETE", `/api/bots/${bot.id}`);
}
- });
+ }, 60_000);
it("applies a bot's own learned skill at once and undoes it from its receipt", async () => {
const bot = (await api("POST", "/api/bots", {})).body.bot;
diff --git a/server/index.ts b/server/index.ts
index d168eefcf3..d2289eeafe 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -11335,14 +11335,14 @@ function proposalPersistence(botId: string, threadId: string, opensCard = true)
: { ok: true as const };
}
-function skillProposalPersistence(botId: string, threadId: string, opensCard = true) {
+function skillProposalPersistence(botId: string, threadId: string, opensCard = true, cardEvenWithFullAccess = false) {
if (!store.bot(botId)) {
return { ok: false as const, status: 403, error: "unknown sender" };
}
if (!connectorThread(botId, threadId)) {
return { ok: false as const, status: 403, error: "source conversation does not belong to sender" };
}
- if (!opensCard || fullAccessForSource(botId, threadId)) return { ok: true as const };
+ if (!opensCard || (!cardEvenWithFullAccess && fullAccessForSource(botId, threadId))) return { ok: true as const };
const openRequests = store.activePath(threadId).filter(
(message) =>
message.card?.skillRequest?.botId === botId &&
@@ -11458,7 +11458,8 @@ function appendSkillRequestCard(args: {
/** The skill a bot asked to turn on, turn off or delete, as it is now. */
function switchableSkill(bot: BotRecord, name: string): SwitchableSkill | undefined {
const own = listSkills(bot.id).find((skill) => skill.name === name);
- if (own) return { kind: "own", enabled: own.enabled, text: readSkillFile(bot.id, name), source: own.source, description: own.description };
+ // Org skills an Admin pushed stay the person's to change, like library skills.
+ if (own) return { kind: own.source.startsWith("org:") ? "fixed" : "own", enabled: own.enabled, text: readSkillFile(bot.id, name), source: own.source, description: own.description };
const seen = listBotSkills(bot).find((skill) => skill.name === name);
if (!seen) return undefined;
const imported = (seen as { origin?: string }).origin === "imported";
@@ -11469,7 +11470,7 @@ function switchableSkill(bot: BotRecord, name: string): SwitchableSkill | undefi
function stageSkillSwitch(res: ServerResponse, from: BotRecord, threadId: string, action: SkillSwitchAction, body: Record<string, unknown>) {
const name = typeof body.skill_name === "string" ? body.skill_name.trim() : "";
if (!name) return json(res, 400, { error: `skill_name is required when action is ${action}` });
- const persistence = skillProposalPersistence(from.id, threadId);
+ const persistence = skillProposalPersistence(from.id, threadId, true, true);
if (!persistence.ok) return json(res, persistence.status, { error: persistence.error });
const target = skillSwitchTarget(name, action, switchableSkill(from, name));
if ("error" in target) return json(res, 422, { error: target.error });
@@ -11508,6 +11509,11 @@ function appendSkillSwitchCard(args: { botId: string; threadId: string; action:
return { requestId, summary: copy.title };
}
+function applySkillSwitch(botId: string, name: string, action: SkillSwitchAction, kind: SwitchableSkill["kind"] | undefined) {
+ if (action === "delete") return removeSkill(botId, name);
+ return (kind === "imported" ? setImportedSkillEnabled : setSkillEnabled)(botId, name, action === "enable");
+}
+
function resolveSkillSwitch(
args: Parameters<typeof resolveSkillRequest>[0],
messageId: string,
@@ -11533,9 +11539,7 @@ function resolveSkillSwitch(
const bot = store.bot(args.botId);
const current = bot ? switchableSkill(bot, request.name) : undefined;
const still = skillSwitchStillMatches(request.name, request.action, current, request.sha256);
- const applied = "error" in still ? still
- : request.action === "delete" ? removeSkill(args.botId, request.name)
- : (current?.kind === "imported" ? setImportedSkillEnabled : setSkillEnabled)(args.botId, request.name, request.action === "enable");
+ const applied = "error" in still ? still : applySkillSwitch(args.botId, request.name, request.action, current?.kind);
if ("error" in applied) {
store.patchMessage(args.threadId, messageId, { card: { ...card, held: applied.error } });
return { claimed: true, status: 422, error: applied.error };
diff --git a/server/skill-review.ts b/server/skill-review.ts
index 91d1c834f0..1f0ef6f0d4 100644
--- a/server/skill-review.ts
+++ b/server/skill-review.ts
@@ -7,7 +7,7 @@ import { mkdirSync, readFileSync } from "node:fs";
import { dirname } from "node:path";
import type { WireMessage } from "../shared/wire.ts";
-import type { SkillRequestAction } from "../shared/skill-request.ts";
+import { isSkillSwitchAction, skillSwitchVerb, type SkillRequestAction } from "../shared/skill-request.ts";
import { writeFileAtomic } from "./atomic.ts";
import { MAX_SKILL_REVIEW_STEPS } from "./config.ts";
import { AUTHORING_STANDARDS } from "./skill-learn.ts";
@@ -91,7 +91,7 @@ function entriesFor(messages: readonly ReviewMessage[], bot: { id: string; name:
entries.push({ role: "tool", speaker: bot.name, text: `${message.tool.name}${message.tool.ok === false ? " (failed)" : ""}${detail ? `: ${detail}` : ""}` });
} else if (message.kind === "options" && message.card?.skillRequest && (message.card.skillRequest.botId === bot.id)) {
const request = message.card.skillRequest;
- const state = message.card.answered === "allow" ? SKILL_DONE[request.action] : `${request.action} proposed`;
+ const state = message.card.answered === "allow" ? SKILL_DONE[request.action] : isSkillSwitchAction(request.action) ? `${skillSwitchVerb(request.action)} proposed` : "proposed";
entries.push({ role: "skill", speaker: bot.name, text: `skill "${request.name}" ${state}` });
}
}
diff --git a/server/skill-switch.test.ts b/server/skill-switch.test.ts
index 553264f66f..6877912bdf 100644
--- a/server/skill-switch.test.ts
+++ b/server/skill-switch.test.ts
@@ -20,6 +20,7 @@ describe("skillSwitchTarget", () => {
expect(skillSwitchTarget("lib", "disable", { kind: "fixed", enabled: true, text: null })).toEqual({ error: expect.stringContaining("only the person can change it") });
expect(skillSwitchTarget("imp", "delete", { kind: "imported", enabled: true, text })).toEqual({ error: expect.stringContaining("turn it off instead") });
expect(skillSwitchTarget("imp", "disable", { kind: "imported", enabled: true, text })).toMatchObject({ sha256: hash(text) });
+ expect(skillSwitchTarget("imp", "enable", { kind: "imported", enabled: false, text })).toEqual({ error: expect.stringContaining("only the person can turn it on") });
});
it("refuses a switch that would change nothing", () => {
diff --git a/server/skill-switch.ts b/server/skill-switch.ts
index 94b1cac3f5..0c4cfe707c 100644
--- a/server/skill-switch.ts
+++ b/server/skill-switch.ts
@@ -1,6 +1,7 @@
import { createHash } from "node:crypto";
import { redactSecretsInText } from "./redact.ts";
+import { STAGED_GIST_MAX } from "./skills.ts";
import type { SkillSwitchAction } from "../shared/skill-request.ts";
/** own: in this bot's own skills; imported: brought in from this computer for every bot, switched per bot;
@@ -37,6 +38,10 @@ export function skillSwitchTarget(
if (action === "delete" && skill.kind === "imported") {
return { error: `skill "${name}" comes from this computer and can't be deleted from one bot; turn it off instead (action "disable")` };
}
+ // Its scan warnings and helper files are reviewed in Settings, not on this card.
+ if (action === "enable" && skill.kind === "imported") {
+ return { error: `skill "${name}" comes from this computer; only the person can turn it on, in the bot's Skills settings` };
+ }
if (action === "enable" && skill.enabled) return { error: `skill "${name}" is already on` };
if (action === "disable" && !skill.enabled) return { error: `skill "${name}" is already off` };
if (skill.text === null) {
@@ -46,8 +51,8 @@ export function skillSwitchTarget(
return {
preview,
sha256: createHash("sha256").update(preview).digest("hex"),
- ...(skill.source ? { source: skill.source } : {}),
- gist: redactSecretsInText(skill.description ?? "").replace(/\s+/g, " ").trim(),
+ ...(skill.source ? { source: redactSecretsInText(skill.source) } : {}),
+ gist: redactSecretsInText(skill.description ?? "").replace(/\s+/g, " ").trim().slice(0, STAGED_GIST_MAX),
};
}
@@ -81,5 +86,5 @@ export function skillSwitchCardCopy(action: SkillSwitchAction, name: string, gis
subtitle: `${lead}The bot stops using this skill until it is turned on again. Nothing is deleted.` };
}
return { title: `Delete skill "${name}"?`, option: "Delete", done: `Skill "${name}" deleted`,
- subtitle: `${lead}Removes this skill from the bot for good. Its SKILL.md is shown below if you want to keep a copy.` };
+ subtitle: `${lead}Removes this skill and all its files from the bot for good. Its SKILL.md is shown below, with any secrets hidden.` };
}
diff --git a/src/components/ApprovalCard.tsx b/src/components/ApprovalCard.tsx
index 5f8d3eee13..50d29f1529 100644
--- a/src/components/ApprovalCard.tsx
+++ b/src/components/ApprovalCard.tsx
@@ -77,7 +77,6 @@ const PROFILE_FIELD_LABEL: Record<ProfileRequestField, LocaleKey> = {
/** A routine card no one answered is from before Triggers v2 applied changes on their own: nothing can confirm it now. */
const staleRoutineCard = (card: OptionCardData) => Boolean(card.routineRequest && !card.answered);
-/** The card brings its own question and answer words (its title and first option): team setup and MCP server changes. */
/** Cards whose server-written title and first option say what approving does. */
export const titledCard = (card: OptionCardData | undefined) =>
Boolean(card?.teamSetupRequest || card?.mcpRequest || isSkillSwitchAction(card?.skillRequest?.action));
diff --git a/src/components/CallView.tsx b/src/components/CallView.tsx
index f92e979e4a..4484f6ec98 100644
--- a/src/components/CallView.tsx
+++ b/src/components/CallView.tsx
@@ -1,7 +1,6 @@
// Half-duplex: the dictation helper is Apple's SFSpeechRecognizer on raw AVAudioEngine input with no echo cancellation,
// so a mic open during playback transcribes the bot's own voice back. The buffer-backed recognizer does not finalize on
// silence; the helper ends the stream.
-import { isSkillSwitchAction, skillSwitchVerb } from "../../shared/skill-request";
import { useCallback, useEffect, useId, useRef, useState } from "react";
import { AudioLines, Check, ChevronDown, Loader2, Phone, PhoneOff, X } from "lucide-react";
@@ -23,6 +22,7 @@ import { navigateThreadMenu } from "./BotProjects";
import { LiveKeyNeeded } from "./LiveKeyNeeded";
import { liveLineHeldElsewhere } from "./LiveCallBar";
import { isRoutineApproval, isSkillApproval, pendingApprovals, spokenApprovalPrompt } from "./PendingApproval";
+import { titledCard } from "./ApprovalCard";
import { callStarted } from "@/lib/product-events";
import { useDesktopCapabilities } from "./DesktopCapabilities";
import { callCapabilityHelp, type CallCapabilityHelp } from "@/lib/call-capability";
@@ -693,13 +693,10 @@ function Call({ bot }: { bot: Bot }) {
submitted: false,
};
spokenIds.current.add(approval.message.id);
- const skill = approval.message.card?.skillRequest;
- const skillPrompt = skill && isSkillSwitchAction(skill.action)
- ? `${bot.name} wants to ${skillSwitchVerb(skill.action)} the skill "${skill.name}". Open this chat to review it. You can say no to deny it.`
- : skill?.action === "update"
+ const skillPrompt = approval.message.card?.skillRequest?.action === "update"
? `${bot.name} wants to update a learned skill. Open this chat to review the complete skill before replacing the current version. You can say no to deny it.`
: `${bot.name} wants to enable a new learned skill. Open this chat to review the complete skill before enabling it. You can say no to deny it.`;
- void sayThenListen(isSkillApproval(approval) ? skillPrompt : spokenApprovalPrompt(approval, bot.name));
+ void sayThenListen(isSkillApproval(approval) && !titledCard(approval.message.card) ? skillPrompt : spokenApprovalPrompt(approval, bot.name));
return;
}
if (
diff --git a/src/components/GroupCallView.tsx b/src/components/GroupCallView.tsx
index 31a8a4495f..0e8db3aabc 100644
--- a/src/components/GroupCallView.tsx
+++ b/src/components/GroupCallView.tsx
@@ -1,6 +1,5 @@
// Half-duplex like CallView: the native recognizer has no echo cancellation. Replies are queued so a fast second member
// never cuts off the first.
-import { isSkillSwitchAction, skillSwitchVerb } from "../../shared/skill-request";
import { useCallback, useEffect, useRef, useState } from "react";
import { Loader2, PhoneOff, X } from "lucide-react";
@@ -18,6 +17,7 @@ import { CallTargetButton, type CallButtonPlacement } from "./CallView";
import { useAdvancedMode } from "@/lib/interface-mode";
import { useDesktopCapabilities } from "./DesktopCapabilities";
import { isRoutineApproval, isSkillApproval, pendingApprovals, spokenApprovalPrompt } from "./PendingApproval";
+import { titledCard } from "./ApprovalCard";
const YES = /^(yes|yeah|yep|yup|sure|ok|okay|go ahead|do it|allow|approve|approved|fine|please do)\b/i;
const NO = /^(no|nope|don'?t|do not|stop|deny|denied|cancel|never|skip it)\b/i;
@@ -369,13 +369,10 @@ function GroupCall({ group, members }: { group: Group; members: Bot[] }) {
};
spokenIds.current.add(approval.message.id);
const name = member?.name ?? approval.message.from?.name ?? "A group member";
- const skill = approval.message.card?.skillRequest;
- const skillPrompt = skill && isSkillSwitchAction(skill.action)
- ? `${name} wants to ${skillSwitchVerb(skill.action)} the skill "${skill.name}". Open the group thread to review it. You can say no to deny it.`
- : skill?.action === "update"
+ const skillPrompt = approval.message.card?.skillRequest?.action === "update"
? `${name} wants to update a learned skill. Open the group thread to review the complete skill before replacing the current version. You can say no to deny it.`
: `${name} wants to enable a new learned skill. Open the group thread to review the complete skill before enabling it. You can say no to deny it.`;
- enqueueSpeech(isSkillApproval(approval) ? skillPrompt : spokenApprovalPrompt(approval, name), member, true);
+ enqueueSpeech(isSkillApproval(approval) && !titledCard(approval.message.card) ? skillPrompt : spokenApprovalPrompt(approval, name), member, true);
}
if (question?.card?.requestId && askedQuestion.current?.requestId !== question.card.requestId) {