fix: skills & memory — tool-name encoding, schema normalization, warm-cache, combo id, Ponytail catalog (#9058)

* feat(skills): add Ponytail minimalism skill as external catalog entry

- Add 'external' SkillCategory + SkillArea
- Register ponytail (MIT, DietrichGebert/ponytail) in CURATED_SKILLS
- Generator: external skills carry content in custom block, no api/cli body
- Generate skills/ponytail/SKILL.md with original content preserved
- Update catalog test counts 45 -> 46

* fix(skills+memory): builtin handler fallback in executor, skip vector upsert for deleted memories

- skills: Next.js compiles SkillExecutor into multiple chunks (own singleton
  each); route chunk lacked builtin handlers registered at startup via
  instrumentation. execute() now falls back to builtinSkills registry, so
  POST /api/skills/executions works for file_read/web_fetch/etc.
- memory: scheduleVectorUpsert is fire-and-forget and embeddings are slow;
  health-check verify (create->delete test memory) left queued upserts
  failing with 'memory not found' every 30s. Check existence before embedding
  and skip quietly.

* fix(skills): encode tool names with @ and . for providers rejecting them

Skill tools were advertised as 'name@version' (e.g. test-fr2@1.0.0), but
DeepSeek/Groq/OpenAI reject function names not matching ^[a-zA-Z0-9_-]+$.
Names already valid are left untouched; invalid ones are reversibly encoded
as omr_skill_<base64url> and decoded in interception before registry lookup.

* fix(combos): include DB id column in combo records for dashboard links

getCombos() selected only data/sort_order/context_cache_protection, so
combos whose JSON blob lacked an id field returned id: undefined. The
dashboard then linked to /dashboard/combos/undefined and Combo Control
Center failed with 'Combo not found'. Merge the id column into parsed
rows (authoritative, only when the blob has no id).

* fix(skills): normalize flat skill schemas to object schema for Gemini/Claude

Stored skill schemas are flat property maps ({ text: { type: string } }),
which OpenAI-compatible providers tolerate but Gemini
(function_declarations[].parameters) rejects with 'Unknown name ... Cannot
find field'. Wrap bare maps into { type: 'object', properties: {...} } for
all three tool formats.

* fix(skills): warm registry cache before skill injection in chat path

injectSkills() lists the in-memory skillRegistry, which is empty after a
cold start until something calls loadFromDatabase(). The interception path
already warms the cache (#2815); the injection path did not, so skills
were silently skipped (no_enabled_skills) for the first requests after
restart. Warm the cache for the chat owner before injection.

---------

Co-authored-by: Egor <egorich-print@users.noreply.github.com>
This commit is contained in:
3g0r1ch
2026-08-11 10:30:38 +03:00
committed by GitHub
parent 8bdd29f835
commit 2e799b33a7
11 changed files with 265 additions and 24 deletions

View File

@@ -202,7 +202,11 @@ export function buildSkillMarkdown(
};
const bodyLines =
skill.category === "api" ? buildApiBody(skill, sources) : buildCliBody(skill, sources);
skill.category === "api"
? buildApiBody(skill, sources)
: skill.category === "cli"
? buildCliBody(skill, sources)
: ""; // external: content lives in the custom block below
// Re-inject custom block if present in existing content
let customBlock = "";

View File

@@ -1,4 +1,4 @@
export type SkillCategory = "api" | "cli" | "config";
export type SkillCategory = "api" | "cli" | "config" | "external";
export type SkillArea =
// API areas (22)
@@ -49,7 +49,9 @@ export type SkillArea =
| "cli-eval"
| "cli-plugins-skills"
| "cli-setup"
| "cli-skill-collector";
| "cli-skill-collector"
// External (third-party) skills
| "external";
export interface AgentSkill {
id: string; // canonical id (e.g. "omni-providers", "cli-serve")

View File

@@ -36,6 +36,20 @@ function withSortOrder(payload: string, sortOrder: number | null): JsonRecord {
return parsed;
}
function getComboId(value: unknown): string | null {
const row = asRecord(value);
return typeof row.id === "string" && row.id.trim().length > 0 ? row.id : null;
}
function withRowId(payload: string, row: JsonRecord): JsonRecord {
const parsed = withSortOrder(payload, getSortOrder(row));
const comboId = getComboId(row);
if (comboId && typeof parsed.id !== "string") {
parsed.id = comboId;
}
return parsed;
}
function getComboNameSet(
db: ReturnType<typeof getDbInstance>,
extraNames: string[] = []
@@ -72,7 +86,7 @@ function normalizeStoredCombo(
function parseComboRow(row: unknown): JsonRecord | null {
const payload = getSerializedData(row);
if (!payload) return null;
const parsed = withSortOrder(payload, getSortOrder(row));
const parsed = withRowId(payload, asRecord(row));
// Merge deduplicated column values back into the record
const record = asRecord(row);
if (record.context_cache_protection !== undefined && record.context_cache_protection !== null) {
@@ -97,7 +111,7 @@ function getNextSortOrder() {
export async function getCombos(limit?: number, offset?: number) {
const db = getDbInstance();
let sql =
"SELECT data, sort_order, context_cache_protection FROM combos ORDER BY sort_order ASC, name COLLATE NOCASE ASC";
"SELECT id, data, sort_order, context_cache_protection FROM combos ORDER BY sort_order ASC, name COLLATE NOCASE ASC";
const params: unknown[] = [];
if (limit !== undefined) {
sql += " LIMIT ? OFFSET ?";
@@ -129,7 +143,7 @@ export function getCombosCount(): number {
export async function getComboById(id: string) {
const db = getDbInstance();
const row = db
.prepare("SELECT data, sort_order, context_cache_protection FROM combos WHERE id = ?")
.prepare("SELECT id, data, sort_order, context_cache_protection FROM combos WHERE id = ?")
.get(id);
const combo = parseComboRow(row);
if (!combo) return null;
@@ -139,7 +153,7 @@ export async function getComboById(id: string) {
export async function getComboByName(name: string) {
const db = getDbInstance();
const row = db
.prepare("SELECT data, sort_order, context_cache_protection FROM combos WHERE name = ?")
.prepare("SELECT id, data, sort_order, context_cache_protection FROM combos WHERE name = ?")
.get(name);
const combo = parseComboRow(row);
if (!combo) return null;
@@ -155,7 +169,7 @@ export async function getComboByNameInsensitive(name: string) {
const db = getDbInstance();
const row = db
.prepare(
"SELECT data, sort_order, context_cache_protection FROM combos WHERE name = ? COLLATE NOCASE"
"SELECT id, data, sort_order, context_cache_protection FROM combos WHERE name = ? COLLATE NOCASE"
)
.get(name);
const combo = parseComboRow(row);
@@ -198,7 +212,7 @@ export async function createCombo(data: JsonRecord) {
export async function updateCombo(id: string, data: JsonRecord): Promise<ComboUpdateResult | null> {
const db = getDbInstance();
const existing = db
.prepare("SELECT data, sort_order, context_cache_protection FROM combos WHERE id = ?")
.prepare("SELECT id, data, sort_order, context_cache_protection FROM combos WHERE id = ?")
.get(id);
if (!existing) return null;

View File

@@ -122,6 +122,17 @@ function safeMarkNeedsReindex(id: string, needs: boolean): void {
function scheduleVectorUpsert(id: string, content: string): void {
setImmediate(async () => {
try {
// The upsert is fire-and-forget and embeddings are slow (potion loads
// lazily). Health-check verification (and user deletes) can remove the
// memory before this callback runs — skip quietly instead of spamming
// "memory not found" warnings every sweep interval.
const db = getDbInstance();
const exists = db.prepare("SELECT rowid FROM memories WHERE id = ?").get(id);
if (!exists) {
log.debug("memory.vec.upsert.skipped_deleted", { id });
return;
}
const settings = await getMemorySettings();
const resolution = resolveEmbeddingSource(settings);
if (!resolution.source) return;

View File

@@ -1,5 +1,6 @@
import { skillRegistry } from "./registry";
import { SkillExecution, SkillStatus, SkillHandler } from "./types";
import { builtinSkills } from "./builtins";
import { getDbInstance } from "../db/core";
import { getSettings } from "../db/settings";
import { randomUUID } from "crypto";
@@ -73,7 +74,19 @@ class SkillExecutor {
new Date().toISOString()
);
const handler = this.handlers.get(skill.handler);
let handler = this.handlers.get(skill.handler);
if (!handler) {
// Builtin handlers are registered by instrumentation-node at startup,
// but Next.js may compile this module into multiple chunks (each with
// its own SkillExecutor singleton). Fall back to the builtin registry
// so `POST /api/skills/executions` works regardless of which chunk the
// route is served from.
const builtin = builtinSkills[skill.handler];
if (builtin) {
this.handlers.set(skill.handler, builtin);
handler = builtin;
}
}
if (!handler) {
throw new Error(`Handler not found: ${skill.handler}`);
}

View File

@@ -25,30 +25,74 @@ interface GeminiTool {
parameters: Record<string, unknown>;
}
// Provider tool/function names must match ^[a-zA-Z0-9_-]+$ (OpenAI, DeepSeek,
// Groq, etc.). Skill identifiers are name@version (and names may contain any
// characters), so encode identifiers that would violate the pattern into a
// reversible base64url form. decodeSkillToolName() must be applied on the way
// back in interception before resolving against the registry.
const SKILL_TOOL_NAME_PREFIX = "omr_skill_";
export function encodeSkillToolName(name: string, version: string): string {
const identifier = `${name}@${version}`;
if (/^[a-zA-Z0-9_-]+$/.test(identifier)) {
return identifier;
}
return `${SKILL_TOOL_NAME_PREFIX}${Buffer.from(identifier, "utf8").toString("base64url")}`;
}
export function decodeSkillToolName(toolName: string): string {
if (!toolName.startsWith(SKILL_TOOL_NAME_PREFIX)) {
return toolName;
}
try {
return Buffer.from(toolName.slice(SKILL_TOOL_NAME_PREFIX.length), "base64url").toString("utf8");
} catch {
return toolName;
}
}
// Skills store a flat JSON Schema record ({ "text": { "type": "string" } }),
// but Gemini (function_declarations[].parameters) and Anthropic
// (input_schema) require a full object schema with a properties wrapper.
// Normalize to { "type": "object", "properties": {...} } when the stored
// schema is a bare property map.
function normalizeInputSchema(input: Record<string, unknown>): Record<string, unknown> {
if (typeof input !== "object" || input === null || Array.isArray(input)) {
return input ?? {};
}
if (typeof input.type === "string") {
return input;
}
return {
type: "object",
properties: input,
};
}
function skillToOpenAI(skill: Skill): OpenAITool {
return {
type: "function",
function: {
name: `${skill.name}@${skill.version}`,
name: encodeSkillToolName(skill.name, skill.version),
description: skill.description,
parameters: skill.schema.input,
parameters: normalizeInputSchema(skill.schema.input),
},
};
}
function skillToClaude(skill: Skill): ClaudeTool {
return {
name: `${skill.name}@${skill.version}`,
name: encodeSkillToolName(skill.name, skill.version),
description: skill.description,
input_schema: skill.schema.input,
input_schema: normalizeInputSchema(skill.schema.input),
};
}
function skillToGemini(skill: Skill): GeminiTool {
return {
name: `${skill.name}@${skill.version}`,
name: encodeSkillToolName(skill.name, skill.version),
description: skill.description,
parameters: skill.schema.input,
parameters: normalizeInputSchema(skill.schema.input),
};
}

View File

@@ -1,7 +1,7 @@
import { skillExecutor } from "./executor";
import { skillRegistry } from "./registry";
import { builtinSkills } from "./builtins";
import { detectProvider } from "./injection";
import { detectProvider, decodeSkillToolName } from "./injection";
import { OMNIROUTE_WEB_SEARCH_FALLBACK_TOOL_NAME } from "@omniroute/open-sse/services/webSearchFallback.ts";
import { OMNIROUTE_WEB_FETCH_FALLBACK_TOOL_NAME } from "@omniroute/open-sse/services/webFetchInterception.ts";
import { logger } from "../../../open-sse/utils/logger.ts";
@@ -113,9 +113,10 @@ export async function interceptToolCalls(
};
}
const [name, version] = call.name.includes("@")
? call.name.split("@")
: [call.name, "latest"];
const decodedName = decodeSkillToolName(call.name);
const [name, version] = decodedName.includes("@")
? decodedName.split("@")
: [decodedName, "latest"];
const skillName = version === "latest" ? name : `${name}@${version}`;
@@ -226,7 +227,10 @@ function parseArguments(args: string | Record<string, unknown>): Record<string,
}
function isRegisteredCustomSkill(toolName: string, apiKeyId: string): boolean {
const [name, version] = toolName.includes("@") ? toolName.split("@", 2) : [toolName, undefined];
const decodedName = decodeSkillToolName(toolName);
const [name, version] = decodedName.includes("@")
? decodedName.split("@", 2)
: [decodedName, undefined];
const identifier = version ? `${name}@${version}` : name;
return skillRegistry.getSkill(identifier, apiKeyId) != null;
}

View File

@@ -463,4 +463,17 @@ export const CURATED_SKILLS: CuratedSkillEntry[] = [
icon: "explore",
isNew: true,
},
// ── External (third-party) Skills ─────────────────────────────────────────
{
id: "ponytail",
name: "Ponytail (Minimalism Ladder)",
description:
"External agent skill (MIT, github.com/DietrichGebert/ponytail). Forces the laziest solution that actually works: question whether the task needs to exist at all (YAGNI), reuse what is already in the codebase, reach for the standard library before custom code, native platform features before dependencies, one line before fifty. Climb the ladder on every coding task — writing, adding, refactoring, fixing, reviewing, or designing code, and choosing libraries or dependencies. Supports intensity levels: lite, full (default), ultra. Never cut validation, error handling, security, or accessibility.",
category: "external",
area: "external",
icon: "compress",
isNew: true,
},
];