Skip to content

Commit 6725bce

Browse files
kinlaneclaude
andcommitted
engine: natural "when to use" phrasing for generated skills
The skill description forced the OpenAPI summary (a Title) into a verb clause: "Use when the user wants to stripe get charges" — reads wrong. Derive the intent from the HTTP method + resource instead: intentOf() picks the first meaningful path segment (skipping params and version/api prefixes, so /v1/charges/search -> "charges" not "v1" or "search") and phrases by verb — "list or search charges", "create charges", "retrieve a specific charges record". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7868ac3 commit 6725bce

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/engine.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,31 @@ export function draftPrompt(op: Operation, tool: ToolDesign): PromptDesign {
195195
};
196196
}
197197

198+
// A natural "when to use" phrase from the HTTP verb + resource. Lowercasing an OpenAPI summary
199+
// (which is a Title, e.g. "Stripe Get Charges") into "…wants to stripe get charges" reads wrong;
200+
// the method+path intent ("list or search charges") is cleaner and always sensible.
201+
function intentOf(op: Operation): string {
202+
// First meaningful path segment = the primary collection. Skip params, and skip version/api
203+
// prefixes (/v1/charges -> "charges", not "v1"); the LAST segment can be a sub-action
204+
// (/charges/search -> "search"), so the first real one is the reliable resource name.
205+
const segs = op.path.split('/').filter((s) => s && !s.startsWith('{') && !/^(v\d+|\d+\.\d+|api|rest|public|internal)$/i.test(s));
206+
const resource = (segs[0] || 'the resource').replace(/[-_]/g, ' ');
207+
const onItem = /\}$/.test(op.path);
208+
switch (op.method) {
209+
case 'get': case 'head': return onItem ? `retrieve a specific ${resource} record` : `list or search ${resource}`;
210+
case 'post': return `create ${resource}`;
211+
case 'put': case 'patch': return `update ${resource}`;
212+
case 'delete': return `delete ${resource}`;
213+
default: return `work with ${resource}`;
214+
}
215+
}
216+
198217
export function draftSkill(doc: any, op: Operation, tool: ToolDesign): SkillDesign {
199218
const title = doc.info?.title || 'the API';
200219
const name = kebab(tool.name).slice(0, 64);
201220
return {
202221
name,
203-
description: `${(op.summary || tool.description).replace(/\.$/, '')} via the ${title}. Use when the user wants to ${(op.summary || tool.name).toLowerCase().replace(/\.$/, '')}.`,
222+
description: `${(op.summary || tool.description).replace(/\.$/, '')} via the ${title}. Use when the user wants to ${intentOf(op)}.`,
204223
metadata: { author: '', version: '1.0' },
205224
body: [
206225
`# ${op.summary || tool.title || tool.name}`,

0 commit comments

Comments
 (0)