Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions main.js

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions src/scaffolds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { SkillType } from "./types";

// Shared scaffold templates for the create-file flows in both the Obsidian plugin
// and the VS Code extension. Keeping them here prevents the two frontends from
// drifting (they used to hand-roll near-identical strings). The rule scaffold emits
// the .mdc frontmatter Cursor and Continue expect (description, globs, alwaysApply);
// AGENTS.md-style agents read a flat body, so memory/rules on those tools still get a
// usable file.

export interface ScaffoldInput {
name: string;
type: SkillType;
// directory-with-skillmd tools get a SKILL.md body; flat tools get a single file.
directory: boolean;
}

function skillBody(name: string): string {
return ["---", `name: ${name}`, 'description: ""', "---", "", `# ${name}`, "", "## Instructions", "", ""].join("\n");
}

function ruleBody(name: string): string {
return [
"---",
`description: ${name}`,
'globs: ""',
"alwaysApply: false",
"---",
"",
`# ${name}`,
"",
].join("\n");
}

function memoryBody(name: string): string {
return [`# ${name}`, "", ""].join("\n");
}

function flatBody(name: string): string {
return ["---", 'description: ""', "---", "", `# ${name}`, ""].join("\n");
}

// The file extension a rule/memory/command file should use for a given tool path.
// Cursor rules are .mdc; everything else is .md.
export function scaffoldExtension(type: SkillType, mdc: boolean): string {
if (type === "rule" && mdc) return ".mdc";
return ".md";
}

export function scaffoldContent(input: ScaffoldInput): string {
if (input.directory) return skillBody(input.name);
switch (input.type) {
case "rule":
return ruleBody(input.name);
case "memory":
return memoryBody(input.name);
default:
return flatBody(input.name);
}
}
12 changes: 12 additions & 0 deletions src/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ function parseSkillFile(
typeof frontmatter.description === "string"
? frontmatter.description
: "";
const globs =
typeof frontmatter.globs === "string"
? frontmatter.globs
: Array.isArray(frontmatter.globs)
? frontmatter.globs.join(",")
: undefined;
const alwaysApply =
typeof frontmatter.alwaysApply === "boolean"
? frontmatter.alwaysApply
: undefined;

let realPath: string;
try {
Expand All @@ -196,6 +206,8 @@ function parseSkillFile(
dirPath: join(filePath, ".."),
content: raw,
frontmatter,
globs,
alwaysApply,
lastModified: stat.mtimeMs,
fileSize: stat.size,
isFavorite: false,
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface SkillItem {
dirPath: string;
content: string;
frontmatter: Record<string, unknown>;
globs?: string;
alwaysApply?: boolean;
lastModified: number;
fileSize: number;
isFavorite: boolean;
Expand Down
38 changes: 16 additions & 22 deletions src/views/create-skill-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync, mkdirSync, writeFileSync } from "fs";
import { join } from "path";
import { TOOL_CONFIGS } from "../tool-configs";
import { TOOL_SVGS, renderToolIcon } from "../tool-icons";
import { scaffoldContent, scaffoldExtension } from "../scaffolds";
import type { ToolConfig, SkillPath } from "../types";

interface ToolOption {
Expand All @@ -16,7 +17,6 @@ function getToolOptions(): ToolOption[] {
if (!tool.isInstalled()) continue;
const paths: { sp: SkillPath; label: string }[] = [];
for (const sp of [...tool.paths, ...tool.agentPaths]) {
if (sp.type === "rule" || sp.type === "memory") continue;
paths.push({ sp, label: sp.type });
}
if (paths.length > 0) options.push({ tool, paths });
Expand All @@ -28,6 +28,8 @@ const TYPE_ICONS: Record<string, string> = {
skill: "sparkles",
command: "terminal",
agent: "bot",
rule: "scroll",
memory: "database",
};

export class CreateSkillModal extends Modal {
Expand Down Expand Up @@ -187,34 +189,26 @@ export class CreateSkillModal extends Modal {
}
mkdirSync(dir, { recursive: true });
filePath = join(dir, "SKILL.md");
writeFileSync(filePath, [
"---",
`name: ${this.name}`,
'description: ""',
"---",
"",
`# ${this.name}`,
"",
"## Instructions",
"",
"",
].join("\n"), "utf-8");
writeFileSync(filePath, scaffoldContent({
name: this.name,
type: sp.type,
directory: true,
}), "utf-8");
} else {
if (!existsSync(sp.baseDir)) {
mkdirSync(sp.baseDir, { recursive: true });
}
filePath = join(sp.baseDir, `${slug}.md`);
const extension = scaffoldExtension(sp.type, sp.pattern === "mdc");
filePath = join(sp.baseDir, `${slug}${extension}`);
if (existsSync(filePath)) {
new Notice(`Already exists: ${slug}.md`);
new Notice(`Already exists: ${slug}${extension}`);
return;
}
writeFileSync(filePath, [
"---",
'description: ""',
"---",
"",
"",
].join("\n"), "utf-8");
writeFileSync(filePath, scaffoldContent({
name: this.name,
type: sp.type,
directory: false,
}), "utf-8");
}

new Notice(`Created ${this.name}`);
Expand Down
1 change: 1 addition & 0 deletions src/views/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class SidebarPanel {
{ label: "Commands", icon: "terminal", type: "command" },
{ label: "Agents", icon: "bot", type: "agent" },
{ label: "Rules", icon: "scroll", type: "rule" },
{ label: "Memories", icon: "database", type: "memory" },
];

const items = types
Expand Down
18 changes: 14 additions & 4 deletions vscode/src/parity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
VALID_AGENTS,
} from "../../src/marketplace";
import { formatLastUsed, getSkillTraces, getSkillkitStats, isSkillkitAvailable } from "../../src/skillkit";
import { scaffoldContent, scaffoldExtension } from "../../src/scaffolds";
import { TOOL_CONFIGS } from "../../src/tool-configs";
import type { SkillItem } from "../../src/types";

Expand Down Expand Up @@ -198,15 +199,24 @@ export async function createSkillFlow(onCreated: () => Promise<void>): Promise<v
}
mkdirSync(dir, { recursive: true });
filePath = join(dir, "SKILL.md");
writeFileSync(filePath, ["---", `name: ${name}`, 'description: ""', "---", "", `# ${name}`, "", "## Instructions", "", ""].join("\n"), "utf-8");
writeFileSync(filePath, scaffoldContent({
name,
type: sp.type,
directory: true,
}), "utf-8");
} else {
if (!existsSync(sp.baseDir)) mkdirSync(sp.baseDir, { recursive: true });
filePath = join(sp.baseDir, `${slug}.md`);
const extension = scaffoldExtension(sp.type, sp.pattern === "mdc");
filePath = join(sp.baseDir, `${slug}${extension}`);
if (existsSync(filePath)) {
vscode.window.showErrorMessage(`Already exists: ${slug}.md`);
vscode.window.showErrorMessage(`Already exists: ${slug}${extension}`);
return;
}
writeFileSync(filePath, ["---", 'description: ""', "---", "", `# ${name}`, ""].join("\n"), "utf-8");
writeFileSync(filePath, scaffoldContent({
name,
type: sp.type,
directory: false,
}), "utf-8");
}

await vscode.window.showTextDocument(vscode.Uri.file(filePath));
Expand Down
Loading