mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-18 03:27:08 +00:00
fix(codex): use app-server native skills (#1289)
* fix(codex): use native skill catalog * fix(codex): refresh changed skill inventory * fix(codex): preserve skill fallback on discovery error * fix(web): refresh skills when completion opens
This commit is contained in:
@@ -564,6 +564,37 @@ describe('appServerConfig', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('builds a structured leading skill input from the native catalog', () => {
|
||||
expect(buildUserInputFromMessage('$hapi inspect @"README.md"', [{
|
||||
name: 'hapi',
|
||||
path: '/home/user/.agents/skills/hapi/SKILL.md',
|
||||
description: 'Manage HAPI',
|
||||
scope: 'user',
|
||||
enabled: true
|
||||
}])).toEqual([
|
||||
{ type: 'skill', name: 'hapi', path: '/home/user/.agents/skills/hapi/SKILL.md' },
|
||||
{ type: 'text', text: ' inspect ' },
|
||||
{ type: 'mention', name: 'README.md', path: 'README.md' }
|
||||
]);
|
||||
});
|
||||
|
||||
it('keeps unknown and disabled skill references as text', () => {
|
||||
const skills = [{
|
||||
name: 'disabled-skill',
|
||||
path: '/skills/disabled/SKILL.md',
|
||||
description: 'Disabled',
|
||||
scope: 'user' as const,
|
||||
enabled: false
|
||||
}];
|
||||
|
||||
expect(buildUserInputFromMessage('$unknown run', skills)).toEqual([
|
||||
{ type: 'text', text: '$unknown run' }
|
||||
]);
|
||||
expect(buildUserInputFromMessage('$disabled-skill run', skills)).toEqual([
|
||||
{ type: 'text', text: '$disabled-skill run' }
|
||||
]);
|
||||
});
|
||||
|
||||
it('builds mention inputs from quoted @file tokens with spaces', () => {
|
||||
expect(buildUserInputFromMessage('please inspect @"docs/My File.md" now')).toEqual([
|
||||
{ type: 'text', text: 'please inspect ' },
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
ApprovalPolicy,
|
||||
SandboxMode,
|
||||
SandboxPolicy,
|
||||
SkillMetadata,
|
||||
ThreadStartParams,
|
||||
TurnStartParams,
|
||||
UserInput
|
||||
@@ -139,13 +140,26 @@ function mentionNameFromPath(path: string): string {
|
||||
return parts[parts.length - 1] ?? path;
|
||||
}
|
||||
|
||||
export function buildUserInputFromMessage(message: string): UserInput[] {
|
||||
export function buildUserInputFromMessage(
|
||||
message: string,
|
||||
skills: readonly SkillMetadata[] = []
|
||||
): UserInput[] {
|
||||
const inputs: UserInput[] = [];
|
||||
const skillMatch = /^\s*\$([^\s]+)(?=\s|$)/.exec(message);
|
||||
const skill = skillMatch
|
||||
? skills.find(candidate => candidate.enabled && candidate.name === skillMatch[1])
|
||||
: undefined;
|
||||
const inputMessage = skill && skillMatch
|
||||
? message.slice(skillMatch[0].length)
|
||||
: message;
|
||||
if (skill) {
|
||||
inputs.push({ type: 'skill', name: skill.name, path: skill.path });
|
||||
}
|
||||
const mentionPattern = /(^|\s)@"((?:\\.|[^"\\])*)"/g;
|
||||
let lastIndex = 0;
|
||||
let match: RegExpExecArray | null;
|
||||
|
||||
while ((match = mentionPattern.exec(message)) !== null) {
|
||||
while ((match = mentionPattern.exec(inputMessage)) !== null) {
|
||||
const prefix = match[1] ?? '';
|
||||
const rawPath = match[2] ?? '';
|
||||
const pathText = rawPath;
|
||||
@@ -153,7 +167,7 @@ export function buildUserInputFromMessage(message: string): UserInput[] {
|
||||
if (!path) continue;
|
||||
|
||||
const atIndex = match.index + prefix.length;
|
||||
const textBeforeMention = message.slice(lastIndex, atIndex);
|
||||
const textBeforeMention = inputMessage.slice(lastIndex, atIndex);
|
||||
if (textBeforeMention) {
|
||||
inputs.push({ type: 'text', text: textBeforeMention });
|
||||
}
|
||||
@@ -166,7 +180,7 @@ export function buildUserInputFromMessage(message: string): UserInput[] {
|
||||
lastIndex = mentionPattern.lastIndex - (rawPath.length - pathText.length);
|
||||
}
|
||||
|
||||
const remainder = message.slice(lastIndex);
|
||||
const remainder = inputMessage.slice(lastIndex);
|
||||
if (remainder || inputs.length === 0) {
|
||||
inputs.push({ type: 'text', text: remainder });
|
||||
}
|
||||
@@ -232,6 +246,7 @@ export function buildTurnStartParams(args: {
|
||||
cliOverrides?: CodexCliOverrides;
|
||||
baseInstructions?: string;
|
||||
developerInstructions?: string;
|
||||
skills?: readonly SkillMetadata[];
|
||||
overrides?: {
|
||||
approvalPolicy?: TurnStartParams['approvalPolicy'];
|
||||
sandboxPolicy?: TurnStartParams['sandboxPolicy'];
|
||||
@@ -242,7 +257,7 @@ export function buildTurnStartParams(args: {
|
||||
const params: TurnStartParams = {
|
||||
threadId: args.threadId,
|
||||
cwd: args.cwd,
|
||||
input: buildUserInputFromMessage(args.message)
|
||||
input: buildUserInputFromMessage(args.message, args.skills)
|
||||
};
|
||||
|
||||
const allowCliOverrides = args.mode?.permissionMode === 'default';
|
||||
|
||||
Reference in New Issue
Block a user