From ea0a8d7b4c6285ab63cf7de31df42274f0185061 Mon Sep 17 00:00:00 2001 From: ruv Date: Fri, 2 Oct 2026 16:29:01 -0400 Subject: [PATCH 1/2] feat(ruflo-console): Skills view over the npx skills CLI (skills.sh) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new view, 🧰 Skills, with no hotkey (every digit and letter is taken): the tab is pressed, and the menu prompt and /ruflo skills reach it by name. - INSTALLED: `skills ls --json` and `ls -g --json`, read when the view opens or on r; one failing scope does not blank the other. Each row has ▸ update ▸ remove ▸ edit. - SEARCH: Enter in the field runs `skills find ` (owner: becomes --owner); the coloured text is read line by line into owner/repo@skill with install counts, each with ▸ add and ▸ add -g. - CREATE: a name field for `skills init `. Enter asks, and Enter again confirms. Reads run at once, but only when the person acts, because npx and skills.sh are on the network. Every change is confirm-gated through the runner (ActionSpec run + shows, so the confirm row prints the exact argv). After a change, both lists are read again and the result says whether the change shows in them. ▸ edit loads the AI terminal with a claude prompt; nothing here writes a file. Input is validated before it becomes argv: [A-Za-z0-9@/._ -], no leading -, capped. A new skill name may not hold a slash or start with a dot, because init joins it onto the project. viewOf no longer matches '' to the hotkey-less view. The tab bar, /ruflo help and the palette drop the key where there is none. The narrow-tab test holds the position, not the total view count. Co-Authored-By: RuFlo --- plugins/ruflo-console/hooks/bindings.ts | 9 +- plugins/ruflo-console/hooks/commands.ts | 2 +- plugins/ruflo-console/hooks/controller.ts | 6 + plugins/ruflo-console/hooks/data/skills.ts | 148 +++++++++++ plugins/ruflo-console/hooks/palette.ts | 2 +- plugins/ruflo-console/hooks/skills.ts | 239 ++++++++++++++++++ plugins/ruflo-console/hooks/state.ts | 10 +- plugins/ruflo-console/hooks/views/common.ts | 3 + plugins/ruflo-console/hooks/views/pane.ts | 8 +- plugins/ruflo-console/hooks/views/skills.ts | 133 ++++++++++ plugins/ruflo-console/tests/behaviour.test.ts | 3 +- .../ruflo-console/tests/fixtures/skills.ts | 32 +++ plugins/ruflo-console/tests/skills.spec.ts | 191 ++++++++++++++ plugins/ruflo-console/tests/views.test.ts | 45 +++- 14 files changed, 822 insertions(+), 9 deletions(-) create mode 100644 plugins/ruflo-console/hooks/data/skills.ts create mode 100644 plugins/ruflo-console/hooks/skills.ts create mode 100644 plugins/ruflo-console/hooks/views/skills.ts create mode 100644 plugins/ruflo-console/tests/fixtures/skills.ts create mode 100644 plugins/ruflo-console/tests/skills.spec.ts diff --git a/plugins/ruflo-console/hooks/bindings.ts b/plugins/ruflo-console/hooks/bindings.ts index 6530018b78..21721ed433 100644 --- a/plugins/ruflo-console/hooks/bindings.ts +++ b/plugins/ruflo-console/hooks/bindings.ts @@ -9,6 +9,7 @@ import { plain } from './data/parse' import type { Host } from './host' import { filterPalette, paletteEntries } from './palette' import type { Runner } from './runner' +import { skillActions } from './skills' import { PANE_ID, viewOf, type State } from './state' import type { Actions } from './views/common' import { openTasks, selection } from './views/select' @@ -40,7 +41,11 @@ export function actionsOf(state: State, host: Host, runner: Runner, steps: Steps const actions: Actions = { view: setView, - refresh: () => void freshRead().then(() => probe(true)), + refresh: () => { + void freshRead().then(() => probe(true)) + // The skills lists come from `npx skills`, not the disk read: r asks for them again on that view. + if (state.view === 'skills') actions.skills.list() + }, help: () => { state.isHelp = !state.isHelp host.invalidate() @@ -208,6 +213,8 @@ export function actionsOf(state: State, host: Host, runner: Runner, steps: Steps setView('terminal') }, }, + // ▸ edit hands the skill to the AI terminal, as x.ruv.io's ▸ open does: typed, not run. + skills: skillActions(state, host, runner, text => actions.term.load('claude', text)), } return actions diff --git a/plugins/ruflo-console/hooks/commands.ts b/plugins/ruflo-console/hooks/commands.ts index 0485cae74a..f8476af424 100644 --- a/plugins/ruflo-console/hooks/commands.ts +++ b/plugins/ruflo-console/hooks/commands.ts @@ -88,7 +88,7 @@ export const HELP = [ '', 'Open and switch', ` /ruflo open the cockpit (also opens by itself where it can dock, panel=auto)`, - ` /ruflo ${VIEWS.map(view => `${view.id} (${view.key})`).join(', ')}`, + ` /ruflo ${VIEWS.map(view => (view.key === '' ? view.id : `${view.id} (${view.key})`)).join(', ')}`, ' /ruflo agent drill into one agent: role, task, claims, activity, logs, timeline', ' /ruflo back | close | status', ' /ruflo dump a view as plain text, without the pane (for claude -p and scripts)', diff --git a/plugins/ruflo-console/hooks/controller.ts b/plugins/ruflo-console/hooks/controller.ts index a1f6408ed8..379a3fb118 100644 --- a/plugins/ruflo-console/hooks/controller.ts +++ b/plugins/ruflo-console/hooks/controller.ts @@ -13,6 +13,7 @@ import { markPicture } from './gfx/pictures' import type { Host } from './host' import { agentLogs } from './ops' import { createRunner, type Runner } from './runner' +import { listSkills } from './skills' import { CLI_PREFIXES, isBooting, PANE_ID, push, rowsOf, storeKeyOf, type State } from './state' import type { Actions } from './views/common' import { picturesOf } from './views/frames' @@ -393,6 +394,11 @@ export function createController(state: State, host: Host): Controller { host.invalidate() // The terminal is for typing: its field takes the keys as it opens, so letters reach it, not the pane's hotkeys. if (view === 'terminal') focusField('term-input') + // Opening the skills view is the person asking for its lists (npx skills reaches the network, so never unasked). + if (view === 'skills') { + void listSkills(state, host) + focusField('skills-search') + } } /** Moves the pane's focus ring onto one of its fields; refused (the pane does not hold the keys), nothing happens. */ diff --git a/plugins/ruflo-console/hooks/data/skills.ts b/plugins/ruflo-console/hooks/data/skills.ts new file mode 100644 index 0000000000..d619703e3f --- /dev/null +++ b/plugins/ruflo-console/hooks/data/skills.ts @@ -0,0 +1,148 @@ +/** + * The `skills` CLI (vercel-labs/skills, skills.sh) as fixed argv, and readers for what it prints. Read against skills + * 1.7.0's source: `ls --json` prints an array of `{ name, path, scope, agents, source, sourceUrl, sourceType }`; `find` + * has no JSON, so its coloured text is read line by line (`source@name 3.7M installs`, then `└ https://skills.sh/…`). + * Every string here is another program's, or the person's, so each one is checked before it can become an argv element. + */ +import type { Outcome } from '../state' +import { jsonAfter } from './cli' +import { plain, recordOf, stringOf } from './parse' + +/** `npx -y skills`: downloads the CLI on first use, so every run here reaches the network. */ +export const SKILLS = ['npx', '-y', 'skills'] as const + +export type Scope = 'project' | 'global' + +export type InstalledSkill = { name: string; path: string; scope: Scope; agents: string[]; source?: string } +export type FoundSkill = { id: string; installs?: string; url?: string } + +/** What the skills view holds between renders: the lists, the last search, and what is running now. */ +export type SkillsState = { + installed: InstalledSkill[] | null + /** Why a list could not be read, by scope; a failing scope never blanks the other. */ + listErrors: Partial> + listedAtMs: number + isListing: boolean + /** The search field's text, and the query the shown results answer. */ + searchDraft: string + query: string + found: FoundSkill[] | null + findError: string | null + isFinding: boolean + createDraft: string + /** The change running now (its label), and the create the last Enter asked about: Enter on it again confirms. */ + busy: string | null + asked: { key: string; label: string } | null + /** How the last change went, kept for the view after the footer lets it go. */ + last: Outcome | null +} + +export const emptySkills = (): SkillsState => ({ + installed: null, + listErrors: {}, + listedAtMs: 0, + isListing: false, + searchDraft: '', + query: '', + found: null, + findError: null, + isFinding: false, + createDraft: '', + busy: null, + asked: null, + last: null, +}) + +const TYPED = /^[A-Za-z0-9@/._ -]+$/ +const SKILL_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*(\/[A-Za-z0-9._-]+)*@[A-Za-z0-9][A-Za-z0-9._:-]*$/ +const SKILL_NAME = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/ +/** A new skill's folder: `init` joins it onto the project, so no slash and no leading dot (`../x` would escape). */ +const NEW_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/ +const OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/ + +export const MAX_QUERY = 64 +export const MAX_NAME = 64 + +/** Text the person typed, trimmed, or null: empty, too long, a character outside [A-Za-z0-9@/._ -], or a leading -. */ +export function typedOf(value: string, max = MAX_QUERY): string | null { + const text = value.trim() + + return text === '' || text.length > max || !TYPED.test(text) || text.startsWith('-') ? null : text +} + +export const skillIdOf = (value: unknown): string | null => (typeof value === 'string' && value.length <= 128 && SKILL_ID.test(value) ? value : null) +export const skillNameOf = (value: unknown): string | null => (typeof value === 'string' && value.length <= 128 && SKILL_NAME.test(value) ? value : null) + +/** The name a new skill may take, or null. */ +export function newNameOf(value: string): string | null { + const text = typedOf(value, MAX_NAME) + + return text !== null && NEW_NAME.test(text) ? text : null +} + +/** + * The search field's words as `find` argv: `owner:` anywhere in it becomes `--owner `, the rest is the query + * as one element. Null when the text would not pass `typedOf`, or names no query. + */ +export function findArgv(value: string): readonly string[] | null { + const words = value.trim().split(/\s+/) + const owners = words.filter(word => word.startsWith('owner:')).map(word => word.slice(6)) + const query = typedOf(words.filter(word => !word.startsWith('owner:')).join(' ')) + const owner = owners[0] + + if (query === null || owners.length > 1 || (owner !== undefined && !OWNER.test(owner))) return null + + return [...SKILLS, 'find', query, ...(owner !== undefined ? ['--owner', owner] : [])] +} + +export const listArgv = (scope: Scope): readonly string[] => [...SKILLS, 'ls', ...(scope === 'global' ? ['-g'] : []), '--json'] +export const addArgv = (id: string, scope: Scope): readonly string[] => [...SKILLS, 'add', id, ...(scope === 'global' ? ['-g'] : []), '-y'] +export const removeArgv = (name: string, scope: Scope): readonly string[] => [...SKILLS, 'remove', name, ...(scope === 'global' ? ['-g'] : []), '-y'] +/** With the scope named, so `update` never stops at its project-or-global prompt. */ +export const updateArgv = (name: string, scope: Scope): readonly string[] => [...SKILLS, 'update', name, scope === 'global' ? '-g' : '-p', '-y'] +export const initArgv = (name: string): readonly string[] => [...SKILLS, 'init', name] + +/** `skills ls [-g] --json`: the installed skills, or null when the output is not a JSON array. */ +export function parseInstalled(stdout: string, scope: Scope): InstalledSkill[] | null { + const value = jsonAfter(stdout) + + if (!Array.isArray(value)) return null + + return value.slice(0, 200).flatMap(entry => { + const skill = recordOf(entry) + const name = stringOf(skill?.name, 128) + const path = stringOf(skill?.path, 300) + + if (skill === null || name === undefined || path === undefined) return [] + + const agents = (Array.isArray(skill.agents) ? skill.agents : []).slice(0, 20).flatMap(agent => stringOf(agent, 30) ?? []) + const source = stringOf(skill.source, 120) + + return [{ name, path, scope: skill.scope === 'global' || skill.scope === 'project' ? skill.scope : scope, agents, ...(source !== undefined && { source }) }] + }) +} + +/** + * `skills find `: each result is a line `source@name[ N installs]` followed by `└ `. Split into lines first + * (`plain` folds newlines away), then strip colour from each. A line that is not a skill id is passed over. + */ +export function parseFind(stdout: string): FoundSkill[] { + const lines = stdout.slice(0, 200_000).split('\n').map(line => plain(line, 300)) + const out: FoundSkill[] = [] + + lines.forEach((line, i) => { + const match = /^(\S+)(?:\s+([\d.]+[KM]?)\s+installs?)?$/.exec(line) + const id = skillIdOf(match?.[1]) + + if (match === null || id === null || out.length >= 30) return + + const next = /^└\s*(https:\/\/\S+)$/.exec(lines[i + 1] ?? '')?.[1] + + out.push({ id, ...(match[2] !== undefined && { installs: match[2] }), ...(next !== undefined && { url: next }) }) + }) + + return out +} + +/** The skill's own name in an `owner/repo@skill` id: what `ls` lists once it is added. */ +export const nameInId = (id: string): string => id.slice(id.lastIndexOf('@') + 1) diff --git a/plugins/ruflo-console/hooks/palette.ts b/plugins/ruflo-console/hooks/palette.ts index 5b38c583a3..9d86f1d9ef 100644 --- a/plugins/ruflo-console/hooks/palette.ts +++ b/plugins/ruflo-console/hooks/palette.ts @@ -95,7 +95,7 @@ export function paletteEntries(state: State, nowMs: number): PaletteEntry[] { add('store', 'memory', 'store : save a note in memory namespace console', { kind: 'text', keyword: 'store', make: text => memoryStore(text, nowMs) }) add('search', 'memory', 'search : semantic memory search', { kind: 'text', keyword: 'search', make: memorySearch }) - for (const view of VIEWS) add(`view-${view.id}`, 'views', `go to ${view.label} (${view.key})`, { kind: 'view', view: view.id }) + for (const view of VIEWS) add(`view-${view.id}`, 'views', `go to ${view.label}${view.key === '' ? '' : ` (${view.key})`}`, { kind: 'view', view: view.id }) add('refresh', 'console', 'refresh now', { kind: 'command', name: 'refresh' }) add('help', 'console', 'help: keys and commands', { kind: 'command', name: 'help' }) diff --git a/plugins/ruflo-console/hooks/skills.ts b/plugins/ruflo-console/hooks/skills.ts new file mode 100644 index 0000000000..5750cbba4d --- /dev/null +++ b/plugins/ruflo-console/hooks/skills.ts @@ -0,0 +1,239 @@ +/** + * The skills view's work: list what is installed (project and global), search skills.sh, and the four changes. Reads + * run at once, but only when the person acts (opening the view, Enter in the search field, refresh), since `npx -y + * skills` downloads the CLI and `find` asks skills.sh. Changes (add, remove, update, init) write to the agents' skill + * folders or the project, so each is asked first: the confirm row prints its exact argv, and after it runs the + * installed lists are read again to say whether it took. Every argv is fixed, with no shell; nothing here writes a file. + */ +import type { ActionSpec } from './actions' +import { addArgv, findArgv, initArgv, listArgv, nameInId, newNameOf, parseFind, parseInstalled, removeArgv, skillIdOf, skillNameOf, updateArgv, type FoundSkill, type InstalledSkill, type Scope } from './data/skills' +import { plain } from './data/parse' +import type { Host } from './host' +import { outputLines } from './ops' +import type { Runner } from './runner' +import type { State } from './state' + +/** A read may first download the CLI; `add` clones a repository. */ +const READ_TIMEOUT_MS = 90_000 +const CHANGE_TIMEOUT_MS = 180_000 + +const firstLine = (text: string): string => plain(text.split('\n').find(line => line.trim() !== '') ?? '', 120) + +const listing = new WeakMap>() + +async function listOnce(state: State, host: Host): Promise { + const skills = state.skills + + skills.isListing = true + host.invalidate() + + try { + const lists = await Promise.all( + (['project', 'global'] as const).map(async scope => { + try { + const result = await host.run(listArgv(scope), READ_TIMEOUT_MS) + const parsed = result.exitCode === 0 ? parseInstalled(result.stdout, scope) : null + + if (parsed === null) skills.listErrors[scope] = result.exitCode !== 0 ? `exit ${result.exitCode}: ${firstLine(result.stderr) || 'no message'}` : 'no JSON list in the output' + else delete skills.listErrors[scope] + + return parsed ?? [] + } catch (error) { + skills.listErrors[scope] = plain(error instanceof Error ? error.message : String(error), 120) || 'refused' + + return [] + } + }), + ) + + skills.installed = lists.flat() + skills.listedAtMs = Date.now() + } finally { + skills.isListing = false + host.invalidate() + } +} + +/** Reads both installed lists; a list already running is joined, unless `isFresh` asks for one that starts after it. */ +export function listSkills(state: State, host: Host, isFresh = false): Promise { + const held = listing.get(state) + + if (held !== undefined && !isFresh) return held + + const run = (held ?? Promise.resolve()).then(() => listOnce(state, host)).finally(() => { + if (listing.get(state) === run) listing.delete(state) + }) + + listing.set(state, run) + + return run +} + +/** Asks skills.sh for the field's text; answers why not when it cannot (bad text, a search already out). */ +export function findSkills(state: State, host: Host, text: string): string | null { + const skills = state.skills + const argv = findArgv(text) + + if (argv === null) return 'search: 1-64 characters of letters, digits, @ / . _ - and spaces, not starting with - (owner: narrows it)' + if (skills.isFinding) return 'a search is still running' + + skills.query = text.trim() + skills.isFinding = true + skills.findError = null + host.invalidate() + + void host + .run(argv, READ_TIMEOUT_MS) + .then(result => { + skills.found = parseFind(result.stdout) + skills.findError = result.exitCode !== 0 ? `exit ${result.exitCode}: ${firstLine(result.stderr) || firstLine(result.stdout) || 'no message'}` : null + }) + .catch((error: unknown) => { + skills.found = null + skills.findError = plain(error instanceof Error ? error.message : String(error), 120) || 'refused' + }) + .finally(() => { + skills.isFinding = false + host.invalidate() + }) + + return null +} + +/** + * One confirm-gated change: `shows` puts its argv on the confirm row; once confirmed, `run` runs it, reads the lists + * again, and says how it went (on disk: the lists show the change). + */ +function change(state: State, host: Host, label: string, argv: readonly string[], expect: string, verify?: (installed: InstalledSkill[]) => boolean): ActionSpec { + return { + label, + args: argv, + shows: argv.join(' '), + expect, + run: async () => { + const skills = state.skills + + if (skills.busy !== null) { + state.outcome = { label, ok: false, verified: 'n/a', detail: `${skills.busy} is still running: ask again when it ends`, atMs: Date.now() } + host.invalidate() + + return + } + + skills.busy = label + host.invalidate() + + try { + const result = await host.run(argv, CHANGE_TIMEOUT_MS) + const ok = result.exitCode === 0 + + await listSkills(state, host, true) + + const verified = !ok || verify === undefined || state.skills.installed === null ? 'n/a' : verify(state.skills.installed) ? 'yes' : 'no' + + state.outcome = { + label, + ok: ok && verified !== 'no', + verified, + detail: ok ? `skills answered ok; expected ${expect}` : `exit ${result.exitCode}: ${firstLine(result.stderr) || firstLine(result.stdout) || 'no message'}`, + atMs: Date.now(), + lines: outputLines(`${result.stdout}\n${result.stderr}`, 6), + } + } catch (error) { + state.outcome = { label, ok: false, verified: 'n/a', detail: plain(error instanceof Error ? error.message : String(error), 160) || 'refused', atMs: Date.now() } + } finally { + skills.busy = null + skills.last = state.outcome + host.invalidate() + } + }, + } +} + +const isIn = (name: string, scope: Scope) => (installed: InstalledSkill[]) => installed.some(skill => skill.name === name && skill.scope === scope) + +export function addSpec(state: State, host: Host, found: FoundSkill, scope: Scope): ActionSpec | null { + const id = skillIdOf(found.id) + + return id === null ? null : change(state, host, `add skill ${id}${scope === 'global' ? ' globally' : ' to this project'}`, addArgv(id, scope), `${nameInId(id)} listed as ${scope}`, isIn(nameInId(id), scope)) +} + +export function removeSpec(state: State, host: Host, skill: InstalledSkill): ActionSpec | null { + const name = skillNameOf(skill.name) + + return name === null ? null : change(state, host, `remove ${skill.scope} skill ${name}`, removeArgv(name, skill.scope), `${name} gone from the ${skill.scope} list`, installed => !isIn(name, skill.scope)(installed)) +} + +export function updateSpec(state: State, host: Host, skill: InstalledSkill): ActionSpec | null { + const name = skillNameOf(skill.name) + + return name === null ? null : change(state, host, `update ${skill.scope} skill ${name}`, updateArgv(name, skill.scope), 'the newest version from its source') +} + +/** `init` writes `/SKILL.md` in the project, which `ls` does not list: nothing to check it against. */ +export function initSpec(state: State, host: Host, name: string): ActionSpec | null { + const safe = newNameOf(name) + + return safe === null ? null : change(state, host, `create skill ${safe}`, initArgv(safe), `${safe}/SKILL.md in this project`) +} + +/** What the AI terminal is loaded with for ▸ edit: the skill named, and where it is; claude makes the change. */ +export const editPrompt = (skill: InstalledSkill): string => `Edit the skill ${plain(skill.name, 128)} at ${plain(skill.path, 300)}: ` + +const NAME_RULE = 'a new skill name: letters, digits, . _ - (no slash, not starting with . or -), at most 64' + +export type SkillActions = { + list: () => void + searchDraft: (text: string) => void + search: (text: string) => void + createDraft: (text: string) => void + /** Enter asks; Enter again on the same name (or an emptied field) confirms, as the field keeps the keys. */ + create: (text: string) => void + add: (found: FoundSkill, scope: Scope) => void + remove: (skill: InstalledSkill) => void + update: (skill: InstalledSkill) => void + edit: (skill: InstalledSkill) => void +} + +export function skillActions(state: State, host: Host, runner: Runner, load: (text: string) => void): SkillActions { + const skills = state.skills + const nameless = (what: string) => `that skill's name cannot be passed to skills ${what}` + + return { + list: () => void listSkills(state, host, true), + searchDraft: text => { + skills.searchDraft = text + }, + search: text => { + skills.searchDraft = text + const why = findSkills(state, host, text) + + if (why !== null) runner.ask(null, why) + }, + createDraft: text => { + skills.createDraft = text + }, + create: text => { + const asked = skills.asked + const name = newNameOf(text) + + if (asked !== null && (asked.key === text.trim() || text.trim() === '') && state.pending?.label === asked.label) { + skills.asked = null + skills.createDraft = '' + void runner.confirm() + + return + } + + const spec = name === null ? null : initSpec(state, host, name) + + skills.createDraft = text + runner.ask(spec, NAME_RULE) + skills.asked = spec !== null && name !== null ? { key: name, label: spec.label } : null + }, + add: (found, scope) => runner.ask(addSpec(state, host, found, scope), 'that result is not an owner/repo@skill id'), + remove: skill => runner.ask(removeSpec(state, host, skill), nameless('remove')), + update: skill => runner.ask(updateSpec(state, host, skill), nameless('update')), + edit: skill => load(editPrompt(skill)), + } +} diff --git a/plugins/ruflo-console/hooks/state.ts b/plugins/ruflo-console/hooks/state.ts index b938cc908c..9405fbc7eb 100644 --- a/plugins/ruflo-console/hooks/state.ts +++ b/plugins/ruflo-console/hooks/state.ts @@ -3,13 +3,14 @@ import type { PluginOptions, Timer } from 'claude-code' import type { ProbeResult } from './data/cli' import type { ConsoleEvent } from './data/events' import type { ReadCache } from './data/files' +import { emptySkills, type SkillsState } from './data/skills' import type { Snapshot } from './data/snapshot' import type { RufloRoute, RufloSnapshot } from '../types' export const PLUGIN_NAME = 'ruflo-console' export const PANE_ID = 'ruflo-console' -export type ViewId = 'menu' | 'overview' | 'swarm' | 'claims' | 'federation' | 'plugins' | 'learning' | 'metaharness' | 'memory' | 'cost' | 'timeline' | 'approvals' | 'events' | 'missions' | 'xruv' | 'terminal' | 'agent' +export type ViewId = 'menu' | 'overview' | 'swarm' | 'claims' | 'federation' | 'plugins' | 'learning' | 'metaharness' | 'memory' | 'cost' | 'timeline' | 'approvals' | 'events' | 'missions' | 'xruv' | 'terminal' | 'skills' | 'agent' /** * The views in tab order, each with its hotkey and the inline height it asks for. Digits are the first nine; the three @@ -37,6 +38,8 @@ export const VIEWS: readonly { id: ViewId; key: string; label: string; short: st { id: 'missions', key: 'm', label: 'Missions', short: 'Msn', icon: '🎯', blurb: 'ADR-406 missions: the plan, task dependencies, acceptance and budget (observe only)', rows: 26 }, { id: 'xruv', key: 'w', label: 'x.ruv.io', short: 'XRV', icon: '🛸', blurb: 'the open agent federation: what it offers, how to join, its channels and who is on', rows: 34 }, { id: 'terminal', key: 'i', label: 'Terminal', short: 'Trm', icon: '💻', blurb: 'an AI terminal: codex, claude or both, each a session that remembers the conversation, streamed live', rows: 32 }, + // No hotkey: every digit and letter is taken. The tab, the menu prompt and /ruflo skills reach it by name. + { id: 'skills', key: '', label: 'Skills', short: 'Skl', icon: '🧰', blurb: 'agent skills (npx skills, skills.sh): what is installed here and globally, search, add, update, remove, create', rows: 34 }, ] export const AGENT_VIEW = { id: 'agent' as const, rows: 28 } @@ -47,7 +50,7 @@ export const rowsOf = (view: ViewId): number => (view === 'agent' ? AGENT_VIEW.r export const viewOf = (word: string): ViewId | null => { const lower = word.trim().toLowerCase() - return VIEWS.find(view => view.id === lower || view.key === lower || view.label.toLowerCase() === lower || (lower.length >= 3 && view.id.startsWith(lower)))?.id ?? null + return VIEWS.find(view => view.id === lower || (view.key !== '' && view.key === lower) || view.label.toLowerCase() === lower || (lower.length >= 3 && view.id.startsWith(lower)))?.id ?? null } /** @@ -201,6 +204,8 @@ export type State = { /** The text the last Enter asked about: Enter on the same text again confirms it. */ asked: { key: string; label: string } | null } + /** The skills view: installed skills, the last search, and the change running now. */ + skills: SkillsState timers: Map stats: { renders: number[]; refreshes: number[]; frames: number[] } } @@ -243,6 +248,7 @@ export function newState(raw: PluginOptions | undefined): State { isRefreshing: false, barDrawnAtMs: 0, terminal: { harness: 'codex', draft: '', lines: [], runs: new Map(), sessions: {}, isLive: { codex: false, claude: false }, turns: { codex: 0, claude: 0 }, costUsd: 0, asked: null }, + skills: emptySkills(), timers: new Map(), stats: { renders: [], refreshes: [], frames: [] }, } diff --git a/plugins/ruflo-console/hooks/views/common.ts b/plugins/ruflo-console/hooks/views/common.ts index b1b063e35b..151029b3aa 100644 --- a/plugins/ruflo-console/hooks/views/common.ts +++ b/plugins/ruflo-console/hooks/views/common.ts @@ -7,6 +7,7 @@ import type { Elements, RenderChildren, RenderElement } from 'claude-code' import type { ProbeResult } from '../data/cli' import type { Grid } from '../gfx/raster' +import type { SkillActions } from '../skills' import type { HarnessId, State, ViewId } from '../state' export type Kit = Pick & { Raster?: Elements['terminal']['Raster']; Input?: Elements['terminal']['Input'] } @@ -41,6 +42,8 @@ export type Actions = { /** The main menu's prompt: a key or a name takes the person to that area. */ menu: (text: string) => void term: { harness: (id: HarnessId) => void; draft: (text: string) => void; submit: (text: string) => void; stop: () => void; fresh: () => void; clear: () => void; load: (id: HarnessId, text: string) => void } + /** The skills view: list, search, and the confirm-gated add, remove, update and create; edit loads the terminal. */ + skills: SkillActions } export type Ctx = { diff --git a/plugins/ruflo-console/hooks/views/pane.ts b/plugins/ruflo-console/hooks/views/pane.ts index c6f33fdf4e..287fedb790 100644 --- a/plugins/ruflo-console/hooks/views/pane.ts +++ b/plugins/ruflo-console/hooks/views/pane.ts @@ -21,6 +21,7 @@ import { missionsView } from './missions' import { overviewView } from './overview' import { paletteView } from './palette' import { pluginsView } from './plugins' +import { skillsView } from './skills' import { swarmView } from './swarm' import { terminalView } from './terminal' import { xruvView } from './xruv' @@ -46,6 +47,7 @@ const BODIES: Record RenderElement> = { missions: missionsView, xruv: xruvView, terminal: terminalView, + skills: skillsView, agent: agentView, } @@ -69,11 +71,13 @@ function tabs(ctx: Ctx): RenderElement { // A Button cannot be styled, so the current tab is Text: its key is not needed, the view is already open // (from a drill-down, b goes back). // BBS: the current tab is framed like a menu pick, [2: 🐝 SWARM]; the name always shows there, in capitals. - const current = isBbs() ? `[${view.key}: ${view.icon}${withNames || view.label.length <= 6 ? ` ${view.label.toUpperCase()}` : ''}]` : `${view.key}: ${words}` + // A view with no hotkey (key '') has no key to show: [🧰 SKILLS], and its tab is pressed, not typed. + const prefix = view.key === '' ? '' : `${view.key}: ` + const current = isBbs() ? `[${prefix}${view.icon}${withNames || view.label.length <= 6 ? ` ${view.label.toUpperCase()}` : ''}]` : `${prefix}${words}` if (isCurrent) return ctx.kit.Box({ key: `tab-${view.id}`, children: [ctx.kit.Text({ bold: true, color: THEME.head, wrap: 'truncate-end', children: current })] }) - return ctx.kit.Button({ key: `tab-${view.id}`, label: words, hotkey: view.key, plain: true, dimColor: true, onPress: () => ctx.act.view(view.id) }) + return ctx.kit.Button({ key: `tab-${view.id}`, label: words, ...(view.key !== '' && { hotkey: view.key }), plain: true, dimColor: true, onPress: () => ctx.act.view(view.id) }) } const line = (views: readonly (typeof VIEWS)[number][], key: string) => ctx.kit.Box({ flexDirection: 'row', gap: 1, key, children: views.map(tab) }) diff --git a/plugins/ruflo-console/hooks/views/skills.ts b/plugins/ruflo-console/hooks/views/skills.ts new file mode 100644 index 0000000000..278c03b60b --- /dev/null +++ b/plugins/ruflo-console/hooks/views/skills.ts @@ -0,0 +1,133 @@ +import type { RenderElement } from 'claude-code' + +import type { FoundSkill, InstalledSkill } from '../data/skills' +import { ago, clip, col, row, rule, text, THEME, type Ctx } from './common' + +const SHOWN = 10 + +/** One dotted-leader row, as the x.ruv.io board lists its menu: the name, what it is, then its ▸ actions. */ +function leader(ctx: Ctx, key: string, name: string, about: string, actions: readonly { key: string; label: string; onPress: () => void }[], color = THEME.head): RenderElement { + const lead = Math.max(18, Math.min(34, ctx.columns - 56)) + + return row( + ctx, + [ + ctx.kit.Text({ bold: true, color, children: clip(` ${name} `, lead).padEnd(lead, '.') }), + ctx.kit.Text({ color: THEME.info, wrap: 'truncate-end', children: clip(` ${about}`, Math.max(4, ctx.columns - lead - actions.length * 11)) }), + ...actions.map(action => ctx.kit.Button({ key: action.key, label: ` ▸ ${action.label}`, plain: true, dimColor: true, onPress: action.onPress })), + ], + `${key}-row`, + ) +} + +function installedRows(ctx: Ctx): RenderElement[] { + const { state, nowMs } = ctx + const skills = state.skills + const installed = skills.installed ?? [] + const count = (scope: InstalledSkill['scope']) => installed.filter(skill => skill.scope === scope).length + const right = skills.isListing ? 'listing…' : skills.installed === null ? 'not listed yet' : `${count('project')} project · ${count('global')} global · ${ago(skills.listedAtMs, nowMs)}` + const rows: RenderElement[] = [rule(ctx, 'Installed', right)] + + for (const [scope, error] of Object.entries(skills.listErrors)) rows.push(text(ctx, ` ${scope} list unreadable: ${error}`, { color: THEME.warn })) + + if (skills.installed === null) { + rows.push(text(ctx, skills.isListing ? ' asking npx -y skills ls --json (project) and ls -g --json (global)… the first run downloads the CLI' : ' not listed yet: r lists them (npx -y skills ls --json)', { dimColor: true })) + } else if (installed.length === 0 && Object.keys(skills.listErrors).length === 0) { + rows.push(text(ctx, ' no skills in this project or globally: search below and ▸ add one', { dimColor: true })) + } + + installed.slice(0, SHOWN).forEach((skill, i) => { + rows.push( + leader(ctx, `sk-in-${i}`, skill.name, `${skill.scope === 'global' ? 'global ' : 'project'} · ${skill.agents.length > 0 ? skill.agents.join(', ') : 'no agent links'}`, [ + { key: `sk-update-${i}`, label: 'update', onPress: () => ctx.act.skills.update(skill) }, + { key: `sk-remove-${i}`, label: 'remove', onPress: () => ctx.act.skills.remove(skill) }, + { key: `sk-edit-${i}`, label: 'edit', onPress: () => ctx.act.skills.edit(skill) }, + ], skill.scope === 'global' ? THEME.ok : THEME.head), + ) + rows.push(text(ctx, ` ${skill.path}${skill.source !== undefined ? ` · from ${skill.source}` : ''}`, { dimColor: true })) + }) + + if (installed.length > SHOWN) rows.push(text(ctx, ` +${installed.length - SHOWN} more: npx skills ls shows them all`, { dimColor: true })) + + return rows +} + +function searchRows(ctx: Ctx): RenderElement[] { + const skills = ctx.state.skills + const rows: RenderElement[] = [rule(ctx, 'Search', 'skills.sh · npx skills find')] + + if (ctx.kit.Input !== undefined) { + rows.push( + ctx.kit.Input({ + key: 'skills-search', + label: 'find', + placeholder: 'a word or two: react, testing, owner:vercel-labs deploy …', + value: skills.searchDraft, + submitLabel: 'search', + onInput: value => ctx.act.skills.searchDraft(value), + onSubmit: value => ctx.act.skills.search(value), + }), + ) + } else { + rows.push(text(ctx, ' this surface has no text field: run npx skills find instead', { dimColor: true })) + } + + if (skills.isFinding) rows.push(text(ctx, ` asking skills.sh for "${skills.query}"…`, { dimColor: true })) + else if (skills.findError !== null) rows.push(text(ctx, ` search failed: ${skills.findError}`, { color: THEME.warn })) + else if (skills.found !== null && skills.found.length === 0) rows.push(text(ctx, ` no skills found for "${skills.query}"`, { dimColor: true })) + else if (skills.found === null) rows.push(text(ctx, ' Enter searches skills.sh (it is on the network, so nothing is asked until you do)', { dimColor: true })) + + ;(skills.found ?? []).slice(0, SHOWN).forEach((found: FoundSkill, i) => { + rows.push( + leader(ctx, `sk-found-${i}`, found.id, found.installs !== undefined ? `${found.installs} installs` : 'installs n/a', [ + { key: `sk-add-${i}`, label: 'add', onPress: () => ctx.act.skills.add(found, 'project') }, + { key: `sk-addg-${i}`, label: 'add -g', onPress: () => ctx.act.skills.add(found, 'global') }, + ]), + ) + }) + + if ((skills.found?.length ?? 0) > 0) rows.push(text(ctx, ' ▸ add installs into this project, ▸ add -g for every project; each asks first (y/n)', { dimColor: true })) + + return rows +} + +function createRows(ctx: Ctx): RenderElement[] { + const skills = ctx.state.skills + const rows: RenderElement[] = [rule(ctx, 'Create', 'npx skills init · here')] + + if (ctx.kit.Input !== undefined) { + rows.push( + ctx.kit.Input({ + key: 'skills-create', + label: 'name', + placeholder: 'my-skill: makes my-skill/SKILL.md in this project', + value: skills.createDraft, + submitLabel: 'create', + onInput: value => ctx.act.skills.createDraft(value), + onSubmit: value => ctx.act.skills.create(value), + }), + ) + } + + rows.push(text(ctx, ' Enter shows the command, Enter again (or y) runs it · ▸ edit opens a skill in the AI terminal with claude', { dimColor: true })) + + return rows +} + +/** + * Agent skills through the `skills` CLI (vercel-labs, skills.sh): what is installed in this project and globally, a + * search of skills.sh, and a field to start a new one. Every change is asked first with its exact argv; ▸ edit puts a + * prompt in the AI terminal rather than writing anything here. + */ +export function skillsView(ctx: Ctx): RenderElement { + const { state, nowMs } = ctx + const skills = state.skills + const status: RenderElement[] = [] + + if (skills.busy !== null) status.push(text(ctx, ` running: ${skills.busy}…`, { bold: true, color: THEME.warn })) + else if (skills.last !== null) { + status.push(text(ctx, ` ${skills.last.ok ? '✓' : '✗'} ${skills.last.label}${skills.last.verified === 'yes' ? ' · listed' : skills.last.verified === 'no' ? ' · not listed' : ''}: ${skills.last.detail} (${ago(skills.last.atMs, nowMs)})`, { color: skills.last.ok ? THEME.ok : THEME.bad })) + } + + return col(ctx, [...status, ...installedRows(ctx), ...searchRows(ctx), ...createRows(ctx)], 'skills') +} diff --git a/plugins/ruflo-console/tests/behaviour.test.ts b/plugins/ruflo-console/tests/behaviour.test.ts index 1dc294cd03..91a1c780f1 100644 --- a/plugins/ruflo-console/tests/behaviour.test.ts +++ b/plugins/ruflo-console/tests/behaviour.test.ts @@ -149,7 +149,8 @@ describe('behaviour', () => { expect(elementsOf(tree, 'Raster').length === 0).toBe(isNarrow) expect(elementsOf(tree, 'Button').map(keyOf).includes('claim')).toBe(!isNarrow) - if (isNarrow) expect(textOf(tree)).toContain('4/16 Claims') + // The count is VIEWS.length, which grows with each view: hold the position and the name, not the total. + if (isNarrow) expect(textOf(tree)).toMatch(/4\/\d+ Claims/) await pane.unmount() } }) diff --git a/plugins/ruflo-console/tests/fixtures/skills.ts b/plugins/ruflo-console/tests/fixtures/skills.ts new file mode 100644 index 0000000000..346336e54f --- /dev/null +++ b/plugins/ruflo-console/tests/fixtures/skills.ts @@ -0,0 +1,32 @@ +/** `npx skills find react` as skills 1.7.0 printed it on this machine: 256-colour names, cyan counts, a └ url line. */ +export const FIND_OUT = [ + '', + '\u001b[38;5;102mInstall with\u001b[0m npx skills add ', + '', + '\u001b[38;5;145mmattpocock/skills@tdd\u001b[0m \u001b[36m1M installs\u001b[0m', + '\u001b[38;5;102m└ https://skills.sh/mattpocock/skills/tdd\u001b[0m', + '', + '\u001b[38;5;145mvercel-labs/agent-skills@vercel-react-best-practices\u001b[0m \u001b[36m764.8K installs\u001b[0m', + '\u001b[38;5;102m└ https://skills.sh/vercel-labs/agent-skills/vercel-react-best-practices\u001b[0m', + '', + '\u001b[38;5;145mopen.feishu.cn@lark-event\u001b[0m \u001b[36m740.2K installs\u001b[0m', + '\u001b[38;5;102m└ https://skills.sh/open.feishu.cn/lark-event\u001b[0m', + '', + '\u001b[38;5;145msomeone/repo@fresh\u001b[0m', + '\u001b[38;5;102m└ https://skills.sh/someone/repo/fresh\u001b[0m', + '', +].join('\n') + +/** `npx skills ls -g --json`, the shape runList prints (one entry from this machine, one made up). */ +export const LS_GLOBAL = JSON.stringify([ + { + name: 'faceless-explainer', + path: '/home/dev/.agents/skills/faceless-explainer', + scope: 'global', + agents: ['Claude Code', 'Codex'], + source: 'heygen-com/hyperframes', + sourceUrl: 'https://github.com/heygen-com/hyperframes.git', + sourceType: 'github', + }, + { name: 'tdd', path: '/home/dev/.agents/skills/tdd', scope: 'global', agents: [], source: null, sourceUrl: null, sourceType: null }, +]) diff --git a/plugins/ruflo-console/tests/skills.spec.ts b/plugins/ruflo-console/tests/skills.spec.ts new file mode 100644 index 0000000000..ad105783f6 --- /dev/null +++ b/plugins/ruflo-console/tests/skills.spec.ts @@ -0,0 +1,191 @@ +/** + * The skills view's pure parts under vitest: reading `skills find` text and `skills ls --json`, the argv each action + * runs, what the search and name fields refuse, and a change run end to end on a fake Host (asked, confirmed, run, the + * lists read again, the outcome checked against them). Nothing here runs the real CLI. + */ +import { describe, expect, it } from 'vitest' + +import { addArgv, findArgv, initArgv, listArgv, newNameOf, parseFind, parseInstalled, removeArgv, skillIdOf, skillNameOf, typedOf, updateArgv } from '../hooks/data/skills' +import type { Host } from '../hooks/host' +import { createRunner } from '../hooks/runner' +import { addSpec, editPrompt, findSkills, initSpec, listSkills, removeSpec, skillActions } from '../hooks/skills' +import { newState } from '../hooks/state' +import { FIND_OUT, LS_GLOBAL } from './fixtures/skills' + +describe('reading the skills CLI', () => { + it('find: each result line with its install count and url, colour gone; the header and blanks are passed over', () => { + expect(parseFind(FIND_OUT)).toEqual([ + { id: 'mattpocock/skills@tdd', installs: '1M', url: 'https://skills.sh/mattpocock/skills/tdd' }, + { id: 'vercel-labs/agent-skills@vercel-react-best-practices', installs: '764.8K', url: 'https://skills.sh/vercel-labs/agent-skills/vercel-react-best-practices' }, + { id: 'open.feishu.cn@lark-event', installs: '740.2K', url: 'https://skills.sh/open.feishu.cn/lark-event' }, + { id: 'someone/repo@fresh', url: 'https://skills.sh/someone/repo/fresh' }, + ]) + }) + + it('find: nothing found, an error, or an id that could be read as a flag gives no results', () => { + expect(parseFind('\u001b[38;5;102mNo skills found for "zzz"\u001b[0m\n')).toEqual([]) + expect(parseFind('-g/x@y 3 installs\n../x@y\nowner/repo@sk;rm 1 install\n')).toEqual([]) + expect(parseFind('')).toEqual([]) + }) + + it('ls --json: name, path, scope and agents; an empty list is empty, an object or text is unreadable', () => { + expect(parseInstalled(LS_GLOBAL, 'global')).toEqual([ + { name: 'faceless-explainer', path: '/home/dev/.agents/skills/faceless-explainer', scope: 'global', agents: ['Claude Code', 'Codex'], source: 'heygen-com/hyperframes' }, + { name: 'tdd', path: '/home/dev/.agents/skills/tdd', scope: 'global', agents: [] }, + ]) + expect(parseInstalled('[]\n', 'project')).toEqual([]) + expect(parseInstalled('{"success": true}', 'project')).toBeNull() + expect(parseInstalled('No project skills found.', 'project')).toBeNull() + // A record without a name or a path is left out; an unknown scope takes the list's own. + expect(parseInstalled(JSON.stringify([{ name: 'a' }, { path: '/b' }, { name: 'c', path: '/c', scope: 'elsewhere', agents: 'x' }]), 'project')).toEqual([{ name: 'c', path: '/c', scope: 'project', agents: [] }]) + }) +}) + +describe('argv and validation', () => { + it('every action is a fixed npx -y skills argv, its scope named', () => { + expect(listArgv('project')).toEqual(['npx', '-y', 'skills', 'ls', '--json']) + expect(listArgv('global')).toEqual(['npx', '-y', 'skills', 'ls', '-g', '--json']) + expect(addArgv('vercel-labs/skills@find-skills', 'project')).toEqual(['npx', '-y', 'skills', 'add', 'vercel-labs/skills@find-skills', '-y']) + expect(addArgv('vercel-labs/skills@find-skills', 'global')).toEqual(['npx', '-y', 'skills', 'add', 'vercel-labs/skills@find-skills', '-g', '-y']) + expect(removeArgv('tdd', 'global')).toEqual(['npx', '-y', 'skills', 'remove', 'tdd', '-g', '-y']) + expect(updateArgv('tdd', 'project')).toEqual(['npx', '-y', 'skills', 'update', 'tdd', '-p', '-y']) + expect(updateArgv('tdd', 'global')).toEqual(['npx', '-y', 'skills', 'update', 'tdd', '-g', '-y']) + expect(initArgv('my-skill')).toEqual(['npx', '-y', 'skills', 'init', 'my-skill']) + }) + + it('search: the text is one argv element; owner: becomes --owner; flags, odd characters and long text are refused', () => { + expect(findArgv(' react hooks ')).toEqual(['npx', '-y', 'skills', 'find', 'react hooks']) + expect(findArgv('owner:vercel-labs deploy')).toEqual(['npx', '-y', 'skills', 'find', 'deploy', '--owner', 'vercel-labs']) + expect(findArgv('-g')).toBeNull() + expect(findArgv('--owner x')).toBeNull() + expect(findArgv('react; rm -rf ~')).toBeNull() + expect(findArgv('$(whoami)')).toBeNull() + expect(findArgv('a'.repeat(65))).toBeNull() + expect(findArgv('owner:-x react')).toBeNull() + expect(findArgv('owner:a owner:b react')).toBeNull() + expect(findArgv('owner:vercel-labs')).toBeNull() + expect(findArgv('')).toBeNull() + }) + + it('typed text keeps to [A-Za-z0-9@/._ -], no leading -, within its cap', () => { + expect(typedOf(' a/b@c_d.e f-g ')).toBe('a/b@c_d.e f-g') + expect(typedOf('-a')).toBeNull() + expect(typedOf('a\u001b[31m')).toBeNull() + expect(typedOf('a\nb')).toBeNull() + expect(typedOf('x'.repeat(10), 9)).toBeNull() + }) + + it('a new skill name cannot leave the project: no slash, no leading dot or dash', () => { + expect(newNameOf('my-skill')).toBe('my-skill') + expect(newNameOf('My.Skill_2')).toBe('My.Skill_2') + expect(newNameOf('../x')).toBeNull() + expect(newNameOf('a/b')).toBeNull() + expect(newNameOf('.hidden')).toBeNull() + expect(newNameOf('-y')).toBeNull() + expect(newNameOf('two words')).toBeNull() + expect(newNameOf('x'.repeat(65))).toBeNull() + }) + + it('ids and names from the CLI pass only in their own shape', () => { + expect(skillIdOf('owner/repo@skill')).toBe('owner/repo@skill') + expect(skillIdOf('open.feishu.cn@lark-event')).toBe('open.feishu.cn@lark-event') + expect(skillIdOf('owner/repo')).toBeNull() + expect(skillIdOf('-g@x')).toBeNull() + expect(skillIdOf('a@b c')).toBeNull() + expect(skillNameOf('tdd')).toBe('tdd') + expect(skillNameOf('-g')).toBeNull() + expect(skillNameOf('a b')).toBeNull() + }) +}) + +/** A Host whose `run` answers by argv and records each call; a Runner over it with nothing else wired. */ +function fake(answer: (argv: readonly string[]) => { exitCode: number; stdout: string; stderr: string }) { + const runs: string[][] = [] + const host = { + run: async (argv: readonly string[]) => { + runs.push([...argv]) + + return { ...answer(argv), isStdoutTruncated: false, isStderrTruncated: false } + }, + invalidate: () => undefined, + } as unknown as Host + const state = newState({}) + const runner = createRunner(state, host, { freshRead: async () => undefined, setView: () => undefined, drill: () => undefined, command: () => undefined }) + + return { host, state, runner, runs } +} + +const settle = () => new Promise(resolve => setTimeout(resolve, 5)) + +describe('the skills actions', () => { + it('listing asks both scopes; a failing one says why and does not blank the other', async () => { + const { host, state, runs } = fake(argv => (argv.includes('-g') ? { exitCode: 0, stdout: LS_GLOBAL, stderr: '' } : { exitCode: 1, stdout: '', stderr: 'boom\n' })) + + await listSkills(state, host) + + expect(runs).toEqual([listArgv('project'), listArgv('global')]) + expect(state.skills.installed?.map(skill => skill.name)).toEqual(['faceless-explainer', 'tdd']) + expect(state.skills.listErrors).toEqual({ project: 'exit 1: boom' }) + }) + + it('a search runs find with the typed text and lists what came back; bad text runs nothing', async () => { + const { host, state, runs } = fake(() => ({ exitCode: 0, stdout: FIND_OUT, stderr: '' })) + + expect(findSkills(state, host, '--help')).toMatch(/not starting with -/) + expect(runs).toEqual([]) + expect(findSkills(state, host, 'react')).toBeNull() + await settle() + expect(runs).toEqual([['npx', '-y', 'skills', 'find', 'react']]) + expect(state.skills.found?.length).toBe(4) + }) + + it('add is asked with its exact argv, runs only on confirm, then reads the lists to say whether it took', async () => { + let isAdded = false + const { host, state, runner, runs } = fake(argv => { + if (argv[3] === 'add') isAdded = true + + return argv[3] === 'ls' ? { exitCode: 0, stdout: argv.includes('-g') ? '[]' : JSON.stringify(isAdded ? [{ name: 'tdd', path: '/work/.agents/skills/tdd', scope: 'project', agents: ['Claude Code'] }] : []), stderr: '' } : { exitCode: 0, stdout: 'Installed tdd\n', stderr: '' } + }) + const spec = addSpec(state, host, { id: 'mattpocock/skills@tdd' }, 'project') + + runner.ask(spec, '') + expect(state.pending?.shows).toBe('npx -y skills add mattpocock/skills@tdd -y') + expect(runs).toEqual([]) + + await runner.confirm() + for (let i = 0; i < 20 && state.skills.busy !== null; i++) await settle() + await settle() + + expect(runs[0]).toEqual(['npx', '-y', 'skills', 'add', 'mattpocock/skills@tdd', '-y']) + expect(runs.slice(1).map(argv => argv[3])).toEqual(['ls', 'ls']) + expect(state.outcome).toMatchObject({ label: 'add skill mattpocock/skills@tdd to this project', ok: true, verified: 'yes' }) + expect(state.skills.last?.label).toBe(state.outcome?.label) + }) + + it('remove and create refuse what they cannot pass; create asks once, Enter again on the name confirms', async () => { + const { host, state, runner, runs } = fake(() => ({ exitCode: 0, stdout: '[]', stderr: '' })) + const loaded: string[] = [] + const act = skillActions(state, host, runner, text => void loaded.push(text)) + + expect(removeSpec(state, host, { name: '-rf', path: '/x', scope: 'global', agents: [] })).toBeNull() + expect(initSpec(state, host, '../escape')).toBeNull() + + act.create('../escape') + expect(state.pending).toBeNull() + expect(state.outcome?.detail).toMatch(/no slash/) + + act.create('my-skill') + expect(state.pending?.shows).toBe('npx -y skills init my-skill') + expect(runs).toEqual([]) + + act.create('my-skill') + for (let i = 0; i < 20 && (state.skills.busy !== null || runs.length === 0); i++) await settle() + expect(runs[0]).toEqual(['npx', '-y', 'skills', 'init', 'my-skill']) + + const skill = { name: 'tdd', path: '/home/dev/.agents/skills/tdd', scope: 'global' as const, agents: [] } + + act.edit(skill) + expect(loaded).toEqual(['Edit the skill tdd at /home/dev/.agents/skills/tdd: ']) + expect(editPrompt(skill)).toBe(loaded[0]) + }) +}) diff --git a/plugins/ruflo-console/tests/views.test.ts b/plugins/ruflo-console/tests/views.test.ts index baa060ff2b..04f8ec4c2c 100644 --- a/plugins/ruflo-console/tests/views.test.ts +++ b/plugins/ruflo-console/tests/views.test.ts @@ -3,7 +3,8 @@ import { describe, expect, mock, test } from 'claude-code/testing' import { MISSION_OBSERVATION } from './fixtures/missions' import { HIVE_TOKEN, RUFLO_FILES } from './fixtures/ruflo-run' -import { command, elementsOf, fakeRuflo, keyOf, paneAt, PLUGIN, SESSION, textOf, worldOf } from './fixtures/world' +import { FIND_OUT, LS_GLOBAL } from './fixtures/skills' +import { cliAnswer, command, elementsOf, fakeRuflo, keyOf, paneAt, PLUGIN, SESSION, textOf, worldOf } from './fixtures/world' const HOME_FILES = { '.claude/plugins/installed_plugins.json': JSON.stringify({ @@ -232,6 +233,48 @@ describe('views', () => { expect(world.runs.some(argv => argv[0] === 'codex' || argv[0] === 'claude')).toBe(false) }) + test('skills: installed, search and create sections; opening lists, nothing else runs until asked and confirmed', { options: { boot: false } }, async ($, on) => { + const world = worldOf(on, RUFLO_FILES) + const skillRuns = () => world.runs.filter(argv => argv[2] === 'skills').map(argv => argv.slice(3).join(' ')) + + world.respond = argv => (argv[2] !== 'skills' ? cliAnswer(argv) : argv[3] === 'ls' ? { exitCode: 0, stdout: argv.includes('-g') ? LS_GLOBAL : '[]', stderr: '' } : argv[3] === 'find' ? { exitCode: 0, stdout: FIND_OUT, stderr: '' } : { exitCode: 0, stdout: 'done\n', stderr: '' }) + mock.clock(on) + await $.session.start(SESSION) + + const { text, tree } = await drawn($, 'skills') + + expect(text).toContain('INSTALLED') + expect(text).toContain('SEARCH') + expect(text).toContain('CREATE') + expect(text).toContain('0 project · 2 global') + expect(text).toMatch(/ faceless-explainer \.+/) + expect(text).toContain('Claude Code, Codex') + expect(elementsOf(tree, 'Input').map(keyOf)).toEqual(['skills-search', 'skills-create']) + expect(elementsOf(tree, 'Button').map(keyOf)).toEqual(expect.arrayContaining(['sk-update-0', 'sk-remove-0', 'sk-edit-0'])) + // The tab has no hotkey, and the current one reads without a key. + expect(text).toContain('[🧰 SKILLS]') + expect(skillRuns()).toEqual(['ls --json', 'ls -g --json']) + + const pane = await $.ui.mount({ ...paneAt(110), surface: 'terminal' as const, plugin: PLUGIN }) + + await pane.input({ key: 'skills-search', text: 'react', kind: 'submit' }) + + const found = textOf(await pane.drawn()) + + expect(found).toMatch(/ mattpocock\/skills@tdd \.*/) + expect(found).toContain('1M installs') + expect(skillRuns()).toEqual(['ls --json', 'ls -g --json', 'find react']) + + await pane.press({ key: 'sk-addg-0' }) + expect(textOf(await pane.drawn())).toContain('runs: npx -y skills add mattpocock/skills@tdd -g -y') + expect(skillRuns().some(line => line.startsWith('add'))).toBe(false) + + await pane.press({ key: 'confirm' }) + await pane.drawn() + expect(skillRuns()).toContain('add mattpocock/skills@tdd -g -y') + await pane.unmount() + }) + test('main menu: bare /ruflo lands on it in the BBS look; its prompt takes a key or a name', { options: { boot: false } }, async ($, on) => { worldOf(on, RUFLO_FILES) mock.clock(on) From d59daa3c4c823c4d38613ee64e6c25207fdfaba3 Mon Sep 17 00:00:00 2001 From: ruv Date: Fri, 2 Oct 2026 16:31:23 -0400 Subject: [PATCH 2/2] fix(ruflo-console): skills add checks the listed name without case (the CLI lowercases on install) Co-Authored-By: RuFlo --- plugins/ruflo-console/hooks/skills.ts | 3 ++- plugins/ruflo-console/tests/skills.spec.ts | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/ruflo-console/hooks/skills.ts b/plugins/ruflo-console/hooks/skills.ts index 5750cbba4d..43bb7ac27b 100644 --- a/plugins/ruflo-console/hooks/skills.ts +++ b/plugins/ruflo-console/hooks/skills.ts @@ -150,7 +150,8 @@ function change(state: State, host: Host, label: string, argv: readonly string[] } } -const isIn = (name: string, scope: Scope) => (installed: InstalledSkill[]) => installed.some(skill => skill.name === name && skill.scope === scope) +/** The CLI lowercases a skill's folder name on install, so a listed name is matched without case. */ +const isIn = (name: string, scope: Scope) => (installed: InstalledSkill[]) => installed.some(skill => skill.name.toLowerCase() === name.toLowerCase() && skill.scope === scope) export function addSpec(state: State, host: Host, found: FoundSkill, scope: Scope): ActionSpec | null { const id = skillIdOf(found.id) diff --git a/plugins/ruflo-console/tests/skills.spec.ts b/plugins/ruflo-console/tests/skills.spec.ts index ad105783f6..be5523fa80 100644 --- a/plugins/ruflo-console/tests/skills.spec.ts +++ b/plugins/ruflo-console/tests/skills.spec.ts @@ -146,19 +146,20 @@ describe('the skills actions', () => { return argv[3] === 'ls' ? { exitCode: 0, stdout: argv.includes('-g') ? '[]' : JSON.stringify(isAdded ? [{ name: 'tdd', path: '/work/.agents/skills/tdd', scope: 'project', agents: ['Claude Code'] }] : []), stderr: '' } : { exitCode: 0, stdout: 'Installed tdd\n', stderr: '' } }) - const spec = addSpec(state, host, { id: 'mattpocock/skills@tdd' }, 'project') + // Listed lowercase, as the CLI installs it: the check still finds it. + const spec = addSpec(state, host, { id: 'mattpocock/skills@TDD' }, 'project') runner.ask(spec, '') - expect(state.pending?.shows).toBe('npx -y skills add mattpocock/skills@tdd -y') + expect(state.pending?.shows).toBe('npx -y skills add mattpocock/skills@TDD -y') expect(runs).toEqual([]) await runner.confirm() for (let i = 0; i < 20 && state.skills.busy !== null; i++) await settle() await settle() - expect(runs[0]).toEqual(['npx', '-y', 'skills', 'add', 'mattpocock/skills@tdd', '-y']) + expect(runs[0]).toEqual(['npx', '-y', 'skills', 'add', 'mattpocock/skills@TDD', '-y']) expect(runs.slice(1).map(argv => argv[3])).toEqual(['ls', 'ls']) - expect(state.outcome).toMatchObject({ label: 'add skill mattpocock/skills@tdd to this project', ok: true, verified: 'yes' }) + expect(state.outcome).toMatchObject({ label: 'add skill mattpocock/skills@TDD to this project', ok: true, verified: 'yes' }) expect(state.skills.last?.label).toBe(state.outcome?.label) })