mirror of
https://github.com/different-ai/openwork
synced 2026-05-10 17:22:05 +02:00
* refactor(repo): move OpenWork apps into apps and ee layout Rebase the monorepo layout migration onto the latest dev changes so the moved app, desktop, share, and cloud surfaces keep working from their new paths. Carry the latest deeplink, token persistence, build, Vercel, and docs updates forward to avoid stale references and broken deploy tooling. * chore(repo): drop generated desktop artifacts Ignore the moved Tauri target and sidecar paths so local cargo checks do not pollute the branch. Remove the accidentally committed outputs from the repo while keeping the layout migration intact. * fix(release): drop built server cli artifact Stop tracking the locally built apps/server/cli binary so generated server outputs do not leak into commits. Also update the release workflow to check the published scoped package name for @openwork/server before deciding whether npm publish is needed. * fix(workspace): add stable CLI bin wrappers Point the server and router package bins at committed wrapper scripts so workspace installs can create shims before dist outputs exist. Keep the wrappers compatible with built binaries and source checkouts to avoid Vercel install warnings without changing runtime behavior.
130 lines
3.4 KiB
TypeScript
130 lines
3.4 KiB
TypeScript
"use client";
|
|
|
|
export const DEFAULT_SKILL_NAME = "skill.md";
|
|
export const DEFAULT_SKILL_DESCRIPTION = "This is a skill I'm currently using.";
|
|
|
|
const SKILL_NAME_STOPWORDS = new Set([
|
|
"a",
|
|
"an",
|
|
"and",
|
|
"for",
|
|
"from",
|
|
"how",
|
|
"identity",
|
|
"into",
|
|
"my",
|
|
"of",
|
|
"or",
|
|
"parameters",
|
|
"scope",
|
|
"skill",
|
|
"skills",
|
|
"that",
|
|
"the",
|
|
"this",
|
|
"to",
|
|
"trigger",
|
|
"when",
|
|
"with",
|
|
"your",
|
|
]);
|
|
|
|
export function yamlValue(value: string): string {
|
|
const normalized = String(value ?? "").trim();
|
|
if (/^[A-Za-z0-9._/\- ]+$/.test(normalized) && !normalized.includes(":")) {
|
|
return normalized;
|
|
}
|
|
return JSON.stringify(normalized);
|
|
}
|
|
|
|
function normalizeNameTokens(value: string): string[] {
|
|
return String(value)
|
|
.toLowerCase()
|
|
.split(/[^a-z0-9]+/g)
|
|
.filter((token) => token && token.length > 2 && !SKILL_NAME_STOPWORDS.has(token));
|
|
}
|
|
|
|
export function inferSkillNameFromBody(body: string): string {
|
|
const candidateLines = [
|
|
...Array.from(String(body ?? "").matchAll(/^#{1,6}\s+(.+)$/gm)).map((match) => match[1] ?? ""),
|
|
...String(body ?? "")
|
|
.split(/\r?\n/)
|
|
.map((line) => line.trim())
|
|
.filter(Boolean)
|
|
.slice(0, 12),
|
|
];
|
|
|
|
for (const line of candidateLines) {
|
|
const tokens = normalizeNameTokens(line);
|
|
if (tokens.length >= 2) {
|
|
return `${tokens[0]}-${tokens[1]}`;
|
|
}
|
|
if (tokens.length === 1) {
|
|
return tokens[0];
|
|
}
|
|
}
|
|
|
|
return "shared-skill";
|
|
}
|
|
|
|
export function resolveSkillName(name: string, body: string): string {
|
|
const normalized = String(name ?? "").trim();
|
|
if (normalized) return normalized;
|
|
return inferSkillNameFromBody(body);
|
|
}
|
|
|
|
export function composeSkillMarkdown(name: string, description: string, body: string): string {
|
|
const normalizedName = resolveSkillName(name, body);
|
|
const normalizedDescription = String(description ?? "").trim() || DEFAULT_SKILL_DESCRIPTION;
|
|
const normalizedBody = String(body ?? "").replace(/\r\n/g, "\n").trim();
|
|
const frontmatter = [
|
|
"---",
|
|
`name: ${yamlValue(normalizedName)}`,
|
|
`description: ${yamlValue(normalizedDescription)}`,
|
|
"---",
|
|
].join("\n");
|
|
|
|
return normalizedBody ? `${frontmatter}\n\n${normalizedBody}\n` : `${frontmatter}\n`;
|
|
}
|
|
|
|
export function normalizeSkillMarkdown(
|
|
content: string,
|
|
fallbackName = DEFAULT_SKILL_NAME,
|
|
fallbackDescription = DEFAULT_SKILL_DESCRIPTION,
|
|
): string {
|
|
const text = String(content ?? "").replace(/\r\n/g, "\n");
|
|
const parsed = parseSkillMarkdown(text);
|
|
if (parsed.hasFrontmatter) return text;
|
|
return composeSkillMarkdown(fallbackName, fallbackDescription, text);
|
|
}
|
|
|
|
export function parseSkillMarkdown(content: string): { name: string; description: string; body: string; hasFrontmatter: boolean } {
|
|
const text = String(content ?? "").replace(/\r\n/g, "\n");
|
|
const match = text.match(/^---\n([\s\S]*?)\n---\n?/);
|
|
if (!match) {
|
|
return {
|
|
name: "",
|
|
description: "",
|
|
body: text,
|
|
hasFrontmatter: false,
|
|
};
|
|
}
|
|
|
|
const header = match[1] ?? "";
|
|
const body = text.slice(match[0].length);
|
|
const nameMatch = header.match(/^name:\s*(.+)$/m);
|
|
const descriptionMatch = header.match(/^description:\s*(.+)$/m);
|
|
|
|
const normalizeField = (value: string | undefined): string =>
|
|
String(value ?? "")
|
|
.trim()
|
|
.replace(/^['"]|['"]$/g, "");
|
|
|
|
return {
|
|
name: normalizeField(nameMatch?.[1]),
|
|
description: normalizeField(descriptionMatch?.[1]),
|
|
body,
|
|
hasFrontmatter: true,
|
|
};
|
|
}
|