Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge #7883: Import a local skill folder from the desktop (#6659)
milind-sonie66a813dcd8b
diff --cc electron/skill-folder-plan.d.mtsindex 0000000000,25db5acdd8..79713ee30fmode 000000,100644..100644--- a/electron/skill-folder-plan.d.mts+++ b/electron/skill-folder-plan.d.mts@@@ -1,0 -1,15 +1,16 @@@+ import type { SkippedSkillFile, SkippedSkillFileReason } from "../shared/skill-import.ts";++ export const SKILL_FOLDER_LIMITS: Readonly<{ files: number; bytes: number; fileBytes: number; depth: number }>;+ export const SKILL_IMPORT_SKIP_REPORT_MAX: number;++ export interface FolderEntry {+ /** Relative to the skill folder, "/"-separated. */+ path: string;+ kind: "file" | "folder" | "link" | "submodule";+ size: number;+ executable?: boolean;+ }+++export function unsafeFileNameProblem(part: string): "name" | null;+ export function skillFilePathProblem(path: string, folder?: boolean): SkippedSkillFileReason | null;+ export function planSkillFolder<T extends FolderEntry>(entries: readonly T[]): { take: T[]; skipped: SkippedSkillFile[] };diff --cc electron/skill-folder-plan.mjsindex 0000000000,6287567ff6..5f5fe958f5mode 000000,100644..100644--- a/electron/skill-folder-plan.mjs+++ b/electron/skill-folder-plan.mjs@@@ -1,0 -1,73 +1,79 @@@+ /** `depth` counts path segments, file name included. */+ export const SKILL_FOLDER_LIMITS = { files: 200, bytes: 16 * 1024 * 1024, fileBytes: 2 * 1024 * 1024, depth: 8 };+ export const SKILL_IMPORT_SKIP_REPORT_MAX = 20;++ const GENERATED = new Set(["__pycache__", "node_modules", "venv"]);+ const unsafeCharacter = (char) => char < " " || char === "\u007f" || '<>:"|?*\\'.includes(char);+ // Windows refuses these names in any folder, with or without an extension.+ const WINDOWS_DEVICE = /^(?:con|prn|aux|nul|com[0-9¹²³]|lpt[0-9¹²³])(?:\..*)?$/i;+++/** Why one path segment may not name a file: characters a filesystem or Windows refuses, a trailing dot or space,++ * a Windows device name, or more than 255 bytes. Null when the segment may be used. */++export function unsafeFileNameProblem(part) {++ return !part || part === "." || part === ".." || [...part].some(unsafeCharacter) || /[. ]$/.test(part) ||++ WINDOWS_DEVICE.test(part) || Buffer.byteLength(part, "utf8") > 255 ? "name" : null;++}+++ /** Why `path` (relative, "/"-separated) may not be written inside a skill folder; null when it may. */+ export function skillFilePathProblem(path, folder = false) {+ const parts = path.split("/");+ for (const part of parts) {- if (!part || part === "." || part === ".." || [...part].some(unsafeCharacter) || /[. ]$/.test(part) ||- WINDOWS_DEVICE.test(part) || Buffer.byteLength(part, "utf8") > 255) return "name";++ if (unsafeFileNameProblem(part)) return "name";+ if (part.startsWith(".")) return "hidden";+ if (GENERATED.has(part.toLowerCase())) return "generated";+ }+ return parts.length > SKILL_FOLDER_LIMITS.depth - (folder ? 1 : 0) ? "deep" : null;+ }++ const depthOf = (path) => path.split("/").length;+ const comparable = (path) => path.normalize("NFC").toLowerCase();++ /** What of a folder listing comes in, SKILL.md first and shallow files before deep ones, within the limits. */+ export function planSkillFolder(entries) {+ const ordered = [...entries].sort((a, b) => depthOf(a.path) - depthOf(b.path) || (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));+ const skillMd = ordered.find((entry) => entry.path === "SKILL.md" && entry.kind === "file");+ const take = skillMd ? [skillMd] : [];+ const skipped = [];+ const closed = [];+ const held = new Map(skillMd ? [["skill.md", { spelling: "SKILL.md", folder: false }]] : []);+ let bytes = skillMd?.size ?? 0;+ const clashes = (path) => {+ const parts = path.split("/");+ return parts.some((_, index) => {+ const prefix = parts.slice(0, index + 1).join("/");+ const holder = held.get(comparable(prefix));+ return holder !== undefined && (index === parts.length - 1 || !holder.folder || holder.spelling !== prefix);+ });+ };+ const hold = (path) => {+ const parts = path.split("/");+ parts.forEach((_, index) => {+ const prefix = parts.slice(0, index + 1).join("/");+ held.set(comparable(prefix), { spelling: prefix, folder: index < parts.length - 1 });+ });+ };+ for (const entry of ordered) {+ if (entry === skillMd || closed.some((prefix) => entry.path.startsWith(prefix))) continue;+ const skip = (reason) => skipped.push({ path: entry.kind === "folder" ? `${entry.path}/` : entry.path, reason });+ if (entry.kind === "link" || entry.kind === "submodule") {+ skip(entry.kind);+ continue;+ }+ const problem = skillFilePathProblem(entry.path, entry.kind === "folder");+ if (problem) {+ skip(problem);+ if (entry.kind === "folder") closed.push(`${entry.path}/`);+ continue;+ }+ if (entry.kind === "folder") continue;+ if (entry.size > SKILL_FOLDER_LIMITS.fileBytes) skip("large");+ else if (clashes(entry.path)) skip("duplicate");+ else if (take.length >= SKILL_FOLDER_LIMITS.files || bytes + entry.size > SKILL_FOLDER_LIMITS.bytes) skip("full");+ else {+ take.push(entry);+ bytes += entry.size;+ hold(entry.path);+ }+ }+ return { take, skipped };+ }diff --cc server/skill-folder.tsindex 10a4f360a6,6f222c4eed..f522cb3a3d--- a/server/skill-folder.ts+++ b/server/skill-folder.ts@@@ -10,35 -10,12 +10,12 @@@ import type { SkillImportSummary, Skippimport { parseSkillMd, scanSkillText, SKILL_FILE_MAX_BYTES, type ParsedSkill } from "../shared/skill-md.ts";import { directoryEntryState } from "./skill-storage.ts";- /** `depth` counts path segments, file name included. */- export const SKILL_FOLDER_LIMITS = { files: 200, bytes: 16 * 1024 * 1024, fileBytes: 2 * 1024 * 1024, depth: 8 } as const;-export { planSkillFolder, SKILL_FOLDER_LIMITS, skillFilePathProblem, type FolderEntry } from "../electron/skill-folder-plan.mjs";++export { planSkillFolder, SKILL_FOLDER_LIMITS, skillFilePathProblem, unsafeFileNameProblem, type FolderEntry } from "../electron/skill-folder-plan.mjs";+ export type { GitHubSkillOrigin } from "../shared/skill-import.ts";- const SKIPPED_LIST_MAX = 20;const MAX_WARNINGS = 20;- const GENERATED = new Set(["__pycache__", "node_modules", "venv"]);- const unsafeCharacter = (char: string) => char < " " || char === "\u007f" || '<>:"|?*\\'.includes(char);- // Windows refuses these names in any folder, with or without an extension.- const WINDOWS_DEVICE = /^(?:con|prn|aux|nul|com[0-9¹²³]|lpt[0-9¹²³])(?:\..*)?$/i;const SCRIPT = /\.(?:sh|bash|zsh|fish|ps1|psm1|bat|cmd|py|rb|pl|php|lua|js|mjs|cjs|ts)$/i;- /** Why one path segment may not name a file: characters a filesystem or Windows refuses, a trailing dot or space,- * a Windows device name, or more than 255 bytes. Null when the segment may be used. */- export function unsafeFileNameProblem(part: string): "name" | null {- return !part || part === "." || part === ".." || [...part].some(unsafeCharacter) || /[. ]$/.test(part) ||- WINDOWS_DEVICE.test(part) || Buffer.byteLength(part, "utf8") > 255 ? "name" : null;- }-- /** Why `path` (relative, "/"-separated) may not be written inside a skill folder; null when it may. */- export function skillFilePathProblem(path: string, folder = false): SkippedSkillFileReason | null {- const parts = path.split("/");- for (const part of parts) {- if (unsafeFileNameProblem(part)) return "name";- if (part.startsWith(".")) return "hidden";- if (GENERATED.has(part.toLowerCase())) return "generated";- }- return parts.length > SKILL_FOLDER_LIMITS.depth - (folder ? 1 : 0) ? "deep" : null;- }-export const isSkillScript = (file: { path: string; executable?: boolean }): boolean =>Boolean(file.executable) || SCRIPT.test(file.path);