Skip to content

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

Publish scrub: one-word names only as handles or folders; Published by starts with the person's own profile name

milind-sonic41bfa9df80a
diff --git a/docs/verification/team-sharing.md b/docs/verification/team-sharing.md
index ab2ab54076..51d559cf43 100644
--- a/docs/verification/team-sharing.md
+++ b/docs/verification/team-sharing.md
@@ -6,10 +6,16 @@ department's "…" → Share makes one at once. Publish sends it to the communit
without a MausBot sign-in the card offers Save folder… and GitHub's upload page instead. Import (+ → Import…) adds one
from a GitHub link or a folder.
+Before anything leaves the computer, every text in a template loses home folders (`~`), the app's workspace folders
+(`<workspace>`), email addresses, phone numbers and the publisher's own names (`shared/publish-scrub.ts`); the card says
+how many in one line, and a template with a key or token in it is never published. Publish has one optional field,
+Published by, which becomes the template's `author.name` ("Community" when empty) and shows on the card and in the
+Templates gallery.
+
## Automated checks
```sh
-pnpm exec vitest run shared/share-folder.test.ts shared/skill-files.test.ts server/share.test.ts server/share-github.test.ts server/share-skill-files.test.ts server/share-team-templates.test.ts src/components/TemplateCard.test.ts src/components/ImportDialog.test.ts src/lib/template-share.test.ts
+pnpm exec vitest run shared/publish-scrub.test.ts shared/share-folder.test.ts shared/skill-files.test.ts server/share.test.ts server/share-github.test.ts server/share-skill-files.test.ts server/share-team-templates.test.ts src/components/TemplateCard.test.ts src/components/ImportDialog.test.ts src/lib/template-share.test.ts
pnpm exec vitest run server/share.e2e.test.ts server/cloud-team-templates.e2e.test.ts --silent=false
OMB_UI_E2E=1 pnpm exec vitest run scripts/testing/team-share-ui.e2e.test.ts scripts/testing/team-template-ui.e2e.test.ts --maxWorkers=1
```
diff --git a/packages/phone-protocol/src/share-card.ts b/packages/phone-protocol/src/share-card.ts
index f48a7c28d7..898c9074eb 100644
--- a/packages/phone-protocol/src/share-card.ts
+++ b/packages/phone-protocol/src/share-card.ts
@@ -28,7 +28,7 @@ export interface TemplateCard {
scrubbed?: { paths: number; emails: number; phones: number; names: number };
/** It holds something key- or token-shaped: Publish is refused until the template is made again without it. */
secret?: boolean;
- /** What the "Published by" field starts with: the name it was last published under, else the profile's name. */
+ /** The name last typed into "Published by" ("" when it was cleared); left out until someone publishes it. */
author?: string;
/** The name it was published under; left out for none ("Community"). */
publishedBy?: string;
diff --git a/server/share.e2e.test.ts b/server/share.e2e.test.ts
index 4c725f246b..7eee0eb2c3 100644
--- a/server/share.e2e.test.ts
+++ b/server/share.e2e.test.ts
@@ -8,6 +8,7 @@ import { TEMPLATE_SHARE_MESSAGE } from "../shared/share-card.ts";
const KEY = "sk-ant-api03-SHAREFIXTUREKEY000000000000000000";
const MEMORY_MARKER = "MEMORY_FIXTURE_Acme_contact_jane";
+const PRIVATE_LINE = "Quotes live in /Users/danarivera/Clients/quotes and /Users/danarivera/.openmausbot/workspaces/7c9e6679-7425-40de-944b-e07fc1f90ae7/out.md; ask [email protected] or +1 (415) 555-0132.";
const CHAT_MARKER = "CHAT_FIXTURE_the_Acme_renewal";
const MCP_TOKEN = "MCPFIXTURETOKEN0123456789";
const skill = (name: string) => `---\nname: ${name}\ndescription: ${name} steps.\n---\n\n# ${name}\n\nQuote the list price.\n`;
@@ -83,7 +84,7 @@ describe("templates on a throwaway server", () => {
});
expect(seeded.status, JSON.stringify(seeded.body)).toBe(201);
const bot = seeded.body.bots[0];
- expect((await api("PATCH", `/api/bots/${bot.id}`, { soul: `Quote from the list. The billing key is ${KEY}.\n` })).status).toBe(200);
+ expect((await api("PATCH", `/api/bots/${bot.id}`, { soul: `Quote from the list. The billing key is ${KEY}.\n${PRIVATE_LINE}\n` })).status).toBe(200);
expect((await api("PUT", `/api/bots/${bot.id}/memory`, { text: `# Memory\n- ${MEMORY_MARKER}\n` })).status).toBe(200);
const mcp = await api("POST", "/api/mcp/servers", { name: "crm", type: "http", url: `https://crm.example.com/mcp/${MCP_TOKEN}` });
expect(mcp.status, JSON.stringify(mcp.body)).toBeLessThan(300);
@@ -103,6 +104,7 @@ describe("templates on a throwaway server", () => {
const card = cards[0].template;
expect(card).toMatchObject({ scope: "bot", name: "Sales helper", status: "draft", counts: { bots: 1, skills: 1, routines: 1, apps: 1 }, fallback: "unavailable" });
expect(card.redacted).toBeGreaterThan(0);
+ expect(card).toMatchObject({ secret: true, scrubbed: { paths: 2, emails: 1, phones: 1, names: 0 } });
const shown = await api("GET", `/api/share/${card.id}`);
expect(shown.status).toBe(200);
@@ -116,7 +118,8 @@ describe("templates on a throwaway server", () => {
const files = readTree(saved.body.path);
expect(Object.keys(files).sort()).toEqual(["bot.md", "skills/pricing/SKILL.md"]);
const everything = Object.values(files).join("\n");
- for (const kept of [KEY, MEMORY_MARKER, CHAT_MARKER, MCP_TOKEN, "crm.example.com", "modelSelection", "approval"]) expect(everything).not.toContain(kept);
+ for (const kept of [KEY, MEMORY_MARKER, CHAT_MARKER, MCP_TOKEN, "crm.example.com", "modelSelection", "approval", "/Users/", "dana@", "555-0132"]) expect(everything).not.toContain(kept);
+ expect(files["bot.md"]).toContain("Quotes live in ~/Clients/quotes and <workspace>/out.md; ask <email> or <phone>.");
expect(files["bot.md"]).toContain("enabledAfterInstall: false");
const zip = await fetch(`${fixture.info.url}/api/share/${card.id}/download`, { headers: { origin: fixture.info.url } });
expect(zip.headers.get("content-type")).toBe("application/zip");
diff --git a/server/share.test.ts b/server/share.test.ts
index d840932a4e..c4395e2156 100644
--- a/server/share.test.ts
+++ b/server/share.test.ts
@@ -261,12 +261,12 @@ describe("publishing without the person's details", () => {
let sent: unknown = null;
const { share } = host({ bots: [clean()], suggestedCredit: "Jane Doe", submit: async (submission) => { sent = submission; return ok; } });
const made = share.export({ scope: "bot", bot: clean() }, []);
- expect(made.card.author).toBe("Jane Doe");
+ expect(made.card.author).toBeUndefined();
expect(frontmatter(readFileSync(join(made.dir, "bot.md"), "utf8")).author).toEqual({ name: "Community" });
const published = await share.publish(made.card.id, { author: "Jane D." });
expect(frontmatter(botFile(sent)).author).toEqual({ name: "Jane D." });
expect(published).toMatchObject({ status: "published", publishedBy: "Jane D.", author: "Jane D." });
- await share.publish(made.card.id);
+ expect((await share.publish(made.card.id)).author).toBe("Jane D.");
expect(frontmatter(botFile(sent)).author).toEqual({ name: "Jane D." });
const cleared = await share.publish(made.card.id, { author: "" });
expect(frontmatter(botFile(sent)).author).toEqual({ name: "Community" });
@@ -283,14 +283,14 @@ describe("publishing without the person's details", () => {
it("takes out the person's user name, and their profile name unless they publish under it", async () => {
let sent: unknown = null;
- const helper = clean({ description: "Made by Jane Doe on janedoe's laptop for root." });
+ const helper = clean({ description: "Made by Jane Doe on ~janedoe/laptop for root, and janedoe will know." });
const { share } = host({ bots: [helper], personNames: ["janedoe", "Jane Doe"], suggestedCredit: "Jane Doe", submit: async (submission) => { sent = submission; return ok; } });
const made = share.export({ scope: "bot", bot: helper }, []);
expect(made.card.scrubbed).toEqual({ paths: 0, emails: 0, phones: 0, names: 1 });
await share.publish(made.card.id, { author: "Jane Doe" });
- expect(frontmatter(botFile(sent)).agents[0].description).toBe("Made by Jane Doe on <name>'s laptop for root.");
+ expect(frontmatter(botFile(sent)).agents[0].description).toBe("Made by Jane Doe on ~<name>/laptop for root, and janedoe will know.");
const card = await share.publish(made.card.id, { author: "JD" });
- expect(frontmatter(botFile(sent)).agents[0].description).toBe("Made by <name> on <name>'s laptop for root.");
+ expect(frontmatter(botFile(sent)).agents[0].description).toBe("Made by <name> on ~<name>/laptop for root, and janedoe will know.");
expect(card.scrubbed).toEqual({ paths: 0, emails: 0, phones: 0, names: 2 });
});
diff --git a/server/share.ts b/server/share.ts
index 2864db5e60..6df7410139 100644
--- a/server/share.ts
+++ b/server/share.ts
@@ -67,7 +67,7 @@ export interface ShareHostDeps {
/** The person's own names here (this computer's user name, the profile's name): taken out of what a template carries
* unless one is the name it is published under. */
personNames?(): ReadonlyArray<string | undefined>;
- /** What "Published by" starts with: the profile's name, where the profile is one person's. */
+ /** The name "Published by" most likely holds (the profile's), kept in the text a template is made with. */
suggestedCredit?(): string | undefined;
/** Re-draws a template card already in a conversation. */
patch(threadId: string, messageId: string, text: string, card: TemplateCard): void;
@@ -309,7 +309,6 @@ export function createShareHost(deps: ShareHostDeps) {
const cardOf = (record: TemplateRecord, document?: PackageDocument): TemplateCard => {
const pkg = document?.package;
const fallback = record.status === "draft" || record.status === "failed" ? deps.publisher.availability() : null;
- const credit = record.author ?? deps.suggestedCredit?.();
return {
id: record.id,
scope: record.scope,
@@ -325,7 +324,7 @@ export function createShareHost(deps: ShareHostDeps) {
redacted: record.redacted,
...(anyScrubbed(record.scrubbed) ? { scrubbed: record.scrubbed } : {}),
...(record.secret ? { secret: true } : {}),
- ...(credit !== undefined ? { author: credit } : {}),
+ ...(record.author !== undefined ? { author: record.author } : {}),
...(record.status === "published" && record.author ? { publishedBy: record.author } : {}),
skipped: record.skipped,
status: record.status,
@@ -499,6 +498,7 @@ export function createShareHost(deps: ShareHostDeps) {
const record = records.get(id);
if (!record || record.status === "gone") throw new ShareError("This template was deleted.", 404);
if (record.status === "publishing") return lastCards.get(id) ?? cardOf(record);
+ if (deps.publisher.availability()) return update(record, { status: "draft", error: undefined });
const credit = options.author ?? record.author ?? "";
let document: PackageDocument, counts: ScrubCounts;
try {
@@ -515,7 +515,7 @@ export function createShareHost(deps: ShareHostDeps) {
const bytes = Object.values(files).reduce((sum, value) => sum + (typeof value === "string" ? Buffer.byteLength(value) : value.byteLength), 0);
if (Object.keys(files).length > COMMUNITY_MAX_FILES) return update(record, { status: "failed", error: `A template can have at most ${COMMUNITY_MAX_FILES} files.` }, document);
if (bytes > COMMUNITY_MAX_BYTES) return update(record, { status: "failed", error: "This template is bigger than 4 MB. Leave out large pictures or skills, then publish again." }, document);
- update(record, { status: "publishing", error: undefined, author: credit, scrubbed }, document);
+ update(record, { status: "publishing", error: undefined, scrubbed, ...(options.author === undefined ? {} : { author: options.author }) }, document);
const result = await deps.publisher.submit({
slug: record.slug,
files: Object.fromEntries(Object.entries(files).map(([path, value]) => [path, typeof value === "string" ? value : { base64: Buffer.from(value).toString("base64") }])),
diff --git a/shared/publish-scrub.ts b/shared/publish-scrub.ts
index 737989588a..652ab235d4 100644
--- a/shared/publish-scrub.ts
+++ b/shared/publish-scrub.ts
@@ -159,13 +159,16 @@ export function personalNames(candidates: ReadonlyArray<string | null | undefine
const escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
+/** A full name anywhere in the text. One word (a user name, a first name) may also be an ordinary word, so it goes only
+ * where it is a handle or a folder: after `@`, `~`, `/` or `\`, or before `/`, `\` or `@`. Never inside a longer word
+ * or an identifier: `jane-helper` keeps its name. */
function scrubNames(text: string, names: readonly string[], found: Found): string {
let out = text;
for (const name of names) {
const words = name.split(" ").map(escapeRegExp).join("\\s+");
- // Not inside a longer word or an identifier: `jane-helper` keeps its name.
- const pattern = new RegExp(`(?<![\\p{L}\\p{N}_-])${words}(?![\\p{L}\\p{N}_-])`, "giu");
- out = out.replace(pattern, () => take(found, "names", name.toLowerCase(), SCRUB_MARKS.name));
+ const alone = `(?<![\\p{L}\\p{N}_-])${words}(?![\\p{L}\\p{N}_-])`;
+ const pattern = name.includes(" ") ? alone : `(?<=[@~/\\\\])${words}(?![\\p{L}\\p{N}_-])|${alone}(?=[/\\\\@])`;
+ out = out.replace(new RegExp(pattern, "giu"), () => take(found, "names", name.toLowerCase(), SCRUB_MARKS.name));
}
return out;
}
diff --git a/shared/publish-scrub.vectors.json b/shared/publish-scrub.vectors.json
index 04ccf13fa6..b694ff6571 100644
--- a/shared/publish-scrub.vectors.json
+++ b/shared/publish-scrub.vectors.json
@@ -216,13 +216,13 @@
}
},
{
- "name": "the person's own names, whole words only",
- "input": "Written by Jane Doe (janedoe). Janedoes and jane stay.",
+ "name": "the person's own names: a full name anywhere, one word only as a handle or a folder",
+ "input": "Written by Jane Doe (@janedoe, /srv/janedoe/x, janedoe@host). janedoe wrote it; janedoes and jane-helper stay.",
"names": [
"janedoe",
"Jane Doe"
],
- "output": "Written by <name> (<name>). Janedoes and jane stay.",
+ "output": "Written by <name> (@<name>, /srv/<name>/x, <name>@host). janedoe wrote it; janedoes and jane-helper stay.",
"counts": {
"paths": 0,
"emails": 0,
@@ -231,6 +231,21 @@
"secrets": 0
}
},
+ {
+ "name": "a one-word name that is an ordinary word stays in prose",
+ "input": "It will mark the rose. Ask @will or open ~will/notes.",
+ "names": [
+ "will"
+ ],
+ "output": "It will mark the rose. Ask @<name> or open ~<name>/notes.",
+ "counts": {
+ "paths": 0,
+ "emails": 0,
+ "phones": 0,
+ "names": 1,
+ "secrets": 0
+ }
+ },
{
"name": "the publisher's markers are not scrubbed again",
"input": "~/x <workspace>/y <email> <phone> <name> <secret> «redacted 40 chars»",
diff --git a/src/components/TemplateCard.test.ts b/src/components/TemplateCard.test.ts
index 1fc8aea241..78c7612b0c 100644
--- a/src/components/TemplateCard.test.ts
+++ b/src/components/TemplateCard.test.ts
@@ -9,12 +9,16 @@ import type { Message } from "@/state/store";
const dispatch = vi.fn();
const api = vi.fn(async (_path: string, _init?: RequestInit): Promise<unknown> => ({ ok: true }));
-const place: { state: { config?: { team?: { id: string; name: string } } }; admin: boolean | null } = { state: {}, admin: null };
+const place: { state: { config?: { team?: { id: string; name: string }; profile?: { name?: string } } }; admin: boolean | null; own: boolean } = { state: {}, admin: null, own: true };
vi.mock("@/state/store", async () => {
const { createContext } = await import("react");
return { StoreContext: createContext(null), useStore: () => ({ state: place.state, dispatch }), api: (path: string, init?: RequestInit) => api(path, init) };
});
vi.mock("@/lib/use-owner-or-admin", () => ({ useOwnerOrAdmin: () => place.admin }));
+vi.mock("@/lib/session", () => ({
+ readSessionState: async () => ({ kind: "loopback" }),
+ profileForSession: (profile: { name?: string } | undefined, session: unknown) => (session && place.own ? profile : undefined),
+}));
const openExternalLink = vi.fn(async (_url: string) => {});
vi.mock("@/lib/app-links", () => ({ openExternalLink: (url: string) => openExternalLink(url) }));
const { TemplateChatCard, TemplateDetailsBody } = await import("./TemplateCard");
@@ -37,7 +41,7 @@ function render(card: TemplateCard) {
}
const button = (container: HTMLElement, label: string) => [...container.querySelectorAll("button")].find((each) => each.textContent?.trim() === label);
-afterEach(() => { vi.clearAllMocks(); delete (window as { ogb?: unknown }).ogb; place.state = {}; place.admin = null; document.body.innerHTML = ""; });
+afterEach(() => { vi.clearAllMocks(); delete (window as { ogb?: unknown }).ogb; place.state = {}; place.admin = null; place.own = true; document.body.innerHTML = ""; });
describe("a template's chat card", () => {
it("shows a draft with its counts, Publish and Details, and says nothing private travels", () => {
@@ -134,6 +138,26 @@ describe("a template's chat card", () => {
} finally { unmount(); }
});
+ it("starts Published by with the person's own profile name, never someone else's, and a cleared one stays cleared", async () => {
+ place.state = { config: { profile: { name: "Sam Rivera" } } };
+ const own = render(draft);
+ try {
+ await vi.waitFor(() => expect(own.container.querySelector<HTMLInputElement>("[data-template-author]")!.value).toBe("Sam Rivera"));
+ } finally { own.unmount(); }
+ place.own = false;
+ const shared = render(draft);
+ try {
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ expect(shared.container.querySelector<HTMLInputElement>("[data-template-author]")!.value).toBe("");
+ } finally { shared.unmount(); }
+ place.own = true;
+ const cleared = render({ ...draft, author: "" });
+ try {
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ expect(cleared.container.querySelector<HTMLInputElement>("[data-template-author]")!.value).toBe("");
+ } finally { cleared.unmount(); }
+ });
+
it("names nobody on a published card credited to the community", () => {
expect(shown({ ...draft, status: "published", link: "https://github.com/x/y/tree/a/teams/q", publishedBy: "Community" })).not.toContain("Published by");
expect(shown({ ...draft, status: "published", link: "https://github.com/x/y/tree/a/teams/q", publishedBy: "MausBot user" })).not.toContain("Published by");
diff --git a/src/components/TemplateCard.tsx b/src/components/TemplateCard.tsx
index dc9b0ddc9b..51536e4eb3 100644
--- a/src/components/TemplateCard.tsx
+++ b/src/components/TemplateCard.tsx
@@ -12,6 +12,7 @@ import { cn } from "@/lib/cn";
import { useCopyFeedback } from "@/lib/copy-text";
import { t } from "@/lib/i18n";
import { addToTeamTemplates, askBot, countsLine, creditShown, deleteTemplate, githubConnection, publishTemplate, publishToRepo, saveTemplateFolder, scrubbedLine, templateDetails } from "@/lib/template-share";
+import { profileForSession, readSessionState, type SessionState } from "@/lib/session";
import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";
import { useModalDialog } from "@/hooks/use-modal-dialog";
import { useStore, type Message } from "@/state/store";
@@ -82,6 +83,18 @@ export function TemplateCardBody({ card }: { card: TemplateCard }) {
);
}
+/** The profile's name when the profile is this person's own (not a shared workspace's owner's). */
+function useOwnProfileName(): string {
+ const { state } = useStore();
+ const [session, setSession] = useState<SessionState | null>(null);
+ useEffect(() => {
+ let live = true;
+ void readSessionState().then((next) => { if (live) setSession(next); });
+ return () => { live = false; };
+ }, []);
+ return profileForSession(state.config?.profile, session)?.name?.trim() ?? "";
+}
+
/** What the card's buttons do. The card shown is the latest the server answered, until the message brings a newer one. */
export function useTemplateActions(initial: TemplateCard) {
const [card, setCard] = useState(initial);
@@ -89,9 +102,10 @@ export function useTemplateActions(initial: TemplateCard) {
const [error, setError] = useState("");
const [saved, setSaved] = useState<string | null>(null);
const [teamNote, setTeamNote] = useState<string | null>(null);
- const [author, setAuthor] = useState(initial.author ?? "");
+ const profileName = useOwnProfileName();
+ const [typed, setAuthor] = useState<string | null>(null);
+ const author = typed ?? card.author ?? profileName;
useEffect(() => setCard(initial), [initial]);
- useEffect(() => setAuthor(initial.author ?? ""), [initial.id, initial.author]);
const run = async (kind: NonNullable<typeof busy>, work: () => Promise<void>) => {
if (busy) return;
setBusy(kind);